interrupts.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 <common.h>
  29. #include <clps7111.h>
  30. #include <asm/proc-armv/ptrace.h>
  31. #include <asm/hardware.h>
  32. #ifndef CONFIG_NETARM
  33. /* we always count down the max. */
  34. #define TIMER_LOAD_VAL 0xffff
  35. /* macro to read the 16 bit timer */
  36. #define READ_TIMER (IO_TC1D & 0xffff)
  37. #ifdef CONFIG_LPC2292
  38. #undef READ_TIMER
  39. #define READ_TIMER (0xFFFFFFFF - GET32(T0TC))
  40. #endif
  41. #else
  42. #define IRQEN (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_INTR_ENABLE))
  43. #define TM2CTRL (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_TIMER2_CONTROL))
  44. #define TM2STAT (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_TIMER2_STATUS))
  45. #define TIMER_LOAD_VAL NETARM_GEN_TSTAT_CTC_MASK
  46. #define READ_TIMER (TM2STAT & NETARM_GEN_TSTAT_CTC_MASK)
  47. #endif
  48. #ifdef CONFIG_S3C4510B
  49. /* require interrupts for the S3C4510B */
  50. # ifndef CONFIG_USE_IRQ
  51. # error CONFIG_USE_IRQ _must_ be defined when using CONFIG_S3C4510B
  52. # else
  53. static struct _irq_handler IRQ_HANDLER[N_IRQS];
  54. # endif
  55. #endif /* CONFIG_S3C4510B */
  56. #ifdef CONFIG_USE_IRQ
  57. void do_irq (struct pt_regs *pt_regs)
  58. {
  59. #if defined(CONFIG_S3C4510B)
  60. unsigned int pending;
  61. while ( (pending = GET_REG( REG_INTOFFSET)) != 0x54) { /* sentinal value for no pending interrutps */
  62. IRQ_HANDLER[pending>>2].m_func( IRQ_HANDLER[pending>>2].m_data);
  63. /* clear pending interrupt */
  64. PUT_REG( REG_INTPEND, (1<<(pending>>2)));
  65. }
  66. #elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
  67. /* No do_irq() for IntegratorAP/CM720T as yet */
  68. #elif defined(CONFIG_LPC2292)
  69. void (*pfnct)(void);
  70. pfnct = (void (*)(void))VICVectAddr;
  71. (*pfnct)();
  72. #else
  73. #error do_irq() not defined for this CPU type
  74. #endif
  75. }
  76. #endif
  77. #ifdef CONFIG_S3C4510B
  78. static void default_isr( void *data) {
  79. printf ("default_isr(): called for IRQ %d\n", (int)data);
  80. }
  81. static void timer_isr( void *data) {
  82. unsigned int *pTime = (unsigned int *)data;
  83. (*pTime)++;
  84. if ( !(*pTime % (CONFIG_SYS_HZ/4))) {
  85. /* toggle LED 0 */
  86. PUT_REG( REG_IOPDATA, GET_REG(REG_IOPDATA) ^ 0x1);
  87. }
  88. }
  89. #endif
  90. #if defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
  91. /* Use IntegratorAP routines in board/integratorap.c */
  92. #else
  93. static ulong timestamp;
  94. static ulong lastdec;
  95. #if defined(CONFIG_USE_IRQ) && defined(CONFIG_S3C4510B)
  96. int arch_interrupt_init (void)
  97. {
  98. int i;
  99. /* install default interrupt handlers */
  100. for ( i = 0; i < N_IRQS; i++) {
  101. IRQ_HANDLER[i].m_data = (void *)i;
  102. IRQ_HANDLER[i].m_func = default_isr;
  103. }
  104. /* configure interrupts for IRQ mode */
  105. PUT_REG( REG_INTMODE, 0x0);
  106. /* clear any pending interrupts */
  107. PUT_REG( REG_INTPEND, 0x1FFFFF);
  108. lastdec = 0;
  109. /* install interrupt handler for timer */
  110. IRQ_HANDLER[INT_TIMER0].m_data = (void *)&timestamp;
  111. IRQ_HANDLER[INT_TIMER0].m_func = timer_isr;
  112. return 0;
  113. }
  114. #endif
  115. int timer_init (void)
  116. {
  117. #if defined(CONFIG_NETARM)
  118. /* disable all interrupts */
  119. IRQEN = 0;
  120. /* operate timer 2 in non-prescale mode */
  121. TM2CTRL = ( NETARM_GEN_TIMER_SET_HZ(CONFIG_SYS_HZ) |
  122. NETARM_GEN_TCTL_ENABLE |
  123. NETARM_GEN_TCTL_INIT_COUNT(TIMER_LOAD_VAL));
  124. /* set timer 2 counter */
  125. lastdec = TIMER_LOAD_VAL;
  126. #elif defined(CONFIG_S3C4510B)
  127. /* configure free running timer 0 */
  128. PUT_REG( REG_TMOD, 0x0);
  129. /* Stop timer 0 */
  130. CLR_REG( REG_TMOD, TM0_RUN);
  131. /* Configure for interval mode */
  132. CLR_REG( REG_TMOD, TM1_TOGGLE);
  133. /*
  134. * Load Timer data register with count down value.
  135. * count_down_val = CONFIG_SYS_SYS_CLK_FREQ/CONFIG_SYS_HZ
  136. */
  137. PUT_REG( REG_TDATA0, (CONFIG_SYS_SYS_CLK_FREQ / CONFIG_SYS_HZ));
  138. /*
  139. * Enable global interrupt
  140. * Enable timer0 interrupt
  141. */
  142. CLR_REG( REG_INTMASK, ((1<<INT_GLOBAL) | (1<<INT_TIMER0)));
  143. /* Start timer */
  144. SET_REG( REG_TMOD, TM0_RUN);
  145. #elif defined(CONFIG_LPC2292)
  146. PUT32(T0IR, 0); /* disable all timer0 interrupts */
  147. PUT32(T0TCR, 0); /* disable timer0 */
  148. PUT32(T0PR, CONFIG_SYS_SYS_CLK_FREQ / CONFIG_SYS_HZ);
  149. PUT32(T0MCR, 0);
  150. PUT32(T0TC, 0);
  151. PUT32(T0TCR, 1); /* enable timer0 */
  152. #elif defined(CONFIG_TEGRA)
  153. /* No timer routines for tegra as yet */
  154. lastdec = 0;
  155. #else
  156. #error No timer_init() defined for this CPU type
  157. #endif
  158. timestamp = 0;
  159. return (0);
  160. }
  161. #endif /* ! IntegratorAP */
  162. /*
  163. * timer without interrupts
  164. */
  165. #if defined(CONFIG_NETARM) || defined(CONFIG_LPC2292)
  166. ulong get_timer (ulong base)
  167. {
  168. return get_timer_masked () - base;
  169. }
  170. void __udelay (unsigned long usec)
  171. {
  172. ulong tmo;
  173. tmo = usec / 1000;
  174. tmo *= CONFIG_SYS_HZ;
  175. tmo /= 1000;
  176. tmo += get_timer (0);
  177. while (get_timer_masked () < tmo)
  178. #ifdef CONFIG_LPC2292
  179. /* GJ - not sure whether this is really needed or a misunderstanding */
  180. __asm__ __volatile__(" nop");
  181. #else
  182. /*NOP*/;
  183. #endif
  184. }
  185. ulong get_timer_masked (void)
  186. {
  187. ulong now = READ_TIMER;
  188. if (lastdec >= now) {
  189. /* normal mode */
  190. timestamp += lastdec - now;
  191. } else {
  192. /* we have an overflow ... */
  193. timestamp += lastdec + TIMER_LOAD_VAL - now;
  194. }
  195. lastdec = now;
  196. return timestamp;
  197. }
  198. void udelay_masked (unsigned long usec)
  199. {
  200. ulong tmo;
  201. ulong endtime;
  202. signed long diff;
  203. if (usec >= 1000) {
  204. tmo = usec / 1000;
  205. tmo *= CONFIG_SYS_HZ;
  206. tmo /= 1000;
  207. } else {
  208. tmo = usec * CONFIG_SYS_HZ;
  209. tmo /= (1000*1000);
  210. }
  211. endtime = get_timer_masked () + tmo;
  212. do {
  213. ulong now = get_timer_masked ();
  214. diff = endtime - now;
  215. } while (diff >= 0);
  216. }
  217. #elif defined(CONFIG_S3C4510B)
  218. ulong get_timer (ulong base)
  219. {
  220. return timestamp - base;
  221. }
  222. void __udelay (unsigned long usec)
  223. {
  224. u32 ticks;
  225. ticks = (usec * CONFIG_SYS_HZ) / 1000000;
  226. ticks += get_timer (0);
  227. while (get_timer (0) < ticks)
  228. /*NOP*/;
  229. }
  230. #elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
  231. /* No timer routines for IntegratorAP/CM720T as yet */
  232. #elif defined(CONFIG_TEGRA)
  233. /* No timer routines for tegra as yet */
  234. #else
  235. #error Timer routines not defined for this CPU type
  236. #endif