sandbox_timer.c 985 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <errno.h>
  9. #include <timer.h>
  10. #include <os.h>
  11. /* system timer offset in ms */
  12. static unsigned long sandbox_timer_offset;
  13. void sandbox_timer_add_offset(unsigned long offset)
  14. {
  15. sandbox_timer_offset += offset;
  16. }
  17. static int sandbox_timer_get_count(struct udevice *dev, unsigned long *count)
  18. {
  19. *count = os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
  20. return 0;
  21. }
  22. static int sandbox_timer_probe(struct udevice *dev)
  23. {
  24. return 0;
  25. }
  26. static const struct timer_ops sandbox_timer_ops = {
  27. .get_count = sandbox_timer_get_count,
  28. };
  29. static const struct udevice_id sandbox_timer_ids[] = {
  30. { .compatible = "sandbox,timer" },
  31. { }
  32. };
  33. U_BOOT_DRIVER(sandbox_timer) = {
  34. .name = "sandbox_timer",
  35. .id = UCLASS_TIMER,
  36. .of_match = sandbox_timer_ids,
  37. .probe = sandbox_timer_probe,
  38. .ops = &sandbox_timer_ops,
  39. .flags = DM_FLAG_PRE_RELOC,
  40. };