Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3882116pxf; Tue, 6 Apr 2021 02:37:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNQlunV6tr3iBihPaKk63NXjPKrzfFQ27vXECFmVI1cDv7I4Cm0NY1pCmEsOpnNqIljReG X-Received: by 2002:a92:7b12:: with SMTP id w18mr22900554ilc.101.1617701862334; Tue, 06 Apr 2021 02:37:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617701862; cv=none; d=google.com; s=arc-20160816; b=J8xN/+xA0uRB/hffexpFu+N7oJ4xhRYRY6M6u6AdxZKQVpFnLjMAFLcLFjbHC5LZOG 70j4OJ4og6j0vNRslhpdkY1WUZRmW7wkodDC5zuP5YXbToU0+9SLln9bStOv2P4YDD4E F2SWbQMBAU8aQmMDlIJhP2yCiQAvWVJrosmktLUmRKvDF71coCA9dQ8F86nAVR0Fagwq Orgoal88m8i0qZSnNEIgO7HgJYOs//a7CZIACfImJIEFNJ3F78+Y05an9VSiY0sbGJ/K W2y8b6ps6HPKp7KgP11+uekOl3tWhbVHsEIUER3JMfiSopZFAOGwCWShRv+qVyE2Pq6X AEhw== 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:dkim-signature :from; bh=QJ2oM7bH/3yPYq2Xe9Wz7yfd+XMLHjLpel29SHFFmUM=; b=znq3y0H5ELEkDiNsAp70NsZB/OOynSf1UJMwKWMHHSTaxUhpr3zxcVuLRIHjZdkJKf ZRrpPlyKGrY01+uqJrtFJo//+5Wtvkc9FRlYshaeS2oWd0KkReSwvFEfFyZ8tTmX17Fo rL6fT+Z9bzgt8g8G+OdeIcsGkDtbHqc0ldzyfIZAtmWIjpWh+v5Ceu9kPD3zJai0eL6y X2RIvPYkF3F8DTZWc6M2sUAk5/Kb7nP2u2Msmfwjy2kCUPDHlPHy4v7ULBIPJgTdFIXa f68oA07J3Lo6Do2goIDveqhinF2JDbolDi3jXf2ajUNYAPeUGNlIGmskvUYqCcpq0vPv w63w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b="RzEc/j9U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o12si15777182ilu.83.2021.04.06.02.37.30; Tue, 06 Apr 2021 02:37:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b="RzEc/j9U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235895AbhDEUt4 (ORCPT + 99 others); Mon, 5 Apr 2021 16:49:56 -0400 Received: from ned.t-8ch.de ([212.47.237.191]:54754 "EHLO ned.t-8ch.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232860AbhDEUtx (ORCPT ); Mon, 5 Apr 2021 16:49:53 -0400 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1617655777; bh=F2uG0XiAg/JJ2Fj+hieuEdstolegFP/KI92lWRicuWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RzEc/j9UOiKD2AbKLZ7zUuC5wAb43gbJd7xwJqZkV2kRMSqVmR5TuKxeuFixe+eO6 E6idX6JnVjmYbLm4y15TxJCO1W6Bct1tcp5yjUlbZy83/aR+gTDj5lltHGOLadnGjR 7Xk9+AzBIdnBH0L0clVqQutaWZGDcHl6TFeqQ9SU= To: platform-driver-x86@vger.kernel.org, Mark Gross , Hans de Goede , linux-kernel@vger.kernel.org, =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Cc: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Matthew Garrett Subject: [PATCH v2] platform/x86: add Gigabyte WMI temperature driver Date: Mon, 5 Apr 2021 22:48:10 +0200 Message-Id: <20210405204810.339763-1-linux@weissschuh.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Changes since v1: * Incorporate feedback from Barnabás Pőcze * Use a WMI driver instead of a platform driver * Let the kernel manage the driver lifecycle * Fix errno/ACPI error confusion * Fix resource cleanup * Document reason for integer casting Thank you Barnabás for your review, it is much appreciated. -- >8 -- Tested with a X570 I Aorus Pro Wifi. The mainboard contains an ITE IT8688E chip for management. This chips is also handled by drivers/hwmon/i87.c but as it is also used by the firmware itself it needs an ACPI driver. Unfortunately not all sensor registers are handled by the firmware and even less are exposed via WMI. Signed-off-by: Thomas Weißschuh --- drivers/platform/x86/Kconfig | 11 +++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/gigabyte-wmi.c | 138 ++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 drivers/platform/x86/gigabyte-wmi.c diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index ad4e630e73e2..96622a2106f7 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -123,6 +123,17 @@ config XIAOMI_WMI To compile this driver as a module, choose M here: the module will be called xiaomi-wmi. +config GIGABYTE_WMI + tristate "Gigabyte WMI temperature driver" + depends on ACPI_WMI + depends on HWMON + help + Say Y here if you want to support WMI-based temperature reporting on + Gigabyte mainboards. + + To compile this driver as a module, choose M here: the module will + be called gigabyte-wmi. + config ACERHDF tristate "Acer Aspire One temperature and fan driver" depends on ACPI && THERMAL diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index 60d554073749..1621ebfd04fd 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -15,6 +15,7 @@ obj-$(CONFIG_INTEL_WMI_THUNDERBOLT) += intel-wmi-thunderbolt.o obj-$(CONFIG_MXM_WMI) += mxm-wmi.o obj-$(CONFIG_PEAQ_WMI) += peaq-wmi.o obj-$(CONFIG_XIAOMI_WMI) += xiaomi-wmi.o +obj-$(CONFIG_GIGABYTE_WMI) += gigabyte-wmi.o # Acer obj-$(CONFIG_ACERHDF) += acerhdf.o diff --git a/drivers/platform/x86/gigabyte-wmi.c b/drivers/platform/x86/gigabyte-wmi.c new file mode 100644 index 000000000000..8618363e3ccf --- /dev/null +++ b/drivers/platform/x86/gigabyte-wmi.c @@ -0,0 +1,138 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2021 Thomas Weißschuh + */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include + +#define GIGABYTE_WMI_GUID "DEADBEEF-2001-0000-00A0-C90629100000" + +enum gigabyte_wmi_commandtype { + GIGABYTE_WMI_BUILD_DATE_QUERY = 0x1, + GIGABYTE_WMI_MAINBOARD_TYPE_QUERY = 0x2, + GIGABYTE_WMI_FIRMWARE_VERSION_QUERY = 0x4, + GIGABYTE_WMI_MAINBOARD_NAME_QUERY = 0x5, + GIGABYTE_WMI_TEMPERATURE_QUERY = 0x125, +}; + +struct gigabyte_wmi_args { + u32 arg1; +}; + +static int gigabyte_wmi_perform_query(enum gigabyte_wmi_commandtype command, + struct gigabyte_wmi_args *args, struct acpi_buffer *out) +{ + const struct acpi_buffer in = { + .length = sizeof(*args), + .pointer = args, + }; + + acpi_status ret = wmi_evaluate_method(GIGABYTE_WMI_GUID, 0x0, command, &in, out); + if (ret == AE_OK) { + return 0; + } else { + return -EIO; + }; +} + +static int gigabyte_wmi_query_integer(enum gigabyte_wmi_commandtype command, + struct gigabyte_wmi_args *args, u64 *res) +{ + union acpi_object *obj; + struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL }; + int ret; + + ret = gigabyte_wmi_perform_query(command, args, &result); + if (ret) { + goto out; + } + obj = result.pointer; + if (obj && obj->type == ACPI_TYPE_INTEGER) { + *res = obj->integer.value; + ret = 0; + } else { + ret = -EIO; + } +out: + kfree(result.pointer); + return ret; +} + +static int gigabyte_wmi_temperature(u8 sensor, long *res) +{ + struct gigabyte_wmi_args args = { + .arg1 = sensor, + }; + u64 temp; + acpi_status ret; + + ret = gigabyte_wmi_query_integer(GIGABYTE_WMI_TEMPERATURE_QUERY, &args, &temp); + if (ret == 0) + *res = (s8) temp * 1000; // value is a signed 8-bit integer + return ret; +} + +static int gigabyte_wmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + return gigabyte_wmi_temperature(channel, val); +} + +static umode_t gigabyte_wmi_hwmon_is_visible(const void *data, enum hwmon_sensor_types type, + u32 attr, int channel) +{ + return 0444; +} + +static const struct hwmon_channel_info *gigabyte_wmi_hwmon_info[] = { + HWMON_CHANNEL_INFO(temp, + HWMON_T_INPUT, + HWMON_T_INPUT, + HWMON_T_INPUT, + HWMON_T_INPUT, + HWMON_T_INPUT, + HWMON_T_INPUT), + NULL, +}; + +static const struct hwmon_ops gigabyte_wmi_hwmon_ops = { + .read = gigabyte_wmi_hwmon_read, + .is_visible = gigabyte_wmi_hwmon_is_visible, +}; + +static const struct hwmon_chip_info gigabyte_wmi_hwmon_chip_info = { + .ops = &gigabyte_wmi_hwmon_ops, + .info = gigabyte_wmi_hwmon_info, +}; + +static int gigabyte_wmi_probe(struct wmi_device *wdev, const void *context) +{ + struct device *hwmon_dev = devm_hwmon_device_register_with_info(&wdev->dev, + "gigabyte_wmi", NULL, + &gigabyte_wmi_hwmon_chip_info, NULL); + + return PTR_ERR_OR_ZERO(hwmon_dev); +} + +static const struct wmi_device_id gigabyte_wmi_id_table[] = { + { GIGABYTE_WMI_GUID, NULL }, + { }, +}; + +static struct wmi_driver gigabyte_wmi_driver = { + .driver = { + .name = "gigabyte-wmi", + }, + .id_table = gigabyte_wmi_id_table, + .probe = gigabyte_wmi_probe, +}; +module_wmi_driver(gigabyte_wmi_driver); + +MODULE_DEVICE_TABLE(wmi, gigabyte_wmi_id_table); +MODULE_AUTHOR("Thomas Weißschuh "); +MODULE_DESCRIPTION("Gigabyte Temperature WMI Driver"); +MODULE_LICENSE("GPL"); base-commit: 144c79ef33536b4ecb4951e07dbc1f2b7fa99d32 -- 2.31.1