Skip to contentSkip to conversation

HID: asus: Add RGB Support to Asus Z13, Ally, unify backlight asus-wmi, and Z13 QOL

PATCH Superseded Antheas Kapenekakis 5 participants 23 messages Mar 25, 2025 – Apr 10, 2025

Subsystems (3)

v5 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v5 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.

---
V4: https://lore.kernel.org/lkml/[email protected]/
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 V4:
- Fix KConfig (reported by kernel robot)
- Fix Ilpo's nits, if I missed anything lmk

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/Kconfig                        |   1 +
 drivers/hid/hid-asus.c                     | 359 +++++++++++++++------
 drivers/hid/hid-ids.h                      |   2 +-
 drivers/platform/x86/asus-wmi.c            | 157 ++++++++-
 include/linux/platform_data/x86/asus-wmi.h |  69 ++--
 5 files changed, 435 insertions(+), 153 deletions(-)

base-commit: 38fec10eb60d687e30c8c6b5420d86e8149f7557

Signature · 1 line
2.49.0
#1 lore raw

PATCH v5 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 | 78 +++++++++++++++++++++++-------------------
 1 file changed, 42 insertions(+), 36 deletions(-)
drivers/hid/hid-asus.c +42 -36
index 46e3e42f9eb5f..47f0a7cb46c80 100644
@@ -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,37 @@ static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t bu
 
 static 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 };
+	/*
+	 * The handshake is first sent as a set_report, then retrieved
+	 * from a get_report. They should be equal.
+	 */
+	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_warn(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 +440,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 +563,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
#2 lore raw

PATCH v5 2/11 HID: asus: prevent binding to all HID devices on ROG

In reply to 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_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, 52 insertions(+), 17 deletions(-)
drivers/hid/hid-asus.c +52 -17
index 47f0a7cb46c80..7269ddc690bca 100644
@@ -47,6 +47,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
 #define T100CHI_MOUSE_REPORT_ID 0x06
 #define FEATURE_REPORT_ID 0x0d
 #define INPUT_REPORT_ID 0x5d
+#define HID_USAGE_PAGE_VENDOR 0xff310000
 #define FEATURE_KBD_REPORT_ID 0x5a
 #define FEATURE_KBD_REPORT_SIZE 64
 #define FEATURE_KBD_LED_REPORT_ID1 0x5d
@@ -84,6 +85,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 +122,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;
@@ -311,7 +312,7 @@ static int asus_e1239t_event(struct asus_drvdata *drvdat, u8 *data, int size)
 static int asus_event(struct hid_device *hdev, struct hid_field *field,
 		      struct hid_usage *usage, __s32 value)
 {
-	if ((usage->hid & HID_USAGE_PAGE) == 0xff310000 &&
+	if ((usage->hid & HID_USAGE_PAGE) == HID_USAGE_PAGE_VENDOR &&
 	    (usage->hid & HID_USAGE) != 0x00 &&
 	    (usage->hid & HID_USAGE) != 0xff && !usage->type) {
 		hid_warn(hdev, "Unmapped Asus vendor usagepage code 0x%02x\n",
@@ -326,6 +327,10 @@ static int asus_raw_event(struct hid_device *hdev,
 {
 	struct asus_drvdata *drvdata = hid_get_drvdata(hdev);
 
+	/* NOOP on generic HID devices to avoid side effects. */
+	if (drvdata->quirks & QUIRK_HANDLE_GENERIC)
+		return 0;
+
 	if (drvdata->battery && data[0] == BATTERY_REPORT_ID)
 		return asus_report_battery(drvdata, data, size);
 
@@ -770,6 +775,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);
 
+	/* NOOP on generic HID devices to avoid side effects. */
+	if (drvdata->quirks & QUIRK_HANDLE_GENERIC)
+		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)
@@ -823,11 +832,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;
 }
 
@@ -847,6 +851,10 @@ static int asus_input_mapping(struct hid_device *hdev,
 		return -1;
 	}
 
+	/* NOOP on generic HID devices to avoid side effects. */
+	if (drvdata->quirks & QUIRK_HANDLE_GENERIC)
+		return 0;
+
 	/*
 	 * Ignore a bunch of bogus collections in the T100CHI descriptor.
 	 * This avoids a bunch of non-functional hid_input devices getting
@@ -897,15 +905,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;
 	}
@@ -1022,8 +1021,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) {
@@ -1107,12 +1108,42 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)
 		return ret;
 	}
 
+	/* Check for vendor for RGB init 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) == HID_USAGE_PAGE_VENDOR)
+			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;
@@ -1163,6 +1194,10 @@ static const __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc,
 {
 	struct asus_drvdata *drvdata = hid_get_drvdata(hdev);
 
+	/* NOOP on generic HID devices to avoid side effects. */
+	if (drvdata->quirks & QUIRK_HANDLE_GENERIC)
+		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
#3 lore raw

PATCH v5 3/11 HID: asus: add Z13 folio to generic group for multitouch to work

In reply to Antheas Kapenekakis

The 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
index 7269ddc690bca..7f070474ef8b4 100644
@@ -1313,9 +1313,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 },
@@ -1345,6 +1342,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
index 7e400624908e3..b1fe7582324ff 100644
@@ -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
#4 lore raw

PATCH v5 4/11 platform/x86: asus-wmi: Add support for multiple kbd RGB handlers

In reply to Antheas Kapenekakis

Some 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
index 38ef778e8c19b..ff1d7ccb3982f 100644
@@ -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
index 783e2a336861b..ec8b0c585a63f 100644
@@ -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
#5 lore raw

Re: [PATCH v5 04/11] platform/x86: asus-wmi: Add support for multiple kbd RGB handlers

kernel test robot noticed the following build warnings:

Hi Antheas,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 38fec10eb60d687e30c8c6b5420d86e8149f7557]

url:    https://github.com/intel-lab-lkp/linux/commits/Antheas-Kapenekakis/HID-asus-refactor-init-sequence-per-spec/20250326-025845
base:   38fec10eb60d687e30c8c6b5420d86e8149f7557
patch link:    https://lore.kernel.org/r/20250325184601.10990-5-lkml%40antheas.dev
patch subject: [PATCH v5 04/11] platform/x86: asus-wmi: Add support for multiple kbd RGB handlers
config: i386-randconfig-062-20250326 (https://download.01.org/0day-ci/archive/20250327/[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/20250327/[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]/

sparse warnings: (new ones prefixed by >>)

>> drivers/platform/x86/asus-wmi.c:1498:21: sparse: sparse: symbol 'asus_ref' was not declared. Should it be static?

drivers/platform/x86/asus-wmi.c:2576:33: sparse: sparse: incorrect type in argument 3 (different base types) @@ expected unsigned int [usertype] val @@ got restricted __le32 [usertype] @@
drivers/platform/x86/asus-wmi.c:2576:33: sparse: expected unsigned int [usertype] val
drivers/platform/x86/asus-wmi.c:2576:33: sparse: got restricted __le32 [usertype]

vim +/asus_ref +1498 drivers/platform/x86/asus-wmi.c

1497

> 1498	struct asus_hid_ref asus_ref = {

1499 .listeners = LIST_HEAD_INIT(asus_ref.listeners),
1500 .asus = NULL,
1501 .lock = __SPIN_LOCK_UNLOCKED(asus_ref.lock),
1502 };
1503

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#6 lore raw

PATCH v5 5/11 HID: asus: listen to the asus-wmi brightness device instead of creating one

In reply to 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 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 | 64 +++++++-----------------------------------
 1 file changed, 10 insertions(+), 54 deletions(-)
drivers/hid/hid-asus.c +10 -54
index 7f070474ef8b4..9497e11577f93 100644
@@ -97,7 +97,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;
@@ -490,11 +490,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);
@@ -504,20 +504,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);
@@ -534,34 +520,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);
@@ -596,14 +554,11 @@ 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);
@@ -997,7 +952,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);
@@ -1133,7 +1088,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");
 
@@ -1174,6 +1128,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
#7 lore raw

PATCH v5 6/11 platform/x86: asus-wmi: remove unused keyboard backlight quirk

In reply to Antheas Kapenekakis

The 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
index ec8b0c585a63f..c513b5a732323 100644
@@ -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
#8 lore raw

PATCH v5 7/11 platform/x86: asus-wmi: add keyboard brightness event handler

In reply to 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.

---
 drivers/platform/x86/asus-wmi.c            | 41 +++++++++++++++++++++-
 include/linux/platform_data/x86/asus-wmi.h | 13 +++++++
 2 files changed, 53 insertions(+), 1 deletion(-)
drivers/platform/x86/asus-wmi.c +40 -1
index ff1d7ccb3982f..64185e3f55000 100644
@@ -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 >= ASUS_EV_MAX_BRIGHTNESS)
+			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
@@ -1835,7 +1874,7 @@ static int asus_wmi_led_init(struct asus_wmi *asus)
 	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.max_brightness = ASUS_EV_MAX_BRIGHTNESS;
 	asus->kbd_led_avail = !kbd_led_read(asus, &led_val, NULL);
 
 	if (asus->kbd_led_avail)
include/linux/platform_data/x86/asus-wmi.h +13 -0
index c513b5a732323..b051cd089c6d0 100644
@@ -162,11 +162,20 @@ 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,
+};
+
+#define ASUS_EV_MAX_BRIGHTNESS 3
+
 #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 +190,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
#9 lore raw

PATCH v5 8/11 HID: asus: add support for the asus-wmi brightness handler

In reply to Antheas Kapenekakis

If 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
index 9497e11577f93..a4d1160460935 100644
@@ -319,6 +319,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
#10 lore raw

PATCH v5 9/11 HID: asus: add basic RGB support

In reply to 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.

---
 drivers/hid/Kconfig    |   1 +
 drivers/hid/hid-asus.c | 171 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 156 insertions(+), 16 deletions(-)
drivers/hid/Kconfig +1 -0
index dfc245867a46a..d324c6ab997de 100644
@@ -151,6 +151,7 @@ config HID_APPLEIR
 config HID_ASUS
 	tristate "Asus"
 	depends on USB_HID
+	depends on LEDS_CLASS_MULTICOLOR
 	depends on LEDS_CLASS
 	depends on ASUS_WMI || ASUS_WMI=n
 	select POWER_SUPPLY
drivers/hid/hid-asus.c +155 -16

255 lines not on this page · raw message

Signature · 1 line
2.49.0
maintainer
#11 lore raw

Re: [PATCH v5 09/11] HID: asus: add basic RGB support

Quoted 150 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.

---
 drivers/hid/Kconfig    |   1 +
 drivers/hid/hid-asus.c | 171 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 156 insertions(+), 16 deletions(-)
drivers/hid/Kconfig +1 -0
index dfc245867a46a..d324c6ab997de 100644
@@ -151,6 +151,7 @@ config HID_APPLEIR
 config HID_ASUS
 	tristate "Asus"
 	depends on USB_HID
+	depends on LEDS_CLASS_MULTICOLOR
 	depends on LEDS_CLASS
 	depends on ASUS_WMI || ASUS_WMI=n
 	select POWER_SUPPLY
drivers/hid/hid-asus.c +59 -5
index a4d1160460935..c135c9ff87b74 100644
@@ -23,6 +23,7 @@
 /*
  */
 
+#include <linux/array_size.h>
 #include <linux/dmi.h>
 #include <linux/hid.h>
 #include <linux/module.h>
@@ -30,6 +31,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"
@@ -52,6 +54,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
 #define FEATURE_KBD_REPORT_SIZE 64
 #define FEATURE_KBD_LED_REPORT_ID1 0x5d
 #define FEATURE_KBD_LED_REPORT_ID2 0x5e
+#define FEATURE_KBD_LED_REPORT_SIZE 7
 
 #define SUPPORT_KBD_BACKLIGHT BIT(0)
 
@@ -86,6 +89,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 | \
@@ -98,9 +102,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;
+	u8 rgb_colors[3];
+	bool rgb_init;
+	bool rgb_set;
+	bool rgb_registered;
 	spinlock_t lock;
 	bool removed;
 };
@@ -501,23 +511,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 593

Quoted 9 lines
drivers/hid/hid-asus.c +6 -0
@@ -531,10 +585,68 @@ 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[][FEATURE_KBD_LED_REPORT_SIZE] = {
+		{ 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 */

Hmm, I don't know why I didn't notice this the last scan... Since you're anyway adding those comments to explain the literals (I assume), wouldn't it be simply better to add defines for 0xB* and forgo the comments.

Usually when one adds any comment, it's always good to ask first oneself if things could be named such that the code itself explains itself. This leaves comments mostly for places where something really odd/tricky/complex occurs as the rest can be covered by simply naming better.

Quoted 20 lines
drivers/hid/hid-asus.c +20 -0
+	};
+	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);

drivers/hid/hid-asus.c static void asus_kbd_backlight_work(struct work_struct *work) · line 623

Quoted 10 lines
drivers/hid/hid-asus.c +10 -0
+		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 */

BTW, this comment is very cryptic to me and I'm unable to connect it with the code below. My only guess is that each non-parenthesized word is explaining one index but things don't add up given what rgb_buf[0][0] and [0][1] have.

Quoted 63 lines
drivers/hid/hid-asus.c +47 -5
+	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;
 	int ret;
 
 	ret = asus_kbd_init(hdev, FEATURE_KBD_REPORT_ID);
@@ -562,20 +674,47 @@ 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 = ASUS_EV_MAX_BRIGHTNESS;
+	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 = ASUS_EV_MAX_BRIGHTNESS;
+	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;
+

drivers/hid/hid-asus.c static int asus_kbd_register_leds(struct hid_device *hdev) · line 708

Quoted 10 lines
drivers/hid/hid-asus.c +4 -3
+	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);
-	if (ret < 0) {
-		/* No need to have this still around */
-		devm_kfree(&hdev->dev, drvdata->kbd_backlight);
+	/* Asus-wmi might not be accessible so this is not fatal. */
+	if (!ret)
+		hid_warn(hdev, "Asus-wmi brightness listener not registered\n");

Is the condition correct way around given the message?

Please also note that you don't need to send an update every day or so after minor comments like this. We're in merge window currently which means I likely won't be applying any next material until -rc1 has been released.

Quoted 31 lines
drivers/hid/hid-asus.c +8 -3
+	if (drvdata->quirks & QUIRK_ROG_NKEY_RGB) {
+		ret = devm_led_classdev_multicolor_register(&hdev->dev, &leds->mc_led);
+		if (!ret)
+			leds->rgb_registered = true;
+		return ret;
 	}
 
-	return ret;
+	return 0;
 }
 
 /*
@@ -1282,7 +1421,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 },
@@ -1311,7 +1450,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.
#12 lore raw

Re: [PATCH v5 09/11] HID: asus: add basic RGB support

Quoted 167 lines · Ilpo Järvinen
Quoted 150 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.

---
 drivers/hid/Kconfig    |   1 +
 drivers/hid/hid-asus.c | 171 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 156 insertions(+), 16 deletions(-)
drivers/hid/Kconfig +1 -0
index dfc245867a46a..d324c6ab997de 100644
@@ -151,6 +151,7 @@ config HID_APPLEIR
 config HID_ASUS
      tristate "Asus"
      depends on USB_HID
+     depends on LEDS_CLASS_MULTICOLOR
      depends on LEDS_CLASS
      depends on ASUS_WMI || ASUS_WMI=n
      select POWER_SUPPLY
drivers/hid/hid-asus.c +59 -5
index a4d1160460935..c135c9ff87b74 100644
@@ -23,6 +23,7 @@
 /*
  */
 
+#include <linux/array_size.h>
 #include <linux/dmi.h>
 #include <linux/hid.h>
 #include <linux/module.h>
@@ -30,6 +31,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"
@@ -52,6 +54,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
 #define FEATURE_KBD_REPORT_SIZE 64
 #define FEATURE_KBD_LED_REPORT_ID1 0x5d
 #define FEATURE_KBD_LED_REPORT_ID2 0x5e
+#define FEATURE_KBD_LED_REPORT_SIZE 7
 
 #define SUPPORT_KBD_BACKLIGHT BIT(0)
 
@@ -86,6 +89,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 | \
@@ -98,9 +102,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;
+     u8 rgb_colors[3];
+     bool rgb_init;
+     bool rgb_set;
+     bool rgb_registered;
      spinlock_t lock;
      bool removed;
 };
@@ -501,23 +511,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 593

Quoted 9 lines
drivers/hid/hid-asus.c +6 -0
@@ -531,10 +585,68 @@ 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[][FEATURE_KBD_LED_REPORT_SIZE] = {
+             { 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 */

Hmm, I don't know why I didn't notice this the last scan... Since you're anyway adding those comments to explain the literals (I assume), wouldn't it be simply better to add defines for 0xB* and forgo the comments.

Quoted 5 lines

Usually when one adds any comment, it's always good to ask first oneself if things could be named such that the code itself explains itself. This leaves comments mostly for places where something really odd/tricky/complex occurs as the rest can be covered by simply naming better.

I guess I can turn them into FEATURE_KBD_LED_CMD_SETMODE etc.

Quoted 27 lines
Quoted 27 lines
drivers/hid/hid-asus.c +27 -0
+     };
+     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);
Quoted 8 lines

drivers/hid/hid-asus.c static void asus_kbd_backlight_work(struct work_struct *work) · line 623

Quoted 3 lines
drivers/hid/hid-asus.c +3 -0
+     }
+
+     /* Protocol is: 54b3 zone (0=all) mode (0=solid) RGB */

BTW, this comment is very cryptic to me and I'm unable to connect it with the code below. My only guess is that each non-parenthesized word is explaining one index but things don't add up given what rgb_buf[0][0] and [0][1] have.

Maybe i fatfingered 54 and it should be 5a. Protocol is 54b3 zone mode R G B. So colors go to indexes 4, 5, 6

Quoted 66 lines
Quoted 66 lines
drivers/hid/hid-asus.c +48 -5
+     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;
      int ret;
 
      ret = asus_kbd_init(hdev, FEATURE_KBD_REPORT_ID);
@@ -562,20 +674,47 @@ 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 = ASUS_EV_MAX_BRIGHTNESS;
+     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 = ASUS_EV_MAX_BRIGHTNESS;
+     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);
 
Quoted 9 lines

drivers/hid/hid-asus.c static int asus_kbd_register_leds(struct hid_device *hdev) · line 708

Quoted 7 lines
drivers/hid/hid-asus.c +3 -3
      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);
+     /* Asus-wmi might not be accessible so this is not fatal. */
+     if (!ret)
+             hid_warn(hdev, "Asus-wmi brightness listener not registered\n");

Is the condition correct way around given the message?

You are right.

Quoted 4 lines

Please also note that you don't need to send an update every day or so after minor comments like this. We're in merge window currently which means I likely won't be applying any next material until -rc1 has been released.

If this is 6.16 material I am happy to put a pause on this for the next 1-3 weeks.

Antheas

Quoted 35 lines
Quoted 23 lines
drivers/hid/hid-asus.c +7 -2
+     if (drvdata->quirks & QUIRK_ROG_NKEY_RGB) {
+             ret = devm_led_classdev_multicolor_register(&hdev->dev, &leds->mc_led);
+             if (!ret)
+                     leds->rgb_registered = true;
+             return ret;
      }
 
-     return ret;
+     return 0;
 }
 
 /*
@@ -1282,7 +1421,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 },

drivers/hid/hid-asus.c static const struct hid_device_id asus_devices[] = { · line 1456

Quoted 8 lines
drivers/hid/hid-asus.c +1 -1
@@ -1311,7 +1450,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) },
      { }

--
i.

maintainer
#13 lore raw

Re: [PATCH v5 09/11] HID: asus: add basic RGB support

Quoted 56 lines · Antheas Kapenekakis
Quoted 45 lines · Ilpo Järvinen
Quoted 42 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.

---
 drivers/hid/Kconfig    |   1 +
 drivers/hid/hid-asus.c | 171 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 156 insertions(+), 16 deletions(-)
drivers/hid/Kconfig +27 -0
index dfc245867a46a..d324c6ab997de 100644
 
+     };
+     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);
Quoted 8 lines

drivers/hid/Kconfig

Quoted 3 lines
drivers/hid/Kconfig +3 -0
+     }
+
+     /* Protocol is: 54b3 zone (0=all) mode (0=solid) RGB */

BTW, this comment is very cryptic to me and I'm unable to connect it with the code below. My only guess is that each non-parenthesized word is explaining one index but things don't add up given what rgb_buf[0][0] and [0][1] have.

Quoted 2 lines

Maybe i fatfingered 54 and it should be 5a. Protocol is 54b3 zone mode R G B. So colors go to indexes 4, 5, 6

Ah. I suggest you add the spaces between the bytes to make it more obvious. Although, this could be a constructed as struct as well in which case the struct itself would document the format without need to cryptic comments nor use of numeric indexes.

Quoted 25 lines
Quoted 21 lines
Quoted 10 lines
drivers/hid/Kconfig +10 -0
+     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;
+             }

drivers/hid/Kconfig

Quoted 10 lines
drivers/hid/Kconfig +5 -3
+     }
+}
 
      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);
+     /* Asus-wmi might not be accessible so this is not fatal. */
+     if (!ret)
+             hid_warn(hdev, "Asus-wmi brightness listener not registered\n");
Quoted 1 line

Is the condition correct way around given the message?

You are right.

Quoted 7 lines
Quoted 4 lines

Please also note that you don't need to send an update every day or so after minor comments like this. We're in merge window currently which means I likely won't be applying any next material until -rc1 has been released.

If this is 6.16 material I am happy to put a pause on this for the next 1-3 weeks.

You don't need to "pause" for the merge window, in some subsystem there's mandatory pause during merge window but I find that unnecessary. I know people on pdx86 do review during merge window so no need to wait when working with patches related to pdx86. Just don't expect patches get applied during the merge window or right after it (the latter tends to be the most busiest time of cycle for me) :-).

It's more about the frequency, how often to send a series which is relatively large. Large number of versions end up just filling inboxes (and patchwork's pending patches list) and we don't have time to read them all through so I suggest waiting like 3 days at minimum between versions when the series is large or complex to give time to go through the series.

This is not a hard rule, so if there are e.g. many significant changes, feel free to "violate" it in that case.

Signature · 1 line
 i.
maintainer
#14 lore raw

Re: [PATCH v5 09/11] HID: asus: add basic RGB support

Quoted 7 lines · Ilpo Järvinen

You don't need to "pause" for the merge window, in some subsystem there's mandatory pause during merge window but I find that unnecessary. I know people on pdx86 do review during merge window so no need to wait when working with patches related to pdx86. Just don't expect patches get applied during the merge window or right after it (the latter tends to be the most busiest time of cycle for me) :-).

Quoted 8 lines

It's more about the frequency, how often to send a series which is relatively large. Large number of versions end up just filling inboxes (and patchwork's pending patches list) and we don't have time to read them all through so I suggest waiting like 3 days at minimum between versions when the series is large or complex to give time to go through the series.

This is not a hard rule, so if there are e.g. many significant changes, feel free to "violate" it in that case.

Exactly. I am unlikely to do much review during the merge window myself, but I'll pick up the patchset and followup once the merge window is over, so feel free to keep discussing and polishing it with me on CC :)

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#15 lore raw

Re: [PATCH v5 09/11] HID: asus: add basic RGB support

Quoted 16 lines · Jiri Kosina
Quoted 13 lines · Ilpo Järvinen

You don't need to "pause" for the merge window, in some subsystem there's mandatory pause during merge window but I find that unnecessary. I know people on pdx86 do review during merge window so no need to wait when working with patches related to pdx86. Just don't expect patches get applied during the merge window or right after it (the latter tends to be the most busiest time of cycle for me) :-).

It's more about the frequency, how often to send a series which is relatively large. Large number of versions end up just filling inboxes (and patchwork's pending patches list) and we don't have time to read them all through so I suggest waiting like 3 days at minimum between versions when the series is large or complex to give time to go through the series.

Quoted 8 lines
Quoted 2 lines

This is not a hard rule, so if there are e.g. many significant changes, feel free to "violate" it in that case.

Exactly. I am unlikely to do much review during the merge window myself, but I'll pick up the patchset and followup once the merge window is over, so feel free to keep discussing and polishing it with me on CC :)

Thanks,

I think we have reached a good point with this series. We can pick up again when you guys are ready.

I will switch gears and look a bit into msi-wmi-platform for the MSI Claw with Armin and we can revisit this come rc1.

Let's try to get through it early in 6.16 so that Luke can also do what he wants to with the Ally, and let's push the oxpec move as well, so I can get those two off my plate.

Antheas

Quoted 4 lines

--
Jiri Kosina
SUSE Labs

maintainer
#16 lore raw

Re: [PATCH v5 09/11] HID: asus: add basic RGB support

Quoted 29 lines · Antheas Kapenekakis
Quoted 16 lines · Jiri Kosina
Quoted 13 lines · Ilpo Järvinen

You don't need to "pause" for the merge window, in some subsystem there's mandatory pause during merge window but I find that unnecessary. I know people on pdx86 do review during merge window so no need to wait when working with patches related to pdx86. Just don't expect patches get applied during the merge window or right after it (the latter tends to be the most busiest time of cycle for me) :-).

It's more about the frequency, how often to send a series which is relatively large. Large number of versions end up just filling inboxes (and patchwork's pending patches list) and we don't have time to read them all through so I suggest waiting like 3 days at minimum between versions when the series is large or complex to give time to go through the series.

Quoted 8 lines
Quoted 2 lines

This is not a hard rule, so if there are e.g. many significant changes, feel free to "violate" it in that case.

Exactly. I am unlikely to do much review during the merge window myself, but I'll pick up the patchset and followup once the merge window is over, so feel free to keep discussing and polishing it with me on CC :)

Thanks,

I think we have reached a good point with this series. We can pick up again when you guys are ready.

Quoted 6 lines

I will switch gears and look a bit into msi-wmi-platform for the MSI Claw with Armin and we can revisit this come rc1.

Let's try to get through it early in 6.16 so that Luke can also do what he wants to with the Ally, and let's push the oxpec move as well, so I can get those two off my plate.

I see Ilpo and Jiri mentioned no need to pause development. But it does look like everything is in good state so far, and no doubt you might have some ideas after a few days (plus that did of helpful info asus dropped in my lap).

If you do anything significant and would like someone to test on a few variety of laptop please let me know privately and I'll do what I can.

Cheers,
Luke.

Quoted 6 lines

Antheas

Quoted 4 lines

--
Jiri Kosina
SUSE Labs

#17 lore raw

Re: [PATCH v5 09/11] HID: asus: add basic RGB support

Quoted 38 lines · Luke D. Jones
Quoted 29 lines · Antheas Kapenekakis
Quoted 16 lines · Jiri Kosina
Quoted 13 lines · Ilpo Järvinen

You don't need to "pause" for the merge window, in some subsystem there's mandatory pause during merge window but I find that unnecessary. I know people on pdx86 do review during merge window so no need to wait when working with patches related to pdx86. Just don't expect patches get applied during the merge window or right after it (the latter tends to be the most busiest time of cycle for me) :-).

It's more about the frequency, how often to send a series which is relatively large. Large number of versions end up just filling inboxes (and patchwork's pending patches list) and we don't have time to read them all through so I suggest waiting like 3 days at minimum between versions when the series is large or complex to give time to go through the series.

Quoted 8 lines
Quoted 2 lines

This is not a hard rule, so if there are e.g. many significant changes, feel free to "violate" it in that case.

Exactly. I am unlikely to do much review during the merge window myself, but I'll pick up the patchset and followup once the merge window is over, so feel free to keep discussing and polishing it with me on CC :)

Thanks,

I think we have reached a good point with this series. We can pick up again when you guys are ready.

Quoted 6 lines

I will switch gears and look a bit into msi-wmi-platform for the MSI Claw with Armin and we can revisit this come rc1.

Let's try to get through it early in 6.16 so that Luke can also do what he wants to with the Ally, and let's push the oxpec move as well, so I can get those two off my plate.

Quoted 7 lines

I see Ilpo and Jiri mentioned no need to pause development. But it does look like everything is in good state so far, and no doubt you might have some ideas after a few days (plus that did of helpful info asus dropped in my lap).

If you do anything significant and would like someone to test on a few variety of laptop please let me know privately and I'll do what I can.

Yeah, I think the comments I got so far I could fix in an hour or so, so I would like some more to pool in.

It is good we have a way to parse the keyboard check [1] now, but all this boils down to removing the RGB quirk and tweaking how the result of that function is parsed.

If you have some deadtime atm, you can check the MSI Claw draft I am working on [2]. It is still too early to send. The fwupd integration is causing some issues, such as it being picky and requiring all optional vars are implemented, and I think the potential interference with shift mode (platform profile in MSI laptops) will be confusing as well. But the same issues are present in Asus and Lenovo Legion too, so MSI is not unique in that regard.

Antheas

[1] https://github.com/torvalds/linux/blob/4e82c87058f45e79eeaa4d5bcc3b38dd3dce7209/drivers/hid/hid-asus.c#L402-L434
[2] https://github.com/bazzite-org/patchwork/tree/msi

Quoted 10 lines

Cheers,
Luke.

Quoted 6 lines

Antheas

Quoted 4 lines

--
Jiri Kosina
SUSE Labs

#18 lore raw

PATCH v5 10/11 HID: asus: add RGB support to the ROG Ally units

In reply to Antheas Kapenekakis

Apply 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
index c135c9ff87b74..fa8ec237efe26 100644
@@ -1424,10 +1424,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
maintainer
#19 lore raw

Re: [PATCH v5 10/11] HID: asus: add RGB support to the ROG Ally units

Quoted 15 lines · Antheas Kapenekakis

Apply 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 +0 -0
index c135c9ff87b74..fa8ec237efe26 100644
@@ -1424,10 +1424,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,

drivers/hid/hid-asus.c static const struct hid_device_id asus_devices[] = { · line 1433

Quoted 10 lines
drivers/hid/hid-asus.c +2 -2
  	    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 },

Hi Antheas,

I have some good news for you, ASUS got back to me, there *is* a way to get the feature level of a keyboard.

## 2.2. Configuration command

In order to confirm what functions are the USB device supported, host retrieves the configuration information by feature report method. Therefore, the firmware has to return the data (byte 0x06~) to the host.

### 2.2.1. Set feature

| Byte 0    | Byte 1    | Byte 2   | Byte 3   | Byte 4     | Byte 5  |
|-----------|-----------|----------|----------|------------|---------|
| Report ID | OP code   | Addr_L   | Addr_H   | Read ROM   | Length  |
| Report ID | 0x05      | 0x20     | 0x31     | 0x00       | 0x08    |

### 2.2.2. Get feature

| Byte 0    | Byte 1    | Byte 2   | Byte 3   | Byte 4     | Byte 5  |
|-----------|-----------|----------|----------|------------|---------|
| Report ID | 0x05      | 0x20     | 0x31     | 0x00       | 0x08    |

**Byte 6**
- 0x00: KB, 1-zone with single color
- 0x01: KB, QWERASD-partition
- 0x02: KB, 4-zone with RGB
- 0x03: KB, Per-key with RGB
- 0x04: KB, 1-zone with RGB
- Other: reserved

**Byte 7(keyboard language)**
- 0x01: US
- 0x02: UK
- 0x03: JP
- Other: reserved

I've not done anything with this myself yet, circumstances last week weren't great for me. If you implement this in driver I will ensure I get it tested as I have both single colour and rgb laptops.

What i *do* know is:

- 0x00: KB, 1-zone with single color
- 0x01: KB, QWERASD-partition
These can be standard kb_backlight

- 0x02: KB, 4-zone with RGB
- 0x03: KB, Per-key with RGB
- 0x04: KB, 1-zone with RGB
These work with the regular EC-mode RGB command for static/solid colour and you don't need to worry about zone/per-key. It would be good to document those as defines or enum or something for future.

Hope this helps.

Cheers,
Luke.

#20 lore raw

Re: [PATCH v5 10/11] HID: asus: add RGB support to the ROG Ally units

Quoted 48 lines · Luke D. Jones
Quoted 15 lines · Antheas Kapenekakis

Apply 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 +0 -0
index c135c9ff87b74..fa8ec237efe26 100644
@@ -1424,10 +1424,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,

drivers/hid/hid-asus.c static const struct hid_device_id asus_devices[] = { · line 1433

Quoted 10 lines
drivers/hid/hid-asus.c +2 -2
          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 },

Hi Antheas,

I have some good news for you, ASUS got back to me, there *is* a way to get the feature level of a keyboard.

## 2.2. Configuration command

In order to confirm what functions are the USB device supported, host retrieves the
configuration information by feature report method. Therefore, the firmware has to
return the data (byte 0x06~) to the host.

### 2.2.1. Set feature

| Byte 0    | Byte 1    | Byte 2   | Byte 3   | Byte 4     | Byte 5  |
|-----------|-----------|----------|----------|------------|---------|
| Report ID | OP code   | Addr_L   | Addr_H   | Read ROM   | Length  |
| Report ID | 0x05      | 0x20     | 0x31     | 0x00       | 0x08    |
Quoted 8 lines

### 2.2.2. Get feature

| Byte 0    | Byte 1    | Byte 2   | Byte 3   | Byte 4     | Byte 5  |
|-----------|-----------|----------|----------|------------|---------|
| Report ID | 0x05      | 0x20     | 0x31     | 0x00       | 0x08    |

**Byte 6**
- 0x00: KB, 1-zone with single color

Nice find. The asus-hid driver already implements this and checks for 0x00 to bail the backlight.

So that check should be removed as it does not work with single color keyboards and instead checked for 2,3,4 to enable RGB.

This also means removing the RGB check and getting global support in one go.

Antheas

Quoted 33 lines

- 0x01: KB, QWERASD-partition
- 0x02: KB, 4-zone with RGB
- 0x03: KB, Per-key with RGB
- 0x04: KB, 1-zone with RGB
- Other: reserved

**Byte 7(keyboard language)**
- 0x01: US
- 0x02: UK
- 0x03: JP
- Other: reserved

I've not done anything with this myself yet, circumstances last week weren't great for me. If you implement this in driver I will ensure I get it tested as I have both single colour and rgb laptops.

What i *do* know is:

- 0x00: KB, 1-zone with single color
- 0x01: KB, QWERASD-partition
These can be standard kb_backlight

- 0x02: KB, 4-zone with RGB
- 0x03: KB, Per-key with RGB
- 0x04: KB, 1-zone with RGB
These work with the regular EC-mode RGB command for static/solid colour and you don't need to worry about zone/per-key. It would be good to document those as defines or enum or something for future.

Hope this helps.

Cheers,
Luke.

#21 lore raw

Re: [PATCH v5 10/11] HID: asus: add RGB support to the ROG Ally units

Quoted 62 lines · Antheas Kapenekakis
Quoted 48 lines · Luke D. Jones
Quoted 15 lines · Antheas Kapenekakis

Apply 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 +0 -0
index c135c9ff87b74..fa8ec237efe26 100644
@@ -1424,10 +1424,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,

drivers/hid/hid-asus.c static const struct hid_device_id asus_devices[] = { · line 1433

Quoted 10 lines
drivers/hid/hid-asus.c +2 -2
          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 },

Hi Antheas,

I have some good news for you, ASUS got back to me, there *is* a way to get the feature level of a keyboard.

## 2.2. Configuration command

In order to confirm what functions are the USB device supported, host retrieves the
configuration information by feature report method. Therefore, the firmware has to
return the data (byte 0x06~) to the host.

### 2.2.1. Set feature

| Byte 0    | Byte 1    | Byte 2   | Byte 3   | Byte 4     | Byte 5  |
|-----------|-----------|----------|----------|------------|---------|
| Report ID | OP code   | Addr_L   | Addr_H   | Read ROM   | Length  |
| Report ID | 0x05      | 0x20     | 0x31     | 0x00       | 0x08    |
Quoted 8 lines

### 2.2.2. Get feature

| Byte 0    | Byte 1    | Byte 2   | Byte 3   | Byte 4     | Byte 5  |
|-----------|-----------|----------|----------|------------|---------|
| Report ID | 0x05      | 0x20     | 0x31     | 0x00       | 0x08    |

**Byte 6**
- 0x00: KB, 1-zone with single color

Nice find. The asus-hid driver already implements this and checks for 0x00 to bail the backlight.

Quoted 35 lines

So that check should be removed as it does not work with single color keyboards and instead checked for 2,3,4 to enable RGB.

This also means removing the RGB check and getting global support in one go.

Antheas

Quoted 28 lines

- 0x01: KB, QWERASD-partition
- 0x02: KB, 4-zone with RGB
- 0x03: KB, Per-key with RGB
- 0x04: KB, 1-zone with RGB
- Other: reserved

**Byte 7(keyboard language)**
- 0x01: US
- 0x02: UK
- 0x03: JP
- Other: reserved

I've not done anything with this myself yet, circumstances last week weren't great for me. If you implement this in driver I will ensure I get it tested as I have both single colour and rgb laptops.

What i *do* know is:

- 0x00: KB, 1-zone with single color
- 0x01: KB, QWERASD-partition
These can be standard kb_backlight

- 0x02: KB, 4-zone with RGB
- 0x03: KB, Per-key with RGB
- 0x04: KB, 1-zone with RGB
These work with the regular EC-mode RGB command for static/solid colour and you don't need to worry about zone/per-key. It would be good to document those as defines or enum or something for future.

Let's start slowly getting back into this.

Ok, the lightbar of the Z13 returns:
5a05203100080100010423000100060214020000000000000153550000000000

And the keyboard returns:
5a052031000801000004250501002e0000000000000000000000000000000000

That is 01 for both the lightbar and keyboard when it comes to zone (QWERASD) and 00/undefined when it comes to keyboard?

Now, if they meant byte 6 _after_ the header:
5a0520310008 01 00 01 04 23 00 01 00060214020000000000000153550000000000 5a0520310008 01 00 00 04 25 05 01 002e0000000000000000000000000000000000

It is still inconclusive

So I am unsure what to make of this

Antheas

Quoted 4 lines
Quoted 4 lines

Hope this helps.

Cheers,
Luke.

#22 lore raw

PATCH v5 11/11 HID: asus: initialize LED endpoint early for old NKEY keyboards

In reply to Antheas Kapenekakis

These 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 | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
drivers/hid/hid-asus.c +17 -3
index fa8ec237efe26..d02d0629d03cd 100644
@@ -90,6 +90,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 | \
@@ -647,12 +648,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 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)
@@ -683,7 +697,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",
@@ -1415,10 +1429,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