diff options
author | David Brownell <dbrownell@users.sourceforge.net> | 2008-11-16 14:46:56 -0500 |
---|---|---|
committer | Liam Girdwood <lrg@slimlogic.co.uk> | 2009-01-08 15:10:30 -0500 |
commit | e573520b171095c106ffbbbf4f9cbed6d9bff576 (patch) | |
tree | ab0d3b0e4adadcf6fc68915f7703048b4aea2a76 /drivers/regulator | |
parent | 412aec610559bdb602a0a21ce149ba8ffbb6f983 (diff) |
regulator: improved mode error checks
Minor bugfixes in handling of regulator modes:
- have the routine verifying regulator modes check against
the set of legal modes (!);
- have regulator_set_optimum_mode() verify the return value
of regulator_ops.get_optimum_mode(), like drms_uA_update();
- one call to regulator_ops.set_mode() treated zero as a
failure code; make this consistent with other callers.
Both regulator_set_mode() and regulator_set_optimum_mode() now
require valid_ops_mask to include REGULATOR_CHANGE_MODE; that
seems like a bugfix too.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/core.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index c2b7ec901036..686dfa990726 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -174,6 +174,16 @@ static int regulator_check_current_limit(struct regulator_dev *rdev, | |||
174 | /* operating mode constraint check */ | 174 | /* operating mode constraint check */ |
175 | static int regulator_check_mode(struct regulator_dev *rdev, int mode) | 175 | static int regulator_check_mode(struct regulator_dev *rdev, int mode) |
176 | { | 176 | { |
177 | switch (mode) { | ||
178 | case REGULATOR_MODE_FAST: | ||
179 | case REGULATOR_MODE_NORMAL: | ||
180 | case REGULATOR_MODE_IDLE: | ||
181 | case REGULATOR_MODE_STANDBY: | ||
182 | break; | ||
183 | default: | ||
184 | return -EINVAL; | ||
185 | } | ||
186 | |||
177 | if (!rdev->constraints) { | 187 | if (!rdev->constraints) { |
178 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, | 188 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, |
179 | rdev->desc->name); | 189 | rdev->desc->name); |
@@ -1494,7 +1504,8 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load) | |||
1494 | mode = rdev->desc->ops->get_optimum_mode(rdev, | 1504 | mode = rdev->desc->ops->get_optimum_mode(rdev, |
1495 | input_uV, output_uV, | 1505 | input_uV, output_uV, |
1496 | total_uA_load); | 1506 | total_uA_load); |
1497 | if (ret <= 0) { | 1507 | ret = regulator_check_mode(rdev, mode); |
1508 | if (ret < 0) { | ||
1498 | printk(KERN_ERR "%s: failed to get optimum mode for %s @" | 1509 | printk(KERN_ERR "%s: failed to get optimum mode for %s @" |
1499 | " %d uA %d -> %d uV\n", __func__, rdev->desc->name, | 1510 | " %d uA %d -> %d uV\n", __func__, rdev->desc->name, |
1500 | total_uA_load, input_uV, output_uV); | 1511 | total_uA_load, input_uV, output_uV); |
@@ -1502,7 +1513,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load) | |||
1502 | } | 1513 | } |
1503 | 1514 | ||
1504 | ret = rdev->desc->ops->set_mode(rdev, mode); | 1515 | ret = rdev->desc->ops->set_mode(rdev, mode); |
1505 | if (ret <= 0) { | 1516 | if (ret < 0) { |
1506 | printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n", | 1517 | printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n", |
1507 | __func__, mode, rdev->desc->name); | 1518 | __func__, mode, rdev->desc->name); |
1508 | goto out; | 1519 | goto out; |