net: dsa: realtek: realtek-mdio: reset before setup
Luiz Angelo Daros de Luca
maintainerPATCH 1/1 net: dsa: realtek: realtek-mdio: reset before setup
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.
--- drivers/net/dsa/realtek/realtek-mdio.c | 19 +++++++++++++++++++ drivers/net/dsa/realtek/realtek-smi.c | 6 ++---- drivers/net/dsa/realtek/realtek.h | 9 ++++++--- 3 files changed, 27 insertions(+), 7 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" ); +/* Assert then deassert RESET */ + priv->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); +if (IS_ERR (priv->reset)) { +dev_err (dev,"failed to get RESET GPIO\n" ); +return PTR_ERR (priv->reset); + } + +if (priv->reset) { +dev_info (dev,"asserted RESET\n" ); +msleep (REALTEK_HW_STOP_DELAY ); +gpiod_set_value (priv->reset,0 ); +msleep (REALTEK_HW_START_DELAY ); +dev_info (dev,"deasserted RESET\n" ); + } + ret = priv->ops->detect (priv);if (ret) {dev_err (dev,"unable to detect switch\n" );
@@ -183,6 +198,10 @@ static void realtek_mdio_remove(struct mdio_device *mdiodev)if (!priv)return ; +/* leave the device reset asserted */ +if (priv->reset) +gpiod_set_value (priv->reset,1 ); +dsa_unregister_switch (priv->ds);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) {
@@ -426,9 +424,9 @@ static int realtek_smi_probe(struct platform_device *pdev)dev_err (dev,"failed to get RESET GPIO\n" );return PTR_ERR (priv->reset); } -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_info (dev,"deasserted RESET\n" );/* Fetch MDIO pins */
drivers/net/dsa/realtek/realtek.h +6 -3
@@ -5,14 +5,17 @@* Copyright (C) 2009-2010 Gabor Juhos <[email protected]> */ -#ifndef _REALTEK_SMI_H -#define _REALTEK_SMI_H +#ifndef _REALTEK_H +#define _REALTEK_H#include <linux/phy.h> #include <linux/platform_device.h> #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 ;
@@ -142,4 +145,4 @@ void rtl8366_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);extern const struct realtek_variant rtl8366rb_variant;extern const struct realtek_variant rtl8365mb_variant; -#endif /* _REALTEK_SMI_H */ +#endif /* _REALTEK_H */
Signature · 1 line
2.35.1
Am 11. Februar 2022 06:14:04 MEZ schrieb Luiz Angelo Daros de Luca <[email protected]>:
Quoted 107 lines
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]>---
drivers/net/dsa/realtek/realtek-mdio.c | 19 +++++++++++++++++++ drivers/net/dsa/realtek/realtek-smi.c | 6 ++---- drivers/net/dsa/realtek/realtek.h | 9 ++++++--- 3 files changed, 27 insertions(+), 7 deletions(-)drivers/net/dsa/realtek/realtek-mdio.c +15
-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" ); +/* Assert then deassert RESET */ + priv->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); +if (IS_ERR (priv->reset)) { +dev_err (dev,"failed to get RESET GPIO\n" ); +return PTR_ERR (priv->reset); + } + +if (priv->reset) { +dev_info (dev,"asserted RESET\n" ); +msleep (REALTEK_HW_STOP_DELAY ); +gpiod_set_value (priv->reset,0 ); +msleep (REALTEK_HW_START_DELAY ); +dev_info (dev,"deasserted RESET\n" ); + } +ret = priv->ops->detect(priv); if (ret) { dev_err(dev, "unable to detect switch\n");drivers/net/dsa/realtek/realtek-mdio.c +4
-0@@ -183,6 +198,10 @@ static void realtek_mdio_remove(struct mdio_device *mdiodev)if (!priv)return ; +/* leave the device reset asserted */ +if (priv->reset) +gpiod_set_value (priv->reset,1 ); +dsa_unregister_switch (priv->ds);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) {@@ -426,9 +424,9 @@ static int realtek_smi_probe(struct platform_device *pdev)dev_err (dev,"failed to get RESET GPIO\n" );return PTR_ERR (priv->reset); } -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_info (dev,"deasserted RESET\n" );/* Fetch MDIO pins */drivers/net/dsa/realtek/realtek.h +5
-2@@ -5,14 +5,17 @@* Copyright (C) 2009-2010 Gabor Juhos <[email protected]> */ -#ifndef _REALTEK_SMI_H -#define _REALTEK_SMI_H +#ifndef _REALTEK_H +#define _REALTEK_H#include <linux/phy.h> #include <linux/platform_device.h> #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 ;
drivers/net/dsa/realtek/realtek.h void rtl8366_get_ethtool_stats(struct dsa_switch · line 148
Quoted 6 lines
drivers/net/dsa/realtek/realtek.h +1
-1@@ -142,4 +145,4 @@ void rtl8366_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);extern const struct realtek_variant rtl8366rb_variant;extern const struct realtek_variant rtl8365mb_variant; -#endif /* _REALTEK_SMI_H */ +#endif /* _REALTEK_H */
Tested on Bpi-r64 v0.1. After this reset switch gets recognized. Before mdio-read is always 0.
regards Frank
Quoted 17 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]>--- drivers/net/dsa/realtek/realtek-mdio.c | 19 +++++++++++++++++++ drivers/net/dsa/realtek/realtek-smi.c | 6 ++---- drivers/net/dsa/realtek/realtek.h | 9 ++++++--- 3 files changed, 27 insertions(+), 7 deletions(-)drivers/net/dsa/realtek/realtek-mdio.c +0
-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 */
drivers/net/dsa/realtek/realtek-mdio.c static int realtek_mdio_probe(struct mdio_device *mdiodev) · line 162
Quoted 10 lines
drivers/net/dsa/realtek/realtek-mdio.c +8
-0priv->leds_disabled =of_property_read_bool (np,"realtek,disable-leds" ); +/* Assert then deassert RESET */ + priv->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); +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 seems tolerant of a NULL gpio_desc pointer, but perhaps you would like to add the same if statement to realtek-smi so that it doesn't pretend to reset the chip when the reset GPIO is absent?
Quoted 11 lines
drivers/net/dsa/realtek/realtek-mdio.c +7
-0+dev_info (dev,"asserted RESET\n" ); +msleep (REALTEK_HW_STOP_DELAY ); +gpiod_set_value (priv->reset,0 ); +msleep (REALTEK_HW_START_DELAY ); +dev_info (dev,"deasserted RESET\n" ); + } + ret = priv->ops->detect (priv);if (ret) {dev_err (dev,"unable to detect switch\n" );
drivers/net/dsa/realtek/realtek-mdio.c static void realtek_mdio_remove(struct mdio_device *mdiodev) · line 205
Quoted 8 lines
drivers/net/dsa/realtek/realtek-mdio.c +4
-0@@ -183,6 +198,10 @@ static void realtek_mdio_remove(struct mdio_device *mdiodev)if (!priv)return ; +/* leave the device reset asserted */ +if (priv->reset) +gpiod_set_value (priv->reset,1 ); +dsa_unregister_switch (priv->ds);
Wouldn't you prefer to reset the chip after dsa_unregister_switch()?
Otherwise:
Quoted 57 lines
drivers/net/dsa/realtek/realtek-mdio.c +0
-0dev_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) {@@ -426,9 +424,9 @@ static int realtek_smi_probe(struct platform_device *pdev)dev_err (dev,"failed to get RESET GPIO\n" );return PTR_ERR (priv->reset); } -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_info (dev,"deasserted RESET\n" );/* Fetch MDIO pins */ drivers/net/dsa/realtek/realtek.h +6
-3@@ -5,14 +5,17 @@* Copyright (C) 2009-2010 Gabor Juhos <[email protected]> */ -#ifndef _REALTEK_SMI_H -#define _REALTEK_SMI_H +#ifndef _REALTEK_H +#define _REALTEK_H#include <linux/phy.h> #include <linux/platform_device.h> #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 ;@@ -142,4 +145,4 @@ void rtl8366_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);extern const struct realtek_variant rtl8366rb_variant;extern const struct realtek_variant rtl8365mb_variant; -#endif /* _REALTEK_SMI_H */ +#endif /* _REALTEK_H */
Quoted 7 lines · Alvin Šipraga
Quoted 1 line · Luiz Angelo Daros de Luca
+ if (
priv->reset) {
gpiod_set_valueseems tolerant of a NULLgpio_descpointer, but perhaps you would like to add the same if statement to realtek-smi so that it doesn't pretend to reset the chip when the reset GPIO is absent?
That is fine by me and you can keep my review tag if you also add this.
Yours,
Linus Walleij
Luiz Angelo Daros de Luca
maintainerQuoted 8 lines
drivers/net/dsa/realtek/realtek-mdio.c static void realtek_mdio_remove(struct mdio_device *mdiodev) · line 205
Quoted 6 lines
drivers/net/dsa/realtek/realtek-mdio.c +4
-0+/* leave the device reset asserted */ +if (priv->reset) +gpiod_set_value (priv->reset,1 ); +dsa_unregister_switch (priv->ds);Wouldn't you prefer to reset the chip after
dsa_unregister_switch()?
Thanks Alvin, you are right. Maybe a thread might ask something after reset/before unregisters.
Quoted 5 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]>
Looks good to me!
Yours,
Linus Walleij
Andrew Lunn
maintainerQuoted 6 lines
drivers/net/dsa/realtek/realtek.h +0
-0@@ -5,14 +5,17 @@* Copyright (C) 2009-2010 Gabor Juhos <[email protected]>
drivers/net/dsa/realtek/realtek.h line 12
Quoted 10 lines
drivers/net/dsa/realtek/realtek.h +3
-3*/ -#ifndef _REALTEK_SMI_H -#define _REALTEK_SMI_H +#ifndef _REALTEK_H +#define _REALTEK_H -#endif /* _REALTEK_SMI_H */ +#endif /* _REALTEK_H */
These two hunks should probably be in a separate patch. At minimum, please mention it is in the commit message.
Andrew
Quoted 6 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]>---
[snip]
Quoted 28 lines
drivers/net/dsa/realtek/realtek-mdio.c +4
-0ret = priv->ops->detect (priv);if (ret) {dev_err (dev,"unable to detect switch\n" );@@ -183,6 +198,10 @@ static void realtek_mdio_remove(struct mdio_device *mdiodev)if (!priv)return ; +/* leave the device reset asserted */ +if (priv->reset) +gpiod_set_value (priv->reset,1 ); +dsa_unregister_switch (priv->ds);dev_set_drvdata (&mdiodev->dev,NULL );drivers/net/dsa/realtek/realtek-smi.c +0
-2@@ -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) {
drivers/net/dsa/realtek/realtek-smi.c static int realtek_smi_probe(struct platform_device *pdev) · line 430
Quoted 9 lines
drivers/net/dsa/realtek/realtek-smi.c +2
-2@@ -426,9 +424,9 @@ static int realtek_smi_probe(struct platform_device *pdev)dev_err (dev,"failed to get RESET GPIO\n" );return PTR_ERR (priv->reset); } -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_info (dev,"deasserted RESET\n" );
Maybe demote these to debug prints since they would show up every time you load/unload the driver.
Signature · 1 line
Florian