irq.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. .base_reg = 0,
  47. .nr_irqs = 96,
  48. },
  49. };
  50. /* Structure to save interrupt controller context */
  51. struct omap3_intc_regs {
  52. u32 sysconfig;
  53. u32 protection;
  54. u32 idle;
  55. u32 threshold;
  56. u32 ilr[INTCPS_NR_IRQS];
  57. u32 mir[INTCPS_NR_MIR_REGS];
  58. };
  59. static struct omap3_intc_regs intc_context[ARRAY_SIZE(irq_banks)];
  60. /* INTC bank register get/set */
  61. static void intc_bank_write_reg(u32 val, struct omap_irq_bank *bank, u16 reg)
  62. {
  63. __raw_writel(val, bank->base_reg + reg);
  64. }
  65. static u32 intc_bank_read_reg(struct omap_irq_bank *bank, u16 reg)
  66. {
  67. return __raw_readl(bank->base_reg + reg);
  68. }
  69. static int previous_irq;
  70. /*
  71. * On 34xx we can get occasional spurious interrupts if the ack from
  72. * an interrupt handler does not get posted before we unmask. Warn about
  73. * the interrupt handlers that need to flush posted writes.
  74. */
  75. static int omap_check_spurious(unsigned int irq)
  76. {
  77. u32 sir, spurious;
  78. sir = intc_bank_read_reg(&irq_banks[0], INTC_SIR);
  79. spurious = sir >> 7;
  80. if (spurious) {
  81. printk(KERN_WARNING "Spurious irq %i: 0x%08x, please flush "
  82. "posted write for irq %i\n",
  83. irq, sir, previous_irq);
  84. return spurious;
  85. }
  86. return 0;
  87. }
  88. /* XXX: FIQ and additional INTC support (only MPU at the moment) */
  89. static void omap_ack_irq(unsigned int irq)
  90. {
  91. intc_bank_write_reg(0x1, &irq_banks[0], INTC_CONTROL);
  92. }
  93. static void omap_mask_irq(unsigned int irq)
  94. {
  95. int offset = irq & (~(IRQ_BITS_PER_REG - 1));
  96. if (cpu_is_omap34xx()) {
  97. int spurious = 0;
  98. /*
  99. * INT_34XX_GPT12_IRQ is also the spurious irq. Maybe because
  100. * it is the highest irq number?
  101. */
  102. if (irq == INT_34XX_GPT12_IRQ)
  103. spurious = omap_check_spurious(irq);
  104. if (!spurious)
  105. previous_irq = irq;
  106. }
  107. irq &= (IRQ_BITS_PER_REG - 1);
  108. intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_SET0 + offset);
  109. }
  110. static void omap_unmask_irq(unsigned int irq)
  111. {
  112. int offset = irq & (~(IRQ_BITS_PER_REG - 1));
  113. irq &= (IRQ_BITS_PER_REG - 1);
  114. intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_CLEAR0 + offset);
  115. }
  116. static void omap_mask_ack_irq(unsigned int irq)
  117. {
  118. omap_mask_irq(irq);
  119. omap_ack_irq(irq);
  120. }
  121. static struct irq_chip omap_irq_chip = {
  122. .name = "INTC",
  123. .ack = omap_mask_ack_irq,
  124. .mask = omap_mask_irq,
  125. .unmask = omap_unmask_irq,
  126. };
  127. static void __init omap_irq_bank_init_one(struct omap_irq_bank *bank)
  128. {
  129. unsigned long tmp;
  130. tmp = intc_bank_read_reg(bank, INTC_REVISION) & 0xff;
  131. printk(KERN_INFO "IRQ: Found an INTC at 0x%p "
  132. "(revision %ld.%ld) with %d interrupts\n",
  133. bank->base_reg, tmp >> 4, tmp & 0xf, bank->nr_irqs);
  134. tmp = intc_bank_read_reg(bank, INTC_SYSCONFIG);
  135. tmp |= 1 << 1; /* soft reset */
  136. intc_bank_write_reg(tmp, bank, INTC_SYSCONFIG);
  137. while (!(intc_bank_read_reg(bank, INTC_SYSSTATUS) & 0x1))
  138. /* Wait for reset to complete */;
  139. /* Enable autoidle */
  140. intc_bank_write_reg(1 << 0, bank, INTC_SYSCONFIG);
  141. }
  142. int omap_irq_pending(void)
  143. {
  144. int i;
  145. for (i = 0; i < ARRAY_SIZE(irq_banks); i++) {
  146. struct omap_irq_bank *bank = irq_banks + i;
  147. int irq;
  148. for (irq = 0; irq < bank->nr_irqs; irq += 32)
  149. if (intc_bank_read_reg(bank, INTC_PENDING_IRQ0 +
  150. ((irq >> 5) << 5)))
  151. return 1;
  152. }
  153. return 0;
  154. }
  155. void __init omap_init_irq(void)
  156. {
  157. unsigned long nr_of_irqs = 0;
  158. unsigned int nr_banks = 0;
  159. int i;
  160. for (i = 0; i < ARRAY_SIZE(irq_banks); i++) {
  161. unsigned long base = 0;
  162. struct omap_irq_bank *bank = irq_banks + i;
  163. if (cpu_is_omap24xx())
  164. base = OMAP24XX_IC_BASE;
  165. else if (cpu_is_omap34xx())
  166. base = OMAP34XX_IC_BASE;
  167. BUG_ON(!base);
  168. /* Static mapping, never released */
  169. bank->base_reg = ioremap(base, SZ_4K);
  170. if (!bank->base_reg) {
  171. printk(KERN_ERR "Could not ioremap irq bank%i\n", i);
  172. continue;
  173. }
  174. omap_irq_bank_init_one(bank);
  175. nr_of_irqs += bank->nr_irqs;
  176. nr_banks++;
  177. }
  178. printk(KERN_INFO "Total of %ld interrupts on %d active controller%s\n",
  179. nr_of_irqs, nr_banks, nr_banks > 1 ? "s" : "");
  180. for (i = 0; i < nr_of_irqs; i++) {
  181. set_irq_chip(i, &omap_irq_chip);
  182. set_irq_handler(i, handle_level_irq);
  183. set_irq_flags(i, IRQF_VALID);
  184. }
  185. }
  186. #ifdef CONFIG_ARCH_OMAP3
  187. void omap_intc_save_context(void)
  188. {
  189. int ind = 0, i = 0;
  190. for (ind = 0; ind < ARRAY_SIZE(irq_banks); ind++) {
  191. struct omap_irq_bank *bank = irq_banks + ind;
  192. intc_context[ind].sysconfig =
  193. intc_bank_read_reg(bank, INTC_SYSCONFIG);
  194. intc_context[ind].protection =
  195. intc_bank_read_reg(bank, INTC_PROTECTION);
  196. intc_context[ind].idle =
  197. intc_bank_read_reg(bank, INTC_IDLE);
  198. intc_context[ind].threshold =
  199. intc_bank_read_reg(bank, INTC_THRESHOLD);
  200. for (i = 0; i < INTCPS_NR_IRQS; i++)
  201. intc_context[ind].ilr[i] =
  202. intc_bank_read_reg(bank, (0x100 + 0x4*i));
  203. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  204. intc_context[ind].mir[i] =
  205. intc_bank_read_reg(&irq_banks[0], INTC_MIR0 +
  206. (0x20 * i));
  207. }
  208. }
  209. void omap_intc_restore_context(void)
  210. {
  211. int ind = 0, i = 0;
  212. for (ind = 0; ind < ARRAY_SIZE(irq_banks); ind++) {
  213. struct omap_irq_bank *bank = irq_banks + ind;
  214. intc_bank_write_reg(intc_context[ind].sysconfig,
  215. bank, INTC_SYSCONFIG);
  216. intc_bank_write_reg(intc_context[ind].sysconfig,
  217. bank, INTC_SYSCONFIG);
  218. intc_bank_write_reg(intc_context[ind].protection,
  219. bank, INTC_PROTECTION);
  220. intc_bank_write_reg(intc_context[ind].idle,
  221. bank, INTC_IDLE);
  222. intc_bank_write_reg(intc_context[ind].threshold,
  223. bank, INTC_THRESHOLD);
  224. for (i = 0; i < INTCPS_NR_IRQS; i++)
  225. intc_bank_write_reg(intc_context[ind].ilr[i],
  226. bank, (0x100 + 0x4*i));
  227. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  228. intc_bank_write_reg(intc_context[ind].mir[i],
  229. &irq_banks[0], INTC_MIR0 + (0x20 * i));
  230. }
  231. /* MIRs are saved and restore with other PRCM registers */
  232. }
  233. void omap3_intc_suspend(void)
  234. {
  235. /* A pending interrupt would prevent OMAP from entering suspend */
  236. omap_ack_irq(0);
  237. }
  238. void omap3_intc_prepare_idle(void)
  239. {
  240. /* Disable autoidle as it can stall interrupt controller */
  241. intc_bank_write_reg(0, &irq_banks[0], INTC_SYSCONFIG);
  242. }
  243. void omap3_intc_resume_idle(void)
  244. {
  245. /* Re-enable autoidle */
  246. intc_bank_write_reg(1, &irq_banks[0], INTC_SYSCONFIG);
  247. }
  248. #endif /* CONFIG_ARCH_OMAP3 */