sirc.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. static unsigned int save_type;
  39. static unsigned int save_polarity;
  40. /* Mask off the given interrupt. Keep the int_enable mask in sync with
  41. the enable reg, so it can be restored after power collapse. */
  42. static void sirc_irq_mask(unsigned int irq)
  43. {
  44. unsigned int mask;
  45. mask = 1 << (irq - FIRST_SIRC_IRQ);
  46. writel(mask, sirc_regs.int_enable_clear);
  47. int_enable &= ~mask;
  48. return;
  49. }
  50. /* Unmask the given interrupt. Keep the int_enable mask in sync with
  51. the enable reg, so it can be restored after power collapse. */
  52. static void sirc_irq_unmask(unsigned int irq)
  53. {
  54. unsigned int mask;
  55. mask = 1 << (irq - FIRST_SIRC_IRQ);
  56. writel(mask, sirc_regs.int_enable_set);
  57. int_enable |= mask;
  58. return;
  59. }
  60. static void sirc_irq_ack(unsigned int irq)
  61. {
  62. unsigned int mask;
  63. mask = 1 << (irq - FIRST_SIRC_IRQ);
  64. writel(mask, sirc_regs.int_clear);
  65. return;
  66. }
  67. static int sirc_irq_set_wake(unsigned int irq, unsigned int on)
  68. {
  69. unsigned int mask;
  70. /* Used to set the interrupt enable mask during power collapse. */
  71. mask = 1 << (irq - FIRST_SIRC_IRQ);
  72. if (on)
  73. wake_enable |= mask;
  74. else
  75. wake_enable &= ~mask;
  76. return 0;
  77. }
  78. static int sirc_irq_set_type(unsigned int irq, unsigned int flow_type)
  79. {
  80. unsigned int mask;
  81. unsigned int val;
  82. mask = 1 << (irq - FIRST_SIRC_IRQ);
  83. val = readl(sirc_regs.int_polarity);
  84. if (flow_type & (IRQF_TRIGGER_LOW | IRQF_TRIGGER_FALLING))
  85. val |= mask;
  86. else
  87. val &= ~mask;
  88. writel(val, sirc_regs.int_polarity);
  89. val = readl(sirc_regs.int_type);
  90. if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) {
  91. val |= mask;
  92. irq_desc[irq].handle_irq = handle_edge_irq;
  93. } else {
  94. val &= ~mask;
  95. irq_desc[irq].handle_irq = handle_level_irq;
  96. }
  97. writel(val, sirc_regs.int_type);
  98. return 0;
  99. }
  100. /* Finds the pending interrupt on the passed cascade irq and redrives it */
  101. static void sirc_irq_handler(unsigned int irq, struct irq_desc *desc)
  102. {
  103. unsigned int reg = 0;
  104. unsigned int sirq;
  105. unsigned int status;
  106. while ((reg < ARRAY_SIZE(sirc_reg_table)) &&
  107. (sirc_reg_table[reg].cascade_irq != irq))
  108. reg++;
  109. status = readl(sirc_reg_table[reg].int_status);
  110. status &= SIRC_MASK;
  111. if (status == 0)
  112. return;
  113. for (sirq = 0;
  114. (sirq < NR_SIRC_IRQS) && ((status & (1U << sirq)) == 0);
  115. sirq++)
  116. ;
  117. generic_handle_irq(sirq+FIRST_SIRC_IRQ);
  118. desc->chip->ack(irq);
  119. }
  120. static struct irq_chip sirc_irq_chip = {
  121. .name = "sirc",
  122. .ack = sirc_irq_ack,
  123. .mask = sirc_irq_mask,
  124. .unmask = sirc_irq_unmask,
  125. .set_wake = sirc_irq_set_wake,
  126. .set_type = sirc_irq_set_type,
  127. };
  128. void __init msm_init_sirc(void)
  129. {
  130. int i;
  131. int_enable = 0;
  132. wake_enable = 0;
  133. for (i = FIRST_SIRC_IRQ; i < LAST_SIRC_IRQ; i++) {
  134. set_irq_chip(i, &sirc_irq_chip);
  135. set_irq_handler(i, handle_edge_irq);
  136. set_irq_flags(i, IRQF_VALID);
  137. }
  138. for (i = 0; i < ARRAY_SIZE(sirc_reg_table); i++) {
  139. set_irq_chained_handler(sirc_reg_table[i].cascade_irq,
  140. sirc_irq_handler);
  141. set_irq_wake(sirc_reg_table[i].cascade_irq, 1);
  142. }
  143. return;
  144. }