maxims@google.com | daea6d4 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 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 | |
Andy Shevchenko | 2befb4b | 2017-08-04 15:48:28 -0600 | [diff] [blame^] | 16 | int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags) |
maxims@google.com | daea6d4 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 17 | { |
| 18 | const struct wdt_ops *ops = device_get_ops(dev); |
| 19 | |
| 20 | if (!ops->start) |
| 21 | return -ENOSYS; |
| 22 | |
Andy Shevchenko | 2befb4b | 2017-08-04 15:48:28 -0600 | [diff] [blame^] | 23 | return ops->start(dev, timeout_ms, flags); |
maxims@google.com | daea6d4 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 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 | |
Andy Shevchenko | f047be4 | 2017-07-05 20:44:06 +0300 | [diff] [blame] | 51 | debug("WDT Resetting: %lu\n", flags); |
maxims@google.com | daea6d4 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 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 | }; |