Skip to content

Commit a42ed59

Browse files
committed
[WIP] app/fan: Add tach init
Signed-off-by: Tim Crawford <tcrawford@system76.com>
1 parent e378973 commit a42ed59

5 files changed

Lines changed: 65 additions & 3 deletions

File tree

src/app/main/fan.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <common/debug.h>
66
#include <common/macro.h>
77
#include <drivers/dgpu/dgpu.h>
8+
#include <ec/gpio.h>
89
#include <ec/pwm.h>
910

1011
#if CONFIG_PLATFORM_INTEL
@@ -299,3 +300,49 @@ enum FanMode fan_get_mode(void) {
299300
void fan_set_mode(enum FanMode mode) {
300301
fan_mode = mode;
301302
}
303+
304+
// TODO: Per-board
305+
#define NR_TACHS 2
306+
307+
// TODO: Per-board
308+
enum TachCh board_tachs[NR_TACHS] = {
309+
TACH_CH_0A,
310+
TACH_CH_1A,
311+
};
312+
313+
void fan_tach_init(void) {
314+
for (uint8_t i = 0; i < NR_TACHS; i++) {
315+
// XXX: Should init be responsible for setting GPIO to ALT for TACH function?
316+
switch (board_tachs[i]) {
317+
case TACH_CH_0B:
318+
// GPJ2
319+
GCR5 |= TACH0BEN;
320+
TSWCTLR |= T0CHSEL;
321+
break;
322+
323+
case TACH_CH_1B:
324+
// GPJ3
325+
GCR5 |= TACH1BEN;
326+
TSWCTLR |= T1CHSEL;
327+
break;
328+
329+
case TACH_CH_2A:
330+
// GPJ0
331+
GCR2 |= TACH2AEN;
332+
// `A` channel is default
333+
break;
334+
335+
#if CONFIG_EC_ITE_IT5570E || CONFIG_EC_ITE_IT5571E
336+
case TACH_CH_2B:
337+
// GPJ1
338+
GCR15 |= TACH2BEN;
339+
TSWCTLR2 |= T2CHSEL;
340+
break;
341+
#endif
342+
343+
default:
344+
// T0A/T1A always available
345+
break;
346+
}
347+
}
348+
}

src/app/main/include/app/fan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern uint8_t fan2_pwm_actual;
3939
extern uint8_t fan2_pwm_target;
4040
extern uint16_t fan2_rpm;
4141

42+
void fan_tach_init(void);
4243
void fan_reset(void);
4344
void fan_update_duty(void);
4445
void fan_update_target(void);

src/app/main/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ void init(void) {
8383
peci_init();
8484
#endif
8585
pmc_init();
86+
87+
fan_tach_init(); // Configure TACHs before enabling PWM
8688
pwm_init();
89+
8790
smbus_init();
8891
smfi_init();
8992
usbpd_init();

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ volatile uint8_t __xdata __at(0x184F) TSWCTLR2;
7979
volatile uint8_t __xdata __at(0x185A) PWMLCCR;
8080
#endif
8181

82+
enum TachCh {
83+
// `A` channels are always available.
84+
TACH_CH_0A = 0,
85+
TACH_CH_1A,
86+
// `B` and `2` channels must be configured and enabled.
87+
TACH_CH_0B,
88+
TACH_CH_1B,
89+
TACH_CH_2A,
90+
#if CONFIG_EC_ITE_IT5570E || CONFIG_EC_ITE_IT5571E
91+
TACH_CH_2B,
92+
#endif
93+
NR_TACH_CHS,
94+
};
95+
8296
void pwm_init(void);
8397

8498
#endif // _EC_PWM_H

src/ec/ite/pwm.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
#include <common/macro.h>
55

66
void pwm_init(void) {
7-
// Set T0CHSEL to TACH0A and T1CHSEL to TACH1A
8-
TSWCTLR = 0;
9-
107
// Disable PWM
118
ZTIER = 0;
129

0 commit comments

Comments
 (0)