Skip to content

Commit 234f715

Browse files
tarirafaeljw
authored andcommitted
ACPI: battery: negate current when discharging
The ACPI specification requires that battery rate is always positive, but the kernel ABI for POWER_SUPPLY_PROP_CURRENT_NOW (Documentation/ABI/testing/sysfs-class-power) specifies that it should be negative when a battery is discharging. When reporting CURRENT_NOW, massage the value to match the documented ABI. This only changes the sign of `current_now` and not `power_now` because documentation doesn't describe any particular meaning for `power_now` so leaving `power_now` unchanged is less likely to confuse userspace unnecessarily, whereas becoming consistent with the documented ABI is worth potentially confusing clients that read `current_now`. Signed-off-by: Peter Marheine <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 46d839a commit 234f715

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

drivers/acpi/battery.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,23 @@ static int acpi_battery_get_property(struct power_supply *psy,
243243
break;
244244
case POWER_SUPPLY_PROP_CURRENT_NOW:
245245
case POWER_SUPPLY_PROP_POWER_NOW:
246-
if (battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN)
246+
if (battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN) {
247247
ret = -ENODEV;
248-
else
249-
val->intval = battery->rate_now * 1000;
248+
break;
249+
}
250+
251+
val->intval = battery->rate_now * 1000;
252+
/*
253+
* When discharging, the current should be reported as a
254+
* negative number as per the power supply class interface
255+
* definition.
256+
*/
257+
if (psp == POWER_SUPPLY_PROP_CURRENT_NOW &&
258+
(battery->state & ACPI_BATTERY_STATE_DISCHARGING) &&
259+
acpi_battery_handle_discharging(battery)
260+
== POWER_SUPPLY_STATUS_DISCHARGING)
261+
val->intval = -val->intval;
262+
250263
break;
251264
case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
252265
case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:

0 commit comments

Comments
 (0)