1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * Copyright 2017 Google, Inc 4 */ 5 6 #ifndef _WDT_H_ 7 #define _WDT_H_ 8 9 struct udevice; 10 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 * Force watchdog start during init. Called by driver's probe when the watchdog 23 * is detected as already started. 24 * 25 * @dev: WDT Device 26 * @return: 0 if OK, -ve on error 27 */ 28 int wdt_set_force_autostart(struct udevice *dev); 29 30 /* 31 * Start the timer 32 * 33 * @dev: WDT Device 34 * @timeout_ms: Number of ticks (milliseconds) before timer expires 35 * @flags: Driver specific flags. This might be used to specify 36 * which action needs to be executed when the timer expires 37 * @return: 0 if OK, -ve on error 38 */ 39 int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags); 40 41 /* 42 * Stop the timer, thus disabling the Watchdog. Use wdt_start to start it again. 43 * 44 * @dev: WDT Device 45 * @return: 0 if OK, -ve on error 46 */ 47 int wdt_stop(struct udevice *dev); 48 49 /* 50 * Stop all registered watchdog devices. 51 * 52 * @return: 0 if ok, first error encountered otherwise (but wdt_stop() 53 * is still called on following devices) 54 */ 55 int wdt_stop_all(void); 56 57 /* 58 * Reset the timer, typically restoring the counter to 59 * the value configured by start() 60 * 61 * @dev: WDT Device 62 * @return: 0 if OK, -ve on error 63 */ 64 int wdt_reset(struct udevice *dev); 65 66 /* 67 * Expire the timer, thus executing its action immediately. 68 * This is typically used to reset the board or peripherals. 69 * 70 * @dev: WDT Device 71 * @flags: Driver specific flags 72 * Return: 0 if OK -ve on error. If wdt action is system reset, 73 * this function may never return. 74 */ 75 int wdt_expire_now(struct udevice *dev, ulong flags); 76 77 /* 78 * struct wdt_ops - Driver model wdt operations 79 * 80 * The uclass interface is implemented by all wdt devices which use 81 * driver model. 82 */ 83 struct wdt_ops { 84 /* 85 * Start the timer 86 * 87 * @dev: WDT Device 88 * @timeout_ms: Number of ticks (milliseconds) before the timer expires 89 * @flags: Driver specific flags. This might be used to specify 90 * which action needs to be executed when the timer expires 91 * @return: 0 if OK, -ve on error 92 */ 93 int (*start)(struct udevice *dev, u64 timeout_ms, ulong flags); 94 /* 95 * Stop the timer 96 * 97 * @dev: WDT Device 98 * @return: 0 if OK, -ve on error 99 */ 100 int (*stop)(struct udevice *dev); 101 /* 102 * Reset the timer, typically restoring the counter to 103 * the value configured by start() 104 * 105 * @dev: WDT Device 106 * @return: 0 if OK, -ve on error 107 */ 108 int (*reset)(struct udevice *dev); 109 /* 110 * Expire the timer, thus executing the action immediately (optional) 111 * 112 * If this function is not provided, a default implementation 113 * will be used, which sets the counter to 1 114 * and waits forever. This is good enough for system level 115 * reset, where the function is not expected to return, but might not be 116 * good enough for other use cases. 117 * 118 * @dev: WDT Device 119 * @flags: Driver specific flags 120 * @return 0 if OK -ve on error. May not return. 121 */ 122 int (*expire_now)(struct udevice *dev, ulong flags); 123 }; 124 125 int initr_watchdog(void); 126 127 #endif /* _WDT_H_ */ 128