Re: [PATCH] regulator: Defer init completion for a while after late_initcall

From: Mark Brown
Date: Mon Nov 18 2019 - 15:29:54 EST

On Mon, Nov 18, 2019 at 08:40:12PM +0100, Torsten Duwe wrote:
> On Mon, Nov 18, 2019 at 04:56:51PM +0000, Mark Brown wrote:

> > I don't follow at all, if a driver is calling regulator_get() and
> > regulator_put() repeatedly at runtime around voltage changes then it
> > sounds like the driver is extremely broken. Further, if a supply has a
> > regulator provided in device tree then a dummy regulator will never be
> > provided for it.

> I'm afraid I must object here:
> kernel: anx6345 0-0038: 0-0038 supply dvdd12-supply not found, using dummy regulator
> kernel: anx6345 0-0038: 0-0038 supply dvdd25-supply not found, using dummy regulator

> DT has:
> dvdd25-supply = <&reg_dldo2>;
> dvdd12-supply = <&reg_dldo3>;

> It's only that the regulator driver module has not fully loaded at that point.

We substitute in the dummy regulator in regulator_get() if
regulator_dev_lookup() returns -ENODEV and a few other conditions are
satisfied. When lookup up via DT regulator_dev_lookup() will use
of_find_regulator_by_node() to look up the regulator, if that lookup
fails it returns -EPROBE_DEFER. Until we get to of_find_regulator_by_node()
we're just looking to see if nodes exist, not to see if anything is
registered. What mechanism do you see causing issues? If there's
something going wrong here it's in that area.

> > > AFAICS the caller is then stuck with a reference to the dummy, correct?

> > If a dummy regulator has been provided then there is no possibility that
> > a real supply could be provided, there's not a firmware description of
> > one. We use a dummy regulator to keep software working on the basis
> > that it's unlikely that the device can operate without power but lacking
> > any information on the regulator we can't actually control it.

> That's what I figured. I was fancying some hash table for yet unkown
> regulators with callbacks to those who had asked. Or the EPROBE_DEFER
> to have them come back later. Maybe initrd barriers would help.

Like I've been saying attempts to get a regulator will defer unless the
core can confirm that the regulator can't be resolved.

I don't know what an initrd barrier is but anything that relies on
initrds not going to help with trying to figure out when userspace is
ready since there's no requirement for userspace to use an initrd at all
let alone put all modules in there.

> So is my understanding correct that with the above messages, the anx6345
> driver will never be able to control those voltages for real?
> And additionally, the real regulator's use count will remain 0 unless there
> are other users (which there aren't)?

If the consumer driver is gets a reference to the dummy regulator it's
going to continue to have a reference to the dummy regulator.

> Again: this all didn't matter before this init completion code was moved
> to the right location. Power management wouldn't work, but at least the
> established voltages stayed on.

As far as I can tell whatever is going on with your system it's only
ever been working through luck. Without any specific references to
what's going on in the system it's hard to tell what might be happening,
it looks like you're working with out of tree code here so it's possible
there's something going on in there and your use of non-standard
terminology makes it a bit hard to follow.

Attachment: signature.asc
Description: PGP signature