11//! Interact with Infineon (formerly Cypress) PD controllers (their firmware binaries) in the CCGx series
22
3+ use alloc:: string:: String ;
4+ use alloc:: string:: ToString ;
35#[ cfg( feature = "uefi" ) ]
46use core:: prelude:: rust_2021:: derive;
57use num_derive:: FromPrimitive ;
68use std:: fmt;
79
810use crate :: chromium_ec:: { CrosEc , EcResult } ;
11+ use crate :: smbios;
12+ use crate :: util:: Platform ;
913
1014use self :: device:: { FwMode , PdController , PdPort } ;
1115
@@ -102,7 +106,7 @@ pub enum SiliconId {
102106 Ccg8 = 0x3580 ,
103107}
104108
105- #[ derive( Debug , PartialEq ) ]
109+ #[ derive( Debug , PartialEq , Copy , Clone ) ]
106110pub struct BaseVersion {
107111 /// Major part of the version. X of X.Y.Z.BB
108112 pub major : u8 ,
@@ -138,15 +142,15 @@ impl From<u32> for BaseVersion {
138142 }
139143}
140144
141- #[ derive( Debug , PartialEq ) ]
145+ #[ derive( Debug , PartialEq , Copy , Clone ) ]
142146pub enum Application {
143147 Notebook ,
144148 Monitor ,
145149 AA ,
146150 Invalid ,
147151}
148152
149- #[ derive( Debug , PartialEq ) ]
153+ #[ derive( Debug , PartialEq , Copy , Clone ) ]
150154pub struct AppVersion {
151155 pub application : Application ,
152156 /// Major part of the version. X of X.Y.Z
@@ -185,7 +189,7 @@ impl From<u32> for AppVersion {
185189 }
186190}
187191
188- #[ derive( Debug , PartialEq ) ]
192+ #[ derive( Debug , PartialEq , Copy , Clone ) ]
189193pub struct ControllerVersion {
190194 pub base : BaseVersion ,
191195 pub app : AppVersion ,
@@ -199,6 +203,26 @@ pub struct ControllerFirmwares {
199203 pub main_fw : ControllerVersion ,
200204}
201205
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+
202226#[ derive( Debug , PartialEq ) ]
203227pub struct PdVersions {
204228 pub controller01 : ControllerFirmwares ,
0 commit comments