[PATCH v2] platform/x86: huawei-wmi: Add keyboard backlight support
From: Cian Ruane
Date: Mon Oct 26 2026 - 09:19:44 EST
The HWMI interface of the HUAWEI MateBook X Pro 2020 (MACHC-WAX9)
exposes the keyboard backlight through the \GLIV and \SLIV methods of
the WMAA dispatcher (MFID 2, SFID 6/7), with the level in byte 2 of the
buffer. The EC stores the level doubled, so the three levels off/low/
high are represented as 0, 2 and 4.
Register a "platform::kbd_backlight" LED class device with a maximum
brightness of 2 so that userspace, e.g. UPower, can control it.
Changes made with the Fn+F3 hotkey are handled by the EC itself and
are not reported to the OS on this model: no EC query or WMI event is
generated. LED_BRIGHT_HW_CHANGED is therefore not set.
The level encoding has only been verified on this model, so enable the
feature through a DMI quirk.
Add a HWMI_BUF_SIZE define for the size of the HWMI result buffer and
use it for the existing battery threshold and Fn-lock buffers as well.
Tested on: HUAWEI MACHC-WAX9 (MateBook X Pro 2020), BIOS 1.05 and 1.26,
Ubuntu 24.04 (kernel 6.8.0-147-generic, with this patch backported).
Signed-off-by: Cian Ruane <cian.ruane1@xxxxxxxxx>
---
Changes in v2:
- Use named defines for the HWMI buffer size and the level byte offsets
instead of literals, and use HWMI_BUF_SIZE for the existing battery
and Fn-lock buffers too (Ilpo)
v1: https://lore.kernel.org/r/20261025233910.9907-1-cian.ruane1@xxxxxxxxx
drivers/platform/x86/huawei-wmi.c | 75 +++++++++++++++++++++++++++++--
1 file changed, 72 insertions(+), 3 deletions(-)
diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
index 96ee9a97c..59b3f7d9d 100644
--- a/drivers/platform/x86/huawei-wmi.c
+++ b/drivers/platform/x86/huawei-wmi.c
@@ -31,6 +31,9 @@
#define WMI0_EXPENSIVE_GUID "39142400-C6A3-40fa-BADB-8A2652834100"
#define WMI0_EVENT_GUID "59142400-C6A3-40fa-BADB-8A2652834100"
+/* Size of the buffer returned by HWMI, byte 0 is the return status */
+#define HWMI_BUF_SIZE 0x100
+
/* HWMI commands */
enum {
@@ -39,8 +42,17 @@ enum {
FN_LOCK_GET = 0x00000604, /* \GFRS */
FN_LOCK_SET = 0x00000704, /* \SFRS */
MICMUTE_LED_SET = 0x00000b04, /* \SMLS */
+ KBD_BACKLIGHT_GET = 0x00000602, /* \GLIV */
+ KBD_BACKLIGHT_SET = 0x00000702, /* \SLIV */
};
+/* The EC stores the keyboard backlight level doubled: off/low/high = 0/2/4. */
+#define KBD_BACKLIGHT_MAX 2
+#define KBD_BACKLIGHT_STEP 2
+/* Level byte in the \GLIV result (KBLL) and in the \SLIV argument (SOCP) */
+#define KBD_BACKLIGHT_GET_LEVEL_OFFSET 2
+#define KBD_BACKLIGHT_SET_LEVEL_OFFSET 2
+
union hwmi_arg {
u64 cmd;
u8 args[8];
@@ -50,6 +62,7 @@ struct quirk_entry {
bool battery_reset;
bool ec_micmute;
bool report_brightness;
+ bool kbd_backlight;
};
static struct quirk_entry *quirks;
@@ -65,6 +78,7 @@ struct huawei_wmi {
struct huawei_wmi_debug debug;
struct led_classdev cdev;
+ struct led_classdev kbd_cdev;
struct device *dev;
struct mutex wmi_lock;
@@ -126,6 +140,10 @@ static struct quirk_entry quirk_matebook_x = {
.report_brightness = true,
};
+static struct quirk_entry quirk_kbd_backlight = {
+ .kbd_backlight = true,
+};
+
static const struct dmi_system_id huawei_quirks[] = {
{
.callback = dmi_matched,
@@ -145,6 +163,15 @@ static const struct dmi_system_id huawei_quirks[] = {
},
.driver_data = &quirk_matebook_x
},
+ {
+ .callback = dmi_matched,
+ .ident = "Huawei MACHC-WAX9",
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "HUAWEI"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "MACHC-WAX9"),
+ },
+ .driver_data = &quirk_kbd_backlight
+ },
{ }
};
@@ -322,11 +349,52 @@ static void huawei_wmi_leds_setup(struct device *dev)
devm_led_classdev_register(dev, &huawei->cdev);
}
+/* Keyboard backlight */
+
+static enum led_brightness huawei_wmi_kbd_backlight_get(struct led_classdev *led_cdev)
+{
+ u8 ret[HWMI_BUF_SIZE];
+
+ if (huawei_wmi_cmd(KBD_BACKLIGHT_GET, ret, sizeof(ret)))
+ return 0;
+
+ return ret[KBD_BACKLIGHT_GET_LEVEL_OFFSET] / KBD_BACKLIGHT_STEP;
+}
+
+static int huawei_wmi_kbd_backlight_set(struct led_classdev *led_cdev,
+ enum led_brightness brightness)
+{
+ union hwmi_arg arg;
+
+ arg.cmd = KBD_BACKLIGHT_SET;
+ arg.args[KBD_BACKLIGHT_SET_LEVEL_OFFSET] = brightness * KBD_BACKLIGHT_STEP;
+
+ return huawei_wmi_cmd(arg.cmd, NULL, 0);
+}
+
+static void huawei_wmi_kbd_backlight_setup(struct device *dev)
+{
+ struct huawei_wmi *huawei = dev_get_drvdata(dev);
+
+ if (!quirks || !quirks->kbd_backlight)
+ return;
+
+ if (huawei_wmi_cmd(KBD_BACKLIGHT_GET, NULL, 0))
+ return;
+
+ huawei->kbd_cdev.name = "platform::kbd_backlight";
+ huawei->kbd_cdev.max_brightness = KBD_BACKLIGHT_MAX;
+ huawei->kbd_cdev.brightness_get = &huawei_wmi_kbd_backlight_get;
+ huawei->kbd_cdev.brightness_set_blocking = &huawei_wmi_kbd_backlight_set;
+
+ devm_led_classdev_register(dev, &huawei->kbd_cdev);
+}
+
/* Battery protection */
static int huawei_wmi_battery_get(int *start, int *end)
{
- u8 ret[0x100];
+ u8 ret[HWMI_BUF_SIZE];
int err, i;
err = huawei_wmi_cmd(BATTERY_THRESH_GET, ret, sizeof(ret));
@@ -619,7 +687,7 @@ static int huawei_acpi_fn_lock_set(int on)
static int huawei_wmi_fn_lock_get(int *on)
{
- u8 ret[0x100] = { 0 };
+ u8 ret[HWMI_BUF_SIZE] = { 0 };
int err, i;
/* Newer models: use direct ACPI \GFRS method */
@@ -627,7 +695,7 @@ static int huawei_wmi_fn_lock_get(int *on)
return huawei_acpi_fn_lock_get(on);
/* WMI fallback */
- err = huawei_wmi_cmd(FN_LOCK_GET, ret, 0x100);
+ err = huawei_wmi_cmd(FN_LOCK_GET, ret, sizeof(ret));
if (err)
return err;
@@ -915,6 +983,7 @@ static int huawei_wmi_probe(struct platform_device *pdev)
mutex_init(&huawei_wmi->wmi_lock);
huawei_wmi_leds_setup(&pdev->dev);
+ huawei_wmi_kbd_backlight_setup(&pdev->dev);
huawei_wmi_fn_lock_setup(&pdev->dev);
huawei_wmi_battery_setup(&pdev->dev);
huawei_wmi_debugfs_setup(&pdev->dev);
base-commit: 9d3475065167197742b0882aff21cf8e78393277
--
2.43.0