Skip to content

Commit

Permalink
tool: Implement usbc_mux_info command
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 authored and crawfxrd committed Dec 13, 2023
1 parent 9dc3a46 commit cf64388
Show file tree
Hide file tree
Showing 2 changed files with 30 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
19 changes: 19 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 @@ -364,6 +371,9 @@ enum SubCommand {
Security {
state: Option<String>,
},
UsbcMuxInfo {
port: u8,
},
}

#[derive(clap::ArgEnum, Clone)]
Expand Down Expand Up @@ -652,5 +662,14 @@ fn main() {
},
}
},
SubCommand::UsbcMuxInfo { port } => {
match unsafe { usbc_mux_info(&mut ec, port) } {
Ok(()) => (),
Err(err) => {
eprintln!("failed to get usbc_mux_info {}: {:X?}", port, err);
process::exit(1);
},
}
},
}
}

0 comments on commit cf64388

Please sign in to comment.