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