timer.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 <asm/arch/pxa-regs.h>
  29. #include <asm/io.h>
  30. #include <common.h>
  31. #include <div64.h>
  32. #ifdef CONFIG_USE_IRQ
  33. #error: interrupts not implemented yet
  34. #endif
  35. #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS)
  36. #define TIMER_FREQ_HZ 3250000
  37. #elif defined(CONFIG_PXA250)
  38. #define TIMER_FREQ_HZ 3686400
  39. #else
  40. #error "Timer frequency unknown - please config PXA CPU type"
  41. #endif
  42. static inline unsigned long long tick_to_time(unsigned long long tick)
  43. {
  44. tick *= CONFIG_SYS_HZ;
  45. do_div(tick, TIMER_FREQ_HZ);
  46. return tick;
  47. }
  48. static inline unsigned long long us_to_tick(unsigned long long us)
  49. {
  50. us = us * TIMER_FREQ_HZ + 999999;
  51. do_div(us, 1000000);
  52. return us;
  53. }
  54. int timer_init (void)
  55. {
  56. reset_timer();
  57. return 0;
  58. }
  59. void reset_timer (void)
  60. {
  61. reset_timer_masked ();
  62. }
  63. ulong get_timer (ulong base)
  64. {
  65. return get_timer_masked () - base;
  66. }
  67. void set_timer (ulong t)
  68. {
  69. /* nop */
  70. }
  71. void __udelay (unsigned long usec)
  72. {
  73. udelay_masked (usec);
  74. }
  75. void reset_timer_masked (void)
  76. {
  77. writel(0, OSCR);
  78. }
  79. ulong get_timer_masked (void)
  80. {
  81. return tick_to_time(get_ticks());
  82. }
  83. void udelay_masked (unsigned long usec)
  84. {
  85. unsigned long long tmp;
  86. ulong tmo;
  87. tmo = us_to_tick(usec);
  88. tmp = get_ticks() + tmo; /* get current timestamp */
  89. while (get_ticks() < tmp) /* loop till event */
  90. /*NOP*/;
  91. }
  92. /*
  93. * This function is derived from PowerPC code (read timebase as long long).
  94. * On ARM it just returns the timer value.
  95. */
  96. unsigned long long get_ticks(void)
  97. {
  98. return readl(OSCR);
  99. }
  100. /*
  101. * This function is derived from PowerPC code (timebase clock frequency).
  102. * On ARM it returns the number of timer ticks per second.
  103. */
  104. ulong get_tbclk (void)
  105. {
  106. ulong tbclk;
  107. tbclk = TIMER_FREQ_HZ;
  108. return tbclk;
  109. }