Skip to content

Commit 5d5d335

Browse files
committed
Implement usbc_mux_info tool command
1 parent fe52ae5 commit 5d5d335

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ unsafe fn security_set(ec: &mut Ec<Box<dyn Access>>, state: SecurityState) -> Re
300300
Ok(())
301301
}
302302

303+
unsafe fn usbc_mux_info(ec: &mut Ec<Box<dyn Access>>, port: u8) -> Result<(), Error> {
304+
let info = ec.usbc_mux_info(port)?;
305+
println!("{:04X}", info);
306+
307+
Ok(())
308+
}
309+
303310
fn parse_color(s: &str) -> Result<(u8, u8, u8), String> {
304311
let r = u8::from_str_radix(&s[0..2], 16);
305312
let g = u8::from_str_radix(&s[2..4], 16);
@@ -411,6 +418,12 @@ fn main() {
411418
.possible_values(["lock", "unlock"])
412419
)
413420
)
421+
.subcommand(SubCommand::with_name("usbc_mux_info")
422+
.arg(Arg::with_name("port")
423+
.value_parser(clap::value_parser!(u8))
424+
.required(true)
425+
)
426+
)
414427
.get_matches();
415428

416429
let get_ec = || -> Result<_, Error> {
@@ -693,6 +706,16 @@ fn main() {
693706
},
694707
}
695708
},
709+
Some(("usbc_mux_info", sub_m)) => {
710+
let port = sub_m.get_one::<u8>("port").unwrap();
711+
match unsafe { usbc_mux_info(&mut ec, *port) } {
712+
Ok(()) => (),
713+
Err(err) => {
714+
eprintln!("failed to get usbc_mux_info {}: {:X?}", port, err);
715+
process::exit(1);
716+
},
717+
}
718+
},
696719
_ => unreachable!()
697720
}
698721
}

0 commit comments

Comments
 (0)