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 *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, 0, 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, 0, 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, 0, buf)) {
976 printk (KERN_WARNING LOGNAME "download patch failed\n");
984 wavefront_freemem (void)
989 if (wavefront_cmd (WFC_REPORT_FREE_MEMORY, rbuf, 0)) {
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,
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 *data_end = 0;
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 0x%x\n",
1028 header->size ? "" : "header ",
1029 header->number, header->subkey,
1031 (int) header->dataptr);
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,
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, 0, 0)) {
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, 0, 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, 0, 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 *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 *) &(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 *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 *) 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((unsigned char *) &header.hdr.s,
1692 (unsigned char *) header.hdrptr,
1693 sizeof(wavefront_multisample)))
1696 return wavefront_send_multisample (&header);
1701 if (copy_from_user((unsigned char *) &header.hdr.a,
1702 (unsigned char *) header.hdrptr,
1703 sizeof (wavefront_alias)))
1706 return wavefront_send_alias (&header);
1709 if (copy_from_user((unsigned char *) &header.hdr.d,
1710 (unsigned char *) header.hdrptr,
1711 sizeof (wavefront_drum)))
1714 return wavefront_send_drum (&header);
1717 if (copy_from_user((unsigned char *) &header.hdr.p,
1718 (unsigned char *) header.hdrptr,
1719 sizeof (wavefront_patch)))
1722 return wavefront_send_patch (&header);
1725 if (copy_from_user((unsigned char *) &header.hdr.pr,
1726 (unsigned char *) header.hdrptr,
1727 sizeof (wavefront_program)))
1730 return wavefront_send_program (&header);
1733 printk (KERN_ERR LOGNAME "unknown patch type %d.\n",
1741 /***********************************************************************
1742 WaveFront: /dev/sequencer{,2} and other hardware-dependent interfaces
1743 ***********************************************************************/
1746 process_sample_hdr (UCHAR8 *buf)
1754 /* The board doesn't send us an exact copy of a "wavefront_sample"
1755 in response to an Upload Sample Header command. Instead, we
1756 have to convert the data format back into our data structure,
1757 just as in the Download Sample command, where we have to do
1758 something very similar in the reverse direction.
1761 *((UINT32 *) &s.sampleStartOffset) = demunge_int32 (ptr, 4); ptr += 4;
1762 *((UINT32 *) &s.loopStartOffset) = demunge_int32 (ptr, 4); ptr += 4;
1763 *((UINT32 *) &s.loopEndOffset) = demunge_int32 (ptr, 4); ptr += 4;
1764 *((UINT32 *) &s.sampleEndOffset) = demunge_int32 (ptr, 4); ptr += 4;
1765 *((UINT32 *) &s.FrequencyBias) = demunge_int32 (ptr, 3); ptr += 3;
1767 s.SampleResolution = *ptr & 0x3;
1768 s.Loop = *ptr & 0x8;
1769 s.Bidirectional = *ptr & 0x10;
1770 s.Reverse = *ptr & 0x40;
1772 /* Now copy it back to where it came from */
1774 memcpy (buf, (unsigned char *) &s, sizeof (wavefront_sample));
1778 wavefront_synth_control (int cmd, wavefront_control *wc)
1781 unsigned char patchnumbuf[2];
1784 DPRINT (WF_DEBUG_CMD, "synth control with "
1785 "cmd 0x%x\n", wc->cmd);
1787 /* Pre-handling of or for various commands */
1790 case WFC_DISABLE_INTERRUPTS:
1791 printk (KERN_INFO LOGNAME "interrupts disabled.\n");
1792 outb (0x80|0x20, dev.control_port);
1793 dev.interrupts_on = 0;
1796 case WFC_ENABLE_INTERRUPTS:
1797 printk (KERN_INFO LOGNAME "interrupts enabled.\n");
1798 outb (0x80|0x40|0x20, dev.control_port);
1799 dev.interrupts_on = 1;
1802 case WFC_INTERRUPT_STATUS:
1803 wc->rbuf[0] = dev.interrupts_on;
1806 case WFC_ROMSAMPLES_RDONLY:
1807 dev.rom_samples_rdonly = wc->wbuf[0];
1811 case WFC_IDENTIFY_SLOT_TYPE:
1812 i = wc->wbuf[0] | (wc->wbuf[1] << 7);
1813 if (i <0 || i >= WF_MAX_SAMPLE) {
1814 printk (KERN_WARNING LOGNAME "invalid slot ID %d\n",
1816 wc->status = EINVAL;
1819 wc->rbuf[0] = dev.sample_status[i];
1823 case WFC_DEBUG_DRIVER:
1824 dev.debug = wc->wbuf[0];
1825 printk (KERN_INFO LOGNAME "debug = 0x%x\n", dev.debug);
1829 wffx_ioctl ((wavefront_fx_info *) &wc->wbuf[0]);
1832 case WFC_UPLOAD_PATCH:
1833 munge_int32 (*((UINT32 *) wc->wbuf), patchnumbuf, 2);
1834 memcpy (wc->wbuf, patchnumbuf, 2);
1837 case WFC_UPLOAD_MULTISAMPLE:
1838 /* multisamples have to be handled differently, and
1839 cannot be dealt with properly by wavefront_cmd() alone.
1841 wc->status = wavefront_fetch_multisample
1842 ((wavefront_patch_info *) wc->rbuf);
1845 case WFC_UPLOAD_SAMPLE_ALIAS:
1846 printk (KERN_INFO LOGNAME "support for sample alias upload "
1847 "being considered.\n");
1848 wc->status = EINVAL;
1852 wc->status = wavefront_cmd (wc->cmd, wc->rbuf, wc->wbuf);
1854 /* Post-handling of certain commands.
1856 In particular, if the command was an upload, demunge the data
1857 so that the user-level doesn't have to think about it.
1860 if (wc->status == 0) {
1862 /* intercept any freemem requests so that we know
1863 we are always current with the user-level view
1867 case WFC_REPORT_FREE_MEMORY:
1868 dev.freemem = demunge_int32 (wc->rbuf, 4);
1871 case WFC_UPLOAD_PATCH:
1872 demunge_buf (wc->rbuf, wc->rbuf, WF_PATCH_BYTES);
1875 case WFC_UPLOAD_PROGRAM:
1876 demunge_buf (wc->rbuf, wc->rbuf, WF_PROGRAM_BYTES);
1879 case WFC_UPLOAD_EDRUM_PROGRAM:
1880 demunge_buf (wc->rbuf, wc->rbuf, WF_DRUM_BYTES - 1);
1883 case WFC_UPLOAD_SAMPLE_HEADER:
1884 process_sample_hdr (wc->rbuf);
1887 case WFC_UPLOAD_SAMPLE_ALIAS:
1888 printk (KERN_INFO LOGNAME "support for "
1889 "sample aliases still "
1890 "being considered.\n");
1894 if (virtual_midi_disable () < 0) {
1900 if (virtual_midi_enable () < 0) {
1911 /***********************************************************************/
1912 /* WaveFront: Linux file system interface (for access via raw synth) */
1913 /***********************************************************************/
1916 wavefront_open (struct inode *inode, struct file *file)
1919 dev.opened = file->f_flags;
1924 wavefront_release(struct inode *inode, struct file *file)
1934 wavefront_ioctl(struct inode *inode, struct file *file,
1935 unsigned int cmd, unsigned long arg)
1937 wavefront_control wc;
1943 if (copy_from_user(&wc, (void *) arg, sizeof (wc)))
1946 if ((err = wavefront_synth_control (cmd, &wc)) == 0) {
1947 if (copy_to_user ((void *) arg, &wc, sizeof (wc)))
1953 case WFCTL_LOAD_SPP:
1954 return wavefront_load_patch ((const char *) arg);
1957 printk (KERN_WARNING LOGNAME "invalid ioctl %#x\n", cmd);
1964 static /*const*/ struct file_operations wavefront_fops = {
1965 .owner = THIS_MODULE,
1966 .llseek = no_llseek,
1967 .ioctl = wavefront_ioctl,
1968 .open = wavefront_open,
1969 .release = wavefront_release,
1973 /***********************************************************************/
1974 /* WaveFront: OSS installation and support interface */
1975 /***********************************************************************/
1977 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
1979 static struct synth_info wavefront_info =
1980 {"Turtle Beach WaveFront", 0, SYNTH_TYPE_SAMPLE, SAMPLE_TYPE_WAVEFRONT,
1981 0, 32, 0, 0, SYNTH_CAP_INPUT};
1984 wavefront_oss_open (int devno, int mode)
1992 wavefront_oss_close (int devno)
2001 wavefront_oss_ioctl (int devno, unsigned int cmd, caddr_t arg)
2004 wavefront_control wc;
2008 case SNDCTL_SYNTH_INFO:
2009 if(copy_to_user(&((char *) arg)[0], &wavefront_info,
2010 sizeof (wavefront_info)))
2014 case SNDCTL_SEQ_RESETSAMPLES:
2015 // printk (KERN_WARNING LOGNAME "driver cannot reset samples.\n");
2016 return 0; /* don't force an error */
2018 case SNDCTL_SEQ_PERCMODE:
2019 return 0; /* don't force an error */
2021 case SNDCTL_SYNTH_MEMAVL:
2022 if ((dev.freemem = wavefront_freemem ()) < 0) {
2023 printk (KERN_ERR LOGNAME "cannot get memory size\n");
2030 case SNDCTL_SYNTH_CONTROL:
2031 if(copy_from_user (&wc, arg, sizeof (wc)))
2033 else if ((err = wavefront_synth_control (cmd, &wc)) == 0) {
2034 if(copy_to_user (arg, &wc, sizeof (wc)))
2046 wavefront_oss_load_patch (int devno, int format, const char *addr,
2047 int offs, int count, int pmgr_flag)
2050 if (format == SYSEX_PATCH) { /* Handled by midi_synth.c */
2051 if (midi_load_patch == NULL) {
2052 printk (KERN_ERR LOGNAME
2053 "SYSEX not loadable: "
2054 "no midi patch loader!\n");
2058 return midi_load_patch (devno, format, addr,
2059 offs, count, pmgr_flag);
2061 } else if (format == GUS_PATCH) {
2062 return wavefront_load_gus_patch (devno, format,
2063 addr, offs, count, pmgr_flag);
2065 } else if (format != WAVEFRONT_PATCH) {
2066 printk (KERN_ERR LOGNAME "unknown patch format %d\n", format);
2070 if (count < sizeof (wavefront_patch_info)) {
2071 printk (KERN_ERR LOGNAME "sample header too short\n");
2075 /* "addr" points to a user-space wavefront_patch_info */
2077 return wavefront_load_patch (addr);
2080 static struct synth_operations wavefront_operations =
2082 .owner = THIS_MODULE,
2084 .info = &wavefront_info,
2086 .synth_type = SYNTH_TYPE_SAMPLE,
2087 .synth_subtype = SAMPLE_TYPE_WAVEFRONT,
2088 .open = wavefront_oss_open,
2089 .close = wavefront_oss_close,
2090 .ioctl = wavefront_oss_ioctl,
2091 .kill_note = midi_synth_kill_note,
2092 .start_note = midi_synth_start_note,
2093 .set_instr = midi_synth_set_instr,
2094 .reset = midi_synth_reset,
2095 .load_patch = midi_synth_load_patch,
2096 .aftertouch = midi_synth_aftertouch,
2097 .controller = midi_synth_controller,
2098 .panning = midi_synth_panning,
2099 .bender = midi_synth_bender,
2100 .setup_voice = midi_synth_setup_voice
2102 #endif /* OSS_SUPPORT_SEQ */
2104 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_STATIC_INSTALL
2106 static void __init attach_wavefront (struct address_info *hw_config)
2108 (void) install_wavefront ();
2111 static int __init probe_wavefront (struct address_info *hw_config)
2113 return !detect_wavefront (hw_config->irq, hw_config->io_base);
2116 static void __exit unload_wavefront (struct address_info *hw_config)
2118 (void) uninstall_wavefront ();
2121 #endif /* OSS_SUPPORT_STATIC_INSTALL */
2123 /***********************************************************************/
2124 /* WaveFront: Linux modular sound kernel installation interface */
2125 /***********************************************************************/
2128 wavefrontintr(int irq, void *dev_id, struct pt_regs *dummy)
2130 struct wf_config *hw = dev_id;
2133 Some comments on interrupts. I attempted a version of this
2134 driver that used interrupts throughout the code instead of
2135 doing busy and/or sleep-waiting. Alas, it appears that once
2136 the Motorola firmware is downloaded, the card *never*
2137 generates an RX interrupt. These are successfully generated
2138 during firmware loading, and after that wavefront_status()
2139 reports that an interrupt is pending on the card from time
2140 to time, but it never seems to be delivered to this
2141 driver. Note also that wavefront_status() continues to
2142 report that RX interrupts are enabled, suggesting that I
2143 didn't goof up and disable them by mistake.
2145 Thus, I stepped back to a prior version of
2146 wavefront_wait(), the only place where this really
2147 matters. Its sad, but I've looked through the code to check
2148 on things, and I really feel certain that the Motorola
2149 firmware prevents RX-ready interrupts.
2152 if ((wavefront_status() & (STAT_INTR_READ|STAT_INTR_WRITE)) == 0) {
2158 wake_up_interruptible (&hw->interrupt_sleeper);
2164 0 Host Rx Interrupt Enable (1=Enabled)
2165 1 Host Rx Register Full (1=Full)
2166 2 Host Rx Interrupt Pending (1=Interrupt)
2168 4 Host Tx Interrupt (1=Enabled)
2169 5 Host Tx Register empty (1=Empty)
2170 6 Host Tx Interrupt Pending (1=Interrupt)
2175 wavefront_interrupt_bits (int irq)
2195 printk (KERN_WARNING LOGNAME "invalid IRQ %d\n", irq);
2203 wavefront_should_cause_interrupt (int val, int port, int timeout)
2206 unsigned long flags;
2208 /* this will not help on SMP - but at least it compiles */
2209 spin_lock_irqsave(&lock, flags);
2212 interruptible_sleep_on_timeout (&dev.interrupt_sleeper, timeout);
2213 spin_unlock_irqrestore(&lock,flags);
2216 static int __init wavefront_hw_reset (void)
2220 unsigned long irq_mask;
2223 /* IRQ already checked in init_module() */
2225 bits = wavefront_interrupt_bits (dev.irq);
2227 printk (KERN_DEBUG LOGNAME "autodetecting WaveFront IRQ\n");
2229 irq_mask = probe_irq_on ();
2231 outb (0x0, dev.control_port);
2232 outb (0x80 | 0x40 | bits, dev.data_port);
2233 wavefront_should_cause_interrupt(0x80|0x40|0x10|0x1,
2235 (reset_time*HZ)/100);
2237 reported_irq = probe_irq_off (irq_mask);
2239 if (reported_irq != dev.irq) {
2240 if (reported_irq == 0) {
2241 printk (KERN_ERR LOGNAME
2242 "No unassigned interrupts detected "
2243 "after h/w reset\n");
2244 } else if (reported_irq < 0) {
2245 printk (KERN_ERR LOGNAME
2246 "Multiple unassigned interrupts detected "
2247 "after h/w reset\n");
2249 printk (KERN_ERR LOGNAME "autodetected IRQ %d not the "
2250 "value provided (%d)\n", reported_irq,
2256 printk (KERN_INFO LOGNAME "autodetected IRQ at %d\n",
2260 if (request_irq (dev.irq, wavefrontintr,
2261 SA_INTERRUPT|SA_SHIRQ,
2262 "wavefront synth", &dev) < 0) {
2263 printk (KERN_WARNING LOGNAME "IRQ %d not available!\n",
2268 /* try reset of port */
2270 outb (0x0, dev.control_port);
2272 /* At this point, the board is in reset, and the H/W initialization
2273 register is accessed at the same address as the data port.
2275 Bit 7 - Enable IRQ Driver
2276 0 - Tri-state the Wave-Board drivers for the PC Bus IRQs
2277 1 - Enable IRQ selected by bits 5:3 to be driven onto the PC Bus.
2279 Bit 6 - MIDI Interface Select
2281 0 - Use the MIDI Input from the 26-pin WaveBlaster
2282 compatible header as the serial MIDI source
2283 1 - Use the MIDI Input from the 9-pin D connector as the
2286 Bits 5:3 - IRQ Selection
2297 Bit 0 - Disable Boot ROM
2298 0 - memory accesses to 03FC30-03FFFFH utilize the internal Boot ROM
2299 1 - memory accesses to 03FC30-03FFFFH are directed to external
2304 /* configure hardware: IRQ, enable interrupts,
2305 plus external 9-pin MIDI interface selected
2308 outb (0x80 | 0x40 | bits, dev.data_port);
2312 0 Host Rx Interrupt Enable (1=Enabled) 0x1
2316 4 Host Tx Interrupt Enable 0x10
2317 5 Mute (0=Mute; 1=Play) 0x20
2318 6 Master Interrupt Enable (1=Enabled) 0x40
2319 7 Master Reset (0=Reset; 1=Run) 0x80
2321 Take us out of reset, mute output, master + TX + RX interrupts on.
2323 We'll get an interrupt presumably to tell us that the TX
2327 wavefront_should_cause_interrupt(0x80|0x40|0x10|0x1,
2329 (reset_time*HZ)/100);
2331 /* Note: data port is now the data port, not the h/w initialization
2336 printk (KERN_WARNING LOGNAME
2337 "intr not received after h/w un-reset.\n");
2341 dev.interrupts_on = 1;
2343 /* Note: data port is now the data port, not the h/w initialization
2346 At this point, only "HW VERSION" or "DOWNLOAD OS" commands
2347 will work. So, issue one of them, and wait for TX
2348 interrupt. This can take a *long* time after a cold boot,
2349 while the ISC ROM does its RAM test. The SDK says up to 4
2350 seconds - with 12MB of RAM on a Tropez+, it takes a lot
2351 longer than that (~16secs). Note that the card understands
2352 the difference between a warm and a cold boot, so
2353 subsequent ISC2115 reboots (say, caused by module
2354 reloading) will get through this much faster.
2356 XXX Interesting question: why is no RX interrupt received first ?
2359 wavefront_should_cause_interrupt(WFC_HARDWARE_VERSION,
2360 dev.data_port, ramcheck_time*HZ);
2363 printk (KERN_WARNING LOGNAME
2364 "post-RAM-check interrupt not received.\n");
2368 if (!wavefront_wait (STAT_CAN_READ)) {
2369 printk (KERN_WARNING LOGNAME
2370 "no response to HW version cmd.\n");
2374 if ((hwv[0] = wavefront_read ()) == -1) {
2375 printk (KERN_WARNING LOGNAME
2376 "board not responding correctly.\n");
2380 if (hwv[0] == 0xFF) { /* NAK */
2382 /* Board's RAM test failed. Try to read error code,
2383 and tell us about it either way.
2386 if ((hwv[0] = wavefront_read ()) == -1) {
2387 printk (KERN_WARNING LOGNAME "on-board RAM test failed "
2388 "(bad error code).\n");
2390 printk (KERN_WARNING LOGNAME "on-board RAM test failed "
2391 "(error code: 0x%x).\n",
2397 /* We're OK, just get the next byte of the HW version response */
2399 if ((hwv[1] = wavefront_read ()) == -1) {
2400 printk (KERN_WARNING LOGNAME "incorrect h/w response.\n");
2404 printk (KERN_INFO LOGNAME "hardware version %d.%d\n",
2412 free_irq (dev.irq, &dev);
2418 static int __init detect_wavefront (int irq, int io_base)
2420 unsigned char rbuf[4], wbuf[4];
2422 /* TB docs say the device takes up 8 ports, but we know that
2423 if there is an FX device present (i.e. a Tropez+) it really
2427 if (check_region (io_base, 16)) {
2428 printk (KERN_ERR LOGNAME "IO address range 0x%x - 0x%x "
2429 "already in use - ignored\n", dev.base,
2437 dev.debug = debug_default;
2438 dev.interrupts_on = 0;
2440 dev.rom_samples_rdonly = 1; /* XXX default lock on ROM sample slots */
2442 if (wavefront_cmd (WFC_FIRMWARE_VERSION, rbuf, wbuf) == 0) {
2444 dev.fw_version[0] = rbuf[0];
2445 dev.fw_version[1] = rbuf[1];
2446 printk (KERN_INFO LOGNAME
2447 "firmware %d.%d already loaded.\n",
2450 /* check that a command actually works */
2452 if (wavefront_cmd (WFC_HARDWARE_VERSION,
2454 dev.hw_version[0] = rbuf[0];
2455 dev.hw_version[1] = rbuf[1];
2457 printk (KERN_WARNING LOGNAME "not raw, but no "
2458 "hardware version!\n");
2465 printk (KERN_INFO LOGNAME
2466 "reloading firmware anyway.\n");
2473 printk (KERN_INFO LOGNAME
2474 "no response to firmware probe, assume raw.\n");
2478 init_waitqueue_head (&dev.interrupt_sleeper);
2480 if (wavefront_hw_reset ()) {
2481 printk (KERN_WARNING LOGNAME "hardware reset failed\n");
2485 /* Check for FX device, present only on Tropez+ */
2487 dev.has_fx = (detect_wffx () == 0);
2493 #include <linux/fs.h>
2494 #include <linux/mm.h>
2495 #include <linux/slab.h>
2496 #include <asm/uaccess.h>
2500 wavefront_download_firmware (char *path)
2503 unsigned char section[WF_SECTION_MAX];
2504 char section_length; /* yes, just a char; max value is WF_SECTION_MAX */
2505 int section_cnt_downloaded = 0;
2511 /* This tries to be a bit cleverer than the stuff Alan Cox did for
2512 the generic sound firmware, in that it actually knows
2513 something about the structure of the Motorola firmware. In
2514 particular, it uses a version that has been stripped of the
2515 20K of useless header information, and had section lengths
2516 added, making it possible to load the entire OS without any
2517 [kv]malloc() activity, since the longest entity we ever read is
2518 42 bytes (well, WF_SECTION_MAX) long.
2524 if ((fd = sys_open (path, 0, 0)) < 0) {
2525 printk (KERN_WARNING LOGNAME "Unable to load \"%s\".\n",
2533 if ((x = sys_read (fd, §ion_length, sizeof (section_length))) !=
2534 sizeof (section_length)) {
2535 printk (KERN_ERR LOGNAME "firmware read error.\n");
2539 if (section_length == 0) {
2543 if (sys_read (fd, section, section_length) != section_length) {
2544 printk (KERN_ERR LOGNAME "firmware section "
2551 if (wavefront_write (WFC_DOWNLOAD_OS)) {
2555 for (i = 0; i < section_length; i++) {
2556 if (wavefront_write (section[i])) {
2563 if (wavefront_wait (STAT_CAN_READ)) {
2565 if ((c = inb (dev.data_port)) != WF_ACK) {
2567 printk (KERN_ERR LOGNAME "download "
2568 "of section #%d not "
2569 "acknowledged, ack = 0x%x\n",
2570 section_cnt_downloaded + 1, c);
2576 printk (KERN_ERR LOGNAME "time out for firmware ACK.\n");
2589 printk (KERN_ERR "\nWaveFront: firmware download failed!!!\n");
2593 static int __init wavefront_config_midi (void)
2595 unsigned char rbuf[4], wbuf[4];
2597 if (detect_wf_mpu (dev.irq, dev.base) < 0) {
2598 printk (KERN_WARNING LOGNAME
2599 "could not find working MIDI device\n");
2603 if ((dev.mididev = install_wf_mpu ()) < 0) {
2604 printk (KERN_WARNING LOGNAME
2605 "MIDI interfaces not configured\n");
2609 /* Route external MIDI to WaveFront synth (by default) */
2611 if (wavefront_cmd (WFC_MISYNTH_ON, rbuf, wbuf)) {
2612 printk (KERN_WARNING LOGNAME
2613 "cannot enable MIDI-IN to synth routing.\n");
2618 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2619 /* Get the regular MIDI patch loading function, so we can
2620 use it if we ever get handed a SYSEX patch. This is
2621 unlikely, because its so damn slow, but we may as well
2622 leave this functionality from maui.c behind, since it
2623 could be useful for sequencer applications that can
2624 only use MIDI to do patch loading.
2627 if (midi_devs[dev.mididev]->converter != NULL) {
2628 midi_load_patch = midi_devs[dev.mididev]->converter->load_patch;
2629 midi_devs[dev.mididev]->converter->load_patch =
2630 &wavefront_oss_load_patch;
2633 #endif /* OSS_SUPPORT_SEQ */
2635 /* Turn on Virtual MIDI, but first *always* turn it off,
2636 since otherwise consectutive reloads of the driver will
2637 never cause the hardware to generate the initial "internal" or
2638 "external" source bytes in the MIDI data stream. This
2639 is pretty important, since the internal hardware generally will
2640 be used to generate none or very little MIDI output, and
2641 thus the only source of MIDI data is actually external. Without
2642 the switch bytes, the driver will think it all comes from
2643 the internal interface. Duh.
2646 if (wavefront_cmd (WFC_VMIDI_OFF, rbuf, wbuf)) {
2647 printk (KERN_WARNING LOGNAME
2648 "virtual MIDI mode not disabled\n");
2649 return 0; /* We're OK, but missing the external MIDI dev */
2652 if ((dev.ext_mididev = virtual_midi_enable ()) < 0) {
2653 printk (KERN_WARNING LOGNAME "no virtual MIDI access.\n");
2655 if (wavefront_cmd (WFC_VMIDI_ON, rbuf, wbuf)) {
2656 printk (KERN_WARNING LOGNAME
2657 "cannot enable virtual MIDI mode.\n");
2658 virtual_midi_disable ();
2665 static int __init wavefront_do_reset (int atboot)
2669 if (!atboot && wavefront_hw_reset ()) {
2670 printk (KERN_WARNING LOGNAME "hw reset failed.\n");
2675 if (wavefront_download_firmware (ospath)) {
2681 /* Wait for the OS to get running. The protocol for
2682 this is non-obvious, and was determined by
2683 using port-IO tracing in DOSemu and some
2684 experimentation here.
2686 Rather than using timed waits, use interrupts creatively.
2689 wavefront_should_cause_interrupt (WFC_NOOP,
2694 printk (KERN_WARNING LOGNAME
2695 "no post-OS interrupt.\n");
2699 /* Now, do it again ! */
2701 wavefront_should_cause_interrupt (WFC_NOOP,
2702 dev.data_port, (10*HZ));
2705 printk (KERN_WARNING LOGNAME
2706 "no post-OS interrupt(2).\n");
2710 /* OK, no (RX/TX) interrupts any more, but leave mute
2714 outb (0x80|0x40, dev.control_port);
2716 /* No need for the IRQ anymore */
2718 free_irq (dev.irq, &dev);
2722 if (dev.has_fx && fx_raw) {
2726 /* SETUPSND.EXE asks for sample memory config here, but since i
2727 have no idea how to interpret the result, we'll forget
2731 if ((dev.freemem = wavefront_freemem ()) < 0) {
2735 printk (KERN_INFO LOGNAME "available DRAM %dk\n", dev.freemem / 1024);
2737 if (wavefront_write (0xf0) ||
2738 wavefront_write (1) ||
2739 (wavefront_read () < 0)) {
2741 printk (KERN_WARNING LOGNAME "MPU emulation mode not set.\n");
2747 if (wavefront_cmd (WFC_SET_NVOICES, 0, voices)) {
2748 printk (KERN_WARNING LOGNAME
2749 "cannot set number of voices to 32.\n");
2757 /* reset that sucker so that it doesn't bother us. */
2759 outb (0x0, dev.control_port);
2760 dev.interrupts_on = 0;
2762 free_irq (dev.irq, &dev);
2767 static int __init wavefront_init (int atboot)
2769 int samples_are_from_rom;
2772 samples_are_from_rom = 1;
2774 /* XXX is this always true ? */
2775 samples_are_from_rom = 0;
2778 if (dev.israw || fx_raw) {
2779 if (wavefront_do_reset (atboot)) {
2784 wavefront_get_sample_status (samples_are_from_rom);
2785 wavefront_get_program_status ();
2786 wavefront_get_patch_status ();
2788 /* Start normal operation: unreset, master interrupt enabled, no mute
2791 outb (0x80|0x40|0x20, dev.control_port);
2796 static int __init install_wavefront (void)
2799 if ((dev.synth_dev = register_sound_synth (&wavefront_fops, -1)) < 0) {
2800 printk (KERN_ERR LOGNAME "cannot register raw synth\n");
2804 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2805 if ((dev.oss_dev = sound_alloc_synthdev()) == -1) {
2806 printk (KERN_ERR LOGNAME "Too many sequencers\n");
2809 synth_devs[dev.oss_dev] = &wavefront_operations;
2811 #endif /* OSS_SUPPORT_SEQ */
2813 if (wavefront_init (1) < 0) {
2814 printk (KERN_WARNING LOGNAME "initialization failed.\n");
2816 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2817 sound_unload_synthdev (dev.oss_dev);
2818 #endif /* OSS_SUPPORT_SEQ */
2823 request_region (dev.base+2, 6, "wavefront synth");
2826 request_region (dev.base+8, 8, "wavefront fx");
2829 if (wavefront_config_midi ()) {
2830 printk (KERN_WARNING LOGNAME "could not initialize MIDI.\n");
2836 static void __exit uninstall_wavefront (void)
2838 /* the first two i/o addresses are freed by the wf_mpu code */
2839 release_region (dev.base+2, 6);
2842 release_region (dev.base+8, 8);
2845 unregister_sound_synth (dev.synth_dev);
2847 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2848 sound_unload_synthdev (dev.oss_dev);
2849 #endif /* OSS_SUPPORT_SEQ */
2850 uninstall_wf_mpu ();
2853 /***********************************************************************/
2854 /* WaveFront FX control */
2855 /***********************************************************************/
2859 /* Control bits for the Load Control Register
2862 #define FX_LSB_TRANSFER 0x01 /* transfer after DSP LSB byte written */
2863 #define FX_MSB_TRANSFER 0x02 /* transfer after DSP MSB byte written */
2864 #define FX_AUTO_INCR 0x04 /* auto-increment DSP address after transfer */
2871 unsigned int x = 0x80;
2873 for (i = 0; i < 1000; i++) {
2874 x = inb (dev.fx_status);
2875 if ((x & 0x80) == 0) {
2881 printk (KERN_ERR LOGNAME "FX device never idle.\n");
2888 int __init detect_wffx (void)
2890 /* This is a crude check, but its the best one I have for now.
2891 Certainly on the Maui and the Tropez, wffx_idle() will
2892 report "never idle", which suggests that this test should
2896 if (inb (dev.fx_status) & 0x80) {
2897 printk (KERN_INFO LOGNAME "Hmm, probably a Maui or Tropez.\n");
2904 int __init attach_wffx (void)
2906 if ((dev.fx_mididev = sound_alloc_mididev ()) < 0) {
2907 printk (KERN_WARNING LOGNAME "cannot install FX Midi driver\n");
2915 wffx_mute (int onoff)
2922 outb (onoff ? 0x02 : 0x00, dev.fx_op);
2926 wffx_memset (int page,
2927 int addr, int cnt, unsigned short *data)
2929 if (page < 0 || page > 7) {
2930 printk (KERN_ERR LOGNAME "FX memset: "
2931 "page must be >= 0 and <= 7\n");
2935 if (addr < 0 || addr > 0x7f) {
2936 printk (KERN_ERR LOGNAME "FX memset: "
2937 "addr must be >= 0 and <= 7f\n");
2943 outb (FX_LSB_TRANSFER, dev.fx_lcr);
2944 outb (page, dev.fx_dsp_page);
2945 outb (addr, dev.fx_dsp_addr);
2946 outb ((data[0] >> 8), dev.fx_dsp_msb);
2947 outb ((data[0] & 0xff), dev.fx_dsp_lsb);
2949 printk (KERN_INFO LOGNAME "FX: addr %d:%x set to 0x%x\n",
2950 page, addr, data[0]);
2955 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
2956 outb (page, dev.fx_dsp_page);
2957 outb (addr, dev.fx_dsp_addr);
2959 for (i = 0; i < cnt; i++) {
2960 outb ((data[i] >> 8), dev.fx_dsp_msb);
2961 outb ((data[i] & 0xff), dev.fx_dsp_lsb);
2962 if (!wffx_idle ()) {
2968 printk (KERN_WARNING LOGNAME
2970 "(0x%x, 0x%x, 0x%x, %d) incomplete\n",
2971 page, addr, (int) data, cnt);
2980 wffx_ioctl (wavefront_fx_info *r)
2983 unsigned short page_data[256];
2986 switch (r->request) {
2988 wffx_mute (r->data[0]);
2993 if (r->data[2] <= 0) {
2994 printk (KERN_ERR LOGNAME "cannot write "
2995 "<= 0 bytes to FX\n");
2997 } else if (r->data[2] == 1) {
2998 pd = (unsigned short *) &r->data[3];
3000 if (r->data[2] > sizeof (page_data)) {
3001 printk (KERN_ERR LOGNAME "cannot write "
3002 "> 255 bytes to FX\n");
3005 if (copy_from_user(page_data,
3006 (unsigned char *)r->data[3],
3012 return wffx_memset (r->data[0], /* page */
3013 r->data[1], /* addr */
3014 r->data[2], /* cnt */
3018 printk (KERN_WARNING LOGNAME
3019 "FX: ioctl %d not yet supported\n",
3025 /* YSS225 initialization.
3027 This code was developed using DOSEMU. The Turtle Beach SETUPSND
3028 utility was run with I/O tracing in DOSEMU enabled, and a reconstruction
3029 of the port I/O done, using the Yamaha faxback document as a guide
3030 to add more logic to the code. Its really pretty weird.
3032 There was an alternative approach of just dumping the whole I/O
3033 sequence as a series of port/value pairs and a simple loop
3034 that output it. However, I hope that eventually I'll get more
3035 control over what this code does, and so I tried to stick with
3036 a somewhat "algorithmic" approach.
3039 static int __init wffx_init (void)
3044 /* Set all bits for all channels on the MOD unit to zero */
3045 /* XXX But why do this twice ? */
3047 for (j = 0; j < 2; j++) {
3048 for (i = 0x10; i <= 0xff; i++) {
3050 if (!wffx_idle ()) {
3054 outb (i, dev.fx_mod_addr);
3055 outb (0x0, dev.fx_mod_data);
3059 if (!wffx_idle()) return (-1);
3060 outb (0x02, dev.fx_op); /* mute on */
3062 if (!wffx_idle()) return (-1);
3063 outb (0x07, dev.fx_dsp_page);
3064 outb (0x44, dev.fx_dsp_addr);
3065 outb (0x00, dev.fx_dsp_msb);
3066 outb (0x00, dev.fx_dsp_lsb);
3067 if (!wffx_idle()) return (-1);
3068 outb (0x07, dev.fx_dsp_page);
3069 outb (0x42, dev.fx_dsp_addr);
3070 outb (0x00, dev.fx_dsp_msb);
3071 outb (0x00, dev.fx_dsp_lsb);
3072 if (!wffx_idle()) return (-1);
3073 outb (0x07, dev.fx_dsp_page);
3074 outb (0x43, dev.fx_dsp_addr);
3075 outb (0x00, dev.fx_dsp_msb);
3076 outb (0x00, dev.fx_dsp_lsb);
3077 if (!wffx_idle()) return (-1);
3078 outb (0x07, dev.fx_dsp_page);
3079 outb (0x7c, dev.fx_dsp_addr);
3080 outb (0x00, dev.fx_dsp_msb);
3081 outb (0x00, dev.fx_dsp_lsb);
3082 if (!wffx_idle()) return (-1);
3083 outb (0x07, dev.fx_dsp_page);
3084 outb (0x7e, dev.fx_dsp_addr);
3085 outb (0x00, dev.fx_dsp_msb);
3086 outb (0x00, dev.fx_dsp_lsb);
3087 if (!wffx_idle()) return (-1);
3088 outb (0x07, dev.fx_dsp_page);
3089 outb (0x46, dev.fx_dsp_addr);
3090 outb (0x00, dev.fx_dsp_msb);
3091 outb (0x00, dev.fx_dsp_lsb);
3092 if (!wffx_idle()) return (-1);
3093 outb (0x07, dev.fx_dsp_page);
3094 outb (0x49, dev.fx_dsp_addr);
3095 outb (0x00, dev.fx_dsp_msb);
3096 outb (0x00, dev.fx_dsp_lsb);
3097 if (!wffx_idle()) return (-1);
3098 outb (0x07, dev.fx_dsp_page);
3099 outb (0x47, dev.fx_dsp_addr);
3100 outb (0x00, dev.fx_dsp_msb);
3101 outb (0x00, dev.fx_dsp_lsb);
3102 if (!wffx_idle()) return (-1);
3103 outb (0x07, dev.fx_dsp_page);
3104 outb (0x4a, dev.fx_dsp_addr);
3105 outb (0x00, dev.fx_dsp_msb);
3106 outb (0x00, dev.fx_dsp_lsb);
3108 /* either because of stupidity by TB's programmers, or because it
3109 actually does something, rezero the MOD page.
3111 for (i = 0x10; i <= 0xff; i++) {
3113 if (!wffx_idle ()) {
3117 outb (i, dev.fx_mod_addr);
3118 outb (0x0, dev.fx_mod_data);
3120 /* load page zero */
3122 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3123 outb (0x00, dev.fx_dsp_page);
3124 outb (0x00, dev.fx_dsp_addr);
3126 for (i = 0; i < sizeof (page_zero); i += 2) {
3127 outb (page_zero[i], dev.fx_dsp_msb);
3128 outb (page_zero[i+1], dev.fx_dsp_lsb);
3129 if (!wffx_idle()) return (-1);
3132 /* Now load page one */
3134 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3135 outb (0x01, dev.fx_dsp_page);
3136 outb (0x00, dev.fx_dsp_addr);
3138 for (i = 0; i < sizeof (page_one); i += 2) {
3139 outb (page_one[i], dev.fx_dsp_msb);
3140 outb (page_one[i+1], dev.fx_dsp_lsb);
3141 if (!wffx_idle()) return (-1);
3144 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3145 outb (0x02, dev.fx_dsp_page);
3146 outb (0x00, dev.fx_dsp_addr);
3148 for (i = 0; i < sizeof (page_two); i++) {
3149 outb (page_two[i], dev.fx_dsp_lsb);
3150 if (!wffx_idle()) return (-1);
3153 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3154 outb (0x03, dev.fx_dsp_page);
3155 outb (0x00, dev.fx_dsp_addr);
3157 for (i = 0; i < sizeof (page_three); i++) {
3158 outb (page_three[i], dev.fx_dsp_lsb);
3159 if (!wffx_idle()) return (-1);
3162 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3163 outb (0x04, dev.fx_dsp_page);
3164 outb (0x00, dev.fx_dsp_addr);
3166 for (i = 0; i < sizeof (page_four); i++) {
3167 outb (page_four[i], dev.fx_dsp_lsb);
3168 if (!wffx_idle()) return (-1);
3171 /* Load memory area (page six) */
3173 outb (FX_LSB_TRANSFER, dev.fx_lcr);
3174 outb (0x06, dev.fx_dsp_page);
3176 for (i = 0; i < sizeof (page_six); i += 3) {
3177 outb (page_six[i], dev.fx_dsp_addr);
3178 outb (page_six[i+1], dev.fx_dsp_msb);
3179 outb (page_six[i+2], dev.fx_dsp_lsb);
3180 if (!wffx_idle()) return (-1);
3183 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3184 outb (0x07, dev.fx_dsp_page);
3185 outb (0x00, dev.fx_dsp_addr);
3187 for (i = 0; i < sizeof (page_seven); i += 2) {
3188 outb (page_seven[i], dev.fx_dsp_msb);
3189 outb (page_seven[i+1], dev.fx_dsp_lsb);
3190 if (!wffx_idle()) return (-1);
3193 /* Now setup the MOD area. We do this algorithmically in order to
3194 save a little data space. It could be done in the same fashion
3198 for (i = 0x00; i <= 0x0f; i++) {
3199 outb (0x01, dev.fx_mod_addr);
3200 outb (i, dev.fx_mod_data);
3201 if (!wffx_idle()) return (-1);
3202 outb (0x02, dev.fx_mod_addr);
3203 outb (0x00, dev.fx_mod_data);
3204 if (!wffx_idle()) return (-1);
3207 for (i = 0xb0; i <= 0xbf; i++) {
3208 outb (i, dev.fx_mod_addr);
3209 outb (0x20, dev.fx_mod_data);
3210 if (!wffx_idle()) return (-1);
3213 for (i = 0xf0; i <= 0xff; i++) {
3214 outb (i, dev.fx_mod_addr);
3215 outb (0x20, dev.fx_mod_data);
3216 if (!wffx_idle()) return (-1);
3219 for (i = 0x10; i <= 0x1d; i++) {
3220 outb (i, dev.fx_mod_addr);
3221 outb (0xff, dev.fx_mod_data);
3222 if (!wffx_idle()) return (-1);
3225 outb (0x1e, dev.fx_mod_addr);
3226 outb (0x40, dev.fx_mod_data);
3227 if (!wffx_idle()) return (-1);
3229 for (i = 0x1f; i <= 0x2d; i++) {
3230 outb (i, dev.fx_mod_addr);
3231 outb (0xff, dev.fx_mod_data);
3232 if (!wffx_idle()) return (-1);
3235 outb (0x2e, dev.fx_mod_addr);
3236 outb (0x00, dev.fx_mod_data);
3237 if (!wffx_idle()) return (-1);
3239 for (i = 0x2f; i <= 0x3e; i++) {
3240 outb (i, dev.fx_mod_addr);
3241 outb (0x00, dev.fx_mod_data);
3242 if (!wffx_idle()) return (-1);
3245 outb (0x3f, dev.fx_mod_addr);
3246 outb (0x20, dev.fx_mod_data);
3247 if (!wffx_idle()) return (-1);
3249 for (i = 0x40; i <= 0x4d; i++) {
3250 outb (i, dev.fx_mod_addr);
3251 outb (0x00, dev.fx_mod_data);
3252 if (!wffx_idle()) return (-1);
3255 outb (0x4e, dev.fx_mod_addr);
3256 outb (0x0e, dev.fx_mod_data);
3257 if (!wffx_idle()) return (-1);
3258 outb (0x4f, dev.fx_mod_addr);
3259 outb (0x0e, dev.fx_mod_data);
3260 if (!wffx_idle()) return (-1);
3263 for (i = 0x50; i <= 0x6b; i++) {
3264 outb (i, dev.fx_mod_addr);
3265 outb (0x00, dev.fx_mod_data);
3266 if (!wffx_idle()) return (-1);
3269 outb (0x6c, dev.fx_mod_addr);
3270 outb (0x40, dev.fx_mod_data);
3271 if (!wffx_idle()) return (-1);
3273 outb (0x6d, dev.fx_mod_addr);
3274 outb (0x00, dev.fx_mod_data);
3275 if (!wffx_idle()) return (-1);
3277 outb (0x6e, dev.fx_mod_addr);
3278 outb (0x40, dev.fx_mod_data);
3279 if (!wffx_idle()) return (-1);
3281 outb (0x6f, dev.fx_mod_addr);
3282 outb (0x40, dev.fx_mod_data);
3283 if (!wffx_idle()) return (-1);
3285 for (i = 0x70; i <= 0x7f; i++) {
3286 outb (i, dev.fx_mod_addr);
3287 outb (0xc0, dev.fx_mod_data);
3288 if (!wffx_idle()) return (-1);
3291 for (i = 0x80; i <= 0xaf; i++) {
3292 outb (i, dev.fx_mod_addr);
3293 outb (0x00, dev.fx_mod_data);
3294 if (!wffx_idle()) return (-1);
3297 for (i = 0xc0; i <= 0xdd; i++) {
3298 outb (i, dev.fx_mod_addr);
3299 outb (0x00, dev.fx_mod_data);
3300 if (!wffx_idle()) return (-1);
3303 outb (0xde, dev.fx_mod_addr);
3304 outb (0x10, dev.fx_mod_data);
3305 if (!wffx_idle()) return (-1);
3306 outb (0xdf, dev.fx_mod_addr);
3307 outb (0x10, dev.fx_mod_data);
3308 if (!wffx_idle()) return (-1);
3310 for (i = 0xe0; i <= 0xef; i++) {
3311 outb (i, dev.fx_mod_addr);
3312 outb (0x00, dev.fx_mod_data);
3313 if (!wffx_idle()) return (-1);
3316 for (i = 0x00; i <= 0x0f; i++) {
3317 outb (0x01, dev.fx_mod_addr);
3318 outb (i, dev.fx_mod_data);
3319 outb (0x02, dev.fx_mod_addr);
3320 outb (0x01, dev.fx_mod_data);
3321 if (!wffx_idle()) return (-1);
3324 outb (0x02, dev.fx_op); /* mute on */
3326 /* Now set the coefficients and so forth for the programs above */
3328 for (i = 0; i < sizeof (coefficients); i += 4) {
3329 outb (coefficients[i], dev.fx_dsp_page);
3330 outb (coefficients[i+1], dev.fx_dsp_addr);
3331 outb (coefficients[i+2], dev.fx_dsp_msb);
3332 outb (coefficients[i+3], dev.fx_dsp_lsb);
3333 if (!wffx_idle()) return (-1);
3336 /* Some settings (?) that are too small to bundle into loops */
3338 if (!wffx_idle()) return (-1);
3339 outb (0x1e, dev.fx_mod_addr);
3340 outb (0x14, dev.fx_mod_data);
3341 if (!wffx_idle()) return (-1);
3342 outb (0xde, dev.fx_mod_addr);
3343 outb (0x20, dev.fx_mod_data);
3344 if (!wffx_idle()) return (-1);
3345 outb (0xdf, dev.fx_mod_addr);
3346 outb (0x20, dev.fx_mod_data);
3348 /* some more coefficients */
3350 if (!wffx_idle()) return (-1);
3351 outb (0x06, dev.fx_dsp_page);
3352 outb (0x78, dev.fx_dsp_addr);
3353 outb (0x00, dev.fx_dsp_msb);
3354 outb (0x40, dev.fx_dsp_lsb);
3355 if (!wffx_idle()) return (-1);
3356 outb (0x07, dev.fx_dsp_page);
3357 outb (0x03, dev.fx_dsp_addr);
3358 outb (0x0f, dev.fx_dsp_msb);
3359 outb (0xff, dev.fx_dsp_lsb);
3360 if (!wffx_idle()) return (-1);
3361 outb (0x07, dev.fx_dsp_page);
3362 outb (0x0b, dev.fx_dsp_addr);
3363 outb (0x0f, dev.fx_dsp_msb);
3364 outb (0xff, dev.fx_dsp_lsb);
3365 if (!wffx_idle()) return (-1);
3366 outb (0x07, dev.fx_dsp_page);
3367 outb (0x02, dev.fx_dsp_addr);
3368 outb (0x00, dev.fx_dsp_msb);
3369 outb (0x00, dev.fx_dsp_lsb);
3370 if (!wffx_idle()) return (-1);
3371 outb (0x07, dev.fx_dsp_page);
3372 outb (0x0a, dev.fx_dsp_addr);
3373 outb (0x00, dev.fx_dsp_msb);
3374 outb (0x00, dev.fx_dsp_lsb);
3375 if (!wffx_idle()) return (-1);
3376 outb (0x07, dev.fx_dsp_page);
3377 outb (0x46, dev.fx_dsp_addr);
3378 outb (0x00, dev.fx_dsp_msb);
3379 outb (0x00, dev.fx_dsp_lsb);
3380 if (!wffx_idle()) return (-1);
3381 outb (0x07, dev.fx_dsp_page);
3382 outb (0x49, dev.fx_dsp_addr);
3383 outb (0x00, dev.fx_dsp_msb);
3384 outb (0x00, dev.fx_dsp_lsb);
3386 /* Now, for some strange reason, lets reload every page
3387 and all the coefficients over again. I have *NO* idea
3388 why this is done. I do know that no sound is produced
3389 is this phase is omitted.
3392 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3393 outb (0x00, dev.fx_dsp_page);
3394 outb (0x10, dev.fx_dsp_addr);
3396 for (i = 0; i < sizeof (page_zero_v2); i += 2) {
3397 outb (page_zero_v2[i], dev.fx_dsp_msb);
3398 outb (page_zero_v2[i+1], dev.fx_dsp_lsb);
3399 if (!wffx_idle()) return (-1);
3402 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3403 outb (0x01, dev.fx_dsp_page);
3404 outb (0x10, dev.fx_dsp_addr);
3406 for (i = 0; i < sizeof (page_one_v2); i += 2) {
3407 outb (page_one_v2[i], dev.fx_dsp_msb);
3408 outb (page_one_v2[i+1], dev.fx_dsp_lsb);
3409 if (!wffx_idle()) return (-1);
3412 if (!wffx_idle()) return (-1);
3413 if (!wffx_idle()) return (-1);
3415 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3416 outb (0x02, dev.fx_dsp_page);
3417 outb (0x10, dev.fx_dsp_addr);
3419 for (i = 0; i < sizeof (page_two_v2); i++) {
3420 outb (page_two_v2[i], dev.fx_dsp_lsb);
3421 if (!wffx_idle()) return (-1);
3423 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3424 outb (0x03, dev.fx_dsp_page);
3425 outb (0x10, dev.fx_dsp_addr);
3427 for (i = 0; i < sizeof (page_three_v2); i++) {
3428 outb (page_three_v2[i], dev.fx_dsp_lsb);
3429 if (!wffx_idle()) return (-1);
3432 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3433 outb (0x04, dev.fx_dsp_page);
3434 outb (0x10, dev.fx_dsp_addr);
3436 for (i = 0; i < sizeof (page_four_v2); i++) {
3437 outb (page_four_v2[i], dev.fx_dsp_lsb);
3438 if (!wffx_idle()) return (-1);
3441 outb (FX_LSB_TRANSFER, dev.fx_lcr);
3442 outb (0x06, dev.fx_dsp_page);
3444 /* Page six v.2 is algorithmic */
3446 for (i = 0x10; i <= 0x3e; i += 2) {
3447 outb (i, dev.fx_dsp_addr);
3448 outb (0x00, dev.fx_dsp_msb);
3449 outb (0x00, dev.fx_dsp_lsb);
3450 if (!wffx_idle()) return (-1);
3453 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3454 outb (0x07, dev.fx_dsp_page);
3455 outb (0x10, dev.fx_dsp_addr);
3457 for (i = 0; i < sizeof (page_seven_v2); i += 2) {
3458 outb (page_seven_v2[i], dev.fx_dsp_msb);
3459 outb (page_seven_v2[i+1], dev.fx_dsp_lsb);
3460 if (!wffx_idle()) return (-1);
3463 for (i = 0x00; i < sizeof(mod_v2); i += 2) {
3464 outb (mod_v2[i], dev.fx_mod_addr);
3465 outb (mod_v2[i+1], dev.fx_mod_data);
3466 if (!wffx_idle()) return (-1);
3469 for (i = 0; i < sizeof (coefficients2); i += 4) {
3470 outb (coefficients2[i], dev.fx_dsp_page);
3471 outb (coefficients2[i+1], dev.fx_dsp_addr);
3472 outb (coefficients2[i+2], dev.fx_dsp_msb);
3473 outb (coefficients2[i+3], dev.fx_dsp_lsb);
3474 if (!wffx_idle()) return (-1);
3477 for (i = 0; i < sizeof (coefficients3); i += 2) {
3480 outb (0x07, dev.fx_dsp_page);
3481 x = (i % 4) ? 0x4e : 0x4c;
3482 outb (x, dev.fx_dsp_addr);
3483 outb (coefficients3[i], dev.fx_dsp_msb);
3484 outb (coefficients3[i+1], dev.fx_dsp_lsb);
3487 outb (0x00, dev.fx_op); /* mute off */
3488 if (!wffx_idle()) return (-1);
3494 static int irq = -1;
3496 MODULE_AUTHOR ("Paul Barton-Davis <pbd@op.net>");
3497 MODULE_DESCRIPTION ("Turtle Beach WaveFront Linux Driver");
3498 MODULE_LICENSE("GPL");
3499 MODULE_PARM (io,"i");
3500 MODULE_PARM (irq,"i");
3502 static int __init init_wavfront (void)
3504 printk ("Turtle Beach WaveFront Driver\n"
3505 "Copyright (C) by Hannu Solvainen, "
3506 "Paul Barton-Davis 1993-1998.\n");
3508 /* XXX t'would be lovely to ask the CS4232 for these values, eh ? */
3510 if (io == -1 || irq == -1) {
3511 printk (KERN_INFO LOGNAME "irq and io options must be set.\n");
3515 if (wavefront_interrupt_bits (irq) < 0) {
3516 printk (KERN_INFO LOGNAME
3517 "IRQ must be 9, 5, 12 or 15 (not %d)\n", irq);
3521 if (detect_wavefront (irq, io) < 0) {
3525 if (install_wavefront () < 0) {
3532 static void __exit cleanup_wavfront (void)
3534 uninstall_wavefront ();
3537 module_init(init_wavfront);
3538 module_exit(cleanup_wavfront);