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

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

initial import

File size: 13.6 KB
Line 
1/*
2 * Driver for Gravis UltraSound MAX soundcard
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/cs4231.h>
26#define SNDRV_LEGACY_AUTO_PROBE
27#define SNDRV_LEGACY_FIND_FREE_IRQ
28#define SNDRV_LEGACY_FIND_FREE_DMA
29#define SNDRV_GET_ID
30#include <sound/initval.h>
31
32EXPORT_NO_SYMBOLS;
33MODULE_DESCRIPTION("Gravis UltraSound MAX");
34MODULE_CLASSES("{sound}");
35MODULE_DEVICES("{{Gravis,UltraSound MAX}}");
36
37static int snd_index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
38static char *snd_id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
39static int snd_enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
40static long snd_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x230,0x240,0x250,0x260 */
41static int snd_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 2,3,5,9,11,12,15 */
42static int snd_dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
43static int snd_dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
44#ifdef TARGET_OS2
45static int snd_joystick_dac[SNDRV_CARDS] = {REPEAT_SNDRV(29)};
46 /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
47static int snd_channels[SNDRV_CARDS] = {REPEAT_SNDRV(24)};
48static int snd_pcm_channels[SNDRV_CARDS] = {REPEAT_SNDRV(2)};
49#else
50static int snd_joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
51 /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
52static int snd_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24};
53static int snd_pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
54#endif
55
56MODULE_PARM(snd_index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
57MODULE_PARM_DESC(snd_index, "Index value for GUS MAX soundcard.");
58MODULE_PARM_SYNTAX(snd_index, SNDRV_INDEX_DESC);
59MODULE_PARM(snd_id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
60MODULE_PARM_DESC(snd_id, "ID string for GUS MAX soundcard.");
61MODULE_PARM_SYNTAX(snd_id, SNDRV_ID_DESC);
62MODULE_PARM(snd_enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
63MODULE_PARM_DESC(snd_enable, "Enable GUS MAX soundcard.");
64MODULE_PARM_SYNTAX(snd_enable, SNDRV_ENABLE_DESC);
65MODULE_PARM(snd_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
66MODULE_PARM_DESC(snd_port, "Port # for GUS MAX driver.");
67MODULE_PARM_SYNTAX(snd_port, SNDRV_ENABLED ",allows:{{0x220},{0x230},{0x240},{0x250},{0x260}},dialog:list");
68MODULE_PARM(snd_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
69MODULE_PARM_DESC(snd_irq, "IRQ # for GUS MAX driver.");
70MODULE_PARM_SYNTAX(snd_irq, SNDRV_ENABLED ",allows:{{3},{5},{9},{11},{12},{15}},dialog:list");
71MODULE_PARM(snd_dma1, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
72MODULE_PARM_DESC(snd_dma1, "DMA1 # for GUS MAX driver.");
73MODULE_PARM_SYNTAX(snd_dma1, SNDRV_DMA_DESC);
74MODULE_PARM(snd_dma2, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
75MODULE_PARM_DESC(snd_dma2, "DMA2 # for GUS MAX driver.");
76MODULE_PARM_SYNTAX(snd_dma2, SNDRV_DMA_DESC);
77MODULE_PARM(snd_joystick_dac, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
78MODULE_PARM_DESC(snd_joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for GUS MAX driver.");
79MODULE_PARM_SYNTAX(snd_joystick_dac, SNDRV_ENABLED ",allows:{{0,31}}");
80MODULE_PARM(snd_channels, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
81MODULE_PARM_DESC(snd_channels, "Used GF1 channels for GUS MAX driver.");
82MODULE_PARM_SYNTAX(snd_channels, SNDRV_ENABLED ",allows:{{14,32}}");
83MODULE_PARM(snd_pcm_channels, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
84MODULE_PARM_DESC(snd_pcm_channels, "Reserved PCM channels for GUS MAX driver.");
85MODULE_PARM_SYNTAX(snd_pcm_channels, SNDRV_ENABLED ",allows:{{2,16}}");
86
87struct snd_gusmax {
88 int irq;
89 snd_card_t *card;
90 snd_gus_card_t *gus;
91 cs4231_t *cs4231;
92 unsigned short gus_status_reg;
93 unsigned short pcm_status_reg;
94};
95
96static snd_card_t *snd_gusmax_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
97
98
99static int __init snd_gusmax_detect(snd_gus_card_t * gus)
100{
101 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
102#ifdef CONFIG_SND_DEBUG_DETECT
103 {
104 unsigned char d;
105
106 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
107 snd_printk("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
108 return -ENODEV;
109 }
110 }
111#else
112 if ((snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET) & 0x07) != 0)
113 return -ENODEV;
114#endif
115 udelay(160);
116 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
117 udelay(160);
118#ifdef CONFIG_SND_DEBUG_DETECT
119 {
120 unsigned char d;
121
122 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
123 snd_printk("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
124 return -ENODEV;
125 }
126 }
127#else
128 if ((snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET) & 0x07) != 1)
129 return -ENODEV;
130#endif
131 return 0;
132}
133
134static void snd_gusmax_interrupt(int irq, void *dev_id, struct pt_regs *regs)
135{
136 struct snd_gusmax *maxcard = (struct snd_gusmax *) dev_id;
137 int loop, max = 5;
138
139 do {
140 loop = 0;
141 if (inb(maxcard->gus_status_reg)) {
142 snd_gus_interrupt(irq, maxcard->gus, regs);
143 loop++;
144 }
145 if (inb(maxcard->pcm_status_reg) & 0x01) { /* IRQ bit is set? */
146 snd_cs4231_interrupt(irq, maxcard->cs4231, regs);
147 loop++;
148 }
149 } while (loop && --max > 0);
150}
151
152static void __init snd_gusmax_init(int dev, snd_card_t * card, snd_gus_card_t * gus)
153{
154 gus->equal_irq = 1;
155 gus->codec_flag = 1;
156 gus->joystick_dac = snd_joystick_dac[dev];
157 /* init control register */
158 gus->max_cntrl_val = (gus->gf1.port >> 4) & 0x0f;
159 if (gus->gf1.dma1 > 3)
160 gus->max_cntrl_val |= 0x10;
161 if (gus->gf1.dma2 > 3)
162 gus->max_cntrl_val |= 0x20;
163 gus->max_cntrl_val |= 0x40;
164 outb(gus->max_cntrl_val, GUSP(gus, MAXCNTRLPORT));
165}
166
167#define CS4231_PRIVATE( left, right, shift, mute ) \
168 ((left << 24)|(right << 16)|(shift<<8)|mute)
169
170static int __init snd_gusmax_mixer(cs4231_t *chip)
171{
172 snd_card_t *card = chip->card;
173 snd_ctl_elem_id_t id1, id2;
174 int err;
175
176 memset(&id1, 0, sizeof(id1));
177 memset(&id2, 0, sizeof(id2));
178 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
179 /* reassign AUXA to SYNTHESIZER */
180 strcpy(id1.name, "Aux Playback Switch");
181 strcpy(id2.name, "Synth Playback Switch");
182 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
183 return err;
184 strcpy(id1.name, "Aux Playback Volume");
185 strcpy(id2.name, "Synth Playback Volume");
186 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
187 return err;
188 /* reassign AUXB to CD */
189 strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
190 strcpy(id2.name, "CD Playback Switch");
191 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
192 return err;
193 strcpy(id1.name, "Aux Playback Volume");
194 strcpy(id2.name, "CD Playback Volume");
195 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
196 return err;
197#if 0
198 /* reassign Mono Input to MIC */
199 if (snd_mixer_group_rename(mixer,
200 SNDRV_MIXER_IN_MONO, 0,
201 SNDRV_MIXER_IN_MIC, 0) < 0)
202 goto __error;
203 if (snd_mixer_elem_rename(mixer,
204 SNDRV_MIXER_IN_MONO, 0, SNDRV_MIXER_ETYPE_INPUT,
205 SNDRV_MIXER_IN_MIC, 0) < 0)
206 goto __error;
207 if (snd_mixer_elem_rename(mixer,
208 "Mono Capture Volume", 0, SNDRV_MIXER_ETYPE_VOLUME1,
209 "Mic Capture Volume", 0) < 0)
210 goto __error;
211 if (snd_mixer_elem_rename(mixer,
212 "Mono Capture Switch", 0, SNDRV_MIXER_ETYPE_SWITCH1,
213 "Mic Capture Switch", 0) < 0)
214 goto __error;
215#endif
216 return 0;
217}
218
219static void snd_gusmax_free(snd_card_t *card)
220{
221 struct snd_gusmax *maxcard = (struct snd_gusmax *)card->private_data;
222
223 if (maxcard == NULL)
224 return;
225 if (maxcard->irq >= 0)
226 free_irq(maxcard->irq, (void *)maxcard);
227}
228
229static int __init snd_gusmax_probe(int dev)
230{
231 static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, -1};
232 static int possible_dmas[] = {5, 6, 7, 1, 3, -1};
233 int irq, dma1, dma2, err;
234 snd_card_t *card;
235 snd_gus_card_t *gus = NULL;
236 cs4231_t *cs4231;
237 struct snd_gusmax *maxcard;
238
239 card = snd_card_new(snd_index[dev], snd_id[dev], THIS_MODULE,
240 sizeof(struct snd_gusmax));
241 if (card == NULL)
242 return -ENOMEM;
243 card->private_free = snd_gusmax_free;
244 maxcard = (struct snd_gusmax *)card->private_data;
245 maxcard->card = card;
246 maxcard->irq = -1;
247
248 irq = snd_irq[dev];
249 if (irq == SNDRV_AUTO_IRQ) {
250 if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
251 snd_card_free(card);
252 snd_printk("unable to find a free IRQ\n");
253 return -EBUSY;
254 }
255 }
256 dma1 = snd_dma1[dev];
257 if (dma1 == SNDRV_AUTO_DMA) {
258 if ((dma1 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
259 snd_card_free(card);
260 snd_printk("unable to find a free DMA1\n");
261 return -EBUSY;
262 }
263 }
264 dma2 = snd_dma2[dev];
265 if (dma2 == SNDRV_AUTO_DMA) {
266 if ((dma2 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
267 snd_card_free(card);
268 snd_printk("unable to find a free DMA2\n");
269 return -EBUSY;
270 }
271 }
272
273 if ((err = snd_gus_create(card,
274 snd_port[dev],
275 -irq, dma1, dma2,
276 0, snd_channels[dev],
277 snd_pcm_channels[dev],
278 0, &gus)) < 0) {
279 snd_card_free(card);
280 return err;
281 }
282 if ((err = snd_gusmax_detect(gus)) < 0) {
283 snd_card_free(card);
284 return err;
285 }
286 maxcard->gus_status_reg = gus->gf1.reg_irqstat;
287 maxcard->pcm_status_reg = gus->gf1.port + 0x10c + 2;
288 snd_gusmax_init(dev, card, gus);
289 if ((err = snd_gus_initialize(gus)) < 0) {
290 snd_card_free(card);
291 return err;
292 }
293 if (!gus->max_flag) {
294 snd_card_free(card);
295 snd_printk("GUS MAX soundcard was not detected at 0x%lx\n", gus->gf1.port);
296 return -ENODEV;
297 }
298
299 if (request_irq(irq, snd_gusmax_interrupt, SA_INTERRUPT, "GUS MAX", (void *)maxcard)) {
300 snd_card_free(card);
301 snd_printk("unable to grab IRQ %d\n", irq);
302 return -EBUSY;
303 }
304 maxcard->irq = irq;
305
306 if ((err = snd_cs4231_create(card,
307 gus->gf1.port + 0x10c, -1, irq,
308 dma2 < 0 ? dma1 : dma2, dma1,
309 CS4231_HW_DETECT,
310 CS4231_HWSHARE_IRQ |
311 CS4231_HWSHARE_DMA1 |
312 CS4231_HWSHARE_DMA2,
313 &cs4231)) < 0) {
314 snd_card_free(card);
315 return err;
316 }
317 if ((err = snd_cs4231_pcm(cs4231, 0, NULL)) < 0) {
318 snd_card_free(card);
319 return err;
320 }
321 if ((err = snd_cs4231_mixer(cs4231)) < 0) {
322 snd_card_free(card);
323 return err;
324 }
325 if ((err = snd_cs4231_timer(cs4231, 2, NULL)) < 0) {
326 snd_card_free(card);
327 return err;
328 }
329 if (snd_pcm_channels[dev] > 0) {
330 if ((err = snd_gf1_pcm_new(gus, 1, 1, NULL)) < 0) {
331 snd_card_free(card);
332 return err;
333 }
334 }
335 if ((err = snd_gusmax_mixer(cs4231)) < 0) {
336 snd_card_free(card);
337 return err;
338 }
339
340 if ((err = snd_gf1_rawmidi_new(gus, 0, NULL)) < 0) {
341 snd_card_free(card);
342 return err;
343 }
344
345 sprintf(card->longname + strlen(card->longname), " at 0x%lx, irq %i, dma %i", gus->gf1.port, irq, dma1);
346 if (dma2 >= 0)
347 sprintf(card->longname + strlen(card->longname), "&%i", dma2);
348 if ((err = snd_card_register(card)) < 0) {
349 snd_card_free(card);
350 return err;
351 }
352
353 maxcard->gus = gus;
354 maxcard->cs4231 = cs4231;
355 snd_gusmax_cards[dev] = card;
356 return 0;
357}
358
359static int __init snd_gusmax_legacy_auto_probe(unsigned long port)
360{
361 static int dev = 0;
362 int res;
363
364 for ( ; dev < SNDRV_CARDS; dev++) {
365 if (!snd_enable[dev] || snd_port[dev] != SNDRV_AUTO_PORT)
366 continue;
367 snd_port[dev] = port;
368 res = snd_gusmax_probe(dev);
369 if (res < 0)
370 snd_port[dev] = SNDRV_AUTO_PORT;
371 return res;
372 }
373 return -ENODEV;
374}
375
376static int __init alsa_card_gusmax_init(void)
377{
378 static unsigned long possible_ports[] = {0x220, 0x230, 0x240, 0x250, 0x260, -1};
379 int dev, cards;
380
381 for (dev = cards = 0; dev < SNDRV_CARDS && snd_enable[dev] > 0; dev++) {
382 if (snd_port[dev] == SNDRV_AUTO_PORT)
383 continue;
384 if (snd_gusmax_probe(dev) >= 0)
385 cards++;
386 }
387 cards += snd_legacy_auto_probe(possible_ports, snd_gusmax_legacy_auto_probe);
388 if (!cards) {
389#ifdef MODULE
390 snd_printk("GUS MAX soundcard not found or device busy\n");
391#endif
392 return -ENODEV;
393 }
394 return 0;
395}
396
397static void __exit alsa_card_gusmax_exit(void)
398{
399 int idx;
400
401 for (idx = 0; idx < SNDRV_CARDS; idx++)
402 snd_card_free(snd_gusmax_cards[idx]);
403}
404
405module_init(alsa_card_gusmax_init)
406module_exit(alsa_card_gusmax_exit)
407
408#ifndef MODULE
409
410/* format is: snd-card-gusmax=snd_enable,snd_index,snd_id,
411 snd_port,snd_irq,
412 snd_dma1,snd_dma2,
413 snd_joystick_dac,
414 snd_channels,snd_pcm_channels */
415
416static int __init alsa_card_gusmax_setup(char *str)
417{
418 static unsigned __initdata nr_dev = 0;
419
420 if (nr_dev >= SNDRV_CARDS)
421 return 0;
422 (void)(get_option(&str,&snd_enable[nr_dev]) == 2 &&
423 get_option(&str,&snd_index[nr_dev]) == 2 &&
424 get_id(&str,&snd_id[nr_dev]) == 2 &&
425 get_option(&str,(int *)&snd_port[nr_dev]) == 2 &&
426 get_option(&str,&snd_irq[nr_dev]) == 2 &&
427 get_option(&str,&snd_dma1[nr_dev]) == 2 &&
428 get_option(&str,&snd_dma2[nr_dev]) == 2 &&
429 get_option(&str,&snd_joystick_dac[nr_dev]) == 2 &&
430 get_option(&str,&snd_channels[nr_dev]) == 2 &&
431 get_option(&str,&snd_pcm_channels[nr_dev]) == 2);
432 nr_dev++;
433 return 1;
434}
435
436__setup("snd-card-gusmax=", alsa_card_gusmax_setup);
437
438#endif /* ifndef MODULE */
Note: See TracBrowser for help on using the repository browser.