Commit b13296d0 authored by Axel Lin's avatar Axel Lin Committed by Mark Brown

regulator: ab3100: Use regulator_map_voltage_iterate()

regulator_map_voltage_iterate() is for drivers implementing set_voltage_sel()
and list_voltage() to use it as their map_voltage() operation.

In this case, regulator_map_voltage_iterate() happen to be doing the same thing
as ab3100_get_best_voltage_index() function. So we can use it to replace
ab3100_get_best_voltage_index() function.
Signed-off-by: default avatarAxel Lin <axel.lin@gmail.com>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 8b22285f
...@@ -304,39 +304,6 @@ static int ab3100_get_voltage_regulator(struct regulator_dev *reg) ...@@ -304,39 +304,6 @@ static int ab3100_get_voltage_regulator(struct regulator_dev *reg)
return abreg->typ_voltages[regval]; return abreg->typ_voltages[regval];
} }
static int ab3100_get_best_voltage_index(struct regulator_dev *reg,
int min_uV, int max_uV)
{
struct ab3100_regulator *abreg = reg->reg_data;
int i;
int bestmatch;
int bestindex;
/*
* Locate the minimum voltage fitting the criteria on
* this regulator. The switchable voltages are not
* in strict falling order so we need to check them
* all for the best match.
*/
bestmatch = INT_MAX;
bestindex = -1;
for (i = 0; i < abreg->voltages_len; i++) {
if (abreg->typ_voltages[i] <= max_uV &&
abreg->typ_voltages[i] >= min_uV &&
abreg->typ_voltages[i] < bestmatch) {
bestmatch = abreg->typ_voltages[i];
bestindex = i;
}
}
if (bestindex < 0) {
dev_warn(&reg->dev, "requested %d<=x<=%d uV, out of range!\n",
min_uV, max_uV);
return -EINVAL;
}
return bestindex;
}
static int ab3100_set_voltage_regulator_sel(struct regulator_dev *reg, static int ab3100_set_voltage_regulator_sel(struct regulator_dev *reg,
unsigned selector) unsigned selector)
{ {
...@@ -383,7 +350,7 @@ static int ab3100_set_suspend_voltage_regulator(struct regulator_dev *reg, ...@@ -383,7 +350,7 @@ static int ab3100_set_suspend_voltage_regulator(struct regulator_dev *reg,
return -EINVAL; return -EINVAL;
/* LDO E and BUCK have special suspend voltages you can set */ /* LDO E and BUCK have special suspend voltages you can set */
bestindex = ab3100_get_best_voltage_index(reg, uV, uV); bestindex = regulator_map_voltage_iterate(reg, uV, uV);
err = abx500_get_register_interruptible(abreg->dev, 0, err = abx500_get_register_interruptible(abreg->dev, 0,
targetreg, &regval); targetreg, &regval);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment