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