Linux ACPI
 help / color / mirror / Atom feed
* [PATCH v4 0/1]  acpi: battery: Read Battery charge time for Steamdeck devices
@ 2026-11-16 10:27 Umang Jain
  2026-11-16 10:27 ` [PATCH v4 1/1] acpi: battery: Read Battery charge time("_BCT") " Umang Jain
  0 siblings, 1 reply; 4+ messages in thread
From: Umang Jain @ 2026-11-16 10:27 UTC (permalink / raw)
  To: Rafael J . Wysocki, Len Brown
  Cc: linux-acpi, linux-kernel, kernel-dev, Umang Jain

Patch to query Battery charge time ("_BCT") from ACPI tables
for steamdeck devices to determine when low power PSU is connected,
which is discharging the device.

changes in v4:
- Merge both 1/2 and 2/2 into single patch
- Set quirk and _BCT reading at same place
- Edit comments for the same.
- Log failed message as acpi_handle_debug()
- Split case when _BCT value > ACPI_UINT32_MAX

Changes in v3:
- Only query BCT method for the steamdeck quirk
- Drop charge_time member from battery object
- check for returned value from acpi_evaluate_integer for max
  ACPI_UINT32_MAX bounds as per the spec
Link: https://lore.kernel.org/all/20261014204558.466130-1-uajain@igalia.com/

Changes in v2:
- comment improvements
- split off BCT method handling into separate patch
- https://lore.kernel.org/all/20260923082932.1049270-1-uajain@igalia.com/

v1:
https://lore.kernel.org/all/20260918135628.2322188-1-uajain@igalia.com/

Umang Jain (1):
  acpi: battery: Read Battery charge time("_BCT") for Steamdeck devices

 drivers/acpi/battery.c | 49 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

-- 
2.55.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v4 1/1] acpi: battery: Read Battery charge time("_BCT") for Steamdeck devices
  2026-11-16 10:27 [PATCH v4 0/1] acpi: battery: Read Battery charge time for Steamdeck devices Umang Jain
@ 2026-11-16 10:27 ` Umang Jain
  2026-11-20 13:35   ` Rafael J. Wysocki (Intel)
  0 siblings, 1 reply; 4+ messages in thread
From: Umang Jain @ 2026-11-16 10:27 UTC (permalink / raw)
  To: Rafael J . Wysocki, Len Brown
  Cc: linux-acpi, linux-kernel, kernel-dev, Umang Jain

Valve steamdeck devices can report battery status as
charging, even when low-powered power supply is connected
to the device. The battery status is reported as charging
through sysfs, even though in reality, it is discharging.

To address this, introduce a battery quirk for Valve Steamdeck devices
ACPI_BATTERY_QUIRK_VALVE_STEAMDECK. This is required to detect
if a low-power supply unit is connected to the device.
To handle this case, read out Battery charge time ("_BCT")
as it is reported accurately on these devices and use that
information for report charging vs discharging status.
Battery charge time ("_BCT") with an eligible power supply unit
will have valid values whereas with a low-powered supply unit,
it shall report ACPI_BATTERY_VALUE_UNKNOWN. Use this as a
differentiator to determine, whether the battery of steamdeck
devices is really charging or not.

Signed-off-by: Umang Jain <uajain@igalia.com>
---
 drivers/acpi/battery.c | 49 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 6edea559a5bc..458c2b23a05a 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -94,6 +94,15 @@ enum {
 	 * on a full charge, but showing degradation in full charge cap.
 	 */
 	ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE,
+	/*
+	 * Valve steamdeck devices can get discharged even when battery status
+	 * is charging. This happens typically when low power supply unit is
+	 * connected. To accurately determine this scenario, we shall read
+	 * battery charge time ("_BCT") and set this quirk. This is the key
+	 * differentiator to determine whether the steamdeck is actually
+	 * charging or not.
+	 */
+	ACPI_BATTERY_QUIRK_VALVE_STEAMDECK,
 };
 
 struct acpi_battery {
@@ -234,7 +243,7 @@ static int acpi_battery_get_property(struct power_supply *psy,
 					: POWER_SUPPLY_STATUS_DISCHARGING;
 				return 0;
 			}
-		else if (battery->state & ACPI_BATTERY_STATE_CHARGING)
+		else if (battery->state & ACPI_BATTERY_STATE_CHARGING) {
 			/* Check the rate and capacity to validate the status. */
 			if (!acpi_battery_is_full(battery) ||
 			    (battery->rate_now != ACPI_BATTERY_VALUE_UNKNOWN &&
@@ -244,6 +253,27 @@ static int acpi_battery_get_property(struct power_supply *psy,
 				/* Full and zero rate. */
 				val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
 			}
+
+			if (test_bit(ACPI_BATTERY_QUIRK_VALVE_STEAMDECK, &battery->flags)) {
+				unsigned long long bct;
+				acpi_status status;
+				union acpi_object arg0 = { ACPI_TYPE_INTEGER };
+				struct acpi_object_list args = { 1, &arg0 };
+
+				arg0.integer.value = 100;
+				status = acpi_evaluate_integer(battery->device->handle, "_BCT",
+							       &args, &bct);
+				if (ACPI_FAILURE(status))
+					acpi_handle_debug(battery->device->handle,
+							  "_BCT evaluation failed: %s",
+							  acpi_format_exception(status));
+				else if (bct > ACPI_UINT32_MAX)
+					acpi_handle_debug(battery->device->handle,
+							  "_BCT value is invalid");
+				else if (bct == ACPI_BATTERY_VALUE_UNKNOWN)
+					val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
+			}
+		}
 		else if (battery->state & ACPI_BATTERY_STATE_CHARGE_LIMITING)
 			val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
 		else if (acpi_battery_is_charged(battery))
@@ -1150,6 +1180,23 @@ static void acpi_battery_quirks(struct acpi_battery *battery)
 		set_bit(ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, &battery->flags);
 		battery->capacity_now = battery->full_charge_capacity;
 	}
+
+	if (test_bit(ACPI_BATTERY_QUIRK_VALVE_STEAMDECK, &battery->flags))
+		return;
+
+	/*
+	 * For Valve Steamdeck devices, determine _BCT presence as well before
+	 * setting its battery quirk.
+	 */
+	if (dmi_name_in_vendors("Valve") &&
+	    acpi_has_method(battery->device->handle, "_BCT")) {
+		const char *name;
+
+		name = dmi_get_system_info(DMI_PRODUCT_NAME);
+		if ((name && (!strncmp("Jupiter", name, 7))) ||
+		    (name && (!strncmp("Galileo", name, 7))))
+			set_bit(ACPI_BATTERY_QUIRK_VALVE_STEAMDECK, &battery->flags);
+	}
 }
 
 static int acpi_battery_update(struct acpi_battery *battery, bool resume)
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 1/1] acpi: battery: Read Battery charge time("_BCT") for Steamdeck devices
  2026-11-16 10:27 ` [PATCH v4 1/1] acpi: battery: Read Battery charge time("_BCT") " Umang Jain
@ 2026-11-20 13:35   ` Rafael J. Wysocki (Intel)
  2026-11-27 12:43     ` Umang Jain
  0 siblings, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-20 13:35 UTC (permalink / raw)
  To: Umang Jain
  Cc: Rafael J . Wysocki, Len Brown, linux-acpi, linux-kernel,
	kernel-dev

On Mon, Nov 16, 2026 at 11:26 AM Umang Jain <uajain@igalia.com> wrote:
>
> Valve steamdeck devices can report battery status as
> charging, even when low-powered power supply is connected
> to the device. The battery status is reported as charging
> through sysfs, even though in reality, it is discharging.
>
> To address this, introduce a battery quirk for Valve Steamdeck devices
> ACPI_BATTERY_QUIRK_VALVE_STEAMDECK. This is required to detect
> if a low-power supply unit is connected to the device.
> To handle this case, read out Battery charge time ("_BCT")
> as it is reported accurately on these devices and use that
> information for report charging vs discharging status.
> Battery charge time ("_BCT") with an eligible power supply unit
> will have valid values whereas with a low-powered supply unit,
> it shall report ACPI_BATTERY_VALUE_UNKNOWN. Use this as a
> differentiator to determine, whether the battery of steamdeck
> devices is really charging or not.
>
> Signed-off-by: Umang Jain <uajain@igalia.com>

Sashiko has feedback on this:

https://sashiko.dev/#/patchset/20261116102752.520062-1-uajain%40igalia.com

Please let me know what you think about it.

> ---
>  drivers/acpi/battery.c | 49 +++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 48 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
> index 6edea559a5bc..458c2b23a05a 100644
> --- a/drivers/acpi/battery.c
> +++ b/drivers/acpi/battery.c
> @@ -94,6 +94,15 @@ enum {
>          * on a full charge, but showing degradation in full charge cap.
>          */
>         ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE,
> +       /*
> +        * Valve steamdeck devices can get discharged even when battery status
> +        * is charging. This happens typically when low power supply unit is
> +        * connected. To accurately determine this scenario, we shall read
> +        * battery charge time ("_BCT") and set this quirk. This is the key
> +        * differentiator to determine whether the steamdeck is actually
> +        * charging or not.
> +        */
> +       ACPI_BATTERY_QUIRK_VALVE_STEAMDECK,
>  };
>
>  struct acpi_battery {
> @@ -234,7 +243,7 @@ static int acpi_battery_get_property(struct power_supply *psy,
>                                         : POWER_SUPPLY_STATUS_DISCHARGING;
>                                 return 0;
>                         }
> -               else if (battery->state & ACPI_BATTERY_STATE_CHARGING)
> +               else if (battery->state & ACPI_BATTERY_STATE_CHARGING) {
>                         /* Check the rate and capacity to validate the status. */
>                         if (!acpi_battery_is_full(battery) ||
>                             (battery->rate_now != ACPI_BATTERY_VALUE_UNKNOWN &&
> @@ -244,6 +253,27 @@ static int acpi_battery_get_property(struct power_supply *psy,
>                                 /* Full and zero rate. */
>                                 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
>                         }
> +
> +                       if (test_bit(ACPI_BATTERY_QUIRK_VALVE_STEAMDECK, &battery->flags)) {
> +                               unsigned long long bct;
> +                               acpi_status status;
> +                               union acpi_object arg0 = { ACPI_TYPE_INTEGER };
> +                               struct acpi_object_list args = { 1, &arg0 };
> +
> +                               arg0.integer.value = 100;
> +                               status = acpi_evaluate_integer(battery->device->handle, "_BCT",
> +                                                              &args, &bct);
> +                               if (ACPI_FAILURE(status))
> +                                       acpi_handle_debug(battery->device->handle,
> +                                                         "_BCT evaluation failed: %s",
> +                                                         acpi_format_exception(status));
> +                               else if (bct > ACPI_UINT32_MAX)
> +                                       acpi_handle_debug(battery->device->handle,
> +                                                         "_BCT value is invalid");
> +                               else if (bct == ACPI_BATTERY_VALUE_UNKNOWN)
> +                                       val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
> +                       }
> +               }
>                 else if (battery->state & ACPI_BATTERY_STATE_CHARGE_LIMITING)
>                         val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
>                 else if (acpi_battery_is_charged(battery))
> @@ -1150,6 +1180,23 @@ static void acpi_battery_quirks(struct acpi_battery *battery)
>                 set_bit(ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, &battery->flags);
>                 battery->capacity_now = battery->full_charge_capacity;
>         }
> +
> +       if (test_bit(ACPI_BATTERY_QUIRK_VALVE_STEAMDECK, &battery->flags))
> +               return;
> +
> +       /*
> +        * For Valve Steamdeck devices, determine _BCT presence as well before
> +        * setting its battery quirk.
> +        */
> +       if (dmi_name_in_vendors("Valve") &&
> +           acpi_has_method(battery->device->handle, "_BCT")) {
> +               const char *name;
> +
> +               name = dmi_get_system_info(DMI_PRODUCT_NAME);
> +               if ((name && (!strncmp("Jupiter", name, 7))) ||
> +                   (name && (!strncmp("Galileo", name, 7))))
> +                       set_bit(ACPI_BATTERY_QUIRK_VALVE_STEAMDECK, &battery->flags);
> +       }
>  }
>
>  static int acpi_battery_update(struct acpi_battery *battery, bool resume)
> --
> 2.55.0
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 1/1] acpi: battery: Read Battery charge time("_BCT") for Steamdeck devices
  2026-11-20 13:35   ` Rafael J. Wysocki (Intel)
@ 2026-11-27 12:43     ` Umang Jain
  0 siblings, 0 replies; 4+ messages in thread
From: Umang Jain @ 2026-11-27 12:43 UTC (permalink / raw)
  To: Rafael J. Wysocki (Intel); +Cc: Len Brown, linux-acpi, linux-kernel, kernel-dev

Hi Rafael,

Sorry for late reply.

On 2026-11-20 13:35, Rafael J. Wysocki (Intel) wrote:
> On Mon, Nov 16, 2026 at 11:26 AM Umang Jain <uajain@igalia.com> wrote:
>>
>> Valve steamdeck devices can report battery status as
>> charging, even when low-powered power supply is connected
>> to the device. The battery status is reported as charging
>> through sysfs, even though in reality, it is discharging.
>>
>> To address this, introduce a battery quirk for Valve Steamdeck devices
>> ACPI_BATTERY_QUIRK_VALVE_STEAMDECK. This is required to detect
>> if a low-power supply unit is connected to the device.
>> To handle this case, read out Battery charge time ("_BCT")
>> as it is reported accurately on these devices and use that
>> information for report charging vs discharging status.
>> Battery charge time ("_BCT") with an eligible power supply unit
>> will have valid values whereas with a low-powered supply unit,
>> it shall report ACPI_BATTERY_VALUE_UNKNOWN. Use this as a
>> differentiator to determine, whether the battery of steamdeck
>> devices is really charging or not.
>>
>> Signed-off-by: Umang Jain <uajain@igalia.com>
> 
> Sashiko has feedback on this:
> 
> https://sashiko.dev/#/patchset/20261116102752.520062-1-uajain%40igalia.com

I'll post the feedback here and then reply.

> Should _BCT be evaluated inside acpi_battery_get_state() using an exclusive
> evaluation helper instead of directly in acpi_battery_get_property()?
> Evaluating _BCT here bypasses the cache_time rate-limiting in
> acpi_battery_get_state(), so every sysfs status read or uevent executes the
> method on the embedded controller.  In addition, all other battery control
> methods in this driver (_BIF, _BIX, _BST, and _BTP) serialize execution
> under acpi_exclusive_eval_lock via acpi_evaluate_object_exclusive() or
> acpi_execute_simple_method_exclusive(), whereas acpi_evaluate_integer() runs
> unlocked.

I agree on the part that battery control methods are evaluated in
acpi_battery_get_state(),
however we are not trying to determine and store "_BCT" here. We are
just using to get
the proper charging status for the steamdeck device using _BCT. We
rejected the idea of "_BCT"
being evaluated globally for all devices in previous reviews, which
would be fit in get_state().
We just bind _BCT evaluation to steamdeck's quirk case.

Regarding question of rate-limiting calls on every sysfs status read or
uevent, I don't
think it's necessary either, since get_property() calls are executed on
every power supply
changes from power_supply_core.c - hence as soon as you unplug and plug
or even replug a
low-powered charger it will go through acpi_battery_get_property() code
paths (since power
supply is effectively changed) and update the correct charging status.
We don't need to
constantly call/evaluate _BCT again in this case, since a charger won't
suddenly change from
low-power to high-power one or vice versa.

I agree with usage acpi_evaluate_integer_exclusive() though. I will
include it in next revision.

> Does this overwrite POWER_SUPPLY_STATUS_NOT_CHARGING with
> POWER_SUPPLY_STATUS_DISCHARGING when the battery is full and its charge rate
> is zero?

When the battery is full in steamdeck case, it is correctly inferred:
i.e. acpi_battery_is_charged() returns TRUE.

Hence the branch
```
else if (battery->state & ACPI_BATTERY_STATE_CHARGING) {
...
...
    if (test_bit(ACPI_BATTERY_QUIRK_VALVE_STEAMDECK, &battery->flags)) {
    ...
    }
}
```
is _not_ executed at all and instead the branch

		else if (acpi_battery_is_charged(battery))
			val->intval = POWER_SUPPLY_STATUS_FULL;

is evaluated instead and status is correctly updated to "Full". So no,
it would not overwrite.

> When acpi_battery_is_full(battery) is true and battery->rate_now is 0, the
> preceding else branch sets val->intval to POWER_SUPPLY_STATUS_NOT_CHARGING.
> Because the quirk check sits outside the if branch, it still runs, and
> _BCT(100) returns 0xffffffff (ACPI_BATTERY_VALUE_UNKNOWN) when the battery
> is already at 100% and not actively charging.  Moving the quirk check inside
> the branch that sets POWER_SUPPLY_STATUS_CHARGING would avoid this
> regression.
> 
> Please let me know what you think about it.

Hope the explanations clarifies things.

I'll send a v5 if there are no more things to discuss?
The only change in v5 would be use of acpi_evaluate_integer_exclusive()
instead
of acpi_evaluate_integer() for evaluating the _BCT.

> 
>> ---
>>  drivers/acpi/battery.c | 49 +++++++++++++++++++++++++++++++++++++++++-
>>  1 file changed, 48 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
>> index 6edea559a5bc..458c2b23a05a 100644
>> --- a/drivers/acpi/battery.c
>> +++ b/drivers/acpi/battery.c
>> @@ -94,6 +94,15 @@ enum {
>>          * on a full charge, but showing degradation in full charge cap.
>>          */
>>         ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE,
>> +       /*
>> +        * Valve steamdeck devices can get discharged even when battery status
>> +        * is charging. This happens typically when low power supply unit is
>> +        * connected. To accurately determine this scenario, we shall read
>> +        * battery charge time ("_BCT") and set this quirk. This is the key
>> +        * differentiator to determine whether the steamdeck is actually
>> +        * charging or not.
>> +        */
>> +       ACPI_BATTERY_QUIRK_VALVE_STEAMDECK,
>>  };
>>
>>  struct acpi_battery {
>> @@ -234,7 +243,7 @@ static int acpi_battery_get_property(struct power_supply *psy,
>>                                         : POWER_SUPPLY_STATUS_DISCHARGING;
>>                                 return 0;
>>                         }
>> -               else if (battery->state & ACPI_BATTERY_STATE_CHARGING)
>> +               else if (battery->state & ACPI_BATTERY_STATE_CHARGING) {
>>                         /* Check the rate and capacity to validate the status. */
>>                         if (!acpi_battery_is_full(battery) ||
>>                             (battery->rate_now != ACPI_BATTERY_VALUE_UNKNOWN &&
>> @@ -244,6 +253,27 @@ static int acpi_battery_get_property(struct power_supply *psy,
>>                                 /* Full and zero rate. */
>>                                 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
>>                         }
>> +
>> +                       if (test_bit(ACPI_BATTERY_QUIRK_VALVE_STEAMDECK, &battery->flags)) {
>> +                               unsigned long long bct;
>> +                               acpi_status status;
>> +                               union acpi_object arg0 = { ACPI_TYPE_INTEGER };
>> +                               struct acpi_object_list args = { 1, &arg0 };
>> +
>> +                               arg0.integer.value = 100;
>> +                               status = acpi_evaluate_integer(battery->device->handle, "_BCT",
>> +                                                              &args, &bct);
>> +                               if (ACPI_FAILURE(status))
>> +                                       acpi_handle_debug(battery->device->handle,
>> +                                                         "_BCT evaluation failed: %s",
>> +                                                         acpi_format_exception(status));
>> +                               else if (bct > ACPI_UINT32_MAX)
>> +                                       acpi_handle_debug(battery->device->handle,
>> +                                                         "_BCT value is invalid");
>> +                               else if (bct == ACPI_BATTERY_VALUE_UNKNOWN)
>> +                                       val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
>> +                       }
>> +               }
>>                 else if (battery->state & ACPI_BATTERY_STATE_CHARGE_LIMITING)
>>                         val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
>>                 else if (acpi_battery_is_charged(battery))
>> @@ -1150,6 +1180,23 @@ static void acpi_battery_quirks(struct acpi_battery *battery)
>>                 set_bit(ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, &battery->flags);
>>                 battery->capacity_now = battery->full_charge_capacity;
>>         }
>> +
>> +       if (test_bit(ACPI_BATTERY_QUIRK_VALVE_STEAMDECK, &battery->flags))
>> +               return;
>> +
>> +       /*
>> +        * For Valve Steamdeck devices, determine _BCT presence as well before
>> +        * setting its battery quirk.
>> +        */
>> +       if (dmi_name_in_vendors("Valve") &&
>> +           acpi_has_method(battery->device->handle, "_BCT")) {
>> +               const char *name;
>> +
>> +               name = dmi_get_system_info(DMI_PRODUCT_NAME);
>> +               if ((name && (!strncmp("Jupiter", name, 7))) ||
>> +                   (name && (!strncmp("Galileo", name, 7))))
>> +                       set_bit(ACPI_BATTERY_QUIRK_VALVE_STEAMDECK, &battery->flags);
>> +       }
>>  }
>>
>>  static int acpi_battery_update(struct acpi_battery *battery, bool resume)
>> --
>> 2.55.0
>>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-27 12:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 10:27 [PATCH v4 0/1] acpi: battery: Read Battery charge time for Steamdeck devices Umang Jain
2026-11-16 10:27 ` [PATCH v4 1/1] acpi: battery: Read Battery charge time("_BCT") " Umang Jain
2026-11-20 13:35   ` Rafael J. Wysocki (Intel)
2026-11-27 12:43     ` Umang Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox