Blame view
include/wdt.h
4.08 KB
83d290c56 SPDX: Convert all... |
1 |
/* SPDX-License-Identifier: GPL-2.0+ */ |
0753bc2d3 dm: Simple Watchd... |
2 3 |
/* * Copyright 2017 Google, Inc |
0753bc2d3 dm: Simple Watchd... |
4 5 6 7 |
*/ #ifndef _WDT_H_ #define _WDT_H_ |
06985289d watchdog: Impleme... |
8 9 |
#include <dm.h> #include <dm/read.h> |
0753bc2d3 dm: Simple Watchd... |
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
/* * Implement a simple watchdog uclass. Watchdog is basically a timer that * is used to detect or recover from malfunction. During normal operation * the watchdog would be regularly reset to prevent it from timing out. * If, due to a hardware fault or program error, the computer fails to reset * the watchdog, the timer will elapse and generate a timeout signal. * The timeout signal is used to initiate corrective action or actions, * which typically include placing the system in a safe, known state. */ /* * Start the timer * * @dev: WDT Device |
ffdec3000 wdt: Update uclas... |
24 |
* @timeout_ms: Number of ticks (milliseconds) before timer expires |
0753bc2d3 dm: Simple Watchd... |
25 26 27 28 |
* @flags: Driver specific flags. This might be used to specify * which action needs to be executed when the timer expires * @return: 0 if OK, -ve on error */ |
ffdec3000 wdt: Update uclas... |
29 |
int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags); |
0753bc2d3 dm: Simple Watchd... |
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
/* * Stop the timer, thus disabling the Watchdog. Use wdt_start to start it again. * * @dev: WDT Device * @return: 0 if OK, -ve on error */ int wdt_stop(struct udevice *dev); /* * Reset the timer, typically restoring the counter to * the value configured by start() * * @dev: WDT Device * @return: 0 if OK, -ve on error */ int wdt_reset(struct udevice *dev); /* * Expire the timer, thus executing its action immediately. * This is typically used to reset the board or peripherals. * * @dev: WDT Device * @flags: Driver specific flags * @return 0 if OK -ve on error. If wdt action is system reset, * this function may never return. */ int wdt_expire_now(struct udevice *dev, ulong flags); /* * struct wdt_ops - Driver model wdt operations * * The uclass interface is implemented by all wdt devices which use * driver model. */ struct wdt_ops { /* * Start the timer * * @dev: WDT Device |
ffdec3000 wdt: Update uclas... |
70 |
* @timeout_ms: Number of ticks (milliseconds) before the timer expires |
0753bc2d3 dm: Simple Watchd... |
71 72 73 74 |
* @flags: Driver specific flags. This might be used to specify * which action needs to be executed when the timer expires * @return: 0 if OK, -ve on error */ |
ffdec3000 wdt: Update uclas... |
75 |
int (*start)(struct udevice *dev, u64 timeout_ms, ulong flags); |
0753bc2d3 dm: Simple Watchd... |
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
/* * Stop the timer * * @dev: WDT Device * @return: 0 if OK, -ve on error */ int (*stop)(struct udevice *dev); /* * Reset the timer, typically restoring the counter to * the value configured by start() * * @dev: WDT Device * @return: 0 if OK, -ve on error */ int (*reset)(struct udevice *dev); /* * Expire the timer, thus executing the action immediately (optional) * * If this function is not provided, a default implementation * will be used, which sets the counter to 1 * and waits forever. This is good enough for system level * reset, where the function is not expected to return, but might not be * good enough for other use cases. * * @dev: WDT Device * @flags: Driver specific flags * @return 0 if OK -ve on error. May not return. */ int (*expire_now)(struct udevice *dev, ulong flags); }; |
6874cb722 watchdog: Split W... |
106 |
#if CONFIG_IS_ENABLED(WDT) |
06985289d watchdog: Impleme... |
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
#ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS #define CONFIG_WATCHDOG_TIMEOUT_MSECS (60 * 1000) #endif #define WATCHDOG_TIMEOUT_SECS (CONFIG_WATCHDOG_TIMEOUT_MSECS / 1000) static inline int initr_watchdog(void) { u32 timeout = WATCHDOG_TIMEOUT_SECS; /* * Init watchdog: This will call the probe function of the * watchdog driver, enabling the use of the device */ if (uclass_get_device_by_seq(UCLASS_WDT, 0, (struct udevice **)&gd->watchdog_dev)) { debug("WDT: Not found by seq! "); if (uclass_get_device(UCLASS_WDT, 0, (struct udevice **)&gd->watchdog_dev)) { printf("WDT: Not found! "); return 0; } } |
ed666fb12 watchdog: Use dev... |
131 |
if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) { |
06985289d watchdog: Impleme... |
132 133 134 |
timeout = dev_read_u32_default(gd->watchdog_dev, "timeout-sec", WATCHDOG_TIMEOUT_SECS); } |
06985289d watchdog: Impleme... |
135 136 137 138 139 140 141 142 143 |
wdt_start(gd->watchdog_dev, timeout * 1000, 0); gd->flags |= GD_FLG_WDT_READY; printf("WDT: Started with%s servicing (%ds timeout) ", IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout); return 0; } #endif |
0753bc2d3 dm: Simple Watchd... |
144 |
#endif /* _WDT_H_ */ |