Skip to content

Commit 511ae9c

Browse files
committed
ccgx: Add enable_ports function
To disable or enable all ports of a PD controller Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 77c514e commit 511ae9c

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

framework_lib/src/ccgx/device.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,10 @@ impl PdController {
338338
)?;
339339
Ok(())
340340
}
341+
342+
pub fn enable_ports(&self, enable: bool) -> EcResult<()> {
343+
let mask = if enable { 0b11 } else { 0b00 };
344+
self.ccgx_write(ControlRegisters::PdPortsEnable, &[mask])?;
345+
Ok(())
346+
}
341347
}

framework_lib/src/commandline/clap_std.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ struct ClapCli {
8787
#[arg(long)]
8888
pd_reset: Option<u8>,
8989

90+
/// Disable all ports on a specific PD controller (for debugging only)
91+
#[arg(long)]
92+
pd_disable: Option<u8>,
93+
94+
/// Enable all ports on a specific PD controller (for debugging only)
95+
#[arg(long)]
96+
pd_enable: Option<u8>,
97+
9098
/// Show details about connected DP or HDMI Expansion Cards
9199
#[arg(long)]
92100
dp_hdmi_info: bool,
@@ -355,6 +363,8 @@ pub fn parse(args: &[String]) -> Cli {
355363
pdports: args.pdports,
356364
pd_info: args.pd_info,
357365
pd_reset: args.pd_reset,
366+
pd_disable: args.pd_disable,
367+
pd_enable: args.pd_enable,
358368
dp_hdmi_info: args.dp_hdmi_info,
359369
dp_hdmi_update: args
360370
.dp_hdmi_update

framework_lib/src/commandline/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ pub struct Cli {
157157
pub privacy: bool,
158158
pub pd_info: bool,
159159
pub pd_reset: Option<u8>,
160+
pub pd_disable: Option<u8>,
161+
pub pd_enable: Option<u8>,
160162
pub dp_hdmi_info: bool,
161163
pub dp_hdmi_update: Option<String>,
162164
pub audio_card_info: bool,
@@ -918,6 +920,26 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
918920
Ok(())
919921
}
920922
});
923+
} else if let Some(pd) = args.pd_disable {
924+
println!("Disabling PD {}...", pd);
925+
print_err(match pd {
926+
0 => PdController::new(PdPort::Left01, ec.clone()).enable_ports(false),
927+
1 => PdController::new(PdPort::Right23, ec.clone()).enable_ports(false),
928+
_ => {
929+
error!("PD {} does not exist", pd);
930+
Ok(())
931+
}
932+
});
933+
} else if let Some(pd) = args.pd_enable {
934+
println!("Enabling PD {}...", pd);
935+
print_err(match pd {
936+
0 => PdController::new(PdPort::Left01, ec.clone()).enable_ports(true),
937+
1 => PdController::new(PdPort::Right23, ec.clone()).enable_ports(true),
938+
_ => {
939+
error!("PD {} does not exist", pd);
940+
Ok(())
941+
}
942+
});
921943
} else if args.dp_hdmi_info {
922944
#[cfg(feature = "hidapi")]
923945
print_dp_hdmi_details();

0 commit comments

Comments
 (0)