timer.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. writel(0, OSCR);
  57. return 0;
  58. }
  59. ulong get_timer (ulong base)
  60. {
  61. return get_timer_masked () - base;
  62. }
  63. void __udelay (unsigned long usec)
  64. {
  65. udelay_masked (usec);
  66. }
  67. ulong get_timer_masked (void)
  68. {
  69. return tick_to_time(get_ticks());
  70. }
  71. void udelay_masked (unsigned long usec)
  72. {
  73. unsigned long long tmp;
  74. ulong tmo;
  75. tmo = us_to_tick(usec);
  76. tmp = get_ticks() + tmo; /* get current timestamp */
  77. while (get_ticks() < tmp) /* loop till event */
  78. /*NOP*/;
  79. }
  80. /*
  81. * This function is derived from PowerPC code (read timebase as long long).
  82. * On ARM it just returns the timer value.
  83. */
  84. unsigned long long get_ticks(void)
  85. {
  86. return readl(OSCR);
  87. }
  88. /*
  89. * This function is derived from PowerPC code (timebase clock frequency).
  90. * On ARM it returns the number of timer ticks per second.
  91. */
  92. ulong get_tbclk (void)
  93. {
  94. ulong tbclk;
  95. tbclk = TIMER_FREQ_HZ;
  96. return tbclk;
  97. }