X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=include%2Fwdt.h;h=aa77d3e9b40368af889b67e81fa411d9c66d42e4;hb=5656d04537a9d047aee66683200d909b7e0cfc04;hp=0b5f05851a33c0e7527d30958a86e2214a9469e4;hpb=a6d4cd4778bcc30f451f2d5d92ec4722ff5b71cc;p=oweals%2Fu-boot.git diff --git a/include/wdt.h b/include/wdt.h index 0b5f05851a..aa77d3e9b4 100644 --- a/include/wdt.h +++ b/include/wdt.h @@ -1,12 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright 2017 Google, Inc - * - * SPDX-License-Identifier: GPL-2.0+ */ #ifndef _WDT_H_ #define _WDT_H_ +#include +#include + /* * Implement a simple watchdog uclass. Watchdog is basically a timer that * is used to detect or recover from malfunction. During normal operation @@ -21,12 +23,12 @@ * Start the timer * * @dev: WDT Device - * @timeout: Number of ticks before timer expires + * @timeout_ms: Number of ticks (milliseconds) before timer expires * @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 */ -int wdt_start(struct udevice *dev, u64 timeout, ulong flags); +int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags); /* * Stop the timer, thus disabling the Watchdog. Use wdt_start to start it again. @@ -67,12 +69,12 @@ struct wdt_ops { * Start the timer * * @dev: WDT Device - * @timeout: Number of ticks before the timer expires + * @timeout_ms: Number of ticks (milliseconds) before the timer expires * @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 */ - int (*start)(struct udevice *dev, u64 timeout, ulong flags); + int (*start)(struct udevice *dev, u64 timeout_ms, ulong flags); /* * Stop the timer * @@ -104,4 +106,42 @@ struct wdt_ops { int (*expire_now)(struct udevice *dev, ulong flags); }; +#if defined(CONFIG_WDT) +#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!\n"); + if (uclass_get_device(UCLASS_WDT, 0, + (struct udevice **)&gd->watchdog_dev)) { + printf("WDT: Not found!\n"); + return 0; + } + } + + if (CONFIG_IS_ENABLED(OF_CONTROL)) { + timeout = dev_read_u32_default(gd->watchdog_dev, "timeout-sec", + WATCHDOG_TIMEOUT_SECS); + } + + wdt_start(gd->watchdog_dev, timeout * 1000, 0); + gd->flags |= GD_FLG_WDT_READY; + printf("WDT: Started with%s servicing (%ds timeout)\n", + IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", timeout); + + return 0; +} +#endif + #endif /* _WDT_H_ */