Skip to content

Commit

Permalink
regulator: da9063: Optimize da9063_set_current_limit implementation
Browse files Browse the repository at this point in the history
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: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
  • Loading branch information
Axel Lin authored and Mark Brown committed Aug 30, 2013
1 parent 69ca3e5 commit 556dcf9
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions drivers/regulator/da9063-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,15 @@ static int da9063_set_current_limit(struct regulator_dev *rdev,
{
struct da9063_regulator *regl = rdev_get_drvdata(rdev);
const struct da9063_regulator_info *rinfo = regl->info;
int val = INT_MAX;
unsigned sel = 0;
int n;
int tval;
int n, tval;

for (n = 0; n < rinfo->n_current_limits; n++) {
tval = rinfo->current_limits[n];
if (tval >= min_uA && tval <= max_uA && val > tval) {
val = tval;
sel = n;
}
if (tval >= min_uA && tval <= max_uA)
return regmap_field_write(regl->ilimit, 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)
Expand Down

0 comments on commit 556dcf9

Please sign in to comment.