Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2017 Google, Inc |
maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef _WDT_H_ |
| 7 | #define _WDT_H_ |
| 8 | |
Simon Glass | defce58 | 2020-07-19 10:15:33 -0600 | [diff] [blame] | 9 | struct udevice; |
Stefan Roese | 0698528 | 2019-04-11 15:58:44 +0200 | [diff] [blame] | 10 | |
maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 11 | /* |
| 12 | * Implement a simple watchdog uclass. Watchdog is basically a timer that |
| 13 | * is used to detect or recover from malfunction. During normal operation |
| 14 | * the watchdog would be regularly reset to prevent it from timing out. |
| 15 | * If, due to a hardware fault or program error, the computer fails to reset |
| 16 | * the watchdog, the timer will elapse and generate a timeout signal. |
| 17 | * The timeout signal is used to initiate corrective action or actions, |
| 18 | * which typically include placing the system in a safe, known state. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * Start the timer |
| 23 | * |
| 24 | * @dev: WDT Device |
Andy Shevchenko | ffdec30 | 2017-08-04 15:48:28 -0600 | [diff] [blame] | 25 | * @timeout_ms: Number of ticks (milliseconds) before timer expires |
maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 26 | * @flags: Driver specific flags. This might be used to specify |
| 27 | * which action needs to be executed when the timer expires |
| 28 | * @return: 0 if OK, -ve on error |
| 29 | */ |
Andy Shevchenko | ffdec30 | 2017-08-04 15:48:28 -0600 | [diff] [blame] | 30 | int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags); |
maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * Stop the timer, thus disabling the Watchdog. Use wdt_start to start it again. |
| 34 | * |
| 35 | * @dev: WDT Device |
| 36 | * @return: 0 if OK, -ve on error |
| 37 | */ |
| 38 | int wdt_stop(struct udevice *dev); |
| 39 | |
| 40 | /* |
Rasmus Villemoes | 90555dc | 2021-08-19 11:57:01 +0200 | [diff] [blame] | 41 | * Stop all registered watchdog devices. |
| 42 | * |
| 43 | * @return: 0 if ok, first error encountered otherwise (but wdt_stop() |
| 44 | * is still called on following devices) |
| 45 | */ |
| 46 | int wdt_stop_all(void); |
| 47 | |
| 48 | /* |
maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 49 | * Reset the timer, typically restoring the counter to |
| 50 | * the value configured by start() |
| 51 | * |
| 52 | * @dev: WDT Device |
| 53 | * @return: 0 if OK, -ve on error |
| 54 | */ |
| 55 | int wdt_reset(struct udevice *dev); |
| 56 | |
| 57 | /* |
| 58 | * Expire the timer, thus executing its action immediately. |
| 59 | * This is typically used to reset the board or peripherals. |
| 60 | * |
| 61 | * @dev: WDT Device |
| 62 | * @flags: Driver specific flags |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame^] | 63 | * Return: 0 if OK -ve on error. If wdt action is system reset, |
maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 64 | * this function may never return. |
| 65 | */ |
| 66 | int wdt_expire_now(struct udevice *dev, ulong flags); |
| 67 | |
| 68 | /* |
| 69 | * struct wdt_ops - Driver model wdt operations |
| 70 | * |
| 71 | * The uclass interface is implemented by all wdt devices which use |
| 72 | * driver model. |
| 73 | */ |
| 74 | struct wdt_ops { |
| 75 | /* |
| 76 | * Start the timer |
| 77 | * |
| 78 | * @dev: WDT Device |
Andy Shevchenko | ffdec30 | 2017-08-04 15:48:28 -0600 | [diff] [blame] | 79 | * @timeout_ms: Number of ticks (milliseconds) before the timer expires |
maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 80 | * @flags: Driver specific flags. This might be used to specify |
| 81 | * which action needs to be executed when the timer expires |
| 82 | * @return: 0 if OK, -ve on error |
| 83 | */ |
Andy Shevchenko | ffdec30 | 2017-08-04 15:48:28 -0600 | [diff] [blame] | 84 | int (*start)(struct udevice *dev, u64 timeout_ms, ulong flags); |
maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 85 | /* |
| 86 | * Stop the timer |
| 87 | * |
| 88 | * @dev: WDT Device |
| 89 | * @return: 0 if OK, -ve on error |
| 90 | */ |
| 91 | int (*stop)(struct udevice *dev); |
| 92 | /* |
| 93 | * Reset the timer, typically restoring the counter to |
| 94 | * the value configured by start() |
| 95 | * |
| 96 | * @dev: WDT Device |
| 97 | * @return: 0 if OK, -ve on error |
| 98 | */ |
| 99 | int (*reset)(struct udevice *dev); |
| 100 | /* |
| 101 | * Expire the timer, thus executing the action immediately (optional) |
| 102 | * |
| 103 | * If this function is not provided, a default implementation |
| 104 | * will be used, which sets the counter to 1 |
| 105 | * and waits forever. This is good enough for system level |
| 106 | * reset, where the function is not expected to return, but might not be |
| 107 | * good enough for other use cases. |
| 108 | * |
| 109 | * @dev: WDT Device |
| 110 | * @flags: Driver specific flags |
| 111 | * @return 0 if OK -ve on error. May not return. |
| 112 | */ |
| 113 | int (*expire_now)(struct udevice *dev, ulong flags); |
| 114 | }; |
| 115 | |
Rasmus Villemoes | b4d9452 | 2020-03-13 17:04:57 +0100 | [diff] [blame] | 116 | int initr_watchdog(void); |
Stefan Roese | 0698528 | 2019-04-11 15:58:44 +0200 | [diff] [blame] | 117 | |
maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 118 | #endif /* _WDT_H_ */ |