1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2017 Google, Inc
12 #include <dm/device-internal.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
19 const struct wdt_ops *ops = device_get_ops(dev);
24 return ops->start(dev, timeout_ms, flags);
27 int wdt_stop(struct udevice *dev)
29 const struct wdt_ops *ops = device_get_ops(dev);
34 return ops->stop(dev);
37 int wdt_reset(struct udevice *dev)
39 const struct wdt_ops *ops = device_get_ops(dev);
44 return ops->reset(dev);
47 int wdt_expire_now(struct udevice *dev, ulong flags)
50 const struct wdt_ops *ops;
52 debug("WDT Resetting: %lu\n", flags);
53 ops = device_get_ops(dev);
54 if (ops->expire_now) {
55 return ops->expire_now(dev, flags);
60 ret = ops->start(dev, 1, flags);
70 #if defined(CONFIG_WATCHDOG)
72 * Called by macro WATCHDOG_RESET. This function be called *very* early,
73 * so we need to make sure, that the watchdog driver is ready before using
74 * it in this function.
76 void watchdog_reset(void)
78 static ulong next_reset;
81 /* Exit if GD is not ready or watchdog is not initialized yet */
82 if (!gd || !(gd->flags & GD_FLG_WDT_READY))
85 /* Do not reset the watchdog too often */
87 if (time_after(now, next_reset)) {
88 next_reset = now + 1000; /* reset every 1000ms */
89 wdt_reset(gd->watchdog_dev);
94 static int wdt_post_bind(struct udevice *dev)
96 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
97 struct wdt_ops *ops = (struct wdt_ops *)device_get_ops(dev);
98 static int reloc_done;
102 ops->start += gd->reloc_off;
104 ops->stop += gd->reloc_off;
106 ops->reset += gd->reloc_off;
108 ops->expire_now += gd->reloc_off;
116 UCLASS_DRIVER(wdt) = {
119 .flags = DM_UC_FLAG_SEQ_ALIAS,
120 .post_bind = wdt_post_bind,