]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/gpu/drm/exynos/exynos_drm_core.c
UAPI: (Scripted) Convert #include "..." to #include <path/...> in drivers/gpu/
[mirror_ubuntu-bionic-kernel.git] / drivers / gpu / drm / exynos / exynos_drm_core.c
CommitLineData
1c248b7d
ID
1/* exynos_drm_core.c
2 *
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * Author:
5 * Inki Dae <inki.dae@samsung.com>
6 * Joonyoung Shim <jy0922.shim@samsung.com>
7 * Seung-Woo Kim <sw0312.kim@samsung.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
18 * Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
27 */
28
760285e7 29#include <drm/drmP.h>
1c248b7d
ID
30#include "exynos_drm_drv.h"
31#include "exynos_drm_encoder.h"
32#include "exynos_drm_connector.h"
33#include "exynos_drm_fbdev.h"
34
1c248b7d 35static LIST_HEAD(exynos_drm_subdrv_list);
1c248b7d
ID
36
37static int exynos_drm_subdrv_probe(struct drm_device *dev,
38 struct exynos_drm_subdrv *subdrv)
39{
40 struct drm_encoder *encoder;
41 struct drm_connector *connector;
42
43 DRM_DEBUG_DRIVER("%s\n", __FILE__);
44
45 if (subdrv->probe) {
46 int ret;
47
48 /*
49 * this probe callback would be called by sub driver
50 * after setting of all resources to this sub driver,
51 * such as clock, irq and register map are done or by load()
52 * of exynos drm driver.
53 *
54 * P.S. note that this driver is considered for modularization.
55 */
677e84c1 56 ret = subdrv->probe(dev, subdrv->dev);
1c248b7d
ID
57 if (ret)
58 return ret;
59 }
60
677e84c1 61 if (!subdrv->manager)
a31f6ecf
JS
62 return 0;
63
677e84c1
JS
64 subdrv->manager->dev = subdrv->dev;
65
1c248b7d 66 /* create and initialize a encoder for this sub driver. */
677e84c1 67 encoder = exynos_drm_encoder_create(dev, subdrv->manager,
1c248b7d
ID
68 (1 << MAX_CRTC) - 1);
69 if (!encoder) {
70 DRM_ERROR("failed to create encoder\n");
71 return -EFAULT;
72 }
73
74 /*
75 * create and initialize a connector for this sub driver and
76 * attach the encoder created above to the connector.
77 */
78 connector = exynos_drm_connector_create(dev, encoder);
79 if (!connector) {
80 DRM_ERROR("failed to create connector\n");
81 encoder->funcs->destroy(encoder);
82 return -EFAULT;
83 }
84
85 subdrv->encoder = encoder;
86 subdrv->connector = connector;
87
88 return 0;
89}
90
91static void exynos_drm_subdrv_remove(struct drm_device *dev,
92 struct exynos_drm_subdrv *subdrv)
93{
94 DRM_DEBUG_DRIVER("%s\n", __FILE__);
95
96 if (subdrv->remove)
97 subdrv->remove(dev);
98
99 if (subdrv->encoder) {
100 struct drm_encoder *encoder = subdrv->encoder;
101 encoder->funcs->destroy(encoder);
102 subdrv->encoder = NULL;
103 }
104
105 if (subdrv->connector) {
106 struct drm_connector *connector = subdrv->connector;
107 connector->funcs->destroy(connector);
108 subdrv->connector = NULL;
109 }
110}
111
112int exynos_drm_device_register(struct drm_device *dev)
113{
114 struct exynos_drm_subdrv *subdrv, *n;
115 int err;
116
117 DRM_DEBUG_DRIVER("%s\n", __FILE__);
118
119 if (!dev)
120 return -EINVAL;
121
1c248b7d 122 list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) {
132a5b91 123 subdrv->drm_dev = dev;
1c248b7d
ID
124 err = exynos_drm_subdrv_probe(dev, subdrv);
125 if (err) {
126 DRM_DEBUG("exynos drm subdrv probe failed.\n");
127 list_del(&subdrv->list);
128 }
129 }
130
1c248b7d
ID
131 return 0;
132}
133EXPORT_SYMBOL_GPL(exynos_drm_device_register);
134
135int exynos_drm_device_unregister(struct drm_device *dev)
136{
137 struct exynos_drm_subdrv *subdrv;
138
139 DRM_DEBUG_DRIVER("%s\n", __FILE__);
140
132a5b91 141 if (!dev) {
1c248b7d
ID
142 WARN(1, "Unexpected drm device unregister!\n");
143 return -EINVAL;
144 }
145
1c248b7d
ID
146 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list)
147 exynos_drm_subdrv_remove(dev, subdrv);
148
1c248b7d
ID
149 return 0;
150}
151EXPORT_SYMBOL_GPL(exynos_drm_device_unregister);
152
1c248b7d
ID
153int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
154{
1c248b7d
ID
155 DRM_DEBUG_DRIVER("%s\n", __FILE__);
156
157 if (!subdrv)
158 return -EINVAL;
159
1c248b7d 160 list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
1c248b7d
ID
161
162 return 0;
163}
164EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register);
165
166int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
167{
1c248b7d
ID
168 DRM_DEBUG_DRIVER("%s\n", __FILE__);
169
132a5b91
JS
170 if (!subdrv)
171 return -EINVAL;
1c248b7d 172
132a5b91 173 list_del(&subdrv->list);
1c248b7d 174
132a5b91 175 return 0;
1c248b7d
ID
176}
177EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister);
9084f7b8
JS
178
179int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file)
180{
181 struct exynos_drm_subdrv *subdrv;
182 int ret;
183
184 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
185 if (subdrv->open) {
677e84c1 186 ret = subdrv->open(dev, subdrv->dev, file);
9084f7b8
JS
187 if (ret)
188 goto err;
189 }
190 }
191
192 return 0;
193
194err:
195 list_for_each_entry_reverse(subdrv, &subdrv->list, list) {
196 if (subdrv->close)
677e84c1 197 subdrv->close(dev, subdrv->dev, file);
9084f7b8
JS
198 }
199 return ret;
200}
201EXPORT_SYMBOL_GPL(exynos_drm_subdrv_open);
202
203void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file)
204{
205 struct exynos_drm_subdrv *subdrv;
206
207 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
208 if (subdrv->close)
677e84c1 209 subdrv->close(dev, subdrv->dev, file);
9084f7b8
JS
210 }
211}
212EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close);