irq.c 5.0 KB

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