Skip to contentSkip to conversation

net: dsa: lan9303: fix reset on probe

PATCH Applied Mans Rullgard 5 participants 8 messages Feb 9, 2022 – Feb 11, 2022

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

PATCH 1/1 net: dsa: lan9303: fix reset on probe

The reset input to the LAN9303 chip is active low, and devicetree gpio handles reflect this. Therefore, the gpio should be requested with an initial state of high in order for the reset signal to be asserted. Other uses of the gpio already use the correct polarity.

---
 drivers/net/dsa/lan9303-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/lan9303-core.c +1 -1
index aa1142d6a9f5..2de67708bbd2 100644
@@ -1301,7 +1301,7 @@ static int lan9303_probe_reset_gpio(struct lan9303 *chip,
 				     struct device_node *np)
 {
 	chip->reset_gpio = devm_gpiod_get_optional(chip->dev, "reset",
-						   GPIOD_OUT_LOW);
+						   GPIOD_OUT_HIGH);
 	if (IS_ERR(chip->reset_gpio))
 		return PTR_ERR(chip->reset_gpio);
 
Signature · 1 line
2.35.1
maintainer
#1 lore raw
Quoted 15 lines · Mans Rullgard

The reset input to the LAN9303 chip is active low, and devicetree gpio handles reflect this. Therefore, the gpio should be requested with an initial state of high in order for the reset signal to be asserted. Other uses of the gpio already use the correct polarity.

---
 drivers/net/dsa/lan9303-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/lan9303-core.c +0 -0
index aa1142d6a9f5..2de67708bbd2 100644

drivers/net/dsa/lan9303-core.c static int lan9303_probe_reset_gpio(struct lan9303 *chip, · line 1306

Quoted 7 lines
drivers/net/dsa/lan9303-core.c +1 -1
@@ -1301,7 +1301,7 @@ static int lan9303_probe_reset_gpio(struct lan9303 *chip,
 				     struct device_node *np)
 {
 	chip->reset_gpio = devm_gpiod_get_optional(chip->dev, "reset",
-						   GPIOD_OUT_LOW);
+						   GPIOD_OUT_HIGH);
 	if (IS_ERR(chip->reset_gpio))
 		return PTR_ERR(chip->reset_gpio);

lan9303_handle_reset() does a sleep and then releases the reset. I don't see anywhere in the driver which asserts the reset first. So is it actually asserted as part of this getting the GPIO? And if so, does not this change actually break the reset?

Andrew

#2 lore raw
Quoted 20 lines · Andrew Lunn
Quoted 19 lines · Mans Rullgard

The reset input to the LAN9303 chip is active low, and devicetree gpio handles reflect this. Therefore, the gpio should be requested with an initial state of high in order for the reset signal to be asserted. Other uses of the gpio already use the correct polarity.

---
 drivers/net/dsa/lan9303-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/lan9303-core.c +0 -1
index aa1142d6a9f5..2de67708bbd2 100644
@@ -1301,7 +1301,7 @@ static int lan9303_probe_reset_gpio(struct lan9303 *chip,
 				     struct device_node *np)
 {
 	chip->reset_gpio = devm_gpiod_get_optional(chip->dev, "reset",
-						   GPIOD_OUT_LOW);
Quoted 8 lines

drivers/net/dsa/lan9303-core.c static int lan9303_probe_reset_gpio(struct lan9303 *chip, · line 1306

Quoted 3 lines
drivers/net/dsa/lan9303-core.c +1 -0
+						   GPIOD_OUT_HIGH);
 	if (IS_ERR(chip->reset_gpio))
 		return PTR_ERR(chip->reset_gpio);

lan9303_handle_reset() does a sleep and then releases the reset. I don't see anywhere in the driver which asserts the reset first. So is it actually asserted as part of this getting the GPIO? And if so, does not this change actually break the reset?

The GPIOD_OUT_xxx flags to gpiod_get() request that the pin be configured as output and set to high/low initially. The GPIOD_OUT_LOW currently used by the lan9303 driver together with GPIO_ACTIVE_LOW in the devicetrees results in the actual voltage being set high. The driver then sleeps for a bit before setting the gpio value to zero, again translated to a high output voltage. That is, the value set after the sleep is the same as it was initially. This is obviously not the intent.

With the patch applied, I can measure the reset signal pulse low for the configured duration when the device is probed. Without the patch, the reset signal remains high and no reset of the device occurs.

Signature · 1 line
Måns Rullgård
maintainer Reviewed-by
#3 lore raw
Quoted 31 lines · Måns Rullgård
Quoted 20 lines · Andrew Lunn
Quoted 19 lines · Mans Rullgard

The reset input to the LAN9303 chip is active low, and devicetree gpio handles reflect this. Therefore, the gpio should be requested with an initial state of high in order for the reset signal to be asserted. Other uses of the gpio already use the correct polarity.

---
 drivers/net/dsa/lan9303-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/lan9303-core.c +0 -1
index aa1142d6a9f5..2de67708bbd2 100644
@@ -1301,7 +1301,7 @@ static int lan9303_probe_reset_gpio(struct lan9303 *chip,
 				     struct device_node *np)
 {
 	chip->reset_gpio = devm_gpiod_get_optional(chip->dev, "reset",
-						   GPIOD_OUT_LOW);
Quoted 8 lines

drivers/net/dsa/lan9303-core.c static int lan9303_probe_reset_gpio(struct lan9303 *chip, · line 1306

Quoted 3 lines
drivers/net/dsa/lan9303-core.c +1 -0
+						   GPIOD_OUT_HIGH);
 	if (IS_ERR(chip->reset_gpio))
 		return PTR_ERR(chip->reset_gpio);

lan9303_handle_reset() does a sleep and then releases the reset. I don't see anywhere in the driver which asserts the reset first. So is it actually asserted as part of this getting the GPIO? And if so, does not this change actually break the reset?

Quoted 8 lines

The GPIOD_OUT_xxx flags to gpiod_get() request that the pin be configured as output and set to high/low initially. The GPIOD_OUT_LOW currently used by the lan9303 driver together with GPIO_ACTIVE_LOW in the devicetrees results in the actual voltage being set high. The driver then sleeps for a bit before setting the gpio value to zero, again translated to a high output voltage. That is, the value set after the sleep is the same as it was initially. This is obviously not the intent.

Yes, i agree. I'm just wondering how this worked for whoever implemented this code. I guess it never actually did a reset, or the bootloader left the reset already in the asserted state, so that the gpiod_get() actual deasserted the reset?

Andrew

maintainer
#4 lore raw
In reply to Mans Rullgard
Quoted 6 lines · On Wed, 9 Feb 2022 14:54:54 +0000 Mans Rullgard wrote:

The reset input to the LAN9303 chip is active low, and devicetree gpio handles reflect this. Therefore, the gpio should be requested with an initial state of high in order for the reset signal to be asserted. Other uses of the gpio already use the correct polarity.

Pending Andrew's review, this is the correct fixes tag, right?

Fixes a1292595e006 ("net: dsa: add new DSA switch driver for the SMSC-LAN9303")
#5 lore raw
Quoted 11 lines · Jakub Kicinski
Quoted 6 lines · On Wed, 9 Feb 2022 14:54:54 +0000 Mans Rullgard wrote:

The reset input to the LAN9303 chip is active low, and devicetree gpio handles reflect this. Therefore, the gpio should be requested with an initial state of high in order for the reset signal to be asserted. Other uses of the gpio already use the correct polarity.

Pending Andrew's review, this is the correct fixes tag, right?

Fixes a1292595e006 ("net: dsa: add new DSA switch driver for the SMSC-LAN9303")

Yes, the error has been there since the driver was first added.

Signature · 1 line
Måns Rullgård
Reviewed-by on v1 1/1
#6 lore raw
In reply to Mans Rullgard
Quoted 6 lines · Mans Rullgard

The reset input to the LAN9303 chip is active low, and devicetree gpio handles reflect this. Therefore, the gpio should be requested with an initial state of high in order for the reset signal to be asserted. Other uses of the gpio already use the correct polarity.

Signature · 1 line
Florian
#7 lore raw
In reply to Mans Rullgard
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Wed, 9 Feb 2022 14:54:54 +0000 you wrote:

The reset input to the LAN9303 chip is active low, and devicetree gpio handles reflect this. Therefore, the gpio should be requested with an initial state of high in order for the reset signal to be asserted. Other uses of the gpio already use the correct polarity.

[...]

Here is the summary with links:
- net: dsa: lan9303: fix reset on probe

    https://git.kernel.org/netdev/net/c/6bb9681a43f3

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html