i2c-eg20t: change timeout value 50msec to 1000msec
[zen-stable.git] / drivers / gpu / drm / exynos / exynos_drm_core.c
blobd08a55896d50adce1345902bbe8072c399179378
1 /* exynos_drm_core.c
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>
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:
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.
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.
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"
35 static DEFINE_MUTEX(exynos_drm_mutex);
36 static LIST_HEAD(exynos_drm_subdrv_list);
37 static struct drm_device *drm_dev;
39 static int exynos_drm_subdrv_probe(struct drm_device *dev,
40 struct exynos_drm_subdrv *subdrv)
42 struct drm_encoder *encoder;
43 struct drm_connector *connector;
45 DRM_DEBUG_DRIVER("%s\n", __FILE__);
47 if (subdrv->probe) {
48 int ret;
51 * this probe callback would be called by sub driver
52 * after setting of all resources to this sub driver,
53 * such as clock, irq and register map are done or by load()
54 * of exynos drm driver.
56 * P.S. note that this driver is considered for modularization.
58 ret = subdrv->probe(dev, subdrv->manager.dev);
59 if (ret)
60 return ret;
63 /* create and initialize a encoder for this sub driver. */
64 encoder = exynos_drm_encoder_create(dev, &subdrv->manager,
65 (1 << MAX_CRTC) - 1);
66 if (!encoder) {
67 DRM_ERROR("failed to create encoder\n");
68 return -EFAULT;
72 * create and initialize a connector for this sub driver and
73 * attach the encoder created above to the connector.
75 connector = exynos_drm_connector_create(dev, encoder);
76 if (!connector) {
77 DRM_ERROR("failed to create connector\n");
78 encoder->funcs->destroy(encoder);
79 return -EFAULT;
82 subdrv->encoder = encoder;
83 subdrv->connector = connector;
85 return 0;
88 static void exynos_drm_subdrv_remove(struct drm_device *dev,
89 struct exynos_drm_subdrv *subdrv)
91 DRM_DEBUG_DRIVER("%s\n", __FILE__);
93 if (subdrv->remove)
94 subdrv->remove(dev);
96 if (subdrv->encoder) {
97 struct drm_encoder *encoder = subdrv->encoder;
98 encoder->funcs->destroy(encoder);
99 subdrv->encoder = NULL;
102 if (subdrv->connector) {
103 struct drm_connector *connector = subdrv->connector;
104 connector->funcs->destroy(connector);
105 subdrv->connector = NULL;
109 int exynos_drm_device_register(struct drm_device *dev)
111 struct exynos_drm_subdrv *subdrv, *n;
112 int err;
114 DRM_DEBUG_DRIVER("%s\n", __FILE__);
116 if (!dev)
117 return -EINVAL;
119 if (drm_dev) {
120 DRM_ERROR("Already drm device were registered\n");
121 return -EBUSY;
124 mutex_lock(&exynos_drm_mutex);
125 list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) {
126 err = exynos_drm_subdrv_probe(dev, subdrv);
127 if (err) {
128 DRM_DEBUG("exynos drm subdrv probe failed.\n");
129 list_del(&subdrv->list);
133 drm_dev = dev;
134 mutex_unlock(&exynos_drm_mutex);
136 return 0;
138 EXPORT_SYMBOL_GPL(exynos_drm_device_register);
140 int exynos_drm_device_unregister(struct drm_device *dev)
142 struct exynos_drm_subdrv *subdrv;
144 DRM_DEBUG_DRIVER("%s\n", __FILE__);
146 if (!dev || dev != drm_dev) {
147 WARN(1, "Unexpected drm device unregister!\n");
148 return -EINVAL;
151 mutex_lock(&exynos_drm_mutex);
152 list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list)
153 exynos_drm_subdrv_remove(dev, subdrv);
155 drm_dev = NULL;
156 mutex_unlock(&exynos_drm_mutex);
158 return 0;
160 EXPORT_SYMBOL_GPL(exynos_drm_device_unregister);
162 static int exynos_drm_mode_group_reinit(struct drm_device *dev)
164 struct drm_mode_group *group = &dev->primary->mode_group;
165 uint32_t *id_list = group->id_list;
166 int ret;
168 DRM_DEBUG_DRIVER("%s\n", __FILE__);
170 ret = drm_mode_group_init_legacy_group(dev, group);
171 if (ret < 0)
172 return ret;
174 kfree(id_list);
175 return 0;
178 int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
180 int err;
182 DRM_DEBUG_DRIVER("%s\n", __FILE__);
184 if (!subdrv)
185 return -EINVAL;
187 mutex_lock(&exynos_drm_mutex);
188 if (drm_dev) {
189 err = exynos_drm_subdrv_probe(drm_dev, subdrv);
190 if (err) {
191 DRM_ERROR("failed to probe exynos drm subdrv\n");
192 mutex_unlock(&exynos_drm_mutex);
193 return err;
196 /* setup possible_clones. */
197 exynos_drm_encoder_setup(drm_dev);
200 * if any specific driver such as fimd or hdmi driver called
201 * exynos_drm_subdrv_register() later than drm_load(),
202 * the fb helper should be re-initialized and re-configured.
204 err = exynos_drm_fbdev_reinit(drm_dev);
205 if (err) {
206 DRM_ERROR("failed to reinitialize exynos drm fbdev\n");
207 exynos_drm_subdrv_remove(drm_dev, subdrv);
208 mutex_unlock(&exynos_drm_mutex);
209 return err;
212 err = exynos_drm_mode_group_reinit(drm_dev);
213 if (err) {
214 DRM_ERROR("failed to reinitialize mode group\n");
215 exynos_drm_fbdev_fini(drm_dev);
216 exynos_drm_subdrv_remove(drm_dev, subdrv);
217 mutex_unlock(&exynos_drm_mutex);
218 return err;
222 subdrv->drm_dev = drm_dev;
224 list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
225 mutex_unlock(&exynos_drm_mutex);
227 return 0;
229 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register);
231 int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
233 int ret = -EFAULT;
235 DRM_DEBUG_DRIVER("%s\n", __FILE__);
237 if (!subdrv) {
238 DRM_DEBUG("Unexpected exynos drm subdrv unregister!\n");
239 return ret;
242 mutex_lock(&exynos_drm_mutex);
243 if (drm_dev) {
244 exynos_drm_subdrv_remove(drm_dev, subdrv);
245 list_del(&subdrv->list);
248 * fb helper should be updated once a sub driver is released
249 * to re-configure crtc and connector and also to re-setup
250 * drm framebuffer.
252 ret = exynos_drm_fbdev_reinit(drm_dev);
253 if (ret < 0) {
254 DRM_ERROR("failed fb helper reinit.\n");
255 goto fail;
258 ret = exynos_drm_mode_group_reinit(drm_dev);
259 if (ret < 0) {
260 DRM_ERROR("failed drm mode group reinit.\n");
261 goto fail;
265 fail:
266 mutex_unlock(&exynos_drm_mutex);
267 return ret;
269 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister);
271 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
272 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
273 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
274 MODULE_DESCRIPTION("Samsung SoC DRM Core Driver");
275 MODULE_LICENSE("GPL");