]>
Commit | Line | Data |
---|---|---|
0753bc2d | 1 | /* |
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 | ||
14 | DECLARE_GLOBAL_DATA_PTR; | |
15 | ||
16 | int 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 | ||
26 | int 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 | ||
36 | int 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 | ||
46 | int wdt_expire_now(struct udevice *dev, ulong flags) | |
47 | { | |
48 | int ret = 0; | |
49 | const struct wdt_ops *ops; | |
50 | ||
51 | debug("WDT Resettting: %lu\n", flags); | |
52 | 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 | ||
69 | UCLASS_DRIVER(wdt) = { | |
70 | .id = UCLASS_WDT, | |
71 | .name = "wdt", | |
72 | }; |