From patchwork Tue Aug 9 02:50:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 12939300 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29391C25B0C for ; Tue, 9 Aug 2022 02:51:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229530AbiHICvN (ORCPT ); Mon, 8 Aug 2022 22:51:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231360AbiHICvM (ORCPT ); Mon, 8 Aug 2022 22:51:12 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 758D9192BF; Mon, 8 Aug 2022 19:51:11 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id D85965C00AE; Mon, 8 Aug 2022 22:51:10 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 08 Aug 2022 22:51:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1660013470; x=1660099870; bh=b8 zBqnbjGfkGFv4egHJI0533lSwO5A03klYpq+LVrGI=; b=kyJMAg7BhnEYXKf5J1 qJWQnsF4bOfgAtRiuhwmZFdVUyww6d1dr/3wP/OkF6gH5kV1otg1ak3phk+ITTPO BvIh1FXgEbH9+WwMQ//C6yhWPkv/d2t3urwkwbrl0wUW9/1o1+jN2JBMMG43eqTK cxYIGkVVMZCapU+C1XDLpyovivsaOZa5Rk2SHfptaZ4jE7IDZ1Ik1u6CWk4aZMgW XZLMsCkHJJKPqHIlV7ioItwB0yVJNV9QDsrfngKn1yNqzwhJzl2aQJ6fEJad3s6A 1RE+kvanN/DpB0bm0Y5Y5BcBe0hbv4kJHmwUjzlbAtpkLAo1Ss9n1l2ZoHc/pD+a hUoQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1660013470; x=1660099870; bh=b8zBqnbjGfkGF v4egHJI0533lSwO5A03klYpq+LVrGI=; b=CaMyhMmMf46yNc3FODZkVz5JMQtdM Vf0WXkeo/ESyhch3KqFGFEr6OnUncQBRfc/CT4nCLbE6Vrb3WDc39CL2Hcr7Z7eI V2Oo4xlg2vgqYRx0CCJSLpDTxtJLGsZuMpu+t9ZN4+8X43L7xIDHSFhEl/XinzeA n52nl7JPBxlsQQqVjxwKoEGqmr6FP55B21D7SuZnpYDygQL+YFYum18wdFtU7ehA zXXQ1hNig5JVWzxqdNMK9ZdBLkFteUJFjEJ9kj2kskfWMAqiSARHDeMBNKW2wUjh VxUw/FC0LJ0ce/fP763lcFhbxNTwpFz27EIQS1+j4gRvrSAJTTtUEw92g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdefledgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 8 Aug 2022 22:51:08 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: andy.shevchenko@gmail.com, pobrn@protonmail.com, pavel@ucw.cz, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH v3 1/6] asus-wmi: Implement TUF laptop keyboard RGB control Date: Tue, 9 Aug 2022 14:50:49 +1200 Message-Id: <20220809025054.1626339-2-luke@ljones.dev> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220809025054.1626339-1-luke@ljones.dev> References: <20220809025054.1626339-1-luke@ljones.dev> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Adds support for TUF laptop RGB control via the multicolor LED API. As this is the bas for adjusting only the RGB values, it sets the default mode of the keyboard to static since there is no way to read any existing settings from the device. These defaults overwrite the booted state of the keyboard when the module is loaded. Signed-off-by: Luke D. Jones --- drivers/platform/x86/asus-wmi.c | 80 ++++++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 3 + 2 files changed, 83 insertions(+) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 0e7fbed8a50d..233e73f4313d 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -117,6 +118,9 @@ static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL }; static int throttle_thermal_policy_write(struct asus_wmi *); +static int tuf_rgb_brightness_set(struct led_classdev *cdev, + enum led_brightness brightness); + static bool ashs_present(void) { int i = 0; @@ -190,6 +194,14 @@ struct fan_curve_data { u8 percents[FAN_CURVE_POINTS]; }; +struct keyboard_rgb_led { + struct mc_subled subled_info[3]; /* r g b */ + struct led_classdev_mc dev; + u8 save; + u8 mode; + u8 speed; +}; + struct asus_wmi { int dsts_id; int spec; @@ -234,6 +246,8 @@ struct asus_wmi { bool dgpu_disable_available; bool dgpu_disable; + struct keyboard_rgb_led keyboard_rgb_mode; + bool throttle_thermal_policy_available; u8 throttle_thermal_policy_mode; @@ -1028,12 +1042,40 @@ static enum led_brightness lightbar_led_get(struct led_classdev *led_cdev) return result & ASUS_WMI_DSTS_LIGHTBAR_MASK; } +static int tuf_rgb_brightness_set(struct led_classdev *cdev, + enum led_brightness brightness) +{ + struct led_classdev_mc *mc_cdev = lcdev_to_mccdev(cdev); + struct keyboard_rgb_led *rgb = container_of(mc_cdev, struct keyboard_rgb_led, dev); + struct asus_wmi *asus = container_of(rgb, struct asus_wmi, keyboard_rgb_mode); + struct device *dev = &asus->platform_device->dev; + u8 r, g, b; + int err; + u32 ret; + + led_mc_calc_color_components(mc_cdev, brightness); + r = mc_cdev->subled_info[0].brightness; + g = mc_cdev->subled_info[1].brightness; + b = mc_cdev->subled_info[2].brightness; + + /* Writing out requires some defaults. This will overwrite boot mode */ + err = asus_wmi_evaluate_method3(ASUS_WMI_METHODID_DEVS, ASUS_WMI_DEVID_TUF_RGB_MODE, + rgb->save | (rgb->mode << 8) | (r << 16) | (g << 24), + (b) | (rgb->speed << 8), + &ret); + if (err) + dev_err(dev, "Unable to set TUF RGB data?\n"); + + return err; +} + static void asus_wmi_led_exit(struct asus_wmi *asus) { led_classdev_unregister(&asus->kbd_led); led_classdev_unregister(&asus->tpd_led); led_classdev_unregister(&asus->wlan_led); led_classdev_unregister(&asus->lightbar_led); + led_classdev_multicolor_unregister(&asus->keyboard_rgb_mode.dev); if (asus->led_workqueue) destroy_workqueue(asus->led_workqueue); @@ -1105,6 +1147,44 @@ static int asus_wmi_led_init(struct asus_wmi *asus) &asus->lightbar_led); } + if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE)) { + struct mc_subled *mc_led_info = asus->keyboard_rgb_mode.subled_info; + struct led_classdev_mc *mc_cdev = &asus->keyboard_rgb_mode.dev; + struct device *dev = &asus->platform_device->dev; + u8 led_brightness = 255; + + /* + * asus::kbd_backlight still controls a base 3-level backlight and when + * it is on 0, the RGB is not visible at all. RGB should be treated as + * an additional step. + */ + mc_cdev->led_cdev.name = "asus::multicolour::kbd_backlight"; + mc_cdev->led_cdev.flags = LED_CORE_SUSPENDRESUME | LED_RETAIN_AT_SHUTDOWN; + mc_cdev->led_cdev.brightness_set_blocking = tuf_rgb_brightness_set; + mc_cdev->led_cdev.brightness_get = NULL; + + mc_cdev->subled_info = mc_led_info; + mc_led_info[0].intensity = 127; + mc_led_info[0].color_index = LED_COLOR_ID_RED; + mc_led_info[1].color_index = LED_COLOR_ID_GREEN; + mc_led_info[2].color_index = LED_COLOR_ID_BLUE; + mc_cdev->num_colors = 3; + + /* + * It's not possible to get last set data from device so set defaults + * to make it safe for a user to change either RGB or modes. + */ + asus->keyboard_rgb_mode.save = 1; + asus->keyboard_rgb_mode.mode = 0; + asus->keyboard_rgb_mode.speed = 0xeb; + + mc_cdev->led_cdev.brightness = led_brightness; + mc_cdev->led_cdev.max_brightness = led_brightness; + led_mc_calc_color_components(mc_cdev, led_brightness); + + rv = led_classdev_multicolor_register(dev, mc_cdev); + } + error: if (rv) asus_wmi_led_exit(asus); diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index a571b47ff362..d63c9945a17d 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -98,6 +98,9 @@ /* dgpu on/off */ #define ASUS_WMI_DEVID_DGPU 0x00090020 +/* TUF laptop RGB control */ +#define ASUS_WMI_DEVID_TUF_RGB_MODE 0x00100056 + /* DSTS masks */ #define ASUS_WMI_DSTS_STATUS_BIT 0x00000001 #define ASUS_WMI_DSTS_UNKNOWN_BIT 0x00000002 From patchwork Tue Aug 9 02:50:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 12939301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8981BC00140 for ; Tue, 9 Aug 2022 02:51:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231791AbiHICv1 (ORCPT ); Mon, 8 Aug 2022 22:51:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231603AbiHICvP (ORCPT ); Mon, 8 Aug 2022 22:51:15 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7407A1E3DE; Mon, 8 Aug 2022 19:51:14 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id D00A75C0046; Mon, 8 Aug 2022 22:51:13 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 08 Aug 2022 22:51:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1660013473; x=1660099873; bh=gE pD7e0phpvDHfZqNwT6fJk1Mqt4jaxDnSrfoJgQ/BY=; b=hwTnS4yC7MPu5vjEUr 9BxGBZcbCL4ouUWdy9ENW4zvTWPzmF76IH4nUkq5kTRwYaliCj/txvpVQlTRWgbF Oqf/xMoWGNr9Nt5B9XUgZiiS9cItAz86Cto8TaMpKDRXSSPyS0xpo2GR+alfjAFr 8NKbYVSJEzK+Ma9QQQoxlWqQfnG1AoveX2W5cBb/Z6hbS0AsHI8ucHFirWDu999v OCd5j1J+5q2GMOpnKUpkYXcTlenkd6oLGc/GLp4X6PyETrr0MP1GSxBP0mEMtNG/ PxvzPH/YVEbK2l4SQyuMhva8znJII6Cjp9P+HMlCwKMpPTM9nIlcmV2E37dJnbQK YfCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1660013473; x=1660099873; bh=gEpD7e0phpvDH fZqNwT6fJk1Mqt4jaxDnSrfoJgQ/BY=; b=tYOGkjo+929VmnRVZtExjsc9C/v05 M4osAgSfBw2tup/Dqv9U61nFCXYkYdI2f9GJHHxRcdMVO6/o2PYjJiL+9LpQnY1w akIV+8gyGrLqfj2jCYTO7pH8kQVjXKts9gKQKidRrGzS/+i5srZCaATV4n6hBXuT KIyv7+QxeiEYWsDvrWjONEQiidJjYLrOJyHEC2pRfDXqeTNSFSppfRHSeKmfm1W0 bnFLU3txhrcKMmMpxPnKKrTPZ+OBDwGGrih+9/OJd3JwnD9JcB0g66N74KQj9z4z j7hk+scVj/xIIaEyUXe3SPmobRqZjry8NJrXtmlb0cvaRJjI8ZnTCDYVw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdefledgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 8 Aug 2022 22:51:11 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: andy.shevchenko@gmail.com, pobrn@protonmail.com, pavel@ucw.cz, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH v3 2/6] asus-wmi: Implement TUF laptop keyboard LED modes Date: Tue, 9 Aug 2022 14:50:50 +1200 Message-Id: <20220809025054.1626339-3-luke@ljones.dev> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220809025054.1626339-1-luke@ljones.dev> References: <20220809025054.1626339-1-luke@ljones.dev> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Adds support for changing the laptop keyboard LED modes. These are visible effects such as static, rainbow, pulsing, colour cycles. These sysfs attributes are added to asus-nb-wmi: - keyboard_rgb_save - keyboard_rgb_mode - keyboard_rgb_speed Signed-off-by: Luke D. Jones --- .../ABI/testing/sysfs-platform-asus-wmi | 30 +++++ drivers/platform/x86/asus-wmi.c | 127 ++++++++++++++++-- 2 files changed, 149 insertions(+), 8 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index 04885738cf15..a9128fa5cc65 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -57,3 +57,33 @@ Description: * 0 - default, * 1 - overboost, * 2 - silent + +What: /sys/devices/platform//keyboard_rgb_save +Date: Aug 2022 +KernelVersion: 6.1 +Contact: "Luke Jones" +Description: + Set or save the RGB mode details (write-only): + * 0 - set, the settings will be lost on boot + * 1 - save, the settings will be retained on boot + +What: /sys/devices/platform//keyboard_rgb_mode +Date: Aug 2022 +KernelVersion: 6.1 +Contact: "Luke Jones" +Description: + Set the mode of the RGB keyboard, the mode will not apply until the + keyboard_rgb_save attribute is set (write-only): + * 0 to 12, each is an RGB such as static, rainbow, pulse. + Not all keyboards accept every mode. + +What: /sys/devices/platform//keyboard_rgb_speed +Date: Aug 2022 +KernelVersion: 6.1 +Contact: "Luke Jones" +Description: + Set the speed of the selected RGB effect, the speed will not apply + until the keyboard_rgb_save attribute is set (write-only): + * 0 - slow + * 1 - medium + * 2 - fast \ No newline at end of file diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 233e73f4313d..fa0cc2895a66 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -246,7 +246,8 @@ struct asus_wmi { bool dgpu_disable_available; bool dgpu_disable; - struct keyboard_rgb_led keyboard_rgb_mode; + bool keyboard_rgb_mode_available; + struct keyboard_rgb_led keyboard_rgb_led; bool throttle_thermal_policy_available; u8 throttle_thermal_policy_mode; @@ -748,6 +749,102 @@ static ssize_t egpu_enable_store(struct device *dev, static DEVICE_ATTR_RW(egpu_enable); +/* TUF Laptop Keyboard RGB Modes **********************************************/ +static int keyboard_rgb_check_present(struct asus_wmi *asus) +{ + u32 result; + int err; + + asus->keyboard_rgb_mode_available = false; + + err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_TUF_RGB_MODE, &result); + if (err) { + if (err == -ENODEV) + return 0; + return err; + } + + if (result & ASUS_WMI_DSTS_PRESENCE_BIT) + asus->keyboard_rgb_mode_available = true; + + return 0; +} + +static ssize_t keyboard_rgb_save_store(struct device *device, + struct device_attribute *attr, + const char *buf, size_t count) +{ + u8 save; + int err; + + struct asus_wmi *asus = dev_get_drvdata(device); + struct led_classdev *cdev = &asus->keyboard_rgb_led.dev.led_cdev; + + if (sscanf(buf, "%hhd", &save) != 1) + return -EINVAL; + + asus->keyboard_rgb_led.save = !!save; + + err = tuf_rgb_brightness_set(cdev, cdev->brightness); + if (err) + return err; + + return count; +} +static DEVICE_ATTR_WO(keyboard_rgb_save); + +static ssize_t keyboard_rgb_mode_store(struct device *device, + struct device_attribute *attr, + const char *buf, size_t count) +{ + u8 mode; + + struct asus_wmi *asus = dev_get_drvdata(device); + + if (sscanf(buf, "%hhd", &mode) != 1) + return -EINVAL; + + /* These are the known usable modes across all TUF/ROG */ + if (mode >= 12 || mode == 10) + asus->keyboard_rgb_led.mode = 10; + else + asus->keyboard_rgb_led.mode = mode; + + return count; +} +static DEVICE_ATTR_WO(keyboard_rgb_mode); + + +static ssize_t keyboard_rgb_speed_store(struct device *device, + struct device_attribute *attr, + const char *buf, size_t count) +{ + u8 speed; + + struct asus_wmi *asus = dev_get_drvdata(device); + + if (sscanf(buf, "%hhd", &speed) != 1) + return -EINVAL; + + switch (speed) { + case 0: + asus->keyboard_rgb_led.speed = 0xe1; + break; + case 1: + asus->keyboard_rgb_led.speed = 0xeb; + break; + case 2: + asus->keyboard_rgb_led.speed = 0xf5; + break; + default: + asus->keyboard_rgb_led.speed = 0xeb; + break; + } + + return count; +} +static DEVICE_ATTR_WO(keyboard_rgb_speed); + /* Battery ********************************************************************/ /* The battery maximum charging percentage */ @@ -1047,7 +1144,7 @@ static int tuf_rgb_brightness_set(struct led_classdev *cdev, { struct led_classdev_mc *mc_cdev = lcdev_to_mccdev(cdev); struct keyboard_rgb_led *rgb = container_of(mc_cdev, struct keyboard_rgb_led, dev); - struct asus_wmi *asus = container_of(rgb, struct asus_wmi, keyboard_rgb_mode); + struct asus_wmi *asus = container_of(rgb, struct asus_wmi, keyboard_rgb_led); struct device *dev = &asus->platform_device->dev; u8 r, g, b; int err; @@ -1075,7 +1172,7 @@ static void asus_wmi_led_exit(struct asus_wmi *asus) led_classdev_unregister(&asus->tpd_led); led_classdev_unregister(&asus->wlan_led); led_classdev_unregister(&asus->lightbar_led); - led_classdev_multicolor_unregister(&asus->keyboard_rgb_mode.dev); + led_classdev_multicolor_unregister(&asus->keyboard_rgb_led.dev); if (asus->led_workqueue) destroy_workqueue(asus->led_workqueue); @@ -1148,8 +1245,8 @@ static int asus_wmi_led_init(struct asus_wmi *asus) } if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE)) { - struct mc_subled *mc_led_info = asus->keyboard_rgb_mode.subled_info; - struct led_classdev_mc *mc_cdev = &asus->keyboard_rgb_mode.dev; + struct mc_subled *mc_led_info = asus->keyboard_rgb_led.subled_info; + struct led_classdev_mc *mc_cdev = &asus->keyboard_rgb_led.dev; struct device *dev = &asus->platform_device->dev; u8 led_brightness = 255; @@ -1174,9 +1271,9 @@ static int asus_wmi_led_init(struct asus_wmi *asus) * It's not possible to get last set data from device so set defaults * to make it safe for a user to change either RGB or modes. */ - asus->keyboard_rgb_mode.save = 1; - asus->keyboard_rgb_mode.mode = 0; - asus->keyboard_rgb_mode.speed = 0xeb; + asus->keyboard_rgb_led.save = 1; + asus->keyboard_rgb_led.mode = 0; + asus->keyboard_rgb_led.speed = 0xeb; mc_cdev->led_cdev.brightness = led_brightness; mc_cdev->led_cdev.max_brightness = led_brightness; @@ -3338,6 +3435,9 @@ static struct attribute *platform_attributes[] = { &dev_attr_touchpad.attr, &dev_attr_egpu_enable.attr, &dev_attr_dgpu_disable.attr, + &dev_attr_keyboard_rgb_save.attr, + &dev_attr_keyboard_rgb_mode.attr, + &dev_attr_keyboard_rgb_speed.attr, &dev_attr_lid_resume.attr, &dev_attr_als_enable.attr, &dev_attr_fan_boost_mode.attr, @@ -3368,6 +3468,12 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, ok = asus->egpu_enable_available; else if (attr == &dev_attr_dgpu_disable.attr) ok = asus->dgpu_disable_available; + else if (attr == &dev_attr_keyboard_rgb_save.attr) + ok = asus->keyboard_rgb_mode_available; + else if (attr == &dev_attr_keyboard_rgb_mode.attr) + ok = asus->keyboard_rgb_mode_available; + else if (attr == &dev_attr_keyboard_rgb_speed.attr) + ok = asus->keyboard_rgb_mode_available; else if (attr == &dev_attr_fan_boost_mode.attr) ok = asus->fan_boost_mode_available; else if (attr == &dev_attr_throttle_thermal_policy.attr) @@ -3637,6 +3743,10 @@ static int asus_wmi_add(struct platform_device *pdev) if (err) goto fail_dgpu_disable; + err = keyboard_rgb_check_present(asus); + if (err) + goto fail_keyboard_rgb_mode; + err = fan_boost_mode_check_present(asus); if (err) goto fail_fan_boost_mode; @@ -3751,6 +3861,7 @@ static int asus_wmi_add(struct platform_device *pdev) fail_fan_boost_mode: fail_egpu_enable: fail_dgpu_disable: +fail_keyboard_rgb_mode: fail_platform: fail_panel_od: kfree(asus); From patchwork Tue Aug 9 02:50:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 12939302 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13B1CC00140 for ; Tue, 9 Aug 2022 02:51:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231360AbiHICvc (ORCPT ); Mon, 8 Aug 2022 22:51:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231733AbiHICvT (ORCPT ); Mon, 8 Aug 2022 22:51:19 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6E8D192BF; Mon, 8 Aug 2022 19:51:17 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id B9E615C01AC; Mon, 8 Aug 2022 22:51:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 08 Aug 2022 22:51:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1660013476; x=1660099876; bh=tA FVuLEiq4n15PVSxtti2rN3Q28tmHpru0E3XtX5Hts=; b=lHB3Rx1VzDqmzo8cXD QrOOajjk4cY5kcKQjbc+GMRtMq6Z+oRTHqV3UPNCkfvTllj5ciEhKf1A6pvPVShY B/VqDj48wYjQEBKN8MWUL6lErvKgoIKOknbcMwlzT8KAsAb9UTvSl2HmBqoCGp99 6tvl9z1i/bbl6f+rVLStZnsBN1x+b1uhYRez6awyNYR50G0bmCO8UwqyHV3SqTYc abqB3VoCnEXm4113RnL56nNblhIs5Fb/DXpP2XlObGIUTlLnKEvAH9vshfREy25f F7+HmE+g9mMm+fd4gddHI98o2G3T7BZtaBzaLjkSaDS7WW7JpBF6g3GghQRsx/le I41Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1660013476; x=1660099876; bh=tAFVuLEiq4n15 PVSxtti2rN3Q28tmHpru0E3XtX5Hts=; b=Fib8bFy7gvSGxyIl0RssTbLX6b+gF dL8dpcXKMhIX4cJ+vWwAly/fNkWvvzNnpjIlAJcl9+ry5Egw7pLfZexz0Xn5OZMW KmEUPVnu3YVUGAIAhPr8Qx5um5KkV0KBuSUzxMurn9Yng9tNt8pe/50otwuiQn7F p7mm9m71Hd4G9YXVy1U0nR6l5ba7dbTKYHonCDe3HiG35B0I7P4d0gP0JMv+b06e uSu3Y9b8XZWzJEkseZQ539J27eU9CzqMUGW8ag7FL5addYpZxZdGGRRGXoBkt8dM 5AyyXDt/SCcWxGaADq30j3X41UfV8bIzFAdo9FTRSAFVJJljTOAm6XP6A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdefledgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 8 Aug 2022 22:51:14 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: andy.shevchenko@gmail.com, pobrn@protonmail.com, pavel@ucw.cz, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH v3 3/6] asus-wmi: Implement TUF laptop keyboard power states Date: Tue, 9 Aug 2022 14:50:51 +1200 Message-Id: <20220809025054.1626339-4-luke@ljones.dev> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220809025054.1626339-1-luke@ljones.dev> References: <20220809025054.1626339-1-luke@ljones.dev> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Adds support for setting various power states of TUF keyboards. These states are combinations of: - boot, set if a boot animation is shown on keyboard - awake, set if the keyboard LEDs are visible while laptop is on - sleep, set if an animation is displayed while the laptop is suspended - keyboard (unknown effect) Adds two sysfs attributes to asus-nb-wmi: - keyboard_rgb_state - keyboard_rgb_state_index Signed-off-by: Luke D. Jones --- .../ABI/testing/sysfs-platform-asus-wmi | 18 ++++- drivers/platform/x86/asus-wmi.c | 72 +++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 2 + 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index a9128fa5cc65..3e3f2dcf9bfa 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -86,4 +86,20 @@ Description: until the keyboard_rgb_save attribute is set (write-only): * 0 - slow * 1 - medium - * 2 - fast \ No newline at end of file + * 2 - fast + +What: /sys/devices/platform//keyboard_rgb_state +Date: Aug 2022 +KernelVersion: 6.1 +Contact: "Luke Jones" +Description: + Set some RGB keyboard power states (write-only). + + The accepted input is "boot awake sleep keyboard", where "n n n n n" + options are: + * save - 0 or 1, if 0 then settings are not retained on boot + * boot - 0 or 1, controls if a boot animation is shown + * awake - 0 or 1, controls if the keyboard LED are on during awake + * sleep - 0 or 1, controls if a suspended animation is shown. + This is only active if the AC is connected. + * keyboard - 0 or 1, unknown what effect this really has \ No newline at end of file diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index fa0cc2895a66..719223804c0e 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -246,6 +246,7 @@ struct asus_wmi { bool dgpu_disable_available; bool dgpu_disable; + bool keyboard_rgb_state_available; bool keyboard_rgb_mode_available; struct keyboard_rgb_led keyboard_rgb_led; @@ -845,6 +846,66 @@ static ssize_t keyboard_rgb_speed_store(struct device *device, } static DEVICE_ATTR_WO(keyboard_rgb_speed); +/* TUF Laptop Keyboard RGB States *********************************************/ +static int keyboard_rgb_state_check_present(struct asus_wmi *asus) +{ + u32 result; + int err; + + asus->keyboard_rgb_state_available = false; + + err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_TUF_RGB_STATE, &result); + if (err) { + if (err == -ENODEV) + return 0; + return err; + } + + if (result & ASUS_WMI_DSTS_PRESENCE_BIT) + asus->keyboard_rgb_state_available = true; + + return 0; +} + +static ssize_t keyboard_rgb_state_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + u8 flags, save, boot, awake, sleep, keyboard; + int err; + u32 ret; + + flags = 0; + if (sscanf(buf, "%hhd %hhd %hhd %hhd %hhd", &save, &boot, &awake, &sleep, &keyboard) != 5) + return -EINVAL; + + save = save == 0 ? 0x0100 : 0x0000; + if (boot) + flags |= 0x02; + if (awake) + flags |= 0x08; + if (sleep) + flags |= 0x20; + if (keyboard) + flags |= 0x80; + + err = asus_wmi_evaluate_method3(ASUS_WMI_METHODID_DEVS, + ASUS_WMI_DEVID_TUF_RGB_STATE, 0xBD | save | (flags << 16), 0, &ret); + if (err) + return err; + + return count; +} +static DEVICE_ATTR_WO(keyboard_rgb_state); + +static ssize_t keyboard_rgb_state_index_show(struct device *device, + struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%s\n", "save boot awake sleep keyboard"); +} +static DEVICE_ATTR_RO(keyboard_rgb_state_index); + /* Battery ********************************************************************/ /* The battery maximum charging percentage */ @@ -3438,6 +3499,8 @@ static struct attribute *platform_attributes[] = { &dev_attr_keyboard_rgb_save.attr, &dev_attr_keyboard_rgb_mode.attr, &dev_attr_keyboard_rgb_speed.attr, + &dev_attr_keyboard_rgb_state.attr, + &dev_attr_keyboard_rgb_state_index.attr, &dev_attr_lid_resume.attr, &dev_attr_als_enable.attr, &dev_attr_fan_boost_mode.attr, @@ -3474,6 +3537,10 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, ok = asus->keyboard_rgb_mode_available; else if (attr == &dev_attr_keyboard_rgb_speed.attr) ok = asus->keyboard_rgb_mode_available; + else if (attr == &dev_attr_keyboard_rgb_state.attr) + ok = asus->keyboard_rgb_state_available; + else if (attr == &dev_attr_keyboard_rgb_state_index.attr) + ok = asus->keyboard_rgb_state_available; else if (attr == &dev_attr_fan_boost_mode.attr) ok = asus->fan_boost_mode_available; else if (attr == &dev_attr_throttle_thermal_policy.attr) @@ -3747,6 +3814,10 @@ static int asus_wmi_add(struct platform_device *pdev) if (err) goto fail_keyboard_rgb_mode; + err = keyboard_rgb_state_check_present(asus); + if (err) + goto fail_keyboard_rgb_state; + err = fan_boost_mode_check_present(asus); if (err) goto fail_fan_boost_mode; @@ -3862,6 +3933,7 @@ static int asus_wmi_add(struct platform_device *pdev) fail_egpu_enable: fail_dgpu_disable: fail_keyboard_rgb_mode: +fail_keyboard_rgb_state: fail_platform: fail_panel_od: kfree(asus); diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index d63c9945a17d..b5c966798ef8 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -100,6 +100,8 @@ /* TUF laptop RGB control */ #define ASUS_WMI_DEVID_TUF_RGB_MODE 0x00100056 +/* TUF laptop RGB state control */ +#define ASUS_WMI_DEVID_TUF_RGB_STATE 0x00100057 /* DSTS masks */ #define ASUS_WMI_DSTS_STATUS_BIT 0x00000001 From patchwork Tue Aug 9 02:50:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 12939311 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11F9FC00140 for ; Tue, 9 Aug 2022 02:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232141AbiHICvn (ORCPT ); Mon, 8 Aug 2022 22:51:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231673AbiHICvb (ORCPT ); Mon, 8 Aug 2022 22:51:31 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 027501EAD0; Mon, 8 Aug 2022 19:51:20 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 60F0E5C01C1; Mon, 8 Aug 2022 22:51:19 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 08 Aug 2022 22:51:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1660013479; x=1660099879; bh=38 udBJAW+pe0pQZBWrn35ZUdlsO4rdjQ4UZPBf5LI80=; b=KWZLBE9HMZDjEFNCgt URxlJ6EQeYcRdrc0+ZPhBRHZTqHQ+LcCQQXxPqCzi/aVrRYvFMg1ICy5qznPLKbb jtnCmuMGITlgqDBthEY/BW9BeB2945tGAL2Qe9ZhKCUwwV9W5B7//JbOn+YEUEBf LN2kXsLlwKrENONkc6ZUmL9L+rFSw+NiuFrprNTPfnjBUi7ZquwYntxsCVsUnwMo pIpAKQQKiovoSXQ17r03edczqnovGYHcnwcdbkIZWqwFGgLTuPgfQsEG6b3Jkz/L pW8GcuNHgbmKU0h5hD0bu0YmIaNsZbOvwEZ736w0v9aO/kVw2gEkc2e307Nq8TO3 2/3g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1660013479; x=1660099879; bh=38udBJAW+pe0p QZBWrn35ZUdlsO4rdjQ4UZPBf5LI80=; b=PEUEEFHrLEO08JA4Wt9SMrrvRdcRm 3mQxkzliS0so03pHo93NZ8YTNRHQq2FC1qcJP16ELGt+1xzzD8ZlrfwG8dOOpltd cPe5S9YdNu+kVt16YhgYhEE8k2L4tEapwFN5jIzTLAdfWmz3iUT0zpMFMWCDrvv5 iLKPN3/HisKqq5KStY1WovzArOu/dJF/Z5VQWYvMJLaj2CFzQH4XSOwM71gsHEkJ +lYRhHOiZ/NAAGtH0ZWERP2V6YfqUPTj17svfZB639I9u6kFohdN9yXuvmkjXS3c hsnl5oLj+q1HH/+t1IBTpUi5Pks1J2rpouzQuRfi/eNT33Jad++W7B1Ig== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdefledgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgepuden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 8 Aug 2022 22:51:16 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: andy.shevchenko@gmail.com, pobrn@protonmail.com, pavel@ucw.cz, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH v3 4/6] asus-wmi: Document previously added attributes Date: Tue, 9 Aug 2022 14:50:52 +1200 Message-Id: <20220809025054.1626339-5-luke@ljones.dev> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220809025054.1626339-1-luke@ljones.dev> References: <20220809025054.1626339-1-luke@ljones.dev> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Documents some previously added attributes: - dgpu_disable - egpu_enable - panel_od Signed-off-by: Luke D. Jones --- .../ABI/testing/sysfs-platform-asus-wmi | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index 3e3f2dcf9bfa..541dbfbbbb26 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -48,6 +48,34 @@ Description: * 1 - overboost, * 2 - silent +What: /sys/devices/platform//dgpu_disable +Date: Aug 2022 +KernelVersion: 5.17 +Contact: "Luke Jones" +Description: + Disable discrete GPU: + * 0 - Enable dGPU, + * 1 - Disable dGPU, + +What: /sys/devices/platform//egpu_enable +Date: Aug 2022 +KernelVersion: 5.17 +Contact: "Luke Jones" +Description: + Enable the external GPU paired with ROG X-Flow laptops. + Toggling this setting will also trigger ACPI to disable the dGPU: + * 0 - Disable, + * 1 - Enable, + +What: /sys/devices/platform//panel_od +Date: Aug 2022 +KernelVersion: 5.17 +Contact: "Luke Jones" +Description: + Enable an LCD response-time boost to reduce or remove ghosting: + * 0 - Disable, + * 1 - Enable, + What: /sys/devices/platform//throttle_thermal_policy Date: Dec 2019 KernelVersion: 5.6 @@ -102,4 +130,4 @@ Description: * awake - 0 or 1, controls if the keyboard LED are on during awake * sleep - 0 or 1, controls if a suspended animation is shown. This is only active if the AC is connected. - * keyboard - 0 or 1, unknown what effect this really has \ No newline at end of file + * keyboard - 0 or 1, unknown what effect this really has From patchwork Tue Aug 9 02:50:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 12939312 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35F73C25B0D for ; Tue, 9 Aug 2022 02:51:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232030AbiHICvq (ORCPT ); Mon, 8 Aug 2022 22:51:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231603AbiHICvg (ORCPT ); Mon, 8 Aug 2022 22:51:36 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADC141EAE0; Mon, 8 Aug 2022 19:51:22 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 1CE745C0130; Mon, 8 Aug 2022 22:51:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Mon, 08 Aug 2022 22:51:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1660013482; x=1660099882; bh=p6 022WMN/oVY4nyX42sR1Bs+V2EDgtJ2eDDOx0oRuX0=; b=IzNGScerdfPuztAoj/ rTuUmSY/bxa3qGS599PEx4vqnr8/CCAYreOe5pVMZLIQ5S73eI0F7wnfRx6evP8r 1y/MlLIZoK4JatpVvBI54Lj2rI7ZmjC8dbD1MlzJWESTRuMdGkb+RQlqQ9glD4Ip NgPJOdeTDRATNQHN4lB+NVW8ndti814JROLzV3oPb965O0M9sKJT8MA4XpB3TM7N I1Zx3CtSDJ3z/tk310OQkBBh2pE26ZRnAZdn5oUtKV8q9xE/1Ji2POUoTOzFKsSc OPDT3XwQw1LbtE92nivxQxEPzRgd4FvFLTpbXva0u7d3/uxtAiYjB64gw8cEbgoj xEww== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1660013482; x=1660099882; bh=p6022WMN/oVY4 nyX42sR1Bs+V2EDgtJ2eDDOx0oRuX0=; b=Go2mbV9o08pjJEeBL4GZUk36KEi1r ckae8nenacQtfEWiz59Dogg4HUDh0qpJQvQNVUpD6Oo+yGe5IJPW1Ao5vXyu3Ouj S5A9Y7i2Tw9CxYzsM5BOe6WktCecpb3lCxVEdXomT9Wy17RZdIWi6xqYkHJo29X1 83pFB3eSrfq+62qh184UIQAAc76ExeJFyZkfoiThv6nLpye0VPN4jPNU/fJruzSm gp/26upefYgZj5ohYG62AnJSQVtMIRTeOy7Pe4B+0faAIq9RfaYSnE5exBomPWTP D8MoMXfBFD9YBN9a7f0/8SiumivDITS3C4elnOLiNJeIMIQR5xYY7nN3g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdefledgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 8 Aug 2022 22:51:19 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: andy.shevchenko@gmail.com, pobrn@protonmail.com, pavel@ucw.cz, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH v3 5/6] asus-wmi: Convert all attr-show to use sysfs_emit Date: Tue, 9 Aug 2022 14:50:53 +1200 Message-Id: <20220809025054.1626339-6-luke@ljones.dev> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220809025054.1626339-1-luke@ljones.dev> References: <20220809025054.1626339-1-luke@ljones.dev> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org This changes all *_show attributes in asus-wmi.c to use sysfs_emit() instead of the older method of writing to the output buffer manually. Signed-off-by: Luke D. Jones Reviewed-by: Andy Shevchenko --- drivers/platform/x86/asus-wmi.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 719223804c0e..78f1f3af1b12 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -942,7 +942,7 @@ static ssize_t charge_control_end_threshold_show(struct device *device, struct device_attribute *attr, char *buf) { - return sprintf(buf, "%d\n", charge_end_threshold); + return sysfs_emit(buf, "%d\n", charge_end_threshold); } static DEVICE_ATTR_RW(charge_control_end_threshold); @@ -2032,7 +2032,7 @@ static ssize_t pwm1_show(struct device *dev, value = -1; } - return sprintf(buf, "%d\n", value); + return sysfs_emit(buf, "%d\n", value); } static ssize_t pwm1_store(struct device *dev, @@ -2092,7 +2092,7 @@ static ssize_t fan1_input_show(struct device *dev, return -ENXIO; } - return sprintf(buf, "%d\n", value < 0 ? -1 : value*100); + return sysfs_emit(buf, "%d\n", value < 0 ? -1 : value * 100); } static ssize_t pwm1_enable_show(struct device *dev, @@ -2110,7 +2110,7 @@ static ssize_t pwm1_enable_show(struct device *dev, * in practice on X532FL at least (the bit is always 0) and there's * also nothing in the DSDT to indicate that this behaviour exists. */ - return sprintf(buf, "%d\n", asus->fan_pwm_mode); + return sysfs_emit(buf, "%d\n", asus->fan_pwm_mode); } static ssize_t pwm1_enable_store(struct device *dev, @@ -2178,7 +2178,7 @@ static ssize_t fan1_label_show(struct device *dev, struct device_attribute *attr, char *buf) { - return sprintf(buf, "%s\n", ASUS_FAN_DESC); + return sysfs_emit(buf, "%s\n", ASUS_FAN_DESC); } static ssize_t asus_hwmon_temp1(struct device *dev, @@ -2371,7 +2371,7 @@ static ssize_t fan_boost_mode_show(struct device *dev, { struct asus_wmi *asus = dev_get_drvdata(dev); - return scnprintf(buf, PAGE_SIZE, "%d\n", asus->fan_boost_mode); + return sysfs_emit(buf, "%d\n", asus->fan_boost_mode); } static ssize_t fan_boost_mode_store(struct device *dev, @@ -2924,7 +2924,7 @@ static ssize_t throttle_thermal_policy_show(struct device *dev, struct asus_wmi *asus = dev_get_drvdata(dev); u8 mode = asus->throttle_thermal_policy_mode; - return scnprintf(buf, PAGE_SIZE, "%d\n", mode); + return sysfs_emit(buf, "%d\n", mode); } static ssize_t throttle_thermal_policy_store(struct device *dev, From patchwork Tue Aug 9 02:50:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 12939313 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56A47C00140 for ; Tue, 9 Aug 2022 02:51:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232584AbiHICvt (ORCPT ); Mon, 8 Aug 2022 22:51:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232085AbiHICvi (ORCPT ); Mon, 8 Aug 2022 22:51:38 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B48671EAF9; Mon, 8 Aug 2022 19:51:25 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id EDBE35C0076; Mon, 8 Aug 2022 22:51:24 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 08 Aug 2022 22:51:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1660013484; x=1660099884; bh=o+ juuYOh1Fprq4WVZMezN2y7MDe2vSHHS0tkW1i/SsI=; b=DeJeUR2xouHH5t3HAY wBtQ+ORckWq0BoUeDmuJ+KP+Y+h/2xRO46pgVa1Xq2tl+f0u2yMMt0l4Df99WHRc qH6zfaPugaQXtZi+GfGCW7oE/EYBTZ8DMNLJLG23YErgYpcWwgXahhg5C8nw0znW DS6fDJxr+ZcEwTaP7ptqzsa/8kmco+u0Ss8zf60Mdr7QYcrdjuD4m7aU4f4Ltskh GilCZt5LWIQ65luV7WWrB1TrGYnP6kCAM+1rfnZMdaU44vBX0kheNvBTob375Lr3 iK8utWSD2IxzSbKAMEpFK1915nLtbYkDTFUTLEfubVNhZQ3xKWBq75hUO0w4zb0q w2Ow== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1660013484; x=1660099884; bh=o+juuYOh1Fprq 4WVZMezN2y7MDe2vSHHS0tkW1i/SsI=; b=G7f3UNErF2NXbef1wR8kvqlz0SuoM mJVDAXebGcAo65ns1IQIPU3G8nk4TywNAcTxJrNvdjvfrW3vh65I4HY0WLDG+KTR 7iJcH8XLbNbRZpiC1mKQqzmr9nQZkK98uhIlOi8PeMf4nMtVGhmv/gwuDRnbpXge LTC8sIJK3sxmKrb+AUUEo8VryHOH7fBEINpL37XxFb8TPF1VaCkH46KkDKL1LJU1 JBXjfP0R5o8mLhVXzdWLucdl0Vn7SaIkhCjbjxpF1byc8nAdsI1oUgyYJU/5ewTp sYYYeGLxGNjRZRcT5df9KE7Gs//DcBKq+xbGqzufnmhw9Cj0/MPjzJ0sw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdefledgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgepvden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 8 Aug 2022 22:51:22 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: andy.shevchenko@gmail.com, pobrn@protonmail.com, pavel@ucw.cz, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH v3 6/6] asus-wmi: Support the hardware GPU MUX on some laptops Date: Tue, 9 Aug 2022 14:50:54 +1200 Message-Id: <20220809025054.1626339-7-luke@ljones.dev> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220809025054.1626339-1-luke@ljones.dev> References: <20220809025054.1626339-1-luke@ljones.dev> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Support the hardware GPU MUX switch available on some models. This switch can toggle the MUX between: - 0, Dedicated mode - 1, Optimus mode Optimus mode is the regular iGPU + dGPU available, while dedicated mode switches the system to have only the dGPU available. Signed-off-by: Luke D. Jones --- .../ABI/testing/sysfs-platform-asus-wmi | 9 ++ drivers/platform/x86/asus-wmi.c | 91 +++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 3 + 3 files changed, 103 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index 541dbfbbbb26..d483bc3cb2e6 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -67,6 +67,15 @@ Description: * 0 - Disable, * 1 - Enable, +What: /sys/devices/platform//gpu_mux_mode +Date: Aug 2022 +KernelVersion: 6.0 +Contact: "Luke Jones" +Description: + Switch the GPU used by the hardware MUX: + * 0 - Dedicated GPU, + * 1 - Optimus mode, + What: /sys/devices/platform//panel_od Date: Aug 2022 KernelVersion: 5.17 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 78f1f3af1b12..c5fa21370481 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -246,6 +246,9 @@ struct asus_wmi { bool dgpu_disable_available; bool dgpu_disable; + bool gpu_mux_mode_available; + bool gpu_mux_mode; + bool keyboard_rgb_state_available; bool keyboard_rgb_mode_available; struct keyboard_rgb_led keyboard_rgb_led; @@ -750,6 +753,86 @@ static ssize_t egpu_enable_store(struct device *dev, static DEVICE_ATTR_RW(egpu_enable); +/* gpu mux switch *************************************************************/ +static int gpu_mux_mode_check_present(struct asus_wmi *asus) +{ + u32 result; + int err; + + asus->gpu_mux_mode_available = false; + + err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_GPU_MUX, &result); + if (err) { + if (err == -ENODEV) + return 0; + return err; + } + + if (result & ASUS_WMI_DSTS_PRESENCE_BIT) { + asus->gpu_mux_mode_available = true; + asus->gpu_mux_mode = result & ASUS_WMI_DSTS_STATUS_BIT; + } + + return 0; +} + +static int gpu_mux_mode_write(struct asus_wmi *asus) +{ + u32 retval; + u8 value; + int err; + + /* Don't rely on type conversion */ + value = asus->gpu_mux_mode ? 1 : 0; + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_GPU_MUX, value, &retval); + if (err) { + pr_warn("Failed to set dGPU-only mode: %d\n", err); + return err; + } + + if (retval > 1) { + pr_warn("Failed to set dGPU-only mode (retval): 0x%x\n", retval); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "gpu_mux_mode"); + + return 0; +} + +static ssize_t gpu_mux_mode_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + u8 mode = asus->gpu_mux_mode; + + return sysfs_emit(buf, "%d\n", mode); +} + +static ssize_t gpu_mux_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + bool optimus; + int result; + + struct asus_wmi *asus = dev_get_drvdata(dev); + + result = kstrtobool(buf, &optimus); + if (result) + return result; + + asus->gpu_mux_mode = optimus; + + result = gpu_mux_mode_write(asus); + if (result) + return result; + + return count; +} +static DEVICE_ATTR_RW(gpu_mux_mode); + /* TUF Laptop Keyboard RGB Modes **********************************************/ static int keyboard_rgb_check_present(struct asus_wmi *asus) { @@ -3496,6 +3579,7 @@ static struct attribute *platform_attributes[] = { &dev_attr_touchpad.attr, &dev_attr_egpu_enable.attr, &dev_attr_dgpu_disable.attr, + &dev_attr_gpu_mux_mode.attr, &dev_attr_keyboard_rgb_save.attr, &dev_attr_keyboard_rgb_mode.attr, &dev_attr_keyboard_rgb_speed.attr, @@ -3531,6 +3615,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, ok = asus->egpu_enable_available; else if (attr == &dev_attr_dgpu_disable.attr) ok = asus->dgpu_disable_available; + else if (attr == &dev_attr_gpu_mux_mode.attr) + ok = asus->gpu_mux_mode_available; else if (attr == &dev_attr_keyboard_rgb_save.attr) ok = asus->keyboard_rgb_mode_available; else if (attr == &dev_attr_keyboard_rgb_mode.attr) @@ -3810,6 +3896,10 @@ static int asus_wmi_add(struct platform_device *pdev) if (err) goto fail_dgpu_disable; + err = gpu_mux_mode_check_present(asus); + if (err) + goto fail_gpu_mux_mode; + err = keyboard_rgb_check_present(asus); if (err) goto fail_keyboard_rgb_mode; @@ -3932,6 +4022,7 @@ static int asus_wmi_add(struct platform_device *pdev) fail_fan_boost_mode: fail_egpu_enable: fail_dgpu_disable: +fail_gpu_mux_mode: fail_keyboard_rgb_mode: fail_keyboard_rgb_state: fail_platform: diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index b5c966798ef8..3faeb98f6ea9 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -98,6 +98,9 @@ /* dgpu on/off */ #define ASUS_WMI_DEVID_DGPU 0x00090020 +/* gpu mux switch, 0 = dGPU, 1 = Optimus */ +#define ASUS_WMI_DEVID_GPU_MUX 0x00090016 + /* TUF laptop RGB control */ #define ASUS_WMI_DEVID_TUF_RGB_MODE 0x00100056 /* TUF laptop RGB state control */