irq.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Interrupt handler for DaVinci boards.
  3. *
  4. * Copyright (C) 2006 Texas Instruments.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. *
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/irq.h>
  25. #include <linux/io.h>
  26. #include <mach/hardware.h>
  27. #include <mach/cputype.h>
  28. #include <mach/common.h>
  29. #include <asm/mach/irq.h>
  30. #define IRQ_BIT(irq) ((irq) & 0x1f)
  31. #define FIQ_REG0_OFFSET 0x0000
  32. #define FIQ_REG1_OFFSET 0x0004
  33. #define IRQ_REG0_OFFSET 0x0008
  34. #define IRQ_REG1_OFFSET 0x000C
  35. #define IRQ_ENT_REG0_OFFSET 0x0018
  36. #define IRQ_ENT_REG1_OFFSET 0x001C
  37. #define IRQ_INCTL_REG_OFFSET 0x0020
  38. #define IRQ_EABASE_REG_OFFSET 0x0024
  39. #define IRQ_INTPRI0_REG_OFFSET 0x0030
  40. #define IRQ_INTPRI7_REG_OFFSET 0x004C
  41. static inline unsigned int davinci_irq_readl(int offset)
  42. {
  43. return __raw_readl(davinci_intc_base + offset);
  44. }
  45. static inline void davinci_irq_writel(unsigned long value, int offset)
  46. {
  47. __raw_writel(value, davinci_intc_base + offset);
  48. }
  49. /* Disable interrupt */
  50. static void davinci_mask_irq(unsigned int irq)
  51. {
  52. unsigned int mask;
  53. u32 l;
  54. mask = 1 << IRQ_BIT(irq);
  55. if (irq > 31) {
  56. l = davinci_irq_readl(IRQ_ENT_REG1_OFFSET);
  57. l &= ~mask;
  58. davinci_irq_writel(l, IRQ_ENT_REG1_OFFSET);
  59. } else {
  60. l = davinci_irq_readl(IRQ_ENT_REG0_OFFSET);
  61. l &= ~mask;
  62. davinci_irq_writel(l, IRQ_ENT_REG0_OFFSET);
  63. }
  64. }
  65. /* Enable interrupt */
  66. static void davinci_unmask_irq(unsigned int irq)
  67. {
  68. unsigned int mask;
  69. u32 l;
  70. mask = 1 << IRQ_BIT(irq);
  71. if (irq > 31) {
  72. l = davinci_irq_readl(IRQ_ENT_REG1_OFFSET);
  73. l |= mask;
  74. davinci_irq_writel(l, IRQ_ENT_REG1_OFFSET);
  75. } else {
  76. l = davinci_irq_readl(IRQ_ENT_REG0_OFFSET);
  77. l |= mask;
  78. davinci_irq_writel(l, IRQ_ENT_REG0_OFFSET);
  79. }
  80. }
  81. /* EOI interrupt */
  82. static void davinci_ack_irq(unsigned int irq)
  83. {
  84. unsigned int mask;
  85. mask = 1 << IRQ_BIT(irq);
  86. if (irq > 31)
  87. davinci_irq_writel(mask, IRQ_REG1_OFFSET);
  88. else
  89. davinci_irq_writel(mask, IRQ_REG0_OFFSET);
  90. }
  91. static struct irq_chip davinci_irq_chip_0 = {
  92. .name = "AINTC",
  93. .ack = davinci_ack_irq,
  94. .mask = davinci_mask_irq,
  95. .unmask = davinci_unmask_irq,
  96. };
  97. /* ARM Interrupt Controller Initialization */
  98. void __init davinci_irq_init(void)
  99. {
  100. unsigned i;
  101. const u8 *davinci_def_priorities = davinci_soc_info.intc_irq_prios;
  102. davinci_intc_type = DAVINCI_INTC_TYPE_AINTC;
  103. davinci_intc_base = ioremap(davinci_soc_info.intc_base, SZ_4K);
  104. if (WARN_ON(!davinci_intc_base))
  105. return;
  106. /* Clear all interrupt requests */
  107. davinci_irq_writel(~0x0, FIQ_REG0_OFFSET);
  108. davinci_irq_writel(~0x0, FIQ_REG1_OFFSET);
  109. davinci_irq_writel(~0x0, IRQ_REG0_OFFSET);
  110. davinci_irq_writel(~0x0, IRQ_REG1_OFFSET);
  111. /* Disable all interrupts */
  112. davinci_irq_writel(0x0, IRQ_ENT_REG0_OFFSET);
  113. davinci_irq_writel(0x0, IRQ_ENT_REG1_OFFSET);
  114. /* Interrupts disabled immediately, IRQ entry reflects all */
  115. davinci_irq_writel(0x0, IRQ_INCTL_REG_OFFSET);
  116. /* we don't use the hardware vector table, just its entry addresses */
  117. davinci_irq_writel(0, IRQ_EABASE_REG_OFFSET);
  118. /* Clear all interrupt requests */
  119. davinci_irq_writel(~0x0, FIQ_REG0_OFFSET);
  120. davinci_irq_writel(~0x0, FIQ_REG1_OFFSET);
  121. davinci_irq_writel(~0x0, IRQ_REG0_OFFSET);
  122. davinci_irq_writel(~0x0, IRQ_REG1_OFFSET);
  123. for (i = IRQ_INTPRI0_REG_OFFSET; i <= IRQ_INTPRI7_REG_OFFSET; i += 4) {
  124. unsigned j;
  125. u32 pri;
  126. for (j = 0, pri = 0; j < 32; j += 4, davinci_def_priorities++)
  127. pri |= (*davinci_def_priorities & 0x07) << j;
  128. davinci_irq_writel(pri, i);
  129. }
  130. /* set up genirq dispatch for ARM INTC */
  131. for (i = 0; i < davinci_soc_info.intc_irq_num; i++) {
  132. set_irq_chip(i, &davinci_irq_chip_0);
  133. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  134. if (i != IRQ_TINT1_TINT34)
  135. set_irq_handler(i, handle_edge_irq);
  136. else
  137. set_irq_handler(i, handle_level_irq);
  138. }
  139. }