irq_intc.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * arch/sh64/kernel/irq_intc.c
  7. *
  8. * Copyright (C) 2000, 2001 Paolo Alberelli
  9. * Copyright (C) 2003 Paul Mundt
  10. *
  11. * Interrupt Controller support for SH5 INTC.
  12. * Per-interrupt selective. IRLM=0 (Fixed priority) is not
  13. * supported being useless without a cascaded interrupt
  14. * controller.
  15. *
  16. */
  17. #include <linux/init.h>
  18. #include <linux/irq.h>
  19. #include <linux/kernel.h>
  20. #include <linux/stddef.h>
  21. #include <linux/bitops.h> /* this includes also <asm/registers.h */
  22. /* which is required to remap register */
  23. /* names used into __asm__ blocks... */
  24. #include <asm/hardware.h>
  25. #include <asm/platform.h>
  26. #include <asm/page.h>
  27. #include <asm/io.h>
  28. #include <asm/irq.h>
  29. /*
  30. * Maybe the generic Peripheral block could move to a more
  31. * generic include file. INTC Block will be defined here
  32. * and only here to make INTC self-contained in a single
  33. * file.
  34. */
  35. #define INTC_BLOCK_OFFSET 0x01000000
  36. /* Base */
  37. #define INTC_BASE PHYS_PERIPHERAL_BLOCK + \
  38. INTC_BLOCK_OFFSET
  39. /* Address */
  40. #define INTC_ICR_SET (intc_virt + 0x0)
  41. #define INTC_ICR_CLEAR (intc_virt + 0x8)
  42. #define INTC_INTPRI_0 (intc_virt + 0x10)
  43. #define INTC_INTSRC_0 (intc_virt + 0x50)
  44. #define INTC_INTSRC_1 (intc_virt + 0x58)
  45. #define INTC_INTREQ_0 (intc_virt + 0x60)
  46. #define INTC_INTREQ_1 (intc_virt + 0x68)
  47. #define INTC_INTENB_0 (intc_virt + 0x70)
  48. #define INTC_INTENB_1 (intc_virt + 0x78)
  49. #define INTC_INTDSB_0 (intc_virt + 0x80)
  50. #define INTC_INTDSB_1 (intc_virt + 0x88)
  51. #define INTC_ICR_IRLM 0x1
  52. #define INTC_INTPRI_PREGS 8 /* 8 Priority Registers */
  53. #define INTC_INTPRI_PPREG 8 /* 8 Priorities per Register */
  54. /*
  55. * Mapper between the vector ordinal and the IRQ number
  56. * passed to kernel/device drivers.
  57. */
  58. int intc_evt_to_irq[(0xE20/0x20)+1] = {
  59. -1, -1, -1, -1, -1, -1, -1, -1, /* 0x000 - 0x0E0 */
  60. -1, -1, -1, -1, -1, -1, -1, -1, /* 0x100 - 0x1E0 */
  61. 0, 0, 0, 0, 0, 1, 0, 0, /* 0x200 - 0x2E0 */
  62. 2, 0, 0, 3, 0, 0, 0, -1, /* 0x300 - 0x3E0 */
  63. 32, 33, 34, 35, 36, 37, 38, -1, /* 0x400 - 0x4E0 */
  64. -1, -1, -1, 63, -1, -1, -1, -1, /* 0x500 - 0x5E0 */
  65. -1, -1, 18, 19, 20, 21, 22, -1, /* 0x600 - 0x6E0 */
  66. 39, 40, 41, 42, -1, -1, -1, -1, /* 0x700 - 0x7E0 */
  67. 4, 5, 6, 7, -1, -1, -1, -1, /* 0x800 - 0x8E0 */
  68. -1, -1, -1, -1, -1, -1, -1, -1, /* 0x900 - 0x9E0 */
  69. 12, 13, 14, 15, 16, 17, -1, -1, /* 0xA00 - 0xAE0 */
  70. -1, -1, -1, -1, -1, -1, -1, -1, /* 0xB00 - 0xBE0 */
  71. -1, -1, -1, -1, -1, -1, -1, -1, /* 0xC00 - 0xCE0 */
  72. -1, -1, -1, -1, -1, -1, -1, -1, /* 0xD00 - 0xDE0 */
  73. -1, -1 /* 0xE00 - 0xE20 */
  74. };
  75. /*
  76. * Opposite mapper.
  77. */
  78. static int IRQ_to_vectorN[NR_INTC_IRQS] = {
  79. 0x12, 0x15, 0x18, 0x1B, 0x40, 0x41, 0x42, 0x43, /* 0- 7 */
  80. -1, -1, -1, -1, 0x50, 0x51, 0x52, 0x53, /* 8-15 */
  81. 0x54, 0x55, 0x32, 0x33, 0x34, 0x35, 0x36, -1, /* 16-23 */
  82. -1, -1, -1, -1, -1, -1, -1, -1, /* 24-31 */
  83. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x38, /* 32-39 */
  84. 0x39, 0x3A, 0x3B, -1, -1, -1, -1, -1, /* 40-47 */
  85. -1, -1, -1, -1, -1, -1, -1, -1, /* 48-55 */
  86. -1, -1, -1, -1, -1, -1, -1, 0x2B, /* 56-63 */
  87. };
  88. static unsigned long intc_virt;
  89. static unsigned int startup_intc_irq(unsigned int irq);
  90. static void shutdown_intc_irq(unsigned int irq);
  91. static void enable_intc_irq(unsigned int irq);
  92. static void disable_intc_irq(unsigned int irq);
  93. static void mask_and_ack_intc(unsigned int);
  94. static void end_intc_irq(unsigned int irq);
  95. static struct hw_interrupt_type intc_irq_type = {
  96. .typename = "INTC",
  97. .startup = startup_intc_irq,
  98. .shutdown = shutdown_intc_irq,
  99. .enable = enable_intc_irq,
  100. .disable = disable_intc_irq,
  101. .ack = mask_and_ack_intc,
  102. .end = end_intc_irq
  103. };
  104. static int irlm; /* IRL mode */
  105. static unsigned int startup_intc_irq(unsigned int irq)
  106. {
  107. enable_intc_irq(irq);
  108. return 0; /* never anything pending */
  109. }
  110. static void shutdown_intc_irq(unsigned int irq)
  111. {
  112. disable_intc_irq(irq);
  113. }
  114. static void enable_intc_irq(unsigned int irq)
  115. {
  116. unsigned long reg;
  117. unsigned long bitmask;
  118. if ((irq <= IRQ_IRL3) && (irlm == NO_PRIORITY))
  119. printk("Trying to use straight IRL0-3 with an encoding platform.\n");
  120. if (irq < 32) {
  121. reg = INTC_INTENB_0;
  122. bitmask = 1 << irq;
  123. } else {
  124. reg = INTC_INTENB_1;
  125. bitmask = 1 << (irq - 32);
  126. }
  127. ctrl_outl(bitmask, reg);
  128. }
  129. static void disable_intc_irq(unsigned int irq)
  130. {
  131. unsigned long reg;
  132. unsigned long bitmask;
  133. if (irq < 32) {
  134. reg = INTC_INTDSB_0;
  135. bitmask = 1 << irq;
  136. } else {
  137. reg = INTC_INTDSB_1;
  138. bitmask = 1 << (irq - 32);
  139. }
  140. ctrl_outl(bitmask, reg);
  141. }
  142. static void mask_and_ack_intc(unsigned int irq)
  143. {
  144. disable_intc_irq(irq);
  145. }
  146. static void end_intc_irq(unsigned int irq)
  147. {
  148. enable_intc_irq(irq);
  149. }
  150. /* For future use, if we ever support IRLM=0) */
  151. void make_intc_irq(unsigned int irq)
  152. {
  153. disable_irq_nosync(irq);
  154. irq_desc[irq].chip = &intc_irq_type;
  155. disable_intc_irq(irq);
  156. }
  157. #if defined(CONFIG_PROC_FS) && defined(CONFIG_SYSCTL)
  158. int intc_irq_describe(char* p, int irq)
  159. {
  160. if (irq < NR_INTC_IRQS)
  161. return sprintf(p, "(0x%3x)", IRQ_to_vectorN[irq]*0x20);
  162. else
  163. return 0;
  164. }
  165. #endif
  166. void __init init_IRQ(void)
  167. {
  168. unsigned long long __dummy0, __dummy1=~0x00000000100000f0;
  169. unsigned long reg;
  170. unsigned long data;
  171. int i;
  172. intc_virt = onchip_remap(INTC_BASE, 1024, "INTC");
  173. if (!intc_virt) {
  174. panic("Unable to remap INTC\n");
  175. }
  176. /* Set default: per-line enable/disable, priority driven ack/eoi */
  177. for (i = 0; i < NR_INTC_IRQS; i++) {
  178. if (platform_int_priority[i] != NO_PRIORITY) {
  179. irq_desc[i].chip = &intc_irq_type;
  180. }
  181. }
  182. /* Disable all interrupts and set all priorities to 0 to avoid trouble */
  183. ctrl_outl(-1, INTC_INTDSB_0);
  184. ctrl_outl(-1, INTC_INTDSB_1);
  185. for (reg = INTC_INTPRI_0, i = 0; i < INTC_INTPRI_PREGS; i++, reg += 8)
  186. ctrl_outl( NO_PRIORITY, reg);
  187. /* Set IRLM */
  188. /* If all the priorities are set to 'no priority', then
  189. * assume we are using encoded mode.
  190. */
  191. irlm = platform_int_priority[IRQ_IRL0] + platform_int_priority[IRQ_IRL1] + \
  192. platform_int_priority[IRQ_IRL2] + platform_int_priority[IRQ_IRL3];
  193. if (irlm == NO_PRIORITY) {
  194. /* IRLM = 0 */
  195. reg = INTC_ICR_CLEAR;
  196. i = IRQ_INTA;
  197. printk("Trying to use encoded IRL0-3. IRLs unsupported.\n");
  198. } else {
  199. /* IRLM = 1 */
  200. reg = INTC_ICR_SET;
  201. i = IRQ_IRL0;
  202. }
  203. ctrl_outl(INTC_ICR_IRLM, reg);
  204. /* Set interrupt priorities according to platform description */
  205. for (data = 0, reg = INTC_INTPRI_0; i < NR_INTC_IRQS; i++) {
  206. data |= platform_int_priority[i] << ((i % INTC_INTPRI_PPREG) * 4);
  207. if ((i % INTC_INTPRI_PPREG) == (INTC_INTPRI_PPREG - 1)) {
  208. /* Upon the 7th, set Priority Register */
  209. ctrl_outl(data, reg);
  210. data = 0;
  211. reg += 8;
  212. }
  213. }
  214. #ifdef CONFIG_SH_CAYMAN
  215. {
  216. extern void init_cayman_irq(void);
  217. init_cayman_irq();
  218. }
  219. #endif
  220. /*
  221. * And now let interrupts come in.
  222. * sti() is not enough, we need to
  223. * lower priority, too.
  224. */
  225. __asm__ __volatile__("getcon " __SR ", %0\n\t"
  226. "and %0, %1, %0\n\t"
  227. "putcon %0, " __SR "\n\t"
  228. : "=&r" (__dummy0)
  229. : "r" (__dummy1));
  230. }