sandbox_wdt.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2017 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <wdt.h>
  8. #include <asm/state.h>
  9. static int sandbox_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
  10. {
  11. struct sandbox_state *state = state_get_current();
  12. state->wdt.counter = timeout;
  13. state->wdt.running = true;
  14. return 0;
  15. }
  16. static int sandbox_wdt_stop(struct udevice *dev)
  17. {
  18. struct sandbox_state *state = state_get_current();
  19. state->wdt.running = false;
  20. return 0;
  21. }
  22. static int sandbox_wdt_reset(struct udevice *dev)
  23. {
  24. struct sandbox_state *state = state_get_current();
  25. state->wdt.reset_count++;
  26. return 0;
  27. }
  28. static int sandbox_wdt_expire_now(struct udevice *dev, ulong flags)
  29. {
  30. sandbox_wdt_start(dev, 1, flags);
  31. sandbox_reset();
  32. return 0;
  33. }
  34. static const struct wdt_ops sandbox_wdt_ops = {
  35. .start = sandbox_wdt_start,
  36. .reset = sandbox_wdt_reset,
  37. .stop = sandbox_wdt_stop,
  38. .expire_now = sandbox_wdt_expire_now,
  39. };
  40. static const struct udevice_id sandbox_wdt_ids[] = {
  41. { .compatible = "sandbox,wdt" },
  42. {}
  43. };
  44. U_BOOT_DRIVER(wdt_sandbox) = {
  45. .name = "wdt_sandbox",
  46. .id = UCLASS_WDT,
  47. .of_match = sandbox_wdt_ids,
  48. .ops = &sandbox_wdt_ops,
  49. };