platform/x86/lenovo: Yoga Book 9 keyboard dock detection
Dave Carey
maintainerv8 cover platform/x86/lenovo: Yoga Book 9 keyboard dock detection
Hi Ilpo,
Thank you for the v7 review. All nine items are addressed in v8.
One item needs a brief explanation: for the mutex lifecycle, I used __MUTEX_INITIALIZER(yb9.lock) in the struct definition rather than devm_mutex_init(). The yb9 struct is a module-level global with no associated device at __init time, and since yb9_kbdock_block_probe() acquires the lock and can run before yb9_kbdock_event_probe(), the mutex must be valid before either probe runs. Static initialization achieves the same goal (no manual init/destroy lifecycle) without requiring a device pointer. If you'd prefer a different approach, please let me know.
Changes in v8:
- Add #include <linux/bits.h> (required for GENMASK).
- Add #include <linux/dev_printk.h> (explicit include for dev_warn/dev_dbg).
- Use __MUTEX_INITIALIZER(yb9.lock) for static mutex initialization; removes mutex_init() call and the need for mutex_destroy().
- Update wmidev_query_block() call to pass min_size=8; remove manual length check now handled by the WMI core.
- Move u8 *data __free(kfree) declaration to immediately after the successful wmidev_query_block() call (cleanup.h convention).
- Change data type from void * to u8 * to allow pointer arithmetic without cast.
- Remove (int) cast from FIELD_GET() return value.
- Remove blank line between yb9_kbdock_query_locked() call and error check in keyboard_position_show().
- Use %d format specifier in sysfs_emit(); remove (unsigned int) cast.
Patch 1/2 (lenovo-ymc) is unchanged from v7.
Tested on Lenovo Yoga Book 9 14IAH10 (model 83KJ), kernel 7.0.
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
.../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.54.0
Dave Carey
maintainerPATCH v8 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
@@ -23,7 +23,23 @@ module_param(force, bool, 0444);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 = {
@@ -100,7 +116,10 @@ static int lenovo_ymc_probe(struct wmi_device *wdev, const void *ctx)struct lenovo_ymc_private *priv;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" );
--
2.54.0
Dave Carey
maintainerPATCH v8 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: one on the event GUID (LENOVO_BTKBD_EVENT) and one on the block GUID (LENOVO_FEATURE_STATUS_DATA).
- On probe, reads initial BKBD state via wmidev_query_block() on the block device; whichever driver probes last triggers the initial read.
- On WMI notification, reads BKBD directly from the event data integer
(ACPI _WED(0xEB) returns EC.BKBD) without a redundant WQAF call.
- Reports SW_TABLET_MODE=1 when detached, SW_TABLET_MODE=0 when docked in either position (a physical keyboard is present in both cases).
- Exposes the raw BKBD value via read-only sysfs attribute "keyboard_position".
- Re-reads BKBD state on resume from suspend or hibernation.
Tested on: Lenovo Yoga Book 9 14IAH10 (model 83KJ), kernel 7.0.
---
v8:
- Add #include <linux/bits.h> (required for GENMASK).
- Add #include <linux/dev_printk.h> (explicit include for dev_warn/dev_dbg).
- Use __MUTEX_INITIALIZER(yb9.lock) for static mutex initialization; removes mutex_init() call and the need for mutex_destroy().
- Update wmidev_query_block() call to pass min_size=8; remove manual length check that is now handled by the WMI core.
- Move u8 *data __free(kfree) declaration to immediately after the successful wmidev_query_block() call (cleanup.h convention).
- Change data type from void * to u8 * to allow pointer arithmetic without cast.
- Remove (int) cast from FIELD_GET() return value.
- Remove blank line between yb9_kbdock_query_locked() call and error check in keyboard_position_show().
- Use %d format specifier in sysfs_emit(); remove (unsigned int) cast.
v7:
- Use wmidev_query_block() in place of deprecated wmidev_block_query(). Use __free(kfree) to manage the output buffer; simplify the parsing to a single length check now that the WMI core handles type conversion.
- Define BKBD_FIELD with GENMASK() and extract the field with FIELD_GET() instead of open-coded masking.
- Use guard(mutex) for all lock/unlock pairs.
- Add yb9_kbdock_sync_locked() helper to consolidate the duplicated initial-state read pattern in event_probe, block_probe, and resume.
- Add linux/bitfield.h, linux/cleanup.h, linux/slab.h includes.
- Fix comment on struct mutex field; use Context:/Returns: sections in the kerneldoc comment for yb9_kbdock_query_locked().
v6:
- Submitted as 2/2; patch 1/2 adds a DMI early-exit to lenovo-ymc to prevent duplicate SW_TABLET_MODE input nodes on the YB9.
v5:
- Rewrote as two WMI drivers (event + block) to avoid the deprecated wmi_query_block() API: event driver owns the GUID that delivers notifications, block driver owns the GUID used for querying state. Either can probe first; both probe callbacks check whether the other has already probed and fire the initial read when both are ready.
- Use wmidev_block_query() on the block wmi_device directly (replaces the deprecated wmi_query_block()).
- In the notify callback, read BKBD directly from the event data integer passed by the WMI core (_WED(0xEB) returns EC.BKBD; confirmed by decoding the embedded BMOF from WQDD). Eliminates the redundant WQAF call that v4 made on every notification.
- Documented the two BMOF classes (LENOVO_BTKBD_EVENT and LENOVO_FEATURE_STATUS_DATA) with field layouts in the commit message and file header.
- sysfs keyboard_position: output bare integer, drop the parenthetical position-name suffix that a couple of reviewers found non-standard.
- Set .no_singleton = true on both WMI drivers (was missing from block driver in v4).
- Add PM resume callback (yb9_kbdock_resume) to re-read BKBD state after suspend/hibernation.
v4:
- Dropped module_wmi_driver(); registered two WMI drivers manually to allow sharing state. module_init/exit pair registers/unregisters both.
- Added ATTRIBUTE_GROUPS() and .dev_groups for the sysfs attribute.
- sysfs show: performed a live query instead of returning a cached value.
v3:
- Switched to devm_input_allocate_device().
- Added DMI guard (dmi_check_system) to reject non-YB9 machines.
- Removed redundant MODULE_DEVICE_TABLE on block driver.
v2:
- Added .no_singleton = true on the event WMI driver.
- Added PM suspend/resume skeleton.
- Fixed MODULE_LICENSE to "GPL" (was "GPL v2").
.../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: April 2026 +KernelVersion: 6.10 +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.54.0
Re: [PATCH v8 1/2] platform/x86/lenovo: lenovo-ymc: Suppress probe on Yoga Book 9 14IAH10
In reply to Dave CareyHi Dave,
Quoted 10 lines · Dave Carey
The Yoga Book 9 14IAH10 (DMI product name "83KJ") has a dedicated yb9-kbdock WMI driver that registers an input device reporting
SW_TABLET_MODEto track the detachable Bluetooth keyboard.lenovo-ymc also loads on this machine and creates an input node with the
SW_TABLET_MODEcapability 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.
Quoted 6 lines
Add a DMI match for the Yoga Book 9 14IAH10 to
probe()so that lenovo-ymc returns-ENODEVon this hardware, leaving yb9-kbdock as the soleSW_TABLET_MODEsource. Theymc_ec_triggerEC 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.
You dropped my tags again, if there is going to be a v9 please add:
here, so just above your Signed-off-by.
Quoted 1 line
Signed-off-by Dave Carey <[email protected]>
Regards,
Hans
Quoted 44 lines
--- drivers/platform/x86/lenovo/ymc.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)drivers/platform/x86/lenovo/ymc.c +19
-1@@ -23,7 +23,23 @@ module_param(force, bool, 0444);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 = {@@ -100,7 +116,10 @@ static int lenovo_ymc_probe(struct wmi_device *wdev, const void *ctx)struct lenovo_ymc_private *priv;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" ); --2.54.0
Re: [PATCH v8 2/2] platform/x86/lenovo: Add Yoga Book 9 keyboard dock detection driver
In reply to Dave CareyHi,
Quoted 30 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: one on the event GUID (LENOVO_BTKBD_EVENT) and one on the block GUID (LENOVO_FEATURE_STATUS_DATA).
- On probe, reads initial BKBD state viawmidev_query_block()on the block device; whichever driver probes last triggers the initial read.
- On WMI notification, reads BKBD directly from the event data integer
Quoted 9 lines
(ACPI _WED(0xEB) returns EC.BKBD) without a redundant WQAF call.- Reports SW_TABLET_MODE=1 when detached, SW_TABLET_MODE=0 when docked in either position (a physical keyboard is present in both cases).
- Exposes the raw BKBD value via read-only sysfs attribute "keyboard_position".
- Re-reads BKBD state on resume from suspend or hibernation.Tested on: Lenovo Yoga Book 9 14IAH10 (model 83KJ), kernel 7.0.
Quoted 1 line
Signed-off-by Dave Carey <[email protected]>
Regards,
Hans
Quoted 479 lines
---
v8:
- Add #include <linux/bits.h> (required for GENMASK).
- Add #include <linux/dev_printk.h> (explicit include for dev_warn/dev_dbg).
- Use__MUTEX_INITIALIZER(yb9.lock)for static mutex initialization; removesmutex_init()call and the need formutex_destroy().
- Updatewmidev_query_block()call to pass min_size=8; remove manual length check that is now handled by the WMI core.
- Move u8 *data__free(kfree)declaration to immediately after the successfulwmidev_query_block()call (cleanup.hconvention).
- Change data type from void * to u8 * to allow pointer arithmetic without cast.
- Remove (int) cast fromFIELD_GET()return value.
- Remove blank line betweenyb9_kbdock_query_locked()call and error check inkeyboard_position_show().
- Use %d format specifier insysfs_emit(); remove (unsigned int) cast.v7:
- Usewmidev_query_block()in place of deprecatedwmidev_block_query(). Use__free(kfree)to manage the output buffer; simplify the parsing to a single length check now that the WMI core handles type conversion.
- DefineBKBD_FIELDwithGENMASK()and extract the field withFIELD_GET()instead of open-coded masking.
- Use guard(mutex) for all lock/unlock pairs.
- Addyb9_kbdock_sync_locked()helper to consolidate the duplicated initial-state read pattern inevent_probe,block_probe, and resume.
- Addlinux/bitfield.h,linux/cleanup.h,linux/slab.hincludes.
- Fix comment on struct mutex field; use Context:/Returns: sections in the kerneldoc comment foryb9_kbdock_query_locked().v6:
- Submitted as 2/2; patch 1/2 adds a DMI early-exit to lenovo-ymc to prevent duplicateSW_TABLET_MODEinput nodes on the YB9.v5:
- Rewrote as two WMI drivers (event + block) to avoid the deprecatedwmi_query_block()API: event driver owns the GUID that delivers notifications, block driver owns the GUID used for querying state. Either can probe first; both probe callbacks check whether the other has already probed and fire the initial read when both are ready.
- Usewmidev_block_query()on the blockwmi_devicedirectly (replaces the deprecatedwmi_query_block()).
- In the notify callback, read BKBD directly from the event data integer passed by the WMI core (_WED(0xEB)returns EC.BKBD; confirmed by decoding the embedded BMOF from WQDD). Eliminates the redundant WQAF call that v4 made on every notification.
- Documented the two BMOF classes (LENOVO_BTKBD_EVENTandLENOVO_FEATURE_STATUS_DATA) with field layouts in the commit message and file header.
- sysfskeyboard_position: output bare integer, drop the parenthetical position-name suffix that a couple of reviewers found non-standard.
- Set .no_singleton = true on both WMI drivers (was missing from block driver in v4).
- Add PM resume callback (yb9_kbdock_resume) to re-read BKBD state after suspend/hibernation.v4:
- Droppedmodule_wmi_driver(); registered two WMI drivers manually to allow sharing state. module_init/exit pair registers/unregisters both.
- AddedATTRIBUTE_GROUPS()and .dev_groups for the sysfs attribute.
- sysfs show: performed a live query instead of returning a cached value.v3:
- Switched todevm_input_allocate_device().
- Added DMI guard (dmi_check_system) to reject non-YB9 machines.
- Removed redundantMODULE_DEVICE_TABLEon block driver.v2:
- Added .no_singleton = true on the event WMI driver.
- Added PM suspend/resume skeleton.
- FixedMODULE_LICENSEto "GPL" (was "GPL v2")..../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: April 2026 +KernelVersion: 6.10 +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 +312
-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. +* +* 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/bitfield.h> +#include <linux/bits.h> +#include <linux/cleanup.h> +#include <linux/dev_printk.h> +#include <linux/dmi.h> +#include <linux/input.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/pm.h> +#include <linux/slab.h> +#include <linux/wmi.h> + +#define YB9_KBDOCK_EVENT_GUID "806BD2A2-177B-481D-BFB5-3BA0BB4A2285" +#define YB9_KBDOCK_QUERY_GUID "E7F300FA-21CD-4003-ADAC-2696135982E6" + +/* 2-bit EC field encoding the keyboard dock position */ +#define BKBD_FIELD GENMASK(1, 0) + +/* BKBD encoding */ +#define BKBD_DETACHED 0 +#define BKBD_TOP_HALF 1 +#define BKBD_BOTTOM_HALF 2 + +static const struct dmi_system_id yb9_kbdock_dmi_table[] = { + { +/* Lenovo Yoga Book 9 14IAH10 */ + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"83KJ" ), + }, + }, + { } +}; + +/* +* Shared state between the event and block WMI drivers. Protected by lock. +* The lock may be held across wmidev_query_block() calls (which can sleep); +* block_remove() acquires the lock before clearing block_wdev, ensuring +* block_wdev remains valid for the duration of any in-progress query. +*/ +static struct { +struct mutex lock;/* protects input_dev and block_wdev */ +struct input_dev *input_dev;/* set by event probe */ +struct wmi_device *block_wdev;/* set by block probe */ +} yb9 = { + .lock =__MUTEX_INITIALIZER (yb9.lock), +}; + +/** +* yb9_kbdock_query_locked() - Read BKBD from the block device. +* @log_dev: Device for logging. +* +* Context: Caller must hold yb9.lock. +* Returns: 0-3 on success, -errno on failure. +*/ +static int yb9_kbdock_query_locked (struct device *log_dev) +{ +struct wmi_buffer out = {}; +u32 bkbd; +int ret; + +if (!yb9.block_wdev) +return -ENODEV ; + + ret =wmidev_query_block (yb9.block_wdev,0 , &out,8 ); +if (ret) { +dev_warn (log_dev,"WQAF failed: %d\n" , ret); +return ret; + } + + u8 *data __free(kfree) = out.data; + +/* +* LENOVO_FEATURE_STATUS_DATA: 8-byte buffer {IDs=0x00060000, Status=BKBD}. +* BKBD is at bytes 4-7. +*/ +memcpy (&bkbd, data +4 ,sizeof (bkbd)); +return FIELD_GET (BKBD_FIELD , bkbd); +} + +/* Report SW_TABLET_MODE from BKBD. Caller must hold yb9.lock. */ +static void yb9_kbdock_report_locked (int bkbd,struct device *log_dev) +{ +int tablet = (bkbd ==BKBD_DETACHED ) ?1 :0 ; + +input_report_switch (yb9.input_dev,SW_TABLET_MODE , tablet); +input_sync (yb9.input_dev); +dev_dbg (log_dev,"BKBD=%d SW_TABLET_MODE=%d\n" , bkbd, tablet); +} + +/* Read BKBD and report if both WMI devices are ready. Caller must hold yb9.lock. */ +static void yb9_kbdock_sync_locked (struct device *log_dev) +{ +int bkbd; + +if (!yb9.input_dev || !yb9.block_wdev) +return ; + + bkbd =yb9_kbdock_query_locked (log_dev); +if (bkbd >=0 ) +yb9_kbdock_report_locked (bkbd, log_dev); +} + +/* ------------------------------------------------------------------ +* sysfs +* ------------------------------------------------------------------ */ + +static ssize_t keyboard_position_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +int bkbd; + +guard (mutex)(&yb9.lock); + bkbd =yb9_kbdock_query_locked (dev); +if (bkbd <0 ) +return bkbd; +return sysfs_emit (buf,"%d\n" , bkbd); +} +static DEVICE_ATTR_RO (keyboard_position); + +static struct attribute *yb9_kbdock_attrs[] = { + &dev_attr_keyboard_position.attr, +NULL , +}; +ATTRIBUTE_GROUPS (yb9_kbdock); + +/* ------------------------------------------------------------------ +* Event WMI driver — LENOVO_BTKBD_EVENT +* ------------------------------------------------------------------ */ + +static void yb9_kbdock_notify (struct wmi_device *wdev,union acpi_object *data) +{ +u32 bkbd; + +/* +* _WED(0xEB) returns EC.BKBD directly as an integer +* (LENOVO_BTKBD_EVENT WmiDataId(1) uint32 Status). +*/ +if (!data || data->type !=ACPI_TYPE_INTEGER ) { +dev_warn (&wdev->dev,"unexpected event data type %d\n" , + data ? data->type :-1 ); +return ; + } + bkbd =FIELD_GET (BKBD_FIELD , data->integer.value); + +guard (mutex)(&yb9.lock); +if (yb9.input_dev) +yb9_kbdock_report_locked (bkbd, &wdev->dev); +} + +static int yb9_kbdock_event_probe (struct wmi_device *wdev,const void *ctx) +{ +struct input_dev *input_dev; +int err; + +if (!dmi_check_system (yb9_kbdock_dmi_table)) +return -ENODEV ; + + input_dev =devm_input_allocate_device (&wdev->dev); +if (!input_dev) +return -ENOMEM ; + + input_dev->name ="Lenovo Yoga Book 9 keyboard dock switch" ; + input_dev->phys =YB9_KBDOCK_EVENT_GUID "/input0" ; + input_dev->id.bustype =BUS_HOST ; +input_set_capability (input_dev,EV_SW ,SW_TABLET_MODE ); + + err =input_register_device (input_dev); +if (err) +return err; + +guard (mutex)(&yb9.lock); + yb9.input_dev = input_dev; +yb9_kbdock_sync_locked (&wdev->dev); +return 0 ; +} + +static void yb9_kbdock_event_remove (struct wmi_device *wdev) +{ +guard (mutex)(&yb9.lock); + yb9.input_dev =NULL ; +} + +static int yb9_kbdock_resume (struct device *dev) +{ +guard (mutex)(&yb9.lock); +yb9_kbdock_sync_locked (dev); +return 0 ; +} + +static DEFINE_SIMPLE_DEV_PM_OPS(yb9_kbdock_pm_ops, NULL, yb9_kbdock_resume); + +static const struct wmi_device_id yb9_kbdock_event_id_table[] = { + { .guid_string =YB9_KBDOCK_EVENT_GUID }, + { } +}; +MODULE_DEVICE_TABLE (wmi, yb9_kbdock_event_id_table); + +static struct wmi_driver yb9_kbdock_event_driver = { + .driver = { + .name ="lenovo-yb9-kbdock" , + .dev_groups = yb9_kbdock_groups, + .pm =pm_sleep_ptr (&yb9_kbdock_pm_ops), + }, + .id_table = yb9_kbdock_event_id_table, + .no_singleton = true, + .probe = yb9_kbdock_event_probe, + .remove = yb9_kbdock_event_remove, + .notify = yb9_kbdock_notify, +}; + +/* ------------------------------------------------------------------ +* Block WMI driver — LENOVO_FEATURE_STATUS_DATA +* ------------------------------------------------------------------ */ + +static int yb9_kbdock_block_probe (struct wmi_device *wdev,const void *ctx) +{ +if (!dmi_check_system (yb9_kbdock_dmi_table)) +return -ENODEV ; + +guard (mutex)(&yb9.lock); + yb9.block_wdev = wdev; +yb9_kbdock_sync_locked (&wdev->dev); +return 0 ; +} + +static void yb9_kbdock_block_remove (struct wmi_device *wdev) +{ +guard (mutex)(&yb9.lock); + yb9.block_wdev =NULL ; +} + +static const struct wmi_device_id yb9_kbdock_block_id_table[] = { + { .guid_string =YB9_KBDOCK_QUERY_GUID }, + { } +}; + +static struct wmi_driver yb9_kbdock_block_driver = { + .driver = { + .name ="lenovo-yb9-kbdock-block" , + }, + .id_table = yb9_kbdock_block_id_table, + .no_singleton = true, + .probe = yb9_kbdock_block_probe, + .remove = yb9_kbdock_block_remove, +}; + +/* ------------------------------------------------------------------ +* Module init / exit +* ------------------------------------------------------------------ */ + +static int __init yb9_kbdock_init (void ) +{ +int ret; + + ret =wmi_driver_register (&yb9_kbdock_event_driver); +if (ret) +return ret; + + ret =wmi_driver_register (&yb9_kbdock_block_driver); +if (ret) { +wmi_driver_unregister (&yb9_kbdock_event_driver); +return ret; + } +return 0 ; +} +module_init (yb9_kbdock_init); + +static void __exit yb9_kbdock_exit(void) +{ +wmi_driver_unregister (&yb9_kbdock_block_driver); +wmi_driver_unregister (&yb9_kbdock_event_driver); +} +module_exit (yb9_kbdock_exit); + +MODULE_AUTHOR ("Dave Carey <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo Yoga Book 9 keyboard dock detection" ); +MODULE_LICENSE ("GPL" );
Armin Wolf
NAKRe: [PATCH v8 2/2] platform/x86/lenovo: Add Yoga Book 9 keyboard dock detection driver
In reply to Dave CareyAm 10.06.26 um 17:53 schrieb Dave Carey:
Quoted 10 lines
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:
Quoted 7 lines
LENOVO_BTKBD_EVENT(event GUID): WmiDataId(1) uint32 Status. The ACPI_WED(0xEB)method returns EC.cd 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.
Hi,
how many instances of the LENOVO_FEATURE_STATUS_DATA data block exist? You can check this with the lswmi tool (https://pypi.org/project/lswmi/).
Quoted 261 lines
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: one on the event GUID (LENOVO_BTKBD_EVENT) and one on the block GUID (LENOVO_FEATURE_STATUS_DATA).
- On probe, reads initial BKBD state viawmidev_query_block()on the block device; whichever driver probes last triggers the initial read.
- On WMI notification, reads BKBD directly from the event data integer(ACPI _WED(0xEB) returns EC.BKBD) without a redundant WQAF call.- Reports SW_TABLET_MODE=1 when detached, SW_TABLET_MODE=0 when docked in either position (a physical keyboard is present in both cases).
- Exposes the raw BKBD value via read-only sysfs attribute "keyboard_position".
- Re-reads BKBD state on resume from suspend or hibernation.Tested on: Lenovo Yoga Book 9 14IAH10 (model 83KJ), kernel 7.0.
Signed-off-by Dave Carey <[email protected]>---
v8:
- Add #include <linux/bits.h> (required for GENMASK).
- Add #include <linux/dev_printk.h> (explicit include for dev_warn/dev_dbg).
- Use__MUTEX_INITIALIZER(yb9.lock)for static mutex initialization; removesmutex_init()call and the need formutex_destroy().
- Updatewmidev_query_block()call to pass min_size=8; remove manual length check that is now handled by the WMI core.
- Move u8 *data__free(kfree)declaration to immediately after the successfulwmidev_query_block()call (cleanup.hconvention).
- Change data type from void * to u8 * to allow pointer arithmetic without cast.
- Remove (int) cast fromFIELD_GET()return value.
- Remove blank line betweenyb9_kbdock_query_locked()call and error check inkeyboard_position_show().
- Use %d format specifier insysfs_emit(); remove (unsigned int) cast.v7:
- Usewmidev_query_block()in place of deprecatedwmidev_block_query(). Use__free(kfree)to manage the output buffer; simplify the parsing to a single length check now that the WMI core handles type conversion.
- DefineBKBD_FIELDwithGENMASK()and extract the field withFIELD_GET()instead of open-coded masking.
- Use guard(mutex) for all lock/unlock pairs.
- Addyb9_kbdock_sync_locked()helper to consolidate the duplicated initial-state read pattern inevent_probe,block_probe, and resume.
- Addlinux/bitfield.h,linux/cleanup.h,linux/slab.hincludes.
- Fix comment on struct mutex field; use Context:/Returns: sections in the kerneldoc comment foryb9_kbdock_query_locked().v6:
- Submitted as 2/2; patch 1/2 adds a DMI early-exit to lenovo-ymc to prevent duplicateSW_TABLET_MODEinput nodes on the YB9.v5:
- Rewrote as two WMI drivers (event + block) to avoid the deprecatedwmi_query_block()API: event driver owns the GUID that delivers notifications, block driver owns the GUID used for querying state. Either can probe first; both probe callbacks check whether the other has already probed and fire the initial read when both are ready.
- Usewmidev_block_query()on the blockwmi_devicedirectly (replaces the deprecatedwmi_query_block()).
- In the notify callback, read BKBD directly from the event data integer passed by the WMI core (_WED(0xEB)returns EC.BKBD; confirmed by decoding the embedded BMOF from WQDD). Eliminates the redundant WQAF call that v4 made on every notification.
- Documented the two BMOF classes (LENOVO_BTKBD_EVENTandLENOVO_FEATURE_STATUS_DATA) with field layouts in the commit message and file header.
- sysfskeyboard_position: output bare integer, drop the parenthetical position-name suffix that a couple of reviewers found non-standard.
- Set .no_singleton = true on both WMI drivers (was missing from block driver in v4).
- Add PM resume callback (yb9_kbdock_resume) to re-read BKBD state after suspend/hibernation.v4:
- Droppedmodule_wmi_driver(); registered two WMI drivers manually to allow sharing state. module_init/exit pair registers/unregisters both.
- AddedATTRIBUTE_GROUPS()and .dev_groups for the sysfs attribute.
- sysfs show: performed a live query instead of returning a cached value.v3:
- Switched todevm_input_allocate_device().
- Added DMI guard (dmi_check_system) to reject non-YB9 machines.
- Removed redundantMODULE_DEVICE_TABLEon block driver.v2:
- Added .no_singleton = true on the event WMI driver.
- Added PM suspend/resume skeleton.
- FixedMODULE_LICENSEto "GPL" (was "GPL v2")..../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: April 2026 +KernelVersion: 6.10 +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 +71
-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. +* +* 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/bitfield.h> +#include <linux/bits.h> +#include <linux/cleanup.h> +#include <linux/dev_printk.h> +#include <linux/dmi.h> +#include <linux/input.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/pm.h> +#include <linux/slab.h> +#include <linux/wmi.h> + +#define YB9_KBDOCK_EVENT_GUID "806BD2A2-177B-481D-BFB5-3BA0BB4A2285" +#define YB9_KBDOCK_QUERY_GUID "E7F300FA-21CD-4003-ADAC-2696135982E6" + +/* 2-bit EC field encoding the keyboard dock position */ +#define BKBD_FIELD GENMASK(1, 0) + +/* BKBD encoding */ +#define BKBD_DETACHED 0 +#define BKBD_TOP_HALF 1 +#define BKBD_BOTTOM_HALF 2 + +static const struct dmi_system_id yb9_kbdock_dmi_table[] = { + { +/* Lenovo Yoga Book 9 14IAH10 */ + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"83KJ" ), + }, + }, + { } +}; + +/* +* Shared state between the event and block WMI drivers. Protected by lock. +* The lock may be held across wmidev_query_block() calls (which can sleep);
drivers/platform/x86/lenovo/yb9-kbdock.c line 81
Quoted 10 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +10
-0+* block_remove() acquires the lock before clearing block_wdev, ensuring +* block_wdev remains valid for the duration of any in-progress query. +*/ +static struct { +struct mutex lock;/* protects input_dev and block_wdev */ +struct input_dev *input_dev;/* set by event probe */ +struct wmi_device *block_wdev;/* set by block probe */ +} yb9 = { + .lock =__MUTEX_INITIALIZER (yb9.lock), +};
Nack, having global data like this is not a good idea. Please use a notifier like uniwill-wmi.c to deliver WMI events to the WMI block driver, and put the input device into the private data struct of said driver.
This would also allow you to get rid of the mutex.
Quoted 8 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +8
-0+ +/** +* yb9_kbdock_query_locked() - Read BKBD from the block device. +* @log_dev: Device for logging. +* +* Context: Caller must hold yb9.lock. +* Returns: 0-3 on success, -errno on failure. +*/
drivers/platform/x86/lenovo/yb9-kbdock.c line 99
Quoted 10 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +10
-0+static int yb9_kbdock_query_locked (struct device *log_dev) +{ +struct wmi_buffer out = {}; +u32 bkbd; +int ret; + +if (!yb9.block_wdev) +return -ENODEV ; + + ret =wmidev_query_block (yb9.block_wdev,0 , &out,8 );
Please define a struct like this:
struct lenovo_feature_status {
__le32 id;
__le32 status;
} __packed;You should then use said struct for size calculations using sizeof() and for accessing the individual fields using le32_to_cpu().
drivers/platform/x86/lenovo/yb9-kbdock.c line 101
Quoted 2 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +2
-0+if (ret) { +dev_warn (log_dev,"WQAF failed: %d\n" , ret);
Please drop the error message, passing on the error code should be enough.
drivers/platform/x86/lenovo/yb9-kbdock.c line 112
Quoted 11 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +11
-0+return ret; + } + + u8 *data __free(kfree) = out.data; + +/* +* LENOVO_FEATURE_STATUS_DATA: 8-byte buffer {IDs=0x00060000, Status=BKBD}. +* BKBD is at bytes 4-7. +*/ +memcpy (&bkbd, data +4 ,sizeof (bkbd)); +return FIELD_GET (BKBD_FIELD , bkbd);
I think the whole 32-bit status field is meant to be used instead of only the first 2 bits. Can you share the output of "acpidump" on this machine so i can take a look myself?
IMHO we should verify here that the ID value is correct.
Quoted 31 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +31
-0+} + +/* Report SW_TABLET_MODE from BKBD. Caller must hold yb9.lock. */ +static void yb9_kbdock_report_locked (int bkbd,struct device *log_dev) +{ +int tablet = (bkbd ==BKBD_DETACHED ) ?1 :0 ; + +input_report_switch (yb9.input_dev,SW_TABLET_MODE , tablet); +input_sync (yb9.input_dev); +dev_dbg (log_dev,"BKBD=%d SW_TABLET_MODE=%d\n" , bkbd, tablet); +} + +/* Read BKBD and report if both WMI devices are ready. Caller must hold yb9.lock. */ +static void yb9_kbdock_sync_locked (struct device *log_dev) +{ +int bkbd; + +if (!yb9.input_dev || !yb9.block_wdev) +return ; + + bkbd =yb9_kbdock_query_locked (log_dev); +if (bkbd >=0 ) +yb9_kbdock_report_locked (bkbd, log_dev); +} + +/* ------------------------------------------------------------------ +* sysfs +* ------------------------------------------------------------------ */ + +static ssize_t keyboard_position_show (struct device *dev, +struct device_attribute *attr,char *buf)
drivers/platform/x86/lenovo/yb9-kbdock.c line 153
Quoted 10 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +10
-0+{ +int bkbd; + +guard (mutex)(&yb9.lock); + bkbd =yb9_kbdock_query_locked (dev); +if (bkbd <0 ) +return bkbd; +return sysfs_emit (buf,"%d\n" , bkbd); +} +static DEVICE_ATTR_RO (keyboard_position);
Please mark this attribute as const. The same should be done with yb9_kbdock_attrs[].
Quoted 19 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +19
-0+ +static struct attribute *yb9_kbdock_attrs[] = { + &dev_attr_keyboard_position.attr, +NULL , +}; +ATTRIBUTE_GROUPS (yb9_kbdock); + +/* ------------------------------------------------------------------ +* Event WMI driver — LENOVO_BTKBD_EVENT +* ------------------------------------------------------------------ */ + +static void yb9_kbdock_notify (struct wmi_device *wdev,union acpi_object *data) +{ +u32 bkbd; + +/* +* _WED(0xEB) returns EC.BKBD directly as an integer +* (LENOVO_BTKBD_EVENT WmiDataId(1) uint32 Status). +*/
drivers/platform/x86/lenovo/yb9-kbdock.c line 182
Quoted 10 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +10
-0+if (!data || data->type !=ACPI_TYPE_INTEGER ) { +dev_warn (&wdev->dev,"unexpected event data type %d\n" , + data ? data->type :-1 ); +return ; + } + bkbd =FIELD_GET (BKBD_FIELD , data->integer.value); + +guard (mutex)(&yb9.lock); +if (yb9.input_dev) +yb9_kbdock_report_locked (bkbd, &wdev->dev);
Please use .notify_new() instead of .notify() to avoid having to deal with ACPI objects.
Quoted 96 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +96
-0+} + +static int yb9_kbdock_event_probe (struct wmi_device *wdev,const void *ctx) +{ +struct input_dev *input_dev; +int err; + +if (!dmi_check_system (yb9_kbdock_dmi_table)) +return -ENODEV ; + + input_dev =devm_input_allocate_device (&wdev->dev); +if (!input_dev) +return -ENOMEM ; + + input_dev->name ="Lenovo Yoga Book 9 keyboard dock switch" ; + input_dev->phys =YB9_KBDOCK_EVENT_GUID "/input0" ; + input_dev->id.bustype =BUS_HOST ; +input_set_capability (input_dev,EV_SW ,SW_TABLET_MODE ); + + err =input_register_device (input_dev); +if (err) +return err; + +guard (mutex)(&yb9.lock); + yb9.input_dev = input_dev; +yb9_kbdock_sync_locked (&wdev->dev); +return 0 ; +} + +static void yb9_kbdock_event_remove (struct wmi_device *wdev) +{ +guard (mutex)(&yb9.lock); + yb9.input_dev =NULL ; +} + +static int yb9_kbdock_resume (struct device *dev) +{ +guard (mutex)(&yb9.lock); +yb9_kbdock_sync_locked (dev); +return 0 ; +} + +static DEFINE_SIMPLE_DEV_PM_OPS(yb9_kbdock_pm_ops, NULL, yb9_kbdock_resume); + +static const struct wmi_device_id yb9_kbdock_event_id_table[] = { + { .guid_string =YB9_KBDOCK_EVENT_GUID }, + { } +}; +MODULE_DEVICE_TABLE (wmi, yb9_kbdock_event_id_table); + +static struct wmi_driver yb9_kbdock_event_driver = { + .driver = { + .name ="lenovo-yb9-kbdock" , + .dev_groups = yb9_kbdock_groups, + .pm =pm_sleep_ptr (&yb9_kbdock_pm_ops), + }, + .id_table = yb9_kbdock_event_id_table, + .no_singleton = true, + .probe = yb9_kbdock_event_probe, + .remove = yb9_kbdock_event_remove, + .notify = yb9_kbdock_notify, +}; + +/* ------------------------------------------------------------------ +* Block WMI driver — LENOVO_FEATURE_STATUS_DATA +* ------------------------------------------------------------------ */ + +static int yb9_kbdock_block_probe (struct wmi_device *wdev,const void *ctx) +{ +if (!dmi_check_system (yb9_kbdock_dmi_table)) +return -ENODEV ; + +guard (mutex)(&yb9.lock); + yb9.block_wdev = wdev; +yb9_kbdock_sync_locked (&wdev->dev); +return 0 ; +} + +static void yb9_kbdock_block_remove (struct wmi_device *wdev) +{ +guard (mutex)(&yb9.lock); + yb9.block_wdev =NULL ; +} + +static const struct wmi_device_id yb9_kbdock_block_id_table[] = { + { .guid_string =YB9_KBDOCK_QUERY_GUID }, + { } +}; + +static struct wmi_driver yb9_kbdock_block_driver = { + .driver = { + .name ="lenovo-yb9-kbdock-block" , + }, + .id_table = yb9_kbdock_block_id_table, + .no_singleton = true, + .probe = yb9_kbdock_block_probe,
drivers/platform/x86/lenovo/yb9-kbdock.c line 288
Quoted 10 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +10
-0+ .remove = yb9_kbdock_block_remove, +}; + +/* ------------------------------------------------------------------ +* Module init / exit +* ------------------------------------------------------------------ */ + +static int __init yb9_kbdock_init (void ) +{ +int ret;
I think you should do the DMI check here. This would allow you to mark the DMI whitelist as __initconst.
Thanks,
Armin Wolf
Quoted 24 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +24
-0+ + ret =wmi_driver_register (&yb9_kbdock_event_driver); +if (ret) +return ret; + + ret =wmi_driver_register (&yb9_kbdock_block_driver); +if (ret) { +wmi_driver_unregister (&yb9_kbdock_event_driver); +return ret; + } +return 0 ; +} +module_init (yb9_kbdock_init); + +static void __exit yb9_kbdock_exit(void) +{ +wmi_driver_unregister (&yb9_kbdock_block_driver); +wmi_driver_unregister (&yb9_kbdock_event_driver); +} +module_exit (yb9_kbdock_exit); + +MODULE_AUTHOR ("Dave Carey <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo Yoga Book 9 keyboard dock detection" ); +MODULE_LICENSE ("GPL" );
Dave Carey
maintainerRe: [PATCH v8 2/2] platform/x86/lenovo: Add Yoga Book 9 keyboard dock detection driver
Quoted 2 lines · Armin Wolf
how many instances of the
LENOVO_FEATURE_STATUS_DATAdata block exist? You can check this with the lswmi tool (https://pypi.org/project/lswmi/).
One instance:
E7F300FA-21CD-4003-ADAC-2696135982E6: Data (Instances: 1)
Quoted 9 lines
Please define a struct like this:
struct lenovo_feature_status { __le32 id; __le32 status; } __packed;You should then use said struct for size calculations using
sizeof()and for accessing the individual fields usingle32_to_cpu().
Understood, will do.
Quoted 1 line
Please drop the error message, passing on the error code should be enough.
Will do.
Quoted 6 lines
I think the whole 32-bit status field is meant to be used instead of only the first 2 bits.
Can you share the output of "acpidump" on this machine so i can take a look myself?IMHO we should verify here that the ID value is correct.
The DSDT confirms the field layout. In the EC namespace, BKBD is declared as a 2-bit field:
Offset (0x23),
, 2,
PELF, 1,
, 1,
BKBD, 2, /* bits 4-5 of EC byte 0x23 */
, 1,
U7U9, 1,WQAF builds an 8-byte buffer and assigns EC0.BKBD to a 32-bit dword:
Name (LFSD, Buffer (0x08) { 0x00 })
CreateDWordField (LFSD, Zero, LFID)
CreateDWordField (LFSD, 0x04, LFST)
LFID = 0x00060000
If ((Acquire (EC0.LFCM, 0xA000) == Zero)) {
LFST = EC0.BKBD
Release (EC0.LFCM)
}
Return (LFSD)ACPI zero-extends the 2-bit BKBD value to 32 bits, so le32_to_cpu(fs->status) is always 0-3 and equals the full BKBD encoding. I'll use the status field directly and add an ID check (le32_to_cpu(fs->id) == 0x00060000) as you suggest.
_WED(0xEB) also reads EC0.BKBD directly and returns it as an integer, which is consistent.
I can provide the full acpidump if it would be useful; let me know.
Quoted 6 lines
Nack, having global data like this is not a good idea. Please use a notifier like
uniwill-wmi.cto deliver WMI events to the WMI block driver, and put the input device into the private data struct of said driver.This would also allow you to get rid of the mutex.
Understood. I'll restructure along the lines of uniwill-wmi.c:
- Event driver (LENOVO_BTKBD_EVENT) owns a BLOCKING_NOTIFIER_HEAD and fires it from its notify callback. It exports devm_yb9_kbdock_register_notifier() for consumers.
- Block driver (LENOVO_FEATURE_STATUS_DATA) owns the input_dev in its driver private data, registers a notifier_block at probe time, reads initial state via wmidev_query_block() on itself, and handles sysfs and PM resume.
No global struct, no mutex.
Quoted 2 lines
Please mark this attribute as const. The same should be done with yb9_kbdock_attrs[].
Will do.
Quoted 2 lines
Please use .notify_new() instead of .notify() to avoid having to deal with ACPI objects.
Will do. notify_new receives a const struct wmi_buffer *, which is cleaner for extracting the integer.
Quoted 2 lines
I think you should do the DMI check here. This would allow you to mark the DMI whitelist as
__initconst.
Good point. I'll move dmi_check_system() into yb9_kbdock_init() and mark the table __initconst.
Thanks,
Dave
Dave Carey
maintainerv9 cover platform/x86/lenovo: Yoga Book 9 keyboard dock detection
In reply to Dave CareyHi Armin,
Thank you for the v8 review. All nine items are addressed in v9:
- Added struct lenovo_feature_status { __le32 id; __le32 status; } __packed; and used it for size calculations and field access via le32_to_cpu().
- Added ID verification: return -EIO if le32_to_cpu(fs->id) != 0x00060000.
- Dropped the error message from yb9_kbdock_query(); returning the error code is sufficient.
- Replaced the global struct + mutex with a BLOCKING_NOTIFIER_HEAD at module scope. The event driver fires the chain from .notify_new(); the block driver registers a notifier_block and owns the input_dev in its per-device private struct. No global state, no mutex.
- Switched from .notify() to .notify_new() to receive a pre-parsed wmi_buffer directly.
- Marked yb9_kbdock_attrs[] and the attribute pointer as const.
- Moved dmi_check_system() to yb9_kbdock_init(); DMI table is now __initconst.
- Used le32_to_cpu(fs->status) directly (BKBD is zero-extended to 32 bits by ACPI); removed BKBD_FIELD masking and the BKBD_TOP_HALF / BKBD_BOTTOM_HALF constants (not needed by driver logic).
- Dropped #include <linux/bitfield.h>, <linux/bits.h>, and <linux/mutex.h> (no longer needed); added #include <linux/notifier.h>.
Patch 1/2 (lenovo-ymc) is unchanged from v8, with Hans de Goede's Reviewed-by tag added.
Tested on Lenovo Yoga Book 9 14IAH10 (model 83KJ), kernel 7.0.
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 | 310 ++++++++++++++++++ drivers/platform/x86/lenovo/ymc.c | 19 ++ 6 files changed, 370 insertions(+)
--
2.54.0
Dave Carey
maintainerPATCH v9 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
@@ -23,7 +23,23 @@ module_param(force, bool, 0444);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 = {
@@ -100,7 +116,10 @@ static int lenovo_ymc_probe(struct wmi_device *wdev, const void *ctx)struct lenovo_ymc_private *priv;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" );
--
2.54.0
Dave Carey
maintainerPATCH v9 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.
--- .../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 | 310 ++++++++++++++++++ 5 files changed, 351 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: April 2026 +KernelVersion: 6.10 +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 +310 -0
310 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v9 2/2] platform/x86/lenovo: Add Yoga Book 9 keyboard dock detection driver
Am 16.06.26 um 16:35 schrieb Dave Carey:
Quoted 67 lines
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]>Signed-off-by Dave Carey <[email protected]>--- .../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 | 310 ++++++++++++++++++ 5 files changed, 351 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 +0
-0
Documentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock line 3
Quoted 3 lines
Documentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock new file +3
-0@@ -0,0 +1,19 @@ +What: /sys/bus/wmi/drivers/lenovo-yb9-kbdock/<guid>/keyboard_position +Date: April 2026 +KernelVersion: 6.10
Hi,
please update the kernel version and date.
Quoted 133 lines
Documentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock new file +16
-0+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 +56
-0@@ -0,0 +1,310 @@ +// 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> +#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/wmi.h> + +#define YB9_KBDOCK_EVENT_GUID "806BD2A2-177B-481D-BFB5-3BA0BB4A2285" +#define YB9_KBDOCK_QUERY_GUID "E7F300FA-21CD-4003-ADAC-2696135982E6" + +/* BKBD encoding */ +#define BKBD_DETACHED 0 + +/* LENOVO_FEATURE_STATUS_DATA feature selector */
drivers/platform/x86/lenovo/yb9-kbdock.c line 66
Quoted 10 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +10
-0+#define YB9_FEATURE_STATUS_ID 0x00060000u + +/* +* LENOVO_FEATURE_STATUS_DATA: 8-byte buffer {uint32 IDs, uint32 Status}. +* IDs is always 0x00060000; Status holds the BKBD value (0–3). +*/ +struct lenovo_feature_status { +__le32 id; +__le32 status; +} __packed;
Please add:
#include <linux/compiler_attributes.h>
#include <linux/types.h>
Quoted 30 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +30
-0+ +/* ------------------------------------------------------------------ +* Notifier chain — event driver fires it, block driver listens +* ------------------------------------------------------------------ */ + +static BLOCKING_NOTIFIER_HEAD (yb9_kbdock_chain_head); + +static void devm_yb9_kbdock_unregister_notifier (void *data) +{ +struct notifier_block *nb = data; + +blocking_notifier_chain_unregister (&yb9_kbdock_chain_head, nb); +} + +static int devm_yb9_kbdock_register_notifier (struct device *dev, +struct notifier_block *nb) +{ +int ret; + + ret =blocking_notifier_chain_register (&yb9_kbdock_chain_head, nb); +if (ret <0 ) +return ret; + +return devm_add_action_or_reset (dev, devm_yb9_kbdock_unregister_notifier, nb); +} + +/* ------------------------------------------------------------------ +* Block WMI driver — LENOVO_FEATURE_STATUS_DATA +* (owns input_dev, sysfs, PM resume) +* ------------------------------------------------------------------ */
drivers/platform/x86/lenovo/yb9-kbdock.c line 106
Quoted 10 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +10
-0+ +struct yb9_kbdock_data { +struct wmi_device *wdev; +struct input_dev *input_dev; +struct notifier_block nb; +}; + +static int yb9_kbdock_query (struct yb9_kbdock_data *d) +{ +struct wmi_buffer out = {};
"out" does not need to be initialized.
drivers/platform/x86/lenovo/yb9-kbdock.c line 119
Quoted 13 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +13
-0+int ret; + + ret =wmidev_query_block (d->wdev,0 , &out, +sizeof (struct lenovo_feature_status )); +if (ret) +return ret; + + struct lenovo_feature_status *fs __free(kfree) = out.data; + +if (le32_to_cpu (fs->id) !=YB9_FEATURE_STATUS_ID ) +return -EIO ; + +return le32_to_cpu (fs->status);
I suggest you return "status" using a pointer argument:
static int yb9_kbdock_query(struct yb9_kbdock_data *d, u32 *bkbd)
The reason for this is that a status of 0xFFFFFFFF will be misinterpreted as -1 (error EPERM).
drivers/platform/x86/lenovo/yb9-kbdock.c line 128
Quoted 9 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +9
-0+} + +static void yb9_kbdock_report (struct yb9_kbdock_data *d,u32 bkbd) +{ +int tablet = (bkbd ==BKBD_DETACHED ) ?1 :0 ; + +input_report_switch (d->input_dev,SW_TABLET_MODE , tablet); +input_sync (d->input_dev); +dev_dbg (&d->wdev->dev,"BKBD=%u SW_TABLET_MODE=%d\n" , bkbd, tablet);
I think you should protect the input sequence with a spinlock.
drivers/platform/x86/lenovo/yb9-kbdock.c line 136
Quoted 8 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +8
-0+} + +static void yb9_kbdock_sync (struct yb9_kbdock_data *d) +{ +int bkbd =yb9_kbdock_query (d); + +if (bkbd >=0 ) +yb9_kbdock_report (d, bkbd);
Please propagate the errno back to the caller.
Quoted 14 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +14
-0+} + +static int yb9_kbdock_nb_call (struct notifier_block *nb, +unsigned long bkbd,void *unused) +{ +struct yb9_kbdock_data *d = + container_of(nb, struct yb9_kbdock_data, nb); + +yb9_kbdock_report (d, bkbd); +return NOTIFY_DONE ; +} + +static ssize_t keyboard_position_show(struct device *dev, + struct device_attribute *attr,
drivers/platform/x86/lenovo/yb9-kbdock.c line 160
Quoted 10 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +10
-0+ char *buf) +{ +struct yb9_kbdock_data *d =dev_get_drvdata (dev); +int bkbd =yb9_kbdock_query (d); + +if (bkbd <0 ) +return bkbd; +return sysfs_emit (buf,"%d\n" , bkbd); +} +static DEVICE_ATTR_RO (keyboard_position);
Can you make this const too?
drivers/platform/x86/lenovo/yb9-kbdock.c line 166
Quoted 6 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +6
-0+ +static const struct attribute *const yb9_kbdock_attrs[] = { + &dev_attr_keyboard_position.attr, +NULL , +}; +ATTRIBUTE_GROUPS (yb9_kbdock);
Can you make this const too?
drivers/platform/x86/lenovo/yb9-kbdock.c line 173
Quoted 7 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +7
-0+ +static int yb9_kbdock_resume (struct device *dev) +{ +struct yb9_kbdock_data *d =dev_get_drvdata (dev); + +yb9_kbdock_sync (d); +return 0 ;
Please propagate the error of yb9_kbdock_sync() here.
Quoted 27 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +27
-0+} +static DEFINE_SIMPLE_DEV_PM_OPS(yb9_kbdock_pm_ops, NULL, yb9_kbdock_resume); + +static int yb9_kbdock_block_probe (struct wmi_device *wdev,const void *ctx) +{ +struct yb9_kbdock_data *d; +struct input_dev *input_dev; +int ret; + + d =devm_kzalloc (&wdev->dev,sizeof (*d),GFP_KERNEL ); +if (!d) +return -ENOMEM ; + + d->wdev = wdev; + + input_dev =devm_input_allocate_device (&wdev->dev); +if (!input_dev) +return -ENOMEM ; + + input_dev->name ="Lenovo Yoga Book 9 keyboard dock switch" ; + input_dev->phys =YB9_KBDOCK_QUERY_GUID "/input0" ; + input_dev->id.bustype =BUS_HOST ; +input_set_capability (input_dev,EV_SW ,SW_TABLET_MODE ); + + ret =input_register_device (input_dev); +if (ret) +return ret;
drivers/platform/x86/lenovo/yb9-kbdock.c line 210
Quoted 10 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +10
-0+ + d->input_dev = input_dev; + d->nb.notifier_call = yb9_kbdock_nb_call; + + ret =devm_yb9_kbdock_register_notifier (&wdev->dev, &d->nb); +if (ret) +return ret; + +dev_set_drvdata (&wdev->dev, d); +yb9_kbdock_sync (d);
Please propagate the error of yb9_kbdock_sync() here.
Quoted 23 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +23
-0+return 0 ; +} + +static const struct wmi_device_id yb9_kbdock_block_id_table[] = { + { .guid_string =YB9_KBDOCK_QUERY_GUID }, + { } +}; + +static struct wmi_driver yb9_kbdock_block_driver = { + .driver = { + .name ="lenovo-yb9-kbdock" , + .dev_groups = yb9_kbdock_groups, + .pm =pm_sleep_ptr (&yb9_kbdock_pm_ops), + }, + .id_table = yb9_kbdock_block_id_table, + .no_singleton = true, + .probe = yb9_kbdock_block_probe, +}; + +/* ------------------------------------------------------------------ +* Event WMI driver — LENOVO_BTKBD_EVENT +* (fires the notifier chain on each WMI event) +* ------------------------------------------------------------------ */
drivers/platform/x86/lenovo/yb9-kbdock.c line 243
Quoted 10 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +10
-0+ +static void yb9_kbdock_notify_new (struct wmi_device *wdev, +const struct wmi_buffer *data) +{ +/* +* _WED(0xEB) returns EC.BKBD directly as a 32-bit integer +* (LENOVO_BTKBD_EVENT WmiDataId(1) uint32 Status). +*/ +if (!data || data->length <sizeof (__le32)) +return ;
Please use the .min_event_size field inside struct wmi_driver for this.
Otherwise the driver looks quite good to me.
Thanks,
Armin Wolf
Quoted 67 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +67
-0+ +u32 bkbd =le32_to_cpu (*(const __le32 *)data->data); + +blocking_notifier_call_chain (&yb9_kbdock_chain_head, bkbd,NULL ); +} + +static const struct wmi_device_id yb9_kbdock_event_id_table[] = { + { .guid_string =YB9_KBDOCK_EVENT_GUID }, + { } +}; +MODULE_DEVICE_TABLE (wmi, yb9_kbdock_event_id_table); + +static struct wmi_driver yb9_kbdock_event_driver = { + .driver = { + .name ="lenovo-yb9-kbdock-event" , + }, + .id_table = yb9_kbdock_event_id_table, + .no_singleton = true, + .notify_new = yb9_kbdock_notify_new, +}; + +/* ------------------------------------------------------------------ +* Module init / exit +* ------------------------------------------------------------------ */ + +static const struct dmi_system_id yb9_kbdock_dmi_table[]__initconst = { + { +/* Lenovo Yoga Book 9 14IAH10 */ + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"83KJ" ), + }, + }, + { } +}; + +static int __init yb9_kbdock_init (void ) +{ +int ret; + +if (!dmi_check_system (yb9_kbdock_dmi_table)) +return -ENODEV ; + + ret =wmi_driver_register (&yb9_kbdock_event_driver); +if (ret) +return ret; + + ret =wmi_driver_register (&yb9_kbdock_block_driver); +if (ret) { +wmi_driver_unregister (&yb9_kbdock_event_driver); +return ret; + } + +return 0 ; +} +module_init (yb9_kbdock_init); + +static void __exit yb9_kbdock_exit(void) +{ +wmi_driver_unregister (&yb9_kbdock_block_driver); +wmi_driver_unregister (&yb9_kbdock_event_driver); +} +module_exit (yb9_kbdock_exit); + +MODULE_AUTHOR ("Dave Carey <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo Yoga Book 9 keyboard dock detection" ); +MODULE_LICENSE ("GPL" );
Dave Carey
maintainerv10 cover Lenovo Yoga Book 9 keyboard dock detection
In reply to Dave CareyChanges 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 | 322 ++++++++++++ drivers/platform/x86/lenovo/ymc.c | 19 ++ 6 files changed, 382 insertions(+)
2.47.0
Dave Carey
maintainerPATCH v10 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
@@ -23,7 +23,23 @@ module_param(force, bool, 0444);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 = {
@@ -100,7 +116,10 @@ static int lenovo_ymc_probe(struct wmi_device *wdev, const void *ctx)struct lenovo_ymc_private *priv;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" );
--
2.54.0
Dave Carey
maintainerPATCH v10 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.
--- .../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 | 322 ++++++++++++++++++ 5 files changed, 363 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 2026 +KernelVersion: 6.16 +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_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 +322 -0
322 lines not on this page · raw message
2.47.0
Re: [PATCH v10 2/2] platform/x86/lenovo: Add Yoga Book 9 keyboard dock detection driver
Am 21.06.26 um 15:57 schrieb Dave Carey:
Quoted 67 lines
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]>Signed-off-by Dave Carey <[email protected]>--- .../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 | 322 ++++++++++++++++++ 5 files changed, 363 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 +0
-0
Documentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock line 3
Quoted 3 lines
Documentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock new file +3
-0@@ -0,0 +1,19 @@ +What: /sys/bus/wmi/drivers/lenovo-yb9-kbdock/<guid>/keyboard_position +Date: June 2026 +KernelVersion: 6.16
The Date and Version should show the date on which said ABI was accepted into the kernel. So June 2027, 7.3 would be correct.
Please fix.
Other than that:
Quoted 401 lines
Documentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock new file +16
-0+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_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 +322
-0@@ -0,0 +1,322 @@ +// 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> +#include <linux/compiler_attributes.h> +#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/spinlock.h> +#include <linux/types.h> +#include <linux/wmi.h> + +#define YB9_KBDOCK_EVENT_GUID "806BD2A2-177B-481D-BFB5-3BA0BB4A2285" +#define YB9_KBDOCK_QUERY_GUID "E7F300FA-21CD-4003-ADAC-2696135982E6" + +/* BKBD encoding */ +#define BKBD_DETACHED 0 + +/* LENOVO_FEATURE_STATUS_DATA feature selector */ +#define YB9_FEATURE_STATUS_ID 0x00060000u + +/* +* LENOVO_FEATURE_STATUS_DATA: 8-byte buffer {uint32 IDs, uint32 Status}. +* IDs is always 0x00060000; Status holds the BKBD value (0–3). +*/ +struct lenovo_feature_status { +__le32 id; +__le32 status; +} __packed; + +/* ------------------------------------------------------------------ +* Notifier chain — event driver fires it, block driver listens +* ------------------------------------------------------------------ */ + +static BLOCKING_NOTIFIER_HEAD (yb9_kbdock_chain_head); + +static void devm_yb9_kbdock_unregister_notifier (void *data) +{ +struct notifier_block *nb = data; + +blocking_notifier_chain_unregister (&yb9_kbdock_chain_head, nb); +} + +static int devm_yb9_kbdock_register_notifier (struct device *dev, +struct notifier_block *nb) +{ +int ret; + + ret =blocking_notifier_chain_register (&yb9_kbdock_chain_head, nb); +if (ret <0 ) +return ret; + +return devm_add_action_or_reset (dev, devm_yb9_kbdock_unregister_notifier, nb); +} + +/* ------------------------------------------------------------------ +* Block WMI driver — LENOVO_FEATURE_STATUS_DATA +* (owns input_dev, sysfs, PM resume) +* ------------------------------------------------------------------ */ + +struct yb9_kbdock_data { +struct wmi_device *wdev; +struct input_dev *input_dev; +struct notifier_block nb; +spinlock_t lock;/* protects input_report_switch + input_sync */ +}; + +static int yb9_kbdock_query (struct yb9_kbdock_data *d,u32 *bkbd) +{ +struct wmi_buffer out; +int ret; + + ret =wmidev_query_block (d->wdev,0 , &out, +sizeof (struct lenovo_feature_status )); +if (ret) +return ret; + + struct lenovo_feature_status *fs __free(kfree) = out.data; + +if (le32_to_cpu (fs->id) !=YB9_FEATURE_STATUS_ID ) +return -EIO ; + + *bkbd =le32_to_cpu (fs->status); +return 0 ; +} + +static void yb9_kbdock_report (struct yb9_kbdock_data *d,u32 bkbd) +{ +int tablet = (bkbd ==BKBD_DETACHED ) ?1 :0 ; + +spin_lock (&d->lock); +input_report_switch (d->input_dev,SW_TABLET_MODE , tablet); +input_sync (d->input_dev); +spin_unlock (&d->lock); +dev_dbg (&d->wdev->dev,"BKBD=%u SW_TABLET_MODE=%d\n" , bkbd, tablet); +} + +static int yb9_kbdock_sync (struct yb9_kbdock_data *d) +{ +u32 bkbd; +int ret; + + ret =yb9_kbdock_query (d, &bkbd); +if (ret) +return ret; + +yb9_kbdock_report (d, bkbd); +return 0 ; +} + +static int yb9_kbdock_nb_call (struct notifier_block *nb, +unsigned long bkbd,void *unused) +{ +struct yb9_kbdock_data *d = + container_of(nb, struct yb9_kbdock_data, nb); + +yb9_kbdock_report (d, bkbd); +return NOTIFY_DONE ; +} + +static ssize_t keyboard_position_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct yb9_kbdock_data *d =dev_get_drvdata (dev); +u32 bkbd; +int ret; + + ret =yb9_kbdock_query (d, &bkbd); +if (ret) +return ret; +return sysfs_emit (buf,"%u\n" , bkbd); +} +static DEVICE_ATTR_RO (keyboard_position); + +static const struct attribute *const yb9_kbdock_attrs[] = { + &dev_attr_keyboard_position.attr, +NULL , +}; +ATTRIBUTE_GROUPS (yb9_kbdock); + +static int yb9_kbdock_resume (struct device *dev) +{ +struct yb9_kbdock_data *d =dev_get_drvdata (dev); + +return yb9_kbdock_sync (d); +} +static DEFINE_SIMPLE_DEV_PM_OPS(yb9_kbdock_pm_ops, NULL, yb9_kbdock_resume); + +static int yb9_kbdock_block_probe (struct wmi_device *wdev,const void *ctx) +{ +struct yb9_kbdock_data *d; +struct input_dev *input_dev; +int ret; + + d =devm_kzalloc (&wdev->dev,sizeof (*d),GFP_KERNEL ); +if (!d) +return -ENOMEM ; + + d->wdev = wdev; +spin_lock_init (&d->lock); + + input_dev =devm_input_allocate_device (&wdev->dev); +if (!input_dev) +return -ENOMEM ; + + input_dev->name ="Lenovo Yoga Book 9 keyboard dock switch" ; + input_dev->phys =YB9_KBDOCK_QUERY_GUID "/input0" ; + input_dev->id.bustype =BUS_HOST ; +input_set_capability (input_dev,EV_SW ,SW_TABLET_MODE ); + + ret =input_register_device (input_dev); +if (ret) +return ret; + + d->input_dev = input_dev; + d->nb.notifier_call = yb9_kbdock_nb_call; + + ret =devm_yb9_kbdock_register_notifier (&wdev->dev, &d->nb); +if (ret) +return ret; + +dev_set_drvdata (&wdev->dev, d); +return yb9_kbdock_sync (d); +} + +static const struct wmi_device_id yb9_kbdock_block_id_table[] = { + { .guid_string =YB9_KBDOCK_QUERY_GUID }, + { } +}; + +static struct wmi_driver yb9_kbdock_block_driver = { + .driver = { + .name ="lenovo-yb9-kbdock" , + .dev_groups = yb9_kbdock_groups, + .pm =pm_sleep_ptr (&yb9_kbdock_pm_ops), + }, + .id_table = yb9_kbdock_block_id_table, + .no_singleton = true, + .probe = yb9_kbdock_block_probe, +}; + +/* ------------------------------------------------------------------ +* Event WMI driver — LENOVO_BTKBD_EVENT +* (fires the notifier chain on each WMI event) +* ------------------------------------------------------------------ */ + +static void yb9_kbdock_notify_new (struct wmi_device *wdev, +const struct wmi_buffer *data) +{ +/* +* _WED(0xEB) returns EC.BKBD directly as a 32-bit integer +* (LENOVO_BTKBD_EVENT WmiDataId(1) uint32 Status). +* Short-buffer guard is handled by .min_event_size below. +*/ +u32 bkbd =le32_to_cpu (*(const __le32 *)data->data); + +blocking_notifier_call_chain (&yb9_kbdock_chain_head, bkbd,NULL ); +} + +static const struct wmi_device_id yb9_kbdock_event_id_table[] = { + { .guid_string =YB9_KBDOCK_EVENT_GUID }, + { } +}; +MODULE_DEVICE_TABLE (wmi, yb9_kbdock_event_id_table); + +static struct wmi_driver yb9_kbdock_event_driver = { + .driver = { + .name ="lenovo-yb9-kbdock-event" , + }, + .id_table = yb9_kbdock_event_id_table, + .no_singleton = true, + .notify_new = yb9_kbdock_notify_new, + .min_event_size =sizeof (__le32), +}; + +/* ------------------------------------------------------------------ +* Module init / exit +* ------------------------------------------------------------------ */ + +static const struct dmi_system_id yb9_kbdock_dmi_table[]__initconst = { + { +/* Lenovo Yoga Book 9 14IAH10 */ + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"83KJ" ), + }, + }, + { } +}; + +static int __init yb9_kbdock_init (void ) +{ +int ret; + +if (!dmi_check_system (yb9_kbdock_dmi_table)) +return -ENODEV ; + + ret =wmi_driver_register (&yb9_kbdock_event_driver); +if (ret) +return ret; + + ret =wmi_driver_register (&yb9_kbdock_block_driver); +if (ret) { +wmi_driver_unregister (&yb9_kbdock_event_driver); +return ret; + } + +return 0 ; +} +module_init (yb9_kbdock_init); + +static void __exit yb9_kbdock_exit(void) +{ +wmi_driver_unregister (&yb9_kbdock_block_driver); +wmi_driver_unregister (&yb9_kbdock_event_driver); +} +module_exit (yb9_kbdock_exit); + +MODULE_AUTHOR ("Dave Carey <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo Yoga Book 9 keyboard dock detection" ); +MODULE_LICENSE ("GPL" );2.47.0
Dave Carey
maintainerv11 cover platform/x86/lenovo: Yoga Book 9 keyboard dock detection
Hi Armin,
Thanks for the v10 review. One-line fix in v11:
- 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 (Armin Wolf).
Armin's Reviewed-by tag has been added to patch 2/2.
Patch 1/2 (lenovo-ymc) is unchanged from v10.
Tested on Lenovo Yoga Book 9 14IAH10 (model 83KJ), kernel 7.0.
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 | 310 ++++++++++++++++++ drivers/platform/x86/lenovo/ymc.c | 19 ++ 6 files changed, 370 insertions(+)
--
2.54.0
Dave Carey
maintainerPATCH v11 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
@@ -23,7 +23,23 @@ module_param(force, bool, 0444);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 = {
@@ -100,7 +116,10 @@ static int lenovo_ymc_probe(struct wmi_device *wdev, const void *ctx)struct lenovo_ymc_private *priv;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" );
--
2.54.0
Dave Carey
maintainerPATCH v11 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.
---
v11:
- 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 (Armin Wolf).
v5:
- Rewrote as two WMI drivers (event + block) to avoid the deprecated wmi_query_block() API: event driver owns the GUID that delivers notifications, block driver owns the GUID used for querying state. Either can probe first; both probe callbacks check whether the other has already probed and fire the initial read when both are ready.
- Use wmidev_block_query() on the block wmi_device directly (replaces the deprecated wmi_query_block()).
- In the notify callback, read BKBD directly from the event data integer passed by the WMI core (_WED(0xEB) returns EC.BKBD; confirmed by decoding the embedded BMOF from WQDD). Eliminates the redundant WQAF call that v4 made on every notification.
- Documented the two BMOF classes (LENOVO_BTKBD_EVENT and LENOVO_FEATURE_STATUS_DATA) with field layouts in the commit message and file header.
- sysfs keyboard_position: output bare integer, drop the parenthetical position-name suffix that a couple of reviewers found non-standard.
- Set .no_singleton = true on both WMI drivers (was missing from block driver in v4).
- Add PM resume callback (yb9_kbdock_resume) to re-read BKBD state after suspend/hibernation.
v4:
- Dropped module_wmi_driver(); registered two WMI drivers manually to allow sharing state. module_init/exit pair registers/unregisters both.
- Added ATTRIBUTE_GROUPS() and .dev_groups for the sysfs attribute.
- sysfs show: performed a live query instead of returning a cached value.
v3:
- Switched to devm_input_allocate_device().
- Added DMI guard (dmi_check_system) to reject non-YB9 machines.
- Removed redundant MODULE_DEVICE_TABLE on block driver.
v2:
- Added .no_singleton = true on the event WMI driver.
- Added PM suspend/resume skeleton.
- Fixed MODULE_LICENSE to "GPL" (was "GPL v2").
.../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 | 310 ++++++++++++++++++ 5 files changed, 351 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 +310 -0
310 lines not on this page · raw message
Signature · 1 line
2.54.0
Ilpo Järvinen
maintainerRe: [PATCH v11 2/2] platform/x86/lenovo: Add Yoga Book 9 keyboard dock detection driver
Quoted 248 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]>---
v11:
- 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 (Armin Wolf).v5:
- Rewrote as two WMI drivers (event + block) to avoid the deprecatedwmi_query_block()API: event driver owns the GUID that delivers notifications, block driver owns the GUID used for querying state. Either can probe first; both probe callbacks check whether the other has already probed and fire the initial read when both are ready.
- Usewmidev_block_query()on the blockwmi_devicedirectly (replaces the deprecatedwmi_query_block()).
- In the notify callback, read BKBD directly from the event data integer passed by the WMI core (_WED(0xEB)returns EC.BKBD; confirmed by decoding the embedded BMOF from WQDD). Eliminates the redundant WQAF call that v4 made on every notification.
- Documented the two BMOF classes (LENOVO_BTKBD_EVENTandLENOVO_FEATURE_STATUS_DATA) with field layouts in the commit message and file header.
- sysfskeyboard_position: output bare integer, drop the parenthetical position-name suffix that a couple of reviewers found non-standard.
- Set .no_singleton = true on both WMI drivers (was missing from block driver in v4).
- Add PM resume callback (yb9_kbdock_resume) to re-read BKBD state after suspend/hibernation.v4:
- Droppedmodule_wmi_driver(); registered two WMI drivers manually to allow sharing state. module_init/exit pair registers/unregisters both.
- AddedATTRIBUTE_GROUPS()and .dev_groups for the sysfs attribute.
- sysfs show: performed a live query instead of returning a cached value.v3:
- Switched todevm_input_allocate_device().
- Added DMI guard (dmi_check_system) to reject non-YB9 machines.
- Removed redundantMODULE_DEVICE_TABLEon block driver.v2:
- Added .no_singleton = true on the event WMI driver.
- Added PM suspend/resume skeleton.
- FixedMODULE_LICENSEto "GPL" (was "GPL v2")..../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 | 310 ++++++++++++++++++ 5 files changed, 351 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 +56
-0@@ -0,0 +1,310 @@ +// 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> +#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/wmi.h> + +#define YB9_KBDOCK_EVENT_GUID "806BD2A2-177B-481D-BFB5-3BA0BB4A2285" +#define YB9_KBDOCK_QUERY_GUID "E7F300FA-21CD-4003-ADAC-2696135982E6" + +/* BKBD encoding */ +#define BKBD_DETACHED 0 + +/* LENOVO_FEATURE_STATUS_DATA feature selector */
drivers/platform/x86/lenovo/yb9-kbdock.c line 66
Quoted 10 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +10
-0+#define YB9_FEATURE_STATUS_ID 0x00060000u + +/* +* LENOVO_FEATURE_STATUS_DATA: 8-byte buffer {uint32 IDs, uint32 Status}. +* IDs is always 0x00060000; Status holds the BKBD value (0–3). +*/ +struct lenovo_feature_status { +__le32 id; +__le32 status; +} __packed;
Add includes for __packed and __le32.
Quoted 82 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +82
-0+ +/* ------------------------------------------------------------------ +* Notifier chain — event driver fires it, block driver listens +* ------------------------------------------------------------------ */ + +static BLOCKING_NOTIFIER_HEAD (yb9_kbdock_chain_head); + +static void devm_yb9_kbdock_unregister_notifier (void *data) +{ +struct notifier_block *nb = data; + +blocking_notifier_chain_unregister (&yb9_kbdock_chain_head, nb); +} + +static int devm_yb9_kbdock_register_notifier (struct device *dev, +struct notifier_block *nb) +{ +int ret; + + ret =blocking_notifier_chain_register (&yb9_kbdock_chain_head, nb); +if (ret <0 ) +return ret; + +return devm_add_action_or_reset (dev, devm_yb9_kbdock_unregister_notifier, nb); +} + +/* ------------------------------------------------------------------ +* Block WMI driver — LENOVO_FEATURE_STATUS_DATA +* (owns input_dev, sysfs, PM resume) +* ------------------------------------------------------------------ */ + +struct yb9_kbdock_data { +struct wmi_device *wdev; +struct input_dev *input_dev; +struct notifier_block nb; +}; + +static int yb9_kbdock_query (struct yb9_kbdock_data *d) +{ +struct wmi_buffer out = {}; +int ret; + + ret =wmidev_query_block (d->wdev,0 , &out, +sizeof (struct lenovo_feature_status )); +if (ret) +return ret; + + struct lenovo_feature_status *fs __free(kfree) = out.data; + +if (le32_to_cpu (fs->id) !=YB9_FEATURE_STATUS_ID ) +return -EIO ; + +return le32_to_cpu (fs->status); +} + +static void yb9_kbdock_report (struct yb9_kbdock_data *d,u32 bkbd) +{ +int tablet = (bkbd ==BKBD_DETACHED ) ?1 :0 ; + +input_report_switch (d->input_dev,SW_TABLET_MODE , tablet); +input_sync (d->input_dev); +dev_dbg (&d->wdev->dev,"BKBD=%u SW_TABLET_MODE=%d\n" , bkbd, tablet); +} + +static void yb9_kbdock_sync (struct yb9_kbdock_data *d) +{ +int bkbd =yb9_kbdock_query (d); + +if (bkbd >=0 ) +yb9_kbdock_report (d, bkbd); +} + +static int yb9_kbdock_nb_call (struct notifier_block *nb, +unsigned long bkbd,void *unused) +{ +struct yb9_kbdock_data *d = + container_of(nb, struct yb9_kbdock_data, nb); + +yb9_kbdock_report (d, bkbd); +return NOTIFY_DONE ; +} +
drivers/platform/x86/lenovo/yb9-kbdock.c line 158
Quoted 10 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +10
-0+static ssize_t keyboard_position_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct yb9_kbdock_data *d =dev_get_drvdata (dev); +int bkbd =yb9_kbdock_query (d); + +if (bkbd <0 ) +return bkbd; +return sysfs_emit (buf,"%d\n" , bkbd);
Add include.
Quoted 153 lines
drivers/platform/x86/lenovo/yb9-kbdock.c new file +152
-0+} +static DEVICE_ATTR_RO (keyboard_position); + +static const struct attribute *const yb9_kbdock_attrs[] = { + &dev_attr_keyboard_position.attr, +NULL , +}; +ATTRIBUTE_GROUPS (yb9_kbdock); + +static int yb9_kbdock_resume (struct device *dev) +{ +struct yb9_kbdock_data *d =dev_get_drvdata (dev); + +yb9_kbdock_sync (d); +return 0 ; +} +static DEFINE_SIMPLE_DEV_PM_OPS(yb9_kbdock_pm_ops, NULL, yb9_kbdock_resume); + +static int yb9_kbdock_block_probe (struct wmi_device *wdev,const void *ctx) +{ +struct yb9_kbdock_data *d; +struct input_dev *input_dev; +int ret; + + d =devm_kzalloc (&wdev->dev,sizeof (*d),GFP_KERNEL ); +if (!d) +return -ENOMEM ; + + d->wdev = wdev; + + input_dev =devm_input_allocate_device (&wdev->dev); +if (!input_dev) +return -ENOMEM ; + + input_dev->name ="Lenovo Yoga Book 9 keyboard dock switch" ; + input_dev->phys =YB9_KBDOCK_QUERY_GUID "/input0" ; + input_dev->id.bustype =BUS_HOST ; +input_set_capability (input_dev,EV_SW ,SW_TABLET_MODE ); + + ret =input_register_device (input_dev); +if (ret) +return ret; + + d->input_dev = input_dev; + d->nb.notifier_call = yb9_kbdock_nb_call; + + ret =devm_yb9_kbdock_register_notifier (&wdev->dev, &d->nb); +if (ret) +return ret; + +dev_set_drvdata (&wdev->dev, d); +yb9_kbdock_sync (d); +return 0 ; +} + +static const struct wmi_device_id yb9_kbdock_block_id_table[] = { + { .guid_string =YB9_KBDOCK_QUERY_GUID }, + { } +}; + +static struct wmi_driver yb9_kbdock_block_driver = { + .driver = { + .name ="lenovo-yb9-kbdock" , + .dev_groups = yb9_kbdock_groups, + .pm =pm_sleep_ptr (&yb9_kbdock_pm_ops), + }, + .id_table = yb9_kbdock_block_id_table, + .no_singleton = true, + .probe = yb9_kbdock_block_probe, +}; + +/* ------------------------------------------------------------------ +* Event WMI driver — LENOVO_BTKBD_EVENT +* (fires the notifier chain on each WMI event) +* ------------------------------------------------------------------ */ + +static void yb9_kbdock_notify_new (struct wmi_device *wdev, +const struct wmi_buffer *data) +{ +/* +* _WED(0xEB) returns EC.BKBD directly as a 32-bit integer +* (LENOVO_BTKBD_EVENT WmiDataId(1) uint32 Status). +*/ +if (!data || data->length <sizeof (__le32)) +return ; + +u32 bkbd =le32_to_cpu (*(const __le32 *)data->data); + +blocking_notifier_call_chain (&yb9_kbdock_chain_head, bkbd,NULL ); +} + +static const struct wmi_device_id yb9_kbdock_event_id_table[] = { + { .guid_string =YB9_KBDOCK_EVENT_GUID }, + { } +}; +MODULE_DEVICE_TABLE (wmi, yb9_kbdock_event_id_table); + +static struct wmi_driver yb9_kbdock_event_driver = { + .driver = { + .name ="lenovo-yb9-kbdock-event" , + }, + .id_table = yb9_kbdock_event_id_table, + .no_singleton = true, + .notify_new = yb9_kbdock_notify_new, +}; + +/* ------------------------------------------------------------------ +* Module init / exit +* ------------------------------------------------------------------ */ + +static const struct dmi_system_id yb9_kbdock_dmi_table[]__initconst = { + { +/* Lenovo Yoga Book 9 14IAH10 */ + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"83KJ" ), + }, + }, + { } +}; + +static int __init yb9_kbdock_init (void ) +{ +int ret; + +if (!dmi_check_system (yb9_kbdock_dmi_table)) +return -ENODEV ; + + ret =wmi_driver_register (&yb9_kbdock_event_driver); +if (ret) +return ret; + + ret =wmi_driver_register (&yb9_kbdock_block_driver); +if (ret) { +wmi_driver_unregister (&yb9_kbdock_event_driver); +return ret; + } + +return 0 ; +} +module_init (yb9_kbdock_init); + +static void __exit yb9_kbdock_exit(void) +{ +wmi_driver_unregister (&yb9_kbdock_block_driver); +wmi_driver_unregister (&yb9_kbdock_event_driver); +} +module_exit (yb9_kbdock_exit); + +MODULE_AUTHOR ("Dave Carey <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo Yoga Book 9 keyboard dock detection" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
i.
Dave Carey
maintainerv12 cover Lenovo Yoga Book 9 keyboard dock detection
In reply to Dave CareyChanges 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 | 322 ++++++++++++ drivers/platform/x86/lenovo/ymc.c | 19 ++ 6 files changed, 382 insertions(+)
2.47.0
Dave Carey
maintainerPATCH v12 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
@@ -23,7 +23,23 @@ module_param(force, bool, 0444);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 = {
@@ -100,7 +116,10 @@ static int lenovo_ymc_probe(struct wmi_device *wdev, const void *ctx)struct lenovo_ymc_private *priv;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" );
--
2.54.0
Dave Carey
maintainerPATCH v12 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.
---
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:
- 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 (Armin Wolf).
--- .../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 | 322 ++++++++++++++++++ 5 files changed, 363 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_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 +322 -0
322 lines not on this page · raw message
+MODULE_LICENSE("GPL");
2.47.0
Ilpo Järvinen
maintainerRe: [PATCH v12 0/2] Lenovo Yoga Book 9 keyboard dock detection
In reply to Dave CareyQuoted 33 lines · Dave Carey
Changes in v12 (addressing Ilpo Järvinen's v11 review of patch 2/2):
- Add #include <
linux/sysfs.h> (forsysfs_emit)
- Add #include <linux/types.h> (for__le32and__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 avoida 0xFFFFFFFF status value being misread as -EPERM- struct
yb9_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 (not needed)
-yb9_kbdock_notify_new(): drop manual length check; use .min_event_size =sizeof(__le32)in structwmi_driverinsteadPatch 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
Quoted 7 lines
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 | 322 ++++++++++++ drivers/platform/x86/lenovo/ymc.c | 19 ++ 6 files changed, 382 insertions(+)
Please resend this series into a separate thread (you can reuse the version number as long as there are no other changes).
In future, always send new versions of a series into own thread so that our tools can better distinguish which patches belong to which version.
Signature · 1 line
i.
Ilpo Järvinen
maintainerRe: [PATCH v12 0/2] Lenovo Yoga Book 9 keyboard dock detection
In reply to a message not in the archiveQuoted 2 lines · Dave Carey
Apologies, pretty new to upstream submissions. Are you asking that I abandon this thread and submit a new v1 patch series?
That's not what I meant but submit v12 again into own thread that is entirely unrelated to this email thread.
Currently, the recent versions are part of thread that contains the earlier versions (see the thread overview towards the end):
https://lore.kernel.org/platform-driver-x86/[email protected]/T/#t
On low-level, it relates to what appears/doesn't appear in References/In-Reply-To headers of the email.
--
i.