Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Routine for IRQ handling from GF1/InterWave chip |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 3 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <sound/core.h> |
| 23 | #include <sound/info.h> |
| 24 | #include <sound/gus.h> |
| 25 | |
| 26 | #ifdef CONFIG_SND_DEBUG |
| 27 | #define STAT_ADD(x) ((x)++) |
| 28 | #else |
| 29 | #define STAT_ADD(x) while (0) { ; } |
| 30 | #endif |
| 31 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 32 | irqreturn_t snd_gus_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | { |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 34 | struct snd_gus_card * gus = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | unsigned char status; |
| 36 | int loop = 100; |
| 37 | int handled = 0; |
| 38 | |
| 39 | __again: |
| 40 | status = inb(gus->gf1.reg_irqstat); |
| 41 | if (status == 0) |
| 42 | return IRQ_RETVAL(handled); |
| 43 | handled = 1; |
Takashi Iwai | 91f0506 | 2009-02-05 15:46:48 +0100 | [diff] [blame^] | 44 | /* snd_printk(KERN_DEBUG "IRQ: status = 0x%x\n", status); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | if (status & 0x02) { |
| 46 | STAT_ADD(gus->gf1.interrupt_stat_midi_in); |
Ingo Molnar | c2cbdbb | 2007-10-16 14:42:30 +0200 | [diff] [blame] | 47 | if (gus->gf1.interrupt_handler_midi_in) |
| 48 | gus->gf1.interrupt_handler_midi_in(gus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | if (status & 0x01) { |
| 51 | STAT_ADD(gus->gf1.interrupt_stat_midi_out); |
Ingo Molnar | c2cbdbb | 2007-10-16 14:42:30 +0200 | [diff] [blame] | 52 | if (gus->gf1.interrupt_handler_midi_out) |
| 53 | gus->gf1.interrupt_handler_midi_out(gus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } |
| 55 | if (status & (0x20 | 0x40)) { |
| 56 | unsigned int already, _current_; |
| 57 | unsigned char voice_status, voice; |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 58 | struct snd_gus_voice *pvoice; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | already = 0; |
| 61 | while (((voice_status = snd_gf1_i_read8(gus, SNDRV_GF1_GB_VOICES_IRQ)) & 0xc0) != 0xc0) { |
| 62 | voice = voice_status & 0x1f; |
| 63 | _current_ = 1 << voice; |
| 64 | if (already & _current_) |
| 65 | continue; /* multi request */ |
| 66 | already |= _current_; /* mark request */ |
| 67 | #if 0 |
Takashi Iwai | 91f0506 | 2009-02-05 15:46:48 +0100 | [diff] [blame^] | 68 | printk(KERN_DEBUG "voice = %i, voice_status = 0x%x, " |
| 69 | "voice_verify = %i\n", |
| 70 | voice, voice_status, inb(GUSP(gus, GF1PAGE))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #endif |
| 72 | pvoice = &gus->gf1.voices[voice]; |
| 73 | if (pvoice->use) { |
| 74 | if (!(voice_status & 0x80)) { /* voice position IRQ */ |
| 75 | STAT_ADD(pvoice->interrupt_stat_wave); |
| 76 | pvoice->handler_wave(gus, pvoice); |
| 77 | } |
| 78 | if (!(voice_status & 0x40)) { /* volume ramp IRQ */ |
| 79 | STAT_ADD(pvoice->interrupt_stat_volume); |
| 80 | pvoice->handler_volume(gus, pvoice); |
| 81 | } |
| 82 | } else { |
| 83 | STAT_ADD(gus->gf1.interrupt_stat_voice_lost); |
| 84 | snd_gf1_i_ctrl_stop(gus, SNDRV_GF1_VB_ADDRESS_CONTROL); |
| 85 | snd_gf1_i_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | if (status & 0x04) { |
| 90 | STAT_ADD(gus->gf1.interrupt_stat_timer1); |
Ingo Molnar | c2cbdbb | 2007-10-16 14:42:30 +0200 | [diff] [blame] | 91 | if (gus->gf1.interrupt_handler_timer1) |
| 92 | gus->gf1.interrupt_handler_timer1(gus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | if (status & 0x08) { |
| 95 | STAT_ADD(gus->gf1.interrupt_stat_timer2); |
Ingo Molnar | c2cbdbb | 2007-10-16 14:42:30 +0200 | [diff] [blame] | 96 | if (gus->gf1.interrupt_handler_timer2) |
| 97 | gus->gf1.interrupt_handler_timer2(gus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | if (status & 0x80) { |
| 100 | if (snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_DMA_CONTROL) & 0x40) { |
| 101 | STAT_ADD(gus->gf1.interrupt_stat_dma_write); |
Ingo Molnar | c2cbdbb | 2007-10-16 14:42:30 +0200 | [diff] [blame] | 102 | if (gus->gf1.interrupt_handler_dma_write) |
| 103 | gus->gf1.interrupt_handler_dma_write(gus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | if (snd_gf1_i_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL) & 0x40) { |
| 106 | STAT_ADD(gus->gf1.interrupt_stat_dma_read); |
Ingo Molnar | c2cbdbb | 2007-10-16 14:42:30 +0200 | [diff] [blame] | 107 | if (gus->gf1.interrupt_handler_dma_read) |
| 108 | gus->gf1.interrupt_handler_dma_read(gus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | if (--loop > 0) |
| 112 | goto __again; |
| 113 | return IRQ_NONE; |
| 114 | } |
| 115 | |
| 116 | #ifdef CONFIG_SND_DEBUG |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 117 | static void snd_gus_irq_info_read(struct snd_info_entry *entry, |
| 118 | struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 120 | struct snd_gus_card *gus; |
| 121 | struct snd_gus_voice *pvoice; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | int idx; |
| 123 | |
| 124 | gus = entry->private_data; |
| 125 | snd_iprintf(buffer, "midi out = %u\n", gus->gf1.interrupt_stat_midi_out); |
| 126 | snd_iprintf(buffer, "midi in = %u\n", gus->gf1.interrupt_stat_midi_in); |
| 127 | snd_iprintf(buffer, "timer1 = %u\n", gus->gf1.interrupt_stat_timer1); |
| 128 | snd_iprintf(buffer, "timer2 = %u\n", gus->gf1.interrupt_stat_timer2); |
| 129 | snd_iprintf(buffer, "dma write = %u\n", gus->gf1.interrupt_stat_dma_write); |
| 130 | snd_iprintf(buffer, "dma read = %u\n", gus->gf1.interrupt_stat_dma_read); |
| 131 | snd_iprintf(buffer, "voice lost = %u\n", gus->gf1.interrupt_stat_voice_lost); |
| 132 | for (idx = 0; idx < 32; idx++) { |
| 133 | pvoice = &gus->gf1.voices[idx]; |
| 134 | snd_iprintf(buffer, "voice %i: wave = %u, volume = %u\n", |
| 135 | idx, |
| 136 | pvoice->interrupt_stat_wave, |
| 137 | pvoice->interrupt_stat_volume); |
| 138 | } |
| 139 | } |
| 140 | |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 141 | void snd_gus_irq_profile_init(struct snd_gus_card *gus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 143 | struct snd_info_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | if (! snd_card_proc_new(gus->card, "gusirq", &entry)) |
Takashi Iwai | bf85020 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 146 | snd_info_set_text_ops(entry, gus, snd_gus_irq_info_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | #endif |