-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcommands.rs
More file actions
1733 lines (1528 loc) · 40.2 KB
/
commands.rs
File metadata and controls
1733 lines (1528 loc) · 40.2 KB
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
use core::fmt;
use num_derive::FromPrimitive;
use super::{command::*, input_deck::INPUT_DECK_SLOTS};
#[cfg(feature = "uefi")]
use core::prelude::rust_2021::derive;
#[repr(C, packed)]
pub struct EcRequestGetVersion {}
#[repr(C, packed)]
pub struct EcResponseGetVersion {
/// Null-terminated version of the RO firmware
pub version_string_ro: [u8; 32],
/// Null-terminated version of the RW firmware
pub version_string_rw: [u8; 32],
/// Used to be the RW-B string
pub reserved: [u8; 32],
/// Which EC image is currently in-use. See enum EcCurrentImage
pub current_image: u32,
}
impl EcRequest<EcResponseGetVersion> for EcRequestGetVersion {
fn command_id() -> EcCommands {
EcCommands::GetVersion
}
}
#[repr(C, packed)]
pub struct EcRequestGetCmdVersionsV0 {
pub cmd: u8,
}
#[repr(C, packed)]
#[derive(Debug, Clone, Copy)]
pub struct EcResponseGetCmdVersionsV0 {
pub version_mask: u32,
}
impl EcRequest<EcResponseGetCmdVersionsV0> for EcRequestGetCmdVersionsV0 {
fn command_id() -> EcCommands {
EcCommands::GetCmdVersions
}
fn command_version() -> u8 {
0
}
}
#[repr(C, packed)]
pub struct EcRequestGetCmdVersionsV1 {
pub cmd: u32,
}
#[repr(C, packed)]
#[derive(Debug, Clone, Copy)]
pub struct EcResponseGetCmdVersionsV1 {
pub version_mask: u32,
}
impl EcRequest<EcResponseGetCmdVersionsV1> for EcRequestGetCmdVersionsV1 {
fn command_id() -> EcCommands {
EcCommands::GetCmdVersions
}
fn command_version() -> u8 {
1
}
}
pub struct EcRequestFlashInfo {}
#[repr(C, packed)]
#[derive(Clone, Copy, Debug)]
pub struct EcResponseFlashInfo {
pub flash_size: u32,
pub write_block_size: u32,
pub erase_block_size: u32,
pub protect_block_size: u32,
// New fields in version 1 of the command
pub write_ideal_size: u32,
pub flags: u32,
}
impl EcRequest<EcResponseFlashInfo> for EcRequestFlashInfo {
fn command_version() -> u8 {
1
}
fn command_id() -> EcCommands {
EcCommands::FlashInfo
}
}
pub struct EcRequestFlashRead {
pub offset: u32,
pub size: u32,
}
impl EcRequest<()> for EcRequestFlashRead {
fn command_id() -> EcCommands {
EcCommands::FlashRead
}
}
#[repr(C, packed)]
pub struct EcRequestFlashWrite {
pub offset: u32,
pub size: u32,
/// Dynamically sized array (data copied after this struct)
pub data: [u8; 0],
}
impl EcRequest<()> for EcRequestFlashWrite {
fn command_id() -> EcCommands {
EcCommands::FlashWrite
}
}
#[repr(C, packed)]
pub struct EcRequestFlashErase {
pub offset: u32,
pub size: u32,
}
impl EcRequest<()> for EcRequestFlashErase {
fn command_id() -> EcCommands {
EcCommands::FlashErase
}
}
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum FlashProtectFlags {
ProtectRoAtBoot = 1 << 0,
ProtectRoNow = 1 << 1,
ProtectAllNow = 1 << 2,
ProtectGpioAsserted = 1 << 3,
/// At least one flash bank is stuck and can't be unlocked
ErrorStruck = 1 << 4,
ErrorInconsistent = 1 << 5,
ProtectAllAtBoot = 1 << 6,
}
#[repr(C, packed)]
pub struct EcRequestFlashProtect {
pub mask: u32,
pub flags: u32,
}
pub struct EcResponseFlashProtect {
/// Current flash protect flags
pub flags: u32,
/// Flags that are valid on this platform
pub valid_flags: u32,
/// Flags that can be currently written (depending on protection status)
pub writeable_flags: u32,
}
impl EcRequest<EcResponseFlashProtect> for EcRequestFlashProtect {
fn command_id() -> EcCommands {
EcCommands::FlashProtect
}
}
#[repr(C, packed)]
pub struct EcRequestPwmSetKeyboardBacklight {
pub percent: u8,
}
impl EcRequest<()> for EcRequestPwmSetKeyboardBacklight {
fn command_id() -> EcCommands {
EcCommands::PwmSetKeyboardBacklight
}
}
#[repr(C, packed)]
pub struct EcRequestPwmGetKeyboardBacklight {}
#[repr(C, packed)]
pub struct EcResponsePwmGetKeyboardBacklight {
pub percent: u8,
pub enabled: u8,
}
#[repr(u8)]
pub enum PwmType {
Generic = 0,
KbLight,
DisplayLight,
}
impl EcRequest<EcResponsePwmGetKeyboardBacklight> for EcRequestPwmGetKeyboardBacklight {
fn command_id() -> EcCommands {
EcCommands::PwmGetKeyboardBacklight
}
}
#[repr(C, packed)]
pub struct EcRequestPwmSetFanTargetRpmV0 {
/// Duty cycle in percent
pub rpm: u32,
}
impl EcRequest<()> for EcRequestPwmSetFanTargetRpmV0 {
fn command_id() -> EcCommands {
EcCommands::PwmSetFanTargetRpm
}
}
pub struct EcRequestPwmSetFanTargetRpmV1 {
/// Fan RPM
pub rpm: u32,
/// Fan index
pub fan_idx: u32,
}
impl EcRequest<()> for EcRequestPwmSetFanTargetRpmV1 {
fn command_id() -> EcCommands {
EcCommands::PwmSetFanTargetRpm
}
fn command_version() -> u8 {
1
}
}
#[repr(C, packed)]
pub struct EcRequestPwmSetFanDutyV0 {
/// Duty cycle in percent
pub percent: u32,
}
impl EcRequest<()> for EcRequestPwmSetFanDutyV0 {
fn command_id() -> EcCommands {
EcCommands::PwmSetFanDuty
}
}
#[repr(C, packed)]
pub struct EcRequestPwmSetFanDutyV1 {
/// Duty cycle in percent
pub percent: u32,
/// Fan index
pub fan_idx: u32,
}
impl EcRequest<()> for EcRequestPwmSetFanDutyV1 {
fn command_id() -> EcCommands {
EcCommands::PwmSetFanDuty
}
fn command_version() -> u8 {
1
}
}
pub const PWM_MAX_DUTY: u16 = 0xFFFF;
pub fn percent_to_duty(percent: u8) -> u16 {
let duty = percent as u32 * PWM_MAX_DUTY as u32;
(duty / 100) as u16
}
pub fn duty_to_percent(duty: u16) -> u8 {
let percent = duty as u32 * 100;
(percent / PWM_MAX_DUTY as u32) as u8
}
#[repr(C, packed)]
pub struct EcRequestPwmSetDuty {
/// Duty cycle, min 0, max 0xFFFF
pub duty: u16,
/// See enum PwmType
pub pwm_type: u8,
/// Type-specific index, or 0 if unique
pub index: u8,
}
impl EcRequest<()> for EcRequestPwmSetDuty {
fn command_id() -> EcCommands {
EcCommands::PwmSetDuty
}
}
#[repr(C, packed)]
pub struct EcRequestPwmGetDuty {
/// See enum PwmType
pub pwm_type: u8,
/// Type-specific index, or 0 if unique
pub index: u8,
}
#[repr(C, packed)]
pub struct EcResponsePwmGetDuty {
/// Duty cycle, min 0, max 0xFFFF
pub duty: u16,
}
impl EcRequest<EcResponsePwmGetDuty> for EcRequestPwmGetDuty {
fn command_id() -> EcCommands {
EcCommands::PwmGetDuty
}
}
#[repr(u8)]
pub enum MotionSenseCmd {
Dump = 0,
Info = 1,
}
#[repr(C, packed)]
pub struct EcRequestMotionSenseDump {
/// MotionSenseCmd::Dump
pub cmd: u8,
/// Maximal number of sensor the host is expecting.
/// 0 means the host is only interested in the number
/// of sensors controlled by the EC.
pub max_sensor_count: u8,
}
#[repr(C, packed)]
pub struct EcResponseMotionSenseDump {
/// Flags representing the motion sensor module
pub module_flags: u8,
/// Number of sensors managed directly by the EC
pub sensor_count: u8,
/// Sensor data is truncated if response_max is too small
/// for holding all the data.
pub sensor: [u8; 0],
}
impl EcRequest<EcResponseMotionSenseDump> for EcRequestMotionSenseDump {
fn command_id() -> EcCommands {
EcCommands::MotionSense
}
fn command_version() -> u8 {
1
}
}
#[derive(Debug, FromPrimitive, PartialEq)]
pub enum MotionSenseType {
Accel = 0,
Gyro = 1,
Mag = 2,
Prox = 3,
Light = 4,
Activity = 5,
Baro = 6,
Sync = 7,
LightRgb = 8,
}
#[derive(Debug, FromPrimitive)]
pub enum MotionSenseLocation {
Base = 0,
Lid = 1,
Camera = 2,
}
#[derive(Debug, FromPrimitive)]
pub enum MotionSenseChip {
Kxcj9 = 0,
Lsm6ds0 = 1,
Bmi160 = 2,
Si1141 = 3,
Si1142 = 4,
Si1143 = 5,
Kx022 = 6,
L3gd20h = 7,
Bma255 = 8,
Bmp280 = 9,
Opt3001 = 10,
Bh1730 = 11,
Gpio = 12,
Lis2dh = 13,
Lsm6dsm = 14,
Lis2de = 15,
Lis2mdl = 16,
Lsm6ds3 = 17,
Lsm6dso = 18,
Lng2dm = 19,
Tcs3400 = 20,
Lis2dw12 = 21,
Lis2dwl = 22,
Lis2ds = 23,
Bmi260 = 24,
Icm426xx = 25,
Icm42607 = 26,
Bma422 = 27,
Bmi323 = 28,
Bmi220 = 29,
Cm32183 = 30,
Veml3328 = 31,
}
#[repr(C, packed)]
pub struct EcRequestMotionSenseInfo {
/// MotionSenseCmd::Info
pub cmd: u8,
/// Sensor index
pub sensor_num: u8,
}
#[repr(C)]
pub struct EcResponseMotionSenseInfo {
/// See enum MotionSenseInfo
pub sensor_type: u8,
/// See enum MotionSenseLocation
pub location: u8,
/// See enum MotionSenseChip
pub chip: u8,
}
#[derive(Debug)]
pub struct MotionSenseInfo {
pub sensor_type: MotionSenseType,
pub location: MotionSenseLocation,
pub chip: MotionSenseChip,
}
impl EcRequest<EcResponseMotionSenseInfo> for EcRequestMotionSenseInfo {
fn command_id() -> EcCommands {
EcCommands::MotionSense
}
fn command_version() -> u8 {
1
}
}
pub enum TabletModeOverride {
Default = 0,
ForceTablet = 1,
ForceClamshell = 2,
}
#[repr(C, packed)]
pub struct EcRequestSetTabletMode {
/// See TabletModeOverride
pub mode: u8,
}
impl EcRequest<()> for EcRequestSetTabletMode {
fn command_id() -> EcCommands {
EcCommands::SetTabletMode
}
}
#[repr(C, packed)]
pub struct EcRequestAutoFanCtrlV0 {}
impl EcRequest<()> for EcRequestAutoFanCtrlV0 {
fn command_id() -> EcCommands {
EcCommands::AutoFanCtrl
}
}
#[repr(C, packed)]
pub struct EcRequestAutoFanCtrlV1 {
/// Fan id
pub fan_idx: u8,
}
impl EcRequest<()> for EcRequestAutoFanCtrlV1 {
fn command_id() -> EcCommands {
EcCommands::AutoFanCtrl
}
fn command_version() -> u8 {
1
}
}
#[repr(C, packed)]
pub struct EcRequestGpioSetV0 {
pub name: [u8; 32],
pub value: u8,
}
impl EcRequest<()> for EcRequestGpioSetV0 {
fn command_id() -> EcCommands {
EcCommands::GpioSet
}
}
#[repr(C, packed)]
pub struct EcRequestGpioGetV0 {
pub name: [u8; 32],
}
#[repr(C, packed)]
pub struct EcResponseGpioGetV0 {
pub val: u8,
}
impl EcRequest<EcResponseGpioGetV0> for EcRequestGpioGetV0 {
fn command_id() -> EcCommands {
EcCommands::GpioGet
}
fn command_version() -> u8 {
0
}
}
pub enum GpioGetSubCommand {
ByName = 0,
Count = 1,
Info = 2,
}
#[repr(C, packed)]
pub struct EcRequestGpioGetV1Count {
pub subcmd: u8,
}
#[repr(C, packed)]
pub struct EcRequestGpioGetV1ByName {
pub subcmd: u8,
pub name: [u8; 32],
}
#[repr(C, packed)]
pub struct EcRequestGpioGetV1Info {
pub subcmd: u8,
pub index: u8,
}
#[repr(C)]
pub struct EcResponseGpioGetV1Info {
pub val: u8,
pub name: [u8; 32],
pub flags: u32,
}
impl EcRequest<EcResponseGpioGetV0> for EcRequestGpioGetV1Count {
fn command_id() -> EcCommands {
EcCommands::GpioGet
}
fn command_version() -> u8 {
1
}
}
impl EcRequest<EcResponseGpioGetV0> for EcRequestGpioGetV1ByName {
fn command_id() -> EcCommands {
EcCommands::GpioGet
}
fn command_version() -> u8 {
1
}
}
impl EcRequest<EcResponseGpioGetV1Info> for EcRequestGpioGetV1Info {
fn command_id() -> EcCommands {
EcCommands::GpioGet
}
fn command_version() -> u8 {
1
}
}
#[repr(C, packed)]
pub struct EcRequestReboot {}
impl EcRequest<()> for EcRequestReboot {
fn command_id() -> EcCommands {
EcCommands::Reboot
}
}
pub struct EcRequestConsoleSnapshot {}
impl EcRequest<()> for EcRequestConsoleSnapshot {
fn command_id() -> EcCommands {
EcCommands::ConsoleSnapshot
}
}
pub enum ConsoleReadSubCommand {
ConsoleReadNext = 0,
ConsoleReadRecent = 1,
}
pub struct EcRequestConsoleRead {
pub subcmd: u8,
}
impl EcRequest<()> for EcRequestConsoleRead {
fn command_id() -> EcCommands {
EcCommands::ConsoleRead
}
fn command_version() -> u8 {
1
}
}
#[repr(u8)]
pub enum ChargeStateCmd {
GetState = 0,
GetParam,
SetParam,
NumCmds,
}
#[repr(C, packed)]
pub struct EcRequestChargeStateGetV0 {
pub cmd: u8,
pub param: u32,
}
#[repr(C, packed)]
pub struct EcResponseChargeStateGetV0 {
pub ac: u32,
pub chg_voltage: u32,
pub chg_current: u32,
pub chg_input_current: u32,
pub batt_state_of_charge: u32,
}
impl EcRequest<EcResponseChargeStateGetV0> for EcRequestChargeStateGetV0 {
fn command_id() -> EcCommands {
EcCommands::ChargeState
}
fn command_version() -> u8 {
0
}
}
pub struct EcRequestCurrentLimitV0 {
/// Current limit in mA
pub current: u32,
}
impl EcRequest<()> for EcRequestCurrentLimitV0 {
fn command_id() -> EcCommands {
EcCommands::ChargeCurrentLimit
}
}
pub struct EcRequestCurrentLimitV1 {
/// Current limit in mA
pub current: u32,
/// Battery state of charge is the minimum charge percentage at which
/// the battery charge current limit will apply.
/// When not set, the limit will apply regardless of state of charge.
pub battery_soc: u8,
}
impl EcRequest<()> for EcRequestCurrentLimitV1 {
fn command_id() -> EcCommands {
EcCommands::ChargeCurrentLimit
}
fn command_version() -> u8 {
1
}
}
#[repr(C, packed)]
pub struct EcRequesetHibernationDelay {
/// Seconds in G3 after EC turns off, 0 to read current
pub seconds: u32,
}
#[repr(C, packed)]
pub struct EcResponseHibernationDelay {
pub time_g3: u32,
pub time_remaining: u32,
/// How long to wait in G3 until turn off
pub hibernation_delay: u32,
}
impl EcRequest<EcResponseHibernationDelay> for EcRequesetHibernationDelay {
fn command_id() -> EcCommands {
EcCommands::HibernationDelay
}
}
#[repr(C, packed)]
pub struct EcRequestS0ixCounter {
/// If 0x01 then reset the counter, otherwise get it
pub flags: u32,
}
#[repr(C, packed)]
pub struct EcResponseS0ixCounter {
pub s0ix_counter: u32,
}
pub const EC_S0IX_COUNTER_RESET: u32 = 0x01;
impl EcRequest<EcResponseS0ixCounter> for EcRequestS0ixCounter {
fn command_id() -> EcCommands {
EcCommands::S0ixCounter
}
}
/// Supported features
#[derive(Debug, FromPrimitive)]
pub enum EcFeatureCode {
/// This image contains a limited set of features. Another image
/// in RW partition may support more features.
Limited = 0,
/// Commands for probing/reading/writing/erasing the flash in the
/// EC are present.
Flash = 1,
/// Can control the fan speed directly.
PwmFan = 2,
/// Can control the intensity of the keyboard backlight.
PwmKeyboardBacklight = 3,
/// Support Google lightbar, introduced on Pixel.
Lightbar = 4,
/// Control of LEDs
Led = 5,
/// Exposes an interface to control gyro and sensors.
/// The host goes through the EC to access these sensors.
/// In addition, the EC may provide composite sensors, like lid angle.
MotionSense = 6,
/// The keyboard is controlled by the EC
Keyboard = 7,
/// The AP can use part of the EC flash as persistent storage.
PersistentStorage = 8,
/// The EC monitors BIOS port 80h, and can return POST codes.
Port80 = 9,
/// Thermal management: include TMP specific commands.
/// Higher level than direct fan control.
Thermal = 10,
/// Can switch the screen backlight on/off
BacklightSwitch = 11,
/// Can switch the wifi module on/off
WifiSwitch = 12,
/// Monitor host events, through for example SMI or SCI
HostEvents = 13,
/// The EC exposes GPIO commands to control/monitor connected devices.
Gpio = 14,
/// The EC can send i2c messages to downstream devices.
I2c = 15,
/// Command to control charger are included
Charger = 16,
/// Simple battery support.
Battery = 17,
/// Support Smart battery protocol
/// (Common Smart Battery System Interface Specification)
SmartBattery = 18,
/// EC can detect when the host hangs.
HangDetect = 19,
/// Report power information, for pit only
Pmu = 20,
/// Another Cros EC device is present downstream of this one
SubMcu = 21,
/// Support USB Power delivery (PD) commands
UsbPd = 22,
/// Control USB multiplexer, for audio through USB port for instance.
UsbMux = 23,
/// Motion Sensor code has an internal software FIFO
MotionSenseFifo = 24,
/// Support temporary secure vstore
SecureVstore = 25,
/// EC decides on USB-C SS mux state, muxes configured by host
UsbcSsMuxVirtual = 26,
/// EC has RTC feature that can be controlled by host commands
Rtc = 27,
/// The MCU exposes a Fingerprint sensor
Fingerprint = 28,
/// The MCU exposes a Touchpad
Touchpad = 29,
/// The MCU has RWSIG task enabled
RwSig = 30,
/// EC has device events support
DeviceEvent = 31,
/// EC supports the unified wake masks for LPC/eSPI systems
UnifiedWakeMasks = 32,
/// EC supports 64-bit host events
HostEvent64 = 33,
/// EC runs code in RAM (not in place, a.k.a. XIP)
ExecInRam = 34,
/// EC supports CEC commands
Cec = 35,
/// EC supports tight sensor timestamping.
MotionSenseTightTimesStamps = 36,
///
/// EC supports tablet mode detection aligned to Chrome and allows
/// setting of threshold by host command using
/// MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
RefinedTabletModeHysteresis = 37,
/// Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
/// Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
/// be sent to RO to be precise.
Efs2 = 38,
/// The MCU is a System Companion Processor (SCP).
Scp = 39,
/// The MCU is an Integrated Sensor Hub
Ish = 40,
/// New TCPMv2 TYPEC_ prefaced commands supported
TypecCmd = 41,
/// The EC will wait for direction from the AP to enter Type-C alternate
/// modes or USB4.
TypecRequireApModeEntry = 42,
/// The EC will wait for an acknowledge from the AP after setting the
/// mux.
TypeCMuxRequireApAck = 43,
/// The EC supports entering and residing in S4.
S4Residency = 44,
/// The EC supports the AP directing mux sets for the board.
TypeCApMuxSet = 45,
/// The EC supports the AP composing VDMs for us to send.
TypeCApVdmSend = 46,
/// The EC supports system safe mode panic recovery.
SystemSafeMode = 47,
/// The EC will reboot on runtime assertion failures.
AssertReboots = 48,
/// The EC image is built with tokenized logging enabled.
TokenizedLogging = 49,
/// The EC supports triggering an STB dump.
AmdStbDump = 50,
/// The EC supports memory dump commands.
MemoryDump = 51,
/// The EC supports DP2.1 capability
Dp21 = 52,
/// The MCU is System Companion Processor Core 1
ScpC1 = 53,
/// The EC supports UCSI PPM.
UcsiPpm = 54,
}
pub struct EcRequestGetFeatures {}
pub struct EcResponseGetFeatures {
pub flags: [u32; 2],
}
impl EcRequest<EcResponseGetFeatures> for EcRequestGetFeatures {
fn command_id() -> EcCommands {
EcCommands::GetFeatures
}
}
#[repr(u8)]
pub enum RebootEcCmd {
/// Cancel a pending reboot
Cancel = 0,
/// Jump to RO firmware without rebooting
JumpRo = 1,
/// Jump to RW firmware without rebooting
JumpRw = 2,
/// DEPRECATED: Was jump to RW-B
DeprecatedJumpToRwB = 3,
/// Cold reboot of the EC. Causes host reset as well
ColdReboot = 4,
/// Disable jumping until the next EC reboot
DisableJump = 5,
/// Hibernate the EC
Hibernate = 6,
/// DEPRECATED: Hibernate EC and clears AP_IDLE flag.
/// Use EC_REBOOT_HIBERNATE and EC_REBOOT_FLAG_CLEAR_AP_IDLE, instead.
DeprecatedClearApOff = 7,
/// Cold-reboot and don't boot AP
ColdApOff = 8,
/// Do nothing but apply the flags
NoOp = 9,
}
#[repr(u8)]
pub enum RebootEcFlags {
/// Default
None = 0x00,
DeprecatedRecoveryRequest = 0x01,
/// Reboot after AP shutdown
OnApShutdown = 0x02,
/// Switch RW slot
SwitchRwSlot = 0x04,
/// Clear AP_IDLE flag
ClearApidle = 0x08,
}
pub struct EcRequestRebootEc {
/// See enum RebootEcCmd
pub cmd: u8,
pub flags: u8,
}
impl EcRequest<()> for EcRequestRebootEc {
fn command_id() -> EcCommands {
EcCommands::RebootEc
}
fn command_version() -> u8 {
0
}
}
#[repr(C, packed)]
pub struct EcRequestUsbPdPowerInfo {
pub port: u8,
}
#[repr(C, packed)]
pub struct _UsbChargeMeasures {
pub voltage_max: u16,
pub voltage_now: u16,
pub current_max: u16,
pub current_lim: u16,
}
#[repr(C, packed)]
pub struct EcResponseUsbPdPowerInfo {
pub role: u8, // UsbPowerRoles
pub charging_type: u8, // UsbChargingType
pub dualrole: u8, // I think this is a boolean?
pub reserved1: u8,
pub meas: _UsbChargeMeasures,
pub max_power: u32,
}
impl EcRequest<EcResponseUsbPdPowerInfo> for EcRequestUsbPdPowerInfo {
fn command_id() -> EcCommands {
EcCommands::UsbPdPowerInfo
}
}
#[repr(usize)]
#[derive(Debug, FromPrimitive)]
pub enum EcResetFlag {
/// Other known reason
Other,
/// Reset pin asserted
ResetPin,
/// Brownout
Brownout,
/// Power-on reset
PowerOn,
/// Watchdog timer reset
Watchdog,
/// Soft reset trigger by core
Soft,
/// Wake from hibernate
Hibernate,
/// RTC alarm wake
RtcAlarm,
/// Wake pin triggered wake
WakePin,
/// Low battery triggered wake
LowBattery,
/// Jumped directly to this image
Sysjump,
/// Hard reset from software
Hard,
/// Do not power on AP
APOff,
/// Some reset flags preserved from previous boot
Preserved,
/// USB resume triggered wake
UsbResume,
/// USB Type-C debug cable
Rdd,
/// Fixed Reset Functionality
Rbox,
/// Security threat
Security,
/// AP experienced a watchdog reset
ApWatchdog,
/// Do not select RW in EFS. This enables PD in RO for Chromebox
StayInRo,
/// Jumped to this image by EFS
Efs,
/// Leave alone AP
ApIdle,
/// EC had power, then was reset
InitialPwr,
Count,
}
#[repr(u16)]
#[derive(Debug, FromPrimitive)]
pub enum ResetCause {
ResetUnknown = 0x0000,
/// Custom reason defined by a board.c or baseboard.c file
ResetBoardCustom,
/// Believe that the AP has hung
ResetHangReboot,
/// Reset by EC console command
ResetConsoleCommand,
/// Reset by EC host command
ResetHostCommand,
/// Keyboard module reset key combination
ResetKeyboardSysReset,
/// Keyboard module warm reboot
ResetKeyboardWarmBoot,
/// Debug module warm reboot
ResetDebugWarmBoot,
/// I cannot self-terminate. You must lower me into the steel
ResetApReq,
/// Reset as side-effect of startup sequence
ResetInit,
/// EC detected an AP watchdog event
ResetApWatchdog,
ShutdownPowerFail = 0x8000,
/// Forcing a shutdown as part of EC initialization
ShutdownInit,
/// Custom reason on a per-board basis.
ShutdownBoardCustom,
/// This is a reason to inhibit startup, not cause shut down.
ShutdownBatteryInhibit,
/// A power_wait_signal is being asserted
ShutdownWait,
/// Critical battery level.
ShutdownBatteryCritical,
/// Because you told me to.
ShutdownConsoleCommand,
/// Forcing a shutdown to effect entry to G3.
ShutdownG3,
/// Force shutdown due to over-temperature.
ShutdownThermal,