Skip to content

Add command to set EC hibernation delay #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -42,6 +42,7 @@ pub enum EcCommands {
ConsoleRead = 0x0098,
ChargeState = 0x00A0,
ChargeCurrentLimit = 0x00A1,
HibernationDelay = 0x00A8,
/// List the features supported by the firmware
GetFeatures = 0x000D,
/// Force reboot, causes host reboot as well
Expand Down
20 changes: 20 additions & 0 deletions framework_lib/src/chromium_ec/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,26 @@ impl EcRequest<()> for EcRequestCurrentLimitV1 {
}
}

#[repr(C, packed)]
pub struct EcRequesetHibernationDelay {
/// Seconds in G3 after EC turns off, 0 to read current
pub seconds: u32,
}

#[repr(C, packed)]
pub struct EcResponseHibernationDelay {
pub time_g3: u32,
pub time_remaining: u32,
/// How long to wait in G3 until turn off
pub hibernation_delay: u32,
}

impl EcRequest<EcResponseHibernationDelay> for EcRequesetHibernationDelay {
fn command_id() -> EcCommands {
EcCommands::HibernationDelay
}
}

/// Supported features
#[derive(Debug, FromPrimitive)]
pub enum EcFeatureCode {
Expand Down
13 changes: 13 additions & 0 deletions framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,19 @@ impl CrosEc {
Ok(())
}

pub fn set_ec_hib_delay(&self, seconds: u32) -> EcResult<()> {
EcRequesetHibernationDelay { seconds }.send_command(self)?;
Ok(())
}

pub fn get_ec_hib_delay(&self) -> EcResult<u32> {
let res = EcRequesetHibernationDelay { seconds: 0 }.send_command(self)?;
debug!("Time in G3: {:?}", { res.time_g3 });
debug!("Time remaining: {:?}", { res.time_remaining });
println!("EC Hibernation Delay: {:?}s", { res.hibernation_delay });
Ok(res.hibernation_delay)
}

/// Check features supported by the firmware
pub fn get_features(&self) -> EcResult<()> {
let data = EcRequestGetFeatures {}.send_command(self)?;
Expand Down
6 changes: 6 additions & 0 deletions framework_lib/src/commandline/clap_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ struct ClapCli {
#[arg(long)]
reboot_ec: Option<RebootEcArg>,

/// Get or set EC hibernate delay (S5 to G3)
#[clap(value_enum)]
#[arg(long)]
ec_hib_delay: Option<Option<u32>>,

/// Hash a file of arbitrary data
#[arg(long)]
hash: Option<std::path::PathBuf>,
Expand Down Expand Up @@ -398,6 +403,7 @@ pub fn parse(args: &[String]) -> Cli {
stylus_battery: args.stylus_battery,
console: args.console,
reboot_ec: args.reboot_ec,
ec_hib_delay: args.ec_hib_delay,
hash: args.hash.map(|x| x.into_os_string().into_string().unwrap()),
driver: args.driver,
pd_addrs,
Expand Down
6 changes: 6 additions & 0 deletions framework_lib/src/commandline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ pub struct Cli {
pub stylus_battery: bool,
pub console: Option<ConsoleArg>,
pub reboot_ec: Option<RebootEcArg>,
pub ec_hib_delay: Option<Option<u32>>,
pub hash: Option<String>,
pub pd_addrs: Option<(u16, u16)>,
pub pd_ports: Option<(u8, u8)>,
Expand Down Expand Up @@ -868,6 +869,11 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
Err(err) => println!("Failed: {:?}", err),
},
}
} else if let Some(delay) = &args.ec_hib_delay {
if let Some(delay) = delay {
print_err(ec.set_ec_hib_delay(*delay));
}
print_err(ec.get_ec_hib_delay());
} else if args.test {
println!("Self-Test");
let result = selftest(&ec);
Expand Down
18 changes: 18 additions & 0 deletions framework_lib/src/commandline/uefi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub fn parse(args: &[String]) -> Cli {
stylus_battery: false,
console: None,
reboot_ec: None,
ec_hib_delay: None,
hash: None,
// This is the only driver that works on UEFI
driver: Some(CrosEcDriverType::Portio),
Expand Down Expand Up @@ -462,6 +463,23 @@ pub fn parse(args: &[String]) -> Cli {
None
};
found_an_option = true;
} else if arg == "--reboot-ec" {
cli.ec_hib_delay = if args.len() > i + 1 {
if let Ok(delay) = args[i + 1].parse::<u32>() {
if delay == 0 {
println!("Invalid value for --ec-hib-delay: {}. Must be >0", delay);
None
} else {
Some(Some(delay))
}
} else {
println!("Invalid value for --fp-brightness. Must be amount in seconds >0");
None
}
} else {
Some(None)
};
found_an_option = true;
} else if arg == "-t" || arg == "--test" {
cli.test = true;
found_an_option = true;
Expand Down