Skip to content

Commit 19fffc8

Browse files
jwrdegoederafaeljw
authored andcommitted
ACPI / battery: Add handling for devices which wrongly report discharging state
On quite a few devices the battery code in the ACPI tables is buggy and first checks the charging status bits of the charger-IC, and if those report not charging it will report discharging, without looking at the presence of AC power or at the battery dis(charge) current from the fuel-gauge. This causes the wrong status to be reported for the battery in the following quite common scenario: 1) Plug in charger while battery is say half full, battery starts charging, charging state bits indicate: pre-charge or fast-charge, ACPI reported battery status is ok 2) When fully charged charging state bits indicate: end-of-charge, ACPI reported battery status is ok 3) unplug the charger, wait 1 minute, replug. Now the battery voltage is still above the start-charging threshold, so the charger will not start charging to avoid wrecking the battery by repeatedly recharging the last 1% capacity. The charger IC charging state bits now are all 0 (not-charging) and the broken ACPI code wrongly translate this to "discharging" and ends up setting the ACPI_BATTERY_STATE_DISCHARGING bit in its state field. Reporting this "not charging" state as discharging is confusing for users, making the user think his adapter/power-brick is broken or not properly plugged in. This commit adds a helper for handling the ACPI_BATTERY_STATE_DISCHARGING state. This helper checks if we're an AC and the current going out of the battery is 0 and in that case reports a status of "not charging" to userspace rather then "discharging". This replaces commit c68f067 ("ACPI / battery: Add quirk for Asus GL502VSK and UX305LA"), a previous fix for this which was reverted. Signed-off-by: Hans de Goede <[email protected]> Reviewed-by: Daniel Drake <[email protected]> Reviewed-by: Sebastian Reichel <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 91afa07 commit 19fffc8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

drivers/acpi/battery.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@ static bool acpi_battery_is_degraded(struct acpi_battery *battery)
215215
battery->full_charge_capacity < battery->design_capacity;
216216
}
217217

218+
static int acpi_battery_handle_discharging(struct acpi_battery *battery)
219+
{
220+
/*
221+
* Some devices wrongly report discharging if the battery's charge level
222+
* was above the device's start charging threshold atm the AC adapter
223+
* was plugged in and the device thus did not start a new charge cycle.
224+
*/
225+
if (power_supply_is_system_supplied() && battery->rate_now == 0)
226+
return POWER_SUPPLY_STATUS_NOT_CHARGING;
227+
228+
return POWER_SUPPLY_STATUS_DISCHARGING;
229+
}
230+
218231
static int acpi_battery_get_property(struct power_supply *psy,
219232
enum power_supply_property psp,
220233
union power_supply_propval *val)
@@ -230,7 +243,7 @@ static int acpi_battery_get_property(struct power_supply *psy,
230243
switch (psp) {
231244
case POWER_SUPPLY_PROP_STATUS:
232245
if (battery->state & ACPI_BATTERY_STATE_DISCHARGING)
233-
val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
246+
val->intval = acpi_battery_handle_discharging(battery);
234247
else if (battery->state & ACPI_BATTERY_STATE_CHARGING)
235248
val->intval = POWER_SUPPLY_STATUS_CHARGING;
236249
else if (acpi_battery_is_charged(battery))

0 commit comments

Comments
 (0)