Skip to content

Commit 2fddf03

Browse files
committed
ec/ite: Add tach init
Add initial SoC support for boards to configure tachs. Signed-off-by: Tim Crawford <tcrawford@system76.com>
1 parent 5d680e7 commit 2fddf03

2 files changed

Lines changed: 62 additions & 2 deletions

File tree

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

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

82+
enum TachCh {
83+
TACH_CH_0A = 0, // GPD6
84+
TACH_CH_1A, // GPD7
85+
TACH_CH_0B, // GPJ2
86+
TACH_CH_1B, // GPJ3
87+
TACH_CH_2A, // GPJ0
88+
#if CONFIG_EC_ITE_IT5570E || CONFIG_EC_ITE_IT5571E
89+
TACH_CH_2B, // GPJ1
90+
#endif
91+
};
92+
8293
void pwm_init(void);
8394

8495
#endif // _EC_PWM_H

src/ec/ite/pwm.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,59 @@
22

33
#include <ec/pwm.h>
44
#include <common/macro.h>
5+
#include <ec/gpio.h>
6+
7+
// TODO: Define per-board
8+
// All boards use T0A/T1A, so just declare it here for now based on FAN2_PWM
9+
#ifdef FAN2_PWM
10+
#define NR_TACHS 2
11+
#else
12+
#define NR_TACHS 1
13+
#endif
14+
15+
const enum TachCh board_tachs[NR_TACHS] = {
16+
TACH_CH_0A,
17+
#ifdef FAN2_PWM
18+
TACH_CH_1A,
19+
#endif
20+
};
21+
22+
static void pwm_tach_init(void) {
23+
for (uint8_t i = 0; i < NR_TACHS; i++) {
24+
switch (board_tachs[i]) {
25+
case TACH_CH_0A:
26+
case TACH_CH_1A:
27+
// T0A/T1A always available
28+
// CHSEL default is `A` (0) at init.
29+
break;
30+
31+
case TACH_CH_0B:
32+
GCR5 |= TACH0BEN;
33+
TSWCTLR |= T0CHSEL;
34+
break;
35+
36+
case TACH_CH_1B:
37+
GCR5 |= TACH1BEN;
38+
TSWCTLR |= T1CHSEL;
39+
break;
40+
41+
case TACH_CH_2A:
42+
GCR2 |= TACH2AEN;
43+
// CHSEL default is `A` (0) at init.
44+
break;
45+
46+
#if CONFIG_EC_ITE_IT5570E || CONFIG_EC_ITE_IT5571E
47+
case TACH_CH_2B:
48+
GCR15 |= TACH2BEN;
49+
TSWCTLR2 |= T2CHSEL;
50+
break;
51+
#endif
52+
}
53+
}
54+
}
555

656
void pwm_init(void) {
7-
// Set T0CHSEL to TACH0A and T1CHSEL to TACH1A
8-
TSWCTLR = 0;
57+
pwm_tach_init();
958

1059
// Disable PWM
1160
ZTIER = 0;

0 commit comments

Comments
 (0)