blob: 1eb5721d1a606fe99593596b9aa91d87b4fdf125 [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
Andy Shevchenkoffdec302017-08-04 15:48:28 -060014int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
maxims@google.com0753bc22017-04-17 12:00:21 -070015{
16 const struct wdt_ops *ops = device_get_ops(dev);
17
18 if (!ops->start)
19 return -ENOSYS;
20
Andy Shevchenkoffdec302017-08-04 15:48:28 -060021 return ops->start(dev, timeout_ms, flags);
maxims@google.com0753bc22017-04-17 12:00:21 -070022}
23
24int wdt_stop(struct udevice *dev)
25{
26 const struct wdt_ops *ops = device_get_ops(dev);
27
28 if (!ops->stop)
29 return -ENOSYS;
30
31 return ops->stop(dev);
32}
33
34int wdt_reset(struct udevice *dev)
35{
36 const struct wdt_ops *ops = device_get_ops(dev);
37
38 if (!ops->reset)
39 return -ENOSYS;
40
41 return ops->reset(dev);
42}
43
44int wdt_expire_now(struct udevice *dev, ulong flags)
45{
46 int ret = 0;
47 const struct wdt_ops *ops;
48
Andy Shevchenkob71e0c12017-07-05 20:44:06 +030049 debug("WDT Resetting: %lu\n", flags);
maxims@google.com0753bc22017-04-17 12:00:21 -070050 ops = device_get_ops(dev);
51 if (ops->expire_now) {
52 return ops->expire_now(dev, flags);
53 } else {
54 if (!ops->start)
55 return -ENOSYS;
56
57 ret = ops->start(dev, 1, flags);
58 if (ret < 0)
59 return ret;
60
61 hang();
62 }
63
64 return ret;
65}
66
67UCLASS_DRIVER(wdt) = {
68 .id = UCLASS_WDT,
69 .name = "wdt",
70};