Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions framework_lib/src/chromium_ec/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum EcCommands {
PwmGetDuty = 0x0026,
SetTabletMode = 0x0031,
AutoFanCtrl = 0x0052,
GpioSet = 0x0092,
GpioGet = 0x0093,
I2cPassthrough = 0x009e,
ConsoleSnapshot = 0x0097,
Expand Down
12 changes: 12 additions & 0 deletions framework_lib/src/chromium_ec/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,18 @@ impl EcRequest<()> for EcRequestAutoFanCtrlV1 {
}
}

#[repr(C, packed)]
pub struct EcRequestGpioSetV0 {
pub name: [u8; 32],
pub value: u8,
}

impl EcRequest<()> for EcRequestGpioSetV0 {
fn command_id() -> EcCommands {
EcCommands::GpioSet
}
}

#[repr(C, packed)]
pub struct EcRequestGpioGetV0 {
pub name: [u8; 32],
Expand Down
58 changes: 55 additions & 3 deletions framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,10 +1326,35 @@ impl CrosEc {
"Writing GPU EEPROM {}",
if dry_run { " (DRY RUN)" } else { "" }
);
let mut force_power = false;

let info = EcRequestExpansionBayStatus {}.send_command(self)?;
println!(" Enabled: {}", info.module_enabled());
println!(" No fault: {}", !info.module_fault());
println!(" Door closed: {}", info.hatch_switch_closed());

match info.expansion_bay_board() {
Ok(board) => println!(" Board: {:?}", board),
Err(err) => println!(" Board: {:?}", err),
}

if let Ok(ExpansionBayBoard::DualInterposer) = info.expansion_bay_board() {
/* Force power to the GPU if we are writing the EEPROM */
let res = self.set_gpio("gpu_3v_5v_en", true);
if let Err(err) = res {
error!("Failed to set ALW power to GPU off {:?}", err);
return Err(err);
}
println!("Forcing Power to GPU");
os_specific::sleep(100_000);
force_power = true;
}

// Need to program the EEPROM 32 bytes at a time.
let chunk_size = 32;

let chunks = data.len() / chunk_size;
let mut return_val: EcResult<()> = Ok(());
for chunk_no in 0..chunks {
let offset = chunk_no * chunk_size;
// Current chunk might be smaller if it's the last
Expand All @@ -1356,12 +1381,26 @@ impl CrosEc {
// Don't read too fast, wait 100ms before writing more to allow for page erase/write cycle.
os_specific::sleep(100_000);
if let Err(err) = res {
println!(" Failed to write chunk: {:?}", err);
return Err(err);
error!("Failed to write chunk: {:?}", err);
return_val = Err(err);
break;
}
}
println!();
Ok(())

if force_power {
let res = self.set_gpio("gpu_3v_5v_en", false);
if let Err(err) = res {
error!("Failed to set ALW power to GPU off {:?}", err);
return if return_val.is_err() {
return_val
} else {
Err(err)
};
}
};

return_val
}

pub fn read_gpu_descriptor(&self) -> EcResult<Vec<u8>> {
Expand Down Expand Up @@ -1580,6 +1619,19 @@ impl CrosEc {
.send_command(self)
}

pub fn set_gpio(&self, name: &str, value: bool) -> EcResult<()> {
const MAX_LEN: usize = 32;
let mut request = EcRequestGpioSetV0 {
name: [0; MAX_LEN],
value: value as u8,
};

let end = MAX_LEN.min(name.len());
request.name[..end].copy_from_slice(&name.as_bytes()[..end]);

request.send_command(self)?;
Ok(())
}
pub fn get_gpio(&self, name: &str) -> EcResult<bool> {
const MAX_LEN: usize = 32;
let mut request = EcRequestGpioGetV0 { name: [0; MAX_LEN] };
Expand Down