From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Add the DWMAC glue layer for the GBETH IP found in the Renesas RZ/V2H(P)
SoC.
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
drivers/net/ethernet/stmicro/stmmac/Kconfig | 11 ++
drivers/net/ethernet/stmicro/stmmac/Makefile | 1 +
.../stmicro/stmmac/dwmac-renesas-gbeth.c | 148 ++++++++++++++++++
3 files changed, 160 insertions(+)
create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c
diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
index 3c820ef56775..2c99b23f0faa 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
+++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
@@ -131,6 +131,17 @@ config DWMAC_QCOM_ETHQOS
This selects the Qualcomm ETHQOS glue layer support for the
stmmac device driver.
+config DWMAC_RENESAS_GBETH
+ tristate "Renesas RZ/V2H(P) GBETH support"
+ default ARCH_RENESAS
+ depends on OF && (ARCH_RENESAS || COMPILE_TEST)
+ help
+ Support for Gigabit Ethernet Interface (GBETH) on Renesas
+ RZ/V2H(P) SoCs.
+
+ This selects the Renesas RZ/V2H(P) Soc specific glue layer support
+ for the stmmac device driver.
+
config DWMAC_ROCKCHIP
tristate "Rockchip dwmac support"
default ARCH_ROCKCHIP
diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile
index 594883fb4164..91050215511b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Makefile
+++ b/drivers/net/ethernet/stmicro/stmmac/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_DWMAC_LPC18XX) += dwmac-lpc18xx.o
obj-$(CONFIG_DWMAC_MEDIATEK) += dwmac-mediatek.o
obj-$(CONFIG_DWMAC_MESON) += dwmac-meson.o dwmac-meson8b.o
obj-$(CONFIG_DWMAC_QCOM_ETHQOS) += dwmac-qcom-ethqos.o
+obj-$(CONFIG_DWMAC_RENESAS_GBETH) += dwmac-renesas-gbeth.o
obj-$(CONFIG_DWMAC_ROCKCHIP) += dwmac-rk.o
obj-$(CONFIG_DWMAC_RZN1) += dwmac-rzn1.o
obj-$(CONFIG_DWMAC_S32) += dwmac-s32.o
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c
new file mode 100644
index 000000000000..8674b7605d83
--- /dev/null
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * dwmac-renesas-gbeth.c - DWMAC Specific Glue layer for Renesas GBETH
+ *
+ * The Rx and Tx clocks are supplied as follows for the GBETH IP.
+ *
+ * Rx / Tx
+ * -------+------------- on / off -------
+ * |
+ * | Rx-180 / Tx-180
+ * +---- not ---- on / off -------
+ *
+ * Copyright (C) 2025 Renesas Electronics Corporation
+ */
+
+#include <linux/clk.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/reset.h>
+
+#include "stmmac_platform.h"
+
+struct renesas_gbeth {
+ struct plat_stmmacenet_data *plat_dat;
+ struct reset_control *rstc;
+ struct device *dev;
+ void __iomem *regs;
+};
+
+static const char *const renesas_gbeth_clks[] = {
+ "tx", "tx-180", "rx", "rx-180",
+};
+
+static int renesas_gbeth_clks_config(struct renesas_gbeth *gbeth, bool enabled)
+{
+ struct plat_stmmacenet_data *plat_dat;
+ int ret;
+
+ plat_dat = gbeth->plat_dat;
+ if (enabled) {
+ ret = reset_control_deassert(gbeth->rstc);
+ if (ret) {
+ dev_err(gbeth->dev, "Reset deassert failed\n");
+ return ret;
+ }
+
+ ret = clk_bulk_prepare_enable(plat_dat->num_clks,
+ plat_dat->clks);
+ if (ret)
+ reset_control_assert(gbeth->rstc);
+ } else {
+ clk_bulk_disable_unprepare(plat_dat->num_clks, plat_dat->clks);
+ ret = reset_control_assert(gbeth->rstc);
+ if (ret)
+ dev_err(gbeth->dev, "Reset assert failed\n");
+ }
+
+ return ret;
+}
+
+static int renesas_gbeth_init(struct platform_device *pdev, void *priv)
+{
+ return renesas_gbeth_clks_config(priv, true);
+}
+
+static void renesas_gbeth_exit(struct platform_device *pdev, void *priv)
+{
+ renesas_gbeth_clks_config(priv, false);
+}
+
+static int renesas_gbeth_probe(struct platform_device *pdev)
+{
+ struct plat_stmmacenet_data *plat_dat;
+ struct stmmac_resources stmmac_res;
+ struct device *dev = &pdev->dev;
+ struct renesas_gbeth *gbeth;
+ unsigned int i;
+ int err;
+
+ err = stmmac_get_platform_resources(pdev, &stmmac_res);
+ if (err)
+ return dev_err_probe(dev, err,
+ "failed to get resources\n");
+
+ plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac);
+ if (IS_ERR(plat_dat))
+ return dev_err_probe(dev, PTR_ERR(plat_dat),
+ "dt configuration failed\n");
+
+ gbeth = devm_kzalloc(dev, sizeof(*gbeth), GFP_KERNEL);
+ if (!gbeth)
+ return -ENOMEM;
+
+ plat_dat->num_clks = ARRAY_SIZE(renesas_gbeth_clks);
+ plat_dat->clks = devm_kcalloc(dev, plat_dat->num_clks,
+ sizeof(*plat_dat->clks), GFP_KERNEL);
+ if (!plat_dat->clks)
+ return -ENOMEM;
+
+ for (i = 0; i < plat_dat->num_clks; i++)
+ plat_dat->clks[i].id = renesas_gbeth_clks[i];
+
+ err = devm_clk_bulk_get(dev, plat_dat->num_clks, plat_dat->clks);
+ if (err < 0)
+ return err;
+
+ plat_dat->clk_tx_i = stmmac_pltfr_find_clk(plat_dat, "tx");
+ if (!plat_dat->clk_tx_i)
+ return dev_err_probe(dev, -EINVAL,
+ "error finding tx clock\n");
+
+ gbeth->rstc = devm_reset_control_get_exclusive(dev, NULL);
+ if (IS_ERR(gbeth->rstc))
+ return PTR_ERR(gbeth->rstc);
+
+ gbeth->dev = dev;
+ gbeth->regs = stmmac_res.addr;
+ gbeth->plat_dat = plat_dat;
+ plat_dat->bsp_priv = gbeth;
+ plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate;
+ plat_dat->init = renesas_gbeth_init;
+ plat_dat->exit = renesas_gbeth_exit;
+ plat_dat->flags |= STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY |
+ STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP |
+ STMMAC_FLAG_SPH_DISABLE;
+
+ return devm_stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res);
+}
+
+static const struct of_device_id renesas_gbeth_match[] = {
+ { .compatible = "renesas,rzv2h-gbeth", },
+ { /* Sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, renesas_gbeth_match);
+
+static struct platform_driver renesas_gbeth_driver = {
+ .probe = renesas_gbeth_probe,
+ .driver = {
+ .name = "renesas-gbeth",
+ .of_match_table = renesas_gbeth_match,
+ },
+};
+module_platform_driver(renesas_gbeth_driver);
+
+MODULE_AUTHOR("Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>");
+MODULE_DESCRIPTION("Renesas GBETH DWMAC Specific Glue layer");
+MODULE_LICENSE("GPL");
--
2.49.0
On Tue, Apr 15, 2025 at 01:56:41PM +0100, Prabhakar wrote:
> Add the DWMAC glue layer for the GBETH IP found in the Renesas RZ/V2H(P)
> SoC.
I think we're almost there, but now that the trees have parted, we can
start seeing other bits of wood :)
> +struct renesas_gbeth {
> + struct plat_stmmacenet_data *plat_dat;
> + struct reset_control *rstc;
> + struct device *dev;
> + void __iomem *regs;
This appears to be only written, never read. Do you need it?
I think that's the last thing I can spot in this driver, so with that
fixed, please add:
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Thanks!
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Hi Russell,
On Tue, Apr 15, 2025 at 2:39 PM Russell King (Oracle)
<linux@armlinux.org.uk> wrote:
>
> On Tue, Apr 15, 2025 at 01:56:41PM +0100, Prabhakar wrote:
> > Add the DWMAC glue layer for the GBETH IP found in the Renesas RZ/V2H(P)
> > SoC.
>
> I think we're almost there, but now that the trees have parted, we can
> start seeing other bits of wood :)
>
:)
> > +struct renesas_gbeth {
> > + struct plat_stmmacenet_data *plat_dat;
> > + struct reset_control *rstc;
> > + struct device *dev;
> > + void __iomem *regs;
>
> This appears to be only written, never read. Do you need it?
>
No, I can get rid of it.
> I think that's the last thing I can spot in this driver, so with that
> fixed, please add:
>
Thanks, along with this I'll fold renesas_gbeth_clks_config() contents
into renesas_gbeth_init/exit() as suggested by Philipp.
> Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
>
Cheers,
Prabhakar
On Di, 2025-04-15 at 13:56 +0100, Prabhakar wrote:
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> Add the DWMAC glue layer for the GBETH IP found in the Renesas RZ/V2H(P)
> SoC.
>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> ---
> drivers/net/ethernet/stmicro/stmmac/Kconfig | 11 ++
> drivers/net/ethernet/stmicro/stmmac/Makefile | 1 +
> .../stmicro/stmmac/dwmac-renesas-gbeth.c | 148 ++++++++++++++++++
> 3 files changed, 160 insertions(+)
> create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> index 3c820ef56775..2c99b23f0faa 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
> +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> @@ -131,6 +131,17 @@ config DWMAC_QCOM_ETHQOS
> This selects the Qualcomm ETHQOS glue layer support for the
> stmmac device driver.
>
> +config DWMAC_RENESAS_GBETH
> + tristate "Renesas RZ/V2H(P) GBETH support"
> + default ARCH_RENESAS
> + depends on OF && (ARCH_RENESAS || COMPILE_TEST)
> + help
> + Support for Gigabit Ethernet Interface (GBETH) on Renesas
> + RZ/V2H(P) SoCs.
> +
> + This selects the Renesas RZ/V2H(P) Soc specific glue layer support
> + for the stmmac device driver.
> +
> config DWMAC_ROCKCHIP
> tristate "Rockchip dwmac support"
> default ARCH_ROCKCHIP
> diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile
> index 594883fb4164..91050215511b 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/Makefile
> +++ b/drivers/net/ethernet/stmicro/stmmac/Makefile
> @@ -20,6 +20,7 @@ obj-$(CONFIG_DWMAC_LPC18XX) += dwmac-lpc18xx.o
> obj-$(CONFIG_DWMAC_MEDIATEK) += dwmac-mediatek.o
> obj-$(CONFIG_DWMAC_MESON) += dwmac-meson.o dwmac-meson8b.o
> obj-$(CONFIG_DWMAC_QCOM_ETHQOS) += dwmac-qcom-ethqos.o
> +obj-$(CONFIG_DWMAC_RENESAS_GBETH) += dwmac-renesas-gbeth.o
> obj-$(CONFIG_DWMAC_ROCKCHIP) += dwmac-rk.o
> obj-$(CONFIG_DWMAC_RZN1) += dwmac-rzn1.o
> obj-$(CONFIG_DWMAC_S32) += dwmac-s32.o
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c
> new file mode 100644
> index 000000000000..8674b7605d83
> --- /dev/null
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c
> @@ -0,0 +1,148 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * dwmac-renesas-gbeth.c - DWMAC Specific Glue layer for Renesas GBETH
> + *
> + * The Rx and Tx clocks are supplied as follows for the GBETH IP.
> + *
> + * Rx / Tx
> + * -------+------------- on / off -------
> + * |
> + * | Rx-180 / Tx-180
> + * +---- not ---- on / off -------
> + *
> + * Copyright (C) 2025 Renesas Electronics Corporation
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/device.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/reset.h>
> +
> +#include "stmmac_platform.h"
> +
> +struct renesas_gbeth {
> + struct plat_stmmacenet_data *plat_dat;
> + struct reset_control *rstc;
> + struct device *dev;
> + void __iomem *regs;
This doesn't seem to be used anywhere.
> +};
> +
> +static const char *const renesas_gbeth_clks[] = {
> + "tx", "tx-180", "rx", "rx-180",
> +};
> +
> +static int renesas_gbeth_clks_config(struct renesas_gbeth *gbeth, bool enabled)
> +{
> + struct plat_stmmacenet_data *plat_dat;
> + int ret;
> +
> + plat_dat = gbeth->plat_dat;
> + if (enabled) {
> + ret = reset_control_deassert(gbeth->rstc);
> + if (ret) {
> + dev_err(gbeth->dev, "Reset deassert failed\n");
> + return ret;
> + }
> +
> + ret = clk_bulk_prepare_enable(plat_dat->num_clks,
> + plat_dat->clks);
> + if (ret)
> + reset_control_assert(gbeth->rstc);
> + } else {
> + clk_bulk_disable_unprepare(plat_dat->num_clks, plat_dat->clks);
> + ret = reset_control_assert(gbeth->rstc);
> + if (ret)
> + dev_err(gbeth->dev, "Reset assert failed\n");
> + }
> +
> + return ret;
> +}
Apart from the plat_dat assignment, this function has two completely
separate paths. I'd fold its contents into renesas_gbeth_init/exit().
regards
Philipp
Hi Philipp,
Thank you for the review.
On Tue, Apr 15, 2025 at 2:38 PM Philipp Zabel <p.zabel@pengutronix.de> wrote:
>
> On Di, 2025-04-15 at 13:56 +0100, Prabhakar wrote:
> > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> >
> > Add the DWMAC glue layer for the GBETH IP found in the Renesas RZ/V2H(P)
> > SoC.
> >
> > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> > ---
> > drivers/net/ethernet/stmicro/stmmac/Kconfig | 11 ++
> > drivers/net/ethernet/stmicro/stmmac/Makefile | 1 +
> > .../stmicro/stmmac/dwmac-renesas-gbeth.c | 148 ++++++++++++++++++
> > 3 files changed, 160 insertions(+)
> > create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c
> >
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> > index 3c820ef56775..2c99b23f0faa 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
> > +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> > @@ -131,6 +131,17 @@ config DWMAC_QCOM_ETHQOS
> > This selects the Qualcomm ETHQOS glue layer support for the
> > stmmac device driver.
> >
> > +config DWMAC_RENESAS_GBETH
> > + tristate "Renesas RZ/V2H(P) GBETH support"
> > + default ARCH_RENESAS
> > + depends on OF && (ARCH_RENESAS || COMPILE_TEST)
> > + help
> > + Support for Gigabit Ethernet Interface (GBETH) on Renesas
> > + RZ/V2H(P) SoCs.
> > +
> > + This selects the Renesas RZ/V2H(P) Soc specific glue layer support
> > + for the stmmac device driver.
> > +
> > config DWMAC_ROCKCHIP
> > tristate "Rockchip dwmac support"
> > default ARCH_ROCKCHIP
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile
> > index 594883fb4164..91050215511b 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/Makefile
> > +++ b/drivers/net/ethernet/stmicro/stmmac/Makefile
> > @@ -20,6 +20,7 @@ obj-$(CONFIG_DWMAC_LPC18XX) += dwmac-lpc18xx.o
> > obj-$(CONFIG_DWMAC_MEDIATEK) += dwmac-mediatek.o
> > obj-$(CONFIG_DWMAC_MESON) += dwmac-meson.o dwmac-meson8b.o
> > obj-$(CONFIG_DWMAC_QCOM_ETHQOS) += dwmac-qcom-ethqos.o
> > +obj-$(CONFIG_DWMAC_RENESAS_GBETH) += dwmac-renesas-gbeth.o
> > obj-$(CONFIG_DWMAC_ROCKCHIP) += dwmac-rk.o
> > obj-$(CONFIG_DWMAC_RZN1) += dwmac-rzn1.o
> > obj-$(CONFIG_DWMAC_S32) += dwmac-s32.o
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c
> > new file mode 100644
> > index 000000000000..8674b7605d83
> > --- /dev/null
> > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c
> > @@ -0,0 +1,148 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * dwmac-renesas-gbeth.c - DWMAC Specific Glue layer for Renesas GBETH
> > + *
> > + * The Rx and Tx clocks are supplied as follows for the GBETH IP.
> > + *
> > + * Rx / Tx
> > + * -------+------------- on / off -------
> > + * |
> > + * | Rx-180 / Tx-180
> > + * +---- not ---- on / off -------
> > + *
> > + * Copyright (C) 2025 Renesas Electronics Corporation
> > + */
> > +
> > +#include <linux/clk.h>
> > +#include <linux/device.h>
> > +#include <linux/module.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/reset.h>
> > +
> > +#include "stmmac_platform.h"
> > +
> > +struct renesas_gbeth {
> > + struct plat_stmmacenet_data *plat_dat;
> > + struct reset_control *rstc;
> > + struct device *dev;
> > + void __iomem *regs;
>
> This doesn't seem to be used anywhere.
>
I'll get rid of it.
> > +};
> > +
> > +static const char *const renesas_gbeth_clks[] = {
> > + "tx", "tx-180", "rx", "rx-180",
> > +};
> > +
> > +static int renesas_gbeth_clks_config(struct renesas_gbeth *gbeth, bool enabled)
> > +{
> > + struct plat_stmmacenet_data *plat_dat;
> > + int ret;
> > +
> > + plat_dat = gbeth->plat_dat;
> > + if (enabled) {
> > + ret = reset_control_deassert(gbeth->rstc);
> > + if (ret) {
> > + dev_err(gbeth->dev, "Reset deassert failed\n");
> > + return ret;
> > + }
> > +
> > + ret = clk_bulk_prepare_enable(plat_dat->num_clks,
> > + plat_dat->clks);
> > + if (ret)
> > + reset_control_assert(gbeth->rstc);
> > + } else {
> > + clk_bulk_disable_unprepare(plat_dat->num_clks, plat_dat->clks);
> > + ret = reset_control_assert(gbeth->rstc);
> > + if (ret)
> > + dev_err(gbeth->dev, "Reset assert failed\n");
> > + }
> > +
> > + return ret;
> > +}
>
> Apart from the plat_dat assignment, this function has two completely
> separate paths. I'd fold its contents into renesas_gbeth_init/exit().
>
OK, I'll fix that in v7.
Cheers,
Prabhakar
© 2016 - 2025 Red Hat, Inc.