cyclic: Integrate cyclic infrastructure into WATCHDOG_RESET
[platform/kernel/u-boot.git] / include / watchdog.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * (C) Copyright 2001
4  * Erik Theisen,  Wave 7 Optics, etheisen@mindspring.com.
5  */
6
7 /*
8  * Watchdog functions and macros.
9  */
10 #ifndef _WATCHDOG_H_
11 #define _WATCHDOG_H_
12
13 #if !defined(__ASSEMBLY__)
14 #include <cyclic.h>
15
16 /*
17  * Reset the watchdog timer, always returns 0
18  *
19  * This function is here since it is shared between board_f() and board_r(),
20  * and the legacy arch/<arch>/board.c code.
21  */
22 int init_func_watchdog_reset(void);
23 #endif
24
25 #if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
26 #define INIT_FUNC_WATCHDOG_INIT init_func_watchdog_init,
27 #define INIT_FUNC_WATCHDOG_RESET        init_func_watchdog_reset,
28 #else
29 #define INIT_FUNC_WATCHDOG_INIT
30 #define INIT_FUNC_WATCHDOG_RESET
31 #endif
32
33 #if defined(CONFIG_HW_WATCHDOG) && defined(CONFIG_WATCHDOG)
34 #  error "Configuration error: CONFIG_HW_WATCHDOG and CONFIG_WATCHDOG can't be used together."
35 #endif
36
37 /*
38  * Hardware watchdog
39  */
40 #ifdef CONFIG_HW_WATCHDOG
41         #if defined(__ASSEMBLY__)
42                 #define WATCHDOG_RESET bl hw_watchdog_reset
43         #else
44                 extern void hw_watchdog_reset(void);
45
46                 #define WATCHDOG_RESET hw_watchdog_reset
47         #endif /* __ASSEMBLY__ */
48 #else
49         /*
50          * Maybe a software watchdog?
51          */
52         #if defined(CONFIG_WATCHDOG)
53                 #if defined(__ASSEMBLY__)
54                         /* Don't require the watchdog to be enabled in SPL */
55                         #if defined(CONFIG_SPL_BUILD) &&                \
56                                 !defined(CONFIG_SPL_WATCHDOG)
57                                 #define WATCHDOG_RESET /*XXX DO_NOT_DEL_THIS_COMMENT*/
58                         #else
59                                 #define WATCHDOG_RESET bl watchdog_reset
60                         #endif
61                 #else
62                         /* Don't require the watchdog to be enabled in SPL */
63                         #if defined(CONFIG_SPL_BUILD) &&                \
64                                 !defined(CONFIG_SPL_WATCHDOG)
65                                 #define WATCHDOG_RESET() { \
66                                         cyclic_run(); \
67                                 }
68                         #else
69                                 extern void watchdog_reset(void);
70
71                                 #define WATCHDOG_RESET() { \
72                                         watchdog_reset(); \
73                                         cyclic_run(); \
74                                 }
75                         #endif
76                 #endif
77         #else
78                 /*
79                  * No hardware or software watchdog.
80                  */
81                 #if defined(__ASSEMBLY__)
82                         #define WATCHDOG_RESET /*XXX DO_NOT_DEL_THIS_COMMENT*/
83                 #else
84                         #define WATCHDOG_RESET() { \
85                                 cyclic_run(); \
86                         }
87                 #endif /* __ASSEMBLY__ */
88         #endif /* CONFIG_WATCHDOG && !__ASSEMBLY__ */
89 #endif /* CONFIG_HW_WATCHDOG */
90
91 #if !defined(__ASSEMBLY__)
92 /* Currently only needed for fs/cramfs/uncompress.c */
93 static inline void watchdog_reset_func(void)
94 {
95         WATCHDOG_RESET();
96 }
97 #endif
98
99 /*
100  * Prototypes from $(CPU)/cpu.c.
101  */
102
103 #if (defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)) && !defined(__ASSEMBLY__)
104         void hw_watchdog_init(void);
105 #endif
106
107 #if defined(CONFIG_MPC85xx) && !defined(__ASSEMBLY__)
108         void init_85xx_watchdog(void);
109 #endif
110 #endif /* _WATCHDOG_H_ */