Skip to contentSkip to conversation

gpiolib: fix issues with legacy spi-cs-high handling

PATCH In review H. Nikolaus Schaller 3 participants 10 messages Mar 31, 2019 – Apr 2, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover gpiolib: fix issues with legacy spi-cs-high handling

2018-07-25 07:55:28: 

H. Nikolaus Schaller (4):
DTS: GTA04: SPI / gpiolib: work around a regression that unhides a
broken legacy handler, which makes the gta04 display inoperable
REVERT: DTS: GTA04: SPI / gpiolib: no no no, we do not want to "fix"
our device tree file
gpiolib: make legacy handling for spi-cs-high optional
gpiolib: spi-cs-high is checking the wrong node (the controller and
not the SPI slave device)

 drivers/gpio/Kconfig      | 8 ++++++++
 drivers/gpio/gpiolib-of.c | 8 +++++---
 2 files changed, 13 insertions(+), 3 deletions(-)
Signature · 1 line
2.19.1
#1 lore raw

PATCH 1/4 DTS: GTA04: SPI / gpiolib: work around a regression that unhides a broken legacy handler, which makes the gta04 display inoperable

This is an ugly workaround for a regression introduced into v5.1-rc1 by

<c1c04cea13dc234ce9a4504879ddd36ea524d880>

The GTA04 board uses a bitbanged SPI interface to control the LCD and it did work right from the introduction of the cs-gpios 5 years ago by <c2e138bc8ed80ae291d689917e88d2d09bf1d478> but unexpectedly stopped with v5.1-rc1.

Since we already use the gpio-flags for high level CS, we did not add spi-cs-high, which is listed in the bindings documentation as optional and indicative and not described as required to make it work. And it worked without this flag until now.

Now the newly introduced patch to gpiolib-of.c removes a bug which prevented an ugly legacy handler for of SPI active high chip select to run. This now suddenly requires spi-cs-high to be defined in addition to the gpio flags.

Trying to find a workaround in DTS shows that there seems to be another bug in the legacy handler code in gpiolib-of.c because it checks for the spi-cs-high flag not in the individual slave node (as one could expect from bindings documentation) but the spi controller node.

Unfortunately it requires us to add legacy flags to a DTS to make the workaround code functioning.

I would prefer that the workaround code and the spi-cs-high property is completely removed from gpiolib-of.c and all DTS which still use legacy gpio flags are fixed.

fgrep spi-cs-high arch/*/boot/dts/*.dts* shows only a handful of board candidates.

---
 arch/arm/boot/dts/omap3-gta04.dtsi | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/boot/dts/omap3-gta04.dtsi +2 -0
index 04f2b53d4d3d..1e134dfab428 100644
@@ -114,6 +114,7 @@
 		gpio-miso = <&gpio1 18 GPIO_ACTIVE_HIGH>;
 		gpio-mosi = <&gpio1 20 GPIO_ACTIVE_HIGH>;
 		cs-gpios = <&gpio1 19 GPIO_ACTIVE_HIGH>;
+		spi-cs-high;	/* make the legacy handler in gpiolib not intervene */
 		num-chipselects = <1>;
 
 		/* lcd panel */
@@ -123,6 +124,7 @@
 			spi-max-frequency = <100000>;
 			spi-cpol;
 			spi-cpha;
+			spi-cs-high;	/* here is where it should be but this is ignored by a bug in the gpiolib handler */
 
 			backlight= <&backlight>;
 			label = "lcd";
Signature · 1 line
2.19.1
#2 lore raw

Re: [BUG/PATCH 1/4] DTS: GTA04: SPI / gpiolib: work around a regression that unhides a broken legacy handler, which makes the gta04 display inoperable

Hi,

Quoted 3 lines · H. Nikolaus Schaller

This is an ugly workaround for a regression introduced into v5.1-rc1 by

<c1c04cea13dc234ce9a4504879ddd36ea524d880>

You should standardized commit references like this instead:

c1c04cea13dc ("gpio: of: Fix logic inversion")

Then please also include a proper Fixes tag.

You can configure an alias for it to make things easier:

git log --abbrev=12 --pretty=format:"%h (\"%s\")"

Quoted 11 lines
arch/arm/boot/dts/omap3-gta04.dtsi +1 -0
@@ -114,6 +114,7 @@
 		gpio-miso = <&gpio1 18 GPIO_ACTIVE_HIGH>;
 		gpio-mosi = <&gpio1 20 GPIO_ACTIVE_HIGH>;
 		cs-gpios = <&gpio1 19 GPIO_ACTIVE_HIGH>;
+		spi-cs-high;	/* make the legacy handler in gpiolib not intervene */
 		num-chipselects = <1>;
 
 		/* lcd panel */

arch/arm/boot/dts/omap3-gta04.dtsi line 130

Quoted 7 lines
arch/arm/boot/dts/omap3-gta04.dtsi +1 -0
@@ -123,6 +124,7 @@
 			spi-max-frequency = <100000>;
 			spi-cpol;
 			spi-cpha;
+			spi-cs-high;	/* here is where it should be but this is ignored by a bug in the gpiolib handler */
 
 			backlight= <&backlight>;
 			label = "lcd";

So what's the plan with this fix? Add this for v5.2-rc cycle, then revert it later? I'd probably go directly for the proper fix if possible.

Regards,

Tony

#3 lore raw

Re: [BUG/PATCH 1/4] DTS: GTA04: SPI / gpiolib: work around a regression that unhides a broken legacy handler, which makes the gta04 display inoperable

Hi Tony,

Quoted 35 lines

Am 01.04.2019 um 18:46 schrieb Tony Lindgren <[email protected]>:

Hi,

Quoted 3 lines · H. Nikolaus Schaller

This is an ugly workaround for a regression introduced into v5.1-rc1 by

<c1c04cea13dc234ce9a4504879ddd36ea524d880>

You should standardized commit references like this instead:

c1c04cea13dc ("gpio: of: Fix logic inversion")

Then please also include a proper Fixes tag.

You can configure an alias for it to make things easier:

git log --abbrev=12 --pretty=format:"%h (\"%s\")"

Quoted 16 lines
arch/arm/boot/dts/omap3-gta04.dtsi +2 -0
@@ -114,6 +114,7 @@
 		gpio-miso = <&gpio1 18 GPIO_ACTIVE_HIGH>;
 		gpio-mosi = <&gpio1 20 GPIO_ACTIVE_HIGH>;
 		cs-gpios = <&gpio1 19 GPIO_ACTIVE_HIGH>;
+		spi-cs-high;	/* make the legacy handler in gpiolib not intervene */
 		num-chipselects = <1>;
 
 		/* lcd panel */
@@ -123,6 +124,7 @@
 			spi-max-frequency = <100000>;
 			spi-cpol;
 			spi-cpha;
+			spi-cs-high;	/* here is where it should be but this is ignored by a bug in the gpiolib handler */
 
Quoted 6 lines

arch/arm/boot/dts/omap3-gta04.dtsi line 130

Quoted 2 lines
arch/arm/boot/dts/omap3-gta04.dtsi +0 -0
 			backlight= <&backlight>;
 			label = "lcd";

So what's the plan with this fix? Add this for v5.2-rc cycle, then revert it later? I'd probably go directly for the proper fix if possible.

Well, I learned just some minutes ago that a new patch for gpiolib came through 5.1-rc3 which does fix this.

It seems to check for "cs-gpios" and then disable the legacy handling.

This means that we do not need to patch the DTS at all.

BR and thanks,
Nikolaus

#4 lore raw

Re: [BUG/PATCH 1/4] DTS: GTA04: SPI / gpiolib: work around a regression that unhides a broken legacy handler, which makes the gta04 display inoperable

Quoted 11 lines · H. Nikolaus Schaller
Quoted 4 lines

Am 01.04.2019 um 18:46 schrieb Tony Lindgren <[email protected]>:
So what's the plan with this fix? Add this for v5.2-rc cycle, then revert it later? I'd probably go directly for the proper fix if possible.

Well, I learned just some minutes ago that a new patch for gpiolib came through 5.1-rc3 which does fix this.

It seems to check for "cs-gpios" and then disable the legacy handling.

This means that we do not need to patch the DTS at all.

OK good to hear, thanks for the update.

Regards,

Tony

#5 lore raw

PATCH 2/4 REVERT: DTS: GTA04: SPI / gpiolib: no no no, we do not want to "fix" our device tree file

In reply to H. Nikolaus Schaller

just because some legacy boards seem to require changes in the gpio-lib which make our so far correct DTS/DTB being wrongly interpreted.

A better solution seems to make the legacy handler optional so that DTS/DTB developed without legacy modes are not harmed.

---
 arch/arm/boot/dts/omap3-gta04.dtsi | 2 --
 1 file changed, 2 deletions(-)
arch/arm/boot/dts/omap3-gta04.dtsi +0 -2
index 1e134dfab428..04f2b53d4d3d 100644
@@ -114,7 +114,6 @@
 		gpio-miso = <&gpio1 18 GPIO_ACTIVE_HIGH>;
 		gpio-mosi = <&gpio1 20 GPIO_ACTIVE_HIGH>;
 		cs-gpios = <&gpio1 19 GPIO_ACTIVE_HIGH>;
-		spi-cs-high;	/* make the legacy handler in gpiolib not intervene */
 		num-chipselects = <1>;
 
 		/* lcd panel */
@@ -124,7 +123,6 @@
 			spi-max-frequency = <100000>;
 			spi-cpol;
 			spi-cpha;
-			spi-cs-high;	/* here is where it should be but this is ignored by a bug in the gpiolib handler */
 
 			backlight= <&backlight>;
 			label = "lcd";
Signature · 1 line
2.19.1
#6 lore raw

PATCH 3/4 gpiolib: make legacy handling for spi-cs-high optional

In reply to H. Nikolaus Schaller

It is better to make legacy support a config option instead of requiring non-legacy device tree files to be updated.

---
 drivers/gpio/Kconfig      | 8 ++++++++
 drivers/gpio/gpiolib-of.c | 2 ++
 2 files changed, 10 insertions(+)
drivers/gpio/Kconfig +8 -0
index 3f50526a771f..1a82619727c1 100644
@@ -39,6 +39,14 @@ config OF_GPIO
 	depends on OF
 	depends on HAS_IOMEM
 
+config SPI_CS_HIGH_LEGACY_HANDLING
+	def_bool n
+	depends on OF_GPIO
+	help
+	   This enables a legacy handler which decodes the boolean spi-cs-high
+	   property found in some DTS/DTB to correctly work with cs-gpios
+	   with GPIO_ACTIVE_HIGH.
+
 config GPIO_ACPI
 	def_bool y
 	depends on ACPI
drivers/gpio/gpiolib-of.c +2 -0
index 8b9c3ab70f6e..a22d2233458b 100644
@@ -114,6 +114,7 @@ static void of_gpio_flags_quirks(struct device_node *np,
 			of_node_full_name(np));
 	}
 
+#if defined(CONFIG_SPI_CS_HIGH_LEGACY_HANDLING)
 	/*
 	 * Legacy handling of SPI active high chip select. If we have a
 	 * property named "cs-gpios" we need to inspect the child node
@@ -158,6 +159,7 @@ static void of_gpio_flags_quirks(struct device_node *np,
 			}
 		}
 	}
+#endif
 }
 
 /**
Signature · 1 line
2.19.1
#7 lore raw

PATCH 4/4 gpiolib: spi-cs-high is checking the wrong node (the controller and not the SPI slave device)

In reply to H. Nikolaus Schaller

Bindings say:

All slave nodes can contain the following optional properties:
- spi-cs-high - Empty property indicating device requires chip select
active high.

---
 drivers/gpio/gpiolib-of.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpio/gpiolib-of.c +3 -3
index a22d2233458b..82e7a1f63b0a 100644
@@ -143,16 +143,16 @@ static void of_gpio_flags_quirks(struct device_node *np,
 				 * conflict and the "spi-cs-high" flag will
 				 * take precedence.
 				 */
-				if (of_property_read_bool(np, "spi-cs-high")) {
+				if (of_property_read_bool(child, "spi-cs-high")) {
 					if (*flags & OF_GPIO_ACTIVE_LOW) {
 						pr_warn("%s GPIO handle specifies active low - ignored\n",
-							of_node_full_name(np));
+							of_node_full_name(child));
 						*flags &= ~OF_GPIO_ACTIVE_LOW;
 					}
 				} else {
 					if (!(*flags & OF_GPIO_ACTIVE_LOW))
 						pr_info("%s enforce active low on chipselect handle\n",
-							of_node_full_name(np));
+							of_node_full_name(child));
 					*flags |= OF_GPIO_ACTIVE_LOW;
 				}
 				break;
Signature · 1 line
2.19.1
#8 lore raw
In reply to H. Nikolaus Schaller

Hi all,

Quoted 13 lines

Am 31.03.2019 um 12:07 schrieb H. Nikolaus Schaller <[email protected]>:

2018-07-25 07:55:28: 

H. Nikolaus Schaller (4):
DTS: GTA04: SPI / gpiolib: work around a regression that unhides a
broken legacy handler, which makes the gta04 display inoperable
REVERT: DTS: GTA04: SPI / gpiolib: no no no, we do not want to "fix"
our device tree file
gpiolib: make legacy handling for spi-cs-high optional
gpiolib: spi-cs-high is checking the wrong node (the controller and
not the SPI slave device)

Quoted 7 lines

drivers/gpio/Kconfig | 8 ++++++++
drivers/gpio/gpiolib-of.c | 8 +++++---

2 files changed, 13 insertions(+), 3 deletions(-)
Signature · 1 line
2.19.1

I learned just some minutes ago that a new patch for gpiolib came through 5.1-rc3 which does fix this in almost the same way as I proposed.

Except that it seems to check for "cs-gpios" and then disable the legacy handling.

So we do not need to add a config option for this legacy handling (although I'd prefer to have it anyways to remove some dead code).

Summary: this series can now be ignored.

BR and thanks,
Nikolaus

#9 lore raw
Quoted 3 lines · H. Nikolaus Schaller

I learned just some minutes ago that a new patch for gpiolib came through 5.1-rc3 which does fix this in almost the same way as I proposed.

I am sorry for not being very attentive, I have been travelling. I collected the most urgent fixes and this was fixed as part of that quick patchup.

Quoted 2 lines

Except that it seems to check for "cs-gpios" and then disable the legacy handling.

Yups.

Quoted 5 lines

So we do not need to add a config option for this legacy handling (although I'd prefer to have it anyways to remove some dead code).

Summary: this series can now be ignored.

OK please verify that we are doing things right now, the big worry I have is some interrim DTBs that use the GPIO flag GPIO_ACTIVE_HIGH, which is zero and therefore often the default, and expect it to actually work, while the SPI bindings by definition will ignore that and make the line active low.

I'm not very happy about this but it is a result of how we quickly implemented some bindings in the past while the GPIO flags were not yet standardized.

Yours,
Linus Walleij