From: Lad Prabhakar Extend the Renesas GBETH stmmac glue driver to support the RZ/T2H SoC, where the GMAC is connected through a MIIC PCS. Introduce a new `has_pcs` flag in `struct renesas_gbeth_of_data` to indicate when PCS handling is required. When enabled, the driver parses the `pcs-handle` phandle, creates a PCS instance with `miic_create()`, and wires it into phylink. Proper cleanup is done with `miic_destroy()`. New init/exit/select hooks are added to `plat_stmmacenet_data` for PCS integration. Update Kconfig to select `PCS_RZN1_MIIC` when building the Renesas GBETH driver so the PCS support is always available. Signed-off-by: Lad Prabhakar --- v1->v2: - Switched using "renesas,r9a09g077-gbeth" compatible string for RZ/T2H instead of "renesas,rzt2h-gbeth". --- drivers/net/ethernet/stmicro/stmmac/Kconfig | 1 + .../stmicro/stmmac/dwmac-renesas-gbeth.c | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig index 67fa879b1e52..a01c83b109f9 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig @@ -136,6 +136,7 @@ config DWMAC_RENESAS_GBETH tristate "Renesas RZ/V2H(P) GBETH support" default ARCH_RENESAS depends on OF && (ARCH_RENESAS || COMPILE_TEST) + select PCS_RZN1_MIIC help Support for Gigabit Ethernet Interface (GBETH) on Renesas RZ/V2H(P) SoCs. diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c index 022e595a9e1b..129543c37a5e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +34,7 @@ * handled by the glue driver or core driver. * @set_clk_tx_rate: Flag to indicate if Tx clock is fixed or * set_clk_tx_rate is needed. + * @has_pcs: Flag to indicate if the MAC has a PCS */ struct renesas_gbeth_of_data { const char * const *clks; @@ -40,6 +42,7 @@ struct renesas_gbeth_of_data { u32 stmmac_flags; bool handle_reset; bool set_clk_tx_rate; + bool has_pcs; }; struct renesas_gbeth { @@ -53,6 +56,41 @@ static const char *const renesas_gbeth_clks[] = { "tx", "tx-180", "rx", "rx-180", }; +static const char *const renesas_gmac_clks[] = { + "tx", +}; + +static int renesas_gmac_pcs_init(struct stmmac_priv *priv) +{ + struct device_node *np = priv->device->of_node; + struct device_node *pcs_node; + struct phylink_pcs *pcs; + + pcs_node = of_parse_phandle(np, "pcs-handle", 0); + if (pcs_node) { + pcs = miic_create(priv->device, pcs_node); + of_node_put(pcs_node); + if (IS_ERR(pcs)) + return PTR_ERR(pcs); + + priv->hw->phylink_pcs = pcs; + } + + return 0; +} + +static void renesas_gmac_pcs_exit(struct stmmac_priv *priv) +{ + if (priv->hw->phylink_pcs) + miic_destroy(priv->hw->phylink_pcs); +} + +static struct phylink_pcs *renesas_gmac_select_pcs(struct stmmac_priv *priv, + phy_interface_t interface) +{ + return priv->hw->phylink_pcs; +} + static int renesas_gbeth_init(struct platform_device *pdev, void *priv) { struct plat_stmmacenet_data *plat_dat; @@ -149,6 +187,11 @@ static int renesas_gbeth_probe(struct platform_device *pdev) plat_dat->init = renesas_gbeth_init; plat_dat->exit = renesas_gbeth_exit; plat_dat->flags |= gbeth->of_data->stmmac_flags; + if (of_data->has_pcs) { + plat_dat->pcs_init = renesas_gmac_pcs_init; + plat_dat->pcs_exit = renesas_gmac_pcs_exit; + plat_dat->select_pcs = renesas_gmac_select_pcs; + } return devm_stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res); } @@ -163,7 +206,16 @@ static const struct renesas_gbeth_of_data renesas_gbeth_of_data = { STMMAC_FLAG_SPH_DISABLE, }; +static const struct renesas_gbeth_of_data renesas_gmac_of_data = { + .clks = renesas_gmac_clks, + .num_clks = ARRAY_SIZE(renesas_gmac_clks), + .stmmac_flags = STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY | + STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP, + .has_pcs = true, +}; + static const struct of_device_id renesas_gbeth_match[] = { + { .compatible = "renesas,r9a09g077-gbeth", .data = &renesas_gmac_of_data }, { .compatible = "renesas,rzv2h-gbeth", .data = &renesas_gbeth_of_data }, { /* Sentinel */ } }; -- 2.51.0