ints-priority.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Copyright 2005-2009 Analog Devices Inc.
  3. *
  4. * Licensed under the GPL-2 or later.
  5. *
  6. * Set up the interrupt priorities
  7. */
  8. #include <linux/module.h>
  9. #include <linux/irq.h>
  10. #include <asm/blackfin.h>
  11. #include <asm/irq_handler.h>
  12. #include <asm/bfin5xx_spi.h>
  13. #include <asm/bfin_sport.h>
  14. #include <asm/bfin_can.h>
  15. #include <asm/bfin_dma.h>
  16. #include <asm/dpmc.h>
  17. void __init program_IAR(void)
  18. {
  19. /* Program the IAR0 Register with the configured priority */
  20. bfin_write_SIC_IAR0(((CONFIG_IRQ_PLL_WAKEUP - 7) << IRQ_PLL_WAKEUP_POS) |
  21. ((CONFIG_IRQ_DMA_ERROR - 7) << IRQ_DMA_ERROR_POS) |
  22. ((CONFIG_IRQ_ERROR - 7) << IRQ_ERROR_POS) |
  23. ((CONFIG_IRQ_RTC - 7) << IRQ_RTC_POS) |
  24. ((CONFIG_IRQ_PPI - 7) << IRQ_PPI_POS) |
  25. ((CONFIG_IRQ_SPORT0_RX - 7) << IRQ_SPORT0_RX_POS) |
  26. ((CONFIG_IRQ_SPORT0_TX - 7) << IRQ_SPORT0_TX_POS) |
  27. ((CONFIG_IRQ_SPORT1_RX - 7) << IRQ_SPORT1_RX_POS));
  28. bfin_write_SIC_IAR1(((CONFIG_IRQ_SPORT1_TX - 7) << IRQ_SPORT1_TX_POS) |
  29. ((CONFIG_IRQ_TWI - 7) << IRQ_TWI_POS) |
  30. ((CONFIG_IRQ_SPI - 7) << IRQ_SPI_POS) |
  31. ((CONFIG_IRQ_UART0_RX - 7) << IRQ_UART0_RX_POS) |
  32. ((CONFIG_IRQ_UART0_TX - 7) << IRQ_UART0_TX_POS) |
  33. ((CONFIG_IRQ_UART1_RX - 7) << IRQ_UART1_RX_POS) |
  34. ((CONFIG_IRQ_UART1_TX - 7) << IRQ_UART1_TX_POS) |
  35. ((CONFIG_IRQ_CAN_RX - 7) << IRQ_CAN_RX_POS));
  36. bfin_write_SIC_IAR2(((CONFIG_IRQ_CAN_TX - 7) << IRQ_CAN_TX_POS) |
  37. ((CONFIG_IRQ_MAC_RX - 7) << IRQ_MAC_RX_POS) |
  38. ((CONFIG_IRQ_MAC_TX - 7) << IRQ_MAC_TX_POS) |
  39. ((CONFIG_IRQ_TIMER0 - 7) << IRQ_TIMER0_POS) |
  40. ((CONFIG_IRQ_TIMER1 - 7) << IRQ_TIMER1_POS) |
  41. ((CONFIG_IRQ_TIMER2 - 7) << IRQ_TIMER2_POS) |
  42. ((CONFIG_IRQ_TIMER3 - 7) << IRQ_TIMER3_POS) |
  43. ((CONFIG_IRQ_TIMER4 - 7) << IRQ_TIMER4_POS));
  44. bfin_write_SIC_IAR3(((CONFIG_IRQ_TIMER5 - 7) << IRQ_TIMER5_POS) |
  45. ((CONFIG_IRQ_TIMER6 - 7) << IRQ_TIMER6_POS) |
  46. ((CONFIG_IRQ_TIMER7 - 7) << IRQ_TIMER7_POS) |
  47. ((CONFIG_IRQ_PROG_INTA - 7) << IRQ_PROG_INTA_POS) |
  48. ((CONFIG_IRQ_PORTG_INTB - 7) << IRQ_PORTG_INTB_POS) |
  49. ((CONFIG_IRQ_MEM_DMA0 - 7) << IRQ_MEM_DMA0_POS) |
  50. ((CONFIG_IRQ_MEM_DMA1 - 7) << IRQ_MEM_DMA1_POS) |
  51. ((CONFIG_IRQ_WATCH - 7) << IRQ_WATCH_POS));
  52. SSYNC();
  53. }
  54. #define SPI_ERR_MASK (BIT_STAT_TXCOL | BIT_STAT_RBSY | BIT_STAT_MODF | BIT_STAT_TXE) /* SPI_STAT */
  55. #define SPORT_ERR_MASK (ROVF | RUVF | TOVF | TUVF) /* SPORT_STAT */
  56. #define PPI_ERR_MASK (0xFFFF & ~FLD) /* PPI_STATUS */
  57. #define EMAC_ERR_MASK (PHYINT | MMCINT | RXFSINT | TXFSINT | WAKEDET | RXDMAERR | TXDMAERR | STMDONE) /* EMAC_SYSTAT */
  58. #define UART_ERR_MASK (0x6) /* UART_IIR */
  59. #define CAN_ERR_MASK (EWTIF | EWRIF | EPIF | BOIF | WUIF | UIAIF | AAIF | RMLIF | UCEIF | EXTIF | ADIF) /* CAN_GIF */
  60. static int error_int_mask;
  61. static void bf537_generic_error_mask_irq(struct irq_data *d)
  62. {
  63. error_int_mask &= ~(1L << (d->irq - IRQ_PPI_ERROR));
  64. if (!error_int_mask)
  65. bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
  66. }
  67. static void bf537_generic_error_unmask_irq(struct irq_data *d)
  68. {
  69. bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
  70. error_int_mask |= 1L << (d->irq - IRQ_PPI_ERROR);
  71. }
  72. static struct irq_chip bf537_generic_error_irqchip = {
  73. .name = "ERROR",
  74. .irq_ack = bfin_ack_noop,
  75. .irq_mask_ack = bf537_generic_error_mask_irq,
  76. .irq_mask = bf537_generic_error_mask_irq,
  77. .irq_unmask = bf537_generic_error_unmask_irq,
  78. };
  79. static void bf537_demux_error_irq(unsigned int int_err_irq,
  80. struct irq_desc *inta_desc)
  81. {
  82. int irq = 0;
  83. #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
  84. if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
  85. irq = IRQ_MAC_ERROR;
  86. else
  87. #endif
  88. if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
  89. irq = IRQ_SPORT0_ERROR;
  90. else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
  91. irq = IRQ_SPORT1_ERROR;
  92. else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
  93. irq = IRQ_PPI_ERROR;
  94. else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
  95. irq = IRQ_CAN_ERROR;
  96. else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
  97. irq = IRQ_SPI_ERROR;
  98. else if ((bfin_read_UART0_IIR() & UART_ERR_MASK) == UART_ERR_MASK)
  99. irq = IRQ_UART0_ERROR;
  100. else if ((bfin_read_UART1_IIR() & UART_ERR_MASK) == UART_ERR_MASK)
  101. irq = IRQ_UART1_ERROR;
  102. if (irq) {
  103. if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR)))
  104. bfin_handle_irq(irq);
  105. else {
  106. switch (irq) {
  107. case IRQ_PPI_ERROR:
  108. bfin_write_PPI_STATUS(PPI_ERR_MASK);
  109. break;
  110. #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
  111. case IRQ_MAC_ERROR:
  112. bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
  113. break;
  114. #endif
  115. case IRQ_SPORT0_ERROR:
  116. bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
  117. break;
  118. case IRQ_SPORT1_ERROR:
  119. bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
  120. break;
  121. case IRQ_CAN_ERROR:
  122. bfin_write_CAN_GIS(CAN_ERR_MASK);
  123. break;
  124. case IRQ_SPI_ERROR:
  125. bfin_write_SPI_STAT(SPI_ERR_MASK);
  126. break;
  127. default:
  128. break;
  129. }
  130. pr_debug("IRQ %d:"
  131. " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
  132. irq);
  133. }
  134. } else
  135. pr_err("%s: IRQ ?: PERIPHERAL ERROR INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
  136. __func__);
  137. }
  138. #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
  139. static int mac_rx_int_mask;
  140. static void bf537_mac_rx_mask_irq(struct irq_data *d)
  141. {
  142. mac_rx_int_mask &= ~(1L << (d->irq - IRQ_MAC_RX));
  143. if (!mac_rx_int_mask)
  144. bfin_internal_mask_irq(IRQ_PH_INTA_MAC_RX);
  145. }
  146. static void bf537_mac_rx_unmask_irq(struct irq_data *d)
  147. {
  148. bfin_internal_unmask_irq(IRQ_PH_INTA_MAC_RX);
  149. mac_rx_int_mask |= 1L << (d->irq - IRQ_MAC_RX);
  150. }
  151. static struct irq_chip bf537_mac_rx_irqchip = {
  152. .name = "ERROR",
  153. .irq_ack = bfin_ack_noop,
  154. .irq_mask_ack = bf537_mac_rx_mask_irq,
  155. .irq_mask = bf537_mac_rx_mask_irq,
  156. .irq_unmask = bf537_mac_rx_unmask_irq,
  157. };
  158. static void bf537_demux_mac_rx_irq(unsigned int int_irq,
  159. struct irq_desc *desc)
  160. {
  161. if (bfin_read_DMA1_IRQ_STATUS() & (DMA_DONE | DMA_ERR))
  162. bfin_handle_irq(IRQ_MAC_RX);
  163. else
  164. bfin_demux_gpio_irq(int_irq, desc);
  165. }
  166. #endif
  167. void __init init_mach_irq(void)
  168. {
  169. int irq;
  170. #if defined(CONFIG_BF537) || defined(CONFIG_BF536)
  171. /* Clear EMAC Interrupt Status bits so we can demux it later */
  172. bfin_write_EMAC_SYSTAT(-1);
  173. #endif
  174. irq_set_chained_handler(IRQ_GENERIC_ERROR, bf537_demux_error_irq);
  175. for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
  176. irq_set_chip_and_handler(irq, &bf537_generic_error_irqchip,
  177. handle_level_irq);
  178. #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
  179. irq_set_chained_handler(IRQ_PH_INTA_MAC_RX, bf537_demux_mac_rx_irq);
  180. irq_set_chip_and_handler(IRQ_MAC_RX, &bf537_mac_rx_irqchip, handle_level_irq);
  181. irq_set_chip_and_handler(IRQ_PORTH_INTA, &bf537_mac_rx_irqchip, handle_level_irq);
  182. irq_set_chained_handler(IRQ_MAC_ERROR, bfin_demux_mac_status_irq);
  183. #endif
  184. }