Skip to content

Commit c71105f

Browse files
committed
ccgx: Add reset_device function
framwork_tool --pd-reset 0 framwork_tool --pd-reset 1 Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent cdf538d commit c71105f

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

framework_lib/src/ccgx/device.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,12 @@ impl PdController {
358358
base_ver, app_ver
359359
);
360360
}
361+
362+
pub fn reset_device(&self) -> EcResult<()> {
363+
self.ccgx_write(
364+
ControlRegisters::ResetRequest,
365+
&[HPI_RESET_SIGNATURE as u8, HPI_RESET_DEV_CMD],
366+
)?;
367+
Ok(())
368+
}
361369
}

framework_lib/src/commandline/clap_std.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ struct ClapCli {
8383
#[arg(long)]
8484
pd_info: bool,
8585

86+
/// Reset a specific PD controller (for debugging only)
87+
#[arg(long)]
88+
pd_reset: Option<u8>,
89+
8690
/// Show details about connected DP or HDMI Expansion Cards
8791
#[arg(long)]
8892
dp_hdmi_info: bool,
@@ -376,6 +380,7 @@ pub fn parse(args: &[String]) -> Cli {
376380
autofanctrl: args.autofanctrl,
377381
pdports: args.pdports,
378382
pd_info: args.pd_info,
383+
pd_reset: args.pd_reset,
379384
dp_hdmi_info: args.dp_hdmi_info,
380385
dp_hdmi_update: args
381386
.dp_hdmi_update

framework_lib/src/commandline/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ pub struct Cli {
156156
pub pdports: bool,
157157
pub privacy: bool,
158158
pub pd_info: bool,
159+
pub pd_reset: Option<u8>,
159160
pub dp_hdmi_info: bool,
160161
pub dp_hdmi_update: Option<String>,
161162
pub audio_card_info: bool,
@@ -999,6 +1000,17 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
9991000
smbios_info();
10001001
} else if args.pd_info {
10011002
print_pd_details(&ec);
1003+
} else if let Some(pd) = args.pd_reset {
1004+
println!("Resetting PD {}...", pd);
1005+
print_err(match pd {
1006+
0 => PdController::new(PdPort::Left01, ec.clone()).reset_device(),
1007+
1 => PdController::new(PdPort::Right23, ec.clone()).reset_device(),
1008+
2 => PdController::new(PdPort::Back, ec.clone()).reset_device(),
1009+
_ => {
1010+
error!("PD {} does not exist", pd);
1011+
Ok(())
1012+
}
1013+
});
10021014
} else if args.dp_hdmi_info {
10031015
#[cfg(feature = "hidapi")]
10041016
print_dp_hdmi_details(true);

framework_lib/src/commandline/uefi.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub fn parse(args: &[String]) -> Cli {
7070
autofanctrl: false,
7171
pdports: false,
7272
pd_info: false,
73+
pd_reset: None,
7374
dp_hdmi_info: false,
7475
dp_hdmi_update: None,
7576
audio_card_info: false,
@@ -518,6 +519,22 @@ pub fn parse(args: &[String]) -> Cli {
518519
} else if arg == "--pd-info" {
519520
cli.pd_info = true;
520521
found_an_option = true;
522+
} else if arg == "--pd-reset" {
523+
cli.pd_reset = if args.len() > i + 1 {
524+
if let Ok(pd) = args[i + 1].parse::<u8>() {
525+
Some(pd)
526+
} else {
527+
println!(
528+
"Invalid value for --pd-reset: '{}'. Must be 0 or 1.",
529+
args[i + 1],
530+
);
531+
None
532+
}
533+
} else {
534+
println!("--pd-reset requires specifying the PD controller");
535+
None
536+
};
537+
found_an_option = true;
521538
} else if arg == "--privacy" {
522539
cli.privacy = true;
523540
found_an_option = true;

0 commit comments

Comments
 (0)