Skip to content

Commit c095ff9

Browse files
chleroyScott Wood
authored andcommitted
powerpc/sysdev: change CPM GPIO to platform_device
Since commit 9427ecb ("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>
1 parent d038386 commit c095ff9

7 files changed

Lines changed: 97 additions & 39 deletions

File tree

‎arch/powerpc/include/asm/cpm.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,6 @@ static inline int cpm_command(u32 command, u8 opcode)
166166
}
167167
#endif /* CONFIG_CPM */
168168

169-
int cpm2_gpiochip_add32(struct device_node *np);
169+
int cpm2_gpiochip_add32(struct device *dev);
170170

171171
#endif

‎arch/powerpc/include/asm/cpm1.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,5 +605,7 @@ enum cpm_clk {
605605
};
606606

607607
int cpm1_clk_setup(enum cpm_clk_target target, int clock, int mode);
608+
int cpm1_gpiochip_add16(struct device *dev);
609+
int cpm1_gpiochip_add32(struct device *dev);
608610

609611
#endif /* __CPM1__ */

‎arch/powerpc/sysdev/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ obj-$(CONFIG_OF_RTC) += of_rtc.o
4343

4444
obj-$(CONFIG_CPM) += cpm_common.o
4545
obj-$(CONFIG_CPM1) += cpm1.o
46-
obj-$(CONFIG_CPM2) += cpm2.o cpm2_pic.o
46+
obj-$(CONFIG_CPM2) += cpm2.o cpm2_pic.o cpm_gpio.o
47+
obj-$(CONFIG_8xx_GPIO) += cpm_gpio.o
4748
obj-$(CONFIG_QUICC_ENGINE) += cpm_common.o
4849
obj-$(CONFIG_PPC_DCR) += dcr.o
4950
obj-$(CONFIG_UCODE_PATCH) += micropatch.o

‎arch/powerpc/sysdev/cpm1.c‎

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,9 @@ static int cpm1_gpio16_dir_in(struct gpio_chip *gc, unsigned int gpio)
629629
return 0;
630630
}
631631

632-
int cpm1_gpiochip_add16(struct device_node *np)
632+
int cpm1_gpiochip_add16(struct device *dev)
633633
{
634+
struct device_node *np = dev->of_node;
634635
struct cpm1_gpio16_chip *cpm1_gc;
635636
struct of_mm_gpio_chip *mm_gc;
636637
struct gpio_chip *gc;
@@ -660,6 +661,8 @@ int cpm1_gpiochip_add16(struct device_node *np)
660661
gc->get = cpm1_gpio16_get;
661662
gc->set = cpm1_gpio16_set;
662663
gc->to_irq = cpm1_gpio16_to_irq;
664+
gc->parent = dev;
665+
gc->owner = THIS_MODULE;
663666

664667
return of_mm_gpiochip_add_data(np, mm_gc, cpm1_gc);
665668
}
@@ -755,8 +758,9 @@ static int cpm1_gpio32_dir_in(struct gpio_chip *gc, unsigned int gpio)
755758
return 0;
756759
}
757760

758-
int cpm1_gpiochip_add32(struct device_node *np)
761+
int cpm1_gpiochip_add32(struct device *dev)
759762
{
763+
struct device_node *np = dev->of_node;
760764
struct cpm1_gpio32_chip *cpm1_gc;
761765
struct of_mm_gpio_chip *mm_gc;
762766
struct gpio_chip *gc;
@@ -776,31 +780,10 @@ int cpm1_gpiochip_add32(struct device_node *np)
776780
gc->direction_output = cpm1_gpio32_dir_out;
777781
gc->get = cpm1_gpio32_get;
778782
gc->set = cpm1_gpio32_set;
783+
gc->parent = dev;
784+
gc->owner = THIS_MODULE;
779785

780786
return of_mm_gpiochip_add_data(np, mm_gc, cpm1_gc);
781787
}
782788

783-
static int cpm_init_par_io(void)
784-
{
785-
struct device_node *np;
786-
787-
for_each_compatible_node(np, NULL, "fsl,cpm1-pario-bank-a")
788-
cpm1_gpiochip_add16(np);
789-
790-
for_each_compatible_node(np, NULL, "fsl,cpm1-pario-bank-b")
791-
cpm1_gpiochip_add32(np);
792-
793-
for_each_compatible_node(np, NULL, "fsl,cpm1-pario-bank-c")
794-
cpm1_gpiochip_add16(np);
795-
796-
for_each_compatible_node(np, NULL, "fsl,cpm1-pario-bank-d")
797-
cpm1_gpiochip_add16(np);
798-
799-
/* Port E uses CPM2 layout */
800-
for_each_compatible_node(np, NULL, "fsl,cpm1-pario-bank-e")
801-
cpm2_gpiochip_add32(np);
802-
return 0;
803-
}
804-
arch_initcall(cpm_init_par_io);
805-
806789
#endif /* CONFIG_8xx_GPIO */

‎arch/powerpc/sysdev/cpm2.c‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,3 @@ void cpm2_set_pin(int port, int pin, int flags)
354354
else
355355
clrbits32(&iop[port].odr, pin);
356356
}
357-
358-
static int cpm_init_par_io(void)
359-
{
360-
struct device_node *np;
361-
362-
for_each_compatible_node(np, NULL, "fsl,cpm2-pario-bank")
363-
cpm2_gpiochip_add32(np);
364-
return 0;
365-
}
366-
arch_initcall(cpm_init_par_io);
367-

‎arch/powerpc/sysdev/cpm_common.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ static int cpm2_gpio32_dir_in(struct gpio_chip *gc, unsigned int gpio)
190190
return 0;
191191
}
192192

193-
int cpm2_gpiochip_add32(struct device_node *np)
193+
int cpm2_gpiochip_add32(struct device *dev)
194194
{
195+
struct device_node *np = dev->of_node;
195196
struct cpm2_gpio32_chip *cpm2_gc;
196197
struct of_mm_gpio_chip *mm_gc;
197198
struct gpio_chip *gc;
@@ -211,6 +212,8 @@ int cpm2_gpiochip_add32(struct device_node *np)
211212
gc->direction_output = cpm2_gpio32_dir_out;
212213
gc->get = cpm2_gpio32_get;
213214
gc->set = cpm2_gpio32_set;
215+
gc->parent = dev;
216+
gc->owner = THIS_MODULE;
214217

215218
return of_mm_gpiochip_add_data(np, mm_gc, cpm2_gc);
216219
}

‎arch/powerpc/sysdev/cpm_gpio.c‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Common CPM GPIO wrapper for the CPM GPIO ports
4+
*
5+
* Author: Christophe Leroy <christophe.leroy@c-s.fr>
6+
*
7+
* Copyright 2017 CS Systemes d'Information.
8+
*
9+
*/
10+
11+
#include <linux/module.h>
12+
#include <linux/of_device.h>
13+
14+
#include <asm/cpm.h>
15+
#ifdef CONFIG_8xx_GPIO
16+
#include <asm/cpm1.h>
17+
#endif
18+
19+
static int cpm_gpio_probe(struct platform_device *ofdev)
20+
{
21+
struct device *dev = &ofdev->dev;
22+
int (*gp_add)(struct device *dev) = of_device_get_match_data(dev);
23+
24+
if (!gp_add)
25+
return -ENODEV;
26+
27+
return gp_add(dev);
28+
}
29+
30+
static const struct of_device_id cpm_gpio_match[] = {
31+
#ifdef CONFIG_8xx_GPIO
32+
{
33+
.compatible = "fsl,cpm1-pario-bank-a",
34+
.data = cpm1_gpiochip_add16,
35+
},
36+
{
37+
.compatible = "fsl,cpm1-pario-bank-b",
38+
.data = cpm1_gpiochip_add32,
39+
},
40+
{
41+
.compatible = "fsl,cpm1-pario-bank-c",
42+
.data = cpm1_gpiochip_add16,
43+
},
44+
{
45+
.compatible = "fsl,cpm1-pario-bank-d",
46+
.data = cpm1_gpiochip_add16,
47+
},
48+
/* Port E uses CPM2 layout */
49+
{
50+
.compatible = "fsl,cpm1-pario-bank-e",
51+
.data = cpm2_gpiochip_add32,
52+
},
53+
#endif
54+
{
55+
.compatible = "fsl,cpm2-pario-bank",
56+
.data = cpm2_gpiochip_add32,
57+
},
58+
{},
59+
};
60+
MODULE_DEVICE_TABLE(of, cpm_gpio_match);
61+
62+
static struct platform_driver cpm_gpio_driver = {
63+
.probe = cpm_gpio_probe,
64+
.driver = {
65+
.name = "cpm-gpio",
66+
.owner = THIS_MODULE,
67+
.of_match_table = cpm_gpio_match,
68+
},
69+
};
70+
71+
static int __init cpm_gpio_init(void)
72+
{
73+
return platform_driver_register(&cpm_gpio_driver);
74+
}
75+
arch_initcall(cpm_gpio_init);
76+
77+
MODULE_AUTHOR("Christophe Leroy <christophe.leroy@c-s.fr>");
78+
MODULE_DESCRIPTION("Driver for CPM GPIO");
79+
MODULE_LICENSE("GPL");
80+
MODULE_ALIAS("platform:cpm-gpio");

0 commit comments

Comments
 (0)