sysreset_watchdog.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <errno.h>
  9. #include <sysreset.h>
  10. #include <wdt.h>
  11. struct wdt_reboot_priv {
  12. struct udevice *wdt;
  13. };
  14. static int wdt_reboot_request(struct udevice *dev, enum sysreset_t type)
  15. {
  16. struct wdt_reboot_priv *priv = dev_get_priv(dev);
  17. int ret;
  18. ret = wdt_expire_now(priv->wdt, 0);
  19. if (ret)
  20. return ret;
  21. return -EINPROGRESS;
  22. }
  23. static struct sysreset_ops wdt_reboot_ops = {
  24. .request = wdt_reboot_request,
  25. };
  26. int wdt_reboot_probe(struct udevice *dev)
  27. {
  28. struct wdt_reboot_priv *priv = dev_get_priv(dev);
  29. int err;
  30. err = uclass_get_device_by_phandle(UCLASS_WDT, dev,
  31. "wdt", &priv->wdt);
  32. if (err) {
  33. error("unable to find wdt device\n");
  34. return err;
  35. }
  36. return 0;
  37. }
  38. static const struct udevice_id wdt_reboot_ids[] = {
  39. { .compatible = "wdt-reboot" },
  40. { /* sentinel */ }
  41. };
  42. U_BOOT_DRIVER(wdt_reboot) = {
  43. .name = "wdt_reboot",
  44. .id = UCLASS_SYSRESET,
  45. .of_match = wdt_reboot_ids,
  46. .ops = &wdt_reboot_ops,
  47. .priv_auto_alloc_size = sizeof(struct wdt_reboot_priv),
  48. .probe = wdt_reboot_probe,
  49. };