gus_irq.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Routine for IRQ handling from GF1/InterWave chip
  3. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <sound/core.h>
  22. #include <sound/info.h>
  23. #include <sound/gus.h>
  24. #ifdef CONFIG_SND_DEBUG
  25. #define STAT_ADD(x) ((x)++)
  26. #else
  27. #define STAT_ADD(x) while (0) { ; }
  28. #endif
  29. irqreturn_t snd_gus_interrupt(int irq, void *dev_id)
  30. {
  31. struct snd_gus_card * gus = dev_id;
  32. unsigned char status;
  33. int loop = 100;
  34. int handled = 0;
  35. __again:
  36. status = inb(gus->gf1.reg_irqstat);
  37. if (status == 0)
  38. return IRQ_RETVAL(handled);
  39. handled = 1;
  40. // snd_printk("IRQ: status = 0x%x\n", status);
  41. if (status & 0x02) {
  42. STAT_ADD(gus->gf1.interrupt_stat_midi_in);
  43. if (gus->gf1.interrupt_handler_midi_in)
  44. gus->gf1.interrupt_handler_midi_in(gus);
  45. }
  46. if (status & 0x01) {
  47. STAT_ADD(gus->gf1.interrupt_stat_midi_out);
  48. if (gus->gf1.interrupt_handler_midi_out)
  49. gus->gf1.interrupt_handler_midi_out(gus);
  50. }
  51. if (status & (0x20 | 0x40)) {
  52. unsigned int already, _current_;
  53. unsigned char voice_status, voice;
  54. struct snd_gus_voice *pvoice;
  55. already = 0;
  56. while (((voice_status = snd_gf1_i_read8(gus, SNDRV_GF1_GB_VOICES_IRQ)) & 0xc0) != 0xc0) {
  57. voice = voice_status & 0x1f;
  58. _current_ = 1 << voice;
  59. if (already & _current_)
  60. continue; /* multi request */
  61. already |= _current_; /* mark request */
  62. #if 0
  63. printk("voice = %i, voice_status = 0x%x, voice_verify = %i\n", voice, voice_status, inb(GUSP(gus, GF1PAGE)));
  64. #endif
  65. pvoice = &gus->gf1.voices[voice];
  66. if (pvoice->use) {
  67. if (!(voice_status & 0x80)) { /* voice position IRQ */
  68. STAT_ADD(pvoice->interrupt_stat_wave);
  69. pvoice->handler_wave(gus, pvoice);
  70. }
  71. if (!(voice_status & 0x40)) { /* volume ramp IRQ */
  72. STAT_ADD(pvoice->interrupt_stat_volume);
  73. pvoice->handler_volume(gus, pvoice);
  74. }
  75. } else {
  76. STAT_ADD(gus->gf1.interrupt_stat_voice_lost);
  77. snd_gf1_i_ctrl_stop(gus, SNDRV_GF1_VB_ADDRESS_CONTROL);
  78. snd_gf1_i_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
  79. }
  80. }
  81. }
  82. if (status & 0x04) {
  83. STAT_ADD(gus->gf1.interrupt_stat_timer1);
  84. if (gus->gf1.interrupt_handler_timer1)
  85. gus->gf1.interrupt_handler_timer1(gus);
  86. }
  87. if (status & 0x08) {
  88. STAT_ADD(gus->gf1.interrupt_stat_timer2);
  89. if (gus->gf1.interrupt_handler_timer2)
  90. gus->gf1.interrupt_handler_timer2(gus);
  91. }
  92. if (status & 0x80) {
  93. if (snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_DMA_CONTROL) & 0x40) {
  94. STAT_ADD(gus->gf1.interrupt_stat_dma_write);
  95. if (gus->gf1.interrupt_handler_dma_write)
  96. gus->gf1.interrupt_handler_dma_write(gus);
  97. }
  98. if (snd_gf1_i_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL) & 0x40) {
  99. STAT_ADD(gus->gf1.interrupt_stat_dma_read);
  100. if (gus->gf1.interrupt_handler_dma_read)
  101. gus->gf1.interrupt_handler_dma_read(gus);
  102. }
  103. }
  104. if (--loop > 0)
  105. goto __again;
  106. return IRQ_NONE;
  107. }
  108. #ifdef CONFIG_SND_DEBUG
  109. static void snd_gus_irq_info_read(struct snd_info_entry *entry,
  110. struct snd_info_buffer *buffer)
  111. {
  112. struct snd_gus_card *gus;
  113. struct snd_gus_voice *pvoice;
  114. int idx;
  115. gus = entry->private_data;
  116. snd_iprintf(buffer, "midi out = %u\n", gus->gf1.interrupt_stat_midi_out);
  117. snd_iprintf(buffer, "midi in = %u\n", gus->gf1.interrupt_stat_midi_in);
  118. snd_iprintf(buffer, "timer1 = %u\n", gus->gf1.interrupt_stat_timer1);
  119. snd_iprintf(buffer, "timer2 = %u\n", gus->gf1.interrupt_stat_timer2);
  120. snd_iprintf(buffer, "dma write = %u\n", gus->gf1.interrupt_stat_dma_write);
  121. snd_iprintf(buffer, "dma read = %u\n", gus->gf1.interrupt_stat_dma_read);
  122. snd_iprintf(buffer, "voice lost = %u\n", gus->gf1.interrupt_stat_voice_lost);
  123. for (idx = 0; idx < 32; idx++) {
  124. pvoice = &gus->gf1.voices[idx];
  125. snd_iprintf(buffer, "voice %i: wave = %u, volume = %u\n",
  126. idx,
  127. pvoice->interrupt_stat_wave,
  128. pvoice->interrupt_stat_volume);
  129. }
  130. }
  131. void snd_gus_irq_profile_init(struct snd_gus_card *gus)
  132. {
  133. struct snd_info_entry *entry;
  134. if (! snd_card_proc_new(gus->card, "gusirq", &entry))
  135. snd_info_set_text_ops(entry, gus, snd_gus_irq_info_read);
  136. }
  137. #endif