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

Tool for power mode and custom fan control #8

Open
johnfanv2 opened this issue Jan 30, 2023 · 32 comments
Open

Tool for power mode and custom fan control #8

johnfanv2 opened this issue Jan 30, 2023 · 32 comments

Comments

@johnfanv2
Copy link

I created a tool for custom fan curves for Lenovo Legion 5, Legion 7 etc. It is called LenovoLegionLinux and is on github https://github.com/johnfanv2/LenovoLegionLinux

I guess it also works for the 15ARH05 series because it works for the 15ARH05A series. If you want, you could try it according to the README and let me now if it works or if something has to be fixed.

@rozwell
Copy link

rozwell commented Jan 30, 2023

Awesome!
I was recently looking for such tool for my Legion 5-17ACH6 which has horrible high pitched fan noise at certain RPM and it drives me crazy.
I'll test it out this week and see what does or doesn't work.
Thank you!

Edit:
Legion 5-15ACH6, Legion 5P-6ACH6, Legion 5-17ACH6 are using the same BIOS so they should all be compatible.

@antony-jr
Copy link
Owner

I would highly recommend you to avoid using Lenovo's name, since it's copyrighted. I have seen DMCA takedowns even from Github for using their name in a open source software name. Hope that helps.

@rozwell
Copy link

rozwell commented Jan 31, 2023

@johnfanv2 Looks like it works fine on my 5-17ACH6. I didn't exactly test every possible option, but it looks like everything is working. Installation went smooth on kernel 6.0.9
It seems that minifancurve was causing me headaches and disabling it made using the laptop 10x better.
Thank you so much!

@johnfanv2
Copy link
Author

johnfanv2 commented Feb 3, 2023

@rozwell Thanks for the test and the information. Yes, mini fancurve is enabled by default in the firmware and you can disable it if you do not want it. Can you tell me your BIOS version sudo dmidecode -t bios.
@antony-jr Thank's a lot for the information. I guess, I will have to rename it.

@pm4rcin
Copy link

pm4rcin commented Mar 6, 2023

@johnfanv2 is is possible to integrate your project to powerprofilesctl in the future? Because for me the output is:

❯ powerprofilesctl list
* balanced:
    Driver:     placeholder

  power-saver:
    Driver:     placeholder

@johnfanv2
Copy link
Author

Hmm. It should work with it. Have you loaded the kernel module? Does the other stuff work? What is the output of sudo dmesg after loading it. What is the output of sudo cat /sys/kernel/debug/legion/fancurve?

@johnfanv2
Copy link
Author

You can check it in the README of the tool it should be

# List all profiles (power-saver = quiet= blue)
powerprofilesctl list

#   performance:
#     Driver:     platform_profile
#     Degraded:   no

#   balanced:
#     Driver:     platform_profile

# * power-saver:
#     Driver:     platform_profile

@pm4rcin If you can give me the requested output I could try to diagnose your problem.

@pm4rcin
Copy link

pm4rcin commented Mar 11, 2023

@johnfanv2 I'm on Arch(btw) with kernel 6.2.2
dmesg:

[27602.816523] legion_laptop 0.1 starts loading
[27602.816526] Read identifying information: DMI_SYS_VENDOR: LENOVO; DMI_PRODUCT_NAME: 82B5; DMI_BIOS_VERSION:EUCN31WW
[27602.816578] legion PNP0C09:00: legion_laptop platform driver 0.1 probing
[27602.816580] Read identifying information: DMI_SYS_VENDOR: LENOVO; DMI_PRODUCT_NAME: 82B5; DMI_BIOS_VERSION:EUCN31WW
[27602.816581] legion PNP0C09:00: is_denied: 0; is_allowed: 1; do_load_by_list: 1; do_load: 1
[27602.816583] legion PNP0C09:00: Using configuration for system: EUCN
[27602.816595] Succeffuly mapped embedded controller: 0xfe00d400 (in RAM)/0xc400 (in EC) to virtual 0x0000000014e8d487
[27602.816652] legion PNP0C09:00: Read embedded controller ID 0x8227
[27602.816653] legion PNP0C09:00: Creating debugfs inteface
[27602.816659] Creating sysfs inteface
[27602.816662] Creating hwmon interface
[27602.816721] Creating platform profile support
[27602.816723] Init WMI driver support
[27602.816741] legion_wmi 887B54E3-DDDC-4B2C-8B88-68A26A8835D0: Register after probing for WMI.
[27602.816756] legion_wmi BFD42481-AEE3-4501-A107-AFB68425C5F8: Register after probing for WMI.
[27602.816764] legion_wmi D062906B-12D4-4510-999D-4831EE80E985: Register after probing for WMI.
[27602.816772] legion_wmi BFD42481-AEE3-4502-A107-AFB68425C5F8: Register after probing for WMI.
[27602.816779] legion_wmi BC72A435-E8C1-4275-B3E2-D8B8074ABA59: Register after probing for WMI.
[27602.816786] legion_wmi 10AFC6D9-EA8B-4590-A2E7-1CD3C84BB4B1: Register after probing for WMI.
[27602.816792] legion_wmi D320289E-8FEA-41E0-86F9-611D83151B5F: Register after probing for WMI.
[27602.816811] legion PNP0C09:00: legion_laptop loaded for this device

fan curve:

❯ sudo cat /sys/kernel/debug/legion/fancurve
EC Chip ID: 8227
EC Chip Version: 2a4
legion_laptop version: 0.1
legion_laptop features: fancurve powermode platformprofile platformprofilenotify minifancurve
legion_laptop ec_readonly: 0
minifancurve feature enabled: 1
minifancurve on cool: true
lock fan controller: false
enable maximumfanspeed: false
enable maximumfanspeed status: 0
fan curve current point id: 0
fan curve points size: 9
Current fan curve in hardware (embedded controller):
rpm1|rpm2|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp
0	0	5	7	0	59	0	54	0	38
1700	1600	5	7	55	59	51	54	35	42
2000	1900	5	7	55	59	51	54	39	127
2100	2100	5	7	55	68	51	54	39	127
2300	2300	5	7	60	77	51	54	39	127
2600	2600	5	7	72	82	51	54	39	127
2900	2900	5	7	78	87	51	58	39	127
3500	3500	5	7	83	89	55	66	39	127
3800	3800	5	7	86	127	63	127	39	127
=====================

@johnfanv2
Copy link
Author

Everthing looks good! The driver creates the files "/sys/firmware/acpi/platform_profile" and "/sys/firmware/acpi/platform_profile_choices". Check if they exists and contain the useful values.

cat /sys/firmware/acpi/platform_profile
# quiet

cat /sys/firmware/acpi/platform_profile_choices 
#quiet balanced performance

If powerprofilesctl list still gives wrong values, maybe you have to configure the power-profiles-daemon somehow to pick up these values.

@pm4rcin
Copy link

pm4rcin commented Mar 12, 2023

So they exist and have useful values like you but when I do echo quiet it changes the value but doesn't change the led color of power button. So I'm not sure if it does anything at all. powerprofilesctl list still gives wrong values.

@pm4rcin
Copy link

pm4rcin commented Apr 2, 2023

@johnfanv2 thanks to your new instructions on RE I have dumped the EC values when I change from various power modes with fn+Q. Tell me if you need something more. These are files from dumping cat /sys/kernel/debug/legion/ecmemory | hexdump -C
start_normal.log
silent_to_start.log
perf_to_silent.log
normal_to_perf.log

@johnfanv2
Copy link
Author

johnfanv2 commented Apr 3, 2023

@pm4rcin sorry, for the later reply. I did not see this thread. I guess everything works for you except this power profiles thing.
Could you try reading/writing directly the powermode?

# display power mode (try switching manually)
cat /sys/module/legion_laptop/drivers/platform\:legion/PNP0C09\:00/powermode

# set a power mode (balanced)
echo 0 > /sys/module/legion_laptop/drivers/platform\:legion/PNP0C09\:00/powermode

@pm4rcin
Copy link

pm4rcin commented Apr 3, 2023

Exactly. Everything but power profiles. I can change the value of powermode with your command but the diode stays the same color. Only fn+Q works.

@johnfanv2
Copy link
Author

Interestingly. I can change the power mode with another adsress in the embedded controller. I will build a version for you withe the change. If you change the power mode with Fn + Q, does the output of the following changes?

# display power mode (try switching manually)
cat /sys/module/legion_laptop/drivers/platform\:legion/PNP0C09\:00/powermode

@pm4rcin
Copy link

pm4rcin commented Apr 5, 2023

If you change the power mode with Fn + Q, does the output of the following changes?

No

@pm4rcin
Copy link

pm4rcin commented Apr 6, 2023

So I've done some more tests and this time restarted power-profiles-daemon. Sorry for So now I have correct output

❯ powerprofilesctl
  performance:
    Driver:     platform_profile
    Degraded:   no

* balanced:
    Driver:     platform_profile

  power-saver:
    Driver:     platform_profile

And also the powermode in sysfs is changing when powerprofilesctl is used. But still fn+Q doesn't change values there nor powerprofilesctl change the LED color.

@johnfanv2
Copy link
Author

@pm4rcin I guess we have to find the memory address for you model for the power mode. Can you verify that the byte at offset 0x1D that I marked with HH in the next line below corresponds to the power mode. Toggle the power mode with Fn + Q and observer the value with cat /sys/kernel/debug/legion/ecmemory | hexdump -C. Does it change when the mode changes? Does it attain the values 02 (quiet=blue), 00 (balanced=white), and 01 (performance=red)?

00000000  00 01 00 00 00 00 00 00  00 00 10 00 00 25 19 00  |.............%..|
00000010  00 00 80 00 06 00 76 00  01 01 06 00 00 02 00 00  |......v.........|
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 HH 00 00

Did you observe any other bytes that attain these values at other offsets?

@pm4rcin
Copy link

pm4rcin commented Apr 7, 2023

So that HH changes exactly as you've said. I have created diff of 3 files with command diff3 new_balanced new_perf new_quiet > new.diff. I can't see that other values changes as in the place you mentioned. Only place the 01, 02 and 00 but in the wrong order is in 20,30c.
Here's the output:

====
1:1,2c
  00000000  00 00 00 00 00 00 00 00  00 00 10 00 00 20 18 00  |............. ..|
  00000010  00 00 80 00 06 00 76 00  01 01 06 00 00 00 00 00  |......v.........|
2:1,2c
  00000000  00 00 00 00 00 00 00 00  00 00 10 00 00 20 18 00  |............. ..|
  00000010  00 00 80 00 06 00 76 00  01 01 06 00 00 01 00 00  |......v.........|
3:1,2c
  00000000  00 00 00 00 00 00 00 00  00 00 10 00 00 21 18 00  |.............!..|
  00000010  00 00 80 00 06 00 76 00  01 01 06 00 00 02 00 00  |......v.........|
====1
1:9c
  00000080  00 00 00 00 08 00 00 00  c0 00 43 00 00 00 00 43  |..........C....C|
2:9c
3:9c
  00000080  00 00 00 00 0b 00 00 00  c0 00 43 00 00 00 00 43  |..........C....C|
====
1:13c
  000000c0  00 00 9a 0c 94 10 cb 3b  28 3c 70 17 ff 14 3c 00  |.......;(<p...<.|
2:13c
  000000c0  00 00 9a 0c 94 10 cd 3b  28 3c 70 17 ff 14 3c 00  |.......;(<p...<.|
3:13c
  000000c0  00 00 9a 0c 94 10 cc 3b  28 3c 70 17 ff 14 3c 00  |.......;(<p...<.|
====
1:17,18c
  00000100  80 00 00 00 00 00 05 05  16 72 13 13 13 72 16 72  |.........r...r.r|
  00000110  00 00 ff ff 00 00 00 00  00 00 3d 3e 41 00 00 00  |..........=>A...|
2:17,18c
  00000100  80 00 00 00 00 00 03 03  16 72 13 13 16 72 16 72  |.........r...r.r|
  00000110  00 00 ff ff 00 00 00 00  00 00 3d 50 3f 00 00 00  |..........=P?...|
3:17,18c
  00000100  80 00 00 00 00 00 04 04  16 72 13 13 16 72 16 72  |.........r...r.r|
  00000110  00 00 ff ff 00 00 00 00  00 00 3d 50 3f 00 00 00  |..........=P?...|
====
1:20,30c
  00000130  01 02 21 00 00 09 04 00  24 24 22 22 00 24 20 18  |..!.....$$"".$ .|
  00000140  00 11 14 15 17 1a 1d 23  26 00 00 00 00 00 00 00  |.......#&.......|
  00000150  00 10 13 15 17 1a 1d 23  26 00 00 00 00 00 00 00  |.......#&.......|
  00000160  05 05 05 05 05 05 05 05  05 00 00 00 00 00 00 00  |................|
  00000170  07 07 07 07 07 07 07 07  07 00 00 00 00 00 00 00  |................|
  00000180  3b 3b 3b 44 4d 52 57 59  7f 00 00 00 00 00 00 00  |;;;DMRWY........|
  00000190  00 37 37 37 3c 48 4e 53  56 00 00 00 00 00 00 00  |.777<HNSV.......|
  000001a0  36 36 36 36 36 36 3a 42  7f 00 00 00 00 00 00 00  |666666:B........|
  000001b0  00 33 33 33 33 33 33 37  3f 00 00 00 00 00 00 00  |.3333337?.......|
  000001c0  26 2a 7f 7f 7f 7f 7f 7f  7f 00 00 00 00 00 00 00  |&*..............|
  000001d0  00 23 27 27 27 27 27 27  27 00 00 00 00 00 00 00  |.#'''''''.......|
2:20,30c
  00000130  02 02 21 00 00 0a 04 00  24 24 22 22 00 24 20 18  |..!.....$$"".$ .|
  00000140  00 11 14 15 17 1a 1d 23  26 2c 00 00 00 00 00 00  |.......#&,......|
  00000150  00 10 13 15 17 1a 1d 23  26 2c 00 00 00 00 00 00  |.......#&,......|
  00000160  02 02 02 02 02 02 02 02  02 02 00 00 00 00 00 00  |................|
  *
  00000180  3b 3b 3b 48 4c 52 57 5c  60 7f 00 00 00 00 00 00  |;;;HLRW\`.......|
  00000190  00 37 37 37 43 49 4c 53  58 5d 00 00 00 00 00 00  |.777CILSX]......|
  000001a0  36 36 36 36 36 36 3a 42  46 7f 00 00 00 00 00 00  |666666:BF.......|
  000001b0  00 33 33 33 33 33 33 37  3f 43 00 00 00 00 00 00  |.3333337?C......|
  000001c0  26 2a 7f 7f 7f 7f 7f 7f  7f 7f 00 00 00 00 00 00  |&*..............|
  000001d0  00 23 27 27 27 27 27 27  27 27 00 00 00 00 00 00  |.#''''''''......|
3:20,30c
  00000130  00 02 21 00 00 09 04 00  24 24 22 22 00 24 21 18  |..!.....$$"".$!.|
  00000140  00 11 14 15 17 1a 1d 23  26 00 00 00 00 00 00 00  |.......#&.......|
  00000150  00 10 13 15 17 1a 1d 23  26 00 00 00 00 00 00 00  |.......#&.......|
  00000160  05 05 05 05 05 05 05 05  05 00 00 00 00 00 00 00  |................|
  00000170  07 07 07 07 07 07 07 07  07 00 00 00 00 00 00 00  |................|
  00000180  7f 7f 7f 7f 7f 7f 7f 7f  7f 00 00 00 00 00 00 00  |................|
  00000190  00 7f 7f 7f 7f 7f 7f 7f  7f 00 00 00 00 00 00 00  |................|
  000001a0  33 33 33 33 37 3c 40 46  7f 00 00 00 00 00 00 00  |33337<@F........|
  000001b0  00 30 30 30 30 34 38 3d  42 00 00 00 00 00 00 00  |.000048=B.......|
  000001c0  26 2a 36 7f 7f 7f 7f 7f  7f 00 00 00 00 00 00 00  |&*6.............|
  000001d0  00 23 27 33 33 33 33 33  33 00 00 00 00 00 00 00  |.#'333333.......|
====3
1:32c
2:32c
  000001f0  cf 03 07 03 00 00 00 00  00 00 00 00 00 00 5f 5f  |..............__|
3:32c
  000001f0  cf 03 07 03 00 00 00 00  00 00 00 00 00 00 55 55  |..............UU|
====1
1:36c
  00000230  03 80 81 82 00 00 00 00  00 00 00 00 00 02 00 00  |................|
2:36c
3:36c
  00000230  03 80 81 82 00 00 00 00  00 00 00 00 00 01 00 00  |................|

@johnfanv2
Copy link
Author

@pm4rcin I created a new version. Please pull the latest code, compile, and reload module. Then report the output of

# report output after next command (reloading module)
sudo make reloadmodule
# report output of after going to performance mode
sudo cat /sys/kernel/debug/legion/fancurve
# report output of next command after going to quiet mode
sudo cat /sys/kernel/debug/legion/fancurve
# report output of next command after going to balanced mode
sudo cat /sys/kernel/debug/legion/fancurve

@pm4rcin
Copy link

pm4rcin commented Apr 7, 2023

LenovoLegionLinux/kernel_module on  main via C v12.2.1-gcc took 5s 
❯ powerprofilesctl set performance

LenovoLegionLinux/kernel_module on  main via C v12.2.1-gcc 
❯ sudo cat /sys/kernel/debug/legion/fancurve
[sudo] hasło użytkownika marcin: 
EC Chip ID: 8227
EC Chip Version: 2a4
legion_laptop features: fancurve powermode platformprofile platformprofilenotify minifancurve
legion_laptop ec_readonly: 0
powermode: 1
minifancurve feature enabled: 1
minifancurve on cool: true
lock fan controller: false
enable maximumfanspeed: false
enable maximumfanspeed status: 0
fan curve current point id: 0
fan curve points size: 9
Current fan curve in hardware (embedded controller):
rpm1|rpm2|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp
0	0	5	7	0	59	0	54	0	38
1700	1600	5	7	55	59	51	54	35	42
2000	1900	5	7	55	59	51	54	39	127
2100	2100	5	7	55	68	51	54	39	127
2300	2300	5	7	60	77	51	54	39	127
2600	2600	5	7	72	82	51	54	39	127
2900	2900	5	7	78	87	51	58	39	127
3500	3500	5	7	83	89	55	66	39	127
3800	3800	5	7	86	127	63	127	39	127
=====================

LenovoLegionLinux/kernel_module on  main via C v12.2.1-gcc 
❯ powerprofilesctl set power-saver

LenovoLegionLinux/kernel_module on  main via C v12.2.1-gcc 
❯ sudo cat /sys/kernel/debug/legion/fancurve
EC Chip ID: 8227
EC Chip Version: 2a4
legion_laptop features: fancurve powermode platformprofile platformprofilenotify minifancurve
legion_laptop ec_readonly: 0
powermode: 2
minifancurve feature enabled: 1
minifancurve on cool: true
lock fan controller: false
enable maximumfanspeed: false
enable maximumfanspeed status: 0
fan curve current point id: 0
fan curve points size: 9
Current fan curve in hardware (embedded controller):
rpm1|rpm2|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp
0	0	5	7	0	59	0	54	0	38
1700	1600	5	7	55	59	51	54	35	42
2000	1900	5	7	55	59	51	54	39	127
2100	2100	5	7	55	68	51	54	39	127
2300	2300	5	7	60	77	51	54	39	127
2600	2600	5	7	72	82	51	54	39	127
2900	2900	5	7	78	87	51	58	39	127
3500	3500	5	7	83	89	55	66	39	127
3800	3800	5	7	86	127	63	127	39	127
=====================

LenovoLegionLinux/kernel_module on  main via C v12.2.1-gcc 
❯ powerprofilesctl set balanced

LenovoLegionLinux/kernel_module on  main via C v12.2.1-gcc 
❯ sudo cat /sys/kernel/debug/legion/fancurve
EC Chip ID: 8227
EC Chip Version: 2a4
legion_laptop features: fancurve powermode platformprofile platformprofilenotify minifancurve
legion_laptop ec_readonly: 0
powermode: 0
minifancurve feature enabled: 1
minifancurve on cool: true
lock fan controller: false
enable maximumfanspeed: false
enable maximumfanspeed status: 0
fan curve current point id: 0
fan curve points size: 9
Current fan curve in hardware (embedded controller):
rpm1|rpm2|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp
0	0	5	7	0	59	0	54	0	38
1700	1600	5	7	55	59	51	54	35	42
2000	1900	5	7	55	59	51	54	39	127
2100	2100	5	7	55	68	51	54	39	127
2300	2300	5	7	60	77	51	54	39	127
2600	2600	5	7	72	82	51	54	39	127
2900	2900	5	7	78	87	51	58	39	127
3500	3500	5	7	83	89	55	66	39	127
3800	3800	5	7	86	127	63	127	39	127
=====================

@johnfanv2
Copy link
Author

Hmm. Can you switch powermode with Fn + Q instead of powerprofilesctl?

@pm4rcin
Copy link

pm4rcin commented Apr 7, 2023

EDIT: Oh looks like powerprofilesctl switches diode but not power mode.
Here you go:

❯ sudo cat /sys/kernel/debug/legion/fancurve
[sudo] hasło użytkownika marcin: 
EC Chip ID: 8227
EC Chip Version: 2a4
legion_laptop features: fancurve powermode platformprofile platformprofilenotify minifancurve
legion_laptop ec_readonly: 0
powermode: 1
minifancurve feature enabled: 1
minifancurve on cool: true
lock fan controller: false
enable maximumfanspeed: false
enable maximumfanspeed status: 0
fan curve current point id: 0
fan curve points size: 10
Current fan curve in hardware (embedded controller):
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	59	0	54	0	38
1700	1600	2	2	55	59	51	54	35	42
2000	1900	2	2	55	59	51	54	39	127
2100	2100	2	2	55	72	51	54	39	127
2300	2300	2	2	67	76	51	54	39	127
2600	2600	2	2	73	82	51	54	39	127
2900	2900	2	2	76	87	51	58	39	127
3500	3500	2	2	83	92	55	66	39	127
3800	3800	2	2	88	96	63	70	39	127
4400	4400	2	2	93	127	67	127	39	127
=====================

~ 
❯ sudo cat /sys/kernel/debug/legion/fancurve
EC Chip ID: 8227
EC Chip Version: 2a4
legion_laptop features: fancurve powermode platformprofile platformprofilenotify minifancurve
legion_laptop ec_readonly: 0
powermode: 2
minifancurve feature enabled: 1
minifancurve on cool: true
lock fan controller: false
enable maximumfanspeed: false
enable maximumfanspeed status: 0
fan curve current point id: 0
fan curve points size: 9
Current fan curve in hardware (embedded controller):
rpm1|rpm2|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp
0	0	5	7	0	127	0	51	0	38
1700	1600	5	7	127	127	48	51	35	42
2000	1900	5	7	127	127	48	51	39	54
2100	2100	5	7	127	127	48	51	51	127
2300	2300	5	7	127	127	48	55	51	127
2600	2600	5	7	127	127	52	60	51	127
2900	2900	5	7	127	127	56	64	51	127
3500	3500	5	7	127	127	61	70	51	127
3800	3800	5	7	127	127	66	127	51	127
=====================

~ 
❯ sudo cat /sys/kernel/debug/legion/fancurve
EC Chip ID: 8227
EC Chip Version: 2a4
legion_laptop features: fancurve powermode platformprofile platformprofilenotify minifancurve
legion_laptop ec_readonly: 0
powermode: 0
minifancurve feature enabled: 1
minifancurve on cool: true
lock fan controller: false
enable maximumfanspeed: false
enable maximumfanspeed status: 0
fan curve current point id: 0
fan curve points size: 9
Current fan curve in hardware (embedded controller):
rpm1|rpm2|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp
0	0	5	7	0	59	0	54	0	38
1700	1600	5	7	55	59	51	54	35	42
2000	1900	5	7	55	59	51	54	39	127
2100	2100	5	7	55	68	51	54	39	127
2300	2300	5	7	60	77	51	54	39	127
2600	2600	5	7	72	82	51	54	39	127
2900	2900	5	7	78	87	51	58	39	127
3500	3500	5	7	83	89	55	66	39	127
3800	3800	5	7	86	127	63	127	39	127
=====================

@johnfanv2
Copy link
Author

So if you press Fn + Q the mode displayed via powerprofilesctl list updates correctly? But the LED does not change if you change the power mode with powerprofilesctl set?

@pm4rcin
Copy link

pm4rcin commented Apr 7, 2023

  1. Yes
    It looks like everything works now. Maybe I've had an old data copied in primary selection. Sorry for my dumbness.
❯ powerprofilesctl set performance

~ 
❯ sudo cat /sys/kernel/debug/legion/fancurve
[sudo] hasło użytkownika marcin: 
EC Chip ID: 8227
EC Chip Version: 2a4
legion_laptop features: fancurve powermode platformprofile platformprofilenotify minifancurve
legion_laptop ec_readonly: 0
powermode: 1
minifancurve feature enabled: 1
minifancurve on cool: true
lock fan controller: false
enable maximumfanspeed: false
enable maximumfanspeed status: 0
fan curve current point id: 0
fan curve points size: 10
Current fan curve in hardware (embedded controller):
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	59	0	54	0	38
1700	1600	2	2	55	59	51	54	35	42
2000	1900	2	2	55	59	51	54	39	127
2100	2100	2	2	55	72	51	54	39	127
2300	2300	2	2	67	76	51	54	39	127
2600	2600	2	2	73	82	51	54	39	127
2900	2900	2	2	76	87	51	58	39	127
3500	3500	2	2	83	92	55	66	39	127
3800	3800	2	2	88	96	63	70	39	127
4400	4400	2	2	93	127	67	127	39	127
=====================

~ 
❯ powerprofilesctl set power-saver

~ 
❯ sudo cat /sys/kernel/debug/legion/fancurve
EC Chip ID: 8227
EC Chip Version: 2a4
legion_laptop features: fancurve powermode platformprofile platformprofilenotify minifancurve
legion_laptop ec_readonly: 0
powermode: 2
minifancurve feature enabled: 1
minifancurve on cool: true
lock fan controller: false
enable maximumfanspeed: false
enable maximumfanspeed status: 0
fan curve current point id: 0
fan curve points size: 9
Current fan curve in hardware (embedded controller):
rpm1|rpm2|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp
0	0	5	7	0	127	0	51	0	38
1700	1600	5	7	127	127	48	51	35	42
2000	1900	5	7	127	127	48	51	39	54
2100	2100	5	7	127	127	48	51	51	127
2300	2300	5	7	127	127	48	55	51	127
2600	2600	5	7	127	127	52	60	51	127
2900	2900	5	7	127	127	56	64	51	127
3500	3500	5	7	127	127	61	70	51	127
3800	3800	5	7	127	127	66	127	51	127
=====================

~ 
❯ powerprofilesctl set balanced

~ 
❯ sudo cat /sys/kernel/debug/legion/fancurve
EC Chip ID: 8227
EC Chip Version: 2a4
legion_laptop features: fancurve powermode platformprofile platformprofilenotify minifancurve
legion_laptop ec_readonly: 0
powermode: 0
minifancurve feature enabled: 1
minifancurve on cool: true
lock fan controller: false
enable maximumfanspeed: false
enable maximumfanspeed status: 0
fan curve current point id: 0
fan curve points size: 9
Current fan curve in hardware (embedded controller):
rpm1|rpm2|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp
0	0	5	7	0	59	0	54	0	38
1700	1600	5	7	55	59	51	54	35	42
2000	1900	5	7	55	59	51	54	39	127
2100	2100	5	7	55	68	51	54	39	127
2300	2300	5	7	60	77	51	54	39	127
2600	2600	5	7	72	82	51	54	39	127
2900	2900	5	7	78	87	51	58	39	127
3500	3500	5	7	83	89	55	66	39	127
3800	3800	5	7	86	127	63	127	39	127
=====================

@johnfanv2
Copy link
Author

johnfanv2 commented Apr 7, 2023

Great! Thanks for the detailed troubleshooting. So can you confirm that everything is working as described below?

  • if you switch power mode with Fn + Q this changes the output of powerprofilesctl list correctly?
  • if you switch powermode with powerprofilesctl set this changes the LED color and the fan curve reported by sudo cat /sys/kernel/debug/legion/fancurve?

@pm4rcin
Copy link

pm4rcin commented Apr 7, 2023

  1. Yes
  2. Yes
  3. If I'm not mistaken there's only 1 thing left that requires ACPI calls rather than some sysfs or similiar interface. It's the rapid charge. I use the https://github.com/0xless/battmngr which utilizes information from wiki. Make sure to read the note because I'm not sure if it is kernel's responsibility or userspace tool. And what if someone wants to rapid charge but only to the battery conservation level and then turn rapid charge off?

PS. Regarding point 3 I'm not saying you have to implement that but it's probably the only thing for ultimate all in one Legion experience.
PS2. On Readme of your project the Legion 5-15ARH05 has listed BIOS version FSCN14WW but I think it's a mistake since I could only find EUCN BIOS for that model. If you think it's right than prove me wrong. From my research FSCN14WW is for 5-15ARH05H.

@johnfanv2
Copy link
Author

johnfanv2 commented Apr 8, 2023

@pm4rcin Thanks for the tip for the README. I guess the H is missing.

I also created an new version with rapid charge support. Please try the new feature for enabling/disabling rapid charge. Please make sure that rapid charge is really enabled/disabled as configured and shown, i.e. that it charges faster/slower. In particular, if battery conservation is enabled, rapid charging should automatically be disabled by the python user space tool. Maybe this can be checked by the estimated charging time.

johnfanv2 added a commit to johnfanv2/LenovoLegionLinux that referenced this issue Apr 8, 2023
@pm4rcin
Copy link

pm4rcin commented Apr 8, 2023

Happy to say that everything works as expected. I have checked battery charging with bottom and rapid charge works and reports higher power (more than 2x of normal charging). When you click battery conservation or rapid charge the former disables the latter and vice versa.

Regarding the change in README there's one more thing. There's no such model as 5-15ARH05A. That should be changed to 5-15ARH05 which is my model with updated description of working features.

The things left for my laptop are:

  1. Touchpad enable/disable is grey for me. I don't remember how it could be switched with sysfs or smth to check if it's your GUI not working properly or something on my side. I remember that I was able to switch that when I used KDE.
  2. Set speed to maximum fan speed is also grey for me. Any hints? Should it even be working on my laptop at all?

@johnfanv2
Copy link
Author

Thanks for the feedback. Someone told me that one his 15ARH05A it works. I have found some hints that these exists (https://www.reddit.com/r/Lenovo/comments/10hnjig/factory_reset_my_legion_5_15arh05a_advice/). In any case, the BIOS is what counts.

Touchpad: This is provided by the kernel module ideapad if available.
Maximum Fan Speed/Dust cleaner: This is not implemented yet fully, hence disabled :)

The following features might be missing and might be implemented in the future:

  • toggling gsync
  • toggling internal GPU
  • toggling overdrive
  • toggling touchpad (with another method)
  • setting to max fan speed (with another method)
  • turn on/off keyboard backlight: do you have the white backlight?
    Which of these features work on your device in Windows with Vantage or Lenovo Legion Toolkit?

@pm4rcin
Copy link

pm4rcin commented Apr 11, 2023

  1. I don't use Windows so can't tell what works and what doesn't there.
  2. Kde uses libinput for touchpad and it works great there.
  3. My laptop doesn't have gsync/freesync so can't test.
  4. iGPU/overdrive/fan max speed see point 1
  5. I have white keyboard backlight and I'm able to toggle it with writing 0 or 1 to /sys/class/leds/platform::kbd_backlight/brightness

@johnfanv2
Copy link
Author

johnfanv2 commented Apr 12, 2023

  1. ok

  2. I guess it is disabled somehow in software with libinput. This driver tries to do in "in hardware"

  3. ok

  4. Not sure what you mean with the listed features. Are these the functions you have? I created a new version with new features - still experimential. You can test them by writing and reading to files in ls /sys/module/legion_laptop/drivers/platform\:legion/PNP0C09\:00/. Still experimental, so it also displays features that you do not have. In that case it will return an error when trying to access.

  • cpu_shortterm_powerlimit
  • cpu_longterm_powerlimit
  • gpu_ppab_powerlimit
  • gpu_ctgp_powerlimit
  • gpu_ctgp2_powerlimit (readonly)
  • isacfitforoc (read only - 1 if high power charger is connected)
  • rapidcharge
  • cpumaxfrequency (readonly),
  • gsync
  • overdrive
  • powerchargemode,
  • fan_fullspeed (only works in custom power mode mode probably not available on your model),
  • touchpad (lock touchpad)
  • winkey (enable/disable winkey)
  • and more
  1. I have created a new version that also creates platform::kbd_backlight. Is this file from the legion driver or from ideapad? you can check with ls -lah /sys/class/leds/platform::kbd_backlight. If it contains PNP0C09:00, then it is from legion driver. Do you have the light that can be toggled by Fn + Space into the modes off, medium, full? Or just on/off?

@pm4rcin
Copy link

pm4rcin commented Apr 12, 2023

  1. Switching touchpad by writing to PNP0C09:00 below works fine.

  1. List of new features with output.
la /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/
razem 0
-r--r--r-- 1 root root 4,0K 04-12 22:05 aslcodeversion
-rw-r--r-- 1 root root 4,0K 04-12 22:05 cpu_longterm_powerlimit
-r--r--r-- 1 root root 4,0K 04-12 22:05 cpumaxfrequency
-rw-r--r-- 1 root root 4,0K 04-12 22:05 cpu_shortterm_powerlimit
lrwxrwxrwx 1 root root    0 04-12 22:04 driver -> ../../../../bus/platform/drivers/legion/
-rw-r--r-- 1 root root 4,0K 04-12 22:05 driver_override
-rw-r--r-- 1 root root 4,0K 04-12 22:05 fan_fullspeed
lrwxrwxrwx 1 root root    0 04-12 22:05 firmware_node -> ../../../LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:31/PNP0C09:00/
-r--r--r-- 1 root root 4,0K 04-12 22:05 gpu_ctgp2_powerlimit
-rw-r--r-- 1 root root 4,0K 04-12 22:05 gpu_ctgp_powerlimit
-rw-r--r-- 1 root root 4,0K 04-12 22:05 gpu_ppab_powerlimit
-rw-r--r-- 1 root root 4,0K 04-12 22:05 gsync
drwxr-xr-x 3 root root    0 04-12 22:04 hwmon/
-r--r--r-- 1 root root 4,0K 04-12 22:05 isacfitforoc
-r--r--r-- 1 root root 4,0K 04-12 22:05 issupportcpuoc
-r--r--r-- 1 root root 4,0K 04-12 22:05 issupportgpuoc
-rw-r--r-- 1 root root 4,0K 04-12 22:05 lockfancontroller
-r--r--r-- 1 root root 4,0K 04-12 14:19 modalias
-rw-r--r-- 1 root root 4,0K 04-12 22:05 overdrive
drwxr-xr-x 3 root root    0 04-12 14:19 PNP0C0A:00/
drwxr-xr-x 2 root root    0 04-12 22:05 power/
-r--r--r-- 1 root root 4,0K 04-12 22:05 powerchargemode
-rw-r--r-- 1 root root 4,0K 04-12 22:05 powermode
-rw-r--r-- 1 root root 4,0K 04-12 22:05 rapidcharge
lrwxrwxrwx 1 root root    0 04-12 14:19 subsystem -> ../../../../bus/platform/
-r--r--r-- 1 root root 4,0K 04-12 22:05 thermalmode
-rw-r--r-- 1 root root 4,0K 04-12 22:05 touchpad
-rw-r--r-- 1 root root 4,0K 04-12 14:19 uevent
drwxr-xr-x 6 root root    0 04-12 14:19 VPC2004:00/
-rw-r--r-- 1 root root 4,0K 04-12 22:05 winkey

LenovoLegionLinux/kernel_module on  main via C v12.2.1-gcc 
❯ cat /sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/*
11
cat: '/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/cpu_longterm_powerlimit': Zły argument
cat: '/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/cpu_shortterm_powerlimit': Zły argument
0
cat: '/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/driver': Jest katalogiem
(null)
cat: '/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/fan_fullspeed': Zły argument
cat: '/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/firmware_node': Jest katalogiem
cat: '/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/gpu_ctgp2_powerlimit': Zły argument
cat: '/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/gpu_ctgp_powerlimit': Zły argument
cat: '/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/gpu_ppab_powerlimit': Zły argument
1
cat: '/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/hwmon': Jest katalogiem
0
0
2
0
acpi:PNP0C09:
0
cat: '/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/PNP0C0A:00': Jest katalogiem
cat: '/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/power': Jest katalogiem
1
0
0
cat: '/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/subsystem': Jest katalogiem
2
0
DRIVER=legion
MODALIAS=acpi:PNP0C09:
cat: '/sys/module/legion_laptop/drivers/platform:legion/PNP0C09:00/VPC2004:00': Jest katalogiem
1
  1. It's from ideapad driver. I have fn + Space with modes off, medium and full. But in ideapad driver there's only off or full.
    PS. I don't know why it shows gsync=1. I'm pretty sure that my laptop doesn't support it.

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

No branches or pull requests

4 participants