irq.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 "common.h"
  21. static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
  22. {
  23. int irqoff;
  24. BUG_ON(irq < IRQ_DOVE_GPIO_0_7 || irq > IRQ_DOVE_HIGH_GPIO);
  25. irqoff = irq <= IRQ_DOVE_GPIO_16_23 ? irq - IRQ_DOVE_GPIO_0_7 :
  26. 3 + irq - IRQ_DOVE_GPIO_24_31;
  27. orion_gpio_irq_handler(irqoff << 3);
  28. if (irq == IRQ_DOVE_HIGH_GPIO) {
  29. orion_gpio_irq_handler(40);
  30. orion_gpio_irq_handler(48);
  31. orion_gpio_irq_handler(56);
  32. }
  33. }
  34. static void pmu_irq_mask(struct irq_data *d)
  35. {
  36. int pin = irq_to_pmu(d->irq);
  37. u32 u;
  38. u = readl(PMU_INTERRUPT_MASK);
  39. u &= ~(1 << (pin & 31));
  40. writel(u, PMU_INTERRUPT_MASK);
  41. }
  42. static void pmu_irq_unmask(struct irq_data *d)
  43. {
  44. int pin = irq_to_pmu(d->irq);
  45. u32 u;
  46. u = readl(PMU_INTERRUPT_MASK);
  47. u |= 1 << (pin & 31);
  48. writel(u, PMU_INTERRUPT_MASK);
  49. }
  50. static void pmu_irq_ack(struct irq_data *d)
  51. {
  52. int pin = irq_to_pmu(d->irq);
  53. u32 u;
  54. /*
  55. * The PMU mask register is not RW0C: it is RW. This means that
  56. * the bits take whatever value is written to them; if you write
  57. * a '1', you will set the interrupt.
  58. *
  59. * Unfortunately this means there is NO race free way to clear
  60. * these interrupts.
  61. *
  62. * So, let's structure the code so that the window is as small as
  63. * possible.
  64. */
  65. u = ~(1 << (pin & 31));
  66. u &= readl_relaxed(PMU_INTERRUPT_CAUSE);
  67. writel_relaxed(u, PMU_INTERRUPT_CAUSE);
  68. }
  69. static struct irq_chip pmu_irq_chip = {
  70. .name = "pmu_irq",
  71. .irq_mask = pmu_irq_mask,
  72. .irq_unmask = pmu_irq_unmask,
  73. .irq_ack = pmu_irq_ack,
  74. };
  75. static void pmu_irq_handler(unsigned int irq, struct irq_desc *desc)
  76. {
  77. unsigned long cause = readl(PMU_INTERRUPT_CAUSE);
  78. cause &= readl(PMU_INTERRUPT_MASK);
  79. if (cause == 0) {
  80. do_bad_IRQ(irq, desc);
  81. return;
  82. }
  83. for (irq = 0; irq < NR_PMU_IRQS; irq++) {
  84. if (!(cause & (1 << irq)))
  85. continue;
  86. irq = pmu_to_irq(irq);
  87. generic_handle_irq(irq);
  88. }
  89. }
  90. void __init dove_init_irq(void)
  91. {
  92. int i;
  93. orion_irq_init(0, (void __iomem *)(IRQ_VIRT_BASE + IRQ_MASK_LOW_OFF));
  94. orion_irq_init(32, (void __iomem *)(IRQ_VIRT_BASE + IRQ_MASK_HIGH_OFF));
  95. /*
  96. * Initialize gpiolib for GPIOs 0-71.
  97. */
  98. orion_gpio_init(0, 32, DOVE_GPIO_LO_VIRT_BASE, 0,
  99. IRQ_DOVE_GPIO_START);
  100. irq_set_chained_handler(IRQ_DOVE_GPIO_0_7, gpio_irq_handler);
  101. irq_set_chained_handler(IRQ_DOVE_GPIO_8_15, gpio_irq_handler);
  102. irq_set_chained_handler(IRQ_DOVE_GPIO_16_23, gpio_irq_handler);
  103. irq_set_chained_handler(IRQ_DOVE_GPIO_24_31, gpio_irq_handler);
  104. orion_gpio_init(32, 32, DOVE_GPIO_HI_VIRT_BASE, 0,
  105. IRQ_DOVE_GPIO_START + 32);
  106. irq_set_chained_handler(IRQ_DOVE_HIGH_GPIO, gpio_irq_handler);
  107. orion_gpio_init(64, 8, DOVE_GPIO2_VIRT_BASE, 0,
  108. IRQ_DOVE_GPIO_START + 64);
  109. /*
  110. * Mask and clear PMU interrupts
  111. */
  112. writel(0, PMU_INTERRUPT_MASK);
  113. writel(0, PMU_INTERRUPT_CAUSE);
  114. for (i = IRQ_DOVE_PMU_START; i < NR_IRQS; i++) {
  115. irq_set_chip_and_handler(i, &pmu_irq_chip, handle_level_irq);
  116. irq_set_status_flags(i, IRQ_LEVEL);
  117. set_irq_flags(i, IRQF_VALID);
  118. }
  119. irq_set_chained_handler(IRQ_DOVE_PMU, pmu_irq_handler);
  120. }