Re: [PATCH v2 2/3] ethernet: stmmac: dwmac-rk: Add gmac support for rk3562

Andrew Lunn
2025-02-27T13:58:11Z

On Thu, Feb 27, 2025 at 07:06:51PM +0800, Kever Yang wrote:
> From: David Wu <david.wu@rock-chips.com>
>
> Add constants and callback functions for the dwmac on RK3562 soc.
> As can be seen, the base structure is the same.
>
> Signed-off-by: David Wu <david.wu@rock-chips.com>
> Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
> Reviewed-by: Heiko Stuebner <heiko@sntech.de>
> ---
>
> Changes in v2:
> - Collect review tag
>
> .../net/ethernet/stmicro/stmmac/dwmac-rk.c | 207 +++++++++++++++++-
> 1 file changed, 205 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> index a4dc89e23a68..ccf4ecdffad3 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> @@ -2,8 +2,7 @@
> /**
> * DOC: dwmac-rk.c - Rockchip RK3288 DWMAC specific glue layer
> *
> - * Copyright (C) 2014 Chen-Zhi (Roger Chen)
> - *
> + * Copyright (c) 2014 Rockchip Electronics Co., Ltd.
> * Chen-Zhi (Roger Chen) <roger.chen@rock-chips.com>
> */

IANAL, but generally, you add additional copyright notices, not
replace them.

> +#define DELAY_VALUE(soc, tx, rx) \
> + ((((tx) >= 0) ? soc##_GMAC_CLK_TX_DL_CFG(tx) : 0) | \
> + (((rx) >= 0) ? soc##_GMAC_CLK_RX_DL_CFG(rx) : 0))
> +
> +#define GMAC_RGMII_CLK_DIV_BY_ID(soc, id, div) \
> + (soc##_GMAC##id##_CLK_RGMII_DIV##div)
> +
> +#define GMAC_RMII_CLK_DIV_BY_ID(soc, id, div) \
> + (soc##_GMAC##id##_CLK_RMII_DIV##div)
> +

This macro magic is pretty unreadable. Please consider another way to
do this. Some wise developer once said, code is written once, read 100
times. So please make code readable by default, unless it is hot path.

> +static void rk3562_set_gmac_speed(struct rk_priv_data *bsp_priv, int speed)
> +{
> + struct device *dev = &bsp_priv->pdev->dev;
> + unsigned int val = 0, offset, id = bsp_priv->id;
> +
> + switch (speed) {
> + case 10:
> + if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) {
> + if (id > 0) {
> + val = GMAC_RMII_CLK_DIV_BY_ID(RK3562, 1, 20);
> + regmap_write(bsp_priv->grf, RK3562_GRF_SYS_SOC_CON0,
> + RK3562_GMAC1_RMII_SPEED10);
> + } else {
> + val = GMAC_RMII_CLK_DIV_BY_ID(RK3562, 0, 20);
> + }
> + } else {
> + val = GMAC_RGMII_CLK_DIV_BY_ID(RK3562, 0, 50);
> + }
> + break;

It seems like this function would be a lot more readable if it was
split into two, one dealing with RMII and another with RGMII.

> +static void rk3562_set_clock_selection(struct rk_priv_data *bsp_priv, bool input,
> + bool enable)
> +{
> + struct device *dev = &bsp_priv->pdev->dev;
> + unsigned int value;
> +
> + if (IS_ERR(bsp_priv->grf) || IS_ERR(bsp_priv->php_grf)) {
> + dev_err(dev, "Missing rockchip,grf or rockchip,php_grf property\n");
> + return;
> + }

That should of been checked much earlier, at probe.

Andrew