提交 556dcf90 编写于 作者: A Axel Lin 提交者: Mark Brown

regulator: da9063: Optimize da9063_set_current_limit implementation

All the current limit tables have the values in ascend order.
So we can slightly optimize the for loop iteration because the first match
is the minimal value.
Signed-off-by: NAxel Lin <axel.lin@ingics.com>
Signed-off-by: NMark Brown <broonie@linaro.org>
上级 69ca3e58
...@@ -166,22 +166,15 @@ static int da9063_set_current_limit(struct regulator_dev *rdev, ...@@ -166,22 +166,15 @@ static int da9063_set_current_limit(struct regulator_dev *rdev,
{ {
struct da9063_regulator *regl = rdev_get_drvdata(rdev); struct da9063_regulator *regl = rdev_get_drvdata(rdev);
const struct da9063_regulator_info *rinfo = regl->info; const struct da9063_regulator_info *rinfo = regl->info;
int val = INT_MAX; int n, tval;
unsigned sel = 0;
int n;
int tval;
for (n = 0; n < rinfo->n_current_limits; n++) { for (n = 0; n < rinfo->n_current_limits; n++) {
tval = rinfo->current_limits[n]; tval = rinfo->current_limits[n];
if (tval >= min_uA && tval <= max_uA && val > tval) { if (tval >= min_uA && tval <= max_uA)
val = tval; return regmap_field_write(regl->ilimit, n);
sel = n;
}
} }
if (val == INT_MAX)
return -EINVAL;
return regmap_field_write(regl->ilimit, sel); return -EINVAL;
} }
static int da9063_get_current_limit(struct regulator_dev *rdev) static int da9063_get_current_limit(struct regulator_dev *rdev)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册