Skip to contentSkip to conversation

New: thinkpad_acpi: ThinkPad L590 returns previous threshold value when switching between BCTG and BCSG reads

Bug 222329 [email protected] 1 participant 1 message Nov 26 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

https://bugzilla.kernel.org/show_bug.cgi?id=222329

            Bug ID: 222329
           Summary: thinkpad_acpi: ThinkPad L590 returns previous
                    threshold value when switching between BCTG and BCSG
                    reads
           Product: Drivers
           Version: 2.5
    Kernel Version: 6.18.65
          Hardware: Intel
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P3
         Component: Platform_x86
          Assignee: [email protected]
          Reporter: [email protected]
        Regression: No

Created attachment 311586
--> https://bugzilla.kernel.org/attachment.cgi?id=311586&action=edit
DSDT dump (ThinkPad L590, BIOS R0ZET60P 1.38)

Hi,

On a Lenovo ThinkPad L590, reading battery charge thresholds via thinkpad_acpi sysfs attributes returns the *previous* query's result on the first read whenever switching between start threshold (BCTG) and stop/end threshold (BCSG).
A second consecutive read of the same attribute returns the actual value.

== System Information ==
- Model: Lenovo ThinkPad L590 (20Q8A0MLCD)
- DMI:

  sys_vendor:          LENOVO
  product_name:        20Q8A0MLCD
  product_version:     ThinkPad L590
  product_family:      ThinkPad L590
  bios_version:        R0ZET60P (1.38 )
  bios_date:           11/05/2025

ec_firmware_release: 1.18 (EC R0ZHT39W)
- Kernels tested:
- 6.18.65-1-lts (Arch Linux official LTS kernel)
- 7.3.6-zen1-1-zen

== Kernel Boot Log (6.18.65-1-lts) ==
Linux version 6.18.65-1-lts (linux-lts@archlinux) #1 SMP PREEMPT_DYNAMIC Mon, 23 Nov 2026 16:05:10 +0000
thinkpad_acpi: ThinkPad ACPI Extras v0.26
thinkpad_acpi: ThinkPad BIOS R0ZET60P (1.38 ), EC R0ZHT39W
thinkpad_acpi: Lenovo ThinkPad L590, model 20Q8A0MLCD
thinkpad_acpi: battery 1 registered (start 45, stop 60, behaviours: 0xb)

== Steps to Reproduce ==
With actual EC thresholds set to start=45, stop=60:

1. On 6.18.65-1-lts, reading start 3 times then end 3 times:

   $ for f in charge_control_start_threshold charge_control_end_threshold; do
       echo -n "$f: "
       for i in 1 2 3; do echo -n "$(cat /sys/class/power_supply/BAT0/$f) ";
done
       echo
     done
   charge_control_start_threshold: 45 45 45
   charge_control_end_threshold: 45 60 60

2. Similarly, reading start after end returns 60 on the first read and 45 on subsequent reads (60 45 45 45 45). Reading end then start once each in alternation consistently returns swapped values (end=45, start=60).

3. This is not a timing race: inserting sleep 2 between switching from start to end (or vice versa) still returns the previous query's value on the first read (45 then 60, and 60 then 45).

== Analysis ==
In the DSDT, both methods delegate to the same SMI wrapper:
- BCTG(Arg0) -> \PSIF(0x05, Arg0) -> SMI_(0x14, 0x05, 0x05, Arg0, 0x00)
- BCSG(Arg0) -> \PSIF(0x07, Arg0) -> SMI_(0x14, 0x05, 0x07, Arg0, 0x00)

The firmware appears to lag by one query when switching between BCTG and BCSG.
- tpacpi_battery_add() reports the right values at boot because it evaluates BCTG twice (capability check + read) and BCSG twice.
- upowerd also reports the right values because libgudev reads each sysfs file twice (g_udev_device_has_sysfs_attr() followed by g_udev_device_get_sysfs_attr_as_int_uncached()).
- Userspace tools that read each sysfs attribute once in sequence (such as KDE PowerDevil's chargethresholdhelper, which reads end then start once each) consistently get swapped thresholds (end=45, start=60), causing KDE Settings to clamp the stop threshold to 50% and risk writing wrong values back to EC.

== Potential Fix ==
A ThinkPad L590 quirk in thinkpad_acpi performing a dummy read (evaluating BCTG/BCSG twice and returning the second result) in charge_control_{start,end}_threshold_show (and legacy start/stop attributes) would work around this firmware bug transparently for all userspace tools.

I am happy to test patches on this hardware if needed.

Thanks!

Signature · 2 lines
You are receiving this mail because:
You are watching the assignee of the bug.