From a8f5fc5ec052ea762c1600d9ac15052a5834c9f0 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 5 Oct 2020 09:44:05 -0600 Subject: [PATCH] Add fan module and implement fan_max switch --- src/board/system76/common/dgpu.c | 13 +++++------- src/board/system76/common/fan.c | 8 ++++++++ src/board/system76/common/include/board/fan.h | 20 +++++++++++++++++++ src/board/system76/common/peci.c | 13 +++++------- src/board/system76/common/power.c | 3 +++ 5 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 src/board/system76/common/fan.c create mode 100644 src/board/system76/common/include/board/fan.h diff --git a/src/board/system76/common/dgpu.c b/src/board/system76/common/dgpu.c index c76b714..9412e93 100644 --- a/src/board/system76/common/dgpu.c +++ b/src/board/system76/common/dgpu.c @@ -4,8 +4,7 @@ #if HAVE_DGPU -#include - +#include #include #include #include @@ -34,12 +33,6 @@ int16_t dgpu_temp = 0; uint8_t dgpu_duty = 0; #define DGPU_TEMP(X) ((int16_t)(X)) -#define PWM_DUTY(X) ((uint8_t)(((((uint16_t)(X)) * 255) + 99) / 100)) - -struct FanPoint { - int16_t temp; - uint8_t duty; -}; #define FAN_POINT(T, D) { .temp = DGPU_TEMP(T), .duty = PWM_DUTY(D) } @@ -154,6 +147,10 @@ void dgpu_event(void) { uint8_t heatup_duty = fan_heatup(dgpu_duty); uint8_t cooldown_duty = fan_cooldown(heatup_duty); + if (fan_max) { + // Override duty if fans are manually set to maximum + cooldown_duty = 0xFF; + } if (cooldown_duty != DCR4) { DCR4 = cooldown_duty; DEBUG("DGPU temp=%d = %d\n", dgpu_temp, cooldown_duty); diff --git a/src/board/system76/common/fan.c b/src/board/system76/common/fan.c new file mode 100644 index 0000000..979332d --- /dev/null +++ b/src/board/system76/common/fan.c @@ -0,0 +1,8 @@ +#include + +bool fan_max = false; + +void fan_reset(void) { + // Do not manually set fans to maximum speed + fan_max = false; +} diff --git a/src/board/system76/common/include/board/fan.h b/src/board/system76/common/include/board/fan.h new file mode 100644 index 0000000..c37d1c9 --- /dev/null +++ b/src/board/system76/common/include/board/fan.h @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-3.0-only + +#ifndef _BOARD_FAN_H +#define _BOARD_FAN_H + +#include +#include + +struct FanPoint { + int16_t temp; + uint8_t duty; +}; + +#define PWM_DUTY(X) ((uint8_t)(((((uint16_t)(X)) * 255) + 99) / 100)) + +extern bool fan_max; + +void fan_reset(void); + +#endif // _BOARD_FAN_H diff --git a/src/board/system76/common/peci.c b/src/board/system76/common/peci.c index 85b9a0e..9f41268 100644 --- a/src/board/system76/common/peci.c +++ b/src/board/system76/common/peci.c @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only -#include - +#include #include #include #include @@ -34,12 +33,6 @@ int16_t peci_temp = 0; uint8_t peci_duty = 0; #define PECI_TEMP(X) (((int16_t)(X)) << 6) -#define PWM_DUTY(X) ((uint8_t)(((((uint16_t)(X)) * 255) + 99) / 100)) - -struct FanPoint { - int16_t temp; - uint8_t duty; -}; #define FAN_POINT(T, D) { .temp = PECI_TEMP(T), .duty = PWM_DUTY(D) } @@ -237,6 +230,10 @@ void peci_event(void) { uint8_t heatup_duty = fan_heatup(peci_duty); uint8_t cooldown_duty = fan_cooldown(heatup_duty); + if (fan_max) { + // Override duty if fans are manually set to maximum + cooldown_duty = 0xFF; + } if (cooldown_duty != DCR2) { DCR2 = cooldown_duty; DEBUG("PECI offset=%d, temp=%d = %d\n", peci_offset, peci_temp, cooldown_duty); diff --git a/src/board/system76/common/power.c b/src/board/system76/common/power.c index d113b27..1452e6d 100644 --- a/src/board/system76/common/power.c +++ b/src/board/system76/common/power.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -337,6 +338,8 @@ static void power_cpu_reset(void) { pnp_enable(); // Reset ACPI registers acpi_reset(); + // Reset fans + fan_reset(); //TODO: reset KBC and touchpad states kbled_reset(); }