Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f24efe2 authored by Evgeny Boger's avatar Evgeny Boger Committed by Greg Kroah-Hartman
Browse files

power: supply: axp20x_battery: properly report current when discharging



[ Upstream commit d4f408cdcd26921c1268cb8dcbe8ffb6faf837f3 ]

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: default avatarEvgeny Boger <boger@wirenboard.com>
Acked-by: default avatarChen-Yu Tsai <wens@csie.org>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 3575fa75
Loading
Loading
Loading
Loading
+6 −7
Original line number Original line Diff line number Diff line
@@ -185,7 +185,6 @@ static int axp20x_battery_get_prop(struct power_supply *psy,
				   union power_supply_propval *val)
				   union power_supply_propval *val)
{
{
	struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy);
	struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy);
	struct iio_channel *chan;
	int ret = 0, reg, val1;
	int ret = 0, reg, val1;


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


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

			val->intval = -val1;
		ret = iio_read_channel_processed(chan, &val->intval);
		}
		if (ret)
		if (ret)
			return ret;
			return ret;