interrupts.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. int interrupt_init (void)
  96. {
  97. #if defined(CONFIG_NETARM)
  98. /* disable all interrupts */
  99. IRQEN = 0;
  100. /* operate timer 2 in non-prescale mode */
  101. TM2CTRL = ( NETARM_GEN_TIMER_SET_HZ(CONFIG_SYS_HZ) |
  102. NETARM_GEN_TCTL_ENABLE |
  103. NETARM_GEN_TCTL_INIT_COUNT(TIMER_LOAD_VAL));
  104. /* set timer 2 counter */
  105. lastdec = TIMER_LOAD_VAL;
  106. #elif defined(CONFIG_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_ARMADILLO)
  107. /* disable all interrupts */
  108. IO_INTMR1 = 0;
  109. /* operate timer 1 in prescale mode */
  110. IO_SYSCON1 |= SYSCON1_TC1M;
  111. /* select 2kHz clock source for timer 1 */
  112. IO_SYSCON1 &= ~SYSCON1_TC1S;
  113. /* set timer 1 counter */
  114. lastdec = IO_TC1D = TIMER_LOAD_VAL;
  115. #elif defined(CONFIG_S3C4510B)
  116. int i;
  117. /* install default interrupt handlers */
  118. for ( i = 0; i < N_IRQS; i++) {
  119. IRQ_HANDLER[i].m_data = (void *)i;
  120. IRQ_HANDLER[i].m_func = default_isr;
  121. }
  122. /* configure interrupts for IRQ mode */
  123. PUT_REG( REG_INTMODE, 0x0);
  124. /* clear any pending interrupts */
  125. PUT_REG( REG_INTPEND, 0x1FFFFF);
  126. lastdec = 0;
  127. /* install interrupt handler for timer */
  128. IRQ_HANDLER[INT_TIMER0].m_data = (void *)&timestamp;
  129. IRQ_HANDLER[INT_TIMER0].m_func = timer_isr;
  130. /* configure free running timer 0 */
  131. PUT_REG( REG_TMOD, 0x0);
  132. /* Stop timer 0 */
  133. CLR_REG( REG_TMOD, TM0_RUN);
  134. /* Configure for interval mode */
  135. CLR_REG( REG_TMOD, TM1_TOGGLE);
  136. /*
  137. * Load Timer data register with count down value.
  138. * count_down_val = CONFIG_SYS_SYS_CLK_FREQ/CONFIG_SYS_HZ
  139. */
  140. PUT_REG( REG_TDATA0, (CONFIG_SYS_SYS_CLK_FREQ / CONFIG_SYS_HZ));
  141. /*
  142. * Enable global interrupt
  143. * Enable timer0 interrupt
  144. */
  145. CLR_REG( REG_INTMASK, ((1<<INT_GLOBAL) | (1<<INT_TIMER0)));
  146. /* Start timer */
  147. SET_REG( REG_TMOD, TM0_RUN);
  148. #elif defined(CONFIG_LPC2292)
  149. PUT32(T0IR, 0); /* disable all timer0 interrupts */
  150. PUT32(T0TCR, 0); /* disable timer0 */
  151. PUT32(T0PR, CONFIG_SYS_SYS_CLK_FREQ / CONFIG_SYS_HZ);
  152. PUT32(T0MCR, 0);
  153. PUT32(T0TC, 0);
  154. PUT32(T0TCR, 1); /* enable timer0 */
  155. #else
  156. #error No interrupt_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_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_NETARM) || defined(CONFIG_ARMADILLO) || defined(CONFIG_LPC2292)
  166. void reset_timer (void)
  167. {
  168. reset_timer_masked ();
  169. }
  170. ulong get_timer (ulong base)
  171. {
  172. return get_timer_masked () - base;
  173. }
  174. void set_timer (ulong t)
  175. {
  176. timestamp = t;
  177. }
  178. void udelay (unsigned long usec)
  179. {
  180. ulong tmo;
  181. tmo = usec / 1000;
  182. tmo *= CONFIG_SYS_HZ;
  183. tmo /= 1000;
  184. tmo += get_timer (0);
  185. while (get_timer_masked () < tmo)
  186. #ifdef CONFIG_LPC2292
  187. /* GJ - not sure whether this is really needed or a misunderstanding */
  188. __asm__ __volatile__(" nop");
  189. #else
  190. /*NOP*/;
  191. #endif
  192. }
  193. void reset_timer_masked (void)
  194. {
  195. /* reset time */
  196. lastdec = READ_TIMER;
  197. timestamp = 0;
  198. }
  199. ulong get_timer_masked (void)
  200. {
  201. ulong now = READ_TIMER;
  202. if (lastdec >= now) {
  203. /* normal mode */
  204. timestamp += lastdec - now;
  205. } else {
  206. /* we have an overflow ... */
  207. timestamp += lastdec + TIMER_LOAD_VAL - now;
  208. }
  209. lastdec = now;
  210. return timestamp;
  211. }
  212. void udelay_masked (unsigned long usec)
  213. {
  214. ulong tmo;
  215. ulong endtime;
  216. signed long diff;
  217. if (usec >= 1000) {
  218. tmo = usec / 1000;
  219. tmo *= CONFIG_SYS_HZ;
  220. tmo /= 1000;
  221. } else {
  222. tmo = usec * CONFIG_SYS_HZ;
  223. tmo /= (1000*1000);
  224. }
  225. endtime = get_timer_masked () + tmo;
  226. do {
  227. ulong now = get_timer_masked ();
  228. diff = endtime - now;
  229. } while (diff >= 0);
  230. }
  231. #elif defined(CONFIG_S3C4510B)
  232. ulong get_timer (ulong base)
  233. {
  234. return timestamp - base;
  235. }
  236. void udelay (unsigned long usec)
  237. {
  238. u32 ticks;
  239. ticks = (usec * CONFIG_SYS_HZ) / 1000000;
  240. ticks += get_timer (0);
  241. while (get_timer (0) < ticks)
  242. /*NOP*/;
  243. }
  244. #elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
  245. /* No timer routines for IntegratorAP/CM720T as yet */
  246. #else
  247. #error Timer routines not defined for this CPU type
  248. #endif