From: Joseph Telaak <redacted>
The switch keeps the configuration the bootloader left in it, and the
driver never resets it. The MDIO core asserts and releases reset-gpios
only for PHY devices, so a reset line described on the switch node has
no effect either.
On the GL.iNet GL-SFT1200, nothing answers at internal MDIO address 0
after the bootloader, and the PHY that answers at each port's address
belongs to the neighboring port, so port 0 fails with "failed to
connect to PHY: -ENODEV". Describing the PHYs at the addresses they
answer at is not enough: with them at 1 to 3 and no reset, neither LAN
port passes traffic. After a hardware reset every PHY is back at its
port's address and all ports work. GL.iNet's own firmware resets the
switch from Linux too.
Get the reset through the reset controller API and pulse it before the
first register access. The reset core hands a reset-gpios property to
the reset-gpio driver, so a board that wires the reset this way needs
CONFIG_RESET_GPIO; without it the reset is skipped. Imply it, so it is
enabled by default, and say so in the help text. The timing follows the
vendor's driver for the GSW150: asserted for 250 ms, then 1 s before the
switch is accessed. No timing is known for the other GSW1xx parts, so
they get the same.
The reset also returns the RGMII slew rates to their power-on defaults,
so a board that uses reset-gpios sets the ones it needs in its device
tree.
Signed-off-by: Joseph Telaak <redacted>
---
drivers/net/dsa/lantiq/Kconfig | 5 +++++
drivers/net/dsa/lantiq/mxl-gsw1xx.c | 26 ++++++++++++++++++++++++++
drivers/net/dsa/lantiq/mxl-gsw1xx.h | 6 ++++++
3 files changed, 37 insertions(+)
diff --git a/drivers/net/dsa/lantiq/Kconfig b/drivers/net/dsa/lantiq/Kconfig
index 98efeef266..c0f2e36bf6 100644
--- a/drivers/net/dsa/lantiq/Kconfig
+++ b/drivers/net/dsa/lantiq/Kconfig
@@ -16,6 +16,7 @@ config NET_DSA_MXL_GSW1XX
select NET_DSA_TAG_MXL_GSW1XX
select NET_DSA_LANTIQ_COMMON
select PHY_COMMON_PROPS
+ imply RESET_GPIO
help
This enables support for the Intel/MaxLinear GSW1xx family of 1GE
switches.
@@ -25,3 +26,7 @@ config NET_DSA_MXL_GSW1XX
GSW141 6 port, 4 PHYs, RGMII & SGMII
GSW145 6 port, 4 PHYs, RGMII & SGMII/2500Base-X, industrial temperature
GSW150 7 port, 5 PHYs, 1x GMII/RGMII, 1x RGMII
+
+ A switch whose hardware reset is described with reset-gpios is
+ only reset when RESET_GPIO is enabled as well, which this option
+ does by default.
diff --git a/drivers/net/dsa/lantiq/mxl-gsw1xx.c b/drivers/net/dsa/lantiq/mxl-gsw1xx.c
index 0c7ea242a6..33b73b2ed5 100644
--- a/drivers/net/dsa/lantiq/mxl-gsw1xx.c
+++ b/drivers/net/dsa/lantiq/mxl-gsw1xx.c
@@ -18,6 +18,7 @@
#include <linux/phy/phy-common-props.h>
#include <linux/property.h>
#include <linux/regmap.h>
+#include <linux/reset.h>
#include <linux/workqueue.h>
#include <net/dsa.h>
@@ -719,6 +720,7 @@ static int gsw1xx_serdes_pcs_init(struct gsw1xx_priv *priv)
static int gsw1xx_probe(struct mdio_device *mdiodev)
{
struct device *dev = &mdiodev->dev;
+ struct reset_control *reset;
struct gsw1xx_priv *priv;
u32 version, val;
u8 shellver;@@ -737,6 +739,30 @@ static int gsw1xx_probe(struct mdio_device *mdiodev)
if (!priv->gswip.hw_info)
return -EINVAL;
+ /* The MDIO core handles reset-gpios only for PHYs. Reset the switch
+ * here, so it does not run with whatever the bootloader configured.
+ */
+ reset = devm_reset_control_get_optional_exclusive(dev, NULL);
+ if (IS_ERR(reset))
+ return dev_err_probe(dev, PTR_ERR(reset),
+ "failed to get reset control\n");
+
+ if (reset) {
+ ret = reset_control_assert(reset);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "failed to assert reset\n");
+
+ fsleep(GSW1XX_RESET_ASSERT_US);
+
+ ret = reset_control_deassert(reset);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "failed to deassert reset\n");
+
+ fsleep(GSW1XX_RESET_DEASSERT_US);
+ }
+
priv->gswip.gswip = gsw1xx_regmap_init(priv, "switch",
GSW1XX_SWITCH_BASE, 0xfff);
if (IS_ERR(priv->gswip.gswip))diff --git a/drivers/net/dsa/lantiq/mxl-gsw1xx.h b/drivers/net/dsa/lantiq/mxl-gsw1xx.h
index 81bc00eabb..7d91a7b7e2 100644
--- a/drivers/net/dsa/lantiq/mxl-gsw1xx.h
+++ b/drivers/net/dsa/lantiq/mxl-gsw1xx.h
@@ -19,6 +19,12 @@
#define GSW1XX_SYS_CLK_FREQ 340000000
+/* Hardware reset timing of the vendor's driver for the GSW150, which is the
+ * only one known and is used for all the GSW1xx parts
+ */
+#define GSW1XX_RESET_ASSERT_US 250000
+#define GSW1XX_RESET_DEASSERT_US 1000000
+
/* SMDIO switch register base address */
#define GSW1XX_SMDIO_BADR 0x1f
#define GSW1XX_SMDIO_BADR_UNKNOWN -1
--
Git-155)