Skip to content

Commit

Permalink
Sync dGPU and PECI fans (at highest requested duty)
Browse files Browse the repository at this point in the history
  • Loading branch information
curiousercreative committed Apr 16, 2021
1 parent 73b4e42 commit ae3c5d4
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/board/system76/common/dgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void dgpu_init(void) {
i2c_reset(&I2C_DGPU, true);
}

void dgpu_event(void) {
uint8_t dgpu_get_fan_duty(void) {
uint8_t duty;
if (power_state == POWER_STATE_S0 && gpio_get(&DGPU_PWR_EN) && !gpio_get(&GC6_FB_EN)) {
// Use I2CS if in S0 state
Expand Down Expand Up @@ -91,16 +91,16 @@ void dgpu_event(void) {
duty = fan_cooldown(&FAN, duty);
}

if (duty != DCR4) {
DCR4 = duty;
DEBUG("DGPU temp=%d = %d\n", dgpu_temp, duty);
}
DEBUG("DGPU temp=%d\n", dgpu_temp);
return duty;
}

#else

void dgpu_init(void) {}

void dgpu_event(void) {}
uint8_t dgpu_get_fan_duty(void) {
return PWM_DUTY(0);
}

#endif // HAVE_DGPU
28 changes: 26 additions & 2 deletions src/board/system76/common/fan.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// SPDX-License-Identifier: GPL-3.0-only

#include <board/fan.h>
#include <common/debug.h>
#include <ec/pwm.h>

bool fan_max = false;

#define max_speed PWM_DUTY(100)
#define min_speed PWM_DUTY(0)

void fan_reset(void) {
// Do not manually set fans to maximum speed
fan_max = false;
Expand All @@ -21,7 +26,7 @@ uint8_t fan_duty(const struct Fan * fan, int16_t temp) __reentrant {
} else if (temp < cur->temp) {
// If lower than first temp, return 0%
if (i == 0) {
return PWM_DUTY(0);
return min_speed;
} else {
const struct FanPoint * prev = &fan->points[i - 1];

Expand All @@ -43,7 +48,26 @@ uint8_t fan_duty(const struct Fan * fan, int16_t temp) __reentrant {
}

// If no point is found, return 100%
return PWM_DUTY(100);
return max_speed;
}

void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant {
#ifdef SYNC_FANS
peci_fan_duty = peci_fan_duty > dgpu_fan_duty ? peci_fan_duty : dgpu_fan_duty;
dgpu_fan_duty = peci_fan_duty > dgpu_fan_duty ? peci_fan_duty : dgpu_fan_duty;
#endif

// set PECI fan duty
if (peci_fan_duty != DCR2) {
DCR2 = peci_fan_duty;
DEBUG("PECI fan_duty=%d\n", peci_fan_duty);
}

// set dGPU fan duty
if (dgpu_fan_duty != DCR4) {
DCR4 = dgpu_fan_duty;
DEBUG("DGPU fan_duty=%d\n", dgpu_fan_duty);
}
}

uint8_t fan_heatup(const struct Fan * fan, uint8_t duty) __reentrant {
Expand Down
2 changes: 1 addition & 1 deletion src/board/system76/common/include/board/dgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
#endif // HAVE_DGPU

void dgpu_init(void);
void dgpu_event(void);
uint8_t dgpu_get_fan_duty(void);

#endif // _BOARD_DGPU_H
1 change: 1 addition & 0 deletions src/board/system76/common/include/board/fan.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern bool fan_max;
void fan_reset(void);

uint8_t fan_duty(const struct Fan * fan, int16_t temp) __reentrant;
void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant;
uint8_t fan_heatup(const struct Fan * fan, uint8_t duty) __reentrant;
uint8_t fan_cooldown(const struct Fan * fan, uint8_t duty) __reentrant;

Expand Down
2 changes: 1 addition & 1 deletion src/board/system76/common/include/board/peci.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ extern int16_t peci_temp;

void peci_init(void);
int peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data);
void peci_event(void);
uint8_t peci_get_fan_duty(void);

#endif // _BOARD_PECI_H
9 changes: 2 additions & 7 deletions src/board/system76/common/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,8 @@ void main(void) {
if (last_time > time || (time - last_time) >= 1000) {
last_time = time;

// Updates fan status and temps
peci_event();

#if HAVE_DGPU
// Updates discrete GPU fan status and temps
dgpu_event();
#endif
// Update fan speeds
fan_duty_set(peci_get_fan_duty(), dgpu_get_fan_duty());

// Updates battery status
battery_event();
Expand Down
8 changes: 3 additions & 5 deletions src/board/system76/common/peci.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
}

// PECI information can be found here: https://www.intel.com/content/dam/www/public/us/en/documents/design-guides/core-i7-lga-2011-guide.pdf
void peci_event(void) {
uint8_t peci_get_fan_duty(void) {
uint8_t duty;

#if EC_ESPI
Expand Down Expand Up @@ -180,8 +180,6 @@ void peci_event(void) {
duty = fan_cooldown(&FAN, duty);
}

if (duty != DCR2) {
DCR2 = duty;
DEBUG("PECI temp=%d = %d\n", peci_temp, duty);
}
DEBUG("PECI temp=%d\n", peci_temp);
return duty;
}
2 changes: 1 addition & 1 deletion src/board/system76/common/pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void pwm_init(void) {
// Set cycle time to 255 + 1
CTR0 = 255;

// Turn off CPU fan (temperature control in peci_event)
// Turn off CPU fan (temperature control in peci_get_fan_duty)
DCR2 = 0;

// Enable PWM
Expand Down
3 changes: 3 additions & 0 deletions src/board/system76/galp5/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ CFLAGS+=\
-DPOWER_LIMIT_AC=65 \
-DPOWER_LIMIT_DC=28

# sync GPU fan speed to CPU fan speed (great for galp5 w/o dGPU)
CFLAGS+=-DSYNC_FANS=1

# Custom fan curve
CFLAGS+=-DBOARD_HEATUP=5
CFLAGS+=-DBOARD_COOLDOWN=20
Expand Down

0 comments on commit ae3c5d4

Please sign in to comment.