Skip to content

Commit 1bb83a4

Browse files
evgeny-bogersmb49
authored andcommitted
power: supply: axp20x_battery: properly report current when discharging
BugLink: https://bugs.launchpad.net/bugs/1971497 [ Upstream commit d4f408c ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent da9b450 commit 1bb83a4

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
@@ -185,7 +185,6 @@ static int axp20x_battery_get_prop(struct power_supply *psy,
185185
union power_supply_propval *val)
186186
{
187187
struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy);
188-
struct iio_channel *chan;
189188
int ret = 0, reg, val1;
190189

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

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);
267+
if (reg & AXP20X_PWR_STATUS_BAT_CHARGING) {
268+
ret = iio_read_channel_processed(axp20x_batt->batt_chrg_i, &val->intval);
269+
} else {
270+
ret = iio_read_channel_processed(axp20x_batt->batt_dischrg_i, &val1);
271+
val->intval = -val1;
272+
}
274273
if (ret)
275274
return ret;
276275

0 commit comments

Comments
 (0)