wdt-uclass.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2017 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <errno.h>
  8. #include <wdt.h>
  9. #include <dm/device-internal.h>
  10. #include <dm/lists.h>
  11. int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
  12. {
  13. const struct wdt_ops *ops = device_get_ops(dev);
  14. if (!ops->start)
  15. return -ENOSYS;
  16. return ops->start(dev, timeout_ms, flags);
  17. }
  18. int wdt_stop(struct udevice *dev)
  19. {
  20. const struct wdt_ops *ops = device_get_ops(dev);
  21. if (!ops->stop)
  22. return -ENOSYS;
  23. return ops->stop(dev);
  24. }
  25. int wdt_reset(struct udevice *dev)
  26. {
  27. const struct wdt_ops *ops = device_get_ops(dev);
  28. if (!ops->reset)
  29. return -ENOSYS;
  30. return ops->reset(dev);
  31. }
  32. int wdt_expire_now(struct udevice *dev, ulong flags)
  33. {
  34. int ret = 0;
  35. const struct wdt_ops *ops;
  36. debug("WDT Resetting: %lu\n", flags);
  37. ops = device_get_ops(dev);
  38. if (ops->expire_now) {
  39. return ops->expire_now(dev, flags);
  40. } else {
  41. if (!ops->start)
  42. return -ENOSYS;
  43. ret = ops->start(dev, 1, flags);
  44. if (ret < 0)
  45. return ret;
  46. hang();
  47. }
  48. return ret;
  49. }
  50. UCLASS_DRIVER(wdt) = {
  51. .id = UCLASS_WDT,
  52. .name = "wdt",
  53. };