[PATCH v5 1/3] platform/x86: huawei-wmi: bind hotkeys and key data on the WMI bus
From: Fuwei Xie
Date: Tue Dec 01 2026 - 09:42:26 EST
Bind the event GUIDs and the optional legacy data block independently.
For a 0x80 notification, query the data block on the same WMI mapper
as the event. This keeps scancodes from two mappers separate.
Keep the input devices under the existing platform device. Register the
data driver before the event driver and unwind registration on error.
Tested-by: Eren Özen <erenozen@xxxxxxxxxxxxxx> # MateBook 16 CREM-WXX9
Signed-off-by: Fuwei Xie <12313607@xxxxxxxxxxxxxxxxxxx>
---
drivers/platform/x86/huawei-wmi.c | 188 ++++++++++++++++++------------
1 file changed, 116 insertions(+), 72 deletions(-)
diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
index 96ee9a97c..94e3f34b3 100644
--- a/drivers/platform/x86/huawei-wmi.c
+++ b/drivers/platform/x86/huawei-wmi.c
@@ -15,6 +15,7 @@
#include <linux/leds.h>
#include <linux/module.h>
#include <linux/mutex.h>
+#include <linux/notifier.h>
#include <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/sysfs.h>
@@ -28,8 +29,8 @@
#define HWMI_EVENT_GUID "ABBC0F5C-8EA1-11D1-A000-C90629100000"
/* Legacy GUIDs */
-#define WMI0_EXPENSIVE_GUID "39142400-C6A3-40fa-BADB-8A2652834100"
-#define WMI0_EVENT_GUID "59142400-C6A3-40fa-BADB-8A2652834100"
+#define WMI0_EXPENSIVE_GUID "39142400-C6A3-40FA-BADB-8A2652834100"
+#define WMI0_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
/* HWMI commands */
@@ -72,6 +73,8 @@ struct huawei_wmi {
static struct huawei_wmi *huawei_wmi;
+static BLOCKING_NOTIFIER_HEAD(huawei_wmi_keycode_chain);
+
static const struct key_entry huawei_wmi_keymap[] = {
{ KE_KEY, 0x281, { KEY_BRIGHTNESSDOWN } },
{ KE_KEY, 0x282, { KEY_BRIGHTNESSUP } },
@@ -799,29 +802,84 @@ static void huawei_wmi_debugfs_exit(struct device *dev)
/* Input */
-static void huawei_wmi_process_key(struct input_dev *idev, int code)
+/* WMI0 reports 0x80 and provides the actual scancode in a sibling data block. */
+struct huawei_wmi_keycode {
+ struct wmi_device *event;
+ u32 code;
+};
+
+struct huawei_wmi_keyblock {
+ struct wmi_device *wdev;
+ struct notifier_block notifier;
+};
+
+static int huawei_wmi_query_keycode(struct notifier_block *nb, unsigned long action, void *data)
+{
+ struct huawei_wmi_keyblock *block = container_of(nb, struct huawei_wmi_keyblock, notifier);
+ struct huawei_wmi_keycode *key = data;
+ struct wmi_buffer out;
+
+ if (block->wdev->dev.parent != key->event->dev.parent)
+ return NOTIFY_DONE;
+
+ if (wmidev_query_block(block->wdev, 0, &out, sizeof(__le32)))
+ return NOTIFY_BAD;
+
+ u8 *buf __free(kfree) = out.data;
+
+ key->code = le32_to_cpup((const __le32 *)buf);
+ return NOTIFY_STOP;
+}
+
+static int huawei_wmi_keyblock_probe(struct wmi_device *wdev, const void *context)
+{
+ struct huawei_wmi_keyblock *block;
+
+ block = devm_kzalloc(&wdev->dev, sizeof(*block), GFP_KERNEL);
+ if (!block)
+ return -ENOMEM;
+
+ block->wdev = wdev;
+ block->notifier.notifier_call = huawei_wmi_query_keycode;
+ dev_set_drvdata(&wdev->dev, block);
+
+ return blocking_notifier_chain_register(&huawei_wmi_keycode_chain, &block->notifier);
+}
+
+static void huawei_wmi_keyblock_remove(struct wmi_device *wdev)
{
+ struct huawei_wmi_keyblock *block = dev_get_drvdata(&wdev->dev);
+
+ blocking_notifier_chain_unregister(&huawei_wmi_keycode_chain, &block->notifier);
+}
+
+static const struct wmi_device_id huawei_wmi_keyblock_ids[] = {
+ { WMI0_EXPENSIVE_GUID },
+ {}
+};
+MODULE_DEVICE_TABLE(wmi, huawei_wmi_keyblock_ids);
+
+static struct wmi_driver huawei_wmi_keyblock_driver = {
+ .driver.name = "huawei-wmi-keyblock",
+ .id_table = huawei_wmi_keyblock_ids,
+ .probe = huawei_wmi_keyblock_probe,
+ .remove = huawei_wmi_keyblock_remove,
+ .no_singleton = true,
+};
+
+static void huawei_wmi_input_notify(struct wmi_device *wdev, const struct wmi_buffer *data)
+{
+ struct input_dev *idev = dev_get_drvdata(&wdev->dev);
+ u32 code = le32_to_cpup(data->data);
const struct key_entry *key;
- /*
- * WMI0 uses code 0x80 to indicate a hotkey event.
- * The actual key is fetched from the method WQ00
- * using WMI0_EXPENSIVE_GUID.
- */
if (code == 0x80) {
- struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
- union acpi_object *obj;
- acpi_status status;
+ struct huawei_wmi_keycode keycode = { .event = wdev };
- status = wmi_query_block(WMI0_EXPENSIVE_GUID, 0, &response);
- if (ACPI_FAILURE(status))
+ if (blocking_notifier_call_chain(&huawei_wmi_keycode_chain, 0, &keycode) !=
+ NOTIFY_STOP)
return;
-
- obj = (union acpi_object *)response.pointer;
- if (obj && obj->type == ACPI_TYPE_INTEGER)
- code = obj->integer.value;
-
- kfree(response.pointer);
+ code = keycode.code;
}
key = sparse_keymap_entry_from_scancode(idev, code);
@@ -831,85 +889,74 @@ static void huawei_wmi_process_key(struct input_dev *idev, int code)
}
if (quirks && !quirks->report_brightness &&
- (key->sw.code == KEY_BRIGHTNESSDOWN ||
- key->sw.code == KEY_BRIGHTNESSUP))
+ (key->sw.code == KEY_BRIGHTNESSDOWN || key->sw.code == KEY_BRIGHTNESSUP))
return;
sparse_keymap_report_entry(idev, key, 1, true);
}
-static void huawei_wmi_input_notify(union acpi_object *obj, void *context)
-{
- struct input_dev *idev = (struct input_dev *)context;
-
- if (obj && obj->type == ACPI_TYPE_INTEGER)
- huawei_wmi_process_key(idev, obj->integer.value);
- else
- dev_err(&idev->dev, "Bad response type\n");
-}
-
-static int huawei_wmi_input_setup(struct device *dev, const char *guid)
+static int huawei_wmi_input_probe(struct wmi_device *wdev, const void *context)
{
struct input_dev *idev;
- acpi_status status;
int err;
- idev = devm_input_allocate_device(dev);
+ idev = input_allocate_device();
if (!idev)
return -ENOMEM;
idev->name = "Huawei WMI hotkeys";
idev->phys = "wmi/input0";
idev->id.bustype = BUS_HOST;
- idev->dev.parent = dev;
+ idev->dev.parent = huawei_wmi->dev;
err = sparse_keymap_setup(idev, huawei_wmi_keymap, NULL);
- if (err)
+ if (!err)
+ err = input_register_device(idev);
+ if (err) {
+ input_free_device(idev);
return err;
+ }
- err = input_register_device(idev);
- if (err)
- return err;
-
- status = wmi_install_notify_handler(guid, huawei_wmi_input_notify, idev);
- if (ACPI_FAILURE(status))
- return -EIO;
-
+ dev_set_drvdata(&wdev->dev, idev);
return 0;
}
-static void huawei_wmi_input_exit(struct device *dev, const char *guid)
+static void huawei_wmi_input_remove(struct wmi_device *wdev)
{
- wmi_remove_notify_handler(guid);
+ input_unregister_device(dev_get_drvdata(&wdev->dev));
}
-/* Huawei driver */
-
-static const struct wmi_device_id huawei_wmi_events_id_table[] = {
- { .guid_string = WMI0_EVENT_GUID },
- { .guid_string = HWMI_EVENT_GUID },
- { }
+static const struct wmi_device_id huawei_wmi_event_ids[] = {
+ { WMI0_EVENT_GUID },
+ { HWMI_EVENT_GUID },
+ {}
+};
+MODULE_DEVICE_TABLE(wmi, huawei_wmi_event_ids);
+
+static struct wmi_driver huawei_wmi_event_driver = {
+ .driver.name = "huawei-wmi-events",
+ .id_table = huawei_wmi_event_ids,
+ .probe = huawei_wmi_input_probe,
+ .remove = huawei_wmi_input_remove,
+ .notify_new = huawei_wmi_input_notify,
+ .min_event_size = sizeof(__le32),
+ .no_singleton = true,
};
static int huawei_wmi_probe(struct platform_device *pdev)
{
- const struct wmi_device_id *guid = huawei_wmi_events_id_table;
int err;
platform_set_drvdata(pdev, huawei_wmi);
huawei_wmi->dev = &pdev->dev;
- while (*guid->guid_string) {
- if (wmi_has_guid(guid->guid_string)) {
- err = huawei_wmi_input_setup(&pdev->dev, guid->guid_string);
- if (err) {
- dev_err(&pdev->dev, "Failed to setup input on %s\n", guid->guid_string);
- return err;
- }
- }
+ err = wmi_driver_register(&huawei_wmi_keyblock_driver);
+ if (err)
+ return err;
- guid++;
- }
+ err = wmi_driver_register(&huawei_wmi_event_driver);
+ if (err)
+ goto err_unregister_keyblock;
if (wmi_has_guid(HWMI_METHOD_GUID)) {
mutex_init(&huawei_wmi->wmi_lock);
@@ -921,18 +968,16 @@ static int huawei_wmi_probe(struct platform_device *pdev)
}
return 0;
+
+err_unregister_keyblock:
+ wmi_driver_unregister(&huawei_wmi_keyblock_driver);
+ return err;
}
static void huawei_wmi_remove(struct platform_device *pdev)
{
- const struct wmi_device_id *guid = huawei_wmi_events_id_table;
-
- while (*guid->guid_string) {
- if (wmi_has_guid(guid->guid_string))
- huawei_wmi_input_exit(&pdev->dev, guid->guid_string);
-
- guid++;
- }
+ wmi_driver_unregister(&huawei_wmi_event_driver);
+ wmi_driver_unregister(&huawei_wmi_keyblock_driver);
if (wmi_has_guid(HWMI_METHOD_GUID)) {
huawei_wmi_debugfs_exit(&pdev->dev);
@@ -998,7 +1043,6 @@ module_init(huawei_wmi_init);
module_exit(huawei_wmi_exit);
MODULE_ALIAS("wmi:"HWMI_METHOD_GUID);
-MODULE_DEVICE_TABLE(wmi, huawei_wmi_events_id_table);
MODULE_AUTHOR("Ayman Bagabas <ayman.bagabas@xxxxxxxxx>");
MODULE_DESCRIPTION("Huawei WMI laptop extras driver");
MODULE_LICENSE("GPL v2");
--
2.55.0