Skip to content

Commit 5ba932e

Browse files
Merge pull request #122 from FrameworkComputer/hibernate-delay
Add command to set EC hibernation delay
2 parents b697c88 + 09380be commit 5ba932e

File tree

6 files changed

+64
-0
lines changed

6 files changed

+64
-0
lines changed

framework_lib/src/chromium_ec/command.rs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub enum EcCommands {
4242
ConsoleRead = 0x0098,
4343
ChargeState = 0x00A0,
4444
ChargeCurrentLimit = 0x00A1,
45+
HibernationDelay = 0x00A8,
4546
/// List the features supported by the firmware
4647
GetFeatures = 0x000D,
4748
/// Force reboot, causes host reboot as well

framework_lib/src/chromium_ec/commands.rs

+20
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,26 @@ impl EcRequest<()> for EcRequestCurrentLimitV1 {
438438
}
439439
}
440440

441+
#[repr(C, packed)]
442+
pub struct EcRequesetHibernationDelay {
443+
/// Seconds in G3 after EC turns off, 0 to read current
444+
pub seconds: u32,
445+
}
446+
447+
#[repr(C, packed)]
448+
pub struct EcResponseHibernationDelay {
449+
pub time_g3: u32,
450+
pub time_remaining: u32,
451+
/// How long to wait in G3 until turn off
452+
pub hibernation_delay: u32,
453+
}
454+
455+
impl EcRequest<EcResponseHibernationDelay> for EcRequesetHibernationDelay {
456+
fn command_id() -> EcCommands {
457+
EcCommands::HibernationDelay
458+
}
459+
}
460+
441461
/// Supported features
442462
#[derive(Debug, FromPrimitive)]
443463
pub enum EcFeatureCode {

framework_lib/src/chromium_ec/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,19 @@ impl CrosEc {
11471147
Ok(())
11481148
}
11491149

1150+
pub fn set_ec_hib_delay(&self, seconds: u32) -> EcResult<()> {
1151+
EcRequesetHibernationDelay { seconds }.send_command(self)?;
1152+
Ok(())
1153+
}
1154+
1155+
pub fn get_ec_hib_delay(&self) -> EcResult<u32> {
1156+
let res = EcRequesetHibernationDelay { seconds: 0 }.send_command(self)?;
1157+
debug!("Time in G3: {:?}", { res.time_g3 });
1158+
debug!("Time remaining: {:?}", { res.time_remaining });
1159+
println!("EC Hibernation Delay: {:?}s", { res.hibernation_delay });
1160+
Ok(res.hibernation_delay)
1161+
}
1162+
11501163
/// Check features supported by the firmware
11511164
pub fn get_features(&self) -> EcResult<()> {
11521165
let data = EcRequestGetFeatures {}.send_command(self)?;

framework_lib/src/commandline/clap_std.rs

+6
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ struct ClapCli {
213213
#[arg(long)]
214214
reboot_ec: Option<RebootEcArg>,
215215

216+
/// Get or set EC hibernate delay (S5 to G3)
217+
#[clap(value_enum)]
218+
#[arg(long)]
219+
ec_hib_delay: Option<Option<u32>>,
220+
216221
/// Hash a file of arbitrary data
217222
#[arg(long)]
218223
hash: Option<std::path::PathBuf>,
@@ -398,6 +403,7 @@ pub fn parse(args: &[String]) -> Cli {
398403
stylus_battery: args.stylus_battery,
399404
console: args.console,
400405
reboot_ec: args.reboot_ec,
406+
ec_hib_delay: args.ec_hib_delay,
401407
hash: args.hash.map(|x| x.into_os_string().into_string().unwrap()),
402408
driver: args.driver,
403409
pd_addrs,

framework_lib/src/commandline/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ pub struct Cli {
187187
pub stylus_battery: bool,
188188
pub console: Option<ConsoleArg>,
189189
pub reboot_ec: Option<RebootEcArg>,
190+
pub ec_hib_delay: Option<Option<u32>>,
190191
pub hash: Option<String>,
191192
pub pd_addrs: Option<(u16, u16)>,
192193
pub pd_ports: Option<(u8, u8)>,
@@ -868,6 +869,11 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
868869
Err(err) => println!("Failed: {:?}", err),
869870
},
870871
}
872+
} else if let Some(delay) = &args.ec_hib_delay {
873+
if let Some(delay) = delay {
874+
print_err(ec.set_ec_hib_delay(*delay));
875+
}
876+
print_err(ec.get_ec_hib_delay());
871877
} else if args.test {
872878
println!("Self-Test");
873879
let result = selftest(&ec);

framework_lib/src/commandline/uefi.rs

+18
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub fn parse(args: &[String]) -> Cli {
100100
stylus_battery: false,
101101
console: None,
102102
reboot_ec: None,
103+
ec_hib_delay: None,
103104
hash: None,
104105
// This is the only driver that works on UEFI
105106
driver: Some(CrosEcDriverType::Portio),
@@ -462,6 +463,23 @@ pub fn parse(args: &[String]) -> Cli {
462463
None
463464
};
464465
found_an_option = true;
466+
} else if arg == "--reboot-ec" {
467+
cli.ec_hib_delay = if args.len() > i + 1 {
468+
if let Ok(delay) = args[i + 1].parse::<u32>() {
469+
if delay == 0 {
470+
println!("Invalid value for --ec-hib-delay: {}. Must be >0", delay);
471+
None
472+
} else {
473+
Some(Some(delay))
474+
}
475+
} else {
476+
println!("Invalid value for --fp-brightness. Must be amount in seconds >0");
477+
None
478+
}
479+
} else {
480+
Some(None)
481+
};
482+
found_an_option = true;
465483
} else if arg == "-t" || arg == "--test" {
466484
cli.test = true;
467485
found_an_option = true;

0 commit comments

Comments
 (0)