interrupts.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_ARMADILLO)
  127. /* disable all interrupts */
  128. IO_INTMR1 = 0;
  129. /* operate timer 1 in prescale mode */
  130. IO_SYSCON1 |= SYSCON1_TC1M;
  131. /* select 2kHz clock source for timer 1 */
  132. IO_SYSCON1 &= ~SYSCON1_TC1S;
  133. /* set timer 1 counter */
  134. lastdec = IO_TC1D = TIMER_LOAD_VAL;
  135. #elif defined(CONFIG_S3C4510B)
  136. /* configure free running timer 0 */
  137. PUT_REG( REG_TMOD, 0x0);
  138. /* Stop timer 0 */
  139. CLR_REG( REG_TMOD, TM0_RUN);
  140. /* Configure for interval mode */
  141. CLR_REG( REG_TMOD, TM1_TOGGLE);
  142. /*
  143. * Load Timer data register with count down value.
  144. * count_down_val = CONFIG_SYS_SYS_CLK_FREQ/CONFIG_SYS_HZ
  145. */
  146. PUT_REG( REG_TDATA0, (CONFIG_SYS_SYS_CLK_FREQ / CONFIG_SYS_HZ));
  147. /*
  148. * Enable global interrupt
  149. * Enable timer0 interrupt
  150. */
  151. CLR_REG( REG_INTMASK, ((1<<INT_GLOBAL) | (1<<INT_TIMER0)));
  152. /* Start timer */
  153. SET_REG( REG_TMOD, TM0_RUN);
  154. #elif defined(CONFIG_LPC2292)
  155. PUT32(T0IR, 0); /* disable all timer0 interrupts */
  156. PUT32(T0TCR, 0); /* disable timer0 */
  157. PUT32(T0PR, CONFIG_SYS_SYS_CLK_FREQ / CONFIG_SYS_HZ);
  158. PUT32(T0MCR, 0);
  159. PUT32(T0TC, 0);
  160. PUT32(T0TCR, 1); /* enable timer0 */
  161. #else
  162. #error No timer_init() defined for this CPU type
  163. #endif
  164. timestamp = 0;
  165. return (0);
  166. }
  167. #endif /* ! IntegratorAP */
  168. /*
  169. * timer without interrupts
  170. */
  171. #if defined(CONFIG_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_NETARM) || defined(CONFIG_ARMADILLO) || defined(CONFIG_LPC2292)
  172. void reset_timer (void)
  173. {
  174. reset_timer_masked ();
  175. }
  176. ulong get_timer (ulong base)
  177. {
  178. return get_timer_masked () - base;
  179. }
  180. void set_timer (ulong t)
  181. {
  182. timestamp = t;
  183. }
  184. void udelay (unsigned long usec)
  185. {
  186. ulong tmo;
  187. tmo = usec / 1000;
  188. tmo *= CONFIG_SYS_HZ;
  189. tmo /= 1000;
  190. tmo += get_timer (0);
  191. while (get_timer_masked () < tmo)
  192. #ifdef CONFIG_LPC2292
  193. /* GJ - not sure whether this is really needed or a misunderstanding */
  194. __asm__ __volatile__(" nop");
  195. #else
  196. /*NOP*/;
  197. #endif
  198. }
  199. void reset_timer_masked (void)
  200. {
  201. /* reset time */
  202. lastdec = READ_TIMER;
  203. timestamp = 0;
  204. }
  205. ulong get_timer_masked (void)
  206. {
  207. ulong now = READ_TIMER;
  208. if (lastdec >= now) {
  209. /* normal mode */
  210. timestamp += lastdec - now;
  211. } else {
  212. /* we have an overflow ... */
  213. timestamp += lastdec + TIMER_LOAD_VAL - now;
  214. }
  215. lastdec = now;
  216. return timestamp;
  217. }
  218. void udelay_masked (unsigned long usec)
  219. {
  220. ulong tmo;
  221. ulong endtime;
  222. signed long diff;
  223. if (usec >= 1000) {
  224. tmo = usec / 1000;
  225. tmo *= CONFIG_SYS_HZ;
  226. tmo /= 1000;
  227. } else {
  228. tmo = usec * CONFIG_SYS_HZ;
  229. tmo /= (1000*1000);
  230. }
  231. endtime = get_timer_masked () + tmo;
  232. do {
  233. ulong now = get_timer_masked ();
  234. diff = endtime - now;
  235. } while (diff >= 0);
  236. }
  237. #elif defined(CONFIG_S3C4510B)
  238. ulong get_timer (ulong base)
  239. {
  240. return timestamp - base;
  241. }
  242. void udelay (unsigned long usec)
  243. {
  244. u32 ticks;
  245. ticks = (usec * CONFIG_SYS_HZ) / 1000000;
  246. ticks += get_timer (0);
  247. while (get_timer (0) < ticks)
  248. /*NOP*/;
  249. }
  250. #elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
  251. /* No timer routines for IntegratorAP/CM720T as yet */
  252. #else
  253. #error Timer routines not defined for this CPU type
  254. #endif