File tree Expand file tree Collapse file tree 7 files changed +80
-17
lines changed
Expand file tree Collapse file tree 7 files changed +80
-17
lines changed Original file line number Diff line number Diff line change 66#include <stdint.h>
77
88void smfi_init (void );
9- void smfi_watchdog (void );
109void smfi_event (void );
1110void smfi_debug (uint8_t byte );
1211
Original file line number Diff line number Diff line change 2929#include <common/macro.h>
3030#include <common/version.h>
3131#include <ec/ec.h>
32+ #include <ec/etwd.h>
3233
3334#if CONFIG_PLATFORM_INTEL
3435#include <board/peci.h>
@@ -101,6 +102,8 @@ void main(void) {
101102 gpio_debug ();
102103#endif
103104
105+ wdt_init ();
106+
104107 INFO ("System76 EC board '%s', version '%s'\n" , board (), version ());
105108
106109 systick_t last_time_100ms = 0 ;
@@ -167,6 +170,9 @@ void main(void) {
167170 pmc_event (& PMC_1 );
168171 // AP/EC communication over SMFI
169172 smfi_event ();
173+
174+ wdt_kick ();
175+
170176 // Idle until next timer interrupt
171177 //Disabled until interrupts used: PCON |= 1;
172178 }
Original file line number Diff line number Diff line change 44#include <board/fan.h>
55#include <board/smfi.h>
66#include <common/macro.h>
7+ #include <ec/etwd.h>
78#include <ec/pwm.h>
89#include <ec/scratch.h>
910
@@ -25,8 +26,8 @@ void scratch_trampoline(void) {
2526
2627 //TODO: Clear keyboard presses
2728
28- // Start watchdog timer
29- smfi_watchdog ();
29+ // Restart WDT before entry to scratch ROM
30+ wdt_kick ();
3031
3132 // Disable interrupts
3233 EA = 0 ;
Original file line number Diff line number Diff line change @@ -337,26 +337,17 @@ static enum Result cmd_reset(void) {
337337
338338#endif // !defined(__SCRATCH__)
339339
340- // Attempt to trigger watchdog reset
341- ETWCFG |= BIT (5 );
342- EWDKEYR = 0 ;
340+ wdt_trigger ();
343341
344342 // Failed if it got this far
345343 return RES_ERR ;
346344}
347345
348- // Set a watchdog timer of 10 seconds
349- void smfi_watchdog (void ) {
350- ET1CNTLLR = 0xFF ;
351- EWDCNTLLR = 0xFF ;
352- EWDCNTLHR = 0x04 ;
353- }
354-
355346void smfi_event (void ) {
356347 if (smfi_cmd [SMFI_CMD_CMD ]) {
357348#if defined(__SCRATCH__ )
358349 // If in scratch ROM, restart watchdog timer when command received
359- smfi_watchdog ();
350+ wdt_kick ();
360351#endif
361352
362353 switch (smfi_cmd [SMFI_CMD_CMD ]) {
Original file line number Diff line number Diff line change 22
33ec-y += ec.c
44ec-$(CONFIG_BUS_ESPI) += espi.c
5+ ec-y += etwd.c
56ec-y += gpio.c
67ec-y += i2c.c
78ec-y += intc.c
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: GPL-3.0-only
2+
3+ // External Timer and External Watchdog (ETWD)
4+
5+ #include <ec/etwd.h>
6+ #include <common/macro.h>
7+
8+ enum EwtCfg {
9+ // Lock EWTCFG register
10+ LETWCFG = BIT (0 ),
11+ // Lock ET1PS register
12+ LETPS1 = BIT (1 ),
13+ // Lock ET1CNTLx registers
14+ LET1CNTL = BIT (2 ),
15+ // Lock EWDCNTLx registers
16+ LEWDCNTL = BIT (3 ),
17+ // External WDT clock source
18+ EWDSRC = BIT (4 ),
19+ // Enable key match function to touch the WDT
20+ EWDKEYEN = BIT (5 ),
21+ // Lock ET1 and EWDT registers
22+ LOCK_ALL = LETWCFG | LETPS1 | LET1CNTL | LEWDCNTL ,
23+ };
24+
25+ enum EtwdPrescaler {
26+ ETWD_PRESCALER_32768_HZ = 0 ,
27+ ETWD_PRESCALER_1024_HZ = 1 ,
28+ ETWD_PRESCALER_32_HZ = 2 ,
29+ ETWD_PRESCALER_EC_CLK = 3 , // Not available for ET1PS
30+ };
31+
32+ void wdt_init (void ) {
33+ ET1PSR = ETWD_PRESCALER_1024_HZ ;
34+ ETWCFG = EWDKEYEN | EWDSRC ;
35+
36+ // Start ET1 so EWDT can be started
37+ ET1CNTLLR = 0xFF ;
38+
39+ // Start EWDT with timeout of 8s
40+ // TODO: Determine time based on system performance or requirement
41+ EWDCNTLHR = 0x20 ;
42+ EWDCNTLLR = 0 ;
43+
44+ ETWCFG |= LOCK_ALL ;
45+ }
Original file line number Diff line number Diff line change 11// SPDX-License-Identifier: GPL-3.0-only
22
3- #ifndef _EC_ECWD_H
4- #define _EC_ECWD_H
3+ // External Timer and External Watchdog (ETWD)
4+
5+ #ifndef _EC_ETWD_H
6+ #define _EC_ETWD_H
57
68#include <stdint.h>
79
@@ -27,4 +29,22 @@ volatile uint8_t __xdata __at(0x1F13) ET3CNTLH2R;
2729volatile uint8_t __xdata __at (0x1F16 ) ET4CNTLLR ;
2830#endif
2931
30- #endif // _EC_ECWD_H
32+ // When the key match function of EWD is enabled (EWTCFG[5]), writing this
33+ // value to EWDKEY will restart the WDT.
34+ #define WDT_KEY 0x5C
35+
36+ void wdt_init (void );
37+
38+ // Restart WDT
39+ // NOTE: Must be inlined for compiling in Scratch ROM
40+ static inline void wdt_kick (void ) {
41+ EWDKEYR = WDT_KEY ;
42+ }
43+
44+ // Trigger EC reset by WDT key mismatch
45+ // NOTE: Must be inlined for compiling in Scratch ROM
46+ static inline void wdt_trigger (void ) {
47+ EWDKEYR = 0 ;
48+ }
49+
50+ #endif // _EC_ETWD_H
You can’t perform that action at this time.
0 commit comments