5 * A Linux driver for Turtle Beach WaveFront Series (Maui, Tropez, Tropez Plus)
7 * This driver supports the onboard wavetable synthesizer (an ICS2115),
8 * including patch, sample and program loading and unloading, conversion
9 * of GUS patches during loading, and full user-level access to all
10 * WaveFront commands. It tries to provide semi-intelligent patch and
11 * sample management as well.
13 * It also provides support for the ICS emulation of an MPU-401. Full
14 * support for the ICS emulation's "virtual MIDI mode" is provided in
17 * Support is also provided for the Tropez Plus' onboard FX processor,
18 * a Yamaha YSS225. Currently, code exists to configure the YSS225,
19 * and there is an interface allowing tweaking of any of its memory
20 * addresses. However, I have been unable to decipher the logical
21 * positioning of the configuration info for various effects, so for
22 * now, you just get the YSS225 in the same state as Turtle Beach's
23 * "SETUPSND.EXE" utility leaves it.
25 * The boards' DAC/ADC (a Crystal CS4232) is supported by cs4232.[co],
26 * This chip also controls the configuration of the card: the wavefront
27 * synth is logical unit 4.
32 * /dev/dsp - using cs4232+ad1848 modules, OSS compatible
33 * /dev/midiNN and /dev/midiNN+1 - using wf_midi code, OSS compatible
34 * /dev/synth00 - raw synth interface
36 **********************************************************************
38 * Copyright (C) by Paul Barton-Davis 1998
40 * Some portions of this file are taken from work that is
41 * copyright (C) by Hannu Savolainen 1993-1996
43 * Although the relevant code here is all new, the handling of
44 * sample/alias/multi- samples is entirely based on a driver by Matt
45 * Martin and Rutger Nijlunsing which demonstrated how to get things
46 * to work correctly. The GUS patch loading code has been almost
47 * unaltered by me, except to fit formatting and function names in the
48 * rest of the file. Many thanks to them.
50 * Appreciation and thanks to Hannu Savolainen for his early work on the Maui
51 * driver, and answering a few questions while this one was developed.
53 * Absolutely NO thanks to Turtle Beach/Voyetra and Yamaha for their
54 * complete lack of help in developing this driver, and in particular
55 * for their utter silence in response to questions about undocumented
56 * aspects of configuring a WaveFront soundcard, particularly the
59 * $Id: wavfront.c,v 0.7 1998/09/09 15:47:36 pbd Exp $
61 * This program is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
62 * Version 2 (June 1991). See the "COPYING" file distributed with this software
66 * 11-10-2000 Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
67 * Added some __init and __initdata to entries in yss225.c
70 #include <linux/module.h>
72 #include <linux/kernel.h>
73 #include <linux/init.h>
74 #include <linux/sched.h>
75 #include <linux/smp_lock.h>
76 #include <linux/ptrace.h>
77 #include <linux/fcntl.h>
78 #include <linux/syscalls.h>
79 #include <linux/ioport.h>
80 #include <linux/spinlock.h>
81 #include <linux/interrupt.h>
82 #include <linux/config.h>
84 #include <linux/delay.h>
86 #include "sound_config.h"
88 #include <linux/wavefront.h>
90 #define _MIDI_SYNTH_C_
91 #define MIDI_SYNTH_NAME "WaveFront MIDI"
92 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
93 #include "midi_synth.h"
95 /* Compile-time control of the extent to which OSS is supported.
97 I consider /dev/sequencer to be an anachronism, but given its
98 widespread usage by various Linux MIDI software, it seems worth
99 offering support to it if it's not too painful. Instead of using
100 /dev/sequencer, I recommend:
102 for synth programming and patch loading: /dev/synthNN
103 for kernel-synchronized MIDI sequencing: the ALSA sequencer
104 for direct MIDI control: /dev/midiNN
106 I have never tried static compilation into the kernel. The #if's
107 for this are really just notes to myself about what the code is
111 #define OSS_SUPPORT_SEQ 0x1 /* use of /dev/sequencer */
112 #define OSS_SUPPORT_STATIC_INSTALL 0x2 /* static compilation into kernel */
114 #define OSS_SUPPORT_LEVEL 0x1 /* just /dev/sequencer for now */
116 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
117 static int (*midi_load_patch
) (int devno
, int format
, const char __user
*addr
,
118 int offs
, int count
, int pmgr_flag
) = NULL
;
119 #endif /* OSS_SUPPORT_SEQ */
121 /* if WF_DEBUG not defined, no run-time debugging messages will
122 be available via the debug flag setting. Given the current
123 beta state of the driver, this will remain set until a future
131 /* Thank goodness for gcc's preprocessor ... */
133 #define DPRINT(cond, format, args...) \
134 if ((dev.debug & (cond)) == (cond)) { \
135 printk (KERN_DEBUG LOGNAME format, ## args); \
138 #define DPRINT(cond, format, args...)
141 #define LOGNAME "WaveFront: "
143 /* bitmasks for WaveFront status port value */
145 #define STAT_RINTR_ENABLED 0x01
146 #define STAT_CAN_READ 0x02
147 #define STAT_INTR_READ 0x04
148 #define STAT_WINTR_ENABLED 0x10
149 #define STAT_CAN_WRITE 0x20
150 #define STAT_INTR_WRITE 0x40
152 /*** Module-accessible parameters ***************************************/
154 int wf_raw
; /* we normally check for "raw state" to firmware
155 loading. if set, then during driver loading, the
156 state of the board is ignored, and we reset the
157 board and load the firmware anyway.
160 int fx_raw
= 1; /* if this is zero, we'll leave the FX processor in
161 whatever state it is when the driver is loaded.
162 The default is to download the microprogram and
163 associated coefficients to set it up for "default"
164 operation, whatever that means.
167 int debug_default
; /* you can set this to control debugging
168 during driver loading. it takes any combination
169 of the WF_DEBUG_* flags defined in
173 /* XXX this needs to be made firmware and hardware version dependent */
175 char *ospath
= "/etc/sound/wavefront.os"; /* where to find a processed
176 version of the WaveFront OS
179 int wait_polls
= 2000; /* This is a number of tries we poll the status register
180 before resorting to sleeping. WaveFront being an ISA
181 card each poll takes about 1.2us. So before going to
182 sleep we wait up to 2.4ms in a loop.
185 int sleep_length
= HZ
/100; /* This says how long we're going to sleep between polls.
186 10ms sounds reasonable for fast response.
189 int sleep_tries
= 50; /* Wait for status 0.5 seconds total. */
191 int reset_time
= 2; /* hundreths of a second we wait after a HW reset for
192 the expected interrupt.
195 int ramcheck_time
= 20; /* time in seconds to wait while ROM code
199 int osrun_time
= 10; /* time in seconds we wait for the OS to
203 MODULE_PARM(wf_raw
,"i");
204 MODULE_PARM(fx_raw
,"i");
205 MODULE_PARM(debug_default
,"i");
206 MODULE_PARM(wait_polls
,"i");
207 MODULE_PARM(sleep_length
,"i");
208 MODULE_PARM(sleep_tries
,"i");
209 MODULE_PARM(ospath
,"s");
210 MODULE_PARM(reset_time
,"i");
211 MODULE_PARM(ramcheck_time
,"i");
212 MODULE_PARM(osrun_time
,"i");
214 /***************************************************************************/
216 /* Note: because this module doesn't export any symbols, this really isn't
217 a global variable, even if it looks like one. I was quite confused by
218 this when I started writing this as a (newer) module -- pbd.
222 int devno
; /* device number from kernel */
223 int irq
; /* "you were one, one of the few ..." */
224 int base
; /* low i/o port address */
226 #define mpu_data_port base
227 #define mpu_command_port base + 1 /* write semantics */
228 #define mpu_status_port base + 1 /* read semantics */
229 #define data_port base + 2
230 #define status_port base + 3 /* read semantics */
231 #define control_port base + 3 /* write semantics */
232 #define block_port base + 4 /* 16 bit, writeonly */
233 #define last_block_port base + 6 /* 16 bit, writeonly */
235 /* FX ports. These are mapped through the ICS2115 to the YS225.
236 The ICS2115 takes care of flipping the relevant pins on the
237 YS225 so that access to each of these ports does the right
238 thing. Note: these are NOT documented by Turtle Beach.
241 #define fx_status base + 8
242 #define fx_op base + 8
243 #define fx_lcr base + 9
244 #define fx_dsp_addr base + 0xa
245 #define fx_dsp_page base + 0xb
246 #define fx_dsp_lsb base + 0xc
247 #define fx_dsp_msb base + 0xd
248 #define fx_mod_addr base + 0xe
249 #define fx_mod_data base + 0xf
251 volatile int irq_ok
; /* set by interrupt handler */
252 volatile int irq_cnt
; /* ditto */
253 int opened
; /* flag, holds open(2) mode */
254 char debug
; /* debugging flags */
255 int freemem
; /* installed RAM, in bytes */
257 int synth_dev
; /* devno for "raw" synth */
258 int mididev
; /* devno for internal MIDI */
259 int ext_mididev
; /* devno for external MIDI */
260 int fx_mididev
; /* devno for FX MIDI interface */
261 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
262 int oss_dev
; /* devno for OSS sequencer synth */
263 #endif /* OSS_SUPPORT_SEQ */
265 char fw_version
[2]; /* major = [0], minor = [1] */
266 char hw_version
[2]; /* major = [0], minor = [1] */
267 char israw
; /* needs Motorola microcode */
268 char has_fx
; /* has FX processor (Tropez+) */
269 char prog_status
[WF_MAX_PROGRAM
]; /* WF_SLOT_* */
270 char patch_status
[WF_MAX_PATCH
]; /* WF_SLOT_* */
271 char sample_status
[WF_MAX_SAMPLE
]; /* WF_ST_* | WF_SLOT_* */
272 int samples_used
; /* how many */
273 char interrupts_on
; /* h/w MPU interrupts enabled ? */
274 char rom_samples_rdonly
; /* can we write on ROM samples */
275 wait_queue_head_t interrupt_sleeper
;
278 static spinlock_t lock
=SPIN_LOCK_UNLOCKED
;
279 static int detect_wffx(void);
280 static int wffx_ioctl (wavefront_fx_info
*);
281 static int wffx_init (void);
283 static int wavefront_delete_sample (int sampnum
);
284 static int wavefront_find_free_sample (void);
288 extern int virtual_midi_enable (void);
289 extern int virtual_midi_disable (void);
290 extern int detect_wf_mpu (int, int);
291 extern int install_wf_mpu (void);
292 extern int uninstall_wf_mpu (void);
297 unsigned int read_cnt
;
298 unsigned int write_cnt
;
305 } wavefront_errors
[] = {
306 { 0x01, "Bad sample number" },
307 { 0x02, "Out of sample memory" },
308 { 0x03, "Bad patch number" },
309 { 0x04, "Error in number of voices" },
310 { 0x06, "Sample load already in progress" },
311 { 0x0B, "No sample load request pending" },
312 { 0x0E, "Bad MIDI channel number" },
313 { 0x10, "Download Record Error" },
320 static wavefront_command wavefront_commands
[] = {
321 { WFC_SET_SYNTHVOL
, "set synthesizer volume", 0, 1, NEEDS_ACK
},
322 { WFC_GET_SYNTHVOL
, "get synthesizer volume", 1, 0, 0},
323 { WFC_SET_NVOICES
, "set number of voices", 0, 1, NEEDS_ACK
},
324 { WFC_GET_NVOICES
, "get number of voices", 1, 0, 0 },
325 { WFC_SET_TUNING
, "set synthesizer tuning", 0, 2, NEEDS_ACK
},
326 { WFC_GET_TUNING
, "get synthesizer tuning", 2, 0, 0 },
327 { WFC_DISABLE_CHANNEL
, "disable synth channel", 0, 1, NEEDS_ACK
},
328 { WFC_ENABLE_CHANNEL
, "enable synth channel", 0, 1, NEEDS_ACK
},
329 { WFC_GET_CHANNEL_STATUS
, "get synth channel status", 3, 0, 0 },
330 { WFC_MISYNTH_OFF
, "disable midi-in to synth", 0, 0, NEEDS_ACK
},
331 { WFC_MISYNTH_ON
, "enable midi-in to synth", 0, 0, NEEDS_ACK
},
332 { WFC_VMIDI_ON
, "enable virtual midi mode", 0, 0, NEEDS_ACK
},
333 { WFC_VMIDI_OFF
, "disable virtual midi mode", 0, 0, NEEDS_ACK
},
334 { WFC_MIDI_STATUS
, "report midi status", 1, 0, 0 },
335 { WFC_FIRMWARE_VERSION
, "report firmware version", 2, 0, 0 },
336 { WFC_HARDWARE_VERSION
, "report hardware version", 2, 0, 0 },
337 { WFC_GET_NSAMPLES
, "report number of samples", 2, 0, 0 },
338 { WFC_INSTOUT_LEVELS
, "report instantaneous output levels", 7, 0, 0 },
339 { WFC_PEAKOUT_LEVELS
, "report peak output levels", 7, 0, 0 },
340 { WFC_DOWNLOAD_SAMPLE
, "download sample",
341 0, WF_SAMPLE_BYTES
, NEEDS_ACK
},
342 { WFC_DOWNLOAD_BLOCK
, "download block", 0, 0, NEEDS_ACK
},
343 { WFC_DOWNLOAD_SAMPLE_HEADER
, "download sample header",
344 0, WF_SAMPLE_HDR_BYTES
, NEEDS_ACK
},
345 { WFC_UPLOAD_SAMPLE_HEADER
, "upload sample header", 13, 2, 0 },
347 /* This command requires a variable number of bytes to be written.
348 There is a hack in wavefront_cmd() to support this. The actual
349 count is passed in as the read buffer ptr, cast appropriately.
353 { WFC_DOWNLOAD_MULTISAMPLE
, "download multisample", 0, 0, NEEDS_ACK
},
355 /* This one is a hack as well. We just read the first byte of the
356 response, don't fetch an ACK, and leave the rest to the
357 calling function. Ugly, ugly, ugly.
360 { WFC_UPLOAD_MULTISAMPLE
, "upload multisample", 2, 1, 0 },
361 { WFC_DOWNLOAD_SAMPLE_ALIAS
, "download sample alias",
362 0, WF_ALIAS_BYTES
, NEEDS_ACK
},
363 { WFC_UPLOAD_SAMPLE_ALIAS
, "upload sample alias", WF_ALIAS_BYTES
, 2, 0},
364 { WFC_DELETE_SAMPLE
, "delete sample", 0, 2, NEEDS_ACK
},
365 { WFC_IDENTIFY_SAMPLE_TYPE
, "identify sample type", 5, 2, 0 },
366 { WFC_UPLOAD_SAMPLE_PARAMS
, "upload sample parameters" },
367 { WFC_REPORT_FREE_MEMORY
, "report free memory", 4, 0, 0 },
368 { WFC_DOWNLOAD_PATCH
, "download patch", 0, 134, NEEDS_ACK
},
369 { WFC_UPLOAD_PATCH
, "upload patch", 132, 2, 0 },
370 { WFC_DOWNLOAD_PROGRAM
, "download program", 0, 33, NEEDS_ACK
},
371 { WFC_UPLOAD_PROGRAM
, "upload program", 32, 1, 0 },
372 { WFC_DOWNLOAD_EDRUM_PROGRAM
, "download enhanced drum program", 0, 9,
374 { WFC_UPLOAD_EDRUM_PROGRAM
, "upload enhanced drum program", 8, 1, 0},
375 { WFC_SET_EDRUM_CHANNEL
, "set enhanced drum program channel",
377 { WFC_DISABLE_DRUM_PROGRAM
, "disable drum program", 0, 1, NEEDS_ACK
},
378 { WFC_REPORT_CHANNEL_PROGRAMS
, "report channel program numbers",
380 { WFC_NOOP
, "the no-op command", 0, 0, NEEDS_ACK
},
385 wavefront_errorstr (int errnum
)
390 for (i
= 0; wavefront_errors
[i
].errstr
; i
++) {
391 if (wavefront_errors
[i
].errno
== errnum
) {
392 return wavefront_errors
[i
].errstr
;
396 return "Unknown WaveFront error";
399 static wavefront_command
*
400 wavefront_get_command (int cmd
)
405 for (i
= 0; wavefront_commands
[i
].cmd
!= 0; i
++) {
406 if (cmd
== wavefront_commands
[i
].cmd
) {
407 return &wavefront_commands
[i
];
411 return (wavefront_command
*) 0;
415 wavefront_status (void)
418 return inb (dev
.status_port
);
422 wavefront_wait (int mask
)
427 for (i
= 0; i
< wait_polls
; i
++)
428 if (wavefront_status() & mask
)
431 for (i
= 0; i
< sleep_tries
; i
++) {
433 if (wavefront_status() & mask
) {
434 set_current_state(TASK_RUNNING
);
438 set_current_state(TASK_INTERRUPTIBLE
);
439 schedule_timeout(sleep_length
);
440 if (signal_pending(current
))
444 set_current_state(TASK_RUNNING
);
449 wavefront_read (void)
452 if (wavefront_wait (STAT_CAN_READ
))
453 return inb (dev
.data_port
);
455 DPRINT (WF_DEBUG_DATA
, "read timeout.\n");
461 wavefront_write (unsigned char data
)
464 if (wavefront_wait (STAT_CAN_WRITE
)) {
465 outb (data
, dev
.data_port
);
469 DPRINT (WF_DEBUG_DATA
, "write timeout.\n");
475 wavefront_cmd (int cmd
, unsigned char *rbuf
, unsigned char *wbuf
)
481 wavefront_command
*wfcmd
;
483 if ((wfcmd
= wavefront_get_command (cmd
)) == (wavefront_command
*) 0) {
484 printk (KERN_WARNING LOGNAME
"command 0x%x not supported.\n",
489 /* Hack to handle the one variable-size write command. See
490 wavefront_send_multisample() for the other half of this
491 gross and ugly strategy.
494 if (cmd
== WFC_DOWNLOAD_MULTISAMPLE
) {
495 wfcmd
->write_cnt
= (unsigned int) rbuf
;
499 DPRINT (WF_DEBUG_CMD
, "0x%x [%s] (%d,%d,%d)\n",
500 cmd
, wfcmd
->action
, wfcmd
->read_cnt
,
501 wfcmd
->write_cnt
, wfcmd
->need_ack
);
503 if (wavefront_write (cmd
)) {
504 DPRINT ((WF_DEBUG_IO
|WF_DEBUG_CMD
), "cannot request "
510 if (wfcmd
->write_cnt
> 0) {
511 DPRINT (WF_DEBUG_DATA
, "writing %d bytes "
513 wfcmd
->write_cnt
, cmd
);
515 for (i
= 0; i
< wfcmd
->write_cnt
; i
++) {
516 if (wavefront_write (wbuf
[i
])) {
517 DPRINT (WF_DEBUG_IO
, "bad write for byte "
518 "%d of 0x%x [%s].\n",
519 i
, cmd
, wfcmd
->action
);
523 DPRINT (WF_DEBUG_DATA
, "write[%d] = 0x%x\n",
528 if (wfcmd
->read_cnt
> 0) {
529 DPRINT (WF_DEBUG_DATA
, "reading %d ints "
531 wfcmd
->read_cnt
, cmd
);
533 for (i
= 0; i
< wfcmd
->read_cnt
; i
++) {
535 if ((c
= wavefront_read()) == -1) {
536 DPRINT (WF_DEBUG_IO
, "bad read for byte "
537 "%d of 0x%x [%s].\n",
538 i
, cmd
, wfcmd
->action
);
542 /* Now handle errors. Lots of special cases here */
545 if ((c
= wavefront_read ()) == -1) {
546 DPRINT (WF_DEBUG_IO
, "bad read for "
555 /* Can you believe this madness ? */
558 wfcmd
->cmd
== WFC_IDENTIFY_SAMPLE_TYPE
) {
559 rbuf
[0] = WF_ST_EMPTY
;
563 wfcmd
->cmd
== WFC_UPLOAD_PATCH
) {
568 wfcmd
->cmd
== WFC_UPLOAD_PROGRAM
) {
574 DPRINT (WF_DEBUG_IO
, "error %d (%s) "
580 wavefront_errorstr (c
),
591 DPRINT (WF_DEBUG_DATA
, "read[%d] = 0x%x\n",i
, rbuf
[i
]);
595 if ((wfcmd
->read_cnt
== 0 && wfcmd
->write_cnt
== 0) || wfcmd
->need_ack
) {
597 DPRINT (WF_DEBUG_CMD
, "reading ACK for 0x%x\n", cmd
);
599 /* Some commands need an ACK, but return zero instead
600 of the standard value.
603 if ((ack
= wavefront_read()) == 0) {
609 DPRINT (WF_DEBUG_IO
, "cannot read ack for "
615 int err
= -1; /* something unknown */
617 if (ack
== 0xff) { /* explicit error */
619 if ((err
= wavefront_read ()) == -1) {
620 DPRINT (WF_DEBUG_DATA
,
627 DPRINT (WF_DEBUG_IO
, "0x%x [%s] "
628 "failed (0x%x, 0x%x, %s)\n",
629 cmd
, wfcmd
->action
, ack
, err
,
630 wavefront_errorstr (err
));
636 DPRINT (WF_DEBUG_DATA
, "ack received "
641 DPRINT (WF_DEBUG_CMD
, "0x%x [%s] does not need "
643 cmd
, wfcmd
->action
, wfcmd
->read_cnt
,
644 wfcmd
->write_cnt
, wfcmd
->need_ack
);
651 /***********************************************************************
652 WaveFront: data munging
654 Things here are weird. All data written to the board cannot
655 have its most significant bit set. Any data item with values
656 potentially > 0x7F (127) must be split across multiple bytes.
658 Sometimes, we need to munge numeric values that are represented on
659 the x86 side as 8-32 bit values. Sometimes, we need to munge data
660 that is represented on the x86 side as an array of bytes. The most
661 efficient approach to handling both cases seems to be to use 2
662 different functions for munging and 2 for de-munging. This avoids
663 weird casting and worrying about bit-level offsets.
665 **********************************************************************/
669 munge_int32 (unsigned int src
,
671 unsigned int dst_size
)
675 for (i
= 0;i
< dst_size
; i
++) {
676 *dst
= src
& 0x7F; /* Mask high bit of LSB */
677 src
= src
>> 7; /* Rotate Right 7 bits */
678 /* Note: we leave the upper bits in place */
686 demunge_int32 (unsigned char* src
, int src_size
)
692 for (i
= src_size
- 1; i
>= 0; i
--) {
693 outval
=(outval
<<7)+src
[i
];
701 munge_buf (unsigned char *src
, unsigned char *dst
, unsigned int dst_size
)
705 unsigned int last
= dst_size
/ 2;
707 for (i
= 0; i
< last
; i
++) {
708 *dst
++ = src
[i
] & 0x7f;
709 *dst
++ = src
[i
] >> 7;
716 demunge_buf (unsigned char *src
, unsigned char *dst
, unsigned int src_bytes
)
720 unsigned char *end
= src
+ src_bytes
;
722 end
= src
+ src_bytes
;
724 /* NOTE: src and dst *CAN* point to the same address */
726 for (i
= 0; src
!= end
; i
++) {
728 dst
[i
] |= (*src
++)<<7;
734 /***********************************************************************
735 WaveFront: sample, patch and program management.
736 ***********************************************************************/
739 wavefront_delete_sample (int sample_num
)
742 unsigned char wbuf
[2];
745 wbuf
[0] = sample_num
& 0x7f;
746 wbuf
[1] = sample_num
>> 7;
748 if ((x
= wavefront_cmd (WFC_DELETE_SAMPLE
, NULL
, wbuf
)) == 0) {
749 dev
.sample_status
[sample_num
] = WF_ST_EMPTY
;
756 wavefront_get_sample_status (int assume_rom
)
760 unsigned char rbuf
[32], wbuf
[32];
761 unsigned int sc_real
, sc_alias
, sc_multi
;
763 /* check sample status */
765 if (wavefront_cmd (WFC_GET_NSAMPLES
, rbuf
, wbuf
)) {
766 printk (KERN_WARNING LOGNAME
"cannot request sample count.\n");
770 sc_real
= sc_alias
= sc_multi
= dev
.samples_used
= 0;
772 for (i
= 0; i
< WF_MAX_SAMPLE
; i
++) {
777 if (wavefront_cmd (WFC_IDENTIFY_SAMPLE_TYPE
, rbuf
, wbuf
)) {
778 printk (KERN_WARNING LOGNAME
779 "cannot identify sample "
780 "type of slot %d\n", i
);
781 dev
.sample_status
[i
] = WF_ST_EMPTY
;
785 dev
.sample_status
[i
] = (WF_SLOT_FILLED
|rbuf
[0]);
788 dev
.sample_status
[i
] |= WF_SLOT_ROM
;
791 switch (rbuf
[0] & WF_ST_MASK
) {
795 case WF_ST_MULTISAMPLE
:
805 printk (KERN_WARNING LOGNAME
"unknown sample type for "
810 if (rbuf
[0] != WF_ST_EMPTY
) {
815 printk (KERN_INFO LOGNAME
816 "%d samples used (%d real, %d aliases, %d multi), "
817 "%d empty\n", dev
.samples_used
, sc_real
, sc_alias
, sc_multi
,
818 WF_MAX_SAMPLE
- dev
.samples_used
);
826 wavefront_get_patch_status (void)
829 unsigned char patchbuf
[WF_PATCH_BYTES
];
830 unsigned char patchnum
[2];
834 for (i
= 0; i
< WF_MAX_PATCH
; i
++) {
835 patchnum
[0] = i
& 0x7f;
836 patchnum
[1] = i
>> 7;
838 if ((x
= wavefront_cmd (WFC_UPLOAD_PATCH
, patchbuf
,
841 dev
.patch_status
[i
] |= WF_SLOT_FILLED
;
842 p
= (wavefront_patch
*) patchbuf
;
844 [p
->sample_number
|(p
->sample_msb
<<7)] |=
847 } else if (x
== 3) { /* Bad patch number */
848 dev
.patch_status
[i
] = 0;
850 printk (KERN_ERR LOGNAME
"upload patch "
852 dev
.patch_status
[i
] = 0;
857 /* program status has already filled in slot_used bits */
859 for (i
= 0, cnt
= 0, cnt2
= 0; i
< WF_MAX_PATCH
; i
++) {
860 if (dev
.patch_status
[i
] & WF_SLOT_FILLED
) {
863 if (dev
.patch_status
[i
] & WF_SLOT_USED
) {
868 printk (KERN_INFO LOGNAME
869 "%d patch slots filled, %d in use\n", cnt
, cnt2
);
875 wavefront_get_program_status (void)
878 unsigned char progbuf
[WF_PROGRAM_BYTES
];
879 wavefront_program prog
;
880 unsigned char prognum
;
883 for (i
= 0; i
< WF_MAX_PROGRAM
; i
++) {
886 if ((x
= wavefront_cmd (WFC_UPLOAD_PROGRAM
, progbuf
,
889 dev
.prog_status
[i
] |= WF_SLOT_USED
;
891 demunge_buf (progbuf
, (unsigned char *) &prog
,
894 for (l
= 0; l
< WF_NUM_LAYERS
; l
++) {
895 if (prog
.layer
[l
].mute
) {
897 [prog
.layer
[l
].patch_number
] |=
901 } else if (x
== 1) { /* Bad program number */
902 dev
.prog_status
[i
] = 0;
904 printk (KERN_ERR LOGNAME
"upload program "
906 dev
.prog_status
[i
] = 0;
910 for (i
= 0, cnt
= 0; i
< WF_MAX_PROGRAM
; i
++) {
911 if (dev
.prog_status
[i
]) {
916 printk (KERN_INFO LOGNAME
"%d programs slots in use\n", cnt
);
922 wavefront_send_patch (wavefront_patch_info
*header
)
925 unsigned char buf
[WF_PATCH_BYTES
+2];
928 DPRINT (WF_DEBUG_LOAD_PATCH
, "downloading patch %d\n",
931 dev
.patch_status
[header
->number
] |= WF_SLOT_FILLED
;
934 bptr
= munge_int32 (header
->number
, buf
, 2);
935 munge_buf ((unsigned char *)&header
->hdr
.p
, bptr
, WF_PATCH_BYTES
);
937 if (wavefront_cmd (WFC_DOWNLOAD_PATCH
, NULL
, buf
)) {
938 printk (KERN_ERR LOGNAME
"download patch failed\n");
946 wavefront_send_program (wavefront_patch_info
*header
)
949 unsigned char buf
[WF_PROGRAM_BYTES
+1];
952 DPRINT (WF_DEBUG_LOAD_PATCH
, "downloading program %d\n",
955 dev
.prog_status
[header
->number
] = WF_SLOT_USED
;
957 /* XXX need to zero existing SLOT_USED bit for program_status[i]
958 where `i' is the program that's being (potentially) overwritten.
961 for (i
= 0; i
< WF_NUM_LAYERS
; i
++) {
962 if (header
->hdr
.pr
.layer
[i
].mute
) {
963 dev
.patch_status
[header
->hdr
.pr
.layer
[i
].patch_number
] |=
966 /* XXX need to mark SLOT_USED for sample used by
967 patch_number, but this means we have to load it. Ick.
972 buf
[0] = header
->number
;
973 munge_buf ((unsigned char *)&header
->hdr
.pr
, &buf
[1], WF_PROGRAM_BYTES
);
975 if (wavefront_cmd (WFC_DOWNLOAD_PROGRAM
, NULL
, buf
)) {
976 printk (KERN_WARNING LOGNAME
"download patch failed\n");
984 wavefront_freemem (void)
989 if (wavefront_cmd (WFC_REPORT_FREE_MEMORY
, rbuf
, NULL
)) {
990 printk (KERN_WARNING LOGNAME
"can't get memory stats.\n");
993 return demunge_int32 (rbuf
, 4);
998 wavefront_send_sample (wavefront_patch_info
*header
,
999 UINT16 __user
*dataptr
,
1000 int data_is_unsigned
)
1003 /* samples are downloaded via a 16-bit wide i/o port
1004 (you could think of it as 2 adjacent 8-bit wide ports
1005 but its less efficient that way). therefore, all
1006 the blocksizes and so forth listed in the documentation,
1007 and used conventionally to refer to sample sizes,
1008 which are given in 8-bit units (bytes), need to be
1012 UINT16 sample_short
;
1014 UINT16 __user
*data_end
= NULL
;
1016 const int max_blksize
= 4096/2;
1017 unsigned int written
;
1018 unsigned int blocksize
;
1021 unsigned char sample_hdr
[WF_SAMPLE_HDR_BYTES
];
1022 unsigned char *shptr
;
1024 int initial_skip
= 0;
1026 DPRINT (WF_DEBUG_LOAD_PATCH
, "sample %sdownload for slot %d, "
1027 "type %d, %d bytes from %p\n",
1028 header
->size
? "" : "header ",
1029 header
->number
, header
->subkey
,
1033 if (header
->number
== WAVEFRONT_FIND_FREE_SAMPLE_SLOT
) {
1036 if ((x
= wavefront_find_free_sample ()) < 0) {
1039 printk (KERN_DEBUG LOGNAME
"unspecified sample => %d\n", x
);
1045 /* XXX it's a debatable point whether or not RDONLY semantics
1046 on the ROM samples should cover just the sample data or
1047 the sample header. For now, it only covers the sample data,
1048 so anyone is free at all times to rewrite sample headers.
1050 My reason for this is that we have the sample headers
1051 available in the WFB file for General MIDI, and so these
1052 can always be reset if needed. The sample data, however,
1053 cannot be recovered without a complete reset and firmware
1054 reload of the ICS2115, which is a very expensive operation.
1056 So, doing things this way allows us to honor the notion of
1057 "RESETSAMPLES" reasonably cheaply. Note however, that this
1058 is done purely at user level: there is no WFB parser in
1059 this driver, and so a complete reset (back to General MIDI,
1060 or theoretically some other configuration) is the
1061 responsibility of the user level library.
1063 To try to do this in the kernel would be a little
1064 crazy: we'd need 158K of kernel space just to hold
1065 a copy of the patch/program/sample header data.
1068 if (dev
.rom_samples_rdonly
) {
1069 if (dev
.sample_status
[header
->number
] & WF_SLOT_ROM
) {
1070 printk (KERN_ERR LOGNAME
"sample slot %d "
1071 "write protected\n",
1077 wavefront_delete_sample (header
->number
);
1081 dev
.freemem
= wavefront_freemem ();
1083 if (dev
.freemem
< header
->size
) {
1084 printk (KERN_ERR LOGNAME
1085 "insufficient memory to "
1086 "load %d byte sample.\n",
1093 skip
= WF_GET_CHANNEL(&header
->hdr
.s
);
1095 if (skip
> 0 && header
->hdr
.s
.SampleResolution
!= LINEAR_16BIT
) {
1096 printk (KERN_ERR LOGNAME
"channel selection only "
1097 "possible on 16-bit samples");
1132 DPRINT (WF_DEBUG_LOAD_PATCH
, "channel selection: %d => "
1133 "initial skip = %d, skip = %d\n",
1134 WF_GET_CHANNEL (&header
->hdr
.s
),
1135 initial_skip
, skip
);
1137 /* Be safe, and zero the "Unused" bits ... */
1139 WF_SET_CHANNEL(&header
->hdr
.s
, 0);
1141 /* adjust size for 16 bit samples by dividing by two. We always
1142 send 16 bits per write, even for 8 bit samples, so the length
1143 is always half the size of the sample data in bytes.
1146 length
= header
->size
/ 2;
1148 /* the data we're sent has not been munged, and in fact, the
1149 header we have to send isn't just a munged copy either.
1150 so, build the sample header right here.
1153 shptr
= &sample_hdr
[0];
1155 shptr
= munge_int32 (header
->number
, shptr
, 2);
1158 shptr
= munge_int32 (length
, shptr
, 4);
1161 /* Yes, a 4 byte result doesn't contain all of the offset bits,
1162 but the offset only uses 24 bits.
1165 shptr
= munge_int32 (*((UINT32
*) &header
->hdr
.s
.sampleStartOffset
),
1167 shptr
= munge_int32 (*((UINT32
*) &header
->hdr
.s
.loopStartOffset
),
1169 shptr
= munge_int32 (*((UINT32
*) &header
->hdr
.s
.loopEndOffset
),
1171 shptr
= munge_int32 (*((UINT32
*) &header
->hdr
.s
.sampleEndOffset
),
1174 /* This one is truly weird. What kind of weirdo decided that in
1175 a system dominated by 16 and 32 bit integers, they would use
1179 shptr
= munge_int32 (header
->hdr
.s
.FrequencyBias
, shptr
, 3);
1181 /* Why is this nybblified, when the MSB is *always* zero ?
1182 Anyway, we can't take address of bitfield, so make a
1183 good-faith guess at where it starts.
1186 shptr
= munge_int32 (*(&header
->hdr
.s
.FrequencyBias
+1),
1189 if (wavefront_cmd (header
->size
?
1190 WFC_DOWNLOAD_SAMPLE
: WFC_DOWNLOAD_SAMPLE_HEADER
,
1191 NULL
, sample_hdr
)) {
1192 printk (KERN_WARNING LOGNAME
"sample %sdownload refused.\n",
1193 header
->size
? "" : "header ");
1197 if (header
->size
== 0) {
1198 goto sent
; /* Sorry. Just had to have one somewhere */
1201 data_end
= dataptr
+ length
;
1203 /* Do any initial skip over an unused channel's data */
1205 dataptr
+= initial_skip
;
1207 for (written
= 0, blocknum
= 0;
1208 written
< length
; written
+= max_blksize
, blocknum
++) {
1210 if ((length
- written
) > max_blksize
) {
1211 blocksize
= max_blksize
;
1213 /* round to nearest 16-byte value */
1214 blocksize
= ((length
-written
+7)&~0x7);
1217 if (wavefront_cmd (WFC_DOWNLOAD_BLOCK
, NULL
, NULL
)) {
1218 printk (KERN_WARNING LOGNAME
"download block "
1219 "request refused.\n");
1223 for (i
= 0; i
< blocksize
; i
++) {
1225 if (dataptr
< data_end
) {
1227 __get_user (sample_short
, dataptr
);
1230 if (data_is_unsigned
) { /* GUS ? */
1232 if (WF_SAMPLE_IS_8BIT(&header
->hdr
.s
)) {
1240 &sample_short
)[0] += 0x7f;
1242 &sample_short
)[1] += 0x7f;
1251 sample_short
+= 0x7fff;
1257 /* In padding section of final block:
1259 Don't fetch unsupplied data from
1260 user space, just continue with
1261 whatever the final value was.
1265 if (i
< blocksize
- 1) {
1266 outw (sample_short
, dev
.block_port
);
1268 outw (sample_short
, dev
.last_block_port
);
1272 /* Get "DMA page acknowledge", even though its really
1273 nothing to do with DMA at all.
1276 if ((dma_ack
= wavefront_read ()) != WF_DMA_ACK
) {
1277 if (dma_ack
== -1) {
1278 printk (KERN_ERR LOGNAME
"upload sample "
1279 "DMA ack timeout\n");
1282 printk (KERN_ERR LOGNAME
"upload sample "
1283 "DMA ack error 0x%x\n",
1290 dev
.sample_status
[header
->number
] = (WF_SLOT_FILLED
|WF_ST_SAMPLE
);
1292 /* Note, label is here because sending the sample header shouldn't
1293 alter the sample_status info at all.
1301 wavefront_send_alias (wavefront_patch_info
*header
)
1304 unsigned char alias_hdr
[WF_ALIAS_BYTES
];
1306 DPRINT (WF_DEBUG_LOAD_PATCH
, "download alias, %d is "
1309 header
->hdr
.a
.OriginalSample
);
1311 munge_int32 (header
->number
, &alias_hdr
[0], 2);
1312 munge_int32 (header
->hdr
.a
.OriginalSample
, &alias_hdr
[2], 2);
1313 munge_int32 (*((unsigned int *)&header
->hdr
.a
.sampleStartOffset
),
1315 munge_int32 (*((unsigned int *)&header
->hdr
.a
.loopStartOffset
),
1317 munge_int32 (*((unsigned int *)&header
->hdr
.a
.loopEndOffset
),
1319 munge_int32 (*((unsigned int *)&header
->hdr
.a
.sampleEndOffset
),
1321 munge_int32 (header
->hdr
.a
.FrequencyBias
, &alias_hdr
[20], 3);
1322 munge_int32 (*(&header
->hdr
.a
.FrequencyBias
+1), &alias_hdr
[23], 2);
1324 if (wavefront_cmd (WFC_DOWNLOAD_SAMPLE_ALIAS
, NULL
, alias_hdr
)) {
1325 printk (KERN_ERR LOGNAME
"download alias failed.\n");
1329 dev
.sample_status
[header
->number
] = (WF_SLOT_FILLED
|WF_ST_ALIAS
);
1335 wavefront_send_multisample (wavefront_patch_info
*header
)
1339 unsigned char msample_hdr
[WF_MSAMPLE_BYTES
];
1341 munge_int32 (header
->number
, &msample_hdr
[0], 2);
1343 /* You'll recall at this point that the "number of samples" value
1344 in a wavefront_multisample struct is actually the log2 of the
1345 real number of samples.
1348 num_samples
= (1<<(header
->hdr
.ms
.NumberOfSamples
&7));
1349 msample_hdr
[2] = (unsigned char) header
->hdr
.ms
.NumberOfSamples
;
1351 DPRINT (WF_DEBUG_LOAD_PATCH
, "multi %d with %d=%d samples\n",
1353 header
->hdr
.ms
.NumberOfSamples
,
1356 for (i
= 0; i
< num_samples
; i
++) {
1357 DPRINT(WF_DEBUG_LOAD_PATCH
|WF_DEBUG_DATA
, "sample[%d] = %d\n",
1358 i
, header
->hdr
.ms
.SampleNumber
[i
]);
1359 munge_int32 (header
->hdr
.ms
.SampleNumber
[i
],
1360 &msample_hdr
[3+(i
*2)], 2);
1363 /* Need a hack here to pass in the number of bytes
1364 to be written to the synth. This is ugly, and perhaps
1365 one day, I'll fix it.
1368 if (wavefront_cmd (WFC_DOWNLOAD_MULTISAMPLE
,
1369 (unsigned char *) ((num_samples
*2)+3),
1371 printk (KERN_ERR LOGNAME
"download of multisample failed.\n");
1375 dev
.sample_status
[header
->number
] = (WF_SLOT_FILLED
|WF_ST_MULTISAMPLE
);
1381 wavefront_fetch_multisample (wavefront_patch_info
*header
)
1384 unsigned char log_ns
[1];
1385 unsigned char number
[2];
1388 munge_int32 (header
->number
, number
, 2);
1390 if (wavefront_cmd (WFC_UPLOAD_MULTISAMPLE
, log_ns
, number
)) {
1391 printk (KERN_ERR LOGNAME
"upload multisample failed.\n");
1395 DPRINT (WF_DEBUG_DATA
, "msample %d has %d samples\n",
1396 header
->number
, log_ns
[0]);
1398 header
->hdr
.ms
.NumberOfSamples
= log_ns
[0];
1400 /* get the number of samples ... */
1402 num_samples
= (1 << log_ns
[0]);
1404 for (i
= 0; i
< num_samples
; i
++) {
1407 if ((d
[0] = wavefront_read ()) == -1) {
1408 printk (KERN_ERR LOGNAME
"upload multisample failed "
1409 "during sample loop.\n");
1413 if ((d
[1] = wavefront_read ()) == -1) {
1414 printk (KERN_ERR LOGNAME
"upload multisample failed "
1415 "during sample loop.\n");
1419 header
->hdr
.ms
.SampleNumber
[i
] =
1420 demunge_int32 ((unsigned char *) d
, 2);
1422 DPRINT (WF_DEBUG_DATA
, "msample sample[%d] = %d\n",
1423 i
, header
->hdr
.ms
.SampleNumber
[i
]);
1431 wavefront_send_drum (wavefront_patch_info
*header
)
1434 unsigned char drumbuf
[WF_DRUM_BYTES
];
1435 wavefront_drum
*drum
= &header
->hdr
.d
;
1438 DPRINT (WF_DEBUG_LOAD_PATCH
, "downloading edrum for MIDI "
1439 "note %d, patch = %d\n",
1440 header
->number
, drum
->PatchNumber
);
1442 drumbuf
[0] = header
->number
& 0x7f;
1444 for (i
= 0; i
< 4; i
++) {
1445 munge_int32 (((unsigned char *)drum
)[i
], &drumbuf
[1+(i
*2)], 2);
1448 if (wavefront_cmd (WFC_DOWNLOAD_EDRUM_PROGRAM
, NULL
, drumbuf
)) {
1449 printk (KERN_ERR LOGNAME
"download drum failed.\n");
1457 wavefront_find_free_sample (void)
1462 for (i
= 0; i
< WF_MAX_SAMPLE
; i
++) {
1463 if (!(dev
.sample_status
[i
] & WF_SLOT_FILLED
)) {
1467 printk (KERN_WARNING LOGNAME
"no free sample slots!\n");
1472 wavefront_find_free_patch (void)
1477 for (i
= 0; i
< WF_MAX_PATCH
; i
++) {
1478 if (!(dev
.patch_status
[i
] & WF_SLOT_FILLED
)) {
1482 printk (KERN_WARNING LOGNAME
"no free patch slots!\n");
1490 int tbl
[]={0, 0, 2048, 3246, 4096, 4755, 5294, 5749, 6143,
1491 6492, 6803, 7084, 7342, 7578, 7797, 8001, 8192,
1492 8371, 8540, 8699, 8851, 8995, 9132, 9264, 9390,
1493 9510, 9626, 9738, 9845, 9949, 10049, 10146};
1496 /* Returns 2048*log2(n) */
1498 /* FIXME: this is like doing integer math
1499 on quantum particles (RuN) */
1515 wavefront_load_gus_patch (int devno
, int format
, const char __user
*addr
,
1516 int offs
, int count
, int pmgr_flag
)
1518 struct patch_info guspatch
;
1519 wavefront_patch_info samp
, pat
, prog
;
1520 wavefront_patch
*patp
;
1521 wavefront_sample
*sampp
;
1522 wavefront_program
*progp
;
1527 /* Copy in the header of the GUS patch */
1529 sizeof_patch
= (long) &guspatch
.data
[0] - (long) &guspatch
;
1530 if (copy_from_user(&((char *) &guspatch
)[offs
],
1531 &(addr
)[offs
], sizeof_patch
- offs
))
1534 if ((i
= wavefront_find_free_patch ()) == -1) {
1538 pat
.subkey
= WF_ST_PATCH
;
1541 if ((i
= wavefront_find_free_sample ()) == -1) {
1545 samp
.subkey
= WF_ST_SAMPLE
;
1546 samp
.size
= guspatch
.len
;
1547 sampp
= &samp
.hdr
.s
;
1549 prog
.number
= guspatch
.instr_no
;
1550 progp
= &prog
.hdr
.pr
;
1552 /* Setup the patch structure */
1554 patp
->amplitude_bias
=guspatch
.volume
;
1556 patp
->sample_number
= samp
.number
& 0xff;
1557 patp
->sample_msb
= samp
.number
>>8;
1558 patp
->pitch_bend
= /*12*/ 0;
1561 patp
->nohold
=(guspatch
.mode
& WAVE_SUSTAIN_ON
) ? 0:1;
1562 patp
->frequency_bias
=0;
1567 patp
->fm_src1
=WF_MOD_MOD_WHEEL
;
1568 patp
->am_src
=WF_MOD_PRESSURE
;
1569 patp
->am_amount
=127;
1570 patp
->fc1_mod_amount
=0;
1571 patp
->fc2_mod_amount
=0;
1574 patp
->envelope1
.attack_level
=127;
1575 patp
->envelope1
.decay1_level
=127;
1576 patp
->envelope1
.decay2_level
=127;
1577 patp
->envelope1
.sustain_level
=127;
1578 patp
->envelope1
.release_level
=0;
1579 patp
->envelope2
.attack_velocity
=127;
1580 patp
->envelope2
.attack_level
=127;
1581 patp
->envelope2
.decay1_level
=127;
1582 patp
->envelope2
.decay2_level
=127;
1583 patp
->envelope2
.sustain_level
=127;
1584 patp
->envelope2
.release_level
=0;
1585 patp
->envelope2
.attack_velocity
=127;
1588 /* Program for this patch */
1590 progp
->layer
[0].patch_number
= pat
.number
; /* XXX is this right ? */
1591 progp
->layer
[0].mute
=1;
1592 progp
->layer
[0].pan_or_mod
=1;
1593 progp
->layer
[0].pan
=7;
1594 progp
->layer
[0].mix_level
=127 /* guspatch.volume */;
1595 progp
->layer
[0].split_type
=0;
1596 progp
->layer
[0].split_point
=0;
1597 progp
->layer
[0].play_below
=0;
1599 for (i
= 1; i
< 4; i
++) {
1600 progp
->layer
[i
].mute
=0;
1605 sampp
->SampleResolution
=((~guspatch
.mode
& WAVE_16_BITS
)<<1);
1608 note_to_freq (base_note
) < guspatch
.base_note
;
1611 if ((guspatch
.base_note
-note_to_freq(base_note
))
1612 >(note_to_freq(base_note
)-guspatch
.base_note
))
1615 printk(KERN_DEBUG
"ref freq=%d,base note=%d\n",
1619 sampp
->FrequencyBias
= (29550 - log2_2048(guspatch
.base_freq
)
1621 printk(KERN_DEBUG
"Freq Bias is %d\n", sampp
->FrequencyBias
);
1622 sampp
->Loop
=(guspatch
.mode
& WAVE_LOOPING
) ? 1:0;
1623 sampp
->sampleStartOffset
.Fraction
=0;
1624 sampp
->sampleStartOffset
.Integer
=0;
1625 sampp
->loopStartOffset
.Fraction
=0;
1626 sampp
->loopStartOffset
.Integer
=guspatch
.loop_start
1627 >>((guspatch
.mode
&WAVE_16_BITS
) ? 1:0);
1628 sampp
->loopEndOffset
.Fraction
=0;
1629 sampp
->loopEndOffset
.Integer
=guspatch
.loop_end
1630 >>((guspatch
.mode
&WAVE_16_BITS
) ? 1:0);
1631 sampp
->sampleEndOffset
.Fraction
=0;
1632 sampp
->sampleEndOffset
.Integer
=guspatch
.len
>> (guspatch
.mode
&1);
1633 sampp
->Bidirectional
=(guspatch
.mode
&WAVE_BIDIR_LOOP
) ? 1:0;
1634 sampp
->Reverse
=(guspatch
.mode
&WAVE_LOOP_BACK
) ? 1:0;
1636 /* Now ship it down */
1638 wavefront_send_sample (&samp
,
1639 (unsigned short __user
*) &(addr
)[sizeof_patch
],
1640 (guspatch
.mode
& WAVE_UNSIGNED
) ? 1:0);
1641 wavefront_send_patch (&pat
);
1642 wavefront_send_program (&prog
);
1644 /* Now pan as best we can ... use the slave/internal MIDI device
1645 number if it exists (since it talks to the WaveFront), or the
1649 if (dev
.mididev
> 0) {
1650 midi_synth_controller (dev
.mididev
, guspatch
.instr_no
, 10,
1651 ((guspatch
.panning
<< 4) > 127) ?
1652 127 : (guspatch
.panning
<< 4));
1659 wavefront_load_patch (const char __user
*addr
)
1663 wavefront_patch_info header
;
1665 if (copy_from_user (&header
, addr
, sizeof(wavefront_patch_info
) -
1666 sizeof(wavefront_any
))) {
1667 printk (KERN_WARNING LOGNAME
"bad address for load patch.\n");
1671 DPRINT (WF_DEBUG_LOAD_PATCH
, "download "
1673 "Sample number: %d "
1674 "Sample size: %d\n",
1679 switch (header
.subkey
) {
1680 case WF_ST_SAMPLE
: /* sample or sample_header, based on patch->size */
1682 if (copy_from_user((unsigned char *) &header
.hdr
.s
,
1683 (unsigned char __user
*) header
.hdrptr
,
1684 sizeof (wavefront_sample
)))
1687 return wavefront_send_sample (&header
, header
.dataptr
, 0);
1689 case WF_ST_MULTISAMPLE
:
1691 if (copy_from_user(&header
.hdr
.s
, header
.hdrptr
,
1692 sizeof(wavefront_multisample
)))
1695 return wavefront_send_multisample (&header
);
1700 if (copy_from_user(&header
.hdr
.a
, header
.hdrptr
,
1701 sizeof (wavefront_alias
)))
1704 return wavefront_send_alias (&header
);
1707 if (copy_from_user(&header
.hdr
.d
, header
.hdrptr
,
1708 sizeof (wavefront_drum
)))
1711 return wavefront_send_drum (&header
);
1714 if (copy_from_user(&header
.hdr
.p
, header
.hdrptr
,
1715 sizeof (wavefront_patch
)))
1718 return wavefront_send_patch (&header
);
1721 if (copy_from_user(&header
.hdr
.pr
, header
.hdrptr
,
1722 sizeof (wavefront_program
)))
1725 return wavefront_send_program (&header
);
1728 printk (KERN_ERR LOGNAME
"unknown patch type %d.\n",
1736 /***********************************************************************
1737 WaveFront: /dev/sequencer{,2} and other hardware-dependent interfaces
1738 ***********************************************************************/
1741 process_sample_hdr (UCHAR8
*buf
)
1749 /* The board doesn't send us an exact copy of a "wavefront_sample"
1750 in response to an Upload Sample Header command. Instead, we
1751 have to convert the data format back into our data structure,
1752 just as in the Download Sample command, where we have to do
1753 something very similar in the reverse direction.
1756 *((UINT32
*) &s
.sampleStartOffset
) = demunge_int32 (ptr
, 4); ptr
+= 4;
1757 *((UINT32
*) &s
.loopStartOffset
) = demunge_int32 (ptr
, 4); ptr
+= 4;
1758 *((UINT32
*) &s
.loopEndOffset
) = demunge_int32 (ptr
, 4); ptr
+= 4;
1759 *((UINT32
*) &s
.sampleEndOffset
) = demunge_int32 (ptr
, 4); ptr
+= 4;
1760 *((UINT32
*) &s
.FrequencyBias
) = demunge_int32 (ptr
, 3); ptr
+= 3;
1762 s
.SampleResolution
= *ptr
& 0x3;
1763 s
.Loop
= *ptr
& 0x8;
1764 s
.Bidirectional
= *ptr
& 0x10;
1765 s
.Reverse
= *ptr
& 0x40;
1767 /* Now copy it back to where it came from */
1769 memcpy (buf
, (unsigned char *) &s
, sizeof (wavefront_sample
));
1773 wavefront_synth_control (int cmd
, wavefront_control
*wc
)
1776 unsigned char patchnumbuf
[2];
1779 DPRINT (WF_DEBUG_CMD
, "synth control with "
1780 "cmd 0x%x\n", wc
->cmd
);
1782 /* Pre-handling of or for various commands */
1785 case WFC_DISABLE_INTERRUPTS
:
1786 printk (KERN_INFO LOGNAME
"interrupts disabled.\n");
1787 outb (0x80|0x20, dev
.control_port
);
1788 dev
.interrupts_on
= 0;
1791 case WFC_ENABLE_INTERRUPTS
:
1792 printk (KERN_INFO LOGNAME
"interrupts enabled.\n");
1793 outb (0x80|0x40|0x20, dev
.control_port
);
1794 dev
.interrupts_on
= 1;
1797 case WFC_INTERRUPT_STATUS
:
1798 wc
->rbuf
[0] = dev
.interrupts_on
;
1801 case WFC_ROMSAMPLES_RDONLY
:
1802 dev
.rom_samples_rdonly
= wc
->wbuf
[0];
1806 case WFC_IDENTIFY_SLOT_TYPE
:
1807 i
= wc
->wbuf
[0] | (wc
->wbuf
[1] << 7);
1808 if (i
<0 || i
>= WF_MAX_SAMPLE
) {
1809 printk (KERN_WARNING LOGNAME
"invalid slot ID %d\n",
1811 wc
->status
= EINVAL
;
1814 wc
->rbuf
[0] = dev
.sample_status
[i
];
1818 case WFC_DEBUG_DRIVER
:
1819 dev
.debug
= wc
->wbuf
[0];
1820 printk (KERN_INFO LOGNAME
"debug = 0x%x\n", dev
.debug
);
1824 wffx_ioctl ((wavefront_fx_info
*) &wc
->wbuf
[0]);
1827 case WFC_UPLOAD_PATCH
:
1828 munge_int32 (*((UINT32
*) wc
->wbuf
), patchnumbuf
, 2);
1829 memcpy (wc
->wbuf
, patchnumbuf
, 2);
1832 case WFC_UPLOAD_MULTISAMPLE
:
1833 /* multisamples have to be handled differently, and
1834 cannot be dealt with properly by wavefront_cmd() alone.
1836 wc
->status
= wavefront_fetch_multisample
1837 ((wavefront_patch_info
*) wc
->rbuf
);
1840 case WFC_UPLOAD_SAMPLE_ALIAS
:
1841 printk (KERN_INFO LOGNAME
"support for sample alias upload "
1842 "being considered.\n");
1843 wc
->status
= EINVAL
;
1847 wc
->status
= wavefront_cmd (wc
->cmd
, wc
->rbuf
, wc
->wbuf
);
1849 /* Post-handling of certain commands.
1851 In particular, if the command was an upload, demunge the data
1852 so that the user-level doesn't have to think about it.
1855 if (wc
->status
== 0) {
1857 /* intercept any freemem requests so that we know
1858 we are always current with the user-level view
1862 case WFC_REPORT_FREE_MEMORY
:
1863 dev
.freemem
= demunge_int32 (wc
->rbuf
, 4);
1866 case WFC_UPLOAD_PATCH
:
1867 demunge_buf (wc
->rbuf
, wc
->rbuf
, WF_PATCH_BYTES
);
1870 case WFC_UPLOAD_PROGRAM
:
1871 demunge_buf (wc
->rbuf
, wc
->rbuf
, WF_PROGRAM_BYTES
);
1874 case WFC_UPLOAD_EDRUM_PROGRAM
:
1875 demunge_buf (wc
->rbuf
, wc
->rbuf
, WF_DRUM_BYTES
- 1);
1878 case WFC_UPLOAD_SAMPLE_HEADER
:
1879 process_sample_hdr (wc
->rbuf
);
1882 case WFC_UPLOAD_SAMPLE_ALIAS
:
1883 printk (KERN_INFO LOGNAME
"support for "
1884 "sample aliases still "
1885 "being considered.\n");
1889 if (virtual_midi_disable () < 0) {
1895 if (virtual_midi_enable () < 0) {
1906 /***********************************************************************/
1907 /* WaveFront: Linux file system interface (for access via raw synth) */
1908 /***********************************************************************/
1911 wavefront_open (struct inode
*inode
, struct file
*file
)
1914 dev
.opened
= file
->f_flags
;
1919 wavefront_release(struct inode
*inode
, struct file
*file
)
1929 wavefront_ioctl(struct inode
*inode
, struct file
*file
,
1930 unsigned int cmd
, unsigned long arg
)
1932 wavefront_control wc
;
1938 if (copy_from_user(&wc
, (void __user
*) arg
, sizeof (wc
)))
1941 if ((err
= wavefront_synth_control (cmd
, &wc
)) == 0) {
1942 if (copy_to_user ((void __user
*) arg
, &wc
, sizeof (wc
)))
1948 case WFCTL_LOAD_SPP
:
1949 return wavefront_load_patch ((const char __user
*) arg
);
1952 printk (KERN_WARNING LOGNAME
"invalid ioctl %#x\n", cmd
);
1959 static /*const*/ struct file_operations wavefront_fops
= {
1960 .owner
= THIS_MODULE
,
1961 .llseek
= no_llseek
,
1962 .ioctl
= wavefront_ioctl
,
1963 .open
= wavefront_open
,
1964 .release
= wavefront_release
,
1968 /***********************************************************************/
1969 /* WaveFront: OSS installation and support interface */
1970 /***********************************************************************/
1972 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
1974 static struct synth_info wavefront_info
=
1975 {"Turtle Beach WaveFront", 0, SYNTH_TYPE_SAMPLE
, SAMPLE_TYPE_WAVEFRONT
,
1976 0, 32, 0, 0, SYNTH_CAP_INPUT
};
1979 wavefront_oss_open (int devno
, int mode
)
1987 wavefront_oss_close (int devno
)
1996 wavefront_oss_ioctl (int devno
, unsigned int cmd
, void __user
* arg
)
1999 wavefront_control wc
;
2003 case SNDCTL_SYNTH_INFO
:
2004 if(copy_to_user(arg
, &wavefront_info
, sizeof (wavefront_info
)))
2008 case SNDCTL_SEQ_RESETSAMPLES
:
2009 // printk (KERN_WARNING LOGNAME "driver cannot reset samples.\n");
2010 return 0; /* don't force an error */
2012 case SNDCTL_SEQ_PERCMODE
:
2013 return 0; /* don't force an error */
2015 case SNDCTL_SYNTH_MEMAVL
:
2016 if ((dev
.freemem
= wavefront_freemem ()) < 0) {
2017 printk (KERN_ERR LOGNAME
"cannot get memory size\n");
2024 case SNDCTL_SYNTH_CONTROL
:
2025 if(copy_from_user (&wc
, arg
, sizeof (wc
)))
2027 else if ((err
= wavefront_synth_control (cmd
, &wc
)) == 0) {
2028 if(copy_to_user (arg
, &wc
, sizeof (wc
)))
2040 wavefront_oss_load_patch (int devno
, int format
, const char __user
*addr
,
2041 int offs
, int count
, int pmgr_flag
)
2044 if (format
== SYSEX_PATCH
) { /* Handled by midi_synth.c */
2045 if (midi_load_patch
== NULL
) {
2046 printk (KERN_ERR LOGNAME
2047 "SYSEX not loadable: "
2048 "no midi patch loader!\n");
2052 return midi_load_patch (devno
, format
, addr
,
2053 offs
, count
, pmgr_flag
);
2055 } else if (format
== GUS_PATCH
) {
2056 return wavefront_load_gus_patch (devno
, format
,
2057 addr
, offs
, count
, pmgr_flag
);
2059 } else if (format
!= WAVEFRONT_PATCH
) {
2060 printk (KERN_ERR LOGNAME
"unknown patch format %d\n", format
);
2064 if (count
< sizeof (wavefront_patch_info
)) {
2065 printk (KERN_ERR LOGNAME
"sample header too short\n");
2069 /* "addr" points to a user-space wavefront_patch_info */
2071 return wavefront_load_patch (addr
);
2074 static struct synth_operations wavefront_operations
=
2076 .owner
= THIS_MODULE
,
2078 .info
= &wavefront_info
,
2080 .synth_type
= SYNTH_TYPE_SAMPLE
,
2081 .synth_subtype
= SAMPLE_TYPE_WAVEFRONT
,
2082 .open
= wavefront_oss_open
,
2083 .close
= wavefront_oss_close
,
2084 .ioctl
= wavefront_oss_ioctl
,
2085 .kill_note
= midi_synth_kill_note
,
2086 .start_note
= midi_synth_start_note
,
2087 .set_instr
= midi_synth_set_instr
,
2088 .reset
= midi_synth_reset
,
2089 .load_patch
= midi_synth_load_patch
,
2090 .aftertouch
= midi_synth_aftertouch
,
2091 .controller
= midi_synth_controller
,
2092 .panning
= midi_synth_panning
,
2093 .bender
= midi_synth_bender
,
2094 .setup_voice
= midi_synth_setup_voice
2096 #endif /* OSS_SUPPORT_SEQ */
2098 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_STATIC_INSTALL
2100 static void __init
attach_wavefront (struct address_info
*hw_config
)
2102 (void) install_wavefront ();
2105 static int __init
probe_wavefront (struct address_info
*hw_config
)
2107 return !detect_wavefront (hw_config
->irq
, hw_config
->io_base
);
2110 static void __exit
unload_wavefront (struct address_info
*hw_config
)
2112 (void) uninstall_wavefront ();
2115 #endif /* OSS_SUPPORT_STATIC_INSTALL */
2117 /***********************************************************************/
2118 /* WaveFront: Linux modular sound kernel installation interface */
2119 /***********************************************************************/
2122 wavefrontintr(int irq
, void *dev_id
, struct pt_regs
*dummy
)
2124 struct wf_config
*hw
= dev_id
;
2127 Some comments on interrupts. I attempted a version of this
2128 driver that used interrupts throughout the code instead of
2129 doing busy and/or sleep-waiting. Alas, it appears that once
2130 the Motorola firmware is downloaded, the card *never*
2131 generates an RX interrupt. These are successfully generated
2132 during firmware loading, and after that wavefront_status()
2133 reports that an interrupt is pending on the card from time
2134 to time, but it never seems to be delivered to this
2135 driver. Note also that wavefront_status() continues to
2136 report that RX interrupts are enabled, suggesting that I
2137 didn't goof up and disable them by mistake.
2139 Thus, I stepped back to a prior version of
2140 wavefront_wait(), the only place where this really
2141 matters. Its sad, but I've looked through the code to check
2142 on things, and I really feel certain that the Motorola
2143 firmware prevents RX-ready interrupts.
2146 if ((wavefront_status() & (STAT_INTR_READ
|STAT_INTR_WRITE
)) == 0) {
2152 wake_up_interruptible (&hw
->interrupt_sleeper
);
2158 0 Host Rx Interrupt Enable (1=Enabled)
2159 1 Host Rx Register Full (1=Full)
2160 2 Host Rx Interrupt Pending (1=Interrupt)
2162 4 Host Tx Interrupt (1=Enabled)
2163 5 Host Tx Register empty (1=Empty)
2164 6 Host Tx Interrupt Pending (1=Interrupt)
2169 wavefront_interrupt_bits (int irq
)
2189 printk (KERN_WARNING LOGNAME
"invalid IRQ %d\n", irq
);
2197 wavefront_should_cause_interrupt (int val
, int port
, int timeout
)
2200 unsigned long flags
;
2202 /* this will not help on SMP - but at least it compiles */
2203 spin_lock_irqsave(&lock
, flags
);
2206 interruptible_sleep_on_timeout (&dev
.interrupt_sleeper
, timeout
);
2207 spin_unlock_irqrestore(&lock
,flags
);
2210 static int __init
wavefront_hw_reset (void)
2214 unsigned long irq_mask
;
2217 /* IRQ already checked in init_module() */
2219 bits
= wavefront_interrupt_bits (dev
.irq
);
2221 printk (KERN_DEBUG LOGNAME
"autodetecting WaveFront IRQ\n");
2223 irq_mask
= probe_irq_on ();
2225 outb (0x0, dev
.control_port
);
2226 outb (0x80 | 0x40 | bits
, dev
.data_port
);
2227 wavefront_should_cause_interrupt(0x80|0x40|0x10|0x1,
2229 (reset_time
*HZ
)/100);
2231 reported_irq
= probe_irq_off (irq_mask
);
2233 if (reported_irq
!= dev
.irq
) {
2234 if (reported_irq
== 0) {
2235 printk (KERN_ERR LOGNAME
2236 "No unassigned interrupts detected "
2237 "after h/w reset\n");
2238 } else if (reported_irq
< 0) {
2239 printk (KERN_ERR LOGNAME
2240 "Multiple unassigned interrupts detected "
2241 "after h/w reset\n");
2243 printk (KERN_ERR LOGNAME
"autodetected IRQ %d not the "
2244 "value provided (%d)\n", reported_irq
,
2250 printk (KERN_INFO LOGNAME
"autodetected IRQ at %d\n",
2254 if (request_irq (dev
.irq
, wavefrontintr
,
2255 SA_INTERRUPT
|SA_SHIRQ
,
2256 "wavefront synth", &dev
) < 0) {
2257 printk (KERN_WARNING LOGNAME
"IRQ %d not available!\n",
2262 /* try reset of port */
2264 outb (0x0, dev
.control_port
);
2266 /* At this point, the board is in reset, and the H/W initialization
2267 register is accessed at the same address as the data port.
2269 Bit 7 - Enable IRQ Driver
2270 0 - Tri-state the Wave-Board drivers for the PC Bus IRQs
2271 1 - Enable IRQ selected by bits 5:3 to be driven onto the PC Bus.
2273 Bit 6 - MIDI Interface Select
2275 0 - Use the MIDI Input from the 26-pin WaveBlaster
2276 compatible header as the serial MIDI source
2277 1 - Use the MIDI Input from the 9-pin D connector as the
2280 Bits 5:3 - IRQ Selection
2291 Bit 0 - Disable Boot ROM
2292 0 - memory accesses to 03FC30-03FFFFH utilize the internal Boot ROM
2293 1 - memory accesses to 03FC30-03FFFFH are directed to external
2298 /* configure hardware: IRQ, enable interrupts,
2299 plus external 9-pin MIDI interface selected
2302 outb (0x80 | 0x40 | bits
, dev
.data_port
);
2306 0 Host Rx Interrupt Enable (1=Enabled) 0x1
2310 4 Host Tx Interrupt Enable 0x10
2311 5 Mute (0=Mute; 1=Play) 0x20
2312 6 Master Interrupt Enable (1=Enabled) 0x40
2313 7 Master Reset (0=Reset; 1=Run) 0x80
2315 Take us out of reset, mute output, master + TX + RX interrupts on.
2317 We'll get an interrupt presumably to tell us that the TX
2321 wavefront_should_cause_interrupt(0x80|0x40|0x10|0x1,
2323 (reset_time
*HZ
)/100);
2325 /* Note: data port is now the data port, not the h/w initialization
2330 printk (KERN_WARNING LOGNAME
2331 "intr not received after h/w un-reset.\n");
2335 dev
.interrupts_on
= 1;
2337 /* Note: data port is now the data port, not the h/w initialization
2340 At this point, only "HW VERSION" or "DOWNLOAD OS" commands
2341 will work. So, issue one of them, and wait for TX
2342 interrupt. This can take a *long* time after a cold boot,
2343 while the ISC ROM does its RAM test. The SDK says up to 4
2344 seconds - with 12MB of RAM on a Tropez+, it takes a lot
2345 longer than that (~16secs). Note that the card understands
2346 the difference between a warm and a cold boot, so
2347 subsequent ISC2115 reboots (say, caused by module
2348 reloading) will get through this much faster.
2350 XXX Interesting question: why is no RX interrupt received first ?
2353 wavefront_should_cause_interrupt(WFC_HARDWARE_VERSION
,
2354 dev
.data_port
, ramcheck_time
*HZ
);
2357 printk (KERN_WARNING LOGNAME
2358 "post-RAM-check interrupt not received.\n");
2362 if (!wavefront_wait (STAT_CAN_READ
)) {
2363 printk (KERN_WARNING LOGNAME
2364 "no response to HW version cmd.\n");
2368 if ((hwv
[0] = wavefront_read ()) == -1) {
2369 printk (KERN_WARNING LOGNAME
2370 "board not responding correctly.\n");
2374 if (hwv
[0] == 0xFF) { /* NAK */
2376 /* Board's RAM test failed. Try to read error code,
2377 and tell us about it either way.
2380 if ((hwv
[0] = wavefront_read ()) == -1) {
2381 printk (KERN_WARNING LOGNAME
"on-board RAM test failed "
2382 "(bad error code).\n");
2384 printk (KERN_WARNING LOGNAME
"on-board RAM test failed "
2385 "(error code: 0x%x).\n",
2391 /* We're OK, just get the next byte of the HW version response */
2393 if ((hwv
[1] = wavefront_read ()) == -1) {
2394 printk (KERN_WARNING LOGNAME
"incorrect h/w response.\n");
2398 printk (KERN_INFO LOGNAME
"hardware version %d.%d\n",
2406 free_irq (dev
.irq
, &dev
);
2412 static int __init
detect_wavefront (int irq
, int io_base
)
2414 unsigned char rbuf
[4], wbuf
[4];
2416 /* TB docs say the device takes up 8 ports, but we know that
2417 if there is an FX device present (i.e. a Tropez+) it really
2421 if (check_region (io_base
, 16)) {
2422 printk (KERN_ERR LOGNAME
"IO address range 0x%x - 0x%x "
2423 "already in use - ignored\n", dev
.base
,
2431 dev
.debug
= debug_default
;
2432 dev
.interrupts_on
= 0;
2434 dev
.rom_samples_rdonly
= 1; /* XXX default lock on ROM sample slots */
2436 if (wavefront_cmd (WFC_FIRMWARE_VERSION
, rbuf
, wbuf
) == 0) {
2438 dev
.fw_version
[0] = rbuf
[0];
2439 dev
.fw_version
[1] = rbuf
[1];
2440 printk (KERN_INFO LOGNAME
2441 "firmware %d.%d already loaded.\n",
2444 /* check that a command actually works */
2446 if (wavefront_cmd (WFC_HARDWARE_VERSION
,
2448 dev
.hw_version
[0] = rbuf
[0];
2449 dev
.hw_version
[1] = rbuf
[1];
2451 printk (KERN_WARNING LOGNAME
"not raw, but no "
2452 "hardware version!\n");
2459 printk (KERN_INFO LOGNAME
2460 "reloading firmware anyway.\n");
2467 printk (KERN_INFO LOGNAME
2468 "no response to firmware probe, assume raw.\n");
2472 init_waitqueue_head (&dev
.interrupt_sleeper
);
2474 if (wavefront_hw_reset ()) {
2475 printk (KERN_WARNING LOGNAME
"hardware reset failed\n");
2479 /* Check for FX device, present only on Tropez+ */
2481 dev
.has_fx
= (detect_wffx () == 0);
2487 #include <linux/fs.h>
2488 #include <linux/mm.h>
2489 #include <linux/slab.h>
2490 #include <asm/uaccess.h>
2494 wavefront_download_firmware (char *path
)
2497 unsigned char section
[WF_SECTION_MAX
];
2498 char section_length
; /* yes, just a char; max value is WF_SECTION_MAX */
2499 int section_cnt_downloaded
= 0;
2505 /* This tries to be a bit cleverer than the stuff Alan Cox did for
2506 the generic sound firmware, in that it actually knows
2507 something about the structure of the Motorola firmware. In
2508 particular, it uses a version that has been stripped of the
2509 20K of useless header information, and had section lengths
2510 added, making it possible to load the entire OS without any
2511 [kv]malloc() activity, since the longest entity we ever read is
2512 42 bytes (well, WF_SECTION_MAX) long.
2518 if ((fd
= sys_open (path
, 0, 0)) < 0) {
2519 printk (KERN_WARNING LOGNAME
"Unable to load \"%s\".\n",
2527 if ((x
= sys_read (fd
, §ion_length
, sizeof (section_length
))) !=
2528 sizeof (section_length
)) {
2529 printk (KERN_ERR LOGNAME
"firmware read error.\n");
2533 if (section_length
== 0) {
2537 if (sys_read (fd
, section
, section_length
) != section_length
) {
2538 printk (KERN_ERR LOGNAME
"firmware section "
2545 if (wavefront_write (WFC_DOWNLOAD_OS
)) {
2549 for (i
= 0; i
< section_length
; i
++) {
2550 if (wavefront_write (section
[i
])) {
2557 if (wavefront_wait (STAT_CAN_READ
)) {
2559 if ((c
= inb (dev
.data_port
)) != WF_ACK
) {
2561 printk (KERN_ERR LOGNAME
"download "
2562 "of section #%d not "
2563 "acknowledged, ack = 0x%x\n",
2564 section_cnt_downloaded
+ 1, c
);
2570 printk (KERN_ERR LOGNAME
"time out for firmware ACK.\n");
2583 printk (KERN_ERR
"\nWaveFront: firmware download failed!!!\n");
2587 static int __init
wavefront_config_midi (void)
2589 unsigned char rbuf
[4], wbuf
[4];
2591 if (detect_wf_mpu (dev
.irq
, dev
.base
) < 0) {
2592 printk (KERN_WARNING LOGNAME
2593 "could not find working MIDI device\n");
2597 if ((dev
.mididev
= install_wf_mpu ()) < 0) {
2598 printk (KERN_WARNING LOGNAME
2599 "MIDI interfaces not configured\n");
2603 /* Route external MIDI to WaveFront synth (by default) */
2605 if (wavefront_cmd (WFC_MISYNTH_ON
, rbuf
, wbuf
)) {
2606 printk (KERN_WARNING LOGNAME
2607 "cannot enable MIDI-IN to synth routing.\n");
2612 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2613 /* Get the regular MIDI patch loading function, so we can
2614 use it if we ever get handed a SYSEX patch. This is
2615 unlikely, because its so damn slow, but we may as well
2616 leave this functionality from maui.c behind, since it
2617 could be useful for sequencer applications that can
2618 only use MIDI to do patch loading.
2621 if (midi_devs
[dev
.mididev
]->converter
!= NULL
) {
2622 midi_load_patch
= midi_devs
[dev
.mididev
]->converter
->load_patch
;
2623 midi_devs
[dev
.mididev
]->converter
->load_patch
=
2624 &wavefront_oss_load_patch
;
2627 #endif /* OSS_SUPPORT_SEQ */
2629 /* Turn on Virtual MIDI, but first *always* turn it off,
2630 since otherwise consectutive reloads of the driver will
2631 never cause the hardware to generate the initial "internal" or
2632 "external" source bytes in the MIDI data stream. This
2633 is pretty important, since the internal hardware generally will
2634 be used to generate none or very little MIDI output, and
2635 thus the only source of MIDI data is actually external. Without
2636 the switch bytes, the driver will think it all comes from
2637 the internal interface. Duh.
2640 if (wavefront_cmd (WFC_VMIDI_OFF
, rbuf
, wbuf
)) {
2641 printk (KERN_WARNING LOGNAME
2642 "virtual MIDI mode not disabled\n");
2643 return 0; /* We're OK, but missing the external MIDI dev */
2646 if ((dev
.ext_mididev
= virtual_midi_enable ()) < 0) {
2647 printk (KERN_WARNING LOGNAME
"no virtual MIDI access.\n");
2649 if (wavefront_cmd (WFC_VMIDI_ON
, rbuf
, wbuf
)) {
2650 printk (KERN_WARNING LOGNAME
2651 "cannot enable virtual MIDI mode.\n");
2652 virtual_midi_disable ();
2659 static int __init
wavefront_do_reset (int atboot
)
2663 if (!atboot
&& wavefront_hw_reset ()) {
2664 printk (KERN_WARNING LOGNAME
"hw reset failed.\n");
2669 if (wavefront_download_firmware (ospath
)) {
2675 /* Wait for the OS to get running. The protocol for
2676 this is non-obvious, and was determined by
2677 using port-IO tracing in DOSemu and some
2678 experimentation here.
2680 Rather than using timed waits, use interrupts creatively.
2683 wavefront_should_cause_interrupt (WFC_NOOP
,
2688 printk (KERN_WARNING LOGNAME
2689 "no post-OS interrupt.\n");
2693 /* Now, do it again ! */
2695 wavefront_should_cause_interrupt (WFC_NOOP
,
2696 dev
.data_port
, (10*HZ
));
2699 printk (KERN_WARNING LOGNAME
2700 "no post-OS interrupt(2).\n");
2704 /* OK, no (RX/TX) interrupts any more, but leave mute
2708 outb (0x80|0x40, dev
.control_port
);
2710 /* No need for the IRQ anymore */
2712 free_irq (dev
.irq
, &dev
);
2716 if (dev
.has_fx
&& fx_raw
) {
2720 /* SETUPSND.EXE asks for sample memory config here, but since i
2721 have no idea how to interpret the result, we'll forget
2725 if ((dev
.freemem
= wavefront_freemem ()) < 0) {
2729 printk (KERN_INFO LOGNAME
"available DRAM %dk\n", dev
.freemem
/ 1024);
2731 if (wavefront_write (0xf0) ||
2732 wavefront_write (1) ||
2733 (wavefront_read () < 0)) {
2735 printk (KERN_WARNING LOGNAME
"MPU emulation mode not set.\n");
2741 if (wavefront_cmd (WFC_SET_NVOICES
, NULL
, voices
)) {
2742 printk (KERN_WARNING LOGNAME
2743 "cannot set number of voices to 32.\n");
2751 /* reset that sucker so that it doesn't bother us. */
2753 outb (0x0, dev
.control_port
);
2754 dev
.interrupts_on
= 0;
2756 free_irq (dev
.irq
, &dev
);
2761 static int __init
wavefront_init (int atboot
)
2763 int samples_are_from_rom
;
2766 samples_are_from_rom
= 1;
2768 /* XXX is this always true ? */
2769 samples_are_from_rom
= 0;
2772 if (dev
.israw
|| fx_raw
) {
2773 if (wavefront_do_reset (atboot
)) {
2778 wavefront_get_sample_status (samples_are_from_rom
);
2779 wavefront_get_program_status ();
2780 wavefront_get_patch_status ();
2782 /* Start normal operation: unreset, master interrupt enabled, no mute
2785 outb (0x80|0x40|0x20, dev
.control_port
);
2790 static int __init
install_wavefront (void)
2793 if ((dev
.synth_dev
= register_sound_synth (&wavefront_fops
, -1)) < 0) {
2794 printk (KERN_ERR LOGNAME
"cannot register raw synth\n");
2798 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2799 if ((dev
.oss_dev
= sound_alloc_synthdev()) == -1) {
2800 printk (KERN_ERR LOGNAME
"Too many sequencers\n");
2803 synth_devs
[dev
.oss_dev
] = &wavefront_operations
;
2805 #endif /* OSS_SUPPORT_SEQ */
2807 if (wavefront_init (1) < 0) {
2808 printk (KERN_WARNING LOGNAME
"initialization failed.\n");
2810 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2811 sound_unload_synthdev (dev
.oss_dev
);
2812 #endif /* OSS_SUPPORT_SEQ */
2817 request_region (dev
.base
+2, 6, "wavefront synth");
2820 request_region (dev
.base
+8, 8, "wavefront fx");
2823 if (wavefront_config_midi ()) {
2824 printk (KERN_WARNING LOGNAME
"could not initialize MIDI.\n");
2830 static void __exit
uninstall_wavefront (void)
2832 /* the first two i/o addresses are freed by the wf_mpu code */
2833 release_region (dev
.base
+2, 6);
2836 release_region (dev
.base
+8, 8);
2839 unregister_sound_synth (dev
.synth_dev
);
2841 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2842 sound_unload_synthdev (dev
.oss_dev
);
2843 #endif /* OSS_SUPPORT_SEQ */
2844 uninstall_wf_mpu ();
2847 /***********************************************************************/
2848 /* WaveFront FX control */
2849 /***********************************************************************/
2853 /* Control bits for the Load Control Register
2856 #define FX_LSB_TRANSFER 0x01 /* transfer after DSP LSB byte written */
2857 #define FX_MSB_TRANSFER 0x02 /* transfer after DSP MSB byte written */
2858 #define FX_AUTO_INCR 0x04 /* auto-increment DSP address after transfer */
2865 unsigned int x
= 0x80;
2867 for (i
= 0; i
< 1000; i
++) {
2868 x
= inb (dev
.fx_status
);
2869 if ((x
& 0x80) == 0) {
2875 printk (KERN_ERR LOGNAME
"FX device never idle.\n");
2882 int __init
detect_wffx (void)
2884 /* This is a crude check, but its the best one I have for now.
2885 Certainly on the Maui and the Tropez, wffx_idle() will
2886 report "never idle", which suggests that this test should
2890 if (inb (dev
.fx_status
) & 0x80) {
2891 printk (KERN_INFO LOGNAME
"Hmm, probably a Maui or Tropez.\n");
2898 int __init
attach_wffx (void)
2900 if ((dev
.fx_mididev
= sound_alloc_mididev ()) < 0) {
2901 printk (KERN_WARNING LOGNAME
"cannot install FX Midi driver\n");
2909 wffx_mute (int onoff
)
2916 outb (onoff
? 0x02 : 0x00, dev
.fx_op
);
2920 wffx_memset (int page
,
2921 int addr
, int cnt
, unsigned short *data
)
2923 if (page
< 0 || page
> 7) {
2924 printk (KERN_ERR LOGNAME
"FX memset: "
2925 "page must be >= 0 and <= 7\n");
2929 if (addr
< 0 || addr
> 0x7f) {
2930 printk (KERN_ERR LOGNAME
"FX memset: "
2931 "addr must be >= 0 and <= 7f\n");
2937 outb (FX_LSB_TRANSFER
, dev
.fx_lcr
);
2938 outb (page
, dev
.fx_dsp_page
);
2939 outb (addr
, dev
.fx_dsp_addr
);
2940 outb ((data
[0] >> 8), dev
.fx_dsp_msb
);
2941 outb ((data
[0] & 0xff), dev
.fx_dsp_lsb
);
2943 printk (KERN_INFO LOGNAME
"FX: addr %d:%x set to 0x%x\n",
2944 page
, addr
, data
[0]);
2949 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
2950 outb (page
, dev
.fx_dsp_page
);
2951 outb (addr
, dev
.fx_dsp_addr
);
2953 for (i
= 0; i
< cnt
; i
++) {
2954 outb ((data
[i
] >> 8), dev
.fx_dsp_msb
);
2955 outb ((data
[i
] & 0xff), dev
.fx_dsp_lsb
);
2956 if (!wffx_idle ()) {
2962 printk (KERN_WARNING LOGNAME
2964 "(0x%x, 0x%x, %p, %d) incomplete\n",
2965 page
, addr
, data
, cnt
);
2974 wffx_ioctl (wavefront_fx_info
*r
)
2977 unsigned short page_data
[256];
2980 switch (r
->request
) {
2982 wffx_mute (r
->data
[0]);
2987 if (r
->data
[2] <= 0) {
2988 printk (KERN_ERR LOGNAME
"cannot write "
2989 "<= 0 bytes to FX\n");
2991 } else if (r
->data
[2] == 1) {
2992 pd
= (unsigned short *) &r
->data
[3];
2994 if (r
->data
[2] > sizeof (page_data
)) {
2995 printk (KERN_ERR LOGNAME
"cannot write "
2996 "> 255 bytes to FX\n");
2999 if (copy_from_user(page_data
,
3000 (unsigned char __user
*)r
->data
[3],
3006 return wffx_memset (r
->data
[0], /* page */
3007 r
->data
[1], /* addr */
3008 r
->data
[2], /* cnt */
3012 printk (KERN_WARNING LOGNAME
3013 "FX: ioctl %d not yet supported\n",
3019 /* YSS225 initialization.
3021 This code was developed using DOSEMU. The Turtle Beach SETUPSND
3022 utility was run with I/O tracing in DOSEMU enabled, and a reconstruction
3023 of the port I/O done, using the Yamaha faxback document as a guide
3024 to add more logic to the code. Its really pretty weird.
3026 There was an alternative approach of just dumping the whole I/O
3027 sequence as a series of port/value pairs and a simple loop
3028 that output it. However, I hope that eventually I'll get more
3029 control over what this code does, and so I tried to stick with
3030 a somewhat "algorithmic" approach.
3033 static int __init
wffx_init (void)
3038 /* Set all bits for all channels on the MOD unit to zero */
3039 /* XXX But why do this twice ? */
3041 for (j
= 0; j
< 2; j
++) {
3042 for (i
= 0x10; i
<= 0xff; i
++) {
3044 if (!wffx_idle ()) {
3048 outb (i
, dev
.fx_mod_addr
);
3049 outb (0x0, dev
.fx_mod_data
);
3053 if (!wffx_idle()) return (-1);
3054 outb (0x02, dev
.fx_op
); /* mute on */
3056 if (!wffx_idle()) return (-1);
3057 outb (0x07, dev
.fx_dsp_page
);
3058 outb (0x44, dev
.fx_dsp_addr
);
3059 outb (0x00, dev
.fx_dsp_msb
);
3060 outb (0x00, dev
.fx_dsp_lsb
);
3061 if (!wffx_idle()) return (-1);
3062 outb (0x07, dev
.fx_dsp_page
);
3063 outb (0x42, dev
.fx_dsp_addr
);
3064 outb (0x00, dev
.fx_dsp_msb
);
3065 outb (0x00, dev
.fx_dsp_lsb
);
3066 if (!wffx_idle()) return (-1);
3067 outb (0x07, dev
.fx_dsp_page
);
3068 outb (0x43, dev
.fx_dsp_addr
);
3069 outb (0x00, dev
.fx_dsp_msb
);
3070 outb (0x00, dev
.fx_dsp_lsb
);
3071 if (!wffx_idle()) return (-1);
3072 outb (0x07, dev
.fx_dsp_page
);
3073 outb (0x7c, dev
.fx_dsp_addr
);
3074 outb (0x00, dev
.fx_dsp_msb
);
3075 outb (0x00, dev
.fx_dsp_lsb
);
3076 if (!wffx_idle()) return (-1);
3077 outb (0x07, dev
.fx_dsp_page
);
3078 outb (0x7e, dev
.fx_dsp_addr
);
3079 outb (0x00, dev
.fx_dsp_msb
);
3080 outb (0x00, dev
.fx_dsp_lsb
);
3081 if (!wffx_idle()) return (-1);
3082 outb (0x07, dev
.fx_dsp_page
);
3083 outb (0x46, dev
.fx_dsp_addr
);
3084 outb (0x00, dev
.fx_dsp_msb
);
3085 outb (0x00, dev
.fx_dsp_lsb
);
3086 if (!wffx_idle()) return (-1);
3087 outb (0x07, dev
.fx_dsp_page
);
3088 outb (0x49, dev
.fx_dsp_addr
);
3089 outb (0x00, dev
.fx_dsp_msb
);
3090 outb (0x00, dev
.fx_dsp_lsb
);
3091 if (!wffx_idle()) return (-1);
3092 outb (0x07, dev
.fx_dsp_page
);
3093 outb (0x47, dev
.fx_dsp_addr
);
3094 outb (0x00, dev
.fx_dsp_msb
);
3095 outb (0x00, dev
.fx_dsp_lsb
);
3096 if (!wffx_idle()) return (-1);
3097 outb (0x07, dev
.fx_dsp_page
);
3098 outb (0x4a, dev
.fx_dsp_addr
);
3099 outb (0x00, dev
.fx_dsp_msb
);
3100 outb (0x00, dev
.fx_dsp_lsb
);
3102 /* either because of stupidity by TB's programmers, or because it
3103 actually does something, rezero the MOD page.
3105 for (i
= 0x10; i
<= 0xff; i
++) {
3107 if (!wffx_idle ()) {
3111 outb (i
, dev
.fx_mod_addr
);
3112 outb (0x0, dev
.fx_mod_data
);
3114 /* load page zero */
3116 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3117 outb (0x00, dev
.fx_dsp_page
);
3118 outb (0x00, dev
.fx_dsp_addr
);
3120 for (i
= 0; i
< sizeof (page_zero
); i
+= 2) {
3121 outb (page_zero
[i
], dev
.fx_dsp_msb
);
3122 outb (page_zero
[i
+1], dev
.fx_dsp_lsb
);
3123 if (!wffx_idle()) return (-1);
3126 /* Now load page one */
3128 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3129 outb (0x01, dev
.fx_dsp_page
);
3130 outb (0x00, dev
.fx_dsp_addr
);
3132 for (i
= 0; i
< sizeof (page_one
); i
+= 2) {
3133 outb (page_one
[i
], dev
.fx_dsp_msb
);
3134 outb (page_one
[i
+1], dev
.fx_dsp_lsb
);
3135 if (!wffx_idle()) return (-1);
3138 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3139 outb (0x02, dev
.fx_dsp_page
);
3140 outb (0x00, dev
.fx_dsp_addr
);
3142 for (i
= 0; i
< sizeof (page_two
); i
++) {
3143 outb (page_two
[i
], dev
.fx_dsp_lsb
);
3144 if (!wffx_idle()) return (-1);
3147 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3148 outb (0x03, dev
.fx_dsp_page
);
3149 outb (0x00, dev
.fx_dsp_addr
);
3151 for (i
= 0; i
< sizeof (page_three
); i
++) {
3152 outb (page_three
[i
], dev
.fx_dsp_lsb
);
3153 if (!wffx_idle()) return (-1);
3156 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3157 outb (0x04, dev
.fx_dsp_page
);
3158 outb (0x00, dev
.fx_dsp_addr
);
3160 for (i
= 0; i
< sizeof (page_four
); i
++) {
3161 outb (page_four
[i
], dev
.fx_dsp_lsb
);
3162 if (!wffx_idle()) return (-1);
3165 /* Load memory area (page six) */
3167 outb (FX_LSB_TRANSFER
, dev
.fx_lcr
);
3168 outb (0x06, dev
.fx_dsp_page
);
3170 for (i
= 0; i
< sizeof (page_six
); i
+= 3) {
3171 outb (page_six
[i
], dev
.fx_dsp_addr
);
3172 outb (page_six
[i
+1], dev
.fx_dsp_msb
);
3173 outb (page_six
[i
+2], dev
.fx_dsp_lsb
);
3174 if (!wffx_idle()) return (-1);
3177 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3178 outb (0x07, dev
.fx_dsp_page
);
3179 outb (0x00, dev
.fx_dsp_addr
);
3181 for (i
= 0; i
< sizeof (page_seven
); i
+= 2) {
3182 outb (page_seven
[i
], dev
.fx_dsp_msb
);
3183 outb (page_seven
[i
+1], dev
.fx_dsp_lsb
);
3184 if (!wffx_idle()) return (-1);
3187 /* Now setup the MOD area. We do this algorithmically in order to
3188 save a little data space. It could be done in the same fashion
3192 for (i
= 0x00; i
<= 0x0f; i
++) {
3193 outb (0x01, dev
.fx_mod_addr
);
3194 outb (i
, dev
.fx_mod_data
);
3195 if (!wffx_idle()) return (-1);
3196 outb (0x02, dev
.fx_mod_addr
);
3197 outb (0x00, dev
.fx_mod_data
);
3198 if (!wffx_idle()) return (-1);
3201 for (i
= 0xb0; i
<= 0xbf; i
++) {
3202 outb (i
, dev
.fx_mod_addr
);
3203 outb (0x20, dev
.fx_mod_data
);
3204 if (!wffx_idle()) return (-1);
3207 for (i
= 0xf0; i
<= 0xff; i
++) {
3208 outb (i
, dev
.fx_mod_addr
);
3209 outb (0x20, dev
.fx_mod_data
);
3210 if (!wffx_idle()) return (-1);
3213 for (i
= 0x10; i
<= 0x1d; i
++) {
3214 outb (i
, dev
.fx_mod_addr
);
3215 outb (0xff, dev
.fx_mod_data
);
3216 if (!wffx_idle()) return (-1);
3219 outb (0x1e, dev
.fx_mod_addr
);
3220 outb (0x40, dev
.fx_mod_data
);
3221 if (!wffx_idle()) return (-1);
3223 for (i
= 0x1f; i
<= 0x2d; i
++) {
3224 outb (i
, dev
.fx_mod_addr
);
3225 outb (0xff, dev
.fx_mod_data
);
3226 if (!wffx_idle()) return (-1);
3229 outb (0x2e, dev
.fx_mod_addr
);
3230 outb (0x00, dev
.fx_mod_data
);
3231 if (!wffx_idle()) return (-1);
3233 for (i
= 0x2f; i
<= 0x3e; i
++) {
3234 outb (i
, dev
.fx_mod_addr
);
3235 outb (0x00, dev
.fx_mod_data
);
3236 if (!wffx_idle()) return (-1);
3239 outb (0x3f, dev
.fx_mod_addr
);
3240 outb (0x20, dev
.fx_mod_data
);
3241 if (!wffx_idle()) return (-1);
3243 for (i
= 0x40; i
<= 0x4d; i
++) {
3244 outb (i
, dev
.fx_mod_addr
);
3245 outb (0x00, dev
.fx_mod_data
);
3246 if (!wffx_idle()) return (-1);
3249 outb (0x4e, dev
.fx_mod_addr
);
3250 outb (0x0e, dev
.fx_mod_data
);
3251 if (!wffx_idle()) return (-1);
3252 outb (0x4f, dev
.fx_mod_addr
);
3253 outb (0x0e, dev
.fx_mod_data
);
3254 if (!wffx_idle()) return (-1);
3257 for (i
= 0x50; i
<= 0x6b; i
++) {
3258 outb (i
, dev
.fx_mod_addr
);
3259 outb (0x00, dev
.fx_mod_data
);
3260 if (!wffx_idle()) return (-1);
3263 outb (0x6c, dev
.fx_mod_addr
);
3264 outb (0x40, dev
.fx_mod_data
);
3265 if (!wffx_idle()) return (-1);
3267 outb (0x6d, dev
.fx_mod_addr
);
3268 outb (0x00, dev
.fx_mod_data
);
3269 if (!wffx_idle()) return (-1);
3271 outb (0x6e, dev
.fx_mod_addr
);
3272 outb (0x40, dev
.fx_mod_data
);
3273 if (!wffx_idle()) return (-1);
3275 outb (0x6f, dev
.fx_mod_addr
);
3276 outb (0x40, dev
.fx_mod_data
);
3277 if (!wffx_idle()) return (-1);
3279 for (i
= 0x70; i
<= 0x7f; i
++) {
3280 outb (i
, dev
.fx_mod_addr
);
3281 outb (0xc0, dev
.fx_mod_data
);
3282 if (!wffx_idle()) return (-1);
3285 for (i
= 0x80; i
<= 0xaf; i
++) {
3286 outb (i
, dev
.fx_mod_addr
);
3287 outb (0x00, dev
.fx_mod_data
);
3288 if (!wffx_idle()) return (-1);
3291 for (i
= 0xc0; i
<= 0xdd; i
++) {
3292 outb (i
, dev
.fx_mod_addr
);
3293 outb (0x00, dev
.fx_mod_data
);
3294 if (!wffx_idle()) return (-1);
3297 outb (0xde, dev
.fx_mod_addr
);
3298 outb (0x10, dev
.fx_mod_data
);
3299 if (!wffx_idle()) return (-1);
3300 outb (0xdf, dev
.fx_mod_addr
);
3301 outb (0x10, dev
.fx_mod_data
);
3302 if (!wffx_idle()) return (-1);
3304 for (i
= 0xe0; i
<= 0xef; i
++) {
3305 outb (i
, dev
.fx_mod_addr
);
3306 outb (0x00, dev
.fx_mod_data
);
3307 if (!wffx_idle()) return (-1);
3310 for (i
= 0x00; i
<= 0x0f; i
++) {
3311 outb (0x01, dev
.fx_mod_addr
);
3312 outb (i
, dev
.fx_mod_data
);
3313 outb (0x02, dev
.fx_mod_addr
);
3314 outb (0x01, dev
.fx_mod_data
);
3315 if (!wffx_idle()) return (-1);
3318 outb (0x02, dev
.fx_op
); /* mute on */
3320 /* Now set the coefficients and so forth for the programs above */
3322 for (i
= 0; i
< sizeof (coefficients
); i
+= 4) {
3323 outb (coefficients
[i
], dev
.fx_dsp_page
);
3324 outb (coefficients
[i
+1], dev
.fx_dsp_addr
);
3325 outb (coefficients
[i
+2], dev
.fx_dsp_msb
);
3326 outb (coefficients
[i
+3], dev
.fx_dsp_lsb
);
3327 if (!wffx_idle()) return (-1);
3330 /* Some settings (?) that are too small to bundle into loops */
3332 if (!wffx_idle()) return (-1);
3333 outb (0x1e, dev
.fx_mod_addr
);
3334 outb (0x14, dev
.fx_mod_data
);
3335 if (!wffx_idle()) return (-1);
3336 outb (0xde, dev
.fx_mod_addr
);
3337 outb (0x20, dev
.fx_mod_data
);
3338 if (!wffx_idle()) return (-1);
3339 outb (0xdf, dev
.fx_mod_addr
);
3340 outb (0x20, dev
.fx_mod_data
);
3342 /* some more coefficients */
3344 if (!wffx_idle()) return (-1);
3345 outb (0x06, dev
.fx_dsp_page
);
3346 outb (0x78, dev
.fx_dsp_addr
);
3347 outb (0x00, dev
.fx_dsp_msb
);
3348 outb (0x40, dev
.fx_dsp_lsb
);
3349 if (!wffx_idle()) return (-1);
3350 outb (0x07, dev
.fx_dsp_page
);
3351 outb (0x03, dev
.fx_dsp_addr
);
3352 outb (0x0f, dev
.fx_dsp_msb
);
3353 outb (0xff, dev
.fx_dsp_lsb
);
3354 if (!wffx_idle()) return (-1);
3355 outb (0x07, dev
.fx_dsp_page
);
3356 outb (0x0b, dev
.fx_dsp_addr
);
3357 outb (0x0f, dev
.fx_dsp_msb
);
3358 outb (0xff, dev
.fx_dsp_lsb
);
3359 if (!wffx_idle()) return (-1);
3360 outb (0x07, dev
.fx_dsp_page
);
3361 outb (0x02, dev
.fx_dsp_addr
);
3362 outb (0x00, dev
.fx_dsp_msb
);
3363 outb (0x00, dev
.fx_dsp_lsb
);
3364 if (!wffx_idle()) return (-1);
3365 outb (0x07, dev
.fx_dsp_page
);
3366 outb (0x0a, dev
.fx_dsp_addr
);
3367 outb (0x00, dev
.fx_dsp_msb
);
3368 outb (0x00, dev
.fx_dsp_lsb
);
3369 if (!wffx_idle()) return (-1);
3370 outb (0x07, dev
.fx_dsp_page
);
3371 outb (0x46, dev
.fx_dsp_addr
);
3372 outb (0x00, dev
.fx_dsp_msb
);
3373 outb (0x00, dev
.fx_dsp_lsb
);
3374 if (!wffx_idle()) return (-1);
3375 outb (0x07, dev
.fx_dsp_page
);
3376 outb (0x49, dev
.fx_dsp_addr
);
3377 outb (0x00, dev
.fx_dsp_msb
);
3378 outb (0x00, dev
.fx_dsp_lsb
);
3380 /* Now, for some strange reason, lets reload every page
3381 and all the coefficients over again. I have *NO* idea
3382 why this is done. I do know that no sound is produced
3383 is this phase is omitted.
3386 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3387 outb (0x00, dev
.fx_dsp_page
);
3388 outb (0x10, dev
.fx_dsp_addr
);
3390 for (i
= 0; i
< sizeof (page_zero_v2
); i
+= 2) {
3391 outb (page_zero_v2
[i
], dev
.fx_dsp_msb
);
3392 outb (page_zero_v2
[i
+1], dev
.fx_dsp_lsb
);
3393 if (!wffx_idle()) return (-1);
3396 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3397 outb (0x01, dev
.fx_dsp_page
);
3398 outb (0x10, dev
.fx_dsp_addr
);
3400 for (i
= 0; i
< sizeof (page_one_v2
); i
+= 2) {
3401 outb (page_one_v2
[i
], dev
.fx_dsp_msb
);
3402 outb (page_one_v2
[i
+1], dev
.fx_dsp_lsb
);
3403 if (!wffx_idle()) return (-1);
3406 if (!wffx_idle()) return (-1);
3407 if (!wffx_idle()) return (-1);
3409 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3410 outb (0x02, dev
.fx_dsp_page
);
3411 outb (0x10, dev
.fx_dsp_addr
);
3413 for (i
= 0; i
< sizeof (page_two_v2
); i
++) {
3414 outb (page_two_v2
[i
], dev
.fx_dsp_lsb
);
3415 if (!wffx_idle()) return (-1);
3417 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3418 outb (0x03, dev
.fx_dsp_page
);
3419 outb (0x10, dev
.fx_dsp_addr
);
3421 for (i
= 0; i
< sizeof (page_three_v2
); i
++) {
3422 outb (page_three_v2
[i
], dev
.fx_dsp_lsb
);
3423 if (!wffx_idle()) return (-1);
3426 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3427 outb (0x04, dev
.fx_dsp_page
);
3428 outb (0x10, dev
.fx_dsp_addr
);
3430 for (i
= 0; i
< sizeof (page_four_v2
); i
++) {
3431 outb (page_four_v2
[i
], dev
.fx_dsp_lsb
);
3432 if (!wffx_idle()) return (-1);
3435 outb (FX_LSB_TRANSFER
, dev
.fx_lcr
);
3436 outb (0x06, dev
.fx_dsp_page
);
3438 /* Page six v.2 is algorithmic */
3440 for (i
= 0x10; i
<= 0x3e; i
+= 2) {
3441 outb (i
, dev
.fx_dsp_addr
);
3442 outb (0x00, dev
.fx_dsp_msb
);
3443 outb (0x00, dev
.fx_dsp_lsb
);
3444 if (!wffx_idle()) return (-1);
3447 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3448 outb (0x07, dev
.fx_dsp_page
);
3449 outb (0x10, dev
.fx_dsp_addr
);
3451 for (i
= 0; i
< sizeof (page_seven_v2
); i
+= 2) {
3452 outb (page_seven_v2
[i
], dev
.fx_dsp_msb
);
3453 outb (page_seven_v2
[i
+1], dev
.fx_dsp_lsb
);
3454 if (!wffx_idle()) return (-1);
3457 for (i
= 0x00; i
< sizeof(mod_v2
); i
+= 2) {
3458 outb (mod_v2
[i
], dev
.fx_mod_addr
);
3459 outb (mod_v2
[i
+1], dev
.fx_mod_data
);
3460 if (!wffx_idle()) return (-1);
3463 for (i
= 0; i
< sizeof (coefficients2
); i
+= 4) {
3464 outb (coefficients2
[i
], dev
.fx_dsp_page
);
3465 outb (coefficients2
[i
+1], dev
.fx_dsp_addr
);
3466 outb (coefficients2
[i
+2], dev
.fx_dsp_msb
);
3467 outb (coefficients2
[i
+3], dev
.fx_dsp_lsb
);
3468 if (!wffx_idle()) return (-1);
3471 for (i
= 0; i
< sizeof (coefficients3
); i
+= 2) {
3474 outb (0x07, dev
.fx_dsp_page
);
3475 x
= (i
% 4) ? 0x4e : 0x4c;
3476 outb (x
, dev
.fx_dsp_addr
);
3477 outb (coefficients3
[i
], dev
.fx_dsp_msb
);
3478 outb (coefficients3
[i
+1], dev
.fx_dsp_lsb
);
3481 outb (0x00, dev
.fx_op
); /* mute off */
3482 if (!wffx_idle()) return (-1);
3488 static int irq
= -1;
3490 MODULE_AUTHOR ("Paul Barton-Davis <pbd@op.net>");
3491 MODULE_DESCRIPTION ("Turtle Beach WaveFront Linux Driver");
3492 MODULE_LICENSE("GPL");
3493 MODULE_PARM (io
,"i");
3494 MODULE_PARM (irq
,"i");
3496 static int __init
init_wavfront (void)
3498 printk ("Turtle Beach WaveFront Driver\n"
3499 "Copyright (C) by Hannu Solvainen, "
3500 "Paul Barton-Davis 1993-1998.\n");
3502 /* XXX t'would be lovely to ask the CS4232 for these values, eh ? */
3504 if (io
== -1 || irq
== -1) {
3505 printk (KERN_INFO LOGNAME
"irq and io options must be set.\n");
3509 if (wavefront_interrupt_bits (irq
) < 0) {
3510 printk (KERN_INFO LOGNAME
3511 "IRQ must be 9, 5, 12 or 15 (not %d)\n", irq
);
3515 if (detect_wavefront (irq
, io
) < 0) {
3519 if (install_wavefront () < 0) {
3526 static void __exit
cleanup_wavfront (void)
3528 uninstall_wavefront ();
3531 module_init(init_wavfront
);
3532 module_exit(cleanup_wavfront
);