File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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) {
299300void 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+ }
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ extern uint8_t fan2_pwm_actual;
3939extern uint8_t fan2_pwm_target ;
4040extern uint16_t fan2_rpm ;
4141
42+ void fan_tach_init (void );
4243void fan_reset (void );
4344void fan_update_duty (void );
4445void fan_update_target (void );
Original file line number Diff line number Diff 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 ();
Original file line number Diff line number Diff line change @@ -79,6 +79,20 @@ volatile uint8_t __xdata __at(0x184F) TSWCTLR2;
7979volatile 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+
8296void pwm_init (void );
8397
8498#endif // _EC_PWM_H
Original file line number Diff line number Diff line change 44#include <common/macro.h>
55
66void pwm_init (void ) {
7- // Set T0CHSEL to TACH0A and T1CHSEL to TACH1A
8- TSWCTLR = 0 ;
9-
107 // Disable PWM
118 ZTIER = 0 ;
129
You can’t perform that action at this time.
0 commit comments