[RFC PATCH net-next 2/2] net: dsa: mt7530: introduce MMIO driver for MT7988 SoC
Andrew Lunn
andrew at lunn.ch
Mon Mar 27 18:58:50 PDT 2023
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
> @@ -118,6 +118,9 @@ core_write_mmd_indirect(struct mt7530_priv *priv, int prtad,
> struct mii_bus *bus = priv->bus;
> int ret;
>
> + if (!bus)
> + return 0;
> +
> /* Write the desired MMD Devad */
> ret = bus->write(bus, 0, MII_MMD_CTRL, devad);
> if (ret < 0)
> @@ -147,11 +150,13 @@ core_write(struct mt7530_priv *priv, u32 reg, u32 val)
> {
> struct mii_bus *bus = priv->bus;
>
> - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
> + if (bus)
> + mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
>
> core_write_mmd_indirect(priv, reg, MDIO_MMD_VEND2, val);
>
> - mutex_unlock(&bus->mdio_lock);
> + if (bus)
> + mutex_unlock(&bus->mdio_lock);
> }
>
> static void
> @@ -160,6 +165,9 @@ core_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set)
> struct mii_bus *bus = priv->bus;
> u32 val;
>
> + if (!bus)
> + return;
> +
> mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
>
> val = core_read_mmd_indirect(priv, reg, MDIO_MMD_VEND2);
> @@ -189,6 +197,11 @@ mt7530_mii_write(struct mt7530_priv *priv, u32 reg, u32 val)
> u16 page, r, lo, hi;
> int ret;
>
> + if (priv->base_addr) {
> + iowrite32(val, priv->base_addr + reg);
> + return 0;
> + }
> +
> page = (reg >> 6) & 0x3ff;
> r = (reg >> 2) & 0xf;
> lo = val & 0xffff;
> @@ -218,6 +231,9 @@ mt7530_mii_read(struct mt7530_priv *priv, u32 reg)
> u16 page, r, lo, hi;
> int ret;
>
> + if (priv->base_addr)
> + return ioread32(priv->base_addr + reg);
> +
> page = (reg >> 6) & 0x3ff;
> r = (reg >> 2) & 0xf;
>
This looks pretty ugly.
A much better way to do this is to use regmap. Take a look at xrs700x
and how it has both an i2c and an mdio version.
Andrew
More information about the linux-arm-kernel
mailing list