From: "Derek J. Clark" <derekjohn.clark@gmail.com>
To: "Rong Zhang" <i@rong.moe>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Hans de Goede" <hansg@kernel.org>
Cc: Mark Pearson <mpearson-lenovo@squebb.ca>,
Armin Wolf <W_Armin@gmx.de>, Jonathan Corbet <corbet@lwn.net>,
Kurt Borja <kuurtb@gmail.com>,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 3/8] platform/x86: lenovo-wmi-other: Add lwmi_attr_id() function
Date: Sat, 14 Mar 2026 20:38:28 -0700 [thread overview]
Message-ID: <CD767F09-E737-4F8F-9FAD-00277F030643@gmail.com> (raw)
In-Reply-To: <e44e31bf1f811c504d1ee199c9fd8b239731995e.camel@rong.moe>
On March 14, 2026 6:08:55 PM PDT, Rong Zhang <i@rong.moe> wrote:
>Hi Derek,
>
>On Thu, 2026-03-12 at 03:10 +0000, Derek J. Clark wrote:
>> Adds lwmi_attr_id() function. In the same vein as LWMI_ATTR_ID_FAN_RPM(),
>> but as a generic, to de-duplicate attribute_id assignment biolerplate.
>>
>> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
>> ---
>> v4:
>> - Switch from macro to static inline to preserve types.
>> ---
>> drivers/platform/x86/lenovo/wmi-gamezone.h | 1 +
>> drivers/platform/x86/lenovo/wmi-other.c | 59 +++++++++++++---------
>> 2 files changed, 35 insertions(+), 25 deletions(-)
>>
>> diff --git a/drivers/platform/x86/lenovo/wmi-gamezone.h b/drivers/platform/x86/lenovo/wmi-gamezone.h
>> index 6b163a5eeb95..ddb919cf6c36 100644
>> --- a/drivers/platform/x86/lenovo/wmi-gamezone.h
>> +++ b/drivers/platform/x86/lenovo/wmi-gamezone.h
>> @@ -10,6 +10,7 @@ enum gamezone_events_type {
>> };
>>
>> enum thermal_mode {
>> + LWMI_GZ_THERMAL_MODE_NONE = 0x00,
>> LWMI_GZ_THERMAL_MODE_QUIET = 0x01,
>> LWMI_GZ_THERMAL_MODE_BALANCED = 0x02,
>> LWMI_GZ_THERMAL_MODE_PERFORMANCE = 0x03,
>> diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
>> index c1728c7c2957..9fff9c1f768c 100644
>> --- a/drivers/platform/x86/lenovo/wmi-other.c
>> +++ b/drivers/platform/x86/lenovo/wmi-other.c
>> @@ -73,10 +73,26 @@
>>
>> #define LWMI_FAN_DIV 100
>>
>> -#define LWMI_ATTR_ID_FAN_RPM(x) \
>> - (FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, LWMI_DEVICE_ID_FAN) | \
>> - FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, LWMI_FEATURE_ID_FAN_RPM) | \
>> - FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, LWMI_FAN_ID(x)))
>> +/**
>> + * lwmi_attr_id() - Formats a capability data attribute ID
>> + * @dev_id: The u8 corresponding to the device ID.
>> + * @feat_id: The u8 corresponding to the feature ID on the device.
>> + * @mode_id: The u8 corresponding to the wmi-gamezone mode for set/get.
>> + * @type_id: The u8 corresponding to the sub-device.
>> + *
>> + * Return: u32.
>> + */
>> +static u32 lwmi_attr_id(u8 dev_id, u8 feat_id, u8 mode_id, u8 type_id)
>> +{
>> + return (FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, dev_id) |
>> + FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, feat_id) |
>> + FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode_id) |
>> + FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, type_id));
>> +}
>> +
>> +#define LWMI_ATTR_ID_FAN_RPM(x) \
>> + lwmi_attr_id(LWMI_DEVICE_ID_FAN, LWMI_FEATURE_ID_FAN_RPM, \
>> + LWMI_GZ_THERMAL_MODE_NONE, LWMI_FAN_ID(x))
>>
>> #define LWMI_OM_FW_ATTR_BASE_PATH "lenovo-wmi-other"
>> #define LWMI_OM_HWMON_NAME "lenovo_wmi_other"
>> @@ -550,6 +566,8 @@ struct tunable_attr_01 {
>> u8 feature_id;
>> u8 device_id;
>> u8 type_id;
>> + u8 cd_mode_id; /* mode arg for searching capdata */
>> + u8 cv_mode_id; /* mode arg for set/get current_value */
>
>Adding them actually depends on [PATCH v4 4/8], otherwise you always
>get 0 when accessing them in this patch. There are potential
>regressions...
>
>
Hi Rong,
Good catch. I think they got moved during a rebase edit by mistake. Thanks.
- Derek
>> };
>>
>> static struct tunable_attr_01 ppt_pl1_spl = {
>> @@ -715,12 +733,8 @@ static ssize_t attr_capdata01_show(struct kobject *kobj,
>> u32 attribute_id;
>> int value, ret;
>>
>> - attribute_id =
>> - FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) |
>> - FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) |
>> - FIELD_PREP(LWMI_ATTR_MODE_ID_MASK,
>> - LWMI_GZ_THERMAL_MODE_CUSTOM) |
>> - FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id);
>> + attribute_id = lwmi_attr_id(tunable_attr->device_id, tunable_attr->feature_id,
>> + LWMI_GZ_THERMAL_MODE_CUSTOM, tunable_attr->type_id);
>>
>> ret = lwmi_cd01_get_data(priv->cd01_list, attribute_id, &capdata);
>> if (ret)
>> @@ -775,7 +789,6 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
>> struct wmi_method_args_32 args;
>> struct capdata01 capdata;
>> enum thermal_mode mode;
>> - u32 attribute_id;
>> u32 value;
>> int ret;
>>
>> @@ -786,13 +799,10 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
>> if (mode != LWMI_GZ_THERMAL_MODE_CUSTOM)
>> return -EBUSY;
>>
>> - attribute_id =
>> - FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) |
>> - FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) |
>> - FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode) |
>> - FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id);
>> + args.arg0 = lwmi_attr_id(tunable_attr->device_id, tunable_attr->feature_id,
>> + mode, tunable_attr->type_id);
>>
>> - ret = lwmi_cd01_get_data(priv->cd01_list, attribute_id, &capdata);
>> + ret = lwmi_cd01_get_data(priv->cd01_list, args.arg0, &capdata);
>> if (ret)
>> return ret;
>>
>> @@ -803,7 +813,8 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
>> if (value < capdata.min_value || value > capdata.max_value)
>> return -EINVAL;
>>
>> - args.arg0 = attribute_id;
>> + args.arg0 = lwmi_attr_id(tunable_attr->device_id, tunable_attr->feature_id,
>> + tunable_attr->cv_mode_id, tunable_attr->type_id);
>
>...here...
>
>> args.arg1 = value;
>>
>> ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_SET,
>> @@ -837,7 +848,6 @@ static ssize_t attr_current_value_show(struct kobject *kobj,
>> struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev);
>> struct wmi_method_args_32 args;
>> enum thermal_mode mode;
>> - u32 attribute_id;
>> int retval;
>> int ret;
>>
>> @@ -845,13 +855,12 @@ static ssize_t attr_current_value_show(struct kobject *kobj,
>> if (ret)
>> return ret;
>>
>> - attribute_id =
>> - FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) |
>> - FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) |
>> - FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode) |
>> - FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id);
>> + /* If "no-mode" is the supported mode, ensure we never send current mode */
>> + if (tunable_attr->cv_mode_id == LWMI_GZ_THERMAL_MODE_NONE)
>> + mode = tunable_attr->cv_mode_id;
>
>...and here.
>
>Thanks,
>Rong
>
>>
>> - args.arg0 = attribute_id;
>> + args.arg0 = lwmi_attr_id(tunable_attr->device_id, tunable_attr->feature_id,
>> + mode, tunable_attr->type_id);
>>
>> ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_GET,
>> (unsigned char *)&args, sizeof(args),
next prev parent reply other threads:[~2026-03-15 3:38 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 3:10 [PATCH v4 0/8] platform-x86: lenovo-wmi: Add fixes and enhancement Derek J. Clark
2026-03-12 3:10 ` [PATCH v4 1/8] platform-x86: lenovo-wmi-other: Move LWMI_FAN_DIV Derek J. Clark
2026-03-12 3:10 ` [PATCH v4 2/8] platform-x86: lenovo-wmi-other: Fix tunable_attr_01 struct members Derek J. Clark
2026-03-12 3:10 ` [PATCH v4 3/8] platform/x86: lenovo-wmi-other: Add lwmi_attr_id() function Derek J. Clark
2026-03-15 1:08 ` Rong Zhang
2026-03-15 3:38 ` Derek J. Clark [this message]
2026-03-15 1:32 ` Rong Zhang
2026-03-15 3:49 ` Derek J. Clark
2026-03-12 3:10 ` [PATCH v4 4/8] platform/x86: lenovo-wmi-other: Limit adding attributes to supported devices Derek J. Clark
2026-03-15 1:26 ` Rong Zhang
2026-03-15 1:39 ` Rong Zhang
2026-03-15 3:47 ` Derek J. Clark
2026-03-15 18:50 ` Rong Zhang
2026-03-12 3:10 ` [PATCH v4 5/8] platform/x86: lenovo-wmi-other: Add missing CPU tunable attributes Derek J. Clark
2026-03-12 3:10 ` [PATCH v4 6/8] platform/x86: lenovo-wmi-other: Add GPU " Derek J. Clark
2026-03-12 3:10 ` [PATCH v4 7/8] platform-x86: lenovo-wmi-other: Rename LWMI_OM_FW_ATTR_BASE_PATH Derek J. Clark
2026-03-12 3:10 ` [PATCH v4 8/8] platform/x86: lenovo-wmi-other: Add WMI battery charge limiting Derek J. Clark
2026-03-15 2:00 ` Rong Zhang
2026-03-15 3:52 ` Derek J. Clark
2026-03-15 18:59 ` Rong Zhang
2026-03-17 23:46 ` kernel test robot
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=CD767F09-E737-4F8F-9FAD-00277F030643@gmail.com \
--to=derekjohn.clark@gmail.com \
--cc=W_Armin@gmx.de \
--cc=corbet@lwn.net \
--cc=hansg@kernel.org \
--cc=i@rong.moe \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=kuurtb@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mpearson-lenovo@squebb.ca \
--cc=platform-driver-x86@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.