Skip to content

Commit 71823ec

Browse files
committed
turn on bay power when programming eeprom
for fresh expansion bay modules that are unprogrammed, we need to turn on the power to program them if they are not preprogrammed with dummy values. Signed-off-by: Kieran Levin <ktl@frame.work>
1 parent bb87855 commit 71823ec

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

framework_lib/src/chromium_ec/command.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub enum EcCommands {
3737
PwmGetDuty = 0x0026,
3838
SetTabletMode = 0x0031,
3939
AutoFanCtrl = 0x0052,
40+
GpioSet = 0x0092,
4041
GpioGet = 0x0093,
4142
I2cPassthrough = 0x009e,
4243
ConsoleSnapshot = 0x0097,

framework_lib/src/chromium_ec/commands.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,18 @@ impl EcRequest<()> for EcRequestAutoFanCtrlV1 {
452452
}
453453
}
454454

455+
#[repr(C, packed)]
456+
pub struct EcRequestGpioSetV0 {
457+
pub name: [u8; 32],
458+
pub value: u8,
459+
}
460+
461+
impl EcRequest<()> for EcRequestGpioSetV0 {
462+
fn command_id() -> EcCommands {
463+
EcCommands::GpioSet
464+
}
465+
}
466+
455467
#[repr(C, packed)]
456468
pub struct EcRequestGpioGetV0 {
457469
pub name: [u8; 32],

framework_lib/src/chromium_ec/mod.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,30 @@ impl CrosEc {
13231323
"Writing GPU EEPROM {}",
13241324
if dry_run { " (DRY RUN)" } else { "" }
13251325
);
1326+
let mut force_power = false;
1327+
1328+
let info = EcRequestExpansionBayStatus {}.send_command(self)?;
1329+
println!(" Enabled: {}", info.module_enabled());
1330+
println!(" No fault: {}", !info.module_fault());
1331+
println!(" Door closed: {}", info.hatch_switch_closed());
1332+
1333+
match info.expansion_bay_board() {
1334+
Ok(board) => println!(" Board: {:?}", board),
1335+
Err(err) => println!(" Board: {:?}", err),
1336+
}
1337+
1338+
if let Ok(ExpansionBayBoard::DualInterposer) = info.expansion_bay_board() {
1339+
/* Force power to the GPU if we are writing the EEPROM */
1340+
let res = self.set_gpio("gpu_3v_5v_en", true);
1341+
if let Err(err) = res {
1342+
println!(" Failed to set ALW power to GPU off {:?}", err);
1343+
return Err(err);
1344+
}
1345+
println!("Forcing Power to GPU");
1346+
os_specific::sleep(100_000);
1347+
force_power = true;
1348+
}
1349+
13261350
// Need to program the EEPROM 32 bytes at a time.
13271351
let chunk_size = 32;
13281352

@@ -1358,6 +1382,15 @@ impl CrosEc {
13581382
}
13591383
}
13601384
println!();
1385+
1386+
if force_power {
1387+
let res = self.set_gpio("gpu_3v_5v_en", false);
1388+
if let Err(err) = res {
1389+
println!(" Failed to set ALW power to GPU off {:?}", err);
1390+
return Err(err);
1391+
}
1392+
};
1393+
13611394
Ok(())
13621395
}
13631396

@@ -1564,6 +1597,19 @@ impl CrosEc {
15641597
.send_command(self)
15651598
}
15661599

1600+
pub fn set_gpio(&self, name: &str, value: bool) -> EcResult<()> {
1601+
const MAX_LEN: usize = 32;
1602+
let mut request = EcRequestGpioSetV0 {
1603+
name: [0; MAX_LEN],
1604+
value: value as u8,
1605+
};
1606+
1607+
let end = MAX_LEN.min(name.len());
1608+
request.name[..end].copy_from_slice(&name.as_bytes()[..end]);
1609+
1610+
request.send_command(self)?;
1611+
Ok(())
1612+
}
15671613
pub fn get_gpio(&self, name: &str) -> EcResult<bool> {
15681614
const MAX_LEN: usize = 32;
15691615
let mut request = EcRequestGpioGetV0 { name: [0; MAX_LEN] };

0 commit comments

Comments
 (0)