Skip to content

Commit 030311b

Browse files
committed
parade_retimer: Allow reading firmware version
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent cee844e commit 030311b

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

framework_lib/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub mod csme;
4141
pub mod ec_binary;
4242
pub mod esrt;
4343
mod os_specific;
44+
pub mod parade_retimer;
4445
pub mod power;
4546
pub mod smbios;
4647
#[cfg(feature = "uefi")]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use alloc::vec::Vec;
2+
use num_traits::FromPrimitive;
3+
4+
use crate::chromium_ec::command::EcRequestRaw;
5+
use crate::chromium_ec::commands::{EcRequestGetGpuPcie, GpuVendor};
6+
use crate::chromium_ec::i2c_passthrough::*;
7+
use crate::chromium_ec::{CrosEc, EcResult};
8+
use crate::os_specific;
9+
10+
pub fn get_version(ec: &CrosEc) -> EcResult<Option<Vec<u8>>> {
11+
let res = EcRequestGetGpuPcie {}.send_command(ec)?;
12+
let vendor: Option<GpuVendor> = FromPrimitive::from_u8(res.gpu_vendor);
13+
if vendor != Some(GpuVendor::NvidiaGn22) {
14+
debug!("No compatible retimer present");
15+
return Ok(None);
16+
};
17+
18+
// I2C Port on the EC
19+
let i2c_port = 5;
20+
// 8-bit I2C address of the retimer
21+
// EC passthrough needs 7-bit, so shift one over before sending to EC
22+
let i2c_addr = 0x10;
23+
24+
// Check safe mode
25+
let i2c_response = i2c_read(ec, i2c_port, i2c_addr >> 1, 0x00, 0x01)?;
26+
if i2c_response.data[0] == 0 {
27+
// Safe mode not enabled, enable it
28+
i2c_write(ec, i2c_port, i2c_addr >> 1, 0x00, &[0x01])?;
29+
}
30+
31+
// Wake up from low power mode
32+
for _ in 0..3 {
33+
let i2c_response = i2c_read(ec, i2c_port, (i2c_addr + 2) >> 1, 0x70, 0x01)?;
34+
if i2c_response.data[0] != 0 {
35+
i2c_write(ec, i2c_port, (i2c_addr + 2) >> 1, 0x70, &[0x00])?;
36+
os_specific::sleep(50_000);
37+
}
38+
}
39+
40+
// Read version
41+
let i2c_response = i2c_read(ec, i2c_port, (i2c_addr + 18) >> 1, 0x01, 0x04)?;
42+
43+
Ok(Some(i2c_response.data))
44+
}

0 commit comments

Comments
 (0)