acpi: battery: Read Battery charge time for Steamdeck devices
v4 cover acpi: battery: Read Battery charge time for Steamdeck devices
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
Changes in v2:
- comment improvements
- split off BCT method handling into separate patch
- https://lore.kernel.org/all/[email protected]/
v1:
https://lore.kernel.org/all/[email protected]/
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(-)
Signature · 1 line
2.55.0
PATCH v4 1/1 acpi: battery: Read Battery charge time("_BCT") for Steamdeck devices
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.
--- drivers/acpi/battery.c | 49 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-)
drivers/acpi/battery.c +48 -1
@@ -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)
Signature · 1 line
2.55.0
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH v4 1/1] acpi: battery: Read Battery charge time("_BCT") for Steamdeck devices
Quoted 18 lines · 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 reportACPI_BATTERY_VALUE_UNKNOWN. Use this as a differentiator to determine, whether the battery of steamdeck devices is really charging or not.
Quoted 1 line
Signed-off-by Umang Jain <[email protected]>
Sashiko has feedback on this:
https://sashiko.dev/#/patchset/20261116102752.520062-1-uajain%40igalia.com
Please let me know what you think about it.
Quoted 88 lines
--- drivers/acpi/battery.c | 49 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-)drivers/acpi/battery.c +48
-2@@ -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