1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2017 Google, Inc
10 #include <dm/device-internal.h>
13 DECLARE_GLOBAL_DATA_PTR
;
15 int wdt_start(struct udevice
*dev
, u64 timeout_ms
, ulong flags
)
17 const struct wdt_ops
*ops
= device_get_ops(dev
);
22 return ops
->start(dev
, timeout_ms
, flags
);
25 int wdt_stop(struct udevice
*dev
)
27 const struct wdt_ops
*ops
= device_get_ops(dev
);
32 return ops
->stop(dev
);
35 int wdt_reset(struct udevice
*dev
)
37 const struct wdt_ops
*ops
= device_get_ops(dev
);
42 return ops
->reset(dev
);
45 int wdt_expire_now(struct udevice
*dev
, ulong flags
)
48 const struct wdt_ops
*ops
;
50 debug("WDT Resetting: %lu\n", flags
);
51 ops
= device_get_ops(dev
);
52 if (ops
->expire_now
) {
53 return ops
->expire_now(dev
, flags
);
58 ret
= ops
->start(dev
, 1, flags
);
68 #if defined(CONFIG_WATCHDOG)
70 * Called by macro WATCHDOG_RESET. This function be called *very* early,
71 * so we need to make sure, that the watchdog driver is ready before using
72 * it in this function.
74 void watchdog_reset(void)
76 static ulong next_reset
;
79 /* Exit if GD is not ready or watchdog is not initialized yet */
80 if (!gd
|| !(gd
->flags
& GD_FLG_WDT_READY
))
83 /* Do not reset the watchdog too often */
85 if (now
> next_reset
) {
86 next_reset
= now
+ 1000; /* reset every 1000ms */
87 wdt_reset(gd
->watchdog_dev
);
92 static int wdt_post_bind(struct udevice
*dev
)
94 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
95 struct wdt_ops
*ops
= (struct wdt_ops
*)device_get_ops(dev
);
96 static int reloc_done
;
100 ops
->start
+= gd
->reloc_off
;
102 ops
->stop
+= gd
->reloc_off
;
104 ops
->reset
+= gd
->reloc_off
;
106 ops
->expire_now
+= gd
->reloc_off
;
114 UCLASS_DRIVER(wdt
) = {
117 .flags
= DM_UC_FLAG_SEQ_ALIAS
,
118 .post_bind
= wdt_post_bind
,