Thread View: linux.kernel.netdev
4 messages
4 total messages
Started by Cunhao Lu via B4 Relay
Mon, 16 Nov 2026 07:39
[PATCH net-next v3 2/2] net: stmmac: dwmac-rk: Add RK3572 support
Author: Cunhao Lu via B4 Relay
Date: Mon, 16 Nov 2026 07:39
Date: Mon, 16 Nov 2026 07:39
90 lines
13603 bytes
13603 bytes
From: Cunhao Lu <1579567540@qq.com>
The RK3572 has two GMAC controllers with separate mode and clock control
registers in the PHP and NVM0 GRFs. RGMII delay lines are configured
through the IOC.
Add the register layout and delay callback for both controllers so the
Rockchip glue driver can configure their RGMII and RMII interfaces and
select the appropriate clocks for each link speed.
Signed-off-by: Cunhao Lu <1579567540@qq.com>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 53 ++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
index a37df5767d84..c9d8d8bf51f7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
@@ -900,6 +900,58 @@ static const struct rk_gmac_ops rk3568_ops = {
},
};
+#define RK3572_VCCIO0_3_VO_IOC_CON1 0x10608
+#define RK3572_VCCIO1_2_4_VI_IOC_CON1 0x12604
+#define RK3572_VCCIO5_6_IOC_MISC0 0x14630
+#define RK3572_PHP_GRF_GMAC0_CON 0x0070
+#define RK3572_NVM0_GRF_GMAC1_CON 0x0020
+
+static int rk3572_init(struct rk_priv_data *bsp_priv)
+{
+ switch (bsp_priv->id) {
+ case 0:
+ bsp_priv->gmac_grf_reg = RK3572_PHP_GRF_GMAC0_CON;
+ break;
+ case 1:
+ bsp_priv->gmac_grf_reg = RK3572_NVM0_GRF_GMAC1_CON;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ bsp_priv->clock_grf_reg = bsp_priv->gmac_grf_reg;
+ return 0;
+}
+
+static void rk3572_set_to_rgmii(struct rk_priv_data *bsp_priv,
+ int tx_delay, int rx_delay)
+{
+ u32 val = GRF_FIELD(14, 8, rx_delay) | GRF_FIELD(6, 0, tx_delay) |
+ GRF_FIELD(15, 15, !!rx_delay) | GRF_FIELD(7, 7, !!tx_delay);
+
+ if (bsp_priv->id == 1) {
+ regmap_write(bsp_priv->php_grf, RK3572_VCCIO0_3_VO_IOC_CON1, val);
+ regmap_write(bsp_priv->php_grf, RK3572_VCCIO5_6_IOC_MISC0, val);
+ } else {
+ regmap_write(bsp_priv->php_grf, RK3572_VCCIO1_2_4_VI_IOC_CON1, val);
+ }
+}
+
+static const struct rk_gmac_ops rk3572_ops = {
+ .init = rk3572_init,
+ .set_to_rgmii = rk3572_set_to_rgmii,
+ .gmac_phy_intf_sel_mask = GENMASK_U16(11, 9),
+ .gmac_rmii_mode_mask = BIT_U16(3),
+ .clock.io_clksel_io_mask = BIT_U16(7),
+ .clock.gmii_clk_sel_mask = GENMASK_U16(6, 5),
+ .clock.rmii_clk_sel_mask = BIT_U16(5),
+ .clock.rmii_gate_en_mask = BIT_U16(4),
+ .supports_rmii = true,
+ .php_grf_required = true,
+ .regs_valid = true,
+ .regs = { 0x29d20000, 0x2a040000, 0 },
+};
+
/* VCCIO0_1_3_IOC */
#define RK3576_VCCIO0_1_3_IOC_CON2 0X6408
#define RK3576_VCCIO0_1_3_IOC_CON3 0X640c
@@ -1720,6 +1772,7 @@ static const struct of_device_id rk_gmac_dwmac_match[] = {
{ .compatible = "rockchip,rk3506-gmac", .data = &rk3506_ops },
{ .compatible = "rockchip,rk3528-gmac", .data = &rk3528_ops },
{ .compatible = "rockchip,rk3568-gmac", .data = &rk3568_ops },
+ { .compatible = "rockchip,rk3572-gmac", .data = &rk3572_ops },
{ .compatible = "rockchip,rk3576-gmac", .data = &rk3576_ops },
{ .compatible = "rockchip,rk3588-gmac", .data = &rk3588_ops },
{ .compatible = "rockchip,rv1108-gmac", .data = &rv1108_ops },
--
2.34.1
Re: [PATCH net-next v3 2/2] net: stmmac: dwmac-rk: Add RK3572 support
Author: Andrew Lunn
Date: Mon, 16 Nov 2026 13:55
Date: Mon, 16 Nov 2026 13:55
34 lines
9926 bytes
9926 bytes
> +static void rk3572_set_to_rgmii(struct rk_priv_data *bsp_priv,
> + int tx_delay, int rx_delay)
> +{
> + u32 val = GRF_FIELD(14, 8, rx_delay) | GRF_FIELD(6, 0, tx_delay) |
> + GRF_FIELD(15, 15, !!rx_delay) | GRF_FIELD(7, 7, !!tx_delay);
> +
> + if (bsp_priv->id == 1) {
> + regmap_write(bsp_priv->php_grf, RK3572_VCCIO0_3_VO_IOC_CON1, val);
> + regmap_write(bsp_priv->php_grf, RK3572_VCCIO5_6_IOC_MISC0, val);
> + } else {
> + regmap_write(bsp_priv->php_grf, RK3572_VCCIO1_2_4_VI_IOC_CON1, val);
> + }
> +}
> +
> +static const struct rk_gmac_ops rk3572_ops = {
> + .init = rk3572_init,
> + .set_to_rgmii = rk3572_set_to_rgmii,
> + .gmac_phy_intf_sel_mask = GENMASK_U16(11, 9),
> + .gmac_rmii_mode_mask = BIT_U16(3),
> + .clock.io_clksel_io_mask = BIT_U16(7),
> + .clock.gmii_clk_sel_mask = GENMASK_U16(6, 5),
> + .clock.rmii_clk_sel_mask = BIT_U16(5),
> + .clock.rmii_gate_en_mask = BIT_U16(4),
> + .supports_rmii = true,
> + .php_grf_required = true,
> + .regs_valid = true,
> + .regs = { 0x29d20000, 0x2a040000, 0 },
> +};
Just looking at this, it is not obvious that rx_delay and tx_delay are
actually not used.
Andrew
Re: [PATCH net-next v3 2/2] net: stmmac: dwmac-rk: Add RK3572 support
Author: Andrew Lunn
Date: Mon, 16 Nov 2026 15:58
Date: Mon, 16 Nov 2026 15:58
39 lines
10631 bytes
10631 bytes
On Mon, Nov 16, 2026 at 11:11:42PM +0800, Cunhao Lu wrote:
> Hi,
>
> > [...]
> > > + .regs_valid = true,
> > > + .regs = { 0x29d20000, 0x2a040000, 0 },
> > > +};
> >
> > Just looking at this, it is not obvious that rx_delay and tx_delay are
> > actually not used.
>
> My board currently uses rgmii-id, where both MAC TX and RX delays
> are disabled. I kept the delay handling to support rgmii-rxid,
> rgmii-txid and rgmii, using the default values for the MAC delays
> enabled in those modes. The legacy tx_delay and rx_delay properties
> are now disallowed for RK3572 in the binding.
>
> I currently have only one oscilloscope, with a maximum bandwidth of
> 200 MHz. With this equipment, I cannot accurately determine how the
> TX and RX delay register values translate to picoseconds, so I am
> not planning to add support for tx-internal-delay-ps and
> rx-internal-delay-ps in this series for now.
>
> Would it be acceptable to support only rgmii-id for RGMII in the next
> version, and reject rgmii, rgmii-rxid and rgmii-txid? This would let me
> stop using tx_delay and rx_delay in the RK3572 driver path as well.
No, rgmii, rgmii-rxid and rgmii-txid are valid, it depends on the PCB
design.
https://elixir.bootlin.com/linux/v6.15/source/Documentation/devicetree/bindings/net/ethernet-controller.yaml#L287
What i would prefer is that the C code does not parse the rx_delay and
tx_delay properties. If somebody actually needs them, they need to
implement tx-internal-delay-ps and rx-internal-delay-ps. Since you
don't need them, you don't need to implement them.
Andrew
Re: [PATCH net-next v3 2/2] net: stmmac: dwmac-rk: Add RK3572 support
Author: netdev-bot+sashiko
Date: Wed, 18 Nov 2026 10:41
Date: Wed, 18 Nov 2026 10:41
108 lines
11907 bytes
11907 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] RK3572 RGMII delay lines get fixed values that the DT is not
allowed to describe.
--
net: stmmac: dwmac-rk: Add RK3572 support
This patch adds RK3572 support to the Rockchip dwmac glue driver. It
covers the register layout for the two GMAC controllers in the PHP and
NVM0 GRFs, plus a set_to_rgmii callback that programs the RGMII delay
lines through the IOC.
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> index a37df5767d84e..c9d8d8bf51f7b 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
[ ... ]
> +static void rk3572_set_to_rgmii(struct rk_priv_data *bsp_priv,
> + int tx_delay, int rx_delay)
> +{
> + u32 val = GRF_FIELD(14, 8, rx_delay) | GRF_FIELD(6, 0, tx_delay) |
> + GRF_FIELD(15, 15, !!rx_delay) | GRF_FIELD(7, 7, !!tx_delay);
> +
> + if (bsp_priv->id == 1) {
> + regmap_write(bsp_priv->php_grf, RK3572_VCCIO0_3_VO_IOC_CON1, val);
> + regmap_write(bsp_priv->php_grf, RK3572_VCCIO5_6_IOC_MISC0, val);
> + } else {
> + regmap_write(bsp_priv->php_grf, RK3572_VCCIO1_2_4_VI_IOC_CON1, val);
> + }
> +}
[Severity: Medium]
Where are the tx_delay and rx_delay values for RK3572 meant to come from?
The companion binding change in rockchip-dwmac.yaml forbids the legacy
properties for this compatible:
- if:
properties:
compatible:
contains:
const: rockchip,rk3572-gmac
then:
properties:
rx_delay: false
tx_delay: false
That means a schema-valid RK3572 node never has them. rk_gmac_setup() then
falls back to the old defaults and logs an error on every probe:
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c:rk_gmac_setup() {
...
ret = of_property_read_u32(dev->of_node, "tx_delay", &value);
if (ret) {
bsp_priv->tx_delay = 0x30;
dev_err(dev, "Can not read property: tx_delay.");
...
ret = of_property_read_u32(dev->of_node, "rx_delay", &value);
if (ret) {
bsp_priv->rx_delay = 0x10;
dev_err(dev, "Can not read property: rx_delay.");
...
}
rk_gmac_powerup() passes these defaults on for "rgmii" (both delays),
"rgmii-rxid" (tx_delay) and "rgmii-txid" (rx_delay). Since bits 15 and 7
are set from !!rx_delay and !!tx_delay, rk3572_set_to_rgmii() switches on
the IOC delay lines with 0x30/0x10 taps for every RGMII mode except
"rgmii-id".
The 0x30/0x10 defaults come from older Rockchip SoCs. Do they match the
RK3572 tap size?
A board can't override them without failing schema validation. The driver
also doesn't read rx-internal-delay-ps or tx-internal-delay-ps.
Consider a board that uses "rgmii" with PCB delays, or a PHY that adds its
own delay. Could this leave the RX/TX sampling skewed, with no supported
way to fix it in DT?
Would it make sense to either zero the MAC-side delays for RK3572 when the
legacy properties are absent, or take them from the standard
*-internal-delay-ps properties? If not, should the binding keep allowing
tx_delay/rx_delay for now?
> +
> +static const struct rk_gmac_ops rk3572_ops = {
> + .init = rk3572_init,
> + .set_to_rgmii = rk3572_set_to_rgmii,
[ ... ]
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-add-board-ok3572-c-net-v3-0-a957fdcd9c7a%40qq.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads