mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH RFT v2 1/2] gpio: dw: support numbering via aliases
@ 2025-08-06 10:15 Ahmad Fatoum
  2025-08-06 10:15 ` [PATCH RFT v2 2/2] gpio: dw: make deep probe compatible Ahmad Fatoum
  2025-08-07  7:26 ` [PATCH RFT v2 1/2] gpio: dw: support numbering via aliases Sascha Hauer
  0 siblings, 2 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2025-08-06 10:15 UTC (permalink / raw)
  To: barebox; +Cc: David Picard, Ahmad Fatoum

This device driver is OF-only, so reflect that in the Kconfig and have
it parse aliases if available to derive its id.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - add missing prerequisite patch
---
 drivers/gpio/Kconfig   | 1 +
 drivers/gpio/gpio-dw.c | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 7caa1aa96eb3..17d5587ea8cf 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -201,6 +201,7 @@ config GPIO_TEGRA
 
 config GPIO_DESIGNWARE
 	tristate "Synopsys DesignWare GPIO driver"
+	depends on OF_GPIO
 	help
 	  Say Y or M here to build support for the Synopsys DesignWare APB
 	  GPIO block.
diff --git a/drivers/gpio/gpio-dw.c b/drivers/gpio/gpio-dw.c
index e6eba6b423f5..98668c0a2d54 100644
--- a/drivers/gpio/gpio-dw.c
+++ b/drivers/gpio/gpio-dw.c
@@ -114,6 +114,8 @@ static int dw_gpio_add_port(struct device *dev, struct device_node *node,
 	chip = xzalloc(sizeof(*chip));
 
 	chip->chip.ops = &dw_gpio_ops;
+
+	dev->id = of_alias_get_id(dev->device_node, "gpio");
 	if (dev->id < 0)
 		chip->chip.base = DEVICE_ID_DYNAMIC;
 	else
@@ -181,7 +183,7 @@ MODULE_DEVICE_TABLE(of, dwgpio_match);
 static struct driver dwgpio_driver = {
 	.name = "dw-apb-gpio",
 	.probe = dw_gpio_probe,
-	.of_compatible = DRV_OF_COMPAT(dwgpio_match),
+	.of_compatible = dwgpio_match,
 };
 
 postcore_platform_driver(dwgpio_driver);
-- 
2.39.5




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH RFT v2 2/2] gpio: dw: make deep probe compatible
  2025-08-06 10:15 [PATCH RFT v2 1/2] gpio: dw: support numbering via aliases Ahmad Fatoum
@ 2025-08-06 10:15 ` Ahmad Fatoum
  2025-08-06 14:24   ` David Picard
  2025-08-07  7:26 ` [PATCH RFT v2 1/2] gpio: dw: support numbering via aliases Sascha Hauer
  1 sibling, 1 reply; 4+ messages in thread
From: Ahmad Fatoum @ 2025-08-06 10:15 UTC (permalink / raw)
  To: barebox; +Cc: David Picard, Ahmad Fatoum

When deep probing GPIO controller, we expect struct gpio_chip::dev to be
bound to a driver.

This is currently not the case as the driver for the parent nodes
creates devices for the child nodes and never binds a driver to them.

As the child nodes have compatibles themselves too, let's match against
proper drivers.

Reported-by: David Picard <david.picard@clermont.in2p3.fr>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - unchanged
---
 drivers/gpio/gpio-dw.c | 44 ++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 19 deletions(-)

diff --git a/drivers/gpio/gpio-dw.c b/drivers/gpio/gpio-dw.c
index 98668c0a2d54..688b2536be2b 100644
--- a/drivers/gpio/gpio-dw.c
+++ b/drivers/gpio/gpio-dw.c
@@ -6,6 +6,7 @@
  */
 
 #include <common.h>
+#include <linux/device.h>
 #include <errno.h>
 #include <io.h>
 #include <gpio.h>
@@ -104,9 +105,9 @@ static struct gpio_ops dw_gpio_ops = {
 	.set = dw_gpio_set,
 };
 
-static int dw_gpio_add_port(struct device *dev, struct device_node *node,
-			    struct dw_gpio *parent)
+static int dw_gpio_add_port(struct device *dev)
 {
+	struct dw_gpio *parent = dev_get_drvdata(dev->parent);
 	struct dw_gpio_instance *chip;
 	uint32_t config1, config2;
 	int ngpio, ret;
@@ -130,17 +131,7 @@ static int dw_gpio_add_port(struct device *dev, struct device_node *node,
 
 	chip->parent = parent;
 	chip->chip.ngpio = ngpio;
-	chip->chip.dev = add_generic_device("dw-port", DEVICE_ID_DYNAMIC, NULL,
-					    dev->resource[0].start,
-					    resource_size(&dev->resource[0]),
-					    IORESOURCE_MEM, NULL);
-
-	if (!chip->chip.dev) {
-		dev_err(dev, "unable to add device\n");
-		return -ENODEV;
-	}
-
-	chip->chip.dev->of_node = node;
+	chip->chip.dev = dev;
 
 	ret = gpiochip_add(&chip->chip);
 	if (ret)
@@ -152,11 +143,22 @@ static int dw_gpio_add_port(struct device *dev, struct device_node *node,
 	return 0;
 }
 
+static struct of_device_id dwgpio_port_match[] = {
+	{ .compatible = "snps,dw-apb-gpio-port" },
+	{ /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, dwgpio_port_match);
+
+static struct driver dwgpio_port_driver = {
+	.name = "dw-apb-gpio-port",
+	.probe = dw_gpio_add_port,
+	.of_compatible = dwgpio_port_match,
+};
+
 static int dw_gpio_probe(struct device *dev)
 {
 	struct resource *iores;
 	struct dw_gpio *gpio;
-	struct device_node *node;
 
 	gpio = xzalloc(sizeof(*gpio));
 
@@ -165,13 +167,12 @@ static int dw_gpio_probe(struct device *dev)
 		return PTR_ERR(iores);
 	gpio->regs = IOMEM(iores->start);
 
-	for_each_child_of_node(dev->of_node, node)
-		dw_gpio_add_port(dev, node, gpio);
+	dev_set_drvdata(dev, gpio);
 
-	return 0;
+	return of_platform_populate(dev->of_node, NULL, dev);
 }
 
-static __maybe_unused struct of_device_id dwgpio_match[] = {
+static struct of_device_id dwgpio_match[] = {
 	{
 		.compatible = "snps,dw-apb-gpio",
 	}, {
@@ -186,4 +187,9 @@ static struct driver dwgpio_driver = {
 	.of_compatible = dwgpio_match,
 };
 
-postcore_platform_driver(dwgpio_driver);
+static int __init dwgpio_driver_register(void)
+{
+	platform_driver_register(&dwgpio_port_driver);
+	return platform_driver_register(&dwgpio_driver);
+}
+postcore_initcall(dwgpio_driver_register);
-- 
2.39.5




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH RFT v2 2/2] gpio: dw: make deep probe compatible
  2025-08-06 10:15 ` [PATCH RFT v2 2/2] gpio: dw: make deep probe compatible Ahmad Fatoum
@ 2025-08-06 14:24   ` David Picard
  0 siblings, 0 replies; 4+ messages in thread
From: David Picard @ 2025-08-06 14:24 UTC (permalink / raw)
  To: barebox

Tested-by:David Picard <david.picard@clermont.in2p3.fr>



Le 06/08/2025 à 12:15, Ahmad Fatoum a écrit :
> When deep probing GPIO controller, we expect struct gpio_chip::dev to be
> bound to a driver.
>
> This is currently not the case as the driver for the parent nodes
> creates devices for the child nodes and never binds a driver to them.
>
> As the child nodes have compatibles themselves too, let's match against
> proper drivers.
>
> Reported-by: David Picard <david.picard@clermont.in2p3.fr>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> v1 -> v2:
>    - unchanged
> ---
>   drivers/gpio/gpio-dw.c | 44 ++++++++++++++++++++++++------------------
>   1 file changed, 25 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/gpio/gpio-dw.c b/drivers/gpio/gpio-dw.c
> index 98668c0a2d54..688b2536be2b 100644
> --- a/drivers/gpio/gpio-dw.c
> +++ b/drivers/gpio/gpio-dw.c
> @@ -6,6 +6,7 @@
>    */
>   
>   #include <common.h>
> +#include <linux/device.h>
>   #include <errno.h>
>   #include <io.h>
>   #include <gpio.h>
> @@ -104,9 +105,9 @@ static struct gpio_ops dw_gpio_ops = {
>   	.set = dw_gpio_set,
>   };
>   
> -static int dw_gpio_add_port(struct device *dev, struct device_node *node,
> -			    struct dw_gpio *parent)
> +static int dw_gpio_add_port(struct device *dev)
>   {
> +	struct dw_gpio *parent = dev_get_drvdata(dev->parent);
>   	struct dw_gpio_instance *chip;
>   	uint32_t config1, config2;
>   	int ngpio, ret;
> @@ -130,17 +131,7 @@ static int dw_gpio_add_port(struct device *dev, struct device_node *node,
>   
>   	chip->parent = parent;
>   	chip->chip.ngpio = ngpio;
> -	chip->chip.dev = add_generic_device("dw-port", DEVICE_ID_DYNAMIC, NULL,
> -					    dev->resource[0].start,
> -					    resource_size(&dev->resource[0]),
> -					    IORESOURCE_MEM, NULL);
> -
> -	if (!chip->chip.dev) {
> -		dev_err(dev, "unable to add device\n");
> -		return -ENODEV;
> -	}
> -
> -	chip->chip.dev->of_node = node;
> +	chip->chip.dev = dev;
>   
>   	ret = gpiochip_add(&chip->chip);
>   	if (ret)
> @@ -152,11 +143,22 @@ static int dw_gpio_add_port(struct device *dev, struct device_node *node,
>   	return 0;
>   }
>   
> +static struct of_device_id dwgpio_port_match[] = {
> +	{ .compatible = "snps,dw-apb-gpio-port" },
> +	{ /* sentinel */ },
> +};
> +MODULE_DEVICE_TABLE(of, dwgpio_port_match);
> +
> +static struct driver dwgpio_port_driver = {
> +	.name = "dw-apb-gpio-port",
> +	.probe = dw_gpio_add_port,
> +	.of_compatible = dwgpio_port_match,
> +};
> +
>   static int dw_gpio_probe(struct device *dev)
>   {
>   	struct resource *iores;
>   	struct dw_gpio *gpio;
> -	struct device_node *node;
>   
>   	gpio = xzalloc(sizeof(*gpio));
>   
> @@ -165,13 +167,12 @@ static int dw_gpio_probe(struct device *dev)
>   		return PTR_ERR(iores);
>   	gpio->regs = IOMEM(iores->start);
>   
> -	for_each_child_of_node(dev->of_node, node)
> -		dw_gpio_add_port(dev, node, gpio);
> +	dev_set_drvdata(dev, gpio);
>   
> -	return 0;
> +	return of_platform_populate(dev->of_node, NULL, dev);
>   }
>   
> -static __maybe_unused struct of_device_id dwgpio_match[] = {
> +static struct of_device_id dwgpio_match[] = {
>   	{
>   		.compatible = "snps,dw-apb-gpio",
>   	}, {
> @@ -186,4 +187,9 @@ static struct driver dwgpio_driver = {
>   	.of_compatible = dwgpio_match,
>   };
>   
> -postcore_platform_driver(dwgpio_driver);
> +static int __init dwgpio_driver_register(void)
> +{
> +	platform_driver_register(&dwgpio_port_driver);
> +	return platform_driver_register(&dwgpio_driver);
> +}
> +postcore_initcall(dwgpio_driver_register);




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH RFT v2 1/2] gpio: dw: support numbering via aliases
  2025-08-06 10:15 [PATCH RFT v2 1/2] gpio: dw: support numbering via aliases Ahmad Fatoum
  2025-08-06 10:15 ` [PATCH RFT v2 2/2] gpio: dw: make deep probe compatible Ahmad Fatoum
@ 2025-08-07  7:26 ` Sascha Hauer
  1 sibling, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2025-08-07  7:26 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum; +Cc: David Picard


On Wed, 06 Aug 2025 12:15:58 +0200, Ahmad Fatoum wrote:
> This device driver is OF-only, so reflect that in the Kconfig and have
> it parse aliases if available to derive its id.
> 
> 

Applied, thanks!

[1/2] gpio: dw: support numbering via aliases
      https://git.pengutronix.de/cgit/barebox/commit/?id=d07fab49b60c (link may not be stable)
[2/2] gpio: dw: make deep probe compatible
      https://git.pengutronix.de/cgit/barebox/commit/?id=1d7ae44b8ca3 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-08-07  7:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-06 10:15 [PATCH RFT v2 1/2] gpio: dw: support numbering via aliases Ahmad Fatoum
2025-08-06 10:15 ` [PATCH RFT v2 2/2] gpio: dw: make deep probe compatible Ahmad Fatoum
2025-08-06 14:24   ` David Picard
2025-08-07  7:26 ` [PATCH RFT v2 1/2] gpio: dw: support numbering via aliases Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox