regulator: Take into account the requirements of all consumers

Extend the regulator_set_voltage() function to take into account the
voltage requirements of all consumers of the regulator being changed,
in order to set the voltage to the minimum voltage acceptable to all
consumers. The existing behaviour was that the latest
regulator_set_voltage() call would win over previous
regulator_set_voltage() calls even if setting the voltage to a
non-acceptable level from other consumers.

Signed-off-by: Thomas Petazzoni <t-petazzoni@ti.com>
Cc: Liam Girdwood <lrg@slimlogic.co.uk>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Kevin Hilman <khilman@deeprootsystems.com>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
This commit is contained in:
Thomas Petazzoni 2010-12-03 11:31:07 +01:00 committed by Liam Girdwood
parent 5da84fd99b
commit 05fda3b1ab
1 changed files with 25 additions and 0 deletions

View File

@ -142,6 +142,27 @@ static int regulator_check_voltage(struct regulator_dev *rdev,
return 0;
}
/* Make sure we select a voltage that suits the needs of all
* regulator consumers
*/
static int regulator_check_consumers(struct regulator_dev *rdev,
int *min_uV, int *max_uV)
{
struct regulator *regulator;
list_for_each_entry(regulator, &rdev->consumer_list, list) {
if (*max_uV > regulator->max_uV)
*max_uV = regulator->max_uV;
if (*min_uV < regulator->min_uV)
*min_uV = regulator->min_uV;
}
if (*min_uV > *max_uV)
return -EINVAL;
return 0;
}
/* current constraint check */
static int regulator_check_current_limit(struct regulator_dev *rdev,
int *min_uA, int *max_uA)
@ -1637,6 +1658,10 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
regulator->min_uV = min_uV;
regulator->max_uV = max_uV;
ret = regulator_check_consumers(rdev, &min_uV, &max_uV);
if (ret < 0)
goto out;
trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV);
ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, &selector);