]>
Commit | Line | Data |
---|---|---|
1c248b7d ID |
1 | /* |
2 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. | |
3 | * Authors: | |
4 | * Inki Dae <inki.dae@samsung.com> | |
5 | * Joonyoung Shim <jy0922.shim@samsung.com> | |
6 | * Seung-Woo Kim <sw0312.kim@samsung.com> | |
7 | * | |
d81aecb5 ID |
8 | * This program is free software; you can redistribute it and/or modify it |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2 of the License, or (at your | |
11 | * option) any later version. | |
1c248b7d ID |
12 | */ |
13 | ||
af65c804 | 14 | #include <linux/pm_runtime.h> |
760285e7 DH |
15 | #include <drm/drmP.h> |
16 | #include <drm/drm_crtc_helper.h> | |
1c248b7d | 17 | |
f37cd5e8 | 18 | #include <linux/component.h> |
96f54215 | 19 | |
1c248b7d ID |
20 | #include <drm/exynos_drm.h> |
21 | ||
22 | #include "exynos_drm_drv.h" | |
23 | #include "exynos_drm_crtc.h" | |
d081f566 | 24 | #include "exynos_drm_encoder.h" |
1c248b7d ID |
25 | #include "exynos_drm_fbdev.h" |
26 | #include "exynos_drm_fb.h" | |
27 | #include "exynos_drm_gem.h" | |
864ee9e6 | 28 | #include "exynos_drm_plane.h" |
b73d1230 | 29 | #include "exynos_drm_vidi.h" |
b2df26c1 | 30 | #include "exynos_drm_dmabuf.h" |
d7f1642c | 31 | #include "exynos_drm_g2d.h" |
cb471f14 | 32 | #include "exynos_drm_ipp.h" |
0519f9a1 | 33 | #include "exynos_drm_iommu.h" |
1c248b7d | 34 | |
0edf9936 | 35 | #define DRIVER_NAME "exynos" |
1c248b7d ID |
36 | #define DRIVER_DESC "Samsung SoC DRM" |
37 | #define DRIVER_DATE "20110530" | |
38 | #define DRIVER_MAJOR 1 | |
39 | #define DRIVER_MINOR 0 | |
40 | ||
422bd00e RS |
41 | static struct platform_device *exynos_drm_pdev; |
42 | ||
f37cd5e8 ID |
43 | static DEFINE_MUTEX(drm_component_lock); |
44 | static LIST_HEAD(drm_component_list); | |
45 | ||
46 | struct component_dev { | |
47 | struct list_head list; | |
df5225bc ID |
48 | struct device *crtc_dev; |
49 | struct device *conn_dev; | |
50 | enum exynos_drm_output_type out_type; | |
51 | unsigned int dev_type_flag; | |
f37cd5e8 ID |
52 | }; |
53 | ||
1c248b7d ID |
54 | static int exynos_drm_load(struct drm_device *dev, unsigned long flags) |
55 | { | |
56 | struct exynos_drm_private *private; | |
57 | int ret; | |
58 | int nr; | |
59 | ||
1c248b7d | 60 | private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL); |
38bb5253 | 61 | if (!private) |
1c248b7d | 62 | return -ENOMEM; |
1c248b7d ID |
63 | |
64 | INIT_LIST_HEAD(&private->pageflip_event_list); | |
af65c804 | 65 | dev_set_drvdata(dev->dev, dev); |
1c248b7d ID |
66 | dev->dev_private = (void *)private; |
67 | ||
0519f9a1 ID |
68 | /* |
69 | * create mapping to manage iommu table and set a pointer to iommu | |
70 | * mapping structure to iommu_mapping of private data. | |
71 | * also this iommu_mapping can be used to check if iommu is supported | |
72 | * or not. | |
73 | */ | |
74 | ret = drm_create_iommu_mapping(dev); | |
75 | if (ret < 0) { | |
76 | DRM_ERROR("failed to create iommu mapping.\n"); | |
d2ba65f6 | 77 | goto err_free_private; |
0519f9a1 ID |
78 | } |
79 | ||
1c248b7d ID |
80 | drm_mode_config_init(dev); |
81 | ||
82 | exynos_drm_mode_config_init(dev); | |
83 | ||
864ee9e6 | 84 | for (nr = 0; nr < MAX_PLANE; nr++) { |
b5d2eb3b | 85 | struct drm_plane *plane; |
3f283d93 | 86 | unsigned long possible_crtcs = (1 << MAX_CRTC) - 1; |
b5d2eb3b | 87 | |
72ed6ccd AH |
88 | plane = exynos_plane_init(dev, possible_crtcs, |
89 | DRM_PLANE_TYPE_OVERLAY); | |
64f7aed8 AH |
90 | if (!IS_ERR(plane)) |
91 | continue; | |
92 | ||
93 | ret = PTR_ERR(plane); | |
94 | goto err_mode_config_cleanup; | |
864ee9e6 JS |
95 | } |
96 | ||
d081f566 ID |
97 | /* setup possible_clones. */ |
98 | exynos_drm_encoder_setup(dev); | |
99 | ||
a9a346d6 DV |
100 | platform_set_drvdata(dev->platformdev, dev); |
101 | ||
f37cd5e8 ID |
102 | /* Try to bind all sub drivers. */ |
103 | ret = component_bind_all(dev->dev, dev); | |
104 | if (ret) | |
c52142e6 AH |
105 | goto err_mode_config_cleanup; |
106 | ||
107 | ret = drm_vblank_init(dev, dev->mode_config.num_crtc); | |
108 | if (ret) | |
109 | goto err_unbind_all; | |
f37cd5e8 | 110 | |
4a3ffedd JS |
111 | /* |
112 | * enable drm irq mode. | |
113 | * - with irq_enabled = true, we can use the vblank feature. | |
114 | * | |
115 | * P.S. note that we wouldn't use drm irq handler but | |
116 | * just specific driver own one instead because | |
117 | * drm framework supports only one irq handler. | |
118 | */ | |
119 | dev->irq_enabled = true; | |
120 | ||
121 | /* | |
122 | * with vblank_disable_allowed = true, vblank interrupt will be disabled | |
123 | * by drm timer once a current process gives up ownership of | |
124 | * vblank event.(after drm_vblank_put function is called) | |
125 | */ | |
126 | dev->vblank_disable_allowed = true; | |
127 | ||
3cb6830a AH |
128 | /* init kms poll for handling hpd */ |
129 | drm_kms_helper_poll_init(dev); | |
130 | ||
131 | /* force connectors detection */ | |
132 | drm_helper_hpd_irq_event(dev); | |
133 | ||
1c248b7d ID |
134 | return 0; |
135 | ||
c52142e6 AH |
136 | err_unbind_all: |
137 | component_unbind_all(dev->dev, dev); | |
080be03d SP |
138 | err_mode_config_cleanup: |
139 | drm_mode_config_cleanup(dev); | |
0519f9a1 | 140 | drm_release_iommu_mapping(dev); |
d2ba65f6 | 141 | err_free_private: |
1c248b7d ID |
142 | kfree(private); |
143 | ||
144 | return ret; | |
145 | } | |
146 | ||
147 | static int exynos_drm_unload(struct drm_device *dev) | |
148 | { | |
1c248b7d | 149 | exynos_drm_fbdev_fini(dev); |
7db3eba6 | 150 | drm_kms_helper_poll_fini(dev); |
0519f9a1 | 151 | |
9f3dd7db | 152 | drm_vblank_cleanup(dev); |
c52142e6 | 153 | component_unbind_all(dev->dev, dev); |
9f3dd7db | 154 | drm_mode_config_cleanup(dev); |
0519f9a1 | 155 | drm_release_iommu_mapping(dev); |
1c248b7d | 156 | |
9f3dd7db | 157 | kfree(dev->dev_private); |
1c248b7d ID |
158 | dev->dev_private = NULL; |
159 | ||
160 | return 0; | |
161 | } | |
162 | ||
af65c804 SP |
163 | static int exynos_drm_suspend(struct drm_device *dev, pm_message_t state) |
164 | { | |
165 | struct drm_connector *connector; | |
166 | ||
167 | drm_modeset_lock_all(dev); | |
168 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
169 | int old_dpms = connector->dpms; | |
170 | ||
171 | if (connector->funcs->dpms) | |
172 | connector->funcs->dpms(connector, DRM_MODE_DPMS_OFF); | |
173 | ||
174 | /* Set the old mode back to the connector for resume */ | |
175 | connector->dpms = old_dpms; | |
176 | } | |
177 | drm_modeset_unlock_all(dev); | |
178 | ||
179 | return 0; | |
180 | } | |
181 | ||
182 | static int exynos_drm_resume(struct drm_device *dev) | |
183 | { | |
184 | struct drm_connector *connector; | |
185 | ||
186 | drm_modeset_lock_all(dev); | |
187 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
74cfe07a AH |
188 | if (connector->funcs->dpms) { |
189 | int dpms = connector->dpms; | |
190 | ||
191 | connector->dpms = DRM_MODE_DPMS_OFF; | |
192 | connector->funcs->dpms(connector, dpms); | |
193 | } | |
af65c804 | 194 | } |
a16f223e | 195 | drm_modeset_unlock_all(dev); |
af65c804 SP |
196 | |
197 | drm_helper_resume_force_mode(dev); | |
af65c804 SP |
198 | |
199 | return 0; | |
200 | } | |
201 | ||
9084f7b8 JS |
202 | static int exynos_drm_open(struct drm_device *dev, struct drm_file *file) |
203 | { | |
d7f1642c | 204 | struct drm_exynos_file_private *file_priv; |
ba3706c0 | 205 | int ret; |
d7f1642c | 206 | |
d7f1642c JS |
207 | file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL); |
208 | if (!file_priv) | |
209 | return -ENOMEM; | |
210 | ||
d7f1642c | 211 | file->driver_priv = file_priv; |
b2df26c1 | 212 | |
ba3706c0 | 213 | ret = exynos_drm_subdrv_open(dev, file); |
6ca605f7 | 214 | if (ret) |
307ceaff | 215 | goto err_file_priv_free; |
ba3706c0 | 216 | |
6ca605f7 | 217 | return ret; |
307ceaff | 218 | |
307ceaff | 219 | err_file_priv_free: |
6ca605f7 SK |
220 | kfree(file_priv); |
221 | file->driver_priv = NULL; | |
ba3706c0 | 222 | return ret; |
9084f7b8 JS |
223 | } |
224 | ||
ccf4d883 | 225 | static void exynos_drm_preclose(struct drm_device *dev, |
6f811502 | 226 | struct drm_file *file) |
0cbc330e ID |
227 | { |
228 | exynos_drm_subdrv_close(dev, file); | |
229 | } | |
230 | ||
231 | static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file) | |
ccf4d883 | 232 | { |
3ab09435 | 233 | struct exynos_drm_private *private = dev->dev_private; |
0cbc330e ID |
234 | struct drm_pending_vblank_event *v, *vt; |
235 | struct drm_pending_event *e, *et; | |
3ab09435 JS |
236 | unsigned long flags; |
237 | ||
0cbc330e ID |
238 | if (!file->driver_priv) |
239 | return; | |
240 | ||
241 | /* Release all events not unhandled by page flip handler. */ | |
3ab09435 | 242 | spin_lock_irqsave(&dev->event_lock, flags); |
0cbc330e | 243 | list_for_each_entry_safe(v, vt, &private->pageflip_event_list, |
3ab09435 | 244 | base.link) { |
0cbc330e ID |
245 | if (v->base.file_priv == file) { |
246 | list_del(&v->base.link); | |
247 | drm_vblank_put(dev, v->pipe); | |
248 | v->base.destroy(&v->base); | |
3ab09435 JS |
249 | } |
250 | } | |
9084f7b8 | 251 | |
0cbc330e ID |
252 | /* Release all events handled by page flip handler but not freed. */ |
253 | list_for_each_entry_safe(e, et, &file->event_list, link) { | |
254 | list_del(&e->link); | |
255 | e->destroy(e); | |
256 | } | |
257 | spin_unlock_irqrestore(&dev->event_lock, flags); | |
ccf4d883 | 258 | |
53ef299f ID |
259 | kfree(file->driver_priv); |
260 | file->driver_priv = NULL; | |
261 | } | |
262 | ||
1c248b7d ID |
263 | static void exynos_drm_lastclose(struct drm_device *dev) |
264 | { | |
1c248b7d ID |
265 | exynos_drm_fbdev_restore_mode(dev); |
266 | } | |
267 | ||
78b68556 | 268 | static const struct vm_operations_struct exynos_drm_gem_vm_ops = { |
1c248b7d ID |
269 | .fault = exynos_drm_gem_fault, |
270 | .open = drm_gem_vm_open, | |
271 | .close = drm_gem_vm_close, | |
272 | }; | |
273 | ||
baa70943 | 274 | static const struct drm_ioctl_desc exynos_ioctls[] = { |
1c248b7d ID |
275 | DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl, |
276 | DRM_UNLOCKED | DRM_AUTH), | |
40cd7e0c ID |
277 | DRM_IOCTL_DEF_DRV(EXYNOS_GEM_GET, |
278 | exynos_drm_gem_get_ioctl, DRM_UNLOCKED), | |
b73d1230 ID |
279 | DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION, |
280 | vidi_connection_ioctl, DRM_UNLOCKED | DRM_AUTH), | |
d7f1642c JS |
281 | DRM_IOCTL_DEF_DRV(EXYNOS_G2D_GET_VER, |
282 | exynos_g2d_get_ver_ioctl, DRM_UNLOCKED | DRM_AUTH), | |
283 | DRM_IOCTL_DEF_DRV(EXYNOS_G2D_SET_CMDLIST, | |
284 | exynos_g2d_set_cmdlist_ioctl, DRM_UNLOCKED | DRM_AUTH), | |
285 | DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC, | |
286 | exynos_g2d_exec_ioctl, DRM_UNLOCKED | DRM_AUTH), | |
cb471f14 EK |
287 | DRM_IOCTL_DEF_DRV(EXYNOS_IPP_GET_PROPERTY, |
288 | exynos_drm_ipp_get_property, DRM_UNLOCKED | DRM_AUTH), | |
289 | DRM_IOCTL_DEF_DRV(EXYNOS_IPP_SET_PROPERTY, | |
290 | exynos_drm_ipp_set_property, DRM_UNLOCKED | DRM_AUTH), | |
291 | DRM_IOCTL_DEF_DRV(EXYNOS_IPP_QUEUE_BUF, | |
292 | exynos_drm_ipp_queue_buf, DRM_UNLOCKED | DRM_AUTH), | |
293 | DRM_IOCTL_DEF_DRV(EXYNOS_IPP_CMD_CTRL, | |
294 | exynos_drm_ipp_cmd_ctrl, DRM_UNLOCKED | DRM_AUTH), | |
1c248b7d ID |
295 | }; |
296 | ||
ac2bdf73 JS |
297 | static const struct file_operations exynos_drm_driver_fops = { |
298 | .owner = THIS_MODULE, | |
299 | .open = drm_open, | |
300 | .mmap = exynos_drm_gem_mmap, | |
301 | .poll = drm_poll, | |
302 | .read = drm_read, | |
303 | .unlocked_ioctl = drm_ioctl, | |
804d74ab KP |
304 | #ifdef CONFIG_COMPAT |
305 | .compat_ioctl = drm_compat_ioctl, | |
306 | #endif | |
ac2bdf73 JS |
307 | .release = drm_release, |
308 | }; | |
309 | ||
1c248b7d | 310 | static struct drm_driver exynos_drm_driver = { |
be9b64a8 | 311 | .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME, |
1c248b7d ID |
312 | .load = exynos_drm_load, |
313 | .unload = exynos_drm_unload, | |
af65c804 SP |
314 | .suspend = exynos_drm_suspend, |
315 | .resume = exynos_drm_resume, | |
9084f7b8 | 316 | .open = exynos_drm_open, |
ccf4d883 | 317 | .preclose = exynos_drm_preclose, |
1c248b7d | 318 | .lastclose = exynos_drm_lastclose, |
53ef299f | 319 | .postclose = exynos_drm_postclose, |
915b4d11 | 320 | .set_busid = drm_platform_set_busid, |
1c248b7d ID |
321 | .get_vblank_counter = drm_vblank_count, |
322 | .enable_vblank = exynos_drm_crtc_enable_vblank, | |
323 | .disable_vblank = exynos_drm_crtc_disable_vblank, | |
1c248b7d ID |
324 | .gem_free_object = exynos_drm_gem_free_object, |
325 | .gem_vm_ops = &exynos_drm_gem_vm_ops, | |
326 | .dumb_create = exynos_drm_gem_dumb_create, | |
327 | .dumb_map_offset = exynos_drm_gem_dumb_map_offset, | |
43387b37 | 328 | .dumb_destroy = drm_gem_dumb_destroy, |
b2df26c1 ID |
329 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
330 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, | |
331 | .gem_prime_export = exynos_dmabuf_prime_export, | |
332 | .gem_prime_import = exynos_dmabuf_prime_import, | |
1c248b7d | 333 | .ioctls = exynos_ioctls, |
baa70943 | 334 | .num_ioctls = ARRAY_SIZE(exynos_ioctls), |
ac2bdf73 | 335 | .fops = &exynos_drm_driver_fops, |
1c248b7d ID |
336 | .name = DRIVER_NAME, |
337 | .desc = DRIVER_DESC, | |
338 | .date = DRIVER_DATE, | |
339 | .major = DRIVER_MAJOR, | |
340 | .minor = DRIVER_MINOR, | |
341 | }; | |
342 | ||
af65c804 SP |
343 | #ifdef CONFIG_PM_SLEEP |
344 | static int exynos_drm_sys_suspend(struct device *dev) | |
345 | { | |
346 | struct drm_device *drm_dev = dev_get_drvdata(dev); | |
347 | pm_message_t message; | |
348 | ||
d50a1907 | 349 | if (pm_runtime_suspended(dev) || !drm_dev) |
af65c804 SP |
350 | return 0; |
351 | ||
352 | message.event = PM_EVENT_SUSPEND; | |
353 | return exynos_drm_suspend(drm_dev, message); | |
354 | } | |
355 | ||
356 | static int exynos_drm_sys_resume(struct device *dev) | |
357 | { | |
358 | struct drm_device *drm_dev = dev_get_drvdata(dev); | |
359 | ||
d50a1907 | 360 | if (pm_runtime_suspended(dev) || !drm_dev) |
af65c804 SP |
361 | return 0; |
362 | ||
363 | return exynos_drm_resume(drm_dev); | |
364 | } | |
365 | #endif | |
366 | ||
af65c804 SP |
367 | static const struct dev_pm_ops exynos_drm_pm_ops = { |
368 | SET_SYSTEM_SLEEP_PM_OPS(exynos_drm_sys_suspend, exynos_drm_sys_resume) | |
af65c804 SP |
369 | }; |
370 | ||
f37cd5e8 | 371 | int exynos_drm_component_add(struct device *dev, |
df5225bc ID |
372 | enum exynos_drm_device_type dev_type, |
373 | enum exynos_drm_output_type out_type) | |
f37cd5e8 ID |
374 | { |
375 | struct component_dev *cdev; | |
df5225bc ID |
376 | |
377 | if (dev_type != EXYNOS_DEVICE_TYPE_CRTC && | |
378 | dev_type != EXYNOS_DEVICE_TYPE_CONNECTOR) { | |
379 | DRM_ERROR("invalid device type.\n"); | |
380 | return -EINVAL; | |
381 | } | |
382 | ||
383 | mutex_lock(&drm_component_lock); | |
384 | ||
385 | /* | |
386 | * Make sure to check if there is a component which has two device | |
387 | * objects, for connector and for encoder/connector. | |
388 | * It should make sure that crtc and encoder/connector drivers are | |
389 | * ready before exynos drm core binds them. | |
390 | */ | |
391 | list_for_each_entry(cdev, &drm_component_list, list) { | |
392 | if (cdev->out_type == out_type) { | |
393 | /* | |
394 | * If crtc and encoder/connector device objects are | |
395 | * added already just return. | |
396 | */ | |
397 | if (cdev->dev_type_flag == (EXYNOS_DEVICE_TYPE_CRTC | | |
398 | EXYNOS_DEVICE_TYPE_CONNECTOR)) { | |
399 | mutex_unlock(&drm_component_lock); | |
400 | return 0; | |
401 | } | |
402 | ||
403 | if (dev_type == EXYNOS_DEVICE_TYPE_CRTC) { | |
404 | cdev->crtc_dev = dev; | |
405 | cdev->dev_type_flag |= dev_type; | |
406 | } | |
407 | ||
408 | if (dev_type == EXYNOS_DEVICE_TYPE_CONNECTOR) { | |
409 | cdev->conn_dev = dev; | |
410 | cdev->dev_type_flag |= dev_type; | |
411 | } | |
412 | ||
413 | mutex_unlock(&drm_component_lock); | |
414 | return 0; | |
415 | } | |
416 | } | |
417 | ||
418 | mutex_unlock(&drm_component_lock); | |
f37cd5e8 ID |
419 | |
420 | cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); | |
421 | if (!cdev) | |
422 | return -ENOMEM; | |
423 | ||
df5225bc ID |
424 | if (dev_type == EXYNOS_DEVICE_TYPE_CRTC) |
425 | cdev->crtc_dev = dev; | |
426 | if (dev_type == EXYNOS_DEVICE_TYPE_CONNECTOR) | |
427 | cdev->conn_dev = dev; | |
f37cd5e8 | 428 | |
df5225bc ID |
429 | cdev->out_type = out_type; |
430 | cdev->dev_type_flag = dev_type; | |
f37cd5e8 ID |
431 | |
432 | mutex_lock(&drm_component_lock); | |
433 | list_add_tail(&cdev->list, &drm_component_list); | |
434 | mutex_unlock(&drm_component_lock); | |
435 | ||
436 | return 0; | |
437 | } | |
438 | ||
439 | void exynos_drm_component_del(struct device *dev, | |
df5225bc | 440 | enum exynos_drm_device_type dev_type) |
f37cd5e8 ID |
441 | { |
442 | struct component_dev *cdev, *next; | |
443 | ||
444 | mutex_lock(&drm_component_lock); | |
445 | ||
446 | list_for_each_entry_safe(cdev, next, &drm_component_list, list) { | |
df5225bc ID |
447 | if (dev_type == EXYNOS_DEVICE_TYPE_CRTC) { |
448 | if (cdev->crtc_dev == dev) { | |
449 | cdev->crtc_dev = NULL; | |
450 | cdev->dev_type_flag &= ~dev_type; | |
451 | } | |
452 | } | |
453 | ||
454 | if (dev_type == EXYNOS_DEVICE_TYPE_CONNECTOR) { | |
455 | if (cdev->conn_dev == dev) { | |
456 | cdev->conn_dev = NULL; | |
457 | cdev->dev_type_flag &= ~dev_type; | |
458 | } | |
459 | } | |
460 | ||
461 | /* | |
462 | * Release cdev object only in case that both of crtc and | |
463 | * encoder/connector device objects are NULL. | |
464 | */ | |
465 | if (!cdev->crtc_dev && !cdev->conn_dev) { | |
f37cd5e8 ID |
466 | list_del(&cdev->list); |
467 | kfree(cdev); | |
f37cd5e8 | 468 | } |
df5225bc ID |
469 | |
470 | break; | |
f37cd5e8 ID |
471 | } |
472 | ||
473 | mutex_unlock(&drm_component_lock); | |
f37cd5e8 ID |
474 | } |
475 | ||
53c5558d | 476 | static int compare_dev(struct device *dev, void *data) |
f37cd5e8 ID |
477 | { |
478 | return dev == (struct device *)data; | |
479 | } | |
480 | ||
53c5558d | 481 | static struct component_match *exynos_drm_match_add(struct device *dev) |
f37cd5e8 | 482 | { |
53c5558d | 483 | struct component_match *match = NULL; |
f37cd5e8 | 484 | struct component_dev *cdev; |
df5225bc | 485 | unsigned int attach_cnt = 0; |
f37cd5e8 ID |
486 | |
487 | mutex_lock(&drm_component_lock); | |
488 | ||
fbdf093d ID |
489 | /* Do not retry to probe if there is no any kms driver regitered. */ |
490 | if (list_empty(&drm_component_list)) { | |
491 | mutex_unlock(&drm_component_lock); | |
492 | return ERR_PTR(-ENODEV); | |
493 | } | |
494 | ||
f37cd5e8 | 495 | list_for_each_entry(cdev, &drm_component_list, list) { |
df5225bc ID |
496 | /* |
497 | * Add components to master only in case that crtc and | |
498 | * encoder/connector device objects exist. | |
499 | */ | |
500 | if (!cdev->crtc_dev || !cdev->conn_dev) | |
501 | continue; | |
502 | ||
503 | attach_cnt++; | |
504 | ||
f37cd5e8 ID |
505 | mutex_unlock(&drm_component_lock); |
506 | ||
df5225bc ID |
507 | /* |
508 | * fimd and dpi modules have same device object so add | |
509 | * only crtc device object in this case. | |
df5225bc ID |
510 | */ |
511 | if (cdev->crtc_dev == cdev->conn_dev) { | |
53c5558d ID |
512 | component_match_add(dev, &match, compare_dev, |
513 | cdev->crtc_dev); | |
df5225bc ID |
514 | goto out_lock; |
515 | } | |
f37cd5e8 | 516 | |
df5225bc ID |
517 | /* |
518 | * Do not chage below call order. | |
519 | * crtc device first should be added to master because | |
520 | * connector/encoder need pipe number of crtc when they | |
521 | * are created. | |
522 | */ | |
53c5558d ID |
523 | component_match_add(dev, &match, compare_dev, cdev->crtc_dev); |
524 | component_match_add(dev, &match, compare_dev, cdev->conn_dev); | |
df5225bc ID |
525 | |
526 | out_lock: | |
f37cd5e8 ID |
527 | mutex_lock(&drm_component_lock); |
528 | } | |
529 | ||
530 | mutex_unlock(&drm_component_lock); | |
531 | ||
53c5558d | 532 | return attach_cnt ? match : ERR_PTR(-EPROBE_DEFER); |
f37cd5e8 ID |
533 | } |
534 | ||
535 | static int exynos_drm_bind(struct device *dev) | |
536 | { | |
f37cd5e8 ID |
537 | return drm_platform_init(&exynos_drm_driver, to_platform_device(dev)); |
538 | } | |
539 | ||
540 | static void exynos_drm_unbind(struct device *dev) | |
541 | { | |
542 | drm_put_dev(dev_get_drvdata(dev)); | |
543 | } | |
544 | ||
545 | static const struct component_master_ops exynos_drm_ops = { | |
f37cd5e8 ID |
546 | .bind = exynos_drm_bind, |
547 | .unbind = exynos_drm_unbind, | |
1c248b7d ID |
548 | }; |
549 | ||
f37cd5e8 | 550 | static int exynos_drm_platform_probe(struct platform_device *pdev) |
1c248b7d | 551 | { |
53c5558d | 552 | struct component_match *match; |
132a5b91 JS |
553 | int ret; |
554 | ||
f37cd5e8 | 555 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
f95aeb17 | 556 | exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls); |
f37cd5e8 ID |
557 | |
558 | #ifdef CONFIG_DRM_EXYNOS_FIMD | |
559 | ret = platform_driver_register(&fimd_driver); | |
560 | if (ret < 0) | |
561 | return ret; | |
562 | #endif | |
563 | ||
1417f109 SP |
564 | #ifdef CONFIG_DRM_EXYNOS_DP |
565 | ret = platform_driver_register(&dp_driver); | |
566 | if (ret < 0) | |
f37cd5e8 | 567 | goto err_unregister_fimd_drv; |
1417f109 SP |
568 | #endif |
569 | ||
7eb8f069 AH |
570 | #ifdef CONFIG_DRM_EXYNOS_DSI |
571 | ret = platform_driver_register(&dsi_driver); | |
572 | if (ret < 0) | |
121692eb | 573 | goto err_unregister_dp_drv; |
7eb8f069 AH |
574 | #endif |
575 | ||
132a5b91 | 576 | #ifdef CONFIG_DRM_EXYNOS_HDMI |
132a5b91 JS |
577 | ret = platform_driver_register(&mixer_driver); |
578 | if (ret < 0) | |
f37cd5e8 ID |
579 | goto err_unregister_dsi_drv; |
580 | ret = platform_driver_register(&hdmi_driver); | |
b73d1230 | 581 | if (ret < 0) |
121692eb | 582 | goto err_unregister_mixer_drv; |
b73d1230 ID |
583 | #endif |
584 | ||
e9fbdcb4 ID |
585 | match = exynos_drm_match_add(&pdev->dev); |
586 | if (IS_ERR(match)) { | |
587 | ret = PTR_ERR(match); | |
588 | goto err_unregister_hdmi_drv; | |
589 | } | |
590 | ||
591 | ret = component_master_add_with_match(&pdev->dev, &exynos_drm_ops, | |
592 | match); | |
593 | if (ret < 0) | |
594 | goto err_unregister_hdmi_drv; | |
595 | ||
d7f1642c JS |
596 | #ifdef CONFIG_DRM_EXYNOS_G2D |
597 | ret = platform_driver_register(&g2d_driver); | |
598 | if (ret < 0) | |
e9fbdcb4 | 599 | goto err_del_component_master; |
d7f1642c JS |
600 | #endif |
601 | ||
16102edb EK |
602 | #ifdef CONFIG_DRM_EXYNOS_FIMC |
603 | ret = platform_driver_register(&fimc_driver); | |
604 | if (ret < 0) | |
121692eb | 605 | goto err_unregister_g2d_drv; |
16102edb EK |
606 | #endif |
607 | ||
bea8a429 EK |
608 | #ifdef CONFIG_DRM_EXYNOS_ROTATOR |
609 | ret = platform_driver_register(&rotator_driver); | |
610 | if (ret < 0) | |
121692eb | 611 | goto err_unregister_fimc_drv; |
bea8a429 EK |
612 | #endif |
613 | ||
f2646380 EK |
614 | #ifdef CONFIG_DRM_EXYNOS_GSC |
615 | ret = platform_driver_register(&gsc_driver); | |
616 | if (ret < 0) | |
121692eb | 617 | goto err_unregister_rotator_drv; |
f2646380 EK |
618 | #endif |
619 | ||
cb471f14 EK |
620 | #ifdef CONFIG_DRM_EXYNOS_IPP |
621 | ret = platform_driver_register(&ipp_driver); | |
622 | if (ret < 0) | |
121692eb | 623 | goto err_unregister_gsc_drv; |
43f41900 SWK |
624 | |
625 | ret = exynos_platform_device_ipp_register(); | |
626 | if (ret < 0) | |
121692eb | 627 | goto err_unregister_ipp_drv; |
cb471f14 EK |
628 | #endif |
629 | ||
421ee18d ID |
630 | /* Probe non kms sub drivers and virtual display driver. */ |
631 | ret = exynos_drm_device_subdrv_probe(platform_get_drvdata(pdev)); | |
632 | if (ret) | |
633 | goto err_unregister_resources; | |
634 | ||
53c5558d ID |
635 | return ret; |
636 | ||
421ee18d | 637 | err_unregister_resources: |
cb471f14 | 638 | #ifdef CONFIG_DRM_EXYNOS_IPP |
421ee18d | 639 | exynos_platform_device_ipp_unregister(); |
121692eb | 640 | err_unregister_ipp_drv: |
cb471f14 | 641 | platform_driver_unregister(&ipp_driver); |
121692eb | 642 | err_unregister_gsc_drv: |
cb471f14 EK |
643 | #endif |
644 | ||
f2646380 EK |
645 | #ifdef CONFIG_DRM_EXYNOS_GSC |
646 | platform_driver_unregister(&gsc_driver); | |
121692eb | 647 | err_unregister_rotator_drv: |
f2646380 EK |
648 | #endif |
649 | ||
bea8a429 EK |
650 | #ifdef CONFIG_DRM_EXYNOS_ROTATOR |
651 | platform_driver_unregister(&rotator_driver); | |
121692eb | 652 | err_unregister_fimc_drv: |
bea8a429 EK |
653 | #endif |
654 | ||
16102edb EK |
655 | #ifdef CONFIG_DRM_EXYNOS_FIMC |
656 | platform_driver_unregister(&fimc_driver); | |
121692eb | 657 | err_unregister_g2d_drv: |
16102edb EK |
658 | #endif |
659 | ||
d7f1642c JS |
660 | #ifdef CONFIG_DRM_EXYNOS_G2D |
661 | platform_driver_unregister(&g2d_driver); | |
e9fbdcb4 | 662 | err_del_component_master: |
b73d1230 | 663 | #endif |
e9fbdcb4 | 664 | component_master_del(&pdev->dev, &exynos_drm_ops); |
b73d1230 | 665 | |
e9fbdcb4 | 666 | err_unregister_hdmi_drv: |
132a5b91 | 667 | #ifdef CONFIG_DRM_EXYNOS_HDMI |
132a5b91 | 668 | platform_driver_unregister(&hdmi_driver); |
f37cd5e8 ID |
669 | err_unregister_mixer_drv: |
670 | platform_driver_unregister(&mixer_driver); | |
121692eb | 671 | err_unregister_dsi_drv: |
1417f109 | 672 | #endif |
25928a39 | 673 | |
7eb8f069 AH |
674 | #ifdef CONFIG_DRM_EXYNOS_DSI |
675 | platform_driver_unregister(&dsi_driver); | |
121692eb | 676 | err_unregister_dp_drv: |
7eb8f069 AH |
677 | #endif |
678 | ||
1417f109 SP |
679 | #ifdef CONFIG_DRM_EXYNOS_DP |
680 | platform_driver_unregister(&dp_driver); | |
f37cd5e8 ID |
681 | err_unregister_fimd_drv: |
682 | #endif | |
683 | ||
684 | #ifdef CONFIG_DRM_EXYNOS_FIMD | |
685 | platform_driver_unregister(&fimd_driver); | |
132a5b91 JS |
686 | #endif |
687 | return ret; | |
1c248b7d ID |
688 | } |
689 | ||
f37cd5e8 | 690 | static int exynos_drm_platform_remove(struct platform_device *pdev) |
1c248b7d | 691 | { |
421ee18d ID |
692 | exynos_drm_device_subdrv_remove(platform_get_drvdata(pdev)); |
693 | ||
cb471f14 | 694 | #ifdef CONFIG_DRM_EXYNOS_IPP |
43f41900 | 695 | exynos_platform_device_ipp_unregister(); |
cb471f14 EK |
696 | platform_driver_unregister(&ipp_driver); |
697 | #endif | |
698 | ||
f2646380 EK |
699 | #ifdef CONFIG_DRM_EXYNOS_GSC |
700 | platform_driver_unregister(&gsc_driver); | |
701 | #endif | |
702 | ||
bea8a429 EK |
703 | #ifdef CONFIG_DRM_EXYNOS_ROTATOR |
704 | platform_driver_unregister(&rotator_driver); | |
705 | #endif | |
706 | ||
16102edb EK |
707 | #ifdef CONFIG_DRM_EXYNOS_FIMC |
708 | platform_driver_unregister(&fimc_driver); | |
709 | #endif | |
710 | ||
d7f1642c JS |
711 | #ifdef CONFIG_DRM_EXYNOS_G2D |
712 | platform_driver_unregister(&g2d_driver); | |
713 | #endif | |
714 | ||
132a5b91 | 715 | #ifdef CONFIG_DRM_EXYNOS_HDMI |
132a5b91 JS |
716 | platform_driver_unregister(&mixer_driver); |
717 | platform_driver_unregister(&hdmi_driver); | |
718 | #endif | |
719 | ||
720 | #ifdef CONFIG_DRM_EXYNOS_FIMD | |
721 | platform_driver_unregister(&fimd_driver); | |
722 | #endif | |
1417f109 | 723 | |
7eb8f069 AH |
724 | #ifdef CONFIG_DRM_EXYNOS_DSI |
725 | platform_driver_unregister(&dsi_driver); | |
726 | #endif | |
727 | ||
1417f109 SP |
728 | #ifdef CONFIG_DRM_EXYNOS_DP |
729 | platform_driver_unregister(&dp_driver); | |
730 | #endif | |
f37cd5e8 ID |
731 | component_master_del(&pdev->dev, &exynos_drm_ops); |
732 | return 0; | |
733 | } | |
734 | ||
735 | static struct platform_driver exynos_drm_platform_driver = { | |
736 | .probe = exynos_drm_platform_probe, | |
737 | .remove = exynos_drm_platform_remove, | |
738 | .driver = { | |
739 | .owner = THIS_MODULE, | |
740 | .name = "exynos-drm", | |
741 | .pm = &exynos_drm_pm_ops, | |
742 | }, | |
743 | }; | |
744 | ||
745 | static int exynos_drm_init(void) | |
746 | { | |
747 | int ret; | |
748 | ||
5cbb37df ID |
749 | /* |
750 | * Register device object only in case of Exynos SoC. | |
751 | * | |
752 | * Below codes resolves temporarily infinite loop issue incurred | |
753 | * by Exynos drm driver when using multi-platform kernel. | |
754 | * So these codes will be replaced with more generic way later. | |
755 | */ | |
756 | if (!of_machine_is_compatible("samsung,exynos3") && | |
757 | !of_machine_is_compatible("samsung,exynos4") && | |
758 | !of_machine_is_compatible("samsung,exynos5")) | |
759 | return -ENODEV; | |
760 | ||
f37cd5e8 ID |
761 | exynos_drm_pdev = platform_device_register_simple("exynos-drm", -1, |
762 | NULL, 0); | |
763 | if (IS_ERR(exynos_drm_pdev)) | |
764 | return PTR_ERR(exynos_drm_pdev); | |
765 | ||
766 | #ifdef CONFIG_DRM_EXYNOS_VIDI | |
767 | ret = exynos_drm_probe_vidi(); | |
768 | if (ret < 0) | |
769 | goto err_unregister_pd; | |
770 | #endif | |
771 | ||
772 | ret = platform_driver_register(&exynos_drm_platform_driver); | |
773 | if (ret) | |
774 | goto err_remove_vidi; | |
775 | ||
776 | return 0; | |
777 | ||
f37cd5e8 ID |
778 | err_remove_vidi: |
779 | #ifdef CONFIG_DRM_EXYNOS_VIDI | |
780 | exynos_drm_remove_vidi(); | |
0013fc9e SK |
781 | |
782 | err_unregister_pd: | |
f37cd5e8 | 783 | #endif |
0013fc9e | 784 | platform_device_unregister(exynos_drm_pdev); |
f37cd5e8 ID |
785 | |
786 | return ret; | |
787 | } | |
788 | ||
789 | static void exynos_drm_exit(void) | |
790 | { | |
0013fc9e | 791 | platform_driver_unregister(&exynos_drm_platform_driver); |
f37cd5e8 ID |
792 | #ifdef CONFIG_DRM_EXYNOS_VIDI |
793 | exynos_drm_remove_vidi(); | |
794 | #endif | |
795 | platform_device_unregister(exynos_drm_pdev); | |
1c248b7d ID |
796 | } |
797 | ||
798 | module_init(exynos_drm_init); | |
799 | module_exit(exynos_drm_exit); | |
800 | ||
801 | MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>"); | |
802 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); | |
803 | MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>"); | |
804 | MODULE_DESCRIPTION("Samsung SoC DRM Driver"); | |
805 | MODULE_LICENSE("GPL"); |