From: Rong Zhang <i@rong.moe>
To: "Mark Pearson" <mpearson-lenovo@squebb.ca>,
"Derek J. Clark" <derekjohn.clark@gmail.com>,
"Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Gergo Koteles" <soyer@irl.hu>, "Ike Panhc" <ikepanhc@gmail.com>,
"Andrew Kallmeyer" <kallmeyeras@gmail.com>
Cc: Eduard Aliman <edialiman20@gmail.com>,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org,
Mahir Faisal <mahirfaisalantiq33@gmail.com>,
Rong Zhang <i@rong.moe>
Subject: [PATCH v3 6/8] platform/x86: ideapad-laptop: Trigger the EC on YMC events following Windows behavior
Date: Thu, 26 Nov 2026 02:08:24 +0800 [thread overview]
Message-ID: <20261126-ymc-82yl-v3-6-e30842671ec3@rong.moe> (raw)
In-Reply-To: <20261126-ymc-82yl-v3-0-e30842671ec3@rong.moe>
Currently, the ideapad-laptop driver triggers the EC with YMC command
0x01, which is necessary for existing devices in the DMI quirk table to
clear the pending event to allow further events to be emitted.
Newer models do not require command 0x01 anymore (writing it is a
no-op), but some of them require other commands to properly synchronize
and set the hardware state.
It turned out that Lenovo's YMC driver for Windows (YMC.exe) writes YMC
command 0x08/0x09 on fold/unfold YMC events, in which "unfold" means
laptop mode and "fold" means other modes.
Adopt the said sequence and combine it with command 0x01 to make
ymc_ec_trigger work on all relevant devices. For the sake of caution,
write command 0x08 only for the known fold postures. For all other
postures (including unknown ones), write 0x09 to make sure the touchpad
and keyboard are still functional. Finally, 0x01 is always written to
ensure the pending event is cleared.
Reported-by: Mahir Faisal <mahirfaisalantiq33@gmail.com>
Closes: https://msgid.link/CAGAHqH6o0TUa1HXMrNV6e+HNYwU3xxHkOM665756n8Cp3AzhVQ@mail.gmail.com
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Rong Zhang <i@rong.moe>
---
Changes in v3:
- Always write YMC command 0x01 at last (thanks Gergo Koteles)
- Drop Eduard Aliman's Tested-by: due to the change above
Changes in v2:
- Fix typos (thanks Mark Pearson)
---
drivers/platform/x86/lenovo/ideapad-laptop.c | 60 ++++++++++++++++++++++++----
1 file changed, 53 insertions(+), 7 deletions(-)
diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platform/x86/lenovo/ideapad-laptop.c
index 91a8d11c79c5..f3467cd8df36 100644
--- a/drivers/platform/x86/lenovo/ideapad-laptop.c
+++ b/drivers/platform/x86/lenovo/ideapad-laptop.c
@@ -133,6 +133,12 @@ enum {
VPCCMD_W_BL_POWER = 0x33,
};
+enum ymc_cmd {
+ YMC_CMD_CLEAR = 0x01,
+ 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,10 +1876,11 @@ 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;
- int ret;
+ enum ymc_cmd cmd;
+ int ret[2];
guard(mutex)(&ideapad_shared_mutex);
@@ -1884,18 +1891,57 @@ static void ideapad_laptop_trigger_ec(void)
if (!priv->features.ymc_ec_trigger)
return;
- scoped_guard(mutex, &priv->vpc_mutex)
- ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_YMC, 1);
- if (ret)
- dev_warn(&priv->platform_device->dev, "Could not write YMC: %d\n", ret);
+ 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;
+ }
+
+ /*
+ * Old and new models behave differently:
+ *
+ * - Old: YMC_CMD_CLEAR clears the pending event to allow further events
+ * to be emitted. Any other YMC commands are no-op.
+ * - New: YMC_CMD_CLEAR is not required anymore and becomes a no-op.
+ * However, YMC_CMD_FOLD/YMC_CMD_UNFOLD must be sent on event
+ * (see above).
+ *
+ * Take the union of the two by writing both commands on both categories
+ * of devices.
+ */
+ scoped_guard(mutex, &priv->vpc_mutex) {
+ ret[0] = write_ec_cmd(priv->adev->handle, VPCCMD_W_YMC, cmd);
+ ret[1] = write_ec_cmd(priv->adev->handle, VPCCMD_W_YMC, YMC_CMD_CLEAR);
+ }
+ if (ret[0] || ret[1]) {
+ dev_warn(&priv->platform_device->dev,
+ "Could not write YMC: %d/%d\n", ret[0], ret[1]);
+ }
}
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
next prev parent reply other threads:[~2026-11-25 18:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 18:08 [PATCH v3 0/8] " Rong Zhang
2026-11-25 18:08 ` [PATCH v3 1/8] platform/x86: lenovo-ymc: Use enumeration to represent device posture Rong Zhang
2026-11-25 18:08 ` [PATCH v3 2/8] platform/x86: lenovo-ymc: Serialize WMI event handling Rong Zhang
2026-11-25 18:08 ` [PATCH v3 3/8] platform/x86: lenovo-wmi-events: Modernize " Rong Zhang
2026-11-25 18:08 ` [PATCH v3 4/8] platform/x86: lenovo-ymc: Modernize WMI driver and factor out events Rong Zhang
2026-11-25 18:08 ` [PATCH v3 5/8] platform/x86: lenovo-ymc: Refresh posture on resume Rong Zhang
2026-11-25 18:08 ` Rong Zhang [this message]
2026-11-25 18:08 ` [PATCH v3 7/8] platform/x86: ideapad-laptop: Enable ymc_ec_trigger for Lenovo Yoga 7 14IRL8 Rong Zhang
2026-11-25 18:08 ` [PATCH v3 8/8] platform/x86: ideapad-laptop: Enable ymc_ec_trigger for Lenovo Yoga 7 14ARP8 Rong Zhang
2026-11-25 19:14 ` [PATCH v3 0/8] platform/x86: ideapad-laptop: Trigger the EC on YMC events following Windows behavior Eduard Aliman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126-ymc-82yl-v3-6-e30842671ec3@rong.moe \
--to=i@rong.moe \
--cc=derekjohn.clark@gmail.com \
--cc=edialiman20@gmail.com \
--cc=hansg@kernel.org \
--cc=ikepanhc@gmail.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=kallmeyeras@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mahirfaisalantiq33@gmail.com \
--cc=mpearson-lenovo@squebb.ca \
--cc=platform-driver-x86@vger.kernel.org \
--cc=soyer@irl.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®