[PATCH 2/5] regulator: core: Use parent voltage from the supply when bypassed

From: Thierry Reding
Date: Thu Apr 07 2016 - 10:22:52 EST


From: Mark Brown <broonie@xxxxxxxxxx>

When a regulator is in bypass mode it is functioning as a switch
returning the voltage set in the regulator will not give the voltage
being output by the regulator as it's just passing through its supply.
This means that when we are getting the voltage from a regulator we
should check to see if it is in bypass mode and if it is we should
report the voltage from the supply rather than that which is set on the
regulator.

Reported-by: Jon Hunter <jonathanh@xxxxxxxxxx>
Signed-off-by: Mark Brown <broonie@xxxxxxxxxx>
[treding@xxxxxxxxxx: return early for bypass mode]
Signed-off-by: Thierry Reding <treding@xxxxxxxxxx>
---
drivers/regulator/core.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index cc0333a79924..23c8c4c86389 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -3118,6 +3118,20 @@ EXPORT_SYMBOL_GPL(regulator_sync_voltage);
static int _regulator_get_voltage(struct regulator_dev *rdev)
{
int sel, ret;
+ bool bypassed;
+
+ if (rdev->desc->ops->get_bypass) {
+ ret = rdev->desc->ops->get_bypass(rdev, &bypassed);
+ if (ret < 0)
+ return ret;
+ if (bypassed) {
+ /* if bypassed the regulator must have a supply */
+ if (!rdev->supply)
+ return -EINVAL;
+
+ return _regulator_get_voltage(rdev->supply->rdev);
+ }
+ }

if (rdev->desc->ops->get_voltage_sel) {
sel = rdev->desc->ops->get_voltage_sel(rdev);
--
2.8.0