Skip to content

Commit 42543f8

Browse files
committed
add commands to read/write gpu serial
Signed-off-by: Kieran Levin <[email protected]>
1 parent 999b271 commit 42543f8

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

framework_lib/src/chromium_ec/command.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ pub enum EcCommands {
6767
ExpansionBayStatus = 0x3E1B,
6868
/// Get hardware diagnostics
6969
GetHwDiag = 0x3E1C,
70+
/// Get gpu bay serial
71+
GetGpuSerial = 0x3E1D,
72+
/// Set gpu bay serial and program structure
73+
SetGpuSerial = 0x3E1F,
7074
}
7175

7276
pub trait EcRequest<R> {

framework_lib/src/chromium_ec/commands.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,51 @@ impl EcRequest<EcResponseFpLedLevelControl> for EcRequestFpLedLevelControl {
489489
EcCommands::FpLedLevelControl
490490
}
491491
}
492+
493+
494+
#[repr(C, packed)]
495+
pub struct EcRequestGetGpuSerial {
496+
pub idx: u8,
497+
}
498+
499+
#[repr(C, packed)]
500+
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
501+
pub struct EcResponseGetGpuSerial {
502+
pub idx: u8,
503+
pub valid: u8,
504+
pub serial: [u8; 20]
505+
}
506+
507+
impl EcRequest<EcResponseGetGpuSerial> for EcRequestGetGpuSerial {
508+
fn command_id() -> EcCommands {
509+
EcCommands::GetGpuSerial
510+
}
511+
}
512+
513+
#[repr(u8)]
514+
pub enum SetGpuSerialMagic {
515+
/// Disable all settings, handled automatically
516+
WriteGPUConfig = 0x0D,
517+
/// Set maxiumum and minimum percentage
518+
WriteSSDConfig = 0x55,
519+
}
520+
521+
522+
#[repr(C, packed)]
523+
pub struct EcRequestSetGpuSerial {
524+
pub magic: u8,
525+
pub idx: u8,
526+
pub serial: [u8; 20]
527+
}
528+
529+
#[repr(C, packed)]
530+
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
531+
pub struct EcResponseSetGpuSerial {
532+
pub valid: u8
533+
}
534+
535+
impl EcRequest<EcResponseSetGpuSerial> for EcRequestSetGpuSerial {
536+
fn command_id() -> EcCommands {
537+
EcCommands::SetGpuSerial
538+
}
539+
}

framework_lib/src/chromium_ec/mod.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ impl CrosEc {
342342
/// Check the current brightness of the keyboard backlight
343343
///
344344
pub fn get_keyboard_backlight(&self) -> EcResult<u8> {
345-
let kblight = EcRequestPwmGetKeyboardBacklight {}.send_command(self)?;
345+
let kblight: EcResponsePwmGetKeyboardBacklight = EcRequestPwmGetKeyboardBacklight {}.send_command(self)?;
346346

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

356+
/// Get the GPU Serial
357+
///
358+
pub fn get_gpu_serial(&self) -> EcResult<String> {
359+
let gpuserial: EcResponseGetGpuSerial = EcRequestGetGpuSerial {idx: 0}.send_command(self)?;
360+
let serial: String = String::from_utf8(gpuserial.serial.to_vec()).unwrap();
361+
362+
if gpuserial.valid == 0 {
363+
println!("no valid gpu serial");
364+
return Ok(serial);
365+
}
366+
return Ok(serial);
367+
}
368+
369+
/// Set the GPU Serial
370+
///
371+
/// # Arguments
372+
/// `newserial` - a string that is 18 characters long
373+
pub fn set_gpu_serial(&self, newserial: String) {
374+
let response = EcRequestSetGpuSerial {
375+
magic: SetGpuSerialMagic::WriteGPUConfig as u8,
376+
idx: 0,
377+
serial: newserial.as_bytes().try_into().unwrap(),
378+
}
379+
.send_command(self);
380+
}
381+
356382
/// Requests recent console output from EC and constantly asks for more
357383
/// Prints the output and returns it when an error is encountered
358384
pub fn console_read(&self) -> EcResult<String> {

0 commit comments

Comments
 (0)