Skip to content

Commit

Permalink
allow ACPI to set fan speeds
Browse files Browse the repository at this point in the history
Smooth ACPI fan pwm values same as EC fan curve points
  • Loading branch information
curiousercreative committed Jan 24, 2024
1 parent 01be30f commit 4bd15aa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
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

0 comments on commit 4bd15aa

Please sign in to comment.