diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2009-07-21 17:00:24 +0200 |
---|---|---|
committer | Liam Girdwood <lrg@slimlogic.co.uk> | 2009-09-22 14:32:38 +0200 |
commit | a7a1ad9066e0266c8a4357ba3dbaeebfb80f531d (patch) | |
tree | 382d5c8a17a4dd44f3193274710caae7721881f8 | |
parent | regulator: Add regulator_get_exclusive() API (diff) | |
download | linux-a7a1ad9066e0266c8a4357ba3dbaeebfb80f531d.tar.xz linux-a7a1ad9066e0266c8a4357ba3dbaeebfb80f531d.zip |
regulator: Add regulator voltage range check API
Simplify checking of support for voltage ranges by providing an API which
wraps the existing count and list operations.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
-rw-r--r-- | drivers/regulator/core.c | 29 | ||||
-rw-r--r-- | include/linux/regulator/consumer.h | 2 |
2 files changed, 31 insertions, 0 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 68549008582c..e11c2222d9af 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1442,6 +1442,35 @@ int regulator_list_voltage(struct regulator *regulator, unsigned selector) EXPORT_SYMBOL_GPL(regulator_list_voltage); /** + * regulator_is_supported_voltage - check if a voltage range can be supported + * + * @regulator: Regulator to check. + * @min_uV: Minimum required voltage in uV. + * @max_uV: Maximum required voltage in uV. + * + * Returns a boolean or a negative error code. + */ +int regulator_is_supported_voltage(struct regulator *regulator, + int min_uV, int max_uV) +{ + int i, voltages, ret; + + ret = regulator_count_voltages(regulator); + if (ret < 0) + return ret; + voltages = ret; + + for (i = 0; i < voltages; i++) { + ret = regulator_list_voltage(regulator, i); + + if (ret >= min_uV && ret <= max_uV) + return 1; + } + + return 0; +} + +/** * regulator_set_voltage - set regulator output voltage * @regulator: regulator source * @min_uV: Minimum required voltage in uV diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index 976b57b6912c..490c5b37b6d7 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -146,6 +146,8 @@ void regulator_bulk_free(int num_consumers, int regulator_count_voltages(struct regulator *regulator); int regulator_list_voltage(struct regulator *regulator, unsigned selector); +int regulator_is_supported_voltage(struct regulator *regulator, + int min_uV, int max_uV); int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV); int regulator_get_voltage(struct regulator *regulator); int regulator_set_current_limit(struct regulator *regulator, |