sandbox_wdt.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. return 0;
  32. }
  33. static const struct wdt_ops sandbox_wdt_ops = {
  34. .start = sandbox_wdt_start,
  35. .reset = sandbox_wdt_reset,
  36. .stop = sandbox_wdt_stop,
  37. .expire_now = sandbox_wdt_expire_now,
  38. };
  39. static const struct udevice_id sandbox_wdt_ids[] = {
  40. { .compatible = "sandbox,wdt" },
  41. {}
  42. };
  43. U_BOOT_DRIVER(wdt_sandbox) = {
  44. .name = "wdt_sandbox",
  45. .id = UCLASS_WDT,
  46. .of_match = sandbox_wdt_ids,
  47. .ops = &sandbox_wdt_ops,
  48. };