platform/x86: Add Emdoor Intel EWMI platform driver
Subsystems (3)
v2 cover platform/x86: Add Emdoor Intel EWMI platform driver
This series adds a pure-WMI Linux platform driver for the Intel EWMI (\_SB.EWMI) interface found on Emdoor-based Intel laptops, verified on the MECHREVO Wujie 14 2026 (WUJIE Series-Lark4-LNL, Intel Core Ultra 5 226V Lunar Lake, BIOS EM_LNL326_V1.0.19).
In response to review feedback on RFC v1 regarding direct EC register access, v2 removes every ec_read() call and every board/BIOS-specific EC offset so the driver operates strictly through standard ACPI WMI methods (WMCD and _WED(0xD0)) using wmi_driver / wmidev_invoke_method(), gated by WMI GUID and WMCD GVER protocol version 1.0.1.0:
- Dual fan tachometers (fan1_input, fan2_input) via hwmon (WMCD GFNS)
- Platform profile (balanced / performance) via WMCD GPFM / SPFM, synced with Fn+X hardware profile-switch events
- Read-only touchpad_enabled sysfs attribute via WMCD GTPS (0x03/0x07)
- Sparse keymap input reporting for _WED(0xD0) hotkey events
Notes on firmware quirks and dropped RFC v1 features:
- Legacy WMAA-WMCB methods on this DSDT allocate an 8-byte Local0 inside AML and define CreateField(Local0, 0x20, 0x3F, RES3), aborting with AE_AML_BUFFER_LIMIT regardless of input buffer size; they are unused.
- EC temperature sensors (TSR1..TSR4) are dropped because TSR2..TSR4 are already exposed via int3403_thermal (SEN2..SEN4 under \_SB.IETM) and CPU temperature is already covered by coretemp / x86_pkg_temp / TCPU.
- fn_lock / win_lock (EC5D 20 ms mailbox race) and auto_power_on (WMCC write-only with EC 0xF5 readback) are dropped so v2 has zero direct EC access and zero per-BIOS DMI tables.
- SPFM (0x03/0x0a) arms ZZTT/TIZZ before Notify(IETM, 0x88) and before writing EC5F, so an EC scan during the notify can consume a stale EC5F and return RTNC=0 without updating PPMD (or return RTNC=1). The driver verifies WMCD 0x03/0x09 readback and reissues the absolute mode up to 3 times using pure WMI calls.
- Sanitized ACPI tables (DSDT + SSDT1..SSDT28, Windows licensing table omitted) and decoded ewmi.mof are available at:
https://gist.github.com/winddd666/8f739d1cab5beb503f606093ade10d65
---
Changes in v2:
- Drop RFC prefix.
- Remove all direct ec_read() calls, ACPI_EC dependency, and per-BIOS
DMI/EC offset tables (drop temp_regs, fn_lock, win_lock, and
auto_power_on / WMCC driver).
- Keep the driver strictly pure WMI (WMCD + _WED(0xD0)) using WMI GUID
matching and WMCD GVER (1.0.1.0) protocol version validation.
- Update ABI documentation, Kconfig, and commit descriptions accordingly.
- Link to v1: https://patch.msgid.link/[email protected]
To: Armin Wolf <[email protected]>
To: Ziqiang Xia <[email protected]>
To: Hans de Goede <[email protected]>
To: Ilpo Järvinen <[email protected]>
To: Guenter Roeck <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
Ziqiang Xia (2):
Documentation: ABI: testing: Add emdoor-intel-wmi sysfs ABI platform/x86: Add Emdoor Intel EWMI platform driver
.../ABI/testing/sysfs-bus-wmi-devices-emdoor-ewmi | 7 + MAINTAINERS | 7 + drivers/platform/x86/Kconfig | 16 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/emdoor-intel-wmi.c | 494 +++++++++++++++++++++ 5 files changed, 525 insertions(+)
---
base-commit: 5680519168f65666d2c03cc6ed8fe2b7052aee12
change-id: 20261113-emdoor-intel-wmi-rfc-2173530b3df6
Best regards,
Signature · 1 line
Ziqiang Xia <[email protected]>
PATCH v2 1/2 Documentation: ABI: testing: Add emdoor-intel-wmi sysfs ABI
Document the read-only touchpad_enabled sysfs attribute exposed by the Emdoor Intel EWMI platform driver.
--- Documentation/ABI/testing/sysfs-bus-wmi-devices-emdoor-ewmi | 7 +++++++ MAINTAINERS | 6 ++++++ 2 files changed, 13 insertions(+)
Documentation/ABI/testing/sysfs-bus-wmi-devices-emdoor-ewmi new file +7 -0
@@ -0,0 +1,7 @@ +What: /sys/bus/wmi/devices/0B30FD67-1B62-4FCA-B10B-50DC7ADE6A39-*/touchpad_enabled +Date: November 2026 +KernelVersion: 7.4 +Contact: [email protected] +Description: + (RO) Firmware touchpad enable state ("0" or "1") queried via + WMCD GTPS (0x03/0x07).
MAINTAINERS +6 -0
@@ -9848,6 +9848,12 @@ T: git git://linuxtv.org/media.git F: Documentation/admin-guide/media/em28xx* F: drivers/media/usb/em28xx/ +EMDOOR INTEL EWMI DRIVER +M: Ziqiang Xia <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/ABI/testing/sysfs-bus-wmi-devices-emdoor-ewmi + EMMC CMDQ HOST CONTROLLER INTERFACE (CQHCI) DRIVER M: Adrian Hunter <[email protected]> M: Asutosh Das <[email protected]>
Signature · 1 line
2.56.1
Ilpo Järvinen
maintainerRe: [PATCH v2 1/2] Documentation: ABI: testing: Add emdoor-intel-wmi sysfs ABI
Quoted 17 lines · On Mon, 23 Nov 2026, Ziqiang Xia via B4 Relay wrote:
From: Ziqiang Xia <[email protected]>
Document the read-only
touchpad_enabledsysfs attribute exposed by the Emdoor Intel EWMI platform driver.Signed-off-by Ziqiang Xia <[email protected]>--- Documentation/ABI/testing/sysfs-bus-wmi-devices-emdoor-ewmi | 7 +++++++ MAINTAINERS | 6 ++++++ 2 files changed, 13 insertions(+)Documentation/ABI/testing/sysfs-bus-wmi-devices-emdoor-ewmi new file +0
-0
Documentation/ABI/testing/sysfs-bus-wmi-devices-emdoor-ewmi line 3
Quoted 3 lines
Documentation/ABI/testing/sysfs-bus-wmi-devices-emdoor-ewmi new file +3
-0@@ -0,0 +1,7 @@ +What: /sys/bus/wmi/devices/0B30FD67-1B62-4FCA-B10B-50DC7ADE6A39-*/touchpad_enabled +Date: November 2026 +KernelVersion: 7.4
This ship has sailed already.
Quoted 23 lines
Documentation/ABI/testing/sysfs-bus-wmi-devices-emdoor-ewmi new file +4
-0+Contact: [email protected] +Description: + (RO) Firmware touchpad enable state ("0" or "1") queried via + WMCD GTPS (0x03/0x07).MAINTAINERS +6
-0@@ -9848,6 +9848,12 @@ T: git git://linuxtv.org/media.git F: Documentation/admin-guide/media/em28xx* F: drivers/media/usb/em28xx/ +EMDOOR INTEL EWMI DRIVER +M: Ziqiang Xia <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/ABI/testing/sysfs-bus-wmi-devices-emdoor-ewmi + EMMC CMDQ HOST CONTROLLER INTERFACE (CQHCI) DRIVER M: Adrian Hunter <[email protected]> M: Asutosh Das <[email protected]>
Signature · 1 line
i.
PATCH v2 2/2 platform/x86: Add Emdoor Intel EWMI platform driver
In reply to Ziqiang XiaAdd a pure-WMI platform driver for the Emdoor Intel EWMI (\_SB.EWMI) interface (protocol version 1.0.1.0, verified on MECHREVO Wujie 14 2026 / WUJIE Series-Lark4-LNL, BIOS EM_LNL326_V1.0.19), exposing hwmon dual fan tachometers, platform_profile (balanced/performance), touchpad_enabled state, and WMI hotkey sparse keymap events without direct EC register access.
--- MAINTAINERS | 1 + drivers/platform/x86/Kconfig | 16 ++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/emdoor-intel-wmi.c | 494 ++++++++++++++++++++++++++++++++ 4 files changed, 512 insertions(+)
MAINTAINERS +1 -0
@@ -9853,6 +9853,7 @@ M: Ziqiang Xia <[email protected]> L: [email protected] S: Maintained F: Documentation/ABI/testing/sysfs-bus-wmi-devices-emdoor-ewmi +F: drivers/platform/x86/emdoor-intel-wmi.c EMMC CMDQ HOST CONTROLLER INTERFACE (CQHCI) DRIVER M: Adrian Hunter <[email protected]>
drivers/platform/x86/Kconfig +16 -0
@@ -120,6 +120,22 @@ config BITLAND_MIFS_WMI To compile this driver as a module, choose M here: the module will be called bitland-mifs-wmi. +config EMDOOR_INTEL_WMI + tristate "Emdoor Intel EWMI laptop support" + depends on ACPI_WMI + depends on HWMON + depends on INPUT + select ACPI_PLATFORM_PROFILE + select INPUT_SPARSEKMAP + help + This is a pure-WMI driver for Emdoor Intel EWMI laptops implementing + protocol version 1.0.1.0 (such as the MECHREVO Wujie 14 2026). It + exposes hwmon fan tachometers, platform_profile, touchpad state, and + WMI hotkey events. + + To compile this driver as a module, choose M here: the module will be + called emdoor-intel-wmi. + config ACERHDF tristate "Acer Aspire One temperature and fan driver" depends on ACPI_EC && THERMAL
drivers/platform/x86/Makefile +1 -0
@@ -12,6 +12,7 @@ obj-$(CONFIG_XIAOMI_WMI) += xiaomi-wmi.o obj-$(CONFIG_REDMI_WMI) += redmi-wmi.o obj-$(CONFIG_GIGABYTE_WMI) += gigabyte-wmi.o obj-$(CONFIG_BITLAND_MIFS_WMI) += bitland-mifs-wmi.o +obj-$(CONFIG_EMDOOR_INTEL_WMI) += emdoor-intel-wmi.o # Acer obj-$(CONFIG_ACERHDF) += acerhdf.o
drivers/platform/x86/emdoor-intel-wmi.c new file +494 -0
494 lines not on this page · raw message
Signature · 1 line
2.56.1
Ilpo Järvinen
maintainerQuoted 102 lines · On Mon, 23 Nov 2026, Ziqiang Xia via B4 Relay wrote:
From: Ziqiang Xia <[email protected]>
Add a pure-WMI platform driver for the Emdoor Intel EWMI (\_SB.EWMI) interface (protocol version 1.0.1.0, verified on MECHREVO Wujie 14 2026 / WUJIE Series-Lark4-LNL, BIOS EM_LNL326_V1.0.19), exposing hwmon dual fan tachometers,
platform_profile(balanced/performance),touchpad_enabledstate, and WMI hotkey sparse keymap events without direct EC register access.Signed-off-by Ziqiang Xia <[email protected]>--- MAINTAINERS | 1 + drivers/platform/x86/Kconfig | 16 ++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/emdoor-intel-wmi.c | 494 ++++++++++++++++++++++++++++++++ 4 files changed, 512 insertions(+)MAINTAINERS +1
-0@@ -9853,6 +9853,7 @@ M: Ziqiang Xia <[email protected]> L: [email protected] S: Maintained F: Documentation/ABI/testing/sysfs-bus-wmi-devices-emdoor-ewmi +F: drivers/platform/x86/emdoor-intel-wmi.c EMMC CMDQ HOST CONTROLLER INTERFACE (CQHCI) DRIVER M: Adrian Hunter <[email protected]>drivers/platform/x86/Kconfig +16
-0@@ -120,6 +120,22 @@ config BITLAND_MIFS_WMI To compile this driver as a module, choose M here: the module will be called bitland-mifs-wmi. +config EMDOOR_INTEL_WMI + tristate "Emdoor Intel EWMI laptop support" + depends on ACPI_WMI + depends on HWMON + depends on INPUT + select ACPI_PLATFORM_PROFILE + select INPUT_SPARSEKMAP + help + This is a pure-WMI driver for Emdoor Intel EWMI laptops implementing + protocol version 1.0.1.0 (such as the MECHREVO Wujie 14 2026). It + exposes hwmon fan tachometers, platform_profile, touchpad state, and + WMI hotkey events. + + To compile this driver as a module, choose M here: the module will be + called emdoor-intel-wmi. + config ACERHDF tristate "Acer Aspire One temperature and fan driver" depends on ACPI_EC && THERMALdrivers/platform/x86/Makefile +1
-0@@ -12,6 +12,7 @@ obj-$(CONFIG_XIAOMI_WMI) += xiaomi-wmi.o obj-$(CONFIG_REDMI_WMI) += redmi-wmi.o obj-$(CONFIG_GIGABYTE_WMI) += gigabyte-wmi.o obj-$(CONFIG_BITLAND_MIFS_WMI) += bitland-mifs-wmi.o +obj-$(CONFIG_EMDOOR_INTEL_WMI) += emdoor-intel-wmi.o # Acer obj-$(CONFIG_ACERHDF) += acerhdf.odrivers/platform/x86/emdoor-intel-wmi.c new file +28
-0@@ -0,0 +1,494 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Emdoor Intel EWMI platform driver. +* +* Verified on MECHREVO Wujie 14 2026 (WUJIE Series-Lark4-LNL, +* BIOS EM_LNL326_V1.0.19). +*/ + +#include <linux/bitops.h> +#include <linux/cleanup.h> +#include <linux/container_of.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/errno.h> +#include <linux/hwmon.h> +#include <linux/input.h> +#include <linux/input/sparse-keymap.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/notifier.h> +#include <linux/platform_profile.h> +#include <linux/slab.h> +#include <linux/string.h> +#include <linux/sysfs.h> +#include <linux/types.h> +#include <linux/unaligned.h> +#include <linux/wmi.h>
drivers/platform/x86/emdoor-intel-wmi.c line 38
Quoted 10 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +10
-0+#include <linux/workqueue.h> + +#define EWMI_METHOD_GUID "0B30FD67-1B62-4FCA-B10B-50DC7ADE6A39" +#define EWMI_EVENT_GUID "0B30FD67-1B62-4FCA-B10B-50DC7ADE6DDD" + +#define EWMI_INPUT_SIZE 64 +#define EWMI_OUTPUT_SIZE 256 + +enum { +EWMI_FAN_COUNT =2 ,
Can this be replaced with ARRAY_SIZE() ?
Quoted 48 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +48
-0+EWMI_PROFILE_RETRIES =3 , + EWMI_PROFILE_SETTLE_MS = 100, +}; + +struct ewmi_reply { +u8 reserved[4 ]; +u8 status; +u8 data[EWMI_OUTPUT_SIZE -1 ]; +}; + +static_assert (sizeof (struct ewmi_reply ) ==260 ); + +struct ewmi_method { +struct wmi_device *wdev; +struct mutex lock;/* Serializes WMCD firmware calls. */ +struct device *profile; +struct notifier_block event_nb; +struct work_struct profile_work; +bool profile_dirty;/* A partial set must not become a successful no-op. */ +}; + +struct ewmi_event { +struct input_dev *input; +struct mutex lock;/* Serializes input press/release sequences. */ +}; + +static BLOCKING_NOTIFIER_HEAD (ewmi_event_chain); + +/* +* WMCD returns Package(Buffer(4), Buffer(256)). The WMI core marshals +* both buffers into 260 bytes; the firmware status is at byte 4. +* Always check the full result size before accessing the payload. +*/ +static int ewmi_call_status (struct ewmi_method *priv,u8 group,u8 command, +u8 argument,void *result,size_t result_len, +bool *firmware_failure) +{ +u8 request[EWMI_INPUT_SIZE ] = { group, command, argument }; +struct wmi_buffer in = { .length =sizeof (request), .data = request }; +struct wmi_buffer out = { }; +const struct ewmi_reply *reply; +int ret; + +lockdep_assert_held (&priv->lock); +if (firmware_failure) + *firmware_failure = false; +if (result_len >sizeof (reply->data)) +return -EINVAL ;
drivers/platform/x86/emdoor-intel-wmi.c line 96
Quoted 10 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +10
-0+ + ret =wmidev_invoke_method (priv->wdev,0 ,1 , &in, &out,sizeof (*reply)); +if (ret) { +dev_warn_ratelimited (&priv->wdev->dev, +"WMCD %02x/%02x transport error %d\n" , + group, command, ret); +return ret; + } + + reply = out.data;
Please use __free() for this variable and declare it here (as per the long comment in cleanup.h).
drivers/platform/x86/emdoor-intel-wmi.c line 100
Quoted 4 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +4
-0+if (reply->status) { +if (firmware_failure && reply->status ==1 ) + *firmware_failure = true; + dev_warn_ratelimited(&priv->wdev->dev,
Include?
Quoted 16 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +16
-0+"WMCD %02x/%02x firmware status %u, data %8ph\n" , + group, command, reply->status, reply->data); + ret = -EIO ; + }else if (result_len) { +memcpy (result, reply->data, result_len); + } +kfree (out.data); +return ret; +} + +static int ewmi_call (struct ewmi_method *priv,u8 group,u8 command, +u8 argument,void *result,size_t result_len) +{ +return ewmi_call_status (priv, group, command, argument, result, + result_len,NULL ); +}
drivers/platform/x86/emdoor-intel-wmi.c line 126
Quoted 10 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +10
-0+ +static ssize_t touchpad_enabled_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct ewmi_method *priv =dev_get_drvdata (dev); +u8 value; +int ret; + +guard (mutex)(&priv->lock); + ret =ewmi_call (priv,0x03 ,0x07 ,0 , &value,sizeof (value));
Literals should be changed to named defines.
drivers/platform/x86/emdoor-intel-wmi.c line 130
Quoted 4 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +4
-0+if (ret) +return ret; +if (value >1 ) +return -EPROTO ;
Add empty line for better readability..
Quoted 18 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +18
-0+return sysfs_emit (buf,"%u\n" , value); +} +static DEVICE_ATTR_RO (touchpad_enabled); + +static struct attribute *ewmi_attrs[] = { + &dev_attr_touchpad_enabled.attr, +NULL +}; +ATTRIBUTE_GROUPS (ewmi); + +static const char *const ewmi_fan_labels[EWMI_FAN_COUNT ] = { +"Fan 1" ,"Fan 2" +}; + +static int ewmi_hwmon_read (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,long *value) +{ +struct ewmi_method *priv =dev_get_drvdata (dev);
drivers/platform/x86/emdoor-intel-wmi.c line 158
Quoted 10 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +10
-0+__le16 rpm; +int ret; + +if (type != hwmon_fan || attr != hwmon_fan_input) +return -EOPNOTSUPP ; +if (channel <0 || channel >=EWMI_FAN_COUNT ) +return -EOPNOTSUPP ; + +guard (mutex)(&priv->lock); + ret =ewmi_call (priv,0x02 ,0x01 , channel, &rpm,sizeof (rpm));
Name literals with defines.
drivers/platform/x86/emdoor-intel-wmi.c line 169
Quoted 11 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +11
-0+if (!ret) + *value =le16_to_cpu (rpm); +return ret; +} + +static int ewmi_hwmon_read_string (struct device *dev, +enum hwmon_sensor_types type,u32 attr, +int channel,const char **str) +{ +if (type == hwmon_fan && attr == hwmon_fan_label && + channel >=0 && channel <EWMI_FAN_COUNT ) {
Why's the logic reverse of that above?
Quoted 30 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +30
-0+ *str = ewmi_fan_labels[channel]; +return 0 ; + } +return -EOPNOTSUPP ; +} + +static const struct hwmon_ops ewmi_hwmon_ops = { + .visible =0444 , + .read = ewmi_hwmon_read, + .read_string = ewmi_hwmon_read_string, +}; + +static const struct hwmon_channel_info *const ewmi_hwmon_info[] = { +HWMON_CHANNEL_INFO (fan, +HWMON_F_INPUT |HWMON_F_LABEL , +HWMON_F_INPUT |HWMON_F_LABEL ), +NULL +}; + +static const struct hwmon_chip_info ewmi_hwmon_chip = { + .ops = &ewmi_hwmon_ops, + .info = ewmi_hwmon_info, +}; + +static int ewmi_profile_probe (void *drvdata,unsigned long *choices) +{ +set_bit (PLATFORM_PROFILE_BALANCED , choices); +set_bit (PLATFORM_PROFILE_PERFORMANCE , choices); +return 0 ; +}
drivers/platform/x86/emdoor-intel-wmi.c line 209
Quoted 10 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +10
-0+ +static int ewmi_profile_get (struct device *dev, +enum platform_profile_option *profile) +{ +struct ewmi_method *priv =dev_get_drvdata (dev); +u8 mode; +int ret; + +guard (mutex)(&priv->lock); + ret =ewmi_call (priv,0x03 ,0x09 ,0 , &mode,sizeof (mode));
Name with define.
drivers/platform/x86/emdoor-intel-wmi.c line 211
Quoted 2 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +2
-0+if (ret) +return ret;
Add empty line.
Quoted 16 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +16
-0+switch (mode) { +case 1 : + *profile =PLATFORM_PROFILE_BALANCED ; +return 0 ; +case 2 : + *profile =PLATFORM_PROFILE_PERFORMANCE ; +return 0 ; +default : +return -EPROTO ; + } +} + +static int ewmi_profile_set (struct device *dev, +enum platform_profile_option profile) +{ +struct ewmi_method *priv =dev_get_drvdata (dev);
drivers/platform/x86/emdoor-intel-wmi.c line 237
Quoted 10 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +10
-0+bool firmware_failure; +u8 mode, actual; +int attempt, ret; + +switch (profile) { +case PLATFORM_PROFILE_BALANCED : + mode =1 ; +break ; +case PLATFORM_PROFILE_PERFORMANCE : + mode =2 ;
Usually the HW values relating to profiles are also named with defines.
drivers/platform/x86/emdoor-intel-wmi.c line 244
Quoted 7 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +7
-0+break ; +default : +return -EOPNOTSUPP ; + } + +guard (mutex)(&priv->lock); +/* Avoid a redundant firmware command when userspace reapplies this profile. */
Not sure how this relates to the call?
drivers/platform/x86/emdoor-intel-wmi.c line 245
Quoted 1 line
drivers/platform/x86/emdoor-intel-wmi.c new file +1
-0+ ret =ewmi_call (priv,0x03 ,0x09 ,0 , &actual,sizeof (actual));
Name literals.
drivers/platform/x86/emdoor-intel-wmi.c line 248
Quoted 3 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +3
-0+if (ret) +return ret; +if (actual == mode && !priv->profile_dirty)
Does the comment above belong here instead?
drivers/platform/x86/emdoor-intel-wmi.c line 260
Quoted 12 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +12
-0+return 0 ; + +/* +* SPFM arms the EC (ZZTT/TIZZ) before Notify(IETM, 0x88) and before +* writing EC5F, so an EC scan during the notify can consume a stale +* EC5F and return RTNC=0 without updating PPMD; SPFM can also report +* RTNC=1 after changing mode. Reissue this absolute mode command up +* to three times when RTNC=1 or 03/09 still reads back the old mode. +*/ + priv->profile_dirty = true; +for (attempt =0 ; attempt <EWMI_PROFILE_RETRIES ; attempt++) { + ret = ewmi_call_status(priv, 0x03, 0x0a, mode, NULL, 0,
You know the drill, I won't mark the rest.
drivers/platform/x86/emdoor-intel-wmi.c line 264
Quoted 4 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +4
-0+ &firmware_failure); +if (ret) { +if (!firmware_failure || + attempt +1 ==EWMI_PROFILE_RETRIES )
+ 1 ???
You're mismanaging the counting variable if you need to apply off-by-one correction.
Quoted 14 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +14
-0+return ret; +msleep (EWMI_PROFILE_SETTLE_MS ); +continue ; + } + ret =ewmi_call (priv,0x03 ,0x09 ,0 , &actual,sizeof (actual)); +if (ret) +return ret; +if (actual == mode) { + priv->profile_dirty = false; +return 0 ; + } +msleep (EWMI_PROFILE_SETTLE_MS ); + ret =ewmi_call (priv,0x03 ,0x09 ,0 , &actual,sizeof (actual)); +if (ret)
drivers/platform/x86/emdoor-intel-wmi.c line 288
Quoted 10 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +10
-0+return ret; +if (actual == mode) { + priv->profile_dirty = false; +return 0 ; + } +if (attempt +1 <EWMI_PROFILE_RETRIES ) +dev_dbg (dev, +"Profile 03/0a requested %u, readback %u on attempt %d/%d; retrying\n" , + mode, actual, attempt +1 , +EWMI_PROFILE_RETRIES );
Please add some empty lines to break this long block.
Quoted 21 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +21
-0+ } +dev_warn_ratelimited (dev, +"Profile 03/0a requested %u, settled readback %u\n" , + mode, actual); +return -EIO ; +} + +static const struct platform_profile_ops ewmi_profile_ops = { + .probe = ewmi_profile_probe, + .profile_get = ewmi_profile_get, + .profile_set = ewmi_profile_set, +}; + +static void ewmi_profile_work (struct work_struct *work) +{ + struct ewmi_method *priv = container_of(work, struct ewmi_method, + profile_work); + +platform_profile_notify (priv->profile); +} +
drivers/platform/x86/emdoor-intel-wmi.c line 319
Quoted 10 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +10
-0+static int ewmi_method_event (struct notifier_block *nb,unsigned long code, +void *data) +{ + struct ewmi_method *priv = container_of(nb, struct ewmi_method, + event_nb); +struct wmi_device *event_wdev = data; + +if (event_wdev->dev.parent != priv->wdev->dev.parent) +return NOTIFY_DONE ; +if (code ==0 || code ==0x41 || code ==0x42 )
Can we name the codes with defines?
Quoted 15 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +15
-0+schedule_work (&priv->profile_work); +return NOTIFY_OK ; +} + +static void ewmi_method_stop (void *data) +{ +struct ewmi_method *priv = data; + +blocking_notifier_chain_unregister (&ewmi_event_chain, &priv->event_nb); +cancel_work_sync (&priv->profile_work); +} + +static int ewmi_method_probe (struct wmi_device *wdev,const void *context) +{ +static const u8 expected_version[] = {1 ,0 ,1 ,0 };
drivers/platform/x86/emdoor-intel-wmi.c line 344
Quoted 10 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +10
-0+struct ewmi_method *priv; +struct device *hwmon; +u8 version[4 ]; +int ret; + + priv =devm_kzalloc (&wdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + priv->wdev = wdev; +mutex_init (&priv->lock);
devm_ + error handling.
drivers/platform/x86/emdoor-intel-wmi.c line 345
Quoted 1 line
drivers/platform/x86/emdoor-intel-wmi.c new file +1
-0+INIT_WORK (&priv->profile_work, ewmi_profile_work);
devm autocancel?
drivers/platform/x86/emdoor-intel-wmi.c line 350
Quoted 5 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +5
-0+dev_set_drvdata (&wdev->dev, priv); + +scoped_guard (mutex, &priv->lock) + ret = ewmi_call(priv, 0x01, 0x01, 0, version, sizeof(version)); +if (ret)
This looks ugly, just put the error handling inside the lock.
drivers/platform/x86/emdoor-intel-wmi.c line 362
Quoted 12 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +12
-0+return dev_err_probe (&wdev->dev, ret, +"Cannot query protocol version\n" ); +if (memcmp (version, expected_version,sizeof (version))) +return dev_err_probe (&wdev->dev, -ENODEV , +"Unsupported protocol version\n" ); + + priv->profile =devm_platform_profile_register (&wdev->dev, +"emdoor-intel-wmi" , + priv, &ewmi_profile_ops); +if (IS_ERR (priv->profile)) +return dev_err_probe (&wdev->dev,PTR_ERR (priv->profile), +"Cannot register platform profile\n" );
Use braces for multiline blocks even if they're just one statement.
Quoted 25 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +25
-0+ + priv->event_nb.notifier_call = ewmi_method_event; + ret =blocking_notifier_chain_register (&ewmi_event_chain, + &priv->event_nb); +if (ret) +return ret; + ret =devm_add_action_or_reset (&wdev->dev, ewmi_method_stop, priv); +if (ret) +return ret; + + hwmon =devm_hwmon_device_register_with_info (&wdev->dev,"emdoor_ewmi" , + priv, &ewmi_hwmon_chip, +NULL ); +if (IS_ERR (hwmon)) +return dev_err_probe (&wdev->dev,PTR_ERR (hwmon), +"Cannot register hwmon\n" ); + +return 0 ; +} + +/* Firmware already changes these states; never request a second toggle. */ +static const struct key_entry ewmi_keymap[] = { + {KE_KEY ,0x30 , {KEY_TOUCHPAD_OFF } }, + {KE_KEY ,0x31 , {KEY_TOUCHPAD_ON } }, + {KE_KEY ,0xa0 , {KEY_PROG1 } },
drivers/platform/x86/emdoor-intel-wmi.c line 397
Quoted 10 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +10
-0+ { KE_KEY, 0xa1, { KEY_PROG2 } }, + { KE_KEY, 0xa2, { KEY_PROG3 } }, + { KE_IGNORE, 0x00, { 0 } }, + { KE_IGNORE, 0x41, { 0 } }, + { KE_IGNORE, 0x42, { 0 } }, + { KE_IGNORE, 0x20, { 0 } }, + { KE_IGNORE, 0x21, { 0 } }, + { KE_IGNORE, 0x22, { 0 } }, + { KE_IGNORE, 0x50, { 0 } }, + { KE_IGNORE, 0x51, { 0 } },
Usually we still fill what the key is even if it ends up being ignored, see the other drivers.
drivers/platform/x86/emdoor-intel-wmi.c line 409
Quoted 12 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +12
-0+ { KE_END, 0 } +}; + +static int ewmi_event_probe (struct wmi_device *wdev,const void *context) +{ +struct ewmi_event *priv; +int ret; + + priv =devm_kzalloc (&wdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; +mutex_init (&priv->lock);
devm_ + error handling.
Quoted 87 lines
drivers/platform/x86/emdoor-intel-wmi.c new file +85
-0+ priv->input =devm_input_allocate_device (&wdev->dev); +if (!priv->input) +return -ENOMEM ; + priv->input->name ="Emdoor EWMI hotkeys" ; + priv->input->phys ="wmi/input0" ; + priv->input->id.bustype =BUS_HOST ; + ret =sparse_keymap_setup (priv->input, ewmi_keymap,NULL ); +if (ret) +return ret; +dev_set_drvdata (&wdev->dev, priv); +return input_register_device (priv->input); +} + +static void ewmi_event_notify (struct wmi_device *wdev, +const struct wmi_buffer *event) +{ +struct ewmi_event *priv =dev_get_drvdata (&wdev->dev); +u32 code =get_unaligned_le32 (event->data); + +blocking_notifier_call_chain (&ewmi_event_chain, code, wdev); +guard (mutex)(&priv->lock); +if (!sparse_keymap_report_event (priv->input, code,1 , true)) +dev_dbg (&wdev->dev,"Unknown event 0x%x\n" , code); +} + +static const struct wmi_device_id ewmi_method_ids[] = { + {EWMI_METHOD_GUID ,NULL }, + { } +}; +MODULE_DEVICE_TABLE (wmi, ewmi_method_ids); + +static const struct wmi_device_id ewmi_event_ids[] = { + {EWMI_EVENT_GUID ,NULL }, + { } +}; +MODULE_DEVICE_TABLE (wmi, ewmi_event_ids); + +static struct wmi_driver ewmi_method_driver = { + .driver = { + .name ="emdoor-ewmi" , + .probe_type =PROBE_PREFER_ASYNCHRONOUS , + .dev_groups = ewmi_groups, + }, + .id_table = ewmi_method_ids, + .no_singleton = true, + .probe = ewmi_method_probe, +}; + +static struct wmi_driver ewmi_event_driver = { + .driver = { + .name ="emdoor-ewmi-events" , + .probe_type =PROBE_PREFER_ASYNCHRONOUS , + }, + .id_table = ewmi_event_ids, + .no_singleton = true, + .min_event_size =sizeof (__le32), + .probe = ewmi_event_probe, + .notify_new = ewmi_event_notify, +}; + +static int __init ewmi_init (void ) +{ +int ret; + + ret =wmi_driver_register (&ewmi_method_driver); +if (ret) +return ret; + ret =wmi_driver_register (&ewmi_event_driver); +if (ret) +wmi_driver_unregister (&ewmi_method_driver); +return ret; +} + +static void __exit ewmi_exit(void) +{ +wmi_driver_unregister (&ewmi_event_driver); +wmi_driver_unregister (&ewmi_method_driver); +} + +module_init (ewmi_init); +module_exit (ewmi_exit); + +MODULE_AUTHOR ("Ziqiang Xia <[email protected]>" ); +MODULE_DESCRIPTION ("Emdoor Intel EWMI platform driver" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
i.
[email protected]
AI reviewSashiko has reviewed this 2-patch series and found no issues.
Sashiko has reviewed this 2-patch series and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]