blob: 4a619f71fe910b7a18c6e37d7f0fe13e37423c91 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
maxims@google.comdaea6d42017-04-17 12:00:21 -07002/*
3 * Copyright 2017 Google, Inc
maxims@google.comdaea6d42017-04-17 12:00:21 -07004 */
5
6#include <common.h>
7#include <dm.h>
8#include <errno.h>
9#include <wdt.h>
10#include <dm/device-internal.h>
11#include <dm/lists.h>
12
Andy Shevchenko2befb4b2017-08-04 15:48:28 -060013int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
maxims@google.comdaea6d42017-04-17 12:00:21 -070014{
15 const struct wdt_ops *ops = device_get_ops(dev);
16
17 if (!ops->start)
18 return -ENOSYS;
19
Andy Shevchenko2befb4b2017-08-04 15:48:28 -060020 return ops->start(dev, timeout_ms, flags);
maxims@google.comdaea6d42017-04-17 12:00:21 -070021}
22
23int wdt_stop(struct udevice *dev)
24{
25 const struct wdt_ops *ops = device_get_ops(dev);
26
27 if (!ops->stop)
28 return -ENOSYS;
29
30 return ops->stop(dev);
31}
32
33int wdt_reset(struct udevice *dev)
34{
35 const struct wdt_ops *ops = device_get_ops(dev);
36
37 if (!ops->reset)
38 return -ENOSYS;
39
40 return ops->reset(dev);
41}
42
43int wdt_expire_now(struct udevice *dev, ulong flags)
44{
45 int ret = 0;
46 const struct wdt_ops *ops;
47
Andy Shevchenkof047be42017-07-05 20:44:06 +030048 debug("WDT Resetting: %lu\n", flags);
maxims@google.comdaea6d42017-04-17 12:00:21 -070049 ops = device_get_ops(dev);
50 if (ops->expire_now) {
51 return ops->expire_now(dev, flags);
52 } else {
53 if (!ops->start)
54 return -ENOSYS;
55
56 ret = ops->start(dev, 1, flags);
57 if (ret < 0)
58 return ret;
59
60 hang();
61 }
62
63 return ret;
64}
65
66UCLASS_DRIVER(wdt) = {
67 .id = UCLASS_WDT,
68 .name = "wdt",
69};