irq.c 5.0 KB

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