Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: stmmac: add platform init/exit for Altera's ARM socfpga

This patch adds platform init/exit functions and modifications to support
suspend/resume for the Altera Cyclone 5 SOC Ethernet controller. The platform
exit function puts the controller into reset using the socfpga reset
controller driver. The platform init function sets up the Synopsys mac by
first making sure the Ethernet controller is held in reset, programming the
phy mode through external support logic, then deasserts reset through
the socfpga reset manager driver.

Signed-off-by: Vince Bridgers <vbridgers2013@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Vince Bridgers and committed by
David S. Miller
2d871aa0 7aa06bf5

+73
+69
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
··· 20 20 #include <linux/of_net.h> 21 21 #include <linux/phy.h> 22 22 #include <linux/regmap.h> 23 + #include <linux/reset.h> 23 24 #include <linux/stmmac.h> 25 + #include "stmmac.h" 24 26 25 27 #define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII 0x0 26 28 #define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII 0x1 ··· 36 34 u32 reg_shift; 37 35 struct device *dev; 38 36 struct regmap *sys_mgr_base_addr; 37 + struct reset_control *stmmac_rst; 39 38 }; 40 39 41 40 static int socfpga_dwmac_parse_data(struct socfpga_dwmac *dwmac, struct device *dev) ··· 45 42 struct regmap *sys_mgr_base_addr; 46 43 u32 reg_offset, reg_shift; 47 44 int ret; 45 + 46 + dwmac->stmmac_rst = devm_reset_control_get(dev, 47 + STMMAC_RESOURCE_NAME); 48 + if (IS_ERR(dwmac->stmmac_rst)) { 49 + dev_info(dev, "Could not get reset control!\n"); 50 + return -EINVAL; 51 + } 48 52 49 53 dwmac->interface = of_get_phy_mode(np); 50 54 ··· 135 125 return dwmac; 136 126 } 137 127 128 + static void socfpga_dwmac_exit(struct platform_device *pdev, void *priv) 129 + { 130 + struct socfpga_dwmac *dwmac = priv; 131 + 132 + /* On socfpga platform exit, assert and hold reset to the 133 + * enet controller - the default state after a hard reset. 134 + */ 135 + if (dwmac->stmmac_rst) 136 + reset_control_assert(dwmac->stmmac_rst); 137 + } 138 + 139 + static int socfpga_dwmac_init(struct platform_device *pdev, void *priv) 140 + { 141 + struct socfpga_dwmac *dwmac = priv; 142 + struct net_device *ndev = platform_get_drvdata(pdev); 143 + struct stmmac_priv *stpriv = NULL; 144 + int ret = 0; 145 + 146 + if (ndev) 147 + stpriv = netdev_priv(ndev); 148 + 149 + /* Assert reset to the enet controller before changing the phy mode */ 150 + if (dwmac->stmmac_rst) 151 + reset_control_assert(dwmac->stmmac_rst); 152 + 153 + /* Setup the phy mode in the system manager registers according to 154 + * devicetree configuration 155 + */ 156 + ret = socfpga_dwmac_setup(dwmac); 157 + 158 + /* Deassert reset for the phy configuration to be sampled by 159 + * the enet controller, and operation to start in requested mode 160 + */ 161 + if (dwmac->stmmac_rst) 162 + reset_control_deassert(dwmac->stmmac_rst); 163 + 164 + /* Before the enet controller is suspended, the phy is suspended. 165 + * This causes the phy clock to be gated. The enet controller is 166 + * resumed before the phy, so the clock is still gated "off" when 167 + * the enet controller is resumed. This code makes sure the phy 168 + * is "resumed" before reinitializing the enet controller since 169 + * the enet controller depends on an active phy clock to complete 170 + * a DMA reset. A DMA reset will "time out" if executed 171 + * with no phy clock input on the Synopsys enet controller. 172 + * Verified through Synopsys Case #8000711656. 173 + * 174 + * Note that the phy clock is also gated when the phy is isolated. 175 + * Phy "suspend" and "isolate" controls are located in phy basic 176 + * control register 0, and can be modified by the phy driver 177 + * framework. 178 + */ 179 + if (stpriv && stpriv->phydev) 180 + phy_resume(stpriv->phydev); 181 + 182 + return ret; 183 + } 184 + 138 185 const struct stmmac_of_data socfpga_gmac_data = { 139 186 .setup = socfpga_dwmac_probe, 187 + .init = socfpga_dwmac_init, 188 + .exit = socfpga_dwmac_exit, 140 189 };
+4
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
··· 2878 2878 clk_disable_unprepare(priv->stmmac_clk); 2879 2879 } 2880 2880 spin_unlock_irqrestore(&priv->lock, flags); 2881 + 2882 + priv->oldlink = 0; 2883 + priv->speed = 0; 2884 + priv->oldduplex = -1; 2881 2885 return 0; 2882 2886 } 2883 2887