Skip to content

Commit dc460b9

Browse files
committed
--thermal: Remove hardcoded names
We can figure them out from EC_CMD_TEMP_SENSOR_GET_INFO Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 8ee5f17 commit dc460b9

2 files changed

Lines changed: 47 additions & 106 deletions

File tree

EXAMPLES.md

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -481,13 +481,16 @@ Board IDs
481481
Example on one system, note that different systems have different thermal
482482
sensors and number of fans, so your output may look different:
483483

484+
The sensor names are reported by the EC firmware:
485+
484486
```
485487
> sudo framework_tool --thermal
486-
F75303_Local: 43 C
487-
F75303_CPU: 44 C
488-
F75303_DDR: 39 C
489-
APU: 62 C
490-
API Fan: 0 RPM
488+
local_f75397@4c: 36 C
489+
cpu_f75303@4d: 37 C
490+
battery_temp@b: 32 C
491+
ddr_f75303@4d: 35 C
492+
peci-temp: 42 C
493+
APU Fan: 0 RPM
491494
AP Throttle Status
492495
Soft: false
493496
Hard: false
@@ -571,30 +574,33 @@ Accelerometers:
571574
> sudo framework_tool --fansetduty 100
572575
> sudo framework_tool --fansetduty 0 100
573576
> sudo framework_tool --thermal
574-
F75303_Local: 40 C
575-
F75303_CPU: 41 C
576-
F75303_DDR: 37 C
577-
APU: 42 C
578-
APU Fan: 7281 RPM
577+
local_f75397@4c: 40 C
578+
cpu_f75303@4d: 41 C
579+
battery_temp@b: 32 C
580+
ddr_f75303@4d: 37 C
581+
peci-temp: 42 C
582+
APU Fan: 7281 RPM
579583
580584
# Set a target RPM (all or just fan ID=0)
581585
> sudo framework_tool --fansetrpm 3141
582586
> sudo framework_tool --fansetrpm 0 3141
583587
> sudo framework_tool --thermal
584-
F75303_Local: 41 C
585-
F75303_CPU: 42 C
586-
F75303_DDR: 37 C
587-
APU: 44 C
588-
APU Fan: 3171 RPM
588+
local_f75397@4c: 41 C
589+
cpu_f75303@4d: 42 C
590+
battery_temp@b: 32 C
591+
ddr_f75303@4d: 37 C
592+
peci-temp: 44 C
593+
APU Fan: 3171 RPM
589594
590595
# And back to normal
591596
> sudo framework_tool --autofanctrl
592597
> sudo framework_tool --thermal
593-
F75303_Local: 40 C
594-
F75303_CPU: 40 C
595-
F75303_DDR: 38 C
596-
APU: 42 C
597-
APU Fan: 0 RPM
598+
local_f75397@4c: 40 C
599+
cpu_f75303@4d: 40 C
600+
battery_temp@b: 32 C
601+
ddr_f75303@4d: 38 C
602+
peci-temp: 42 C
603+
APU Fan: 0 RPM
598604
599605
# Or just for a specific fan (e.g. on Framework Desktop)
600606
> sudo framework_tool --autofanctrl 0

framework_lib/src/power.rs

Lines changed: 21 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::chromium_ec::command::EcRequestRaw;
1414
use crate::chromium_ec::commands::*;
1515
use crate::chromium_ec::*;
1616
use crate::smbios;
17-
use crate::util::{Platform, PlatformFamily};
17+
use crate::util::PlatformFamily;
1818

1919
/// Maximum length of strings in memmap
2020
const EC_MEMMAP_TEXT_MAX: u16 = 8;
@@ -477,92 +477,27 @@ pub fn print_thermal(ec: &CrosEc) {
477477
let temps = ec.read_memory(EC_MEMMAP_TEMP_SENSOR, 0x0F).unwrap();
478478
let fans = ec.read_memory(EC_MEMMAP_FAN, 0x08).unwrap();
479479

480-
let platform = smbios::get_platform();
481480
let family = smbios::get_family();
482-
let remaining_sensors = match platform {
483-
Some(Platform::IntelGen11) | Some(Platform::IntelGen12) | Some(Platform::IntelGen13) => {
484-
println!(" F75303_Local: {:>4}", TempSensor::from(temps[0]));
485-
println!(" F75303_CPU: {:>4}", TempSensor::from(temps[1]));
486-
println!(" F75303_DDR: {:>4}", TempSensor::from(temps[2]));
487-
println!(" Battery: {:>4}", TempSensor::from(temps[3]));
488-
println!(" PECI: {:>4}", TempSensor::from(temps[4]));
489-
if matches!(
490-
platform,
491-
Some(Platform::IntelGen12) | Some(Platform::IntelGen13)
492-
) {
493-
println!(" F57397_VCCGT: {:>4}", TempSensor::from(temps[5]));
494-
}
495-
2
496-
}
497-
498-
Some(Platform::IntelCoreUltra1) | Some(Platform::IntelCoreUltra3) => {
499-
println!(" F75303_Local: {:>4}", TempSensor::from(temps[0]));
500-
println!(" F75303_CPU: {:>4}", TempSensor::from(temps[1]));
501-
println!(" Battery: {:>4}", TempSensor::from(temps[2]));
502-
println!(" F75303_DDR: {:>4}", TempSensor::from(temps[3]));
503-
println!(" PECI: {:>4}", TempSensor::from(temps[4]));
504-
3
505-
}
506-
507-
Some(Platform::Framework12IntelGen13) => {
508-
println!(" F75303_CPU: {:>4}", TempSensor::from(temps[0]));
509-
println!(" F75303_Skin: {:>4}", TempSensor::from(temps[1]));
510-
println!(" F75303_Local: {:>4}", TempSensor::from(temps[2]));
511-
println!(" Battery: {:>4}", TempSensor::from(temps[3]));
512-
println!(" PECI: {:>4}", TempSensor::from(temps[4]));
513-
println!(" Charger IC {:>4}", TempSensor::from(temps[5]));
514-
2
515-
}
516-
517-
Some(
518-
Platform::Framework13Amd7080
519-
| Platform::Framework13AmdAi300
520-
| Platform::Framework16Amd7080
521-
| Platform::Framework16AmdAi300,
522-
) => {
523-
println!(" F75303_Local: {:>4}", TempSensor::from(temps[0]));
524-
println!(" F75303_CPU: {:>4}", TempSensor::from(temps[1]));
525-
println!(" F75303_DDR: {:>4}", TempSensor::from(temps[2]));
526-
println!(" APU: {:>4}", TempSensor::from(temps[3]));
527-
if family == Some(PlatformFamily::Framework16) {
528-
println!(" dGPU VR: {:>4}", TempSensor::from(temps[4]));
529-
println!(" dGPU VRAM: {:>4}", TempSensor::from(temps[5]));
530-
println!(" dGPU AMB: {:>4}", TempSensor::from(temps[6]));
531-
println!(" dGPU temp: {:>4}", TempSensor::from(temps[7]));
532-
0
533-
} else {
534-
4
535-
}
536-
}
537481

538-
Some(Platform::FrameworkDesktopAmdAiMax300) => {
539-
println!(" F75303_APU: {:>4}", TempSensor::from(temps[0]));
540-
println!(" F75303_DDR: {:>4}", TempSensor::from(temps[1]));
541-
println!(" F75303_AMB: {:>4}", TempSensor::from(temps[2]));
542-
println!(" APU: {:>4}", TempSensor::from(temps[3]));
543-
println!(" Virtual: {:>4}", TempSensor::from(temps[4]));
544-
3
545-
}
546-
547-
_ => {
548-
println!(" Temp 0: {:>4}", TempSensor::from(temps[0]));
549-
println!(" Temp 1: {:>4}", TempSensor::from(temps[1]));
550-
println!(" Temp 2: {:>4}", TempSensor::from(temps[2]));
551-
println!(" Temp 3: {:>4}", TempSensor::from(temps[3]));
552-
println!(" Temp 4: {:>4}", TempSensor::from(temps[4]));
553-
println!(" Temp 5: {:>4}", TempSensor::from(temps[5]));
554-
println!(" Temp 6: {:>4}", TempSensor::from(temps[6]));
555-
println!(" Temp 7: {:>4}", TempSensor::from(temps[7]));
556-
0
557-
}
558-
};
559-
560-
// Just in case EC has more sensors than we know about, print them
561-
for (i, temp) in temps.iter().enumerate().take(8).skip(8 - remaining_sensors) {
482+
let mut sensors = vec![];
483+
for (i, temp) in temps.iter().enumerate() {
562484
let temp = TempSensor::from(*temp);
563-
if temp != TempSensor::NotPresent {
564-
println!(" Temp {}: {:>4}", i, temp);
485+
if temp == TempSensor::NotPresent {
486+
continue;
565487
}
488+
// All our EC firmware supports reporting the sensor name
489+
let name = ec
490+
.get_temp_sensor_name(i as u8)
491+
.unwrap_or_else(|_| format!("Temp {}", i));
492+
sensors.push((name, temp));
493+
}
494+
let width = sensors
495+
.iter()
496+
.map(|(name, _)| name.len() + 1)
497+
.max()
498+
.unwrap_or(13);
499+
for (name, temp) in sensors {
500+
println!(" {:<width$} {:>4}", format!("{name}:"), temp);
566501
}
567502

568503
for i in 0..EC_FAN_SPEED_ENTRIES {
@@ -580,11 +515,11 @@ pub fn print_thermal(ec: &CrosEc) {
580515

581516
let fan = u16::from_le_bytes([fans[i * 2], fans[1 + i * 2]]);
582517
if fan == EC_FAN_SPEED_STALLED_DEPRECATED {
583-
println!(" {name:<11} {:>4} RPM (Stalled)", fan);
518+
println!(" {name:<width$} {:>4} RPM (Stalled)", fan);
584519
} else if fan == EC_FAN_SPEED_NOT_PRESENT {
585-
info!(" {name:<11} Not present");
520+
info!(" {name:<width$} Not present");
586521
} else {
587-
println!(" {name:<11} {:>4} RPM", fan);
522+
println!(" {name:<width$} {:>4} RPM", fan);
588523
}
589524
}
590525

0 commit comments

Comments
 (0)