Skip to content

Commit 3ec068d

Browse files
sergiomelasopsiff
authored andcommitted
hwmon: (yogafan) Add support for Lenovo Yoga/Legion fan monitoring
This driver provides fan speed monitoring for Lenovo Yoga, Legion, and IdeaPad laptops by interfacing with the Embedded Controller (EC) via ACPI. To address low-resolution sampling in Lenovo EC firmware, a Rate-Limited Lag (RLLag) filter is implemented. The filter ensures a consistent physical curve regardless of userspace polling frequency. Hardware identification is performed via DMI-based quirk tables, which map specific ACPI object paths and register widths (8-bit vs 16-bit) deterministically. Signed-off-by: Sergio Melas <sergiomelas@gmail.com> Link: https://lore.kernel.org/r/20260327221602.18832-1-sergiomelas@gmail.com [groeck: Dropped double empty line in Kconfig] Signed-off-by: Guenter Roeck <linux@roeck-us.net> [WangYuli: Fix conflicts] Link: https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git/commit/?h=hwmon-next&id=c67c248ca406a86cf8b20bf1b3af5e7f3e36581f Signed-off-by: WangYuli <wangyl5933@chinaunicom.cn>
1 parent ab202a7 commit 3ec068d

6 files changed

Lines changed: 427 additions & 0 deletions

File tree

Documentation/hwmon/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ Hardware Monitoring Kernel Drivers
238238
xgene-hwmon
239239
xdpe12284
240240
xdpe152c4
241+
yogafan
241242
zl6100
242243

243244
.. only:: subproject and html

Documentation/hwmon/yogafan.rst

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
.. SPDX-License-Identifier: GPL-2.0-only
2+
===============================================================================================
3+
Kernel driver yogafan
4+
===============================================================================================
5+
6+
Supported chips:
7+
8+
* Lenovo Yoga, Legion, IdeaPad, Slim, Flex, and LOQ Embedded Controllers
9+
Prefix: 'yogafan'
10+
Addresses: ACPI handle (See Database Below)
11+
12+
Author: Sergio Melas <sergiomelas@gmail.com>
13+
14+
Description
15+
-----------
16+
17+
This driver provides fan speed monitoring for modern Lenovo consumer laptops.
18+
Most Lenovo laptops do not provide fan tachometer data through standard
19+
ISA/LPC hardware monitoring chips. Instead, the data is stored in the
20+
Embedded Controller (EC) and exposed via ACPI.
21+
22+
The driver implements a **Rate-Limited Lag (RLLag)** filter to handle
23+
the low-resolution and jittery sampling found in Lenovo EC firmware.
24+
25+
Hardware Identification and Multiplier Logic
26+
--------------------------------------------
27+
28+
The driver supports two distinct EC architectures. Differentiation is handled
29+
deterministically via a DMI Product Family quirk table during the probe phase,
30+
eliminating the need for runtime heuristics.
31+
32+
1. 8-bit EC Architecture (Multiplier: 100)
33+
- **Families:** Yoga, IdeaPad, Slim, Flex.
34+
- **Technical Detail:** These models allocate a single 8-bit register for
35+
tachometer data. Since 8-bit fields are limited to a value of 255, the
36+
BIOS stores fan speed in units of 100 RPM (e.g., 42 = 4200 RPM).
37+
38+
2. 16-bit EC Architecture (Multiplier: 1)
39+
- **Families:** Legion, LOQ.
40+
- **Technical Detail:** High-performance gaming models require greater
41+
precision for fans exceeding 6000 RPM. These use a 16-bit word (2 bytes)
42+
storing the raw RPM value directly.
43+
44+
Filter Details:
45+
---------------
46+
47+
The RLLag filter is a passive discrete-time first-order lag model that ensures:
48+
- **Smoothing:** Low-resolution step increments are smoothed into 1-RPM increments.
49+
- **Slew-Rate Limiting:** Prevents unrealistic readings by capping the change
50+
to 1500 RPM/s, matching physical fan inertia.
51+
- **Polling Independence:** The filter math scales based on the time delta
52+
between userspace reads, ensuring a consistent physical curve regardless
53+
of polling frequency.
54+
55+
Suspend and Resume
56+
------------------
57+
58+
The driver utilizes the boottime clock (ktime_get_boottime()) to calculate the
59+
sampling delta. This ensures that time spent in system suspend is accounted
60+
for. If the delta exceeds 5 seconds (e.g., after waking the laptop), the
61+
filter automatically resets to the current hardware value to prevent
62+
reporting "ghost" RPM data from before the sleep state.
63+
64+
Usage
65+
-----
66+
67+
The driver exposes standard hwmon sysfs attributes:
68+
Attribute Description
69+
fanX_input Filtered fan speed in RPM.
70+
71+
72+
Note: If the hardware reports 0 RPM, the filter is bypassed and 0 is reported
73+
immediately to ensure the user knows the fan has stopped.
74+
75+
76+
====================================================================================================
77+
LENOVO FAN CONTROLLER: MASTER REFERENCE DATABASE (2026)
78+
====================================================================================================
79+
80+
MODEL (DMI PN) | FAMILY / SERIES | EC OFFSET | FULL ACPI OBJECT PATH | WIDTH | MULTiplier
81+
----------------------------------------------------------------------------------------------------
82+
82N7 | Yoga 14cACN | 0x06 | \_SB.PCI0.LPC0.EC0.FANS | 8-bit | 100
83+
80V2 / 81C3 | Yoga 710/720 | 0x06 | \_SB.PCI0.LPC0.EC0.FAN0 | 8-bit | 100
84+
83E2 / 83DN | Yoga Pro 7/9 | 0xFE | \_SB.PCI0.LPC0.EC0.FANS | 8-bit | 100
85+
82A2 / 82A3 | Yoga Slim 7 | 0x06 | \_SB.PCI0.LPC0.EC0.FANS | 8-bit | 100
86+
81YM / 82FG | IdeaPad 5 | 0x06 | \_SB.PCI0.LPC0.EC0.FAN0 | 8-bit | 100
87+
82JW / 82JU | Legion 5 (AMD) | 0xFE/0xFF | \_SB.PCI0.LPC0.EC0.FANS (Fan1) | 16-bit | 1
88+
82JW / 82JU | Legion 5 (AMD) | 0xFE/0xFF | \_SB.PCI0.LPC0.EC0.FA2S (Fan2) | 16-bit | 1
89+
82WQ | Legion 7i (Int) | 0xFE/0xFF | \_SB.PCI0.LPC0.EC0.FANS (Fan1) | 16-bit | 1
90+
82WQ | Legion 7i (Int) | 0xFE/0xFF | \_SB.PCI0.LPC0.EC0.FA2S (Fan2) | 16-bit | 1
91+
82XV / 83DV | LOQ 15/16 | 0xFE/0xFF | \_SB.PCI0.LPC0.EC0.FANS /FA2S | 16-bit | 1
92+
83AK | ThinkBook G6 | 0x06 | \_SB.PCI0.LPC0.EC0.FAN0 | 8-bit | 100
93+
81X1 | Flex 5 | 0x06 | \_SB.PCI0.LPC0.EC0.FAN0 | 8-bit | 100
94+
*Legacy* | Pre-2020 Models | 0x06 | \_SB.PCI0.LPC.EC.FAN0 | 8-bit | 100
95+
----------------------------------------------------------------------------------------------------
96+
97+
METHODOLOGY & IDENTIFICATION:
98+
99+
1. DSDT ANALYSIS (THE PATH):
100+
BIOS ACPI tables were analyzed using 'iasl' and cross-referenced with
101+
public dumps. Internal labels (FANS, FAN0, FA2S) are mapped to
102+
EmbeddedControl OperationRegion offsets.
103+
104+
2. EC MEMORY MAPPING (THE OFFSET):
105+
Validated by matching NBFC (NoteBook FanControl) XML logic with DSDT Field
106+
definitions found in BIOS firmware.
107+
108+
3. DATA-WIDTH ANALYSIS (THE MULTIPLIER):
109+
- 8-bit (Multiplier 100): Standard for Yoga/IdeaPad. Raw values (0-255).
110+
- 16-bit (Multiplier 1): Standard for Legion/LOQ. Two registers (0xFE/0xFF).
111+
112+
113+
References
114+
----------
115+
116+
1. **ACPI Specification (Field Objects):** Documentation on how 8-bit vs 16-bit
117+
fields are accessed in OperationRegions.
118+
https://uefi.org/specs/ACPI/6.5/05_ACPI_Software_Programming_Model.html#field-objects
119+
120+
2. **NBFC Projects:** Community-driven reverse engineering
121+
of Lenovo Legion/LOQ EC memory maps (16-bit raw registers).
122+
https://github.com/hirschmann/nbfc/tree/master/Configs
123+
124+
3. **Linux Kernel Timekeeping API:** Documentation for ktime_get_boottime() and
125+
handling deltas across suspend states.
126+
https://www.kernel.org/doc/html/latest/core-api/timekeeping.html
127+
128+
4. **Lenovo IdeaPad Laptop Driver:** Reference for DMI-based hardware
129+
feature gating in Lenovo laptops.
130+
https://github.com/torvalds/linux/blob/master/drivers/platform/x86/ideapad-laptop.c

MAINTAINERS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12373,6 +12373,14 @@ W: https://linuxtv.org
1237312373
Q: http://patchwork.linuxtv.org/project/linux-media/list/
1237412374
F: drivers/media/usb/dvb-usb-v2/lmedm04*
1237512375

12376+
LENOVO YOGA FAN DRIVER
12377+
M: Sergio Melas <sergiomelas@gmail.com>
12378+
L: linux-hwmon@vger.kernel.org
12379+
S: Maintained
12380+
W: https://github.com/sergiomelas
12381+
F: Documentation/hwmon/yogafan.rst
12382+
F: drivers/hwmon/yogafan.c
12383+
1237612384
LOADPIN SECURITY MODULE
1237712385
M: Kees Cook <keescook@chromium.org>
1237812386
S: Supported

drivers/hwmon/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,6 +2408,18 @@ config SENSORS_XGENE
24082408
If you say yes here you get support for the temperature
24092409
and power sensors for APM X-Gene SoC.
24102410

2411+
config SENSORS_YOGAFAN
2412+
tristate "Lenovo Yoga Fan Hardware Monitoring"
2413+
depends on ACPI && HWMON && DMI
2414+
help
2415+
If you say yes here you get support for fan speed monitoring
2416+
on Lenovo Yoga, Legion, IdeaPad, Slim and LOQ laptops.
2417+
The driver interfaces with the Embedded Controller via ACPI
2418+
and uses a Rate-Limited Lag filter to smooth RPM readings.
2419+
2420+
This driver can also be built as a module. If so, the module
2421+
will be called yogafan.
2422+
24112423
config SENSORS_INTEL_M10_BMC_HWMON
24122424
tristate "Intel MAX10 BMC Hardware Monitoring"
24132425
depends on MFD_INTEL_M10_BMC_CORE

drivers/hwmon/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ obj-$(CONFIG_SENSORS_W83L786NG) += w83l786ng.o
224224
obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o
225225
obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
226226
obj-$(CONFIG_SENSORS_XGENE) += xgene-hwmon.o
227+
obj-$(CONFIG_SENSORS_YOGAFAN) += yogafan.o
227228
obj-$(CONFIG_SENSORS_PVT) += sw64_pvt.o
228229

229230
obj-$(CONFIG_SENSORS_OCC) += occ/

0 commit comments

Comments
 (0)