Skip to contentSkip to conversation

net: dsa: realtek: support reset controller and update docs

PATCH Superseded Luiz Angelo Daros de Luca 3 participants 8 messages Feb 14, 2024 – Feb 16, 2024

Subsystems (5)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Luiz Angelo Daros de Luca

author maintainer
#0 lore raw

v3 cover net: dsa: realtek: support reset controller and update docs

The driver previously supported reset pins using GPIO, but it lacked support for reset controllers. Although a reset method is generally not required, the driver fails to detect the switch if the reset was kept asserted by a previous driver.

This series adds support to reset a Realtek switch using a reset controller. It also updates the binding documentation to remove the requirement of a reset method and to add the new reset controller property.

It was tested on a TL-WR1043ND v1 router (rtl8366rb via SMI).

---

Changes in v3:
- Rebased on the Realtek DSA driver refactoring (08f627164126)
- Dropped the reset controller example in bindings
- Used %pe in error printing
- Linked to v2: https://lore.kernel.org/r/[email protected]/

Changes in v2:
- Introduced a dedicated commit for removing the reset-gpios requirement
- Placed binding patches before code changes
- Removed the 'reset-names' property
- Moved the example from the commit message to realtek.yaml
- Split the reset function into _assert/_deassert variants
- Modified reset functions to return a warning instead of a value
- Utilized devm_reset_control_get_optional to prevent failure when the reset control is missing
- Used 'true' and 'false' for boolean values
- Removed the CONFIG_RESET_CONTROLLER check as stub methods are sufficient when undefined
- Linked to v1: https://lore.kernel.org/r/[email protected]/

---
Luiz Angelo Daros de Luca (3):
dt-bindings: net: dsa: realtek: reset-gpios is not required
dt-bindings: net: dsa: realtek: add reset controller
net: dsa: realtek: support reset controller

 .../devicetree/bindings/net/dsa/realtek.yaml       |  4 +-
 drivers/net/dsa/realtek/realtek.h                  |  2 +
 drivers/net/dsa/realtek/rtl83xx.c                  | 52 +++++++++++++++++++---
 drivers/net/dsa/realtek/rtl83xx.h                  |  2 +
 4 files changed, 54 insertions(+), 6 deletions(-)

---
base-commit: 0f37666d87d2dea42ec21776c3d562b7cbd71612
change-id: 20240212-realtek-reset-88a0bf25bb22

Best regards,

Signature · 1 line
Luiz Angelo Daros de Luca <[email protected]>
author maintainer
#1 lore raw

PATCH v3 1/3 dt-bindings: net: dsa: realtek: reset-gpios is not required

The 'reset-gpios' should not be mandatory. although they might be required for some devices if the switch reset was left asserted by a previous driver, such as the bootloader.

---
 Documentation/devicetree/bindings/net/dsa/realtek.yaml | 1 -
 1 file changed, 1 deletion(-)
Documentation/devicetree/bindings/net/dsa/realtek.yaml +0 -1
index cce692f57b08..46e113df77c8 100644
@@ -127,7 +127,6 @@ else:
     - mdc-gpios
     - mdio-gpios
     - mdio
-    - reset-gpios
 
 required:
   - compatible
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH v3 2/3 dt-bindings: net: dsa: realtek: add reset controller

In reply to Luiz Angelo Daros de Luca

Realtek switches can use a reset controller instead of reset-gpios.

---
 Documentation/devicetree/bindings/net/dsa/realtek.yaml | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/net/dsa/realtek.yaml +3 -0
index 46e113df77c8..70b6bda3cf98 100644
@@ -59,6 +59,9 @@ properties:
     description: GPIO to be used to reset the whole device
     maxItems: 1
 
+  resets:
+    maxItems: 1
+
   realtek,disable-leds:
     type: boolean
     description: |
Signature · 1 line
2.43.0
author maintainer
#3 lore raw

PATCH v3 3/3 net: dsa: realtek: support reset controller

In reply to Luiz Angelo Daros de Luca

The 'reset-gpios' will not work when the switch reset is controlled by a reset controller.

Although the reset is optional and the driver performs a soft reset during setup, if the initial reset state was asserted, the driver will not detect it.

The reset controller will take precedence over the reset GPIO.

---
 drivers/net/dsa/realtek/realtek.h |  2 ++
 drivers/net/dsa/realtek/rtl83xx.c | 52 +++++++++++++++++++++++++++++++++++----
 drivers/net/dsa/realtek/rtl83xx.h |  2 ++
 3 files changed, 51 insertions(+), 5 deletions(-)
drivers/net/dsa/realtek/realtek.h +2 -0
index b80bfde1ad04..e0b1aa01337b 100644
@@ -12,6 +12,7 @@
 #include <linux/platform_device.h>
 #include <linux/gpio/consumer.h>
 #include <net/dsa.h>
+#include <linux/reset.h>
 
 #define REALTEK_HW_STOP_DELAY		25	/* msecs */
 #define REALTEK_HW_START_DELAY		100	/* msecs */
@@ -48,6 +49,7 @@ struct rtl8366_vlan_4k {
 
 struct realtek_priv {
 	struct device		*dev;
+	struct reset_control    *reset_ctl;
 	struct gpio_desc	*reset;
 	struct gpio_desc	*mdc;
 	struct gpio_desc	*mdio;
drivers/net/dsa/realtek/rtl83xx.c +47 -5

75 lines not on this page · raw message

drivers/net/dsa/realtek/rtl83xx.h +2 -0
index 0ddff33df6b0..c8a0ff8fd75e 100644
@@ -18,5 +18,7 @@ int rtl83xx_register_switch(struct realtek_priv *priv);
 void rtl83xx_unregister_switch(struct realtek_priv *priv);
 void rtl83xx_shutdown(struct realtek_priv *priv);
 void rtl83xx_remove(struct realtek_priv *priv);
+void rtl83xx_reset_assert(struct realtek_priv *priv);
+void rtl83xx_reset_deassert(struct realtek_priv *priv);
 
 #endif /* _RTL83XX_H */
Signature · 1 line
2.43.0
Reviewed-by on v3 3/3
#4 lore raw

Re: [PATCH net-next v3 3/3] net: dsa: realtek: support reset controller

Hi Luiz,

thanks for your patch!

Quoted 10 lines · Luiz Angelo Daros de Luca

The 'reset-gpios' will not work when the switch reset is controlled by a reset controller.

Although the reset is optional and the driver performs a soft reset during setup, if the initial reset state was asserted, the driver will not detect it.

The reset controller will take precedence over the reset GPIO.

(...)

drivers/net/dsa/realtek/rtl83xx.c EXPORT_SYMBOL_NS_GPL(rtl83xx_shutdown, REALTEK_DSA); · line 311

Quoted 6 lines
drivers/net/dsa/realtek/rtl83xx.c +6 -0
+void rtl83xx_reset_assert(struct realtek_priv *priv)
+{
+       int ret;
+
+       if (priv->reset_ctl) {
+               ret = reset_control_assert(priv->reset_ctl);

Actually, reset_control_assert() is NULL-tolerand (as well as the stubs) so you can just issue this unconditionally. If priv->reset_ctl is NULL it will just return 0.

drivers/net/dsa/realtek/rtl83xx.c EXPORT_SYMBOL_NS_GPL(rtl83xx_shutdown, REALTEK_DSA); · line 321

Quoted 10 lines
drivers/net/dsa/realtek/rtl83xx.c +10 -0
+               if (!ret)
+                       return;
+
+               dev_warn(priv->dev,
+                        "Failed to assert the switch reset control: %pe\n",
+                        ERR_PTR(ret));
+       }
+
+       if (priv->reset)
+               gpiod_set_value(priv->reset, true);

Same here! Also NULL-tolerant. You do not need to check priv->reset. Just issue it.

Quoted 1 line

+void rtl83xx_reset_deassert(struct realtek_priv *priv)

Same comments for deassert.

With this fixed (the rest looks just fine):

Yours,
Linus Walleij

author maintainer
#5 lore raw

Re: [PATCH net-next v3 3/3] net: dsa: realtek: support reset controller

Quoted 1 line

Hi Luiz,

Hi Linus,

Quoted 1 line

thanks for your patch!

I'm glad to help ;-)

Quoted 14 lines
Quoted 10 lines · Luiz Angelo Daros de Luca

The 'reset-gpios' will not work when the switch reset is controlled by a reset controller.

Although the reset is optional and the driver performs a soft reset during setup, if the initial reset state was asserted, the driver will not detect it.

The reset controller will take precedence over the reset GPIO.

(...)

Quoted 10 lines

drivers/net/dsa/realtek/rtl83xx.c EXPORT_SYMBOL_NS_GPL(rtl83xx_shutdown, REALTEK_DSA); · line 311

Quoted 6 lines
drivers/net/dsa/realtek/rtl83xx.c +6 -0
+void rtl83xx_reset_assert(struct realtek_priv *priv)
+{
+       int ret;
+
+       if (priv->reset_ctl) {
+               ret = reset_control_assert(priv->reset_ctl);

Actually, reset_control_assert() is NULL-tolerand (as well as the stubs) so you can just issue this unconditionally. If priv->reset_ctl is NULL it will just return 0.

The idea was to avoid gpiod_set_value if the reset_control_assert was configured and worked. However, I don't see a big issue in calling them both as you don't expect both to be configured.
I'll remove the "ifs not null" and let both be called.

Quoted 24 lines

drivers/net/dsa/realtek/rtl83xx.c EXPORT_SYMBOL_NS_GPL(rtl83xx_shutdown, REALTEK_DSA); · line 321

Quoted 11 lines
drivers/net/dsa/realtek/rtl83xx.c +10 -0
+               if (!ret)
+                       return;
+
+               dev_warn(priv->dev,
+                        "Failed to assert the switch reset control: %pe\n",
+                        ERR_PTR(ret));
+       }
+
+       if (priv->reset)
+               gpiod_set_value(priv->reset, true);

Same here! Also NULL-tolerant. You do not need to check priv->reset. Just issue it.

Quoted 1 line

+void rtl83xx_reset_deassert(struct realtek_priv *priv)

Same comments for deassert.

With this fixed (the rest looks just fine):

Yours,
Linus Walleij

maintainer
#6 lore raw

Re: [PATCH net-next v3 3/3] net: dsa: realtek: support reset controller

Quoted 25 lines · Luiz Angelo Daros de Luca
Quoted 14 lines
Quoted 10 lines · Luiz Angelo Daros de Luca

The 'reset-gpios' will not work when the switch reset is controlled by a reset controller.

Although the reset is optional and the driver performs a soft reset during setup, if the initial reset state was asserted, the driver will not detect it.

The reset controller will take precedence over the reset GPIO.

(...)

Quoted 10 lines

drivers/net/dsa/realtek/rtl83xx.c EXPORT_SYMBOL_NS_GPL(rtl83xx_shutdown, REALTEK_DSA); · line 311

Quoted 6 lines
drivers/net/dsa/realtek/rtl83xx.c +6 -0
+void rtl83xx_reset_assert(struct realtek_priv *priv)
+{
+       int ret;
+
+       if (priv->reset_ctl) {
+               ret = reset_control_assert(priv->reset_ctl);

Actually, reset_control_assert() is NULL-tolerand (as well as the stubs) so you can just issue this unconditionally. If priv->reset_ctl is NULL it will just return 0.

Quoted 4 lines

The idea was to avoid gpiod_set_value if the reset_control_assert was configured and worked. However, I don't see a big issue in calling them both as you don't expect both to be configured.
I'll remove the "ifs not null" and let both be called.

In the defense of Linus' comment, your proposed code did not do what you seem to have intended anyway. If priv->reset_ctl was non-NULL, it fell through and potentially ran gpiod_set_value() anyway - there was no early "return". So, the simplification comment was predictable.

maintainer
#7 lore raw

Re: [PATCH net-next v3 3/3] net: dsa: realtek: support reset controller

In reply to Luiz Angelo Daros de Luca
Quoted 3 lines · Luiz Angelo Daros de Luca
Quoted 1 line
Quoted 1 line

The reset controller will take precedence over the reset GPIO.

I'll remove the "ifs not null" and let both be called.

If you do, be sure to update the commit message about it (see first line).