regulator: core: Resolve supply name earlier to prevent double-init
authorChristian Kohlschütter <christian@kohlschutter.com>
Thu, 18 Aug 2022 12:46:47 +0000 (12:46 +0000)
committerMark Brown <broonie@kernel.org>
Thu, 18 Aug 2022 14:02:07 +0000 (15:02 +0100)
commit8a866d527ac0441c0eb14a991fa11358b476b11d
tree111b2fe8e387d492e27a1db1d3d857826e9ff5e2
parentee94aff2628b18afdb0b6b175e568657bdaead59
regulator: core: Resolve supply name earlier to prevent double-init

Previously, an unresolved regulator supply reference upon calling
regulator_register on an always-on or boot-on regulator caused
set_machine_constraints to be called twice.

This in turn may initialize the regulator twice, leading to voltage
glitches that are timing-dependent. A simple, unrelated configuration
change may be enough to hide this problem, only to be surfaced by
chance.

One such example is the SD-Card voltage regulator in a NanoPI R4S that
would not initialize reliably unless the registration flow was just
complex enough to allow the regulator to properly reset between calls.

Fix this by re-arranging regulator_register, trying resolve the
regulator's supply early enough that set_machine_constraints does not
need to be called twice.

Signed-off-by: Christian Kohlschütter <christian@kohlschutter.com>
Link: https://lore.kernel.org/r/20220818124646.6005-1-christian@kohlschutter.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/core.c