[RFC PATCH v2 2/2] platform/x86: huawei-wmi: expose native Turbo mode as platform_profile

From: Fuwei Xie

Date: Wed Nov 18 2026 - 16:48:29 EST


The firmware on Huawei NbF-XX and MateBook 16 CREM-WXX9 exposes GTUB/STUB
behind WMI commands 0x00000e04 and 0x00000f04. The driver does not expose
this state through platform_profile, so userspace cannot select the
native firmware profile through the standard interface.

Map Turbo off/on to balanced/performance and read back the state after
a set. CREM-WXX9 firmware can return status zero even when it refuses a
request; the resulting state must determine whether the change succeeded.

Detect support within the existing Huawei WMI method device, requiring
both ACPI methods and a successful query of a known state (0 or 1).
Do not switch modes during detection. Unsupported or malformed responses
leave profiles unavailable without disabling the driver's other features.
This replaces a model/BIOS allowlist: the same interface was reported on
both Intel NbF-XX BIOS 3.07 and AMD CREM-WXX9 BIOS 2.32.

Refresh the reported state through deferred work on WMI notifications,
power-supply changes and resume. The power-supply notifier also covers
CREM-WXX9 firmware turning Turbo off on unplug without a 0x2a0 event.
Re-query on 0x2a6, which was observed on refused requests on that model,
without assigning a universal meaning to the notification.

Leave AC and battery restrictions to the firmware. NbF-XX BIOS 3.07 checks
AC power and a minimum battery charge, whereas CREM-WXX9 BIOS 2.32 was
reported to check AC power only. Do not enforce a fixed wattage, write
power-limit registers, or override the fan policy.

Eren Ozen reported working mode readback, tuned-ppd integration, Fn+P
and AC transitions on CREM-WXX9 using v1 plus a DMI entry. Testing the
revised capability-based probe on that machine is still requested.

Signed-off-by: Fuwei Xie <12313607@xxxxxxxxxxxxxxxxxxx>
---
drivers/platform/x86/Kconfig | 1 +
drivers/platform/x86/huawei-wmi.c | 190 +++++++++++++++++++++++++++++-
2 files changed, 189 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 9ce384e04..05e65a483 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -22,6 +22,7 @@ config HUAWEI_WMI
depends on ACPI_EC
depends on ACPI_WMI
depends on INPUT
+ select ACPI_PLATFORM_PROFILE
select INPUT_SPARSEKMAP
select LEDS_CLASS
select NEW_LEDS
diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
index 9894424e7..9e79f7452 100644
--- a/drivers/platform/x86/huawei-wmi.c
+++ b/drivers/platform/x86/huawei-wmi.c
@@ -16,9 +16,11 @@
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/platform_device.h>
+#include <linux/platform_profile.h>
#include <linux/power_supply.h>
#include <linux/sysfs.h>
#include <linux/wmi.h>
+#include <linux/workqueue.h>
#include <acpi/battery.h>

/*
@@ -39,6 +41,8 @@ enum {
FN_LOCK_GET = 0x00000604, /* \GFRS */
FN_LOCK_SET = 0x00000704, /* \SFRS */
MICMUTE_LED_SET = 0x00000b04, /* \SMLS */
+ POWER_MODE_GET = 0x00000e04, /* \GTUB */
+ POWER_MODE_SET = 0x00000f04, /* \STUB */
};

union hwmi_arg {
@@ -68,6 +72,9 @@ struct huawei_wmi {
struct device *dev;

struct mutex wmi_lock;
+ struct device *profile_dev;
+ struct work_struct profile_work;
+ struct notifier_block power_notifier;
};

static struct huawei_wmi *huawei_wmi;
@@ -264,6 +271,170 @@ static int huawei_wmi_cmd(u64 arg, u8 *buf, size_t buflen)
return huawei_wmi_cmd_min(arg, buf, buflen, buflen);
}

+/* Native firmware profiles: no RAPL writes and no periodic enforcement. */
+
+static int huawei_wmi_profile_get(struct device *dev,
+ enum platform_profile_option *profile)
+{
+ u8 ret[2];
+ int err;
+
+ err = huawei_wmi_cmd(POWER_MODE_GET, ret, sizeof(ret));
+ if (err)
+ return err;
+ if (ret[1] > 1)
+ return -ENODATA;
+ *profile = ret[1] ? PLATFORM_PROFILE_PERFORMANCE : PLATFORM_PROFILE_BALANCED;
+ return 0;
+}
+
+static int huawei_wmi_profile_set(struct device *dev,
+ enum platform_profile_option profile)
+{
+ enum platform_profile_option actual;
+ union hwmi_arg arg = { .cmd = POWER_MODE_SET };
+ int err;
+
+ if (profile != PLATFORM_PROFILE_BALANCED &&
+ profile != PLATFORM_PROFILE_PERFORMANCE)
+ return -EOPNOTSUPP;
+
+ err = huawei_wmi_profile_get(dev, &actual);
+ if (err || actual == profile)
+ return err;
+
+ /* Firmware enforces model-specific AC and battery requirements. */
+ arg.args[2] = profile == PLATFORM_PROFILE_PERFORMANCE;
+ err = huawei_wmi_cmd(arg.cmd, NULL, 0);
+ if (err)
+ return err;
+ /* Some firmware returns success even when it refuses the change. */
+ err = huawei_wmi_profile_get(dev, &actual);
+ if (err)
+ return err;
+ return actual == profile ? 0 : -EAGAIN;
+}
+
+static bool huawei_wmi_has_profile_method(char *path)
+{
+ acpi_object_type type;
+ acpi_handle handle;
+
+ return ACPI_SUCCESS(acpi_get_handle(NULL, path, &handle)) &&
+ ACPI_SUCCESS(acpi_get_type(handle, &type)) &&
+ type == ACPI_TYPE_METHOD;
+}
+
+static int huawei_wmi_profile_detect(struct device *dev)
+{
+ enum platform_profile_option profile;
+
+ if (!huawei_wmi_has_profile_method("\\GTUB") ||
+ !huawei_wmi_has_profile_method("\\STUB"))
+ return -ENODEV;
+
+ /* Query a known state; never switch modes to probe firmware support. */
+ return huawei_wmi_profile_get(dev, &profile);
+}
+
+static int huawei_wmi_profile_probe(void *drvdata, unsigned long *choices)
+{
+ set_bit(PLATFORM_PROFILE_BALANCED, choices);
+ set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
+ return 0;
+}
+
+static const struct platform_profile_ops huawei_profile_ops = {
+ .probe = huawei_wmi_profile_probe,
+ .profile_get = huawei_wmi_profile_get,
+ .profile_set = huawei_wmi_profile_set,
+};
+
+static void huawei_wmi_profile_work(struct work_struct *work)
+{
+ struct huawei_wmi *huawei = container_of(work, struct huawei_wmi, profile_work);
+ /* Pairs with release publication after profile/notifier registration. */
+ struct device *dev = smp_load_acquire(&huawei->profile_dev);
+ enum platform_profile_option profile;
+ int err;
+
+ if (!dev)
+ return;
+ err = huawei_wmi_profile_get(dev, &profile);
+ if (err) {
+ dev_warn_ratelimited(huawei->dev, "Cannot refresh firmware profile: %d\n", err);
+ return;
+ }
+ /* A cached value can miss a quick userspace change followed by Fn+P. */
+ platform_profile_notify(dev);
+}
+
+static void huawei_wmi_profile_refresh(struct huawei_wmi *huawei)
+{
+ /* Pairs with release publication after profile/notifier registration. */
+ if (smp_load_acquire(&huawei->profile_dev))
+ schedule_work(&huawei->profile_work);
+}
+
+static int huawei_wmi_power_changed(struct notifier_block *nb,
+ unsigned long event, void *data)
+{
+ struct huawei_wmi *huawei = container_of(nb, struct huawei_wmi, power_notifier);
+
+ if (event == PSY_EVENT_PROP_CHANGED)
+ huawei_wmi_profile_refresh(huawei);
+ return NOTIFY_OK;
+}
+
+static void huawei_wmi_profile_setup(struct huawei_wmi *huawei)
+{
+ struct device *dev;
+ int err;
+
+ err = huawei_wmi_profile_detect(huawei->dev);
+ if (err == -ENODEV)
+ return;
+ if (err)
+ goto fail;
+ dev = platform_profile_register(huawei->dev, "huawei-wmi", huawei,
+ &huawei_profile_ops);
+ if (IS_ERR(dev)) {
+ err = PTR_ERR(dev);
+ goto fail;
+ }
+ huawei->power_notifier.notifier_call = huawei_wmi_power_changed;
+ err = power_supply_reg_notifier(&huawei->power_notifier);
+ if (err) {
+ platform_profile_remove(dev);
+ goto fail;
+ }
+ /* Publish only after both registration steps succeed. */
+ smp_store_release(&huawei->profile_dev, dev);
+ huawei_wmi_profile_refresh(huawei);
+ return;
+fail:
+ dev_warn(huawei->dev, "Native platform profiles unavailable: %d\n", err);
+}
+
+/* Call after removing the WMI event handlers. */
+static void huawei_wmi_profile_exit(struct huawei_wmi *huawei)
+{
+ if (!huawei->profile_dev)
+ return;
+ power_supply_unreg_notifier(&huawei->power_notifier);
+ cancel_work_sync(&huawei->profile_work);
+ platform_profile_remove(huawei->profile_dev);
+ huawei->profile_dev = NULL;
+}
+
+static int huawei_wmi_resume(struct device *dev)
+{
+ huawei_wmi_profile_refresh(dev_get_drvdata(dev));
+ return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(huawei_wmi_pm, NULL, huawei_wmi_resume);
+
/* LEDs */

static int huawei_wmi_micmute_led_set(struct led_classdev *led_cdev,
@@ -830,6 +1001,18 @@ static void huawei_wmi_process_key(struct input_dev *idev, int code)
kfree(response.pointer);
}

+ /*
+ * Refresh on mode events and 0x2a6, observed on refused STUB requests
+ * on CREM-WXX9. Do not infer a mode or a universal error from the event.
+ */
+ if (code == 0x2a0 || code == 0x2a1 || code == 0x2a6) {
+ /* Pairs with release publication after profile/notifier registration. */
+ if (smp_load_acquire(&huawei_wmi->profile_dev)) {
+ huawei_wmi_profile_refresh(huawei_wmi);
+ return;
+ }
+ }
+
key = sparse_keymap_entry_from_scancode(idev, code);
if (!key) {
dev_info(&idev->dev, "Unknown key pressed, code: 0x%04x\n", code);
@@ -904,6 +1087,8 @@ static int huawei_wmi_probe(struct platform_device *pdev)

platform_set_drvdata(pdev, huawei_wmi);
huawei_wmi->dev = &pdev->dev;
+ mutex_init(&huawei_wmi->wmi_lock);
+ INIT_WORK(&huawei_wmi->profile_work, huawei_wmi_profile_work);

while (*guid->guid_string) {
if (wmi_has_guid(guid->guid_string)) {
@@ -918,12 +1103,11 @@ static int huawei_wmi_probe(struct platform_device *pdev)
}

if (wmi_has_guid(HWMI_METHOD_GUID)) {
- mutex_init(&huawei_wmi->wmi_lock);
-
huawei_wmi_leds_setup(&pdev->dev);
huawei_wmi_fn_lock_setup(&pdev->dev);
huawei_wmi_battery_setup(&pdev->dev);
huawei_wmi_debugfs_setup(&pdev->dev);
+ huawei_wmi_profile_setup(huawei_wmi);
}

return 0;
@@ -940,6 +1124,7 @@ static void huawei_wmi_remove(struct platform_device *pdev)
guid++;
}

+ huawei_wmi_profile_exit(huawei_wmi);
if (wmi_has_guid(HWMI_METHOD_GUID)) {
huawei_wmi_debugfs_exit(&pdev->dev);
huawei_wmi_battery_exit(&pdev->dev);
@@ -950,6 +1135,7 @@ static void huawei_wmi_remove(struct platform_device *pdev)
static struct platform_driver huawei_wmi_driver = {
.driver = {
.name = "huawei-wmi",
+ .pm = pm_sleep_ptr(&huawei_wmi_pm),
},
.probe = huawei_wmi_probe,
.remove = huawei_wmi_remove,
--
2.55.0