Import 2.1.81
[davej-history.git] / drivers / sound / gus_card.c
blob141cd7db8e1fdd17f11457395b28a065a970b129
1 /*
2 * sound/gus_card.c
4 * Detection routine for the Gravis Ultrasound.
5 */
6 /*
7 * Copyright (C) by Hannu Savolainen 1993-1997
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
13 #include <linux/config.h>
14 #include <linux/module.h>
16 #include "sound_config.h"
17 #include "soundmodule.h"
19 #if defined(CONFIG_GUSHW) || defined(MODULE)
21 #include "gus_hw.h"
23 void gusintr(int irq, void *dev_id, struct pt_regs *dummy);
25 int gus_base = 0, gus_irq = 0, gus_dma = 0;
26 extern int gus_wave_volume;
27 extern int gus_pcm_volume;
28 extern int have_gus_max;
29 int gus_pnp_flag = 0;
31 void attach_gus_card(struct address_info *hw_config)
33 snd_set_irq_handler(hw_config->irq, gusintr, "Gravis Ultrasound", hw_config->osp);
35 gus_wave_init(hw_config);
37 request_region(hw_config->io_base, 16, "GUS");
38 request_region(hw_config->io_base + 0x100, 12, "GUS"); /* 0x10c-> is MAX */
40 if (sound_alloc_dma(hw_config->dma, "GUS"))
41 printk("gus_card.c: Can't allocate DMA channel\n");
42 if (hw_config->dma2 != -1 && hw_config->dma2 != hw_config->dma)
43 if (sound_alloc_dma(hw_config->dma2, "GUS(2)"))
44 printk("gus_card.c: Can't allocate DMA channel 2\n");
45 #if defined(CONFIG_MIDI)
46 gus_midi_init(hw_config);
47 #endif
50 int probe_gus(struct address_info *hw_config)
52 int irq;
53 int io_addr;
55 if (hw_config->card_subtype == 1)
56 gus_pnp_flag = 1;
58 irq = hw_config->irq;
60 if (hw_config->card_subtype == 0) /* GUS/MAX/ACE */
61 if (irq != 3 && irq != 5 && irq != 7 && irq != 9 &&
62 irq != 11 && irq != 12 && irq != 15)
64 printk(KERN_ERR "GUS: Unsupported IRQ %d\n", irq);
65 return 0;
67 if (check_region(hw_config->io_base, 16))
68 printk(KERN_ERR "GUS: I/O range conflict (1)\n");
69 else if (check_region(hw_config->io_base + 0x100, 16))
70 printk(KERN_ERR "GUS: I/O range conflict (2)\n");
71 else if (gus_wave_detect(hw_config->io_base))
72 return 1;
74 #ifndef EXCLUDE_GUS_IODETECT
77 * Look at the possible base addresses (0x2X0, X=1, 2, 3, 4, 5, 6)
80 for (io_addr = 0x210; io_addr <= 0x260; io_addr += 0x10)
81 if (io_addr != hw_config->io_base) /*
82 * Already tested
84 if (!check_region(io_addr, 16))
85 if (!check_region(io_addr + 0x100, 16))
86 if (gus_wave_detect(io_addr))
88 hw_config->io_base = io_addr;
89 return 1;
91 #endif
93 return 0;
96 void unload_gus(struct address_info *hw_config)
98 DDB(printk("unload_gus(%x)\n", hw_config->io_base));
100 gus_wave_unload(hw_config);
102 release_region(hw_config->io_base, 16);
103 release_region(hw_config->io_base + 0x100, 12); /* 0x10c-> is MAX */
104 snd_release_irq(hw_config->irq);
106 sound_free_dma(hw_config->dma);
108 if (hw_config->dma2 != -1 && hw_config->dma2 != hw_config->dma)
109 sound_free_dma(hw_config->dma2);
112 void gusintr(int irq, void *dev_id, struct pt_regs *dummy)
114 unsigned char src;
115 extern int gus_timer_enabled;
117 sti();
119 #ifdef CONFIG_GUSMAX
120 if (have_gus_max)
121 adintr(irq, NULL, NULL);
122 #endif
124 while (1)
126 if (!(src = inb(u_IrqStatus)))
127 return;
129 if (src & DMA_TC_IRQ)
131 guswave_dma_irq();
133 if (src & (MIDI_TX_IRQ | MIDI_RX_IRQ))
135 #if defined(CONFIG_MIDI)
136 gus_midi_interrupt(0);
137 #endif
139 if (src & (GF1_TIMER1_IRQ | GF1_TIMER2_IRQ))
141 #if defined(CONFIG_SEQUENCER) || defined(CONFIG_SEQUENCER_MODULE)
142 if (gus_timer_enabled)
143 sound_timer_interrupt();
144 gus_write8(0x45, 0); /* Ack IRQ */
145 gus_timer_command(4, 0x80); /* Reset IRQ flags */
146 #else
147 gus_write8(0x45, 0); /* Stop timers */
148 #endif
150 if (src & (WAVETABLE_IRQ | ENVELOPE_IRQ))
151 gus_voice_irq();
155 #endif
158 * Some extra code for the 16 bit sampling option
161 #ifdef CONFIG_GUS16
163 int probe_gus_db16(struct address_info *hw_config)
165 return ad1848_detect(hw_config->io_base, NULL, hw_config->osp);
168 void attach_gus_db16(struct address_info *hw_config)
170 #if defined(CONFIG_GUSHW) || defined(MODULE)
171 gus_pcm_volume = 100;
172 gus_wave_volume = 90;
173 #endif
175 hw_config->slots[3] = ad1848_init("GUS 16 bit sampling", hw_config->io_base,
176 hw_config->irq,
177 hw_config->dma,
178 hw_config->dma, 0,
179 hw_config->osp);
182 void unload_gus_db16(struct address_info *hw_config)
185 ad1848_unload(hw_config->io_base,
186 hw_config->irq,
187 hw_config->dma,
188 hw_config->dma, 0);
189 sound_unload_audiodev(hw_config->slots[3]);
191 #endif
193 #ifdef MODULE
195 static struct address_info config;
198 * Note DMA2 of -1 has the right meaning in the GUS driver as well
199 * as here.
202 int io = -1;
203 int irq = -1;
204 int dma = -1;
205 int dma16 = -1; /* Set this for modules that need it */
206 int type = 0; /* 1 for PnP */
207 int gus16 = 0;
208 static int db16 = 0; /* Has a Gus16 AD1848 on it */
210 MODULE_PARM(io, "i");
211 MODULE_PARM(irq, "i");
212 MODULE_PARM(dma, "i");
213 MODULE_PARM(dma16, "i");
214 MODULE_PARM(type, "i");
215 MODULE_PARM(gus16, "i");
216 MODULE_PARM(db16, "i");
218 int init_module(void)
220 printk(KERN_INFO "Gravis Ultrasound audio driver Copyright (C) by Hannu Savolainen 1993-1996\n");
222 if (io == -1 || dma == -1 || irq == -1)
224 printk(KERN_ERR "I/O, IRQ, and DMA are mandatory\n");
225 return -EINVAL;
227 config.io_base = io;
228 config.irq = irq;
229 config.dma = dma;
230 config.dma2 = dma16;
231 config.card_subtype = type;
233 #if defined(CONFIG_GUS16)
234 if (probe_gus_db16(&config) && gus16)
236 attach_gus_db16(&config);
237 db16 = 1;
239 #endif
240 if (probe_gus(&config) == 0)
241 return -ENODEV;
242 attach_gus_card(&config);
243 SOUND_LOCK;
244 return 0;
247 void cleanup_module(void)
249 #if defined(CONFIG_GUS16)
250 if (db16)
251 unload_gus_db16(&config);
252 #endif
253 unload_gus(&config);
254 SOUND_LOCK_END;
257 #endif