irq.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * arch/arm/mach-dove/irq.c
  3. *
  4. * Dove IRQ handling.
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/irq.h>
  13. #include <linux/gpio.h>
  14. #include <linux/io.h>
  15. #include <asm/mach/arch.h>
  16. #include <plat/irq.h>
  17. #include <asm/mach/irq.h>
  18. #include <mach/pm.h>
  19. #include <mach/bridge-regs.h>
  20. #include <plat/orion-gpio.h>
  21. #include "common.h"
  22. static void pmu_irq_mask(struct irq_data *d)
  23. {
  24. int pin = irq_to_pmu(d->irq);
  25. u32 u;
  26. u = readl(PMU_INTERRUPT_MASK);
  27. u &= ~(1 << (pin & 31));
  28. writel(u, PMU_INTERRUPT_MASK);
  29. }
  30. static void pmu_irq_unmask(struct irq_data *d)
  31. {
  32. int pin = irq_to_pmu(d->irq);
  33. u32 u;
  34. u = readl(PMU_INTERRUPT_MASK);
  35. u |= 1 << (pin & 31);
  36. writel(u, PMU_INTERRUPT_MASK);
  37. }
  38. static void pmu_irq_ack(struct irq_data *d)
  39. {
  40. int pin = irq_to_pmu(d->irq);
  41. u32 u;
  42. /*
  43. * The PMU mask register is not RW0C: it is RW. This means that
  44. * the bits take whatever value is written to them; if you write
  45. * a '1', you will set the interrupt.
  46. *
  47. * Unfortunately this means there is NO race free way to clear
  48. * these interrupts.
  49. *
  50. * So, let's structure the code so that the window is as small as
  51. * possible.
  52. */
  53. u = ~(1 << (pin & 31));
  54. u &= readl_relaxed(PMU_INTERRUPT_CAUSE);
  55. writel_relaxed(u, PMU_INTERRUPT_CAUSE);
  56. }
  57. static struct irq_chip pmu_irq_chip = {
  58. .name = "pmu_irq",
  59. .irq_mask = pmu_irq_mask,
  60. .irq_unmask = pmu_irq_unmask,
  61. .irq_ack = pmu_irq_ack,
  62. };
  63. static void pmu_irq_handler(struct irq_desc *desc)
  64. {
  65. unsigned long cause = readl(PMU_INTERRUPT_CAUSE);
  66. unsigned int irq;
  67. cause &= readl(PMU_INTERRUPT_MASK);
  68. if (cause == 0) {
  69. do_bad_IRQ(desc);
  70. return;
  71. }
  72. for (irq = 0; irq < NR_PMU_IRQS; irq++) {
  73. if (!(cause & (1 << irq)))
  74. continue;
  75. irq = pmu_to_irq(irq);
  76. generic_handle_irq(irq);
  77. }
  78. }
  79. static int __initdata gpio0_irqs[4] = {
  80. IRQ_DOVE_GPIO_0_7,
  81. IRQ_DOVE_GPIO_8_15,
  82. IRQ_DOVE_GPIO_16_23,
  83. IRQ_DOVE_GPIO_24_31,
  84. };
  85. static int __initdata gpio1_irqs[4] = {
  86. IRQ_DOVE_HIGH_GPIO,
  87. 0,
  88. 0,
  89. 0,
  90. };
  91. static int __initdata gpio2_irqs[4] = {
  92. 0,
  93. 0,
  94. 0,
  95. 0,
  96. };
  97. #ifdef CONFIG_MULTI_IRQ_HANDLER
  98. /*
  99. * Compiling with both non-DT and DT support enabled, will
  100. * break asm irq handler used by non-DT boards. Therefore,
  101. * we provide a C-style irq handler even for non-DT boards,
  102. * if MULTI_IRQ_HANDLER is set.
  103. */
  104. static void __iomem *dove_irq_base = IRQ_VIRT_BASE;
  105. static asmlinkage void
  106. __exception_irq_entry dove_legacy_handle_irq(struct pt_regs *regs)
  107. {
  108. u32 stat;
  109. stat = readl_relaxed(dove_irq_base + IRQ_CAUSE_LOW_OFF);
  110. stat &= readl_relaxed(dove_irq_base + IRQ_MASK_LOW_OFF);
  111. if (stat) {
  112. unsigned int hwirq = 1 + __fls(stat);
  113. handle_IRQ(hwirq, regs);
  114. return;
  115. }
  116. stat = readl_relaxed(dove_irq_base + IRQ_CAUSE_HIGH_OFF);
  117. stat &= readl_relaxed(dove_irq_base + IRQ_MASK_HIGH_OFF);
  118. if (stat) {
  119. unsigned int hwirq = 33 + __fls(stat);
  120. handle_IRQ(hwirq, regs);
  121. return;
  122. }
  123. }
  124. #endif
  125. void __init dove_init_irq(void)
  126. {
  127. int i;
  128. orion_irq_init(1, IRQ_VIRT_BASE + IRQ_MASK_LOW_OFF);
  129. orion_irq_init(33, IRQ_VIRT_BASE + IRQ_MASK_HIGH_OFF);
  130. #ifdef CONFIG_MULTI_IRQ_HANDLER
  131. set_handle_irq(dove_legacy_handle_irq);
  132. #endif
  133. /*
  134. * Initialize gpiolib for GPIOs 0-71.
  135. */
  136. orion_gpio_init(NULL, 0, 32, DOVE_GPIO_LO_VIRT_BASE, 0,
  137. IRQ_DOVE_GPIO_START, gpio0_irqs);
  138. orion_gpio_init(NULL, 32, 32, DOVE_GPIO_HI_VIRT_BASE, 0,
  139. IRQ_DOVE_GPIO_START + 32, gpio1_irqs);
  140. orion_gpio_init(NULL, 64, 8, DOVE_GPIO2_VIRT_BASE, 0,
  141. IRQ_DOVE_GPIO_START + 64, gpio2_irqs);
  142. /*
  143. * Mask and clear PMU interrupts
  144. */
  145. writel(0, PMU_INTERRUPT_MASK);
  146. writel(0, PMU_INTERRUPT_CAUSE);
  147. for (i = IRQ_DOVE_PMU_START; i < NR_IRQS; i++) {
  148. irq_set_chip_and_handler(i, &pmu_irq_chip, handle_level_irq);
  149. irq_set_status_flags(i, IRQ_LEVEL);
  150. irq_clear_status_flags(i, IRQ_NOREQUEST);
  151. }
  152. irq_set_chained_handler(IRQ_DOVE_PMU, pmu_irq_handler);
  153. }