interrupts.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. int timer_load_val = 0;
  40. /* macro to read the 16 bit timer */
  41. static inline ulong READ_TIMER(void)
  42. {
  43. S3C24X0_TIMERS * const timers = S3C24X0_GetBase_TIMERS();
  44. return (timers->TCNTO4 & 0xffff);
  45. }
  46. static ulong timestamp;
  47. static ulong lastdec;
  48. int interrupt_init (void)
  49. {
  50. S3C24X0_TIMERS * const timers = S3C24X0_GetBase_TIMERS();
  51. /* use PWM Timer 4 because it has no output */
  52. /* prescaler for Timer 4 is 16 */
  53. timers->TCFG0 = 0x0f00;
  54. if (timer_load_val == 0)
  55. {
  56. /*
  57. * for 10 ms clock period @ PCLK with 4 bit divider = 1/2
  58. * (default) and prescaler = 16. Should be 10390
  59. * @33.25MHz and 15625 @ 50 MHz
  60. */
  61. timer_load_val = get_PCLK()/(2 * 16 * 100);
  62. }
  63. /* load value for 10 ms timeout */
  64. lastdec = timers->TCNTB4 = timer_load_val;
  65. /* auto load, manual update of Timer 4 */
  66. timers->TCON = (timers->TCON & ~0x0700000) | 0x600000;
  67. /* auto load, start Timer 4 */
  68. timers->TCON = (timers->TCON & ~0x0700000) | 0x500000;
  69. timestamp = 0;
  70. return (0);
  71. }
  72. /*
  73. * timer without interrupts
  74. */
  75. void reset_timer (void)
  76. {
  77. reset_timer_masked ();
  78. }
  79. ulong get_timer (ulong base)
  80. {
  81. return get_timer_masked () - base;
  82. }
  83. void set_timer (ulong t)
  84. {
  85. timestamp = t;
  86. }
  87. void udelay (unsigned long usec)
  88. {
  89. ulong tmo;
  90. ulong start = get_timer(0);
  91. tmo = usec / 1000;
  92. tmo *= (timer_load_val * 100);
  93. tmo /= 1000;
  94. while ((ulong)(get_timer_masked () - start) < tmo)
  95. /*NOP*/;
  96. }
  97. void reset_timer_masked (void)
  98. {
  99. /* reset time */
  100. lastdec = READ_TIMER();
  101. timestamp = 0;
  102. }
  103. ulong get_timer_masked (void)
  104. {
  105. ulong now = READ_TIMER();
  106. if (lastdec >= now) {
  107. /* normal mode */
  108. timestamp += lastdec - now;
  109. } else {
  110. /* we have an overflow ... */
  111. timestamp += lastdec + timer_load_val - now;
  112. }
  113. lastdec = now;
  114. return timestamp;
  115. }
  116. void udelay_masked (unsigned long usec)
  117. {
  118. ulong tmo;
  119. ulong endtime;
  120. signed long diff;
  121. if (usec >= 1000) {
  122. tmo = usec / 1000;
  123. tmo *= (timer_load_val * 100);
  124. tmo /= 1000;
  125. } else {
  126. tmo = usec * (timer_load_val * 100);
  127. tmo /= (1000*1000);
  128. }
  129. endtime = get_timer_masked () + tmo;
  130. do {
  131. ulong now = get_timer_masked ();
  132. diff = endtime - now;
  133. } while (diff >= 0);
  134. }
  135. /*
  136. * This function is derived from PowerPC code (read timebase as long long).
  137. * On ARM it just returns the timer value.
  138. */
  139. unsigned long long get_ticks(void)
  140. {
  141. return get_timer(0);
  142. }
  143. /*
  144. * This function is derived from PowerPC code (timebase clock frequency).
  145. * On ARM it returns the number of timer ticks per second.
  146. */
  147. ulong get_tbclk (void)
  148. {
  149. ulong tbclk;
  150. #if defined(CONFIG_SMDK2400) || defined(CONFIG_TRAB)
  151. tbclk = timer_load_val * 100;
  152. #elif defined(CONFIG_SMDK2410) || defined(CONFIG_VCMA9)
  153. tbclk = CFG_HZ;
  154. #else
  155. # error "tbclk not configured"
  156. #endif
  157. return tbclk;
  158. }
  159. /*
  160. * reset the cpu by setting up the watchdog timer and let him time out
  161. */
  162. void reset_cpu (ulong ignored)
  163. {
  164. volatile S3C24X0_WATCHDOG * watchdog;
  165. #ifdef CONFIG_TRAB
  166. extern void disable_vfd (void);
  167. disable_vfd();
  168. #endif
  169. watchdog = S3C24X0_GetBase_WATCHDOG();
  170. /* Disable watchdog */
  171. watchdog->WTCON = 0x0000;
  172. /* Initialize watchdog timer count register */
  173. watchdog->WTCNT = 0x0001;
  174. /* Enable watchdog timer; assert reset at timer timeout */
  175. watchdog->WTCON = 0x0021;
  176. while(1); /* loop forever and wait for reset to happen */
  177. /*NOTREACHED*/
  178. }
  179. #endif /* defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) || defined (CONFIG_TRAB) */