1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*********************************************************************
4 * Linux multisound pinnacle/fiji driver for ALSA.
6 * 2002/06/30 Karsten Wiese:
7 * for now this is only used to build a pinnacle / fiji driver.
8 * the OSS parent of this code is designed to also support
9 * the multisound classic via the file msnd_classic.c.
10 * to make it easier for some brave heart to implemt classic
11 * support in alsa, i left all the MSND_CLASSIC tokens in this file.
12 * but for now this untested & undone.
14 * ripped from linux kernel 2.4.18 by Karsten Wiese.
16 * the following is a copy of the 2.4.18 OSS FREE file-heading comment:
18 * Turtle Beach MultiSound Sound Card Driver for Linux
19 * msnd_pinnacle.c / msnd_classic.c
21 * -- If MSND_CLASSIC is defined:
23 * -> driver for Turtle Beach Classic/Monterey/Tahiti
27 * -> driver for Turtle Beach Pinnacle/Fiji
29 * 12-3-2000 Modified IO port validation Steve Sycamore
31 * Copyright (C) 1998 Andrew Veliath
33 ********************************************************************/
35 #include <linux/kernel.h>
36 #include <linux/module.h>
37 #include <linux/interrupt.h>
38 #include <linux/types.h>
39 #include <linux/delay.h>
40 #include <linux/ioport.h>
41 #include <linux/firmware.h>
42 #include <linux/isa.h>
43 #include <linux/isapnp.h>
44 #include <linux/irq.h>
47 #include <sound/core.h>
48 #include <sound/initval.h>
49 #include <sound/asound.h>
50 #include <sound/pcm.h>
51 #include <sound/mpu401.h>
60 # include "msnd_classic.h"
61 # define LOGNAME "msnd_classic"
62 # define DEV_NAME "msnd-classic"
64 # include "msnd_pinnacle.h"
65 # define LOGNAME "snd_msnd_pinnacle"
66 # define DEV_NAME "msnd-pinnacle"
69 static void set_default_audio_parameters(struct snd_msnd *chip)
71 chip->play_sample_size = snd_pcm_format_width(DEFSAMPLESIZE);
72 chip->play_sample_rate = DEFSAMPLERATE;
73 chip->play_channels = DEFCHANNELS;
74 chip->capture_sample_size = snd_pcm_format_width(DEFSAMPLESIZE);
75 chip->capture_sample_rate = DEFSAMPLERATE;
76 chip->capture_channels = DEFCHANNELS;
79 static void snd_msnd_eval_dsp_msg(struct snd_msnd *chip, u16 wMessage)
81 switch (HIBYTE(wMessage)) {
82 case HIMT_PLAY_DONE: {
83 if (chip->banksPlayed < 3)
84 snd_printdd("%08X: HIMT_PLAY_DONE: %i\n",
85 (unsigned)jiffies, LOBYTE(wMessage));
87 if (chip->last_playbank == LOBYTE(wMessage)) {
88 snd_printdd("chip.last_playbank == LOBYTE(wMessage)\n");
93 if (test_bit(F_WRITING, &chip->flags))
94 snd_msnd_DAPQ(chip, 0);
96 chip->last_playbank = LOBYTE(wMessage);
97 chip->playDMAPos += chip->play_period_bytes;
98 if (chip->playDMAPos > chip->playLimit)
100 snd_pcm_period_elapsed(chip->playback_substream);
104 case HIMT_RECORD_DONE:
105 if (chip->last_recbank == LOBYTE(wMessage))
107 chip->last_recbank = LOBYTE(wMessage);
108 chip->captureDMAPos += chip->capturePeriodBytes;
109 if (chip->captureDMAPos > (chip->captureLimit))
110 chip->captureDMAPos = 0;
112 if (test_bit(F_READING, &chip->flags))
113 snd_msnd_DARQ(chip, chip->last_recbank);
115 snd_pcm_period_elapsed(chip->capture_substream);
119 switch (LOBYTE(wMessage)) {
121 case HIDSP_PLAY_UNDER:
123 case HIDSP_INT_PLAY_UNDER:
124 snd_printd(KERN_WARNING LOGNAME ": Play underflow %i\n",
126 if (chip->banksPlayed > 2)
127 clear_bit(F_WRITING, &chip->flags);
130 case HIDSP_INT_RECORD_OVER:
131 snd_printd(KERN_WARNING LOGNAME ": Record overflow\n");
132 clear_bit(F_READING, &chip->flags);
136 snd_printd(KERN_WARNING LOGNAME
137 ": DSP message %d 0x%02x\n",
138 LOBYTE(wMessage), LOBYTE(wMessage));
143 case HIMT_MIDI_IN_UCHAR:
144 if (chip->msndmidi_mpu)
145 snd_msndmidi_input_read(chip->msndmidi_mpu);
149 snd_printd(KERN_WARNING LOGNAME ": HIMT message %d 0x%02x\n",
150 HIBYTE(wMessage), HIBYTE(wMessage));
155 static irqreturn_t snd_msnd_interrupt(int irq, void *dev_id)
157 struct snd_msnd *chip = dev_id;
158 void __iomem *pwDSPQData = chip->mappedbase + DSPQ_DATA_BUFF;
159 u16 head, tail, size;
161 /* Send ack to DSP */
162 /* inb(chip->io + HP_RXL); */
164 /* Evaluate queued DSP messages */
165 head = readw(chip->DSPQ + JQS_wHead);
166 tail = readw(chip->DSPQ + JQS_wTail);
167 size = readw(chip->DSPQ + JQS_wSize);
168 if (head > size || tail > size)
170 while (head != tail) {
171 snd_msnd_eval_dsp_msg(chip, readw(pwDSPQData + 2 * head));
174 writew(head, chip->DSPQ + JQS_wHead);
177 /* Send ack to DSP */
178 inb(chip->io + HP_RXL);
183 static int snd_msnd_reset_dsp(long io, unsigned char *info)
187 outb(HPDSPRESET_ON, io + HP_DSPR);
191 *info = inb(io + HP_INFO);
193 outb(HPDSPRESET_OFF, io + HP_DSPR);
195 while (timeout-- > 0) {
196 if (inb(io + HP_CVR) == HP_CVR_DEF)
200 snd_printk(KERN_ERR LOGNAME ": Cannot reset DSP\n");
205 static int snd_msnd_probe(struct snd_card *card)
207 struct snd_msnd *chip = card->private_data;
210 char *xv, *rev = NULL;
211 char *pin = "TB Pinnacle", *fiji = "TB Fiji";
212 char *pinfiji = "TB Pinnacle/Fiji";
215 if (!request_region(chip->io, DSP_NUMIO, "probing")) {
216 snd_printk(KERN_ERR LOGNAME ": I/O port conflict\n");
220 if (snd_msnd_reset_dsp(chip->io, &info) < 0) {
221 release_region(chip->io, DSP_NUMIO);
226 strcpy(card->shortname, "Classic/Tahiti/Monterey");
227 strcpy(card->longname, "Turtle Beach Multisound");
228 printk(KERN_INFO LOGNAME ": %s, "
229 "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n",
231 chip->io, chip->io + DSP_NUMIO - 1,
233 chip->base, chip->base + 0x7fff);
253 switch (info & 0x7) {
256 strcpy(card->shortname, pin);
260 strcpy(card->shortname, pin);
264 strcpy(card->shortname, pin);
268 strcpy(card->shortname, pin);
272 strcpy(card->shortname, fiji);
276 strcpy(card->shortname, fiji);
280 strcpy(card->shortname, fiji);
283 rev = "A-B (Fiji) or A-E (Pinnacle)";
284 strcpy(card->shortname, pinfiji);
287 strcpy(card->longname, "Turtle Beach Multisound Pinnacle");
288 printk(KERN_INFO LOGNAME ": %s revision %s, Xilinx version %s, "
289 "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n",
292 chip->io, chip->io + DSP_NUMIO - 1,
294 chip->base, chip->base + 0x7fff);
297 release_region(chip->io, DSP_NUMIO);
301 static int snd_msnd_init_sma(struct snd_msnd *chip)
304 u16 mastVolLeft, mastVolRight;
308 outb(chip->memid, chip->io + HP_MEMM);
310 outb(HPBLKSEL_0, chip->io + HP_BLKS);
311 /* Motorola 56k shared memory base */
312 chip->SMA = chip->mappedbase + SMA_STRUCT_START;
315 mastVolLeft = readw(chip->SMA + SMA_wCurrMastVolLeft);
316 mastVolRight = readw(chip->SMA + SMA_wCurrMastVolRight);
318 mastVolLeft = mastVolRight = 0;
319 memset_io(chip->mappedbase, 0, 0x8000);
321 /* Critical section: bank 1 access */
322 spin_lock_irqsave(&chip->lock, flags);
323 outb(HPBLKSEL_1, chip->io + HP_BLKS);
324 memset_io(chip->mappedbase, 0, 0x8000);
325 outb(HPBLKSEL_0, chip->io + HP_BLKS);
326 spin_unlock_irqrestore(&chip->lock, flags);
328 /* Digital audio play queue */
329 chip->DAPQ = chip->mappedbase + DAPQ_OFFSET;
330 snd_msnd_init_queue(chip->DAPQ, DAPQ_DATA_BUFF, DAPQ_BUFF_SIZE);
332 /* Digital audio record queue */
333 chip->DARQ = chip->mappedbase + DARQ_OFFSET;
334 snd_msnd_init_queue(chip->DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE);
337 chip->MODQ = chip->mappedbase + MODQ_OFFSET;
338 snd_msnd_init_queue(chip->MODQ, MODQ_DATA_BUFF, MODQ_BUFF_SIZE);
341 chip->MIDQ = chip->mappedbase + MIDQ_OFFSET;
342 snd_msnd_init_queue(chip->MIDQ, MIDQ_DATA_BUFF, MIDQ_BUFF_SIZE);
344 /* DSP -> host message queue */
345 chip->DSPQ = chip->mappedbase + DSPQ_OFFSET;
346 snd_msnd_init_queue(chip->DSPQ, DSPQ_DATA_BUFF, DSPQ_BUFF_SIZE);
348 /* Setup some DSP values */
350 writew(1, chip->SMA + SMA_wCurrPlayFormat);
351 writew(chip->play_sample_size, chip->SMA + SMA_wCurrPlaySampleSize);
352 writew(chip->play_channels, chip->SMA + SMA_wCurrPlayChannels);
353 writew(chip->play_sample_rate, chip->SMA + SMA_wCurrPlaySampleRate);
355 writew(chip->play_sample_rate, chip->SMA + SMA_wCalFreqAtoD);
356 writew(mastVolLeft, chip->SMA + SMA_wCurrMastVolLeft);
357 writew(mastVolRight, chip->SMA + SMA_wCurrMastVolRight);
359 writel(0x00010000, chip->SMA + SMA_dwCurrPlayPitch);
360 writel(0x00000001, chip->SMA + SMA_dwCurrPlayRate);
362 writew(0x303, chip->SMA + SMA_wCurrInputTagBits);
370 static int upload_dsp_code(struct snd_card *card)
372 struct snd_msnd *chip = card->private_data;
373 const struct firmware *init_fw = NULL, *perm_fw = NULL;
376 outb(HPBLKSEL_0, chip->io + HP_BLKS);
378 err = request_firmware(&init_fw, INITCODEFILE, card->dev);
380 printk(KERN_ERR LOGNAME ": Error loading " INITCODEFILE);
383 err = request_firmware(&perm_fw, PERMCODEFILE, card->dev);
385 printk(KERN_ERR LOGNAME ": Error loading " PERMCODEFILE);
389 memcpy_toio(chip->mappedbase, perm_fw->data, perm_fw->size);
390 if (snd_msnd_upload_host(chip, init_fw->data, init_fw->size) < 0) {
391 printk(KERN_WARNING LOGNAME ": Error uploading to DSP\n");
395 printk(KERN_INFO LOGNAME ": DSP firmware uploaded\n");
399 release_firmware(perm_fw);
401 release_firmware(init_fw);
406 static void reset_proteus(struct snd_msnd *chip)
408 outb(HPPRORESET_ON, chip->io + HP_PROR);
409 msleep(TIME_PRO_RESET);
410 outb(HPPRORESET_OFF, chip->io + HP_PROR);
411 msleep(TIME_PRO_RESET_DONE);
415 static int snd_msnd_initialize(struct snd_card *card)
417 struct snd_msnd *chip = card->private_data;
421 outb(HPWAITSTATE_0, chip->io + HP_WAIT);
422 outb(HPBITMODE_16, chip->io + HP_BITM);
426 err = snd_msnd_init_sma(chip);
428 printk(KERN_WARNING LOGNAME ": Cannot initialize SMA\n");
432 err = snd_msnd_reset_dsp(chip->io, NULL);
436 err = upload_dsp_code(card);
438 printk(KERN_WARNING LOGNAME ": Cannot upload DSP code\n");
444 while (readw(chip->mappedbase)) {
447 snd_printd(KERN_ERR LOGNAME ": DSP reset timeout\n");
452 snd_msndmix_setup(chip);
456 static int snd_msnd_dsp_full_reset(struct snd_card *card)
458 struct snd_msnd *chip = card->private_data;
461 if (test_bit(F_RESETTING, &chip->flags) || ++chip->nresets > 10)
464 set_bit(F_RESETTING, &chip->flags);
465 snd_msnd_dsp_halt(chip, NULL); /* Unconditionally halt */
467 rv = snd_msnd_initialize(card);
469 printk(KERN_WARNING LOGNAME ": DSP reset failed\n");
470 snd_msndmix_force_recsrc(chip, 0);
471 clear_bit(F_RESETTING, &chip->flags);
476 static int snd_msnd_send_dsp_cmd_chk(struct snd_msnd *chip, u8 cmd)
478 if (snd_msnd_send_dsp_cmd(chip, cmd) == 0)
480 snd_msnd_dsp_full_reset(chip->card);
481 return snd_msnd_send_dsp_cmd(chip, cmd);
484 static int snd_msnd_calibrate_adc(struct snd_msnd *chip, u16 srate)
486 snd_printdd("snd_msnd_calibrate_adc(%i)\n", srate);
487 writew(srate, chip->SMA + SMA_wCalFreqAtoD);
488 if (chip->calibrate_signal == 0)
489 writew(readw(chip->SMA + SMA_wCurrHostStatusFlags)
490 | 0x0001, chip->SMA + SMA_wCurrHostStatusFlags);
492 writew(readw(chip->SMA + SMA_wCurrHostStatusFlags)
493 & ~0x0001, chip->SMA + SMA_wCurrHostStatusFlags);
494 if (snd_msnd_send_word(chip, 0, 0, HDEXAR_CAL_A_TO_D) == 0 &&
495 snd_msnd_send_dsp_cmd_chk(chip, HDEX_AUX_REQ) == 0) {
496 schedule_timeout_interruptible(msecs_to_jiffies(333));
499 printk(KERN_WARNING LOGNAME ": ADC calibration failed\n");
504 * ALSA callback function, called when attempting to open the MIDI device.
506 static int snd_msnd_mpu401_open(struct snd_mpu401 *mpu)
508 snd_msnd_enable_irq(mpu->private_data);
509 snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_START);
513 static void snd_msnd_mpu401_close(struct snd_mpu401 *mpu)
515 snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_STOP);
516 snd_msnd_disable_irq(mpu->private_data);
519 static long mpu_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
520 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
522 static int snd_msnd_attach(struct snd_card *card)
524 struct snd_msnd *chip = card->private_data;
527 err = devm_request_irq(card->dev, chip->irq, snd_msnd_interrupt, 0,
528 card->shortname, chip);
530 printk(KERN_ERR LOGNAME ": Couldn't grab IRQ %d\n", chip->irq);
533 card->sync_irq = chip->irq;
534 if (!devm_request_region(card->dev, chip->io, DSP_NUMIO,
538 if (!devm_request_mem_region(card->dev, chip->base, BUFFSIZE,
540 printk(KERN_ERR LOGNAME
541 ": unable to grab memory region 0x%lx-0x%lx\n",
542 chip->base, chip->base + BUFFSIZE - 1);
545 chip->mappedbase = devm_ioremap(card->dev, chip->base, 0x8000);
546 if (!chip->mappedbase) {
547 printk(KERN_ERR LOGNAME
548 ": unable to map memory region 0x%lx-0x%lx\n",
549 chip->base, chip->base + BUFFSIZE - 1);
553 err = snd_msnd_dsp_full_reset(card);
557 err = snd_msnd_pcm(card, 0);
559 printk(KERN_ERR LOGNAME ": error creating new PCM device\n");
563 err = snd_msndmix_new(card);
565 printk(KERN_ERR LOGNAME ": error creating new Mixer device\n");
570 if (mpu_io[0] != SNDRV_AUTO_PORT) {
571 struct snd_mpu401 *mpu;
573 err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
580 printk(KERN_ERR LOGNAME
581 ": error creating new Midi device\n");
584 mpu = chip->rmidi->private_data;
586 mpu->open_input = snd_msnd_mpu401_open;
587 mpu->close_input = snd_msnd_mpu401_close;
588 mpu->private_data = chip;
591 disable_irq(chip->irq);
592 snd_msnd_calibrate_adc(chip, chip->play_sample_rate);
593 snd_msndmix_force_recsrc(chip, 0);
595 err = snd_card_register(card);
605 /* Pinnacle/Fiji Logical Device Configuration */
607 static int snd_msnd_write_cfg(int cfg, int reg, int value)
610 outb(value, cfg + 1);
611 if (value != inb(cfg + 1)) {
612 printk(KERN_ERR LOGNAME ": snd_msnd_write_cfg: I/O error\n");
618 static int snd_msnd_write_cfg_io0(int cfg, int num, u16 io)
620 if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
622 if (snd_msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io)))
624 if (snd_msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io)))
629 static int snd_msnd_write_cfg_io1(int cfg, int num, u16 io)
631 if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
633 if (snd_msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io)))
635 if (snd_msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io)))
640 static int snd_msnd_write_cfg_irq(int cfg, int num, u16 irq)
642 if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
644 if (snd_msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq)))
646 if (snd_msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE))
651 static int snd_msnd_write_cfg_mem(int cfg, int num, int mem)
656 wmem = (u16)(mem & 0xfff);
657 if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
659 if (snd_msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem)))
661 if (snd_msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem)))
663 if (wmem && snd_msnd_write_cfg(cfg, IREG_MEMCONTROL,
664 MEMTYPE_HIADDR | MEMTYPE_16BIT))
669 static int snd_msnd_activate_logical(int cfg, int num)
671 if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
673 if (snd_msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE))
678 static int snd_msnd_write_cfg_logical(int cfg, int num, u16 io0,
679 u16 io1, u16 irq, int mem)
681 if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
683 if (snd_msnd_write_cfg_io0(cfg, num, io0))
685 if (snd_msnd_write_cfg_io1(cfg, num, io1))
687 if (snd_msnd_write_cfg_irq(cfg, num, irq))
689 if (snd_msnd_write_cfg_mem(cfg, num, mem))
691 if (snd_msnd_activate_logical(cfg, num))
696 static int snd_msnd_pinnacle_cfg_reset(int cfg)
700 /* Reset devices if told to */
701 printk(KERN_INFO LOGNAME ": Resetting all devices\n");
702 for (i = 0; i < 4; ++i)
703 if (snd_msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0))
710 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
711 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
713 module_param_array(index, int, NULL, 0444);
714 MODULE_PARM_DESC(index, "Index value for msnd_pinnacle soundcard.");
715 module_param_array(id, charp, NULL, 0444);
716 MODULE_PARM_DESC(id, "ID string for msnd_pinnacle soundcard.");
718 static long io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
719 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
720 static long mem[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
723 static long cfg[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
725 /* Extra Peripheral Configuration (Default: Disable) */
726 static long ide_io0[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
727 static long ide_io1[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
728 static int ide_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
730 static long joystick_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
731 /* If we have the digital daugherboard... */
732 static int digital[SNDRV_CARDS];
734 /* Extra Peripheral Configuration */
735 static int reset[SNDRV_CARDS];
738 static int write_ndelay[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 1 };
740 static int calibrate_signal;
743 static bool isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
744 module_param_array(isapnp, bool, NULL, 0444);
745 MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
746 #define has_isapnp(x) isapnp[x]
748 #define has_isapnp(x) 0
751 MODULE_AUTHOR("Karsten Wiese <annabellesgarden@yahoo.de>");
752 MODULE_DESCRIPTION("Turtle Beach " LONGNAME " Linux Driver");
753 MODULE_LICENSE("GPL");
754 MODULE_FIRMWARE(INITCODEFILE);
755 MODULE_FIRMWARE(PERMCODEFILE);
757 module_param_hw_array(io, long, ioport, NULL, 0444);
758 MODULE_PARM_DESC(io, "IO port #");
759 module_param_hw_array(irq, int, irq, NULL, 0444);
760 module_param_hw_array(mem, long, iomem, NULL, 0444);
761 module_param_array(write_ndelay, int, NULL, 0444);
762 module_param(calibrate_signal, int, 0444);
764 module_param_array(digital, int, NULL, 0444);
765 module_param_hw_array(cfg, long, ioport, NULL, 0444);
766 module_param_array(reset, int, NULL, 0444);
767 module_param_hw_array(mpu_io, long, ioport, NULL, 0444);
768 module_param_hw_array(mpu_irq, int, irq, NULL, 0444);
769 module_param_hw_array(ide_io0, long, ioport, NULL, 0444);
770 module_param_hw_array(ide_io1, long, ioport, NULL, 0444);
771 module_param_hw_array(ide_irq, int, irq, NULL, 0444);
772 module_param_hw_array(joystick_io, long, ioport, NULL, 0444);
776 static int snd_msnd_isa_match(struct device *pdev, unsigned int i)
778 if (io[i] == SNDRV_AUTO_PORT)
781 if (irq[i] == SNDRV_AUTO_PORT || mem[i] == SNDRV_AUTO_PORT) {
782 printk(KERN_WARNING LOGNAME ": io, irq and mem must be set\n");
787 if (!(io[i] == 0x290 ||
795 printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set "
796 " to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, "
801 if (io[i] < 0x100 || io[i] > 0x3e0 || (io[i] % 0x10) != 0) {
802 printk(KERN_ERR LOGNAME
803 ": \"io\" - DSP I/O base must within the range 0x100 "
804 "to 0x3E0 and must be evenly divisible by 0x10\n");
807 #endif /* MSND_CLASSIC */
815 printk(KERN_ERR LOGNAME
816 ": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n");
820 if (!(mem[i] == 0xb0000 ||
825 mem[i] == 0xe8000)) {
826 printk(KERN_ERR LOGNAME ": \"mem\" - must be set to "
827 "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or "
833 if (cfg[i] == SNDRV_AUTO_PORT) {
834 printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
835 } else if (cfg[i] != 0x250 && cfg[i] != 0x260 && cfg[i] != 0x270) {
836 printk(KERN_INFO LOGNAME
837 ": Config port must be 0x250, 0x260 or 0x270 "
838 "(or unspecified for PnP mode)\n");
841 #endif /* MSND_CLASSIC */
846 static int snd_msnd_isa_probe(struct device *pdev, unsigned int idx)
849 struct snd_card *card;
850 struct snd_msnd *chip;
854 || cfg[idx] == SNDRV_AUTO_PORT
857 printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
861 err = snd_devm_card_new(pdev, index[idx], id[idx], THIS_MODULE,
862 sizeof(struct snd_msnd), &card);
866 chip = card->private_data;
872 chip->irqid = HPIRQ_5; break;
874 chip->irqid = HPIRQ_7; break;
876 chip->irqid = HPIRQ_9; break;
878 chip->irqid = HPIRQ_10; break;
880 chip->irqid = HPIRQ_11; break;
882 chip->irqid = HPIRQ_12; break;
887 chip->memid = HPMEM_B000; break;
889 chip->memid = HPMEM_C800; break;
891 chip->memid = HPMEM_D000; break;
893 chip->memid = HPMEM_D800; break;
895 chip->memid = HPMEM_E000; break;
897 chip->memid = HPMEM_E800; break;
900 printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%lx\n",
903 if (!devm_request_region(card->dev, cfg[idx], 2,
904 "Pinnacle/Fiji Config")) {
905 printk(KERN_ERR LOGNAME ": Config port 0x%lx conflict\n",
910 if (snd_msnd_pinnacle_cfg_reset(cfg[idx]))
914 err = snd_msnd_write_cfg_logical(cfg[idx], 0,
921 /* The following are Pinnacle specific */
924 if (mpu_io[idx] != SNDRV_AUTO_PORT
925 && mpu_irq[idx] != SNDRV_AUTO_IRQ) {
926 printk(KERN_INFO LOGNAME
927 ": Configuring MPU to I/O 0x%lx IRQ %d\n",
928 mpu_io[idx], mpu_irq[idx]);
929 err = snd_msnd_write_cfg_logical(cfg[idx], 1,
938 if (ide_io0[idx] != SNDRV_AUTO_PORT
939 && ide_io1[idx] != SNDRV_AUTO_PORT
940 && ide_irq[idx] != SNDRV_AUTO_IRQ) {
941 printk(KERN_INFO LOGNAME
942 ": Configuring IDE to I/O 0x%lx, 0x%lx IRQ %d\n",
943 ide_io0[idx], ide_io1[idx], ide_irq[idx]);
944 err = snd_msnd_write_cfg_logical(cfg[idx], 2,
945 ide_io0[idx], ide_io1[idx],
953 if (joystick_io[idx] != SNDRV_AUTO_PORT) {
954 printk(KERN_INFO LOGNAME
955 ": Configuring joystick to I/O 0x%lx\n",
957 err = snd_msnd_write_cfg_logical(cfg[idx], 3,
965 #endif /* MSND_CLASSIC */
967 set_default_audio_parameters(chip);
969 chip->type = msndClassic;
971 chip->type = msndPinnacle;
974 chip->irq = irq[idx];
975 chip->base = mem[idx];
977 chip->calibrate_signal = calibrate_signal ? 1 : 0;
979 chip->dspq_data_buff = DSPQ_DATA_BUFF;
980 chip->dspq_buff_size = DSPQ_BUFF_SIZE;
981 if (write_ndelay[idx])
982 clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
984 set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
987 set_bit(F_HAVEDIGITAL, &chip->flags);
989 spin_lock_init(&chip->lock);
990 err = snd_msnd_probe(card);
992 printk(KERN_ERR LOGNAME ": Probe failed\n");
996 err = snd_msnd_attach(card);
998 printk(KERN_ERR LOGNAME ": Attach failed\n");
1001 dev_set_drvdata(pdev, card);
1006 static struct isa_driver snd_msnd_driver = {
1007 .match = snd_msnd_isa_match,
1008 .probe = snd_msnd_isa_probe,
1009 /* FIXME: suspend, resume */
1016 static int snd_msnd_pnp_detect(struct pnp_card_link *pcard,
1017 const struct pnp_card_device_id *pid)
1020 struct pnp_dev *pnp_dev;
1021 struct pnp_dev *mpu_dev;
1022 struct snd_card *card;
1023 struct snd_msnd *chip;
1026 for ( ; idx < SNDRV_CARDS; idx++) {
1027 if (has_isapnp(idx))
1030 if (idx >= SNDRV_CARDS)
1034 * Check that we still have room for another sound card ...
1036 pnp_dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
1040 mpu_dev = pnp_request_card_device(pcard, pid->devs[1].id, NULL);
1044 if (!pnp_is_active(pnp_dev) && pnp_activate_dev(pnp_dev) < 0) {
1045 printk(KERN_INFO "msnd_pinnacle: device is inactive\n");
1049 if (!pnp_is_active(mpu_dev) && pnp_activate_dev(mpu_dev) < 0) {
1050 printk(KERN_INFO "msnd_pinnacle: MPU device is inactive\n");
1055 * Create a new ALSA sound card entry, in anticipation
1056 * of detecting our hardware ...
1058 ret = snd_devm_card_new(&pcard->card->dev,
1059 index[idx], id[idx], THIS_MODULE,
1060 sizeof(struct snd_msnd), &card);
1064 chip = card->private_data;
1068 * Read the correct parameters off the ISA PnP bus ...
1070 io[idx] = pnp_port_start(pnp_dev, 0);
1071 irq[idx] = pnp_irq(pnp_dev, 0);
1072 mem[idx] = pnp_mem_start(pnp_dev, 0);
1073 mpu_io[idx] = pnp_port_start(mpu_dev, 0);
1074 mpu_irq[idx] = pnp_irq(mpu_dev, 0);
1076 set_default_audio_parameters(chip);
1078 chip->type = msndClassic;
1080 chip->type = msndPinnacle;
1083 chip->irq = irq[idx];
1084 chip->base = mem[idx];
1086 chip->calibrate_signal = calibrate_signal ? 1 : 0;
1088 chip->dspq_data_buff = DSPQ_DATA_BUFF;
1089 chip->dspq_buff_size = DSPQ_BUFF_SIZE;
1090 if (write_ndelay[idx])
1091 clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
1093 set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
1094 #ifndef MSND_CLASSIC
1096 set_bit(F_HAVEDIGITAL, &chip->flags);
1098 spin_lock_init(&chip->lock);
1099 ret = snd_msnd_probe(card);
1101 printk(KERN_ERR LOGNAME ": Probe failed\n");
1105 ret = snd_msnd_attach(card);
1107 printk(KERN_ERR LOGNAME ": Attach failed\n");
1111 pnp_set_card_drvdata(pcard, card);
1116 static int isa_registered;
1117 static int pnp_registered;
1119 static const struct pnp_card_device_id msnd_pnpids[] = {
1121 { .id = "BVJ0440", .devs = { { "TBS0000" }, { "TBS0001" } } },
1122 { .id = "" } /* end */
1125 MODULE_DEVICE_TABLE(pnp_card, msnd_pnpids);
1127 static struct pnp_card_driver msnd_pnpc_driver = {
1128 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
1129 .name = "msnd_pinnacle",
1130 .id_table = msnd_pnpids,
1131 .probe = snd_msnd_pnp_detect,
1133 #endif /* CONFIG_PNP */
1135 static int __init snd_msnd_init(void)
1139 err = isa_register_driver(&snd_msnd_driver, SNDRV_CARDS);
1144 err = pnp_register_card_driver(&msnd_pnpc_driver);
1154 static void __exit snd_msnd_exit(void)
1158 pnp_unregister_card_driver(&msnd_pnpc_driver);
1161 isa_unregister_driver(&snd_msnd_driver);
1164 module_init(snd_msnd_init);
1165 module_exit(snd_msnd_exit);