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 int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags) 15 { 16 const struct wdt_ops *ops = device_get_ops(dev); 17 18 if (!ops->start) 19 return -ENOSYS; 20 21 return ops->start(dev, timeout_ms, flags); 22 } 23 24 int 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 34 int 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 44 int wdt_expire_now(struct udevice *dev, ulong flags) 45 { 46 int ret = 0; 47 const struct wdt_ops *ops; 48 49 debug("WDT Resetting: %lu\n", flags); 50 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 67 UCLASS_DRIVER(wdt) = { 68 .id = UCLASS_WDT, 69 .name = "wdt", 70 }; 71