Skip to content

Commit

Permalink
net: dsa: realtek: realtek-mdio: reset before setup
Browse files Browse the repository at this point in the history
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 <frank-w@public-files.de>
Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
Tested-by: Frank Wunderlich <frank-w@public-files.de>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Alvin Šipraga <alsi@bang-olufsen.dk>
Acked-by: Arınç ÜNAL <arinc.unal@arinc9.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Luiz Angelo Daros de Luca authored and David S. Miller committed Feb 14, 2022
1 parent 9a236b5 commit 05f7b04
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
19 changes: 19 additions & 0 deletions drivers/net/dsa/realtek/realtek-mdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 2 additions & 4 deletions drivers/net/dsa/realtek/realtek-smi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");
}

Expand Down
3 changes: 3 additions & 0 deletions drivers/net/dsa/realtek/realtek.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 05f7b04

Please sign in to comment.