aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2011-03-29 17:29:12 -0400
committerLiam Girdwood <lrg@slimlogic.co.uk>2011-05-27 05:34:35 -0400
commit2c6082341d1896218ca974cc2bb6876e36fcba5c (patch)
treef5ca00b3402eb36a0581c4481787ede5a4be5c72 /drivers/regulator
parentdc7acbb2518f250050179c8581a972df3b6a24f1 (diff)
regulator: When constraining modes fall back to higher power modes
If a mode requested by a consumer is not allowed by constraints automatically fall back to a higher power mode if possible. This ensures that consumers get at least the output they requested while allowing machine drivers to transparently limit lower power modes if required. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/core.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 0fae51c4845..7104404a9fa 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -197,9 +197,9 @@ static int regulator_check_current_limit(struct regulator_dev *rdev,
197} 197}
198 198
199/* operating mode constraint check */ 199/* operating mode constraint check */
200static int regulator_check_mode(struct regulator_dev *rdev, int mode) 200static int regulator_mode_constrain(struct regulator_dev *rdev, int *mode)
201{ 201{
202 switch (mode) { 202 switch (*mode) {
203 case REGULATOR_MODE_FAST: 203 case REGULATOR_MODE_FAST:
204 case REGULATOR_MODE_NORMAL: 204 case REGULATOR_MODE_NORMAL:
205 case REGULATOR_MODE_IDLE: 205 case REGULATOR_MODE_IDLE:
@@ -217,11 +217,17 @@ static int regulator_check_mode(struct regulator_dev *rdev, int mode)
217 rdev_err(rdev, "operation not allowed\n"); 217 rdev_err(rdev, "operation not allowed\n");
218 return -EPERM; 218 return -EPERM;
219 } 219 }
220 if (!(rdev->constraints->valid_modes_mask & mode)) { 220
221 rdev_err(rdev, "invalid mode %x\n", mode); 221 /* The modes are bitmasks, the most power hungry modes having
222 return -EINVAL; 222 * the lowest values. If the requested mode isn't supported
223 * try higher modes. */
224 while (*mode) {
225 if (rdev->constraints->valid_modes_mask & *mode)
226 return 0;
227 *mode /= 2;
223 } 228 }
224 return 0; 229
230 return -EINVAL;
225} 231}
226 232
227/* dynamic regulator mode switching constraint check */ 233/* dynamic regulator mode switching constraint check */
@@ -612,7 +618,7 @@ static void drms_uA_update(struct regulator_dev *rdev)
612 output_uV, current_uA); 618 output_uV, current_uA);
613 619
614 /* check the new mode is allowed */ 620 /* check the new mode is allowed */
615 err = regulator_check_mode(rdev, mode); 621 err = regulator_mode_constrain(rdev, &mode);
616 if (err == 0) 622 if (err == 0)
617 rdev->desc->ops->set_mode(rdev, mode); 623 rdev->desc->ops->set_mode(rdev, mode);
618} 624}
@@ -2005,7 +2011,7 @@ int regulator_set_mode(struct regulator *regulator, unsigned int mode)
2005 } 2011 }
2006 2012
2007 /* constraints check */ 2013 /* constraints check */
2008 ret = regulator_check_mode(rdev, mode); 2014 ret = regulator_mode_constrain(rdev, mode);
2009 if (ret < 0) 2015 if (ret < 0)
2010 goto out; 2016 goto out;
2011 2017
@@ -2116,7 +2122,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
2116 mode = rdev->desc->ops->get_optimum_mode(rdev, 2122 mode = rdev->desc->ops->get_optimum_mode(rdev,
2117 input_uV, output_uV, 2123 input_uV, output_uV,
2118 total_uA_load); 2124 total_uA_load);
2119 ret = regulator_check_mode(rdev, mode); 2125 ret = regulator_mode_constrain(rdev, &mode);
2120 if (ret < 0) { 2126 if (ret < 0) {
2121 rdev_err(rdev, "failed to get optimum mode @ %d uA %d -> %d uV\n", 2127 rdev_err(rdev, "failed to get optimum mode @ %d uA %d -> %d uV\n",
2122 total_uA_load, input_uV, output_uV); 2128 total_uA_load, input_uV, output_uV);