3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
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
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.
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__
);
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
);
63 /* create and initialize a encoder for this sub driver. */
64 encoder
= exynos_drm_encoder_create(dev
, &subdrv
->manager
,
67 DRM_ERROR("failed to create encoder\n");
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
);
77 DRM_ERROR("failed to create connector\n");
78 encoder
->funcs
->destroy(encoder
);
82 subdrv
->encoder
= encoder
;
83 subdrv
->connector
= connector
;
88 static void exynos_drm_subdrv_remove(struct drm_device
*dev
,
89 struct exynos_drm_subdrv
*subdrv
)
91 DRM_DEBUG_DRIVER("%s\n", __FILE__
);
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
;
114 DRM_DEBUG_DRIVER("%s\n", __FILE__
);
120 DRM_ERROR("Already drm device were registered\n");
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
);
128 DRM_DEBUG("exynos drm subdrv probe failed.\n");
129 list_del(&subdrv
->list
);
134 mutex_unlock(&exynos_drm_mutex
);
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");
151 mutex_lock(&exynos_drm_mutex
);
152 list_for_each_entry(subdrv
, &exynos_drm_subdrv_list
, list
)
153 exynos_drm_subdrv_remove(dev
, subdrv
);
156 mutex_unlock(&exynos_drm_mutex
);
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
;
168 DRM_DEBUG_DRIVER("%s\n", __FILE__
);
170 ret
= drm_mode_group_init_legacy_group(dev
, group
);
178 int exynos_drm_subdrv_register(struct exynos_drm_subdrv
*subdrv
)
182 DRM_DEBUG_DRIVER("%s\n", __FILE__
);
187 mutex_lock(&exynos_drm_mutex
);
189 err
= exynos_drm_subdrv_probe(drm_dev
, subdrv
);
191 DRM_ERROR("failed to probe exynos drm subdrv\n");
192 mutex_unlock(&exynos_drm_mutex
);
197 * if any specific driver such as fimd or hdmi driver called
198 * exynos_drm_subdrv_register() later than drm_load(),
199 * the fb helper should be re-initialized and re-configured.
201 err
= exynos_drm_fbdev_reinit(drm_dev
);
203 DRM_ERROR("failed to reinitialize exynos drm fbdev\n");
204 exynos_drm_subdrv_remove(drm_dev
, subdrv
);
205 mutex_unlock(&exynos_drm_mutex
);
209 err
= exynos_drm_mode_group_reinit(drm_dev
);
211 DRM_ERROR("failed to reinitialize mode group\n");
212 exynos_drm_fbdev_fini(drm_dev
);
213 exynos_drm_subdrv_remove(drm_dev
, subdrv
);
214 mutex_unlock(&exynos_drm_mutex
);
219 subdrv
->drm_dev
= drm_dev
;
221 list_add_tail(&subdrv
->list
, &exynos_drm_subdrv_list
);
222 mutex_unlock(&exynos_drm_mutex
);
226 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register
);
228 int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv
*subdrv
)
232 DRM_DEBUG_DRIVER("%s\n", __FILE__
);
235 DRM_DEBUG("Unexpected exynos drm subdrv unregister!\n");
239 mutex_lock(&exynos_drm_mutex
);
241 exynos_drm_subdrv_remove(drm_dev
, subdrv
);
242 list_del(&subdrv
->list
);
245 * fb helper should be updated once a sub driver is released
246 * to re-configure crtc and connector and also to re-setup
249 ret
= exynos_drm_fbdev_reinit(drm_dev
);
251 DRM_ERROR("failed fb helper reinit.\n");
255 ret
= exynos_drm_mode_group_reinit(drm_dev
);
257 DRM_ERROR("failed drm mode group reinit.\n");
263 mutex_unlock(&exynos_drm_mutex
);
266 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister
);
268 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
269 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
270 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
271 MODULE_DESCRIPTION("Samsung SoC DRM Core Driver");
272 MODULE_LICENSE("GPL");