10753bc2dSmaxims@google.com /*
20753bc2dSmaxims@google.com * Copyright 2017 Google, Inc
30753bc2dSmaxims@google.com *
40753bc2dSmaxims@google.com * SPDX-License-Identifier: GPL-2.0+
50753bc2dSmaxims@google.com */
60753bc2dSmaxims@google.com
70753bc2dSmaxims@google.com #include <common.h>
80753bc2dSmaxims@google.com #include <dm.h>
90753bc2dSmaxims@google.com #include <errno.h>
100753bc2dSmaxims@google.com #include <wdt.h>
110753bc2dSmaxims@google.com #include <dm/device-internal.h>
120753bc2dSmaxims@google.com #include <dm/lists.h>
130753bc2dSmaxims@google.com
140753bc2dSmaxims@google.com DECLARE_GLOBAL_DATA_PTR;
150753bc2dSmaxims@google.com
wdt_start(struct udevice * dev,u64 timeout_ms,ulong flags)16*ffdec300SAndy Shevchenko int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
170753bc2dSmaxims@google.com {
180753bc2dSmaxims@google.com const struct wdt_ops *ops = device_get_ops(dev);
190753bc2dSmaxims@google.com
200753bc2dSmaxims@google.com if (!ops->start)
210753bc2dSmaxims@google.com return -ENOSYS;
220753bc2dSmaxims@google.com
23*ffdec300SAndy Shevchenko return ops->start(dev, timeout_ms, flags);
240753bc2dSmaxims@google.com }
250753bc2dSmaxims@google.com
wdt_stop(struct udevice * dev)260753bc2dSmaxims@google.com int wdt_stop(struct udevice *dev)
270753bc2dSmaxims@google.com {
280753bc2dSmaxims@google.com const struct wdt_ops *ops = device_get_ops(dev);
290753bc2dSmaxims@google.com
300753bc2dSmaxims@google.com if (!ops->stop)
310753bc2dSmaxims@google.com return -ENOSYS;
320753bc2dSmaxims@google.com
330753bc2dSmaxims@google.com return ops->stop(dev);
340753bc2dSmaxims@google.com }
350753bc2dSmaxims@google.com
wdt_reset(struct udevice * dev)360753bc2dSmaxims@google.com int wdt_reset(struct udevice *dev)
370753bc2dSmaxims@google.com {
380753bc2dSmaxims@google.com const struct wdt_ops *ops = device_get_ops(dev);
390753bc2dSmaxims@google.com
400753bc2dSmaxims@google.com if (!ops->reset)
410753bc2dSmaxims@google.com return -ENOSYS;
420753bc2dSmaxims@google.com
430753bc2dSmaxims@google.com return ops->reset(dev);
440753bc2dSmaxims@google.com }
450753bc2dSmaxims@google.com
wdt_expire_now(struct udevice * dev,ulong flags)460753bc2dSmaxims@google.com int wdt_expire_now(struct udevice *dev, ulong flags)
470753bc2dSmaxims@google.com {
480753bc2dSmaxims@google.com int ret = 0;
490753bc2dSmaxims@google.com const struct wdt_ops *ops;
500753bc2dSmaxims@google.com
51b71e0c1aSAndy Shevchenko debug("WDT Resetting: %lu\n", flags);
520753bc2dSmaxims@google.com ops = device_get_ops(dev);
530753bc2dSmaxims@google.com if (ops->expire_now) {
540753bc2dSmaxims@google.com return ops->expire_now(dev, flags);
550753bc2dSmaxims@google.com } else {
560753bc2dSmaxims@google.com if (!ops->start)
570753bc2dSmaxims@google.com return -ENOSYS;
580753bc2dSmaxims@google.com
590753bc2dSmaxims@google.com ret = ops->start(dev, 1, flags);
600753bc2dSmaxims@google.com if (ret < 0)
610753bc2dSmaxims@google.com return ret;
620753bc2dSmaxims@google.com
630753bc2dSmaxims@google.com hang();
640753bc2dSmaxims@google.com }
650753bc2dSmaxims@google.com
660753bc2dSmaxims@google.com return ret;
670753bc2dSmaxims@google.com }
680753bc2dSmaxims@google.com
690753bc2dSmaxims@google.com UCLASS_DRIVER(wdt) = {
700753bc2dSmaxims@google.com .id = UCLASS_WDT,
710753bc2dSmaxims@google.com .name = "wdt",
720753bc2dSmaxims@google.com };
73