platform/x86:lenovo-wmi-hotkey-utilities.c: Support for mic and audio mute LEDs
PATCH v11 1/1 platform/x86:lenovo-wmi-hotkey-utilities.c: Support for mic and audio mute LEDs
Implement Lenovo utility data WMI calls needed to make LEDs work on Ideapads that support this GUID.
This enables the mic and audio LEDs to be updated correctly.
Tested on below samples.
ThinkBook 13X Gen4 IMH
ThinkBook 14 G6 ABP
ThinkBook 16p Gen4-21J8
ThinkBook 16 G8 IRL
ThinkBook 16 G7+ ASP
---
Changes in v11:
- Removed MODULE_INFO(depends, "wmi,ideapad-laptop")
Changes in v10:
- Using "imply" instead of "depends on" for CONFIG_IDEAPAD_LAPTOP
- Drop led_reg_failed and call dev_err() directly
Changes in v9:
- Call devm_led_classdev_register() after the switch statement
- Update struct wmi_driver with .name = "lenovo_wmi_hotkey_utilities"
Changes in v8:
- Update MAINTAINERS for this driver
- Added Reviewed-by: Ilpo Järvinen <[email protected]>
- Added Reviewed-by: Reviewed-by: Armin Wolf <[email protected]>
Changes in v7:
- Replaced spaces by tab for items in enum hotkey_set_feature
- Directly return lenovo_super_hotkey_wmi_leds_setup(&wdev->dev)
- Added Reviewed-by: Kurt Borja <[email protected]>
Changes in v6:
- Rename lenovo-super-hotkey-wmi.c to lenovo-wmi-hotkey-utilities
- Update LENOVO_WMI_HOTKEY_UTILITIES item description and add select NEW_LEDS, LEDS_CLASS based on reviewer's suggestion.
- Align items in enum hotkey_set_feature
- Drop some brances and return error message directly
- Check return value of lenovo_super_hotkey_wmi_led_init() in lenovo_super_hotkey_wmi_leds_setup
Changes in v5:
- Take out union acpi_object *obj __free(kfree) = output.pointer from if-else block
- Remove lsk_wmi_context_lud_keys related source code
Changes in v4:
- Add related head files include cleanup.h, dev_printk.h, device.h, module.h
- Replaced kfree() by __free()
- Remove double free for obj
- Remove wpriv->cdev[led_type].dev = dev
- Remove *wpriv = *(const struct lenovo_super_hotkey_wmi_private *)context
- Remove wpriv->event == LSH_WMI_EVENT_LUD_KEYS
- Remove lenovo_super_hotkey_wmi_remove() for unnecessary
Changes in v3:
- Changed the name of the Kconfig entry to LENOVO_SUPER_HOTKEY_WMI
- Renamed everything in this driver which contains the name "ideapad" to instead contain the name of this driver.
- Moved struct wmi_device *led_wdev in lenovo_super_hotkey_wmi_private, and use container_of() to the led_wdev pointer.
- Replaced sizeof(struct wmi_led_args) by sizeof(led_arg)
- Added condtions checking for obj && obj->type == ACPI_TYPE_INTEGER and free the ACPI object after get the required value.
- Removed led_classdev_unregister() after led_reg_failed label, but add lenovo_super_hotkey_wmi_remove(struct wmi_device *wdev) to free resource.
- Removed IDEAPAD_WMI_EVENT_FN_KEYS/IDEAPAD_WMI_EVENT_LUD_KEYS related source codes and only keep LUD_WMI_METHOD_GUID.
Changes in v2:
- Update code layout and formatting as recommended in review
- Improved error handling in ideapad_wmi_led_init
- Separated a WMI driver named lenovo-super-hotkey-wmi.c from ideapad-lap.c, it's only for Lenovo Super Hotkey WMI devices.
MAINTAINERS | 6 + drivers/platform/x86/Kconfig | 11 + drivers/platform/x86/Makefile | 1 + .../x86/lenovo-wmi-hotkey-utilities.c | 212 ++++++++++++++++++ 4 files changed, 230 insertions(+) create mode 100644 drivers/platform/x86/lenovo-wmi-hotkey-utilities.c
MAINTAINERS +6 -0
@@ -13142,6 +13142,12 @@ S: Maintained W: http://legousb.sourceforge.net/ F: drivers/usb/misc/legousbtower.c +LENOVO WMI HOTKEY UTILITIES DRIVER +M: Jackie Dong <[email protected]> +L: [email protected] +S: Maintained +F: drivers/platform/x86/lenovo-wmi-hotkey-utilities.c + LETSKETCH HID TABLET DRIVER M: Hans de Goede <[email protected]> L: [email protected]
drivers/platform/x86/Kconfig +11 -0
@@ -475,6 +475,17 @@ config IDEAPAD_LAPTOP This is a driver for Lenovo IdeaPad netbooks contains drivers for rfkill switch, hotkey, fan control and backlight control. +config LENOVO_WMI_HOTKEY_UTILITIES + tristate "Lenovo Hotkey Utility WMI extras driver" + depends on ACPI_WMI + select NEW_LEDS + select LEDS_CLASS + imply IDEAPAD_LAPTOP + help + This driver provides WMI support for Lenovo customized hotkeys function, + such as LED control for audio/mic mute event for Ideapad, YOGA, XiaoXin, + Gaming, ThinkBook and so on. + config LENOVO_YMC tristate "Lenovo Yoga Tablet Mode Control" depends on ACPI_WMI
drivers/platform/x86/Makefile +1 -0
@@ -61,6 +61,7 @@ obj-$(CONFIG_UV_SYSFS) += uv_sysfs.o # IBM Thinkpad and Lenovo obj-$(CONFIG_IBM_RTL) += ibm_rtl.o obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o +obj-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += lenovo-wmi-hotkey-utilities.o obj-$(CONFIG_LENOVO_YMC) += lenovo-ymc.o obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
drivers/platform/x86/lenovo-wmi-hotkey-utilities.c new file +212 -0
212 lines not on this page · raw message
Signature · 1 line
2.43.0
Am 22.02.25 um 12:45 schrieb Jackie Dong:
Quoted 10 lines
Implement Lenovo utility data WMI calls needed to make LEDs work on Ideapads that support this GUID.
This enables the mic and audio LEDs to be updated correctly.Tested on below samples.
ThinkBook 13X Gen4 IMH
ThinkBook 14 G6 ABP
ThinkBook 16p Gen4-21J8
ThinkBook 16 G8 IRL
ThinkBook 16 G7+ ASP
Hi,
the whole patch looks good to me now.
Thanks,
Armin Wolf
Quoted 349 lines
Signed-off-by Jackie Dong <[email protected]>Suggested-by Mark Pearson <[email protected]>Reviewed-by Kurt Borja <[email protected]>Reviewed-by Ilpo Järvinen <[email protected]>Reviewed-by Armin Wolf <[email protected]>---
Changes in v11:
- RemovedMODULE_INFO(depends, "wmi,ideapad-laptop")Changes in v10:
- Using "imply" instead of "depends on" forCONFIG_IDEAPAD_LAPTOP
- Dropled_reg_failedand calldev_err()directlyChanges in v9:
- Calldevm_led_classdev_register()after the switch statement
- Update structwmi_driverwith .name = "lenovo_wmi_hotkey_utilities"Changes in v8:
- UpdateMAINTAINERSfor this driver
- Added Reviewed-by: Ilpo Järvinen <[email protected]>
- Added Reviewed-by: Reviewed-by: Armin Wolf <[email protected]>Changes in v7:
- Replaced spaces by tab for items in enumhotkey_set_feature
- Directly returnlenovo_super_hotkey_wmi_leds_setup(&wdev->dev)
- Added Reviewed-by: Kurt Borja <[email protected]>Changes in v6:
- Renamelenovo-super-hotkey-wmi.cto lenovo-wmi-hotkey-utilities
- UpdateLENOVO_WMI_HOTKEY_UTILITIESitem description and add selectNEW_LEDS,LEDS_CLASSbased on reviewer's suggestion.
- Align items in enumhotkey_set_feature
- Drop some brances and return error message directly
- Check return value oflenovo_super_hotkey_wmi_led_init()inlenovo_super_hotkey_wmi_leds_setupChanges in v5:
- Take out unionacpi_object*obj__free(kfree)= output.pointer from if-else block
- Removelsk_wmi_context_lud_keysrelated source codeChanges in v4:
- Add related head files includecleanup.h,dev_printk.h,device.h,module.h
- Replacedkfree()by__free()
- Remove double free for obj
- Remove wpriv->cdev[led_type].dev = dev
- Remove *wpriv = *(const structlenovo_super_hotkey_wmi_private*)context
- Removewpriv->event==LSH_WMI_EVENT_LUD_KEYS
- Removelenovo_super_hotkey_wmi_remove()for unnecessaryChanges in v3:
- Changed the name of theKconfigentry toLENOVO_SUPER_HOTKEY_WMI
- Renamed everything in this driver which contains the name "ideapad" to instead contain the name of this driver.
- Moved structwmi_device*led_wdevinlenovo_super_hotkey_wmi_private, and usecontainer_of()to theled_wdevpointer.
- Replacedsizeof(struct wmi_led_args)bysizeof(led_arg)
- Added condtions checking for obj &&obj->type==ACPI_TYPE_INTEGERand free the ACPI object after get the required value.
- Removedled_classdev_unregister()afterled_reg_failedlabel, but addlenovo_super_hotkey_wmi_remove(struct wmi_device *wdev)to free resource.
- Removed IDEAPAD_WMI_EVENT_FN_KEYS/IDEAPAD_WMI_EVENT_LUD_KEYS related source codes and only keepLUD_WMI_METHOD_GUID.Changes in v2:
- Update code layout and formatting as recommended in review
- Improved error handling inideapad_wmi_led_init
- Separated a WMI driver namedlenovo-super-hotkey-wmi.cfromideapad-lap.c, it's only for Lenovo Super Hotkey WMI devices.MAINTAINERS | 6 + drivers/platform/x86/Kconfig | 11 + drivers/platform/x86/Makefile | 1 + .../x86/lenovo-wmi-hotkey-utilities.c | 212 ++++++++++++++++++ 4 files changed, 230 insertions(+)create mode 100644
drivers/platform/x86/lenovo-wmi-hotkey-utilities.cMAINTAINERS +6
-0@@ -13142,6 +13142,12 @@ S: Maintained W: http://legousb.sourceforge.net/ F: drivers/usb/misc/legousbtower.c +LENOVO WMI HOTKEY UTILITIES DRIVER +M: Jackie Dong <[email protected]> +L: [email protected] +S: Maintained +F: drivers/platform/x86/lenovo-wmi-hotkey-utilities.c + LETSKETCH HID TABLET DRIVER M: Hans de Goede <[email protected]> L: [email protected]drivers/platform/x86/Kconfig +11
-0@@ -475,6 +475,17 @@ config IDEAPAD_LAPTOP This is a driver for Lenovo IdeaPad netbooks contains drivers for rfkill switch, hotkey, fan control and backlight control. +config LENOVO_WMI_HOTKEY_UTILITIES + tristate "Lenovo Hotkey Utility WMI extras driver" + depends on ACPI_WMI + select NEW_LEDS + select LEDS_CLASS + imply IDEAPAD_LAPTOP + help + This driver provides WMI support for Lenovo customized hotkeys function, + such as LED control for audio/mic mute event for Ideapad, YOGA, XiaoXin, + Gaming, ThinkBook and so on. + config LENOVO_YMC tristate "Lenovo Yoga Tablet Mode Control" depends on ACPI_WMIdrivers/platform/x86/Makefile +1
-0@@ -61,6 +61,7 @@ obj-$(CONFIG_UV_SYSFS) += uv_sysfs.o # IBM Thinkpad and Lenovo obj-$(CONFIG_IBM_RTL) += ibm_rtl.o obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o +obj-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += lenovo-wmi-hotkey-utilities.o obj-$(CONFIG_LENOVO_YMC) += lenovo-ymc.o obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.odrivers/platform/x86/lenovo-wmi-hotkey-utilities.c new file +212
-0@@ -0,0 +1,212 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Lenovo Super Hotkey Utility WMI extras driver for Ideapad laptop +* +* Copyright (C) 2025 Lenovo +*/ + +#include <linux/cleanup.h> +#include <linux/dev_printk.h> +#include <linux/device.h> +#include <linux/leds.h> +#include <linux/module.h> +#include <linux/wmi.h> + +/* Lenovo Super Hotkey WMI GUIDs */ +#define LUD_WMI_METHOD_GUID "CE6C0974-0407-4F50-88BA-4FC3B6559AD8" + +/* Lenovo Utility Data WMI method_id */ +#define WMI_LUD_GET_SUPPORT 1 +#define WMI_LUD_SET_FEATURE 2 + +#define WMI_LUD_GET_MICMUTE_LED_VER 20 +#define WMI_LUD_GET_AUDIOMUTE_LED_VER 26 + +#define WMI_LUD_SUPPORT_MICMUTE_LED_VER 25 +#define WMI_LUD_SUPPORT_AUDIOMUTE_LED_VER 27 + +/* Input parameters to mute/unmute audio LED and Mic LED */ +struct wmi_led_args { +u8 id; +u8 subid; +u16 value; +}; + +/* Values of input parameters to SetFeature of audio LED and Mic LED */ +enum hotkey_set_feature { +MIC_MUTE_LED_ON =1 , +MIC_MUTE_LED_OFF =2 , +AUDIO_MUTE_LED_ON =4 , +AUDIO_MUTE_LED_OFF =5 , +}; + +#define LSH_ACPI_LED_MAX 2 + +struct lenovo_super_hotkey_wmi_private { +struct led_classdev cdev[LSH_ACPI_LED_MAX ]; +struct wmi_device *led_wdev; +}; + +enum mute_led_type { +MIC_MUTE , +AUDIO_MUTE , +}; + +static int lsh_wmi_mute_led_set (enum mute_led_type led_type,struct led_classdev *led_cdev, +enum led_brightness brightness) + +{ +struct lenovo_super_hotkey_wmi_private *wpriv =container_of (led_cdev, + struct lenovo_super_hotkey_wmi_private, cdev[led_type]); +struct wmi_led_args led_arg = {0 ,0 ,0 }; +struct acpi_buffer input; +acpi_status status; + +switch (led_type) { +case MIC_MUTE : + led_arg.id = brightness ==LED_ON ?MIC_MUTE_LED_ON :MIC_MUTE_LED_OFF ; +break ; +case AUDIO_MUTE : + led_arg.id = brightness ==LED_ON ?AUDIO_MUTE_LED_ON :AUDIO_MUTE_LED_OFF ; +break ; +default : +return -EINVAL ; + } + + input.length =sizeof (led_arg); + input.pointer = &led_arg; + status =wmidev_evaluate_method (wpriv->led_wdev,0 ,WMI_LUD_SET_FEATURE , &input,NULL ); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} + +static int lsh_wmi_audiomute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) + +{ +return lsh_wmi_mute_led_set (AUDIO_MUTE , led_cdev, brightness); +} + +static int lsh_wmi_micmute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +return lsh_wmi_mute_led_set (MIC_MUTE , led_cdev, brightness); +} + +static int lenovo_super_hotkey_wmi_led_init (enum mute_led_type led_type,struct device *dev) +{ +struct lenovo_super_hotkey_wmi_private *wpriv =dev_get_drvdata (dev); +struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER ,NULL }; +struct acpi_buffer input; +int led_version, err =0 ; +unsigned int wmiarg; +acpi_status status; + +switch (led_type) { +case MIC_MUTE : + wmiarg =WMI_LUD_GET_MICMUTE_LED_VER ; +break ; +case AUDIO_MUTE : + wmiarg =WMI_LUD_GET_AUDIOMUTE_LED_VER ; +break ; +default : +return -EINVAL ; + } + + input.length =sizeof (wmiarg); + input.pointer = &wmiarg; + status =wmidev_evaluate_method (wpriv->led_wdev,0 ,WMI_LUD_GET_SUPPORT , &input, &output); +if (ACPI_FAILURE (status)) +return -EIO ; + + union acpi_object *obj __free(kfree) = output.pointer; +if (obj && obj->type ==ACPI_TYPE_INTEGER ) + led_version = obj->integer.value; +else +return -EIO ; + + wpriv->cdev[led_type].max_brightness =LED_ON ; + wpriv->cdev[led_type].flags =LED_CORE_SUSPENDRESUME ; + +switch (led_type) { +case MIC_MUTE : +if (led_version !=WMI_LUD_SUPPORT_MICMUTE_LED_VER ) +return -EIO ; + + wpriv->cdev[led_type].name ="platform::micmute" ; + wpriv->cdev[led_type].brightness_set_blocking = &lsh_wmi_micmute_led_set; + wpriv->cdev[led_type].default_trigger ="audio-micmute" ; +break ; +case AUDIO_MUTE : +if (led_version !=WMI_LUD_SUPPORT_AUDIOMUTE_LED_VER ) +return -EIO ; + + wpriv->cdev[led_type].name ="platform::mute" ; + wpriv->cdev[led_type].brightness_set_blocking = &lsh_wmi_audiomute_led_set; + wpriv->cdev[led_type].default_trigger ="audio-mute" ; +break ; +default : +dev_err (dev,"Unknown LED type %d\n" , led_type); +return -EINVAL ; + } + + err =devm_led_classdev_register (dev, &wpriv->cdev[led_type]); +if (err <0 ) { +dev_err (dev,"Could not register mute LED %d : %d\n" , led_type, err); +return err; + } +return 0 ; +} + +static int lenovo_super_hotkey_wmi_leds_setup (struct device *dev) +{ +int err; + + err =lenovo_super_hotkey_wmi_led_init (MIC_MUTE , dev); +if (err) +return err; + + err =lenovo_super_hotkey_wmi_led_init (AUDIO_MUTE , dev); +if (err) +return err; + +return 0 ; +} + +static int lenovo_super_hotkey_wmi_probe (struct wmi_device *wdev,const void *context) +{ +struct lenovo_super_hotkey_wmi_private *wpriv; + + wpriv =devm_kzalloc (&wdev->dev,sizeof (*wpriv),GFP_KERNEL ); +if (!wpriv) +return -ENOMEM ; + +dev_set_drvdata (&wdev->dev, wpriv); + wpriv->led_wdev = wdev; +return lenovo_super_hotkey_wmi_leds_setup (&wdev->dev); +} + +static const struct wmi_device_id lenovo_super_hotkey_wmi_id_table[] = { + {LUD_WMI_METHOD_GUID ,NULL },/* Utility data */ + { } +}; + +MODULE_DEVICE_TABLE (wmi, lenovo_super_hotkey_wmi_id_table); + +static struct wmi_driver lenovo_wmi_hotkey_utilities_driver = { + .driver = { + .name ="lenovo_wmi_hotkey_utilities" , + .probe_type =PROBE_PREFER_ASYNCHRONOUS + }, + .id_table = lenovo_super_hotkey_wmi_id_table, + .probe = lenovo_super_hotkey_wmi_probe, + .no_singleton = true, +}; + +module_wmi_driver (lenovo_wmi_hotkey_utilities_driver); + +MODULE_AUTHOR ("Jackie Dong <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo Super Hotkey Utility WMI extras driver" ); +MODULE_LICENSE ("GPL" );
Re: [PATCH v11] platform/x86:lenovo-wmi-hotkey-utilities.c: Supportfor mic and audio mute LEDs
Quoted 13 lines · Armin Wolf
Am 22.02.25 um 12:45 schrieb Jackie Dong:
Quoted 10 lines
Implement Lenovo utility data WMI calls needed to make LEDs work on Ideapads that support this GUID.
This enables the mic and audio LEDs to be updated correctly.Tested on below samples.
ThinkBook 13X Gen4 IMH
ThinkBook 14 G6 ABP
ThinkBook 16p Gen4-21J8
ThinkBook 16 G8 IRL
ThinkBook 16 G7+ ASP
Quoted 6 lines
Hi,
the whole patch looks good to me now.
Thanks,
Armin Wolf
Hi all maintainers,
First thanks comments and suggestion from Ilpo, Armin and Kurt. All
of them are very helpful for me.
Do you have any new comments or suggestion for this patch?
Best Regards,
Jackie Dong
Quoted 365 lines
Quoted 365 lines
Signed-off-by Jackie Dong <[email protected]>Suggested-by Mark Pearson <[email protected]>Reviewed-by Kurt Borja <[email protected]>Reviewed-by Ilpo Järvinen <[email protected]>Reviewed-by Armin Wolf <[email protected]>---
Changes in v11:
- RemovedMODULE_INFO(depends, "wmi,ideapad-laptop")Changes in v10:
- Using "imply" instead of "depends on" forCONFIG_IDEAPAD_LAPTOP
- Dropled_reg_failedand calldev_err()directlyChanges in v9:
- Calldevm_led_classdev_register()after the switch statement
- Update structwmi_driverwith .name = "lenovo_wmi_hotkey_utilities"Changes in v8:
- UpdateMAINTAINERSfor this driver
- Added Reviewed-by: Ilpo Järvinen <[email protected]>
- Added Reviewed-by: Reviewed-by: Armin Wolf <[email protected]>Changes in v7:
- Replaced spaces by tab for items in enumhotkey_set_feature
- Directly returnlenovo_super_hotkey_wmi_leds_setup(&wdev->dev)
- Added Reviewed-by: Kurt Borja <[email protected]>Changes in v6:
- Renamelenovo-super-hotkey-wmi.cto lenovo-wmi-hotkey-utilities
- UpdateLENOVO_WMI_HOTKEY_UTILITIESitem description and add selectNEW_LEDS,LEDS_CLASSbased on reviewer's suggestion.
- Align items in enumhotkey_set_feature
- Drop some brances and return error message directly
- Check return value oflenovo_super_hotkey_wmi_led_init()inlenovo_super_hotkey_wmi_leds_setupChanges in v5:
- Take out unionacpi_object*obj__free(kfree)= output.pointer from if-else block
- Removelsk_wmi_context_lud_keysrelated source codeChanges in v4:
- Add related head files includecleanup.h,dev_printk.h,device.h,module.h
- Replacedkfree()by__free()
- Remove double free for obj
- Remove wpriv->cdev[led_type].dev = dev
- Remove *wpriv = *(const structlenovo_super_hotkey_wmi_private*)context
- Removewpriv->event==LSH_WMI_EVENT_LUD_KEYS
- Removelenovo_super_hotkey_wmi_remove()for unnecessaryChanges in v3:
- Changed the name of theKconfigentry toLENOVO_SUPER_HOTKEY_WMI
- Renamed everything in this driver which contains the name "ideapad" to instead contain the name of this driver.
- Moved structwmi_device*led_wdevinlenovo_super_hotkey_wmi_private, and usecontainer_of()to theled_wdevpointer.
- Replacedsizeof(struct wmi_led_args)bysizeof(led_arg)
- Added condtions checking for obj &&obj->type==ACPI_TYPE_INTEGERand free the ACPI object after get the required value.
- Removedled_classdev_unregister()afterled_reg_failedlabel, but addlenovo_super_hotkey_wmi_remove(struct wmi_device *wdev)to free resource.
- Removed IDEAPAD_WMI_EVENT_FN_KEYS/IDEAPAD_WMI_EVENT_LUD_KEYS related source codes and only keepLUD_WMI_METHOD_GUID.Changes in v2:
- Update code layout and formatting as recommended in review
- Improved error handling inideapad_wmi_led_init
- Separated a WMI driver namedlenovo-super-hotkey-wmi.cfromideapad-lap.c, it's only for Lenovo Super Hotkey WMI devices.MAINTAINERS | 6 + drivers/platform/x86/Kconfig | 11 + drivers/platform/x86/Makefile | 1 + .../x86/lenovo-wmi-hotkey-utilities.c | 212 ++++++++++++++++++
4 files changed, 230 insertions(+)create mode 100644
drivers/platform/x86/lenovo-wmi-hotkey-utilities.cMAINTAINERS +0
-0@@ -13142,6 +13142,12 @@ S: MaintainedW: http://legousb.sourceforge.net/
F:drivers/usb/misc/legousbtower.cMAINTAINERS +6
-0+LENOVO WMI HOTKEY UTILITIES DRIVER +M: Jackie Dong <[email protected]> +L: [email protected] +S: Maintained +F: drivers/platform/x86/lenovo-wmi-hotkey-utilities.c +LETSKETCH HID TABLET DRIVER
M: Hans de Goede <[email protected]>
L: [email protected]drivers/platform/x86/Kconfig +0
-0@@ -475,6 +475,17 @@ config IDEAPAD_LAPTOPThis is a driver for Lenovo IdeaPad netbooks contains drivers for rfkill switch, hotkey, fan control and backlight control.
+config
LENOVO_WMI_HOTKEY_UTILITIES
+ tristate "Lenovo Hotkey Utility WMI extras driver"
+ depends onACPI_WMI
+ selectNEW_LEDS
+ selectLEDS_CLASS
+ implyIDEAPAD_LAPTOP
+ help
+ This driver provides WMI support for Lenovo customized hotkeys function,
+ such as LED control for audio/mic mute event for Ideapad, YOGA, XiaoXin,
+ Gaming, ThinkBook and so on.
+
configLENOVO_YMC
tristate "Lenovo Yoga Tablet Mode Control"
depends onACPI_WMIdrivers/platform/x86/Makefile +0
-0@@ -61,6 +61,7 @@ obj-$(CONFIG_UV_SYSFS) += uv_sysfs.o # IBM Thinkpad and Lenovoobj-$(CONFIG_IBM_RTL) += ibm_rtl.o obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o +obj-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += lenovo-wmi-hotkey- utilities.o
obj-$(CONFIG_LENOVO_YMC) += lenovo-ymc.o obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.odrivers/platform/x86/lenovo-wmi-hotkey-utilities.c new file +55
-0@@ -0,0 +1,212 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Lenovo Super Hotkey Utility WMI extras driver for Ideapad laptop +* +* Copyright (C) 2025 Lenovo +*/ + +#include <linux/cleanup.h> +#include <linux/dev_printk.h> +#include <linux/device.h> +#include <linux/leds.h> +#include <linux/module.h> +#include <linux/wmi.h> + +/* Lenovo Super Hotkey WMI GUIDs */ +#define LUD_WMI_METHOD_GUID "CE6C0974-0407-4F50-88BA-4FC3B6559AD8" + +/* Lenovo Utility Data WMI method_id */ +#define WMI_LUD_GET_SUPPORT 1 +#define WMI_LUD_SET_FEATURE 2 + +#define WMI_LUD_GET_MICMUTE_LED_VER 20 +#define WMI_LUD_GET_AUDIOMUTE_LED_VER 26 + +#define WMI_LUD_SUPPORT_MICMUTE_LED_VER 25 +#define WMI_LUD_SUPPORT_AUDIOMUTE_LED_VER 27 + +/* Input parameters to mute/unmute audio LED and Mic LED */ +struct wmi_led_args { + u8 id; + u8 subid; + u16 value; +}; + +/* Values of input parameters to SetFeature of audio LED and Mic LED */ +enum hotkey_set_feature { + MIC_MUTE_LED_ON = 1, + MIC_MUTE_LED_OFF = 2, + AUDIO_MUTE_LED_ON = 4, + AUDIO_MUTE_LED_OFF = 5, +}; + +#define LSH_ACPI_LED_MAX 2 + +struct lenovo_super_hotkey_wmi_private { + struct led_classdev cdev[LSH_ACPI_LED_MAX]; + struct wmi_device *led_wdev; +}; + +enum mute_led_type { + MIC_MUTE, + AUDIO_MUTE, +}; + +static int lsh_wmi_mute_led_set(enum mute_led_type led_type, struct
led_classdev*led_cdev,
+ enumled_brightnessbrightness)drivers/platform/x86/lenovo-wmi-hotkey-utilities.c new file +3
-0+ +{ + struct lenovo_super_hotkey_wmi_private *wpriv =container_of(led_cdev,
+ structlenovo_super_hotkey_wmi_private, cdev[led_type]); + structwmi_led_argsled_arg= {0, 0, 0};
+ structacpi_bufferinput;
+acpi_statusstatus;
+
+ switch (led_type) {
+ caseMIC_MUTE:
+ led_arg.id = brightness ==LED_ON?MIC_MUTE_LED_ON:MIC_MUTE_LED_OFF;
+ break;
+ caseAUDIO_MUTE:
+ led_arg.id = brightness ==LED_ON?AUDIO_MUTE_LED_ON:AUDIO_MUTE_LED_OFF;
+ break;
+ default:
+ return-EINVAL;
+ }
+
+ input.length =sizeof(led_arg);
+ input.pointer =&led_arg;
+ status =wmidev_evaluate_method(wpriv->led_wdev, 0, WMI_LUD_SET_FEATURE, &input, NULL);
+ if (ACPI_FAILURE(status))
+ return-EIO;drivers/platform/x86/lenovo-wmi-hotkey-utilities.c new file +18
-0+ + return 0; +} + +static int lsh_wmi_audiomute_led_set (struct led_classdev *led_cdev, + enum led_brightness brightness) + +{ + return lsh_wmi_mute_led_set(AUDIO_MUTE, led_cdev, brightness); +} + +static int lsh_wmi_micmute_led_set (struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + return lsh_wmi_mute_led_set(MIC_MUTE, led_cdev, brightness); +} + +static int lenovo_super_hotkey_wmi_led_init(enum mute_led_type
led_type, struct device *dev)
+{
+ structlenovo_super_hotkey_wmi_private*wpriv =dev_get_drvdata(dev);
+ structacpi_bufferoutput = {ACPI_ALLOCATE_BUFFER, NULL }; + structacpi_bufferinput;
+ intled_version, err = 0;
+ unsigned int wmiarg;
+acpi_statusstatus;drivers/platform/x86/lenovo-wmi-hotkey-utilities.c new file +15
-0+ + switch (led_type) { + case MIC_MUTE: + wmiarg = WMI_LUD_GET_MICMUTE_LED_VER; + break; + case AUDIO_MUTE: + wmiarg = WMI_LUD_GET_AUDIOMUTE_LED_VER; + break; + default: + return -EINVAL; + } + + input.length = sizeof(wmiarg); + input.pointer = &wmiarg; + status = wmidev_evaluate_method(wpriv->led_wdev, 0,
WMI_LUD_GET_SUPPORT, &input, &output);
+ if (ACPI_FAILURE(status))
+ return-EIO;drivers/platform/x86/lenovo-wmi-hotkey-utilities.c new file +17
-0+ + union acpi_object *obj __free(kfree) = output.pointer; + if (obj && obj->type == ACPI_TYPE_INTEGER) + led_version = obj->integer.value; + else + return -EIO; + + wpriv->cdev[led_type].max_brightness = LED_ON; + wpriv->cdev[led_type].flags = LED_CORE_SUSPENDRESUME; + + switch (led_type) { + case MIC_MUTE: + if (led_version != WMI_LUD_SUPPORT_MICMUTE_LED_VER) + return -EIO; + + wpriv->cdev[led_type].name = "platform::micmute"; + wpriv->cdev[led_type].brightness_set_blocking =
&lsh_wmi_micmute_led_set;
+ wpriv->cdev[led_type].default_trigger = "audio-micmute"; + break;
+ caseAUDIO_MUTE:
+ if (led_version!=WMI_LUD_SUPPORT_AUDIOMUTE_LED_VER) + return-EIO;
+
+ wpriv->cdev[led_type].name = "platform::mute"; + wpriv->cdev[led_type].brightness_set_blocking =&lsh_wmi_audiomute_led_set;
+ wpriv->cdev[led_type].default_trigger = "audio-mute"; + break;
+ default:
+dev_err(dev, "Unknown LED type %d\n", led_type); + return-EINVAL;
+ }
+
+ err =devm_led_classdev_register(dev, &wpriv->cdev[led_type]); + if (err < 0) {
+dev_err(dev, "Could not register mute LED %d : %d\n", led_type, err);
+ return err;
+ }
+ return 0;drivers/platform/x86/lenovo-wmi-hotkey-utilities.c new file +18
-0+} + +static int lenovo_super_hotkey_wmi_leds_setup (struct device *dev) +{ + int err; + + err = lenovo_super_hotkey_wmi_led_init(MIC_MUTE, dev); + if (err) + return err; + + err = lenovo_super_hotkey_wmi_led_init(AUDIO_MUTE, dev); + if (err) + return err; + + return 0; +} + +static int lenovo_super_hotkey_wmi_probe(struct wmi_device *wdev,const void *context)
drivers/platform/x86/lenovo-wmi-hotkey-utilities.c new file +34
-0+{ + struct lenovo_super_hotkey_wmi_private *wpriv; + + wpriv = devm_kzalloc(&wdev->dev, sizeof(*wpriv), GFP_KERNEL); + if (!wpriv) + return -ENOMEM; + + dev_set_drvdata(&wdev->dev, wpriv); + wpriv->led_wdev = wdev; + return lenovo_super_hotkey_wmi_leds_setup(&wdev->dev); +} + +static const struct wmi_device_id lenovo_super_hotkey_wmi_id_table[] = { + { LUD_WMI_METHOD_GUID, NULL }, /* Utility data */ + { } +}; + +MODULE_DEVICE_TABLE (wmi, lenovo_super_hotkey_wmi_id_table); + +static struct wmi_driver lenovo_wmi_hotkey_utilities_driver = { + .driver = { + .name = "lenovo_wmi_hotkey_utilities", + .probe_type = PROBE_PREFER_ASYNCHRONOUS + }, + .id_table = lenovo_super_hotkey_wmi_id_table, + .probe = lenovo_super_hotkey_wmi_probe, + .no_singleton = true, +}; + +module_wmi_driver (lenovo_wmi_hotkey_utilities_driver); + +MODULE_AUTHOR ("Jackie Dong <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo Super Hotkey Utility WMI extras driver" ); +MODULE_LICENSE ("GPL" );
Ilpo Järvinen
maintainerQuoted 4 lines · Jackie Dong
Implement Lenovo utility data WMI calls needed to make LEDs work on Ideapads that support this GUID.
This enables the mic and audio LEDs to be updated correctly.
Quoted 8 lines
Tested on below samples.
ThinkBook 13X Gen4 IMH
ThinkBook 14 G6 ABP
ThinkBook 16p Gen4-21J8
ThinkBook 16 G8 IRL
ThinkBook 16 G7+ ASP[...]
Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.
The list of commits applied:
[1/1] platform/x86:lenovo-wmi-hotkey-utilities.c: Support for mic and audio mute LEDs
commit: 61250669eaa9fd480e0f1c3cec107924b6a06b46
--
i.
Re: [PATCH v11] platform/x86:lenovo-wmi-hotkey-utilities.c:Support for mic and audio mute LEDs
Quoted 21 lines · Ilpo Järvinen
Quoted 4 lines · Jackie Dong
Implement Lenovo utility data WMI calls needed to make LEDs work on Ideapads that support this GUID.
This enables the mic and audio LEDs to be updated correctly.Quoted 8 lines
Tested on below samples.
ThinkBook 13X Gen4 IMH
ThinkBook 14 G6 ABP
ThinkBook 16p Gen4-21J8
ThinkBook 16 G8 IRL
ThinkBook 16 G7+ ASP[...]
Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.
Quoted 7 lines
The list of commits applied:
[1/1] platform/x86:lenovo-wmi-hotkey-utilities.c: Support for mic and audio mute LEDscommit: 61250669eaa9fd480e0f1c3cec107924b6a06b46--
i.
Hi Ilpo,
Thanks for your confirmation and help for this patch.
Best Regards,
Jackie Dong