gus_irq.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Routine for IRQ handling from GF1/InterWave chip
  4. * Copyright (c) by Jaroslav Kysela <[email protected]>
  5. */
  6. #include <sound/core.h>
  7. #include <sound/info.h>
  8. #include <sound/gus.h>
  9. #ifdef CONFIG_SND_DEBUG
  10. #define STAT_ADD(x) ((x)++)
  11. #else
  12. #define STAT_ADD(x) while (0) { ; }
  13. #endif
  14. irqreturn_t snd_gus_interrupt(int irq, void *dev_id)
  15. {
  16. struct snd_gus_card * gus = dev_id;
  17. unsigned char status;
  18. int loop = 100;
  19. int handled = 0;
  20. __again:
  21. status = inb(gus->gf1.reg_irqstat);
  22. if (status == 0)
  23. return IRQ_RETVAL(handled);
  24. handled = 1;
  25. /* snd_printk(KERN_DEBUG "IRQ: status = 0x%x\n", status); */
  26. if (status & 0x02) {
  27. STAT_ADD(gus->gf1.interrupt_stat_midi_in);
  28. if (gus->gf1.interrupt_handler_midi_in)
  29. gus->gf1.interrupt_handler_midi_in(gus);
  30. }
  31. if (status & 0x01) {
  32. STAT_ADD(gus->gf1.interrupt_stat_midi_out);
  33. if (gus->gf1.interrupt_handler_midi_out)
  34. gus->gf1.interrupt_handler_midi_out(gus);
  35. }
  36. if (status & (0x20 | 0x40)) {
  37. unsigned int already, _current_;
  38. unsigned char voice_status, voice;
  39. struct snd_gus_voice *pvoice;
  40. already = 0;
  41. while (((voice_status = snd_gf1_i_read8(gus, SNDRV_GF1_GB_VOICES_IRQ)) & 0xc0) != 0xc0) {
  42. voice = voice_status & 0x1f;
  43. _current_ = 1 << voice;
  44. if (already & _current_)
  45. continue; /* multi request */
  46. already |= _current_; /* mark request */
  47. #if 0
  48. printk(KERN_DEBUG "voice = %i, voice_status = 0x%x, "
  49. "voice_verify = %i\n",
  50. voice, voice_status, inb(GUSP(gus, GF1PAGE)));
  51. #endif
  52. pvoice = &gus->gf1.voices[voice];
  53. if (pvoice->use) {
  54. if (!(voice_status & 0x80)) { /* voice position IRQ */
  55. STAT_ADD(pvoice->interrupt_stat_wave);
  56. pvoice->handler_wave(gus, pvoice);
  57. }
  58. if (!(voice_status & 0x40)) { /* volume ramp IRQ */
  59. STAT_ADD(pvoice->interrupt_stat_volume);
  60. pvoice->handler_volume(gus, pvoice);
  61. }
  62. } else {
  63. STAT_ADD(gus->gf1.interrupt_stat_voice_lost);
  64. snd_gf1_i_ctrl_stop(gus, SNDRV_GF1_VB_ADDRESS_CONTROL);
  65. snd_gf1_i_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
  66. }
  67. }
  68. }
  69. if (status & 0x04) {
  70. STAT_ADD(gus->gf1.interrupt_stat_timer1);
  71. if (gus->gf1.interrupt_handler_timer1)
  72. gus->gf1.interrupt_handler_timer1(gus);
  73. }
  74. if (status & 0x08) {
  75. STAT_ADD(gus->gf1.interrupt_stat_timer2);
  76. if (gus->gf1.interrupt_handler_timer2)
  77. gus->gf1.interrupt_handler_timer2(gus);
  78. }
  79. if (status & 0x80) {
  80. if (snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_DMA_CONTROL) & 0x40) {
  81. STAT_ADD(gus->gf1.interrupt_stat_dma_write);
  82. if (gus->gf1.interrupt_handler_dma_write)
  83. gus->gf1.interrupt_handler_dma_write(gus);
  84. }
  85. if (snd_gf1_i_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL) & 0x40) {
  86. STAT_ADD(gus->gf1.interrupt_stat_dma_read);
  87. if (gus->gf1.interrupt_handler_dma_read)
  88. gus->gf1.interrupt_handler_dma_read(gus);
  89. }
  90. }
  91. if (--loop > 0)
  92. goto __again;
  93. return IRQ_NONE;
  94. }
  95. #ifdef CONFIG_SND_DEBUG
  96. static void snd_gus_irq_info_read(struct snd_info_entry *entry,
  97. struct snd_info_buffer *buffer)
  98. {
  99. struct snd_gus_card *gus;
  100. struct snd_gus_voice *pvoice;
  101. int idx;
  102. gus = entry->private_data;
  103. snd_iprintf(buffer, "midi out = %u\n", gus->gf1.interrupt_stat_midi_out);
  104. snd_iprintf(buffer, "midi in = %u\n", gus->gf1.interrupt_stat_midi_in);
  105. snd_iprintf(buffer, "timer1 = %u\n", gus->gf1.interrupt_stat_timer1);
  106. snd_iprintf(buffer, "timer2 = %u\n", gus->gf1.interrupt_stat_timer2);
  107. snd_iprintf(buffer, "dma write = %u\n", gus->gf1.interrupt_stat_dma_write);
  108. snd_iprintf(buffer, "dma read = %u\n", gus->gf1.interrupt_stat_dma_read);
  109. snd_iprintf(buffer, "voice lost = %u\n", gus->gf1.interrupt_stat_voice_lost);
  110. for (idx = 0; idx < 32; idx++) {
  111. pvoice = &gus->gf1.voices[idx];
  112. snd_iprintf(buffer, "voice %i: wave = %u, volume = %u\n",
  113. idx,
  114. pvoice->interrupt_stat_wave,
  115. pvoice->interrupt_stat_volume);
  116. }
  117. }
  118. void snd_gus_irq_profile_init(struct snd_gus_card *gus)
  119. {
  120. snd_card_ro_proc_new(gus->card, "gusirq", gus, snd_gus_irq_info_read);
  121. }
  122. #endif