irq.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* -------------------------------------------------------------------- */
  2. /* setup_voyagergx.c: */
  3. /* -------------------------------------------------------------------- */
  4. /* This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. Copyright 2003 (c) Lineo uSolutions,Inc.
  16. */
  17. #include <linux/interrupt.h>
  18. #include <linux/init.h>
  19. #include <linux/io.h>
  20. #include <asm/voyagergx.h>
  21. #include <asm/rts7751r2d.h>
  22. static void disable_voyagergx_irq(unsigned int irq)
  23. {
  24. unsigned long val;
  25. unsigned long mask = 1 << (irq - VOYAGER_IRQ_BASE);
  26. pr_debug("disable_voyagergx_irq(%d): mask=%lx\n", irq, mask);
  27. val = readl((void __iomem *)VOYAGER_INT_MASK);
  28. val &= ~mask;
  29. writel(val, (void __iomem *)VOYAGER_INT_MASK);
  30. }
  31. static void enable_voyagergx_irq(unsigned int irq)
  32. {
  33. unsigned long val;
  34. unsigned long mask = 1 << (irq - VOYAGER_IRQ_BASE);
  35. pr_debug("disable_voyagergx_irq(%d): mask=%lx\n", irq, mask);
  36. val = readl((void __iomem *)VOYAGER_INT_MASK);
  37. val |= mask;
  38. writel(val, (void __iomem *)VOYAGER_INT_MASK);
  39. }
  40. static void mask_and_ack_voyagergx(unsigned int irq)
  41. {
  42. disable_voyagergx_irq(irq);
  43. }
  44. static void end_voyagergx_irq(unsigned int irq)
  45. {
  46. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  47. enable_voyagergx_irq(irq);
  48. }
  49. static unsigned int startup_voyagergx_irq(unsigned int irq)
  50. {
  51. enable_voyagergx_irq(irq);
  52. return 0;
  53. }
  54. static void shutdown_voyagergx_irq(unsigned int irq)
  55. {
  56. disable_voyagergx_irq(irq);
  57. }
  58. static struct hw_interrupt_type voyagergx_irq_type = {
  59. .typename = "VOYAGERGX-IRQ",
  60. .startup = startup_voyagergx_irq,
  61. .shutdown = shutdown_voyagergx_irq,
  62. .enable = enable_voyagergx_irq,
  63. .disable = disable_voyagergx_irq,
  64. .ack = mask_and_ack_voyagergx,
  65. .end = end_voyagergx_irq,
  66. };
  67. static irqreturn_t voyagergx_interrupt(int irq, void *dev_id)
  68. {
  69. printk(KERN_INFO
  70. "VoyagerGX: spurious interrupt, status: 0x%x\n",
  71. (unsigned int)readl((void __iomem *)INT_STATUS));
  72. return IRQ_HANDLED;
  73. }
  74. static struct {
  75. int (*func)(int, void *);
  76. void *dev;
  77. } voyagergx_demux[VOYAGER_IRQ_NUM];
  78. void voyagergx_register_irq_demux(int irq,
  79. int (*demux)(int irq, void *dev), void *dev)
  80. {
  81. voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = demux;
  82. voyagergx_demux[irq - VOYAGER_IRQ_BASE].dev = dev;
  83. }
  84. void voyagergx_unregister_irq_demux(int irq)
  85. {
  86. voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = 0;
  87. }
  88. int voyagergx_irq_demux(int irq)
  89. {
  90. if (irq == IRQ_VOYAGER ) {
  91. unsigned long i = 0, bit __attribute__ ((unused));
  92. unsigned long val = readl((void __iomem *)INT_STATUS);
  93. if (val & (1 << 1))
  94. i = 1;
  95. else if (val & (1 << 2))
  96. i = 2;
  97. else if (val & (1 << 6))
  98. i = 6;
  99. else if (val & (1 << 10))
  100. i = 10;
  101. else if (val & (1 << 11))
  102. i = 11;
  103. else if (val & (1 << 12))
  104. i = 12;
  105. else if (val & (1 << 17))
  106. i = 17;
  107. else
  108. printk("Unexpected IRQ irq = %d status = 0x%08lx\n", irq, val);
  109. pr_debug("voyagergx_irq_demux %ld \n", i);
  110. if (i < VOYAGER_IRQ_NUM) {
  111. irq = VOYAGER_IRQ_BASE + i;
  112. if (voyagergx_demux[i].func != 0)
  113. irq = voyagergx_demux[i].func(irq,
  114. voyagergx_demux[i].dev);
  115. }
  116. }
  117. return irq;
  118. }
  119. static struct irqaction irq0 = {
  120. .name = "voyagergx",
  121. .handler = voyagergx_interrupt,
  122. .flags = IRQF_DISABLED,
  123. .mask = CPU_MASK_NONE,
  124. };
  125. void __init setup_voyagergx_irq(void)
  126. {
  127. int i, flag;
  128. printk(KERN_INFO "VoyagerGX configured at 0x%x on irq %d(mapped into %d to %d)\n",
  129. VOYAGER_BASE,
  130. IRQ_VOYAGER,
  131. VOYAGER_IRQ_BASE,
  132. VOYAGER_IRQ_BASE + VOYAGER_IRQ_NUM - 1);
  133. for (i=0; i<VOYAGER_IRQ_NUM; i++) {
  134. flag = 0;
  135. switch (VOYAGER_IRQ_BASE + i) {
  136. case VOYAGER_USBH_IRQ:
  137. case VOYAGER_8051_IRQ:
  138. case VOYAGER_UART0_IRQ:
  139. case VOYAGER_UART1_IRQ:
  140. case VOYAGER_AC97_IRQ:
  141. flag = 1;
  142. }
  143. if (flag == 1)
  144. irq_desc[VOYAGER_IRQ_BASE + i].chip = &voyagergx_irq_type;
  145. }
  146. setup_irq(IRQ_VOYAGER, &irq0);
  147. }