Skip to content

Commit 8df33dc

Browse files
committed
Add --thermal dump
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 86aae8a commit 8df33dc

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

framework_lib/src/commandline/clap_std.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ struct ClapCli {
2929
#[arg(long)]
3030
power: bool,
3131

32+
/// Print thermal information (Temperatures and Fan speed)
33+
#[arg(long)]
34+
thermal: bool,
35+
3236
/// Show information about USB-C PD ports
3337
#[arg(long)]
3438
pdports: bool,
@@ -126,6 +130,7 @@ pub fn parse(args: &[String]) -> Cli {
126130
version: args.version,
127131
esrt: args.esrt,
128132
power: args.power,
133+
thermal: args.thermal,
129134
pdports: args.pdports,
130135
pd_info: args.pd_info,
131136
dp_hdmi_info: args.dp_hdmi_info,

framework_lib/src/commandline/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub struct Cli {
104104
pub version: bool,
105105
pub esrt: bool,
106106
pub power: bool,
107+
pub thermal: bool,
107108
pub pdports: bool,
108109
pub privacy: bool,
109110
pub pd_info: bool,
@@ -492,6 +493,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
492493
}
493494
} else if args.power {
494495
power::get_and_print_power_info(&ec);
496+
} else if args.thermal {
497+
power::print_thermal(&ec);
495498
} else if args.pdports {
496499
power::get_and_print_pd_info(&ec);
497500
} else if args.info {
@@ -642,6 +645,7 @@ Options:
642645
--version Show tool version information (Add -vv for more detailed information)
643646
--esrt Display the UEFI ESRT table
644647
--power Show current power status (battery and AC)
648+
--thermal Show current power status (battery and AC)
645649
--pdports Show information about USB-C PD ports
646650
--info Show info from SMBIOS (Only on UEFI)
647651
--pd-info Show details about the PD controllers

framework_lib/src/commandline/uefi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub fn parse(args: &[String]) -> Cli {
5959
version: false,
6060
esrt: false,
6161
power: false,
62+
thermal: false,
6263
pdports: false,
6364
pd_info: false,
6465
dp_hdmi_info: false,
@@ -118,6 +119,9 @@ pub fn parse(args: &[String]) -> Cli {
118119
} else if arg == "--power" {
119120
cli.power = true;
120121
found_an_option = true;
122+
} else if arg == "--thermal" {
123+
cli.thermal = true;
124+
found_an_option = true;
121125
} else if arg == "--pdports" {
122126
cli.pdports = true;
123127
found_an_option = true;

framework_lib/src/power.rs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ use crate::ccgx::{AppVersion, Application, BaseVersion, ControllerVersion, MainP
1111
use crate::chromium_ec::command::EcRequestRaw;
1212
use crate::chromium_ec::commands::{EcRequestReadPdVersion, EcRequestUsbPdPowerInfo};
1313
use crate::chromium_ec::{print_err_ref, CrosEc, CrosEcDriver, EcResult};
14+
use crate::smbios;
1415
use crate::smbios::get_platform;
16+
use crate::util::Platform;
1517

1618
/// Maximum length of strings in memmap
1719
const EC_MEMMAP_TEXT_MAX: u16 = 8;
1820

1921
// The offset address of each type of data in mapped memory.
2022
// TODO: Move non-power values to other modules
21-
const _EC_MEMMAP_TEMP_SENSOR: u16 = 0x00; // Temp sensors 0x00 - 0x0f
22-
const _EC_MEMMAP_FAN: u16 = 0x10; // Fan speeds 0x10 - 0x17
23+
const EC_MEMMAP_TEMP_SENSOR: u16 = 0x00; // Temp sensors 0x00 - 0x0f
24+
const EC_MEMMAP_FAN: u16 = 0x10; // Fan speeds 0x10 - 0x17
2325
const _EC_MEMMAP_TEMP_SENSOR_B: u16 = 0x18; // More temp sensors 0x18 - 0x1f
2426
const _EC_MEMMAP_ID: u16 = 0x2120; // 0x20 == 'E', 0x21 == 'C'
2527
const EC_MEMMAP_ID_VERSION: u16 = 0x22; // Version of data in 0x20 - 0x2f
@@ -159,6 +161,56 @@ pub fn print_memmap_version_info(ec: &CrosEc) {
159161
let _events_ver = ec.read_memory(EC_MEMMAP_EVENTS_VERSION, 2).unwrap();
160162
}
161163

164+
fn in_c(t: u8) -> u8 {
165+
if t == 255 {
166+
t
167+
} else {
168+
t - 73
169+
}
170+
}
171+
172+
pub fn print_thermal(ec: &CrosEc) {
173+
let temps = ec.read_memory(EC_MEMMAP_TEMP_SENSOR, 0x0F).unwrap();
174+
let fans = ec.read_memory(EC_MEMMAP_FAN, 0x08).unwrap();
175+
176+
let platform = smbios::get_platform();
177+
match platform {
178+
Some(Platform::IntelGen11) | Some(Platform::IntelGen12) | Some(Platform::IntelGen13) => {
179+
println!(" F75303_Local: {:>4} C", in_c(temps[0]));
180+
println!(" F75303_CPU: {:>4} C", in_c(temps[1]));
181+
println!(" F75303_DDR: {:>4} C", in_c(temps[2]));
182+
println!(" Battery: {:>4} C", in_c(temps[3]));
183+
println!(" PECI: {:>4} C", in_c(temps[4]));
184+
println!(" F57397_VCCGT: {:>4} C", in_c(temps[5]));
185+
}
186+
Some(Platform::Framework13Amd | Platform::Framework16) => {
187+
println!(" F75303_Local: {:>4} C", in_c(temps[0]));
188+
println!(" F75303_CPU: {:>4} C", in_c(temps[1]));
189+
println!(" F75303_DDR: {:>4} C", in_c(temps[2]));
190+
println!(" APU: {:>4} C", in_c(temps[3]));
191+
if matches!(platform, Some(Platform::Framework16)) {
192+
println!(" dGPU VR: {:>4} C", in_c(temps[4]));
193+
println!(" dGPU VRAM: {:>4} C", in_c(temps[5]));
194+
println!(" dGPU AMB: {:>4} C", in_c(temps[6]));
195+
println!(" dGPU temp: {:>4} C", in_c(temps[7]));
196+
}
197+
}
198+
_ => {
199+
println!(" Temp 0: {:>4} C", in_c(temps[0]));
200+
println!(" Temp 1: {:>4} C", in_c(temps[1]));
201+
println!(" Temp 2: {:>4} C", in_c(temps[2]));
202+
println!(" Temp 3: {:>4} C", in_c(temps[3]));
203+
println!(" Temp 4: {:>4} C", in_c(temps[4]));
204+
println!(" Temp 5: {:>4} C", in_c(temps[5]));
205+
println!(" Temp 6: {:>4} C", in_c(temps[6]));
206+
println!(" Temp 7: {:>4} C", in_c(temps[7]));
207+
}
208+
}
209+
210+
let fan0 = u16::from_le_bytes([fans[0], fans[1]]);
211+
println!(" Fan Speed: {:>4} RPM", fan0);
212+
}
213+
162214
// TODO: Use Result
163215
pub fn power_info(ec: &CrosEc) -> Option<PowerInfo> {
164216
let battery_flag = ec.read_memory(EC_MEMMAP_BATT_FLAG, 1)?[0];

0 commit comments

Comments
 (0)