blob: 411832e8e17aa9fcd9eed13fc614be878f781403 [file] [log] [blame]
Inki Dae1c248b72011-10-04 19:19:01 +09001/* 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
29#include "drmP.h"
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
Inki Dae1c248b72011-10-04 19:19:01 +090035static LIST_HEAD(exynos_drm_subdrv_list);
36static struct drm_device *drm_dev;
37
38static int exynos_drm_subdrv_probe(struct drm_device *dev,
39 struct exynos_drm_subdrv *subdrv)
40{
41 struct drm_encoder *encoder;
42 struct drm_connector *connector;
43
44 DRM_DEBUG_DRIVER("%s\n", __FILE__);
45
46 if (subdrv->probe) {
47 int ret;
48
49 /*
50 * this probe callback would be called by sub driver
51 * after setting of all resources to this sub driver,
52 * such as clock, irq and register map are done or by load()
53 * of exynos drm driver.
54 *
55 * P.S. note that this driver is considered for modularization.
56 */
Inki Dae41c24342011-10-14 13:29:48 +090057 ret = subdrv->probe(dev, subdrv->manager.dev);
Inki Dae1c248b72011-10-04 19:19:01 +090058 if (ret)
59 return ret;
60 }
61
Joonyoung Shima31f6ec2012-03-16 18:47:10 +090062 if (subdrv->is_local)
63 return 0;
64
Inki Dae1c248b72011-10-04 19:19:01 +090065 /* create and initialize a encoder for this sub driver. */
66 encoder = exynos_drm_encoder_create(dev, &subdrv->manager,
67 (1 << MAX_CRTC) - 1);
68 if (!encoder) {
69 DRM_ERROR("failed to create encoder\n");
70 return -EFAULT;
71 }
72
73 /*
74 * create and initialize a connector for this sub driver and
75 * attach the encoder created above to the connector.
76 */
77 connector = exynos_drm_connector_create(dev, encoder);
78 if (!connector) {
79 DRM_ERROR("failed to create connector\n");
80 encoder->funcs->destroy(encoder);
81 return -EFAULT;
82 }
83
84 subdrv->encoder = encoder;
85 subdrv->connector = connector;
86
87 return 0;
88}
89
90static void exynos_drm_subdrv_remove(struct drm_device *dev,
91 struct exynos_drm_subdrv *subdrv)
92{
93 DRM_DEBUG_DRIVER("%s\n", __FILE__);
94
95 if (subdrv->remove)
96 subdrv->remove(dev);
97
98 if (subdrv->encoder) {
99 struct drm_encoder *encoder = subdrv->encoder;
100 encoder->funcs->destroy(encoder);
101 subdrv->encoder = NULL;
102 }
103
104 if (subdrv->connector) {
105 struct drm_connector *connector = subdrv->connector;
106 connector->funcs->destroy(connector);
107 subdrv->connector = NULL;
108 }
109}
110
111int exynos_drm_device_register(struct drm_device *dev)
112{
113 struct exynos_drm_subdrv *subdrv, *n;
114 int err;
115
116 DRM_DEBUG_DRIVER("%s\n", __FILE__);
117
118 if (!dev)
119 return -EINVAL;
120
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900121 drm_dev = dev;
Inki Dae1c248b72011-10-04 19:19:01 +0900122
Inki Dae1c248b72011-10-04 19:19:01 +0900123 list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) {
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900124 subdrv->drm_dev = dev;
Inki Dae1c248b72011-10-04 19:19:01 +0900125 err = exynos_drm_subdrv_probe(dev, subdrv);
126 if (err) {
127 DRM_DEBUG("exynos drm subdrv probe failed.\n");
128 list_del(&subdrv->list);
129 }
130 }
131
Inki Dae1c248b72011-10-04 19:19:01 +0900132 return 0;
133}
134EXPORT_SYMBOL_GPL(exynos_drm_device_register);
135
136int exynos_drm_device_unregister(struct drm_device *dev)
137{
138 struct exynos_drm_subdrv *subdrv;
139
140 DRM_DEBUG_DRIVER("%s\n", __FILE__);
141
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900142 if (!dev) {
Inki Dae1c248b72011-10-04 19:19:01 +0900143 WARN(1, "Unexpected drm device unregister!\n");
144 return -EINVAL;
145 }
146
Inki Dae1c248b72011-10-04 19:19:01 +0900147 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list)
148 exynos_drm_subdrv_remove(dev, subdrv);
149
150 drm_dev = NULL;
Inki Dae1c248b72011-10-04 19:19:01 +0900151
152 return 0;
153}
154EXPORT_SYMBOL_GPL(exynos_drm_device_unregister);
155
Inki Dae1c248b72011-10-04 19:19:01 +0900156int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
157{
Inki Dae1c248b72011-10-04 19:19:01 +0900158 DRM_DEBUG_DRIVER("%s\n", __FILE__);
159
160 if (!subdrv)
161 return -EINVAL;
162
Inki Dae1c248b72011-10-04 19:19:01 +0900163 list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
Inki Dae1c248b72011-10-04 19:19:01 +0900164
165 return 0;
166}
167EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register);
168
169int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
170{
Inki Dae1c248b72011-10-04 19:19:01 +0900171 DRM_DEBUG_DRIVER("%s\n", __FILE__);
172
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900173 if (!subdrv)
174 return -EINVAL;
Inki Dae1c248b72011-10-04 19:19:01 +0900175
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900176 list_del(&subdrv->list);
Inki Dae1c248b72011-10-04 19:19:01 +0900177
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900178 return 0;
Inki Dae1c248b72011-10-04 19:19:01 +0900179}
180EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister);
Joonyoung Shim9084f7b2012-03-16 18:47:09 +0900181
182int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file)
183{
184 struct exynos_drm_subdrv *subdrv;
185 int ret;
186
187 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
188 if (subdrv->open) {
189 ret = subdrv->open(dev, subdrv->manager.dev, file);
190 if (ret)
191 goto err;
192 }
193 }
194
195 return 0;
196
197err:
198 list_for_each_entry_reverse(subdrv, &subdrv->list, list) {
199 if (subdrv->close)
200 subdrv->close(dev, subdrv->manager.dev, file);
201 }
202 return ret;
203}
204EXPORT_SYMBOL_GPL(exynos_drm_subdrv_open);
205
206void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file)
207{
208 struct exynos_drm_subdrv *subdrv;
209
210 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
211 if (subdrv->close)
212 subdrv->close(dev, subdrv->manager.dev, file);
213 }
214}
215EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close);