Message ID | 20230820120213.2054-1-jszhang@kernel.org |
---|---|
Headers | show |
Series | add the dwmac driver for T-HEAD TH1520 SoC | expand |
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@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; > + } > +} ...
On 20/08/2023 14:02, Jisheng Zhang wrote: > Add documentation to describe T-HEAD dwmac. > > Signed-off-by: Jisheng Zhang <jszhang@kernel.org> > --- Thank you for your patch. There is something to discuss/improve. > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) > +%YAML 1.2 > +--- > +$id: http://devicetree.org/schemas/net/thead,dwmac.yaml# > +$schema: http://devicetree.org/meta-schemas/core.yaml# > + > +title: T-HEAD DWMAC glue layer Describe/name rather the actual device, not some layer. > + > +maintainers: > + - Jisheng Zhang <jszhang@kernel.org> > + > +select: > + properties: > + compatible: > + contains: > + enum: > + - thead,th1520-dwmac > + required: > + - compatible > + > +properties: > + compatible: > + items: > + - enum: > + - thead,th1520-dwmac > + - const: snps,dwmac-3.70a > + > + reg: > + maxItems: 1 > + > + clocks: > + items: > + - description: GMAC main clock > + - description: AXI clock > + > + clock-names: > + items: > + - const: stmmaceth > + - const: axi Isn't basically axi clock a pclk? You should rather use the names from snps,dwmac > + > + thead,gmacapb: > + $ref: /schemas/types.yaml#/definitions/phandle > + description: > + The phandle to the syscon node that control ethernet > + interface and timing delay. > + > +required: > + - compatible > + - reg > + - clocks > + - clock-names > + - interrupts > + - interrupt-names > + - phy-mode > + - thead,gmacapb Best regards, Krzysztof