Skip to content

Commit

Permalink
feat: zero RPM settings (#11)
Browse files Browse the repository at this point in the history
* feat: add fan zero rpm functionality

* feat: new zero rpm controls
  • Loading branch information
ilya-zlobintsev authored Nov 13, 2024
1 parent 513a74b commit 747eeff
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
48 changes: 47 additions & 1 deletion src/gpu_handle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,29 @@ impl GpuHandle {
self.read_fan_info("fan_minimum_pwm", "FAN_MINIMUM_PWM", "MINIMUM_PWM")
}

/// Gets the current fan zero RPM mode.
///
/// Only available on Navi3x (RDNA 3) or newer.
pub fn get_fan_zero_rpm_enable(&self) -> Result<bool> {
self.read_fan_info(
"fan_zero_rpm_enable",
"FAN_ZERO_RPM_ENABLE",
"ZERO_RPM_ENABLE",
)
.map(|info| info.current == 1)
}

/// Gets the current fan zero RPM stop temperature.
///
/// Only available on Navi3x (RDNA 3) or newer.
pub fn get_fan_zero_rpm_stop_temperature(&self) -> Result<FanInfo> {
self.read_fan_info(
"fan_zero_rpm_stop_temperature",
"FAN_ZERO_RPM_STOP_TEMPERATURE",
"ZERO_RPM_STOP_TEMPERATURE",
)
}

fn set_fan_value(
&self,
file: &str,
Expand Down Expand Up @@ -508,11 +531,34 @@ impl GpuHandle {
/// Sets the fan minimum PWM. Value is a percentage.
///
/// Only available on Navi3x (RDNA 3) or newer.
/// <https://kernel.org/doc/html/latest/gpu/amdgpu/thermal.html#fan-minimum-pwm>
pub fn set_fan_minimum_pwm(&self, value: u32) -> Result<CommitHandle> {
self.set_fan_value("fan_minimum_pwm", value, "FAN_MINIMUM_PWM", "MINIMUM_PWM")
}

/// Sets the current fan zero RPM mode.
///
/// Only available on Navi3x (RDNA 3) or newer.
pub fn set_fan_zero_rpm_enable(&self, enabled: bool) -> Result<CommitHandle> {
self.set_fan_value(
"fan_zero_rpm_enable",
enabled as u32,
"FAN_ZERO_RPM_ENABLE",
"ZERO_RPM_ENABLE",
)
}

/// Sets the fan zero RPM stop temperature.
///
/// Only available on Navi3x (RDNA 3) or newer.
pub fn set_fan_zero_rpm_stop_temperature(&self, value: u32) -> Result<CommitHandle> {
self.set_fan_value(
"fan_zero_rpm_stop_temperature",
value,
"FAN_ZERO_RPM_STOP_TEMPERATURE",
"ZERO_RPM_STOP_TEMPERATURE",
)
}

fn reset_fan_value(&self, file: &str) -> Result<()> {
let file_path = self.sysfs_path.join("gpu_od/fan_ctrl").join(file);
let mut file = File::create(file_path)?;
Expand Down
4 changes: 4 additions & 0 deletions tests/data/rx7800xt/gpu_od/fan_ctrl/fan_zero_rpm_enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FAN_ZERO_RPM_ENABLE:
0
OD_RANGE:
ZERO_RPM_ENABLE: 0 1
4 changes: 4 additions & 0 deletions tests/rx7800xt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ test_with_handle! {
get_fan_curve => {
GpuHandle::get_fan_curve,
Ok(FanCurve { points: vec![(0, 0); 5].into_boxed_slice(), allowed_ranges: Some(FanCurveRanges {temperature_range: 25..=100, speed_range: 20..=100 })})
},
get_fan_zero_rpm => {
GpuHandle::get_fan_zero_rpm_enable,
Ok(false),
}
}

0 comments on commit 747eeff

Please sign in to comment.