Skip to contentSkip to conversation

platform: lenovo: architecture independent home for the Lenovo WMI drivers

RFC PATCH Superseded David Cemin 7 participants 38 messages Nov 13 – Nov 21

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover platform: lenovo: architecture independent home for the Lenovo WMI drivers

Lenovo now ships ACPI based arm64 laptops whose firmware exposes the same ACPI-WMI interfaces as the x86 IdeaPad and Legion machines: the Fn key event GUID consumed by ideapad-laptop, the hotkey utility GUID used for the microphone mute LED, and the GameZone, Other Mode and capability data GUIDs behind the thermal operation modes. Since 884d53763d30 ("platform/wmi: Remove dependency on CONFIG_X86") the ACPI-WMI core builds on arm64, but the Lenovo WMI drivers still live under drivers/platform/x86, which is gated by X86_PLATFORM_DEVICES, so none of that code can be used where the firmware is.

This series:
1. moves the architecture independent Lenovo WMI drivers into a new drivers/platform/lenovo directory, following drivers/platform/surface which exists for the same reason (Surface ships x86 and arm64); ideapad-laptop, thinkpad_acpi, think-lmi and the Yoga tablet drivers stay under x86 because they need i8042, port I/O or x86 only devices;
2. adds a small WMI hotkeys driver for the Fn key event GUID on machines

     where ideapad-laptop cannot bind;

3. makes ideapad-laptop's own WMI event driver decline the GUIDs when the IdeaPad VPC device is absent, since it can never report events there.

Patch 2 was tested on a Lenovo Yoga 9 2-in-1 16 (arm64): microphone mute, airplane mode, the Smart Key, the Smart Connect key and the Fn+Q operation mode key all report input events. The same key set is dead on a Lenovo Yoga Pro 9 (arm64) today and uses the same GUID. Patches 1 and 3 are compile tested on x86_64 and arm64 (defconfig plus all LENOVO_WMI options as modules).

Two questions I would like the maintainers' view on before this goes further:

a. Is a vendor directory (drivers/platform/lenovo, like surface) the
right home, or should the architecture independent Lenovo WMI drivers move under drivers/platform/wmi next to the core instead?
b. Should the Fn key event handling stay a separate small driver, or
be factored out of ideapad-laptop so x86 and arm64 share one path? ideapad-laptop handles the event only when its VPC platform driver is bound, and the arm64 machines expose none of the VPC interface it is built on (no _CFG, VPCR/VPCW, DYTC or HALS/SALS), so making it the single driver means gating most of its probe. Two smaller
options: lift ideapad-laptop's own Fn key wmi_driver and keymap into this file and let ideapad-laptop register for the events it still wants (Fn lock LED, DYTC cycle), or the hid-asus/asus-wmi shape where a companion WMI module exports the event to a subsystem driver. The keymap in patch 2 duplicates entries of ideapad-laptop's table on purpose until that is decided.

Patch 2 declines to bind when the IdeaPad VPC device (VPC2004) is present, so machines handled by ideapad-laptop keep it; patch 3 is the mirror on the ideapad-laptop side. The new MAINTAINERS entry uses platform-driver-x86, the list that already covers drivers/platform/arm64, the ACPI-WMI core and the other Lenovo WMI drivers.

David Cemin (3):
platform: lenovo: move the architecture independent WMI drivers out of

    x86

platform: lenovo: add WMI hotkeys driver platform/x86: ideapad-laptop: do not bind the WMI event devices
without the VPC

 MAINTAINERS                                   |   9 +-
 drivers/platform/Kconfig                      |   2 +
 drivers/platform/Makefile                     |   1 +
 drivers/platform/lenovo/Kconfig               | 101 ++++++++++++
 drivers/platform/lenovo/Makefile              |  23 +++
 .../platform/{x86 => }/lenovo/wmi-camera.c    |   0
 .../platform/{x86 => }/lenovo/wmi-capdata.c   |   0
 .../platform/{x86 => }/lenovo/wmi-capdata.h   |   0
 .../platform/{x86 => }/lenovo/wmi-events.c    |   0
 .../platform/{x86 => }/lenovo/wmi-events.h    |   0
 .../platform/{x86 => }/lenovo/wmi-gamezone.c  |   0
 .../platform/{x86 => }/lenovo/wmi-helpers.c   |   0
 .../platform/{x86 => }/lenovo/wmi-helpers.h   |   0
 .../{x86 => }/lenovo/wmi-hotkey-utilities.c   |   0
 drivers/platform/lenovo/wmi-hotkeys.c         | 151 ++++++++++++++++++
 drivers/platform/{x86 => }/lenovo/wmi-other.c |   0
 drivers/platform/x86/lenovo/Kconfig           |  67 --------
 drivers/platform/x86/lenovo/Makefile          |   7 -
 drivers/platform/x86/lenovo/ideapad-laptop.c  |   8 +
 19 files changed, 294 insertions(+), 75 deletions(-)
 create mode 100644 drivers/platform/lenovo/Kconfig
 create mode 100644 drivers/platform/lenovo/Makefile
 rename drivers/platform/{x86 => }/lenovo/wmi-camera.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-gamezone.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-hotkey-utilities.c (100%)
 create mode 100644 drivers/platform/lenovo/wmi-hotkeys.c
 rename drivers/platform/{x86 => }/lenovo/wmi-other.c (100%)

base-commit: 2800868f63227c8237d70c41e70d441c919620d6

Signature · 1 line
2.56.1
#1 lore raw

RFC PATCH 1/3 platform: lenovo: move the architecture independent WMI drivers out of x86

The Lenovo WMI drivers (events, helpers, capability data, GameZone, Other Mode, hotkey utilities and camera button) contain no x86 specific
code: they talk to firmware through the ACPI-WMI core only. They live under drivers/platform/x86 because that is where Lenovo drivers were collected, and X86_PLATFORM_DEVICES keeps them off every other architecture.

Lenovo now ships ACPI based arm64 laptops whose firmware exposes the same WMI GUIDs (the Fn key events, the mic mute LED method, GameZone and Other Mode). Give these drivers an architecture independent home, drivers/platform/lenovo, following the layout of drivers/platform/surface which exists for the same reason, so they can be built wherever the WMI core is available. ideapad-laptop, thinkpad_acpi, think-lmi, yogabook and the Yoga Tablet drivers stay under x86: they depend on i8042, port I/O or x86 only ACPI devices.

Pure code motion: the files, their Kconfig entries and the module naming scheme are unchanged. MAINTAINERS entries are updated for the new paths.

---
 MAINTAINERS                                   |  3 +-
 drivers/platform/Kconfig                      |  2 +
 drivers/platform/Makefile                     |  1 +
 drivers/platform/lenovo/Kconfig               | 87 +++++++++++++++++++
 drivers/platform/lenovo/Makefile              | 22 +++++
 .../platform/{x86 => }/lenovo/wmi-camera.c    |  0
 .../platform/{x86 => }/lenovo/wmi-capdata.c   |  0
 .../platform/{x86 => }/lenovo/wmi-capdata.h   |  0
 .../platform/{x86 => }/lenovo/wmi-events.c    |  0
 .../platform/{x86 => }/lenovo/wmi-events.h    |  0
 .../platform/{x86 => }/lenovo/wmi-gamezone.c  |  0
 .../platform/{x86 => }/lenovo/wmi-helpers.c   |  0
 .../platform/{x86 => }/lenovo/wmi-helpers.h   |  0
 .../{x86 => }/lenovo/wmi-hotkey-utilities.c   |  0
 drivers/platform/{x86 => }/lenovo/wmi-other.c |  0
 drivers/platform/x86/lenovo/Kconfig           | 67 --------------
 drivers/platform/x86/lenovo/Makefile          |  7 --
 17 files changed, 114 insertions(+), 75 deletions(-)
 create mode 100644 drivers/platform/lenovo/Kconfig
 create mode 100644 drivers/platform/lenovo/Makefile
 rename drivers/platform/{x86 => }/lenovo/wmi-camera.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-gamezone.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-hotkey-utilities.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-other.c (100%)
MAINTAINERS +2 -1
index 056408bc086e..3b0ad5a3debe 100644
@@ -15170,13 +15170,14 @@ L:	[email protected]
 S:	Maintained
 F:	Documentation/wmi/devices/lenovo-wmi-gamezone.rst
 F:	Documentation/wmi/devices/lenovo-wmi-other.rst
+F:	drivers/platform/lenovo/
 F:	drivers/platform/x86/lenovo/*
 
 LENOVO WMI HOTKEY UTILITIES DRIVER
 M:	Jackie Dong <[email protected]>
 L:	[email protected]
 S:	Maintained
-F:	drivers/platform/x86/lenovo/wmi-hotkey-utilities.c
+F:	drivers/platform/lenovo/wmi-hotkey-utilities.c
 
 LENOVO HID drivers
 M:	Derek J. Clark <[email protected]>
drivers/platform/Kconfig +2 -0
index 312788f249c9..80b2b83b69e5 100644
@@ -15,6 +15,8 @@ source "drivers/platform/olpc/Kconfig"
 
 source "drivers/platform/surface/Kconfig"
 
+source "drivers/platform/lenovo/Kconfig"
+
 source "drivers/platform/x86/Kconfig"
 
 source "drivers/platform/arm64/Kconfig"
drivers/platform/Makefile +1 -0
index fa322e7f8716..0144f88ff6db 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_GOLDFISH)		+= goldfish/
 obj-$(CONFIG_CHROME_PLATFORMS)	+= chrome/
 obj-$(CONFIG_CZNIC_PLATFORMS)	+= cznic/
 obj-$(CONFIG_SURFACE_PLATFORMS)	+= surface/
+obj-$(CONFIG_LENOVO_PLATFORMS)	+= lenovo/
 obj-$(CONFIG_ARM64_PLATFORM_DEVICES)	+= arm64/
 obj-$(CONFIG_BCM2835_VCHIQ)	+= raspberrypi/
 obj-$(CONFIG_ACPI_WMI)		+= wmi/
drivers/platform/lenovo/Kconfig new file +87 -0

87 lines not on this page · raw message

drivers/platform/lenovo/Makefile new file +22 -0
new file mode 100644
index 000000000000..1cac115dd735
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for linux/drivers/platform/lenovo
+# Lenovo Platform Specific Drivers (architecture independent)
+#
+
+lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
+lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
+lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
+lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
+lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
+lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
+lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
+
+# Add 'lenovo' prefix to each module listed in lenovo-target-*
+define LENOVO_OBJ_TARGET
+lenovo-$(1)-y := $(1).o
+obj-$(2) += lenovo-$(1).o
+endef
+
+$(foreach target, $(basename $(lenovo-target-y)), $(eval $(call LENOVO_OBJ_TARGET,$(target),y)))
+$(foreach target, $(basename $(lenovo-target-m)), $(eval $(call LENOVO_OBJ_TARGET,$(target),m)))
drivers/platform/lenovo/wmi-camera.c renamed from drivers/platform/x86/lenovo/wmi-camera.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-camera.c
rename to drivers/platform/lenovo/wmi-camera.c
drivers/platform/lenovo/wmi-capdata.c renamed from drivers/platform/x86/lenovo/wmi-capdata.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-capdata.c
rename to drivers/platform/lenovo/wmi-capdata.c
drivers/platform/lenovo/wmi-capdata.h renamed from drivers/platform/x86/lenovo/wmi-capdata.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-capdata.h
rename to drivers/platform/lenovo/wmi-capdata.h
drivers/platform/lenovo/wmi-events.c renamed from drivers/platform/x86/lenovo/wmi-events.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-events.c
rename to drivers/platform/lenovo/wmi-events.c
drivers/platform/lenovo/wmi-events.h renamed from drivers/platform/x86/lenovo/wmi-events.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-events.h
rename to drivers/platform/lenovo/wmi-events.h
drivers/platform/lenovo/wmi-gamezone.c renamed from drivers/platform/x86/lenovo/wmi-gamezone.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-gamezone.c
rename to drivers/platform/lenovo/wmi-gamezone.c
drivers/platform/lenovo/wmi-helpers.c renamed from drivers/platform/x86/lenovo/wmi-helpers.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-helpers.c
rename to drivers/platform/lenovo/wmi-helpers.c
drivers/platform/lenovo/wmi-helpers.h renamed from drivers/platform/x86/lenovo/wmi-helpers.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-helpers.h
rename to drivers/platform/lenovo/wmi-helpers.h
drivers/platform/lenovo/wmi-hotkey-utilities.c renamed from drivers/platform/x86/lenovo/wmi-hotkey-utilities.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-hotkey-utilities.c
rename to drivers/platform/lenovo/wmi-hotkey-utilities.c
drivers/platform/lenovo/wmi-other.c renamed from drivers/platform/x86/lenovo/wmi-other.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-other.c
rename to drivers/platform/lenovo/wmi-other.c
drivers/platform/x86/lenovo/Kconfig +0 -67

76 lines not on this page · raw message

drivers/platform/x86/lenovo/Makefile +0 -7
index 12816d8d5e24..758c36cedee8 100644
@@ -7,17 +7,10 @@ obj-$(CONFIG_IDEAPAD_LAPTOP)	+= ideapad-laptop.o
 obj-$(CONFIG_THINKPAD_LMI)	+= think-lmi.o
 obj-$(CONFIG_THINKPAD_ACPI)	+= thinkpad_acpi.o
 
-lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
 lenovo-target-$(CONFIG_LENOVO_YB9_KBDOCK)	+= yb9-kbdock.o
 lenovo-target-$(CONFIG_LENOVO_YMC)	+= ymc.o
 lenovo-target-$(CONFIG_YOGABOOK)	+= yogabook.o
 lenovo-target-$(CONFIG_YT2_1380)	+= yoga-tab2-pro-1380-fastcharger.o
-lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
-lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
-lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
-lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
-lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
-lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
 
 # Add 'lenovo' prefix to each module listed in lenovo-target-*
 define LENOVO_OBJ_TARGET
Signature · 1 line
2.56.1
maintainer Reviewed-by on v1 1/3
#2 lore raw

Re: [RFC PATCH 1/3] platform: lenovo: move the architecture independent WMI drivers out of x86

Quoted 392 lines · David Cemin

The Lenovo WMI drivers (events, helpers, capability data, GameZone, Other Mode, hotkey utilities and camera button) contain no x86 specific
code: they talk to firmware through the ACPI-WMI core only. They live under drivers/platform/x86 because that is where Lenovo drivers were collected, and X86_PLATFORM_DEVICES keeps them off every other architecture.

Lenovo now ships ACPI based arm64 laptops whose firmware exposes the same WMI GUIDs (the Fn key events, the mic mute LED method, GameZone and Other Mode). Give these drivers an architecture independent home, drivers/platform/lenovo, following the layout of drivers/platform/surface which exists for the same reason, so they can be built wherever the WMI core is available. ideapad-laptop, thinkpad_acpi, think-lmi, yogabook and the Yoga Tablet drivers stay under x86: they depend on i8042, port I/O or x86 only ACPI devices.

Pure code motion: the files, their Kconfig entries and the module naming scheme are unchanged. MAINTAINERS entries are updated for the new paths.

---
 MAINTAINERS                                   |  3 +-
 drivers/platform/Kconfig                      |  2 +
 drivers/platform/Makefile                     |  1 +
 drivers/platform/lenovo/Kconfig               | 87 +++++++++++++++++++
 drivers/platform/lenovo/Makefile              | 22 +++++
 .../platform/{x86 => }/lenovo/wmi-camera.c    |  0
 .../platform/{x86 => }/lenovo/wmi-capdata.c   |  0
 .../platform/{x86 => }/lenovo/wmi-capdata.h   |  0
 .../platform/{x86 => }/lenovo/wmi-events.c    |  0
 .../platform/{x86 => }/lenovo/wmi-events.h    |  0
 .../platform/{x86 => }/lenovo/wmi-gamezone.c  |  0
 .../platform/{x86 => }/lenovo/wmi-helpers.c   |  0
 .../platform/{x86 => }/lenovo/wmi-helpers.h   |  0
 .../{x86 => }/lenovo/wmi-hotkey-utilities.c   |  0
 drivers/platform/{x86 => }/lenovo/wmi-other.c |  0
 drivers/platform/x86/lenovo/Kconfig           | 67 --------------
 drivers/platform/x86/lenovo/Makefile          |  7 --
 17 files changed, 114 insertions(+), 75 deletions(-)
 create mode 100644 drivers/platform/lenovo/Kconfig
 create mode 100644 drivers/platform/lenovo/Makefile
 rename drivers/platform/{x86 => }/lenovo/wmi-camera.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-gamezone.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-hotkey-utilities.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-other.c (100%)
MAINTAINERS +2 -1
index 056408bc086e..3b0ad5a3debe 100644
@@ -15170,13 +15170,14 @@ L:	[email protected]
 S:	Maintained
 F:	Documentation/wmi/devices/lenovo-wmi-gamezone.rst
 F:	Documentation/wmi/devices/lenovo-wmi-other.rst
+F:	drivers/platform/lenovo/
 F:	drivers/platform/x86/lenovo/*
 
 LENOVO WMI HOTKEY UTILITIES DRIVER
 M:	Jackie Dong <[email protected]>
 L:	[email protected]
 S:	Maintained
-F:	drivers/platform/x86/lenovo/wmi-hotkey-utilities.c
+F:	drivers/platform/lenovo/wmi-hotkey-utilities.c
 
 LENOVO HID drivers
 M:	Derek J. Clark <[email protected]>
drivers/platform/Kconfig +2 -0
index 312788f249c9..80b2b83b69e5 100644
@@ -15,6 +15,8 @@ source "drivers/platform/olpc/Kconfig"
 
 source "drivers/platform/surface/Kconfig"
 
+source "drivers/platform/lenovo/Kconfig"
+
 source "drivers/platform/x86/Kconfig"
 
 source "drivers/platform/arm64/Kconfig"
drivers/platform/Makefile +1 -0
index fa322e7f8716..0144f88ff6db 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_GOLDFISH)		+= goldfish/
 obj-$(CONFIG_CHROME_PLATFORMS)	+= chrome/
 obj-$(CONFIG_CZNIC_PLATFORMS)	+= cznic/
 obj-$(CONFIG_SURFACE_PLATFORMS)	+= surface/
+obj-$(CONFIG_LENOVO_PLATFORMS)	+= lenovo/
 obj-$(CONFIG_ARM64_PLATFORM_DEVICES)	+= arm64/
 obj-$(CONFIG_BCM2835_VCHIQ)	+= raspberrypi/
 obj-$(CONFIG_ACPI_WMI)		+= wmi/
drivers/platform/lenovo/Kconfig new file +11 -0
new file mode 100644
index 000000000000..8222322ca671
@@ -0,0 +1,87 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Lenovo Platform-Specific Drivers
+#
+
+menuconfig LENOVO_PLATFORMS
+	bool "Lenovo Platform-Specific Device Drivers"
+	depends on ARM64 || X86 || COMPILE_TEST
+	default y if ARM64 || X86
+	help
+	  Say Y here to get to see options for platform-specific device 

drivers

drivers/platform/lenovo/Kconfig new file +5 -0
+	  for Lenovo devices that do not depend on the CPU architecture, such
+	  as the ACPI-WMI based drivers used on both x86 and arm64 laptops.
+	  This option alone does not add any kernel code.
+
+	  If you say N, all options in this submenu will be skipped and 

disabled.

drivers/platform/lenovo/Kconfig new file +24 -0
+
+if LENOVO_PLATFORMS
+
+config LENOVO_WMI_HELPERS
+	tristate
+	depends on ACPI_WMI
+
+config LENOVO_WMI_EVENTS
+	tristate
+	depends on ACPI_WMI
+
+config LENOVO_WMI_CAPDATA
+	tristate
+	depends on ACPI_WMI
+	depends on LENOVO_WMI_HELPERS
+
+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,

drivers/platform/lenovo/Kconfig new file +1 -0
+	  such as LED control for audio/mic mute event for Ideapad, YOGA, 

XiaoXin,

drivers/platform/lenovo/Kconfig new file +9 -0
+	  Gaming, ThinkBook and so on.
+
+config LENOVO_WMI_CAMERA
+	tristate "Lenovo WMI Camera Button driver"
+	depends on ACPI_WMI
+	depends on INPUT
+	help
+	  This driver provides support for Lenovo camera button. The Camera
+	  button is a GPIO device. This driver receives ACPI notifications 

when

drivers/platform/lenovo/Kconfig new file +14 -0
+	  the camera button is switched on/off.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called lenovo-wmi-camera.
+
+config LENOVO_WMI_GAMEZONE
+	tristate "Lenovo GameZone WMI Driver"
+	depends on ACPI_WMI
+	depends on DMI
+	select ACPI_PLATFORM_PROFILE
+	select LENOVO_WMI_EVENTS
+	select LENOVO_WMI_HELPERS
+	help
+	  Say Y here if you have a WMI aware Lenovo Legion device and would 

like to use the

drivers/platform/lenovo/Kconfig new file +16 -0
+	  platform-profile firmware interface to manage power usage.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called lenovo-wmi-gamezone.
+
+config LENOVO_WMI_TUNING
+	tristate "Lenovo Other Mode WMI Driver"
+	depends on ACPI_WMI
+	depends on ACPI_BATTERY
+	select HWMON
+	select FW_ATTR_CLASS
+	select LENOVO_WMI_CAPDATA
+	select LENOVO_WMI_EVENTS
+	select LENOVO_WMI_HELPERS
+	help
+	  Say Y here if you have a WMI aware Lenovo Legion device and would 

like to use the

drivers/platform/lenovo/Kconfig new file +1 -0
+	  firmware_attributes API to control various tunable settings 

typically exposed by

drivers/platform/lenovo/Kconfig new file +6 -0
+	  Lenovo software in Windows.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called lenovo-wmi-other.
+
+endif # LENOVO_PLATFORMS
drivers/platform/lenovo/Makefile new file +10 -0
new file mode 100644
index 000000000000..1cac115dd735
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for linux/drivers/platform/lenovo
+# Lenovo Platform Specific Drivers (architecture independent)
+#
+
+lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
+lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
+lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
+lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= 

wmi-hotkey-utilities.o

drivers/platform/lenovo/Makefile new file +11 -0
+lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
+lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
+lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
+
+# Add 'lenovo' prefix to each module listed in lenovo-target-*
+define LENOVO_OBJ_TARGET
+lenovo-$(1)-y := $(1).o
+obj-$(2) += lenovo-$(1).o
+endef
+
+$(foreach target, $(basename $(lenovo-target-y)), $(eval $(call 

LENOVO_OBJ_TARGET,$(target),y)))
+$(foreach target, $(basename $(lenovo-target-m)), $(eval $(call LENOVO_OBJ_TARGET,$(target),m)))

drivers/platform/lenovo/wmi-camera.c renamed from drivers/platform/x86/lenovo/wmi-camera.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-camera.c
rename to drivers/platform/lenovo/wmi-camera.c
drivers/platform/lenovo/wmi-capdata.c renamed from drivers/platform/x86/lenovo/wmi-capdata.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-capdata.c
rename to drivers/platform/lenovo/wmi-capdata.c
drivers/platform/lenovo/wmi-capdata.h renamed from drivers/platform/x86/lenovo/wmi-capdata.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-capdata.h
rename to drivers/platform/lenovo/wmi-capdata.h
drivers/platform/lenovo/wmi-events.c renamed from drivers/platform/x86/lenovo/wmi-events.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-events.c
rename to drivers/platform/lenovo/wmi-events.c
drivers/platform/lenovo/wmi-events.h renamed from drivers/platform/x86/lenovo/wmi-events.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-events.h
rename to drivers/platform/lenovo/wmi-events.h
drivers/platform/lenovo/wmi-gamezone.c renamed from drivers/platform/x86/lenovo/wmi-gamezone.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-gamezone.c
rename to drivers/platform/lenovo/wmi-gamezone.c
drivers/platform/lenovo/wmi-helpers.c renamed from drivers/platform/x86/lenovo/wmi-helpers.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-helpers.c
rename to drivers/platform/lenovo/wmi-helpers.c
drivers/platform/lenovo/wmi-helpers.h renamed from drivers/platform/x86/lenovo/wmi-helpers.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-helpers.h
rename to drivers/platform/lenovo/wmi-helpers.h
drivers/platform/lenovo/wmi-hotkey-utilities.c renamed from drivers/platform/x86/lenovo/wmi-hotkey-utilities.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-hotkey-utilities.c
rename to drivers/platform/lenovo/wmi-hotkey-utilities.c
drivers/platform/lenovo/wmi-other.c renamed from drivers/platform/x86/lenovo/wmi-other.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-other.c
rename to drivers/platform/lenovo/wmi-other.c
drivers/platform/x86/lenovo/Kconfig +0 -46
index 516594993073..36bcefb61805 100644
@@ -20,29 +20,6 @@ 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_WMI_CAMERA
-	tristate "Lenovo WMI Camera Button driver"
-	depends on ACPI_WMI
-	depends on INPUT
-	help
-	  This driver provides support for Lenovo camera button. The Camera
-	  button is a GPIO device. This driver receives ACPI notifications when
-	  the camera button is switched on/off.
-
-	  To compile this driver as a module, choose M here: the module
-	  will be called lenovo-wmi-camera.
-
 config LENOVO_YB9_KBDOCK
 	tristate "Lenovo Yoga Book 9 keyboard dock detection"
 	depends on ACPI_WMI
@@ -246,47 +223,3 @@ config YT2_1380
 
 	  To compile this driver as a module, choose M here: the module will
 	  be called lenovo-yogabook.
-
-config LENOVO_WMI_CAPDATA
-	tristate
-	depends on ACPI_WMI
-	depends on LENOVO_WMI_HELPERS
-
-config LENOVO_WMI_EVENTS
-	tristate
-	depends on ACPI_WMI
-
-config LENOVO_WMI_HELPERS
-	tristate
-	depends on ACPI_WMI
-
-config LENOVO_WMI_GAMEZONE
-	tristate "Lenovo GameZone WMI Driver"
-	depends on ACPI_WMI
-	depends on DMI
-	select ACPI_PLATFORM_PROFILE
-	select LENOVO_WMI_EVENTS
-	select LENOVO_WMI_HELPERS
-	help
-	  Say Y here if you have a WMI aware Lenovo Legion device and would 

like to use the

drivers/platform/x86/lenovo/Kconfig +0 -16
-	  platform-profile firmware interface to manage power usage.
-
-	  To compile this driver as a module, choose M here: the module will
-	  be called lenovo-wmi-gamezone.
-
-config LENOVO_WMI_TUNING
-	tristate "Lenovo Other Mode WMI Driver"
-	depends on ACPI_WMI
-	depends on ACPI_BATTERY
-	select HWMON
-	select FW_ATTR_CLASS
-	select LENOVO_WMI_CAPDATA
-	select LENOVO_WMI_EVENTS
-	select LENOVO_WMI_HELPERS
-	help
-	  Say Y here if you have a WMI aware Lenovo Legion device and would 

like to use the

drivers/platform/x86/lenovo/Kconfig +0 -1
-	  firmware_attributes API to control various tunable settings 

typically exposed by

drivers/platform/x86/lenovo/Kconfig +0 -4
-	  Lenovo software in Windows.
-
-	  To compile this driver as a module, choose M here: the module will
-	  be called lenovo-wmi-other.
drivers/platform/x86/lenovo/Makefile +0 -7
index 12816d8d5e24..758c36cedee8 100644
@@ -7,17 +7,10 @@ obj-$(CONFIG_IDEAPAD_LAPTOP)	+= ideapad-laptop.o
 obj-$(CONFIG_THINKPAD_LMI)	+= think-lmi.o
 obj-$(CONFIG_THINKPAD_ACPI)	+= thinkpad_acpi.o
 
-lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
 lenovo-target-$(CONFIG_LENOVO_YB9_KBDOCK)	+= yb9-kbdock.o
 lenovo-target-$(CONFIG_LENOVO_YMC)	+= ymc.o
 lenovo-target-$(CONFIG_YOGABOOK)	+= yogabook.o
 lenovo-target-$(CONFIG_YT2_1380)	+= yoga-tab2-pro-1380-fastcharger.o
-lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
-lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
-lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
-lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
-lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
-lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
 
 # Add 'lenovo' prefix to each module listed in lenovo-target-*
 define LENOVO_OBJ_TARGET
Signature · 1 line
2.56.1

Looks good to me.
Will the MAINTAINERS file need updating?

Mark

#3 lore raw

Re: [RFC PATCH 1/3] platform: lenovo: move the architecture independent WMI drivers out of x86

Hi Mark,

Thanks for the review. Patch 1 moves the MAINTAINERS paths for the moved files and adds the new entry; I will double check the entries for the files you listed in v2. Happy to see think-lmi follow once your tlmi series is out.

Thanks,
David

maintainer
#4 lore raw

Re: [RFC PATCH 1/3] platform: lenovo: move the architecture independent WMI drivers out of x86

Quoted 7 lines · David Cemin

Hi Mark,

Thanks for the review. Patch 1 moves the MAINTAINERS paths for the moved files and adds the new entry; I will double check the entries for the files you listed in v2. Happy to see think-lmi follow once your tlmi series is out.

Doh - my apologies. Not sure how I missed that.
Thanks
Mark

maintainer Reviewed-by
#5 lore raw

Re: [RFC PATCH 1/3] platform: lenovo: move the architecture independent WMI drivers out of x86

In reply to Mark Pearson
Quoted 446 lines · Mark Pearson
Quoted 435 lines · David Cemin

The Lenovo WMI drivers (events, helpers, capability data, GameZone, Other Mode, hotkey utilities and camera button) contain no x86 specific
code: they talk to firmware through the ACPI-WMI core only. They live
under drivers/platform/x86 because that is where Lenovo drivers were
collected, and X86_PLATFORM_DEVICES keeps them off every other architecture.

Lenovo now ships ACPI based arm64 laptops whose firmware exposes the
same WMI GUIDs (the Fn key events, the mic mute LED method, GameZone and
Other Mode). Give these drivers an architecture independent home, drivers/platform/lenovo, following the layout of drivers/platform/surface
which exists for the same reason, so they can be built wherever the WMI
core is available. ideapad-laptop, thinkpad_acpi, think-lmi, yogabook and
the Yoga Tablet drivers stay under x86: they depend on i8042, port I/O or
x86 only ACPI devices.

Pure code motion: the files, their Kconfig entries and the module naming
scheme are unchanged. MAINTAINERS entries are updated for the new paths.

---
 MAINTAINERS                                   |  3 +- drivers/platform/Kconfig                      |  2 + drivers/platform/Makefile                     |  1 + drivers/platform/lenovo/Kconfig               | 87
+++++++++++++++++++
 drivers/platform/lenovo/Makefile              | 22 +++++ .../platform/{x86 => }/lenovo/wmi-camera.c    |  0 .../platform/{x86 => }/lenovo/wmi-capdata.c   |  0 .../platform/{x86 => }/lenovo/wmi-capdata.h   |  0 .../platform/{x86 => }/lenovo/wmi-events.c    |  0 .../platform/{x86 => }/lenovo/wmi-events.h    |  0 .../platform/{x86 => }/lenovo/wmi-gamezone.c  |  0

 .../platform/{x86 => }/lenovo/wmi-helpers.c   |  0
 .../platform/{x86 => }/lenovo/wmi-helpers.h   |  0
 .../{x86 => }/lenovo/wmi-hotkey-utilities.c   |  0
 drivers/platform/{x86 => }/lenovo/wmi-other.c |  0
 drivers/platform/x86/lenovo/Kconfig           | 67 --------------
 drivers/platform/x86/lenovo/Makefile          |  7 --
 17 files changed, 114 insertions(+), 75 deletions(-)

 create mode 100644 drivers/platform/lenovo/Kconfig create mode 100644 drivers/platform/lenovo/Makefile rename drivers/platform/{x86 => }/lenovo/wmi-camera.c (100%) rename drivers/platform/{x86 => }/lenovo/wmi-capdata.c (100%) rename drivers/platform/{x86 => }/lenovo/wmi-capdata.h (100%) rename drivers/platform/{x86 => }/lenovo/wmi-events.c (100%) rename drivers/platform/{x86 => }/lenovo/wmi-events.h (100%) rename drivers/platform/{x86 => }/lenovo/wmi-gamezone.c (100%) rename drivers/platform/{x86 => }/lenovo/wmi-helpers.c (100%) rename drivers/platform/{x86 => }/lenovo/wmi-helpers.h (100%) rename drivers/platform/{x86 => }/lenovo/wmi-hotkey-utilities.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-other.c (100%)

MAINTAINERS +0 -0
index 056408bc086e..3b0ad5a3debe 100644
@@ -15170,13 +15170,14 @@

L: [email protected]
 S: Maintained
 F: Documentation/wmi/devices/lenovo-wmi-gamezone.rst
 F: Documentation/wmi/devices/lenovo-wmi-other.rst
+F: drivers/platform/lenovo/
 F: drivers/platform/x86/lenovo/*

 LENOVO WMI HOTKEY UTILITIES DRIVER
 M: Jackie Dong <[email protected]>
 L: [email protected]
 S: Maintained

MAINTAINERS +1 -1
-F:	drivers/platform/x86/lenovo/wmi-hotkey-utilities.c
+F:	drivers/platform/lenovo/wmi-hotkey-utilities.c

 LENOVO HID drivers
 M: Derek J. Clark <[email protected]>

drivers/platform/Kconfig +0 -0
index 312788f249c9..80b2b83b69e5 100644
@@ -15,6 +15,8 @@ source "drivers/platform/olpc/Kconfig"
 

 source "drivers/platform/surface/Kconfig"

drivers/platform/Kconfig +2 -0
+source "drivers/platform/lenovo/Kconfig"
+

 source "drivers/platform/x86/Kconfig"

 source "drivers/platform/arm64/Kconfig"

drivers/platform/Makefile +0 -0
index fa322e7f8716..0144f88ff6db 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_GOLDFISH)		+=

goldfish/
 obj-$(CONFIG_CHROME_PLATFORMS) += chrome/
 obj-$(CONFIG_CZNIC_PLATFORMS) += cznic/
 obj-$(CONFIG_SURFACE_PLATFORMS) += surface/
+obj-$(CONFIG_LENOVO_PLATFORMS) += lenovo/
 obj-$(CONFIG_ARM64_PLATFORM_DEVICES) += arm64/
 obj-$(CONFIG_BCM2835_VCHIQ) += raspberrypi/
 obj-$(CONFIG_ACPI_WMI) += wmi/

drivers/platform/lenovo/Kconfig new file +11 -0
new file mode 100644
index 000000000000..8222322ca671
@@ -0,0 +1,87 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Lenovo Platform-Specific Drivers
+#
+
+menuconfig LENOVO_PLATFORMS
+	bool "Lenovo Platform-Specific Device Drivers"
+	depends on ARM64 || X86 || COMPILE_TEST
+	default y if ARM64 || X86
+	help
+	  Say Y here to get to see options for platform-specific

device
drivers

drivers/platform/lenovo/Kconfig new file +1 -0
+	  for Lenovo devices that do not depend on the CPU

architecture, such

drivers/platform/lenovo/Kconfig new file +1 -0
+	  as the ACPI-WMI based drivers used on both x86 and arm64

laptops.

drivers/platform/lenovo/Kconfig new file +3 -0
+	  This option alone does not add any kernel code.
+
+	  If you say N, all options in this submenu will be

skipped and
disabled.

drivers/platform/lenovo/Kconfig new file +24 -0
+
+if LENOVO_PLATFORMS
+
+config LENOVO_WMI_HELPERS
+	tristate
+	depends on ACPI_WMI
+
+config LENOVO_WMI_EVENTS
+	tristate
+	depends on ACPI_WMI
+
+config LENOVO_WMI_CAPDATA
+	tristate
+	depends on ACPI_WMI
+	depends on LENOVO_WMI_HELPERS
+
+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,

drivers/platform/lenovo/Kconfig new file +1 -0
+	  such as LED control for audio/mic mute event for

Ideapad, YOGA,
XiaoXin,

drivers/platform/lenovo/Kconfig new file +8 -0
+	  Gaming, ThinkBook and so on.
+
+config LENOVO_WMI_CAMERA
+	tristate "Lenovo WMI Camera Button driver"
+	depends on ACPI_WMI
+	depends on INPUT
+	help
+	  This driver provides support for Lenovo camera button.

The Camera

drivers/platform/lenovo/Kconfig new file +1 -0
+	  button is a GPIO device. This driver receives ACPI

notifications
when

drivers/platform/lenovo/Kconfig new file +3 -0
+	  the camera button is switched on/off.
+
+	  To compile this driver as a module, choose M here: the

module

drivers/platform/lenovo/Kconfig new file +11 -0
+	  will be called lenovo-wmi-camera.
+
+config LENOVO_WMI_GAMEZONE
+	tristate "Lenovo GameZone WMI Driver"
+	depends on ACPI_WMI
+	depends on DMI
+	select ACPI_PLATFORM_PROFILE
+	select LENOVO_WMI_EVENTS
+	select LENOVO_WMI_HELPERS
+	help
+	  Say Y here if you have a WMI aware Lenovo Legion device

and would
like to use the

drivers/platform/lenovo/Kconfig new file +1 -0
+	  platform-profile firmware interface to manage power

usage.

drivers/platform/lenovo/Kconfig new file +2 -0
+
+	  To compile this driver as a module, choose M here: the

module will

drivers/platform/lenovo/Kconfig new file +13 -0
+	  be called lenovo-wmi-gamezone.
+
+config LENOVO_WMI_TUNING
+	tristate "Lenovo Other Mode WMI Driver"
+	depends on ACPI_WMI
+	depends on ACPI_BATTERY
+	select HWMON
+	select FW_ATTR_CLASS
+	select LENOVO_WMI_CAPDATA
+	select LENOVO_WMI_EVENTS
+	select LENOVO_WMI_HELPERS
+	help
+	  Say Y here if you have a WMI aware Lenovo Legion device

and would
like to use the

drivers/platform/lenovo/Kconfig new file +1 -0
+	  firmware_attributes API to control various tunable

settings
typically exposed by

drivers/platform/lenovo/Kconfig new file +3 -0
+	  Lenovo software in Windows.
+
+	  To compile this driver as a module, choose M here: the

module will

drivers/platform/lenovo/Kconfig new file +3 -0
+	  be called lenovo-wmi-other.
+
+endif # LENOVO_PLATFORMS
drivers/platform/lenovo/Makefile new file +10 -0
new file mode 100644
index 000000000000..1cac115dd735
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for linux/drivers/platform/lenovo
+# Lenovo Platform Specific Drivers (architecture independent)
+#
+
+lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
+lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
+lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
+lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= 

wmi-hotkey-utilities.o

drivers/platform/lenovo/Makefile new file +11 -0
+lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
+lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
+lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
+
+# Add 'lenovo' prefix to each module listed in lenovo-target-*
+define LENOVO_OBJ_TARGET
+lenovo-$(1)-y := $(1).o
+obj-$(2) += lenovo-$(1).o
+endef
+
+$(foreach target, $(basename $(lenovo-target-y)), $(eval $(call 

LENOVO_OBJ_TARGET,$(target),y)))
+$(foreach target, $(basename $(lenovo-target-m)), $(eval $(call LENOVO_OBJ_TARGET,$(target),m)))

drivers/platform/lenovo/wmi-camera.c renamed from drivers/platform/x86/lenovo/wmi-camera.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-camera.c
rename to drivers/platform/lenovo/wmi-camera.c
drivers/platform/lenovo/wmi-capdata.c renamed from drivers/platform/x86/lenovo/wmi-capdata.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-capdata.c
rename to drivers/platform/lenovo/wmi-capdata.c
drivers/platform/lenovo/wmi-capdata.h renamed from drivers/platform/x86/lenovo/wmi-capdata.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-capdata.h
rename to drivers/platform/lenovo/wmi-capdata.h
drivers/platform/lenovo/wmi-events.c renamed from drivers/platform/x86/lenovo/wmi-events.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-events.c
rename to drivers/platform/lenovo/wmi-events.c
drivers/platform/lenovo/wmi-events.h renamed from drivers/platform/x86/lenovo/wmi-events.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-events.h
rename to drivers/platform/lenovo/wmi-events.h
drivers/platform/lenovo/wmi-gamezone.c renamed from drivers/platform/x86/lenovo/wmi-gamezone.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-gamezone.c
rename to drivers/platform/lenovo/wmi-gamezone.c
drivers/platform/lenovo/wmi-helpers.c renamed from drivers/platform/x86/lenovo/wmi-helpers.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-helpers.c
rename to drivers/platform/lenovo/wmi-helpers.c
drivers/platform/lenovo/wmi-helpers.h renamed from drivers/platform/x86/lenovo/wmi-helpers.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-helpers.h
rename to drivers/platform/lenovo/wmi-helpers.h
drivers/platform/lenovo/wmi-hotkey-utilities.c renamed from drivers/platform/x86/lenovo/wmi-hotkey-utilities.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-hotkey-utilities.c
rename to drivers/platform/lenovo/wmi-hotkey-utilities.c
drivers/platform/lenovo/wmi-other.c renamed from drivers/platform/x86/lenovo/wmi-other.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-other.c
rename to drivers/platform/lenovo/wmi-other.c
drivers/platform/x86/lenovo/Kconfig +0 -0
index 516594993073..36bcefb61805 100644
@@ -20,29 +20,6 @@ config IDEAPAD_LAPTOP

    This is a driver for Lenovo IdeaPad netbooks contains drivers for
    rfkill switch, hotkey, fan control and backlight control.

drivers/platform/x86/lenovo/Kconfig +0 -8
-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,

drivers/platform/x86/lenovo/Kconfig +0 -1
-	  such as LED control for audio/mic mute event for

Ideapad, YOGA, XiaoXin,

drivers/platform/x86/lenovo/Kconfig +0 -8
-	  Gaming, ThinkBook and so on.
-
-config LENOVO_WMI_CAMERA
-	tristate "Lenovo WMI Camera Button driver"
-	depends on ACPI_WMI
-	depends on INPUT
-	help
-	  This driver provides support for Lenovo camera button.

The Camera

drivers/platform/x86/lenovo/Kconfig +0 -1
-	  button is a GPIO device. This driver receives ACPI

notifications when

drivers/platform/x86/lenovo/Kconfig +0 -3
-	  the camera button is switched on/off.
-
-	  To compile this driver as a module, choose M here: the

module

drivers/platform/x86/lenovo/Kconfig +0 -2
-	  will be called lenovo-wmi-camera.
-

 config LENOVO_YB9_KBDOCK
  tristate "Lenovo Yoga Book 9 keyboard dock detection" depends on ACPI_WMI

drivers/platform/x86/lenovo/Kconfig +0 -0
@@ -246,47 +223,3 @@ config YT2_1380
 

    To compile this driver as a module, choose M here: the module will
    be called lenovo-yogabook.

drivers/platform/x86/lenovo/Kconfig +0 -23
-
-config LENOVO_WMI_CAPDATA
-	tristate
-	depends on ACPI_WMI
-	depends on LENOVO_WMI_HELPERS
-
-config LENOVO_WMI_EVENTS
-	tristate
-	depends on ACPI_WMI
-
-config LENOVO_WMI_HELPERS
-	tristate
-	depends on ACPI_WMI
-
-config LENOVO_WMI_GAMEZONE
-	tristate "Lenovo GameZone WMI Driver"
-	depends on ACPI_WMI
-	depends on DMI
-	select ACPI_PLATFORM_PROFILE
-	select LENOVO_WMI_EVENTS
-	select LENOVO_WMI_HELPERS
-	help
-	  Say Y here if you have a WMI aware Lenovo Legion device

and would
like to use the

drivers/platform/x86/lenovo/Kconfig +0 -1
-	  platform-profile firmware interface to manage power

usage.

drivers/platform/x86/lenovo/Kconfig +0 -2
-
-	  To compile this driver as a module, choose M here: the

module will

drivers/platform/x86/lenovo/Kconfig +0 -13
-	  be called lenovo-wmi-gamezone.
-
-config LENOVO_WMI_TUNING
-	tristate "Lenovo Other Mode WMI Driver"
-	depends on ACPI_WMI
-	depends on ACPI_BATTERY
-	select HWMON
-	select FW_ATTR_CLASS
-	select LENOVO_WMI_CAPDATA
-	select LENOVO_WMI_EVENTS
-	select LENOVO_WMI_HELPERS
-	help
-	  Say Y here if you have a WMI aware Lenovo Legion device

and would
like to use the

drivers/platform/x86/lenovo/Kconfig +0 -1
-	  firmware_attributes API to control various tunable

settings
typically exposed by

drivers/platform/x86/lenovo/Kconfig +0 -3
-	  Lenovo software in Windows.
-
-	  To compile this driver as a module, choose M here: the

module will

drivers/platform/x86/lenovo/Kconfig +0 -1
-	  be called lenovo-wmi-other.
drivers/platform/x86/lenovo/Makefile +0 -0
index 12816d8d5e24..758c36cedee8 100644
@@ -7,17 +7,10 @@ obj-$(CONFIG_IDEAPAD_LAPTOP)	+= ideapad-

laptop.o
 obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
 obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o

-lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += wmi-
hotkey-utilities.o
 lenovo-target-$(CONFIG_LENOVO_YB9_KBDOCK) += yb9-kbdock.o
 lenovo-target-$(CONFIG_LENOVO_YMC) += ymc.o
 lenovo-target-$(CONFIG_YOGABOOK) += yogabook.o
 lenovo-target-$(CONFIG_YT2_1380) += yoga-tab2-pro-1380-
fastcharger.o

drivers/platform/x86/lenovo/Makefile +0 -6
-lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
-lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
-lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
-lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
-lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
-lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
Quoted 4 lines

 # Add 'lenovo' prefix to each module listed in lenovo-target-* define LENOVO_OBJ_TARGET

Signature · 1 line
2.56.1

Looks good to me.
Will the MAINTAINERS file need updating?

Quoted 2 lines

Mark

It's a good idea that the Lenovo WMI drivers codes are in one lenovo directory for different architecture.
It's OK for me.

Jackie

#6 lore raw

RFC PATCH 2/3 platform: lenovo: add WMI hotkeys driver

In reply to David Cemin

Lenovo consumer laptops deliver their vendor specific Fn keys (microphone mute, airplane mode, performance mode, the Smart Key and Smart Connect keys) as WMI events on GUID 8FC0DE0C-B4E4-43FD-B0F3-8871711C1294 instead of keyboard usages. On x86, ideapad-laptop consumes these events, but it depends on i8042 and on the IdeaPad VPC ACPI device, neither of which exist on the ACPI based arm64 models. Add a small WMI driver that reports the same key codes through a sparse keymap, so desktops see the generic input events.

The key map follows ideapad-laptop. One code seen on the Yoga 9 2-in-1 16 (arm64) is new: 0x48 for the Smart Connect key.

Both drivers match the same GUID. The probe declines when the IdeaPad VPC device (VPC2004) is present, so machines handled by ideapad-laptop, including its Fn lock LED and DYTC performance mode handling, keep that driver.

---
 MAINTAINERS                           |   6 +
 drivers/platform/lenovo/Kconfig       |  14 +++
 drivers/platform/lenovo/Makefile      |   1 +
 drivers/platform/lenovo/wmi-hotkeys.c | 151 ++++++++++++++++++++++++++
 4 files changed, 172 insertions(+)
 create mode 100644 drivers/platform/lenovo/wmi-hotkeys.c
MAINTAINERS +6 -0
index 3b0ad5a3debe..207684aeaf69 100644
@@ -15173,6 +15173,12 @@ F:	Documentation/wmi/devices/lenovo-wmi-other.rst
 F:	drivers/platform/lenovo/
 F:	drivers/platform/x86/lenovo/*
 
+LENOVO WMI HOTKEYS DRIVER
+M:	David Cemin <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/platform/lenovo/wmi-hotkeys.c
+
 LENOVO WMI HOTKEY UTILITIES DRIVER
 M:	Jackie Dong <[email protected]>
 L:	[email protected]
drivers/platform/lenovo/Kconfig +14 -0
index 8222322ca671..ba4248d56e5f 100644
@@ -41,6 +41,20 @@ config LENOVO_WMI_HOTKEY_UTILITIES
 	  such as LED control for audio/mic mute event for Ideapad, YOGA, XiaoXin,
 	  Gaming, ThinkBook and so on.
 
+config LENOVO_WMI_HOTKEYS
+	tristate "Lenovo WMI hotkeys driver"
+	depends on ACPI_WMI
+	depends on INPUT
+	select INPUT_SPARSEKMAP
+	help
+	  Say Y or M here to enable the vendor specific Fn keys (microphone
+	  mute, airplane mode, performance mode, star key) on Lenovo laptops
+	  that deliver them as WMI events and are not handled by the
+	  ideapad-laptop driver, such as the ACPI based arm64 models.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called lenovo-wmi-hotkeys.
+
 config LENOVO_WMI_CAMERA
 	tristate "Lenovo WMI Camera Button driver"
 	depends on ACPI_WMI
drivers/platform/lenovo/Makefile +1 -0
index 1cac115dd735..d3f5e3ac14c2 100644
@@ -8,6 +8,7 @@ lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
 lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
 lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
 lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
+lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEYS)	+= wmi-hotkeys.o
 lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
 lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
 lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
drivers/platform/lenovo/wmi-hotkeys.c new file +151 -0

151 lines not on this page · raw message

Signature · 1 line
2.56.1
#7 lore raw

Re: [RFC PATCH 2/3] platform: lenovo: add WMI hotkeys driver

Am 13.11.26 um 23:27 schrieb David Cemin:

Quoted 126 lines

Lenovo consumer laptops deliver their vendor specific Fn keys (microphone mute, airplane mode, performance mode, the Smart Key and Smart Connect keys) as WMI events on GUID 8FC0DE0C-B4E4-43FD-B0F3-8871711C1294 instead of keyboard usages. On x86, ideapad-laptop consumes these events, but it depends on i8042 and on the IdeaPad VPC ACPI device, neither of which exist on the ACPI based arm64 models. Add a small WMI driver that reports the same key codes through a sparse keymap, so desktops see the generic input events.

The key map follows ideapad-laptop. One code seen on the Yoga 9 2-in-1 16 (arm64) is new: 0x48 for the Smart Connect key.

Both drivers match the same GUID. The probe declines when the IdeaPad VPC device (VPC2004) is present, so machines handled by ideapad-laptop, including its Fn lock LED and DYTC performance mode handling, keep that driver.

---
  MAINTAINERS                           |   6 +
  drivers/platform/lenovo/Kconfig       |  14 +++
  drivers/platform/lenovo/Makefile      |   1 +
  drivers/platform/lenovo/wmi-hotkeys.c | 151 ++++++++++++++++++++++++++
  4 files changed, 172 insertions(+)

create mode 100644 drivers/platform/lenovo/wmi-hotkeys.c

MAINTAINERS +6 -0
index 3b0ad5a3debe..207684aeaf69 100644
@@ -15173,6 +15173,12 @@ F:	Documentation/wmi/devices/lenovo-wmi-other.rst
  F:	drivers/platform/lenovo/
  F:	drivers/platform/x86/lenovo/*
 
+LENOVO WMI HOTKEYS DRIVER
+M:	David Cemin <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/platform/lenovo/wmi-hotkeys.c
+
  LENOVO WMI HOTKEY UTILITIES DRIVER
  M:	Jackie Dong <[email protected]>
  L:	[email protected]
drivers/platform/lenovo/Kconfig +14 -0
index 8222322ca671..ba4248d56e5f 100644
@@ -41,6 +41,20 @@ config LENOVO_WMI_HOTKEY_UTILITIES
  	  such as LED control for audio/mic mute event for Ideapad, YOGA, XiaoXin,
  	  Gaming, ThinkBook and so on.
 
+config LENOVO_WMI_HOTKEYS
+	tristate "Lenovo WMI hotkeys driver"
+	depends on ACPI_WMI
+	depends on INPUT
+	select INPUT_SPARSEKMAP
+	help
+	  Say Y or M here to enable the vendor specific Fn keys (microphone
+	  mute, airplane mode, performance mode, star key) on Lenovo laptops
+	  that deliver them as WMI events and are not handled by the
+	  ideapad-laptop driver, such as the ACPI based arm64 models.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called lenovo-wmi-hotkeys.
+
  config LENOVO_WMI_CAMERA
  	tristate "Lenovo WMI Camera Button driver"
  	depends on ACPI_WMI
drivers/platform/lenovo/Makefile +1 -0
index 1cac115dd735..d3f5e3ac14c2 100644
@@ -8,6 +8,7 @@ lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
  lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
  lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
  lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
+lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEYS)	+= wmi-hotkeys.o
  lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
  lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
  lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
drivers/platform/lenovo/wmi-hotkeys.c new file +40 -0
new file mode 100644
index 000000000000..fc18867d8144
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Lenovo WMI hotkey driver
+ *
+ * Lenovo consumer laptops deliver their vendor specific Fn keys (microphone
+ * mute, airplane mode, performance mode, the star key and others) as WMI
+ * events on GUID 8FC0DE0C-B4E4-43FD-B0F3-8871711C1294 instead of keyboard
+ * usages.  On x86 ideapad-laptop consumes these events; that driver depends
+ * on i8042 and the IdeaPad VPC device, neither of which exist on the arm64
+ * platforms.  This driver consumes the same event and reports the keys the
+ * same way, so desktops see the usual generic key codes.
+ *
+ * The key codes follow the mapping used by ideapad-laptop.
+ */
+
+#include <linux/acpi.h>
+#include <linux/input.h>
+#include <linux/input/sparse-keymap.h>
+#include <linux/module.h>
+#include <linux/wmi.h>
+
+#define LENOVO_FN_KEYS_WMI_GUID	"8FC0DE0C-B4E4-43FD-B0F3-8871711C1294"
+
+static const struct key_entry lenovo_wmi_hotkeys_keymap[] = {
+	/* Customizable Lenovo Hotkey ("star" with 'S' inside) */
+	{ KE_KEY, 0x01, { KEY_FAVORITES } },
+	/* Fn lock toggled on / off, firmware handles the LED */
+	{ KE_IGNORE, 0x02 },
+	{ KE_IGNORE, 0x03 },
+	{ KE_KEY, 0x04, { KEY_SELECTIVE_SCREENSHOT } },
+	/* Lenovo Support */
+	{ KE_KEY, 0x07, { KEY_HELP } },
+	{ KE_KEY, 0x0a, { KEY_REFRESH_RATE_TOGGLE } },
+	{ KE_KEY, 0x0e, { KEY_PICKUP_PHONE } },
+	{ KE_KEY, 0x0f, { KEY_HANGUP_PHONE } },
+	{ KE_KEY, 0x10, { KEY_REFRESH_RATE_TOGGLE } },
+	/* Sound profile switch */
+	{ KE_KEY, 0x12, { KEY_PROG2 } },
+	/* Dark mode toggle */
+	{ KE_KEY, 0x13, { KEY_PROG1 } },

drivers/platform/lenovo/wmi-hotkeys.c line 50

Quoted 10 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +10 -0
+	/* Lenovo Support */
+	{ KE_KEY, 0x27, { KEY_HELP } },
+	/* Lenovo Virtual Background application */
+	{ KE_KEY, 0x28, { KEY_PROG3 } },
+	{ KE_KEY, 0x29, { KEY_TOUCHPAD_TOGGLE } },
+	{ KE_KEY, 0x2a, { KEY_ROOT_MENU } },
+	/* Shift + PrtSc */
+	{ KE_KEY, 0x2d, { KEY_SELECTIVE_SCREENSHOT } },
+	/* Performance mode, Fn+Q */
+	{ KE_KEY, 0x3d, { KEY_PROG4 } },

Hi,

please consider using KEY_PERFORMANCE instead.

Quoted 27 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +27 -0
+	{ KE_KEY, 0x3e, { KEY_MICMUTE } },
+	{ KE_KEY, 0x3f, { KEY_RFKILL } },
+	/*
+	 * Keyboard backlight level after Fn+Space, handled by the firmware:
+	 * 0x40 off, 0x41 low, 0x42 high, 0x43 also seen
+	 */
+	{ KE_IGNORE, 0x40 },
+	{ KE_IGNORE, 0x41 },
+	{ KE_IGNORE, 0x42 },
+	{ KE_IGNORE, 0x43 },
+	/* Star, user assignable key */
+	{ KE_KEY, 0x44, { KEY_PROG1 } },
+	/* Eye care */
+	{ KE_KEY, 0x45, { KEY_PROG3 } },
+	/* Smart Connect, phone to PC link */
+	{ KE_KEY, 0x48, { KEY_PROG2 } },
+	{ KE_END },
+};
+
+struct lenovo_wmi_hotkeys {
+	struct input_dev *input;
+};
+
+static int lenovo_wmi_hotkeys_probe(struct wmi_device *wdev, const void *context)
+{
+	struct lenovo_wmi_hotkeys *priv;
+	int ret;

drivers/platform/lenovo/wmi-hotkeys.c line 87

Quoted 10 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +10 -0
+
+	/*
+	 * ideapad-laptop binds the same GUID and handles these events together
+	 * with the IdeaPad VPC device (Fn lock LED, DYTC performance mode
+	 * cycling).  Leave those machines to it.
+	 */
+	if (acpi_dev_found("VPC2004")) {
+		dev_dbg(&wdev->dev, "IdeaPad VPC present, deferring to ideapad-laptop\n");
+		return -ENODEV;
+	}

Please use a notifier chain to allow the ideapad-laptop driver to consume WMI events. This avoids code duplication and ensures that the WMI event GUIDs are only handled by a single driver.

You can use drivers/platform/x86/uniwill/uniwill-wmi.c as a inspiration, except that in this case the sparse keymap resides in this driver.

drivers/platform/lenovo/wmi-hotkeys.c line 91

Quoted 4 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +4 -0
+
+	priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;

Please use devm_kzalloc_obj() instead.

Quoted 9 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +9 -0
+
+	priv->input = devm_input_allocate_device(&wdev->dev);
+	if (!priv->input)
+		return -ENOMEM;
+
+	priv->input->name = "Lenovo WMI hotkeys";
+	priv->input->phys = "wmi/input0";
+	priv->input->id.bustype = BUS_HOST;
+	priv->input->dev.parent = &wdev->dev;

drivers/platform/lenovo/wmi-hotkeys.c line 110

Quoted 10 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +10 -0
+
+	ret = sparse_keymap_setup(priv->input, lenovo_wmi_hotkeys_keymap, NULL);
+	if (ret)
+		return ret;
+
+	ret = input_register_device(priv->input);
+	if (ret)
+		return ret;
+
+	dev_set_drvdata(&wdev->dev, priv);

Please set drvdata before registering the input device, otherwise a WMI event arriving between input_register_device() and dev_set_drvdata() will cause a kernel panic by dereferencing NULL.

Quoted 13 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +13 -0
+
+	return 0;
+}
+
+static void lenovo_wmi_hotkeys_notify(struct wmi_device *wdev, union acpi_object *data)
+{
+	struct lenovo_wmi_hotkeys *priv = dev_get_drvdata(&wdev->dev);
+	u32 code;
+
+	if (!data || data->type != ACPI_TYPE_INTEGER) {
+		dev_dbg(&wdev->dev, "event data is not an integer\n");
+		return;
+	}

drivers/platform/lenovo/wmi-hotkeys.c line 133

Quoted 10 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +10 -0
+
+	code = data->integer.value;
+	dev_dbg(&wdev->dev, "hotkey event 0x%x\n", code);
+
+	if (!sparse_keymap_report_event(priv->input, code, 1, true))
+		dev_info_ratelimited(&wdev->dev, "unknown hotkey event 0x%x\n", code);
+}
+
+static const struct wmi_device_id lenovo_wmi_hotkeys_id_table[] = {
+	{ LENOVO_FN_KEYS_WMI_GUID, NULL },

What about the GUIDs for handling the Esc keys?

drivers/platform/lenovo/wmi-hotkeys.c line 145

Quoted 12 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +12 -0
+	{ }
+};
+MODULE_DEVICE_TABLE(wmi, lenovo_wmi_hotkeys_id_table);
+
+static struct wmi_driver lenovo_wmi_hotkeys_driver = {
+	.driver = {
+		.name = "lenovo-wmi-hotkeys",
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+	},
+	.id_table = lenovo_wmi_hotkeys_id_table,
+	.probe = lenovo_wmi_hotkeys_probe,
+	.notify = lenovo_wmi_hotkeys_notify,

Please use .notify_new instead. This will also allow you to get rid of any ACPI-related code in this driver. What is the WMI data type of the event payload?

Thanks,
Armin Wolf

Quoted 6 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +6 -0
+	.no_singleton = true,
+};
+module_wmi_driver(lenovo_wmi_hotkeys_driver);
+
+MODULE_DESCRIPTION("Lenovo WMI hotkey driver");
+MODULE_LICENSE("GPL");
#8 lore raw

Re: [RFC PATCH 2/3] platform: lenovo: add WMI hotkeys driver

Hi Armin,

Thanks, all taken for v2: KEY_PERFORMANCE for 0x3D, devm_kzalloc_obj, drvdata set before registering the input device, notify_new, and the events delivered through the lenovo-wmi-events notifier chain with NOTIFY_STOP honoured. The payload is a single integer, the key code, so with notify_new it is a 4 byte little endian value.

On the Esc GUIDs: the arm64 firmware here exposes 8FC0DE0C for the Fn keys but neither 26CAB2E5 nor 56322276, so the new driver claims only the Fn key GUID and the Esc GUIDs stay with ideapad-laptop.

Thanks,
David

#9 lore raw

Re: [RFC PATCH 2/3] platform: lenovo: add WMI hotkeys driver

Am 16.11.26 um 05:42 schrieb David Cemin:

Quoted 8 lines

Hi Armin,

Thanks, all taken for v2: KEY_PERFORMANCE for 0x3D, devm_kzalloc_obj, drvdata set before registering the input device, notify_new, and the events delivered through the lenovo-wmi-events notifier chain with NOTIFY_STOP honoured. The payload is a single integer, the key code, so with notify_new it is a 4 byte little endian value.

Quoted 6 lines

On the Esc GUIDs: the arm64 firmware here exposes 8FC0DE0C for the Fn keys but neither 26CAB2E5 nor 56322276, so the new driver claims only the Fn key GUID and the Esc GUIDs stay with ideapad-laptop.

Thanks,
David

Hi,

i think that we should still move the handling of the Esc GUIDs into the new event driver, so that ideapad-laptop is free from any WMI event drivers.

Thanks,
Armin Wolf

#10 lore raw

Re: [RFC PATCH 2/3] platform: lenovo: add WMI hotkeys driver

In reply to David Cemin

Hi David,

just a quick comment that this:

Quoted 2 lines

The key map follows ideapad-laptop. One code seen on the Yoga 9 2-in-1 16 (arm64) is new: 0x48 for the Smart Connect key.

isn't quite right; the ideapad-laptop driver has covered the smart connect key/event 0x48 since commit ccc8c8481c1f ("platform/x86: ideapad-laptop:
Map Smart Connect hotkey to KEY_LINK_PHONE"), which is in 7.4-rc1+.

drivers/platform/lenovo/wmi-hotkeys.c line 66

Quoted 2 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +2 -0
+	/* Smart Connect, phone to PC link */
+	{ KE_KEY, 0x48, { KEY_PROG2 } },

Similarly to that commit, I would suggest using KEY_LINK_PHONE here instead.

Best regards,
Marco

maintainer
#11 lore raw

Re: [RFC PATCH 2/3] platform: lenovo: add WMI hotkeys driver

In reply to David Cemin
Quoted 265 lines · David Cemin

Lenovo consumer laptops deliver their vendor specific Fn keys (microphone
mute, airplane mode, performance mode, the Smart Key and Smart Connect
keys) as WMI events on GUID 8FC0DE0C-B4E4-43FD-B0F3-8871711C1294 instead
of keyboard usages. On x86, ideapad-laptop consumes these events, but it
depends on i8042 and on the IdeaPad VPC ACPI device, neither of which exist on the ACPI based arm64 models. Add a small WMI driver that reports
the same key codes through a sparse keymap, so desktops see the generic
input events.

The key map follows ideapad-laptop. One code seen on the Yoga 9 2-in- 1
16 (arm64) is new: 0x48 for the Smart Connect key.

Both drivers match the same GUID. The probe declines when the IdeaPad VPC device (VPC2004) is present, so machines handled by ideapad- laptop,
including its Fn lock LED and DYTC performance mode handling, keep that
driver.

---
 MAINTAINERS                           |   6 +
 drivers/platform/lenovo/Kconfig       |  14 +++
 drivers/platform/lenovo/Makefile      |   1 +
 drivers/platform/lenovo/wmi-hotkeys.c | 151
++++++++++++++++++++++++++

 4 files changed, 172 insertions(+)

 create mode 100644 drivers/platform/lenovo/wmi-hotkeys.c

MAINTAINERS +0 -0
index 3b0ad5a3debe..207684aeaf69 100644
@@ -15173,6 +15173,12 @@ F:	Documentation/wmi/devices/lenovo-

wmi-other.rst
 F: drivers/platform/lenovo/
 F: drivers/platform/x86/lenovo/*

MAINTAINERS +6 -0
+LENOVO WMI HOTKEYS DRIVER
+M:	David Cemin <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/platform/lenovo/wmi-hotkeys.c
+

 LENOVO WMI HOTKEY UTILITIES DRIVER
 M: Jackie Dong <[email protected]>
 L: [email protected]

drivers/platform/lenovo/Kconfig +0 -0
index 8222322ca671..ba4248d56e5f 100644
@@ -41,6 +41,20 @@ config LENOVO_WMI_HOTKEY_UTILITIES
  	  such as LED control for audio/mic mute event for Ideapad,
 YOGA, XiaoXin,

    Gaming, ThinkBook and so on.

drivers/platform/lenovo/Kconfig +7 -0
+config LENOVO_WMI_HOTKEYS
+	tristate "Lenovo WMI hotkeys driver"
+	depends on ACPI_WMI
+	depends on INPUT
+	select INPUT_SPARSEKMAP
+	help
+	  Say Y or M here to enable the vendor specific Fn keys

(microphone

drivers/platform/lenovo/Kconfig +1 -0
+	  mute, airplane mode, performance mode, star key) on Lenovo

laptops

drivers/platform/lenovo/Kconfig +2 -0
+	  that deliver them as WMI events and are not handled by the
+	  ideapad-laptop driver, such as the ACPI based arm64

models.

drivers/platform/lenovo/Kconfig +2 -0
+
+	  To compile this driver as a module, choose M here: the

module will

drivers/platform/lenovo/Kconfig +2 -0
+	  be called lenovo-wmi-hotkeys.
+

 config LENOVO_WMI_CAMERA
  tristate "Lenovo WMI Camera Button driver" depends on ACPI_WMI

drivers/platform/lenovo/Makefile +0 -0
index 1cac115dd735..d3f5e3ac14c2 100644
@@ -8,6 +8,7 @@ lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+=

wmi-helpers.o
 lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS) += wmi-events.o
 lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA) += wmi-capdata.o
 lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += wmi-
hotkey-utilities.o
+lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEYS) += wmi-hotkeys.o
 lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA) += wmi-camera.o
 lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE) += wmi-gamezone.o
 lenovo-target-$(CONFIG_LENOVO_WMI_TUNING) += wmi-other.o

drivers/platform/lenovo/wmi-hotkeys.c new file +5 -0
new file mode 100644
index 000000000000..fc18867d8144
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Lenovo WMI hotkey driver
+ *
+ * Lenovo consumer laptops deliver their vendor specific Fn keys

(microphone
+ * mute, airplane mode, performance mode, the star key and others) as WMI
+ * events on GUID 8FC0DE0C-B4E4-43FD-B0F3-8871711C1294 instead of keyboard
+ * usages.  On x86 ideapad-laptop consumes these events; that driver depends
+ * on i8042 and the IdeaPad VPC device, neither of which exist on the arm64
+ * platforms.  This driver consumes the same event and reports the keys the
+ * same way, so desktops see the usual generic key codes.
+ *
+ * The key codes follow the mapping used by ideapad-laptop.
+ */

drivers/platform/lenovo/wmi-hotkeys.c new file +8 -0
+
+#include <linux/acpi.h>
+#include <linux/input.h>
+#include <linux/input/sparse-keymap.h>
+#include <linux/module.h>
+#include <linux/wmi.h>
+
+#define LENOVO_FN_KEYS_WMI_GUID	"8FC0DE0C-B4E4-43FD-B0F3-

8871711C1294"

drivers/platform/lenovo/wmi-hotkeys.c new file +32 -0
+
+static const struct key_entry lenovo_wmi_hotkeys_keymap[] = {
+	/* Customizable Lenovo Hotkey ("star" with 'S' inside) */
+	{ KE_KEY, 0x01, { KEY_FAVORITES } },
+	/* Fn lock toggled on / off, firmware handles the LED */
+	{ KE_IGNORE, 0x02 },
+	{ KE_IGNORE, 0x03 },
+	{ KE_KEY, 0x04, { KEY_SELECTIVE_SCREENSHOT } },
+	/* Lenovo Support */
+	{ KE_KEY, 0x07, { KEY_HELP } },
+	{ KE_KEY, 0x0a, { KEY_REFRESH_RATE_TOGGLE } },
+	{ KE_KEY, 0x0e, { KEY_PICKUP_PHONE } },
+	{ KE_KEY, 0x0f, { KEY_HANGUP_PHONE } },
+	{ KE_KEY, 0x10, { KEY_REFRESH_RATE_TOGGLE } },
+	/* Sound profile switch */
+	{ KE_KEY, 0x12, { KEY_PROG2 } },
+	/* Dark mode toggle */
+	{ KE_KEY, 0x13, { KEY_PROG1 } },
+	/* Lenovo Support */
+	{ KE_KEY, 0x27, { KEY_HELP } },
+	/* Lenovo Virtual Background application */
+	{ KE_KEY, 0x28, { KEY_PROG3 } },
+	{ KE_KEY, 0x29, { KEY_TOUCHPAD_TOGGLE } },
+	{ KE_KEY, 0x2a, { KEY_ROOT_MENU } },
+	/* Shift + PrtSc */
+	{ KE_KEY, 0x2d, { KEY_SELECTIVE_SCREENSHOT } },
+	/* Performance mode, Fn+Q */
+	{ KE_KEY, 0x3d, { KEY_PROG4 } },
+	{ KE_KEY, 0x3e, { KEY_MICMUTE } },
+	{ KE_KEY, 0x3f, { KEY_RFKILL } },
+	/*
+	 * Keyboard backlight level after Fn+Space, handled by the

firmware:

drivers/platform/lenovo/wmi-hotkeys.c new file +20 -0
+	 * 0x40 off, 0x41 low, 0x42 high, 0x43 also seen
+	 */
+	{ KE_IGNORE, 0x40 },
+	{ KE_IGNORE, 0x41 },
+	{ KE_IGNORE, 0x42 },
+	{ KE_IGNORE, 0x43 },
+	/* Star, user assignable key */
+	{ KE_KEY, 0x44, { KEY_PROG1 } },
+	/* Eye care */
+	{ KE_KEY, 0x45, { KEY_PROG3 } },
+	/* Smart Connect, phone to PC link */
+	{ KE_KEY, 0x48, { KEY_PROG2 } },
+	{ KE_END },
+};
+
+struct lenovo_wmi_hotkeys {
+	struct input_dev *input;
+};
+
+static int lenovo_wmi_hotkeys_probe(struct wmi_device *wdev, const

void *context)

drivers/platform/lenovo/wmi-hotkeys.c new file +6 -0
+{
+	struct lenovo_wmi_hotkeys *priv;
+	int ret;
+
+	/*
+	 * ideapad-laptop binds the same GUID and handles these

events together

drivers/platform/lenovo/wmi-hotkeys.c new file +1 -0
+	 * with the IdeaPad VPC device (Fn lock LED, DYTC

performance mode

drivers/platform/lenovo/wmi-hotkeys.c new file +4 -0
+	 * cycling).  Leave those machines to it.
+	 */
+	if (acpi_dev_found("VPC2004")) {
+		dev_dbg(&wdev->dev, "IdeaPad VPC present, deferring

to ideapad-laptop\n");

drivers/platform/lenovo/wmi-hotkeys.c new file +17 -0
+		return -ENODEV;
+	}
+
+	priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->input = devm_input_allocate_device(&wdev->dev);
+	if (!priv->input)
+		return -ENOMEM;
+
+	priv->input->name = "Lenovo WMI hotkeys";
+	priv->input->phys = "wmi/input0";
+	priv->input->id.bustype = BUS_HOST;
+	priv->input->dev.parent = &wdev->dev;
+
+	ret = sparse_keymap_setup(priv->input,

lenovo_wmi_hotkeys_keymap, NULL);

drivers/platform/lenovo/wmi-hotkeys.c new file +13 -0
+	if (ret)
+		return ret;
+
+	ret = input_register_device(priv->input);
+	if (ret)
+		return ret;
+
+	dev_set_drvdata(&wdev->dev, priv);
+
+	return 0;
+}
+
+static void lenovo_wmi_hotkeys_notify(struct wmi_device *wdev, union

acpi_object *data)

drivers/platform/lenovo/wmi-hotkeys.c new file +2 -0
+{
+	struct lenovo_wmi_hotkeys *priv = dev_get_drvdata(&wdev-
Quoted 1 line

dev);

drivers/platform/lenovo/wmi-hotkeys.c new file +4 -0
+	u32 code;
+
+	if (!data || data->type != ACPI_TYPE_INTEGER) {
+		dev_dbg(&wdev->dev, "event data is not an

integer\n");

drivers/platform/lenovo/wmi-hotkeys.c new file +8 -0
+		return;
+	}
+
+	code = data->integer.value;
+	dev_dbg(&wdev->dev, "hotkey event 0x%x\n", code);
+
+	if (!sparse_keymap_report_event(priv->input, code, 1, true))
+		dev_info_ratelimited(&wdev->dev, "unknown hotkey

event 0x%x\n", code);

drivers/platform/lenovo/wmi-hotkeys.c new file +12 -0
+}
+
+static const struct wmi_device_id lenovo_wmi_hotkeys_id_table[] = {
+	{ LENOVO_FN_KEYS_WMI_GUID, NULL },
+	{ }
+};
+MODULE_DEVICE_TABLE(wmi, lenovo_wmi_hotkeys_id_table);
+
+static struct wmi_driver lenovo_wmi_hotkeys_driver = {
+	.driver = {
+		.name = "lenovo-wmi-hotkeys",
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,

drivers/platform/lenovo/wmi-hotkeys.c line 151

Quoted 10 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +10 -0
+	},
+	.id_table = lenovo_wmi_hotkeys_id_table,
+	.probe = lenovo_wmi_hotkeys_probe,
+	.notify = lenovo_wmi_hotkeys_notify,
+	.no_singleton = true,
+};
+module_wmi_driver(lenovo_wmi_hotkeys_driver);
+
+MODULE_DESCRIPTION("Lenovo WMI hotkey driver");
+MODULE_LICENSE("GPL");

Hi David,
This wmi-hotkeys.c is for suspecific Fn keys(microphone mute, airplane mode, performance mode, the star key and others) with WMI and wmi- hotkey-utilities.c is the same target. Now the two file names are similar and easy to confuse for developers and maintainer. Would you merge them into one file?
If yes, developers can support Lenovo product other hotkeys and new functions by wmi in one file in future.
Jackie Dong

#12 lore raw

Re: [RFC PATCH 2/3] platform: lenovo: add WMI hotkeys driver

In reply to David Cemin

Hi Jackie,

Thanks for the review and the Reviewed-by on patch 1.

On merging wmi-hotkeys.c with wmi-hotkey-utilities.c: I kept them separate because they are different interfaces. wmi-hotkey-utilities.c drives the method GUID (microphone mute LED, Fn lock state), while wmi-hotkeys.c owns the event GUIDs and only turns events into input reports; the notifier chain is how the two sides meet, and ideapad-laptop uses it. If the maintainers prefer a single file the merge is mechanical and I am happy to do it in v3; otherwise I would keep the method and event sides apart, as the other Lenovo WMI drivers do.

v2 is out as [email protected] and includes your tag.

Thanks,
David

maintainer
#13 lore raw

Re: [RFC PATCH 2/3] platform: lenovo: add WMI hotkeys driver

Quoted 17 lines · David Cemin

Hi Jackie,

Thanks for the review and the Reviewed-by on patch 1.

On merging wmi-hotkeys.c with wmi-hotkey-utilities.c: I kept them separate because they are different interfaces. wmi-hotkey- utilities.c
drives the method GUID (microphone mute LED, Fn lock state), while wmi-hotkeys.c owns the event GUIDs and only turns events into input reports; the notifier chain is how the two sides meet, and ideapad- laptop
uses it. If the maintainers prefer a single file the merge is mechanical
and I am happy to do it in v3; otherwise I would keep the method and event
sides apart, as the other Lenovo WMI drivers do.

Quoted 5 lines

v2 is out as [email protected] and includes your tag.

Thanks,
David

Hi David,
I agree that wmi-hotkeys.c and wmi-hotkey-utilities.c are different interfaces. But I stick on my point that the two file names are similar and easy to confuse for developers and maintainer. I suggest another file name should be a solution, such as wmi-hotkeys- switches.c, wmi-FnKey-event-report.c, FYR.

Regards,

Jackie

#14 lore raw

RFC PATCH 3/3 platform/x86: ideapad-laptop: do not bind the WMI event devices without the VPC

In reply to David Cemin

ideapad-laptop binds the Fn key and Esc WMI event GUIDs unconditionally, but ideapad_wmi_notify() only acts when the VPC platform driver has probed and set ideapad_shared. On machines that expose the WMI GUIDs without the IdeaPad VPC device (VPC2004) the driver claims the WMI device and then drops every event.

Decline the WMI devices when there is no VPC2004, so the device stays free for a consumer that can report the events, such as the Lenovo WMI hotkeys driver.

---
 drivers/platform/x86/lenovo/ideapad-laptop.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/platform/x86/lenovo/ideapad-laptop.c +8 -0
index 91a8d11c79c5..44ae248c5a4d 100644
@@ -2278,6 +2278,14 @@ static int ideapad_wmi_probe(struct wmi_device *wdev, const void *context)
 {
 	struct ideapad_wmi_private *wpriv;
 
+	/*
+	 * The events are only delivered once the VPC platform driver is bound
+	 * (ideapad_shared).  Without the VPC device this driver can never
+	 * report them, so leave the WMI device to another consumer.
+	 */
+	if (!acpi_dev_found("VPC2004"))
+		return -ENODEV;
+
 	wpriv = devm_kzalloc_obj(&wdev->dev, *wpriv);
 	if (!wpriv)
 		return -ENOMEM;
Signature · 1 line
2.56.1
maintainer
#15 lore raw
In reply to David Cemin

<sorry for any double-send (first reply incomplete) Thunderbird has a new Ctrl+s send
shortcut which I sometimes fat-finger when copy/pasting>

Hi,

Quoted 28 lines · David Cemin

Lenovo now ships ACPI based arm64 laptops whose firmware exposes the same ACPI-WMI interfaces as the x86 IdeaPad and Legion machines: the Fn key event GUID consumed by ideapad-laptop, the hotkey utility GUID used for the microphone mute LED, and the GameZone, Other Mode and capability data GUIDs behind the thermal operation modes. Since 884d53763d30 ("platform/wmi: Remove dependency on CONFIG_X86") the ACPI-WMI core builds on arm64, but the Lenovo WMI drivers still live under drivers/platform/x86, which is gated by X86_PLATFORM_DEVICES, so none of that code can be used where the firmware is.

This series:
1. moves the architecture independent Lenovo WMI drivers into a new drivers/platform/lenovo directory, following drivers/platform/surface which exists for the same reason (Surface ships x86 and arm64); ideapad-laptop, thinkpad_acpi, think-lmi and the Yoga tablet drivers stay under x86 because they need i8042, port I/O or x86 only devices;
2. adds a small WMI hotkeys driver for the Fn key event GUID on machines> where ideapad-laptop cannot bind;
3. makes ideapad-laptop's own WMI event driver decline the GUIDs when the IdeaPad VPC device is absent, since it can never report events there.

Patch 2 was tested on a Lenovo Yoga 9 2-in-1 16 (arm64): microphone mute, airplane mode, the Smart Key, the Smart Connect key and the Fn+Q operation mode key all report input events. The same key set is dead on a Lenovo Yoga Pro 9 (arm64) today and uses the same GUID. Patches 1 and 3 are compile tested on x86_64 and arm64 (defconfig plus all LENOVO_WMI options as modules).

Quoted 6 lines

Two questions I would like the maintainers' view on before this goes further:

a. Is a vendor directory (drivers/platform/lenovo, like surface) the
right home, or should the architecture independent Lenovo WMI drivers move under drivers/platform/wmi next to the core instead?

I think that drivers/platform/lenovo makes sense since eventually we may want more then just WMI drivers, e.g. the thinkpad_acpi driver which actually sort of works on Qualcomm Snapdragon laptops when booting these with my experimental DT-ACPI hybrid mode patches:

https://github.com/jwrdegoede/linux-sunxi/commits/acpi-dt-hybrid-v0.4/

Quoted 4 lines

b. Should the Fn key event handling stay a separate small driver, or
be factored out of ideapad-laptop so x86 and arm64 share one path? ideapad-laptop handles the event only when its VPC platform driver is bound, and the arm64 machines expose none of the VPC interface

Quoted 8 lines

it is built on (no _CFG, VPCR/VPCW, DYTC or HALS/SALS), so making it the single driver means gating most of its probe. Two smaller
options: lift ideapad-laptop's own Fn key wmi_driver and keymap into this file and let ideapad-laptop register for the events it still wants (Fn lock LED, DYTC cycle), or the hid-asus/asus-wmi shape where a companion WMI module exports the event to a subsystem driver. The keymap in patch 2 duplicates entries of ideapad-laptop's table on purpose until that is decided.

IIRC the ideapad-laptop driver is a bit of a mess atm, so factoring a common handling for the the Fn key events out of this and sharing that sounds like a nice cleanup.

I see that patch 2/3 uses the new wmi-driver/-bus infra which is nice and clean.

So maybe just keep your existing stand-alone driver for both x86_64 + arm64 and drop the WMI event handling from ideapad-laptop.

I guess this may hit some problems where WMI event handlig is used in ideapad-laptops integrating with some VPC functionality.

For that purpose I think that the new drivers/platform/lenovo/wmi-hotkeys.c could maybe expose some notifier and call that for events it does not handle itself and then ideapad-laptop can depend on some function to register a listener on that notifier (1) and register a notifier handler staying out of WMI handling itself.

No idea if this is feasible / how clean the end result will be, just brainstorming and saying yes to doing some refactoring of the somewhat messy ideapad-laptop code.

Note that https://github.com/systemd/systemd/blob/main/hwdb.d/60-keyboard.hwdb
has some mappings for "Ideapad extra buttons" input devices
(+ DMI match), so if any of the buttons remapped there end up under the new WMI driver then that should probably give its
input device the same name, to make sure those mappings still apply.

Regards,

Hans

1) +Kconfig dep, which will also avoid regressions by wrong Kconfig

Quoted 51 lines

Patch 2 declines to bind when the IdeaPad VPC device (VPC2004) is present, so machines handled by ideapad-laptop keep it; patch 3 is the mirror on the ideapad-laptop side. The new MAINTAINERS entry uses platform-driver-x86, the list that already covers drivers/platform/arm64, the ACPI-WMI core and the other Lenovo WMI drivers.

David Cemin (3):
platform: lenovo: move the architecture independent WMI drivers out of

    x86

platform: lenovo: add WMI hotkeys driver platform/x86: ideapad-laptop: do not bind the WMI event devices
without the VPC

 MAINTAINERS                                   |   9 +-
 drivers/platform/Kconfig                      |   2 +
 drivers/platform/Makefile                     |   1 +
 drivers/platform/lenovo/Kconfig               | 101 ++++++++++++
 drivers/platform/lenovo/Makefile              |  23 +++
 .../platform/{x86 => }/lenovo/wmi-camera.c    |   0
 .../platform/{x86 => }/lenovo/wmi-capdata.c   |   0
 .../platform/{x86 => }/lenovo/wmi-capdata.h   |   0
 .../platform/{x86 => }/lenovo/wmi-events.c    |   0
 .../platform/{x86 => }/lenovo/wmi-events.h    |   0
 .../platform/{x86 => }/lenovo/wmi-gamezone.c  |   0
 .../platform/{x86 => }/lenovo/wmi-helpers.c   |   0
 .../platform/{x86 => }/lenovo/wmi-helpers.h   |   0
 .../{x86 => }/lenovo/wmi-hotkey-utilities.c   |   0
 drivers/platform/lenovo/wmi-hotkeys.c         | 151 ++++++++++++++++++
 drivers/platform/{x86 => }/lenovo/wmi-other.c |   0
 drivers/platform/x86/lenovo/Kconfig           |  67 --------
 drivers/platform/x86/lenovo/Makefile          |   7 -
 drivers/platform/x86/lenovo/ideapad-laptop.c  |   8 +
 19 files changed, 294 insertions(+), 75 deletions(-)
 create mode 100644 drivers/platform/lenovo/Kconfig
 create mode 100644 drivers/platform/lenovo/Makefile
 rename drivers/platform/{x86 => }/lenovo/wmi-camera.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-gamezone.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-hotkey-utilities.c (100%)
 create mode 100644 drivers/platform/lenovo/wmi-hotkeys.c
 rename drivers/platform/{x86 => }/lenovo/wmi-other.c (100%)

base-commit: 2800868f63227c8237d70c41e70d441c919620d6

#16 lore raw

Am 15.11.26 um 16:33 schrieb Hans de Goede:

Quoted 40 lines

<sorry for any double-send (first reply incomplete) Thunderbird has a new Ctrl+s send
shortcut which I sometimes fat-finger when copy/pasting>

Hi,

Quoted 28 lines · David Cemin

Lenovo now ships ACPI based arm64 laptops whose firmware exposes the same ACPI-WMI interfaces as the x86 IdeaPad and Legion machines: the Fn key event GUID consumed by ideapad-laptop, the hotkey utility GUID used for the microphone mute LED, and the GameZone, Other Mode and capability data GUIDs behind the thermal operation modes. Since 884d53763d30 ("platform/wmi: Remove dependency on CONFIG_X86") the ACPI-WMI core builds on arm64, but the Lenovo WMI drivers still live under drivers/platform/x86, which is gated by X86_PLATFORM_DEVICES, so none of that code can be used where the firmware is.

This series:
1. moves the architecture independent Lenovo WMI drivers into a new drivers/platform/lenovo directory, following drivers/platform/surface which exists for the same reason (Surface ships x86 and arm64); ideapad-laptop, thinkpad_acpi, think-lmi and the Yoga tablet drivers stay under x86 because they need i8042, port I/O or x86 only devices;
2. adds a small WMI hotkeys driver for the Fn key event GUID on machines> where ideapad-laptop cannot bind;
3. makes ideapad-laptop's own WMI event driver decline the GUIDs when the IdeaPad VPC device is absent, since it can never report events there.

Patch 2 was tested on a Lenovo Yoga 9 2-in-1 16 (arm64): microphone mute, airplane mode, the Smart Key, the Smart Connect key and the Fn+Q operation mode key all report input events. The same key set is dead on a Lenovo Yoga Pro 9 (arm64) today and uses the same GUID. Patches 1 and 3 are compile tested on x86_64 and arm64 (defconfig plus all LENOVO_WMI options as modules).

Quoted 6 lines

Two questions I would like the maintainers' view on before this goes further:

a. Is a vendor directory (drivers/platform/lenovo, like surface) the
right home, or should the architecture independent Lenovo WMI drivers move under drivers/platform/wmi next to the core instead?

Quoted 6 lines

I think that drivers/platform/lenovo makes sense since eventually we may want more then just WMI drivers, e.g. the thinkpad_acpi driver which actually sort of works on Qualcomm Snapdragon laptops when booting these with my experimental DT-ACPI hybrid mode patches:

https://github.com/jwrdegoede/linux-sunxi/commits/acpi-dt-hybrid-v0.4/

Agreed, the drivers/platform/wmi directory should only contain core WMI infrastructure code and maybe some generic drivers like wmi-bmof.

Quoted 43 lines
Quoted 4 lines

b. Should the Fn key event handling stay a separate small driver, or
be factored out of ideapad-laptop so x86 and arm64 share one path? ideapad-laptop handles the event only when its VPC platform driver is bound, and the arm64 machines expose none of the VPC interface

Quoted 8 lines

it is built on (no _CFG, VPCR/VPCW, DYTC or HALS/SALS), so making it the single driver means gating most of its probe. Two smaller
options: lift ideapad-laptop's own Fn key wmi_driver and keymap into this file and let ideapad-laptop register for the events it still wants (Fn lock LED, DYTC cycle), or the hid-asus/asus-wmi shape where a companion WMI module exports the event to a subsystem driver. The keymap in patch 2 duplicates entries of ideapad-laptop's table on purpose until that is decided.

IIRC the ideapad-laptop driver is a bit of a mess atm, so factoring a common handling for the the Fn key events out of this and sharing that sounds like a nice cleanup.

I see that patch 2/3 uses the new wmi-driver/-bus infra which is nice and clean.

So maybe just keep your existing stand-alone driver for both x86_64 + arm64 and drop the WMI event handling from ideapad-laptop.

I guess this may hit some problems where WMI event handlig is used in ideapad-laptops integrating with some VPC functionality.

For that purpose I think that the new drivers/platform/lenovo/wmi-hotkeys.c could maybe expose some notifier and call that for events it does not handle itself and then ideapad-laptop can depend on some function to register a listener on that notifier (1) and register a notifier handler staying out of WMI handling itself.

No idea if this is feasible / how clean the end result will be, just brainstorming and saying yes to doing some refactoring of the somewhat messy ideapad-laptop code.

Note that https://github.com/systemd/systemd/blob/main/hwdb.d/60-keyboard.hwdb
has some mappings for "Ideapad extra buttons" input devices
(+ DMI match), so if any of the buttons remapped there end up under the new WMI driver then that should probably give its
input device the same name, to make sure those mappings still apply.

Quoted 3 lines

Regards,

Hans

I like the idea of using a notifier to allow ideapad-laptop to consume WMI events from wmi-hotkeys. This would even allow ideapad-laptop to override the sparse keymap inside wmi-hotkeys by simply returning NOTIFY_STOP when "catching" an WMI event that has to be handled internally (like event 0x3D (Performance Key)). wmi-hotkeys can check for this return value and not emit a key code in such a case.

Thanks,
Armin Wolf

Quoted 54 lines

1) +Kconfig dep, which will also avoid regressions by wrong Kconfig

Quoted 50 lines

Patch 2 declines to bind when the IdeaPad VPC device (VPC2004) is present, so machines handled by ideapad-laptop keep it; patch 3 is the mirror on the ideapad-laptop side. The new MAINTAINERS entry uses platform-driver-x86, the list that already covers drivers/platform/arm64, the ACPI-WMI core and the other Lenovo WMI drivers.

David Cemin (3):
platform: lenovo: move the architecture independent WMI drivers out of

     x86

platform: lenovo: add WMI hotkeys driver platform/x86: ideapad-laptop: do not bind the WMI event devices
without the VPC

  MAINTAINERS                                   |   9 +-
  drivers/platform/Kconfig                      |   2 +
  drivers/platform/Makefile                     |   1 +
  drivers/platform/lenovo/Kconfig               | 101 ++++++++++++
  drivers/platform/lenovo/Makefile              |  23 +++
  .../platform/{x86 => }/lenovo/wmi-camera.c    |   0
  .../platform/{x86 => }/lenovo/wmi-capdata.c   |   0
  .../platform/{x86 => }/lenovo/wmi-capdata.h   |   0
  .../platform/{x86 => }/lenovo/wmi-events.c    |   0
  .../platform/{x86 => }/lenovo/wmi-events.h    |   0
  .../platform/{x86 => }/lenovo/wmi-gamezone.c  |   0
  .../platform/{x86 => }/lenovo/wmi-helpers.c   |   0
  .../platform/{x86 => }/lenovo/wmi-helpers.h   |   0
  .../{x86 => }/lenovo/wmi-hotkey-utilities.c   |   0
  drivers/platform/lenovo/wmi-hotkeys.c         | 151 ++++++++++++++++++
  drivers/platform/{x86 => }/lenovo/wmi-other.c |   0
  drivers/platform/x86/lenovo/Kconfig           |  67 --------
  drivers/platform/x86/lenovo/Makefile          |   7 -
  drivers/platform/x86/lenovo/ideapad-laptop.c  |   8 +
  19 files changed, 294 insertions(+), 75 deletions(-)

create mode 100644 drivers/platform/lenovo/Kconfig
create mode 100644 drivers/platform/lenovo/Makefile
rename drivers/platform/{x86 => }/lenovo/wmi-camera.c (100%) rename drivers/platform/{x86 => }/lenovo/wmi-capdata.c (100%) rename drivers/platform/{x86 => }/lenovo/wmi-capdata.h (100%) rename drivers/platform/{x86 => }/lenovo/wmi-events.c (100%) rename drivers/platform/{x86 => }/lenovo/wmi-events.h (100%) rename drivers/platform/{x86 => }/lenovo/wmi-gamezone.c (100%) rename drivers/platform/{x86 => }/lenovo/wmi-helpers.c (100%) rename drivers/platform/{x86 => }/lenovo/wmi-helpers.h (100%) rename drivers/platform/{x86 => }/lenovo/wmi-hotkey-utilities.c (100%) create mode 100644 drivers/platform/lenovo/wmi-hotkeys.c rename drivers/platform/{x86 => }/lenovo/wmi-other.c (100%)

base-commit: 2800868f63227c8237d70c41e70d441c919620d6

maintainer
#17 lore raw

Hi,

Quoted 97 lines · Armin Wolf

Am 15.11.26 um 16:33 schrieb Hans de Goede:

Quoted 40 lines

<sorry for any double-send (first reply incomplete) Thunderbird has a new Ctrl+s send shortcut which I sometimes fat-finger when copy/pasting>

Hi,

Quoted 28 lines · David Cemin

Lenovo now ships ACPI based arm64 laptops whose firmware exposes the same ACPI-WMI interfaces as the x86 IdeaPad and Legion machines: the Fn key event GUID consumed by ideapad-laptop, the hotkey utility GUID used for the microphone mute LED, and the GameZone, Other Mode and capability data GUIDs behind the thermal operation modes. Since 884d53763d30 ("platform/wmi: Remove dependency on CONFIG_X86") the ACPI-WMI core builds on arm64, but the Lenovo WMI drivers still live under drivers/platform/x86, which is gated by X86_PLATFORM_DEVICES, so none of that code can be used where the firmware is.

This series:
   1. moves the architecture independent Lenovo WMI drivers into a new
      drivers/platform/lenovo directory, following drivers/platform/surface
      which exists for the same reason (Surface ships x86 and arm64);
      ideapad-laptop, thinkpad_acpi, think-lmi and the Yoga tablet drivers
      stay under x86 because they need i8042, port I/O or x86 only devices;
   2. adds a small WMI hotkeys driver for the Fn key event GUID on machines>      where ideapad-laptop cannot bind;
   3. makes ideapad-laptop's own WMI event driver decline the GUIDs when
      the IdeaPad VPC device is absent, since it can never report events
      there.

Patch 2 was tested on a Lenovo Yoga 9 2-in-1 16 (arm64): microphone mute, airplane mode, the Smart Key, the Smart Connect key and the Fn+Q operation mode key all report input events. The same key set is dead on a Lenovo Yoga Pro 9 (arm64) today and uses the same GUID. Patches 1 and 3 are compile tested on x86_64 and arm64 (defconfig plus all LENOVO_WMI options as modules).

Quoted 6 lines

Two questions I would like the maintainers' view on before this goes further:

   a. Is a vendor directory (drivers/platform/lenovo, like surface) the right home, or should the architecture independent Lenovo WMI drivers move under drivers/platform/wmi next to the core instead?

Quoted 6 lines

I think that drivers/platform/lenovo makes sense since eventually we may want more then just WMI drivers, e.g. the thinkpad_acpi driver which actually sort of works on Qualcomm Snapdragon laptops when booting these with my experimental DT-ACPI hybrid mode patches:

https://github.com/jwrdegoede/linux-sunxi/commits/acpi-dt-hybrid-v0.4/

Agreed, the drivers/platform/wmi directory should only contain core WMI infrastructure code and maybe some generic drivers like wmi-bmof.

Quoted 45 lines
Quoted 4 lines

   b. Should the Fn key event handling stay a separate small driver, or be factored out of ideapad-laptop so x86 and arm64 share one path? ideapad-laptop handles the event only when its VPC platform driver is bound, and the arm64 machines expose none of the VPC interface

Quoted 8 lines

      it is built on (no _CFG, VPCR/VPCW, DYTC or HALS/SALS), so making it the single driver means gating most of its probe. Two smaller
      options: lift ideapad-laptop's own Fn key wmi_driver and keymap into this file and let ideapad-laptop register for the events it still wants (Fn lock LED, DYTC cycle), or the hid-asus/asus-wmi shape where a companion WMI module exports the event to a subsystem driver. The keymap in patch 2 duplicates entries of ideapad-laptop's table on purpose until that is decided.

IIRC the ideapad-laptop driver is a bit of a mess atm, so factoring a common handling for the the Fn key events out of this and sharing that sounds like a nice cleanup.

I see that patch 2/3 uses the new wmi-driver/-bus infra which is nice and clean.

So maybe just keep your existing stand-alone driver for both x86_64 + arm64 and drop the WMI event handling from ideapad-laptop.

I guess this may hit some problems where WMI event handlig is used in ideapad-laptops integrating with some VPC functionality.

For that purpose I think that the new drivers/platform/lenovo/wmi-hotkeys.c could maybe expose some notifier and call that for events it does not handle itself and then ideapad-laptop can depend on some function to register a listener on that notifier (1) and register a notifier handler staying out of WMI handling itself.

No idea if this is feasible / how clean the end result will be, just brainstorming and saying yes to doing some refactoring of the somewhat messy ideapad-laptop code.

Note that https://github.com/systemd/systemd/blob/main/hwdb.d/60-keyboard.hwdb
has some mappings for "Ideapad extra buttons" input devices
(+ DMI match), so if any of the buttons remapped there end up under the new WMI driver then that should probably give its
input device the same name, to make sure those mappings still apply.

Regards,

Quoted 7 lines
Quoted 1 line

Hans

I like the idea of using a notifier to allow ideapad-laptop to consume WMI events from wmi-hotkeys. This would even allow ideapad-laptop to override the sparse keymap inside wmi-hotkeys by simply returning NOTIFY_STOP when "catching" an WMI event that has to be handled internally (like event 0x3D (Performance Key)). wmi-hotkeys can check for this return value and not emit a key code in such a case.

Ah yes, I was thinking about only calling the notifier after not finding an entry in the sparse keymap, but calling it before allowing notifier handlers to return NOTIFY_STOP and filter out further processing is a good idea.

Regards,

Hans

maintainer
#18 lore raw
In reply to Hans de Goede

On 15-Nov-26 16:33, Hans de Goede wrote:

<snip>

Quoted 37 lines
Quoted 4 lines

b. Should the Fn key event handling stay a separate small driver, or
be factored out of ideapad-laptop so x86 and arm64 share one path? ideapad-laptop handles the event only when its VPC platform driver is bound, and the arm64 machines expose none of the VPC interface

Quoted 8 lines

it is built on (no _CFG, VPCR/VPCW, DYTC or HALS/SALS), so making it the single driver means gating most of its probe. Two smaller
options: lift ideapad-laptop's own Fn key wmi_driver and keymap into this file and let ideapad-laptop register for the events it still wants (Fn lock LED, DYTC cycle), or the hid-asus/asus-wmi shape where a companion WMI module exports the event to a subsystem driver. The keymap in patch 2 duplicates entries of ideapad-laptop's table on purpose until that is decided.

IIRC the ideapad-laptop driver is a bit of a mess atm, so factoring a common handling for the the Fn key events out of this and sharing that sounds like a nice cleanup.

I see that patch 2/3 uses the new wmi-driver/-bus infra which is nice and clean.

So maybe just keep your existing stand-alone driver for both x86_64 + arm64 and drop the WMI event handling from ideapad-laptop.

I guess this may hit some problems where WMI event handlig is used in ideapad-laptops integrating with some VPC functionality.

For that purpose I think that the new drivers/platform/lenovo/wmi-hotkeys.c could maybe expose some notifier and call that for events it does not handle itself and then ideapad-laptop can depend on some function to register a listener on that notifier (1) and register a notifier handler staying out of WMI handling itself.

No idea if this is feasible / how clean the end result will be, just brainstorming and saying yes to doing some refactoring of the somewhat messy ideapad-laptop code.

Quoted 6 lines

Note that https://github.com/systemd/systemd/blob/main/hwdb.d/60-keyboard.hwdb
has some mappings for "Ideapad extra buttons" input devices
(+ DMI match), so if any of the buttons remapped there end up under the new WMI driver then that should probably give its
input device the same name, to make sure those mappings still apply.

Also see this just posted ideapad-laptop series which does something similar for handling YMC events:

https://lore.kernel.org/platform-driver-x86/[email protected]/

Regards,

Hans

Quoted 2 lines

1) +Kconfig dep, which will also avoid regressions by wrong Kconfig

maintainer
#19 lore raw

p.s.

Quoted 48 lines · Hans de Goede

On 15-Nov-26 16:33, Hans de Goede wrote:

<snip>

Quoted 37 lines
Quoted 4 lines

b. Should the Fn key event handling stay a separate small driver, or
be factored out of ideapad-laptop so x86 and arm64 share one path? ideapad-laptop handles the event only when its VPC platform driver is bound, and the arm64 machines expose none of the VPC interface

Quoted 8 lines

it is built on (no _CFG, VPCR/VPCW, DYTC or HALS/SALS), so making it the single driver means gating most of its probe. Two smaller
options: lift ideapad-laptop's own Fn key wmi_driver and keymap into this file and let ideapad-laptop register for the events it still wants (Fn lock LED, DYTC cycle), or the hid-asus/asus-wmi shape where a companion WMI module exports the event to a subsystem driver. The keymap in patch 2 duplicates entries of ideapad-laptop's table on purpose until that is decided.

IIRC the ideapad-laptop driver is a bit of a mess atm, so factoring a common handling for the the Fn key events out of this and sharing that sounds like a nice cleanup.

I see that patch 2/3 uses the new wmi-driver/-bus infra which is nice and clean.

So maybe just keep your existing stand-alone driver for both x86_64 + arm64 and drop the WMI event handling from ideapad-laptop.

I guess this may hit some problems where WMI event handlig is used in ideapad-laptops integrating with some VPC functionality.

For that purpose I think that the new drivers/platform/lenovo/wmi-hotkeys.c could maybe expose some notifier and call that for events it does not handle itself and then ideapad-laptop can depend on some function to register a listener on that notifier (1) and register a notifier handler staying out of WMI handling itself.

No idea if this is feasible / how clean the end result will be, just brainstorming and saying yes to doing some refactoring of the somewhat messy ideapad-laptop code.

Quoted 6 lines

Note that https://github.com/systemd/systemd/blob/main/hwdb.d/60-keyboard.hwdb
has some mappings for "Ideapad extra buttons" input devices
(+ DMI match), so if any of the buttons remapped there end up under the new WMI driver then that should probably give its
input device the same name, to make sure those mappings still apply.

Quoted 4 lines

Also see this just posted ideapad-laptop series which does something similar for handling YMC events:

https://lore.kernel.org/platform-driver-x86/[email protected]/

I see that this routes everything through a new lenovo wmi-events helper which uses a single notifier to which interested parties like ideapad-laptop can subscribe. I think this models could be extended to also handle the hotkeys, assuming all the base bits are moved into the new drivers/platform/lenovo/ dir.

Regards,

Hans

maintainer
#20 lore raw
Quoted 54 lines · Hans de Goede

p.s.

Quoted 51 lines · Hans de Goede

On 15-Nov-26 16:33, Hans de Goede wrote:

<snip>

Quoted 37 lines
Quoted 4 lines

b. Should the Fn key event handling stay a separate small driver, or
be factored out of ideapad-laptop so x86 and arm64 share one path? ideapad-laptop handles the event only when its VPC platform driver is bound, and the arm64 machines expose none of the VPC interface

Quoted 8 lines

it is built on (no _CFG, VPCR/VPCW, DYTC or HALS/SALS), so making it the single driver means gating most of its probe. Two smaller
options: lift ideapad-laptop's own Fn key wmi_driver and keymap into this file and let ideapad-laptop register for the events it still wants (Fn lock LED, DYTC cycle), or the hid-asus/asus-wmi shape where a companion WMI module exports the event to a subsystem driver. The keymap in patch 2 duplicates entries of ideapad-laptop's table on purpose until that is decided.

IIRC the ideapad-laptop driver is a bit of a mess atm, so factoring a common handling for the the Fn key events out of this and sharing that sounds like a nice cleanup.

I see that patch 2/3 uses the new wmi-driver/-bus infra which is nice and clean.

So maybe just keep your existing stand-alone driver for both x86_64 + arm64 and drop the WMI event handling from ideapad-laptop.

I guess this may hit some problems where WMI event handlig is used in ideapad-laptops integrating with some VPC functionality.

For that purpose I think that the new drivers/platform/lenovo/wmi-hotkeys.c could maybe expose some notifier and call that for events it does not handle itself and then ideapad-laptop can depend on some function to register a listener on that notifier (1) and register a notifier handler staying out of WMI handling itself.

No idea if this is feasible / how clean the end result will be, just brainstorming and saying yes to doing some refactoring of the somewhat messy ideapad-laptop code.

Quoted 6 lines

Note that https://github.com/systemd/systemd/blob/main/hwdb.d/60-keyboard.hwdb
has some mappings for "Ideapad extra buttons" input devices
(+ DMI match), so if any of the buttons remapped there end up under the new WMI driver then that should probably give its
input device the same name, to make sure those mappings still apply.

Also see this just posted ideapad-laptop series which does something similar for handling YMC events:

Quoted 8 lines
Quoted 1 line

https://lore.kernel.org/platform-driver-x86/[email protected]/

I see that this routes everything through a new lenovo wmi-events helper which uses a single notifier to which interested parties like ideapad-laptop can subscribe. I think this models could be extended to also handle the hotkeys, assuming all the base bits are moved into the new drivers/platform/lenovo/ dir.

This all sounds good to me. I would quite like to break thinkpad_apci up a bit ultimately too....just tough finding the time.

The think-lmi driver should likely move here (and a newer version tlmi-* that I should be posting for review next week, fingers crossed).

Mark

#21 lore raw
In reply to Hans de Goede

Hi Hans,

Thanks, agreed on all points. For v2 I will keep wmi-hotkeys as the single driver for the Fn key GUID on both architectures, route its events through the lenovo-wmi-events notifier so ideapad-laptop subscribes instead of binding the GUIDs itself, call the chain before the keymap lookup so NOTIFY_STOP suppresses the key, and keep the input device name compatible with the hwdb entries. I will look at Rong Zhang's series and base on it or coordinate so we do not collide. The ideapad-laptop side I can only compile test, I have no x86 IdeaPad here, so I will ask for testers with v2.

Thanks,
David

#22 lore raw

v2 cover platform: lenovo: architecture independent home for the Lenovo WMI drivers

In reply to David Cemin

Lenovo now ships ACPI based arm64 laptops whose firmware exposes the same ACPI-WMI interfaces as the x86 IdeaPad and Legion machines: the Fn key event GUID consumed by ideapad-laptop, the hotkey utility GUID used for the microphone mute LED, and the GameZone, Other Mode and capability data GUIDs behind the thermal operation modes. Since 884d53763d30 ("platform/wmi: Remove dependency on CONFIG_X86") the ACPI-WMI core builds on arm64, but the Lenovo WMI drivers still live under drivers/platform/x86, which is gated by X86_PLATFORM_DEVICES.

This series:
1. moves the architecture independent Lenovo WMI drivers into a new

     drivers/platform/lenovo directory, following drivers/platform/surface;
     ideapad-laptop, thinkpad_acpi, think-lmi and the Yoga tablet drivers
     stay under x86 because they need i8042, port I/O or x86 only devices;

2. adds a WMI hotkeys driver that owns the Fn key and Fn+Esc event GUIDs on every architecture, reports the keys through a sparse keymap and offers a notifier chain to drivers with platform knowledge;
3. makes ideapad-laptop drop its WMI event driver and subscribe to that notifier instead, keeping its Fn lock LED and DYTC performance mode handling.

The series applies on top of Rong Zhang's "platform/x86: ideapad-laptop:
Trigger the EC on YMC events" ([email protected]) because both touch the ideapad-laptop WMI code and that series modernizes the lenovo-wmi-events helper.

Patch 2 was tested on a Lenovo Yoga 9 2-in-1 16 (arm64): microphone mute, airplane mode, the Smart Key, the Smart Connect key and the Fn+Q performance key report input events. The Fn+Esc GUIDs are not exposed by that firmware. Patch 3 is compile tested on x86_64 only, I do not have an x86 IdeaPad; a test on a Yoga 3 or Yoga 700 (Fn+Esc) and on a machine where ideapad-laptop handles the Fn lock LED or DYTC would be appreciated.

Changes in v2:
- dropped the WMI core Kconfig patch, 884d53763d30 covers it (Armin)
- wmi-hotkeys: notify_new with the wmi_buffer, devm_kzalloc_obj, drvdata

    set before input registration, KEY_PERFORMANCE for 0x3d (Armin)

- wmi-hotkeys: notifier chain called before the keymap lookup, NOTIFY_STOP suppresses the key (Hans, Armin); input device named like the ideapad-laptop one so the hwdb mappings keep applying (Hans)
- wmi-hotkeys: camera lens cover switch events moved here with the rest of the Fn key GUID handling
- the VPC guard patch is replaced by ideapad-laptop subscribing to the notifier and dropping its own Fn key WMI driver and keymap entries
- wmi-hotkeys: the Fn+Esc event GUIDs move here as well, so that ideapad-laptop registers no WMI event driver at all (Armin); they carry no data and are reported under code 128 as before
- commit message: 0x48 (Smart Connect) was already KEY_LINK_PHONE in ideapad-laptop since ccc8c8481c1f, the keymap follows it (Marco Giunta)
- collected Mark's and Jackie's Reviewed-by on patch 1

David Cemin (3):
platform: lenovo: move the architecture independent WMI drivers out of

    x86

platform: lenovo: add WMI hotkeys driver
platform/x86: ideapad-laptop: consume the Fn key events from the WMI
hotkeys driver

 MAINTAINERS                                   |  10 +-
 drivers/platform/Kconfig                      |   2 +
 drivers/platform/Makefile                     |   1 +
 drivers/platform/lenovo/Kconfig               | 101 ++++++++
 drivers/platform/lenovo/Makefile              |  23 ++
 .../platform/{x86 => }/lenovo/wmi-camera.c    |   0
 .../platform/{x86 => }/lenovo/wmi-capdata.c   |   0
 .../platform/{x86 => }/lenovo/wmi-capdata.h   |   0
 .../platform/{x86 => }/lenovo/wmi-events.c    |   0
 .../platform/{x86 => }/lenovo/wmi-events.h    |   0
 .../platform/{x86 => }/lenovo/wmi-gamezone.c  |   0
 .../platform/{x86 => }/lenovo/wmi-helpers.c   |   0
 .../platform/{x86 => }/lenovo/wmi-helpers.h   |   0
 .../{x86 => }/lenovo/wmi-hotkey-utilities.c   |   0
 drivers/platform/lenovo/wmi-hotkeys.c         | 244 ++++++++++++++++++
 drivers/platform/{x86 => }/lenovo/wmi-other.c |   0
 drivers/platform/x86/lenovo/Kconfig           |  68 +----
 drivers/platform/x86/lenovo/Makefile          |   7 -
 drivers/platform/x86/lenovo/ideapad-laptop.c  | 225 +++-------------
 .../platform_data/x86/lenovo-wmi-hotkeys.h    |  28 ++
 20 files changed, 447 insertions(+), 262 deletions(-)
 create mode 100644 drivers/platform/lenovo/Kconfig
 create mode 100644 drivers/platform/lenovo/Makefile
 rename drivers/platform/{x86 => }/lenovo/wmi-camera.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-gamezone.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-hotkey-utilities.c (100%)
 create mode 100644 drivers/platform/lenovo/wmi-hotkeys.c
 rename drivers/platform/{x86 => }/lenovo/wmi-other.c (100%)
 create mode 100644 include/linux/platform_data/x86/lenovo-wmi-hotkeys.h
Signature · 1 line
2.56.1
#23 lore raw

PATCH v2 1/3 platform: lenovo: move the architecture independent WMI drivers out of x86

The Lenovo WMI drivers (events, helpers, capability data, GameZone, Other Mode, hotkey utilities and camera button) contain no x86 specific
code: they talk to firmware through the ACPI-WMI core only. They live under drivers/platform/x86 because that is where Lenovo drivers were collected, and X86_PLATFORM_DEVICES keeps them off every other architecture.

Lenovo now ships ACPI based arm64 laptops whose firmware exposes the same WMI GUIDs (the Fn key events, the mic mute LED method, GameZone and Other Mode). Give these drivers an architecture independent home, drivers/platform/lenovo, following the layout of drivers/platform/surface which exists for the same reason, so they can be built wherever the WMI core is available. ideapad-laptop, thinkpad_acpi, think-lmi, yogabook and the Yoga Tablet drivers stay under x86: they depend on i8042, port I/O or x86 only ACPI devices.

Pure code motion: the files, their Kconfig entries and the module naming scheme are unchanged. MAINTAINERS entries are updated for the new paths.

---
 MAINTAINERS                                   |  3 +-
 drivers/platform/Kconfig                      |  2 +
 drivers/platform/Makefile                     |  1 +
 drivers/platform/lenovo/Kconfig               | 87 +++++++++++++++++++
 drivers/platform/lenovo/Makefile              | 22 +++++
 .../platform/{x86 => }/lenovo/wmi-camera.c    |  0
 .../platform/{x86 => }/lenovo/wmi-capdata.c   |  0
 .../platform/{x86 => }/lenovo/wmi-capdata.h   |  0
 .../platform/{x86 => }/lenovo/wmi-events.c    |  0
 .../platform/{x86 => }/lenovo/wmi-events.h    |  0
 .../platform/{x86 => }/lenovo/wmi-gamezone.c  |  0
 .../platform/{x86 => }/lenovo/wmi-helpers.c   |  0
 .../platform/{x86 => }/lenovo/wmi-helpers.h   |  0
 .../{x86 => }/lenovo/wmi-hotkey-utilities.c   |  0
 drivers/platform/{x86 => }/lenovo/wmi-other.c |  0
 drivers/platform/x86/lenovo/Kconfig           | 67 --------------
 drivers/platform/x86/lenovo/Makefile          |  7 --
 17 files changed, 114 insertions(+), 75 deletions(-)
 create mode 100644 drivers/platform/lenovo/Kconfig
 create mode 100644 drivers/platform/lenovo/Makefile
 rename drivers/platform/{x86 => }/lenovo/wmi-camera.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-gamezone.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-hotkey-utilities.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-other.c (100%)
MAINTAINERS +2 -1
index 056408bc086e..3b0ad5a3debe 100644
@@ -15170,13 +15170,14 @@ L:	[email protected]
 S:	Maintained
 F:	Documentation/wmi/devices/lenovo-wmi-gamezone.rst
 F:	Documentation/wmi/devices/lenovo-wmi-other.rst
+F:	drivers/platform/lenovo/
 F:	drivers/platform/x86/lenovo/*
 
 LENOVO WMI HOTKEY UTILITIES DRIVER
 M:	Jackie Dong <[email protected]>
 L:	[email protected]
 S:	Maintained
-F:	drivers/platform/x86/lenovo/wmi-hotkey-utilities.c
+F:	drivers/platform/lenovo/wmi-hotkey-utilities.c
 
 LENOVO HID drivers
 M:	Derek J. Clark <[email protected]>
drivers/platform/Kconfig +2 -0
index 312788f249c9..80b2b83b69e5 100644
@@ -15,6 +15,8 @@ source "drivers/platform/olpc/Kconfig"
 
 source "drivers/platform/surface/Kconfig"
 
+source "drivers/platform/lenovo/Kconfig"
+
 source "drivers/platform/x86/Kconfig"
 
 source "drivers/platform/arm64/Kconfig"
drivers/platform/Makefile +1 -0
index fa322e7f8716..0144f88ff6db 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_GOLDFISH)		+= goldfish/
 obj-$(CONFIG_CHROME_PLATFORMS)	+= chrome/
 obj-$(CONFIG_CZNIC_PLATFORMS)	+= cznic/
 obj-$(CONFIG_SURFACE_PLATFORMS)	+= surface/
+obj-$(CONFIG_LENOVO_PLATFORMS)	+= lenovo/
 obj-$(CONFIG_ARM64_PLATFORM_DEVICES)	+= arm64/
 obj-$(CONFIG_BCM2835_VCHIQ)	+= raspberrypi/
 obj-$(CONFIG_ACPI_WMI)		+= wmi/
drivers/platform/lenovo/Kconfig new file +87 -0

87 lines not on this page · raw message

drivers/platform/lenovo/Makefile new file +22 -0
new file mode 100644
index 000000000000..1cac115dd735
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for linux/drivers/platform/lenovo
+# Lenovo Platform Specific Drivers (architecture independent)
+#
+
+lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
+lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
+lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
+lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
+lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
+lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
+lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
+
+# Add 'lenovo' prefix to each module listed in lenovo-target-*
+define LENOVO_OBJ_TARGET
+lenovo-$(1)-y := $(1).o
+obj-$(2) += lenovo-$(1).o
+endef
+
+$(foreach target, $(basename $(lenovo-target-y)), $(eval $(call LENOVO_OBJ_TARGET,$(target),y)))
+$(foreach target, $(basename $(lenovo-target-m)), $(eval $(call LENOVO_OBJ_TARGET,$(target),m)))
drivers/platform/lenovo/wmi-camera.c renamed from drivers/platform/x86/lenovo/wmi-camera.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-camera.c
rename to drivers/platform/lenovo/wmi-camera.c
drivers/platform/lenovo/wmi-capdata.c renamed from drivers/platform/x86/lenovo/wmi-capdata.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-capdata.c
rename to drivers/platform/lenovo/wmi-capdata.c
drivers/platform/lenovo/wmi-capdata.h renamed from drivers/platform/x86/lenovo/wmi-capdata.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-capdata.h
rename to drivers/platform/lenovo/wmi-capdata.h
drivers/platform/lenovo/wmi-events.c renamed from drivers/platform/x86/lenovo/wmi-events.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-events.c
rename to drivers/platform/lenovo/wmi-events.c
drivers/platform/lenovo/wmi-events.h renamed from drivers/platform/x86/lenovo/wmi-events.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-events.h
rename to drivers/platform/lenovo/wmi-events.h
drivers/platform/lenovo/wmi-gamezone.c renamed from drivers/platform/x86/lenovo/wmi-gamezone.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-gamezone.c
rename to drivers/platform/lenovo/wmi-gamezone.c
drivers/platform/lenovo/wmi-helpers.c renamed from drivers/platform/x86/lenovo/wmi-helpers.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-helpers.c
rename to drivers/platform/lenovo/wmi-helpers.c
drivers/platform/lenovo/wmi-helpers.h renamed from drivers/platform/x86/lenovo/wmi-helpers.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-helpers.h
rename to drivers/platform/lenovo/wmi-helpers.h
drivers/platform/lenovo/wmi-hotkey-utilities.c renamed from drivers/platform/x86/lenovo/wmi-hotkey-utilities.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-hotkey-utilities.c
rename to drivers/platform/lenovo/wmi-hotkey-utilities.c
drivers/platform/lenovo/wmi-other.c renamed from drivers/platform/x86/lenovo/wmi-other.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-other.c
rename to drivers/platform/lenovo/wmi-other.c
drivers/platform/x86/lenovo/Kconfig +0 -67

76 lines not on this page · raw message

drivers/platform/x86/lenovo/Makefile +0 -7
index 12816d8d5e24..758c36cedee8 100644
@@ -7,17 +7,10 @@ obj-$(CONFIG_IDEAPAD_LAPTOP)	+= ideapad-laptop.o
 obj-$(CONFIG_THINKPAD_LMI)	+= think-lmi.o
 obj-$(CONFIG_THINKPAD_ACPI)	+= thinkpad_acpi.o
 
-lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
 lenovo-target-$(CONFIG_LENOVO_YB9_KBDOCK)	+= yb9-kbdock.o
 lenovo-target-$(CONFIG_LENOVO_YMC)	+= ymc.o
 lenovo-target-$(CONFIG_YOGABOOK)	+= yogabook.o
 lenovo-target-$(CONFIG_YT2_1380)	+= yoga-tab2-pro-1380-fastcharger.o
-lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
-lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
-lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
-lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
-lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
-lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
 
 # Add 'lenovo' prefix to each module listed in lenovo-target-*
 define LENOVO_OBJ_TARGET
Signature · 1 line
2.56.1
Reviewed-by on v2 1/3
#24 lore raw

Re: [PATCH v2 1/3] platform: lenovo: move the architecture independent WMI drivers out of x86

Hi David,

Thanks for working on this.

Quoted 16 lines · David Cemin

The Lenovo WMI drivers (events, helpers, capability data, GameZone, Other Mode, hotkey utilities and camera button) contain no x86 specific
code: they talk to firmware through the ACPI-WMI core only. They live under drivers/platform/x86 because that is where Lenovo drivers were collected, and X86_PLATFORM_DEVICES keeps them off every other architecture.

Lenovo now ships ACPI based arm64 laptops whose firmware exposes the same WMI GUIDs (the Fn key events, the mic mute LED method, GameZone and Other Mode). Give these drivers an architecture independent home, drivers/platform/lenovo, following the layout of drivers/platform/surface which exists for the same reason, so they can be built wherever the WMI core is available. ideapad-laptop, thinkpad_acpi, think-lmi, yogabook and the Yoga Tablet drivers stay under x86: they depend on i8042, port I/O or x86 only ACPI devices.

Quoted 6 lines

Pure code motion: the files, their Kconfig entries and the module naming scheme are unchanged. MAINTAINERS entries are updated for the new paths.

Thanks,
Rong

Quoted 342 lines
---
 MAINTAINERS                                   |  3 +-
 drivers/platform/Kconfig                      |  2 +
 drivers/platform/Makefile                     |  1 +
 drivers/platform/lenovo/Kconfig               | 87 +++++++++++++++++++
 drivers/platform/lenovo/Makefile              | 22 +++++
 .../platform/{x86 => }/lenovo/wmi-camera.c    |  0
 .../platform/{x86 => }/lenovo/wmi-capdata.c   |  0
 .../platform/{x86 => }/lenovo/wmi-capdata.h   |  0
 .../platform/{x86 => }/lenovo/wmi-events.c    |  0
 .../platform/{x86 => }/lenovo/wmi-events.h    |  0
 .../platform/{x86 => }/lenovo/wmi-gamezone.c  |  0
 .../platform/{x86 => }/lenovo/wmi-helpers.c   |  0
 .../platform/{x86 => }/lenovo/wmi-helpers.h   |  0
 .../{x86 => }/lenovo/wmi-hotkey-utilities.c   |  0
 drivers/platform/{x86 => }/lenovo/wmi-other.c |  0
 drivers/platform/x86/lenovo/Kconfig           | 67 --------------
 drivers/platform/x86/lenovo/Makefile          |  7 --
 17 files changed, 114 insertions(+), 75 deletions(-)
 create mode 100644 drivers/platform/lenovo/Kconfig
 create mode 100644 drivers/platform/lenovo/Makefile
 rename drivers/platform/{x86 => }/lenovo/wmi-camera.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-gamezone.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-hotkey-utilities.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-other.c (100%)
MAINTAINERS +2 -1
index 056408bc086e..3b0ad5a3debe 100644
@@ -15170,13 +15170,14 @@ L:	[email protected]
 S:	Maintained
 F:	Documentation/wmi/devices/lenovo-wmi-gamezone.rst
 F:	Documentation/wmi/devices/lenovo-wmi-other.rst
+F:	drivers/platform/lenovo/
 F:	drivers/platform/x86/lenovo/*
 
 LENOVO WMI HOTKEY UTILITIES DRIVER
 M:	Jackie Dong <[email protected]>
 L:	[email protected]
 S:	Maintained
-F:	drivers/platform/x86/lenovo/wmi-hotkey-utilities.c
+F:	drivers/platform/lenovo/wmi-hotkey-utilities.c
 
 LENOVO HID drivers
 M:	Derek J. Clark <[email protected]>
drivers/platform/Kconfig +2 -0
index 312788f249c9..80b2b83b69e5 100644
@@ -15,6 +15,8 @@ source "drivers/platform/olpc/Kconfig"
 
 source "drivers/platform/surface/Kconfig"
 
+source "drivers/platform/lenovo/Kconfig"
+
 source "drivers/platform/x86/Kconfig"
 
 source "drivers/platform/arm64/Kconfig"
drivers/platform/Makefile +1 -0
index fa322e7f8716..0144f88ff6db 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_GOLDFISH)		+= goldfish/
 obj-$(CONFIG_CHROME_PLATFORMS)	+= chrome/
 obj-$(CONFIG_CZNIC_PLATFORMS)	+= cznic/
 obj-$(CONFIG_SURFACE_PLATFORMS)	+= surface/
+obj-$(CONFIG_LENOVO_PLATFORMS)	+= lenovo/
 obj-$(CONFIG_ARM64_PLATFORM_DEVICES)	+= arm64/
 obj-$(CONFIG_BCM2835_VCHIQ)	+= raspberrypi/
 obj-$(CONFIG_ACPI_WMI)		+= wmi/
drivers/platform/lenovo/Kconfig new file +87 -0
new file mode 100644
index 000000000000..8222322ca671
@@ -0,0 +1,87 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Lenovo Platform-Specific Drivers
+#
+
+menuconfig LENOVO_PLATFORMS
+	bool "Lenovo Platform-Specific Device Drivers"
+	depends on ARM64 || X86 || COMPILE_TEST
+	default y if ARM64 || X86
+	help
+	  Say Y here to get to see options for platform-specific device drivers
+	  for Lenovo devices that do not depend on the CPU architecture, such
+	  as the ACPI-WMI based drivers used on both x86 and arm64 laptops.
+	  This option alone does not add any kernel code.
+
+	  If you say N, all options in this submenu will be skipped and disabled.
+
+if LENOVO_PLATFORMS
+
+config LENOVO_WMI_HELPERS
+	tristate
+	depends on ACPI_WMI
+
+config LENOVO_WMI_EVENTS
+	tristate
+	depends on ACPI_WMI
+
+config LENOVO_WMI_CAPDATA
+	tristate
+	depends on ACPI_WMI
+	depends on LENOVO_WMI_HELPERS
+
+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_WMI_CAMERA
+	tristate "Lenovo WMI Camera Button driver"
+	depends on ACPI_WMI
+	depends on INPUT
+	help
+	  This driver provides support for Lenovo camera button. The Camera
+	  button is a GPIO device. This driver receives ACPI notifications when
+	  the camera button is switched on/off.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called lenovo-wmi-camera.
+
+config LENOVO_WMI_GAMEZONE
+	tristate "Lenovo GameZone WMI Driver"
+	depends on ACPI_WMI
+	depends on DMI
+	select ACPI_PLATFORM_PROFILE
+	select LENOVO_WMI_EVENTS
+	select LENOVO_WMI_HELPERS
+	help
+	  Say Y here if you have a WMI aware Lenovo Legion device and would like to use the
+	  platform-profile firmware interface to manage power usage.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called lenovo-wmi-gamezone.
+
+config LENOVO_WMI_TUNING
+	tristate "Lenovo Other Mode WMI Driver"
+	depends on ACPI_WMI
+	depends on ACPI_BATTERY
+	select HWMON
+	select FW_ATTR_CLASS
+	select LENOVO_WMI_CAPDATA
+	select LENOVO_WMI_EVENTS
+	select LENOVO_WMI_HELPERS
+	help
+	  Say Y here if you have a WMI aware Lenovo Legion device and would like to use the
+	  firmware_attributes API to control various tunable settings typically exposed by
+	  Lenovo software in Windows.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called lenovo-wmi-other.
+
+endif # LENOVO_PLATFORMS
drivers/platform/lenovo/Makefile new file +22 -0
new file mode 100644
index 000000000000..1cac115dd735
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for linux/drivers/platform/lenovo
+# Lenovo Platform Specific Drivers (architecture independent)
+#
+
+lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
+lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
+lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
+lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
+lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
+lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
+lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
+
+# Add 'lenovo' prefix to each module listed in lenovo-target-*
+define LENOVO_OBJ_TARGET
+lenovo-$(1)-y := $(1).o
+obj-$(2) += lenovo-$(1).o
+endef
+
+$(foreach target, $(basename $(lenovo-target-y)), $(eval $(call LENOVO_OBJ_TARGET,$(target),y)))
+$(foreach target, $(basename $(lenovo-target-m)), $(eval $(call LENOVO_OBJ_TARGET,$(target),m)))
drivers/platform/lenovo/wmi-camera.c renamed from drivers/platform/x86/lenovo/wmi-camera.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-camera.c
rename to drivers/platform/lenovo/wmi-camera.c
drivers/platform/lenovo/wmi-capdata.c renamed from drivers/platform/x86/lenovo/wmi-capdata.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-capdata.c
rename to drivers/platform/lenovo/wmi-capdata.c
drivers/platform/lenovo/wmi-capdata.h renamed from drivers/platform/x86/lenovo/wmi-capdata.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-capdata.h
rename to drivers/platform/lenovo/wmi-capdata.h
drivers/platform/lenovo/wmi-events.c renamed from drivers/platform/x86/lenovo/wmi-events.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-events.c
rename to drivers/platform/lenovo/wmi-events.c
drivers/platform/lenovo/wmi-events.h renamed from drivers/platform/x86/lenovo/wmi-events.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-events.h
rename to drivers/platform/lenovo/wmi-events.h
drivers/platform/lenovo/wmi-gamezone.c renamed from drivers/platform/x86/lenovo/wmi-gamezone.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-gamezone.c
rename to drivers/platform/lenovo/wmi-gamezone.c
drivers/platform/lenovo/wmi-helpers.c renamed from drivers/platform/x86/lenovo/wmi-helpers.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-helpers.c
rename to drivers/platform/lenovo/wmi-helpers.c
drivers/platform/lenovo/wmi-helpers.h renamed from drivers/platform/x86/lenovo/wmi-helpers.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-helpers.h
rename to drivers/platform/lenovo/wmi-helpers.h
drivers/platform/lenovo/wmi-hotkey-utilities.c renamed from drivers/platform/x86/lenovo/wmi-hotkey-utilities.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-hotkey-utilities.c
rename to drivers/platform/lenovo/wmi-hotkey-utilities.c
drivers/platform/lenovo/wmi-other.c renamed from drivers/platform/x86/lenovo/wmi-other.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-other.c
rename to drivers/platform/lenovo/wmi-other.c
drivers/platform/x86/lenovo/Kconfig +0 -67
index f16b09bab082..4d9a25d0e3b5 100644
@@ -20,29 +20,6 @@ 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_WMI_CAMERA
-	tristate "Lenovo WMI Camera Button driver"
-	depends on ACPI_WMI
-	depends on INPUT
-	help
-	  This driver provides support for Lenovo camera button. The Camera
-	  button is a GPIO device. This driver receives ACPI notifications when
-	  the camera button is switched on/off.
-
-	  To compile this driver as a module, choose M here: the module
-	  will be called lenovo-wmi-camera.
-
 config LENOVO_YB9_KBDOCK
 	tristate "Lenovo Yoga Book 9 keyboard dock detection"
 	depends on ACPI_WMI
@@ -248,47 +225,3 @@ config YT2_1380
 
 	  To compile this driver as a module, choose M here: the module will
 	  be called lenovo-yogabook.
-
-config LENOVO_WMI_CAPDATA
-	tristate
-	depends on ACPI_WMI
-	depends on LENOVO_WMI_HELPERS
-
-config LENOVO_WMI_EVENTS
-	tristate
-	depends on ACPI_WMI
-
-config LENOVO_WMI_HELPERS
-	tristate
-	depends on ACPI_WMI
-
-config LENOVO_WMI_GAMEZONE
-	tristate "Lenovo GameZone WMI Driver"
-	depends on ACPI_WMI
-	depends on DMI
-	select ACPI_PLATFORM_PROFILE
-	select LENOVO_WMI_EVENTS
-	select LENOVO_WMI_HELPERS
-	help
-	  Say Y here if you have a WMI aware Lenovo Legion device and would like to use the
-	  platform-profile firmware interface to manage power usage.
-
-	  To compile this driver as a module, choose M here: the module will
-	  be called lenovo-wmi-gamezone.
-
-config LENOVO_WMI_TUNING
-	tristate "Lenovo Other Mode WMI Driver"
-	depends on ACPI_WMI
-	depends on ACPI_BATTERY
-	select HWMON
-	select FW_ATTR_CLASS
-	select LENOVO_WMI_CAPDATA
-	select LENOVO_WMI_EVENTS
-	select LENOVO_WMI_HELPERS
-	help
-	  Say Y here if you have a WMI aware Lenovo Legion device and would like to use the
-	  firmware_attributes API to control various tunable settings typically exposed by
-	  Lenovo software in Windows.
-
-	  To compile this driver as a module, choose M here: the module will
-	  be called lenovo-wmi-other.
drivers/platform/x86/lenovo/Makefile +0 -7
index 12816d8d5e24..758c36cedee8 100644
@@ -7,17 +7,10 @@ obj-$(CONFIG_IDEAPAD_LAPTOP)	+= ideapad-laptop.o
 obj-$(CONFIG_THINKPAD_LMI)	+= think-lmi.o
 obj-$(CONFIG_THINKPAD_ACPI)	+= thinkpad_acpi.o
 
-lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
 lenovo-target-$(CONFIG_LENOVO_YB9_KBDOCK)	+= yb9-kbdock.o
 lenovo-target-$(CONFIG_LENOVO_YMC)	+= ymc.o
 lenovo-target-$(CONFIG_YOGABOOK)	+= yogabook.o
 lenovo-target-$(CONFIG_YT2_1380)	+= yoga-tab2-pro-1380-fastcharger.o
-lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
-lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
-lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
-lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
-lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
-lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
 
 # Add 'lenovo' prefix to each module listed in lenovo-target-*
 define LENOVO_OBJ_TARGET
#25 lore raw

PATCH v2 2/3 platform: lenovo: add WMI hotkeys driver

In reply to David Cemin

Lenovo consumer laptops deliver their vendor specific Fn keys (microphone mute, airplane mode, performance mode, the Smart Key, Smart Connect and others) as WMI events on GUID 8FC0DE0C-B4E4-43FD-B0F3-8871711C1294 instead of keyboard usages, and the Yoga 3 and Yoga 700 generations report Fn+Esc on two dedicated event GUIDs that carry no data. On x86 ideapad-laptop consumes these events together with the IdeaPad VPC device; that driver depends on i8042 and the VPC, neither of which exist on the ACPI based arm64 models, so the keys do nothing there.

Add a small WMI driver that owns these event GUIDs on every architecture and reports the keys through a sparse keymap, using the key codes ideapad-laptop has used for them, including code 128 for the Fn+Esc events. The input device keeps the ideapad-laptop name so that the existing hwdb mappings for these keys continue to apply.

Drivers with platform knowledge can subscribe to a notifier chain that is called with the event code before the key is reported; a subscriber that handles the event itself returns NOTIFY_STOP and no key is reported. ideapad-laptop uses this for the Fn lock LED and the performance mode button, which cycles the platform profile instead of producing a key.

The camera lens cover switch (events 0x0c and 0x0d) is reported as SW_CAMERA_LENS_COVER, as ideapad-laptop does today.

Tested on a Lenovo Yoga 9 2-in-1 16 (arm64): microphone mute, airplane mode, the Smart Key, the Smart Connect key and the Fn+Q performance key report input events. The Esc event GUIDs are not exposed by that firmware, so that path is compile tested only.

---
 MAINTAINERS                                   |   7 +
 drivers/platform/lenovo/Kconfig               |  14 +
 drivers/platform/lenovo/Makefile              |   1 +
 drivers/platform/lenovo/wmi-hotkeys.c         | 244 ++++++++++++++++++
 .../platform_data/x86/lenovo-wmi-hotkeys.h    |  28 ++
 5 files changed, 294 insertions(+)
 create mode 100644 drivers/platform/lenovo/wmi-hotkeys.c
 create mode 100644 include/linux/platform_data/x86/lenovo-wmi-hotkeys.h
MAINTAINERS +7 -0
index 3b0ad5a3debe..1d5b08c033b1 100644
@@ -15173,6 +15173,13 @@ F:	Documentation/wmi/devices/lenovo-wmi-other.rst
 F:	drivers/platform/lenovo/
 F:	drivers/platform/x86/lenovo/*
 
+LENOVO WMI HOTKEYS DRIVER
+M:	David Cemin <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/platform/lenovo/wmi-hotkeys.c
+F:	include/linux/platform_data/x86/lenovo-wmi-hotkeys.h
+
 LENOVO WMI HOTKEY UTILITIES DRIVER
 M:	Jackie Dong <[email protected]>
 L:	[email protected]
drivers/platform/lenovo/Kconfig +14 -0
index 8222322ca671..2810c995ee8c 100644
@@ -41,6 +41,20 @@ config LENOVO_WMI_HOTKEY_UTILITIES
 	  such as LED control for audio/mic mute event for Ideapad, YOGA, XiaoXin,
 	  Gaming, ThinkBook and so on.
 
+config LENOVO_WMI_HOTKEYS
+	tristate "Lenovo WMI hotkeys driver"
+	depends on ACPI_WMI
+	depends on INPUT
+	select INPUT_SPARSEKMAP
+	help
+	  Say Y or M here to enable the vendor specific Fn keys (microphone
+	  mute, airplane mode, performance mode, star key, Fn+Esc) on Lenovo
+	  laptops that deliver them as WMI events. ideapad-laptop subscribes
+	  to this driver for its Fn lock LED and performance mode handling.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called lenovo-wmi-hotkeys.
+
 config LENOVO_WMI_CAMERA
 	tristate "Lenovo WMI Camera Button driver"
 	depends on ACPI_WMI
drivers/platform/lenovo/Makefile +1 -0
index 1cac115dd735..d3f5e3ac14c2 100644
@@ -8,6 +8,7 @@ lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
 lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
 lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
 lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
+lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEYS)	+= wmi-hotkeys.o
 lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
 lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
 lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
drivers/platform/lenovo/wmi-hotkeys.c new file +244 -0

244 lines not on this page · raw message

include/linux/platform_data/x86/lenovo-wmi-hotkeys.h new file +28 -0
new file mode 100644
index 000000000000..cf07eb00f3bb
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Lenovo WMI hotkeys driver, notifier interface for drivers that want to act
+ * on the vendor specific Fn key events before a key is reported.
+ */
+
+#ifndef _LENOVO_WMI_HOTKEYS_H_
+#define _LENOVO_WMI_HOTKEYS_H_
+
+struct device;
+struct notifier_block;
+
+/* Code reported for the Fn+Esc event GUIDs, as ideapad-laptop always did */
+#define LENOVO_WMI_HOTKEYS_ESC_CODE	128
+
+/*
+ * Notifier callbacks receive the WMI event code as the action and no data:
+ * the Fn key code from the Fn key event GUID, or LENOVO_WMI_HOTKEYS_ESC_CODE
+ * for the Fn+Esc event GUIDs, which carry none. A callback that handles the
+ * event itself returns NOTIFY_STOP to suppress the input report; NOTIFY_OK or
+ * NOTIFY_DONE let it through.
+ */
+int lenovo_wmi_hotkeys_register_notifier(struct notifier_block *nb);
+int lenovo_wmi_hotkeys_unregister_notifier(struct notifier_block *nb);
+int devm_lenovo_wmi_hotkeys_register_notifier(struct device *dev,
+					      struct notifier_block *nb);
+
+#endif /* _LENOVO_WMI_HOTKEYS_H_ */
Signature · 1 line
2.56.1
Reviewed-by on v2 2/3
#26 lore raw

Re: [PATCH v2 2/3] platform: lenovo: add WMI hotkeys driver

Am 19.11.26 um 03:27 schrieb David Cemin:

Quoted 22 lines

Lenovo consumer laptops deliver their vendor specific Fn keys (microphone mute, airplane mode, performance mode, the Smart Key, Smart Connect and others) as WMI events on GUID 8FC0DE0C-B4E4-43FD-B0F3-8871711C1294 instead of keyboard usages, and the Yoga 3 and Yoga 700 generations report Fn+Esc on two dedicated event GUIDs that carry no data. On x86 ideapad-laptop consumes these events together with the IdeaPad VPC device; that driver depends on i8042 and the VPC, neither of which exist on the ACPI based arm64 models, so the keys do nothing there.

Add a small WMI driver that owns these event GUIDs on every architecture and reports the keys through a sparse keymap, using the key codes ideapad-laptop has used for them, including code 128 for the Fn+Esc events. The input device keeps the ideapad-laptop name so that the existing hwdb mappings for these keys continue to apply.

Drivers with platform knowledge can subscribe to a notifier chain that is called with the event code before the key is reported; a subscriber that handles the event itself returns NOTIFY_STOP and no key is reported. ideapad-laptop uses this for the Fn lock LED and the performance mode button, which cycles the platform profile instead of producing a key.

Quoted 7 lines

The camera lens cover switch (events 0x0c and 0x0d) is reported as SW_CAMERA_LENS_COVER, as ideapad-laptop does today.

Tested on a Lenovo Yoga 9 2-in-1 16 (arm64): microphone mute, airplane mode, the Smart Key, the Smart Connect key and the Fn+Q performance key report input events. The Esc event GUIDs are not exposed by that firmware, so that path is compile tested only.

Quoted 350 lines
---
  MAINTAINERS                                   |   7 +
  drivers/platform/lenovo/Kconfig               |  14 +
  drivers/platform/lenovo/Makefile              |   1 +
  drivers/platform/lenovo/wmi-hotkeys.c         | 244 ++++++++++++++++++
  .../platform_data/x86/lenovo-wmi-hotkeys.h    |  28 ++
  5 files changed, 294 insertions(+)

create mode 100644 drivers/platform/lenovo/wmi-hotkeys.c create mode 100644 include/linux/platform_data/x86/lenovo-wmi-hotkeys.h

MAINTAINERS +7 -0
index 3b0ad5a3debe..1d5b08c033b1 100644
@@ -15173,6 +15173,13 @@ F:	Documentation/wmi/devices/lenovo-wmi-other.rst
  F:	drivers/platform/lenovo/
  F:	drivers/platform/x86/lenovo/*
 
+LENOVO WMI HOTKEYS DRIVER
+M:	David Cemin <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/platform/lenovo/wmi-hotkeys.c
+F:	include/linux/platform_data/x86/lenovo-wmi-hotkeys.h
+
  LENOVO WMI HOTKEY UTILITIES DRIVER
  M:	Jackie Dong <[email protected]>
  L:	[email protected]
drivers/platform/lenovo/Kconfig +14 -0
index 8222322ca671..2810c995ee8c 100644
@@ -41,6 +41,20 @@ config LENOVO_WMI_HOTKEY_UTILITIES
  	  such as LED control for audio/mic mute event for Ideapad, YOGA, XiaoXin,
  	  Gaming, ThinkBook and so on.
 
+config LENOVO_WMI_HOTKEYS
+	tristate "Lenovo WMI hotkeys driver"
+	depends on ACPI_WMI
+	depends on INPUT
+	select INPUT_SPARSEKMAP
+	help
+	  Say Y or M here to enable the vendor specific Fn keys (microphone
+	  mute, airplane mode, performance mode, star key, Fn+Esc) on Lenovo
+	  laptops that deliver them as WMI events. ideapad-laptop subscribes
+	  to this driver for its Fn lock LED and performance mode handling.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called lenovo-wmi-hotkeys.
+
  config LENOVO_WMI_CAMERA
  	tristate "Lenovo WMI Camera Button driver"
  	depends on ACPI_WMI
drivers/platform/lenovo/Makefile +1 -0
index 1cac115dd735..d3f5e3ac14c2 100644
@@ -8,6 +8,7 @@ lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
  lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
  lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
  lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
+lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEYS)	+= wmi-hotkeys.o
  lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
  lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
  lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
drivers/platform/lenovo/wmi-hotkeys.c new file +243 -0
new file mode 100644
index 000000000000..f412652e9f72
@@ -0,0 +1,244 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Lenovo WMI hotkeys driver
+ *
+ * Lenovo consumer laptops deliver their vendor specific Fn keys (microphone
+ * mute, airplane mode, performance mode, the star key and others) as WMI
+ * events on GUID 8FC0DE0C-B4E4-43FD-B0F3-8871711C1294 instead of keyboard
+ * usages, and the older Yoga models report Fn+Esc on two dedicated event
+ * GUIDs that carry no data. This driver owns these event GUIDs on every
+ * architecture and reports the keys through a sparse keymap. Drivers with
+ * platform knowledge, such as ideapad-laptop, subscribe to the notifier chain
+ * to act on an event and may stop the key from being reported.
+ *
+ * The key codes follow the mapping historically used by ideapad-laptop.
+ */
+
+#include <linux/device.h>
+#include <linux/export.h>
+#include <linux/input.h>
+#include <linux/input/sparse-keymap.h>
+#include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/platform_data/x86/lenovo-wmi-hotkeys.h>
+#include <linux/types.h>
+#include <linux/wmi.h>
+
+#include <asm/byteorder.h>
+
+#define LENOVO_FN_KEYS_WMI_GUID	"8FC0DE0C-B4E4-43FD-B0F3-8871711C1294"
+/* Fn+Esc on the Yoga 3 and Yoga 700 generations, no event data */
+#define LENOVO_ESC_WMI_GUID_YOGA3	"26CAB2E5-5CF1-46AE-AAC3-4A12B6BA50E6"
+#define LENOVO_ESC_WMI_GUID_YOGA700	"56322276-8493-4CE8-A783-98C991274F5E"
+
+/*
+ * The Esc event GUIDs carry no key code; they are reported under
+ * LENOVO_WMI_HOTKEYS_ESC_CODE, the code ideapad-laptop has always used for
+ * them, so the existing hwdb mappings keep applying. The Fn key GUID codes
+ * are all below 0x80.
+ */
+
+enum lenovo_wmi_hotkeys_type {
+	LENOVO_WMI_HOTKEYS_FN_KEYS,
+	LENOVO_WMI_HOTKEYS_ESC,
+};
+
+static const enum lenovo_wmi_hotkeys_type lenovo_wmi_hotkeys_fn_keys = LENOVO_WMI_HOTKEYS_FN_KEYS;
+static const enum lenovo_wmi_hotkeys_type lenovo_wmi_hotkeys_esc = LENOVO_WMI_HOTKEYS_ESC;
+
+static BLOCKING_NOTIFIER_HEAD(lenovo_wmi_hotkeys_chain);
+
+static const struct key_entry lenovo_wmi_hotkeys_keymap[] = {
+	/* Fn+Esc from the Esc event GUIDs */
+	{ KE_KEY, LENOVO_WMI_HOTKEYS_ESC_CODE, { KEY_ESC } },
+	/* Customizable Lenovo Hotkey ("star" with 'S' inside) */
+	{ KE_KEY, 0x01, { KEY_FAVORITES } },
+	/* Fn lock toggled on / off, handled by the firmware */
+	{ KE_IGNORE, 0x02 },
+	/* Esc, handled by the firmware */
+	{ KE_IGNORE, 0x03 },
+	{ KE_KEY, 0x04, { KEY_SELECTIVE_SCREENSHOT } },
+	/* Lenovo Support */
+	{ KE_KEY, 0x07, { KEY_HELP } },
+	/* Refresh Rate Toggle */
+	{ KE_KEY, 0x0a, { KEY_REFRESH_RATE_TOGGLE } },
+	/* Camera lens cover closed / opened */
+	{ KE_SW, 0x0c, .sw = { SW_CAMERA_LENS_COVER, 0 } },
+	{ KE_SW, 0x0d, .sw = { SW_CAMERA_LENS_COVER, 1 } },
+	{ KE_KEY, 0x0e, { KEY_PICKUP_PHONE } },
+	{ KE_KEY, 0x0f, { KEY_HANGUP_PHONE } },
+	/* Refresh Rate Toggle (Fn+R) */
+	{ KE_KEY, 0x10, { KEY_REFRESH_RATE_TOGGLE } },
+	/* Sound profile switch */
+	{ KE_KEY, 0x12, { KEY_PROG2 } },
+	/* Dark mode toggle */
+	{ KE_KEY, 0x13, { KEY_PROG1 } },
+	/* Lenovo Support */
+	{ KE_KEY, 0x27, { KEY_HELP } },
+	/* Lenovo Virtual Background application */
+	{ KE_KEY, 0x28, { KEY_PROG3 } },
+	{ KE_KEY, 0x29, { KEY_TOUCHPAD_TOGGLE } },
+	{ KE_KEY, 0x2a, { KEY_ROOT_MENU } },
+	/* Shift + PrtSc */
+	{ KE_KEY, 0x2d, { KEY_SELECTIVE_SCREENSHOT } },
+	/* Performance mode toggle, Fn+Q */
+	{ KE_KEY, 0x3d, { KEY_PERFORMANCE } },
+	{ KE_KEY, 0x3e, { KEY_MICMUTE } },
+	{ KE_KEY, 0x3f, { KEY_RFKILL } },
+	/*
+	 * Keyboard backlight level after Fn+Space, handled by the firmware:
+	 * 0x40 off, 0x41 low, 0x42 high, 0x43 also seen
+	 */
+	{ KE_IGNORE, 0x40 },
+	{ KE_IGNORE, 0x41 },
+	{ KE_IGNORE, 0x42 },
+	{ KE_IGNORE, 0x43 },
+	/* Star, user assignable key */
+	{ KE_KEY, 0x44, { KEY_PROG1 } },
+	/* Eye care */
+	{ KE_KEY, 0x45, { KEY_PROG3 } },
+	/* Mode, opens a profile chooser; the Fn+Q button cycles the profile */
+	{ KE_KEY, 0x46, { KEY_PROG4 } },
+	/* Lenovo Smart Connect */
+	{ KE_KEY, 0x48, { KEY_LINK_PHONE } },
+	{ KE_END },
+};
+
+struct lenovo_wmi_hotkeys {
+	struct input_dev *input;
+	enum lenovo_wmi_hotkeys_type type;
+};
+
+/**
+ * lenovo_wmi_hotkeys_register_notifier() - Subscribe to the hotkey events.
+ * @nb: The notifier_block to register.
+ *
+ * The callback runs in process context with the WMI event code as the
+ * action. Return NOTIFY_STOP from the callback to consume the event.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int lenovo_wmi_hotkeys_register_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_register(&lenovo_wmi_hotkeys_chain, nb);
+}
+EXPORT_SYMBOL_NS_GPL(lenovo_wmi_hotkeys_register_notifier, "LENOVO_WMI_HOTKEYS");
+
+/**
+ * lenovo_wmi_hotkeys_unregister_notifier() - Unsubscribe from the hotkey events.
+ * @nb: The notifier_block to unregister.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int lenovo_wmi_hotkeys_unregister_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_unregister(&lenovo_wmi_hotkeys_chain, nb);
+}
+EXPORT_SYMBOL_NS_GPL(lenovo_wmi_hotkeys_unregister_notifier, "LENOVO_WMI_HOTKEYS");
 
+static void devm_lenovo_wmi_hotkeys_unregister_notifier(void *data)
+{
+	lenovo_wmi_hotkeys_unregister_notifier(data);
+}
+
+/**
+ * devm_lenovo_wmi_hotkeys_register_notifier() - Device managed subscription.
+ * @dev: The device whose lifetime bounds the subscription.
+ * @nb: The notifier_block to register.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int devm_lenovo_wmi_hotkeys_register_notifier(struct device *dev,
+					      struct notifier_block *nb)
+{
+	int ret;
+
+	ret = lenovo_wmi_hotkeys_register_notifier(nb);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, devm_lenovo_wmi_hotkeys_unregister_notifier, nb);
+}
+EXPORT_SYMBOL_NS_GPL(devm_lenovo_wmi_hotkeys_register_notifier, "LENOVO_WMI_HOTKEYS");
+
+static int lenovo_wmi_hotkeys_probe(struct wmi_device *wdev, const void *context)
+{
+	struct lenovo_wmi_hotkeys *priv;
+	int ret;
+
+	priv = devm_kzalloc_obj(&wdev->dev, *priv);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->type = *(const enum lenovo_wmi_hotkeys_type *)context;
+
+	priv->input = devm_input_allocate_device(&wdev->dev);
+	if (!priv->input)
+		return -ENOMEM;
+
+	/*
+	 * Same name as the ideapad-laptop input device so that the existing
+	 * hwdb keyboard mappings for these keys keep applying.
+	 */
+	priv->input->name = "Ideapad extra buttons";
+	priv->input->phys = priv->type == LENOVO_WMI_HOTKEYS_ESC ? "wmi/input1" : "wmi/input0";
+	priv->input->id.bustype = BUS_HOST;
+	priv->input->dev.parent = &wdev->dev;
+
+	ret = sparse_keymap_setup(priv->input, lenovo_wmi_hotkeys_keymap, NULL);
+	if (ret)
+		return ret;
+
+	dev_set_drvdata(&wdev->dev, priv);
+
+	return input_register_device(priv->input);
+}
+
+static void lenovo_wmi_hotkeys_notify(struct wmi_device *wdev, const struct wmi_buffer *buf)
+{
+	struct lenovo_wmi_hotkeys *priv = dev_get_drvdata(&wdev->dev);
+	u32 code;
+	int ret;
+
+	if (priv->type == LENOVO_WMI_HOTKEYS_ESC) {
+		code = LENOVO_WMI_HOTKEYS_ESC_CODE;
+	} else {
+		if (buf->length < sizeof(u32)) {
+			dev_dbg(&wdev->dev, "short hotkey event (%zu bytes)\n", buf->length);
+			return;
+		}
+		code = le32_to_cpup(buf->data);
+	}
+
+	dev_dbg(&wdev->dev, "hotkey event 0x%x\n", code);
+
+	ret = blocking_notifier_call_chain(&lenovo_wmi_hotkeys_chain, code, NULL);
+	if (ret & NOTIFY_STOP_MASK)
+		return;
+
+	if (!sparse_keymap_report_event(priv->input, code, 1, true))
+		dev_info_ratelimited(&wdev->dev, "unknown hotkey event 0x%x\n", code);
+}
+
+static const struct wmi_device_id lenovo_wmi_hotkeys_id_table[] = {
+	{ LENOVO_FN_KEYS_WMI_GUID, &lenovo_wmi_hotkeys_fn_keys },
+	{ LENOVO_ESC_WMI_GUID_YOGA3, &lenovo_wmi_hotkeys_esc },
+	{ LENOVO_ESC_WMI_GUID_YOGA700, &lenovo_wmi_hotkeys_esc },
+	{ }
+};
+MODULE_DEVICE_TABLE(wmi, lenovo_wmi_hotkeys_id_table);
+
+static struct wmi_driver lenovo_wmi_hotkeys_driver = {
+	.driver = {
+		.name = "lenovo-wmi-hotkeys",
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+	},
+	.id_table = lenovo_wmi_hotkeys_id_table,
+	.probe = lenovo_wmi_hotkeys_probe,
+	.notify_new = lenovo_wmi_hotkeys_notify,
+	.no_singleton = true,
+};
+module_wmi_driver(lenovo_wmi_hotkeys_driver);
+
+MODULE_DESCRIPTION("Lenovo WMI hotkeys driver");
+MODULE_LICENSE("GPL");
include/linux/platform_data/x86/lenovo-wmi-hotkeys.h new file +28 -0
new file mode 100644
index 000000000000..cf07eb00f3bb
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Lenovo WMI hotkeys driver, notifier interface for drivers that want to act
+ * on the vendor specific Fn key events before a key is reported.
+ */
+
+#ifndef _LENOVO_WMI_HOTKEYS_H_
+#define _LENOVO_WMI_HOTKEYS_H_
+
+struct device;
+struct notifier_block;
+
+/* Code reported for the Fn+Esc event GUIDs, as ideapad-laptop always did */
+#define LENOVO_WMI_HOTKEYS_ESC_CODE	128
+
+/*
+ * Notifier callbacks receive the WMI event code as the action and no data:
+ * the Fn key code from the Fn key event GUID, or LENOVO_WMI_HOTKEYS_ESC_CODE
+ * for the Fn+Esc event GUIDs, which carry none. A callback that handles the
+ * event itself returns NOTIFY_STOP to suppress the input report; NOTIFY_OK or
+ * NOTIFY_DONE let it through.
+ */
+int lenovo_wmi_hotkeys_register_notifier(struct notifier_block *nb);
+int lenovo_wmi_hotkeys_unregister_notifier(struct notifier_block *nb);
+int devm_lenovo_wmi_hotkeys_register_notifier(struct device *dev,
+					      struct notifier_block *nb);
+
+#endif /* _LENOVO_WMI_HOTKEYS_H_ */
#27 lore raw

Re: [PATCH v2 2/3] platform: lenovo: add WMI hotkeys driver

In reply to David Cemin

Hi David,

Thanks for working on this.

Quoted 22 lines · David Cemin

Lenovo consumer laptops deliver their vendor specific Fn keys (microphone mute, airplane mode, performance mode, the Smart Key, Smart Connect and others) as WMI events on GUID 8FC0DE0C-B4E4-43FD-B0F3-8871711C1294 instead of keyboard usages, and the Yoga 3 and Yoga 700 generations report Fn+Esc on two dedicated event GUIDs that carry no data. On x86 ideapad-laptop consumes these events together with the IdeaPad VPC device; that driver depends on i8042 and the VPC, neither of which exist on the ACPI based arm64 models, so the keys do nothing there.

Add a small WMI driver that owns these event GUIDs on every architecture and reports the keys through a sparse keymap, using the key codes ideapad-laptop has used for them, including code 128 for the Fn+Esc events. The input device keeps the ideapad-laptop name so that the existing hwdb mappings for these keys continue to apply.

Drivers with platform knowledge can subscribe to a notifier chain that is called with the event code before the key is reported; a subscriber that handles the event itself returns NOTIFY_STOP and no key is reported. ideapad-laptop uses this for the Fn lock LED and the performance mode button, which cycles the platform profile instead of producing a key.

Quoted 7 lines

The camera lens cover switch (events 0x0c and 0x0d) is reported as SW_CAMERA_LENS_COVER, as ideapad-laptop does today.

Tested on a Lenovo Yoga 9 2-in-1 16 (arm64): microphone mute, airplane mode, the Smart Key, the Smart Connect key and the Fn+Q performance key report input events. The Esc event GUIDs are not exposed by that firmware, so that path is compile tested only.

Overall, I like the methodology of factoring out the WMI hotkeys driver from ideapad-laptop, though I still have some comments on the implementation.

Quoted 11 lines
---
 MAINTAINERS                                   |   7 +
 drivers/platform/lenovo/Kconfig               |  14 +
 drivers/platform/lenovo/Makefile              |   1 +
 drivers/platform/lenovo/wmi-hotkeys.c         | 244 ++++++++++++++++++
 .../platform_data/x86/lenovo-wmi-hotkeys.h    |  28 ++
 5 files changed, 294 insertions(+)
 create mode 100644 drivers/platform/lenovo/wmi-hotkeys.c
 create mode 100644 include/linux/platform_data/x86/lenovo-wmi-hotkeys.h

Please merge PATCH 2 and 3 into a monolithic patch, as they are mostly code movement and refactoring. Otherwise, applying PATCH 2 without PATCH 3 allows both drivers to contend for the same WMI devices IIUC.

Quoted 6 lines
MAINTAINERS +0 -0
index 3b0ad5a3debe..1d5b08c033b1 100644

MAINTAINERS F: Documentation/wmi/devices/lenovo-wmi-other.rst · line 15181

Quoted 9 lines
MAINTAINERS +6 -0
@@ -15173,6 +15173,13 @@ F:	Documentation/wmi/devices/lenovo-wmi-other.rst
 F:	drivers/platform/lenovo/
 F:	drivers/platform/x86/lenovo/*
 
+LENOVO WMI HOTKEYS DRIVER
+M:	David Cemin <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/platform/lenovo/wmi-hotkeys.c
+F:	include/linux/platform_data/x86/lenovo-wmi-hotkeys.h

The driver is mostly factored out from ideapad-laptop, so I am not sure if this driver should belong to IDEAPAD LAPTOP EXTRAS DRIVER. Besides, ideapad-laptop is still he most important in-kernel user of the new driver.

I don't have a strong preference, so I will defer the question to others.

Meanwhile, I am glad to co-maintain the driver if you decided to keep a dedicated MAINTAINERS entry. My daily device has the WMI hotkeys device and I have the experience of working on both the ACPI and WMI parts of ideapad-laptop.

Quoted 11 lines
MAINTAINERS +1 -0
+
 LENOVO WMI HOTKEY UTILITIES DRIVER
 M:	Jackie Dong <[email protected]>
 L:	[email protected]
drivers/platform/lenovo/Kconfig +0 -0
index 8222322ca671..2810c995ee8c 100644
@@ -41,6 +41,20 @@ config LENOVO_WMI_HOTKEY_UTILITIES
 	  such as LED control for audio/mic mute event for Ideapad, YOGA, XiaoXin,
 	  Gaming, ThinkBook and so on.

drivers/platform/lenovo/Kconfig config LENOVO_WMI_HOTKEY_UTILITIES · line 52

Quoted 10 lines
drivers/platform/lenovo/Kconfig +8 -0
 
+config LENOVO_WMI_HOTKEYS
+	tristate "Lenovo WMI hotkeys driver"
+	depends on ACPI_WMI
+	depends on INPUT
+	select INPUT_SPARSEKMAP
+	help
+	  Say Y or M here to enable the vendor specific Fn keys (microphone
+	  mute, airplane mode, performance mode, star key, Fn+Esc
 

, etc

Quoted 32 lines

) on Lenovo

drivers/platform/lenovo/Kconfig +6 -0
+	  laptops that deliver them as WMI events. ideapad-laptop subscribes
+	  to this driver for its Fn lock LED and performance mode handling.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called lenovo-wmi-hotkeys.
+
 config LENOVO_WMI_CAMERA
 	tristate "Lenovo WMI Camera Button driver"
 	depends on ACPI_WMI
drivers/platform/lenovo/Makefile +1 -0
index 1cac115dd735..d3f5e3ac14c2 100644
@@ -8,6 +8,7 @@ lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
 lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
 lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
 lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
+lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEYS)	+= wmi-hotkeys.o
 lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
 lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
 lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
drivers/platform/lenovo/wmi-hotkeys.c new file +4 -0
new file mode 100644
index 000000000000..f412652e9f72
@@ -0,0 +1,244 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Lenovo WMI hotkeys driver
+ *

drivers/platform/lenovo/wmi-hotkeys.c line 14

Quoted 10 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +10 -0
+ * Lenovo consumer laptops deliver their vendor specific Fn keys (microphone
+ * mute, airplane mode, performance mode, the star key and others) as WMI
+ * events on GUID 8FC0DE0C-B4E4-43FD-B0F3-8871711C1294 instead of keyboard
+ * usages, and the older Yoga models report Fn+Esc on two dedicated event
+ * GUIDs that carry no data. This driver owns these event GUIDs on every
+ * architecture and reports the keys through a sparse keymap. Drivers with
+ * platform knowledge, such as ideapad-laptop, subscribe to the notifier chain
+ * to act on an event and may stop the key from being reported.
+ *
+ * The key codes follow the mapping historically used by ideapad-laptop.

I don't believe this is the case...

drivers/platform/lenovo/wmi-hotkeys.c line 23

Quoted 9 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +9 -0
+ */
+
+#include <linux/device.h>
+#include <linux/export.h>
+#include <linux/input.h>
+#include <linux/input/sparse-keymap.h>
+#include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/platform_data/x86/lenovo-wmi-hotkeys.h>

I found the path confusing. The driver is intended to function on both ARM64 and x86 based Lenovo devices according to your cover letter.

drivers/platform/lenovo/wmi-hotkeys.c line 30

Quoted 7 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +7 -0
+#include <linux/types.h>
+#include <linux/wmi.h>
+
+#include <asm/byteorder.h>
+
+#define LENOVO_FN_KEYS_WMI_GUID	"8FC0DE0C-B4E4-43FD-B0F3-8871711C1294"
+/* Fn+Esc on the Yoga 3 and Yoga 700 generations, no event data */

Isn't the comment redundant? The macros' names and the next comment below have said the same things.

drivers/platform/lenovo/wmi-hotkeys.c line 41

Quoted 11 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +11 -0
+#define LENOVO_ESC_WMI_GUID_YOGA3	"26CAB2E5-5CF1-46AE-AAC3-4A12B6BA50E6"
+#define LENOVO_ESC_WMI_GUID_YOGA700	"56322276-8493-4CE8-A783-98C991274F5E"
+
+/*
+ * The Esc event GUIDs carry no key code; they are reported under
+ * LENOVO_WMI_HOTKEYS_ESC_CODE, the code ideapad-laptop has always used for
+ * them, so the existing hwdb mappings keep applying. The Fn key GUID codes
+ * are all below 0x80.
+ */
+
+enum lenovo_wmi_hotkeys_type {

Most Lenovo WMI drivers use "lwmi_*_" as their prefixes. Could you use "lwmi_hotkeys_" in all types and methods to make them more brief and unified?

drivers/platform/lenovo/wmi-hotkeys.c line 47

Quoted 6 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +6 -0
+	LENOVO_WMI_HOTKEYS_FN_KEYS,
+	LENOVO_WMI_HOTKEYS_ESC,
+};
+
+static const enum lenovo_wmi_hotkeys_type lenovo_wmi_hotkeys_fn_keys = LENOVO_WMI_HOTKEYS_FN_KEYS;
+static const enum lenovo_wmi_hotkeys_type lenovo_wmi_hotkeys_esc = LENOVO_WMI_HOTKEYS_ESC;

Could you declare a struct (say, lwmi_hotkeys_info) to store these static allocated metadata? In this manner it's tidier and makes future additions much easier. Please refer to lwmi_cd_info.

drivers/platform/lenovo/wmi-hotkeys.c line 53

Quoted 6 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +6 -0
+
+static BLOCKING_NOTIFIER_HEAD(lenovo_wmi_hotkeys_chain);
+
+static const struct key_entry lenovo_wmi_hotkeys_keymap[] = {
+	/* Fn+Esc from the Esc event GUIDs */
+	{ KE_KEY, LENOVO_WMI_HOTKEYS_ESC_CODE, { KEY_ESC } },

I'd prefer using a dedicated keymap for Esc. In this manner we can save some memory (note that sparse_keymap_setup() calls devm_kmemdup_array() to make a RW copy of the keymap).

drivers/platform/lenovo/wmi-hotkeys.c line 56

Quoted 3 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +3 -0
+	/* Customizable Lenovo Hotkey ("star" with 'S' inside) */
+	{ KE_KEY, 0x01, { KEY_FAVORITES } },
+	/* Fn lock toggled on / off, handled by the firmware */

Could you preserve all these comments as they are instead of adding the trimmings?

drivers/platform/lenovo/wmi-hotkeys.c line 59

Quoted 3 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +3 -0
+	{ KE_IGNORE, 0x02 },
+	/* Esc, handled by the firmware */
+	{ KE_IGNORE, 0x03 },

I'd prefer collecting entries of the same type together, i.e., a collection of KE_IGNORE, then KE_KEY, and then KE_SW. In this manner, all entries in a collection is also aligned, improving the readability.

drivers/platform/lenovo/wmi-hotkeys.c line 67

Quoted 8 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +8 -0
+	{ KE_KEY, 0x04, { KEY_SELECTIVE_SCREENSHOT } },
+	/* Lenovo Support */
+	{ KE_KEY, 0x07, { KEY_HELP } },
+	/* Refresh Rate Toggle */
+	{ KE_KEY, 0x0a, { KEY_REFRESH_RATE_TOGGLE } },
+	/* Camera lens cover closed / opened */
+	{ KE_SW, 0x0c, .sw = { SW_CAMERA_LENS_COVER, 0 } },
+	{ KE_SW, 0x0d, .sw = { SW_CAMERA_LENS_COVER, 1 } },

The comment is mistaken. 0x0c means cover opened (uncovered) and 0x0d means the opposite. So, please don't add the trimmings.

This also drops the comment about how WMI switches work. Please preserve it for better documentation.

Quoted 8 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +8 -0
+	{ KE_KEY, 0x0e, { KEY_PICKUP_PHONE } },
+	{ KE_KEY, 0x0f, { KEY_HANGUP_PHONE } },
+	/* Refresh Rate Toggle (Fn+R) */
+	{ KE_KEY, 0x10, { KEY_REFRESH_RATE_TOGGLE } },
+	/* Sound profile switch */
+	{ KE_KEY, 0x12, { KEY_PROG2 } },
+	/* Dark mode toggle */
+	{ KE_KEY, 0x13, { KEY_PROG1 } },

drivers/platform/lenovo/wmi-hotkeys.c line 85

Quoted 10 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +10 -0
+	/* Lenovo Support */
+	{ KE_KEY, 0x27, { KEY_HELP } },
+	/* Lenovo Virtual Background application */
+	{ KE_KEY, 0x28, { KEY_PROG3 } },
+	{ KE_KEY, 0x29, { KEY_TOUCHPAD_TOGGLE } },
+	{ KE_KEY, 0x2a, { KEY_ROOT_MENU } },
+	/* Shift + PrtSc */
+	{ KE_KEY, 0x2d, { KEY_SELECTIVE_SCREENSHOT } },
+	/* Performance mode toggle, Fn+Q */
+	{ KE_KEY, 0x3d, { KEY_PERFORMANCE } },

...because this is changed.

drivers/platform/lenovo/wmi-hotkeys.c line 95

Quoted 10 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +10 -0
+	{ KE_KEY, 0x3e, { KEY_MICMUTE } },
+	{ KE_KEY, 0x3f, { KEY_RFKILL } },
+	/*
+	 * Keyboard backlight level after Fn+Space, handled by the firmware:
+	 * 0x40 off, 0x41 low, 0x42 high, 0x43 also seen
+	 */
+	{ KE_IGNORE, 0x40 },
+	{ KE_IGNORE, 0x41 },
+	{ KE_IGNORE, 0x42 },
+	{ KE_IGNORE, 0x43 },

These entries are new. Please factor out additions into a dedicated patch.

drivers/platform/lenovo/wmi-hotkeys.c line 98

Quoted 3 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +3 -0
+	/* Star, user assignable key */
+	{ KE_KEY, 0x44, { KEY_PROG1 } },
+	/* Eye care */

The original comment has no "care". How did you conclude that?

drivers/platform/lenovo/wmi-hotkeys.c line 104

Quoted 6 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +6 -0
+	{ KE_KEY, 0x45, { KEY_PROG3 } },
+	/* Mode, opens a profile chooser; the Fn+Q button cycles the profile */
+	{ KE_KEY, 0x46, { KEY_PROG4 } },
+	/* Lenovo Smart Connect */
+	{ KE_KEY, 0x48, { KEY_LINK_PHONE } },
+	{ KE_END },

Drop the comma after the terminator item.

Quoted 70 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +70 -0
+};
+
+struct lenovo_wmi_hotkeys {
+	struct input_dev *input;
+	enum lenovo_wmi_hotkeys_type type;
+};
+
+/**
+ * lenovo_wmi_hotkeys_register_notifier() - Subscribe to the hotkey events.
+ * @nb: The notifier_block to register.
+ *
+ * The callback runs in process context with the WMI event code as the
+ * action. Return NOTIFY_STOP from the callback to consume the event.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int lenovo_wmi_hotkeys_register_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_register(&lenovo_wmi_hotkeys_chain, nb);
+}
+EXPORT_SYMBOL_NS_GPL(lenovo_wmi_hotkeys_register_notifier, "LENOVO_WMI_HOTKEYS");
+
+/**
+ * lenovo_wmi_hotkeys_unregister_notifier() - Unsubscribe from the hotkey events.
+ * @nb: The notifier_block to unregister.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int lenovo_wmi_hotkeys_unregister_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_unregister(&lenovo_wmi_hotkeys_chain, nb);
+}
+EXPORT_SYMBOL_NS_GPL(lenovo_wmi_hotkeys_unregister_notifier, "LENOVO_WMI_HOTKEYS");
+
+static void devm_lenovo_wmi_hotkeys_unregister_notifier(void *data)
+{
+	lenovo_wmi_hotkeys_unregister_notifier(data);
+}
+
+/**
+ * devm_lenovo_wmi_hotkeys_register_notifier() - Device managed subscription.
+ * @dev: The device whose lifetime bounds the subscription.
+ * @nb: The notifier_block to register.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int devm_lenovo_wmi_hotkeys_register_notifier(struct device *dev,
+					      struct notifier_block *nb)
+{
+	int ret;
+
+	ret = lenovo_wmi_hotkeys_register_notifier(nb);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, devm_lenovo_wmi_hotkeys_unregister_notifier, nb);
+}
+EXPORT_SYMBOL_NS_GPL(devm_lenovo_wmi_hotkeys_register_notifier, "LENOVO_WMI_HOTKEYS");
+
+static int lenovo_wmi_hotkeys_probe(struct wmi_device *wdev, const void *context)
+{
+	struct lenovo_wmi_hotkeys *priv;
+	int ret;
+
+	priv = devm_kzalloc_obj(&wdev->dev, *priv);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->type = *(const enum lenovo_wmi_hotkeys_type *)context;
+

drivers/platform/lenovo/wmi-hotkeys.c line 184

Quoted 10 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +10 -0
+	priv->input = devm_input_allocate_device(&wdev->dev);
+	if (!priv->input)
+		return -ENOMEM;
+
+	/*
+	 * Same name as the ideapad-laptop input device so that the existing
+	 * hwdb keyboard mappings for these keys keep applying.
+	 */
+	priv->input->name = "Ideapad extra buttons";
+	priv->input->phys = priv->type == LENOVO_WMI_HOTKEYS_ESC ? "wmi/input1" : "wmi/input0";

The strings can be stored in the suggested struct lwmi_hotkeys_info to get rid of the ternary.

Quoted 12 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +12 -0
+	priv->input->id.bustype = BUS_HOST;
+	priv->input->dev.parent = &wdev->dev;
+
+	ret = sparse_keymap_setup(priv->input, lenovo_wmi_hotkeys_keymap, NULL);
+	if (ret)
+		return ret;
+
+	dev_set_drvdata(&wdev->dev, priv);
+
+	return input_register_device(priv->input);
+}
+

drivers/platform/lenovo/wmi-hotkeys.c line 206

Quoted 10 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +10 -0
+static void lenovo_wmi_hotkeys_notify(struct wmi_device *wdev, const struct wmi_buffer *buf)
+{
+	struct lenovo_wmi_hotkeys *priv = dev_get_drvdata(&wdev->dev);
+	u32 code;
+	int ret;
+
+	if (priv->type == LENOVO_WMI_HOTKEYS_ESC) {
+		code = LENOVO_WMI_HOTKEYS_ESC_CODE;
+	} else {
+		if (buf->length < sizeof(u32)) {

Event sizes can be stored in the suggested struct wmi_hotkeys_info.

The same applies to LENOVO_WMI_HOTKEYS_ESC_CODE (let's rename it to LWMI_HOTKEYS_ESC, too).

For example:

static const struct lwmi_hotkeys_info lwmi_hotkeys_esc = {
.type = LWMI_HOTKEYS_ESC,
.phys = "wmi/input1",
.event_size = 0,
.code = LWMI_HOTKEYS_ESC_CODE, /* Used only when !event_size */ .keymap = lwmi_hotkeys_esc_keymap,
}

Quoted 28 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +28 -0
+			dev_dbg(&wdev->dev, "short hotkey event (%zu bytes)\n", buf->length);
+			return;
+		}
+		code = le32_to_cpup(buf->data);
+	}
+
+	dev_dbg(&wdev->dev, "hotkey event 0x%x\n", code);
+
+	ret = blocking_notifier_call_chain(&lenovo_wmi_hotkeys_chain, code, NULL);
+	if (ret & NOTIFY_STOP_MASK)
+		return;
+
+	if (!sparse_keymap_report_event(priv->input, code, 1, true))
+		dev_info_ratelimited(&wdev->dev, "unknown hotkey event 0x%x\n", code);
+}
+
+static const struct wmi_device_id lenovo_wmi_hotkeys_id_table[] = {
+	{ LENOVO_FN_KEYS_WMI_GUID, &lenovo_wmi_hotkeys_fn_keys },
+	{ LENOVO_ESC_WMI_GUID_YOGA3, &lenovo_wmi_hotkeys_esc },
+	{ LENOVO_ESC_WMI_GUID_YOGA700, &lenovo_wmi_hotkeys_esc },
+	{ }
+};
+MODULE_DEVICE_TABLE(wmi, lenovo_wmi_hotkeys_id_table);
+
+static struct wmi_driver lenovo_wmi_hotkeys_driver = {
+	.driver = {
+		.name = "lenovo-wmi-hotkeys",
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,

drivers/platform/lenovo/wmi-hotkeys.c line 244

Quoted 10 lines
drivers/platform/lenovo/wmi-hotkeys.c new file +10 -0
+	},
+	.id_table = lenovo_wmi_hotkeys_id_table,
+	.probe = lenovo_wmi_hotkeys_probe,
+	.notify_new = lenovo_wmi_hotkeys_notify,
+	.no_singleton = true,
+};
+module_wmi_driver(lenovo_wmi_hotkeys_driver);
+
+MODULE_DESCRIPTION("Lenovo WMI hotkeys driver");
+MODULE_LICENSE("GPL");

MODULE_AUTHOR()?

Quoted 10 lines
include/linux/platform_data/x86/lenovo-wmi-hotkeys.h new file +4 -0
new file mode 100644
index 000000000000..cf07eb00f3bb
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Lenovo WMI hotkeys driver, notifier interface for drivers that want to act
+ * on the vendor specific Fn key events before a key is reported.

include/linux/platform_data/x86/lenovo-wmi-hotkeys.h line 14

Quoted 10 lines
include/linux/platform_data/x86/lenovo-wmi-hotkeys.h new file +10 -0
+ */
+
+#ifndef _LENOVO_WMI_HOTKEYS_H_
+#define _LENOVO_WMI_HOTKEYS_H_
+
+struct device;
+struct notifier_block;
+
+/* Code reported for the Fn+Esc event GUIDs, as ideapad-laptop always did */
+#define LENOVO_WMI_HOTKEYS_ESC_CODE	128

If you need the scan codes to be stable, it seemed that you've forgot Fn Keys. They are no longer OR'd with IDEAPAD_WMI_KEY.

If you decide to preserve the scan code of Fn Keys, the offset can be stored in the suggested struct wmi_hotkeys_info, too. The keymap can be modified on the fly by passing a callback to sparse_keymap_setup().

I guess there may also be some useful review comments on sashiko.dev, though I haven't checked it yet.

Thanks,
Rong

Quoted 14 lines
include/linux/platform_data/x86/lenovo-wmi-hotkeys.h new file +14 -0
+
+/*
+ * Notifier callbacks receive the WMI event code as the action and no data:
+ * the Fn key code from the Fn key event GUID, or LENOVO_WMI_HOTKEYS_ESC_CODE
+ * for the Fn+Esc event GUIDs, which carry none. A callback that handles the
+ * event itself returns NOTIFY_STOP to suppress the input report; NOTIFY_OK or
+ * NOTIFY_DONE let it through.
+ */
+int lenovo_wmi_hotkeys_register_notifier(struct notifier_block *nb);
+int lenovo_wmi_hotkeys_unregister_notifier(struct notifier_block *nb);
+int devm_lenovo_wmi_hotkeys_register_notifier(struct device *dev,
+					      struct notifier_block *nb);
+
+#endif /* _LENOVO_WMI_HOTKEYS_H_ */
#28 lore raw

PATCH v2 3/3 platform/x86: ideapad-laptop: consume the Fn key events from the WMI hotkeys driver

In reply to David Cemin

ideapad-laptop binds the Fn key and Fn+Esc WMI event GUIDs itself and reports the keys through its own keymap, but the arm64 Lenovo laptops expose the Fn key GUID without the VPC device this driver is built on, and now have the lenovo-wmi-hotkeys driver reporting those keys on every architecture.

Drop the WMI event driver from ideapad-laptop and subscribe to the lenovo-wmi-hotkeys notifier instead. The notifier callback keeps the two platform specific behaviours: it refreshes the Fn lock LED from the EC on every event, and on the performance button (0x3d) it cycles the platform profile through DYTC and returns NOTIFY_STOP so that no key is reported, as before. All other key codes, the Fn+Esc events and the camera lens cover switch are reported by lenovo-wmi-hotkeys with the same key codes this driver used, so the WMI entries of the keymap are dropped and ideapad-laptop no longer registers any WMI driver.

ideapad-laptop now depends on LENOVO_WMI_HOTKEYS being enabled or disabled consistently; without it the Fn keys are not reported, as on a kernel without ACPI_WMI.

---
 drivers/platform/x86/lenovo/Kconfig          |   1 +
 drivers/platform/x86/lenovo/ideapad-laptop.c | 225 ++++---------------
 2 files changed, 39 insertions(+), 187 deletions(-)
drivers/platform/x86/lenovo/Kconfig +1 -0
index 4d9a25d0e3b5..25817e2f0e1a 100644
@@ -12,6 +12,7 @@ config IDEAPAD_LAPTOP
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on ACPI_VIDEO || ACPI_VIDEO = n
 	depends on ACPI_WMI || ACPI_WMI = n
+	depends on LENOVO_WMI_HOTKEYS || LENOVO_WMI_HOTKEYS = n
 	select ACPI_PLATFORM_PROFILE
 	select INPUT_SPARSEKMAP
 	select NEW_LEDS
drivers/platform/x86/lenovo/ideapad-laptop.c +38 -187

284 lines not on this page · raw message

Signature · 1 line
2.56.1
Reviewed-by on v2 3/3
#29 lore raw

Re: [PATCH v2 3/3] platform/x86: ideapad-laptop: consume the Fn key events from the WMI hotkeys driver

Am 19.11.26 um 03:27 schrieb David Cemin:

Quoted 31 lines

ideapad-laptop binds the Fn key and Fn+Esc WMI event GUIDs itself and reports the keys through its own keymap, but the arm64 Lenovo laptops expose the Fn key GUID without the VPC device this driver is built on, and now have the lenovo-wmi-hotkeys driver reporting those keys on every architecture.

Drop the WMI event driver from ideapad-laptop and subscribe to the lenovo-wmi-hotkeys notifier instead. The notifier callback keeps the two platform specific behaviours: it refreshes the Fn lock LED from the EC on every event, and on the performance button (0x3d) it cycles the platform profile through DYTC and returns NOTIFY_STOP so that no key is reported, as before. All other key codes, the Fn+Esc events and the camera lens cover switch are reported by lenovo-wmi-hotkeys with the same key codes this driver used, so the WMI entries of the keymap are dropped and ideapad-laptop no longer registers any WMI driver.

ideapad-laptop now depends on LENOVO_WMI_HOTKEYS being enabled or disabled consistently; without it the Fn keys are not reported, as on a kernel without ACPI_WMI.

---
  drivers/platform/x86/lenovo/Kconfig          |   1 +
  drivers/platform/x86/lenovo/ideapad-laptop.c | 225 ++++---------------
  2 files changed, 39 insertions(+), 187 deletions(-)
drivers/platform/x86/lenovo/Kconfig +0 -0
index 4d9a25d0e3b5..25817e2f0e1a 100644

drivers/platform/x86/lenovo/Kconfig config IDEAPAD_LAPTOP · line 14

Quoted 3 lines
drivers/platform/x86/lenovo/Kconfig +0 -0
@@ -12,6 +12,7 @@ config IDEAPAD_LAPTOP
  	depends on BACKLIGHT_CLASS_DEVICE
  	depends on ACPI_VIDEO || ACPI_VIDEO = n
  	depends on ACPI_WMI || ACPI_WMI = n

Hi,

i think you can drop the dependency on ACPI_WMI here now, because LENOVO_WMI_HOTKEYS already takes care of that.

With this being addressed:

Quoted 299 lines
drivers/platform/x86/lenovo/Kconfig +1 -0
+	depends on LENOVO_WMI_HOTKEYS || LENOVO_WMI_HOTKEYS = n
  	select ACPI_PLATFORM_PROFILE
  	select INPUT_SPARSEKMAP
  	select NEW_LEDS
drivers/platform/x86/lenovo/ideapad-laptop.c +38 -187
index f9453de6df76..7461f4a59347 100644
@@ -34,7 +34,7 @@
  #include <linux/string_choices.h>
  #include <linux/sysfs.h>
  #include <linux/types.h>
-#include <linux/wmi.h>
+#include <linux/platform_data/x86/lenovo-wmi-hotkeys.h>
  #include "ideapad-laptop.h"
 
  #include <acpi/battery.h>
@@ -185,6 +185,7 @@ struct ideapad_private {
  	struct input_dev *inputdev;
  	struct backlight_device *blightdev;
  	struct ideapad_dytc_priv *dytc;
+	struct notifier_block hotkeys_nb;
  	struct dentry *debug;
  	struct acpi_battery_hook battery_hook;
  	const struct power_supply_ext *battery_ext;
@@ -1317,8 +1318,6 @@ static void ideapad_unregister_rfkill(struct ideapad_private *priv, int dev)
  /*
   * input device
   */
-#define IDEAPAD_WMI_KEY 0x100
-
  static const struct key_entry ideapad_keymap[] = {
  	{ KE_KEY,   6, { KEY_SWITCHVIDEOMODE } },
  	{ KE_KEY,   7, { KEY_CAMERA } },
@@ -1331,65 +1330,6 @@ static const struct key_entry ideapad_keymap[] = {
  	{ KE_KEY,  65, { KEY_PROG4 } },
  	{ KE_KEY,  66, { KEY_TOUCHPAD_OFF } },
  	{ KE_KEY,  67, { KEY_TOUCHPAD_ON } },
-	{ KE_KEY, 128, { KEY_ESC } },
-
-	/*
-	 * WMI keys
-	 */
-
-	/* FnLock (handled by the firmware) */
-	{ KE_IGNORE,	0x02 | IDEAPAD_WMI_KEY },
-	/* Esc (handled by the firmware) */
-	{ KE_IGNORE,	0x03 | IDEAPAD_WMI_KEY },
-	/* Customizable Lenovo Hotkey ("star" with 'S' inside) */
-	{ KE_KEY,	0x01 | IDEAPAD_WMI_KEY, { KEY_FAVORITES } },
-	{ KE_KEY,	0x04 | IDEAPAD_WMI_KEY, { KEY_SELECTIVE_SCREENSHOT } },
-	/* Lenovo Support */
-	{ KE_KEY,	0x07 | IDEAPAD_WMI_KEY, { KEY_HELP } },
-	{ KE_KEY,	0x0e | IDEAPAD_WMI_KEY, { KEY_PICKUP_PHONE } },
-	{ KE_KEY,	0x0f | IDEAPAD_WMI_KEY, { KEY_HANGUP_PHONE } },
-	/* Refresh Rate Toggle (Fn+R) */
-	{ KE_KEY,	0x10 | IDEAPAD_WMI_KEY, { KEY_REFRESH_RATE_TOGGLE } },
-	/* Dark mode toggle */
-	{ KE_KEY,	0x13 | IDEAPAD_WMI_KEY, { KEY_PROG1 } },
-	/* Sound profile switch */
-	{ KE_KEY,	0x12 | IDEAPAD_WMI_KEY, { KEY_PROG2 } },
-	/* Lenovo Virtual Background application */
-	{ KE_KEY,	0x28 | IDEAPAD_WMI_KEY, { KEY_PROG3 } },
-	/* Lenovo Support */
-	{ KE_KEY,	0x27 | IDEAPAD_WMI_KEY, { KEY_HELP } },
-	/* Refresh Rate Toggle */
-	{ KE_KEY,	0x0a | IDEAPAD_WMI_KEY, { KEY_REFRESH_RATE_TOGGLE } },
-	/* Specific to some newer models */
-	{ KE_KEY,	0x3e | IDEAPAD_WMI_KEY, { KEY_MICMUTE } },
-	{ KE_KEY,	0x3f | IDEAPAD_WMI_KEY, { KEY_RFKILL } },
-	/* Star- (User Assignable Key) */
-	{ KE_KEY,	0x44 | IDEAPAD_WMI_KEY, { KEY_PROG1 } },
-	/* Eye */
-	{ KE_KEY,	0x45 | IDEAPAD_WMI_KEY, { KEY_PROG3 } },
-	/* Lenovo Smart Connect */
-	{ KE_KEY,	0x48 | IDEAPAD_WMI_KEY, { KEY_LINK_PHONE } },
-	/* Performance toggle also Fn+Q, handled inside ideapad_wmi_notify() */
-	{ KE_KEY,	0x3d | IDEAPAD_WMI_KEY, { KEY_PROG4 } },
-	/* Mode, opens a profile chooser; the Fn+Q button cycles the profile */
-	{ KE_KEY,	0x46 | IDEAPAD_WMI_KEY, { KEY_PROG4 } },
-	/* shift + prtsc */
-	{ KE_KEY,   0x2d | IDEAPAD_WMI_KEY, { KEY_SELECTIVE_SCREENSHOT } },
-	{ KE_KEY,   0x29 | IDEAPAD_WMI_KEY, { KEY_TOUCHPAD_TOGGLE } },
-	{ KE_KEY,   0x2a | IDEAPAD_WMI_KEY, { KEY_ROOT_MENU } },
-
-	/*
-	 * WMI switches
-	 *
-	 * Some devices come with physical switches. Whenever a switch is
-	 * toggled, an WMI event is emitted to inform the software about the
-	 * switch's latest state.
-	 */
-
-	/* Camera switch */
-	{ KE_SW,	0x0c | IDEAPAD_WMI_KEY, .sw = { SW_CAMERA_LENS_COVER, 0 } },
-	{ KE_SW,	0x0d | IDEAPAD_WMI_KEY, .sw = { SW_CAMERA_LENS_COVER, 1 } },
-
  	{ KE_END },
  };
 
@@ -2297,123 +2237,52 @@ static int ideapad_check_features(struct ideapad_private *priv)
  	return 0;
  }
 
-#if IS_ENABLED(CONFIG_ACPI_WMI)
+#if IS_ENABLED(CONFIG_LENOVO_WMI_HOTKEYS)
  /*
- * WMI driver
+ * The vendor specific Fn keys arrive as WMI events owned by the Lenovo WMI
+ * hotkeys driver, which reports them as input events. Subscribe to act on the
+ * ones that touch the VPC state: the Fn lock LED and the performance mode
+ * button, which cycles the platform profile through DYTC instead of
+ * reporting a key.
   */
-enum ideapad_wmi_event_type {
-	IDEAPAD_WMI_EVENT_ESC,
-	IDEAPAD_WMI_EVENT_FN_KEYS,
-};
-
-struct ideapad_wmi_private {
-	enum ideapad_wmi_event_type event;
-};
-
-static int ideapad_wmi_probe(struct wmi_device *wdev, const void *context)
-{
-	struct ideapad_wmi_private *wpriv;
-
-	wpriv = devm_kzalloc_obj(&wdev->dev, *wpriv);
-	if (!wpriv)
-		return -ENOMEM;
-
-	*wpriv = *(const struct ideapad_wmi_private *)context;
-
-	dev_set_drvdata(&wdev->dev, wpriv);
-	return 0;
-}
-
-static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data)
+static int ideapad_hotkeys_notify(struct notifier_block *nb, unsigned long code,
+				  void *data)
  {
-	struct ideapad_wmi_private *wpriv = dev_get_drvdata(&wdev->dev);
-	struct ideapad_private *priv;
-
-	guard(mutex)(&ideapad_shared_mutex);
-
-	priv = ideapad_shared;
-	if (!priv)
-		return;
+	struct ideapad_private *priv = container_of(nb, struct ideapad_private, hotkeys_nb);
 
-	switch (wpriv->event) {
-	case IDEAPAD_WMI_EVENT_ESC:
-		ideapad_input_report(priv, 128);
-		break;
-	case IDEAPAD_WMI_EVENT_FN_KEYS:
-		if (priv->features.set_fn_lock_led) {
-			int brightness = ideapad_fn_lock_get(priv);
+	if (priv->features.set_fn_lock_led) {
+		int brightness = ideapad_fn_lock_get(priv);
 
-			if (brightness >= 0) {
-				ideapad_fn_lock_set(priv, brightness);
-				ideapad_fn_lock_led_notify(priv, brightness);
-			}
+		if (brightness >= 0) {
+			ideapad_fn_lock_set(priv, brightness);
+			ideapad_fn_lock_led_notify(priv, brightness);
  		}
-
-		if (data->type != ACPI_TYPE_INTEGER) {
-			dev_warn(&wdev->dev,
-				 "WMI event data is not an integer\n");
-			break;
-		}
-
-		dev_dbg(&wdev->dev, "WMI fn-key event: 0x%llx\n",
-			data->integer.value);
-
-		/* performance button triggered by 0x3d */
-		if (data->integer.value == 0x3d && priv->dytc) {
-			platform_profile_cycle();
-			break;
-		}
-
-		/* 0x02 FnLock, 0x03 Esc */
-		if (data->integer.value == 0x02 || data->integer.value == 0x03)
-			ideapad_fn_lock_led_notify(priv, data->integer.value == 0x02);
-
-		ideapad_input_report(priv,
-				     data->integer.value | IDEAPAD_WMI_KEY);
-
-		break;
  	}
-}
-
-static const struct ideapad_wmi_private ideapad_wmi_context_esc = {
-	.event = IDEAPAD_WMI_EVENT_ESC
-};
 
-static const struct ideapad_wmi_private ideapad_wmi_context_fn_keys = {
-	.event = IDEAPAD_WMI_EVENT_FN_KEYS
-};
+	dev_dbg(&priv->platform_device->dev, "WMI fn-key event: 0x%lx\n", code);
 
-static const struct wmi_device_id ideapad_wmi_ids[] = {
-	{ "26CAB2E5-5CF1-46AE-AAC3-4A12B6BA50E6", &ideapad_wmi_context_esc }, /* Yoga 3 */
-	{ "56322276-8493-4CE8-A783-98C991274F5E", &ideapad_wmi_context_esc }, /* Yoga 700 */
-	{ "8FC0DE0C-B4E4-43FD-B0F3-8871711C1294", &ideapad_wmi_context_fn_keys }, /* Legion 5 */
-	{},
-};
-MODULE_DEVICE_TABLE(wmi, ideapad_wmi_ids);
+	/* performance button triggered by 0x3d */
+	if (code == 0x3d && priv->dytc) {
+		platform_profile_cycle();
+		return NOTIFY_STOP;
+	}
 
-static struct wmi_driver ideapad_wmi_driver = {
-	.driver = {
-		.name = "ideapad_wmi",
-	},
-	.id_table = ideapad_wmi_ids,
-	.min_event_size = sizeof(u32),
-	.probe = ideapad_wmi_probe,
-	.notify = ideapad_wmi_notify,
-};
+	/* 0x02 FnLock, 0x03 Esc */
+	if (code == 0x02 || code == 0x03)
+		ideapad_fn_lock_led_notify(priv, code == 0x02);
 
-static int ideapad_wmi_driver_register(void)
-{
-	return wmi_driver_register(&ideapad_wmi_driver);
+	return NOTIFY_OK;
  }
 
-static void ideapad_wmi_driver_unregister(void)
+static int ideapad_hotkeys_register(struct ideapad_private *priv)
  {
-	return wmi_driver_unregister(&ideapad_wmi_driver);
-}
+	priv->hotkeys_nb.notifier_call = ideapad_hotkeys_notify;
 
+	return devm_lenovo_wmi_hotkeys_register_notifier(&priv->platform_device->dev,
+							 &priv->hotkeys_nb);
+}
  #else
-static inline int ideapad_wmi_driver_register(void) { return 0; }
-static inline void ideapad_wmi_driver_unregister(void) { }
+static inline int ideapad_hotkeys_register(struct ideapad_private *priv) { return 0; }
  #endif
 
  /*
@@ -2496,6 +2365,10 @@ static int ideapad_acpi_add(struct platform_device *pdev)
  			dev_info(&pdev->dev, "DYTC interface is not available\n");
  	}
 
+	err = ideapad_hotkeys_register(priv);
+	if (err)
+		dev_warn(&pdev->dev, "Could not subscribe to the WMI hotkey events: %d\n", err);
+
  	if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
  		err = ideapad_backlight_init(priv);
  		if (err && err != -ENODEV)
@@ -2600,31 +2473,9 @@ static struct platform_driver ideapad_acpi_driver = {
  	},
  };
 
-static int __init ideapad_laptop_init(void)
-{
-	int err;
-
-	err = ideapad_wmi_driver_register();
-	if (err)
-		return err;
-
-	err = platform_driver_register(&ideapad_acpi_driver);
-	if (err) {
-		ideapad_wmi_driver_unregister();
-		return err;
-	}
-
-	return 0;
-}
-module_init(ideapad_laptop_init)
-
-static void __exit ideapad_laptop_exit(void)
-{
-	platform_driver_unregister(&ideapad_acpi_driver);
-	ideapad_wmi_driver_unregister();
-}
-module_exit(ideapad_laptop_exit)
+module_platform_driver(ideapad_acpi_driver);
 
  MODULE_AUTHOR("David Woodhouse <[email protected]>");
  MODULE_DESCRIPTION("IdeaPad ACPI Extras");
+MODULE_IMPORT_NS("LENOVO_WMI_HOTKEYS");
  MODULE_LICENSE("GPL");
#30 lore raw

Re: [PATCH v2 3/3] platform/x86: ideapad-laptop: consume the Fn key events from the WMI hotkeys driver

In reply to David Cemin

Hi David,

Thanks for working on this.

Quoted 16 lines · David Cemin

ideapad-laptop binds the Fn key and Fn+Esc WMI event GUIDs itself and reports the keys through its own keymap, but the arm64 Lenovo laptops expose the Fn key GUID without the VPC device this driver is built on, and now have the lenovo-wmi-hotkeys driver reporting those keys on every architecture.

Drop the WMI event driver from ideapad-laptop and subscribe to the lenovo-wmi-hotkeys notifier instead. The notifier callback keeps the two platform specific behaviours: it refreshes the Fn lock LED from the EC on every event, and on the performance button (0x3d) it cycles the platform profile through DYTC and returns NOTIFY_STOP so that no key is reported, as before. All other key codes, the Fn+Esc events and the camera lens cover switch are reported by lenovo-wmi-hotkeys with the same key codes this driver used, so the WMI entries of the keymap are dropped and ideapad-laptop no longer registers any WMI driver.

Quoted 5 lines

ideapad-laptop now depends on LENOVO_WMI_HOTKEYS being enabled or disabled consistently; without it the Fn keys are not reported, as on a kernel without ACPI_WMI.

This should be merge into PATCH 2 as I've said there.

Quoted 10 lines
---
 drivers/platform/x86/lenovo/Kconfig          |   1 +
 drivers/platform/x86/lenovo/ideapad-laptop.c | 225 ++++---------------
 2 files changed, 39 insertions(+), 187 deletions(-)
drivers/platform/x86/lenovo/Kconfig +0 -0
index 4d9a25d0e3b5..25817e2f0e1a 100644

drivers/platform/x86/lenovo/Kconfig config IDEAPAD_LAPTOP · line 15

Quoted 4 lines
drivers/platform/x86/lenovo/Kconfig +1 -0
@@ -12,6 +12,7 @@ config IDEAPAD_LAPTOP
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on ACPI_VIDEO || ACPI_VIDEO = n
 	depends on ACPI_WMI || ACPI_WMI = n
+	depends on LENOVO_WMI_HOTKEYS || LENOVO_WMI_HOTKEYS = n

This introduces a migration issue. When updating .config (say, make olddefconfig), IDEAPAD_LAPTOP=y will not enable LENOVO_WMI_HOTKEYS by default, breaking users' or distributions' existing setup.

IMO it would be better to use `imply LENOVO_WMI_HOTKEYS if ACPI_WMI'.

Quoted 145 lines
drivers/platform/x86/lenovo/Kconfig +0 -0
 	select ACPI_PLATFORM_PROFILE
 	select INPUT_SPARSEKMAP
 	select NEW_LEDS
drivers/platform/x86/lenovo/ideapad-laptop.c +10 -93
index f9453de6df76..7461f4a59347 100644
@@ -34,7 +34,7 @@
 #include <linux/string_choices.h>
 #include <linux/sysfs.h>
 #include <linux/types.h>
-#include <linux/wmi.h>
+#include <linux/platform_data/x86/lenovo-wmi-hotkeys.h>
 #include "ideapad-laptop.h"
 
 #include <acpi/battery.h>
@@ -185,6 +185,7 @@ struct ideapad_private {
 	struct input_dev *inputdev;
 	struct backlight_device *blightdev;
 	struct ideapad_dytc_priv *dytc;
+	struct notifier_block hotkeys_nb;
 	struct dentry *debug;
 	struct acpi_battery_hook battery_hook;
 	const struct power_supply_ext *battery_ext;
@@ -1317,8 +1318,6 @@ static void ideapad_unregister_rfkill(struct ideapad_private *priv, int dev)
 /*
  * input device
  */
-#define IDEAPAD_WMI_KEY 0x100
-
 static const struct key_entry ideapad_keymap[] = {
 	{ KE_KEY,   6, { KEY_SWITCHVIDEOMODE } },
 	{ KE_KEY,   7, { KEY_CAMERA } },
@@ -1331,65 +1330,6 @@ static const struct key_entry ideapad_keymap[] = {
 	{ KE_KEY,  65, { KEY_PROG4 } },
 	{ KE_KEY,  66, { KEY_TOUCHPAD_OFF } },
 	{ KE_KEY,  67, { KEY_TOUCHPAD_ON } },
-	{ KE_KEY, 128, { KEY_ESC } },
-
-	/*
-	 * WMI keys
-	 */
-
-	/* FnLock (handled by the firmware) */
-	{ KE_IGNORE,	0x02 | IDEAPAD_WMI_KEY },
-	/* Esc (handled by the firmware) */
-	{ KE_IGNORE,	0x03 | IDEAPAD_WMI_KEY },
-	/* Customizable Lenovo Hotkey ("star" with 'S' inside) */
-	{ KE_KEY,	0x01 | IDEAPAD_WMI_KEY, { KEY_FAVORITES } },
-	{ KE_KEY,	0x04 | IDEAPAD_WMI_KEY, { KEY_SELECTIVE_SCREENSHOT } },
-	/* Lenovo Support */
-	{ KE_KEY,	0x07 | IDEAPAD_WMI_KEY, { KEY_HELP } },
-	{ KE_KEY,	0x0e | IDEAPAD_WMI_KEY, { KEY_PICKUP_PHONE } },
-	{ KE_KEY,	0x0f | IDEAPAD_WMI_KEY, { KEY_HANGUP_PHONE } },
-	/* Refresh Rate Toggle (Fn+R) */
-	{ KE_KEY,	0x10 | IDEAPAD_WMI_KEY, { KEY_REFRESH_RATE_TOGGLE } },
-	/* Dark mode toggle */
-	{ KE_KEY,	0x13 | IDEAPAD_WMI_KEY, { KEY_PROG1 } },
-	/* Sound profile switch */
-	{ KE_KEY,	0x12 | IDEAPAD_WMI_KEY, { KEY_PROG2 } },
-	/* Lenovo Virtual Background application */
-	{ KE_KEY,	0x28 | IDEAPAD_WMI_KEY, { KEY_PROG3 } },
-	/* Lenovo Support */
-	{ KE_KEY,	0x27 | IDEAPAD_WMI_KEY, { KEY_HELP } },
-	/* Refresh Rate Toggle */
-	{ KE_KEY,	0x0a | IDEAPAD_WMI_KEY, { KEY_REFRESH_RATE_TOGGLE } },
-	/* Specific to some newer models */
-	{ KE_KEY,	0x3e | IDEAPAD_WMI_KEY, { KEY_MICMUTE } },
-	{ KE_KEY,	0x3f | IDEAPAD_WMI_KEY, { KEY_RFKILL } },
-	/* Star- (User Assignable Key) */
-	{ KE_KEY,	0x44 | IDEAPAD_WMI_KEY, { KEY_PROG1 } },
-	/* Eye */
-	{ KE_KEY,	0x45 | IDEAPAD_WMI_KEY, { KEY_PROG3 } },
-	/* Lenovo Smart Connect */
-	{ KE_KEY,	0x48 | IDEAPAD_WMI_KEY, { KEY_LINK_PHONE } },
-	/* Performance toggle also Fn+Q, handled inside ideapad_wmi_notify() */
-	{ KE_KEY,	0x3d | IDEAPAD_WMI_KEY, { KEY_PROG4 } },
-	/* Mode, opens a profile chooser; the Fn+Q button cycles the profile */
-	{ KE_KEY,	0x46 | IDEAPAD_WMI_KEY, { KEY_PROG4 } },
-	/* shift + prtsc */
-	{ KE_KEY,   0x2d | IDEAPAD_WMI_KEY, { KEY_SELECTIVE_SCREENSHOT } },
-	{ KE_KEY,   0x29 | IDEAPAD_WMI_KEY, { KEY_TOUCHPAD_TOGGLE } },
-	{ KE_KEY,   0x2a | IDEAPAD_WMI_KEY, { KEY_ROOT_MENU } },
-
-	/*
-	 * WMI switches
-	 *
-	 * Some devices come with physical switches. Whenever a switch is
-	 * toggled, an WMI event is emitted to inform the software about the
-	 * switch's latest state.
-	 */
-
-	/* Camera switch */
-	{ KE_SW,	0x0c | IDEAPAD_WMI_KEY, .sw = { SW_CAMERA_LENS_COVER, 0 } },
-	{ KE_SW,	0x0d | IDEAPAD_WMI_KEY, .sw = { SW_CAMERA_LENS_COVER, 1 } },
-
 	{ KE_END },
 };
 
@@ -2297,123 +2237,52 @@ static int ideapad_check_features(struct ideapad_private *priv)
 	return 0;
 }
 
-#if IS_ENABLED(CONFIG_ACPI_WMI)
+#if IS_ENABLED(CONFIG_LENOVO_WMI_HOTKEYS)
 /*
- * WMI driver
+ * The vendor specific Fn keys arrive as WMI events owned by the Lenovo WMI
+ * hotkeys driver, which reports them as input events. Subscribe to act on the
+ * ones that touch the VPC state: the Fn lock LED and the performance mode
+ * button, which cycles the platform profile through DYTC instead of
+ * reporting a key.
  */
-enum ideapad_wmi_event_type {
-	IDEAPAD_WMI_EVENT_ESC,
-	IDEAPAD_WMI_EVENT_FN_KEYS,
-};
-
-struct ideapad_wmi_private {
-	enum ideapad_wmi_event_type event;
-};
-
-static int ideapad_wmi_probe(struct wmi_device *wdev, const void *context)
-{
-	struct ideapad_wmi_private *wpriv;
-
-	wpriv = devm_kzalloc_obj(&wdev->dev, *wpriv);
-	if (!wpriv)
-		return -ENOMEM;
-
-	*wpriv = *(const struct ideapad_wmi_private *)context;
-
-	dev_set_drvdata(&wdev->dev, wpriv);
-	return 0;
-}
-
-static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data)
+static int ideapad_hotkeys_notify(struct notifier_block *nb, unsigned long code,
+				  void *data)
 {
-	struct ideapad_wmi_private *wpriv = dev_get_drvdata(&wdev->dev);
-	struct ideapad_private *priv;
-
-	guard(mutex)(&ideapad_shared_mutex);
-

drivers/platform/x86/lenovo/ideapad-laptop.c static int ideapad_check_features(struct ideapad_private *priv) · line 2342

Quoted 10 lines
drivers/platform/x86/lenovo/ideapad-laptop.c +1 -8
-	priv = ideapad_shared;
-	if (!priv)
-		return;
+	struct ideapad_private *priv = container_of(nb, struct ideapad_private, hotkeys_nb);
 
-	switch (wpriv->event) {
-	case IDEAPAD_WMI_EVENT_ESC:
-		ideapad_input_report(priv, 128);
-		break;
-	case IDEAPAD_WMI_EVENT_FN_KEYS:

Now all stuff here listen to both Esc and Fn Keys!

Please export enum lwmi_hotkeys_type and pass it as an event code, the scan code should be passed as event data. In this manner the switch statement and indentation are also preserved, which should result in a much more readable diff set.

Quoted 48 lines
drivers/platform/x86/lenovo/ideapad-laptop.c +6 -38
-		if (priv->features.set_fn_lock_led) {
-			int brightness = ideapad_fn_lock_get(priv);
+	if (priv->features.set_fn_lock_led) {
+		int brightness = ideapad_fn_lock_get(priv);
 
-			if (brightness >= 0) {
-				ideapad_fn_lock_set(priv, brightness);
-				ideapad_fn_lock_led_notify(priv, brightness);
-			}
+		if (brightness >= 0) {
+			ideapad_fn_lock_set(priv, brightness);
+			ideapad_fn_lock_led_notify(priv, brightness);
 		}
-
-		if (data->type != ACPI_TYPE_INTEGER) {
-			dev_warn(&wdev->dev,
-				 "WMI event data is not an integer\n");
-			break;
-		}
-
-		dev_dbg(&wdev->dev, "WMI fn-key event: 0x%llx\n",
-			data->integer.value);
-
-		/* performance button triggered by 0x3d */
-		if (data->integer.value == 0x3d && priv->dytc) {
-			platform_profile_cycle();
-			break;
-		}
-
-		/* 0x02 FnLock, 0x03 Esc */
-		if (data->integer.value == 0x02 || data->integer.value == 0x03)
-			ideapad_fn_lock_led_notify(priv, data->integer.value == 0x02);
-
-		ideapad_input_report(priv,
-				     data->integer.value | IDEAPAD_WMI_KEY);
-
-		break;
 	}
-}
-
-static const struct ideapad_wmi_private ideapad_wmi_context_esc = {
-	.event = IDEAPAD_WMI_EVENT_ESC
-};
 
-static const struct ideapad_wmi_private ideapad_wmi_context_fn_keys = {
-	.event = IDEAPAD_WMI_EVENT_FN_KEYS
-};
+	dev_dbg(&priv->platform_device->dev, "WMI fn-key event: 0x%lx\n", code);

drivers/platform/x86/lenovo/ideapad-laptop.c static int ideapad_check_features(struct ideapad_private *priv) · line 2265

Quoted 10 lines
drivers/platform/x86/lenovo/ideapad-laptop.c +2 -7
 
-static const struct wmi_device_id ideapad_wmi_ids[] = {
-	{ "26CAB2E5-5CF1-46AE-AAC3-4A12B6BA50E6", &ideapad_wmi_context_esc }, /* Yoga 3 */
-	{ "56322276-8493-4CE8-A783-98C991274F5E", &ideapad_wmi_context_esc }, /* Yoga 700 */
-	{ "8FC0DE0C-B4E4-43FD-B0F3-8871711C1294", &ideapad_wmi_context_fn_keys }, /* Legion 5 */
-	{},
-};
-MODULE_DEVICE_TABLE(wmi, ideapad_wmi_ids);
+	/* performance button triggered by 0x3d */
+	if (code == 0x3d && priv->dytc) {

I am not sure if we should introduce a symbolic enumeration for scan codes. It may make things tidier, or it may not...

Quoted 6 lines
drivers/platform/x86/lenovo/ideapad-laptop.c +3 -2
+		platform_profile_cycle();
+		return NOTIFY_STOP;
+	}
 
-static struct wmi_driver ideapad_wmi_driver = {
-	.driver = {

drivers/platform/x86/lenovo/ideapad-laptop.c static int ideapad_check_features(struct ideapad_private *priv) · line 2272

Quoted 10 lines
drivers/platform/x86/lenovo/ideapad-laptop.c +3 -7
-		.name = "ideapad_wmi",
-	},
-	.id_table = ideapad_wmi_ids,
-	.min_event_size = sizeof(u32),
-	.probe = ideapad_wmi_probe,
-	.notify = ideapad_wmi_notify,
-};
+	/* 0x02 FnLock, 0x03 Esc */
+	if (code == 0x02 || code == 0x03)
+		ideapad_fn_lock_led_notify(priv, code == 0x02);

I think we can refactor the branches for 0x3d/0x02/0x03 into a switch statement to improve readability.

Quoted 6 lines
drivers/platform/x86/lenovo/ideapad-laptop.c +1 -3
-static int ideapad_wmi_driver_register(void)
-{
-	return wmi_driver_register(&ideapad_wmi_driver);
+	return NOTIFY_OK;
 }

drivers/platform/x86/lenovo/ideapad-laptop.c static int ideapad_check_features(struct ideapad_private *priv) · line 2282

Quoted 10 lines
drivers/platform/x86/lenovo/ideapad-laptop.c +4 -3
 
-static void ideapad_wmi_driver_unregister(void)
+static int ideapad_hotkeys_register(struct ideapad_private *priv)
 {
-	return wmi_driver_unregister(&ideapad_wmi_driver);
-}
+	priv->hotkeys_nb.notifier_call = ideapad_hotkeys_notify;
 
+	return devm_lenovo_wmi_hotkeys_register_notifier(&priv->platform_device->dev,
+							 &priv->hotkeys_nb);

I haven't examined everything carefully, but is it safe to devm here? It makes the notifier live longer than dytc and LEDs. Perhaps sashiko.dev had examined the devm safety, so please check it out.

drivers/platform/x86/lenovo/ideapad-laptop.c static int ideapad_check_features(struct ideapad_private *priv) · line 2287

Quoted 7 lines
drivers/platform/x86/lenovo/ideapad-laptop.c +2 -2
+}
 #else
-static inline int ideapad_wmi_driver_register(void) { return 0; }
-static inline void ideapad_wmi_driver_unregister(void) { }
+static inline int ideapad_hotkeys_register(struct ideapad_private *priv) { return 0; }
 #endif
 

Since you are modifying the context anyway, could you add comments to the #else and #endif as well?

Thanks,
Rong

Quoted 47 lines
drivers/platform/x86/lenovo/ideapad-laptop.c +6 -24
 /*
@@ -2496,6 +2365,10 @@ static int ideapad_acpi_add(struct platform_device *pdev)
 			dev_info(&pdev->dev, "DYTC interface is not available\n");
 	}
 
+	err = ideapad_hotkeys_register(priv);
+	if (err)
+		dev_warn(&pdev->dev, "Could not subscribe to the WMI hotkey events: %d\n", err);
+
 	if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
 		err = ideapad_backlight_init(priv);
 		if (err && err != -ENODEV)
@@ -2600,31 +2473,9 @@ static struct platform_driver ideapad_acpi_driver = {
 	},
 };
 
-static int __init ideapad_laptop_init(void)
-{
-	int err;
-
-	err = ideapad_wmi_driver_register();
-	if (err)
-		return err;
-
-	err = platform_driver_register(&ideapad_acpi_driver);
-	if (err) {
-		ideapad_wmi_driver_unregister();
-		return err;
-	}
-
-	return 0;
-}
-module_init(ideapad_laptop_init)
-
-static void __exit ideapad_laptop_exit(void)
-{
-	platform_driver_unregister(&ideapad_acpi_driver);
-	ideapad_wmi_driver_unregister();
-}
-module_exit(ideapad_laptop_exit)
+module_platform_driver(ideapad_acpi_driver);
 
 MODULE_AUTHOR("David Woodhouse <[email protected]>");
 MODULE_DESCRIPTION("IdeaPad ACPI Extras");
+MODULE_IMPORT_NS("LENOVO_WMI_HOTKEYS");
 MODULE_LICENSE("GPL");
#31 lore raw

v3 cover platform: lenovo: architecture independent home for the Lenovo WMI drivers

In reply to David Cemin

Lenovo now ships ACPI based arm64 laptops whose firmware exposes the same ACPI-WMI interfaces as the x86 IdeaPad and Legion machines: the Fn key event GUID consumed by ideapad-laptop, the hotkey utility GUID used for the microphone mute LED, and the GameZone, Other Mode and capability data GUIDs behind the thermal operation modes. Since 884d53763d30 ("platform/wmi: Remove dependency on CONFIG_X86") the ACPI-WMI core builds on arm64, but the Lenovo WMI drivers still live under drivers/platform/x86, which is gated by X86_PLATFORM_DEVICES.

This series:
1. moves the architecture independent Lenovo WMI drivers into a new

     drivers/platform/lenovo directory, following drivers/platform/surface;
     ideapad-laptop, thinkpad_acpi, think-lmi and the Yoga tablet drivers
     stay under x86 because they need i8042, port I/O or x86 only devices;

2. adds a WMI Fn keys driver that owns the Fn key and Fn+Esc event GUIDs on every architecture, reports the keys through the keymap taken over from ideapad-laptop, and offers a notifier chain to drivers with platform knowledge; ideapad-laptop drops its WMI event driver in the same patch and subscribes to that notifier for its Fn lock LED and DYTC performance mode handling;
3. adds the keyboard backlight level events seen on the arm64 Yoga as ignored entries.

The series applies on top of Rong Zhang's "platform/x86: ideapad-laptop:
Trigger the EC on YMC events" ([email protected]) because both touch the ideapad-laptop WMI code and that series modernizes the lenovo-wmi-events helper.

Rong offered to co-maintain the new driver and is listed in the MAINTAINERS entry; Rong, please shout if you would rather I drop that until the driver is in.

Patch 2 was tested on a Lenovo Yoga 9 2-in-1 16 (arm64): microphone mute, airplane mode, the Smart Key, the Smart Connect key and the Fn+Q performance key report input events with the same scan codes as before. The Fn+Esc GUIDs are not exposed by that firmware, and the ideapad-laptop side is compile tested on x86_64 only; a test on a Yoga 3 or Yoga 700 (Fn+Esc) and on a machine where ideapad-laptop handles the Fn lock LED or DYTC would be appreciated.

Changes in v3:
- driver renamed to wmi-fn-keys (LENOVO_WMI_FN_KEYS, lenovo-wmi-fn-keys) so it is not confused with wmi-hotkey-utilities (Jackie); header moved to include/linux/platform_data/lenovo-wmi-fn-keys.h (Rong)
- patches 2 and 3 of v2 merged, so both drivers never bind the same WMI devices between the two (Rong)
- lwmi_fn_keys_ prefix, per GUID struct lwmi_fn_keys_info with phys name, event size, scan code base and keymap, dedicated keymap for the Esc GUIDs, MODULE_AUTHOR (Rong)
- keymap taken over from ideapad-laptop with its scan codes (Fn keys

    offset by 0x100, Fn+Esc 128) and comments unchanged, so userspace
    and the hwdb mappings see the same events; the new 0x40 to 0x43
    entries moved to their own patch (Rong)

- notifier: the event type is the action and the Fn key code the data, ideapad-laptop keeps its switch statement; the notifier is unregistered before the DYTC and LED teardown instead of devm (Rong)
- ideapad-laptop: imply LENOVO_WMI_FN_KEYS and IS_REACHABLE() instead of a depends on, so existing configurations keep the Fn keys (Rong); dropped the ACPI_WMI dependency (Armin); #else/#endif comments
- collected Rong's Reviewed-by on patch 1

Changes in v2:
- dropped the WMI core Kconfig patch, 884d53763d30 covers it (Armin)
- notify_new with the wmi_buffer, devm_kzalloc_obj, drvdata set before

    input registration, KEY_PERFORMANCE for 0x3d (Armin)
  - notifier chain called before the keymap lookup, NOTIFY_STOP
    suppresses the key (Hans, Armin); input device named like the
    ideapad-laptop one so the hwdb mappings keep applying (Hans)
  - camera lens cover switch and Fn+Esc GUIDs handled by the new driver
    so ideapad-laptop registers no WMI event driver at all (Armin)
  - 0x48 (Smart Connect) stays KEY_LINK_PHONE as in ideapad-laptop since
    ccc8c8481c1f (Marco Giunta)

- collected Mark's and Jackie's Reviewed-by on patch 1

David Cemin (3):
platform: lenovo: move the architecture independent WMI drivers out of

    x86

platform: lenovo: add WMI Fn keys driver and use it from
ideapad-laptop
platform: lenovo: wmi-fn-keys: ignore the keyboard backlight level
events

 MAINTAINERS                                   |  11 +-
 drivers/platform/Kconfig                      |   2 +
 drivers/platform/Makefile                     |   1 +
 drivers/platform/lenovo/Kconfig               | 102 +++++++
 drivers/platform/lenovo/Makefile              |  23 ++
 .../platform/{x86 => }/lenovo/wmi-camera.c    |   0
 .../platform/{x86 => }/lenovo/wmi-capdata.c   |   0
 .../platform/{x86 => }/lenovo/wmi-capdata.h   |   0
 .../platform/{x86 => }/lenovo/wmi-events.c    |   0
 .../platform/{x86 => }/lenovo/wmi-events.h    |   0
 drivers/platform/lenovo/wmi-fn-keys.c         | 288 ++++++++++++++++++
 .../platform/{x86 => }/lenovo/wmi-gamezone.c  |   0
 .../platform/{x86 => }/lenovo/wmi-helpers.c   |   0
 .../platform/{x86 => }/lenovo/wmi-helpers.h   |   0
 .../{x86 => }/lenovo/wmi-hotkey-utilities.c   |   0
 drivers/platform/{x86 => }/lenovo/wmi-other.c |   0
 drivers/platform/x86/lenovo/Kconfig           |  69 +----
 drivers/platform/x86/lenovo/Makefile          |   7 -
 drivers/platform/x86/lenovo/ideapad-laptop.c  | 227 +++-----------
 .../linux/platform_data/lenovo-wmi-fn-keys.h  |  32 ++
 20 files changed, 508 insertions(+), 254 deletions(-)
 create mode 100644 drivers/platform/lenovo/Kconfig
 create mode 100644 drivers/platform/lenovo/Makefile
 rename drivers/platform/{x86 => }/lenovo/wmi-camera.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.h (100%)
 create mode 100644 drivers/platform/lenovo/wmi-fn-keys.c
 rename drivers/platform/{x86 => }/lenovo/wmi-gamezone.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-hotkey-utilities.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-other.c (100%)
 create mode 100644 include/linux/platform_data/lenovo-wmi-fn-keys.h
Signature · 1 line
2.56.1
#32 lore raw

PATCH v3 1/3 platform: lenovo: move the architecture independent WMI drivers out of x86

The Lenovo WMI drivers (events, helpers, capability data, GameZone, Other Mode, hotkey utilities and camera button) contain no x86 specific
code: they talk to firmware through the ACPI-WMI core only. They live under drivers/platform/x86 because that is where Lenovo drivers were collected, and X86_PLATFORM_DEVICES keeps them off every other architecture.

Lenovo now ships ACPI based arm64 laptops whose firmware exposes the same WMI GUIDs (the Fn key events, the mic mute LED method, GameZone and Other Mode). Give these drivers an architecture independent home, drivers/platform/lenovo, following the layout of drivers/platform/surface which exists for the same reason, so they can be built wherever the WMI core is available. ideapad-laptop, thinkpad_acpi, think-lmi, yogabook and the Yoga Tablet drivers stay under x86: they depend on i8042, port I/O or x86 only ACPI devices.

Pure code motion: the files, their Kconfig entries and the module naming scheme are unchanged. MAINTAINERS entries are updated for the new paths.

---
 MAINTAINERS                                   |  3 +-
 drivers/platform/Kconfig                      |  2 +
 drivers/platform/Makefile                     |  1 +
 drivers/platform/lenovo/Kconfig               | 87 +++++++++++++++++++
 drivers/platform/lenovo/Makefile              | 22 +++++
 .../platform/{x86 => }/lenovo/wmi-camera.c    |  0
 .../platform/{x86 => }/lenovo/wmi-capdata.c   |  0
 .../platform/{x86 => }/lenovo/wmi-capdata.h   |  0
 .../platform/{x86 => }/lenovo/wmi-events.c    |  0
 .../platform/{x86 => }/lenovo/wmi-events.h    |  0
 .../platform/{x86 => }/lenovo/wmi-gamezone.c  |  0
 .../platform/{x86 => }/lenovo/wmi-helpers.c   |  0
 .../platform/{x86 => }/lenovo/wmi-helpers.h   |  0
 .../{x86 => }/lenovo/wmi-hotkey-utilities.c   |  0
 drivers/platform/{x86 => }/lenovo/wmi-other.c |  0
 drivers/platform/x86/lenovo/Kconfig           | 67 --------------
 drivers/platform/x86/lenovo/Makefile          |  7 --
 17 files changed, 114 insertions(+), 75 deletions(-)
 create mode 100644 drivers/platform/lenovo/Kconfig
 create mode 100644 drivers/platform/lenovo/Makefile
 rename drivers/platform/{x86 => }/lenovo/wmi-camera.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-capdata.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-events.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-gamezone.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-helpers.h (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-hotkey-utilities.c (100%)
 rename drivers/platform/{x86 => }/lenovo/wmi-other.c (100%)
MAINTAINERS +2 -1
index 056408bc086e..3b0ad5a3debe 100644
@@ -15170,13 +15170,14 @@ L:	[email protected]
 S:	Maintained
 F:	Documentation/wmi/devices/lenovo-wmi-gamezone.rst
 F:	Documentation/wmi/devices/lenovo-wmi-other.rst
+F:	drivers/platform/lenovo/
 F:	drivers/platform/x86/lenovo/*
 
 LENOVO WMI HOTKEY UTILITIES DRIVER
 M:	Jackie Dong <[email protected]>
 L:	[email protected]
 S:	Maintained
-F:	drivers/platform/x86/lenovo/wmi-hotkey-utilities.c
+F:	drivers/platform/lenovo/wmi-hotkey-utilities.c
 
 LENOVO HID drivers
 M:	Derek J. Clark <[email protected]>
drivers/platform/Kconfig +2 -0
index 312788f249c9..80b2b83b69e5 100644
@@ -15,6 +15,8 @@ source "drivers/platform/olpc/Kconfig"
 
 source "drivers/platform/surface/Kconfig"
 
+source "drivers/platform/lenovo/Kconfig"
+
 source "drivers/platform/x86/Kconfig"
 
 source "drivers/platform/arm64/Kconfig"
drivers/platform/Makefile +1 -0
index fa322e7f8716..0144f88ff6db 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_GOLDFISH)		+= goldfish/
 obj-$(CONFIG_CHROME_PLATFORMS)	+= chrome/
 obj-$(CONFIG_CZNIC_PLATFORMS)	+= cznic/
 obj-$(CONFIG_SURFACE_PLATFORMS)	+= surface/
+obj-$(CONFIG_LENOVO_PLATFORMS)	+= lenovo/
 obj-$(CONFIG_ARM64_PLATFORM_DEVICES)	+= arm64/
 obj-$(CONFIG_BCM2835_VCHIQ)	+= raspberrypi/
 obj-$(CONFIG_ACPI_WMI)		+= wmi/
drivers/platform/lenovo/Kconfig new file +87 -0

87 lines not on this page · raw message

drivers/platform/lenovo/Makefile new file +22 -0
new file mode 100644
index 000000000000..1cac115dd735
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for linux/drivers/platform/lenovo
+# Lenovo Platform Specific Drivers (architecture independent)
+#
+
+lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
+lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
+lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
+lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
+lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
+lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
+lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
+
+# Add 'lenovo' prefix to each module listed in lenovo-target-*
+define LENOVO_OBJ_TARGET
+lenovo-$(1)-y := $(1).o
+obj-$(2) += lenovo-$(1).o
+endef
+
+$(foreach target, $(basename $(lenovo-target-y)), $(eval $(call LENOVO_OBJ_TARGET,$(target),y)))
+$(foreach target, $(basename $(lenovo-target-m)), $(eval $(call LENOVO_OBJ_TARGET,$(target),m)))
drivers/platform/lenovo/wmi-camera.c renamed from drivers/platform/x86/lenovo/wmi-camera.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-camera.c
rename to drivers/platform/lenovo/wmi-camera.c
drivers/platform/lenovo/wmi-capdata.c renamed from drivers/platform/x86/lenovo/wmi-capdata.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-capdata.c
rename to drivers/platform/lenovo/wmi-capdata.c
drivers/platform/lenovo/wmi-capdata.h renamed from drivers/platform/x86/lenovo/wmi-capdata.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-capdata.h
rename to drivers/platform/lenovo/wmi-capdata.h
drivers/platform/lenovo/wmi-events.c renamed from drivers/platform/x86/lenovo/wmi-events.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-events.c
rename to drivers/platform/lenovo/wmi-events.c
drivers/platform/lenovo/wmi-events.h renamed from drivers/platform/x86/lenovo/wmi-events.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-events.h
rename to drivers/platform/lenovo/wmi-events.h
drivers/platform/lenovo/wmi-gamezone.c renamed from drivers/platform/x86/lenovo/wmi-gamezone.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-gamezone.c
rename to drivers/platform/lenovo/wmi-gamezone.c
drivers/platform/lenovo/wmi-helpers.c renamed from drivers/platform/x86/lenovo/wmi-helpers.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-helpers.c
rename to drivers/platform/lenovo/wmi-helpers.c
drivers/platform/lenovo/wmi-helpers.h renamed from drivers/platform/x86/lenovo/wmi-helpers.h +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-helpers.h
rename to drivers/platform/lenovo/wmi-helpers.h
drivers/platform/lenovo/wmi-hotkey-utilities.c renamed from drivers/platform/x86/lenovo/wmi-hotkey-utilities.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-hotkey-utilities.c
rename to drivers/platform/lenovo/wmi-hotkey-utilities.c
drivers/platform/lenovo/wmi-other.c renamed from drivers/platform/x86/lenovo/wmi-other.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo/wmi-other.c
rename to drivers/platform/lenovo/wmi-other.c
drivers/platform/x86/lenovo/Kconfig +0 -67

76 lines not on this page · raw message

drivers/platform/x86/lenovo/Makefile +0 -7
index 12816d8d5e24..758c36cedee8 100644
@@ -7,17 +7,10 @@ obj-$(CONFIG_IDEAPAD_LAPTOP)	+= ideapad-laptop.o
 obj-$(CONFIG_THINKPAD_LMI)	+= think-lmi.o
 obj-$(CONFIG_THINKPAD_ACPI)	+= thinkpad_acpi.o
 
-lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
 lenovo-target-$(CONFIG_LENOVO_YB9_KBDOCK)	+= yb9-kbdock.o
 lenovo-target-$(CONFIG_LENOVO_YMC)	+= ymc.o
 lenovo-target-$(CONFIG_YOGABOOK)	+= yogabook.o
 lenovo-target-$(CONFIG_YT2_1380)	+= yoga-tab2-pro-1380-fastcharger.o
-lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
-lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
-lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
-lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
-lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
-lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
 
 # Add 'lenovo' prefix to each module listed in lenovo-target-*
 define LENOVO_OBJ_TARGET
Signature · 1 line
2.56.1
#33 lore raw

PATCH v3 2/3 platform: lenovo: add WMI Fn keys driver and use it from ideapad-laptop

In reply to David Cemin

Lenovo consumer laptops deliver their vendor specific Fn keys (microphone mute, airplane mode, performance mode, the star key and others) as WMI events on GUID 8FC0DE0C-B4E4-43FD-B0F3-8871711C1294, and the older Yoga models report Fn+Esc on two event GUIDs that carry no data. ideapad-laptop handles all of them today, but it is an x86 only driver built on the VPC ACPI device and the i8042 controller, and the new arm64 Lenovo laptops expose the Fn key GUID without any of that.

Add a Lenovo WMI Fn keys driver that owns the three event GUIDs on every architecture and reports the keys through a sparse keymap. The keymap, the scan codes (the Fn key codes offset by 0x100, Fn+Esc as
128) and the input device name are taken over from ideapad-laptop, so the events userspace sees do not change and the existing hwdb mappings keep applying. The one difference is 0x3d, which now reports KEY_PERFORMANCE instead of KEY_PROG4. A notifier chain lets drivers with platform knowledge act on an event before the key is reported and suppress it with NOTIFY_STOP.

Make ideapad-laptop drop its WMI event driver and keymap entries and subscribe to that notifier instead. The callback keeps the two platform specific behaviours: it refreshes the Fn lock LED from the EC on every Fn key event, and on the performance button it cycles the platform profile through DYTC and consumes the event, as before. The notifier is unregistered before the DYTC and LED teardown in remove() and on the probe error paths. Both changes land in one patch because with the new driver present but ideapad-laptop unchanged, both drivers would bind the same WMI devices.

ideapad-laptop implies LENOVO_WMI_FN_KEYS so that existing configurations keep the Fn keys on a config update, and uses IS_REACHABLE() to tolerate the driver being a module while ideapad-laptop is built in, in which case the keys are still reported by the Fn keys driver and only the VPC specific handling is lost.

Tested on a Lenovo Yoga 9 2-in-1 16 (arm64): microphone mute, airplane mode, the Smart Key, the Smart Connect key and the Fn+Q performance key report input events. The Esc event GUIDs are not exposed by that firmware, so that path is compile tested only, as is ideapad-laptop.

---
 MAINTAINERS                                   |   8 +
 drivers/platform/lenovo/Kconfig               |  15 +
 drivers/platform/lenovo/Makefile              |   1 +
 drivers/platform/lenovo/wmi-fn-keys.c         | 280 ++++++++++++++++++
 drivers/platform/x86/lenovo/Kconfig           |   2 +-
 drivers/platform/x86/lenovo/ideapad-laptop.c  | 227 +++-----------
 .../linux/platform_data/lenovo-wmi-fn-keys.h  |  32 ++
 7 files changed, 386 insertions(+), 179 deletions(-)
 create mode 100644 drivers/platform/lenovo/wmi-fn-keys.c
 create mode 100644 include/linux/platform_data/lenovo-wmi-fn-keys.h
MAINTAINERS +8 -0
index 3b0ad5a3debe..e2be0b7debeb 100644
@@ -15173,6 +15173,14 @@ F:	Documentation/wmi/devices/lenovo-wmi-other.rst
 F:	drivers/platform/lenovo/
 F:	drivers/platform/x86/lenovo/*
 
+LENOVO WMI FN KEYS DRIVER
+M:	David Cemin <[email protected]>
+M:	Rong Zhang <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/platform/lenovo/wmi-fn-keys.c
+F:	include/linux/platform_data/lenovo-wmi-fn-keys.h
+
 LENOVO WMI HOTKEY UTILITIES DRIVER
 M:	Jackie Dong <[email protected]>
 L:	[email protected]
drivers/platform/lenovo/Kconfig +15 -0
index 8222322ca671..f67f7c811214 100644
@@ -41,6 +41,21 @@ config LENOVO_WMI_HOTKEY_UTILITIES
 	  such as LED control for audio/mic mute event for Ideapad, YOGA, XiaoXin,
 	  Gaming, ThinkBook and so on.
 
+config LENOVO_WMI_FN_KEYS
+	tristate "Lenovo WMI Fn keys driver"
+	depends on ACPI_WMI
+	depends on INPUT
+	select INPUT_SPARSEKMAP
+	help
+	  Say Y or M here to enable the vendor specific Fn keys (microphone
+	  mute, airplane mode, performance mode, star key, Fn+Esc, etc.) on
+	  Lenovo laptops that deliver them as WMI events. ideapad-laptop
+	  subscribes to this driver for its Fn lock LED and performance mode
+	  handling.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called lenovo-wmi-fn-keys.
+
 config LENOVO_WMI_CAMERA
 	tristate "Lenovo WMI Camera Button driver"
 	depends on ACPI_WMI
drivers/platform/lenovo/Makefile +1 -0
index 1cac115dd735..8ea207e79a43 100644
@@ -8,6 +8,7 @@ lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
 lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
 lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
 lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
+lenovo-target-$(CONFIG_LENOVO_WMI_FN_KEYS)	+= wmi-fn-keys.o
 lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
 lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
 lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
drivers/platform/lenovo/wmi-fn-keys.c new file +280 -0

280 lines not on this page · raw message

drivers/platform/x86/lenovo/Kconfig +1 -1
index 4d9a25d0e3b5..8a11c981241c 100644
@@ -11,7 +11,7 @@ config IDEAPAD_LAPTOP
 	depends on SERIO_I8042
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on ACPI_VIDEO || ACPI_VIDEO = n
-	depends on ACPI_WMI || ACPI_WMI = n
+	imply LENOVO_WMI_FN_KEYS
 	select ACPI_PLATFORM_PROFILE
 	select INPUT_SPARSEKMAP
 	select NEW_LEDS
drivers/platform/x86/lenovo/ideapad-laptop.c +49 -178

305 lines not on this page · raw message

include/linux/platform_data/lenovo-wmi-fn-keys.h new file +32 -0
new file mode 100644
index 000000000000..4a737990b184
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Lenovo WMI Fn keys driver, notifier interface for drivers that want to act
+ * on the vendor specific Fn key events before a key is reported.
+ */
+
+#ifndef _LENOVO_WMI_FN_KEYS_H_
+#define _LENOVO_WMI_FN_KEYS_H_
+
+struct device;
+struct notifier_block;
+
+/**
+ * enum lwmi_fn_keys_event - notifier chain actions
+ * @LWMI_FN_KEYS_EVENT_ESC: Fn+Esc from one of the Esc event GUIDs, which
+ *                          carry no event data
+ * @LWMI_FN_KEYS_EVENT_FN_KEY: a key from the Fn key event GUID, the notifier
+ *                             data points to the u32 key code
+ *
+ * A callback that handles the event itself returns NOTIFY_STOP to suppress
+ * the input report; NOTIFY_OK or NOTIFY_DONE let it through.
+ */
+enum lwmi_fn_keys_event {
+	LWMI_FN_KEYS_EVENT_ESC,
+	LWMI_FN_KEYS_EVENT_FN_KEY,
+};
+
+int lwmi_fn_keys_register_notifier(struct notifier_block *nb);
+int lwmi_fn_keys_unregister_notifier(struct notifier_block *nb);
+int devm_lwmi_fn_keys_register_notifier(struct device *dev, struct notifier_block *nb);
+
+#endif /* _LENOVO_WMI_FN_KEYS_H_ */
Signature · 1 line
2.56.1
Reviewed-by on v3 2/3
#34 lore raw

Re: [PATCH v3 2/3] platform: lenovo: add WMI Fn keys driver and use it from ideapad-laptop

Hi David,

Thanks for your work.

Quoted 34 lines · David Cemin

Lenovo consumer laptops deliver their vendor specific Fn keys (microphone mute, airplane mode, performance mode, the star key and others) as WMI events on GUID 8FC0DE0C-B4E4-43FD-B0F3-8871711C1294, and the older Yoga models report Fn+Esc on two event GUIDs that carry no data. ideapad-laptop handles all of them today, but it is an x86 only driver built on the VPC ACPI device and the i8042 controller, and the new arm64 Lenovo laptops expose the Fn key GUID without any of that.

Add a Lenovo WMI Fn keys driver that owns the three event GUIDs on every architecture and reports the keys through a sparse keymap. The keymap, the scan codes (the Fn key codes offset by 0x100, Fn+Esc as
128) and the input device name are taken over from ideapad-laptop, so the events userspace sees do not change and the existing hwdb mappings keep applying. The one difference is 0x3d, which now reports KEY_PERFORMANCE instead of KEY_PROG4. A notifier chain lets drivers with platform knowledge act on an event before the key is reported and suppress it with NOTIFY_STOP.

Make ideapad-laptop drop its WMI event driver and keymap entries and subscribe to that notifier instead. The callback keeps the two platform specific behaviours: it refreshes the Fn lock LED from the EC on every Fn key event, and on the performance button it cycles the platform profile through DYTC and consumes the event, as before. The notifier is unregistered before the DYTC and LED teardown in remove() and on the probe error paths. Both changes land in one patch because with the new driver present but ideapad-laptop unchanged, both drivers would bind the same WMI devices.

ideapad-laptop implies LENOVO_WMI_FN_KEYS so that existing configurations keep the Fn keys on a config update, and uses IS_REACHABLE() to tolerate the driver being a module while ideapad-laptop is built in, in which case the keys are still reported by the Fn keys driver and only the VPC specific handling is lost.

Quoted 6 lines

Tested on a Lenovo Yoga 9 2-in-1 16 (arm64): microphone mute, airplane mode, the Smart Key, the Smart Connect key and the Fn+Q performance key report input events. The Esc event GUIDs are not exposed by that firmware, so that path is compile tested only, as is ideapad-laptop.

The patch now looks quite good to me, except for some minor issues. See below.

Quoted 131 lines
---
 MAINTAINERS                                   |   8 +
 drivers/platform/lenovo/Kconfig               |  15 +
 drivers/platform/lenovo/Makefile              |   1 +
 drivers/platform/lenovo/wmi-fn-keys.c         | 280 ++++++++++++++++++
 drivers/platform/x86/lenovo/Kconfig           |   2 +-
 drivers/platform/x86/lenovo/ideapad-laptop.c  | 227 +++-----------
 .../linux/platform_data/lenovo-wmi-fn-keys.h  |  32 ++
 7 files changed, 386 insertions(+), 179 deletions(-)
 create mode 100644 drivers/platform/lenovo/wmi-fn-keys.c
 create mode 100644 include/linux/platform_data/lenovo-wmi-fn-keys.h
MAINTAINERS +8 -0
index 3b0ad5a3debe..e2be0b7debeb 100644
@@ -15173,6 +15173,14 @@ F:	Documentation/wmi/devices/lenovo-wmi-other.rst
 F:	drivers/platform/lenovo/
 F:	drivers/platform/x86/lenovo/*
 
+LENOVO WMI FN KEYS DRIVER
+M:	David Cemin <[email protected]>
+M:	Rong Zhang <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/platform/lenovo/wmi-fn-keys.c
+F:	include/linux/platform_data/lenovo-wmi-fn-keys.h
+
 LENOVO WMI HOTKEY UTILITIES DRIVER
 M:	Jackie Dong <[email protected]>
 L:	[email protected]
drivers/platform/lenovo/Kconfig +15 -0
index 8222322ca671..f67f7c811214 100644
@@ -41,6 +41,21 @@ config LENOVO_WMI_HOTKEY_UTILITIES
 	  such as LED control for audio/mic mute event for Ideapad, YOGA, XiaoXin,
 	  Gaming, ThinkBook and so on.
 
+config LENOVO_WMI_FN_KEYS
+	tristate "Lenovo WMI Fn keys driver"
+	depends on ACPI_WMI
+	depends on INPUT
+	select INPUT_SPARSEKMAP
+	help
+	  Say Y or M here to enable the vendor specific Fn keys (microphone
+	  mute, airplane mode, performance mode, star key, Fn+Esc, etc.) on
+	  Lenovo laptops that deliver them as WMI events. ideapad-laptop
+	  subscribes to this driver for its Fn lock LED and performance mode
+	  handling.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called lenovo-wmi-fn-keys.
+
 config LENOVO_WMI_CAMERA
 	tristate "Lenovo WMI Camera Button driver"
 	depends on ACPI_WMI
drivers/platform/lenovo/Makefile +1 -0
index 1cac115dd735..8ea207e79a43 100644
@@ -8,6 +8,7 @@ lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
 lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
 lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
 lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
+lenovo-target-$(CONFIG_LENOVO_WMI_FN_KEYS)	+= wmi-fn-keys.o
 lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
 lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
 lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
drivers/platform/lenovo/wmi-fn-keys.c new file +56 -0
new file mode 100644
index 000000000000..330de9529a87
@@ -0,0 +1,280 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Lenovo WMI Fn keys driver
+ *
+ * Lenovo consumer laptops deliver their vendor specific Fn keys (microphone
+ * mute, airplane mode, performance mode, the star key and others) as WMI
+ * events on a dedicated GUID instead of keyboard usages, and the older Yoga
+ * models report Fn+Esc on two event GUIDs that carry no data. This driver
+ * owns these event GUIDs on every architecture and reports the keys through
+ * a sparse keymap. Drivers with platform knowledge, such as ideapad-laptop,
+ * subscribe to the notifier chain to act on an event and may stop the key
+ * from being reported.
+ *
+ * The keymap and the scan codes were moved here from ideapad-laptop, so the
+ * input events are the same as before for userspace.
+ */
+
+#include <linux/device.h>
+#include <linux/export.h>
+#include <linux/input.h>
+#include <linux/input/sparse-keymap.h>
+#include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/platform_data/lenovo-wmi-fn-keys.h>
+#include <linux/types.h>
+#include <linux/wmi.h>
+
+#include <asm/byteorder.h>
+
+#define LWMI_FN_KEYS_GUID	"8FC0DE0C-B4E4-43FD-B0F3-8871711C1294"
+#define LWMI_ESC_GUID_YOGA3	"26CAB2E5-5CF1-46AE-AAC3-4A12B6BA50E6"
+#define LWMI_ESC_GUID_YOGA700	"56322276-8493-4CE8-A783-98C991274F5E"
+
+/*
+ * Scan codes as ideapad-laptop reported them: the Fn key event codes are
+ * offset by LWMI_FN_KEY so they do not collide with the ACPI hotkeys of that
+ * driver, and the Fn+Esc events, which carry no data, use scan code 128.
+ */
+#define LWMI_FN_KEY		0x100
+#define LWMI_ESC_SCANCODE	128
+
+/**
+ * struct lwmi_fn_keys_info - per event GUID description
+ * @event: event type passed to the notifier chain
+ * @phys: physical path of the input device
+ * @event_size: size of the WMI event data, 0 when the GUID carries none
+ * @code: scan code base: the offset added to the event data, or the whole
+ *        scan code for GUIDs without event data
+ * @keymap: sparse keymap for the input device
+ */
+struct lwmi_fn_keys_info {
+	enum lwmi_fn_keys_event event;
+	const char *phys;
+	size_t event_size;
+	u32 code;
+	const struct key_entry *keymap;

drivers/platform/lenovo/wmi-fn-keys.c line 66

Quoted 10 lines
drivers/platform/lenovo/wmi-fn-keys.c new file +10 -0
+};
+
+struct lwmi_fn_keys {
+	struct input_dev *input;
+	const struct lwmi_fn_keys_info *info;
+};
+
+static BLOCKING_NOTIFIER_HEAD(lwmi_fn_keys_chain);
+
+static const struct key_entry lwmi_fn_keys_keymap[] = {

Let's add a separator here, like:

/*
* WMI ignored events
*/

drivers/platform/lenovo/wmi-fn-keys.c line 70

Quoted 4 lines
drivers/platform/lenovo/wmi-fn-keys.c new file +4 -0
+	/* FnLock (handled by the firmware) */
+	{ KE_IGNORE,	0x02 | LWMI_FN_KEY },
+	/* Esc (handled by the firmware) */
+	{ KE_IGNORE,	0x03 | LWMI_FN_KEY },

Ditto, like ideapad-laptop originally did:

/*
* WMI keys
*/

Quoted 215 lines
drivers/platform/lenovo/wmi-fn-keys.c new file +210 -0
+
+	/* Customizable Lenovo Hotkey ("star" with 'S' inside) */
+	{ KE_KEY,	0x01 | LWMI_FN_KEY, { KEY_FAVORITES } },
+	{ KE_KEY,	0x04 | LWMI_FN_KEY, { KEY_SELECTIVE_SCREENSHOT } },
+	/* Lenovo Support */
+	{ KE_KEY,	0x07 | LWMI_FN_KEY, { KEY_HELP } },
+	{ KE_KEY,	0x0e | LWMI_FN_KEY, { KEY_PICKUP_PHONE } },
+	{ KE_KEY,	0x0f | LWMI_FN_KEY, { KEY_HANGUP_PHONE } },
+	/* Refresh Rate Toggle (Fn+R) */
+	{ KE_KEY,	0x10 | LWMI_FN_KEY, { KEY_REFRESH_RATE_TOGGLE } },
+	/* Dark mode toggle */
+	{ KE_KEY,	0x13 | LWMI_FN_KEY, { KEY_PROG1 } },
+	/* Sound profile switch */
+	{ KE_KEY,	0x12 | LWMI_FN_KEY, { KEY_PROG2 } },
+	/* Lenovo Virtual Background application */
+	{ KE_KEY,	0x28 | LWMI_FN_KEY, { KEY_PROG3 } },
+	/* Lenovo Support */
+	{ KE_KEY,	0x27 | LWMI_FN_KEY, { KEY_HELP } },
+	/* Refresh Rate Toggle */
+	{ KE_KEY,	0x0a | LWMI_FN_KEY, { KEY_REFRESH_RATE_TOGGLE } },
+	/* Specific to some newer models */
+	{ KE_KEY,	0x3e | LWMI_FN_KEY, { KEY_MICMUTE } },
+	{ KE_KEY,	0x3f | LWMI_FN_KEY, { KEY_RFKILL } },
+	/* Star- (User Assignable Key) */
+	{ KE_KEY,	0x44 | LWMI_FN_KEY, { KEY_PROG1 } },
+	/* Eye */
+	{ KE_KEY,	0x45 | LWMI_FN_KEY, { KEY_PROG3 } },
+	/* Lenovo Smart Connect */
+	{ KE_KEY,	0x48 | LWMI_FN_KEY, { KEY_LINK_PHONE } },
+	/*
+	 * Performance toggle also Fn+Q, consumed by ideapad-laptop through the
+	 * notifier chain on machines where it cycles the platform profile
+	 */
+	{ KE_KEY,	0x3d | LWMI_FN_KEY, { KEY_PERFORMANCE } },
+	/* Mode, opens a profile chooser; the Fn+Q button cycles the profile */
+	{ KE_KEY,	0x46 | LWMI_FN_KEY, { KEY_PROG4 } },
+	/* shift + prtsc */
+	{ KE_KEY,	0x2d | LWMI_FN_KEY, { KEY_SELECTIVE_SCREENSHOT } },
+	{ KE_KEY,	0x29 | LWMI_FN_KEY, { KEY_TOUCHPAD_TOGGLE } },
+	{ KE_KEY,	0x2a | LWMI_FN_KEY, { KEY_ROOT_MENU } },
+
+	/*
+	 * WMI switches
+	 *
+	 * Some devices come with physical switches. Whenever a switch is
+	 * toggled, an WMI event is emitted to inform the software about the
+	 * switch's latest state.
+	 */
+
+	/* Camera switch */
+	{ KE_SW,	0x0c | LWMI_FN_KEY, .sw = { SW_CAMERA_LENS_COVER, 0 } },
+	{ KE_SW,	0x0d | LWMI_FN_KEY, .sw = { SW_CAMERA_LENS_COVER, 1 } },
+
+	{ KE_END }
+};
+
+static const struct key_entry lwmi_esc_keymap[] = {
+	{ KE_KEY,	LWMI_ESC_SCANCODE, { KEY_ESC } },
+	{ KE_END }
+};
+
+static const struct lwmi_fn_keys_info lwmi_fn_keys_info_fn_keys = {
+	.event = LWMI_FN_KEYS_EVENT_FN_KEY,
+	.phys = "wmi/input0",
+	.event_size = sizeof(u32),
+	.code = LWMI_FN_KEY,
+	.keymap = lwmi_fn_keys_keymap,
+};
+
+static const struct lwmi_fn_keys_info lwmi_fn_keys_info_esc = {
+	.event = LWMI_FN_KEYS_EVENT_ESC,
+	.phys = "wmi/input1",
+	.code = LWMI_ESC_SCANCODE,
+	.keymap = lwmi_esc_keymap,
+};
+
+/**
+ * lwmi_fn_keys_register_notifier() - Subscribe to the Fn key events.
+ * @nb: The notifier_block to register.
+ *
+ * The callback runs in process context with the &enum lwmi_fn_keys_event as
+ * the action and, for LWMI_FN_KEYS_EVENT_FN_KEY, a pointer to the u32 key
+ * code as the data. Return NOTIFY_STOP from the callback to consume the event
+ * so that no key is reported.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int lwmi_fn_keys_register_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_register(&lwmi_fn_keys_chain, nb);
+}
+EXPORT_SYMBOL_NS_GPL(lwmi_fn_keys_register_notifier, "LENOVO_WMI_FN_KEYS");
+
+/**
+ * lwmi_fn_keys_unregister_notifier() - Unsubscribe from the Fn key events.
+ * @nb: The notifier_block to unregister.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int lwmi_fn_keys_unregister_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_unregister(&lwmi_fn_keys_chain, nb);
+}
+EXPORT_SYMBOL_NS_GPL(lwmi_fn_keys_unregister_notifier, "LENOVO_WMI_FN_KEYS");
+
+static void devm_lwmi_fn_keys_unregister_notifier(void *data)
+{
+	lwmi_fn_keys_unregister_notifier(data);
+}
+
+/**
+ * devm_lwmi_fn_keys_register_notifier() - Device managed subscription.
+ * @dev: The device whose lifetime bounds the subscription.
+ * @nb: The notifier_block to register.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int devm_lwmi_fn_keys_register_notifier(struct device *dev, struct notifier_block *nb)
+{
+	int ret;
+
+	ret = lwmi_fn_keys_register_notifier(nb);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, devm_lwmi_fn_keys_unregister_notifier, nb);
+}
+EXPORT_SYMBOL_NS_GPL(devm_lwmi_fn_keys_register_notifier, "LENOVO_WMI_FN_KEYS");
+
+static int lwmi_fn_keys_probe(struct wmi_device *wdev, const void *context)
+{
+	struct lwmi_fn_keys *priv;
+	int ret;
+
+	priv = devm_kzalloc_obj(&wdev->dev, *priv);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->info = context;
+
+	priv->input = devm_input_allocate_device(&wdev->dev);
+	if (!priv->input)
+		return -ENOMEM;
+
+	/*
+	 * Same name as the ideapad-laptop input device so that the existing
+	 * hwdb keyboard mappings for these keys keep applying.
+	 */
+	priv->input->name = "Ideapad extra buttons";
+	priv->input->phys = priv->info->phys;
+	priv->input->id.bustype = BUS_HOST;
+	priv->input->dev.parent = &wdev->dev;
+
+	ret = sparse_keymap_setup(priv->input, priv->info->keymap, NULL);
+	if (ret)
+		return ret;
+
+	dev_set_drvdata(&wdev->dev, priv);
+
+	return input_register_device(priv->input);
+}
+
+static void lwmi_fn_keys_notify(struct wmi_device *wdev, const struct wmi_buffer *buf)
+{
+	struct lwmi_fn_keys *priv = dev_get_drvdata(&wdev->dev);
+	const struct lwmi_fn_keys_info *info = priv->info;
+	u32 code = 0;
+	int ret;
+
+	if (buf->length < info->event_size) {
+		dev_dbg(&wdev->dev, "short event (%zu bytes)\n", buf->length);
+		return;
+	}
+
+	if (info->event_size)
+		code = le32_to_cpup(buf->data);
+
+	dev_dbg(&wdev->dev, "event %d code 0x%x\n", info->event, code);
+
+	ret = blocking_notifier_call_chain(&lwmi_fn_keys_chain, info->event, &code);
+	if (ret & NOTIFY_STOP_MASK)
+		return;
+
+	if (!sparse_keymap_report_event(priv->input, info->code | code, 1, true))
+		dev_info_ratelimited(&wdev->dev, "unknown key code 0x%x\n", code);
+}
+
+static const struct wmi_device_id lwmi_fn_keys_id_table[] = {
+	{ LWMI_FN_KEYS_GUID, &lwmi_fn_keys_info_fn_keys },
+	{ LWMI_ESC_GUID_YOGA3, &lwmi_fn_keys_info_esc },
+	{ LWMI_ESC_GUID_YOGA700, &lwmi_fn_keys_info_esc },
+	{ }
+};
+MODULE_DEVICE_TABLE(wmi, lwmi_fn_keys_id_table);
+
+static struct wmi_driver lwmi_fn_keys_driver = {
+	.driver = {
+		.name = "lenovo-wmi-fn-keys",
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+	},
+	.id_table = lwmi_fn_keys_id_table,
+	.probe = lwmi_fn_keys_probe,
+	.notify_new = lwmi_fn_keys_notify,
+	.no_singleton = true,
+};
+module_wmi_driver(lwmi_fn_keys_driver);
+
+MODULE_AUTHOR("David Cemin <[email protected]>");
+MODULE_DESCRIPTION("Lenovo WMI Fn keys driver");
+MODULE_LICENSE("GPL");
drivers/platform/x86/lenovo/Kconfig +0 -0
index 4d9a25d0e3b5..8a11c981241c 100644

drivers/platform/x86/lenovo/Kconfig config IDEAPAD_LAPTOP · line 14

Quoted 5 lines
drivers/platform/x86/lenovo/Kconfig +1 -1
@@ -11,7 +11,7 @@ config IDEAPAD_LAPTOP
 	depends on SERIO_I8042
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on ACPI_VIDEO || ACPI_VIDEO = n
-	depends on ACPI_WMI || ACPI_WMI = n
+	imply LENOVO_WMI_FN_KEYS

Unconditionally implying LENOVO_WMI_FN_KEYS is broken. See Documentation/kbuild/kconfig-language.rst:

select should be used with care. select will force a symbol to a value without visiting the dependencies. By abusing select you are able to select a symbol FOO even if FOO depends on BAR that is not set.

(which also applies to `imply')

In general, you can only select or imply a symbol when you've collected all its dependencies. That's why I suggested

imply LENOVO_WMI_FN_KEYS if ACPI_WMI

in my previous reply.

Quoted 166 lines
drivers/platform/x86/lenovo/Kconfig +0 -0
 	select ACPI_PLATFORM_PROFILE
 	select INPUT_SPARSEKMAP
 	select NEW_LEDS
drivers/platform/x86/lenovo/ideapad-laptop.c +15 -100
index f9453de6df76..92d05470dee9 100644
@@ -34,7 +34,7 @@
 #include <linux/string_choices.h>
 #include <linux/sysfs.h>
 #include <linux/types.h>
-#include <linux/wmi.h>
+#include <linux/platform_data/lenovo-wmi-fn-keys.h>
 #include "ideapad-laptop.h"
 
 #include <acpi/battery.h>
@@ -185,6 +185,7 @@ struct ideapad_private {
 	struct input_dev *inputdev;
 	struct backlight_device *blightdev;
 	struct ideapad_dytc_priv *dytc;
+	struct notifier_block fn_keys_nb;
 	struct dentry *debug;
 	struct acpi_battery_hook battery_hook;
 	const struct power_supply_ext *battery_ext;
@@ -1317,8 +1318,6 @@ static void ideapad_unregister_rfkill(struct ideapad_private *priv, int dev)
 /*
  * input device
  */
-#define IDEAPAD_WMI_KEY 0x100
-
 static const struct key_entry ideapad_keymap[] = {
 	{ KE_KEY,   6, { KEY_SWITCHVIDEOMODE } },
 	{ KE_KEY,   7, { KEY_CAMERA } },
@@ -1331,65 +1330,6 @@ static const struct key_entry ideapad_keymap[] = {
 	{ KE_KEY,  65, { KEY_PROG4 } },
 	{ KE_KEY,  66, { KEY_TOUCHPAD_OFF } },
 	{ KE_KEY,  67, { KEY_TOUCHPAD_ON } },
-	{ KE_KEY, 128, { KEY_ESC } },
-
-	/*
-	 * WMI keys
-	 */
-
-	/* FnLock (handled by the firmware) */
-	{ KE_IGNORE,	0x02 | IDEAPAD_WMI_KEY },
-	/* Esc (handled by the firmware) */
-	{ KE_IGNORE,	0x03 | IDEAPAD_WMI_KEY },
-	/* Customizable Lenovo Hotkey ("star" with 'S' inside) */
-	{ KE_KEY,	0x01 | IDEAPAD_WMI_KEY, { KEY_FAVORITES } },
-	{ KE_KEY,	0x04 | IDEAPAD_WMI_KEY, { KEY_SELECTIVE_SCREENSHOT } },
-	/* Lenovo Support */
-	{ KE_KEY,	0x07 | IDEAPAD_WMI_KEY, { KEY_HELP } },
-	{ KE_KEY,	0x0e | IDEAPAD_WMI_KEY, { KEY_PICKUP_PHONE } },
-	{ KE_KEY,	0x0f | IDEAPAD_WMI_KEY, { KEY_HANGUP_PHONE } },
-	/* Refresh Rate Toggle (Fn+R) */
-	{ KE_KEY,	0x10 | IDEAPAD_WMI_KEY, { KEY_REFRESH_RATE_TOGGLE } },
-	/* Dark mode toggle */
-	{ KE_KEY,	0x13 | IDEAPAD_WMI_KEY, { KEY_PROG1 } },
-	/* Sound profile switch */
-	{ KE_KEY,	0x12 | IDEAPAD_WMI_KEY, { KEY_PROG2 } },
-	/* Lenovo Virtual Background application */
-	{ KE_KEY,	0x28 | IDEAPAD_WMI_KEY, { KEY_PROG3 } },
-	/* Lenovo Support */
-	{ KE_KEY,	0x27 | IDEAPAD_WMI_KEY, { KEY_HELP } },
-	/* Refresh Rate Toggle */
-	{ KE_KEY,	0x0a | IDEAPAD_WMI_KEY, { KEY_REFRESH_RATE_TOGGLE } },
-	/* Specific to some newer models */
-	{ KE_KEY,	0x3e | IDEAPAD_WMI_KEY, { KEY_MICMUTE } },
-	{ KE_KEY,	0x3f | IDEAPAD_WMI_KEY, { KEY_RFKILL } },
-	/* Star- (User Assignable Key) */
-	{ KE_KEY,	0x44 | IDEAPAD_WMI_KEY, { KEY_PROG1 } },
-	/* Eye */
-	{ KE_KEY,	0x45 | IDEAPAD_WMI_KEY, { KEY_PROG3 } },
-	/* Lenovo Smart Connect */
-	{ KE_KEY,	0x48 | IDEAPAD_WMI_KEY, { KEY_LINK_PHONE } },
-	/* Performance toggle also Fn+Q, handled inside ideapad_wmi_notify() */
-	{ KE_KEY,	0x3d | IDEAPAD_WMI_KEY, { KEY_PROG4 } },
-	/* Mode, opens a profile chooser; the Fn+Q button cycles the profile */
-	{ KE_KEY,	0x46 | IDEAPAD_WMI_KEY, { KEY_PROG4 } },
-	/* shift + prtsc */
-	{ KE_KEY,   0x2d | IDEAPAD_WMI_KEY, { KEY_SELECTIVE_SCREENSHOT } },
-	{ KE_KEY,   0x29 | IDEAPAD_WMI_KEY, { KEY_TOUCHPAD_TOGGLE } },
-	{ KE_KEY,   0x2a | IDEAPAD_WMI_KEY, { KEY_ROOT_MENU } },
-
-	/*
-	 * WMI switches
-	 *
-	 * Some devices come with physical switches. Whenever a switch is
-	 * toggled, an WMI event is emitted to inform the software about the
-	 * switch's latest state.
-	 */
-
-	/* Camera switch */
-	{ KE_SW,	0x0c | IDEAPAD_WMI_KEY, .sw = { SW_CAMERA_LENS_COVER, 0 } },
-	{ KE_SW,	0x0d | IDEAPAD_WMI_KEY, .sw = { SW_CAMERA_LENS_COVER, 1 } },
-
 	{ KE_END },
 };
 
@@ -2297,49 +2237,24 @@ static int ideapad_check_features(struct ideapad_private *priv)
 	return 0;
 }
 
-#if IS_ENABLED(CONFIG_ACPI_WMI)
+#if IS_REACHABLE(CONFIG_LENOVO_WMI_FN_KEYS)
 /*
- * WMI driver
+ * The vendor specific Fn keys arrive as WMI events owned by the Lenovo WMI
+ * Fn keys driver, which reports them as input events. Subscribe to act on the
+ * ones that touch the VPC state: the Fn lock LED and the performance mode
+ * button, which cycles the platform profile through DYTC instead of
+ * reporting a key.
  */
-enum ideapad_wmi_event_type {
-	IDEAPAD_WMI_EVENT_ESC,
-	IDEAPAD_WMI_EVENT_FN_KEYS,
-};
-
-struct ideapad_wmi_private {
-	enum ideapad_wmi_event_type event;
-};
-
-static int ideapad_wmi_probe(struct wmi_device *wdev, const void *context)
+static int ideapad_fn_keys_notify(struct notifier_block *nb, unsigned long event,
+				  void *data)
 {
-	struct ideapad_wmi_private *wpriv;
+	struct ideapad_private *priv = container_of(nb, struct ideapad_private, fn_keys_nb);
+	u32 code;
 
-	wpriv = devm_kzalloc_obj(&wdev->dev, *wpriv);
-	if (!wpriv)
-		return -ENOMEM;
-
-	*wpriv = *(const struct ideapad_wmi_private *)context;
-
-	dev_set_drvdata(&wdev->dev, wpriv);
-	return 0;
-}
-
-static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data)
-{
-	struct ideapad_wmi_private *wpriv = dev_get_drvdata(&wdev->dev);
-	struct ideapad_private *priv;
-
-	guard(mutex)(&ideapad_shared_mutex);
-
-	priv = ideapad_shared;
-	if (!priv)
-		return;
-
-	switch (wpriv->event) {
-	case IDEAPAD_WMI_EVENT_ESC:
-		ideapad_input_report(priv, 128);
+	switch (event) {
+	case LWMI_FN_KEYS_EVENT_ESC:
 		break;
-	case IDEAPAD_WMI_EVENT_FN_KEYS:
+	case LWMI_FN_KEYS_EVENT_FN_KEY:
 		if (priv->features.set_fn_lock_led) {
 			int brightness = ideapad_fn_lock_get(priv);
 
@@ -2349,72 +2264,44 @@ static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data)
 			}
 		}
 

drivers/platform/x86/lenovo/ideapad-laptop.c static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data) · line 2268

Quoted 10 lines
drivers/platform/x86/lenovo/ideapad-laptop.c +2 -8
-		if (data->type != ACPI_TYPE_INTEGER) {
-			dev_warn(&wdev->dev,
-				 "WMI event data is not an integer\n");
-			break;
-		}
-
-		dev_dbg(&wdev->dev, "WMI fn-key event: 0x%llx\n",
-			data->integer.value);
+		code = *(u32 *)data;
+		dev_dbg(&priv->platform_device->dev, "WMI fn-key event: 0x%x\n", code);

Let's drop the dev_dbg() as there is already a dev_dbg() in lwmi_fn_keys_notify().

With all these issues fixed:

Thanks,
Rong

Quoted 184 lines
drivers/platform/x86/lenovo/ideapad-laptop.c +32 -70
-		/* performance button triggered by 0x3d */
-		if (data->integer.value == 0x3d && priv->dytc) {
-			platform_profile_cycle();
+		switch (code) {
+		case 0x3d:
+			/* performance button */
+			if (priv->dytc) {
+				platform_profile_cycle();
+				return NOTIFY_STOP;
+			}
+			break;
+		case 0x02:
+		case 0x03:
+			/* 0x02 FnLock, 0x03 Esc */
+			ideapad_fn_lock_led_notify(priv, code == 0x02);
 			break;
 		}
-
-		/* 0x02 FnLock, 0x03 Esc */
-		if (data->integer.value == 0x02 || data->integer.value == 0x03)
-			ideapad_fn_lock_led_notify(priv, data->integer.value == 0x02);
-
-		ideapad_input_report(priv,
-				     data->integer.value | IDEAPAD_WMI_KEY);
-
 		break;
 	}
-}
 
-static const struct ideapad_wmi_private ideapad_wmi_context_esc = {
-	.event = IDEAPAD_WMI_EVENT_ESC
-};
-
-static const struct ideapad_wmi_private ideapad_wmi_context_fn_keys = {
-	.event = IDEAPAD_WMI_EVENT_FN_KEYS
-};
-
-static const struct wmi_device_id ideapad_wmi_ids[] = {
-	{ "26CAB2E5-5CF1-46AE-AAC3-4A12B6BA50E6", &ideapad_wmi_context_esc }, /* Yoga 3 */
-	{ "56322276-8493-4CE8-A783-98C991274F5E", &ideapad_wmi_context_esc }, /* Yoga 700 */
-	{ "8FC0DE0C-B4E4-43FD-B0F3-8871711C1294", &ideapad_wmi_context_fn_keys }, /* Legion 5 */
-	{},
-};
-MODULE_DEVICE_TABLE(wmi, ideapad_wmi_ids);
-
-static struct wmi_driver ideapad_wmi_driver = {
-	.driver = {
-		.name = "ideapad_wmi",
-	},
-	.id_table = ideapad_wmi_ids,
-	.min_event_size = sizeof(u32),
-	.probe = ideapad_wmi_probe,
-	.notify = ideapad_wmi_notify,
-};
+	return NOTIFY_OK;
+}
 
-static int ideapad_wmi_driver_register(void)
+static int ideapad_fn_keys_register(struct ideapad_private *priv)
 {
-	return wmi_driver_register(&ideapad_wmi_driver);
+	priv->fn_keys_nb.notifier_call = ideapad_fn_keys_notify;
+
+	return lwmi_fn_keys_register_notifier(&priv->fn_keys_nb);
 }
 
-static void ideapad_wmi_driver_unregister(void)
+static void ideapad_fn_keys_unregister(struct ideapad_private *priv)
 {
-	return wmi_driver_unregister(&ideapad_wmi_driver);
+	lwmi_fn_keys_unregister_notifier(&priv->fn_keys_nb);
 }
-
-#else
-static inline int ideapad_wmi_driver_register(void) { return 0; }
-static inline void ideapad_wmi_driver_unregister(void) { }
-#endif
+#else /* CONFIG_LENOVO_WMI_FN_KEYS */
+static inline int ideapad_fn_keys_register(struct ideapad_private *priv) { return 0; }
+static inline void ideapad_fn_keys_unregister(struct ideapad_private *priv) { }
+#endif /* CONFIG_LENOVO_WMI_FN_KEYS */
 
 /*
  * ACPI driver
@@ -2496,6 +2383,10 @@ static int ideapad_acpi_add(struct platform_device *pdev)
 			dev_info(&pdev->dev, "DYTC interface is not available\n");
 	}
 
+	err = ideapad_fn_keys_register(priv);
+	if (err)
+		dev_warn(&pdev->dev, "Could not subscribe to the WMI Fn key events: %d\n", err);
+
 	if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
 		err = ideapad_backlight_init(priv);
 		if (err && err != -ENODEV)
@@ -2527,6 +2418,7 @@ static int ideapad_acpi_add(struct platform_device *pdev)
 	ideapad_backlight_exit(priv);
 
 backlight_failed:
+	ideapad_fn_keys_unregister(priv);
 	ideapad_dytc_profile_exit(priv);
 
 	for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
@@ -2556,6 +2448,7 @@ static void ideapad_acpi_remove(struct platform_device *pdev)
 				   ideapad_acpi_notify);
 
 	ideapad_backlight_exit(priv);
+	ideapad_fn_keys_unregister(priv);
 	ideapad_dytc_profile_exit(priv);
 
 	for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
@@ -2600,31 +2493,9 @@ static struct platform_driver ideapad_acpi_driver = {
 	},
 };
 
-static int __init ideapad_laptop_init(void)
-{
-	int err;
-
-	err = ideapad_wmi_driver_register();
-	if (err)
-		return err;
-
-	err = platform_driver_register(&ideapad_acpi_driver);
-	if (err) {
-		ideapad_wmi_driver_unregister();
-		return err;
-	}
-
-	return 0;
-}
-module_init(ideapad_laptop_init)
-
-static void __exit ideapad_laptop_exit(void)
-{
-	platform_driver_unregister(&ideapad_acpi_driver);
-	ideapad_wmi_driver_unregister();
-}
-module_exit(ideapad_laptop_exit)
+module_platform_driver(ideapad_acpi_driver);
 
 MODULE_AUTHOR("David Woodhouse <[email protected]>");
 MODULE_DESCRIPTION("IdeaPad ACPI Extras");
+MODULE_IMPORT_NS("LENOVO_WMI_FN_KEYS");
 MODULE_LICENSE("GPL");
include/linux/platform_data/lenovo-wmi-fn-keys.h new file +32 -0
new file mode 100644
index 000000000000..4a737990b184
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Lenovo WMI Fn keys driver, notifier interface for drivers that want to act
+ * on the vendor specific Fn key events before a key is reported.
+ */
+
+#ifndef _LENOVO_WMI_FN_KEYS_H_
+#define _LENOVO_WMI_FN_KEYS_H_
+
+struct device;
+struct notifier_block;
+
+/**
+ * enum lwmi_fn_keys_event - notifier chain actions
+ * @LWMI_FN_KEYS_EVENT_ESC: Fn+Esc from one of the Esc event GUIDs, which
+ *                          carry no event data
+ * @LWMI_FN_KEYS_EVENT_FN_KEY: a key from the Fn key event GUID, the notifier
+ *                             data points to the u32 key code
+ *
+ * A callback that handles the event itself returns NOTIFY_STOP to suppress
+ * the input report; NOTIFY_OK or NOTIFY_DONE let it through.
+ */
+enum lwmi_fn_keys_event {
+	LWMI_FN_KEYS_EVENT_ESC,
+	LWMI_FN_KEYS_EVENT_FN_KEY,
+};
+
+int lwmi_fn_keys_register_notifier(struct notifier_block *nb);
+int lwmi_fn_keys_unregister_notifier(struct notifier_block *nb);
+int devm_lwmi_fn_keys_register_notifier(struct device *dev, struct notifier_block *nb);
+
+#endif /* _LENOVO_WMI_FN_KEYS_H_ */
#35 lore raw

Re: [PATCH v3 2/3] platform: lenovo: add WMI Fn keys driver and use it from ideapad-laptop

Hi David,

Quoted 437 lines · 于 2026年11月21日 GMT+08:00 18:42:04,Rong Zhang <[email protected]> 写道:

Hi David,

Thanks for your work.

Quoted 34 lines · David Cemin

Lenovo consumer laptops deliver their vendor specific Fn keys (microphone mute, airplane mode, performance mode, the star key and others) as WMI events on GUID 8FC0DE0C-B4E4-43FD-B0F3-8871711C1294, and the older Yoga models report Fn+Esc on two event GUIDs that carry no data. ideapad-laptop handles all of them today, but it is an x86 only driver built on the VPC ACPI device and the i8042 controller, and the new arm64 Lenovo laptops expose the Fn key GUID without any of that.

Add a Lenovo WMI Fn keys driver that owns the three event GUIDs on every architecture and reports the keys through a sparse keymap. The keymap, the scan codes (the Fn key codes offset by 0x100, Fn+Esc as
128) and the input device name are taken over from ideapad-laptop, so the events userspace sees do not change and the existing hwdb mappings keep applying. The one difference is 0x3d, which now reports KEY_PERFORMANCE instead of KEY_PROG4. A notifier chain lets drivers with platform knowledge act on an event before the key is reported and suppress it with NOTIFY_STOP.

Make ideapad-laptop drop its WMI event driver and keymap entries and subscribe to that notifier instead. The callback keeps the two platform specific behaviours: it refreshes the Fn lock LED from the EC on every Fn key event, and on the performance button it cycles the platform profile through DYTC and consumes the event, as before. The notifier is unregistered before the DYTC and LED teardown in remove() and on the probe error paths. Both changes land in one patch because with the new driver present but ideapad-laptop unchanged, both drivers would bind the same WMI devices.

ideapad-laptop implies LENOVO_WMI_FN_KEYS so that existing configurations keep the Fn keys on a config update, and uses IS_REACHABLE() to tolerate the driver being a module while ideapad-laptop is built in, in which case the keys are still reported by the Fn keys driver and only the VPC specific handling is lost.

Quoted 6 lines

Tested on a Lenovo Yoga 9 2-in-1 16 (arm64): microphone mute, airplane mode, the Smart Key, the Smart Connect key and the Fn+Q performance key report input events. The Esc event GUIDs are not exposed by that firmware, so that path is compile tested only, as is ideapad-laptop.

The patch now looks quite good to me, except for some minor issues. See below.

Quoted 131 lines
---
 MAINTAINERS                                   |   8 +
 drivers/platform/lenovo/Kconfig               |  15 +
 drivers/platform/lenovo/Makefile              |   1 +
 drivers/platform/lenovo/wmi-fn-keys.c         | 280 ++++++++++++++++++
 drivers/platform/x86/lenovo/Kconfig           |   2 +-
 drivers/platform/x86/lenovo/ideapad-laptop.c  | 227 +++-----------
 .../linux/platform_data/lenovo-wmi-fn-keys.h  |  32 ++
 7 files changed, 386 insertions(+), 179 deletions(-)
 create mode 100644 drivers/platform/lenovo/wmi-fn-keys.c
 create mode 100644 include/linux/platform_data/lenovo-wmi-fn-keys.h
MAINTAINERS +8 -0
index 3b0ad5a3debe..e2be0b7debeb 100644
@@ -15173,6 +15173,14 @@ F:	Documentation/wmi/devices/lenovo-wmi-other.rst
 F:	drivers/platform/lenovo/
 F:	drivers/platform/x86/lenovo/*
 
+LENOVO WMI FN KEYS DRIVER
+M:	David Cemin <[email protected]>
+M:	Rong Zhang <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/platform/lenovo/wmi-fn-keys.c
+F:	include/linux/platform_data/lenovo-wmi-fn-keys.h
+
 LENOVO WMI HOTKEY UTILITIES DRIVER
 M:	Jackie Dong <[email protected]>
 L:	[email protected]
drivers/platform/lenovo/Kconfig +15 -0
index 8222322ca671..f67f7c811214 100644
@@ -41,6 +41,21 @@ config LENOVO_WMI_HOTKEY_UTILITIES
 	  such as LED control for audio/mic mute event for Ideapad, YOGA, XiaoXin,
 	  Gaming, ThinkBook and so on.
 
+config LENOVO_WMI_FN_KEYS
+	tristate "Lenovo WMI Fn keys driver"
+	depends on ACPI_WMI
+	depends on INPUT
+	select INPUT_SPARSEKMAP
+	help
+	  Say Y or M here to enable the vendor specific Fn keys (microphone
+	  mute, airplane mode, performance mode, star key, Fn+Esc, etc.) on
+	  Lenovo laptops that deliver them as WMI events. ideapad-laptop
+	  subscribes to this driver for its Fn lock LED and performance mode
+	  handling.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called lenovo-wmi-fn-keys.
+
 config LENOVO_WMI_CAMERA
 	tristate "Lenovo WMI Camera Button driver"
 	depends on ACPI_WMI
drivers/platform/lenovo/Makefile +1 -0
index 1cac115dd735..8ea207e79a43 100644
@@ -8,6 +8,7 @@ lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS)	+= wmi-helpers.o
 lenovo-target-$(CONFIG_LENOVO_WMI_EVENTS)	+= wmi-events.o
 lenovo-target-$(CONFIG_LENOVO_WMI_CAPDATA)	+= wmi-capdata.o
 lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES)	+= wmi-hotkey-utilities.o
+lenovo-target-$(CONFIG_LENOVO_WMI_FN_KEYS)	+= wmi-fn-keys.o
 lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA)	+= wmi-camera.o
 lenovo-target-$(CONFIG_LENOVO_WMI_GAMEZONE)	+= wmi-gamezone.o
 lenovo-target-$(CONFIG_LENOVO_WMI_TUNING)	+= wmi-other.o
drivers/platform/lenovo/wmi-fn-keys.c new file +56 -0
new file mode 100644
index 000000000000..330de9529a87
@@ -0,0 +1,280 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Lenovo WMI Fn keys driver
+ *
+ * Lenovo consumer laptops deliver their vendor specific Fn keys (microphone
+ * mute, airplane mode, performance mode, the star key and others) as WMI
+ * events on a dedicated GUID instead of keyboard usages, and the older Yoga
+ * models report Fn+Esc on two event GUIDs that carry no data. This driver
+ * owns these event GUIDs on every architecture and reports the keys through
+ * a sparse keymap. Drivers with platform knowledge, such as ideapad-laptop,
+ * subscribe to the notifier chain to act on an event and may stop the key
+ * from being reported.
+ *
+ * The keymap and the scan codes were moved here from ideapad-laptop, so the
+ * input events are the same as before for userspace.
+ */
+
+#include <linux/device.h>
+#include <linux/export.h>
+#include <linux/input.h>
+#include <linux/input/sparse-keymap.h>
+#include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/platform_data/lenovo-wmi-fn-keys.h>
+#include <linux/types.h>
+#include <linux/wmi.h>
+
+#include <asm/byteorder.h>
+
+#define LWMI_FN_KEYS_GUID	"8FC0DE0C-B4E4-43FD-B0F3-8871711C1294"
+#define LWMI_ESC_GUID_YOGA3	"26CAB2E5-5CF1-46AE-AAC3-4A12B6BA50E6"
+#define LWMI_ESC_GUID_YOGA700	"56322276-8493-4CE8-A783-98C991274F5E"
+
+/*
+ * Scan codes as ideapad-laptop reported them: the Fn key event codes are
+ * offset by LWMI_FN_KEY so they do not collide with the ACPI hotkeys of that
+ * driver, and the Fn+Esc events, which carry no data, use scan code 128.
+ */
+#define LWMI_FN_KEY		0x100
+#define LWMI_ESC_SCANCODE	128
+
+/**
+ * struct lwmi_fn_keys_info - per event GUID description
+ * @event: event type passed to the notifier chain
+ * @phys: physical path of the input device
+ * @event_size: size of the WMI event data, 0 when the GUID carries none
+ * @code: scan code base: the offset added to the event data, or the whole
+ *        scan code for GUIDs without event data
+ * @keymap: sparse keymap for the input device
+ */
+struct lwmi_fn_keys_info {
+	enum lwmi_fn_keys_event event;
+	const char *phys;
+	size_t event_size;
+	u32 code;
+	const struct key_entry *keymap;

drivers/platform/lenovo/wmi-fn-keys.c line 66

Quoted 10 lines
drivers/platform/lenovo/wmi-fn-keys.c new file +10 -0
+};
+
+struct lwmi_fn_keys {
+	struct input_dev *input;
+	const struct lwmi_fn_keys_info *info;
+};
+
+static BLOCKING_NOTIFIER_HEAD(lwmi_fn_keys_chain);
+
+static const struct key_entry lwmi_fn_keys_keymap[] = {

Let's add a separator here, like:

   /*
    * WMI ignored events
    */

drivers/platform/lenovo/wmi-fn-keys.c line 70

Quoted 4 lines
drivers/platform/lenovo/wmi-fn-keys.c new file +4 -0
+	/* FnLock (handled by the firmware) */
+	{ KE_IGNORE,	0x02 | LWMI_FN_KEY },
+	/* Esc (handled by the firmware) */
+	{ KE_IGNORE,	0x03 | LWMI_FN_KEY },

Ditto, like ideapad-laptop originally did:

   /*
    * WMI keys
    */
Quoted 215 lines
drivers/platform/lenovo/wmi-fn-keys.c new file +210 -0
+
+	/* Customizable Lenovo Hotkey ("star" with 'S' inside) */
+	{ KE_KEY,	0x01 | LWMI_FN_KEY, { KEY_FAVORITES } },
+	{ KE_KEY,	0x04 | LWMI_FN_KEY, { KEY_SELECTIVE_SCREENSHOT } },
+	/* Lenovo Support */
+	{ KE_KEY,	0x07 | LWMI_FN_KEY, { KEY_HELP } },
+	{ KE_KEY,	0x0e | LWMI_FN_KEY, { KEY_PICKUP_PHONE } },
+	{ KE_KEY,	0x0f | LWMI_FN_KEY, { KEY_HANGUP_PHONE } },
+	/* Refresh Rate Toggle (Fn+R) */
+	{ KE_KEY,	0x10 | LWMI_FN_KEY, { KEY_REFRESH_RATE_TOGGLE } },
+	/* Dark mode toggle */
+	{ KE_KEY,	0x13 | LWMI_FN_KEY, { KEY_PROG1 } },
+	/* Sound profile switch */
+	{ KE_KEY,	0x12 | LWMI_FN_KEY, { KEY_PROG2 } },
+	/* Lenovo Virtual Background application */
+	{ KE_KEY,	0x28 | LWMI_FN_KEY, { KEY_PROG3 } },
+	/* Lenovo Support */
+	{ KE_KEY,	0x27 | LWMI_FN_KEY, { KEY_HELP } },
+	/* Refresh Rate Toggle */
+	{ KE_KEY,	0x0a | LWMI_FN_KEY, { KEY_REFRESH_RATE_TOGGLE } },
+	/* Specific to some newer models */
+	{ KE_KEY,	0x3e | LWMI_FN_KEY, { KEY_MICMUTE } },
+	{ KE_KEY,	0x3f | LWMI_FN_KEY, { KEY_RFKILL } },
+	/* Star- (User Assignable Key) */
+	{ KE_KEY,	0x44 | LWMI_FN_KEY, { KEY_PROG1 } },
+	/* Eye */
+	{ KE_KEY,	0x45 | LWMI_FN_KEY, { KEY_PROG3 } },
+	/* Lenovo Smart Connect */
+	{ KE_KEY,	0x48 | LWMI_FN_KEY, { KEY_LINK_PHONE } },
+	/*
+	 * Performance toggle also Fn+Q, consumed by ideapad-laptop through the
+	 * notifier chain on machines where it cycles the platform profile
+	 */
+	{ KE_KEY,	0x3d | LWMI_FN_KEY, { KEY_PERFORMANCE } },
+	/* Mode, opens a profile chooser; the Fn+Q button cycles the profile */
+	{ KE_KEY,	0x46 | LWMI_FN_KEY, { KEY_PROG4 } },
+	/* shift + prtsc */
+	{ KE_KEY,	0x2d | LWMI_FN_KEY, { KEY_SELECTIVE_SCREENSHOT } },
+	{ KE_KEY,	0x29 | LWMI_FN_KEY, { KEY_TOUCHPAD_TOGGLE } },
+	{ KE_KEY,	0x2a | LWMI_FN_KEY, { KEY_ROOT_MENU } },
+
+	/*
+	 * WMI switches
+	 *
+	 * Some devices come with physical switches. Whenever a switch is
+	 * toggled, an WMI event is emitted to inform the software about the
+	 * switch's latest state.
+	 */
+
+	/* Camera switch */
+	{ KE_SW,	0x0c | LWMI_FN_KEY, .sw = { SW_CAMERA_LENS_COVER, 0 } },
+	{ KE_SW,	0x0d | LWMI_FN_KEY, .sw = { SW_CAMERA_LENS_COVER, 1 } },
+
+	{ KE_END }
+};
+
+static const struct key_entry lwmi_esc_keymap[] = {
+	{ KE_KEY,	LWMI_ESC_SCANCODE, { KEY_ESC } },
+	{ KE_END }
+};
+
+static const struct lwmi_fn_keys_info lwmi_fn_keys_info_fn_keys = {
+	.event = LWMI_FN_KEYS_EVENT_FN_KEY,
+	.phys = "wmi/input0",
+	.event_size = sizeof(u32),
+	.code = LWMI_FN_KEY,
+	.keymap = lwmi_fn_keys_keymap,
+};
+
+static const struct lwmi_fn_keys_info lwmi_fn_keys_info_esc = {
+	.event = LWMI_FN_KEYS_EVENT_ESC,
+	.phys = "wmi/input1",
+	.code = LWMI_ESC_SCANCODE,
+	.keymap = lwmi_esc_keymap,
+};
+
+/**
+ * lwmi_fn_keys_register_notifier() - Subscribe to the Fn key events.
+ * @nb: The notifier_block to register.
+ *
+ * The callback runs in process context with the &enum lwmi_fn_keys_event as
+ * the action and, for LWMI_FN_KEYS_EVENT_FN_KEY, a pointer to the u32 key
+ * code as the data. Return NOTIFY_STOP from the callback to consume the event
+ * so that no key is reported.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int lwmi_fn_keys_register_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_register(&lwmi_fn_keys_chain, nb);
+}
+EXPORT_SYMBOL_NS_GPL(lwmi_fn_keys_register_notifier, "LENOVO_WMI_FN_KEYS");
+
+/**
+ * lwmi_fn_keys_unregister_notifier() - Unsubscribe from the Fn key events.
+ * @nb: The notifier_block to unregister.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int lwmi_fn_keys_unregister_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_unregister(&lwmi_fn_keys_chain, nb);
+}
+EXPORT_SYMBOL_NS_GPL(lwmi_fn_keys_unregister_notifier, "LENOVO_WMI_FN_KEYS");
+
+static void devm_lwmi_fn_keys_unregister_notifier(void *data)
+{
+	lwmi_fn_keys_unregister_notifier(data);
+}
+
+/**
+ * devm_lwmi_fn_keys_register_notifier() - Device managed subscription.
+ * @dev: The device whose lifetime bounds the subscription.
+ * @nb: The notifier_block to register.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int devm_lwmi_fn_keys_register_notifier(struct device *dev, struct notifier_block *nb)
+{
+	int ret;
+
+	ret = lwmi_fn_keys_register_notifier(nb);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, devm_lwmi_fn_keys_unregister_notifier, nb);
+}
+EXPORT_SYMBOL_NS_GPL(devm_lwmi_fn_keys_register_notifier, "LENOVO_WMI_FN_KEYS");
+
+static int lwmi_fn_keys_probe(struct wmi_device *wdev, const void *context)
+{
+	struct lwmi_fn_keys *priv;
+	int ret;
+
+	priv = devm_kzalloc_obj(&wdev->dev, *priv);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->info = context;
+
+	priv->input = devm_input_allocate_device(&wdev->dev);
+	if (!priv->input)
+		return -ENOMEM;
+
+	/*
+	 * Same name as the ideapad-laptop input device so that the existing
+	 * hwdb keyboard mappings for these keys keep applying.
+	 */
+	priv->input->name = "Ideapad extra buttons";
+	priv->input->phys = priv->info->phys;
+	priv->input->id.bustype = BUS_HOST;
+	priv->input->dev.parent = &wdev->dev;
+
+	ret = sparse_keymap_setup(priv->input, priv->info->keymap, NULL);
+	if (ret)
+		return ret;
+
+	dev_set_drvdata(&wdev->dev, priv);
+
+	return input_register_device(priv->input);
+}
+
+static void lwmi_fn_keys_notify(struct wmi_device *wdev, const struct wmi_buffer *buf)
+{
+	struct lwmi_fn_keys *priv = dev_get_drvdata(&wdev->dev);
+	const struct lwmi_fn_keys_info *info = priv->info;
+	u32 code = 0;
+	int ret;
+
+	if (buf->length < info->event_size) {
+		dev_dbg(&wdev->dev, "short event (%zu bytes)\n", buf->length);
+		return;
+	}
+
+	if (info->event_size)
+		code = le32_to_cpup(buf->data);
+
+	dev_dbg(&wdev->dev, "event %d code 0x%x\n", info->event, code);
+
+	ret = blocking_notifier_call_chain(&lwmi_fn_keys_chain, info->event, &code);
+	if (ret & NOTIFY_STOP_MASK)
+		return;
+
+	if (!sparse_keymap_report_event(priv->input, info->code | code, 1, true))
+		dev_info_ratelimited(&wdev->dev, "unknown key code 0x%x\n", code);
+}
+
+static const struct wmi_device_id lwmi_fn_keys_id_table[] = {
+	{ LWMI_FN_KEYS_GUID, &lwmi_fn_keys_info_fn_keys },
+	{ LWMI_ESC_GUID_YOGA3, &lwmi_fn_keys_info_esc },
+	{ LWMI_ESC_GUID_YOGA700, &lwmi_fn_keys_info_esc },
+	{ }
+};
+MODULE_DEVICE_TABLE(wmi, lwmi_fn_keys_id_table);
+
+static struct wmi_driver lwmi_fn_keys_driver = {
+	.driver = {
+		.name = "lenovo-wmi-fn-keys",
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+	},
+	.id_table = lwmi_fn_keys_id_table,
+	.probe = lwmi_fn_keys_probe,
+	.notify_new = lwmi_fn_keys_notify,
+	.no_singleton = true,
+};
+module_wmi_driver(lwmi_fn_keys_driver);
+
+MODULE_AUTHOR("David Cemin <[email protected]>");
+MODULE_DESCRIPTION("Lenovo WMI Fn keys driver");
+MODULE_LICENSE("GPL");
drivers/platform/x86/lenovo/Kconfig +0 -0
index 4d9a25d0e3b5..8a11c981241c 100644

drivers/platform/x86/lenovo/Kconfig config IDEAPAD_LAPTOP · line 14

Quoted 5 lines
drivers/platform/x86/lenovo/Kconfig +1 -1
@@ -11,7 +11,7 @@ config IDEAPAD_LAPTOP
 	depends on SERIO_I8042
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on ACPI_VIDEO || ACPI_VIDEO = n
-	depends on ACPI_WMI || ACPI_WMI = n
+	imply LENOVO_WMI_FN_KEYS

Unconditionally implying LENOVO_WMI_FN_KEYS is broken. See Documentation/kbuild/kconfig-language.rst:

select should be used with care. select will force a symbol to a value without visiting the dependencies. By abusing select you are able to select a symbol FOO even if FOO depends on BAR that is not set.

Quoted 8 lines

(which also applies to `imply')

In general, you can only select or imply a symbol when you've collected all its dependencies. That's why I suggested

imply LENOVO_WMI_FN_KEYS if ACPI_WMI

in my previous reply.

Please ignore this. I must have lost my mind when I wrote this. Sorry for the confusion.

Other suggestions still apply.

Thanks,
Rong

Quoted 372 lines
Quoted 167 lines
drivers/platform/x86/lenovo/Kconfig +0 -0
 	select ACPI_PLATFORM_PROFILE
 	select INPUT_SPARSEKMAP
 	select NEW_LEDS
drivers/platform/x86/lenovo/ideapad-laptop.c +15 -100
index f9453de6df76..92d05470dee9 100644
@@ -34,7 +34,7 @@
 #include <linux/string_choices.h>
 #include <linux/sysfs.h>
 #include <linux/types.h>
-#include <linux/wmi.h>
+#include <linux/platform_data/lenovo-wmi-fn-keys.h>
 #include "ideapad-laptop.h"
 
 #include <acpi/battery.h>
@@ -185,6 +185,7 @@ struct ideapad_private {
 	struct input_dev *inputdev;
 	struct backlight_device *blightdev;
 	struct ideapad_dytc_priv *dytc;
+	struct notifier_block fn_keys_nb;
 	struct dentry *debug;
 	struct acpi_battery_hook battery_hook;
 	const struct power_supply_ext *battery_ext;
@@ -1317,8 +1318,6 @@ static void ideapad_unregister_rfkill(struct ideapad_private *priv, int dev)
 /*
  * input device
  */
-#define IDEAPAD_WMI_KEY 0x100
-
 static const struct key_entry ideapad_keymap[] = {
 	{ KE_KEY,   6, { KEY_SWITCHVIDEOMODE } },
 	{ KE_KEY,   7, { KEY_CAMERA } },
@@ -1331,65 +1330,6 @@ static const struct key_entry ideapad_keymap[] = {
 	{ KE_KEY,  65, { KEY_PROG4 } },
 	{ KE_KEY,  66, { KEY_TOUCHPAD_OFF } },
 	{ KE_KEY,  67, { KEY_TOUCHPAD_ON } },
-	{ KE_KEY, 128, { KEY_ESC } },
-
-	/*
-	 * WMI keys
-	 */
-
-	/* FnLock (handled by the firmware) */
-	{ KE_IGNORE,	0x02 | IDEAPAD_WMI_KEY },
-	/* Esc (handled by the firmware) */
-	{ KE_IGNORE,	0x03 | IDEAPAD_WMI_KEY },
-	/* Customizable Lenovo Hotkey ("star" with 'S' inside) */
-	{ KE_KEY,	0x01 | IDEAPAD_WMI_KEY, { KEY_FAVORITES } },
-	{ KE_KEY,	0x04 | IDEAPAD_WMI_KEY, { KEY_SELECTIVE_SCREENSHOT } },
-	/* Lenovo Support */
-	{ KE_KEY,	0x07 | IDEAPAD_WMI_KEY, { KEY_HELP } },
-	{ KE_KEY,	0x0e | IDEAPAD_WMI_KEY, { KEY_PICKUP_PHONE } },
-	{ KE_KEY,	0x0f | IDEAPAD_WMI_KEY, { KEY_HANGUP_PHONE } },
-	/* Refresh Rate Toggle (Fn+R) */
-	{ KE_KEY,	0x10 | IDEAPAD_WMI_KEY, { KEY_REFRESH_RATE_TOGGLE } },
-	/* Dark mode toggle */
-	{ KE_KEY,	0x13 | IDEAPAD_WMI_KEY, { KEY_PROG1 } },
-	/* Sound profile switch */
-	{ KE_KEY,	0x12 | IDEAPAD_WMI_KEY, { KEY_PROG2 } },
-	/* Lenovo Virtual Background application */
-	{ KE_KEY,	0x28 | IDEAPAD_WMI_KEY, { KEY_PROG3 } },
-	/* Lenovo Support */
-	{ KE_KEY,	0x27 | IDEAPAD_WMI_KEY, { KEY_HELP } },
-	/* Refresh Rate Toggle */
-	{ KE_KEY,	0x0a | IDEAPAD_WMI_KEY, { KEY_REFRESH_RATE_TOGGLE } },
-	/* Specific to some newer models */
-	{ KE_KEY,	0x3e | IDEAPAD_WMI_KEY, { KEY_MICMUTE } },
-	{ KE_KEY,	0x3f | IDEAPAD_WMI_KEY, { KEY_RFKILL } },
-	/* Star- (User Assignable Key) */
-	{ KE_KEY,	0x44 | IDEAPAD_WMI_KEY, { KEY_PROG1 } },
-	/* Eye */
-	{ KE_KEY,	0x45 | IDEAPAD_WMI_KEY, { KEY_PROG3 } },
-	/* Lenovo Smart Connect */
-	{ KE_KEY,	0x48 | IDEAPAD_WMI_KEY, { KEY_LINK_PHONE } },
-	/* Performance toggle also Fn+Q, handled inside ideapad_wmi_notify() */
-	{ KE_KEY,	0x3d | IDEAPAD_WMI_KEY, { KEY_PROG4 } },
-	/* Mode, opens a profile chooser; the Fn+Q button cycles the profile */
-	{ KE_KEY,	0x46 | IDEAPAD_WMI_KEY, { KEY_PROG4 } },
-	/* shift + prtsc */
-	{ KE_KEY,   0x2d | IDEAPAD_WMI_KEY, { KEY_SELECTIVE_SCREENSHOT } },
-	{ KE_KEY,   0x29 | IDEAPAD_WMI_KEY, { KEY_TOUCHPAD_TOGGLE } },
-	{ KE_KEY,   0x2a | IDEAPAD_WMI_KEY, { KEY_ROOT_MENU } },
-
-	/*
-	 * WMI switches
-	 *
-	 * Some devices come with physical switches. Whenever a switch is
-	 * toggled, an WMI event is emitted to inform the software about the
-	 * switch's latest state.
-	 */
-
-	/* Camera switch */
-	{ KE_SW,	0x0c | IDEAPAD_WMI_KEY, .sw = { SW_CAMERA_LENS_COVER, 0 } },
-	{ KE_SW,	0x0d | IDEAPAD_WMI_KEY, .sw = { SW_CAMERA_LENS_COVER, 1 } },
-
 	{ KE_END },
 };
 
@@ -2297,49 +2237,24 @@ static int ideapad_check_features(struct ideapad_private *priv)
 	return 0;
 }
 
-#if IS_ENABLED(CONFIG_ACPI_WMI)
+#if IS_REACHABLE(CONFIG_LENOVO_WMI_FN_KEYS)
 /*
- * WMI driver
+ * The vendor specific Fn keys arrive as WMI events owned by the Lenovo WMI
+ * Fn keys driver, which reports them as input events. Subscribe to act on the
+ * ones that touch the VPC state: the Fn lock LED and the performance mode
+ * button, which cycles the platform profile through DYTC instead of
+ * reporting a key.
  */
-enum ideapad_wmi_event_type {
-	IDEAPAD_WMI_EVENT_ESC,
-	IDEAPAD_WMI_EVENT_FN_KEYS,
-};
-
-struct ideapad_wmi_private {
-	enum ideapad_wmi_event_type event;
-};
-
-static int ideapad_wmi_probe(struct wmi_device *wdev, const void *context)
+static int ideapad_fn_keys_notify(struct notifier_block *nb, unsigned long event,
+				  void *data)
 {
-	struct ideapad_wmi_private *wpriv;
+	struct ideapad_private *priv = container_of(nb, struct ideapad_private, fn_keys_nb);
+	u32 code;
 
-	wpriv = devm_kzalloc_obj(&wdev->dev, *wpriv);
-	if (!wpriv)
-		return -ENOMEM;
-
-	*wpriv = *(const struct ideapad_wmi_private *)context;
-
-	dev_set_drvdata(&wdev->dev, wpriv);
-	return 0;
-}
-
-static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data)
-{
-	struct ideapad_wmi_private *wpriv = dev_get_drvdata(&wdev->dev);
-	struct ideapad_private *priv;
-
-	guard(mutex)(&ideapad_shared_mutex);
-
-	priv = ideapad_shared;
-	if (!priv)
-		return;
-
-	switch (wpriv->event) {
-	case IDEAPAD_WMI_EVENT_ESC:
-		ideapad_input_report(priv, 128);
+	switch (event) {
+	case LWMI_FN_KEYS_EVENT_ESC:
 		break;
-	case IDEAPAD_WMI_EVENT_FN_KEYS:
+	case LWMI_FN_KEYS_EVENT_FN_KEY:
 		if (priv->features.set_fn_lock_led) {
 			int brightness = ideapad_fn_lock_get(priv);
 
@@ -2349,72 +2264,44 @@ static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data)
 			}
 		}
 

drivers/platform/x86/lenovo/ideapad-laptop.c static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data) · line 2268

Quoted 10 lines
drivers/platform/x86/lenovo/ideapad-laptop.c +2 -8
-		if (data->type != ACPI_TYPE_INTEGER) {
-			dev_warn(&wdev->dev,
-				 "WMI event data is not an integer\n");
-			break;
-		}
-
-		dev_dbg(&wdev->dev, "WMI fn-key event: 0x%llx\n",
-			data->integer.value);
+		code = *(u32 *)data;
+		dev_dbg(&priv->platform_device->dev, "WMI fn-key event: 0x%x\n", code);

Let's drop the dev_dbg() as there is already a dev_dbg() in lwmi_fn_keys_notify().

With all these issues fixed:

Thanks,
Rong

Quoted 184 lines
drivers/platform/x86/lenovo/ideapad-laptop.c +32 -70
-		/* performance button triggered by 0x3d */
-		if (data->integer.value == 0x3d && priv->dytc) {
-			platform_profile_cycle();
+		switch (code) {
+		case 0x3d:
+			/* performance button */
+			if (priv->dytc) {
+				platform_profile_cycle();
+				return NOTIFY_STOP;
+			}
+			break;
+		case 0x02:
+		case 0x03:
+			/* 0x02 FnLock, 0x03 Esc */
+			ideapad_fn_lock_led_notify(priv, code == 0x02);
 			break;
 		}
-
-		/* 0x02 FnLock, 0x03 Esc */
-		if (data->integer.value == 0x02 || data->integer.value == 0x03)
-			ideapad_fn_lock_led_notify(priv, data->integer.value == 0x02);
-
-		ideapad_input_report(priv,
-				     data->integer.value | IDEAPAD_WMI_KEY);
-
 		break;
 	}
-}
 
-static const struct ideapad_wmi_private ideapad_wmi_context_esc = {
-	.event = IDEAPAD_WMI_EVENT_ESC
-};
-
-static const struct ideapad_wmi_private ideapad_wmi_context_fn_keys = {
-	.event = IDEAPAD_WMI_EVENT_FN_KEYS
-};
-
-static const struct wmi_device_id ideapad_wmi_ids[] = {
-	{ "26CAB2E5-5CF1-46AE-AAC3-4A12B6BA50E6", &ideapad_wmi_context_esc }, /* Yoga 3 */
-	{ "56322276-8493-4CE8-A783-98C991274F5E", &ideapad_wmi_context_esc }, /* Yoga 700 */
-	{ "8FC0DE0C-B4E4-43FD-B0F3-8871711C1294", &ideapad_wmi_context_fn_keys }, /* Legion 5 */
-	{},
-};
-MODULE_DEVICE_TABLE(wmi, ideapad_wmi_ids);
-
-static struct wmi_driver ideapad_wmi_driver = {
-	.driver = {
-		.name = "ideapad_wmi",
-	},
-	.id_table = ideapad_wmi_ids,
-	.min_event_size = sizeof(u32),
-	.probe = ideapad_wmi_probe,
-	.notify = ideapad_wmi_notify,
-};
+	return NOTIFY_OK;
+}
 
-static int ideapad_wmi_driver_register(void)
+static int ideapad_fn_keys_register(struct ideapad_private *priv)
 {
-	return wmi_driver_register(&ideapad_wmi_driver);
+	priv->fn_keys_nb.notifier_call = ideapad_fn_keys_notify;
+
+	return lwmi_fn_keys_register_notifier(&priv->fn_keys_nb);
 }
 
-static void ideapad_wmi_driver_unregister(void)
+static void ideapad_fn_keys_unregister(struct ideapad_private *priv)
 {
-	return wmi_driver_unregister(&ideapad_wmi_driver);
+	lwmi_fn_keys_unregister_notifier(&priv->fn_keys_nb);
 }
-
-#else
-static inline int ideapad_wmi_driver_register(void) { return 0; }
-static inline void ideapad_wmi_driver_unregister(void) { }
-#endif
+#else /* CONFIG_LENOVO_WMI_FN_KEYS */
+static inline int ideapad_fn_keys_register(struct ideapad_private *priv) { return 0; }
+static inline void ideapad_fn_keys_unregister(struct ideapad_private *priv) { }
+#endif /* CONFIG_LENOVO_WMI_FN_KEYS */
 
 /*
  * ACPI driver
@@ -2496,6 +2383,10 @@ static int ideapad_acpi_add(struct platform_device *pdev)
 			dev_info(&pdev->dev, "DYTC interface is not available\n");
 	}
 
+	err = ideapad_fn_keys_register(priv);
+	if (err)
+		dev_warn(&pdev->dev, "Could not subscribe to the WMI Fn key events: %d\n", err);
+
 	if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
 		err = ideapad_backlight_init(priv);
 		if (err && err != -ENODEV)
@@ -2527,6 +2418,7 @@ static int ideapad_acpi_add(struct platform_device *pdev)
 	ideapad_backlight_exit(priv);
 
 backlight_failed:
+	ideapad_fn_keys_unregister(priv);
 	ideapad_dytc_profile_exit(priv);
 
 	for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
@@ -2556,6 +2448,7 @@ static void ideapad_acpi_remove(struct platform_device *pdev)
 				   ideapad_acpi_notify);
 
 	ideapad_backlight_exit(priv);
+	ideapad_fn_keys_unregister(priv);
 	ideapad_dytc_profile_exit(priv);
 
 	for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
@@ -2600,31 +2493,9 @@ static struct platform_driver ideapad_acpi_driver = {
 	},
 };
 
-static int __init ideapad_laptop_init(void)
-{
-	int err;
-
-	err = ideapad_wmi_driver_register();
-	if (err)
-		return err;
-
-	err = platform_driver_register(&ideapad_acpi_driver);
-	if (err) {
-		ideapad_wmi_driver_unregister();
-		return err;
-	}
-
-	return 0;
-}
-module_init(ideapad_laptop_init)
-
-static void __exit ideapad_laptop_exit(void)
-{
-	platform_driver_unregister(&ideapad_acpi_driver);
-	ideapad_wmi_driver_unregister();
-}
-module_exit(ideapad_laptop_exit)
+module_platform_driver(ideapad_acpi_driver);
 
 MODULE_AUTHOR("David Woodhouse <[email protected]>");
 MODULE_DESCRIPTION("IdeaPad ACPI Extras");
+MODULE_IMPORT_NS("LENOVO_WMI_FN_KEYS");
 MODULE_LICENSE("GPL");
include/linux/platform_data/lenovo-wmi-fn-keys.h new file +32 -0
new file mode 100644
index 000000000000..4a737990b184
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Lenovo WMI Fn keys driver, notifier interface for drivers that want to act
+ * on the vendor specific Fn key events before a key is reported.
+ */
+
+#ifndef _LENOVO_WMI_FN_KEYS_H_
+#define _LENOVO_WMI_FN_KEYS_H_
+
+struct device;
+struct notifier_block;
+
+/**
+ * enum lwmi_fn_keys_event - notifier chain actions
+ * @LWMI_FN_KEYS_EVENT_ESC: Fn+Esc from one of the Esc event GUIDs, which
+ *                          carry no event data
+ * @LWMI_FN_KEYS_EVENT_FN_KEY: a key from the Fn key event GUID, the notifier
+ *                             data points to the u32 key code
+ *
+ * A callback that handles the event itself returns NOTIFY_STOP to suppress
+ * the input report; NOTIFY_OK or NOTIFY_DONE let it through.
+ */
+enum lwmi_fn_keys_event {
+	LWMI_FN_KEYS_EVENT_ESC,
+	LWMI_FN_KEYS_EVENT_FN_KEY,
+};
+
+int lwmi_fn_keys_register_notifier(struct notifier_block *nb);
+int lwmi_fn_keys_unregister_notifier(struct notifier_block *nb);
+int devm_lwmi_fn_keys_register_notifier(struct device *dev, struct notifier_block *nb);
+
+#endif /* _LENOVO_WMI_FN_KEYS_H_ */
#36 lore raw

PATCH v3 3/3 platform: lenovo: wmi-fn-keys: ignore the keyboard backlight level events

In reply to David Cemin

The Yoga 9 2-in-1 16 reports the keyboard backlight level selected with Fn+Space on the Fn key event GUID: 0x40 for off, 0x41 for low, 0x42 for high, and 0x43 was seen once while cycling. The firmware changes the backlight itself, so these events carry no action for the OS; add them as KE_IGNORE entries so they stop being logged as unknown key codes.

---
 drivers/platform/lenovo/wmi-fn-keys.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/platform/lenovo/wmi-fn-keys.c +8 -0
index 330de9529a87..21d36e798ba5 100644
@@ -108,6 +108,14 @@ static const struct key_entry lwmi_fn_keys_keymap[] = {
 	{ KE_KEY,	0x2d | LWMI_FN_KEY, { KEY_SELECTIVE_SCREENSHOT } },
 	{ KE_KEY,	0x29 | LWMI_FN_KEY, { KEY_TOUCHPAD_TOGGLE } },
 	{ KE_KEY,	0x2a | LWMI_FN_KEY, { KEY_ROOT_MENU } },
+	/*
+	 * Keyboard backlight level after Fn+Space, handled by the firmware:
+	 * 0x40 off, 0x41 low, 0x42 high
+	 */
+	{ KE_IGNORE,	0x40 | LWMI_FN_KEY },
+	{ KE_IGNORE,	0x41 | LWMI_FN_KEY },
+	{ KE_IGNORE,	0x42 | LWMI_FN_KEY },
+	{ KE_IGNORE,	0x43 | LWMI_FN_KEY },
 
 	/*
 	 * WMI switches
Signature · 1 line
2.56.1
Reviewed-by on v3 3/3
#37 lore raw

Re: [PATCH v3 3/3] platform: lenovo: wmi-fn-keys: ignore the keyboard backlight level events

Hi David,

Thanks for your work.

Quoted 17 lines · David Cemin

The Yoga 9 2-in-1 16 reports the keyboard backlight level selected with Fn+Space on the Fn key event GUID: 0x40 for off, 0x41 for low, 0x42 for high, and 0x43 was seen once while cycling. The firmware changes the backlight itself, so these events carry no action for the OS; add them as KE_IGNORE entries so they stop being logged as unknown key codes.

---
 drivers/platform/lenovo/wmi-fn-keys.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/platform/lenovo/wmi-fn-keys.c +0 -0
index 330de9529a87..21d36e798ba5 100644
@@ -108,6 +108,14 @@ static const struct key_entry lwmi_fn_keys_keymap[] = {
 	{ KE_KEY,	0x2d | LWMI_FN_KEY, { KEY_SELECTIVE_SCREENSHOT } },

drivers/platform/lenovo/wmi-fn-keys.c static const struct key_entry lwmi_fn_keys_keymap[] = { · line 118

Quoted 10 lines
drivers/platform/lenovo/wmi-fn-keys.c +8 -0
 	{ KE_KEY,	0x29 | LWMI_FN_KEY, { KEY_TOUCHPAD_TOGGLE } },
 	{ KE_KEY,	0x2a | LWMI_FN_KEY, { KEY_ROOT_MENU } },
+	/*
+	 * Keyboard backlight level after Fn+Space, handled by the firmware:
+	 * 0x40 off, 0x41 low, 0x42 high
+	 */
+	{ KE_IGNORE,	0x40 | LWMI_FN_KEY },
+	{ KE_IGNORE,	0x41 | LWMI_FN_KEY },
+	{ KE_IGNORE,	0x42 | LWMI_FN_KEY },
+	{ KE_IGNORE,	0x43 | LWMI_FN_KEY },

Could you please place all KE_IGNORE entries together? I.e., following 0x03.

With it fixed, the patch looks good to me:

Thanks,
Rong

Quoted 3 lines
drivers/platform/lenovo/wmi-fn-keys.c +0 -0
 	/*
 	 * WMI switches