From 96b7fcce39b4dfefbf401139bc3bf13568cf1ab4 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Mon, 5 May 2025 11:42:54 +0800 Subject: [PATCH] Don't require PD config if platform isn't detected Now even if the platform isn't detected, we can run the commands just fine. For example both of these work (if I comment out the smbios entry): ``` framework_tool --versions framework_tool --versions --pd-ports 1 2 --pd-addrs 66 64 ``` The first one just fails accessing I2C passthrough for the PD ports. This is the final change to allow just running the tool on any system in as many cases as possible - even if the linux kernel or framework_tool dose not recognize the system. Signed-off-by: Daniel Schaefer --- framework_lib/src/ccgx/device.rs | 24 +++++++++++++----------- framework_lib/src/smbios.rs | 9 ++++++--- framework_lib/src/util.rs | 2 ++ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/framework_lib/src/ccgx/device.rs b/framework_lib/src/ccgx/device.rs index 3163f082..532ad10e 100644 --- a/framework_lib/src/ccgx/device.rs +++ b/framework_lib/src/ccgx/device.rs @@ -30,11 +30,11 @@ pub enum PdPort { impl PdPort { /// SMBUS/I2C Address - fn i2c_address(&self) -> u16 { + fn i2c_address(&self) -> EcResult { let config = Config::get(); let platform = &(*config).as_ref().unwrap().platform; - match (platform, self) { + Ok(match (platform, self) { (Platform::GenericFramework((left, _), _), PdPort::Left01) => *left, (Platform::GenericFramework((_, right), _), PdPort::Right23) => *right, // Framework AMD Platforms (CCG8) @@ -52,10 +52,13 @@ impl PdPort { ) => 0x40, // TODO: It only has a single PD controller (Platform::FrameworkDesktopAmdAiMax300, _) => 0x08, + (Platform::UnknownSystem, _) => { + Err(EcError::DeviceError("Unsupported platform".to_string()))? + } // Framework Intel Platforms (CCG5 and CCG6) (_, PdPort::Left01) => 0x08, (_, PdPort::Right23) => 0x40, - } + }) } /// I2C port on the EC @@ -87,10 +90,9 @@ impl PdPort { ) => 2, // TODO: It only has a single PD controller (Platform::FrameworkDesktopAmdAiMax300, _) => 1, - // (_, _) => Err(EcError::DeviceError(format!( - // "Unsupported platform: {:?} {:?}", - // platform, self - // )))?, + (Platform::UnknownSystem, _) => { + Err(EcError::DeviceError("Unsupported platform".to_string()))? + } }) } } @@ -140,13 +142,13 @@ impl PdController { fn i2c_read(&self, addr: u16, len: u16) -> EcResult { trace!( "I2C passthrough from I2C Port {} to I2C Addr {}", - self.port.i2c_port().unwrap(), - self.port.i2c_address() + self.port.i2c_port()?, + self.port.i2c_address()? ); i2c_read( &self.ec, - self.port.i2c_port().unwrap(), - self.port.i2c_address(), + self.port.i2c_port()?, + self.port.i2c_address()?, addr, len, ) diff --git a/framework_lib/src/smbios.rs b/framework_lib/src/smbios.rs index 1345b396..83190bd4 100644 --- a/framework_lib/src/smbios.rs +++ b/framework_lib/src/smbios.rs @@ -46,7 +46,7 @@ pub enum ConfigDigit0 { pub fn is_framework() -> bool { if matches!( get_platform(), - Some(Platform::GenericFramework((_, _), (_, _))) + Some(Platform::GenericFramework((_, _), (_, _))) | Some(Platform::UnknownSystem) ) { return true; } @@ -252,7 +252,10 @@ pub fn get_platform() -> Option { // Except if it's a GenericFramework platform let config = Config::get(); let platform = &(*config).as_ref().unwrap().platform; - if matches!(platform, Platform::GenericFramework((_, _), (_, _))) { + if matches!( + platform, + Platform::GenericFramework((_, _), (_, _)) | Platform::UnknownSystem + ) { return Some(*platform); } } @@ -270,7 +273,7 @@ pub fn get_platform() -> Option { "Laptop 13 (Intel Core Ultra Series 1)" => Some(Platform::IntelCoreUltra1), "Laptop 16 (AMD Ryzen 7040 Series)" => Some(Platform::Framework16Amd7080), "Desktop (AMD Ryzen AI Max 300 Series)" => Some(Platform::FrameworkDesktopAmdAiMax300), - _ => None, + _ => Some(Platform::UnknownSystem), }; if let Some(platform) = platform { diff --git a/framework_lib/src/util.rs b/framework_lib/src/util.rs index 972d82a3..1aeb765e 100644 --- a/framework_lib/src/util.rs +++ b/framework_lib/src/util.rs @@ -38,6 +38,7 @@ pub enum Platform { /// Generic Framework device /// pd_addrs, pd_ports GenericFramework((u16, u16), (u8, u8)), + UnknownSystem, } #[derive(Debug, PartialEq, Clone, Copy)] @@ -61,6 +62,7 @@ impl Platform { Platform::Framework16Amd7080 => Some(PlatformFamily::Framework16), Platform::FrameworkDesktopAmdAiMax300 => Some(PlatformFamily::FrameworkDesktop), Platform::GenericFramework(..) => None, + Platform::UnknownSystem => None, } } }