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