aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/exynos/exynos_drm_drv.c
diff options
context:
space:
mode:
authorAndrzej Hajda <a.hajda@samsung.com>2015-06-11 10:20:52 -0400
committerInki Dae <daeinki@gmail.com>2015-06-19 11:32:55 -0400
commit417133e46924a9aa7bfa0e17dab01a1b475878c4 (patch)
tree23272a6c611178774a3077c4a132964388d4c752 /drivers/gpu/drm/exynos/exynos_drm_drv.c
parent38000dbb71ded4121b27338a2d41ad060001592a (diff)
drm/exynos: consolidate driver/device initialization code
Code registering different drivers and simple platform devices was dispersed across multiple sub-modules. This patch moves it to one place. As a result initialization code is shorter and cleaner and should simplify further development. Signed-off-by: Andrzej Hajda <a.hajda@samsung.com> Signed-off-by: Inki Dae <inki.dae@samsung.com>
Diffstat (limited to 'drivers/gpu/drm/exynos/exynos_drm_drv.c')
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_drv.c220
1 files changed, 138 insertions, 82 deletions
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
index 08b9a8caadb7..835dec1c8fea 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
@@ -38,8 +38,6 @@
38#define DRIVER_MAJOR 1 38#define DRIVER_MAJOR 1
39#define DRIVER_MINOR 0 39#define DRIVER_MINOR 0
40 40
41static struct platform_device *exynos_drm_pdev;
42
43static DEFINE_MUTEX(drm_component_lock); 41static DEFINE_MUTEX(drm_component_lock);
44static LIST_HEAD(drm_component_list); 42static LIST_HEAD(drm_component_list);
45 43
@@ -527,7 +525,40 @@ static const struct component_master_ops exynos_drm_ops = {
527 .unbind = exynos_drm_unbind, 525 .unbind = exynos_drm_unbind,
528}; 526};
529 527
528static int exynos_drm_platform_probe(struct platform_device *pdev)
529{
530 struct component_match *match;
531
532 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
533 exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls);
534
535 match = exynos_drm_match_add(&pdev->dev);
536 if (IS_ERR(match))
537 return PTR_ERR(match);
538
539 return component_master_add_with_match(&pdev->dev, &exynos_drm_ops,
540 match);
541}
542
543static int exynos_drm_platform_remove(struct platform_device *pdev)
544{
545 component_master_del(&pdev->dev, &exynos_drm_ops);
546 return 0;
547}
548
549static struct platform_driver exynos_drm_platform_driver = {
550 .probe = exynos_drm_platform_probe,
551 .remove = exynos_drm_platform_remove,
552 .driver = {
553 .name = "exynos-drm",
554 .pm = &exynos_drm_pm_ops,
555 },
556};
557
530static struct platform_driver *const exynos_drm_kms_drivers[] = { 558static struct platform_driver *const exynos_drm_kms_drivers[] = {
559#ifdef CONFIG_DRM_EXYNOS_VIDI
560 &vidi_driver,
561#endif
531#ifdef CONFIG_DRM_EXYNOS_FIMD 562#ifdef CONFIG_DRM_EXYNOS_FIMD
532 &fimd_driver, 563 &fimd_driver,
533#endif 564#endif
@@ -562,30 +593,109 @@ static struct platform_driver *const exynos_drm_non_kms_drivers[] = {
562#ifdef CONFIG_DRM_EXYNOS_IPP 593#ifdef CONFIG_DRM_EXYNOS_IPP
563 &ipp_driver, 594 &ipp_driver,
564#endif 595#endif
596 &exynos_drm_platform_driver,
565}; 597};
566 598
567static int exynos_drm_platform_probe(struct platform_device *pdev) 599
600static struct platform_driver *const exynos_drm_drv_with_simple_dev[] = {
601#ifdef CONFIG_DRM_EXYNOS_VIDI
602 &vidi_driver,
603#endif
604#ifdef CONFIG_DRM_EXYNOS_IPP
605 &ipp_driver,
606#endif
607 &exynos_drm_platform_driver,
608};
609
610#define PDEV_COUNT ARRAY_SIZE(exynos_drm_drv_with_simple_dev)
611
612static struct platform_device *exynos_drm_pdevs[PDEV_COUNT];
613
614static void exynos_drm_unregister_devices(void)
568{ 615{
569 struct component_match *match; 616 int i = PDEV_COUNT;
570 617
571 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); 618 while (--i >= 0) {
572 exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls); 619 platform_device_unregister(exynos_drm_pdevs[i]);
620 exynos_drm_pdevs[i] = NULL;
621 }
622}
573 623
574 match = exynos_drm_match_add(&pdev->dev); 624static int exynos_drm_register_devices(void)
575 if (IS_ERR(match)) { 625{
576 return PTR_ERR(match); 626 int i;
627
628 for (i = 0; i < PDEV_COUNT; ++i) {
629 struct platform_driver *d = exynos_drm_drv_with_simple_dev[i];
630 struct platform_device *pdev =
631 platform_device_register_simple(d->driver.name, -1,
632 NULL, 0);
633
634 if (!IS_ERR(pdev)) {
635 exynos_drm_pdevs[i] = pdev;
636 continue;
637 }
638 while (--i >= 0) {
639 platform_device_unregister(exynos_drm_pdevs[i]);
640 exynos_drm_pdevs[i] = NULL;
641 }
642
643 return PTR_ERR(pdev);
577 } 644 }
578 645
579 return component_master_add_with_match(&pdev->dev, &exynos_drm_ops, 646 return 0;
580 match);
581} 647}
582 648
583static int exynos_drm_platform_remove(struct platform_device *pdev) 649static void exynos_drm_unregister_drivers(struct platform_driver * const *drv,
650 int count)
584{ 651{
585 component_master_del(&pdev->dev, &exynos_drm_ops); 652 while (--count >= 0)
653 platform_driver_unregister(drv[count]);
654}
655
656static int exynos_drm_register_drivers(struct platform_driver * const *drv,
657 int count)
658{
659 int i, ret;
660
661 for (i = 0; i < count; ++i) {
662 ret = platform_driver_register(drv[i]);
663 if (!ret)
664 continue;
665
666 while (--i >= 0)
667 platform_driver_unregister(drv[i]);
668
669 return ret;
670 }
671
586 return 0; 672 return 0;
587} 673}
588 674
675static inline int exynos_drm_register_kms_drivers(void)
676{
677 return exynos_drm_register_drivers(exynos_drm_kms_drivers,
678 ARRAY_SIZE(exynos_drm_kms_drivers));
679}
680
681static inline int exynos_drm_register_non_kms_drivers(void)
682{
683 return exynos_drm_register_drivers(exynos_drm_non_kms_drivers,
684 ARRAY_SIZE(exynos_drm_non_kms_drivers));
685}
686
687static inline void exynos_drm_unregister_kms_drivers(void)
688{
689 exynos_drm_unregister_drivers(exynos_drm_kms_drivers,
690 ARRAY_SIZE(exynos_drm_kms_drivers));
691}
692
693static inline void exynos_drm_unregister_non_kms_drivers(void)
694{
695 exynos_drm_unregister_drivers(exynos_drm_non_kms_drivers,
696 ARRAY_SIZE(exynos_drm_non_kms_drivers));
697}
698
589static const char * const strings[] = { 699static const char * const strings[] = {
590 "samsung,exynos3", 700 "samsung,exynos3",
591 "samsung,exynos4", 701 "samsung,exynos4",
@@ -593,19 +703,10 @@ static const char * const strings[] = {
593 "samsung,exynos7", 703 "samsung,exynos7",
594}; 704};
595 705
596static struct platform_driver exynos_drm_platform_driver = {
597 .probe = exynos_drm_platform_probe,
598 .remove = exynos_drm_platform_remove,
599 .driver = {
600 .name = "exynos-drm",
601 .pm = &exynos_drm_pm_ops,
602 },
603};
604
605static int exynos_drm_init(void) 706static int exynos_drm_init(void)
606{ 707{
607 bool is_exynos = false; 708 bool is_exynos = false;
608 int ret, i, j; 709 int ret, i;
609 710
610 /* 711 /*
611 * Register device object only in case of Exynos SoC. 712 * Register device object only in case of Exynos SoC.
@@ -624,79 +725,34 @@ static int exynos_drm_init(void)
624 if (!is_exynos) 725 if (!is_exynos)
625 return -ENODEV; 726 return -ENODEV;
626 727
627 exynos_drm_pdev = platform_device_register_simple("exynos-drm", -1, 728 ret = exynos_drm_register_devices();
628 NULL, 0); 729 if (ret)
629 if (IS_ERR(exynos_drm_pdev)) 730 return ret;
630 return PTR_ERR(exynos_drm_pdev);
631
632 ret = exynos_drm_probe_vidi();
633 if (ret < 0)
634 goto err_unregister_pd;
635
636 for (i = 0; i < ARRAY_SIZE(exynos_drm_kms_drivers); ++i) {
637 ret = platform_driver_register(exynos_drm_kms_drivers[i]);
638 if (ret < 0)
639 goto err_unregister_kms_drivers;
640 }
641
642 for (j = 0; j < ARRAY_SIZE(exynos_drm_non_kms_drivers); ++j) {
643 ret = platform_driver_register(exynos_drm_non_kms_drivers[j]);
644 if (ret < 0)
645 goto err_unregister_non_kms_drivers;
646 }
647 731
648#ifdef CONFIG_DRM_EXYNOS_IPP 732 ret = exynos_drm_register_kms_drivers();
649 ret = exynos_platform_device_ipp_register(); 733 if (ret)
650 if (ret < 0) 734 goto err_unregister_pdevs;
651 goto err_unregister_non_kms_drivers;
652#endif
653 735
654 ret = platform_driver_register(&exynos_drm_platform_driver); 736 ret = exynos_drm_register_non_kms_drivers();
655 if (ret) 737 if (ret)
656 goto err_unregister_resources; 738 goto err_unregister_kms_drivers;
657 739
658 return 0; 740 return 0;
659 741
660err_unregister_resources:
661#ifdef CONFIG_DRM_EXYNOS_IPP
662 exynos_platform_device_ipp_unregister();
663#endif
664
665err_unregister_non_kms_drivers:
666 while (--j >= 0)
667 platform_driver_unregister(exynos_drm_non_kms_drivers[j]);
668
669err_unregister_kms_drivers: 742err_unregister_kms_drivers:
670 while (--i >= 0) 743 exynos_drm_unregister_kms_drivers();
671 platform_driver_unregister(exynos_drm_kms_drivers[i]);
672 744
673 exynos_drm_remove_vidi(); 745err_unregister_pdevs:
674 746 exynos_drm_unregister_devices();
675err_unregister_pd:
676 platform_device_unregister(exynos_drm_pdev);
677 747
678 return ret; 748 return ret;
679} 749}
680 750
681static void exynos_drm_exit(void) 751static void exynos_drm_exit(void)
682{ 752{
683 int i; 753 exynos_drm_unregister_non_kms_drivers();
684 754 exynos_drm_unregister_kms_drivers();
685#ifdef CONFIG_DRM_EXYNOS_IPP 755 exynos_drm_unregister_devices();
686 exynos_platform_device_ipp_unregister();
687#endif
688
689 for (i = ARRAY_SIZE(exynos_drm_non_kms_drivers) - 1; i >= 0; --i)
690 platform_driver_unregister(exynos_drm_non_kms_drivers[i]);
691
692 for (i = ARRAY_SIZE(exynos_drm_kms_drivers) - 1; i >= 0; --i)
693 platform_driver_unregister(exynos_drm_kms_drivers[i]);
694
695 platform_driver_unregister(&exynos_drm_platform_driver);
696
697 exynos_drm_remove_vidi();
698
699 platform_device_unregister(exynos_drm_pdev);
700} 756}
701 757
702module_init(exynos_drm_init); 758module_init(exynos_drm_init);