Skip to content

Commit d4f408c

Browse files
evgeny-bogersre
authored andcommitted
power: supply: axp20x_battery: properly report current when discharging
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>
1 parent ba18dad commit d4f408c

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

drivers/power/supply/axp20x_battery.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ static int axp20x_battery_get_prop(struct power_supply *psy,
186186
union power_supply_propval *val)
187187
{
188188
struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy);
189-
struct iio_channel *chan;
190189
int ret = 0, reg, val1;
191190

192191
switch (psp) {
@@ -266,12 +265,12 @@ static int axp20x_battery_get_prop(struct power_supply *psy,
266265
if (ret)
267266
return ret;
268267

269-
if (reg & AXP20X_PWR_STATUS_BAT_CHARGING)
270-
chan = axp20x_batt->batt_chrg_i;
271-
else
272-
chan = axp20x_batt->batt_dischrg_i;
273-
274-
ret = iio_read_channel_processed(chan, &val->intval);
268+
if (reg & AXP20X_PWR_STATUS_BAT_CHARGING) {
269+
ret = iio_read_channel_processed(axp20x_batt->batt_chrg_i, &val->intval);
270+
} else {
271+
ret = iio_read_channel_processed(axp20x_batt->batt_dischrg_i, &val1);
272+
val->intval = -val1;
273+
}
275274
if (ret)
276275
return ret;
277276

0 commit comments

Comments
 (0)