Skip to content

Commit

Permalink
Implement usbc_mux_info tool command
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Dec 8, 2023
1 parent fe52ae5 commit 5d5d335
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tool/src/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum Cmd {
SecurityGet = 20,
SecuritySet = 21,
FanTach = 22,
UsbcMuxInfo = 23,
}

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

/// Get USB-C mux info
pub unsafe fn usbc_mux_info(&mut self, port: u8) -> Result<u16, Error> {
let mut data = [port, 0, 0];
self.command(Cmd::UsbcMuxInfo, &mut data)?;
Ok(
(data[1] as u16) |
((data[2] as u16) << 8)
)
}

/// Read fan tachometer by fan index
pub unsafe fn fan_tach(&mut self, index: u8) -> Result<u16, Error> {
let mut data = [
Expand Down
23 changes: 23 additions & 0 deletions tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ unsafe fn security_set(ec: &mut Ec<Box<dyn Access>>, state: SecurityState) -> Re
Ok(())
}

unsafe fn usbc_mux_info(ec: &mut Ec<Box<dyn Access>>, port: u8) -> Result<(), Error> {
let info = ec.usbc_mux_info(port)?;
println!("{:04X}", info);

Ok(())
}

fn parse_color(s: &str) -> Result<(u8, u8, u8), String> {
let r = u8::from_str_radix(&s[0..2], 16);
let g = u8::from_str_radix(&s[2..4], 16);
Expand Down Expand Up @@ -411,6 +418,12 @@ fn main() {
.possible_values(["lock", "unlock"])
)
)
.subcommand(SubCommand::with_name("usbc_mux_info")
.arg(Arg::with_name("port")
.value_parser(clap::value_parser!(u8))
.required(true)
)
)
.get_matches();

let get_ec = || -> Result<_, Error> {
Expand Down Expand Up @@ -693,6 +706,16 @@ fn main() {
},
}
},
Some(("usbc_mux_info", sub_m)) => {
let port = sub_m.get_one::<u8>("port").unwrap();
match unsafe { usbc_mux_info(&mut ec, *port) } {
Ok(()) => (),
Err(err) => {
eprintln!("failed to get usbc_mux_info {}: {:X?}", port, err);
process::exit(1);
},
}
},
_ => unreachable!()
}
}

0 comments on commit 5d5d335

Please sign in to comment.