Skip to content

Commit 582481d

Browse files
committed
pwm: actually use the correct DCR registers for each fan
Signed-off-by: Michał Kopeć <michal.kopec@3mdeb.com>
1 parent 220e5f9 commit 582481d

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

src/board/system76/common/fan.c

+2-11
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@
1717

1818
#define PWM_REG(x) concat(DCR, x)
1919

20-
#ifndef CPU_FAN1
21-
#define CPU_FAN1 2
22-
#endif
23-
24-
// Only V5x0TNx is different
25-
#ifndef GPU_FAN1
26-
#define GPU_FAN1 4
27-
#endif
28-
2920
bool fan_max = false;
3021
uint8_t last_duty_dgpu = 0;
3122
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 {
8172
#endif
8273

8374
// set PECI fan duty
84-
if (peci_fan_duty != DCR2) {
75+
if (peci_fan_duty != PWM_REG(CPU_FAN1)) {
8576
TRACE("PECI fan_duty_raw=%d\n", peci_fan_duty);
8677
last_duty_peci = peci_fan_duty = fan_smooth(last_duty_peci, peci_fan_duty);
8778
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 {
9283
}
9384

9485
// set dGPU fan duty
95-
if (dgpu_fan_duty != DCR4) {
86+
if (dgpu_fan_duty != PWM_REG(GPU_FAN1)) {
9687
TRACE("DGPU fan_duty_raw=%d\n", dgpu_fan_duty);
9788
last_duty_dgpu = dgpu_fan_duty = fan_smooth(last_duty_dgpu, dgpu_fan_duty);
9889
PWM_REG(GPU_FAN1) = fan_max ? MAX_FAN_SPEED : dgpu_fan_duty;

src/board/system76/common/include/board/fan.h

+9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131
#define SMOOTH_FANS_MIN 0 // default to smoothing all fan speed changes
3232
#endif
3333

34+
#ifndef CPU_FAN1
35+
#define CPU_FAN1 2
36+
#endif
37+
38+
// Only V5x0TNx is different
39+
#ifndef GPU_FAN1
40+
#define GPU_FAN1 4
41+
#endif
42+
3443
struct FanPoint {
3544
int16_t temp;
3645
uint8_t duty;

src/board/system76/common/pwm.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: GPL-3.0-only
22

3+
#include <board/fan.h>
34
#include <board/pwm.h>
45
#include <common/macro.h>
56

@@ -24,9 +25,12 @@ void pwm_init(void) {
2425
CTR0 = 255;
2526

2627
// Turn off CPU fan (temperature control in peci_get_fan_duty)
27-
DCR2 = 0;
28+
PWM_REG(CPU_FAN1) = 0;
2829
#if HAVE_CPU_FAN2
29-
DCR3 = 0;
30+
PWM_REG(CPU_FAN2) = 0;
31+
#endif
32+
#if HAVE_DGPU
33+
PWM_REG(GPU_FAN1) = 0;
3034
#endif
3135

3236
#if CONFIG_EC_ITE_IT5570E

src/board/system76/common/scratch.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ uint8_t __code __at(SCRATCH_OFFSET) scratch_rom[] = {
1717
// Enter or exit scratch ROM
1818
void scratch_trampoline(void) {
1919
// Set fans to 100%
20-
DCR2 = 0xFF;
20+
PWM_REG(CPU_FAN1) = 0xFF;
2121
#if HAVE_CPU_FAN2
22-
DCR3 = 0xFF;
22+
PWM_REG(CPU_FAN2) = 0xFF;
2323
#endif
2424
#if HAVE_DGPU
25-
DCR4 = 0xFF;
25+
PWM_REG(GPU_FAN1) = 0xFF;
2626
#endif
2727

2828
//TODO: Clear keyboard presses

src/board/system76/common/smfi.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ static enum Result cmd_fan_get(void) {
133133
switch (smfi_cmd[SMFI_CMD_DATA]) {
134134
case 0:
135135
// Get duty of fan 0
136-
smfi_cmd[SMFI_CMD_DATA + 1] = DCR2;
136+
smfi_cmd[SMFI_CMD_DATA + 1] = PWM_REG(CPU_FAN1);
137137
// TODO handle dual CPU fans
138138
return RES_OK;
139139
case 1:
140140
// Get duty of fan 1
141141
//TODO: only allow on platforms like addw2
142-
smfi_cmd[SMFI_CMD_DATA + 1] = DCR4;
142+
smfi_cmd[SMFI_CMD_DATA + 1] = PWM_REG(GPU_FAN1);
143143
return RES_OK;
144144
}
145145

@@ -151,16 +151,16 @@ static enum Result cmd_fan_set(void) {
151151
switch (smfi_cmd[SMFI_CMD_DATA]) {
152152
case 0:
153153
// Set duty cycle of fan 0
154-
DCR2 = smfi_cmd[SMFI_CMD_DATA + 1];
154+
PWM_REG(CPU_FAN1) = smfi_cmd[SMFI_CMD_DATA + 1];
155155
#if HAVE_CPU_FAN2
156156
// TODO handle CPU fan 2 separately
157-
DCR3 = smfi_cmd[SMFI_CMD_DATA + 1];
157+
PWM_REG(CPU_FAN2) = smfi_cmd[SMFI_CMD_DATA + 1];
158158
#endif
159159
return RES_OK;
160160
case 1:
161161
// Set duty cycle of fan 1
162162
//TODO: only allow on platforms like addw2
163-
DCR4 = smfi_cmd[SMFI_CMD_DATA + 1];
163+
PWM_REG(GPU_FAN1) = smfi_cmd[SMFI_CMD_DATA + 1];
164164
return RES_OK;
165165
}
166166

src/ec/ite/include/ec/pwm.h

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include <stdint.h>
77

8+
#define PWM_REG(x) concat(DCR, x)
9+
810
// Channel 0 clock prescaler register
911
volatile uint8_t __xdata __at(0x1800) C0CPRS;
1012
// Channel 6 clock prescaler register (low byte)

0 commit comments

Comments
 (0)