Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert kernel hwmon interface to use PWM (0-255) intsead of RPM v2 #268

Merged
merged 12 commits into from
Oct 19, 2024

Conversation

MrDuartePT
Copy link
Collaborator

@MrDuartePT MrDuartePT commented Oct 13, 2024

This is the second version from #261

The debug messages will be removed later!

@johnfanv2 johnfanv2 marked this pull request as ready for review October 19, 2024 18:02
@johnfanv2
Copy link
Owner

johnfanv2 commented Oct 19, 2024

@MrDuartePT Have you encountered any errors in the meantime when using this version? Otherwise, please merge it.

@johnfanv2 johnfanv2 merged commit b7da713 into main Oct 19, 2024
7 checks passed
@kepten
Copy link

kepten commented Jan 12, 2025

@MrDuartePT @johnfanv2 This PR broke fan speed reading/writing on Legion 7 (not slim) 2022 (16ARHA7). (It is broken in current main too).
This is the latest commit (the last merge commit before that PR) which works:

Current fan curve in hardware:
rpm1|rpm2|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp
0	 0	 2	 2	 0	 127	 0	 127	 0	 37
1600	 1600	 2	 2	 127	 127	 127	 127	 33	 41
1700	 1600	 2	 2	 127	 127	 127	 127	 38	 46
1900	 1800	 2	 2	 127	 127	 127	 127	 41	 127

Working dmesg output:

(...)
[Tue Jan 14 14:43:33 2025] legion PNP0C09:00: Read identifying information: DMI_SYS_VENDOR: LENOVO; DMI_PRODUCT_NAME: 82UH; DMI_BIOS_VERSION:K9CN46WW
[Tue Jan 14 14:43:33 2025] legion_laptop: Read identifying information: DMI_SYS_VENDOR: LENOVO; DMI_PRODUCT_NAME: 82UH; DMI_BIOS_VERSION:K9CN46WW
[Tue Jan 14 14:43:33 2025] legion PNP0C09:00: is_denied: 0; is_allowed: 1; do_load_by_list: 1; do_load: 1
[Tue Jan 14 14:43:33 2025] legion PNP0C09:00: Using configuration for system: K9CN
[Tue Jan 14 14:43:33 2025] legion PNP0C09:00: ACPI CFG: 2081289482
[Tue Jan 14 14:43:33 2025] legion_laptop: Creating RAM access to embedded controller
[Tue Jan 14 14:43:33 2025] legion_laptop: Successfully mapped embedded controller: 0xfe00d400 (in RAM)/0x0 (in EC) to virtual 0x00000000d8e6d151
[Tue Jan 14 14:43:33 2025] legion PNP0C09:00: Read embedded controller ID 0x5507
[Tue Jan 14 14:43:33 2025] legion PNP0C09:00: Skipped checking embedded controller id
[Tue Jan 14 14:43:33 2025] legion PNP0C09:00: Creating debugfs interface
[Tue Jan 14 14:43:33 2025] legion_laptop: Creating sysfs interface
[Tue Jan 14 14:43:33 2025] legion_laptop: Creating hwmon interface
[Tue Jan 14 14:43:33 2025] legion_laptop: Creating platform profile support
[Tue Jan 14 14:43:33 2025] legion_laptop: Init WMI driver support
[Tue Jan 14 14:43:33 2025] legion_wmi 887B54E3-DDDC-4B2C-8B88-68A26A8835D0: Register after probing for WMI.
[Tue Jan 14 14:43:33 2025] legion_wmi BFD42481-AEE3-4501-A107-AFB68425C5F8: Register after probing for WMI.
[Tue Jan 14 14:43:33 2025] legion_wmi BFD42481-AEE3-4502-A107-AFB68425C5F8: Register after probing for WMI.
[Tue Jan 14 14:43:33 2025] legion_wmi D062906B-12D4-4510-999D-4831EE80E985: Register after probing for WMI.
[Tue Jan 14 14:43:33 2025] legion_wmi BC72A435-E8C1-4275-B3E2-D8B8074ABA59: Register after probing for WMI.
[Tue Jan 14 14:43:33 2025] legion_wmi 10AFC6D9-EA8B-4590-A2E7-1CD3C84BB4B1: Register after probing for WMI.
[Tue Jan 14 14:43:33 2025] legion_wmi D320289E-8FEA-41E0-86F9-611D83151B5F: Register after probing for WMI.
[Tue Jan 14 14:43:33 2025] legion_wmi 8FC0DE0C-B4E4-43FD-B0F3-8871711C1294: Register after probing for WMI.
[Tue Jan 14 14:43:33 2025] legion_laptop: Init keyboard backlight LED driver
[Tue Jan 14 14:43:33 2025] legion_laptop: Init Y-Logo LED driver
[Tue Jan 14 14:43:33 2025] legion_laptop: Init IO-Port LED driver
[Tue Jan 14 14:43:33 2025] legion_laptop: Error WMI call for reading brightness: expected a value between 1 and 2, but got 0
[Tue Jan 14 14:43:33 2025] legion_laptop: Error reading brightness for light: 5
[Tue Jan 14 14:43:33 2025] legion PNP0C09:00: Failed to init IO-Port LED driver. Skipping ...
[Tue Jan 14 14:43:33 2025] legion PNP0C09:00: legion_laptop loaded for this device
bash -c "./issue-warning.sh"
(...)

Dmesg with this commit:

git checkout b7da713ca3ada0c34e24b27409365105e45aae6d
make && sudo make reloadmodule

(...)
[Tue Jan 14 14:50:40 2025] legion_laptop: Unmapping embedded controller memory at 0xfe00d400 (in RAM)/0x0 (in EC) at virtual 0x00000000d8e6d151
[Tue Jan 14 14:50:40 2025] legion_laptop: Unloading legion shared
[Tue Jan 14 14:50:40 2025] legion_laptop: Unloading legion shared done
[Tue Jan 14 14:50:40 2025] legion_laptop: Legion platform unloaded
[Tue Jan 14 14:50:40 2025] legion_laptop: legion_laptop exit
[Tue Jan 14 14:50:40 2025] legion_laptop: Loading legion_laptop
[Tue Jan 14 14:50:40 2025] legion PNP0C09:00: legion_laptop platform driver probing
[Tue Jan 14 14:50:40 2025] legion PNP0C09:00: Read identifying information: DMI_SYS_VENDOR: LENOVO; DMI_PRODUCT_NAME: 82UH; DMI_BIOS_VERSION:K9CN46WW
[Tue Jan 14 14:50:40 2025] legion_laptop: Read identifying information: DMI_SYS_VENDOR: LENOVO; DMI_PRODUCT_NAME: 82UH; DMI_BIOS_VERSION:K9CN46WW
[Tue Jan 14 14:50:40 2025] legion PNP0C09:00: is_denied: 0; is_allowed: 1; do_load_by_list: 1; do_load: 1
[Tue Jan 14 14:50:40 2025] legion PNP0C09:00: Using configuration for system: K9CN
[Tue Jan 14 14:50:40 2025] legion PNP0C09:00: ACPI CFG: 2081289482
[Tue Jan 14 14:50:40 2025] legion_laptop: Creating RAM access to embedded controller
[Tue Jan 14 14:50:40 2025] legion_laptop: Successfully mapped embedded controller: 0xfe00d400 (in RAM)/0x0 (in EC) to virtual 0x00000000d8e6d151
[Tue Jan 14 14:50:40 2025] legion PNP0C09:00: Read embedded controller ID 0x5507
[Tue Jan 14 14:50:40 2025] legion PNP0C09:00: Skipped checking embedded controller id
[Tue Jan 14 14:50:40 2025] legion PNP0C09:00: Creating debugfs interface
[Tue Jan 14 14:50:40 2025] legion_laptop: Creating sysfs interface
[Tue Jan 14 14:50:40 2025] legion_laptop: Creating hwmon interface
[Tue Jan 14 14:50:40 2025] legion_laptop: Creating platform profile support
[Tue Jan 14 14:50:40 2025] legion_laptop: Init WMI driver support
[Tue Jan 14 14:50:40 2025] legion_wmi 887B54E3-DDDC-4B2C-8B88-68A26A8835D0: Register after probing for WMI.
[Tue Jan 14 14:50:40 2025] legion_wmi BFD42481-AEE3-4501-A107-AFB68425C5F8: Register after probing for WMI.
[Tue Jan 14 14:50:40 2025] legion_wmi BFD42481-AEE3-4502-A107-AFB68425C5F8: Register after probing for WMI.
[Tue Jan 14 14:50:40 2025] legion_wmi D062906B-12D4-4510-999D-4831EE80E985: Register after probing for WMI.
[Tue Jan 14 14:50:40 2025] legion_wmi BC72A435-E8C1-4275-B3E2-D8B8074ABA59: Register after probing for WMI.
[Tue Jan 14 14:50:40 2025] legion_wmi 10AFC6D9-EA8B-4590-A2E7-1CD3C84BB4B1: Register after probing for WMI.
[Tue Jan 14 14:50:40 2025] legion_wmi D320289E-8FEA-41E0-86F9-611D83151B5F: Register after probing for WMI.
[Tue Jan 14 14:50:40 2025] legion_wmi 8FC0DE0C-B4E4-43FD-B0F3-8871711C1294: Register after probing for WMI.
[Tue Jan 14 14:50:40 2025] legion_laptop: Init keyboard backlight LED driver
[Tue Jan 14 14:50:40 2025] legion_laptop: Init Y-Logo LED driver
[Tue Jan 14 14:50:40 2025] legion_laptop: Init IO-Port LED driver
[Tue Jan 14 14:50:40 2025] legion_laptop: Error WMI call for reading brightness: expected a value between 1 and 2, but got 0
[Tue Jan 14 14:50:40 2025] legion_laptop: Error reading brightness for light: 5
[Tue Jan 14 14:50:40 2025] legion PNP0C09:00: Failed to init IO-Port LED driver. Skipping ...
[Tue Jan 14 14:50:40 2025] legion PNP0C09:00: legion_laptop loaded for this device
bash -c "./issue-warning.sh"
  If you have a 2022 or 2023 model, please help testing the new features 'here' 
  If you have a light on the lid (Y-logo) or at the IO-ports (all Legion 7 models), please help test controlling it 'here' 
  Please give a star on github to support. my goal is to merge the driver into the main Linux kernel, so no recompilation would be required after a Linux update: 'here'
sudo cat /sys/kernel/debug/legion/fancurve
EC Chip ID: 5507
EC Chip Version: 2a4
legion_laptop features: fancurve powermode platformprofile platformprofilenotify minifancurve fancurve_pmw_speed fancurve_rpm_speed
legion_laptop ec_readonly: 0
ACPI CFG error: 0
ACPI CFG: 2081289482
temperature access method: 1
CPU temperature error: 0
CPU temperature: 41
CPU temperature EC error: 0
CPU temperature EC: 41
CPU temperature ACPI error: 0
CPU temperature ACPI: 41
CPU temperature WMI error: 0
CPU temperature WMI: 0
CPU temperature WMI2 error: 0
CPU temperature WMI2: 41
CPU temperature WMI3 error: 0
CPU temperature WMI3: 0
GPU temperature error: 0
GPU temperature: 0
GPU temperature EC error: 0
GPU temperature EC: 0
GPU temperature ACPI error: 0
GPU temperature ACPI: 0
GPU temperature WMI error: 0
GPU temperature WMI: 0
GPU temperature WMI2 error: 0
GPU temperature WMI2: 0
GPU temperature WMI3 error: 0
GPU temperature WMI3: 0
fan speed access method: 1
1 fanspeed error: 0
1 fanspeed: 1659
1 fanspeed EC error: 0
1 fanspeed EC: 1659
1 fanspeed ACPI error: 0
1 fanspeed ACPI: 1600
1 fanspeed WMI error: 0
1 fanspeed WMI: 0
1 fanspeed WMI2 error: 0
1 fanspeed WMI2: 1600
1 fanspeed WMI3 error: 0
1 fanspeed WMI3: 0
2 fanspeed error: 0
2 fanspeed: 1666
2 fanspeed EC error: 0
2 fanspeed EC: 1666
2 fanspeed ACPI error: 0
2 fanspeed ACPI: 1600
2 fanspeed WMI error: 0
2 fanspeed WMI: 0
2 fanspeed WMI2 error: 0
2 fanspeed WMI2: 1600
2 fanspeed WMI3 error: 0
2 fanspeed WMI3: 0
powermode access method: 3
powermode error: 0
powermode: 1
powermode EC error: 0
powermode EC: 2
powermode ACPI error: -5
powermode ACPI: 0
powermode WMI error: 0
powermode WMI: 1
has custom powermode: 1
ACPI rapidcharge error: 0
ACPI rapidcharge: 1
WMI backlight 2 state: 0
WMI backlight 3 state: 0
WMI light IO port: 0
WMI light Y logo/lid: 0
EC minifancurve feature enabled: 1
EC minifancurve on cool: true
EC lockfancontroller error: 0
EC lockfancontroller: false
fanfullspeed error: 0
fanfullspeed: 0
fanfullspeed EC error: 0
fanfullspeed EC: 0
Max speed for fancurve: 10000
Current fan curve in hardware:
Fan curve current point id: 1
Fan curve points size: 4
u(speed_of_unit)|speed1[u]|speed2[u]|speed1[pwm]|speed2[pwm]|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp
3	 0	 0	 0	 0	 2	 2	 0	 127	 0	 127	 0	 37
3	 16	 16	 40	 40	 2	 2	 127	 127	 127	 127	 33	 41
3	 17	 16	 43	 43	 2	 2	 127	 127	 127	 127	 38	 46
3	 19	 18	 48	 48	 2	 2	 127	 127	 127	 127	 41	 127
=====================
Current fan curve in hardware (WMI; might be empty)
Fan curve current point id: 0
Fan curve points size: 0
u(speed_of_unit)|speed1[u]|speed2[u]|speed1[pwm]|speed2[pwm]|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp
=====================

When trying to set the speed, it gets set to something different, I guess it's bad pwm/rpm conversion:

sudo echo 1500 > /sys/module/legion_laptop/drivers/platform\:legion/PNP0C09\:00/hwmon/hwmon*/pwm1_auto_point2_pwm 

sudo cat /sys/kernel/debug/legion/fancurve
Fan curve points size: 4
Current fan curve in hardware:
Fan curve current point id: 1
Fan curve points size: 4
u(speed_of_unit)|speed1[u]|speed2[u]|speed1[pwm]|speed2[pwm]|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp
3	 0	 0	 0	 0	 2	 2	 0	 127	 0	 127	 0	 37
3	 39	 16	 99	 99	 2	 2	 127	 127	 127	 127	 33	 41
3	 17	 16	 43	 43	 2	 2	 127	 127	 127	 127	 38	 46
3	 19	 18	 48	 48	 2	 2	 127	 127	 127	 127	 41	 127

I'm happy to help testing/debugging the fix/issue, I'm also on the Legion Discord channel.

@MrDuartePT
Copy link
Collaborator Author

MrDuartePT commented Jan 12, 2025

@kepten Nothing is broken if you see #268 the kernel driver now uses pwm (in necessary for the driver to be upstream) if you want to set the fancurve using cli create a profile and use legion-cli (the userspace tool convert rpm to pwm) or just use the gui

@kepten
Copy link

kepten commented Jan 13, 2025

@MrDuartePT Hmm, I tried to use the GUI too but it didn't work, so I tried to use the CLI according to the README which instructed me to use such echo 1600 > /sys/XXX commands. Is the README outdated?
This is what the GUI shows for me for the current main commit:
image

The temperatures are not read correctly. The fan speeds are close to the default (1600, 1700, ...) values but when I try to change them they are overwritten to something different (e.g 1764.71 instead of 1800). And because the temps are wrong, I couldn't make the fans change their speed according to what I provided. Any idea what's going on?

For the commit before this PR, it shows the same values as in the CLI and I can succcessfully change them.

@MrDuartePT
Copy link
Collaborator Author

MrDuartePT commented Jan 13, 2025

Yes the readme is outdated for 1600 rpm you should send 40, intead of 40.8 since pwm only accept integers.

The difference you see in the values is because of the rounding of the pwm value and conversion again to rpm, by default the python rounds off to the nearest lower number.

Also looking at the debug output after and before the pwm PR you only have 3 fan curve points, so the ec_registers are not correct for you model they need to be change. So even this PR didn't exist the fan curve control for you model is still broken.

@kepten
Copy link

kepten commented Jan 13, 2025

@MrDuartePT I got it, thanks.
How can I debug/figure out the correct ec_registers for my model?
I thought it was supported because I found this PR: #23

@MrDuartePT
Copy link
Collaborator Author

MrDuartePT commented Jan 17, 2025

@MrDuartePT I got it, thanks.

How can I debug/figure out the correct ec_registers for my model?

I thought it was supported because I found this PR: #23

I think a hexdump is required. Post a hexdump with the fancurve lock and unlock in performance mode (I look again at the issue and when the fancurve is locket the 10 values appear)

Also see if in custom mode (purple color) you can see the 10 fancurve values with the fancurve unlock.

Also check if you have minifancurve disable

@kepten
Copy link

kepten commented Jan 20, 2025

@MrDuartePT
There are 10 values in custom mode (purple color) when I read the values from HW (unlocked, minifancurve enabled):
image
It's the same if I enable locking (nonetheless if minifancurve is enabled or disabled):
image

There are no values when unlocked and minifancurve is disabled (in custom mode):
image

Now in performance mode (red color):

Unlocked and minifancurve disabled (10 values but I cannot set them, they are defaulting after write to the default value):
image

EC memory hexdump

cat /sys/kernel/debug/legion/ecmemory | hexdump -C
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 2a 20 00  |.............* .|
00000010  00 00 80 00 05 00 64 05  01 01 06 00 00 00 00 00  |......d.........|
00000020  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 01 00  |................|
00000040  00 00 00 00 50 01 00 00  00 00 00 00 2d 73 00 00  |....P.......-s..|
00000050  00 00 00 00 00 00 c0 e1  00 07 00 1b 63 00 00 00  |............c...|
00000060  00 80 02 03 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000080  00 00 00 00 08 00 00 00  e0 00 40 00 81 00 00 53  |[email protected]|
00000090  4d 50 00 32 30 32 31 00  4c 32 31 4d 34 50 43 35  |MP.2021.L21M4PC5|
000000a0  00 18 00 8e 00 00 00 61  64 00 00 00 64 25 00 00  |.......ad...d%..|
000000b0  32 2a 26 29 00 00 00 00  02 11 00 00 00 00 01 00  |2*&)............|
000000c0  70 00 83 28 e7 07 0b 45  a0 3c 06 27 83 28 64 00  |p..(...E.<.'.(d.|
000000d0  00 00 00 00 00 00 00 1e  00 00 00 00 00 00 00 00  |................|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 06 00  |................|
000000f0  03 00 00 00 b2 54 00 00  00 00 00 00 00 00 00 00  |.....T..........|
00000100  82 00 00 04 00 00 05 05  13 32 13 13 31 32 32 32  |.........2..1222|
00000110  00 00 ff ff 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000120  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000130  00 02 2e 2a 03 0c a0 00  32 00 2a 00 00 00 00 27  |...*....2.*....'|
00000140  00 11 13 15 17 1a 1d 1f  22 24 28 2c 00 00 00 00  |........"$(,....|
00000150  00 11 13 14 17 19 1c 1e  22 24 28 2c 00 00 00 00  |........"$(,....|
00000160  05 05 05 05 02 02 02 02  02 02 02 02 00 00 00 00  |................|
*
00000180  29 2d 31 36 4b 4e 50 53  55 58 5b 7f 00 00 00 00  |)-16KNPSUX[.....|
00000190  00 23 2a 2e 34 48 4c 4d  51 52 56 59 00 00 00 00  |.#*.4HLMQRVY....|
000001a0  41 41 41 41 41 41 41 4b  4f 51 54 7f 00 00 00 00  |AAAAAAAKOQT.....|
000001b0  00 3c 3c 3c 3c 3c 3c 3c  47 4e 50 52 00 00 00 00  |.<<<<<<<GNPR....|
000001c0  25 29 2e 7f 7f 7f 7f 7f  7f 7f 7f 7f 00 00 00 00  |%)..............|
000001d0  00 21 26 29 7f 7f 7f 7f  7f 7f 7f 7f 00 00 00 00  |.!&)............|
000001e0  00 00 00 00 00 00 32 00  2a 00 00 00 00 00 00 00  |......2.*.......|
000001f0  00 00 07 03 00 00 00 00  00 04 00 00 15 14 18 18  |................|
00000200  15 14 00 00 00 00 00 00  00 00 00 00 00 04 00 00  |................|
00000210  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000220  00 00 00 00 00 00 00 39  00 00 00 00 84 28 00 00  |.......9.....(..|
00000230  00 00 00 03 03 00 02 21  21 00 00 00 00 03 00 01  |.......!!.......|
00000240  00 00 00 00 00 00 00 00  00 00 02 00 00 00 00 00  |................|
00000250  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000260  58 32 58 50 32 35 4a 30  31 5a 37 00 00 00 00 00  |X2XP25J01Z7.....|
00000270  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000002b0  9c 00 70 00 00 00 00 00  00 00 00 00 00 00 00 00  |..p.............|
000002c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000002f0  00 00 00 00 00 00 00 00  00 00 00 00 3d 03 00 00  |............=...|
00000300

Unlocked, minifancurve enabled (only 3 values):
image

EC memory hexdump

cat /sys/kernel/debug/legion/ecmemory | hexdump -C
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 2b 21 00  |.............+!.|
00000010  00 00 80 00 05 00 64 05  01 01 06 00 00 00 00 00  |......d.........|
00000020  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 01 00  |................|
00000040  00 00 00 00 50 01 00 00  00 00 00 00 2d 73 00 00  |....P.......-s..|
00000050  00 00 00 00 00 00 c0 e1  00 07 00 1b 63 00 00 00  |............c...|
00000060  00 80 02 03 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000080  00 00 00 00 08 00 00 00  e0 00 40 00 81 00 00 53  |[email protected]|
00000090  4d 50 00 32 30 32 31 00  4c 32 31 4d 34 50 43 35  |MP.2021.L21M4PC5|
000000a0  00 18 00 8e 00 00 00 61  64 00 00 00 64 25 00 00  |.......ad...d%..|
000000b0  32 2b 27 2a 00 00 00 00  02 11 00 00 00 00 01 00  |2+'*............|
000000c0  70 00 83 28 e7 07 0b 45  a0 3c 06 27 83 28 64 00  |p..(...E.<.'.(d.|
000000d0  00 00 00 00 00 00 00 1e  00 00 00 00 00 00 00 00  |................|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 06 00  |................|
000000f0  03 00 00 00 b2 54 00 00  00 00 00 00 00 00 00 00  |.....T..........|
00000100  82 00 00 04 00 00 05 05  13 32 13 13 31 32 32 32  |.........2..1222|
00000110  00 00 ff ff 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000120  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000130  00 02 2e 2a 03 0c 04 00  32 00 2b 00 00 00 00 27  |...*....2.+....'|
00000140  00 10 12 14 16 19 1c 1e  21 23 28 2c 00 00 00 00  |........!#(,....|
00000150  00 10 12 14 16 18 1b 1d  21 23 28 2c 00 00 00 00  |........!#(,....|
00000160  05 05 05 05 02 02 02 02  02 02 02 02 00 00 00 00  |................|
*
00000180  29 2d 31 36 4b 4e 50 53  55 58 5b 7f 00 00 00 00  |)-16KNPSUX[.....|
00000190  00 23 2a 2e 34 48 4c 4d  51 52 56 59 00 00 00 00  |.#*.4HLMQRVY....|
000001a0  41 41 41 41 41 41 41 4b  4f 51 54 7f 00 00 00 00  |AAAAAAAKOQT.....|
000001b0  00 3c 3c 3c 3c 3c 3c 3c  47 4e 50 52 00 00 00 00  |.<<<<<<<GNPR....|
000001c0  25 29 2e 7f 7f 7f 7f 7f  7f 7f 7f 7f 00 00 00 00  |%)..............|
000001d0  00 21 26 29 7f 7f 7f 7f  7f 7f 7f 7f 00 00 00 00  |.!&)............|
000001e0  00 00 00 00 00 00 32 00  2b 00 00 00 00 00 00 00  |......2.+.......|
000001f0  00 00 07 03 00 00 00 00  00 04 00 00 14 14 30 30  |..............00|
00000200  14 14 00 00 00 00 00 00  00 00 00 00 00 04 00 00  |................|
00000210  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000220  00 00 00 00 00 00 00 39  00 00 00 00 84 28 00 00  |.......9.....(..|
00000230  00 00 00 03 03 00 02 21  21 00 00 00 00 00 00 01  |.......!!.......|
00000240  00 00 00 00 00 00 00 00  00 00 02 00 00 00 00 00  |................|
00000250  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000260  58 32 58 50 32 35 4a 30  31 5a 37 00 00 00 00 00  |X2XP25J01Z7.....|
00000270  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000002b0  9c 00 70 00 00 00 00 00  00 00 00 00 00 00 00 00  |..p.............|
000002c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000002f0  00 00 00 00 00 00 00 00  00 00 00 00 3d 03 00 00  |............=...|
00000300


Locked, minifancurve enabled (only 3 values):
image

EC memory hexdump

cat /sys/kernel/debug/legion/ecmemory | hexdump -C
00000000  00 00 00 00 00 00 11 00  00 00 00 00 00 2b 21 00  |.............+!.|
00000010  00 00 80 00 05 00 64 05  01 01 06 00 00 00 00 00  |......d.........|
00000020  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 01 00  |................|
00000040  00 00 00 00 50 01 00 00  00 00 00 00 2d 73 00 00  |....P.......-s..|
00000050  00 00 00 00 00 00 c0 e1  00 07 00 1b 63 00 00 00  |............c...|
00000060  00 80 02 03 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000080  00 00 00 00 0b 00 00 00  e0 00 40 00 81 00 00 53  |[email protected]|
00000090  4d 50 00 32 30 32 31 00  4c 32 31 4d 34 50 43 35  |MP.2021.L21M4PC5|
000000a0  00 18 00 8e 00 00 00 61  64 00 00 08 64 25 00 00  |.......ad...d%..|
000000b0  33 2a 26 2a 00 00 00 00  02 11 00 00 00 00 01 00  |3*&*............|
000000c0  70 00 83 28 e7 07 0a 45  a0 3c 06 27 83 28 64 00  |p..(...E.<.'.(d.|
000000d0  00 00 00 00 00 00 00 1f  00 00 00 00 00 00 00 00  |................|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 06 00  |................|
000000f0  03 00 00 00 b2 54 00 00  00 00 00 00 00 00 11 00  |.....T..........|
00000100  82 00 00 04 00 00 05 05  13 32 13 13 31 32 32 32  |.........2..1222|
00000110  00 00 ff ff 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000120  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000130  00 01 2e 2a 00 04 04 00  33 00 2a 00 00 00 00 27  |...*....3.*....'|
00000140  00 0f 11 14 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000160  05 05 05 05 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000180  29 2d 31 36 00 00 00 00  00 00 00 00 00 00 00 00  |)-16............|
00000190  00 23 2a 2e 00 00 00 00  00 00 00 00 00 00 00 00  |.#*.............|
000001a0  41 41 41 41 00 00 00 00  00 00 00 00 00 00 00 00  |AAAA............|
000001b0  00 3c 3c 3c 00 00 00 00  00 00 00 00 00 00 00 00  |.<<<............|
000001c0  25 29 2e 7f 00 00 00 00  00 00 00 00 00 00 00 00  |%)..............|
000001d0  00 21 26 29 00 00 00 00  00 00 00 00 00 00 00 00  |.!&)............|
000001e0  01 07 e3 06 11 11 30 00  2a 00 00 00 00 00 00 00  |......0.*.......|
000001f0  00 00 07 03 00 00 00 00  00 04 00 00 11 11 00 00  |................|
00000200  11 11 00 00 00 00 00 00  00 00 00 00 00 04 00 00  |................|
00000210  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000220  00 00 00 00 00 00 00 39  00 00 00 00 84 28 00 00  |.......9.....(..|
00000230  00 00 00 03 00 00 00 21  21 00 00 00 00 00 00 02  |.......!!.......|
00000240  00 00 00 00 00 00 00 00  00 00 02 00 00 00 00 00  |................|
00000250  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000260  58 32 58 50 32 35 4a 30  31 5a 37 00 00 00 00 00  |X2XP25J01Z7.....|
00000270  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000002b0  9c 00 70 00 00 00 00 00  00 00 00 00 00 00 00 00  |..p.............|
000002c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000002f0  00 00 00 00 00 00 00 00  00 00 00 00 3d 03 00 00  |............=...|
00000300

Don't know if it matters but I ran the above commands with the fixed ec_id and base address to match my hw:

diff --git a/kernel_module/legion-laptop.c b/kernel_module/legion-laptop.c
index 227588e..ddbd364 100644
--- a/kernel_module/legion-laptop.c
+++ b/kernel_module/legion-laptop.c
@@ -744,9 +744,9 @@ static const struct model_config model_hacn = {
 
 static const struct model_config model_k9cn = {
        .registers = &ec_register_offsets_v0,
-       .check_embedded_controller_id = false,
-       .embedded_controller_id = 0x8227,
-       .memoryio_physical_ec_start = 0xC400, // or replace 0xC400 by 0x0400  ?
+       .check_embedded_controller_id = true,
+       .embedded_controller_id = 0x5507,
+       .memoryio_physical_ec_start = 0xC400,
        .memoryio_size = 0x300,
        .has_minifancurve = true,
        .has_custom_powermode = true,
@@ -757,7 +757,7 @@ static const struct model_config model_k9cn = {
        .access_method_fancurve = ACCESS_METHOD_EC,
        .access_method_fanfullspeed = ACCESS_METHOD_WMI,
        .acpi_check_dev = true,
-       .ramio_physical_start = 0xFE00D400,
+       .ramio_physical_start = 0xFE0B0400,
        .ramio_size = 0x600
 };

The issue exists without this patch too in current main branch. This patch attempted to fix it and hopefully make the hexdump correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants