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 static 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 static 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 static char *ospath = "/etc/sound/wavefront.os"; /* where to find a processed
176 version of the WaveFront OS
179 static int wait_polls = 2000; /* This is a number of tries we poll the
180 status register before resorting to sleeping.
181 WaveFront being an ISA card each poll takes
182 about 1.2us. So before going to
183 sleep we wait up to 2.4ms in a loop.
186 static int sleep_length = HZ/100; /* This says how long we're going to
188 10ms sounds reasonable for fast response.
191 static int sleep_tries = 50; /* Wait for status 0.5 seconds total. */
193 static int reset_time = 2; /* hundreths of a second we wait after a HW reset for
194 the expected interrupt.
197 static int ramcheck_time = 20; /* time in seconds to wait while ROM code
201 static int osrun_time = 10; /* time in seconds we wait for the OS to
205 module_param(wf_raw, int, 0);
206 module_param(fx_raw, int, 0);
207 module_param(debug_default, int, 0);
208 module_param(wait_polls, int, 0);
209 module_param(sleep_length, int, 0);
210 module_param(sleep_tries, int, 0);
211 module_param(ospath, charp, 0);
212 module_param(reset_time, int, 0);
213 module_param(ramcheck_time, int, 0);
214 module_param(osrun_time, int, 0);
216 /***************************************************************************/
218 /* Note: because this module doesn't export any symbols, this really isn't
219 a global variable, even if it looks like one. I was quite confused by
220 this when I started writing this as a (newer) module -- pbd.
224 int devno; /* device number from kernel */
225 int irq; /* "you were one, one of the few ..." */
226 int base; /* low i/o port address */
228 #define mpu_data_port base
229 #define mpu_command_port base + 1 /* write semantics */
230 #define mpu_status_port base + 1 /* read semantics */
231 #define data_port base + 2
232 #define status_port base + 3 /* read semantics */
233 #define control_port base + 3 /* write semantics */
234 #define block_port base + 4 /* 16 bit, writeonly */
235 #define last_block_port base + 6 /* 16 bit, writeonly */
237 /* FX ports. These are mapped through the ICS2115 to the YS225.
238 The ICS2115 takes care of flipping the relevant pins on the
239 YS225 so that access to each of these ports does the right
240 thing. Note: these are NOT documented by Turtle Beach.
243 #define fx_status base + 8
244 #define fx_op base + 8
245 #define fx_lcr base + 9
246 #define fx_dsp_addr base + 0xa
247 #define fx_dsp_page base + 0xb
248 #define fx_dsp_lsb base + 0xc
249 #define fx_dsp_msb base + 0xd
250 #define fx_mod_addr base + 0xe
251 #define fx_mod_data base + 0xf
253 volatile int irq_ok; /* set by interrupt handler */
254 volatile int irq_cnt; /* ditto */
255 int opened; /* flag, holds open(2) mode */
256 char debug; /* debugging flags */
257 int freemem; /* installed RAM, in bytes */
259 int synth_dev; /* devno for "raw" synth */
260 int mididev; /* devno for internal MIDI */
261 int ext_mididev; /* devno for external MIDI */
262 int fx_mididev; /* devno for FX MIDI interface */
263 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
264 int oss_dev; /* devno for OSS sequencer synth */
265 #endif /* OSS_SUPPORT_SEQ */
267 char fw_version[2]; /* major = [0], minor = [1] */
268 char hw_version[2]; /* major = [0], minor = [1] */
269 char israw; /* needs Motorola microcode */
270 char has_fx; /* has FX processor (Tropez+) */
271 char prog_status[WF_MAX_PROGRAM]; /* WF_SLOT_* */
272 char patch_status[WF_MAX_PATCH]; /* WF_SLOT_* */
273 char sample_status[WF_MAX_SAMPLE]; /* WF_ST_* | WF_SLOT_* */
274 int samples_used; /* how many */
275 char interrupts_on; /* h/w MPU interrupts enabled ? */
276 char rom_samples_rdonly; /* can we write on ROM samples */
277 wait_queue_head_t interrupt_sleeper;
280 static DEFINE_SPINLOCK(lock);
281 static int detect_wffx(void);
282 static int wffx_ioctl (wavefront_fx_info *);
283 static int wffx_init (void);
285 static int wavefront_delete_sample (int sampnum);
286 static int wavefront_find_free_sample (void);
290 extern int virtual_midi_enable (void);
291 extern int virtual_midi_disable (void);
292 extern int detect_wf_mpu (int, int);
293 extern int install_wf_mpu (void);
294 extern int uninstall_wf_mpu (void);
299 unsigned int read_cnt;
300 unsigned int write_cnt;
307 } wavefront_errors[] = {
308 { 0x01, "Bad sample number" },
309 { 0x02, "Out of sample memory" },
310 { 0x03, "Bad patch number" },
311 { 0x04, "Error in number of voices" },
312 { 0x06, "Sample load already in progress" },
313 { 0x0B, "No sample load request pending" },
314 { 0x0E, "Bad MIDI channel number" },
315 { 0x10, "Download Record Error" },
322 static wavefront_command wavefront_commands[] = {
323 { WFC_SET_SYNTHVOL, "set synthesizer volume", 0, 1, NEEDS_ACK },
324 { WFC_GET_SYNTHVOL, "get synthesizer volume", 1, 0, 0},
325 { WFC_SET_NVOICES, "set number of voices", 0, 1, NEEDS_ACK },
326 { WFC_GET_NVOICES, "get number of voices", 1, 0, 0 },
327 { WFC_SET_TUNING, "set synthesizer tuning", 0, 2, NEEDS_ACK },
328 { WFC_GET_TUNING, "get synthesizer tuning", 2, 0, 0 },
329 { WFC_DISABLE_CHANNEL, "disable synth channel", 0, 1, NEEDS_ACK },
330 { WFC_ENABLE_CHANNEL, "enable synth channel", 0, 1, NEEDS_ACK },
331 { WFC_GET_CHANNEL_STATUS, "get synth channel status", 3, 0, 0 },
332 { WFC_MISYNTH_OFF, "disable midi-in to synth", 0, 0, NEEDS_ACK },
333 { WFC_MISYNTH_ON, "enable midi-in to synth", 0, 0, NEEDS_ACK },
334 { WFC_VMIDI_ON, "enable virtual midi mode", 0, 0, NEEDS_ACK },
335 { WFC_VMIDI_OFF, "disable virtual midi mode", 0, 0, NEEDS_ACK },
336 { WFC_MIDI_STATUS, "report midi status", 1, 0, 0 },
337 { WFC_FIRMWARE_VERSION, "report firmware version", 2, 0, 0 },
338 { WFC_HARDWARE_VERSION, "report hardware version", 2, 0, 0 },
339 { WFC_GET_NSAMPLES, "report number of samples", 2, 0, 0 },
340 { WFC_INSTOUT_LEVELS, "report instantaneous output levels", 7, 0, 0 },
341 { WFC_PEAKOUT_LEVELS, "report peak output levels", 7, 0, 0 },
342 { WFC_DOWNLOAD_SAMPLE, "download sample",
343 0, WF_SAMPLE_BYTES, NEEDS_ACK },
344 { WFC_DOWNLOAD_BLOCK, "download block", 0, 0, NEEDS_ACK},
345 { WFC_DOWNLOAD_SAMPLE_HEADER, "download sample header",
346 0, WF_SAMPLE_HDR_BYTES, NEEDS_ACK },
347 { WFC_UPLOAD_SAMPLE_HEADER, "upload sample header", 13, 2, 0 },
349 /* This command requires a variable number of bytes to be written.
350 There is a hack in wavefront_cmd() to support this. The actual
351 count is passed in as the read buffer ptr, cast appropriately.
355 { WFC_DOWNLOAD_MULTISAMPLE, "download multisample", 0, 0, NEEDS_ACK },
357 /* This one is a hack as well. We just read the first byte of the
358 response, don't fetch an ACK, and leave the rest to the
359 calling function. Ugly, ugly, ugly.
362 { WFC_UPLOAD_MULTISAMPLE, "upload multisample", 2, 1, 0 },
363 { WFC_DOWNLOAD_SAMPLE_ALIAS, "download sample alias",
364 0, WF_ALIAS_BYTES, NEEDS_ACK },
365 { WFC_UPLOAD_SAMPLE_ALIAS, "upload sample alias", WF_ALIAS_BYTES, 2, 0},
366 { WFC_DELETE_SAMPLE, "delete sample", 0, 2, NEEDS_ACK },
367 { WFC_IDENTIFY_SAMPLE_TYPE, "identify sample type", 5, 2, 0 },
368 { WFC_UPLOAD_SAMPLE_PARAMS, "upload sample parameters" },
369 { WFC_REPORT_FREE_MEMORY, "report free memory", 4, 0, 0 },
370 { WFC_DOWNLOAD_PATCH, "download patch", 0, 134, NEEDS_ACK },
371 { WFC_UPLOAD_PATCH, "upload patch", 132, 2, 0 },
372 { WFC_DOWNLOAD_PROGRAM, "download program", 0, 33, NEEDS_ACK },
373 { WFC_UPLOAD_PROGRAM, "upload program", 32, 1, 0 },
374 { WFC_DOWNLOAD_EDRUM_PROGRAM, "download enhanced drum program", 0, 9,
376 { WFC_UPLOAD_EDRUM_PROGRAM, "upload enhanced drum program", 8, 1, 0},
377 { WFC_SET_EDRUM_CHANNEL, "set enhanced drum program channel",
379 { WFC_DISABLE_DRUM_PROGRAM, "disable drum program", 0, 1, NEEDS_ACK },
380 { WFC_REPORT_CHANNEL_PROGRAMS, "report channel program numbers",
382 { WFC_NOOP, "the no-op command", 0, 0, NEEDS_ACK },
387 wavefront_errorstr (int errnum)
392 for (i = 0; wavefront_errors[i].errstr; i++) {
393 if (wavefront_errors[i].errno == errnum) {
394 return wavefront_errors[i].errstr;
398 return "Unknown WaveFront error";
401 static wavefront_command *
402 wavefront_get_command (int cmd)
407 for (i = 0; wavefront_commands[i].cmd != 0; i++) {
408 if (cmd == wavefront_commands[i].cmd) {
409 return &wavefront_commands[i];
413 return (wavefront_command *) 0;
417 wavefront_status (void)
420 return inb (dev.status_port);
424 wavefront_wait (int mask)
429 for (i = 0; i < wait_polls; i++)
430 if (wavefront_status() & mask)
433 for (i = 0; i < sleep_tries; i++) {
435 if (wavefront_status() & mask) {
436 set_current_state(TASK_RUNNING);
440 set_current_state(TASK_INTERRUPTIBLE);
441 schedule_timeout(sleep_length);
442 if (signal_pending(current))
446 set_current_state(TASK_RUNNING);
451 wavefront_read (void)
454 if (wavefront_wait (STAT_CAN_READ))
455 return inb (dev.data_port);
457 DPRINT (WF_DEBUG_DATA, "read timeout.\n");
463 wavefront_write (unsigned char data)
466 if (wavefront_wait (STAT_CAN_WRITE)) {
467 outb (data, dev.data_port);
471 DPRINT (WF_DEBUG_DATA, "write timeout.\n");
477 wavefront_cmd (int cmd, unsigned char *rbuf, unsigned char *wbuf)
483 wavefront_command *wfcmd;
485 if ((wfcmd = wavefront_get_command (cmd)) == (wavefront_command *) 0) {
486 printk (KERN_WARNING LOGNAME "command 0x%x not supported.\n",
491 /* Hack to handle the one variable-size write command. See
492 wavefront_send_multisample() for the other half of this
493 gross and ugly strategy.
496 if (cmd == WFC_DOWNLOAD_MULTISAMPLE) {
497 wfcmd->write_cnt = (unsigned int) rbuf;
501 DPRINT (WF_DEBUG_CMD, "0x%x [%s] (%d,%d,%d)\n",
502 cmd, wfcmd->action, wfcmd->read_cnt,
503 wfcmd->write_cnt, wfcmd->need_ack);
505 if (wavefront_write (cmd)) {
506 DPRINT ((WF_DEBUG_IO|WF_DEBUG_CMD), "cannot request "
512 if (wfcmd->write_cnt > 0) {
513 DPRINT (WF_DEBUG_DATA, "writing %d bytes "
515 wfcmd->write_cnt, cmd);
517 for (i = 0; i < wfcmd->write_cnt; i++) {
518 if (wavefront_write (wbuf[i])) {
519 DPRINT (WF_DEBUG_IO, "bad write for byte "
520 "%d of 0x%x [%s].\n",
521 i, cmd, wfcmd->action);
525 DPRINT (WF_DEBUG_DATA, "write[%d] = 0x%x\n",
530 if (wfcmd->read_cnt > 0) {
531 DPRINT (WF_DEBUG_DATA, "reading %d ints "
533 wfcmd->read_cnt, cmd);
535 for (i = 0; i < wfcmd->read_cnt; i++) {
537 if ((c = wavefront_read()) == -1) {
538 DPRINT (WF_DEBUG_IO, "bad read for byte "
539 "%d of 0x%x [%s].\n",
540 i, cmd, wfcmd->action);
544 /* Now handle errors. Lots of special cases here */
547 if ((c = wavefront_read ()) == -1) {
548 DPRINT (WF_DEBUG_IO, "bad read for "
557 /* Can you believe this madness ? */
560 wfcmd->cmd == WFC_IDENTIFY_SAMPLE_TYPE) {
561 rbuf[0] = WF_ST_EMPTY;
565 wfcmd->cmd == WFC_UPLOAD_PATCH) {
570 wfcmd->cmd == WFC_UPLOAD_PROGRAM) {
576 DPRINT (WF_DEBUG_IO, "error %d (%s) "
582 wavefront_errorstr (c),
593 DPRINT (WF_DEBUG_DATA, "read[%d] = 0x%x\n",i, rbuf[i]);
597 if ((wfcmd->read_cnt == 0 && wfcmd->write_cnt == 0) || wfcmd->need_ack) {
599 DPRINT (WF_DEBUG_CMD, "reading ACK for 0x%x\n", cmd);
601 /* Some commands need an ACK, but return zero instead
602 of the standard value.
605 if ((ack = wavefront_read()) == 0) {
611 DPRINT (WF_DEBUG_IO, "cannot read ack for "
617 int err = -1; /* something unknown */
619 if (ack == 0xff) { /* explicit error */
621 if ((err = wavefront_read ()) == -1) {
622 DPRINT (WF_DEBUG_DATA,
629 DPRINT (WF_DEBUG_IO, "0x%x [%s] "
630 "failed (0x%x, 0x%x, %s)\n",
631 cmd, wfcmd->action, ack, err,
632 wavefront_errorstr (err));
638 DPRINT (WF_DEBUG_DATA, "ack received "
643 DPRINT (WF_DEBUG_CMD, "0x%x [%s] does not need "
645 cmd, wfcmd->action, wfcmd->read_cnt,
646 wfcmd->write_cnt, wfcmd->need_ack);
653 /***********************************************************************
654 WaveFront: data munging
656 Things here are weird. All data written to the board cannot
657 have its most significant bit set. Any data item with values
658 potentially > 0x7F (127) must be split across multiple bytes.
660 Sometimes, we need to munge numeric values that are represented on
661 the x86 side as 8-32 bit values. Sometimes, we need to munge data
662 that is represented on the x86 side as an array of bytes. The most
663 efficient approach to handling both cases seems to be to use 2
664 different functions for munging and 2 for de-munging. This avoids
665 weird casting and worrying about bit-level offsets.
667 **********************************************************************/
671 munge_int32 (unsigned int src,
673 unsigned int dst_size)
677 for (i = 0;i < dst_size; i++) {
678 *dst = src & 0x7F; /* Mask high bit of LSB */
679 src = src >> 7; /* Rotate Right 7 bits */
680 /* Note: we leave the upper bits in place */
688 demunge_int32 (unsigned char* src, int src_size)
694 for (i = src_size - 1; i >= 0; i--) {
695 outval=(outval<<7)+src[i];
703 munge_buf (unsigned char *src, unsigned char *dst, unsigned int dst_size)
707 unsigned int last = dst_size / 2;
709 for (i = 0; i < last; i++) {
710 *dst++ = src[i] & 0x7f;
711 *dst++ = src[i] >> 7;
718 demunge_buf (unsigned char *src, unsigned char *dst, unsigned int src_bytes)
722 unsigned char *end = src + src_bytes;
724 end = src + src_bytes;
726 /* NOTE: src and dst *CAN* point to the same address */
728 for (i = 0; src != end; i++) {
730 dst[i] |= (*src++)<<7;
736 /***********************************************************************
737 WaveFront: sample, patch and program management.
738 ***********************************************************************/
741 wavefront_delete_sample (int sample_num)
744 unsigned char wbuf[2];
747 wbuf[0] = sample_num & 0x7f;
748 wbuf[1] = sample_num >> 7;
750 if ((x = wavefront_cmd (WFC_DELETE_SAMPLE, NULL, wbuf)) == 0) {
751 dev.sample_status[sample_num] = WF_ST_EMPTY;
758 wavefront_get_sample_status (int assume_rom)
762 unsigned char rbuf[32], wbuf[32];
763 unsigned int sc_real, sc_alias, sc_multi;
765 /* check sample status */
767 if (wavefront_cmd (WFC_GET_NSAMPLES, rbuf, wbuf)) {
768 printk (KERN_WARNING LOGNAME "cannot request sample count.\n");
772 sc_real = sc_alias = sc_multi = dev.samples_used = 0;
774 for (i = 0; i < WF_MAX_SAMPLE; i++) {
779 if (wavefront_cmd (WFC_IDENTIFY_SAMPLE_TYPE, rbuf, wbuf)) {
780 printk (KERN_WARNING LOGNAME
781 "cannot identify sample "
782 "type of slot %d\n", i);
783 dev.sample_status[i] = WF_ST_EMPTY;
787 dev.sample_status[i] = (WF_SLOT_FILLED|rbuf[0]);
790 dev.sample_status[i] |= WF_SLOT_ROM;
793 switch (rbuf[0] & WF_ST_MASK) {
797 case WF_ST_MULTISAMPLE:
807 printk (KERN_WARNING LOGNAME "unknown sample type for "
812 if (rbuf[0] != WF_ST_EMPTY) {
817 printk (KERN_INFO LOGNAME
818 "%d samples used (%d real, %d aliases, %d multi), "
819 "%d empty\n", dev.samples_used, sc_real, sc_alias, sc_multi,
820 WF_MAX_SAMPLE - dev.samples_used);
828 wavefront_get_patch_status (void)
831 unsigned char patchbuf[WF_PATCH_BYTES];
832 unsigned char patchnum[2];
836 for (i = 0; i < WF_MAX_PATCH; i++) {
837 patchnum[0] = i & 0x7f;
838 patchnum[1] = i >> 7;
840 if ((x = wavefront_cmd (WFC_UPLOAD_PATCH, patchbuf,
843 dev.patch_status[i] |= WF_SLOT_FILLED;
844 p = (wavefront_patch *) patchbuf;
846 [p->sample_number|(p->sample_msb<<7)] |=
849 } else if (x == 3) { /* Bad patch number */
850 dev.patch_status[i] = 0;
852 printk (KERN_ERR LOGNAME "upload patch "
854 dev.patch_status[i] = 0;
859 /* program status has already filled in slot_used bits */
861 for (i = 0, cnt = 0, cnt2 = 0; i < WF_MAX_PATCH; i++) {
862 if (dev.patch_status[i] & WF_SLOT_FILLED) {
865 if (dev.patch_status[i] & WF_SLOT_USED) {
870 printk (KERN_INFO LOGNAME
871 "%d patch slots filled, %d in use\n", cnt, cnt2);
877 wavefront_get_program_status (void)
880 unsigned char progbuf[WF_PROGRAM_BYTES];
881 wavefront_program prog;
882 unsigned char prognum;
885 for (i = 0; i < WF_MAX_PROGRAM; i++) {
888 if ((x = wavefront_cmd (WFC_UPLOAD_PROGRAM, progbuf,
891 dev.prog_status[i] |= WF_SLOT_USED;
893 demunge_buf (progbuf, (unsigned char *) &prog,
896 for (l = 0; l < WF_NUM_LAYERS; l++) {
897 if (prog.layer[l].mute) {
899 [prog.layer[l].patch_number] |=
903 } else if (x == 1) { /* Bad program number */
904 dev.prog_status[i] = 0;
906 printk (KERN_ERR LOGNAME "upload program "
908 dev.prog_status[i] = 0;
912 for (i = 0, cnt = 0; i < WF_MAX_PROGRAM; i++) {
913 if (dev.prog_status[i]) {
918 printk (KERN_INFO LOGNAME "%d programs slots in use\n", cnt);
924 wavefront_send_patch (wavefront_patch_info *header)
927 unsigned char buf[WF_PATCH_BYTES+2];
930 DPRINT (WF_DEBUG_LOAD_PATCH, "downloading patch %d\n",
933 dev.patch_status[header->number] |= WF_SLOT_FILLED;
936 bptr = munge_int32 (header->number, buf, 2);
937 munge_buf ((unsigned char *)&header->hdr.p, bptr, WF_PATCH_BYTES);
939 if (wavefront_cmd (WFC_DOWNLOAD_PATCH, NULL, buf)) {
940 printk (KERN_ERR LOGNAME "download patch failed\n");
948 wavefront_send_program (wavefront_patch_info *header)
951 unsigned char buf[WF_PROGRAM_BYTES+1];
954 DPRINT (WF_DEBUG_LOAD_PATCH, "downloading program %d\n",
957 dev.prog_status[header->number] = WF_SLOT_USED;
959 /* XXX need to zero existing SLOT_USED bit for program_status[i]
960 where `i' is the program that's being (potentially) overwritten.
963 for (i = 0; i < WF_NUM_LAYERS; i++) {
964 if (header->hdr.pr.layer[i].mute) {
965 dev.patch_status[header->hdr.pr.layer[i].patch_number] |=
968 /* XXX need to mark SLOT_USED for sample used by
969 patch_number, but this means we have to load it. Ick.
974 buf[0] = header->number;
975 munge_buf ((unsigned char *)&header->hdr.pr, &buf[1], WF_PROGRAM_BYTES);
977 if (wavefront_cmd (WFC_DOWNLOAD_PROGRAM, NULL, buf)) {
978 printk (KERN_WARNING LOGNAME "download patch failed\n");
986 wavefront_freemem (void)
991 if (wavefront_cmd (WFC_REPORT_FREE_MEMORY, rbuf, NULL)) {
992 printk (KERN_WARNING LOGNAME "can't get memory stats.\n");
995 return demunge_int32 (rbuf, 4);
1000 wavefront_send_sample (wavefront_patch_info *header,
1001 UINT16 __user *dataptr,
1002 int data_is_unsigned)
1005 /* samples are downloaded via a 16-bit wide i/o port
1006 (you could think of it as 2 adjacent 8-bit wide ports
1007 but its less efficient that way). therefore, all
1008 the blocksizes and so forth listed in the documentation,
1009 and used conventionally to refer to sample sizes,
1010 which are given in 8-bit units (bytes), need to be
1014 UINT16 sample_short;
1016 UINT16 __user *data_end = NULL;
1018 const int max_blksize = 4096/2;
1019 unsigned int written;
1020 unsigned int blocksize;
1023 unsigned char sample_hdr[WF_SAMPLE_HDR_BYTES];
1024 unsigned char *shptr;
1026 int initial_skip = 0;
1028 DPRINT (WF_DEBUG_LOAD_PATCH, "sample %sdownload for slot %d, "
1029 "type %d, %d bytes from %p\n",
1030 header->size ? "" : "header ",
1031 header->number, header->subkey,
1035 if (header->number == WAVEFRONT_FIND_FREE_SAMPLE_SLOT) {
1038 if ((x = wavefront_find_free_sample ()) < 0) {
1041 printk (KERN_DEBUG LOGNAME "unspecified sample => %d\n", x);
1047 /* XXX it's a debatable point whether or not RDONLY semantics
1048 on the ROM samples should cover just the sample data or
1049 the sample header. For now, it only covers the sample data,
1050 so anyone is free at all times to rewrite sample headers.
1052 My reason for this is that we have the sample headers
1053 available in the WFB file for General MIDI, and so these
1054 can always be reset if needed. The sample data, however,
1055 cannot be recovered without a complete reset and firmware
1056 reload of the ICS2115, which is a very expensive operation.
1058 So, doing things this way allows us to honor the notion of
1059 "RESETSAMPLES" reasonably cheaply. Note however, that this
1060 is done purely at user level: there is no WFB parser in
1061 this driver, and so a complete reset (back to General MIDI,
1062 or theoretically some other configuration) is the
1063 responsibility of the user level library.
1065 To try to do this in the kernel would be a little
1066 crazy: we'd need 158K of kernel space just to hold
1067 a copy of the patch/program/sample header data.
1070 if (dev.rom_samples_rdonly) {
1071 if (dev.sample_status[header->number] & WF_SLOT_ROM) {
1072 printk (KERN_ERR LOGNAME "sample slot %d "
1073 "write protected\n",
1079 wavefront_delete_sample (header->number);
1083 dev.freemem = wavefront_freemem ();
1085 if (dev.freemem < header->size) {
1086 printk (KERN_ERR LOGNAME
1087 "insufficient memory to "
1088 "load %d byte sample.\n",
1095 skip = WF_GET_CHANNEL(&header->hdr.s);
1097 if (skip > 0 && header->hdr.s.SampleResolution != LINEAR_16BIT) {
1098 printk (KERN_ERR LOGNAME "channel selection only "
1099 "possible on 16-bit samples");
1134 DPRINT (WF_DEBUG_LOAD_PATCH, "channel selection: %d => "
1135 "initial skip = %d, skip = %d\n",
1136 WF_GET_CHANNEL (&header->hdr.s),
1137 initial_skip, skip);
1139 /* Be safe, and zero the "Unused" bits ... */
1141 WF_SET_CHANNEL(&header->hdr.s, 0);
1143 /* adjust size for 16 bit samples by dividing by two. We always
1144 send 16 bits per write, even for 8 bit samples, so the length
1145 is always half the size of the sample data in bytes.
1148 length = header->size / 2;
1150 /* the data we're sent has not been munged, and in fact, the
1151 header we have to send isn't just a munged copy either.
1152 so, build the sample header right here.
1155 shptr = &sample_hdr[0];
1157 shptr = munge_int32 (header->number, shptr, 2);
1160 shptr = munge_int32 (length, shptr, 4);
1163 /* Yes, a 4 byte result doesn't contain all of the offset bits,
1164 but the offset only uses 24 bits.
1167 shptr = munge_int32 (*((UINT32 *) &header->hdr.s.sampleStartOffset),
1169 shptr = munge_int32 (*((UINT32 *) &header->hdr.s.loopStartOffset),
1171 shptr = munge_int32 (*((UINT32 *) &header->hdr.s.loopEndOffset),
1173 shptr = munge_int32 (*((UINT32 *) &header->hdr.s.sampleEndOffset),
1176 /* This one is truly weird. What kind of weirdo decided that in
1177 a system dominated by 16 and 32 bit integers, they would use
1181 shptr = munge_int32 (header->hdr.s.FrequencyBias, shptr, 3);
1183 /* Why is this nybblified, when the MSB is *always* zero ?
1184 Anyway, we can't take address of bitfield, so make a
1185 good-faith guess at where it starts.
1188 shptr = munge_int32 (*(&header->hdr.s.FrequencyBias+1),
1191 if (wavefront_cmd (header->size ?
1192 WFC_DOWNLOAD_SAMPLE : WFC_DOWNLOAD_SAMPLE_HEADER,
1193 NULL, sample_hdr)) {
1194 printk (KERN_WARNING LOGNAME "sample %sdownload refused.\n",
1195 header->size ? "" : "header ");
1199 if (header->size == 0) {
1200 goto sent; /* Sorry. Just had to have one somewhere */
1203 data_end = dataptr + length;
1205 /* Do any initial skip over an unused channel's data */
1207 dataptr += initial_skip;
1209 for (written = 0, blocknum = 0;
1210 written < length; written += max_blksize, blocknum++) {
1212 if ((length - written) > max_blksize) {
1213 blocksize = max_blksize;
1215 /* round to nearest 16-byte value */
1216 blocksize = ((length-written+7)&~0x7);
1219 if (wavefront_cmd (WFC_DOWNLOAD_BLOCK, NULL, NULL)) {
1220 printk (KERN_WARNING LOGNAME "download block "
1221 "request refused.\n");
1225 for (i = 0; i < blocksize; i++) {
1227 if (dataptr < data_end) {
1229 __get_user (sample_short, dataptr);
1232 if (data_is_unsigned) { /* GUS ? */
1234 if (WF_SAMPLE_IS_8BIT(&header->hdr.s)) {
1242 &sample_short)[0] += 0x7f;
1244 &sample_short)[1] += 0x7f;
1253 sample_short += 0x7fff;
1259 /* In padding section of final block:
1261 Don't fetch unsupplied data from
1262 user space, just continue with
1263 whatever the final value was.
1267 if (i < blocksize - 1) {
1268 outw (sample_short, dev.block_port);
1270 outw (sample_short, dev.last_block_port);
1274 /* Get "DMA page acknowledge", even though its really
1275 nothing to do with DMA at all.
1278 if ((dma_ack = wavefront_read ()) != WF_DMA_ACK) {
1279 if (dma_ack == -1) {
1280 printk (KERN_ERR LOGNAME "upload sample "
1281 "DMA ack timeout\n");
1284 printk (KERN_ERR LOGNAME "upload sample "
1285 "DMA ack error 0x%x\n",
1292 dev.sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_SAMPLE);
1294 /* Note, label is here because sending the sample header shouldn't
1295 alter the sample_status info at all.
1303 wavefront_send_alias (wavefront_patch_info *header)
1306 unsigned char alias_hdr[WF_ALIAS_BYTES];
1308 DPRINT (WF_DEBUG_LOAD_PATCH, "download alias, %d is "
1311 header->hdr.a.OriginalSample);
1313 munge_int32 (header->number, &alias_hdr[0], 2);
1314 munge_int32 (header->hdr.a.OriginalSample, &alias_hdr[2], 2);
1315 munge_int32 (*((unsigned int *)&header->hdr.a.sampleStartOffset),
1317 munge_int32 (*((unsigned int *)&header->hdr.a.loopStartOffset),
1319 munge_int32 (*((unsigned int *)&header->hdr.a.loopEndOffset),
1321 munge_int32 (*((unsigned int *)&header->hdr.a.sampleEndOffset),
1323 munge_int32 (header->hdr.a.FrequencyBias, &alias_hdr[20], 3);
1324 munge_int32 (*(&header->hdr.a.FrequencyBias+1), &alias_hdr[23], 2);
1326 if (wavefront_cmd (WFC_DOWNLOAD_SAMPLE_ALIAS, NULL, alias_hdr)) {
1327 printk (KERN_ERR LOGNAME "download alias failed.\n");
1331 dev.sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_ALIAS);
1337 wavefront_send_multisample (wavefront_patch_info *header)
1341 unsigned char msample_hdr[WF_MSAMPLE_BYTES];
1343 munge_int32 (header->number, &msample_hdr[0], 2);
1345 /* You'll recall at this point that the "number of samples" value
1346 in a wavefront_multisample struct is actually the log2 of the
1347 real number of samples.
1350 num_samples = (1<<(header->hdr.ms.NumberOfSamples&7));
1351 msample_hdr[2] = (unsigned char) header->hdr.ms.NumberOfSamples;
1353 DPRINT (WF_DEBUG_LOAD_PATCH, "multi %d with %d=%d samples\n",
1355 header->hdr.ms.NumberOfSamples,
1358 for (i = 0; i < num_samples; i++) {
1359 DPRINT(WF_DEBUG_LOAD_PATCH|WF_DEBUG_DATA, "sample[%d] = %d\n",
1360 i, header->hdr.ms.SampleNumber[i]);
1361 munge_int32 (header->hdr.ms.SampleNumber[i],
1362 &msample_hdr[3+(i*2)], 2);
1365 /* Need a hack here to pass in the number of bytes
1366 to be written to the synth. This is ugly, and perhaps
1367 one day, I'll fix it.
1370 if (wavefront_cmd (WFC_DOWNLOAD_MULTISAMPLE,
1371 (unsigned char *) ((num_samples*2)+3),
1373 printk (KERN_ERR LOGNAME "download of multisample failed.\n");
1377 dev.sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_MULTISAMPLE);
1383 wavefront_fetch_multisample (wavefront_patch_info *header)
1386 unsigned char log_ns[1];
1387 unsigned char number[2];
1390 munge_int32 (header->number, number, 2);
1392 if (wavefront_cmd (WFC_UPLOAD_MULTISAMPLE, log_ns, number)) {
1393 printk (KERN_ERR LOGNAME "upload multisample failed.\n");
1397 DPRINT (WF_DEBUG_DATA, "msample %d has %d samples\n",
1398 header->number, log_ns[0]);
1400 header->hdr.ms.NumberOfSamples = log_ns[0];
1402 /* get the number of samples ... */
1404 num_samples = (1 << log_ns[0]);
1406 for (i = 0; i < num_samples; i++) {
1409 if ((d[0] = wavefront_read ()) == -1) {
1410 printk (KERN_ERR LOGNAME "upload multisample failed "
1411 "during sample loop.\n");
1415 if ((d[1] = wavefront_read ()) == -1) {
1416 printk (KERN_ERR LOGNAME "upload multisample failed "
1417 "during sample loop.\n");
1421 header->hdr.ms.SampleNumber[i] =
1422 demunge_int32 ((unsigned char *) d, 2);
1424 DPRINT (WF_DEBUG_DATA, "msample sample[%d] = %d\n",
1425 i, header->hdr.ms.SampleNumber[i]);
1433 wavefront_send_drum (wavefront_patch_info *header)
1436 unsigned char drumbuf[WF_DRUM_BYTES];
1437 wavefront_drum *drum = &header->hdr.d;
1440 DPRINT (WF_DEBUG_LOAD_PATCH, "downloading edrum for MIDI "
1441 "note %d, patch = %d\n",
1442 header->number, drum->PatchNumber);
1444 drumbuf[0] = header->number & 0x7f;
1446 for (i = 0; i < 4; i++) {
1447 munge_int32 (((unsigned char *)drum)[i], &drumbuf[1+(i*2)], 2);
1450 if (wavefront_cmd (WFC_DOWNLOAD_EDRUM_PROGRAM, NULL, drumbuf)) {
1451 printk (KERN_ERR LOGNAME "download drum failed.\n");
1459 wavefront_find_free_sample (void)
1464 for (i = 0; i < WF_MAX_SAMPLE; i++) {
1465 if (!(dev.sample_status[i] & WF_SLOT_FILLED)) {
1469 printk (KERN_WARNING LOGNAME "no free sample slots!\n");
1474 wavefront_find_free_patch (void)
1479 for (i = 0; i < WF_MAX_PATCH; i++) {
1480 if (!(dev.patch_status[i] & WF_SLOT_FILLED)) {
1484 printk (KERN_WARNING LOGNAME "no free patch slots!\n");
1492 int tbl[]={0, 0, 2048, 3246, 4096, 4755, 5294, 5749, 6143,
1493 6492, 6803, 7084, 7342, 7578, 7797, 8001, 8192,
1494 8371, 8540, 8699, 8851, 8995, 9132, 9264, 9390,
1495 9510, 9626, 9738, 9845, 9949, 10049, 10146};
1498 /* Returns 2048*log2(n) */
1500 /* FIXME: this is like doing integer math
1501 on quantum particles (RuN) */
1517 wavefront_load_gus_patch (int devno, int format, const char __user *addr,
1518 int offs, int count, int pmgr_flag)
1520 struct patch_info guspatch;
1521 wavefront_patch_info samp, pat, prog;
1522 wavefront_patch *patp;
1523 wavefront_sample *sampp;
1524 wavefront_program *progp;
1529 /* Copy in the header of the GUS patch */
1531 sizeof_patch = (long) &guspatch.data[0] - (long) &guspatch;
1532 if (copy_from_user(&((char *) &guspatch)[offs],
1533 &(addr)[offs], sizeof_patch - offs))
1536 if ((i = wavefront_find_free_patch ()) == -1) {
1540 pat.subkey = WF_ST_PATCH;
1543 if ((i = wavefront_find_free_sample ()) == -1) {
1547 samp.subkey = WF_ST_SAMPLE;
1548 samp.size = guspatch.len;
1549 sampp = &samp.hdr.s;
1551 prog.number = guspatch.instr_no;
1552 progp = &prog.hdr.pr;
1554 /* Setup the patch structure */
1556 patp->amplitude_bias=guspatch.volume;
1558 patp->sample_number= samp.number & 0xff;
1559 patp->sample_msb= samp.number>>8;
1560 patp->pitch_bend= /*12*/ 0;
1563 patp->nohold=(guspatch.mode & WAVE_SUSTAIN_ON) ? 0:1;
1564 patp->frequency_bias=0;
1569 patp->fm_src1=WF_MOD_MOD_WHEEL;
1570 patp->am_src=WF_MOD_PRESSURE;
1571 patp->am_amount=127;
1572 patp->fc1_mod_amount=0;
1573 patp->fc2_mod_amount=0;
1576 patp->envelope1.attack_level=127;
1577 patp->envelope1.decay1_level=127;
1578 patp->envelope1.decay2_level=127;
1579 patp->envelope1.sustain_level=127;
1580 patp->envelope1.release_level=0;
1581 patp->envelope2.attack_velocity=127;
1582 patp->envelope2.attack_level=127;
1583 patp->envelope2.decay1_level=127;
1584 patp->envelope2.decay2_level=127;
1585 patp->envelope2.sustain_level=127;
1586 patp->envelope2.release_level=0;
1587 patp->envelope2.attack_velocity=127;
1590 /* Program for this patch */
1592 progp->layer[0].patch_number= pat.number; /* XXX is this right ? */
1593 progp->layer[0].mute=1;
1594 progp->layer[0].pan_or_mod=1;
1595 progp->layer[0].pan=7;
1596 progp->layer[0].mix_level=127 /* guspatch.volume */;
1597 progp->layer[0].split_type=0;
1598 progp->layer[0].split_point=0;
1599 progp->layer[0].play_below=0;
1601 for (i = 1; i < 4; i++) {
1602 progp->layer[i].mute=0;
1607 sampp->SampleResolution=((~guspatch.mode & WAVE_16_BITS)<<1);
1610 note_to_freq (base_note) < guspatch.base_note;
1613 if ((guspatch.base_note-note_to_freq(base_note))
1614 >(note_to_freq(base_note)-guspatch.base_note))
1617 printk(KERN_DEBUG "ref freq=%d,base note=%d\n",
1621 sampp->FrequencyBias = (29550 - log2_2048(guspatch.base_freq)
1623 printk(KERN_DEBUG "Freq Bias is %d\n", sampp->FrequencyBias);
1624 sampp->Loop=(guspatch.mode & WAVE_LOOPING) ? 1:0;
1625 sampp->sampleStartOffset.Fraction=0;
1626 sampp->sampleStartOffset.Integer=0;
1627 sampp->loopStartOffset.Fraction=0;
1628 sampp->loopStartOffset.Integer=guspatch.loop_start
1629 >>((guspatch.mode&WAVE_16_BITS) ? 1:0);
1630 sampp->loopEndOffset.Fraction=0;
1631 sampp->loopEndOffset.Integer=guspatch.loop_end
1632 >>((guspatch.mode&WAVE_16_BITS) ? 1:0);
1633 sampp->sampleEndOffset.Fraction=0;
1634 sampp->sampleEndOffset.Integer=guspatch.len >> (guspatch.mode&1);
1635 sampp->Bidirectional=(guspatch.mode&WAVE_BIDIR_LOOP) ? 1:0;
1636 sampp->Reverse=(guspatch.mode&WAVE_LOOP_BACK) ? 1:0;
1638 /* Now ship it down */
1640 wavefront_send_sample (&samp,
1641 (unsigned short __user *) &(addr)[sizeof_patch],
1642 (guspatch.mode & WAVE_UNSIGNED) ? 1:0);
1643 wavefront_send_patch (&pat);
1644 wavefront_send_program (&prog);
1646 /* Now pan as best we can ... use the slave/internal MIDI device
1647 number if it exists (since it talks to the WaveFront), or the
1651 if (dev.mididev > 0) {
1652 midi_synth_controller (dev.mididev, guspatch.instr_no, 10,
1653 ((guspatch.panning << 4) > 127) ?
1654 127 : (guspatch.panning << 4));
1661 wavefront_load_patch (const char __user *addr)
1665 wavefront_patch_info header;
1667 if (copy_from_user (&header, addr, sizeof(wavefront_patch_info) -
1668 sizeof(wavefront_any))) {
1669 printk (KERN_WARNING LOGNAME "bad address for load patch.\n");
1673 DPRINT (WF_DEBUG_LOAD_PATCH, "download "
1675 "Sample number: %d "
1676 "Sample size: %d\n",
1681 switch (header.subkey) {
1682 case WF_ST_SAMPLE: /* sample or sample_header, based on patch->size */
1684 if (copy_from_user((unsigned char *) &header.hdr.s,
1685 (unsigned char __user *) header.hdrptr,
1686 sizeof (wavefront_sample)))
1689 return wavefront_send_sample (&header, header.dataptr, 0);
1691 case WF_ST_MULTISAMPLE:
1693 if (copy_from_user(&header.hdr.s, header.hdrptr,
1694 sizeof(wavefront_multisample)))
1697 return wavefront_send_multisample (&header);
1702 if (copy_from_user(&header.hdr.a, header.hdrptr,
1703 sizeof (wavefront_alias)))
1706 return wavefront_send_alias (&header);
1709 if (copy_from_user(&header.hdr.d, header.hdrptr,
1710 sizeof (wavefront_drum)))
1713 return wavefront_send_drum (&header);
1716 if (copy_from_user(&header.hdr.p, header.hdrptr,
1717 sizeof (wavefront_patch)))
1720 return wavefront_send_patch (&header);
1723 if (copy_from_user(&header.hdr.pr, header.hdrptr,
1724 sizeof (wavefront_program)))
1727 return wavefront_send_program (&header);
1730 printk (KERN_ERR LOGNAME "unknown patch type %d.\n",
1738 /***********************************************************************
1739 WaveFront: /dev/sequencer{,2} and other hardware-dependent interfaces
1740 ***********************************************************************/
1743 process_sample_hdr (UCHAR8 *buf)
1751 /* The board doesn't send us an exact copy of a "wavefront_sample"
1752 in response to an Upload Sample Header command. Instead, we
1753 have to convert the data format back into our data structure,
1754 just as in the Download Sample command, where we have to do
1755 something very similar in the reverse direction.
1758 *((UINT32 *) &s.sampleStartOffset) = demunge_int32 (ptr, 4); ptr += 4;
1759 *((UINT32 *) &s.loopStartOffset) = demunge_int32 (ptr, 4); ptr += 4;
1760 *((UINT32 *) &s.loopEndOffset) = demunge_int32 (ptr, 4); ptr += 4;
1761 *((UINT32 *) &s.sampleEndOffset) = demunge_int32 (ptr, 4); ptr += 4;
1762 *((UINT32 *) &s.FrequencyBias) = demunge_int32 (ptr, 3); ptr += 3;
1764 s.SampleResolution = *ptr & 0x3;
1765 s.Loop = *ptr & 0x8;
1766 s.Bidirectional = *ptr & 0x10;
1767 s.Reverse = *ptr & 0x40;
1769 /* Now copy it back to where it came from */
1771 memcpy (buf, (unsigned char *) &s, sizeof (wavefront_sample));
1775 wavefront_synth_control (int cmd, wavefront_control *wc)
1778 unsigned char patchnumbuf[2];
1781 DPRINT (WF_DEBUG_CMD, "synth control with "
1782 "cmd 0x%x\n", wc->cmd);
1784 /* Pre-handling of or for various commands */
1787 case WFC_DISABLE_INTERRUPTS:
1788 printk (KERN_INFO LOGNAME "interrupts disabled.\n");
1789 outb (0x80|0x20, dev.control_port);
1790 dev.interrupts_on = 0;
1793 case WFC_ENABLE_INTERRUPTS:
1794 printk (KERN_INFO LOGNAME "interrupts enabled.\n");
1795 outb (0x80|0x40|0x20, dev.control_port);
1796 dev.interrupts_on = 1;
1799 case WFC_INTERRUPT_STATUS:
1800 wc->rbuf[0] = dev.interrupts_on;
1803 case WFC_ROMSAMPLES_RDONLY:
1804 dev.rom_samples_rdonly = wc->wbuf[0];
1808 case WFC_IDENTIFY_SLOT_TYPE:
1809 i = wc->wbuf[0] | (wc->wbuf[1] << 7);
1810 if (i <0 || i >= WF_MAX_SAMPLE) {
1811 printk (KERN_WARNING LOGNAME "invalid slot ID %d\n",
1813 wc->status = EINVAL;
1816 wc->rbuf[0] = dev.sample_status[i];
1820 case WFC_DEBUG_DRIVER:
1821 dev.debug = wc->wbuf[0];
1822 printk (KERN_INFO LOGNAME "debug = 0x%x\n", dev.debug);
1826 wffx_ioctl ((wavefront_fx_info *) &wc->wbuf[0]);
1829 case WFC_UPLOAD_PATCH:
1830 munge_int32 (*((UINT32 *) wc->wbuf), patchnumbuf, 2);
1831 memcpy (wc->wbuf, patchnumbuf, 2);
1834 case WFC_UPLOAD_MULTISAMPLE:
1835 /* multisamples have to be handled differently, and
1836 cannot be dealt with properly by wavefront_cmd() alone.
1838 wc->status = wavefront_fetch_multisample
1839 ((wavefront_patch_info *) wc->rbuf);
1842 case WFC_UPLOAD_SAMPLE_ALIAS:
1843 printk (KERN_INFO LOGNAME "support for sample alias upload "
1844 "being considered.\n");
1845 wc->status = EINVAL;
1849 wc->status = wavefront_cmd (wc->cmd, wc->rbuf, wc->wbuf);
1851 /* Post-handling of certain commands.
1853 In particular, if the command was an upload, demunge the data
1854 so that the user-level doesn't have to think about it.
1857 if (wc->status == 0) {
1859 /* intercept any freemem requests so that we know
1860 we are always current with the user-level view
1864 case WFC_REPORT_FREE_MEMORY:
1865 dev.freemem = demunge_int32 (wc->rbuf, 4);
1868 case WFC_UPLOAD_PATCH:
1869 demunge_buf (wc->rbuf, wc->rbuf, WF_PATCH_BYTES);
1872 case WFC_UPLOAD_PROGRAM:
1873 demunge_buf (wc->rbuf, wc->rbuf, WF_PROGRAM_BYTES);
1876 case WFC_UPLOAD_EDRUM_PROGRAM:
1877 demunge_buf (wc->rbuf, wc->rbuf, WF_DRUM_BYTES - 1);
1880 case WFC_UPLOAD_SAMPLE_HEADER:
1881 process_sample_hdr (wc->rbuf);
1884 case WFC_UPLOAD_SAMPLE_ALIAS:
1885 printk (KERN_INFO LOGNAME "support for "
1886 "sample aliases still "
1887 "being considered.\n");
1891 if (virtual_midi_disable () < 0) {
1897 if (virtual_midi_enable () < 0) {
1908 /***********************************************************************/
1909 /* WaveFront: Linux file system interface (for access via raw synth) */
1910 /***********************************************************************/
1913 wavefront_open (struct inode *inode, struct file *file)
1916 dev.opened = file->f_flags;
1921 wavefront_release(struct inode *inode, struct file *file)
1931 wavefront_ioctl(struct inode *inode, struct file *file,
1932 unsigned int cmd, unsigned long arg)
1934 wavefront_control wc;
1940 if (copy_from_user(&wc, (void __user *) arg, sizeof (wc)))
1943 if ((err = wavefront_synth_control (cmd, &wc)) == 0) {
1944 if (copy_to_user ((void __user *) arg, &wc, sizeof (wc)))
1950 case WFCTL_LOAD_SPP:
1951 return wavefront_load_patch ((const char __user *) arg);
1954 printk (KERN_WARNING LOGNAME "invalid ioctl %#x\n", cmd);
1961 static /*const*/ struct file_operations wavefront_fops = {
1962 .owner = THIS_MODULE,
1963 .llseek = no_llseek,
1964 .ioctl = wavefront_ioctl,
1965 .open = wavefront_open,
1966 .release = wavefront_release,
1970 /***********************************************************************/
1971 /* WaveFront: OSS installation and support interface */
1972 /***********************************************************************/
1974 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
1976 static struct synth_info wavefront_info =
1977 {"Turtle Beach WaveFront", 0, SYNTH_TYPE_SAMPLE, SAMPLE_TYPE_WAVEFRONT,
1978 0, 32, 0, 0, SYNTH_CAP_INPUT};
1981 wavefront_oss_open (int devno, int mode)
1989 wavefront_oss_close (int devno)
1998 wavefront_oss_ioctl (int devno, unsigned int cmd, void __user * arg)
2001 wavefront_control wc;
2005 case SNDCTL_SYNTH_INFO:
2006 if(copy_to_user(arg, &wavefront_info, sizeof (wavefront_info)))
2010 case SNDCTL_SEQ_RESETSAMPLES:
2011 // printk (KERN_WARNING LOGNAME "driver cannot reset samples.\n");
2012 return 0; /* don't force an error */
2014 case SNDCTL_SEQ_PERCMODE:
2015 return 0; /* don't force an error */
2017 case SNDCTL_SYNTH_MEMAVL:
2018 if ((dev.freemem = wavefront_freemem ()) < 0) {
2019 printk (KERN_ERR LOGNAME "cannot get memory size\n");
2026 case SNDCTL_SYNTH_CONTROL:
2027 if(copy_from_user (&wc, arg, sizeof (wc)))
2029 else if ((err = wavefront_synth_control (cmd, &wc)) == 0) {
2030 if(copy_to_user (arg, &wc, sizeof (wc)))
2042 wavefront_oss_load_patch (int devno, int format, const char __user *addr,
2043 int offs, int count, int pmgr_flag)
2046 if (format == SYSEX_PATCH) { /* Handled by midi_synth.c */
2047 if (midi_load_patch == NULL) {
2048 printk (KERN_ERR LOGNAME
2049 "SYSEX not loadable: "
2050 "no midi patch loader!\n");
2054 return midi_load_patch (devno, format, addr,
2055 offs, count, pmgr_flag);
2057 } else if (format == GUS_PATCH) {
2058 return wavefront_load_gus_patch (devno, format,
2059 addr, offs, count, pmgr_flag);
2061 } else if (format != WAVEFRONT_PATCH) {
2062 printk (KERN_ERR LOGNAME "unknown patch format %d\n", format);
2066 if (count < sizeof (wavefront_patch_info)) {
2067 printk (KERN_ERR LOGNAME "sample header too short\n");
2071 /* "addr" points to a user-space wavefront_patch_info */
2073 return wavefront_load_patch (addr);
2076 static struct synth_operations wavefront_operations =
2078 .owner = THIS_MODULE,
2080 .info = &wavefront_info,
2082 .synth_type = SYNTH_TYPE_SAMPLE,
2083 .synth_subtype = SAMPLE_TYPE_WAVEFRONT,
2084 .open = wavefront_oss_open,
2085 .close = wavefront_oss_close,
2086 .ioctl = wavefront_oss_ioctl,
2087 .kill_note = midi_synth_kill_note,
2088 .start_note = midi_synth_start_note,
2089 .set_instr = midi_synth_set_instr,
2090 .reset = midi_synth_reset,
2091 .load_patch = midi_synth_load_patch,
2092 .aftertouch = midi_synth_aftertouch,
2093 .controller = midi_synth_controller,
2094 .panning = midi_synth_panning,
2095 .bender = midi_synth_bender,
2096 .setup_voice = midi_synth_setup_voice
2098 #endif /* OSS_SUPPORT_SEQ */
2100 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_STATIC_INSTALL
2102 static void __init attach_wavefront (struct address_info *hw_config)
2104 (void) install_wavefront ();
2107 static int __init probe_wavefront (struct address_info *hw_config)
2109 return !detect_wavefront (hw_config->irq, hw_config->io_base);
2112 static void __exit unload_wavefront (struct address_info *hw_config)
2114 (void) uninstall_wavefront ();
2117 #endif /* OSS_SUPPORT_STATIC_INSTALL */
2119 /***********************************************************************/
2120 /* WaveFront: Linux modular sound kernel installation interface */
2121 /***********************************************************************/
2124 wavefrontintr(int irq, void *dev_id, struct pt_regs *dummy)
2126 struct wf_config *hw = dev_id;
2129 Some comments on interrupts. I attempted a version of this
2130 driver that used interrupts throughout the code instead of
2131 doing busy and/or sleep-waiting. Alas, it appears that once
2132 the Motorola firmware is downloaded, the card *never*
2133 generates an RX interrupt. These are successfully generated
2134 during firmware loading, and after that wavefront_status()
2135 reports that an interrupt is pending on the card from time
2136 to time, but it never seems to be delivered to this
2137 driver. Note also that wavefront_status() continues to
2138 report that RX interrupts are enabled, suggesting that I
2139 didn't goof up and disable them by mistake.
2141 Thus, I stepped back to a prior version of
2142 wavefront_wait(), the only place where this really
2143 matters. Its sad, but I've looked through the code to check
2144 on things, and I really feel certain that the Motorola
2145 firmware prevents RX-ready interrupts.
2148 if ((wavefront_status() & (STAT_INTR_READ|STAT_INTR_WRITE)) == 0) {
2154 wake_up_interruptible (&hw->interrupt_sleeper);
2160 0 Host Rx Interrupt Enable (1=Enabled)
2161 1 Host Rx Register Full (1=Full)
2162 2 Host Rx Interrupt Pending (1=Interrupt)
2164 4 Host Tx Interrupt (1=Enabled)
2165 5 Host Tx Register empty (1=Empty)
2166 6 Host Tx Interrupt Pending (1=Interrupt)
2171 wavefront_interrupt_bits (int irq)
2191 printk (KERN_WARNING LOGNAME "invalid IRQ %d\n", irq);
2199 wavefront_should_cause_interrupt (int val, int port, int timeout)
2202 unsigned long flags;
2204 /* this will not help on SMP - but at least it compiles */
2205 spin_lock_irqsave(&lock, flags);
2208 interruptible_sleep_on_timeout (&dev.interrupt_sleeper, timeout);
2209 spin_unlock_irqrestore(&lock,flags);
2212 static int __init wavefront_hw_reset (void)
2216 unsigned long irq_mask;
2219 /* IRQ already checked in init_module() */
2221 bits = wavefront_interrupt_bits (dev.irq);
2223 printk (KERN_DEBUG LOGNAME "autodetecting WaveFront IRQ\n");
2225 irq_mask = probe_irq_on ();
2227 outb (0x0, dev.control_port);
2228 outb (0x80 | 0x40 | bits, dev.data_port);
2229 wavefront_should_cause_interrupt(0x80|0x40|0x10|0x1,
2231 (reset_time*HZ)/100);
2233 reported_irq = probe_irq_off (irq_mask);
2235 if (reported_irq != dev.irq) {
2236 if (reported_irq == 0) {
2237 printk (KERN_ERR LOGNAME
2238 "No unassigned interrupts detected "
2239 "after h/w reset\n");
2240 } else if (reported_irq < 0) {
2241 printk (KERN_ERR LOGNAME
2242 "Multiple unassigned interrupts detected "
2243 "after h/w reset\n");
2245 printk (KERN_ERR LOGNAME "autodetected IRQ %d not the "
2246 "value provided (%d)\n", reported_irq,
2252 printk (KERN_INFO LOGNAME "autodetected IRQ at %d\n",
2256 if (request_irq (dev.irq, wavefrontintr,
2257 SA_INTERRUPT|SA_SHIRQ,
2258 "wavefront synth", &dev) < 0) {
2259 printk (KERN_WARNING LOGNAME "IRQ %d not available!\n",
2264 /* try reset of port */
2266 outb (0x0, dev.control_port);
2268 /* At this point, the board is in reset, and the H/W initialization
2269 register is accessed at the same address as the data port.
2271 Bit 7 - Enable IRQ Driver
2272 0 - Tri-state the Wave-Board drivers for the PC Bus IRQs
2273 1 - Enable IRQ selected by bits 5:3 to be driven onto the PC Bus.
2275 Bit 6 - MIDI Interface Select
2277 0 - Use the MIDI Input from the 26-pin WaveBlaster
2278 compatible header as the serial MIDI source
2279 1 - Use the MIDI Input from the 9-pin D connector as the
2282 Bits 5:3 - IRQ Selection
2293 Bit 0 - Disable Boot ROM
2294 0 - memory accesses to 03FC30-03FFFFH utilize the internal Boot ROM
2295 1 - memory accesses to 03FC30-03FFFFH are directed to external
2300 /* configure hardware: IRQ, enable interrupts,
2301 plus external 9-pin MIDI interface selected
2304 outb (0x80 | 0x40 | bits, dev.data_port);
2308 0 Host Rx Interrupt Enable (1=Enabled) 0x1
2312 4 Host Tx Interrupt Enable 0x10
2313 5 Mute (0=Mute; 1=Play) 0x20
2314 6 Master Interrupt Enable (1=Enabled) 0x40
2315 7 Master Reset (0=Reset; 1=Run) 0x80
2317 Take us out of reset, mute output, master + TX + RX interrupts on.
2319 We'll get an interrupt presumably to tell us that the TX
2323 wavefront_should_cause_interrupt(0x80|0x40|0x10|0x1,
2325 (reset_time*HZ)/100);
2327 /* Note: data port is now the data port, not the h/w initialization
2332 printk (KERN_WARNING LOGNAME
2333 "intr not received after h/w un-reset.\n");
2337 dev.interrupts_on = 1;
2339 /* Note: data port is now the data port, not the h/w initialization
2342 At this point, only "HW VERSION" or "DOWNLOAD OS" commands
2343 will work. So, issue one of them, and wait for TX
2344 interrupt. This can take a *long* time after a cold boot,
2345 while the ISC ROM does its RAM test. The SDK says up to 4
2346 seconds - with 12MB of RAM on a Tropez+, it takes a lot
2347 longer than that (~16secs). Note that the card understands
2348 the difference between a warm and a cold boot, so
2349 subsequent ISC2115 reboots (say, caused by module
2350 reloading) will get through this much faster.
2352 XXX Interesting question: why is no RX interrupt received first ?
2355 wavefront_should_cause_interrupt(WFC_HARDWARE_VERSION,
2356 dev.data_port, ramcheck_time*HZ);
2359 printk (KERN_WARNING LOGNAME
2360 "post-RAM-check interrupt not received.\n");
2364 if (!wavefront_wait (STAT_CAN_READ)) {
2365 printk (KERN_WARNING LOGNAME
2366 "no response to HW version cmd.\n");
2370 if ((hwv[0] = wavefront_read ()) == -1) {
2371 printk (KERN_WARNING LOGNAME
2372 "board not responding correctly.\n");
2376 if (hwv[0] == 0xFF) { /* NAK */
2378 /* Board's RAM test failed. Try to read error code,
2379 and tell us about it either way.
2382 if ((hwv[0] = wavefront_read ()) == -1) {
2383 printk (KERN_WARNING LOGNAME "on-board RAM test failed "
2384 "(bad error code).\n");
2386 printk (KERN_WARNING LOGNAME "on-board RAM test failed "
2387 "(error code: 0x%x).\n",
2393 /* We're OK, just get the next byte of the HW version response */
2395 if ((hwv[1] = wavefront_read ()) == -1) {
2396 printk (KERN_WARNING LOGNAME "incorrect h/w response.\n");
2400 printk (KERN_INFO LOGNAME "hardware version %d.%d\n",
2408 free_irq (dev.irq, &dev);
2414 static int __init detect_wavefront (int irq, int io_base)
2416 unsigned char rbuf[4], wbuf[4];
2418 /* TB docs say the device takes up 8 ports, but we know that
2419 if there is an FX device present (i.e. a Tropez+) it really
2423 if (check_region (io_base, 16)) {
2424 printk (KERN_ERR LOGNAME "IO address range 0x%x - 0x%x "
2425 "already in use - ignored\n", dev.base,
2433 dev.debug = debug_default;
2434 dev.interrupts_on = 0;
2436 dev.rom_samples_rdonly = 1; /* XXX default lock on ROM sample slots */
2438 if (wavefront_cmd (WFC_FIRMWARE_VERSION, rbuf, wbuf) == 0) {
2440 dev.fw_version[0] = rbuf[0];
2441 dev.fw_version[1] = rbuf[1];
2442 printk (KERN_INFO LOGNAME
2443 "firmware %d.%d already loaded.\n",
2446 /* check that a command actually works */
2448 if (wavefront_cmd (WFC_HARDWARE_VERSION,
2450 dev.hw_version[0] = rbuf[0];
2451 dev.hw_version[1] = rbuf[1];
2453 printk (KERN_WARNING LOGNAME "not raw, but no "
2454 "hardware version!\n");
2461 printk (KERN_INFO LOGNAME
2462 "reloading firmware anyway.\n");
2469 printk (KERN_INFO LOGNAME
2470 "no response to firmware probe, assume raw.\n");
2474 init_waitqueue_head (&dev.interrupt_sleeper);
2476 if (wavefront_hw_reset ()) {
2477 printk (KERN_WARNING LOGNAME "hardware reset failed\n");
2481 /* Check for FX device, present only on Tropez+ */
2483 dev.has_fx = (detect_wffx () == 0);
2489 #include <linux/fs.h>
2490 #include <linux/mm.h>
2491 #include <linux/slab.h>
2492 #include <asm/uaccess.h>
2496 wavefront_download_firmware (char *path)
2499 unsigned char section[WF_SECTION_MAX];
2500 char section_length; /* yes, just a char; max value is WF_SECTION_MAX */
2501 int section_cnt_downloaded = 0;
2507 /* This tries to be a bit cleverer than the stuff Alan Cox did for
2508 the generic sound firmware, in that it actually knows
2509 something about the structure of the Motorola firmware. In
2510 particular, it uses a version that has been stripped of the
2511 20K of useless header information, and had section lengths
2512 added, making it possible to load the entire OS without any
2513 [kv]malloc() activity, since the longest entity we ever read is
2514 42 bytes (well, WF_SECTION_MAX) long.
2520 if ((fd = sys_open (path, 0, 0)) < 0) {
2521 printk (KERN_WARNING LOGNAME "Unable to load \"%s\".\n",
2529 if ((x = sys_read (fd, §ion_length, sizeof (section_length))) !=
2530 sizeof (section_length)) {
2531 printk (KERN_ERR LOGNAME "firmware read error.\n");
2535 if (section_length == 0) {
2539 if (sys_read (fd, section, section_length) != section_length) {
2540 printk (KERN_ERR LOGNAME "firmware section "
2547 if (wavefront_write (WFC_DOWNLOAD_OS)) {
2551 for (i = 0; i < section_length; i++) {
2552 if (wavefront_write (section[i])) {
2559 if (wavefront_wait (STAT_CAN_READ)) {
2561 if ((c = inb (dev.data_port)) != WF_ACK) {
2563 printk (KERN_ERR LOGNAME "download "
2564 "of section #%d not "
2565 "acknowledged, ack = 0x%x\n",
2566 section_cnt_downloaded + 1, c);
2572 printk (KERN_ERR LOGNAME "time out for firmware ACK.\n");
2585 printk (KERN_ERR "\nWaveFront: firmware download failed!!!\n");
2589 static int __init wavefront_config_midi (void)
2591 unsigned char rbuf[4], wbuf[4];
2593 if (detect_wf_mpu (dev.irq, dev.base) < 0) {
2594 printk (KERN_WARNING LOGNAME
2595 "could not find working MIDI device\n");
2599 if ((dev.mididev = install_wf_mpu ()) < 0) {
2600 printk (KERN_WARNING LOGNAME
2601 "MIDI interfaces not configured\n");
2605 /* Route external MIDI to WaveFront synth (by default) */
2607 if (wavefront_cmd (WFC_MISYNTH_ON, rbuf, wbuf)) {
2608 printk (KERN_WARNING LOGNAME
2609 "cannot enable MIDI-IN to synth routing.\n");
2614 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2615 /* Get the regular MIDI patch loading function, so we can
2616 use it if we ever get handed a SYSEX patch. This is
2617 unlikely, because its so damn slow, but we may as well
2618 leave this functionality from maui.c behind, since it
2619 could be useful for sequencer applications that can
2620 only use MIDI to do patch loading.
2623 if (midi_devs[dev.mididev]->converter != NULL) {
2624 midi_load_patch = midi_devs[dev.mididev]->converter->load_patch;
2625 midi_devs[dev.mididev]->converter->load_patch =
2626 &wavefront_oss_load_patch;
2629 #endif /* OSS_SUPPORT_SEQ */
2631 /* Turn on Virtual MIDI, but first *always* turn it off,
2632 since otherwise consectutive reloads of the driver will
2633 never cause the hardware to generate the initial "internal" or
2634 "external" source bytes in the MIDI data stream. This
2635 is pretty important, since the internal hardware generally will
2636 be used to generate none or very little MIDI output, and
2637 thus the only source of MIDI data is actually external. Without
2638 the switch bytes, the driver will think it all comes from
2639 the internal interface. Duh.
2642 if (wavefront_cmd (WFC_VMIDI_OFF, rbuf, wbuf)) {
2643 printk (KERN_WARNING LOGNAME
2644 "virtual MIDI mode not disabled\n");
2645 return 0; /* We're OK, but missing the external MIDI dev */
2648 if ((dev.ext_mididev = virtual_midi_enable ()) < 0) {
2649 printk (KERN_WARNING LOGNAME "no virtual MIDI access.\n");
2651 if (wavefront_cmd (WFC_VMIDI_ON, rbuf, wbuf)) {
2652 printk (KERN_WARNING LOGNAME
2653 "cannot enable virtual MIDI mode.\n");
2654 virtual_midi_disable ();
2661 static int __init wavefront_do_reset (int atboot)
2665 if (!atboot && wavefront_hw_reset ()) {
2666 printk (KERN_WARNING LOGNAME "hw reset failed.\n");
2671 if (wavefront_download_firmware (ospath)) {
2677 /* Wait for the OS to get running. The protocol for
2678 this is non-obvious, and was determined by
2679 using port-IO tracing in DOSemu and some
2680 experimentation here.
2682 Rather than using timed waits, use interrupts creatively.
2685 wavefront_should_cause_interrupt (WFC_NOOP,
2690 printk (KERN_WARNING LOGNAME
2691 "no post-OS interrupt.\n");
2695 /* Now, do it again ! */
2697 wavefront_should_cause_interrupt (WFC_NOOP,
2698 dev.data_port, (10*HZ));
2701 printk (KERN_WARNING LOGNAME
2702 "no post-OS interrupt(2).\n");
2706 /* OK, no (RX/TX) interrupts any more, but leave mute
2710 outb (0x80|0x40, dev.control_port);
2712 /* No need for the IRQ anymore */
2714 free_irq (dev.irq, &dev);
2718 if (dev.has_fx && fx_raw) {
2722 /* SETUPSND.EXE asks for sample memory config here, but since i
2723 have no idea how to interpret the result, we'll forget
2727 if ((dev.freemem = wavefront_freemem ()) < 0) {
2731 printk (KERN_INFO LOGNAME "available DRAM %dk\n", dev.freemem / 1024);
2733 if (wavefront_write (0xf0) ||
2734 wavefront_write (1) ||
2735 (wavefront_read () < 0)) {
2737 printk (KERN_WARNING LOGNAME "MPU emulation mode not set.\n");
2743 if (wavefront_cmd (WFC_SET_NVOICES, NULL, voices)) {
2744 printk (KERN_WARNING LOGNAME
2745 "cannot set number of voices to 32.\n");
2753 /* reset that sucker so that it doesn't bother us. */
2755 outb (0x0, dev.control_port);
2756 dev.interrupts_on = 0;
2758 free_irq (dev.irq, &dev);
2763 static int __init wavefront_init (int atboot)
2765 int samples_are_from_rom;
2768 samples_are_from_rom = 1;
2770 /* XXX is this always true ? */
2771 samples_are_from_rom = 0;
2774 if (dev.israw || fx_raw) {
2775 if (wavefront_do_reset (atboot)) {
2780 wavefront_get_sample_status (samples_are_from_rom);
2781 wavefront_get_program_status ();
2782 wavefront_get_patch_status ();
2784 /* Start normal operation: unreset, master interrupt enabled, no mute
2787 outb (0x80|0x40|0x20, dev.control_port);
2792 static int __init install_wavefront (void)
2795 if ((dev.synth_dev = register_sound_synth (&wavefront_fops, -1)) < 0) {
2796 printk (KERN_ERR LOGNAME "cannot register raw synth\n");
2800 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2801 if ((dev.oss_dev = sound_alloc_synthdev()) == -1) {
2802 printk (KERN_ERR LOGNAME "Too many sequencers\n");
2805 synth_devs[dev.oss_dev] = &wavefront_operations;
2807 #endif /* OSS_SUPPORT_SEQ */
2809 if (wavefront_init (1) < 0) {
2810 printk (KERN_WARNING LOGNAME "initialization failed.\n");
2812 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2813 sound_unload_synthdev (dev.oss_dev);
2814 #endif /* OSS_SUPPORT_SEQ */
2819 request_region (dev.base+2, 6, "wavefront synth");
2822 request_region (dev.base+8, 8, "wavefront fx");
2825 if (wavefront_config_midi ()) {
2826 printk (KERN_WARNING LOGNAME "could not initialize MIDI.\n");
2832 static void __exit uninstall_wavefront (void)
2834 /* the first two i/o addresses are freed by the wf_mpu code */
2835 release_region (dev.base+2, 6);
2838 release_region (dev.base+8, 8);
2841 unregister_sound_synth (dev.synth_dev);
2843 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2844 sound_unload_synthdev (dev.oss_dev);
2845 #endif /* OSS_SUPPORT_SEQ */
2846 uninstall_wf_mpu ();
2849 /***********************************************************************/
2850 /* WaveFront FX control */
2851 /***********************************************************************/
2855 /* Control bits for the Load Control Register
2858 #define FX_LSB_TRANSFER 0x01 /* transfer after DSP LSB byte written */
2859 #define FX_MSB_TRANSFER 0x02 /* transfer after DSP MSB byte written */
2860 #define FX_AUTO_INCR 0x04 /* auto-increment DSP address after transfer */
2867 unsigned int x = 0x80;
2869 for (i = 0; i < 1000; i++) {
2870 x = inb (dev.fx_status);
2871 if ((x & 0x80) == 0) {
2877 printk (KERN_ERR LOGNAME "FX device never idle.\n");
2884 int __init detect_wffx (void)
2886 /* This is a crude check, but its the best one I have for now.
2887 Certainly on the Maui and the Tropez, wffx_idle() will
2888 report "never idle", which suggests that this test should
2892 if (inb (dev.fx_status) & 0x80) {
2893 printk (KERN_INFO LOGNAME "Hmm, probably a Maui or Tropez.\n");
2901 wffx_mute (int onoff)
2908 outb (onoff ? 0x02 : 0x00, dev.fx_op);
2912 wffx_memset (int page,
2913 int addr, int cnt, unsigned short *data)
2915 if (page < 0 || page > 7) {
2916 printk (KERN_ERR LOGNAME "FX memset: "
2917 "page must be >= 0 and <= 7\n");
2921 if (addr < 0 || addr > 0x7f) {
2922 printk (KERN_ERR LOGNAME "FX memset: "
2923 "addr must be >= 0 and <= 7f\n");
2929 outb (FX_LSB_TRANSFER, dev.fx_lcr);
2930 outb (page, dev.fx_dsp_page);
2931 outb (addr, dev.fx_dsp_addr);
2932 outb ((data[0] >> 8), dev.fx_dsp_msb);
2933 outb ((data[0] & 0xff), dev.fx_dsp_lsb);
2935 printk (KERN_INFO LOGNAME "FX: addr %d:%x set to 0x%x\n",
2936 page, addr, data[0]);
2941 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
2942 outb (page, dev.fx_dsp_page);
2943 outb (addr, dev.fx_dsp_addr);
2945 for (i = 0; i < cnt; i++) {
2946 outb ((data[i] >> 8), dev.fx_dsp_msb);
2947 outb ((data[i] & 0xff), dev.fx_dsp_lsb);
2948 if (!wffx_idle ()) {
2954 printk (KERN_WARNING LOGNAME
2956 "(0x%x, 0x%x, %p, %d) incomplete\n",
2957 page, addr, data, cnt);
2966 wffx_ioctl (wavefront_fx_info *r)
2969 unsigned short page_data[256];
2972 switch (r->request) {
2974 wffx_mute (r->data[0]);
2979 if (r->data[2] <= 0) {
2980 printk (KERN_ERR LOGNAME "cannot write "
2981 "<= 0 bytes to FX\n");
2983 } else if (r->data[2] == 1) {
2984 pd = (unsigned short *) &r->data[3];
2986 if (r->data[2] > sizeof (page_data)) {
2987 printk (KERN_ERR LOGNAME "cannot write "
2988 "> 255 bytes to FX\n");
2991 if (copy_from_user(page_data,
2992 (unsigned char __user *)r->data[3],
2998 return wffx_memset (r->data[0], /* page */
2999 r->data[1], /* addr */
3000 r->data[2], /* cnt */
3004 printk (KERN_WARNING LOGNAME
3005 "FX: ioctl %d not yet supported\n",
3011 /* YSS225 initialization.
3013 This code was developed using DOSEMU. The Turtle Beach SETUPSND
3014 utility was run with I/O tracing in DOSEMU enabled, and a reconstruction
3015 of the port I/O done, using the Yamaha faxback document as a guide
3016 to add more logic to the code. Its really pretty weird.
3018 There was an alternative approach of just dumping the whole I/O
3019 sequence as a series of port/value pairs and a simple loop
3020 that output it. However, I hope that eventually I'll get more
3021 control over what this code does, and so I tried to stick with
3022 a somewhat "algorithmic" approach.
3025 static int __init wffx_init (void)
3030 /* Set all bits for all channels on the MOD unit to zero */
3031 /* XXX But why do this twice ? */
3033 for (j = 0; j < 2; j++) {
3034 for (i = 0x10; i <= 0xff; i++) {
3036 if (!wffx_idle ()) {
3040 outb (i, dev.fx_mod_addr);
3041 outb (0x0, dev.fx_mod_data);
3045 if (!wffx_idle()) return (-1);
3046 outb (0x02, dev.fx_op); /* mute on */
3048 if (!wffx_idle()) return (-1);
3049 outb (0x07, dev.fx_dsp_page);
3050 outb (0x44, dev.fx_dsp_addr);
3051 outb (0x00, dev.fx_dsp_msb);
3052 outb (0x00, dev.fx_dsp_lsb);
3053 if (!wffx_idle()) return (-1);
3054 outb (0x07, dev.fx_dsp_page);
3055 outb (0x42, dev.fx_dsp_addr);
3056 outb (0x00, dev.fx_dsp_msb);
3057 outb (0x00, dev.fx_dsp_lsb);
3058 if (!wffx_idle()) return (-1);
3059 outb (0x07, dev.fx_dsp_page);
3060 outb (0x43, dev.fx_dsp_addr);
3061 outb (0x00, dev.fx_dsp_msb);
3062 outb (0x00, dev.fx_dsp_lsb);
3063 if (!wffx_idle()) return (-1);
3064 outb (0x07, dev.fx_dsp_page);
3065 outb (0x7c, dev.fx_dsp_addr);
3066 outb (0x00, dev.fx_dsp_msb);
3067 outb (0x00, dev.fx_dsp_lsb);
3068 if (!wffx_idle()) return (-1);
3069 outb (0x07, dev.fx_dsp_page);
3070 outb (0x7e, dev.fx_dsp_addr);
3071 outb (0x00, dev.fx_dsp_msb);
3072 outb (0x00, dev.fx_dsp_lsb);
3073 if (!wffx_idle()) return (-1);
3074 outb (0x07, dev.fx_dsp_page);
3075 outb (0x46, dev.fx_dsp_addr);
3076 outb (0x00, dev.fx_dsp_msb);
3077 outb (0x00, dev.fx_dsp_lsb);
3078 if (!wffx_idle()) return (-1);
3079 outb (0x07, dev.fx_dsp_page);
3080 outb (0x49, dev.fx_dsp_addr);
3081 outb (0x00, dev.fx_dsp_msb);
3082 outb (0x00, dev.fx_dsp_lsb);
3083 if (!wffx_idle()) return (-1);
3084 outb (0x07, dev.fx_dsp_page);
3085 outb (0x47, dev.fx_dsp_addr);
3086 outb (0x00, dev.fx_dsp_msb);
3087 outb (0x00, dev.fx_dsp_lsb);
3088 if (!wffx_idle()) return (-1);
3089 outb (0x07, dev.fx_dsp_page);
3090 outb (0x4a, dev.fx_dsp_addr);
3091 outb (0x00, dev.fx_dsp_msb);
3092 outb (0x00, dev.fx_dsp_lsb);
3094 /* either because of stupidity by TB's programmers, or because it
3095 actually does something, rezero the MOD page.
3097 for (i = 0x10; i <= 0xff; i++) {
3099 if (!wffx_idle ()) {
3103 outb (i, dev.fx_mod_addr);
3104 outb (0x0, dev.fx_mod_data);
3106 /* load page zero */
3108 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3109 outb (0x00, dev.fx_dsp_page);
3110 outb (0x00, dev.fx_dsp_addr);
3112 for (i = 0; i < sizeof (page_zero); i += 2) {
3113 outb (page_zero[i], dev.fx_dsp_msb);
3114 outb (page_zero[i+1], dev.fx_dsp_lsb);
3115 if (!wffx_idle()) return (-1);
3118 /* Now load page one */
3120 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3121 outb (0x01, dev.fx_dsp_page);
3122 outb (0x00, dev.fx_dsp_addr);
3124 for (i = 0; i < sizeof (page_one); i += 2) {
3125 outb (page_one[i], dev.fx_dsp_msb);
3126 outb (page_one[i+1], dev.fx_dsp_lsb);
3127 if (!wffx_idle()) return (-1);
3130 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3131 outb (0x02, dev.fx_dsp_page);
3132 outb (0x00, dev.fx_dsp_addr);
3134 for (i = 0; i < sizeof (page_two); i++) {
3135 outb (page_two[i], dev.fx_dsp_lsb);
3136 if (!wffx_idle()) return (-1);
3139 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3140 outb (0x03, dev.fx_dsp_page);
3141 outb (0x00, dev.fx_dsp_addr);
3143 for (i = 0; i < sizeof (page_three); i++) {
3144 outb (page_three[i], dev.fx_dsp_lsb);
3145 if (!wffx_idle()) return (-1);
3148 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3149 outb (0x04, dev.fx_dsp_page);
3150 outb (0x00, dev.fx_dsp_addr);
3152 for (i = 0; i < sizeof (page_four); i++) {
3153 outb (page_four[i], dev.fx_dsp_lsb);
3154 if (!wffx_idle()) return (-1);
3157 /* Load memory area (page six) */
3159 outb (FX_LSB_TRANSFER, dev.fx_lcr);
3160 outb (0x06, dev.fx_dsp_page);
3162 for (i = 0; i < sizeof (page_six); i += 3) {
3163 outb (page_six[i], dev.fx_dsp_addr);
3164 outb (page_six[i+1], dev.fx_dsp_msb);
3165 outb (page_six[i+2], dev.fx_dsp_lsb);
3166 if (!wffx_idle()) return (-1);
3169 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3170 outb (0x07, dev.fx_dsp_page);
3171 outb (0x00, dev.fx_dsp_addr);
3173 for (i = 0; i < sizeof (page_seven); i += 2) {
3174 outb (page_seven[i], dev.fx_dsp_msb);
3175 outb (page_seven[i+1], dev.fx_dsp_lsb);
3176 if (!wffx_idle()) return (-1);
3179 /* Now setup the MOD area. We do this algorithmically in order to
3180 save a little data space. It could be done in the same fashion
3184 for (i = 0x00; i <= 0x0f; i++) {
3185 outb (0x01, dev.fx_mod_addr);
3186 outb (i, dev.fx_mod_data);
3187 if (!wffx_idle()) return (-1);
3188 outb (0x02, dev.fx_mod_addr);
3189 outb (0x00, dev.fx_mod_data);
3190 if (!wffx_idle()) return (-1);
3193 for (i = 0xb0; i <= 0xbf; i++) {
3194 outb (i, dev.fx_mod_addr);
3195 outb (0x20, dev.fx_mod_data);
3196 if (!wffx_idle()) return (-1);
3199 for (i = 0xf0; i <= 0xff; i++) {
3200 outb (i, dev.fx_mod_addr);
3201 outb (0x20, dev.fx_mod_data);
3202 if (!wffx_idle()) return (-1);
3205 for (i = 0x10; i <= 0x1d; i++) {
3206 outb (i, dev.fx_mod_addr);
3207 outb (0xff, dev.fx_mod_data);
3208 if (!wffx_idle()) return (-1);
3211 outb (0x1e, dev.fx_mod_addr);
3212 outb (0x40, dev.fx_mod_data);
3213 if (!wffx_idle()) return (-1);
3215 for (i = 0x1f; i <= 0x2d; i++) {
3216 outb (i, dev.fx_mod_addr);
3217 outb (0xff, dev.fx_mod_data);
3218 if (!wffx_idle()) return (-1);
3221 outb (0x2e, dev.fx_mod_addr);
3222 outb (0x00, dev.fx_mod_data);
3223 if (!wffx_idle()) return (-1);
3225 for (i = 0x2f; i <= 0x3e; i++) {
3226 outb (i, dev.fx_mod_addr);
3227 outb (0x00, dev.fx_mod_data);
3228 if (!wffx_idle()) return (-1);
3231 outb (0x3f, dev.fx_mod_addr);
3232 outb (0x20, dev.fx_mod_data);
3233 if (!wffx_idle()) return (-1);
3235 for (i = 0x40; i <= 0x4d; i++) {
3236 outb (i, dev.fx_mod_addr);
3237 outb (0x00, dev.fx_mod_data);
3238 if (!wffx_idle()) return (-1);
3241 outb (0x4e, dev.fx_mod_addr);
3242 outb (0x0e, dev.fx_mod_data);
3243 if (!wffx_idle()) return (-1);
3244 outb (0x4f, dev.fx_mod_addr);
3245 outb (0x0e, dev.fx_mod_data);
3246 if (!wffx_idle()) return (-1);
3249 for (i = 0x50; i <= 0x6b; i++) {
3250 outb (i, dev.fx_mod_addr);
3251 outb (0x00, dev.fx_mod_data);
3252 if (!wffx_idle()) return (-1);
3255 outb (0x6c, dev.fx_mod_addr);
3256 outb (0x40, dev.fx_mod_data);
3257 if (!wffx_idle()) return (-1);
3259 outb (0x6d, dev.fx_mod_addr);
3260 outb (0x00, dev.fx_mod_data);
3261 if (!wffx_idle()) return (-1);
3263 outb (0x6e, dev.fx_mod_addr);
3264 outb (0x40, dev.fx_mod_data);
3265 if (!wffx_idle()) return (-1);
3267 outb (0x6f, dev.fx_mod_addr);
3268 outb (0x40, dev.fx_mod_data);
3269 if (!wffx_idle()) return (-1);
3271 for (i = 0x70; i <= 0x7f; i++) {
3272 outb (i, dev.fx_mod_addr);
3273 outb (0xc0, dev.fx_mod_data);
3274 if (!wffx_idle()) return (-1);
3277 for (i = 0x80; i <= 0xaf; i++) {
3278 outb (i, dev.fx_mod_addr);
3279 outb (0x00, dev.fx_mod_data);
3280 if (!wffx_idle()) return (-1);
3283 for (i = 0xc0; i <= 0xdd; i++) {
3284 outb (i, dev.fx_mod_addr);
3285 outb (0x00, dev.fx_mod_data);
3286 if (!wffx_idle()) return (-1);
3289 outb (0xde, dev.fx_mod_addr);
3290 outb (0x10, dev.fx_mod_data);
3291 if (!wffx_idle()) return (-1);
3292 outb (0xdf, dev.fx_mod_addr);
3293 outb (0x10, dev.fx_mod_data);
3294 if (!wffx_idle()) return (-1);
3296 for (i = 0xe0; i <= 0xef; i++) {
3297 outb (i, dev.fx_mod_addr);
3298 outb (0x00, dev.fx_mod_data);
3299 if (!wffx_idle()) return (-1);
3302 for (i = 0x00; i <= 0x0f; i++) {
3303 outb (0x01, dev.fx_mod_addr);
3304 outb (i, dev.fx_mod_data);
3305 outb (0x02, dev.fx_mod_addr);
3306 outb (0x01, dev.fx_mod_data);
3307 if (!wffx_idle()) return (-1);
3310 outb (0x02, dev.fx_op); /* mute on */
3312 /* Now set the coefficients and so forth for the programs above */
3314 for (i = 0; i < sizeof (coefficients); i += 4) {
3315 outb (coefficients[i], dev.fx_dsp_page);
3316 outb (coefficients[i+1], dev.fx_dsp_addr);
3317 outb (coefficients[i+2], dev.fx_dsp_msb);
3318 outb (coefficients[i+3], dev.fx_dsp_lsb);
3319 if (!wffx_idle()) return (-1);
3322 /* Some settings (?) that are too small to bundle into loops */
3324 if (!wffx_idle()) return (-1);
3325 outb (0x1e, dev.fx_mod_addr);
3326 outb (0x14, dev.fx_mod_data);
3327 if (!wffx_idle()) return (-1);
3328 outb (0xde, dev.fx_mod_addr);
3329 outb (0x20, dev.fx_mod_data);
3330 if (!wffx_idle()) return (-1);
3331 outb (0xdf, dev.fx_mod_addr);
3332 outb (0x20, dev.fx_mod_data);
3334 /* some more coefficients */
3336 if (!wffx_idle()) return (-1);
3337 outb (0x06, dev.fx_dsp_page);
3338 outb (0x78, dev.fx_dsp_addr);
3339 outb (0x00, dev.fx_dsp_msb);
3340 outb (0x40, dev.fx_dsp_lsb);
3341 if (!wffx_idle()) return (-1);
3342 outb (0x07, dev.fx_dsp_page);
3343 outb (0x03, dev.fx_dsp_addr);
3344 outb (0x0f, dev.fx_dsp_msb);
3345 outb (0xff, dev.fx_dsp_lsb);
3346 if (!wffx_idle()) return (-1);
3347 outb (0x07, dev.fx_dsp_page);
3348 outb (0x0b, dev.fx_dsp_addr);
3349 outb (0x0f, dev.fx_dsp_msb);
3350 outb (0xff, dev.fx_dsp_lsb);
3351 if (!wffx_idle()) return (-1);
3352 outb (0x07, dev.fx_dsp_page);
3353 outb (0x02, dev.fx_dsp_addr);
3354 outb (0x00, dev.fx_dsp_msb);
3355 outb (0x00, dev.fx_dsp_lsb);
3356 if (!wffx_idle()) return (-1);
3357 outb (0x07, dev.fx_dsp_page);
3358 outb (0x0a, dev.fx_dsp_addr);
3359 outb (0x00, dev.fx_dsp_msb);
3360 outb (0x00, dev.fx_dsp_lsb);
3361 if (!wffx_idle()) return (-1);
3362 outb (0x07, dev.fx_dsp_page);
3363 outb (0x46, dev.fx_dsp_addr);
3364 outb (0x00, dev.fx_dsp_msb);
3365 outb (0x00, dev.fx_dsp_lsb);
3366 if (!wffx_idle()) return (-1);
3367 outb (0x07, dev.fx_dsp_page);
3368 outb (0x49, dev.fx_dsp_addr);
3369 outb (0x00, dev.fx_dsp_msb);
3370 outb (0x00, dev.fx_dsp_lsb);
3372 /* Now, for some strange reason, lets reload every page
3373 and all the coefficients over again. I have *NO* idea
3374 why this is done. I do know that no sound is produced
3375 is this phase is omitted.
3378 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3379 outb (0x00, dev.fx_dsp_page);
3380 outb (0x10, dev.fx_dsp_addr);
3382 for (i = 0; i < sizeof (page_zero_v2); i += 2) {
3383 outb (page_zero_v2[i], dev.fx_dsp_msb);
3384 outb (page_zero_v2[i+1], dev.fx_dsp_lsb);
3385 if (!wffx_idle()) return (-1);
3388 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3389 outb (0x01, dev.fx_dsp_page);
3390 outb (0x10, dev.fx_dsp_addr);
3392 for (i = 0; i < sizeof (page_one_v2); i += 2) {
3393 outb (page_one_v2[i], dev.fx_dsp_msb);
3394 outb (page_one_v2[i+1], dev.fx_dsp_lsb);
3395 if (!wffx_idle()) return (-1);
3398 if (!wffx_idle()) return (-1);
3399 if (!wffx_idle()) return (-1);
3401 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3402 outb (0x02, dev.fx_dsp_page);
3403 outb (0x10, dev.fx_dsp_addr);
3405 for (i = 0; i < sizeof (page_two_v2); i++) {
3406 outb (page_two_v2[i], dev.fx_dsp_lsb);
3407 if (!wffx_idle()) return (-1);
3409 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3410 outb (0x03, dev.fx_dsp_page);
3411 outb (0x10, dev.fx_dsp_addr);
3413 for (i = 0; i < sizeof (page_three_v2); i++) {
3414 outb (page_three_v2[i], dev.fx_dsp_lsb);
3415 if (!wffx_idle()) return (-1);
3418 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3419 outb (0x04, dev.fx_dsp_page);
3420 outb (0x10, dev.fx_dsp_addr);
3422 for (i = 0; i < sizeof (page_four_v2); i++) {
3423 outb (page_four_v2[i], dev.fx_dsp_lsb);
3424 if (!wffx_idle()) return (-1);
3427 outb (FX_LSB_TRANSFER, dev.fx_lcr);
3428 outb (0x06, dev.fx_dsp_page);
3430 /* Page six v.2 is algorithmic */
3432 for (i = 0x10; i <= 0x3e; i += 2) {
3433 outb (i, dev.fx_dsp_addr);
3434 outb (0x00, dev.fx_dsp_msb);
3435 outb (0x00, dev.fx_dsp_lsb);
3436 if (!wffx_idle()) return (-1);
3439 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3440 outb (0x07, dev.fx_dsp_page);
3441 outb (0x10, dev.fx_dsp_addr);
3443 for (i = 0; i < sizeof (page_seven_v2); i += 2) {
3444 outb (page_seven_v2[i], dev.fx_dsp_msb);
3445 outb (page_seven_v2[i+1], dev.fx_dsp_lsb);
3446 if (!wffx_idle()) return (-1);
3449 for (i = 0x00; i < sizeof(mod_v2); i += 2) {
3450 outb (mod_v2[i], dev.fx_mod_addr);
3451 outb (mod_v2[i+1], dev.fx_mod_data);
3452 if (!wffx_idle()) return (-1);
3455 for (i = 0; i < sizeof (coefficients2); i += 4) {
3456 outb (coefficients2[i], dev.fx_dsp_page);
3457 outb (coefficients2[i+1], dev.fx_dsp_addr);
3458 outb (coefficients2[i+2], dev.fx_dsp_msb);
3459 outb (coefficients2[i+3], dev.fx_dsp_lsb);
3460 if (!wffx_idle()) return (-1);
3463 for (i = 0; i < sizeof (coefficients3); i += 2) {
3466 outb (0x07, dev.fx_dsp_page);
3467 x = (i % 4) ? 0x4e : 0x4c;
3468 outb (x, dev.fx_dsp_addr);
3469 outb (coefficients3[i], dev.fx_dsp_msb);
3470 outb (coefficients3[i+1], dev.fx_dsp_lsb);
3473 outb (0x00, dev.fx_op); /* mute off */
3474 if (!wffx_idle()) return (-1);
3480 static int irq = -1;
3482 MODULE_AUTHOR ("Paul Barton-Davis <pbd@op.net>");
3483 MODULE_DESCRIPTION ("Turtle Beach WaveFront Linux Driver");
3484 MODULE_LICENSE("GPL");
3485 module_param (io, int, 0);
3486 module_param (irq, int, 0);
3488 static int __init init_wavfront (void)
3490 printk ("Turtle Beach WaveFront Driver\n"
3491 "Copyright (C) by Hannu Solvainen, "
3492 "Paul Barton-Davis 1993-1998.\n");
3494 /* XXX t'would be lovely to ask the CS4232 for these values, eh ? */
3496 if (io == -1 || irq == -1) {
3497 printk (KERN_INFO LOGNAME "irq and io options must be set.\n");
3501 if (wavefront_interrupt_bits (irq) < 0) {
3502 printk (KERN_INFO LOGNAME
3503 "IRQ must be 9, 5, 12 or 15 (not %d)\n", irq);
3507 if (detect_wavefront (irq, io) < 0) {
3511 if (install_wavefront () < 0) {
3518 static void __exit cleanup_wavfront (void)
3520 uninstall_wavefront ();
3523 module_init(init_wavfront);
3524 module_exit(cleanup_wavfront);