intc2.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * Interrupt handling for INTC2-based IRQ.
  3. *
  4. * Copyright (C) 2001 David J. Mckay (david.mckay@st.com)
  5. * Copyright (C) 2005, 2006 Paul Mundt (lethal@linux-sh.org)
  6. *
  7. * May be copied or modified under the terms of the GNU General Public
  8. * License. See linux/COPYING for more information.
  9. *
  10. * These are the "new Hitachi style" interrupts, as present on the
  11. * Hitachi 7751, the STM ST40 STB1, SH7760, and SH7780.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/irq.h>
  16. #include <asm/system.h>
  17. #include <asm/io.h>
  18. #include <asm/machvec.h>
  19. struct intc2_data {
  20. unsigned char msk_offset;
  21. unsigned char msk_shift;
  22. int (*clear_irq) (int);
  23. };
  24. static struct intc2_data intc2_data[NR_INTC2_IRQS];
  25. static void enable_intc2_irq(unsigned int irq);
  26. static void disable_intc2_irq(unsigned int irq);
  27. /* shutdown is same as "disable" */
  28. #define shutdown_intc2_irq disable_intc2_irq
  29. static void mask_and_ack_intc2(unsigned int);
  30. static void end_intc2_irq(unsigned int irq);
  31. static unsigned int startup_intc2_irq(unsigned int irq)
  32. {
  33. enable_intc2_irq(irq);
  34. return 0; /* never anything pending */
  35. }
  36. static struct hw_interrupt_type intc2_irq_type = {
  37. .typename = "INTC2-IRQ",
  38. .startup = startup_intc2_irq,
  39. .shutdown = shutdown_intc2_irq,
  40. .enable = enable_intc2_irq,
  41. .disable = disable_intc2_irq,
  42. .ack = mask_and_ack_intc2,
  43. .end = end_intc2_irq
  44. };
  45. static void disable_intc2_irq(unsigned int irq)
  46. {
  47. int irq_offset = irq - INTC2_FIRST_IRQ;
  48. int msk_shift, msk_offset;
  49. /* Sanity check */
  50. if (unlikely(irq_offset < 0 || irq_offset >= NR_INTC2_IRQS))
  51. return;
  52. msk_shift = intc2_data[irq_offset].msk_shift;
  53. msk_offset = intc2_data[irq_offset].msk_offset;
  54. ctrl_outl(1 << msk_shift,
  55. INTC2_BASE + INTC2_INTMSK_OFFSET + msk_offset);
  56. }
  57. static void enable_intc2_irq(unsigned int irq)
  58. {
  59. int irq_offset = irq - INTC2_FIRST_IRQ;
  60. int msk_shift, msk_offset;
  61. /* Sanity check */
  62. if (unlikely(irq_offset < 0 || irq_offset >= NR_INTC2_IRQS))
  63. return;
  64. msk_shift = intc2_data[irq_offset].msk_shift;
  65. msk_offset = intc2_data[irq_offset].msk_offset;
  66. ctrl_outl(1 << msk_shift,
  67. INTC2_BASE + INTC2_INTMSKCLR_OFFSET + msk_offset);
  68. }
  69. static void mask_and_ack_intc2(unsigned int irq)
  70. {
  71. disable_intc2_irq(irq);
  72. }
  73. static void end_intc2_irq(unsigned int irq)
  74. {
  75. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  76. enable_intc2_irq(irq);
  77. if (unlikely(intc2_data[irq - INTC2_FIRST_IRQ].clear_irq))
  78. intc2_data[irq - INTC2_FIRST_IRQ].clear_irq(irq);
  79. }
  80. /*
  81. * Setup an INTC2 style interrupt.
  82. * NOTE: Unlike IPR interrupts, parameters are not shifted by this code,
  83. * allowing the use of the numbers straight out of the datasheet.
  84. * For example:
  85. * PIO1 which is INTPRI00[19,16] and INTMSK00[13]
  86. * would be: ^ ^ ^ ^
  87. * | | | |
  88. * make_intc2_irq(84, 0, 16, 0, 13);
  89. */
  90. void make_intc2_irq(unsigned int irq,
  91. unsigned int ipr_offset, unsigned int ipr_shift,
  92. unsigned int msk_offset, unsigned int msk_shift,
  93. unsigned int priority)
  94. {
  95. int irq_offset = irq - INTC2_FIRST_IRQ;
  96. unsigned int flags;
  97. unsigned long ipr;
  98. if (unlikely(irq_offset < 0 || irq_offset >= NR_INTC2_IRQS))
  99. return;
  100. disable_irq_nosync(irq);
  101. /* Fill the data we need */
  102. intc2_data[irq_offset].msk_offset = msk_offset;
  103. intc2_data[irq_offset].msk_shift = msk_shift;
  104. intc2_data[irq_offset].clear_irq = NULL;
  105. /* Set the priority level */
  106. local_irq_save(flags);
  107. ipr = ctrl_inl(INTC2_BASE + INTC2_INTPRI_OFFSET + ipr_offset);
  108. ipr &= ~(0xf << ipr_shift);
  109. ipr |= priority << ipr_shift;
  110. ctrl_outl(ipr, INTC2_BASE + INTC2_INTPRI_OFFSET + ipr_offset);
  111. local_irq_restore(flags);
  112. irq_desc[irq].handler = &intc2_irq_type;
  113. disable_intc2_irq(irq);
  114. }
  115. static struct intc2_init {
  116. unsigned short irq;
  117. unsigned char ipr_offset, ipr_shift;
  118. unsigned char msk_offset, msk_shift;
  119. unsigned char priority;
  120. } intc2_init_data[] __initdata = {
  121. #if defined(CONFIG_CPU_SUBTYPE_ST40)
  122. {64, 0, 0, 0, 0, 13}, /* PCI serr */
  123. {65, 0, 4, 0, 1, 13}, /* PCI err */
  124. {66, 0, 4, 0, 2, 13}, /* PCI ad */
  125. {67, 0, 4, 0, 3, 13}, /* PCI pwd down */
  126. {72, 0, 8, 0, 5, 13}, /* DMAC INT0 */
  127. {73, 0, 8, 0, 6, 13}, /* DMAC INT1 */
  128. {74, 0, 8, 0, 7, 13}, /* DMAC INT2 */
  129. {75, 0, 8, 0, 8, 13}, /* DMAC INT3 */
  130. {76, 0, 8, 0, 9, 13}, /* DMAC INT4 */
  131. {78, 0, 8, 0, 11, 13}, /* DMAC ERR */
  132. {80, 0, 12, 0, 12, 13}, /* PIO0 */
  133. {84, 0, 16, 0, 13, 13}, /* PIO1 */
  134. {88, 0, 20, 0, 14, 13}, /* PIO2 */
  135. {112, 4, 0, 4, 0, 13}, /* Mailbox */
  136. #ifdef CONFIG_CPU_SUBTYPE_ST40GX1
  137. {116, 4, 4, 4, 4, 13}, /* SSC0 */
  138. {120, 4, 8, 4, 8, 13}, /* IR Blaster */
  139. {124, 4, 12, 4, 12, 13}, /* USB host */
  140. {128, 4, 16, 4, 16, 13}, /* Video processor BLITTER */
  141. {132, 4, 20, 4, 20, 13}, /* UART0 */
  142. {134, 4, 20, 4, 22, 13}, /* UART2 */
  143. {136, 4, 24, 4, 24, 13}, /* IO_PIO0 */
  144. {140, 4, 28, 4, 28, 13}, /* EMPI */
  145. {144, 8, 0, 8, 0, 13}, /* MAFE */
  146. {148, 8, 4, 8, 4, 13}, /* PWM */
  147. {152, 8, 8, 8, 8, 13}, /* SSC1 */
  148. {156, 8, 12, 8, 12, 13}, /* IO_PIO1 */
  149. {160, 8, 16, 8, 16, 13}, /* USB target */
  150. {164, 8, 20, 8, 20, 13}, /* UART1 */
  151. {168, 8, 24, 8, 24, 13}, /* Teletext */
  152. {172, 8, 28, 8, 28, 13}, /* VideoSync VTG */
  153. {173, 8, 28, 8, 29, 13}, /* VideoSync DVP0 */
  154. {174, 8, 28, 8, 30, 13}, /* VideoSync DVP1 */
  155. #endif
  156. #elif defined(CONFIG_CPU_SUBTYPE_SH7760)
  157. /*
  158. * SH7760 INTC2-Style interrupts, vectors IRQ48-111 INTEVT 0x800-0xFE0
  159. */
  160. /* INTPRIO0 | INTMSK0 */
  161. {48, 0, 28, 0, 31, 3}, /* IRQ 4 */
  162. {49, 0, 24, 0, 30, 3}, /* IRQ 3 */
  163. {50, 0, 20, 0, 29, 3}, /* IRQ 2 */
  164. {51, 0, 16, 0, 28, 3}, /* IRQ 1 */
  165. /* 52-55 (INTEVT 0x880-0x8E0) unused/reserved */
  166. /* INTPRIO4 | INTMSK0 */
  167. {56, 4, 28, 0, 25, 3}, /* HCAN2_CHAN0 */
  168. {57, 4, 24, 0, 24, 3}, /* HCAN2_CHAN1 */
  169. {58, 4, 20, 0, 23, 3}, /* I2S_CHAN0 */
  170. {59, 4, 16, 0, 22, 3}, /* I2S_CHAN1 */
  171. {60, 4, 12, 0, 21, 3}, /* AC97_CHAN0 */
  172. {61, 4, 8, 0, 20, 3}, /* AC97_CHAN1 */
  173. {62, 4, 4, 0, 19, 3}, /* I2C_CHAN0 */
  174. {63, 4, 0, 0, 18, 3}, /* I2C_CHAN1 */
  175. /* INTPRIO8 | INTMSK0 */
  176. {52, 8, 16, 0, 11, 3}, /* SCIF0_ERI_IRQ */
  177. {53, 8, 16, 0, 10, 3}, /* SCIF0_RXI_IRQ */
  178. {54, 8, 16, 0, 9, 3}, /* SCIF0_BRI_IRQ */
  179. {55, 8, 16, 0, 8, 3}, /* SCIF0_TXI_IRQ */
  180. {64, 8, 28, 0, 17, 3}, /* USBHI_IRQ */
  181. {65, 8, 24, 0, 16, 3}, /* LCDC */
  182. /* 66, 67 unused */
  183. {68, 8, 20, 0, 14, 13}, /* DMABRGI0_IRQ */
  184. {69, 8, 20, 0, 13, 13}, /* DMABRGI1_IRQ */
  185. {70, 8, 20, 0, 12, 13}, /* DMABRGI2_IRQ */
  186. /* 71 unused */
  187. {72, 8, 12, 0, 7, 3}, /* SCIF1_ERI_IRQ */
  188. {73, 8, 12, 0, 6, 3}, /* SCIF1_RXI_IRQ */
  189. {74, 8, 12, 0, 5, 3}, /* SCIF1_BRI_IRQ */
  190. {75, 8, 12, 0, 4, 3}, /* SCIF1_TXI_IRQ */
  191. {76, 8, 8, 0, 3, 3}, /* SCIF2_ERI_IRQ */
  192. {77, 8, 8, 0, 2, 3}, /* SCIF2_RXI_IRQ */
  193. {78, 8, 8, 0, 1, 3}, /* SCIF2_BRI_IRQ */
  194. {79, 8, 8, 0, 0, 3}, /* SCIF2_TXI_IRQ */
  195. /* | INTMSK4 */
  196. {80, 8, 4, 4, 23, 3}, /* SIM_ERI */
  197. {81, 8, 4, 4, 22, 3}, /* SIM_RXI */
  198. {82, 8, 4, 4, 21, 3}, /* SIM_TXI */
  199. {83, 8, 4, 4, 20, 3}, /* SIM_TEI */
  200. {84, 8, 0, 4, 19, 3}, /* HSPII */
  201. /* INTPRIOC | INTMSK4 */
  202. /* 85-87 unused/reserved */
  203. {88, 12, 20, 4, 18, 3}, /* MMCI0 */
  204. {89, 12, 20, 4, 17, 3}, /* MMCI1 */
  205. {90, 12, 20, 4, 16, 3}, /* MMCI2 */
  206. {91, 12, 20, 4, 15, 3}, /* MMCI3 */
  207. {92, 12, 12, 4, 6, 3}, /* MFI (unsure, bug? in my 7760 manual*/
  208. /* 93-107 reserved/undocumented */
  209. {108,12, 4, 4, 1, 3}, /* ADC */
  210. {109,12, 0, 4, 0, 3}, /* CMTI */
  211. /* 110-111 reserved/unused */
  212. #elif defined(CONFIG_CPU_SUBTYPE_SH7780)
  213. { TIMER_IRQ, 0, 24, 0, INTC_TMU0_MSK, 2},
  214. #ifdef CONFIG_SH_RTC
  215. { RTC_IRQ, 4, 0, 0, INTC_RTC_MSK, TIMER_PRIORITY },
  216. #endif
  217. { SCIF0_ERI_IRQ, 8, 24, 0, INTC_SCIF0_MSK, SCIF0_PRIORITY },
  218. { SCIF0_RXI_IRQ, 8, 24, 0, INTC_SCIF0_MSK, SCIF0_PRIORITY },
  219. { SCIF0_BRI_IRQ, 8, 24, 0, INTC_SCIF0_MSK, SCIF0_PRIORITY },
  220. { SCIF0_TXI_IRQ, 8, 24, 0, INTC_SCIF0_MSK, SCIF0_PRIORITY },
  221. { SCIF1_ERI_IRQ, 8, 16, 0, INTC_SCIF1_MSK, SCIF1_PRIORITY },
  222. { SCIF1_RXI_IRQ, 8, 16, 0, INTC_SCIF1_MSK, SCIF1_PRIORITY },
  223. { SCIF1_BRI_IRQ, 8, 16, 0, INTC_SCIF1_MSK, SCIF1_PRIORITY },
  224. { SCIF1_TXI_IRQ, 8, 16, 0, INTC_SCIF1_MSK, SCIF1_PRIORITY },
  225. { PCIC0_IRQ, 0x10, 8, 0, INTC_PCIC0_MSK, PCIC0_PRIORITY },
  226. { PCIC1_IRQ, 0x10, 0, 0, INTC_PCIC1_MSK, PCIC1_PRIORITY },
  227. { PCIC2_IRQ, 0x14, 24, 0, INTC_PCIC2_MSK, PCIC2_PRIORITY },
  228. { PCIC3_IRQ, 0x14, 16, 0, INTC_PCIC3_MSK, PCIC3_PRIORITY },
  229. { PCIC4_IRQ, 0x14, 8, 0, INTC_PCIC4_MSK, PCIC4_PRIORITY },
  230. #endif
  231. };
  232. void __init init_IRQ_intc2(void)
  233. {
  234. int i;
  235. for (i = 0; i < ARRAY_SIZE(intc2_init_data); i++) {
  236. struct intc2_init *p = intc2_init_data + i;
  237. make_intc2_irq(p->irq, p->ipr_offset, p->ipr_shift,
  238. p-> msk_offset, p->msk_shift, p->priority);
  239. }
  240. }
  241. /* Adds a termination callback to the interrupt */
  242. void intc2_add_clear_irq(int irq, int (*fn)(int))
  243. {
  244. if (unlikely(irq < INTC2_FIRST_IRQ))
  245. return;
  246. intc2_data[irq - INTC2_FIRST_IRQ].clear_irq = fn;
  247. }