[PATCH 0/2 v2] gpio-omap: ensure a stable gpio numbering

STALE3725d

6 messages, 4 authors, 2016-06-23 · open the first message on its own page

[PATCH 0/2 v2] gpio-omap: ensure a stable gpio numbering

From: Uwe Kleine-König <hidden>
Date: 2016-06-14 18:57:35

Hello,

this series' first patch is v2 of the patch I sent earlier. This now also
compiles without CONFIG_OF_GPIO.

The second patch is new and adds the respective aliases to all device trees
that make use of the gpio-omap driver.

Best regards
Uwe

Uwe Kleine-K?nig (2):
  gpio: omap: make gpio numbering deterministical by using of aliases
  ARM: dts: add aliases for ti,omap[234]-gpio devices

 arch/arm/boot/dts/am33xx.dtsi   |  4 ++++
 arch/arm/boot/dts/am4372.dtsi   |  6 ++++++
 arch/arm/boot/dts/dm814x.dtsi   |  2 ++
 arch/arm/boot/dts/dm816x.dtsi   |  2 ++
 arch/arm/boot/dts/dra7.dtsi     |  8 ++++++++
 arch/arm/boot/dts/omap2420.dtsi |  7 +++++++
 arch/arm/boot/dts/omap2430.dtsi |  8 ++++++++
 arch/arm/boot/dts/omap3.dtsi    |  6 ++++++
 arch/arm/boot/dts/omap4.dtsi    |  6 ++++++
 arch/arm/boot/dts/omap5.dtsi    |  8 ++++++++
 drivers/gpio/gpio-omap.c        | 19 ++++++++++++++++++-
 11 files changed, 75 insertions(+), 1 deletion(-)

-- 
2.8.1

[PATCH 2/2 v2] ARM: dts: add aliases for ti,omap[234]-gpio devices

From: Uwe Kleine-König <hidden>
Date: 2016-06-14 18:57:27

This together with the corresponding change to the gpio-omap driver
ensures that the gpio numbering is independant of the probing order.

Signed-off-by: Uwe Kleine-K?nig <redacted>
---
 arch/arm/boot/dts/am33xx.dtsi   | 4 ++++
 arch/arm/boot/dts/am4372.dtsi   | 6 ++++++
 arch/arm/boot/dts/dm814x.dtsi   | 2 ++
 arch/arm/boot/dts/dm816x.dtsi   | 2 ++
 arch/arm/boot/dts/dra7.dtsi     | 8 ++++++++
 arch/arm/boot/dts/omap2420.dtsi | 7 +++++++
 arch/arm/boot/dts/omap2430.dtsi | 8 ++++++++
 arch/arm/boot/dts/omap3.dtsi    | 6 ++++++
 arch/arm/boot/dts/omap4.dtsi    | 6 ++++++
 arch/arm/boot/dts/omap5.dtsi    | 8 ++++++++
 10 files changed, 57 insertions(+)
diff --git a/arch/arm/boot/dts/am33xx.dtsi b/arch/arm/boot/dts/am33xx.dtsi
index 52be48bbd2dd..fbfc17ab56d8 100644
--- a/arch/arm/boot/dts/am33xx.dtsi
+++ b/arch/arm/boot/dts/am33xx.dtsi
@@ -35,6 +35,10 @@
 		phy1 = &usb1_phy;
 		ethernet0 = &cpsw_emac0;
 		ethernet1 = &cpsw_emac1;
+		gpio0 = &gpio0;
+		gpio1 = &gpio1;
+		gpio2 = &gpio2;
+		gpio3 = &gpio3;
 	};
 
 	cpus {
diff --git a/arch/arm/boot/dts/am4372.dtsi b/arch/arm/boot/dts/am4372.dtsi
index 12fcde4d4d2e..0f5a915ba94b 100644
--- a/arch/arm/boot/dts/am4372.dtsi
+++ b/arch/arm/boot/dts/am4372.dtsi
@@ -31,6 +31,12 @@
 		ethernet0 = &cpsw_emac0;
 		ethernet1 = &cpsw_emac1;
 		spi0 = &qspi;
+		gpio0 = &gpio0;
+		gpio1 = &gpio1;
+		gpio2 = &gpio2;
+		gpio3 = &gpio3;
+		gpio4 = &gpio4;
+		gpio5 = &gpio5;
 	};
 
 	cpus {
diff --git a/arch/arm/boot/dts/dm814x.dtsi b/arch/arm/boot/dts/dm814x.dtsi
index d4537dc61497..d5a49ad31d50 100644
--- a/arch/arm/boot/dts/dm814x.dtsi
+++ b/arch/arm/boot/dts/dm814x.dtsi
@@ -25,6 +25,8 @@
 		usb1 = &usb1;
 		phy0 = &usb0_phy;
 		phy1 = &usb1_phy;
+		gpio0 = &gpio1;
+		gpio1 = &gpio2;
 	};
 
 	cpus {
diff --git a/arch/arm/boot/dts/dm816x.dtsi b/arch/arm/boot/dts/dm816x.dtsi
index 44e39c743b53..500d9091701e 100644
--- a/arch/arm/boot/dts/dm816x.dtsi
+++ b/arch/arm/boot/dts/dm816x.dtsi
@@ -21,6 +21,8 @@
 		serial2 = &uart3;
 		ethernet0 = &eth0;
 		ethernet1 = &eth1;
+		gpio0 = &gpio1;
+		gpio1 = &gpio2;
 	};
 
 	cpus {
diff --git a/arch/arm/boot/dts/dra7.dtsi b/arch/arm/boot/dts/dra7.dtsi
index e0074014385a..4d6e2309a742 100644
--- a/arch/arm/boot/dts/dra7.dtsi
+++ b/arch/arm/boot/dts/dra7.dtsi
@@ -42,6 +42,14 @@
 		d_can0 = &dcan1;
 		d_can1 = &dcan2;
 		spi0 = &qspi;
+		gpio0 = &gpio1;
+		gpio1 = &gpio2;
+		gpio2 = &gpio3;
+		gpio3 = &gpio4;
+		gpio4 = &gpio5;
+		gpio5 = &gpio6;
+		gpio6 = &gpio7;
+		gpio7 = &gpio8;
 	};
 
 	timer {
diff --git a/arch/arm/boot/dts/omap2420.dtsi b/arch/arm/boot/dts/omap2420.dtsi
index fb712b9aa874..933e4415d3d2 100644
--- a/arch/arm/boot/dts/omap2420.dtsi
+++ b/arch/arm/boot/dts/omap2420.dtsi
@@ -13,6 +13,13 @@
 / {
 	compatible = "ti,omap2420", "ti,omap2";
 
+	aliases {
+		gpio0 = &gpio1;
+		gpio1 = &gpio2;
+		gpio2 = &gpio3;
+		gpio3 = &gpio4;
+	};
+
 	ocp {
 		l4: l4 at 48000000 {
 			compatible = "ti,omap2-l4", "simple-bus";
diff --git a/arch/arm/boot/dts/omap2430.dtsi b/arch/arm/boot/dts/omap2430.dtsi
index 455aaea407dd..8c0e5555a550 100644
--- a/arch/arm/boot/dts/omap2430.dtsi
+++ b/arch/arm/boot/dts/omap2430.dtsi
@@ -13,6 +13,14 @@
 / {
 	compatible = "ti,omap2430", "ti,omap2";
 
+	aliases {
+		gpio0 = &gpio1;
+		gpio1 = &gpio2;
+		gpio2 = &gpio3;
+		gpio3 = &gpio4;
+		gpio4 = &gpio5;
+	};
+
 	ocp {
 		l4_wkup: l4_wkup at 49000000 {
 			compatible = "ti,omap2-l4-wkup", "simple-bus";
diff --git a/arch/arm/boot/dts/omap3.dtsi b/arch/arm/boot/dts/omap3.dtsi
index 9fbda38528dc..2676c34c5830 100644
--- a/arch/arm/boot/dts/omap3.dtsi
+++ b/arch/arm/boot/dts/omap3.dtsi
@@ -25,6 +25,12 @@
 		serial0 = &uart1;
 		serial1 = &uart2;
 		serial2 = &uart3;
+		gpio0 = &gpio1;
+		gpio1 = &gpio2;
+		gpio2 = &gpio3;
+		gpio3 = &gpio4;
+		gpio4 = &gpio5;
+		gpio5 = &gpio6;
 	};
 
 	cpus {
diff --git a/arch/arm/boot/dts/omap4.dtsi b/arch/arm/boot/dts/omap4.dtsi
index 3fdc51cd0fad..367a2fb04829 100644
--- a/arch/arm/boot/dts/omap4.dtsi
+++ b/arch/arm/boot/dts/omap4.dtsi
@@ -25,6 +25,12 @@
 		serial1 = &uart2;
 		serial2 = &uart3;
 		serial3 = &uart4;
+		gpio0 = &gpio1;
+		gpio1 = &gpio2;
+		gpio2 = &gpio3;
+		gpio3 = &gpio4;
+		gpio4 = &gpio5;
+		gpio5 = &gpio6;
 	};
 
 	cpus {
diff --git a/arch/arm/boot/dts/omap5.dtsi b/arch/arm/boot/dts/omap5.dtsi
index 84c10195e79b..017edd442390 100644
--- a/arch/arm/boot/dts/omap5.dtsi
+++ b/arch/arm/boot/dts/omap5.dtsi
@@ -32,6 +32,14 @@
 		serial3 = &uart4;
 		serial4 = &uart5;
 		serial5 = &uart6;
+		gpio0 = &gpio1;
+		gpio1 = &gpio2;
+		gpio2 = &gpio3;
+		gpio3 = &gpio4;
+		gpio4 = &gpio5;
+		gpio5 = &gpio6;
+		gpio6 = &gpio7;
+		gpio7 = &gpio8;
 	};
 
 	cpus {
-- 
2.8.1

[PATCH 1/2 v2] gpio: omap: make gpio numbering deterministical by using of aliases

From: Uwe Kleine-König <hidden>
Date: 2016-06-14 18:57:48

Traditionally the n-th gpio device probed by the omap gpio driver got
the gpio number range [n*32 .. n*32+31].
When order of the devices probed by the driver changes (which can happen
already now when some devices have a pinctrl and so the first probe
attempt returns -ENODEV) the numbering changes.

To ensure a deterministical numbering use of_alias_get_id to determine
the base for a given device. If no respective alias exists fall back to
the traditional numbering.

For the unusual case where only a part of the gpio devices have a
matching alias some of them might fail to probe. But if none of them has
an alias or all, there is no conflict which should be good enough to
maintain backward compatibility.

Signed-off-by: Uwe Kleine-K?nig <redacted>
---
 drivers/gpio/gpio-omap.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index b98ede78c9d8..4d91792e7266 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -1053,9 +1053,26 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
 			bank->chip.parent = &omap_mpuio_device.dev;
 		bank->chip.base = OMAP_MPUIO(0);
 	} else {
+		int gpio_alias_id __maybe_unused;
+
 		bank->chip.label = "gpio";
-		bank->chip.base = gpio;
+
+#if defined(CONFIG_OF_GPIO)
+		/*
+		 * Traditionally the base is given out in first-come-first-serve
+		 * order.  This might shuffle the numbering of gpios if the
+		 * probe order changes.  So make the base deterministical if the
+		 * device tree specifies alias ids.
+		 */
+		gpio_alias_id = of_alias_get_id(bank->chip.of_node, "gpio");
+		if (gpio_alias_id >= 0)
+			bank->chip.base = bank->width * gpio_alias_id;
+		else
+#endif
+			bank->chip.base = gpio;
 	}
+
+
 	bank->chip.ngpio = bank->width;
 
 	ret = gpiochip_add_data(&bank->chip, bank);
-- 
2.8.1

Re: [PATCH 1/2 v2] gpio: omap: make gpio numbering deterministical by using of aliases

From: Tony Lindgren <tony@atomide.com>
Date: 2016-06-21 11:28:59

* Uwe Kleine-K?nig [off-list ref] [160614 12:03]:
Traditionally the n-th gpio device probed by the omap gpio driver got
the gpio number range [n*32 .. n*32+31].
When order of the devices probed by the driver changes (which can happen
already now when some devices have a pinctrl and so the first probe
attempt returns -ENODEV) the numbering changes.

To ensure a deterministical numbering use of_alias_get_id to determine
the base for a given device. If no respective alias exists fall back to
the traditional numbering.

For the unusual case where only a part of the gpio devices have a
matching alias some of them might fail to probe. But if none of them has
an alias or all, there is no conflict which should be good enough to
maintain backward compatibility.
I think doing this is a good idea to prevent nasty suprises when
upgrading a kernel on some device:

Acked-by: Tony Lindgren <tony@atomide.com>

Re: [PATCH 1/2 v2] gpio: omap: make gpio numbering deterministical by using of aliases

From: Grygorii Strashko <grygorii.strashko@ti.com>
Date: 2016-06-21 17:01:36

On 06/14/2016 09:57 PM, Uwe Kleine-K?nig wrote:
quoted hunk
Traditionally the n-th gpio device probed by the omap gpio driver got
the gpio number range [n*32 .. n*32+31].
When order of the devices probed by the driver changes (which can happen
already now when some devices have a pinctrl and so the first probe
attempt returns -ENODEV) the numbering changes.

To ensure a deterministical numbering use of_alias_get_id to determine
the base for a given device. If no respective alias exists fall back to
the traditional numbering.

For the unusual case where only a part of the gpio devices have a
matching alias some of them might fail to probe. But if none of them has
an alias or all, there is no conflict which should be good enough to
maintain backward compatibility.

Signed-off-by: Uwe Kleine-K?nig <redacted>
---
  drivers/gpio/gpio-omap.c | 19 ++++++++++++++++++-
  1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index b98ede78c9d8..4d91792e7266 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -1053,9 +1053,26 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
  			bank->chip.parent = &omap_mpuio_device.dev;
  		bank->chip.base = OMAP_MPUIO(0);
  	} else {
+		int gpio_alias_id __maybe_unused;
+
  		bank->chip.label = "gpio";
-		bank->chip.base = gpio;
+
+#if defined(CONFIG_OF_GPIO)
+		/*
+		 * Traditionally the base is given out in first-come-first-serve
+		 * order.  This might shuffle the numbering of gpios if the
+		 * probe order changes.  So make the base deterministical if the
+		 * device tree specifies alias ids.
+		 */
+		gpio_alias_id = of_alias_get_id(bank->chip.of_node, "gpio");
+		if (gpio_alias_id >= 0)
+			bank->chip.base = bank->width * gpio_alias_id;
+		else
+#endif
+			bank->chip.base = gpio;
  	}
+
+
  	bank->chip.ngpio = bank->width;

  	ret = gpiochip_add_data(&bank->chip, bank);
Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>

-- 
regards,
-grygorii

Re: [PATCH 1/2 v2] gpio: omap: make gpio numbering deterministical by using of aliases

From: Linus Walleij <hidden>
Date: 2016-06-23 08:54:05

Looping in DT people.

Please send subsequent patches also to devicetree at vger.kernel.org

On Tue, Jun 14, 2016 at 8:57 PM, Uwe Kleine-K?nig
[off-list ref] wrote:
quoted hunk
Traditionally the n-th gpio device probed by the omap gpio driver got
the gpio number range [n*32 .. n*32+31].
When order of the devices probed by the driver changes (which can happen
already now when some devices have a pinctrl and so the first probe
attempt returns -ENODEV) the numbering changes.

To ensure a deterministical numbering use of_alias_get_id to determine
the base for a given device. If no respective alias exists fall back to
the traditional numbering.

For the unusual case where only a part of the gpio devices have a
matching alias some of them might fail to probe. But if none of them has
an alias or all, there is no conflict which should be good enough to
maintain backward compatibility.

Signed-off-by: Uwe Kleine-K?nig <redacted>
---
 drivers/gpio/gpio-omap.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index b98ede78c9d8..4d91792e7266 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -1053,9 +1053,26 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
                        bank->chip.parent = &omap_mpuio_device.dev;
                bank->chip.base = OMAP_MPUIO(0);
        } else {
+               int gpio_alias_id __maybe_unused;
+
                bank->chip.label = "gpio";
-               bank->chip.base = gpio;
+
+#if defined(CONFIG_OF_GPIO)
+               /*
+                * Traditionally the base is given out in first-come-first-serve
+                * order.  This might shuffle the numbering of gpios if the
+                * probe order changes.  So make the base deterministical if the
+                * device tree specifies alias ids.
+                */
+               gpio_alias_id = of_alias_get_id(bank->chip.of_node, "gpio");
+               if (gpio_alias_id >= 0)
+                       bank->chip.base = bank->width * gpio_alias_id;
+               else
+#endif
+                       bank->chip.base = gpio;
        }
+
+
I need:

- A hunk of the patch to hit
  Documentation/devicetree/bindings/gpio/gpio.txt
  and describe the alias usage there

-  an ACK from a DT bindings maintainer for this.

Yours,
Linus Walleij
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help