Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 526294e

Browse files
Wer-Wolfrafaeljw
authored andcommitted
ACPI: battery: Add support for charge limiting state
The ACPI specification says that bit 3 inside the battery state signals that the battery is in charge limiting state. In this state, the platform limits the battery from reaching its full capacity, the exact limit is platform-specific. This might explain why a number of batteries reported a "Unknown" battery state in the past when using platform-specific interfaces to stop battery charging at a user defined level. Unfortunately not all platforms set this bit in such cases, so "non-charging" is still the default state when the battery is neither charging, discharging or full. Tested on a Lenovo Ideapad S145-14IWL. Signed-off-by: Armin Wolf <W_Armin@gmx.de> Link: https://patch.msgid.link/20240620191410.3646-1-W_Armin@gmx.de Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 6bad28c commit 526294e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

drivers/acpi/battery.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
/* Battery power unit: 0 means mW, 1 means mA */
3939
#define ACPI_BATTERY_POWER_UNIT_MA 1
4040

41-
#define ACPI_BATTERY_STATE_DISCHARGING 0x1
42-
#define ACPI_BATTERY_STATE_CHARGING 0x2
43-
#define ACPI_BATTERY_STATE_CRITICAL 0x4
41+
#define ACPI_BATTERY_STATE_DISCHARGING 0x1
42+
#define ACPI_BATTERY_STATE_CHARGING 0x2
43+
#define ACPI_BATTERY_STATE_CRITICAL 0x4
44+
#define ACPI_BATTERY_STATE_CHARGE_LIMITING 0x8
4445

4546
#define MAX_STRING_LENGTH 64
4647

@@ -155,7 +156,7 @@ static int acpi_battery_get_state(struct acpi_battery *battery);
155156

156157
static int acpi_battery_is_charged(struct acpi_battery *battery)
157158
{
158-
/* charging, discharging or critical low */
159+
/* charging, discharging, critical low or charge limited */
159160
if (battery->state != 0)
160161
return 0;
161162

@@ -215,6 +216,8 @@ static int acpi_battery_get_property(struct power_supply *psy,
215216
val->intval = acpi_battery_handle_discharging(battery);
216217
else if (battery->state & ACPI_BATTERY_STATE_CHARGING)
217218
val->intval = POWER_SUPPLY_STATUS_CHARGING;
219+
else if (battery->state & ACPI_BATTERY_STATE_CHARGE_LIMITING)
220+
val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
218221
else if (acpi_battery_is_charged(battery))
219222
val->intval = POWER_SUPPLY_STATUS_FULL;
220223
else

0 commit comments

Comments
 (0)