Skip to content

Commit

Permalink
fan: Remove HEATUP, reduce COOLDOWN
Browse files Browse the repository at this point in the history
Since these values actually use seconds for the unit again, their use
needs to be re-evaluated.

`HEATUP` can be removed entirely. We want the quick response to rising
temps without it instantly going to max from temp spikes. This is
handled by the new hardware control, which limits how quickly the fan
duty can change (3.9%/s).

`COOLDOWN` is still useful for hysteresis, to provide extra cooling as
temps come down, but does not need to run for 10/20s it is set to.

Signed-off-by: Tim Crawford <[email protected]>
  • Loading branch information
crawfxrd committed Dec 30, 2024
1 parent 6420539 commit e18388c
Show file tree
Hide file tree
Showing 18 changed files with 11 additions and 111 deletions.
4 changes: 0 additions & 4 deletions src/board/system76/addw3/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand All @@ -60,8 +58,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\
"

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DBOARD_FAN2_HEATUP=5
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand Down
4 changes: 0 additions & 4 deletions src/board/system76/addw4/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(60, 28), \
FAN_POINT(65, 28), \
Expand All @@ -58,8 +56,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\
"

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DBOARD_FAN2_HEATUP=5
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(60, 28), \
FAN_POINT(65, 28), \
Expand Down
4 changes: 0 additions & 4 deletions src/board/system76/bonw15-b/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand All @@ -67,8 +65,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\
"

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DBOARD_FAN2_HEATUP=5
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand Down
4 changes: 0 additions & 4 deletions src/board/system76/bonw15/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand All @@ -65,8 +63,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\
"

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DBOARD_FAN2_HEATUP=5
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand Down
56 changes: 11 additions & 45 deletions src/board/system76/common/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,10 @@ uint16_t fan2_rpm = 0;
#define FAN1_PWM_MIN 0
#endif

// Fan speed is the lowest requested over HEATUP seconds
#ifndef BOARD_FAN1_HEATUP
#define BOARD_FAN1_HEATUP 4
#endif

static uint8_t FAN1_HEATUP[BOARD_FAN1_HEATUP] = { 0 };

// Fan speed is the highest HEATUP speed over COOLDOWN seconds
#ifndef BOARD_FAN1_COOLDOWN
#define BOARD_FAN1_COOLDOWN 10
#endif
// Use highest duty over last COOLDOWN seconds.
#define FAN1_COOLDOWN_SEC 5

static uint8_t FAN1_COOLDOWN[BOARD_FAN1_COOLDOWN] = { 0 };
static uint8_t FAN1_COOLDOWN[FAN1_COOLDOWN_SEC] = { 0 };

// Fan curve with temperature in degrees C, duty cycle in percent
static const struct FanPoint __code FAN1_POINTS[] = {
Expand All @@ -62,8 +53,6 @@ static const struct FanPoint __code FAN1_POINTS[] = {
static const struct Fan __code FAN1 = {
.points = FAN1_POINTS,
.points_size = ARRAY_SIZE(FAN1_POINTS),
.heatup = FAN1_HEATUP,
.heatup_size = ARRAY_SIZE(FAN1_HEATUP),
.cooldown = FAN1_COOLDOWN,
.cooldown_size = ARRAY_SIZE(FAN1_COOLDOWN),
.pwm_min = PWM_DUTY(FAN1_PWM_MIN),
Expand All @@ -75,19 +64,10 @@ static const struct Fan __code FAN1 = {
#define FAN2_PWM_MIN 0
#endif

// Fan speed is the lowest requested over HEATUP seconds
#ifndef BOARD_FAN2_HEATUP
#define BOARD_FAN2_HEATUP 4
#endif

static uint8_t FAN2_HEATUP[BOARD_FAN2_HEATUP] = { 0 };

// Fan speed is the highest HEATUP speed over COOLDOWN seconds
#ifndef BOARD_FAN2_COOLDOWN
#define BOARD_FAN2_COOLDOWN 10
#endif
// Use highest duty over last COOLDOWN seconds.
#define FAN2_COOLDOWN_SEC 5

static uint8_t FAN2_COOLDOWN[BOARD_FAN2_COOLDOWN] = { 0 };
static uint8_t FAN2_COOLDOWN[FAN2_COOLDOWN_SEC] = { 0 };

// Fan curve with temperature in degrees C, duty cycle in percent
static const struct FanPoint __code FAN2_POINTS[] = {
Expand All @@ -101,8 +81,6 @@ static const struct FanPoint __code FAN2_POINTS[] = {
static const struct Fan __code FAN2 = {
.points = FAN2_POINTS,
.points_size = ARRAY_SIZE(FAN2_POINTS),
.heatup = FAN2_HEATUP,
.heatup_size = ARRAY_SIZE(FAN2_HEATUP),
.cooldown = FAN2_COOLDOWN,
.cooldown_size = ARRAY_SIZE(FAN2_COOLDOWN),
.pwm_min = PWM_DUTY(FAN2_PWM_MIN),
Expand Down Expand Up @@ -137,22 +115,11 @@ static uint8_t fan_duty(const struct Fan *const fan, int16_t temp) {
return CTR0;
}

static uint8_t fan_heatup(const struct Fan *const fan, uint8_t duty) {
uint8_t lowest = duty;

uint8_t i;
for (i = 0; (i + 1) < fan->heatup_size; i++) {
uint8_t value = fan->heatup[i + 1];
if (value < lowest) {
lowest = value;
}
fan->heatup[i] = value;
}
fan->heatup[i] = duty;

return lowest;
}

// Apply hysteresis: Use the highest duty over the last COOLDOWN seconds.
// Keep the fans at higher duties for a short time as the system cools to help
// reduce temps below the target duty.
// Useful for addressing the case where fans will constantly start/stop at the
// point 0 temperature threshold.
static uint8_t fan_cooldown(const struct Fan *const fan, uint8_t duty) {
uint8_t highest = duty;

Expand All @@ -173,7 +140,6 @@ static uint8_t fan_get_duty(const struct Fan *const fan, int16_t temp) {
uint8_t duty;

duty = fan_duty(fan, temp);
duty = fan_heatup(fan, duty);
duty = fan_cooldown(fan, duty);

return duty;
Expand Down
2 changes: 0 additions & 2 deletions src/board/system76/common/include/board/fan.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ struct FanPoint {
struct Fan {
const struct FanPoint *points;
uint8_t points_size;
uint8_t *heatup;
uint8_t heatup_size;
uint8_t *cooldown;
uint8_t cooldown_size;
uint8_t pwm_min;
Expand Down
4 changes: 0 additions & 4 deletions src/board/system76/gaze16-3050/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand All @@ -56,8 +54,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\
"

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DBOARD_FAN2_HEATUP=5
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand Down
4 changes: 0 additions & 4 deletions src/board/system76/gaze16-3060-b/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand All @@ -59,8 +57,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\
"

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS+=-DBOARD_FAN2_HEATUP=5
CFLAGS+=-DBOARD_FAN2_COOLDOWN=20
CFLAGS+=-DBOARD_FAN2_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand Down
4 changes: 0 additions & 4 deletions src/board/system76/gaze16-3060/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand All @@ -56,8 +54,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\
"

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DBOARD_FAN2_HEATUP=5
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand Down
4 changes: 0 additions & 4 deletions src/board/system76/gaze17-3050/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ CFLAGS += -DI2C_DGPU=I2C_1
# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DFAN1_PWM_MIN=20
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(50, 28), \
FAN_POINT(58, 28), \
Expand All @@ -61,8 +59,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DFAN2_PWM_MIN=20
CFLAGS += -DBOARD_FAN2_HEATUP=5
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(50, 28), \
FAN_POINT(58, 28), \
Expand Down
4 changes: 0 additions & 4 deletions src/board/system76/gaze17-3060-b/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand All @@ -60,8 +58,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\
"

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DBOARD_FAN2_HEATUP=5
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand Down
4 changes: 0 additions & 4 deletions src/board/system76/gaze17-3060/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand All @@ -57,8 +55,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\
"

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DBOARD_FAN2_HEATUP=5
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand Down
4 changes: 0 additions & 4 deletions src/board/system76/gaze18/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand All @@ -59,8 +57,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\
"

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DBOARD_FAN2_HEATUP=5
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
Expand Down
4 changes: 0 additions & 4 deletions src/board/system76/oryp10/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(50, 40), \
FAN_POINT(55, 40), \
Expand All @@ -65,8 +63,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\
"

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DBOARD_FAN2_HEATUP=5
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(50, 40), \
FAN_POINT(56, 40), \
Expand Down
4 changes: 0 additions & 4 deletions src/board/system76/oryp11/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ CFLAGS += -DI2C_DGPU=I2C_1
# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DFAN1_PWM_MIN=28
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(60, 28), \
FAN_POINT(65, 28), \
Expand All @@ -70,8 +68,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DFAN2_PWM_MIN=28
CFLAGS += -DBOARD_FAN2_HEATUP=5
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(60, 28), \
FAN_POINT(65, 28), \
Expand Down
4 changes: 0 additions & 4 deletions src/board/system76/oryp12/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(50, 30), \
FAN_POINT(60, 30), \
Expand All @@ -64,8 +62,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\
"

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DBOARD_FAN2_HEATUP=5
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(50, 30), \
FAN_POINT(60, 30), \
Expand Down
4 changes: 0 additions & 4 deletions src/board/system76/oryp9/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(50, 40), \
FAN_POINT(55, 40), \
Expand All @@ -62,8 +60,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\
"

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DBOARD_FAN2_HEATUP=5
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(50, 40), \
FAN_POINT(56, 40), \
Expand Down
4 changes: 0 additions & 4 deletions src/board/system76/serw13/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ CFLAGS += -DI2C_DGPU=I2C_1
# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DFAN1_PWM_MIN=28
CFLAGS += -DBOARD_FAN1_HEATUP=5
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(50, 28), \
FAN_POINT(55, 28), \
Expand All @@ -67,8 +65,6 @@ CFLAGS += -DBOARD_FAN1_POINTS="\

CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DFAN2_PWM_MIN=28
CFLAGS += -DBOARD_FAN2_HEATUP=5
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(50, 28), \
FAN_POINT(55, 28), \
Expand Down

0 comments on commit e18388c

Please sign in to comment.