irq.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* linux/arch/arm/mach-msm/irq.c
  2. *
  3. * Copyright (C) 2007 Google, Inc.
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #include <linux/init.h>
  16. #include <linux/module.h>
  17. #include <linux/sched.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/ptrace.h>
  20. #include <linux/timer.h>
  21. #include <linux/irq.h>
  22. #include <linux/io.h>
  23. #include <mach/hardware.h>
  24. #include <mach/msm_iomap.h>
  25. #define VIC_REG(off) (MSM_VIC_BASE + (off))
  26. #define VIC_INT_SELECT0 VIC_REG(0x0000) /* 1: FIQ, 0: IRQ */
  27. #define VIC_INT_SELECT1 VIC_REG(0x0004) /* 1: FIQ, 0: IRQ */
  28. #define VIC_INT_EN0 VIC_REG(0x0010)
  29. #define VIC_INT_EN1 VIC_REG(0x0014)
  30. #define VIC_INT_ENCLEAR0 VIC_REG(0x0020)
  31. #define VIC_INT_ENCLEAR1 VIC_REG(0x0024)
  32. #define VIC_INT_ENSET0 VIC_REG(0x0030)
  33. #define VIC_INT_ENSET1 VIC_REG(0x0034)
  34. #define VIC_INT_TYPE0 VIC_REG(0x0040) /* 1: EDGE, 0: LEVEL */
  35. #define VIC_INT_TYPE1 VIC_REG(0x0044) /* 1: EDGE, 0: LEVEL */
  36. #define VIC_INT_POLARITY0 VIC_REG(0x0050) /* 1: NEG, 0: POS */
  37. #define VIC_INT_POLARITY1 VIC_REG(0x0054) /* 1: NEG, 0: POS */
  38. #define VIC_NO_PEND_VAL VIC_REG(0x0060)
  39. #define VIC_INT_MASTEREN VIC_REG(0x0064) /* 1: IRQ, 2: FIQ */
  40. #define VIC_PROTECTION VIC_REG(0x006C) /* 1: ENABLE */
  41. #define VIC_CONFIG VIC_REG(0x0068) /* 1: USE ARM1136 VIC */
  42. #define VIC_IRQ_STATUS0 VIC_REG(0x0080)
  43. #define VIC_IRQ_STATUS1 VIC_REG(0x0084)
  44. #define VIC_FIQ_STATUS0 VIC_REG(0x0090)
  45. #define VIC_FIQ_STATUS1 VIC_REG(0x0094)
  46. #define VIC_RAW_STATUS0 VIC_REG(0x00A0)
  47. #define VIC_RAW_STATUS1 VIC_REG(0x00A4)
  48. #define VIC_INT_CLEAR0 VIC_REG(0x00B0)
  49. #define VIC_INT_CLEAR1 VIC_REG(0x00B4)
  50. #define VIC_SOFTINT0 VIC_REG(0x00C0)
  51. #define VIC_SOFTINT1 VIC_REG(0x00C4)
  52. #define VIC_IRQ_VEC_RD VIC_REG(0x00D0) /* pending int # */
  53. #define VIC_IRQ_VEC_PEND_RD VIC_REG(0x00D4) /* pending vector addr */
  54. #define VIC_IRQ_VEC_WR VIC_REG(0x00D8)
  55. #define VIC_IRQ_IN_SERVICE VIC_REG(0x00E0)
  56. #define VIC_IRQ_IN_STACK VIC_REG(0x00E4)
  57. #define VIC_TEST_BUS_SEL VIC_REG(0x00E8)
  58. #define VIC_VECTPRIORITY(n) VIC_REG(0x0200+((n) * 4))
  59. #define VIC_VECTADDR(n) VIC_REG(0x0400+((n) * 4))
  60. static void msm_irq_ack(struct irq_data *d)
  61. {
  62. void __iomem *reg = VIC_INT_CLEAR0 + ((d->irq & 32) ? 4 : 0);
  63. writel(1 << (d->irq & 31), reg);
  64. }
  65. static void msm_irq_mask(struct irq_data *d)
  66. {
  67. void __iomem *reg = VIC_INT_ENCLEAR0 + ((d->irq & 32) ? 4 : 0);
  68. writel(1 << (d->irq & 31), reg);
  69. }
  70. static void msm_irq_unmask(struct irq_data *d)
  71. {
  72. void __iomem *reg = VIC_INT_ENSET0 + ((d->irq & 32) ? 4 : 0);
  73. writel(1 << (d->irq & 31), reg);
  74. }
  75. static int msm_irq_set_wake(struct irq_data *d, unsigned int on)
  76. {
  77. return -EINVAL;
  78. }
  79. static int msm_irq_set_type(struct irq_data *d, unsigned int flow_type)
  80. {
  81. void __iomem *treg = VIC_INT_TYPE0 + ((d->irq & 32) ? 4 : 0);
  82. void __iomem *preg = VIC_INT_POLARITY0 + ((d->irq & 32) ? 4 : 0);
  83. int b = 1 << (d->irq & 31);
  84. if (flow_type & (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_LOW))
  85. writel(readl(preg) | b, preg);
  86. if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_HIGH))
  87. writel(readl(preg) & (~b), preg);
  88. if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) {
  89. writel(readl(treg) | b, treg);
  90. __irq_set_handler_locked(d->irq, handle_edge_irq);
  91. }
  92. if (flow_type & (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW)) {
  93. writel(readl(treg) & (~b), treg);
  94. __irq_set_handler_locked(d->irq, handle_level_irq);
  95. }
  96. return 0;
  97. }
  98. static struct irq_chip msm_irq_chip = {
  99. .name = "msm",
  100. .irq_ack = msm_irq_ack,
  101. .irq_mask = msm_irq_mask,
  102. .irq_unmask = msm_irq_unmask,
  103. .irq_set_wake = msm_irq_set_wake,
  104. .irq_set_type = msm_irq_set_type,
  105. };
  106. void __init msm_init_irq(void)
  107. {
  108. unsigned n;
  109. /* select level interrupts */
  110. writel(0, VIC_INT_TYPE0);
  111. writel(0, VIC_INT_TYPE1);
  112. /* select highlevel interrupts */
  113. writel(0, VIC_INT_POLARITY0);
  114. writel(0, VIC_INT_POLARITY1);
  115. /* select IRQ for all INTs */
  116. writel(0, VIC_INT_SELECT0);
  117. writel(0, VIC_INT_SELECT1);
  118. /* disable all INTs */
  119. writel(0, VIC_INT_EN0);
  120. writel(0, VIC_INT_EN1);
  121. /* don't use 1136 vic */
  122. writel(0, VIC_CONFIG);
  123. /* enable interrupt controller */
  124. writel(1, VIC_INT_MASTEREN);
  125. for (n = 0; n < NR_MSM_IRQS; n++) {
  126. irq_set_chip_and_handler(n, &msm_irq_chip, handle_level_irq);
  127. set_irq_flags(n, IRQF_VALID);
  128. }
  129. }