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

Allow ACPI to set fan speeds #309

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/board/system76/common/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <board/acpi.h>
#include <board/battery.h>
#include <board/dgpu.h>
#include <board/fan.h>
#include <board/gpio.h>
#include <board/kbled.h>
#include <board/lid.h>
Expand Down Expand Up @@ -65,6 +66,14 @@ void fcommand(void) {
break;
}
break;
case 0xCE:
acpi_peci_fan_duty = fbuf[0];
break;
#if HAVE_DGPU
case 0xCF:
acpi_dgpu_fan_duty = fbuf[0];
break;
#endif
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/board/system76/common/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#define MIN_SPEED_TO_SMOOTH PWM_DUTY(SMOOTH_FANS_MIN)

bool fan_max = false;
uint8_t acpi_peci_fan_duty = 0;
uint8_t acpi_dgpu_fan_duty = 0;
uint8_t last_duty_dgpu = 0;
uint8_t last_duty_peci = 0;

Expand Down Expand Up @@ -68,8 +70,13 @@ void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant {
dgpu_fan_duty = peci_fan_duty > dgpu_fan_duty ? peci_fan_duty : dgpu_fan_duty;
#endif

// allow for ACPI to request a higher duty
peci_fan_duty = peci_fan_duty > acpi_peci_fan_duty ? peci_fan_duty : acpi_peci_fan_duty;
dgpu_fan_duty = dgpu_fan_duty > acpi_dgpu_fan_duty ? dgpu_fan_duty : acpi_dgpu_fan_duty;

// set PECI fan duty
if (peci_fan_duty != DCR2) {
TRACE("PECI acpi_fan_duty_raw=%d\n", acpi_peci_fan_duty);
TRACE("PECI fan_duty_raw=%d\n", peci_fan_duty);
last_duty_peci = peci_fan_duty = fan_smooth(last_duty_peci, peci_fan_duty);
DCR2 = fan_max ? MAX_FAN_SPEED : peci_fan_duty;
Expand All @@ -78,6 +85,7 @@ void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant {

// set dGPU fan duty
if (dgpu_fan_duty != DCR4) {
TRACE("DGPU acpi_fan_duty_raw=%d\n", acpi_peci_fan_duty);
TRACE("DGPU fan_duty_raw=%d\n", dgpu_fan_duty);
last_duty_dgpu = dgpu_fan_duty = fan_smooth(last_duty_dgpu, dgpu_fan_duty);
DCR4 = fan_max ? MAX_FAN_SPEED : dgpu_fan_duty;
Expand Down
2 changes: 2 additions & 0 deletions src/board/system76/common/include/board/fan.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ struct Fan {
bool interpolate;
};

extern uint8_t acpi_dgpu_fan_duty;
extern uint8_t acpi_peci_fan_duty;
extern bool fan_max;

void fan_reset(void);
Expand Down