Skip to content

Commit

Permalink
fan: Allow FAN2 without dGPU
Browse files Browse the repository at this point in the history
Fully support fan points for the second fan on darp10.

Signed-off-by: Tim Crawford <[email protected]>
  • Loading branch information
crawfxrd committed Jul 4, 2024
1 parent 1ce027b commit 2905938
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions src/board/system76/common/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static struct Fan __code FAN1 = {
.interpolate = SMOOTH_FANS != 0,
};

#if CONFIG_HAVE_DGPU
#ifdef FAN2_PWM

// Fan speed is the lowest requested over HEATUP seconds
#ifndef BOARD_FAN2_HEATUP
Expand Down Expand Up @@ -101,7 +101,7 @@ static struct Fan __code FAN2 = {
.interpolate = SMOOTH_FANS != 0,
};

#endif // CONFIG_HAVE_DGPU
#endif // FAN2_PWM

void fan_reset(void) {
// Do not manually set fans to maximum speed
Expand Down Expand Up @@ -209,52 +209,32 @@ static uint8_t fan_cooldown(const struct Fan *const fan, uint8_t duty) {
return highest;
}

static uint8_t get_fan1_duty(void) {
uint8_t duty;

if (power_state == POWER_STATE_S0) {
duty = fan_duty(&FAN1, peci_temp);
if (fan_max) {
duty = PWM_DUTY(100);
} else {
duty = fan_heatup(&FAN1, duty);
duty = fan_cooldown(&FAN1, duty);
}
} else {
duty = PWM_DUTY(0);
}

return duty;
}

#if CONFIG_HAVE_DGPU
static uint8_t get_fan2_duty(void) {
static uint8_t fan_get_duty(const struct Fan *const fan, int16_t temp) {
uint8_t duty;

if (power_state == POWER_STATE_S0) {
duty = fan_duty(&FAN2, dgpu_temp);
duty = fan_duty(fan, temp);
if (fan_max) {
duty = PWM_DUTY(100);
} else {
duty = fan_heatup(&FAN2, duty);
duty = fan_cooldown(&FAN2, duty);
duty = fan_heatup(fan, duty);
duty = fan_cooldown(fan, duty);
}
} else {
duty = PWM_DUTY(0);
}

return duty;
}
#else
static uint8_t get_fan2_duty(void) {
return PWM_DUTY(0);
}
#endif // CONFIG_HAVE_DGPU

void fan_update_duty(void) {
uint8_t fan1_duty = get_fan1_duty();
#if defined(FAN2_PWM) && !CONFIG_HAVE_DGPU
int16_t dgpu_temp = peci_temp;
#endif

uint8_t fan1_duty = fan_get_duty(&FAN1, peci_temp);
#ifdef FAN2_PWM
uint8_t fan2_duty = get_fan2_duty();
uint8_t fan2_duty = fan_get_duty(&FAN2, dgpu_temp);

#if SYNC_FANS != 0
fan1_duty = MAX(fan1_duty, fan2_duty);
Expand Down

0 comments on commit 2905938

Please sign in to comment.