• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6/sound/isa/gus/
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
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
32irqreturn_t snd_gus_interrupt(int irq, void *dev_id)
33{
34	struct snd_gus_card * gus = dev_id;
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;
44	/* snd_printk(KERN_DEBUG "IRQ: status = 0x%x\n", status); */
45	if (status & 0x02) {
46		STAT_ADD(gus->gf1.interrupt_stat_midi_in);
47		if (gus->gf1.interrupt_handler_midi_in)
48			gus->gf1.interrupt_handler_midi_in(gus);
49	}
50	if (status & 0x01) {
51		STAT_ADD(gus->gf1.interrupt_stat_midi_out);
52		if (gus->gf1.interrupt_handler_midi_out)
53			gus->gf1.interrupt_handler_midi_out(gus);
54	}
55	if (status & (0x20 | 0x40)) {
56		unsigned int already, _current_;
57		unsigned char voice_status, voice;
58		struct snd_gus_voice *pvoice;
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			pvoice = &gus->gf1.voices[voice];
68			if (pvoice->use) {
69				if (!(voice_status & 0x80)) {	/* voice position IRQ */
70					STAT_ADD(pvoice->interrupt_stat_wave);
71					pvoice->handler_wave(gus, pvoice);
72				}
73				if (!(voice_status & 0x40)) {	/* volume ramp IRQ */
74					STAT_ADD(pvoice->interrupt_stat_volume);
75					pvoice->handler_volume(gus, pvoice);
76				}
77			} else {
78				STAT_ADD(gus->gf1.interrupt_stat_voice_lost);
79				snd_gf1_i_ctrl_stop(gus, SNDRV_GF1_VB_ADDRESS_CONTROL);
80				snd_gf1_i_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
81			}
82		}
83	}
84	if (status & 0x04) {
85		STAT_ADD(gus->gf1.interrupt_stat_timer1);
86		if (gus->gf1.interrupt_handler_timer1)
87			gus->gf1.interrupt_handler_timer1(gus);
88	}
89	if (status & 0x08) {
90		STAT_ADD(gus->gf1.interrupt_stat_timer2);
91		if (gus->gf1.interrupt_handler_timer2)
92			gus->gf1.interrupt_handler_timer2(gus);
93	}
94	if (status & 0x80) {
95		if (snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_DMA_CONTROL) & 0x40) {
96			STAT_ADD(gus->gf1.interrupt_stat_dma_write);
97			if (gus->gf1.interrupt_handler_dma_write)
98				gus->gf1.interrupt_handler_dma_write(gus);
99		}
100		if (snd_gf1_i_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL) & 0x40) {
101			STAT_ADD(gus->gf1.interrupt_stat_dma_read);
102			if (gus->gf1.interrupt_handler_dma_read)
103				gus->gf1.interrupt_handler_dma_read(gus);
104		}
105	}
106	if (--loop > 0)
107		goto __again;
108	return IRQ_NONE;
109}
110
111#ifdef CONFIG_SND_DEBUG
112static void snd_gus_irq_info_read(struct snd_info_entry *entry,
113				  struct snd_info_buffer *buffer)
114{
115	struct snd_gus_card *gus;
116	struct snd_gus_voice *pvoice;
117	int idx;
118
119	gus = entry->private_data;
120	snd_iprintf(buffer, "midi out = %u\n", gus->gf1.interrupt_stat_midi_out);
121	snd_iprintf(buffer, "midi in = %u\n", gus->gf1.interrupt_stat_midi_in);
122	snd_iprintf(buffer, "timer1 = %u\n", gus->gf1.interrupt_stat_timer1);
123	snd_iprintf(buffer, "timer2 = %u\n", gus->gf1.interrupt_stat_timer2);
124	snd_iprintf(buffer, "dma write = %u\n", gus->gf1.interrupt_stat_dma_write);
125	snd_iprintf(buffer, "dma read = %u\n", gus->gf1.interrupt_stat_dma_read);
126	snd_iprintf(buffer, "voice lost = %u\n", gus->gf1.interrupt_stat_voice_lost);
127	for (idx = 0; idx < 32; idx++) {
128		pvoice = &gus->gf1.voices[idx];
129		snd_iprintf(buffer, "voice %i: wave = %u, volume = %u\n",
130					idx,
131					pvoice->interrupt_stat_wave,
132					pvoice->interrupt_stat_volume);
133	}
134}
135
136void snd_gus_irq_profile_init(struct snd_gus_card *gus)
137{
138	struct snd_info_entry *entry;
139
140	if (! snd_card_proc_new(gus->card, "gusirq", &entry))
141		snd_info_set_text_ops(entry, gus, snd_gus_irq_info_read);
142}
143
144#endif
145