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, 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,
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 *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 __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((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 __user *) arg, sizeof (wc)))
1946 if ((err = wavefront_synth_control (cmd, &wc)) == 0) {
1947 if (copy_to_user ((void __user *) arg, &wc, sizeof (wc)))
1953 case WFCTL_LOAD_SPP:
1954 return wavefront_load_patch ((const char __user *) 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, void __user * arg)
2004 wavefront_control wc;
2008 case SNDCTL_SYNTH_INFO:
2009 if(copy_to_user(arg, &wavefront_info, sizeof (wavefront_info)))
2013 case SNDCTL_SEQ_RESETSAMPLES:
2014 // printk (KERN_WARNING LOGNAME "driver cannot reset samples.\n");
2015 return 0; /* don't force an error */
2017 case SNDCTL_SEQ_PERCMODE:
2018 return 0; /* don't force an error */
2020 case SNDCTL_SYNTH_MEMAVL:
2021 if ((dev.freemem = wavefront_freemem ()) < 0) {
2022 printk (KERN_ERR LOGNAME "cannot get memory size\n");
2029 case SNDCTL_SYNTH_CONTROL:
2030 if(copy_from_user (&wc, arg, sizeof (wc)))
2032 else if ((err = wavefront_synth_control (cmd, &wc)) == 0) {
2033 if(copy_to_user (arg, &wc, sizeof (wc)))
2045 wavefront_oss_load_patch (int devno, int format, const char __user *addr,
2046 int offs, int count, int pmgr_flag)
2049 if (format == SYSEX_PATCH) { /* Handled by midi_synth.c */
2050 if (midi_load_patch == NULL) {
2051 printk (KERN_ERR LOGNAME
2052 "SYSEX not loadable: "
2053 "no midi patch loader!\n");
2057 return midi_load_patch (devno, format, addr,
2058 offs, count, pmgr_flag);
2060 } else if (format == GUS_PATCH) {
2061 return wavefront_load_gus_patch (devno, format,
2062 addr, offs, count, pmgr_flag);
2064 } else if (format != WAVEFRONT_PATCH) {
2065 printk (KERN_ERR LOGNAME "unknown patch format %d\n", format);
2069 if (count < sizeof (wavefront_patch_info)) {
2070 printk (KERN_ERR LOGNAME "sample header too short\n");
2074 /* "addr" points to a user-space wavefront_patch_info */
2076 return wavefront_load_patch (addr);
2079 static struct synth_operations wavefront_operations =
2081 .owner = THIS_MODULE,
2083 .info = &wavefront_info,
2085 .synth_type = SYNTH_TYPE_SAMPLE,
2086 .synth_subtype = SAMPLE_TYPE_WAVEFRONT,
2087 .open = wavefront_oss_open,
2088 .close = wavefront_oss_close,
2089 .ioctl = wavefront_oss_ioctl,
2090 .kill_note = midi_synth_kill_note,
2091 .start_note = midi_synth_start_note,
2092 .set_instr = midi_synth_set_instr,
2093 .reset = midi_synth_reset,
2094 .load_patch = midi_synth_load_patch,
2095 .aftertouch = midi_synth_aftertouch,
2096 .controller = midi_synth_controller,
2097 .panning = midi_synth_panning,
2098 .bender = midi_synth_bender,
2099 .setup_voice = midi_synth_setup_voice
2101 #endif /* OSS_SUPPORT_SEQ */
2103 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_STATIC_INSTALL
2105 static void __init attach_wavefront (struct address_info *hw_config)
2107 (void) install_wavefront ();
2110 static int __init probe_wavefront (struct address_info *hw_config)
2112 return !detect_wavefront (hw_config->irq, hw_config->io_base);
2115 static void __exit unload_wavefront (struct address_info *hw_config)
2117 (void) uninstall_wavefront ();
2120 #endif /* OSS_SUPPORT_STATIC_INSTALL */
2122 /***********************************************************************/
2123 /* WaveFront: Linux modular sound kernel installation interface */
2124 /***********************************************************************/
2127 wavefrontintr(int irq, void *dev_id, struct pt_regs *dummy)
2129 struct wf_config *hw = dev_id;
2132 Some comments on interrupts. I attempted a version of this
2133 driver that used interrupts throughout the code instead of
2134 doing busy and/or sleep-waiting. Alas, it appears that once
2135 the Motorola firmware is downloaded, the card *never*
2136 generates an RX interrupt. These are successfully generated
2137 during firmware loading, and after that wavefront_status()
2138 reports that an interrupt is pending on the card from time
2139 to time, but it never seems to be delivered to this
2140 driver. Note also that wavefront_status() continues to
2141 report that RX interrupts are enabled, suggesting that I
2142 didn't goof up and disable them by mistake.
2144 Thus, I stepped back to a prior version of
2145 wavefront_wait(), the only place where this really
2146 matters. Its sad, but I've looked through the code to check
2147 on things, and I really feel certain that the Motorola
2148 firmware prevents RX-ready interrupts.
2151 if ((wavefront_status() & (STAT_INTR_READ|STAT_INTR_WRITE)) == 0) {
2157 wake_up_interruptible (&hw->interrupt_sleeper);
2163 0 Host Rx Interrupt Enable (1=Enabled)
2164 1 Host Rx Register Full (1=Full)
2165 2 Host Rx Interrupt Pending (1=Interrupt)
2167 4 Host Tx Interrupt (1=Enabled)
2168 5 Host Tx Register empty (1=Empty)
2169 6 Host Tx Interrupt Pending (1=Interrupt)
2174 wavefront_interrupt_bits (int irq)
2194 printk (KERN_WARNING LOGNAME "invalid IRQ %d\n", irq);
2202 wavefront_should_cause_interrupt (int val, int port, int timeout)
2205 unsigned long flags;
2207 /* this will not help on SMP - but at least it compiles */
2208 spin_lock_irqsave(&lock, flags);
2211 interruptible_sleep_on_timeout (&dev.interrupt_sleeper, timeout);
2212 spin_unlock_irqrestore(&lock,flags);
2215 static int __init wavefront_hw_reset (void)
2219 unsigned long irq_mask;
2222 /* IRQ already checked in init_module() */
2224 bits = wavefront_interrupt_bits (dev.irq);
2226 printk (KERN_DEBUG LOGNAME "autodetecting WaveFront IRQ\n");
2228 irq_mask = probe_irq_on ();
2230 outb (0x0, dev.control_port);
2231 outb (0x80 | 0x40 | bits, dev.data_port);
2232 wavefront_should_cause_interrupt(0x80|0x40|0x10|0x1,
2234 (reset_time*HZ)/100);
2236 reported_irq = probe_irq_off (irq_mask);
2238 if (reported_irq != dev.irq) {
2239 if (reported_irq == 0) {
2240 printk (KERN_ERR LOGNAME
2241 "No unassigned interrupts detected "
2242 "after h/w reset\n");
2243 } else if (reported_irq < 0) {
2244 printk (KERN_ERR LOGNAME
2245 "Multiple unassigned interrupts detected "
2246 "after h/w reset\n");
2248 printk (KERN_ERR LOGNAME "autodetected IRQ %d not the "
2249 "value provided (%d)\n", reported_irq,
2255 printk (KERN_INFO LOGNAME "autodetected IRQ at %d\n",
2259 if (request_irq (dev.irq, wavefrontintr,
2260 SA_INTERRUPT|SA_SHIRQ,
2261 "wavefront synth", &dev) < 0) {
2262 printk (KERN_WARNING LOGNAME "IRQ %d not available!\n",
2267 /* try reset of port */
2269 outb (0x0, dev.control_port);
2271 /* At this point, the board is in reset, and the H/W initialization
2272 register is accessed at the same address as the data port.
2274 Bit 7 - Enable IRQ Driver
2275 0 - Tri-state the Wave-Board drivers for the PC Bus IRQs
2276 1 - Enable IRQ selected by bits 5:3 to be driven onto the PC Bus.
2278 Bit 6 - MIDI Interface Select
2280 0 - Use the MIDI Input from the 26-pin WaveBlaster
2281 compatible header as the serial MIDI source
2282 1 - Use the MIDI Input from the 9-pin D connector as the
2285 Bits 5:3 - IRQ Selection
2296 Bit 0 - Disable Boot ROM
2297 0 - memory accesses to 03FC30-03FFFFH utilize the internal Boot ROM
2298 1 - memory accesses to 03FC30-03FFFFH are directed to external
2303 /* configure hardware: IRQ, enable interrupts,
2304 plus external 9-pin MIDI interface selected
2307 outb (0x80 | 0x40 | bits, dev.data_port);
2311 0 Host Rx Interrupt Enable (1=Enabled) 0x1
2315 4 Host Tx Interrupt Enable 0x10
2316 5 Mute (0=Mute; 1=Play) 0x20
2317 6 Master Interrupt Enable (1=Enabled) 0x40
2318 7 Master Reset (0=Reset; 1=Run) 0x80
2320 Take us out of reset, mute output, master + TX + RX interrupts on.
2322 We'll get an interrupt presumably to tell us that the TX
2326 wavefront_should_cause_interrupt(0x80|0x40|0x10|0x1,
2328 (reset_time*HZ)/100);
2330 /* Note: data port is now the data port, not the h/w initialization
2335 printk (KERN_WARNING LOGNAME
2336 "intr not received after h/w un-reset.\n");
2340 dev.interrupts_on = 1;
2342 /* Note: data port is now the data port, not the h/w initialization
2345 At this point, only "HW VERSION" or "DOWNLOAD OS" commands
2346 will work. So, issue one of them, and wait for TX
2347 interrupt. This can take a *long* time after a cold boot,
2348 while the ISC ROM does its RAM test. The SDK says up to 4
2349 seconds - with 12MB of RAM on a Tropez+, it takes a lot
2350 longer than that (~16secs). Note that the card understands
2351 the difference between a warm and a cold boot, so
2352 subsequent ISC2115 reboots (say, caused by module
2353 reloading) will get through this much faster.
2355 XXX Interesting question: why is no RX interrupt received first ?
2358 wavefront_should_cause_interrupt(WFC_HARDWARE_VERSION,
2359 dev.data_port, ramcheck_time*HZ);
2362 printk (KERN_WARNING LOGNAME
2363 "post-RAM-check interrupt not received.\n");
2367 if (!wavefront_wait (STAT_CAN_READ)) {
2368 printk (KERN_WARNING LOGNAME
2369 "no response to HW version cmd.\n");
2373 if ((hwv[0] = wavefront_read ()) == -1) {
2374 printk (KERN_WARNING LOGNAME
2375 "board not responding correctly.\n");
2379 if (hwv[0] == 0xFF) { /* NAK */
2381 /* Board's RAM test failed. Try to read error code,
2382 and tell us about it either way.
2385 if ((hwv[0] = wavefront_read ()) == -1) {
2386 printk (KERN_WARNING LOGNAME "on-board RAM test failed "
2387 "(bad error code).\n");
2389 printk (KERN_WARNING LOGNAME "on-board RAM test failed "
2390 "(error code: 0x%x).\n",
2396 /* We're OK, just get the next byte of the HW version response */
2398 if ((hwv[1] = wavefront_read ()) == -1) {
2399 printk (KERN_WARNING LOGNAME "incorrect h/w response.\n");
2403 printk (KERN_INFO LOGNAME "hardware version %d.%d\n",
2411 free_irq (dev.irq, &dev);
2417 static int __init detect_wavefront (int irq, int io_base)
2419 unsigned char rbuf[4], wbuf[4];
2421 /* TB docs say the device takes up 8 ports, but we know that
2422 if there is an FX device present (i.e. a Tropez+) it really
2426 if (check_region (io_base, 16)) {
2427 printk (KERN_ERR LOGNAME "IO address range 0x%x - 0x%x "
2428 "already in use - ignored\n", dev.base,
2436 dev.debug = debug_default;
2437 dev.interrupts_on = 0;
2439 dev.rom_samples_rdonly = 1; /* XXX default lock on ROM sample slots */
2441 if (wavefront_cmd (WFC_FIRMWARE_VERSION, rbuf, wbuf) == 0) {
2443 dev.fw_version[0] = rbuf[0];
2444 dev.fw_version[1] = rbuf[1];
2445 printk (KERN_INFO LOGNAME
2446 "firmware %d.%d already loaded.\n",
2449 /* check that a command actually works */
2451 if (wavefront_cmd (WFC_HARDWARE_VERSION,
2453 dev.hw_version[0] = rbuf[0];
2454 dev.hw_version[1] = rbuf[1];
2456 printk (KERN_WARNING LOGNAME "not raw, but no "
2457 "hardware version!\n");
2464 printk (KERN_INFO LOGNAME
2465 "reloading firmware anyway.\n");
2472 printk (KERN_INFO LOGNAME
2473 "no response to firmware probe, assume raw.\n");
2477 init_waitqueue_head (&dev.interrupt_sleeper);
2479 if (wavefront_hw_reset ()) {
2480 printk (KERN_WARNING LOGNAME "hardware reset failed\n");
2484 /* Check for FX device, present only on Tropez+ */
2486 dev.has_fx = (detect_wffx () == 0);
2492 #include <linux/fs.h>
2493 #include <linux/mm.h>
2494 #include <linux/slab.h>
2495 #include <asm/uaccess.h>
2499 wavefront_download_firmware (char *path)
2502 unsigned char section[WF_SECTION_MAX];
2503 char section_length; /* yes, just a char; max value is WF_SECTION_MAX */
2504 int section_cnt_downloaded = 0;
2510 /* This tries to be a bit cleverer than the stuff Alan Cox did for
2511 the generic sound firmware, in that it actually knows
2512 something about the structure of the Motorola firmware. In
2513 particular, it uses a version that has been stripped of the
2514 20K of useless header information, and had section lengths
2515 added, making it possible to load the entire OS without any
2516 [kv]malloc() activity, since the longest entity we ever read is
2517 42 bytes (well, WF_SECTION_MAX) long.
2523 if ((fd = sys_open (path, 0, 0)) < 0) {
2524 printk (KERN_WARNING LOGNAME "Unable to load \"%s\".\n",
2532 if ((x = sys_read (fd, §ion_length, sizeof (section_length))) !=
2533 sizeof (section_length)) {
2534 printk (KERN_ERR LOGNAME "firmware read error.\n");
2538 if (section_length == 0) {
2542 if (sys_read (fd, section, section_length) != section_length) {
2543 printk (KERN_ERR LOGNAME "firmware section "
2550 if (wavefront_write (WFC_DOWNLOAD_OS)) {
2554 for (i = 0; i < section_length; i++) {
2555 if (wavefront_write (section[i])) {
2562 if (wavefront_wait (STAT_CAN_READ)) {
2564 if ((c = inb (dev.data_port)) != WF_ACK) {
2566 printk (KERN_ERR LOGNAME "download "
2567 "of section #%d not "
2568 "acknowledged, ack = 0x%x\n",
2569 section_cnt_downloaded + 1, c);
2575 printk (KERN_ERR LOGNAME "time out for firmware ACK.\n");
2588 printk (KERN_ERR "\nWaveFront: firmware download failed!!!\n");
2592 static int __init wavefront_config_midi (void)
2594 unsigned char rbuf[4], wbuf[4];
2596 if (detect_wf_mpu (dev.irq, dev.base) < 0) {
2597 printk (KERN_WARNING LOGNAME
2598 "could not find working MIDI device\n");
2602 if ((dev.mididev = install_wf_mpu ()) < 0) {
2603 printk (KERN_WARNING LOGNAME
2604 "MIDI interfaces not configured\n");
2608 /* Route external MIDI to WaveFront synth (by default) */
2610 if (wavefront_cmd (WFC_MISYNTH_ON, rbuf, wbuf)) {
2611 printk (KERN_WARNING LOGNAME
2612 "cannot enable MIDI-IN to synth routing.\n");
2617 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2618 /* Get the regular MIDI patch loading function, so we can
2619 use it if we ever get handed a SYSEX patch. This is
2620 unlikely, because its so damn slow, but we may as well
2621 leave this functionality from maui.c behind, since it
2622 could be useful for sequencer applications that can
2623 only use MIDI to do patch loading.
2626 if (midi_devs[dev.mididev]->converter != NULL) {
2627 midi_load_patch = midi_devs[dev.mididev]->converter->load_patch;
2628 midi_devs[dev.mididev]->converter->load_patch =
2629 &wavefront_oss_load_patch;
2632 #endif /* OSS_SUPPORT_SEQ */
2634 /* Turn on Virtual MIDI, but first *always* turn it off,
2635 since otherwise consectutive reloads of the driver will
2636 never cause the hardware to generate the initial "internal" or
2637 "external" source bytes in the MIDI data stream. This
2638 is pretty important, since the internal hardware generally will
2639 be used to generate none or very little MIDI output, and
2640 thus the only source of MIDI data is actually external. Without
2641 the switch bytes, the driver will think it all comes from
2642 the internal interface. Duh.
2645 if (wavefront_cmd (WFC_VMIDI_OFF, rbuf, wbuf)) {
2646 printk (KERN_WARNING LOGNAME
2647 "virtual MIDI mode not disabled\n");
2648 return 0; /* We're OK, but missing the external MIDI dev */
2651 if ((dev.ext_mididev = virtual_midi_enable ()) < 0) {
2652 printk (KERN_WARNING LOGNAME "no virtual MIDI access.\n");
2654 if (wavefront_cmd (WFC_VMIDI_ON, rbuf, wbuf)) {
2655 printk (KERN_WARNING LOGNAME
2656 "cannot enable virtual MIDI mode.\n");
2657 virtual_midi_disable ();
2664 static int __init wavefront_do_reset (int atboot)
2668 if (!atboot && wavefront_hw_reset ()) {
2669 printk (KERN_WARNING LOGNAME "hw reset failed.\n");
2674 if (wavefront_download_firmware (ospath)) {
2680 /* Wait for the OS to get running. The protocol for
2681 this is non-obvious, and was determined by
2682 using port-IO tracing in DOSemu and some
2683 experimentation here.
2685 Rather than using timed waits, use interrupts creatively.
2688 wavefront_should_cause_interrupt (WFC_NOOP,
2693 printk (KERN_WARNING LOGNAME
2694 "no post-OS interrupt.\n");
2698 /* Now, do it again ! */
2700 wavefront_should_cause_interrupt (WFC_NOOP,
2701 dev.data_port, (10*HZ));
2704 printk (KERN_WARNING LOGNAME
2705 "no post-OS interrupt(2).\n");
2709 /* OK, no (RX/TX) interrupts any more, but leave mute
2713 outb (0x80|0x40, dev.control_port);
2715 /* No need for the IRQ anymore */
2717 free_irq (dev.irq, &dev);
2721 if (dev.has_fx && fx_raw) {
2725 /* SETUPSND.EXE asks for sample memory config here, but since i
2726 have no idea how to interpret the result, we'll forget
2730 if ((dev.freemem = wavefront_freemem ()) < 0) {
2734 printk (KERN_INFO LOGNAME "available DRAM %dk\n", dev.freemem / 1024);
2736 if (wavefront_write (0xf0) ||
2737 wavefront_write (1) ||
2738 (wavefront_read () < 0)) {
2740 printk (KERN_WARNING LOGNAME "MPU emulation mode not set.\n");
2746 if (wavefront_cmd (WFC_SET_NVOICES, 0, voices)) {
2747 printk (KERN_WARNING LOGNAME
2748 "cannot set number of voices to 32.\n");
2756 /* reset that sucker so that it doesn't bother us. */
2758 outb (0x0, dev.control_port);
2759 dev.interrupts_on = 0;
2761 free_irq (dev.irq, &dev);
2766 static int __init wavefront_init (int atboot)
2768 int samples_are_from_rom;
2771 samples_are_from_rom = 1;
2773 /* XXX is this always true ? */
2774 samples_are_from_rom = 0;
2777 if (dev.israw || fx_raw) {
2778 if (wavefront_do_reset (atboot)) {
2783 wavefront_get_sample_status (samples_are_from_rom);
2784 wavefront_get_program_status ();
2785 wavefront_get_patch_status ();
2787 /* Start normal operation: unreset, master interrupt enabled, no mute
2790 outb (0x80|0x40|0x20, dev.control_port);
2795 static int __init install_wavefront (void)
2798 if ((dev.synth_dev = register_sound_synth (&wavefront_fops, -1)) < 0) {
2799 printk (KERN_ERR LOGNAME "cannot register raw synth\n");
2803 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2804 if ((dev.oss_dev = sound_alloc_synthdev()) == -1) {
2805 printk (KERN_ERR LOGNAME "Too many sequencers\n");
2808 synth_devs[dev.oss_dev] = &wavefront_operations;
2810 #endif /* OSS_SUPPORT_SEQ */
2812 if (wavefront_init (1) < 0) {
2813 printk (KERN_WARNING LOGNAME "initialization failed.\n");
2815 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2816 sound_unload_synthdev (dev.oss_dev);
2817 #endif /* OSS_SUPPORT_SEQ */
2822 request_region (dev.base+2, 6, "wavefront synth");
2825 request_region (dev.base+8, 8, "wavefront fx");
2828 if (wavefront_config_midi ()) {
2829 printk (KERN_WARNING LOGNAME "could not initialize MIDI.\n");
2835 static void __exit uninstall_wavefront (void)
2837 /* the first two i/o addresses are freed by the wf_mpu code */
2838 release_region (dev.base+2, 6);
2841 release_region (dev.base+8, 8);
2844 unregister_sound_synth (dev.synth_dev);
2846 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2847 sound_unload_synthdev (dev.oss_dev);
2848 #endif /* OSS_SUPPORT_SEQ */
2849 uninstall_wf_mpu ();
2852 /***********************************************************************/
2853 /* WaveFront FX control */
2854 /***********************************************************************/
2858 /* Control bits for the Load Control Register
2861 #define FX_LSB_TRANSFER 0x01 /* transfer after DSP LSB byte written */
2862 #define FX_MSB_TRANSFER 0x02 /* transfer after DSP MSB byte written */
2863 #define FX_AUTO_INCR 0x04 /* auto-increment DSP address after transfer */
2870 unsigned int x = 0x80;
2872 for (i = 0; i < 1000; i++) {
2873 x = inb (dev.fx_status);
2874 if ((x & 0x80) == 0) {
2880 printk (KERN_ERR LOGNAME "FX device never idle.\n");
2887 int __init detect_wffx (void)
2889 /* This is a crude check, but its the best one I have for now.
2890 Certainly on the Maui and the Tropez, wffx_idle() will
2891 report "never idle", which suggests that this test should
2895 if (inb (dev.fx_status) & 0x80) {
2896 printk (KERN_INFO LOGNAME "Hmm, probably a Maui or Tropez.\n");
2903 int __init attach_wffx (void)
2905 if ((dev.fx_mididev = sound_alloc_mididev ()) < 0) {
2906 printk (KERN_WARNING LOGNAME "cannot install FX Midi driver\n");
2914 wffx_mute (int onoff)
2921 outb (onoff ? 0x02 : 0x00, dev.fx_op);
2925 wffx_memset (int page,
2926 int addr, int cnt, unsigned short *data)
2928 if (page < 0 || page > 7) {
2929 printk (KERN_ERR LOGNAME "FX memset: "
2930 "page must be >= 0 and <= 7\n");
2934 if (addr < 0 || addr > 0x7f) {
2935 printk (KERN_ERR LOGNAME "FX memset: "
2936 "addr must be >= 0 and <= 7f\n");
2942 outb (FX_LSB_TRANSFER, dev.fx_lcr);
2943 outb (page, dev.fx_dsp_page);
2944 outb (addr, dev.fx_dsp_addr);
2945 outb ((data[0] >> 8), dev.fx_dsp_msb);
2946 outb ((data[0] & 0xff), dev.fx_dsp_lsb);
2948 printk (KERN_INFO LOGNAME "FX: addr %d:%x set to 0x%x\n",
2949 page, addr, data[0]);
2954 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
2955 outb (page, dev.fx_dsp_page);
2956 outb (addr, dev.fx_dsp_addr);
2958 for (i = 0; i < cnt; i++) {
2959 outb ((data[i] >> 8), dev.fx_dsp_msb);
2960 outb ((data[i] & 0xff), dev.fx_dsp_lsb);
2961 if (!wffx_idle ()) {
2967 printk (KERN_WARNING LOGNAME
2969 "(0x%x, 0x%x, 0x%x, %d) incomplete\n",
2970 page, addr, (int) data, cnt);
2979 wffx_ioctl (wavefront_fx_info *r)
2982 unsigned short page_data[256];
2985 switch (r->request) {
2987 wffx_mute (r->data[0]);
2992 if (r->data[2] <= 0) {
2993 printk (KERN_ERR LOGNAME "cannot write "
2994 "<= 0 bytes to FX\n");
2996 } else if (r->data[2] == 1) {
2997 pd = (unsigned short *) &r->data[3];
2999 if (r->data[2] > sizeof (page_data)) {
3000 printk (KERN_ERR LOGNAME "cannot write "
3001 "> 255 bytes to FX\n");
3004 if (copy_from_user(page_data,
3005 (unsigned char *)r->data[3],
3011 return wffx_memset (r->data[0], /* page */
3012 r->data[1], /* addr */
3013 r->data[2], /* cnt */
3017 printk (KERN_WARNING LOGNAME
3018 "FX: ioctl %d not yet supported\n",
3024 /* YSS225 initialization.
3026 This code was developed using DOSEMU. The Turtle Beach SETUPSND
3027 utility was run with I/O tracing in DOSEMU enabled, and a reconstruction
3028 of the port I/O done, using the Yamaha faxback document as a guide
3029 to add more logic to the code. Its really pretty weird.
3031 There was an alternative approach of just dumping the whole I/O
3032 sequence as a series of port/value pairs and a simple loop
3033 that output it. However, I hope that eventually I'll get more
3034 control over what this code does, and so I tried to stick with
3035 a somewhat "algorithmic" approach.
3038 static int __init wffx_init (void)
3043 /* Set all bits for all channels on the MOD unit to zero */
3044 /* XXX But why do this twice ? */
3046 for (j = 0; j < 2; j++) {
3047 for (i = 0x10; i <= 0xff; i++) {
3049 if (!wffx_idle ()) {
3053 outb (i, dev.fx_mod_addr);
3054 outb (0x0, dev.fx_mod_data);
3058 if (!wffx_idle()) return (-1);
3059 outb (0x02, dev.fx_op); /* mute on */
3061 if (!wffx_idle()) return (-1);
3062 outb (0x07, dev.fx_dsp_page);
3063 outb (0x44, 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 (0x42, 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 (0x43, 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 (0x7c, 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 (0x7e, 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 (0x46, 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 (0x49, 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 (0x47, dev.fx_dsp_addr);
3099 outb (0x00, dev.fx_dsp_msb);
3100 outb (0x00, dev.fx_dsp_lsb);
3101 if (!wffx_idle()) return (-1);
3102 outb (0x07, dev.fx_dsp_page);
3103 outb (0x4a, dev.fx_dsp_addr);
3104 outb (0x00, dev.fx_dsp_msb);
3105 outb (0x00, dev.fx_dsp_lsb);
3107 /* either because of stupidity by TB's programmers, or because it
3108 actually does something, rezero the MOD page.
3110 for (i = 0x10; i <= 0xff; i++) {
3112 if (!wffx_idle ()) {
3116 outb (i, dev.fx_mod_addr);
3117 outb (0x0, dev.fx_mod_data);
3119 /* load page zero */
3121 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3122 outb (0x00, dev.fx_dsp_page);
3123 outb (0x00, dev.fx_dsp_addr);
3125 for (i = 0; i < sizeof (page_zero); i += 2) {
3126 outb (page_zero[i], dev.fx_dsp_msb);
3127 outb (page_zero[i+1], dev.fx_dsp_lsb);
3128 if (!wffx_idle()) return (-1);
3131 /* Now load page one */
3133 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3134 outb (0x01, dev.fx_dsp_page);
3135 outb (0x00, dev.fx_dsp_addr);
3137 for (i = 0; i < sizeof (page_one); i += 2) {
3138 outb (page_one[i], dev.fx_dsp_msb);
3139 outb (page_one[i+1], dev.fx_dsp_lsb);
3140 if (!wffx_idle()) return (-1);
3143 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3144 outb (0x02, dev.fx_dsp_page);
3145 outb (0x00, dev.fx_dsp_addr);
3147 for (i = 0; i < sizeof (page_two); i++) {
3148 outb (page_two[i], dev.fx_dsp_lsb);
3149 if (!wffx_idle()) return (-1);
3152 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3153 outb (0x03, dev.fx_dsp_page);
3154 outb (0x00, dev.fx_dsp_addr);
3156 for (i = 0; i < sizeof (page_three); i++) {
3157 outb (page_three[i], dev.fx_dsp_lsb);
3158 if (!wffx_idle()) return (-1);
3161 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3162 outb (0x04, dev.fx_dsp_page);
3163 outb (0x00, dev.fx_dsp_addr);
3165 for (i = 0; i < sizeof (page_four); i++) {
3166 outb (page_four[i], dev.fx_dsp_lsb);
3167 if (!wffx_idle()) return (-1);
3170 /* Load memory area (page six) */
3172 outb (FX_LSB_TRANSFER, dev.fx_lcr);
3173 outb (0x06, dev.fx_dsp_page);
3175 for (i = 0; i < sizeof (page_six); i += 3) {
3176 outb (page_six[i], dev.fx_dsp_addr);
3177 outb (page_six[i+1], dev.fx_dsp_msb);
3178 outb (page_six[i+2], dev.fx_dsp_lsb);
3179 if (!wffx_idle()) return (-1);
3182 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3183 outb (0x07, dev.fx_dsp_page);
3184 outb (0x00, dev.fx_dsp_addr);
3186 for (i = 0; i < sizeof (page_seven); i += 2) {
3187 outb (page_seven[i], dev.fx_dsp_msb);
3188 outb (page_seven[i+1], dev.fx_dsp_lsb);
3189 if (!wffx_idle()) return (-1);
3192 /* Now setup the MOD area. We do this algorithmically in order to
3193 save a little data space. It could be done in the same fashion
3197 for (i = 0x00; i <= 0x0f; i++) {
3198 outb (0x01, dev.fx_mod_addr);
3199 outb (i, dev.fx_mod_data);
3200 if (!wffx_idle()) return (-1);
3201 outb (0x02, dev.fx_mod_addr);
3202 outb (0x00, dev.fx_mod_data);
3203 if (!wffx_idle()) return (-1);
3206 for (i = 0xb0; i <= 0xbf; i++) {
3207 outb (i, dev.fx_mod_addr);
3208 outb (0x20, dev.fx_mod_data);
3209 if (!wffx_idle()) return (-1);
3212 for (i = 0xf0; i <= 0xff; i++) {
3213 outb (i, dev.fx_mod_addr);
3214 outb (0x20, dev.fx_mod_data);
3215 if (!wffx_idle()) return (-1);
3218 for (i = 0x10; i <= 0x1d; i++) {
3219 outb (i, dev.fx_mod_addr);
3220 outb (0xff, dev.fx_mod_data);
3221 if (!wffx_idle()) return (-1);
3224 outb (0x1e, dev.fx_mod_addr);
3225 outb (0x40, dev.fx_mod_data);
3226 if (!wffx_idle()) return (-1);
3228 for (i = 0x1f; i <= 0x2d; i++) {
3229 outb (i, dev.fx_mod_addr);
3230 outb (0xff, dev.fx_mod_data);
3231 if (!wffx_idle()) return (-1);
3234 outb (0x2e, dev.fx_mod_addr);
3235 outb (0x00, dev.fx_mod_data);
3236 if (!wffx_idle()) return (-1);
3238 for (i = 0x2f; i <= 0x3e; i++) {
3239 outb (i, dev.fx_mod_addr);
3240 outb (0x00, dev.fx_mod_data);
3241 if (!wffx_idle()) return (-1);
3244 outb (0x3f, dev.fx_mod_addr);
3245 outb (0x20, dev.fx_mod_data);
3246 if (!wffx_idle()) return (-1);
3248 for (i = 0x40; i <= 0x4d; i++) {
3249 outb (i, dev.fx_mod_addr);
3250 outb (0x00, dev.fx_mod_data);
3251 if (!wffx_idle()) return (-1);
3254 outb (0x4e, dev.fx_mod_addr);
3255 outb (0x0e, dev.fx_mod_data);
3256 if (!wffx_idle()) return (-1);
3257 outb (0x4f, dev.fx_mod_addr);
3258 outb (0x0e, dev.fx_mod_data);
3259 if (!wffx_idle()) return (-1);
3262 for (i = 0x50; i <= 0x6b; i++) {
3263 outb (i, dev.fx_mod_addr);
3264 outb (0x00, dev.fx_mod_data);
3265 if (!wffx_idle()) return (-1);
3268 outb (0x6c, dev.fx_mod_addr);
3269 outb (0x40, dev.fx_mod_data);
3270 if (!wffx_idle()) return (-1);
3272 outb (0x6d, dev.fx_mod_addr);
3273 outb (0x00, dev.fx_mod_data);
3274 if (!wffx_idle()) return (-1);
3276 outb (0x6e, dev.fx_mod_addr);
3277 outb (0x40, dev.fx_mod_data);
3278 if (!wffx_idle()) return (-1);
3280 outb (0x6f, dev.fx_mod_addr);
3281 outb (0x40, dev.fx_mod_data);
3282 if (!wffx_idle()) return (-1);
3284 for (i = 0x70; i <= 0x7f; i++) {
3285 outb (i, dev.fx_mod_addr);
3286 outb (0xc0, dev.fx_mod_data);
3287 if (!wffx_idle()) return (-1);
3290 for (i = 0x80; i <= 0xaf; i++) {
3291 outb (i, dev.fx_mod_addr);
3292 outb (0x00, dev.fx_mod_data);
3293 if (!wffx_idle()) return (-1);
3296 for (i = 0xc0; i <= 0xdd; i++) {
3297 outb (i, dev.fx_mod_addr);
3298 outb (0x00, dev.fx_mod_data);
3299 if (!wffx_idle()) return (-1);
3302 outb (0xde, dev.fx_mod_addr);
3303 outb (0x10, dev.fx_mod_data);
3304 if (!wffx_idle()) return (-1);
3305 outb (0xdf, dev.fx_mod_addr);
3306 outb (0x10, dev.fx_mod_data);
3307 if (!wffx_idle()) return (-1);
3309 for (i = 0xe0; i <= 0xef; i++) {
3310 outb (i, dev.fx_mod_addr);
3311 outb (0x00, dev.fx_mod_data);
3312 if (!wffx_idle()) return (-1);
3315 for (i = 0x00; i <= 0x0f; i++) {
3316 outb (0x01, dev.fx_mod_addr);
3317 outb (i, dev.fx_mod_data);
3318 outb (0x02, dev.fx_mod_addr);
3319 outb (0x01, dev.fx_mod_data);
3320 if (!wffx_idle()) return (-1);
3323 outb (0x02, dev.fx_op); /* mute on */
3325 /* Now set the coefficients and so forth for the programs above */
3327 for (i = 0; i < sizeof (coefficients); i += 4) {
3328 outb (coefficients[i], dev.fx_dsp_page);
3329 outb (coefficients[i+1], dev.fx_dsp_addr);
3330 outb (coefficients[i+2], dev.fx_dsp_msb);
3331 outb (coefficients[i+3], dev.fx_dsp_lsb);
3332 if (!wffx_idle()) return (-1);
3335 /* Some settings (?) that are too small to bundle into loops */
3337 if (!wffx_idle()) return (-1);
3338 outb (0x1e, dev.fx_mod_addr);
3339 outb (0x14, dev.fx_mod_data);
3340 if (!wffx_idle()) return (-1);
3341 outb (0xde, dev.fx_mod_addr);
3342 outb (0x20, dev.fx_mod_data);
3343 if (!wffx_idle()) return (-1);
3344 outb (0xdf, dev.fx_mod_addr);
3345 outb (0x20, dev.fx_mod_data);
3347 /* some more coefficients */
3349 if (!wffx_idle()) return (-1);
3350 outb (0x06, dev.fx_dsp_page);
3351 outb (0x78, dev.fx_dsp_addr);
3352 outb (0x00, dev.fx_dsp_msb);
3353 outb (0x40, dev.fx_dsp_lsb);
3354 if (!wffx_idle()) return (-1);
3355 outb (0x07, dev.fx_dsp_page);
3356 outb (0x03, 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 (0x0b, dev.fx_dsp_addr);
3362 outb (0x0f, dev.fx_dsp_msb);
3363 outb (0xff, dev.fx_dsp_lsb);
3364 if (!wffx_idle()) return (-1);
3365 outb (0x07, dev.fx_dsp_page);
3366 outb (0x02, 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 (0x0a, 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 (0x46, dev.fx_dsp_addr);
3377 outb (0x00, dev.fx_dsp_msb);
3378 outb (0x00, dev.fx_dsp_lsb);
3379 if (!wffx_idle()) return (-1);
3380 outb (0x07, dev.fx_dsp_page);
3381 outb (0x49, dev.fx_dsp_addr);
3382 outb (0x00, dev.fx_dsp_msb);
3383 outb (0x00, dev.fx_dsp_lsb);
3385 /* Now, for some strange reason, lets reload every page
3386 and all the coefficients over again. I have *NO* idea
3387 why this is done. I do know that no sound is produced
3388 is this phase is omitted.
3391 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3392 outb (0x00, dev.fx_dsp_page);
3393 outb (0x10, dev.fx_dsp_addr);
3395 for (i = 0; i < sizeof (page_zero_v2); i += 2) {
3396 outb (page_zero_v2[i], dev.fx_dsp_msb);
3397 outb (page_zero_v2[i+1], dev.fx_dsp_lsb);
3398 if (!wffx_idle()) return (-1);
3401 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3402 outb (0x01, dev.fx_dsp_page);
3403 outb (0x10, dev.fx_dsp_addr);
3405 for (i = 0; i < sizeof (page_one_v2); i += 2) {
3406 outb (page_one_v2[i], dev.fx_dsp_msb);
3407 outb (page_one_v2[i+1], dev.fx_dsp_lsb);
3408 if (!wffx_idle()) return (-1);
3411 if (!wffx_idle()) return (-1);
3412 if (!wffx_idle()) return (-1);
3414 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3415 outb (0x02, dev.fx_dsp_page);
3416 outb (0x10, dev.fx_dsp_addr);
3418 for (i = 0; i < sizeof (page_two_v2); i++) {
3419 outb (page_two_v2[i], dev.fx_dsp_lsb);
3420 if (!wffx_idle()) return (-1);
3422 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3423 outb (0x03, dev.fx_dsp_page);
3424 outb (0x10, dev.fx_dsp_addr);
3426 for (i = 0; i < sizeof (page_three_v2); i++) {
3427 outb (page_three_v2[i], dev.fx_dsp_lsb);
3428 if (!wffx_idle()) return (-1);
3431 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3432 outb (0x04, dev.fx_dsp_page);
3433 outb (0x10, dev.fx_dsp_addr);
3435 for (i = 0; i < sizeof (page_four_v2); i++) {
3436 outb (page_four_v2[i], dev.fx_dsp_lsb);
3437 if (!wffx_idle()) return (-1);
3440 outb (FX_LSB_TRANSFER, dev.fx_lcr);
3441 outb (0x06, dev.fx_dsp_page);
3443 /* Page six v.2 is algorithmic */
3445 for (i = 0x10; i <= 0x3e; i += 2) {
3446 outb (i, dev.fx_dsp_addr);
3447 outb (0x00, dev.fx_dsp_msb);
3448 outb (0x00, dev.fx_dsp_lsb);
3449 if (!wffx_idle()) return (-1);
3452 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3453 outb (0x07, dev.fx_dsp_page);
3454 outb (0x10, dev.fx_dsp_addr);
3456 for (i = 0; i < sizeof (page_seven_v2); i += 2) {
3457 outb (page_seven_v2[i], dev.fx_dsp_msb);
3458 outb (page_seven_v2[i+1], dev.fx_dsp_lsb);
3459 if (!wffx_idle()) return (-1);
3462 for (i = 0x00; i < sizeof(mod_v2); i += 2) {
3463 outb (mod_v2[i], dev.fx_mod_addr);
3464 outb (mod_v2[i+1], dev.fx_mod_data);
3465 if (!wffx_idle()) return (-1);
3468 for (i = 0; i < sizeof (coefficients2); i += 4) {
3469 outb (coefficients2[i], dev.fx_dsp_page);
3470 outb (coefficients2[i+1], dev.fx_dsp_addr);
3471 outb (coefficients2[i+2], dev.fx_dsp_msb);
3472 outb (coefficients2[i+3], dev.fx_dsp_lsb);
3473 if (!wffx_idle()) return (-1);
3476 for (i = 0; i < sizeof (coefficients3); i += 2) {
3479 outb (0x07, dev.fx_dsp_page);
3480 x = (i % 4) ? 0x4e : 0x4c;
3481 outb (x, dev.fx_dsp_addr);
3482 outb (coefficients3[i], dev.fx_dsp_msb);
3483 outb (coefficients3[i+1], dev.fx_dsp_lsb);
3486 outb (0x00, dev.fx_op); /* mute off */
3487 if (!wffx_idle()) return (-1);
3493 static int irq = -1;
3495 MODULE_AUTHOR ("Paul Barton-Davis <pbd@op.net>");
3496 MODULE_DESCRIPTION ("Turtle Beach WaveFront Linux Driver");
3497 MODULE_LICENSE("GPL");
3498 MODULE_PARM (io,"i");
3499 MODULE_PARM (irq,"i");
3501 static int __init init_wavfront (void)
3503 printk ("Turtle Beach WaveFront Driver\n"
3504 "Copyright (C) by Hannu Solvainen, "
3505 "Paul Barton-Davis 1993-1998.\n");
3507 /* XXX t'would be lovely to ask the CS4232 for these values, eh ? */
3509 if (io == -1 || irq == -1) {
3510 printk (KERN_INFO LOGNAME "irq and io options must be set.\n");
3514 if (wavefront_interrupt_bits (irq) < 0) {
3515 printk (KERN_INFO LOGNAME
3516 "IRQ must be 9, 5, 12 or 15 (not %d)\n", irq);
3520 if (detect_wavefront (irq, io) < 0) {
3524 if (install_wavefront () < 0) {
3531 static void __exit cleanup_wavfront (void)
3533 uninstall_wavefront ();
3536 module_init(init_wavfront);
3537 module_exit(cleanup_wavfront);