From patchwork Mon Mar 24 21:01:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 875861 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D12BB190462; Mon, 24 Mar 2025 21:08:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742850511; cv=none; b=FYcbsHEFyBRad2CrMuJjtyHV7n4jv655kQHYMzgc2EI+3SNY26aApd8qnrid2PVMRBxc52hm5HfY5J5Q87DA01TGOgP/wNks5TzXqwvJNWGMifcryCmkaN6R8czNRpneo6BcqRS7ssfU7MQeUUjCCGbyB7ik5UsSyxtpNKAP4/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742850511; c=relaxed/simple; bh=ZD3wx4hNUz9BZe1/e+hobcWMQ+fpJHCUnKBkTo77P6Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QJw6TZQ4OFYf2Rz4G1+e0WjkvXnoRczBxRPhdKzuUNQEKvrZcZWKeJ0Yn7JdOn3FiRBkuQrzfjA4CEIbY1LoPplG5jUbWjs7UluZv85kT86ZOq40tfrfUfH7vg9G2eki3dl8NQe7AooHm617W2T0xjM0hpdEo9hVY7M5VCQA4qM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=XLbIkTzk; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="XLbIkTzk" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id A87E12E09D8F; Mon, 24 Mar 2025 23:02:03 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1742850125; bh=kOiMKB/AIMqxzK9oXdhi8MBWksAEM6at8+RYbcDHfEc=; h=From:To:Subject; b=XLbIkTzkwpKb8OyChZzP60fYA4RBvEz+tK8x+DJVCF168awwZVLxR0viPDqUy5Gyh sYBxH7StU5+UvYOu5wvg8OaLCHDwjhISBSjwGBDRSHk+Zf3GCzeO3/7ZZfLcsahmGB fnpUOGUTia4S1h6i0c0DJRlx++3+9WB9vxPmKFsg= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a05:f6c2:511b:0:cbc0:999f:73ad:33bd) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: platform-driver-x86@vger.kernel.org, linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , Corentin Chary , "Luke D . Jones" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Antheas Kapenekakis Subject: [PATCH v4 01/11] HID: asus: refactor init sequence per spec Date: Mon, 24 Mar 2025 22:01:41 +0100 Message-ID: <20250324210151.6042-2-lkml@antheas.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250324210151.6042-1-lkml@antheas.dev> References: <20250324210151.6042-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <174285012484.21685.17753773909563545833@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean 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. Signed-off-by: Antheas Kapenekakis --- drivers/hid/hid-asus.c | 82 +++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index 46e3e42f9eb5f..8d4df1b6f143b 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -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 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 }; + /* + * 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); From patchwork Mon Mar 24 21:01:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 875866 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D8641E3762; Mon, 24 Mar 2025 21:02:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742850132; cv=none; b=a8Cdwo36h4bwd0y0Wp085cnlZ6buUOggtY3A4a5BR3y893RXS92xl/4uuln9Z2ZZ0gf7Hi4b2+t5oGjytMIETsl9sK4dYCQQPHNFIHxlgh3gLyjkGhY9u1qunpHEdsyHNZy5aokpyt1PJBimyX8Uc2dmc18UkGStNi7/8YjI8KA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742850132; c=relaxed/simple; bh=H/Y3NmzdKKzvRN929LX+yUdAUn+O07TRj6qCPSEDLDM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tarwrDQ9oOXOsgR1kavj2K1s9po2NqO54vPpntC9vb7DXcGitE05EpP5Y/JGABYKQe/zFLiWjOum9j7HM4IpTio/S8QCkDFXns+2JfYirlahJdG5vW/dN1l8PdRlOu36nc2T/VO0MQnonsmoO3xsX9whx1HVlqzzgIAa6Y+3w4M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=shkY+AgI; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="shkY+AgI" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 63D752E09D75; Mon, 24 Mar 2025 23:02:05 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1742850126; bh=0XK3YQnxiL3OEcNEf4aKgNDNIEWkM7EnJOdDjVojKBc=; h=From:To:Subject; b=shkY+AgI9oPUqOsl43/I9ADydaxX5Iv5auPyaBE2VgNch8QiUNaDd9gW6zQuTKhWc 2sJoo7IdS2EJ8gU+jLEY/P2LP8DV7GvbAQU8TWVqYO96K2FHSKuMW8vAvvC/krPlfm 0R9AnKeQt9GpAXgubko+bsAdbfjHY5PVSod49btM= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a05:f6c2:511b:0:cbc0:999f:73ad:33bd) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: platform-driver-x86@vger.kernel.org, linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , Corentin Chary , "Luke D . Jones" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Antheas Kapenekakis Subject: [PATCH v4 02/11] HID: asus: prevent binding to all HID devices on ROG Date: Mon, 24 Mar 2025 22:01:42 +0100 Message-ID: <20250324210151.6042-3-lkml@antheas.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250324210151.6042-1-lkml@antheas.dev> References: <20250324210151.6042-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <174285012667.22876.17082709125197395445@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean 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). Reviewed-by: Luke D. Jones Signed-off-by: Antheas Kapenekakis --- drivers/hid/hid-asus.c | 69 ++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index 8d4df1b6f143b..96461321c191c 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -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"); From patchwork Mon Mar 24 21:01:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 875865 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E11A18B464; Mon, 24 Mar 2025 21:02:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742850134; cv=none; b=tbKtmCsq7fiU3CyOmy7OV12cc/JHroMNj9AzbXwb8NS8k39Tfyx7dq5FEoPZcVjzPBi0Shu0r/zi+zMHd91rZDsjY6ceW+SlyRA+gXx1TXSG3rIFrJqGg91KurDpxIYMGIm/0CZBytA4BaTOqGTO7fEIGnwSvtAkNOcosMqq3jc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742850134; c=relaxed/simple; bh=McfPLinrI0UIGMPTJCpquK06WbMzxn0Fz1pp5+lKrN4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m4/kdhkcb0LH3L+j7fkorBKY0C51N8dIZeB7anhWDuWHCPSw4jmTSJChwhqqXWmvZZs6gDtv3LojcQkFMueGNwx3/GtFf2/PKl04efCaK44+WC1tSSpbR9Y0qIFvBbzeI3J7YM/A48DHulKfoAyZpjk4c/gROEXmMXQG7WRfZkQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=dYfZjPSs; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="dYfZjPSs" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id AA95F2E09D97; Mon, 24 Mar 2025 23:02:08 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1742850130; bh=3e4rHQpsDEsDnd8v9T2vzddRYWY1i6Z2uoxlKsEJHsM=; h=From:To:Subject; b=dYfZjPSsYX3ohgR6GlEgOb/+kC8ewjUDMNDszYpcN0n+3d5gsRXMwzrIDc0mVCidC WxSYxoWHUZPM5oN4hyBa2UIcdBNJ+xkdmsCe1NW3r2bS6ZR2PiFhvQbqF+KUbgIIso V8rIRDFzIdPC0OL9ZgDE6EIJZtMgg8E0/H0aMgdw= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a05:f6c2:511b:0:cbc0:999f:73ad:33bd) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: platform-driver-x86@vger.kernel.org, linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , Corentin Chary , "Luke D . Jones" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Antheas Kapenekakis Subject: [PATCH v4 04/11] platform/x86: asus-wmi: Add support for multiple kbd RGB handlers Date: Mon, 24 Mar 2025 22:01:44 +0100 Message-ID: <20250324210151.6042-5-lkml@antheas.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250324210151.6042-1-lkml@antheas.dev> References: <20250324210151.6042-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <174285012978.23088.6500408720132805208@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean 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. Reviewed-by: Luke D. Jones Tested-by: Luke D. Jones Signed-off-by: Antheas Kapenekakis --- drivers/platform/x86/asus-wmi.c | 118 ++++++++++++++++++--- include/linux/platform_data/x86/asus-wmi.h | 16 +++ 2 files changed, 121 insertions(+), 13 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 38ef778e8c19b..ff1d7ccb3982f 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -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)) { diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index 783e2a336861b..ec8b0c585a63f 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -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 */ From patchwork Mon Mar 24 21:01:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 875864 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCC091EF0B9; Mon, 24 Mar 2025 21:02:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742850136; cv=none; b=DdbL6S50EPPxal1DAVNLhWN+T4GcNylL9wsZrWeUB2rxNXYVe5UnDEJn4f0OA/cyyGrhVjlWlEYRBUdkEmrh7vUkS0Gtw5IYl1wCNxZkbMQ6Eelv34q/7DqQTTyflJtANl8Df99Dq5OLyFruqqVtMvoJ//8L5lCN8AKAIN7XwQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742850136; c=relaxed/simple; bh=BygUYtcHC1IOlX6moh+kyyRPEQgYoFGQtll23Vkk43w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JW0pJUTenqyJ18W/zqVuZdGDsLfiSVe+hGOYw86yIlkZPX9A+B/G1PwyyuZHLGI5pBHiLK0JJnm7UAP9EZHjclV8jkRZ2Qj0I9QhNArGwhza0xiLQwuE18CProGKYo1nWxiGUH/7pbhnGyimcrHRobthumMwSILIL0OIPpbgKlc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=YsP7Okpr; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="YsP7Okpr" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id BE6EF2E09D99; Mon, 24 Mar 2025 23:02:11 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1742850133; bh=KpxnHdWM8D2D/jh5HMKpqy9RmSSrb7wZeUDfWEFML2Y=; h=From:To:Subject; b=YsP7OkprP8icsD1DC+3kzVkNsS9vOww8qJ7jiI3WtdbTLEhJlTLfUV5OtwFjkcDc6 /hDXo7QzjL11pNvk0mdkJ8tU3SF6eYK/xKFY7hnjsoyCLn0suuVDYMttjYfqJuBvzd zZjvPvWoXYdnFREv+HC7ZuOngBdH5xUqT4gojlwo= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a05:f6c2:511b:0:cbc0:999f:73ad:33bd) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: platform-driver-x86@vger.kernel.org, linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , Corentin Chary , "Luke D . Jones" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Antheas Kapenekakis Subject: [PATCH v4 06/11] platform/x86: asus-wmi: remove unused keyboard backlight quirk Date: Mon, 24 Mar 2025 22:01:46 +0100 Message-ID: <20250324210151.6042-7-lkml@antheas.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250324210151.6042-1-lkml@antheas.dev> References: <20250324210151.6042-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <174285013284.23328.13618271856619638031@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean The quirk for selecting whether keyboard backlight should be controlled by HID or WMI is not needed anymore, so remove it. Reviewed-by: Luke D. Jones Signed-off-by: Antheas Kapenekakis --- include/linux/platform_data/x86/asus-wmi.h | 40 ---------------------- 1 file changed, 40 deletions(-) diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index ec8b0c585a63f..c513b5a732323 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -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 */ From patchwork Mon Mar 24 21:01:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 875863 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACB261F1518; Mon, 24 Mar 2025 21:02:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742850140; cv=none; b=tcNw8Ydcd0ig95GJOclOeEDBVQ80aXaDkz8AnN4PacuxAatsrAzC06PRNoAgN8bzPhshNw5fXinrt4B+gOr4QuysugKrHJGMAjkVUYlf9R/iqEpLc6mDcdf0oFETT7HWEqHzwUIK8ktKqUfxy6PGcAcMICAY3dmF9wmnRaomw9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742850140; c=relaxed/simple; bh=EAZJWYvWbWYXu2Qch2ZOhtRMQVg1W6inZG8gAyFhZH8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c3/l3Ogig0WiXHqTnNnU1ifthm3B4cASOPFQqdTFGhml063gW9sEofEE7UuQb5fWZg0cW5OToVk+vCzRg46qjdJCCamnJuyCrOjrXj6io4csgthUWVmxK3vwSj16JnYNKA5bt40h0Y3HsPnte6HxFWjvjkF90xy5KDDDynwo/Jk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=EHkxcbsm; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="EHkxcbsm" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 094BB2E09DAA; Mon, 24 Mar 2025 23:02:14 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1742850136; bh=uHc6A/5Tddhr9d1X2hQfj7VNMzeN9xMO6fbLvovs/fg=; h=From:To:Subject; b=EHkxcbsmzEOkpQydLAAEsPSQTRAbUMLC5XT9Ey4b72cSuS/x51p5UDujxHO5qYPGr lICAV2thKrDc+vaR6ClBz2Ewgc8T923w3HNTGFgMNjbBvBOgw5tX3KLz0PgPKeL3ji CcrtjfMR9s6KudAK4weuYQCqJCkUlDUBzqKVM6m8= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a05:f6c2:511b:0:cbc0:999f:73ad:33bd) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: platform-driver-x86@vger.kernel.org, linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , Corentin Chary , "Luke D . Jones" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Antheas Kapenekakis Subject: [PATCH v4 08/11] HID: asus: add support for the asus-wmi brightness handler Date: Mon, 24 Mar 2025 22:01:48 +0100 Message-ID: <20250324210151.6042-9-lkml@antheas.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250324210151.6042-1-lkml@antheas.dev> References: <20250324210151.6042-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <174285013617.23580.10245558916576077403@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean 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. Reviewed-by: Luke D. Jones Tested-by: Luke D. Jones Signed-off-by: Antheas Kapenekakis --- drivers/hid/hid-asus.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index c40b5c14c797f..905453a4eb5b7 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -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; } From patchwork Mon Mar 24 21:01:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 875862 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC7D11FAC4E; Mon, 24 Mar 2025 21:02:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742850143; cv=none; b=fzGg5W9NSAiWrBa5nM8aE+mm+n/aYvNWudihUIJ08pJPUe5okabQoloVrds3WKWFduoPK9paMPbNZYfjUjhxiz1oyzfrHFZgFFocBVd+M9/ebB0WVvKUwx+E4OlSzKK7joPwqoDIBA1T+xmwEXl679czDD6RgVVpVsY4h7SgSdU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742850143; c=relaxed/simple; bh=a/cCK5Wge9QuIbtaZ2mmyMgmsunD0YU8KMFqH0xm+ZI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BIJICGYz2iUhLIIrBikIQNOqw5oFzVQRLARLRrCfKedNyG4YVdm+EBWAyHI+rJSAx1PCgkIzT01wTdf7Brmf8KPCToQq7KLKkhYYI72fnVT2okNeJ4pUYVjLzDHvAHu7uK8PSbOBgMfucZ+L+QSVdFSZ9H+DUKUQpg7vawEjlYk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=KO0LRS7+; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="KO0LRS7+" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 474C72E09DA0; Mon, 24 Mar 2025 23:02:18 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1742850139; bh=n0aD/DdSdrx2B65x8nHA8pettZ7OcIh2qaRfe8ZVuHU=; h=From:To:Subject; b=KO0LRS7+rILsLfsvrueKEDG+TCHQQ67WkRMVyJck4e/3B/7E2UM8fS0KTwyHA8Jtk T8l8+a9T1WCC4uA+lMHFu5IEzfKWqsKZiUTNPnbTmS3KVZAp7kpCMMr5nrPedwKhAV aBLIyN+7Hz42N409+9LSCNL184kNJldupAUcU2wM= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a05:f6c2:511b:0:cbc0:999f:73ad:33bd) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: platform-driver-x86@vger.kernel.org, linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , Corentin Chary , "Luke D . Jones" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Antheas Kapenekakis Subject: [PATCH v4 10/11] HID: asus: add RGB support to the ROG Ally units Date: Mon, 24 Mar 2025 22:01:50 +0100 Message-ID: <20250324210151.6042-11-lkml@antheas.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250324210151.6042-1-lkml@antheas.dev> References: <20250324210151.6042-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <174285013932.23812.6923666193104179547@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean Apply the RGB quirk to the QOG Ally units to enable basic RGB support. Reviewed-by: Luke D. Jones Signed-off-by: Antheas Kapenekakis --- drivers/hid/hid-asus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index 3ac1e2dea45bb..7025c6971431d 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -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 },