hwmon: (yogafan) Add support for Lenovo Yoga/Legion fan monitoring
Subsystems (3)
Sergio Melas
maintainerPATCH v11 1/1 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.
---
v11:
- Mapped ACPI paths directly via DMI quirks to ensure deterministic resolution.
- Implemented 100ms MIN_SAMPLING to prevent excessive EC polling.
- Fixed Documentation/hwmon/yogafan.rst formatting (0-day robot warnings).
- Cleaned up MAINTAINERS entry and Kconfig help description.
- Removed redundant platform_set_drvdata() from probe function.
- Validated with checkpatch.pl --strict (0 errors, 0 warnings, 0 checks).
v9/10:
- Implement ACPI handle resolution during probe for better performance (O(1) read).
- Add MODULE_DEVICE_TABLE(dmi, ...) to enable module autoloading.
- Refine RLLag filter documentation and suspend/resume logic.
- Include comprehensive EC architecture research database (8-bit vs 16-bit).
- Validated efficiency on kernels 6.18, 6.19, and 7.0-rc5: 'perf top' confirms negligible CPU overhead (<0.01%) during active polling.
v8:
- Replaced heuristic multiplier with deterministic DMI Quirk Table.
- Added 'depends on DMI' to Kconfig.
- Verified FOPTD model (1000ms TAU / 1500 RPM/s slew) against hardware traces.
- Increased filter precision to 12-bit fixed-point.
v7:
- Fixed Kconfig: Removed non-existent 'select MATH64'.
- Fixed unused macro: Utilized RPM_FLOOR_LIMIT to implement an immediate 0-RPM bypass in the filter.
- Clarification: Previous "unified structure" comment meant that all 6 files (driver, docs, metadata) are now in this single atomic patch.
v6:
- Unified patch structure (6 files changed).
- Verified FOPTD (First-Order Plus Time Delay) model against hardware traces (Yoga 14c) to ensure physical accuracy of the 1000ms time constant.
- Fixed a rounding stall: added a +/- 1 RPM floor to the step calculation 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 = 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 | 130 +++++++++++++++ MAINTAINERS | 8 + drivers/hwmon/Kconfig | 13 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/yogafan.c | 275 ++++++++++++++++++++++++++++++++ 6 files changed, 428 insertions(+) create mode 100644 Documentation/hwmon/yogafan.rst create mode 100644 drivers/hwmon/yogafan.c
Documentation/hwmon/index.rst +1 -0
@@ -282,4 +282,5 @@ Hardware Monitoring Kernel Drivers xdp710 xdpe12284 xdpe152c4 + yogafan zl6100
Documentation/hwmon/yogafan.rst new file +130 -0
130 lines not on this page · raw message
MAINTAINERS +8 -0
@@ -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* +LENOVO YOGA FAN DRIVER +M: Sergio Melas <[email protected]> +L: [email protected] +S: Maintained +W: https://github.com/sergiomelas +F: Documentation/hwmon/yogafan.rst +F: drivers/hwmon/yogafan.c + LOADPIN SECURITY MODULE M: Kees Cook <[email protected]> S: Supported
drivers/hwmon/Kconfig +13 -0
@@ -2653,6 +2653,19 @@ config SENSORS_XGENE If you say yes here you get support for the temperature and power sensors for APM X-Gene SoC. +config SENSORS_YOGAFAN + tristate "Lenovo Yoga Fan Hardware Monitoring" + depends on ACPI && HWMON && DMI + help + If you say yes here you get support for fan speed monitoring + on Lenovo Yoga, Legion, IdeaPad, Slim and LOQ laptops. + The driver interfaces with the Embedded Controller via ACPI + and uses a Rate-Limited Lag filter to smooth RPM readings. + + This driver can also be built as a module. If so, the module + will be called yogafan. + + config SENSORS_INTEL_M10_BMC_HWMON tristate "Intel MAX10 BMC Hardware Monitoring" depends on MFD_INTEL_M10_BMC_CORE
drivers/hwmon/Makefile +1 -0
@@ -245,6 +245,7 @@ obj-$(CONFIG_SENSORS_W83L786NG) += w83l786ng.o obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o obj-$(CONFIG_SENSORS_XGENE) += xgene-hwmon.o +obj-$(CONFIG_SENSORS_YOGAFAN) += yogafan.o obj-$(CONFIG_SENSORS_OCC) += occ/ obj-$(CONFIG_SENSORS_PECI) += peci/
drivers/hwmon/yogafan.c new file +275 -0
275 lines not on this page · raw message
Signature · 1 line
2.53.0
Quoted 7 lines · Sergio Melas
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.
Quoted 5 lines
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 <[email protected]>
Sashiko is happy, and I don't find anything to complain about anymore either, so...
Applied.
Thanks,
Guenter
Sergio Melas
maintainerQuoted 8 lines · Guenter Roeck
Sashiko is happy, and I don't find anything to complain about anymore either, so...
Applied.
Thanks,
Guenter
Hi Guenter,
That is great news! Thank you very much for your patience and for the detailed reviews through all these iterations. It was a great learning experience.
After 30 years of using Linux, seeing my own driver accepted into the mainline kernel is truly a dream come true.
Best regards,
Sergio