Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2505849lqb; Tue, 28 May 2024 01:47:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXpKzT1l3hMbaVa4g4A5Ya6iZXNuGcueuZx3i6U84NUC9BVDWHO02AoQEun29yj29Sr7IPyWKib1vTmIuwz8PFi2n5l0WZdkilxebHOaA== X-Google-Smtp-Source: AGHT+IF2hWWbvFglFtLcKemXxE3s3AiyDHdo9pWhg5mG0hvXxYbI8ScQHkpJDXxHtVtiIgzXgk9Z X-Received: by 2002:a05:6214:2b94:b0:6ad:8316:4cbb with SMTP id 6a1803df08f44-6ad83165706mr58430236d6.14.1716886059810; Tue, 28 May 2024 01:47:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716886059; cv=pass; d=google.com; s=arc-20160816; b=Hd2c2xAeoupkR+T35hfGkE3Rd7PoFF+Zwo8KKxXNcYuUYIzqd71CdNoT0r1wlWyCiv /V6scqnvkPgdV2olXThazI4Kf4ovjHHM+0gg211uIgl12HGLDVA1mlYksSS73ZuyOx6y QzhDjGwZ3pYD+gjbdiCVUSz+M4zocnpmVoK1jSs+h1kGVRcjnFP18x7dQ54RvHgAOots 0o2Y26dpFaCCKjJstrp5TbixdYTkcHL4FxoyNqFuOeyiqQBUHXcLVGCAiFxFzRe8cbVT zv0/bFTN2egIDIbqPvkEyjIb2tE1NKIE1GPfeE7mGGFGvTHSf07x+FmkzYnHmW6IXe4N WlCw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:feedback-id:dkim-signature:dkim-signature; bh=hfv8F1e+/1YTGPoUag9mnDwd8gl58J8C/k+Vg3dKLvM=; fh=WDf2fzzXJEYQ2k4FXP75D2meq4urYMyDO+O0ViGWY24=; b=SnJ6cXbHTzPEbWHLIvBbcJqzqqBtN95TnuKZtiqOP8f3FSQuXjdfTBUlIIU3EKKRaG nKPWVMz4JrNPG0BnCxR3H69YqBqfyWbhN+O9Obw++9pQxM5T6gpKdMLfpCce63DLxL1H ilebt6dJgr5psfrgCjBpqEqkFoVeGhfabeyKQqQ4VLqpJFNg3mJs0mG2C3lu5ATAFBeN 6zxsGNjdUdfZSw7/D4br+ddjUizcaSqgV7SG2/8IaFtuiu18IyQ4UzLy9UeCteunXGZ7 PYpMBAikAPQOsRBmnXcrtMgKKZdpCP0hD72kDtiOLFv22dOZYzjJil3qoYlWfbyhBw5K x1DA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm2 header.b=jmxvTzE7; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=DxPSZSUe; arc=pass (i=1 dkim=pass dkdomain=ljones.dev dkim=pass dkdomain=messagingengine.com); spf=pass (google.com: domain of linux-kernel+bounces-191622-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191622-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6ac06f4f535si96420206d6.17.2024.05.28.01.47.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 01:47:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-191622-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm2 header.b=jmxvTzE7; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=DxPSZSUe; arc=pass (i=1 dkim=pass dkdomain=ljones.dev dkim=pass dkdomain=messagingengine.com); spf=pass (google.com: domain of linux-kernel+bounces-191622-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191622-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DFCDF1C231AD for ; Tue, 28 May 2024 01:40:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 64748CA64; Tue, 28 May 2024 01:40:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b="jmxvTzE7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="DxPSZSUe" Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 B4897DF49; Tue, 28 May 2024 01:40:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860414; cv=none; b=eYl2vbZ7T11EdMi+bB2iUNK5o0y9t5nhlsf29nAA6mkoAbKrZLPExI3N22hCf18oTnBMuTSkcQyZxsE1dpfEnM5WPeJynWan2QlZI5AESvqOL3ZJZsSHXe+2GE9sSGODJpqKDN95GQtweapWJ+jfS9O5QfTRJn8LmN6LchjYnJ8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860414; c=relaxed/simple; bh=6Zda21Jo8keaOvTrsU69xa03MnSQfCWrWoWucqAQV+g=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=LhZsZy5Q3ncLSyPDy1DUTLSD5U6eeNz4y2j9uZbJPuNgPy6zHb41K4Snp20TokZd6un9PDVRytXq3WZko0dB6PJb95cxmjAz+ukXFACVCb22fT+JpPd4TrJSY8MNnCGxSXAFWVF8ZiR+KHNnVvprwIpTggMkhdYK3hJolW8OMKM= 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=jmxvTzE7; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=DxPSZSUe; arc=none smtp.client-ip=103.168.172.145 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 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id B5AA71380149; Mon, 27 May 2024 21:40:11 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 27 May 2024 21:40:11 -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=1716860411; x=1716946811; bh=hfv8F1e+/1YTGPoUag9mn Dwd8gl58J8C/k+Vg3dKLvM=; b=jmxvTzE7v/CTRheWzJ6QaKn73IjXvyqy+Sgls DmqB/CSHo9kgZD+qv/rI33Jq9Eruo38TSAvlCLQWxDixdVqVcrUJa0U+eDZLRQ+U AdFxACu3wD8aHKAratNzpxXq1tnzP+Zy85rIkLbMO4CobBL/Ymhqg4jJUtRBFrxu E4EixCOy4fjy4+/8pCEGhwAe9ml1DWg05/8e8R372sfiAvH7E5x58DfPQlAUayqh 76To/XQ9uzicOsSxCNBTcfRSKdvdcCaEqedwmflpjc4k2AAbjT43+rdb3z78NtJG 5LxSrce/xBSqnETS1IQsyDkby/9yxK2nfcGDn5R6VuPY3rU6Q== 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=1716860411; x=1716946811; bh=hfv8F1e+/1YTGPoUag9mnDwd8gl5 8J8C/k+Vg3dKLvM=; b=DxPSZSUeqnPC1GmkiHIT+QvdJ3zUImvc5TVCZWkWSREg kyBF6l9z2QaODn/cTgx8V6RDBdBSnZa+g+OIytpaCcLkvGutvC4kggiWpbN3Sqkq qLQEbYGZBp+D0FKR1Gyuq1lKI5+bkHIouRZtTXFczarzFAldDOah3MrpezVsxPpG mDraPw3HjhhUcPjhQ9SXX2FkKK/lSNAcjx/+UZO39GKcItmwovgO9eDlC+EYCUdd PnHCmxdFBee4tZXm+3eqQHLzwxHbpf+cGEaheltb7mAnoeVnV73Oo0Yr1Asr6AK0 iwxpKHnK14C2zkdXjaW6J8CG9KtB4G6OiWxXWckgIQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejhedggeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffoggfgsedtkeertd ertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehljhho nhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfdujedthfduudekffefkeeiffdttd dvhfegudduueffuefhfefggeefteevvdegnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 May 2024 21:40:07 -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] hid-asus: use hid for brightness control on keyboard Date: Tue, 28 May 2024 13:39:59 +1200 Message-ID: <20240528013959.14661-1-luke@ljones.dev> X-Mailer: git-send-email 2.45.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 | 19 ++++++++++++- drivers/platform/x86/asus-wmi.c | 3 ++- include/linux/platform_data/x86/asus-wmi.h | 31 ++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index 02de2bf4f790..9389a3e733e3 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -101,6 +101,7 @@ struct asus_kbd_leds { unsigned int brightness; spinlock_t lock; bool removed; + int report_id; }; struct asus_touchpad_info { @@ -473,7 +474,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; @@ -492,12 +493,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_hidraw_led()) { + hid_info(hdev, "using hidraw 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); @@ -507,6 +514,12 @@ 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) +{ + return dmi_match(DMI_PRODUCT_NAME, "GU605") + || dmi_match(DMI_PRODUCT_NAME, "GA403"); +} + static int asus_kbd_register_leds(struct hid_device *hdev) { struct asus_drvdata *drvdata = hid_get_drvdata(hdev); @@ -549,6 +562,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; diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 3f9b6285c9a6..a58df18a70ad 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -1681,7 +1681,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_hidraw_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..79a50102440d 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -160,4 +160,35 @@ 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_REACHABLE(CONFIG_ASUS_WMI) +static bool asus_use_hidraw_led(void) +{ + const char *product, *board; + + product = dmi_get_system_info(DMI_PRODUCT_FAMILY); + if (!product) + return false; + + /* These product ranges should all be using HID for keyboard LED */ + if (strstr(product, "ROG Zephyrus") + || strstr(product, "ROG Strix") + || strstr(product, "ROG Flow") + || strstr(product, "GA403") + || strstr(product, "GU605")) + return true; + + board = dmi_get_system_info(DMI_BOARD_NAME); + if (!board) + return false; + + return strstr(board, "RC71L"); /* ROG Ally specific */ +} +#else +static inline bool asus_use_hidraw_led(void) +{ + return true; +} +#endif + #endif /* __PLATFORM_DATA_X86_ASUS_WMI_H */ -- 2.45.1