From nobody Fri Dec 19 18:43:13 2025 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24A6B25EF90; Tue, 8 Apr 2025 01:28:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744075715; cv=none; b=rVRs0WcMklTRL+c/m3xBw/MYHjtloSNYERZh4vFEWSTvSJeVJl6nsDOa0xpJ9rK94GezcqgtidUrOkL5fPvh8kwAXpC9fF0hMoibXgnMncermE7u+R41arxYZnAKk9fC+3xWgbZP1tO2FbAqshk9wzTscFFm6NoB8daeOJ4afkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744075715; c=relaxed/simple; bh=xu6sNRrDLATKIvJGQguptuXMpTq6cZKcMawcZ5rimaE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b6VVt6+lij+bA+ym3zyJDuVeB8wnUkNaRk4SwKGw9CsceKA79bSHpaOg+VyPh9RbxnGAEHeecSEWs8YPXFrYO7bME6gRJcNLj0nOYFZnsnth+6dw3idLwIVVfEyQvUlp1rqeUt4sUevbEKLasVoJRY/ngE80TLlnQLWcNVHTjqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OvW97v9j; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OvW97v9j" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2260c91576aso41575795ad.3; Mon, 07 Apr 2025 18:28:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744075713; x=1744680513; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xb4m3UUafcGE4ENlyLLiHz3gWw3SXy1QmUM9x05nJKo=; b=OvW97v9jj+iWrEdnBgEmV0pd6mmJAi+nIZfjoq86FujZXy0FFEPzERT9LKChIPCgO9 Y7v/J9b1JrJU4BZJci9k9Q17Vy1RvXqsiUpg8vhnUsSQPpDO2v/VFD5BeX5UpAPdBCtJ /3N5kQ6hoSbx/ALRqWGhfTrwwz5LMc4ykq6uzZl6pjE3veor45QzSE7iahAtMtvpDt04 aL5TBwN4kaQtVdpAbMpkR7XT1PtyDP6kJWKojkfcjSzh0w3evfHoGshYuGpF+F/hrx64 L3bX5Q6Fq6sSxJksRM9hRc8B8SvkupxU04UFqL+67t1qq21/IfqLKv2qyENg98AhPABL Bq6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744075713; x=1744680513; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xb4m3UUafcGE4ENlyLLiHz3gWw3SXy1QmUM9x05nJKo=; b=Be/ifV0TcLXrKi0DiTBIG3zCzFwcLx7cXPk/GVIm4y9yV/4zAUPFrznHYbXnOySIjE EMJN7HkvYjqrOP9HwYO9XGN5z4aErvRBLk0A1LaMpJ9rCXtuvgoni911EezQeldWYvuf 8LBYJh4uRnk+b3r9Rxn7Ti/Ss8c2tV+gGE66UnbTzw4oqyZdBsit3UaytTMDrKLCnoNt AJeJwGWzINWYGe2XqdzY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5kXHQilA4OmWwcQugwNBymnzpqCpw== X-Received: by 2002:a17:902:db06:b0:223:37ec:63d3 with SMTP id d9443c01a7336-22a8a05e91dmr154501005ad.18.1744075713229; Mon, 07 Apr 2025 18:28:33 -0700 (PDT) Received: from localhost.localdomain (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-229785c39c1sm87901255ad.85.2025.04.07.18.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Apr 2025 18:28:32 -0700 (PDT) From: "Derek J. Clark" To: Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Cc: Armin Wolf , Jonathan Corbet , Mario Limonciello , Luke Jones , Xino Ni , Zhixin Zhang , Mia Shao , Mark Pearson , "Pierre-Loup A . Griffais" , "Cody T . -H . Chiu" , John Martens , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Mario Limonciello Subject: [PATCH v5 3/6] platform/x86: Add Lenovo WMI Events Driver Date: Mon, 7 Apr 2025 18:28:12 -0700 Message-ID: <20250408012815.1032357-4-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408012815.1032357-1-derekjohn.clark@gmail.com> References: <20250408012815.1032357-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds lenovo-wmi-events driver. The events driver is designed as a general entrypoint for all Lenovo WMI Events. It acts as a notification chain head that will process event data and pass it on to registered drivers so they can react to the events. Currently only the Gamezone interface Thermal Mode Event GUID is implemented in this driver. It is documented in the Gamezone documentation. Suggested-by: Armin Wolf Reviewed-by: Armin Wolf Reviewed-by: Mario Limonciello Signed-off-by: Derek J. Clark --- v5: - Fixes from v4 review. v4: - Remove the Thermal Mode Event GUID from Gamezone and add this driver. --- MAINTAINERS | 2 + drivers/platform/x86/Kconfig | 4 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/lenovo-wmi-events.c | 196 +++++++++++++++++++++++ drivers/platform/x86/lenovo-wmi-events.h | 20 +++ 5 files changed, 223 insertions(+) create mode 100644 drivers/platform/x86/lenovo-wmi-events.c create mode 100644 drivers/platform/x86/lenovo-wmi-events.h diff --git a/MAINTAINERS b/MAINTAINERS index 3a370a18b806..6dde75922aaf 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13164,6 +13164,8 @@ L: platform-driver-x86@vger.kernel.org S: Maintained F: Documentation/wmi/devices/lenovo-wmi-gamezone.rst F: Documentation/wmi/devices/lenovo-wmi-other.rst +F: drivers/platform/x86/lenovo-wmi-events.c +F: drivers/platform/x86/lenovo-wmi-events.h F: drivers/platform/x86/lenovo-wmi-helpers.c F: drivers/platform/x86/lenovo-wmi-helpers.h =20 diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index bece1ba61417..13b8f4ac5dc5 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -459,6 +459,10 @@ config IBM_RTL state =3D 0 (BIOS SMIs on) state =3D 1 (BIOS SMIs off) =20 +config LENOVO_WMI_EVENTS + tristate + depends on ACPI_WMI + config LENOVO_WMI_HELPERS tristate depends on ACPI_WMI diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index 5a9f4e94f78b..fc039839286a 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -69,6 +69,7 @@ obj-$(CONFIG_THINKPAD_LMI) +=3D think-lmi.o obj-$(CONFIG_YOGABOOK) +=3D lenovo-yogabook.o obj-$(CONFIG_YT2_1380) +=3D lenovo-yoga-tab2-pro-1380-fastcharger.o obj-$(CONFIG_LENOVO_WMI_CAMERA) +=3D lenovo-wmi-camera.o +obj-$(CONFIG_LENOVO_WMI_EVENTS) +=3D lenovo-wmi-events.o obj-$(CONFIG_LENOVO_WMI_HELPERS) +=3D lenovo-wmi-helpers.o =20 # Intel diff --git a/drivers/platform/x86/lenovo-wmi-events.c b/drivers/platform/x8= 6/lenovo-wmi-events.c new file mode 100644 index 000000000000..5c18c392d0e9 --- /dev/null +++ b/drivers/platform/x86/lenovo-wmi-events.c @@ -0,0 +1,196 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Lenovo WMI Events driver. Lenovo WMI interfaces provide various + * hardware triggered events that many drivers need to have propagated. + * This driver provides a uniform entrypoint for these events so that + * any driver that needs to respond to these events can subscribe to a + * notifier chain. + * + * Copyright(C) 2025 Derek J. Clark + */ + +#include +#include +#include +#include +#include +#include + +#include "lenovo-wmi-events.h" +#include "lenovo-wmi-gamezone.h" + +#define THERMAL_MODE_EVENT_GUID "D320289E-8FEA-41E0-86F9-911D83151B5F" + +#define LWMI_EVENT_DEVICE(guid, type) \ + .guid_string =3D (guid), .context =3D &(enum lwmi_events_type) \ + { \ + type \ + } + +static BLOCKING_NOTIFIER_HEAD(events_chain_head); + +struct lwmi_events_priv { + struct wmi_device *wdev; + enum lwmi_events_type type; +}; + +/** + * lwmi_events_register_notifier() - Add a notifier to the notifier chain. + * @nb: The notifier_block struct to register + * + * Call blocking_notifier_chain_register to register the notifier block to= the + * lenovo-wmi-events driver blocking notifer chain. + * + * Return: 0 on success, %-EEXIST on error. + */ +int lwmi_events_register_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&events_chain_head, nb); +} +EXPORT_SYMBOL_NS_GPL(lwmi_events_register_notifier, "LENOVO_WMI_EVENTS"); + +/** + * lwmi_events_unregister_notifier() - Remove a notifier from the notifier + * chain. + * @nb: The notifier_block struct to register + * + * Call blocking_notifier_chain_unregister to unregister the notifier block + * from the lenovo-wmi-events driver blocking notifer chain. + * + * Return: 0 on success, %-ENOENT on error. + */ +int lwmi_events_unregister_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&events_chain_head, nb); +} +EXPORT_SYMBOL_NS_GPL(lwmi_events_unregister_notifier, "LENOVO_WMI_EVENTS"); + +/** + * devm_lwmi_events_unregister_notifier() - Remove a notifier from the not= ifier + * chain. + * @data: Void pointer to the notifier_block struct to register. + * + * Call lwmi_events_unregister_notifier to unregister the notifier block f= rom + * the lenovo-wmi-events driver blocking notifer chain. + * + * Return: 0 on success, %-ENOENT on error. + */ +static void devm_lwmi_events_unregister_notifier(void *data) +{ + struct notifier_block *nb =3D data; + + lwmi_events_unregister_notifier(nb); +} + +/** + * devm_lwmi_events_register_notifier() - Add a notifier to the notifier c= hain. + * @dev: The parent device of the notifier_block struct. + * @nb: The notifier_block struct to register + * + * Call lwmi_events_register_notifier to register the notifier block to the + * lenovo-wmi-events driver blocking notifer chain. Then add, as a device + * managed action, unregister_notifier to automatically unregister the + * notifier block upon its parent device removal. + * + * Return: 0 on success, or on error. + */ +int devm_lwmi_events_register_notifier(struct device *dev, + struct notifier_block *nb) +{ + int ret; + + ret =3D lwmi_events_register_notifier(nb); + if (ret < 0) + return ret; + + return devm_add_action_or_reset(dev, devm_lwmi_events_unregister_notifier= , nb); +} +EXPORT_SYMBOL_NS_GPL(devm_lwmi_events_register_notifier, "LENOVO_WMI_EVENT= S"); + +/** + * 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. + * + * Validate WMI event data and notify all registered drivers of the event = and + * its output. + * + * Return: 0 on success, or on error. + */ +static void lwmi_events_notify(struct wmi_device *wdev, union acpi_object = *obj) +{ + struct lwmi_events_priv *priv =3D dev_get_drvdata(&wdev->dev); + int sel_prof; + int ret; + + switch (priv->type) { + case LWMI_EVENT_THERMAL_MODE: + if (obj->type !=3D ACPI_TYPE_INTEGER) + return; + + sel_prof =3D obj->integer.value; + + switch (sel_prof) { + case LWMI_GZ_THERMAL_MODE_QUIET: + case LWMI_GZ_THERMAL_MODE_BALANCED: + case LWMI_GZ_THERMAL_MODE_PERFORMANCE: + case LWMI_GZ_THERMAL_MODE_EXTREME: + case LWMI_GZ_THERMAL_MODE_CUSTOM: + ret =3D blocking_notifier_call_chain(&events_chain_head, + LWMI_EVENT_THERMAL_MODE, + &sel_prof); + if (ret =3D=3D NOTIFY_BAD) + dev_err(&wdev->dev, + "Failed to send notification to call chain for WMI Events\n"); + return; + default: + dev_err(&wdev->dev, "Got invalid thermal mode: %x", + sel_prof); + return; + } + break; + default: + return; + } +} + +static int lwmi_events_probe(struct wmi_device *wdev, const void *context) +{ + struct lwmi_events_priv *priv; + + priv =3D devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + if (!context) + return -EINVAL; + + priv->wdev =3D wdev; + priv->type =3D *(enum lwmi_events_type *)context; + + dev_set_drvdata(&wdev->dev, priv); + return 0; +} + +static const struct wmi_device_id lwmi_events_id_table[] =3D { + { LWMI_EVENT_DEVICE(THERMAL_MODE_EVENT_GUID, LWMI_EVENT_THERMAL_MODE) }, + {} +}; + +static struct wmi_driver lwmi_events_driver =3D { + .driver =3D { + .name =3D "lenovo_wmi_events", + .probe_type =3D PROBE_PREFER_ASYNCHRONOUS, + }, + .id_table =3D lwmi_events_id_table, + .probe =3D lwmi_events_probe, + .notify =3D lwmi_events_notify, + .no_singleton =3D true, +}; + +module_wmi_driver(lwmi_events_driver); + +MODULE_DEVICE_TABLE(wmi, lwmi_events_id_table); +MODULE_AUTHOR("Derek J. Clark "); +MODULE_DESCRIPTION("Lenovo WMI Events Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/platform/x86/lenovo-wmi-events.h b/drivers/platform/x8= 6/lenovo-wmi-events.h new file mode 100644 index 000000000000..e4c5459c2f24 --- /dev/null +++ b/drivers/platform/x86/lenovo-wmi-events.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* Copyright(C) 2025 Derek J. Clark */ + +#ifndef _LENOVO_WMI_EVENTS_H_ +#define _LENOVO_WMI_EVENTS_H_ + +struct device; +struct notifier_block; + +enum lwmi_events_type { + LWMI_EVENT_THERMAL_MODE =3D 1, +}; + +int lwmi_events_register_notifier(struct notifier_block *nb); +int lwmi_events_unregister_notifier(struct notifier_block *nb); +int devm_lwmi_events_register_notifier(struct device *dev, + struct notifier_block *nb); + +#endif /* !_LENOVO_WMI_EVENTS_H_ */ --=20 2.49.0