[PATCH 6/7] platform/x86: ideapad-laptop: Trigger the EC on YMC events following Windows behavior

From: Rong Zhang

Date: Sun Nov 15 2026 - 14:29:21 EST


Currently, the ideapad-laptop driver triggers the EC with YMC command
0x01, which seems to be randomly chosen with trail-and-error and turns
out to be not a command for YMC events. While the devices in the DMI
quirk table recognize it, some other devices do not, making the
trigger_ec functionality a no-op.

Lenovo's YMC driver for Windows (YMC.exe) emits YMC command 0x08/0x09 on
fold/unfold YMC events, in which "unfold" means laptop mode and "fold"
means other modes.

Adopt the said sequence to make it work on all relevant devices. For the
sake of caution, only emit YMC command 0x08 only for the known fold
postures. For all other postures (including unknown ones), emit 0x09 to
make sure the touchpad and keyboard are still functional.

Reported-by: Mahir Faisal <mahirfaisalantiq33@xxxxxxxxx>
Closes: https://msgid.link/CAGAHqH6o0TUa1HXMrNV6e+HNYwU3xxHkOM665756n8Cp3AzhVQ@xxxxxxxxxxxxxx
Signed-off-by: Rong Zhang <i@xxxxxxxx>
---
drivers/platform/x86/lenovo/ideapad-laptop.c | 35 +++++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platform/x86/lenovo/ideapad-laptop.c
index 91a8d11c79c5..4f9dc95d8c65 100644
--- a/drivers/platform/x86/lenovo/ideapad-laptop.c
+++ b/drivers/platform/x86/lenovo/ideapad-laptop.c
@@ -133,6 +133,11 @@ enum {
VPCCMD_W_BL_POWER = 0x33,
};

+enum ymc_cmd {
+ YMC_CMD_FOLD = 0x08,
+ YMC_CMD_UNFOLD = 0x09,
+};
+
/*
* These correspond to the number of supported states - 1
* Future keyboard types may need a new system, if there's a collision
@@ -1870,9 +1875,10 @@ static const struct dmi_system_id ymc_ec_trigger_quirk_dmi_table[] = {
{ }
};

-static void ideapad_laptop_trigger_ec(void)
+static void ideapad_laptop_trigger_ec(u32 code)
{
struct ideapad_private *priv;
+ enum ymc_cmd cmd;
int ret;

guard(mutex)(&ideapad_shared_mutex);
@@ -1884,8 +1890,29 @@ static void ideapad_laptop_trigger_ec(void)
if (!priv->features.ymc_ec_trigger)
return;

+ switch (code) {
+ case YMC_POSTURE_TABLET:
+ case YMC_POSTURE_DRAWING_BOARD:
+ case YMC_POSTURE_TENT:
+ /*
+ * Sync keyboard backlight and disable the touchapd and keyboard
+ * only when the device is folded...
+ */
+ cmd = YMC_CMD_FOLD;
+ break;
+ default:
+ /*
+ * ...IOW, whenever there is a chance that the device may be
+ * unfolded, e.g., in laptop mode or any other unknown modes,
+ * sync keyboard backlight and enable the touchapd and keyboard,
+ * so that users don't lose input.
+ */
+ cmd = YMC_CMD_UNFOLD;
+ break;
+ }
+
scoped_guard(mutex, &priv->vpc_mutex)
- ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_YMC, 1);
+ ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_YMC, cmd);
if (ret)
dev_warn(&priv->platform_device->dev, "Could not write YMC: %d\n", ret);
}
@@ -1893,9 +1920,11 @@ static void ideapad_laptop_trigger_ec(void)
static int ideapad_laptop_nb_notify(struct notifier_block *nb,
unsigned long action, void *data)
{
+ const u32 *p = data;
+
switch (action) {
case IDEAPAD_LAPTOP_YMC_EVENT:
- ideapad_laptop_trigger_ec();
+ ideapad_laptop_trigger_ec(*p);
break;
}


--
2.55.0