Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Evgeny Boger and committed by
Sebastian Reichel
d4f408cd ba18dad0

+6 -7
+6 -7
drivers/power/supply/axp20x_battery.c
··· 186 186 union power_supply_propval *val) 187 187 { 188 188 struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy); 189 - struct iio_channel *chan; 190 189 int ret = 0, reg, val1; 191 190 192 191 switch (psp) { ··· 265 266 if (ret) 266 267 return ret; 267 268 268 - if (reg & AXP20X_PWR_STATUS_BAT_CHARGING) 269 - chan = axp20x_batt->batt_chrg_i; 270 - else 271 - chan = axp20x_batt->batt_dischrg_i; 272 - 273 - ret = iio_read_channel_processed(chan, &val->intval); 269 + if (reg & AXP20X_PWR_STATUS_BAT_CHARGING) { 270 + ret = iio_read_channel_processed(axp20x_batt->batt_chrg_i, &val->intval); 271 + } else { 272 + ret = iio_read_channel_processed(axp20x_batt->batt_dischrg_i, &val1); 273 + val->intval = -val1; 274 + } 274 275 if (ret) 275 276 return ret; 276 277