The Allwinner A733 GMAC210 controller differs from A523 GMAC200 and requires SoC-specific glue handling: - Glue registers reside inside the AHB reset domain, and stmmac calls plat_dat->init() before deasserting stmmac_ahb_rst, so dwmac-sun55i deasserts stmmac_ahb_rst prior to devm_stmmac_pltfr_probe() (with a devm action to re-assert on error or unbind). - An active-low clock gate at glue offset 0x80 (BIT(0)) must be cleared in init() and set in exit(). - Hardware splits the 5-bit RGMII TX delay across [17:16] and [12:10] in 180 ps steps, and uses external GMII TX clocking (SYSCON_ETCS_EXT_GMII) for RGMII rather than internal GMII. - Enable STMMAC_FLAG_SPH_DISABLE, STMMAC_FLAG_MULTI_MSI_EN for the per-queue TX/RX interrupts, and STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP. Add sun60i_a733_gmac210_data and its glue handling to dwmac-sun55i. Assisted-by: LLM Signed-off-by: Alastair D'Silva --- .../ethernet/stmicro/stmmac/dwmac-sun55i.c | 98 ++++++++++++++++++- 1 file changed, 93 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c index e872e241a220..c7117802abb8 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun55i.c @@ -19,11 +19,15 @@ #include #include #include +#include #include #include "stmmac.h" #include "stmmac_platform.h" +#define SYSCON_GMAC210_CLK_GATE 0x80 +#define SYSCON_GMAC210_CLK_GATE_DIS BIT(0) + /* RMII specific bits */ #define SYSCON_RMII_EN BIT(13) /* 1: enable RMII (overrides EPIT) */ /* Generic system control EMAC_CLK bits */ @@ -42,9 +46,12 @@ struct sun55i_gmac_data { int (*init_resources)(struct platform_device *pdev, struct sun55i_gmac *gmac); unsigned int flags; + u32 etxdc_ext_mask; u32 txdly_step_ps; u32 rxdly_step_ps; u32 offset; + u32 etcs_rgmii; + bool has_clk_gate; }; struct sun55i_gmac { @@ -65,6 +72,31 @@ static int sun55i_gmac200_init_resources(struct platform_device *pdev, return 0; } +static const struct regmap_config sun60i_a733_regmap_cfg = { + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, +}; + +static int sun60i_gmac210_init_resources(struct platform_device *pdev, + struct sun55i_gmac *gmac) +{ + struct device *dev = &pdev->dev; + void __iomem *base; + + base = devm_platform_ioremap_resource(pdev, 1); + if (IS_ERR(base)) + return dev_err_probe(dev, PTR_ERR(base), + "Unable to get glue memory region\n"); + + gmac->regmap = devm_regmap_init_mmio(dev, base, &sun60i_a733_regmap_cfg); + if (IS_ERR(gmac->regmap)) + return dev_err_probe(dev, PTR_ERR(gmac->regmap), + "Unable to init regmap for glue region\n"); + + return 0; +} + static int sun55i_gmac200_validate_delay(struct device *dev, const char *dir, u32 *val, u32 step, u32 max) { @@ -93,13 +125,18 @@ static int sun55i_gmac200_parse_config(struct device *dev, int ret; if (!of_property_read_u32(node, "tx-internal-delay-ps", &val)) { + u32 low_bits = hweight32(SYSCON_ETXDC_MASK); + u32 max = (1U << (low_bits + hweight32(data->etxdc_ext_mask))) - 1; + ret = sun55i_gmac200_validate_delay(dev, "tx", &val, - data->txdly_step_ps, - FIELD_MAX(SYSCON_ETXDC_MASK)); + data->txdly_step_ps, max); if (ret) return ret; - reg |= FIELD_PREP(SYSCON_ETXDC_MASK, val); + reg |= FIELD_PREP(SYSCON_ETXDC_MASK, + val & FIELD_MAX(SYSCON_ETXDC_MASK)); + if (data->etxdc_ext_mask) + reg |= field_prep(data->etxdc_ext_mask, val >> low_bits); } if (!of_property_read_u32(node, "rx-internal-delay-ps", &val)) { @@ -117,10 +154,10 @@ static int sun55i_gmac200_parse_config(struct device *dev, /* default */ break; case PHY_INTERFACE_MODE_RGMII: + case PHY_INTERFACE_MODE_RGMII_TXID: case PHY_INTERFACE_MODE_RGMII_ID: case PHY_INTERFACE_MODE_RGMII_RXID: - case PHY_INTERFACE_MODE_RGMII_TXID: - reg |= SYSCON_EPIT | SYSCON_ETCS_INT_GMII; + reg |= SYSCON_EPIT | data->etcs_rgmii; break; case PHY_INTERFACE_MODE_RMII: reg |= SYSCON_RMII_EN; @@ -145,9 +182,31 @@ static int sun55i_gmac200_init(struct device *dev, void *priv) return dev_err_probe(dev, ret, "Failed to write glue configuration\n"); + if (gmac->data->has_clk_gate) { + ret = regmap_clear_bits(gmac->regmap, SYSCON_GMAC210_CLK_GATE, + SYSCON_GMAC210_CLK_GATE_DIS); + if (ret < 0) + return dev_err_probe(dev, ret, + "Failed to enable GMAC clock gate\n"); + } + return 0; } +static void sun55i_gmac200_exit(struct device *dev, void *priv) +{ + struct sun55i_gmac *gmac = priv; + + if (gmac->data->has_clk_gate) + regmap_set_bits(gmac->regmap, SYSCON_GMAC210_CLK_GATE, + SYSCON_GMAC210_CLK_GATE_DIS); +} + +static void sun55i_gmac_reset_assert(void *data) +{ + reset_control_assert(data); +} + static int sun55i_gmac200_probe(struct platform_device *pdev) { struct plat_stmmacenet_data *plat_dat; @@ -184,8 +243,21 @@ static int sun55i_gmac200_probe(struct platform_device *pdev) if (ret) return ret; + if (gmac->data->has_clk_gate && plat_dat->stmmac_ahb_rst) { + ret = reset_control_deassert(plat_dat->stmmac_ahb_rst); + if (ret) + return dev_err_probe(dev, ret, + "Failed to deassert ahb reset\n"); + + ret = devm_add_action_or_reset(dev, sun55i_gmac_reset_assert, + plat_dat->stmmac_ahb_rst); + if (ret) + return ret; + } + plat_dat->bsp_priv = gmac; plat_dat->init = sun55i_gmac200_init; + plat_dat->exit = sun55i_gmac200_exit; clk = devm_clk_get_enabled(dev, "mbus"); if (IS_ERR(clk)) @@ -205,11 +277,27 @@ static const struct sun55i_gmac_data sun55i_a523_gmac200_data = { .offset = 0x34, .txdly_step_ps = 100, .rxdly_step_ps = 100, + .etcs_rgmii = SYSCON_ETCS_INT_GMII, +}; + +static const struct sun55i_gmac_data sun60i_a733_gmac210_data = { + .init_resources = sun60i_gmac210_init_resources, + .flags = STMMAC_FLAG_SPH_DISABLE | + STMMAC_FLAG_MULTI_MSI_EN | + STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP, + .offset = 0x0, + .etxdc_ext_mask = GENMASK(17, 16), + .txdly_step_ps = 180, + .rxdly_step_ps = 180, + .etcs_rgmii = SYSCON_ETCS_EXT_GMII, + .has_clk_gate = true, }; static const struct of_device_id sun55i_gmac200_match[] = { { .compatible = "allwinner,sun55i-a523-gmac200", .data = &sun55i_a523_gmac200_data }, + { .compatible = "allwinner,sun60i-a733-gmac210", + .data = &sun60i_a733_gmac210_data }, { } }; MODULE_DEVICE_TABLE(of, sun55i_gmac200_match); -- 2.53.0