irq.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. void __init omap_init_irq(void)
  123. {
  124. unsigned long nr_of_irqs = 0;
  125. unsigned int nr_banks = 0;
  126. int i, j;
  127. for (i = 0; i < ARRAY_SIZE(irq_banks); i++) {
  128. unsigned long base = 0;
  129. struct omap_irq_bank *bank = irq_banks + i;
  130. if (cpu_is_omap24xx())
  131. base = OMAP24XX_IC_BASE;
  132. else if (cpu_is_omap34xx())
  133. base = OMAP34XX_IC_BASE;
  134. BUG_ON(!base);
  135. if (cpu_is_ti816x())
  136. bank->nr_irqs = 128;
  137. /* Static mapping, never released */
  138. bank->base_reg = ioremap(base, SZ_4K);
  139. if (!bank->base_reg) {
  140. printk(KERN_ERR "Could not ioremap irq bank%i\n", i);
  141. continue;
  142. }
  143. omap_irq_bank_init_one(bank);
  144. for (i = 0, j = 0; i < bank->nr_irqs; i += 32, j += 0x20)
  145. omap_alloc_gc(bank->base_reg + j, i, 32);
  146. nr_of_irqs += bank->nr_irqs;
  147. nr_banks++;
  148. }
  149. printk(KERN_INFO "Total of %ld interrupts on %d active controller%s\n",
  150. nr_of_irqs, nr_banks, nr_banks > 1 ? "s" : "");
  151. }
  152. #ifdef CONFIG_ARCH_OMAP3
  153. static struct omap3_intc_regs intc_context[ARRAY_SIZE(irq_banks)];
  154. void omap_intc_save_context(void)
  155. {
  156. int ind = 0, i = 0;
  157. for (ind = 0; ind < ARRAY_SIZE(irq_banks); ind++) {
  158. struct omap_irq_bank *bank = irq_banks + ind;
  159. intc_context[ind].sysconfig =
  160. intc_bank_read_reg(bank, INTC_SYSCONFIG);
  161. intc_context[ind].protection =
  162. intc_bank_read_reg(bank, INTC_PROTECTION);
  163. intc_context[ind].idle =
  164. intc_bank_read_reg(bank, INTC_IDLE);
  165. intc_context[ind].threshold =
  166. intc_bank_read_reg(bank, INTC_THRESHOLD);
  167. for (i = 0; i < INTCPS_NR_IRQS; i++)
  168. intc_context[ind].ilr[i] =
  169. intc_bank_read_reg(bank, (0x100 + 0x4*i));
  170. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  171. intc_context[ind].mir[i] =
  172. intc_bank_read_reg(&irq_banks[0], INTC_MIR0 +
  173. (0x20 * i));
  174. }
  175. }
  176. void omap_intc_restore_context(void)
  177. {
  178. int ind = 0, i = 0;
  179. for (ind = 0; ind < ARRAY_SIZE(irq_banks); ind++) {
  180. struct omap_irq_bank *bank = irq_banks + ind;
  181. intc_bank_write_reg(intc_context[ind].sysconfig,
  182. bank, INTC_SYSCONFIG);
  183. intc_bank_write_reg(intc_context[ind].sysconfig,
  184. bank, INTC_SYSCONFIG);
  185. intc_bank_write_reg(intc_context[ind].protection,
  186. bank, INTC_PROTECTION);
  187. intc_bank_write_reg(intc_context[ind].idle,
  188. bank, INTC_IDLE);
  189. intc_bank_write_reg(intc_context[ind].threshold,
  190. bank, INTC_THRESHOLD);
  191. for (i = 0; i < INTCPS_NR_IRQS; i++)
  192. intc_bank_write_reg(intc_context[ind].ilr[i],
  193. bank, (0x100 + 0x4*i));
  194. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  195. intc_bank_write_reg(intc_context[ind].mir[i],
  196. &irq_banks[0], INTC_MIR0 + (0x20 * i));
  197. }
  198. /* MIRs are saved and restore with other PRCM registers */
  199. }
  200. void omap3_intc_suspend(void)
  201. {
  202. /* A pending interrupt would prevent OMAP from entering suspend */
  203. omap_ack_irq(0);
  204. }
  205. void omap3_intc_prepare_idle(void)
  206. {
  207. /*
  208. * Disable autoidle as it can stall interrupt controller,
  209. * cf. errata ID i540 for 3430 (all revisions up to 3.1.x)
  210. */
  211. intc_bank_write_reg(0, &irq_banks[0], INTC_SYSCONFIG);
  212. }
  213. void omap3_intc_resume_idle(void)
  214. {
  215. /* Re-enable autoidle */
  216. intc_bank_write_reg(1, &irq_banks[0], INTC_SYSCONFIG);
  217. }
  218. #endif /* CONFIG_ARCH_OMAP3 */