interrupts.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * (C) Copyright 2009
  3. * 2N Telekomunikace, <www.2n.cz>
  4. *
  5. * (C) Copyright 2003
  6. * Texas Instruments, <www.ti.com>
  7. *
  8. * (C) Copyright 2002
  9. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  10. * Marius Groeger <mgroeger@sysgo.de>
  11. *
  12. * (C) Copyright 2002
  13. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  14. * Alex Zuepke <azu@sysgo.de>
  15. *
  16. * (C) Copyright 2002
  17. * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
  18. *
  19. * See file CREDITS for list of people who contributed to this
  20. * project.
  21. *
  22. * This program is free software; you can redistribute it and/or
  23. * modify it under the terms of the GNU General Public License as
  24. * published by the Free Software Foundation; either version 2 of
  25. * the License, or (at your option) any later version.
  26. *
  27. * This program is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. * GNU General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU General Public License
  33. * along with this program; if not, write to the Free Software
  34. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  35. * MA 02111-1307 USA
  36. */
  37. #include <common.h>
  38. #include <arm925t.h>
  39. #include <configs/omap1510.h>
  40. #include <asm/io.h>
  41. #define TIMER_LOAD_VAL 0xffffffff
  42. #define TIMER_CLOCK (CONFIG_SYS_CLK_FREQ / (2 << CONFIG_SYS_PTV))
  43. static uint32_t timestamp;
  44. static uint32_t lastdec;
  45. /* nothing really to do with interrupts, just starts up a counter. */
  46. int interrupt_init (void)
  47. {
  48. /* Start the decrementer ticking down from 0xffffffff */
  49. __raw_writel(TIMER_LOAD_VAL, CONFIG_SYS_TIMERBASE + LOAD_TIM);
  50. __raw_writel(MPUTIM_ST | MPUTIM_AR | MPUTIM_CLOCK_ENABLE |
  51. (CONFIG_SYS_PTV << MPUTIM_PTV_BIT),
  52. CONFIG_SYS_TIMERBASE + CNTL_TIMER);
  53. /* init the timestamp and lastdec value */
  54. reset_timer_masked();
  55. return 0;
  56. }
  57. /*
  58. * timer without interrupts
  59. */
  60. void reset_timer (void)
  61. {
  62. reset_timer_masked ();
  63. }
  64. ulong get_timer (ulong base)
  65. {
  66. return get_timer_masked () - base;
  67. }
  68. void set_timer (ulong t)
  69. {
  70. timestamp = t;
  71. }
  72. /* delay x useconds AND preserve advance timestamp value */
  73. void udelay (unsigned long usec)
  74. {
  75. int32_t tmo = usec * (TIMER_CLOCK / 1000) / 1000;
  76. uint32_t now, last = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM);
  77. while (tmo > 0) {
  78. now = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM);
  79. if (last < now) /* count down timer underflow */
  80. tmo -= TIMER_LOAD_VAL - now + last;
  81. else
  82. tmo -= last - now;
  83. last = now;
  84. }
  85. }
  86. void reset_timer_masked (void)
  87. {
  88. /* reset time */
  89. lastdec = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM) /
  90. (TIMER_CLOCK / CONFIG_SYS_HZ);
  91. timestamp = 0; /* start "advancing" time stamp from 0 */
  92. }
  93. ulong get_timer_masked (void)
  94. {
  95. uint32_t now = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM) /
  96. (TIMER_CLOCK / CONFIG_SYS_HZ);
  97. if (lastdec < now) /* count down timer underflow */
  98. timestamp += TIMER_LOAD_VAL / (TIMER_CLOCK / CONFIG_SYS_HZ) -
  99. now + lastdec;
  100. else
  101. timestamp += lastdec - now;
  102. lastdec = now;
  103. return timestamp;
  104. }
  105. /*
  106. * This function is derived from PowerPC code (read timebase as long long).
  107. * On ARM it just returns the timer value.
  108. */
  109. unsigned long long get_ticks(void)
  110. {
  111. return get_timer(0);
  112. }
  113. /*
  114. * This function is derived from PowerPC code (timebase clock frequency).
  115. * On ARM it returns the number of timer ticks per second.
  116. */
  117. ulong get_tbclk (void)
  118. {
  119. return CONFIG_SYS_HZ;
  120. }