Skip to content

Commit be57edb

Browse files
committed
chromium_ec: Add host command to read board ID
This command is not present on all systems, it was only recently added to our main branch and will be slowly backported. Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 6fa32d5 commit be57edb

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

framework_lib/src/chromium_ec/command.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ pub enum EcCommands {
110110
GetGpuPcie = 0x3E1E,
111111
/// Set gpu bay serial and program structure
112112
ProgramGpuEeprom = 0x3E1F,
113+
/// Read board ID of specific ADC channel
114+
ReadBoardId = 0x3E26,
113115
}
114116

115117
pub trait EcRequest<R> {

framework_lib/src/chromium_ec/commands.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,3 +1658,39 @@ impl EcRequest<EcResponseSetGpuSerial> for EcRequestSetGpuSerial {
16581658
EcCommands::ProgramGpuEeprom
16591659
}
16601660
}
1661+
1662+
#[repr(u8)]
1663+
#[derive(Debug, Clone, Copy)]
1664+
pub enum BoardIdType {
1665+
/// Mainboard - any system
1666+
Mainboard = 0,
1667+
/// Power button board - Framework 12
1668+
PowerButtonBoard = 1,
1669+
/// Touchpad - Framework 12, 13, 16
1670+
Touchpad = 2,
1671+
/// Audio Board - Framework 12, 13
1672+
AudioBoard = 3,
1673+
/// dGPU board - Framework 16
1674+
DGpu0 = 4,
1675+
/// dGPU board - Framework 16
1676+
DGpu1 = 5,
1677+
}
1678+
1679+
#[repr(C, packed)]
1680+
pub struct EcRequestReadBoardId {
1681+
/// See BoardIdType
1682+
pub board_id_type: u8,
1683+
}
1684+
1685+
#[repr(C, packed)]
1686+
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
1687+
pub struct EcResponseReadBoardId {
1688+
/// Board ID: -1 invalid, 0–14 valid, 15 not present
1689+
pub board_id: i8,
1690+
}
1691+
1692+
impl EcRequest<EcResponseReadBoardId> for EcRequestReadBoardId {
1693+
fn command_id() -> EcCommands {
1694+
EcCommands::ReadBoardId
1695+
}
1696+
}

framework_lib/src/chromium_ec/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,22 @@ impl CrosEc {
17431743
Ok(())
17441744
}
17451745

1746+
pub fn read_board_id_hc(&self, board_id_type: BoardIdType) -> EcResult<Option<u8>> {
1747+
let res = EcRequestReadBoardId {
1748+
board_id_type: board_id_type as u8,
1749+
}
1750+
.send_command(self)?;
1751+
match res.board_id {
1752+
-1 => Err(EcError::DeviceError(format!(
1753+
"Failed to read Board ID {:?}",
1754+
board_id_type
1755+
))),
1756+
15 => Ok(None),
1757+
0..=14 => Ok(Some(res.board_id as u8)),
1758+
n => Err(EcError::DeviceError(format!("Invalid Board ID {}", n))),
1759+
}
1760+
}
1761+
17461762
pub fn get_uptime_info(&self) -> EcResult<()> {
17471763
let res = EcRequestGetUptimeInfo {}.send_command(self)?;
17481764
let t_since_boot = Duration::from_millis(res.time_since_ec_boot.into());

0 commit comments

Comments
 (0)