Skip to content

Commit 7afea73

Browse files
committed
chromium_ec: Add host command to read board ID
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 7b67f0c commit 7afea73

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

framework_lib/src/chromium_ec/command.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ pub enum EcCommands {
107107
GetGpuPcie = 0x3E1E,
108108
/// Set gpu bay serial and program structure
109109
ProgramGpuEeprom = 0x3E1F,
110+
/// Read board ID of specific ADC channel
111+
ReadBoardId = 0x3E26,
110112
}
111113

112114
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
@@ -1501,3 +1501,39 @@ impl EcRequest<EcResponseSetGpuSerial> for EcRequestSetGpuSerial {
15011501
EcCommands::ProgramGpuEeprom
15021502
}
15031503
}
1504+
1505+
#[repr(u8)]
1506+
#[derive(Debug, Clone, Copy)]
1507+
pub enum BoardIdType {
1508+
/// Mainboard - any system
1509+
Mainboard = 0,
1510+
/// Power button board - Framework 12
1511+
PowerButtonBoard = 1,
1512+
/// Touchpad - Framework 12, 13, 16
1513+
Touchpad = 2,
1514+
/// Audio Board - Framework 12, 13
1515+
AudioBoard = 3,
1516+
/// dGPU board - Framework 16
1517+
DGpu0 = 4,
1518+
/// dGPU board - Framework 16
1519+
DGpu1 = 5,
1520+
}
1521+
1522+
#[repr(C, packed)]
1523+
pub struct EcRequestReadBoardId {
1524+
/// See BoardIdType
1525+
pub board_id_type: u8,
1526+
}
1527+
1528+
#[repr(C, packed)]
1529+
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
1530+
pub struct EcResponseReadBoardId {
1531+
/// Board ID (-1 invalid, 15 not present)
1532+
pub board_id: i8,
1533+
}
1534+
1535+
impl EcRequest<EcResponseReadBoardId> for EcRequestReadBoardId {
1536+
fn command_id() -> EcCommands {
1537+
EcCommands::ReadBoardId
1538+
}
1539+
}

framework_lib/src/chromium_ec/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,22 @@ impl CrosEc {
16481648
}
16491649
Ok(())
16501650
}
1651+
1652+
pub fn read_board_id_hc(&self, board_id_type: BoardIdType) -> EcResult<Option<u8>> {
1653+
let res = EcRequestReadBoardId {
1654+
board_id_type: board_id_type as u8,
1655+
}
1656+
.send_command(self)?;
1657+
match res.board_id {
1658+
-1 => Err(EcError::DeviceError(format!(
1659+
"Failed to read Board ID {:?}",
1660+
board_id_type
1661+
))),
1662+
15 => Ok(None),
1663+
0..=14 => Ok(Some(res.board_id as u8)),
1664+
n => Err(EcError::DeviceError(format!("Invalid Board ID {}", n))),
1665+
}
1666+
}
16511667
}
16521668

16531669
#[cfg_attr(not(feature = "uefi"), derive(clap::ValueEnum))]

0 commit comments

Comments
 (0)