1
1
//! Interact with Infineon (formerly Cypress) PD controllers (their firmware binaries) in the CCGx series
2
2
3
+ use alloc:: string:: String ;
4
+ use alloc:: string:: ToString ;
3
5
#[ cfg( feature = "uefi" ) ]
4
6
use core:: prelude:: rust_2021:: derive;
5
7
use num_derive:: FromPrimitive ;
6
8
use std:: fmt;
7
9
8
10
use crate :: chromium_ec:: { CrosEc , EcResult } ;
11
+ use crate :: smbios;
12
+ use crate :: util:: Platform ;
9
13
10
14
use self :: device:: { FwMode , PdController , PdPort } ;
11
15
@@ -102,7 +106,7 @@ pub enum SiliconId {
102
106
Ccg8 = 0x3580 ,
103
107
}
104
108
105
- #[ derive( Debug , PartialEq ) ]
109
+ #[ derive( Debug , PartialEq , Copy , Clone ) ]
106
110
pub struct BaseVersion {
107
111
/// Major part of the version. X of X.Y.Z.BB
108
112
pub major : u8 ,
@@ -138,15 +142,15 @@ impl From<u32> for BaseVersion {
138
142
}
139
143
}
140
144
141
- #[ derive( Debug , PartialEq ) ]
145
+ #[ derive( Debug , PartialEq , Copy , Clone ) ]
142
146
pub enum Application {
143
147
Notebook ,
144
148
Monitor ,
145
149
AA ,
146
150
Invalid ,
147
151
}
148
152
149
- #[ derive( Debug , PartialEq ) ]
153
+ #[ derive( Debug , PartialEq , Copy , Clone ) ]
150
154
pub struct AppVersion {
151
155
pub application : Application ,
152
156
/// Major part of the version. X of X.Y.Z
@@ -185,7 +189,7 @@ impl From<u32> for AppVersion {
185
189
}
186
190
}
187
191
188
- #[ derive( Debug , PartialEq ) ]
192
+ #[ derive( Debug , PartialEq , Copy , Clone ) ]
189
193
pub struct ControllerVersion {
190
194
pub base : BaseVersion ,
191
195
pub app : AppVersion ,
@@ -199,6 +203,26 @@ pub struct ControllerFirmwares {
199
203
pub main_fw : ControllerVersion ,
200
204
}
201
205
206
+ impl ControllerFirmwares {
207
+ pub fn active_fw ( & self ) -> ControllerVersion {
208
+ match self . active_fw {
209
+ FwMode :: MainFw => self . main_fw ,
210
+ FwMode :: BackupFw => self . backup_fw ,
211
+ FwMode :: BootLoader => self . bootloader ,
212
+ }
213
+ }
214
+
215
+ pub fn active_fw_ver ( & self ) -> String {
216
+ let active = self . active_fw ( ) ;
217
+ // On 11th Gen we modified base version instead of app version
218
+ if let Some ( Platform :: IntelGen11 ) = smbios:: get_platform ( ) {
219
+ active. base . to_string ( )
220
+ } else {
221
+ active. app . to_string ( )
222
+ }
223
+ }
224
+ }
225
+
202
226
#[ derive( Debug , PartialEq ) ]
203
227
pub struct PdVersions {
204
228
pub controller01 : ControllerFirmwares ,
0 commit comments