irq.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. /* INTC bank register get/set */
  59. static void intc_bank_write_reg(u32 val, struct omap_irq_bank *bank, u16 reg)
  60. {
  61. __raw_writel(val, bank->base_reg + reg);
  62. }
  63. static u32 intc_bank_read_reg(struct omap_irq_bank *bank, u16 reg)
  64. {
  65. return __raw_readl(bank->base_reg + reg);
  66. }
  67. static int previous_irq;
  68. /*
  69. * On 34xx we can get occasional spurious interrupts if the ack from
  70. * an interrupt handler does not get posted before we unmask. Warn about
  71. * the interrupt handlers that need to flush posted writes.
  72. */
  73. static int omap_check_spurious(unsigned int irq)
  74. {
  75. u32 sir, spurious;
  76. sir = intc_bank_read_reg(&irq_banks[0], INTC_SIR);
  77. spurious = sir >> 7;
  78. if (spurious) {
  79. printk(KERN_WARNING "Spurious irq %i: 0x%08x, please flush "
  80. "posted write for irq %i\n",
  81. irq, sir, previous_irq);
  82. return spurious;
  83. }
  84. return 0;
  85. }
  86. /* XXX: FIQ and additional INTC support (only MPU at the moment) */
  87. static void omap_ack_irq(struct irq_data *d)
  88. {
  89. intc_bank_write_reg(0x1, &irq_banks[0], INTC_CONTROL);
  90. }
  91. static void omap_mask_irq(struct irq_data *d)
  92. {
  93. unsigned int irq = d->irq;
  94. int offset = irq & (~(IRQ_BITS_PER_REG - 1));
  95. if (cpu_is_omap34xx() && !cpu_is_ti816x()) {
  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(struct irq_data *d)
  110. {
  111. unsigned int irq = d->irq;
  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(struct irq_data *d)
  117. {
  118. omap_mask_irq(d);
  119. omap_ack_irq(d);
  120. }
  121. static struct irq_chip omap_irq_chip = {
  122. .name = "INTC",
  123. .irq_ack = omap_mask_ack_irq,
  124. .irq_mask = omap_mask_irq,
  125. .irq_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. if (cpu_is_ti816x())
  169. bank->nr_irqs = 128;
  170. /* Static mapping, never released */
  171. bank->base_reg = ioremap(base, SZ_4K);
  172. if (!bank->base_reg) {
  173. printk(KERN_ERR "Could not ioremap irq bank%i\n", i);
  174. continue;
  175. }
  176. omap_irq_bank_init_one(bank);
  177. nr_of_irqs += bank->nr_irqs;
  178. nr_banks++;
  179. }
  180. printk(KERN_INFO "Total of %ld interrupts on %d active controller%s\n",
  181. nr_of_irqs, nr_banks, nr_banks > 1 ? "s" : "");
  182. for (i = 0; i < nr_of_irqs; i++) {
  183. irq_set_chip_and_handler(i, &omap_irq_chip, handle_level_irq);
  184. set_irq_flags(i, IRQF_VALID);
  185. }
  186. }
  187. #ifdef CONFIG_ARCH_OMAP3
  188. static struct omap3_intc_regs intc_context[ARRAY_SIZE(irq_banks)];
  189. void omap_intc_save_context(void)
  190. {
  191. int ind = 0, i = 0;
  192. for (ind = 0; ind < ARRAY_SIZE(irq_banks); ind++) {
  193. struct omap_irq_bank *bank = irq_banks + ind;
  194. intc_context[ind].sysconfig =
  195. intc_bank_read_reg(bank, INTC_SYSCONFIG);
  196. intc_context[ind].protection =
  197. intc_bank_read_reg(bank, INTC_PROTECTION);
  198. intc_context[ind].idle =
  199. intc_bank_read_reg(bank, INTC_IDLE);
  200. intc_context[ind].threshold =
  201. intc_bank_read_reg(bank, INTC_THRESHOLD);
  202. for (i = 0; i < INTCPS_NR_IRQS; i++)
  203. intc_context[ind].ilr[i] =
  204. intc_bank_read_reg(bank, (0x100 + 0x4*i));
  205. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  206. intc_context[ind].mir[i] =
  207. intc_bank_read_reg(&irq_banks[0], INTC_MIR0 +
  208. (0x20 * i));
  209. }
  210. }
  211. void omap_intc_restore_context(void)
  212. {
  213. int ind = 0, i = 0;
  214. for (ind = 0; ind < ARRAY_SIZE(irq_banks); ind++) {
  215. struct omap_irq_bank *bank = irq_banks + ind;
  216. intc_bank_write_reg(intc_context[ind].sysconfig,
  217. bank, INTC_SYSCONFIG);
  218. intc_bank_write_reg(intc_context[ind].sysconfig,
  219. bank, INTC_SYSCONFIG);
  220. intc_bank_write_reg(intc_context[ind].protection,
  221. bank, INTC_PROTECTION);
  222. intc_bank_write_reg(intc_context[ind].idle,
  223. bank, INTC_IDLE);
  224. intc_bank_write_reg(intc_context[ind].threshold,
  225. bank, INTC_THRESHOLD);
  226. for (i = 0; i < INTCPS_NR_IRQS; i++)
  227. intc_bank_write_reg(intc_context[ind].ilr[i],
  228. bank, (0x100 + 0x4*i));
  229. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  230. intc_bank_write_reg(intc_context[ind].mir[i],
  231. &irq_banks[0], INTC_MIR0 + (0x20 * i));
  232. }
  233. /* MIRs are saved and restore with other PRCM registers */
  234. }
  235. void omap3_intc_suspend(void)
  236. {
  237. /* A pending interrupt would prevent OMAP from entering suspend */
  238. omap_ack_irq(0);
  239. }
  240. void omap3_intc_prepare_idle(void)
  241. {
  242. /*
  243. * Disable autoidle as it can stall interrupt controller,
  244. * cf. errata ID i540 for 3430 (all revisions up to 3.1.x)
  245. */
  246. intc_bank_write_reg(0, &irq_banks[0], INTC_SYSCONFIG);
  247. }
  248. void omap3_intc_resume_idle(void)
  249. {
  250. /* Re-enable autoidle */
  251. intc_bank_write_reg(1, &irq_banks[0], INTC_SYSCONFIG);
  252. }
  253. #endif /* CONFIG_ARCH_OMAP3 */