]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
powerpc/sysdev: change CPM GPIO to platform_device
authorChristophe Leroy <christophe.leroy@c-s.fr>
Wed, 13 Dec 2017 11:26:23 +0000 (12:26 +0100)
committerScott Wood <oss@buserror.net>
Sun, 21 Jan 2018 05:29:02 +0000 (23:29 -0600)
Since commit 9427ecbed46cc ("gpio: Rework of_gpiochip_set_names()
to use device property accessors"), gpio chips have to have a
parent, otherwise devprop_gpiochip_set_names() prematurely exists
with message "GPIO chip parent is NULL" and doesn't proceed
'gpio-line-names' DT property.

This patch wraps the CPM GPIO into a platform driver to allow
assignment of the parent device.

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <oss@buserror.net>
arch/powerpc/include/asm/cpm.h
arch/powerpc/include/asm/cpm1.h
arch/powerpc/sysdev/Makefile
arch/powerpc/sysdev/cpm1.c
arch/powerpc/sysdev/cpm2.c
arch/powerpc/sysdev/cpm_common.c
arch/powerpc/sysdev/cpm_gpio.c [new file with mode: 0644]

index b925df1b87d0c357e8a769a50b070cce81275540..4c24ea8209bbabe16dc68336f9ab206c7932e7a0 100644 (file)
@@ -166,6 +166,6 @@ static inline int cpm_command(u32 command, u8 opcode)
 }
 #endif /* CONFIG_CPM */
 
-int cpm2_gpiochip_add32(struct device_node *np);
+int cpm2_gpiochip_add32(struct device *dev);
 
 #endif
index 3db821876d485a964040cb815843b0122282f7bb..a116fe9317892e93426c7904a3b70d3b098e3708 100644 (file)
@@ -605,5 +605,7 @@ enum cpm_clk {
 };
 
 int cpm1_clk_setup(enum cpm_clk_target target, int clock, int mode);
+int cpm1_gpiochip_add16(struct device *dev);
+int cpm1_gpiochip_add32(struct device *dev);
 
 #endif /* __CPM1__ */
index 0baba21404dcc0ec3f0342fca8f16d418be8fec2..fc31a271830b34b0d80181355f1d627b53068f4d 100644 (file)
@@ -43,7 +43,8 @@ obj-$(CONFIG_OF_RTC)          += of_rtc.o
 
 obj-$(CONFIG_CPM)              += cpm_common.o
 obj-$(CONFIG_CPM1)             += cpm1.o
-obj-$(CONFIG_CPM2)             += cpm2.o cpm2_pic.o
+obj-$(CONFIG_CPM2)             += cpm2.o cpm2_pic.o cpm_gpio.o
+obj-$(CONFIG_8xx_GPIO)         += cpm_gpio.o
 obj-$(CONFIG_QUICC_ENGINE)     += cpm_common.o
 obj-$(CONFIG_PPC_DCR)          += dcr.o
 obj-$(CONFIG_UCODE_PATCH)      += micropatch.o
index c6f154b602fb8b005480c3a369c45a5068d524da..5240d3a74a1076772fc48be35656ee50f4cf27fb 100644 (file)
@@ -629,8 +629,9 @@ static int cpm1_gpio16_dir_in(struct gpio_chip *gc, unsigned int gpio)
        return 0;
 }
 
-int cpm1_gpiochip_add16(struct device_node *np)
+int cpm1_gpiochip_add16(struct device *dev)
 {
+       struct device_node *np = dev->of_node;
        struct cpm1_gpio16_chip *cpm1_gc;
        struct of_mm_gpio_chip *mm_gc;
        struct gpio_chip *gc;
@@ -660,6 +661,8 @@ int cpm1_gpiochip_add16(struct device_node *np)
        gc->get = cpm1_gpio16_get;
        gc->set = cpm1_gpio16_set;
        gc->to_irq = cpm1_gpio16_to_irq;
+       gc->parent = dev;
+       gc->owner = THIS_MODULE;
 
        return of_mm_gpiochip_add_data(np, mm_gc, cpm1_gc);
 }
@@ -755,8 +758,9 @@ static int cpm1_gpio32_dir_in(struct gpio_chip *gc, unsigned int gpio)
        return 0;
 }
 
-int cpm1_gpiochip_add32(struct device_node *np)
+int cpm1_gpiochip_add32(struct device *dev)
 {
+       struct device_node *np = dev->of_node;
        struct cpm1_gpio32_chip *cpm1_gc;
        struct of_mm_gpio_chip *mm_gc;
        struct gpio_chip *gc;
@@ -776,31 +780,10 @@ int cpm1_gpiochip_add32(struct device_node *np)
        gc->direction_output = cpm1_gpio32_dir_out;
        gc->get = cpm1_gpio32_get;
        gc->set = cpm1_gpio32_set;
+       gc->parent = dev;
+       gc->owner = THIS_MODULE;
 
        return of_mm_gpiochip_add_data(np, mm_gc, cpm1_gc);
 }
 
-static int cpm_init_par_io(void)
-{
-       struct device_node *np;
-
-       for_each_compatible_node(np, NULL, "fsl,cpm1-pario-bank-a")
-               cpm1_gpiochip_add16(np);
-
-       for_each_compatible_node(np, NULL, "fsl,cpm1-pario-bank-b")
-               cpm1_gpiochip_add32(np);
-
-       for_each_compatible_node(np, NULL, "fsl,cpm1-pario-bank-c")
-               cpm1_gpiochip_add16(np);
-
-       for_each_compatible_node(np, NULL, "fsl,cpm1-pario-bank-d")
-               cpm1_gpiochip_add16(np);
-
-       /* Port E uses CPM2 layout */
-       for_each_compatible_node(np, NULL, "fsl,cpm1-pario-bank-e")
-               cpm2_gpiochip_add32(np);
-       return 0;
-}
-arch_initcall(cpm_init_par_io);
-
 #endif /* CONFIG_8xx_GPIO */
index f78ff841652c2fd2006b977db12e28447661aa87..07718b9a2c99b4fdd6e22f75cbc0f4f78b7e6866 100644 (file)
@@ -354,14 +354,3 @@ void cpm2_set_pin(int port, int pin, int flags)
        else
                clrbits32(&iop[port].odr, pin);
 }
-
-static int cpm_init_par_io(void)
-{
-       struct device_node *np;
-
-       for_each_compatible_node(np, NULL, "fsl,cpm2-pario-bank")
-               cpm2_gpiochip_add32(np);
-       return 0;
-}
-arch_initcall(cpm_init_par_io);
-
index 51bf749a4f3a7b6c8a245c8d793cee0cc47f9a51..b74508175b6777a5196236a249c947afc413bc00 100644 (file)
@@ -190,8 +190,9 @@ static int cpm2_gpio32_dir_in(struct gpio_chip *gc, unsigned int gpio)
        return 0;
 }
 
-int cpm2_gpiochip_add32(struct device_node *np)
+int cpm2_gpiochip_add32(struct device *dev)
 {
+       struct device_node *np = dev->of_node;
        struct cpm2_gpio32_chip *cpm2_gc;
        struct of_mm_gpio_chip *mm_gc;
        struct gpio_chip *gc;
@@ -211,6 +212,8 @@ int cpm2_gpiochip_add32(struct device_node *np)
        gc->direction_output = cpm2_gpio32_dir_out;
        gc->get = cpm2_gpio32_get;
        gc->set = cpm2_gpio32_set;
+       gc->parent = dev;
+       gc->owner = THIS_MODULE;
 
        return of_mm_gpiochip_add_data(np, mm_gc, cpm2_gc);
 }
diff --git a/arch/powerpc/sysdev/cpm_gpio.c b/arch/powerpc/sysdev/cpm_gpio.c
new file mode 100644 (file)
index 0000000..0badc90
--- /dev/null
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Common CPM GPIO wrapper for the CPM GPIO ports
+ *
+ * Author: Christophe Leroy <christophe.leroy@c-s.fr>
+ *
+ * Copyright 2017 CS Systemes d'Information.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/of_device.h>
+
+#include <asm/cpm.h>
+#ifdef CONFIG_8xx_GPIO
+#include <asm/cpm1.h>
+#endif
+
+static int cpm_gpio_probe(struct platform_device *ofdev)
+{
+       struct device *dev = &ofdev->dev;
+       int (*gp_add)(struct device *dev) = of_device_get_match_data(dev);
+
+       if (!gp_add)
+               return -ENODEV;
+
+       return gp_add(dev);
+}
+
+static const struct of_device_id cpm_gpio_match[] = {
+#ifdef CONFIG_8xx_GPIO
+       {
+               .compatible = "fsl,cpm1-pario-bank-a",
+               .data = cpm1_gpiochip_add16,
+       },
+       {
+               .compatible = "fsl,cpm1-pario-bank-b",
+               .data = cpm1_gpiochip_add32,
+       },
+       {
+               .compatible = "fsl,cpm1-pario-bank-c",
+               .data = cpm1_gpiochip_add16,
+       },
+       {
+               .compatible = "fsl,cpm1-pario-bank-d",
+               .data = cpm1_gpiochip_add16,
+       },
+       /* Port E uses CPM2 layout */
+       {
+               .compatible = "fsl,cpm1-pario-bank-e",
+               .data = cpm2_gpiochip_add32,
+       },
+#endif
+       {
+               .compatible = "fsl,cpm2-pario-bank",
+               .data = cpm2_gpiochip_add32,
+       },
+       {},
+};
+MODULE_DEVICE_TABLE(of, cpm_gpio_match);
+
+static struct platform_driver cpm_gpio_driver = {
+       .probe          = cpm_gpio_probe,
+       .driver         = {
+               .name   = "cpm-gpio",
+               .owner  = THIS_MODULE,
+               .of_match_table = cpm_gpio_match,
+       },
+};
+
+static int __init cpm_gpio_init(void)
+{
+       return platform_driver_register(&cpm_gpio_driver);
+}
+arch_initcall(cpm_gpio_init);
+
+MODULE_AUTHOR("Christophe Leroy <christophe.leroy@c-s.fr>");
+MODULE_DESCRIPTION("Driver for CPM GPIO");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:cpm-gpio");