regulator: core: repeat voltage setting request for stepped regulators
authorRomain Gantois <romain.gantois@bootlin.com>
Fri, 18 Jul 2025 14:11:36 +0000 (16:11 +0200)
committerMark Brown <broonie@kernel.org>
Fri, 18 Jul 2025 15:17:09 +0000 (16:17 +0100)
commitd511206dc7443120637efd9cfa3ab06a26da33dd
tree35ff4859d440ba5fe45553c9174be32cc9a5fd5d
parentef616b9763e374454957a8785a068479fa5665a6
regulator: core: repeat voltage setting request for stepped regulators

The regulator_set_voltage() function may exhibit unexpected behavior if the
target regulator has a maximum voltage step constraint. With such a
constraint, the regulator core may clamp the requested voltage to a lesser
value, to ensure that the voltage delta stays under the specified limit.

This means that the resulting regulator voltage depends on the current
voltage, as well as the requested range, which invalidates the assumption
that a repeated request for a specific voltage range will amount to a noop.

Considering the case of a regulator with a maximum voltage step constraint
of 1V:

initial voltage: 2.5V

consumer requests 4V
expected result: 3.5V
resulting voltage: 3.5V

consumer requests 4V again
expected result: 4V
actual result: 3.5V

Correct this by repeating attempts to balance the regulator voltage until
the result converges.

Signed-off-by: Romain Gantois <romain.gantois@bootlin.com>
Link: https://patch.msgid.link/20250718-regulator-stepping-v2-1-e28c9ac5d54a@bootlin.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/core.c