timer.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * (C) Copyright 2002
  3. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  4. * Marius Groeger <mgroeger@sysgo.de>
  5. *
  6. * (C) Copyright 2002
  7. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  8. * Alex Zuepke <azu@sysgo.de>
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <common.h>
  29. #include <asm/arch/pxa-regs.h>
  30. #include <div64.h>
  31. #ifdef CONFIG_USE_IRQ
  32. #error: interrupts not implemented yet
  33. #endif
  34. #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS)
  35. #define TIMER_FREQ_HZ 3250000
  36. #elif defined(CONFIG_PXA250)
  37. #define TIMER_FREQ_HZ 3686400
  38. #else
  39. #error "Timer frequency unknown - please config PXA CPU type"
  40. #endif
  41. static inline unsigned long long tick_to_time(unsigned long long tick)
  42. {
  43. tick *= CONFIG_SYS_HZ;
  44. do_div(tick, TIMER_FREQ_HZ);
  45. return tick;
  46. }
  47. static inline unsigned long long us_to_tick(unsigned long long us)
  48. {
  49. us = us * TIMER_FREQ_HZ + 999999;
  50. do_div(us, 1000000);
  51. return us;
  52. }
  53. int timer_init (void)
  54. {
  55. reset_timer();
  56. return 0;
  57. }
  58. void reset_timer (void)
  59. {
  60. reset_timer_masked ();
  61. }
  62. ulong get_timer (ulong base)
  63. {
  64. return get_timer_masked () - base;
  65. }
  66. void set_timer (ulong t)
  67. {
  68. /* nop */
  69. }
  70. void udelay (unsigned long usec)
  71. {
  72. udelay_masked (usec);
  73. }
  74. void reset_timer_masked (void)
  75. {
  76. OSCR = 0;
  77. }
  78. ulong get_timer_masked (void)
  79. {
  80. return tick_to_time(get_ticks());
  81. }
  82. void udelay_masked (unsigned long usec)
  83. {
  84. unsigned long long tmp;
  85. ulong tmo;
  86. tmo = us_to_tick(usec);
  87. tmp = get_ticks() + tmo; /* get current timestamp */
  88. while (get_ticks() < tmp) /* loop till event */
  89. /*NOP*/;
  90. }
  91. /*
  92. * This function is derived from PowerPC code (read timebase as long long).
  93. * On ARM it just returns the timer value.
  94. */
  95. unsigned long long get_ticks(void)
  96. {
  97. return OSCR;
  98. }
  99. /*
  100. * This function is derived from PowerPC code (timebase clock frequency).
  101. * On ARM it returns the number of timer ticks per second.
  102. */
  103. ulong get_tbclk (void)
  104. {
  105. ulong tbclk;
  106. tbclk = TIMER_FREQ_HZ;
  107. return tbclk;
  108. }