From patchwork Tue Jun 20 02:56:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 110233 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3386222vqr; Mon, 19 Jun 2023 19:58:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5nZ8Cb4l+e6NIeY7yGpGdXbWPlh2i1utAPfB/5sxevya3y+o6wZTH+hfo7/lTiHTXTn4Oy X-Received: by 2002:a17:903:247:b0:1b3:dcf1:97 with SMTP id j7-20020a170903024700b001b3dcf10097mr13891079plh.25.1687229935659; Mon, 19 Jun 2023 19:58:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687229935; cv=none; d=google.com; s=arc-20160816; b=DjhrLR1YcpCD3rKFE45nbeQ4Ip0ExWgBnWDrd3JA3wf8ZzCk6R1A/CyAxeNA9gIjwg mMI0qx6yYVrA7oiheENf50wAf2p76FrPPcNZd/1F9+xT6Fc8BXWTM2ahwvQNUJgP3nMs SJ20sMftNqEN96iUd+YKomlQJd+rtdsInEG7ritRVkKz31mRh9zisPWsXOvOVa/cij3P WCZVslaADN0vhoAn61Gxz93kIVpTZg/0VlV1NZtPDEc/Z94iuWJ76k8C1xeSU4nZ55BY 3WkpNngtdlpQFoJ197ZW6UgTBLbZDiE9Hdt/uzw8+oQ6vi6E7AKminTfCWO8y9N59ueU Qneg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=i2v99NqpJrZxAzLHsyMCcMd30q0IFnY2dIA+JESeIh8=; b=ptsVPmQrpcIGVyv4NcLThpp8rFbduWA5c19EBrDns7ww5LVVhnCMXdx8tQYD/jXpH/ AjAans4S+b5EQRMtvLv7M9lnx7DKbIm6TtezYu6iD0ppsRAS+ql1DUwFe8IdIZGH0XDg kJE6Q38fEdYXn+s/2NX3QH06dY3jzt5E4S2lyIY96bafoPG5pIP1jiS66UYUojUnDula ftSVju1LINPfUQJBP/VHEutdb+N1jepOOUEHVyAfFtnE2asDvgDlMkG6Uh3RpacUzMUs kQLb2Fsf79ikwpSobLzUnAB+FZqIW5eO6Cl1X5gFfxqjxOxh+w0XsPFpNFwAunwqkiUM UvPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=dKoNkgBG; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=PmwIt3y+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f17-20020a170902f39100b001a9b4bda723si862886ple.421.2023.06.19.19.58.43; Mon, 19 Jun 2023 19:58:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm3 header.b=dKoNkgBG; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=PmwIt3y+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230062AbjFTC5W (ORCPT + 99 others); Mon, 19 Jun 2023 22:57:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbjFTC5P (ORCPT ); Mon, 19 Jun 2023 22:57:15 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F7E910CE; Mon, 19 Jun 2023 19:57:13 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C7E565C01E4; Mon, 19 Jun 2023 22:57:12 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 19 Jun 2023 22:57:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1687229832; x= 1687316232; bh=i2v99NqpJrZxAzLHsyMCcMd30q0IFnY2dIA+JESeIh8=; b=d KoNkgBGYUqzm2MyCdEBOpeVHf/gJ4KkT0cPooKtsix0niehPf0Yq5I4FwjvBg4+J f6t5qSpjr/QemhAUx44GjHJaDbVoBeWo3oRmKJWCbFV3g7gQvE13SgGtPUnKcVev C8m7bkj5Ej/6CpoKlnwwoHd4TLPadq3iG8TP0Y246wvwkBKnSbxX4CLwQHYjZqLj MHtnSRae0YgQaVyxzPWq32zP29YnTmx65PGpSqNV0YHLQfzORoogOrXeZWi6v6lK ikk4l9JprQqVaoqGx4+7wu6Hi4CA543qQ36ZXrGcfo1wgHCCMkZCImYaaM9w2LNH zqQbRAXFSc5hLlkz+lBfg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1687229832; x= 1687316232; bh=i2v99NqpJrZxAzLHsyMCcMd30q0IFnY2dIA+JESeIh8=; b=P mwIt3y+m6nKhG6cfmUH+qMqXD1Z0m9e0YSpsofvRpTHzd1AdViCcFsjuBXO98jgR FVXEdbZ55EK2YL7ZLJLmgOXj1eCQ5rT86y/LwYBenkjB8VOVU8+Wn8LkEeV3UCex CBky3zDgo3DLbrLQ5FBhMzZZXMrd+wcyZvWI5K6EoSQ8u5gBpRiZ89nBw5hbjVXR /+747MnTg6USfaZgaiiU0V0BCeaYj8O0K403YSvaWzl3GI6gP/wAXqWCjQSdbrBY wrz8vq32NHYL7UDyPmyC2ty8sL7ynaROFWA52NkjcxtCh4MMFLH5Nnk2+ldE8tby sx6mNAIIpdvdCYX908eZQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeefgedgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 19 Jun 2023 22:57:09 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: corentin.chary@gmail.com, acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, markgross@kernel.org, jdelvare@suse.com, linux@roeck-us.net, "Luke D. Jones" Subject: [PATCH 2/8] platform/x86: asus-wmi: add support for showing middle fan RPM Date: Tue, 20 Jun 2023 14:56:35 +1200 Message-Id: <20230620025641.53197-3-luke@ljones.dev> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620025641.53197-1-luke@ljones.dev> References: <20230620025641.53197-1-luke@ljones.dev> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769188817345005150?= X-GMAIL-MSGID: =?utf-8?q?1769188817345005150?= Some newer ASUS ROG laptops now have a middle/center fan in addition to the CPU and GPU fans. This new fan typically blows across the heatpipes and VRMs betweent eh CPU and GPU. This commit exposes that fan to PWM control plus showing RPM. Signed-off-by: Luke D. Jones --- drivers/platform/x86/asus-wmi.c | 91 ++++++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 1 + 2 files changed, 92 insertions(+) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index f23375d5fb82..375d25ae0aca 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -72,6 +72,7 @@ module_param(fnlock_default, bool, 0444); #define ASUS_WMI_FNLOCK_BIOS_DISABLED BIT(0) +#define ASUS_MID_FAN_DESC "mid_fan" #define ASUS_GPU_FAN_DESC "gpu_fan" #define ASUS_FAN_DESC "cpu_fan" #define ASUS_FAN_MFUN 0x13 @@ -229,8 +230,10 @@ struct asus_wmi { enum fan_type fan_type; enum fan_type gpu_fan_type; + enum fan_type mid_fan_type; int fan_pwm_mode; int gpu_fan_pwm_mode; + int mid_fan_pwm_mode; int agfn_pwm; bool fan_boost_mode_available; @@ -2129,6 +2132,31 @@ static ssize_t fan2_label_show(struct device *dev, return sysfs_emit(buf, "%s\n", ASUS_GPU_FAN_DESC); } +/* Middle/Center fan on modern ROG laptops */ +static ssize_t fan3_input_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + int value; + int ret; + + ret = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_MID_FAN_CTRL, &value); + if (ret < 0) + return ret; + + value &= 0xffff; + + return sysfs_emit(buf, "%d\n", value * 100); +} + +static ssize_t fan3_label_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%s\n", ASUS_MID_FAN_DESC); +} + static ssize_t pwm2_enable_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -2175,6 +2203,52 @@ static ssize_t pwm2_enable_store(struct device *dev, return count; } +static ssize_t pwm3_enable_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + + return sysfs_emit(buf, "%d\n", asus->mid_fan_pwm_mode); +} + +static ssize_t pwm3_enable_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + int state; + int value; + int ret; + u32 retval; + + ret = kstrtouint(buf, 10, &state); + if (ret) + return ret; + + switch (state) { /* standard documented hwmon values */ + case ASUS_FAN_CTRL_FULLSPEED: + value = 1; + break; + case ASUS_FAN_CTRL_AUTO: + value = 0; + break; + default: + return -EINVAL; + } + + ret = asus_wmi_set_devstate(ASUS_WMI_DEVID_MID_FAN_CTRL, + value, &retval); + if (ret) + return ret; + + if (retval != 1) + return -EIO; + + asus->mid_fan_pwm_mode = state; + return count; +} + /* Fan1 */ static DEVICE_ATTR_RW(pwm1); static DEVICE_ATTR_RW(pwm1_enable); @@ -2184,6 +2258,10 @@ static DEVICE_ATTR_RO(fan1_label); static DEVICE_ATTR_RW(pwm2_enable); static DEVICE_ATTR_RO(fan2_input); static DEVICE_ATTR_RO(fan2_label); +/* Fan3 - Middle/center fan */ +static DEVICE_ATTR_RW(pwm3_enable); +static DEVICE_ATTR_RO(fan3_input); +static DEVICE_ATTR_RO(fan3_label); /* Temperature */ static DEVICE_ATTR(temp1_input, S_IRUGO, asus_hwmon_temp1, NULL); @@ -2192,10 +2270,13 @@ static struct attribute *hwmon_attributes[] = { &dev_attr_pwm1.attr, &dev_attr_pwm1_enable.attr, &dev_attr_pwm2_enable.attr, + &dev_attr_pwm3_enable.attr, &dev_attr_fan1_input.attr, &dev_attr_fan1_label.attr, &dev_attr_fan2_input.attr, &dev_attr_fan2_label.attr, + &dev_attr_fan3_input.attr, + &dev_attr_fan3_label.attr, &dev_attr_temp1_input.attr, NULL @@ -2221,6 +2302,11 @@ static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj, || attr == &dev_attr_pwm2_enable.attr) { if (asus->gpu_fan_type == FAN_TYPE_NONE) return 0; + } else if (attr == &dev_attr_fan3_input.attr + || attr == &dev_attr_fan3_label.attr + || attr == &dev_attr_pwm3_enable.attr) { + if (asus->mid_fan_type == FAN_TYPE_NONE) + return 0; } else if (attr == &dev_attr_temp1_input.attr) { int err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_THERMAL_CTRL, @@ -2264,6 +2350,7 @@ static int asus_wmi_hwmon_init(struct asus_wmi *asus) static int asus_wmi_fan_init(struct asus_wmi *asus) { asus->gpu_fan_type = FAN_TYPE_NONE; + asus->mid_fan_type = FAN_TYPE_NONE; asus->fan_type = FAN_TYPE_NONE; asus->agfn_pwm = -1; @@ -2278,6 +2365,10 @@ static int asus_wmi_fan_init(struct asus_wmi *asus) if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_GPU_FAN_CTRL)) asus->gpu_fan_type = FAN_TYPE_SPEC83; + /* Some models also have a center/middle fan */ + if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_MID_FAN_CTRL)) + asus->mid_fan_type = FAN_TYPE_SPEC83; + if (asus->fan_type == FAN_TYPE_NONE) return -ENODEV; diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index f90cafe26af1..2c03bda7703f 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -80,6 +80,7 @@ #define ASUS_WMI_DEVID_FAN_CTRL 0x00110012 /* deprecated */ #define ASUS_WMI_DEVID_CPU_FAN_CTRL 0x00110013 #define ASUS_WMI_DEVID_GPU_FAN_CTRL 0x00110014 +#define ASUS_WMI_DEVID_MID_FAN_CTRL 0x00110031 #define ASUS_WMI_DEVID_CPU_FAN_CURVE 0x00110024 #define ASUS_WMI_DEVID_GPU_FAN_CURVE 0x00110025