Re: [PATCH v4 02/11] mfd: Add support for Kontron sl28cpld management controller

From: Michael Walle
Date: Wed Jun 10 2020 - 03:11:14 EST


Am 2020-06-09 21:45, schrieb Lee Jones:
On Tue, 09 Jun 2020, Michael Walle wrote:

Am 2020-06-09 17:19, schrieb Lee Jones:
> On Tue, 09 Jun 2020, Michael Walle wrote:
>
> > Am 2020-06-09 08:47, schrieb Lee Jones:
> > > On Mon, 08 Jun 2020, Michael Walle wrote:
> > >
> > > > Am 2020-06-08 20:56, schrieb Lee Jones:
> > > > > On Mon, 08 Jun 2020, Michael Walle wrote:
> > > > >
> > > > > > Am 2020-06-08 12:02, schrieb Andy Shevchenko:
> > > > > > > +Cc: some Intel people WRT our internal discussion about similar
> > > > > > > problem and solutions.
> > > > > > >
> > > > > > > On Mon, Jun 8, 2020 at 11:30 AM Lee Jones <lee.jones@xxxxxxxxxx> wrote:
> > > > > > > > On Sat, 06 Jun 2020, Michael Walle wrote:
> > > > > > > > > Am 2020-06-06 13:46, schrieb Mark Brown:
> > > > > > > > > > On Fri, Jun 05, 2020 at 10:07:36PM +0200, Michael Walle wrote:
> > > > > > > > > > > Am 2020-06-05 12:50, schrieb Mark Brown:
> > > > > > >
> > > > > > > ...
> > > > > > >
> > > > > > > > Right. I'm suggesting a means to extrapolate complex shared and
> > > > > > > > sometimes intertwined batches of register sets to be consumed by
> > > > > > > > multiple (sub-)devices spanning different subsystems.
> > > > > > > >
> > > > > > > > Actually scrap that. The most common case I see is a single Regmap
> > > > > > > > covering all child-devices.
> > > > > > >
> > > > > > > Yes, because often we need a synchronization across the entire address
> > > > > > > space of the (parent) device in question.
> > > > > > >
> > > > > > > > It would be great if there was a way in
> > > > > > > > which we could make an assumption that the entire register address
> > > > > > > > space for a 'tagged' (MFD) device is to be shared (via Regmap) between
> > > > > > > > each of the devices described by its child-nodes. Probably by picking
> > > > > > > > up on the 'simple-mfd' compatible string in the first instance.
> > > > > > > >
> > > > > > > > Rob, is the above something you would contemplate?
> > > > > > > >
> > > > > > > > Michael, do your register addresses overlap i.e. are they intermingled
> > > > > > > > with one another? Do multiple child devices need access to the same
> > > > > > > > registers i.e. are they shared?
> > > > > >
> > > > > > No they don't overlap, expect for maybe the version register, which is
> > > > > > just there once and not per function block.
> > > > >
> > > > > Then what's stopping you having each device Regmap their own space?
> > > >
> > > > Because its just one I2C device, AFAIK thats not possible, right?
> > >
> > > Not sure what (if any) the restrictions are.
> >
> > You can only have one device per I2C address. Therefore, I need one
> > device
> > which is enumerated by the I2C bus, which then enumerates its
> > sub-devices.
> > I thought this was one of the use cases for MFD. (Regardless of how a
> > sub-device access its registers). So even in the "simple-regmap"
> > case this
> > would need to be an i2c device.

Here (see below)

Yes, it should still be an I2C device.

> >
> > E.g.
> >
> > &i2cbus {
> > mfd-device@10 {
> > compatible = "simple-regmap", "simple-mfd";
> > reg = <10>;
> > regmap,reg-bits = <8>;
> > regmap,val-bits = <8>;
> > sub-device@0 {
> > compatible = "vendor,sub-device0";
> > reg = <0>;
> > };
> > ...
> > };
> >
> > Or if you just want the regmap:
> >
> > &soc {
> > regmap: regmap@fff0000 {
> > compatible = "simple-regmap";
> > reg = <0xfff0000>;
> > regmap,reg-bits = <16>;
> > regmap,val-bits = <32>;
> > };
> >
> > enet-which-needs-syscon-too@1000000 {
> > vendor,ctrl-regmap = <&regmap>;
> > };
> > };
> >
> > Similar to the current syscon (which is MMIO only..).
>
> We do not need a 'simple-regmap' solution for your use-case.
>
> Since your device's registers are segregated, just split up the
> register map and allocate each sub-device with it's own slice.

I don't get it, could you make a device tree example for my
use-case? (see also above)

&i2cbus {
mfd-device@10 {
compatible = "simple-mfd";
reg = <10>;

sub-device@10 {
compatible = "vendor,sub-device";
reg = <10>;
};
};

The Regmap config would be present in each of the child devices.

Each child device would call devm_regmap_init_i2c() in .probe().

Ah, I see. If I'm not wrong, this still means to create an i2c
device driver with the name "simple-mfd".

Besides that, I don't like this, because:
- Rob already expressed its concerns with "simple-mfd" and so on.
- you need to duplicate the config in each sub device
- which also means you are restricting the sub devices to be
i2c only (unless you implement and duplicate other regmap configs,
too). For this driver, SPI and MMIO may be viable options.

Thus, I'd rather implement a simple-mfd.c which implement a common
I2C driver for now and populate its children using
devm_of_platform_populate(). This could be extended to support other
type of regmaps like SPI in the future.

Also some MFD drivers could be moved to this, a likely candidate is
the smsc-ece1099.c. Although I don't really understand its purpose,
if don't have CONFIG_OF.

Judging from the existing code, this simple-mfd.c wouldn't just be
"a list of compatible" strings but also additional quirks and tweaks
for particular devices in this list.

-michael