interrupts.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * (C) Copyright 2002
  3. * Lineo, Inc. <www.lineo.com>
  4. * Bernhard Kuhn <bkuhn@lineo.com>
  5. *
  6. * (C) Copyright 2002
  7. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  8. * Marius Groeger <mgroeger@sysgo.de>
  9. *
  10. * (C) Copyright 2002
  11. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  12. * Alex Zuepke <azu@sysgo.de>
  13. *
  14. * See file CREDITS for list of people who contributed to this
  15. * project.
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License as
  19. * published by the Free Software Foundation; either version 2 of
  20. * the License, or (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  30. * MA 02111-1307 USA
  31. */
  32. #include <common.h>
  33. /*#include <asm/io.h>*/
  34. #include <asm/arch/hardware.h>
  35. /*#include <asm/proc/ptrace.h>*/
  36. /* the number of clocks per CFG_HZ */
  37. #define TIMER_LOAD_VAL (CFG_HZ_CLOCK/CFG_HZ)
  38. /* macro to read the 16 bit timer */
  39. #define READ_TIMER (tmr->TC_CV & 0x0000ffff)
  40. AT91PS_TC tmr;
  41. static ulong timestamp;
  42. static ulong lastinc;
  43. int interrupt_init (void)
  44. {
  45. tmr = AT91C_BASE_TC0;
  46. /* enables TC1.0 clock */
  47. *AT91C_PMC_PCER = 1 << AT91C_ID_TC0; /* enable clock */
  48. *AT91C_TCB0_BCR = 0;
  49. *AT91C_TCB0_BMR = AT91C_TCB_TC0XC0S_NONE | AT91C_TCB_TC1XC1S_NONE | AT91C_TCB_TC2XC2S_NONE;
  50. tmr->TC_CCR = AT91C_TC_CLKDIS;
  51. #define AT91C_TC_CMR_CPCTRG (1 << 14)
  52. /* set to MCLK/2 and restart the timer when the vlaue in TC_RC is reached */
  53. tmr->TC_CMR = AT91C_TC_TIMER_DIV1_CLOCK | AT91C_TC_CMR_CPCTRG;
  54. tmr->TC_IDR = ~0ul;
  55. tmr->TC_RC = TIMER_LOAD_VAL;
  56. lastinc = 0;
  57. tmr->TC_CCR = AT91C_TC_SWTRG | AT91C_TC_CLKEN;
  58. timestamp = 0;
  59. return (0);
  60. }
  61. /*
  62. * timer without interrupts
  63. */
  64. void reset_timer (void)
  65. {
  66. reset_timer_masked ();
  67. }
  68. ulong get_timer (ulong base)
  69. {
  70. return get_timer_masked () - base;
  71. }
  72. void set_timer (ulong t)
  73. {
  74. timestamp = t;
  75. }
  76. void udelay (unsigned long usec)
  77. {
  78. udelay_masked(usec);
  79. }
  80. void reset_timer_masked (void)
  81. {
  82. /* reset time */
  83. lastinc = READ_TIMER;
  84. timestamp = 0;
  85. }
  86. ulong get_timer_raw (void)
  87. {
  88. ulong now = READ_TIMER;
  89. if (now >= lastinc) {
  90. /* normal mode */
  91. timestamp += now - lastinc;
  92. } else {
  93. /* we have an overflow ... */
  94. timestamp += now + TIMER_LOAD_VAL - lastinc;
  95. }
  96. lastinc = now;
  97. return timestamp;
  98. }
  99. ulong get_timer_masked (void)
  100. {
  101. return get_timer_raw()/TIMER_LOAD_VAL;
  102. }
  103. void udelay_masked (unsigned long usec)
  104. {
  105. ulong tmo;
  106. ulong endtime;
  107. signed long diff;
  108. tmo = CFG_HZ_CLOCK / 1000;
  109. tmo *= usec;
  110. tmo /= 1000;
  111. endtime = get_timer_raw () + tmo;
  112. do {
  113. ulong now = get_timer_raw ();
  114. diff = endtime - now;
  115. } while (diff >= 0);
  116. }
  117. /*
  118. * This function is derived from PowerPC code (read timebase as long long).
  119. * On ARM it just returns the timer value.
  120. */
  121. unsigned long long get_ticks(void)
  122. {
  123. return get_timer(0);
  124. }
  125. /*
  126. * This function is derived from PowerPC code (timebase clock frequency).
  127. * On ARM it returns the number of timer ticks per second.
  128. */
  129. ulong get_tbclk (void)
  130. {
  131. ulong tbclk;
  132. tbclk = CFG_HZ;
  133. return tbclk;
  134. }
  135. /*
  136. * Reset the cpu by setting up the watchdog timer and let him time out
  137. * or toggle a GPIO pin on the AT91RM9200DK board
  138. */
  139. void reset_cpu (ulong ignored)
  140. {
  141. #ifdef CONFIG_DBGU
  142. AT91PS_USART us = (AT91PS_USART) AT91C_BASE_DBGU;
  143. #endif
  144. #ifdef CONFIG_USART0
  145. AT91PS_USART us = AT91C_BASE_US0;
  146. #endif
  147. #ifdef CONFIG_USART1
  148. AT91PS_USART us = AT91C_BASE_US1;
  149. #endif
  150. #ifdef CONFIG_AT91RM9200DK
  151. AT91PS_PIO pio = AT91C_BASE_PIOA;
  152. #endif
  153. /*shutdown the console to avoid strange chars during reset */
  154. us->US_CR = (AT91C_US_RSTRX | AT91C_US_RSTTX);
  155. #ifdef CONFIG_AT91RM9200DK
  156. /* Clear PA19 to trigger the hard reset */
  157. pio->PIO_CODR = 0x00080000;
  158. pio->PIO_OER = 0x00080000;
  159. pio->PIO_PER = 0x00080000;
  160. #endif
  161. /* this is the way Linux does it */
  162. /* FIXME:
  163. * These defines should be moved into
  164. * include/asm-arm/arch-at91rm9200/AT91RM9200.h
  165. * as soon as the whitespace fix gets applied.
  166. */
  167. #define AT91C_ST_RSTEN (0x1 << 16)
  168. #define AT91C_ST_EXTEN (0x1 << 17)
  169. #define AT91C_ST_WDRST (0x1 << 0)
  170. #define ST_WDMR *((unsigned long *)0xfffffd08) /* watchdog mode register */
  171. #define ST_CR *((unsigned long *)0xfffffd00) /* system clock control register */
  172. ST_WDMR = AT91C_ST_RSTEN | AT91C_ST_EXTEN | 1 ;
  173. ST_CR = AT91C_ST_WDRST;
  174. while (1);
  175. /* Never reached */
  176. }