Skip to content

Commit b1a1ed1

Browse files
committed
Add --pdports-cypd
The regular --pdports command does not return useful data on our systems because it uses the chrome PD subsystem instead of the cypress PD subsystem that we use. Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 3f2deb2 commit b1a1ed1

9 files changed

Lines changed: 190 additions & 1 deletion

File tree

framework_lib/src/chromium_ec/command.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ pub enum EcCommands {
110110
GetGpuPcie = 0x3E1E,
111111
/// Set gpu bay serial and program structure
112112
ProgramGpuEeprom = 0x3E1F,
113+
/// Get PD port state from Cypress PD controller
114+
GetPdPortState = 0x3E23,
113115
/// Read board ID of specific ADC channel
114116
ReadBoardId = 0x3E26,
115117
}

framework_lib/src/chromium_ec/commands.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,33 @@ impl EcRequest<_EcResponseReadPdVersionV1> for EcRequestReadPdVersionV1 {
12471247
}
12481248
}
12491249

1250+
#[repr(C, packed)]
1251+
pub struct EcRequestGetPdPortState {
1252+
pub port: u8,
1253+
}
1254+
1255+
#[repr(C, packed)]
1256+
pub struct EcResponseGetPdPortState {
1257+
pub c_state: u8,
1258+
pub pd_state: u8,
1259+
pub power_role: u8,
1260+
pub data_role: u8,
1261+
pub vconn: u8,
1262+
pub epr_active: u8,
1263+
pub epr_support: u8,
1264+
pub cc_polarity: u8,
1265+
pub voltage: u16,
1266+
pub current: u16,
1267+
pub active_port: u8,
1268+
pub pd_alt_mode_status: u8,
1269+
}
1270+
1271+
impl EcRequest<EcResponseGetPdPortState> for EcRequestGetPdPortState {
1272+
fn command_id() -> EcCommands {
1273+
EcCommands::GetPdPortState
1274+
}
1275+
}
1276+
12501277
#[repr(C, packed)]
12511278
pub struct EcRequestPrivacySwitches {}
12521279

framework_lib/src/commandline/clap_std.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ struct ClapCli {
7878
#[arg(long)]
7979
pdports: bool,
8080

81+
/// Show CYPD PD port state (Framework-specific)
82+
#[arg(long)]
83+
pdports_cypd: bool,
84+
8185
/// Show info from SMBIOS (Only on UEFI)
8286
#[arg(long)]
8387
info: bool,
@@ -475,6 +479,7 @@ pub fn parse(args: &[String]) -> Cli {
475479
fansetrpm,
476480
autofanctrl: args.autofanctrl,
477481
pdports: args.pdports,
482+
pdports_cypd: args.pdports_cypd,
478483
pd_info: args.pd_info,
479484
pd_reset: args.pd_reset,
480485
pd_disable: args.pd_disable,

framework_lib/src/commandline/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ pub struct Cli {
171171
pub fansetrpm: Option<(Option<u32>, u32)>,
172172
pub autofanctrl: Option<Option<u8>>,
173173
pub pdports: bool,
174+
pub pdports_cypd: bool,
174175
pub privacy: bool,
175176
pub pd_info: bool,
176177
pub pd_reset: Option<u8>,
@@ -260,6 +261,7 @@ pub fn parse(args: &[String]) -> Cli {
260261
// fansetrpm
261262
// autofanctrl
262263
pdports: cli.pdports,
264+
pdports_cypd: cli.pdports_cypd,
263265
privacy: cli.privacy,
264266
pd_info: cli.version,
265267
// pd_reset
@@ -1542,6 +1544,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
15421544
print_err(ec.autofanctrl(None));
15431545
} else if args.pdports {
15441546
power::get_and_print_pd_info(&ec);
1547+
} else if args.pdports_cypd {
1548+
power::get_and_print_cypd_pd_info(&ec);
15451549
} else if args.info {
15461550
smbios_info();
15471551
} else if let Some(dump_path) = &args.meinfo {
@@ -1833,6 +1837,7 @@ Options:
18331837
--fansetrpm Set fan RPM (limited by EC fan table max RPM)
18341838
--autofanctrl [<FANID>]Turn on automatic fan speed control (optionally provide fan index)
18351839
--pdports Show information about USB-C PD ports
1840+
--pdports-cypd Show CYPD PD port state (Framework-specific)
18361841
--info Show info from SMBIOS (Only on UEFI)
18371842
--meinfo [<DUMPFILE>] Show Intel ME information (from SMBIOS type 0xDB)
18381843
--pd-info Show details about the PD controllers

framework_lib/src/commandline/uefi.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ pub fn parse(args: &[String]) -> Cli {
224224
} else if arg == "--pdports" {
225225
cli.pdports = true;
226226
found_an_option = true;
227+
} else if arg == "--pdports-cypd" {
228+
cli.pdports_cypd = true;
229+
found_an_option = true;
227230
} else if arg == "--allupdate" {
228231
cli.allupdate = true;
229232
found_an_option = true;

framework_lib/src/power.rs

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,151 @@ pub fn get_pd_info(ec: &CrosEc, ports: u8) -> Vec<EcResult<UsbPdPowerInfo>> {
718718
info
719719
}
720720

721+
#[derive(Debug)]
722+
enum CypdTypeCState {
723+
Nothing,
724+
Sink,
725+
Source,
726+
Debug,
727+
Audio,
728+
PoweredAccessory,
729+
Unsupported,
730+
Invalid,
731+
}
732+
733+
impl From<u8> for CypdTypeCState {
734+
fn from(v: u8) -> Self {
735+
match v {
736+
0 => CypdTypeCState::Nothing,
737+
1 => CypdTypeCState::Sink,
738+
2 => CypdTypeCState::Source,
739+
3 => CypdTypeCState::Debug,
740+
4 => CypdTypeCState::Audio,
741+
5 => CypdTypeCState::PoweredAccessory,
742+
6 => CypdTypeCState::Unsupported,
743+
_ => CypdTypeCState::Invalid,
744+
}
745+
}
746+
}
747+
748+
#[derive(Debug)]
749+
enum CypdPdPowerRole {
750+
Sink,
751+
Source,
752+
Unknown,
753+
}
754+
755+
impl From<u8> for CypdPdPowerRole {
756+
fn from(v: u8) -> Self {
757+
match v {
758+
0 => CypdPdPowerRole::Sink,
759+
1 => CypdPdPowerRole::Source,
760+
_ => CypdPdPowerRole::Unknown,
761+
}
762+
}
763+
}
764+
765+
#[derive(Debug)]
766+
enum CypdPdDataRole {
767+
Ufp,
768+
Dfp,
769+
Disconnected,
770+
Unknown,
771+
}
772+
773+
impl From<u8> for CypdPdDataRole {
774+
fn from(v: u8) -> Self {
775+
match v {
776+
0 => CypdPdDataRole::Ufp,
777+
1 => CypdPdDataRole::Dfp,
778+
2 => CypdPdDataRole::Disconnected,
779+
_ => CypdPdDataRole::Unknown,
780+
}
781+
}
782+
}
783+
784+
pub fn get_and_print_cypd_pd_info(ec: &CrosEc) {
785+
let fl16 = Some(PlatformFamily::Framework16) == smbios::get_family();
786+
let ports = 4u8;
787+
788+
for port in 0..ports {
789+
println!(
790+
"USB-C Port {} ({}):",
791+
port,
792+
match port {
793+
0 => "Right Back",
794+
1 =>
795+
if fl16 {
796+
"Right Middle"
797+
} else {
798+
"Right Front"
799+
},
800+
2 =>
801+
if fl16 {
802+
"Left Middle"
803+
} else {
804+
"Left Front"
805+
},
806+
3 => "Left Back",
807+
_ => "??",
808+
}
809+
);
810+
811+
let result = EcRequestGetPdPortState { port }.send_command(ec);
812+
match result {
813+
Ok(info) => {
814+
let c_state = CypdTypeCState::from(info.c_state);
815+
let power_role = CypdPdPowerRole::from(info.power_role);
816+
let data_role = CypdPdDataRole::from(info.data_role);
817+
let voltage = { info.voltage };
818+
let current = { info.current };
819+
let watts_mw = voltage as u32 * current as u32 / 1000;
820+
821+
println!(" Type-C State: {:?}", c_state);
822+
println!(
823+
" PD Contract: {}",
824+
if info.pd_state != 0 { "Yes" } else { "No" }
825+
);
826+
println!(" Power Role: {:?}", power_role);
827+
println!(" Data Role: {:?}", data_role);
828+
println!(
829+
" VCONN: {}",
830+
if info.vconn != 0 { "On" } else { "Off" }
831+
);
832+
println!(
833+
" Voltage: {}.{:03} V",
834+
voltage / 1000,
835+
voltage % 1000
836+
);
837+
println!(" Current: {} mA", current);
838+
println!(" Power: {}.{} W", watts_mw / 1000, watts_mw % 1000);
839+
println!(
840+
" EPR: {}{}",
841+
if info.epr_active != 0 {
842+
"Active"
843+
} else {
844+
"Inactive"
845+
},
846+
if info.epr_support != 0 {
847+
" (Supported)"
848+
} else {
849+
""
850+
}
851+
);
852+
println!(" CC Polarity: CC{}", info.cc_polarity + 1);
853+
println!(
854+
" Active Port: {}",
855+
if info.active_port != 0 { "Yes" } else { "No" }
856+
);
857+
println!(" Alt Mode: 0x{:02X}", info.pd_alt_mode_status);
858+
}
859+
Err(e) => {
860+
print_err::<()>(Err(e));
861+
}
862+
}
863+
}
864+
}
865+
721866
pub fn get_and_print_pd_info(ec: &CrosEc) {
722867
let fl16 = Some(PlatformFamily::Framework16) == smbios::get_family();
723868
let ports = 4; // All our platforms have 4 PD ports so far

framework_tool/completions/bash/framework_tool

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _framework_tool() {
2323

2424
case "${cmd}" in
2525
framework_tool)
26-
opts="-v -q -t -f -h --flash-gpu-descriptor --verbose --quiet --versions --version --features --esrt --device --compare-version --power --thermal --sensors --fansetduty --fansetrpm --autofanctrl --pdports --info --meinfo --pd-info --pd-reset --pd-disable --pd-enable --dp-hdmi-info --dp-hdmi-update --audio-card-info --privacy --pd-bin --ec-bin --capsule --dump --h2o-capsule --dump-ec-flash --flash-full-ec --flash-ec --flash-ro-ec --flash-rw-ec --intrusion --inputdeck --inputdeck-mode --expansion-bay --charge-limit --charge-current-limit --charge-rate-limit --get-gpio --fp-led-level --fp-brightness --kblight --remap-key --rgbkbd --ps2-enable --tablet-mode --touchscreen-enable --stylus-battery --console --reboot-ec --ec-hib-delay --uptimeinfo --s0ix-counter --hash --driver --pd-addrs --pd-ports --test --test-retimer --boardid --force --dry-run --flash-gpu-descriptor-file --dump-gpu-descriptor-file --nvidia --host-command --generate-completions --help"
26+
opts="-v -q -t -f -h --flash-gpu-descriptor --verbose --quiet --versions --version --features --esrt --device --compare-version --power --thermal --sensors --fansetduty --fansetrpm --autofanctrl --pdports --pdports-cypd --info --meinfo --pd-info --pd-reset --pd-disable --pd-enable --dp-hdmi-info --dp-hdmi-update --audio-card-info --privacy --pd-bin --ec-bin --capsule --dump --h2o-capsule --dump-ec-flash --flash-full-ec --flash-ec --flash-ro-ec --flash-rw-ec --intrusion --inputdeck --inputdeck-mode --expansion-bay --charge-limit --charge-current-limit --charge-rate-limit --get-gpio --fp-led-level --fp-brightness --kblight --remap-key --rgbkbd --ps2-enable --tablet-mode --touchscreen-enable --stylus-battery --console --reboot-ec --ec-hib-delay --uptimeinfo --s0ix-counter --hash --driver --pd-addrs --pd-ports --test --test-retimer --boardid --force --dry-run --flash-gpu-descriptor-file --dump-gpu-descriptor-file --nvidia --host-command --generate-completions --help"
2727
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
2828
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
2929
return 0

framework_tool/completions/fish/framework_tool.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ complete -c framework_tool -l power -d 'Show current power status of battery and
8181
complete -c framework_tool -l thermal -d 'Print thermal information (Temperatures and Fan speed)'
8282
complete -c framework_tool -l sensors -d 'Print sensor information (ALS, G-Sensor)'
8383
complete -c framework_tool -l pdports -d 'Show information about USB-C PD ports'
84+
complete -c framework_tool -l pdports-cypd -d 'Show CYPD PD port state (Framework-specific)'
8485
complete -c framework_tool -l info -d 'Show info from SMBIOS (Only on UEFI)'
8586
complete -c framework_tool -l pd-info -d 'Show details about the PD controllers'
8687
complete -c framework_tool -l dp-hdmi-info -d 'Show details about connected DP or HDMI Expansion Cards'

framework_tool/completions/zsh/_framework_tool

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ _framework_tool() {
7272
'--thermal[Print thermal information (Temperatures and Fan speed)]' \
7373
'--sensors[Print sensor information (ALS, G-Sensor)]' \
7474
'--pdports[Show information about USB-C PD ports]' \
75+
'--pdports-cypd[Show CYPD PD port state (Framework-specific)]' \
7576
'--info[Show info from SMBIOS (Only on UEFI)]' \
7677
'--pd-info[Show details about the PD controllers]' \
7778
'--dp-hdmi-info[Show details about connected DP or HDMI Expansion Cards]' \

0 commit comments

Comments
 (0)