irq.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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_MIR_CLEAR0 0x0088
  26. #define INTC_MIR_SET0 0x008c
  27. #define INTC_PENDING_IRQ0 0x0098
  28. /* Number of IRQ state bits in each MIR register */
  29. #define IRQ_BITS_PER_REG 32
  30. /*
  31. * OMAP2 has a number of different interrupt controllers, each interrupt
  32. * controller is identified as its own "bank". Register definitions are
  33. * fairly consistent for each bank, but not all registers are implemented
  34. * for each bank.. when in doubt, consult the TRM.
  35. */
  36. static struct omap_irq_bank {
  37. void __iomem *base_reg;
  38. unsigned int nr_irqs;
  39. } __attribute__ ((aligned(4))) irq_banks[] = {
  40. {
  41. /* MPU INTC */
  42. .base_reg = 0,
  43. .nr_irqs = 96,
  44. },
  45. };
  46. /* INTC bank register get/set */
  47. static void intc_bank_write_reg(u32 val, struct omap_irq_bank *bank, u16 reg)
  48. {
  49. __raw_writel(val, bank->base_reg + reg);
  50. }
  51. static u32 intc_bank_read_reg(struct omap_irq_bank *bank, u16 reg)
  52. {
  53. return __raw_readl(bank->base_reg + reg);
  54. }
  55. static int previous_irq;
  56. /*
  57. * On 34xx we can get occasional spurious interrupts if the ack from
  58. * an interrupt handler does not get posted before we unmask. Warn about
  59. * the interrupt handlers that need to flush posted writes.
  60. */
  61. static int omap_check_spurious(unsigned int irq)
  62. {
  63. u32 sir, spurious;
  64. sir = intc_bank_read_reg(&irq_banks[0], INTC_SIR);
  65. spurious = sir >> 6;
  66. if (spurious > 1) {
  67. printk(KERN_WARNING "Spurious irq %i: 0x%08x, please flush "
  68. "posted write for irq %i\n",
  69. irq, sir, previous_irq);
  70. return spurious;
  71. }
  72. return 0;
  73. }
  74. /* XXX: FIQ and additional INTC support (only MPU at the moment) */
  75. static void omap_ack_irq(unsigned int irq)
  76. {
  77. intc_bank_write_reg(0x1, &irq_banks[0], INTC_CONTROL);
  78. }
  79. static void omap_mask_irq(unsigned int irq)
  80. {
  81. int offset = irq & (~(IRQ_BITS_PER_REG - 1));
  82. if (cpu_is_omap34xx()) {
  83. int spurious = 0;
  84. /*
  85. * INT_34XX_GPT12_IRQ is also the spurious irq. Maybe because
  86. * it is the highest irq number?
  87. */
  88. if (irq == INT_34XX_GPT12_IRQ)
  89. spurious = omap_check_spurious(irq);
  90. if (!spurious)
  91. previous_irq = irq;
  92. }
  93. irq &= (IRQ_BITS_PER_REG - 1);
  94. intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_SET0 + offset);
  95. }
  96. static void omap_unmask_irq(unsigned int irq)
  97. {
  98. int offset = irq & (~(IRQ_BITS_PER_REG - 1));
  99. irq &= (IRQ_BITS_PER_REG - 1);
  100. intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_CLEAR0 + offset);
  101. }
  102. static void omap_mask_ack_irq(unsigned int irq)
  103. {
  104. omap_mask_irq(irq);
  105. omap_ack_irq(irq);
  106. }
  107. static struct irq_chip omap_irq_chip = {
  108. .name = "INTC",
  109. .ack = omap_mask_ack_irq,
  110. .mask = omap_mask_irq,
  111. .unmask = omap_unmask_irq,
  112. .disable = omap_mask_irq,
  113. };
  114. static void __init omap_irq_bank_init_one(struct omap_irq_bank *bank)
  115. {
  116. unsigned long tmp;
  117. tmp = intc_bank_read_reg(bank, INTC_REVISION) & 0xff;
  118. printk(KERN_INFO "IRQ: Found an INTC at 0x%p "
  119. "(revision %ld.%ld) with %d interrupts\n",
  120. bank->base_reg, tmp >> 4, tmp & 0xf, bank->nr_irqs);
  121. tmp = intc_bank_read_reg(bank, INTC_SYSCONFIG);
  122. tmp |= 1 << 1; /* soft reset */
  123. intc_bank_write_reg(tmp, bank, INTC_SYSCONFIG);
  124. while (!(intc_bank_read_reg(bank, INTC_SYSSTATUS) & 0x1))
  125. /* Wait for reset to complete */;
  126. /* Enable autoidle */
  127. intc_bank_write_reg(1 << 0, bank, INTC_SYSCONFIG);
  128. }
  129. void __init omap_init_irq(void)
  130. {
  131. unsigned long nr_of_irqs = 0;
  132. unsigned int nr_banks = 0;
  133. int i;
  134. for (i = 0; i < ARRAY_SIZE(irq_banks); i++) {
  135. struct omap_irq_bank *bank = irq_banks + i;
  136. if (cpu_is_omap24xx())
  137. bank->base_reg = OMAP2_IO_ADDRESS(OMAP24XX_IC_BASE);
  138. else if (cpu_is_omap34xx())
  139. bank->base_reg = OMAP2_IO_ADDRESS(OMAP34XX_IC_BASE);
  140. omap_irq_bank_init_one(bank);
  141. nr_of_irqs += bank->nr_irqs;
  142. nr_banks++;
  143. }
  144. printk(KERN_INFO "Total of %ld interrupts on %d active controller%s\n",
  145. nr_of_irqs, nr_banks, nr_banks > 1 ? "s" : "");
  146. for (i = 0; i < nr_of_irqs; i++) {
  147. set_irq_chip(i, &omap_irq_chip);
  148. set_irq_handler(i, handle_level_irq);
  149. set_irq_flags(i, IRQF_VALID);
  150. }
  151. }