]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
platform/x86: lenovo-wmi-other: Add WMI battery charge limiting
authorDerek J. Clark <derekjohn.clark@gmail.com>
Wed, 20 May 2026 06:07:37 +0000 (06:07 +0000)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Thu, 28 May 2026 11:17:44 +0000 (14:17 +0300)
commit9ca8fc065b88b327acbfdc33454efea391639716
treea3ba29c196ea206f389588750bdb009dc54c4374
parent891d43749445fed6725acf9ee1c37e052dba8288
platform/x86: lenovo-wmi-other: Add WMI battery charge limiting

Add charge_behaviour and charge_types attributes through a power supply
extension for devices that support WMI based charge enable & disable.

Lenovo Legion devices that implement WMI function and capdata ID
0x03010001 in their BIOS are able to enable or disable charging at 80%
through the lenovo-wmi-other interface. Add a charge_types attribute for
BATX devices to expose this capability with Standard and Long_Life types
enabled.

Additionally, devices that support WMI function and capdata ID 0x03020000
are able to force discharge of the battery. Expose this capability with
a charge_behaviour attribute in the power supply extension, with the auto
and force-discharge behaviors enabled. The GET method for this attribute
is bugged. After analyzing the DSDT, and some testing, it appears the
method grabs bit(3) instead of bit(4) from the EC register that stores the
current status, and will only report if charging has been inhibited or
not. To work around this, store and report the last setting written to the
attribute.

As some devices only expose one attribute or the other, a bitmask is
added with a lookup table and some helper macros to select the correct
configuration for the hardware at runtime.

The ideapad_laptop driver provides the charge_types attribute to provide
similar functionality. When the WMI method is set this can corrupt the
ACPI method return and cause hardware and driver errors. To avoid
conflicts between the drivers, we get the acpi_handle and do the same
check that ideapad_laptop does when it enables the feature. If the
feature is supported in ideapad_laptop, abort adding the extension from
lenovo-wmi-other. The ACPI method is more reliable when both are
present from my testing, so we can prefer that implementation and do
not need to worry about de-conflicting from inside that driver.

Reviewed-by: Rong Zhang <i@rong.moe>
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
Link: https://patch.msgid.link/20260520060740.119554-5-derekjohn.clark@gmail.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/lenovo/Kconfig
drivers/platform/x86/lenovo/wmi-capdata.h
drivers/platform/x86/lenovo/wmi-other.c