diff mbox series

[1/2] ACPI: battery: Add support for charge limiting state

Message ID 20240620191410.3646-1-W_Armin@gmx.de (mailing list archive)
State Mainlined, archived
Headers show
Series [1/2] ACPI: battery: Add support for charge limiting state | expand

Commit Message

Armin Wolf June 20, 2024, 7:14 p.m. UTC
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>
---
 drivers/acpi/battery.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

--
2.39.2

Comments

Rafael J. Wysocki July 1, 2024, 5:34 p.m. UTC | #1
On Thu, Jun 20, 2024 at 9:14 PM Armin Wolf <W_Armin@gmx.de> wrote:
>
> 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>
> ---
>  drivers/acpi/battery.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
> index d289b98a2cca..9ba2191a96d6 100644
> --- a/drivers/acpi/battery.c
> +++ b/drivers/acpi/battery.c
> @@ -38,9 +38,10 @@
>  /* Battery power unit: 0 means mW, 1 means mA */
>  #define ACPI_BATTERY_POWER_UNIT_MA     1
>
> -#define ACPI_BATTERY_STATE_DISCHARGING 0x1
> -#define ACPI_BATTERY_STATE_CHARGING    0x2
> -#define ACPI_BATTERY_STATE_CRITICAL    0x4
> +#define ACPI_BATTERY_STATE_DISCHARGING         0x1
> +#define ACPI_BATTERY_STATE_CHARGING            0x2
> +#define ACPI_BATTERY_STATE_CRITICAL            0x4
> +#define ACPI_BATTERY_STATE_CHARGE_LIMITING     0x8
>
>  #define MAX_STRING_LENGTH      64
>
> @@ -155,7 +156,7 @@ static int acpi_battery_get_state(struct acpi_battery *battery);
>
>  static int acpi_battery_is_charged(struct acpi_battery *battery)
>  {
> -       /* charging, discharging or critical low */
> +       /* charging, discharging, critical low or charge limited */
>         if (battery->state != 0)
>                 return 0;
>
> @@ -215,6 +216,8 @@ static int acpi_battery_get_property(struct power_supply *psy,
>                         val->intval = acpi_battery_handle_discharging(battery);
>                 else if (battery->state & ACPI_BATTERY_STATE_CHARGING)
>                         val->intval = POWER_SUPPLY_STATUS_CHARGING;
> +               else if (battery->state & ACPI_BATTERY_STATE_CHARGE_LIMITING)
> +                       val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
>                 else if (acpi_battery_is_charged(battery))
>                         val->intval = POWER_SUPPLY_STATUS_FULL;
>                 else
> --

Applied as 6.11 material along with the [2/2], thanks!
diff mbox series

Patch

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index d289b98a2cca..9ba2191a96d6 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -38,9 +38,10 @@ 
 /* Battery power unit: 0 means mW, 1 means mA */
 #define ACPI_BATTERY_POWER_UNIT_MA	1

-#define ACPI_BATTERY_STATE_DISCHARGING	0x1
-#define ACPI_BATTERY_STATE_CHARGING	0x2
-#define ACPI_BATTERY_STATE_CRITICAL	0x4
+#define ACPI_BATTERY_STATE_DISCHARGING		0x1
+#define ACPI_BATTERY_STATE_CHARGING		0x2
+#define ACPI_BATTERY_STATE_CRITICAL		0x4
+#define ACPI_BATTERY_STATE_CHARGE_LIMITING	0x8

 #define MAX_STRING_LENGTH	64

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

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

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