Skip to content

Commit 7c53403

Browse files
jackpot51crawfxrd
authored andcommitted
tool: Implement usbc_mux_info command
1 parent 289fc64 commit 7c53403

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

tool/src/ec.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum Cmd {
3939
SetNoInput = 19,
4040
SecurityGet = 20,
4141
SecuritySet = 21,
42+
UsbcMuxInfo = 22,
4243
}
4344

4445
const CMD_SPI_FLAG_READ: u8 = 1 << 0;
@@ -327,6 +328,16 @@ impl<A: Access> Ec<A> {
327328
self.command(Cmd::SecuritySet, &mut data)
328329
}
329330

331+
/// Get USB-C mux info
332+
pub unsafe fn usbc_mux_info(&mut self, port: u8) -> Result<u16, Error> {
333+
let mut data = [port, 0, 0];
334+
self.command(Cmd::UsbcMuxInfo, &mut data)?;
335+
Ok(
336+
(data[1] as u16) |
337+
((data[2] as u16) << 8)
338+
)
339+
}
340+
330341
pub fn into_dyn(self) -> Ec<Box<dyn Access>>
331342
where A: 'static {
332343
Ec {

tool/src/main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ unsafe fn security_set(ec: &mut Ec<Box<dyn Access>>, state: SecurityState) -> Re
301301
Ok(())
302302
}
303303

304+
unsafe fn usbc_mux_info(ec: &mut Ec<Box<dyn Access>>, port: u8) -> Result<(), Error> {
305+
let info = ec.usbc_mux_info(port)?;
306+
println!("{:04X}", info);
307+
308+
Ok(())
309+
}
310+
304311
fn parse_color(s: &str) -> Result<(u8, u8, u8), String> {
305312
let r = u8::from_str_radix(&s[0..2], 16);
306313
let g = u8::from_str_radix(&s[2..4], 16);
@@ -361,6 +368,9 @@ enum SubCommand {
361368
Security {
362369
state: Option<String>,
363370
},
371+
UsbcMuxInfo {
372+
port: u8,
373+
},
364374
}
365375

366376
#[derive(clap::ValueEnum, Clone)]
@@ -638,5 +648,14 @@ fn main() {
638648
},
639649
}
640650
},
651+
SubCommand::UsbcMuxInfo { port } => {
652+
match unsafe { usbc_mux_info(&mut ec, port) } {
653+
Ok(()) => (),
654+
Err(err) => {
655+
eprintln!("failed to get usbc_mux_info {}: {:X?}", port, err);
656+
process::exit(1);
657+
},
658+
}
659+
},
641660
}
642661
}

0 commit comments

Comments
 (0)