sysreset_watchdog.c 1.1 KB

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