Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support second fan without dGPU #474

Merged
merged 9 commits into from
Jul 17, 2024
Merged
19 changes: 11 additions & 8 deletions src/board/system76/addw1/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,27 @@ CFLAGS+=\
-DPOWER_LIMIT_AC=180 \
-DPOWER_LIMIT_DC=45

# Custom fan curve
CFLAGS+=-DBOARD_FAN_POINTS="\
# Enable dGPU support
CONFIG_HAVE_DGPU = y
CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
FAN_POINT(70, 75), \
FAN_POINT(75, 90), \
FAN_POINT(80, 100) \
FAN_POINT(80, 100), \
"

# Enable dGPU support
CONFIG_HAVE_DGPU = y
CFLAGS += -DI2C_DGPU=I2C_1
CFLAGS+=-DBOARD_DGPU_FAN_POINTS="\
CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
FAN_POINT(70, 75), \
FAN_POINT(75, 90), \
FAN_POINT(80, 100) \
FAN_POINT(80, 100), \
"

# Add system76 common code
Expand Down
19 changes: 11 additions & 8 deletions src/board/system76/addw2/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,27 @@ CFLAGS+=\
-DPOWER_LIMIT_AC=180 \
-DPOWER_LIMIT_DC=45

# Custom fan curve
CFLAGS+=-DBOARD_FAN_POINTS="\
# Enable dGPU support
CONFIG_HAVE_DGPU = y
CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
FAN_POINT(70, 75), \
FAN_POINT(75, 90), \
FAN_POINT(80, 100) \
FAN_POINT(80, 100), \
"

# Enable dGPU support
CONFIG_HAVE_DGPU = y
CFLAGS += -DI2C_DGPU=I2C_1
CFLAGS+=-DBOARD_DGPU_FAN_POINTS="\
CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
FAN_POINT(70, 75), \
FAN_POINT(75, 90), \
FAN_POINT(80, 100) \
FAN_POINT(80, 100), \
"

# Add system76 common code
Expand Down
27 changes: 15 additions & 12 deletions src/board/system76/addw3/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,31 @@ CFLAGS+=\
-DPOWER_LIMIT_AC=280 \
-DPOWER_LIMIT_DC=55

# Custom fan curve
CFLAGS+=-DBOARD_HEATUP=5
CFLAGS+=-DBOARD_COOLDOWN=20
CFLAGS+=-DBOARD_FAN_POINTS="\
# Enable dGPU support
CONFIG_HAVE_DGPU = y
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), \
FAN_POINT(70, 75), \
FAN_POINT(75, 90), \
FAN_POINT(80, 100) \
FAN_POINT(80, 100), \
"

# Enable dGPU support
CONFIG_HAVE_DGPU = y
CFLAGS += -DI2C_DGPU=I2C_1
CFLAGS+=-DBOARD_DGPU_HEATUP=5
CFLAGS+=-DBOARD_DGPU_COOLDOWN=20
CFLAGS+=-DBOARD_DGPU_FAN_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), \
FAN_POINT(70, 75), \
FAN_POINT(75, 90), \
FAN_POINT(80, 100) \
FAN_POINT(80, 100), \
"

# Add system76 common code
Expand Down
27 changes: 15 additions & 12 deletions src/board/system76/addw4/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,35 @@ CFLAGS += \
-DPOWER_LIMIT_AC=230 \
-DPOWER_LIMIT_DC=45

# Custom fan curve
CFLAGS += -DBOARD_HEATUP=5
CFLAGS += -DBOARD_COOLDOWN=20
CFLAGS += -DBOARD_FAN_POINTS="\
# Enable DGPU support
CONFIG_HAVE_DGPU = y
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), \
FAN_POINT(70, 40), \
FAN_POINT(75, 60), \
FAN_POINT(80, 75), \
FAN_POINT(85, 90), \
FAN_POINT(90, 100) \
FAN_POINT(90, 100), \
"

# Enable DGPU support
CONFIG_HAVE_DGPU = y
CFLAGS += -DI2C_DGPU=I2C_1
CFLAGS += -DBOARD_DGPU_HEATUP=5
CFLAGS += -DBOARD_DGPU_COOLDOWN=20
CFLAGS += -DBOARD_DGPU_FAN_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), \
FAN_POINT(70, 40), \
FAN_POINT(75, 60), \
FAN_POINT(80, 75), \
FAN_POINT(85, 90), \
FAN_POINT(90, 100) \
FAN_POINT(90, 100), \
"

# Add system76 common code
Expand Down
19 changes: 11 additions & 8 deletions src/board/system76/bonw14/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,27 @@ CFLAGS+=\
-DPOWER_LIMIT_AC=180 \
-DPOWER_LIMIT_DC=45

# Custom fan curve
CFLAGS+=-DBOARD_FAN_POINTS="\
# Enable dGPU support
CONFIG_HAVE_DGPU = y
CFLAGS += -DI2C_DGPU=I2C_1

# Fan configs
CFLAGS += -DFAN1_PWM=DCR2
CFLAGS += -DBOARD_FAN1_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
FAN_POINT(70, 75), \
FAN_POINT(75, 90), \
FAN_POINT(80, 100) \
FAN_POINT(80, 100), \
"

# Enable dGPU support
CONFIG_HAVE_DGPU = y
CFLAGS += -DI2C_DGPU=I2C_1
CFLAGS+=-DBOARD_DGPU_FAN_POINTS="\
CFLAGS += -DFAN2_PWM=DCR4
CFLAGS += -DBOARD_FAN2_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
FAN_POINT(70, 75), \
FAN_POINT(75, 90), \
FAN_POINT(80, 100) \
FAN_POINT(80, 100), \
"

# Add system76 common code
Expand Down
27 changes: 15 additions & 12 deletions src/board/system76/bonw15/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,31 @@ CFLAGS+=\
-DPOWER_LIMIT_AC=330 \
-DPOWER_LIMIT_DC=55

# Custom fan curve
CFLAGS+=-DBOARD_HEATUP=5
CFLAGS+=-DBOARD_COOLDOWN=20
CFLAGS+=-DBOARD_FAN_POINTS="\
# Enable dGPU support
CONFIG_HAVE_DGPU = y
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), \
FAN_POINT(70, 75), \
FAN_POINT(75, 90), \
FAN_POINT(80, 100) \
FAN_POINT(80, 100), \
"

# Enable dGPU support
CONFIG_HAVE_DGPU = y
CFLAGS += -DI2C_DGPU=I2C_1
CFLAGS+=-DBOARD_DGPU_HEATUP=5
CFLAGS+=-DBOARD_DGPU_COOLDOWN=20
CFLAGS+=-DBOARD_DGPU_FAN_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), \
FAN_POINT(70, 75), \
FAN_POINT(75, 90), \
FAN_POINT(80, 100) \
FAN_POINT(80, 100), \
"

# Add system76 common code
Expand Down
16 changes: 8 additions & 8 deletions src/board/system76/common/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <board/kbled.h>
#include <board/lid.h>
#include <board/peci.h>
#include <common/macro.h>
#include <board/pwm.h>
#include <common/debug.h>
#include <ec/pwm.h>
#include <common/macro.h>

#ifndef HAVE_LED_AIRPLANE_N
#define HAVE_LED_AIRPLANE_N 1
Expand Down Expand Up @@ -161,15 +161,15 @@ uint8_t acpi_read(uint8_t addr) {

ACPI_8(0xCC, sci_extra);

ACPI_8(0xCE, DCR2);
ACPI_8(0xD0, F1TLRR);
ACPI_8(0xD1, F1TMRR);
ACPI_8(0xCE, FAN1_PWM);
ACPI_16(0xD0, pwm_tach0_rpm);
#if CONFIG_HAVE_DGPU
ACPI_8(0xCD, dgpu_temp);
ACPI_8(0xCF, DCR4);
ACPI_8(0xD2, F2TLRR);
ACPI_8(0xD3, F2TMRR);
#endif // CONFIG_HAVE_DGPU
#ifdef FAN2_PWM
ACPI_8(0xCF, FAN2_PWM);
ACPI_16(0xD2, pwm_tach1_rpm);
#endif // FAN2_PWM

#if HAVE_LED_AIRPLANE_N
// Airplane mode LED
Expand Down
83 changes: 16 additions & 67 deletions src/board/system76/common/dgpu.c
Original file line number Diff line number Diff line change
@@ -1,94 +1,43 @@
// SPDX-License-Identifier: GPL-3.0-only

#include <board/dgpu.h>
#include <board/fan.h>
#include <board/gpio.h>
#include <board/peci.h>
#include <board/power.h>
#include <common/debug.h>
#include <common/macro.h>
#include <ec/i2c.h>
#include <ec/pwm.h>

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

static uint8_t FAN_HEATUP[BOARD_DGPU_HEATUP] = { 0 };

// Fan speed is the highest HEATUP speed over COOLDOWN seconds
#ifndef BOARD_DGPU_COOLDOWN
#define BOARD_DGPU_COOLDOWN 10
#endif

static uint8_t FAN_COOLDOWN[BOARD_DGPU_COOLDOWN] = { 0 };

int16_t dgpu_temp = 0;

#define DGPU_TEMP(X) ((int16_t)(X))

#define FAN_POINT(T, D) \
{ .temp = DGPU_TEMP(T), .duty = PWM_DUTY(D) }

// Fan curve with temperature in degrees C, duty cycle in percent
static struct FanPoint __code FAN_POINTS[] = {
#ifdef BOARD_DGPU_FAN_POINTS
BOARD_DGPU_FAN_POINTS
#else
FAN_POINT(70, 40),
FAN_POINT(75, 50),
FAN_POINT(80, 60),
FAN_POINT(85, 65),
FAN_POINT(90, 65)
#endif
};

static struct Fan __code FAN = {
.points = FAN_POINTS,
.points_size = ARRAY_SIZE(FAN_POINTS),
.heatup = FAN_HEATUP,
.heatup_size = ARRAY_SIZE(FAN_HEATUP),
.cooldown = FAN_COOLDOWN,
.cooldown_size = ARRAY_SIZE(FAN_COOLDOWN),
.interpolate = SMOOTH_FANS != 0,
};

void dgpu_init(void) {
// Set up for i2c usage
i2c_reset(&I2C_DGPU, true);
}

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
bool dgpu_get_temp(int16_t *const data) {
if (gpio_get(&DGPU_PWR_EN) && !gpio_get(&GC6_FB_EN)) {
int8_t rlts;
int16_t res = i2c_get(&I2C_DGPU, 0x4F, 0x00, &rlts, 1);
if (res == 1) {
dgpu_temp = (int16_t)rlts;
duty = fan_duty(&FAN, dgpu_temp);
*data = (int16_t)rlts;
return true;
} else {
DEBUG("DGPU temp error: %d\n", res);
// Default to 50% if there is an error
dgpu_temp = 0;
duty = PWM_DUTY(50);
*data = 0;
return false;
}
} else {
// Turn fan off if not in S0 state or GPU power not on
dgpu_temp = 0;
duty = PWM_DUTY(0);
}

if (peci_on && fan_max) {
// Override duty if fans are manually set to maximum
duty = PWM_DUTY(100);
} else {
// Apply heatup and cooldown filters to duty
duty = fan_heatup(&FAN, duty);
duty = fan_cooldown(&FAN, duty);
*data = 0;
return true;
}

void dgpu_read_temp(void) {
if (power_state == POWER_STATE_S0) {
if (dgpu_get_temp(&dgpu_temp)) {
return;
}
}

TRACE("DGPU temp=%d\n", dgpu_temp);
return duty;
dgpu_temp = 0;
}
Loading
Loading