From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.10 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796399037; b=2tdCTGF7I8vm2kvLq5KBCAEggF1SOKECbFnxtyMiKr/iAn5SO2w+80SjQHFgyoagYBCs fBMt5uHxCVm7YQqA5s68xXoCltYM47Z2JdLx03bJe0wpMfLcWIyrLfq2AA4HO+W16ZQcH xR3OdypYKVxhS2Hu+jDOW0emN7wS99EvQYn56RriNc6Wx8qfamAtMpHC3PJ37+vntmHrS rqqgJR5DngF+tMdCF6USXJOd++OkB6QYLQBuoV7ndzreylwzIq+Gr/bxaOAe1TbgiqIA/ OqPYGFHZCX+4p7c1r4T7S4Kz5t28nUnPzaj6ahNwEFk6PBW8dqzKDVteDmrR0ZKRj0g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796399037; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:Date:To:cc: Subject:In-Reply-To:Message-ID:References:MIME-Version:Content-Type; bh=Ny7eySoWQOltnaLazRLqKfizzlE9a/K3dEIVovKACIo=; b=tltVzLkWnHxUL9OCyxejNE5NR3JUAaPABXDogOgr7J17TiZy6M33QOcCdgwRp0OZOuqp JgjhBOEUwZ8ET9h8lXFXEV0yEr+GPYfvcR5ChGbb41aTU7BuzU+IscPLZjtacSg1ou9eg /sDGo6/cyOjYDEKNDPyI6esalRYb6iQkTuZZ+V8t7uT0PYcQFfh1vCF6y5H4tqo0+8ye4 GgduRXtifbmQ9k5sL4DvTMO2qF7h35chuzDmVg+2AVNJirhD0YIw6pYxnu5rpd+KWRq5K Ze6/wSPD5L2RNRF6aJhRL057j5KpFBs/xDXhjwWZHxClkB+8D4cJjzFpIHTLgAGjfJg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=XfvC6MyZ; arc=none smtp.remote-ip=198.175.65.10 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC770606A322; Fri, 4 Dec 2026 15:43:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CC770606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=XfvC6MyZ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796399036; x=1827935036; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=Ny7eySoWQOltnaLazRLqKfizzlE9a/K3dEIVovKACIo=; b=XfvC6MyZm8Y9SysRW++cwYqXcUUWNYEv5pHMTHQ86iZhx1uf5Hs715Q+ vxYtUhIuoPov47RZajJqgIcj4f5MR44mimh/qv1eSjeZh4626ohda72Dp B8vKrQs8fIfNJk8+CK3fDxQ1qWKcmCH5d4CaCtQJHDlfMcCo5qsgpQ25i DYUqsZmUZbgUYnbwVuUHOCfBkNCNXyrSzqC3uZWKLOreatqZ9w4c8WV4T 4RlNQ5icLO2EXG1Z01sPQXNNBAMkzZkV75kYSw0USGlmooIzTIEw9giXj TekTImAEZfNP9h+Zszo82I7cM/2+sdKV2hmt68EKArpGHBjg119zZUFlb g==; X-CSE-ConnectionGUID: v0JS4Pr/QtyjyPjhcp51qw== X-CSE-MsgGUID: 4kPcQimgS1+/ZluHWH0APw== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5322325" X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="5322325" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 07:43:56 -0800 X-CSE-ConnectionGUID: 171gMkQlQ+S41wEUqx26gA== X-CSE-MsgGUID: MGQXfDXZQlOgG3FvHftEqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="14162250" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.245.47]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 07:43:50 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Fri, 4 Dec 2026 17:43:46 +0200 (EET) To: David Cemin cc: Hans de Goede , W_Armin@gmx.de, Mark Pearson , derekjohn.clark@gmail.com, xy-jackie@139.com, i@rong.moe, marco_giunta@outlook.it, ciro.pedrini@gmail.com, ldemarchi@nvidia.com, platform-driver-x86@vger.kernel.org, LKML Subject: Re: [PATCH v5 2/4] platform: lenovo: add WMI Fn keys driver and use it from ideapad-laptop In-Reply-To: <20261203000251.1006053-3-dcemin@nvidia.com> Message-ID: References: <20261130043245.758932-1-dcemin@nvidia.com> <20261203000251.1006053-1-dcemin@nvidia.com> <20261203000251.1006053-3-dcemin@nvidia.com> X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Wed, 2 Dec 2026, David Cemin wrote: > 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. > > Reviewed-by: Rong Zhang > Signed-off-by: David Cemin Please check if sashiko's race report has some validity on it or not. -- i. > --- > MAINTAINERS | 8 + > drivers/platform/lenovo/Kconfig | 15 + > drivers/platform/lenovo/Makefile | 1 + > drivers/platform/lenovo/wmi-fn-keys.c | 290 ++++++++++++++++++ > drivers/platform/x86/lenovo/Kconfig | 2 +- > drivers/platform/x86/lenovo/ideapad-laptop.c | 214 +++---------- > .../linux/platform_data/lenovo-wmi-fn-keys.h | 32 ++ > 7 files changed, 395 insertions(+), 167 deletions(-) > create mode 100644 drivers/platform/lenovo/wmi-fn-keys.c > create mode 100644 include/linux/platform_data/lenovo-wmi-fn-keys.h > > diff --git a/MAINTAINERS b/MAINTAINERS > index b8356204a0ea..823183033b5c 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -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 > +M: Rong Zhang > +L: platform-driver-x86@vger.kernel.org > +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 > L: platform-driver-x86@vger.kernel.org > diff --git a/drivers/platform/lenovo/Kconfig b/drivers/platform/lenovo/Kconfig > index 8222322ca671..f67f7c811214 100644 > --- a/drivers/platform/lenovo/Kconfig > +++ b/drivers/platform/lenovo/Kconfig > @@ -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 > diff --git a/drivers/platform/lenovo/Makefile b/drivers/platform/lenovo/Makefile > index 1cac115dd735..8ea207e79a43 100644 > --- a/drivers/platform/lenovo/Makefile > +++ b/drivers/platform/lenovo/Makefile > @@ -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 > diff --git a/drivers/platform/lenovo/wmi-fn-keys.c b/drivers/platform/lenovo/wmi-fn-keys.c > new file mode 100644 > index 000000000000..ba159def3956 > --- /dev/null > +++ b/drivers/platform/lenovo/wmi-fn-keys.c > @@ -0,0 +1,290 @@ > +// 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 > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > + > +#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; > +}; > + > +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[] = { > + /* > + * WMI ignored events > + */ > + /* FnLock (handled by the firmware) */ > + { KE_IGNORE, 0x02 | LWMI_FN_KEY }, > + /* Esc (handled by the firmware) */ > + { KE_IGNORE, 0x03 | LWMI_FN_KEY }, > + /* Keyboard backlight down, up and effect (handled by the keyboard) */ > + { KE_IGNORE, 0x19 | LWMI_FN_KEY }, > + { KE_IGNORE, 0x1a | LWMI_FN_KEY }, > + { KE_IGNORE, 0x21 | LWMI_FN_KEY }, > + > + /* > + * WMI keys > + */ > + /* 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 "); > +MODULE_DESCRIPTION("Lenovo WMI Fn keys driver"); > +MODULE_LICENSE("GPL"); > diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/lenovo/Kconfig > index 140f8acf7cc0..8e9fc5df4dd6 100644 > --- a/drivers/platform/x86/lenovo/Kconfig > +++ b/drivers/platform/x86/lenovo/Kconfig > @@ -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 > diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platform/x86/lenovo/ideapad-laptop.c > index b225dfee18c5..8b0f8eff4937 100644 > --- a/drivers/platform/x86/lenovo/ideapad-laptop.c > +++ b/drivers/platform/x86/lenovo/ideapad-laptop.c > @@ -41,7 +41,7 @@ > #include > #include > #include > -#include > +#include > #include "ideapad-laptop.h" > > #include > @@ -216,6 +216,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; > @@ -1366,8 +1367,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 } }, > @@ -1380,69 +1379,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 }, > - /* Keyboard backlight down, up and effect (handled by the keyboard) */ > - { KE_IGNORE, 0x19 | IDEAPAD_WMI_KEY }, > - { KE_IGNORE, 0x1a | IDEAPAD_WMI_KEY }, > - { KE_IGNORE, 0x21 | 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 }, > }; > > @@ -2702,49 +2638,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; > - > - 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; > + struct ideapad_private *priv = container_of(nb, struct ideapad_private, fn_keys_nb); > + u32 code; > > - 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); > > @@ -2754,72 +2665,43 @@ static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data) > } > } > > - if (data->type != ACPI_TYPE_INTEGER) { > - dev_warn(&wdev->dev, > - "WMI event data is not an integer\n"); > - break; > - } > + code = *(u32 *)data; > > - 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(); > + 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 > @@ -2905,6 +2787,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) > @@ -2936,6 +2822,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++) > @@ -2968,6 +2855,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++) > @@ -3025,18 +2913,12 @@ static int __init ideapad_laptop_init(void) > ideapad_kbd_bl_auto_trigger_registered = true; > } > > - err = ideapad_wmi_driver_register(); > - if (err) > - goto err_ledtrig; > - > err = platform_driver_register(&ideapad_acpi_driver); > if (err) > - goto err_wmi; > + goto err_ledtrig; > > return 0; > > -err_wmi: > - ideapad_wmi_driver_unregister(); > err_ledtrig: > if (ideapad_kbd_bl_auto_trigger_registered) > led_trigger_unregister(&ideapad_kbd_bl_auto_trigger); > @@ -3047,7 +2929,6 @@ module_init(ideapad_laptop_init) > static void __exit ideapad_laptop_exit(void) > { > platform_driver_unregister(&ideapad_acpi_driver); > - ideapad_wmi_driver_unregister(); > > if (ideapad_kbd_bl_auto_trigger_registered) > led_trigger_unregister(&ideapad_kbd_bl_auto_trigger); > @@ -3056,4 +2937,5 @@ module_exit(ideapad_laptop_exit) > > MODULE_AUTHOR("David Woodhouse "); > MODULE_DESCRIPTION("IdeaPad ACPI Extras"); > +MODULE_IMPORT_NS("LENOVO_WMI_FN_KEYS"); > MODULE_LICENSE("GPL"); > diff --git a/include/linux/platform_data/lenovo-wmi-fn-keys.h b/include/linux/platform_data/lenovo-wmi-fn-keys.h > new file mode 100644 > index 000000000000..4a737990b184 > --- /dev/null > +++ b/include/linux/platform_data/lenovo-wmi-fn-keys.h > @@ -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_ */ >