Skip to content

Commit 8d9504a

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 2f4c4e3 commit 8d9504a

2 files changed

Lines changed: 69 additions & 2 deletions

File tree

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+
// T0A/T1A are always available and enabled by default.
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: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,63 @@
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+
// XXX: Should init be responsible for setting GPIO to ALT for TACH function?
25+
switch (board_tachs[i]) {
26+
case TACH_CH_0B:
27+
// GPJ2
28+
GCR5 |= TACH0BEN;
29+
TSWCTLR |= T0CHSEL;
30+
break;
31+
32+
case TACH_CH_1B:
33+
// GPJ3
34+
GCR5 |= TACH1BEN;
35+
TSWCTLR |= T1CHSEL;
36+
break;
37+
38+
case TACH_CH_2A:
39+
// GPJ0
40+
GCR2 |= TACH2AEN;
41+
// CHSEL default is `A` (0) at init.
42+
break;
43+
44+
#if CONFIG_EC_ITE_IT5570E || CONFIG_EC_ITE_IT5571E
45+
case TACH_CH_2B:
46+
// GPJ1
47+
GCR15 |= TACH2BEN;
48+
TSWCTLR2 |= T2CHSEL;
49+
break;
50+
#endif
51+
52+
default:
53+
// T0A/T1A always available
54+
// CHSEL default is `A` (0) at init.
55+
break;
56+
}
57+
}
58+
}
559

660
void pwm_init(void) {
7-
// Set T0CHSEL to TACH0A and T1CHSEL to TACH1A
8-
TSWCTLR = 0;
61+
pwm_tach_init();
962

1063
// Disable PWM
1164
ZTIER = 0;

0 commit comments

Comments
 (0)