Re: [net-next PATCH v11 5/9] mfd: an8855: Add support for Airoha AN8855 Switch MFD

Christian Marangi
2024-12-10T22:33:39Z

On Tue, Dec 10, 2024 at 11:15:29PM +0200, Vladimir Oltean wrote:
> On Mon, Dec 09, 2024 at 02:44:22PM +0100, Christian Marangi wrote:
> > +int an8855_mii_set_page(struct an8855_mfd_priv *priv, u8 phy_id,
> > + u8 page) __must_hold(&priv->bus->mdio_lock)
> > +{
> > + struct mii_bus *bus = priv->bus;
> > + int ret;
> > +
> > + ret = __mdiobus_write(bus, phy_id, AN8855_PHY_SELECT_PAGE, page);
> > + if (ret < 0)
> > + dev_err_ratelimited(&bus->dev,
> > + "failed to set an8855 mii page\n");
> > +
> > + /* Cache current page if next mii read/write is for switch */
> > + priv->current_page = page;
> > + return ret < 0 ? ret : 0;
> > +}
> > +EXPORT_SYMBOL_GPL(an8855_mii_set_page);
>
> You could keep the implementation more contained, and you could avoid
> exporting an8855_mii_set_page() and an8855_mfd_priv to the MDIO
> passthrough driver, if you implement a virtual regmap and give it to the
> MDIO passthrough child MFD device.
>
> If this bus supports only clause 22 accesses (and it looks like it does),
> you could expose a 16-bit regmap with a linear address space of 32 MDIO
> addresses x 65536 registers. The bus->read() of the MDIO bus passthrough
> just performs regmap_read(), and bus->write() just performs regmap_write().
> The MFD driver decodes the regmap address into a PHY address and a regnum,
> and performs the page switching locally, if needed.

Doesn't regmap add lots of overhead tho? Maybe I should really change
the switch regmap to apply a save/restore logic?

With an implementation like that current_page is not needed anymore.
And I feel additional read/write are ok for switch OP.

On mdio I can use the parent-mdio-bus property to get the bus directly
without using MFD priv.

What do you think?

--
Ansuel