Skip to content

Commit 5b10d0f

Browse files
committed
ccgx: Add enable_ports function
To disable or enable all ports of a PD controller framwork_tool --pd-disable 0 framwork_tool --pd-enable 1 framwork_tool --pd-disable 0 framwork_tool --pd-enable 1 Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent c71105f commit 5b10d0f

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

framework_lib/src/ccgx/device.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,10 @@ impl PdController {
366366
)?;
367367
Ok(())
368368
}
369+
370+
pub fn enable_ports(&self, enable: bool) -> EcResult<()> {
371+
let mask = if enable { 0b11 } else { 0b00 };
372+
self.ccgx_write(ControlRegisters::PdPortsEnable, &[mask])?;
373+
Ok(())
374+
}
369375
}

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,
@@ -381,6 +389,8 @@ pub fn parse(args: &[String]) -> Cli {
381389
pdports: args.pdports,
382390
pd_info: args.pd_info,
383391
pd_reset: args.pd_reset,
392+
pd_disable: args.pd_disable,
393+
pd_enable: args.pd_enable,
384394
dp_hdmi_info: args.dp_hdmi_info,
385395
dp_hdmi_update: args
386396
.dp_hdmi_update

framework_lib/src/commandline/mod.rs

Lines changed: 24 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,
@@ -1011,6 +1013,28 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
10111013
Ok(())
10121014
}
10131015
});
1016+
} else if let Some(pd) = args.pd_disable {
1017+
println!("Disabling PD {}...", pd);
1018+
print_err(match pd {
1019+
0 => PdController::new(PdPort::Left01, ec.clone()).enable_ports(false),
1020+
1 => PdController::new(PdPort::Right23, ec.clone()).enable_ports(false),
1021+
2 => PdController::new(PdPort::Back, ec.clone()).enable_ports(false),
1022+
_ => {
1023+
error!("PD {} does not exist", pd);
1024+
Ok(())
1025+
}
1026+
});
1027+
} else if let Some(pd) = args.pd_enable {
1028+
println!("Enabling PD {}...", pd);
1029+
print_err(match pd {
1030+
0 => PdController::new(PdPort::Left01, ec.clone()).enable_ports(true),
1031+
1 => PdController::new(PdPort::Right23, ec.clone()).enable_ports(true),
1032+
2 => PdController::new(PdPort::Back, ec.clone()).enable_ports(true),
1033+
_ => {
1034+
error!("PD {} does not exist", pd);
1035+
Ok(())
1036+
}
1037+
});
10141038
} else if args.dp_hdmi_info {
10151039
#[cfg(feature = "hidapi")]
10161040
print_dp_hdmi_details(true);

framework_lib/src/commandline/uefi.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ pub fn parse(args: &[String]) -> Cli {
7171
pdports: false,
7272
pd_info: false,
7373
pd_reset: None,
74+
pd_disable: None,
75+
pd_enable: None,
7476
dp_hdmi_info: false,
7577
dp_hdmi_update: None,
7678
audio_card_info: false,
@@ -535,6 +537,38 @@ pub fn parse(args: &[String]) -> Cli {
535537
None
536538
};
537539
found_an_option = true;
540+
} else if arg == "--pd-disable" {
541+
cli.pd_reset = if args.len() > i + 1 {
542+
if let Ok(pd) = args[i + 1].parse::<u8>() {
543+
Some(pd)
544+
} else {
545+
println!(
546+
"Invalid value for --pd-disable: '{}'. Must be 0 or 1.",
547+
args[i + 1],
548+
);
549+
None
550+
}
551+
} else {
552+
println!("--pd-disable requires specifying the PD controller");
553+
None
554+
};
555+
found_an_option = true;
556+
} else if arg == "--pd-enable" {
557+
cli.pd_enable = if args.len() > i + 1 {
558+
if let Ok(pd) = args[i + 1].parse::<u8>() {
559+
Some(pd)
560+
} else {
561+
println!(
562+
"Invalid value for --pd-enable: '{}'. Must be 0 or 1.",
563+
args[i + 1],
564+
);
565+
None
566+
}
567+
} else {
568+
println!("--pd-enable requires specifying the PD controller");
569+
None
570+
};
571+
found_an_option = true;
538572
} else if arg == "--privacy" {
539573
cli.privacy = true;
540574
found_an_option = true;

0 commit comments

Comments
 (0)