Re: [PATCH v3] HID: asus: support the Zenbook A14 (UX3407RA) keyboard backlight

From: Dr. David Alan Gilbert

Date: Fri Dec 04 2026 - 21:12:46 EST


* Jesper B. Christensen (jaytersen@xxxxxxxxx) wrote:
> The ASUS Zenbook A14 (UX3407RA), a Qualcomm Snapdragon X2 Elite
> (Hamoa)-based laptop, carries its main keyboard on an I2C-HID device
> with the ID 0B05:0220. Its Fn/media hotkeys are emitted as vendor-page
> (HID_UP_ASUSVENDOR) usages on report 0x5A.
>
> In addition to the the standard I2C keyboard quirks and the keyboard
> backlight quirk, a few new have been added:
>
> QUIRK_KBD_REPORT_SIZE: The UX3407RA seems to only accept 64 byte
> reports
> QUIRK_KBD_OOBE: Refactor existing Out-Of-Box mitigation into a
> quirk.
>
> The keyboard backlight is software controlled. Since WMI is not
> available on Snapdragon based platforms this change registers a
> separate led device that sends hid reports to the Embedded Controller
> (EC).
>
> Signed-off-by: Jesper B. Christensen <jaytersen@xxxxxxxxx>

Tested-by: Dr. David Alan Gilbert <dave@xxxxxxxxxxx>
on my UX3407QA on 7.4.0-rc5 (and some local other hacks)

> ---
> drivers/hid/hid-asus.c | 74 ++++++++++++++++++++++++++++++++++++++----
> drivers/hid/hid-ids.h | 1 +
> 2 files changed, 69 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c
> index f8339740b9ba..93d90ac5655e 100644
> --- a/drivers/hid/hid-asus.c
> +++ b/drivers/hid/hid-asus.c
> @@ -68,6 +68,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
> #define ASUS_FAN_CTRL_KEY_CODE 0xae
>
> #define SUPPORT_KBD_BACKLIGHT BIT(0)
> +#define EC_KBD_MAX_BACKLIGHT 3
>
> #define MAX_TOUCH_MAJOR 8
> #define MAX_PRESSURE 128
> @@ -102,6 +103,8 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
> #define QUIRK_ROG_ALLY_XPAD BIT(13)
> #define QUIRK_HID_FN_LOCK BIT(14)
> #define QUIRK_FILTER_CAMERA_COMPANION BIT(15)
> +#define QUIRK_KBD_REPORT_SIZE BIT(16)
> +#define QUIRK_KBD_OOBE BIT(17)
>
> #define I2C_KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \
> QUIRK_NO_INIT_REPORTS | \
> @@ -176,6 +179,7 @@ struct asus_drvdata {
> bool battery_in_query;
> unsigned long battery_next_query;
> struct asus_hid_listener listener;
> + struct led_classdev kbd_led_cdev;
> bool fn_lock;
> struct asus_xgm_led *xgm_led;
> };
> @@ -585,10 +589,19 @@ static int asus_raw_event(struct hid_device *hdev,
> static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t buf_size)
> {
> int ret;
> - u8 *dmabuf __free(kfree) = kmemdup(buf, buf_size, GFP_KERNEL);
> + size_t alloc_size = buf_size;
> + struct asus_drvdata *drvdata = hid_get_drvdata(hdev);
> +
> + if (drvdata->quirks & QUIRK_KBD_REPORT_SIZE)
> + alloc_size = (buf_size > FEATURE_KBD_REPORT_SIZE) ?
> + buf_size : FEATURE_KBD_REPORT_SIZE;
> +
> + u8 *dmabuf __free(kfree) = kzalloc(alloc_size, GFP_KERNEL);
> if (!dmabuf)
> return -ENOMEM;
>
> + memcpy(dmabuf, buf, buf_size);
> +
> /* The device may be runtime suspended, e.g. for a deferred backlight change */
> ret = hid_hw_power(hdev, PM_HINT_FULLON);
> if (ret < 0)
> @@ -598,8 +611,8 @@ static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t bu
> * The report ID should be set from the incoming buffer due to LED and key
> * interfaces having different pages
> */
> - ret = hid_hw_raw_request(hdev, buf[0], dmabuf, buf_size, HID_FEATURE_REPORT,
> - HID_REQ_SET_REPORT);
> + ret = hid_hw_raw_request(hdev, buf[0], dmabuf, alloc_size, HID_FEATURE_REPORT,
> + HID_REQ_SET_REPORT);
> hid_hw_power(hdev, PM_HINT_NORMAL);
> return ret;
> }
> @@ -706,7 +719,7 @@ static void asus_kbd_set_fn_lock(struct hid_device *hdev, bool enabled)
> hid_err(hdev, "Asus failed to set fn lock: %d\n", ret);
> }
>
> -static void asus_kbd_set_brightness(struct hid_device *hdev, u8 brightness)
> +static int asus_kbd_set_brightness(struct hid_device *hdev, u8 brightness)
> {
> const u8 buf[FEATURE_KBD_REPORT_SIZE] = {
> FEATURE_KBD_REPORT_ID, 0xba, 0xc5, 0xc4, brightness
> @@ -716,6 +729,20 @@ static void asus_kbd_set_brightness(struct hid_device *hdev, u8 brightness)
> ret = asus_kbd_set_report(hdev, buf, sizeof(buf));
> if (ret < 0)
> hid_err(hdev, "Asus failed to set keyboard backlight: %d\n", ret);
> +
> + return ret;
> +}
> +
> +static int asus_kbd_set_brightness_cdev(struct led_classdev *led_cdev,
> + enum led_brightness brightness)
> +{
> + struct asus_drvdata *drvdata = container_of(led_cdev, struct asus_drvdata, kbd_led_cdev);
> + u8 level = (u8)brightness;
> +
> + if (level > EC_KBD_MAX_BACKLIGHT)
> + level = EC_KBD_MAX_BACKLIGHT;
> +
> + return asus_kbd_set_brightness(drvdata->hdev, level);
> }
>
> static void asus_kbd_wmi_fan(struct hid_device *hdev, struct hid_raw_event_data *data)
> @@ -996,7 +1023,7 @@ static int asus_kbd_register_leds(struct hid_device *hdev)
> if (!(kbd_func & SUPPORT_KBD_BACKLIGHT))
> return -ENODEV;
>
> - if (dmi_match(DMI_PRODUCT_FAMILY, "ProArt P16")) {
> + if (drvdata->quirks & QUIRK_KBD_OOBE) {
> ret = asus_kbd_disable_oobe(hdev);
> if (ret < 0)
> return ret;
> @@ -1012,10 +1039,29 @@ static int asus_kbd_register_leds(struct hid_device *hdev)
> drvdata->listener.brightness_set = asus_kbd_backlight_set;
> ret = asus_hid_register_listener(&drvdata->listener);
> if (ret < 0) {
> - hid_err(hdev, "Unable to register kbd brightness listener: %d\n", ret);
> + if (ret != -ENODEV) {
> + hid_err(hdev, "Unable to register kbd brightness listener: %d\n", ret);
> + }
> drvdata->listener.brightness_set = NULL;
> }
>
> + // Non-x86 architectures do not have WMI, just register a led
> + // device directly
> + if (ret == -ENODEV) {
> + drvdata->kbd_led_cdev.name = "asus::kbd_backlight";
> + drvdata->kbd_led_cdev.brightness = 1;
> + drvdata->kbd_led_cdev.brightness_set_blocking = asus_kbd_set_brightness_cdev;
> + drvdata->kbd_led_cdev.max_brightness = EC_KBD_MAX_BACKLIGHT;
> + ret = led_classdev_register(&hdev->dev, &drvdata->kbd_led_cdev);
> + if (ret < 0) {
> + hid_err(hdev, "Unable to register kbd brightness led: %d\n", ret);
> + drvdata->kbd_led_cdev.brightness_set_blocking = NULL;
> + } else {
> + asus_kbd_set_brightness_cdev(&drvdata->kbd_led_cdev,
> + drvdata->kbd_led_cdev.brightness);
> + }
> + }
> +
> return ret;
> }
>
> @@ -1499,6 +1545,9 @@ static int __maybe_unused asus_resume(struct hid_device *hdev)
> if (drvdata->listener.brightness_set)
> asus_kbd_backlight_set(&drvdata->listener, drvdata->kbd_backlight_brightness);
>
> + if (drvdata->kbd_led_cdev.brightness_set_blocking)
> + asus_kbd_set_brightness_cdev(&drvdata->kbd_led_cdev, drvdata->kbd_led_cdev.brightness);
> +
> return 0;
> }
>
> @@ -1636,6 +1685,9 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)
> }
> }
>
> + if (dmi_match(DMI_PRODUCT_FAMILY, "ProArt P16"))
> + drvdata->quirks |= QUIRK_KBD_OOBE;
> +
> /* Laptops keyboard backlight is always at 0x5a */
> if (is_vendor && (drvdata->quirks & QUIRK_USE_KBD_BACKLIGHT) &&
> (asus_has_report_id(hdev, FEATURE_KBD_REPORT_ID)) &&
> @@ -1676,6 +1728,9 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)
> if (drvdata->xgm_led)
> devm_led_classdev_unregister(&hdev->dev, &drvdata->xgm_led->cdev);
>
> + if (drvdata->kbd_led_cdev.brightness_set_blocking)
> + led_classdev_unregister(&drvdata->kbd_led_cdev);
> +
> asus_worker_stop(drvdata->worker);
> hid_hw_stop(hdev);
> return ret;
> @@ -1691,6 +1746,9 @@ static void asus_remove(struct hid_device *hdev)
> if (drvdata->xgm_led)
> devm_led_classdev_unregister(&hdev->dev, &drvdata->xgm_led->cdev);
>
> + if (drvdata->kbd_led_cdev.brightness_set_blocking)
> + led_classdev_unregister(&drvdata->kbd_led_cdev);
> +
> asus_worker_stop(drvdata->worker);
> hid_hw_stop(hdev);
> }
> @@ -1813,6 +1871,10 @@ static const struct hid_device_id asus_devices[] = {
> { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK,
> USB_DEVICE_ID_ASUSTEK_I2C_ZENBOOK_KEYBOARD),
> I2C_KEYBOARD_QUIRKS | QUIRK_FILTER_CAMERA_COMPANION },
> + { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK,
> + USB_DEVICE_ID_ASUSTEK_I2C_ZENBOOK_A14_KEYBOARD),
> + I2C_KEYBOARD_QUIRKS | QUIRK_USE_KBD_BACKLIGHT | QUIRK_KBD_REPORT_SIZE |
> + QUIRK_KBD_OOBE},
> { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK,
> USB_DEVICE_ID_ASUSTEK_I2C_TOUCHPAD), I2C_TOUCHPAD_QUIRKS },
> { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,
> diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
> index 61c1c6673de1..fc6d93338fec 100644
> --- a/drivers/hid/hid-ids.h
> +++ b/drivers/hid/hid-ids.h
> @@ -222,6 +222,7 @@
> #define USB_DEVICE_ID_ASUSTEK_T304_KEYBOARD 0x184a
> #define USB_DEVICE_ID_ASUSTEK_I2C_KEYBOARD 0x8585
> #define USB_DEVICE_ID_ASUSTEK_I2C_ZENBOOK_KEYBOARD 0x4b42
> +#define USB_DEVICE_ID_ASUSTEK_I2C_ZENBOOK_A14_KEYBOARD 0x0220
> #define USB_DEVICE_ID_ASUSTEK_I2C_TOUCHPAD 0x0101
> #define USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD1 0x1854
> #define USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD2 0x1837
> --
> 2.53.0
>
>
--
-----Open up your eyes, open up your mind, open up your code -------
/ Dr. David Alan Gilbert | Running GNU/Linux | Happy \
\ dave @ treblig.org | | In Hex /
\ _________________________|_____ http://www.treblig.org |_______/