From patchwork Tue Nov 21 19:58:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SungHwan Jung X-Patchwork-Id: 167919 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp880645vqb; Tue, 21 Nov 2023 11:59:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IELvPakmvNMoIPyo/XhnhC9Iy1J+0IIDTNf2Ln65U+JAscNcx3nt7Xl2JOLtFMfWQq/uLYU X-Received: by 2002:a17:90b:1d05:b0:280:35d:4532 with SMTP id on5-20020a17090b1d0500b00280035d4532mr268589pjb.14.1700596781058; Tue, 21 Nov 2023 11:59:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700596781; cv=none; d=google.com; s=arc-20160816; b=YDCrdBc2+yC1Fsveom21/InbFT1kmw4ap6xqQO14JLJ8W661aU7IXnfkdv3rSJq+jB XHovARRp6Cn9zogZ/CphmZNSZVSGnFjymANDcHRkSNwqWkejVXlUf/zcKkj03LFZYC9p M6e9PyRzs4JR+8c1JYyyTfh535hNbIqAEBtz7NFoOWRR1FfCBenTtCQcm7ubgEpE4HG6 gyAAqmP9tJYGRU5P+bzIvkUYt56SLlUwBbcbFXRrSTM0k4VnHDNrePV52UFdARFulKAd mGCI2OZJcP6NvdSuzKPEOiYu0EtEQaGcFiE85spay+sWv34t72YkZIT1jxVVl/0kB5T2 pfew== 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 :dkim-signature; bh=QRRUJUOXJctvN9PLktMW3h80GnHZHmmhDQykuiBWWWw=; fh=qpxfvBEua7iZFi+sjbljVHlbTqf3rDluNZKWKUolrwI=; b=JpgkNrqRxagaN2WdVDF6qQKvnB0qFbpONREnsAQq+kETXPyVc65JRYLGIxk9ZiGclx cEiRAbQIlQMzvadZ08iyyXmJXGvhjySHo84wEHVNv63sGDPZNTemp7itm0keAa7tQIwx H4eUmif89VTT02Sibmgaeat4S2q9TLAVJT3HpxDn1GJCIpT9gJRj2uzLEsjVsAKABeEd ugWC9KgQ4K2ft1w9vN4qcDloYKRQxLPXs/k/QaH2UBLrZfBj/oLd9YH5qCBF9Ggy3AMd VcITzpHLOf5XuCGIOfipDZ1ZXG6I+Z83iy7xsAzNdHjSPUXiDlgDFzAg581+nrBT5EUB TgQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=buX7GBHE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id s5-20020a17090a948500b00283a2ae9f65si9100636pjo.92.2023.11.21.11.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 11:59:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=buX7GBHE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id F0D59811F918; Tue, 21 Nov 2023 11:59:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233937AbjKUT7h (ORCPT + 99 others); Tue, 21 Nov 2023 14:59:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234023AbjKUT7f (ORCPT ); Tue, 21 Nov 2023 14:59:35 -0500 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC055D49; Tue, 21 Nov 2023 11:59:30 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1ce3084c2d1so50378975ad.3; Tue, 21 Nov 2023 11:59:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700596770; x=1701201570; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QRRUJUOXJctvN9PLktMW3h80GnHZHmmhDQykuiBWWWw=; b=buX7GBHEwXDVpVodg80gJvMUemu87ywu4VX83eJ+Rj3JTWAZu1hSPfcSeMqONDP/X8 iEzcxFOG2/s8e94NvoVIIOlYlKMOjTXlQQt4W5knMwYFhp4sGjOw5wZM/MoC+5buEK7q DBAKS8sRpLy2bI5gRc33gibudnPqfteJlIRbNWir0MHhBku0e/79zOZov/bHJIXNMLOi qjKUDLBcpmGBelOanB+69efhwEHwPCngMhIIuBGs73p3R7YREBjJP41bDsX+yN3rtPg/ Ul9wcAXYZkDBCFJ6KmEONi+h03TvwgXbYDpnx/hNjnpNI1G2pFYE9ZryHzhCMzF+Yns0 6pyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700596770; x=1701201570; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QRRUJUOXJctvN9PLktMW3h80GnHZHmmhDQykuiBWWWw=; b=tS6Q1S8DHBHEJ+nW97AnwXvZkA1dMTbltVemfrVnCfoDlBPrJlbXWOKjLQ55aTemFn bpE90IIB4c1mYxD06twpS0V3sU3L06RKu1vpjEdrR97BrmEoGVsDzSUjGiO3oDx36Sqa 7A2Hc60Q5esdauBjSdB4iPGa6p4PR66fsV6tgfi2b1sJlbfjyTgZp1ldDLMf85vy24Hs oKcFrmV7+iMeLkYSjxpTFeTyvpMHWVvYzWhbmlrdlKrIZuALNAilHW/CKKeUTEUS3khm tBffO0pCzm4Hjd3b0naBTlKG9dc7SgQYWx3cqZ2/+J6mS1JTNBzALO/NWATsgv4XEv4I rQYw== X-Gm-Message-State: AOJu0YyhQrpXE3FSbVzojXR06JgzsGpp4GKjlHt+N1oDyB0jCHLkfvME MXpKu5SmW1q34eRDsc3SeO0= X-Received: by 2002:a17:903:124b:b0:1cc:2dad:7ae9 with SMTP id u11-20020a170903124b00b001cc2dad7ae9mr190268plh.32.1700596770331; Tue, 21 Nov 2023 11:59:30 -0800 (PST) Received: from localhost.localdomain ([110.46.146.116]) by smtp.gmail.com with ESMTPSA id u4-20020a17090282c400b001cc615e6850sm8310732plz.90.2023.11.21.11.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 11:59:29 -0800 (PST) From: SungHwan Jung To: "Lee, Chun-Yi" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Mark Gross , Jean Delvare , Guenter Roeck Cc: SungHwan Jung , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org Subject: [PATCH 2/2] platform/x86: acer-wmi: add fan speed monitoring for Date: Wed, 22 Nov 2023 04:58:16 +0900 Message-ID: <20231121195817.18128-3-onenowy@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231121195817.18128-1-onenowy@gmail.com> References: <20231121195817.18128-1-onenowy@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 11:59:40 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783204969934605179 X-GMAIL-MSGID: 1783204969934605179 Support CPU and GPU fan speed monitoring through WMI for Predator PHN16-71. This patch depends on patch "platform/x86: acer-wmi: Add platform profile and mode key support for Predator PHN16-71" Signed-off-by: SungHwan Jung --- drivers/platform/x86/acer-wmi.c | 101 +++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c index 6572a8f7a..6ad9d4030 100644 --- a/drivers/platform/x86/acer-wmi.c +++ b/drivers/platform/x86/acer-wmi.c @@ -30,6 +30,7 @@ #include #include #include +#include MODULE_AUTHOR("Carlos Corbacho"); MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver"); @@ -96,6 +97,8 @@ enum acer_wmi_event_ids { enum acer_wmi_predator_v4_sys_info_command { ACER_WMID_CMD_GET_PREDATOR_V4_BAT_STATUS = 0x02, + ACER_WMID_CMD_GET_PREDATOR_V4_CPU_FAN_SPEED = 0x0201, + ACER_WMID_CMD_GET_PREDATOR_V4_GPU_FAN_SPEED = 0x0601, }; static const struct key_entry acer_wmi_keymap[] __initconst = { @@ -241,6 +244,7 @@ struct hotkey_function_type_aa { #define ACER_CAP_TURBO_LED BIT(8) #define ACER_CAP_TURBO_FAN BIT(9) #define ACER_CAP_PLAFORM_PROFILE BIT(10) +#define ACER_CAP_FAN_SPEED_READ BIT(11) /* * Interface type flags @@ -353,7 +357,8 @@ static void __init set_quirks(void) | ACER_CAP_TURBO_FAN; if (quirks->predator_v4) - interface->capability |= ACER_CAP_PLAFORM_PROFILE; + interface->capability |= ACER_CAP_PLAFORM_PROFILE | + ACER_CAP_FAN_SPEED_READ; } static int __init dmi_matched(const struct dmi_system_id *dmi) @@ -1722,6 +1727,25 @@ static int acer_gsensor_event(void) return 0; } +static int acer_get_fan_speed(int fan) +{ + if (quirks->predator_v4) { + acpi_status status; + u64 fanspeed; + + status = WMI_gaming_execute_u64( + ACER_WMID_GET_GAMING_SYS_INFO_METHODID, + fan == 0 ? ACER_WMID_CMD_GET_PREDATOR_V4_CPU_FAN_SPEED : + ACER_WMID_CMD_GET_PREDATOR_V4_GPU_FAN_SPEED, + &fanspeed); + + if (ACPI_FAILURE(status)) + return -EIO; + return fanspeed >> 8; + } + return -EOPNOTSUPP; +} + /* * Predator series turbo button */ @@ -2476,6 +2500,8 @@ static u32 get_wmid_devices(void) return devices; } +static int acer_wmi_hwmon_init(void); + /* * Platform device */ @@ -2505,6 +2531,12 @@ static int acer_platform_probe(struct platform_device *device) goto error_platform_profile; } + if (has_cap(ACER_CAP_FAN_SPEED_READ)) { + err = acer_wmi_hwmon_init(); + if (err < 0) + return err; + } + return err; error_rfkill: @@ -2617,6 +2649,73 @@ static void __init create_debugfs(void) &interface->debug.wmid_devices); } +static umode_t acer_wmi_hwmon_is_visible(const void *data, + enum hwmon_sensor_types type, u32 attr, + int channel) +{ + switch (type) { + case hwmon_fan: + if (acer_get_fan_speed(channel) >= 0) + return 0444; + break; + default: + return 0; + } + + return 0; +} + +static int acer_wmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + int ret; + + switch (type) { + case hwmon_fan: + ret = acer_get_fan_speed(channel); + if (ret < 0) + return ret; + *val = ret; + break; + default: + return -EOPNOTSUPP; + } + + return 0; +} + +static const struct hwmon_channel_info *const acer_wmi_hwmon_info[] = { + HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT, HWMON_F_INPUT), NULL +}; + +static const struct hwmon_ops acer_wmi_hwmon_ops = { + .read = acer_wmi_hwmon_read, + .is_visible = acer_wmi_hwmon_is_visible, +}; + +static const struct hwmon_chip_info acer_wmi_hwmon_chip_info = { + .ops = &acer_wmi_hwmon_ops, + .info = acer_wmi_hwmon_info, +}; + +static int acer_wmi_hwmon_init(void) +{ + struct device *dev = &acer_platform_device->dev; + struct device *hwmon; + + hwmon = devm_hwmon_device_register_with_info(dev, "acer", + &acer_platform_driver, + &acer_wmi_hwmon_chip_info, + NULL); + + if (IS_ERR(hwmon)) { + dev_err(dev, "Could not register acer hwmon device\n"); + return PTR_ERR(hwmon); + } + + return 0; +} + static int __init acer_wmi_init(void) { int err;