aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2011-02-22 22:13:26 -0500
committerGrant Likely <grant.likely@secretlab.ca>2011-02-28 15:22:43 -0500
commit55f19d56742a7b544e80b47339c17bfcfd0ff3b4 (patch)
tree49a576776b7da7535245de3938d93c9c4f04c91c
parenta1e9c9dd3383e6a1a762464ad604b1081774dbda (diff)
dt: xilinx_hwicap: merge platform and of_platform driver bindings
of_platform_driver is getting removed, and a single platform_driver can now support both devicetree and non-devicetree use cases. This patch merges the two driver registrations. Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: Stephen Neuendorffer <stephen.neuendorffer@xilinx.com>
-rw-r--r--drivers/char/xilinx_hwicap/xilinx_hwicap.c129
1 files changed, 47 insertions, 82 deletions
diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
index 9f2272e6de1c..d3c9d755ed98 100644
--- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
+++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
@@ -714,20 +714,29 @@ static int __devexit hwicap_remove(struct device *dev)
714 return 0; /* success */ 714 return 0; /* success */
715} 715}
716 716
717static int __devinit hwicap_drv_probe(struct platform_device *pdev) 717#ifdef CONFIG_OF
718static int __devinit hwicap_of_probe(struct platform_device *op)
718{ 719{
719 struct resource *res; 720 struct resource res;
720 const struct config_registers *regs; 721 const unsigned int *id;
721 const char *family; 722 const char *family;
723 int rc;
724 const struct hwicap_driver_config *config = op->dev.of_match->data;
725 const struct config_registers *regs;
722 726
723 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 727
724 if (!res) 728 rc = of_address_to_resource(op->dev.of_node, 0, &res);
725 return -ENODEV; 729 if (rc) {
730 dev_err(&op->dev, "invalid address\n");
731 return rc;
732 }
733
734 id = of_get_property(op->dev.of_node, "port-number", NULL);
726 735
727 /* It's most likely that we're using V4, if the family is not 736 /* It's most likely that we're using V4, if the family is not
728 specified */ 737 specified */
729 regs = &v4_config_registers; 738 regs = &v4_config_registers;
730 family = pdev->dev.platform_data; 739 family = of_get_property(op->dev.of_node, "xlnx,family", NULL);
731 740
732 if (family) { 741 if (family) {
733 if (!strcmp(family, "virtex2p")) { 742 if (!strcmp(family, "virtex2p")) {
@@ -738,54 +747,33 @@ static int __devinit hwicap_drv_probe(struct platform_device *pdev)
738 regs = &v5_config_registers; 747 regs = &v5_config_registers;
739 } 748 }
740 } 749 }
741 750 return hwicap_setup(&op->dev, id ? *id : -1, &res, config,
742 return hwicap_setup(&pdev->dev, pdev->id, res, 751 regs);
743 &buffer_icap_config, regs);
744} 752}
745 753#else
746static int __devexit hwicap_drv_remove(struct platform_device *pdev) 754static inline int hwicap_of_probe(struct platform_device *op)
747{ 755{
748 return hwicap_remove(&pdev->dev); 756 return -EINVAL;
749} 757}
758#endif /* CONFIG_OF */
750 759
751static struct platform_driver hwicap_platform_driver = { 760static int __devinit hwicap_drv_probe(struct platform_device *pdev)
752 .probe = hwicap_drv_probe,
753 .remove = hwicap_drv_remove,
754 .driver = {
755 .owner = THIS_MODULE,
756 .name = DRIVER_NAME,
757 },
758};
759
760/* ---------------------------------------------------------------------
761 * OF bus binding
762 */
763
764#if defined(CONFIG_OF)
765static int __devinit
766hwicap_of_probe(struct platform_device *op, const struct of_device_id *match)
767{ 761{
768 struct resource res; 762 struct resource *res;
769 const unsigned int *id;
770 const char *family;
771 int rc;
772 const struct hwicap_driver_config *config = match->data;
773 const struct config_registers *regs; 763 const struct config_registers *regs;
764 const char *family;
774 765
775 dev_dbg(&op->dev, "hwicap_of_probe(%p, %p)\n", op, match); 766 if (pdev->dev.of_match)
776 767 return hwicap_of_probe(pdev);
777 rc = of_address_to_resource(op->dev.of_node, 0, &res);
778 if (rc) {
779 dev_err(&op->dev, "invalid address\n");
780 return rc;
781 }
782 768
783 id = of_get_property(op->dev.of_node, "port-number", NULL); 769 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
770 if (!res)
771 return -ENODEV;
784 772
785 /* It's most likely that we're using V4, if the family is not 773 /* It's most likely that we're using V4, if the family is not
786 specified */ 774 specified */
787 regs = &v4_config_registers; 775 regs = &v4_config_registers;
788 family = of_get_property(op->dev.of_node, "xlnx,family", NULL); 776 family = pdev->dev.platform_data;
789 777
790 if (family) { 778 if (family) {
791 if (!strcmp(family, "virtex2p")) { 779 if (!strcmp(family, "virtex2p")) {
@@ -796,50 +784,38 @@ hwicap_of_probe(struct platform_device *op, const struct of_device_id *match)
796 regs = &v5_config_registers; 784 regs = &v5_config_registers;
797 } 785 }
798 } 786 }
799 return hwicap_setup(&op->dev, id ? *id : -1, &res, config, 787
800 regs); 788 return hwicap_setup(&pdev->dev, pdev->id, res,
789 &buffer_icap_config, regs);
801} 790}
802 791
803static int __devexit hwicap_of_remove(struct platform_device *op) 792static int __devexit hwicap_drv_remove(struct platform_device *pdev)
804{ 793{
805 return hwicap_remove(&op->dev); 794 return hwicap_remove(&pdev->dev);
806} 795}
807 796
808/* Match table for of_platform binding */ 797#ifdef CONFIG_OF
798/* Match table for device tree binding */
809static const struct of_device_id __devinitconst hwicap_of_match[] = { 799static const struct of_device_id __devinitconst hwicap_of_match[] = {
810 { .compatible = "xlnx,opb-hwicap-1.00.b", .data = &buffer_icap_config}, 800 { .compatible = "xlnx,opb-hwicap-1.00.b", .data = &buffer_icap_config},
811 { .compatible = "xlnx,xps-hwicap-1.00.a", .data = &fifo_icap_config}, 801 { .compatible = "xlnx,xps-hwicap-1.00.a", .data = &fifo_icap_config},
812 {}, 802 {},
813}; 803};
814MODULE_DEVICE_TABLE(of, hwicap_of_match); 804MODULE_DEVICE_TABLE(of, hwicap_of_match);
805#else
806#define hwicap_of_match NULL
807#endif
815 808
816static struct of_platform_driver hwicap_of_driver = { 809static struct platform_driver hwicap_platform_driver = {
817 .probe = hwicap_of_probe, 810 .probe = hwicap_drv_probe,
818 .remove = __devexit_p(hwicap_of_remove), 811 .remove = hwicap_drv_remove,
819 .driver = { 812 .driver = {
820 .name = DRIVER_NAME,
821 .owner = THIS_MODULE, 813 .owner = THIS_MODULE,
814 .name = DRIVER_NAME,
822 .of_match_table = hwicap_of_match, 815 .of_match_table = hwicap_of_match,
823 }, 816 },
824}; 817};
825 818
826/* Registration helpers to keep the number of #ifdefs to a minimum */
827static inline int __init hwicap_of_register(void)
828{
829 pr_debug("hwicap: calling of_register_platform_driver()\n");
830 return of_register_platform_driver(&hwicap_of_driver);
831}
832
833static inline void __exit hwicap_of_unregister(void)
834{
835 of_unregister_platform_driver(&hwicap_of_driver);
836}
837#else /* CONFIG_OF */
838/* CONFIG_OF not enabled; do nothing helpers */
839static inline int __init hwicap_of_register(void) { return 0; }
840static inline void __exit hwicap_of_unregister(void) { }
841#endif /* CONFIG_OF */
842
843static int __init hwicap_module_init(void) 819static int __init hwicap_module_init(void)
844{ 820{
845 dev_t devt; 821 dev_t devt;
@@ -856,21 +832,12 @@ static int __init hwicap_module_init(void)
856 return retval; 832 return retval;
857 833
858 retval = platform_driver_register(&hwicap_platform_driver); 834 retval = platform_driver_register(&hwicap_platform_driver);
859
860 if (retval)
861 goto failed1;
862
863 retval = hwicap_of_register();
864
865 if (retval) 835 if (retval)
866 goto failed2; 836 goto failed;
867 837
868 return retval; 838 return retval;
869 839
870 failed2: 840 failed:
871 platform_driver_unregister(&hwicap_platform_driver);
872
873 failed1:
874 unregister_chrdev_region(devt, HWICAP_DEVICES); 841 unregister_chrdev_region(devt, HWICAP_DEVICES);
875 842
876 return retval; 843 return retval;
@@ -884,8 +851,6 @@ static void __exit hwicap_module_cleanup(void)
884 851
885 platform_driver_unregister(&hwicap_platform_driver); 852 platform_driver_unregister(&hwicap_platform_driver);
886 853
887 hwicap_of_unregister();
888
889 unregister_chrdev_region(devt, HWICAP_DEVICES); 854 unregister_chrdev_region(devt, HWICAP_DEVICES);
890} 855}
891 856