Skip to content

Commit

Permalink
power: supply: axp20x_battery: properly report current when discharging
Browse files Browse the repository at this point in the history
As stated in [1], negative current values are used for discharging
batteries.

AXP PMICs internally have two different ADC channels for shunt current
measurement: one used during charging and one during discharging.
The values reported by these ADCs are unsigned.
While the driver properly selects ADC channel to get the data from,
it doesn't apply negative sign when reporting discharging current.

[1] Documentation/ABI/testing/sysfs-class-power

Signed-off-by: Evgeny Boger <boger@wirenboard.com>
Acked-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
  • Loading branch information
Evgeny Boger authored and Sebastian Reichel committed Feb 1, 2022
1 parent ba18dad commit d4f408c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions drivers/power/supply/axp20x_battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ static int axp20x_battery_get_prop(struct power_supply *psy,
union power_supply_propval *val)
{
struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy);
struct iio_channel *chan;
int ret = 0, reg, val1;

switch (psp) {
Expand Down Expand Up @@ -266,12 +265,12 @@ static int axp20x_battery_get_prop(struct power_supply *psy,
if (ret)
return ret;

if (reg & AXP20X_PWR_STATUS_BAT_CHARGING)
chan = axp20x_batt->batt_chrg_i;
else
chan = axp20x_batt->batt_dischrg_i;

ret = iio_read_channel_processed(chan, &val->intval);
if (reg & AXP20X_PWR_STATUS_BAT_CHARGING) {
ret = iio_read_channel_processed(axp20x_batt->batt_chrg_i, &val->intval);
} else {
ret = iio_read_channel_processed(axp20x_batt->batt_dischrg_i, &val1);
val->intval = -val1;
}
if (ret)
return ret;

Expand Down

0 comments on commit d4f408c

Please sign in to comment.