[PATCH v2 net 2/2] net: stmmac: dwmac-imx: pause the TXC clock in fixed-link
Shenwei Wang
shenwei.wang at nxp.com
Thu Jul 27 08:25:03 PDT 2023
When using a fixed-link setup, certain devices like the SJA1105 require a
small pause in the TXC clock line to enable their internal tunable
delay line (TDL).
To satisfy this requirement, this patch temporarily disables the TX clock,
and restarts it after a required period. This provides the required
silent interval on the clock line for SJA1105 to complete the frequency
transition and enable the internal TDLs.
So far we have only enabled this feature on the i.MX93 platform.
Signed-off-by: Shenwei Wang <shenwei.wang at nxp.com>
Reviewed-by: Frank Li <frank.li at nxp.com>
---
.../net/ethernet/stmicro/stmmac/dwmac-imx.c | 45 +++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c
index 53ee5a42c071..e7819960128e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c
@@ -40,6 +40,9 @@
#define DMA_BUS_MODE 0x00001000
#define DMA_BUS_MODE_SFT_RESET (0x1 << 0)
#define RMII_RESET_SPEED (0x3 << 14)
+#define MII_RESET_SPEED (0x2 << 14)
+#define RGMII_RESET_SPEED (0x0 << 14)
+#define CTRL_SPEED_MASK (0x3 << 14)
struct imx_dwmac_ops {
u32 addr_width;
@@ -56,6 +59,7 @@ struct imx_priv_data {
struct regmap *intf_regmap;
u32 intf_reg_off;
bool rmii_refclk_ext;
+ void __iomem *base_addr;
const struct imx_dwmac_ops *ops;
struct plat_stmmacenet_data *plat_dat;
@@ -212,6 +216,44 @@ static void imx_dwmac_fix_speed(void *priv, uint speed, uint mode)
dev_err(dwmac->dev, "failed to set tx rate %lu\n", rate);
}
+static void imx_dwmac_fix_speed_mx93(void *priv, uint speed, uint mode)
+{
+ struct imx_priv_data *dwmac = priv;
+ int ctrl, old_ctrl, iface;
+
+ imx_dwmac_fix_speed(priv, speed, mode);
+
+ if (!dwmac || mode != MLO_AN_FIXED)
+ return;
+
+ if (regmap_read(dwmac->intf_regmap, dwmac->intf_reg_off, &iface))
+ return;
+
+ iface &= MX93_GPR_ENET_QOS_INTF_MODE_MASK;
+ old_ctrl = readl(dwmac->base_addr + MAC_CTRL_REG);
+ ctrl = old_ctrl & ~CTRL_SPEED_MASK;
+
+ /* by default ctrl will be RGMII */
+ if (iface == MX93_GPR_ENET_QOS_INTF_SEL_RMII)
+ ctrl |= RMII_RESET_SPEED;
+ if (iface == MX93_GPR_ENET_QOS_INTF_SEL_MII)
+ ctrl |= MII_RESET_SPEED;
+
+ writel(ctrl, dwmac->base_addr + MAC_CTRL_REG);
+
+ /* Ensure the settings for CTRL are applied */
+ wmb();
+
+ regmap_update_bits(dwmac->intf_regmap, dwmac->intf_reg_off,
+ MX93_GPR_ENET_QOS_INTF_MODE_MASK, 0);
+ usleep_range(50, 100);
+ iface |= MX93_GPR_ENET_QOS_CLK_GEN_EN;
+ regmap_update_bits(dwmac->intf_regmap, dwmac->intf_reg_off,
+ MX93_GPR_ENET_QOS_INTF_MODE_MASK, iface);
+
+ writel(old_ctrl, dwmac->base_addr + MAC_CTRL_REG);
+}
+
static int imx_dwmac_mx93_reset(void *priv, void __iomem *ioaddr)
{
struct plat_stmmacenet_data *plat_dat = priv;
@@ -317,8 +359,11 @@ static int imx_dwmac_probe(struct platform_device *pdev)
plat_dat->exit = imx_dwmac_exit;
plat_dat->clks_config = imx_dwmac_clks_config;
plat_dat->fix_mac_speed = imx_dwmac_fix_speed;
+ if (of_machine_is_compatible("fsl,imx93"))
+ plat_dat->fix_mac_speed = imx_dwmac_fix_speed_mx93;
plat_dat->bsp_priv = dwmac;
dwmac->plat_dat = plat_dat;
+ dwmac->base_addr = stmmac_res.addr;
ret = imx_dwmac_clks_config(dwmac, true);
if (ret)
--
2.34.1
More information about the linux-arm-kernel
mailing list