interrupts.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * (C) Copyright 2000-2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <mpc8xx.h>
  25. #include <mpc8xx_irq.h>
  26. #include <asm/processor.h>
  27. #include <commproc.h>
  28. /************************************************************************/
  29. /*
  30. * CPM interrupt vector functions.
  31. */
  32. struct interrupt_action {
  33. interrupt_handler_t *handler;
  34. void *arg;
  35. };
  36. static struct interrupt_action cpm_vecs[CPMVEC_NR];
  37. static struct interrupt_action irq_vecs[NR_IRQS];
  38. static void cpm_interrupt_init (void);
  39. static void cpm_interrupt (void *regs);
  40. /************************************************************************/
  41. int interrupt_init_cpu (unsigned *decrementer_count)
  42. {
  43. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  44. *decrementer_count = get_tbclk () / CONFIG_SYS_HZ;
  45. /* disable all interrupts */
  46. immr->im_siu_conf.sc_simask = 0;
  47. /* Configure CPM interrupts */
  48. cpm_interrupt_init ();
  49. return (0);
  50. }
  51. /************************************************************************/
  52. /*
  53. * Handle external interrupts
  54. */
  55. void external_interrupt (struct pt_regs *regs)
  56. {
  57. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  58. int irq;
  59. ulong simask, newmask;
  60. ulong vec, v_bit;
  61. /*
  62. * read the SIVEC register and shift the bits down
  63. * to get the irq number
  64. */
  65. vec = immr->im_siu_conf.sc_sivec;
  66. irq = vec >> 26;
  67. v_bit = 0x80000000UL >> irq;
  68. /*
  69. * Read Interrupt Mask Register and Mask Interrupts
  70. */
  71. simask = immr->im_siu_conf.sc_simask;
  72. newmask = simask & (~(0xFFFF0000 >> irq));
  73. immr->im_siu_conf.sc_simask = newmask;
  74. if (!(irq & 0x1)) { /* External Interrupt ? */
  75. ulong siel;
  76. /*
  77. * Read Interrupt Edge/Level Register
  78. */
  79. siel = immr->im_siu_conf.sc_siel;
  80. if (siel & v_bit) { /* edge triggered interrupt ? */
  81. /*
  82. * Rewrite SIPEND Register to clear interrupt
  83. */
  84. immr->im_siu_conf.sc_sipend = v_bit;
  85. }
  86. }
  87. if (irq_vecs[irq].handler != NULL) {
  88. irq_vecs[irq].handler (irq_vecs[irq].arg);
  89. } else {
  90. printf ("\nBogus External Interrupt IRQ %d Vector %ld\n",
  91. irq, vec);
  92. /* turn off the bogus interrupt to avoid it from now */
  93. simask &= ~v_bit;
  94. }
  95. /*
  96. * Re-Enable old Interrupt Mask
  97. */
  98. immr->im_siu_conf.sc_simask = simask;
  99. }
  100. /************************************************************************/
  101. /*
  102. * CPM interrupt handler
  103. */
  104. static void cpm_interrupt (void *regs)
  105. {
  106. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  107. uint vec;
  108. /*
  109. * Get the vector by setting the ACK bit
  110. * and then reading the register.
  111. */
  112. immr->im_cpic.cpic_civr = 1;
  113. vec = immr->im_cpic.cpic_civr;
  114. vec >>= 11;
  115. if (cpm_vecs[vec].handler != NULL) {
  116. (*cpm_vecs[vec].handler) (cpm_vecs[vec].arg);
  117. } else {
  118. immr->im_cpic.cpic_cimr &= ~(1 << vec);
  119. printf ("Masking bogus CPM interrupt vector 0x%x\n", vec);
  120. }
  121. /*
  122. * After servicing the interrupt,
  123. * we have to remove the status indicator.
  124. */
  125. immr->im_cpic.cpic_cisr |= (1 << vec);
  126. }
  127. /*
  128. * The CPM can generate the error interrupt when there is a race
  129. * condition between generating and masking interrupts. All we have
  130. * to do is ACK it and return. This is a no-op function so we don't
  131. * need any special tests in the interrupt handler.
  132. */
  133. static void cpm_error_interrupt (void *dummy)
  134. {
  135. }
  136. /************************************************************************/
  137. /*
  138. * Install and free an interrupt handler
  139. */
  140. void irq_install_handler (int vec, interrupt_handler_t * handler,
  141. void *arg)
  142. {
  143. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  144. if ((vec & CPMVEC_OFFSET) != 0) {
  145. /* CPM interrupt */
  146. vec &= 0xffff;
  147. if (cpm_vecs[vec].handler != NULL) {
  148. printf ("CPM interrupt 0x%x replacing 0x%x\n",
  149. (uint) handler,
  150. (uint) cpm_vecs[vec].handler);
  151. }
  152. cpm_vecs[vec].handler = handler;
  153. cpm_vecs[vec].arg = arg;
  154. immr->im_cpic.cpic_cimr |= (1 << vec);
  155. #if 0
  156. printf ("Install CPM interrupt for vector %d ==> %p\n",
  157. vec, handler);
  158. #endif
  159. } else {
  160. /* SIU interrupt */
  161. if (irq_vecs[vec].handler != NULL) {
  162. printf ("SIU interrupt %d 0x%x replacing 0x%x\n",
  163. vec,
  164. (uint) handler,
  165. (uint) cpm_vecs[vec].handler);
  166. }
  167. irq_vecs[vec].handler = handler;
  168. irq_vecs[vec].arg = arg;
  169. immr->im_siu_conf.sc_simask |= 1 << (31 - vec);
  170. #if 0
  171. printf ("Install SIU interrupt for vector %d ==> %p\n",
  172. vec, handler);
  173. #endif
  174. }
  175. }
  176. void irq_free_handler (int vec)
  177. {
  178. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  179. if ((vec & CPMVEC_OFFSET) != 0) {
  180. /* CPM interrupt */
  181. vec &= 0xffff;
  182. #if 0
  183. printf ("Free CPM interrupt for vector %d ==> %p\n",
  184. vec, cpm_vecs[vec].handler);
  185. #endif
  186. immr->im_cpic.cpic_cimr &= ~(1 << vec);
  187. cpm_vecs[vec].handler = NULL;
  188. cpm_vecs[vec].arg = NULL;
  189. } else {
  190. /* SIU interrupt */
  191. #if 0
  192. printf ("Free CPM interrupt for vector %d ==> %p\n",
  193. vec, cpm_vecs[vec].handler);
  194. #endif
  195. immr->im_siu_conf.sc_simask &= ~(1 << (31 - vec));
  196. irq_vecs[vec].handler = NULL;
  197. irq_vecs[vec].arg = NULL;
  198. }
  199. }
  200. /************************************************************************/
  201. static void cpm_interrupt_init (void)
  202. {
  203. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  204. /*
  205. * Initialize the CPM interrupt controller.
  206. */
  207. immr->im_cpic.cpic_cicr =
  208. (CICR_SCD_SCC4 |
  209. CICR_SCC_SCC3 |
  210. CICR_SCB_SCC2 |
  211. CICR_SCA_SCC1) | ((CPM_INTERRUPT / 2) << 13) | CICR_HP_MASK;
  212. immr->im_cpic.cpic_cimr = 0;
  213. /*
  214. * Install the error handler.
  215. */
  216. irq_install_handler (CPMVEC_ERROR, cpm_error_interrupt, NULL);
  217. immr->im_cpic.cpic_cicr |= CICR_IEN;
  218. /*
  219. * Install the cpm interrupt handler
  220. */
  221. irq_install_handler (CPM_INTERRUPT, cpm_interrupt, NULL);
  222. }
  223. /************************************************************************/
  224. /*
  225. * timer_interrupt - gets called when the decrementer overflows,
  226. * with interrupts disabled.
  227. * Trivial implementation - no need to be really accurate.
  228. */
  229. void timer_interrupt_cpu (struct pt_regs *regs)
  230. {
  231. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  232. #if 0
  233. printf ("*** Timer Interrupt *** ");
  234. #endif
  235. /* Reset Timer Expired and Timers Interrupt Status */
  236. immr->im_clkrstk.cark_plprcrk = KAPWR_KEY;
  237. __asm__ ("nop");
  238. /*
  239. Clear TEXPS (and TMIST on older chips). SPLSS (on older
  240. chips) is cleared too.
  241. Bitwise OR is a read-modify-write operation so ALL bits
  242. which are cleared by writing `1' would be cleared by
  243. operations like
  244. immr->im_clkrst.car_plprcr |= PLPRCR_TEXPS;
  245. The same can be achieved by simple writing of the PLPRCR
  246. to itself. If a bit value should be preserved, read the
  247. register, ZERO the bit and write, not OR, the result back.
  248. */
  249. immr->im_clkrst.car_plprcr = immr->im_clkrst.car_plprcr;
  250. }
  251. /************************************************************************/