Skip to content

Commit

Permalink
power: supply: axp288_fuel_gauge: Optimize get_current()
Browse files Browse the repository at this point in the history
First check the discharge current, and when that is non 0 use that without
also checking the charge current (which will be 0 then). This makes
get_current() do only 1 i2c read instead of 2 when on battery.

This is esp. important given the pmic i2c bus mutex stuff used on boards
with an axp288 because the SoC's own punit also may access the axp288,
which makes i2c accesses more expensive then normal.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
  • Loading branch information
Hans de Goede authored and Sebastian Reichel committed Jan 9, 2018
1 parent 2b5a4b4 commit ceb4083
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions drivers/power/supply/axp288_fuel_gauge.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,24 +386,19 @@ static int fuel_gauge_get_vbatt(struct axp288_fg_info *info, int *vbatt)

static int fuel_gauge_get_current(struct axp288_fg_info *info, int *cur)
{
int ret, value = 0;
int charge, discharge;
int ret, discharge;

ret = iio_read_channel_raw(info->iio_channel[BAT_CHRG_CURR], &charge);
if (ret < 0)
goto current_read_fail;
/* First check discharge current, so that we do only 1 read on bat. */
ret = iio_read_channel_raw(info->iio_channel[BAT_D_CURR], &discharge);
if (ret < 0)
goto current_read_fail;
return ret;

if (charge > 0)
value = charge;
else if (discharge > 0)
value = -1 * discharge;
if (discharge > 0) {
*cur = -1 * discharge;
return 0;
}

*cur = value;
current_read_fail:
return ret;
return iio_read_channel_raw(info->iio_channel[BAT_CHRG_CURR], cur);
}

static int fuel_gauge_get_vocv(struct axp288_fg_info *info, int *vocv)
Expand Down

0 comments on commit ceb4083

Please sign in to comment.