diff --git a/src/board/system76/common/fan.c b/src/board/system76/common/fan.c index 3d455b8ab..d0e1199e2 100644 --- a/src/board/system76/common/fan.c +++ b/src/board/system76/common/fan.c @@ -17,15 +17,6 @@ #define PWM_REG(x) concat(DCR, x) -#ifndef CPU_FAN1 -#define CPU_FAN1 2 -#endif - -// Only V5x0TNx is different -#ifndef GPU_FAN1 -#define GPU_FAN1 4 -#endif - bool fan_max = false; uint8_t last_duty_dgpu = 0; uint8_t last_duty_peci = 0; @@ -81,7 +72,7 @@ void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant { #endif // set PECI fan duty - if (peci_fan_duty != DCR2) { + if (peci_fan_duty != PWM_REG(CPU_FAN1)) { TRACE("PECI fan_duty_raw=%d\n", peci_fan_duty); last_duty_peci = peci_fan_duty = fan_smooth(last_duty_peci, peci_fan_duty); PWM_REG(CPU_FAN1) = fan_max ? MAX_FAN_SPEED : peci_fan_duty; @@ -92,7 +83,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) { + if (dgpu_fan_duty != PWM_REG(GPU_FAN1)) { TRACE("DGPU fan_duty_raw=%d\n", dgpu_fan_duty); last_duty_dgpu = dgpu_fan_duty = fan_smooth(last_duty_dgpu, dgpu_fan_duty); PWM_REG(GPU_FAN1) = fan_max ? MAX_FAN_SPEED : dgpu_fan_duty; diff --git a/src/board/system76/common/include/board/fan.h b/src/board/system76/common/include/board/fan.h index 36f98551f..140623884 100644 --- a/src/board/system76/common/include/board/fan.h +++ b/src/board/system76/common/include/board/fan.h @@ -31,6 +31,15 @@ #define SMOOTH_FANS_MIN 0 // default to smoothing all fan speed changes #endif +#ifndef CPU_FAN1 +#define CPU_FAN1 2 +#endif + +// Only V5x0TNx is different +#ifndef GPU_FAN1 +#define GPU_FAN1 4 +#endif + struct FanPoint { int16_t temp; uint8_t duty; diff --git a/src/board/system76/common/pwm.c b/src/board/system76/common/pwm.c index 04924dfeb..0f57a4646 100644 --- a/src/board/system76/common/pwm.c +++ b/src/board/system76/common/pwm.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only +#include #include #include @@ -24,9 +25,12 @@ void pwm_init(void) { CTR0 = 255; // Turn off CPU fan (temperature control in peci_get_fan_duty) - DCR2 = 0; + PWM_REG(CPU_FAN1) = 0; #if HAVE_CPU_FAN2 - DCR3 = 0; + PWM_REG(CPU_FAN2) = 0; +#endif +#if HAVE_DGPU + PWM_REG(GPU_FAN1) = 0; #endif #if CONFIG_EC_ITE_IT5570E diff --git a/src/board/system76/common/scratch.c b/src/board/system76/common/scratch.c index 5237df35a..182c19c3e 100644 --- a/src/board/system76/common/scratch.c +++ b/src/board/system76/common/scratch.c @@ -17,12 +17,12 @@ uint8_t __code __at(SCRATCH_OFFSET) scratch_rom[] = { // Enter or exit scratch ROM void scratch_trampoline(void) { // Set fans to 100% - DCR2 = 0xFF; + PWM_REG(CPU_FAN1) = 0xFF; #if HAVE_CPU_FAN2 - DCR3 = 0xFF; + PWM_REG(CPU_FAN2) = 0xFF; #endif #if HAVE_DGPU - DCR4 = 0xFF; + PWM_REG(GPU_FAN1) = 0xFF; #endif //TODO: Clear keyboard presses diff --git a/src/board/system76/common/smfi.c b/src/board/system76/common/smfi.c index 7cd3ace04..51e3bc8bf 100644 --- a/src/board/system76/common/smfi.c +++ b/src/board/system76/common/smfi.c @@ -133,13 +133,13 @@ static enum Result cmd_fan_get(void) { switch (smfi_cmd[SMFI_CMD_DATA]) { case 0: // Get duty of fan 0 - smfi_cmd[SMFI_CMD_DATA + 1] = DCR2; + smfi_cmd[SMFI_CMD_DATA + 1] = PWM_REG(CPU_FAN1); // TODO handle dual CPU fans return RES_OK; case 1: // Get duty of fan 1 //TODO: only allow on platforms like addw2 - smfi_cmd[SMFI_CMD_DATA + 1] = DCR4; + smfi_cmd[SMFI_CMD_DATA + 1] = PWM_REG(GPU_FAN1); return RES_OK; } @@ -151,16 +151,16 @@ static enum Result cmd_fan_set(void) { switch (smfi_cmd[SMFI_CMD_DATA]) { case 0: // Set duty cycle of fan 0 - DCR2 = smfi_cmd[SMFI_CMD_DATA + 1]; + PWM_REG(CPU_FAN1) = smfi_cmd[SMFI_CMD_DATA + 1]; #if HAVE_CPU_FAN2 // TODO handle CPU fan 2 separately - DCR3 = smfi_cmd[SMFI_CMD_DATA + 1]; + PWM_REG(CPU_FAN2) = smfi_cmd[SMFI_CMD_DATA + 1]; #endif return RES_OK; case 1: // Set duty cycle of fan 1 //TODO: only allow on platforms like addw2 - DCR4 = smfi_cmd[SMFI_CMD_DATA + 1]; + PWM_REG(GPU_FAN1) = smfi_cmd[SMFI_CMD_DATA + 1]; return RES_OK; } diff --git a/src/ec/ite/include/ec/pwm.h b/src/ec/ite/include/ec/pwm.h index 43b96fb60..a12660acd 100644 --- a/src/ec/ite/include/ec/pwm.h +++ b/src/ec/ite/include/ec/pwm.h @@ -5,6 +5,8 @@ #include +#define PWM_REG(x) concat(DCR, x) + // Channel 0 clock prescaler register volatile uint8_t __xdata __at(0x1800) C0CPRS; // Channel 6 clock prescaler register (low byte)