BACKPORT: drm/exynos: use private plane for crtc
[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                 struct drm_plane *plane;
138                 unsigned int possible_crtcs =
139                         (1 << EXYNOS_DRM_DISPLAY_NUM_DISPLAYS) - 1;
140
141                 plane = exynos_plane_init(dev, possible_crtcs, false);
142                 if (!plane)
143                         goto err_crtc;
144         }
145
146         ret = drm_vblank_init(dev, EXYNOS_DRM_DISPLAY_NUM_DISPLAYS);
147         if (ret)
148                 goto err_crtc;
149
150         ret = find_bridge("ptn3460-bridge", &bridge);
151         if (ret) {
152                 DRM_ERROR("Could not get PTN3460 bridge %d\n", ret);
153                 goto err_kds;
154         }
155         if (bridge.valid) {
156                 ret = ptn3460_init(dev, bridge.client, bridge.node);
157                 if (ret) {
158                         DRM_ERROR("Failed to initialize the ptn bridge\n");
159                         goto err_kds;
160                 }
161         } else {
162                 ret = find_bridge("ps8622-bridge", &bridge);
163                 if (ret) {
164                         DRM_ERROR("Could not get PS8622 bridge %d\n", ret);
165                         goto err_kds;
166                 }
167
168                 if (bridge.valid) {
169                         ret = ps8622_init(dev, bridge.client, bridge.node);
170                         if (ret) {
171                                 DRM_ERROR("Failed to initialize the Parade "
172                                           "bridge\n");
173                                 goto err_kds;
174                         }
175                 }
176         }
177
178         /*
179          * probe sub drivers such as display controller and hdmi driver,
180          * that were registered at probe() of platform driver
181          * to the sub driver and create encoder and connector for them.
182          */
183         ret = exynos_drm_device_register(dev);
184         if (ret)
185                 goto err_vblank;
186
187         /* setup possible_clones. */
188         exynos_drm_encoder_setup(dev);
189
190         /*
191          * create and configure fb helper and also exynos specific
192          * fbdev object.
193          */
194         ret = exynos_drm_fbdev_init(dev);
195         if (ret) {
196                 DRM_ERROR("failed to initialize drm fbdev\n");
197                 goto err_drm_device;
198         }
199
200         drm_vblank_offdelay = VBLANK_OFF_DELAY;
201
202         return 0;
203
204 err_drm_device:
205         exynos_drm_device_unregister(dev);
206 err_vblank:
207         drm_vblank_cleanup(dev);
208 err_crtc:
209         drm_mode_config_cleanup(dev);
210 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
211         kds_callback_term(&private->kds_cb);
212 err_kds:
213 #endif
214         kfree(private);
215
216         return ret;
217 }
218
219 static int exynos_drm_unload(struct drm_device *dev)
220 {
221         struct exynos_drm_private *private = dev->dev_private;
222
223         DRM_DEBUG("[DEV:%s]\n", dev->devname);
224
225         exynos_drm_fbdev_fini(dev);
226         exynos_drm_device_unregister(dev);
227         drm_vblank_cleanup(dev);
228         drm_kms_helper_poll_fini(dev);
229         drm_mode_config_cleanup(dev);
230 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
231         kds_callback_term(&private->kds_cb);
232 #endif
233         kfree(private);
234
235         dev->dev_private = NULL;
236
237         return 0;
238 }
239
240 static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
241 {
242         struct exynos_drm_file_private *file_private;
243
244         DRM_DEBUG("[DEV:%s]\n", dev->devname);
245
246         file_private = kzalloc(sizeof(*file_private), GFP_KERNEL);
247         if (!file_private) {
248                 DRM_ERROR("failed to allocate exynos_drm_file_private\n");
249                 return -ENOMEM;
250         }
251         INIT_LIST_HEAD(&file_private->gem_cpu_acquire_list);
252
253         file->driver_priv = file_private;
254
255         return exynos_drm_subdrv_open(dev, file);
256 }
257
258 static void exynos_drm_preclose(struct drm_device *dev,
259                                         struct drm_file *file)
260 {
261         struct exynos_drm_file_private *file_private = file->driver_priv;
262         struct exynos_drm_gem_obj_node *cur, *d;
263
264         DRM_DEBUG("[DEV:%s]\n", dev->devname);
265
266         mutex_lock(&dev->struct_mutex);
267         /* release kds resource sets for outstanding GEM object acquires */
268         list_for_each_entry_safe(cur, d,
269                         &file_private->gem_cpu_acquire_list, list) {
270 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
271                 BUG_ON(cur->exynos_gem_obj->resource_set == NULL);
272                 kds_resource_set_release(&cur->exynos_gem_obj->resource_set);
273 #endif
274                 drm_gem_object_unreference(&cur->exynos_gem_obj->base);
275                 kfree(cur);
276         }
277         mutex_unlock(&dev->struct_mutex);
278         INIT_LIST_HEAD(&file_private->gem_cpu_acquire_list);
279
280         exynos_drm_subdrv_close(dev, file);
281 }
282
283 static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
284 {
285         DRM_DEBUG("[DEV:%s]\n", dev->devname);
286
287         if (!file->driver_priv)
288                 return;
289
290         kfree(file->driver_priv);
291         file->driver_priv = NULL;
292 }
293
294 static void exynos_drm_lastclose(struct drm_device *dev)
295 {
296         DRM_DEBUG("[DEV:%s]\n", dev->devname);
297
298         exynos_drm_fbdev_restore_mode(dev);
299 }
300
301 static struct vm_operations_struct exynos_drm_gem_vm_ops = {
302         .fault = exynos_drm_gem_fault,
303         .open = drm_gem_vm_open,
304         .close = drm_gem_vm_close,
305 };
306
307 static struct drm_ioctl_desc exynos_ioctls[] = {
308         DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
309                         DRM_UNLOCKED | DRM_AUTH),
310         DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET,
311                         exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
312                         DRM_AUTH),
313         DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP,
314                         exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
315         DRM_IOCTL_DEF_DRV(EXYNOS_PLANE_SET_ZPOS, exynos_plane_set_zpos_ioctl,
316                         DRM_UNLOCKED | DRM_AUTH),
317         DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION,
318                         vidi_connection_ioctl, DRM_UNLOCKED | DRM_AUTH),
319         DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CPU_ACQUIRE,
320                         exynos_drm_gem_cpu_acquire_ioctl,
321                         DRM_UNLOCKED | DRM_AUTH),
322         DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CPU_RELEASE,
323                         exynos_drm_gem_cpu_release_ioctl,
324                         DRM_UNLOCKED | DRM_AUTH),
325 };
326
327 static const struct file_operations exynos_drm_driver_fops = {
328         .owner          = THIS_MODULE,
329         .open           = drm_open,
330         .mmap           = exynos_drm_gem_mmap,
331         .poll           = drm_poll,
332         .read           = drm_read,
333         .unlocked_ioctl = drm_ioctl,
334         .release        = drm_release,
335 };
336
337 static struct drm_driver exynos_drm_driver = {
338         .driver_features        = DRIVER_HAVE_IRQ | DRIVER_BUS_PLATFORM |
339                                   DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME,
340         .load                   = exynos_drm_load,
341         .unload                 = exynos_drm_unload,
342         .open                   = exynos_drm_open,
343         .preclose               = exynos_drm_preclose,
344         .lastclose              = exynos_drm_lastclose,
345         .postclose              = exynos_drm_postclose,
346         .get_vblank_counter     = drm_vblank_count,
347         .enable_vblank          = exynos_drm_crtc_enable_vblank,
348         .disable_vblank         = exynos_drm_crtc_disable_vblank,
349 #if defined(CONFIG_DEBUG_FS)
350         .debugfs_init           = exynos_drm_debugfs_init,
351         .debugfs_cleanup        = exynos_drm_debugfs_cleanup,
352 #endif
353         .gem_free_object        = exynos_drm_gem_free_object,
354         .gem_vm_ops             = &exynos_drm_gem_vm_ops,
355         .dumb_create            = exynos_drm_gem_dumb_create,
356         .dumb_map_offset        = exynos_drm_gem_dumb_map_offset,
357         .dumb_destroy           = exynos_drm_gem_dumb_destroy,
358         .prime_handle_to_fd     = drm_gem_prime_handle_to_fd,
359         .prime_fd_to_handle     = drm_gem_prime_fd_to_handle,
360         .gem_prime_export       = exynos_dmabuf_prime_export,
361         .gem_prime_import       = exynos_dmabuf_prime_import,
362         .ioctls                 = exynos_ioctls,
363         .fops                   = &exynos_drm_driver_fops,
364         .name   = DRIVER_NAME,
365         .desc   = DRIVER_DESC,
366         .date   = DRIVER_DATE,
367         .major  = DRIVER_MAJOR,
368         .minor  = DRIVER_MINOR,
369 };
370
371 #ifdef CONFIG_EXYNOS_IOMMU
372 static int iommu_init(struct platform_device *pdev)
373 {
374         /* DRM device expects a IOMMU mapping to be already
375          * created in FIMD. Else this function should
376          * throw an error.
377          */
378         if (exynos_drm_common_mapping==NULL) {
379                 printk(KERN_ERR "exynos drm common mapping is invalid\n");
380                 return -1;
381         }
382
383         /*
384          * The ordering in Makefile warrants that this is initialized after
385          * FIMD, so only just ensure that it works as expected and we are
386          * reusing the mapping originally created in exynos_drm_fimd.c.
387          */
388         WARN_ON(!exynos_drm_common_mapping);
389         if (!s5p_create_iommu_mapping(&pdev->dev, 0,
390                                 0, 0, exynos_drm_common_mapping)) {
391                 printk(KERN_ERR "failed to create IOMMU mapping\n");
392                 return -1;
393         }
394
395         return 0;
396 }
397
398 static void iommu_deinit(struct platform_device *pdev)
399 {
400         /* detach the device and mapping */
401         s5p_destroy_iommu_mapping(&pdev->dev);
402         DRM_DEBUG("released the IOMMU mapping\n");
403
404         return;
405 }
406 #endif
407
408 static int exynos_drm_platform_probe(struct platform_device *pdev)
409 {
410         struct device *dev = &pdev->dev;
411         int ret;
412
413         DRM_DEBUG("[PDEV:%s]\n", pdev->name);
414
415 #ifdef CONFIG_EXYNOS_IOMMU
416         if (iommu_init(pdev)) {
417                 DRM_ERROR("failed to initialize IOMMU\n");
418                 return -ENODEV;
419         }
420 #endif
421
422         exynos_drm_driver.num_ioctls = DRM_ARRAY_SIZE(exynos_ioctls);
423
424         pm_vt_switch_required(dev, false);
425         pm_runtime_enable(dev);
426         pm_runtime_get_sync(dev);
427
428         ret = drm_platform_init(&exynos_drm_driver, pdev);
429 #ifdef CONFIG_EXYNOS_IOMMU
430         if (ret)
431                 iommu_deinit(pdev);
432 #endif
433
434         return ret;
435 }
436
437 static int __devexit exynos_drm_platform_remove(struct platform_device *pdev)
438 {
439         struct device *dev = &pdev->dev;
440
441         DRM_DEBUG("[PDEV:%s]\n", pdev->name);
442
443         pm_vt_switch_unregister(dev);
444         pm_runtime_disable(dev);
445
446         drm_platform_exit(&exynos_drm_driver, pdev);
447
448 #ifdef CONFIG_EXYNOS_IOMMU
449         iommu_deinit(pdev);
450 #endif
451         return 0;
452 }
453
454 const char *exynos_display_type_name(const struct exynos_drm_display *display)
455 {
456         switch (display->display_type) {
457         case EXYNOS_DRM_DISPLAY_TYPE_FIMD:
458                 return "FIMD";
459         case EXYNOS_DRM_DISPLAY_TYPE_MIXER:
460                 return "MIXER";
461         case EXYNOS_DRM_DISPLAY_TYPE_VIDI:
462                 return "VIDI";
463         default:
464                 return "?";
465         }
466 }
467
468 void exynos_display_attach_panel(enum exynos_drm_display_type type,
469                 struct exynos_panel_ops *ops, void *ctx)
470 {
471         int i;
472         for (i = 0; i < EXYNOS_DRM_DISPLAY_NUM_DISPLAYS; i++) {
473                 if (displays[i]->display_type == type) {
474                         displays[i]->panel_ctx = ctx;
475                         displays[i]->panel_ops = ops;
476                         return;
477                 }
478         }
479 }
480
481 void exynos_display_attach_controller(enum exynos_drm_display_type type,
482                 struct exynos_controller_ops *ops, void *ctx)
483 {
484         int i;
485         for (i = 0; i < EXYNOS_DRM_DISPLAY_NUM_DISPLAYS; i++) {
486                 if (displays[i]->display_type == type) {
487                         displays[i]->controller_ctx = ctx;
488                         displays[i]->controller_ops = ops;
489                         return;
490                 }
491         }
492 }
493
494 static int display_subdrv_probe(struct drm_device *drm_dev,
495                 struct exynos_drm_subdrv *subdrv)
496 {
497         struct exynos_drm_display *display = subdrv->display;
498         int ret;
499
500         if (!display->controller_ops || !display->panel_ops)
501                 return -EINVAL;
502
503         if (display->controller_ops->subdrv_probe) {
504                 ret = display->controller_ops->subdrv_probe(
505                                 display->controller_ctx, drm_dev);
506                 if (ret)
507                         return ret;
508         }
509
510         if (display->panel_ops->subdrv_probe) {
511                 ret = display->panel_ops->subdrv_probe(display->panel_ctx,
512                                 drm_dev);
513                 if (ret)
514                         return ret;
515         }
516
517         return 0;
518 }
519
520 int exynos_display_init(struct exynos_drm_display *display,
521                 enum exynos_drm_display_type type)
522 {
523         struct exynos_drm_subdrv *subdrv;
524
525         subdrv = kzalloc(sizeof(*subdrv), GFP_KERNEL);
526         if (!subdrv) {
527                 DRM_ERROR("Failed to allocate display subdrv\n");
528                 return -ENOMEM;
529         }
530
531         display->display_type = type;
532         display->pipe = -1;
533         display->subdrv = subdrv;
534
535         subdrv->probe = display_subdrv_probe;
536         subdrv->display = display;
537         exynos_drm_subdrv_register(subdrv);
538
539         return 0;
540 }
541
542 void exynos_display_remove(struct exynos_drm_display *display)
543 {
544         if (display->subdrv) {
545                 exynos_drm_subdrv_unregister(display->subdrv);
546                 kfree(display->subdrv);
547         }
548 }
549
550 static int exynos_drm_resume_displays(struct drm_device *dev)
551 {
552         int i;
553
554         for (i = 0; i < EXYNOS_DRM_DISPLAY_NUM_DISPLAYS; i++) {
555                 struct exynos_drm_display *display = displays[i];
556                 struct drm_connector *connector = display->subdrv->connector;
557
558                 if (!connector || !connector->funcs->dpms)
559                         continue;
560
561                 connector->funcs->dpms(connector, display->suspend_dpms);
562         }
563
564         drm_helper_resume_force_mode(dev);
565
566         return 0;
567 }
568
569 static int exynos_drm_suspend_displays(void)
570 {
571         int i;
572
573         for (i = 0; i < EXYNOS_DRM_DISPLAY_NUM_DISPLAYS; i++) {
574                 struct exynos_drm_display *display = displays[i];
575                 struct drm_connector *connector = display->subdrv->connector;
576
577                 if (!connector)
578                         continue;
579
580                 display->suspend_dpms = connector->dpms;
581                 if (connector->funcs->dpms)
582                         connector->funcs->dpms(connector, DRM_MODE_DPMS_OFF);
583         }
584         return 0;
585 }
586
587 #ifdef CONFIG_PM_SLEEP
588 static int exynos_drm_suspend(struct device *dev)
589 {
590         if (pm_runtime_suspended(dev))
591                 return 0;
592
593         return exynos_drm_suspend_displays();
594 }
595
596 static int exynos_drm_resume(struct device *dev)
597 {
598         struct platform_device *pdev = to_platform_device(dev);
599         struct drm_device *drm_dev = platform_get_drvdata(pdev);
600
601         if (pm_runtime_suspended(dev))
602                 return 0;
603
604         return exynos_drm_resume_displays(drm_dev);
605 }
606 #endif
607
608 #ifdef CONFIG_PM_RUNTIME
609 static int exynos_drm_runtime_resume(struct device *dev)
610 {
611         struct platform_device *pdev = to_platform_device(dev);
612         struct drm_device *drm_dev = platform_get_drvdata(pdev);
613
614         /* Check drm_dev here since this function is called from probe */
615         if (!drm_dev)
616                 return 0;
617
618         return exynos_drm_resume_displays(drm_dev);
619 }
620
621 static int exynos_drm_runtime_suspend(struct device *dev)
622 {
623         return exynos_drm_suspend_displays();
624 }
625 #endif
626
627 static const struct dev_pm_ops drm_pm_ops = {
628         SET_SYSTEM_SLEEP_PM_OPS(exynos_drm_suspend, exynos_drm_resume)
629         SET_RUNTIME_PM_OPS(exynos_drm_runtime_suspend,
630                         exynos_drm_runtime_resume, NULL)
631 };
632
633 static struct platform_driver exynos_drm_platform_driver = {
634         .probe          = exynos_drm_platform_probe,
635         .remove         = __devexit_p(exynos_drm_platform_remove),
636         .driver         = {
637                 .owner  = THIS_MODULE,
638                 .name   = "exynos-drm",
639                 .pm     = &drm_pm_ops,
640         },
641 };
642
643 static int __init exynos_drm_init(void)
644 {
645         int ret, i;
646
647         DRM_DEBUG_DRIVER("\n");
648
649         for (i = 0; i < EXYNOS_DRM_DISPLAY_NUM_DISPLAYS; i++) {
650                 displays[i] = kzalloc(sizeof(*displays[i]), GFP_KERNEL);
651                 if (!displays[i]) {
652                         ret = -ENOMEM;
653                         goto out_display;
654                 }
655
656                 ret = exynos_display_init(displays[i], i);
657                 if (ret)
658                         goto out_display;
659         }
660
661 #ifdef CONFIG_DRM_EXYNOS_FIMD
662         ret = platform_driver_register(&fimd_driver);
663         if (ret < 0)
664                 goto out_fimd;
665 #endif
666
667 #ifdef CONFIG_DRM_EXYNOS_DP
668         ret = platform_driver_register(&dp_driver);
669         if (ret < 0)
670                 goto out_dp_driver;
671 #endif
672
673 #ifdef CONFIG_DRM_EXYNOS_HDMI
674         ret = platform_driver_register(&hdmi_driver);
675         if (ret < 0)
676                 goto out_hdmi;
677         ret = platform_driver_register(&mixer_driver);
678         if (ret < 0)
679                 goto out_mixer;
680 #endif
681
682 #ifdef CONFIG_DRM_EXYNOS_VIDI
683         ret = platform_driver_register(&vidi_driver);
684         if (ret < 0)
685                 goto out_vidi;
686 #endif
687
688         ret = platform_driver_register(&exynos_drm_platform_driver);
689         if (ret < 0)
690                 goto out;
691
692         return 0;
693
694 out:
695 #ifdef CONFIG_DRM_EXYNOS_VIDI
696 out_vidi:
697         platform_driver_unregister(&vidi_driver);
698 #endif
699
700 #ifdef CONFIG_DRM_EXYNOS_HDMI
701         platform_driver_unregister(&mixer_driver);
702 out_mixer:
703         platform_driver_unregister(&hdmi_driver);
704 out_hdmi:
705 #endif
706
707         platform_driver_unregister(&dp_driver);
708 out_dp_driver:
709 #ifdef CONFIG_DRM_EXYNOS_FIMD
710         platform_driver_unregister(&fimd_driver);
711 out_fimd:
712 #endif
713 out_display:
714         for (i = 0; i < EXYNOS_DRM_DISPLAY_NUM_DISPLAYS; i++) {
715                 if (!displays[i])
716                         continue;
717
718                 exynos_display_remove(displays[i]);
719                 kfree(displays[i]);
720         }
721         return ret;
722 }
723
724 static void __exit exynos_drm_exit(void)
725 {
726         int i;
727
728         DRM_DEBUG_DRIVER("\n");
729
730         platform_driver_unregister(&exynos_drm_platform_driver);
731
732 #ifdef CONFIG_DRM_EXYNOS_HDMI
733         platform_driver_unregister(&mixer_driver);
734         platform_driver_unregister(&hdmi_driver);
735 #endif
736
737 #ifdef CONFIG_DRM_EXYNOS_VIDI
738         platform_driver_unregister(&vidi_driver);
739 #endif
740
741         platform_driver_unregister(&dp_driver);
742 #ifdef CONFIG_DRM_EXYNOS_FIMD
743         platform_driver_unregister(&fimd_driver);
744 #endif
745
746         for (i = 0; i < EXYNOS_DRM_DISPLAY_NUM_DISPLAYS; i++) {
747                 if (!displays[i])
748                         continue;
749
750                 exynos_display_remove(displays[i]);
751                 kfree(displays[i]);
752         }
753 }
754
755 module_init(exynos_drm_init);
756 module_exit(exynos_drm_exit);
757
758 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
759 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
760 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
761 MODULE_DESCRIPTION("Samsung SoC DRM Driver");
762 MODULE_LICENSE("GPL");