Re: [RFC PATCH 0/2] Add software node support to regulator framework

From: Daniel Scally
Date: Mon Jul 12 2021 - 19:32:30 EST


Hi Mark - sorry for the late reply.

On 12/07/2021 18:01, Mark Brown wrote:
> On Mon, Jul 12, 2021 at 07:08:23PM +0300, Andy Shevchenko wrote:
>> On Mon, Jul 12, 2021 at 4:35 PM Mark Brown <broonie@xxxxxxxxxx> wrote:
>>> But why? I'm not seeing the advantage over providing platform data
>>> based on DMI quirks here, it seems like a bunch of work for no reason.
>> What do you mean by additional work? It's exactly opposite since most
>> of the drivers in the kernel are using the fwnode interface rather
>> than platform data. Why should we _add_ the specific platform data
>> handling code in the certain drivers instead of not touching them at
>> all?
> It's adding an entirely new representation of standard data with less
> validation support than either DT or platform data which seems like a
> needlessly roundabout and error prone way of moving the data about with
> less tooling support. As far as I can tell the only advantage is that
> it lets you write the quirk in a different source file but I'm finding
> it hard to get excited about that.


I do think it can simplify driver code too; a lot of them aren't written
to parse platform data to get the init data, as they're just relying on
reading it from devicetree so in the event that we get more cases like
this, we need to modify those drivers to look for platform data too. On
the other hand, even the drivers that don't directly call
of_get_regulator_init_data() still do that lookup during the
regulator_of_get_init_data() call in regulator_register(), so the ones
that do parse platform data for init_data structs will check DT as part
of regulator_register() anyway. Imitating that seems simpler to me.


It also creates some problems to suppress the enumeration of the i2c
device via ACPI (which we'll have to do in a machine specific fashion,
because some laptops have this chip with properly configured ACPI and
thus work fine as-is) to re-enumerate it in a board file with the
platform data; the ACPI methods and buffers are used by the i2c device's
driver; there's a bunch of regrettably non-standards-compliant
information in there that we need to check to make sure we do things
properly.


I take the point about this being error-prone lacking tooling support -
happy to work on this as much as needed to alleviate your concerns if we
decide to proceed down this route.


> If we were fixing up an existing
> ACPI binding or something this approach would make sense to me but it's
> making something entirely new out of whole cloth here.
>
> We already have generic platform data support for the regulator API so
> driver modifications would just be the DMI matching which is going to
> have to happen somewhere anyway, I don't see a huge win from putting
> them in one file rather than another. It should basically just boil
> down to being another data table, I imagine you could write a helper for
> it, or probably even come up with some generic thing that let you
> register a platform data/DMI combo independently of the driver to get it
> out of the driver code (looking more like the existing GPIO code which
> is already being used in another bit of this quirking).
>
> It feels like this should be making more use of existing stuff than it
> is. If you look at what the core part of the code does it's taking data
> which was provided by one part of the kernel in one set of C structs and
> parsing those into a struct init_data which is what the core actually
> wants to consume. This seems like an entirely redundant process, we
> should be able to just write the machine configuration into some struct
> init_datas and get that associated with the regulators without creating
> an otherwise entirely unused intermediate representation of the data.

The advantage of the GPIO lookups is there's no need to have the pointer
to the registered devices to register the lookup table; we could imitate
that, by adding entries to a list with the lookup values being device
and regulator name (with the init data as the thing that's "looked up")
and check for those during regulator_register() maybe?