gus_irq.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 <perex@perex.cz>
  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. if (status & 0x02) {
  26. STAT_ADD(gus->gf1.interrupt_stat_midi_in);
  27. if (gus->gf1.interrupt_handler_midi_in)
  28. gus->gf1.interrupt_handler_midi_in(gus);
  29. }
  30. if (status & 0x01) {
  31. STAT_ADD(gus->gf1.interrupt_stat_midi_out);
  32. if (gus->gf1.interrupt_handler_midi_out)
  33. gus->gf1.interrupt_handler_midi_out(gus);
  34. }
  35. if (status & (0x20 | 0x40)) {
  36. unsigned int already, _current_;
  37. unsigned char voice_status, voice;
  38. struct snd_gus_voice *pvoice;
  39. already = 0;
  40. while (((voice_status = snd_gf1_i_read8(gus, SNDRV_GF1_GB_VOICES_IRQ)) & 0xc0) != 0xc0) {
  41. voice = voice_status & 0x1f;
  42. _current_ = 1 << voice;
  43. if (already & _current_)
  44. continue; /* multi request */
  45. already |= _current_; /* mark request */
  46. #if 0
  47. dev_dbg(gus->card->dev,
  48. "voice = %i, voice_status = 0x%x, voice_verify = %i\n",
  49. voice, voice_status, inb(GUSP(gus, GF1PAGE)));
  50. #endif
  51. pvoice = &gus->gf1.voices[voice];
  52. if (pvoice->use) {
  53. if (!(voice_status & 0x80)) { /* voice position IRQ */
  54. STAT_ADD(pvoice->interrupt_stat_wave);
  55. pvoice->handler_wave(gus, pvoice);
  56. }
  57. if (!(voice_status & 0x40)) { /* volume ramp IRQ */
  58. STAT_ADD(pvoice->interrupt_stat_volume);
  59. pvoice->handler_volume(gus, pvoice);
  60. }
  61. } else {
  62. STAT_ADD(gus->gf1.interrupt_stat_voice_lost);
  63. snd_gf1_i_ctrl_stop(gus, SNDRV_GF1_VB_ADDRESS_CONTROL);
  64. snd_gf1_i_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
  65. }
  66. }
  67. }
  68. if (status & 0x04) {
  69. STAT_ADD(gus->gf1.interrupt_stat_timer1);
  70. if (gus->gf1.interrupt_handler_timer1)
  71. gus->gf1.interrupt_handler_timer1(gus);
  72. }
  73. if (status & 0x08) {
  74. STAT_ADD(gus->gf1.interrupt_stat_timer2);
  75. if (gus->gf1.interrupt_handler_timer2)
  76. gus->gf1.interrupt_handler_timer2(gus);
  77. }
  78. if (status & 0x80) {
  79. if (snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_DMA_CONTROL) & 0x40) {
  80. STAT_ADD(gus->gf1.interrupt_stat_dma_write);
  81. if (gus->gf1.interrupt_handler_dma_write)
  82. gus->gf1.interrupt_handler_dma_write(gus);
  83. }
  84. if (snd_gf1_i_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL) & 0x40) {
  85. STAT_ADD(gus->gf1.interrupt_stat_dma_read);
  86. if (gus->gf1.interrupt_handler_dma_read)
  87. gus->gf1.interrupt_handler_dma_read(gus);
  88. }
  89. }
  90. if (--loop > 0)
  91. goto __again;
  92. return IRQ_NONE;
  93. }
  94. #ifdef CONFIG_SND_DEBUG
  95. static void snd_gus_irq_info_read(struct snd_info_entry *entry,
  96. struct snd_info_buffer *buffer)
  97. {
  98. struct snd_gus_card *gus;
  99. struct snd_gus_voice *pvoice;
  100. int idx;
  101. gus = entry->private_data;
  102. snd_iprintf(buffer, "midi out = %u\n", gus->gf1.interrupt_stat_midi_out);
  103. snd_iprintf(buffer, "midi in = %u\n", gus->gf1.interrupt_stat_midi_in);
  104. snd_iprintf(buffer, "timer1 = %u\n", gus->gf1.interrupt_stat_timer1);
  105. snd_iprintf(buffer, "timer2 = %u\n", gus->gf1.interrupt_stat_timer2);
  106. snd_iprintf(buffer, "dma write = %u\n", gus->gf1.interrupt_stat_dma_write);
  107. snd_iprintf(buffer, "dma read = %u\n", gus->gf1.interrupt_stat_dma_read);
  108. snd_iprintf(buffer, "voice lost = %u\n", gus->gf1.interrupt_stat_voice_lost);
  109. for (idx = 0; idx < 32; idx++) {
  110. pvoice = &gus->gf1.voices[idx];
  111. snd_iprintf(buffer, "voice %i: wave = %u, volume = %u\n",
  112. idx,
  113. pvoice->interrupt_stat_wave,
  114. pvoice->interrupt_stat_volume);
  115. }
  116. }
  117. void snd_gus_irq_profile_init(struct snd_gus_card *gus)
  118. {
  119. snd_card_ro_proc_new(gus->card, "gusirq", gus, snd_gus_irq_info_read);
  120. }
  121. #endif