Skip to content

Commit

Permalink
Merge pull request #6 from FrameworkComputer/uefi-inputmodule-app
Browse files Browse the repository at this point in the history
chromium_ec: Add more commands for UEFI Inputmodule App
  • Loading branch information
JohnAZoidberg authored Oct 20, 2023
2 parents 00d2e36 + 9980f9a commit a929fbc
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 11 deletions.
49 changes: 45 additions & 4 deletions framework_lib/src/chromium_ec/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ use core::prelude::rust_2021::derive;
use alloc::format;
use alloc::vec;
use alloc::vec::Vec;
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;

use crate::util;

use super::{CrosEc, CrosEcDriver, EcError, EcResult};

// u16
#[non_exhaustive]
#[derive(Debug)]
#[derive(Debug, FromPrimitive)]
#[repr(u16)]
pub enum EcCommands {
GetVersion = 0x02,
GetBuildInfo = 0x04,
Expand All @@ -32,12 +34,34 @@ pub enum EcCommands {
ChassisOpenCheck = 0x3E0F,
/// Get information about historical chassis open/close (intrusion) information
ChassisIntrusion = 0x3E09,

/// Not used by this library
AcpiNotify = 0xE10,

/// Get information about PD controller version
ReadPdVersion = 0x3E11,

/// Not used by this library
StandaloneMode = 0x3E13,
/// Get information about current state of privacy switches
PriavcySwitchesCheckMode = 0x3E14,
/// Not used by this library
ChassisCounter = 0x3E15,
/// On Framework 16, check the status of the input module deck
CheckDeckState = 0x3E16,
/// Not used by this library
GetSimpleVersion = 0x3E17,
/// GetActiveChargePdChip
GetActiveChargePdChip = 0x3E18,

/// Set UEFI App mode
UefiAppMode = 0x3E19,
/// Get UEFI APP Button status
UefiAppBtnStatus = 0x3E1A,
/// Get expansion bay status
ExpansionBayStatus = 0x3E1B,
/// Get hardware diagnostics
GetHwDiag = 0x3E1C,
}

pub trait EcRequest<R> {
Expand All @@ -46,6 +70,20 @@ pub trait EcRequest<R> {
fn command_version() -> u8 {
0
}
}

impl<T: EcRequest<R>, R> EcRequestRaw<R> for T {
fn command_id_u16() -> u16 {
Self::command_id() as u16
}
}

pub trait EcRequestRaw<R> {
fn command_id_u16() -> u16;
// Can optionally override this
fn command_version() -> u8 {
0
}

fn format_request(&self) -> &[u8]
where
Expand Down Expand Up @@ -75,8 +113,11 @@ pub trait EcRequest<R> {
buffer
};
let response =
ec.send_command(Self::command_id() as u16, Self::command_version(), &request)?;
trace!("send_command<{:X?}>", Self::command_id());
ec.send_command(Self::command_id_u16(), Self::command_version(), &request)?;
trace!(
"send_command<{:X?}>",
<EcCommands as FromPrimitive>::from_u16(Self::command_id_u16())
);
trace!(" Request: {:?}", request);
trace!(" Response: {:?}", response);
Ok(response)
Expand Down
154 changes: 154 additions & 0 deletions framework_lib/src/chromium_ec/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,157 @@ impl EcRequest<EcResponseDeckState> for EcRequestDeckState {
EcCommands::CheckDeckState
}
}

// TODO
#[repr(C, packed)]
pub struct EcRequestUefiAppMode {
pub enable: u8,
}

impl EcRequest<()> for EcRequestUefiAppMode {
fn command_id() -> EcCommands {
EcCommands::UefiAppMode
}
}

#[repr(C, packed)]
pub struct EcRequestUefiAppBtnStatus {}

#[repr(C, packed)]
pub struct EcResponseUefiAppBtnStatus {
pub status: u8,
}

impl EcRequest<EcResponseUefiAppBtnStatus> for EcRequestUefiAppBtnStatus {
fn command_id() -> EcCommands {
EcCommands::UefiAppBtnStatus
}
}

#[derive(Debug)]
pub enum ExpansionByStates {
ModuleEnabled = 0x01,
ModuleFault = 0x02,
HatchSwitchClosed = 0x04,
}
#[derive(Debug)]
pub enum ExpansionBayBoard {
DualInterposer,
SingleInterposer,
Invalid,
}

// pub to disable unused warnings
pub const BOARD_VERSION_0: u8 = 0;
pub const BOARD_VERSION_1: u8 = 1;
pub const BOARD_VERSION_2: u8 = 2;
pub const BOARD_VERSION_3: u8 = 3;
pub const BOARD_VERSION_4: u8 = 4;
pub const BOARD_VERSION_5: u8 = 5;
pub const BOARD_VERSION_6: u8 = 6;
pub const BOARD_VERSION_7: u8 = 7;
pub const BOARD_VERSION_8: u8 = 8;
pub const BOARD_VERSION_9: u8 = 9;
pub const BOARD_VERSION_10: u8 = 10;
pub const BOARD_VERSION_11: u8 = 11;
pub const BOARD_VERSION_12: u8 = 12;
pub const BOARD_VERSION_13: u8 = 13;
pub const BOARD_VERSION_14: u8 = 14;
pub const BOARD_VERSION_15: u8 = 15;

#[repr(C, packed)]
pub struct EcRequestExpansionBayStatus {}

#[repr(C, packed)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct EcResponseExpansionBayStatus {
pub state: u8,
pub board_id_0: u8,
pub board_id_1: u8,
}

impl EcResponseExpansionBayStatus {
pub fn module_enabled(&self) -> bool {
self.state & (ExpansionByStates::ModuleEnabled as u8) != 0
}
pub fn module_fault(&self) -> bool {
self.state & (ExpansionByStates::ModuleFault as u8) != 0
}
pub fn hatch_switch_closed(&self) -> bool {
self.state & (ExpansionByStates::HatchSwitchClosed as u8) != 0
}
pub fn expansion_bay_board(&self) -> Option<ExpansionBayBoard> {
match (self.board_id_1, self.board_id_0) {
(BOARD_VERSION_12, BOARD_VERSION_12) => Some(ExpansionBayBoard::DualInterposer),
(BOARD_VERSION_11, BOARD_VERSION_15) => Some(ExpansionBayBoard::SingleInterposer),
(BOARD_VERSION_15, BOARD_VERSION_15) => None,
_ => Some(ExpansionBayBoard::Invalid),
}
}
}

impl EcRequest<EcResponseExpansionBayStatus> for EcRequestExpansionBayStatus {
fn command_id() -> EcCommands {
EcCommands::ExpansionBayStatus
}
}

pub const DIAGNOSTICS_START: usize = 0;
pub const DIAGNOSTICS_HW_NO_BATTERY: usize = 1;
pub const DIAGNOSTICS_HW_PGOOD_3V5V: usize = 2;
pub const DIAGNOSTICS_VCCIN_AUX_VR: usize = 3;
pub const DIAGNOSTICS_SLP_S4: usize = 4;
pub const DIAGNOSTICS_HW_PGOOD_VR: usize = 5;

// Lotus: Start
pub const DIAGNOSTICS_INPUT_MODULE_FAULT: usize = 6;
pub const DIAGNOSTICS_NO_LEFT_FAN: usize = 7;
pub const DIAGNOSTICS_NO_RIGHT_FAN: usize = 8;
pub const DIAGNOSTICS_GPU_MODULE_FAULT: usize = 9;
// Lotus: End
// Azalea: Start
pub const DIAGNOSTICS_TOUCHPAD: usize = 6;
pub const DIAGNOSTICS_AUDIO_DAUGHTERBOARD: usize = 7;
pub const DIAGNOSTICS_THERMAL_SENSOR: usize = 8;
pub const DIAGNOSTICS_NOFAN: usize = 9;
// Azalea: End

// Different on azalea and lotus
// pub const DIAGNOSTICS_NO_S0: usize = 10;
// pub const DIAGNOSTICS_NO_DDR: usize = 11;
// pub const DIAGNOSTICS_NO_EDP: usize = 12;
// pub const DIAGNOSTICS_HW_FINISH: usize = 13;
/*BIOS BITS*/
// pub const DIAGNOSTICS_BIOS_BIT0: usize = 18;
// pub const DIAGNOSTICS_BIOS_BIT1: usize = 19;
// pub const DIAGNOSTICS_BIOS_BIT2: usize = 21;
// pub const DIAGNOSTICS_BIOS_BIT3: usize = 22;
// pub const DIAGNOSTICS_BIOS_BIT4: usize = 23;
// pub const DIAGNOSTICS_BIOS_BIT5: usize = 24;
// pub const DIAGNOSTICS_BIOS_BIT6: usize = 25;
// pub const DIAGNOSTICS_BIOS_BIT7: usize = 26;

#[repr(C, packed)]
pub struct EcRequestGetHwDiag {}

#[repr(C, packed)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct EcResponseGetHwDiag {
pub hw_diag: u32,
pub bios_complete: u8,
}

impl EcResponseGetHwDiag {
pub fn fan_fault(&self) -> (bool, bool) {
(
self.hw_diag & (1 << DIAGNOSTICS_NO_LEFT_FAN) != 0,
self.hw_diag & (1 << DIAGNOSTICS_NO_RIGHT_FAN) != 0,
)
}
}

impl EcRequest<EcResponseGetHwDiag> for EcRequestGetHwDiag {
fn command_id() -> EcCommands {
EcCommands::GetHwDiag
}
}
19 changes: 17 additions & 2 deletions framework_lib/src/chromium_ec/input_deck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ enum InputDeckMux {
}

#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InputModuleType {
Short,
Reserved1,
Expand Down Expand Up @@ -98,7 +98,7 @@ impl InputModuleType {
}
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InputDeckState {
/// Manual workaround during EVT
Off,
Expand Down Expand Up @@ -130,6 +130,7 @@ impl From<u8> for InputDeckState {
}
}

#[derive(Clone, PartialEq, Eq)]
pub struct InputDeckStatus {
pub state: InputDeckState,
pub hubboard_present: bool,
Expand All @@ -149,10 +150,22 @@ impl InputDeckStatus {
}
/// Whether the input deck is fully populated
pub fn fully_populated(&self) -> bool {
if matches!(self.state, InputDeckState::ForceOn | InputDeckState::On) {
return false;
}

if !self.hubboard_present {
return false;
}

if !self.touchpad_present {
return false;
}

self.top_row_fully_populated()
}

pub fn top_row_fully_populated(&self) -> bool {
self.top_row_to_array()
.iter()
.map(InputModuleType::size)
Expand Down Expand Up @@ -183,6 +196,8 @@ impl From<EcResponseDeckState> for InputDeckStatus {
}
}
}

#[derive(Clone, PartialEq, Eq)]
pub struct TopRowPositions {
/// C1 all the way left
/// B1 all the way left
Expand Down
7 changes: 4 additions & 3 deletions framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ use alloc::vec;
use alloc::vec::Vec;
#[cfg(feature = "uefi")]
use core::prelude::rust_2021::derive;
use num_traits::FromPrimitive;

use command::EcRequest;
pub use command::EcRequestRaw;
use commands::*;

use self::command::EcCommands;
Expand Down Expand Up @@ -374,8 +375,8 @@ impl CrosEcDriver for CrosEc {
}
fn send_command(&self, command: u16, command_version: u8, data: &[u8]) -> EcResult<Vec<u8>> {
debug!(
"send_command(command=0x{:X}, ver={:?}, data_len={:?})",
command,
"send_command(command={:X?}, ver={:?}, data_len={:?})",
<EcCommands as FromPrimitive>::from_u16(command),
command_version,
data.len()
);
Expand Down
2 changes: 1 addition & 1 deletion framework_lib/src/esrt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub const ADL_RETIMER01_GUID: Guid = guid!("a9c91b0c-c0b8-463d-a7da-a5d6ec646333
pub const ADL_RETIMER23_GUID: Guid = guid!("ba2e4e6e-3b0c-4f25-8a59-4c553fc86ea2");
pub const RPL_RETIMER01_GUID: Guid = guid!("0c42b824-818f-428f-8687-5efcaf059bea");
pub const RPL_RETIMER23_GUID: Guid = guid!("268ccbde-e087-420b-bf82-2212bd3f9bfc");
pub const FL16_BIOS_GUID: Guid = guid!("4496aebc-2421-5dfb-9e75-03ec44245994");
pub const FL16_BIOS_GUID: Guid = guid!("6ae76af1-c002-5d64-8e18-658d205acf34");
pub const AMD13_BIOS_GUID: Guid = guid!("b5f7dcc1-568c-50f8-a4dd-e39d1f93fda1");
pub const RPL_CSME_GUID: Guid = guid!("865d322c-6ac7-4734-b43e-55db5a557d63");

Expand Down
5 changes: 4 additions & 1 deletion framework_lib/src/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use core::prelude::v1::derive;
use log::Level;

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

Expand Down Expand Up @@ -66,6 +66,7 @@ const EC_BATT_FLAG_DISCHARGING: u8 = 0x04;
const EC_BATT_FLAG_CHARGING: u8 = 0x08;
const EC_BATT_FLAG_LEVEL_CRITICAL: u8 = 0x10;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BatteryInformation {
pub present_voltage: u32,
pub present_rate: u32,
Expand All @@ -89,6 +90,7 @@ pub struct BatteryInformation {
pub level_critical: bool,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PowerInfo {
pub ac_present: bool,
pub battery: Option<BatteryInformation>,
Expand Down Expand Up @@ -227,6 +229,7 @@ fn print_battery_information(power_info: &PowerInfo) {
);
println!(" Present Rate: {} mA", battery.present_rate);
// We only have a single battery in all our systems
// Both values are always 0
// println!(" Battery Count: {}", battery.battery_count);
// println!(" Current Battery#: {}", battery.current_battery_index);

Expand Down
6 changes: 6 additions & 0 deletions framework_lib/src/smbios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,23 @@ pub fn get_platform() -> Option<Platform> {
"Laptop" => return Some(Platform::IntelGen11),
"Laptop (12th Gen Intel Core)" => return Some(Platform::IntelGen12),
"Laptop (13th Gen Intel Core)" => return Some(Platform::IntelGen13),
"Laptop 13 (AMD Ryzen 7040Series)" => return Some(Platform::Framework13Amd),
"Laptop 13 (AMD Ryzen 7040 Series)" => return Some(Platform::Framework13Amd),
"Laptop 16 (AMD Ryzen 7040 Series)" => return Some(Platform::Framework16),
_ => {}
}
}
if let Some(family) = dmidecode_string_val(&data.family()) {
// Actually "Laptop" and "16in Laptop"
match family.as_str() {
// TGL Mainboard (I don't this ever appears in family)
"FRANBMCP" => return Some(Platform::IntelGen11),
// ADL Mainboard (I don't this ever appears in family)
"FRANMACP" => return Some(Platform::IntelGen12),
// RPL Mainboard (I don't this ever appears in family)
"FRANMCCP" => return Some(Platform::IntelGen13),
// Framework 13 AMD Mainboard
"FRANMDCP" => return Some(Platform::Framework13Amd),
// Framework 16 Mainboard
"FRANMZCP" => return Some(Platform::Framework16),
_ => {}
Expand Down

0 comments on commit a929fbc

Please sign in to comment.