Skip to content

Commit 5584119

Browse files
diandersbroonie
authored andcommitted
regulator: core: Require regulator drivers to check uV for get_optimum_mode()
The get_optimum_mode() for regulator drivers is passed the input voltage and output voltage as well as the current. This is because, in theory, the optimum mode can depend on all three things. It turns out that for all regulator drivers in mainline only the current is looked at when implementing get_optimum_mode(). None of the drivers take the input or output voltage into account. Despite the fact that none of the drivers take the input or output voltage into account, though, the regulator framework will error out before calling into get_optimum_mode() if it doesn't know the input or output voltage. The above behavior turned out to be a probelm for some boards when we landed commit efb0cb5 ("regulator: qcom-rpmh: Implement get_optimum_mode(), not set_load()"). Before that change we'd have no problems running drms_uA_update() for RPMH regulators even if a regulator's input or output voltage was unknown. After that change drms_uA_update() started to fail. This is because typically boards using RPMH regulators don't model the input supplies of RPMH regulators. Input supplies for RPMH regulators nearly always come from the output of other RPMH regulators (or always-on regulators) and RPMH firmware is initialized with this knowledge and handles enabling (and adjusting the voltage of) input supplies. While we could model the parent/child relationship of the regulators in Linux, many boards don't bother since it adds extra overhead. Let's change the regulator core to make things work again. Now if we fail to get the input or output voltage we'll still call into get_optimum_mode() and we'll just pass error codes in for input_uV and/or output_uV parameters. Since no existing regulator drivers even look at input_uV and output_uV we don't need to add this error handling anywhere right now. We'll add some comments in the core so that it's obvious that (if regulator drivers care) it's up to them to add the checks. Reported-by: Andrew Halaney <[email protected]> Fixes: efb0cb5 ("regulator: qcom-rpmh: Implement get_optimum_mode(), not set_load()") Signed-off-by: Douglas Anderson <[email protected]> Tested-by: Andrew Halaney <[email protected]> Link: https://lore.kernel.org/r/20220824142229.RFT.v2.1.I137e6bef4f6d517be7b081be926059321102fd3d@changeid Signed-off-by: Mark Brown <[email protected]>
1 parent d46f737 commit 5584119

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

drivers/regulator/core.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -979,21 +979,27 @@ static int drms_uA_update(struct regulator_dev *rdev)
979979
} else {
980980
/* get output voltage */
981981
output_uV = regulator_get_voltage_rdev(rdev);
982-
if (output_uV <= 0) {
983-
rdev_err(rdev, "invalid output voltage found\n");
984-
return -EINVAL;
985-
}
982+
983+
/*
984+
* Don't return an error; if regulator driver cares about
985+
* output_uV then it's up to the driver to validate.
986+
*/
987+
if (output_uV <= 0)
988+
rdev_dbg(rdev, "invalid output voltage found\n");
986989

987990
/* get input voltage */
988991
input_uV = 0;
989992
if (rdev->supply)
990993
input_uV = regulator_get_voltage(rdev->supply);
991994
if (input_uV <= 0)
992995
input_uV = rdev->constraints->input_uV;
993-
if (input_uV <= 0) {
994-
rdev_err(rdev, "invalid input voltage found\n");
995-
return -EINVAL;
996-
}
996+
997+
/*
998+
* Don't return an error; if regulator driver cares about
999+
* input_uV then it's up to the driver to validate.
1000+
*/
1001+
if (input_uV <= 0)
1002+
rdev_dbg(rdev, "invalid input voltage found\n");
9971003

9981004
/* now get the optimum mode for our new total regulator load */
9991005
mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV,

0 commit comments

Comments
 (0)