From db2dd662880e9951352754636f71dcee4b50e122 Mon Sep 17 00:00:00 2001 From: Alexey Sheplyakov Date: Wed, 24 Feb 2021 16:45:30 +0400 Subject: [PATCH] dwmac_baikal: correctly reset PHY In BE-M1000 "nRST Ethernet PHY" is not connected to GPIO, instead it goes to GMAC. Thus `stmmac_mdio_reset` is useless. Therefore reset PHY manually in `baikal_dwmac_setup`, and tell the generic setup code that PHY has been already reset. Without this patch Ethernet will fail to initialize with the following error: [ 17.596114] Micrel KSZ9031 Gigabit PHY stmmac-2:03: phy_poll_reset failed: -110 [ 17.603602] baikal-dwmac 30250000.eth1 eth1: no phy at addr -1 [ 17.609468] baikal-dwmac 30250000.eth1 eth1: stmmac_open: Cannot attach to PHY (error: -19) Closes: #39714 (cherry picked from commit c51d8bdbda995a04e30a68e9e74ddd12772704ce) (cherry picked from commit 84a2f0d6f6556f923b0d7c58fe86ebc62c2b3766) --- drivers/net/ethernet/stmicro/stmmac/dwmac-baikal.c | 20 ++++++++++++++++---- 1 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-baikal.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-baikal.c index 646051c..5047b0fe 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-baikal.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-baikal.c @@ -34,6 +34,14 @@ struct baikal_dwmac { struct clk *tx2_clk; }; +static void clear_phy_reset(void __iomem *ioaddr) +{ + u32 value; + value = readl(ioaddr + MAC_GPIO); + value |= MAC_GPIO_GPO0; + writel(value, ioaddr + MAC_GPIO); +} + static int baikal_dwmac_dma_reset(void __iomem *ioaddr) { int err; @@ -44,10 +52,7 @@ static int baikal_dwmac_dma_reset(void __iomem *ioaddr) writel(value, ioaddr + DMA_BUS_MODE); udelay(10); - /* Clear PHY reset */ - value = readl(ioaddr + MAC_GPIO); - value |= MAC_GPIO_GPO0; - writel(value, ioaddr + MAC_GPIO); + clear_phy_reset(ioaddr); pr_info("PHY re-inited for Baikal DWMAC\n"); err = readl_poll_timeout(ioaddr + DMA_BUS_MODE, value, @@ -90,6 +95,8 @@ static struct mac_device_info* baikal_dwmac_setup(void *ppriv) if (!mac) return NULL; + clear_phy_reset(priv->ioaddr); + mac->dma = &baikal_dwmac_dma_ops; old_mac = priv->hw; priv->hw = mac; @@ -186,6 +193,11 @@ static int dwmac_baikal_probe(struct platform_device *pdev) // TODO: set CSR correct clock in dts! plat_dat->clk_csr = 3; plat_dat->setup = baikal_dwmac_setup; + /* nRST Ethernet PHY is *not* connected to GPIO. Instead it goes + * to GMAC. Therefore mdio bus should be reset only once, in + * baikal_dwmac_setup. + */ + plat_dat->mdio_bus_data->needs_reset = false; dev_info(&pdev->dev, "Baikal Electronics DWMAC glue driver\n"); -- 1.7.3.3