Skip to content

Commit

Permalink
power/supply: ingenic-battery: Don't change scale if there's only one
Browse files Browse the repository at this point in the history
commit 86b9182 upstream.

The ADC in the JZ4740 can work either in high-precision mode with a 2.5V
range, or in low-precision mode with a 7.5V range. The code in place in
this driver will select the proper scale according to the maximum
voltage of the battery.

The JZ4770 however only has one mode, with a 6.6V range. If only one
scale is available, there's no need to change it (and nothing to change
it to), and trying to do so will fail with -EINVAL.

Fixes: fb24ccf ("power: supply: add Ingenic JZ47xx battery driver.")

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Acked-by: Artur Rojek <contact@artur-rojek.eu>
Cc: stable@vger.kernel.org
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Paul Cercueil authored and Greg Kroah-Hartman committed Feb 1, 2020
1 parent 3a9c778 commit a1d58ba
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions drivers/power/supply/ingenic-battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,17 @@ static int ingenic_battery_set_scale(struct ingenic_battery *bat)
return -EINVAL;
}

return iio_write_channel_attribute(bat->channel,
scale_raw[best_idx],
scale_raw[best_idx + 1],
IIO_CHAN_INFO_SCALE);
/* Only set scale if there is more than one (fractional) entry */
if (scale_len > 2) {
ret = iio_write_channel_attribute(bat->channel,
scale_raw[best_idx],
scale_raw[best_idx + 1],
IIO_CHAN_INFO_SCALE);
if (ret)
return ret;
}

return 0;
}

static enum power_supply_property ingenic_battery_properties[] = {
Expand Down

0 comments on commit a1d58ba

Please sign in to comment.