patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / sound / isa / wavefront / wavefront.c
1 /*
2  *  ALSA card-level driver for Turtle Beach Wavefront cards 
3  *                                              (Maui,Tropez,Tropez+)
4  *
5  *  Copyright (c) 1997-1999 by Paul Barton-Davis <pbd@op.net>
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20  */
21
22 #include <sound/driver.h>
23 #include <linux/init.h>
24 #include <linux/interrupt.h>
25 #include <linux/slab.h>
26 #include <linux/pnp.h>
27 #include <linux/moduleparam.h>
28 #include <sound/core.h>
29 #include <sound/initval.h>
30 #include <sound/opl3.h>
31 #include <sound/snd_wavefront.h>
32
33 #define chip_t cs4231_t
34
35 MODULE_AUTHOR("Paul Barton-Davis <pbd@op.net>");
36 MODULE_DESCRIPTION("Turtle Beach Wavefront");
37 MODULE_LICENSE("GPL");
38 MODULE_CLASSES("{sound}");
39 MODULE_DEVICES("{{Turtle Beach,Maui/Tropez/Tropez+}}");
40
41 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;          /* Index 0-MAX */
42 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;           /* ID for this card */
43 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;      /* Enable this card */
44 static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
45 static long cs4232_pcm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;  /* PnP setup */
46 static int cs4232_pcm_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
47 static long cs4232_mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
48 static int cs4232_mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
49 static long ics2115_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
50 static int ics2115_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;    /* 2,9,11,12,15 */
51 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;      /* PnP setup */
52 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;           /* 0,1,3,5,6,7 */
53 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;           /* 0,1,3,5,6,7 */
54 static int use_cs4232_midi[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; 
55 static int boot_devs;
56
57 module_param_array(index, int, boot_devs, 0444);
58 MODULE_PARM_DESC(index, "Index value for WaveFront soundcard.");
59 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
60 module_param_array(id, charp, boot_devs, 0444);
61 MODULE_PARM_DESC(id, "ID string for WaveFront soundcard.");
62 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
63 module_param_array(enable, bool, boot_devs, 0444);
64 MODULE_PARM_DESC(enable, "Enable WaveFront soundcard.");
65 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
66 #ifdef CONFIG_PNP
67 module_param_array(isapnp, bool, boot_devs, 0444);
68 MODULE_PARM_DESC(isapnp, "ISA PnP detection for WaveFront soundcards.");
69 MODULE_PARM_SYNTAX(isapnp, SNDRV_ISAPNP_DESC);
70 #endif
71 module_param_array(cs4232_pcm_port, long, boot_devs, 0444);
72 MODULE_PARM_DESC(cs4232_pcm_port, "Port # for CS4232 PCM interface.");
73 MODULE_PARM_SYNTAX(cs4232_pcm_port, SNDRV_PORT12_DESC);
74 module_param_array(cs4232_pcm_irq, int, boot_devs, 0444);
75 MODULE_PARM_DESC(cs4232_pcm_irq, "IRQ # for CS4232 PCM interface.");
76 MODULE_PARM_SYNTAX(cs4232_pcm_irq, SNDRV_ENABLED ",allows:{{5},{7},{9},{11},{12},{15}},dialog:list");
77 module_param_array(dma1, int, boot_devs, 0444);
78 MODULE_PARM_DESC(dma1, "DMA1 # for CS4232 PCM interface.");
79 MODULE_PARM_SYNTAX(dma1, SNDRV_DMA_DESC);
80 module_param_array(dma2, int, boot_devs, 0444);
81 MODULE_PARM_DESC(dma2, "DMA2 # for CS4232 PCM interface.");
82 MODULE_PARM_SYNTAX(dma2, SNDRV_DMA_DESC);
83 module_param_array(cs4232_mpu_port, long, boot_devs, 0444);
84 MODULE_PARM_DESC(cs4232_mpu_port, "port # for CS4232 MPU-401 interface.");
85 MODULE_PARM_SYNTAX(cs4232_mpu_port, SNDRV_PORT12_DESC);
86 module_param_array(cs4232_mpu_irq, int, boot_devs, 0444);
87 MODULE_PARM_DESC(cs4232_mpu_irq, "IRQ # for CS4232 MPU-401 interface.");
88 MODULE_PARM_SYNTAX(cs4232_mpu_irq, SNDRV_ENABLED ",allows:{{9},{11},{12},{15}},dialog:list");
89 module_param_array(ics2115_irq, int, boot_devs, 0444);
90 MODULE_PARM_DESC(ics2115_irq, "IRQ # for ICS2115.");
91 MODULE_PARM_SYNTAX(ics2115_irq, SNDRV_ENABLED ",allows:{{9},{11},{12},{15}},dialog:list");
92 module_param_array(ics2115_port, long, boot_devs, 0444);
93 MODULE_PARM_DESC(ics2115_port, "Port # for ICS2115.");
94 MODULE_PARM_SYNTAX(ics2115_port, SNDRV_PORT12_DESC);
95 module_param_array(fm_port, long, boot_devs, 0444);
96 MODULE_PARM_DESC(fm_port, "FM port #.");
97 MODULE_PARM_SYNTAX(fm_port, SNDRV_PORT12_DESC);
98 module_param_array(use_cs4232_midi, bool, boot_devs, 0444);
99 MODULE_PARM_DESC(use_cs4232_midi, "Use CS4232 MPU-401 interface (inaccessibly located inside your computer)");
100 MODULE_PARM_SYNTAX(use_cs4232_midi, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC);
101
102 static snd_card_t *snd_wavefront_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
103
104 #ifdef CONFIG_PNP
105
106 static struct pnp_card_device_id snd_wavefront_pnpids[] = {
107         /* Tropez */
108         { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "PnPb006" }, { "CSC0004" } } },
109         /* Tropez+ */
110         { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PnPb006" }, { "CSC0004" } } },
111         { .id = "" }
112 };
113
114 MODULE_DEVICE_TABLE(pnp_card, snd_wavefront_pnpids);
115
116 static int __devinit
117 snd_wavefront_pnp (int dev, snd_wavefront_card_t *acard, struct pnp_card_link *card,
118                    const struct pnp_card_device_id *id)
119 {
120         struct pnp_dev *pdev;
121         struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
122         int err;
123
124         if (!cfg)
125                 return -ENOMEM;
126
127         /* Check for each logical device. */
128
129         /* CS4232 chip (aka "windows sound system") is logical device 0 */
130
131         acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
132         if (acard->wss == NULL) {
133                 kfree(cfg);
134                 return -EBUSY;
135         }
136
137         /* there is a game port at logical device 1, but we ignore it completely */
138
139         /* the control interface is logical device 2, but we ignore it
140            completely. in fact, nobody even seems to know what it
141            does.
142         */
143
144         /* Only configure the CS4232 MIDI interface if its been
145            specifically requested. It is logical device 3.
146         */
147
148         if (use_cs4232_midi[dev]) {
149                 acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
150                 if (acard->mpu == NULL) {
151                         kfree(cfg);
152                         return -EBUSY;
153                 }
154         }
155
156         /* The ICS2115 synth is logical device 4 */
157
158         acard->synth = pnp_request_card_device(card, id->devs[3].id, NULL);
159         if (acard->synth == NULL) {
160                 kfree(cfg);
161                 return -EBUSY;
162         }
163
164         /* PCM/FM initialization */
165
166         pdev = acard->wss;
167
168         pnp_init_resource_table(cfg);
169
170         /* An interesting note from the Tropez+ FAQ:
171
172            Q. [Ports] Why is the base address of the WSS I/O ports off by 4?
173
174            A. WSS I/O requires a block of 8 I/O addresses ("ports"). Of these, the first
175            4 are used to identify and configure the board. With the advent of PnP,
176            these first 4 addresses have become obsolete, and software applications
177            only use the last 4 addresses to control the codec chip. Therefore, the
178            base address setting "skips past" the 4 unused addresses.
179
180         */
181
182         if (cs4232_pcm_port[dev] != SNDRV_AUTO_PORT)
183                 pnp_resource_change(&cfg->port_resource[0], cs4232_pcm_port[dev], 4);
184         if (fm_port[dev] != SNDRV_AUTO_PORT)
185                 pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
186         if (dma1[dev] != SNDRV_AUTO_DMA)
187                 pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
188         if (dma2[dev] != SNDRV_AUTO_DMA)
189                 pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
190         if (cs4232_pcm_irq[dev] != SNDRV_AUTO_IRQ)
191                 pnp_resource_change(&cfg->irq_resource[0], cs4232_pcm_irq[dev], 1);
192
193         if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
194                 snd_printk(KERN_ERR "PnP WSS the requested resources are invalid, using auto config\n");
195         err = pnp_activate_dev(pdev);
196         if (err < 0) {
197                 snd_printk(KERN_ERR "PnP WSS pnp configure failure\n");
198                 kfree(cfg);
199                 return err;
200         }
201
202         cs4232_pcm_port[dev] = pnp_port_start(pdev, 0);
203         fm_port[dev] = pnp_port_start(pdev, 1);
204         dma1[dev] = pnp_dma(pdev, 0);
205         dma2[dev] = pnp_dma(pdev, 1);
206         cs4232_pcm_irq[dev] = pnp_irq(pdev, 0);
207
208         /* Synth initialization */
209
210         pdev = acard->synth;
211         
212         pnp_init_resource_table(cfg);
213
214         if (ics2115_port[dev] != SNDRV_AUTO_PORT) {
215                 pnp_resource_change(&cfg->port_resource[0], ics2115_port[dev], 16);
216         }
217                 
218         if (ics2115_port[dev] != SNDRV_AUTO_IRQ) {
219                 pnp_resource_change(&cfg->irq_resource[0], ics2115_irq[dev], 1);
220         }
221
222         if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
223                 snd_printk(KERN_ERR "PnP ICS2115 the requested resources are invalid, using auto config\n");
224         err = pnp_activate_dev(pdev);
225         if (err < 0) {
226                 snd_printk(KERN_ERR "PnP ICS2115 pnp configure failure\n");
227                 kfree(cfg);
228                 return err;
229         }
230
231         ics2115_port[dev] = pnp_port_start(pdev, 0);
232         ics2115_irq[dev] = pnp_irq(pdev, 0);
233
234         /* CS4232 MPU initialization. Configure this only if
235            explicitly requested, since its physically inaccessible and
236            consumes another IRQ.
237         */
238
239         if (use_cs4232_midi[dev]) {
240
241                 pdev = acard->mpu;
242
243                 pnp_init_resource_table(cfg);
244
245                 if (cs4232_mpu_port[dev] != SNDRV_AUTO_PORT)
246                         pnp_resource_change(&cfg->port_resource[0], cs4232_mpu_port[dev], 2);
247                 if (cs4232_mpu_irq[dev] != SNDRV_AUTO_IRQ)
248                         pnp_resource_change(&cfg->port_resource[0], cs4232_mpu_irq[dev], 1);
249
250                 if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
251                         snd_printk(KERN_ERR "PnP MPU401 the requested resources are invalid, using auto config\n");
252                 err = pnp_activate_dev(pdev);
253                 if (err < 0) {
254                         snd_printk(KERN_ERR "PnP MPU401 pnp configure failure\n");
255                         cs4232_mpu_port[dev] = SNDRV_AUTO_PORT;
256                 } else {
257                         cs4232_mpu_port[dev] = pnp_port_start(pdev, 0);
258                         cs4232_mpu_irq[dev] = pnp_irq(pdev, 0);
259                 }
260
261                 snd_printk ("CS4232 MPU: port=0x%lx, irq=%i\n", 
262                             cs4232_mpu_port[dev], 
263                             cs4232_mpu_irq[dev]);
264         }
265
266         snd_printdd ("CS4232: pcm port=0x%lx, fm port=0x%lx, dma1=%i, dma2=%i, irq=%i\nICS2115: port=0x%lx, irq=%i\n", 
267                     cs4232_pcm_port[dev], 
268                     fm_port[dev],
269                     dma1[dev], 
270                     dma2[dev], 
271                     cs4232_pcm_irq[dev],
272                     ics2115_port[dev], 
273                     ics2115_irq[dev]);
274         
275         kfree(cfg);
276         return 0;
277 }
278
279 #endif /* CONFIG_PNP */
280
281 static irqreturn_t snd_wavefront_ics2115_interrupt(int irq, 
282                                             void *dev_id, 
283                                             struct pt_regs *regs)
284 {
285         snd_wavefront_card_t *acard;
286
287         acard = (snd_wavefront_card_t *) dev_id;
288
289         if (acard == NULL) 
290                 return IRQ_NONE;
291
292         if (acard->wavefront.interrupts_are_midi) {
293                 snd_wavefront_midi_interrupt (acard);
294         } else {
295                 snd_wavefront_internal_interrupt (acard);
296         }
297         return IRQ_HANDLED;
298 }
299
300 snd_hwdep_t * __devinit
301 snd_wavefront_new_synth (snd_card_t *card,
302                          int hw_dev,
303                          snd_wavefront_card_t *acard)
304 {
305         snd_hwdep_t *wavefront_synth;
306
307         if (snd_wavefront_detect (acard) < 0) {
308                 return NULL;
309         }
310
311         if (snd_wavefront_start (&acard->wavefront) < 0) {
312                 return NULL;
313         }
314
315         if (snd_hwdep_new(card, "WaveFront", hw_dev, &wavefront_synth) < 0)
316                 return NULL;
317         strcpy (wavefront_synth->name, 
318                 "WaveFront (ICS2115) wavetable synthesizer");
319         wavefront_synth->ops.open = snd_wavefront_synth_open;
320         wavefront_synth->ops.release = snd_wavefront_synth_release;
321         wavefront_synth->ops.ioctl = snd_wavefront_synth_ioctl;
322
323         return wavefront_synth;
324 }
325
326 snd_hwdep_t * __devinit
327 snd_wavefront_new_fx (snd_card_t *card,
328                       int hw_dev,
329                       snd_wavefront_card_t *acard,
330                       unsigned long port)
331
332 {
333         snd_hwdep_t *fx_processor;
334
335         if (snd_wavefront_fx_start (&acard->wavefront)) {
336                 snd_printk ("cannot initialize YSS225 FX processor");
337                 return NULL;
338         }
339
340         if (snd_hwdep_new (card, "YSS225", hw_dev, &fx_processor) < 0)
341                 return NULL;
342         sprintf (fx_processor->name, "YSS225 FX Processor at 0x%lx", port);
343         fx_processor->ops.open = snd_wavefront_fx_open;
344         fx_processor->ops.release = snd_wavefront_fx_release;
345         fx_processor->ops.ioctl = snd_wavefront_fx_ioctl;
346         
347         return fx_processor;
348 }
349
350 static snd_wavefront_mpu_id internal_id = internal_mpu;
351 static snd_wavefront_mpu_id external_id = external_mpu;
352
353 snd_rawmidi_t * __devinit
354 snd_wavefront_new_midi (snd_card_t *card,
355                         int midi_dev,
356                         snd_wavefront_card_t *acard,
357                         unsigned long port,
358                         snd_wavefront_mpu_id mpu)
359
360 {
361         snd_rawmidi_t *rmidi;
362         static int first = 1;
363
364         if (first) {
365                 first = 0;
366                 acard->wavefront.midi.base = port;
367                 if (snd_wavefront_midi_start (acard)) {
368                         snd_printk ("cannot initialize MIDI interface\n");
369                         return NULL;
370                 }
371         }
372
373         if (snd_rawmidi_new (card, "WaveFront MIDI", midi_dev, 1, 1, &rmidi) < 0)
374                 return NULL;
375
376         if (mpu == internal_mpu) {
377                 strcpy(rmidi->name, "WaveFront MIDI (Internal)");
378                 rmidi->private_data = &internal_id;
379         } else {
380                 strcpy(rmidi->name, "WaveFront MIDI (External)");
381                 rmidi->private_data = &external_id;
382         }
383
384         snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_wavefront_midi_output);
385         snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_wavefront_midi_input);
386
387         rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
388                              SNDRV_RAWMIDI_INFO_INPUT |
389                              SNDRV_RAWMIDI_INFO_DUPLEX;
390
391         return rmidi;
392 }
393
394 static void
395 snd_wavefront_free(snd_card_t *card)
396 {
397         snd_wavefront_card_t *acard = (snd_wavefront_card_t *)card->private_data;
398         
399         if (acard) {
400                 if (acard->wavefront.res_base != NULL) {
401                         release_resource(acard->wavefront.res_base);
402                         kfree_nocheck(acard->wavefront.res_base);
403                 }
404                 if (acard->wavefront.irq > 0)
405                         free_irq(acard->wavefront.irq, (void *)acard);
406         }
407 }
408
409 static int __devinit
410 snd_wavefront_probe (int dev, struct pnp_card_link *pcard,
411                      const struct pnp_card_device_id *pid)
412 {
413         snd_card_t *card;
414         snd_wavefront_card_t *acard;
415         cs4231_t *chip;
416         snd_hwdep_t *wavefront_synth;
417         snd_rawmidi_t *ics2115_internal_rmidi = NULL;
418         snd_rawmidi_t *ics2115_external_rmidi = NULL;
419         snd_hwdep_t *fx_processor;
420         int hw_dev = 0, midi_dev = 0, err;
421
422 #ifdef CONFIG_PNP
423         if (!isapnp[dev]) {
424 #endif
425                 if (cs4232_pcm_port[dev] == SNDRV_AUTO_PORT) {
426                         snd_printk("specify CS4232 port\n");
427                         return -EINVAL;
428                 }
429                 if (ics2115_port[dev] == SNDRV_AUTO_PORT) {
430                         snd_printk("specify ICS2115 port\n");
431                         return -ENODEV;
432                 }
433 #ifdef CONFIG_PNP
434         }
435 #endif
436         card = snd_card_new (index[dev], 
437                              id[dev],
438                              THIS_MODULE,
439                              sizeof(snd_wavefront_card_t));
440
441         if (card == NULL) {
442                 return -ENOMEM;
443         }
444         acard = (snd_wavefront_card_t *)card->private_data;
445         acard->wavefront.irq = -1;
446         spin_lock_init(&acard->wavefront.irq_lock);
447         init_waitqueue_head(&acard->wavefront.interrupt_sleeper);
448         spin_lock_init(&acard->wavefront.midi.open);
449         spin_lock_init(&acard->wavefront.midi.virtual);
450         card->private_free = snd_wavefront_free;
451
452 #ifdef CONFIG_PNP
453         if (isapnp[dev]) {
454                 if (snd_wavefront_pnp (dev, acard, pcard, pid) < 0) {
455                         if (cs4232_pcm_port[dev] == SNDRV_AUTO_PORT) {
456                                 snd_printk ("isapnp detection failed\n");
457                                 snd_card_free (card);
458                                 return -ENODEV;
459                         }
460                 }
461                 snd_card_set_dev(card, &pcard->card->dev);
462         }
463 #endif /* CONFIG_PNP */
464
465         /* --------- PCM --------------- */
466
467         if ((err = snd_cs4231_create (card,
468                                       cs4232_pcm_port[dev],
469                                       -1,
470                                       cs4232_pcm_irq[dev],
471                                       dma1[dev],
472                                       dma2[dev],
473                                       CS4231_HW_DETECT, 0, &chip)) < 0) {
474                 snd_card_free(card);
475                 snd_printk ("can't allocate CS4231 device\n");
476                 return err;
477         }
478
479         if ((err = snd_cs4231_pcm (chip, 0, NULL)) < 0) {
480                 snd_card_free(card);
481                 return err;
482         }
483         if ((err = snd_cs4231_timer (chip, 0, NULL)) < 0) {
484                 snd_card_free(card);
485                 return err;
486         }
487
488         /* ---------- OPL3 synth --------- */
489
490         if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
491                 opl3_t *opl3;
492
493                 if ((err = snd_opl3_create(card,
494                                            fm_port[dev],
495                                            fm_port[dev] + 2,
496                                            OPL3_HW_OPL3_CS,
497                                            0, &opl3)) < 0) {
498                         snd_printk ("can't allocate or detect OPL3 synth\n");
499                         snd_card_free(card);
500                         return err;
501                 }
502
503                 if ((err = snd_opl3_hwdep_new(opl3, hw_dev, 1, NULL)) < 0) {
504                         snd_card_free(card);
505                         return err;
506                 }
507                 hw_dev++;
508         }
509
510         /* ------- ICS2115 Wavetable synth ------- */
511
512         if ((acard->wavefront.res_base = request_region(ics2115_port[dev], 16, "ICS2115")) == NULL) {
513                 snd_printk("unable to grab ICS2115 i/o region 0x%lx-0x%lx\n", ics2115_port[dev], ics2115_port[dev] + 16 - 1);
514                 snd_card_free(card);
515                 return -EBUSY;
516         }
517         if (request_irq(ics2115_irq[dev], snd_wavefront_ics2115_interrupt, SA_INTERRUPT, "ICS2115", (void *)acard)) {
518                 snd_printk("unable to use ICS2115 IRQ %d\n", ics2115_irq[dev]);
519                 snd_card_free(card);
520                 return -EBUSY;
521         }
522         
523         acard->wavefront.irq = ics2115_irq[dev];
524         acard->wavefront.base = ics2115_port[dev];
525
526         if ((wavefront_synth = snd_wavefront_new_synth (card, hw_dev, acard)) == NULL) {
527                 snd_printk ("can't create WaveFront synth device\n");
528                 snd_card_free(card);
529                 return -ENOMEM;
530         }
531
532         strcpy (wavefront_synth->name, "ICS2115 Wavetable MIDI Synthesizer");
533         wavefront_synth->iface = SNDRV_HWDEP_IFACE_ICS2115;
534         hw_dev++;
535
536         /* --------- Mixer ------------ */
537
538         if ((err = snd_cs4231_mixer(chip)) < 0) {
539                 snd_printk ("can't allocate mixer device\n");
540                 snd_card_free(card);
541                 return err;
542         }
543
544         /* -------- CS4232 MPU-401 interface -------- */
545
546         if (cs4232_mpu_port[dev] > 0 && cs4232_mpu_port[dev] != SNDRV_AUTO_PORT) {
547                 if ((err = snd_mpu401_uart_new(card, midi_dev, MPU401_HW_CS4232,
548                                                cs4232_mpu_port[dev], 0,
549                                                cs4232_mpu_irq[dev],
550                                                SA_INTERRUPT,
551                                                NULL)) < 0) {
552                         snd_printk ("can't allocate CS4232 MPU-401 device\n");
553                         snd_card_free(card);
554                         return err;
555                 }
556                 midi_dev++;
557         }
558
559         /* ------ ICS2115 internal MIDI ------------ */
560
561         if (ics2115_port[dev] > 0 && ics2115_port[dev] != SNDRV_AUTO_PORT) {
562                 ics2115_internal_rmidi = 
563                         snd_wavefront_new_midi (card, 
564                                                 midi_dev,
565                                                 acard,
566                                                 ics2115_port[dev],
567                                                 internal_mpu);
568                 if (ics2115_internal_rmidi == NULL) {
569                         snd_printk ("can't setup ICS2115 internal MIDI device\n");
570                         snd_card_free(card);
571                         return -ENOMEM;
572                 }
573                 midi_dev++;
574         }
575
576         /* ------ ICS2115 external MIDI ------------ */
577
578         if (ics2115_port[dev] > 0 && ics2115_port[dev] != SNDRV_AUTO_PORT) {
579                 ics2115_external_rmidi = 
580                         snd_wavefront_new_midi (card, 
581                                                 midi_dev,
582                                                 acard,
583                                                 ics2115_port[dev],
584                                                 external_mpu);
585                 if (ics2115_external_rmidi == NULL) {
586                         snd_printk ("can't setup ICS2115 external MIDI device\n");
587                         snd_card_free(card);
588                         return -ENOMEM;
589                 }
590                 midi_dev++;
591         }
592
593         /* FX processor for Tropez+ */
594
595         if (acard->wavefront.has_fx) {
596                 fx_processor = snd_wavefront_new_fx (card,
597                                                      hw_dev,
598                                                      acard,
599                                                      ics2115_port[dev]);
600                 if (fx_processor == NULL) {
601                         snd_printk ("can't setup FX device\n");
602                         snd_card_free(card);
603                         return -ENOMEM;
604                 }
605
606                 hw_dev++;
607
608                 strcpy(card->driver, "Tropez+");
609                 strcpy(card->shortname, "Turtle Beach Tropez+");
610         } else {
611                 /* Need a way to distinguish between Maui and Tropez */
612                 strcpy(card->driver, "WaveFront");
613                 strcpy(card->shortname, "Turtle Beach WaveFront");
614         }
615
616         /* ----- Register the card --------- */
617
618         /* Not safe to include "Turtle Beach" in longname, due to 
619            length restrictions
620         */
621
622         sprintf(card->longname, "%s PCM 0x%lx irq %d dma %d",
623                 card->driver,
624                 chip->port,
625                 cs4232_pcm_irq[dev],
626                 dma1[dev]);
627
628         if (dma2[dev] >= 0 && dma2[dev] < 8)
629                 sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
630
631         if (cs4232_mpu_port[dev] > 0 && cs4232_mpu_port[dev] != SNDRV_AUTO_PORT) {
632                 sprintf (card->longname + strlen (card->longname), 
633                          " MPU-401 0x%lx irq %d",
634                          cs4232_mpu_port[dev],
635                          cs4232_mpu_irq[dev]);
636         }
637
638         sprintf (card->longname + strlen (card->longname), 
639                  " SYNTH 0x%lx irq %d",
640                  ics2115_port[dev],
641                  ics2115_irq[dev]);
642
643         if ((err = snd_card_register(card)) < 0) {
644                 snd_card_free(card);
645                 return err;
646         }
647         if (pcard)
648                 pnp_set_card_drvdata(pcard, card);
649         else
650                 snd_wavefront_legacy[dev] = card;
651         return 0;
652 }       
653
654 #ifdef CONFIG_PNP
655
656 static int __devinit snd_wavefront_pnp_detect(struct pnp_card_link *card,
657                                               const struct pnp_card_device_id *id)
658 {
659         static int dev;
660         int res;
661
662         for ( ; dev < SNDRV_CARDS; dev++) {
663                 if (!enable[dev] || !isapnp[dev])
664                         continue;
665                 res = snd_wavefront_probe(dev, card, id);
666                 if (res < 0)
667                         return res;
668                 dev++;
669                 return 0;
670         }
671
672         return -ENODEV;
673 }
674
675 static void __devexit snd_wavefront_pnp_remove(struct pnp_card_link * pcard)
676 {
677         snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
678
679         snd_card_disconnect(card);
680         snd_card_free_in_thread(card);
681 }
682
683 static struct pnp_card_driver wavefront_pnpc_driver = {
684         .flags          = PNP_DRIVER_RES_DISABLE,
685         .name           = "wavefront",
686         .id_table       = snd_wavefront_pnpids,
687         .probe          = snd_wavefront_pnp_detect,
688         .remove         = __devexit_p(snd_wavefront_pnp_remove),
689 };
690
691 #endif /* CONFIG_PNP */
692
693 static int __init alsa_card_wavefront_init(void)
694 {
695         int cards = 0;
696         int dev;
697         for (dev = 0; dev < SNDRV_CARDS; dev++) {
698                 if (!enable[dev])
699                         continue;
700 #ifdef CONFIG_PNP
701                 if (isapnp[dev])
702                         continue;
703 #endif
704                 if (snd_wavefront_probe(dev, NULL, NULL) >= 0)
705                         cards++;
706         }
707 #ifdef CONFIG_PNP
708         cards += pnp_register_card_driver(&wavefront_pnpc_driver);
709 #endif
710         if (!cards) {
711 #ifdef CONFIG_PNP
712                 pnp_unregister_card_driver(&wavefront_pnpc_driver);
713 #endif
714 #ifdef MODULE
715                 printk (KERN_ERR "No WaveFront cards found or devices busy\n");
716 #endif
717                 return -ENODEV;
718         }
719         return 0;
720 }
721
722 static void __exit alsa_card_wavefront_exit(void)
723 {
724         int idx;
725
726 #ifdef CONFIG_PNP
727         pnp_unregister_card_driver(&wavefront_pnpc_driver);
728 #endif
729         for (idx = 0; idx < SNDRV_CARDS; idx++)
730                 snd_card_free(snd_wavefront_legacy[idx]);
731 }
732
733 module_init(alsa_card_wavefront_init)
734 module_exit(alsa_card_wavefront_exit)