net: dsa: realtek: realtek-mdio: reset before setup
Luiz Angelo Daros de Luca
maintainerv3 cover net: dsa: realtek: realtek-mdio: reset before setup
This patch series cleans the realtek-smi reset code and copy that to the realtek-mdio.
v1-v2)
- do not run reset code block if GPIO is missing. It was printing "RESET deasserted" even when there is no GPIO configured.
- reset switch after dsa_unregister_switch()
- demote reset messages to debug
v2-v3)
- do not assert the reset on gpiod_get. Do it explicitly aferwards.
- split the commit into two (one for each module)
Luiz Angelo Daros de Luca
maintainerPATCH v3 1/2 net: dsa: realtek: realtek-smi: clean-up reset
When reset GPIO was missing, the driver was still printing an info message and still trying to assert the reset. Although gpiod_set_value() will silently ignore calls with NULL gpio_desc, it is better to make it clear the driver might allow gpio_desc to be NULL.
The initial value for the reset pin was changed to GPIOD_OUT_LOW, followed by a gpiod_set_value() asserting the reset. This way, it will be easier to spot if and where the reset really happens.
A new "asserted RESET" message was added just after the reset is asserted, similar to the existing "deasserted RESET" message. Both messages were demoted to dbg. The code comment is not needed anymore.
--- drivers/net/dsa/realtek/realtek-smi.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/net/dsa/realtek/realtek-smi.c +13 -7
@@ -420,16 +420,19 @@ static int realtek_smi_probe(struct platform_device *pdev)/* TODO: if power is software controlled, set up any regulators here */ -/* Assert then deassert RESET */ - priv->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); + priv->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_LOW );if (IS_ERR (priv->reset)) {dev_err (dev,"failed to get RESET GPIO\n" );return PTR_ERR (priv->reset); } -msleep (REALTEK_SMI_HW_STOP_DELAY ); -gpiod_set_value (priv->reset,0 ); -msleep (REALTEK_SMI_HW_START_DELAY ); -dev_info (dev,"deasserted RESET\n" ); +if (priv->reset) { +gpiod_set_value (priv->reset,1 ); +dev_dbg (dev,"asserted RESET\n" ); +msleep (REALTEK_SMI_HW_STOP_DELAY ); +gpiod_set_value (priv->reset,0 ); +msleep (REALTEK_SMI_HW_START_DELAY ); +dev_dbg (dev,"deasserted RESET\n" ); + }/* Fetch MDIO pins */ priv->mdc =devm_gpiod_get_optional (dev,"mdc" ,GPIOD_OUT_LOW );
@@ -474,7 +477,10 @@ static int realtek_smi_remove(struct platform_device *pdev)dsa_unregister_switch (priv->ds);if (priv->slave_mii_bus)of_node_put (priv->slave_mii_bus->dev.of_node); -gpiod_set_value (priv->reset,1 ); + +/* leave the device reset asserted */ +if (priv->reset) +gpiod_set_value (priv->reset,1 );platform_set_drvdata (pdev,NULL );
Signature · 1 line
2.35.1
Re: [PATCH net-next v3 1/2] net: dsa: realtek: realtek-smi: clean-up reset
Quoted 9 lines · Luiz Angelo Daros de Luca
When reset GPIO was missing, the driver was still printing an info message and still trying to assert the reset. Although
gpiod_set_value()will silently ignore calls with NULLgpio_desc, it is better to make it clear the driver might allowgpio_descto be NULL.The initial value for the reset pin was changed to
GPIOD_OUT_LOW, followed by agpiod_set_value()asserting the reset. This way, it will be easier to spot if and where the reset really happens.
Quoted 5 lines
A new "asserted RESET" message was added just after the reset is asserted, similar to the existing "deasserted RESET" message. Both messages were demoted to dbg. The code comment is not needed anymore.
Signed-off-by Luiz Angelo Daros de Luca <[email protected]>
Arınç
Luiz Angelo Daros de Luca
maintainerPATCH v3 2/2 net: dsa: realtek: realtek-mdio: reset before setup
In reply to Luiz Angelo Daros de LucaSome devices, like the switch in Banana Pi BPI R64 only starts to answer after a HW reset. It is the same reset code from realtek-smi.
--- drivers/net/dsa/realtek/realtek-mdio.c | 19 +++++++++++++++++++ drivers/net/dsa/realtek/realtek-smi.c | 6 ++---- drivers/net/dsa/realtek/realtek.h | 3 +++ 3 files changed, 24 insertions(+), 4 deletions(-)
drivers/net/dsa/realtek/realtek-mdio.c +19 -0
@@ -152,6 +152,21 @@ static int realtek_mdio_probe(struct mdio_device *mdiodev)/* TODO: if power is software controlled, set up any regulators here */ priv->leds_disabled =of_property_read_bool (np,"realtek,disable-leds" ); + priv->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_LOW ); +if (IS_ERR (priv->reset)) { +dev_err (dev,"failed to get RESET GPIO\n" ); +return PTR_ERR (priv->reset); + } + +if (priv->reset) { +gpiod_set_value (priv->reset,1 ); +dev_dbg (dev,"asserted RESET\n" ); +msleep (REALTEK_HW_STOP_DELAY ); +gpiod_set_value (priv->reset,0 ); +msleep (REALTEK_HW_START_DELAY ); +dev_dbg (dev,"deasserted RESET\n" ); + } + ret = priv->ops->detect (priv);if (ret) {dev_err (dev,"unable to detect switch\n" );
@@ -185,6 +200,10 @@ static void realtek_mdio_remove(struct mdio_device *mdiodev)dsa_unregister_switch (priv->ds); +/* leave the device reset asserted */ +if (priv->reset) +gpiod_set_value (priv->reset,1 ); +dev_set_drvdata (&mdiodev->dev,NULL ); }
drivers/net/dsa/realtek/realtek-smi.c +2 -4
@@ -43,8 +43,6 @@#include "realtek.h" #define REALTEK_SMI_ACK_RETRY_COUNT 5 -#define REALTEK_SMI_HW_STOP_DELAY 25/* msecs */ -#define REALTEK_SMI_HW_START_DELAY 100/* msecs */ static inline void realtek_smi_clk_delay (struct realtek_priv *priv) {
@@ -428,9 +426,9 @@ static int realtek_smi_probe(struct platform_device *pdev)if (priv->reset) {gpiod_set_value (priv->reset,1 );dev_dbg (dev,"asserted RESET\n" ); -msleep (REALTEK_SMI_HW_STOP_DELAY ); +msleep (REALTEK_HW_STOP_DELAY );gpiod_set_value (priv->reset,0 ); -msleep (REALTEK_SMI_HW_START_DELAY ); +msleep (REALTEK_HW_START_DELAY );dev_dbg (dev,"deasserted RESET\n" ); }
drivers/net/dsa/realtek/realtek.h +3 -0
@@ -13,6 +13,9 @@#include <linux/gpio/consumer.h> #include <net/dsa.h> +#define REALTEK_HW_STOP_DELAY 25/* msecs */ +#define REALTEK_HW_START_DELAY 100/* msecs */ +struct realtek_ops ;struct dentry ;struct inode ;
Signature · 1 line
2.35.1
Quoted 8 lines · Luiz Angelo Daros de Luca
Some devices, like the switch in Banana Pi BPI R64 only starts to answer after a HW reset. It is the same reset code from realtek-smi.
Reported-by Frank Wunderlich <[email protected]>Signed-off-by Luiz Angelo Daros de Luca <[email protected]>Tested-by Frank Wunderlich <[email protected]>Reviewed-by Linus Walleij <[email protected]>Reviewed-by Alvin Šipraga <[email protected]>
Arınç
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 10 lines · On Sun, 13 Feb 2022 23:20:10 -0300 you wrote:
This patch series cleans the realtek-smi reset code and copy that to the realtek-mdio.
v1-v2)
- do not run reset code block if GPIO is missing. It was printing "RESET deasserted" even when there is no GPIO configured.
- reset switch afterdsa_unregister_switch()
- demote reset messages to debug[...]
Here is the summary with links:
- [net-next,v3,1/2] net: dsa: realtek: realtek-smi: clean-up reset
https://git.kernel.org/netdev/net-next/c/9a236b543f6b - [net-next,v3,2/2] net: dsa: realtek: realtek-mdio: reset before setup https://git.kernel.org/netdev/net-next/c/05f7b042c5a6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html