From 55bc53986b3835b73283651665f1e42cdaa52f51 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 3116e4415..fab88ab94 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 @@ -65,6 +66,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 66ea199b0..51543a987 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; @@ -68,8 +70,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; @@ -78,6 +85,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 4551a3d43..52d5fad63 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);