xref: /rk3399_rockchip-uboot/include/wdt.h (revision 0753bc2d30d7ca4a0ea4ef7f97083961c3a9d0e0)
1*0753bc2dSmaxims@google.com /*
2*0753bc2dSmaxims@google.com  * Copyright 2017 Google, Inc
3*0753bc2dSmaxims@google.com  *
4*0753bc2dSmaxims@google.com  * SPDX-License-Identifier:	GPL-2.0+
5*0753bc2dSmaxims@google.com  */
6*0753bc2dSmaxims@google.com 
7*0753bc2dSmaxims@google.com #ifndef _WDT_H_
8*0753bc2dSmaxims@google.com #define _WDT_H_
9*0753bc2dSmaxims@google.com 
10*0753bc2dSmaxims@google.com /*
11*0753bc2dSmaxims@google.com  * Implement a simple watchdog uclass. Watchdog is basically a timer that
12*0753bc2dSmaxims@google.com  * is used to detect or recover from malfunction. During normal operation
13*0753bc2dSmaxims@google.com  * the watchdog would be regularly reset to prevent it from timing out.
14*0753bc2dSmaxims@google.com  * If, due to a hardware fault or program error, the computer fails to reset
15*0753bc2dSmaxims@google.com  * the watchdog, the timer will elapse and generate a timeout signal.
16*0753bc2dSmaxims@google.com  * The timeout signal is used to initiate corrective action or actions,
17*0753bc2dSmaxims@google.com  * which typically include placing the system in a safe, known state.
18*0753bc2dSmaxims@google.com  */
19*0753bc2dSmaxims@google.com 
20*0753bc2dSmaxims@google.com /*
21*0753bc2dSmaxims@google.com  * Start the timer
22*0753bc2dSmaxims@google.com  *
23*0753bc2dSmaxims@google.com  * @dev: WDT Device
24*0753bc2dSmaxims@google.com  * @timeout: Number of ticks before timer expires
25*0753bc2dSmaxims@google.com  * @flags: Driver specific flags. This might be used to specify
26*0753bc2dSmaxims@google.com  * which action needs to be executed when the timer expires
27*0753bc2dSmaxims@google.com  * @return: 0 if OK, -ve on error
28*0753bc2dSmaxims@google.com  */
29*0753bc2dSmaxims@google.com int wdt_start(struct udevice *dev, u64 timeout, ulong flags);
30*0753bc2dSmaxims@google.com 
31*0753bc2dSmaxims@google.com /*
32*0753bc2dSmaxims@google.com  * Stop the timer, thus disabling the Watchdog. Use wdt_start to start it again.
33*0753bc2dSmaxims@google.com  *
34*0753bc2dSmaxims@google.com  * @dev: WDT Device
35*0753bc2dSmaxims@google.com  * @return: 0 if OK, -ve on error
36*0753bc2dSmaxims@google.com  */
37*0753bc2dSmaxims@google.com int wdt_stop(struct udevice *dev);
38*0753bc2dSmaxims@google.com 
39*0753bc2dSmaxims@google.com /*
40*0753bc2dSmaxims@google.com  * Reset the timer, typically restoring the counter to
41*0753bc2dSmaxims@google.com  * the value configured by start()
42*0753bc2dSmaxims@google.com  *
43*0753bc2dSmaxims@google.com  * @dev: WDT Device
44*0753bc2dSmaxims@google.com  * @return: 0 if OK, -ve on error
45*0753bc2dSmaxims@google.com  */
46*0753bc2dSmaxims@google.com int wdt_reset(struct udevice *dev);
47*0753bc2dSmaxims@google.com 
48*0753bc2dSmaxims@google.com /*
49*0753bc2dSmaxims@google.com  * Expire the timer, thus executing its action immediately.
50*0753bc2dSmaxims@google.com  * This is typically used to reset the board or peripherals.
51*0753bc2dSmaxims@google.com  *
52*0753bc2dSmaxims@google.com  * @dev: WDT Device
53*0753bc2dSmaxims@google.com  * @flags: Driver specific flags
54*0753bc2dSmaxims@google.com  * @return 0 if OK -ve on error. If wdt action is system reset,
55*0753bc2dSmaxims@google.com  * this function may never return.
56*0753bc2dSmaxims@google.com  */
57*0753bc2dSmaxims@google.com int wdt_expire_now(struct udevice *dev, ulong flags);
58*0753bc2dSmaxims@google.com 
59*0753bc2dSmaxims@google.com /*
60*0753bc2dSmaxims@google.com  * struct wdt_ops - Driver model wdt operations
61*0753bc2dSmaxims@google.com  *
62*0753bc2dSmaxims@google.com  * The uclass interface is implemented by all wdt devices which use
63*0753bc2dSmaxims@google.com  * driver model.
64*0753bc2dSmaxims@google.com  */
65*0753bc2dSmaxims@google.com struct wdt_ops {
66*0753bc2dSmaxims@google.com 	/*
67*0753bc2dSmaxims@google.com 	 * Start the timer
68*0753bc2dSmaxims@google.com 	 *
69*0753bc2dSmaxims@google.com 	 * @dev: WDT Device
70*0753bc2dSmaxims@google.com 	 * @timeout: Number of ticks before the timer expires
71*0753bc2dSmaxims@google.com 	 * @flags: Driver specific flags. This might be used to specify
72*0753bc2dSmaxims@google.com 	 * which action needs to be executed when the timer expires
73*0753bc2dSmaxims@google.com 	 * @return: 0 if OK, -ve on error
74*0753bc2dSmaxims@google.com 	 */
75*0753bc2dSmaxims@google.com 	int (*start)(struct udevice *dev, u64 timeout, ulong flags);
76*0753bc2dSmaxims@google.com 	/*
77*0753bc2dSmaxims@google.com 	 * Stop the timer
78*0753bc2dSmaxims@google.com 	 *
79*0753bc2dSmaxims@google.com 	 * @dev: WDT Device
80*0753bc2dSmaxims@google.com 	 * @return: 0 if OK, -ve on error
81*0753bc2dSmaxims@google.com 	 */
82*0753bc2dSmaxims@google.com 	int (*stop)(struct udevice *dev);
83*0753bc2dSmaxims@google.com 	/*
84*0753bc2dSmaxims@google.com 	 * Reset the timer, typically restoring the counter to
85*0753bc2dSmaxims@google.com 	 * the value configured by start()
86*0753bc2dSmaxims@google.com 	 *
87*0753bc2dSmaxims@google.com 	 * @dev: WDT Device
88*0753bc2dSmaxims@google.com 	 * @return: 0 if OK, -ve on error
89*0753bc2dSmaxims@google.com 	 */
90*0753bc2dSmaxims@google.com 	int (*reset)(struct udevice *dev);
91*0753bc2dSmaxims@google.com 	/*
92*0753bc2dSmaxims@google.com 	 * Expire the timer, thus executing the action immediately (optional)
93*0753bc2dSmaxims@google.com 	 *
94*0753bc2dSmaxims@google.com 	 * If this function is not provided, a default implementation
95*0753bc2dSmaxims@google.com 	 * will be used, which sets the counter to 1
96*0753bc2dSmaxims@google.com 	 * and waits forever. This is good enough for system level
97*0753bc2dSmaxims@google.com 	 * reset, where the function is not expected to return, but might not be
98*0753bc2dSmaxims@google.com 	 * good enough for other use cases.
99*0753bc2dSmaxims@google.com 	 *
100*0753bc2dSmaxims@google.com 	 * @dev: WDT Device
101*0753bc2dSmaxims@google.com 	 * @flags: Driver specific flags
102*0753bc2dSmaxims@google.com 	 * @return 0 if OK -ve on error. May not return.
103*0753bc2dSmaxims@google.com 	 */
104*0753bc2dSmaxims@google.com 	int (*expire_now)(struct udevice *dev, ulong flags);
105*0753bc2dSmaxims@google.com };
106*0753bc2dSmaxims@google.com 
107*0753bc2dSmaxims@google.com #endif  /* _WDT_H_ */
108