irq.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  3. * Creative Labs, Inc.
  4. * Routines for IRQ control of EMU10K1 chips
  5. *
  6. * BUGS:
  7. * --
  8. *
  9. * TODO:
  10. * --
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. *
  26. */
  27. #include <linux/time.h>
  28. #include <sound/core.h>
  29. #include <sound/emu10k1.h>
  30. irqreturn_t snd_emu10k1_interrupt(int irq, void *dev_id)
  31. {
  32. struct snd_emu10k1 *emu = dev_id;
  33. unsigned int status, status2, orig_status, orig_status2;
  34. int handled = 0;
  35. int timeout = 0;
  36. while (((status = inl(emu->port + IPR)) != 0) && (timeout < 1000)) {
  37. timeout++;
  38. orig_status = status;
  39. handled = 1;
  40. if ((status & 0xffffffff) == 0xffffffff) {
  41. snd_printk(KERN_INFO "snd-emu10k1: Suspected sound card removal\n");
  42. break;
  43. }
  44. if (status & IPR_PCIERROR) {
  45. snd_printk(KERN_ERR "interrupt: PCI error\n");
  46. snd_emu10k1_intr_disable(emu, INTE_PCIERRORENABLE);
  47. status &= ~IPR_PCIERROR;
  48. }
  49. if (status & (IPR_VOLINCR|IPR_VOLDECR|IPR_MUTE)) {
  50. if (emu->hwvol_interrupt)
  51. emu->hwvol_interrupt(emu, status);
  52. else
  53. snd_emu10k1_intr_disable(emu, INTE_VOLINCRENABLE|INTE_VOLDECRENABLE|INTE_MUTEENABLE);
  54. status &= ~(IPR_VOLINCR|IPR_VOLDECR|IPR_MUTE);
  55. }
  56. if (status & IPR_CHANNELLOOP) {
  57. int voice;
  58. int voice_max = status & IPR_CHANNELNUMBERMASK;
  59. u32 val;
  60. struct snd_emu10k1_voice *pvoice = emu->voices;
  61. val = snd_emu10k1_ptr_read(emu, CLIPL, 0);
  62. for (voice = 0; voice <= voice_max; voice++) {
  63. if (voice == 0x20)
  64. val = snd_emu10k1_ptr_read(emu, CLIPH, 0);
  65. if (val & 1) {
  66. if (pvoice->use && pvoice->interrupt != NULL) {
  67. pvoice->interrupt(emu, pvoice);
  68. snd_emu10k1_voice_intr_ack(emu, voice);
  69. } else {
  70. snd_emu10k1_voice_intr_disable(emu, voice);
  71. }
  72. }
  73. val >>= 1;
  74. pvoice++;
  75. }
  76. val = snd_emu10k1_ptr_read(emu, HLIPL, 0);
  77. for (voice = 0; voice <= voice_max; voice++) {
  78. if (voice == 0x20)
  79. val = snd_emu10k1_ptr_read(emu, HLIPH, 0);
  80. if (val & 1) {
  81. if (pvoice->use && pvoice->interrupt != NULL) {
  82. pvoice->interrupt(emu, pvoice);
  83. snd_emu10k1_voice_half_loop_intr_ack(emu, voice);
  84. } else {
  85. snd_emu10k1_voice_half_loop_intr_disable(emu, voice);
  86. }
  87. }
  88. val >>= 1;
  89. pvoice++;
  90. }
  91. status &= ~IPR_CHANNELLOOP;
  92. }
  93. status &= ~IPR_CHANNELNUMBERMASK;
  94. if (status & (IPR_ADCBUFFULL|IPR_ADCBUFHALFFULL)) {
  95. if (emu->capture_interrupt)
  96. emu->capture_interrupt(emu, status);
  97. else
  98. snd_emu10k1_intr_disable(emu, INTE_ADCBUFENABLE);
  99. status &= ~(IPR_ADCBUFFULL|IPR_ADCBUFHALFFULL);
  100. }
  101. if (status & (IPR_MICBUFFULL|IPR_MICBUFHALFFULL)) {
  102. if (emu->capture_mic_interrupt)
  103. emu->capture_mic_interrupt(emu, status);
  104. else
  105. snd_emu10k1_intr_disable(emu, INTE_MICBUFENABLE);
  106. status &= ~(IPR_MICBUFFULL|IPR_MICBUFHALFFULL);
  107. }
  108. if (status & (IPR_EFXBUFFULL|IPR_EFXBUFHALFFULL)) {
  109. if (emu->capture_efx_interrupt)
  110. emu->capture_efx_interrupt(emu, status);
  111. else
  112. snd_emu10k1_intr_disable(emu, INTE_EFXBUFENABLE);
  113. status &= ~(IPR_EFXBUFFULL|IPR_EFXBUFHALFFULL);
  114. }
  115. if (status & (IPR_MIDITRANSBUFEMPTY|IPR_MIDIRECVBUFEMPTY)) {
  116. if (emu->midi.interrupt)
  117. emu->midi.interrupt(emu, status);
  118. else
  119. snd_emu10k1_intr_disable(emu, INTE_MIDITXENABLE|INTE_MIDIRXENABLE);
  120. status &= ~(IPR_MIDITRANSBUFEMPTY|IPR_MIDIRECVBUFEMPTY);
  121. }
  122. if (status & (IPR_A_MIDITRANSBUFEMPTY2|IPR_A_MIDIRECVBUFEMPTY2)) {
  123. if (emu->midi2.interrupt)
  124. emu->midi2.interrupt(emu, status);
  125. else
  126. snd_emu10k1_intr_disable(emu, INTE_A_MIDITXENABLE2|INTE_A_MIDIRXENABLE2);
  127. status &= ~(IPR_A_MIDITRANSBUFEMPTY2|IPR_A_MIDIRECVBUFEMPTY2);
  128. }
  129. if (status & IPR_INTERVALTIMER) {
  130. if (emu->timer)
  131. snd_timer_interrupt(emu->timer, emu->timer->sticks);
  132. else
  133. snd_emu10k1_intr_disable(emu, INTE_INTERVALTIMERENB);
  134. status &= ~IPR_INTERVALTIMER;
  135. }
  136. if (status & (IPR_GPSPDIFSTATUSCHANGE|IPR_CDROMSTATUSCHANGE)) {
  137. if (emu->spdif_interrupt)
  138. emu->spdif_interrupt(emu, status);
  139. else
  140. snd_emu10k1_intr_disable(emu, INTE_GPSPDIFENABLE|INTE_CDSPDIFENABLE);
  141. status &= ~(IPR_GPSPDIFSTATUSCHANGE|IPR_CDROMSTATUSCHANGE);
  142. }
  143. if (status & IPR_FXDSP) {
  144. if (emu->dsp_interrupt)
  145. emu->dsp_interrupt(emu);
  146. else
  147. snd_emu10k1_intr_disable(emu, INTE_FXDSPENABLE);
  148. status &= ~IPR_FXDSP;
  149. }
  150. if (status & IPR_P16V) {
  151. while ((status2 = inl(emu->port + IPR2)) != 0) {
  152. u32 mask = INTE2_PLAYBACK_CH_0_LOOP; /* Full Loop */
  153. struct snd_emu10k1_voice *pvoice = &(emu->p16v_voices[0]);
  154. struct snd_emu10k1_voice *cvoice = &(emu->p16v_capture_voice);
  155. //printk(KERN_INFO "status2=0x%x\n", status2);
  156. orig_status2 = status2;
  157. if(status2 & mask) {
  158. if(pvoice->use) {
  159. snd_pcm_period_elapsed(pvoice->epcm->substream);
  160. } else {
  161. snd_printk(KERN_ERR "p16v: status: 0x%08x, mask=0x%08x, pvoice=%p, use=%d\n", status2, mask, pvoice, pvoice->use);
  162. }
  163. }
  164. if(status2 & 0x110000) {
  165. //printk(KERN_INFO "capture int found\n");
  166. if(cvoice->use) {
  167. //printk(KERN_INFO "capture period_elapsed\n");
  168. snd_pcm_period_elapsed(cvoice->epcm->substream);
  169. }
  170. }
  171. outl(orig_status2, emu->port + IPR2); /* ack all */
  172. }
  173. status &= ~IPR_P16V;
  174. }
  175. if (status) {
  176. unsigned int bits;
  177. snd_printk(KERN_ERR "emu10k1: unhandled interrupt: 0x%08x\n", status);
  178. //make sure any interrupts we don't handle are disabled:
  179. bits = INTE_FXDSPENABLE |
  180. INTE_PCIERRORENABLE |
  181. INTE_VOLINCRENABLE |
  182. INTE_VOLDECRENABLE |
  183. INTE_MUTEENABLE |
  184. INTE_MICBUFENABLE |
  185. INTE_ADCBUFENABLE |
  186. INTE_EFXBUFENABLE |
  187. INTE_GPSPDIFENABLE |
  188. INTE_CDSPDIFENABLE |
  189. INTE_INTERVALTIMERENB |
  190. INTE_MIDITXENABLE |
  191. INTE_MIDIRXENABLE;
  192. if (emu->audigy)
  193. bits |= INTE_A_MIDITXENABLE2 | INTE_A_MIDIRXENABLE2;
  194. snd_emu10k1_intr_disable(emu, bits);
  195. }
  196. outl(orig_status, emu->port + IPR); /* ack all */
  197. }
  198. if (timeout == 1000)
  199. snd_printk(KERN_INFO "emu10k1 irq routine failure\n");
  200. return IRQ_RETVAL(handled);
  201. }