intc-sh5.c 6.0 KB

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