New Lenovo Legion Fan, Temperature, Power Mode Driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear Kernel devs, Mr. Hans de Goede, Mr. Ike Panhc,

I am currently working on a driver for fan control, fan speed, temperature sensors, and power mode (platform profile) for Lenovo Legion Laptops. Switching iGPU/dGPU could also be possible. It is a port of the closed and open tools in Windows LenovoLegionToolkit, Vantage, LegionFanControl. I am testing it on different laptops with the help of a forum/chat and its working quite good.

There is a README (https://github.com/johnfanv2/LenovoLegionLinux) and code (https://github.com/johnfanv2/LenovoLegionLinux/blob/main/kernel_module/legion-laptop.c).

I would be interested to get your opinion.

Questions

Should this extend ideapad_laptop.c or a new file?
    - pro:
        - both access parts of the same hardware
    - con:
        - both files are already quite large
        - it only works on Lenovo Legion laptops that have this 
          custom control firmware in the embedded controller (EC)
        - there is almost no reuse of code

Which method do you prefer writing to EC memory for older models? With ioremap or outb? 
    - To use ioremap one needs to get the start address. It is
      different on Intel vs AMD. It is the same as a OperationRegion
      in the ACPI tables, e.g. "OperationRegion (ERAX, SystemMemory,  
      0xFE00D400, 0xFF)". However, I have found no kernel functions  
      to get the address (here 0xFE00D400) of a  OperationRegion.  
      One could also hardcode it for each model/firmware.
    - alternative (which I am currently using) is sending commands    
      to IO ports 0x4E/0x4F (Super IO controller). 

Background

The laptops come with an embedded controller (EC) from ITE. These usually come with a 3 point fan curve in ROM, but also can be flashed with a small additional custom program. Lenovo implemented implemented a 10 point fan curve. The program is also shipped with each EFI update.

The fan curve can be edited by writing to some memory locations in the EC. These locations are

The driver works by:
- directly writing/reading embedded controller memory
    - older models (2020-2021): there are two possibilities
        - the EC memory is already memory mapped, so one can 
          use ioremap
        - one can use outb/inb and write sequenc of commands to 
          port 0x43, 0x4F (super IO ports)
        - ideapad_laptop.c writes to some parts of EC memory 
          with ACPI methods VPCR, VPCW. However, these do not seem  
          to work in the memory region with the fan curve.
    - newer models (2022): these provide ACPI/WMI methods  
      setFanCurve/getFanCurve to write to these regions. However, I  
      have implemented that and have no models for testing

The driver works for the models 2020-2022. The code layout is heavily inspired by the ideapad_laptop driver.

Best regards,

John Martens





[Index of Archives]     [Linux Kernel Development]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux