irq.c 4.8 KB

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