From patchwork Tue Jun 20 02:56:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 110239 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3388297vqr; Mon, 19 Jun 2023 20:03:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Sk8mfdWnmPspK4BZs2QjPII7R860BFhF/Fi9oVx7B2HsYlRw3yNw9Ps9N3cArDZdmeYCL X-Received: by 2002:a05:6a20:1585:b0:122:470:377c with SMTP id h5-20020a056a20158500b001220470377cmr4517570pzj.2.1687230227410; Mon, 19 Jun 2023 20:03:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687230227; cv=none; d=google.com; s=arc-20160816; b=xxZr9kpytvTo+7WxvkQyLNHDgtPxnKnpBZNSp4iDcZ8i7USBGGG1PxewcolRG4Trg/ 00SAwlvaKimyL56QzDg5HQYSz3P86+NrWYh8f/3s0dN7fi/gfBYxbZ13yPBRx5r+AWbB Q1KgAvDg07BpqBfu5yniqTAcq2EAqHAfEZpPMTsPRpbcS7toqrZIKF765+PPi75hQZT9 LK6UBX39Nr4CB/rAWRoVy5IgBS1FsSUQxDcRFpDjS82pRA4M75VGkFu4idIkS69sk64G 97RjDjvIOPLmu7UHPkzIeJ2QpLL2eSUccE+fT8g5oOX3NPwKJWyRGQj1FguT+eC/DoBb w62w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=JAa2+5OdKdG1aE9dm0qeBtCZnBJBWtJ16Oa1u/aXq1c=; b=LGkJJm+wzqhDEh6f/uOvq7FvoyUAOADB373iOutZERHC6vxy8GBLl6nwT1AG7j9lq9 K9svWYr3Z1zKcUDZGPnVbYbIJTTCtmoJdgrQLM8xuv0OfSd9nAQqKN6J9iIudYqW21N6 WIL7r0cwhfH35yidgda0oxw66JbHzpoyO1ASsPATI9HuIVSjDuwZj8W3fC+RMjJ6AojM AV6bH4X99xvBQ4cqXXSVtPl6sh+f4bcWIDbMICiHrkl4dpKHtrN9Q9PqLuKfJQp7U2uY ee1zDtAjVdS7UmJ28VcuELpf2NpRzUTtUc33KT9T+5BfY0sKgUfGvRgkoJ+XWxiOAKrJ tPeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=aHRyjjee; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=UETfuI+8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g145-20020a625297000000b00666e6eccf49si749763pfb.30.2023.06.19.20.03.32; Mon, 19 Jun 2023 20:03:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=aHRyjjee; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=UETfuI+8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230038AbjFTC5S (ORCPT + 99 others); Mon, 19 Jun 2023 22:57:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjFTC5K (ORCPT ); Mon, 19 Jun 2023 22:57:10 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C266F10CB; Mon, 19 Jun 2023 19:57:09 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 2D8945C01EF; Mon, 19 Jun 2023 22:57:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 19 Jun 2023 22:57:09 -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:sender:subject:subject:to:to; s=fm3; t=1687229829; x= 1687316229; bh=JAa2+5OdKdG1aE9dm0qeBtCZnBJBWtJ16Oa1u/aXq1c=; b=a HRyjjeebR+MN4XUwK21uK//2996g945qYh2beELHP90mbv7vEm08p+KvspyY7pMH kKu0mwLyK8Dlz6KK3naw0kOanh1yK2rBESuabGGGn2dMDkqJg937FhEzD4sZPMAy r3q2ZYNyC7zpi5t5IEGm5pvzQjF+5pU4Bz6iPvTU/Pm9x7I65N+l7UiP1GceUQoD lKv33h0KaD8YRJQf1lorSdL8txyceRoPUUSaArgyyuCHRvdhReCZvWW5Njq1V5pd MxMkRj2yw3eb8GYwZ0zGf2AoROyT8ap6ZUR6ekkhd1RBfhMmyBrRuyWrRfQc/ICW kR904FX1LBRHMPqab7tTw== 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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1687229829; x= 1687316229; bh=JAa2+5OdKdG1aE9dm0qeBtCZnBJBWtJ16Oa1u/aXq1c=; b=U ETfuI+8103LMF52K+2WdH6c4k45OELYUvEnN9faqYpEwZ3TCdLSM8nm7wf702Pft RvOxI+TMfdy2RjtqF3e91btwneh3A4oeggf988F7VuR93o/CTGedG8xRgVghWFj5 1J3Wez2+nPkPgYXLHTZwy4CgmZvpK5R1q+DJ1bFAUkX0Sll6E8jk/1gmrQO664u5 VhYI2jqc9r1pp7PNgg7EfMG9EomRxseLg2NFoDkc0eCG3OPHGvxtvZoUwivldolb 30Fmu/OvwKULxQzDk/TDBTUGK2JKLQpUWtOBaX+iKV5JBMVFMZrIxGovYv5J3Iqd MoXUpoL18w+8cYIbJmhoA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeefgedgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Jun 2023 22:57:05 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: corentin.chary@gmail.com, acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, markgross@kernel.org, jdelvare@suse.com, linux@roeck-us.net, "Luke D. Jones" Subject: [PATCH 1/8] platform/x86: asus-wmi: add support for showing charger mode Date: Tue, 20 Jun 2023 14:56:34 +1200 Message-Id: <20230620025641.53197-2-luke@ljones.dev> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620025641.53197-1-luke@ljones.dev> References: <20230620025641.53197-1-luke@ljones.dev> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769189122785961697?= X-GMAIL-MSGID: =?utf-8?q?1769189122785961697?= Expose a WMI method in sysfs platform for showing which connected charger the laptop is currently using. Signed-off-by: Luke D. Jones --- .../ABI/testing/sysfs-platform-asus-wmi | 10 +++++++++ drivers/platform/x86/asus-wmi.c | 21 +++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 3 +++ 3 files changed, 34 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index a77a004a1baa..eb29e3023c7b 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -98,3 +98,13 @@ Description: Enable an LCD response-time boost to reduce or remove ghosting: * 0 - Disable, * 1 - Enable + +What: /sys/devices/platform//charge_mode +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Get the current charging mode being used: + * 1 - Barrel connected charger, + * 2 - USB-C charging + * 3 - Both connected, barrel used for charging \ No newline at end of file diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 1038dfdcdd32..f23375d5fb82 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -237,6 +237,7 @@ struct asus_wmi { u8 fan_boost_mode_mask; u8 fan_boost_mode; + bool charge_mode_available; bool egpu_enable_available; bool dgpu_disable_available; bool gpu_mux_mode_available; @@ -586,6 +587,22 @@ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus) asus_wmi_tablet_sw_report(asus, result); } +/* Charging mode, 1=Barrel, 2=USB ******************************************/ +static ssize_t charge_mode_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + int result, value; + + result = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_CHARGE_MODE, &value); + if (result < 0) + return result; + + return sysfs_emit(buf, "%d\n", value & 0xff); +} + +static DEVICE_ATTR_RO(charge_mode); + /* dGPU ********************************************************************/ static ssize_t dgpu_disable_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -3462,6 +3479,7 @@ static struct attribute *platform_attributes[] = { &dev_attr_camera.attr, &dev_attr_cardr.attr, &dev_attr_touchpad.attr, + &dev_attr_charge_mode.attr, &dev_attr_egpu_enable.attr, &dev_attr_dgpu_disable.attr, &dev_attr_gpu_mux_mode.attr, @@ -3491,6 +3509,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, devid = ASUS_WMI_DEVID_LID_RESUME; else if (attr == &dev_attr_als_enable.attr) devid = ASUS_WMI_DEVID_ALS_ENABLE; + else if (attr == &dev_attr_charge_mode.attr) + ok = asus->charge_mode_available; else if (attr == &dev_attr_egpu_enable.attr) ok = asus->egpu_enable_available; else if (attr == &dev_attr_dgpu_disable.attr) @@ -3757,6 +3777,7 @@ static int asus_wmi_add(struct platform_device *pdev) if (err) goto fail_platform; + asus->charge_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_CHARGE_MODE); asus->egpu_enable_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_EGPU); asus->dgpu_disable_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_DGPU); asus->gpu_mux_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_GPU_MUX); diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index 28234dc9fa6a..f90cafe26af1 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -95,6 +95,9 @@ /* Keyboard dock */ #define ASUS_WMI_DEVID_KBD_DOCK 0x00120063 +/* Charging mode - 1=Barrel, 2=USB */ +#define ASUS_WMI_DEVID_CHARGE_MODE 0x0012006C + /* dgpu on/off */ #define ASUS_WMI_DEVID_EGPU 0x00090019 From patchwork Tue Jun 20 02:56:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 110233 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3386222vqr; Mon, 19 Jun 2023 19:58:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5nZ8Cb4l+e6NIeY7yGpGdXbWPlh2i1utAPfB/5sxevya3y+o6wZTH+hfo7/lTiHTXTn4Oy X-Received: by 2002:a17:903:247:b0:1b3:dcf1:97 with SMTP id j7-20020a170903024700b001b3dcf10097mr13891079plh.25.1687229935659; Mon, 19 Jun 2023 19:58:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687229935; cv=none; d=google.com; s=arc-20160816; b=DjhrLR1YcpCD3rKFE45nbeQ4Ip0ExWgBnWDrd3JA3wf8ZzCk6R1A/CyAxeNA9gIjwg mMI0qx6yYVrA7oiheENf50wAf2p76FrPPcNZd/1F9+xT6Fc8BXWTM2ahwvQNUJgP3nMs SJ20sMftNqEN96iUd+YKomlQJd+rtdsInEG7ritRVkKz31mRh9zisPWsXOvOVa/cij3P WCZVslaADN0vhoAn61Gxz93kIVpTZg/0VlV1NZtPDEc/Z94iuWJ76k8C1xeSU4nZ55BY 3WkpNngtdlpQFoJ197ZW6UgTBLbZDiE9Hdt/uzw8+oQ6vi6E7AKminTfCWO8y9N59ueU Qneg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=i2v99NqpJrZxAzLHsyMCcMd30q0IFnY2dIA+JESeIh8=; b=ptsVPmQrpcIGVyv4NcLThpp8rFbduWA5c19EBrDns7ww5LVVhnCMXdx8tQYD/jXpH/ AjAans4S+b5EQRMtvLv7M9lnx7DKbIm6TtezYu6iD0ppsRAS+ql1DUwFe8IdIZGH0XDg kJE6Q38fEdYXn+s/2NX3QH06dY3jzt5E4S2lyIY96bafoPG5pIP1jiS66UYUojUnDula ftSVju1LINPfUQJBP/VHEutdb+N1jepOOUEHVyAfFtnE2asDvgDlMkG6Uh3RpacUzMUs kQLb2Fsf79ikwpSobLzUnAB+FZqIW5eO6Cl1X5gFfxqjxOxh+w0XsPFpNFwAunwqkiUM UvPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=dKoNkgBG; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=PmwIt3y+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f17-20020a170902f39100b001a9b4bda723si862886ple.421.2023.06.19.19.58.43; Mon, 19 Jun 2023 19:58:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=dKoNkgBG; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=PmwIt3y+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230062AbjFTC5W (ORCPT + 99 others); Mon, 19 Jun 2023 22:57:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbjFTC5P (ORCPT ); Mon, 19 Jun 2023 22:57:15 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F7E910CE; Mon, 19 Jun 2023 19:57:13 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C7E565C01E4; Mon, 19 Jun 2023 22:57:12 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 19 Jun 2023 22:57:12 -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:sender:subject:subject:to:to; s=fm3; t=1687229832; x= 1687316232; bh=i2v99NqpJrZxAzLHsyMCcMd30q0IFnY2dIA+JESeIh8=; b=d KoNkgBGYUqzm2MyCdEBOpeVHf/gJ4KkT0cPooKtsix0niehPf0Yq5I4FwjvBg4+J f6t5qSpjr/QemhAUx44GjHJaDbVoBeWo3oRmKJWCbFV3g7gQvE13SgGtPUnKcVev C8m7bkj5Ej/6CpoKlnwwoHd4TLPadq3iG8TP0Y246wvwkBKnSbxX4CLwQHYjZqLj MHtnSRae0YgQaVyxzPWq32zP29YnTmx65PGpSqNV0YHLQfzORoogOrXeZWi6v6lK ikk4l9JprQqVaoqGx4+7wu6Hi4CA543qQ36ZXrGcfo1wgHCCMkZCImYaaM9w2LNH zqQbRAXFSc5hLlkz+lBfg== 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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1687229832; x= 1687316232; bh=i2v99NqpJrZxAzLHsyMCcMd30q0IFnY2dIA+JESeIh8=; b=P mwIt3y+m6nKhG6cfmUH+qMqXD1Z0m9e0YSpsofvRpTHzd1AdViCcFsjuBXO98jgR FVXEdbZ55EK2YL7ZLJLmgOXj1eCQ5rT86y/LwYBenkjB8VOVU8+Wn8LkEeV3UCex CBky3zDgo3DLbrLQ5FBhMzZZXMrd+wcyZvWI5K6EoSQ8u5gBpRiZ89nBw5hbjVXR /+747MnTg6USfaZgaiiU0V0BCeaYj8O0K403YSvaWzl3GI6gP/wAXqWCjQSdbrBY wrz8vq32NHYL7UDyPmyC2ty8sL7ynaROFWA52NkjcxtCh4MMFLH5Nnk2+ldE8tby sx6mNAIIpdvdCYX908eZQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeefgedgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Jun 2023 22:57:09 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: corentin.chary@gmail.com, acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, markgross@kernel.org, jdelvare@suse.com, linux@roeck-us.net, "Luke D. Jones" Subject: [PATCH 2/8] platform/x86: asus-wmi: add support for showing middle fan RPM Date: Tue, 20 Jun 2023 14:56:35 +1200 Message-Id: <20230620025641.53197-3-luke@ljones.dev> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620025641.53197-1-luke@ljones.dev> References: <20230620025641.53197-1-luke@ljones.dev> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769188817345005150?= X-GMAIL-MSGID: =?utf-8?q?1769188817345005150?= Some newer ASUS ROG laptops now have a middle/center fan in addition to the CPU and GPU fans. This new fan typically blows across the heatpipes and VRMs betweent eh CPU and GPU. This commit exposes that fan to PWM control plus showing RPM. Signed-off-by: Luke D. Jones --- drivers/platform/x86/asus-wmi.c | 91 ++++++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 1 + 2 files changed, 92 insertions(+) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index f23375d5fb82..375d25ae0aca 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -72,6 +72,7 @@ module_param(fnlock_default, bool, 0444); #define ASUS_WMI_FNLOCK_BIOS_DISABLED BIT(0) +#define ASUS_MID_FAN_DESC "mid_fan" #define ASUS_GPU_FAN_DESC "gpu_fan" #define ASUS_FAN_DESC "cpu_fan" #define ASUS_FAN_MFUN 0x13 @@ -229,8 +230,10 @@ struct asus_wmi { enum fan_type fan_type; enum fan_type gpu_fan_type; + enum fan_type mid_fan_type; int fan_pwm_mode; int gpu_fan_pwm_mode; + int mid_fan_pwm_mode; int agfn_pwm; bool fan_boost_mode_available; @@ -2129,6 +2132,31 @@ static ssize_t fan2_label_show(struct device *dev, return sysfs_emit(buf, "%s\n", ASUS_GPU_FAN_DESC); } +/* Middle/Center fan on modern ROG laptops */ +static ssize_t fan3_input_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + int value; + int ret; + + ret = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_MID_FAN_CTRL, &value); + if (ret < 0) + return ret; + + value &= 0xffff; + + return sysfs_emit(buf, "%d\n", value * 100); +} + +static ssize_t fan3_label_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%s\n", ASUS_MID_FAN_DESC); +} + static ssize_t pwm2_enable_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -2175,6 +2203,52 @@ static ssize_t pwm2_enable_store(struct device *dev, return count; } +static ssize_t pwm3_enable_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + + return sysfs_emit(buf, "%d\n", asus->mid_fan_pwm_mode); +} + +static ssize_t pwm3_enable_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + int state; + int value; + int ret; + u32 retval; + + ret = kstrtouint(buf, 10, &state); + if (ret) + return ret; + + switch (state) { /* standard documented hwmon values */ + case ASUS_FAN_CTRL_FULLSPEED: + value = 1; + break; + case ASUS_FAN_CTRL_AUTO: + value = 0; + break; + default: + return -EINVAL; + } + + ret = asus_wmi_set_devstate(ASUS_WMI_DEVID_MID_FAN_CTRL, + value, &retval); + if (ret) + return ret; + + if (retval != 1) + return -EIO; + + asus->mid_fan_pwm_mode = state; + return count; +} + /* Fan1 */ static DEVICE_ATTR_RW(pwm1); static DEVICE_ATTR_RW(pwm1_enable); @@ -2184,6 +2258,10 @@ static DEVICE_ATTR_RO(fan1_label); static DEVICE_ATTR_RW(pwm2_enable); static DEVICE_ATTR_RO(fan2_input); static DEVICE_ATTR_RO(fan2_label); +/* Fan3 - Middle/center fan */ +static DEVICE_ATTR_RW(pwm3_enable); +static DEVICE_ATTR_RO(fan3_input); +static DEVICE_ATTR_RO(fan3_label); /* Temperature */ static DEVICE_ATTR(temp1_input, S_IRUGO, asus_hwmon_temp1, NULL); @@ -2192,10 +2270,13 @@ static struct attribute *hwmon_attributes[] = { &dev_attr_pwm1.attr, &dev_attr_pwm1_enable.attr, &dev_attr_pwm2_enable.attr, + &dev_attr_pwm3_enable.attr, &dev_attr_fan1_input.attr, &dev_attr_fan1_label.attr, &dev_attr_fan2_input.attr, &dev_attr_fan2_label.attr, + &dev_attr_fan3_input.attr, + &dev_attr_fan3_label.attr, &dev_attr_temp1_input.attr, NULL @@ -2221,6 +2302,11 @@ static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj, || attr == &dev_attr_pwm2_enable.attr) { if (asus->gpu_fan_type == FAN_TYPE_NONE) return 0; + } else if (attr == &dev_attr_fan3_input.attr + || attr == &dev_attr_fan3_label.attr + || attr == &dev_attr_pwm3_enable.attr) { + if (asus->mid_fan_type == FAN_TYPE_NONE) + return 0; } else if (attr == &dev_attr_temp1_input.attr) { int err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_THERMAL_CTRL, @@ -2264,6 +2350,7 @@ static int asus_wmi_hwmon_init(struct asus_wmi *asus) static int asus_wmi_fan_init(struct asus_wmi *asus) { asus->gpu_fan_type = FAN_TYPE_NONE; + asus->mid_fan_type = FAN_TYPE_NONE; asus->fan_type = FAN_TYPE_NONE; asus->agfn_pwm = -1; @@ -2278,6 +2365,10 @@ static int asus_wmi_fan_init(struct asus_wmi *asus) if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_GPU_FAN_CTRL)) asus->gpu_fan_type = FAN_TYPE_SPEC83; + /* Some models also have a center/middle fan */ + if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_MID_FAN_CTRL)) + asus->mid_fan_type = FAN_TYPE_SPEC83; + if (asus->fan_type == FAN_TYPE_NONE) return -ENODEV; diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index f90cafe26af1..2c03bda7703f 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -80,6 +80,7 @@ #define ASUS_WMI_DEVID_FAN_CTRL 0x00110012 /* deprecated */ #define ASUS_WMI_DEVID_CPU_FAN_CTRL 0x00110013 #define ASUS_WMI_DEVID_GPU_FAN_CTRL 0x00110014 +#define ASUS_WMI_DEVID_MID_FAN_CTRL 0x00110031 #define ASUS_WMI_DEVID_CPU_FAN_CURVE 0x00110024 #define ASUS_WMI_DEVID_GPU_FAN_CURVE 0x00110025 From patchwork Tue Jun 20 02:56:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 110237 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3387456vqr; Mon, 19 Jun 2023 20:01:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ67y8uIi1OTbiq2mg6ESA0jRS9poMbzS751CjD+Am1C3Pz+2PDmkIwK72zFnEii56vMrGTf X-Received: by 2002:a17:902:f351:b0:1b5:3c2c:76ee with SMTP id q17-20020a170902f35100b001b53c2c76eemr10111002ple.15.1687230105327; Mon, 19 Jun 2023 20:01:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687230105; cv=none; d=google.com; s=arc-20160816; b=FepALkYR8BDrLyklXDwVQJpLvwXfbWMpkzYHDddw3rzWmqa24CecainTnCtIw219Db WTWH8qip/qJjZPQpijsV5LopXRY82BZvVmEsfw9Ox87LBgy5AIwqzV/QYvgutClWab8S jCDFVETrKPqULf5gUpqriyZg3S91TlmjFKGZ8TYJx4xPa+9E3VagPS5OZr3RkU3EV5Fo CSTiAvtxNxPq0oHGQ8uIoqOhv1BsliyyBLUFUsOCcDAex7YB55nToDjpZ7MXc2zIMjFH yEtGM+YGsNYaMAeD7xYI/c/aMtDJwtxEMkbfY4ZiLl03iIUcLmlly7deWUMLqv4fLfQH y6Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=lUTuHDqLTLgI45JDTkN4av/NgduImU02Ny3VO4Ijj6g=; b=DEmowAdRuJuvnryke/yHsU9a40S7KBQCLXBPerN/IW7aaHUfJGh8as3DtCda+4ERHD OjHzzl5t5WeX59W2ernoxGCVKDc97xcMLlYHwqKhxY34kCoE+Xxq63ItS5Ae6l5NCVp7 A2lr/M/MH/lE6TH9DjEv8RbqKTzzAtXicTbMxu5sMP0Hws2knSjQhs13SaAFJLcWiWXS NgAso9F57ou7RPjnW1HwS6zSBXlvcgQ6EJDiy14hKalyT49FJyRJ9KILzBG6Lto/DyRp JhYQSGRsMq4SUsG7Hhn2WdXdOwPaw9rGVN4FQJpKg1OeuKf/A2SG4nQUKVM18aB0O48H u8NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=dHtUwnyX; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ccuAQzbm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u2-20020a170902e5c200b001b3bda067dasi1014785plf.493.2023.06.19.20.01.33; Mon, 19 Jun 2023 20:01:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=dHtUwnyX; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ccuAQzbm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230087AbjFTC5Z (ORCPT + 99 others); Mon, 19 Jun 2023 22:57:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230037AbjFTC5S (ORCPT ); Mon, 19 Jun 2023 22:57:18 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1BCE10CB; Mon, 19 Jun 2023 19:57:16 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 5550A5C01EA; Mon, 19 Jun 2023 22:57:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 19 Jun 2023 22:57:16 -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:sender:subject:subject:to:to; s=fm3; t=1687229836; x= 1687316236; bh=lUTuHDqLTLgI45JDTkN4av/NgduImU02Ny3VO4Ijj6g=; b=d HtUwnyX/3j8S4JGu1ZwdVf5HQq4gUhHadbYZsz2OhFipiukeT9VVW2YusMtM/ayG KICWzaw15szJnjKiTCRgINK/LJSpMPaoFvEuX7VJCFLdgIPBl3UA1TZISQetznRu GYGws9hjgXarg0ShX2014NT9Mj97i5PKlrlglfEmiGTNqiXd9QlBg35McZVBNVsI z0h6iZbWxta/E3Jv3Tarcw7F182OO8yIZzE1keCvMa//L0HA0SOzLZ5Mu1dlfBya Bc0EQFP6nGSI7KqnAZ87zkFE6jbUUK3lDusLpFQcqu90Bt8khSrt8rxpSAb+aWGP /ji/i7JEJvEeLf6juAtWw== 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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1687229836; x= 1687316236; bh=lUTuHDqLTLgI45JDTkN4av/NgduImU02Ny3VO4Ijj6g=; b=c cuAQzbmhgLbhdpr0hN3XNCeR6tls8h+zLCPVH/6t5Q6FndYW4eRzlN5JVftEDb+c XlY5k+/u5sdWlAdptgCUiDH+Fe29ES+z+kn3EXwAKxQqgUWKjyRj1hFY+ifPLmAk dLonmtxZ0Yhi/0CKbO1QlH5gAIl15O6FH7ND0WKO1Rq6TyisGWSHiWGsAUHb+cPn KJYZcvjhukFEmWXz1NM89/k8h9ILD/Bz+QL+oSi13RzSesqBsytZaLDHfof1HtPd I22Vmq9XBTuZj23k9hfwfzx9dmo/fe84gJ315Fq1GCzkCcvLIF9/jb6vnNVn7BKL 6Mul/ZUfIDSmtlo19bV1A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeefgedgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Jun 2023 22:57:13 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: corentin.chary@gmail.com, acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, markgross@kernel.org, jdelvare@suse.com, linux@roeck-us.net, "Luke D. Jones" Subject: [PATCH 3/8] platform/x86: asus-wmi: support middle fan custom curves Date: Tue, 20 Jun 2023 14:56:36 +1200 Message-Id: <20230620025641.53197-4-luke@ljones.dev> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620025641.53197-1-luke@ljones.dev> References: <20230620025641.53197-1-luke@ljones.dev> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769188994749343082?= X-GMAIL-MSGID: =?utf-8?q?1769188994749343082?= Adds support for fan curves defined for the middle fan which is available on some ASUS ROG laptops. Signed-off-by: Luke D. Jones --- drivers/platform/x86/asus-wmi.c | 77 +++++++++++++++++++++- include/linux/platform_data/x86/asus-wmi.h | 1 + 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 375d25ae0aca..fb27218e51cf 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -113,6 +113,7 @@ module_param(fnlock_default, bool, 0444); #define FAN_CURVE_BUF_LEN 32 #define FAN_CURVE_DEV_CPU 0x00 #define FAN_CURVE_DEV_GPU 0x01 +#define FAN_CURVE_DEV_MID 0x02 /* Mask to determine if setting temperature or percentage */ #define FAN_CURVE_PWM_MASK 0x04 @@ -253,7 +254,8 @@ struct asus_wmi { bool cpu_fan_curve_available; bool gpu_fan_curve_available; - struct fan_curve_data custom_fan_curves[2]; + bool mid_fan_curve_available; + struct fan_curve_data custom_fan_curves[3]; struct platform_profile_handler platform_profile_handler; bool platform_profile_support; @@ -2080,6 +2082,8 @@ static ssize_t pwm1_enable_store(struct device *dev, asus->custom_fan_curves[FAN_CURVE_DEV_CPU].enabled = false; if (asus->gpu_fan_curve_available) asus->custom_fan_curves[FAN_CURVE_DEV_GPU].enabled = false; + if (asus->mid_fan_curve_available) + asus->custom_fan_curves[FAN_CURVE_DEV_MID].enabled = false; return count; } @@ -2531,6 +2535,9 @@ static int fan_curve_get_factory_default(struct asus_wmi *asus, u32 fan_dev) if (fan_dev == ASUS_WMI_DEVID_GPU_FAN_CURVE) fan_idx = FAN_CURVE_DEV_GPU; + if (fan_dev == ASUS_WMI_DEVID_MID_FAN_CURVE) + fan_idx = FAN_CURVE_DEV_MID; + curves = &asus->custom_fan_curves[fan_idx]; err = asus_wmi_evaluate_method_buf(asus->dsts_id, fan_dev, mode, buf, FAN_CURVE_BUF_LEN); @@ -2819,6 +2826,42 @@ static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point7_pwm, fan_curve, static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point8_pwm, fan_curve, FAN_CURVE_DEV_GPU | FAN_CURVE_PWM_MASK, 7); +/* MID */ +static SENSOR_DEVICE_ATTR_RW(pwm3_enable, fan_curve_enable, FAN_CURVE_DEV_GPU); +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point1_temp, fan_curve, + FAN_CURVE_DEV_GPU, 0); +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point2_temp, fan_curve, + FAN_CURVE_DEV_GPU, 1); +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point3_temp, fan_curve, + FAN_CURVE_DEV_GPU, 2); +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point4_temp, fan_curve, + FAN_CURVE_DEV_GPU, 3); +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point5_temp, fan_curve, + FAN_CURVE_DEV_GPU, 4); +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point6_temp, fan_curve, + FAN_CURVE_DEV_GPU, 5); +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point7_temp, fan_curve, + FAN_CURVE_DEV_GPU, 6); +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point8_temp, fan_curve, + FAN_CURVE_DEV_GPU, 7); + +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point1_pwm, fan_curve, + FAN_CURVE_DEV_GPU | FAN_CURVE_PWM_MASK, 0); +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point2_pwm, fan_curve, + FAN_CURVE_DEV_GPU | FAN_CURVE_PWM_MASK, 1); +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point3_pwm, fan_curve, + FAN_CURVE_DEV_GPU | FAN_CURVE_PWM_MASK, 2); +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point4_pwm, fan_curve, + FAN_CURVE_DEV_GPU | FAN_CURVE_PWM_MASK, 3); +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point5_pwm, fan_curve, + FAN_CURVE_DEV_GPU | FAN_CURVE_PWM_MASK, 4); +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point6_pwm, fan_curve, + FAN_CURVE_DEV_GPU | FAN_CURVE_PWM_MASK, 5); +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point7_pwm, fan_curve, + FAN_CURVE_DEV_GPU | FAN_CURVE_PWM_MASK, 6); +static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point8_pwm, fan_curve, + FAN_CURVE_DEV_GPU | FAN_CURVE_PWM_MASK, 7); + static struct attribute *asus_fan_curve_attr[] = { /* CPU */ &sensor_dev_attr_pwm1_enable.dev_attr.attr, @@ -2856,6 +2899,24 @@ static struct attribute *asus_fan_curve_attr[] = { &sensor_dev_attr_pwm2_auto_point6_pwm.dev_attr.attr, &sensor_dev_attr_pwm2_auto_point7_pwm.dev_attr.attr, &sensor_dev_attr_pwm2_auto_point8_pwm.dev_attr.attr, + /* MID */ + &sensor_dev_attr_pwm3_enable.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point5_temp.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point6_temp.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point7_temp.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point8_temp.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point5_pwm.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point6_pwm.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point7_pwm.dev_attr.attr, + &sensor_dev_attr_pwm3_auto_point8_pwm.dev_attr.attr, NULL }; @@ -2875,6 +2936,9 @@ static umode_t asus_fan_curve_is_visible(struct kobject *kobj, if (asus->gpu_fan_curve_available && attr->name[3] == '2') return 0644; + if (asus->mid_fan_curve_available && attr->name[3] == '3') + return 0644; + return 0; } @@ -2904,7 +2968,14 @@ static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus) if (err) return err; - if (!asus->cpu_fan_curve_available && !asus->gpu_fan_curve_available) + err = fan_curve_check_present(asus, &asus->mid_fan_curve_available, + ASUS_WMI_DEVID_MID_FAN_CURVE); + if (err) + return err; + + if (!asus->cpu_fan_curve_available + && !asus->gpu_fan_curve_available + && !asus->mid_fan_curve_available) return 0; hwmon = devm_hwmon_device_register_with_groups( @@ -2973,6 +3044,8 @@ static int throttle_thermal_policy_write(struct asus_wmi *asus) asus->custom_fan_curves[FAN_CURVE_DEV_CPU].enabled = false; if (asus->gpu_fan_curve_available) asus->custom_fan_curves[FAN_CURVE_DEV_GPU].enabled = false; + if (asus->mid_fan_curve_available) + asus->custom_fan_curves[FAN_CURVE_DEV_MID].enabled = false; return 0; } diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index 2c03bda7703f..329efc086993 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -83,6 +83,7 @@ #define ASUS_WMI_DEVID_MID_FAN_CTRL 0x00110031 #define ASUS_WMI_DEVID_CPU_FAN_CURVE 0x00110024 #define ASUS_WMI_DEVID_GPU_FAN_CURVE 0x00110025 +#define ASUS_WMI_DEVID_MID_FAN_CURVE 0x00110032 /* Power */ #define ASUS_WMI_DEVID_PROCESSOR_STATE 0x00120012 From patchwork Tue Jun 20 02:56:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 110238 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3387464vqr; Mon, 19 Jun 2023 20:01:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6tzhNFedqmIwMB9m/Asp/dtDwPXtnDpYIlewmqA2c7c1BgoOtO4d0AJ1Ykqu34y2n1Kur1 X-Received: by 2002:a05:6a20:4405:b0:121:7454:be26 with SMTP id ce5-20020a056a20440500b001217454be26mr8059093pzb.42.1687230105694; Mon, 19 Jun 2023 20:01:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687230105; cv=none; d=google.com; s=arc-20160816; b=NZ9sLC6P3wTWwXfzgN1VSRUnq2h6IDsesC7xm4Sy5A0RQcSp5dAHDHAneCmRr36PXC ZFlGwA6T5wdcD6XNZNwz+Q5kapVv3J0htLxi3/bsv1Et1ORjLSYw0W55OgovQ+t933b9 iz/OSBChxWD2QVFit3urEMSirqPmMO/9ZmAqAe+TH03jMX3edF89ejecMNk3IIIBMctz cG+vTtQ/jRStXF4MUh4tHtwTGyHhmkz3oMpLjpT2fcbFf5I8YyUer+Iw0oWD/fITkkfe lUmosfuojcm4JvUzEyWi7KdFjtdS+ganPACZS61xncXCmYSgP1+/DwC0YaTpk8dlMvyv SCyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=I3tnp+mvvRjS8iBgvTLyJ+F7dhMK7joB/j/1+I6s5OA=; b=b02M4VtXs6BU4WbLg9UV6dquFpgF0DQig9AtMpjSaDoIMEDikXgh/0XK3PqBD/VjOL zsUe9vey8WqLY5z1ErVvczkMhS4xARnfs0maVS591a2YZB45FvOZSXCzI39FpdIS3V/Z kTjLaP4kp3n22LUn5xRfWdc4epT+OWHCViqdMc2Dk/zJqrV6coJpGKP3Dn2BLowtbGk6 2tvHU1/2GBb3azATcWROMKQ2Ntphr3yJHFtoXbxLLVDbvgHYzPInQpq1qog1d/M+J7+J EI8Z6SFN4H5sOMXpVhAE1jDUawx5UYN5g01hDb+ZBDM+L9mshTIZbS5sNWGwa+PEAyn3 X6mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b="Qt/pmuPD"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=iWsLiK6d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020aa796c6000000b00666ee6bd07bsi727987pfq.284.2023.06.19.20.01.31; Mon, 19 Jun 2023 20:01:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b="Qt/pmuPD"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=iWsLiK6d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230094AbjFTC53 (ORCPT + 99 others); Mon, 19 Jun 2023 22:57:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjFTC5V (ORCPT ); Mon, 19 Jun 2023 22:57:21 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5773C10CB; Mon, 19 Jun 2023 19:57:20 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id C3FE85C01F3; Mon, 19 Jun 2023 22:57:19 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 19 Jun 2023 22:57:19 -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:sender:subject:subject:to:to; s=fm3; t=1687229839; x= 1687316239; bh=I3tnp+mvvRjS8iBgvTLyJ+F7dhMK7joB/j/1+I6s5OA=; b=Q t/pmuPDeRtBQo208LusYXlL3i6+gIuCTEzDM+DVJ0eO+iiZlLX0xqbTjJvUTHfzL 2Du/09RFh0vQ//JoRt58VOSj9wI8y2zGLuixJEfnOjXFBqlmw/P5GCOWu7v6Kr5N S9mxBQMp63Fo/3d3VFGffLOBAxTVnPQldGEQ9j/oEvlGm+TfAFTpPQV0VHtdBrkI nmpVMhbPbvAl21hvrqF1/d4PKS1th6x/c1M2Le95xxjZA5odP4J76HLc+GU8HWwd yDUmH15qwqmSm0zioDawK7gMzBLYL7G5yUB5nBTZKUONrn0zCBUrrkRoAv2EyUoF me4enkalMeVv8j4dj/6hg== 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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1687229839; x= 1687316239; bh=I3tnp+mvvRjS8iBgvTLyJ+F7dhMK7joB/j/1+I6s5OA=; b=i WsLiK6dN2kpV4fDebywrxCLkPKNievDtFOrVnwFBWXkNc5lSx8C14QQggA3FhQr3 HlOqRc3RSImJqZCPr4cJyEDIe9+r0p7the82f7DB03Z03sjM9KoIgz+u9aKyCwCa wwePzgJVeokkNvGPuVELESULS3rgoWEpJi6yiMwvewoabT5jMPMut+dSsXI9sC7E eyj6ahMYgABgjdR0ks/YV5UMjNm1hz6BaqAES5HdoIUH0cjpjb/ZdagfP1YH8H4Y uRa4w1gnsGFAXAO0yohSeeYI6Kn5qt76XNdeeqC9G6/zgGEfH22fBDsSvCRHAJxr O1u99ObPNyRdDahnLnnmw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeefgedgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Jun 2023 22:57:16 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: corentin.chary@gmail.com, acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, markgross@kernel.org, jdelvare@suse.com, linux@roeck-us.net, "Luke D. Jones" Subject: [PATCH 4/8] platform/x86: asus-wmi: add WMI method to show if egpu connected Date: Tue, 20 Jun 2023 14:56:37 +1200 Message-Id: <20230620025641.53197-5-luke@ljones.dev> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620025641.53197-1-luke@ljones.dev> References: <20230620025641.53197-1-luke@ljones.dev> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769188995713234285?= X-GMAIL-MSGID: =?utf-8?q?1769188995713234285?= Exposes the WMI method which tells if the eGPU is properly connected on the devices that support it. Signed-off-by: Luke D. Jones --- .../ABI/testing/sysfs-platform-asus-wmi | 11 +++++++++- drivers/platform/x86/asus-wmi.c | 21 +++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 4 +++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index eb29e3023c7b..878daf7c2036 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -107,4 +107,13 @@ Description: Get the current charging mode being used: * 1 - Barrel connected charger, * 2 - USB-C charging - * 3 - Both connected, barrel used for charging \ No newline at end of file + * 3 - Both connected, barrel used for charging + +What: /sys/devices/platform//egpu_connected +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Show if the egpu (XG Mobile) is correctly connected: + * 0 - False, + * 1 - True diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index fb27218e51cf..0c8a4a46b121 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -243,6 +243,7 @@ struct asus_wmi { bool charge_mode_available; bool egpu_enable_available; + bool egpu_connect_available; bool dgpu_disable_available; bool gpu_mux_mode_available; @@ -709,6 +710,22 @@ static ssize_t egpu_enable_store(struct device *dev, } static DEVICE_ATTR_RW(egpu_enable); +/* Is eGPU connected? *********************************************************/ +static ssize_t egpu_connected_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + int result; + + result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_EGPU_CONNECTED); + if (result < 0) + return result; + + return sysfs_emit(buf, "%d\n", result); +} + +static DEVICE_ATTR_RO(egpu_connected); + /* gpu mux switch *************************************************************/ static ssize_t gpu_mux_mode_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -3645,6 +3662,7 @@ static struct attribute *platform_attributes[] = { &dev_attr_touchpad.attr, &dev_attr_charge_mode.attr, &dev_attr_egpu_enable.attr, + &dev_attr_egpu_connected.attr, &dev_attr_dgpu_disable.attr, &dev_attr_gpu_mux_mode.attr, &dev_attr_lid_resume.attr, @@ -3677,6 +3695,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, ok = asus->charge_mode_available; else if (attr == &dev_attr_egpu_enable.attr) ok = asus->egpu_enable_available; + else if (attr == &dev_attr_egpu_connected.attr) + ok = asus->egpu_connect_available; else if (attr == &dev_attr_dgpu_disable.attr) ok = asus->dgpu_disable_available; else if (attr == &dev_attr_gpu_mux_mode.attr) @@ -3943,6 +3963,7 @@ static int asus_wmi_add(struct platform_device *pdev) asus->charge_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_CHARGE_MODE); asus->egpu_enable_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_EGPU); + asus->egpu_connect_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_EGPU_CONNECTED); asus->dgpu_disable_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_DGPU); asus->gpu_mux_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_GPU_MUX); asus->kbd_rgb_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE); diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index 329efc086993..2034648f8cdf 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -100,7 +100,9 @@ /* Charging mode - 1=Barrel, 2=USB */ #define ASUS_WMI_DEVID_CHARGE_MODE 0x0012006C -/* dgpu on/off */ +/* epu is connected? 1 == true */ +#define ASUS_WMI_DEVID_EGPU_CONNECTED 0x00090018 +/* egpu on/off */ #define ASUS_WMI_DEVID_EGPU 0x00090019 /* dgpu on/off */ From patchwork Tue Jun 20 02:56:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 110235 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3386384vqr; Mon, 19 Jun 2023 19:59:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4JvDX6XyZDAu2MtihmKIGBiitcL2w+DXc6GWHKNgvHN+TUoXamy/9iIRp6sitEoL5g4dy4 X-Received: by 2002:a05:6808:1a29:b0:39e:c6e4:a4a8 with SMTP id bk41-20020a0568081a2900b0039ec6e4a4a8mr9497429oib.12.1687229967478; Mon, 19 Jun 2023 19:59:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687229967; cv=none; d=google.com; s=arc-20160816; b=z/Yi0+74qyXABZZyER/iImOJWMIYOy3k952Tg1ZBFzkutxRPYYEktWbuHZMa/zsFId DJG45HsGLJ4iixmzA1Ea/afDSebFJaUOcccgCmgasle9UUSCRJiQfnFXXLEPXceVeGqt tMmEnJr/vE6CFhpW00wiHmGY5mV20V/lnSIumX98889Y4C5z1OpqXkioKHZyxSOmKzEL RR4Eff9zM8uGwzyweff+Nn8sk9W056N0O34fkvGdgqpUlF77GL8Umi6fYEs3bC0zOF1S dD8E2jbXjZKNTS4kGt87sBYUQhW6LH8ky5XbTUB2qquAKC/9JnZHTDKZwse0guc8ES2q EdAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=bX+yoIucZ9XFfpbnNsMb71SaXrBmiqcLLOezSaDu8sg=; b=Bopk87RWRfk6XRxPzdNVbff353ZHgssX/2IyAiC3SgJfvXUuDJLg7EcuQ2K2g+4J4r j98mCeKWiC8Fy6EpTVZ++YmLppHixkgS2pGEf4DCwOdVIp0UiBfwNAhghdeTWFzXSofX Ymc6TAy5iPywHKsvjSlOhZBw2hQW/Qxee4/cJvg3dJvVUdmo/5d9jQgJEpiscMQwnM70 tpvJDfmdCWKA4tVK7wu1YbyUlrEiP1Ul8M+KZpKaCeaAPL0H++j0fyfIxZ5Gbxj597cr 0J2HG3LxJCiduNj8hyqeRfDnIpgTM7SI6PxIRoJN2dbSfxmhy04+Hsubfb32suVgiD9i jESw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=YPD2oF1w; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=VrrogAgt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u15-20020a17090a3fcf00b00256023fabd3si8817762pjm.151.2023.06.19.19.59.15; Mon, 19 Jun 2023 19:59:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=YPD2oF1w; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=VrrogAgt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230099AbjFTC5c (ORCPT + 99 others); Mon, 19 Jun 2023 22:57:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230102AbjFTC51 (ORCPT ); Mon, 19 Jun 2023 22:57:27 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECD0910C8; Mon, 19 Jun 2023 19:57:23 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 578885C01F9; Mon, 19 Jun 2023 22:57:23 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 19 Jun 2023 22:57:23 -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:sender:subject:subject:to:to; s=fm3; t=1687229843; x= 1687316243; bh=bX+yoIucZ9XFfpbnNsMb71SaXrBmiqcLLOezSaDu8sg=; b=Y PD2oF1wMxdvxaubUCi8j+10DdV/cmm3W9Hq5nJ+OMnRX2l9gb78DBeTQyQWbZIxv GHDmS0I68q93uae/F5yK5EtGCy2z9Q4ictMcpJ89GAe9mFt2sdCMW01bb4OuFKwE /K5Urku03Whz/DmBhBxLy7Zu8u2JOg54IEGCVYAXyCjQ3gBo9c905v8pdiayUTtn yoOa6PVcdkavmk+X2+dtRBvkiDrXsSbN+ik7DbWInZFc1ZC/UnoqJzuFE2L4qCR/ TaT3TcMTfRJdtvHnmYjAaTgj0bVctu9kVUR/rSn9bSmEu0pAYd0PODg6bqx3BYws qz+esZT5IAOe3IsXyHTpw== 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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1687229843; x= 1687316243; bh=bX+yoIucZ9XFfpbnNsMb71SaXrBmiqcLLOezSaDu8sg=; b=V rrogAgtPW3tlj4PUB7AH6VJ6yt7wJOUOUrupj2Wf+ZY4F+GJ4+xPgLw/x/9a1yX7 3x4OShyleERO8Ygtltsq85CYZyKio5L7AjcqFTJXqspVJnGaAQuCXX/5cv2tphBS zBRKmjGBlASOrargf8ZhEBsr7RBFujU6FGWfEoWvHO4jiHSaRK99aVC8GgqTxC+p UhGXcLKplFQmj+l8lbtH7BK79O5STZALyEc3ExwWOB1zPzY/trHVilzReUiJ9lXG p9qXKcJDgFUKtHxflV0DpzM8CzJ1afS1RzExhJ/Gz1kiFFQNTAvbo38hg/DzcYz6 p94L6GZTR6860QxYN1O/w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeefgedgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgepuden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Jun 2023 22:57:20 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: corentin.chary@gmail.com, acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, markgross@kernel.org, jdelvare@suse.com, linux@roeck-us.net, "Luke D. Jones" Subject: [PATCH 5/8] platform/x86: asus-wmi: don't allow eGPU switching if eGPU not connected Date: Tue, 20 Jun 2023 14:56:38 +1200 Message-Id: <20230620025641.53197-6-luke@ljones.dev> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620025641.53197-1-luke@ljones.dev> References: <20230620025641.53197-1-luke@ljones.dev> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769188850732106876?= X-GMAIL-MSGID: =?utf-8?q?1769188850732106876?= Check the ASUS_WMI_DEVID_EGPU_CONNECTED method for eGPU connection before allowing the ASUS_WMI_DEVID_EGPU method to run. Signed-off-by: Luke D. Jones --- drivers/platform/x86/asus-wmi.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 0c8a4a46b121..821addb284d7 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -693,6 +693,15 @@ static ssize_t egpu_enable_store(struct device *dev, if (enable > 1) return -EINVAL; + err = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_EGPU_CONNECTED); + if (err < 0) + return err; + if (err < 1) { + err = -ENODEV; + pr_warn("Failed to set egpu disable: %d\n", err); + return err; + } + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_EGPU, enable, &result); if (err) { pr_warn("Failed to set egpu disable: %d\n", err); From patchwork Tue Jun 20 02:56:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 110236 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3386443vqr; Mon, 19 Jun 2023 19:59:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6YXdt1J2bqvUbsjDfKKJaYCgeS1TGiX1Z8bHqdhB1P0gtO6R0UCuxcmVABCb6nYkrdTuWT X-Received: by 2002:a67:e404:0:b0:43c:381d:a04 with SMTP id d4-20020a67e404000000b0043c381d0a04mr2582432vsf.18.1687229975471; Mon, 19 Jun 2023 19:59:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687229975; cv=none; d=google.com; s=arc-20160816; b=RJF6LHaFWKUh44uDvnynLAw9V2Im3C/bBLjPo23qRKBc+RekMBTkwcJkNpM9qE73/I zqcl/UzOti5UsVxb60UaRowVHyC7+2J7QET8O+6Ot05IxPkEyvBMvB7M/DrFxXzgO/5l qZOqpyhNdXfeZWq2gA2iLyy/HyjngrlGDr5Ef2HgzKIbg1qVuICml3YvzBvq2uOnmBSk TjCGZiAbXCO/G+FcgT0ThsA8JmaC/8NQNMU4jMVvk+NmWCRJQtCkVn7TgnKnkH4oe6TJ PgY3D5NhW3Z3hiP58OhDxk3QLzz7lEaFPBnUO5eLENW8EXBNrGufquTcJQHBRSKaJ+zU EqiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=I8Xbl0BJKPKnoyHohJOj+6eHAELlgJ6aFeDPrAiW/Gk=; b=OENZYbNpx4Y4KsWtAB9RmHz0ML4FnF4ffC1hhXQOC2K66Mq+YqVkK9EL0tjYWqbbmR NPbKPdb1c0UI3EzqEgbbqF2/H2w7saTuD/s4fneuIiIAb/jo9H+6OQdsDb/BV504QX+p S5k39jfhHUK+05f/42EDQpnsVfI+PTGblTOx5db9HlPVjdMnB0hFqGCgpnnePuRT3C6w i/LFFkGyfjfXxTXMf7jaxFw8vZg+XEhBdZ44hFyK3nmJAFsMK2oWQckTO/DguHI/hGp+ C8HI02Z6YNfvTBgHAMoD6MjSxptDFu916L47DmHEhVs+bKtQHxBbEP/6Hv4/bUhkh4hn 6Ltw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=Ul27cz2O; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=dL1ub+6o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n4-20020a63b444000000b00533fce755adsi793988pgu.130.2023.06.19.19.59.23; Mon, 19 Jun 2023 19:59:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=Ul27cz2O; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=dL1ub+6o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230134AbjFTC5q (ORCPT + 99 others); Mon, 19 Jun 2023 22:57:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229683AbjFTC5k (ORCPT ); Mon, 19 Jun 2023 22:57:40 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2C0510E2; Mon, 19 Jun 2023 19:57:27 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id D0CD15C01F4; Mon, 19 Jun 2023 22:57:26 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 19 Jun 2023 22:57:26 -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:sender:subject:subject:to:to; s=fm3; t=1687229846; x= 1687316246; bh=I8Xbl0BJKPKnoyHohJOj+6eHAELlgJ6aFeDPrAiW/Gk=; b=U l27cz2Ow6Iux71DMKTU/qE+7APTsz3GrOvM1cDM8MY4739+fnsRd+f8xQzvuJLS8 fQu6r8Jfk4NEKPsI0tjSomyKucdStsyQ0gQZ0TGTjIDJMtbOcWsc3guu4TvyVnU8 MowVi+89gVjrATf2lAG8NruSOpjWOGXHZDRtAM2aTlz1vjJrZrkWJ/z6XLLND7gy OtRph6CyDLQSmWu9b/ZJmLbFQ75uLIBVYubeucK8EK0ZA3kytnNK+IR3mjdR9km2 pMsO7kGRQu9s4KC0I046HwuGFERmgLFdJE+TKs5/tn9k6MuF5FZ0ZYQ5eLBHQEoz aTCeDlqCgbLNz8Hb18TkQ== 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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1687229846; x= 1687316246; bh=I8Xbl0BJKPKnoyHohJOj+6eHAELlgJ6aFeDPrAiW/Gk=; b=d L1ub+6ozQsGMvzSk2rEfK1h6H16yBCI7ytDvl4g5PQ/gfdzK2DR7Agd8Isk6C4gZ 4y3bs7B0zAezqah+Uf3Lzx5yOND5lFcwEobfT16aFA1ggEixD+dXcRIbC7TueZll hvrh6eey6/0LB6XSNLHQ37GStLiODjzGKWONbqiFpGmuO1cD0VsYtP4D7PCMH8fV PBGdmxEsrOYhahuwkHtlqrlcj/liO5MfWL9nVbVSZx0h0ZeP5qfui6MeL3p571ZV gChzmu8uRQcZ6q7AhBzDag/mDYu28K8P+mNmOqg1K9JWk5X8Ex7i4WfGlc/QkaGP 457tMSaSuZoRsBIekG4FQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeefgedgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgepvden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Jun 2023 22:57:23 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: corentin.chary@gmail.com, acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, markgross@kernel.org, jdelvare@suse.com, linux@roeck-us.net, "Luke D. Jones" Subject: [PATCH 6/8] platform/x86: asus-wmi: add safety checks to gpu switching Date: Tue, 20 Jun 2023 14:56:39 +1200 Message-Id: <20230620025641.53197-7-luke@ljones.dev> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620025641.53197-1-luke@ljones.dev> References: <20230620025641.53197-1-luke@ljones.dev> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769188858397002871?= X-GMAIL-MSGID: =?utf-8?q?1769188858397002871?= Add safety checking to dgpu_disable, egpu_enable, gpu_mux_mode. These checks prevent users from doing such things as: - disabling the dGPU while is muxed to drive the internal screen - enabling the eGPU which also disables the dGPU, while muxed to the internal screen - switching the MUX to dGPU while the dGPU is disabled Signed-off-by: Luke D. Jones --- drivers/platform/x86/asus-wmi.c | 50 ++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 821addb284d7..602426a7fb41 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -645,6 +645,18 @@ static ssize_t dgpu_disable_store(struct device *dev, if (disable > 1) return -EINVAL; + if (asus->gpu_mux_mode_available) { + result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_GPU_MUX); + if (result < 0) + /* An error here may signal greater failure of GPU handling */ + return result; + if (!result && disable) { + err = -ENODEV; + pr_warn("Can not disable dGPU when the MUX is in dGPU mode: %d\n", err); + return err; + } + } + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_DGPU, disable, &result); if (err) { pr_warn("Failed to set dgpu disable: %d\n", err); @@ -693,7 +705,7 @@ static ssize_t egpu_enable_store(struct device *dev, if (enable > 1) return -EINVAL; - err = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_EGPU_CONNECTED); + result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_EGPU_CONNECTED); if (err < 0) return err; if (err < 1) { @@ -702,6 +714,18 @@ static ssize_t egpu_enable_store(struct device *dev, return err; } + if (asus->gpu_mux_mode_available) { + result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_GPU_MUX); + if (result < 0) + /* An error here may signal greater failure of GPU handling */ + return result; + if (!result && enable) { + err = -ENODEV; + pr_warn("Can not enable eGPU when the MUX is in dGPU mode: %d\n", err); + return err; + } + } + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_EGPU, enable, &result); if (err) { pr_warn("Failed to set egpu disable: %d\n", err); @@ -764,6 +788,30 @@ static ssize_t gpu_mux_mode_store(struct device *dev, if (optimus > 1) return -EINVAL; + if (asus->dgpu_disable_available) { + result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_DGPU); + if (result < 0) + /* An error here may signal greater failure of GPU handling */ + return result; + if (result && !optimus) { + err = -ENODEV; + pr_warn("Can not switch MUX to dGPU mode when dGPU is disabled: %d\n", err); + return err; + } + } + + if (asus->egpu_enable_available) { + result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_EGPU); + if (result < 0) + /* An error here may signal greater failure of GPU handling */ + return result; + if (result && !optimus) { + err = -ENODEV; + pr_warn("Can not switch MUX to dGPU mode when eGPU is enabled: %d\n", err); + return err; + } + } + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_GPU_MUX, optimus, &result); if (err) { dev_err(dev, "Failed to set GPU MUX mode: %d\n", err); From patchwork Tue Jun 20 02:56:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 110240 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3390597vqr; Mon, 19 Jun 2023 20:10:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4R7z/bfMEYd/JpRlydY1tSh/5whA6zaLh4BUBENXoG3zLLMpv9BK6Xx9DcA/dyZEOLYz2X X-Received: by 2002:a17:90a:9bc6:b0:25e:abc1:6fd7 with SMTP id b6-20020a17090a9bc600b0025eabc16fd7mr15176537pjw.12.1687230629885; Mon, 19 Jun 2023 20:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687230629; cv=none; d=google.com; s=arc-20160816; b=mda3REftvLIVEzCmRExXGQk07Sz+Qang6UXMXQRWkpDlcAxFNis1iUUipuFwTLcNsN Bt3BEli/VZrpak9lmMEW57HScQEzHmmBiiN1scQ1DGO7/AGUY+d8li1sN4ft6UA7IWjO 5LRWHTXdtT1URjRWF89ql5eTSuSYRdapVW9ljy2ixXQ4r8i30lMBrt7f8tMUrFl8LYza ZzXFTUdroDtgZvdOusx42tHuGk6cNn6UTUup537xL8W8IUcdgsa7Qjsiqc9FDoT75g9b BROHJpooZ/MgC+EENJAER+DyNCZrMNVykKXCAB5gTrraVINxZBhzlrmEYVps2swEz9N7 UANg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=XyYZavQtwXjIJqr+Wx4YS9kbDJ4aeW/qdYMdNX69/gU=; b=dn+Z53ftTr9SK+FlEgV2P43KObJt6k5X/JpzQlWvF9MH0fANVlD530r3ZdfvlxCEAb 5etOJ5fxHIVvfKWkVyDKoNKRyYi7+G/Iixt7YHl0j046NnzUbOhEqWgQloSBjV2IYVgc 1+g0JzRQQpMIXfh6qyY/BOcvB0obmMcsB8FyBZa7qD4n7c20/5pYVIYyFdq6P7uFhKEk gb44ah+qlYIlalX3DpIjBEdEC/XQgzaU1ZXcw45oaCYpcsGVpH6WCitJoVVDI5PnG/9G 67eK4zXUI4w0esYuG1YwtnCjrw2w8B8I9iDgh3sSCCkFAINTYBVsBCphkkpflxtu2PC3 TPLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=GSF7Y3ah; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ER7NpZCY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u7-20020a17090ae00700b0025bf848104fsi8376968pjy.155.2023.06.19.20.10.15; Mon, 19 Jun 2023 20:10:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=GSF7Y3ah; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ER7NpZCY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229710AbjFTC56 (ORCPT + 99 others); Mon, 19 Jun 2023 22:57:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230125AbjFTC5u (ORCPT ); Mon, 19 Jun 2023 22:57:50 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50B7A1994; Mon, 19 Jun 2023 19:57:31 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 6A0AA5C01F5; Mon, 19 Jun 2023 22:57:30 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 19 Jun 2023 22:57:30 -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:sender:subject:subject:to:to; s=fm3; t=1687229850; x= 1687316250; bh=XyYZavQtwXjIJqr+Wx4YS9kbDJ4aeW/qdYMdNX69/gU=; b=G SF7Y3ahXA2YOb5KxbzirV312WbXX1deQzuyBAx80rTDQrSMYJblueSoN1tqTDDud 7dvhBMRof5umexvpQnl6B/aokr442nqEOyPnngmgDQNNGSN73PRBNUNkRVB+HIU8 TovT5nznPeMZJz3ZCnxhe/H1DQUgxkiNNV6ga6qyof+aT5ZrmxxV6D3GGDzAe6HF Tq0LF5e/dWjPiNbX3vGfD5RNT4X7B0Xd55xHJtACwKSm90TBgCRbOv4bgqxHV+b6 F9IchEknaqHlQzyCrzSoD68rADPJTfoDnH8LsZS6aVCUu7+dPh0KpuNSRX4SYyUI see9ZrGODS08j4Ch3yF+Q== 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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1687229850; x= 1687316250; bh=XyYZavQtwXjIJqr+Wx4YS9kbDJ4aeW/qdYMdNX69/gU=; b=E R7NpZCYr9WzpS7ise/LsXSlBKFqMaKGpLSo8tUzqdKLe6qgyR2jFbWRKQY22P+O+ I04hjaRokXdt8YuxsSPyYavxUoJryADbrnYrP5rvCrxIBsm2b3Vvlc8OP/PJl6i+ DFdtD96sCCZf9+Ob+azTMkq+spYRpTMAsR8vo7NzslW7S1AhWkc2LEdBjFdTv98C M+QzjEw8qnxJ0UfJy/6/9YiOClCr1/Hsbn5CV5+NXy+vTMRTy0U7i7a43ye7FvST WHj5JCLML8Z61Dw9LRTIFq8SuRq9Q9JxpmLxcYyW+7Ja+WxTH5vuMcxkCzfyx/Oi 12EWGSS+348ydusXAWpLg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeefgedgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgepuden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Jun 2023 22:57:27 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: corentin.chary@gmail.com, acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, markgross@kernel.org, jdelvare@suse.com, linux@roeck-us.net, "Luke D. Jones" Subject: [PATCH 7/8] platform/x86: asus-wmi: support setting mini-LED mode Date: Tue, 20 Jun 2023 14:56:40 +1200 Message-Id: <20230620025641.53197-8-luke@ljones.dev> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620025641.53197-1-luke@ljones.dev> References: <20230620025641.53197-1-luke@ljones.dev> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769189544753315104?= X-GMAIL-MSGID: =?utf-8?q?1769189544753315104?= Support changing the mini-LED mode on some of the newer ASUS laptops. Signed-off-by: Luke D. Jones --- .../ABI/testing/sysfs-platform-asus-wmi | 9 ++++ drivers/platform/x86/asus-wmi.c | 53 +++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 1 + 3 files changed, 63 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index 878daf7c2036..5624bdef49cb 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -117,3 +117,12 @@ Description: Show if the egpu (XG Mobile) is correctly connected: * 0 - False, * 1 - True + +What: /sys/devices/platform//mini_led_mode +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Change the mini-LED mode: + * 0 - Single-zone, + * 1 - Multi-zone diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 602426a7fb41..1fc9e8afc2f3 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -265,6 +265,7 @@ struct asus_wmi { bool battery_rsoc_available; bool panel_overdrive_available; + bool mini_led_mode_available; struct hotplug_slot hotplug_slot; struct mutex hotplug_lock; @@ -1820,6 +1821,54 @@ static ssize_t panel_od_store(struct device *dev, } static DEVICE_ATTR_RW(panel_od); +/* Mini-LED mode **************************************************************/ +static ssize_t mini_led_mode_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + int result; + + result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_MINI_LED_MODE); + if (result < 0) + return result; + + return sysfs_emit(buf, "%d\n", result); +} + +static ssize_t mini_led_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int result, err; + u32 mode; + + struct asus_wmi *asus = dev_get_drvdata(dev); + + result = kstrtou32(buf, 10, &mode); + if (result) + return result; + + if (mode > 1) + return -EINVAL; + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_MINI_LED_MODE, mode, &result); + + if (err) { + pr_warn("Failed to set mini-LED: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set mini-LED mode (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "mini_led_mode"); + + return count; +} +static DEVICE_ATTR_RW(mini_led_mode); + /* Quirks *********************************************************************/ static void asus_wmi_set_xusb2pr(struct asus_wmi *asus) @@ -3727,6 +3776,7 @@ static struct attribute *platform_attributes[] = { &dev_attr_fan_boost_mode.attr, &dev_attr_throttle_thermal_policy.attr, &dev_attr_panel_od.attr, + &dev_attr_mini_led_mode.attr, NULL }; @@ -3764,6 +3814,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, ok = asus->throttle_thermal_policy_available; else if (attr == &dev_attr_panel_od.attr) ok = asus->panel_overdrive_available; + else if (attr == &dev_attr_mini_led_mode.attr) + ok = asus->mini_led_mode_available; if (devid != -1) ok = !(asus_wmi_get_devstate_simple(asus, devid) < 0); @@ -4026,6 +4078,7 @@ static int asus_wmi_add(struct platform_device *pdev) asus->kbd_rgb_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE); asus->kbd_rgb_state_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_STATE); asus->panel_overdrive_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PANEL_OD); + asus->mini_led_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_MINI_LED_MODE); err = fan_boost_mode_check_present(asus); if (err) diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index 2034648f8cdf..ea80361ac6c7 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -66,6 +66,7 @@ #define ASUS_WMI_DEVID_CAMERA 0x00060013 #define ASUS_WMI_DEVID_LID_FLIP 0x00060062 #define ASUS_WMI_DEVID_LID_FLIP_ROG 0x00060077 +#define ASUS_WMI_DEVID_MINI_LED_MODE 0x0005001E /* Storage */ #define ASUS_WMI_DEVID_CARDREADER 0x00080013 From patchwork Tue Jun 20 02:56:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 110241 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3390652vqr; Mon, 19 Jun 2023 20:10:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5GnnKU+Kmz67TDncmew8gq6JqT7yYM666iruNZRlpFVMC2GiaxKEJN/jltR6r1tndtJRPx X-Received: by 2002:a05:6a20:3c8e:b0:120:abf9:4f0a with SMTP id b14-20020a056a203c8e00b00120abf94f0amr9119109pzj.15.1687230638660; Mon, 19 Jun 2023 20:10:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687230638; cv=none; d=google.com; s=arc-20160816; b=glC6juc7DuDm7va8Lamt1lLmMjWBFHL8rmROZ32fPvHsRqHD0d9h3+Z6rtdy8BpIQm H87TbdRpxrCo7x/LNPxxfQm8f9N3gxL9Ngf5HT7wy6aWYpztxcSNSPNiTV6hc/LsmJ4o NIuvq1KiTov6PRsADbIDp1gVA06FeO9/YlXHB8/v2Y9WBFZ9zpXdLokuRME4i7ae6PTY AZ/D+iZdmEDpAwOp706pgwL8nTjA5spiiKsOFCnN+BMduk1mZ4itE/08GdErw7dOIrVX KXFKhPUya+4js5FASkXE6tBWVegBjDHMUW2A4TO1hplEH4RWAJGdBUq+UzvtnEclCwRH HCuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=320HCxo0m6kqsTndJmmY8l9xJ3+BedXN0i38xL7mNwQ=; b=gwf83P2N+PKRjj2Cc2TNx98RIiFuE61iOdAP9jTw+4W2HLgBbTyyJahko5tz8dFRSN SBMAxCOCKbtpXgUWz1EoQzSyGkAeMMPkxW+vNbwjVL2c2Y+UNVxKazjo9kEh4U/CY3Go s2SuFyQIV/nEN1Ahs2M5fB3tdGXjbAl7NqkeObIE7ELgQ6aSvwzr5D/HWvhxWeSx5pev f4ilDPs52+q+37E7VKtG8Po5iXfH8dPi8oyaBo5qSC7cKdF8z/Zd1meg7LWJPcNIns3Y WmEdLmifQKdvXaitV+EOdpTeyUzp04Zih3CT9b76lyygsRk5qu4nq9kb7Do665pA441m rJTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=umDcJSER; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=jhhqgncB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w9-20020a639349000000b0053fee168aabsi733037pgm.742.2023.06.19.20.10.26; Mon, 19 Jun 2023 20:10:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=umDcJSER; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=jhhqgncB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229656AbjFTC6M (ORCPT + 99 others); Mon, 19 Jun 2023 22:58:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbjFTC6K (ORCPT ); Mon, 19 Jun 2023 22:58:10 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A28B110DE; Mon, 19 Jun 2023 19:57:42 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id F28135C01F3; Mon, 19 Jun 2023 22:57:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 19 Jun 2023 22:57:33 -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:sender:subject:subject:to:to; s=fm3; t=1687229853; x= 1687316253; bh=320HCxo0m6kqsTndJmmY8l9xJ3+BedXN0i38xL7mNwQ=; b=u mDcJSERBSJI9yCIl3k70MvctiU9ltynKcSj6YwKEfJFUk+Lt5Ml496RuhVSNvuzP ipP42JeHs1a4i6M4K3o1TyhaPUD1O2phOdjGqRwC5FQrGKzL2PM59+qhhmvxhKta iVEFNfDF18lmsM/03drgET8K+Z5RTL+dPSRa4m+OFFFHm/frFbt05JFFAtpMJvYb pCaIIiwcjcfWpZImAK5mmc+j2e+kEizqVCX2AgqYmWHagvmWh6PqRLjJmXTlRrCj MCQtmDSY4y0VHrq55vjn+3wyBBTKQVrN3GH4xD0heIRtulB8w+o+pd+S+eKYfYvU HZBP0CFXAPynBQdpfMt/Q== 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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1687229853; x= 1687316253; bh=320HCxo0m6kqsTndJmmY8l9xJ3+BedXN0i38xL7mNwQ=; b=j hhqgncBCIgwU1Rv7lz1TM5RzQSJtGENImMEVZcPjd4Qet4wpXS4dlQvNqzx6YWKo m+zZl84eEi9ZKejyf2RFM6CwxAwajjFGD+NcSoRiumq0i33GSeiB9KvAKNb9ioch IfXy5zKTS8TK9D9IBjrv6qlxa/oKlwOJDi7hxqViBTz2CkegnU+cn0Tdh70GvFhU chMsDX8aa9/Biy19mrqSgwXLQD8nBAqYXM2C0bQdmw/aOoeGebLjDO6dxmcIxM7g /Q2qB2UTPjC3bHLiI8fXWF+5Tca9lc10QeipQL44f0yenrA11WgTy8QJhVdWCCKX bpLNo8h7QnQ9QA4SvjUYQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeefgedgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgepvden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Jun 2023 22:57:30 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: corentin.chary@gmail.com, acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, markgross@kernel.org, jdelvare@suse.com, linux@roeck-us.net, "Luke D. Jones" Subject: [PATCH 8/8] platform/x86: asus-wmi: expose dGPU and CPU tunables for ROG Date: Tue, 20 Jun 2023 14:56:41 +1200 Message-Id: <20230620025641.53197-9-luke@ljones.dev> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620025641.53197-1-luke@ljones.dev> References: <20230620025641.53197-1-luke@ljones.dev> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769189554295743278?= X-GMAIL-MSGID: =?utf-8?q?1769189554295743278?= Expose various CPU and dGPU tunables that are available on many ASUS ROG laptops. The tunables shown in sysfs will vary depending on the CPU and dGPU vendor. All of these variables are write only and there is no easy way to find what the defaults are. In general they seem to default to the max value the vendor sets for the CPU and dGPU package - this is not the same as the min/max writable value. Values written to these variables that are beyond the capabilities of the CPU are ignored by the laptop. Signed-off-by: Luke D. Jones --- .../ABI/testing/sysfs-platform-asus-wmi | 72 ++++ drivers/platform/x86/asus-wmi.c | 365 ++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 11 + 3 files changed, 448 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index 5624bdef49cb..64c1c76d3fb8 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -126,3 +126,75 @@ Description: Change the mini-LED mode: * 0 - Single-zone, * 1 - Multi-zone + +What: /sys/devices/platform//ppt_total +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Set the Package Power Target total of CPU, corresponds to PL1 on Intel: + * min=5, max=250 + +What: /sys/devices/platform//ppt_sppt +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Set the Slow Package Power Tracking Limit of CPU, corresponds to PL2 on Intel: + * min=5, max=250 + +What: /sys/devices/platform//ppt_fppt +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Set the Fast Package Power Tracking Limit of CPU: + * min=5, max=250 + +What: /sys/devices/platform//ppt_edc +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Set the Electrical Design Current for the CPU, peak current: + * min=5, max=250 + +What: /sys/devices/platform//ppt_tdc +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Set the Thermal Design Current for the CPU, sustained current: + * min=5, max=250 + +What: /sys/devices/platform//ppt_limit +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Set the CPU PPT limit: + * min=5, max=130 + +What: /sys/devices/platform//ppt_limit_slow +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Set the CPU PPT slow limit: + * min=5, max=130 + +What: /sys/devices/platform//nv_gpu_boost +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Set the extra current boost of the Nvidia dGPU: + * min=5, max=25 + +What: /sys/devices/platform//nv_gpu_temp_target +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Set the temperature limit of the Nvidia dGPU: + * min=75, max=87 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 1fc9e8afc2f3..62cee13f5576 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -117,6 +117,16 @@ module_param(fnlock_default, bool, 0444); /* Mask to determine if setting temperature or percentage */ #define FAN_CURVE_PWM_MASK 0x04 +/* Limits for tunables available on ASUS ROG laptops */ +#define PPT_TOTAL_MIN 5 +#define PPT_TOTAL_MAX 250 +#define PPT_CPU_MIN 5 +#define PPT_CPU_MAX 130 +#define NVIDIA_GPU_BOOST_MIN 5 +#define NVIDIA_GPU_BOOST_MAX 25 +#define NVIDIA_GPU_TEMP_MIN 75 +#define NVIDIA_GPU_TEMP_MAX 87 + static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL }; static int throttle_thermal_policy_write(struct asus_wmi *); @@ -247,6 +257,17 @@ struct asus_wmi { bool dgpu_disable_available; bool gpu_mux_mode_available; + /* Tunables provided by ASUS for gaming laptops */ + bool ppt_total_available; + bool ppt_edc_available; + bool ppt_tdc_available; + bool ppt_sppt_available; + bool ppt_limit_available; + bool ppt_limit_slow_available; + bool ppt_fppt_available; + bool nv_gpu_boost_available; + bool nv_gpu_temp_target_available; + bool kbd_rgb_mode_available; bool kbd_rgb_state_available; @@ -946,6 +967,312 @@ static const struct attribute_group *kbd_rgb_mode_groups[] = { NULL, }; +/* Tunable: PPT Total **********************************************************/ +static ssize_t ppt_total_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int result, err; + u32 value; + + struct asus_wmi *asus = dev_get_drvdata(dev); + + result = kstrtou32(buf, 10, &value); + if (result) + return result; + + if (value < PPT_TOTAL_MIN || value > PPT_TOTAL_MAX) + return -EINVAL; + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PPT_TOTAL, value, &result); + if (err) { + pr_warn("Failed to set ppt_total: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set ppt_total (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_total"); + + return count; +} +static DEVICE_ATTR_WO(ppt_total); + +/* Tunable: PPT EDC **********************************************************/ +static ssize_t ppt_edc_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int result, err; + u32 value; + + struct asus_wmi *asus = dev_get_drvdata(dev); + + result = kstrtou32(buf, 10, &value); + if (result) + return result; + + if (value < PPT_TOTAL_MIN || value > PPT_TOTAL_MAX) + return -EINVAL; + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PPT_EDC, value, &result); + if (err) { + pr_warn("Failed to set ppt_edc: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set ppt_edc (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_edc"); + + return count; +} +static DEVICE_ATTR_WO(ppt_edc); + +/* Tunable: PPT TDC ***********************************************************/ +static ssize_t ppt_tdc_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int result, err; + u32 value; + + struct asus_wmi *asus = dev_get_drvdata(dev); + + result = kstrtou32(buf, 10, &value); + if (result) + return result; + + if (value < PPT_TOTAL_MIN || value > PPT_TOTAL_MAX) + return -EINVAL; + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PPT_TDC, value, &result); + if (err) { + pr_warn("Failed to set ppt_tdc: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set ppt_tdc (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_tdc"); + + return count; +} +static DEVICE_ATTR_WO(ppt_tdc); + +/* Tunable: PPT APU sPPT ******************************************************/ +static ssize_t ppt_sppt_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int result, err; + u32 value; + + struct asus_wmi *asus = dev_get_drvdata(dev); + + result = kstrtou32(buf, 10, &value); + if (result) + return result; + + if (value < PPT_TOTAL_MIN || value > PPT_TOTAL_MAX) + return -EINVAL; + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PPT_SPPT, value, &result); + if (err) { + pr_warn("Failed to set ppt_sppt: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set ppt_sppt (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_sppt"); + + return count; +} +static DEVICE_ATTR_WO(ppt_sppt); + +/* Tunable: PPT APU fPPT ******************************************************/ +static ssize_t ppt_fppt_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int result, err; + u32 value; + + struct asus_wmi *asus = dev_get_drvdata(dev); + + result = kstrtou32(buf, 10, &value); + if (result) + return result; + + if (value < PPT_TOTAL_MIN || value > PPT_TOTAL_MAX) + return -EINVAL; + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PPT_FPPT, value, &result); + if (err) { + pr_warn("Failed to set ppt_fppt: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set ppt_fppt (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_fpu_sppt"); + + return count; +} +static DEVICE_ATTR_WO(ppt_fppt); + +/* Tunable: PPT APU limit *****************************************************/ +static ssize_t ppt_limit_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int result, err; + u32 value; + + struct asus_wmi *asus = dev_get_drvdata(dev); + + result = kstrtou32(buf, 10, &value); + if (result) + return result; + + if (value < PPT_CPU_MIN || value > PPT_CPU_MAX) + return -EINVAL; + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PPT_LIMIT, value, &result); + if (err) { + pr_warn("Failed to set ppt_limit: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set ppt_limit (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_limit"); + + return count; +} +static DEVICE_ATTR_WO(ppt_limit); + +/* Tunable: PPT limit slow ****************************************************/ +static ssize_t ppt_limit_slow_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int result, err; + u32 value; + + struct asus_wmi *asus = dev_get_drvdata(dev); + + result = kstrtou32(buf, 10, &value); + if (result) + return result; + + if (value < PPT_CPU_MIN || value > PPT_CPU_MAX) + return -EINVAL; + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PPT_LIMIT_SLOW, value, &result); + if (err) { + pr_warn("Failed to set ppt_limit_slow: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set ppt_limit_slow (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_limit_slow"); + + return count; +} +static DEVICE_ATTR_WO(ppt_limit_slow); + +/* Tunable: NVIDIA GPU boost **************************************************/ +static ssize_t nv_gpu_boost_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int result, err; + u32 value; + + struct asus_wmi *asus = dev_get_drvdata(dev); + + result = kstrtou32(buf, 10, &value); + if (result) + return result; + + if (value < NVIDIA_GPU_BOOST_MIN || value > NVIDIA_GPU_BOOST_MAX) + return -EINVAL; + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_NV_GPU_BOOST, value, &result); + if (err) { + pr_warn("Failed to set nv_gpu_boost: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set nv_gpu_boost (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "nv_gpu_boost"); + + return count; +} +static DEVICE_ATTR_WO(nv_gpu_boost); + +/* Tunable: NVIDIA GPU temperature target *************************************/ +static ssize_t nv_gpu_temp_target_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int result, err; + u32 value; + + struct asus_wmi *asus = dev_get_drvdata(dev); + + result = kstrtou32(buf, 10, &value); + if (result) + return result; + + if (value < NVIDIA_GPU_TEMP_MIN || value > NVIDIA_GPU_TEMP_MAX) + return -EINVAL; + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_NV_GPU_TEMP_TARGET, value, &result); + if (err) { + pr_warn("Failed to set nv_gpu_temp_target: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set nv_gpu_temp_target (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "nv_gpu_temp_target"); + + return count; +} +static DEVICE_ATTR_WO(nv_gpu_temp_target); + /* Battery ********************************************************************/ /* The battery maximum charging percentage */ @@ -3775,6 +4102,15 @@ static struct attribute *platform_attributes[] = { &dev_attr_als_enable.attr, &dev_attr_fan_boost_mode.attr, &dev_attr_throttle_thermal_policy.attr, + &dev_attr_ppt_total.attr, + &dev_attr_ppt_edc.attr, + &dev_attr_ppt_tdc.attr, + &dev_attr_ppt_sppt.attr, + &dev_attr_ppt_fppt.attr, + &dev_attr_ppt_limit.attr, + &dev_attr_ppt_limit_slow.attr, + &dev_attr_nv_gpu_boost.attr, + &dev_attr_nv_gpu_temp_target.attr, &dev_attr_panel_od.attr, &dev_attr_mini_led_mode.attr, NULL @@ -3812,6 +4148,24 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, ok = asus->fan_boost_mode_available; else if (attr == &dev_attr_throttle_thermal_policy.attr) ok = asus->throttle_thermal_policy_available; + else if (attr == &dev_attr_ppt_total.attr) + ok = asus->ppt_total_available; + else if (attr == &dev_attr_ppt_edc.attr) + ok = asus->ppt_edc_available; + else if (attr == &dev_attr_ppt_tdc.attr) + ok = asus->ppt_tdc_available; + else if (attr == &dev_attr_ppt_sppt.attr) + ok = asus->ppt_sppt_available; + else if (attr == &dev_attr_ppt_fppt.attr) + ok = asus->ppt_fppt_available; + else if (attr == &dev_attr_ppt_limit.attr) + ok = asus->ppt_limit_available; + else if (attr == &dev_attr_ppt_limit_slow.attr) + ok = asus->ppt_limit_slow_available; + else if (attr == &dev_attr_nv_gpu_boost.attr) + ok = asus->nv_gpu_boost_available; + else if (attr == &dev_attr_nv_gpu_temp_target.attr) + ok = asus->nv_gpu_temp_target_available; else if (attr == &dev_attr_panel_od.attr) ok = asus->panel_overdrive_available; else if (attr == &dev_attr_mini_led_mode.attr) @@ -4077,6 +4431,17 @@ static int asus_wmi_add(struct platform_device *pdev) asus->gpu_mux_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_GPU_MUX); asus->kbd_rgb_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE); asus->kbd_rgb_state_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_STATE); + asus->ppt_total_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_TOTAL); + asus->ppt_edc_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_EDC); + asus->ppt_tdc_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_TDC); + asus->ppt_sppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_SPPT); + asus->ppt_fppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_FPPT); + asus->ppt_limit_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_LIMIT); + asus->ppt_limit_slow_available = asus_wmi_dev_is_present(asus, + ASUS_WMI_DEVID_PPT_LIMIT_SLOW); + asus->nv_gpu_boost_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_NV_GPU_BOOST); + asus->nv_gpu_temp_target_available = asus_wmi_dev_is_present(asus, + ASUS_WMI_DEVID_NV_GPU_TEMP_TARGET); asus->panel_overdrive_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PANEL_OD); asus->mini_led_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_MINI_LED_MODE); diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index ea80361ac6c7..d17ae2eb0f8d 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -86,6 +86,17 @@ #define ASUS_WMI_DEVID_GPU_FAN_CURVE 0x00110025 #define ASUS_WMI_DEVID_MID_FAN_CURVE 0x00110032 +/* Tunables for AUS ROG laptops */ +#define ASUS_WMI_DEVID_PPT_TOTAL 0x001200A0 +#define ASUS_WMI_DEVID_PPT_EDC 0x001200A1 +#define ASUS_WMI_DEVID_PPT_TDC 0x001200A2 +#define ASUS_WMI_DEVID_PPT_SPPT 0x001200A3 +#define ASUS_WMI_DEVID_PPT_LIMIT 0x001200B0 +#define ASUS_WMI_DEVID_PPT_LIMIT_SLOW 0x001200B1 +#define ASUS_WMI_DEVID_PPT_FPPT 0x001200C1 +#define ASUS_WMI_DEVID_NV_GPU_BOOST 0x001200C0 +#define ASUS_WMI_DEVID_NV_GPU_TEMP_TARGET 0x001200C2 + /* Power */ #define ASUS_WMI_DEVID_PROCESSOR_STATE 0x00120012