Skip to content

Commit 94b0eb6

Browse files
jackpot51crawfxrd
authored andcommitted
tool: Implement usbc_mux_info command
1 parent 15ce7da commit 94b0eb6

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
@@ -40,6 +40,7 @@ enum Cmd {
4040
SecurityGet = 20,
4141
SecuritySet = 21,
4242
FanTach = 22,
43+
UsbcMuxInfo = 23,
4344
}
4445

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

332+
/// Get USB-C mux info
333+
pub unsafe fn usbc_mux_info(&mut self, port: u8) -> Result<u16, Error> {
334+
let mut data = [port, 0, 0];
335+
self.command(Cmd::UsbcMuxInfo, &mut data)?;
336+
Ok(
337+
(data[1] as u16) |
338+
((data[2] as u16) << 8)
339+
)
340+
}
341+
331342
/// Read fan tachometer by fan index
332343
pub unsafe fn fan_tach(&mut self, index: u8) -> Result<u16, Error> {
333344
let mut data = [

tool/src/main.rs

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

305+
unsafe fn usbc_mux_info(ec: &mut Ec<Box<dyn Access>>, port: u8) -> Result<(), Error> {
306+
let info = ec.usbc_mux_info(port)?;
307+
println!("{:04X}", info);
308+
309+
Ok(())
310+
}
311+
305312
fn parse_color(s: &str) -> Result<(u8, u8, u8), String> {
306313
let r = u8::from_str_radix(&s[0..2], 16);
307314
let g = u8::from_str_radix(&s[2..4], 16);
@@ -366,6 +373,9 @@ enum SubCommand {
366373
Security {
367374
state: Option<String>,
368375
},
376+
UsbcMuxInfo {
377+
port: u8,
378+
},
369379
}
370380

371381
#[derive(clap::ArgEnum, Clone)]
@@ -654,5 +664,14 @@ fn main() {
654664
},
655665
}
656666
},
667+
SubCommand::UsbcMuxInfo { port } => {
668+
match unsafe { usbc_mux_info(&mut ec, port) } {
669+
Ok(()) => (),
670+
Err(err) => {
671+
eprintln!("failed to get usbc_mux_info {}: {:X?}", port, err);
672+
process::exit(1);
673+
},
674+
}
675+
},
657676
}
658677
}

0 commit comments

Comments
 (0)