Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
wdenk | 012771d | 2002-03-08 21:31:05 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2001 |
| 4 | * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com. |
wdenk | 012771d | 2002-03-08 21:31:05 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Watchdog functions and macros. |
| 9 | */ |
| 10 | #ifndef _WATCHDOG_H_ |
| 11 | #define _WATCHDOG_H_ |
| 12 | |
Simon Glass | a6741bc | 2013-03-05 14:39:42 +0000 | [diff] [blame] | 13 | #if !defined(__ASSEMBLY__) |
Stefan Roese | 661cdaa | 2022-09-02 13:57:49 +0200 | [diff] [blame] | 14 | #include <cyclic.h> |
| 15 | |
Simon Glass | a6741bc | 2013-03-05 14:39:42 +0000 | [diff] [blame] | 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 | |
Simon Glass | 9be2e79 | 2016-05-14 18:49:35 -0600 | [diff] [blame] | 25 | #if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG) |
Simon Glass | a6741bc | 2013-03-05 14:39:42 +0000 | [diff] [blame] | 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 | |
wdenk | 012771d | 2002-03-08 21:31:05 +0000 | [diff] [blame] | 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__) |
Pali Rohár | 06ceff7 | 2022-04-28 13:33:09 +0200 | [diff] [blame] | 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 |
wdenk | 012771d | 2002-03-08 21:31:05 +0000 | [diff] [blame] | 61 | #else |
Stefan Roese | 7fbd42f | 2019-04-02 10:57:18 +0200 | [diff] [blame] | 62 | /* Don't require the watchdog to be enabled in SPL */ |
| 63 | #if defined(CONFIG_SPL_BUILD) && \ |
Simon Glass | 078111b | 2021-07-10 21:14:28 -0600 | [diff] [blame] | 64 | !defined(CONFIG_SPL_WATCHDOG) |
Stefan Roese | 661cdaa | 2022-09-02 13:57:49 +0200 | [diff] [blame] | 65 | #define WATCHDOG_RESET() { \ |
| 66 | cyclic_run(); \ |
| 67 | } |
Stefan Roese | 7fbd42f | 2019-04-02 10:57:18 +0200 | [diff] [blame] | 68 | #else |
| 69 | extern void watchdog_reset(void); |
wdenk | 012771d | 2002-03-08 21:31:05 +0000 | [diff] [blame] | 70 | |
Stefan Roese | 661cdaa | 2022-09-02 13:57:49 +0200 | [diff] [blame] | 71 | #define WATCHDOG_RESET() { \ |
| 72 | watchdog_reset(); \ |
| 73 | cyclic_run(); \ |
| 74 | } |
Stefan Roese | 7fbd42f | 2019-04-02 10:57:18 +0200 | [diff] [blame] | 75 | #endif |
wdenk | 012771d | 2002-03-08 21:31:05 +0000 | [diff] [blame] | 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 |
Stefan Roese | 661cdaa | 2022-09-02 13:57:49 +0200 | [diff] [blame] | 84 | #define WATCHDOG_RESET() { \ |
| 85 | cyclic_run(); \ |
| 86 | } |
wdenk | 012771d | 2002-03-08 21:31:05 +0000 | [diff] [blame] | 87 | #endif /* __ASSEMBLY__ */ |
| 88 | #endif /* CONFIG_WATCHDOG && !__ASSEMBLY__ */ |
| 89 | #endif /* CONFIG_HW_WATCHDOG */ |
| 90 | |
Stefan Roese | 661cdaa | 2022-09-02 13:57:49 +0200 | [diff] [blame] | 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 | |
wdenk | 012771d | 2002-03-08 21:31:05 +0000 | [diff] [blame] | 99 | /* |
| 100 | * Prototypes from $(CPU)/cpu.c. |
| 101 | */ |
| 102 | |
Suniel Mahesh | 6912f2a | 2019-07-31 21:54:07 +0530 | [diff] [blame] | 103 | #if (defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)) && !defined(__ASSEMBLY__) |
Tom Rini | a672076 | 2013-01-14 13:10:07 -0700 | [diff] [blame] | 104 | void hw_watchdog_init(void); |
| 105 | #endif |
Boschung, Rainer | 0f8062b | 2014-06-03 09:05:14 +0200 | [diff] [blame] | 106 | |
| 107 | #if defined(CONFIG_MPC85xx) && !defined(__ASSEMBLY__) |
| 108 | void init_85xx_watchdog(void); |
| 109 | #endif |
wdenk | 012771d | 2002-03-08 21:31:05 +0000 | [diff] [blame] | 110 | #endif /* _WATCHDOG_H_ */ |