platform/x86: wmi: add Xiaomi WMI key driver
Subsystems (2)
cover platform/x86: wmi: add Xiaomi WMI key driver
This patchset adds a WMI key driver for Xiaomi notebooks. To be able to do this while using the struct wmi_driver a context field has been added to struct wmi_device_id.
[PATCH 1/3]: Add field to struct wmi_device_id and add a helper function [PATCH 2/3]: Add new parameter to the probe function
[PATCH 3/3]: Add new driver
Mattias Jacobsson (3):
platform/x86: wmi: add context pointer field to struct wmi_device_id platform/x86: wmi: add context argument to the probe function platform/x86: wmi: add Xiaomi WMI key driver
drivers/platform/x86/Kconfig | 10 +++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/dell-smbios-wmi.c | 2 +- drivers/platform/x86/dell-wmi-descriptor.c | 3 +- drivers/platform/x86/dell-wmi.c | 2 +- drivers/platform/x86/huawei-wmi.c | 2 +- drivers/platform/x86/intel-wmi-thunderbolt.c | 3 +- drivers/platform/x86/wmi-bmof.c | 2 +- drivers/platform/x86/wmi.c | 25 +++++- drivers/platform/x86/xiaomi-wmi.c | 94 ++++++++++++++++++++ include/linux/mod_devicetable.h | 1 + include/linux/wmi.h | 2 +- 12 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 drivers/platform/x86/xiaomi-wmi.c
Signature · 1 line
2.21.0
PATCH 1/3 platform/x86: wmi: add context pointer field to struct wmi_device_id
When using wmi_install_notify_handler() to initialize a WMI handler a data pointer can be supplied which will be passed on to the notification handler. No similar feature exist when handling WMI events via struct wmi_driver.
Add a context field pointer to struct wmi_device_id and add a function find_guid_context() to retrieve that context pointer.
--- drivers/platform/x86/wmi.c | 22 ++++++++++++++++++++++ include/linux/mod_devicetable.h | 1 + 2 files changed, 23 insertions(+)
drivers/platform/x86/wmi.c +22 -0
@@ -146,6 +146,28 @@ static bool find_guid(const char *guid_string, struct wmi_block **out)return false; } +static const void *find_guid_context (struct wmi_block *wblock, +struct wmi_driver *wdriver) +{ +const struct wmi_device_id *id; +uuid_le guid_input; + +if (wblock ==NULL || wdriver ==NULL ) +return NULL ; +if (wdriver->id_table ==NULL ) +return NULL ; + + id = wdriver->id_table; +while (*id->guid_string) { +if (uuid_le_to_bin (id->guid_string, &guid_input)) +continue ; +if (!memcmp (wblock->gblock.guid, &guid_input,16 )) +return id->context; + id++; + } +return NULL ; +} +static int get_subobj_info (acpi_handle handle,const char *pathname,struct acpi_device_info **info) {
include/linux/mod_devicetable.h +1 -0
@@ -798,6 +798,7 @@ struct tee_client_device_id {*/ struct wmi_device_id {const char guid_string[UUID_STRING_LEN +1 ]; +const void *context; };#endif /* LINUX_MOD_DEVICETABLE_H */
Signature · 1 line
2.21.0
PATCH 2/3 platform/x86: wmi: add context argument to the probe function
In reply to Mattias JacobssonThe struct wmi_device_id has a context pointer field, forward this pointer as an argument to the probe function in struct wmi_driver.
Update existing users of the same probe function to accept this new context argument.
--- drivers/platform/x86/dell-smbios-wmi.c | 2 +- drivers/platform/x86/dell-wmi-descriptor.c | 3 ++- drivers/platform/x86/dell-wmi.c | 2 +- drivers/platform/x86/huawei-wmi.c | 2 +- drivers/platform/x86/intel-wmi-thunderbolt.c | 3 ++- drivers/platform/x86/wmi-bmof.c | 2 +- drivers/platform/x86/wmi.c | 3 ++- include/linux/wmi.h | 2 +- 8 files changed, 11 insertions(+), 8 deletions(-)
drivers/platform/x86/dell-smbios-wmi.c +1 -1
@@ -146,7 +146,7 @@ static long dell_smbios_wmi_filter(struct wmi_device *wdev, unsigned int cmd,return ret; } -static int dell_smbios_wmi_probe (struct wmi_device *wdev) +static int dell_smbios_wmi_probe (struct wmi_device *wdev,const void *context) {struct wmi_driver *wdriver = container_of(wdev->dev.driver, struct wmi_driver, driver);
drivers/platform/x86/dell-wmi-descriptor.c +2 -1
@@ -106,7 +106,8 @@ EXPORT_SYMBOL_GPL(dell_wmi_get_hotfix);* WMI buffer length 12 4 <length> * WMI hotfix number 16 4 <hotfix> */ -static int dell_wmi_descriptor_probe (struct wmi_device *wdev) +static int dell_wmi_descriptor_probe (struct wmi_device *wdev, +const void *context) {union acpi_object *obj =NULL ;struct descriptor_priv *priv;
drivers/platform/x86/dell-wmi.c +1 -1
@@ -672,7 +672,7 @@ static int dell_wmi_events_set_enabled(bool enable)return dell_smbios_error (ret); } -static int dell_wmi_probe (struct wmi_device *wdev) +static int dell_wmi_probe (struct wmi_device *wdev,const void *context) {struct dell_wmi_priv *priv;int ret;
drivers/platform/x86/huawei-wmi.c +1 -1
@@ -166,7 +166,7 @@ static int huawei_wmi_input_setup(struct wmi_device *wdev)return input_register_device (priv->idev); } -static int huawei_wmi_probe (struct wmi_device *wdev) +static int huawei_wmi_probe (struct wmi_device *wdev,const void *context) {struct huawei_wmi_priv *priv;int err;
drivers/platform/x86/intel-wmi-thunderbolt.c +2 -1
@@ -56,7 +56,8 @@ static const struct attribute_group tbt_attribute_group = { .attrs = tbt_attrs, }; -static int intel_wmi_thunderbolt_probe (struct wmi_device *wdev) +static int intel_wmi_thunderbolt_probe (struct wmi_device *wdev, +const void *context) {int ret;
drivers/platform/x86/wmi-bmof.c +1 -1
@@ -54,7 +54,7 @@ read_bmof(struct file *filp, struct kobject *kobj,return count; } -static int wmi_bmof_probe (struct wmi_device *wdev) +static int wmi_bmof_probe (struct wmi_device *wdev,const void *context) {struct bmof_priv *priv;int ret;
drivers/platform/x86/wmi.c +2 -1
@@ -926,7 +926,8 @@ static int wmi_dev_probe(struct device *dev)dev_warn (dev,"failed to enable device -- probing anyway\n" );if (wdriver->probe) { - ret = wdriver->probe (dev_to_wdev (dev)); + ret = wdriver->probe (dev_to_wdev (dev), +find_guid_context (wblock, wdriver));if (ret !=0 ) goto probe_failure; }
include/linux/wmi.h +1 -1
@@ -44,7 +44,7 @@ struct wmi_driver {struct device_driver driver;const struct wmi_device_id *id_table; -int (*probe)(struct wmi_device *wdev); +int (*probe)(struct wmi_device *wdev,const void *context);int (*remove)(struct wmi_device *wdev);void (*notify)(struct wmi_device *device,union acpi_object *data); long (*filter_callback)(struct wmi_device *wdev, unsigned int cmd,
Signature · 1 line
2.21.0
PATCH 3/3 platform/x86: wmi: add Xiaomi WMI key driver
In reply to Mattias JacobssonSome function keys on the built in keyboard on Xiaomi's notebooks does not produce any key events when pressed in combination with the function key. Some of these keys do report that they are being pressed via WMI events.
This driver reports key events for Fn+F7 and double tap on Fn.
Other WMI events that are reported by the hardware but not utilized by this driver are Caps Lock(which already work) and Fn lock/unlock.
--- drivers/platform/x86/Kconfig | 10 ++++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/xiaomi-wmi.c | 94 +++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 drivers/platform/x86/xiaomi-wmi.c
drivers/platform/x86/Kconfig +10 -0
@@ -781,6 +781,16 @@ config INTEL_WMI_THUNDERBOLT To compile this driver as a module, choose M here: the module will be called intel-wmi-thunderbolt. +config XIAOMI_WMI + tristate "Xiaomi WMI key driver" + depends on ACPI_WMI + depends on INPUT + help + Say Y here if you want to support WMI-based keys on Xiaomi notebooks. + + To compile this driver as a module, choose M here: the module will + be called xiaomi-wmi. + config MSI_WMI tristate "MSI WMI extras" depends on ACPI_WMI
drivers/platform/x86/Makefile +1 -0
@@ -51,6 +51,7 @@ obj-$(CONFIG_SURFACE3_WMI) += surface3-wmi.o obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o obj-$(CONFIG_WMI_BMOF) += wmi-bmof.o obj-$(CONFIG_INTEL_WMI_THUNDERBOLT) += intel-wmi-thunderbolt.o +obj-$(CONFIG_XIAOMI_WMI) += xiaomi-wmi.o # toshiba_acpi must link after wmi to ensure that wmi devices are found # before toshiba_acpi initializes
drivers/platform/x86/xiaomi-wmi.c new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.21.0
Quoted 11 lines · Mattias Jacobsson
Some function keys on the built in keyboard on Xiaomi's notebooks does not produce any key events when pressed in combination with the function key. Some of these keys do report that they are being pressed via WMI events.
This driver reports key events for Fn+F7 and double tap on Fn.
Other WMI events that are reported by the hardware but not utilized by this driver are Caps Lock(which already work) and Fn lock/unlock.
Pushed to my review and testing queue, thanks!
Quoted 144 lines
Signed-off-by Mattias Jacobsson <[email protected]>--- drivers/platform/x86/Kconfig | 10 ++++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/xiaomi-wmi.c | 94 +++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 drivers/platform/x86/xiaomi-wmi.cdrivers/platform/x86/Kconfig +10
-0@@ -781,6 +781,16 @@ config INTEL_WMI_THUNDERBOLT To compile this driver as a module, choose M here: the module will be called intel-wmi-thunderbolt. +config XIAOMI_WMI + tristate "Xiaomi WMI key driver" + depends on ACPI_WMI + depends on INPUT + help + Say Y here if you want to support WMI-based keys on Xiaomi notebooks. + + To compile this driver as a module, choose M here: the module will + be called xiaomi-wmi. + config MSI_WMI tristate "MSI WMI extras" depends on ACPI_WMIdrivers/platform/x86/Makefile +1
-0@@ -51,6 +51,7 @@ obj-$(CONFIG_SURFACE3_WMI) += surface3-wmi.o obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o obj-$(CONFIG_WMI_BMOF) += wmi-bmof.o obj-$(CONFIG_INTEL_WMI_THUNDERBOLT) += intel-wmi-thunderbolt.o +obj-$(CONFIG_XIAOMI_WMI) += xiaomi-wmi.o # toshiba_acpi must link after wmi to ensure that wmi devices are found # before toshiba_acpi initializesdrivers/platform/x86/xiaomi-wmi.c new file +94
-1@@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* WMI driver for Xiaomi Laptops +* +*/ + +#include <linux/acpi.h> +#include <linux/input.h> +#include <linux/module.h> +#include <linux/wmi.h> +#include <uapi/linux/input-event-codes.h> + +#define XIAOMI_KEY_FN_ESC_0 "A2095CCE-0491-44E7-BA27-F8ED8F88AA86" +#define XIAOMI_KEY_FN_ESC_1 "7BBE8E39-B486-473D-BA13-66F75C5805CD" +#define XIAOMI_KEY_FN_FN "409B028D-F06B-4C7C-8BBB-EE133A6BD87E" +#define XIAOMI_KEY_CAPSLOCK "83FE7607-053A-4644-822A-21532C621FC7" +#define XIAOMI_KEY_FN_F7 "76E9027C-95D0-4180-8692-DA6747DD1C2D" + +#define XIAOMI_DEVICE (guid, key) \ + .guid_string = (guid), \ + .context = &(const unsigned int){key} + +struct xiaomi_wmi { +struct input_dev *input_dev; +unsigned int key_code; +}; + +int xiaomi_wmi_probe (struct wmi_device *wdev,const void *context) +{ +struct xiaomi_wmi *data; + +if (wdev ==NULL || context ==NULL ) +return -EINVAL ; + + data =devm_kzalloc (&wdev->dev,sizeof (struct xiaomi_wmi ),GFP_KERNEL ); +if (data ==NULL ) +return -ENOMEM ; +dev_set_drvdata (&wdev->dev, data); + + data->input_dev =devm_input_allocate_device (&wdev->dev); +if (data->input_dev ==NULL ) +return -ENOMEM ; + data->input_dev->name ="Xiaomi WMI keys" ; + data->input_dev->phys ="wmi/input0" ; + + data->key_code = *((const unsigned int *)context); +set_bit (EV_KEY , data->input_dev->evbit); +set_bit (data->key_code, data->input_dev->keybit); + +return input_register_device (data->input_dev); +} + +void xiaomi_wmi_notify (struct wmi_device *wdev,union acpi_object *_) +{ +struct xiaomi_wmi *data; + +if (wdev ==NULL ) +return ; + + data =dev_get_drvdata (&wdev->dev); +if (data ==NULL ) +return ; + +input_report_key (data->input_dev, data->key_code,1 ); +input_sync (data->input_dev); +input_report_key (data->input_dev, data->key_code,0 ); +input_sync (data->input_dev); +} + +static const struct wmi_device_id xiaomi_wmi_id_table[] = { +// { XIAOMI_DEVICE(XIAOMI_KEY_FN_ESC_0, KEY_FN_ESC) }, +// { XIAOMI_DEVICE(XIAOMI_KEY_FN_ESC_1, KEY_FN_ESC) }, + {XIAOMI_DEVICE (XIAOMI_KEY_FN_FN ,KEY_PROG1 ) }, +// { XIAOMI_DEVICE(XIAOMI_KEY_CAPSLOCK, KEY_CAPSLOCK) }, + {XIAOMI_DEVICE (XIAOMI_KEY_FN_F7 ,KEY_CUT ) }, + +/* Terminating entry */ + { } +}; + +static struct wmi_driver xiaomi_wmi_driver = { + .driver = { + .name ="xiaomi-wmi" , + }, + .id_table = xiaomi_wmi_id_table, + .probe = xiaomi_wmi_probe, + .notify = xiaomi_wmi_notify, +}; +module_wmi_driver (xiaomi_wmi_driver); + +MODULE_DEVICE_TABLE (wmi, xiaomi_wmi_id_table); +MODULE_AUTHOR ("Mattias Jacobsson" ); +MODULE_DESCRIPTION ("Xiaomi WMI driver" ); +MODULE_LICENSE ("GPL v2" ); --2.21.0
Signature · 2 lines
With Best Regards, Andy Shevchenko