Skip to content

Commit 96b7fcc

Browse files
committed
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 <[email protected]>
1 parent 58960fa commit 96b7fcc

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

framework_lib/src/ccgx/device.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ pub enum PdPort {
3030

3131
impl PdPort {
3232
/// SMBUS/I2C Address
33-
fn i2c_address(&self) -> u16 {
33+
fn i2c_address(&self) -> EcResult<u16> {
3434
let config = Config::get();
3535
let platform = &(*config).as_ref().unwrap().platform;
3636

37-
match (platform, self) {
37+
Ok(match (platform, self) {
3838
(Platform::GenericFramework((left, _), _), PdPort::Left01) => *left,
3939
(Platform::GenericFramework((_, right), _), PdPort::Right23) => *right,
4040
// Framework AMD Platforms (CCG8)
@@ -52,10 +52,13 @@ impl PdPort {
5252
) => 0x40,
5353
// TODO: It only has a single PD controller
5454
(Platform::FrameworkDesktopAmdAiMax300, _) => 0x08,
55+
(Platform::UnknownSystem, _) => {
56+
Err(EcError::DeviceError("Unsupported platform".to_string()))?
57+
}
5558
// Framework Intel Platforms (CCG5 and CCG6)
5659
(_, PdPort::Left01) => 0x08,
5760
(_, PdPort::Right23) => 0x40,
58-
}
61+
})
5962
}
6063

6164
/// I2C port on the EC
@@ -87,10 +90,9 @@ impl PdPort {
8790
) => 2,
8891
// TODO: It only has a single PD controller
8992
(Platform::FrameworkDesktopAmdAiMax300, _) => 1,
90-
// (_, _) => Err(EcError::DeviceError(format!(
91-
// "Unsupported platform: {:?} {:?}",
92-
// platform, self
93-
// )))?,
93+
(Platform::UnknownSystem, _) => {
94+
Err(EcError::DeviceError("Unsupported platform".to_string()))?
95+
}
9496
})
9597
}
9698
}
@@ -140,13 +142,13 @@ impl PdController {
140142
fn i2c_read(&self, addr: u16, len: u16) -> EcResult<EcI2cPassthruResponse> {
141143
trace!(
142144
"I2C passthrough from I2C Port {} to I2C Addr {}",
143-
self.port.i2c_port().unwrap(),
144-
self.port.i2c_address()
145+
self.port.i2c_port()?,
146+
self.port.i2c_address()?
145147
);
146148
i2c_read(
147149
&self.ec,
148-
self.port.i2c_port().unwrap(),
149-
self.port.i2c_address(),
150+
self.port.i2c_port()?,
151+
self.port.i2c_address()?,
150152
addr,
151153
len,
152154
)

framework_lib/src/smbios.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub enum ConfigDigit0 {
4646
pub fn is_framework() -> bool {
4747
if matches!(
4848
get_platform(),
49-
Some(Platform::GenericFramework((_, _), (_, _)))
49+
Some(Platform::GenericFramework((_, _), (_, _))) | Some(Platform::UnknownSystem)
5050
) {
5151
return true;
5252
}
@@ -252,7 +252,10 @@ pub fn get_platform() -> Option<Platform> {
252252
// Except if it's a GenericFramework platform
253253
let config = Config::get();
254254
let platform = &(*config).as_ref().unwrap().platform;
255-
if matches!(platform, Platform::GenericFramework((_, _), (_, _))) {
255+
if matches!(
256+
platform,
257+
Platform::GenericFramework((_, _), (_, _)) | Platform::UnknownSystem
258+
) {
256259
return Some(*platform);
257260
}
258261
}
@@ -270,7 +273,7 @@ pub fn get_platform() -> Option<Platform> {
270273
"Laptop 13 (Intel Core Ultra Series 1)" => Some(Platform::IntelCoreUltra1),
271274
"Laptop 16 (AMD Ryzen 7040 Series)" => Some(Platform::Framework16Amd7080),
272275
"Desktop (AMD Ryzen AI Max 300 Series)" => Some(Platform::FrameworkDesktopAmdAiMax300),
273-
_ => None,
276+
_ => Some(Platform::UnknownSystem),
274277
};
275278

276279
if let Some(platform) = platform {

framework_lib/src/util.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub enum Platform {
3838
/// Generic Framework device
3939
/// pd_addrs, pd_ports
4040
GenericFramework((u16, u16), (u8, u8)),
41+
UnknownSystem,
4142
}
4243

4344
#[derive(Debug, PartialEq, Clone, Copy)]
@@ -61,6 +62,7 @@ impl Platform {
6162
Platform::Framework16Amd7080 => Some(PlatformFamily::Framework16),
6263
Platform::FrameworkDesktopAmdAiMax300 => Some(PlatformFamily::FrameworkDesktop),
6364
Platform::GenericFramework(..) => None,
65+
Platform::UnknownSystem => None,
6466
}
6567
}
6668
}

0 commit comments

Comments
 (0)