1 /*********************************************************************
3 * Linux multisound pinnacle/fiji driver for ALSA.
5 * 2002/06/30 Karsten Wiese:
6 * for now this is only used to build a pinnacle / fiji driver.
7 * the OSS parent of this code is designed to also support
8 * the multisound classic via the file msnd_classic.c.
9 * to make it easier for some brave heart to implemt classic
10 * support in alsa, i left all the MSND_CLASSIC tokens in this file.
11 * 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 * This program is free software; you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License as published by
35 * the Free Software Foundation; either version 2 of the License, or
36 * (at your option) any later version.
38 * This program is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 * GNU General Public License for more details.
43 * You should have received a copy of the GNU General Public License
44 * along with this program; if not, write to the Free Software
45 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
47 ********************************************************************/
49 #include <linux/kernel.h>
50 #include <linux/module.h>
51 #include <linux/interrupt.h>
52 #include <linux/types.h>
53 #include <linux/delay.h>
54 #include <linux/ioport.h>
55 #include <linux/firmware.h>
56 #include <linux/isa.h>
57 #include <linux/isapnp.h>
58 #include <linux/irq.h>
61 #include <sound/core.h>
62 #include <sound/initval.h>
63 #include <sound/asound.h>
64 #include <sound/pcm.h>
65 #include <sound/mpu401.h>
74 # include "msnd_classic.h"
75 # define LOGNAME "msnd_classic"
77 # include "msnd_pinnacle.h"
78 # define LOGNAME "snd_msnd_pinnacle"
81 static void __devinit
set_default_audio_parameters(struct snd_msnd
*chip
)
83 chip
->play_sample_size
= DEFSAMPLESIZE
;
84 chip
->play_sample_rate
= DEFSAMPLERATE
;
85 chip
->play_channels
= DEFCHANNELS
;
86 chip
->capture_sample_size
= DEFSAMPLESIZE
;
87 chip
->capture_sample_rate
= DEFSAMPLERATE
;
88 chip
->capture_channels
= DEFCHANNELS
;
91 static void snd_msnd_eval_dsp_msg(struct snd_msnd
*chip
, u16 wMessage
)
93 switch (HIBYTE(wMessage
)) {
94 case HIMT_PLAY_DONE
: {
95 if (chip
->banksPlayed
< 3)
96 snd_printdd("%08X: HIMT_PLAY_DONE: %i\n",
97 (unsigned)jiffies
, LOBYTE(wMessage
));
99 if (chip
->last_playbank
== LOBYTE(wMessage
)) {
100 snd_printdd("chip.last_playbank == LOBYTE(wMessage)\n");
105 if (test_bit(F_WRITING
, &chip
->flags
))
106 snd_msnd_DAPQ(chip
, 0);
108 chip
->last_playbank
= LOBYTE(wMessage
);
109 chip
->playDMAPos
+= chip
->play_period_bytes
;
110 if (chip
->playDMAPos
> chip
->playLimit
)
111 chip
->playDMAPos
= 0;
112 snd_pcm_period_elapsed(chip
->playback_substream
);
116 case HIMT_RECORD_DONE
:
117 if (chip
->last_recbank
== LOBYTE(wMessage
))
119 chip
->last_recbank
= LOBYTE(wMessage
);
120 chip
->captureDMAPos
+= chip
->capturePeriodBytes
;
121 if (chip
->captureDMAPos
> (chip
->captureLimit
))
122 chip
->captureDMAPos
= 0;
124 if (test_bit(F_READING
, &chip
->flags
))
125 snd_msnd_DARQ(chip
, chip
->last_recbank
);
127 snd_pcm_period_elapsed(chip
->capture_substream
);
131 switch (LOBYTE(wMessage
)) {
133 case HIDSP_PLAY_UNDER
:
135 case HIDSP_INT_PLAY_UNDER
:
136 snd_printd(KERN_WARNING LOGNAME
": Play underflow %i\n",
138 if (chip
->banksPlayed
> 2)
139 clear_bit(F_WRITING
, &chip
->flags
);
142 case HIDSP_INT_RECORD_OVER
:
143 snd_printd(KERN_WARNING LOGNAME
": Record overflow\n");
144 clear_bit(F_READING
, &chip
->flags
);
148 snd_printd(KERN_WARNING LOGNAME
149 ": DSP message %d 0x%02x\n",
150 LOBYTE(wMessage
), LOBYTE(wMessage
));
155 case HIMT_MIDI_IN_UCHAR
:
156 if (chip
->msndmidi_mpu
)
157 snd_msndmidi_input_read(chip
->msndmidi_mpu
);
161 snd_printd(KERN_WARNING LOGNAME
": HIMT message %d 0x%02x\n",
162 HIBYTE(wMessage
), HIBYTE(wMessage
));
167 static irqreturn_t
snd_msnd_interrupt(int irq
, void *dev_id
)
169 struct snd_msnd
*chip
= dev_id
;
170 void *pwDSPQData
= chip
->mappedbase
+ DSPQ_DATA_BUFF
;
172 /* Send ack to DSP */
173 /* inb(chip->io + HP_RXL); */
175 /* Evaluate queued DSP messages */
176 while (readw(chip
->DSPQ
+ JQS_wTail
) != readw(chip
->DSPQ
+ JQS_wHead
)) {
179 snd_msnd_eval_dsp_msg(chip
,
180 readw(pwDSPQData
+ 2 * readw(chip
->DSPQ
+ JQS_wHead
)));
182 wTmp
= readw(chip
->DSPQ
+ JQS_wHead
) + 1;
183 if (wTmp
> readw(chip
->DSPQ
+ JQS_wSize
))
184 writew(0, chip
->DSPQ
+ JQS_wHead
);
186 writew(wTmp
, chip
->DSPQ
+ JQS_wHead
);
188 /* Send ack to DSP */
189 inb(chip
->io
+ HP_RXL
);
194 static int snd_msnd_reset_dsp(long io
, unsigned char *info
)
198 outb(HPDSPRESET_ON
, io
+ HP_DSPR
);
202 *info
= inb(io
+ HP_INFO
);
204 outb(HPDSPRESET_OFF
, io
+ HP_DSPR
);
206 while (timeout
-- > 0) {
207 if (inb(io
+ HP_CVR
) == HP_CVR_DEF
)
211 snd_printk(KERN_ERR LOGNAME
": Cannot reset DSP\n");
216 static int __devinit
snd_msnd_probe(struct snd_card
*card
)
218 struct snd_msnd
*chip
= card
->private_data
;
221 char *xv
, *rev
= NULL
;
222 char *pin
= "TB Pinnacle", *fiji
= "TB Fiji";
223 char *pinfiji
= "TB Pinnacle/Fiji";
226 if (!request_region(chip
->io
, DSP_NUMIO
, "probing")) {
227 snd_printk(KERN_ERR LOGNAME
": I/O port conflict\n");
231 if (snd_msnd_reset_dsp(chip
->io
, &info
) < 0) {
232 release_region(chip
->io
, DSP_NUMIO
);
237 strcpy(card
->shortname
, "Classic/Tahiti/Monterey");
238 strcpy(card
->longname
, "Turtle Beach Multisound");
239 printk(KERN_INFO LOGNAME
": %s, "
240 "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n",
242 chip
->io
, chip
->io
+ DSP_NUMIO
- 1,
244 chip
->base
, chip
->base
+ 0x7fff);
264 switch (info
& 0x7) {
267 strcpy(card
->shortname
, pin
);
271 strcpy(card
->shortname
, pin
);
275 strcpy(card
->shortname
, pin
);
279 strcpy(card
->shortname
, pin
);
283 strcpy(card
->shortname
, fiji
);
287 strcpy(card
->shortname
, fiji
);
291 strcpy(card
->shortname
, fiji
);
294 rev
= "A-B (Fiji) or A-E (Pinnacle)";
295 strcpy(card
->shortname
, pinfiji
);
298 strcpy(card
->longname
, "Turtle Beach Multisound Pinnacle");
299 printk(KERN_INFO LOGNAME
": %s revision %s, Xilinx version %s, "
300 "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n",
303 chip
->io
, chip
->io
+ DSP_NUMIO
- 1,
305 chip
->base
, chip
->base
+ 0x7fff);
308 release_region(chip
->io
, DSP_NUMIO
);
312 static int snd_msnd_init_sma(struct snd_msnd
*chip
)
315 u16 mastVolLeft
, mastVolRight
;
319 outb(chip
->memid
, chip
->io
+ HP_MEMM
);
321 outb(HPBLKSEL_0
, chip
->io
+ HP_BLKS
);
322 /* Motorola 56k shared memory base */
323 chip
->SMA
= chip
->mappedbase
+ SMA_STRUCT_START
;
326 mastVolLeft
= readw(chip
->SMA
+ SMA_wCurrMastVolLeft
);
327 mastVolRight
= readw(chip
->SMA
+ SMA_wCurrMastVolRight
);
329 mastVolLeft
= mastVolRight
= 0;
330 memset_io(chip
->mappedbase
, 0, 0x8000);
332 /* Critical section: bank 1 access */
333 spin_lock_irqsave(&chip
->lock
, flags
);
334 outb(HPBLKSEL_1
, chip
->io
+ HP_BLKS
);
335 memset_io(chip
->mappedbase
, 0, 0x8000);
336 outb(HPBLKSEL_0
, chip
->io
+ HP_BLKS
);
337 spin_unlock_irqrestore(&chip
->lock
, flags
);
339 /* Digital audio play queue */
340 chip
->DAPQ
= chip
->mappedbase
+ DAPQ_OFFSET
;
341 snd_msnd_init_queue(chip
->DAPQ
, DAPQ_DATA_BUFF
, DAPQ_BUFF_SIZE
);
343 /* Digital audio record queue */
344 chip
->DARQ
= chip
->mappedbase
+ DARQ_OFFSET
;
345 snd_msnd_init_queue(chip
->DARQ
, DARQ_DATA_BUFF
, DARQ_BUFF_SIZE
);
348 chip
->MODQ
= chip
->mappedbase
+ MODQ_OFFSET
;
349 snd_msnd_init_queue(chip
->MODQ
, MODQ_DATA_BUFF
, MODQ_BUFF_SIZE
);
352 chip
->MIDQ
= chip
->mappedbase
+ MIDQ_OFFSET
;
353 snd_msnd_init_queue(chip
->MIDQ
, MIDQ_DATA_BUFF
, MIDQ_BUFF_SIZE
);
355 /* DSP -> host message queue */
356 chip
->DSPQ
= chip
->mappedbase
+ DSPQ_OFFSET
;
357 snd_msnd_init_queue(chip
->DSPQ
, DSPQ_DATA_BUFF
, DSPQ_BUFF_SIZE
);
359 /* Setup some DSP values */
361 writew(1, chip
->SMA
+ SMA_wCurrPlayFormat
);
362 writew(chip
->play_sample_size
, chip
->SMA
+ SMA_wCurrPlaySampleSize
);
363 writew(chip
->play_channels
, chip
->SMA
+ SMA_wCurrPlayChannels
);
364 writew(chip
->play_sample_rate
, chip
->SMA
+ SMA_wCurrPlaySampleRate
);
366 writew(chip
->play_sample_rate
, chip
->SMA
+ SMA_wCalFreqAtoD
);
367 writew(mastVolLeft
, chip
->SMA
+ SMA_wCurrMastVolLeft
);
368 writew(mastVolRight
, chip
->SMA
+ SMA_wCurrMastVolRight
);
370 writel(0x00010000, chip
->SMA
+ SMA_dwCurrPlayPitch
);
371 writel(0x00000001, chip
->SMA
+ SMA_dwCurrPlayRate
);
373 writew(0x303, chip
->SMA
+ SMA_wCurrInputTagBits
);
381 static int upload_dsp_code(struct snd_card
*card
)
383 struct snd_msnd
*chip
= card
->private_data
;
384 const struct firmware
*init_fw
= NULL
, *perm_fw
= NULL
;
387 outb(HPBLKSEL_0
, chip
->io
+ HP_BLKS
);
389 err
= request_firmware(&init_fw
, INITCODEFILE
, card
->dev
);
391 printk(KERN_ERR LOGNAME
": Error loading " INITCODEFILE
);
394 err
= request_firmware(&perm_fw
, PERMCODEFILE
, card
->dev
);
396 printk(KERN_ERR LOGNAME
": Error loading " PERMCODEFILE
);
400 memcpy_toio(chip
->mappedbase
, perm_fw
->data
, perm_fw
->size
);
401 if (snd_msnd_upload_host(chip
, init_fw
->data
, init_fw
->size
) < 0) {
402 printk(KERN_WARNING LOGNAME
": Error uploading to DSP\n");
406 printk(KERN_INFO LOGNAME
": DSP firmware uploaded\n");
410 release_firmware(perm_fw
);
412 release_firmware(init_fw
);
417 static void reset_proteus(struct snd_msnd
*chip
)
419 outb(HPPRORESET_ON
, chip
->io
+ HP_PROR
);
420 msleep(TIME_PRO_RESET
);
421 outb(HPPRORESET_OFF
, chip
->io
+ HP_PROR
);
422 msleep(TIME_PRO_RESET_DONE
);
426 static int snd_msnd_initialize(struct snd_card
*card
)
428 struct snd_msnd
*chip
= card
->private_data
;
432 outb(HPWAITSTATE_0
, chip
->io
+ HP_WAIT
);
433 outb(HPBITMODE_16
, chip
->io
+ HP_BITM
);
437 err
= snd_msnd_init_sma(chip
);
439 printk(KERN_WARNING LOGNAME
": Cannot initialize SMA\n");
443 err
= snd_msnd_reset_dsp(chip
->io
, NULL
);
447 err
= upload_dsp_code(card
);
449 printk(KERN_WARNING LOGNAME
": Cannot upload DSP code\n");
455 while (readw(chip
->mappedbase
)) {
458 snd_printd(KERN_ERR LOGNAME
": DSP reset timeout\n");
463 snd_msndmix_setup(chip
);
467 static int snd_msnd_dsp_full_reset(struct snd_card
*card
)
469 struct snd_msnd
*chip
= card
->private_data
;
472 if (test_bit(F_RESETTING
, &chip
->flags
) || ++chip
->nresets
> 10)
475 set_bit(F_RESETTING
, &chip
->flags
);
476 snd_msnd_dsp_halt(chip
, NULL
); /* Unconditionally halt */
478 rv
= snd_msnd_initialize(card
);
480 printk(KERN_WARNING LOGNAME
": DSP reset failed\n");
481 snd_msndmix_force_recsrc(chip
, 0);
482 clear_bit(F_RESETTING
, &chip
->flags
);
486 static int snd_msnd_dev_free(struct snd_device
*device
)
488 snd_printdd("snd_msnd_chip_free()\n");
492 static int snd_msnd_send_dsp_cmd_chk(struct snd_msnd
*chip
, u8 cmd
)
494 if (snd_msnd_send_dsp_cmd(chip
, cmd
) == 0)
496 snd_msnd_dsp_full_reset(chip
->card
);
497 return snd_msnd_send_dsp_cmd(chip
, cmd
);
500 static int __devinit
snd_msnd_calibrate_adc(struct snd_msnd
*chip
, u16 srate
)
502 snd_printdd("snd_msnd_calibrate_adc(%i)\n", srate
);
503 writew(srate
, chip
->SMA
+ SMA_wCalFreqAtoD
);
504 if (chip
->calibrate_signal
== 0)
505 writew(readw(chip
->SMA
+ SMA_wCurrHostStatusFlags
)
506 | 0x0001, chip
->SMA
+ SMA_wCurrHostStatusFlags
);
508 writew(readw(chip
->SMA
+ SMA_wCurrHostStatusFlags
)
509 & ~0x0001, chip
->SMA
+ SMA_wCurrHostStatusFlags
);
510 if (snd_msnd_send_word(chip
, 0, 0, HDEXAR_CAL_A_TO_D
) == 0 &&
511 snd_msnd_send_dsp_cmd_chk(chip
, HDEX_AUX_REQ
) == 0) {
512 schedule_timeout_interruptible(msecs_to_jiffies(333));
515 printk(KERN_WARNING LOGNAME
": ADC calibration failed\n");
520 * ALSA callback function, called when attempting to open the MIDI device.
522 static int snd_msnd_mpu401_open(struct snd_mpu401
*mpu
)
524 snd_msnd_enable_irq(mpu
->private_data
);
525 snd_msnd_send_dsp_cmd(mpu
->private_data
, HDEX_MIDI_IN_START
);
529 static void snd_msnd_mpu401_close(struct snd_mpu401
*mpu
)
531 snd_msnd_send_dsp_cmd(mpu
->private_data
, HDEX_MIDI_IN_STOP
);
532 snd_msnd_disable_irq(mpu
->private_data
);
535 static long mpu_io
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
536 static int mpu_irq
[SNDRV_CARDS
] = SNDRV_DEFAULT_IRQ
;
538 static int __devinit
snd_msnd_attach(struct snd_card
*card
)
540 struct snd_msnd
*chip
= card
->private_data
;
542 static struct snd_device_ops ops
= {
543 .dev_free
= snd_msnd_dev_free
,
546 err
= request_irq(chip
->irq
, snd_msnd_interrupt
, 0, card
->shortname
,
549 printk(KERN_ERR LOGNAME
": Couldn't grab IRQ %d\n", chip
->irq
);
552 if (request_region(chip
->io
, DSP_NUMIO
, card
->shortname
) == NULL
) {
553 free_irq(chip
->irq
, chip
);
557 if (!request_mem_region(chip
->base
, BUFFSIZE
, card
->shortname
)) {
558 printk(KERN_ERR LOGNAME
559 ": unable to grab memory region 0x%lx-0x%lx\n",
560 chip
->base
, chip
->base
+ BUFFSIZE
- 1);
561 release_region(chip
->io
, DSP_NUMIO
);
562 free_irq(chip
->irq
, chip
);
565 chip
->mappedbase
= ioremap_nocache(chip
->base
, 0x8000);
566 if (!chip
->mappedbase
) {
567 printk(KERN_ERR LOGNAME
568 ": unable to map memory region 0x%lx-0x%lx\n",
569 chip
->base
, chip
->base
+ BUFFSIZE
- 1);
571 goto err_release_region
;
574 err
= snd_msnd_dsp_full_reset(card
);
576 goto err_release_region
;
578 /* Register device */
579 err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
);
581 goto err_release_region
;
583 err
= snd_msnd_pcm(card
, 0, NULL
);
585 printk(KERN_ERR LOGNAME
": error creating new PCM device\n");
586 goto err_release_region
;
589 err
= snd_msndmix_new(card
);
591 printk(KERN_ERR LOGNAME
": error creating new Mixer device\n");
592 goto err_release_region
;
596 if (mpu_io
[0] != SNDRV_AUTO_PORT
) {
597 struct snd_mpu401
*mpu
;
599 err
= snd_mpu401_uart_new(card
, 0, MPU401_HW_MPU401
,
603 mpu_irq
[0], IRQF_DISABLED
,
606 printk(KERN_ERR LOGNAME
607 ": error creating new Midi device\n");
608 goto err_release_region
;
610 mpu
= chip
->rmidi
->private_data
;
612 mpu
->open_input
= snd_msnd_mpu401_open
;
613 mpu
->close_input
= snd_msnd_mpu401_close
;
614 mpu
->private_data
= chip
;
617 disable_irq(chip
->irq
);
618 snd_msnd_calibrate_adc(chip
, chip
->play_sample_rate
);
619 snd_msndmix_force_recsrc(chip
, 0);
621 err
= snd_card_register(card
);
623 goto err_release_region
;
628 if (chip
->mappedbase
)
629 iounmap(chip
->mappedbase
);
630 release_mem_region(chip
->base
, BUFFSIZE
);
631 release_region(chip
->io
, DSP_NUMIO
);
632 free_irq(chip
->irq
, chip
);
637 static void __devexit
snd_msnd_unload(struct snd_card
*card
)
639 struct snd_msnd
*chip
= card
->private_data
;
641 iounmap(chip
->mappedbase
);
642 release_mem_region(chip
->base
, BUFFSIZE
);
643 release_region(chip
->io
, DSP_NUMIO
);
644 free_irq(chip
->irq
, chip
);
650 /* Pinnacle/Fiji Logical Device Configuration */
652 static int __devinit
snd_msnd_write_cfg(int cfg
, int reg
, int value
)
655 outb(value
, cfg
+ 1);
656 if (value
!= inb(cfg
+ 1)) {
657 printk(KERN_ERR LOGNAME
": snd_msnd_write_cfg: I/O error\n");
663 static int __devinit
snd_msnd_write_cfg_io0(int cfg
, int num
, u16 io
)
665 if (snd_msnd_write_cfg(cfg
, IREG_LOGDEVICE
, num
))
667 if (snd_msnd_write_cfg(cfg
, IREG_IO0_BASEHI
, HIBYTE(io
)))
669 if (snd_msnd_write_cfg(cfg
, IREG_IO0_BASELO
, LOBYTE(io
)))
674 static int __devinit
snd_msnd_write_cfg_io1(int cfg
, int num
, u16 io
)
676 if (snd_msnd_write_cfg(cfg
, IREG_LOGDEVICE
, num
))
678 if (snd_msnd_write_cfg(cfg
, IREG_IO1_BASEHI
, HIBYTE(io
)))
680 if (snd_msnd_write_cfg(cfg
, IREG_IO1_BASELO
, LOBYTE(io
)))
685 static int __devinit
snd_msnd_write_cfg_irq(int cfg
, int num
, u16 irq
)
687 if (snd_msnd_write_cfg(cfg
, IREG_LOGDEVICE
, num
))
689 if (snd_msnd_write_cfg(cfg
, IREG_IRQ_NUMBER
, LOBYTE(irq
)))
691 if (snd_msnd_write_cfg(cfg
, IREG_IRQ_TYPE
, IRQTYPE_EDGE
))
696 static int __devinit
snd_msnd_write_cfg_mem(int cfg
, int num
, int mem
)
701 wmem
= (u16
)(mem
& 0xfff);
702 if (snd_msnd_write_cfg(cfg
, IREG_LOGDEVICE
, num
))
704 if (snd_msnd_write_cfg(cfg
, IREG_MEMBASEHI
, HIBYTE(wmem
)))
706 if (snd_msnd_write_cfg(cfg
, IREG_MEMBASELO
, LOBYTE(wmem
)))
708 if (wmem
&& snd_msnd_write_cfg(cfg
, IREG_MEMCONTROL
,
709 MEMTYPE_HIADDR
| MEMTYPE_16BIT
))
714 static int __devinit
snd_msnd_activate_logical(int cfg
, int num
)
716 if (snd_msnd_write_cfg(cfg
, IREG_LOGDEVICE
, num
))
718 if (snd_msnd_write_cfg(cfg
, IREG_ACTIVATE
, LD_ACTIVATE
))
723 static int __devinit
snd_msnd_write_cfg_logical(int cfg
, int num
, u16 io0
,
724 u16 io1
, u16 irq
, int mem
)
726 if (snd_msnd_write_cfg(cfg
, IREG_LOGDEVICE
, num
))
728 if (snd_msnd_write_cfg_io0(cfg
, num
, io0
))
730 if (snd_msnd_write_cfg_io1(cfg
, num
, io1
))
732 if (snd_msnd_write_cfg_irq(cfg
, num
, irq
))
734 if (snd_msnd_write_cfg_mem(cfg
, num
, mem
))
736 if (snd_msnd_activate_logical(cfg
, num
))
741 static int __devinit
snd_msnd_pinnacle_cfg_reset(int cfg
)
745 /* Reset devices if told to */
746 printk(KERN_INFO LOGNAME
": Resetting all devices\n");
747 for (i
= 0; i
< 4; ++i
)
748 if (snd_msnd_write_cfg_logical(cfg
, i
, 0, 0, 0, 0))
755 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
756 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
758 module_param_array(index
, int, NULL
, S_IRUGO
);
759 MODULE_PARM_DESC(index
, "Index value for msnd_pinnacle soundcard.");
760 module_param_array(id
, charp
, NULL
, S_IRUGO
);
761 MODULE_PARM_DESC(id
, "ID string for msnd_pinnacle soundcard.");
763 static long io
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
764 static int irq
[SNDRV_CARDS
] = SNDRV_DEFAULT_IRQ
;
765 static long mem
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
768 static long cfg
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
770 /* Extra Peripheral Configuration (Default: Disable) */
771 static long ide_io0
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
772 static long ide_io1
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
773 static int ide_irq
[SNDRV_CARDS
] = SNDRV_DEFAULT_IRQ
;
775 static long joystick_io
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
776 /* If we have the digital daugherboard... */
777 static int digital
[SNDRV_CARDS
];
779 /* Extra Peripheral Configuration */
780 static int reset
[SNDRV_CARDS
];
783 static int write_ndelay
[SNDRV_CARDS
] = { [0 ... (SNDRV_CARDS
-1)] = 1 };
785 static int calibrate_signal
;
788 static int isapnp
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
789 module_param_array(isapnp
, bool, NULL
, 0444);
790 MODULE_PARM_DESC(isapnp
, "ISA PnP detection for specified soundcard.");
791 #define has_isapnp(x) isapnp[x]
793 #define has_isapnp(x) 0
796 MODULE_AUTHOR("Karsten Wiese <annabellesgarden@yahoo.de>");
797 MODULE_DESCRIPTION("Turtle Beach " LONGNAME
" Linux Driver");
798 MODULE_LICENSE("GPL");
799 MODULE_FIRMWARE(INITCODEFILE
);
800 MODULE_FIRMWARE(PERMCODEFILE
);
802 module_param_array(io
, long, NULL
, S_IRUGO
);
803 MODULE_PARM_DESC(io
, "IO port #");
804 module_param_array(irq
, int, NULL
, S_IRUGO
);
805 module_param_array(mem
, long, NULL
, S_IRUGO
);
806 module_param_array(write_ndelay
, int, NULL
, S_IRUGO
);
807 module_param(calibrate_signal
, int, S_IRUGO
);
809 module_param_array(digital
, int, NULL
, S_IRUGO
);
810 module_param_array(cfg
, long, NULL
, S_IRUGO
);
811 module_param_array(reset
, int, 0, S_IRUGO
);
812 module_param_array(mpu_io
, long, NULL
, S_IRUGO
);
813 module_param_array(mpu_irq
, int, NULL
, S_IRUGO
);
814 module_param_array(ide_io0
, long, NULL
, S_IRUGO
);
815 module_param_array(ide_io1
, long, NULL
, S_IRUGO
);
816 module_param_array(ide_irq
, int, NULL
, S_IRUGO
);
817 module_param_array(joystick_io
, long, NULL
, S_IRUGO
);
821 static int __devinit
snd_msnd_isa_match(struct device
*pdev
, unsigned int i
)
823 if (io
[i
] == SNDRV_AUTO_PORT
)
826 if (irq
[i
] == SNDRV_AUTO_PORT
|| mem
[i
] == SNDRV_AUTO_PORT
) {
827 printk(KERN_WARNING LOGNAME
": io, irq and mem must be set\n");
832 if (!(io
[i
] == 0x290 ||
840 printk(KERN_ERR LOGNAME
": \"io\" - DSP I/O base must be set "
841 " to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, "
846 if (io
[i
] < 0x100 || io
[i
] > 0x3e0 || (io
[i
] % 0x10) != 0) {
847 printk(KERN_ERR LOGNAME
848 ": \"io\" - DSP I/O base must within the range 0x100 "
849 "to 0x3E0 and must be evenly divisible by 0x10\n");
852 #endif /* MSND_CLASSIC */
860 printk(KERN_ERR LOGNAME
861 ": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n");
865 if (!(mem
[i
] == 0xb0000 ||
870 mem
[i
] == 0xe8000)) {
871 printk(KERN_ERR LOGNAME
": \"mem\" - must be set to "
872 "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or "
878 if (cfg
[i
] == SNDRV_AUTO_PORT
) {
879 printk(KERN_INFO LOGNAME
": Assuming PnP mode\n");
880 } else if (cfg
[i
] != 0x250 && cfg
[i
] != 0x260 && cfg
[i
] != 0x270) {
881 printk(KERN_INFO LOGNAME
882 ": Config port must be 0x250, 0x260 or 0x270 "
883 "(or unspecified for PnP mode)\n");
886 #endif /* MSND_CLASSIC */
891 static int __devinit
snd_msnd_isa_probe(struct device
*pdev
, unsigned int idx
)
894 struct snd_card
*card
;
895 struct snd_msnd
*chip
;
899 || cfg
[idx
] == SNDRV_AUTO_PORT
902 printk(KERN_INFO LOGNAME
": Assuming PnP mode\n");
906 err
= snd_card_create(index
[idx
], id
[idx
], THIS_MODULE
,
907 sizeof(struct snd_msnd
), &card
);
911 snd_card_set_dev(card
, pdev
);
912 chip
= card
->private_data
;
918 chip
->irqid
= HPIRQ_5
; break;
920 chip
->irqid
= HPIRQ_7
; break;
922 chip
->irqid
= HPIRQ_9
; break;
924 chip
->irqid
= HPIRQ_10
; break;
926 chip
->irqid
= HPIRQ_11
; break;
928 chip
->irqid
= HPIRQ_12
; break;
933 chip
->memid
= HPMEM_B000
; break;
935 chip
->memid
= HPMEM_C800
; break;
937 chip
->memid
= HPMEM_D000
; break;
939 chip
->memid
= HPMEM_D800
; break;
941 chip
->memid
= HPMEM_E000
; break;
943 chip
->memid
= HPMEM_E800
; break;
946 printk(KERN_INFO LOGNAME
": Non-PnP mode: configuring at port 0x%lx\n",
949 if (!request_region(cfg
[idx
], 2, "Pinnacle/Fiji Config")) {
950 printk(KERN_ERR LOGNAME
": Config port 0x%lx conflict\n",
956 if (snd_msnd_pinnacle_cfg_reset(cfg
[idx
])) {
962 err
= snd_msnd_write_cfg_logical(cfg
[idx
], 0,
969 /* The following are Pinnacle specific */
972 if (mpu_io
[idx
] != SNDRV_AUTO_PORT
973 && mpu_irq
[idx
] != SNDRV_AUTO_IRQ
) {
974 printk(KERN_INFO LOGNAME
975 ": Configuring MPU to I/O 0x%lx IRQ %d\n",
976 mpu_io
[idx
], mpu_irq
[idx
]);
977 err
= snd_msnd_write_cfg_logical(cfg
[idx
], 1,
986 if (ide_io0
[idx
] != SNDRV_AUTO_PORT
987 && ide_io1
[idx
] != SNDRV_AUTO_PORT
988 && ide_irq
[idx
] != SNDRV_AUTO_IRQ
) {
989 printk(KERN_INFO LOGNAME
990 ": Configuring IDE to I/O 0x%lx, 0x%lx IRQ %d\n",
991 ide_io0
[idx
], ide_io1
[idx
], ide_irq
[idx
]);
992 err
= snd_msnd_write_cfg_logical(cfg
[idx
], 2,
993 ide_io0
[idx
], ide_io1
[idx
],
1001 if (joystick_io
[idx
] != SNDRV_AUTO_PORT
) {
1002 printk(KERN_INFO LOGNAME
1003 ": Configuring joystick to I/O 0x%lx\n",
1005 err
= snd_msnd_write_cfg_logical(cfg
[idx
], 3,
1006 joystick_io
[idx
], 0,
1012 release_region(cfg
[idx
], 2);
1014 #endif /* MSND_CLASSIC */
1016 set_default_audio_parameters(chip
);
1018 chip
->type
= msndClassic
;
1020 chip
->type
= msndPinnacle
;
1023 chip
->irq
= irq
[idx
];
1024 chip
->base
= mem
[idx
];
1026 chip
->calibrate_signal
= calibrate_signal
? 1 : 0;
1028 chip
->dspq_data_buff
= DSPQ_DATA_BUFF
;
1029 chip
->dspq_buff_size
= DSPQ_BUFF_SIZE
;
1030 if (write_ndelay
[idx
])
1031 clear_bit(F_DISABLE_WRITE_NDELAY
, &chip
->flags
);
1033 set_bit(F_DISABLE_WRITE_NDELAY
, &chip
->flags
);
1034 #ifndef MSND_CLASSIC
1036 set_bit(F_HAVEDIGITAL
, &chip
->flags
);
1038 spin_lock_init(&chip
->lock
);
1039 err
= snd_msnd_probe(card
);
1041 printk(KERN_ERR LOGNAME
": Probe failed\n");
1042 snd_card_free(card
);
1046 err
= snd_msnd_attach(card
);
1048 printk(KERN_ERR LOGNAME
": Attach failed\n");
1049 snd_card_free(card
);
1052 dev_set_drvdata(pdev
, card
);
1056 #ifndef MSND_CLASSIC
1058 release_region(cfg
[idx
], 2);
1059 snd_card_free(card
);
1064 static int __devexit
snd_msnd_isa_remove(struct device
*pdev
, unsigned int dev
)
1066 snd_msnd_unload(dev_get_drvdata(pdev
));
1067 dev_set_drvdata(pdev
, NULL
);
1071 #define DEV_NAME "msnd-pinnacle"
1073 static struct isa_driver snd_msnd_driver
= {
1074 .match
= snd_msnd_isa_match
,
1075 .probe
= snd_msnd_isa_probe
,
1076 .remove
= __devexit_p(snd_msnd_isa_remove
),
1077 /* FIXME: suspend, resume */
1084 static int __devinit
snd_msnd_pnp_detect(struct pnp_card_link
*pcard
,
1085 const struct pnp_card_device_id
*pid
)
1088 struct pnp_dev
*pnp_dev
;
1089 struct pnp_dev
*mpu_dev
;
1090 struct snd_card
*card
;
1091 struct snd_msnd
*chip
;
1094 for ( ; idx
< SNDRV_CARDS
; idx
++) {
1095 if (has_isapnp(idx
))
1098 if (idx
>= SNDRV_CARDS
)
1102 * Check that we still have room for another sound card ...
1104 pnp_dev
= pnp_request_card_device(pcard
, pid
->devs
[0].id
, NULL
);
1108 mpu_dev
= pnp_request_card_device(pcard
, pid
->devs
[1].id
, NULL
);
1112 if (!pnp_is_active(pnp_dev
) && pnp_activate_dev(pnp_dev
) < 0) {
1113 printk(KERN_INFO
"msnd_pinnacle: device is inactive\n");
1117 if (!pnp_is_active(mpu_dev
) && pnp_activate_dev(mpu_dev
) < 0) {
1118 printk(KERN_INFO
"msnd_pinnacle: MPU device is inactive\n");
1123 * Create a new ALSA sound card entry, in anticipation
1124 * of detecting our hardware ...
1126 ret
= snd_card_create(index
[idx
], id
[idx
], THIS_MODULE
,
1127 sizeof(struct snd_msnd
), &card
);
1131 chip
= card
->private_data
;
1133 snd_card_set_dev(card
, &pcard
->card
->dev
);
1136 * Read the correct parameters off the ISA PnP bus ...
1138 io
[idx
] = pnp_port_start(pnp_dev
, 0);
1139 irq
[idx
] = pnp_irq(pnp_dev
, 0);
1140 mem
[idx
] = pnp_mem_start(pnp_dev
, 0);
1141 mpu_io
[idx
] = pnp_port_start(mpu_dev
, 0);
1142 mpu_irq
[idx
] = pnp_irq(mpu_dev
, 0);
1144 set_default_audio_parameters(chip
);
1146 chip
->type
= msndClassic
;
1148 chip
->type
= msndPinnacle
;
1151 chip
->irq
= irq
[idx
];
1152 chip
->base
= mem
[idx
];
1154 chip
->calibrate_signal
= calibrate_signal
? 1 : 0;
1156 chip
->dspq_data_buff
= DSPQ_DATA_BUFF
;
1157 chip
->dspq_buff_size
= DSPQ_BUFF_SIZE
;
1158 if (write_ndelay
[idx
])
1159 clear_bit(F_DISABLE_WRITE_NDELAY
, &chip
->flags
);
1161 set_bit(F_DISABLE_WRITE_NDELAY
, &chip
->flags
);
1162 #ifndef MSND_CLASSIC
1164 set_bit(F_HAVEDIGITAL
, &chip
->flags
);
1166 spin_lock_init(&chip
->lock
);
1167 ret
= snd_msnd_probe(card
);
1169 printk(KERN_ERR LOGNAME
": Probe failed\n");
1173 ret
= snd_msnd_attach(card
);
1175 printk(KERN_ERR LOGNAME
": Attach failed\n");
1179 pnp_set_card_drvdata(pcard
, card
);
1184 snd_card_free(card
);
1188 static void __devexit
snd_msnd_pnp_remove(struct pnp_card_link
*pcard
)
1190 snd_msnd_unload(pnp_get_card_drvdata(pcard
));
1191 pnp_set_card_drvdata(pcard
, NULL
);
1194 static int isa_registered
;
1195 static int pnp_registered
;
1197 static struct pnp_card_device_id msnd_pnpids
[] = {
1199 { .id
= "BVJ0440", .devs
= { { "TBS0000" }, { "TBS0001" } } },
1200 { .id
= "" } /* end */
1203 MODULE_DEVICE_TABLE(pnp_card
, msnd_pnpids
);
1205 static struct pnp_card_driver msnd_pnpc_driver
= {
1206 .flags
= PNP_DRIVER_RES_DO_NOT_CHANGE
,
1207 .name
= "msnd_pinnacle",
1208 .id_table
= msnd_pnpids
,
1209 .probe
= snd_msnd_pnp_detect
,
1210 .remove
= __devexit_p(snd_msnd_pnp_remove
),
1212 #endif /* CONFIG_PNP */
1214 static int __init
snd_msnd_init(void)
1218 err
= isa_register_driver(&snd_msnd_driver
, SNDRV_CARDS
);
1223 err
= pnp_register_card_driver(&msnd_pnpc_driver
);
1233 static void __exit
snd_msnd_exit(void)
1237 pnp_unregister_card_driver(&msnd_pnpc_driver
);
1240 isa_unregister_driver(&snd_msnd_driver
);
1243 module_init(snd_msnd_init
);
1244 module_exit(snd_msnd_exit
);