Skip to contentSkip to conversation

platform/x86: add Acer battery control driver

PATCH In review Jelle van der Waa 2 participants 3 messages Sep 13 – Sep 15

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v8 cover platform/x86: add Acer battery control driver

This patch upstreams a part of the out of tree acer wmi battery specifically the battery charge control and battery temperature. [1] On my Acer Aspire A315-510P battery calibration did not work as expected so for now this is left out.

Jelle van der Waa (1):
platform/x86: add Acer battery control driver

 .../wmi/devices/acer-wmi-battery.rst          |  70 +++
 drivers/platform/x86/Kconfig                  |  12 +
 drivers/platform/x86/Makefile                 |   1 +
 drivers/platform/x86/acer-wmi-battery.c       | 457 ++++++++++++++++++
 4 files changed, 540 insertions(+)
 create mode 100644 Documentation/wmi/devices/acer-wmi-battery.rst
 create mode 100644 drivers/platform/x86/acer-wmi-battery.c
Signature · 1 line
2.55.0
#1 lore raw

PATCH v8 1/1 platform/x86: add Acer battery control driver

Some Acer laptops can configure battery related features through Acer Care Center on Windows. This driver uses the power supply extension to set a battery charge limit and exposes the battery temperature.

This driver is based on the existing acer-wmi-battery project on GitHub and was tested on an Acer Aspire A315-510P.

---
v8:
- Add missing direct linux header includes
v7:
- Add Acer Aspire A315-58G to the DMI allowlist
v6:
- Mark health_mode static and use __ro_after_init
- Convert output.data using kernel helper le32_to_cpup
- Drop unneeded if-statement for health_mode check
- Remove property_is_writeable for acer_wmi_battery_extension_v1
- Move DMI whitelist above acer_wmi_battery_module_init
v5:
- Add Acer WMI Battery Interface documentation
- Drop unneeded wmi_buffer output initialisation
- Drop get_unaligned_le32, as wmi core returns aligned data
- Derive temperature divider contsant from <linux/units.h> defines
- Add trailing commas to any non-terminating entry in DMI match table
- Remove duplicate DMI entry from DMI match table
- Update set_battery_health_control_output members to be __le16 not u8
as WMI data suggests
- Replace sizeof(u32) with sizeof(*result)
- Add an empty line between if statements in POWER_SUPPLY_PROP_TEMP case
- Drop unneeded .set_property callback in acer_wmi_battery_extension_v1
- Introduce a force module parameter for easier testing of new notebook
models
- Use "ret" instead of "r"
- Check the "uReturn" value of SetBatteryHealthControl
v4:
- Add additional DMI ids from https://github.com/frederik-h/acer-wmi-battery/blob/main/MODELS.md
cross checked with DMI ids found in https://github.com/linuxhw/DMI
- Move DMI matching to __init and make the DMI table __initconst
- Port to the new wmidev_invoke_* API
v3:
- Add depends on DMI
- Rename CamelCase struct member names
- Simplify returning errors
- Add comma to non-terminating entries
- Simplified acer_wmi_battery_set_battery_health_control to acer_wmi_set_battery_health_control
- Use sizeof for acpi_object buffer
- Drop POWER_SUPPLY_EXTENSION macro
v2:
- Alphabetically sort linux headers
- Include headers for types / _packed
- Use cleanup.h instead of goto + label
- Add missing prefix for set_battery_health_control
- General code formatting fixes
- Remove HWMON dependency in Kconfig
- Use wmidev_evaluate_method()
- Accept oversized ACPI buffers
- Use DRIVER_NAME for battery extension name
- Set no_singleton = true
- Implement DMI matching to support laptops with only battery
temperature support.

---
 .../wmi/devices/acer-wmi-battery.rst          |  70 +++
 drivers/platform/x86/Kconfig                  |  12 +
 drivers/platform/x86/Makefile                 |   1 +
 drivers/platform/x86/acer-wmi-battery.c       | 457 ++++++++++++++++++
 4 files changed, 540 insertions(+)
 create mode 100644 Documentation/wmi/devices/acer-wmi-battery.rst
 create mode 100644 drivers/platform/x86/acer-wmi-battery.c
Documentation/wmi/devices/acer-wmi-battery.rst new file +70 -0
new file mode 100644
index 000000000000..8aa3e1334490
@@ -0,0 +1,70 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+====================================================
+Acer WMI Battery interface driver (acer-wmi-battery)
+====================================================
+
+Introduction
+============
+
+Some Acer laptops support setting battery charge control limits and allow a
+user to calibrate their battery.
+
+WMI interface description
+=========================
+
+The WMI interface description can be decoded from the embedded binary MOF (bmof)
+data using the `bmfdec <https://github.com/pali/bmfdec>`_ utility:
+
+::
+
+  [WMI, Dynamic, Provider("WmiProv"), Locale("MS\\0x409"), Description("Class used to control smart battery, Version 2.88"), guid("{79772EC5-04B1-4bfd-843C-61E7F77B6CC9}")]
+  class BatteryControl {
+    [key, read] string InstanceName;
+    [read] boolean Active;
+
+    [WmiMethodId(19), Implemented, read, write, Description("Get battery Information Interface.")] void GetBattInfoInterface([in] uint32 uBatteryInfoIndex, [in] uint32 uBatteryNo, [out] uint32 uReturn);
+    [WmiMethodId(20), Implemented, read, write, Description("Get Battery Health Control Status.")] void GetBatteryHealthControlStatus([in] uint8 uBatteryNo, [in] uint8 uFunctionQuery, [in] uint8 uReserved[2], [out] uint8 uFunctionList, [out] uint8 uReturn[2], [out] uint8 uFunctionStatus[5]);
+    [WmiMethodId(21), Implemented, read, write, Description("Set Battery Health Control.")] void SetBatteryHealthControl([in] uint8 uBatteryNo, [in] uint8 uFunctionMask, [in] uint8 uFunctionStatus, [in] uint8 uReservedIn[5], [out] uint16 uReturn, [out] uint16 uReservedOut);
+    [WmiMethodId(22), Implemented, read, write, Description("Get Battery Function Data.")] void GetBatteryFunctionData([in] uint8 uFunctionMask, [in] uint8 uReservedIn[3], [out] uint8 uReturnCode[2], [out] uint8 uBACStartTime[2], [out] uint8 uBACStopTime[2], [out] uint8 uBACStatus, [out] uint8 uReservedOut[9]);
+    [WmiMethodId(23), Implemented, read, write, Description("Set Battery Function Data.")] void SetBatteryFunctionData([in] uint8 uFunctionMask, [in] uint8 uBACSwitch, [in] uint8 uReservedIn[6], [out] uint16 uReturnCode, [out] uint8 uReservedOut[2]);
+  };
+
+For all methods the ``uBatteryNo`` is always ``0x1``, there are no known Acer
+laptop models with two batteries.
+
+WMI method GetBatteryInfoInterface()
+------------------------------------
+
+Returns additional battery information, the data seems to be based on the
+"Smart Battery Data Specification". The only known value for
+``uBatteryInfoIndex`` is ``0x8``, the battery temperature.
+
+WMI method GetBatteryHealthControlStatus()
+------------------------------------------
+
+This interface does not exist on all Acer laptops, it returns whether battery
+charge limiting or calibration mode is enabled.
+
+When calling this method, ``uFunctionList`` is a bitmask with known values:
+
++--------------------+------------------------------------+
+| Value              | Description                        |
++====================+====================================+
+| 0x01               | Health mode supported              |
++--------------------+------------------------------------+
+| 0x02               | Calibration mode supported         |
++--------------------+------------------------------------+
+
+``uFunctionStatus`` is a 5 byte array known elements are ``0`` for health mode
+and ``1`` for calibration mode. A non-zero value means the mode is enabled.
+
+WMI method SetBatteryHealthControl()
+------------------------------------
+
+This interface does not exist on all Acer laptops, it enables battery
+charge limiting or battery calibration.
+
+The argument ``uFunctionMask`` is known to accept either ``0x01`` for setting
+health mode or ``0x02`` for calibration mode; other values are unknown.
+``uFunctionStatus`` is an uint8 value, a non-zero value enables the given mode.
drivers/platform/x86/Kconfig +12 -0
index 957034f39e4e..45f15f93afa7 100644
@@ -189,6 +189,18 @@ config ACER_WMI
 	  If you have an ACPI-WMI compatible Acer/ Wistron laptop, say Y or M
 	  here.
 
+config ACER_WMI_BATTERY
+	tristate "Acer WMI Battery"
+	depends on ACPI_WMI
+	depends on ACPI_BATTERY
+	depends on DMI
+	help
+	  This is a driver for Acer laptops with battery health control. It
+	  adds charge limit control and battery temperature reporting.
+
+	  If you have an ACPI-WMI Battery compatible Acer laptop, say Y or M
+	  here.
+
 source "drivers/platform/x86/amd/Kconfig"
 
 config ADV_SWBUTTON
drivers/platform/x86/Makefile +1 -0
index 872ac3842391..a877acd937cd 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_BITLAND_MIFS_WMI)		+= bitland-mifs-wmi.o
 obj-$(CONFIG_ACERHDF)		+= acerhdf.o
 obj-$(CONFIG_ACER_WIRELESS)	+= acer-wireless.o
 obj-$(CONFIG_ACER_WMI)		+= acer-wmi.o
+obj-$(CONFIG_ACER_WMI_BATTERY)	+= acer-wmi-battery.o
 
 # AMD
 obj-y				+= amd/
drivers/platform/x86/acer-wmi-battery.c new file +457 -0

457 lines not on this page · raw message

Signature · 1 line
2.55.0
maintainer
#2 lore raw
In reply to Jelle van der Waa
Quoted 9 lines · Jelle van der Waa

This patch upstreams a part of the out of tree acer wmi battery specifically the battery charge control and battery temperature. [1] On my Acer Aspire A315-510P battery calibration did not work as expected so for now this is left out.

Jelle van der Waa (1):
platform/x86: add Acer battery control driver

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

FYI [if applicable to your patch], as per Linus' policy change, also fixes are mostly routed through for-next unless the fix is for a commit introduced in the most recent cycle or is clearly a regression fix.

The list of commits applied:
[1/1] platform/x86: add Acer battery control driver

      commit: b36ee17b40037845eb2f29c151a65c698f273d4e

--
i.