1 // SPDX-License-Identifier: GPL-2.0
2 /* WMI driver for Xiaomi Laptops */
4 #include <linux/acpi.h>
5 #include <linux/input.h>
6 #include <linux/module.h>
9 #include <uapi/linux/input-event-codes.h>
11 #define XIAOMI_KEY_FN_ESC_0 "A2095CCE-0491-44E7-BA27-F8ED8F88AA86"
12 #define XIAOMI_KEY_FN_ESC_1 "7BBE8E39-B486-473D-BA13-66F75C5805CD"
13 #define XIAOMI_KEY_FN_FN "409B028D-F06B-4C7C-8BBB-EE133A6BD87E"
14 #define XIAOMI_KEY_CAPSLOCK "83FE7607-053A-4644-822A-21532C621FC7"
15 #define XIAOMI_KEY_FN_F7 "76E9027C-95D0-4180-8692-DA6747DD1C2D"
17 #define XIAOMI_DEVICE(guid, key) \
18 .guid_string = (guid), \
19 .context = &(const unsigned int){key}
22 struct input_dev
*input_dev
;
23 unsigned int key_code
;
26 int xiaomi_wmi_probe(struct wmi_device
*wdev
, const void *context
)
28 struct xiaomi_wmi
*data
;
30 if (wdev
== NULL
|| context
== NULL
)
33 data
= devm_kzalloc(&wdev
->dev
, sizeof(struct xiaomi_wmi
), GFP_KERNEL
);
36 dev_set_drvdata(&wdev
->dev
, data
);
38 data
->input_dev
= devm_input_allocate_device(&wdev
->dev
);
39 if (data
->input_dev
== NULL
)
41 data
->input_dev
->name
= "Xiaomi WMI keys";
42 data
->input_dev
->phys
= "wmi/input0";
44 data
->key_code
= *((const unsigned int *)context
);
45 set_bit(EV_KEY
, data
->input_dev
->evbit
);
46 set_bit(data
->key_code
, data
->input_dev
->keybit
);
48 return input_register_device(data
->input_dev
);
51 void xiaomi_wmi_notify(struct wmi_device
*wdev
, union acpi_object
*dummy
)
53 struct xiaomi_wmi
*data
;
58 data
= dev_get_drvdata(&wdev
->dev
);
62 input_report_key(data
->input_dev
, data
->key_code
, 1);
63 input_sync(data
->input_dev
);
64 input_report_key(data
->input_dev
, data
->key_code
, 0);
65 input_sync(data
->input_dev
);
68 static const struct wmi_device_id xiaomi_wmi_id_table
[] = {
69 // { XIAOMI_DEVICE(XIAOMI_KEY_FN_ESC_0, KEY_FN_ESC) },
70 // { XIAOMI_DEVICE(XIAOMI_KEY_FN_ESC_1, KEY_FN_ESC) },
71 { XIAOMI_DEVICE(XIAOMI_KEY_FN_FN
, KEY_PROG1
) },
72 // { XIAOMI_DEVICE(XIAOMI_KEY_CAPSLOCK, KEY_CAPSLOCK) },
73 { XIAOMI_DEVICE(XIAOMI_KEY_FN_F7
, KEY_CUT
) },
75 /* Terminating entry */
79 static struct wmi_driver xiaomi_wmi_driver
= {
83 .id_table
= xiaomi_wmi_id_table
,
84 .probe
= xiaomi_wmi_probe
,
85 .notify
= xiaomi_wmi_notify
,
87 module_wmi_driver(xiaomi_wmi_driver
);
89 MODULE_DEVICE_TABLE(wmi
, xiaomi_wmi_id_table
);
90 MODULE_AUTHOR("Mattias Jacobsson");
91 MODULE_DESCRIPTION("Xiaomi WMI driver");
92 MODULE_LICENSE("GPL v2");