Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
maxims@google.com | daea6d4 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2017 Google, Inc |
maxims@google.com | daea6d4 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <errno.h> |
| 9 | #include <wdt.h> |
| 10 | #include <dm/device-internal.h> |
| 11 | #include <dm/lists.h> |
| 12 | |
Andy Shevchenko | 2befb4b | 2017-08-04 15:48:28 -0600 | [diff] [blame] | 13 | int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags) |
maxims@google.com | daea6d4 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 14 | { |
| 15 | const struct wdt_ops *ops = device_get_ops(dev); |
| 16 | |
| 17 | if (!ops->start) |
| 18 | return -ENOSYS; |
| 19 | |
Andy Shevchenko | 2befb4b | 2017-08-04 15:48:28 -0600 | [diff] [blame] | 20 | return ops->start(dev, timeout_ms, flags); |
maxims@google.com | daea6d4 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | int wdt_stop(struct udevice *dev) |
| 24 | { |
| 25 | const struct wdt_ops *ops = device_get_ops(dev); |
| 26 | |
| 27 | if (!ops->stop) |
| 28 | return -ENOSYS; |
| 29 | |
| 30 | return ops->stop(dev); |
| 31 | } |
| 32 | |
| 33 | int wdt_reset(struct udevice *dev) |
| 34 | { |
| 35 | const struct wdt_ops *ops = device_get_ops(dev); |
| 36 | |
| 37 | if (!ops->reset) |
| 38 | return -ENOSYS; |
| 39 | |
| 40 | return ops->reset(dev); |
| 41 | } |
| 42 | |
| 43 | int wdt_expire_now(struct udevice *dev, ulong flags) |
| 44 | { |
| 45 | int ret = 0; |
| 46 | const struct wdt_ops *ops; |
| 47 | |
Andy Shevchenko | f047be4 | 2017-07-05 20:44:06 +0300 | [diff] [blame] | 48 | debug("WDT Resetting: %lu\n", flags); |
maxims@google.com | daea6d4 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 49 | ops = device_get_ops(dev); |
| 50 | if (ops->expire_now) { |
| 51 | return ops->expire_now(dev, flags); |
| 52 | } else { |
| 53 | if (!ops->start) |
| 54 | return -ENOSYS; |
| 55 | |
| 56 | ret = ops->start(dev, 1, flags); |
| 57 | if (ret < 0) |
| 58 | return ret; |
| 59 | |
| 60 | hang(); |
| 61 | } |
| 62 | |
| 63 | return ret; |
| 64 | } |
| 65 | |
Michal Simek | 7b5eca9 | 2018-07-11 15:42:25 +0200 | [diff] [blame] | 66 | static int wdt_post_bind(struct udevice *dev) |
| 67 | { |
| 68 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
| 69 | struct wdt_ops *ops = (struct wdt_ops *)device_get_ops(dev); |
| 70 | static int reloc_done; |
| 71 | |
| 72 | if (!reloc_done) { |
| 73 | if (ops->start) |
| 74 | ops->start += gd->reloc_off; |
| 75 | if (ops->stop) |
| 76 | ops->stop += gd->reloc_off; |
| 77 | if (ops->reset) |
| 78 | ops->reset += gd->reloc_off; |
| 79 | if (ops->expire_now) |
| 80 | ops->expire_now += gd->reloc_off; |
| 81 | |
| 82 | reloc_done++; |
| 83 | } |
| 84 | #endif |
| 85 | return 0; |
| 86 | } |
| 87 | |
maxims@google.com | daea6d4 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 88 | UCLASS_DRIVER(wdt) = { |
| 89 | .id = UCLASS_WDT, |
Michal Simek | fc61be3 | 2018-07-11 08:24:43 +0200 | [diff] [blame] | 90 | .name = "watchdog", |
| 91 | .flags = DM_UC_FLAG_SEQ_ALIAS, |
Michal Simek | 7b5eca9 | 2018-07-11 15:42:25 +0200 | [diff] [blame] | 92 | .post_bind = wdt_post_bind, |
maxims@google.com | daea6d4 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 93 | }; |