Skip to content

Commit

Permalink
add commands to read/write gpu serial
Browse files Browse the repository at this point in the history
Signed-off-by: Kieran Levin <[email protected]>
  • Loading branch information
kiram9 committed Nov 1, 2023
1 parent 999b271 commit 42543f8
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
4 changes: 4 additions & 0 deletions framework_lib/src/chromium_ec/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ pub enum EcCommands {
ExpansionBayStatus = 0x3E1B,
/// Get hardware diagnostics
GetHwDiag = 0x3E1C,
/// Get gpu bay serial
GetGpuSerial = 0x3E1D,
/// Set gpu bay serial and program structure
SetGpuSerial = 0x3E1F,
}

pub trait EcRequest<R> {
Expand Down
48 changes: 48 additions & 0 deletions framework_lib/src/chromium_ec/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,51 @@ impl EcRequest<EcResponseFpLedLevelControl> for EcRequestFpLedLevelControl {
EcCommands::FpLedLevelControl
}
}


#[repr(C, packed)]
pub struct EcRequestGetGpuSerial {
pub idx: u8,
}

#[repr(C, packed)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct EcResponseGetGpuSerial {
pub idx: u8,
pub valid: u8,
pub serial: [u8; 20]
}

impl EcRequest<EcResponseGetGpuSerial> for EcRequestGetGpuSerial {
fn command_id() -> EcCommands {
EcCommands::GetGpuSerial
}
}

#[repr(u8)]
pub enum SetGpuSerialMagic {
/// Disable all settings, handled automatically
WriteGPUConfig = 0x0D,
/// Set maxiumum and minimum percentage
WriteSSDConfig = 0x55,
}


#[repr(C, packed)]
pub struct EcRequestSetGpuSerial {
pub magic: u8,
pub idx: u8,
pub serial: [u8; 20]
}

#[repr(C, packed)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct EcResponseSetGpuSerial {
pub valid: u8
}

impl EcRequest<EcResponseSetGpuSerial> for EcRequestSetGpuSerial {
fn command_id() -> EcCommands {
EcCommands::SetGpuSerial
}
}
28 changes: 27 additions & 1 deletion framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl CrosEc {
/// Check the current brightness of the keyboard backlight
///
pub fn get_keyboard_backlight(&self) -> EcResult<u8> {
let kblight = EcRequestPwmGetKeyboardBacklight {}.send_command(self)?;
let kblight: EcResponsePwmGetKeyboardBacklight = EcRequestPwmGetKeyboardBacklight {}.send_command(self)?;

// The enabled field is deprecated and must always be 1
debug_assert_eq!(kblight.enabled, 1);
Expand All @@ -353,6 +353,32 @@ impl CrosEc {
Ok(kblight.percent)
}

/// Get the GPU Serial
///
pub fn get_gpu_serial(&self) -> EcResult<String> {
let gpuserial: EcResponseGetGpuSerial = EcRequestGetGpuSerial {idx: 0}.send_command(self)?;
let serial: String = String::from_utf8(gpuserial.serial.to_vec()).unwrap();

if gpuserial.valid == 0 {
println!("no valid gpu serial");
return Ok(serial);
}
return Ok(serial);
}

/// Set the GPU Serial
///
/// # Arguments
/// `newserial` - a string that is 18 characters long
pub fn set_gpu_serial(&self, newserial: String) {
let response = EcRequestSetGpuSerial {
magic: SetGpuSerialMagic::WriteGPUConfig as u8,
idx: 0,
serial: newserial.as_bytes().try_into().unwrap(),
}
.send_command(self);
}

/// Requests recent console output from EC and constantly asks for more
/// Prints the output and returns it when an error is encountered
pub fn console_read(&self) -> EcResult<String> {
Expand Down

0 comments on commit 42543f8

Please sign in to comment.