Skip to content

Commit 770914c

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

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

framework_lib/src/chromium_ec/command.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ pub enum EcCommands {
105105
GetGpuPcie = 0x3E1E,
106106
/// Set gpu bay serial and program structure
107107
ProgramGpuEeprom = 0x3E1F,
108+
/// Read board ID of specific ADC channel
109+
ReadBoardId = 0x3E26,
108110
}
109111

110112
pub trait EcRequest<R> {

framework_lib/src/chromium_ec/commands.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,3 +1468,22 @@ impl EcRequest<EcResponseSetGpuSerial> for EcRequestSetGpuSerial {
14681468
EcCommands::ProgramGpuEeprom
14691469
}
14701470
}
1471+
1472+
#[repr(C, packed)]
1473+
pub struct EcRequestReadBoardId {
1474+
/// ADC Channel, specific to each mainboard schematic
1475+
pub adc_channel: u8,
1476+
}
1477+
1478+
#[repr(C, packed)]
1479+
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
1480+
pub struct EcResponseReadBoardId {
1481+
/// Board ID (-1 invalid, 15 not present)
1482+
pub board_id: i8,
1483+
}
1484+
1485+
impl EcRequest<EcResponseReadBoardId> for EcRequestReadBoardId {
1486+
fn command_id() -> EcCommands {
1487+
EcCommands::ReadBoardId
1488+
}
1489+
}

framework_lib/src/chromium_ec/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,22 @@ impl CrosEc {
15871587
}
15881588
Ok(())
15891589
}
1590+
1591+
pub fn read_board_id_hc(&self, adc_channel: u8) -> EcResult<Option<u8>> {
1592+
let res = EcRequestReadBoardId { adc_channel }.send_command(self)?;
1593+
match res.board_id {
1594+
-1 => Err(EcError::DeviceError(format!(
1595+
"Failed to read ADC channel {}",
1596+
adc_channel
1597+
))),
1598+
15 => Ok(None),
1599+
0..=14 => Ok(Some(res.board_id as u8)),
1600+
n => Err(EcError::DeviceError(format!(
1601+
"Invalid ID to read ADC channel {}",
1602+
n
1603+
))),
1604+
}
1605+
}
15901606
}
15911607

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

0 commit comments

Comments
 (0)