Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp463502pxb; Sat, 10 Apr 2021 08:21:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDN9+wBCaIX9cYb5XR3cfxMXzBELJ4ODec4Fk/17TP/RsRFpSZX3pu6oXwVekFFjFrBUyB X-Received: by 2002:aa7:908c:0:b029:209:aacd:d8b with SMTP id i12-20020aa7908c0000b0290209aacd0d8bmr17402906pfa.74.1618068118026; Sat, 10 Apr 2021 08:21:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618068118; cv=none; d=google.com; s=arc-20160816; b=Fl+XWkHDNS/W6+9zBXwnX4RMOP34k2aAZynv53hJ3Ulkut8dPM7sOHAwBTxhjnbNIk cnkf0WWw9LOEVAzXv8otUumePvCBJYoeZB1gCdN0jcWgu/SCjX6QywvRgAjVPpKzoD3k xtYlaMWz31s4Jt7eBdta/X1pViwT/kiUPDQ7cffrierTRbNHUCRfwF57d4i4JA/PpVvD 1rq39cQjCotGNykh3UBpiMzsBxPzNhQ7b8Y1sbB+JnTIng5GWjhog+a2l7ZCxF2jMT+9 hKT5JloK2Ggo2W2+bZ1KT3O3eI4SD2zuBuWXFdQgFQZ++DoIUsvVtNLalNWupCMci6+5 k1Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:autocrypt:from :references:cc:to:subject:sender:dkim-signature; bh=pjI6u6UYsUkFtZQA7WTP9+7XiMaMvTGfuvAt/AdrZpE=; b=kDW/eTNaPBssSfhSl1VJOh+/a+Cv6xWv5+J8JeT0nFFwSm/XG3i9FW9LA10r3h7RMe vR2xY8uPkleC8gWSGDFUpJzsC0+vP/F9pPPcAtdFMLulgOdtSOZddQ0sQ5fnr+4K2UBg haTdvkoVxVO5gK4xYJ/xibsmy5Zo9cDDi+iJhk+vjQAWzt8Ulku+plIHJWor2opbLG1y Sgr7n2D7gB1EMzYVFJZicWyiHBkBf2PP+Pzai7TOBmdJ8ZPG2DX5eebPMF+Es5SfnD1X 5TYvOxbT3MW92ZpLjIB1CeSeDmszmYHCsTEugMYwaa3RAzWzfvzcv3W35LgQ5k4VVL3B ZMwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ul9vhkEC; 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 m9si6254669plc.147.2021.04.10.08.21.45; Sat, 10 Apr 2021 08:21:58 -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=pass header.i=@gmail.com header.s=20161025 header.b=ul9vhkEC; 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 S234754AbhDJPV0 (ORCPT + 99 others); Sat, 10 Apr 2021 11:21:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234392AbhDJPVZ (ORCPT ); Sat, 10 Apr 2021 11:21:25 -0400 Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA5DCC06138A; Sat, 10 Apr 2021 08:21:10 -0700 (PDT) Received: by mail-oo1-xc2b.google.com with SMTP id h2-20020a4ad7420000b02901e5901169a5so1809954oot.8; Sat, 10 Apr 2021 08:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=pjI6u6UYsUkFtZQA7WTP9+7XiMaMvTGfuvAt/AdrZpE=; b=ul9vhkECX9ZtPHmn00cPAEOTNPFYMkc4vVlLAdFgA0ImSW2Yz/cqrLDDaCbiQGf+w/ cNN/cJTUA3sTYVW/YkL5D1AA1ok8DUy85P8GF4gXn/leQJkhfAGBrrvX1nC7Kaec1G7+ e61ykR7cz8w/E/vSLqXxmvfWwd440ktxmCcZnLkt8Y3ZwTrWh8WWSGIKb/GBSIOJzCgR Y0ViOfNDoLzXwgwqXMkSWZlo6DM69YqZoFZ4haMYgvIWc7XEE2DpZbxn4TijMBMhIyiu G75fXKIOgX+3JbJC9W4XTrVV45ozMDg3U6lX4V3iQxrIEvbBEjatrt2wbFJ5wPgsGhJg GTqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=pjI6u6UYsUkFtZQA7WTP9+7XiMaMvTGfuvAt/AdrZpE=; b=Lb4bkC/XC4ucs+g74pa0bUNjo9rbfds70aH3RDWW1z3GKm012rOF5ncfnVur5GprDT /FSzwU+INB5UGVBm4Xg0flPvRjlCWY2g/534xkqk7ew7+dpTIEwLYQqENOTlBCHI0O1s 5CaXdgbaiBGPY5BZJEsaV4F+A110X5XuVM6hZnQ+g/vmyM4ApQpWm4pMgymb7jXv3hff vMLYcZiDYP515Cvd0uCVgNbvWRJjEcRG6vp06+kgELD2YHpyMBOc5rtZR2SleQhXNyEu ghRB7PSU6kwMDEm5KKdMSR19nMy2CpCjugobPnIvt9ssJuK7DTSLjGugVjgghnYWe0iF skuw== X-Gm-Message-State: AOAM531fImHjHc4ir391CHsP6fyaDvsYBF21i7luRLRp5Lpz27Si9TPs TInLjdMxe6YUhBP+JD7OZLNkXTVdZoM= X-Received: by 2002:a4a:bd1a:: with SMTP id n26mr16097535oop.45.1618068069960; Sat, 10 Apr 2021 08:21:09 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id v65sm1164166oib.42.2021.04.10.08.21.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 10 Apr 2021 08:21:09 -0700 (PDT) Sender: Guenter Roeck Subject: Re: [PATCH v3] platform/x86: add Gigabyte WMI temperature driver To: Hans de Goede , =?UTF-8?Q?Thomas_Wei=c3=9fschuh?= , platform-driver-x86@vger.kernel.org, Mark Gross , linux-kernel@vger.kernel.org, =?UTF-8?Q?Barnab=c3=a1s_P=c5=91cze?= , Jean Delvare , linux-hwmon@vger.kernel.org Cc: Matthew Garrett References: <117cadef-c1cb-d66a-15f8-ce50d596be4b@redhat.com> <20210410144021.138035-1-linux@weissschuh.net> From: Guenter Roeck Autocrypt: addr=linux@roeck-us.net; keydata= xsFNBE6H1WcBEACu6jIcw5kZ5dGeJ7E7B2uweQR/4FGxH10/H1O1+ApmcQ9i87XdZQiB9cpN RYHA7RCEK2dh6dDccykQk3bC90xXMPg+O3R+C/SkwcnUak1UZaeK/SwQbq/t0tkMzYDRxfJ7 nyFiKxUehbNF3r9qlJgPqONwX5vJy4/GvDHdddSCxV41P/ejsZ8PykxyJs98UWhF54tGRWFl 7i1xvaDB9lN5WTLRKSO7wICuLiSz5WZHXMkyF4d+/O5ll7yz/o/JxK5vO/sduYDIlFTvBZDh gzaEtNf5tQjsjG4io8E0Yq0ViobLkS2RTNZT8ICq/Jmvl0SpbHRvYwa2DhNsK0YjHFQBB0FX IdhdUEzNefcNcYvqigJpdICoP2e4yJSyflHFO4dr0OrdnGLe1Zi/8Xo/2+M1dSSEt196rXaC kwu2KgIgmkRBb3cp2vIBBIIowU8W3qC1+w+RdMUrZxKGW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uHplgmR3seYCOrT4jriMFBtKNPtj2EE4DNV4s7k0Zy+6iRQ8G8ng QjsSqYJx8iAR8JRB7Gm2rQOMv8lSRdjva++GT0VLXtHULdlzg8VjDnFZ3lfz5PWEOeIMk7Rj trjv82EZtrhLuLjHRCaG50OOm0hwPSk1J64R8O3HjSLdertmw7eyAYOo4RuWJguYMg5DRnBk WkRwrSuCn7UG+qVWZeKEsFKFOkynOs3pVbcbq1pxbhk3TRWCGRU5JolI4ohy/7JV1TVbjiDI HP/aVnm6NC8of26P40Pg8EdAhajZnHHjA7FrJXsy3cyIGqvg9os4rNkUWmrCfLLsZDHD8FnU mDW4+i+XlNFUPUYMrIKi9joBhu18ssf5i5Q= Message-ID: <2ffc9df4-f5d1-e093-6223-e6c705ef8688@roeck-us.net> Date: Sat, 10 Apr 2021 08:21:07 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/10/21 7:57 AM, Hans de Goede wrote: > Hi, > > On 4/10/21 4:40 PM, Thomas Weißschuh wrote: >> 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 >> >> Changes since v2: >> * Style cleanups >> * Test for usability during probing >> * DMI-based whitelist >> * CC hwmon maintainers >> >> -- >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 > > This looks good, one small nitpick: > > I know this is a touchy subject for some, but we are trying to move away > from the whitelist/blacklist naming where possible and we don't want to > introduce any new cases, see: > > https://github.com/torvalds/linux/blob/master/Documentation/process/coding-style.rst#4-naming > > The driver currently uses this twice: > "Force loading on non-whitelisted platform" > "Forcing loading on non-whitelisted platform" > > Interestingly enough you already avoided naming the dmi_system_id table > a whitelist (good). > > I would like to see "non-whitelisted" replaced with "unknown" so that we end up with: > > "Force loading on unknown platform" > "Forcing loading on unknown platform" > > And while at it, I think for the second sentence this would be better English > (I'm not a native speaker myself): > > "Forcing load on unknown platform" > Not native either, but I think it is either "Forcing load" or "Force loading". > If you are ok with these changes I can fix this up while merging, no need > to send a v4. Although if you prefer to send a v4 that is fine too. > Please consider adding an existence check into the is_visible function. Sysfs attributes for non-existing sensors should not be created. Thanks, Guenter > Either way let me know. > > Regards, > > Hans > > p.s. > > For v4 or for a next patch, the way to add the changelog so that it does > not get picked up / automatically gets snipped by git am is to put it > below the Signed-off-by at the end of the commit message like this: > > Signed-off-by: Thomas Weißschuh > --- > 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 > > Changes since v2: > * Style cleanups > * Test for usability during probing > * DMI-based whitelist > * CC hwmon maintainers > > > > > > > >> --- >> MAINTAINERS | 6 + >> drivers/platform/x86/Kconfig | 11 ++ >> drivers/platform/x86/Makefile | 1 + >> drivers/platform/x86/gigabyte-wmi.c | 194 ++++++++++++++++++++++++++++ >> 4 files changed, 212 insertions(+) >> create mode 100644 drivers/platform/x86/gigabyte-wmi.c >> >> diff --git a/MAINTAINERS b/MAINTAINERS >> index d92f85ca831d..9c10cfc00fe8 100644 >> --- a/MAINTAINERS >> +++ b/MAINTAINERS >> @@ -7543,6 +7543,12 @@ F: Documentation/filesystems/gfs2* >> F: fs/gfs2/ >> F: include/uapi/linux/gfs2_ondisk.h >> >> +GIGABYTE WMI DRIVER >> +M: Thomas Weißschuh >> +L: platform-driver-x86@vger.kernel.org >> +S: Maintained >> +F: drivers/platform/x86/gigabyte-wmi.c >> + >> GNSS SUBSYSTEM >> M: Johan Hovold >> S: Maintained >> 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..fb4e6d4c1823 >> --- /dev/null >> +++ b/drivers/platform/x86/gigabyte-wmi.c >> @@ -0,0 +1,194 @@ >> +// 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 >> +#include >> + >> +#define GIGABYTE_WMI_GUID "DEADBEEF-2001-0000-00A0-C90629100000" >> +#define NUM_TEMPERATURE_SENSORS 6 >> + >> +static bool force_load; >> +module_param(force_load, bool, 0); >> +MODULE_PARM_DESC(force_load, "Force loading on non-whitelisted platform"); >> + >> +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(struct wmi_device *wdev, >> + 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 = wmidev_evaluate_method(wdev, 0x0, command, &in, out); >> + >> + if ACPI_FAILURE(ret) >> + return -EIO; >> + >> + return 0; >> +} >> + >> +static int gigabyte_wmi_query_integer(struct wmi_device *wdev, >> + 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(wdev, command, args, &result); >> + if (ret) >> + return ret; >> + obj = result.pointer; >> + if (obj && obj->type == ACPI_TYPE_INTEGER) >> + *res = obj->integer.value; >> + else >> + ret = -EIO; >> + kfree(result.pointer); >> + return ret; >> +} >> + >> +static int gigabyte_wmi_temperature(struct wmi_device *wdev, u8 sensor, long *res) >> +{ >> + struct gigabyte_wmi_args args = { >> + .arg1 = sensor, >> + }; >> + u64 temp; >> + acpi_status ret; >> + >> + ret = gigabyte_wmi_query_integer(wdev, GIGABYTE_WMI_TEMPERATURE_QUERY, &args, &temp); >> + if (ret == 0) { >> + if (temp == 0) >> + return -ENODEV; >> + *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) >> +{ >> + struct wmi_device *wdev = dev_get_drvdata(dev); >> + >> + return gigabyte_wmi_temperature(wdev, 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_validate_sensor_presence(struct wmi_device *wdev) >> +{ >> + int working_sensors = 0, i; >> + long temp; >> + >> + for (i = 0; i < NUM_TEMPERATURE_SENSORS; i++) { >> + if (!gigabyte_wmi_temperature(wdev, i, &temp)) >> + working_sensors++; >> + } >> + return working_sensors ? 0 : -ENODEV; >> +} >> + >> +static const struct dmi_system_id gigabyte_wmi_known_working_platforms[] = { >> + { .matches = { >> + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."), >> + DMI_EXACT_MATCH(DMI_BOARD_NAME, "B550 GAMING X V2"), >> + }}, >> + { .matches = { >> + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."), >> + DMI_EXACT_MATCH(DMI_BOARD_NAME, "B550M DS3H"), >> + }}, >> + { .matches = { >> + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."), >> + DMI_EXACT_MATCH(DMI_BOARD_NAME, "Z390 I AORUS PRO WIFI-CF"), >> + }}, >> + { .matches = { >> + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."), >> + DMI_EXACT_MATCH(DMI_BOARD_NAME, "X570 I AORUS PRO WIFI"), >> + }}, >> + { } >> +}; >> + >> +static int gigabyte_wmi_probe(struct wmi_device *wdev, const void *context) >> +{ >> + struct device *hwmon_dev; >> + int ret; >> + >> + if (!dmi_check_system(gigabyte_wmi_known_working_platforms)) { >> + if (force_load) >> + dev_warn(&wdev->dev, "Forcing loading on non-whitelisted platform"); >> + else >> + return -ENODEV; >> + } >> + >> + ret = gigabyte_wmi_validate_sensor_presence(wdev); >> + if (ret) { >> + dev_info(&wdev->dev, "No temperature sensors usable"); >> + return ret; >> + } >> + >> + hwmon_dev = devm_hwmon_device_register_with_info(&wdev->dev, "gigabyte_wmi", wdev, >> + &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 WMI temperature Driver"); >> +MODULE_LICENSE("GPL"); >> >> base-commit: 144c79ef33536b4ecb4951e07dbc1f2b7fa99d32 >> >