From b1a2679afa2c8a71e0cbfd9566eebc61738fc402 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 | 8 ++++++++ src/board/system76/common/include/board/fan.h | 2 ++ 3 files changed, 19 insertions(+) diff --git a/src/board/system76/common/acpi.c b/src/board/system76/common/acpi.c index 192fc8431..ddf05145d 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 @@ -52,6 +53,14 @@ void fcommand(void) { break; } break; + case 0xCE: + acpi_peci_fan_duty = fbuf[0]; + break; +#if HAVE_DGPU + case 0xCF: + acpi_dgpu_fan_duty = fbuf[0]; + break; +#endif } } diff --git a/src/board/system76/common/fan.c b/src/board/system76/common/fan.c index 9d5f16c02..c82a8c8ed 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,8 +68,13 @@ 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); last_duty_peci = peci_fan_duty = fan_smooth(last_duty_peci, peci_fan_duty); DCR2 = fan_max ? MAX_FAN_SPEED : peci_fan_duty; @@ -76,6 +83,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);