Lenovo Yoga Book 9 keyboard dock detection
Dave Carey
maintainerv13 cover Lenovo Yoga Book 9 keyboard dock detection
Changes in v13:
- Resend of v12: v12 was corrupted in transit. Root cause: the ABI documentation uses RST table separator lines (== ====...) which contain '=' characters; git-send-email selected quoted-printable transfer encoding due to non-ASCII in the changelog (UTF-8 author name), encoding '=' as '=3D' and breaking git-am on the receiving end. Fixed by setting sendemail.transferEncoding=8bit. No content changes from v12.
Changes in v12 (addressing Ilpo Järvinen's v11 review of patch 2/2):
- Add #include <linux/sysfs.h> (for sysfs_emit)
- Add #include <linux/types.h> (for __le32 and __packed)
Changes in v11 (addressing Armin Wolf's v10 review of patch 2/2):
- ABI doc: correct Date to "June 2027" and KernelVersion to "7.3"; these fields should reflect when the ABI lands in the kernel, not the submission date.
Patch 1/2 (lenovo-ymc) is unchanged from v10.
Changes in v10 (addressing Armin Wolf's v9 review of patch 2/2):
- Update ABI doc: Date: June 2026, KernelVersion: 6.16
- Add #include <linux/compiler_attributes.h> and <linux/types.h>
- yb9_kbdock_query(): change return to pointer-out u32 *bkbd to avoid
a 0xFFFFFFFF status value being misread as -EPERM
- struct yb9_kbdock_data: add spinlock_t lock
- yb9_kbdock_report(): hold lock across input_report_switch + input_sync
- yb9_kbdock_sync(): return int, propagate query error to callers
- yb9_kbdock_resume(), yb9_kbdock_block_probe(): propagate sync error
- struct wmi_buffer out: remove zero-initializer (not needed)
- yb9_kbdock_notify_new(): drop manual length check; use .min_event_size = sizeof(__le32) in struct wmi_driver instead
Patch 1/2 (lenovo-ymc) is unchanged from v9.
Dave Carey (2):
platform/x86/lenovo: lenovo-ymc: Suppress probe on Yoga Book 9 14IAH10 platform/x86/lenovo: Add Yoga Book 9 keyboard dock detection driver
Documentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock | 19 ++ MAINTAINERS | 7 + drivers/platform/x86/lenovo/Kconfig | 14 + drivers/platform/x86/lenovo/Makefile | 1 + drivers/platform/x86/lenovo/yb9-kbdock.c | 312 ++++++++++++ drivers/platform/x86/lenovo/ymc.c | 19 ++ 6 files changed, 372 insertions(+)
2.55.0
Dave Carey
maintainerPATCH v13 1/2 platform/x86/lenovo: lenovo-ymc: Suppress probe on Yoga Book 9 14IAH10
The Yoga Book 9 14IAH10 (DMI product name "83KJ") has a dedicated yb9-kbdock WMI driver that registers an input device reporting SW_TABLET_MODE to track the detachable Bluetooth keyboard.
lenovo-ymc also loads on this machine and creates an input node with the SW_TABLET_MODE capability bit set. For input switches, the presence of the capability bit has semantic meaning: userspace (e.g. GNOME) reads the switch state at startup from every node advertising the capability and does not expect more than one such node.
Add a DMI match for the Yoga Book 9 14IAH10 to probe() so that lenovo-ymc returns -ENODEV on this hardware, leaving yb9-kbdock as the sole SW_TABLET_MODE source. The ymc_ec_trigger EC write, the only other action taken in response to a YMC event, is guarded by a separate DMI table that excludes this machine; no other functionality is affected.
--- drivers/platform/x86/lenovo/ymc.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/platform/x86/lenovo/ymc.c +19 -0
@@ -24,6 +24,22 @@ static bool force;module_param (force, bool,0444 );MODULE_PARM_DESC (force,"Force loading on boards without a convertible DMI chassis-type" ); +static const struct dmi_system_id lenovo_ymc_nosupport_dmi_table[] = { + { +/* +* Yoga Book 9 14IAH10: SW_TABLET_MODE is reported by the +* yb9-kbdock driver. Suppress lenovo-ymc on this machine to +* avoid userspace seeing two input nodes that both advertise +* the SW_TABLET_MODE capability. +*/ + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"83KJ" ), + }, + }, + { } +}; +static const struct dmi_system_id allowed_chasis_types_dmi_table[] = { { .matches = {
@@ -101,6 +117,9 @@ static int lenovo_ymc_probe(struct wmi_device *wdev, const void *ctx)struct input_dev *input_dev;int err; +if (dmi_check_system (lenovo_ymc_nosupport_dmi_table)) +return -ENODEV ; +if (!dmi_check_system (allowed_chasis_types_dmi_table)) {if (force)dev_info (&wdev->dev,"Force loading Lenovo YMC support\n" );
Signature · 1 line
2.55.0
Dave Carey
maintainerPATCH v13 2/2 platform/x86/lenovo: Add Yoga Book 9 keyboard dock detection driver
In reply to Dave CareyThe Lenovo Yoga Book 9 14IAH10 ships with a detachable Bluetooth keyboard that magnetically attaches to the bottom (secondary) screen in one of two positions. The Embedded Controller tracks the attachment state in a 2-bit field called BKBD and signals changes via WMI event GUID 806BD2A2-177B-481D-BFB5-3BA0BB4A2285 (notify ID 0xEB on the WM10 ACPI device, _UID "GMZN").
The device contains embedded BMOF data (WQDD, 20705 bytes) documenting both WMI interfaces used by this driver:
LENOVO_BTKBD_EVENT (event GUID): WmiDataId(1) uint32 Status. The ACPI _WED(0xEB) method returns EC.BKBD directly as an integer, so the notify callback receives BKBD without a separate query.
LENOVO_FEATURE_STATUS_DATA (block GUID, WQAF method): returns an 8-byte buffer {uint32 IDs=0x00060000, uint32 Status=BKBD}. Used for the initial state read on probe and after resume.
BKBD encoding:
0 = keyboard detached
1 = keyboard docked on top half of bottom screen 2 = keyboard docked on bottom half of bottom screen 3 = reserved (not observed in practice)
This driver registers two WMI drivers sharing a module-level BLOCKING_NOTIFIER_HEAD:
- The event driver (LENOVO_BTKBD_EVENT) uses .notify_new() to receive a pre-parsed wmi_buffer and fires the notifier chain with the BKBD value extracted from the buffer.
- The block driver (LENOVO_FEATURE_STATUS_DATA) owns the input_dev in its per-device private struct. At probe time it registers a notifier_block on the chain and reads the initial BKBD state via wmidev_query_block(). The WMI buffer is parsed as struct lenovo_feature_status { __le32 id; __le32 status; }, and the ID field is verified before the status is used.
- SW_TABLET_MODE=1 is reported when the keyboard is detached; SW_TABLET_MODE=0 when docked in either position (keyboard present).
- The raw BKBD value is exposed via read-only sysfs attribute "keyboard_position".
- BKBD state is re-read via wmidev_query_block() on resume from suspend or hibernation.
Tested on: Lenovo Yoga Book 9 14IAH10 (model 83KJ), kernel 7.0.
---
v13:
- Resend of v12: patch was corrupted in transit. git-send-email chose quoted-printable encoding (triggered by non-ASCII in the changelog) which encoded '=' as '=3D', corrupting the RST table separators in the ABI doc and breaking git-am. No content changes from v12.
v12:
- Add #include <linux/sysfs.h> (for sysfs_emit; Ilpo Järvinen)
- Add #include <linux/types.h> (for __le32 and __packed; Ilpo Järvinen)
v11 (addressing Armin Wolf's v10 review):
- ABI doc: correct Date to "June 2027" and KernelVersion to "7.3"
v10 (addressing Armin Wolf's v9 review):
- Update ABI doc: Date: June 2026, KernelVersion: 6.16
- Add #include <linux/compiler_attributes.h> and <linux/types.h>
- yb9_kbdock_query(): change return to pointer-out u32 *bkbd
- struct yb9_kbdock_data: add spinlock_t lock
- yb9_kbdock_report(): hold lock across input_report_switch + input_sync
- yb9_kbdock_sync(): return int, propagate query error to callers
- yb9_kbdock_resume(), yb9_kbdock_block_probe(): propagate sync error
- struct wmi_buffer out: remove zero-initializer
- yb9_kbdock_notify_new(): drop manual length check; use .min_event_size = sizeof(__le32) in struct wmi_driver instead
.../testing/sysfs-driver-lenovo-yb9-kbdock | 19 ++ MAINTAINERS | 7 + drivers/platform/x86/lenovo/Kconfig | 14 + drivers/platform/x86/lenovo/Makefile | 1 + drivers/platform/x86/lenovo/yb9-kbdock.c | 312 ++++++++++++++++++ 5 files changed, 353 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock create mode 100644 drivers/platform/x86/lenovo/yb9-kbdock.c
Documentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock new file +19 -0
@@ -0,0 +1,19 @@ +What: /sys/bus/wmi/drivers/lenovo-yb9-kbdock/<guid>/keyboard_position +Date: June 2027 +KernelVersion: 7.3 +Contact: Dave Carey <[email protected]> +Description: + Read-only attribute reporting the current keyboard dock position + as reported by the Embedded Controller on the Lenovo Yoga Book 9 + 14IAH10. + + Possible values: + + == ============================================================= + 0 keyboard is not docked to any screen (detached) + 1 keyboard docked on the top half of the bottom screen + 2 keyboard docked on the bottom half of the bottom screen + == ============================================================= + + SW_TABLET_MODE input events are also emitted: 0 when the keyboard + is docked (either position), 1 when detached.
MAINTAINERS +7 -0
@@ -14479,6 +14479,13 @@ L: [email protected] S: Maintained F: drivers/platform/x86/lenovo/wmi-hotkey-utilities.c +LENOVO YOGA BOOK 9 KEYBOARD DOCK DRIVER +M: Dave Carey <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock +F: drivers/platform/x86/lenovo/yb9-kbdock.c + LETSKETCH HID TABLET DRIVER M: Hans de Goede <[email protected]> L: [email protected]
drivers/platform/x86/lenovo/Kconfig +14 -0
@@ -43,6 +43,20 @@ config LENOVO_WMI_CAMERA 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 + depends on DMI + depends on INPUT + help + Say Y here to enable keyboard dock detection on the Lenovo Yoga Book 9 + 14IAH10. The detachable Bluetooth keyboard magnetically attaches to + either screen; this driver reports SW_TABLET_MODE input events based + on the attachment state and exposes the raw position in sysfs. + + To compile this driver as a module, choose M here: the module will be + called lenovo-yb9-kbdock. + config LENOVO_YMC tristate "Lenovo Yoga Tablet Mode Control" depends on ACPI_WMI
drivers/platform/x86/lenovo/Makefile +1 -0
@@ -8,6 +8,7 @@ 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/yb9-kbdock.c new file +312 -0
312 lines not on this page · raw message
Signature · 1 line
2.55.0
Ilpo Järvinen
maintainerRe: [PATCH v13 2/2] platform/x86/lenovo: Add Yoga Book 9 keyboard dock detection driver
Quoted 213 lines · Dave Carey
The Lenovo Yoga Book 9 14IAH10 ships with a detachable Bluetooth keyboard that magnetically attaches to the bottom (secondary) screen in one of two positions. The Embedded Controller tracks the attachment state in a 2-bit field called BKBD and signals changes via WMI event GUID 806BD2A2-177B-481D-BFB5-3BA0BB4A2285 (notify ID
0xEBon the WM10 ACPI device,_UID"GMZN").The device contains embedded BMOF data (WQDD, 20705 bytes) documenting both WMI interfaces used by this driver:
LENOVO_BTKBD_EVENT(event GUID): WmiDataId(1) uint32 Status. The ACPI_WED(0xEB)method returns EC.BKBD directly as an integer, so the notify callback receives BKBD without a separate query.
LENOVO_FEATURE_STATUS_DATA(block GUID, WQAF method): returns an 8-byte buffer {uint32 IDs=0x00060000, uint32 Status=BKBD}. Used for the initial state read on probe and after resume.BKBD encoding:
0 = keyboard detached
1 = keyboard docked on top half of bottom screen 2 = keyboard docked on bottom half of bottom screen 3 = reserved (not observed in practice)This driver registers two WMI drivers sharing a module-level
BLOCKING_NOTIFIER_HEAD:- The event driver (
LENOVO_BTKBD_EVENT) uses .notify_new() to receive a pre-parsedwmi_bufferand fires the notifier chain with the BKBD value extracted from the buffer.- The block driver (
LENOVO_FEATURE_STATUS_DATA) owns theinput_devin its per-device private struct. At probe time it registers anotifier_blockon the chain and reads the initial BKBD state viawmidev_query_block(). The WMI buffer is parsed as structlenovo_feature_status{__le32id;__le32status; }, and the ID field is verified before the status is used.- SW_TABLET_MODE=1 is reported when the keyboard is detached; SW_TABLET_MODE=0 when docked in either position (keyboard present).
- The raw BKBD value is exposed via read-only sysfs attribute "
keyboard_position".- BKBD state is re-read via
wmidev_query_block()on resume from suspend or hibernation.Tested on: Lenovo Yoga Book 9 14IAH10 (model 83KJ), kernel 7.0.
Acked-by Hans de Goede <[email protected]>Reviewed-by Armin Wolf <[email protected]>Signed-off-by Dave Carey <[email protected]>---
v13:
- Resend of v12: patch was corrupted in transit. git-send-email chose quoted-printable encoding (triggered by non-ASCII in the changelog) which encoded '=' as '=3D', corrupting the RST table separators in the ABI doc and breaking git-am. No content changes from v12.v12:
- Add #include <linux/sysfs.h> (forsysfs_emit; Ilpo Järvinen)
- Add #include <linux/types.h> (for__le32and__packed; Ilpo Järvinen)v11 (addressing Armin Wolf's v10 review):
- ABI doc: correct Date to "June 2027" and KernelVersion to "7.3"v10 (addressing Armin Wolf's v9 review):
- Update ABI doc: Date: June 2026, KernelVersion: 6.16
- Add #include <linux/compiler_attributes.h> and <linux/types.h>
-yb9_kbdock_query(): change return to pointer-out u32 *bkbd
- structyb9_kbdock_data: addspinlock_tlock
-yb9_kbdock_report(): hold lock acrossinput_report_switch+input_sync
-yb9_kbdock_sync(): return int, propagate query error to callers
-yb9_kbdock_resume(),yb9_kbdock_block_probe(): propagate sync error
- structwmi_bufferout: remove zero-initializer
-yb9_kbdock_notify_new(): drop manual length check; use .min_event_size =sizeof(__le32)in structwmi_driverinstead.../testing/sysfs-driver-lenovo-yb9-kbdock | 19 ++ MAINTAINERS | 7 + drivers/platform/x86/lenovo/Kconfig | 14 + drivers/platform/x86/lenovo/Makefile | 1 + drivers/platform/x86/lenovo/yb9-kbdock.c | 312 ++++++++++++++++++ 5 files changed, 353 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock create mode 100644 drivers/platform/x86/lenovo/yb9-kbdock.cDocumentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock new file +19
-0@@ -0,0 +1,19 @@ +What: /sys/bus/wmi/drivers/lenovo-yb9-kbdock/<guid>/keyboard_position +Date: June 2027 +KernelVersion: 7.3 +Contact: Dave Carey <[email protected]> +Description: + Read-only attribute reporting the current keyboard dock position + as reported by the Embedded Controller on the Lenovo Yoga Book 9 + 14IAH10. + + Possible values: + + == ============================================================= + 0 keyboard is not docked to any screen (detached) + 1 keyboard docked on the top half of the bottom screen + 2 keyboard docked on the bottom half of the bottom screen + == ============================================================= + + SW_TABLET_MODE input events are also emitted: 0 when the keyboard + is docked (either position), 1 when detached.MAINTAINERS +7
-0@@ -14479,6 +14479,13 @@ L: [email protected] S: Maintained F: drivers/platform/x86/lenovo/wmi-hotkey-utilities.c +LENOVO YOGA BOOK 9 KEYBOARD DOCK DRIVER +M: Dave Carey <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock +F: drivers/platform/x86/lenovo/yb9-kbdock.c + LETSKETCH HID TABLET DRIVER M: Hans de Goede <[email protected]> L: [email protected]drivers/platform/x86/lenovo/Kconfig +14
-0@@ -43,6 +43,20 @@ config LENOVO_WMI_CAMERA 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 + depends on DMI + depends on INPUT + help + Say Y here to enable keyboard dock detection on the Lenovo Yoga Book 9 + 14IAH10. The detachable Bluetooth keyboard magnetically attaches to + either screen; this driver reports SW_TABLET_MODE input events based + on the attachment state and exposes the raw position in sysfs. + + To compile this driver as a module, choose M here: the module will be + called lenovo-yb9-kbdock. + config LENOVO_YMC tristate "Lenovo Yoga Tablet Mode Control" depends on ACPI_WMIdrivers/platform/x86/lenovo/Makefile +1
-0@@ -8,6 +8,7 @@ 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.odrivers/platform/x86/lenovo/yb9-kbdock.c new file +40
-0@@ -0,0 +1,312 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Lenovo Yoga Book 9 keyboard-dock detection +* +* The Yoga Book 9 ships with a detachable Bluetooth keyboard that magnetically +* attaches to the bottom screen in one of two positions. The EC tracks +* attachment state in a 2-bit field called BKBD and signals changes via WMI +* event 0xEB on the WM10 ACPI device (_UID "GMZN"). +* +* BKBD values: +* 0 = keyboard detached +* 1 = keyboard docked on the top half of the bottom screen +* 2 = keyboard docked on the bottom half of the bottom screen +* 3 = reserved / not observed +* +* Two WMI interfaces are used (documented in embedded BMOF, WQDD, 20705 bytes): +* +* LENOVO_BTKBD_EVENT (event GUID, 806BD2A2-...) +* WmiDataId(1) uint32 Status — _WED(0xEB) returns EC.BKBD directly. +* The notify callback receives BKBD as an integer; no separate query needed. +* +* LENOVO_FEATURE_STATUS_DATA (block GUID, E7F300FA-...) +* WmiDataId(1) uint32 IDs = 0x00060000 (feature selector) +* WmiDataId(2) uint32 Status = BKBD value +* Used on probe and resume to read initial state. +* +* The event driver (LENOVO_BTKBD_EVENT) fires a notifier chain on each WMI +* event. The block driver (LENOVO_FEATURE_STATUS_DATA) owns the input_dev +* and registers a notifier_block to receive those events, eliminating the +* need for shared global state or a mutex. +* +* SW_TABLET_MODE=1 is reported when the keyboard is detached; +* SW_TABLET_MODE=0 when docked in either position (keyboard present). +* The raw BKBD value is exposed via the sysfs attribute "keyboard_position". +* +* Copyright (C) 2026 Dave Carey <[email protected]> +*/ + +#include <linux/acpi.h> +#include <linux/cleanup.h>
drivers/platform/x86/lenovo/yb9-kbdock.c line 50
Quoted 10 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +10
-0+#include <linux/dev_printk.h> +#include <linux/dmi.h> +#include <linux/input.h> +#include <linux/module.h> +#include <linux/notifier.h> +#include <linux/pm.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/types.h> +#include <linux/wmi.h>
Hi,
Are you sure you sent the latest version, AFAICT, v12 had this:
+#include <linux/acpi.h>
+#include <linux/cleanup.h>
+#include <linux/compiler_attributes.h>
+#include <linux/dev_printk.h>
...
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/sysfs.h>
+#include <linux/types.h>
+#include <linux/wmi.h>
?
Signature · 1 line
i.
Dave Carey
maintainerRe: [PATCH v13 2/2] platform/x86/lenovo: Add Yoga Book 9 keyboard dock detection driver
Ugh ... let me check, was trying to do a few different things today at the same time. Appreciate the patience.
-DC
Quoted 242 lines · Ilpo Järvinen
Quoted 213 lines · Dave Carey
The Lenovo Yoga Book 9 14IAH10 ships with a detachable Bluetooth keyboard that magnetically attaches to the bottom (secondary) screen in one of two positions. The Embedded Controller tracks the attachment state in a 2-bit field called BKBD and signals changes via WMI event GUID 806BD2A2-177B-481D-BFB5-3BA0BB4A2285 (notify ID
0xEBon the WM10 ACPI device,_UID"GMZN").The device contains embedded BMOF data (WQDD, 20705 bytes) documenting both WMI interfaces used by this driver:
LENOVO_BTKBD_EVENT(event GUID): WmiDataId(1) uint32 Status. The ACPI_WED(0xEB)method returns EC.BKBD directly as an integer, so the notify callback receives BKBD without a separate query.
LENOVO_FEATURE_STATUS_DATA(block GUID, WQAF method): returns an 8-byte buffer {uint32 IDs=0x00060000, uint32 Status=BKBD}. Used for the initial state read on probe and after resume.BKBD encoding:
0 = keyboard detached
1 = keyboard docked on top half of bottom screen 2 = keyboard docked on bottom half of bottom screen 3 = reserved (not observed in practice)This driver registers two WMI drivers sharing a module-level
BLOCKING_NOTIFIER_HEAD:- The event driver (
LENOVO_BTKBD_EVENT) uses .notify_new() to receive a pre-parsedwmi_bufferand fires the notifier chain with the BKBD value extracted from the buffer.- The block driver (
LENOVO_FEATURE_STATUS_DATA) owns theinput_devin its per-device private struct. At probe time it registers anotifier_blockon the chain and reads the initial BKBD state viawmidev_query_block(). The WMI buffer is parsed as structlenovo_feature_status{__le32id;__le32status; }, and the ID field is verified before the status is used.- SW_TABLET_MODE=1 is reported when the keyboard is detached; SW_TABLET_MODE=0 when docked in either position (keyboard present).
- The raw BKBD value is exposed via read-only sysfs attribute "
keyboard_position".- BKBD state is re-read via
wmidev_query_block()on resume from suspend or hibernation.Tested on: Lenovo Yoga Book 9 14IAH10 (model 83KJ), kernel 7.0.
Acked-by Hans de Goede <[email protected]>Reviewed-by Armin Wolf <[email protected]>Signed-off-by Dave Carey <[email protected]>---
v13:
- Resend of v12: patch was corrupted in transit. git-send-email chose quoted-printable encoding (triggered by non-ASCII in the changelog) which encoded '=' as '=3D', corrupting the RST table separators in the ABI doc and breaking git-am. No content changes from v12.v12:
- Add #include <linux/sysfs.h> (forsysfs_emit; Ilpo Järvinen)
- Add #include <linux/types.h> (for__le32and__packed; Ilpo Järvinen)v11 (addressing Armin Wolf's v10 review):
- ABI doc: correct Date to "June 2027" and KernelVersion to "7.3"v10 (addressing Armin Wolf's v9 review):
- Update ABI doc: Date: June 2026, KernelVersion: 6.16
- Add #include <linux/compiler_attributes.h> and <linux/types.h>
-yb9_kbdock_query(): change return to pointer-out u32 *bkbd
- structyb9_kbdock_data: addspinlock_tlock
-yb9_kbdock_report(): hold lock acrossinput_report_switch+input_sync
-yb9_kbdock_sync(): return int, propagate query error to callers
-yb9_kbdock_resume(),yb9_kbdock_block_probe(): propagate sync error
- structwmi_bufferout: remove zero-initializer
-yb9_kbdock_notify_new(): drop manual length check; use .min_event_size =sizeof(__le32)in structwmi_driverinstead.../testing/sysfs-driver-lenovo-yb9-kbdock | 19 ++ MAINTAINERS | 7 + drivers/platform/x86/lenovo/Kconfig | 14 + drivers/platform/x86/lenovo/Makefile | 1 + drivers/platform/x86/lenovo/yb9-kbdock.c | 312 ++++++++++++++++++ 5 files changed, 353 insertions(+)create mode 100644
Documentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdockcreate mode 100644drivers/platform/x86/lenovo/yb9-kbdock.cDocumentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock new file +19
-0@@ -0,0 +1,19 @@ +What: /sys/bus/wmi/drivers/lenovo-yb9-kbdock/<guid>/keyboard_position +Date: June 2027 +KernelVersion: 7.3 +Contact: Dave Carey <[email protected]> +Description: + Read-only attribute reporting the current keyboard dock position + as reported by the Embedded Controller on the Lenovo Yoga Book 9 + 14IAH10. + + Possible values: + + == ============================================================= + 0 keyboard is not docked to any screen (detached) + 1 keyboard docked on the top half of the bottom screen + 2 keyboard docked on the bottom half of the bottom screen + == ============================================================= + + SW_TABLET_MODE input events are also emitted: 0 when the keyboard + is docked (either position), 1 when detached.MAINTAINERS +7
-0@@ -14479,6 +14479,13 @@ L: [email protected] S: Maintained F: drivers/platform/x86/lenovo/wmi-hotkey-utilities.c +LENOVO YOGA BOOK 9 KEYBOARD DOCK DRIVER +M: Dave Carey <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock +F: drivers/platform/x86/lenovo/yb9-kbdock.c + LETSKETCH HID TABLET DRIVER M: Hans de Goede <[email protected]> L: [email protected]drivers/platform/x86/lenovo/Kconfig +14
-0@@ -43,6 +43,20 @@ config LENOVO_WMI_CAMERA 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 + depends on DMI + depends on INPUT + help + Say Y here to enable keyboard dock detection on the Lenovo Yoga Book 9 + 14IAH10. The detachable Bluetooth keyboard magnetically attaches to + either screen; this driver reports SW_TABLET_MODE input events based + on the attachment state and exposes the raw position in sysfs. + + To compile this driver as a module, choose M here: the module will be + called lenovo-yb9-kbdock. + config LENOVO_YMC tristate "Lenovo Yoga Tablet Mode Control" depends on ACPI_WMIdrivers/platform/x86/lenovo/Makefile +1
-0@@ -8,6 +8,7 @@ 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.odrivers/platform/x86/lenovo/yb9-kbdock.c new file +40
-0@@ -0,0 +1,312 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Lenovo Yoga Book 9 keyboard-dock detection +* +* The Yoga Book 9 ships with a detachable Bluetooth keyboard that magnetically +* attaches to the bottom screen in one of two positions. The EC tracks +* attachment state in a 2-bit field called BKBD and signals changes via WMI +* event 0xEB on the WM10 ACPI device (_UID "GMZN"). +* +* BKBD values: +* 0 = keyboard detached +* 1 = keyboard docked on the top half of the bottom screen +* 2 = keyboard docked on the bottom half of the bottom screen +* 3 = reserved / not observed +* +* Two WMI interfaces are used (documented in embedded BMOF, WQDD, 20705 bytes): +* +* LENOVO_BTKBD_EVENT (event GUID, 806BD2A2-...) +* WmiDataId(1) uint32 Status — _WED(0xEB) returns EC.BKBD directly. +* The notify callback receives BKBD as an integer; no separate query needed. +* +* LENOVO_FEATURE_STATUS_DATA (block GUID, E7F300FA-...) +* WmiDataId(1) uint32 IDs = 0x00060000 (feature selector) +* WmiDataId(2) uint32 Status = BKBD value +* Used on probe and resume to read initial state. +* +* The event driver (LENOVO_BTKBD_EVENT) fires a notifier chain on each WMI +* event. The block driver (LENOVO_FEATURE_STATUS_DATA) owns the input_dev +* and registers a notifier_block to receive those events, eliminating the +* need for shared global state or a mutex. +* +* SW_TABLET_MODE=1 is reported when the keyboard is detached; +* SW_TABLET_MODE=0 when docked in either position (keyboard present). +* The raw BKBD value is exposed via the sysfs attribute "keyboard_position". +* +* Copyright (C) 2026 Dave Carey <[email protected]> +*/ + +#include <linux/acpi.h> +#include <linux/cleanup.h> drivers/platform/x86/lenovo/yb9-kbdock.c line 50
Quoted 10 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +10
-0+#include <linux/dev_printk.h> +#include <linux/dmi.h> +#include <linux/input.h> +#include <linux/module.h> +#include <linux/notifier.h> +#include <linux/pm.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/types.h> +#include <linux/wmi.h> Hi,
Are you sure you sent the latest version, AFAICT, v12 had this:
drivers/platform/x86/lenovo/yb9-kbdock.c new file +9
-0+#include <linux/acpi.h> +#include <linux/cleanup.h> +#include <linux/compiler_attributes.h> +#include <linux/dev_printk.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/sysfs.h> +#include <linux/types.h> +#include <linux/wmi.h> ?