From a201bcf29cf8216ba73627610c12e29af4316ad0 Mon Sep 17 00:00:00 2001 From: Winston Hoy Date: Sun, 16 Oct 2022 23:26:10 -0400 Subject: [PATCH] allow ACPI to set fan speeds Smooth ACPI fan pwm values same as EC fan curve points --- src/board/system76/common/acpi.c | 9 +++++++++ src/board/system76/common/fan.c | 9 +++++++++ src/board/system76/common/include/board/fan.h | 2 ++ 3 files changed, 20 insertions(+) diff --git a/src/board/system76/common/acpi.c b/src/board/system76/common/acpi.c index 3a36f0567..ea94d879b 100644 --- a/src/board/system76/common/acpi.c +++ b/src/board/system76/common/acpi.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -224,5 +225,13 @@ void acpi_write(uint8_t addr, uint8_t data) { case 0xFD: fbuf[3] = data; break; + case 0xCE: + acpi_peci_fan_duty = data; + break; +#if HAVE_DGPU + case 0xCF: + acpi_dgpu_fan_duty = data; + break; +#endif } } diff --git a/src/board/system76/common/fan.c b/src/board/system76/common/fan.c index 9d5f16c02..ce5c5ed92 100644 --- a/src/board/system76/common/fan.c +++ b/src/board/system76/common/fan.c @@ -15,6 +15,8 @@ #define MIN_SPEED_TO_SMOOTH PWM_DUTY(SMOOTH_FANS_MIN) bool fan_max = false; +uint8_t acpi_peci_fan_duty = 0; +uint8_t acpi_dgpu_fan_duty = 0; uint8_t last_duty_dgpu = 0; uint8_t last_duty_peci = 0; @@ -66,9 +68,15 @@ void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant { dgpu_fan_duty = peci_fan_duty > dgpu_fan_duty ? peci_fan_duty : dgpu_fan_duty; #endif + // allow for ACPI to request a higher duty + peci_fan_duty = peci_fan_duty > acpi_peci_fan_duty ? peci_fan_duty : acpi_peci_fan_duty; + dgpu_fan_duty = dgpu_fan_duty > acpi_dgpu_fan_duty ? dgpu_fan_duty : acpi_dgpu_fan_duty; + // set PECI fan duty if (peci_fan_duty != DCR2) { + TRACE("PECI acpi_fan_duty_raw=%d\n", acpi_peci_fan_duty); TRACE("PECI fan_duty_raw=%d\n", peci_fan_duty); + // allow for ACPI to request a higher duty last_duty_peci = peci_fan_duty = fan_smooth(last_duty_peci, peci_fan_duty); DCR2 = fan_max ? MAX_FAN_SPEED : peci_fan_duty; TRACE("PECI fan_duty_smoothed=%d\n", peci_fan_duty); @@ -76,6 +84,7 @@ void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant { // set dGPU fan duty if (dgpu_fan_duty != DCR4) { + TRACE("DGPU acpi_fan_duty_raw=%d\n", acpi_peci_fan_duty); TRACE("DGPU fan_duty_raw=%d\n", dgpu_fan_duty); last_duty_dgpu = dgpu_fan_duty = fan_smooth(last_duty_dgpu, dgpu_fan_duty); DCR4 = fan_max ? MAX_FAN_SPEED : dgpu_fan_duty; diff --git a/src/board/system76/common/include/board/fan.h b/src/board/system76/common/include/board/fan.h index 74a326a28..a2e974135 100644 --- a/src/board/system76/common/include/board/fan.h +++ b/src/board/system76/common/include/board/fan.h @@ -46,6 +46,8 @@ struct Fan { bool interpolate; }; +extern uint8_t acpi_dgpu_fan_duty; +extern uint8_t acpi_peci_fan_duty; extern bool fan_max; void fan_reset(void);