sirc.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* Copyright (c) 2008-2009, Code Aurora Forum. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. * 02110-1301, USA.
  16. *
  17. */
  18. #include <linux/io.h>
  19. #include <linux/irq.h>
  20. #include <linux/interrupt.h>
  21. #include <asm/irq.h>
  22. static unsigned int int_enable;
  23. static unsigned int wake_enable;
  24. static struct sirc_regs_t sirc_regs = {
  25. .int_enable = SPSS_SIRC_INT_ENABLE,
  26. .int_enable_clear = SPSS_SIRC_INT_ENABLE_CLEAR,
  27. .int_enable_set = SPSS_SIRC_INT_ENABLE_SET,
  28. .int_type = SPSS_SIRC_INT_TYPE,
  29. .int_polarity = SPSS_SIRC_INT_POLARITY,
  30. .int_clear = SPSS_SIRC_INT_CLEAR,
  31. };
  32. static struct sirc_cascade_regs sirc_reg_table[] = {
  33. {
  34. .int_status = SPSS_SIRC_IRQ_STATUS,
  35. .cascade_irq = INT_SIRC_0,
  36. }
  37. };
  38. /* Mask off the given interrupt. Keep the int_enable mask in sync with
  39. the enable reg, so it can be restored after power collapse. */
  40. static void sirc_irq_mask(struct irq_data *d)
  41. {
  42. unsigned int mask;
  43. mask = 1 << (d->irq - FIRST_SIRC_IRQ);
  44. writel(mask, sirc_regs.int_enable_clear);
  45. int_enable &= ~mask;
  46. return;
  47. }
  48. /* Unmask the given interrupt. Keep the int_enable mask in sync with
  49. the enable reg, so it can be restored after power collapse. */
  50. static void sirc_irq_unmask(struct irq_data *d)
  51. {
  52. unsigned int mask;
  53. mask = 1 << (d->irq - FIRST_SIRC_IRQ);
  54. writel(mask, sirc_regs.int_enable_set);
  55. int_enable |= mask;
  56. return;
  57. }
  58. static void sirc_irq_ack(struct irq_data *d)
  59. {
  60. unsigned int mask;
  61. mask = 1 << (d->irq - FIRST_SIRC_IRQ);
  62. writel(mask, sirc_regs.int_clear);
  63. return;
  64. }
  65. static int sirc_irq_set_wake(struct irq_data *d, unsigned int on)
  66. {
  67. unsigned int mask;
  68. /* Used to set the interrupt enable mask during power collapse. */
  69. mask = 1 << (d->irq - FIRST_SIRC_IRQ);
  70. if (on)
  71. wake_enable |= mask;
  72. else
  73. wake_enable &= ~mask;
  74. return 0;
  75. }
  76. static int sirc_irq_set_type(struct irq_data *d, unsigned int flow_type)
  77. {
  78. unsigned int mask;
  79. unsigned int val;
  80. mask = 1 << (d->irq - FIRST_SIRC_IRQ);
  81. val = readl(sirc_regs.int_polarity);
  82. if (flow_type & (IRQF_TRIGGER_LOW | IRQF_TRIGGER_FALLING))
  83. val |= mask;
  84. else
  85. val &= ~mask;
  86. writel(val, sirc_regs.int_polarity);
  87. val = readl(sirc_regs.int_type);
  88. if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) {
  89. val |= mask;
  90. __irq_set_handler_locked(d->irq, handle_edge_irq);
  91. } else {
  92. val &= ~mask;
  93. __irq_set_handler_locked(d->irq, handle_level_irq);
  94. }
  95. writel(val, sirc_regs.int_type);
  96. return 0;
  97. }
  98. /* Finds the pending interrupt on the passed cascade irq and redrives it */
  99. static void sirc_irq_handler(unsigned int irq, struct irq_desc *desc)
  100. {
  101. unsigned int reg = 0;
  102. unsigned int sirq;
  103. unsigned int status;
  104. while ((reg < ARRAY_SIZE(sirc_reg_table)) &&
  105. (sirc_reg_table[reg].cascade_irq != irq))
  106. reg++;
  107. status = readl(sirc_reg_table[reg].int_status);
  108. status &= SIRC_MASK;
  109. if (status == 0)
  110. return;
  111. for (sirq = 0;
  112. (sirq < NR_SIRC_IRQS) && ((status & (1U << sirq)) == 0);
  113. sirq++)
  114. ;
  115. generic_handle_irq(sirq+FIRST_SIRC_IRQ);
  116. desc->irq_data.chip->irq_ack(&desc->irq_data);
  117. }
  118. static struct irq_chip sirc_irq_chip = {
  119. .name = "sirc",
  120. .irq_ack = sirc_irq_ack,
  121. .irq_mask = sirc_irq_mask,
  122. .irq_unmask = sirc_irq_unmask,
  123. .irq_set_wake = sirc_irq_set_wake,
  124. .irq_set_type = sirc_irq_set_type,
  125. };
  126. void __init msm_init_sirc(void)
  127. {
  128. int i;
  129. int_enable = 0;
  130. wake_enable = 0;
  131. for (i = FIRST_SIRC_IRQ; i < LAST_SIRC_IRQ; i++) {
  132. irq_set_chip_and_handler(i, &sirc_irq_chip, handle_edge_irq);
  133. set_irq_flags(i, IRQF_VALID);
  134. }
  135. for (i = 0; i < ARRAY_SIZE(sirc_reg_table); i++) {
  136. irq_set_chained_handler(sirc_reg_table[i].cascade_irq,
  137. sirc_irq_handler);
  138. irq_set_irq_wake(sirc_reg_table[i].cascade_irq, 1);
  139. }
  140. return;
  141. }