source: GPL/alsa-kernel/isa/gus/gusextreme.c@ 1

Last change on this file since 1 was 1, checked in by vladest, 20 years ago

initial import

File size: 14.9 KB
Line 
1/*
2 * Driver for Gravis UltraSound Extreme soundcards
3 * Copyright (c) by Jaroslav Kysela <perex@suse.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., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 */
21
22#define SNDRV_MAIN_OBJECT_FILE
23#include <sound/driver.h>
24#include <sound/gus.h>
25#include <sound/es1688.h>
26#include <sound/mpu401.h>
27#include <sound/opl3.h>
28#define SNDRV_LEGACY_AUTO_PROBE
29#define SNDRV_LEGACY_FIND_FREE_IRQ
30#define SNDRV_LEGACY_FIND_FREE_DMA
31#define SNDRV_GET_ID
32#include <sound/initval.h>
33
34EXPORT_NO_SYMBOLS;
35MODULE_DESCRIPTION("Gravis UltraSound Extreme");
36MODULE_CLASSES("{sound}");
37MODULE_DEVICES("{{Gravis,UltraSound Extreme}}");
38
39static int snd_index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
40static char *snd_id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
41static int snd_enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
42static long snd_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */
43#ifdef TARGET_OS2
44static long snd_gf1_port[SNDRV_CARDS] = {-1,-1,-1,-1,-1,-1,-1,-1}; /* 0x210,0x220,0x230,0x240,0x250,0x260,0x270 */
45static long snd_mpu_port[SNDRV_CARDS] = {-1,-1,-1,-1,-1,-1,-1,-1}; /* 0x300,0x310,0x320 */
46#else
47static long snd_gf1_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS) - 1] = -1}; /* 0x210,0x220,0x230,0x240,0x250,0x260,0x270 */
48static long snd_mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS) - 1] = -1}; /* 0x300,0x310,0x320 */
49#endif
50static int snd_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
51static int snd_mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
52static int snd_gf1_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 2,3,5,9,11,12,15 */
53static int snd_dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
54static int snd_dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
55#ifdef TARGET_OS2
56static int snd_joystick_dac[SNDRV_CARDS] = {REPEAT_SNDRV(29)};
57 /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
58static int snd_channels[SNDRV_CARDS] = {REPEAT_SNDRV(24)};
59static int snd_pcm_channels[SNDRV_CARDS] = {REPEAT_SNDRV(2)};
60#else
61static int snd_joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
62 /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
63static int snd_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24};
64static int snd_pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
65#endif
66
67MODULE_PARM(snd_index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
68MODULE_PARM_DESC(snd_index, "Index value for GUS Extreme soundcard.");
69MODULE_PARM_SYNTAX(snd_index, SNDRV_INDEX_DESC);
70MODULE_PARM(snd_id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
71MODULE_PARM_DESC(snd_id, "ID string for GUS Extreme soundcard.");
72MODULE_PARM_SYNTAX(snd_id, SNDRV_ID_DESC);
73MODULE_PARM(snd_enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
74MODULE_PARM_DESC(snd_enable, "Enable GUS Extreme soundcard.");
75MODULE_PARM_SYNTAX(snd_enable, SNDRV_ENABLE_DESC);
76MODULE_PARM(snd_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
77MODULE_PARM_DESC(snd_port, "Port # for GUS Extreme driver.");
78MODULE_PARM_SYNTAX(snd_port, SNDRV_ENABLED ",allows:{{0x220,0x260,0x20}},dialog:list");
79MODULE_PARM(snd_gf1_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
80MODULE_PARM_DESC(snd_gf1_port, "GF1 port # for GUS Extreme driver (optional).");
81MODULE_PARM_SYNTAX(snd_gf1_port, SNDRV_ENABLED ",allows:{{0x210,0x270,0x10}},dialog:list");
82MODULE_PARM(snd_mpu_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
83MODULE_PARM_DESC(snd_mpu_port, "MPU-401 port # for GUS Extreme driver.");
84MODULE_PARM_SYNTAX(snd_mpu_port, SNDRV_ENABLED ",allows:{{0x300,0x320,0x10}},dialog:list");
85MODULE_PARM(snd_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
86MODULE_PARM_DESC(snd_irq, "IRQ # for GUS Extreme driver.");
87MODULE_PARM_SYNTAX(snd_irq, SNDRV_ENABLED ",allows:{{5},{7},{9},{10}},dialog:list");
88MODULE_PARM(snd_mpu_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
89MODULE_PARM_DESC(snd_mpu_irq, "MPU-401 IRQ # for GUS Extreme driver.");
90MODULE_PARM_SYNTAX(snd_mpu_irq, SNDRV_ENABLED ",allows:{{5},{7},{9},{10}},dialog:list");
91MODULE_PARM(snd_gf1_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
92MODULE_PARM_DESC(snd_gf1_irq, "GF1 IRQ # for GUS Extreme driver.");
93MODULE_PARM_SYNTAX(snd_gf1_irq, SNDRV_ENABLED ",allows:{{2},{3},{5},{9},{11},{12},{15}},dialog:list");
94MODULE_PARM(snd_dma8, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
95MODULE_PARM_DESC(snd_dma8, "8-bit DMA # for GUS Extreme driver.");
96MODULE_PARM_SYNTAX(snd_dma8, SNDRV_DMA8_DESC);
97MODULE_PARM(snd_dma1, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
98MODULE_PARM_DESC(snd_dma1, "GF1 DMA # for GUS Extreme driver.");
99MODULE_PARM_SYNTAX(snd_dma1, SNDRV_DMA_DESC);
100MODULE_PARM(snd_joystick_dac, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
101MODULE_PARM_DESC(snd_joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for GUS Extreme driver.");
102MODULE_PARM_SYNTAX(snd_joystick_dac, SNDRV_ENABLED ",allows:{{0,31}}");
103MODULE_PARM(snd_channels, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
104MODULE_PARM_DESC(snd_channels, "GF1 channels for GUS Extreme driver.");
105MODULE_PARM_SYNTAX(snd_channels, SNDRV_ENABLED ",allows:{{14,32}}");
106MODULE_PARM(snd_pcm_channels, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
107MODULE_PARM_DESC(snd_pcm_channels, "Reserved PCM channels for GUS Extreme driver.");
108MODULE_PARM_SYNTAX(snd_pcm_channels, SNDRV_ENABLED ",allows:{{2,16}}");
109
110static snd_card_t *snd_gusextreme_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
111
112
113static int __init snd_gusextreme_detect(int dev,
114 snd_card_t * card,
115 snd_gus_card_t * gus,
116 es1688_t *es1688)
117{
118 unsigned long flags;
119
120 /*
121 * This is main stuff - enable access to GF1 chip...
122 * I'm not sure, if this will work for card which have
123 * ES1688 chip in another place than 0x220.
124 *
125 * I used reverse-engineering in DOSEMU. [--jk]
126 *
127 * ULTRINIT.EXE:
128 * 0x230 = 0,2,3
129 * 0x240 = 2,0,1
130 * 0x250 = 2,0,3
131 * 0x260 = 2,2,1
132 */
133
134 spin_lock_irqsave(&es1688->mixer_lock, flags);
135 snd_es1688_mixer_write(es1688, 0x40, 0x0b); /* don't change!!! */
136 spin_unlock_irqrestore(&es1688->mixer_lock, flags);
137 spin_lock_irqsave(&es1688->reg_lock, flags);
138 outb(snd_gf1_port[dev] & 0x040 ? 2 : 0, ES1688P(es1688, INIT1));
139 outb(0, 0x201);
140 outb(snd_gf1_port[dev] & 0x020 ? 2 : 0, ES1688P(es1688, INIT1));
141 outb(0, 0x201);
142 outb(snd_gf1_port[dev] & 0x010 ? 3 : 1, ES1688P(es1688, INIT1));
143 spin_unlock_irqrestore(&es1688->reg_lock, flags);
144
145 udelay(100);
146
147 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
148#ifdef CONFIG_SND_DEBUG_DETECT
149 {
150 unsigned char d;
151
152 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
153 snd_printk("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
154 return -EIO;
155 }
156 }
157#else
158 if ((snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET) & 0x07) != 0)
159 return -EIO;
160#endif
161 udelay(160);
162 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
163 udelay(160);
164#ifdef CONFIG_SND_DEBUG_DETECT
165 {
166 unsigned char d;
167
168 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
169 snd_printk("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
170 return -EIO;
171 }
172 }
173#else
174 if ((snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET) & 0x07) != 1)
175 return -EIO;
176#endif
177
178 return 0;
179}
180
181static void __init snd_gusextreme_init(int dev, snd_gus_card_t * gus)
182{
183 gus->joystick_dac = snd_joystick_dac[dev];
184}
185
186static int __init snd_gusextreme_mixer(es1688_t *chip)
187{
188 snd_card_t *card = chip->card;
189 snd_ctl_elem_id_t id1, id2;
190 int err;
191
192 memset(&id1, 0, sizeof(id1));
193 memset(&id2, 0, sizeof(id2));
194 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
195 /* reassign AUX to SYNTHESIZER */
196 strcpy(id1.name, "Aux Playback Volume");
197 strcpy(id2.name, "Synth Playback Volume");
198 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
199 return err;
200 /* reassign Master Playback Switch to Synth Playback Switch */
201 strcpy(id1.name, "Master Playback Switch");
202 strcpy(id2.name, "Synth Playback Switch");
203 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
204 return err;
205 return 0;
206}
207
208static int __init snd_gusextreme_probe(int dev)
209{
210 static int possible_ess_irqs[] = {5, 9, 10, 7, -1};
211 static int possible_ess_dmas[] = {1, 3, 0, -1};
212 static int possible_gf1_irqs[] = {5, 11, 12, 9, 7, 15, 3, -1};
213 static int possible_gf1_dmas[] = {5, 6, 7, 1, 3, -1};
214 int gf1_irq, gf1_dma, ess_irq, mpu_irq, ess_dma;
215 snd_card_t *card;
216 struct snd_gusextreme *acard;
217 snd_gus_card_t *gus;
218 es1688_t *es1688;
219 opl3_t *opl3;
220 int err;
221
222 card = snd_card_new(snd_index[dev], snd_id[dev], THIS_MODULE, 0);
223 if (card == NULL)
224 return -ENOMEM;
225 acard = (struct snd_gusextreme *)card->private_data;
226
227 gf1_irq = snd_gf1_irq[dev];
228 if (gf1_irq == SNDRV_AUTO_IRQ) {
229 if ((gf1_irq = snd_legacy_find_free_irq(possible_gf1_irqs)) < 0) {
230 snd_card_free(card);
231 snd_printk("unable to find a free IRQ for GF1\n");
232 return -EBUSY;
233 }
234 }
235 ess_irq = snd_irq[dev];
236 if (ess_irq == SNDRV_AUTO_IRQ) {
237 if ((ess_irq = snd_legacy_find_free_irq(possible_ess_irqs)) < 0) {
238 snd_card_free(card);
239 snd_printk("unable to find a free IRQ for ES1688\n");
240 return -EBUSY;
241 }
242 }
243 if (snd_mpu_port[dev] == SNDRV_AUTO_PORT)
244 snd_mpu_port[dev] = 0;
245 mpu_irq = snd_mpu_irq[dev];
246 if (mpu_irq > 15)
247 mpu_irq = -1;
248 gf1_dma = snd_dma1[dev];
249 if (gf1_dma == SNDRV_AUTO_DMA) {
250 if ((gf1_dma = snd_legacy_find_free_dma(possible_gf1_dmas)) < 0) {
251 snd_card_free(card);
252 snd_printk("unable to find a free DMA for GF1\n");
253 return -EBUSY;
254 }
255 }
256 ess_dma = snd_dma8[dev];
257 if (ess_dma == SNDRV_AUTO_DMA) {
258 if ((ess_dma = snd_legacy_find_free_dma(possible_ess_dmas)) < 0) {
259 snd_card_free(card);
260 snd_printk("unable to find a free DMA for ES1688\n");
261 return -EBUSY;
262 }
263 }
264
265 if ((err = snd_es1688_create(card, snd_port[dev], snd_mpu_port[dev],
266 ess_irq, mpu_irq, ess_dma,
267 ES1688_HW_1688, &es1688)) < 0) {
268 snd_card_free(card);
269 return err;
270 }
271 if (snd_gf1_port[dev] < 0)
272 snd_gf1_port[dev] = snd_port[dev] + 0x20;
273 if ((err = snd_gus_create(card,
274 snd_gf1_port[dev],
275 gf1_irq,
276 gf1_dma,
277 -1,
278 0, snd_channels[dev],
279 snd_pcm_channels[dev], 0,
280 &gus)) < 0) {
281 snd_card_free(card);
282 return err;
283 }
284 if ((err = snd_gusextreme_detect(dev, card, gus, es1688)) < 0) {
285 snd_card_free(card);
286 return err;
287 }
288 snd_gusextreme_init(dev, gus);
289 if ((err = snd_gus_initialize(gus)) < 0) {
290 snd_card_free(card);
291 return err;
292 }
293 if (!gus->ess_flag) {
294 snd_card_free(card);
295 snd_printdd("GUS Extreme soundcard was not detected at 0x%lx\n", gus->gf1.port);
296 return -ENODEV;
297 }
298 if ((err = snd_es1688_pcm(es1688, 0, NULL)) < 0) {
299 snd_card_free(card);
300 return err;
301 }
302 if ((err = snd_es1688_mixer(es1688)) < 0) {
303 snd_card_free(card);
304 return err;
305 }
306 snd_component_add(card, "ES1688");
307 if (snd_pcm_channels[dev] > 0) {
308 if ((err = snd_gf1_pcm_new(gus, 1, 1, NULL)) < 0) {
309 snd_card_free(card);
310 return err;
311 }
312 }
313 if ((err = snd_gf1_new_mixer(gus)) < 0) {
314 snd_card_free(card);
315 return err;
316 }
317 if ((err = snd_gusextreme_mixer(es1688)) < 0) {
318 snd_card_free(card);
319 return err;
320 }
321
322 if (snd_opl3_create(card, es1688->port, es1688->port + 2,
323 OPL3_HW_OPL3, 0, &opl3) < 0) {
324 snd_printk("opl3 not detected at 0x%lx\n", es1688->port);
325 } else {
326 if ((err = snd_opl3_hwdep_new(opl3, 0, 2, NULL)) < 0) {
327 snd_card_free(card);
328 return err;
329 }
330 }
331
332 if (es1688->mpu_port >= 0x300) {
333 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
334 es1688->mpu_port, 0,
335 mpu_irq,
336 SA_INTERRUPT,
337 NULL)) < 0) {
338 snd_card_free(card);
339 return err;
340 }
341 }
342
343 sprintf(card->longname, "Gravis UltraSound Extreme at 0x%lx, irq %i&%i, dma %i&%i",
344 es1688->port, gf1_irq, ess_irq, gf1_dma, ess_dma);
345 if ((err = snd_card_register(card)) < 0) {
346 snd_card_free(card);
347 return err;
348 }
349 snd_gusextreme_cards[dev] = card;
350 return 0;
351}
352
353static int __init snd_gusextreme_legacy_auto_probe(unsigned long port)
354{
355 static int dev = 0;
356 int res;
357
358 for ( ; dev < SNDRV_CARDS; dev++) {
359 if (!snd_enable[dev] || snd_port[dev] != SNDRV_AUTO_PORT)
360 continue;
361 snd_port[dev] = port;
362 res = snd_gusextreme_probe(dev);
363 if (res < 0)
364 snd_port[dev] = SNDRV_AUTO_PORT;
365 return res;
366 }
367 return -ENODEV;
368}
369
370static int __init alsa_card_gusextreme_init(void)
371{
372 static unsigned long possible_ports[] = {0x220, 0x240, 0x260, -1};
373 int dev, cards;
374
375 for (dev = cards = 0; dev < SNDRV_CARDS && snd_enable[dev] > 0; dev++) {
376 if (snd_port[dev] == SNDRV_AUTO_PORT)
377 continue;
378 if (snd_gusextreme_probe(dev) >= 0)
379 cards++;
380 }
381 cards += snd_legacy_auto_probe(possible_ports, snd_gusextreme_legacy_auto_probe);
382 if (!cards) {
383#ifdef MODULE
384 snd_printk("GUS Extreme soundcard not found or device busy\n");
385#endif
386 return -ENODEV;
387 }
388 return 0;
389}
390
391static void __exit alsa_card_gusextreme_exit(void)
392{
393 int idx;
394 snd_card_t *card;
395 struct snd_gusextreme *acard;
396
397 for (idx = 0; idx < SNDRV_CARDS; idx++) {
398 card = snd_gusextreme_cards[idx];
399 if (card == NULL)
400 continue;
401 acard = (struct snd_gusextreme *)card->private_data;
402 snd_card_free(snd_gusextreme_cards[idx]);
403 }
404}
405
406module_init(alsa_card_gusextreme_init)
407module_exit(alsa_card_gusextreme_exit)
408
409#ifndef MODULE
410
411/* format is: snd-card-gusextreme=snd_enable,snd_index,snd_id,
412 snd_port,snd_gf1_port,snd_mpu_port,
413 snd_irq,snd_gf1_irq,snd_mpu_irq,
414 snd_dma8,snd_dma1,
415 snd_joystick_dac,
416 snd_channels,snd_pcm_channels */
417
418static int __init alsa_card_gusextreme_setup(char *str)
419{
420 static unsigned __initdata nr_dev = 0;
421
422 if (nr_dev >= SNDRV_CARDS)
423 return 0;
424 (void)(get_option(&str,&snd_enable[nr_dev]) == 2 &&
425 get_option(&str,&snd_index[nr_dev]) == 2 &&
426 get_id(&str,&snd_id[nr_dev]) == 2 &&
427 get_option(&str,(int *)&snd_port[nr_dev]) == 2 &&
428 get_option(&str,(int *)&snd_gf1_port[nr_dev]) == 2 &&
429 get_option(&str,(int *)&snd_mpu_port[nr_dev]) == 2 &&
430 get_option(&str,&snd_irq[nr_dev]) == 2 &&
431 get_option(&str,&snd_gf1_irq[nr_dev]) == 2 &&
432 get_option(&str,&snd_mpu_irq[nr_dev]) == 2 &&
433 get_option(&str,&snd_dma8[nr_dev]) == 2 &&
434 get_option(&str,&snd_dma1[nr_dev]) == 2);
435 nr_dev++;
436 return 1;
437}
438
439__setup("snd-card-gusextreme=", alsa_card_gusextreme_setup);
440
441#endif /* ifndef MODULE */
Note: See TracBrowser for help on using the repository browser.