Skip to content

Commit 526ba80

Browse files
Merge pull request #129 from FrameworkComputer/generic-pd
Don't require PD config if platform isn't detected
2 parents 5ab173b + 96b7fcc commit 526ba80

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
@@ -47,7 +47,7 @@ pub enum ConfigDigit0 {
4747
pub fn is_framework() -> bool {
4848
if matches!(
4949
get_platform(),
50-
Some(Platform::GenericFramework((_, _), (_, _)))
50+
Some(Platform::GenericFramework((_, _), (_, _))) | Some(Platform::UnknownSystem)
5151
) {
5252
return true;
5353
}
@@ -286,7 +286,10 @@ pub fn get_platform() -> Option<Platform> {
286286
// Except if it's a GenericFramework platform
287287
let config = Config::get();
288288
let platform = &(*config).as_ref().unwrap().platform;
289-
if matches!(platform, Platform::GenericFramework((_, _), (_, _))) {
289+
if matches!(
290+
platform,
291+
Platform::GenericFramework((_, _), (_, _)) | Platform::UnknownSystem
292+
) {
290293
return Some(*platform);
291294
}
292295
}
@@ -304,7 +307,7 @@ pub fn get_platform() -> Option<Platform> {
304307
"Laptop 13 (Intel Core Ultra Series 1)" => Some(Platform::IntelCoreUltra1),
305308
"Laptop 16 (AMD Ryzen 7040 Series)" => Some(Platform::Framework16Amd7080),
306309
"Desktop (AMD Ryzen AI Max 300 Series)" => Some(Platform::FrameworkDesktopAmdAiMax300),
307-
_ => None,
310+
_ => Some(Platform::UnknownSystem),
308311
};
309312

310313
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)