timer.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2002
  4. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  5. * Marius Groeger <mgroeger@sysgo.de>
  6. *
  7. * (C) Copyright 2002
  8. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  9. * Alex Zuepke <azu@sysgo.de>
  10. */
  11. #include <common.h>
  12. #include <SA-1100.h>
  13. #include <time.h>
  14. #include <linux/delay.h>
  15. static ulong get_timer_masked (void)
  16. {
  17. return OSCR;
  18. }
  19. ulong get_timer (ulong base)
  20. {
  21. return get_timer_masked ();
  22. }
  23. void __udelay(unsigned long usec)
  24. {
  25. ulong tmo;
  26. ulong endtime;
  27. signed long diff;
  28. if (usec >= 1000) {
  29. tmo = usec / 1000;
  30. tmo *= CONFIG_SYS_HZ;
  31. tmo /= 1000;
  32. } else {
  33. tmo = usec * CONFIG_SYS_HZ;
  34. tmo /= (1000*1000);
  35. }
  36. endtime = get_timer_masked () + tmo;
  37. do {
  38. ulong now = get_timer_masked ();
  39. diff = endtime - now;
  40. } while (diff >= 0);
  41. }
  42. /*
  43. * This function is derived from PowerPC code (read timebase as long long).
  44. * On ARM it just returns the timer value.
  45. */
  46. unsigned long long get_ticks(void)
  47. {
  48. return get_timer(0);
  49. }
  50. /*
  51. * This function is derived from PowerPC code (timebase clock frequency).
  52. * On ARM it returns the number of timer ticks per second.
  53. */
  54. ulong get_tbclk(void)
  55. {
  56. return CONFIG_SYS_HZ;
  57. }