Skip to contentSkip to conversation

MIPS: pci: lantiq: restore reset gpio polarity

PATCH Applied Martin Schiller 4 participants 15 messages Jun 7, 2024 – Jun 24, 2024

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

PATCH 1/1 MIPS: pci: lantiq: restore reset gpio polarity

Commit 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API") not only switched to the gpiod API, but also inverted / changed the polarity of the GPIO.

According to the PCI specification, the RST# pin is an active-low signal. However, most of the device trees that have been widely used for a long time (mainly in the openWrt project) define this GPIO as active-high and the old driver code inverted the signal internally.

Apparently there are actually boards where the reset gpio must be operated inverted. For this reason, we cannot use the GPIOD_OUT_LOW/HIGH flag for initialization. Instead, we must explicitly set the gpio to value 1 in order to take into account any "GPIO_ACTIVE_LOW" flag that may have been set.

In order to remain compatible with all these existing device trees, we should therefore keep the logic as it was before the commit.

Fixes 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API")
---
 arch/mips/pci/pci-lantiq.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/mips/pci/pci-lantiq.c +4 -4
index 68a8cefed420..0844db34022e 100644
@@ -124,14 +124,14 @@ static int ltq_pci_startup(struct platform_device *pdev)
 		clk_disable(clk_external);
 
 	/* setup reset gpio used by pci */
-	reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
-					     GPIOD_OUT_LOW);
+	reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset", GPIOD_ASIS);
 	error = PTR_ERR_OR_ZERO(reset_gpio);
 	if (error) {
 		dev_err(&pdev->dev, "failed to request gpio: %d\n", error);
 		return error;
 	}
 	gpiod_set_consumer_name(reset_gpio, "pci_reset");
+	gpiod_direction_output(reset_gpio, 1);
 
 	/* enable auto-switching between PCI and EBU */
 	ltq_pci_w32(0xa, PCI_CR_CLK_CTRL);
@@ -194,10 +194,10 @@ static int ltq_pci_startup(struct platform_device *pdev)
 
 	/* toggle reset pin */
 	if (reset_gpio) {
-		gpiod_set_value_cansleep(reset_gpio, 1);
+		gpiod_set_value_cansleep(reset_gpio, 0);
 		wmb();
 		mdelay(1);
-		gpiod_set_value_cansleep(reset_gpio, 0);
+		gpiod_set_value_cansleep(reset_gpio, 1);
 	}
 	return 0;
 }
Signature · 1 line
2.39.2
maintainer Applied
#1 lore raw
Quoted 18 lines · Martin Schiller

Commit 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API") not only switched to the gpiod API, but also inverted / changed the polarity of the GPIO.

According to the PCI specification, the RST# pin is an active-low signal. However, most of the device trees that have been widely used for a long time (mainly in the openWrt project) define this GPIO as active-high and the old driver code inverted the signal internally.

Apparently there are actually boards where the reset gpio must be operated inverted. For this reason, we cannot use the GPIOD_OUT_LOW/HIGH flag for initialization. Instead, we must explicitly set the gpio to value 1 in order to take into account any "GPIO_ACTIVE_LOW" flag that may have been set.

In order to remain compatible with all these existing device trees, we should therefore keep the logic as it was before the commit.

Quoted 6 lines
Fixes 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API")
---
 arch/mips/pci/pci-lantiq.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

applied to mips-fixes

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
#2 lore raw

Hi Thomas, Martin,

Quoted 19 lines · Thomas Bogendoerfer
Quoted 18 lines · Martin Schiller

Commit 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API") not only switched to the gpiod API, but also inverted / changed the polarity of the GPIO.

According to the PCI specification, the RST# pin is an active-low signal. However, most of the device trees that have been widely used for a long time (mainly in the openWrt project) define this GPIO as active-high and the old driver code inverted the signal internally.

Apparently there are actually boards where the reset gpio must be operated inverted. For this reason, we cannot use the GPIOD_OUT_LOW/HIGH flag for initialization. Instead, we must explicitly set the gpio to value 1 in order to take into account any "GPIO_ACTIVE_LOW" flag that may have been set.

In order to remain compatible with all these existing device trees, we should therefore keep the logic as it was before the commit.

Quoted 8 lines
Quoted 6 lines
Fixes 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API")
---
 arch/mips/pci/pci-lantiq.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

applied to mips-fixes

The patch is unfortunately also wrong as it will break any board that actually has correct polarity annotation.

I will prepare a quirk for drivers/gpio/gpiolib-of.c to force the polarity to low for this GPIO.

Thanks.

Signature · 1 line
Dmitry
#3 lore raw
In reply to Martin Schiller

Hi Marton,

Quoted 9 lines · Martin Schiller

Commit 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API") not only switched to the gpiod API, but also inverted / changed the polarity of the GPIO.

According to the PCI specification, the RST# pin is an active-low signal. However, most of the device trees that have been widely used for a long time (mainly in the openWrt project) define this GPIO as active-high and the old driver code inverted the signal internally.

Quoted 5 lines

Apparently there are actually boards where the reset gpio must be operated inverted. For this reason, we cannot use the GPIOD_OUT_LOW/HIGH flag for initialization. Instead, we must explicitly set the gpio to value 1 in order to take into account any "GPIO_ACTIVE_LOW" flag that may have been set.

Do you have example of such boards? They could not have worked before 90c2d2eb7ab5 because it was actively setting the reset line to physical high, which should leave the device in reset state if there is an inverter between the AP and the device.

Quoted 3 lines

In order to remain compatible with all these existing device trees, we should therefore keep the logic as it was before the commit.

With gpiod API operating with logical states there's still difference in logic:

	gpiod_set_value_cansleep(reset_gpio, 1);

will leave GPIO at 1 if it is described as GPIO_ACTIVE_HIGH (which is apparently what you want for boards with broken DTS) but for boards that accurately describe GPIO as GPIO_ACTIVE_LOW it well drive GPIO to 0, leaving the card in reset state.

You should either use gpiod_set_raw_value_calsleep() or we can try and quirk it in gpiolib (like we do for many other cases of incorrect GPIO polarity descriptions and which is my preference).

This still leaves the question about boards that require inversion. Are you saying that they have real signal inverter on the line or that their device trees correctly describe the signal as GPIO_ACTIVE_LOW?

BTW, please consider getting DTS trees for your devices into mainline. Why do you keep them separate?

Quoted 45 lines
Fixes 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API")
---
 arch/mips/pci/pci-lantiq.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/mips/pci/pci-lantiq.c +4 -4
index 68a8cefed420..0844db34022e 100644
@@ -124,14 +124,14 @@ static int ltq_pci_startup(struct platform_device *pdev)
 		clk_disable(clk_external);
 
 	/* setup reset gpio used by pci */
-	reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
-					     GPIOD_OUT_LOW);
+	reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset", GPIOD_ASIS);
 	error = PTR_ERR_OR_ZERO(reset_gpio);
 	if (error) {
 		dev_err(&pdev->dev, "failed to request gpio: %d\n", error);
 		return error;
 	}
 	gpiod_set_consumer_name(reset_gpio, "pci_reset");
+	gpiod_direction_output(reset_gpio, 1);
 
 	/* enable auto-switching between PCI and EBU */
 	ltq_pci_w32(0xa, PCI_CR_CLK_CTRL);
@@ -194,10 +194,10 @@ static int ltq_pci_startup(struct platform_device *pdev)
 
 	/* toggle reset pin */
 	if (reset_gpio) {
-		gpiod_set_value_cansleep(reset_gpio, 1);
+		gpiod_set_value_cansleep(reset_gpio, 0);
 		wmb();
 		mdelay(1);
-		gpiod_set_value_cansleep(reset_gpio, 0);
+		gpiod_set_value_cansleep(reset_gpio, 1);
 	}
 	return 0;
 }
Signature · 1 line
2.39.2

Thanks.

Signature · 1 line
Dmitry
#4 lore raw
Quoted 1 line · Dmitry Torokhov

Hi Marton,

Hi Dmitry,

Quoted 17 lines · Martin Schiller
Quoted 9 lines

Commit 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API") not only switched to the gpiod API, but also inverted / changed the polarity of the GPIO.

According to the PCI specification, the RST# pin is an active-low signal. However, most of the device trees that have been widely used for a long time (mainly in the openWrt project) define this GPIO as active-high and the old driver code inverted the signal internally.

Quoted 5 lines

Apparently there are actually boards where the reset gpio must be operated inverted. For this reason, we cannot use the GPIOD_OUT_LOW/HIGH flag for initialization. Instead, we must explicitly set the gpio to value 1 in order to take into account any "GPIO_ACTIVE_LOW" flag that may have been set.

Quoted 4 lines

Do you have example of such boards? They could not have worked before 90c2d2eb7ab5 because it was actively setting the reset line to physical high, which should leave the device in reset state if there is an inverter between the AP and the device.

Oh, you're right. I totally missed that '__gpio_set_value' was used in the original code and that raw accesses took place without paying attention to the GPIO_ACTIVE_* flags.

You can find the device trees I am talking about in [1].

@Thomas Bogendoerfer:
Would it be possible to stop the merging of this patch? I think We have to do do some further/other changes.

Quoted 19 lines
Quoted 4 lines

In order to remain compatible with all these existing device trees, we should therefore keep the logic as it was before the commit.

With gpiod API operating with logical states there's still difference in logic:

	gpiod_set_value_cansleep(reset_gpio, 1);

will leave GPIO at 1 if it is described as GPIO_ACTIVE_HIGH (which is apparently what you want for boards with broken DTS) but for boards that accurately describe GPIO as GPIO_ACTIVE_LOW it well drive GPIO to 0, leaving the card in reset state.

You should either use gpiod_set_raw_value_calsleep() or we can try and quirk it in gpiolib (like we do for many other cases of incorrect GPIO polarity descriptions and which is my preference).

Quoted 6 lines

This still leaves the question about boards that require inversion. Are you saying that they have real signal inverter on the line or that their device trees correctly describe the signal as GPIO_ACTIVE_LOW?

BTW, please consider getting DTS trees for your devices into mainline. Why do you keep them separate?

Unfortunately, these are not "my" devices and I can't even test them. I've got feedback from some users when I updated the lantiq target to linux 6.1 in openwrt.

Let's assume that all boards physically expect an active-low signal.

If the GPIO_ACTIVE_LOW flag were now set in the device tree, the original (old) driver would have an incorrect initial level (LOW instead of HIGH) due to the

	gpio_direction_output(reset_gpio, 1);

This is probably the reason why the flag GPIO_ACTIVE_HIGH is set in almost all dts files in openwrt.

But with commit 90c2d2eb7ab5 the initial level (LOW) is guaranteed to be wrong because of the "GPIOD_OUT_LOW" and cannot be changed by "wrong" device tree settings.

The signal curve is LOW -> LOW -> HIGH instead of HIGH -> LOW -> HIGH.

Quoted 35 lines
Quoted 35 lines
Fixes 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API")
---
 arch/mips/pci/pci-lantiq.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/mips/pci/pci-lantiq.c +2 -2
index 68a8cefed420..0844db34022e 100644
@@ -124,14 +124,14 @@ static int ltq_pci_startup(struct 
 platform_device *pdev)
 		clk_disable(clk_external);
 
 	/* setup reset gpio used by pci */
-	reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
-					     GPIOD_OUT_LOW);
+	reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset", 
 GPIOD_ASIS);
 	error = PTR_ERR_OR_ZERO(reset_gpio);
 	if (error) {
 		dev_err(&pdev->dev, "failed to request gpio: %d\n", error);
 		return error;
 	}
 	gpiod_set_consumer_name(reset_gpio, "pci_reset");
+	gpiod_direction_output(reset_gpio, 1);
 
arch/mips/pci/pci-lantiq.c +0 -0
 	/* enable auto-switching between PCI and EBU */
 	ltq_pci_w32(0xa, PCI_CR_CLK_CTRL);
@@ -194,10 +194,10 @@ static int ltq_pci_startup(struct 
 platform_device *pdev)
 
Quoted 16 lines
Quoted 10 lines
arch/mips/pci/pci-lantiq.c +2 -2
 	/* toggle reset pin */
 	if (reset_gpio) {
-		gpiod_set_value_cansleep(reset_gpio, 1);
+		gpiod_set_value_cansleep(reset_gpio, 0);
 		wmb();
 		mdelay(1);
-		gpiod_set_value_cansleep(reset_gpio, 0);
+		gpiod_set_value_cansleep(reset_gpio, 1);
 	}
 	return 0;
Quoted 4 lines

}
--
2.39.2

Thanks.

[1] https://git.openwrt.org/?p=openwrt/openwrt.git;a=tree;f=target/linux/lantiq/files/arch/mips/boot/dts/lantiq

#5 lore raw
Quoted 31 lines · Martin Schiller
Quoted 1 line · Dmitry Torokhov

Hi Marton,

Hi Dmitry,

Quoted 17 lines · Martin Schiller
Quoted 9 lines

Commit 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API") not only switched to the gpiod API, but also inverted / changed the polarity of the GPIO.

According to the PCI specification, the RST# pin is an active-low signal. However, most of the device trees that have been widely used for a long time (mainly in the openWrt project) define this GPIO as active-high and the old driver code inverted the signal internally.

Quoted 5 lines

Apparently there are actually boards where the reset gpio must be operated inverted. For this reason, we cannot use the GPIOD_OUT_LOW/HIGH flag for initialization. Instead, we must explicitly set the gpio to value 1 in order to take into account any "GPIO_ACTIVE_LOW" flag that may have been set.

Quoted 4 lines

Do you have example of such boards? They could not have worked before 90c2d2eb7ab5 because it was actively setting the reset line to physical high, which should leave the device in reset state if there is an inverter between the AP and the device.

Oh, you're right. I totally missed that '__gpio_set_value' was used in the original code and that raw accesses took place without paying attention to the GPIO_ACTIVE_* flags.

Quoted 24 lines

You can find the device trees I am talking about in [1].

@Thomas Bogendoerfer:
Would it be possible to stop the merging of this patch? I think We have to do do some further/other changes.

Quoted 18 lines
Quoted 4 lines

In order to remain compatible with all these existing device trees, we should therefore keep the logic as it was before the commit.

With gpiod API operating with logical states there's still difference in logic:

	gpiod_set_value_cansleep(reset_gpio, 1);

will leave GPIO at 1 if it is described as GPIO_ACTIVE_HIGH (which is apparently what you want for boards with broken DTS) but for boards that accurately describe GPIO as GPIO_ACTIVE_LOW it well drive GPIO to 0, leaving the card in reset state.

You should either use gpiod_set_raw_value_calsleep() or we can try and quirk it in gpiolib (like we do for many other cases of incorrect GPIO polarity descriptions and which is my preference).

So you mean we should add an entry for "lantiq,pci-xway" to the of_gpio_try_fixup_polarity()?
Do you know any dts / device outside the openWrt universe which is using this driver.

For the lantiq targets in openWrt, the devicetree blob is appended to the kernel image and therefore also updated when doing a firmware upgrade. So, maybe it would also be an option to fix the driver (using GPIO_ACTIVE_* flag for the initial level and set it to 0 -> 1 -> 0) and rework all the dts files to use GPIO_ACTIVE_LOW.

Then we won't need any quirks.

Quoted 84 lines
Quoted 7 lines

This still leaves the question about boards that require inversion. Are you saying that they have real signal inverter on the line or that their device trees correctly describe the signal as GPIO_ACTIVE_LOW?

BTW, please consider getting DTS trees for your devices into mainline. Why do you keep them separate?

Unfortunately, these are not "my" devices and I can't even test them. I've got feedback from some users when I updated the lantiq target to linux 6.1 in openwrt.

Let's assume that all boards physically expect an active-low signal.

If the GPIO_ACTIVE_LOW flag were now set in the device tree, the original (old) driver would have an incorrect initial level (LOW instead of HIGH) due to the

	gpio_direction_output(reset_gpio, 1);

This is probably the reason why the flag GPIO_ACTIVE_HIGH is set in almost all dts files in openwrt.

But with commit 90c2d2eb7ab5 the initial level (LOW) is guaranteed to be wrong because of the "GPIOD_OUT_LOW" and cannot be changed by "wrong" device tree settings.

The signal curve is LOW -> LOW -> HIGH instead of HIGH -> LOW -> HIGH.

Quoted 35 lines
Quoted 35 lines
Fixes 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API")
---
 arch/mips/pci/pci-lantiq.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/mips/pci/pci-lantiq.c +2 -2
index 68a8cefed420..0844db34022e 100644
@@ -124,14 +124,14 @@ static int ltq_pci_startup(struct 
 platform_device *pdev)
 		clk_disable(clk_external);
 
 	/* setup reset gpio used by pci */
-	reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
-					     GPIOD_OUT_LOW);
+	reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset", 
 GPIOD_ASIS);
 	error = PTR_ERR_OR_ZERO(reset_gpio);
 	if (error) {
 		dev_err(&pdev->dev, "failed to request gpio: %d\n", error);
 		return error;
 	}
 	gpiod_set_consumer_name(reset_gpio, "pci_reset");
+	gpiod_direction_output(reset_gpio, 1);
 
arch/mips/pci/pci-lantiq.c +0 -0
 	/* enable auto-switching between PCI and EBU */
 	ltq_pci_w32(0xa, PCI_CR_CLK_CTRL);
@@ -194,10 +194,10 @@ static int ltq_pci_startup(struct 
 platform_device *pdev)
 
Quoted 16 lines
Quoted 10 lines
arch/mips/pci/pci-lantiq.c +2 -2
 	/* toggle reset pin */
 	if (reset_gpio) {
-		gpiod_set_value_cansleep(reset_gpio, 1);
+		gpiod_set_value_cansleep(reset_gpio, 0);
 		wmb();
 		mdelay(1);
-		gpiod_set_value_cansleep(reset_gpio, 0);
+		gpiod_set_value_cansleep(reset_gpio, 1);
 	}
 	return 0;
Quoted 4 lines

}
--
2.39.2

Thanks.

[1]
https://git.openwrt.org/?p=openwrt/openwrt.git;a=tree;f=target/linux/lantiq/files/arch/mips/boot/dts/lantiq

#6 lore raw
Quoted 60 lines · Martin Schiller
Quoted 59 lines · Martin Schiller
Quoted 1 line · Dmitry Torokhov

Hi Marton,

Hi Dmitry,

Quoted 21 lines · Martin Schiller
Quoted 12 lines

Commit 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API") not
only switched to the gpiod API, but also inverted / changed the polarity
of the GPIO.

According to the PCI specification, the RST# pin is an active-low signal. However, most of the device trees that have been widely used for
a long time (mainly in the openWrt project) define this GPIO as active-high and the old driver code inverted the signal internally.

Quoted 6 lines

Apparently there are actually boards where the reset gpio must be operated inverted. For this reason, we cannot use the GPIOD_OUT_LOW/HIGH
flag for initialization. Instead, we must explicitly set the gpio to value 1 in order to take into account any "GPIO_ACTIVE_LOW" flag that may have been set.

Quoted 5 lines

Do you have example of such boards? They could not have worked before 90c2d2eb7ab5 because it was actively setting the reset line to physical
high, which should leave the device in reset state if there is an inverter between the AP and the device.

Oh, you're right. I totally missed that '__gpio_set_value' was used in the original code and that raw accesses took place without paying attention to the GPIO_ACTIVE_* flags.

You can find the device trees I am talking about in [1].

@Thomas Bogendoerfer:
Would it be possible to stop the merging of this patch? I think We have to do do some further/other changes.

Quoted 17 lines
Quoted 5 lines

In order to remain compatible with all these existing device trees, we
should therefore keep the logic as it was before the commit.

With gpiod API operating with logical states there's still difference in
logic:

	gpiod_set_value_cansleep(reset_gpio, 1);

will leave GPIO at 1 if it is described as GPIO_ACTIVE_HIGH (which is apparently what you want for boards with broken DTS) but for boards that accurately describe GPIO as GPIO_ACTIVE_LOW it well drive GPIO to 0, leaving the card in reset state.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

You should either use gpiod_set_raw_value_calsleep() or we can try and quirk it in gpiolib (like we do for many other cases of incorrect GPIO polarity descriptions and which is my preference).

So you mean we should add an entry for "lantiq,pci-xway" to the of_gpio_try_fixup_polarity()?
Do you know any dts / device outside the openWrt universe which is using this driver.

No, I don't.

Could you please try this:

drivers/gpio/gpiolib-of.c +11 -1
index 59c7f8a2431a..4948ecaa422c 100644
@@ -203,6 +203,16 @@ static void of_gpio_try_fixup_polarity(const struct device_node *np,
 		 */
 		{ "qi,lb60",		"rb-gpios",	true },
 #endif
+#if IS_ENABLED(CONFIG_PCI_LANTIQ)
+		/*
+		 * According to the PCI specification, the RST# pin is an
+		 * active-low signal. However, most of the device trees that
+		 * have been widely used for a long time incorrectly describe
+		 * reset GPIO as active-high, and were also using wrong name
+		 * for the property.
+		 */
+		{ "lantiq,pci-xway",	"gpios-reset",	false },
+#endif
 #if IS_ENABLED(CONFIG_TOUCHSCREEN_TSC2005)
 		/*
 		 * DTS for Nokia N900 incorrectly specified "active high"
@@ -512,7 +522,7 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
 		{ "reset",	"reset-n-io",	"marvell,nfc-uart" },
 		{ "reset",	"reset-n-io",	"mrvl,nfc-uart" },
 #endif
-#if !IS_ENABLED(CONFIG_PCI_LANTIQ)
+#if IS_ENABLED(CONFIG_PCI_LANTIQ)
 		/* MIPS Lantiq PCI */
 		{ "reset",	"gpios-reset",	"lantiq,pci-xway" },
 #endif

Thanks.

Signature · 1 line
Dmitry
#7 lore raw
Quoted 81 lines · Dmitry Torokhov
Quoted 60 lines · Martin Schiller
Quoted 59 lines · Martin Schiller
Quoted 1 line · Dmitry Torokhov

Hi Marton,

Hi Dmitry,

Quoted 21 lines · Martin Schiller
Quoted 12 lines

Commit 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API") not
only switched to the gpiod API, but also inverted / changed the polarity
of the GPIO.

According to the PCI specification, the RST# pin is an active-low signal. However, most of the device trees that have been widely used for
a long time (mainly in the openWrt project) define this GPIO as active-high and the old driver code inverted the signal internally.

Quoted 6 lines

Apparently there are actually boards where the reset gpio must be operated inverted. For this reason, we cannot use the GPIOD_OUT_LOW/HIGH
flag for initialization. Instead, we must explicitly set the gpio to value 1 in order to take into account any "GPIO_ACTIVE_LOW" flag that may have been set.

Quoted 5 lines

Do you have example of such boards? They could not have worked before 90c2d2eb7ab5 because it was actively setting the reset line to physical
high, which should leave the device in reset state if there is an inverter between the AP and the device.

Oh, you're right. I totally missed that '__gpio_set_value' was used in the original code and that raw accesses took place without paying attention to the GPIO_ACTIVE_* flags.

You can find the device trees I am talking about in [1].

@Thomas Bogendoerfer:
Would it be possible to stop the merging of this patch? I think We have to do do some further/other changes.

Quoted 17 lines
Quoted 5 lines

In order to remain compatible with all these existing device trees, we
should therefore keep the logic as it was before the commit.

With gpiod API operating with logical states there's still difference in
logic:

	gpiod_set_value_cansleep(reset_gpio, 1);

will leave GPIO at 1 if it is described as GPIO_ACTIVE_HIGH (which is apparently what you want for boards with broken DTS) but for boards that accurately describe GPIO as GPIO_ACTIVE_LOW it well drive GPIO to 0, leaving the card in reset state.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

You should either use gpiod_set_raw_value_calsleep() or we can try and quirk it in gpiolib (like we do for many other cases of incorrect GPIO polarity descriptions and which is my preference).

So you mean we should add an entry for "lantiq,pci-xway" to the of_gpio_try_fixup_polarity()?
Do you know any dts / device outside the openWrt universe which is using this driver.

No, I don't.

Could you please try this:

drivers/gpio/gpiolib-of.c +0 -0
index 59c7f8a2431a..4948ecaa422c 100644
@@ -203,6 +203,16 @@ static void of_gpio_try_fixup_polarity(const struct device_node *np,
 		 */
 		{ "qi,lb60",		"rb-gpios",	true },

drivers/gpio/gpiolib-of.c static void of_gpio_try_fixup_polarity(const struct device_node *np, · line 214

Quoted 10 lines
drivers/gpio/gpiolib-of.c +9 -0
 #endif
+#if IS_ENABLED(CONFIG_PCI_LANTIQ)
+		/*
+		 * According to the PCI specification, the RST# pin is an
+		 * active-low signal. However, most of the device trees that
+		 * have been widely used for a long time incorrectly describe
+		 * reset GPIO as active-high, and were also using wrong name
+		 * for the property.
+		 */
+		{ "lantiq,pci-xway",	"gpios-reset",	false },

Sorry, "gpios-reset" is wrong, the driver used "gpio-reset". So:

drivers/gpio/gpiolib-of.c +12 -2
index 59c7f8a2431a..d21085830632 100644
@@ -203,6 +203,16 @@ static void of_gpio_try_fixup_polarity(const struct device_node *np,
 		 */
 		{ "qi,lb60",		"rb-gpios",	true },
 #endif
+#if IS_ENABLED(CONFIG_PCI_LANTIQ)
+		/*
+		 * According to the PCI specification, the RST# pin is an
+		 * active-low signal. However, most of the device trees that
+		 * have been widely used for a long time incorrectly describe
+		 * reset GPIO as active-high, and were also using wrong name
+		 * for the property.
+		 */
+		{ "lantiq,pci-xway",	"gpio-reset",	false },
+#endif
 #if IS_ENABLED(CONFIG_TOUCHSCREEN_TSC2005)
 		/*
 		 * DTS for Nokia N900 incorrectly specified "active high"
@@ -512,9 +522,9 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
 		{ "reset",	"reset-n-io",	"marvell,nfc-uart" },
 		{ "reset",	"reset-n-io",	"mrvl,nfc-uart" },
 #endif
-#if !IS_ENABLED(CONFIG_PCI_LANTIQ)
+#if IS_ENABLED(CONFIG_PCI_LANTIQ)
 		/* MIPS Lantiq PCI */
-		{ "reset",	"gpios-reset",	"lantiq,pci-xway" },
+		{ "reset",	"gpio-reset",	"lantiq,pci-xway" },
 #endif
 
 		/*
Signature · 1 line
Dmitry
#8 lore raw
Quoted 130 lines · Dmitry Torokhov
Quoted 82 lines · Dmitry Torokhov
Quoted 60 lines · Martin Schiller
Quoted 59 lines · Martin Schiller
Quoted 1 line · Dmitry Torokhov

Hi Marton,

Hi Dmitry,

Quoted 21 lines · Martin Schiller
Quoted 12 lines

Commit 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API") not
only switched to the gpiod API, but also inverted / changed the polarity
of the GPIO.

According to the PCI specification, the RST# pin is an active-low signal. However, most of the device trees that have been widely used for
a long time (mainly in the openWrt project) define this GPIO as active-high and the old driver code inverted the signal internally.

Quoted 6 lines

Apparently there are actually boards where the reset gpio must be operated inverted. For this reason, we cannot use the GPIOD_OUT_LOW/HIGH
flag for initialization. Instead, we must explicitly set the gpio to value 1 in order to take into account any "GPIO_ACTIVE_LOW" flag that may have been set.

Quoted 5 lines

Do you have example of such boards? They could not have worked before 90c2d2eb7ab5 because it was actively setting the reset line to physical
high, which should leave the device in reset state if there is an inverter between the AP and the device.

Oh, you're right. I totally missed that '__gpio_set_value' was used in the original code and that raw accesses took place without paying attention to the GPIO_ACTIVE_* flags.

You can find the device trees I am talking about in [1].

@Thomas Bogendoerfer:
Would it be possible to stop the merging of this patch? I think We have to do do some further/other changes.

Quoted 17 lines
Quoted 5 lines

In order to remain compatible with all these existing device trees, we
should therefore keep the logic as it was before the commit.

With gpiod API operating with logical states there's still difference in
logic:

	gpiod_set_value_cansleep(reset_gpio, 1);

will leave GPIO at 1 if it is described as GPIO_ACTIVE_HIGH (which is apparently what you want for boards with broken DTS) but for boards that accurately describe GPIO as GPIO_ACTIVE_LOW it well drive GPIO to 0, leaving the card in reset state.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

You should either use gpiod_set_raw_value_calsleep() or we can try and quirk it in gpiolib (like we do for many other cases of incorrect GPIO polarity descriptions and which is my preference).

So you mean we should add an entry for "lantiq,pci-xway" to the of_gpio_try_fixup_polarity()?
Do you know any dts / device outside the openWrt universe which is using this driver.

No, I don't.

Could you please try this:

drivers/gpio/gpiolib-of.c +0 -0
index 59c7f8a2431a..4948ecaa422c 100644
@@ -203,6 +203,16 @@ static void of_gpio_try_fixup_polarity(const 
 struct device_node *np,
 		 */
 		{ "qi,lb60",		"rb-gpios",	true },

drivers/gpio/gpiolib-of.c static void of_gpio_try_fixup_polarity(const · line 215

Quoted 10 lines
drivers/gpio/gpiolib-of.c +9 -0
 #endif
+#if IS_ENABLED(CONFIG_PCI_LANTIQ)
+		/*
+		 * According to the PCI specification, the RST# pin is an
+		 * active-low signal. However, most of the device trees that
+		 * have been widely used for a long time incorrectly describe
+		 * reset GPIO as active-high, and were also using wrong name
+		 * for the property.
+		 */
+		{ "lantiq,pci-xway",	"gpios-reset",	false },

Sorry, "gpios-reset" is wrong, the driver used "gpio-reset". So:

drivers/gpio/gpiolib-of.c +10 -0
index 59c7f8a2431a..d21085830632 100644
@@ -203,6 +203,16 @@ static void of_gpio_try_fixup_polarity(const
 struct device_node *np,
 		 */
 		{ "qi,lb60",		"rb-gpios",	true },
 #endif
+#if IS_ENABLED(CONFIG_PCI_LANTIQ)
+		/*
+		 * According to the PCI specification, the RST# pin is an
+		 * active-low signal. However, most of the device trees that
+		 * have been widely used for a long time incorrectly describe
+		 * reset GPIO as active-high, and were also using wrong name
+		 * for the property.
+		 */
+		{ "lantiq,pci-xway",	"gpio-reset",	false },
+#endif
 #if IS_ENABLED(CONFIG_TOUCHSCREEN_TSC2005)
 		/*
drivers/gpio/gpiolib-of.c +2 -2
 		 * DTS for Nokia N900 incorrectly specified "active high"
@@ -512,9 +522,9 @@ static struct gpio_desc
 *of_find_gpio_rename(struct device_node *np,
 		{ "reset",	"reset-n-io",	"marvell,nfc-uart" },
 		{ "reset",	"reset-n-io",	"mrvl,nfc-uart" },
 #endif
-#if !IS_ENABLED(CONFIG_PCI_LANTIQ)
+#if IS_ENABLED(CONFIG_PCI_LANTIQ)
 		/* MIPS Lantiq PCI */
-		{ "reset",	"gpios-reset",	"lantiq,pci-xway" },
+		{ "reset",	"gpio-reset",	"lantiq,pci-xway" },
 #endif
 
Quoted 1 line

/*

I wonder, when this renaming did not work so far, why did we not see the error message "failed to request gpio" in the log?

@Aleksander Jan Bajkowski:
You had problems with the PCI connection when you switched to linux 6.1 and also have corresponding devices to test.

Could you please remove my patch in the latest openWrt and try out Dmitry's change?

#9 lore raw
Quoted 130 lines · Martin Schiller
Quoted 129 lines · Dmitry Torokhov
Quoted 81 lines · Dmitry Torokhov
Quoted 60 lines · Martin Schiller
Quoted 59 lines · Martin Schiller
Quoted 1 line · Dmitry Torokhov

Hi Marton,

Hi Dmitry,

Quoted 21 lines · Martin Schiller
Quoted 12 lines

Commit 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API") not
only switched to the gpiod API, but also inverted / changed the polarity
of the GPIO.

According to the PCI specification, the RST# pin is an active-low signal. However, most of the device trees that have been widely used for
a long time (mainly in the openWrt project) define this GPIO as active-high and the old driver code inverted the signal internally.

Quoted 6 lines

Apparently there are actually boards where the reset gpio must be operated inverted. For this reason, we cannot use the GPIOD_OUT_LOW/HIGH
flag for initialization. Instead, we must explicitly set the gpio to value 1 in order to take into account any "GPIO_ACTIVE_LOW" flag that may have been set.

Quoted 5 lines

Do you have example of such boards? They could not have worked before 90c2d2eb7ab5 because it was actively setting the reset line to physical
high, which should leave the device in reset state if there is an inverter between the AP and the device.

Oh, you're right. I totally missed that '__gpio_set_value' was used in the original code and that raw accesses took place without paying attention to the GPIO_ACTIVE_* flags.

You can find the device trees I am talking about in [1].

@Thomas Bogendoerfer:
Would it be possible to stop the merging of this patch? I think We have to do do some further/other changes.

Quoted 17 lines
Quoted 5 lines

In order to remain compatible with all these existing device trees, we
should therefore keep the logic as it was before the commit.

With gpiod API operating with logical states there's still difference in
logic:

	gpiod_set_value_cansleep(reset_gpio, 1);

will leave GPIO at 1 if it is described as GPIO_ACTIVE_HIGH (which is apparently what you want for boards with broken DTS) but for boards that accurately describe GPIO as GPIO_ACTIVE_LOW it well drive GPIO to 0, leaving the card in reset state.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

You should either use gpiod_set_raw_value_calsleep() or we can try and quirk it in gpiolib (like we do for many other cases of incorrect GPIO polarity descriptions and which is my preference).

So you mean we should add an entry for "lantiq,pci-xway" to the of_gpio_try_fixup_polarity()?
Do you know any dts / device outside the openWrt universe which is using this driver.

No, I don't.

Could you please try this:

drivers/gpio/gpiolib-of.c +0 -0
index 59c7f8a2431a..4948ecaa422c 100644
@@ -203,6 +203,16 @@ static void of_gpio_try_fixup_polarity(const struct device_node *np,
 		 */
 		{ "qi,lb60",		"rb-gpios",	true },

drivers/gpio/gpiolib-of.c static void of_gpio_try_fixup_polarity(const struct device_node *np, · line 214

Quoted 10 lines
drivers/gpio/gpiolib-of.c +9 -0
 #endif
+#if IS_ENABLED(CONFIG_PCI_LANTIQ)
+		/*
+		 * According to the PCI specification, the RST# pin is an
+		 * active-low signal. However, most of the device trees that
+		 * have been widely used for a long time incorrectly describe
+		 * reset GPIO as active-high, and were also using wrong name
+		 * for the property.
+		 */
+		{ "lantiq,pci-xway",	"gpios-reset",	false },

Sorry, "gpios-reset" is wrong, the driver used "gpio-reset". So:

drivers/gpio/gpiolib-of.c +10 -0
index 59c7f8a2431a..d21085830632 100644
@@ -203,6 +203,16 @@ static void of_gpio_try_fixup_polarity(const
 struct device_node *np,
 		 */
 		{ "qi,lb60",		"rb-gpios",	true },
 #endif
+#if IS_ENABLED(CONFIG_PCI_LANTIQ)
+		/*
+		 * According to the PCI specification, the RST# pin is an
+		 * active-low signal. However, most of the device trees that
+		 * have been widely used for a long time incorrectly describe
+		 * reset GPIO as active-high, and were also using wrong name
+		 * for the property.
+		 */
+		{ "lantiq,pci-xway",	"gpio-reset",	false },
+#endif
 #if IS_ENABLED(CONFIG_TOUCHSCREEN_TSC2005)
 		/*
drivers/gpio/gpiolib-of.c +2 -2
 		 * DTS for Nokia N900 incorrectly specified "active high"
@@ -512,9 +522,9 @@ static struct gpio_desc
 *of_find_gpio_rename(struct device_node *np,
 		{ "reset",	"reset-n-io",	"marvell,nfc-uart" },
 		{ "reset",	"reset-n-io",	"mrvl,nfc-uart" },
 #endif
-#if !IS_ENABLED(CONFIG_PCI_LANTIQ)
+#if IS_ENABLED(CONFIG_PCI_LANTIQ)
 		/* MIPS Lantiq PCI */
-		{ "reset",	"gpios-reset",	"lantiq,pci-xway" },
+		{ "reset",	"gpio-reset",	"lantiq,pci-xway" },
 #endif
 
Quoted 4 lines
Quoted 1 line

/*

I wonder, when this renaming did not work so far, why did we not see the error message "failed to request gpio" in the log?

The GPIO is requested as optional, so if it's not found there's no error.

Interestingly the only user in the mainline kernel uses "gpios-reset" in is device tree which never worked.

Signature · 1 line
Dmitry
#10 lore raw
In reply to Martin Schiller
Quoted 62 lines · Martin Schiller
Quoted 31 lines · Martin Schiller
Quoted 1 line · Dmitry Torokhov

Hi Marton,

Hi Dmitry,

Quoted 17 lines · Martin Schiller
Quoted 9 lines

Commit 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API") not only switched to the gpiod API, but also inverted / changed the polarity of the GPIO.

According to the PCI specification, the RST# pin is an active-low signal. However, most of the device trees that have been widely used for a long time (mainly in the openWrt project) define this GPIO as active-high and the old driver code inverted the signal internally.

Quoted 5 lines

Apparently there are actually boards where the reset gpio must be operated inverted. For this reason, we cannot use the GPIOD_OUT_LOW/HIGH flag for initialization. Instead, we must explicitly set the gpio to value 1 in order to take into account any "GPIO_ACTIVE_LOW" flag that may have been set.

Quoted 4 lines

Do you have example of such boards? They could not have worked before 90c2d2eb7ab5 because it was actively setting the reset line to physical high, which should leave the device in reset state if there is an inverter between the AP and the device.

Oh, you're right. I totally missed that '__gpio_set_value' was used in the original code and that raw accesses took place without paying attention to the GPIO_ACTIVE_* flags.

Quoted 24 lines

You can find the device trees I am talking about in [1].

@Thomas Bogendoerfer:
Would it be possible to stop the merging of this patch? I think We have to do do some further/other changes.

Quoted 18 lines
Quoted 4 lines

In order to remain compatible with all these existing device trees, we should therefore keep the logic as it was before the commit.

With gpiod API operating with logical states there's still difference in logic:

    gpiod_set_value_cansleep(reset_gpio, 1);

will leave GPIO at 1 if it is described as GPIO_ACTIVE_HIGH (which is apparently what you want for boards with broken DTS) but for boards that accurately describe GPIO as GPIO_ACTIVE_LOW it well drive GPIO to 0, leaving the card in reset state.

You should either use gpiod_set_raw_value_calsleep() or we can try and quirk it in gpiolib (like we do for many other cases of incorrect GPIO polarity descriptions and which is my preference).

So you mean we should add an entry for "lantiq,pci-xway" to the of_gpio_try_fixup_polarity()?
Do you know any dts / device outside the openWrt universe which is using this driver.

Quoted 7 lines

For the lantiq targets in openWrt, the devicetree blob is appended to the kernel image and therefore also updated when doing a firmware upgrade. So, maybe it would also be an option to fix the driver (using GPIO_ACTIVE_* flag for the initial level and set it to 0 -> 1 -> 0) and rework all the dts files to use GPIO_ACTIVE_LOW.

Then we won't need any quirks.

I am not aware that anyone is using a recent kernel on the VRX200 outside of OpenWrt. I am also not aware that anyone is *not* appending the DTB to the kernel. The SoC is pretty old now, the successor of this SoC was released about 10 years ago.

For me it would be fine if you fix the broken device device trees shipped with the upstream kernel and with OpenWrt to make them work with the PCI driver instead of investing too much time into handling old DTBs.

The PCI reset is inverted on some boards to handle a dying gasp. If the power breaks down the reset should get triggered and the PCIe device can send a dying gasp signal to the other side. This is done on the reference designs of some Lantiq PCIe DSL card for the VRX318 and probably also some other components.

Hauke

#11 lore raw
Quoted 69 lines · Hauke Mehrtens
Quoted 68 lines · Martin Schiller
Quoted 31 lines · Martin Schiller
Quoted 1 line · Dmitry Torokhov

Hi Marton,

Hi Dmitry,

Quoted 17 lines · Martin Schiller
Quoted 9 lines

Commit 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API") not only switched to the gpiod API, but also inverted / changed the polarity of the GPIO.

According to the PCI specification, the RST# pin is an active-low signal. However, most of the device trees that have been widely used for a long time (mainly in the openWrt project) define this GPIO as active-high and the old driver code inverted the signal internally.

Quoted 5 lines

Apparently there are actually boards where the reset gpio must be operated inverted. For this reason, we cannot use the GPIOD_OUT_LOW/HIGH flag for initialization. Instead, we must explicitly set the gpio to value 1 in order to take into account any "GPIO_ACTIVE_LOW" flag that may have been set.

Quoted 4 lines

Do you have example of such boards? They could not have worked before 90c2d2eb7ab5 because it was actively setting the reset line to physical high, which should leave the device in reset state if there is an inverter between the AP and the device.

Oh, you're right. I totally missed that '__gpio_set_value' was used in the original code and that raw accesses took place without paying attention to the GPIO_ACTIVE_* flags.

Quoted 24 lines

You can find the device trees I am talking about in [1].

@Thomas Bogendoerfer:
Would it be possible to stop the merging of this patch? I think We have to do do some further/other changes.

Quoted 18 lines
Quoted 4 lines

In order to remain compatible with all these existing device trees, we should therefore keep the logic as it was before the commit.

With gpiod API operating with logical states there's still difference in logic:

    gpiod_set_value_cansleep(reset_gpio, 1);

will leave GPIO at 1 if it is described as GPIO_ACTIVE_HIGH (which is apparently what you want for boards with broken DTS) but for boards that accurately describe GPIO as GPIO_ACTIVE_LOW it well drive GPIO to 0, leaving the card in reset state.

You should either use gpiod_set_raw_value_calsleep() or we can try and quirk it in gpiolib (like we do for many other cases of incorrect GPIO polarity descriptions and which is my preference).

So you mean we should add an entry for "lantiq,pci-xway" to the of_gpio_try_fixup_polarity()?
Do you know any dts / device outside the openWrt universe which is using this driver.

For the lantiq targets in openWrt, the devicetree blob is appended to the kernel image and therefore also updated when doing a firmware upgrade. So, maybe it would also be an option to fix the driver (using GPIO_ACTIVE_* flag for the initial level and set it to 0 -> 1 -> 0) and rework all the dts files to use GPIO_ACTIVE_LOW.

Quoted 7 lines
Quoted 1 line

Then we won't need any quirks.

I am not aware that anyone is using a recent kernel on the VRX200 outside of OpenWrt. I am also not aware that anyone is *not* appending the DTB to the kernel. The SoC is pretty old now, the successor of this SoC was released about 10 years ago.

We're not just talking about VRX200 (VR9) here, but even older devices such as AR9 and Danube.

Quoted 5 lines

For me it would be fine if you fix the broken device device trees shipped with the upstream kernel and with OpenWrt to make them work with the PCI driver instead of investing too much time into handling old DTBs.

Quoted 7 lines

The PCI reset is inverted on some boards to handle a dying gasp. If the power breaks down the reset should get triggered and the PCIe device can send a dying gasp signal to the other side. This is done on the reference designs of some Lantiq PCIe DSL card for the VRX318 and probably also some other components.

Hauke

What I missed so far is the fact that the driver used '__gpio_set_value' before Dmitry's commit and thus used raw access to the GPIO.

This effectively means that every device that has worked with the driver so far must have an ACTIVE_LOW reset, no matter what was configured in the device tree.

So renaming the property in the dts from "gpio-reset" to "reset-gpios" and setting the FLAGS to "GPIO_ACTIVE_LOW" should actually solve the problem.

What still bothers me about the driver itself are 2 things:
1. the initial value of GPIOD_OUT_LOW. This means that there is no real defined HIGH -> LOW -> HIGH on reset.
2. if we change 1., then I think "mdelay(1)" is too short and we would have to change it to at least "mdelay(100)".

Martin

#12 lore raw
Quoted 80 lines · Martin Schiller
Quoted 79 lines · Hauke Mehrtens
Quoted 78 lines · Martin Schiller
Quoted 40 lines · Martin Schiller
Quoted 1 line · Dmitry Torokhov

Hi Marton,

Hi Dmitry,

Quoted 23 lines · Martin Schiller
Quoted 12 lines

Commit 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API") not
only switched to the gpiod API, but also inverted / changed the polarity
of the GPIO.

According to the PCI specification, the RST# pin is an active-low signal. However, most of the device trees that have been widely used for
a long time (mainly in the openWrt project) define this GPIO as active-high and the old driver code inverted the signal internally.

Quoted 8 lines

Apparently there are actually boards where the reset gpio must be operated inverted. For this reason, we cannot use the GPIOD_OUT_LOW/HIGH
flag for initialization. Instead, we must explicitly set the gpio to
value 1 in order to take into account any "GPIO_ACTIVE_LOW" flag that
may have been set.

Quoted 6 lines

Do you have example of such boards? They could not have worked before
90c2d2eb7ab5 because it was actively setting the reset line to physical
high, which should leave the device in reset state if there is an inverter between the AP and the device.

Oh, you're right. I totally missed that '__gpio_set_value' was used in
the original code and that raw accesses took place without paying attention to the GPIO_ACTIVE_* flags.

Quoted 30 lines

You can find the device trees I am talking about in [1].

@Thomas Bogendoerfer:
Would it be possible to stop the merging of this patch? I think We have to do do some further/other changes.

Quoted 24 lines
Quoted 5 lines

In order to remain compatible with all these existing device trees, we
should therefore keep the logic as it was before the commit.

With gpiod API operating with logical states there's still difference in
logic:

    gpiod_set_value_cansleep(reset_gpio, 1);

will leave GPIO at 1 if it is described as GPIO_ACTIVE_HIGH (which is
apparently what you want for boards with broken DTS) but for boards that accurately describe GPIO as GPIO_ACTIVE_LOW it well drive GPIO to
0, leaving the card in reset state.

You should either use gpiod_set_raw_value_calsleep() or we can try and
quirk it in gpiolib (like we do for many other cases of incorrect GPIO
polarity descriptions and which is my preference).

So you mean we should add an entry for "lantiq,pci-xway" to the of_gpio_try_fixup_polarity()?
Do you know any dts / device outside the openWrt universe which is using
this driver.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

For the lantiq targets in openWrt, the devicetree blob is appended to the kernel image and therefore also updated when doing a firmware upgrade. So, maybe it would also be an option to fix the driver (using GPIO_ACTIVE_* flag for the initial level and set it to 0 -> 1 -> 0) and
rework all the dts files to use GPIO_ACTIVE_LOW.

Yes, cleaning up DTS files when it is possible is nice.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Then we won't need any quirks.

Quirks are fairly cheap and we are not in a hot path here.

Quoted 26 lines
Quoted 6 lines

I am not aware that anyone is using a recent kernel on the VRX200 outside of OpenWrt. I am also not aware that anyone is *not* appending the DTB to the kernel. The SoC is pretty old now, the successor of this SoC was released about 10 years ago.

We're not just talking about VRX200 (VR9) here, but even older devices such as AR9 and Danube.

Quoted 5 lines

For me it would be fine if you fix the broken device device trees shipped with the upstream kernel and with OpenWrt to make them work with the PCI driver instead of investing too much time into handling old DTBs.

Quoted 7 lines

The PCI reset is inverted on some boards to handle a dying gasp. If the power breaks down the reset should get triggered and the PCIe device can send a dying gasp signal to the other side. This is done on the reference designs of some Lantiq PCIe DSL card for the VRX318 and probably also some other components.

Hauke

What I missed so far is the fact that the driver used '__gpio_set_value' before Dmitry's commit and thus used raw access to the GPIO.

Quoted 8 lines

This effectively means that every device that has worked with the driver so far must have an ACTIVE_LOW reset, no matter what was configured in the device tree.

So renaming the property in the dts from "gpio-reset" to "reset-gpios" and setting the FLAGS to "GPIO_ACTIVE_LOW" should actually solve the problem.

Right, luckily (to a definition of luckily) the driver and DTB used "wrong" syntax for the gpio property, so we can quirk it and make force ACTIVE_LOW polarity on old DTBs, and new DTBs with "reset-gpios" property will follow polarity specified in DTB.

Quoted 4 lines

What still bothers me about the driver itself are 2 things:
1. the initial value of GPIOD_OUT_LOW. This means that there is no real defined HIGH -> LOW -> HIGH on reset.

Is this actually needed? Typically a card requires certain time in reset state (with reset line active) before it can be released, however there usually no restrictions on line being inactive beforehand. But typically it will be pulled up to avoid leakage...

Thanks.

Signature · 1 line
Dmitry
#13 lore raw
Quoted 126 lines · Dmitry Torokhov
Quoted 80 lines · Martin Schiller
Quoted 79 lines · Hauke Mehrtens
Quoted 78 lines · Martin Schiller
Quoted 40 lines · Martin Schiller
Quoted 1 line · Dmitry Torokhov

Hi Marton,

Hi Dmitry,

Quoted 23 lines · Martin Schiller
Quoted 12 lines

Commit 90c2d2eb7ab5 ("MIPS: pci: lantiq: switch to using gpiod API") not
only switched to the gpiod API, but also inverted / changed the polarity
of the GPIO.

According to the PCI specification, the RST# pin is an active-low signal. However, most of the device trees that have been widely used for
a long time (mainly in the openWrt project) define this GPIO as active-high and the old driver code inverted the signal internally.

Quoted 8 lines

Apparently there are actually boards where the reset gpio must be operated inverted. For this reason, we cannot use the GPIOD_OUT_LOW/HIGH
flag for initialization. Instead, we must explicitly set the gpio to
value 1 in order to take into account any "GPIO_ACTIVE_LOW" flag that
may have been set.

Quoted 6 lines

Do you have example of such boards? They could not have worked before
90c2d2eb7ab5 because it was actively setting the reset line to physical
high, which should leave the device in reset state if there is an inverter between the AP and the device.

Oh, you're right. I totally missed that '__gpio_set_value' was used in
the original code and that raw accesses took place without paying attention to the GPIO_ACTIVE_* flags.

Quoted 30 lines

You can find the device trees I am talking about in [1].

@Thomas Bogendoerfer:
Would it be possible to stop the merging of this patch? I think We have to do do some further/other changes.

Quoted 24 lines
Quoted 5 lines

In order to remain compatible with all these existing device trees, we
should therefore keep the logic as it was before the commit.

With gpiod API operating with logical states there's still difference in
logic:

    gpiod_set_value_cansleep(reset_gpio, 1);

will leave GPIO at 1 if it is described as GPIO_ACTIVE_HIGH (which is
apparently what you want for boards with broken DTS) but for boards that accurately describe GPIO as GPIO_ACTIVE_LOW it well drive GPIO to
0, leaving the card in reset state.

You should either use gpiod_set_raw_value_calsleep() or we can try and
quirk it in gpiolib (like we do for many other cases of incorrect GPIO
polarity descriptions and which is my preference).

So you mean we should add an entry for "lantiq,pci-xway" to the of_gpio_try_fixup_polarity()?
Do you know any dts / device outside the openWrt universe which is using
this driver.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

For the lantiq targets in openWrt, the devicetree blob is appended to the kernel image and therefore also updated when doing a firmware upgrade. So, maybe it would also be an option to fix the driver (using GPIO_ACTIVE_* flag for the initial level and set it to 0 -> 1 -> 0) and
rework all the dts files to use GPIO_ACTIVE_LOW.

Yes, cleaning up DTS files when it is possible is nice.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Then we won't need any quirks.

Quirks are fairly cheap and we are not in a hot path here.

Quoted 31 lines
Quoted 6 lines

I am not aware that anyone is using a recent kernel on the VRX200 outside of OpenWrt. I am also not aware that anyone is *not* appending the DTB to the kernel. The SoC is pretty old now, the successor of this SoC was released about 10 years ago.

We're not just talking about VRX200 (VR9) here, but even older devices such as AR9 and Danube.

Quoted 5 lines

For me it would be fine if you fix the broken device device trees shipped with the upstream kernel and with OpenWrt to make them work with the PCI driver instead of investing too much time into handling old DTBs.

Quoted 7 lines

The PCI reset is inverted on some boards to handle a dying gasp. If the power breaks down the reset should get triggered and the PCIe device can send a dying gasp signal to the other side. This is done on the reference designs of some Lantiq PCIe DSL card for the VRX318 and probably also some other components.

Hauke

What I missed so far is the fact that the driver used '__gpio_set_value' before Dmitry's commit and thus used raw access to the GPIO.

This effectively means that every device that has worked with the driver so far must have an ACTIVE_LOW reset, no matter what was configured in the device tree.

Quoted 8 lines
Quoted 3 lines

So renaming the property in the dts from "gpio-reset" to "reset-gpios" and setting the FLAGS to "GPIO_ACTIVE_LOW" should actually solve the problem.

Right, luckily (to a definition of luckily) the driver and DTB used "wrong" syntax for the gpio property, so we can quirk it and make force ACTIVE_LOW polarity on old DTBs, and new DTBs with "reset-gpios" property will follow polarity specified in DTB.

We have already adapted the device trees in openWrt. [1] Will you create a quirk patch for the old DTBs or should I create one?

Quoted 11 lines
Quoted 5 lines

What still bothers me about the driver itself are 2 things:
1. the initial value of GPIOD_OUT_LOW. This means that there is no real defined HIGH -> LOW -> HIGH on reset.

Is this actually needed? Typically a card requires certain time in reset state (with reset line active) before it can be released, however there usually no restrictions on line being inactive beforehand. But typically it will be pulled up to avoid leakage...

No, I don't think that's absolutely necessary. Several tests have so far shown that it works as it is at the moment.

[1] https://git.openwrt.org/?p=openwrt/openwrt.git;a=commitdiff;h=f6fe19ed6dfaf0444cd80f530bf89f6878fd5936

#14 lore raw
In reply to Martin Schiller
Quoted 3 lines · Martin Schiller

@Thomas Bogendoerfer:
Would it be possible to stop the merging of this patch? I think We have to do do some further/other changes.

I'll revert the patch in mips-fixes.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]