pint.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * arch/sh/kernel/cpu/irq/pint.c - Interrupt handling for PINT-based IRQs.
  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. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/irq.h>
  14. #include <linux/module.h>
  15. #include <asm/system.h>
  16. #include <asm/io.h>
  17. #include <asm/machvec.h>
  18. #if defined(CONFIG_CPU_SUBTYPE_SH7705)
  19. #define INTC_INTER 0xA4000014UL
  20. #define INTC_IPRD 0xA4000018UL
  21. #define INTC_ICR2 0xA4000012UL
  22. /* PFC */
  23. #define PORT_PACR 0xA4000100UL
  24. #define PORT_PBCR 0xA4000102UL
  25. #define PORT_PCCR 0xA4000104UL
  26. #define PORT_PDCR 0xA4000106UL
  27. #define PORT_PECR 0xA4000108UL
  28. #define PORT_PFCR 0xA400010AUL
  29. #define PORT_PGCR 0xA400010CUL
  30. #define PORT_PHCR 0xA400010EUL
  31. #define PORT_PJCR 0xA4000110UL
  32. #define PORT_PKCR 0xA4000112UL
  33. #define PORT_PLCR 0xA4000114UL
  34. #define PORT_PMCR 0xA4000118UL
  35. #define PORT_PNCR 0xA400011AUL
  36. #define PORT_PECR2 0xA4050148UL
  37. #define PORT_PFCR2 0xA405014AUL
  38. #define PORT_PNCR2 0xA405015AUL
  39. /* I/O port */
  40. #define PORT_PADR 0xA4000120UL
  41. #define PORT_PBDR 0xA4000122UL
  42. #define PORT_PCDR 0xA4000124UL
  43. #define PORT_PDDR 0xA4000126UL
  44. #define PORT_PEDR 0xA4000128UL
  45. #define PORT_PFDR 0xA400012AUL
  46. #define PORT_PGDR 0xA400012CUL
  47. #define PORT_PHDR 0xA400012EUL
  48. #define PORT_PJDR 0xA4000130UL
  49. #define PORT_PKDR 0xA4000132UL
  50. #define PORT_PLDR 0xA4000134UL
  51. #define PORT_PMDR 0xA4000138UL
  52. #define PORT_PNDR 0xA400013AUL
  53. #define PINT0_IRQ 40
  54. #define PINT8_IRQ 41
  55. #define PINT_IRQ_BASE 86
  56. #define PINT0_IPR_ADDR INTC_IPRD
  57. #define PINT0_IPR_POS 3
  58. #define PINT0_PRIORITY 2
  59. #define PINT8_IPR_ADDR INTC_IPRD
  60. #define PINT8_IPR_POS 2
  61. #define PINT8_PRIORITY 2
  62. #endif /* CONFIG_CPU_SUBTYPE_SH7705 */
  63. static unsigned char pint_map[256];
  64. static unsigned long portcr_mask;
  65. static void enable_pint_irq(unsigned int irq);
  66. static void disable_pint_irq(unsigned int irq);
  67. /* shutdown is same as "disable" */
  68. #define shutdown_pint_irq disable_pint_irq
  69. static void mask_and_ack_pint(unsigned int);
  70. static void end_pint_irq(unsigned int irq);
  71. static unsigned int startup_pint_irq(unsigned int irq)
  72. {
  73. enable_pint_irq(irq);
  74. return 0; /* never anything pending */
  75. }
  76. static struct hw_interrupt_type pint_irq_type = {
  77. .typename = "PINT-IRQ",
  78. .startup = startup_pint_irq,
  79. .shutdown = shutdown_pint_irq,
  80. .enable = enable_pint_irq,
  81. .disable = disable_pint_irq,
  82. .ack = mask_and_ack_pint,
  83. .end = end_pint_irq
  84. };
  85. static void disable_pint_irq(unsigned int irq)
  86. {
  87. unsigned long val;
  88. val = ctrl_inw(INTC_INTER);
  89. val &= ~(1 << (irq - PINT_IRQ_BASE));
  90. ctrl_outw(val, INTC_INTER); /* disable PINTn */
  91. portcr_mask &= ~(3 << (irq - PINT_IRQ_BASE)*2);
  92. }
  93. static void enable_pint_irq(unsigned int irq)
  94. {
  95. unsigned long val;
  96. val = ctrl_inw(INTC_INTER);
  97. val |= 1 << (irq - PINT_IRQ_BASE);
  98. ctrl_outw(val, INTC_INTER); /* enable PINTn */
  99. portcr_mask |= 3 << (irq - PINT_IRQ_BASE)*2;
  100. }
  101. static void mask_and_ack_pint(unsigned int irq)
  102. {
  103. disable_pint_irq(irq);
  104. }
  105. static void end_pint_irq(unsigned int irq)
  106. {
  107. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  108. enable_pint_irq(irq);
  109. }
  110. void make_pint_irq(unsigned int irq)
  111. {
  112. disable_irq_nosync(irq);
  113. irq_desc[irq].chip = &pint_irq_type;
  114. disable_pint_irq(irq);
  115. }
  116. static struct ipr_data pint_ipr_map[] = {
  117. { PINT0_IRQ, PINT0_IPR_ADDR, PINT0_IPR_POS, PINT0_PRIORITY },
  118. { PINT8_IRQ, PINT8_IPR_ADDR, PINT8_IPR_POS, PINT8_PRIORITY },
  119. };
  120. void __init init_IRQ_pint(void)
  121. {
  122. int i;
  123. make_ipr_irq(pint_ipr_map, ARRAY_SIZE(pint_ipr_map));
  124. enable_irq(PINT0_IRQ);
  125. enable_irq(PINT8_IRQ);
  126. for(i = 0; i < 16; i++)
  127. make_pint_irq(PINT_IRQ_BASE + i);
  128. for(i = 0; i < 256; i++) {
  129. if (i & 1)
  130. pint_map[i] = 0;
  131. else if (i & 2)
  132. pint_map[i] = 1;
  133. else if (i & 4)
  134. pint_map[i] = 2;
  135. else if (i & 8)
  136. pint_map[i] = 3;
  137. else if (i & 0x10)
  138. pint_map[i] = 4;
  139. else if (i & 0x20)
  140. pint_map[i] = 5;
  141. else if (i & 0x40)
  142. pint_map[i] = 6;
  143. else if (i & 0x80)
  144. pint_map[i] = 7;
  145. }
  146. }
  147. int ipr_irq_demux(int irq)
  148. {
  149. unsigned long creg, dreg, d, sav;
  150. if (irq == PINT0_IRQ) {
  151. #if defined(CONFIG_CPU_SUBTYPE_SH7705) || defined(CONFIG_CPU_SUBTYPE_SH7707)
  152. creg = PORT_PACR;
  153. dreg = PORT_PADR;
  154. #else
  155. creg = PORT_PCCR;
  156. dreg = PORT_PCDR;
  157. #endif
  158. sav = ctrl_inw(creg);
  159. ctrl_outw(sav | portcr_mask, creg);
  160. d = (~ctrl_inb(dreg) ^ ctrl_inw(INTC_ICR2)) &
  161. ctrl_inw(INTC_INTER) & 0xff;
  162. ctrl_outw(sav, creg);
  163. if (d == 0)
  164. return irq;
  165. return PINT_IRQ_BASE + pint_map[d];
  166. } else if (irq == PINT8_IRQ) {
  167. #if defined(CONFIG_CPU_SUBTYPE_SH7705) || defined(CONFIG_CPU_SUBTYPE_SH7707)
  168. creg = PORT_PBCR;
  169. dreg = PORT_PBDR;
  170. #else
  171. creg = PORT_PFCR;
  172. dreg = PORT_PFDR;
  173. #endif
  174. sav = ctrl_inw(creg);
  175. ctrl_outw(sav | (portcr_mask >> 16), creg);
  176. d = (~ctrl_inb(dreg) ^ (ctrl_inw(INTC_ICR2) >> 8)) &
  177. (ctrl_inw(INTC_INTER) >> 8) & 0xff;
  178. ctrl_outw(sav, creg);
  179. if (d == 0)
  180. return irq;
  181. return PINT_IRQ_BASE + 8 + pint_map[d];
  182. }
  183. return irq;
  184. }