irq.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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(unsigned int irq)
  37. {
  38. void __iomem *base = ic_regbase;
  39. u8 edge;
  40. if (irq >= 64) {
  41. base = sic_regbase;
  42. irq -= 64;
  43. }
  44. edge = readb(base + VT8500_IC_DCTR + irq) & VT8500_EDGE;
  45. if (edge) {
  46. void __iomem *stat_reg = base + VT8500_IC_STATUS
  47. + (irq < 32 ? 0 : 4);
  48. unsigned status = readl(stat_reg);
  49. status |= (1 << (irq & 0x1f));
  50. writel(status, stat_reg);
  51. } else {
  52. u8 dctr = readb(base + VT8500_IC_DCTR + irq);
  53. dctr &= ~VT8500_INT_ENABLE;
  54. writeb(dctr, base + VT8500_IC_DCTR + irq);
  55. }
  56. }
  57. static void vt8500_irq_unmask(unsigned int irq)
  58. {
  59. void __iomem *base = ic_regbase;
  60. u8 dctr;
  61. if (irq >= 64) {
  62. base = sic_regbase;
  63. irq -= 64;
  64. }
  65. dctr = readb(base + VT8500_IC_DCTR + irq);
  66. dctr |= VT8500_INT_ENABLE;
  67. writeb(dctr, base + VT8500_IC_DCTR + irq);
  68. }
  69. static int vt8500_irq_set_type(unsigned int irq, unsigned int flow_type)
  70. {
  71. void __iomem *base = ic_regbase;
  72. unsigned int orig_irq = irq;
  73. u8 dctr;
  74. if (irq >= 64) {
  75. base = sic_regbase;
  76. irq -= 64;
  77. }
  78. dctr = readb(base + VT8500_IC_DCTR + irq);
  79. dctr &= ~VT8500_EDGE;
  80. switch (flow_type) {
  81. case IRQF_TRIGGER_LOW:
  82. return -EINVAL;
  83. case IRQF_TRIGGER_HIGH:
  84. dctr |= VT8500_TRIGGER_HIGH;
  85. __irq_set_handler_locked(orig_irq, handle_level_irq);
  86. break;
  87. case IRQF_TRIGGER_FALLING:
  88. dctr |= VT8500_TRIGGER_FALLING;
  89. __irq_set_handler_locked(orig_irq, handle_edge_irq);
  90. break;
  91. case IRQF_TRIGGER_RISING:
  92. dctr |= VT8500_TRIGGER_RISING;
  93. __irq_set_handler_locked(orig_irq, handle_edge_irq);
  94. break;
  95. }
  96. writeb(dctr, base + VT8500_IC_DCTR + irq);
  97. return 0;
  98. }
  99. static struct irq_chip vt8500_irq_chip = {
  100. .name = "vt8500",
  101. .ack = vt8500_irq_mask,
  102. .mask = vt8500_irq_mask,
  103. .unmask = vt8500_irq_unmask,
  104. .set_type = vt8500_irq_set_type,
  105. };
  106. void __init vt8500_init_irq(void)
  107. {
  108. unsigned int i;
  109. ic_regbase = ioremap(wmt_ic_base, SZ_64K);
  110. if (ic_regbase) {
  111. /* Enable rotating priority for IRQ */
  112. writel((1 << 6), ic_regbase + 0x20);
  113. writel(0, ic_regbase + 0x24);
  114. for (i = 0; i < wmt_nr_irqs; i++) {
  115. /* Disable all interrupts and route them to IRQ */
  116. writeb(0x00, ic_regbase + VT8500_IC_DCTR + i);
  117. irq_set_chip_and_handler(i, &vt8500_irq_chip,
  118. handle_level_irq);
  119. set_irq_flags(i, IRQF_VALID);
  120. }
  121. } else {
  122. printk(KERN_ERR "Unable to remap the Interrupt Controller registers, not enabling IRQs!\n");
  123. }
  124. }
  125. void __init wm8505_init_irq(void)
  126. {
  127. unsigned int i;
  128. ic_regbase = ioremap(wmt_ic_base, SZ_64K);
  129. sic_regbase = ioremap(wmt_sic_base, SZ_64K);
  130. if (ic_regbase && sic_regbase) {
  131. /* Enable rotating priority for IRQ */
  132. writel((1 << 6), ic_regbase + 0x20);
  133. writel(0, ic_regbase + 0x24);
  134. writel((1 << 6), sic_regbase + 0x20);
  135. writel(0, sic_regbase + 0x24);
  136. for (i = 0; i < wmt_nr_irqs; i++) {
  137. /* Disable all interrupts and route them to IRQ */
  138. if (i < 64)
  139. writeb(0x00, ic_regbase + VT8500_IC_DCTR + i);
  140. else
  141. writeb(0x00, sic_regbase + VT8500_IC_DCTR
  142. + i - 64);
  143. irq_set_chip_and_handler(i, &vt8500_irq_chip,
  144. handle_level_irq);
  145. set_irq_flags(i, IRQF_VALID);
  146. }
  147. } else {
  148. printk(KERN_ERR "Unable to remap the Interrupt Controller registers, not enabling IRQs!\n");
  149. }
  150. }