ipr.c 6.0 KB

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