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