From patchwork Fri Jun 30 05:35:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 114578 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10131672vqr; Thu, 29 Jun 2023 23:03:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5WEEVvP//4U2XLBdlOXriokMJOb/HUaBPxt5ImX+3tiHtpAPLBsP/mu+UgEyI+ssNvbKQw X-Received: by 2002:a6b:c897:0:b0:780:cb36:6f24 with SMTP id y145-20020a6bc897000000b00780cb366f24mr2407013iof.2.1688105020926; Thu, 29 Jun 2023 23:03:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688105020; cv=none; d=google.com; s=arc-20160816; b=XxCbGkm614wkl3U+r45SWM8x0vFV+Mn17neATtWcfeEYrvsjYpBmsg0YXuobo4lNIp pLaBJmNIxPzZYBDSZSDhIt7ggvxTH25ZQjBt1OtHsWIdp6+9IpJb8GXzV3HaIijrf/kt A356CiYf071YGUZJFYM6UDwRZOs1ioZSdiYn71zXWwrKd6qf7G3retSzdwraD4kpywPW JMcFHmaOM4TXhhU0q7m3+uAzyoW4QsiAtp6HAgHwPlFon1DJio85/YL8ZgWt23206gdF v9cXJZahsiIF46xtmPBTxBDN+AOdVniMUgfgRTJJs5UpHIFnisF7CAZaJRWlnzk//4zI AV1w== 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=9LoAP+lBJvN0CB58nNnqiigraBS5nNzcGrpOaynMiyM=; fh=52RqnqzHFu3c3gS8VqgRtcRPBRgGlf5eGe8HkjfR8FI=; b=Ab/j1cmtr5gB7ZXPOJB+ktG4aqFLzuvR15XN6nPVFUap4LjY0DHW9ulP5XBpNbbRT5 87Jwt5odkRdjxVSCyFcvl6If32XYp3RnDuyTnF9csrOv0msIrkrdzNWOGOYPVNHGFS5w EXmHmhVwKi9ezCXvodNvfQq/QSiO1VY9wMammnPfHywvyp0ESbfR3yYGqn9CMAh9qIKH 28tLAUJUzdjYU0Mlj/A2pfgHyAft62fpRo5Tv1Ngs24CuepsQj3Fe5+T+So2sPIqXBmP nEgWDInX0T2h7gOxUk22orqMQcJ4GSBS6EEAlHVSFHdnrHYWo476mJuhTZk727CaEYM/ UDwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=lK78Ij8M; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=h89N3O7P; 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 z17-20020a634c11000000b0055384255b9bsi10891301pga.24.2023.06.29.23.03.24; Thu, 29 Jun 2023 23:03:40 -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=lK78Ij8M; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=h89N3O7P; 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 S231899AbjF3FgP (ORCPT + 99 others); Fri, 30 Jun 2023 01:36:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231634AbjF3FgJ (ORCPT ); Fri, 30 Jun 2023 01:36:09 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 018E210C3; Thu, 29 Jun 2023 22:36:07 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id A19B2320097B; Fri, 30 Jun 2023 01:36:06 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 30 Jun 2023 01:36:07 -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=1688103366; x= 1688189766; bh=9LoAP+lBJvN0CB58nNnqiigraBS5nNzcGrpOaynMiyM=; b=l K78Ij8M9TMWOgvTqmjHgozTkSju81NN0h0srfKtcTclZGuaSrLLxRzGnGWgCK660 PFS/U2fA2P7J/TwnbJc13f6S1soyBEil6ux9m5ZsNUxh+9D8KCeosyX6gthUATMO EF1udh09hJutwXD2dQXoG56/EPtn8GJzBL2FRjsh+9WV1TmH/P7YVam9BF7tlXf9 NVfWh3oxfUVcp9vYUGne6fMaS1uHKRU4QEfdlQbQ6qiHCmD6kfJn3wXqH9/BA0i5 UxwSLuNwKhYOdOP+UJplQB+ko2vaTh4TKT0PSgcf0s0raIYm+WjuonFDBty4K4nf bvHBiKPE57ZTZLnJ3cNaw== 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=1688103366; x= 1688189766; bh=9LoAP+lBJvN0CB58nNnqiigraBS5nNzcGrpOaynMiyM=; b=h 89N3O7PLKiSGlGZkMzudZL8sQZnHml5XG045RhrsGBX7nTRFHYfdS/F4JBrXQul3 9hGTsbeLDvTOjnxow3FGu9T5yHsu7WY2rP4Wusjm/vGabx7/65F5PVc+cBi+XyfF Qa3U8Uc1LjFHU4JS+j2w5/wOSqOm3MYuDPFzMvB6bsyFzf/EDloYJWKrkaR3gtwQ HmFg5PKdVgc+w92OUYtZ8gJ4ohK3q7SyV1tpozQtgRjnjOd7fgCgR8RYsSdxc6c4 43A4lCfu/eJEPVCgxqN1GDudrsu0Qemzg1Yvr43H9AB6d+eoA+GS8VCcwwQoCW20 sCjwDdYgotEiwOfgXOLbw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrtdehgddutddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Jun 2023 01:36:02 -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 v2 1/8] platform/x86: asus-wmi: add support for showing charger mode Date: Fri, 30 Jun 2023 17:35:45 +1200 Message-ID: <20230630053552.976579-2-luke@ljones.dev> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230630053552.976579-1-luke@ljones.dev> References: <20230630053552.976579-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?1770106410181345190?= X-GMAIL-MSGID: =?utf-8?q?1770106410181345190?= Expose a WMI method in sysfs platform for showing which connected charger the laptop is currently using. Signed-off-by: Luke D. Jones Reviewed-by: Hans de Goede --- .../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 Fri Jun 30 05:35:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 114565 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10122828vqr; Thu, 29 Jun 2023 22:41:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlGd7uPBJVUynk5qKUV1mBHQjb8T4baS8nW3MPmcaS4cpsxmnilmSGl84nvbq7tU5Ghx0p0s X-Received: by 2002:a17:90a:6a87:b0:263:5c30:2cf8 with SMTP id u7-20020a17090a6a8700b002635c302cf8mr1712101pjj.0.1688103701727; Thu, 29 Jun 2023 22:41:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688103701; cv=none; d=google.com; s=arc-20160816; b=z7meuOQ6EhztiR/wSP1BPjwzV4G0yJWRjv1dL2u4qjOH9lJ0dK1JOWmpFhWxf9vIKA WzG9B5KXzoOhdGuAIVkZF1BmiuBXCQU77ZOawwWIET+dJRlP2GdfCQCQkt2p54bshsWe vUJM4B+Gb1XcWUkHabwjutzGml8vzFaE/rmn18iZxmQWO75JpWr+UZX8IyWpKl1Wldm1 cig7F2oXxl9Jq9NriaV+3crB8XK5AZAuL+0BRlnqqWfBiugyX76KDf9A48moS6/iINTK jbmnYcqMk4QDSoym+hfeoN6+uAAjLTXwe5dvk/+DP2PnJNkuE1BovK/MFCxF3LWNKF3o Dcmw== 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=q518sSnivonxiIIgOlInc+YEC37Hekh7BSRQImbPyxI=; fh=52RqnqzHFu3c3gS8VqgRtcRPBRgGlf5eGe8HkjfR8FI=; b=08rww6HgTfI3jRa5U8EcjeOZ8PIJ+msZ93C1NMZ+QTqhqX486DK0ZT2bgJkj1S8GVv 33vVCrDTgHU1AkiBhKjqSRxskCyVoOYsaS6m/vxYga2+biNjv8vA8jO42DIH5hKIQxNZ HwXaCf9lgNuKdsgWR0vCXkStx9DavJfUrJ6V6m2siNnM+NidT7vfj+Nj2jf4sEz+hgbP KZjM4QHZyyfVzSw9h2hD7fkwE/Rl4TDssv1JlivMYi0TjbezJLFkgZTi9lhjmWiILYem jbBUuWn7d+mRgeNEtHvRzL3kV48k2TXmzYNxzwCgbXWN/K74KewqwffLLTuuLEWaIUyI QmYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=Z69iCx3m; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=hJPrB476; 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 a3-20020a17090a8c0300b0025ea4ae2799si10306964pjo.19.2023.06.29.22.41.24; Thu, 29 Jun 2023 22:41:41 -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=Z69iCx3m; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=hJPrB476; 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 S231634AbjF3FgS (ORCPT + 99 others); Fri, 30 Jun 2023 01:36:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231839AbjF3FgO (ORCPT ); Fri, 30 Jun 2023 01:36:14 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 282F32D78; Thu, 29 Jun 2023 22:36:13 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id CBD6F3200984; Fri, 30 Jun 2023 01:36:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 30 Jun 2023 01:36: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=1688103371; x= 1688189771; bh=q518sSnivonxiIIgOlInc+YEC37Hekh7BSRQImbPyxI=; b=Z 69iCx3mp4R/Co/9U29vEZtGBbijKzUJ1VNAgqUvvaYhAQYNiOun62VlujgaarQH+ U8RqazgXiRPZdP3ZJHLQOGAzMmkAIs/opGGppPD6vjDG7EwodPLXYjszFhQEUC5Y GB2dExOecntDR9+PPZqXJmKugXFvvVeYwSOq3aQadTg72QyFojr4HJUEgN83P9sj MQqoI+P6M7yAVbEc8i1Ic6vSBNwLduanxYf/iISt5ZhNM18wuCgpcDYiJQbpuaSe 0U50qdwbWgwoT69L4NF9Dq8Nl81VYAaG3hr4JRLDNzrj+AtXhI7qxDm45XXquRP+ EaYU8HH4yViRh5jUxlMkQ== 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=1688103371; x= 1688189771; bh=q518sSnivonxiIIgOlInc+YEC37Hekh7BSRQImbPyxI=; b=h JPrB4761tq+9Ld1E2EJL21PUgK+Tyb5WuwUTguTiS2sPpvxx9lYQ7dT+yzry6fYW nN0MOOjJhKUicOF8pEoZ4BKJJClaFt1NgmjfIZ9Wf/7M8bf/WdNVARZaKYIzoXi5 /rnm3tz1Hxbz8f8/gjyIAIcPZpeULzxqbIP+KE9i5t5Y0hU9/ZjRK+t0Nm2QVdo2 AfD4Nxaaxw6sZ6LFhd2MmwJWsMOGz9Mr4mbIwiYIkReqKnwuF8a0eO28B9+xgmni 6NikXR9ciUfQiOOw6+ktg/HVf54t7/MGkOG/d9K4YcnnO96r0mbWMN+BqFtupXi+ RqgfylmfKi+JVru61/Cew== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrtdehgdellecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepfdfnuhhkvgcuffdrucflohhnvghsfdcuoehluhhkvgeslhhj ohhnvghsrdguvghvqeenucggtffrrghtthgvrhhnpefgteefudfgteduueehteejhfeugf fgleeltedvveethfeuueejfedvgeelveehgfenucevlhhushhtvghrufhiiigvpedtnecu rfgrrhgrmhepmhgrihhlfhhrohhmpehluhhkvgeslhhjohhnvghsrdguvghv X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Jun 2023 01:36:07 -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 v2 2/8] platform/x86: asus-wmi: add support for showing middle fan RPM Date: Fri, 30 Jun 2023 17:35:46 +1200 Message-ID: <20230630053552.976579-3-luke@ljones.dev> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230630053552.976579-1-luke@ljones.dev> References: <20230630053552.976579-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?1770105027416380170?= X-GMAIL-MSGID: =?utf-8?q?1770105027416380170?= 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 Reviewed-by: Hans de Goede --- 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 Fri Jun 30 05:35:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 114568 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10124532vqr; Thu, 29 Jun 2023 22:46:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4+raOAvwWPZGlOk73PLumKj91N3vGd6auONji5AzufZP7JlplTvUmo4tVKtzW/gFoViUdf X-Received: by 2002:a05:6a20:7da6:b0:10b:e7d2:9066 with SMTP id v38-20020a056a207da600b0010be7d29066mr1894787pzj.2.1688103968935; Thu, 29 Jun 2023 22:46:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688103968; cv=none; d=google.com; s=arc-20160816; b=mIn7d6Q1O0bJGJGnTClsKMCRdQNfP9kYhY5rvKaT8K3ekhQ4zhqWE26rjmCLdN9Z5f n7jFJBhKSgTufDnKJwIYymBkZpwLlVNpjb8jJ8z5J2vfO5OFL+czxZZ2GTd8McHPdd5k 8jxmuqD+m42jX9zdAhIK8BbuNWuP1SEKeydJCcL/SRPgFkuXVDgV9KhQ252hQrhSPQ7s cWIMm9nclQUlbQn72kwkq4jYOAoSUtwRfMNmRh71R91F21/i9gSc1mml9CY6li9PNCuQ R6vE0pXggHVcVVaI7F3cCmQ6IH3RSxnLqgBFGdNxX5eZoz+1453+hvxF9Yrreu2l5kEq xbqQ== 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=J5Y4dx1tZFnnSjeHMvtCaqCyhXJYhqnkpp50GoTLBdg=; fh=52RqnqzHFu3c3gS8VqgRtcRPBRgGlf5eGe8HkjfR8FI=; b=py/tyS84HQm2BeQRAogLIupi0gaBXI9ESd5HmjBzsNgDUVtfJxKXZqYkjkTYzCvRk4 mAD72HPoZSi9wg/d43C5vKjYSuE+5XbgR60vL/PfJmUtgAROeiuJ8AqhtAarph+n7gB4 CkjrkplJ7QDe1UTBEBH7b1oqSJWiTcNB6ZFqK4WIN+4KOIs3Eqs8aj3QGDatNH8hL+Ar DCj9xQU5xGdIUqFYjWBD1sS5sQo4f6DIiuhYJrsO+I4Zd3txus3LEu2ax1mZmmEzEHnm 1e/86/EpXGH29Upmc6OqdOnsPa6iIE3K541h+6uCOS22vTd+0hhPp/7N88TzlJZu/7c2 LBew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=cIOMuKR2; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ek1P5xrJ; 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 s22-20020a63dc16000000b005443c85156bsi11779784pgg.222.2023.06.29.22.45.54; Thu, 29 Jun 2023 22:46:08 -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=cIOMuKR2; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ek1P5xrJ; 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 S232215AbjF3FgY (ORCPT + 99 others); Fri, 30 Jun 2023 01:36:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232185AbjF3FgT (ORCPT ); Fri, 30 Jun 2023 01:36:19 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58FD72D78; Thu, 29 Jun 2023 22:36:18 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 079D9320098C; Fri, 30 Jun 2023 01:36:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 30 Jun 2023 01:36:17 -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=1688103376; x= 1688189776; bh=J5Y4dx1tZFnnSjeHMvtCaqCyhXJYhqnkpp50GoTLBdg=; b=c IOMuKR2xIUrJ8tx6CjYa+F6PYB3k/heUhnFJw1bEJEdrVkBQXxbDk1JOJVFj+OIm 6u6ul7oUOqpC4fp4WWMsZ29jOXCYVM+HNg9F2qiXOfABpX6n/pQeLAYQq692jKwL E+vrSI6f5N9JoSgMhJpDBluD/4iV4bw6u8GWXyq3C/ilFenh+d6wYdwuO9Jcpe1R 6OuYX07r62wrKXSr1mnJ3TU2EnVmEbto4leqgSsHIbVJb3xGpP65ewfykrPatjLx t2T3a3tSPrItTOhzvkfAxFKONVHBEyfbDkDFgMgca7njq1M7DEIqFR/aCIlJWNn6 D0IVmlbUqiMF2U8WKuj/A== 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=1688103376; x= 1688189776; bh=J5Y4dx1tZFnnSjeHMvtCaqCyhXJYhqnkpp50GoTLBdg=; b=e k1P5xrJU1lx/H5MEPcHDYYR46dkcfZy0s7PJoWhRaA2wNGH4yW5jB1LEF/DUAmwN kXg9zgIJrwML39a9g/gcxYrpz8XaPgi1iOwOziy0yhW97GEfBXu9O/Vj0hh1K610 aqpkF3bjOW6Xg9mXUHBnGswSTnjaF9pF1EsunkTvQheIefAcFVCT9Ih6DCu2pqhb hxsKCEx/wOd6cvT0dVJTm8uTaqWYqwkw4eovxNQMgXG8tjG6Abou7AyldLBLmtnx Aboo+0FlnjpGaK2WdTFPcT+CnSBSBT8g+Nci3g9fNe/3swrbbWRyN+ojLDeAoPMa jy5qHRjFeCCPRx8kUICUw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrtdehgddutddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgepuden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Jun 2023 01:36: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 v2 3/8] platform/x86: asus-wmi: support middle fan custom curves Date: Fri, 30 Jun 2023 17:35:47 +1200 Message-ID: <20230630053552.976579-4-luke@ljones.dev> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230630053552.976579-1-luke@ljones.dev> References: <20230630053552.976579-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?1770105307549338252?= X-GMAIL-MSGID: =?utf-8?q?1770105307549338252?= Adds support for fan curves defined for the middle fan which is available on some ASUS ROG laptops. Signed-off-by: Luke D. Jones Reviewed-by: Hans de Goede --- 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 Fri Jun 30 05:35:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 114574 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10129185vqr; Thu, 29 Jun 2023 22:59:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4TGZL7PV4wrCP6YEJtL6qbAw2Pg0ys7xAzqt4qGPu74wvNxd2Qgc+Qgqw7X6wh3J80Sbf4 X-Received: by 2002:a05:6a20:7d99:b0:12b:bc21:65b9 with SMTP id v25-20020a056a207d9900b0012bbc2165b9mr2544983pzj.0.1688104774437; Thu, 29 Jun 2023 22:59:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688104774; cv=none; d=google.com; s=arc-20160816; b=mfBiPCSwbKmW+jWTMCE59n+mLswe2/B5V7z1r5Zf2VNyh7EDtw9vg+/F5HqpS1lc6q gWevaKo/oWkr3Ukh5V1sur/Mr2laIsK1d3Q8ySauol49H1OMAs+jdBzlk1z0ignEr0g/ P8SNIWYJ3YTuC7KWL9F3C8pcjw3rMgOeyXW+mu/Xit9mdpZ/AfuOmQ+lc1JuVijHbtiJ ZVpXEBbxSg/9nccFP70HUW1WxpF6nobJFS9UpD3HTas51BXYw29y0NGMJJ9kcrukJH0K wrC6lJZSrJHhJiNP13ExzEhnH8pUrz2GDv5d5qaMsITpD7+03bx+VSKRkv07kj8EhwCJ uHwQ== 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=x0NWRw+Ml4xfFfMxC4QlVOlD9apc5xmU8rzFplB/f6g=; fh=52RqnqzHFu3c3gS8VqgRtcRPBRgGlf5eGe8HkjfR8FI=; b=YkHx99aMVyA+6TluuJTAIJD4dgmfRCoryPh6Y3LmkZg2TiUrVfnleqnTCefgM+7giW mnb4Lo4U1ZTQnfNxZJ+kQoa9IBmlCtJrGerUSxznAPqqpkohEIjVNea7t+g0hKDEGMF3 vD4ec7V0KwRrPZ0NvrGYr0MNUtex6k4psIqigfXxKEs9quIWOtrKO/bGnV8M4YTmm86z ePO7j19v14eEwzZ1N7y52mWSFLw244czp4Oa2e23zxVWoZOXNF8dX/p9CJAhCHRbQfB8 oAXeYKGDWqxJ6Lh5ZE+LZQaXdmUtaRLWhLvWidXcntUe2yJ1rPJ971yH45lf5IBkW9F2 j8Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=MD8Zlt4l; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=Hqz4RKxo; 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 j3-20020a635943000000b005347d35b573si11923489pgm.580.2023.06.29.22.59.19; Thu, 29 Jun 2023 22:59:34 -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=MD8Zlt4l; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=Hqz4RKxo; 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 S232246AbjF3Fgb (ORCPT + 99 others); Fri, 30 Jun 2023 01:36:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232236AbjF3Fg0 (ORCPT ); Fri, 30 Jun 2023 01:36:26 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9288F3593; Thu, 29 Jun 2023 22:36:23 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 43B5E3200983; Fri, 30 Jun 2023 01:36:22 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 30 Jun 2023 01:36: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=1688103381; x= 1688189781; bh=x0NWRw+Ml4xfFfMxC4QlVOlD9apc5xmU8rzFplB/f6g=; b=M D8Zlt4lu7VLWfeGFldSfBCUv+jQ0fOzUKrcQrIRigVXLNbzQfRSSHpmvECseL09n Hy/xmcIuYe7IRzxYZH6eL3A2ItaREY5vHA7vawHxA6KorS0FyAcNvYSQ1jcV81YG rRbHejuZWDQZV9WDK3ZOiYpK6W6TjiWfD2NOjpCgoyr+rKzIG/r0ZXbDZLhjk5aA 5jYh9ReoHWNc8mDELatZpasCs6GcemGW3mVDw9TaMobvF8QZQN5xtd66QJ8P+egQ JF8R3IFrae70NCBY8muInmpF+EZwYIjnTBcvREHeYjt04gvL5Y6QWv9y101JCx47 /0FfdvhE5XTRK6BvPE/Lw== 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=1688103381; x= 1688189781; bh=x0NWRw+Ml4xfFfMxC4QlVOlD9apc5xmU8rzFplB/f6g=; b=H qz4RKxowc2c/XpO+C5koXJvt8QWA34+VWODyB2rTwCj5+x2IiAtmvtkpdqxQHFPy OCvP5T99C1KiD2GFUy0ESzFwxIbIXd26yWSzbkNrnqNAxSIDU68I2U9oCffyoX9s j3zWytOi5kf/hGECt6QkZl6Wfh3dthV+q9/RMW791+n2FhstyMgY1RThUu5hdkYB xokKb6kbX0YA23sCHSykyo/uDgQcc+Q47S1XpyYbW/XMMVaqPz6cpqKKuOUMwSGr edmOWAx/WzTVh5K04M5Y0K68ymWoZb9tIEKXjgSXIZdScgdxlV/S9gT76Jgx06uT 4OvOrfly0nag4IXR91QBQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrtdehgdellecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepfdfnuhhkvgcuffdrucflohhnvghsfdcuoehluhhkvgeslhhj ohhnvghsrdguvghvqeenucggtffrrghtthgvrhhnpefgteefudfgteduueehteejhfeugf fgleeltedvveethfeuueejfedvgeelveehgfenucevlhhushhtvghrufhiiigvpedtnecu rfgrrhgrmhepmhgrihhlfhhrohhmpehluhhkvgeslhhjohhnvghsrdguvghv X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Jun 2023 01:36:18 -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 v2 4/8] platform/x86: asus-wmi: add WMI method to show if egpu connected Date: Fri, 30 Jun 2023 17:35:48 +1200 Message-ID: <20230630053552.976579-5-luke@ljones.dev> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230630053552.976579-1-luke@ljones.dev> References: <20230630053552.976579-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?1770106152062102256?= X-GMAIL-MSGID: =?utf-8?q?1770106152062102256?= Exposes the WMI method which tells if the eGPU is properly connected on the devices that support it. Signed-off-by: Luke D. Jones Reviewed-by: Hans de Goede --- .../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 Fri Jun 30 05:35:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 114573 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10128742vqr; Thu, 29 Jun 2023 22:58:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlHyZKX+63nnBP9kSZBZTGp1vbCP3e0AjZQGYTglUpBMy2y8SPN239rgzKtwqncbdGie5QIX X-Received: by 2002:a17:902:e485:b0:1b8:2a4d:3e91 with SMTP id i5-20020a170902e48500b001b82a4d3e91mr1289938ple.6.1688104691548; Thu, 29 Jun 2023 22:58:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688104691; cv=none; d=google.com; s=arc-20160816; b=pORI6c5+Ir7tyHvgmBS73d5SZJQW2PPBqiNu/RleeDqZsVwY3ZWZH5ju644NQjtJu+ QwMfsEFw9rAPqZgnQmoR+1Ey7uxeQe04+zllM5cfL/YD15oLMVdAWW0QMbCv6rxDGUdE MBU5iX2lu6BFYgO9g95XGdEReYgMQaGhDgObVAACKbJkrIQ331PrGSVtcURA2V1NXoJq gAdZJG+GBQdLx/YVMU02TH9IF4Cly6S0MZNpB2PmHixjACCxIjQivA/b1riiVGsavkKJ 4sG+X3LatYetm1TsX+Kj0WapFr/mQfll0xT0iBD1ryjrpnnh108y9liEe8aIpmfKUTZP gAeg== 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=WjHn4wz/GuX8KDH05sd8J20E91CWXekfUEtps2Qbx48=; fh=52RqnqzHFu3c3gS8VqgRtcRPBRgGlf5eGe8HkjfR8FI=; b=uwVJB2KWUHlTLw422RKZwX6hRpMioJFJPu3cryp0PA6c6lE01G06augUzWVLhgIix8 Ok9GRL7HXqxI597/p6xCMZO1mw4WpZTInvywewDXkPLGtpW5OT86o6nETga9bcnexqS0 fcMWPZQQbkNWOd3akpB6el5zdlbuU011QRfzcmxF2i27QcBLcNiAdRbujbcmUbkxCjQW oIO+wgKzOdKuzrHSfkcvF1zHm1fbGWJJH755XX2kQcydaeHkbHXiq4xypAv4ftSAIJMG xP+/NpQPTMZICM02t/C3VP+E37TIJ5nCMz60usI+MU+Ld8cPKJmBRjM4x9dpvYU0Dqqr 52ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=JWcUCCIS; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="T/9pJ2v0"; 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 x6-20020a1709029a4600b001b84335fb90si3424599plv.286.2023.06.29.22.57.56; Thu, 29 Jun 2023 22:58:11 -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=JWcUCCIS; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="T/9pJ2v0"; 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 S232185AbjF3Fgd (ORCPT + 99 others); Fri, 30 Jun 2023 01:36:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232212AbjF3Fga (ORCPT ); Fri, 30 Jun 2023 01:36:30 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7C213583; Thu, 29 Jun 2023 22:36:28 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 67DF5320098A; Fri, 30 Jun 2023 01:36:27 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 30 Jun 2023 01:36:28 -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=1688103386; x= 1688189786; bh=WjHn4wz/GuX8KDH05sd8J20E91CWXekfUEtps2Qbx48=; b=J WcUCCIS5J1t+gZGsr2ijLzP0SE/Exlm/L9hnHVeD+lpMJjIDpMP36/ELGeAImXYY 8Xy/MAm4lSa+NXn2k57vrGiwj7I+Z8EXPfHJhSsOVZ6NtcDjxQSq+pjxQQ2Sitaj EcNVp0t2jETclke54KJyoBTLLF0sfrol5fBznisK4j1Pw6DVxRMzYknSYu9QOhOZ k1lfdXQlTbsrqHiZt/c2VVWlhCiOK6SbRCuWwAQ4F5ipFDHH2DJ1YbtMfhnlt9Bg J965T3RR+MGQMj8F3QtrgTMIwjtumXeaCdX0SW8cfeMSm1rc2RdiGtBu3jFVBFqv aNgoMJh1zmqMeg90SFohA== 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=1688103386; x= 1688189786; bh=WjHn4wz/GuX8KDH05sd8J20E91CWXekfUEtps2Qbx48=; b=T /9pJ2v0xHan1XGn0MGoCVzFYRYv/6RoZH5atx2uJaXx0HI1vFYqTZI7pwf9a5fQF rciaZc/j5OqoTXK+OalOF1f5CEmzuiJkBOiNTH9NfIKOjL4sUaJDrooiBHD0iJIX JTRP28R8trl/69ZjrlOA1wI69afU8tipxVlduexTpWi6mP6z89ufMGcC5hD4tlP2 83Vk9mhYaxov/SMVdWR4wjhm5mLv2O8/HRYV6/qacM0rn0+M627fvfYk/7aNOSy2 5Kpjlf975vVSAB+JB5iOELsA59iuLl/ypxZywuJVOw/HNYSIsn2DBapd8Tw/LdTm +KvQZd1Oquh/t/QyEmCmw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrtdehgddutddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgepvden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Jun 2023 01:36: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 v2 5/8] platform/x86: asus-wmi: don't allow eGPU switching if eGPU not connected Date: Fri, 30 Jun 2023 17:35:49 +1200 Message-ID: <20230630053552.976579-6-luke@ljones.dev> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230630053552.976579-1-luke@ljones.dev> References: <20230630053552.976579-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?1770106065157250672?= X-GMAIL-MSGID: =?utf-8?q?1770106065157250672?= 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 Reviewed-by: Hans de Goede --- 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 Fri Jun 30 05:35:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 114566 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10122889vqr; Thu, 29 Jun 2023 22:41:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlHdZOUX5aNSSODwibRe3e7pAKPp8v+ceTAgo4kCb/AjUrwgo/KVekOET/EjH+z8wNSo/ysl X-Received: by 2002:a17:90a:4285:b0:263:2312:60c2 with SMTP id p5-20020a17090a428500b00263231260c2mr1598522pjg.3.1688103710475; Thu, 29 Jun 2023 22:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688103710; cv=none; d=google.com; s=arc-20160816; b=QTxDq8sfqlYhx94FUGVMofRsl11Z+eWrWz5GbiFCf5R37WkQvwxI2+1DlvSzPecUFT IC27U0Y1dtsq6p/w5q/rrBy/BJ3gFhTOGuYLF6226Y5+jhZIVo+QYugevHX4N6cE8W7M Q7AcEqVYsQ1v3j6K8UQXqSn3n6zzD3yl424PdC6/HsXwPcX6GzmAenssZ0DeegpkKmiW qbehoIwAmCJDQmL746Drb11H7Vu9uGVlXBtRF2UuMWvE/yrzrS+7PytyyT0BRkf/A/wt 5GJ0s3yNsMCg8lu+VMQeufethzOJDfo2jUFXEVf5qdd1E6sHFd3vp66BiqlEhoLJ+Vbm mq8g== 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=bWv6npFXhdXxLcYc0Px3FglQvMChhuV4rcjQEuBLYbk=; fh=52RqnqzHFu3c3gS8VqgRtcRPBRgGlf5eGe8HkjfR8FI=; b=0M6w3TVfHvbSGRMwFnAyqkZ2ncNK1ve89X8kNcif3diFEginDPjA6uz4y/mFJfbbbH vcxUpbczlBmG3t9U5eB3YFf4zMutJ22uK0VYjpTsVSdXnwUel/vH552AHZeit1r0cdUA DQPuOdQs17aAEbNIFieQArH9Fo+n9N5Af4y5QywPN6fpvaOuZuLJ5jAkUTcwERH1RnUL 3pBBrNR0OwZOjSCcx4/cRxxXWWbIUggEPnxNwH4laXITJxyrtVgMB8gBlZsQ2BpsqDvz hZXhn83Ns+OPB9Vlh5YgFJ9fz1AiyvuBiTzd2ZKsl39PHm04rgbXH7fu7MfMpWakkJCe 9Drw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b="YZk/LMaq"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=OAbS+R0y; 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 k191-20020a6384c8000000b0055336060f9csi12292014pgd.376.2023.06.29.22.41.35; Thu, 29 Jun 2023 22:41:50 -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="YZk/LMaq"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=OAbS+R0y; 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 S232262AbjF3Fgm (ORCPT + 99 others); Fri, 30 Jun 2023 01:36:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232253AbjF3Fgf (ORCPT ); Fri, 30 Jun 2023 01:36:35 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F83E3585; Thu, 29 Jun 2023 22:36:34 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id A4C70320098C; Fri, 30 Jun 2023 01:36:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 30 Jun 2023 01:36: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=1688103392; x= 1688189792; bh=bWv6npFXhdXxLcYc0Px3FglQvMChhuV4rcjQEuBLYbk=; b=Y Zk/LMaq/CDrkbNzgDOA8FxLB5xK1jRPgdPxfsIs/aHcNnCDkvLGqcQyjvRwIX7MX ay2npQQYjLAPqYzHc66CH3T2VrS+IlPAjjNCLatrRuJ4HCTSM7Bz6BHbc8ZBOq0/ PAAZVweeItWkFIY3cq52OC+OAO9kcpsF2Nex2sEF6oMbYxvi5Uh6HSnVLXVQMD/L hN1f7l5SQ1SpCQDG5aWgitevI/wbnA4N6TjHeuXo4Bnsn0m79JXFncAN4jSAfqzI XGFc5S9K9QgxTNwqFlUdInVwEZmN3yykCE5bG1BMJUe5fa6jWvocI/N6xQChkgdv gvP4X2jLGoFLnSORwZiBg== 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=1688103392; x= 1688189792; bh=bWv6npFXhdXxLcYc0Px3FglQvMChhuV4rcjQEuBLYbk=; b=O AbS+R0ycqgXv4b7My5WBhW49FOY9YfxEhkTZBaMGGKpvEpUJblrT09okc81zrLiL 3vGnjs/0FmFlPSVlNPZJuG9Ha4SBjh2ydIV38WxKI/fyNokDWmPYPOLO4UnwiI/n E7KqINhoelctPCUuXYVGGZSzBkkvuY57hj/sT5at2K8eMa+kC7OMTkPyh+N2BPI4 AdseyPoKBiJylttW1s/9Id3gmkv+XjQfay0Z8tgyleCTwPbf8xLA9ZiprR8ZQXoH fjmqk10Ix/FpVCL/4LvHfCs9hAgFCdBBEWUVqbs0cn7arhqjA5HYtS1VbgYv+4L3 CBFvnALAbw1bwJRNuDElA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrtdehgdellecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepfdfnuhhkvgcuffdrucflohhnvghsfdcuoehluhhkvgeslhhj ohhnvghsrdguvghvqeenucggtffrrghtthgvrhhnpefgteefudfgteduueehteejhfeugf fgleeltedvveethfeuueejfedvgeelveehgfenucevlhhushhtvghrufhiiigvpedunecu rfgrrhgrmhepmhgrihhlfhhrohhmpehluhhkvgeslhhjohhnvghsrdguvghv X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Jun 2023 01:36:28 -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 v2 6/8] platform/x86: asus-wmi: add safety checks to gpu switching Date: Fri, 30 Jun 2023 17:35:50 +1200 Message-ID: <20230630053552.976579-7-luke@ljones.dev> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230630053552.976579-1-luke@ljones.dev> References: <20230630053552.976579-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?1770105036482042222?= X-GMAIL-MSGID: =?utf-8?q?1770105036482042222?= 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 Reviewed-by: Hans de Goede --- 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 Fri Jun 30 05:35:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 114570 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10126226vqr; Thu, 29 Jun 2023 22:50:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlH/Q9DTKC7juZrqJQGYFfVrCTOGAL8IozbWYuknAQRGI8f7HBrTKtyoDF0dZTUQ/dU8j5Lk X-Received: by 2002:a17:903:28c7:b0:1b7:f3e6:5727 with SMTP id kv7-20020a17090328c700b001b7f3e65727mr1320273plb.2.1688104242080; Thu, 29 Jun 2023 22:50:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688104242; cv=none; d=google.com; s=arc-20160816; b=Omenq9DwzWHV3bSOLnNaWC2knutNaPLrZKuJqEYql0cMTjDBrqxBvupoys9DC7rw6F MkmmZvyFZ0u+8Z8zHbymKPQNpJiqvgpRK2rOFyRiW3utwPSfa4unObuzq4FAr0Z5DPli TPWlCu+Zdcz/haxmc/GxgJ8s/o3LEje7YnvKMP21WHi/GCIfVpcH2tMJuOo/dgKPbBj+ NTsAbOrHvlxKwVOGHgn5XUsyjagOwhoRzjbXJib1BGoCgLPLY6sdB74RXeTTnW/Vysml CC5v/JSw9S6wcf+2Us1ROqv67GeWegSUfe7ZSDqpXry4qvNZ87xqKiB4kGs79Avv2Mpw U3dA== 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=wsVYQogneSxXEgP9jYbruJvxTZh+2SC+W+ytbO/Zypg=; fh=52RqnqzHFu3c3gS8VqgRtcRPBRgGlf5eGe8HkjfR8FI=; b=eprshMN8AxhuUTTLDfSFwpRiPAb3LgEQtwu3DvT+75eHw6WaLvHa/GMyAAdSWmi6hp gcSWbdjyDkz+wpkPTbX9dOX91lwsFhj+KQkzheS376yk67ss0UCLZ/1OGzILchNJaUOB vDbMa7nMh2EpjGbvrF3zsC7+ZWRlnt2HA6Q3UmeFOfiTu1R1Ru2E5w3cGZcj/fTb8eyJ wCo2VXvnKPeFXy2k1jVhFfqM22wKroa9oNWnxAFisEWD/7S11WC4ytxN5OPsNDu96a1I xxeWj/vk41iSPxsxUkv9ZuX/C74kimcj+3AWR8bxoyXLvTTzqlEI8M3bcotBd85OphXF oW8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=kNsDp+za; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=SsrMUOaY; 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 w6-20020a1709029a8600b001b03d54354dsi11153849plp.189.2023.06.29.22.50.26; Thu, 29 Jun 2023 22:50:42 -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=kNsDp+za; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=SsrMUOaY; 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 S232288AbjF3Fgr (ORCPT + 99 others); Fri, 30 Jun 2023 01:36:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232267AbjF3Fgl (ORCPT ); Fri, 30 Jun 2023 01:36:41 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AE803596; Thu, 29 Jun 2023 22:36:39 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id E0229320097B; Fri, 30 Jun 2023 01:36:37 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 30 Jun 2023 01:36:38 -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=1688103397; x= 1688189797; bh=wsVYQogneSxXEgP9jYbruJvxTZh+2SC+W+ytbO/Zypg=; b=k NsDp+zaAMdypVg1UIjeTsRe1P/Wu49sf36GOLV7/RVay6FyzPxf82gfSxosOeF2l CQOpnYWA15M1KaRVovNhEfY8R2kf8DOtYRJ1chKljmxUUFsU1tb3vAcdzY+Ao3fb A2r5jU968u9AI35WAhXJojzvhQaWpQibzug8tWzQAcQAhDARc6zOSX2D1mhAu8R5 jxEHmRpZQf3ANnNrY7ODY90TmtOZwSk37GmNJOHxm3URgz6q+QVVuZ3S+HH2NLFO PfQu//8Z8L7PSr8rb/oSN4rpfL3oAT5BiKhfD5/fr0kWdKGurPmUG/X4Bh1vByl3 U5VhmUhUAo4wADltihOuQ== 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=1688103397; x= 1688189797; bh=wsVYQogneSxXEgP9jYbruJvxTZh+2SC+W+ytbO/Zypg=; b=S srMUOaYv32UxT74CqyiHubViKQJoqEQ2UbBEsiKqCaNIWW90n4yEGmn3qhQa410K jtOLuNUiS+TzIMielKA1O3CUwEzyawyeFTHejO6CZZszyr1iaywo96iEI8AK4PEw ctU/wPsi611mEi6yYdPPFVlXn8ujTY0L3XTU9v5FkO7iO1gZCwrHvo8Q7oYRrPLS aAGQJtDsTd7OCBCAtWMdDC9hDlrli/bsGHZRwt71LJUCSpoILUVAU1e/T1/CTRCd 3vP2IH3BkuhrYt69bV58BMmAxk9BBk1pIGMvy0gWmRDUk9WtbT7c1NSTacqEhmC7 Ofc/egYR/D7n38ULiyxVw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrtdehgdellecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepfdfnuhhkvgcuffdrucflohhnvghsfdcuoehluhhkvgeslhhj ohhnvghsrdguvghvqeenucggtffrrghtthgvrhhnpefgteefudfgteduueehteejhfeugf fgleeltedvveethfeuueejfedvgeelveehgfenucevlhhushhtvghrufhiiigvpedvnecu rfgrrhgrmhepmhgrihhlfhhrohhmpehluhhkvgeslhhjohhnvghsrdguvghv X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Jun 2023 01:36:34 -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 v2 7/8] platform/x86: asus-wmi: support setting mini-LED mode Date: Fri, 30 Jun 2023 17:35:51 +1200 Message-ID: <20230630053552.976579-8-luke@ljones.dev> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230630053552.976579-1-luke@ljones.dev> References: <20230630053552.976579-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?1770105593628570033?= X-GMAIL-MSGID: =?utf-8?q?1770105593628570033?= Support changing the mini-LED mode on some of the newer ASUS laptops. Signed-off-by: Luke D. Jones Reviewed-by: Hans de Goede --- .../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 Fri Jun 30 05:35:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 114567 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10123015vqr; Thu, 29 Jun 2023 22:42:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4iDkeH4eXzwBCyJOswJVAHepjXj5rWMXUS1id4Kt9nSnL3nBSx6eriuHwR9NW3ci7QT4EC X-Received: by 2002:a05:6a20:1446:b0:111:a0e5:d2b7 with SMTP id a6-20020a056a20144600b00111a0e5d2b7mr2368427pzi.4.1688103726342; Thu, 29 Jun 2023 22:42:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688103726; cv=none; d=google.com; s=arc-20160816; b=0kiY29kevAcsODkWhbqn0hNAi+uB272bQ/VRseANlWxQ1F6Chwlhz7NgoI5T85GX2Y DTUu0wmS4byQuotJFN88m5X+tV44A+EAuXZLUCz3Jv2cnpJWWLxu5c3TJ3IMjZD/G14v mMrwaGrOft5YlBAzEGBcmmLq5oPyyshuIr/G+5vt9IYcx+qpUwWp6nTqvVTVDSV4ybsY 5orEUw80yng8njceOBqiTCpCiV8q8TcxClAYgHS3iXU2RI+QRWU3QdNhwu14XeNdWXR9 fFJbkM7tZMhSOlgJs00om4q1wBqvdB3CVvE6EUP9t0SSCENA1obeuTEOudVMroczn5gn cT/g== 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=mR7QSVgW/nu39AuwrZ0rmfk/cdu9OmaRYy7gYgT4/qg=; fh=52RqnqzHFu3c3gS8VqgRtcRPBRgGlf5eGe8HkjfR8FI=; b=fDy/ysYZNxc/LqHP/xEGWeYV73AUO/v39JaOppLbC7yJeZz3nWpDuUUDow88PrTDXv jAxlQpvrmtjlP7pfua04zf5XU84YTPOSL+Io1SmjxYTA+BDbIaL1g3jDQjlyrABymo/O f4fwzBupIQuXMCC+sWYjlU7rF5YxN8WKnfpem1iGcVlbiXFS5siCruitK/z1Q1lR0FWB anIwjGSMh/whNCL3WkCsFLBAwCkooB6n2UgpPrv+EJxh5A92hyrUP+vD2N2J4wOZHprX FkkNc1n8abWX1CPrRYKnVYsPRjpoc97wgMVnmI1kJKGOXo/lmU4erD1M8+Tz7OITnvuz 5W1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=wJK76dQe; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=GIMDHkgu; 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 n3-20020a6546c3000000b00553921edac1si12121777pgr.860.2023.06.29.22.41.51; Thu, 29 Jun 2023 22:42:06 -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=wJK76dQe; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=GIMDHkgu; 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 S232308AbjF3Fgv (ORCPT + 99 others); Fri, 30 Jun 2023 01:36:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232284AbjF3Fgp (ORCPT ); Fri, 30 Jun 2023 01:36:45 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66B1010C3; Thu, 29 Jun 2023 22:36:44 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 181FB3200983; Fri, 30 Jun 2023 01:36:43 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 30 Jun 2023 01:36:44 -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=1688103402; x= 1688189802; bh=mR7QSVgW/nu39AuwrZ0rmfk/cdu9OmaRYy7gYgT4/qg=; b=w JK76dQegZVX2AcB+2qYzzgriDfKJqWT24Dl2nDadwWT8FagYyfxufpPfTQW5O9T2 96U2x+1T9aWhtSEn49P7nifxBiXnVxqYHdnT8/0OLiCJdo5tw7P/1Hwh5g/vQlCj wIipq/qlVnoTYg8I8uMskU+XGRQY5jzVPL6WCecFdzevDIZWhfsdrPr0WzC4rjWY eD1RyGiTDiylOMOdDgjYxTdleKi6jQdYwo2Mq/KzUGuNDA9vUavLq4p1t2XEUFEx rpHuCyho06TU9cRu9udzxdCN7WIc7oD2O5EhhM9avGf6lb5J+cOJLiCeB7CLQlKt ddb6LiOd+t3E8CxL3afxw== 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=1688103402; x= 1688189802; bh=mR7QSVgW/nu39AuwrZ0rmfk/cdu9OmaRYy7gYgT4/qg=; b=G IMDHkguwxtLiWi7C3sTKPtInmoqGwbxfIdAGQWCBvD+CF9kL2Tumx0Mr9ZRO6alH G69jklMD9C4uHJPjn7jAoshXxDQ32G+S2OjnvODim+d92nmr2o0I3CqOoOeylspb 6w4cU79K5NSSwLVrkziiN66imYXohHr1Q1gEkGFEBEVhuQXuTKBddk6jMwLL6zjd o0/7GWgJxz1cERBfbmjJGVuyCMjVyKIRCziDUafWW54cQRlMubKO9LbDgPKWbv/K V/hR2AXEJuW8N17B+nm9yz9/JAOQljS+szkxAn9/va8NAf755T0G5ee7OgY1XwD0 C+V7TQ7zOmqNF7tbDEEnw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrtdehgdellecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepfdfnuhhkvgcuffdrucflohhnvghsfdcuoehluhhkvgeslhhj ohhnvghsrdguvghvqeenucggtffrrghtthgvrhhnpefgteefudfgteduueehteejhfeugf fgleeltedvveethfeuueejfedvgeelveehgfenucevlhhushhtvghrufhiiigvpedunecu rfgrrhgrmhepmhgrihhlfhhrohhmpehluhhkvgeslhhjohhnvghsrdguvghv X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Jun 2023 01:36:39 -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 v2 8/8] platform/x86: asus-wmi: expose dGPU and CPU tunables for ROG Date: Fri, 30 Jun 2023 17:35:52 +1200 Message-ID: <20230630053552.976579-9-luke@ljones.dev> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230630053552.976579-1-luke@ljones.dev> References: <20230630053552.976579-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?1770105053131570464?= X-GMAIL-MSGID: =?utf-8?q?1770105053131570464?= 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 Reviewed-by: Hans de Goede --- .../ABI/testing/sysfs-platform-asus-wmi | 58 ++++ drivers/platform/x86/asus-wmi.c | 285 ++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 9 + 3 files changed, 352 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index 5624bdef49cb..caaccd28fabf 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -126,3 +126,61 @@ Description: Change the mini-LED mode: * 0 - Single-zone, * 1 - Multi-zone + +What: /sys/devices/platform//ppt_pl1_spl +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Set the Package Power Target total of CPU: PL1 on Intel, SPL on AMD. + Shown on Intel+Nvidia or AMD+Nvidia based systems. + * min=5, max=250 + +What: /sys/devices/platform//ppt_pl2_sppt +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Set the Slow Package Power Tracking Limit of CPU: PL2 on Intel, SPPT, + on AMD. Shown on Intel+Nvidia or AMD+Nvidia based systems. + * 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. AMD+Nvidia only. + * min=5, max=250 + +What: /sys/devices/platform//ppt_apu_sppt +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Set the APU SPPT limit. Shown on full AMD systems only. + * min=5, max=130 + +What: /sys/devices/platform//ppt_platform_sppt +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Set the platform SPPT limit. Shown on full AMD systems only. + * min=5, max=130 + +What: /sys/devices/platform//nv_dynamic_boost +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Set the dynamic boost limit of the Nvidia dGPU: + * min=5, max=25 + +What: /sys/devices/platform//nv_temp_target +Date: Jun 2023 +KernelVersion: 6.5 +Contact: "Luke Jones" +Description: + Set the target 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..d9a353081f91 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_BOOST_MIN 5 +#define NVIDIA_BOOST_MAX 25 +#define NVIDIA_TEMP_MIN 75 +#define NVIDIA_TEMP_MAX 87 + static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL }; static int throttle_thermal_policy_write(struct asus_wmi *); @@ -247,6 +257,15 @@ struct asus_wmi { bool dgpu_disable_available; bool gpu_mux_mode_available; + /* Tunables provided by ASUS for gaming laptops */ + bool ppt_pl2_sppt_available; + bool ppt_pl1_spl_available; + bool ppt_apu_sppt_available; + bool ppt_plat_sppt_available; + bool ppt_fppt_available; + bool nv_dyn_boost_available; + bool nv_temp_tgt_available; + bool kbd_rgb_mode_available; bool kbd_rgb_state_available; @@ -946,6 +965,244 @@ static const struct attribute_group *kbd_rgb_mode_groups[] = { NULL, }; +/* Tunable: PPT: Intel=PL1, AMD=SPPT *****************************************/ +static ssize_t ppt_pl2_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_PL2_SPPT, value, &result); + if (err) { + pr_warn("Failed to set ppt_pl2_sppt: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set ppt_pl2_sppt (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_pl2_sppt"); + + return count; +} +static DEVICE_ATTR_WO(ppt_pl2_sppt); + +/* Tunable: PPT, Intel=PL1, AMD=SPL ******************************************/ +static ssize_t ppt_pl1_spl_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_PL1_SPL, value, &result); + if (err) { + pr_warn("Failed to set ppt_pl1_spl: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set ppt_pl1_spl (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_pl1_spl"); + + return count; +} +static DEVICE_ATTR_WO(ppt_pl1_spl); + +/* 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 SPPT *****************************************************/ +static ssize_t ppt_apu_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_CPU_MIN || value > PPT_CPU_MAX) + return -EINVAL; + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PPT_APU_SPPT, value, &result); + if (err) { + pr_warn("Failed to set ppt_apu_sppt: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set ppt_apu_sppt (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_apu_sppt"); + + return count; +} +static DEVICE_ATTR_WO(ppt_apu_sppt); + +/* Tunable: PPT platform SPPT ************************************************/ +static ssize_t ppt_platform_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_CPU_MIN || value > PPT_CPU_MAX) + return -EINVAL; + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PPT_PLAT_SPPT, value, &result); + if (err) { + pr_warn("Failed to set ppt_platform_sppt: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set ppt_platform_sppt (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_platform_sppt"); + + return count; +} +static DEVICE_ATTR_WO(ppt_platform_sppt); + +/* Tunable: NVIDIA dynamic boost *********************************************/ +static ssize_t nv_dynamic_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_BOOST_MIN || value > NVIDIA_BOOST_MAX) + return -EINVAL; + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_NV_DYN_BOOST, value, &result); + if (err) { + pr_warn("Failed to set nv_dynamic_boost: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set nv_dynamic_boost (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "nv_dynamic_boost"); + + return count; +} +static DEVICE_ATTR_WO(nv_dynamic_boost); + +/* Tunable: NVIDIA temperature target ****************************************/ +static ssize_t nv_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_TEMP_MIN || value > NVIDIA_TEMP_MAX) + return -EINVAL; + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_NV_THERM_TARGET, value, &result); + if (err) { + pr_warn("Failed to set nv_temp_target: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set nv_temp_target (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "nv_temp_target"); + + return count; +} +static DEVICE_ATTR_WO(nv_temp_target); + /* Battery ********************************************************************/ /* The battery maximum charging percentage */ @@ -3775,6 +4032,13 @@ 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_pl2_sppt.attr, + &dev_attr_ppt_pl1_spl.attr, + &dev_attr_ppt_fppt.attr, + &dev_attr_ppt_apu_sppt.attr, + &dev_attr_ppt_platform_sppt.attr, + &dev_attr_nv_dynamic_boost.attr, + &dev_attr_nv_temp_target.attr, &dev_attr_panel_od.attr, &dev_attr_mini_led_mode.attr, NULL @@ -3812,6 +4076,20 @@ 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_pl2_sppt.attr) + ok = asus->ppt_pl2_sppt_available; + else if (attr == &dev_attr_ppt_pl1_spl.attr) + ok = asus->ppt_pl1_spl_available; + else if (attr == &dev_attr_ppt_fppt.attr) + ok = asus->ppt_fppt_available; + else if (attr == &dev_attr_ppt_apu_sppt.attr) + ok = asus->ppt_apu_sppt_available; + else if (attr == &dev_attr_ppt_platform_sppt.attr) + ok = asus->ppt_plat_sppt_available; + else if (attr == &dev_attr_nv_dynamic_boost.attr) + ok = asus->nv_dyn_boost_available; + else if (attr == &dev_attr_nv_temp_target.attr) + ok = asus->nv_temp_tgt_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 +4355,13 @@ 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_pl2_sppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_PL2_SPPT); + asus->ppt_pl1_spl_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_PL1_SPL); + asus->ppt_fppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_FPPT); + asus->ppt_apu_sppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_APU_SPPT); + asus->ppt_plat_sppt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PPT_PLAT_SPPT); + asus->nv_dyn_boost_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_NV_DYN_BOOST); + asus->nv_temp_tgt_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_NV_THERM_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..16e99a1c37fc 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -86,6 +86,15 @@ #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_PL2_SPPT 0x001200A0 +#define ASUS_WMI_DEVID_PPT_PL1_SPL 0x001200A3 +#define ASUS_WMI_DEVID_PPT_APU_SPPT 0x001200B0 +#define ASUS_WMI_DEVID_PPT_PLAT_SPPT 0x001200B1 +#define ASUS_WMI_DEVID_PPT_FPPT 0x001200C1 +#define ASUS_WMI_DEVID_NV_DYN_BOOST 0x001200C0 +#define ASUS_WMI_DEVID_NV_THERM_TARGET 0x001200C2 + /* Power */ #define ASUS_WMI_DEVID_PROCESSOR_STATE 0x00120012