platform/x86: lenovo-super-hotkey-wmi.c: Support for mic and audio mute LEDs
PATCH v2 1/1 platform/x86: lenovo-super-hotkey-wmi.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 16p Gen8-IRL
ThinkBook 16p G7+ ASP
---
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.
drivers/platform/x86/Kconfig | 7 + drivers/platform/x86/Makefile | 1 + .../platform/x86/lenovo-super-hotkey-wmi.c | 236 ++++++++++++++++++ 3 files changed, 244 insertions(+) create mode 100644 drivers/platform/x86/lenovo-super-hotkey-wmi.c
drivers/platform/x86/Kconfig +9 -0
@@ -475,6 +475,15 @@ config IDEAPAD_LAPTOP This is a driver for Lenovo IdeaPad netbooks contains drivers for rfkill switch, hotkey, fan control and backlight control. +config LENOVO_HOTKEY_WMI + tristate "Lenovo Super Hotkey Utility WMI extras driver" + depends on ACPI_WMI + depends on IDEAPAD_LAPTOP + help + This driver provides WMI support for Lenovo customized hotkeys function + of Lenovo NoteBooks which are for Consumer and SMB customers, such as + 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_HOTKEY_WMI) += lenovo-super-hotkey-wmi.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-super-hotkey-wmi.c new file +236 -0
236 lines not on this page · raw message
Signature · 1 line
2.43.0
Ilpo Järvinen
maintainerQuoted 31 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.Tested on below samples.
ThinkBook 13X Gen4 IMH
ThinkBook 14 G6 ABP
ThinkBook 16p Gen4-21J8
ThinkBook 16p Gen8-IRL
ThinkBook 16p G7+ ASPSigned-off-by Jackie Dong <[email protected]>Suggested-by Mark Pearson <[email protected]>---
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.drivers/platform/x86/Kconfig | 7 + drivers/platform/x86/Makefile | 1 + .../platform/x86/lenovo-super-hotkey-wmi.c | 236 ++++++++++++++++++ 3 files changed, 244 insertions(+) create mode 100644 drivers/platform/x86/lenovo-super-hotkey-wmi.cdrivers/platform/x86/Kconfig +0
-0
drivers/platform/x86/Kconfig config IDEAPAD_LAPTOP · line 481
Quoted 7 lines
drivers/platform/x86/Kconfig +4
-0@@ -475,6 +475,15 @@ config IDEAPAD_LAPTOP This is a driver for Lenovo IdeaPad netbooks contains drivers for rfkill switch, hotkey, fan control and backlight control. +config LENOVO_HOTKEY_WMI + tristate "Lenovo Super Hotkey Utility WMI extras driver" + depends on ACPI_WMI + depends on IDEAPAD_LAPTOP
Something leds related is missing from here.
Quoted 57 lines
drivers/platform/x86/Kconfig +5
-0+ help + This driver provides WMI support for Lenovo customized hotkeys function + of Lenovo NoteBooks which are for Consumer and SMB customers, such as + 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_HOTKEY_WMI) += lenovo-super-hotkey-wmi.o obj-$(CONFIG_LENOVO_YMC) += lenovo-ymc.o obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.odrivers/platform/x86/lenovo-super-hotkey-wmi.c new file +31
-0@@ -0,0 +1,236 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Lenovo Super Hotkey Utility WMI extras driver for Ideapad laptop +* +* Copyright (C) 2025 Lenovo +*/ + +#include <linux/leds.h> +#include <linux/wmi.h> +#include "ideapad-laptop.h" + +/* Lenovo Super Hotkey WMI GUIDs */ +#define LUD_WMI_METHOD_GUID "CE6C0974-0407-4F50-88BA-4FC3B6559AD8" +#define LUPKE_WMI_EVENT_GUID "8FC0DE0C-B4E4-43FD-B0F3-8871711C1294" + +/* 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; +};
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 41
Quoted 10 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +10
-0+ +/* 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 , +AUDIO_MUTE_LED_ON =4 , +AUDIO_MUTE_LED_OFF , +}; + +#define IDEAPAD_ACPI_LED_MAX 2
This seems strongly related to mute_led_type. I'd consider making it the last member in the enum. I'm not sure if "max" is good in the name as the max index is 1.
Quoted 115 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +115
-0+ +enum ideapad_wmi_event_type { +IDEAPAD_WMI_EVENT_FN_KEYS =1 , +IDEAPAD_WMI_EVENT_LUD_KEYS , +}; + +struct ideapad_wmi_private { +enum ideapad_wmi_event_type event; +struct led_classdev cdev[IDEAPAD_ACPI_LED_MAX ]; +}; + +static struct wmi_device *led_wdev; + +enum mute_led_type { +MIC_MUTE , +AUDIO_MUTE , +}; + +static int ideapad_wmi_mute_led_set (enum mute_led_type led_type,struct led_classdev *led_cdev, +enum led_brightness brightness) + +{ +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 (struct wmi_led_args ); + input.pointer = &led_arg; + status =wmidev_evaluate_method (led_wdev,0 ,WMI_LUD_SET_FEATURE , &input,NULL ); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} + +static int ideapad_wmi_audiomute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) + +{ +return ideapad_wmi_mute_led_set (AUDIO_MUTE , led_cdev, brightness); +} + +static int ideapad_wmi_micmute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +return ideapad_wmi_mute_led_set (MIC_MUTE , led_cdev, brightness); +} + +static int ideapad_wmi_led_init (enum mute_led_type led_type,struct device *dev) +{ +struct ideapad_wmi_private *wpriv =dev_get_drvdata (dev); +struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER ,NULL }; +struct acpi_buffer input; +union acpi_object *obj; +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 (led_wdev,0 ,WMI_LUD_GET_SUPPORT , &input, &output); +if (ACPI_FAILURE (status)) +return -EIO ; + + obj = output.pointer; + led_version = obj->integer.value; + + wpriv->cdev[led_type].max_brightness =LED_ON ; + wpriv->cdev[led_type].dev = dev; + wpriv->cdev[led_type].flags =LED_CORE_SUSPENDRESUME ; + +switch (led_type) { +case MIC_MUTE : +if (led_version !=WMI_LUD_SUPPORT_MICMUTE_LED_VER ) { + err = -EIO ; + goto led_error; + } + wpriv->cdev[led_type].name ="platform::micmute" ; + wpriv->cdev[led_type].brightness_set_blocking = &ideapad_wmi_micmute_led_set; + wpriv->cdev[led_type].default_trigger ="audio-micmute" ; + + err =devm_led_classdev_register (dev, &wpriv->cdev[led_type]); +if (err <0 ) + goto led_reg_failed; + +break ; +case AUDIO_MUTE : +if (led_version !=WMI_LUD_SUPPORT_AUDIOMUTE_LED_VER ) { + err = -EIO ; + goto led_error; + } + wpriv->cdev[led_type].name ="platform::mute" ; + wpriv->cdev[led_type].brightness_set_blocking = &ideapad_wmi_audiomute_led_set;
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 166
Quoted 10 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +10
-0+ wpriv->cdev[led_type].default_trigger ="audio-mute" ; + + err =devm_led_classdev_register (dev, &wpriv->cdev[led_type]); +if (err <0 ) + goto led_reg_failed; + +break ; +default : + err = -EINVAL ; +dev_err (dev,"Unknown LED type %d\n" , led_type);
Add #include for dev_err().
Quoted 15 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +15
-0+ goto led_error; + } + +kfree (obj); +return 0 ; + +led_reg_failed: +dev_err (dev,"Could not register mute LED %d : %d\n" , led_type, err); +led_classdev_unregister (&wpriv->cdev[led_type]); +led_error: +kfree (obj); +return err; +} + +static void ideapad_wmi_leds_setup (struct device *dev)
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 191
Quoted 10 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +10
-0+{ +ideapad_wmi_led_init (MIC_MUTE , dev); +ideapad_wmi_led_init (AUDIO_MUTE , dev); +} + +static int lenovo_super_hotkey_wmi_probe (struct wmi_device *wdev,const void *context) +{ +struct ideapad_wmi_private *wpriv; + + wpriv =devm_kzalloc (&wdev->dev,sizeof (*wpriv),GFP_KERNEL );
Add include for devm_kzalloc().
Quoted 46 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +45
-0+if (!wpriv) +return -ENOMEM ; + + *wpriv = *(const struct ideapad_wmi_private *)context; + +dev_set_drvdata (&wdev->dev, wpriv); + +if (wpriv->event ==IDEAPAD_WMI_EVENT_LUD_KEYS ) { + led_wdev = wdev; +ideapad_wmi_leds_setup (&wdev->dev); + } + +return 0 ; +} + +static const struct ideapad_wmi_private lsk_wmi_context_fn_keys = { + .event =IDEAPAD_WMI_EVENT_FN_KEYS +}; + +static const struct ideapad_wmi_private lsk_wmi_context_lud_keys = { + .event =IDEAPAD_WMI_EVENT_LUD_KEYS +}; + +static const struct wmi_device_id lenovo_super_hotkey_wmi_id_table[] = { + {LUPKE_WMI_EVENT_GUID , &lsk_wmi_context_fn_keys },/* FN keys */ + {LUD_WMI_METHOD_GUID , &lsk_wmi_context_lud_keys },/* Utility data */ + { } +}; + +MODULE_DEVICE_TABLE (wmi, lenovo_super_hotkey_wmi_id_table); + +static struct wmi_driver lenovo_super_hotkey_wmi_driver = { + .driver = { + .name ="lenovo_super_hotkey_wmi" , + }, + .id_table = lenovo_super_hotkey_wmi_id_table, + .probe = lenovo_super_hotkey_wmi_probe, +}; + +module_wmi_driver (lenovo_super_hotkey_wmi_driver); + +MODULE_INFO (depends,"wmi,ideapad-laptop" ); +MODULE_AUTHOR ("Jackie Dong <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo Super Hotkey Utility WMI extras driver" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
i.
Re: [PATCH v2] platform/x86: lenovo-super-hotkey-wmi.c: Support formic and audio mute LEDs
Quoted 36 lines · Ilpo Järvinen
Quoted 34 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.Tested on below samples.
ThinkBook 13X Gen4 IMH
ThinkBook 14 G6 ABP
ThinkBook 16p Gen4-21J8
ThinkBook 16p Gen8-IRL
ThinkBook 16p G7+ ASPSigned-off-by Jackie Dong <[email protected]>Suggested-by Mark Pearson <[email protected]>---
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.drivers/platform/x86/Kconfig | 7 + drivers/platform/x86/Makefile | 1 + .../platform/x86/lenovo-super-hotkey-wmi.c | 236 ++++++++++++++++++ 3 files changed, 244 insertions(+)create mode 100644
drivers/platform/x86/lenovo-super-hotkey-wmi.cdrivers/platform/x86/Kconfig +0
-0@@ -475,6 +475,15 @@ config IDEAPAD_LAPTOP This is a driver for Lenovo IdeaPad netbooks contains drivers for rfkill switch, hotkey, fan control and backlight control.
Quoted 5 lines
drivers/platform/x86/Kconfig config IDEAPAD_LAPTOP · line 481
Quoted 4 lines
drivers/platform/x86/Kconfig +4
-0+config LENOVO_HOTKEY_WMI + tristate "Lenovo Super Hotkey Utility WMI extras driver" + depends on ACPI_WMI + depends on IDEAPAD_LAPTOP
Hi Ilpo,
Thanks your review and feedback. I updated some additional
information for your comments, pls review it again.
Quoted 1 line
Something leds related is missing from here.
This LENOVO_HOTKEY_WMI depends on IDEAPAD_LAPTOP which included leds moudles as below. Maybe it shoud be enough.
config IDEAPAD_LAPTOP
tristate "Lenovo IdeaPad Laptop Extras"
depends on ACPI
depends on RFKILL && INPUT
depends on SERIO_I8042
depends on BACKLIGHT_CLASS_DEVICE
depends on ACPI_VIDEO || ACPI_VIDEO = n
depends on ACPI_WMI || ACPI_WMI = n
select ACPI_PLATFORM_PROFILE
select INPUT_SPARSEKMAP
select NEW_LEDS
select LEDS_CLASS
help
This is a driver for Lenovo IdeaPad netbooks contains drivers for rfkill switch, hotkey, fan control and backlight control.
Quoted 64 lines
Quoted 64 lines
drivers/platform/x86/Kconfig +5
-0+ help + This driver provides WMI support for Lenovo customized hotkeys function + of Lenovo NoteBooks which are for Consumer and SMB customers, such as + 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_HOTKEY_WMI) += lenovo-super-hotkey-wmi.o obj-$(CONFIG_LENOVO_YMC) += lenovo-ymc.o obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.odrivers/platform/x86/lenovo-super-hotkey-wmi.c new file +37
-0@@ -0,0 +1,236 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Lenovo Super Hotkey Utility WMI extras driver for Ideapad laptop +* +* Copyright (C) 2025 Lenovo +*/ + +#include <linux/leds.h> +#include <linux/wmi.h> +#include "ideapad-laptop.h" + +/* Lenovo Super Hotkey WMI GUIDs */ +#define LUD_WMI_METHOD_GUID "CE6C0974-0407-4F50-88BA-4FC3B6559AD8" +#define LUPKE_WMI_EVENT_GUID "8FC0DE0C-B4E4-43FD-B0F3-8871711C1294" + +/* 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 , +AUDIO_MUTE_LED_ON =4 ,
Quoted 9 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 41
Quoted 4 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +4
-0+ AUDIO_MUTE_LED_OFF, +}; + +#define IDEAPAD_ACPI_LED_MAX 2This seems strongly related to
mute_led_type. I'd consider making it the last member in the enum. I'm not sure if "max" is good in the name as the max index is 1.
This define way is from thinkpad-apci.c, paste related codes as below for reference.
9265
/*************************************************************************
9266 * Mute LED subdriver
9267 */
9268
9269 #define TPACPI_LED_MAX 2
9270
9271 struct tp_led_table {
9272 acpi_string name; 9273 int on_value; 9274 int off_value; 9275 int state;
9276 };
Quoted 119 lines
Quoted 119 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +119
-0+ +enum ideapad_wmi_event_type { +IDEAPAD_WMI_EVENT_FN_KEYS =1 , +IDEAPAD_WMI_EVENT_LUD_KEYS , +}; + +struct ideapad_wmi_private { +enum ideapad_wmi_event_type event; +struct led_classdev cdev[IDEAPAD_ACPI_LED_MAX ]; +}; + +static struct wmi_device *led_wdev; + +enum mute_led_type { +MIC_MUTE , +AUDIO_MUTE , +}; + +static int ideapad_wmi_mute_led_set (enum mute_led_type led_type,struct led_classdev *led_cdev, +enum led_brightness brightness) + +{ +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 (struct wmi_led_args ); + input.pointer = &led_arg; + status =wmidev_evaluate_method (led_wdev,0 ,WMI_LUD_SET_FEATURE , &input,NULL ); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} + +static int ideapad_wmi_audiomute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) + +{ +return ideapad_wmi_mute_led_set (AUDIO_MUTE , led_cdev, brightness); +} + +static int ideapad_wmi_micmute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +return ideapad_wmi_mute_led_set (MIC_MUTE , led_cdev, brightness); +} + +static int ideapad_wmi_led_init (enum mute_led_type led_type,struct device *dev) +{ +struct ideapad_wmi_private *wpriv =dev_get_drvdata (dev); +struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER ,NULL }; +struct acpi_buffer input; +union acpi_object *obj; +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 (led_wdev,0 ,WMI_LUD_GET_SUPPORT , &input, &output); +if (ACPI_FAILURE (status)) +return -EIO ; + + obj = output.pointer; + led_version = obj->integer.value; + + wpriv->cdev[led_type].max_brightness =LED_ON ; + wpriv->cdev[led_type].dev = dev; + wpriv->cdev[led_type].flags =LED_CORE_SUSPENDRESUME ; + +switch (led_type) { +case MIC_MUTE : +if (led_version !=WMI_LUD_SUPPORT_MICMUTE_LED_VER ) { + err = -EIO ; + goto led_error; + } + wpriv->cdev[led_type].name ="platform::micmute" ; + wpriv->cdev[led_type].brightness_set_blocking = &ideapad_wmi_micmute_led_set; + wpriv->cdev[led_type].default_trigger ="audio-micmute" ; + + err =devm_led_classdev_register (dev, &wpriv->cdev[led_type]); +if (err <0 ) + goto led_reg_failed; + +break ; +case AUDIO_MUTE : +if (led_version !=WMI_LUD_SUPPORT_AUDIOMUTE_LED_VER ) { + err = -EIO ; + goto led_error; + } + wpriv->cdev[led_type].name ="platform::mute" ; + wpriv->cdev[led_type].brightness_set_blocking = &ideapad_wmi_audiomute_led_set; + wpriv->cdev[led_type].default_trigger ="audio-mute" ; + + err =devm_led_classdev_register (dev, &wpriv->cdev[led_type]); +if (err <0 )
Quoted 8 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 166
Quoted 6 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +6
-0+ goto led_reg_failed; + +break ; +default : + err = -EINVAL ; +dev_err (dev,"Unknown LED type %d\n" , led_type);Add #include for
dev_err().
dev_err() is defined in include/linux/dev_printk.h which is included by include/linux/device.h which is included by include/linux/wmi.h which is included by this file as below.
Quoted 35 lines
Quoted 35 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +29
-0+++ b/drivers/platform/x86/lenovo-super-hotkey-wmi.c@@ -0,0 +1,236 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Lenovo Super Hotkey Utility WMI extras driver for Ideapad laptop +* +* Copyright (C) 2025 Lenovo +*/ + +#include <linux/leds.h> +#include <linux/wmi.h> + goto led_error; + } + +kfree (obj); +return 0 ; + +led_reg_failed: +dev_err (dev,"Could not register mute LED %d : %d\n" , led_type, err); +led_classdev_unregister (&wpriv->cdev[led_type]); +led_error: +kfree (obj); +return err; +} + +static void ideapad_wmi_leds_setup (struct device *dev) +{ +ideapad_wmi_led_init (MIC_MUTE , dev); +ideapad_wmi_led_init (AUDIO_MUTE , dev); +}
Quoted 8 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 191
Quoted 6 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +6
-0+ +static int lenovo_super_hotkey_wmi_probe (struct wmi_device *wdev,const void *context) +{ +struct ideapad_wmi_private *wpriv; + + wpriv =devm_kzalloc (&wdev->dev,sizeof (*wpriv),GFP_KERNEL );Add include for
devm_kzalloc().
devm_kzalloc() is defined in include/linux/device.h which is included by include/linux/wmi.h which is included by this file as below.
Quoted 63 lines
Quoted 62 lines
+++
b/drivers/platform/x86/lenovo-super-hotkey-wmi.cdrivers/platform/x86/lenovo-super-hotkey-wmi.c new file +54
-0@@ -0,0 +1,236 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Lenovo Super Hotkey Utility WMI extras driver for Ideapad laptop +* +* Copyright (C) 2025 Lenovo +*/ + +#include <linux/leds.h> +#include <linux/wmi.h> +if (!wpriv) +return -ENOMEM ; + + *wpriv = *(const struct ideapad_wmi_private *)context; + +dev_set_drvdata (&wdev->dev, wpriv); + +if (wpriv->event ==IDEAPAD_WMI_EVENT_LUD_KEYS ) { + led_wdev = wdev; +ideapad_wmi_leds_setup (&wdev->dev); + } + +return 0 ; +} + +static const struct ideapad_wmi_private lsk_wmi_context_fn_keys = { + .event =IDEAPAD_WMI_EVENT_FN_KEYS +}; + +static const struct ideapad_wmi_private lsk_wmi_context_lud_keys = { + .event =IDEAPAD_WMI_EVENT_LUD_KEYS +}; + +static const struct wmi_device_id lenovo_super_hotkey_wmi_id_table[] = { + {LUPKE_WMI_EVENT_GUID , &lsk_wmi_context_fn_keys },/* FN keys */ + {LUD_WMI_METHOD_GUID , &lsk_wmi_context_lud_keys },/* Utility data */ + { } +}; + +MODULE_DEVICE_TABLE (wmi, lenovo_super_hotkey_wmi_id_table); + +static struct wmi_driver lenovo_super_hotkey_wmi_driver = { + .driver = { + .name ="lenovo_super_hotkey_wmi" , + }, + .id_table = lenovo_super_hotkey_wmi_id_table, + .probe = lenovo_super_hotkey_wmi_probe, +}; + +module_wmi_driver (lenovo_super_hotkey_wmi_driver); + +MODULE_INFO (depends,"wmi,ideapad-laptop" ); +MODULE_AUTHOR ("Jackie Dong <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo Super Hotkey Utility WMI extras driver" ); +MODULE_LICENSE ("GPL" );
Am 22.01.25 um 10:09 schrieb Jackie Dong:
Quoted 32 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 16p Gen8-IRL
ThinkBook 16p G7+ ASPSigned-off-by Jackie Dong <[email protected]>Suggested-by Mark Pearson <[email protected]>---
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.drivers/platform/x86/Kconfig | 7 + drivers/platform/x86/Makefile | 1 + .../platform/x86/lenovo-super-hotkey-wmi.c | 236 ++++++++++++++++++ 3 files changed, 244 insertions(+)create mode 100644
drivers/platform/x86/lenovo-super-hotkey-wmi.cdrivers/platform/x86/Kconfig +0
-0@@ -475,6 +475,15 @@ config IDEAPAD_LAPTOP This is a driver for Lenovo IdeaPad netbooks contains drivers for
drivers/platform/x86/Kconfig config IDEAPAD_LAPTOP · line 485
Quoted 10 lines
drivers/platform/x86/Kconfig +8
-0rfkill switch, hotkey, fan control and backlight control. +config LENOVO_HOTKEY_WMI + tristate "Lenovo Super Hotkey Utility WMI extras driver" + depends on ACPI_WMI + depends on IDEAPAD_LAPTOP + help + This driver provides WMI support for Lenovo customized hotkeys function + of Lenovo NoteBooks which are for Consumer and SMB customers, such as + Ideapad/YOGA/XiaoXin/Gaming/ThinkBook and so on.
Please change the name of the Kconfig entry to LENOVO_SUPER_HOTKEY_WMI to match the name of the driver.
Also, why does this driver depend on IDEAPAD_LAPTOP?
Quoted 60 lines
drivers/platform/x86/Kconfig +1
-0+ 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_HOTKEY_WMI) += lenovo-super-hotkey-wmi.o obj-$(CONFIG_LENOVO_YMC) += lenovo-ymc.o obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.odrivers/platform/x86/lenovo-super-hotkey-wmi.c new file +38
-0@@ -0,0 +1,236 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Lenovo Super Hotkey Utility WMI extras driver for Ideapad laptop +* +* Copyright (C) 2025 Lenovo +*/ + +#include <linux/leds.h> +#include <linux/wmi.h> +#include "ideapad-laptop.h" + +/* Lenovo Super Hotkey WMI GUIDs */ +#define LUD_WMI_METHOD_GUID "CE6C0974-0407-4F50-88BA-4FC3B6559AD8" +#define LUPKE_WMI_EVENT_GUID "8FC0DE0C-B4E4-43FD-B0F3-8871711C1294" + +/* 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 , +AUDIO_MUTE_LED_ON =4 , +AUDIO_MUTE_LED_OFF ,
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 48
Quoted 10 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +10
-0+}; + +#define IDEAPAD_ACPI_LED_MAX 2 + +enum ideapad_wmi_event_type { +IDEAPAD_WMI_EVENT_FN_KEYS =1 , +IDEAPAD_WMI_EVENT_LUD_KEYS , +}; + +struct ideapad_wmi_private {
Please rename everything in this driver which contains the name "ideapad" to instead contain the name of this driver.
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 53
Quoted 5 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +5
-0+enum ideapad_wmi_event_type event; +struct led_classdev cdev[IDEAPAD_ACPI_LED_MAX ]; +}; + +static struct wmi_device *led_wdev;
Please use container_of() to get a reference to your private data struct.
Toachieve that i suggest you rework your private data struct like this:
struct lenovo_hotkey_private { enum mute_led_type type; structwmi_device *wdev; struct led_classdev cdev; }; You can then allocate a
private data struct for each LED device and use container_of(led_cdev, struct lenovo_hotkey_private, cdev) to get a reference to the associated struct from each LED classdev pointer. Then you can access
the WMI device and the LED type without having to use global variables.
Quoted 16 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +16
-0+ +enum mute_led_type { +MIC_MUTE , +AUDIO_MUTE , +}; + +static int ideapad_wmi_mute_led_set (enum mute_led_type led_type,struct led_classdev *led_cdev, +enum led_brightness brightness) + +{ +struct wmi_led_args led_arg = {0 ,0 ,0 }; +struct acpi_buffer input; +acpi_status status; + +switch (led_type) { +case MIC_MUTE :
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 79
Quoted 10 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +10
-0+ 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 (struct wmi_led_args );
sizeof(struct wmi_led_args) -> sizeof(led_arg)
Quoted 40 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +40
-0+ input.pointer = &led_arg; + status =wmidev_evaluate_method (led_wdev,0 ,WMI_LUD_SET_FEATURE , &input,NULL ); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} + +static int ideapad_wmi_audiomute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) + +{ +return ideapad_wmi_mute_led_set (AUDIO_MUTE , led_cdev, brightness); +} + +static int ideapad_wmi_micmute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +return ideapad_wmi_mute_led_set (MIC_MUTE , led_cdev, brightness); +} + +static int ideapad_wmi_led_init (enum mute_led_type led_type,struct device *dev) +{ +struct ideapad_wmi_private *wpriv =dev_get_drvdata (dev); +struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER ,NULL }; +struct acpi_buffer input; +union acpi_object *obj; +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 ;
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 129
Quoted 10 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +10
-0+ } + + input.length =sizeof (wmiarg); + input.pointer = &wmiarg; + status =wmidev_evaluate_method (led_wdev,0 ,WMI_LUD_GET_SUPPORT , &input, &output); +if (ACPI_FAILURE (status)) +return -EIO ; + + obj = output.pointer; + led_version = obj->integer.value;
Please check if the resulting ACPI object is:
- not NULL
- actually an integer
I also suggest that you copy the integer inside a local variable and free the ACPI object as soon as possible to avoid leaking it later.
Quoted 36 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +36
-0+ + wpriv->cdev[led_type].max_brightness =LED_ON ; + wpriv->cdev[led_type].dev = dev; + wpriv->cdev[led_type].flags =LED_CORE_SUSPENDRESUME ; + +switch (led_type) { +case MIC_MUTE : +if (led_version !=WMI_LUD_SUPPORT_MICMUTE_LED_VER ) { + err = -EIO ; + goto led_error; + } + wpriv->cdev[led_type].name ="platform::micmute" ; + wpriv->cdev[led_type].brightness_set_blocking = &ideapad_wmi_micmute_led_set; + wpriv->cdev[led_type].default_trigger ="audio-micmute" ; + + err =devm_led_classdev_register (dev, &wpriv->cdev[led_type]); +if (err <0 ) + goto led_reg_failed; + +break ; +case AUDIO_MUTE : +if (led_version !=WMI_LUD_SUPPORT_AUDIOMUTE_LED_VER ) { + err = -EIO ; + goto led_error; + } + wpriv->cdev[led_type].name ="platform::mute" ; + wpriv->cdev[led_type].brightness_set_blocking = &ideapad_wmi_audiomute_led_set; + wpriv->cdev[led_type].default_trigger ="audio-mute" ; + + err =devm_led_classdev_register (dev, &wpriv->cdev[led_type]); +if (err <0 ) + goto led_reg_failed; + +break ; +default : + err = -EINVAL ;
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 175
Quoted 10 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +10
-0+dev_err (dev,"Unknown LED type %d\n" , led_type); + goto led_error; + } + +kfree (obj); +return 0 ; + +led_reg_failed: +dev_err (dev,"Could not register mute LED %d : %d\n" , led_type, err); +led_classdev_unregister (&wpriv->cdev[led_type]);
Do not call led_classdev_unregister() here if the LED device could not be registered in the first place.
Quoted 17 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +17
-0+led_error: +kfree (obj); +return err; +} + +static void ideapad_wmi_leds_setup (struct device *dev) +{ +ideapad_wmi_led_init (MIC_MUTE , dev); +ideapad_wmi_led_init (AUDIO_MUTE , dev); +} + +static int lenovo_super_hotkey_wmi_probe (struct wmi_device *wdev,const void *context) +{ +struct ideapad_wmi_private *wpriv; + + wpriv =devm_kzalloc (&wdev->dev,sizeof (*wpriv),GFP_KERNEL ); +if (!wpriv)
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 202
Quoted 10 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +10
-0+return -ENOMEM ; + + *wpriv = *(const struct ideapad_wmi_private *)context; + +dev_set_drvdata (&wdev->dev, wpriv); + +if (wpriv->event ==IDEAPAD_WMI_EVENT_LUD_KEYS ) { + led_wdev = wdev; +ideapad_wmi_leds_setup (&wdev->dev); + }
What is the purpose of IDEAPAD_WMI_EVENT_FN_KEYS?
Please remove the whole IDEAPAD_WMI_EVENT_FN_KEYS/IDEAPAD_WMI_EVENT_LUD_KEYS context handling code and instead only handle the LUD_WMI_METHOD_GUID in this driver.
Quoted 6 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +6
-0+ +return 0 ; +} + +static const struct ideapad_wmi_private lsk_wmi_context_fn_keys = { + .event =IDEAPAD_WMI_EVENT_FN_KEYS
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 218
Quoted 10 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +10
-0+}; + +static const struct ideapad_wmi_private lsk_wmi_context_lud_keys = { + .event =IDEAPAD_WMI_EVENT_LUD_KEYS +}; + +static const struct wmi_device_id lenovo_super_hotkey_wmi_id_table[] = { + {LUPKE_WMI_EVENT_GUID , &lsk_wmi_context_fn_keys },/* FN keys */ + {LUD_WMI_METHOD_GUID , &lsk_wmi_context_lud_keys },/* Utility data */ + { }
What is the reason for trying to bind to the LUPKE_WMI_EVENT_GUID?
AFAIK the ideapad-laptop driver already takes care of that.
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 225
Quoted 7 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +7
-0+}; + +MODULE_DEVICE_TABLE (wmi, lenovo_super_hotkey_wmi_id_table); + +static struct wmi_driver lenovo_super_hotkey_wmi_driver = { + .driver = { + .name ="lenovo_super_hotkey_wmi" ,
Please set .probe_type = PROBE_PREFER_ASYNCHRONOUS
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 228
Quoted 3 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +3
-0+ }, + .id_table = lenovo_super_hotkey_wmi_id_table, + .probe = lenovo_super_hotkey_wmi_probe,
Please set .no_singleton = true
Thanks,
Armin Wolf
Quoted 8 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +8
-0+}; + +module_wmi_driver (lenovo_super_hotkey_wmi_driver); + +MODULE_INFO (depends,"wmi,ideapad-laptop" ); +MODULE_AUTHOR ("Jackie Dong <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo Super Hotkey Utility WMI extras driver" ); +MODULE_LICENSE ("GPL" );
Re: [PATCH v2] platform/x86: lenovo-super-hotkey-wmi.c: Support formic and audio mute LEDs
Quoted 50 lines · Armin Wolf
Am 22.01.25 um 10:09 schrieb Jackie Dong:
Quoted 34 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 16p Gen8-IRL
ThinkBook 16p G7+ ASPSigned-off-by Jackie Dong <[email protected]>Suggested-by Mark Pearson <[email protected]>---
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.drivers/platform/x86/Kconfig | 7 + drivers/platform/x86/Makefile | 1 + .../platform/x86/lenovo-super-hotkey-wmi.c | 236 ++++++++++++++++++
3 files changed, 244 insertions(+)create mode 100644
drivers/platform/x86/lenovo-super-hotkey-wmi.cdrivers/platform/x86/Kconfig +0
-0@@ -475,6 +475,15 @@ config IDEAPAD_LAPTOPThis is a driver for Lenovo IdeaPad netbooks contains drivers for rfkill switch, hotkey, fan control and backlight control.
Quoted 10 lines
+config
LENOVO_HOTKEY_WMI
+ tristate "Lenovo Super Hotkey Utility WMI extras driver" + depends onACPI_WMI
+ depends onIDEAPAD_LAPTOP
+ help
+ This driver provides WMI support for Lenovo customized hotkeys function
+ of Lenovo NoteBooks which are for Consumer and SMB customers, such as
+ Ideapad/YOGA/XiaoXin/Gaming/ThinkBook and so on.Please change the name of the
Kconfigentry toLENOVO_SUPER_HOTKEY_WMIto match the name of the driver.
Quoted 1 line
Also, why does this driver depend on
IDEAPAD_LAPTOP?
Hi Armin,
Thanks for your carefully review and detail comments.
I have updated the patch based on these comments and send it as v3
just now.
For depend on IDEAPAD_LAPTOP, because KEY_MICMUTE event is handled in ideapad_laptop. And this file only turn on/off MIC mute LED after
the KEY_MICMUTE pressed. mic-mute LED function doesn't work without ideapad_laptop.ko.
{ KE_KEY, 0x3e | IDEAPAD_WMI_KEY, { KEY_MICMUTE } }, in ideapad_keymap[].
As I said in Changes in v2, in fact, this file is separated a WMI
driver named lenovo-super-hotkey-wmi.c from ideapad-lap.c.
Pls review it again, thanks a lot!
Quoted 320 lines
Quoted 61 lines
+
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_HOTKEY_WMI) += lenovo-super-hotkey-wmi.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-super-hotkey-wmi.c new file +38
-0@@ -0,0 +1,236 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Lenovo Super Hotkey Utility WMI extras driver for Ideapad laptop +* +* Copyright (C) 2025 Lenovo +*/ + +#include <linux/leds.h> +#include <linux/wmi.h> +#include "ideapad-laptop.h" + +/* Lenovo Super Hotkey WMI GUIDs */ +#define LUD_WMI_METHOD_GUID "CE6C0974-0407-4F50-88BA-4FC3B6559AD8" +#define LUPKE_WMI_EVENT_GUID "8FC0DE0C-B4E4-43FD-B0F3-8871711C1294" + +/* 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, + AUDIO_MUTE_LED_ON = 4, + AUDIO_MUTE_LED_OFF,drivers/platform/x86/lenovo-super-hotkey-wmi.c line 48
Quoted 10 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +10
-0+}; + +#define IDEAPAD_ACPI_LED_MAX 2 + +enum ideapad_wmi_event_type { + IDEAPAD_WMI_EVENT_FN_KEYS = 1, + IDEAPAD_WMI_EVENT_LUD_KEYS, +}; + +struct ideapad_wmi_private {Please rename everything in this driver which contains the name "ideapad" to instead contain the name of this driver.
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 53
Quoted 5 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +5
-0+ enum ideapad_wmi_event_type event; + struct led_classdev cdev[IDEAPAD_ACPI_LED_MAX]; +}; + +static struct wmi_device *led_wdev;Please use
container_of()to get a reference to your private data struct.Toachieve that i suggest you rework your private data struct like this:
structlenovo_hotkey_private{ enummute_led_typetype; structwmi_device*wdev; structled_classdevcdev; }; You can then allocate a
private data struct for each LED device and usecontainer_of(led_cdev, struct lenovo_hotkey_private, cdev)to get a reference to the associated struct from each LED classdev pointer. Then you can access
the WMI device and the LED type without having to use global variables.Quoted 21 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +7
-0+ +enum mute_led_type { + MIC_MUTE, + AUDIO_MUTE, +}; + +static int ideapad_wmi_mute_led_set(enum mute_led_type led_type,struct
led_classdev*led_cdev,
+ enumled_brightnessbrightness)drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +9
-0+ +{ + 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;
+ caseAUDIO_MUTE:Quoted 8 lines
+ led_arg.id = brightness ==
LED_ON?AUDIO_MUTE_LED_ON:AUDIO_MUTE_LED_OFF;
+ break;
+ default:
+ return-EINVAL;
+ }
+
+ input.length =sizeof(struct wmi_led_args);
sizeof(struct wmi_led_args)->sizeof(led_arg)Quoted 47 lines
+ input.pointer =
&led_arg;
+ status =wmidev_evaluate_method(led_wdev, 0, WMI_LUD_SET_FEATURE, &input, NULL);
+ if (ACPI_FAILURE(status))
+ return-EIO;drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +18
-0+ + return 0; +} + +static int ideapad_wmi_audiomute_led_set (struct led_classdev *led_cdev, + enum led_brightness brightness) + +{ + return ideapad_wmi_mute_led_set(AUDIO_MUTE, led_cdev, brightness); +} + +static int ideapad_wmi_micmute_led_set (struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + return ideapad_wmi_mute_led_set(MIC_MUTE, led_cdev, brightness); +} + +static int ideapad_wmi_led_init(enum mute_led_type led_type, structdevice *dev)
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +23
-0+{ + struct ideapad_wmi_private *wpriv = dev_get_drvdata(dev); + struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; + struct acpi_buffer input; + union acpi_object *obj; + 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(led_wdev, 0, WMI_LUD_GET_SUPPORT,Quoted 6 lines
&input, &output);
+ if (ACPI_FAILURE(status))
+ return-EIO;
+
+ obj = output.pointer;
+led_version=obj->integer.value;Please check if the resulting ACPI object is:
- not NULL
- actually an integerI also suggest that you copy the integer inside a local variable and free the ACPI object as soon as possible to avoid leaking it later.
Quoted 47 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +13
-0+ + wpriv->cdev[led_type].max_brightness = LED_ON; + wpriv->cdev[led_type].dev = dev; + wpriv->cdev[led_type].flags = LED_CORE_SUSPENDRESUME; + + switch (led_type) { + case MIC_MUTE: + if (led_version != WMI_LUD_SUPPORT_MICMUTE_LED_VER) { + err = -EIO; + goto led_error; + } + wpriv->cdev[led_type].name = "platform::micmute"; + wpriv->cdev[led_type].brightness_set_blocking =
&ideapad_wmi_micmute_led_set;
+ wpriv->cdev[led_type].default_trigger = "audio-micmute";drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +13
-0+ + err = devm_led_classdev_register(dev, &wpriv->cdev[led_type]); + if (err < 0) + goto led_reg_failed; + + break; + case AUDIO_MUTE: + if (led_version != WMI_LUD_SUPPORT_AUDIOMUTE_LED_VER) { + err = -EIO; + goto led_error; + } + wpriv->cdev[led_type].name = "platform::mute"; + wpriv->cdev[led_type].brightness_set_blocking =
&ideapad_wmi_audiomute_led_set;
+ wpriv->cdev[led_type].default_trigger = "audio-mute";drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +17
-0+ + err = devm_led_classdev_register(dev, &wpriv->cdev[led_type]); + if (err < 0) + goto led_reg_failed; + + break; + default: + err = -EINVAL; + dev_err(dev, "Unknown LED type %d\n", led_type); + goto led_error; + } + + kfree(obj); + return 0; + +led_reg_failed: + dev_err(dev, "Could not register mute LED %d : %d\n", led_type,Quoted 2 lines
err);
+led_classdev_unregister(&wpriv->cdev[led_type]);Do not call
led_classdev_unregister()here if the LED device could not be registered in the first place.Quoted 18 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +12
-0+led_error: + kfree(obj); + return err; +} + +static void ideapad_wmi_leds_setup (struct device *dev) +{ + ideapad_wmi_led_init(MIC_MUTE, dev); + ideapad_wmi_led_init(AUDIO_MUTE, dev); +} + +static int lenovo_super_hotkey_wmi_probe(struct wmi_device *wdev,const void *context)
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +5
-0+{ + struct ideapad_wmi_private *wpriv; + + wpriv = devm_kzalloc(&wdev->dev, sizeof(*wpriv), GFP_KERNEL); + if (!wpriv)drivers/platform/x86/lenovo-super-hotkey-wmi.c line 202
Quoted 10 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +10
-0+ return -ENOMEM; + + *wpriv = *(const struct ideapad_wmi_private *)context; + + dev_set_drvdata(&wdev->dev, wpriv); + + if (wpriv->event == IDEAPAD_WMI_EVENT_LUD_KEYS) { + led_wdev = wdev; + ideapad_wmi_leds_setup(&wdev->dev); + }What is the purpose of
IDEAPAD_WMI_EVENT_FN_KEYS?Please remove the whole IDEAPAD_WMI_EVENT_FN_KEYS/
IDEAPAD_WMI_EVENT_LUD_KEYScontext handling code and instead only handle theLUD_WMI_METHOD_GUIDin this driver.Quoted 15 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +15
-0+ + return 0; +} + +static const struct ideapad_wmi_private lsk_wmi_context_fn_keys = { + .event = IDEAPAD_WMI_EVENT_FN_KEYS +}; + +static const struct ideapad_wmi_private lsk_wmi_context_lud_keys = { + .event = IDEAPAD_WMI_EVENT_LUD_KEYS +}; + +static const struct wmi_device_id lenovo_super_hotkey_wmi_id_table[] = { + { LUPKE_WMI_EVENT_GUID, &lsk_wmi_context_fn_keys }, /* FN keys */ + { LUD_WMI_METHOD_GUID, &lsk_wmi_context_lud_keys }, /* UtilityQuoted 2 lines
data */
+ { }What is the reason for trying to bind to the
LUPKE_WMI_EVENT_GUID?AFAIK the ideapad-laptop driver already takes care of that.
drivers/platform/x86/lenovo-super-hotkey-wmi.c line 225
Quoted 7 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +7
-0+}; + +MODULE_DEVICE_TABLE (wmi, lenovo_super_hotkey_wmi_id_table); + +static struct wmi_driver lenovo_super_hotkey_wmi_driver = { + .driver = { + .name = "lenovo_super_hotkey_wmi",Please set .probe_type =
PROBE_PREFER_ASYNCHRONOUSQuoted 3 lines
+ },
+ .id_table =lenovo_super_hotkey_wmi_id_table, + .probe =lenovo_super_hotkey_wmi_probe,Please set .no_singleton = true
Thanks,
Armin WolfQuoted 8 lines
drivers/platform/x86/lenovo-super-hotkey-wmi.c new file +8
-0+}; + +module_wmi_driver (lenovo_super_hotkey_wmi_driver); + +MODULE_INFO (depends,"wmi,ideapad-laptop" ); +MODULE_AUTHOR ("Jackie Dong <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo Super Hotkey Utility WMI extras driver" ); +MODULE_LICENSE ("GPL" );