interrupts.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * (C) Copyright 2000-2002 Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  3. * (C) Copyright 2003 Martin Winistoerfer, martinwinistoerfer@gmx.ch.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * File: interrupt.c
  9. *
  10. * Discription: Contains interrupt routines needed by U-Boot
  11. *
  12. */
  13. #include <common.h>
  14. #include <command.h>
  15. #include <mpc5xx.h>
  16. #include <asm/processor.h>
  17. #if defined(CONFIG_PATI)
  18. /* PATI uses IRQs for PCI doorbell */
  19. #undef NR_IRQS
  20. #define NR_IRQS 16
  21. #endif
  22. struct interrupt_action {
  23. interrupt_handler_t *handler;
  24. void *arg;
  25. int count;
  26. };
  27. static struct interrupt_action irq_vecs[NR_IRQS];
  28. /*
  29. * Initialise interrupts
  30. */
  31. int interrupt_init_cpu (ulong *decrementer_count)
  32. {
  33. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  34. int vec;
  35. /* Decrementer used here for status led */
  36. *decrementer_count = get_tbclk () / CONFIG_SYS_HZ;
  37. /* Disable all interrupts */
  38. immr->im_siu_conf.sc_simask = 0;
  39. for (vec=0; vec<NR_IRQS; vec++) {
  40. irq_vecs[vec].handler = NULL;
  41. irq_vecs[vec].arg = NULL;
  42. irq_vecs[vec].count = 0;
  43. }
  44. return (0);
  45. }
  46. /*
  47. * Handle external interrupts
  48. */
  49. void external_interrupt (struct pt_regs *regs)
  50. {
  51. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  52. int irq;
  53. ulong simask, newmask;
  54. ulong vec, v_bit;
  55. /*
  56. * read the SIVEC register and shift the bits down
  57. * to get the irq number
  58. */
  59. vec = immr->im_siu_conf.sc_sivec;
  60. irq = vec >> 26;
  61. v_bit = 0x80000000UL >> irq;
  62. /*
  63. * Read Interrupt Mask Register and Mask Interrupts
  64. */
  65. simask = immr->im_siu_conf.sc_simask;
  66. newmask = simask & (~(0xFFFF0000 >> irq));
  67. immr->im_siu_conf.sc_simask = newmask;
  68. if (!(irq & 0x1)) { /* External Interrupt ? */
  69. ulong siel;
  70. /*
  71. * Read Interrupt Edge/Level Register
  72. */
  73. siel = immr->im_siu_conf.sc_siel;
  74. if (siel & v_bit) { /* edge triggered interrupt ? */
  75. /*
  76. * Rewrite SIPEND Register to clear interrupt
  77. */
  78. immr->im_siu_conf.sc_sipend = v_bit;
  79. }
  80. }
  81. if (irq_vecs[irq].handler != NULL) {
  82. irq_vecs[irq].handler (irq_vecs[irq].arg);
  83. } else {
  84. printf ("\nBogus External Interrupt IRQ %d Vector %ld\n",
  85. irq, vec);
  86. /* turn off the bogus interrupt to avoid it from now */
  87. simask &= ~v_bit;
  88. }
  89. /*
  90. * Re-Enable old Interrupt Mask
  91. */
  92. immr->im_siu_conf.sc_simask = simask;
  93. }
  94. /*
  95. * Install and free an interrupt handler
  96. */
  97. void irq_install_handler (int vec, interrupt_handler_t * handler,
  98. void *arg)
  99. {
  100. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  101. /* SIU interrupt */
  102. if (irq_vecs[vec].handler != NULL) {
  103. printf ("SIU interrupt %d 0x%x\n",
  104. vec,
  105. (uint) handler);
  106. }
  107. irq_vecs[vec].handler = handler;
  108. irq_vecs[vec].arg = arg;
  109. immr->im_siu_conf.sc_simask |= 1 << (31 - vec);
  110. #if 0
  111. printf ("Install SIU interrupt for vector %d ==> %p\n",
  112. vec, handler);
  113. #endif
  114. }
  115. void irq_free_handler (int vec)
  116. {
  117. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  118. /* SIU interrupt */
  119. #if 0
  120. printf ("Free CPM interrupt for vector %d\n",
  121. vec);
  122. #endif
  123. immr->im_siu_conf.sc_simask &= ~(1 << (31 - vec));
  124. irq_vecs[vec].handler = NULL;
  125. irq_vecs[vec].arg = NULL;
  126. }
  127. /*
  128. * Timer interrupt - gets called when bit 0 of DEC changes from
  129. * 0. Decrementer is enabled with bit TBE in TBSCR.
  130. */
  131. void timer_interrupt_cpu (struct pt_regs *regs)
  132. {
  133. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  134. #if 0
  135. printf ("*** Timer Interrupt *** ");
  136. #endif
  137. /* Reset Timer Status Bit and Timers Interrupt Status */
  138. immr->im_clkrstk.cark_plprcrk = KAPWR_KEY;
  139. __asm__ ("nop");
  140. immr->im_clkrst.car_plprcr |= PLPRCR_TEXPS | PLPRCR_TMIST;
  141. return;
  142. }
  143. #if defined(CONFIG_CMD_IRQ)
  144. /*******************************************************************************
  145. *
  146. * irqinfo - print information about IRQs
  147. *
  148. */
  149. int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  150. {
  151. int vec;
  152. printf ("\nInterrupt-Information:\n");
  153. printf ("Nr Routine Arg Count\n");
  154. for (vec=0; vec<NR_IRQS; vec++) {
  155. if (irq_vecs[vec].handler != NULL) {
  156. printf ("%02d %08lx %08lx %d\n",
  157. vec,
  158. (ulong)irq_vecs[vec].handler,
  159. (ulong)irq_vecs[vec].arg,
  160. irq_vecs[vec].count);
  161. }
  162. }
  163. return 0;
  164. }
  165. #endif