colibri_imx6: fix video stdout in default environment
[oweals/u-boot.git] / include / wdt.h
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 #include <dm.h>
10 #include <log.h>
11 #include <dm/read.h>
12
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
27  * @timeout_ms: Number of ticks (milliseconds) before timer expires
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  */
32 int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags);
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
73          * @timeout_ms: Number of ticks (milliseconds) before the timer expires
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          */
78         int (*start)(struct udevice *dev, u64 timeout_ms, ulong flags);
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
110 int initr_watchdog(void);
111
112 #endif  /* _WDT_H_ */