Re: [RFC PATCH net-next 2/2] net: dsa: mt7530: introduce MMIO driver for MT7988 SoC
From: Andrew Lunn
Date: Tue Mar 28 2023 - 10:00:48 EST
> I agree that using regmap would be better and I have evaluated that
> approach as well. As regmap doesn't allow lock-skipping and mt7530.c is
> much more complex than xrs700x in the way indirect access to its MDIO bus
> and interrupts work, using regmap accessors for everything would not be
> trivial.
O.K, so lets go another way.
Study the low level accesors, and put an abstraction over
them. Provide an MDIO set and an MMIO set.
> To illustrate what I'm talking about, let me show some examples in the
> current code for which I don't see a way to use regmap:
> 634) static int
> 635) mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad,
> 636) int regnum)
> 637) {
> 638) struct mii_bus *bus = priv->bus;
> 639) struct mt7530_dummy_poll p;
> 640) u32 reg, val;
> 641) int ret;
> 642)
> 643) INIT_MT7530_DUMMY_POLL(&p, priv, MT7531_PHY_IAC);
> 644)
> 645) mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
So you need an abstract lock() and an unlock(). Maybe the MMIO
implementation is a NOP? And the MDIO implementation does a real lock?
> 646)
> 647) ret = readx_poll_timeout(_mt7530_unlocked_read, &p, val,
> 648) !(val & MT7531_PHY_ACS_ST), 20, 100000);
_mt7530_unlocked_read and presumably _mt7530_unlocked_write()?
> 649) if (ret < 0) {
> 650) dev_err(priv->dev, "poll timeout\n");
> 651) goto out;
> 652) }
> 653)
> 654) reg = MT7531_MDIO_CL45_ADDR | MT7531_MDIO_PHY_ADDR(port) |
> 655) MT7531_MDIO_DEV_ADDR(devad) | regnum;
> 656) mt7530_mii_write(priv, MT7531_PHY_IAC, reg | MT7531_PHY_ACS_ST);
mt7530_write() and mt7530_read()
Put the MDIO accessors in the _mdio.c file, and the MMIO accessors in
the _mmio.c file. Pass them to the core. If you have the abstraction
correct, the core should not care how the registers are accessed.
Andrew