[PATCH] regulator: don't fail to apply_uV for fixed regulators without set_voltage

From: Stephen Warren
Date: Tue Jul 03 2012 - 18:03:36 EST


From: Stephen Warren <swarren@xxxxxxxxxx>

When instantiating a regulator from device tree,
of_get_regulation_constraints() sets apply_uV=true when min_uV==max_uV.
If the regulator only supports that one voltage, it may not implement
set_voltage or set_voltage_sel. If so, the call from
machine_constraints_voltage() to _regulator_do_set_voltage() will fail,
since the latter requires one of those ops to be implemented. Avoid this
problem by avoiding the call to _regulator_do_set_voltage() if the
regulator is already set of the specified voltage.

Signed-off-by: Stephen Warren <swarren@xxxxxxxxxx>
---
Are regulators required to implement get_voltage()? If not, this change
would cause a regression.

An alternative might be to just implement set_voltage*() in the relevant
regulator driver, although it seem like it'd intended to be optional.
Would that be preferable? The driver in question is for the MAX8907 which
isn't upstream yet, but I'll be sending patches for it as soon as I have
legal approval; the code is written and working.

drivers/regulator/core.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index ef07b62..8196764 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -790,7 +790,8 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,

/* do we need to apply the constraint voltage */
if (rdev->constraints->apply_uV &&
- rdev->constraints->min_uV == rdev->constraints->max_uV) {
+ rdev->constraints->min_uV == rdev->constraints->max_uV &&
+ _regulator_get_voltage(rdev) != rdev->constraints->min_uV) {
ret = _regulator_do_set_voltage(rdev,
rdev->constraints->min_uV,
rdev->constraints->max_uV);
--
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/