Message ID | 20250407120317.127056-4-prabhakar.mahadev-lad.rj@bp.renesas.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Geert Uytterhoeven |
Headers | show |
Series | Add GBETH glue layer driver for Renesas RZ/V2H(P) SoC | expand |
On Mon, Apr 07, 2025 at 01:03:17PM +0100, Prabhakar wrote: > +static struct clk *renesas_gbeth_find_clk(struct plat_stmmacenet_data *plat_dat, > + const char *name) > +{ > + for (unsigned int i = 0; i < plat_dat->num_clks; i++) > + if (!strcmp(plat_dat->clks[i].id, name)) > + return plat_dat->clks[i].clk; > + > + return NULL; > +} In addition to Jakub's request, I'll ask that you hold off for a week because I have the following that I'd like to submit: bbc73b8b6dfd net: stmmac: provide stmmac_pltfr_find_clk() diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index c73eff6a56b8..43c869f64c39 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -709,6 +709,17 @@ devm_stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac) #endif /* CONFIG_OF */ EXPORT_SYMBOL_GPL(devm_stmmac_probe_config_dt); +struct clk *stmmac_pltfr_find_clk(struct plat_stmmacenet_data *plat_dat, + const char *name) +{ + for (int i = 0; i < plat_dat->num_clks; i++) + if (strcmp(plat_dat->clks[i].id, name) == 0) + return plat_dat->clks[i].clk; + + return NULL; +} +EXPORT_SYMBOL_GPL(stmmac_pltfr_find_clk); + ... which will avoid glue drivers duplicating this functionality. This will be part of the first sets of patches I'm going to be submitting. Thanks.
On Mon, Apr 7, 2025 at 6:58 PM Russell King (Oracle) <linux@armlinux.org.uk> wrote: > > On Mon, Apr 07, 2025 at 01:03:17PM +0100, Prabhakar wrote: > > +static struct clk *renesas_gbeth_find_clk(struct plat_stmmacenet_data *plat_dat, > > + const char *name) > > +{ > > + for (unsigned int i = 0; i < plat_dat->num_clks; i++) > > + if (!strcmp(plat_dat->clks[i].id, name)) > > + return plat_dat->clks[i].clk; > > + > > + return NULL; > > +} > > In addition to Jakub's request, I'll ask that you hold off for a week > because I have the following that I'd like to submit: > Ack, please add me in Cc while you post this patch. Cheers, Prabhakar > bbc73b8b6dfd net: stmmac: provide stmmac_pltfr_find_clk() > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c > index c73eff6a56b8..43c869f64c39 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c > @@ -709,6 +709,17 @@ devm_stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac) > #endif /* CONFIG_OF */ > EXPORT_SYMBOL_GPL(devm_stmmac_probe_config_dt); > > +struct clk *stmmac_pltfr_find_clk(struct plat_stmmacenet_data *plat_dat, > + const char *name) > +{ > + for (int i = 0; i < plat_dat->num_clks; i++) > + if (strcmp(plat_dat->clks[i].id, name) == 0) > + return plat_dat->clks[i].clk; > + > + return NULL; > +} > +EXPORT_SYMBOL_GPL(stmmac_pltfr_find_clk); > + > ... > > which will avoid glue drivers duplicating this functionality. This will > be part of the first sets of patches I'm going to be submitting. > > Thanks. > > -- > RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ > FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Hi Prabhakar, On 07/04/2025 13:03, 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> [snip] > 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..a0f7cacea810 > --- /dev/null > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c > @@ -0,0 +1,165 @@ > +// 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 "dwmac4.h" I'm looking at this while working on RZ/T2H Ethernet support, clangd says inclusion of dwmac4.h is not needed here and compilation succeeds with the include removed. Thanks,
On Mon, Apr 07, 2025 at 07:07:49PM +0100, Lad, Prabhakar wrote: > On Mon, Apr 7, 2025 at 6:58 PM Russell King (Oracle) > <linux@armlinux.org.uk> wrote: > > > > On Mon, Apr 07, 2025 at 01:03:17PM +0100, Prabhakar wrote: > > > +static struct clk *renesas_gbeth_find_clk(struct plat_stmmacenet_data *plat_dat, > > > + const char *name) > > > +{ > > > + for (unsigned int i = 0; i < plat_dat->num_clks; i++) > > > + if (!strcmp(plat_dat->clks[i].id, name)) > > > + return plat_dat->clks[i].clk; > > > + > > > + return NULL; > > > +} > > > > In addition to Jakub's request, I'll ask that you hold off for a week > > because I have the following that I'd like to submit: > > > Ack, please add me in Cc while you post this patch. FYI, the patch was merged last Thursday, so please update to replace the above with stmmac_pltfr_find_clk() which will do this for you. Thanks.
Hi Paul, On Mon, Apr 14, 2025 at 2:13 PM Paul Barker <paul.barker.ct@bp.renesas.com> wrote: > > Hi Prabhakar, > > On 07/04/2025 13:03, 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> > > [snip] > > > 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..a0f7cacea810 > > --- /dev/null > > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c > > @@ -0,0 +1,165 @@ > > +// 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 "dwmac4.h" > > I'm looking at this while working on RZ/T2H Ethernet support, clangd > says inclusion of dwmac4.h is not needed here and compilation succeeds > with the include removed. > Agreed, I will drop this. Cheers, Prabhakar
Hi Russell, On Mon, Apr 14, 2025 at 3:31 PM Russell King (Oracle) <linux@armlinux.org.uk> wrote: > > On Mon, Apr 07, 2025 at 07:07:49PM +0100, Lad, Prabhakar wrote: > > On Mon, Apr 7, 2025 at 6:58 PM Russell King (Oracle) > > <linux@armlinux.org.uk> wrote: > > > > > > On Mon, Apr 07, 2025 at 01:03:17PM +0100, Prabhakar wrote: > > > > +static struct clk *renesas_gbeth_find_clk(struct plat_stmmacenet_data *plat_dat, > > > > + const char *name) > > > > +{ > > > > + for (unsigned int i = 0; i < plat_dat->num_clks; i++) > > > > + if (!strcmp(plat_dat->clks[i].id, name)) > > > > + return plat_dat->clks[i].clk; > > > > + > > > > + return NULL; > > > > +} > > > > > > In addition to Jakub's request, I'll ask that you hold off for a week > > > because I have the following that I'd like to submit: > > > > > Ack, please add me in Cc while you post this patch. > > FYI, the patch was merged last Thursday, so please update to replace > the above with stmmac_pltfr_find_clk() which will do this for you. > Thanks, I'll rebase my changes on top of it and send out v6. Cheers, Prabhakar
On Mon, Apr 07, 2025 at 01:03:17PM +0100, Prabhakar wrote: > + 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->clks_config = renesas_gbeth_clks_config; > + plat_dat->flags |= STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY | > + STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP | > + STMMAC_FLAG_SPH_DISABLE; > + > + err = renesas_gbeth_clks_config(gbeth, true); > + if (err) > + return err; > + > + err = stmmac_dvr_probe(dev, plat_dat, &stmmac_res); > + if (err) > + renesas_gbeth_clks_config(gbeth, false); > + > + return err; > +} > + > +static void renesas_gbeth_remove(struct platform_device *pdev) > +{ > + stmmac_dvr_remove(&pdev->dev); > + > + renesas_gbeth_clks_config(get_stmmac_bsp_priv(&pdev->dev), false); > +} Would calling renesas_gbeth_clks_config() in the suspend/resume paths cause problems? If not, please consider using plat_dat->init() and plat_dat->exit() to control these clocks, and then use devm_stmmac_pltfr_probe() which will call the ->init and ->exit functions around the probe as necessary and at removal time (and you won't need the remove method.) Thanks.
Hi Russell, On Mon, Apr 14, 2025 at 5:57 PM Russell King (Oracle) <linux@armlinux.org.uk> wrote: > > On Mon, Apr 07, 2025 at 01:03:17PM +0100, Prabhakar wrote: > > + 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->clks_config = renesas_gbeth_clks_config; > > + plat_dat->flags |= STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY | > > + STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP | > > + STMMAC_FLAG_SPH_DISABLE; > > + > > + err = renesas_gbeth_clks_config(gbeth, true); > > + if (err) > > + return err; > > + > > + err = stmmac_dvr_probe(dev, plat_dat, &stmmac_res); > > + if (err) > > + renesas_gbeth_clks_config(gbeth, false); > > + > > + return err; > > +} > > + > > +static void renesas_gbeth_remove(struct platform_device *pdev) > > +{ > > + stmmac_dvr_remove(&pdev->dev); > > + > > + renesas_gbeth_clks_config(get_stmmac_bsp_priv(&pdev->dev), false); > > +} > > Would calling renesas_gbeth_clks_config() in the suspend/resume paths > cause problems? > > If not, please consider using plat_dat->init() and plat_dat->exit() > to control these clocks, and then use devm_stmmac_pltfr_probe() > which will call the ->init and ->exit functions around the probe > as necessary and at removal time (and you won't need the remove > method.) > I'll test this on the platform which can support suspend/resume and update accordingly. Cheers, Prabhakar
Hi Russell, On Mon, Apr 14, 2025 at 7:14 PM Lad, Prabhakar <prabhakar.csengg@gmail.com> wrote: > > Hi Russell, > > On Mon, Apr 14, 2025 at 5:57 PM Russell King (Oracle) > <linux@armlinux.org.uk> wrote: > > > > On Mon, Apr 07, 2025 at 01:03:17PM +0100, Prabhakar wrote: > > > + 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->clks_config = renesas_gbeth_clks_config; > > > + plat_dat->flags |= STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY | > > > + STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP | > > > + STMMAC_FLAG_SPH_DISABLE; > > > + > > > + err = renesas_gbeth_clks_config(gbeth, true); > > > + if (err) > > > + return err; > > > + > > > + err = stmmac_dvr_probe(dev, plat_dat, &stmmac_res); > > > + if (err) > > > + renesas_gbeth_clks_config(gbeth, false); > > > + > > > + return err; > > > +} > > > + > > > +static void renesas_gbeth_remove(struct platform_device *pdev) > > > +{ > > > + stmmac_dvr_remove(&pdev->dev); > > > + > > > + renesas_gbeth_clks_config(get_stmmac_bsp_priv(&pdev->dev), false); > > > +} > > > > Would calling renesas_gbeth_clks_config() in the suspend/resume paths > > cause problems? > > > > If not, please consider using plat_dat->init() and plat_dat->exit() > > to control these clocks, and then use devm_stmmac_pltfr_probe() > > which will call the ->init and ->exit functions around the probe > > as necessary and at removal time (and you won't need the remove > > method.) > > On the RZ/G3E, the upstream support for testing S2R is not yet in a usable state. So for now, I'll switch to using init/exit callbacks and drop the PM callback. Cheers, Prabhakar
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..a0f7cacea810 --- /dev/null +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c @@ -0,0 +1,165 @@ +// 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 "dwmac4.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 struct clk *renesas_gbeth_find_clk(struct plat_stmmacenet_data *plat_dat, + const char *name) +{ + for (unsigned int i = 0; i < plat_dat->num_clks; i++) + if (!strcmp(plat_dat->clks[i].id, name)) + return plat_dat->clks[i].clk; + + return NULL; +} + +static int renesas_gbeth_clks_config(void *priv, bool enabled) +{ + struct plat_stmmacenet_data *plat_dat; + struct renesas_gbeth *gbeth = priv; + 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_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 = renesas_gbeth_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->clks_config = renesas_gbeth_clks_config; + plat_dat->flags |= STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY | + STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP | + STMMAC_FLAG_SPH_DISABLE; + + err = renesas_gbeth_clks_config(gbeth, true); + if (err) + return err; + + err = stmmac_dvr_probe(dev, plat_dat, &stmmac_res); + if (err) + renesas_gbeth_clks_config(gbeth, false); + + return err; +} + +static void renesas_gbeth_remove(struct platform_device *pdev) +{ + stmmac_dvr_remove(&pdev->dev); + + renesas_gbeth_clks_config(get_stmmac_bsp_priv(&pdev->dev), false); +} + +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, + .remove = renesas_gbeth_remove, + .driver = { + .name = "renesas-gbeth", + .pm = &stmmac_pltfr_pm_ops, + .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");