29dd448616d232c0f8703d82fd0bf51b24fcc8c1
[cascardo/linux.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  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice (including the next
16  * paragraph) shall be included in all copies or substantial portions of the
17  * Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  */
27
28 #include "drmP.h"
29 #include "drm.h"
30 #include "drm_crtc_helper.h"
31
32 #include <drm/exynos_drm.h>
33
34 #include "exynos_drm_drv.h"
35 #include "exynos_drm_crtc.h"
36 #include "exynos_drm_encoder.h"
37 #include "exynos_drm_fbdev.h"
38 #include "exynos_drm_fb.h"
39 #include "exynos_drm_gem.h"
40 #include "exynos_drm_plane.h"
41 #include "exynos_drm_vidi.h"
42 #include "exynos_drm_dmabuf.h"
43 #include "exynos_drm_display.h"
44
45 #include <linux/i2c.h>
46 #include <linux/of_i2c.h>
47
48 #include <drm/bridge/ptn3460.h>
49 #include <drm/bridge/ps8622.h>
50
51 #define DRIVER_NAME     "exynos"
52 #define DRIVER_DESC     "Samsung SoC DRM"
53 #define DRIVER_DATE     "20110530"
54 #define DRIVER_MAJOR    1
55 #define DRIVER_MINOR    0
56
57 #define VBLANK_OFF_DELAY        50000
58
59 /* TODO (seanpaul): Once we remove platform drivers, we'll be calling the
60  * various panel/controller init functions directly. These init functions will
61  * return to us the ops and context, so we can get rid of these attach
62  * functions. Once the attach functions are gone, we can move this array of
63  * display pointers into the drm device's platform data.
64  *
65  * For now, we'll use a global to keep track of things.
66  */
67 static struct exynos_drm_display *displays[EXYNOS_DRM_DISPLAY_NUM_DISPLAYS];
68
69 struct bridge_init {
70         struct i2c_client *client;
71         struct device_node *node;
72         bool valid;
73 };
74
75 static int find_bridge(const char *name, struct bridge_init *bridge)
76 {
77         bridge->valid = false;
78         bridge->client = NULL;
79         bridge->node = of_find_node_by_name(NULL, name);
80         if (!bridge->node)
81                 return 0;
82
83         bridge->client = of_find_i2c_device_by_node(bridge->node);
84         if (!bridge->client)
85                 return -ENODEV;
86
87         bridge->valid = true;
88         return 0;
89 }
90
91 static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
92 {
93         struct exynos_drm_private *private;
94         int ret;
95         int nr;
96         struct bridge_init bridge;
97
98         DRM_DEBUG("[DEV:%s] flags: 0x%lx\n", dev->devname, flags);
99
100         private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
101         if (!private) {
102                 DRM_ERROR("failed to allocate private\n");
103                 return -ENOMEM;
104         }
105
106 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
107         if (kds_callback_init(&private->kds_cb, 1,
108                               exynos_drm_kds_callback) < 0) {
109                 DRM_ERROR("kds alloc queue failed.\n");
110                 ret = -ENOMEM;
111                 goto err_kds;
112         }
113 #endif
114
115         DRM_INIT_WAITQUEUE(&private->wait_vsync_queue);
116
117         dev->dev_private = (void *)private;
118
119         drm_mode_config_init(dev);
120
121         /* init kms poll for handling hpd */
122         drm_kms_helper_poll_init(dev);
123
124         exynos_drm_mode_config_init(dev);
125
126         /*
127          * EXYNOS4 is enough to have two CRTCs and each crtc would be used
128          * without dependency of hardware.
129          */
130         for (nr = 0; nr < EXYNOS_DRM_DISPLAY_NUM_DISPLAYS; nr++) {
131                 ret = exynos_drm_crtc_create(dev, nr, displays[nr]);
132                 if (ret)
133                         goto err_crtc;
134         }
135
136         for (nr = 0; nr < MAX_PLANE; nr++) {
137                 ret = exynos_plane_init(dev, nr);
138                 if (ret)
139                         goto err_crtc;
140         }
141
142         ret = drm_vblank_init(dev, EXYNOS_DRM_DISPLAY_NUM_DISPLAYS);
143         if (ret)
144                 goto err_crtc;
145
146         ret = find_bridge("ptn3460-bridge", &bridge);
147         if (ret) {
148                 DRM_ERROR("Could not get PTN3460 bridge %d\n", ret);
149                 goto err_kds;
150         }
151         if (bridge.valid) {
152                 ret = ptn3460_init(dev, bridge.client, bridge.node);
153                 if (ret) {
154                         DRM_ERROR("Failed to initialize the ptn bridge\n");
155                         goto err_kds;
156                 }
157         } else {
158                 ret = find_bridge("ps8622-bridge", &bridge);
159                 if (ret) {
160                         DRM_ERROR("Could not get PS8622 bridge %d\n", ret);
161                         goto err_kds;
162                 }
163
164                 if (bridge.valid) {
165                         ret = ps8622_init(dev, bridge.client, bridge.node);
166                         if (ret) {
167                                 DRM_ERROR("Failed to initialize the Parade "
168                                           "bridge\n");
169                                 goto err_kds;
170                         }
171                 }
172         }
173
174         /*
175          * probe sub drivers such as display controller and hdmi driver,
176          * that were registered at probe() of platform driver
177          * to the sub driver and create encoder and connector for them.
178          */
179         ret = exynos_drm_device_register(dev);
180         if (ret)
181                 goto err_vblank;
182
183         /* setup possible_clones. */
184         exynos_drm_encoder_setup(dev);
185
186         /*
187          * create and configure fb helper and also exynos specific
188          * fbdev object.
189          */
190         ret = exynos_drm_fbdev_init(dev);
191         if (ret) {
192                 DRM_ERROR("failed to initialize drm fbdev\n");
193                 goto err_drm_device;
194         }
195
196         drm_vblank_offdelay = VBLANK_OFF_DELAY;
197
198         return 0;
199
200 err_drm_device:
201         exynos_drm_device_unregister(dev);
202 err_vblank:
203         drm_vblank_cleanup(dev);
204 err_crtc:
205         drm_mode_config_cleanup(dev);
206 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
207         kds_callback_term(&private->kds_cb);
208 err_kds:
209 #endif
210         kfree(private);
211
212         return ret;
213 }
214
215 static int exynos_drm_unload(struct drm_device *dev)
216 {
217         struct exynos_drm_private *private = dev->dev_private;
218
219         DRM_DEBUG("[DEV:%s]\n", dev->devname);
220
221         exynos_drm_fbdev_fini(dev);
222         exynos_drm_device_unregister(dev);
223         drm_vblank_cleanup(dev);
224         drm_kms_helper_poll_fini(dev);
225         drm_mode_config_cleanup(dev);
226 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
227         kds_callback_term(&private->kds_cb);
228 #endif
229         kfree(private);
230
231         dev->dev_private = NULL;
232
233         return 0;
234 }
235
236 static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
237 {
238         struct exynos_drm_file_private *file_private;
239
240         DRM_DEBUG("[DEV:%s]\n", dev->devname);
241
242         file_private = kzalloc(sizeof(*file_private), GFP_KERNEL);
243         if (!file_private) {
244                 DRM_ERROR("failed to allocate exynos_drm_file_private\n");
245                 return -ENOMEM;
246         }
247         INIT_LIST_HEAD(&file_private->gem_cpu_acquire_list);
248
249         file->driver_priv = file_private;
250
251         return exynos_drm_subdrv_open(dev, file);
252 }
253
254 static void exynos_drm_preclose(struct drm_device *dev,
255                                         struct drm_file *file)
256 {
257         struct exynos_drm_file_private *file_private = file->driver_priv;
258         struct exynos_drm_gem_obj_node *cur, *d;
259
260         DRM_DEBUG("[DEV:%s]\n", dev->devname);
261
262         mutex_lock(&dev->struct_mutex);
263         /* release kds resource sets for outstanding GEM object acquires */
264         list_for_each_entry_safe(cur, d,
265                         &file_private->gem_cpu_acquire_list, list) {
266 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
267                 BUG_ON(cur->exynos_gem_obj->resource_set == NULL);
268                 kds_resource_set_release(&cur->exynos_gem_obj->resource_set);
269 #endif
270                 drm_gem_object_unreference(&cur->exynos_gem_obj->base);
271                 kfree(cur);
272         }
273         mutex_unlock(&dev->struct_mutex);
274         INIT_LIST_HEAD(&file_private->gem_cpu_acquire_list);
275
276         exynos_drm_subdrv_close(dev, file);
277 }
278
279 static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
280 {
281         DRM_DEBUG("[DEV:%s]\n", dev->devname);
282
283         if (!file->driver_priv)
284                 return;
285
286         kfree(file->driver_priv);
287         file->driver_priv = NULL;
288 }
289
290 static void exynos_drm_lastclose(struct drm_device *dev)
291 {
292         DRM_DEBUG("[DEV:%s]\n", dev->devname);
293
294         exynos_drm_fbdev_restore_mode(dev);
295 }
296
297 static struct vm_operations_struct exynos_drm_gem_vm_ops = {
298         .fault = exynos_drm_gem_fault,
299         .open = drm_gem_vm_open,
300         .close = drm_gem_vm_close,
301 };
302
303 static struct drm_ioctl_desc exynos_ioctls[] = {
304         DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
305                         DRM_UNLOCKED | DRM_AUTH),
306         DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET,
307                         exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
308                         DRM_AUTH),
309         DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP,
310                         exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
311         DRM_IOCTL_DEF_DRV(EXYNOS_PLANE_SET_ZPOS, exynos_plane_set_zpos_ioctl,
312                         DRM_UNLOCKED | DRM_AUTH),
313         DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION,
314                         vidi_connection_ioctl, DRM_UNLOCKED | DRM_AUTH),
315         DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CPU_ACQUIRE,
316                         exynos_drm_gem_cpu_acquire_ioctl,
317                         DRM_UNLOCKED | DRM_AUTH),
318         DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CPU_RELEASE,
319                         exynos_drm_gem_cpu_release_ioctl,
320                         DRM_UNLOCKED | DRM_AUTH),
321 };
322
323 static const struct file_operations exynos_drm_driver_fops = {
324         .owner          = THIS_MODULE,
325         .open           = drm_open,
326         .mmap           = exynos_drm_gem_mmap,
327         .poll           = drm_poll,
328         .read           = drm_read,
329         .unlocked_ioctl = drm_ioctl,
330         .release        = drm_release,
331 };
332
333 static struct drm_driver exynos_drm_driver = {
334         .driver_features        = DRIVER_HAVE_IRQ | DRIVER_BUS_PLATFORM |
335                                   DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME,
336         .load                   = exynos_drm_load,
337         .unload                 = exynos_drm_unload,
338         .open                   = exynos_drm_open,
339         .preclose               = exynos_drm_preclose,
340         .lastclose              = exynos_drm_lastclose,
341         .postclose              = exynos_drm_postclose,
342         .get_vblank_counter     = drm_vblank_count,
343         .enable_vblank          = exynos_drm_crtc_enable_vblank,
344         .disable_vblank         = exynos_drm_crtc_disable_vblank,
345 #if defined(CONFIG_DEBUG_FS)
346         .debugfs_init           = exynos_drm_debugfs_init,
347         .debugfs_cleanup        = exynos_drm_debugfs_cleanup,
348 #endif
349         .gem_free_object        = exynos_drm_gem_free_object,
350         .gem_vm_ops             = &exynos_drm_gem_vm_ops,
351         .dumb_create            = exynos_drm_gem_dumb_create,
352         .dumb_map_offset        = exynos_drm_gem_dumb_map_offset,
353         .dumb_destroy           = exynos_drm_gem_dumb_destroy,
354         .prime_handle_to_fd     = drm_gem_prime_handle_to_fd,
355         .prime_fd_to_handle     = drm_gem_prime_fd_to_handle,
356         .gem_prime_export       = exynos_dmabuf_prime_export,
357         .gem_prime_import       = exynos_dmabuf_prime_import,
358         .ioctls                 = exynos_ioctls,
359         .fops                   = &exynos_drm_driver_fops,
360         .name   = DRIVER_NAME,
361         .desc   = DRIVER_DESC,
362         .date   = DRIVER_DATE,
363         .major  = DRIVER_MAJOR,
364         .minor  = DRIVER_MINOR,
365 };
366
367 #ifdef CONFIG_EXYNOS_IOMMU
368 static int iommu_init(struct platform_device *pdev)
369 {
370         /* DRM device expects a IOMMU mapping to be already
371          * created in FIMD. Else this function should
372          * throw an error.
373          */
374         if (exynos_drm_common_mapping==NULL) {
375                 printk(KERN_ERR "exynos drm common mapping is invalid\n");
376                 return -1;
377         }
378
379         /*
380          * The ordering in Makefile warrants that this is initialized after
381          * FIMD, so only just ensure that it works as expected and we are
382          * reusing the mapping originally created in exynos_drm_fimd.c.
383          */
384         WARN_ON(!exynos_drm_common_mapping);
385         if (!s5p_create_iommu_mapping(&pdev->dev, 0,
386                                 0, 0, exynos_drm_common_mapping)) {
387                 printk(KERN_ERR "failed to create IOMMU mapping\n");
388                 return -1;
389         }
390
391         return 0;
392 }
393
394 static void iommu_deinit(struct platform_device *pdev)
395 {
396         /* detach the device and mapping */
397         s5p_destroy_iommu_mapping(&pdev->dev);
398         DRM_DEBUG("released the IOMMU mapping\n");
399
400         return;
401 }
402 #endif
403
404 static int exynos_drm_platform_probe(struct platform_device *pdev)
405 {
406         struct device *dev = &pdev->dev;
407         int ret;
408
409         DRM_DEBUG("[PDEV:%s]\n", pdev->name);
410
411 #ifdef CONFIG_EXYNOS_IOMMU
412         if (iommu_init(pdev)) {
413                 DRM_ERROR("failed to initialize IOMMU\n");
414                 return -ENODEV;
415         }
416 #endif
417
418         exynos_drm_driver.num_ioctls = DRM_ARRAY_SIZE(exynos_ioctls);
419
420         pm_vt_switch_required(dev, false);
421         pm_runtime_enable(dev);
422         pm_runtime_get_sync(dev);
423
424         ret = drm_platform_init(&exynos_drm_driver, pdev);
425 #ifdef CONFIG_EXYNOS_IOMMU
426         if (ret)
427                 iommu_deinit(pdev);
428 #endif
429
430         return ret;
431 }
432
433 static int __devexit exynos_drm_platform_remove(struct platform_device *pdev)
434 {
435         struct device *dev = &pdev->dev;
436
437         DRM_DEBUG("[PDEV:%s]\n", pdev->name);
438
439         pm_vt_switch_unregister(dev);
440         pm_runtime_disable(dev);
441
442         drm_platform_exit(&exynos_drm_driver, pdev);
443
444 #ifdef CONFIG_EXYNOS_IOMMU
445         iommu_deinit(pdev);
446 #endif
447         return 0;
448 }
449
450 const char *exynos_display_type_name(const struct exynos_drm_display *display)
451 {
452         switch (display->display_type) {
453         case EXYNOS_DRM_DISPLAY_TYPE_FIMD:
454                 return "FIMD";
455         case EXYNOS_DRM_DISPLAY_TYPE_MIXER:
456                 return "MIXER";
457         case EXYNOS_DRM_DISPLAY_TYPE_VIDI:
458                 return "VIDI";
459         default:
460                 return "?";
461         }
462 }
463
464 void exynos_display_attach_panel(enum exynos_drm_display_type type,
465                 struct exynos_panel_ops *ops, void *ctx)
466 {
467         int i;
468         for (i = 0; i < EXYNOS_DRM_DISPLAY_NUM_DISPLAYS; i++) {
469                 if (displays[i]->display_type == type) {
470                         displays[i]->panel_ctx = ctx;
471                         displays[i]->panel_ops = ops;
472                         return;
473                 }
474         }
475 }
476
477 void exynos_display_attach_controller(enum exynos_drm_display_type type,
478                 struct exynos_controller_ops *ops, void *ctx)
479 {
480         int i;
481         for (i = 0; i < EXYNOS_DRM_DISPLAY_NUM_DISPLAYS; i++) {
482                 if (displays[i]->display_type == type) {
483                         displays[i]->controller_ctx = ctx;
484                         displays[i]->controller_ops = ops;
485                         return;
486                 }
487         }
488 }
489
490 static int display_subdrv_probe(struct drm_device *drm_dev,
491                 struct exynos_drm_subdrv *subdrv)
492 {
493         struct exynos_drm_display *display = subdrv->display;
494         int ret;
495
496         if (!display->controller_ops || !display->panel_ops)
497                 return -EINVAL;
498
499         if (display->controller_ops->subdrv_probe) {
500                 ret = display->controller_ops->subdrv_probe(
501                                 display->controller_ctx, drm_dev);
502                 if (ret)
503                         return ret;
504         }
505
506         if (display->panel_ops->subdrv_probe) {
507                 ret = display->panel_ops->subdrv_probe(display->panel_ctx,
508                                 drm_dev);
509                 if (ret)
510                         return ret;
511         }
512
513         return 0;
514 }
515
516 int exynos_display_init(struct exynos_drm_display *display,
517                 enum exynos_drm_display_type type)
518 {
519         struct exynos_drm_subdrv *subdrv;
520
521         subdrv = kzalloc(sizeof(*subdrv), GFP_KERNEL);
522         if (!subdrv) {
523                 DRM_ERROR("Failed to allocate display subdrv\n");
524                 return -ENOMEM;
525         }
526
527         display->display_type = type;
528         display->pipe = -1;
529         display->subdrv = subdrv;
530
531         subdrv->probe = display_subdrv_probe;
532         subdrv->display = display;
533         exynos_drm_subdrv_register(subdrv);
534
535         return 0;
536 }
537
538 void exynos_display_remove(struct exynos_drm_display *display)
539 {
540         if (display->subdrv) {
541                 exynos_drm_subdrv_unregister(display->subdrv);
542                 kfree(display->subdrv);
543         }
544 }
545
546 static int exynos_drm_resume_displays(struct drm_device *dev)
547 {
548         int i;
549
550         for (i = 0; i < EXYNOS_DRM_DISPLAY_NUM_DISPLAYS; i++) {
551                 struct exynos_drm_display *display = displays[i];
552                 struct drm_connector *connector = display->subdrv->connector;
553
554                 if (!connector || !connector->funcs->dpms)
555                         continue;
556
557                 connector->funcs->dpms(connector, display->suspend_dpms);
558         }
559
560         drm_helper_resume_force_mode(dev);
561
562         return 0;
563 }
564
565 static int exynos_drm_suspend_displays(void)
566 {
567         int i;
568
569         for (i = 0; i < EXYNOS_DRM_DISPLAY_NUM_DISPLAYS; i++) {
570                 struct exynos_drm_display *display = displays[i];
571                 struct drm_connector *connector = display->subdrv->connector;
572
573                 if (!connector)
574                         continue;
575
576                 display->suspend_dpms = connector->dpms;
577                 if (connector->funcs->dpms)
578                         connector->funcs->dpms(connector, DRM_MODE_DPMS_OFF);
579         }
580         return 0;
581 }
582
583 #ifdef CONFIG_PM_SLEEP
584 static int exynos_drm_suspend(struct device *dev)
585 {
586         if (pm_runtime_suspended(dev))
587                 return 0;
588
589         return exynos_drm_suspend_displays();
590 }
591
592 static int exynos_drm_resume(struct device *dev)
593 {
594         struct platform_device *pdev = to_platform_device(dev);
595         struct drm_device *drm_dev = platform_get_drvdata(pdev);
596
597         if (pm_runtime_suspended(dev))
598                 return 0;
599
600         return exynos_drm_resume_displays(drm_dev);
601 }
602 #endif
603
604 #ifdef CONFIG_PM_RUNTIME
605 static int exynos_drm_runtime_resume(struct device *dev)
606 {
607         struct platform_device *pdev = to_platform_device(dev);
608         struct drm_device *drm_dev = platform_get_drvdata(pdev);
609
610         /* Check drm_dev here since this function is called from probe */
611         if (!drm_dev)
612                 return 0;
613
614         return exynos_drm_resume_displays(drm_dev);
615 }
616
617 static int exynos_drm_runtime_suspend(struct device *dev)
618 {
619         return exynos_drm_suspend_displays();
620 }
621 #endif
622
623 static const struct dev_pm_ops drm_pm_ops = {
624         SET_SYSTEM_SLEEP_PM_OPS(exynos_drm_suspend, exynos_drm_resume)
625         SET_RUNTIME_PM_OPS(exynos_drm_runtime_suspend,
626                         exynos_drm_runtime_resume, NULL)
627 };
628
629 static struct platform_driver exynos_drm_platform_driver = {
630         .probe          = exynos_drm_platform_probe,
631         .remove         = __devexit_p(exynos_drm_platform_remove),
632         .driver         = {
633                 .owner  = THIS_MODULE,
634                 .name   = "exynos-drm",
635                 .pm     = &drm_pm_ops,
636         },
637 };
638
639 static int __init exynos_drm_init(void)
640 {
641         int ret, i;
642
643         DRM_DEBUG_DRIVER("\n");
644
645         for (i = 0; i < EXYNOS_DRM_DISPLAY_NUM_DISPLAYS; i++) {
646                 displays[i] = kzalloc(sizeof(*displays[i]), GFP_KERNEL);
647                 if (!displays[i]) {
648                         ret = -ENOMEM;
649                         goto out_display;
650                 }
651
652                 ret = exynos_display_init(displays[i], i);
653                 if (ret)
654                         goto out_display;
655         }
656
657 #ifdef CONFIG_DRM_EXYNOS_FIMD
658         ret = platform_driver_register(&fimd_driver);
659         if (ret < 0)
660                 goto out_fimd;
661 #endif
662
663 #ifdef CONFIG_DRM_EXYNOS_DP
664         ret = platform_driver_register(&dp_driver);
665         if (ret < 0)
666                 goto out_dp_driver;
667 #endif
668
669 #ifdef CONFIG_DRM_EXYNOS_HDMI
670         ret = platform_driver_register(&hdmi_driver);
671         if (ret < 0)
672                 goto out_hdmi;
673         ret = platform_driver_register(&mixer_driver);
674         if (ret < 0)
675                 goto out_mixer;
676 #endif
677
678 #ifdef CONFIG_DRM_EXYNOS_VIDI
679         ret = platform_driver_register(&vidi_driver);
680         if (ret < 0)
681                 goto out_vidi;
682 #endif
683
684         ret = platform_driver_register(&exynos_drm_platform_driver);
685         if (ret < 0)
686                 goto out;
687
688         return 0;
689
690 out:
691 #ifdef CONFIG_DRM_EXYNOS_VIDI
692 out_vidi:
693         platform_driver_unregister(&vidi_driver);
694 #endif
695
696 #ifdef CONFIG_DRM_EXYNOS_HDMI
697         platform_driver_unregister(&mixer_driver);
698 out_mixer:
699         platform_driver_unregister(&hdmi_driver);
700 out_hdmi:
701 #endif
702
703         platform_driver_unregister(&dp_driver);
704 out_dp_driver:
705 #ifdef CONFIG_DRM_EXYNOS_FIMD
706         platform_driver_unregister(&fimd_driver);
707 out_fimd:
708 #endif
709 out_display:
710         for (i = 0; i < EXYNOS_DRM_DISPLAY_NUM_DISPLAYS; i++) {
711                 if (!displays[i])
712                         continue;
713
714                 exynos_display_remove(displays[i]);
715                 kfree(displays[i]);
716         }
717         return ret;
718 }
719
720 static void __exit exynos_drm_exit(void)
721 {
722         int i;
723
724         DRM_DEBUG_DRIVER("\n");
725
726         platform_driver_unregister(&exynos_drm_platform_driver);
727
728 #ifdef CONFIG_DRM_EXYNOS_HDMI
729         platform_driver_unregister(&mixer_driver);
730         platform_driver_unregister(&hdmi_driver);
731 #endif
732
733 #ifdef CONFIG_DRM_EXYNOS_VIDI
734         platform_driver_unregister(&vidi_driver);
735 #endif
736
737         platform_driver_unregister(&dp_driver);
738 #ifdef CONFIG_DRM_EXYNOS_FIMD
739         platform_driver_unregister(&fimd_driver);
740 #endif
741
742         for (i = 0; i < EXYNOS_DRM_DISPLAY_NUM_DISPLAYS; i++) {
743                 if (!displays[i])
744                         continue;
745
746                 exynos_display_remove(displays[i]);
747                 kfree(displays[i]);
748         }
749 }
750
751 module_init(exynos_drm_init);
752 module_exit(exynos_drm_exit);
753
754 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
755 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
756 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
757 MODULE_DESCRIPTION("Samsung SoC DRM Driver");
758 MODULE_LICENSE("GPL");