interrupts.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. * (C) Copyright 2002
  11. * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
  12. *
  13. * See file CREDITS for list of people who contributed to this
  14. * project.
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License as
  18. * published by the Free Software Foundation; either version 2 of
  19. * the License, or (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  29. * MA 02111-1307 USA
  30. */
  31. #include <common.h>
  32. #if defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) || defined (CONFIG_TRAB)
  33. #include <arm920t.h>
  34. #if defined(CONFIG_S3C2400)
  35. #include <s3c2400.h>
  36. #elif defined(CONFIG_S3C2410)
  37. #include <s3c2410.h>
  38. #endif
  39. extern void reset_cpu(ulong addr);
  40. int timer_load_val = 0;
  41. /* macro to read the 16 bit timer */
  42. static inline ulong READ_TIMER(void)
  43. {
  44. S3C24X0_TIMERS * const timers = S3C24X0_GetBase_TIMERS();
  45. return (timers->TCNTO4 & 0xffff);
  46. }
  47. static ulong timestamp;
  48. static ulong lastdec;
  49. int interrupt_init (void)
  50. {
  51. S3C24X0_TIMERS * const timers = S3C24X0_GetBase_TIMERS();
  52. /* use PWM Timer 4 because it has no output */
  53. /* prescaler for Timer 4 is 16 */
  54. timers->TCFG0 = 0x0f00;
  55. if (timer_load_val == 0)
  56. {
  57. /*
  58. * for 10 ms clock period @ PCLK with 4 bit divider = 1/2
  59. * (default) and prescaler = 16. Should be 10390
  60. * @33.25MHz and 15625 @ 50 MHz
  61. */
  62. timer_load_val = get_PCLK()/(2 * 16 * 100);
  63. }
  64. /* load value for 10 ms timeout */
  65. lastdec = timers->TCNTB4 = timer_load_val;
  66. /* auto load, manual update of Timer 4 */
  67. timers->TCON = (timers->TCON & ~0x0700000) | 0x600000;
  68. /* auto load, start Timer 4 */
  69. timers->TCON = (timers->TCON & ~0x0700000) | 0x500000;
  70. timestamp = 0;
  71. return (0);
  72. }
  73. /*
  74. * timer without interrupts
  75. */
  76. void reset_timer (void)
  77. {
  78. reset_timer_masked ();
  79. }
  80. ulong get_timer (ulong base)
  81. {
  82. return get_timer_masked () - base;
  83. }
  84. void set_timer (ulong t)
  85. {
  86. timestamp = t;
  87. }
  88. void udelay (unsigned long usec)
  89. {
  90. ulong tmo;
  91. ulong start = get_timer(0);
  92. tmo = usec / 1000;
  93. tmo *= (timer_load_val * 100);
  94. tmo /= 1000;
  95. while ((ulong)(get_timer_masked () - start) < tmo)
  96. /*NOP*/;
  97. }
  98. void reset_timer_masked (void)
  99. {
  100. /* reset time */
  101. lastdec = READ_TIMER();
  102. timestamp = 0;
  103. }
  104. ulong get_timer_masked (void)
  105. {
  106. ulong now = READ_TIMER();
  107. if (lastdec >= now) {
  108. /* normal mode */
  109. timestamp += lastdec - now;
  110. } else {
  111. /* we have an overflow ... */
  112. timestamp += lastdec + timer_load_val - now;
  113. }
  114. lastdec = now;
  115. return timestamp;
  116. }
  117. void udelay_masked (unsigned long usec)
  118. {
  119. ulong tmo;
  120. tmo = usec / 1000;
  121. tmo *= (timer_load_val * 100);
  122. tmo /= 1000;
  123. reset_timer_masked ();
  124. while (get_timer_masked () < tmo)
  125. /*NOP*/;
  126. }
  127. /*
  128. * This function is derived from PowerPC code (read timebase as long long).
  129. * On ARM it just returns the timer value.
  130. */
  131. unsigned long long get_ticks(void)
  132. {
  133. return get_timer(0);
  134. }
  135. /*
  136. * This function is derived from PowerPC code (timebase clock frequency).
  137. * On ARM it returns the number of timer ticks per second.
  138. */
  139. ulong get_tbclk (void)
  140. {
  141. ulong tbclk;
  142. #if defined(CONFIG_SMDK2400) || defined(CONFIG_TRAB)
  143. tbclk = timer_load_val * 100;
  144. #elif defined(CONFIG_SMDK2410) || defined(CONFIG_VCMA9)
  145. tbclk = CFG_HZ;
  146. #else
  147. # error "tbclk not configured"
  148. #endif
  149. return tbclk;
  150. }
  151. #endif /* defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) || defined (CONFIG_TRAB) */