platform/x86: Add Lenovo Gaming Series WMI Drivers
Subsystems (4)
Derek John Clark
maintainerRe: [PATCH v4 6/6 RESEND] platform/x86: Add Lenovo Gamezone WMI Driver
In reply to Armin WolfQuoted 65 lines · Armin Wolf
Am 17.03.25 um 15:43 schrieb Derek J. Clark:
Quoted 62 lines
Adds lenovo-wmi-gamezone driver which provides the Lenovo Gamezone WMI interface that comes on Lenovo "Gaming Series" hardware. Provides ACPI platform profiles over WMI.
Signed-off-by Derek J. Clark <[email protected]>---
v4:
- Add notifier blocks for the Events and Other Mode drivers.
- Remove notifier block chain head and all reference to Thermal Mode Event GUID.
- Add header for Gamezone specific structs and functions.
- Various fixes from review.
v3:
- Use notifier chain to report platform profile changes to any subscribed drivers.
- AddsTHERMAL_MODE_EVENTGUID and .notify function to trigger notifier chain.
- Adds support for Extreme Mode profile on supported hardware, as well as a DMI quirk table for some devices that report extreme mode version support but so not have it fully implemented.
- Update to include recent changes to platform-profile.
v2:
- Usedevm_kmallocto ensure driver can be instanced, remove global reference.
- Ensure reverse Christmas tree for all variable declarations.
- Remove extra whitespace.
- Use guard(mutex) in all mutex instances, global mutex.
- Usepr_fmtinstead of adding the driver name to eachpr_err.
- Remove noisypr_infousage.
- Renamegamezone_wmitolenovo_wmi_gz_privandgz_wmito priv.
- RemoveGZ_WMIsymbol exporting.--- MAINTAINERS | 2 + drivers/platform/x86/Kconfig | 13 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/lenovo-wmi-gamezone.c | 380 +++++++++++++++++++++ drivers/platform/x86/lenovo-wmi-gamezone.h | 18 + 5 files changed, 414 insertions(+)create mode 100644
drivers/platform/x86/lenovo-wmi-gamezone.ccreate mode 100644drivers/platform/x86/lenovo-wmi-gamezone.hMAINTAINERS +2
-0@@ -13168,6 +13168,8 @@ F: drivers/platform/x86/lenovo-wmi-capdata01.c F: drivers/platform/x86/lenovo-wmi-capdata01.h F: drivers/platform/x86/lenovo-wmi-events.c F: drivers/platform/x86/lenovo-wmi-events.h +F: drivers/platform/x86/lenovo-wmi-gamezone.c +F: drivers/platform/x86/lenovo-wmi-gamezone.h F: drivers/platform/x86/lenovo-wmi-helpers.c F: drivers/platform/x86/lenovo-wmi-helpers.h F: drivers/platform/x86/lenovo-wmi-other.cdrivers/platform/x86/Kconfig +0
-0@@ -467,6 +467,19 @@ config LENOVO_WMI_HELPERS tristate depends on ACPI_WMI
Quoted 8 lines
drivers/platform/x86/Kconfig config LENOVO_WMI_HELPERS · line 472
Quoted 3 lines
drivers/platform/x86/Kconfig +3
-0+config LENOVO_WMI_GAMEZONE + tristate "Lenovo GameZone WMI Driver" + depends on ACPI_WMIHi,
please add a "depends on DMI" here.
Acked
Quoted 102 lines
Quoted 36 lines
drivers/platform/x86/Kconfig +10
-0+ select ACPI_PLATFORM_PROFILE + select LENOVO_WMI_EVENTS + select LENOVO_WMI_HELPERS + help + Say Y here if you have a WMI aware Lenovo Legion device and would like to use the + platform-profile firmware interface to manage power usage. + + To compile this driver as a module, choose M here: the module will + be called lenovo-wmi-gamezone. + config LENOVO_WMI_DATA01 tristate depends on ACPI_WMIdrivers/platform/x86/Makefile +1
-0@@ -71,6 +71,7 @@ obj-$(CONFIG_YT2_1380) += lenovo-yoga-tab2-pro-1380-fastcharger.o obj-$(CONFIG_LENOVO_WMI_CAMERA) += lenovo-wmi-camera.o obj-$(CONFIG_LENOVO_WMI_DATA01) += lenovo-wmi-capdata01.o obj-$(CONFIG_LENOVO_WMI_EVENTS) += lenovo-wmi-events.o +obj-$(CONFIG_LENOVO_WMI_GAMEZONE) += lenovo-wmi-gamezone.o obj-$(CONFIG_LENOVO_WMI_HELPERS) += lenovo-wmi-helpers.o obj-$(CONFIG_LENOVO_WMI_TUNING) += lenovo-wmi-other.odrivers/platform/x86/lenovo-wmi-gamezone.c new file +5
-0@@ -0,0 +1,380 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Lenovo GameZone WMI interface driver. The GameZone WMI interface provides +* platform profile and fan curve settings for devices that fall under the +* "Gaming Series" of Lenovo Legion devices. drivers/platform/x86/lenovo-wmi-gamezone.c line 15
Quoted 10 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +10
-0+* +* Copyright(C) 2025 Derek J. Clark <[email protected]> +*/ + +#include <linux/dmi.h> +#include <linux/list.h> +#include <linux/notifier.h> +#include <linux/platform_profile.h> +#include <linux/types.h> +#include <linux/wmi.h> Please also include
linux/acpi.h,linux/export.handlinux/module.h.Quoted 25 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +25
-0+ +#include "lenovo-wmi-events.h" +#include "lenovo-wmi-gamezone.h" +#include "lenovo-wmi-helpers.h" +#include "lenovo-wmi-other.h" + +/* Interface GUIDs */ +#define LENOVO_GAMEZONE_GUID "887B54E3-DDDC-4B2C-8B88-68A26A8835D0" + +/* Method IDs */ +#define WMI_METHOD_ID_SMARTFAN_SUPP 43/* IsSupportSmartFan */ +#define WMI_METHOD_ID_SMARTFAN_SET 44/* SetSmartFanMode */ +#define WMI_METHOD_ID_SMARTFAN_GET 45/* GetSmartFanMode */ + +static BLOCKING_NOTIFIER_HEAD (gz_chain_head); + +struct lwmi_event_priv { +enum thermal_mode current_mode; +struct wmi_device *wdev; +bool extreme_supported; +struct device *ppdev;/*platform profile device */ +struct notifier_block event_nb; +struct notifier_block mode_nb; +}; +drivers/platform/x86/lenovo-wmi-gamezone.c line 50
Quoted 10 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +10
-0+struct quirk_entry { +bool extreme_supported; +}; + +static struct quirk_entry quirk_no_extreme_bug = { + .extreme_supported = false, +}; + +/* Notifier Methods */ +/* /* -> /**, same goes for the other kernel doc comments.
Quoted 15 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +15
-0+* lwmi_gz_mode_call() - Call method for lenovo-wmi-other notifier +* block call chain. For THERMAL_MODE_EVENT, returns current_mode +* +* @nb: The notifier_block registered to lenovo-wmi-other +* @cmd: The event triggered by lenovo-wmi-other +* @data: The data to be returned by the event. +* +* Returns: notifier_block status. +*/ +static int lwmi_gz_mode_call (struct notifier_block *nb,unsigned long cmd, +void *data) +{ +struct lwmi_event_priv *priv; + + priv = container_of(nb, struct lwmi_event_priv, mode_nb);
Quoted 9 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 70
Quoted 5 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +5
-0+if (!priv) +return NOTIFY_BAD ; + +switch (cmd) { +case THERMAL_MODE_EVENT :I think it would be better to have a separate command code (maybe
GAMEZONE_GET_THERMAL_MODE) for this kind of request. Maybe you can define a separate enum for that?
I originally had two enums for this but it seemed redundant. TBS this is probably a better idea as the spec has two different event types for thermal mode events (one is a buffer with additional data) and getting the thermal mode from GZ would be agnostic from the events that are triggered.
Quoted 5 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 71
Quoted 1 line
drivers/platform/x86/lenovo-wmi-gamezone.c new file +1
-0+ *(enum thermal_mode *)data = priv->current_mode;I think you need to protect this variable from concurrent accesses. Maybe a spinlock would be suitable here?
Acked
Quoted 4 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 72
Quoted 1 line
drivers/platform/x86/lenovo-wmi-gamezone.c new file +1
-0+break ;Please return
NOTIFY_STOPhere to prevent the notifier call chain from calling further.
Acked
Quoted 20 lines
Quoted 20 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +20
-0+default : +return NOTIFY_DONE ; + } + +return NOTIFY_OK ; +} + +/* +* lwmi_gz_event_call() - Call method for lenovo-wmi-events notifier +* block call chain. For THERMAL_MODE_EVENT, sets current_mode and +* notifies platform_profile of a change. +* +* @nb: The notifier_block registered to lenovo-wmi-events +* @cmd: The event triggered by lenovo-wmi-events +* @data: The data to be updated by the event. +* +* Returns: notifier_block status. +*/ +static int lwmi_gz_event_call (struct notifier_block *nb,unsigned long cmd, +void *data)
Quoted 9 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 98
Quoted 6 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +6
-0+{ +struct lwmi_event_priv *priv; + + priv = container_of(nb, struct lwmi_event_priv, event_nb); +if (!priv) +return NOTIFY_BAD ;This check is unnecessary, please drop it?
Will do
Quoted 5 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 102
Quoted 4 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +4
-0+ +switch (cmd) { +case THERMAL_MODE_EVENT : + priv->current_mode = *((enum thermal_mode *)data);
Quoted 7 lines
You do not need to explicitly cast void pointers. Also please validate that the event data is actually a valid thermal mode. This check should IMHO happen inside the event driver itself.
drivers/platform/x86/lenovo-wmi-gamezone.c line 103
Quoted 1 line
drivers/platform/x86/lenovo-wmi-gamezone.c new file +1
-0+platform_profile_notify (&priv->wdev->dev);You are supposed to pass the platform profile device as the argument.
That makes more sense. I'll correct this, thanks.
Quoted 227 lines
Quoted 227 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +227
-0+break ; +default : +return NOTIFY_DONE ; + } + +return NOTIFY_OK ; +} + +/* Platform Profile Methods & Setup */ +/* +* lwmi_gz_platform_profile_supported() - Gets the version of the WMI +* interface to determine the support level. +* +* @wdev: The Gamezone WMI device. +* @supported: Pointer to return the support level with. +* +* Returns: 0, or an error. +*/ +static int lwmi_gz_platform_profile_supported (struct wmi_device *wdev, +int *supported) +{ +return lwmi_dev_evaluate_method (wdev,0x0 ,WMI_METHOD_ID_SMARTFAN_SUPP , +0 ,0 , supported); +} + +/* +* lwmi_gz_thermal_mode_get() - Gets the currently set thermal mode from +* the Gamezone WMI interface. +* +* @wdev: The Gamezone WMI device. +* @mode: Pointer to return the thermal mode with. +* +* Returns: 0, or an error. +*/ +static int lwmi_gz_thermal_mode_get (struct wmi_device *wdev, +enum thermal_mode *mode) +{ +return lwmi_dev_evaluate_method (wdev,0x0 ,WMI_METHOD_ID_SMARTFAN_GET , +0 ,0 , mode); +} + +static int lwmi_gz_profile_get (struct device *dev, +enum platform_profile_option *profile) +{ +struct lwmi_event_priv *priv =dev_get_drvdata (dev); +enum thermal_mode mode; +int ret; + + ret =lwmi_gz_thermal_mode_get (priv->wdev, &mode); +if (ret) +return ret; + +switch (mode) { +case SMARTFAN_MODE_QUIET : + *profile =PLATFORM_PROFILE_LOW_POWER ; +break ; +case SMARTFAN_MODE_BALANCED : + *profile =PLATFORM_PROFILE_BALANCED ; +break ; +case SMARTFAN_MODE_PERFORMANCE : +if (priv->extreme_supported) { + *profile =PLATFORM_PROFILE_BALANCED_PERFORMANCE ; +break ; + } + *profile =PLATFORM_PROFILE_PERFORMANCE ; +break ; +case SMARTFAN_MODE_EXTREME : + *profile =PLATFORM_PROFILE_PERFORMANCE ; +break ; +case SMARTFAN_MODE_CUSTOM : + *profile =PLATFORM_PROFILE_CUSTOM ; +break ; +default : +return -EINVAL ; + } + + priv->current_mode = mode; + +return 0 ; +} + +static int lwmi_gz_profile_set (struct device *dev, +enum platform_profile_option profile) +{ +struct lwmi_event_priv *priv =dev_get_drvdata (dev); +struct wmi_method_args_32 args; +enum thermal_mode mode; +int ret; + +switch (profile) { +case PLATFORM_PROFILE_LOW_POWER : + mode =SMARTFAN_MODE_QUIET ; +break ; +case PLATFORM_PROFILE_BALANCED : + mode =SMARTFAN_MODE_BALANCED ; +break ; +case PLATFORM_PROFILE_BALANCED_PERFORMANCE : + mode =SMARTFAN_MODE_PERFORMANCE ; +break ; +case PLATFORM_PROFILE_PERFORMANCE : +if (priv->extreme_supported) { + mode =SMARTFAN_MODE_EXTREME ; +break ; + } + mode =SMARTFAN_MODE_PERFORMANCE ; +break ; +case PLATFORM_PROFILE_CUSTOM : + mode =SMARTFAN_MODE_CUSTOM ; +break ; +default : +return -EOPNOTSUPP ; + } + + args.arg0 = mode; + + ret =lwmi_dev_evaluate_method (priv->wdev,0x0 , +WMI_METHOD_ID_SMARTFAN_SET , + (unsigned char *)&args,sizeof (args), +NULL ); +if (ret) +return ret; + + priv->current_mode = mode; + +return 0 ; +} + +static const struct dmi_system_id fwbug_list[] = { + { + .ident ="Legion Go 8APU1" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_VERSION ,"Legion Go 8APU1" ), + }, + .driver_data = &quirk_no_extreme_bug, + }, + { + .ident ="Legion Go S 8ARP1" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_VERSION ,"Legion Go S 8ARP1" ), + }, + .driver_data = &quirk_no_extreme_bug, + }, + { + .ident ="Legion Go S 8APU1" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_VERSION ,"Legion Go S 8APU1" ), + }, + .driver_data = &quirk_no_extreme_bug, + }, + {}, + +}; + +/* +* extreme_supported() - Evaluate if a device supports extreme thermal mode. +* For devices that have a profile_support_ver of 6 or greater a DMI check +* is done. Some devices report a version that supports extreme mode but +* have an incomplete entry in the BIOS. To ensure this cannot be set, they +* are quirked to prevent assignment. +* +* @profile_support_ver: Version of WMI interface provided by +* lwmi_gz_platform_profile_supported. +* +* Returns: bool +*/ +static bool extreme_supported (int profile_support_ver) +{ +const struct dmi_system_id *dmi_id; +struct quirk_entry *quirks; + +if (profile_support_ver <6 ) +return false; + + dmi_id =dmi_first_match (fwbug_list); +if (!dmi_id) +return true; + + quirks = dmi_id->driver_data; +return quirks->extreme_supported; +} + +static int lwmi_platform_profile_probe (void *drvdata,unsigned long *choices) +{ +struct lwmi_event_priv *priv = drvdata; +int profile_support_ver; +int ret; + + ret =lwmi_gz_platform_profile_supported (priv->wdev, + &profile_support_ver); +if (ret) +return ret; + +if (profile_support_ver <1 ) +return -ENODEV ; + + priv->extreme_supported =extreme_supported (profile_support_ver); + +set_bit (PLATFORM_PROFILE_LOW_POWER , choices); +set_bit (PLATFORM_PROFILE_BALANCED , choices); +set_bit (PLATFORM_PROFILE_PERFORMANCE , choices); +set_bit (PLATFORM_PROFILE_CUSTOM , choices); + +if (priv->extreme_supported) +set_bit (PLATFORM_PROFILE_BALANCED_PERFORMANCE , choices); + +return 0 ; +} + +static const struct platform_profile_ops lwmi_gz_platform_profile_ops = { + .probe = lwmi_platform_profile_probe, + .profile_get = lwmi_gz_profile_get, + .profile_set = lwmi_gz_profile_set, +}; + +/* Driver Methods */ +static int lwmi_gz_probe (struct wmi_device *wdev,const void *context) +{ +struct lwmi_event_priv *priv; +int ret; + + priv =devm_kzalloc (&wdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; +
Quoted 9 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 334
Quoted 4 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +4
-0+ priv->event_nb.notifier_call = lwmi_gz_event_call; + ret =devm_lwmi_events_register_notifier (&wdev->dev, &priv->event_nb); +if (ret) +return ret;You should register the event notifier after registering the platform profile or else a WMI event could arrive before the platform profile was registered, resulting in
platform_profile_notify()being called on a invalid device pointer.
Acked
Quoted 12 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 342
Quoted 8 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +8
-0+ + priv->mode_nb.notifier_call = lwmi_gz_mode_call; + ret =devm_lwmi_om_register_notifier (&wdev->dev, &priv->mode_nb); +if (ret) +return ret; + + priv->wdev = wdev; +dev_set_drvdata (&wdev->dev, priv);This should happen before the notifiers are registered or else they might try to access those values before they are actually initialized.
Acked
Quoted 5 lines
Quoted 5 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +5
-0+ + priv->ppdev =platform_profile_register (&wdev->dev, +"lenovo-wmi-gamezone" , priv, + &lwmi_gz_platform_profile_ops); +
Quoted 9 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 353
Quoted 6 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +6
-0+if (IS_ERR (priv->ppdev)) +return -ENODEV ; + + ret =lwmi_gz_thermal_mode_get (wdev, &priv->current_mode); +if (ret) +return ret;The thermal mode should be initialized before any notifiers using it are registered.
I'll register notifiers last in this func.
Quoted 10 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 360
Quoted 7 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +7
-0+ +return 0 ; +} + +static const struct wmi_device_id lwmi_gz_id_table[] = { {LENOVO_GAMEZONE_GUID , +NULL }, + {} };Please fix the formatting here.
Will do.
Thanks,
Derek
Quoted 47 lines
Thanks,
Armin WolfQuoted 44 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +20
-0+ +static struct wmi_driver lwmi_gz_driver = { + .driver = { + .name ="lenovo_wmi_gamezone" , + .probe_type =PROBE_PREFER_ASYNCHRONOUS , + }, + .id_table = lwmi_gz_id_table, + .probe = lwmi_gz_probe, + .no_singleton = true, +}; + +module_wmi_driver (lwmi_gz_driver); + +MODULE_IMPORT_NS ("LENOVO_WMI_EVENTS" ); +MODULE_IMPORT_NS ("LENOVO_WMI_HELPERS" ); +MODULE_IMPORT_NS ("LENOVO_WMI_OTHER" ); +MODULE_DEVICE_TABLE (wmi, lwmi_gz_id_table); +MODULE_AUTHOR ("Derek J. Clark <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo GameZone WMI Driver" ); +MODULE_LICENSE ("GPL" );drivers/platform/x86/lenovo-wmi-gamezone.h new file +18
-0@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* Copyright(C) 2025 Derek J. Clark <[email protected]> +* +*/ + +#ifndef _LENOVO_WMI_GAMEZONE_H_ +#define _LENOVO_WMI_GAMEZONE_H_ + +enum thermal_mode { +SMARTFAN_MODE_QUIET =0x01 , +SMARTFAN_MODE_BALANCED =0x02 , +SMARTFAN_MODE_PERFORMANCE =0x03 , +SMARTFAN_MODE_EXTREME =0xE0 ,/* Ver 6+ */ +SMARTFAN_MODE_CUSTOM =0xFF , +}; + +#endif /* !_LENOVO_WMI_GAMEZONE_H_ */
Armin Wolf
maintainerRe: [PATCH v4 6/6 RESEND] platform/x86: Add Lenovo Gamezone WMI Driver
Am 02.04.25 um 22:58 schrieb Derek John Clark:
Quoted 182 lines · Armin Wolf
Quoted 64 lines
Am 17.03.25 um 15:43 schrieb Derek J. Clark:
Quoted 62 lines
Adds lenovo-wmi-gamezone driver which provides the Lenovo Gamezone WMI interface that comes on Lenovo "Gaming Series" hardware. Provides ACPI platform profiles over WMI.
Signed-off-by Derek J. Clark <[email protected]>---
v4:
- Add notifier blocks for the Events and Other Mode drivers.
- Remove notifier block chain head and all reference to Thermal Mode Event GUID.
- Add header for Gamezone specific structs and functions.
- Various fixes from review.
v3:
- Use notifier chain to report platform profile changes to any subscribed drivers.
- AddsTHERMAL_MODE_EVENTGUID and .notify function to trigger notifier chain.
- Adds support for Extreme Mode profile on supported hardware, as well as a DMI quirk table for some devices that report extreme mode version support but so not have it fully implemented.
- Update to include recent changes to platform-profile.
v2:
- Usedevm_kmallocto ensure driver can be instanced, remove global reference.
- Ensure reverse Christmas tree for all variable declarations.
- Remove extra whitespace.
- Use guard(mutex) in all mutex instances, global mutex.
- Usepr_fmtinstead of adding the driver name to eachpr_err.
- Remove noisypr_infousage.
- Renamegamezone_wmitolenovo_wmi_gz_privandgz_wmito priv.
- RemoveGZ_WMIsymbol exporting.--- MAINTAINERS | 2 + drivers/platform/x86/Kconfig | 13 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/lenovo-wmi-gamezone.c | 380 +++++++++++++++++++++ drivers/platform/x86/lenovo-wmi-gamezone.h | 18 + 5 files changed, 414 insertions(+)create mode 100644
drivers/platform/x86/lenovo-wmi-gamezone.ccreate mode 100644drivers/platform/x86/lenovo-wmi-gamezone.hMAINTAINERS +2
-0@@ -13168,6 +13168,8 @@ F: drivers/platform/x86/lenovo-wmi-capdata01.c F: drivers/platform/x86/lenovo-wmi-capdata01.h F: drivers/platform/x86/lenovo-wmi-events.c F: drivers/platform/x86/lenovo-wmi-events.h +F: drivers/platform/x86/lenovo-wmi-gamezone.c +F: drivers/platform/x86/lenovo-wmi-gamezone.h F: drivers/platform/x86/lenovo-wmi-helpers.c F: drivers/platform/x86/lenovo-wmi-helpers.h F: drivers/platform/x86/lenovo-wmi-other.cdrivers/platform/x86/Kconfig +0
-0@@ -467,6 +467,19 @@ config LENOVO_WMI_HELPERS tristate depends on ACPI_WMIQuoted 7 lines
drivers/platform/x86/Kconfig config LENOVO_WMI_HELPERS · line 472
Quoted 3 lines
drivers/platform/x86/Kconfig +3
-0+config LENOVO_WMI_GAMEZONE + tristate "Lenovo GameZone WMI Driver" + depends on ACPI_WMIHi,
please add a "depends on DMI" here.
Acked
Quoted 99 lines
Quoted 36 lines
drivers/platform/x86/Kconfig +10
-0+ select ACPI_PLATFORM_PROFILE + select LENOVO_WMI_EVENTS + select LENOVO_WMI_HELPERS + help + Say Y here if you have a WMI aware Lenovo Legion device and would like to use the + platform-profile firmware interface to manage power usage. + + To compile this driver as a module, choose M here: the module will + be called lenovo-wmi-gamezone. + config LENOVO_WMI_DATA01 tristate depends on ACPI_WMIdrivers/platform/x86/Makefile +1
-0@@ -71,6 +71,7 @@ obj-$(CONFIG_YT2_1380) += lenovo-yoga-tab2-pro-1380-fastcharger.o obj-$(CONFIG_LENOVO_WMI_CAMERA) += lenovo-wmi-camera.o obj-$(CONFIG_LENOVO_WMI_DATA01) += lenovo-wmi-capdata01.o obj-$(CONFIG_LENOVO_WMI_EVENTS) += lenovo-wmi-events.o +obj-$(CONFIG_LENOVO_WMI_GAMEZONE) += lenovo-wmi-gamezone.o obj-$(CONFIG_LENOVO_WMI_HELPERS) += lenovo-wmi-helpers.o obj-$(CONFIG_LENOVO_WMI_TUNING) += lenovo-wmi-other.odrivers/platform/x86/lenovo-wmi-gamezone.c new file +5
-0@@ -0,0 +1,380 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Lenovo GameZone WMI interface driver. The GameZone WMI interface provides +* platform profile and fan curve settings for devices that fall under the +* "Gaming Series" of Lenovo Legion devices. drivers/platform/x86/lenovo-wmi-gamezone.c line 15
Quoted 10 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +10
-0+* +* Copyright(C) 2025 Derek J. Clark <[email protected]> +*/ + +#include <linux/dmi.h> +#include <linux/list.h> +#include <linux/notifier.h> +#include <linux/platform_profile.h> +#include <linux/types.h> +#include <linux/wmi.h> Please also include
linux/acpi.h,linux/export.handlinux/module.h.Quoted 25 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +25
-0+ +#include "lenovo-wmi-events.h" +#include "lenovo-wmi-gamezone.h" +#include "lenovo-wmi-helpers.h" +#include "lenovo-wmi-other.h" + +/* Interface GUIDs */ +#define LENOVO_GAMEZONE_GUID "887B54E3-DDDC-4B2C-8B88-68A26A8835D0" + +/* Method IDs */ +#define WMI_METHOD_ID_SMARTFAN_SUPP 43/* IsSupportSmartFan */ +#define WMI_METHOD_ID_SMARTFAN_SET 44/* SetSmartFanMode */ +#define WMI_METHOD_ID_SMARTFAN_GET 45/* GetSmartFanMode */ + +static BLOCKING_NOTIFIER_HEAD (gz_chain_head); + +struct lwmi_event_priv { +enum thermal_mode current_mode; +struct wmi_device *wdev; +bool extreme_supported; +struct device *ppdev;/*platform profile device */ +struct notifier_block event_nb; +struct notifier_block mode_nb; +}; +drivers/platform/x86/lenovo-wmi-gamezone.c line 50
Quoted 10 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +10
-0+struct quirk_entry { +bool extreme_supported; +}; + +static struct quirk_entry quirk_no_extreme_bug = { + .extreme_supported = false, +}; + +/* Notifier Methods */ +/* /* -> /**, same goes for the other kernel doc comments.
Quoted 14 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +14
-0+* lwmi_gz_mode_call() - Call method for lenovo-wmi-other notifier +* block call chain. For THERMAL_MODE_EVENT, returns current_mode +* +* @nb: The notifier_block registered to lenovo-wmi-other +* @cmd: The event triggered by lenovo-wmi-other +* @data: The data to be returned by the event. +* +* Returns: notifier_block status. +*/ +static int lwmi_gz_mode_call (struct notifier_block *nb,unsigned long cmd, +void *data) +{ +struct lwmi_event_priv *priv; +Quoted 9 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 70
Quoted 6 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +6
-0+ priv = container_of(nb, struct lwmi_event_priv, mode_nb); +if (!priv) +return NOTIFY_BAD ; + +switch (cmd) { +case THERMAL_MODE_EVENT :I think it would be better to have a separate command code (maybe
GAMEZONE_GET_THERMAL_MODE) for this kind of request. Maybe you can define a separate enum for that?
Quoted 5 lines
I originally had two enums for this but it seemed redundant. TBS this is probably a better idea as the spec has two different event types for thermal mode events (one is a buffer with additional data) and getting the thermal mode from GZ would be agnostic from the events that are triggered.
Exactly.
Thanks,
Armin Wolf
Quoted 379 lines
Quoted 4 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 71
Quoted 1 line
drivers/platform/x86/lenovo-wmi-gamezone.c new file +1
-0+ *(enum thermal_mode *)data = priv->current_mode;I think you need to protect this variable from concurrent accesses. Maybe a spinlock would be suitable here?
Acked
Quoted 3 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 72
Quoted 1 line
drivers/platform/x86/lenovo-wmi-gamezone.c new file +1
-0+break ;Please return
NOTIFY_STOPhere to prevent the notifier call chain from calling further.Acked
Quoted 19 lines
Quoted 19 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +19
-0+default : +return NOTIFY_DONE ; + } + +return NOTIFY_OK ; +} + +/* +* lwmi_gz_event_call() - Call method for lenovo-wmi-events notifier +* block call chain. For THERMAL_MODE_EVENT, sets current_mode and +* notifies platform_profile of a change. +* +* @nb: The notifier_block registered to lenovo-wmi-events +* @cmd: The event triggered by lenovo-wmi-events +* @data: The data to be updated by the event. +* +* Returns: notifier_block status. +*/ +static int lwmi_gz_event_call(struct notifier_block *nb, unsigned long cmd,Quoted 9 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 98
Quoted 7 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +7
-0+ void *data) +{ +struct lwmi_event_priv *priv; + + priv = container_of(nb, struct lwmi_event_priv, event_nb); +if (!priv) +return NOTIFY_BAD ;This check is unnecessary, please drop it?
Will do
Quoted 10 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 102
Quoted 4 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +4
-0+ +switch (cmd) { +case THERMAL_MODE_EVENT : + priv->current_mode = *((enum thermal_mode *)data);You do not need to explicitly cast void pointers. Also please validate that the event data is actually a valid thermal mode. This check should IMHO happen inside the event driver itself.
drivers/platform/x86/lenovo-wmi-gamezone.c line 103
Quoted 1 line
drivers/platform/x86/lenovo-wmi-gamezone.c new file +1
-0+platform_profile_notify (&priv->wdev->dev);You are supposed to pass the platform profile device as the argument.
That makes more sense. I'll correct this, thanks.
Quoted 226 lines
Quoted 226 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +226
-0+break ; +default : +return NOTIFY_DONE ; + } + +return NOTIFY_OK ; +} + +/* Platform Profile Methods & Setup */ +/* +* lwmi_gz_platform_profile_supported() - Gets the version of the WMI +* interface to determine the support level. +* +* @wdev: The Gamezone WMI device. +* @supported: Pointer to return the support level with. +* +* Returns: 0, or an error. +*/ +static int lwmi_gz_platform_profile_supported (struct wmi_device *wdev, +int *supported) +{ +return lwmi_dev_evaluate_method (wdev,0x0 ,WMI_METHOD_ID_SMARTFAN_SUPP , +0 ,0 , supported); +} + +/* +* lwmi_gz_thermal_mode_get() - Gets the currently set thermal mode from +* the Gamezone WMI interface. +* +* @wdev: The Gamezone WMI device. +* @mode: Pointer to return the thermal mode with. +* +* Returns: 0, or an error. +*/ +static int lwmi_gz_thermal_mode_get (struct wmi_device *wdev, +enum thermal_mode *mode) +{ +return lwmi_dev_evaluate_method (wdev,0x0 ,WMI_METHOD_ID_SMARTFAN_GET , +0 ,0 , mode); +} + +static int lwmi_gz_profile_get (struct device *dev, +enum platform_profile_option *profile) +{ +struct lwmi_event_priv *priv =dev_get_drvdata (dev); +enum thermal_mode mode; +int ret; + + ret =lwmi_gz_thermal_mode_get (priv->wdev, &mode); +if (ret) +return ret; + +switch (mode) { +case SMARTFAN_MODE_QUIET : + *profile =PLATFORM_PROFILE_LOW_POWER ; +break ; +case SMARTFAN_MODE_BALANCED : + *profile =PLATFORM_PROFILE_BALANCED ; +break ; +case SMARTFAN_MODE_PERFORMANCE : +if (priv->extreme_supported) { + *profile =PLATFORM_PROFILE_BALANCED_PERFORMANCE ; +break ; + } + *profile =PLATFORM_PROFILE_PERFORMANCE ; +break ; +case SMARTFAN_MODE_EXTREME : + *profile =PLATFORM_PROFILE_PERFORMANCE ; +break ; +case SMARTFAN_MODE_CUSTOM : + *profile =PLATFORM_PROFILE_CUSTOM ; +break ; +default : +return -EINVAL ; + } + + priv->current_mode = mode; + +return 0 ; +} + +static int lwmi_gz_profile_set (struct device *dev, +enum platform_profile_option profile) +{ +struct lwmi_event_priv *priv =dev_get_drvdata (dev); +struct wmi_method_args_32 args; +enum thermal_mode mode; +int ret; + +switch (profile) { +case PLATFORM_PROFILE_LOW_POWER : + mode =SMARTFAN_MODE_QUIET ; +break ; +case PLATFORM_PROFILE_BALANCED : + mode =SMARTFAN_MODE_BALANCED ; +break ; +case PLATFORM_PROFILE_BALANCED_PERFORMANCE : + mode =SMARTFAN_MODE_PERFORMANCE ; +break ; +case PLATFORM_PROFILE_PERFORMANCE : +if (priv->extreme_supported) { + mode =SMARTFAN_MODE_EXTREME ; +break ; + } + mode =SMARTFAN_MODE_PERFORMANCE ; +break ; +case PLATFORM_PROFILE_CUSTOM : + mode =SMARTFAN_MODE_CUSTOM ; +break ; +default : +return -EOPNOTSUPP ; + } + + args.arg0 = mode; + + ret =lwmi_dev_evaluate_method (priv->wdev,0x0 , +WMI_METHOD_ID_SMARTFAN_SET , + (unsigned char *)&args,sizeof (args), +NULL ); +if (ret) +return ret; + + priv->current_mode = mode; + +return 0 ; +} + +static const struct dmi_system_id fwbug_list[] = { + { + .ident ="Legion Go 8APU1" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_VERSION ,"Legion Go 8APU1" ), + }, + .driver_data = &quirk_no_extreme_bug, + }, + { + .ident ="Legion Go S 8ARP1" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_VERSION ,"Legion Go S 8ARP1" ), + }, + .driver_data = &quirk_no_extreme_bug, + }, + { + .ident ="Legion Go S 8APU1" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_VERSION ,"Legion Go S 8APU1" ), + }, + .driver_data = &quirk_no_extreme_bug, + }, + {}, + +}; + +/* +* extreme_supported() - Evaluate if a device supports extreme thermal mode. +* For devices that have a profile_support_ver of 6 or greater a DMI check +* is done. Some devices report a version that supports extreme mode but +* have an incomplete entry in the BIOS. To ensure this cannot be set, they +* are quirked to prevent assignment. +* +* @profile_support_ver: Version of WMI interface provided by +* lwmi_gz_platform_profile_supported. +* +* Returns: bool +*/ +static bool extreme_supported (int profile_support_ver) +{ +const struct dmi_system_id *dmi_id; +struct quirk_entry *quirks; + +if (profile_support_ver <6 ) +return false; + + dmi_id =dmi_first_match (fwbug_list); +if (!dmi_id) +return true; + + quirks = dmi_id->driver_data; +return quirks->extreme_supported; +} + +static int lwmi_platform_profile_probe (void *drvdata,unsigned long *choices) +{ +struct lwmi_event_priv *priv = drvdata; +int profile_support_ver; +int ret; + + ret =lwmi_gz_platform_profile_supported (priv->wdev, + &profile_support_ver); +if (ret) +return ret; + +if (profile_support_ver <1 ) +return -ENODEV ; + + priv->extreme_supported =extreme_supported (profile_support_ver); + +set_bit (PLATFORM_PROFILE_LOW_POWER , choices); +set_bit (PLATFORM_PROFILE_BALANCED , choices); +set_bit (PLATFORM_PROFILE_PERFORMANCE , choices); +set_bit (PLATFORM_PROFILE_CUSTOM , choices); + +if (priv->extreme_supported) +set_bit (PLATFORM_PROFILE_BALANCED_PERFORMANCE , choices); + +return 0 ; +} + +static const struct platform_profile_ops lwmi_gz_platform_profile_ops = { + .probe = lwmi_platform_profile_probe, + .profile_get = lwmi_gz_profile_get, + .profile_set = lwmi_gz_profile_set, +}; + +/* Driver Methods */ +static int lwmi_gz_probe (struct wmi_device *wdev,const void *context) +{ +struct lwmi_event_priv *priv; +int ret; + + priv =devm_kzalloc (&wdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ;Quoted 9 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 334
Quoted 5 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +5
-0+ + priv->event_nb.notifier_call = lwmi_gz_event_call; + ret =devm_lwmi_events_register_notifier (&wdev->dev, &priv->event_nb); +if (ret) +return ret;You should register the event notifier after registering the platform profile or else a WMI event could arrive before the platform profile was registered, resulting in
platform_profile_notify()being called on a invalid device pointer.Acked
Quoted 11 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 342
Quoted 8 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +8
-0+ + priv->mode_nb.notifier_call = lwmi_gz_mode_call; + ret =devm_lwmi_om_register_notifier (&wdev->dev, &priv->mode_nb); +if (ret) +return ret; + + priv->wdev = wdev; +dev_set_drvdata (&wdev->dev, priv);This should happen before the notifiers are registered or else they might try to access those values before they are actually initialized.
Acked
Quoted 4 lines
Quoted 4 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +4
-0+ + priv->ppdev =platform_profile_register (&wdev->dev, +"lenovo-wmi-gamezone" , priv, + &lwmi_gz_platform_profile_ops);Quoted 9 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 353
Quoted 7 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +7
-0+ +if (IS_ERR (priv->ppdev)) +return -ENODEV ; + + ret =lwmi_gz_thermal_mode_get (wdev, &priv->current_mode); +if (ret) +return ret;The thermal mode should be initialized before any notifiers using it are registered.
I'll register notifiers last in this func.
Quoted 9 lines
drivers/platform/x86/lenovo-wmi-gamezone.c line 360
Quoted 7 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +7
-0+ +return 0 ; +} + +static const struct wmi_device_id lwmi_gz_id_table[] = { {LENOVO_GAMEZONE_GUID , +NULL }, + {} };Please fix the formatting here.
Will do.
Thanks,
DerekQuoted 47 lines
Thanks,
Armin WolfQuoted 44 lines
drivers/platform/x86/lenovo-wmi-gamezone.c new file +20
-0+ +static struct wmi_driver lwmi_gz_driver = { + .driver = { + .name ="lenovo_wmi_gamezone" , + .probe_type =PROBE_PREFER_ASYNCHRONOUS , + }, + .id_table = lwmi_gz_id_table, + .probe = lwmi_gz_probe, + .no_singleton = true, +}; + +module_wmi_driver (lwmi_gz_driver); + +MODULE_IMPORT_NS ("LENOVO_WMI_EVENTS" ); +MODULE_IMPORT_NS ("LENOVO_WMI_HELPERS" ); +MODULE_IMPORT_NS ("LENOVO_WMI_OTHER" ); +MODULE_DEVICE_TABLE (wmi, lwmi_gz_id_table); +MODULE_AUTHOR ("Derek J. Clark <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo GameZone WMI Driver" ); +MODULE_LICENSE ("GPL" );drivers/platform/x86/lenovo-wmi-gamezone.h new file +18
-0@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* Copyright(C) 2025 Derek J. Clark <[email protected]> +* +*/ + +#ifndef _LENOVO_WMI_GAMEZONE_H_ +#define _LENOVO_WMI_GAMEZONE_H_ + +enum thermal_mode { +SMARTFAN_MODE_QUIET =0x01 , +SMARTFAN_MODE_BALANCED =0x02 , +SMARTFAN_MODE_PERFORMANCE =0x03 , +SMARTFAN_MODE_EXTREME =0xE0 ,/* Ver 6+ */ +SMARTFAN_MODE_CUSTOM =0xFF , +}; + +#endif /* !_LENOVO_WMI_GAMEZONE_H_ */
Ilpo Järvinen
maintainerRe: [PATCH v4 6/6 RESEND] platform/x86: Add Lenovo Gamezone WMI Driver
In reply to Derek J. ClarkQuoted 5 lines · Derek J. Clark
Adds lenovo-wmi-gamezone driver which provides the Lenovo Gamezone WMI interface that comes on Lenovo "Gaming Series" hardware. Provides ACPI platform profiles over WMI.
Signed-off-by Derek J. Clark <[email protected]>
This has a few similar nits I flagged for the other patches but I won't mark them here again but please go through the patches to find similar cases.
Quoted 486 lines
---
v4:
- Add notifier blocks for the Events and Other Mode drivers.
- Remove notifier block chain head and all reference to Thermal Mode Event GUID.
- Add header for Gamezone specific structs and functions.
- Various fixes from review.
v3:
- Use notifier chain to report platform profile changes to any subscribed drivers.
- AddsTHERMAL_MODE_EVENTGUID and .notify function to trigger notifier chain.
- Adds support for Extreme Mode profile on supported hardware, as well as a DMI quirk table for some devices that report extreme mode version support but so not have it fully implemented.
- Update to include recent changes to platform-profile.
v2:
- Usedevm_kmallocto ensure driver can be instanced, remove global reference.
- Ensure reverse Christmas tree for all variable declarations.
- Remove extra whitespace.
- Use guard(mutex) in all mutex instances, global mutex.
- Usepr_fmtinstead of adding the driver name to eachpr_err.
- Remove noisypr_infousage.
- Renamegamezone_wmitolenovo_wmi_gz_privandgz_wmito priv.
- RemoveGZ_WMIsymbol exporting.--- MAINTAINERS | 2 + drivers/platform/x86/Kconfig | 13 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/lenovo-wmi-gamezone.c | 380 +++++++++++++++++++++ drivers/platform/x86/lenovo-wmi-gamezone.h | 18 + 5 files changed, 414 insertions(+) create mode 100644 drivers/platform/x86/lenovo-wmi-gamezone.c create mode 100644 drivers/platform/x86/lenovo-wmi-gamezone.hMAINTAINERS +2
-0@@ -13168,6 +13168,8 @@ F: drivers/platform/x86/lenovo-wmi-capdata01.c F: drivers/platform/x86/lenovo-wmi-capdata01.h F: drivers/platform/x86/lenovo-wmi-events.c F: drivers/platform/x86/lenovo-wmi-events.h +F: drivers/platform/x86/lenovo-wmi-gamezone.c +F: drivers/platform/x86/lenovo-wmi-gamezone.h F: drivers/platform/x86/lenovo-wmi-helpers.c F: drivers/platform/x86/lenovo-wmi-helpers.h F: drivers/platform/x86/lenovo-wmi-other.cdrivers/platform/x86/Kconfig +13
-0@@ -467,6 +467,19 @@ config LENOVO_WMI_HELPERS tristate depends on ACPI_WMI +config LENOVO_WMI_GAMEZONE + tristate "Lenovo GameZone WMI Driver" + depends on ACPI_WMI + select ACPI_PLATFORM_PROFILE + select LENOVO_WMI_EVENTS + select LENOVO_WMI_HELPERS + help + Say Y here if you have a WMI aware Lenovo Legion device and would like to use the + platform-profile firmware interface to manage power usage. + + To compile this driver as a module, choose M here: the module will + be called lenovo-wmi-gamezone. + config LENOVO_WMI_DATA01 tristate depends on ACPI_WMIdrivers/platform/x86/Makefile +1
-0@@ -71,6 +71,7 @@ obj-$(CONFIG_YT2_1380) += lenovo-yoga-tab2-pro-1380-fastcharger.o obj-$(CONFIG_LENOVO_WMI_CAMERA) += lenovo-wmi-camera.o obj-$(CONFIG_LENOVO_WMI_DATA01) += lenovo-wmi-capdata01.o obj-$(CONFIG_LENOVO_WMI_EVENTS) += lenovo-wmi-events.o +obj-$(CONFIG_LENOVO_WMI_GAMEZONE) += lenovo-wmi-gamezone.o obj-$(CONFIG_LENOVO_WMI_HELPERS) += lenovo-wmi-helpers.o obj-$(CONFIG_LENOVO_WMI_TUNING) += lenovo-wmi-other.odrivers/platform/x86/lenovo-wmi-gamezone.c new file +380
-0@@ -0,0 +1,380 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Lenovo GameZone WMI interface driver. The GameZone WMI interface provides +* platform profile and fan curve settings for devices that fall under the +* "Gaming Series" of Lenovo Legion devices. +* +* Copyright(C) 2025 Derek J. Clark <[email protected]> +*/ + +#include <linux/dmi.h> +#include <linux/list.h> +#include <linux/notifier.h> +#include <linux/platform_profile.h> +#include <linux/types.h> +#include <linux/wmi.h> + +#include "lenovo-wmi-events.h" +#include "lenovo-wmi-gamezone.h" +#include "lenovo-wmi-helpers.h" +#include "lenovo-wmi-other.h" + +/* Interface GUIDs */ +#define LENOVO_GAMEZONE_GUID "887B54E3-DDDC-4B2C-8B88-68A26A8835D0" + +/* Method IDs */ +#define WMI_METHOD_ID_SMARTFAN_SUPP 43/* IsSupportSmartFan */ +#define WMI_METHOD_ID_SMARTFAN_SET 44/* SetSmartFanMode */ +#define WMI_METHOD_ID_SMARTFAN_GET 45/* GetSmartFanMode */ + +static BLOCKING_NOTIFIER_HEAD (gz_chain_head); + +struct lwmi_event_priv { +enum thermal_mode current_mode; +struct wmi_device *wdev; +bool extreme_supported; +struct device *ppdev;/*platform profile device */ +struct notifier_block event_nb; +struct notifier_block mode_nb; +}; + +struct quirk_entry { +bool extreme_supported; +}; + +static struct quirk_entry quirk_no_extreme_bug = { + .extreme_supported = false, +}; + +/* Notifier Methods */ +/* +* lwmi_gz_mode_call() - Call method for lenovo-wmi-other notifier +* block call chain. For THERMAL_MODE_EVENT, returns current_mode +* +* @nb: The notifier_block registered to lenovo-wmi-other +* @cmd: The event triggered by lenovo-wmi-other +* @data: The data to be returned by the event. +* +* Returns: notifier_block status. +*/ +static int lwmi_gz_mode_call (struct notifier_block *nb,unsigned long cmd, +void *data) +{ +struct lwmi_event_priv *priv; + + priv = container_of(nb, struct lwmi_event_priv, mode_nb); +if (!priv) +return NOTIFY_BAD ; + +switch (cmd) { +case THERMAL_MODE_EVENT : + *(enum thermal_mode *)data = priv->current_mode; +break ; +default : +return NOTIFY_DONE ; + } + +return NOTIFY_OK ; +} + +/* +* lwmi_gz_event_call() - Call method for lenovo-wmi-events notifier +* block call chain. For THERMAL_MODE_EVENT, sets current_mode and +* notifies platform_profile of a change. +* +* @nb: The notifier_block registered to lenovo-wmi-events +* @cmd: The event triggered by lenovo-wmi-events +* @data: The data to be updated by the event. +* +* Returns: notifier_block status. +*/ +static int lwmi_gz_event_call (struct notifier_block *nb,unsigned long cmd, +void *data) +{ +struct lwmi_event_priv *priv; + + priv = container_of(nb, struct lwmi_event_priv, event_nb); +if (!priv) +return NOTIFY_BAD ; + +switch (cmd) { +case THERMAL_MODE_EVENT : + priv->current_mode = *((enum thermal_mode *)data); +platform_profile_notify (&priv->wdev->dev); +break ; +default : +return NOTIFY_DONE ; + } + +return NOTIFY_OK ; +} + +/* Platform Profile Methods & Setup */ +/* +* lwmi_gz_platform_profile_supported() - Gets the version of the WMI +* interface to determine the support level. +* +* @wdev: The Gamezone WMI device. +* @supported: Pointer to return the support level with. +* +* Returns: 0, or an error. +*/ +static int lwmi_gz_platform_profile_supported (struct wmi_device *wdev, +int *supported) +{ +return lwmi_dev_evaluate_method (wdev,0x0 ,WMI_METHOD_ID_SMARTFAN_SUPP , +0 ,0 , supported); +} + +/* +* lwmi_gz_thermal_mode_get() - Gets the currently set thermal mode from +* the Gamezone WMI interface. +* +* @wdev: The Gamezone WMI device. +* @mode: Pointer to return the thermal mode with. +* +* Returns: 0, or an error. +*/ +static int lwmi_gz_thermal_mode_get (struct wmi_device *wdev, +enum thermal_mode *mode) +{ +return lwmi_dev_evaluate_method (wdev,0x0 ,WMI_METHOD_ID_SMARTFAN_GET , +0 ,0 , mode); +} + +static int lwmi_gz_profile_get (struct device *dev, +enum platform_profile_option *profile) +{ +struct lwmi_event_priv *priv =dev_get_drvdata (dev); +enum thermal_mode mode; +int ret; + + ret =lwmi_gz_thermal_mode_get (priv->wdev, &mode); +if (ret) +return ret; + +switch (mode) { +case SMARTFAN_MODE_QUIET : + *profile =PLATFORM_PROFILE_LOW_POWER ; +break ; +case SMARTFAN_MODE_BALANCED : + *profile =PLATFORM_PROFILE_BALANCED ; +break ; +case SMARTFAN_MODE_PERFORMANCE : +if (priv->extreme_supported) { + *profile =PLATFORM_PROFILE_BALANCED_PERFORMANCE ; +break ; + } + *profile =PLATFORM_PROFILE_PERFORMANCE ; +break ; +case SMARTFAN_MODE_EXTREME : + *profile =PLATFORM_PROFILE_PERFORMANCE ; +break ; +case SMARTFAN_MODE_CUSTOM : + *profile =PLATFORM_PROFILE_CUSTOM ; +break ; +default : +return -EINVAL ; + } + + priv->current_mode = mode; + +return 0 ; +} + +static int lwmi_gz_profile_set (struct device *dev, +enum platform_profile_option profile) +{ +struct lwmi_event_priv *priv =dev_get_drvdata (dev); +struct wmi_method_args_32 args; +enum thermal_mode mode; +int ret; + +switch (profile) { +case PLATFORM_PROFILE_LOW_POWER : + mode =SMARTFAN_MODE_QUIET ; +break ; +case PLATFORM_PROFILE_BALANCED : + mode =SMARTFAN_MODE_BALANCED ; +break ; +case PLATFORM_PROFILE_BALANCED_PERFORMANCE : + mode =SMARTFAN_MODE_PERFORMANCE ; +break ; +case PLATFORM_PROFILE_PERFORMANCE : +if (priv->extreme_supported) { + mode =SMARTFAN_MODE_EXTREME ; +break ; + } + mode =SMARTFAN_MODE_PERFORMANCE ; +break ; +case PLATFORM_PROFILE_CUSTOM : + mode =SMARTFAN_MODE_CUSTOM ; +break ; +default : +return -EOPNOTSUPP ; + } + + args.arg0 = mode; + + ret =lwmi_dev_evaluate_method (priv->wdev,0x0 , +WMI_METHOD_ID_SMARTFAN_SET , + (unsigned char *)&args,sizeof (args), +NULL ); +if (ret) +return ret; + + priv->current_mode = mode; + +return 0 ; +} + +static const struct dmi_system_id fwbug_list[] = { + { + .ident ="Legion Go 8APU1" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_VERSION ,"Legion Go 8APU1" ), + }, + .driver_data = &quirk_no_extreme_bug, + }, + { + .ident ="Legion Go S 8ARP1" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_VERSION ,"Legion Go S 8ARP1" ), + }, + .driver_data = &quirk_no_extreme_bug, + }, + { + .ident ="Legion Go S 8APU1" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_VERSION ,"Legion Go S 8APU1" ), + }, + .driver_data = &quirk_no_extreme_bug, + }, + {}, + +}; + +/* +* extreme_supported() - Evaluate if a device supports extreme thermal mode. +* For devices that have a profile_support_ver of 6 or greater a DMI check +* is done. Some devices report a version that supports extreme mode but +* have an incomplete entry in the BIOS. To ensure this cannot be set, they +* are quirked to prevent assignment. +* +* @profile_support_ver: Version of WMI interface provided by +* lwmi_gz_platform_profile_supported. +* +* Returns: bool +*/ +static bool extreme_supported (int profile_support_ver) +{ +const struct dmi_system_id *dmi_id; +struct quirk_entry *quirks; + +if (profile_support_ver <6 ) +return false; + + dmi_id =dmi_first_match (fwbug_list); +if (!dmi_id) +return true; + + quirks = dmi_id->driver_data; +return quirks->extreme_supported; +} + +static int lwmi_platform_profile_probe (void *drvdata,unsigned long *choices) +{ +struct lwmi_event_priv *priv = drvdata; +int profile_support_ver; +int ret; + + ret =lwmi_gz_platform_profile_supported (priv->wdev, + &profile_support_ver); +if (ret) +return ret; + +if (profile_support_ver <1 ) +return -ENODEV ; + + priv->extreme_supported =extreme_supported (profile_support_ver); + +set_bit (PLATFORM_PROFILE_LOW_POWER , choices); +set_bit (PLATFORM_PROFILE_BALANCED , choices); +set_bit (PLATFORM_PROFILE_PERFORMANCE , choices); +set_bit (PLATFORM_PROFILE_CUSTOM , choices); + +if (priv->extreme_supported) +set_bit (PLATFORM_PROFILE_BALANCED_PERFORMANCE , choices); + +return 0 ; +} + +static const struct platform_profile_ops lwmi_gz_platform_profile_ops = { + .probe = lwmi_platform_profile_probe, + .profile_get = lwmi_gz_profile_get, + .profile_set = lwmi_gz_profile_set, +}; + +/* Driver Methods */ +static int lwmi_gz_probe (struct wmi_device *wdev,const void *context) +{ +struct lwmi_event_priv *priv; +int ret; + + priv =devm_kzalloc (&wdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + priv->event_nb.notifier_call = lwmi_gz_event_call; + ret =devm_lwmi_events_register_notifier (&wdev->dev, &priv->event_nb); +if (ret) +return ret; + + priv->mode_nb.notifier_call = lwmi_gz_mode_call; + ret =devm_lwmi_om_register_notifier (&wdev->dev, &priv->mode_nb); +if (ret) +return ret; + + priv->wdev = wdev; +dev_set_drvdata (&wdev->dev, priv); + + priv->ppdev =platform_profile_register (&wdev->dev, +"lenovo-wmi-gamezone" , priv, + &lwmi_gz_platform_profile_ops); + +if (IS_ERR (priv->ppdev)) +return -ENODEV ; + + ret =lwmi_gz_thermal_mode_get (wdev, &priv->current_mode); +if (ret) +return ret; + +return 0 ; +} + +static const struct wmi_device_id lwmi_gz_id_table[] = { {LENOVO_GAMEZONE_GUID , +NULL }, + {} }; + +static struct wmi_driver lwmi_gz_driver = { + .driver = { + .name ="lenovo_wmi_gamezone" , + .probe_type =PROBE_PREFER_ASYNCHRONOUS , + }, + .id_table = lwmi_gz_id_table, + .probe = lwmi_gz_probe, + .no_singleton = true, +}; + +module_wmi_driver (lwmi_gz_driver); + +MODULE_IMPORT_NS ("LENOVO_WMI_EVENTS" ); +MODULE_IMPORT_NS ("LENOVO_WMI_HELPERS" ); +MODULE_IMPORT_NS ("LENOVO_WMI_OTHER" ); +MODULE_DEVICE_TABLE (wmi, lwmi_gz_id_table); +MODULE_AUTHOR ("Derek J. Clark <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo GameZone WMI Driver" ); +MODULE_LICENSE ("GPL" );drivers/platform/x86/lenovo-wmi-gamezone.h new file +8
-0@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* Copyright(C) 2025 Derek J. Clark <[email protected]> +* +*/ + +#ifndef _LENOVO_WMI_GAMEZONE_H_ +#define _LENOVO_WMI_GAMEZONE_H_
drivers/platform/x86/lenovo-wmi-gamezone.h line 18
Quoted 10 lines
drivers/platform/x86/lenovo-wmi-gamezone.h new file +10
-0+ +enum thermal_mode { +SMARTFAN_MODE_QUIET =0x01 , +SMARTFAN_MODE_BALANCED =0x02 , +SMARTFAN_MODE_PERFORMANCE =0x03 , +SMARTFAN_MODE_EXTREME =0xE0 ,/* Ver 6+ */ +SMARTFAN_MODE_CUSTOM =0xFF , +}; + +#endif /* !_LENOVO_WMI_GAMEZONE_H_ */
Are these going the be used by other .c files?
Signature · 1 line
i.
Derek John Clark
maintainerRe: [PATCH v4 6/6 RESEND] platform/x86: Add Lenovo Gamezone WMI Driver
Quoted 503 lines · Ilpo Järvinen
Quoted 5 lines · Derek J. Clark
Adds lenovo-wmi-gamezone driver which provides the Lenovo Gamezone WMI interface that comes on Lenovo "Gaming Series" hardware. Provides ACPI platform profiles over WMI.
Signed-off-by Derek J. Clark <[email protected]>This has a few similar nits I flagged for the other patches but I won't mark them here again but please go through the patches to find similar cases.
Quoted 490 lines
---
v4:
- Add notifier blocks for the Events and Other Mode drivers.
- Remove notifier block chain head and all reference to Thermal Mode Event GUID.
- Add header for Gamezone specific structs and functions.
- Various fixes from review.
v3:
- Use notifier chain to report platform profile changes to any subscribed drivers.
- AddsTHERMAL_MODE_EVENTGUID and .notify function to trigger notifier chain.
- Adds support for Extreme Mode profile on supported hardware, as well as a DMI quirk table for some devices that report extreme mode version support but so not have it fully implemented.
- Update to include recent changes to platform-profile.
v2:
- Usedevm_kmallocto ensure driver can be instanced, remove global reference.
- Ensure reverse Christmas tree for all variable declarations.
- Remove extra whitespace.
- Use guard(mutex) in all mutex instances, global mutex.
- Usepr_fmtinstead of adding the driver name to eachpr_err.
- Remove noisypr_infousage.
- Renamegamezone_wmitolenovo_wmi_gz_privandgz_wmito priv.
- RemoveGZ_WMIsymbol exporting.--- MAINTAINERS | 2 + drivers/platform/x86/Kconfig | 13 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/lenovo-wmi-gamezone.c | 380 +++++++++++++++++++++ drivers/platform/x86/lenovo-wmi-gamezone.h | 18 + 5 files changed, 414 insertions(+) create mode 100644 drivers/platform/x86/lenovo-wmi-gamezone.c create mode 100644 drivers/platform/x86/lenovo-wmi-gamezone.hMAINTAINERS +2
-0@@ -13168,6 +13168,8 @@ F: drivers/platform/x86/lenovo-wmi-capdata01.c F: drivers/platform/x86/lenovo-wmi-capdata01.h F: drivers/platform/x86/lenovo-wmi-events.c F: drivers/platform/x86/lenovo-wmi-events.h +F: drivers/platform/x86/lenovo-wmi-gamezone.c +F: drivers/platform/x86/lenovo-wmi-gamezone.h F: drivers/platform/x86/lenovo-wmi-helpers.c F: drivers/platform/x86/lenovo-wmi-helpers.h F: drivers/platform/x86/lenovo-wmi-other.cdrivers/platform/x86/Kconfig +13
-0@@ -467,6 +467,19 @@ config LENOVO_WMI_HELPERS tristate depends on ACPI_WMI +config LENOVO_WMI_GAMEZONE + tristate "Lenovo GameZone WMI Driver" + depends on ACPI_WMI + select ACPI_PLATFORM_PROFILE + select LENOVO_WMI_EVENTS + select LENOVO_WMI_HELPERS + help + Say Y here if you have a WMI aware Lenovo Legion device and would like to use the + platform-profile firmware interface to manage power usage. + + To compile this driver as a module, choose M here: the module will + be called lenovo-wmi-gamezone. + config LENOVO_WMI_DATA01 tristate depends on ACPI_WMIdrivers/platform/x86/Makefile +1
-0@@ -71,6 +71,7 @@ obj-$(CONFIG_YT2_1380) += lenovo-yoga-tab2-pro-1380-fastcharger.o obj-$(CONFIG_LENOVO_WMI_CAMERA) += lenovo-wmi-camera.o obj-$(CONFIG_LENOVO_WMI_DATA01) += lenovo-wmi-capdata01.o obj-$(CONFIG_LENOVO_WMI_EVENTS) += lenovo-wmi-events.o +obj-$(CONFIG_LENOVO_WMI_GAMEZONE) += lenovo-wmi-gamezone.o obj-$(CONFIG_LENOVO_WMI_HELPERS) += lenovo-wmi-helpers.o obj-$(CONFIG_LENOVO_WMI_TUNING) += lenovo-wmi-other.odrivers/platform/x86/lenovo-wmi-gamezone.c new file +380
-0@@ -0,0 +1,380 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Lenovo GameZone WMI interface driver. The GameZone WMI interface provides +* platform profile and fan curve settings for devices that fall under the +* "Gaming Series" of Lenovo Legion devices. +* +* Copyright(C) 2025 Derek J. Clark <[email protected]> +*/ + +#include <linux/dmi.h> +#include <linux/list.h> +#include <linux/notifier.h> +#include <linux/platform_profile.h> +#include <linux/types.h> +#include <linux/wmi.h> + +#include "lenovo-wmi-events.h" +#include "lenovo-wmi-gamezone.h" +#include "lenovo-wmi-helpers.h" +#include "lenovo-wmi-other.h" + +/* Interface GUIDs */ +#define LENOVO_GAMEZONE_GUID "887B54E3-DDDC-4B2C-8B88-68A26A8835D0" + +/* Method IDs */ +#define WMI_METHOD_ID_SMARTFAN_SUPP 43/* IsSupportSmartFan */ +#define WMI_METHOD_ID_SMARTFAN_SET 44/* SetSmartFanMode */ +#define WMI_METHOD_ID_SMARTFAN_GET 45/* GetSmartFanMode */ + +static BLOCKING_NOTIFIER_HEAD (gz_chain_head); + +struct lwmi_event_priv { +enum thermal_mode current_mode; +struct wmi_device *wdev; +bool extreme_supported; +struct device *ppdev;/*platform profile device */ +struct notifier_block event_nb; +struct notifier_block mode_nb; +}; + +struct quirk_entry { +bool extreme_supported; +}; + +static struct quirk_entry quirk_no_extreme_bug = { + .extreme_supported = false, +}; + +/* Notifier Methods */ +/* +* lwmi_gz_mode_call() - Call method for lenovo-wmi-other notifier +* block call chain. For THERMAL_MODE_EVENT, returns current_mode +* +* @nb: The notifier_block registered to lenovo-wmi-other +* @cmd: The event triggered by lenovo-wmi-other +* @data: The data to be returned by the event. +* +* Returns: notifier_block status. +*/ +static int lwmi_gz_mode_call (struct notifier_block *nb,unsigned long cmd, +void *data) +{ +struct lwmi_event_priv *priv; + + priv = container_of(nb, struct lwmi_event_priv, mode_nb); +if (!priv) +return NOTIFY_BAD ; + +switch (cmd) { +case THERMAL_MODE_EVENT : + *(enum thermal_mode *)data = priv->current_mode; +break ; +default : +return NOTIFY_DONE ; + } + +return NOTIFY_OK ; +} + +/* +* lwmi_gz_event_call() - Call method for lenovo-wmi-events notifier +* block call chain. For THERMAL_MODE_EVENT, sets current_mode and +* notifies platform_profile of a change. +* +* @nb: The notifier_block registered to lenovo-wmi-events +* @cmd: The event triggered by lenovo-wmi-events +* @data: The data to be updated by the event. +* +* Returns: notifier_block status. +*/ +static int lwmi_gz_event_call (struct notifier_block *nb,unsigned long cmd, +void *data) +{ +struct lwmi_event_priv *priv; + + priv = container_of(nb, struct lwmi_event_priv, event_nb); +if (!priv) +return NOTIFY_BAD ; + +switch (cmd) { +case THERMAL_MODE_EVENT : + priv->current_mode = *((enum thermal_mode *)data); +platform_profile_notify (&priv->wdev->dev); +break ; +default : +return NOTIFY_DONE ; + } + +return NOTIFY_OK ; +} + +/* Platform Profile Methods & Setup */ +/* +* lwmi_gz_platform_profile_supported() - Gets the version of the WMI +* interface to determine the support level. +* +* @wdev: The Gamezone WMI device. +* @supported: Pointer to return the support level with. +* +* Returns: 0, or an error. +*/ +static int lwmi_gz_platform_profile_supported (struct wmi_device *wdev, +int *supported) +{ +return lwmi_dev_evaluate_method (wdev,0x0 ,WMI_METHOD_ID_SMARTFAN_SUPP , +0 ,0 , supported); +} + +/* +* lwmi_gz_thermal_mode_get() - Gets the currently set thermal mode from +* the Gamezone WMI interface. +* +* @wdev: The Gamezone WMI device. +* @mode: Pointer to return the thermal mode with. +* +* Returns: 0, or an error. +*/ +static int lwmi_gz_thermal_mode_get (struct wmi_device *wdev, +enum thermal_mode *mode) +{ +return lwmi_dev_evaluate_method (wdev,0x0 ,WMI_METHOD_ID_SMARTFAN_GET , +0 ,0 , mode); +} + +static int lwmi_gz_profile_get (struct device *dev, +enum platform_profile_option *profile) +{ +struct lwmi_event_priv *priv =dev_get_drvdata (dev); +enum thermal_mode mode; +int ret; + + ret =lwmi_gz_thermal_mode_get (priv->wdev, &mode); +if (ret) +return ret; + +switch (mode) { +case SMARTFAN_MODE_QUIET : + *profile =PLATFORM_PROFILE_LOW_POWER ; +break ; +case SMARTFAN_MODE_BALANCED : + *profile =PLATFORM_PROFILE_BALANCED ; +break ; +case SMARTFAN_MODE_PERFORMANCE : +if (priv->extreme_supported) { + *profile =PLATFORM_PROFILE_BALANCED_PERFORMANCE ; +break ; + } + *profile =PLATFORM_PROFILE_PERFORMANCE ; +break ; +case SMARTFAN_MODE_EXTREME : + *profile =PLATFORM_PROFILE_PERFORMANCE ; +break ; +case SMARTFAN_MODE_CUSTOM : + *profile =PLATFORM_PROFILE_CUSTOM ; +break ; +default : +return -EINVAL ; + } + + priv->current_mode = mode; + +return 0 ; +} + +static int lwmi_gz_profile_set (struct device *dev, +enum platform_profile_option profile) +{ +struct lwmi_event_priv *priv =dev_get_drvdata (dev); +struct wmi_method_args_32 args; +enum thermal_mode mode; +int ret; + +switch (profile) { +case PLATFORM_PROFILE_LOW_POWER : + mode =SMARTFAN_MODE_QUIET ; +break ; +case PLATFORM_PROFILE_BALANCED : + mode =SMARTFAN_MODE_BALANCED ; +break ; +case PLATFORM_PROFILE_BALANCED_PERFORMANCE : + mode =SMARTFAN_MODE_PERFORMANCE ; +break ; +case PLATFORM_PROFILE_PERFORMANCE : +if (priv->extreme_supported) { + mode =SMARTFAN_MODE_EXTREME ; +break ; + } + mode =SMARTFAN_MODE_PERFORMANCE ; +break ; +case PLATFORM_PROFILE_CUSTOM : + mode =SMARTFAN_MODE_CUSTOM ; +break ; +default : +return -EOPNOTSUPP ; + } + + args.arg0 = mode; + + ret =lwmi_dev_evaluate_method (priv->wdev,0x0 , +WMI_METHOD_ID_SMARTFAN_SET , + (unsigned char *)&args,sizeof (args), +NULL ); +if (ret) +return ret; + + priv->current_mode = mode; + +return 0 ; +} + +static const struct dmi_system_id fwbug_list[] = { + { + .ident ="Legion Go 8APU1" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_VERSION ,"Legion Go 8APU1" ), + }, + .driver_data = &quirk_no_extreme_bug, + }, + { + .ident ="Legion Go S 8ARP1" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_VERSION ,"Legion Go S 8ARP1" ), + }, + .driver_data = &quirk_no_extreme_bug, + }, + { + .ident ="Legion Go S 8APU1" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), +DMI_MATCH (DMI_PRODUCT_VERSION ,"Legion Go S 8APU1" ), + }, + .driver_data = &quirk_no_extreme_bug, + }, + {}, + +}; + +/* +* extreme_supported() - Evaluate if a device supports extreme thermal mode. +* For devices that have a profile_support_ver of 6 or greater a DMI check +* is done. Some devices report a version that supports extreme mode but +* have an incomplete entry in the BIOS. To ensure this cannot be set, they +* are quirked to prevent assignment. +* +* @profile_support_ver: Version of WMI interface provided by +* lwmi_gz_platform_profile_supported. +* +* Returns: bool +*/ +static bool extreme_supported (int profile_support_ver) +{ +const struct dmi_system_id *dmi_id; +struct quirk_entry *quirks; + +if (profile_support_ver <6 ) +return false; + + dmi_id =dmi_first_match (fwbug_list); +if (!dmi_id) +return true; + + quirks = dmi_id->driver_data; +return quirks->extreme_supported; +} + +static int lwmi_platform_profile_probe (void *drvdata,unsigned long *choices) +{ +struct lwmi_event_priv *priv = drvdata; +int profile_support_ver; +int ret; + + ret =lwmi_gz_platform_profile_supported (priv->wdev, + &profile_support_ver); +if (ret) +return ret; + +if (profile_support_ver <1 ) +return -ENODEV ; + + priv->extreme_supported =extreme_supported (profile_support_ver); + +set_bit (PLATFORM_PROFILE_LOW_POWER , choices); +set_bit (PLATFORM_PROFILE_BALANCED , choices); +set_bit (PLATFORM_PROFILE_PERFORMANCE , choices); +set_bit (PLATFORM_PROFILE_CUSTOM , choices); + +if (priv->extreme_supported) +set_bit (PLATFORM_PROFILE_BALANCED_PERFORMANCE , choices); + +return 0 ; +} + +static const struct platform_profile_ops lwmi_gz_platform_profile_ops = { + .probe = lwmi_platform_profile_probe, + .profile_get = lwmi_gz_profile_get, + .profile_set = lwmi_gz_profile_set, +}; + +/* Driver Methods */ +static int lwmi_gz_probe (struct wmi_device *wdev,const void *context) +{ +struct lwmi_event_priv *priv; +int ret; + + priv =devm_kzalloc (&wdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + priv->event_nb.notifier_call = lwmi_gz_event_call; + ret =devm_lwmi_events_register_notifier (&wdev->dev, &priv->event_nb); +if (ret) +return ret; + + priv->mode_nb.notifier_call = lwmi_gz_mode_call; + ret =devm_lwmi_om_register_notifier (&wdev->dev, &priv->mode_nb); +if (ret) +return ret; + + priv->wdev = wdev; +dev_set_drvdata (&wdev->dev, priv); + + priv->ppdev =platform_profile_register (&wdev->dev, +"lenovo-wmi-gamezone" , priv, + &lwmi_gz_platform_profile_ops); + +if (IS_ERR (priv->ppdev)) +return -ENODEV ; + + ret =lwmi_gz_thermal_mode_get (wdev, &priv->current_mode); +if (ret) +return ret; + +return 0 ; +} + +static const struct wmi_device_id lwmi_gz_id_table[] = { {LENOVO_GAMEZONE_GUID , +NULL }, + {} }; + +static struct wmi_driver lwmi_gz_driver = { + .driver = { + .name ="lenovo_wmi_gamezone" , + .probe_type =PROBE_PREFER_ASYNCHRONOUS , + }, + .id_table = lwmi_gz_id_table, + .probe = lwmi_gz_probe, + .no_singleton = true, +}; + +module_wmi_driver (lwmi_gz_driver); + +MODULE_IMPORT_NS ("LENOVO_WMI_EVENTS" ); +MODULE_IMPORT_NS ("LENOVO_WMI_HELPERS" ); +MODULE_IMPORT_NS ("LENOVO_WMI_OTHER" ); +MODULE_DEVICE_TABLE (wmi, lwmi_gz_id_table); +MODULE_AUTHOR ("Derek J. Clark <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo GameZone WMI Driver" ); +MODULE_LICENSE ("GPL" );drivers/platform/x86/lenovo-wmi-gamezone.h new file +13
-0@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* Copyright(C) 2025 Derek J. Clark <[email protected]> +* +*/ + +#ifndef _LENOVO_WMI_GAMEZONE_H_ +#define _LENOVO_WMI_GAMEZONE_H_ + +enum thermal_mode { +SMARTFAN_MODE_QUIET =0x01 , +SMARTFAN_MODE_BALANCED =0x02 , + SMARTFAN_MODE_PERFORMANCE = 0x03,
Quoted 9 lines
drivers/platform/x86/lenovo-wmi-gamezone.h line 18
Quoted 6 lines
drivers/platform/x86/lenovo-wmi-gamezone.h new file +5
-0+SMARTFAN_MODE_EXTREME =0xE0 ,/* Ver 6+ */ + SMARTFAN_MODE_CUSTOM = 0xFF, +}; + +#endif /* !_LENOVO_WMI_GAMEZONE_H_ */ Are these going the be used by other .c files?
They are used across different c files in this series. The lenovo-wmi-other driver uses every header.
- Derek
Quoted 3 lines
--
i.
Ilpo Järvinen
maintainerRe: [PATCH v4 6/6 RESEND] platform/x86: Add Lenovo Gamezone WMI Driver
Quoted 81 lines · Derek John Clark
Quoted 69 lines · Ilpo Järvinen
Quoted 5 lines · Derek J. Clark
Adds lenovo-wmi-gamezone driver which provides the Lenovo Gamezone WMI interface that comes on Lenovo "Gaming Series" hardware. Provides ACPI platform profiles over WMI.
Signed-off-by Derek J. Clark <[email protected]>This has a few similar nits I flagged for the other patches but I won't mark them here again but please go through the patches to find similar cases.
Quoted 56 lines
---
v4:
- Add notifier blocks for the Events and Other Mode drivers.
- Remove notifier block chain head and all reference to Thermal Mode Event GUID.
- Add header for Gamezone specific structs and functions.
- Various fixes from review.
v3:
- Use notifier chain to report platform profile changes to any subscribed drivers.
- AddsTHERMAL_MODE_EVENTGUID and .notify function to trigger notifier chain.
- Adds support for Extreme Mode profile on supported hardware, as well as a DMI quirk table for some devices that report extreme mode version support but so not have it fully implemented.
- Update to include recent changes to platform-profile.
v2:
- Usedevm_kmallocto ensure driver can be instanced, remove global reference.
- Ensure reverse Christmas tree for all variable declarations.
- Remove extra whitespace.
- Use guard(mutex) in all mutex instances, global mutex.
- Usepr_fmtinstead of adding the driver name to eachpr_err.
- Remove noisypr_infousage.
- Renamegamezone_wmitolenovo_wmi_gz_privandgz_wmito priv.
- RemoveGZ_WMIsymbol exporting.--- MAINTAINERS | 2 + drivers/platform/x86/Kconfig | 13 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/lenovo-wmi-gamezone.c | 380 +++++++++++++++++++++ drivers/platform/x86/lenovo-wmi-gamezone.h | 18 + 5 files changed, 414 insertions(+) create mode 100644 drivers/platform/x86/lenovo-wmi-gamezone.c create mode 100644 drivers/platform/x86/lenovo-wmi-gamezone.hdrivers/platform/x86/lenovo-wmi-gamezone.h new file +13
-0@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* Copyright(C) 2025 Derek J. Clark <[email protected]> +* +*/ + +#ifndef _LENOVO_WMI_GAMEZONE_H_ +#define _LENOVO_WMI_GAMEZONE_H_ + +enum thermal_mode { +SMARTFAN_MODE_QUIET =0x01 , +SMARTFAN_MODE_BALANCED =0x02 , + SMARTFAN_MODE_PERFORMANCE = 0x03,Quoted 9 lines
drivers/platform/x86/lenovo-wmi-gamezone.h line 18
Quoted 6 lines
drivers/platform/x86/lenovo-wmi-gamezone.h new file +5
-0+SMARTFAN_MODE_EXTREME =0xE0 ,/* Ver 6+ */ + SMARTFAN_MODE_CUSTOM = 0xFF, +}; + +#endif /* !_LENOVO_WMI_GAMEZONE_H_ */ Are these going the be used by other .c files?
Quoted 2 lines
They are used across different c files in this series. The lenovo-wmi-other driver uses every header.
Oh, how can this then be the last patch of the series???
Won't the build fail before this patch for lenovo-wmi-other.c?
Signature · 1 line
i.
Armin Wolf
maintainerAm 17.03.25 um 15:43 schrieb Derek J. Clark:
Quoted 13 lines
Adds support for the Lenovo "Gaming Series" of laptop hardware that use WMI interfaces that control various power settings. There are multiple WMI interfaces that work in concert to provide getting and setting values as well as validation of input. Currently only the "Gamezone", "Other Mode", and "
LENOVO_CAPABILITY_DATA_01" interfaces are implemented, but I attempted to structure the driver so that adding the "Custom Mode", "Lighting", and other data block interfaces would be trivial in a later patches.This driver is distinct from, but should be considered a replacement for this patch:
https://lore.kernel.org/all/[email protected]/
Quoted 7 lines
This driver attempts to standardize the exposed sysfs by mirroring the asus-armoury driver currently under review. As such, a lot of inspiration has been drawn from that driver.
https://lore.kernel.org/platform-driver-x86/[email protected]/The drivers have been tested by me on the Lenovo Legion Go and Legion Go S.
So far the patch series looks promising. The basic architecture seems to be finished by now, only some implementation details need to be fleshed out.
Thanks,
Armin Wolf
Quoted 52 lines
Suggested-by Mario Limonciello <[email protected]>Signed-off-by Derek J. Clark <[email protected]>---
v4:
- Added lenovo-wmi-events driver
- Added headers for every driver
- Fixes requested from v3 review
v3:
https://lore.kernel.org/platform-driver-x86/[email protected]/
v2:
https://lore.kernel.org/platform-driver-x86/[email protected]/
v1:
https://lore.kernel.org/platform-driver-x86/[email protected]/Derek J. Clark (6):
platform/x86: Add lenovo-wmi-* driver Documentation platform/x86: Add lenovo-wmi-helpers platform/x86: Add Lenovo WMI Events Driver platform/x86: Add Lenovo Capability Data 01 WMI Driver platform/x86: Add Lenovo Other Mode WMI Driver platform/x86: Add Lenovo Gamezone WMI Driver.../wmi/devices/lenovo-wmi-gamezone.rst | 203 ++++++ .../wmi/devices/lenovo-wmi-other-method.rst | 108 +++ MAINTAINERS | 17 + drivers/platform/x86/Kconfig | 40 ++ drivers/platform/x86/Makefile | 5 + drivers/platform/x86/lenovo-wmi-capdata01.c | 136 ++++ drivers/platform/x86/lenovo-wmi-capdata01.h | 29 + drivers/platform/x86/lenovo-wmi-events.c | 132 ++++ drivers/platform/x86/lenovo-wmi-events.h | 21 + drivers/platform/x86/lenovo-wmi-gamezone.c | 380 +++++++++++ drivers/platform/x86/lenovo-wmi-gamezone.h | 18 + drivers/platform/x86/lenovo-wmi-helpers.c | 64 ++ drivers/platform/x86/lenovo-wmi-helpers.h | 24 + drivers/platform/x86/lenovo-wmi-other.c | 626 ++++++++++++++++++ drivers/platform/x86/lenovo-wmi-other.h | 19 + 15 files changed, 1822 insertions(+)create mode 100644
Documentation/wmi/devices/lenovo-wmi-gamezone.rstcreate mode 100644Documentation/wmi/devices/lenovo-wmi-other-method.rstcreate mode 100644drivers/platform/x86/lenovo-wmi-capdata01.ccreate mode 100644drivers/platform/x86/lenovo-wmi-capdata01.hcreate mode 100644drivers/platform/x86/lenovo-wmi-events.ccreate mode 100644drivers/platform/x86/lenovo-wmi-events.hcreate mode 100644drivers/platform/x86/lenovo-wmi-gamezone.ccreate mode 100644drivers/platform/x86/lenovo-wmi-gamezone.hcreate mode 100644drivers/platform/x86/lenovo-wmi-helpers.ccreate mode 100644drivers/platform/x86/lenovo-wmi-helpers.hcreate mode 100644drivers/platform/x86/lenovo-wmi-other.ccreate mode 100644drivers/platform/x86/lenovo-wmi-other.h