platform/x86: add Acer battery control driver
v4 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
drivers/platform/x86/Kconfig | 12 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/acer-wmi-battery.c | 445 ++++++++++++++++++++++++ 3 files changed, 458 insertions(+) create mode 100644 drivers/platform/x86/acer-wmi-battery.c
Signature · 1 line
2.54.0
PATCH v4 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.
---
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.
--- drivers/platform/x86/Kconfig | 12 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/acer-wmi-battery.c | 445 ++++++++++++++++++++++++ 3 files changed, 458 insertions(+) create mode 100644 drivers/platform/x86/acer-wmi-battery.c
drivers/platform/x86/Kconfig +12 -0
@@ -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
@@ -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 +445 -0
445 lines not on this page · raw message
Signature · 1 line
2.54.0
Am 31.05.26 um 11:05 schrieb Jelle van der Waa:
Quoted 7 lines
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.
Good work, i tested it on my old Aspire notebook (v1 interface) and i can confirm that the temperature reading and DMI whitelist works as intended.
I found a couple of minor issues, once those are addressed:
Quoted 131 lines
Signed-off-by Jelle van der Waa <[email protected]>---
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__initand 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
- Simplifiedacer_wmi_battery_set_battery_health_controltoacer_wmi_set_battery_health_control
- Use sizeof foracpi_objectbuffer
- DropPOWER_SUPPLY_EXTENSIONmacro
v2:
- Alphabetically sort linux headers
- Include headers for types /_packed
- Usecleanup.hinstead of goto + label
- Add missing prefix forset_battery_health_control
- General code formatting fixes
- Remove HWMON dependency inKconfig
- Usewmidev_evaluate_method()
- Accept oversized ACPI buffers
- UseDRIVER_NAMEfor battery extension name
- Setno_singleton= true
- Implement DMI matching to support laptops with only battery
temperature support.--- drivers/platform/x86/Kconfig | 12 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/acer-wmi-battery.c | 445 ++++++++++++++++++++++++ 3 files changed, 458 insertions(+)create mode 100644
drivers/platform/x86/acer-wmi-battery.cdrivers/platform/x86/Kconfig +12
-0@@ -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_SWBUTTONdrivers/platform/x86/Makefile +1
-0@@ -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 +54
-0@@ -0,0 +1,445 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* acer-wmi-battery.c: Acer battery health control driver +* +* This is a driver for the WMI battery health control interface found +* on some Acer laptops. This interface allows to enable/disable a +* battery charge limit ("health mode") and exposes the battery temperature. +* +* Based on acer-wmi-battery https://github.com/frederik-h/acer-wmi-battery/ +* +* Copyright (C) 2022-2025 Frederik Harwath <[email protected]> +*/ + +#include <linux/acpi.h> +#include <linux/cleanup.h> +#include <linux/compiler_attributes.h> +#include <linux/dmi.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/limits.h> +#include <linux/module.h> +#include <linux/power_supply.h> +#include <linux/types.h> +#include <linux/unaligned.h> +#include <linux/version.h> +#include <linux/wmi.h> + +#include <acpi/battery.h> + +#define DRIVER_NAME "acer-wmi-battery" + +#define ACER_BATTERY_GUID "79772EC5-04B1-4BFD-843C-61E7F77B6CC9" + +/* +* The Acer OEM software seems to always use this battery index, +* so we emulate this behaviour to not confuse the underlying firmware. +* +* However this also means that we only fully support devices with a +* single battery for now. +*/ +#define ACER_BATTERY_INDEX 0x1 + +struct get_battery_health_control_status_input { +u8 battery_no; +u8 function_query; +u8 reserved[2 ]; +} __packed; + +struct get_battery_health_control_status_output { +u8 function_list; +u8 ret[2 ]; +u8 function_status[5 ]; +} __packed; +
drivers/platform/x86/acer-wmi-battery.c line 64
Quoted 10 lines
drivers/platform/x86/acer-wmi-battery.c new file +10
-0+struct set_battery_health_control_input { +u8 battery_no; +u8 function_mask; +u8 function_status; +u8 reserved_in[5 ]; +} __packed; + +struct set_battery_health_control_output { +u8 ret; +u8 reserved_out;
Hi,
when looking at the BMOF content it seems that both field are actually 16-bit wide. Please fix this by using __le16 instead of u8.
[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]);
};
I suggest you write a tiny bit of documentation under Documentation/wmi/devices/ using this MOF description. This way future developers can better understand the WMI interface used by this driver.
Quoted 11 lines
drivers/platform/x86/acer-wmi-battery.c new file +11
-0+} __packed; + +enum battery_mode { +HEALTH_MODE =1 , +CALIBRATION_MODE =2 , +}; + +struct acer_wmi_battery_data { +struct acpi_battery_hook hook; +struct wmi_device *wdev; +const struct power_supply_ext *battery_ext;
drivers/platform/x86/acer-wmi-battery.c line 85
Quoted 10 lines
drivers/platform/x86/acer-wmi-battery.c new file +10
-0+}; + +bool health_mode; + +static int acer_wmi_battery_get_information (struct acer_wmi_battery_data *data, +u32 index,u32 battery,u32 *result) +{ +u32 args[2 ] = { index, battery }; +struct wmi_buffer input = { .length =sizeof (args), .data = args }; +struct wmi_buffer output = {0 };
Nit: You do not need to initialize the output buffer, this is being done by the WMI driver core itself.
drivers/platform/x86/acer-wmi-battery.c line 88
Quoted 3 lines
drivers/platform/x86/acer-wmi-battery.c new file +3
-0+int ret; + + ret =wmidev_invoke_method (data->wdev,0 ,19 , &input, &output,sizeof (u32));
Nit: Replace sizeof(u32) with sizeof(*result).
Quoted 16 lines
drivers/platform/x86/acer-wmi-battery.c new file +16
-0+if (ret) +return ret; + + *result =get_unaligned_le32 (output.data); +kfree (output.data); + +return 0 ; +} + +static int acer_wmi_battery_get_health_control_status (struct acer_wmi_battery_data *data, +bool *health_mode) +{ +/* +* Acer Care Center seems to always call the WMI method +* with fixed parameters. This yields information about +* the availability and state of both health and
drivers/platform/x86/acer-wmi-battery.c line 114
Quoted 10 lines
drivers/platform/x86/acer-wmi-battery.c new file +10
-0+* calibration mode. The modes probably apply to +* all batteries of the system. +*/ +struct get_battery_health_control_status_input args = { + .battery_no =ACER_BATTERY_INDEX , + .function_query =0x1 , + .reserved = {0x0 ,0x0 }, + }; +struct wmi_buffer input = { .length =sizeof (args), .data = &args }; +struct wmi_buffer output = {0 };
Nit: Same issue as above.
Quoted 24 lines
drivers/platform/x86/acer-wmi-battery.c new file +24
-0+int ret; + + ret =wmidev_invoke_method (data->wdev,0 ,20 , &input, &output, +sizeof (struct get_battery_health_control_status_output )); +if (ret) +return ret; + + struct get_battery_health_control_status_output *status_output __free(kfree) = output.data; + +if (health_mode) { +if (!(status_output->function_list &HEALTH_MODE )) +return -EINVAL ; + + *health_mode = status_output->function_status[0 ] >0 ; + } + +return 0 ; +} + +static int acer_wmi_battery_set_health_control (struct acer_wmi_battery_data *data, +u8 function,bool function_status) +{ +struct set_battery_health_control_input args = { + .battery_no =ACER_BATTERY_INDEX ,
drivers/platform/x86/acer-wmi-battery.c line 148
Quoted 10 lines
drivers/platform/x86/acer-wmi-battery.c new file +10
-0+ .function_mask = function, + .function_status = function_status ? 1 : 0, + .reserved_in = { 0x0, 0x0, 0x0, 0x0, 0x0 }, + }; +struct wmi_buffer input = { .length =sizeof (args), .data = &args }; +int ret; + + ret =wmidev_invoke_procedure (data->wdev,0 ,21 , &input); +if (ret) +return ret;
The BMOF content suggest that the WMI method does return (currently unused) data. Please ensure that we actually receive this data because failing WMI method sometimes signal failure by returning not enough output data.
(You only have to verify that you received at least sizeof(struct set_battery_health_control_output) bytes, but i would be very happy if you could find out the value of the "ret" field inside struct set_battery_health_control_output used to indicate success)
Quoted 18 lines
drivers/platform/x86/acer-wmi-battery.c new file +18
-0+ +return 0 ; +} + +static int acer_battery_ext_property_get (struct power_supply *psy, +const struct power_supply_ext *ext, +void *ext_data, +enum power_supply_property psp, +union power_supply_propval *val) +{ +struct acer_wmi_battery_data *data = ext_data; +bool health_mode; +u32 value; +int ret; + +switch (psp) { +case POWER_SUPPLY_PROP_CHARGE_TYPES : + ret =acer_wmi_battery_get_health_control_status (data, &health_mode);
drivers/platform/x86/acer-wmi-battery.c line 176
Quoted 10 lines
drivers/platform/x86/acer-wmi-battery.c new file +10
-0+if (ret) +return ret; + + val->intval = health_mode ?POWER_SUPPLY_CHARGE_TYPE_LONGLIFE + :POWER_SUPPLY_CHARGE_TYPE_STANDARD ; +break ; +case POWER_SUPPLY_PROP_TEMP : + ret =acer_wmi_battery_get_information (data,0x8 ,ACER_BATTERY_INDEX , &value); +if (ret) +return ret;
Nit: Please put an empty line here.
Quoted 165 lines
drivers/platform/x86/acer-wmi-battery.c new file +165
-0+if (value >U16_MAX ) +return -ERANGE ; + + val->intval = value -2731 ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int acer_battery_ext_property_set (struct power_supply *psy, +const struct power_supply_ext *ext, +void *ext_data, +enum power_supply_property psp, +const union power_supply_propval *val) +{ +struct acer_wmi_battery_data *data = ext_data; + +switch (psp) { +case POWER_SUPPLY_PROP_CHARGE_TYPES : +return acer_wmi_battery_set_health_control (data,HEALTH_MODE , + val->intval ==POWER_SUPPLY_CHARGE_TYPE_LONGLIFE ); +default : +return -EINVAL ; + } +} + +static int acer_battery_ext_property_is_writeable (struct power_supply *psy, +const struct power_supply_ext *ext, +void *ext_data, +enum power_supply_property psp) +{ +switch (psp) { +case POWER_SUPPLY_PROP_CHARGE_TYPES : +return true; +default : +return false; + } +} + +static const struct dmi_system_id acer_wmi_battery_health_mode_table[]__initconst = { + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Aspire A315-510P" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Aspire A315-24PT" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Aspire A315-44P" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Aspire A315-59" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Aspire A315-59" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Aspire A315-510P" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Aspire A715-42G" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Nitro ANV15-51" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Nitro AN515-57" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Nitro AN515-58" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Nitro AN517-54" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Nitro AN517-54" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Predator PHN16-71" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Swift SF314-34" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Swift SF314-43" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Swift SFE16-44" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Swift SFG16-72" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Swift SFX14-71G" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Swift SFX16-61G" ) + } + }, + {} +}; + +static const enum power_supply_property acer_battery_properties_v1[] = { +POWER_SUPPLY_PROP_TEMP , +}; + +static const enum power_supply_property acer_battery_properties_v2[] = {
drivers/platform/x86/acer-wmi-battery.c line 351
Quoted 10 lines
drivers/platform/x86/acer-wmi-battery.c new file +10
-0+POWER_SUPPLY_PROP_TEMP , + POWER_SUPPLY_PROP_CHARGE_TYPES, +}; + +static const struct power_supply_ext acer_wmi_battery_extension_v1 = { + .name =DRIVER_NAME , + .properties = acer_battery_properties_v1, + .num_properties =ARRAY_SIZE (acer_battery_properties_v1), + .get_property = acer_battery_ext_property_get, + .set_property = acer_battery_ext_property_set,
Populating the .set_property callback when no writable properties are present is unnecessary, please remove.
Quoted 61 lines
drivers/platform/x86/acer-wmi-battery.c new file +61
-0+ .property_is_writeable = acer_battery_ext_property_is_writeable, +}; + +static const struct power_supply_ext acer_wmi_battery_extension_v2 = { + .name =DRIVER_NAME , + .properties = acer_battery_properties_v2, + .num_properties =ARRAY_SIZE (acer_battery_properties_v2), + .charge_types =BIT (POWER_SUPPLY_CHARGE_TYPE_STANDARD ) | +BIT (POWER_SUPPLY_CHARGE_TYPE_LONGLIFE ), + .get_property = acer_battery_ext_property_get, + .set_property = acer_battery_ext_property_set, + .property_is_writeable = acer_battery_ext_property_is_writeable, +}; + +static int acer_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) +{ + struct acer_wmi_battery_data *data = container_of(hook, struct acer_wmi_battery_data, hook); + +return power_supply_register_extension (battery, data->battery_ext, + &data->wdev->dev, data); +} + +static int acer_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) +{ + struct acer_wmi_battery_data *data = container_of(hook, struct acer_wmi_battery_data, hook); + +power_supply_unregister_extension (battery, data->battery_ext); + +return 0 ; +} + +static int acer_wmi_battery_probe (struct wmi_device *wdev,const void *context) +{ +struct acer_wmi_battery_data *data; + + data =devm_kzalloc (&wdev->dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + +dev_set_drvdata (&wdev->dev, data); + data->wdev = wdev; + data->battery_ext = health_mode ? &acer_wmi_battery_extension_v2 + : &acer_wmi_battery_extension_v1; + data->hook.name ="Acer Battery Extension" ; + data->hook.add_battery = acer_battery_add; + data->hook.remove_battery = acer_battery_remove; + +return devm_battery_hook_register (&data->wdev->dev, &data->hook); +} + +static const struct wmi_device_id acer_wmi_battery_id_table[] = { + {ACER_BATTERY_GUID ,NULL }, + { } +}; +MODULE_DEVICE_TABLE (wmi, acer_wmi_battery_id_table); + +static struct wmi_driver acer_wmi_battery_driver = { + .driver = { + .name =DRIVER_NAME , + .probe_type =PROBE_PREFER_ASYNCHRONOUS , + },
drivers/platform/x86/acer-wmi-battery.c line 422
Quoted 10 lines
drivers/platform/x86/acer-wmi-battery.c new file +10
-0+ .id_table = acer_wmi_battery_id_table, + .probe = acer_wmi_battery_probe, + .no_singleton = true, +}; + +static int __init acer_wmi_battery_module_init (void ) +{ +int r; + +if (dmi_check_system (acer_wmi_battery_health_mode_table))
Maybe you could add a "force" module parameter using:
static bool force;module_param_unsafe(force, bool, 0);MODULE_PARM_DESC(force, "Enable health mode control without checking for supported devices\n");
This way users can optionally override the whitelist for testing new notebook models.
drivers/platform/x86/acer-wmi-battery.c line 431
Quoted 9 lines
drivers/platform/x86/acer-wmi-battery.c new file +9
-0+ health_mode = true; + else + health_mode = false; + + r =wmi_driver_register (&acer_wmi_battery_driver); +if (r) +return r; + +return r;
Nit: Please use "ret" instead of "r".
Thanks,
Armin Wolf
Quoted 14 lines
drivers/platform/x86/acer-wmi-battery.c new file +14
-0+} + +static void __exit acer_wmi_battery_module_exit(void) +{ +wmi_driver_unregister (&acer_wmi_battery_driver); +} + +module_init (acer_wmi_battery_module_init); +module_exit (acer_wmi_battery_module_exit); + +MODULE_AUTHOR ("Frederik Harwath <[email protected]>" ); +MODULE_AUTHOR ("Jelle van der Waa <[email protected]>" ); +MODULE_DESCRIPTION ("Acer battery health control WMI driver" ); +MODULE_LICENSE ("GPL" );
Hi,
Quoted 10 lines · Armin Wolf
Am 31.05.26 um 11:05 schrieb Jelle van der Waa:
Quoted 7 lines
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.
Quoted 6 lines
Good work, i tested it on my old Aspire notebook (v1 interface) and i can confirm that the temperature reading and DMI whitelist works as intended.
I found a couple of minor issues, once those are addressed:
Reviewed-by Armin Wolf <[email protected]>
Sorry for the long hiatus, I send a v5 yesterday and forgot to include this. If it is needed to send a v6 I will include it and send that as soon as possible.
Quoted 17 lines
[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.")] voidGetBattInfoInterface([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]);
};
Quoted 2 lines
I suggest you write a tiny bit of documentation under
Documentation/wmi/devices/ using this MOF description. This way future developers can better understand the WMI interface used by this driver.
Thanks for poking me to write this, this was the first time writing a WMI driver and writing a bit of documentation definitively made everything click in my head.
It also sparked my curiosity. I know you added the temperature reading and referenced "Smart Battery Data Specification", did you try any of the other fields (such as manufacturer?) [1]
[1] https://sbs-forum.org/specs/sbdat110.pdf
Thanks for the review,
Jelle van der Waa
Am 06.08.26 um 17:18 schrieb Jelle van der Waa:
Quoted 13 lines
Hi,
Quoted 10 lines · Armin Wolf
Am 31.05.26 um 11:05 schrieb Jelle van der Waa:
Quoted 7 lines
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.
Quoted 8 lines
Quoted 6 lines
Good work, i tested it on my old Aspire notebook (v1 interface) and i can confirm that the temperature reading and DMI whitelist works as intended.
I found a couple of minor issues, once those are addressed:
Reviewed-by Armin Wolf <[email protected]>Sorry for the long hiatus, I send a v5 yesterday and forgot to include this. If it is needed to send a v6 I will include it and send that as soon as possible.
No problem, just include this tag with the v6.
Thanks,
Armin Wolf
Quoted 25 lines
Quoted 12 lines
[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.")] voidGetBattInfoInterface([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]);
};Quoted 2 lines
I suggest you write a tiny bit of documentation under
Documentation/wmi/devices/ using this MOF description. This way future developers can better understand the WMI interface used by this driver.Thanks for poking me to write this, this was the first time writing a WMI driver and writing a bit of documentation definitively made everything click in my head.
It also sparked my curiosity. I know you added the temperature reading and referenced "Smart Battery Data Specification", did you try any of the other fields (such as manufacturer?) [1]
[1] https://sbs-forum.org/specs/sbdat110.pdf
Thanks for the review,
Jelle van der Waa
Ilpo Järvinen
maintainerQuoted 8 lines · Jelle van der Waa
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.
Quoted 8 lines
Signed-off-by Jelle van der Waa <[email protected]>---
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__initand make the DMI table__initconst
- Port to the new wmidev_invoke_* API
Thanks for the update. Some small things still noted below.
Quoted 144 lines
v3:
- Add depends on DMI
- Rename CamelCase struct member names
- Simplify returning errors
- Add comma to non-terminating entries
- Simplifiedacer_wmi_battery_set_battery_health_controltoacer_wmi_set_battery_health_control
- Use sizeof foracpi_objectbuffer
- DropPOWER_SUPPLY_EXTENSIONmacro
v2:
- Alphabetically sort linux headers
- Include headers for types /_packed
- Usecleanup.hinstead of goto + label
- Add missing prefix forset_battery_health_control
- General code formatting fixes
- Remove HWMON dependency inKconfig
- Usewmidev_evaluate_method()
- Accept oversized ACPI buffers
- UseDRIVER_NAMEfor battery extension name
- Setno_singleton= true
- Implement DMI matching to support laptops with only battery
temperature support.--- drivers/platform/x86/Kconfig | 12 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/acer-wmi-battery.c | 445 ++++++++++++++++++++++++ 3 files changed, 458 insertions(+) create mode 100644 drivers/platform/x86/acer-wmi-battery.cdrivers/platform/x86/Kconfig +12
-0@@ -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_SWBUTTONdrivers/platform/x86/Makefile +1
-0@@ -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 +75
-0@@ -0,0 +1,445 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* acer-wmi-battery.c: Acer battery health control driver +* +* This is a driver for the WMI battery health control interface found +* on some Acer laptops. This interface allows to enable/disable a +* battery charge limit ("health mode") and exposes the battery temperature. +* +* Based on acer-wmi-battery https://github.com/frederik-h/acer-wmi-battery/ +* +* Copyright (C) 2022-2025 Frederik Harwath <[email protected]> +*/ + +#include <linux/acpi.h> +#include <linux/cleanup.h> +#include <linux/compiler_attributes.h> +#include <linux/dmi.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/limits.h> +#include <linux/module.h> +#include <linux/power_supply.h> +#include <linux/types.h> +#include <linux/unaligned.h> +#include <linux/version.h> +#include <linux/wmi.h> + +#include <acpi/battery.h> + +#define DRIVER_NAME "acer-wmi-battery" + +#define ACER_BATTERY_GUID "79772EC5-04B1-4BFD-843C-61E7F77B6CC9" + +/* +* The Acer OEM software seems to always use this battery index, +* so we emulate this behaviour to not confuse the underlying firmware. +* +* However this also means that we only fully support devices with a +* single battery for now. +*/ +#define ACER_BATTERY_INDEX 0x1 + +struct get_battery_health_control_status_input { +u8 battery_no; +u8 function_query; +u8 reserved[2 ]; +} __packed; + +struct get_battery_health_control_status_output { +u8 function_list; +u8 ret[2 ]; +u8 function_status[5 ]; +} __packed; + +struct set_battery_health_control_input { +u8 battery_no; +u8 function_mask; +u8 function_status; +u8 reserved_in[5 ]; +} __packed; + +struct set_battery_health_control_output { +u8 ret; +u8 reserved_out; +} __packed; + +enum battery_mode { +HEALTH_MODE =1 , +CALIBRATION_MODE =2 , +}; + +struct acer_wmi_battery_data { +struct acpi_battery_hook hook; +struct wmi_device *wdev; +const struct power_supply_ext *battery_ext;
drivers/platform/x86/acer-wmi-battery.c line 85
Quoted 10 lines
drivers/platform/x86/acer-wmi-battery.c new file +10
-0+}; + +bool health_mode; + +static int acer_wmi_battery_get_information (struct acer_wmi_battery_data *data, +u32 index,u32 battery,u32 *result) +{ +u32 args[2 ] = { index, battery }; +struct wmi_buffer input = { .length =sizeof (args), .data = args }; +struct wmi_buffer output = {0 };
= {} would be enough to initialize it but I see Armin noted this is unnecesary so please follow his advice.
drivers/platform/x86/acer-wmi-battery.c line 92
Quoted 7 lines
drivers/platform/x86/acer-wmi-battery.c new file +7
-0+int ret; + + ret =wmidev_invoke_method (data->wdev,0 ,19 , &input, &output,sizeof (u32)); +if (ret) +return ret; + + *result =get_unaligned_le32 (output.data);
My impression was that the data is always aligned by wmi core:
"Said data is guaranteed to be aligned on a 8-byte boundary."
You probably don't need the related header afterwards either.
Quoted 12 lines
drivers/platform/x86/acer-wmi-battery.c new file +12
-0+kfree (output.data); + +return 0 ; +} + +static int acer_wmi_battery_get_health_control_status (struct acer_wmi_battery_data *data, +bool *health_mode) +{ +/* +* Acer Care Center seems to always call the WMI method +* with fixed parameters. This yields information about +* the availability and state of both health and
drivers/platform/x86/acer-wmi-battery.c line 114
Quoted 10 lines
drivers/platform/x86/acer-wmi-battery.c new file +10
-0+* calibration mode. The modes probably apply to +* all batteries of the system. +*/ +struct get_battery_health_control_status_input args = { + .battery_no =ACER_BATTERY_INDEX , + .function_query =0x1 , + .reserved = {0x0 ,0x0 }, + }; +struct wmi_buffer input = { .length =sizeof (args), .data = &args }; +struct wmi_buffer output = {0 };
Unnecessary init here as well.
Quoted 56 lines
drivers/platform/x86/acer-wmi-battery.c new file +56
-0+int ret; + + ret =wmidev_invoke_method (data->wdev,0 ,20 , &input, &output, +sizeof (struct get_battery_health_control_status_output )); +if (ret) +return ret; + + struct get_battery_health_control_status_output *status_output __free(kfree) = output.data; + +if (health_mode) { +if (!(status_output->function_list &HEALTH_MODE )) +return -EINVAL ; + + *health_mode = status_output->function_status[0 ] >0 ; + } + +return 0 ; +} + +static int acer_wmi_battery_set_health_control (struct acer_wmi_battery_data *data, +u8 function,bool function_status) +{ +struct set_battery_health_control_input args = { + .battery_no =ACER_BATTERY_INDEX , + .function_mask = function, + .function_status = function_status ?1 :0 , + .reserved_in = {0x0 ,0x0 ,0x0 ,0x0 ,0x0 }, + }; +struct wmi_buffer input = { .length =sizeof (args), .data = &args }; +int ret; + + ret =wmidev_invoke_procedure (data->wdev,0 ,21 , &input); +if (ret) +return ret; + +return 0 ; +} + +static int acer_battery_ext_property_get (struct power_supply *psy, +const struct power_supply_ext *ext, +void *ext_data, +enum power_supply_property psp, +union power_supply_propval *val) +{ +struct acer_wmi_battery_data *data = ext_data; +bool health_mode; +u32 value; +int ret; + +switch (psp) { +case POWER_SUPPLY_PROP_CHARGE_TYPES : + ret =acer_wmi_battery_get_health_control_status (data, &health_mode); +if (ret) +return ret; + + val->intval = health_mode ? POWER_SUPPLY_CHARGE_TYPE_LONGLIFE
drivers/platform/x86/acer-wmi-battery.c line 180
Quoted 10 lines
drivers/platform/x86/acer-wmi-battery.c new file +10
-0+ : POWER_SUPPLY_CHARGE_TYPE_STANDARD; +break ; +case POWER_SUPPLY_PROP_TEMP : + ret =acer_wmi_battery_get_information (data,0x8 ,ACER_BATTERY_INDEX , &value); +if (ret) +return ret; +if (value >U16_MAX ) +return -ERANGE ; + + val->intval = value -2731 ;
We can derive that literal from constant defs:
ABSOLUTE_ZERO_MILLICELSIUS / MILLIDEGREE_PER_DECIDEGREE
Whether you want to comment about losing the 50 millidegrees from ABSOLUTE_ZERO_MILLICELSIUS or not, I leave up to you.
Quoted 141 lines
drivers/platform/x86/acer-wmi-battery.c new file +141
-0+break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int acer_battery_ext_property_set (struct power_supply *psy, +const struct power_supply_ext *ext, +void *ext_data, +enum power_supply_property psp, +const union power_supply_propval *val) +{ +struct acer_wmi_battery_data *data = ext_data; + +switch (psp) { +case POWER_SUPPLY_PROP_CHARGE_TYPES : +return acer_wmi_battery_set_health_control (data,HEALTH_MODE , + val->intval ==POWER_SUPPLY_CHARGE_TYPE_LONGLIFE ); +default : +return -EINVAL ; + } +} + +static int acer_battery_ext_property_is_writeable (struct power_supply *psy, +const struct power_supply_ext *ext, +void *ext_data, +enum power_supply_property psp) +{ +switch (psp) { +case POWER_SUPPLY_PROP_CHARGE_TYPES : +return true; +default : +return false; + } +} + +static const struct dmi_system_id acer_wmi_battery_health_mode_table[]__initconst = { + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Aspire A315-510P" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Aspire A315-24PT" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Aspire A315-44P" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Aspire A315-59" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Aspire A315-59" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Aspire A315-510P" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Aspire A715-42G" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Nitro ANV15-51" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Nitro AN515-57" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Nitro AN515-58" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Nitro AN517-54" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Nitro AN517-54" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Predator PHN16-71" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Swift SF314-34" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Swift SF314-43" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Swift SFE16-44" ) + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Swift SFG16-72" ) + } + },
drivers/platform/x86/acer-wmi-battery.c line 331
Quoted 10 lines
drivers/platform/x86/acer-wmi-battery.c new file +10
-0+ { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), + DMI_MATCH(DMI_PRODUCT_NAME, "Swift SFX14-71G") + } + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Swift SFX16-61G" )
Pleaese add the trailing commas to any non-terminating entry.
Quoted 115 lines
drivers/platform/x86/acer-wmi-battery.c new file +114
-0+ } + }, + {} +}; + +static const enum power_supply_property acer_battery_properties_v1[] = { +POWER_SUPPLY_PROP_TEMP , +}; + +static const enum power_supply_property acer_battery_properties_v2[] = { +POWER_SUPPLY_PROP_TEMP , +POWER_SUPPLY_PROP_CHARGE_TYPES , +}; + +static const struct power_supply_ext acer_wmi_battery_extension_v1 = { + .name =DRIVER_NAME , + .properties = acer_battery_properties_v1, + .num_properties =ARRAY_SIZE (acer_battery_properties_v1), + .get_property = acer_battery_ext_property_get, + .set_property = acer_battery_ext_property_set, + .property_is_writeable = acer_battery_ext_property_is_writeable, +}; + +static const struct power_supply_ext acer_wmi_battery_extension_v2 = { + .name =DRIVER_NAME , + .properties = acer_battery_properties_v2, + .num_properties =ARRAY_SIZE (acer_battery_properties_v2), + .charge_types =BIT (POWER_SUPPLY_CHARGE_TYPE_STANDARD ) | +BIT (POWER_SUPPLY_CHARGE_TYPE_LONGLIFE ), + .get_property = acer_battery_ext_property_get, + .set_property = acer_battery_ext_property_set, + .property_is_writeable = acer_battery_ext_property_is_writeable, +}; + +static int acer_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) +{ + struct acer_wmi_battery_data *data = container_of(hook, struct acer_wmi_battery_data, hook); + +return power_supply_register_extension (battery, data->battery_ext, + &data->wdev->dev, data); +} + +static int acer_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) +{ + struct acer_wmi_battery_data *data = container_of(hook, struct acer_wmi_battery_data, hook); + +power_supply_unregister_extension (battery, data->battery_ext); + +return 0 ; +} + +static int acer_wmi_battery_probe (struct wmi_device *wdev,const void *context) +{ +struct acer_wmi_battery_data *data; + + data =devm_kzalloc (&wdev->dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + +dev_set_drvdata (&wdev->dev, data); + data->wdev = wdev; + data->battery_ext = health_mode ? &acer_wmi_battery_extension_v2 + : &acer_wmi_battery_extension_v1; + data->hook.name ="Acer Battery Extension" ; + data->hook.add_battery = acer_battery_add; + data->hook.remove_battery = acer_battery_remove; + +return devm_battery_hook_register (&data->wdev->dev, &data->hook); +} + +static const struct wmi_device_id acer_wmi_battery_id_table[] = { + {ACER_BATTERY_GUID ,NULL }, + { } +}; +MODULE_DEVICE_TABLE (wmi, acer_wmi_battery_id_table); + +static struct wmi_driver acer_wmi_battery_driver = { + .driver = { + .name =DRIVER_NAME , + .probe_type =PROBE_PREFER_ASYNCHRONOUS , + }, + .id_table = acer_wmi_battery_id_table, + .probe = acer_wmi_battery_probe, + .no_singleton = true, +}; + +static int __init acer_wmi_battery_module_init (void ) +{ +int r; + +if (dmi_check_system (acer_wmi_battery_health_mode_table)) + health_mode = true; +else + health_mode = false; + + r =wmi_driver_register (&acer_wmi_battery_driver); +if (r) +return r; + +return r; +} + +static void __exit acer_wmi_battery_module_exit(void) +{ +wmi_driver_unregister (&acer_wmi_battery_driver); +} + +module_init (acer_wmi_battery_module_init); +module_exit (acer_wmi_battery_module_exit); + +MODULE_AUTHOR ("Frederik Harwath <[email protected]>" ); +MODULE_AUTHOR ("Jelle van der Waa <[email protected]>" ); +MODULE_DESCRIPTION ("Acer battery health control WMI driver" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
i.