-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathlegion-laptop.c
6090 lines (5391 loc) · 178 KB
/
legion-laptop.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* legion-laptop.c - Extra Lenovo Legion laptop support, in
* particular for fan curve control and power mode.
*
* Copyright (C) 2022 johnfan <johnfan (at) example (dot) com>
*
*
* This driver might work on other Lenovo Legion models. If you
* want to try it you can pass force=1 as argument
* to the module which will force it to load even when the DMI
* data doesn't match the model AND FIRMWARE.
*
* Support for other hardware of this model is already partially
* provided by the module ideapad-laptop.
*
* The development page for this driver is located at
* https://github.com/johnfanv2/LenovoLegionLinux
*
* This driver exports the files:
* - /sys/kernel/debug/legion/fancurve (ro)
* The fan curve stored in the firmware in the form of a
* human readable table.
*
* - /sys/module/legion_laptop/drivers/platform\:legion/PNP0C09\:00/powermode (rw)
* 0: balanced mode (white)
* 1: performance mode (red)
* 2: quiet mode (blue)
* ?: custom mode (pink)
*
* NOTE: Writing to this will load the default fan curve from
* the firmware for this mode, so the fan curve might
* have to be reconfigured if needed.
*
* It implements the usual hwmon interface to monitor fan speed and temmperature
* and allows to set the fan curve inside the firware.
*
* - /sys/class/hwmon/X/fan1_input or /sys/class/hwmon/X/fan2_input (ro)
* Current fan speed of fan1/fan2.
* - /sys/class/hwmon/X/temp1_input (ro)
* - /sys/class/hwmon/X/temp2_input (ro)
* - /sys/class/hwmon/X/temp3_input (ro)
* Temperature (Celsius) of CPU, GPU, and IC used for fan control.
* - /sys/class/hwmon/X/pwmY_auto_pointZ_pwm (rw)
* PWM (0-255) of the fan at the Y-level in the fan curve
* - /sys/class/hwmon/X/pwmY_auto_pointZ_temp (rw)
* upper temperature of tempZ (CPU, GPU, or IC) at the Y-level in the fan curve
* - /sys/class/hwmon/X/pwmY_auto_pointZ_temp_hyst (rw)
* hysteris (CPU, GPU, or IC) at the Y-level in the fan curve. The lower
* temperatue of the level is the upper temperature minus the hysteris
*
*
* Credits for reverse engineering the firmware to:
* - David Woodhouse: heavily inspired by lenovo_laptop.c
* - Luke Cama: Windows version "LegionFanControl"
* - SmokelessCPU: reverse engineering of custom registers in EC
* and commincation method with EC via ports
* - 0x1F9F1: additional reverse engineering for complete fan curve
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/acpi.h>
#include <asm/io.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/dmi.h>
#include <linux/leds.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/platform_device.h>
#include <linux/platform_profile.h>
#include <linux/types.h>
#include <linux/wmi.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("johnfan");
MODULE_DESCRIPTION("Lenovo Legion laptop extras");
static bool force;
module_param(force, bool, 0440);
MODULE_PARM_DESC(
force,
"Force loading this module even if model or BIOS does not match.");
static bool ec_readonly;
module_param(ec_readonly, bool, 0440);
MODULE_PARM_DESC(
ec_readonly,
"Only read from embedded controller but do not write or change settings.");
static bool enable_platformprofile = true;
module_param(enable_platformprofile, bool, 0440);
MODULE_PARM_DESC(
enable_platformprofile,
"Enable the platform profile sysfs API to read and write the power mode.");
#define LEGIONFEATURES \
"fancurve powermode platformprofile platformprofilenotify minifancurve"
//Size of fancurve stored in embedded controller
#define MAXFANCURVESIZE 10
#define LEGION_DRVR_SHORTNAME "legion"
#define LEGION_HWMON_NAME LEGION_DRVR_SHORTNAME "_hwmon"
struct legion_private;
/* =============================== */
/* Embedded Controller Description */
/* =============================== */
/* The configuration and registers to access the embedded controller
* depending on different the version of the software on the
* embedded controller or and the BIOS/UEFI firmware.
*
* To control fan curve in the embedded controller (EC) one has to
* write to its "RAM". There are different possibilities:
* - EC RAM is memory mapped (write to it with ioremap)
* - access EC RAM via ported mapped IO (outb/inb)
* - access EC RAM via ACPI methods. It is only possible to write
* to part of it (first 0xFF bytes?)
*
* In later models the firmware directly exposes ACPI methods to
* set the fan curve directly, without writing to EC RAM. This
* is done inside the ACPI method.
*/
/**
* Offsets for interesting values inside the EC RAM (0 = start of
* EC RAM) These might change depending on the software inside of
* the EC, which can be updated by a BIOS update from Lenovo.
*/
// TODO: same order as in initialization
struct ec_register_offsets {
// Super I/O Configuration Registers
// 7.15 General Control (GCTRL)
// General Control (GCTRL)
// (see EC Interface Registers and 6.2 Plug and Play Configuration (PNPCFG)) in datasheet
// note: these are in two places saved
// in EC Interface Registers and in super io configuration registers
// Chip ID
u16 ECHIPID1;
u16 ECHIPID2;
// Chip Version
u16 ECHIPVER;
u16 ECDEBUG;
// Lenovo Custom OEM extension
// Firmware of ITE can be extended by
// custom program using its own "variables"
// These are the offsets to these "variables"
u16 EXT_FAN_CUR_POINT;
u16 EXT_FAN_POINTS_SIZE;
u16 EXT_FAN1_BASE;
u16 EXT_FAN2_BASE;
u16 EXT_FAN_ACC_BASE;
u16 EXT_FAN_DEC_BASE;
u16 EXT_CPU_TEMP;
u16 EXT_CPU_TEMP_HYST;
u16 EXT_GPU_TEMP;
u16 EXT_GPU_TEMP_HYST;
u16 EXT_VRM_TEMP;
u16 EXT_VRM_TEMP_HYST;
u16 EXT_FAN1_RPM_LSB;
u16 EXT_FAN1_RPM_MSB;
u16 EXT_FAN2_RPM_LSB;
u16 EXT_FAN2_RPM_MSB;
u16 EXT_FAN1_TARGET_RPM;
u16 EXT_FAN2_TARGET_RPM;
u16 EXT_POWERMODE;
u16 EXT_MINIFANCURVE_ON_COOL;
// values
// 0x04: enable mini fan curve if left for too long on cool level
// - this might be due to potential temp failure
// - or just because of really cool temps
// 0xA0: disable it
u16 EXT_LOCKFANCONTROLLER;
u16 EXT_MAXIMUMFANSPEED;
u16 EXT_WHITE_KEYBOARD_BACKLIGHT;
u16 EXT_IC_TEMP_INPUT;
u16 EXT_CPU_TEMP_INPUT;
u16 EXT_GPU_TEMP_INPUT;
};
enum access_method {
ACCESS_METHOD_NO_ACCESS = 0,
ACCESS_METHOD_EC = 1,
ACCESS_METHOD_ACPI = 2,
ACCESS_METHOD_WMI = 3,
ACCESS_METHOD_WMI2 = 4,
ACCESS_METHOD_WMI3 = 5,
ACCESS_METHOD_EC2 = 10, // ideapad fancurve method
ACCESS_METHOD_EC3 = 11, // loq
};
struct model_config {
const struct ec_register_offsets *registers;
bool check_embedded_controller_id;
u16 embedded_controller_id;
// first addr in EC we access/scan
phys_addr_t memoryio_physical_ec_start;
size_t memoryio_size;
// TODO: maybe use bitfield
bool has_minifancurve;
bool has_custom_powermode;
enum access_method access_method_powermode;
enum access_method access_method_keyboard;
enum access_method access_method_temperature;
enum access_method access_method_fanspeed;
enum access_method access_method_fancurve;
enum access_method access_method_fanfullspeed;
bool three_state_keyboard;
bool acpi_check_dev;
phys_addr_t ramio_physical_start;
size_t ramio_size;
};
/* =================================== */
/* Configuration for different models */
/* =================================== */
// Idea by SmokelesssCPU (modified)
// - all default names and register addresses are supported by datasheet
// - register addresses for custom firmware by SmokelesssCPU
static const struct ec_register_offsets ec_register_offsets_v0 = {
.ECHIPID1 = 0x2000,
.ECHIPID2 = 0x2001,
.ECHIPVER = 0x2002,
.ECDEBUG = 0x2003,
.EXT_FAN_CUR_POINT = 0xC534,
.EXT_FAN_POINTS_SIZE = 0xC535,
.EXT_FAN1_BASE = 0xC540,
.EXT_FAN2_BASE = 0xC550,
.EXT_FAN_ACC_BASE = 0xC560,
.EXT_FAN_DEC_BASE = 0xC570,
.EXT_CPU_TEMP = 0xC580,
.EXT_CPU_TEMP_HYST = 0xC590,
.EXT_GPU_TEMP = 0xC5A0,
.EXT_GPU_TEMP_HYST = 0xC5B0,
.EXT_VRM_TEMP = 0xC5C0,
.EXT_VRM_TEMP_HYST = 0xC5D0,
.EXT_FAN1_RPM_LSB = 0xC5E0,
.EXT_FAN1_RPM_MSB = 0xC5E1,
.EXT_FAN2_RPM_LSB = 0xC5E2,
.EXT_FAN2_RPM_MSB = 0xC5E3,
.EXT_MINIFANCURVE_ON_COOL = 0xC536,
.EXT_LOCKFANCONTROLLER = 0xc4AB,
.EXT_CPU_TEMP_INPUT = 0xc538,
.EXT_GPU_TEMP_INPUT = 0xc539,
.EXT_IC_TEMP_INPUT = 0xC5E8,
.EXT_POWERMODE = 0xc420,
.EXT_FAN1_TARGET_RPM = 0xc600,
.EXT_FAN2_TARGET_RPM = 0xc601,
.EXT_MAXIMUMFANSPEED = 0xBD,
.EXT_WHITE_KEYBOARD_BACKLIGHT = (0x3B + 0xC400)
};
static const struct ec_register_offsets ec_register_offsets_v1 = {
.ECHIPID1 = 0x2000,
.ECHIPID2 = 0x2001,
.ECHIPVER = 0x2002,
.ECDEBUG = 0x2003,
.EXT_FAN_CUR_POINT = 0xC534,
.EXT_FAN_POINTS_SIZE = 0xC535,
.EXT_FAN1_BASE = 0xC540,
.EXT_FAN2_BASE = 0xC550,
.EXT_FAN_ACC_BASE = 0xC560,
.EXT_FAN_DEC_BASE = 0xC570,
.EXT_CPU_TEMP = 0xC580,
.EXT_CPU_TEMP_HYST = 0xC590,
.EXT_GPU_TEMP = 0xC5A0,
.EXT_GPU_TEMP_HYST = 0xC5B0,
.EXT_VRM_TEMP = 0xC5C0,
.EXT_VRM_TEMP_HYST = 0xC5D0,
.EXT_FAN1_RPM_LSB = 0xC5E0,
.EXT_FAN1_RPM_MSB = 0xC5E1,
.EXT_FAN2_RPM_LSB = 0xC5E2,
.EXT_FAN2_RPM_MSB = 0xC5E3,
.EXT_MINIFANCURVE_ON_COOL = 0xC536,
.EXT_LOCKFANCONTROLLER = 0xc4AB,
.EXT_CPU_TEMP_INPUT = 0xc538,
.EXT_GPU_TEMP_INPUT = 0xc539,
.EXT_IC_TEMP_INPUT = 0xC5E8,
.EXT_POWERMODE = 0xc41D,
.EXT_FAN1_TARGET_RPM = 0xc600,
.EXT_FAN2_TARGET_RPM = 0xc601,
.EXT_MAXIMUMFANSPEED = 0xBD,
.EXT_WHITE_KEYBOARD_BACKLIGHT = (0x3B + 0xC400)
};
static const struct ec_register_offsets ec_register_offsets_ideapad_v0 = {
.ECHIPID1 = 0x2000,
.ECHIPID2 = 0x2001,
.ECHIPVER = 0x2002,
.ECDEBUG = 0x2003,
.EXT_FAN_CUR_POINT = 0xC5a0, // not found yet
.EXT_FAN_POINTS_SIZE = 0xC5a0, // constant 0
.EXT_FAN1_BASE = 0xC5a0,
.EXT_FAN2_BASE = 0xC5a8,
.EXT_FAN_ACC_BASE = 0xC5a0, // not found yet
.EXT_FAN_DEC_BASE = 0xC5a0, // not found yet
.EXT_CPU_TEMP = 0xC550, // and repeated after 8 bytes
.EXT_CPU_TEMP_HYST = 0xC590, // and repeated after 8 bytes
.EXT_GPU_TEMP = 0xC5C0, // and repeated after 8 bytes
.EXT_GPU_TEMP_HYST = 0xC5D0, // and repeated after 8 bytes
.EXT_VRM_TEMP = 0xC5a0, // does not exists or not found
.EXT_VRM_TEMP_HYST = 0xC5a0, // does not exists ot not found yet
.EXT_FAN1_RPM_LSB = 0xC5a0, // not found yet
.EXT_FAN1_RPM_MSB = 0xC5a0, // not found yet
.EXT_FAN2_RPM_LSB = 0xC5a0, // not found yet
.EXT_FAN2_RPM_MSB = 0xC5a0, // not found yet
.EXT_MINIFANCURVE_ON_COOL = 0xC5a0, // does not exists or not found
.EXT_LOCKFANCONTROLLER = 0xC5a0, // does not exists or not found
.EXT_CPU_TEMP_INPUT = 0xC5a0, // not found yet
.EXT_GPU_TEMP_INPUT = 0xC5a0, // not found yet
.EXT_IC_TEMP_INPUT = 0xC5a0, // not found yet
.EXT_POWERMODE = 0xC5a0, // not found yet
.EXT_FAN1_TARGET_RPM = 0xC5a0, // not found yet
.EXT_FAN2_TARGET_RPM = 0xC5a0, // not found yet
.EXT_MAXIMUMFANSPEED = 0xC5a0, // not found yet
.EXT_WHITE_KEYBOARD_BACKLIGHT = 0xC5a0 // not found yet
};
static const struct ec_register_offsets ec_register_offsets_ideapad_v1 = {
.ECHIPID1 = 0x2000,
.ECHIPID2 = 0x2001,
.ECHIPVER = 0x2002,
.ECDEBUG = 0x2003,
.EXT_FAN_CUR_POINT = 0xC5a0, // not found yet
.EXT_FAN_POINTS_SIZE = 0xC5a0, // constant 0
.EXT_FAN1_BASE = 0xC5a0,
.EXT_FAN2_BASE = 0xC5a8,
.EXT_FAN_ACC_BASE = 0xC5a0, // not found yet
.EXT_FAN_DEC_BASE = 0xC5a0, // not found yet
.EXT_CPU_TEMP = 0xC550, // and repeated after 8 bytes
.EXT_CPU_TEMP_HYST = 0xC590, // and repeated after 8 bytes
.EXT_GPU_TEMP = 0xC5C0, // and repeated after 8 bytes
.EXT_GPU_TEMP_HYST = 0xC5D0, // and repeated after 8 bytes
.EXT_VRM_TEMP = 0xC5a0, // does not exists or not found
.EXT_VRM_TEMP_HYST = 0xC5a0, // does not exists ot not found yet
.EXT_FAN1_RPM_LSB = 0xC5a0, // not found yet
.EXT_FAN1_RPM_MSB = 0xC5a0, // not found yet
.EXT_FAN2_RPM_LSB = 0xC5a0, // not found yet
.EXT_FAN2_RPM_MSB = 0xC5a0, // not found yet
.EXT_MINIFANCURVE_ON_COOL = 0xC5a0, // does not exists or not found
.EXT_LOCKFANCONTROLLER = 0xC5a0, // does not exists or not found
.EXT_CPU_TEMP_INPUT = 0xC5a0, // not found yet
.EXT_GPU_TEMP_INPUT = 0xC5a0, // not found yet
.EXT_IC_TEMP_INPUT = 0xC5a0, // not found yet
.EXT_POWERMODE = 0xC5a0, // not found yet
.EXT_FAN1_TARGET_RPM = 0xC5a0, // not found yet
.EXT_FAN2_TARGET_RPM = 0xC5a0, // not found yet
.EXT_MAXIMUMFANSPEED = 0xC5a0, // not found yet
.EXT_WHITE_KEYBOARD_BACKLIGHT = 0xC5a0 // not found yet
};
static const struct ec_register_offsets ec_register_offsets_loq_v0 = {
.ECHIPID1 = 0x2000,
.ECHIPID2 = 0x2001,
.ECHIPVER = 0x2002,
.ECDEBUG = 0x2003,
.EXT_FAN_CUR_POINT = 0xC5a0,
.EXT_FAN_POINTS_SIZE = 0xC5a0, // constant 0
.EXT_FAN1_BASE = 0xC530,
.EXT_FAN2_BASE = 0xC530, // same rpm as cpu
.EXT_FAN_ACC_BASE = 0xC5a0, // not found yet
.EXT_FAN_DEC_BASE = 0xC5a0, // not found yet
.EXT_CPU_TEMP = 0xC52F,
.EXT_CPU_TEMP_HYST = 0xC5a0, // not found yet
.EXT_GPU_TEMP = 0xC531,
.EXT_GPU_TEMP_HYST = 0xC5a0, // not found yet
.EXT_VRM_TEMP = 0xC5a0, // not found yet
.EXT_VRM_TEMP_HYST = 0xC5a0, // not found yet
.EXT_FAN1_RPM_LSB = 0xC5a0, // not found yet
.EXT_FAN1_RPM_MSB = 0xC5a0, // not found yet
.EXT_FAN2_RPM_LSB = 0xC5a0, // not found yet
.EXT_FAN2_RPM_MSB = 0xC5a0, // not found yet
.EXT_MINIFANCURVE_ON_COOL = 0xC5a0, // not found yet
.EXT_LOCKFANCONTROLLER = 0xC5a0, // not found yet
.EXT_CPU_TEMP_INPUT = 0xC5a0, // not found yet
.EXT_GPU_TEMP_INPUT = 0xC5a0, // not found yet
.EXT_IC_TEMP_INPUT = 0xC5a0, // not found yet
.EXT_POWERMODE = 0xc41D,
.EXT_FAN1_TARGET_RPM = 0xC5a0, // not found yet
.EXT_FAN2_TARGET_RPM = 0xC5a0, // not found yet
.EXT_MAXIMUMFANSPEED = 0xC5a0, // not found yet
.EXT_WHITE_KEYBOARD_BACKLIGHT = 0xC5a0 // not found yet
};
static const struct model_config model_v0 = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_EC,
.access_method_temperature = ACCESS_METHOD_EC,
.access_method_fancurve = ACCESS_METHOD_EC,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = true,
.ramio_physical_start = 0xFE00D400,
.ramio_size = 0x600
};
static const struct model_config model_j2cn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_EC,
.access_method_temperature = ACCESS_METHOD_EC,
.access_method_fancurve = ACCESS_METHOD_EC,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = true,
.ramio_physical_start = 0xFE00D400,
.ramio_size = 0x600
};
static const struct model_config model_9vcn = {
.registers = &ec_register_offsets_ideapad_v1,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x8226,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_WMI,
.access_method_temperature = ACCESS_METHOD_WMI,
.access_method_fancurve = ACCESS_METHOD_EC2,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = false,
.ramio_physical_start = 0xFE00D400,
.ramio_size = 0x600
};
static const struct model_config model_v2022 = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_EC,
.access_method_temperature = ACCESS_METHOD_EC,
.access_method_fancurve = ACCESS_METHOD_EC,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = true,
.ramio_physical_start = 0xFE00D400,
.ramio_size = 0x600
};
static const struct model_config model_4gcn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x8226,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_EC,
.access_method_temperature = ACCESS_METHOD_EC,
.access_method_fancurve = ACCESS_METHOD_EC,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = true,
.ramio_physical_start = 0xFE00D400,
.ramio_size = 0x600
};
static const struct model_config model_bvcn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = false,
.embedded_controller_id = 0x8226,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_WMI,
.access_method_temperature = ACCESS_METHOD_WMI,
.access_method_fancurve = ACCESS_METHOD_NO_ACCESS,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = false,
.ramio_physical_start = 0xFC7E0800,
.ramio_size = 0x600
};
static const struct model_config model_bhcn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x8226,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = false,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_ACPI,
.access_method_fanspeed = ACCESS_METHOD_WMI,
.access_method_temperature = ACCESS_METHOD_ACPI,
.access_method_fancurve = ACCESS_METHOD_EC,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = true,
.ramio_physical_start = 0xFF00D400,
.ramio_size = 0x600
};
static const struct model_config model_kwcn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x5507,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = false,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_WMI3,
.access_method_temperature = ACCESS_METHOD_WMI3,
.access_method_fancurve = ACCESS_METHOD_WMI3,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = true,
.ramio_physical_start = 0xFE0B0400,
.ramio_size = 0x600
};
static const struct model_config model_m0cn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x5507,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_WMI3,
.access_method_temperature = ACCESS_METHOD_WMI3,
.access_method_fancurve = ACCESS_METHOD_WMI3,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = false,
.ramio_physical_start = 0xFE0B0400,
.ramio_size = 0x600
};
static const struct model_config model_m1cn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x5507,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_WMI3,
.access_method_temperature = ACCESS_METHOD_WMI3,
.access_method_fancurve = ACCESS_METHOD_WMI3,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = false,
.ramio_physical_start = 0xFE0B0400,
.ramio_size = 0x600
};
static const struct model_config model_m2cn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_WMI3,
.access_method_temperature = ACCESS_METHOD_WMI3,
.access_method_fancurve = ACCESS_METHOD_WMI3,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = false,
.ramio_physical_start = 0xFE0B0400,
.ramio_size = 0x600
};
static const struct model_config model_m6cn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_WMI3,
.access_method_temperature = ACCESS_METHOD_WMI3,
.access_method_fancurve = ACCESS_METHOD_WMI3,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = false,
.ramio_physical_start = 0xFE0B0400,
.ramio_size = 0x600
};
static const struct model_config model_k1cn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x5263,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = false,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_WMI3,
.access_method_temperature = ACCESS_METHOD_WMI3,
.access_method_fancurve = ACCESS_METHOD_WMI3,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = true,
.ramio_physical_start = 0xFE0B0400,
.ramio_size = 0x600
};
static const struct model_config model_lpcn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x5507,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = false,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_WMI3,
.access_method_temperature = ACCESS_METHOD_WMI3,
.access_method_fancurve = ACCESS_METHOD_WMI3,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = true,
.ramio_physical_start = 0xFE0B0400,
.ramio_size = 0x600
};
static const struct model_config model_kfcn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = false,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_EC,
.access_method_temperature = ACCESS_METHOD_EC,
.access_method_fancurve = ACCESS_METHOD_EC,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = true,
.ramio_physical_start = 0xFE00D400,
.ramio_size = 0x600
};
static const struct model_config model_hacn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = false,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_EC,
.access_method_temperature = ACCESS_METHOD_EC,
.access_method_fancurve = ACCESS_METHOD_EC,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = true,
.ramio_physical_start = 0xFE00D400,
.ramio_size = 0x600
};
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 ?
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_EC,
.access_method_temperature = ACCESS_METHOD_EC,
.access_method_fancurve = ACCESS_METHOD_EC,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = true,
.ramio_physical_start = 0xFE00D400,
.ramio_size = 0x600
};
static const struct model_config model_eucn = {
.registers = &ec_register_offsets_v1,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_EC,
.access_method_temperature = ACCESS_METHOD_EC,
.access_method_fancurve = ACCESS_METHOD_EC,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = true,
.ramio_physical_start = 0xFE00D400,
.ramio_size = 0x600
};
static const struct model_config model_fccn = {
.registers = &ec_register_offsets_ideapad_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = false,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_WMI,
.access_method_temperature = ACCESS_METHOD_ACPI,
.access_method_fancurve = ACCESS_METHOD_EC2,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = true,
.ramio_physical_start = 0xFE00D400,
.ramio_size = 0x600
};
static const struct model_config model_h3cn = {
//0xFE0B0800
.registers = &ec_register_offsets_v1,
.check_embedded_controller_id = false,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = false,
.has_custom_powermode = false,
.access_method_powermode = ACCESS_METHOD_WMI,
// not implemented (properly) in WMI, RGB conrolled by USB
.access_method_keyboard = ACCESS_METHOD_NO_ACCESS,
// accessing fan speed is not implemented in ACPI
// a variable in the operation region (or not found)
// and not per WMI (methods returns constant 0)
.access_method_fanspeed = ACCESS_METHOD_NO_ACCESS,
.access_method_temperature = ACCESS_METHOD_WMI,
.access_method_fancurve = ACCESS_METHOD_NO_ACCESS,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = false,
.ramio_physical_start = 0xFE0B0800,
.ramio_size = 0x600
};
static const struct model_config model_e9cn = {
//0xFE0B0800
.registers = &ec_register_offsets_v1,
.check_embedded_controller_id = false,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400, //0xFC7E0800
.memoryio_size = 0x300,
.has_minifancurve = false,
.has_custom_powermode = false,
.access_method_powermode = ACCESS_METHOD_WMI,
// not implemented (properly) in WMI, RGB conrolled by USB
.access_method_keyboard = ACCESS_METHOD_NO_ACCESS,
// accessing fan speed is not implemented in ACPI
// a variable in the operation region (or not found)
// and not per WMI (methods returns constant 0)
.access_method_fanspeed = ACCESS_METHOD_WMI,
.access_method_temperature = ACCESS_METHOD_WMI,
.access_method_fancurve = ACCESS_METHOD_NO_ACCESS,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = false,
.ramio_physical_start = 0xFC7E0800,
.ramio_size = 0x600
};
static const struct model_config model_8jcn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x8226,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_WMI,
.access_method_temperature = ACCESS_METHOD_WMI,
.access_method_fancurve = ACCESS_METHOD_EC,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = false,
.ramio_physical_start = 0xFE00D400,
.ramio_size = 0x600
};
static const struct model_config model_jncn = {
.registers = &ec_register_offsets_v1,
.check_embedded_controller_id = false,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = false,
.has_custom_powermode = false,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_NO_ACCESS,
.access_method_fanspeed = ACCESS_METHOD_WMI,
.access_method_temperature = ACCESS_METHOD_WMI,
.access_method_fancurve = ACCESS_METHOD_NO_ACCESS,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = false,
.ramio_physical_start = 0xFC7E0800,
.ramio_size = 0x600
};
// Yoga Model!
static const struct model_config model_j1cn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_EC,
.access_method_temperature = ACCESS_METHOD_EC,
.access_method_fancurve = ACCESS_METHOD_EC,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = true,
.ramio_physical_start = 0xFE0B0400,
.ramio_size = 0x600
};
// Yoga Model!
static const struct model_config model_dmcn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_EC,
.access_method_temperature = ACCESS_METHOD_EC,
.access_method_fancurve = ACCESS_METHOD_EC,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = true,
.ramio_physical_start = 0xFE700D00,
.ramio_size = 0x600
};
// Yoga Model!
static const struct model_config model_khcn = {
.registers = &ec_register_offsets_v0,
.check_embedded_controller_id = false,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_EC,
.access_method_keyboard = ACCESS_METHOD_WMI,
.access_method_fanspeed = ACCESS_METHOD_EC,
.access_method_temperature = ACCESS_METHOD_EC,
.access_method_fancurve = ACCESS_METHOD_EC,
.access_method_fanfullspeed = ACCESS_METHOD_WMI,
.acpi_check_dev = false,
.ramio_physical_start = 0xFE0B0400,
.ramio_size = 0x600
};
// LOQ Model
static const struct model_config model_lzcn = {
.registers = &ec_register_offsets_loq_v0,
.check_embedded_controller_id = true,
.embedded_controller_id = 0x8227,
.memoryio_physical_ec_start = 0xC400,
.memoryio_size = 0x300,
.has_minifancurve = true,
.has_custom_powermode = true,
.access_method_powermode = ACCESS_METHOD_WMI,
.access_method_keyboard = ACCESS_METHOD_WMI2,
.access_method_fanspeed = ACCESS_METHOD_WMI3,
.access_method_temperature = ACCESS_METHOD_WMI3,
.access_method_fancurve = ACCESS_METHOD_EC3,
.access_method_fanfullspeed = ACCESS_METHOD_WMI3,
.acpi_check_dev = false,
.ramio_physical_start = 0xFE0B0400,
.ramio_size = 0x600
};
static const struct dmi_system_id denylist[] = { {} };
static const struct dmi_system_id optimistic_allowlist[] = {
{
// Release year: 2021
// Generation: 6
// Name: Legion 5, Legion 5 pro, Legion 7
// Family: Legion 5 15ACH6H, ...
.ident = "GKCN",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
DMI_MATCH(DMI_BIOS_VERSION, "GKCN"),
},
.driver_data = (void *)&model_v0
},
{
// Release year: 2020
.ident = "EUCN",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
DMI_MATCH(DMI_BIOS_VERSION, "EUCN"),
},
.driver_data = (void *)&model_eucn
},
{
// Release year: 2020
.ident = "EFCN",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
DMI_MATCH(DMI_BIOS_VERSION, "EFCN"),
},
.driver_data = (void *)&model_v0
},
{
// Release year: 2020
.ident = "FSCN",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
DMI_MATCH(DMI_BIOS_VERSION, "FSCN"),
},
.driver_data = (void *)&model_v0
},
{
// Release year: 2021
.ident = "HHCN",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
DMI_MATCH(DMI_BIOS_VERSION, "HHCN"),
},
.driver_data = (void *)&model_v0
},
{
// Release year: 2022
.ident = "H1CN",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
DMI_MATCH(DMI_BIOS_VERSION, "H1CN"),
},
.driver_data = (void *)&model_v0
},
{
// Release year: 2022
.ident = "J2CN",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
DMI_MATCH(DMI_BIOS_VERSION, "J2CN"),
},
.driver_data = (void *)&model_v0
},
{
// Release year: 2022
.ident = "JUCN",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
DMI_MATCH(DMI_BIOS_VERSION, "JUCN"),
},