ipr.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * arch/sh/kernel/cpu/irq/ipr.c
  3. *
  4. * Copyright (C) 1999 Niibe Yutaka & Takeshi Yaegashi
  5. * Copyright (C) 2000 Kazumoto Kojima
  6. * Copyright (C) 2003 Takashi Kusuda <kusuda-takashi@hitachi-ul.co.jp>
  7. *
  8. * Interrupt handling for IPR-based IRQ.
  9. *
  10. * Supported system:
  11. * On-chip supporting modules (TMU, RTC, etc.).
  12. * On-chip supporting modules for SH7709/SH7709A/SH7729/SH7300.
  13. * Hitachi SolutionEngine external I/O:
  14. * MS7709SE01, MS7709ASE01, and MS7750SE01
  15. *
  16. */
  17. #include <linux/init.h>
  18. #include <linux/irq.h>
  19. #include <linux/module.h>
  20. #include <asm/system.h>
  21. #include <asm/io.h>
  22. #include <asm/machvec.h>
  23. struct ipr_data {
  24. unsigned int addr; /* Address of Interrupt Priority Register */
  25. int shift; /* Shifts of the 16-bit data */
  26. int priority; /* The priority */
  27. };
  28. static struct ipr_data ipr_data[NR_IRQS];
  29. static void enable_ipr_irq(unsigned int irq);
  30. static void disable_ipr_irq(unsigned int irq);
  31. /* shutdown is same as "disable" */
  32. #define shutdown_ipr_irq disable_ipr_irq
  33. static void mask_and_ack_ipr(unsigned int);
  34. static void end_ipr_irq(unsigned int irq);
  35. static unsigned int startup_ipr_irq(unsigned int irq)
  36. {
  37. enable_ipr_irq(irq);
  38. return 0; /* never anything pending */
  39. }
  40. static struct hw_interrupt_type ipr_irq_type = {
  41. .typename = "IPR-IRQ",
  42. .startup = startup_ipr_irq,
  43. .shutdown = shutdown_ipr_irq,
  44. .enable = enable_ipr_irq,
  45. .disable = disable_ipr_irq,
  46. .ack = mask_and_ack_ipr,
  47. .end = end_ipr_irq
  48. };
  49. static void disable_ipr_irq(unsigned int irq)
  50. {
  51. unsigned long val;
  52. unsigned int addr = ipr_data[irq].addr;
  53. unsigned short mask = 0xffff ^ (0x0f << ipr_data[irq].shift);
  54. /* Set the priority in IPR to 0 */
  55. val = ctrl_inw(addr);
  56. val &= mask;
  57. ctrl_outw(val, addr);
  58. }
  59. static void enable_ipr_irq(unsigned int irq)
  60. {
  61. unsigned long val;
  62. unsigned int addr = ipr_data[irq].addr;
  63. int priority = ipr_data[irq].priority;
  64. unsigned short value = (priority << ipr_data[irq].shift);
  65. /* Set priority in IPR back to original value */
  66. val = ctrl_inw(addr);
  67. val |= value;
  68. ctrl_outw(val, addr);
  69. }
  70. static void mask_and_ack_ipr(unsigned int irq)
  71. {
  72. disable_ipr_irq(irq);
  73. #if defined(CONFIG_CPU_SUBTYPE_SH7707) || defined(CONFIG_CPU_SUBTYPE_SH7709) || \
  74. defined(CONFIG_CPU_SUBTYPE_SH7706) || \
  75. defined(CONFIG_CPU_SUBTYPE_SH7300) || defined(CONFIG_CPU_SUBTYPE_SH7705)
  76. /* This is needed when we use edge triggered setting */
  77. /* XXX: Is it really needed? */
  78. if (IRQ0_IRQ <= irq && irq <= IRQ5_IRQ) {
  79. /* Clear external interrupt request */
  80. int a = ctrl_inb(INTC_IRR0);
  81. a &= ~(1 << (irq - IRQ0_IRQ));
  82. ctrl_outb(a, INTC_IRR0);
  83. }
  84. #endif
  85. }
  86. static void end_ipr_irq(unsigned int irq)
  87. {
  88. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  89. enable_ipr_irq(irq);
  90. }
  91. void make_ipr_irq(unsigned int irq, unsigned int addr, int pos, int priority)
  92. {
  93. disable_irq_nosync(irq);
  94. ipr_data[irq].addr = addr;
  95. ipr_data[irq].shift = pos*4; /* POSition (0-3) x 4 means shift */
  96. ipr_data[irq].priority = priority;
  97. irq_desc[irq].chip = &ipr_irq_type;
  98. disable_ipr_irq(irq);
  99. }
  100. void __init init_IRQ(void)
  101. {
  102. #ifndef CONFIG_CPU_SUBTYPE_SH7780
  103. make_ipr_irq(TIMER_IRQ, TIMER_IPR_ADDR, TIMER_IPR_POS, TIMER_PRIORITY);
  104. make_ipr_irq(TIMER1_IRQ, TIMER1_IPR_ADDR, TIMER1_IPR_POS, TIMER1_PRIORITY);
  105. #ifdef RTC_IRQ
  106. make_ipr_irq(RTC_IRQ, RTC_IPR_ADDR, RTC_IPR_POS, RTC_PRIORITY);
  107. #endif
  108. #ifdef SCI_ERI_IRQ
  109. make_ipr_irq(SCI_ERI_IRQ, SCI_IPR_ADDR, SCI_IPR_POS, SCI_PRIORITY);
  110. make_ipr_irq(SCI_RXI_IRQ, SCI_IPR_ADDR, SCI_IPR_POS, SCI_PRIORITY);
  111. make_ipr_irq(SCI_TXI_IRQ, SCI_IPR_ADDR, SCI_IPR_POS, SCI_PRIORITY);
  112. #endif
  113. #ifdef SCIF1_ERI_IRQ
  114. make_ipr_irq(SCIF1_ERI_IRQ, SCIF1_IPR_ADDR, SCIF1_IPR_POS, SCIF1_PRIORITY);
  115. make_ipr_irq(SCIF1_RXI_IRQ, SCIF1_IPR_ADDR, SCIF1_IPR_POS, SCIF1_PRIORITY);
  116. make_ipr_irq(SCIF1_BRI_IRQ, SCIF1_IPR_ADDR, SCIF1_IPR_POS, SCIF1_PRIORITY);
  117. make_ipr_irq(SCIF1_TXI_IRQ, SCIF1_IPR_ADDR, SCIF1_IPR_POS, SCIF1_PRIORITY);
  118. #endif
  119. #if defined(CONFIG_CPU_SUBTYPE_SH7300)
  120. make_ipr_irq(SCIF0_IRQ, SCIF0_IPR_ADDR, SCIF0_IPR_POS, SCIF0_PRIORITY);
  121. make_ipr_irq(DMTE2_IRQ, DMA1_IPR_ADDR, DMA1_IPR_POS, DMA1_PRIORITY);
  122. make_ipr_irq(DMTE3_IRQ, DMA1_IPR_ADDR, DMA1_IPR_POS, DMA1_PRIORITY);
  123. make_ipr_irq(VIO_IRQ, VIO_IPR_ADDR, VIO_IPR_POS, VIO_PRIORITY);
  124. #endif
  125. #ifdef SCIF_ERI_IRQ
  126. make_ipr_irq(SCIF_ERI_IRQ, SCIF_IPR_ADDR, SCIF_IPR_POS, SCIF_PRIORITY);
  127. make_ipr_irq(SCIF_RXI_IRQ, SCIF_IPR_ADDR, SCIF_IPR_POS, SCIF_PRIORITY);
  128. make_ipr_irq(SCIF_BRI_IRQ, SCIF_IPR_ADDR, SCIF_IPR_POS, SCIF_PRIORITY);
  129. make_ipr_irq(SCIF_TXI_IRQ, SCIF_IPR_ADDR, SCIF_IPR_POS, SCIF_PRIORITY);
  130. #endif
  131. #ifdef IRDA_ERI_IRQ
  132. make_ipr_irq(IRDA_ERI_IRQ, IRDA_IPR_ADDR, IRDA_IPR_POS, IRDA_PRIORITY);
  133. make_ipr_irq(IRDA_RXI_IRQ, IRDA_IPR_ADDR, IRDA_IPR_POS, IRDA_PRIORITY);
  134. make_ipr_irq(IRDA_BRI_IRQ, IRDA_IPR_ADDR, IRDA_IPR_POS, IRDA_PRIORITY);
  135. make_ipr_irq(IRDA_TXI_IRQ, IRDA_IPR_ADDR, IRDA_IPR_POS, IRDA_PRIORITY);
  136. #endif
  137. #if defined(CONFIG_CPU_SUBTYPE_SH7707) || defined(CONFIG_CPU_SUBTYPE_SH7709) || \
  138. defined(CONFIG_CPU_SUBTYPE_SH7706) || \
  139. defined(CONFIG_CPU_SUBTYPE_SH7300) || defined(CONFIG_CPU_SUBTYPE_SH7705)
  140. /*
  141. * Initialize the Interrupt Controller (INTC)
  142. * registers to their power on values
  143. */
  144. /*
  145. * Enable external irq (INTC IRQ mode).
  146. * You should set corresponding bits of PFC to "00"
  147. * to enable these interrupts.
  148. */
  149. make_ipr_irq(IRQ0_IRQ, IRQ0_IPR_ADDR, IRQ0_IPR_POS, IRQ0_PRIORITY);
  150. make_ipr_irq(IRQ1_IRQ, IRQ1_IPR_ADDR, IRQ1_IPR_POS, IRQ1_PRIORITY);
  151. make_ipr_irq(IRQ2_IRQ, IRQ2_IPR_ADDR, IRQ2_IPR_POS, IRQ2_PRIORITY);
  152. make_ipr_irq(IRQ3_IRQ, IRQ3_IPR_ADDR, IRQ3_IPR_POS, IRQ3_PRIORITY);
  153. make_ipr_irq(IRQ4_IRQ, IRQ4_IPR_ADDR, IRQ4_IPR_POS, IRQ4_PRIORITY);
  154. make_ipr_irq(IRQ5_IRQ, IRQ5_IPR_ADDR, IRQ5_IPR_POS, IRQ5_PRIORITY);
  155. #endif
  156. #endif
  157. #ifdef CONFIG_CPU_HAS_PINT_IRQ
  158. init_IRQ_pint();
  159. #endif
  160. #ifdef CONFIG_CPU_HAS_INTC2_IRQ
  161. init_IRQ_intc2();
  162. #endif
  163. /* Perform the machine specific initialisation */
  164. if (sh_mv.mv_init_irq != NULL)
  165. sh_mv.mv_init_irq();
  166. irq_ctx_init(smp_processor_id());
  167. }
  168. #if !defined(CONFIG_CPU_HAS_PINT_IRQ)
  169. int ipr_irq_demux(int irq)
  170. {
  171. return irq;
  172. }
  173. #endif
  174. EXPORT_SYMBOL(make_ipr_irq);