irq.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 = inl(VOYAGER_INT_MASK);
  28. val &= ~mask;
  29. outl(val, 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 = inl(VOYAGER_INT_MASK);
  37. val |= mask;
  38. outl(val, 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. inl(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 = inl(INT_STATUS);
  93. #if 1
  94. if ( val & ( 1 << 1 )){
  95. i = 1;
  96. } else if ( val & ( 1 << 2 )){
  97. i = 2;
  98. } else if ( val & ( 1 << 6 )){
  99. i = 6;
  100. } else if( val & ( 1 << 10 )){
  101. i = 10;
  102. } else if( val & ( 1 << 11 )){
  103. i = 11;
  104. } else if( val & ( 1 << 12 )){
  105. i = 12;
  106. } else if( val & ( 1 << 17 )){
  107. i = 17;
  108. } else {
  109. printk("Unexpected IRQ irq = %d status = 0x%08lx\n", irq, val);
  110. }
  111. pr_debug("voyagergx_irq_demux %ld\n", i);
  112. #else
  113. for (bit = 1, i = 0 ; i < VOYAGER_IRQ_NUM ; bit <<= 1, i++)
  114. if (val & bit)
  115. break;
  116. #endif
  117. if (i < VOYAGER_IRQ_NUM) {
  118. irq = VOYAGER_IRQ_BASE + i;
  119. if (voyagergx_demux[i].func != 0)
  120. irq = voyagergx_demux[i].func(irq, voyagergx_demux[i].dev);
  121. }
  122. }
  123. return irq;
  124. }
  125. static struct irqaction irq0 = {
  126. .name = "voyagergx",
  127. .handler = voyagergx_interrupt,
  128. .flags = IRQF_DISABLED,
  129. .mask = CPU_MASK_NONE,
  130. };
  131. void __init setup_voyagergx_irq(void)
  132. {
  133. int i, flag;
  134. printk(KERN_INFO "VoyagerGX configured at 0x%x on irq %d(mapped into %d to %d)\n",
  135. VOYAGER_BASE,
  136. IRQ_VOYAGER,
  137. VOYAGER_IRQ_BASE,
  138. VOYAGER_IRQ_BASE + VOYAGER_IRQ_NUM - 1);
  139. for (i=0; i<VOYAGER_IRQ_NUM; i++) {
  140. flag = 0;
  141. switch (VOYAGER_IRQ_BASE + i) {
  142. case VOYAGER_USBH_IRQ:
  143. case VOYAGER_8051_IRQ:
  144. case VOYAGER_UART0_IRQ:
  145. case VOYAGER_UART1_IRQ:
  146. case VOYAGER_AC97_IRQ:
  147. flag = 1;
  148. }
  149. if (flag == 1)
  150. irq_desc[VOYAGER_IRQ_BASE + i].chip = &voyagergx_irq_type;
  151. }
  152. setup_irq(IRQ_VOYAGER, &irq0);
  153. }