From patchwork Tue Mar 25 18:45:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 876166 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 8A27A1ACEAF; Tue, 25 Mar 2025 18:46:13 +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=1742928375; cv=none; b=ExWPBf1ni/y88dKJL1EKk9Q+MucxNxw6HpQ3+zjqbZLtDTbpE7e09pdepEcrhuFsEuzzxEJG5Z5HXWk21hhJHGmYpkLqgV+KGJqpFGV4LofsMOBks0edPYFMODh+cdFU9SfRjzx6FT79H+vX5J9aiLFs1wMGbTi4puD3txm5O6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742928375; c=relaxed/simple; bh=xaUGb+diGmllD/MR/PUUhg9ZanRMgEuo/FIr//rXLF8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lf67uccRKkb6HiNgvLIf7793/DHTxiQT3Xg1E0aKi85HtFiWlSdaE/y/RCir9siyAqSHyuwiuWbNeR7OwP7qeCAx/F2PpgFbaF9nnbCMJxhL6W8W5cqLwxszrDehXsGsr+9sUPfQtBHNj89ZeUC23YoanPdpAdA0s13pZpfJd54= 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=V28Hcl4c; 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="V28Hcl4c" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id E97DF2E0932D; Tue, 25 Mar 2025 20:46:08 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1742928370; bh=hChOQ20vCYiy3vvs3LCq5MPJ+0GUXF9+zvDSw0MqvLM=; h=From:To:Subject; b=V28Hcl4ccV9qPYczOA5uIybEpIsf5X5rJS+yRUlnxPikiroWKAEfRepS58odhW6yK Sbr0h6hQTvCS7g18KAt9e33a40CktJ4knKsXf0x9lwKJvRRAVLR37+tqgzAOPMdPv1 m36lMDQqkm1k1tA3r/IBMqQJ+mztHzaSoyOOdR+M= 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 v5 02/11] HID: asus: prevent binding to all HID devices on ROG Date: Tue, 25 Mar 2025 19:45:51 +0100 Message-ID: <20250325184601.10990-3-lkml@antheas.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250325184601.10990-1-lkml@antheas.dev> References: <20250325184601.10990-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: <174292836997.7747.7165150432821297937@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, 52 insertions(+), 17 deletions(-) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index 47f0a7cb46c80..7269ddc690bca 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -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"); From patchwork Tue Mar 25 18:45:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 876165 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 6DEE11F3B9D; Tue, 25 Mar 2025 18:46:16 +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=1742928378; cv=none; b=IIWqgqrbj/eHuInrCjhMsDBObDdl1pIs3NtzQGWyle4geXvMpcGT3Cg8DY8KyZ94/5sBnnaxWWcrTaP6kZR2qkMyojg3KsxgEpkbk3cSgZO9wNAGR6K9nyFGXnC7OUwgR1uM78k+RJe8BkztrEVKwNeIzbV+3SYi2YcFYPcnH4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742928378; c=relaxed/simple; bh=McfPLinrI0UIGMPTJCpquK06WbMzxn0Fz1pp5+lKrN4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S94gY7UviFMmjTIOI1i/xbCGXEImOjV9DmLJxUhaJjDrkT30KT1hekU3yxOmIVIp7bYGamCl5vmwuETYyfSAJYAIrNjMZicj0V37KddYpOtZRI89+LOi/Tiw0ZIwUtU4T+q0cwncPrMvDm/R8vrWJWfmYABMt5nxuBDfk+D5U4Y= 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=Syci9klb; 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="Syci9klb" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id CB0542E098AF; Tue, 25 Mar 2025 20:46:12 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1742928374; bh=3e4rHQpsDEsDnd8v9T2vzddRYWY1i6Z2uoxlKsEJHsM=; h=From:To:Subject; b=Syci9klbEuWsQ0eyIDfAJVf5bxLRD5Z1RASdVKYRreFNJRSlyew8uzE7BIzi4zf1d eapHvWpw+NPaQW83fvTV8kcdmG+ZwvqHpg5BWu2fasa2VpXOK5J8+Wb48Y4VHMyq47 B7iDRzeIc+uBaM6HAY0q9W+bowNsZyMHFAWdjPxs= 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 v5 04/11] platform/x86: asus-wmi: Add support for multiple kbd RGB handlers Date: Tue, 25 Mar 2025 19:45:53 +0100 Message-ID: <20250325184601.10990-5-lkml@antheas.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250325184601.10990-1-lkml@antheas.dev> References: <20250325184601.10990-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: <174292837388.7894.5496627901896805367@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 Tue Mar 25 18:45:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 876164 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 7E8101F419C; Tue, 25 Mar 2025 18:46:20 +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=1742928382; cv=none; b=ENQiar58wX6Vu2j7qkvimzTjjKyUgrmdgD8KNyoMfolqnmNgFmeNgjW8cknlvKcmOuZo7qRtniXaCGFCbIAElb7UbBN64Tp6rzTKrSEpRPpLL7P+b6sdAKH9hHf3iw7f4HHC2jjJ1HzBn6dqSv3uH2sH7TzK87//yn8YA2xoHAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742928382; c=relaxed/simple; bh=BygUYtcHC1IOlX6moh+kyyRPEQgYoFGQtll23Vkk43w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dzKz76rutQjpcGOZLhs8jlC64eb1VsHY5wdUFZJGaoapiz3j8jw5KWXvljFQTqP5lB7BgSD53G6i59L2MfopLOn6YMUMsMIrxKgHXc3R9bbQAOjrDpbF2Ezr+3nTmL5Ut5NlFcGlz5jZzlVU60/OdLyHx4cdHWENp+uwhBqfsWE= 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=1eUyE8cd; 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="1eUyE8cd" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 18FD92E098B3; Tue, 25 Mar 2025 20:46:17 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1742928378; bh=KpxnHdWM8D2D/jh5HMKpqy9RmSSrb7wZeUDfWEFML2Y=; h=From:To:Subject; b=1eUyE8cdejY7a9Vu8mX9HP6JmA1BB9OnbmVkiPn/jsmugRIWiOGssFL0/OJmj4gON bWq1erHW4hg0DjgPfsvDnmvOglSgaM4f9dRWegMcSh0zaIERrAaE0Y84El8OTjN1pe CK7U4Zl69CT4GRgMnt6Sf2Jyf2ZABzMSnNI4Eulg= 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 v5 06/11] platform/x86: asus-wmi: remove unused keyboard backlight quirk Date: Tue, 25 Mar 2025 19:45:55 +0100 Message-ID: <20250325184601.10990-7-lkml@antheas.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250325184601.10990-1-lkml@antheas.dev> References: <20250325184601.10990-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: <174292837817.8085.7106803137935381120@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 Tue Mar 25 18:45:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 876163 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 D29AE1F4CA3; Tue, 25 Mar 2025 18:46:23 +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=1742928385; cv=none; b=jLiX+CKKrXDp9qR7Y1DYstXEtaap44zsVjhngdQZma9G+KOcFHU08iaM5IGXQWHXENHhyHBZtGLxXncDLfqV42QlGR7wUmx/kmr47VZunAWHS7LNhr7f8g/FbaRnBs/LJyALaM5vcJbNVBSQlkVid8Z33b7zmG3P8FBrlW2ck14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742928385; c=relaxed/simple; bh=W9pJLnhFIf35zkQo9rH4p0zSE24DwlGqtwqFEiB/7SE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DvR5HwwE46SS8pmsv6WvZlR08VsVhTYZoNBNOYw8GnYwEOhqhu3mUNwtAci26aSWAh9KKor6o174wMCrOEFIDUo0XhGPbDzlWhaG9AcHs/9kr+Hsk2C0MuWdP16ca9VuMmUoUdjDyLgkikDrffW3sjtaph/wAXs2DHIqhYvRP3M= 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=olRXy8MT; 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="olRXy8MT" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 2DD4D2E098C2; Tue, 25 Mar 2025 20:46:20 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1742928381; bh=y58s2NqoOSS0+r/7Q1xuFckUs2twj7CZeSEpPojWvFk=; h=From:To:Subject; b=olRXy8MTAiED9m6+i/K/xwL+2g2bLuXoMD0D2NBHJVToQlL28Pf1Tdu4aIfG8+6wj o9lh6ZEguB10FricSuXzjyu2Uwfpk/LkLqsnSlQgsPDb7rLPzH1QXMuneOm/pPw7yJ hAq5CSM+6Irr1OpaWhSIb/pegRKJR81C+NcER7A0= 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 v5 08/11] HID: asus: add support for the asus-wmi brightness handler Date: Tue, 25 Mar 2025 19:45:57 +0100 Message-ID: <20250325184601.10990-9-lkml@antheas.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250325184601.10990-1-lkml@antheas.dev> References: <20250325184601.10990-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: <174292838126.8204.16548926258215420829@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 9497e11577f93..a4d1160460935 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -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; } From patchwork Tue Mar 25 18:45:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 876162 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 30B8E1F5840; Tue, 25 Mar 2025 18:46:26 +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=1742928388; cv=none; b=SeZXBV7Lai5z/cgoNPWcngqIItXjb+xhcryE8nR4Hjir38/7WKwf8Sdx1vtAf15Yr0r5w8zy5hU6pArNk7+hDSu9ptJcvjMuF88TONXEoIdw9eaP0FEXuUVlYxZgRVgkkgqk4Pmt03ECTwpKsdQ6lUnUcwgiXWFVrsuljPs7yKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742928388; c=relaxed/simple; bh=taFbeucJn+ckNBISe/bgtmxWdZL30X56uRuLp385a00=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UD59YD6gxOwOis41406+l6abI5uJP/KJsM23EnxQ7Z54Sp1hMFpZ19UzJOxk+om2TmUWm3QRaXw8bodM76zK83ExtVlz5e4W71Cca20tAlnfiSOTX6MI3IblWzGPhV2QbkMUC1Tp/qnh4zcgvRd5tgs1JBHsCVAw1vmzYTly7tg= 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=42WRz7fy; 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="42WRz7fy" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id AFAC52E098CC; Tue, 25 Mar 2025 20:46:23 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1742928385; bh=D4LvuHsVvzT6ncv5a3kKSTQhMfeftQdCgXF8DdE5Ol4=; h=From:To:Subject; b=42WRz7fyIBMaoUFgmPN/7MK1RxbmvXGw5QRHV+FQkFBW+gEHcNmHNMwl+y9tU0afu 6wrlCSulMSVYU642azHDjd3OWQs+HYZw4ayCvX1KBXSYIxwPouzf2Wmo1SZTbGxQiX o6nBCpkb7dG/Y9fKzxmVlZf1AsELSdU3Rjra3NbU= 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 v5 10/11] HID: asus: add RGB support to the ROG Ally units Date: Tue, 25 Mar 2025 19:45:59 +0100 Message-ID: <20250325184601.10990-11-lkml@antheas.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250325184601.10990-1-lkml@antheas.dev> References: <20250325184601.10990-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: <174292838479.8353.14432007376216030493@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 c135c9ff87b74..fa8ec237efe26 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -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 },