irq.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /*
  2. * linux/arch/arm/mach-omap2/irq.c
  3. *
  4. * Interrupt handler for OMAP2 boards.
  5. *
  6. * Copyright (C) 2005 Nokia Corporation
  7. * Author: Paul Mundt <paul.mundt@nokia.com>
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file "COPYING" in the main directory of this archive
  11. * for more details.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/io.h>
  17. #include <mach/hardware.h>
  18. #include <asm/mach/irq.h>
  19. /* selected INTC register offsets */
  20. #define INTC_REVISION 0x0000
  21. #define INTC_SYSCONFIG 0x0010
  22. #define INTC_SYSSTATUS 0x0014
  23. #define INTC_SIR 0x0040
  24. #define INTC_CONTROL 0x0048
  25. #define INTC_PROTECTION 0x004C
  26. #define INTC_IDLE 0x0050
  27. #define INTC_THRESHOLD 0x0068
  28. #define INTC_MIR0 0x0084
  29. #define INTC_MIR_CLEAR0 0x0088
  30. #define INTC_MIR_SET0 0x008c
  31. #define INTC_PENDING_IRQ0 0x0098
  32. /* Number of IRQ state bits in each MIR register */
  33. #define IRQ_BITS_PER_REG 32
  34. /*
  35. * OMAP2 has a number of different interrupt controllers, each interrupt
  36. * controller is identified as its own "bank". Register definitions are
  37. * fairly consistent for each bank, but not all registers are implemented
  38. * for each bank.. when in doubt, consult the TRM.
  39. */
  40. static struct omap_irq_bank {
  41. void __iomem *base_reg;
  42. unsigned int nr_irqs;
  43. } __attribute__ ((aligned(4))) irq_banks[] = {
  44. {
  45. /* MPU INTC */
  46. .nr_irqs = 96,
  47. },
  48. };
  49. /* Structure to save interrupt controller context */
  50. struct omap3_intc_regs {
  51. u32 sysconfig;
  52. u32 protection;
  53. u32 idle;
  54. u32 threshold;
  55. u32 ilr[INTCPS_NR_IRQS];
  56. u32 mir[INTCPS_NR_MIR_REGS];
  57. };
  58. static struct omap3_intc_regs intc_context[ARRAY_SIZE(irq_banks)];
  59. /* INTC bank register get/set */
  60. static void intc_bank_write_reg(u32 val, struct omap_irq_bank *bank, u16 reg)
  61. {
  62. __raw_writel(val, bank->base_reg + reg);
  63. }
  64. static u32 intc_bank_read_reg(struct omap_irq_bank *bank, u16 reg)
  65. {
  66. return __raw_readl(bank->base_reg + reg);
  67. }
  68. static int previous_irq;
  69. /*
  70. * On 34xx we can get occasional spurious interrupts if the ack from
  71. * an interrupt handler does not get posted before we unmask. Warn about
  72. * the interrupt handlers that need to flush posted writes.
  73. */
  74. static int omap_check_spurious(unsigned int irq)
  75. {
  76. u32 sir, spurious;
  77. sir = intc_bank_read_reg(&irq_banks[0], INTC_SIR);
  78. spurious = sir >> 7;
  79. if (spurious) {
  80. printk(KERN_WARNING "Spurious irq %i: 0x%08x, please flush "
  81. "posted write for irq %i\n",
  82. irq, sir, previous_irq);
  83. return spurious;
  84. }
  85. return 0;
  86. }
  87. /* XXX: FIQ and additional INTC support (only MPU at the moment) */
  88. static void omap_ack_irq(unsigned int irq)
  89. {
  90. intc_bank_write_reg(0x1, &irq_banks[0], INTC_CONTROL);
  91. }
  92. static void omap_mask_irq(unsigned int irq)
  93. {
  94. int offset = irq & (~(IRQ_BITS_PER_REG - 1));
  95. if (cpu_is_omap34xx()) {
  96. int spurious = 0;
  97. /*
  98. * INT_34XX_GPT12_IRQ is also the spurious irq. Maybe because
  99. * it is the highest irq number?
  100. */
  101. if (irq == INT_34XX_GPT12_IRQ)
  102. spurious = omap_check_spurious(irq);
  103. if (!spurious)
  104. previous_irq = irq;
  105. }
  106. irq &= (IRQ_BITS_PER_REG - 1);
  107. intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_SET0 + offset);
  108. }
  109. static void omap_unmask_irq(unsigned int irq)
  110. {
  111. int offset = irq & (~(IRQ_BITS_PER_REG - 1));
  112. irq &= (IRQ_BITS_PER_REG - 1);
  113. intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_CLEAR0 + offset);
  114. }
  115. static void omap_mask_ack_irq(unsigned int irq)
  116. {
  117. omap_mask_irq(irq);
  118. omap_ack_irq(irq);
  119. }
  120. static struct irq_chip omap_irq_chip = {
  121. .name = "INTC",
  122. .ack = omap_mask_ack_irq,
  123. .mask = omap_mask_irq,
  124. .unmask = omap_unmask_irq,
  125. };
  126. static void __init omap_irq_bank_init_one(struct omap_irq_bank *bank)
  127. {
  128. unsigned long tmp;
  129. tmp = intc_bank_read_reg(bank, INTC_REVISION) & 0xff;
  130. printk(KERN_INFO "IRQ: Found an INTC at 0x%p "
  131. "(revision %ld.%ld) with %d interrupts\n",
  132. bank->base_reg, tmp >> 4, tmp & 0xf, bank->nr_irqs);
  133. tmp = intc_bank_read_reg(bank, INTC_SYSCONFIG);
  134. tmp |= 1 << 1; /* soft reset */
  135. intc_bank_write_reg(tmp, bank, INTC_SYSCONFIG);
  136. while (!(intc_bank_read_reg(bank, INTC_SYSSTATUS) & 0x1))
  137. /* Wait for reset to complete */;
  138. /* Enable autoidle */
  139. intc_bank_write_reg(1 << 0, bank, INTC_SYSCONFIG);
  140. }
  141. int omap_irq_pending(void)
  142. {
  143. int i;
  144. for (i = 0; i < ARRAY_SIZE(irq_banks); i++) {
  145. struct omap_irq_bank *bank = irq_banks + i;
  146. int irq;
  147. for (irq = 0; irq < bank->nr_irqs; irq += 32)
  148. if (intc_bank_read_reg(bank, INTC_PENDING_IRQ0 +
  149. ((irq >> 5) << 5)))
  150. return 1;
  151. }
  152. return 0;
  153. }
  154. void __init omap_init_irq(void)
  155. {
  156. unsigned long nr_of_irqs = 0;
  157. unsigned int nr_banks = 0;
  158. int i;
  159. for (i = 0; i < ARRAY_SIZE(irq_banks); i++) {
  160. unsigned long base = 0;
  161. struct omap_irq_bank *bank = irq_banks + i;
  162. if (cpu_is_omap24xx())
  163. base = OMAP24XX_IC_BASE;
  164. else if (cpu_is_omap34xx())
  165. base = OMAP34XX_IC_BASE;
  166. BUG_ON(!base);
  167. /* Static mapping, never released */
  168. bank->base_reg = ioremap(base, SZ_4K);
  169. if (!bank->base_reg) {
  170. printk(KERN_ERR "Could not ioremap irq bank%i\n", i);
  171. continue;
  172. }
  173. omap_irq_bank_init_one(bank);
  174. nr_of_irqs += bank->nr_irqs;
  175. nr_banks++;
  176. }
  177. printk(KERN_INFO "Total of %ld interrupts on %d active controller%s\n",
  178. nr_of_irqs, nr_banks, nr_banks > 1 ? "s" : "");
  179. for (i = 0; i < nr_of_irqs; i++) {
  180. set_irq_chip(i, &omap_irq_chip);
  181. set_irq_handler(i, handle_level_irq);
  182. set_irq_flags(i, IRQF_VALID);
  183. }
  184. }
  185. #ifdef CONFIG_ARCH_OMAP3
  186. void omap_intc_save_context(void)
  187. {
  188. int ind = 0, i = 0;
  189. for (ind = 0; ind < ARRAY_SIZE(irq_banks); ind++) {
  190. struct omap_irq_bank *bank = irq_banks + ind;
  191. intc_context[ind].sysconfig =
  192. intc_bank_read_reg(bank, INTC_SYSCONFIG);
  193. intc_context[ind].protection =
  194. intc_bank_read_reg(bank, INTC_PROTECTION);
  195. intc_context[ind].idle =
  196. intc_bank_read_reg(bank, INTC_IDLE);
  197. intc_context[ind].threshold =
  198. intc_bank_read_reg(bank, INTC_THRESHOLD);
  199. for (i = 0; i < INTCPS_NR_IRQS; i++)
  200. intc_context[ind].ilr[i] =
  201. intc_bank_read_reg(bank, (0x100 + 0x4*i));
  202. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  203. intc_context[ind].mir[i] =
  204. intc_bank_read_reg(&irq_banks[0], INTC_MIR0 +
  205. (0x20 * i));
  206. }
  207. }
  208. void omap_intc_restore_context(void)
  209. {
  210. int ind = 0, i = 0;
  211. for (ind = 0; ind < ARRAY_SIZE(irq_banks); ind++) {
  212. struct omap_irq_bank *bank = irq_banks + ind;
  213. intc_bank_write_reg(intc_context[ind].sysconfig,
  214. bank, INTC_SYSCONFIG);
  215. intc_bank_write_reg(intc_context[ind].sysconfig,
  216. bank, INTC_SYSCONFIG);
  217. intc_bank_write_reg(intc_context[ind].protection,
  218. bank, INTC_PROTECTION);
  219. intc_bank_write_reg(intc_context[ind].idle,
  220. bank, INTC_IDLE);
  221. intc_bank_write_reg(intc_context[ind].threshold,
  222. bank, INTC_THRESHOLD);
  223. for (i = 0; i < INTCPS_NR_IRQS; i++)
  224. intc_bank_write_reg(intc_context[ind].ilr[i],
  225. bank, (0x100 + 0x4*i));
  226. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  227. intc_bank_write_reg(intc_context[ind].mir[i],
  228. &irq_banks[0], INTC_MIR0 + (0x20 * i));
  229. }
  230. /* MIRs are saved and restore with other PRCM registers */
  231. }
  232. void omap3_intc_suspend(void)
  233. {
  234. /* A pending interrupt would prevent OMAP from entering suspend */
  235. omap_ack_irq(0);
  236. }
  237. void omap3_intc_prepare_idle(void)
  238. {
  239. /* Disable autoidle as it can stall interrupt controller */
  240. intc_bank_write_reg(0, &irq_banks[0], INTC_SYSCONFIG);
  241. }
  242. void omap3_intc_resume_idle(void)
  243. {
  244. /* Re-enable autoidle */
  245. intc_bank_write_reg(1, &irq_banks[0], INTC_SYSCONFIG);
  246. }
  247. #endif /* CONFIG_ARCH_OMAP3 */