[PATCH RFC net-next 06/15] net: stmmac: rk: convert rk3588 to rk_set_reg_speed()

Russell King (Oracle)
2025-12-01T14:51:31Z

Update rk_set_reg_speed() to use either the grf or php_grf regmap
depending on the SoC's requirements and convert rk3588, removing
its custom code.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
.../net/ethernet/stmicro/stmmac/dwmac-rk.c | 62 ++++++++++---------
1 file changed, 33 insertions(+), 29 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
index e2c5bfbeadc5..2061ced12d6c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
@@ -52,6 +52,7 @@ struct rk_gmac_ops {

u16 speed_grf_reg;

+ bool speed_reg_php_grf;
bool php_grf_required;
bool regs_valid;
u32 regs[];
@@ -134,6 +135,7 @@ static int rk_set_reg_speed(struct rk_priv_data *bsp_priv,
const struct rk_reg_speed_data *rsd,
phy_interface_t interface, int speed)
{
+ struct regmap *regmap;
unsigned int val;

if (phy_interface_mode_is_rgmii(interface)) {
@@ -168,7 +170,12 @@ static int rk_set_reg_speed(struct rk_priv_data *bsp_priv,
return -EINVAL;
}

- regmap_write(bsp_priv->grf, bsp_priv->speed_grf_reg, val);
+ if (bsp_priv->ops->speed_reg_php_grf)
+ regmap = bsp_priv->php_grf;
+ else
+ regmap = bsp_priv->grf;
+
+ regmap_write(regmap, bsp_priv->speed_grf_reg, val);

return 0;

@@ -1318,39 +1325,33 @@ static void rk3588_set_to_rmii(struct rk_priv_data *bsp_priv)
RK3588_GMAC_CLK_RMII_MODE(bsp_priv->id));
}

+static const struct rk_reg_speed_data rk3588_gmac0_speed_data = {
+ .rgmii_10 = RK3588_GMAC_CLK_RGMII(0, GMAC_CLK_DIV50_2_5M),
+ .rgmii_100 = RK3588_GMAC_CLK_RGMII(0, GMAC_CLK_DIV5_25M),
+ .rgmii_1000 = RK3588_GMAC_CLK_RGMII(0, GMAC_CLK_DIV1_125M),
+ .rmii_10 = RK3588_GMA_CLK_RMII_DIV20(0),
+ .rmii_100 = RK3588_GMA_CLK_RMII_DIV2(0),
+};
+
+static const struct rk_reg_speed_data rk3588_gmac1_speed_data = {
+ .rgmii_10 = RK3588_GMAC_CLK_RGMII(1, GMAC_CLK_DIV50_2_5M),
+ .rgmii_100 = RK3588_GMAC_CLK_RGMII(1, GMAC_CLK_DIV5_25M),
+ .rgmii_1000 = RK3588_GMAC_CLK_RGMII(1, GMAC_CLK_DIV1_125M),
+ .rmii_10 = RK3588_GMA_CLK_RMII_DIV20(1),
+ .rmii_100 = RK3588_GMA_CLK_RMII_DIV2(1),
+};
+
static int rk3588_set_gmac_speed(struct rk_priv_data *bsp_priv,
phy_interface_t interface, int speed)
{
- unsigned int val = 0, id = bsp_priv->id;
-
- switch (speed) {
- case 10:
- if (interface == PHY_INTERFACE_MODE_RMII)
- val = RK3588_GMA_CLK_RMII_DIV20(id);
- else
- val = RK3588_GMAC_CLK_RGMII(id, GMAC_CLK_DIV50_2_5M);
- break;
- case 100:
- if (interface == PHY_INTERFACE_MODE_RMII)
- val = RK3588_GMA_CLK_RMII_DIV2(id);
- else
- val = RK3588_GMAC_CLK_RGMII(id, GMAC_CLK_DIV5_25M);
- break;
- case 1000:
- if (interface != PHY_INTERFACE_MODE_RMII)
- val = RK3588_GMAC_CLK_RGMII(id, GMAC_CLK_DIV1_125M);
- else
- goto err;
- break;
- default:
- goto err;
- }
+ const struct rk_reg_speed_data *rsd;

- regmap_write(bsp_priv->php_grf, RK3588_GRF_CLK_CON1, val);
+ if (bsp_priv->id == 0)
+ rsd = &rk3588_gmac0_speed_data;
+ else
+ rsd = &rk3588_gmac1_speed_data;

- return 0;
-err:
- return -EINVAL;
+ return rk_set_reg_speed(bsp_priv, rsd, interface, speed);
}

static void rk3588_set_clock_selection(struct rk_priv_data *bsp_priv, bool input,
@@ -1374,6 +1375,9 @@ static const struct rk_gmac_ops rk3588_ops = {

.phy_intf_sel_grf_reg = RK3588_GRF_GMAC_CON0,

+ .speed_reg_php_grf = true,
+ .speed_grf_reg = RK3588_GRF_CLK_CON1,
+
.php_grf_required = true,
.regs_valid = true,
.regs = {