HID: asus: ASUS Zenbook Duo keyboard support
v4 cover HID: asus: ASUS Zenbook Duo keyboard support
Add support for the detachable USB/Bluetooth keyboard of the ASUS Zenbook Duo line (UX8406MA, UX8406CA, UX8407AA): hotkeys, keyboard backlight and the platform profile key, over both transports.
This patchset is a collective effort, gathered here:
https://github.com/NeroReflex/asusctl/issues/25
Tested on a UX8407AA against 7.3, docked and over Bluetooth: hotkeys, keyboard backlight, Fn+F profile cycling, and the touchpad staying with hid-multitouch.
Since v1 the series has been reworked with the help of an LLM coding assistant. It was used to analyse the review comments and the code they point at, to draft the changes and commit messages that address them. I reviewed every change and tested each version on my UX8407AA, docked and over Bluetooth.
Changes in v4:
- Rebase onto hid.git#for-7.4/asus, now with Denis's "improve the driver support for laptops" series.
- Drop the delayed handshake re-send: Rebecca measured that the keyboard stays in hotkey mode without it.
- 1/7: check one quirk per branch and the transport in a nested if, initializing rsize_orig and offs so that clang still sees them set; use u16 and declare new_rsize at the top of the block (Denis).
- 2/7: shorten the comment and put it next to the mapping (Denis).
- 3/7: shorten the comment (Denis).
- 4/7: only handle usage 0x9d on Zenbook Duo keyboards, and take the worker lock with guard() instead of a goto and a label (Denis). The IS_REACHABLE() checks stay in C conditionals rather than #if, as coding-style.rst asks, so both branches keep being compile-checked.
- 5/7: list the report sizes of other devices in the comment (Denis).
- 6/7: move the entries above the existing HID_GROUP_GENERIC ones, so that they do not conflict with the T302CHI dock entry in for-next.
- New 7/7: keep the input device names the keyboard reports instead of renaming them to "Asus Keyboard" (Denis).
- Add Denis's Reviewed-by to 3/7, 5/7 and 6/7.
- Drop the Assisted-by tags, following "docs: remove Assisted-by references" in linux-next.
Changes in v3 and v2: see the v3 cover letter.
v3: https://lore.kernel.org/r/[email protected]
v2: https://lore.kernel.org/r/[email protected]
v1: https://lore.kernel.org/r/[email protected]
Joshua Leivenzon (4):
HID: asus: Fix up Zenbook Duo report descriptors
HID: asus: Add missing Zenbook Duo hotkeys
HID: asus: Force hid-input to bind to the Zenbook Duo hotkey interface
HID: asus: Cycle the platform profile from the Zenbook Duo profile key
Luke Jones (1):
HID: asus: add prod-id, quirk for Zenbook Duo keyboard
Paolo Pisati (2):
HID: asus: Do not send feature reports larger than declared
HID: asus: Keep the Zenbook Duo input device names
drivers/hid/hid-asus.c | 154 ++++++++++++++++++++++++++++++++++++----- drivers/hid/hid-ids.h | 6 ++ 2 files changed, 142 insertions(+), 18 deletions(-)
base-commit: e16927855d822a163099ffb2d6a449913fe9487d
Signature · 1 line
2.43.0
PATCH v4 1/7 HID: asus: Fix up Zenbook Duo report descriptors
From: Joshua Leivenzon <[email protected]>
The Zenbook Duo keyboards (UX8406MA, UX8406CA, UX8407AA) ship the same broken vendor hotkey collection as the T100CHI/T90CHI keyboard docks:
the Input item of report 0x5a is preceded by a single Usage (76h) instead of a Usage Minimum/Maximum range, so none of the hotkey codes get mapped and every key press logs
Unmapped Asus vendor usagepage code 0x76
Extend the T100CHI/T90CHI fixup to the Zenbook Duo: the descriptor is 90 bytes long with the bogus usage at offset 66 on the USB hotkey interface, and 257 bytes long with the usage at offset 176 over Bluetooth.
The dock fixup only moves the 12 bytes between the usage and the End Collection item, as nothing but a bogus trailing 0 byte follows them. That is not true of the Zenbook Duo: the collection goes on with a 15 byte feature report (also ID 0x5a) after the Input item, and over Bluetooth a further collection follows it, which a 12 byte move corrupts, leaving stray 0 bytes at the end. Move everything after the usage instead, after dropping any trailing 0 bytes, and allocate the two bytes the usage range adds. The result for the T100CHI/T90CHI is unchanged.
[pisati: fold the USB offsets and the padding removal into this patch,
bound the padding removal, move the whole tail of the descriptor, and initialize rsize_orig and offs so clang does not warn that they may be used uninitialized]
--- drivers/hid/hid-asus.c | 44 ++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-)
drivers/hid/hid-asus.c +30 -14
@@ -102,6 +102,7 @@ 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_ZENBOOK_DUO_KEYBOARD BIT(16)#define I2C_KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \ QUIRK_NO_INIT_REPORTS | \
@@ -1707,43 +1708,58 @@ static const __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc,hid_info (hdev,"Fixing up Asus T100 keyb report descriptor\n" ); rdesc[74 ] &= ~HID_MAIN_ITEM_CONSTANT ; } -/* For the T100CHI/T90CHI keyboard dock */ -if (drvdata->quirks & (QUIRK_T100CHI |QUIRK_T90CHI )) { -int rsize_orig; -int offs; +/* For the T100CHI/T90CHI keyboard dock and Zenbook Duo keyboards */ +if (drvdata->quirks & (QUIRK_T100CHI |QUIRK_T90CHI |QUIRK_ZENBOOK_DUO_KEYBOARD )) { +u16 rsize_orig =0 , offs =0 ; +u16 new_rsize;if (drvdata->quirks &QUIRK_T100CHI ) { rsize_orig =403 ; offs =388 ; - }else { + }else if (drvdata->quirks &QUIRK_T90CHI ) { rsize_orig =306 ; offs =291 ; + }else if (drvdata->quirks &QUIRK_ZENBOOK_DUO_KEYBOARD ) { +if (hid_is_usb (hdev)) { + rsize_orig =90 ; + offs =66 ; + }else {/* Bluetooth */ + rsize_orig =257 ; + offs =176 ; + } }/* * Change Usage (76h) to Usage Minimum (00h), Usage Maximum -* (FFh) and clear the flags in the Input() byte. -* Note the descriptor has a bogus 0 byte at the end so we -* only need 1 extra byte. +* (FFh) and clear the flags in the Input() byte, shifting +* the rest of the descriptor by the 2 bytes that adds. Drop +* the bogus 0 bytes some descriptors end with first, but +* never the Input() item that follows the usage. */ if (*rsize == rsize_orig && rdesc[offs] ==0x09 && rdesc[offs +1 ] ==0x76 ) {__u8 *new_rdesc; - new_rdesc =devm_kzalloc (&hdev->dev, rsize_orig +1 , + new_rsize = rsize_orig; +while (new_rsize > offs +14 && rdesc[new_rsize -1 ] ==0 ) + --new_rsize; + + new_rdesc =devm_kzalloc (&hdev->dev, new_rsize +2 ,GFP_KERNEL );if (!new_rdesc)return rdesc;hid_info (hdev,"Fixing up %s keyb report descriptor\n" , - drvdata->quirks &QUIRK_T100CHI ? -"T100CHI" :"T90CHI" ); + drvdata->quirks &QUIRK_T100CHI ?"T100CHI" : + drvdata->quirks &QUIRK_T90CHI ?"T90CHI" : +"Zenbook Duo" ); -memcpy (new_rdesc, rdesc, rsize_orig); - *rsize = rsize_orig +1 ; +memcpy (new_rdesc, rdesc, new_rsize); + *rsize = new_rsize +2 ; rdesc = new_rdesc; -memmove (rdesc + offs +4 , rdesc + offs +2 ,12 ); +memmove (rdesc + offs +4 , rdesc + offs +2 , + new_rsize - (offs +2 )); rdesc[offs] =0x19 ; rdesc[offs +1 ] =0x00 ; rdesc[offs +2 ] =0x29 ;
Signature · 1 line
2.43.0
Re: [PATCH v4 1/7] HID: asus: Fix up Zenbook Duo report descriptors
Quoted 15 lines · Paolo Pisati
From: Joshua Leivenzon <[email protected]>
The Zenbook Duo keyboards (UX8406MA, UX8406CA, UX8407AA) ship the same broken vendor hotkey collection as the T100CHI/T90CHI keyboard docks:
the Input item of report0x5ais preceded by a single Usage (76h) instead of a Usage Minimum/Maximum range, so none of the hotkey codes get mapped and every key press logsUnmapped Asus vendor usagepage code
0x76Extend the T100CHI/T90CHI fixup to the Zenbook Duo: the descriptor is 90 bytes long with the bogus usage at offset 66 on the USB hotkey interface, and 257 bytes long with the usage at offset 176 over Bluetooth.
Quoted 9 lines
The dock fixup only moves the 12 bytes between the usage and the End Collection item, as nothing but a bogus trailing 0 byte follows them. That is not true of the Zenbook Duo: the collection goes on with a 15 byte feature report (also ID
0x5a) after the Input item, and over Bluetooth a further collection follows it, which a 12 byte move corrupts, leaving stray 0 bytes at the end. Move everything after the usage instead, after dropping any trailing 0 bytes, and allocate the two bytes the usage range adds. The result for the T100CHI/T90CHI is unchanged.
Quoted 95 lines
Signed-off-by Joshua Leivenzon <[email protected]>[pisati: fold the USB offsets and the padding removal into this patch,
bound the padding removal, move the whole tail of the descriptor, and initializersize_origand offs so clang does not warn that they may be used uninitialized]Signed-off-by Paolo Pisati <[email protected]>--- drivers/hid/hid-asus.c | 44 ++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-)drivers/hid/hid-asus.c +30
-14@@ -102,6 +102,7 @@ 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_ZENBOOK_DUO_KEYBOARD BIT(16)#define I2C_KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \ QUIRK_NO_INIT_REPORTS | \@@ -1707,43 +1708,58 @@ static const __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc,hid_info (hdev,"Fixing up Asus T100 keyb report descriptor\n" ); rdesc[74 ] &= ~HID_MAIN_ITEM_CONSTANT ; } -/* For the T100CHI/T90CHI keyboard dock */ -if (drvdata->quirks & (QUIRK_T100CHI |QUIRK_T90CHI )) { -int rsize_orig; -int offs; +/* For the T100CHI/T90CHI keyboard dock and Zenbook Duo keyboards */ +if (drvdata->quirks & (QUIRK_T100CHI |QUIRK_T90CHI |QUIRK_ZENBOOK_DUO_KEYBOARD )) { +u16 rsize_orig =0 , offs =0 ; +u16 new_rsize;if (drvdata->quirks &QUIRK_T100CHI ) { rsize_orig =403 ; offs =388 ; - }else { + }else if (drvdata->quirks &QUIRK_T90CHI ) { rsize_orig =306 ; offs =291 ; + }else if (drvdata->quirks &QUIRK_ZENBOOK_DUO_KEYBOARD ) { +if (hid_is_usb (hdev)) { + rsize_orig =90 ; + offs =66 ; + }else {/* Bluetooth */ + rsize_orig =257 ; + offs =176 ; + } }/* * Change Usage (76h) to Usage Minimum (00h), Usage Maximum -* (FFh) and clear the flags in the Input() byte. -* Note the descriptor has a bogus 0 byte at the end so we -* only need 1 extra byte. +* (FFh) and clear the flags in the Input() byte, shifting +* the rest of the descriptor by the 2 bytes that adds. Drop +* the bogus 0 bytes some descriptors end with first, but +* never the Input() item that follows the usage. */ if (*rsize == rsize_orig && rdesc[offs] ==0x09 && rdesc[offs +1 ] ==0x76 ) {__u8 *new_rdesc; - new_rdesc =devm_kzalloc (&hdev->dev, rsize_orig +1 , + new_rsize = rsize_orig; +while (new_rsize > offs +14 && rdesc[new_rsize -1 ] ==0 ) + --new_rsize; + + new_rdesc =devm_kzalloc (&hdev->dev, new_rsize +2 ,GFP_KERNEL );if (!new_rdesc)return rdesc;hid_info (hdev,"Fixing up %s keyb report descriptor\n" , - drvdata->quirks &QUIRK_T100CHI ? -"T100CHI" :"T90CHI" ); + drvdata->quirks &QUIRK_T100CHI ?"T100CHI" : + drvdata->quirks &QUIRK_T90CHI ?"T90CHI" : +"Zenbook Duo" ); -memcpy (new_rdesc, rdesc, rsize_orig); - *rsize = rsize_orig +1 ; +memcpy (new_rdesc, rdesc, new_rsize); + *rsize = new_rsize +2 ; rdesc = new_rdesc; -memmove (rdesc + offs +4 , rdesc + offs +2 ,12 ); +memmove (rdesc + offs +4 , rdesc + offs +2 , + new_rsize - (offs +2 )); rdesc[offs] =0x19 ; rdesc[offs +1 ] =0x00 ; rdesc[offs +2 ] =0x29 ;
PATCH v4 2/7 HID: asus: Add missing Zenbook Duo hotkeys
In reply to Paolo PisatiFrom: Joshua Leivenzon <[email protected]>
Map the Zenbook Duo "screen swap" hotkey (vendor usage 0x9c) to KEY_F19, like the other ASUS vendor keys that have no dedicated keycode, so that userspace can bind it.
Unlike the keys of devices with built-in keyboards, which can share keycodes freely, this one has to stay unique: the Zenbook Duo keyboard is a standard USB/Bluetooth device and can be connected to another ASUS machine handled by this driver. Say so next to the mapping.
[pisati: drop the MyASUS key (0x86) mapping, 2061075360182 ("HID:
asus: support the Zenbook A16 (UX3607OA) keyboard") maps it to KEY_PROG1 like asus-nb-wmi does, and shorten the comment]
--- drivers/hid/hid-asus.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/hid/hid-asus.c +2 -0
@@ -1316,6 +1316,8 @@ static int asus_input_mapping(struct hid_device *hdev,case 0xb3 :asus_map_key_clear (KEY_PROG3 );break ;/* Fn+Left next aura */ case 0x6a :asus_map_key_clear (KEY_F13 );break ;/* Screenpad toggle */ case 0x4b :asus_map_key_clear (KEY_F14 );break ;/* Arrows/Pg-Up/Dn toggle */ +/* Keep unique: the Zenbook Duo keyboard also pairs with other laptops */ +case 0x9c :asus_map_key_clear (KEY_F19 );break ;/* Screen swap */ case 0xa5 :asus_map_key_clear (KEY_F15 );break ;/* ROG Ally left back */ case 0xa6 :asus_map_key_clear (KEY_F16 );break ;/* ROG Ally QAM button */ case 0xa7 :asus_map_key_clear (KEY_F17 );break ;/* ROG Ally ROG long-press */
Signature · 1 line
2.43.0
PATCH v4 3/7 HID: asus: Force hid-input to bind to the Zenbook Duo hotkey interface
In reply to Paolo PisatiFrom: Joshua Leivenzon <[email protected]>
The Zenbook Duo USB keyboard reports its hotkeys on a dedicated interface, separate from the keyboard and consumer control ones, that only contains ASUS vendor usage collections. hid-input does not consider those an input application and never binds to the interface, so the hotkeys are never mapped.
Pass HID_CONNECT_HIDINPUT_FORCE for the interface of Zenbook Duo keyboards that carries the ASUS vendor collection, which skips that check, so the vendor usages go through asus_input_mapping() like on any other ASUS keyboard. The other interfaces either have a proper input application or nothing worth an input device.
[pisati: use HID_CONNECT_HIDINPUT_FORCE on the vendor interface instead
of injecting a fake keyboard collection into its report descriptor]
--- drivers/hid/hid-asus.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/hid/hid-asus.c +10 -1
@@ -1514,6 +1514,7 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)struct asus_drvdata *drvdata;struct hid_report *rep;bool is_vendor = false; +unsigned int connect_mask;int ret; drvdata =devm_kzalloc (&hdev->dev,sizeof (*drvdata),GFP_KERNEL );
@@ -1609,7 +1610,15 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)return ret; } - ret =hid_hw_start (hdev,HID_CONNECT_DEFAULT ); +/* +* The Zenbook Duo hotkey interface only has vendor collections, which +* hid-input does not bind to on its own. +*/ + connect_mask =HID_CONNECT_DEFAULT ; +if ((drvdata->quirks &QUIRK_ZENBOOK_DUO_KEYBOARD ) && is_vendor) + connect_mask |=HID_CONNECT_HIDINPUT_FORCE ; + + ret =hid_hw_start (hdev, connect_mask);if (ret) {asus_worker_stop (drvdata->worker);hid_err (hdev,"Asus hw start failed: %d\n" , ret);
Signature · 1 line
2.43.0
Re: [PATCH v4 3/7] HID: asus: Force hid-input to bind to the Zenbook Duo hotkey interface
Quoted 8 lines · Paolo Pisati
From: Joshua Leivenzon <[email protected]>
The Zenbook Duo USB keyboard reports its hotkeys on a dedicated interface, separate from the keyboard and consumer control ones, that only contains ASUS vendor usage collections. hid-input does not consider those an input application and never binds to the interface, so the hotkeys are never mapped.
Quoted 5 lines
Pass
HID_CONNECT_HIDINPUT_FORCEfor the interface of Zenbook Duo keyboards that carries the ASUS vendor collection, which skips that check, so the vendor usages go throughasus_input_mapping()like on any other ASUS keyboard. The other interfaces either have a proper input application or nothing worth an input device.
Quoted 39 lines
Signed-off-by Joshua Leivenzon <[email protected]>[pisati: use
HID_CONNECT_HIDINPUT_FORCEon the vendor interface instead
of injecting a fake keyboard collection into its report descriptor]Signed-off-by Paolo Pisati <[email protected]>Reviewed-by Denis Benato <[email protected]>--- drivers/hid/hid-asus.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/hid/hid-asus.c +10
-1@@ -1514,6 +1514,7 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)struct asus_drvdata *drvdata;struct hid_report *rep;bool is_vendor = false; +unsigned int connect_mask;int ret; drvdata =devm_kzalloc (&hdev->dev,sizeof (*drvdata),GFP_KERNEL );@@ -1609,7 +1610,15 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)return ret; } - ret =hid_hw_start (hdev,HID_CONNECT_DEFAULT ); +/* +* The Zenbook Duo hotkey interface only has vendor collections, which +* hid-input does not bind to on its own. +*/ + connect_mask =HID_CONNECT_DEFAULT ; +if ((drvdata->quirks &QUIRK_ZENBOOK_DUO_KEYBOARD ) && is_vendor) + connect_mask |=HID_CONNECT_HIDINPUT_FORCE ; + + ret =hid_hw_start (hdev, connect_mask);if (ret) {asus_worker_stop (drvdata->worker);hid_err (hdev,"Asus hw start failed: %d\n" , ret);
PATCH v4 4/7 HID: asus: Cycle the platform profile from the Zenbook Duo profile key
In reply to Paolo PisatiFrom: Joshua Leivenzon <[email protected]>
The Zenbook Duo keyboard reports Fn+F, the performance mode key, as vendor usage 0x9d. On the built-in keyboards of other ASUS laptops the same key arrives through asus-wmi, which cycles the platform profile in response. Do the same here so the key works on the detachable keyboard too. Other ASUS devices may use the same usage for something else, so only handle it on the Zenbook Duo keyboards.
asus_event() runs from the HID input path, which for USB is the URB completion handler, while platform_profile_cycle() takes a mutex, so run it from the driver's worker like the Fn-lock toggle, and consume the event. Queue at most one cycle at a time, so that a device repeating the key cannot grow the worker's list. Only call it when the platform profile class is reachable: it is not built on architectures without ACPI, where HID_ASUS still is, and it may be a module while HID_ASUS is built in.
[pisati: defer platform_profile_cycle() to the worker and queue at
most one cycle, only handle the usage on Zenbook Duo keyboards, return 1 from asus_event() instead of propagating its return value, and guard the call with IS_REACHABLE(CONFIG_ACPI_PLATFORM_PROFILE)]
--- drivers/hid/hid-asus.c | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
drivers/hid/hid-asus.c +54 -0
@@ -29,6 +29,7 @@#include <linux/input/mt.h> #include <linux/usb.h> /* For to_usb_interface for T100 touchpad intf check */ #include <linux/power_supply.h> +#include <linux/platform_profile.h> #include <linux/leds.h> #include "hid-ids.h"
@@ -117,6 +118,7 @@ enum asus_work_action_type {FN_LOCK_SYNC ,BRIGHTNESS_SET ,WMI_FAN , + PLATFORM_PROFILE_CYCLE, }; struct hid_raw_event_data {
@@ -431,6 +433,36 @@ static int asus_kbd_fn_lock_set(struct asus_drvdata *drvdata, bool enabled)return 0 ; } +static int asus_platform_profile_cycle (struct asus_drvdata *drvdata) +{ +struct asus_worker *worker = drvdata->worker; +struct asus_work_action *action, *pending; + +if (!IS_REACHABLE (CONFIG_ACPI_PLATFORM_PROFILE )) +return 0 ; + +guard (spinlock_irqsave)(&worker->lock); + +/* +* One pending cycle is enough: a key press cannot outrun the +* worker, and a device repeating the key must not grow the list. +*/ +list_for_each_entry (pending, &worker->actions, node) { +if (pending->type ==PLATFORM_PROFILE_CYCLE ) +return 0 ; + } + + action = kzalloc_obj(struct asus_work_action, GFP_ATOMIC); +if (!action) +return -ENOMEM ; + + action->type =PLATFORM_PROFILE_CYCLE ; +INIT_LIST_HEAD (&action->node); +asus_worker_schedule (worker, action); + +return 0 ; +} +static int asus_kbd_wmi_fan_send (struct asus_drvdata *drvdata,u8 *report_data,size_t report_size) {
@@ -467,6 +499,20 @@ static int asus_event(struct hid_device *hdev, struct hid_field *field,if ((usage->hid &HID_USAGE_PAGE ) ==HID_UP_ASUSVENDOR && (usage->hid &HID_USAGE ) !=0x00 && (usage->hid &HID_USAGE ) !=0xff && !usage->type) { +/* Zenbook Duo Fn+F: cycle the platform profile */ +if ((drvdata->quirks &QUIRK_ZENBOOK_DUO_KEYBOARD ) && + (usage->hid &HID_USAGE ) ==0x9d ) { +if (value) { + ret =asus_platform_profile_cycle (drvdata); +if (ret) { +hid_err (hdev,"Failed to cycle the platform profile: %d\n" , + ret); +return ret; + } + } +return 1 ; + } +hid_warn (hdev,"Unmapped Asus vendor usagepage code 0x%02x\n" , usage->hid &HID_USAGE ); }
@@ -773,6 +819,7 @@ static void asus_work(struct work_struct *work) struct asus_worker *worker = container_of(work, struct asus_worker, work);struct asus_work_action *action =NULL ;unsigned long flags; +int ret;/* * Dequeue the next action, if any. Once teardown has begun .removed
@@ -801,6 +848,13 @@ static void asus_work(struct work_struct *work)case WMI_FAN :asus_kbd_wmi_fan (worker->hdev, &action->data.fan_hid_data);break ; +case PLATFORM_PROFILE_CYCLE : +if (!IS_REACHABLE (CONFIG_ACPI_PLATFORM_PROFILE )) +break ; + ret =platform_profile_cycle (); +if (ret) +hid_dbg (worker->hdev,"Failed to cycle the platform profile: %d\n" , ret); +break ;default :hid_err (worker->hdev,"Invalid action type: %d\n" , action->type);break ;
Signature · 1 line
2.43.0
Re: [PATCH v4 4/7] HID: asus: Cycle the platform profile from the Zenbook Duo profile key
Quoted 9 lines · Paolo Pisati
From: Joshua Leivenzon <[email protected]>
The Zenbook Duo keyboard reports Fn+F, the performance mode key, as vendor usage
0x9d. On the built-in keyboards of other ASUS laptops the same key arrives through asus-wmi, which cycles the platform profile in response. Do the same here so the key works on the detachable keyboard too. Other ASUS devices may use the same usage for something else, so only handle it on the Zenbook Duo keyboards.
Quoted 8 lines
asus_event()runs from the HID input path, which for USB is the URB completion handler, whileplatform_profile_cycle()takes a mutex, so run it from the driver's worker like the Fn-lock toggle, and consume the event. Queue at most one cycle at a time, so that a device repeating the key cannot grow the worker's list. Only call it when the platform profile class is reachable: it is not built on architectures without ACPI, whereHID_ASUSstill is, and it may be a module whileHID_ASUSis built in.
Quoted 110 lines
Signed-off-by Joshua Leivenzon <[email protected]>[pisati: defer
platform_profile_cycle()to the worker and queue at
most one cycle, only handle the usage on Zenbook Duo keyboards, return 1 fromasus_event()instead of propagating its return value, and guard the call withIS_REACHABLE(CONFIG_ACPI_PLATFORM_PROFILE)]Signed-off-by Paolo Pisati <[email protected]>--- drivers/hid/hid-asus.c | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)drivers/hid/hid-asus.c +54
-0@@ -29,6 +29,7 @@#include <linux/input/mt.h> #include <linux/usb.h> /* For to_usb_interface for T100 touchpad intf check */ #include <linux/power_supply.h> +#include <linux/platform_profile.h> #include <linux/leds.h> #include "hid-ids.h" @@ -117,6 +118,7 @@ enum asus_work_action_type {FN_LOCK_SYNC ,BRIGHTNESS_SET ,WMI_FAN , + PLATFORM_PROFILE_CYCLE, }; struct hid_raw_event_data {@@ -431,6 +433,36 @@ static int asus_kbd_fn_lock_set(struct asus_drvdata *drvdata, bool enabled)return 0 ; } +static int asus_platform_profile_cycle (struct asus_drvdata *drvdata) +{ +struct asus_worker *worker = drvdata->worker; +struct asus_work_action *action, *pending; + +if (!IS_REACHABLE (CONFIG_ACPI_PLATFORM_PROFILE )) +return 0 ; + +guard (spinlock_irqsave)(&worker->lock); + +/* +* One pending cycle is enough: a key press cannot outrun the +* worker, and a device repeating the key must not grow the list. +*/ +list_for_each_entry (pending, &worker->actions, node) { +if (pending->type ==PLATFORM_PROFILE_CYCLE ) +return 0 ; + } + + action = kzalloc_obj(struct asus_work_action, GFP_ATOMIC); +if (!action) +return -ENOMEM ; + + action->type =PLATFORM_PROFILE_CYCLE ; +INIT_LIST_HEAD (&action->node); +asus_worker_schedule (worker, action); + +return 0 ; +} +static int asus_kbd_wmi_fan_send (struct asus_drvdata *drvdata,u8 *report_data,size_t report_size) {@@ -467,6 +499,20 @@ static int asus_event(struct hid_device *hdev, struct hid_field *field,if ((usage->hid &HID_USAGE_PAGE ) ==HID_UP_ASUSVENDOR && (usage->hid &HID_USAGE ) !=0x00 && (usage->hid &HID_USAGE ) !=0xff && !usage->type) { +/* Zenbook Duo Fn+F: cycle the platform profile */ +if ((drvdata->quirks &QUIRK_ZENBOOK_DUO_KEYBOARD ) && + (usage->hid &HID_USAGE ) ==0x9d ) { +if (value) { + ret =asus_platform_profile_cycle (drvdata); +if (ret) { +hid_err (hdev,"Failed to cycle the platform profile: %d\n" , + ret); +return ret; + } + } +return 1 ; + } +hid_warn (hdev,"Unmapped Asus vendor usagepage code 0x%02x\n" , usage->hid &HID_USAGE ); }@@ -773,6 +819,7 @@ static void asus_work(struct work_struct *work) struct asus_worker *worker = container_of(work, struct asus_worker, work);struct asus_work_action *action =NULL ;unsigned long flags; +int ret;/* * Dequeue the next action, if any. Once teardown has begun .removed @@ -801,6 +848,13 @@ static void asus_work(struct work_struct *work)case WMI_FAN :asus_kbd_wmi_fan (worker->hdev, &action->data.fan_hid_data);break ; +case PLATFORM_PROFILE_CYCLE : +if (!IS_REACHABLE (CONFIG_ACPI_PLATFORM_PROFILE )) +break ; + ret =platform_profile_cycle (); +if (ret) +hid_dbg (worker->hdev,"Failed to cycle the platform profile: %d\n" , ret); +break ;default :hid_err (worker->hdev,"Invalid action type: %d\n" , action->type);break ;
PATCH v4 5/7 HID: asus: Do not send feature reports larger than declared
In reply to Paolo PisatiThe keyboard backlight and Fn-lock commands are sent as 64 byte feature reports, the size of report 0x5a on the ROG keyboards. The Zenbook Duo keyboards declare feature report 0x5a with 15 data bytes, 16 with the report ID, and do not answer writes larger than that: the control transfer times out over USB and fails with -EIO over Bluetooth, so the backlight cannot be set, while the 16 byte handshake goes through.
Cap feature report writes at the length the device declares for the report, when it declares it. hid_report_len() counts the report ID, so the handshake and the other commands up to that size are sent as they are.
--- drivers/hid/hid-asus.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/hid/hid-asus.c +13 -0
@@ -631,6 +631,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) { +struct hid_report *report; + +/* +* Do not send more than the declared size of the report, report ID +* included. Sizes differ between devices: most ROG keyboards declare +* 64 bytes and the XG Mobile 300, while the Zenbook Duo keyboards, like +* the touchpads, declare 16 for report 0x5a, the size of the handshake, +* and do not answer the 64 byte writes sized for the ROG keyboards. +*/ + report = hdev->report_enum[HID_FEATURE_REPORT ].report_id_hash[buf[0 ]]; +if (report) + buf_size =min_t (size_t, buf_size,hid_report_len (report)); + u8 *dmabuf __free(kfree) = kmemdup(buf, buf_size, GFP_KERNEL);if (!dmabuf)return -ENOMEM ;
Signature · 1 line
2.43.0
PATCH v4 6/7 HID: asus: add prod-id, quirk for Zenbook Duo keyboard
In reply to Paolo PisatiFrom: Luke Jones <[email protected]>
The 2024/2025/2026 ASUS Zenbook Duo has a similar keyboard setup as many of the ROG range of laptops, with the same init sequence and control for backlight. Enable the keyboard control and backlight by:
- adding the product ID for 2024/2025/2026 Zenbook Duo keyboard MCU
- adding the Bluetooth Zenbook Duo keyboard IDs
Intended for the UX8406-style product line with the fully removable keyboard.
The keyboard also exposes its touchpad as a separate HID device with the same IDs, an interface of the USB device and a second device over Bluetooth, so bind the IDs to the HID_GROUP_GENERIC group only, like the ROG Z13 Folio, and leave the touchpad to hid-multitouch.
Fn-lock is left out for now: with QUIRK_HID_FN_LOCK the Fn-lock report is sent to every interface of the device, before the handshake, and on the UX8407AA that stalled the hotkey interface for good. It can be added back once the driver only sends it where and when it belongs.
[pisati: bind the IDs to HID_GROUP_GENERIC only, drop
QUIRK_HID_FN_LOCK]
--- drivers/hid/hid-asus.c | 24 ++++++++++++++++++++++++ drivers/hid/hid-ids.h | 6 ++++++ 2 files changed, 30 insertions(+)
drivers/hid/hid-asus.c +24 -0
@@ -1948,6 +1948,30 @@ static const struct hid_device_id asus_devices[] = { USB_DEVICE_ID_ASUSTEK_T100CHI_KEYBOARD), QUIRK_T100CHI }, { HID_USB_DEVICE(USB_VENDOR_ID_ITE, USB_DEVICE_ID_ITE_MEDION_E1239T), QUIRK_MEDION_E1239T }, +/* +* Zenbook Duo detachable keyboards. The touchpad shows up as a +* separate HID device with the same IDs, over USB and Bluetooth: +* bind to the HID_GROUP_GENERIC group only, like the ROG Z13 Folio +* below, so that hid-multitouch keeps handling it. +*/ + { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, USB_VENDOR_ID_ASUSTEK, +USB_DEVICE_ID_ASUSTEK_ZENBOOK_DUO_UX8406MA_KEYBOARD ), + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ZENBOOK_DUO_KEYBOARD }, + { HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_GENERIC, USB_VENDOR_ID_ASUSTEK, +BT_DEVICE_ID_ASUSTEK_ZENBOOK_DUO_UX8406MA_KEYBOARD ), + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ZENBOOK_DUO_KEYBOARD }, + { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, USB_VENDOR_ID_ASUSTEK, +USB_DEVICE_ID_ASUSTEK_ZENBOOK_DUO_UX8406CA_KEYBOARD ), + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ZENBOOK_DUO_KEYBOARD }, + { HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_GENERIC, USB_VENDOR_ID_ASUSTEK, +BT_DEVICE_ID_ASUSTEK_ZENBOOK_DUO_UX8406CA_KEYBOARD ), + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ZENBOOK_DUO_KEYBOARD }, + { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, USB_VENDOR_ID_ASUSTEK, +USB_DEVICE_ID_ASUSTEK_ZENBOOK_DUO_UX8407AA_KEYBOARD ), + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ZENBOOK_DUO_KEYBOARD }, + { HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_GENERIC, USB_VENDOR_ID_ASUSTEK, +BT_DEVICE_ID_ASUSTEK_ZENBOOK_DUO_UX8407AA_KEYBOARD ), + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ZENBOOK_DUO_KEYBOARD },/* * Note bind to the HID_GROUP_GENERIC group, so that we only bind to the keyboard * part, while letting hid-multitouch.c handle the touchpad.
drivers/hid/hid-ids.h +6 -0
@@ -228,6 +228,12 @@#define USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD 0x1866#define USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD2 0x19b6#define USB_DEVICE_ID_ASUSTEK_ROG_Z13_FOLIO 0x1a30 +#define USB_DEVICE_ID_ASUSTEK_ZENBOOK_DUO_UX8406MA_KEYBOARD 0x1b2c +#define BT_DEVICE_ID_ASUSTEK_ZENBOOK_DUO_UX8406MA_KEYBOARD 0x1b2d +#define USB_DEVICE_ID_ASUSTEK_ZENBOOK_DUO_UX8406CA_KEYBOARD 0x1bf2 +#define BT_DEVICE_ID_ASUSTEK_ZENBOOK_DUO_UX8406CA_KEYBOARD 0x1bf3 +#define USB_DEVICE_ID_ASUSTEK_ZENBOOK_DUO_UX8407AA_KEYBOARD 0x1cd7 +#define BT_DEVICE_ID_ASUSTEK_ZENBOOK_DUO_UX8407AA_KEYBOARD 0x1cd8#define USB_DEVICE_ID_ASUSTEK_ROG_Z13_LIGHTBAR 0x18c6#define USB_DEVICE_ID_ASUSTEK_ROG_NKEY_ALLY 0x1abe#define USB_DEVICE_ID_ASUSTEK_ROG_NKEY_ALLY_X 0x1b4c
Signature · 1 line
2.43.0
PATCH v4 7/7 HID: asus: Keep the Zenbook Duo input device names
In reply to Paolo Pisatihid-asus renames the input devices of the keyboards it handles to "Asus Keyboard", except for the ROG N-Key ones, which keep the names the devices report. New devices are not renamed any more, so skip the rename for the Zenbook Duo keyboards too: their input devices keep the "ASUS Zenbook Duo Keyboard" names they get without this driver.
--- drivers/hid/hid-asus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/hid/hid-asus.c +3 -3
@@ -1712,10 +1712,10 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)hid_warn (hdev,"Failed to initialize backlight.\n" );/* -* For ROG keyboards, skip rename for consistency and ->input check as -* some devices do not have inputs. +* For ROG and Zenbook Duo keyboards, skip rename for consistency and +* ->input check as some devices do not have inputs. */ -if (drvdata->quirks &QUIRK_ROG_NKEY_KEYBOARD ) +if (drvdata->quirks & (QUIRK_ROG_NKEY_KEYBOARD |QUIRK_ZENBOOK_DUO_KEYBOARD ))return 0 ;/*
Signature · 1 line
2.43.0
Re: [PATCH v4 7/7] HID: asus: Keep the Zenbook Duo input device names
Quoted 5 lines · Paolo Pisati
hid-asus renames the input devices of the keyboards it handles to "Asus Keyboard", except for the ROG N-Key ones, which keep the names the devices report. New devices are not renamed any more, so skip the rename for the Zenbook Duo keyboards too: their input devices keep the "ASUS Zenbook Duo Keyboard" names they get without this driver.
Quoted 24 lines
Suggested-by Denis Benato <[email protected]>Signed-off-by Paolo Pisati <[email protected]>--- drivers/hid/hid-asus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/hid/hid-asus.c +3
-3@@ -1712,10 +1712,10 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)hid_warn (hdev,"Failed to initialize backlight.\n" );/* -* For ROG keyboards, skip rename for consistency and ->input check as -* some devices do not have inputs. +* For ROG and Zenbook Duo keyboards, skip rename for consistency and +* ->input check as some devices do not have inputs. */ -if (drvdata->quirks &QUIRK_ROG_NKEY_KEYBOARD ) +if (drvdata->quirks & (QUIRK_ROG_NKEY_KEYBOARD |QUIRK_ZENBOOK_DUO_KEYBOARD ))return 0 ;/*
Quoted 2 lines · Paolo Pisati
- Drop the delayed handshake re-send: Rebecca measured that the keyboard stays in hotkey mode without it.
Thank you for carrying this, and for the credit.
I tested v4 on the UX8407AA the same way as v3: applied on top of e16927855d82 (hid.git for-7.4/asus), the resulting hid-asus.c matches the index line of 7/7, built unmodified as an out-of-tree module against a 7.0.11-based distribution kernel, with my userspace workaround stopped.
- Docked (USB, 0b05:1cd7), with the module loaded and then three dock
cycles: the five keyboard interfaces bind to hid-asus and the touchpad stays with hid-multitouch. The descriptor fixup is applied to the hotkey interface. The keyboard backlight key and Fn+F (balanced <-> performance) work. An evdev reader sees KEY_BRIGHTNESSDOWN/UP, KEY_VOLUMEDOWN/UP, KEY_MUTE and KEY_MICMUTE.
- Bluetooth (0b05:1cd8): the keyboard binds to hid-asus and the touchpad to hid-multitouch; backlight and Fn+F work. When the keyboard switches between USB and Bluetooth, the backlight goes off for about a second and comes back at the same level.
- 7/7: the input devices keep their names, "Primax Electronics Ltd. ASUS Zenbook Duo Keyboard" over USB and "ASUS Zenbook Duo Keyboard" over Bluetooth, the same as with hid-generic.
For the whole series:
Thanks,
Rebecca
Hi Jiri, Benjamin,
Gentle ping on this series: all 7 patches have a Tested-by, and all but 2/7 a Reviewed-by.
Could it go in for 7.5?
Thanks,
Paolo
Jiri Kosina
maintainerQuoted 40 lines · Paolo Pisati
Add support for the detachable USB/Bluetooth keyboard of the ASUS Zenbook Duo line (UX8406MA, UX8406CA, UX8407AA): hotkeys, keyboard backlight and the platform profile key, over both transports.
This patchset is a collective effort, gathered here:
https://github.com/NeroReflex/asusctl/issues/25
Tested on a UX8407AA against 7.3, docked and over Bluetooth: hotkeys, keyboard backlight, Fn+F profile cycling, and the touchpad staying with hid-multitouch.
Since v1 the series has been reworked with the help of an LLM coding assistant. It was used to analyse the review comments and the code they point at, to draft the changes and commit messages that address them. I reviewed every change and tested each version on my UX8407AA, docked and over Bluetooth.
Changes in v4:
- Rebase onto hid.git#for-7.4/asus, now with Denis's "improve the driver support for laptops" series.
- Drop the delayed handshake re-send: Rebecca measured that the keyboard stays in hotkey mode without it.
- 1/7: check one quirk per branch and the transport in a nested if, initializingrsize_origand offs so that clang still sees them set; use u16 and declarenew_rsizeat the top of the block (Denis).
- 2/7: shorten the comment and put it next to the mapping (Denis).
- 3/7: shorten the comment (Denis).
- 4/7: only handle usage0x9don Zenbook Duo keyboards, and take the worker lock withguard()instead of a goto and a label (Denis). TheIS_REACHABLE()checks stay in C conditionals rather than #if, ascoding-style.rstasks, so both branches keep being compile-checked.
- 5/7: list the report sizes of other devices in the comment (Denis).
- 6/7: move the entries above the existingHID_GROUP_GENERICones, so that they do not conflict with the T302CHI dock entry in for-next.
- New 7/7: keep the input device names the keyboard reports instead of renaming them to "Asus Keyboard" (Denis).
- Add Denis's Reviewed-by to 3/7, 5/7 and 6/7.
- Drop the Assisted-by tags, following "docs: remove Assisted-by references" in linux-next.
Quoted 5 lines
Changes in v3 and v2: see the v3 cover letter.
v3: https://lore.kernel.org/r/[email protected]
v2: https://lore.kernel.org/r/[email protected]
v1: https://lore.kernel.org/r/[email protected]
Now in hid.git#for-7.5/asus, thanks.
Signature · 2 lines
Jiri Kosina SUSE Labs
19 nov 2026 22:31:57 Jiri Kosina <[email protected]>:
Quoted 42 lines · Paolo Pisati
Quoted 41 lines
Add support for the detachable USB/Bluetooth keyboard of the ASUS Zenbook Duo line (UX8406MA, UX8406CA, UX8407AA): hotkeys, keyboard backlight and the platform profile key, over both transports.
This patchset is a collective effort, gathered here:
https://github.com/NeroReflex/asusctl/issues/25
Tested on a UX8407AA against 7.3, docked and over Bluetooth: hotkeys, keyboard backlight, Fn+F profile cycling, and the touchpad staying with hid-multitouch.
Since v1 the series has been reworked with the help of an LLM coding assistant. It was used to analyse the review comments and the code they point at, to draft the changes and commit messages that address them. I reviewed every change and tested each version on my UX8407AA, docked and over Bluetooth.
Changes in v4:
- Rebase onto hid.git#for-7.4/asus, now with Denis's "improve the driver support for laptops" series.
- Drop the delayed handshake re-send: Rebecca measured that the keyboard stays in hotkey mode without it.
- 1/7: check one quirk per branch and the transport in a nested if, initializingrsize_origand offs so that clang still sees them set; use u16 and declarenew_rsizeat the top of the block (Denis).
- 2/7: shorten the comment and put it next to the mapping (Denis).
- 3/7: shorten the comment (Denis).
- 4/7: only handle usage0x9don Zenbook Duo keyboards, and take the worker lock withguard()instead of a goto and a label (Denis). TheIS_REACHABLE()checks stay in C conditionals rather than #if, ascoding-style.rstasks, so both branches keep being compile-checked.
- 5/7: list the report sizes of other devices in the comment (Denis).
- 6/7: move the entries above the existingHID_GROUP_GENERICones, so that they do not conflict with the T302CHI dock entry in for-next.
- New 7/7: keep the input device names the keyboard reports instead of renaming them to "Asus Keyboard" (Denis).
- Add Denis's Reviewed-by to 3/7, 5/7 and 6/7.
- Drop the Assisted-by tags, following "docs: remove Assisted-by references" in linux-next.
Quoted 8 lines
Quoted 5 lines
Changes in v3 and v2: see the v3 cover letter.
v3: https://lore.kernel.org/r/[email protected]
v2: https://lore.kernel.org/r/[email protected]
v1: https://lore.kernel.org/r/[email protected]Now in hid.git#for-7.5/asus, thanks.
Hi Jiri,
Thank you! Tomorrow I will rebase the ROG ally one to sit on top.
Best regards,
Denis
Quoted 3 lines
--
Jiri Kosina
SUSE Labs