blob: 226b8438aa7030ddf3f49ae5c2aa7173c6e285a1 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Routine for IRQ handling from GF1/InterWave chip
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02004 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <sound/core.h>
8#include <sound/info.h>
9#include <sound/gus.h>
10
11#ifdef CONFIG_SND_DEBUG
12#define STAT_ADD(x) ((x)++)
13#else
14#define STAT_ADD(x) while (0) { ; }
15#endif
16
David Howells7d12e782006-10-05 14:55:46 +010017irqreturn_t snd_gus_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018{
Takashi Iwai5e2da202005-11-17 14:36:44 +010019 struct snd_gus_card * gus = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 unsigned char status;
21 int loop = 100;
22 int handled = 0;
23
24__again:
25 status = inb(gus->gf1.reg_irqstat);
26 if (status == 0)
27 return IRQ_RETVAL(handled);
28 handled = 1;
Takashi Iwai91f05062009-02-05 15:46:48 +010029 /* snd_printk(KERN_DEBUG "IRQ: status = 0x%x\n", status); */
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 if (status & 0x02) {
31 STAT_ADD(gus->gf1.interrupt_stat_midi_in);
Ingo Molnarc2cbdbb2007-10-16 14:42:30 +020032 if (gus->gf1.interrupt_handler_midi_in)
33 gus->gf1.interrupt_handler_midi_in(gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 }
35 if (status & 0x01) {
36 STAT_ADD(gus->gf1.interrupt_stat_midi_out);
Ingo Molnarc2cbdbb2007-10-16 14:42:30 +020037 if (gus->gf1.interrupt_handler_midi_out)
38 gus->gf1.interrupt_handler_midi_out(gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 }
40 if (status & (0x20 | 0x40)) {
41 unsigned int already, _current_;
42 unsigned char voice_status, voice;
Takashi Iwai5e2da202005-11-17 14:36:44 +010043 struct snd_gus_voice *pvoice;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45 already = 0;
46 while (((voice_status = snd_gf1_i_read8(gus, SNDRV_GF1_GB_VOICES_IRQ)) & 0xc0) != 0xc0) {
47 voice = voice_status & 0x1f;
48 _current_ = 1 << voice;
49 if (already & _current_)
50 continue; /* multi request */
51 already |= _current_; /* mark request */
52#if 0
Takashi Iwai91f05062009-02-05 15:46:48 +010053 printk(KERN_DEBUG "voice = %i, voice_status = 0x%x, "
54 "voice_verify = %i\n",
55 voice, voice_status, inb(GUSP(gus, GF1PAGE)));
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#endif
57 pvoice = &gus->gf1.voices[voice];
58 if (pvoice->use) {
59 if (!(voice_status & 0x80)) { /* voice position IRQ */
60 STAT_ADD(pvoice->interrupt_stat_wave);
61 pvoice->handler_wave(gus, pvoice);
62 }
63 if (!(voice_status & 0x40)) { /* volume ramp IRQ */
64 STAT_ADD(pvoice->interrupt_stat_volume);
65 pvoice->handler_volume(gus, pvoice);
66 }
67 } else {
68 STAT_ADD(gus->gf1.interrupt_stat_voice_lost);
69 snd_gf1_i_ctrl_stop(gus, SNDRV_GF1_VB_ADDRESS_CONTROL);
70 snd_gf1_i_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
71 }
72 }
73 }
74 if (status & 0x04) {
75 STAT_ADD(gus->gf1.interrupt_stat_timer1);
Ingo Molnarc2cbdbb2007-10-16 14:42:30 +020076 if (gus->gf1.interrupt_handler_timer1)
77 gus->gf1.interrupt_handler_timer1(gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 }
79 if (status & 0x08) {
80 STAT_ADD(gus->gf1.interrupt_stat_timer2);
Ingo Molnarc2cbdbb2007-10-16 14:42:30 +020081 if (gus->gf1.interrupt_handler_timer2)
82 gus->gf1.interrupt_handler_timer2(gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 }
84 if (status & 0x80) {
85 if (snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_DMA_CONTROL) & 0x40) {
86 STAT_ADD(gus->gf1.interrupt_stat_dma_write);
Ingo Molnarc2cbdbb2007-10-16 14:42:30 +020087 if (gus->gf1.interrupt_handler_dma_write)
88 gus->gf1.interrupt_handler_dma_write(gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 }
90 if (snd_gf1_i_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL) & 0x40) {
91 STAT_ADD(gus->gf1.interrupt_stat_dma_read);
Ingo Molnarc2cbdbb2007-10-16 14:42:30 +020092 if (gus->gf1.interrupt_handler_dma_read)
93 gus->gf1.interrupt_handler_dma_read(gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 }
95 }
96 if (--loop > 0)
97 goto __again;
98 return IRQ_NONE;
99}
100
101#ifdef CONFIG_SND_DEBUG
Takashi Iwai5e2da202005-11-17 14:36:44 +0100102static void snd_gus_irq_info_read(struct snd_info_entry *entry,
103 struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
Takashi Iwai5e2da202005-11-17 14:36:44 +0100105 struct snd_gus_card *gus;
106 struct snd_gus_voice *pvoice;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 int idx;
108
109 gus = entry->private_data;
110 snd_iprintf(buffer, "midi out = %u\n", gus->gf1.interrupt_stat_midi_out);
111 snd_iprintf(buffer, "midi in = %u\n", gus->gf1.interrupt_stat_midi_in);
112 snd_iprintf(buffer, "timer1 = %u\n", gus->gf1.interrupt_stat_timer1);
113 snd_iprintf(buffer, "timer2 = %u\n", gus->gf1.interrupt_stat_timer2);
114 snd_iprintf(buffer, "dma write = %u\n", gus->gf1.interrupt_stat_dma_write);
115 snd_iprintf(buffer, "dma read = %u\n", gus->gf1.interrupt_stat_dma_read);
116 snd_iprintf(buffer, "voice lost = %u\n", gus->gf1.interrupt_stat_voice_lost);
117 for (idx = 0; idx < 32; idx++) {
118 pvoice = &gus->gf1.voices[idx];
119 snd_iprintf(buffer, "voice %i: wave = %u, volume = %u\n",
120 idx,
121 pvoice->interrupt_stat_wave,
122 pvoice->interrupt_stat_volume);
123 }
124}
125
Takashi Iwai5e2da202005-11-17 14:36:44 +0100126void snd_gus_irq_profile_init(struct snd_gus_card *gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Takashi Iwai1bac5e12019-02-04 16:00:13 +0100128 snd_card_ro_proc_new(gus->card, "gusirq", gus, snd_gus_irq_info_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
131#endif