blob: d2ccfbc62ef7cd14d5034120a7057a382c539862 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
maxims@google.comdaea6d42017-04-17 12:00:21 -07002/*
3 * Copyright 2017 Google, Inc
maxims@google.comdaea6d42017-04-17 12:00:21 -07004 */
5
6#ifndef _WDT_H_
7#define _WDT_H_
8
Stefan Roese502acb02019-04-11 15:58:44 +02009#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Stefan Roese502acb02019-04-11 15:58:44 +020011#include <dm/read.h>
12
maxims@google.comdaea6d42017-04-17 12:00:21 -070013/*
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
Andy Shevchenko2befb4b2017-08-04 15:48:28 -060027 * @timeout_ms: Number of ticks (milliseconds) before timer expires
maxims@google.comdaea6d42017-04-17 12:00:21 -070028 * @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 */
Andy Shevchenko2befb4b2017-08-04 15:48:28 -060032int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags);
maxims@google.comdaea6d42017-04-17 12:00:21 -070033
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 */
40int 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 */
49int 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 */
60int 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 */
68struct wdt_ops {
69 /*
70 * Start the timer
71 *
72 * @dev: WDT Device
Andy Shevchenko2befb4b2017-08-04 15:48:28 -060073 * @timeout_ms: Number of ticks (milliseconds) before the timer expires
maxims@google.comdaea6d42017-04-17 12:00:21 -070074 * @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 */
Andy Shevchenko2befb4b2017-08-04 15:48:28 -060078 int (*start)(struct udevice *dev, u64 timeout_ms, ulong flags);
maxims@google.comdaea6d42017-04-17 12:00:21 -070079 /*
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
Rasmus Villemoesf7c2e9f2020-03-13 17:04:57 +0100110int initr_watchdog(void);
Stefan Roese502acb02019-04-11 15:58:44 +0200111
maxims@google.comdaea6d42017-04-17 12:00:21 -0700112#endif /* _WDT_H_ */