0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/init.h>
0010 #include <linux/interrupt.h>
0011 #include <linux/err.h>
0012 #include <linux/isa.h>
0013 #include <linux/pnp.h>
0014 #include <linux/module.h>
0015 #include <sound/core.h>
0016 #include <sound/initval.h>
0017 #include <sound/opl3.h>
0018 #include <sound/wss.h>
0019 #include <sound/snd_wavefront.h>
0020
0021 MODULE_AUTHOR("Paul Barton-Davis <pbd@op.net>");
0022 MODULE_DESCRIPTION("Turtle Beach Wavefront");
0023 MODULE_LICENSE("GPL");
0024
0025 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
0026 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
0027 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
0028 #ifdef CONFIG_PNP
0029 static bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
0030 #endif
0031 static long cs4232_pcm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
0032 static int cs4232_pcm_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
0033 static long cs4232_mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
0034 static int cs4232_mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
0035 static long ics2115_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
0036 static int ics2115_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
0037 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
0038 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
0039 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
0040 static bool use_cs4232_midi[SNDRV_CARDS];
0041
0042 module_param_array(index, int, NULL, 0444);
0043 MODULE_PARM_DESC(index, "Index value for WaveFront soundcard.");
0044 module_param_array(id, charp, NULL, 0444);
0045 MODULE_PARM_DESC(id, "ID string for WaveFront soundcard.");
0046 module_param_array(enable, bool, NULL, 0444);
0047 MODULE_PARM_DESC(enable, "Enable WaveFront soundcard.");
0048 #ifdef CONFIG_PNP
0049 module_param_array(isapnp, bool, NULL, 0444);
0050 MODULE_PARM_DESC(isapnp, "ISA PnP detection for WaveFront soundcards.");
0051 #endif
0052 module_param_hw_array(cs4232_pcm_port, long, ioport, NULL, 0444);
0053 MODULE_PARM_DESC(cs4232_pcm_port, "Port # for CS4232 PCM interface.");
0054 module_param_hw_array(cs4232_pcm_irq, int, irq, NULL, 0444);
0055 MODULE_PARM_DESC(cs4232_pcm_irq, "IRQ # for CS4232 PCM interface.");
0056 module_param_hw_array(dma1, int, dma, NULL, 0444);
0057 MODULE_PARM_DESC(dma1, "DMA1 # for CS4232 PCM interface.");
0058 module_param_hw_array(dma2, int, dma, NULL, 0444);
0059 MODULE_PARM_DESC(dma2, "DMA2 # for CS4232 PCM interface.");
0060 module_param_hw_array(cs4232_mpu_port, long, ioport, NULL, 0444);
0061 MODULE_PARM_DESC(cs4232_mpu_port, "port # for CS4232 MPU-401 interface.");
0062 module_param_hw_array(cs4232_mpu_irq, int, irq, NULL, 0444);
0063 MODULE_PARM_DESC(cs4232_mpu_irq, "IRQ # for CS4232 MPU-401 interface.");
0064 module_param_hw_array(ics2115_irq, int, irq, NULL, 0444);
0065 MODULE_PARM_DESC(ics2115_irq, "IRQ # for ICS2115.");
0066 module_param_hw_array(ics2115_port, long, ioport, NULL, 0444);
0067 MODULE_PARM_DESC(ics2115_port, "Port # for ICS2115.");
0068 module_param_hw_array(fm_port, long, ioport, NULL, 0444);
0069 MODULE_PARM_DESC(fm_port, "FM port #.");
0070 module_param_array(use_cs4232_midi, bool, NULL, 0444);
0071 MODULE_PARM_DESC(use_cs4232_midi, "Use CS4232 MPU-401 interface (inaccessibly located inside your computer)");
0072
0073 #ifdef CONFIG_PNP
0074 static int isa_registered;
0075 static int pnp_registered;
0076
0077 static const struct pnp_card_device_id snd_wavefront_pnpids[] = {
0078
0079 { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "PnPb006" }, { "CSC0004" } } },
0080
0081 { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PnPb006" }, { "CSC0004" } } },
0082 { .id = "" }
0083 };
0084
0085 MODULE_DEVICE_TABLE(pnp_card, snd_wavefront_pnpids);
0086
0087 static int
0088 snd_wavefront_pnp (int dev, snd_wavefront_card_t *acard, struct pnp_card_link *card,
0089 const struct pnp_card_device_id *id)
0090 {
0091 struct pnp_dev *pdev;
0092 int err;
0093
0094
0095
0096
0097
0098 acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
0099 if (acard->wss == NULL)
0100 return -EBUSY;
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113 if (use_cs4232_midi[dev]) {
0114 acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
0115 if (acard->mpu == NULL)
0116 return -EBUSY;
0117 }
0118
0119
0120
0121 acard->synth = pnp_request_card_device(card, id->devs[3].id, NULL);
0122 if (acard->synth == NULL)
0123 return -EBUSY;
0124
0125
0126
0127 pdev = acard->wss;
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141 err = pnp_activate_dev(pdev);
0142 if (err < 0) {
0143 snd_printk(KERN_ERR "PnP WSS pnp configure failure\n");
0144 return err;
0145 }
0146
0147 cs4232_pcm_port[dev] = pnp_port_start(pdev, 0);
0148 fm_port[dev] = pnp_port_start(pdev, 1);
0149 dma1[dev] = pnp_dma(pdev, 0);
0150 dma2[dev] = pnp_dma(pdev, 1);
0151 cs4232_pcm_irq[dev] = pnp_irq(pdev, 0);
0152
0153
0154
0155 pdev = acard->synth;
0156
0157 err = pnp_activate_dev(pdev);
0158 if (err < 0) {
0159 snd_printk(KERN_ERR "PnP ICS2115 pnp configure failure\n");
0160 return err;
0161 }
0162
0163 ics2115_port[dev] = pnp_port_start(pdev, 0);
0164 ics2115_irq[dev] = pnp_irq(pdev, 0);
0165
0166
0167
0168
0169
0170
0171 if (use_cs4232_midi[dev]) {
0172
0173 pdev = acard->mpu;
0174
0175 err = pnp_activate_dev(pdev);
0176 if (err < 0) {
0177 snd_printk(KERN_ERR "PnP MPU401 pnp configure failure\n");
0178 cs4232_mpu_port[dev] = SNDRV_AUTO_PORT;
0179 } else {
0180 cs4232_mpu_port[dev] = pnp_port_start(pdev, 0);
0181 cs4232_mpu_irq[dev] = pnp_irq(pdev, 0);
0182 }
0183
0184 snd_printk (KERN_INFO "CS4232 MPU: port=0x%lx, irq=%i\n",
0185 cs4232_mpu_port[dev],
0186 cs4232_mpu_irq[dev]);
0187 }
0188
0189 snd_printdd ("CS4232: pcm port=0x%lx, fm port=0x%lx, dma1=%i, dma2=%i, irq=%i\nICS2115: port=0x%lx, irq=%i\n",
0190 cs4232_pcm_port[dev],
0191 fm_port[dev],
0192 dma1[dev],
0193 dma2[dev],
0194 cs4232_pcm_irq[dev],
0195 ics2115_port[dev],
0196 ics2115_irq[dev]);
0197
0198 return 0;
0199 }
0200
0201 #endif
0202
0203 static irqreturn_t snd_wavefront_ics2115_interrupt(int irq, void *dev_id)
0204 {
0205 snd_wavefront_card_t *acard;
0206
0207 acard = (snd_wavefront_card_t *) dev_id;
0208
0209 if (acard == NULL)
0210 return IRQ_NONE;
0211
0212 if (acard->wavefront.interrupts_are_midi) {
0213 snd_wavefront_midi_interrupt (acard);
0214 } else {
0215 snd_wavefront_internal_interrupt (acard);
0216 }
0217 return IRQ_HANDLED;
0218 }
0219
0220 static struct snd_hwdep *snd_wavefront_new_synth(struct snd_card *card,
0221 int hw_dev,
0222 snd_wavefront_card_t *acard)
0223 {
0224 struct snd_hwdep *wavefront_synth;
0225
0226 if (snd_wavefront_detect (acard) < 0) {
0227 return NULL;
0228 }
0229
0230 if (snd_wavefront_start (&acard->wavefront) < 0) {
0231 return NULL;
0232 }
0233
0234 if (snd_hwdep_new(card, "WaveFront", hw_dev, &wavefront_synth) < 0)
0235 return NULL;
0236 strcpy (wavefront_synth->name,
0237 "WaveFront (ICS2115) wavetable synthesizer");
0238 wavefront_synth->ops.open = snd_wavefront_synth_open;
0239 wavefront_synth->ops.release = snd_wavefront_synth_release;
0240 wavefront_synth->ops.ioctl = snd_wavefront_synth_ioctl;
0241
0242 return wavefront_synth;
0243 }
0244
0245 static struct snd_hwdep *snd_wavefront_new_fx(struct snd_card *card,
0246 int hw_dev,
0247 snd_wavefront_card_t *acard,
0248 unsigned long port)
0249
0250 {
0251 struct snd_hwdep *fx_processor;
0252
0253 if (snd_wavefront_fx_start (&acard->wavefront)) {
0254 snd_printk (KERN_ERR "cannot initialize YSS225 FX processor");
0255 return NULL;
0256 }
0257
0258 if (snd_hwdep_new (card, "YSS225", hw_dev, &fx_processor) < 0)
0259 return NULL;
0260 sprintf (fx_processor->name, "YSS225 FX Processor at 0x%lx", port);
0261 fx_processor->ops.open = snd_wavefront_fx_open;
0262 fx_processor->ops.release = snd_wavefront_fx_release;
0263 fx_processor->ops.ioctl = snd_wavefront_fx_ioctl;
0264
0265 return fx_processor;
0266 }
0267
0268 static snd_wavefront_mpu_id internal_id = internal_mpu;
0269 static snd_wavefront_mpu_id external_id = external_mpu;
0270
0271 static struct snd_rawmidi *snd_wavefront_new_midi(struct snd_card *card,
0272 int midi_dev,
0273 snd_wavefront_card_t *acard,
0274 unsigned long port,
0275 snd_wavefront_mpu_id mpu)
0276
0277 {
0278 struct snd_rawmidi *rmidi;
0279 static int first = 1;
0280
0281 if (first) {
0282 first = 0;
0283 acard->wavefront.midi.base = port;
0284 if (snd_wavefront_midi_start (acard)) {
0285 snd_printk (KERN_ERR "cannot initialize MIDI interface\n");
0286 return NULL;
0287 }
0288 }
0289
0290 if (snd_rawmidi_new (card, "WaveFront MIDI", midi_dev, 1, 1, &rmidi) < 0)
0291 return NULL;
0292
0293 if (mpu == internal_mpu) {
0294 strcpy(rmidi->name, "WaveFront MIDI (Internal)");
0295 rmidi->private_data = &internal_id;
0296 } else {
0297 strcpy(rmidi->name, "WaveFront MIDI (External)");
0298 rmidi->private_data = &external_id;
0299 }
0300
0301 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_wavefront_midi_output);
0302 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_wavefront_midi_input);
0303
0304 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
0305 SNDRV_RAWMIDI_INFO_INPUT |
0306 SNDRV_RAWMIDI_INFO_DUPLEX;
0307
0308 return rmidi;
0309 }
0310
0311 static int snd_wavefront_card_new(struct device *pdev, int dev,
0312 struct snd_card **cardp)
0313 {
0314 struct snd_card *card;
0315 snd_wavefront_card_t *acard;
0316 int err;
0317
0318 err = snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE,
0319 sizeof(snd_wavefront_card_t), &card);
0320 if (err < 0)
0321 return err;
0322
0323 acard = card->private_data;
0324 acard->wavefront.irq = -1;
0325 spin_lock_init(&acard->wavefront.irq_lock);
0326 init_waitqueue_head(&acard->wavefront.interrupt_sleeper);
0327 spin_lock_init(&acard->wavefront.midi.open);
0328 spin_lock_init(&acard->wavefront.midi.virtual);
0329 acard->wavefront.card = card;
0330
0331 *cardp = card;
0332 return 0;
0333 }
0334
0335 static int
0336 snd_wavefront_probe (struct snd_card *card, int dev)
0337 {
0338 snd_wavefront_card_t *acard = card->private_data;
0339 struct snd_wss *chip;
0340 struct snd_hwdep *wavefront_synth;
0341 struct snd_rawmidi *ics2115_internal_rmidi = NULL;
0342 struct snd_rawmidi *ics2115_external_rmidi = NULL;
0343 struct snd_hwdep *fx_processor;
0344 int hw_dev = 0, midi_dev = 0, err;
0345
0346
0347
0348 err = snd_wss_create(card, cs4232_pcm_port[dev], -1,
0349 cs4232_pcm_irq[dev], dma1[dev], dma2[dev],
0350 WSS_HW_DETECT, 0, &chip);
0351 if (err < 0) {
0352 snd_printk(KERN_ERR "can't allocate WSS device\n");
0353 return err;
0354 }
0355
0356 err = snd_wss_pcm(chip, 0);
0357 if (err < 0)
0358 return err;
0359
0360 err = snd_wss_timer(chip, 0);
0361 if (err < 0)
0362 return err;
0363
0364
0365
0366 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
0367 struct snd_opl3 *opl3;
0368
0369 err = snd_opl3_create(card, fm_port[dev], fm_port[dev] + 2,
0370 OPL3_HW_OPL3_CS, 0, &opl3);
0371 if (err < 0) {
0372 snd_printk (KERN_ERR "can't allocate or detect OPL3 synth\n");
0373 return err;
0374 }
0375
0376 err = snd_opl3_hwdep_new(opl3, hw_dev, 1, NULL);
0377 if (err < 0)
0378 return err;
0379 hw_dev++;
0380 }
0381
0382
0383
0384 acard->wavefront.res_base =
0385 devm_request_region(card->dev, ics2115_port[dev], 16,
0386 "ICS2115");
0387 if (acard->wavefront.res_base == NULL) {
0388 snd_printk(KERN_ERR "unable to grab ICS2115 i/o region 0x%lx-0x%lx\n",
0389 ics2115_port[dev], ics2115_port[dev] + 16 - 1);
0390 return -EBUSY;
0391 }
0392 if (devm_request_irq(card->dev, ics2115_irq[dev],
0393 snd_wavefront_ics2115_interrupt,
0394 0, "ICS2115", acard)) {
0395 snd_printk(KERN_ERR "unable to use ICS2115 IRQ %d\n", ics2115_irq[dev]);
0396 return -EBUSY;
0397 }
0398
0399 acard->wavefront.irq = ics2115_irq[dev];
0400 card->sync_irq = acard->wavefront.irq;
0401 acard->wavefront.base = ics2115_port[dev];
0402
0403 wavefront_synth = snd_wavefront_new_synth(card, hw_dev, acard);
0404 if (wavefront_synth == NULL) {
0405 snd_printk (KERN_ERR "can't create WaveFront synth device\n");
0406 return -ENOMEM;
0407 }
0408
0409 strcpy (wavefront_synth->name, "ICS2115 Wavetable MIDI Synthesizer");
0410 wavefront_synth->iface = SNDRV_HWDEP_IFACE_ICS2115;
0411 hw_dev++;
0412
0413
0414
0415 err = snd_wss_mixer(chip);
0416 if (err < 0) {
0417 snd_printk (KERN_ERR "can't allocate mixer device\n");
0418 return err;
0419 }
0420
0421
0422
0423 if (cs4232_mpu_port[dev] > 0 && cs4232_mpu_port[dev] != SNDRV_AUTO_PORT) {
0424 err = snd_mpu401_uart_new(card, midi_dev, MPU401_HW_CS4232,
0425 cs4232_mpu_port[dev], 0,
0426 cs4232_mpu_irq[dev], NULL);
0427 if (err < 0) {
0428 snd_printk (KERN_ERR "can't allocate CS4232 MPU-401 device\n");
0429 return err;
0430 }
0431 midi_dev++;
0432 }
0433
0434
0435
0436 if (ics2115_port[dev] > 0 && ics2115_port[dev] != SNDRV_AUTO_PORT) {
0437 ics2115_internal_rmidi =
0438 snd_wavefront_new_midi (card,
0439 midi_dev,
0440 acard,
0441 ics2115_port[dev],
0442 internal_mpu);
0443 if (ics2115_internal_rmidi == NULL) {
0444 snd_printk (KERN_ERR "can't setup ICS2115 internal MIDI device\n");
0445 return -ENOMEM;
0446 }
0447 midi_dev++;
0448 }
0449
0450
0451
0452 if (ics2115_port[dev] > 0 && ics2115_port[dev] != SNDRV_AUTO_PORT) {
0453 ics2115_external_rmidi =
0454 snd_wavefront_new_midi (card,
0455 midi_dev,
0456 acard,
0457 ics2115_port[dev],
0458 external_mpu);
0459 if (ics2115_external_rmidi == NULL) {
0460 snd_printk (KERN_ERR "can't setup ICS2115 external MIDI device\n");
0461 return -ENOMEM;
0462 }
0463 midi_dev++;
0464 }
0465
0466
0467
0468 if (acard->wavefront.has_fx) {
0469 fx_processor = snd_wavefront_new_fx (card,
0470 hw_dev,
0471 acard,
0472 ics2115_port[dev]);
0473 if (fx_processor == NULL) {
0474 snd_printk (KERN_ERR "can't setup FX device\n");
0475 return -ENOMEM;
0476 }
0477
0478 hw_dev++;
0479
0480 strcpy(card->driver, "Tropez+");
0481 strcpy(card->shortname, "Turtle Beach Tropez+");
0482 } else {
0483
0484 strcpy(card->driver, "WaveFront");
0485 strcpy(card->shortname, "Turtle Beach WaveFront");
0486 }
0487
0488
0489
0490
0491
0492
0493
0494 sprintf(card->longname, "%s PCM 0x%lx irq %d dma %d",
0495 card->driver,
0496 chip->port,
0497 cs4232_pcm_irq[dev],
0498 dma1[dev]);
0499
0500 if (dma2[dev] >= 0 && dma2[dev] < 8)
0501 sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
0502
0503 if (cs4232_mpu_port[dev] > 0 && cs4232_mpu_port[dev] != SNDRV_AUTO_PORT) {
0504 sprintf (card->longname + strlen (card->longname),
0505 " MPU-401 0x%lx irq %d",
0506 cs4232_mpu_port[dev],
0507 cs4232_mpu_irq[dev]);
0508 }
0509
0510 sprintf (card->longname + strlen (card->longname),
0511 " SYNTH 0x%lx irq %d",
0512 ics2115_port[dev],
0513 ics2115_irq[dev]);
0514
0515 return snd_card_register(card);
0516 }
0517
0518 static int snd_wavefront_isa_match(struct device *pdev,
0519 unsigned int dev)
0520 {
0521 if (!enable[dev])
0522 return 0;
0523 #ifdef CONFIG_PNP
0524 if (isapnp[dev])
0525 return 0;
0526 #endif
0527 if (cs4232_pcm_port[dev] == SNDRV_AUTO_PORT) {
0528 snd_printk(KERN_ERR "specify CS4232 port\n");
0529 return 0;
0530 }
0531 if (ics2115_port[dev] == SNDRV_AUTO_PORT) {
0532 snd_printk(KERN_ERR "specify ICS2115 port\n");
0533 return 0;
0534 }
0535 return 1;
0536 }
0537
0538 static int snd_wavefront_isa_probe(struct device *pdev,
0539 unsigned int dev)
0540 {
0541 struct snd_card *card;
0542 int err;
0543
0544 err = snd_wavefront_card_new(pdev, dev, &card);
0545 if (err < 0)
0546 return err;
0547 err = snd_wavefront_probe(card, dev);
0548 if (err < 0)
0549 return err;
0550
0551 dev_set_drvdata(pdev, card);
0552 return 0;
0553 }
0554
0555 #define DEV_NAME "wavefront"
0556
0557 static struct isa_driver snd_wavefront_driver = {
0558 .match = snd_wavefront_isa_match,
0559 .probe = snd_wavefront_isa_probe,
0560
0561 .driver = {
0562 .name = DEV_NAME
0563 },
0564 };
0565
0566
0567 #ifdef CONFIG_PNP
0568 static int snd_wavefront_pnp_detect(struct pnp_card_link *pcard,
0569 const struct pnp_card_device_id *pid)
0570 {
0571 static int dev;
0572 struct snd_card *card;
0573 int res;
0574
0575 for ( ; dev < SNDRV_CARDS; dev++) {
0576 if (enable[dev] && isapnp[dev])
0577 break;
0578 }
0579 if (dev >= SNDRV_CARDS)
0580 return -ENODEV;
0581
0582 res = snd_wavefront_card_new(&pcard->card->dev, dev, &card);
0583 if (res < 0)
0584 return res;
0585
0586 if (snd_wavefront_pnp (dev, card->private_data, pcard, pid) < 0) {
0587 if (cs4232_pcm_port[dev] == SNDRV_AUTO_PORT) {
0588 snd_printk (KERN_ERR "isapnp detection failed\n");
0589 return -ENODEV;
0590 }
0591 }
0592
0593 res = snd_wavefront_probe(card, dev);
0594 if (res < 0)
0595 return res;
0596
0597 pnp_set_card_drvdata(pcard, card);
0598 dev++;
0599 return 0;
0600 }
0601
0602 static struct pnp_card_driver wavefront_pnpc_driver = {
0603 .flags = PNP_DRIVER_RES_DISABLE,
0604 .name = "wavefront",
0605 .id_table = snd_wavefront_pnpids,
0606 .probe = snd_wavefront_pnp_detect,
0607
0608 };
0609
0610 #endif
0611
0612 static int __init alsa_card_wavefront_init(void)
0613 {
0614 int err;
0615
0616 err = isa_register_driver(&snd_wavefront_driver, SNDRV_CARDS);
0617 #ifdef CONFIG_PNP
0618 if (!err)
0619 isa_registered = 1;
0620
0621 err = pnp_register_card_driver(&wavefront_pnpc_driver);
0622 if (!err)
0623 pnp_registered = 1;
0624
0625 if (isa_registered)
0626 err = 0;
0627 #endif
0628 return err;
0629 }
0630
0631 static void __exit alsa_card_wavefront_exit(void)
0632 {
0633 #ifdef CONFIG_PNP
0634 if (pnp_registered)
0635 pnp_unregister_card_driver(&wavefront_pnpc_driver);
0636 if (isa_registered)
0637 #endif
0638 isa_unregister_driver(&snd_wavefront_driver);
0639 }
0640
0641 module_init(alsa_card_wavefront_init)
0642 module_exit(alsa_card_wavefront_exit)