irq.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. /* XXX: FIQ and additional INTC support (only MPU at the moment) */
  68. static void omap_ack_irq(struct irq_data *d)
  69. {
  70. intc_bank_write_reg(0x1, &irq_banks[0], INTC_CONTROL);
  71. }
  72. static void omap_mask_ack_irq(struct irq_data *d)
  73. {
  74. irq_gc_mask_disable_reg(d);
  75. omap_ack_irq(d);
  76. }
  77. static void __init omap_irq_bank_init_one(struct omap_irq_bank *bank)
  78. {
  79. unsigned long tmp;
  80. tmp = intc_bank_read_reg(bank, INTC_REVISION) & 0xff;
  81. printk(KERN_INFO "IRQ: Found an INTC at 0x%p "
  82. "(revision %ld.%ld) with %d interrupts\n",
  83. bank->base_reg, tmp >> 4, tmp & 0xf, bank->nr_irqs);
  84. tmp = intc_bank_read_reg(bank, INTC_SYSCONFIG);
  85. tmp |= 1 << 1; /* soft reset */
  86. intc_bank_write_reg(tmp, bank, INTC_SYSCONFIG);
  87. while (!(intc_bank_read_reg(bank, INTC_SYSSTATUS) & 0x1))
  88. /* Wait for reset to complete */;
  89. /* Enable autoidle */
  90. intc_bank_write_reg(1 << 0, bank, INTC_SYSCONFIG);
  91. }
  92. int omap_irq_pending(void)
  93. {
  94. int i;
  95. for (i = 0; i < ARRAY_SIZE(irq_banks); i++) {
  96. struct omap_irq_bank *bank = irq_banks + i;
  97. int irq;
  98. for (irq = 0; irq < bank->nr_irqs; irq += 32)
  99. if (intc_bank_read_reg(bank, INTC_PENDING_IRQ0 +
  100. ((irq >> 5) << 5)))
  101. return 1;
  102. }
  103. return 0;
  104. }
  105. static __init void
  106. omap_alloc_gc(void __iomem *base, unsigned int irq_start, unsigned int num)
  107. {
  108. struct irq_chip_generic *gc;
  109. struct irq_chip_type *ct;
  110. gc = irq_alloc_generic_chip("INTC", 1, irq_start, base,
  111. handle_level_irq);
  112. ct = gc->chip_types;
  113. ct->chip.irq_ack = omap_mask_ack_irq;
  114. ct->chip.irq_mask = irq_gc_mask_disable_reg;
  115. ct->chip.irq_unmask = irq_gc_unmask_enable_reg;
  116. ct->regs.ack = INTC_CONTROL;
  117. ct->regs.enable = INTC_MIR_CLEAR0;
  118. ct->regs.disable = INTC_MIR_SET0;
  119. irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
  120. IRQ_NOREQUEST | IRQ_NOPROBE, 0);
  121. }
  122. static void __init omap_init_irq(u32 base, int nr_irqs)
  123. {
  124. unsigned long nr_of_irqs = 0;
  125. unsigned int nr_banks = 0;
  126. int i, j;
  127. omap_irq_base = ioremap(base, SZ_4K);
  128. if (WARN_ON(!omap_irq_base))
  129. return;
  130. for (i = 0; i < ARRAY_SIZE(irq_banks); i++) {
  131. struct omap_irq_bank *bank = irq_banks + i;
  132. bank->nr_irqs = nr_irqs;
  133. /* Static mapping, never released */
  134. bank->base_reg = ioremap(base, SZ_4K);
  135. if (!bank->base_reg) {
  136. printk(KERN_ERR "Could not ioremap irq bank%i\n", i);
  137. continue;
  138. }
  139. omap_irq_bank_init_one(bank);
  140. for (i = 0, j = 0; i < bank->nr_irqs; i += 32, j += 0x20)
  141. omap_alloc_gc(bank->base_reg + j, i, 32);
  142. nr_of_irqs += bank->nr_irqs;
  143. nr_banks++;
  144. }
  145. printk(KERN_INFO "Total of %ld interrupts on %d active controller%s\n",
  146. nr_of_irqs, nr_banks, nr_banks > 1 ? "s" : "");
  147. }
  148. void __init omap2_init_irq(void)
  149. {
  150. omap_init_irq(OMAP24XX_IC_BASE, 96);
  151. }
  152. void __init omap3_init_irq(void)
  153. {
  154. omap_init_irq(OMAP34XX_IC_BASE, 96);
  155. }
  156. void __init ti816x_init_irq(void)
  157. {
  158. omap_init_irq(OMAP34XX_IC_BASE, 128);
  159. }
  160. #ifdef CONFIG_ARCH_OMAP3
  161. static struct omap3_intc_regs intc_context[ARRAY_SIZE(irq_banks)];
  162. void omap_intc_save_context(void)
  163. {
  164. int ind = 0, i = 0;
  165. for (ind = 0; ind < ARRAY_SIZE(irq_banks); ind++) {
  166. struct omap_irq_bank *bank = irq_banks + ind;
  167. intc_context[ind].sysconfig =
  168. intc_bank_read_reg(bank, INTC_SYSCONFIG);
  169. intc_context[ind].protection =
  170. intc_bank_read_reg(bank, INTC_PROTECTION);
  171. intc_context[ind].idle =
  172. intc_bank_read_reg(bank, INTC_IDLE);
  173. intc_context[ind].threshold =
  174. intc_bank_read_reg(bank, INTC_THRESHOLD);
  175. for (i = 0; i < INTCPS_NR_IRQS; i++)
  176. intc_context[ind].ilr[i] =
  177. intc_bank_read_reg(bank, (0x100 + 0x4*i));
  178. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  179. intc_context[ind].mir[i] =
  180. intc_bank_read_reg(&irq_banks[0], INTC_MIR0 +
  181. (0x20 * i));
  182. }
  183. }
  184. void omap_intc_restore_context(void)
  185. {
  186. int ind = 0, i = 0;
  187. for (ind = 0; ind < ARRAY_SIZE(irq_banks); ind++) {
  188. struct omap_irq_bank *bank = irq_banks + ind;
  189. intc_bank_write_reg(intc_context[ind].sysconfig,
  190. bank, INTC_SYSCONFIG);
  191. intc_bank_write_reg(intc_context[ind].sysconfig,
  192. bank, INTC_SYSCONFIG);
  193. intc_bank_write_reg(intc_context[ind].protection,
  194. bank, INTC_PROTECTION);
  195. intc_bank_write_reg(intc_context[ind].idle,
  196. bank, INTC_IDLE);
  197. intc_bank_write_reg(intc_context[ind].threshold,
  198. bank, INTC_THRESHOLD);
  199. for (i = 0; i < INTCPS_NR_IRQS; i++)
  200. intc_bank_write_reg(intc_context[ind].ilr[i],
  201. bank, (0x100 + 0x4*i));
  202. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  203. intc_bank_write_reg(intc_context[ind].mir[i],
  204. &irq_banks[0], INTC_MIR0 + (0x20 * i));
  205. }
  206. /* MIRs are saved and restore with other PRCM registers */
  207. }
  208. void omap3_intc_suspend(void)
  209. {
  210. /* A pending interrupt would prevent OMAP from entering suspend */
  211. omap_ack_irq(0);
  212. }
  213. void omap3_intc_prepare_idle(void)
  214. {
  215. /*
  216. * Disable autoidle as it can stall interrupt controller,
  217. * cf. errata ID i540 for 3430 (all revisions up to 3.1.x)
  218. */
  219. intc_bank_write_reg(0, &irq_banks[0], INTC_SYSCONFIG);
  220. }
  221. void omap3_intc_resume_idle(void)
  222. {
  223. /* Re-enable autoidle */
  224. intc_bank_write_reg(1, &irq_banks[0], INTC_SYSCONFIG);
  225. }
  226. #endif /* CONFIG_ARCH_OMAP3 */