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