Re: [RFC v5 net-next 01/13] mfd: ocelot: add support for external mfd control over SPI for the VSC7512

Colin Foster
2022-01-11T18:28:01Z

Hi Lee,

On Tue, Jan 11, 2022 at 05:00:11PM +0000, Lee Jones wrote:
> On Tue, 11 Jan 2022, Colin Foster wrote:
>
> > Hi Mark and Lee,
> >
> > >
> > > > However, even if that is required, I still think we can come up with
> > > > something cleaner than creating a whole API based around creating
> > > > and fetching different regmap configurations depending on how the
> > > > system was initialised.
> > >
> > > Yeah, I'd expect the usual pattern is to have wrapper drivers that
> > > instantiate a regmap then have the bulk of the driver be a library that
> > > they call into should work.
> >
> > Understood. And I think this can make sense and clean things up. The
> > "ocelot_core" mfd will register every regmap range, regardless of
> > whether any child actually uses them. Every child can then get regmaps
> > by name, via dev_get_regmap. That'll get rid of the back-and-forth
> > regmap hooks.
>
> I was under the impression that MFD would not always be used?
>
> Didn't you have a use-case where the child devices could be used
> independently of anything else?
>
> If not, why don't you just register a single Regmap covering the whole
> range? Then let the Regmap API deal with the concurrency handling.

That's exactly the use-case I was considering.

An example:
"mscc,ocelot-miim" exists. It can currently be used in two different
scenarios: directly with devicetree, or indirectly as in
drivers/net/dsa/ocelot/seville_vsc9953.c

mscc_miim_setup(dev, &bus, "VSC9953 internal MDIO bus",
ocelot->targets[GCB],
ocelot->map[GCB][GCB_MIIM_MII_STATUS & REG_MASK]);

The "GCB_MIIM_MII_STATUS" parameter is the offset from the base for that
regmap. See commit (b99658452355 "net: dsa: ocelot: felix: utilize
shared mscc-miim driver for indirect…")

(My apologies if the formatting of that commit refernece is incorrect)

But in that case... the Seville driver makes a devcpu_gcb regmap located
at 0x71070000. That regmap is created over the entire "GCB range". That
gets passed into the mscc-miim driver, along with the base register
location of the MIIM periperal.

At the same time, mscc-miim can be probed independently, at which point it
would create a smaller regmap at 0x7107009c
(Documentation/devicetree/bindings/mscc-miim.txt)

So the mscc-miim driver supports multiple use-cases. I expect the same
type of "offset" idea can be reasonably added to the following drivers,
all of which already exist but need to support the same type of
use-case:

mscc,ocelot-pinctrl, mscc,ocelot-sgpio, mscc,ocelot-miim, and
mscc,vsc7514-serdes. As I'm bringing up different parts of the hardware,
there might be more components that become necessary.

With the exception of vsc7514-serdes, those all exist outside of MFD.
The vsc7512-serdes driver currently relies on syscon / MFD, which adds a
different complexity. One that I think probably merits a separate probe
function.

>
> --
> Lee Jones [李琼斯]
> Principal Technical Lead - Developer Services
> Linaro.org │ Open source software for Arm SoCs
> Follow Linaro: Facebook | Twitter | Blog