1 /*********************************************************************
3 * Turtle Beach MultiSound Sound Card Driver for Linux
4 * Linux 2.0/2.2 Version
6 * msnd_pinnacle.c / msnd_classic.c
8 * -- If MSND_CLASSIC is defined:
10 * -> driver for Turtle Beach Classic/Monterey/Tahiti
14 * -> driver for Turtle Beach Pinnacle/Fiji
16 * Copyright (C) 1998 Andrew Veliath
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 * 12-3-2000 Modified IO port validation Steve Sycamore
34 ********************************************************************/
36 #include <linux/kernel.h>
37 #include <linux/module.h>
38 #include <linux/types.h>
39 #include <linux/delay.h>
40 #include <linux/init.h>
41 #include <linux/interrupt.h>
42 #include <linux/mutex.h>
43 #include <linux/gfp.h>
44 #include <linux/sched/signal.h>
48 #include "sound_config.h"
49 #include "sound_firmware.h"
57 # ifdef CONFIG_MSNDCLAS_HAVE_BOOT
58 # define HAVE_DSPCODEH
60 # include "msnd_classic.h"
61 # define LOGNAME "msnd_classic"
63 # ifdef CONFIG_MSNDPIN_HAVE_BOOT
64 # define HAVE_DSPCODEH
66 # include "msnd_pinnacle.h"
67 # define LOGNAME "msnd_pinnacle"
70 #ifndef CONFIG_MSND_WRITE_NDELAY
71 # define CONFIG_MSND_WRITE_NDELAY 1
74 #define get_play_delay_jiffies(size) ((size) * HZ * \
75 dev.play_sample_size / 8 / \
76 dev.play_sample_rate / \
79 #define get_rec_delay_jiffies(size) ((size) * HZ * \
80 dev.rec_sample_size / 8 / \
81 dev.rec_sample_rate / \
84 static DEFINE_MUTEX(msnd_pinnacle_mutex
);
85 static multisound_dev_t dev
;
88 static char *dspini
, *permini
;
89 static int sizeof_dspini
, sizeof_permini
;
92 static int dsp_full_reset(void);
93 static void dsp_write_flush(void);
95 static __inline__
int chk_send_dsp_cmd(multisound_dev_t
*dev
, register BYTE cmd
)
97 if (msnd_send_dsp_cmd(dev
, cmd
) == 0)
100 return msnd_send_dsp_cmd(dev
, cmd
);
103 static void reset_play_queue(void)
108 dev
.last_playbank
= -1;
109 writew(PCTODSP_OFFSET(0 * DAQDS__size
), dev
.DAPQ
+ JQS_wHead
);
110 writew(PCTODSP_OFFSET(0 * DAQDS__size
), dev
.DAPQ
+ JQS_wTail
);
112 for (n
= 0, lpDAQ
= dev
.base
+ DAPQ_DATA_BUFF
; n
< 3; ++n
, lpDAQ
+= DAQDS__size
) {
113 writew(PCTODSP_BASED((DWORD
)(DAP_BUFF_SIZE
* n
)), lpDAQ
+ DAQDS_wStart
);
114 writew(0, lpDAQ
+ DAQDS_wSize
);
115 writew(1, lpDAQ
+ DAQDS_wFormat
);
116 writew(dev
.play_sample_size
, lpDAQ
+ DAQDS_wSampleSize
);
117 writew(dev
.play_channels
, lpDAQ
+ DAQDS_wChannels
);
118 writew(dev
.play_sample_rate
, lpDAQ
+ DAQDS_wSampleRate
);
119 writew(HIMT_PLAY_DONE
* 0x100 + n
, lpDAQ
+ DAQDS_wIntMsg
);
120 writew(n
, lpDAQ
+ DAQDS_wFlags
);
124 static void reset_record_queue(void)
130 dev
.last_recbank
= 2;
131 writew(PCTODSP_OFFSET(0 * DAQDS__size
), dev
.DARQ
+ JQS_wHead
);
132 writew(PCTODSP_OFFSET(dev
.last_recbank
* DAQDS__size
), dev
.DARQ
+ JQS_wTail
);
134 /* Critical section: bank 1 access */
135 spin_lock_irqsave(&dev
.lock
, flags
);
136 msnd_outb(HPBLKSEL_1
, dev
.io
+ HP_BLKS
);
137 memset_io(dev
.base
, 0, DAR_BUFF_SIZE
* 3);
138 msnd_outb(HPBLKSEL_0
, dev
.io
+ HP_BLKS
);
139 spin_unlock_irqrestore(&dev
.lock
, flags
);
141 for (n
= 0, lpDAQ
= dev
.base
+ DARQ_DATA_BUFF
; n
< 3; ++n
, lpDAQ
+= DAQDS__size
) {
142 writew(PCTODSP_BASED((DWORD
)(DAR_BUFF_SIZE
* n
)) + 0x4000, lpDAQ
+ DAQDS_wStart
);
143 writew(DAR_BUFF_SIZE
, lpDAQ
+ DAQDS_wSize
);
144 writew(1, lpDAQ
+ DAQDS_wFormat
);
145 writew(dev
.rec_sample_size
, lpDAQ
+ DAQDS_wSampleSize
);
146 writew(dev
.rec_channels
, lpDAQ
+ DAQDS_wChannels
);
147 writew(dev
.rec_sample_rate
, lpDAQ
+ DAQDS_wSampleRate
);
148 writew(HIMT_RECORD_DONE
* 0x100 + n
, lpDAQ
+ DAQDS_wIntMsg
);
149 writew(n
, lpDAQ
+ DAQDS_wFlags
);
153 static void reset_queues(void)
155 if (dev
.mode
& FMODE_WRITE
) {
156 msnd_fifo_make_empty(&dev
.DAPF
);
159 if (dev
.mode
& FMODE_READ
) {
160 msnd_fifo_make_empty(&dev
.DARF
);
161 reset_record_queue();
165 static int dsp_set_format(struct file
*file
, int val
)
168 LPDAQD lpDAQ
, lpDARQ
;
170 lpDAQ
= dev
.base
+ DAPQ_DATA_BUFF
;
171 lpDARQ
= dev
.base
+ DARQ_DATA_BUFF
;
179 data
= DEFSAMPLESIZE
;
183 for (i
= 0; i
< 3; ++i
, lpDAQ
+= DAQDS__size
, lpDARQ
+= DAQDS__size
) {
184 if (file
->f_mode
& FMODE_WRITE
)
185 writew(data
, lpDAQ
+ DAQDS_wSampleSize
);
186 if (file
->f_mode
& FMODE_READ
)
187 writew(data
, lpDARQ
+ DAQDS_wSampleSize
);
189 if (file
->f_mode
& FMODE_WRITE
)
190 dev
.play_sample_size
= data
;
191 if (file
->f_mode
& FMODE_READ
)
192 dev
.rec_sample_size
= data
;
197 static int dsp_get_frag_size(void)
200 size
= dev
.fifosize
/ 4;
201 if (size
> 32 * 1024)
206 static int dsp_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
208 int val
, i
, data
, tmp
;
209 LPDAQD lpDAQ
, lpDARQ
;
210 audio_buf_info abinfo
;
212 int __user
*p
= (int __user
*)arg
;
214 lpDAQ
= dev
.base
+ DAPQ_DATA_BUFF
;
215 lpDARQ
= dev
.base
+ DARQ_DATA_BUFF
;
218 case SNDCTL_DSP_SUBDIVIDE
:
219 case SNDCTL_DSP_SETFRAGMENT
:
220 case SNDCTL_DSP_SETDUPLEX
:
221 case SNDCTL_DSP_POST
:
224 case SNDCTL_DSP_GETIPTR
:
225 case SNDCTL_DSP_GETOPTR
:
226 case SNDCTL_DSP_MAPINBUF
:
227 case SNDCTL_DSP_MAPOUTBUF
:
230 case SNDCTL_DSP_GETOSPACE
:
231 if (!(file
->f_mode
& FMODE_WRITE
))
233 spin_lock_irqsave(&dev
.lock
, flags
);
234 abinfo
.fragsize
= dsp_get_frag_size();
235 abinfo
.bytes
= dev
.DAPF
.n
- dev
.DAPF
.len
;
236 abinfo
.fragstotal
= dev
.DAPF
.n
/ abinfo
.fragsize
;
237 abinfo
.fragments
= abinfo
.bytes
/ abinfo
.fragsize
;
238 spin_unlock_irqrestore(&dev
.lock
, flags
);
239 return copy_to_user((void __user
*)arg
, &abinfo
, sizeof(abinfo
)) ? -EFAULT
: 0;
241 case SNDCTL_DSP_GETISPACE
:
242 if (!(file
->f_mode
& FMODE_READ
))
244 spin_lock_irqsave(&dev
.lock
, flags
);
245 abinfo
.fragsize
= dsp_get_frag_size();
246 abinfo
.bytes
= dev
.DARF
.n
- dev
.DARF
.len
;
247 abinfo
.fragstotal
= dev
.DARF
.n
/ abinfo
.fragsize
;
248 abinfo
.fragments
= abinfo
.bytes
/ abinfo
.fragsize
;
249 spin_unlock_irqrestore(&dev
.lock
, flags
);
250 return copy_to_user((void __user
*)arg
, &abinfo
, sizeof(abinfo
)) ? -EFAULT
: 0;
252 case SNDCTL_DSP_RESET
:
257 case SNDCTL_DSP_SYNC
:
261 case SNDCTL_DSP_GETBLKSIZE
:
262 tmp
= dsp_get_frag_size();
263 if (put_user(tmp
, p
))
267 case SNDCTL_DSP_GETFMTS
:
268 val
= AFMT_S16_LE
| AFMT_U8
;
269 if (put_user(val
, p
))
273 case SNDCTL_DSP_SETFMT
:
274 if (get_user(val
, p
))
277 if (file
->f_mode
& FMODE_WRITE
)
278 data
= val
== AFMT_QUERY
279 ? dev
.play_sample_size
280 : dsp_set_format(file
, val
);
282 data
= val
== AFMT_QUERY
283 ? dev
.rec_sample_size
284 : dsp_set_format(file
, val
);
286 if (put_user(data
, p
))
290 case SNDCTL_DSP_NONBLOCK
:
291 if (!test_bit(F_DISABLE_WRITE_NDELAY
, &dev
.flags
) &&
292 file
->f_mode
& FMODE_WRITE
)
294 if (file
->f_mode
& FMODE_READ
)
298 case SNDCTL_DSP_GETCAPS
:
299 val
= DSP_CAP_DUPLEX
| DSP_CAP_BATCH
;
300 if (put_user(val
, p
))
304 case SNDCTL_DSP_SPEED
:
305 if (get_user(val
, p
))
316 for (i
= 0; i
< 3; ++i
, lpDAQ
+= DAQDS__size
, lpDARQ
+= DAQDS__size
) {
317 if (file
->f_mode
& FMODE_WRITE
)
318 writew(data
, lpDAQ
+ DAQDS_wSampleRate
);
319 if (file
->f_mode
& FMODE_READ
)
320 writew(data
, lpDARQ
+ DAQDS_wSampleRate
);
322 if (file
->f_mode
& FMODE_WRITE
)
323 dev
.play_sample_rate
= data
;
324 if (file
->f_mode
& FMODE_READ
)
325 dev
.rec_sample_rate
= data
;
327 if (put_user(data
, p
))
331 case SNDCTL_DSP_CHANNELS
:
332 case SNDCTL_DSP_STEREO
:
333 if (get_user(val
, p
))
336 if (cmd
== SNDCTL_DSP_CHANNELS
) {
359 for (i
= 0; i
< 3; ++i
, lpDAQ
+= DAQDS__size
, lpDARQ
+= DAQDS__size
) {
360 if (file
->f_mode
& FMODE_WRITE
)
361 writew(data
, lpDAQ
+ DAQDS_wChannels
);
362 if (file
->f_mode
& FMODE_READ
)
363 writew(data
, lpDARQ
+ DAQDS_wChannels
);
365 if (file
->f_mode
& FMODE_WRITE
)
366 dev
.play_channels
= data
;
367 if (file
->f_mode
& FMODE_READ
)
368 dev
.rec_channels
= data
;
370 if (put_user(val
, p
))
378 static int mixer_get(int d
)
384 case SOUND_MIXER_VOLUME
:
385 case SOUND_MIXER_PCM
:
386 case SOUND_MIXER_LINE
:
387 case SOUND_MIXER_IMIX
:
388 case SOUND_MIXER_LINE1
:
390 case SOUND_MIXER_MIC
:
391 case SOUND_MIXER_SYNTH
:
393 return (dev
.left_levels
[d
] >> 8) * 100 / 0xff |
394 (((dev
.right_levels
[d
] >> 8) * 100 / 0xff) << 8);
400 #define update_volm(a,b) \
401 writew((dev.left_levels[a] >> 1) * \
402 readw(dev.SMA + SMA_wCurrMastVolLeft) / 0xffff, \
403 dev.SMA + SMA_##b##Left); \
404 writew((dev.right_levels[a] >> 1) * \
405 readw(dev.SMA + SMA_wCurrMastVolRight) / 0xffff, \
406 dev.SMA + SMA_##b##Right);
408 #define update_potm(d,s,ar) \
409 writeb((dev.left_levels[d] >> 8) * \
410 readw(dev.SMA + SMA_wCurrMastVolLeft) / 0xffff, \
411 dev.SMA + SMA_##s##Left); \
412 writeb((dev.right_levels[d] >> 8) * \
413 readw(dev.SMA + SMA_wCurrMastVolRight) / 0xffff, \
414 dev.SMA + SMA_##s##Right); \
415 if (msnd_send_word(&dev, 0, 0, ar) == 0) \
416 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
418 #define update_pot(d,s,ar) \
419 writeb(dev.left_levels[d] >> 8, \
420 dev.SMA + SMA_##s##Left); \
421 writeb(dev.right_levels[d] >> 8, \
422 dev.SMA + SMA_##s##Right); \
423 if (msnd_send_word(&dev, 0, 0, ar) == 0) \
424 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
426 static int mixer_set(int d
, int value
)
428 int left
= value
& 0x000000ff;
429 int right
= (value
& 0x0000ff00) >> 8;
432 int updatemaster
= 0;
437 bLeft
= left
* 0xff / 100;
438 wLeft
= left
* 0xffff / 100;
440 bRight
= right
* 0xff / 100;
441 wRight
= right
* 0xffff / 100;
443 dev
.left_levels
[d
] = wLeft
;
444 dev
.right_levels
[d
] = wRight
;
447 /* master volume unscaled controls */
448 case SOUND_MIXER_LINE
: /* line pot control */
449 /* scaled by IMIX in digital mix */
450 writeb(bLeft
, dev
.SMA
+ SMA_bInPotPosLeft
);
451 writeb(bRight
, dev
.SMA
+ SMA_bInPotPosRight
);
452 if (msnd_send_word(&dev
, 0, 0, HDEXAR_IN_SET_POTS
) == 0)
453 chk_send_dsp_cmd(&dev
, HDEX_AUX_REQ
);
456 case SOUND_MIXER_MIC
: /* mic pot control */
457 /* scaled by IMIX in digital mix */
458 writeb(bLeft
, dev
.SMA
+ SMA_bMicPotPosLeft
);
459 writeb(bRight
, dev
.SMA
+ SMA_bMicPotPosRight
);
460 if (msnd_send_word(&dev
, 0, 0, HDEXAR_MIC_SET_POTS
) == 0)
461 chk_send_dsp_cmd(&dev
, HDEX_AUX_REQ
);
464 case SOUND_MIXER_VOLUME
: /* master volume */
465 writew(wLeft
, dev
.SMA
+ SMA_wCurrMastVolLeft
);
466 writew(wRight
, dev
.SMA
+ SMA_wCurrMastVolRight
);
469 case SOUND_MIXER_LINE1
: /* aux pot control */
470 /* scaled by master volume */
473 /* digital controls */
474 case SOUND_MIXER_SYNTH
: /* synth vol (dsp mix) */
475 case SOUND_MIXER_PCM
: /* pcm vol (dsp mix) */
476 case SOUND_MIXER_IMIX
: /* input monitor (dsp mix) */
477 /* scaled by master volume */
486 /* update master volume scaled controls */
487 update_volm(SOUND_MIXER_PCM
, wCurrPlayVol
);
488 update_volm(SOUND_MIXER_IMIX
, wCurrInVol
);
490 update_volm(SOUND_MIXER_SYNTH
, wCurrMHdrVol
);
492 update_potm(SOUND_MIXER_LINE1
, bAuxPotPos
, HDEXAR_AUX_SET_POTS
);
498 static void mixer_setup(void)
500 update_pot(SOUND_MIXER_LINE
, bInPotPos
, HDEXAR_IN_SET_POTS
);
501 update_potm(SOUND_MIXER_LINE1
, bAuxPotPos
, HDEXAR_AUX_SET_POTS
);
502 update_volm(SOUND_MIXER_PCM
, wCurrPlayVol
);
503 update_volm(SOUND_MIXER_IMIX
, wCurrInVol
);
505 update_pot(SOUND_MIXER_MIC
, bMicPotPos
, HDEXAR_MIC_SET_POTS
);
506 update_volm(SOUND_MIXER_SYNTH
, wCurrMHdrVol
);
510 static unsigned long set_recsrc(unsigned long recsrc
)
512 if (dev
.recsrc
== recsrc
)
515 else if (recsrc
== 0)
519 dev
.recsrc
^= recsrc
;
522 if (dev
.recsrc
& SOUND_MASK_IMIX
) {
523 if (msnd_send_word(&dev
, 0, 0, HDEXAR_SET_ANA_IN
) == 0)
524 chk_send_dsp_cmd(&dev
, HDEX_AUX_REQ
);
526 else if (dev
.recsrc
& SOUND_MASK_SYNTH
) {
527 if (msnd_send_word(&dev
, 0, 0, HDEXAR_SET_SYNTH_IN
) == 0)
528 chk_send_dsp_cmd(&dev
, HDEX_AUX_REQ
);
530 else if ((dev
.recsrc
& SOUND_MASK_DIGITAL1
) && test_bit(F_HAVEDIGITAL
, &dev
.flags
)) {
531 if (msnd_send_word(&dev
, 0, 0, HDEXAR_SET_DAT_IN
) == 0)
532 chk_send_dsp_cmd(&dev
, HDEX_AUX_REQ
);
536 /* Select no input (?) */
539 dev
.recsrc
= SOUND_MASK_IMIX
;
540 if (msnd_send_word(&dev
, 0, 0, HDEXAR_SET_ANA_IN
) == 0)
541 chk_send_dsp_cmd(&dev
, HDEX_AUX_REQ
);
544 #endif /* MSND_CLASSIC */
549 static unsigned long force_recsrc(unsigned long recsrc
)
552 return set_recsrc(recsrc
);
555 #define set_mixer_info() \
556 memset(&info, 0, sizeof(info)); \
557 strlcpy(info.id, "MSNDMIXER", sizeof(info.id)); \
558 strlcpy(info.name, "MultiSound Mixer", sizeof(info.name));
560 static int mixer_ioctl(unsigned int cmd
, unsigned long arg
)
562 if (cmd
== SOUND_MIXER_INFO
) {
565 info
.modify_counter
= dev
.mixer_mod_count
;
566 if (copy_to_user((void __user
*)arg
, &info
, sizeof(info
)))
569 } else if (cmd
== SOUND_OLD_MIXER_INFO
) {
570 _old_mixer_info info
;
572 if (copy_to_user((void __user
*)arg
, &info
, sizeof(info
)))
575 } else if (cmd
== SOUND_MIXER_PRIVATE1
) {
579 } else if (((cmd
>> 8) & 0xff) == 'M') {
582 if (_SIOC_DIR(cmd
) & _SIOC_WRITE
) {
583 switch (cmd
& 0xff) {
584 case SOUND_MIXER_RECSRC
:
585 if (get_user(val
, (int __user
*)arg
))
587 val
= set_recsrc(val
);
591 if (get_user(val
, (int __user
*)arg
))
593 val
= mixer_set(cmd
& 0xff, val
);
596 ++dev
.mixer_mod_count
;
597 return put_user(val
, (int __user
*)arg
);
599 switch (cmd
& 0xff) {
600 case SOUND_MIXER_RECSRC
:
604 case SOUND_MIXER_DEVMASK
:
605 case SOUND_MIXER_STEREODEVS
:
606 val
= SOUND_MASK_PCM
|
617 case SOUND_MIXER_RECMASK
:
621 val
= SOUND_MASK_IMIX
|
623 if (test_bit(F_HAVEDIGITAL
, &dev
.flags
))
624 val
|= SOUND_MASK_DIGITAL1
;
628 case SOUND_MIXER_CAPS
:
629 val
= SOUND_CAP_EXCL_INPUT
;
633 if ((val
= mixer_get(cmd
& 0xff)) < 0)
639 return put_user(val
, (int __user
*)arg
);
645 static long dev_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
647 int minor
= iminor(file_inode(file
));
650 if (cmd
== OSS_GETVERSION
) {
651 int sound_version
= SOUND_VERSION
;
652 return put_user(sound_version
, (int __user
*)arg
);
657 mutex_lock(&msnd_pinnacle_mutex
);
658 if (minor
== dev
.dsp_minor
)
659 ret
= dsp_ioctl(file
, cmd
, arg
);
660 else if (minor
== dev
.mixer_minor
)
661 ret
= mixer_ioctl(cmd
, arg
);
662 mutex_unlock(&msnd_pinnacle_mutex
);
667 static void dsp_write_flush(void)
669 int timeout
= get_play_delay_jiffies(dev
.DAPF
.len
);
671 if (!(dev
.mode
& FMODE_WRITE
) || !test_bit(F_WRITING
, &dev
.flags
))
673 set_bit(F_WRITEFLUSH
, &dev
.flags
);
674 wait_event_interruptible_timeout(
676 !test_bit(F_WRITEFLUSH
, &dev
.flags
),
678 clear_bit(F_WRITEFLUSH
, &dev
.flags
);
679 if (!signal_pending(current
)) {
680 __set_current_state(TASK_INTERRUPTIBLE
);
681 schedule_timeout(get_play_delay_jiffies(DAP_BUFF_SIZE
));
683 clear_bit(F_WRITING
, &dev
.flags
);
686 static void dsp_halt(struct file
*file
)
688 if ((file
? file
->f_mode
: dev
.mode
) & FMODE_READ
) {
689 clear_bit(F_READING
, &dev
.flags
);
690 chk_send_dsp_cmd(&dev
, HDEX_RECORD_STOP
);
691 msnd_disable_irq(&dev
);
693 printk(KERN_DEBUG LOGNAME
": Stopping read for %p\n", file
);
694 dev
.mode
&= ~FMODE_READ
;
696 clear_bit(F_AUDIO_READ_INUSE
, &dev
.flags
);
698 if ((file
? file
->f_mode
: dev
.mode
) & FMODE_WRITE
) {
699 if (test_bit(F_WRITING
, &dev
.flags
)) {
701 chk_send_dsp_cmd(&dev
, HDEX_PLAY_STOP
);
703 msnd_disable_irq(&dev
);
705 printk(KERN_DEBUG LOGNAME
": Stopping write for %p\n", file
);
706 dev
.mode
&= ~FMODE_WRITE
;
708 clear_bit(F_AUDIO_WRITE_INUSE
, &dev
.flags
);
712 static int dsp_release(struct file
*file
)
718 static int dsp_open(struct file
*file
)
720 if ((file
? file
->f_mode
: dev
.mode
) & FMODE_WRITE
) {
721 set_bit(F_AUDIO_WRITE_INUSE
, &dev
.flags
);
722 clear_bit(F_WRITING
, &dev
.flags
);
723 msnd_fifo_make_empty(&dev
.DAPF
);
726 printk(KERN_DEBUG LOGNAME
": Starting write for %p\n", file
);
727 dev
.mode
|= FMODE_WRITE
;
729 msnd_enable_irq(&dev
);
731 if ((file
? file
->f_mode
: dev
.mode
) & FMODE_READ
) {
732 set_bit(F_AUDIO_READ_INUSE
, &dev
.flags
);
733 clear_bit(F_READING
, &dev
.flags
);
734 msnd_fifo_make_empty(&dev
.DARF
);
735 reset_record_queue();
737 printk(KERN_DEBUG LOGNAME
": Starting read for %p\n", file
);
738 dev
.mode
|= FMODE_READ
;
740 msnd_enable_irq(&dev
);
745 static void set_default_play_audio_parameters(void)
747 dev
.play_sample_size
= DEFSAMPLESIZE
;
748 dev
.play_sample_rate
= DEFSAMPLERATE
;
749 dev
.play_channels
= DEFCHANNELS
;
752 static void set_default_rec_audio_parameters(void)
754 dev
.rec_sample_size
= DEFSAMPLESIZE
;
755 dev
.rec_sample_rate
= DEFSAMPLERATE
;
756 dev
.rec_channels
= DEFCHANNELS
;
759 static void set_default_audio_parameters(void)
761 set_default_play_audio_parameters();
762 set_default_rec_audio_parameters();
765 static int dev_open(struct inode
*inode
, struct file
*file
)
767 int minor
= iminor(inode
);
770 mutex_lock(&msnd_pinnacle_mutex
);
771 if (minor
== dev
.dsp_minor
) {
772 if ((file
->f_mode
& FMODE_WRITE
&&
773 test_bit(F_AUDIO_WRITE_INUSE
, &dev
.flags
)) ||
774 (file
->f_mode
& FMODE_READ
&&
775 test_bit(F_AUDIO_READ_INUSE
, &dev
.flags
))) {
780 if ((err
= dsp_open(file
)) >= 0) {
782 if (file
->f_mode
& FMODE_WRITE
) {
783 set_default_play_audio_parameters();
784 if (!test_bit(F_DISABLE_WRITE_NDELAY
, &dev
.flags
))
785 dev
.play_ndelay
= (file
->f_flags
& O_NDELAY
) ? 1 : 0;
789 if (file
->f_mode
& FMODE_READ
) {
790 set_default_rec_audio_parameters();
791 dev
.rec_ndelay
= (file
->f_flags
& O_NDELAY
) ? 1 : 0;
795 else if (minor
== dev
.mixer_minor
) {
800 mutex_unlock(&msnd_pinnacle_mutex
);
804 static int dev_release(struct inode
*inode
, struct file
*file
)
806 int minor
= iminor(inode
);
809 mutex_lock(&msnd_pinnacle_mutex
);
810 if (minor
== dev
.dsp_minor
)
811 err
= dsp_release(file
);
812 else if (minor
== dev
.mixer_minor
) {
816 mutex_unlock(&msnd_pinnacle_mutex
);
820 static __inline__
int pack_DARQ_to_DARF(register int bank
)
822 register int size
, timeout
= 3;
826 /* Increment the tail and check for queue wrap */
827 wTmp
= readw(dev
.DARQ
+ JQS_wTail
) + PCTODSP_OFFSET(DAQDS__size
);
828 if (wTmp
> readw(dev
.DARQ
+ JQS_wSize
))
830 while (wTmp
== readw(dev
.DARQ
+ JQS_wHead
) && timeout
--)
832 writew(wTmp
, dev
.DARQ
+ JQS_wTail
);
834 /* Get our digital audio queue struct */
835 DAQD
= bank
* DAQDS__size
+ dev
.base
+ DARQ_DATA_BUFF
;
837 /* Get length of data */
838 size
= readw(DAQD
+ DAQDS_wSize
);
840 /* Read data from the head (unprotected bank 1 access okay
841 since this is only called inside an interrupt) */
842 msnd_outb(HPBLKSEL_1
, dev
.io
+ HP_BLKS
);
845 dev
.base
+ bank
* DAR_BUFF_SIZE
,
847 msnd_outb(HPBLKSEL_0
, dev
.io
+ HP_BLKS
);
852 static __inline__
int pack_DAPF_to_DAPQ(register int start
)
854 register WORD DAPQ_tail
;
855 register int protect
= start
, nbanks
= 0;
858 DAPQ_tail
= readw(dev
.DAPQ
+ JQS_wTail
);
859 while (DAPQ_tail
!= readw(dev
.DAPQ
+ JQS_wHead
) || start
) {
860 register int bank_num
= DAPQ_tail
/ PCTODSP_OFFSET(DAQDS__size
);
864 /* Write the data to the new tail */
866 /* Critical section: protect fifo in non-interrupt */
867 spin_lock_irqsave(&dev
.lock
, flags
);
868 n
= msnd_fifo_read_io(
870 dev
.base
+ bank_num
* DAP_BUFF_SIZE
,
872 spin_unlock_irqrestore(&dev
.lock
, flags
);
874 n
= msnd_fifo_read_io(
876 dev
.base
+ bank_num
* DAP_BUFF_SIZE
,
885 /* Get our digital audio queue struct */
886 DAQD
= bank_num
* DAQDS__size
+ dev
.base
+ DAPQ_DATA_BUFF
;
888 /* Write size of this bank */
889 writew(n
, DAQD
+ DAQDS_wSize
);
892 /* Then advance the tail */
893 DAPQ_tail
= (++bank_num
% 3) * PCTODSP_OFFSET(DAQDS__size
);
894 writew(DAPQ_tail
, dev
.DAPQ
+ JQS_wTail
);
895 /* Tell the DSP to play the bank */
896 msnd_send_dsp_cmd(&dev
, HDEX_PLAY_START
);
901 static int dsp_read(char __user
*buf
, size_t len
)
904 char *page
= (char *)__get_free_page(GFP_KERNEL
);
905 int timeout
= get_rec_delay_jiffies(DAR_BUFF_SIZE
);
918 /* Critical section: protect fifo in non-interrupt */
919 spin_lock_irqsave(&dev
.lock
, flags
);
920 n
= msnd_fifo_read(&dev
.DARF
, page
, k
);
921 spin_unlock_irqrestore(&dev
.lock
, flags
);
922 if (copy_to_user(buf
, page
, n
)) {
923 free_page((unsigned long)page
);
932 if (!test_bit(F_READING
, &dev
.flags
) && dev
.mode
& FMODE_READ
) {
933 dev
.last_recbank
= -1;
934 if (chk_send_dsp_cmd(&dev
, HDEX_RECORD_START
) == 0)
935 set_bit(F_READING
, &dev
.flags
);
938 if (dev
.rec_ndelay
) {
939 free_page((unsigned long)page
);
940 return count
== len
? -EAGAIN
: len
- count
;
944 set_bit(F_READBLOCK
, &dev
.flags
);
945 if (wait_event_interruptible_timeout(
947 test_bit(F_READBLOCK
, &dev
.flags
),
949 clear_bit(F_READING
, &dev
.flags
);
950 if (signal_pending(current
)) {
951 free_page((unsigned long)page
);
956 free_page((unsigned long)page
);
960 static int dsp_write(const char __user
*buf
, size_t len
)
963 char *page
= (char *)__get_free_page(GFP_KERNEL
);
964 int timeout
= get_play_delay_jiffies(DAP_BUFF_SIZE
);
977 if (copy_from_user(page
, buf
, k
)) {
978 free_page((unsigned long)page
);
982 /* Critical section: protect fifo in non-interrupt */
983 spin_lock_irqsave(&dev
.lock
, flags
);
984 n
= msnd_fifo_write(&dev
.DAPF
, page
, k
);
985 spin_unlock_irqrestore(&dev
.lock
, flags
);
992 if (!test_bit(F_WRITING
, &dev
.flags
) && (dev
.mode
& FMODE_WRITE
)) {
993 dev
.last_playbank
= -1;
994 if (pack_DAPF_to_DAPQ(1) > 0)
995 set_bit(F_WRITING
, &dev
.flags
);
998 if (dev
.play_ndelay
) {
999 free_page((unsigned long)page
);
1000 return count
== len
? -EAGAIN
: len
- count
;
1004 set_bit(F_WRITEBLOCK
, &dev
.flags
);
1005 wait_event_interruptible_timeout(
1007 test_bit(F_WRITEBLOCK
, &dev
.flags
),
1009 if (signal_pending(current
)) {
1010 free_page((unsigned long)page
);
1016 free_page((unsigned long)page
);
1020 static ssize_t
dev_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*off
)
1022 int minor
= iminor(file_inode(file
));
1023 if (minor
== dev
.dsp_minor
)
1024 return dsp_read(buf
, count
);
1029 static ssize_t
dev_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*off
)
1031 int minor
= iminor(file_inode(file
));
1032 if (minor
== dev
.dsp_minor
)
1033 return dsp_write(buf
, count
);
1038 static __inline__
void eval_dsp_msg(register WORD wMessage
)
1040 switch (HIBYTE(wMessage
)) {
1041 case HIMT_PLAY_DONE
:
1042 if (dev
.last_playbank
== LOBYTE(wMessage
) || !test_bit(F_WRITING
, &dev
.flags
))
1044 dev
.last_playbank
= LOBYTE(wMessage
);
1046 if (pack_DAPF_to_DAPQ(0) <= 0) {
1047 if (!test_bit(F_WRITEBLOCK
, &dev
.flags
)) {
1048 if (test_and_clear_bit(F_WRITEFLUSH
, &dev
.flags
))
1049 wake_up_interruptible(&dev
.writeflush
);
1051 clear_bit(F_WRITING
, &dev
.flags
);
1054 if (test_and_clear_bit(F_WRITEBLOCK
, &dev
.flags
))
1055 wake_up_interruptible(&dev
.writeblock
);
1058 case HIMT_RECORD_DONE
:
1059 if (dev
.last_recbank
== LOBYTE(wMessage
))
1061 dev
.last_recbank
= LOBYTE(wMessage
);
1063 pack_DARQ_to_DARF(dev
.last_recbank
);
1065 if (test_and_clear_bit(F_READBLOCK
, &dev
.flags
))
1066 wake_up_interruptible(&dev
.readblock
);
1070 switch (LOBYTE(wMessage
)) {
1071 #ifndef MSND_CLASSIC
1072 case HIDSP_PLAY_UNDER
:
1074 case HIDSP_INT_PLAY_UNDER
:
1075 /* printk(KERN_DEBUG LOGNAME ": Play underflow\n"); */
1076 clear_bit(F_WRITING
, &dev
.flags
);
1079 case HIDSP_INT_RECORD_OVER
:
1080 /* printk(KERN_DEBUG LOGNAME ": Record overflow\n"); */
1081 clear_bit(F_READING
, &dev
.flags
);
1085 /* printk(KERN_DEBUG LOGNAME ": DSP message %d 0x%02x\n",
1086 LOBYTE(wMessage), LOBYTE(wMessage)); */
1091 case HIMT_MIDI_IN_UCHAR
:
1092 if (dev
.midi_in_interrupt
)
1093 (*dev
.midi_in_interrupt
)(&dev
);
1097 /* printk(KERN_DEBUG LOGNAME ": HIMT message %d 0x%02x\n", HIBYTE(wMessage), HIBYTE(wMessage)); */
1102 static irqreturn_t
intr(int irq
, void *dev_id
)
1104 /* Send ack to DSP */
1105 msnd_inb(dev
.io
+ HP_RXL
);
1107 /* Evaluate queued DSP messages */
1108 while (readw(dev
.DSPQ
+ JQS_wTail
) != readw(dev
.DSPQ
+ JQS_wHead
)) {
1111 eval_dsp_msg(readw(dev
.pwDSPQData
+ 2*readw(dev
.DSPQ
+ JQS_wHead
)));
1113 if ((wTmp
= readw(dev
.DSPQ
+ JQS_wHead
) + 1) > readw(dev
.DSPQ
+ JQS_wSize
))
1114 writew(0, dev
.DSPQ
+ JQS_wHead
);
1116 writew(wTmp
, dev
.DSPQ
+ JQS_wHead
);
1121 static const struct file_operations dev_fileops
= {
1122 .owner
= THIS_MODULE
,
1125 .unlocked_ioctl
= dev_ioctl
,
1127 .release
= dev_release
,
1128 .llseek
= noop_llseek
,
1131 static int reset_dsp(void)
1135 msnd_outb(HPDSPRESET_ON
, dev
.io
+ HP_DSPR
);
1137 #ifndef MSND_CLASSIC
1138 dev
.info
= msnd_inb(dev
.io
+ HP_INFO
);
1140 msnd_outb(HPDSPRESET_OFF
, dev
.io
+ HP_DSPR
);
1142 while (timeout
-- > 0) {
1143 if (msnd_inb(dev
.io
+ HP_CVR
) == HP_CVR_DEF
)
1147 printk(KERN_ERR LOGNAME
": Cannot reset DSP\n");
1152 static int __init
probe_multisound(void)
1154 #ifndef MSND_CLASSIC
1155 char *xv
, *rev
= NULL
;
1156 char *pin
= "Pinnacle", *fiji
= "Fiji";
1157 char *pinfiji
= "Pinnacle/Fiji";
1160 if (!request_region(dev
.io
, dev
.numio
, "probing")) {
1161 printk(KERN_ERR LOGNAME
": I/O port conflict\n");
1165 if (reset_dsp() < 0) {
1166 release_region(dev
.io
, dev
.numio
);
1171 dev
.name
= "Classic/Tahiti/Monterey";
1172 printk(KERN_INFO LOGNAME
": %s, "
1174 switch (dev
.info
>> 4) {
1175 case 0xf: xv
= "<= 1.15"; break;
1176 case 0x1: xv
= "1.18/1.2"; break;
1177 case 0x2: xv
= "1.3"; break;
1178 case 0x3: xv
= "1.4"; break;
1179 default: xv
= "unknown"; break;
1182 switch (dev
.info
& 0x7) {
1183 case 0x0: rev
= "I"; dev
.name
= pin
; break;
1184 case 0x1: rev
= "F"; dev
.name
= pin
; break;
1185 case 0x2: rev
= "G"; dev
.name
= pin
; break;
1186 case 0x3: rev
= "H"; dev
.name
= pin
; break;
1187 case 0x4: rev
= "E"; dev
.name
= fiji
; break;
1188 case 0x5: rev
= "C"; dev
.name
= fiji
; break;
1189 case 0x6: rev
= "D"; dev
.name
= fiji
; break;
1191 rev
= "A-B (Fiji) or A-E (Pinnacle)";
1195 printk(KERN_INFO LOGNAME
": %s revision %s, Xilinx version %s, "
1196 #endif /* MSND_CLASSIC */
1197 "I/O 0x%x-0x%x, IRQ %d, memory mapped to %p-%p\n",
1199 #ifndef MSND_CLASSIC
1202 dev
.io
, dev
.io
+ dev
.numio
- 1,
1204 dev
.base
, dev
.base
+ 0x7fff);
1206 release_region(dev
.io
, dev
.numio
);
1210 static int init_sma(void)
1213 WORD mastVolLeft
, mastVolRight
;
1214 unsigned long flags
;
1217 msnd_outb(dev
.memid
, dev
.io
+ HP_MEMM
);
1219 msnd_outb(HPBLKSEL_0
, dev
.io
+ HP_BLKS
);
1221 mastVolLeft
= readw(dev
.SMA
+ SMA_wCurrMastVolLeft
);
1222 mastVolRight
= readw(dev
.SMA
+ SMA_wCurrMastVolRight
);
1224 mastVolLeft
= mastVolRight
= 0;
1225 memset_io(dev
.base
, 0, 0x8000);
1227 /* Critical section: bank 1 access */
1228 spin_lock_irqsave(&dev
.lock
, flags
);
1229 msnd_outb(HPBLKSEL_1
, dev
.io
+ HP_BLKS
);
1230 memset_io(dev
.base
, 0, 0x8000);
1231 msnd_outb(HPBLKSEL_0
, dev
.io
+ HP_BLKS
);
1232 spin_unlock_irqrestore(&dev
.lock
, flags
);
1234 dev
.pwDSPQData
= (dev
.base
+ DSPQ_DATA_BUFF
);
1235 dev
.pwMODQData
= (dev
.base
+ MODQ_DATA_BUFF
);
1236 dev
.pwMIDQData
= (dev
.base
+ MIDQ_DATA_BUFF
);
1238 /* Motorola 56k shared memory base */
1239 dev
.SMA
= dev
.base
+ SMA_STRUCT_START
;
1241 /* Digital audio play queue */
1242 dev
.DAPQ
= dev
.base
+ DAPQ_OFFSET
;
1243 msnd_init_queue(dev
.DAPQ
, DAPQ_DATA_BUFF
, DAPQ_BUFF_SIZE
);
1245 /* Digital audio record queue */
1246 dev
.DARQ
= dev
.base
+ DARQ_OFFSET
;
1247 msnd_init_queue(dev
.DARQ
, DARQ_DATA_BUFF
, DARQ_BUFF_SIZE
);
1249 /* MIDI out queue */
1250 dev
.MODQ
= dev
.base
+ MODQ_OFFSET
;
1251 msnd_init_queue(dev
.MODQ
, MODQ_DATA_BUFF
, MODQ_BUFF_SIZE
);
1254 dev
.MIDQ
= dev
.base
+ MIDQ_OFFSET
;
1255 msnd_init_queue(dev
.MIDQ
, MIDQ_DATA_BUFF
, MIDQ_BUFF_SIZE
);
1257 /* DSP -> host message queue */
1258 dev
.DSPQ
= dev
.base
+ DSPQ_OFFSET
;
1259 msnd_init_queue(dev
.DSPQ
, DSPQ_DATA_BUFF
, DSPQ_BUFF_SIZE
);
1261 /* Setup some DSP values */
1262 #ifndef MSND_CLASSIC
1263 writew(1, dev
.SMA
+ SMA_wCurrPlayFormat
);
1264 writew(dev
.play_sample_size
, dev
.SMA
+ SMA_wCurrPlaySampleSize
);
1265 writew(dev
.play_channels
, dev
.SMA
+ SMA_wCurrPlayChannels
);
1266 writew(dev
.play_sample_rate
, dev
.SMA
+ SMA_wCurrPlaySampleRate
);
1268 writew(dev
.play_sample_rate
, dev
.SMA
+ SMA_wCalFreqAtoD
);
1269 writew(mastVolLeft
, dev
.SMA
+ SMA_wCurrMastVolLeft
);
1270 writew(mastVolRight
, dev
.SMA
+ SMA_wCurrMastVolRight
);
1271 #ifndef MSND_CLASSIC
1272 writel(0x00010000, dev
.SMA
+ SMA_dwCurrPlayPitch
);
1273 writel(0x00000001, dev
.SMA
+ SMA_dwCurrPlayRate
);
1275 writew(0x303, dev
.SMA
+ SMA_wCurrInputTagBits
);
1282 static int __init
calibrate_adc(WORD srate
)
1284 writew(srate
, dev
.SMA
+ SMA_wCalFreqAtoD
);
1285 if (dev
.calibrate_signal
== 0)
1286 writew(readw(dev
.SMA
+ SMA_wCurrHostStatusFlags
)
1287 | 0x0001, dev
.SMA
+ SMA_wCurrHostStatusFlags
);
1289 writew(readw(dev
.SMA
+ SMA_wCurrHostStatusFlags
)
1290 & ~0x0001, dev
.SMA
+ SMA_wCurrHostStatusFlags
);
1291 if (msnd_send_word(&dev
, 0, 0, HDEXAR_CAL_A_TO_D
) == 0 &&
1292 chk_send_dsp_cmd(&dev
, HDEX_AUX_REQ
) == 0) {
1293 schedule_timeout_interruptible(HZ
/ 3);
1296 printk(KERN_WARNING LOGNAME
": ADC calibration failed\n");
1301 static int upload_dsp_code(void)
1305 msnd_outb(HPBLKSEL_0
, dev
.io
+ HP_BLKS
);
1306 #ifndef HAVE_DSPCODEH
1307 INITCODESIZE
= mod_firmware_load(INITCODEFILE
, &INITCODE
);
1309 printk(KERN_ERR LOGNAME
": Error loading " INITCODEFILE
);
1313 PERMCODESIZE
= mod_firmware_load(PERMCODEFILE
, &PERMCODE
);
1315 printk(KERN_ERR LOGNAME
": Error loading " PERMCODEFILE
);
1320 memcpy_toio(dev
.base
, PERMCODE
, PERMCODESIZE
);
1321 if (msnd_upload_host(&dev
, INITCODE
, INITCODESIZE
) < 0) {
1322 printk(KERN_WARNING LOGNAME
": Error uploading to DSP\n");
1326 #ifdef HAVE_DSPCODEH
1327 printk(KERN_INFO LOGNAME
": DSP firmware uploaded (resident)\n");
1329 printk(KERN_INFO LOGNAME
": DSP firmware uploaded\n");
1333 #ifndef HAVE_DSPCODEH
1342 static void reset_proteus(void)
1344 msnd_outb(HPPRORESET_ON
, dev
.io
+ HP_PROR
);
1345 mdelay(TIME_PRO_RESET
);
1346 msnd_outb(HPPRORESET_OFF
, dev
.io
+ HP_PROR
);
1347 mdelay(TIME_PRO_RESET_DONE
);
1351 static int initialize(void)
1356 msnd_outb(HPWAITSTATE_0
, dev
.io
+ HP_WAIT
);
1357 msnd_outb(HPBITMODE_16
, dev
.io
+ HP_BITM
);
1361 if ((err
= init_sma()) < 0) {
1362 printk(KERN_WARNING LOGNAME
": Cannot initialize SMA\n");
1366 if ((err
= reset_dsp()) < 0)
1369 if ((err
= upload_dsp_code()) < 0) {
1370 printk(KERN_WARNING LOGNAME
": Cannot upload DSP code\n");
1375 while (readw(dev
.base
)) {
1378 printk(KERN_DEBUG LOGNAME
": DSP reset timeout\n");
1388 static int dsp_full_reset(void)
1392 if (test_bit(F_RESETTING
, &dev
.flags
) || ++dev
.nresets
> 10)
1395 set_bit(F_RESETTING
, &dev
.flags
);
1396 printk(KERN_INFO LOGNAME
": DSP reset\n");
1397 dsp_halt(NULL
); /* Unconditionally halt */
1398 if ((rv
= initialize()))
1399 printk(KERN_WARNING LOGNAME
": DSP reset failed\n");
1400 force_recsrc(dev
.recsrc
);
1402 clear_bit(F_RESETTING
, &dev
.flags
);
1407 static int __init
attach_multisound(void)
1411 if ((err
= request_irq(dev
.irq
, intr
, 0, dev
.name
, &dev
)) < 0) {
1412 printk(KERN_ERR LOGNAME
": Couldn't grab IRQ %d\n", dev
.irq
);
1415 if (request_region(dev
.io
, dev
.numio
, dev
.name
) == NULL
) {
1416 free_irq(dev
.irq
, &dev
);
1420 err
= dsp_full_reset();
1422 release_region(dev
.io
, dev
.numio
);
1423 free_irq(dev
.irq
, &dev
);
1427 if ((err
= msnd_register(&dev
)) < 0) {
1428 printk(KERN_ERR LOGNAME
": Unable to register MultiSound\n");
1429 release_region(dev
.io
, dev
.numio
);
1430 free_irq(dev
.irq
, &dev
);
1434 if ((dev
.dsp_minor
= register_sound_dsp(&dev_fileops
, -1)) < 0) {
1435 printk(KERN_ERR LOGNAME
": Unable to register DSP operations\n");
1436 msnd_unregister(&dev
);
1437 release_region(dev
.io
, dev
.numio
);
1438 free_irq(dev
.irq
, &dev
);
1439 return dev
.dsp_minor
;
1442 if ((dev
.mixer_minor
= register_sound_mixer(&dev_fileops
, -1)) < 0) {
1443 printk(KERN_ERR LOGNAME
": Unable to register mixer operations\n");
1444 unregister_sound_mixer(dev
.mixer_minor
);
1445 msnd_unregister(&dev
);
1446 release_region(dev
.io
, dev
.numio
);
1447 free_irq(dev
.irq
, &dev
);
1448 return dev
.mixer_minor
;
1451 dev
.ext_midi_dev
= dev
.hdr_midi_dev
= -1;
1453 disable_irq(dev
.irq
);
1454 calibrate_adc(dev
.play_sample_rate
);
1455 #ifndef MSND_CLASSIC
1456 force_recsrc(SOUND_MASK_IMIX
);
1462 static void __exit
unload_multisound(void)
1464 release_region(dev
.io
, dev
.numio
);
1465 free_irq(dev
.irq
, &dev
);
1466 unregister_sound_mixer(dev
.mixer_minor
);
1467 unregister_sound_dsp(dev
.dsp_minor
);
1468 msnd_unregister(&dev
);
1471 #ifndef MSND_CLASSIC
1473 /* Pinnacle/Fiji Logical Device Configuration */
1475 static int __init
msnd_write_cfg(int cfg
, int reg
, int value
)
1477 msnd_outb(reg
, cfg
);
1478 msnd_outb(value
, cfg
+ 1);
1479 if (value
!= msnd_inb(cfg
+ 1)) {
1480 printk(KERN_ERR LOGNAME
": msnd_write_cfg: I/O error\n");
1486 static int __init
msnd_write_cfg_io0(int cfg
, int num
, WORD io
)
1488 if (msnd_write_cfg(cfg
, IREG_LOGDEVICE
, num
))
1490 if (msnd_write_cfg(cfg
, IREG_IO0_BASEHI
, HIBYTE(io
)))
1492 if (msnd_write_cfg(cfg
, IREG_IO0_BASELO
, LOBYTE(io
)))
1497 static int __init
msnd_write_cfg_io1(int cfg
, int num
, WORD io
)
1499 if (msnd_write_cfg(cfg
, IREG_LOGDEVICE
, num
))
1501 if (msnd_write_cfg(cfg
, IREG_IO1_BASEHI
, HIBYTE(io
)))
1503 if (msnd_write_cfg(cfg
, IREG_IO1_BASELO
, LOBYTE(io
)))
1508 static int __init
msnd_write_cfg_irq(int cfg
, int num
, WORD irq
)
1510 if (msnd_write_cfg(cfg
, IREG_LOGDEVICE
, num
))
1512 if (msnd_write_cfg(cfg
, IREG_IRQ_NUMBER
, LOBYTE(irq
)))
1514 if (msnd_write_cfg(cfg
, IREG_IRQ_TYPE
, IRQTYPE_EDGE
))
1519 static int __init
msnd_write_cfg_mem(int cfg
, int num
, int mem
)
1526 if (msnd_write_cfg(cfg
, IREG_LOGDEVICE
, num
))
1528 if (msnd_write_cfg(cfg
, IREG_MEMBASEHI
, HIBYTE(wmem
)))
1530 if (msnd_write_cfg(cfg
, IREG_MEMBASELO
, LOBYTE(wmem
)))
1532 if (wmem
&& msnd_write_cfg(cfg
, IREG_MEMCONTROL
, (MEMTYPE_HIADDR
| MEMTYPE_16BIT
)))
1537 static int __init
msnd_activate_logical(int cfg
, int num
)
1539 if (msnd_write_cfg(cfg
, IREG_LOGDEVICE
, num
))
1541 if (msnd_write_cfg(cfg
, IREG_ACTIVATE
, LD_ACTIVATE
))
1546 static int __init
msnd_write_cfg_logical(int cfg
, int num
, WORD io0
, WORD io1
, WORD irq
, int mem
)
1548 if (msnd_write_cfg(cfg
, IREG_LOGDEVICE
, num
))
1550 if (msnd_write_cfg_io0(cfg
, num
, io0
))
1552 if (msnd_write_cfg_io1(cfg
, num
, io1
))
1554 if (msnd_write_cfg_irq(cfg
, num
, irq
))
1556 if (msnd_write_cfg_mem(cfg
, num
, mem
))
1558 if (msnd_activate_logical(cfg
, num
))
1563 typedef struct msnd_pinnacle_cfg_device
{
1566 } msnd_pinnacle_cfg_t
[4];
1568 static int __init
msnd_pinnacle_cfg_devices(int cfg
, int reset
, msnd_pinnacle_cfg_t device
)
1572 /* Reset devices if told to */
1574 printk(KERN_INFO LOGNAME
": Resetting all devices\n");
1575 for (i
= 0; i
< 4; ++i
)
1576 if (msnd_write_cfg_logical(cfg
, i
, 0, 0, 0, 0))
1580 /* Configure specified devices */
1581 for (i
= 0; i
< 4; ++i
) {
1585 if (!(device
[i
].io0
&& device
[i
].irq
&& device
[i
].mem
))
1589 if (!(device
[i
].io0
&& device
[i
].irq
))
1591 printk(KERN_INFO LOGNAME
1592 ": Configuring MPU to I/O 0x%x IRQ %d\n",
1593 device
[i
].io0
, device
[i
].irq
);
1596 if (!(device
[i
].io0
&& device
[i
].io1
&& device
[i
].irq
))
1598 printk(KERN_INFO LOGNAME
1599 ": Configuring IDE to I/O 0x%x, 0x%x IRQ %d\n",
1600 device
[i
].io0
, device
[i
].io1
, device
[i
].irq
);
1602 case 3: /* Joystick */
1603 if (!(device
[i
].io0
))
1605 printk(KERN_INFO LOGNAME
1606 ": Configuring joystick to I/O 0x%x\n",
1611 /* Configure the device */
1612 if (msnd_write_cfg_logical(cfg
, i
, device
[i
].io0
, device
[i
].io1
, device
[i
].irq
, device
[i
].mem
))
1621 MODULE_AUTHOR ("Andrew Veliath <andrewtv@usa.net>");
1622 MODULE_DESCRIPTION ("Turtle Beach " LONGNAME
" Linux Driver");
1623 MODULE_LICENSE("GPL");
1625 static int io __initdata
= -1;
1626 static int irq __initdata
= -1;
1627 static int mem __initdata
= -1;
1628 static int write_ndelay __initdata
= -1;
1630 #ifndef MSND_CLASSIC
1631 /* Pinnacle/Fiji non-PnP Config Port */
1632 static int cfg __initdata
= -1;
1634 /* Extra Peripheral Configuration */
1635 static int reset __initdata
= 0;
1636 static int mpu_io __initdata
= 0;
1637 static int mpu_irq __initdata
= 0;
1638 static int ide_io0 __initdata
= 0;
1639 static int ide_io1 __initdata
= 0;
1640 static int ide_irq __initdata
= 0;
1641 static int joystick_io __initdata
= 0;
1643 /* If we have the digital daugherboard... */
1644 static bool digital __initdata
= false;
1647 static int fifosize __initdata
= DEFFIFOSIZE
;
1648 static int calibrate_signal __initdata
= 0;
1650 #else /* not a module */
1652 static int write_ndelay __initdata
= -1;
1655 static int io __initdata
= CONFIG_MSNDCLAS_IO
;
1656 static int irq __initdata
= CONFIG_MSNDCLAS_IRQ
;
1657 static int mem __initdata
= CONFIG_MSNDCLAS_MEM
;
1658 #else /* Pinnacle/Fiji */
1660 static int io __initdata
= CONFIG_MSNDPIN_IO
;
1661 static int irq __initdata
= CONFIG_MSNDPIN_IRQ
;
1662 static int mem __initdata
= CONFIG_MSNDPIN_MEM
;
1664 /* Pinnacle/Fiji non-PnP Config Port */
1665 #ifdef CONFIG_MSNDPIN_NONPNP
1666 # ifndef CONFIG_MSNDPIN_CFG
1667 # define CONFIG_MSNDPIN_CFG 0x250
1670 # ifdef CONFIG_MSNDPIN_CFG
1671 # undef CONFIG_MSNDPIN_CFG
1673 # define CONFIG_MSNDPIN_CFG -1
1675 static int cfg __initdata
= CONFIG_MSNDPIN_CFG
;
1676 /* If not a module, we don't need to bother with reset=1 */
1679 /* Extra Peripheral Configuration (Default: Disable) */
1680 #ifndef CONFIG_MSNDPIN_MPU_IO
1681 # define CONFIG_MSNDPIN_MPU_IO 0
1683 static int mpu_io __initdata
= CONFIG_MSNDPIN_MPU_IO
;
1685 #ifndef CONFIG_MSNDPIN_MPU_IRQ
1686 # define CONFIG_MSNDPIN_MPU_IRQ 0
1688 static int mpu_irq __initdata
= CONFIG_MSNDPIN_MPU_IRQ
;
1690 #ifndef CONFIG_MSNDPIN_IDE_IO0
1691 # define CONFIG_MSNDPIN_IDE_IO0 0
1693 static int ide_io0 __initdata
= CONFIG_MSNDPIN_IDE_IO0
;
1695 #ifndef CONFIG_MSNDPIN_IDE_IO1
1696 # define CONFIG_MSNDPIN_IDE_IO1 0
1698 static int ide_io1 __initdata
= CONFIG_MSNDPIN_IDE_IO1
;
1700 #ifndef CONFIG_MSNDPIN_IDE_IRQ
1701 # define CONFIG_MSNDPIN_IDE_IRQ 0
1703 static int ide_irq __initdata
= CONFIG_MSNDPIN_IDE_IRQ
;
1705 #ifndef CONFIG_MSNDPIN_JOYSTICK_IO
1706 # define CONFIG_MSNDPIN_JOYSTICK_IO 0
1708 static int joystick_io __initdata
= CONFIG_MSNDPIN_JOYSTICK_IO
;
1710 /* Have SPDIF (Digital) Daughterboard */
1711 #ifndef CONFIG_MSNDPIN_DIGITAL
1712 # define CONFIG_MSNDPIN_DIGITAL 0
1714 static bool digital __initdata
= CONFIG_MSNDPIN_DIGITAL
;
1716 #endif /* MSND_CLASSIC */
1718 #ifndef CONFIG_MSND_FIFOSIZE
1719 # define CONFIG_MSND_FIFOSIZE DEFFIFOSIZE
1721 static int fifosize __initdata
= CONFIG_MSND_FIFOSIZE
;
1723 #ifndef CONFIG_MSND_CALSIGNAL
1724 # define CONFIG_MSND_CALSIGNAL 0
1727 calibrate_signal __initdata
= CONFIG_MSND_CALSIGNAL
;
1730 module_param_hw (io
, int, ioport
, 0);
1731 module_param_hw (irq
, int, irq
, 0);
1732 module_param_hw (mem
, int, iomem
, 0);
1733 module_param (write_ndelay
, int, 0);
1734 module_param (fifosize
, int, 0);
1735 module_param (calibrate_signal
, int, 0);
1736 #ifndef MSND_CLASSIC
1737 module_param (digital
, bool, 0);
1738 module_param_hw (cfg
, int, ioport
, 0);
1739 module_param (reset
, int, 0);
1740 module_param_hw (mpu_io
, int, ioport
, 0);
1741 module_param_hw (mpu_irq
, int, irq
, 0);
1742 module_param_hw (ide_io0
, int, ioport
, 0);
1743 module_param_hw (ide_io1
, int, ioport
, 0);
1744 module_param_hw (ide_irq
, int, irq
, 0);
1745 module_param_hw (joystick_io
, int, ioport
, 0);
1748 static int __init
msnd_init(void)
1751 #ifndef MSND_CLASSIC
1752 static msnd_pinnacle_cfg_t pinnacle_devs
;
1753 #endif /* MSND_CLASSIC */
1755 printk(KERN_INFO LOGNAME
": Turtle Beach " LONGNAME
" Linux Driver Version "
1756 VERSION
", Copyright (C) 1998 Andrew Veliath\n");
1758 if (io
== -1 || irq
== -1 || mem
== -1)
1759 printk(KERN_WARNING LOGNAME
": io, irq and mem must be set\n");
1771 printk(KERN_ERR LOGNAME
": \"io\" - DSP I/O base must be set to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, or 0x3E0\n");
1779 printk(KERN_ERR LOGNAME
": \"io\" - DSP I/O base must within the range 0x100 to 0x3E0 and must be evenly divisible by 0x10\n");
1782 #endif /* MSND_CLASSIC */
1791 printk(KERN_ERR LOGNAME
": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n");
1802 printk(KERN_ERR LOGNAME
": \"mem\" - must be set to "
1803 "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or 0xe8000\n");
1809 case 5: dev
.irqid
= HPIRQ_5
; break;
1810 case 7: dev
.irqid
= HPIRQ_7
; break;
1811 case 9: dev
.irqid
= HPIRQ_9
; break;
1812 case 10: dev
.irqid
= HPIRQ_10
; break;
1813 case 11: dev
.irqid
= HPIRQ_11
; break;
1814 case 12: dev
.irqid
= HPIRQ_12
; break;
1818 case 0xb0000: dev
.memid
= HPMEM_B000
; break;
1819 case 0xc8000: dev
.memid
= HPMEM_C800
; break;
1820 case 0xd0000: dev
.memid
= HPMEM_D000
; break;
1821 case 0xd8000: dev
.memid
= HPMEM_D800
; break;
1822 case 0xe0000: dev
.memid
= HPMEM_E000
; break;
1823 case 0xe8000: dev
.memid
= HPMEM_E800
; break;
1827 printk(KERN_INFO LOGNAME
": Assuming PnP mode\n");
1828 } else if (cfg
!= 0x250 && cfg
!= 0x260 && cfg
!= 0x270) {
1829 printk(KERN_INFO LOGNAME
": Config port must be 0x250, 0x260 or 0x270 (or unspecified for PnP mode)\n");
1832 printk(KERN_INFO LOGNAME
": Non-PnP mode: configuring at port 0x%x\n", cfg
);
1835 pinnacle_devs
[0].io0
= io
;
1836 pinnacle_devs
[0].irq
= irq
;
1837 pinnacle_devs
[0].mem
= mem
;
1839 /* The following are Pinnacle specific */
1842 pinnacle_devs
[1].io0
= mpu_io
;
1843 pinnacle_devs
[1].irq
= mpu_irq
;
1846 pinnacle_devs
[2].io0
= ide_io0
;
1847 pinnacle_devs
[2].io1
= ide_io1
;
1848 pinnacle_devs
[2].irq
= ide_irq
;
1851 pinnacle_devs
[3].io0
= joystick_io
;
1853 if (!request_region(cfg
, 2, "Pinnacle/Fiji Config")) {
1854 printk(KERN_ERR LOGNAME
": Config port 0x%x conflict\n", cfg
);
1858 if (msnd_pinnacle_cfg_devices(cfg
, reset
, pinnacle_devs
)) {
1859 printk(KERN_ERR LOGNAME
": Device configuration error\n");
1860 release_region(cfg
, 2);
1863 release_region(cfg
, 2);
1865 #endif /* MSND_CLASSIC */
1870 if (fifosize
> 1024)
1873 set_default_audio_parameters();
1875 dev
.type
= msndClassic
;
1877 dev
.type
= msndPinnacle
;
1880 dev
.numio
= DSP_NUMIO
;
1882 dev
.base
= ioremap(mem
, 0x8000);
1883 dev
.fifosize
= fifosize
* 1024;
1884 dev
.calibrate_signal
= calibrate_signal
? 1 : 0;
1886 dev
.dspq_data_buff
= DSPQ_DATA_BUFF
;
1887 dev
.dspq_buff_size
= DSPQ_BUFF_SIZE
;
1888 if (write_ndelay
== -1)
1889 write_ndelay
= CONFIG_MSND_WRITE_NDELAY
;
1891 clear_bit(F_DISABLE_WRITE_NDELAY
, &dev
.flags
);
1893 set_bit(F_DISABLE_WRITE_NDELAY
, &dev
.flags
);
1894 #ifndef MSND_CLASSIC
1896 set_bit(F_HAVEDIGITAL
, &dev
.flags
);
1898 init_waitqueue_head(&dev
.writeblock
);
1899 init_waitqueue_head(&dev
.readblock
);
1900 init_waitqueue_head(&dev
.writeflush
);
1901 msnd_fifo_init(&dev
.DAPF
);
1902 msnd_fifo_init(&dev
.DARF
);
1903 spin_lock_init(&dev
.lock
);
1904 printk(KERN_INFO LOGNAME
": %u byte audio FIFOs (x2)\n", dev
.fifosize
);
1905 if ((err
= msnd_fifo_alloc(&dev
.DAPF
, dev
.fifosize
)) < 0) {
1906 printk(KERN_ERR LOGNAME
": Couldn't allocate write FIFO\n");
1910 if ((err
= msnd_fifo_alloc(&dev
.DARF
, dev
.fifosize
)) < 0) {
1911 printk(KERN_ERR LOGNAME
": Couldn't allocate read FIFO\n");
1912 msnd_fifo_free(&dev
.DAPF
);
1916 if ((err
= probe_multisound()) < 0) {
1917 printk(KERN_ERR LOGNAME
": Probe failed\n");
1918 msnd_fifo_free(&dev
.DAPF
);
1919 msnd_fifo_free(&dev
.DARF
);
1923 if ((err
= attach_multisound()) < 0) {
1924 printk(KERN_ERR LOGNAME
": Attach failed\n");
1925 msnd_fifo_free(&dev
.DAPF
);
1926 msnd_fifo_free(&dev
.DARF
);
1933 static void __exit
msdn_cleanup(void)
1935 unload_multisound();
1936 msnd_fifo_free(&dev
.DAPF
);
1937 msnd_fifo_free(&dev
.DARF
);
1940 module_init(msnd_init
);
1941 module_exit(msdn_cleanup
);