Skip to content

Commit

Permalink
WIP - Doesn't work.
Browse files Browse the repository at this point in the history
GetCmdVersions says it's supported at least version 0. But the command
always fails.

Signed-off-by: Daniel Schaefer <[email protected]>
  • Loading branch information
JohnAZoidberg committed Oct 30, 2023
1 parent 0075593 commit 079c1ff
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 2 deletions.
1 change: 1 addition & 0 deletions framework_lib/src/chromium_ec/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum EcCommands {
I2cPassthrough = 0x9e,
ConsoleSnapshot = 0x97,
ConsoleRead = 0x98,
UsbPdControl = 0x101,
/// Get information about PD controller power
UsbPdPowerInfo = 0x103,

Expand Down
121 changes: 121 additions & 0 deletions framework_lib/src/chromium_ec/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,127 @@ impl EcRequest<()> for EcRequestConsoleRead {
}
}

pub enum UsbPdControlRole {
NoChange = 0,
/// == AUTO
ToggleOn = 1,
ToggleOff = 2,
ForceSink = 3,
ForceSource = 4,
Freeze = 5,
}

#[repr(u8)]
pub enum UsbPdControlMux {
NoChange = 0,
None = 1,
Usb = 2,
Dp = 3,
Dock = 4,
Auto = 5,
}

#[repr(u8)]
pub enum UsbPdControlSwap {
// No change
None = 0,
Data = 1,
Power = 2,
Vconn = 3,
}

#[repr(C, packed)]
pub struct EcRequestUsbPdControlV0 {
pub port: u8,
pub role: u8,
pub mux: u8,
// See UsbPdControlSwap. None to read
pub swap: u8,
}

#[repr(C, packed)]
#[derive(Debug)]
pub struct EcResponseUsbPdControlV0 {
enabled: u8,
role: u8,
polarity: u8,
state: u8,
}
impl EcRequest<EcResponseUsbPdControlV0> for EcRequestUsbPdControlV0 {
fn command_id() -> EcCommands {
EcCommands::UsbPdControl
}
fn command_version() -> u8 {
0
}
}

#[repr(C, packed)]
pub struct EcRequestUsbPdControlV1 {
pub port: u8,
pub role: u8,
pub mux: u8,
// See UsbPdControlSwap. None to read
pub swap: u8,
}

#[repr(C, packed)]
#[derive(Debug)]
pub struct EcResponseUsbPdControlV1 {
enabled: u8,
role: u8,
polarity: u8,
state: [u8; 32],
}

impl EcRequest<EcResponseUsbPdControlV1> for EcRequestUsbPdControlV1 {
fn command_id() -> EcCommands {
EcCommands::UsbPdControl
}
fn command_version() -> u8 {
1
}
}

#[repr(C, packed)]
pub struct EcRequestUsbPdControlV2 {
pub port: u8,
pub role: u8,
pub mux: u8,
// See UsbPdControlSwap. None to read
pub swap: u8,
}

#[repr(C, packed)]
#[derive(Debug)]
pub struct EcResponseUsbPdControlV2 {
enabled: u8,
role: u8,
polarity: u8,
state: [u8; 32],
/// enum pd_cc_states representing cc state
cc_state: u8,
/// Current DP pin mode (MODE_DP_PIN_[A-E])
dp_mode: u8,
reserved: u8,
/// USB_PD_CTRL_*flags
control_flags: u8,
/// TODO: b:158234949 Add definitions for cable speed
/// USB_R30_SS/TBT_SS_* cable speed
cable_speed: u8,
/// TBT_GEN3_* cable rounded support
cable_gen: u8,
}

impl EcRequest<EcResponseUsbPdControlV2> for EcRequestUsbPdControlV2 {
fn command_id() -> EcCommands {
EcCommands::UsbPdControl
}
fn command_version() -> u8 {
2
}
}

#[repr(C, packed)]
pub struct EcRequestUsbPdPowerInfo {
pub port: u8,
Expand Down
61 changes: 59 additions & 2 deletions framework_lib/src/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use core::prelude::v1::derive;
use log::Level;

use crate::ccgx::{AppVersion, Application, BaseVersion, ControllerVersion, MainPdVersions};
use crate::chromium_ec::command::EcRequestRaw;
use crate::chromium_ec::commands::{EcRequestReadPdVersion, EcRequestUsbPdPowerInfo};
use crate::chromium_ec::command::{EcRequestRaw, *};
use crate::chromium_ec::commands::{
EcRequestReadPdVersion, EcRequestUsbPdControlV0, EcRequestUsbPdPowerInfo, *,
};
use crate::chromium_ec::{print_err_ref, CrosEc, CrosEcDriver, EcResult};
use crate::smbios::get_platform;

Expand Down Expand Up @@ -438,6 +440,61 @@ pub fn get_and_print_pd_info(ec: &CrosEc) {
println!(" Max Power: Unknown");
}
}

println!(
"UsbPdControl V0 supported: {}",
ec.cmd_version_supported(EcCommands::UsbPdControl as u16, 0)
.unwrap()
);
println!(
"UsbPdControl V1 supported: {}",
ec.cmd_version_supported(EcCommands::UsbPdControl as u16, 1)
.unwrap()
);
println!(
"UsbPdControl V2 supported: {}",
ec.cmd_version_supported(EcCommands::UsbPdControl as u16, 2)
.unwrap()
);

println!(
"GetCmdVersions V0 supported: {}",
ec.cmd_version_supported(EcCommands::GetCmdVersions as u16, 0)
.unwrap()
);
println!(
"GetCmdVersions V1 supported: {}",
ec.cmd_version_supported(EcCommands::GetCmdVersions as u16, 1)
.unwrap()
);
println!(
"GetCmdVersions V2 supported: {}",
ec.cmd_version_supported(EcCommands::GetCmdVersions as u16, 2)
.unwrap()
);

let info = EcRequestGetCmdVersionsV0 {
cmd: EcCommands::UsbPdControl as u8,
}
.send_command(ec)
.unwrap();
println!("UsbPdControl Versions: {:?}", info);
let info = EcRequestGetCmdVersionsV1 {
cmd: EcCommands::UsbPdControl as u32,
}
.send_command(ec)
.unwrap();
println!("UsbPdControl Versions: {:?}", info);

let info = EcRequestUsbPdControlV0 {
port: 0,
role: 0,
mux: 0,
swap: 0,
}
.send_command(ec)
.unwrap();
println!("Info: {:#?}", info);
}

// TODO: Improve return type to be more obvious
Expand Down

0 comments on commit 079c1ff

Please sign in to comment.