[PATCH 03/10] ARM: pxa/gumstix: convert vbus gpio to use software nodes

Dmitry Torokhov posted 10 patches 1 year, 5 months ago
[PATCH 03/10] ARM: pxa/gumstix: convert vbus gpio to use software nodes
Posted by Dmitry Torokhov 1 year, 5 months ago
Switch vbus gpios from using a custom GPIO lookup table to software
properties using PROPERTY_ENTRY_GPIO() constructs which closely mimic
device tree gpio properties.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 arch/arm/mach-pxa/devices.c |  4 ++++
 arch/arm/mach-pxa/devices.h |  4 ++--
 arch/arm/mach-pxa/gumstix.c | 22 +++++++++-------------
 arch/arm/mach-pxa/pxa25x.c  |  1 +
 4 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/arch/arm/mach-pxa/devices.c b/arch/arm/mach-pxa/devices.c
index 7cc6db2d1615..e2758c94fd77 100644
--- a/arch/arm/mach-pxa/devices.c
+++ b/arch/arm/mach-pxa/devices.c
@@ -629,6 +629,10 @@ struct platform_device pxa27x_device_pwm1 = {
 };
 #endif /* CONFIG_PXA27x || CONFIG_PXA3xx */
 
+const struct software_node pxa2xx_gpiochip_node = {
+	.name	= "gpio-pxa",
+};
+
 struct resource pxa_resource_gpio[] = {
 	{
 		.start	= 0x40e00000,
diff --git a/arch/arm/mach-pxa/devices.h b/arch/arm/mach-pxa/devices.h
index 82c83939017a..b7c0e138ef61 100644
--- a/arch/arm/mach-pxa/devices.h
+++ b/arch/arm/mach-pxa/devices.h
@@ -53,8 +53,8 @@ extern struct platform_device pxa_device_asoc_ssp4;
 
 extern struct platform_device pxa25x_device_gpio;
 extern struct platform_device pxa27x_device_gpio;
-extern struct platform_device pxa3xx_device_gpio;
-extern struct platform_device pxa93x_device_gpio;
+
+extern const struct software_node pxa2xx_gpiochip_node;
 
 void __init pxa_register_device(struct platform_device *dev, void *data);
 void __init pxa2xx_set_dmac_info(struct mmp_dma_platdata *dma_pdata);
diff --git a/arch/arm/mach-pxa/gumstix.c b/arch/arm/mach-pxa/gumstix.c
index c9f0f62187bd..b9eddc691097 100644
--- a/arch/arm/mach-pxa/gumstix.c
+++ b/arch/arm/mach-pxa/gumstix.c
@@ -100,26 +100,22 @@ static void __init gumstix_mmc_init(void)
 #endif
 
 #ifdef CONFIG_USB_PXA25X
-static struct gpiod_lookup_table gumstix_gpio_vbus_gpiod_table = {
-	.dev_id = "gpio-vbus",
-	.table = {
-		GPIO_LOOKUP("gpio-pxa", GPIO_GUMSTIX_USB_GPIOn,
-			    "vbus", GPIO_ACTIVE_HIGH),
-		GPIO_LOOKUP("gpio-pxa", GPIO_GUMSTIX_USB_GPIOx,
-			    "pullup", GPIO_ACTIVE_HIGH),
-		{ },
-	},
+static const struct property_entry spitz_mci_props[] __initconst = {
+	PROPERTY_ENTRY_GPIO("vbus-gpios", &pxa2xx_gpiochip_node,
+			    GPIO_GUMSTIX_USB_GPIOn, GPIO_ACTIVE_HIGH),
+	PROPERTY_ENTRY_GPIO("pullup-gpios", &pxa2xx_gpiochip_node,
+			    GPIO_GUMSTIX_USB_GPIOx, GPIO_ACTIVE_HIGH),
+	{ }
 };
 
-static struct platform_device gumstix_gpio_vbus = {
+static const struct platform_device_info gumstix_gpio_vbus_info __initconst = {
 	.name	= "gpio-vbus",
-	.id	= -1,
+	.id	= PLATFORM_DEVID_NONE,
 };
 
 static void __init gumstix_udc_init(void)
 {
-	gpiod_add_lookup_table(&gumstix_gpio_vbus_gpiod_table);
-	platform_device_register(&gumstix_gpio_vbus);
+	platform_device_register_full(&gumstix_gpio_vbus_info);
 }
 #else
 static void gumstix_udc_init(void)
diff --git a/arch/arm/mach-pxa/pxa25x.c b/arch/arm/mach-pxa/pxa25x.c
index 2ab3d8d66466..03e34841fc00 100644
--- a/arch/arm/mach-pxa/pxa25x.c
+++ b/arch/arm/mach-pxa/pxa25x.c
@@ -239,6 +239,7 @@ static int __init pxa25x_init(void)
 		register_syscore_ops(&pxa2xx_mfp_syscore_ops);
 
 		if (!of_have_populated_dt()) {
+			software_node_register(&pxa2xx_gpiochip_node);
 			pxa2xx_set_dmac_info(&pxa25x_dma_pdata);
 			ret = platform_add_devices(pxa25x_devices,
 						   ARRAY_SIZE(pxa25x_devices));
-- 
2.45.2.803.g4e1b14247a-goog
Re: [PATCH 03/10] ARM: pxa/gumstix: convert vbus gpio to use software nodes
Posted by Arnd Bergmann 1 year, 4 months ago
On Fri, Jun 28, 2024, at 20:08, Dmitry Torokhov wrote:
> Switch vbus gpios from using a custom GPIO lookup table to software
> properties using PROPERTY_ENTRY_GPIO() constructs which closely mimic
> device tree gpio properties.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

I ran into some randconfig build failures with this one now:

> index c9f0f62187bd..b9eddc691097 100644
> --- a/arch/arm/mach-pxa/gumstix.c
> +++ b/arch/arm/mach-pxa/gumstix.c
> @@ -100,26 +100,22 @@ static void __init gumstix_mmc_init(void)
>  #endif
> 
>  #ifdef CONFIG_USB_PXA25X
> -static struct gpiod_lookup_table gumstix_gpio_vbus_gpiod_table = {
> -	.dev_id = "gpio-vbus",
> -	.table = {
> -		GPIO_LOOKUP("gpio-pxa", GPIO_GUMSTIX_USB_GPIOn,
> -			    "vbus", GPIO_ACTIVE_HIGH),
> -		GPIO_LOOKUP("gpio-pxa", GPIO_GUMSTIX_USB_GPIOx,
> -			    "pullup", GPIO_ACTIVE_HIGH),
> -		{ },
> -	},
> +static const struct property_entry spitz_mci_props[] __initconst = {
> +	PROPERTY_ENTRY_GPIO("vbus-gpios", &pxa2xx_gpiochip_node,
> +			    GPIO_GUMSTIX_USB_GPIOn, GPIO_ACTIVE_HIGH),
> +	PROPERTY_ENTRY_GPIO("pullup-gpios", &pxa2xx_gpiochip_node,
> +			    GPIO_GUMSTIX_USB_GPIOx, GPIO_ACTIVE_HIGH),
> +	{ }
>  };
> 

This is missing a few #include, the name spitz_mci_props[]
is wrong for this file and the array is not referenced anywhere.

I assume the gumstix_gpio_vbus_info needs to be turned into
an swnode, but I haven't figured out how to do this.

Based on the recent board deprecation discussion, I expect
that there are no users and that we will remove this machine
early next year, so we don't need to care about making it
pretty now, but maybe you can send a patch to make it build
again.

    Arnd
Re: [PATCH 03/10] ARM: pxa/gumstix: convert vbus gpio to use software nodes
Posted by Dmitry Torokhov 1 year, 4 months ago
On Tue, Aug 06, 2024 at 09:19:55AM +0200, Arnd Bergmann wrote:
> On Fri, Jun 28, 2024, at 20:08, Dmitry Torokhov wrote:
> > Switch vbus gpios from using a custom GPIO lookup table to software
> > properties using PROPERTY_ENTRY_GPIO() constructs which closely mimic
> > device tree gpio properties.
> >
> > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> 
> I ran into some randconfig build failures with this one now:
> 
> > index c9f0f62187bd..b9eddc691097 100644
> > --- a/arch/arm/mach-pxa/gumstix.c
> > +++ b/arch/arm/mach-pxa/gumstix.c
> > @@ -100,26 +100,22 @@ static void __init gumstix_mmc_init(void)
> >  #endif
> > 
> >  #ifdef CONFIG_USB_PXA25X
> > -static struct gpiod_lookup_table gumstix_gpio_vbus_gpiod_table = {
> > -	.dev_id = "gpio-vbus",
> > -	.table = {
> > -		GPIO_LOOKUP("gpio-pxa", GPIO_GUMSTIX_USB_GPIOn,
> > -			    "vbus", GPIO_ACTIVE_HIGH),
> > -		GPIO_LOOKUP("gpio-pxa", GPIO_GUMSTIX_USB_GPIOx,
> > -			    "pullup", GPIO_ACTIVE_HIGH),
> > -		{ },
> > -	},
> > +static const struct property_entry spitz_mci_props[] __initconst = {
> > +	PROPERTY_ENTRY_GPIO("vbus-gpios", &pxa2xx_gpiochip_node,
> > +			    GPIO_GUMSTIX_USB_GPIOn, GPIO_ACTIVE_HIGH),
> > +	PROPERTY_ENTRY_GPIO("pullup-gpios", &pxa2xx_gpiochip_node,
> > +			    GPIO_GUMSTIX_USB_GPIOx, GPIO_ACTIVE_HIGH),
> > +	{ }
> >  };
> > 
> 
> This is missing a few #include, the name spitz_mci_props[]
> is wrong for this file and the array is not referenced anywhere.

Ugh, you are right. Its weird that it does not warn me that the compiler
did not warn me that it is not used... It built for me with
pxa_defconfig so I assumed it was all good.

Ahh, by default it forces CONFIG_USB_PXA25X to be a module and that
skips that block in gumstix.c. I'll change it to IS_ENABLED() because it
should not matter if USB/UDC is built-in or is a module.

> 
> I assume the gumstix_gpio_vbus_info needs to be turned into
> an swnode, but I haven't figured out how to do this.

It is just a matter of initializing .properties in
gumstix_gpio_vbus_info. 

> 
> Based on the recent board deprecation discussion, I expect
> that there are no users and that we will remove this machine
> early next year, so we don't need to care about making it
> pretty now, but maybe you can send a patch to make it build
> again.

Yes, of course. Could you please try the patch below? And if you see
failures, please share your .config.

> 
>     Arnd

-- 
Dmitry

From cff436e3405b7f938e60f693ca7c8410266a893b Mon Sep 17 00:00:00 2001
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date: Tue, 6 Aug 2024 09:12:58 -0700
Subject: [PATCH] ARM: pxa/gumstix: fix attaching properties to vbus gpio device

Commit f1d6588af93b tried to convert GPIO lookup tables to software
properties for the vbus gpio device, bit forgot the most important
step: actually attaching the new properties to the device.

Also fix up the name of the property array to reflect the board name,
and add missing gpio/property.h and devices.h includes absence of which
causes compile failures on some configurations.

Switch "#ifdef CONFIG_USB_PXA25X" to "#if IS_ENABLED(CONFIG_USB_PXA25X)"
because it should not matter if the driver is buolt in or a module, it
still need vbus controls.

Reported-by: Arnd Bergmann <arnd@arndb.de>
Fixes: f1d6588af93b ("ARM: pxa/gumstix: convert vbus gpio to use software nodes")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 arch/arm/mach-pxa/gumstix.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-pxa/gumstix.c b/arch/arm/mach-pxa/gumstix.c
index efa6faa62a2c..1713bdf3b71e 100644
--- a/arch/arm/mach-pxa/gumstix.c
+++ b/arch/arm/mach-pxa/gumstix.c
@@ -21,6 +21,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 #include <linux/gpio/machine.h>
+#include <linux/gpio/property.h>
 #include <linux/gpio.h>
 #include <linux/err.h>
 #include <linux/clk.h>
@@ -40,6 +41,7 @@
 #include <linux/platform_data/mmc-pxamci.h>
 #include "udc.h"
 #include "gumstix.h"
+#include "devices.h"
 
 #include "generic.h"
 
@@ -99,8 +101,8 @@ static void __init gumstix_mmc_init(void)
 }
 #endif
 
-#ifdef CONFIG_USB_PXA25X
-static const struct property_entry spitz_mci_props[] __initconst = {
+#if IS_ENABLED(CONFIG_USB_PXA25X)
+static const struct property_entry gumstix_vbus_props[] __initconst = {
 	PROPERTY_ENTRY_GPIO("vbus-gpios", &pxa2xx_gpiochip_node,
 			    GPIO_GUMSTIX_USB_GPIOn, GPIO_ACTIVE_HIGH),
 	PROPERTY_ENTRY_GPIO("pullup-gpios", &pxa2xx_gpiochip_node,
@@ -109,8 +111,9 @@ static const struct property_entry spitz_mci_props[] __initconst = {
 };
 
 static const struct platform_device_info gumstix_gpio_vbus_info __initconst = {
-	.name	= "gpio-vbus",
-	.id	= PLATFORM_DEVID_NONE,
+	.name		= "gpio-vbus",
+	.id		= PLATFORM_DEVID_NONE,
+	.properties	= gumstix_vbus_props,
 };
 
 static void __init gumstix_udc_init(void)
-- 
2.46.0.rc2.264.g509ed76dc8-goog
Re: [PATCH 03/10] ARM: pxa/gumstix: convert vbus gpio to use software nodes
Posted by Arnd Bergmann 1 year, 4 months ago
On Tue, Aug 6, 2024, at 18:58, Dmitry Torokhov wrote:
> On Tue, Aug 06, 2024 at 09:19:55AM +0200, Arnd Bergmann wrote:
>
> Ugh, you are right. Its weird that it does not warn me that the compiler
> did not warn me that it is not used... It built for me with
> pxa_defconfig so I assumed it was all good.
>
> Ahh, by default it forces CONFIG_USB_PXA25X to be a module and that
> skips that block in gumstix.c. I'll change it to IS_ENABLED() because it
> should not matter if USB/UDC is built-in or is a module.
>
>> 
>> I assume the gumstix_gpio_vbus_info needs to be turned into
>> an swnode, but I haven't figured out how to do this.
>
> It is just a matter of initializing .properties in
> gumstix_gpio_vbus_info. 

Right, makes sense.

>> Based on the recent board deprecation discussion, I expect
>> that there are no users and that we will remove this machine
>> early next year, so we don't need to care about making it
>> pretty now, but maybe you can send a patch to make it build
>> again.
>
> Yes, of course. Could you please try the patch below? And if you see
> failures, please share your .config.

This addresses the configs that failed earlier, and I'm not
seeing any new ones.

I've applied this to the arm/fixes branch now and will send
this branch later this week.

Thanks for the quick fix!

     Arnd