irq.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. /* -------------------------------------------------------------------- */
  18. #undef DEBUG
  19. #include <linux/config.h>
  20. #include <linux/sched.h>
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <linux/param.h>
  24. #include <linux/ioport.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/init.h>
  27. #include <linux/irq.h>
  28. #include <asm/io.h>
  29. #include <asm/irq.h>
  30. #include <asm/rts7751r2d/rts7751r2d.h>
  31. #include <asm/rts7751r2d/voyagergx_reg.h>
  32. static void disable_voyagergx_irq(unsigned int irq)
  33. {
  34. unsigned long flags, val;
  35. unsigned long mask = 1 << (irq - VOYAGER_IRQ_BASE);
  36. pr_debug("disable_voyagergx_irq(%d): mask=%x\n", irq, mask);
  37. local_irq_save(flags);
  38. val = inl(VOYAGER_INT_MASK);
  39. val &= ~mask;
  40. outl(val, VOYAGER_INT_MASK);
  41. local_irq_restore(flags);
  42. }
  43. static void enable_voyagergx_irq(unsigned int irq)
  44. {
  45. unsigned long flags, val;
  46. unsigned long mask = 1 << (irq - VOYAGER_IRQ_BASE);
  47. pr_debug("disable_voyagergx_irq(%d): mask=%x\n", irq, mask);
  48. local_irq_save(flags);
  49. val = inl(VOYAGER_INT_MASK);
  50. val |= mask;
  51. outl(val, VOYAGER_INT_MASK);
  52. local_irq_restore(flags);
  53. }
  54. static void mask_and_ack_voyagergx(unsigned int irq)
  55. {
  56. disable_voyagergx_irq(irq);
  57. }
  58. static void end_voyagergx_irq(unsigned int irq)
  59. {
  60. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  61. enable_voyagergx_irq(irq);
  62. }
  63. static unsigned int startup_voyagergx_irq(unsigned int irq)
  64. {
  65. enable_voyagergx_irq(irq);
  66. return 0;
  67. }
  68. static void shutdown_voyagergx_irq(unsigned int irq)
  69. {
  70. disable_voyagergx_irq(irq);
  71. }
  72. static struct hw_interrupt_type voyagergx_irq_type = {
  73. "VOYAGERGX-IRQ",
  74. startup_voyagergx_irq,
  75. shutdown_voyagergx_irq,
  76. enable_voyagergx_irq,
  77. disable_voyagergx_irq,
  78. mask_and_ack_voyagergx,
  79. end_voyagergx_irq,
  80. };
  81. static irqreturn_t voyagergx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  82. {
  83. printk(KERN_INFO
  84. "VoyagerGX: spurious interrupt, status: 0x%x\n",
  85. inl(INT_STATUS));
  86. return IRQ_HANDLED;
  87. }
  88. /*====================================================*/
  89. static struct {
  90. int (*func)(int, void *);
  91. void *dev;
  92. } voyagergx_demux[VOYAGER_IRQ_NUM];
  93. void voyagergx_register_irq_demux(int irq,
  94. int (*demux)(int irq, void *dev), void *dev)
  95. {
  96. voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = demux;
  97. voyagergx_demux[irq - VOYAGER_IRQ_BASE].dev = dev;
  98. }
  99. void voyagergx_unregister_irq_demux(int irq)
  100. {
  101. voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = 0;
  102. }
  103. int voyagergx_irq_demux(int irq)
  104. {
  105. if (irq == IRQ_VOYAGER ) {
  106. unsigned long i = 0, bit __attribute__ ((unused));
  107. unsigned long val = inl(INT_STATUS);
  108. #if 1
  109. if ( val & ( 1 << 1 )){
  110. i = 1;
  111. } else if ( val & ( 1 << 2 )){
  112. i = 2;
  113. } else if ( val & ( 1 << 6 )){
  114. i = 6;
  115. } else if( val & ( 1 << 10 )){
  116. i = 10;
  117. } else if( val & ( 1 << 11 )){
  118. i = 11;
  119. } else if( val & ( 1 << 12 )){
  120. i = 12;
  121. } else if( val & ( 1 << 17 )){
  122. i = 17;
  123. } else {
  124. printk("Unexpected IRQ irq = %d status = 0x%08lx\n", irq, val);
  125. }
  126. pr_debug("voyagergx_irq_demux %d \n", i);
  127. #else
  128. for (bit = 1, i = 0 ; i < VOYAGER_IRQ_NUM ; bit <<= 1, i++)
  129. if (val & bit)
  130. break;
  131. #endif
  132. if (i < VOYAGER_IRQ_NUM) {
  133. irq = VOYAGER_IRQ_BASE + i;
  134. if (voyagergx_demux[i].func != 0)
  135. irq = voyagergx_demux[i].func(irq, voyagergx_demux[i].dev);
  136. }
  137. }
  138. return irq;
  139. }
  140. static struct irqaction irq0 = { voyagergx_interrupt, SA_INTERRUPT, 0, "VOYAGERGX", NULL, NULL};
  141. void __init setup_voyagergx_irq(void)
  142. {
  143. int i, flag;
  144. printk(KERN_INFO "VoyagerGX configured at 0x%x on irq %d(mapped into %d to %d)\n",
  145. VOYAGER_BASE,
  146. IRQ_VOYAGER,
  147. VOYAGER_IRQ_BASE,
  148. VOYAGER_IRQ_BASE + VOYAGER_IRQ_NUM - 1);
  149. for (i=0; i<VOYAGER_IRQ_NUM; i++) {
  150. flag = 0;
  151. switch (VOYAGER_IRQ_BASE + i) {
  152. case VOYAGER_USBH_IRQ:
  153. case VOYAGER_8051_IRQ:
  154. case VOYAGER_UART0_IRQ:
  155. case VOYAGER_UART1_IRQ:
  156. case VOYAGER_AC97_IRQ:
  157. flag = 1;
  158. }
  159. if (flag == 1)
  160. irq_desc[VOYAGER_IRQ_BASE + i].handler = &voyagergx_irq_type;
  161. }
  162. setup_irq(IRQ_VOYAGER, &irq0);
  163. }