From nobody Fri Apr 3 02:58:10 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A5973C65E1 for ; Tue, 24 Mar 2026 22:10:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774390225; cv=none; b=EIL6n8lTavTJkvHA1+yDRZfRtPo1LwRrEG7q30PpPdcnQEnvFpIrR7UWnHQWh0HJrcqDGReR0gARWASKw9wYDDps8X4lRZq+7PaEbNyEBtLyKnrQy20r3i0LHOn1p91o5MJ5lVlSAhI0+aNzTxZNbKTi9iEkIgSHLwXTOBWUdYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774390225; c=relaxed/simple; bh=DBk2/dZpgI3ud4uRbon6l/tLkmPpW6hhRXmR7S8Xcfs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fqcxbm3DKi8PupjUr1MO1g81lbfok4SdaU2MhFpBdI2t9GlQrfyQQ8AVrSl7mW5MFGyiR1bjFY8lqLQI/AiAjKUaPs806J5wOPNEBmP11/0tc2dH9Q7NDXv4ZwhE/lDHABmipKiNgsJYYMnAVfWV+sa2leW55Favk0FW8YQ7YHg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HgC8qzFd; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HgC8qzFd" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-48558d6ef83so42526885e9.3 for ; Tue, 24 Mar 2026 15:10:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774390222; x=1774995022; 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=fICrsb3AJbCbrFEsOXMZEh6EVvU44ucCuYv+xVHC3PQ=; b=HgC8qzFdiftTozkNQ34CF6A6bSllTISCbW4JVxFX3tuq2bg69X2iJD7JYuBffmLpHm ujh2z4qSaynT9CaYjgqrGB96iaH1kxeDeN1Q+agFGBG7ym8dFNGArlbqMTbxAP28FdL4 McXT6Ls8R8bW7in6MXowE5HtCxR1yIxZyZELoe/SVFru5PNcoWHixk3iMRvsXOZSYkiZ e7zk4okv47sDSrNUFGfAQ8hY4OND5HFRoRsisdsGy0e+YnmG7ht84i2T0aoSQBCjwbvv /xvwGM5J2WdhaVGTlXXc9quvv6p9X2PRNvQfrDDJjsQVsogvB26cQKknTRWmEFOgG77D 8SiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774390222; x=1774995022; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=fICrsb3AJbCbrFEsOXMZEh6EVvU44ucCuYv+xVHC3PQ=; b=Axsr/6KFbvi9kqGz8VQDHNiFuuQT24caA6IjFPTuJqnTIwgVEO45zimJ+G0yIJclYR e8Ly6quPdp6Oj1+cMp8YlajuZy+Zh8nbkbfUZv1WNT+iOZmy5sO8PdOSBn0mhgXjCkYy GzD/YOs7v2NExVbQQZLgzok5w+p34DkzF4WxBiZR4qhtlDhbM5QVG5G//nUxp7subpgk YcRzGBDn3/mu9/hryud1GCg+8k883D87ymd08IImWRx/yMuoUQg84peFnBH8t9t6FWyC ZFRw9ZX4jnBhXAu0O3ULvLpW92Bs3zgyrU+9BpHnNS0r939hTdG1cgLq5B9tuZj89qr6 3KCg== X-Forwarded-Encrypted: i=1; AJvYcCWStXrW2ityaf71HN8svZa6q3JOcDqGvjom4BjBakgdTK2P1ubnwvNl8kE3fTWGW9d6vL/1gJPpOhJs1yw=@vger.kernel.org X-Gm-Message-State: AOJu0YxsnLjbcEAOjkSYXt55AruEitfZla6glRgTu9V7BYURXwBgfpPm NKDHGZ3JxZsNgK2Y4Ozrr9c2WpzabBBUa9/hCf467NB+jw71RBlDB5Bbbln8E6tnBalZ7A== X-Gm-Gg: ATEYQzyhbbsDy2XhOQHeUTF/hm3Z/MX5DWIAkLd3A8687O39Scq1mYM0onpyotzneDz jqwuQVaTs4x5KXu12PaqyAxx1L1SA8xPz6DCSDAhhsNIsrhWFlCmr5GdwE7iMexrZs6cfXCVCJy QPJIcXOjNl+7kkObjZkKyEBo1SvkbGNWAyOm6r2TggHVh+/LVJAKRnGnDJ1FbxIp+Vw7uKvHhxC J1tnhl5WTbWkv8HGLjBPVxrvWv9AObX1JaCa3VuUVqnh6xWPWvPqHulaIKiS2r3f1OE7eKJ/GYn VWlACYhQZSyVugg/EmN0XXwuILBcBMmf/qGDse4XL3xDvlevE7c16MlOjUmHG4c7oe3BdHc7Yna PNNcJmLpQIwxydx0BqyJW6yvP1Cb6pyWtkcKa348sx/94SqlkiMXGCywl4aST2pRlplU9Jr1CAd /+y2fCZHe3ZsGfQWcDaJqw/9nrcH8= X-Received: by 2002:a05:600c:35c6:b0:486:fb69:4960 with SMTP id 5b1f17b1804b1-4871603508fmr20089035e9.19.1774390221368; Tue, 24 Mar 2026 15:10:21 -0700 (PDT) Received: from sergio-82n7 ([134.255.161.117]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-487116abecesm67117055e9.5.2026.03.24.15.10.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2026 15:10:20 -0700 (PDT) From: Sergio Melas To: Guenter Roeck Cc: Jean Delvare , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Sergio Melas Subject: [PATCH v6] hwmon: (yogafan) Add support for Lenovo Yoga/Legion fan monitoring Date: Tue, 24 Mar 2026 23:10:00 +0100 Message-ID: <20260324221008.212753-1-sergiomelas@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <5d771a2a-3c82-4d79-8ccd-a67b9d7461e4@roeck-us.net> References: <5d771a2a-3c82-4d79-8ccd-a67b9d7461e4@roeck-us.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This driver provides fan speed monitoring for modern Lenovo Yoga, Legion, and IdeaPad laptops. It interfaces with the Embedded Controller (EC) via ACPI to retrieve tachometer data. To address low-resolution sampling in the Lenovo EC firmware, the driver implements a Rate-Limited Lag (RLLag) filter using a passive discrete-time first-order model. This ensures physical consistency of the RPM signal regardless of userspace polling rates. Signed-off-by: Sergio Melas --- v6: - Unified patch structure (6 files changed). - Verified FOPTD (First-Order Plus Time Delay) model against hardware=20 traces (Yoga 14c) to ensure physical accuracy of the 1000ms time const= ant. - Fixed a rounding stall: added a +/- 1 RPM floor to the step calculation=20 to ensure convergence even at high polling frequencies. - Set MAX_SLEW_RPM_S to 1500 to match physical motor inertia. - Documentation: Updated to clarify 100-RPM hardware step resolution. - 32-bit safety: Implemented div64_s64 for coefficient precision. v5: - Fixed 32-bit build failures by using div64_s64 for 64-bit division. - Extracted magic numbers into constants (RPM_UNIT_THRESHOLD, etc.). - Fixed filter stall by ensuring a minimum slew limit (limit =3D 1). - Refined RPM floor logic to trigger only when hardware reports 0 RPM. - Resolved 255/256 unit-jump bug by adjusting heuristic thresholds. v4: - Rebased on groeck/hwmon-next branch for clean application. - Corrected alphabetical sorting in Kconfig and Makefile. - Technical Validation & FOPTD Verification: - Implemented RLLag (Rate-Limited Lag) first-order modeling. - Used 10-bit fixed-point math for alpha calculation to avoid floating point overhead in the kernel. - Added 5000ms filter reset for resume/long-polling sanitation. v3: - Added MAINTAINERS entry and full Documentation/hwmon/yogafan.rst. - Fixed integer overflow in filter math. - Added support for secondary fan paths (FA2S) for Legion laptops. v2: - Migrated from background worker to passive multirate filtering. - Implemented dt-based scaling to maximize CPU sleep states. - Restricted driver to Lenovo hardware via DMI matching. v1: - Initial submission with basic ACPI fan path support. --- --- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/yogafan.rst | 48 +++++++ MAINTAINERS | 8 ++ drivers/hwmon/Kconfig | 9 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/yogafan.c | 225 ++++++++++++++++++++++++++++++++ 6 files changed, 292 insertions(+) create mode 100644 Documentation/hwmon/yogafan.rst create mode 100644 drivers/hwmon/yogafan.c diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst index 559c32344cd3..199f35a75282 100644 --- a/Documentation/hwmon/index.rst +++ b/Documentation/hwmon/index.rst @@ -282,4 +282,5 @@ Hardware Monitoring Kernel Drivers xdp710 xdpe12284 xdpe152c4 + yogafan zl6100 diff --git a/Documentation/hwmon/yogafan.rst b/Documentation/hwmon/yogafan.= rst new file mode 100644 index 000000000000..e0f2b060aabc --- /dev/null +++ b/Documentation/hwmon/yogafan.rst @@ -0,0 +1,48 @@ +.. SPDX-License-Identifier: GPL-2.0-only + +Kernel driver yogafan +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Supported chips: + + * Lenovo Yoga, Legion, and IdeaPad Embedded Controllers + Prefix: 'yogafan' + Addresses: ACPI handle (see probe list in driver) + +Author: Sergio Melas + +Description +----------- + +This driver provides fan speed monitoring for modern Lenovo laptops. +Most Lenovo laptops do not provide fan tachometer data through standard +ISA/LPC hardware monitoring chips. Instead, the data is stored in the +Embedded Controller (EC) and exposed via ACPI. + +The driver implements a **Rate-Limited Lag (RLLag)** filter to handle +the low-resolution and jittery sampling found in Lenovo EC firmware. + +Filter Details: +--------------- + +The RLLag filter is a discrete-time first-order lag model that ensures: + - **Smoothing:** Jittery 1000-RPM step increments are smoothed into 1-RP= M increments. + - **Slew-Rate Limiting:** Prevents "teleporting" readings by capping the= change + to 1500 RPM/s, matching physical fan inertia. + - **Polling Independence:** The filter math scales based on the time del= ta + between userspace reads, ensuring the same physical curve regardless + of whether you poll at 1Hz or 1000Hz. + +Usage +----- + +The driver exposes standard hwmon sysfs attributes: + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D +Attribute Description +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D +fanX_input Filtered fan speed in RPM. +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D + +Note: If the hardware reports 0 RPM, the filter is bypassed and 0 is repor= ted +immediately to ensure the user knows the fan has stopped. diff --git a/MAINTAINERS b/MAINTAINERS index 830c6f076b00..94416af57b28 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14873,6 +14873,14 @@ W: https://linuxtv.org Q: http://patchwork.linuxtv.org/project/linux-media/list/ F: drivers/media/usb/dvb-usb-v2/lmedm04* =20 +LENOVO YOGA FAN DRIVER +M: Sergio Melas +L: linux-hwmon@vger.kernel.org +W: https://github.com/sergiomelas +S: Maintained +F: Documentation/hwmon/yogafan.rst +F: drivers/hwmon/yogafan.c + LOADPIN SECURITY MODULE M: Kees Cook S: Supported diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 7dd8381ba0d0..f87023a0066e 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -2653,6 +2653,15 @@ config SENSORS_XGENE If you say yes here you get support for the temperature and power sensors for APM X-Gene SoC. =20 +config SENSORS_YOGAFAN + tristate "Lenovo Yoga Fan Hardware Monitoring" + depends on ACPI && HWMON + select MATH64 + help + Say Y here if you want to monitor fan speeds on Lenovo Yoga + and Legion laptops. + + config SENSORS_INTEL_M10_BMC_HWMON tristate "Intel MAX10 BMC Hardware Monitoring" depends on MFD_INTEL_M10_BMC_CORE diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 556e86d277b1..0fce31b43eb1 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -245,6 +245,7 @@ obj-$(CONFIG_SENSORS_W83L786NG) +=3D w83l786ng.o obj-$(CONFIG_SENSORS_WM831X) +=3D wm831x-hwmon.o obj-$(CONFIG_SENSORS_WM8350) +=3D wm8350-hwmon.o obj-$(CONFIG_SENSORS_XGENE) +=3D xgene-hwmon.o +obj-$(CONFIG_SENSORS_YOGAFAN) +=3D yogafan.o =20 obj-$(CONFIG_SENSORS_OCC) +=3D occ/ obj-$(CONFIG_SENSORS_PECI) +=3D peci/ diff --git a/drivers/hwmon/yogafan.c b/drivers/hwmon/yogafan.c new file mode 100644 index 000000000000..44b6a7fd2deb --- /dev/null +++ b/drivers/hwmon/yogafan.c @@ -0,0 +1,225 @@ +// SPDX-License-Identifier: GPL-2.0-only +/** + * yoga_fan.c - Lenovo Yoga/Legion Fan Hardware Monitoring Driver + * + * Provides fan speed monitoring for Lenovo Yoga, Legion, and IdeaPad + * laptops by interfacing with the Embedded Controller (EC) via ACPI. + * + * The driver implements a passive discrete-time first-order lag filter + * with slew-rate limiting (RLLag). This addresses low-resolution + * tachometer sampling in the EC by smoothing RPM readings based on + * the time delta (dt) between userspace requests, ensuring physical + * consistency without background task overhead or race conditions. + * The filter implements multirate filtering with autoreset in case + * of large sampling time. + * + * Copyright (C) 2021-2026 Sergio Melas + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* Driver Configuration Constants */ +#define DRVNAME "yogafan" +#define MAX_FANS 8 +/* Filter Configuration Constants */ +#define TAU_MS 1000 /* Time constant for the first-order lag (= ms) */ +#define MAX_SLEW_RPM_S 1500 /* Maximum allowed change in RPM per seco= nd */ +#define MAX_SAMPLING 5000 /* Maximum allowed Ts for reset (ms) */ +/* RPM Heuristic and Sanitation Constants */ +#define RPM_UNIT_THRESHOLD 500 /* Values below this treated as units of 1= 00 */ +#define RPM_UNIT_MULT 100 /* Multiplier for low-res EC readings */ +#define RPM_FLOOR_LIMIT 50 /* Snap filtered value to 0 if raw is 0 */ + +struct yoga_fan_data { + const char *active_paths[MAX_FANS]; + long filtered_val[MAX_FANS]; + ktime_t last_sample[MAX_FANS]; /* Renamed from last_update for consistenc= y */ + int fan_count; +}; +/** + * apply_rllag_filter - Discrete-time filter update (Passive Multirate) + * @data: pointer to driver data + * @idx: fan index + * @raw_rpm: new raw value from ACPI + */ +static void apply_rllag_filter(struct yoga_fan_data *data, int idx, long r= aw_rpm) +{ + ktime_t now =3D ktime_get(); + s64 dt_ms =3D ktime_to_ms(ktime_sub(now, data->last_sample[idx])); + long delta, step, limit, alpha; + s64 temp_num; + + /* Initialize on first run or after long sleep/stall */ + if (data->last_sample[idx] =3D=3D 0 || dt_ms > MAX_SAMPLING) { + data->filtered_val[idx] =3D raw_rpm; + data->last_sample[idx] =3D now; + return; + } + if (dt_ms <=3D 0) return; + + delta =3D raw_rpm - data->filtered_val[idx]; + if (delta =3D=3D 0) { + data->last_sample[idx] =3D now; + return; + } + /* Alpha with 12-bit precision to prevent alpha=3D0 on fast polls */ + temp_num =3D dt_ms << 12; + alpha =3D (long)div64_s64(temp_num, (s64)(TAU_MS + dt_ms)); + step =3D (delta * alpha) >> 12; + /* FIX THE STALL: Force a move of 1 RPM if alpha*delta rounds to zero */ + if (step =3D=3D 0 && delta !=3D 0) + step =3D (delta > 0) ? 1 : -1; + /* SLEW RATE LIMITING: Scaled by time delta */ + limit =3D (MAX_SLEW_RPM_S * (long)dt_ms) / 1000; + if (limit < 1) limit =3D 1; + /* Clamp step to physical slew rate */ + if (step > limit) + step =3D limit; + else if (step < -limit) + step =3D -limit; + data->filtered_val[idx] +=3D step; + data->last_sample[idx] =3D now; +} + +static int yoga_fan_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + struct yoga_fan_data *data =3D dev_get_drvdata(dev); + unsigned long long raw_acpi; + acpi_status status; + long rpm; + + if (type !=3D hwmon_fan || attr !=3D hwmon_fan_input) + return -EOPNOTSUPP; + status =3D acpi_evaluate_integer(NULL, (acpi_string)data->active_paths[ch= annel], + NULL, &raw_acpi); + if (ACPI_FAILURE(status)) + return -EIO; + /* * Heuristic: Convert units-of-100 to raw RPM. + * Most Yoga/Legion ECs return a single byte (0-255). + * We use 500 as a safety threshold to distinguish from raw 16-bit RPM. + */ + rpm =3D (long)raw_acpi; + if (rpm > 0 && rpm < RPM_UNIT_THRESHOLD) + rpm *=3D RPM_UNIT_MULT; + apply_rllag_filter(data, channel, rpm); + *val =3D data->filtered_val[channel]; + return 0; +} + +static umode_t yoga_fan_is_visible(const void *data, enum hwmon_sensor_typ= es type, + u32 attr, int channel) +{ + const struct yoga_fan_data *fan_data =3D data; + + if (type =3D=3D hwmon_fan && channel < fan_data->fan_count) + return 0444; + return 0; +} + +static const struct hwmon_ops yoga_fan_hwmon_ops =3D { + .is_visible =3D yoga_fan_is_visible, + .read =3D yoga_fan_read, +}; + +static const struct hwmon_channel_info *yoga_fan_info[] =3D { + HWMON_CHANNEL_INFO(fan, + HWMON_F_INPUT, HWMON_F_INPUT, HWMON_F_INPUT, HWMON_F_INPUT, + HWMON_F_INPUT, HWMON_F_INPUT, HWMON_F_INPUT, HWMON_F_INPUT), + NULL +}; + +static const struct hwmon_chip_info yoga_fan_chip_info =3D { + .ops =3D &yoga_fan_hwmon_ops, + .info =3D yoga_fan_info, +}; + +static int yoga_fan_probe(struct platform_device *pdev) +{ + struct yoga_fan_data *data; + struct device *hwmon_dev; + acpi_handle handle; + int i; + static const char * const fan_paths[] =3D { + "\\_SB.PCI0.LPC0.EC0.FANS", /* Primary Fan (Yoga 14c) */ + "\\_SB.PCI0.LPC0.EC0.FA2S", /* Secondary Fan (Legion) */ + "\\_SB.PCI0.LPC0.EC0.FAN0", /* IdeaPad / Slim */ + "\\_SB.PCI0.LPC.EC.FAN0", /* Legacy */ + "\\_SB.PCI0.LPC0.EC.FAN0", /* Alternate */ + }; + data =3D devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + data->fan_count =3D 0; + for (i =3D 0; i < ARRAY_SIZE(fan_paths); i++) { + if (ACPI_SUCCESS(acpi_get_handle(NULL, (char *)fan_paths[i], &handle))) { + data->active_paths[data->fan_count] =3D fan_paths[i]; + data->fan_count++; + if (data->fan_count >=3D MAX_FANS) + break; + } + } + + if (data->fan_count =3D=3D 0) + return -ENODEV; + platform_set_drvdata(pdev, data); + hwmon_dev =3D devm_hwmon_device_register_with_info(&pdev->dev, DRVNAME, + data, &yoga_fan_chip_info, NULL); + return PTR_ERR_OR_ZERO(hwmon_dev); +} + +static struct platform_driver yoga_fan_driver =3D { + .driver =3D { + .name =3D DRVNAME, + }, + .probe =3D yoga_fan_probe, +}; + +static struct platform_device *yoga_fan_device; + +static const struct dmi_system_id yoga_dmi_table[] __initconst =3D { + { + .ident =3D "Lenovo", + .matches =3D { + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), + }, + }, + { } +}; +MODULE_DEVICE_TABLE(dmi, yoga_dmi_table); + +static int __init yoga_fan_init(void) +{ + int ret; + + if (!dmi_check_system(yoga_dmi_table)) + return -ENODEV; + ret =3D platform_driver_register(&yoga_fan_driver); + if (ret) + return ret; + yoga_fan_device =3D platform_device_register_simple(DRVNAME, 0, NULL, 0); + if (IS_ERR(yoga_fan_device)) { + platform_driver_unregister(&yoga_fan_driver); + return PTR_ERR(yoga_fan_device); + } + return 0; +} + +static void __exit yoga_fan_exit(void) +{ + platform_device_unregister(yoga_fan_device); + platform_driver_unregister(&yoga_fan_driver); +} + +module_init(yoga_fan_init); +module_exit(yoga_fan_exit); +MODULE_AUTHOR("Sergio Melas "); +MODULE_DESCRIPTION("Lenovo Yoga/Legion Fan Monitor Driver"); +MODULE_LICENSE("GPL"); --=20 2.53.0