HID: asus: Add RGB Support to Asus Z13, Ally, unify backlight asus-wmi, and Z13 QOL
v4 cover HID: asus: Add RGB Support to Asus Z13, Ally, unify backlight asus-wmi, and Z13 QOL
This is a three part series which does the following:
- Clean init sequence, fix the keyboard of the Z13 (touchpad,fan button)
- Unifies backlight handling to happen under asus-wmi so that all Aura devices have synced brightness controls and the backlight button works properly when it is on a USB laptop keyboard instead of one w/ WMI.
- Adds RGB support to hid-asus, solid colors only, and for the ROG Ally units and the Asus Z13 2025 first.
For more context, see cover letter of V1.
---
V3: https://lore.kernel.org/lkml/[email protected]/
V2: https://lore.kernel.org/all/[email protected]/
V1: https://lore.kernel.org/all/[email protected]/
Changes since V3:
- Add initializer for 0x5d for old NKEY keyboards until it is verified that it is not needed for their media keys to function.
- Cover init in asus-wmi with spinlock as per Hans
- If asus-wmi registers WMI handler with brightness, init the brightness in USB Asus keyboards, per Hans.
- Change hid handler name to asus-UNIQ:rgb:peripheral to match led class
- Fix oops when unregistering asus-wmi by moving unregister outside of the spin lock (but after the asus reference is set to null)
Changes since V2:
- Check lazy init succeds in asus-wmi before setting register variable
- make explicit check in asus_hid_register_listener for listener existing to avoid re-init
- rename asus_brt to asus_hid in most places and harmonize everything
- switch to a spinlock instead of a mutex to avoid kernel ooops
- fixup hid device quirks to avoid multiple RGB devices while still exposing all input vendor devices. This includes moving rgb init to probe instead of the input_configured callbacks.
- Remove fan key (during retest it appears to be 0xae that is already supported by hid-asus)
- Never unregister asus::kbd_backlight while asus-wmi is active, as that
- removes fds from userspace and breaks backlight functionality. All
- current mainline drivers do not support backlight hotplugging, so most userspace software (e.g., KDE, UPower) is built with that assumption. For the Ally, since it disconnects its controller during sleep, this caused the backlight slider to not work in KDE.
Changes since V1:
- Add basic RGB support on hid-asus, (Z13/Ally) tested in KDE/Z13
- Fix ifdef else having an invalid signature (reported by kernel robot)
- Restore input arguments to init and keyboard function so they can be re-used for RGB controls.
- Remove Z13 delay (it did not work to fix the touchpad) and replace it with a HID_GROUP_GENERIC quirk to allow hid-multitouch to load. Squash keyboard rename into it.
- Unregister brightness listener before removing work queue to avoid a race condition causing corruption
- Remove spurious mutex unlock in asus_brt_event
- Place mutex lock in kbd_led_set after LED_UNREGISTERING check to avoid relocking the mutex and causing a deadlock when unregistering leds
- Add extra check during unregistering to avoid calling unregister when no led device is registered.
- Temporarily HID_QUIRK_INPUT_PER_APP from the ROG endpoint as it causes the driver to create 4 RGB handlers per device. I also suspect some extra events sneak through (KDE had the @@@@@@).
Antheas Kapenekakis (11):
HID: asus: refactor init sequence per spec
HID: asus: prevent binding to all HID devices on ROG
HID: Asus: add Z13 folio to generic group for multitouch to work platform/x86: asus-wmi: Add support for multiple kbd RGB handlers
HID: asus: listen to the asus-wmi brightness device instead of
creating one
platform/x86: asus-wmi: remove unused keyboard backlight quirk platform/x86: asus-wmi: add keyboard brightness event handler
HID: asus: add support for the asus-wmi brightness handler
HID: asus: add basic RGB support
HID: asus: add RGB support to the ROG Ally units
HID: asus: initialize LED endpoint early for old NKEY keyboards
drivers/hid/hid-asus.c | 361 +++++++++++++++------ drivers/hid/hid-ids.h | 2 +- drivers/platform/x86/asus-wmi.c | 157 ++++++++- include/linux/platform_data/x86/asus-wmi.h | 67 ++-- 4 files changed, 437 insertions(+), 150 deletions(-)
base-commit: 38fec10eb60d687e30c8c6b5420d86e8149f7557
Signature · 1 line
2.49.0
PATCH v4 1/11 HID: asus: refactor init sequence per spec
Currently, asus_kbd_init() uses a reverse engineered init sequence from Windows, which contains the handshakes from multiple programs. Keep the main one, which is 0x5a (meant for brightness drivers).
In addition, perform a get_response and check if the response is the same. To avoid regressions, print an error if the response does not match instead of rejecting device.
Then, refactor asus_kbd_get_functions() to use the same ID it is called with, instead of hardcoding it to 0x5a so that it may be used for 0x0d in the future.
--- drivers/hid/hid-asus.c | 82 +++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 36 deletions(-)
drivers/hid/hid-asus.c +46 -36
@@ -48,7 +48,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");#define FEATURE_REPORT_ID 0x0d#define INPUT_REPORT_ID 0x5d#define FEATURE_KBD_REPORT_ID 0x5a -#define FEATURE_KBD_REPORT_SIZE 16 +#define FEATURE_KBD_REPORT_SIZE 64#define FEATURE_KBD_LED_REPORT_ID1 0x5d#define FEATURE_KBD_LED_REPORT_ID2 0x5e
@@ -388,14 +388,41 @@ static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t bustatic int asus_kbd_init (struct hid_device *hdev,u8 report_id) { -const u8 buf[] = { report_id,0x41 ,0x53 ,0x55 ,0x53 ,0x20 ,0x54 , -0x65 ,0x63 ,0x68 ,0x2e ,0x49 ,0x6e ,0x63 ,0x2e ,0x00 }; +/* +* Asus handshake identifying us as a driver (0x5A) +* 0x5A then ASCII for "ASUS Tech.Inc." +* 0x5D is for userspace Windows applications. +* +* The handshake is first sent as a set_report, then retrieved +* from a get_report to verify the response. +*/ +const u8 buf[] = { report_id,0x41 ,0x53 ,0x55 ,0x53 ,0x20 , +0x54 ,0x65 ,0x63 ,0x68 ,0x2e ,0x49 ,0x6e ,0x63 ,0x2e ,0x00 }; +u8 *readbuf;int ret; ret =asus_kbd_set_report (hdev, buf,sizeof (buf)); -if (ret <0 ) -hid_err (hdev,"Asus failed to send init command: %d\n" , ret); +if (ret <0 ) { +hid_err (hdev,"Asus failed to send handshake: %d\n" , ret); +return ret; + } + readbuf =kzalloc (FEATURE_KBD_REPORT_SIZE ,GFP_KERNEL ); +if (!readbuf) +return -ENOMEM ; + + ret =hid_hw_raw_request (hdev, report_id, readbuf, +FEATURE_KBD_REPORT_SIZE ,HID_FEATURE_REPORT , +HID_REQ_GET_REPORT ); +if (ret <0 ) { +hid_err (hdev,"Asus failed to receive handshake ack: %d\n" , ret); + }else if (memcmp (readbuf, buf,sizeof (buf)) !=0 ) { +hid_err (hdev,"Asus handshake returned invalid response: %*ph\n" , +FEATURE_KBD_REPORT_SIZE , readbuf); +// Do not return error if handshake is wrong to avoid regressions + } + +kfree (readbuf);return ret; }
@@ -417,7 +444,7 @@ static int asus_kbd_get_functions(struct hid_device *hdev,if (!readbuf)return -ENOMEM ; - ret =hid_hw_raw_request (hdev,FEATURE_KBD_REPORT_ID , readbuf, + ret =hid_hw_raw_request (hdev, report_id, readbuf,FEATURE_KBD_REPORT_SIZE ,HID_FEATURE_REPORT ,HID_REQ_GET_REPORT );if (ret <0 ) {
@@ -540,42 +567,25 @@ static int asus_kbd_register_leds(struct hid_device *hdev)unsigned char kbd_func;int ret; -if (drvdata->quirks &QUIRK_ROG_NKEY_KEYBOARD ) { -/* Initialize keyboard */ - ret =asus_kbd_init (hdev,FEATURE_KBD_REPORT_ID ); -if (ret <0 ) -return ret; - -/* The LED endpoint is initialised in two HID */ - ret =asus_kbd_init (hdev,FEATURE_KBD_LED_REPORT_ID1 ); -if (ret <0 ) -return ret; - - ret =asus_kbd_init (hdev,FEATURE_KBD_LED_REPORT_ID2 ); -if (ret <0 ) -return ret; + ret =asus_kbd_init (hdev,FEATURE_KBD_REPORT_ID ); +if (ret <0 ) +return ret; -if (dmi_match (DMI_PRODUCT_FAMILY ,"ProArt P16" )) { - ret =asus_kbd_disable_oobe (hdev); -if (ret <0 ) -return ret; - } - }else { -/* Initialize keyboard */ - ret =asus_kbd_init (hdev,FEATURE_KBD_REPORT_ID ); -if (ret <0 ) -return ret; +/* Get keyboard functions */ + ret =asus_kbd_get_functions (hdev, &kbd_func,FEATURE_KBD_REPORT_ID ); +if (ret <0 ) +return ret; -/* Get keyboard functions */ - ret =asus_kbd_get_functions (hdev, &kbd_func,FEATURE_KBD_REPORT_ID ); +if (dmi_match (DMI_PRODUCT_FAMILY ,"ProArt P16" )) { + ret =asus_kbd_disable_oobe (hdev);if (ret <0 )return ret; - -/* Check for backlight support */ -if (!(kbd_func &SUPPORT_KBD_BACKLIGHT )) -return -ENODEV ; } +/* Check for backlight support */ +if (!(kbd_func &SUPPORT_KBD_BACKLIGHT )) +return -ENODEV ; + drvdata->kbd_backlight =devm_kzalloc (&hdev->dev,sizeof (struct asus_kbd_leds ),GFP_KERNEL );
Signature · 1 line
2.49.0
Ilpo Järvinen
maintainerRe: [PATCH v4 01/11] HID: asus: refactor init sequence per spec
Quoted 60 lines · Antheas Kapenekakis
Currently,
asus_kbd_init()uses a reverse engineered init sequence from Windows, which contains the handshakes from multiple programs. Keep the main one, which is0x5a(meant for brightness drivers).In addition, perform a
get_responseand check if the response is the same. To avoid regressions, print an error if the response does not match instead of rejecting device.Then, refactor
asus_kbd_get_functions()to use the same ID it is called with, instead of hardcoding it to0x5aso that it may be used for0x0din the future.Signed-off-by Antheas Kapenekakis <[email protected]>--- drivers/hid/hid-asus.c | 82 +++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 36 deletions(-)drivers/hid/hid-asus.c +19
-5@@ -48,7 +48,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");#define FEATURE_REPORT_ID 0x0d#define INPUT_REPORT_ID 0x5d#define FEATURE_KBD_REPORT_ID 0x5a -#define FEATURE_KBD_REPORT_SIZE 16 +#define FEATURE_KBD_REPORT_SIZE 64#define FEATURE_KBD_LED_REPORT_ID1 0x5d#define FEATURE_KBD_LED_REPORT_ID2 0x5e@@ -388,14 +388,41 @@ static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t bustatic int asus_kbd_init (struct hid_device *hdev,u8 report_id) { -const u8 buf[] = { report_id,0x41 ,0x53 ,0x55 ,0x53 ,0x20 ,0x54 , -0x65 ,0x63 ,0x68 ,0x2e ,0x49 ,0x6e ,0x63 ,0x2e ,0x00 }; +/* +* Asus handshake identifying us as a driver (0x5A) +* 0x5A then ASCII for "ASUS Tech.Inc." +* 0x5D is for userspace Windows applications. +* +* The handshake is first sent as a set_report, then retrieved +* from a get_report to verify the response. +*/ +const u8 buf[] = { report_id,0x41 ,0x53 ,0x55 ,0x53 ,0x20 , +0x54 ,0x65 ,0x63 ,0x68 ,0x2e ,0x49 ,0x6e ,0x63 ,0x2e ,0x00 }; +u8 *readbuf;int ret; ret =asus_kbd_set_report (hdev, buf,sizeof (buf)); -if (ret <0 ) -hid_err (hdev,"Asus failed to send init command: %d\n" , ret); +if (ret <0 ) { +hid_err (hdev,"Asus failed to send handshake: %d\n" , ret); +return ret; + } + readbuf =kzalloc (FEATURE_KBD_REPORT_SIZE ,GFP_KERNEL ); +if (!readbuf) +return -ENOMEM ;
drivers/hid/hid-asus.c static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t bu · line 422
Quoted 10 lines
drivers/hid/hid-asus.c +10
-0+ + ret =hid_hw_raw_request (hdev, report_id, readbuf, +FEATURE_KBD_REPORT_SIZE ,HID_FEATURE_REPORT , +HID_REQ_GET_REPORT ); +if (ret <0 ) { +hid_err (hdev,"Asus failed to receive handshake ack: %d\n" , ret); + }else if (memcmp (readbuf, buf,sizeof (buf)) !=0 ) { +hid_err (hdev,"Asus handshake returned invalid response: %*ph\n" , +FEATURE_KBD_REPORT_SIZE , readbuf); +// Do not return error if handshake is wrong to avoid regressions
Should it be on warn/info level if the error is ignored.
Quoted 72 lines
drivers/hid/hid-asus.c +17
-31+ } + +kfree (readbuf);return ret; }@@ -417,7 +444,7 @@ static int asus_kbd_get_functions(struct hid_device *hdev,if (!readbuf)return -ENOMEM ; - ret =hid_hw_raw_request (hdev,FEATURE_KBD_REPORT_ID , readbuf, + ret =hid_hw_raw_request (hdev, report_id, readbuf,FEATURE_KBD_REPORT_SIZE ,HID_FEATURE_REPORT ,HID_REQ_GET_REPORT );if (ret <0 ) {@@ -540,42 +567,25 @@ static int asus_kbd_register_leds(struct hid_device *hdev)unsigned char kbd_func;int ret; -if (drvdata->quirks &QUIRK_ROG_NKEY_KEYBOARD ) { -/* Initialize keyboard */ - ret =asus_kbd_init (hdev,FEATURE_KBD_REPORT_ID ); -if (ret <0 ) -return ret; - -/* The LED endpoint is initialised in two HID */ - ret =asus_kbd_init (hdev,FEATURE_KBD_LED_REPORT_ID1 ); -if (ret <0 ) -return ret; - - ret =asus_kbd_init (hdev,FEATURE_KBD_LED_REPORT_ID2 ); -if (ret <0 ) -return ret; + ret =asus_kbd_init (hdev,FEATURE_KBD_REPORT_ID ); +if (ret <0 ) +return ret; -if (dmi_match (DMI_PRODUCT_FAMILY ,"ProArt P16" )) { - ret =asus_kbd_disable_oobe (hdev); -if (ret <0 ) -return ret; - } - }else { -/* Initialize keyboard */ - ret =asus_kbd_init (hdev,FEATURE_KBD_REPORT_ID ); -if (ret <0 ) -return ret; +/* Get keyboard functions */ + ret =asus_kbd_get_functions (hdev, &kbd_func,FEATURE_KBD_REPORT_ID ); +if (ret <0 ) +return ret; -/* Get keyboard functions */ - ret =asus_kbd_get_functions (hdev, &kbd_func,FEATURE_KBD_REPORT_ID ); +if (dmi_match (DMI_PRODUCT_FAMILY ,"ProArt P16" )) { + ret =asus_kbd_disable_oobe (hdev);if (ret <0 )return ret; - -/* Check for backlight support */ -if (!(kbd_func &SUPPORT_KBD_BACKLIGHT )) -return -ENODEV ; } +/* Check for backlight support */ +if (!(kbd_func &SUPPORT_KBD_BACKLIGHT )) +return -ENODEV ; + drvdata->kbd_backlight =devm_kzalloc (&hdev->dev,sizeof (struct asus_kbd_leds ),GFP_KERNEL );
Signature · 1 line
i.
PATCH v4 2/11 HID: asus: prevent binding to all HID devices on ROG
In reply to Antheas KapenekakisROG keyboards are HID compliant and only care about the endpoint that produces vendor events (e.g., fan mode) and has the keyboard backlight.
Therefore, handle all of the endpoints of ROG keyboards as compliant, by adding HID_QUIRK_INPUT_PER_APP and, for devices other than the vendor one, by adding QUIRK_HANDLE_GENERIC to stop mutating them.
Due to HID_QUIRK_INPUT_PER_APP, rgb register is moved into probe, as the input_* functions are called multiple times (4 for the Z13).
--- drivers/hid/hid-asus.c | 69 ++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 16 deletions(-)
drivers/hid/hid-asus.c +53 -16
@@ -84,6 +84,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");#define QUIRK_MEDION_E1239T BIT(10)#define QUIRK_ROG_NKEY_KEYBOARD BIT(11)#define QUIRK_ROG_CLAYMORE_II_KEYBOARD BIT(12) +#define QUIRK_HANDLE_GENERIC BIT(13)#define I2C_KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \ QUIRK_NO_INIT_REPORTS | \
@@ -120,7 +121,6 @@ struct asus_drvdata {struct input_dev *tp_kbd_input;struct asus_kbd_leds *kbd_backlight;const struct asus_touchpad_info *tp; -bool enable_backlight;struct power_supply *battery;struct power_supply_desc battery_desc;int battery_capacity;
@@ -326,6 +326,10 @@ static int asus_raw_event(struct hid_device *hdev, {struct asus_drvdata *drvdata =hid_get_drvdata (hdev); +if (drvdata->quirks &QUIRK_HANDLE_GENERIC ) +/* NOOP on generic HID devices to avoid side effects. */ +return 0 ; +if (drvdata->battery && data[0 ] ==BATTERY_REPORT_ID )return asus_report_battery (drvdata, data, size);
@@ -774,6 +778,10 @@ static int asus_input_configured(struct hid_device *hdev, struct hid_input *hi)struct input_dev *input = hi->input;struct asus_drvdata *drvdata =hid_get_drvdata (hdev); +if (drvdata->quirks &QUIRK_HANDLE_GENERIC ) +/* NOOP on generic HID devices to avoid side effects. */ +return 0 ; +/* T100CHI uses MULTI_INPUT, bind the touchpad to the mouse hid_input */ if (drvdata->quirks &QUIRK_T100CHI && hi->report->id !=T100CHI_MOUSE_REPORT_ID )
@@ -827,11 +835,6 @@ static int asus_input_configured(struct hid_device *hdev, struct hid_input *hi) drvdata->input = input; -if (drvdata->enable_backlight && - !asus_kbd_wmi_led_control_present (hdev) && -asus_kbd_register_leds (hdev)) -hid_warn (hdev,"Failed to initialize backlight.\n" ); -return 0 ; }
@@ -851,6 +854,10 @@ static int asus_input_mapping(struct hid_device *hdev,return -1 ; } +if (drvdata->quirks &QUIRK_HANDLE_GENERIC ) +/* NOOP on generic HID devices to avoid side effects. */ +return 0 ; +/* * Ignore a bunch of bogus collections in the T100CHI descriptor. * This avoids a bunch of non-functional hid_input devices getting
@@ -901,15 +908,6 @@ static int asus_input_mapping(struct hid_device *hdev,return -1 ; } -/* -* Check and enable backlight only on devices with UsagePage == -* 0xff31 to avoid initializing the keyboard firmware multiple -* times on devices with multiple HID descriptors but same -* PID/VID. -*/ -if (drvdata->quirks &QUIRK_USE_KBD_BACKLIGHT ) - drvdata->enable_backlight = true; -set_bit (EV_REP , hi->input->evbit);return 1 ; }
@@ -1026,8 +1024,10 @@ static int __maybe_unused asus_reset_resume(struct hid_device *hdev)static int asus_probe (struct hid_device *hdev,const struct hid_device_id *id) { -int ret; +struct hid_report_enum *rep_enum;struct asus_drvdata *drvdata; +struct hid_report *rep; +int ret, is_vendor =0 ; drvdata =devm_kzalloc (&hdev->dev,sizeof (*drvdata),GFP_KERNEL );if (drvdata ==NULL ) {
@@ -1111,12 +1111,45 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)return ret; } +/* +* Check for the vendor interface (0xff31) to init the RGB. +* and handle generic devices properly. +*/ + rep_enum = &hdev->report_enum[HID_INPUT_REPORT ]; +list_for_each_entry (rep, &rep_enum->report_list, list) { +if ((rep->application &HID_USAGE_PAGE ) ==0xff310000 ) + is_vendor = true; + } + +/* +* For ROG keyboards, make them hid compliant by +* creating one input per application. For interfaces other than +* the vendor one, disable hid-asus handlers. +*/ +if (drvdata->quirks &QUIRK_ROG_NKEY_KEYBOARD ) { +if (!is_vendor) + drvdata->quirks |=QUIRK_HANDLE_GENERIC ; + hdev->quirks |=HID_QUIRK_INPUT_PER_APP ; + } + ret =hid_hw_start (hdev,HID_CONNECT_DEFAULT );if (ret) {hid_err (hdev,"Asus hw start failed: %d\n" , ret);return ret; } +if (is_vendor && (drvdata->quirks &QUIRK_USE_KBD_BACKLIGHT ) && + !asus_kbd_wmi_led_control_present (hdev) && +asus_kbd_register_leds (hdev)) +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. +*/ +if (drvdata->quirks &QUIRK_ROG_NKEY_KEYBOARD ) +return 0 ; +if (!drvdata->input) {hid_err (hdev,"Asus input not registered\n" ); ret = -ENOMEM ;
@@ -1167,6 +1200,10 @@ static const __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc, {struct asus_drvdata *drvdata =hid_get_drvdata (hdev); +if (drvdata->quirks &QUIRK_HANDLE_GENERIC ) +/* NOOP on generic HID devices to avoid side effects. */ +return rdesc; +if (drvdata->quirks &QUIRK_FIX_NOTEBOOK_REPORT && *rsize >=56 && rdesc[54 ] ==0x25 && rdesc[55 ] ==0x65 ) {hid_info (hdev,"Fixing up Asus notebook report descriptor\n" );
Signature · 1 line
2.49.0
Ilpo Järvinen
maintainerRe: [PATCH v4 02/11] HID: asus: prevent binding to all HID devices on ROG
Quoted 48 lines · Antheas Kapenekakis
ROG keyboards are HID compliant and only care about the endpoint that produces vendor events (e.g., fan mode) and has the keyboard backlight.
Therefore, handle all of the endpoints of ROG keyboards as compliant, by adding
HID_QUIRK_INPUT_PER_APPand, for devices other than the vendor one, by addingQUIRK_HANDLE_GENERICto stop mutating them.Due to
HID_QUIRK_INPUT_PER_APP, rgb register is moved into probe, as the input_* functions are called multiple times (4 for the Z13).Reviewed-by Luke D. Jones <[email protected]>Signed-off-by Antheas Kapenekakis <[email protected]>--- drivers/hid/hid-asus.c | 69 ++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 16 deletions(-)drivers/hid/hid-asus.c +5
-1@@ -84,6 +84,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");#define QUIRK_MEDION_E1239T BIT(10)#define QUIRK_ROG_NKEY_KEYBOARD BIT(11)#define QUIRK_ROG_CLAYMORE_II_KEYBOARD BIT(12) +#define QUIRK_HANDLE_GENERIC BIT(13)#define I2C_KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \ QUIRK_NO_INIT_REPORTS | \@@ -120,7 +121,6 @@ struct asus_drvdata {struct input_dev *tp_kbd_input;struct asus_kbd_leds *kbd_backlight;const struct asus_touchpad_info *tp; -bool enable_backlight;struct power_supply *battery;struct power_supply_desc battery_desc;int battery_capacity;@@ -326,6 +326,10 @@ static int asus_raw_event(struct hid_device *hdev, {struct asus_drvdata *drvdata =hid_get_drvdata (hdev); +if (drvdata->quirks &QUIRK_HANDLE_GENERIC ) +/* NOOP on generic HID devices to avoid side effects. */ +return 0 ; +if (drvdata->battery && data[0 ] ==BATTERY_REPORT_ID )return asus_report_battery (drvdata, data, size);
drivers/hid/hid-asus.c static int asus_input_configured(struct hid_device *hdev, struct hid_input *hi) · line 783
Quoted 6 lines
drivers/hid/hid-asus.c +3
-0@@ -774,6 +778,10 @@ static int asus_input_configured(struct hid_device *hdev, struct hid_input *hi)struct input_dev *input = hi->input;struct asus_drvdata *drvdata =hid_get_drvdata (hdev); +if (drvdata->quirks &QUIRK_HANDLE_GENERIC ) +/* NOOP on generic HID devices to avoid side effects. */ +return 0 ;
You'd need braces for multiline indented constructs like this, however, I think that comment can appear before the if line which wouldn't require braces. The same applies to many cases below.
Quoted 56 lines
drivers/hid/hid-asus.c +8
-15+/* T100CHI uses MULTI_INPUT, bind the touchpad to the mouse hid_input */ if (drvdata->quirks &QUIRK_T100CHI && hi->report->id !=T100CHI_MOUSE_REPORT_ID )@@ -827,11 +835,6 @@ static int asus_input_configured(struct hid_device *hdev, struct hid_input *hi) drvdata->input = input; -if (drvdata->enable_backlight && - !asus_kbd_wmi_led_control_present (hdev) && -asus_kbd_register_leds (hdev)) -hid_warn (hdev,"Failed to initialize backlight.\n" ); -return 0 ; }@@ -851,6 +854,10 @@ static int asus_input_mapping(struct hid_device *hdev,return -1 ; } +if (drvdata->quirks &QUIRK_HANDLE_GENERIC ) +/* NOOP on generic HID devices to avoid side effects. */ +return 0 ; +/* * Ignore a bunch of bogus collections in the T100CHI descriptor. * This avoids a bunch of non-functional hid_input devices getting @@ -901,15 +908,6 @@ static int asus_input_mapping(struct hid_device *hdev,return -1 ; } -/* -* Check and enable backlight only on devices with UsagePage == -* 0xff31 to avoid initializing the keyboard firmware multiple -* times on devices with multiple HID descriptors but same -* PID/VID. -*/ -if (drvdata->quirks &QUIRK_USE_KBD_BACKLIGHT ) - drvdata->enable_backlight = true; -set_bit (EV_REP , hi->input->evbit);return 1 ; }@@ -1026,8 +1024,10 @@ static int __maybe_unused asus_reset_resume(struct hid_device *hdev)static int asus_probe (struct hid_device *hdev,const struct hid_device_id *id) { -int ret; +struct hid_report_enum *rep_enum;struct asus_drvdata *drvdata; +struct hid_report *rep; +int ret, is_vendor =0 ; drvdata =devm_kzalloc (&hdev->dev,sizeof (*drvdata),GFP_KERNEL );if (drvdata ==NULL ) {
drivers/hid/hid-asus.c static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id) · line 1115
Quoted 5 lines
drivers/hid/hid-asus.c +2
-0@@ -1111,12 +1111,45 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)return ret; } +/* +* Check for the vendor interface (0xff31) to init the RGB.
The next line seems to be continuation, is . extra?
drivers/hid/hid-asus.c static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id) · line 1120
Quoted 5 lines
drivers/hid/hid-asus.c +5
-0+* and handle generic devices properly. +*/ + rep_enum = &hdev->report_enum[HID_INPUT_REPORT ]; +list_for_each_entry (rep, &rep_enum->report_list, list) { +if ((rep->application &HID_USAGE_PAGE ) ==0xff310000 )
Use a named define for the literal?
Quoted 18 lines
drivers/hid/hid-asus.c +14
-0+ is_vendor = true; + } + +/* +* For ROG keyboards, make them hid compliant by +* creating one input per application. For interfaces other than +* the vendor one, disable hid-asus handlers. +*/ +if (drvdata->quirks &QUIRK_ROG_NKEY_KEYBOARD ) { +if (!is_vendor) + drvdata->quirks |=QUIRK_HANDLE_GENERIC ; + hdev->quirks |=HID_QUIRK_INPUT_PER_APP ; + } + ret =hid_hw_start (hdev,HID_CONNECT_DEFAULT );if (ret) {hid_err (hdev,"Asus hw start failed: %d\n" , ret);return ret;
drivers/hid/hid-asus.c static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id) · line 1148
Quoted 10 lines
drivers/hid/hid-asus.c +8
-0} +if (is_vendor && (drvdata->quirks &QUIRK_USE_KBD_BACKLIGHT ) && + !asus_kbd_wmi_led_control_present (hdev) && +asus_kbd_register_leds (hdev)) +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.
Please reflow to 80 chars.
Quoted 19 lines
drivers/hid/hid-asus.c +8
-0+*/ +if (drvdata->quirks &QUIRK_ROG_NKEY_KEYBOARD ) +return 0 ; +if (!drvdata->input) {hid_err (hdev,"Asus input not registered\n" ); ret = -ENOMEM ;@@ -1167,6 +1200,10 @@ static const __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc, {struct asus_drvdata *drvdata =hid_get_drvdata (hdev); +if (drvdata->quirks &QUIRK_HANDLE_GENERIC ) +/* NOOP on generic HID devices to avoid side effects. */ +return rdesc; +if (drvdata->quirks &QUIRK_FIX_NOTEBOOK_REPORT && *rsize >=56 && rdesc[54 ] ==0x25 && rdesc[55 ] ==0x65 ) {hid_info (hdev,"Fixing up Asus notebook report descriptor\n" );
Signature · 1 line
i.
PATCH v4 3/11 HID: Asus: add Z13 folio to generic group for multitouch to work
In reply to Antheas KapenekakisThe Asus Z13 folio has a multitouch touchpad that needs to bind to the hid-multitouch driver in order to work properly. So bind it to the HID_GROUP_GENERIC group to release the touchpad and move it to the bottom so that the comment applies to it.
While at it, change the generic KEYBOARD3 name to Z13_FOLIO.
--- drivers/hid/hid-asus.c | 6 +++--- drivers/hid/hid-ids.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/hid/hid-asus.c +3 -3
@@ -1319,9 +1319,6 @@ static const struct hid_device_id asus_devices[] = { {HID_USB_DEVICE (USB_VENDOR_ID_ASUSTEK ,USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD2 ), QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, - { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, -USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD3 ), - QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,USB_DEVICE_ID_ASUSTEK_ROG_Z13_LIGHTBAR ), QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD },
@@ -1351,6 +1348,9 @@ static const struct hid_device_id asus_devices[] = {* 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. */ + {HID_DEVICE (BUS_USB ,HID_GROUP_GENERIC , +USB_VENDOR_ID_ASUSTEK ,USB_DEVICE_ID_ASUSTEK_ROG_Z13_FOLIO ), + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_T101HA_KEYBOARD) }, { }
drivers/hid/hid-ids.h +1 -1
@@ -209,7 +209,7 @@#define USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD3 0x1822#define USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD 0x1866#define USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD2 0x19b6 -#define USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD3 0x1a30 +#define USB_DEVICE_ID_ASUSTEK_ROG_Z13_FOLIO 0x1a30#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.49.0
PATCH v4 4/11 platform/x86: asus-wmi: Add support for multiple kbd RGB handlers
In reply to Antheas KapenekakisSome devices, such as the Z13 have multiple AURA devices connected to them by USB. In addition, they might have a WMI interface for RGB. In Windows, Armoury Crate exposes a unified brightness slider for all of them, with 3 brightness levels.
Therefore, to be synergistic in Linux, and support existing tooling such as UPower, allow adding listeners to the RGB device of the WMI interface. If WMI does not exist, lazy initialize the interface.
--- drivers/platform/x86/asus-wmi.c | 118 ++++++++++++++++++--- include/linux/platform_data/x86/asus-wmi.h | 16 +++ 2 files changed, 121 insertions(+), 13 deletions(-)
drivers/platform/x86/asus-wmi.c +105 -13
@@ -254,6 +254,8 @@ struct asus_wmi {int tpd_led_wk;struct led_classdev kbd_led;int kbd_led_wk; +bool kbd_led_avail; +bool kbd_led_registered;struct led_classdev lightbar_led;int lightbar_led_wk;struct led_classdev micmute_led;
@@ -1487,6 +1489,53 @@ static void asus_wmi_battery_exit(struct asus_wmi *asus)/* LEDs ***********************************************************************/ +struct asus_hid_ref { +struct list_head listeners; +struct asus_wmi *asus; +spinlock_t lock; +}; + +struct asus_hid_ref asus_ref = { + .listeners =LIST_HEAD_INIT (asus_ref.listeners), + .asus =NULL , + .lock =__SPIN_LOCK_UNLOCKED (asus_ref.lock), +}; + +int asus_hid_register_listener (struct asus_hid_listener *bdev) +{ +unsigned long flags; +int ret =0 ; + +spin_lock_irqsave (&asus_ref.lock, flags); +list_add_tail (&bdev->list, &asus_ref.listeners); +if (asus_ref.asus) { +if (asus_ref.asus->kbd_led_registered && asus_ref.asus->kbd_led_wk >=0 ) + bdev->brightness_set (bdev, asus_ref.asus->kbd_led_wk); + +if (!asus_ref.asus->kbd_led_registered) { + ret =led_classdev_register ( + &asus_ref.asus->platform_device->dev, + &asus_ref.asus->kbd_led); +if (!ret) + asus_ref.asus->kbd_led_registered = true; + } + } +spin_unlock_irqrestore (&asus_ref.lock, flags); + +return ret; +} +EXPORT_SYMBOL_GPL (asus_hid_register_listener); + +void asus_hid_unregister_listener (struct asus_hid_listener *bdev) +{ +unsigned long flags; + +spin_lock_irqsave (&asus_ref.lock, flags); +list_del (&bdev->list); +spin_unlock_irqrestore (&asus_ref.lock, flags); +} +EXPORT_SYMBOL_GPL (asus_hid_unregister_listener); +/* * These functions actually update the LED's, and are called from a * workqueue. By doing this as separate work rather than when the LED
@@ -1566,6 +1615,7 @@ static int kbd_led_read(struct asus_wmi *asus, int *level, int *env)static void do_kbd_led_set (struct led_classdev *led_cdev,int value) { +struct asus_hid_listener *listener;struct asus_wmi *asus;int max_level;
@@ -1573,25 +1623,39 @@ static void do_kbd_led_set(struct led_classdev *led_cdev, int value) max_level = asus->kbd_led.max_brightness; asus->kbd_led_wk =clamp_val (value,0 , max_level); -kbd_led_update (asus); + +if (asus->kbd_led_avail) +kbd_led_update (asus); + +list_for_each_entry (listener, &asus_ref.listeners, list) + listener->brightness_set (listener, asus->kbd_led_wk); }static void kbd_led_set (struct led_classdev *led_cdev,enum led_brightness value) { +unsigned long flags; +/* Prevent disabling keyboard backlight on module unregister */ if (led_cdev->flags &LED_UNREGISTERING )return ; +spin_lock_irqsave (&asus_ref.lock, flags);do_kbd_led_set (led_cdev, value); +spin_unlock_irqrestore (&asus_ref.lock, flags); }static void kbd_led_set_by_kbd (struct asus_wmi *asus,enum led_brightness value) { -struct led_classdev *led_cdev = &asus->kbd_led; +struct led_classdev *led_cdev; +unsigned long flags; + +spin_lock_irqsave (&asus_ref.lock, flags); + led_cdev = &asus->kbd_led;do_kbd_led_set (led_cdev, value);led_classdev_notify_brightness_hw_changed (led_cdev, asus->kbd_led_wk); +spin_unlock_irqrestore (&asus_ref.lock, flags); }static enum led_brightness kbd_led_get (struct led_classdev *led_cdev)
@@ -1601,6 +1665,9 @@ static enum led_brightness kbd_led_get(struct led_classdev *led_cdev) asus = container_of(led_cdev, struct asus_wmi, kbd_led); +if (!asus->kbd_led_avail) +return asus->kbd_led_wk; + retval =kbd_led_read (asus, &value,NULL );if (retval <0 )return retval;
@@ -1716,7 +1783,15 @@ static int camera_led_set(struct led_classdev *led_cdev,static void asus_wmi_led_exit (struct asus_wmi *asus) { -led_classdev_unregister (&asus->kbd_led); +unsigned long flags; + +spin_lock_irqsave (&asus_ref.lock, flags); + asus_ref.asus =NULL ; +spin_unlock_irqrestore (&asus_ref.lock, flags); + +if (asus->kbd_led_registered) +led_classdev_unregister (&asus->kbd_led); +led_classdev_unregister (&asus->tpd_led);led_classdev_unregister (&asus->wlan_led);led_classdev_unregister (&asus->lightbar_led);
@@ -1730,6 +1805,8 @@ static void asus_wmi_led_exit(struct asus_wmi *asus)static int asus_wmi_led_init (struct asus_wmi *asus) {int rv =0 , num_rgb_groups =0 , led_val; +struct asus_hid_listener *listener; +unsigned long flags;if (asus->kbd_rgb_dev) kbd_rgb_mode_groups[num_rgb_groups++] = &kbd_rgb_mode_group;
@@ -1754,23 +1831,38 @@ static int asus_wmi_led_init(struct asus_wmi *asus) goto error; } -if (!kbd_led_read (asus, &led_val,NULL ) && !dmi_check_system (asus_use_hid_led_dmi_ids)) { -pr_info ("using asus-wmi for asus::kbd_backlight\n" ); + asus->kbd_led.name ="asus::kbd_backlight" ; + asus->kbd_led.flags =LED_BRIGHT_HW_CHANGED ; + asus->kbd_led.brightness_set = kbd_led_set; + asus->kbd_led.brightness_get = kbd_led_get; + asus->kbd_led.max_brightness =3 ; + asus->kbd_led_avail = !kbd_led_read (asus, &led_val,NULL ); + +if (asus->kbd_led_avail) asus->kbd_led_wk = led_val; - asus->kbd_led.name ="asus::kbd_backlight" ; - asus->kbd_led.flags =LED_BRIGHT_HW_CHANGED ; - asus->kbd_led.brightness_set = kbd_led_set; - asus->kbd_led.brightness_get = kbd_led_get; - asus->kbd_led.max_brightness =3 ; +else + asus->kbd_led_wk =-1 ; -if (num_rgb_groups !=0 ) - asus->kbd_led.groups = kbd_rgb_mode_groups; +if (asus->kbd_led_avail && num_rgb_groups !=0 ) + asus->kbd_led.groups = kbd_rgb_mode_groups; +spin_lock_irqsave (&asus_ref.lock, flags); +if (asus->kbd_led_avail || !list_empty (&asus_ref.listeners)) { rv =led_classdev_register (&asus->platform_device->dev, &asus->kbd_led); -if (rv) +if (rv) { +spin_unlock_irqrestore (&asus_ref.lock, flags); goto error; + } + asus->kbd_led_registered = true; + +if (asus->kbd_led_wk >=0 ) { +list_for_each_entry (listener, &asus_ref.listeners, list) + listener->brightness_set (listener, asus->kbd_led_wk); + } } + asus_ref.asus = asus; +spin_unlock_irqrestore (&asus_ref.lock, flags);if (asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_WIRELESS_LED ) && (asus->driver->quirks->wapf >0 )) {
include/linux/platform_data/x86/asus-wmi.h +16 -0
@@ -157,14 +157,30 @@#define ASUS_WMI_DSTS_MAX_BRIGTH_MASK 0x0000FF00#define ASUS_WMI_DSTS_LIGHTBAR_MASK 0x0000000F +struct asus_hid_listener { +struct list_head list; +void (*brightness_set)(struct asus_hid_listener *listener,int brightness); +}; +#if IS_REACHABLE (CONFIG_ASUS_WMI )int asus_wmi_evaluate_method (u32 method_id,u32 arg0,u32 arg1,u32 *retval); + +int asus_hid_register_listener (struct asus_hid_listener *cdev); +void asus_hid_unregister_listener (struct asus_hid_listener *cdev);#else static inline int asus_wmi_evaluate_method (u32 method_id,u32 arg0,u32 arg1,u32 *retval) {return -ENODEV ; } + +static inline int asus_hid_register_listener (struct asus_hid_listener *bdev) +{ +return -ENODEV ; +} +static inline void asus_hid_unregister_listener (struct asus_hid_listener *bdev) +{ +}#endif /* To be used by both hid-asus and asus-wmi to determine which controls kbd_brightness */
Signature · 1 line
2.49.0
PATCH v4 5/11 HID: asus: listen to the asus-wmi brightness device instead of creating one
In reply to Antheas KapenekakisSome ROG laptops expose multiple interfaces for controlling the keyboard/RGB brightness. This creates a name conflict under asus::kbd_brightness, where the second device ends up being named asus::kbd_brightness_1 and they are both broken.
Therefore, register a listener to the asus-wmi brightness device instead of creating a new one.
--- drivers/hid/hid-asus.c | 65 +++++++----------------------------------- 1 file changed, 11 insertions(+), 54 deletions(-)
drivers/hid/hid-asus.c +11 -54
@@ -96,7 +96,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");#define TRKID_SGN ((TRKID_MAX + 1) >> 1)struct asus_kbd_leds { -struct led_classdev cdev; +struct asus_hid_listener listener;struct hid_device *hdev;struct work_struct work;unsigned int brightness;
@@ -493,11 +493,11 @@ static void asus_schedule_work(struct asus_kbd_leds *led)spin_unlock_irqrestore (&led->lock, flags); } -static void asus_kbd_backlight_set (struct led_classdev *led_cdev, -enum led_brightness brightness) +static void asus_kbd_backlight_set (struct asus_hid_listener *listener, +int brightness) { - struct asus_kbd_leds *led = container_of(led_cdev, struct asus_kbd_leds, - cdev); + struct asus_kbd_leds *led = container_of(listener, struct asus_kbd_leds, + listener);unsigned long flags;spin_lock_irqsave (&led->lock, flags);
@@ -507,20 +507,6 @@ static void asus_kbd_backlight_set(struct led_classdev *led_cdev,asus_schedule_work (led); } -static enum led_brightness asus_kbd_backlight_get (struct led_classdev *led_cdev) -{ - struct asus_kbd_leds *led = container_of(led_cdev, struct asus_kbd_leds, - cdev); -enum led_brightness brightness; -unsigned long flags; - -spin_lock_irqsave (&led->lock, flags); - brightness = led->brightness; -spin_unlock_irqrestore (&led->lock, flags); - -return brightness; -} -static void asus_kbd_backlight_work (struct work_struct *work) { struct asus_kbd_leds *led = container_of(work, struct asus_kbd_leds, work);
@@ -537,34 +523,6 @@ static void asus_kbd_backlight_work(struct work_struct *work)hid_err (led->hdev,"Asus failed to set keyboard backlight: %d\n" , ret); } -/* WMI-based keyboard backlight LED control (via asus-wmi driver) takes -* precedence. We only activate HID-based backlight control when the -* WMI control is not available. -*/ -static bool asus_kbd_wmi_led_control_present (struct hid_device *hdev) -{ -struct asus_drvdata *drvdata =hid_get_drvdata (hdev); -u32 value; -int ret; - -if (!IS_ENABLED (CONFIG_ASUS_WMI )) -return false; - -if (drvdata->quirks &QUIRK_ROG_NKEY_KEYBOARD && -dmi_check_system (asus_use_hid_led_dmi_ids)) { -hid_info (hdev,"using HID for asus::kbd_backlight\n" ); -return false; - } - - ret =asus_wmi_evaluate_method (ASUS_WMI_METHODID_DSTS , -ASUS_WMI_DEVID_KBD_BACKLIGHT ,0 , &value); -hid_dbg (hdev,"WMI backlight check: rc %d value %x" , ret, value); -if (ret) -return false; - -return !!(value &ASUS_WMI_DSTS_PRESENCE_BIT ); -} -static int asus_kbd_register_leds (struct hid_device *hdev) {struct asus_drvdata *drvdata =hid_get_drvdata (hdev);
@@ -599,14 +557,12 @@ static int asus_kbd_register_leds(struct hid_device *hdev) drvdata->kbd_backlight->removed = false; drvdata->kbd_backlight->brightness =0 ; drvdata->kbd_backlight->hdev = hdev; - drvdata->kbd_backlight->cdev.name ="asus::kbd_backlight" ; - drvdata->kbd_backlight->cdev.max_brightness =3 ; - drvdata->kbd_backlight->cdev.brightness_set = asus_kbd_backlight_set; - drvdata->kbd_backlight->cdev.brightness_get = asus_kbd_backlight_get; + drvdata->kbd_backlight->listener.brightness_set = asus_kbd_backlight_set;INIT_WORK (&drvdata->kbd_backlight->work, asus_kbd_backlight_work);spin_lock_init (&drvdata->kbd_backlight->lock); - ret =devm_led_classdev_register (&hdev->dev, &drvdata->kbd_backlight->cdev); + ret =asus_hid_register_listener (&drvdata->kbd_backlight->listener); +if (ret <0 ) {/* No need to have this still around */ devm_kfree (&hdev->dev, drvdata->kbd_backlight);
@@ -1000,7 +956,7 @@ static int __maybe_unused asus_resume(struct hid_device *hdev) {if (drvdata->kbd_backlight) {const u8 buf[] = {FEATURE_KBD_REPORT_ID ,0xba ,0xc5 ,0xc4 , - drvdata->kbd_backlight->cdev.brightness }; + drvdata->kbd_backlight->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);
@@ -1139,7 +1095,6 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id) }if (is_vendor && (drvdata->quirks &QUIRK_USE_KBD_BACKLIGHT ) && - !asus_kbd_wmi_led_control_present (hdev) &&asus_kbd_register_leds (hdev))hid_warn (hdev,"Failed to initialize backlight.\n" );
@@ -1180,6 +1135,8 @@ static void asus_remove(struct hid_device *hdev)unsigned long flags;if (drvdata->kbd_backlight) { +asus_hid_unregister_listener (&drvdata->kbd_backlight->listener); +spin_lock_irqsave (&drvdata->kbd_backlight->lock, flags); drvdata->kbd_backlight->removed = true;spin_unlock_irqrestore (&drvdata->kbd_backlight->lock, flags);
Signature · 1 line
2.49.0
Ilpo Järvinen
maintainerRe: [PATCH v4 05/11] HID: asus: listen to the asus-wmi brightness device instead of creating one
Quoted 105 lines · Antheas Kapenekakis
Some ROG laptops expose multiple interfaces for controlling the keyboard/RGB brightness. This creates a name conflict under
asus::kbd_brightness, where the second device ends up being namedasus::kbd_brightness_1and they are both broken.Therefore, register a listener to the asus-wmi brightness device instead of creating a new one.
Reviewed-by Luke D. Jones <[email protected]>Signed-off-by Antheas Kapenekakis <[email protected]>--- drivers/hid/hid-asus.c | 65 +++++++----------------------------------- 1 file changed, 11 insertions(+), 54 deletions(-)drivers/hid/hid-asus.c +5
-49@@ -96,7 +96,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");#define TRKID_SGN ((TRKID_MAX + 1) >> 1)struct asus_kbd_leds { -struct led_classdev cdev; +struct asus_hid_listener listener;struct hid_device *hdev;struct work_struct work;unsigned int brightness;@@ -493,11 +493,11 @@ static void asus_schedule_work(struct asus_kbd_leds *led)spin_unlock_irqrestore (&led->lock, flags); } -static void asus_kbd_backlight_set (struct led_classdev *led_cdev, -enum led_brightness brightness) +static void asus_kbd_backlight_set (struct asus_hid_listener *listener, +int brightness) { - struct asus_kbd_leds *led = container_of(led_cdev, struct asus_kbd_leds, - cdev); + struct asus_kbd_leds *led = container_of(listener, struct asus_kbd_leds, + listener);unsigned long flags;spin_lock_irqsave (&led->lock, flags);@@ -507,20 +507,6 @@ static void asus_kbd_backlight_set(struct led_classdev *led_cdev,asus_schedule_work (led); } -static enum led_brightness asus_kbd_backlight_get (struct led_classdev *led_cdev) -{ - struct asus_kbd_leds *led = container_of(led_cdev, struct asus_kbd_leds, - cdev); -enum led_brightness brightness; -unsigned long flags; - -spin_lock_irqsave (&led->lock, flags); - brightness = led->brightness; -spin_unlock_irqrestore (&led->lock, flags); - -return brightness; -} -static void asus_kbd_backlight_work (struct work_struct *work) { struct asus_kbd_leds *led = container_of(work, struct asus_kbd_leds, work);@@ -537,34 +523,6 @@ static void asus_kbd_backlight_work(struct work_struct *work)hid_err (led->hdev,"Asus failed to set keyboard backlight: %d\n" , ret); } -/* WMI-based keyboard backlight LED control (via asus-wmi driver) takes -* precedence. We only activate HID-based backlight control when the -* WMI control is not available. -*/ -static bool asus_kbd_wmi_led_control_present (struct hid_device *hdev) -{ -struct asus_drvdata *drvdata =hid_get_drvdata (hdev); -u32 value; -int ret; - -if (!IS_ENABLED (CONFIG_ASUS_WMI )) -return false; - -if (drvdata->quirks &QUIRK_ROG_NKEY_KEYBOARD && -dmi_check_system (asus_use_hid_led_dmi_ids)) { -hid_info (hdev,"using HID for asus::kbd_backlight\n" ); -return false; - } - - ret =asus_wmi_evaluate_method (ASUS_WMI_METHODID_DSTS , -ASUS_WMI_DEVID_KBD_BACKLIGHT ,0 , &value); -hid_dbg (hdev,"WMI backlight check: rc %d value %x" , ret, value); -if (ret) -return false; - -return !!(value &ASUS_WMI_DSTS_PRESENCE_BIT ); -} -static int asus_kbd_register_leds (struct hid_device *hdev) {struct asus_drvdata *drvdata =hid_get_drvdata (hdev);@@ -599,14 +557,12 @@ static int asus_kbd_register_leds(struct hid_device *hdev) drvdata->kbd_backlight->removed = false; drvdata->kbd_backlight->brightness =0 ; drvdata->kbd_backlight->hdev = hdev; - drvdata->kbd_backlight->cdev.name ="asus::kbd_backlight" ; - drvdata->kbd_backlight->cdev.max_brightness =3 ;
drivers/hid/hid-asus.c static int asus_kbd_register_leds(struct hid_device *hdev) · line 566
Quoted 10 lines
drivers/hid/hid-asus.c +3
-3- drvdata->kbd_backlight->cdev.brightness_set = asus_kbd_backlight_set; - drvdata->kbd_backlight->cdev.brightness_get = asus_kbd_backlight_get; + drvdata->kbd_backlight->listener.brightness_set = asus_kbd_backlight_set;INIT_WORK (&drvdata->kbd_backlight->work, asus_kbd_backlight_work);spin_lock_init (&drvdata->kbd_backlight->lock); - ret =devm_led_classdev_register (&hdev->dev, &drvdata->kbd_backlight->cdev); + ret =asus_hid_register_listener (&drvdata->kbd_backlight->listener); +if (ret <0 ) {
Please don't add empty line in between function and its error handling.
Quoted 29 lines
drivers/hid/hid-asus.c +3
-2/* No need to have this still around */ devm_kfree (&hdev->dev, drvdata->kbd_backlight);@@ -1000,7 +956,7 @@ static int __maybe_unused asus_resume(struct hid_device *hdev) {if (drvdata->kbd_backlight) {const u8 buf[] = {FEATURE_KBD_REPORT_ID ,0xba ,0xc5 ,0xc4 , - drvdata->kbd_backlight->cdev.brightness }; + drvdata->kbd_backlight->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);@@ -1139,7 +1095,6 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id) }if (is_vendor && (drvdata->quirks &QUIRK_USE_KBD_BACKLIGHT ) && - !asus_kbd_wmi_led_control_present (hdev) &&asus_kbd_register_leds (hdev))hid_warn (hdev,"Failed to initialize backlight.\n" );@@ -1180,6 +1135,8 @@ static void asus_remove(struct hid_device *hdev)unsigned long flags;if (drvdata->kbd_backlight) { +asus_hid_unregister_listener (&drvdata->kbd_backlight->listener); +spin_lock_irqsave (&drvdata->kbd_backlight->lock, flags); drvdata->kbd_backlight->removed = true;spin_unlock_irqrestore (&drvdata->kbd_backlight->lock, flags);
Signature · 1 line
i.
PATCH v4 6/11 platform/x86: asus-wmi: remove unused keyboard backlight quirk
In reply to Antheas KapenekakisThe quirk for selecting whether keyboard backlight should be controlled by HID or WMI is not needed anymore, so remove it.
--- include/linux/platform_data/x86/asus-wmi.h | 40 ---------------------- 1 file changed, 40 deletions(-)
include/linux/platform_data/x86/asus-wmi.h +0 -40
@@ -183,44 +183,4 @@ static inline void asus_hid_unregister_listener(struct asus_hid_listener *bdev) }#endif -/* To be used by both hid-asus and asus-wmi to determine which controls kbd_brightness */ -static const struct dmi_system_id asus_use_hid_led_dmi_ids[] = { - { - .matches = { -DMI_MATCH (DMI_PRODUCT_FAMILY ,"ROG Zephyrus" ), - }, - }, - { - .matches = { -DMI_MATCH (DMI_PRODUCT_FAMILY ,"ROG Strix" ), - }, - }, - { - .matches = { -DMI_MATCH (DMI_PRODUCT_FAMILY ,"ROG Flow" ), - }, - }, - { - .matches = { -DMI_MATCH (DMI_PRODUCT_FAMILY ,"ProArt P16" ), - }, - }, - { - .matches = { -DMI_MATCH (DMI_BOARD_NAME ,"GA403U" ), - }, - }, - { - .matches = { -DMI_MATCH (DMI_BOARD_NAME ,"GU605M" ), - }, - }, - { - .matches = { -DMI_MATCH (DMI_BOARD_NAME ,"RC71L" ), - }, - }, - { }, -}; -#endif /* __PLATFORM_DATA_X86_ASUS_WMI_H */
Signature · 1 line
2.49.0
PATCH v4 7/11 platform/x86: asus-wmi: add keyboard brightness event handler
In reply to Antheas KapenekakisCurrenlty, the keyboard brightness control of Asus WMI keyboards is handled in the kernel, which leads to the shortcut going from brightness 0, to 1, to 2, and 3.
However, for HID keyboards it is exposed as a key and handled by the user's desktop environment. For the toggle button, this means that brightness control becomes on/off. In addition, in the absence of a DE, the keyboard brightness does not work.
Therefore, expose an event handler for the keyboard brightness control which can then be used by hid-asus.
--- drivers/platform/x86/asus-wmi.c | 39 ++++++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 11 ++++++ 2 files changed, 50 insertions(+)
drivers/platform/x86/asus-wmi.c +39 -0
@@ -1536,6 +1536,45 @@ void asus_hid_unregister_listener(struct asus_hid_listener *bdev) }EXPORT_SYMBOL_GPL (asus_hid_unregister_listener); +static void do_kbd_led_set (struct led_classdev *led_cdev,int value); + +int asus_hid_event (enum asus_hid_event event) +{ +unsigned long flags; +int brightness; + +spin_lock_irqsave (&asus_ref.lock, flags); +if (!asus_ref.asus || !asus_ref.asus->kbd_led_registered) { +spin_unlock_irqrestore (&asus_ref.lock, flags); +return -EBUSY ; + } + brightness = asus_ref.asus->kbd_led_wk; + +switch (event) { +case ASUS_EV_BRTUP : + brightness +=1 ; +break ; +case ASUS_EV_BRTDOWN : + brightness -=1 ; +break ; +case ASUS_EV_BRTTOGGLE : +if (brightness >=3 ) + brightness =0 ; +else + brightness +=1 ; +break ; + } + +do_kbd_led_set (&asus_ref.asus->kbd_led, brightness); +led_classdev_notify_brightness_hw_changed (&asus_ref.asus->kbd_led, + asus_ref.asus->kbd_led_wk); + +spin_unlock_irqrestore (&asus_ref.lock, flags); + +return 0 ; +} +EXPORT_SYMBOL_GPL (asus_hid_event); +/* * These functions actually update the LED's, and are called from a * workqueue. By doing this as separate work rather than when the LED
include/linux/platform_data/x86/asus-wmi.h +11 -0
@@ -162,11 +162,18 @@ struct asus_hid_listener {void (*brightness_set)(struct asus_hid_listener *listener,int brightness); }; +enum asus_hid_event { +ASUS_EV_BRTUP , +ASUS_EV_BRTDOWN , +ASUS_EV_BRTTOGGLE , +}; +#if IS_REACHABLE (CONFIG_ASUS_WMI )int asus_wmi_evaluate_method (u32 method_id,u32 arg0,u32 arg1,u32 *retval);int asus_hid_register_listener (struct asus_hid_listener *cdev);void asus_hid_unregister_listener (struct asus_hid_listener *cdev); +int asus_hid_event (enum asus_hid_event event);#else static inline int asus_wmi_evaluate_method (u32 method_id,u32 arg0,u32 arg1,u32 *retval)
@@ -181,6 +188,10 @@ static inline int asus_hid_register_listener(struct asus_hid_listener *bdev)static inline void asus_hid_unregister_listener (struct asus_hid_listener *bdev) { } +static inline int asus_hid_event (enum asus_hid_event event) +{ +return -ENODEV ; +}#endif #endif /* __PLATFORM_DATA_X86_ASUS_WMI_H */
Signature · 1 line
2.49.0
Ilpo Järvinen
maintainerRe: [PATCH v4 07/11] platform/x86: asus-wmi: add keyboard brightness event handler
Quoted 41 lines · Antheas Kapenekakis
Currenlty, the keyboard brightness control of Asus WMI keyboards is handled in the kernel, which leads to the shortcut going from brightness 0, to 1, to 2, and 3.
However, for HID keyboards it is exposed as a key and handled by the user's desktop environment. For the toggle button, this means that brightness control becomes on/off. In addition, in the absence of a DE, the keyboard brightness does not work.
Therefore, expose an event handler for the keyboard brightness control which can then be used by hid-asus.
Reviewed-by Luke D. Jones <[email protected]>Tested-by Luke D. Jones <[email protected]>Signed-off-by Antheas Kapenekakis <[email protected]>--- drivers/platform/x86/asus-wmi.c | 39 ++++++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 11 ++++++ 2 files changed, 50 insertions(+)drivers/platform/x86/asus-wmi.c +13
-0@@ -1536,6 +1536,45 @@ void asus_hid_unregister_listener(struct asus_hid_listener *bdev) }EXPORT_SYMBOL_GPL (asus_hid_unregister_listener); +static void do_kbd_led_set (struct led_classdev *led_cdev,int value); + +int asus_hid_event (enum asus_hid_event event) +{ +unsigned long flags; +int brightness; + +spin_lock_irqsave (&asus_ref.lock, flags); +if (!asus_ref.asus || !asus_ref.asus->kbd_led_registered) { +spin_unlock_irqrestore (&asus_ref.lock, flags); +return -EBUSY ; + } + brightness = asus_ref.asus->kbd_led_wk;
drivers/platform/x86/asus-wmi.c void asus_hid_unregister_listener(struct asus_hid_listener *bdev) · line 1561
Quoted 10 lines
drivers/platform/x86/asus-wmi.c +10
-0+ +switch (event) { +case ASUS_EV_BRTUP : + brightness +=1 ; +break ; +case ASUS_EV_BRTDOWN : + brightness -=1 ; +break ; +case ASUS_EV_BRTTOGGLE : +if (brightness >=3 )
Add ASUS_EV_MAX_BRIGHTNESS instead of a literal?
Quoted 54 lines
drivers/platform/x86/asus-wmi.c +16
-0+ brightness =0 ; + else + brightness += 1; +break ; + } + +do_kbd_led_set (&asus_ref.asus->kbd_led, brightness); +led_classdev_notify_brightness_hw_changed (&asus_ref.asus->kbd_led, + asus_ref.asus->kbd_led_wk); + +spin_unlock_irqrestore (&asus_ref.lock, flags); + +return 0 ; +} +EXPORT_SYMBOL_GPL (asus_hid_event); +/* * These functions actually update the LED's, and are called from a * workqueue. By doing this as separate work rather than when the LED include/linux/platform_data/x86/asus-wmi.h +11
-0@@ -162,11 +162,18 @@ struct asus_hid_listener {void (*brightness_set)(struct asus_hid_listener *listener,int brightness); }; +enum asus_hid_event { +ASUS_EV_BRTUP , +ASUS_EV_BRTDOWN , +ASUS_EV_BRTTOGGLE , +}; +#if IS_REACHABLE (CONFIG_ASUS_WMI )int asus_wmi_evaluate_method (u32 method_id,u32 arg0,u32 arg1,u32 *retval);int asus_hid_register_listener (struct asus_hid_listener *cdev);void asus_hid_unregister_listener (struct asus_hid_listener *cdev); +int asus_hid_event (enum asus_hid_event event);#else static inline int asus_wmi_evaluate_method (u32 method_id,u32 arg0,u32 arg1,u32 *retval)@@ -181,6 +188,10 @@ static inline int asus_hid_register_listener(struct asus_hid_listener *bdev)static inline void asus_hid_unregister_listener (struct asus_hid_listener *bdev) { } +static inline int asus_hid_event (enum asus_hid_event event) +{ +return -ENODEV ; +}#endif #endif /* __PLATFORM_DATA_X86_ASUS_WMI_H */
Signature · 1 line
i.
PATCH v4 8/11 HID: asus: add support for the asus-wmi brightness handler
In reply to Antheas KapenekakisIf the asus-wmi brightness handler is available, send the keyboard brightness events to it instead of passing them to userspace. If it is not, fall back to sending them to it.
--- drivers/hid/hid-asus.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/hid/hid-asus.c +11 -0
@@ -318,6 +318,17 @@ static int asus_event(struct hid_device *hdev, struct hid_field *field, usage->hid & HID_USAGE); } +if (usage->type ==EV_KEY && value) { +switch (usage->code) { +case KEY_KBDILLUMUP : +return !asus_hid_event (ASUS_EV_BRTUP ); +case KEY_KBDILLUMDOWN : +return !asus_hid_event (ASUS_EV_BRTDOWN ); +case KEY_KBDILLUMTOGGLE : +return !asus_hid_event (ASUS_EV_BRTTOGGLE ); + } + } +return 0 ; }
Signature · 1 line
2.49.0
PATCH v4 9/11 HID: asus: add basic RGB support
In reply to Antheas KapenekakisAdds basic RGB support to hid-asus through multi-index. The interface works quite well, but has not gone through much stability testing. Applied on demand, if userspace does not touch the RGB sysfs, not even initialization is done. Ensuring compatibility with existing userspace programs.
--- drivers/hid/hid-asus.c | 169 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 155 insertions(+), 14 deletions(-)
drivers/hid/hid-asus.c +155 -14
@@ -30,6 +30,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/led-class-multicolor.h> #include <linux/leds.h> #include "hid-ids.h"
@@ -85,6 +86,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");#define QUIRK_ROG_NKEY_KEYBOARD BIT(11)#define QUIRK_ROG_CLAYMORE_II_KEYBOARD BIT(12)#define QUIRK_HANDLE_GENERIC BIT(13) +#define QUIRK_ROG_NKEY_RGB BIT(14)#define I2C_KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \ QUIRK_NO_INIT_REPORTS | \
@@ -97,9 +99,15 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");struct asus_kbd_leds {struct asus_hid_listener listener; +struct led_classdev_mc mc_led; +struct mc_subled subled_info[3 ];struct hid_device *hdev;struct work_struct work;unsigned int brightness; +uint8_t rgb_colors[3 ]; +bool rgb_init; +bool rgb_set; +bool rgb_registered;spinlock_t lock;bool removed; };
@@ -504,23 +512,67 @@ static void asus_schedule_work(struct asus_kbd_leds *led)spin_unlock_irqrestore (&led->lock, flags); } -static void asus_kbd_backlight_set (struct asus_hid_listener *listener, +static void do_asus_kbd_backlight_set (struct asus_kbd_leds *led,int brightness) +{ +unsigned long flags; + +spin_lock_irqsave (&led->lock, flags); + led->brightness = brightness; +spin_unlock_irqrestore (&led->lock, flags); + +asus_schedule_work (led); +} + +static void asus_kbd_listener_set (struct asus_hid_listener *listener,int brightness) { struct asus_kbd_leds *led = container_of(listener, struct asus_kbd_leds, listener); +do_asus_kbd_backlight_set (led, brightness); +if (led->rgb_registered) { + led->mc_led.led_cdev.brightness = brightness; +led_classdev_notify_brightness_hw_changed (&led->mc_led.led_cdev, + brightness); + } +} + +static void asus_kbd_brightness_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct led_classdev_mc *mc_cdev =lcdev_to_mccdev (led_cdev); + struct asus_kbd_leds *led = container_of(mc_cdev, struct asus_kbd_leds, + mc_led);unsigned long flags;spin_lock_irqsave (&led->lock, flags); - led->brightness = brightness; + led->rgb_colors[0 ] = mc_cdev->subled_info[0 ].intensity; + led->rgb_colors[1 ] = mc_cdev->subled_info[1 ].intensity; + led->rgb_colors[2 ] = mc_cdev->subled_info[2 ].intensity; + led->rgb_set = true;spin_unlock_irqrestore (&led->lock, flags); -asus_schedule_work (led); +do_asus_kbd_backlight_set (led, brightness); +} + +static enum led_brightness asus_kbd_brightness_get (struct led_classdev *led_cdev) +{ +struct led_classdev_mc *mc_led; +struct asus_kbd_leds *led; +enum led_brightness brightness; +unsigned long flags; + + mc_led =lcdev_to_mccdev (led_cdev); + led = container_of(mc_led, struct asus_kbd_leds, mc_led); + +spin_lock_irqsave (&led->lock, flags); + brightness = led->brightness; +spin_unlock_irqrestore (&led->lock, flags); + +return brightness; } -static void asus_kbd_backlight_work (struct work_struct *work) +static void asus_kbd_backlight_work (struct asus_kbd_leds *led) { - struct asus_kbd_leds *led = container_of(work, struct asus_kbd_leds, work);u8 buf[] = {FEATURE_KBD_REPORT_ID ,0xba ,0xc5 ,0xc4 ,0x00 };int ret;unsigned long flags;
@@ -534,10 +586,69 @@ static void asus_kbd_backlight_work(struct work_struct *work)hid_err (led->hdev,"Asus failed to set keyboard backlight: %d\n" , ret); } +static void asus_kbd_rgb_work (struct asus_kbd_leds *led) +{ +u8 rgb_buf[][7 ] = { + {FEATURE_KBD_LED_REPORT_ID1 ,0xB3 },/* set mode */ + {FEATURE_KBD_LED_REPORT_ID1 ,0xB5 },/* apply mode */ + {FEATURE_KBD_LED_REPORT_ID1 ,0xB4 },/* save to mem */ + }; +unsigned long flags; +uint8_t colors[3 ]; +bool rgb_init, rgb_set; +int ret; + +spin_lock_irqsave (&led->lock, flags); + rgb_init = led->rgb_init; + rgb_set = led->rgb_set; + led->rgb_set = false; + colors[0 ] = led->rgb_colors[0 ]; + colors[1 ] = led->rgb_colors[1 ]; + colors[2 ] = led->rgb_colors[2 ]; +spin_unlock_irqrestore (&led->lock, flags); + +if (!rgb_set) +return ; + +if (rgb_init) { + ret =asus_kbd_init (led->hdev,FEATURE_KBD_LED_REPORT_ID1 ); +if (ret <0 ) { +hid_err (led->hdev,"Asus failed to init RGB: %d\n" , ret); +return ; + } +spin_lock_irqsave (&led->lock, flags); + led->rgb_init = false; +spin_unlock_irqrestore (&led->lock, flags); + } + +/* Protocol is: 54b3 zone (0=all) mode (0=solid) RGB */ + rgb_buf[0 ][4 ] = colors[0 ]; + rgb_buf[0 ][5 ] = colors[1 ]; + rgb_buf[0 ][6 ] = colors[2 ]; + +for (size_t i =0 ; i <ARRAY_SIZE (rgb_buf); i++) { + ret =asus_kbd_set_report (led->hdev, rgb_buf[i],sizeof (rgb_buf[i])); +if (ret <0 ) { +hid_err (led->hdev,"Asus failed to set RGB: %d\n" , ret); +return ; + } + } +} + +static void asus_kbd_work (struct work_struct *work) +{ + struct asus_kbd_leds *led = container_of(work, struct asus_kbd_leds, + work); +asus_kbd_backlight_work (led); +asus_kbd_rgb_work (led); +} +static int asus_kbd_register_leds (struct hid_device *hdev) {struct asus_drvdata *drvdata =hid_get_drvdata (hdev);unsigned char kbd_func; +struct asus_kbd_leds *leds; +bool no_led;int ret; ret =asus_kbd_init (hdev,FEATURE_KBD_REPORT_ID );
@@ -565,21 +676,51 @@ static int asus_kbd_register_leds(struct hid_device *hdev)if (!drvdata->kbd_backlight)return -ENOMEM ; - drvdata->kbd_backlight->removed = false; - drvdata->kbd_backlight->brightness =0 ; - drvdata->kbd_backlight->hdev = hdev; - drvdata->kbd_backlight->listener.brightness_set = asus_kbd_backlight_set; -INIT_WORK (&drvdata->kbd_backlight->work, asus_kbd_backlight_work); + leds = drvdata->kbd_backlight; + leds->removed = false; + leds->brightness =3 ; + leds->hdev = hdev; + leds->listener.brightness_set = asus_kbd_listener_set; + + leds->rgb_colors[0 ] =0 ; + leds->rgb_colors[1 ] =0 ; + leds->rgb_colors[2 ] =0 ; + leds->rgb_init = true; + leds->rgb_set = false; + leds->mc_led.led_cdev.name =devm_kasprintf (&hdev->dev,GFP_KERNEL , +"asus-%s:rgb:peripheral" , +strlen (hdev->uniq) ? + hdev->uniq :dev_name (&hdev->dev)); + leds->mc_led.led_cdev.flags =LED_BRIGHT_HW_CHANGED ; + leds->mc_led.led_cdev.max_brightness =3 , + leds->mc_led.led_cdev.brightness_set = asus_kbd_brightness_set, + leds->mc_led.led_cdev.brightness_get = asus_kbd_brightness_get, + leds->mc_led.subled_info = leds->subled_info, + leds->mc_led.num_colors =ARRAY_SIZE (leds->subled_info), + leds->subled_info[0 ].color_index =LED_COLOR_ID_RED ; + leds->subled_info[1 ].color_index =LED_COLOR_ID_GREEN ; + leds->subled_info[2 ].color_index =LED_COLOR_ID_BLUE ; + +INIT_WORK (&drvdata->kbd_backlight->work, asus_kbd_work);spin_lock_init (&drvdata->kbd_backlight->lock); ret =asus_hid_register_listener (&drvdata->kbd_backlight->listener); + no_led = !!ret; + +if (drvdata->quirks &QUIRK_ROG_NKEY_RGB ) { + ret =devm_led_classdev_multicolor_register ( + &hdev->dev, &leds->mc_led); +if (!ret) + leds->rgb_registered = true; + no_led &= !!ret; + } -if (ret <0 ) { +if (no_led) {/* No need to have this still around */ devm_kfree (&hdev->dev, drvdata->kbd_backlight); } -return ret; +return no_led ? -ENODEV :0 ; }/*
@@ -1289,7 +1430,7 @@ static const struct hid_device_id asus_devices[] = { QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, {HID_USB_DEVICE (USB_VENDOR_ID_ASUSTEK ,USB_DEVICE_ID_ASUSTEK_ROG_Z13_LIGHTBAR ), - QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_ROG_NKEY_RGB }, { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,USB_DEVICE_ID_ASUSTEK_ROG_NKEY_ALLY ), QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD },
@@ -1318,7 +1459,7 @@ static const struct hid_device_id asus_devices[] = {*/ {HID_DEVICE (BUS_USB ,HID_GROUP_GENERIC ,USB_VENDOR_ID_ASUSTEK ,USB_DEVICE_ID_ASUSTEK_ROG_Z13_FOLIO ), - QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_ROG_NKEY_RGB }, { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_T101HA_KEYBOARD) }, { }
Signature · 1 line
2.49.0
kernel test robot
build botRe: [PATCH v4 09/11] HID: asus: add basic RGB support
kernel test robot noticed the following build errors:
Hi Antheas,
kernel test robot noticed the following build errors:
[auto build test ERROR on 38fec10eb60d687e30c8c6b5420d86e8149f7557]
url: https://github.com/intel-lab-lkp/linux/commits/Antheas-Kapenekakis/HID-asus-refactor-init-sequence-per-spec/20250325-051852 base: 38fec10eb60d687e30c8c6b5420d86e8149f7557 patch link: https://lore.kernel.org/r/20250324210151.6042-10-lkml%40antheas.dev patch subject: [PATCH v4 09/11] HID: asus: add basic RGB support config: arm64-randconfig-004-20250325 (https://download.01.org/0day-ci/archive/20250325/[email protected]/config) compiler: clang version 20.1.1 (https://github.com/llvm/llvm-project 424c2d9b7e4de40d0804dd374721e6411c27d1d1) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250325/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "devm_led_classdev_multicolor_register_ext" [drivers/hid/hid-asus.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v4 09/11] HID: asus: add basic RGB support
In reply to Antheas Kapenekakiskernel test robot noticed the following build errors:
Hi Antheas,
kernel test robot noticed the following build errors:
[auto build test ERROR on 38fec10eb60d687e30c8c6b5420d86e8149f7557]
url: https://github.com/intel-lab-lkp/linux/commits/Antheas-Kapenekakis/HID-asus-refactor-init-sequence-per-spec/20250325-051852 base: 38fec10eb60d687e30c8c6b5420d86e8149f7557 patch link: https://lore.kernel.org/r/20250324210151.6042-10-lkml%40antheas.dev patch subject: [PATCH v4 09/11] HID: asus: add basic RGB support config: riscv-randconfig-002-20250325 (https://download.01.org/0day-ci/archive/20250325/[email protected]/config) compiler: riscv64-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250325/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
riscv64-linux-ld: drivers/hid/hid-asus.o: in function `asus_kbd_register_leds':
>> drivers/hid/hid-asus.c:676:(.text+0x23f8): undefined reference to `devm_led_classdev_multicolor_register_ext'
vim +676 drivers/hid/hid-asus.c
312a522531f6e5 Antheas Kapenekakis 2025-03-24 645
af22a610bc3850 Carlo Caione 2017-04-06 646 static int asus_kbd_register_leds(struct hid_device *hdev)
af22a610bc3850 Carlo Caione 2017-04-06 647 {
af22a610bc3850 Carlo Caione 2017-04-06 648 struct asus_drvdata *drvdata = hid_get_drvdata(hdev);
af22a610bc3850 Carlo Caione 2017-04-06 649 unsigned char kbd_func;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 650 struct asus_kbd_leds *leds;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 651 bool no_led;
af22a610bc3850 Carlo Caione 2017-04-06 652 int ret;
af22a610bc3850 Carlo Caione 2017-04-06 653
2c82a7b20f7b7a Luke D. Jones 2024-04-16 654 ret = asus_kbd_init(hdev, FEATURE_KBD_REPORT_ID);
2c82a7b20f7b7a Luke D. Jones 2024-04-16 655 if (ret < 0)
2c82a7b20f7b7a Luke D. Jones 2024-04-16 656 return ret;
2c82a7b20f7b7a Luke D. Jones 2024-04-16 657
3ebfeb18b44e01 Antheas Kapenekakis 2025-03-24 658 /* Get keyboard functions */
3ebfeb18b44e01 Antheas Kapenekakis 2025-03-24 659 ret = asus_kbd_get_functions(hdev, &kbd_func, FEATURE_KBD_REPORT_ID);
b92b80246e0626 Luke D Jones 2020-10-27 660 if (ret < 0)
b92b80246e0626 Luke D Jones 2020-10-27 661 return ret;
53078a736fbc60 Luke D. Jones 2025-01-11 662
53078a736fbc60 Luke D. Jones 2025-01-11 663 if (dmi_match(DMI_PRODUCT_FAMILY, "ProArt P16")) {
53078a736fbc60 Luke D. Jones 2025-01-11 664 ret = asus_kbd_disable_oobe(hdev);
53078a736fbc60 Luke D. Jones 2025-01-11 665 if (ret < 0)
53078a736fbc60 Luke D. Jones 2025-01-11 666 return ret;
53078a736fbc60 Luke D. Jones 2025-01-11 667 }
af22a610bc3850 Carlo Caione 2017-04-06 668
af22a610bc3850 Carlo Caione 2017-04-06 669 /* Check for backlight support */
af22a610bc3850 Carlo Caione 2017-04-06 670 if (!(kbd_func & SUPPORT_KBD_BACKLIGHT))
af22a610bc3850 Carlo Caione 2017-04-06 671 return -ENODEV;
af22a610bc3850 Carlo Caione 2017-04-06 672
af22a610bc3850 Carlo Caione 2017-04-06 673 drvdata->kbd_backlight = devm_kzalloc(&hdev->dev,
af22a610bc3850 Carlo Caione 2017-04-06 674 sizeof(struct asus_kbd_leds),
af22a610bc3850 Carlo Caione 2017-04-06 675 GFP_KERNEL);
af22a610bc3850 Carlo Caione 2017-04-06 @676 if (!drvdata->kbd_backlight)
af22a610bc3850 Carlo Caione 2017-04-06 677 return -ENOMEM;
af22a610bc3850 Carlo Caione 2017-04-06 678
312a522531f6e5 Antheas Kapenekakis 2025-03-24 679 leds = drvdata->kbd_backlight;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 680 leds->removed = false;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 681 leds->brightness = 3;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 682 leds->hdev = hdev;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 683 leds->listener.brightness_set = asus_kbd_listener_set;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 684
312a522531f6e5 Antheas Kapenekakis 2025-03-24 685 leds->rgb_colors[0] = 0;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 686 leds->rgb_colors[1] = 0;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 687 leds->rgb_colors[2] = 0;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 688 leds->rgb_init = true;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 689 leds->rgb_set = false;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 690 leds->mc_led.led_cdev.name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
312a522531f6e5 Antheas Kapenekakis 2025-03-24 691 "asus-%s:rgb:peripheral",
312a522531f6e5 Antheas Kapenekakis 2025-03-24 692 strlen(hdev->uniq) ?
312a522531f6e5 Antheas Kapenekakis 2025-03-24 693 hdev->uniq : dev_name(&hdev->dev));
312a522531f6e5 Antheas Kapenekakis 2025-03-24 694 leds->mc_led.led_cdev.flags = LED_BRIGHT_HW_CHANGED;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 695 leds->mc_led.led_cdev.max_brightness = 3,
312a522531f6e5 Antheas Kapenekakis 2025-03-24 696 leds->mc_led.led_cdev.brightness_set = asus_kbd_brightness_set,
312a522531f6e5 Antheas Kapenekakis 2025-03-24 697 leds->mc_led.led_cdev.brightness_get = asus_kbd_brightness_get,
312a522531f6e5 Antheas Kapenekakis 2025-03-24 698 leds->mc_led.subled_info = leds->subled_info,
312a522531f6e5 Antheas Kapenekakis 2025-03-24 699 leds->mc_led.num_colors = ARRAY_SIZE(leds->subled_info),
312a522531f6e5 Antheas Kapenekakis 2025-03-24 700 leds->subled_info[0].color_index = LED_COLOR_ID_RED;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 701 leds->subled_info[1].color_index = LED_COLOR_ID_GREEN;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 702 leds->subled_info[2].color_index = LED_COLOR_ID_BLUE;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 703
312a522531f6e5 Antheas Kapenekakis 2025-03-24 704 INIT_WORK(&drvdata->kbd_backlight->work, asus_kbd_work);
315c537068a13f Pietro Borrello 2023-02-12 705 spin_lock_init(&drvdata->kbd_backlight->lock);
af22a610bc3850 Carlo Caione 2017-04-06 706
d37db2009c913c Antheas Kapenekakis 2025-03-24 707 ret = asus_hid_register_listener(&drvdata->kbd_backlight->listener);
312a522531f6e5 Antheas Kapenekakis 2025-03-24 708 no_led = !!ret;
d37db2009c913c Antheas Kapenekakis 2025-03-24 709
312a522531f6e5 Antheas Kapenekakis 2025-03-24 710 if (drvdata->quirks & QUIRK_ROG_NKEY_RGB) {
312a522531f6e5 Antheas Kapenekakis 2025-03-24 711 ret = devm_led_classdev_multicolor_register(
312a522531f6e5 Antheas Kapenekakis 2025-03-24 712 &hdev->dev, &leds->mc_led);
312a522531f6e5 Antheas Kapenekakis 2025-03-24 713 if (!ret)
312a522531f6e5 Antheas Kapenekakis 2025-03-24 714 leds->rgb_registered = true;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 715 no_led &= !!ret;
312a522531f6e5 Antheas Kapenekakis 2025-03-24 716 }
312a522531f6e5 Antheas Kapenekakis 2025-03-24 717
312a522531f6e5 Antheas Kapenekakis 2025-03-24 718 if (no_led) {
af22a610bc3850 Carlo Caione 2017-04-06 719 /* No need to have this still around */
af22a610bc3850 Carlo Caione 2017-04-06 720 devm_kfree(&hdev->dev, drvdata->kbd_backlight);
af22a610bc3850 Carlo Caione 2017-04-06 721 }
af22a610bc3850 Carlo Caione 2017-04-06 722
312a522531f6e5 Antheas Kapenekakis 2025-03-24 723 return no_led ? -ENODEV : 0;
af22a610bc3850 Carlo Caione 2017-04-06 724 }
af22a610bc3850 Carlo Caione 2017-04-06 725 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v4 09/11] HID: asus: add basic RGB support
My email is not doing too well it seems. It is not just yours Luke. Hopefully my shared host does not bite me for abusing the IP
Quoted 15 lines · kernel test robot
Hi Antheas,
kernel test robot noticed the following build errors:
[auto build test ERROR on
38fec10eb60d687e30c8c6b5420d86e8149f7557]url: https://github.com/intel-lab-lkp/linux/commits/Antheas-Kapenekakis/HID-asus-refactor-init-sequence-per-spec/20250325-051852 base: 38fec10eb60d687e30c8c6b5420d86e8149f7557 patch link: https://lore.kernel.org/r/20250324210151.6042-10-lkml%40antheas.dev patch subject: [PATCH v4 09/11] HID: asus: add basic RGB support config: riscv-randconfig-002-20250325 (https://download.01.org/0day-ci/archive/20250325/[email protected]/config) compiler: riscv64-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250325/[email protected]/reproduce)
Quoted 10 lines
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/All errors (new ones prefixed by >>):
riscv64-linux-ld:
drivers/hid/hid-asus.o: in function `asus_kbd_register_leds':Quoted 1 line
Quoted 1 line
drivers/hid/hid-asus.c:676:(.text+0x23f8): undefined reference to `devm_led_classdev_multicolor_register_ext'
Since I have been getting this error by test robot often, what is the canonical way to check that KConfig is correct before sending patches?
I will try to fix the KConfig and send it later today
Antheas
Quoted 88 lines
vim +676
drivers/hid/hid-asus.c312a522531f6e5 Antheas Kapenekakis 2025-03-24 645 af22a610bc3850 Carlo Caione 2017-04-06 646 static int asus_kbd_register_leds(struct hid_device *hdev) af22a610bc3850 Carlo Caione 2017-04-06 647 { af22a610bc3850 Carlo Caione 2017-04-06 648 struct asus_drvdata *drvdata = hid_get_drvdata(hdev); af22a610bc3850 Carlo Caione 2017-04-06 649 unsigned char kbd_func; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 650 struct asus_kbd_leds *leds; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 651 bool no_led; af22a610bc3850 Carlo Caione 2017-04-06 652 int ret; af22a610bc3850 Carlo Caione 2017-04-06 653 2c82a7b20f7b7a Luke D. Jones 2024-04-16 654 ret = asus_kbd_init(hdev, FEATURE_KBD_REPORT_ID); 2c82a7b20f7b7a Luke D. Jones 2024-04-16 655 if (ret < 0) 2c82a7b20f7b7a Luke D. Jones 2024-04-16 656 return ret; 2c82a7b20f7b7a Luke D. Jones 2024-04-16 657 3ebfeb18b44e01 Antheas Kapenekakis 2025-03-24 658 /* Get keyboard functions */ 3ebfeb18b44e01 Antheas Kapenekakis 2025-03-24 659 ret = asus_kbd_get_functions(hdev, &kbd_func, FEATURE_KBD_REPORT_ID); b92b80246e0626 Luke D Jones 2020-10-27 660 if (ret < 0) b92b80246e0626 Luke D Jones 2020-10-27 661 return ret; 53078a736fbc60 Luke D. Jones 2025-01-11 662 53078a736fbc60 Luke D. Jones 2025-01-11 663 if (dmi_match(DMI_PRODUCT_FAMILY, "ProArt P16")) { 53078a736fbc60 Luke D. Jones 2025-01-11 664 ret = asus_kbd_disable_oobe(hdev); 53078a736fbc60 Luke D. Jones 2025-01-11 665 if (ret < 0) 53078a736fbc60 Luke D. Jones 2025-01-11 666 return ret; 53078a736fbc60 Luke D. Jones 2025-01-11 667 } af22a610bc3850 Carlo Caione 2017-04-06 668 af22a610bc3850 Carlo Caione 2017-04-06 669 /* Check for backlight support */ af22a610bc3850 Carlo Caione 2017-04-06 670 if (!(kbd_func & SUPPORT_KBD_BACKLIGHT)) af22a610bc3850 Carlo Caione 2017-04-06 671 return -ENODEV; af22a610bc3850 Carlo Caione 2017-04-06 672 af22a610bc3850 Carlo Caione 2017-04-06 673 drvdata->kbd_backlight = devm_kzalloc(&hdev->dev, af22a610bc3850 Carlo Caione 2017-04-06 674 sizeof(struct asus_kbd_leds), af22a610bc3850 Carlo Caione 2017-04-06 675 GFP_KERNEL); af22a610bc3850 Carlo Caione 2017-04-06 @676 if (!drvdata->kbd_backlight) af22a610bc3850 Carlo Caione 2017-04-06 677 return -ENOMEM; af22a610bc3850 Carlo Caione 2017-04-06 678 312a522531f6e5 Antheas Kapenekakis 2025-03-24 679 leds = drvdata->kbd_backlight; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 680 leds->removed = false; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 681 leds->brightness = 3; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 682 leds->hdev = hdev; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 683 leds->listener.brightness_set = asus_kbd_listener_set; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 684 312a522531f6e5 Antheas Kapenekakis 2025-03-24 685 leds->rgb_colors[0] = 0; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 686 leds->rgb_colors[1] = 0; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 687 leds->rgb_colors[2] = 0; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 688 leds->rgb_init = true; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 689 leds->rgb_set = false; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 690 leds->mc_led.led_cdev.name = devm_kasprintf(&hdev->dev, GFP_KERNEL, 312a522531f6e5 Antheas Kapenekakis 2025-03-24 691 "asus-%s:rgb:peripheral", 312a522531f6e5 Antheas Kapenekakis 2025-03-24 692 strlen(hdev->uniq) ? 312a522531f6e5 Antheas Kapenekakis 2025-03-24 693 hdev->uniq : dev_name(&hdev->dev)); 312a522531f6e5 Antheas Kapenekakis 2025-03-24 694 leds->mc_led.led_cdev.flags = LED_BRIGHT_HW_CHANGED; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 695 leds->mc_led.led_cdev.max_brightness = 3, 312a522531f6e5 Antheas Kapenekakis 2025-03-24 696 leds->mc_led.led_cdev.brightness_set = asus_kbd_brightness_set, 312a522531f6e5 Antheas Kapenekakis 2025-03-24 697 leds->mc_led.led_cdev.brightness_get = asus_kbd_brightness_get, 312a522531f6e5 Antheas Kapenekakis 2025-03-24 698 leds->mc_led.subled_info = leds->subled_info, 312a522531f6e5 Antheas Kapenekakis 2025-03-24 699 leds->mc_led.num_colors = ARRAY_SIZE(leds->subled_info), 312a522531f6e5 Antheas Kapenekakis 2025-03-24 700 leds->subled_info[0].color_index = LED_COLOR_ID_RED; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 701 leds->subled_info[1].color_index = LED_COLOR_ID_GREEN; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 702 leds->subled_info[2].color_index = LED_COLOR_ID_BLUE; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 703 312a522531f6e5 Antheas Kapenekakis 2025-03-24 704 INIT_WORK(&drvdata->kbd_backlight->work, asus_kbd_work); 315c537068a13f Pietro Borrello 2023-02-12 705 spin_lock_init(&drvdata->kbd_backlight->lock); af22a610bc3850 Carlo Caione 2017-04-06 706 d37db2009c913c Antheas Kapenekakis 2025-03-24 707 ret = asus_hid_register_listener(&drvdata->kbd_backlight->listener); 312a522531f6e5 Antheas Kapenekakis 2025-03-24 708 no_led = !!ret; d37db2009c913c Antheas Kapenekakis 2025-03-24 709 312a522531f6e5 Antheas Kapenekakis 2025-03-24 710 if (drvdata->quirks & QUIRK_ROG_NKEY_RGB) { 312a522531f6e5 Antheas Kapenekakis 2025-03-24 711 ret = devm_led_classdev_multicolor_register( 312a522531f6e5 Antheas Kapenekakis 2025-03-24 712 &hdev->dev, &leds->mc_led); 312a522531f6e5 Antheas Kapenekakis 2025-03-24 713 if (!ret) 312a522531f6e5 Antheas Kapenekakis 2025-03-24 714 leds->rgb_registered = true; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 715 no_led &= !!ret; 312a522531f6e5 Antheas Kapenekakis 2025-03-24 716 } 312a522531f6e5 Antheas Kapenekakis 2025-03-24 717 312a522531f6e5 Antheas Kapenekakis 2025-03-24 718 if (no_led) { af22a610bc3850 Carlo Caione 2017-04-06 719 /* No need to have this still around */ af22a610bc3850 Carlo Caione 2017-04-06 720 devm_kfree(&hdev->dev, drvdata->kbd_backlight); af22a610bc3850 Carlo Caione 2017-04-06 721 } af22a610bc3850 Carlo Caione 2017-04-06 722 312a522531f6e5 Antheas Kapenekakis 2025-03-24 723 return no_led ? -ENODEV : 0; af22a610bc3850 Carlo Caione 2017-04-06 724 } af22a610bc3850 Carlo Caione 2017-04-06 725--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Jiri Kosina
maintainerRe: [PATCH v4 09/11] HID: asus: add basic RGB support
Quoted 17 lines · Antheas Kapenekakis
Quoted 17 lines
[auto build test ERROR on
38fec10eb60d687e30c8c6b5420d86e8149f7557]url: https://github.com/intel-lab-lkp/linux/commits/Antheas-Kapenekakis/HID-asus-refactor-init-sequence-per-spec/20250325-051852 base: 38fec10eb60d687e30c8c6b5420d86e8149f7557 patch link: https://lore.kernel.org/r/20250324210151.6042-10-lkml%40antheas.dev patch subject: [PATCH v4 09/11] HID: asus: add basic RGB support config: riscv-randconfig-002-20250325 (https://download.01.org/0day-ci/archive/20250325/[email protected]/config) compiler: riscv64-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250325/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/All errors (new ones prefixed by >>):
Quoted 8 lines
Quoted 3 lines
riscv64-linux-ld:
drivers/hid/hid-asus.o: in function `asus_kbd_register_leds':Quoted 1 line
Quoted 1 line
drivers/hid/hid-asus.c:676:(.text+0x23f8): undefined reference to `devm_led_classdev_multicolor_register_ext'
Since I have been getting this error by test robot often, what is the canonical way to check that KConfig is correct before sending patches?
I will try to fix the KConfig and send it later today
You either need to add driver's dependency on LEDS_CLASS_MULTICOLOR, or ifdef those parts out in case it's not set.
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs
Ilpo Järvinen
maintainerRe: [PATCH v4 09/11] HID: asus: add basic RGB support
In reply to Antheas KapenekakisQuoted 32 lines · Antheas Kapenekakis
Adds basic RGB support to hid-asus through multi-index. The interface works quite well, but has not gone through much stability testing. Applied on demand, if userspace does not touch the RGB sysfs, not even initialization is done. Ensuring compatibility with existing userspace programs.
Signed-off-by Antheas Kapenekakis <[email protected]>--- drivers/hid/hid-asus.c | 169 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 155 insertions(+), 14 deletions(-)drivers/hid/hid-asus.c +2
-0@@ -30,6 +30,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/led-class-multicolor.h> #include <linux/leds.h> #include "hid-ids.h" @@ -85,6 +86,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");#define QUIRK_ROG_NKEY_KEYBOARD BIT(11)#define QUIRK_ROG_CLAYMORE_II_KEYBOARD BIT(12)#define QUIRK_HANDLE_GENERIC BIT(13) +#define QUIRK_ROG_NKEY_RGB BIT(14)#define I2C_KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \ QUIRK_NO_INIT_REPORTS | \
drivers/hid/hid-asus.c MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad"); · line 107
Quoted 9 lines
drivers/hid/hid-asus.c +3
-0@@ -97,9 +99,15 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");struct asus_kbd_leds {struct asus_hid_listener listener; +struct led_classdev_mc mc_led; +struct mc_subled subled_info[3 ];struct hid_device *hdev;struct work_struct work;unsigned int brightness; +uint8_t rgb_colors[3 ];
u8
Quoted 80 lines
drivers/hid/hid-asus.c +52
-5+bool rgb_init; +bool rgb_set; +bool rgb_registered;spinlock_t lock;bool removed; };@@ -504,23 +512,67 @@ static void asus_schedule_work(struct asus_kbd_leds *led)spin_unlock_irqrestore (&led->lock, flags); } -static void asus_kbd_backlight_set (struct asus_hid_listener *listener, +static void do_asus_kbd_backlight_set (struct asus_kbd_leds *led,int brightness) +{ +unsigned long flags; + +spin_lock_irqsave (&led->lock, flags); + led->brightness = brightness; +spin_unlock_irqrestore (&led->lock, flags); + +asus_schedule_work (led); +} + +static void asus_kbd_listener_set (struct asus_hid_listener *listener,int brightness) { struct asus_kbd_leds *led = container_of(listener, struct asus_kbd_leds, listener); +do_asus_kbd_backlight_set (led, brightness); +if (led->rgb_registered) { + led->mc_led.led_cdev.brightness = brightness; +led_classdev_notify_brightness_hw_changed (&led->mc_led.led_cdev, + brightness); + } +} + +static void asus_kbd_brightness_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct led_classdev_mc *mc_cdev =lcdev_to_mccdev (led_cdev); + struct asus_kbd_leds *led = container_of(mc_cdev, struct asus_kbd_leds, + mc_led);unsigned long flags;spin_lock_irqsave (&led->lock, flags); - led->brightness = brightness; + led->rgb_colors[0 ] = mc_cdev->subled_info[0 ].intensity; + led->rgb_colors[1 ] = mc_cdev->subled_info[1 ].intensity; + led->rgb_colors[2 ] = mc_cdev->subled_info[2 ].intensity; + led->rgb_set = true;spin_unlock_irqrestore (&led->lock, flags); -asus_schedule_work (led); +do_asus_kbd_backlight_set (led, brightness); +} + +static enum led_brightness asus_kbd_brightness_get (struct led_classdev *led_cdev) +{ +struct led_classdev_mc *mc_led; +struct asus_kbd_leds *led; +enum led_brightness brightness; +unsigned long flags; + + mc_led =lcdev_to_mccdev (led_cdev); + led = container_of(mc_led, struct asus_kbd_leds, mc_led); + +spin_lock_irqsave (&led->lock, flags); + brightness = led->brightness; +spin_unlock_irqrestore (&led->lock, flags); + +return brightness; } -static void asus_kbd_backlight_work (struct work_struct *work) +static void asus_kbd_backlight_work (struct asus_kbd_leds *led) { - struct asus_kbd_leds *led = container_of(work, struct asus_kbd_leds, work);u8 buf[] = {FEATURE_KBD_REPORT_ID ,0xba ,0xc5 ,0xc4 ,0x00 };int ret;unsigned long flags;
drivers/hid/hid-asus.c static void asus_kbd_backlight_work(struct work_struct *work) · line 591
Quoted 6 lines
drivers/hid/hid-asus.c +3
-0@@ -534,10 +586,69 @@ static void asus_kbd_backlight_work(struct work_struct *work)hid_err (led->hdev,"Asus failed to set keyboard backlight: %d\n" , ret); } +static void asus_kbd_rgb_work (struct asus_kbd_leds *led) +{ +u8 rgb_buf[][7 ] = {
Magic 7 should be named with a define.
drivers/hid/hid-asus.c static void asus_kbd_backlight_work(struct work_struct *work) · line 597
Quoted 6 lines
drivers/hid/hid-asus.c +6
-0+ { FEATURE_KBD_LED_REPORT_ID1, 0xB3 }, /* set mode */ + { FEATURE_KBD_LED_REPORT_ID1, 0xB5 }, /* apply mode */ + { FEATURE_KBD_LED_REPORT_ID1, 0xB4 }, /* save to mem */ + }; +unsigned long flags; +uint8_t colors[3 ];
uint*_t should be used only for uapi. Please use u8 for in kernel variables.
Quoted 22 lines
drivers/hid/hid-asus.c +22
-0+bool rgb_init, rgb_set; +int ret; + +spin_lock_irqsave (&led->lock, flags); + rgb_init = led->rgb_init; + rgb_set = led->rgb_set; + led->rgb_set = false; + colors[0 ] = led->rgb_colors[0 ]; + colors[1 ] = led->rgb_colors[1 ]; + colors[2 ] = led->rgb_colors[2 ]; +spin_unlock_irqrestore (&led->lock, flags); + +if (!rgb_set) +return ; + +if (rgb_init) { + ret =asus_kbd_init (led->hdev,FEATURE_KBD_LED_REPORT_ID1 ); +if (ret <0 ) { +hid_err (led->hdev,"Asus failed to init RGB: %d\n" , ret); +return ; + } +spin_lock_irqsave (&led->lock, flags);
drivers/hid/hid-asus.c static void asus_kbd_backlight_work(struct work_struct *work) · line 629
Quoted 10 lines
drivers/hid/hid-asus.c +10
-0+ led->rgb_init = false; +spin_unlock_irqrestore (&led->lock, flags); + } + +/* Protocol is: 54b3 zone (0=all) mode (0=solid) RGB */ + rgb_buf[0 ][4 ] = colors[0 ]; + rgb_buf[0 ][5 ] = colors[1 ]; + rgb_buf[0 ][6 ] = colors[2 ]; + +for (size_t i =0 ; i <ARRAY_SIZE (rgb_buf); i++) {
Add include for ARRAY_SIZE()
Quoted 27 lines
drivers/hid/hid-asus.c +18
-0+ ret =asus_kbd_set_report (led->hdev, rgb_buf[i],sizeof (rgb_buf[i])); +if (ret <0 ) { +hid_err (led->hdev,"Asus failed to set RGB: %d\n" , ret); +return ; + } + } +} + +static void asus_kbd_work (struct work_struct *work) +{ + struct asus_kbd_leds *led = container_of(work, struct asus_kbd_leds, + work); +asus_kbd_backlight_work (led); +asus_kbd_rgb_work (led); +} +static int asus_kbd_register_leds (struct hid_device *hdev) {struct asus_drvdata *drvdata =hid_get_drvdata (hdev);unsigned char kbd_func; +struct asus_kbd_leds *leds; +bool no_led;int ret; ret =asus_kbd_init (hdev,FEATURE_KBD_REPORT_ID );@@ -565,21 +676,51 @@ static int asus_kbd_register_leds(struct hid_device *hdev)if (!drvdata->kbd_backlight)
drivers/hid/hid-asus.c static int asus_kbd_register_leds(struct hid_device *hdev) · line 681
Quoted 10 lines
drivers/hid/hid-asus.c +3
-5return -ENOMEM ; - drvdata->kbd_backlight->removed = false; - drvdata->kbd_backlight->brightness =0 ; - drvdata->kbd_backlight->hdev = hdev; - drvdata->kbd_backlight->listener.brightness_set = asus_kbd_backlight_set; -INIT_WORK (&drvdata->kbd_backlight->work, asus_kbd_backlight_work); + leds = drvdata->kbd_backlight; + leds->removed = false; + leds->brightness =3 ;
Use the max brightness define here?
drivers/hid/hid-asus.c static int asus_kbd_register_leds(struct hid_device *hdev) · line 692
Quoted 11 lines
drivers/hid/hid-asus.c +11
-0+ leds->hdev = hdev; + leds->listener.brightness_set = asus_kbd_listener_set; + + leds->rgb_colors[0 ] =0 ; + leds->rgb_colors[1 ] =0 ; + leds->rgb_colors[2 ] =0 ; + leds->rgb_init = true; + leds->rgb_set = false; + leds->mc_led.led_cdev.name = devm_kasprintf(&hdev->dev, GFP_KERNEL, + "asus-%s:rgb:peripheral", + strlen(hdev->uniq) ?
hdev->uniq[0] ?
drivers/hid/hid-asus.c static int asus_kbd_register_leds(struct hid_device *hdev) · line 695
Quoted 3 lines
drivers/hid/hid-asus.c +3
-0+ hdev->uniq : dev_name(&hdev->dev)); + leds->mc_led.led_cdev.flags =LED_BRIGHT_HW_CHANGED ; + leds->mc_led.led_cdev.max_brightness = 3,
Max brightness define.
drivers/hid/hid-asus.c static int asus_kbd_register_leds(struct hid_device *hdev) · line 708
Quoted 13 lines
drivers/hid/hid-asus.c +10
-0+ leds->mc_led.led_cdev.brightness_set = asus_kbd_brightness_set, + leds->mc_led.led_cdev.brightness_get = asus_kbd_brightness_get, + leds->mc_led.subled_info = leds->subled_info, + leds->mc_led.num_colors =ARRAY_SIZE (leds->subled_info), + leds->subled_info[0 ].color_index =LED_COLOR_ID_RED ; + leds->subled_info[1 ].color_index =LED_COLOR_ID_GREEN ; + leds->subled_info[2 ].color_index =LED_COLOR_ID_BLUE ; + +INIT_WORK (&drvdata->kbd_backlight->work, asus_kbd_work);spin_lock_init (&drvdata->kbd_backlight->lock); ret =asus_hid_register_listener (&drvdata->kbd_backlight->listener); + no_led = !!ret;
Assigning to bool doesn't require !!.
drivers/hid/hid-asus.c static int asus_kbd_register_leds(struct hid_device *hdev) · line 712
Quoted 4 lines
drivers/hid/hid-asus.c +4
-0+ +if (drvdata->quirks &QUIRK_ROG_NKEY_RGB ) { + ret =devm_led_classdev_multicolor_register ( + &hdev->dev, &leds->mc_led);
IMO, this could go to one line (it's only 87 chars long). At minimum, the first arg fits to the first line.
drivers/hid/hid-asus.c static int asus_kbd_register_leds(struct hid_device *hdev) · line 715
Quoted 3 lines
drivers/hid/hid-asus.c +3
-0+if (!ret) + leds->rgb_registered = true; + no_led &= !!ret;
No !!
drivers/hid/hid-asus.c static int asus_kbd_register_leds(struct hid_device *hdev) · line 723
Quoted 10 lines
drivers/hid/hid-asus.c +3
-2+ } -if (ret <0 ) { +if (no_led) {/* No need to have this still around */ devm_kfree (&hdev->dev, drvdata->kbd_backlight); } -return ret; +return no_led ? -ENODEV :0 ;
Introduction of no_led leads to shadowing error code which is usually undesirable. What's the reason you don't want to pass the original ret code onward?
If you have a good reason for it, please documented it in the commit message and preferrably make that change own change so it can focus on that thing only. It would also make the diff here cleaner.
Quoted 22 lines
drivers/hid/hid-asus.c +2
-2}/* @@ -1289,7 +1430,7 @@ static const struct hid_device_id asus_devices[] = { QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, {HID_USB_DEVICE (USB_VENDOR_ID_ASUSTEK ,USB_DEVICE_ID_ASUSTEK_ROG_Z13_LIGHTBAR ), - QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_ROG_NKEY_RGB }, { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,USB_DEVICE_ID_ASUSTEK_ROG_NKEY_ALLY ), QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD },@@ -1318,7 +1459,7 @@ static const struct hid_device_id asus_devices[] = {*/ {HID_DEVICE (BUS_USB ,HID_GROUP_GENERIC ,USB_VENDOR_ID_ASUSTEK ,USB_DEVICE_ID_ASUSTEK_ROG_Z13_FOLIO ), - QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_ROG_NKEY_RGB }, { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_T101HA_KEYBOARD) }, { }
Signature · 1 line
i.
PATCH v4 10/11 HID: asus: add RGB support to the ROG Ally units
In reply to Antheas KapenekakisApply the RGB quirk to the QOG Ally units to enable basic RGB support.
--- drivers/hid/hid-asus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hid/hid-asus.c +2 -2
@@ -1433,10 +1433,10 @@ static const struct hid_device_id asus_devices[] = { QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_ROG_NKEY_RGB }, {HID_USB_DEVICE (USB_VENDOR_ID_ASUSTEK ,USB_DEVICE_ID_ASUSTEK_ROG_NKEY_ALLY ), - QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_ROG_NKEY_RGB }, { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,USB_DEVICE_ID_ASUSTEK_ROG_NKEY_ALLY_X ), - QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_ROG_NKEY_RGB }, { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,USB_DEVICE_ID_ASUSTEK_ROG_CLAYMORE_II_KEYBOARD ), QUIRK_ROG_CLAYMORE_II_KEYBOARD },
Signature · 1 line
2.49.0
PATCH v4 11/11 HID: asus: initialize LED endpoint early for old NKEY keyboards
In reply to Antheas KapenekakisThese keyboards have always had initialization in the kernel for 0x5d. At this point, it is hard to verify again and we risk regressions by removing this. Therefore, initialize with 0x5d, and skip RGB initialization if that is enabled.
--- drivers/hid/hid-asus.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
drivers/hid/hid-asus.c +17 -4
@@ -87,6 +87,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");#define QUIRK_ROG_CLAYMORE_II_KEYBOARD BIT(12)#define QUIRK_HANDLE_GENERIC BIT(13)#define QUIRK_ROG_NKEY_RGB BIT(14) +#define QUIRK_ROG_NKEY_LEGACY BIT(15)#define I2C_KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \ QUIRK_NO_INIT_REPORTS | \
@@ -648,13 +649,25 @@ static int asus_kbd_register_leds(struct hid_device *hdev)struct asus_drvdata *drvdata =hid_get_drvdata (hdev);unsigned char kbd_func;struct asus_kbd_leds *leds; -bool no_led; +bool no_led, rgb_init = true;int ret; ret =asus_kbd_init (hdev,FEATURE_KBD_REPORT_ID );if (ret <0 )return ret; +if (drvdata->quirks &QUIRK_ROG_NKEY_LEGACY ) { +/* +* These keyboards might need 0x5d for shortcuts to work. +* As it has been more than 5 years, it is hard to verify. +*/ + ret =asus_kbd_init (hdev,FEATURE_KBD_LED_REPORT_ID1 ); +if (ret <0 ) +return ret; + + rgb_init = false; + } +/* Get keyboard functions */ ret =asus_kbd_get_functions (hdev, &kbd_func,FEATURE_KBD_REPORT_ID );if (ret <0 )
@@ -685,7 +698,7 @@ static int asus_kbd_register_leds(struct hid_device *hdev) leds->rgb_colors[0 ] =0 ; leds->rgb_colors[1 ] =0 ; leds->rgb_colors[2 ] =0 ; - leds->rgb_init = true; + leds->rgb_init = rgb_init; leds->rgb_set = false; leds->mc_led.led_cdev.name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "asus-%s:rgb:peripheral",
@@ -1424,10 +1437,10 @@ static const struct hid_device_id asus_devices[] = { QUIRK_USE_KBD_BACKLIGHT }, {HID_USB_DEVICE (USB_VENDOR_ID_ASUSTEK ,USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD ), - QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_ROG_NKEY_LEGACY }, { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD2 ), - QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_ROG_NKEY_LEGACY }, { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK,USB_DEVICE_ID_ASUSTEK_ROG_Z13_LIGHTBAR ), QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_ROG_NKEY_RGB },
Signature · 1 line
2.49.0