From patchwork Wed May 29 01:24:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 800095 Received: from wfhigh7-smtp.messagingengine.com (wfhigh7-smtp.messagingengine.com [64.147.123.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27F99632; Wed, 29 May 2024 01:24:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945899; cv=none; b=h3Llanbiw0AOkQh23whcjdBUenzLcQ9boPojCFWFfXlvtdrHPf4eKmeddGnuhQijIXOMFM9t6vRBORkDM2Dx3smUGjwOxH57b57Qk8AiPe/XppsojEBK6hkvBdQH3ntRsY7dpV0v+vinYXwJOIAj8vFSDTZzmQbNpjIe5cy0XRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945899; c=relaxed/simple; bh=EVmfaLLDsfMymrtcoYmdakMrtp5jtmrZeC5/eg/2iAk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ax7L6ON4XL5N8n9Q3tgnmYkE7x1IK39iFFwIExEp5VJLfk1wWA1giKmgfvWdoZ9bBPgZ0deN6tZZdHeVhaf6L+cMm05+0bHAKFrhZBK7Wqif4wwDqmflTzl6MLQGUOaz485IXD58LcAzmfDwm2kF1kwdNJoOa5txpyPhwTiLTYI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev; spf=none smtp.mailfrom=ljones.dev; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b=WghErmoU; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=G/Duu+4L; arc=none smtp.client-ip=64.147.123.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ljones.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b="WghErmoU"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="G/Duu+4L" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.west.internal (Postfix) with ESMTP id DB308180018D; Tue, 28 May 2024 21:24:56 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 28 May 2024 21:24:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to; s=fm2; t=1716945896; x=1717032296; bh=VnB5cSkzbTE+pF/YZXsLR qgiA9IkyhO++Upx0eRciEg=; b=WghErmoUO5OnWBFlnv0okHrkrVGQUExFb7Phi dKVRTr0GDSg5REJyfYT1M5KZ3cAYWJISneGdLH8rSJumsrCvy9uh88fGe4MT/CLE 6K1Bsi1PZx5exAVWFlOmPC6T4B6FG/fQHirawrFsfKOu8y/73+q9la0GLyFGqyG1 BPtdopstVcTRiTSlAVWrcBNqT7+zzPPzzYzTUlNiT3O0eLCWnrKl66HguhiovyWU HQnSM0hVPPVLOBnF25UjuH6pA2nJzxQEvOWoEHKkqiP9s2sHX103VAT4yn2Rh61G nY7t/zKh+qWgnZqR+ajlFEX5aKXoN7+qNOe41P0yqVhSh73rg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1716945896; x=1717032296; bh=VnB5cSkzbTE+pF/YZXsLRqgiA9Ik yhO++Upx0eRciEg=; b=G/Duu+4LHTF1BLs8GagnWEk0fbQdmDsmhnL5GzcQPf9V yTB2nHY0zvjAuz2yWvqzOmqBtbZgs1AutN7D4q6QBT/B65z0XPo9A13UDBmx4u2y TMdmKujWElSvzDYIkSYg3HxCXufF8SomSPKkzydD1QeSYsQFvEcS+gWWnlekgekt Fb53Nj8SZpxzbjEISNF6HbAhdG+ugzXeor1DltBADIMU18cqqht4nK8zf4ByccET DlNz++cm77FLAAwbraYUKQ+IYVyEASVsPa03j8MKaLlv3PdSV7y3QyRjntSamb7k LTDD/sAX2fhL3xeHgsGzLp7BpDxiT9gPXlYVj6HlMQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejledggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffoggfgsedtkeertd ertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehljhho nhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfdujedthfduudekffefkeeiffdttd dvhfegudduueffuefhfefggeefteevvdegnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 28 May 2024 21:24:52 -0400 (EDT) From: "Luke D. Jones" To: jikos@kernel.org Cc: hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com, corentin.chary@gmail.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, bentiss@kernel.org, "Luke D. Jones" Subject: [PATCH v1 1/2] hid-asus: use hid for brightness control on keyboard Date: Wed, 29 May 2024 13:24:46 +1200 Message-ID: <20240529012447.145088-1-luke@ljones.dev> X-Mailer: git-send-email 2.45.1 Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On almost all ASUS ROG series laptops the MCU used for the USB keyboard also has a HID packet used for setting the brightness. This is usually the same as the WMI method. But in some laptops the WMI method either is missing or doesn't work, so we should default to the HID control. Signed-off-by: Luke D. Jones --- drivers/hid/hid-asus.c | 6 ++++ drivers/platform/x86/asus-wmi.c | 35 +++++++++++++++++++++- include/linux/platform_data/x86/asus-wmi.h | 10 +++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index 02de2bf4f790..4cba8e143031 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -492,12 +492,18 @@ static void asus_kbd_backlight_work(struct work_struct *work) */ 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 && asus_use_hid_led()) { + 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); diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 3f9b6285c9a6..54cb07c79fcf 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -144,6 +144,15 @@ module_param(fnlock_default, bool, 0444); static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL }; +static const char * const use_hid_led_matches[] = { + "ROG Zephyrus", + "ROG Strix", + "ROG Flow", + "GA403", + "GU605", + "RC71L", +}; + static int throttle_thermal_policy_write(struct asus_wmi *); static bool ashs_present(void) @@ -1642,6 +1651,29 @@ static int micmute_led_set(struct led_classdev *led_cdev, return err < 0 ? err : 0; } +bool asus_use_hid_led(void) +{ + const char *product, *board; + int i; + + product = dmi_get_system_info(DMI_PRODUCT_FAMILY); + if (!product) + return false; + + board = dmi_get_system_info(DMI_BOARD_NAME); + if (!board) + return false; + + for (i = 0; i < ARRAY_SIZE(use_hid_led_matches); i++) { + if (strstr(product, use_hid_led_matches[i])) + return true; + if (strstr(board, use_hid_led_matches[i])) + return true; + } + return false; +} +EXPORT_SYMBOL_GPL(asus_use_hid_led); + static void asus_wmi_led_exit(struct asus_wmi *asus) { led_classdev_unregister(&asus->kbd_led); @@ -1681,7 +1713,8 @@ static int asus_wmi_led_init(struct asus_wmi *asus) goto error; } - if (!kbd_led_read(asus, &led_val, NULL)) { + if (!kbd_led_read(asus, &led_val, NULL) && !asus_use_hid_led()) { + pr_info("using asus-wmi for asus::kbd_backlight\n"); asus->kbd_led_wk = led_val; asus->kbd_led.name = "asus::kbd_backlight"; asus->kbd_led.flags = LED_BRIGHT_HW_CHANGED; diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index 3eb5cd6773ad..6833035f7006 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -160,4 +160,14 @@ static inline int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, } #endif +/* To be used by both hid-asus and asus-wmi to determine which controls kbd_brightness */ +#if IS_ENABLED(CONFIG_ASUS_WMI) +bool asus_use_hid_led(void); +#else +static inline bool asus_use_hid_led(void) +{ + return true; +} +#endif + #endif /* __PLATFORM_DATA_X86_ASUS_WMI_H */ From patchwork Wed May 29 01:28:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 800093 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 821DA15B0EE; Wed, 29 May 2024 01:28:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716946128; cv=none; b=KfDqJcJZR9lIKWaVL/yVC1xaxnKAJ1T/7jxfqQSxUVbwwGcWcgrEgoEzS8uGhmDC6jegLnNwArvCtS+ld7VqMZII9jSKlirSbB9LG7ASwNuH27yv/AmDFB6laqBhmJijzszJ5y1QyiZlXsOP9KkderJ8da+KFy/EJWQBGPLkbxc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716946128; c=relaxed/simple; bh=LDZLCHZzuZFdB9MB2gzeXB2ldjxyM30EyBUTBHEphxw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YEKT+3+leIFDzeuBhREe9efka5+IYVS2f2pc5+7xlsX/+YLVOcxCGuZLUYyoN34CmHlgSchS0mBklIRmrWSiwsSpmLRm8GjqcCd1E3dVMvBp+kvQ3SuQ9ErXZGZwkseXFGzi+4VqjXbwDrEaCo/KBlTDJ9cbLCqpToMN/fDY5wU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev; spf=none smtp.mailfrom=ljones.dev; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b=iBEF5K+l; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KxqS8xZ+; arc=none smtp.client-ip=64.147.123.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ljones.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b="iBEF5K+l"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KxqS8xZ+" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 3CD511C000F6; Tue, 28 May 2024 21:28:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 28 May 2024 21:28:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1716946125; x= 1717032525; bh=LNipYAkSRLIdv0+aK0KD7aPesVOUo+kH+La70D2FdvE=; b=i BEF5K+lImWFXNvL3XvfT8sdACcTIfn67z9Rrh5LJgkOdTmEKXDXWZS2jZ2dVWybg NYU9rvIrW+LYKmzd1OOEizR2xY+jwpBjXHw5oCCzWoGwggY1c83heADkPppOgrjX rxKIwkNvY99+9CvX6YvmlL1dG1e4Fq+xCW7WOnxXKCihtpavQeABrc5UNzoiqF0/ DCiXfQy5d1nyIJ06gl//IUZHLU0X5m6vHzMVxvBFN7q3N7pd0c6UdTLe3fjlfuBf XlgqeCq8+kt/VfvHC1tBx4Wm37Ll9hzmTzKEBjuqERShjvfu0QD9TkzdjEN+uo43 X6yWxZLrgwTzOJ6XFhONw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1716946125; x= 1717032525; bh=LNipYAkSRLIdv0+aK0KD7aPesVOUo+kH+La70D2FdvE=; b=K xqS8xZ+x6kb8uQlUJzSWcceRFdI/8pD/sxM61py/i74w3eaGnC3ajekCQVGRN0Cm OVF00g9xvv7uVYWSw4u1D0uG2MXzPqJ3kA0jpdsnFV+Ae7q/cqJGyD4u9UX4rX4+ eArOLYoAnKaYTIKHxJMNCEeBx+DFTOYZ4C2urMKeOfeNHZkMbw2TW6iJrTJ1Jomx WzB2zScTng4XK/mI2mnT4t5CmYQUWCPEpYtlb5aNdnSpC+Q+fK13K/TNoFeS1dY+ fFxQUdNOeqimWkvQ40Hfnw6vd7APxHbQF0fLG+rxl7n6KbZ0fNFxX3RVQIjQiSAe 21UCFI1rFEn3h+ediL7hg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejledggeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 28 May 2024 21:28:42 -0400 (EDT) From: "Luke D. Jones" To: jikos@kernel.org Cc: hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com, corentin.chary@gmail.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, bentiss@kernel.org, "Luke D. Jones" Subject: [PATCH v1 2/2] hid-asus: change the report_id used for HID LED control Date: Wed, 29 May 2024 13:28:27 +1200 Message-ID: <20240529012827.146005-3-luke@ljones.dev> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240529012827.146005-1-luke@ljones.dev> References: <20240529012827.146005-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On some laptops the report_id used for LED brightness control must be 0x5D instead of 0x5A. Signed-off-by: Luke D. Jones --- drivers/hid/hid-asus.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index 4cba8e143031..ec3556cc4eef 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -94,6 +94,8 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad"); #define TRKID_SGN ((TRKID_MAX + 1) >> 1) +static const char * const use_alt_led_report_id[] = { "GU605", "GA403" }; + struct asus_kbd_leds { struct led_classdev cdev; struct hid_device *hdev; @@ -101,6 +103,7 @@ struct asus_kbd_leds { unsigned int brightness; spinlock_t lock; bool removed; + int report_id; }; struct asus_touchpad_info { @@ -473,7 +476,7 @@ static enum led_brightness asus_kbd_backlight_get(struct led_classdev *led_cdev) static void asus_kbd_backlight_work(struct work_struct *work) { struct asus_kbd_leds *led = container_of(work, struct asus_kbd_leds, work); - u8 buf[] = { FEATURE_KBD_REPORT_ID, 0xba, 0xc5, 0xc4, 0x00 }; + u8 buf[] = { led->report_id, 0xba, 0xc5, 0xc4, 0x00 }; int ret; unsigned long flags; @@ -513,6 +516,23 @@ static bool asus_kbd_wmi_led_control_present(struct hid_device *hdev) return !!(value & ASUS_WMI_DSTS_PRESENCE_BIT); } +static bool asus_kbd_is_input_led(void) +{ + const char *product; + int i; + + product = dmi_get_system_info(DMI_PRODUCT_NAME); + if (!product) + return false; + + for (i = 0; i < ARRAY_SIZE(use_alt_led_report_id); i++) { + if (strstr(product, use_alt_led_report_id[i])) + return true; + } + + return false; +} + static int asus_kbd_register_leds(struct hid_device *hdev) { struct asus_drvdata *drvdata = hid_get_drvdata(hdev); @@ -555,6 +575,10 @@ static int asus_kbd_register_leds(struct hid_device *hdev) if (!drvdata->kbd_backlight) return -ENOMEM; + drvdata->kbd_backlight->report_id = FEATURE_KBD_REPORT_ID; + if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD && asus_kbd_is_input_led()) + drvdata->kbd_backlight->report_id = FEATURE_KBD_LED_REPORT_ID1; + drvdata->kbd_backlight->removed = false; drvdata->kbd_backlight->brightness = 0; drvdata->kbd_backlight->hdev = hdev;