interrupts.c 6.6 KB

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