mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] platform/x86: huawei-wmi: Add keyboard backlight support
@ 2026-10-25 23:39 Cian Ruane
  2026-10-26 11:51 ` Ilpo Järvinen
  0 siblings, 1 reply; 2+ messages in thread
From: Cian Ruane @ 2026-10-25 23:39 UTC (permalink / raw)
  To: Hans de Goede, Ilpo Järvinen
  Cc: platform-driver-x86, linux-kernel, Cian Ruane

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.

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@gmail.com>
---
 drivers/platform/x86/huawei-wmi.c | 64 +++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
index 96ee9a97c..8eafda8a1 100644
--- a/drivers/platform/x86/huawei-wmi.c
+++ b/drivers/platform/x86/huawei-wmi.c
@@ -39,8 +39,14 @@ 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
+
 union hwmi_arg {
 	u64 cmd;
 	u8 args[8];
@@ -50,6 +56,7 @@ struct quirk_entry {
 	bool battery_reset;
 	bool ec_micmute;
 	bool report_brightness;
+	bool kbd_backlight;
 };
 
 static struct quirk_entry *quirks;
@@ -65,6 +72,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 +134,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 +157,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,6 +343,48 @@ 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[0x100];
+
+	if (huawei_wmi_cmd(KBD_BACKLIGHT_GET, ret, sizeof(ret)))
+		return 0;
+
+	/* byte[0] = STAT, byte[2] = level as stored by the EC */
+	return ret[2] / 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[2] = 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)
@@ -915,6 +978,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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] platform/x86: huawei-wmi: Add keyboard backlight support
  2026-10-25 23:39 [PATCH] platform/x86: huawei-wmi: Add keyboard backlight support Cian Ruane
@ 2026-10-26 11:51 ` Ilpo Järvinen
  0 siblings, 0 replies; 2+ messages in thread
From: Ilpo Järvinen @ 2026-10-26 11:51 UTC (permalink / raw)
  To: Cian Ruane; +Cc: Hans de Goede, platform-driver-x86, LKML

On Mon, 26 Oct 2026, Cian Ruane wrote:

> 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.
> 
> 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@gmail.com>
> ---
>  drivers/platform/x86/huawei-wmi.c | 64 +++++++++++++++++++++++++++++++
>  1 file changed, 64 insertions(+)
> 
> diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
> index 96ee9a97c..8eafda8a1 100644
> --- a/drivers/platform/x86/huawei-wmi.c
> +++ b/drivers/platform/x86/huawei-wmi.c
> @@ -39,8 +39,14 @@ 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
> +
>  union hwmi_arg {
>  	u64 cmd;
>  	u8 args[8];
> @@ -50,6 +56,7 @@ struct quirk_entry {
>  	bool battery_reset;
>  	bool ec_micmute;
>  	bool report_brightness;
> +	bool kbd_backlight;
>  };
>  
>  static struct quirk_entry *quirks;
> @@ -65,6 +72,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 +134,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 +157,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,6 +343,48 @@ 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[0x100];

Generally, avoid using literals and use named defines for sizes, offsets, 
and values (and BIT()/GENMASK() for bitfields).

> +	if (huawei_wmi_cmd(KBD_BACKLIGHT_GET, ret, sizeof(ret)))
> +		return 0;
> +
> +	/* byte[0] = STAT, byte[2] = level as stored by the EC */
> +	return ret[2] / 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[2] = 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)
> @@ -915,6 +978,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
> 

-- 
 i.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-26 11:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-25 23:39 [PATCH] platform/x86: huawei-wmi: Add keyboard backlight support Cian Ruane
2026-10-26 11:51 ` Ilpo Järvinen

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®