[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250128-patch-qcomm-bat-uint-power-v1-1-54a63d8ada92@mailbox.org>
Date: Tue, 28 Jan 2025 09:42:56 +0100
From: Anthony Ruhier via B4 Relay <devnull+aruhier.mailbox.org@...nel.org>
To: Sebastian Reichel <sre@...nel.org>
Cc: linux-arm-msm@...r.kernel.org, linux-pm@...r.kernel.org,
linux-kernel@...r.kernel.org, Anthony Ruhier <aruhier@...lbox.org>
Subject: [PATCH] power: supply: qcom_battmgr: abs() on POWER_NOW property
From: Anthony Ruhier <aruhier@...lbox.org>
The value for the POWER_NOW property is by default negative when the
battery is discharging, positive when charging.
However on x1e laptops it breaks several userland tools that give a
prediction of the battery run time (such as the acpi command, powertop
or the waybar battery module), as these tools do not expect a negative
value for /sys/class/power_supply/qcom-battmgr-bat/power_now. They
estimate the battery run time by dividing the value of energy_full by
power_now. The battery percentage is calculated by dividing energy_full
by energy_now, therefore it is not impacted.
While having a negative number during discharge makes sense, it is not
standard with how other battery drivers expose it. Instead, it seems
standard to have a positive value for power_now, and rely on the status
file instead to know if the battery is charging or discharging. It is
what other x86 laptops do.
Without the patch:
$ acpi
Battery 0: Discharging, 98%, discharging at zero rate - will never fully discharge.
With the patch:
$ acpi
Battery 0: Discharging, 97%, 10:18:27 remaining
---
Signed-off-by: Anthony Ruhier <aruhier@...lbox.org>
---
drivers/power/supply/qcom_battmgr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c
index 47d29271ddf400b76dd5b0a1b8d1ba86c017afc0..3e2e0c5af2814df0eb0bfc408d4b3d26399ab4e4 100644
--- a/drivers/power/supply/qcom_battmgr.c
+++ b/drivers/power/supply/qcom_battmgr.c
@@ -530,7 +530,7 @@ static int qcom_battmgr_bat_get_property(struct power_supply *psy,
val->intval = battmgr->status.current_now;
break;
case POWER_SUPPLY_PROP_POWER_NOW:
- val->intval = battmgr->status.power_now;
+ val->intval = abs(battmgr->status.power_now);
break;
case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
if (unit != QCOM_BATTMGR_UNIT_mAh)
---
base-commit: ffd294d346d185b70e28b1a28abe367bbfe53c04
change-id: 20250128-patch-qcomm-bat-uint-power-5793f3638c56
Best regards,
--
Anthony Ruhier <aruhier@...lbox.org>
Powered by blists - more mailing lists