[PATCH net-next 3/3] net: stmmac: add glue layer for T-HEAD TH1520 SoC
Simon Horman
horms at kernel.org
Sun Aug 20 07:55:17 PDT 2023
On Sun, Aug 20, 2023 at 08:02:13PM +0800, Jisheng Zhang wrote:
> Add dwmac glue driver to support the dwmac on the T-HEAD TH1520 SoC.
>
> Signed-off-by: Jisheng Zhang <jszhang at kernel.org>
...
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c
...
> +static void thead_dwmac_fix_speed(void *priv, unsigned int speed, unsigned int mode)
> +{
> + struct thead_dwmac *dwmac = priv;
> + struct plat_stmmacenet_data *plat = dwmac->plat;
> + unsigned long rate;
> + u32 div;
> +
> + switch (plat->interface) {
> + /* For MII, rxc/txc is provided by phy */
> + case PHY_INTERFACE_MODE_MII:
> + return;
> +
> + case PHY_INTERFACE_MODE_RGMII:
> + case PHY_INTERFACE_MODE_RGMII_ID:
> + case PHY_INTERFACE_MODE_RGMII_RXID:
> + case PHY_INTERFACE_MODE_RGMII_TXID:
> + rate = clk_get_rate(plat->stmmac_clk);
> + if (!rate || rate % GMAC_GMII_RGMII_RATE != 0 ||
> + rate % GMAC_MII_RATE != 0) {
> + dev_err(dwmac->dev, "invalid gmac rate %ld\n", rate);
> + return;
> + }
> +
> + regmap_update_bits(dwmac->apb_regmap, GMAC_PLLCLK_DIV, GMAC_PLLCLK_DIV_EN, 0);
> +
> + switch (speed) {
> + case SPEED_1000:
> + div = rate / GMAC_GMII_RGMII_RATE;
> + break;
> + case SPEED_100:
> + div = rate / GMAC_MII_RATE;
> + break;
> + case SPEED_10:
> + div = rate * 10 / GMAC_MII_RATE;
> + break;
> + default:
> + dev_err(dwmac->dev, "invalid speed %u\n", speed);
> + break;
Hi Jisheng Zhang,
In this case, div is not initialised, but it is used a few
lines below. Perhaps the function should return here?
As flagged by clang-16 (W=1) and Smatch.
> + }
> + regmap_update_bits(dwmac->apb_regmap, GMAC_PLLCLK_DIV,
> + GMAC_PLLCLK_DIV_MASK, GMAC_PLLCLK_DIV_NUM(div));
> +
> + regmap_update_bits(dwmac->apb_regmap, GMAC_PLLCLK_DIV,
> + GMAC_PLLCLK_DIV_EN, GMAC_PLLCLK_DIV_EN);
> + break;
> + default:
> + dev_err(dwmac->dev, "unsupported phy interface %d\n",
> + plat->interface);
> + return;
> + }
> +}
...
More information about the linux-riscv
mailing list