blob: bc242c2eb26d49e0e883f19a986daec4251ea9a1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
maxims@google.com0753bc22017-04-17 12:00:21 -07002/*
3 * Copyright 2017 Google, Inc
maxims@google.com0753bc22017-04-17 12:00:21 -07004 */
5
6#ifndef _WDT_H_
7#define _WDT_H_
8
Simon Glassdefce582020-07-19 10:15:33 -06009struct udevice;
Stefan Roese06985282019-04-11 15:58:44 +020010
maxims@google.com0753bc22017-04-17 12:00:21 -070011/*
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 * Start the timer
23 *
24 * @dev: WDT Device
Andy Shevchenkoffdec302017-08-04 15:48:28 -060025 * @timeout_ms: Number of ticks (milliseconds) before timer expires
maxims@google.com0753bc22017-04-17 12:00:21 -070026 * @flags: Driver specific flags. This might be used to specify
27 * which action needs to be executed when the timer expires
28 * @return: 0 if OK, -ve on error
29 */
Andy Shevchenkoffdec302017-08-04 15:48:28 -060030int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags);
maxims@google.com0753bc22017-04-17 12:00:21 -070031
32/*
33 * Stop the timer, thus disabling the Watchdog. Use wdt_start to start it again.
34 *
35 * @dev: WDT Device
36 * @return: 0 if OK, -ve on error
37 */
38int wdt_stop(struct udevice *dev);
39
40/*
41 * Reset the timer, typically restoring the counter to
42 * the value configured by start()
43 *
44 * @dev: WDT Device
45 * @return: 0 if OK, -ve on error
46 */
47int wdt_reset(struct udevice *dev);
48
49/*
50 * Expire the timer, thus executing its action immediately.
51 * This is typically used to reset the board or peripherals.
52 *
53 * @dev: WDT Device
54 * @flags: Driver specific flags
55 * @return 0 if OK -ve on error. If wdt action is system reset,
56 * this function may never return.
57 */
58int wdt_expire_now(struct udevice *dev, ulong flags);
59
60/*
61 * struct wdt_ops - Driver model wdt operations
62 *
63 * The uclass interface is implemented by all wdt devices which use
64 * driver model.
65 */
66struct wdt_ops {
67 /*
68 * Start the timer
69 *
70 * @dev: WDT Device
Andy Shevchenkoffdec302017-08-04 15:48:28 -060071 * @timeout_ms: Number of ticks (milliseconds) before the timer expires
maxims@google.com0753bc22017-04-17 12:00:21 -070072 * @flags: Driver specific flags. This might be used to specify
73 * which action needs to be executed when the timer expires
74 * @return: 0 if OK, -ve on error
75 */
Andy Shevchenkoffdec302017-08-04 15:48:28 -060076 int (*start)(struct udevice *dev, u64 timeout_ms, ulong flags);
maxims@google.com0753bc22017-04-17 12:00:21 -070077 /*
78 * Stop the timer
79 *
80 * @dev: WDT Device
81 * @return: 0 if OK, -ve on error
82 */
83 int (*stop)(struct udevice *dev);
84 /*
85 * Reset the timer, typically restoring the counter to
86 * the value configured by start()
87 *
88 * @dev: WDT Device
89 * @return: 0 if OK, -ve on error
90 */
91 int (*reset)(struct udevice *dev);
92 /*
93 * Expire the timer, thus executing the action immediately (optional)
94 *
95 * If this function is not provided, a default implementation
96 * will be used, which sets the counter to 1
97 * and waits forever. This is good enough for system level
98 * reset, where the function is not expected to return, but might not be
99 * good enough for other use cases.
100 *
101 * @dev: WDT Device
102 * @flags: Driver specific flags
103 * @return 0 if OK -ve on error. May not return.
104 */
105 int (*expire_now)(struct udevice *dev, ulong flags);
106};
107
Rasmus Villemoesb4d94522020-03-13 17:04:57 +0100108int initr_watchdog(void);
Stefan Roese06985282019-04-11 15:58:44 +0200109
maxims@google.com0753bc22017-04-17 12:00:21 -0700110#endif /* _WDT_H_ */