irq.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * arch/arm/mach-vt8500/irq.c
  3. *
  4. * Copyright (C) 2010 Alexey Charkov <alchark@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/io.h>
  21. #include <linux/irq.h>
  22. #include <linux/interrupt.h>
  23. #include <asm/irq.h>
  24. #include "devices.h"
  25. #define VT8500_IC_DCTR 0x40 /* Destination control
  26. register, 64*u8 */
  27. #define VT8500_INT_ENABLE (1 << 3)
  28. #define VT8500_TRIGGER_HIGH (0 << 4)
  29. #define VT8500_TRIGGER_RISING (1 << 4)
  30. #define VT8500_TRIGGER_FALLING (2 << 4)
  31. #define VT8500_EDGE ( VT8500_TRIGGER_RISING \
  32. | VT8500_TRIGGER_FALLING)
  33. #define VT8500_IC_STATUS 0x80 /* Interrupt status, 2*u32 */
  34. static void __iomem *ic_regbase;
  35. static void __iomem *sic_regbase;
  36. static void vt8500_irq_mask(struct irq_data *d)
  37. {
  38. void __iomem *base = ic_regbase;
  39. unsigned irq = d->irq;
  40. u8 edge;
  41. if (irq >= 64) {
  42. base = sic_regbase;
  43. irq -= 64;
  44. }
  45. edge = readb(base + VT8500_IC_DCTR + irq) & VT8500_EDGE;
  46. if (edge) {
  47. void __iomem *stat_reg = base + VT8500_IC_STATUS
  48. + (irq < 32 ? 0 : 4);
  49. unsigned status = readl(stat_reg);
  50. status |= (1 << (irq & 0x1f));
  51. writel(status, stat_reg);
  52. } else {
  53. u8 dctr = readb(base + VT8500_IC_DCTR + irq);
  54. dctr &= ~VT8500_INT_ENABLE;
  55. writeb(dctr, base + VT8500_IC_DCTR + irq);
  56. }
  57. }
  58. static void vt8500_irq_unmask(struct irq_data *d)
  59. {
  60. void __iomem *base = ic_regbase;
  61. unsigned irq = d->irq;
  62. u8 dctr;
  63. if (irq >= 64) {
  64. base = sic_regbase;
  65. irq -= 64;
  66. }
  67. dctr = readb(base + VT8500_IC_DCTR + irq);
  68. dctr |= VT8500_INT_ENABLE;
  69. writeb(dctr, base + VT8500_IC_DCTR + irq);
  70. }
  71. static int vt8500_irq_set_type(struct irq_data *d, unsigned int flow_type)
  72. {
  73. void __iomem *base = ic_regbase;
  74. unsigned irq = d->irq;
  75. unsigned orig_irq = irq;
  76. u8 dctr;
  77. if (irq >= 64) {
  78. base = sic_regbase;
  79. irq -= 64;
  80. }
  81. dctr = readb(base + VT8500_IC_DCTR + irq);
  82. dctr &= ~VT8500_EDGE;
  83. switch (flow_type) {
  84. case IRQF_TRIGGER_LOW:
  85. return -EINVAL;
  86. case IRQF_TRIGGER_HIGH:
  87. dctr |= VT8500_TRIGGER_HIGH;
  88. __irq_set_handler_locked(orig_irq, handle_level_irq);
  89. break;
  90. case IRQF_TRIGGER_FALLING:
  91. dctr |= VT8500_TRIGGER_FALLING;
  92. __irq_set_handler_locked(orig_irq, handle_edge_irq);
  93. break;
  94. case IRQF_TRIGGER_RISING:
  95. dctr |= VT8500_TRIGGER_RISING;
  96. __irq_set_handler_locked(orig_irq, handle_edge_irq);
  97. break;
  98. }
  99. writeb(dctr, base + VT8500_IC_DCTR + irq);
  100. return 0;
  101. }
  102. static struct irq_chip vt8500_irq_chip = {
  103. .name = "vt8500",
  104. .irq_ack = vt8500_irq_mask,
  105. .irq_mask = vt8500_irq_mask,
  106. .irq_unmask = vt8500_irq_unmask,
  107. .irq_set_type = vt8500_irq_set_type,
  108. };
  109. void __init vt8500_init_irq(void)
  110. {
  111. unsigned int i;
  112. ic_regbase = ioremap(wmt_ic_base, SZ_64K);
  113. if (ic_regbase) {
  114. /* Enable rotating priority for IRQ */
  115. writel((1 << 6), ic_regbase + 0x20);
  116. writel(0, ic_regbase + 0x24);
  117. for (i = 0; i < wmt_nr_irqs; i++) {
  118. /* Disable all interrupts and route them to IRQ */
  119. writeb(0x00, ic_regbase + VT8500_IC_DCTR + i);
  120. irq_set_chip_and_handler(i, &vt8500_irq_chip,
  121. handle_level_irq);
  122. set_irq_flags(i, IRQF_VALID);
  123. }
  124. } else {
  125. printk(KERN_ERR "Unable to remap the Interrupt Controller registers, not enabling IRQs!\n");
  126. }
  127. }
  128. void __init wm8505_init_irq(void)
  129. {
  130. unsigned int i;
  131. ic_regbase = ioremap(wmt_ic_base, SZ_64K);
  132. sic_regbase = ioremap(wmt_sic_base, SZ_64K);
  133. if (ic_regbase && sic_regbase) {
  134. /* Enable rotating priority for IRQ */
  135. writel((1 << 6), ic_regbase + 0x20);
  136. writel(0, ic_regbase + 0x24);
  137. writel((1 << 6), sic_regbase + 0x20);
  138. writel(0, sic_regbase + 0x24);
  139. for (i = 0; i < wmt_nr_irqs; i++) {
  140. /* Disable all interrupts and route them to IRQ */
  141. if (i < 64)
  142. writeb(0x00, ic_regbase + VT8500_IC_DCTR + i);
  143. else
  144. writeb(0x00, sic_regbase + VT8500_IC_DCTR
  145. + i - 64);
  146. irq_set_chip_and_handler(i, &vt8500_irq_chip,
  147. handle_level_irq);
  148. set_irq_flags(i, IRQF_VALID);
  149. }
  150. } else {
  151. printk(KERN_ERR "Unable to remap the Interrupt Controller registers, not enabling IRQs!\n");
  152. }
  153. }