mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrei Rusu de Castro <arc@empyreal.works>
To: "Corentin Chary" <corentin.chary@gmail.com>,
	"Luke D. Jones" <luke@ljones.dev>,
	"Denis Benato" <denis.benato@linux.dev>,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] platform/x86: asus-wmi: write the thermal policy only when it changes
Date: Wed, 11 Nov 2026 21:43:57 +0000	[thread overview]
Message-ID: <20261111-asus-wmi-tpolicy-5fbc4e09@empyreal.works> (raw)

On the ROG Flow Z13 (GZ302EA), writing the throttle thermal policy makes
the firmware re-apply its own package power limits for that mode, also
when the written mode is the one already set. Userspace re-asserts the
current platform profile on events such as AC plug and unplug, so power
limits tuned after a profile change are silently replaced by the
firmware's table for the unchanged mode.

Remember whether the firmware is known to be in the cached mode and skip
the WMI call in the platform_profile handler when the requested profile
matches it. A failed write clears that state, and so does restore from
hibernation, where the firmware starts afresh, so the next profile write
reaches it again. The throttle_thermal_policy attribute and the fan
curve reset still write the mode every time.

On a GZ302EA running 7.4-rc2 with this change, re-asserting the current
profile, as happens on AC unplug, leaves package power limits set from
userspace in place.

An LLM assisted with finding the cause, writing this change and its
description, and running the test above on my GZ302EA.

Signed-off-by: Andrei Rusu de Castro <arc@empyreal.works>
---
 drivers/platform/x86/asus-wmi.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index b33ebdb21..4f37a83c2 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -315,6 +315,8 @@ struct asus_wmi {
 
 	u8 throttle_thermal_policy_mode;
 	u32 throttle_thermal_policy_dev;
+	/* the firmware is known to be in throttle_thermal_policy_mode */
+	bool throttle_thermal_policy_synced;
 
 	bool cpu_fan_curve_available;
 	bool gpu_fan_curve_available;
@@ -4183,9 +4185,11 @@ static int throttle_thermal_policy_write(struct asus_wmi *asus)
 			"throttle_thermal_policy");
 
 	if (err) {
+		asus->throttle_thermal_policy_synced = false;
 		pr_warn("Failed to set throttle thermal policy: %d\n", err);
 		return err;
 	}
+	asus->throttle_thermal_policy_synced = true;
 
 	/* Must set to disabled if mode is toggled */
 	if (asus->cpu_fan_curve_available)
@@ -4302,6 +4306,16 @@ static int asus_wmi_platform_profile_set(struct device *dev,
 		return -EOPNOTSUPP;
 	}
 
+	/*
+	 * Write the mode only when it changes. The firmware applies its whole
+	 * power table for a mode each time the mode is written, replacing
+	 * package power limits tuned since then (ROG Flow Z13 GZ302EA), and
+	 * userspace re-asserts the current profile on power-supply events.
+	 */
+	if (asus->throttle_thermal_policy_synced &&
+	    asus->throttle_thermal_policy_mode == tp)
+		return 0;
+
 	asus->throttle_thermal_policy_mode = tp;
 	return throttle_thermal_policy_write(asus);
 }
@@ -5404,6 +5418,9 @@ static int asus_hotk_restore(struct device *device)
 	struct asus_wmi *asus = dev_get_drvdata(device);
 	int bl;
 
+	/* The firmware booted afresh; the next profile write must reach it. */
+	asus->throttle_thermal_policy_synced = false;
+
 	/* Refresh both wlan rfkill state and pci hotplug */
 	if (asus->wlan.rfkill)
 		asus_rfkill_hotplug(asus);
-- 
2.56.0



                 reply	other threads:[~2026-11-11 21:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261111-asus-wmi-tpolicy-5fbc4e09@empyreal.works \
    --to=arc@empyreal.works \
    --cc=corentin.chary@gmail.com \
    --cc=denis.benato@linux.dev \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luke@ljones.dev \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®