drm/exynos: fix null pointer dereference issue
[linux-2.6/btrfs-unstable.git] / drivers / gpu / drm / exynos / exynos_drm_drv.c
blobf0bcdc61778bfb799fe4c7b0151583bec2fda3a2
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>
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.
14 #include <linux/pm_runtime.h>
15 #include <drm/drmP.h>
16 #include <drm/drm_crtc_helper.h>
18 #include <linux/component.h>
20 #include <drm/exynos_drm.h>
22 #include "exynos_drm_drv.h"
23 #include "exynos_drm_crtc.h"
24 #include "exynos_drm_encoder.h"
25 #include "exynos_drm_fbdev.h"
26 #include "exynos_drm_fb.h"
27 #include "exynos_drm_gem.h"
28 #include "exynos_drm_plane.h"
29 #include "exynos_drm_vidi.h"
30 #include "exynos_drm_dmabuf.h"
31 #include "exynos_drm_g2d.h"
32 #include "exynos_drm_ipp.h"
33 #include "exynos_drm_iommu.h"
35 #define DRIVER_NAME "exynos"
36 #define DRIVER_DESC "Samsung SoC DRM"
37 #define DRIVER_DATE "20110530"
38 #define DRIVER_MAJOR 1
39 #define DRIVER_MINOR 0
41 static struct platform_device *exynos_drm_pdev;
43 static DEFINE_MUTEX(drm_component_lock);
44 static LIST_HEAD(drm_component_list);
46 struct component_dev {
47 struct list_head list;
48 struct device *crtc_dev;
49 struct device *conn_dev;
50 enum exynos_drm_output_type out_type;
51 unsigned int dev_type_flag;
54 static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
56 struct exynos_drm_private *private;
57 int ret;
58 int nr;
60 private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
61 if (!private)
62 return -ENOMEM;
64 INIT_LIST_HEAD(&private->pageflip_event_list);
65 dev_set_drvdata(dev->dev, dev);
66 dev->dev_private = (void *)private;
69 * create mapping to manage iommu table and set a pointer to iommu
70 * mapping structure to iommu_mapping of private data.
71 * also this iommu_mapping can be used to check if iommu is supported
72 * or not.
74 ret = drm_create_iommu_mapping(dev);
75 if (ret < 0) {
76 DRM_ERROR("failed to create iommu mapping.\n");
77 goto err_free_private;
80 drm_mode_config_init(dev);
82 exynos_drm_mode_config_init(dev);
84 for (nr = 0; nr < MAX_PLANE; nr++) {
85 struct drm_plane *plane;
86 unsigned long possible_crtcs = (1 << MAX_CRTC) - 1;
88 plane = exynos_plane_init(dev, possible_crtcs,
89 DRM_PLANE_TYPE_OVERLAY);
90 if (!IS_ERR(plane))
91 continue;
93 ret = PTR_ERR(plane);
94 goto err_mode_config_cleanup;
97 /* setup possible_clones. */
98 exynos_drm_encoder_setup(dev);
100 platform_set_drvdata(dev->platformdev, dev);
102 /* Try to bind all sub drivers. */
103 ret = component_bind_all(dev->dev, dev);
104 if (ret)
105 goto err_mode_config_cleanup;
107 ret = drm_vblank_init(dev, dev->mode_config.num_crtc);
108 if (ret)
109 goto err_unbind_all;
112 * enable drm irq mode.
113 * - with irq_enabled = true, we can use the vblank feature.
115 * P.S. note that we wouldn't use drm irq handler but
116 * just specific driver own one instead because
117 * drm framework supports only one irq handler.
119 dev->irq_enabled = true;
122 * with vblank_disable_allowed = true, vblank interrupt will be disabled
123 * by drm timer once a current process gives up ownership of
124 * vblank event.(after drm_vblank_put function is called)
126 dev->vblank_disable_allowed = true;
128 /* init kms poll for handling hpd */
129 drm_kms_helper_poll_init(dev);
131 /* force connectors detection */
132 drm_helper_hpd_irq_event(dev);
134 return 0;
136 err_unbind_all:
137 component_unbind_all(dev->dev, dev);
138 err_mode_config_cleanup:
139 drm_mode_config_cleanup(dev);
140 drm_release_iommu_mapping(dev);
141 err_free_private:
142 kfree(private);
144 return ret;
147 static int exynos_drm_unload(struct drm_device *dev)
149 exynos_drm_fbdev_fini(dev);
150 drm_kms_helper_poll_fini(dev);
152 drm_vblank_cleanup(dev);
153 component_unbind_all(dev->dev, dev);
154 drm_mode_config_cleanup(dev);
155 drm_release_iommu_mapping(dev);
157 kfree(dev->dev_private);
158 dev->dev_private = NULL;
160 return 0;
163 static int exynos_drm_suspend(struct drm_device *dev, pm_message_t state)
165 struct drm_connector *connector;
167 drm_modeset_lock_all(dev);
168 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
169 int old_dpms = connector->dpms;
171 if (connector->funcs->dpms)
172 connector->funcs->dpms(connector, DRM_MODE_DPMS_OFF);
174 /* Set the old mode back to the connector for resume */
175 connector->dpms = old_dpms;
177 drm_modeset_unlock_all(dev);
179 return 0;
182 static int exynos_drm_resume(struct drm_device *dev)
184 struct drm_connector *connector;
186 drm_modeset_lock_all(dev);
187 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
188 if (connector->funcs->dpms) {
189 int dpms = connector->dpms;
191 connector->dpms = DRM_MODE_DPMS_OFF;
192 connector->funcs->dpms(connector, dpms);
195 drm_modeset_unlock_all(dev);
197 drm_helper_resume_force_mode(dev);
199 return 0;
202 static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
204 struct drm_exynos_file_private *file_priv;
205 int ret;
207 file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL);
208 if (!file_priv)
209 return -ENOMEM;
211 file->driver_priv = file_priv;
213 ret = exynos_drm_subdrv_open(dev, file);
214 if (ret)
215 goto err_file_priv_free;
217 return ret;
219 err_file_priv_free:
220 kfree(file_priv);
221 file->driver_priv = NULL;
222 return ret;
225 static void exynos_drm_preclose(struct drm_device *dev,
226 struct drm_file *file)
228 exynos_drm_subdrv_close(dev, file);
231 static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
233 struct exynos_drm_private *private = dev->dev_private;
234 struct drm_pending_vblank_event *v, *vt;
235 struct drm_pending_event *e, *et;
236 unsigned long flags;
238 if (!file->driver_priv)
239 return;
241 /* Release all events not unhandled by page flip handler. */
242 spin_lock_irqsave(&dev->event_lock, flags);
243 list_for_each_entry_safe(v, vt, &private->pageflip_event_list,
244 base.link) {
245 if (v->base.file_priv == file) {
246 list_del(&v->base.link);
247 drm_vblank_put(dev, v->pipe);
248 v->base.destroy(&v->base);
252 /* Release all events handled by page flip handler but not freed. */
253 list_for_each_entry_safe(e, et, &file->event_list, link) {
254 list_del(&e->link);
255 e->destroy(e);
257 spin_unlock_irqrestore(&dev->event_lock, flags);
259 kfree(file->driver_priv);
260 file->driver_priv = NULL;
263 static void exynos_drm_lastclose(struct drm_device *dev)
265 exynos_drm_fbdev_restore_mode(dev);
268 static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
269 .fault = exynos_drm_gem_fault,
270 .open = drm_gem_vm_open,
271 .close = drm_gem_vm_close,
274 static const struct drm_ioctl_desc exynos_ioctls[] = {
275 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
276 DRM_UNLOCKED | DRM_AUTH),
277 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_GET,
278 exynos_drm_gem_get_ioctl, DRM_UNLOCKED),
279 DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION,
280 vidi_connection_ioctl, DRM_UNLOCKED | DRM_AUTH),
281 DRM_IOCTL_DEF_DRV(EXYNOS_G2D_GET_VER,
282 exynos_g2d_get_ver_ioctl, DRM_UNLOCKED | DRM_AUTH),
283 DRM_IOCTL_DEF_DRV(EXYNOS_G2D_SET_CMDLIST,
284 exynos_g2d_set_cmdlist_ioctl, DRM_UNLOCKED | DRM_AUTH),
285 DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC,
286 exynos_g2d_exec_ioctl, DRM_UNLOCKED | DRM_AUTH),
287 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_GET_PROPERTY,
288 exynos_drm_ipp_get_property, DRM_UNLOCKED | DRM_AUTH),
289 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_SET_PROPERTY,
290 exynos_drm_ipp_set_property, DRM_UNLOCKED | DRM_AUTH),
291 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_QUEUE_BUF,
292 exynos_drm_ipp_queue_buf, DRM_UNLOCKED | DRM_AUTH),
293 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_CMD_CTRL,
294 exynos_drm_ipp_cmd_ctrl, DRM_UNLOCKED | DRM_AUTH),
297 static const struct file_operations exynos_drm_driver_fops = {
298 .owner = THIS_MODULE,
299 .open = drm_open,
300 .mmap = exynos_drm_gem_mmap,
301 .poll = drm_poll,
302 .read = drm_read,
303 .unlocked_ioctl = drm_ioctl,
304 #ifdef CONFIG_COMPAT
305 .compat_ioctl = drm_compat_ioctl,
306 #endif
307 .release = drm_release,
310 static struct drm_driver exynos_drm_driver = {
311 .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME,
312 .load = exynos_drm_load,
313 .unload = exynos_drm_unload,
314 .suspend = exynos_drm_suspend,
315 .resume = exynos_drm_resume,
316 .open = exynos_drm_open,
317 .preclose = exynos_drm_preclose,
318 .lastclose = exynos_drm_lastclose,
319 .postclose = exynos_drm_postclose,
320 .set_busid = drm_platform_set_busid,
321 .get_vblank_counter = drm_vblank_count,
322 .enable_vblank = exynos_drm_crtc_enable_vblank,
323 .disable_vblank = exynos_drm_crtc_disable_vblank,
324 .gem_free_object = exynos_drm_gem_free_object,
325 .gem_vm_ops = &exynos_drm_gem_vm_ops,
326 .dumb_create = exynos_drm_gem_dumb_create,
327 .dumb_map_offset = exynos_drm_gem_dumb_map_offset,
328 .dumb_destroy = drm_gem_dumb_destroy,
329 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
330 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
331 .gem_prime_export = exynos_dmabuf_prime_export,
332 .gem_prime_import = exynos_dmabuf_prime_import,
333 .ioctls = exynos_ioctls,
334 .num_ioctls = ARRAY_SIZE(exynos_ioctls),
335 .fops = &exynos_drm_driver_fops,
336 .name = DRIVER_NAME,
337 .desc = DRIVER_DESC,
338 .date = DRIVER_DATE,
339 .major = DRIVER_MAJOR,
340 .minor = DRIVER_MINOR,
343 #ifdef CONFIG_PM_SLEEP
344 static int exynos_drm_sys_suspend(struct device *dev)
346 struct drm_device *drm_dev = dev_get_drvdata(dev);
347 pm_message_t message;
349 if (pm_runtime_suspended(dev) || !drm_dev)
350 return 0;
352 message.event = PM_EVENT_SUSPEND;
353 return exynos_drm_suspend(drm_dev, message);
356 static int exynos_drm_sys_resume(struct device *dev)
358 struct drm_device *drm_dev = dev_get_drvdata(dev);
360 if (pm_runtime_suspended(dev) || !drm_dev)
361 return 0;
363 return exynos_drm_resume(drm_dev);
365 #endif
367 static const struct dev_pm_ops exynos_drm_pm_ops = {
368 SET_SYSTEM_SLEEP_PM_OPS(exynos_drm_sys_suspend, exynos_drm_sys_resume)
371 int exynos_drm_component_add(struct device *dev,
372 enum exynos_drm_device_type dev_type,
373 enum exynos_drm_output_type out_type)
375 struct component_dev *cdev;
377 if (dev_type != EXYNOS_DEVICE_TYPE_CRTC &&
378 dev_type != EXYNOS_DEVICE_TYPE_CONNECTOR) {
379 DRM_ERROR("invalid device type.\n");
380 return -EINVAL;
383 mutex_lock(&drm_component_lock);
386 * Make sure to check if there is a component which has two device
387 * objects, for connector and for encoder/connector.
388 * It should make sure that crtc and encoder/connector drivers are
389 * ready before exynos drm core binds them.
391 list_for_each_entry(cdev, &drm_component_list, list) {
392 if (cdev->out_type == out_type) {
394 * If crtc and encoder/connector device objects are
395 * added already just return.
397 if (cdev->dev_type_flag == (EXYNOS_DEVICE_TYPE_CRTC |
398 EXYNOS_DEVICE_TYPE_CONNECTOR)) {
399 mutex_unlock(&drm_component_lock);
400 return 0;
403 if (dev_type == EXYNOS_DEVICE_TYPE_CRTC) {
404 cdev->crtc_dev = dev;
405 cdev->dev_type_flag |= dev_type;
408 if (dev_type == EXYNOS_DEVICE_TYPE_CONNECTOR) {
409 cdev->conn_dev = dev;
410 cdev->dev_type_flag |= dev_type;
413 mutex_unlock(&drm_component_lock);
414 return 0;
418 mutex_unlock(&drm_component_lock);
420 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
421 if (!cdev)
422 return -ENOMEM;
424 if (dev_type == EXYNOS_DEVICE_TYPE_CRTC)
425 cdev->crtc_dev = dev;
426 if (dev_type == EXYNOS_DEVICE_TYPE_CONNECTOR)
427 cdev->conn_dev = dev;
429 cdev->out_type = out_type;
430 cdev->dev_type_flag = dev_type;
432 mutex_lock(&drm_component_lock);
433 list_add_tail(&cdev->list, &drm_component_list);
434 mutex_unlock(&drm_component_lock);
436 return 0;
439 void exynos_drm_component_del(struct device *dev,
440 enum exynos_drm_device_type dev_type)
442 struct component_dev *cdev, *next;
444 mutex_lock(&drm_component_lock);
446 list_for_each_entry_safe(cdev, next, &drm_component_list, list) {
447 if (dev_type == EXYNOS_DEVICE_TYPE_CRTC) {
448 if (cdev->crtc_dev == dev) {
449 cdev->crtc_dev = NULL;
450 cdev->dev_type_flag &= ~dev_type;
454 if (dev_type == EXYNOS_DEVICE_TYPE_CONNECTOR) {
455 if (cdev->conn_dev == dev) {
456 cdev->conn_dev = NULL;
457 cdev->dev_type_flag &= ~dev_type;
462 * Release cdev object only in case that both of crtc and
463 * encoder/connector device objects are NULL.
465 if (!cdev->crtc_dev && !cdev->conn_dev) {
466 list_del(&cdev->list);
467 kfree(cdev);
470 break;
473 mutex_unlock(&drm_component_lock);
476 static int compare_dev(struct device *dev, void *data)
478 return dev == (struct device *)data;
481 static struct component_match *exynos_drm_match_add(struct device *dev)
483 struct component_match *match = NULL;
484 struct component_dev *cdev;
485 unsigned int attach_cnt = 0;
487 mutex_lock(&drm_component_lock);
489 /* Do not retry to probe if there is no any kms driver regitered. */
490 if (list_empty(&drm_component_list)) {
491 mutex_unlock(&drm_component_lock);
492 return ERR_PTR(-ENODEV);
495 list_for_each_entry(cdev, &drm_component_list, list) {
497 * Add components to master only in case that crtc and
498 * encoder/connector device objects exist.
500 if (!cdev->crtc_dev || !cdev->conn_dev)
501 continue;
503 attach_cnt++;
505 mutex_unlock(&drm_component_lock);
508 * fimd and dpi modules have same device object so add
509 * only crtc device object in this case.
511 if (cdev->crtc_dev == cdev->conn_dev) {
512 component_match_add(dev, &match, compare_dev,
513 cdev->crtc_dev);
514 goto out_lock;
518 * Do not chage below call order.
519 * crtc device first should be added to master because
520 * connector/encoder need pipe number of crtc when they
521 * are created.
523 component_match_add(dev, &match, compare_dev, cdev->crtc_dev);
524 component_match_add(dev, &match, compare_dev, cdev->conn_dev);
526 out_lock:
527 mutex_lock(&drm_component_lock);
530 mutex_unlock(&drm_component_lock);
532 return attach_cnt ? match : ERR_PTR(-EPROBE_DEFER);
535 static int exynos_drm_bind(struct device *dev)
537 return drm_platform_init(&exynos_drm_driver, to_platform_device(dev));
540 static void exynos_drm_unbind(struct device *dev)
542 drm_put_dev(dev_get_drvdata(dev));
545 static const struct component_master_ops exynos_drm_ops = {
546 .bind = exynos_drm_bind,
547 .unbind = exynos_drm_unbind,
550 static int exynos_drm_platform_probe(struct platform_device *pdev)
552 struct component_match *match;
553 int ret;
555 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
556 exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls);
558 #ifdef CONFIG_DRM_EXYNOS_FIMD
559 ret = platform_driver_register(&fimd_driver);
560 if (ret < 0)
561 return ret;
562 #endif
564 #ifdef CONFIG_DRM_EXYNOS_DP
565 ret = platform_driver_register(&dp_driver);
566 if (ret < 0)
567 goto err_unregister_fimd_drv;
568 #endif
570 #ifdef CONFIG_DRM_EXYNOS_DSI
571 ret = platform_driver_register(&dsi_driver);
572 if (ret < 0)
573 goto err_unregister_dp_drv;
574 #endif
576 #ifdef CONFIG_DRM_EXYNOS_HDMI
577 ret = platform_driver_register(&mixer_driver);
578 if (ret < 0)
579 goto err_unregister_dsi_drv;
580 ret = platform_driver_register(&hdmi_driver);
581 if (ret < 0)
582 goto err_unregister_mixer_drv;
583 #endif
585 match = exynos_drm_match_add(&pdev->dev);
586 if (IS_ERR(match)) {
587 ret = PTR_ERR(match);
588 goto err_unregister_hdmi_drv;
591 ret = component_master_add_with_match(&pdev->dev, &exynos_drm_ops,
592 match);
593 if (ret < 0)
594 goto err_unregister_hdmi_drv;
596 #ifdef CONFIG_DRM_EXYNOS_G2D
597 ret = platform_driver_register(&g2d_driver);
598 if (ret < 0)
599 goto err_del_component_master;
600 #endif
602 #ifdef CONFIG_DRM_EXYNOS_FIMC
603 ret = platform_driver_register(&fimc_driver);
604 if (ret < 0)
605 goto err_unregister_g2d_drv;
606 #endif
608 #ifdef CONFIG_DRM_EXYNOS_ROTATOR
609 ret = platform_driver_register(&rotator_driver);
610 if (ret < 0)
611 goto err_unregister_fimc_drv;
612 #endif
614 #ifdef CONFIG_DRM_EXYNOS_GSC
615 ret = platform_driver_register(&gsc_driver);
616 if (ret < 0)
617 goto err_unregister_rotator_drv;
618 #endif
620 #ifdef CONFIG_DRM_EXYNOS_IPP
621 ret = platform_driver_register(&ipp_driver);
622 if (ret < 0)
623 goto err_unregister_gsc_drv;
625 ret = exynos_platform_device_ipp_register();
626 if (ret < 0)
627 goto err_unregister_ipp_drv;
628 #endif
630 /* Probe non kms sub drivers and virtual display driver. */
631 ret = exynos_drm_device_subdrv_probe(platform_get_drvdata(pdev));
632 if (ret)
633 goto err_unregister_resources;
635 return ret;
637 err_unregister_resources:
638 #ifdef CONFIG_DRM_EXYNOS_IPP
639 exynos_platform_device_ipp_unregister();
640 err_unregister_ipp_drv:
641 platform_driver_unregister(&ipp_driver);
642 err_unregister_gsc_drv:
643 #endif
645 #ifdef CONFIG_DRM_EXYNOS_GSC
646 platform_driver_unregister(&gsc_driver);
647 err_unregister_rotator_drv:
648 #endif
650 #ifdef CONFIG_DRM_EXYNOS_ROTATOR
651 platform_driver_unregister(&rotator_driver);
652 err_unregister_fimc_drv:
653 #endif
655 #ifdef CONFIG_DRM_EXYNOS_FIMC
656 platform_driver_unregister(&fimc_driver);
657 err_unregister_g2d_drv:
658 #endif
660 #ifdef CONFIG_DRM_EXYNOS_G2D
661 platform_driver_unregister(&g2d_driver);
662 err_del_component_master:
663 #endif
664 component_master_del(&pdev->dev, &exynos_drm_ops);
666 err_unregister_hdmi_drv:
667 #ifdef CONFIG_DRM_EXYNOS_HDMI
668 platform_driver_unregister(&hdmi_driver);
669 err_unregister_mixer_drv:
670 platform_driver_unregister(&mixer_driver);
671 err_unregister_dsi_drv:
672 #endif
674 #ifdef CONFIG_DRM_EXYNOS_DSI
675 platform_driver_unregister(&dsi_driver);
676 err_unregister_dp_drv:
677 #endif
679 #ifdef CONFIG_DRM_EXYNOS_DP
680 platform_driver_unregister(&dp_driver);
681 err_unregister_fimd_drv:
682 #endif
684 #ifdef CONFIG_DRM_EXYNOS_FIMD
685 platform_driver_unregister(&fimd_driver);
686 #endif
687 return ret;
690 static int exynos_drm_platform_remove(struct platform_device *pdev)
692 exynos_drm_device_subdrv_remove(platform_get_drvdata(pdev));
694 #ifdef CONFIG_DRM_EXYNOS_IPP
695 exynos_platform_device_ipp_unregister();
696 platform_driver_unregister(&ipp_driver);
697 #endif
699 #ifdef CONFIG_DRM_EXYNOS_GSC
700 platform_driver_unregister(&gsc_driver);
701 #endif
703 #ifdef CONFIG_DRM_EXYNOS_ROTATOR
704 platform_driver_unregister(&rotator_driver);
705 #endif
707 #ifdef CONFIG_DRM_EXYNOS_FIMC
708 platform_driver_unregister(&fimc_driver);
709 #endif
711 #ifdef CONFIG_DRM_EXYNOS_G2D
712 platform_driver_unregister(&g2d_driver);
713 #endif
715 #ifdef CONFIG_DRM_EXYNOS_HDMI
716 platform_driver_unregister(&mixer_driver);
717 platform_driver_unregister(&hdmi_driver);
718 #endif
720 #ifdef CONFIG_DRM_EXYNOS_FIMD
721 platform_driver_unregister(&fimd_driver);
722 #endif
724 #ifdef CONFIG_DRM_EXYNOS_DSI
725 platform_driver_unregister(&dsi_driver);
726 #endif
728 #ifdef CONFIG_DRM_EXYNOS_DP
729 platform_driver_unregister(&dp_driver);
730 #endif
731 component_master_del(&pdev->dev, &exynos_drm_ops);
732 return 0;
735 static struct platform_driver exynos_drm_platform_driver = {
736 .probe = exynos_drm_platform_probe,
737 .remove = exynos_drm_platform_remove,
738 .driver = {
739 .owner = THIS_MODULE,
740 .name = "exynos-drm",
741 .pm = &exynos_drm_pm_ops,
745 static int exynos_drm_init(void)
747 int ret;
750 * Register device object only in case of Exynos SoC.
752 * Below codes resolves temporarily infinite loop issue incurred
753 * by Exynos drm driver when using multi-platform kernel.
754 * So these codes will be replaced with more generic way later.
756 if (!of_machine_is_compatible("samsung,exynos3") &&
757 !of_machine_is_compatible("samsung,exynos4") &&
758 !of_machine_is_compatible("samsung,exynos5"))
759 return -ENODEV;
761 exynos_drm_pdev = platform_device_register_simple("exynos-drm", -1,
762 NULL, 0);
763 if (IS_ERR(exynos_drm_pdev))
764 return PTR_ERR(exynos_drm_pdev);
766 #ifdef CONFIG_DRM_EXYNOS_VIDI
767 ret = exynos_drm_probe_vidi();
768 if (ret < 0)
769 goto err_unregister_pd;
770 #endif
772 ret = platform_driver_register(&exynos_drm_platform_driver);
773 if (ret)
774 goto err_remove_vidi;
776 return 0;
778 err_remove_vidi:
779 #ifdef CONFIG_DRM_EXYNOS_VIDI
780 exynos_drm_remove_vidi();
782 err_unregister_pd:
783 #endif
784 platform_device_unregister(exynos_drm_pdev);
786 return ret;
789 static void exynos_drm_exit(void)
791 platform_driver_unregister(&exynos_drm_platform_driver);
792 #ifdef CONFIG_DRM_EXYNOS_VIDI
793 exynos_drm_remove_vidi();
794 #endif
795 platform_device_unregister(exynos_drm_pdev);
798 module_init(exynos_drm_init);
799 module_exit(exynos_drm_exit);
801 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
802 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
803 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
804 MODULE_DESCRIPTION("Samsung SoC DRM Driver");
805 MODULE_LICENSE("GPL");