mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 3/8] platform/x86: lenovo-wmi-events: Modernize WMI event handling
Date: Thu, 26 Nov 2026 02:08:21 +0800	[thread overview]
Message-ID: <20261126-ymc-82yl-v3-3-e30842671ec3@rong.moe> (raw)
In-Reply-To: <20261126-ymc-82yl-v3-0-e30842671ec3@rong.moe>

The WMI core calls the new notify_new() callback with unmarshaled event
data and size check, aligning with the Windows behavior that the ACPI
object type doesn't matter but the size does.

Adopt it to modernize the driver and hopefully improve robustness on
various firmware, like previously did for lenovo-wmi-{capdata,helpers}.

The blocking_notifier_call_chain() code path is also moved, so that it
will be easier when adding new GUIDs to the driver.

Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Tested-by: Eduard Aliman <edialiman20@gmail.com>
Signed-off-by: Rong Zhang <i@rong.moe>
---
 drivers/platform/x86/lenovo/wmi-events.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/platform/x86/lenovo/wmi-events.c b/drivers/platform/x86/lenovo/wmi-events.c
index 3a82192dc9e5..01ad5bcf0437 100644
--- a/drivers/platform/x86/lenovo/wmi-events.c
+++ b/drivers/platform/x86/lenovo/wmi-events.c
@@ -9,13 +9,14 @@
  * Copyright (C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
  */
 
-#include <linux/acpi.h>
 #include <linux/export.h>
 #include <linux/module.h>
 #include <linux/notifier.h>
 #include <linux/types.h>
 #include <linux/wmi.h>
 
+#include <asm/byteorder.h>
+
 #include "wmi-events.h"
 #include "wmi-helpers.h"
 
@@ -110,25 +111,23 @@ EXPORT_SYMBOL_NS_GPL(devm_lwmi_events_register_notifier, "LENOVO_WMI_EVENTS");
 /**
  * lwmi_events_notify() - Call functions for the notifier call chain.
  * @wdev: The parent WMI device of the driver.
- * @obj: ACPI object passed by the registered WMI Event.
+ * @buf: WMI buffer passed by the registered WMI Event.
  *
  * Validate WMI event data and notify all registered drivers of the event and
  * its output.
  *
  * Return: 0 on success, or an error code.
  */
-static void lwmi_events_notify(struct wmi_device *wdev, union acpi_object *obj)
+static void lwmi_events_notify(struct wmi_device *wdev, const struct wmi_buffer *buf)
 {
 	struct lwmi_events_priv *priv = dev_get_drvdata(&wdev->dev);
+	void *notif_data = NULL;
 	int sel_prof;
 	int ret;
 
 	switch (priv->type) {
 	case LWMI_EVENT_THERMAL_MODE:
-		if (obj->type != ACPI_TYPE_INTEGER)
-			return;
-
-		sel_prof = obj->integer.value;
+		sel_prof = le32_to_cpup(buf->data);
 
 		switch (sel_prof) {
 		case LWMI_GZ_THERMAL_MODE_QUIET:
@@ -136,13 +135,8 @@ static void lwmi_events_notify(struct wmi_device *wdev, union acpi_object *obj)
 		case LWMI_GZ_THERMAL_MODE_PERFORMANCE:
 		case LWMI_GZ_THERMAL_MODE_EXTREME:
 		case LWMI_GZ_THERMAL_MODE_CUSTOM:
-			ret = blocking_notifier_call_chain(&events_chain_head,
-							   LWMI_EVENT_THERMAL_MODE,
-							   &sel_prof);
-			if (ret == NOTIFY_BAD)
-				dev_err(&wdev->dev,
-					"Failed to send notification to call chain for WMI Events\n");
-			return;
+			notif_data = &sel_prof;
+			break;
 		default:
 			dev_err(&wdev->dev, "Got invalid thermal mode: %x",
 				sel_prof);
@@ -152,6 +146,13 @@ static void lwmi_events_notify(struct wmi_device *wdev, union acpi_object *obj)
 	default:
 		return;
 	}
+
+	ret = blocking_notifier_call_chain(&events_chain_head, priv->type, notif_data);
+	if (ret == NOTIFY_BAD) {
+		dev_err(&wdev->dev,
+			"Failed to send notification to call chain for WMI event type %d\n",
+			priv->type);
+	}
 }
 
 static int lwmi_events_probe(struct wmi_device *wdev, const void *context)
@@ -185,7 +186,7 @@ static struct wmi_driver lwmi_events_driver = {
 	.id_table = lwmi_events_id_table,
 	.min_event_size = sizeof(u32),
 	.probe = lwmi_events_probe,
-	.notify = lwmi_events_notify,
+	.notify_new = lwmi_events_notify,
 	.no_singleton = true,
 };
 

-- 
2.55.0


  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] platform/x86: ideapad-laptop: Trigger the EC on YMC events following Windows behavior 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 ` Rong Zhang [this message]
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 ` [PATCH v3 6/8] platform/x86: ideapad-laptop: Trigger the EC on YMC events following Windows behavior Rong Zhang
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-3-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®