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 Jul 19, 2024
1 parent 840ac3b commit 05ca434
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 @@ -39,6 +39,7 @@ enum Cmd {
SetNoInput = 19,
SecurityGet = 20,
SecuritySet = 21,
UsbcMuxInfo = 22,
}

const CMD_SPI_FLAG_READ: u8 = 1 << 0;
Expand Down Expand Up @@ -327,6 +328,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)
)
}

pub fn into_dyn(self) -> Ec<Box<dyn Access>>
where A: 'static {
Ec {
Expand Down
19 changes: 19 additions & 0 deletions tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,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 @@ -361,6 +368,9 @@ enum SubCommand {
Security {
state: Option<String>,
},
UsbcMuxInfo {
port: u8,
},
}

#[derive(clap::ValueEnum, Clone)]
Expand Down Expand Up @@ -638,5 +648,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 05ca434

Please sign in to comment.