blob: bb9ae808666f577bef796ab277f1ea8a8e20d6e8 [file] [log] [blame]
maxims@google.com0753bc22017-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
16int wdt_start(struct udevice *dev, u64 timeout, ulong flags)
17{
18 const struct wdt_ops *ops = device_get_ops(dev);
19
20 if (!ops->start)
21 return -ENOSYS;
22
23 return ops->start(dev, timeout, flags);
24}
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 Shevchenkob71e0c12017-07-05 20:44:06 +030051 debug("WDT Resetting: %lu\n", flags);
maxims@google.com0753bc22017-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};