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