All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] power: supply: axp20x_battery: properly report current when discharging
@ 2022-01-12  8:47 Evgeny Boger
  2022-01-13 13:58 ` Chen-Yu Tsai
  0 siblings, 1 reply; 2+ messages in thread
From: Evgeny Boger @ 2022-01-12  8:47 UTC (permalink / raw)
  To: Chen-Yu Tsai, linux-pm, Quentin Schulz
  Cc: Evgeny Boger, Sebastian Reichel, Hermann Lauer

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>
---
Changes from v1:
 * fix formatting, no other changes

 drivers/power/supply/axp20x_battery.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
index 5d197141f476..9106077c0dbb 100644
--- a/drivers/power/supply/axp20x_battery.c
+++ b/drivers/power/supply/axp20x_battery.c
@@ -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) {
@@ -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;
 
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] power: supply: axp20x_battery: properly report current when discharging
  2022-01-12  8:47 [PATCH v2] power: supply: axp20x_battery: properly report current when discharging Evgeny Boger
@ 2022-01-13 13:58 ` Chen-Yu Tsai
  0 siblings, 0 replies; 2+ messages in thread
From: Chen-Yu Tsai @ 2022-01-13 13:58 UTC (permalink / raw)
  To: Evgeny Boger
  Cc: open list:THERMAL, Quentin Schulz, Sebastian Reichel, Hermann Lauer

On Wed, Jan 12, 2022 at 4:47 PM Evgeny Boger <boger@wirenboard.com> wrote:
>
> 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>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-13 13:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-12  8:47 [PATCH v2] power: supply: axp20x_battery: properly report current when discharging Evgeny Boger
2022-01-13 13:58 ` Chen-Yu Tsai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.