diff options
-rw-r--r-- | drivers/regulator/core.c | 31 | ||||
-rw-r--r-- | include/linux/regulator/driver.h | 2 |
2 files changed, 33 insertions, 0 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index e3661c20cf38..56f4ca0854c9 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2138,6 +2138,37 @@ int regulator_map_voltage_iterate(struct regulator_dev *rdev, EXPORT_SYMBOL_GPL(regulator_map_voltage_iterate); /** + * regulator_map_voltage_ascend - map_voltage() for ascendant voltage list + * + * @rdev: Regulator to operate on + * @min_uV: Lower bound for voltage + * @max_uV: Upper bound for voltage + * + * Drivers that have ascendant voltage list can use this as their + * map_voltage() operation. + */ +int regulator_map_voltage_ascend(struct regulator_dev *rdev, + int min_uV, int max_uV) +{ + int i, ret; + + for (i = 0; i < rdev->desc->n_voltages; i++) { + ret = rdev->desc->ops->list_voltage(rdev, i); + if (ret < 0) + continue; + + if (ret > max_uV) + break; + + if (ret >= min_uV && ret <= max_uV) + return i; + } + + return -EINVAL; +} +EXPORT_SYMBOL_GPL(regulator_map_voltage_ascend); + +/** * regulator_map_voltage_linear - map_voltage() for simple linear mappings * * @rdev: Regulator to operate on diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 7df93f52db08..2acdc66f8342 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -329,6 +329,8 @@ int regulator_map_voltage_linear(struct regulator_dev *rdev, int min_uV, int max_uV); int regulator_map_voltage_iterate(struct regulator_dev *rdev, int min_uV, int max_uV); +int regulator_map_voltage_ascend(struct regulator_dev *rdev, + int min_uV, int max_uV); int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev); int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel); int regulator_is_enabled_regmap(struct regulator_dev *rdev); |