Skip to content

Commit 36fe9ed

Browse files
prabhakarladNipaLocal
authored andcommitted
net: stmmac: Add DWMAC glue layer for Renesas GBETH
Add the DWMAC glue layer for the GBETH IP found in the Renesas RZ/V2H(P) SoC. Signed-off-by: Lad Prabhakar <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent bc050f2 commit 36fe9ed

File tree

3 files changed

+177
-0
lines changed

3 files changed

+177
-0
lines changed

drivers/net/ethernet/stmicro/stmmac/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ config DWMAC_QCOM_ETHQOS
131131
This selects the Qualcomm ETHQOS glue layer support for the
132132
stmmac device driver.
133133

134+
config DWMAC_RENESAS_GBETH
135+
tristate "Renesas RZ/V2H(P) GBETH support"
136+
default ARCH_RENESAS
137+
depends on OF && (ARCH_RENESAS || COMPILE_TEST)
138+
help
139+
Support for Gigabit Ethernet Interface (GBETH) on Renesas
140+
RZ/V2H(P) SoCs.
141+
142+
This selects the Renesas RZ/V2H(P) Soc specific glue layer support
143+
for the stmmac device driver.
144+
134145
config DWMAC_ROCKCHIP
135146
tristate "Rockchip dwmac support"
136147
default ARCH_ROCKCHIP

drivers/net/ethernet/stmicro/stmmac/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ obj-$(CONFIG_DWMAC_LPC18XX) += dwmac-lpc18xx.o
2020
obj-$(CONFIG_DWMAC_MEDIATEK) += dwmac-mediatek.o
2121
obj-$(CONFIG_DWMAC_MESON) += dwmac-meson.o dwmac-meson8b.o
2222
obj-$(CONFIG_DWMAC_QCOM_ETHQOS) += dwmac-qcom-ethqos.o
23+
obj-$(CONFIG_DWMAC_RENESAS_GBETH) += dwmac-renesas-gbeth.o
2324
obj-$(CONFIG_DWMAC_ROCKCHIP) += dwmac-rk.o
2425
obj-$(CONFIG_DWMAC_RZN1) += dwmac-rzn1.o
2526
obj-$(CONFIG_DWMAC_S32) += dwmac-s32.o
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* dwmac-renesas-gbeth.c - DWMAC Specific Glue layer for Renesas GBETH
4+
*
5+
* The Rx and Tx clocks are supplied as follows for the GBETH IP.
6+
*
7+
* Rx / Tx
8+
* -------+------------- on / off -------
9+
* |
10+
* | Rx-180 / Tx-180
11+
* +---- not ---- on / off -------
12+
*
13+
* Copyright (C) 2025 Renesas Electronics Corporation
14+
*/
15+
16+
#include <linux/clk.h>
17+
#include <linux/device.h>
18+
#include <linux/module.h>
19+
#include <linux/platform_device.h>
20+
#include <linux/reset.h>
21+
22+
#include "dwmac4.h"
23+
#include "stmmac_platform.h"
24+
25+
struct renesas_gbeth {
26+
struct device *dev;
27+
void __iomem *regs;
28+
unsigned int num_clks;
29+
struct clk *clk_tx_i;
30+
struct clk_bulk_data *clks;
31+
struct reset_control *rstc;
32+
};
33+
34+
static const char *const renesas_gbeth_clks[] = {
35+
"rx", "rx-180", "tx-180",
36+
};
37+
38+
static int renesas_gbeth_clks_config(void *priv, bool enabled)
39+
{
40+
struct renesas_gbeth *gbeth = priv;
41+
int ret;
42+
43+
if (enabled) {
44+
ret = reset_control_deassert(gbeth->rstc);
45+
if (ret) {
46+
dev_err(gbeth->dev, "Reset deassert failed\n");
47+
return ret;
48+
}
49+
50+
ret = clk_prepare_enable(gbeth->clk_tx_i);
51+
if (ret) {
52+
dev_err(gbeth->dev, "Tx clock enable failed\n");
53+
reset_control_assert(gbeth->rstc);
54+
return ret;
55+
}
56+
57+
ret = clk_bulk_prepare_enable(gbeth->num_clks, gbeth->clks);
58+
if (ret)
59+
clk_disable_unprepare(gbeth->clk_tx_i);
60+
} else {
61+
clk_bulk_disable_unprepare(gbeth->num_clks, gbeth->clks);
62+
clk_disable_unprepare(gbeth->clk_tx_i);
63+
ret = reset_control_assert(gbeth->rstc);
64+
if (ret)
65+
dev_err(gbeth->dev, "Reset assert failed\n");
66+
}
67+
68+
return ret;
69+
}
70+
71+
static int renesas_gbeth_probe(struct platform_device *pdev)
72+
{
73+
struct plat_stmmacenet_data *plat_dat;
74+
struct stmmac_resources stmmac_res;
75+
struct device *dev = &pdev->dev;
76+
struct renesas_gbeth *gbeth;
77+
unsigned int i;
78+
int err;
79+
80+
err = stmmac_get_platform_resources(pdev, &stmmac_res);
81+
if (err)
82+
return dev_err_probe(dev, err,
83+
"failed to get resources\n");
84+
85+
plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac);
86+
if (IS_ERR(plat_dat))
87+
return dev_err_probe(dev, PTR_ERR(plat_dat),
88+
"dt configuration failed\n");
89+
90+
gbeth = devm_kzalloc(dev, sizeof(*gbeth), GFP_KERNEL);
91+
if (!gbeth)
92+
return -ENOMEM;
93+
94+
plat_dat->clk_tx_i = devm_clk_get(dev, "tx");
95+
if (IS_ERR(plat_dat->clk_tx_i))
96+
return dev_err_probe(dev, PTR_ERR(plat_dat->clk_tx_i),
97+
"error getting tx clock\n");
98+
99+
gbeth->clk_tx_i = plat_dat->clk_tx_i;
100+
gbeth->num_clks = ARRAY_SIZE(renesas_gbeth_clks);
101+
gbeth->clks = devm_kcalloc(dev, gbeth->num_clks,
102+
sizeof(*gbeth->clks), GFP_KERNEL);
103+
if (!gbeth->clks)
104+
return -ENOMEM;
105+
106+
for (i = 0; i < gbeth->num_clks; i++)
107+
gbeth->clks[i].id = renesas_gbeth_clks[i];
108+
109+
err = devm_clk_bulk_get(dev, gbeth->num_clks, gbeth->clks);
110+
if (err < 0)
111+
return err;
112+
113+
gbeth->rstc = devm_reset_control_get_exclusive(dev, NULL);
114+
if (IS_ERR(gbeth->rstc))
115+
return PTR_ERR(gbeth->rstc);
116+
117+
gbeth->dev = dev;
118+
gbeth->regs = stmmac_res.addr;
119+
plat_dat->bsp_priv = gbeth;
120+
plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate;
121+
plat_dat->clks_config = renesas_gbeth_clks_config;
122+
plat_dat->flags |= STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY |
123+
STMMAC_FLAG_EN_TX_LPI_CLOCKGATING |
124+
STMMAC_FLAG_SPH_DISABLE;
125+
126+
err = renesas_gbeth_clks_config(gbeth, true);
127+
if (err)
128+
return err;
129+
130+
err = stmmac_dvr_probe(dev, plat_dat, &stmmac_res);
131+
if (err) {
132+
renesas_gbeth_clks_config(gbeth, false);
133+
return err;
134+
}
135+
136+
return 0;
137+
}
138+
139+
static void renesas_gbeth_remove(struct platform_device *pdev)
140+
{
141+
stmmac_dvr_remove(&pdev->dev);
142+
143+
renesas_gbeth_clks_config(get_stmmac_bsp_priv(&pdev->dev), false);
144+
}
145+
146+
static const struct of_device_id renesas_gbeth_match[] = {
147+
{ .compatible = "renesas,rzv2h-gbeth", },
148+
{ /* Sentinel */ }
149+
};
150+
MODULE_DEVICE_TABLE(of, renesas_gbeth_match);
151+
152+
static struct platform_driver renesas_gbeth_driver = {
153+
.probe = renesas_gbeth_probe,
154+
.remove = renesas_gbeth_remove,
155+
.driver = {
156+
.name = "renesas-gbeth",
157+
.pm = &stmmac_pltfr_pm_ops,
158+
.of_match_table = renesas_gbeth_match,
159+
},
160+
};
161+
module_platform_driver(renesas_gbeth_driver);
162+
163+
MODULE_AUTHOR("Lad Prabhakar <[email protected]>");
164+
MODULE_DESCRIPTION("Renesas GBETH DWMAC Specific Glue layer");
165+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)