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
65 #include <linux/module.h>
67 #include <linux/kernel.h>
68 #include <linux/init.h>
69 #include <linux/sched.h>
70 #include <linux/smp_lock.h>
71 #include <linux/ptrace.h>
72 #include <linux/fcntl.h>
73 #include <linux/ioport.h>
75 #include <linux/interrupt.h>
76 #include <linux/config.h>
78 #include <linux/delay.h>
80 #include "sound_config.h"
82 #include <linux/wavefront.h>
85 * This sucks, hopefully it'll get standardised
88 #if defined(__alpha__)
90 #define LOOPS_PER_SEC cpu_data[smp_processor_id()].loops_per_sec
92 #define LOOPS_PER_SEC loops_per_sec
97 #define LOOPS_PER_SEC current_cpu_data.loops_per_sec
100 #define _MIDI_SYNTH_C_
101 #define MIDI_SYNTH_NAME "WaveFront MIDI"
102 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
103 #include "midi_synth.h"
105 /* Compile-time control of the extent to which OSS is supported.
107 I consider /dev/sequencer to be an anachronism, but given its
108 widespread usage by various Linux MIDI software, it seems worth
109 offering support to it if its not too painful. Instead of using
110 /dev/sequencer, I recommend:
112 for synth programming and patch loading: /dev/synthNN
113 for kernel-synchronized MIDI sequencing: the ALSA sequencer
114 for direct MIDI control: /dev/midiNN
116 I have never tried static compilation into the kernel. The #if's
117 for this are really just notes to myself about what the code is
121 #define OSS_SUPPORT_SEQ 0x1 /* use of /dev/sequencer */
122 #define OSS_SUPPORT_STATIC_INSTALL 0x2 /* static compilation into kernel */
124 #define OSS_SUPPORT_LEVEL 0x1 /* just /dev/sequencer for now */
126 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
127 static int (*midi_load_patch
) (int devno
, int format
, const char *addr
,
128 int offs
, int count
, int pmgr_flag
) = NULL
;
129 #endif OSS_SUPPORT_SEQ
131 /* if WF_DEBUG not defined, no run-time debugging messages will
132 be available via the debug flag setting. Given the current
133 beta state of the driver, this will remain set until a future
141 /* Thank goodness for gcc's preprocessor ... */
143 #define DPRINT(cond, format, args...) \
144 if ((dev.debug & (cond)) == (cond)) { \
145 printk (KERN_DEBUG LOGNAME format, ## args); \
148 #define DPRINT(cond, format, args...)
151 #define LOGNAME "WaveFront: "
153 /* bitmasks for WaveFront status port value */
155 #define STAT_RINTR_ENABLED 0x01
156 #define STAT_CAN_READ 0x02
157 #define STAT_INTR_READ 0x04
158 #define STAT_WINTR_ENABLED 0x10
159 #define STAT_CAN_WRITE 0x20
160 #define STAT_INTR_WRITE 0x40
162 /*** Module-accessible parameters ***************************************/
164 int wf_raw
= 0; /* we normally check for "raw state" to firmware
165 loading. if set, then during driver loading, the
166 state of the board is ignored, and we reset the
167 board and load the firmware anyway.
170 int fx_raw
= 1; /* if this is zero, we'll leave the FX processor in
171 whatever state it is when the driver is loaded.
172 The default is to download the microprogram and
173 associated coefficients to set it up for "default"
174 operation, whatever that means.
177 int debug_default
= 0; /* you can set this to control debugging
178 during driver loading. it takes any combination
179 of the WF_DEBUG_* flags defined in
183 /* XXX this needs to be made firmware and hardware version dependent */
185 char *ospath
= "/etc/sound/wavefront.os"; /* where to find a processed
186 version of the WaveFront OS
189 int wait_usecs
= 150; /* This magic number seems to give pretty optimal
190 throughput based on my limited experimentation.
191 If you want to play around with it and find a better
192 value, be my guest. Remember, the idea is to
193 get a number that causes us to just busy wait
194 for as many WaveFront commands as possible, without
195 coming up with a number so large that we hog the
198 Specifically, with this number, out of about 134,000
199 status waits, only about 250 result in a sleep.
202 int sleep_interval
= 100; /* HZ/sleep_interval seconds per sleep */
203 int sleep_tries
= 50; /* number of times we'll try to sleep */
205 int reset_time
= 2; /* hundreths of a second we wait after a HW reset for
206 the expected interrupt.
209 int ramcheck_time
= 20; /* time in seconds to wait while ROM code
213 int osrun_time
= 10; /* time in seconds we wait for the OS to
217 MODULE_PARM(wf_raw
,"i");
218 MODULE_PARM(fx_raw
,"i");
219 MODULE_PARM(debug_default
,"i");
220 MODULE_PARM(wait_usecs
,"i");
221 MODULE_PARM(sleep_interval
,"i");
222 MODULE_PARM(sleep_tries
,"i");
223 MODULE_PARM(ospath
,"s");
224 MODULE_PARM(reset_time
,"i");
225 MODULE_PARM(ramcheck_time
,"i");
226 MODULE_PARM(osrun_time
,"i");
228 /***************************************************************************/
230 /* Note: because this module doesn't export any symbols, this really isn't
231 a global variable, even if it looks like one. I was quite confused by
232 this when I started writing this as a (newer) module -- pbd.
236 int devno
; /* device number from kernel */
237 int irq
; /* "you were one, one of the few ..." */
238 int base
; /* low i/o port address */
240 #define mpu_data_port base
241 #define mpu_command_port base + 1 /* write semantics */
242 #define mpu_status_port base + 1 /* read semantics */
243 #define data_port base + 2
244 #define status_port base + 3 /* read semantics */
245 #define control_port base + 3 /* write semantics */
246 #define block_port base + 4 /* 16 bit, writeonly */
247 #define last_block_port base + 6 /* 16 bit, writeonly */
249 /* FX ports. These are mapped through the ICS2115 to the YS225.
250 The ICS2115 takes care of flipping the relevant pins on the
251 YS225 so that access to each of these ports does the right
252 thing. Note: these are NOT documented by Turtle Beach.
255 #define fx_status base + 8
256 #define fx_op base + 8
257 #define fx_lcr base + 9
258 #define fx_dsp_addr base + 0xa
259 #define fx_dsp_page base + 0xb
260 #define fx_dsp_lsb base + 0xc
261 #define fx_dsp_msb base + 0xd
262 #define fx_mod_addr base + 0xe
263 #define fx_mod_data base + 0xf
265 volatile int irq_ok
; /* set by interrupt handler */
266 volatile int irq_cnt
; /* ditto */
267 int opened
; /* flag, holds open(2) mode */
268 char debug
; /* debugging flags */
269 int freemem
; /* installed RAM, in bytes */
271 int synth_dev
; /* devno for "raw" synth */
272 int mididev
; /* devno for internal MIDI */
273 int ext_mididev
; /* devno for external MIDI */
274 int fx_mididev
; /* devno for FX MIDI interface */
275 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
276 int oss_dev
; /* devno for OSS sequencer synth */
277 #endif OSS_SUPPORT_SEQ
279 char fw_version
[2]; /* major = [0], minor = [1] */
280 char hw_version
[2]; /* major = [0], minor = [1] */
281 char israw
; /* needs Motorola microcode */
282 char has_fx
; /* has FX processor (Tropez+) */
283 char prog_status
[WF_MAX_PROGRAM
]; /* WF_SLOT_* */
284 char patch_status
[WF_MAX_PATCH
]; /* WF_SLOT_* */
285 char sample_status
[WF_MAX_SAMPLE
]; /* WF_ST_* | WF_SLOT_* */
286 int samples_used
; /* how many */
287 char interrupts_on
; /* h/w MPU interrupts enabled ? */
288 char rom_samples_rdonly
; /* can we write on ROM samples */
289 wait_queue_head_t interrupt_sleeper
;
292 static int detect_wffx(void);
293 static int wffx_ioctl (wavefront_fx_info
*);
294 static int wffx_init (void);
296 static int wavefront_delete_sample (int sampnum
);
297 static int wavefront_find_free_sample (void);
301 extern int virtual_midi_enable (void);
302 extern int virtual_midi_disable (void);
303 extern int detect_wf_mpu (int, int);
304 extern int install_wf_mpu (void);
305 extern int uninstall_wf_mpu (void);
310 unsigned int read_cnt
;
311 unsigned int write_cnt
;
318 } wavefront_errors
[] = {
319 { 0x01, "Bad sample number" },
320 { 0x02, "Out of sample memory" },
321 { 0x03, "Bad patch number" },
322 { 0x04, "Error in number of voices" },
323 { 0x06, "Sample load already in progress" },
324 { 0x0B, "No sample load request pending" },
325 { 0x0E, "Bad MIDI channel number" },
326 { 0x10, "Download Record Error" },
333 static wavefront_command wavefront_commands
[] = {
334 { WFC_SET_SYNTHVOL
, "set synthesizer volume", 0, 1, NEEDS_ACK
},
335 { WFC_GET_SYNTHVOL
, "get synthesizer volume", 1, 0, 0},
336 { WFC_SET_NVOICES
, "set number of voices", 0, 1, NEEDS_ACK
},
337 { WFC_GET_NVOICES
, "get number of voices", 1, 0, 0 },
338 { WFC_SET_TUNING
, "set synthesizer tuning", 0, 2, NEEDS_ACK
},
339 { WFC_GET_TUNING
, "get synthesizer tuning", 2, 0, 0 },
340 { WFC_DISABLE_CHANNEL
, "disable synth channel", 0, 1, NEEDS_ACK
},
341 { WFC_ENABLE_CHANNEL
, "enable synth channel", 0, 1, NEEDS_ACK
},
342 { WFC_GET_CHANNEL_STATUS
, "get synth channel status", 3, 0, 0 },
343 { WFC_MISYNTH_OFF
, "disable midi-in to synth", 0, 0, NEEDS_ACK
},
344 { WFC_MISYNTH_ON
, "enable midi-in to synth", 0, 0, NEEDS_ACK
},
345 { WFC_VMIDI_ON
, "enable virtual midi mode", 0, 0, NEEDS_ACK
},
346 { WFC_VMIDI_OFF
, "disable virtual midi mode", 0, 0, NEEDS_ACK
},
347 { WFC_MIDI_STATUS
, "report midi status", 1, 0, 0 },
348 { WFC_FIRMWARE_VERSION
, "report firmware version", 2, 0, 0 },
349 { WFC_HARDWARE_VERSION
, "report hardware version", 2, 0, 0 },
350 { WFC_GET_NSAMPLES
, "report number of samples", 2, 0, 0 },
351 { WFC_INSTOUT_LEVELS
, "report instantaneous output levels", 7, 0, 0 },
352 { WFC_PEAKOUT_LEVELS
, "report peak output levels", 7, 0, 0 },
353 { WFC_DOWNLOAD_SAMPLE
, "download sample",
354 0, WF_SAMPLE_BYTES
, NEEDS_ACK
},
355 { WFC_DOWNLOAD_BLOCK
, "download block", 0, 0, NEEDS_ACK
},
356 { WFC_DOWNLOAD_SAMPLE_HEADER
, "download sample header",
357 0, WF_SAMPLE_HDR_BYTES
, NEEDS_ACK
},
358 { WFC_UPLOAD_SAMPLE_HEADER
, "upload sample header", 13, 2, 0 },
360 /* This command requires a variable number of bytes to be written.
361 There is a hack in wavefront_cmd() to support this. The actual
362 count is passed in as the read buffer ptr, cast appropriately.
366 { WFC_DOWNLOAD_MULTISAMPLE
, "download multisample", 0, 0, NEEDS_ACK
},
368 /* This one is a hack as well. We just read the first byte of the
369 response, don't fetch an ACK, and leave the rest to the
370 calling function. Ugly, ugly, ugly.
373 { WFC_UPLOAD_MULTISAMPLE
, "upload multisample", 2, 1, 0 },
374 { WFC_DOWNLOAD_SAMPLE_ALIAS
, "download sample alias",
375 0, WF_ALIAS_BYTES
, NEEDS_ACK
},
376 { WFC_UPLOAD_SAMPLE_ALIAS
, "upload sample alias", WF_ALIAS_BYTES
, 2, 0},
377 { WFC_DELETE_SAMPLE
, "delete sample", 0, 2, NEEDS_ACK
},
378 { WFC_IDENTIFY_SAMPLE_TYPE
, "identify sample type", 5, 2, 0 },
379 { WFC_UPLOAD_SAMPLE_PARAMS
, "upload sample parameters" },
380 { WFC_REPORT_FREE_MEMORY
, "report free memory", 4, 0, 0 },
381 { WFC_DOWNLOAD_PATCH
, "download patch", 0, 134, NEEDS_ACK
},
382 { WFC_UPLOAD_PATCH
, "upload patch", 132, 2, 0 },
383 { WFC_DOWNLOAD_PROGRAM
, "download program", 0, 33, NEEDS_ACK
},
384 { WFC_UPLOAD_PROGRAM
, "upload program", 32, 1, 0 },
385 { WFC_DOWNLOAD_EDRUM_PROGRAM
, "download enhanced drum program", 0, 9,
387 { WFC_UPLOAD_EDRUM_PROGRAM
, "upload enhanced drum program", 8, 1, 0},
388 { WFC_SET_EDRUM_CHANNEL
, "set enhanced drum program channel",
390 { WFC_DISABLE_DRUM_PROGRAM
, "disable drum program", 0, 1, NEEDS_ACK
},
391 { WFC_REPORT_CHANNEL_PROGRAMS
, "report channel program numbers",
393 { WFC_NOOP
, "the no-op command", 0, 0, NEEDS_ACK
},
398 wavefront_errorstr (int errnum
)
403 for (i
= 0; wavefront_errors
[i
].errstr
; i
++) {
404 if (wavefront_errors
[i
].errno
== errnum
) {
405 return wavefront_errors
[i
].errstr
;
409 return "Unknown WaveFront error";
412 static wavefront_command
*
413 wavefront_get_command (int cmd
)
418 for (i
= 0; wavefront_commands
[i
].cmd
!= 0; i
++) {
419 if (cmd
== wavefront_commands
[i
].cmd
) {
420 return &wavefront_commands
[i
];
424 return (wavefront_command
*) 0;
428 wavefront_status (void)
431 return inb (dev
.status_port
);
435 wavefront_sleep (int limit
)
438 current
->state
= TASK_INTERRUPTIBLE
;
439 schedule_timeout(limit
);
441 return signal_pending(current
);
445 wavefront_wait (int mask
)
449 static int short_loop_cnt
= 0;
451 /* Compute the loop count that lets us sleep for about the
452 right amount of time, cache issues, bus speeds and all
453 other issues being unequal but largely irrelevant.
456 if (short_loop_cnt
== 0) {
457 short_loop_cnt
= wait_usecs
*
458 (LOOPS_PER_SEC
/ 1000000);
461 /* Spin for a short period of time, because >99% of all
462 requests to the WaveFront can be serviced inline like this.
465 for (i
= 0; i
< short_loop_cnt
; i
++) {
466 if (wavefront_status() & mask
) {
471 for (i
= 0; i
< sleep_tries
; i
++) {
473 if (wavefront_status() & mask
) {
477 if (wavefront_sleep (HZ
/sleep_interval
)) {
486 wavefront_read (void)
489 if (wavefront_wait (STAT_CAN_READ
))
490 return inb (dev
.data_port
);
492 DPRINT (WF_DEBUG_DATA
, "read timeout.\n");
498 wavefront_write (unsigned char data
)
501 if (wavefront_wait (STAT_CAN_WRITE
)) {
502 outb (data
, dev
.data_port
);
506 DPRINT (WF_DEBUG_DATA
, "write timeout.\n");
512 wavefront_cmd (int cmd
, unsigned char *rbuf
, unsigned char *wbuf
)
518 wavefront_command
*wfcmd
;
520 if ((wfcmd
= wavefront_get_command (cmd
)) == (wavefront_command
*) 0) {
521 printk (KERN_WARNING LOGNAME
"command 0x%x not supported.\n",
526 /* Hack to handle the one variable-size write command. See
527 wavefront_send_multisample() for the other half of this
528 gross and ugly strategy.
531 if (cmd
== WFC_DOWNLOAD_MULTISAMPLE
) {
532 wfcmd
->write_cnt
= (unsigned int) rbuf
;
536 DPRINT (WF_DEBUG_CMD
, "0x%x [%s] (%d,%d,%d)\n",
537 cmd
, wfcmd
->action
, wfcmd
->read_cnt
,
538 wfcmd
->write_cnt
, wfcmd
->need_ack
);
540 if (wavefront_write (cmd
)) {
541 DPRINT ((WF_DEBUG_IO
|WF_DEBUG_CMD
), "cannot request "
547 if (wfcmd
->write_cnt
> 0) {
548 DPRINT (WF_DEBUG_DATA
, "writing %d bytes "
550 wfcmd
->write_cnt
, cmd
);
552 for (i
= 0; i
< wfcmd
->write_cnt
; i
++) {
553 if (wavefront_write (wbuf
[i
])) {
554 DPRINT (WF_DEBUG_IO
, "bad write for byte "
555 "%d of 0x%x [%s].\n",
556 i
, cmd
, wfcmd
->action
);
560 DPRINT (WF_DEBUG_DATA
, "write[%d] = 0x%x\n",
565 if (wfcmd
->read_cnt
> 0) {
566 DPRINT (WF_DEBUG_DATA
, "reading %d ints "
568 wfcmd
->read_cnt
, cmd
);
570 for (i
= 0; i
< wfcmd
->read_cnt
; i
++) {
572 if ((c
= wavefront_read()) == -1) {
573 DPRINT (WF_DEBUG_IO
, "bad read for byte "
574 "%d of 0x%x [%s].\n",
575 i
, cmd
, wfcmd
->action
);
579 /* Now handle errors. Lots of special cases here */
582 if ((c
= wavefront_read ()) == -1) {
583 DPRINT (WF_DEBUG_IO
, "bad read for "
592 /* Can you believe this madness ? */
595 wfcmd
->cmd
== WFC_IDENTIFY_SAMPLE_TYPE
) {
596 rbuf
[0] = WF_ST_EMPTY
;
600 wfcmd
->cmd
== WFC_UPLOAD_PATCH
) {
605 wfcmd
->cmd
== WFC_UPLOAD_PROGRAM
) {
611 DPRINT (WF_DEBUG_IO
, "error %d (%s) "
617 wavefront_errorstr (c
),
628 DPRINT (WF_DEBUG_DATA
, "read[%d] = 0x%x\n",i
, rbuf
[i
]);
632 if ((wfcmd
->read_cnt
== 0 && wfcmd
->write_cnt
== 0) || wfcmd
->need_ack
) {
634 DPRINT (WF_DEBUG_CMD
, "reading ACK for 0x%x\n", cmd
);
636 /* Some commands need an ACK, but return zero instead
637 of the standard value.
640 if ((ack
= wavefront_read()) == 0) {
646 DPRINT (WF_DEBUG_IO
, "cannot read ack for "
652 int err
= -1; /* something unknown */
654 if (ack
== 0xff) { /* explicit error */
656 if ((err
= wavefront_read ()) == -1) {
657 DPRINT (WF_DEBUG_DATA
,
664 DPRINT (WF_DEBUG_IO
, "0x%x [%s] "
665 "failed (0x%x, 0x%x, %s)\n",
666 cmd
, wfcmd
->action
, ack
, err
,
667 wavefront_errorstr (err
));
673 DPRINT (WF_DEBUG_DATA
, "ack received "
678 DPRINT (WF_DEBUG_CMD
, "0x%x [%s] does not need "
680 cmd
, wfcmd
->action
, wfcmd
->read_cnt
,
681 wfcmd
->write_cnt
, wfcmd
->need_ack
);
688 /***********************************************************************
689 WaveFront: data munging
691 Things here are wierd. All data written to the board cannot
692 have its most significant bit set. Any data item with values
693 potentially > 0x7F (127) must be split across multiple bytes.
695 Sometimes, we need to munge numeric values that are represented on
696 the x86 side as 8-32 bit values. Sometimes, we need to munge data
697 that is represented on the x86 side as an array of bytes. The most
698 efficient approach to handling both cases seems to be to use 2
699 different functions for munging and 2 for de-munging. This avoids
700 wierd casting and worrying about bit-level offsets.
702 **********************************************************************/
706 munge_int32 (unsigned int src
,
708 unsigned int dst_size
)
712 for (i
= 0;i
< dst_size
; i
++) {
713 *dst
= src
& 0x7F; /* Mask high bit of LSB */
714 src
= src
>> 7; /* Rotate Right 7 bits */
715 /* Note: we leave the upper bits in place */
723 demunge_int32 (unsigned char* src
, int src_size
)
729 for (i
= src_size
- 1; i
>= 0; i
--) {
730 outval
=(outval
<<7)+src
[i
];
738 munge_buf (unsigned char *src
, unsigned char *dst
, unsigned int dst_size
)
742 unsigned int last
= dst_size
/ 2;
744 for (i
= 0; i
< last
; i
++) {
745 *dst
++ = src
[i
] & 0x7f;
746 *dst
++ = src
[i
] >> 7;
753 demunge_buf (unsigned char *src
, unsigned char *dst
, unsigned int src_bytes
)
757 unsigned char *end
= src
+ src_bytes
;
759 end
= src
+ src_bytes
;
761 /* NOTE: src and dst *CAN* point to the same address */
763 for (i
= 0; src
!= end
; i
++) {
765 dst
[i
] |= (*src
++)<<7;
771 /***********************************************************************
772 WaveFront: sample, patch and program management.
773 ***********************************************************************/
776 wavefront_delete_sample (int sample_num
)
779 unsigned char wbuf
[2];
782 wbuf
[0] = sample_num
& 0x7f;
783 wbuf
[1] = sample_num
>> 7;
785 if ((x
= wavefront_cmd (WFC_DELETE_SAMPLE
, 0, wbuf
)) == 0) {
786 dev
.sample_status
[sample_num
] = WF_ST_EMPTY
;
793 wavefront_get_sample_status (int assume_rom
)
797 unsigned char rbuf
[32], wbuf
[32];
798 unsigned int sc_real
, sc_alias
, sc_multi
;
800 /* check sample status */
802 if (wavefront_cmd (WFC_GET_NSAMPLES
, rbuf
, wbuf
)) {
803 printk (KERN_WARNING LOGNAME
"cannot request sample count.\n");
807 sc_real
= sc_alias
= sc_multi
= dev
.samples_used
= 0;
809 for (i
= 0; i
< WF_MAX_SAMPLE
; i
++) {
814 if (wavefront_cmd (WFC_IDENTIFY_SAMPLE_TYPE
, rbuf
, wbuf
)) {
815 printk (KERN_WARNING LOGNAME
816 "cannot identify sample "
817 "type of slot %d\n", i
);
818 dev
.sample_status
[i
] = WF_ST_EMPTY
;
822 dev
.sample_status
[i
] = (WF_SLOT_FILLED
|rbuf
[0]);
825 dev
.sample_status
[i
] |= WF_SLOT_ROM
;
828 switch (rbuf
[0] & WF_ST_MASK
) {
832 case WF_ST_MULTISAMPLE
:
842 printk (KERN_WARNING LOGNAME
"unknown sample type for "
847 if (rbuf
[0] != WF_ST_EMPTY
) {
852 printk (KERN_INFO LOGNAME
853 "%d samples used (%d real, %d aliases, %d multi), "
854 "%d empty\n", dev
.samples_used
, sc_real
, sc_alias
, sc_multi
,
855 WF_MAX_SAMPLE
- dev
.samples_used
);
863 wavefront_get_patch_status (void)
866 unsigned char patchbuf
[WF_PATCH_BYTES
];
867 unsigned char patchnum
[2];
871 for (i
= 0; i
< WF_MAX_PATCH
; i
++) {
872 patchnum
[0] = i
& 0x7f;
873 patchnum
[1] = i
>> 7;
875 if ((x
= wavefront_cmd (WFC_UPLOAD_PATCH
, patchbuf
,
878 dev
.patch_status
[i
] |= WF_SLOT_FILLED
;
879 p
= (wavefront_patch
*) patchbuf
;
881 [p
->sample_number
|(p
->sample_msb
<<7)] |=
884 } else if (x
== 3) { /* Bad patch number */
885 dev
.patch_status
[i
] = 0;
887 printk (KERN_ERR LOGNAME
"upload patch "
889 dev
.patch_status
[i
] = 0;
894 /* program status has already filled in slot_used bits */
896 for (i
= 0, cnt
= 0, cnt2
= 0; i
< WF_MAX_PATCH
; i
++) {
897 if (dev
.patch_status
[i
] & WF_SLOT_FILLED
) {
900 if (dev
.patch_status
[i
] & WF_SLOT_USED
) {
905 printk (KERN_INFO LOGNAME
906 "%d patch slots filled, %d in use\n", cnt
, cnt2
);
912 wavefront_get_program_status (void)
915 unsigned char progbuf
[WF_PROGRAM_BYTES
];
916 wavefront_program prog
;
917 unsigned char prognum
;
920 for (i
= 0; i
< WF_MAX_PROGRAM
; i
++) {
923 if ((x
= wavefront_cmd (WFC_UPLOAD_PROGRAM
, progbuf
,
926 dev
.prog_status
[i
] |= WF_SLOT_USED
;
928 demunge_buf (progbuf
, (unsigned char *) &prog
,
931 for (l
= 0; l
< WF_NUM_LAYERS
; l
++) {
932 if (prog
.layer
[l
].mute
) {
934 [prog
.layer
[l
].patch_number
] |=
938 } else if (x
== 1) { /* Bad program number */
939 dev
.prog_status
[i
] = 0;
941 printk (KERN_ERR LOGNAME
"upload program "
943 dev
.prog_status
[i
] = 0;
947 for (i
= 0, cnt
= 0; i
< WF_MAX_PROGRAM
; i
++) {
948 if (dev
.prog_status
[i
]) {
953 printk (KERN_INFO LOGNAME
"%d programs slots in use\n", cnt
);
959 wavefront_send_patch (wavefront_patch_info
*header
)
962 unsigned char buf
[WF_PATCH_BYTES
+2];
965 DPRINT (WF_DEBUG_LOAD_PATCH
, "downloading patch %d\n",
968 dev
.patch_status
[header
->number
] |= WF_SLOT_FILLED
;
971 bptr
= munge_int32 (header
->number
, buf
, 2);
972 munge_buf ((unsigned char *)&header
->hdr
.p
, bptr
, WF_PATCH_BYTES
);
974 if (wavefront_cmd (WFC_DOWNLOAD_PATCH
, 0, buf
)) {
975 printk (KERN_ERR LOGNAME
"download patch failed\n");
983 wavefront_send_program (wavefront_patch_info
*header
)
986 unsigned char buf
[WF_PROGRAM_BYTES
+1];
989 DPRINT (WF_DEBUG_LOAD_PATCH
, "downloading program %d\n",
992 dev
.prog_status
[header
->number
] = WF_SLOT_USED
;
994 /* XXX need to zero existing SLOT_USED bit for program_status[i]
995 where `i' is the program that's being (potentially) overwritten.
998 for (i
= 0; i
< WF_NUM_LAYERS
; i
++) {
999 if (header
->hdr
.pr
.layer
[i
].mute
) {
1000 dev
.patch_status
[header
->hdr
.pr
.layer
[i
].patch_number
] |=
1003 /* XXX need to mark SLOT_USED for sample used by
1004 patch_number, but this means we have to load it. Ick.
1009 buf
[0] = header
->number
;
1010 munge_buf ((unsigned char *)&header
->hdr
.pr
, &buf
[1], WF_PROGRAM_BYTES
);
1012 if (wavefront_cmd (WFC_DOWNLOAD_PROGRAM
, 0, buf
)) {
1013 printk (KERN_WARNING LOGNAME
"download patch failed\n");
1021 wavefront_freemem (void)
1026 if (wavefront_cmd (WFC_REPORT_FREE_MEMORY
, rbuf
, 0)) {
1027 printk (KERN_WARNING LOGNAME
"can't get memory stats.\n");
1030 return demunge_int32 (rbuf
, 4);
1035 wavefront_send_sample (wavefront_patch_info
*header
,
1037 int data_is_unsigned
)
1040 /* samples are downloaded via a 16-bit wide i/o port
1041 (you could think of it as 2 adjacent 8-bit wide ports
1042 but its less efficient that way). therefore, all
1043 the blocksizes and so forth listed in the documentation,
1044 and used conventionally to refer to sample sizes,
1045 which are given in 8-bit units (bytes), need to be
1049 UINT16 sample_short
;
1051 UINT16
*data_end
= 0;
1053 const int max_blksize
= 4096/2;
1054 unsigned int written
;
1055 unsigned int blocksize
;
1058 unsigned char sample_hdr
[WF_SAMPLE_HDR_BYTES
];
1059 unsigned char *shptr
;
1061 int initial_skip
= 0;
1063 DPRINT (WF_DEBUG_LOAD_PATCH
, "sample %sdownload for slot %d, "
1064 "type %d, %d bytes from 0x%x\n",
1065 header
->size
? "" : "header ",
1066 header
->number
, header
->subkey
,
1068 (int) header
->dataptr
);
1070 if (header
->number
== WAVEFRONT_FIND_FREE_SAMPLE_SLOT
) {
1073 if ((x
= wavefront_find_free_sample ()) < 0) {
1076 printk (KERN_DEBUG LOGNAME
"unspecified sample => %d\n", x
);
1082 /* XXX its a debatable point whether or not RDONLY semantics
1083 on the ROM samples should cover just the sample data or
1084 the sample header. For now, it only covers the sample data,
1085 so anyone is free at all times to rewrite sample headers.
1087 My reason for this is that we have the sample headers
1088 available in the WFB file for General MIDI, and so these
1089 can always be reset if needed. The sample data, however,
1090 cannot be recovered without a complete reset and firmware
1091 reload of the ICS2115, which is a very expensive operation.
1093 So, doing things this way allows us to honor the notion of
1094 "RESETSAMPLES" reasonably cheaply. Note however, that this
1095 is done purely at user level: there is no WFB parser in
1096 this driver, and so a complete reset (back to General MIDI,
1097 or theoretically some other configuration) is the
1098 responsibility of the user level library.
1100 To try to do this in the kernel would be a little
1101 crazy: we'd need 158K of kernel space just to hold
1102 a copy of the patch/program/sample header data.
1105 if (dev
.rom_samples_rdonly
) {
1106 if (dev
.sample_status
[header
->number
] & WF_SLOT_ROM
) {
1107 printk (KERN_ERR LOGNAME
"sample slot %d "
1108 "write protected\n",
1114 wavefront_delete_sample (header
->number
);
1118 dev
.freemem
= wavefront_freemem ();
1120 if (dev
.freemem
< header
->size
) {
1121 printk (KERN_ERR LOGNAME
1122 "insufficient memory to "
1123 "load %d byte sample.\n",
1130 skip
= WF_GET_CHANNEL(&header
->hdr
.s
);
1132 if (skip
> 0 && header
->hdr
.s
.SampleResolution
!= LINEAR_16BIT
) {
1133 printk (KERN_ERR LOGNAME
"channel selection only "
1134 "possible on 16-bit samples");
1169 DPRINT (WF_DEBUG_LOAD_PATCH
, "channel selection: %d => "
1170 "initial skip = %d, skip = %d\n",
1171 WF_GET_CHANNEL (&header
->hdr
.s
),
1172 initial_skip
, skip
);
1174 /* Be safe, and zero the "Unused" bits ... */
1176 WF_SET_CHANNEL(&header
->hdr
.s
, 0);
1178 /* adjust size for 16 bit samples by dividing by two. We always
1179 send 16 bits per write, even for 8 bit samples, so the length
1180 is always half the size of the sample data in bytes.
1183 length
= header
->size
/ 2;
1185 /* the data we're sent has not been munged, and in fact, the
1186 header we have to send isn't just a munged copy either.
1187 so, build the sample header right here.
1190 shptr
= &sample_hdr
[0];
1192 shptr
= munge_int32 (header
->number
, shptr
, 2);
1195 shptr
= munge_int32 (length
, shptr
, 4);
1198 /* Yes, a 4 byte result doesn't contain all of the offset bits,
1199 but the offset only uses 24 bits.
1202 shptr
= munge_int32 (*((UINT32
*) &header
->hdr
.s
.sampleStartOffset
),
1204 shptr
= munge_int32 (*((UINT32
*) &header
->hdr
.s
.loopStartOffset
),
1206 shptr
= munge_int32 (*((UINT32
*) &header
->hdr
.s
.loopEndOffset
),
1208 shptr
= munge_int32 (*((UINT32
*) &header
->hdr
.s
.sampleEndOffset
),
1211 /* This one is truly wierd. What kind of wierdo decided that in
1212 a system dominated by 16 and 32 bit integers, they would use
1216 shptr
= munge_int32 (header
->hdr
.s
.FrequencyBias
, shptr
, 3);
1218 /* Why is this nybblified, when the MSB is *always* zero ?
1219 Anyway, we can't take address of bitfield, so make a
1220 good-faith guess at where it starts.
1223 shptr
= munge_int32 (*(&header
->hdr
.s
.FrequencyBias
+1),
1226 if (wavefront_cmd (header
->size
?
1227 WFC_DOWNLOAD_SAMPLE
: WFC_DOWNLOAD_SAMPLE_HEADER
,
1229 printk (KERN_WARNING LOGNAME
"sample %sdownload refused.\n",
1230 header
->size
? "" : "header ");
1234 if (header
->size
== 0) {
1235 goto sent
; /* Sorry. Just had to have one somewhere */
1238 data_end
= dataptr
+ length
;
1240 /* Do any initial skip over an unused channel's data */
1242 dataptr
+= initial_skip
;
1244 for (written
= 0, blocknum
= 0;
1245 written
< length
; written
+= max_blksize
, blocknum
++) {
1247 if ((length
- written
) > max_blksize
) {
1248 blocksize
= max_blksize
;
1250 /* round to nearest 16-byte value */
1251 blocksize
= ((length
-written
+7)&~0x7);
1254 if (wavefront_cmd (WFC_DOWNLOAD_BLOCK
, 0, 0)) {
1255 printk (KERN_WARNING LOGNAME
"download block "
1256 "request refused.\n");
1260 for (i
= 0; i
< blocksize
; i
++) {
1262 if (dataptr
< data_end
) {
1264 __get_user (sample_short
, dataptr
);
1267 if (data_is_unsigned
) { /* GUS ? */
1269 if (WF_SAMPLE_IS_8BIT(&header
->hdr
.s
)) {
1277 &sample_short
)[0] += 0x7f;
1279 &sample_short
)[1] += 0x7f;
1288 sample_short
+= 0x7fff;
1294 /* In padding section of final block:
1296 Don't fetch unsupplied data from
1297 user space, just continue with
1298 whatever the final value was.
1302 if (i
< blocksize
- 1) {
1303 outw (sample_short
, dev
.block_port
);
1305 outw (sample_short
, dev
.last_block_port
);
1309 /* Get "DMA page acknowledge", even though its really
1310 nothing to do with DMA at all.
1313 if ((dma_ack
= wavefront_read ()) != WF_DMA_ACK
) {
1314 if (dma_ack
== -1) {
1315 printk (KERN_ERR LOGNAME
"upload sample "
1316 "DMA ack timeout\n");
1319 printk (KERN_ERR LOGNAME
"upload sample "
1320 "DMA ack error 0x%x\n",
1327 dev
.sample_status
[header
->number
] = (WF_SLOT_FILLED
|WF_ST_SAMPLE
);
1329 /* Note, label is here because sending the sample header shouldn't
1330 alter the sample_status info at all.
1338 wavefront_send_alias (wavefront_patch_info
*header
)
1341 unsigned char alias_hdr
[WF_ALIAS_BYTES
];
1343 DPRINT (WF_DEBUG_LOAD_PATCH
, "download alias, %d is "
1346 header
->hdr
.a
.OriginalSample
);
1348 munge_int32 (header
->number
, &alias_hdr
[0], 2);
1349 munge_int32 (header
->hdr
.a
.OriginalSample
, &alias_hdr
[2], 2);
1350 munge_int32 (*((unsigned int *)&header
->hdr
.a
.sampleStartOffset
),
1352 munge_int32 (*((unsigned int *)&header
->hdr
.a
.loopStartOffset
),
1354 munge_int32 (*((unsigned int *)&header
->hdr
.a
.loopEndOffset
),
1356 munge_int32 (*((unsigned int *)&header
->hdr
.a
.sampleEndOffset
),
1358 munge_int32 (header
->hdr
.a
.FrequencyBias
, &alias_hdr
[20], 3);
1359 munge_int32 (*(&header
->hdr
.a
.FrequencyBias
+1), &alias_hdr
[23], 2);
1361 if (wavefront_cmd (WFC_DOWNLOAD_SAMPLE_ALIAS
, 0, alias_hdr
)) {
1362 printk (KERN_ERR LOGNAME
"download alias failed.\n");
1366 dev
.sample_status
[header
->number
] = (WF_SLOT_FILLED
|WF_ST_ALIAS
);
1372 wavefront_send_multisample (wavefront_patch_info
*header
)
1376 unsigned char msample_hdr
[WF_MSAMPLE_BYTES
];
1378 munge_int32 (header
->number
, &msample_hdr
[0], 2);
1380 /* You'll recall at this point that the "number of samples" value
1381 in a wavefront_multisample struct is actually the log2 of the
1382 real number of samples.
1385 num_samples
= (1<<(header
->hdr
.ms
.NumberOfSamples
&7));
1386 msample_hdr
[2] = (unsigned char) header
->hdr
.ms
.NumberOfSamples
;
1388 DPRINT (WF_DEBUG_LOAD_PATCH
, "multi %d with %d=%d samples\n",
1390 header
->hdr
.ms
.NumberOfSamples
,
1393 for (i
= 0; i
< num_samples
; i
++) {
1394 DPRINT(WF_DEBUG_LOAD_PATCH
|WF_DEBUG_DATA
, "sample[%d] = %d\n",
1395 i
, header
->hdr
.ms
.SampleNumber
[i
]);
1396 munge_int32 (header
->hdr
.ms
.SampleNumber
[i
],
1397 &msample_hdr
[3+(i
*2)], 2);
1400 /* Need a hack here to pass in the number of bytes
1401 to be written to the synth. This is ugly, and perhaps
1402 one day, I'll fix it.
1405 if (wavefront_cmd (WFC_DOWNLOAD_MULTISAMPLE
,
1406 (unsigned char *) ((num_samples
*2)+3),
1408 printk (KERN_ERR LOGNAME
"download of multisample failed.\n");
1412 dev
.sample_status
[header
->number
] = (WF_SLOT_FILLED
|WF_ST_MULTISAMPLE
);
1418 wavefront_fetch_multisample (wavefront_patch_info
*header
)
1421 unsigned char log_ns
[1];
1422 unsigned char number
[2];
1425 munge_int32 (header
->number
, number
, 2);
1427 if (wavefront_cmd (WFC_UPLOAD_MULTISAMPLE
, log_ns
, number
)) {
1428 printk (KERN_ERR LOGNAME
"upload multisample failed.\n");
1432 DPRINT (WF_DEBUG_DATA
, "msample %d has %d samples\n",
1433 header
->number
, log_ns
[0]);
1435 header
->hdr
.ms
.NumberOfSamples
= log_ns
[0];
1437 /* get the number of samples ... */
1439 num_samples
= (1 << log_ns
[0]);
1441 for (i
= 0; i
< num_samples
; i
++) {
1444 if ((d
[0] = wavefront_read ()) == -1) {
1445 printk (KERN_ERR LOGNAME
"upload multisample failed "
1446 "during sample loop.\n");
1450 if ((d
[1] = wavefront_read ()) == -1) {
1451 printk (KERN_ERR LOGNAME
"upload multisample failed "
1452 "during sample loop.\n");
1456 header
->hdr
.ms
.SampleNumber
[i
] =
1457 demunge_int32 ((unsigned char *) d
, 2);
1459 DPRINT (WF_DEBUG_DATA
, "msample sample[%d] = %d\n",
1460 i
, header
->hdr
.ms
.SampleNumber
[i
]);
1468 wavefront_send_drum (wavefront_patch_info
*header
)
1471 unsigned char drumbuf
[WF_DRUM_BYTES
];
1472 wavefront_drum
*drum
= &header
->hdr
.d
;
1475 DPRINT (WF_DEBUG_LOAD_PATCH
, "downloading edrum for MIDI "
1476 "note %d, patch = %d\n",
1477 header
->number
, drum
->PatchNumber
);
1479 drumbuf
[0] = header
->number
& 0x7f;
1481 for (i
= 0; i
< 4; i
++) {
1482 munge_int32 (((unsigned char *)drum
)[i
], &drumbuf
[1+(i
*2)], 2);
1485 if (wavefront_cmd (WFC_DOWNLOAD_EDRUM_PROGRAM
, 0, drumbuf
)) {
1486 printk (KERN_ERR LOGNAME
"download drum failed.\n");
1494 wavefront_find_free_sample (void)
1499 for (i
= 0; i
< WF_MAX_SAMPLE
; i
++) {
1500 if (!(dev
.sample_status
[i
] & WF_SLOT_FILLED
)) {
1504 printk (KERN_WARNING LOGNAME
"no free sample slots!\n");
1509 wavefront_find_free_patch (void)
1514 for (i
= 0; i
< WF_MAX_PATCH
; i
++) {
1515 if (!(dev
.patch_status
[i
] & WF_SLOT_FILLED
)) {
1519 printk (KERN_WARNING LOGNAME
"no free patch slots!\n");
1527 int tbl
[]={0, 0, 2048, 3246, 4096, 4755, 5294, 5749, 6143,
1528 6492, 6803, 7084, 7342, 7578, 7797, 8001, 8192,
1529 8371, 8540, 8699, 8851, 8995, 9132, 9264, 9390,
1530 9510, 9626, 9738, 9845, 9949, 10049, 10146};
1533 /* Returns 2048*log2(n) */
1535 /* FIXME: this is like doing integer math
1536 on quantum particles (RuN) */
1552 wavefront_load_gus_patch (int devno
, int format
, const char *addr
,
1553 int offs
, int count
, int pmgr_flag
)
1555 struct patch_info guspatch
;
1556 wavefront_patch_info samp
, pat
, prog
;
1557 wavefront_patch
*patp
;
1558 wavefront_sample
*sampp
;
1559 wavefront_program
*progp
;
1564 /* Copy in the header of the GUS patch */
1566 sizeof_patch
= (long) &guspatch
.data
[0] - (long) &guspatch
;
1567 copy_from_user (&((char *) &guspatch
)[offs
],
1568 &(addr
)[offs
], sizeof_patch
- offs
);
1570 if ((i
= wavefront_find_free_patch ()) == -1) {
1574 pat
.subkey
= WF_ST_PATCH
;
1577 if ((i
= wavefront_find_free_sample ()) == -1) {
1581 samp
.subkey
= WF_ST_SAMPLE
;
1582 samp
.size
= guspatch
.len
;
1583 sampp
= &samp
.hdr
.s
;
1585 prog
.number
= guspatch
.instr_no
;
1586 progp
= &prog
.hdr
.pr
;
1588 /* Setup the patch structure */
1590 patp
->amplitude_bias
=guspatch
.volume
;
1592 patp
->sample_number
= samp
.number
& 0xff;
1593 patp
->sample_msb
= samp
.number
>>8;
1594 patp
->pitch_bend
= /*12*/ 0;
1597 patp
->nohold
=(guspatch
.mode
& WAVE_SUSTAIN_ON
) ? 0:1;
1598 patp
->frequency_bias
=0;
1603 patp
->fm_src1
=WF_MOD_MOD_WHEEL
;
1604 patp
->am_src
=WF_MOD_PRESSURE
;
1605 patp
->am_amount
=127;
1606 patp
->fc1_mod_amount
=0;
1607 patp
->fc2_mod_amount
=0;
1610 patp
->envelope1
.attack_level
=127;
1611 patp
->envelope1
.decay1_level
=127;
1612 patp
->envelope1
.decay2_level
=127;
1613 patp
->envelope1
.sustain_level
=127;
1614 patp
->envelope1
.release_level
=0;
1615 patp
->envelope2
.attack_velocity
=127;
1616 patp
->envelope2
.attack_level
=127;
1617 patp
->envelope2
.decay1_level
=127;
1618 patp
->envelope2
.decay2_level
=127;
1619 patp
->envelope2
.sustain_level
=127;
1620 patp
->envelope2
.release_level
=0;
1621 patp
->envelope2
.attack_velocity
=127;
1624 /* Program for this patch */
1626 progp
->layer
[0].patch_number
= pat
.number
; /* XXX is this right ? */
1627 progp
->layer
[0].mute
=1;
1628 progp
->layer
[0].pan_or_mod
=1;
1629 progp
->layer
[0].pan
=7;
1630 progp
->layer
[0].mix_level
=127 /* guspatch.volume */;
1631 progp
->layer
[0].split_type
=0;
1632 progp
->layer
[0].split_point
=0;
1633 progp
->layer
[0].play_below
=0;
1635 for (i
= 1; i
< 4; i
++) {
1636 progp
->layer
[i
].mute
=0;
1641 sampp
->SampleResolution
=((~guspatch
.mode
& WAVE_16_BITS
)<<1);
1644 note_to_freq (base_note
) < guspatch
.base_note
;
1647 if ((guspatch
.base_note
-note_to_freq(base_note
))
1648 >(note_to_freq(base_note
)-guspatch
.base_note
))
1651 printk(KERN_DEBUG
"ref freq=%d,base note=%d\n",
1655 sampp
->FrequencyBias
= (29550 - log2_2048(guspatch
.base_freq
)
1657 printk(KERN_DEBUG
"Freq Bias is %d\n", sampp
->FrequencyBias
);
1658 sampp
->Loop
=(guspatch
.mode
& WAVE_LOOPING
) ? 1:0;
1659 sampp
->sampleStartOffset
.Fraction
=0;
1660 sampp
->sampleStartOffset
.Integer
=0;
1661 sampp
->loopStartOffset
.Fraction
=0;
1662 sampp
->loopStartOffset
.Integer
=guspatch
.loop_start
1663 >>((guspatch
.mode
&WAVE_16_BITS
) ? 1:0);
1664 sampp
->loopEndOffset
.Fraction
=0;
1665 sampp
->loopEndOffset
.Integer
=guspatch
.loop_end
1666 >>((guspatch
.mode
&WAVE_16_BITS
) ? 1:0);
1667 sampp
->sampleEndOffset
.Fraction
=0;
1668 sampp
->sampleEndOffset
.Integer
=guspatch
.len
>> (guspatch
.mode
&1);
1669 sampp
->Bidirectional
=(guspatch
.mode
&WAVE_BIDIR_LOOP
) ? 1:0;
1670 sampp
->Reverse
=(guspatch
.mode
&WAVE_LOOP_BACK
) ? 1:0;
1672 /* Now ship it down */
1674 wavefront_send_sample (&samp
,
1675 (unsigned short *) &(addr
)[sizeof_patch
],
1676 (guspatch
.mode
& WAVE_UNSIGNED
) ? 1:0);
1677 wavefront_send_patch (&pat
);
1678 wavefront_send_program (&prog
);
1680 /* Now pan as best we can ... use the slave/internal MIDI device
1681 number if it exists (since it talks to the WaveFront), or the
1685 if (dev
.mididev
> 0) {
1686 midi_synth_controller (dev
.mididev
, guspatch
.instr_no
, 10,
1687 ((guspatch
.panning
<< 4) > 127) ?
1688 127 : (guspatch
.panning
<< 4));
1695 wavefront_load_patch (const char *addr
)
1699 wavefront_patch_info header
;
1701 if (copy_from_user (&header
, addr
, sizeof(wavefront_patch_info
) -
1702 sizeof(wavefront_any
))) {
1703 printk (KERN_WARNING LOGNAME
"bad address for load patch.\n");
1707 DPRINT (WF_DEBUG_LOAD_PATCH
, "download "
1709 "Sample number: %d "
1710 "Sample size: %d\n",
1715 switch (header
.subkey
) {
1716 case WF_ST_SAMPLE
: /* sample or sample_header, based on patch->size */
1718 copy_from_user ((unsigned char *) &header
.hdr
.s
,
1719 (unsigned char *) header
.hdrptr
,
1720 sizeof (wavefront_sample
));
1722 return wavefront_send_sample (&header
, header
.dataptr
, 0);
1724 case WF_ST_MULTISAMPLE
:
1726 copy_from_user ((unsigned char *) &header
.hdr
.s
,
1727 (unsigned char *) header
.hdrptr
,
1728 sizeof (wavefront_multisample
));
1730 return wavefront_send_multisample (&header
);
1735 copy_from_user ((unsigned char *) &header
.hdr
.a
,
1736 (unsigned char *) header
.hdrptr
,
1737 sizeof (wavefront_alias
));
1739 return wavefront_send_alias (&header
);
1742 copy_from_user ((unsigned char *) &header
.hdr
.d
,
1743 (unsigned char *) header
.hdrptr
,
1744 sizeof (wavefront_drum
));
1746 return wavefront_send_drum (&header
);
1749 copy_from_user ((unsigned char *) &header
.hdr
.p
,
1750 (unsigned char *) header
.hdrptr
,
1751 sizeof (wavefront_patch
));
1753 return wavefront_send_patch (&header
);
1756 copy_from_user ((unsigned char *) &header
.hdr
.pr
,
1757 (unsigned char *) header
.hdrptr
,
1758 sizeof (wavefront_program
));
1760 return wavefront_send_program (&header
);
1763 printk (KERN_ERR LOGNAME
"unknown patch type %d.\n",
1771 /***********************************************************************
1772 WaveFront: /dev/sequencer{,2} and other hardware-dependent interfaces
1773 ***********************************************************************/
1776 process_sample_hdr (UCHAR8
*buf
)
1784 /* The board doesn't send us an exact copy of a "wavefront_sample"
1785 in response to an Upload Sample Header command. Instead, we
1786 have to convert the data format back into our data structure,
1787 just as in the Download Sample command, where we have to do
1788 something very similar in the reverse direction.
1791 *((UINT32
*) &s
.sampleStartOffset
) = demunge_int32 (ptr
, 4); ptr
+= 4;
1792 *((UINT32
*) &s
.loopStartOffset
) = demunge_int32 (ptr
, 4); ptr
+= 4;
1793 *((UINT32
*) &s
.loopEndOffset
) = demunge_int32 (ptr
, 4); ptr
+= 4;
1794 *((UINT32
*) &s
.sampleEndOffset
) = demunge_int32 (ptr
, 4); ptr
+= 4;
1795 *((UINT32
*) &s
.FrequencyBias
) = demunge_int32 (ptr
, 3); ptr
+= 3;
1797 s
.SampleResolution
= *ptr
& 0x3;
1798 s
.Loop
= *ptr
& 0x8;
1799 s
.Bidirectional
= *ptr
& 0x10;
1800 s
.Reverse
= *ptr
& 0x40;
1802 /* Now copy it back to where it came from */
1804 memcpy (buf
, (unsigned char *) &s
, sizeof (wavefront_sample
));
1808 wavefront_synth_control (int cmd
, wavefront_control
*wc
)
1811 unsigned char patchnumbuf
[2];
1814 DPRINT (WF_DEBUG_CMD
, "synth control with "
1815 "cmd 0x%x\n", wc
->cmd
);
1817 /* Pre-handling of or for various commands */
1820 case WFC_DISABLE_INTERRUPTS
:
1821 printk (KERN_INFO LOGNAME
"interrupts disabled.\n");
1822 outb (0x80|0x20, dev
.control_port
);
1823 dev
.interrupts_on
= 0;
1826 case WFC_ENABLE_INTERRUPTS
:
1827 printk (KERN_INFO LOGNAME
"interrupts enabled.\n");
1828 outb (0x80|0x40|0x20, dev
.control_port
);
1829 dev
.interrupts_on
= 1;
1832 case WFC_INTERRUPT_STATUS
:
1833 wc
->rbuf
[0] = dev
.interrupts_on
;
1836 case WFC_ROMSAMPLES_RDONLY
:
1837 dev
.rom_samples_rdonly
= wc
->wbuf
[0];
1841 case WFC_IDENTIFY_SLOT_TYPE
:
1842 i
= wc
->wbuf
[0] | (wc
->wbuf
[1] << 7);
1843 if (i
<0 || i
>= WF_MAX_SAMPLE
) {
1844 printk (KERN_WARNING LOGNAME
"invalid slot ID %d\n",
1846 wc
->status
= EINVAL
;
1849 wc
->rbuf
[0] = dev
.sample_status
[i
];
1853 case WFC_DEBUG_DRIVER
:
1854 dev
.debug
= wc
->wbuf
[0];
1855 printk (KERN_INFO LOGNAME
"debug = 0x%x\n", dev
.debug
);
1859 wffx_ioctl ((wavefront_fx_info
*) &wc
->wbuf
[0]);
1862 case WFC_UPLOAD_PATCH
:
1863 munge_int32 (*((UINT32
*) wc
->wbuf
), patchnumbuf
, 2);
1864 memcpy (wc
->wbuf
, patchnumbuf
, 2);
1867 case WFC_UPLOAD_MULTISAMPLE
:
1868 /* multisamples have to be handled differently, and
1869 cannot be dealt with properly by wavefront_cmd() alone.
1871 wc
->status
= wavefront_fetch_multisample
1872 ((wavefront_patch_info
*) wc
->rbuf
);
1875 case WFC_UPLOAD_SAMPLE_ALIAS
:
1876 printk (KERN_INFO LOGNAME
"support for sample alias upload "
1877 "being considered.\n");
1878 wc
->status
= EINVAL
;
1882 wc
->status
= wavefront_cmd (wc
->cmd
, wc
->rbuf
, wc
->wbuf
);
1884 /* Post-handling of certain commands.
1886 In particular, if the command was an upload, demunge the data
1887 so that the user-level doesn't have to think about it.
1890 if (wc
->status
== 0) {
1892 /* intercept any freemem requests so that we know
1893 we are always current with the user-level view
1897 case WFC_REPORT_FREE_MEMORY
:
1898 dev
.freemem
= demunge_int32 (wc
->rbuf
, 4);
1901 case WFC_UPLOAD_PATCH
:
1902 demunge_buf (wc
->rbuf
, wc
->rbuf
, WF_PATCH_BYTES
);
1905 case WFC_UPLOAD_PROGRAM
:
1906 demunge_buf (wc
->rbuf
, wc
->rbuf
, WF_PROGRAM_BYTES
);
1909 case WFC_UPLOAD_EDRUM_PROGRAM
:
1910 demunge_buf (wc
->rbuf
, wc
->rbuf
, WF_DRUM_BYTES
- 1);
1913 case WFC_UPLOAD_SAMPLE_HEADER
:
1914 process_sample_hdr (wc
->rbuf
);
1917 case WFC_UPLOAD_SAMPLE_ALIAS
:
1918 printk (KERN_INFO LOGNAME
"support for "
1919 "sample aliases still "
1920 "being considered.\n");
1924 if (virtual_midi_disable () < 0) {
1930 if (virtual_midi_enable () < 0) {
1941 /***********************************************************************/
1942 /* WaveFront: Linux file system interface (for access via raw synth) */
1943 /***********************************************************************/
1946 wavefront_llseek(struct file
*file
, loff_t offset
, int origin
)
1952 wavefront_open (struct inode
*inode
, struct file
*file
)
1955 dev
.opened
= file
->f_flags
;
1960 wavefront_release(struct inode
*inode
, struct file
*file
)
1970 wavefront_ioctl(struct inode
*inode
, struct file
*file
,
1971 unsigned int cmd
, unsigned long arg
)
1973 wavefront_control wc
;
1979 copy_from_user (&wc
, (void *) arg
, sizeof (wc
));
1981 if ((err
= wavefront_synth_control (cmd
, &wc
)) == 0) {
1982 copy_to_user ((void *) arg
, &wc
, sizeof (wc
));
1987 case WFCTL_LOAD_SPP
:
1988 return wavefront_load_patch ((const char *) arg
);
1991 printk (KERN_WARNING LOGNAME
"invalid ioctl %#x\n", cmd
);
1998 static /*const*/ struct file_operations wavefront_fops
= {
2000 llseek
: wavefront_llseek
,
2001 ioctl
: wavefront_ioctl
,
2002 open
: wavefront_open
,
2003 release
: wavefront_release
,
2007 /***********************************************************************/
2008 /* WaveFront: OSS installation and support interface */
2009 /***********************************************************************/
2011 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2013 static struct synth_info wavefront_info
=
2014 {"Turtle Beach WaveFront", 0, SYNTH_TYPE_SAMPLE
, SAMPLE_TYPE_WAVEFRONT
,
2015 0, 32, 0, 0, SYNTH_CAP_INPUT
};
2018 wavefront_oss_open (int devno
, int mode
)
2026 wavefront_oss_close (int devno
)
2035 wavefront_oss_ioctl (int devno
, unsigned int cmd
, caddr_t arg
)
2038 wavefront_control wc
;
2042 case SNDCTL_SYNTH_INFO
:
2043 memcpy (&((char *) arg
)[0], &wavefront_info
,
2044 sizeof (wavefront_info
));
2048 case SNDCTL_SEQ_RESETSAMPLES
:
2049 printk (KERN_WARNING LOGNAME
"driver cannot reset samples.\n");
2050 return 0; /* don't force an error */
2053 case SNDCTL_SEQ_PERCMODE
:
2054 return 0; /* don't force an error */
2057 case SNDCTL_SYNTH_MEMAVL
:
2058 if ((dev
.freemem
= wavefront_freemem ()) < 0) {
2059 printk (KERN_ERR LOGNAME
"cannot get memory size\n");
2066 case SNDCTL_SYNTH_CONTROL
:
2067 copy_from_user (&wc
, arg
, sizeof (wc
));
2069 if ((err
= wavefront_synth_control (cmd
, &wc
)) == 0) {
2070 copy_to_user (arg
, &wc
, sizeof (wc
));
2081 wavefront_oss_load_patch (int devno
, int format
, const char *addr
,
2082 int offs
, int count
, int pmgr_flag
)
2085 if (format
== SYSEX_PATCH
) { /* Handled by midi_synth.c */
2086 if (midi_load_patch
== NULL
) {
2087 printk (KERN_ERR LOGNAME
2088 "SYSEX not loadable: "
2089 "no midi patch loader!\n");
2093 return midi_load_patch (devno
, format
, addr
,
2094 offs
, count
, pmgr_flag
);
2096 } else if (format
== GUS_PATCH
) {
2097 return wavefront_load_gus_patch (devno
, format
,
2098 addr
, offs
, count
, pmgr_flag
);
2100 } else if (format
!= WAVEFRONT_PATCH
) {
2101 printk (KERN_ERR LOGNAME
"unknown patch format %d\n", format
);
2105 if (count
< sizeof (wavefront_patch_info
)) {
2106 printk (KERN_ERR LOGNAME
"sample header too short\n");
2110 /* "addr" points to a user-space wavefront_patch_info */
2112 return wavefront_load_patch (addr
);
2115 static struct synth_operations wavefront_operations
=
2119 info
: &wavefront_info
,
2121 synth_type
: SYNTH_TYPE_SAMPLE
,
2122 synth_subtype
: SAMPLE_TYPE_WAVEFRONT
,
2123 open
: wavefront_oss_open
,
2124 close
: wavefront_oss_close
,
2125 ioctl
: wavefront_oss_ioctl
,
2126 kill_note
: midi_synth_kill_note
,
2127 start_note
: midi_synth_start_note
,
2128 set_instr
: midi_synth_set_instr
,
2129 reset
: midi_synth_reset
,
2130 load_patch
: midi_synth_load_patch
,
2131 aftertouch
: midi_synth_aftertouch
,
2132 controller
: midi_synth_controller
,
2133 panning
: midi_synth_panning
,
2134 bender
: midi_synth_bender
,
2135 setup_voice
: midi_synth_setup_voice
2137 #endif OSS_SUPPORT_SEQ
2139 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_STATIC_INSTALL
2141 static void __init
attach_wavefront (struct address_info
*hw_config
)
2143 (void) install_wavefront ();
2146 static int __init
probe_wavefront (struct address_info
*hw_config
)
2148 return !detect_wavefront (hw_config
->irq
, hw_config
->io_base
);
2151 static void __exit
unload_wavefront (struct address_info
*hw_config
)
2153 (void) uninstall_wavefront ();
2156 #endif OSS_SUPPORT_STATIC_INSTALL
2158 /***********************************************************************/
2159 /* WaveFront: Linux modular sound kernel installation interface */
2160 /***********************************************************************/
2163 wavefrontintr (int irq
, void *dev_id
, struct pt_regs
*dummy
)
2165 struct wf_config
*hw
= dev_id
;
2168 Some comments on interrupts. I attempted a version of this
2169 driver that used interrupts throughout the code instead of
2170 doing busy and/or sleep-waiting. Alas, it appears that once
2171 the Motorola firmware is downloaded, the card *never*
2172 generates an RX interrupt. These are successfully generated
2173 during firmware loading, and after that wavefront_status()
2174 reports that an interrupt is pending on the card from time
2175 to time, but it never seems to be delivered to this
2176 driver. Note also that wavefront_status() continues to
2177 report that RX interrupts are enabled, suggesting that I
2178 didn't goof up and disable them by mistake.
2180 Thus, I stepped back to a prior version of
2181 wavefront_wait(), the only place where this really
2182 matters. Its sad, but I've looked through the code to check
2183 on things, and I really feel certain that the Motorola
2184 firmware prevents RX-ready interrupts.
2187 if ((wavefront_status() & (STAT_INTR_READ
|STAT_INTR_WRITE
)) == 0) {
2193 wake_up_interruptible (&hw
->interrupt_sleeper
);
2198 0 Host Rx Interrupt Enable (1=Enabled)
2199 1 Host Rx Register Full (1=Full)
2200 2 Host Rx Interrupt Pending (1=Interrupt)
2202 4 Host Tx Interrupt (1=Enabled)
2203 5 Host Tx Register empty (1=Empty)
2204 6 Host Tx Interrupt Pending (1=Interrupt)
2209 wavefront_interrupt_bits (int irq
)
2229 printk (KERN_WARNING LOGNAME
"invalid IRQ %d\n", irq
);
2237 wavefront_should_cause_interrupt (int val
, int port
, int timeout
)
2240 unsigned long flags
;
2246 interruptible_sleep_on_timeout (&dev
.interrupt_sleeper
, timeout
);
2247 restore_flags (flags
);
2251 wavefront_hw_reset (void)
2256 unsigned long irq_mask
;
2259 /* IRQ already checked in init_module() */
2261 bits
= wavefront_interrupt_bits (dev
.irq
);
2263 printk (KERN_DEBUG LOGNAME
"autodetecting WaveFront IRQ\n");
2267 irq_mask
= probe_irq_on ();
2269 outb (0x0, dev
.control_port
);
2270 outb (0x80 | 0x40 | bits
, dev
.data_port
);
2271 wavefront_should_cause_interrupt(0x80|0x40|0x10|0x1,
2273 (reset_time
*HZ
)/100);
2275 reported_irq
= probe_irq_off (irq_mask
);
2277 if (reported_irq
!= dev
.irq
) {
2278 if (reported_irq
== 0) {
2279 printk (KERN_ERR LOGNAME
2280 "No unassigned interrupts detected "
2281 "after h/w reset\n");
2282 } else if (reported_irq
< 0) {
2283 printk (KERN_ERR LOGNAME
2284 "Multiple unassigned interrupts detected "
2285 "after h/w reset\n");
2287 printk (KERN_ERR LOGNAME
"autodetected IRQ %d not the "
2288 "value provided (%d)\n", reported_irq
,
2294 printk (KERN_INFO LOGNAME
"autodetected IRQ at %d\n",
2298 if (request_irq (dev
.irq
, wavefrontintr
,
2299 SA_INTERRUPT
|SA_SHIRQ
,
2300 "wavefront synth", &dev
) < 0) {
2301 printk (KERN_WARNING LOGNAME
"IRQ %d not available!\n",
2306 /* try reset of port */
2308 outb (0x0, dev
.control_port
);
2310 /* At this point, the board is in reset, and the H/W initialization
2311 register is accessed at the same address as the data port.
2313 Bit 7 - Enable IRQ Driver
2314 0 - Tri-state the Wave-Board drivers for the PC Bus IRQs
2315 1 - Enable IRQ selected by bits 5:3 to be driven onto the PC Bus.
2317 Bit 6 - MIDI Interface Select
2319 0 - Use the MIDI Input from the 26-pin WaveBlaster
2320 compatible header as the serial MIDI source
2321 1 - Use the MIDI Input from the 9-pin D connector as the
2324 Bits 5:3 - IRQ Selection
2335 Bit 0 - Disable Boot ROM
2336 0 - memory accesses to 03FC30-03FFFFH utilize the internal Boot ROM
2337 1 - memory accesses to 03FC30-03FFFFH are directed to external
2342 /* configure hardware: IRQ, enable interrupts,
2343 plus external 9-pin MIDI interface selected
2346 outb (0x80 | 0x40 | bits
, dev
.data_port
);
2350 0 Host Rx Interrupt Enable (1=Enabled) 0x1
2354 4 Host Tx Interrupt Enable 0x10
2355 5 Mute (0=Mute; 1=Play) 0x20
2356 6 Master Interrupt Enable (1=Enabled) 0x40
2357 7 Master Reset (0=Reset; 1=Run) 0x80
2359 Take us out of reset, mute output, master + TX + RX interrupts on.
2361 We'll get an interrupt presumably to tell us that the TX
2365 wavefront_should_cause_interrupt(0x80|0x40|0x10|0x1,
2367 (reset_time
*HZ
)/100);
2369 /* Note: data port is now the data port, not the h/w initialization
2374 printk (KERN_WARNING LOGNAME
2375 "intr not received after h/w un-reset.\n");
2379 dev
.interrupts_on
= 1;
2381 /* Note: data port is now the data port, not the h/w initialization
2384 At this point, only "HW VERSION" or "DOWNLOAD OS" commands
2385 will work. So, issue one of them, and wait for TX
2386 interrupt. This can take a *long* time after a cold boot,
2387 while the ISC ROM does its RAM test. The SDK says up to 4
2388 seconds - with 12MB of RAM on a Tropez+, it takes a lot
2389 longer than that (~16secs). Note that the card understands
2390 the difference between a warm and a cold boot, so
2391 subsequent ISC2115 reboots (say, caused by module
2392 reloading) will get through this much faster.
2394 XXX Interesting question: why is no RX interrupt received first ?
2397 wavefront_should_cause_interrupt(WFC_HARDWARE_VERSION
,
2398 dev
.data_port
, ramcheck_time
*HZ
);
2401 printk (KERN_WARNING LOGNAME
2402 "post-RAM-check interrupt not received.\n");
2406 if (!wavefront_wait (STAT_CAN_READ
)) {
2407 printk (KERN_WARNING LOGNAME
2408 "no response to HW version cmd.\n");
2412 if ((hwv
[0] = wavefront_read ()) == -1) {
2413 printk (KERN_WARNING LOGNAME
2414 "board not responding correctly.\n");
2418 if (hwv
[0] == 0xFF) { /* NAK */
2420 /* Board's RAM test failed. Try to read error code,
2421 and tell us about it either way.
2424 if ((hwv
[0] = wavefront_read ()) == -1) {
2425 printk (KERN_WARNING LOGNAME
"on-board RAM test failed "
2426 "(bad error code).\n");
2428 printk (KERN_WARNING LOGNAME
"on-board RAM test failed "
2429 "(error code: 0x%x).\n",
2435 /* We're OK, just get the next byte of the HW version response */
2437 if ((hwv
[1] = wavefront_read ()) == -1) {
2438 printk (KERN_WARNING LOGNAME
"incorrect h/w response.\n");
2442 printk (KERN_INFO LOGNAME
"hardware version %d.%d\n",
2450 free_irq (dev
.irq
, &dev
);
2456 static int __init
detect_wavefront (int irq
, int io_base
)
2458 unsigned char rbuf
[4], wbuf
[4];
2460 /* TB docs say the device takes up 8 ports, but we know that
2461 if there is an FX device present (i.e. a Tropez+) it really
2465 if (check_region (io_base
, 16)) {
2466 printk (KERN_ERR LOGNAME
"IO address range 0x%x - 0x%x "
2467 "already in use - ignored\n", dev
.base
,
2475 dev
.debug
= debug_default
;
2476 dev
.interrupts_on
= 0;
2478 dev
.rom_samples_rdonly
= 1; /* XXX default lock on ROM sample slots */
2480 if (wavefront_cmd (WFC_FIRMWARE_VERSION
, rbuf
, wbuf
) == 0) {
2482 dev
.fw_version
[0] = rbuf
[0];
2483 dev
.fw_version
[1] = rbuf
[1];
2484 printk (KERN_INFO LOGNAME
2485 "firmware %d.%d already loaded.\n",
2488 /* check that a command actually works */
2490 if (wavefront_cmd (WFC_HARDWARE_VERSION
,
2492 dev
.hw_version
[0] = rbuf
[0];
2493 dev
.hw_version
[1] = rbuf
[1];
2495 printk (KERN_WARNING LOGNAME
"not raw, but no "
2496 "hardware version!\n");
2503 printk (KERN_INFO LOGNAME
2504 "reloading firmware anyway.\n");
2511 printk (KERN_INFO LOGNAME
2512 "no response to firmware probe, assume raw.\n");
2516 init_waitqueue_head (&dev
.interrupt_sleeper
);
2518 if (wavefront_hw_reset ()) {
2519 printk (KERN_WARNING LOGNAME
"hardware reset failed\n");
2523 /* Check for FX device, present only on Tropez+ */
2525 dev
.has_fx
= (detect_wffx () == 0);
2531 #define __KERNEL_SYSCALLS__
2532 #include <linux/fs.h>
2533 #include <linux/mm.h>
2534 #include <linux/malloc.h>
2535 #include <linux/unistd.h>
2536 #include <asm/uaccess.h>
2541 wavefront_download_firmware (char *path
)
2544 unsigned char section
[WF_SECTION_MAX
];
2545 char section_length
; /* yes, just a char; max value is WF_SECTION_MAX */
2546 int section_cnt_downloaded
= 0;
2552 /* This tries to be a bit cleverer than the stuff Alan Cox did for
2553 the generic sound firmware, in that it actually knows
2554 something about the structure of the Motorola firmware. In
2555 particular, it uses a version that has been stripped of the
2556 20K of useless header information, and had section lengths
2557 added, making it possible to load the entire OS without any
2558 [kv]malloc() activity, since the longest entity we ever read is
2559 42 bytes (well, WF_SECTION_MAX) long.
2565 if ((fd
= open (path
, 0, 0)) < 0) {
2566 printk (KERN_WARNING LOGNAME
"Unable to load \"%s\".\n",
2574 if ((x
= read (fd
, §ion_length
, sizeof (section_length
))) !=
2575 sizeof (section_length
)) {
2576 printk (KERN_ERR LOGNAME
"firmware read error.\n");
2580 if (section_length
== 0) {
2584 if (read (fd
, section
, section_length
) != section_length
) {
2585 printk (KERN_ERR LOGNAME
"firmware section "
2592 if (wavefront_write (WFC_DOWNLOAD_OS
)) {
2596 for (i
= 0; i
< section_length
; i
++) {
2597 if (wavefront_write (section
[i
])) {
2604 if (wavefront_wait (STAT_CAN_READ
)) {
2606 if ((c
= inb (dev
.data_port
)) != WF_ACK
) {
2608 printk (KERN_ERR LOGNAME
"download "
2609 "of section #%d not "
2610 "acknowledged, ack = 0x%x\n",
2611 section_cnt_downloaded
+ 1, c
);
2617 printk (KERN_ERR LOGNAME
"time out for firmware ACK.\n");
2630 printk (KERN_ERR
"\nWaveFront: firmware download failed!!!\n");
2634 static int __init
wavefront_config_midi (void)
2636 unsigned char rbuf
[4], wbuf
[4];
2638 if (detect_wf_mpu (dev
.irq
, dev
.base
) < 0) {
2639 printk (KERN_WARNING LOGNAME
2640 "could not find working MIDI device\n");
2644 if ((dev
.mididev
= install_wf_mpu ()) < 0) {
2645 printk (KERN_WARNING LOGNAME
2646 "MIDI interfaces not configured\n");
2650 /* Route external MIDI to WaveFront synth (by default) */
2652 if (wavefront_cmd (WFC_MISYNTH_ON
, rbuf
, wbuf
)) {
2653 printk (KERN_WARNING LOGNAME
2654 "cannot enable MIDI-IN to synth routing.\n");
2659 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2660 /* Get the regular MIDI patch loading function, so we can
2661 use it if we ever get handed a SYSEX patch. This is
2662 unlikely, because its so damn slow, but we may as well
2663 leave this functionality from maui.c behind, since it
2664 could be useful for sequencer applications that can
2665 only use MIDI to do patch loading.
2668 if (midi_devs
[dev
.mididev
]->converter
!= NULL
) {
2669 midi_load_patch
= midi_devs
[dev
.mididev
]->converter
->load_patch
;
2670 midi_devs
[dev
.mididev
]->converter
->load_patch
=
2671 &wavefront_oss_load_patch
;
2674 #endif OSS_SUPPORT_SEQ
2676 /* Turn on Virtual MIDI, but first *always* turn it off,
2677 since otherwise consectutive reloads of the driver will
2678 never cause the hardware to generate the initial "internal" or
2679 "external" source bytes in the MIDI data stream. This
2680 is pretty important, since the internal hardware generally will
2681 be used to generate none or very little MIDI output, and
2682 thus the only source of MIDI data is actually external. Without
2683 the switch bytes, the driver will think it all comes from
2684 the internal interface. Duh.
2687 if (wavefront_cmd (WFC_VMIDI_OFF
, rbuf
, wbuf
)) {
2688 printk (KERN_WARNING LOGNAME
2689 "virtual MIDI mode not disabled\n");
2690 return 0; /* We're OK, but missing the external MIDI dev */
2693 if ((dev
.ext_mididev
= virtual_midi_enable ()) < 0) {
2694 printk (KERN_WARNING LOGNAME
"no virtual MIDI access.\n");
2696 if (wavefront_cmd (WFC_VMIDI_ON
, rbuf
, wbuf
)) {
2697 printk (KERN_WARNING LOGNAME
2698 "cannot enable virtual MIDI mode.\n");
2699 virtual_midi_disable ();
2707 wavefront_do_reset (int atboot
)
2711 if (!atboot
&& wavefront_hw_reset ()) {
2712 printk (KERN_WARNING LOGNAME
"hw reset failed.\n");
2717 if (wavefront_download_firmware (ospath
)) {
2723 /* Wait for the OS to get running. The protocol for
2724 this is non-obvious, and was determined by
2725 using port-IO tracing in DOSemu and some
2726 experimentation here.
2728 Rather than using timed waits, use interrupts creatively.
2731 wavefront_should_cause_interrupt (WFC_NOOP
,
2736 printk (KERN_WARNING LOGNAME
2737 "no post-OS interrupt.\n");
2741 /* Now, do it again ! */
2743 wavefront_should_cause_interrupt (WFC_NOOP
,
2744 dev
.data_port
, (10*HZ
));
2747 printk (KERN_WARNING LOGNAME
2748 "no post-OS interrupt(2).\n");
2752 /* OK, no (RX/TX) interrupts any more, but leave mute
2756 outb (0x80|0x40, dev
.control_port
);
2758 /* No need for the IRQ anymore */
2760 free_irq (dev
.irq
, &dev
);
2764 if (dev
.has_fx
&& fx_raw
) {
2768 /* SETUPSND.EXE asks for sample memory config here, but since i
2769 have no idea how to interpret the result, we'll forget
2773 if ((dev
.freemem
= wavefront_freemem ()) < 0) {
2777 printk (KERN_INFO LOGNAME
"available DRAM %dk\n", dev
.freemem
/ 1024);
2779 if (wavefront_write (0xf0) ||
2780 wavefront_write (1) ||
2781 (wavefront_read () < 0)) {
2783 printk (KERN_WARNING LOGNAME
"MPU emulation mode not set.\n");
2789 if (wavefront_cmd (WFC_SET_NVOICES
, 0, voices
)) {
2790 printk (KERN_WARNING LOGNAME
2791 "cannot set number of voices to 32.\n");
2799 /* reset that sucker so that it doesn't bother us. */
2801 outb (0x0, dev
.control_port
);
2802 dev
.interrupts_on
= 0;
2804 free_irq (dev
.irq
, &dev
);
2809 static int __init
wavefront_init (int atboot
)
2811 int samples_are_from_rom
;
2814 samples_are_from_rom
= 1;
2816 /* XXX is this always true ? */
2817 samples_are_from_rom
= 0;
2820 if (dev
.israw
|| fx_raw
) {
2821 if (wavefront_do_reset (atboot
)) {
2826 wavefront_get_sample_status (samples_are_from_rom
);
2827 wavefront_get_program_status ();
2828 wavefront_get_patch_status ();
2830 /* Start normal operation: unreset, master interrupt enabled, no mute
2833 outb (0x80|0x40|0x20, dev
.control_port
);
2838 static int __init
install_wavefront (void)
2841 if ((dev
.synth_dev
= register_sound_synth (&wavefront_fops
, -1)) < 0) {
2842 printk (KERN_ERR LOGNAME
"cannot register raw synth\n");
2846 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2847 if ((dev
.oss_dev
= sound_alloc_synthdev()) == -1) {
2848 printk (KERN_ERR LOGNAME
"Too many sequencers\n");
2851 synth_devs
[dev
.oss_dev
] = &wavefront_operations
;
2853 #endif OSS_SUPPORT_SEQ
2855 if (wavefront_init (1) < 0) {
2856 printk (KERN_WARNING LOGNAME
"initialization failed.\n");
2858 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2859 sound_unload_synthdev (dev
.oss_dev
);
2860 #endif OSS_SUPPORT_SEQ
2865 request_region (dev
.base
+2, 6, "wavefront synth");
2868 request_region (dev
.base
+8, 8, "wavefront fx");
2871 if (wavefront_config_midi ()) {
2872 printk (KERN_WARNING LOGNAME
"could not initialize MIDI.\n");
2878 static void __exit
uninstall_wavefront (void)
2880 /* the first two i/o addresses are freed by the wf_mpu code */
2881 release_region (dev
.base
+2, 6);
2884 release_region (dev
.base
+8, 8);
2887 unregister_sound_synth (dev
.synth_dev
);
2889 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2890 sound_unload_synthdev (dev
.oss_dev
);
2891 #endif OSS_SUPPORT_SEQ
2892 uninstall_wf_mpu ();
2895 /***********************************************************************/
2896 /* WaveFront FX control */
2897 /***********************************************************************/
2901 /* Control bits for the Load Control Register
2904 #define FX_LSB_TRANSFER 0x01 /* transfer after DSP LSB byte written */
2905 #define FX_MSB_TRANSFER 0x02 /* transfer after DSP MSB byte written */
2906 #define FX_AUTO_INCR 0x04 /* auto-increment DSP address after transfer */
2913 unsigned int x
= 0x80;
2915 for (i
= 0; i
< 1000; i
++) {
2916 x
= inb (dev
.fx_status
);
2917 if ((x
& 0x80) == 0) {
2923 printk (KERN_ERR LOGNAME
"FX device never idle.\n");
2930 int __init
detect_wffx (void)
2932 /* This is a crude check, but its the best one I have for now.
2933 Certainly on the Maui and the Tropez, wffx_idle() will
2934 report "never idle", which suggests that this test should
2938 if (inb (dev
.fx_status
) & 0x80) {
2939 printk (KERN_INFO LOGNAME
"Hmm, probably a Maui or Tropez.\n");
2946 int __init
attach_wffx (void)
2948 if ((dev
.fx_mididev
= sound_alloc_mididev ()) < 0) {
2949 printk (KERN_WARNING LOGNAME
"cannot install FX Midi driver\n");
2957 wffx_mute (int onoff
)
2964 outb (onoff
? 0x02 : 0x00, dev
.fx_op
);
2968 wffx_memset (int page
,
2969 int addr
, int cnt
, unsigned short *data
)
2971 if (page
< 0 || page
> 7) {
2972 printk (KERN_ERR LOGNAME
"FX memset: "
2973 "page must be >= 0 and <= 7\n");
2977 if (addr
< 0 || addr
> 0x7f) {
2978 printk (KERN_ERR LOGNAME
"FX memset: "
2979 "addr must be >= 0 and <= 7f\n");
2985 outb (FX_LSB_TRANSFER
, dev
.fx_lcr
);
2986 outb (page
, dev
.fx_dsp_page
);
2987 outb (addr
, dev
.fx_dsp_addr
);
2988 outb ((data
[0] >> 8), dev
.fx_dsp_msb
);
2989 outb ((data
[0] & 0xff), dev
.fx_dsp_lsb
);
2991 printk (KERN_INFO LOGNAME
"FX: addr %d:%x set to 0x%x\n",
2992 page
, addr
, data
[0]);
2997 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
2998 outb (page
, dev
.fx_dsp_page
);
2999 outb (addr
, dev
.fx_dsp_addr
);
3001 for (i
= 0; i
< cnt
; i
++) {
3002 outb ((data
[i
] >> 8), dev
.fx_dsp_msb
);
3003 outb ((data
[i
] & 0xff), dev
.fx_dsp_lsb
);
3004 if (!wffx_idle ()) {
3010 printk (KERN_WARNING LOGNAME
3012 "(0x%x, 0x%x, 0x%x, %d) incomplete\n",
3013 page
, addr
, (int) data
, cnt
);
3022 wffx_ioctl (wavefront_fx_info
*r
)
3025 unsigned short page_data
[256];
3028 switch (r
->request
) {
3030 wffx_mute (r
->data
[0]);
3035 if (r
->data
[2] <= 0) {
3036 printk (KERN_ERR LOGNAME
"cannot write "
3037 "<= 0 bytes to FX\n");
3039 } else if (r
->data
[2] == 1) {
3040 pd
= (unsigned short *) &r
->data
[3];
3042 if (r
->data
[2] > sizeof (page_data
)) {
3043 printk (KERN_ERR LOGNAME
"cannot write "
3044 "> 255 bytes to FX\n");
3047 copy_from_user (page_data
, (unsigned char *) r
->data
[3],
3052 return wffx_memset (r
->data
[0], /* page */
3053 r
->data
[1], /* addr */
3054 r
->data
[2], /* cnt */
3058 printk (KERN_WARNING LOGNAME
3059 "FX: ioctl %d not yet supported\n",
3065 /* YSS225 initialization.
3067 This code was developed using DOSEMU. The Turtle Beach SETUPSND
3068 utility was run with I/O tracing in DOSEMU enabled, and a reconstruction
3069 of the port I/O done, using the Yamaha faxback document as a guide
3070 to add more logic to the code. Its really pretty wierd.
3072 There was an alternative approach of just dumping the whole I/O
3073 sequence as a series of port/value pairs and a simple loop
3074 that output it. However, I hope that eventually I'll get more
3075 control over what this code does, and so I tried to stick with
3076 a somewhat "algorithmic" approach.
3079 static int wffx_init (void)
3084 /* Set all bits for all channels on the MOD unit to zero */
3085 /* XXX But why do this twice ? */
3087 for (j
= 0; j
< 2; j
++) {
3088 for (i
= 0x10; i
<= 0xff; i
++) {
3090 if (!wffx_idle ()) {
3094 outb (i
, dev
.fx_mod_addr
);
3095 outb (0x0, dev
.fx_mod_data
);
3099 if (!wffx_idle()) return (-1);
3100 outb (0x02, dev
.fx_op
); /* mute on */
3102 if (!wffx_idle()) return (-1);
3103 outb (0x07, dev
.fx_dsp_page
);
3104 outb (0x44, dev
.fx_dsp_addr
);
3105 outb (0x00, dev
.fx_dsp_msb
);
3106 outb (0x00, dev
.fx_dsp_lsb
);
3107 if (!wffx_idle()) return (-1);
3108 outb (0x07, dev
.fx_dsp_page
);
3109 outb (0x42, dev
.fx_dsp_addr
);
3110 outb (0x00, dev
.fx_dsp_msb
);
3111 outb (0x00, dev
.fx_dsp_lsb
);
3112 if (!wffx_idle()) return (-1);
3113 outb (0x07, dev
.fx_dsp_page
);
3114 outb (0x43, dev
.fx_dsp_addr
);
3115 outb (0x00, dev
.fx_dsp_msb
);
3116 outb (0x00, dev
.fx_dsp_lsb
);
3117 if (!wffx_idle()) return (-1);
3118 outb (0x07, dev
.fx_dsp_page
);
3119 outb (0x7c, dev
.fx_dsp_addr
);
3120 outb (0x00, dev
.fx_dsp_msb
);
3121 outb (0x00, dev
.fx_dsp_lsb
);
3122 if (!wffx_idle()) return (-1);
3123 outb (0x07, dev
.fx_dsp_page
);
3124 outb (0x7e, dev
.fx_dsp_addr
);
3125 outb (0x00, dev
.fx_dsp_msb
);
3126 outb (0x00, dev
.fx_dsp_lsb
);
3127 if (!wffx_idle()) return (-1);
3128 outb (0x07, dev
.fx_dsp_page
);
3129 outb (0x46, dev
.fx_dsp_addr
);
3130 outb (0x00, dev
.fx_dsp_msb
);
3131 outb (0x00, dev
.fx_dsp_lsb
);
3132 if (!wffx_idle()) return (-1);
3133 outb (0x07, dev
.fx_dsp_page
);
3134 outb (0x49, dev
.fx_dsp_addr
);
3135 outb (0x00, dev
.fx_dsp_msb
);
3136 outb (0x00, dev
.fx_dsp_lsb
);
3137 if (!wffx_idle()) return (-1);
3138 outb (0x07, dev
.fx_dsp_page
);
3139 outb (0x47, dev
.fx_dsp_addr
);
3140 outb (0x00, dev
.fx_dsp_msb
);
3141 outb (0x00, dev
.fx_dsp_lsb
);
3142 if (!wffx_idle()) return (-1);
3143 outb (0x07, dev
.fx_dsp_page
);
3144 outb (0x4a, dev
.fx_dsp_addr
);
3145 outb (0x00, dev
.fx_dsp_msb
);
3146 outb (0x00, dev
.fx_dsp_lsb
);
3148 /* either because of stupidity by TB's programmers, or because it
3149 actually does something, rezero the MOD page.
3151 for (i
= 0x10; i
<= 0xff; i
++) {
3153 if (!wffx_idle ()) {
3157 outb (i
, dev
.fx_mod_addr
);
3158 outb (0x0, dev
.fx_mod_data
);
3160 /* load page zero */
3162 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3163 outb (0x00, dev
.fx_dsp_page
);
3164 outb (0x00, dev
.fx_dsp_addr
);
3166 for (i
= 0; i
< sizeof (page_zero
); i
+= 2) {
3167 outb (page_zero
[i
], dev
.fx_dsp_msb
);
3168 outb (page_zero
[i
+1], dev
.fx_dsp_lsb
);
3169 if (!wffx_idle()) return (-1);
3172 /* Now load page one */
3174 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3175 outb (0x01, dev
.fx_dsp_page
);
3176 outb (0x00, dev
.fx_dsp_addr
);
3178 for (i
= 0; i
< sizeof (page_one
); i
+= 2) {
3179 outb (page_one
[i
], dev
.fx_dsp_msb
);
3180 outb (page_one
[i
+1], dev
.fx_dsp_lsb
);
3181 if (!wffx_idle()) return (-1);
3184 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3185 outb (0x02, dev
.fx_dsp_page
);
3186 outb (0x00, dev
.fx_dsp_addr
);
3188 for (i
= 0; i
< sizeof (page_two
); i
++) {
3189 outb (page_two
[i
], dev
.fx_dsp_lsb
);
3190 if (!wffx_idle()) return (-1);
3193 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3194 outb (0x03, dev
.fx_dsp_page
);
3195 outb (0x00, dev
.fx_dsp_addr
);
3197 for (i
= 0; i
< sizeof (page_three
); i
++) {
3198 outb (page_three
[i
], dev
.fx_dsp_lsb
);
3199 if (!wffx_idle()) return (-1);
3202 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3203 outb (0x04, dev
.fx_dsp_page
);
3204 outb (0x00, dev
.fx_dsp_addr
);
3206 for (i
= 0; i
< sizeof (page_four
); i
++) {
3207 outb (page_four
[i
], dev
.fx_dsp_lsb
);
3208 if (!wffx_idle()) return (-1);
3211 /* Load memory area (page six) */
3213 outb (FX_LSB_TRANSFER
, dev
.fx_lcr
);
3214 outb (0x06, dev
.fx_dsp_page
);
3216 for (i
= 0; i
< sizeof (page_six
); i
+= 3) {
3217 outb (page_six
[i
], dev
.fx_dsp_addr
);
3218 outb (page_six
[i
+1], dev
.fx_dsp_msb
);
3219 outb (page_six
[i
+2], dev
.fx_dsp_lsb
);
3220 if (!wffx_idle()) return (-1);
3223 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3224 outb (0x07, dev
.fx_dsp_page
);
3225 outb (0x00, dev
.fx_dsp_addr
);
3227 for (i
= 0; i
< sizeof (page_seven
); i
+= 2) {
3228 outb (page_seven
[i
], dev
.fx_dsp_msb
);
3229 outb (page_seven
[i
+1], dev
.fx_dsp_lsb
);
3230 if (!wffx_idle()) return (-1);
3233 /* Now setup the MOD area. We do this algorithmically in order to
3234 save a little data space. It could be done in the same fashion
3238 for (i
= 0x00; i
<= 0x0f; i
++) {
3239 outb (0x01, dev
.fx_mod_addr
);
3240 outb (i
, dev
.fx_mod_data
);
3241 if (!wffx_idle()) return (-1);
3242 outb (0x02, dev
.fx_mod_addr
);
3243 outb (0x00, dev
.fx_mod_data
);
3244 if (!wffx_idle()) return (-1);
3247 for (i
= 0xb0; i
<= 0xbf; i
++) {
3248 outb (i
, dev
.fx_mod_addr
);
3249 outb (0x20, dev
.fx_mod_data
);
3250 if (!wffx_idle()) return (-1);
3253 for (i
= 0xf0; i
<= 0xff; i
++) {
3254 outb (i
, dev
.fx_mod_addr
);
3255 outb (0x20, dev
.fx_mod_data
);
3256 if (!wffx_idle()) return (-1);
3259 for (i
= 0x10; i
<= 0x1d; i
++) {
3260 outb (i
, dev
.fx_mod_addr
);
3261 outb (0xff, dev
.fx_mod_data
);
3262 if (!wffx_idle()) return (-1);
3265 outb (0x1e, dev
.fx_mod_addr
);
3266 outb (0x40, dev
.fx_mod_data
);
3267 if (!wffx_idle()) return (-1);
3269 for (i
= 0x1f; i
<= 0x2d; i
++) {
3270 outb (i
, dev
.fx_mod_addr
);
3271 outb (0xff, dev
.fx_mod_data
);
3272 if (!wffx_idle()) return (-1);
3275 outb (0x2e, dev
.fx_mod_addr
);
3276 outb (0x00, dev
.fx_mod_data
);
3277 if (!wffx_idle()) return (-1);
3279 for (i
= 0x2f; i
<= 0x3e; i
++) {
3280 outb (i
, dev
.fx_mod_addr
);
3281 outb (0x00, dev
.fx_mod_data
);
3282 if (!wffx_idle()) return (-1);
3285 outb (0x3f, dev
.fx_mod_addr
);
3286 outb (0x20, dev
.fx_mod_data
);
3287 if (!wffx_idle()) return (-1);
3289 for (i
= 0x40; i
<= 0x4d; i
++) {
3290 outb (i
, dev
.fx_mod_addr
);
3291 outb (0x00, dev
.fx_mod_data
);
3292 if (!wffx_idle()) return (-1);
3295 outb (0x4e, dev
.fx_mod_addr
);
3296 outb (0x0e, dev
.fx_mod_data
);
3297 if (!wffx_idle()) return (-1);
3298 outb (0x4f, dev
.fx_mod_addr
);
3299 outb (0x0e, dev
.fx_mod_data
);
3300 if (!wffx_idle()) return (-1);
3303 for (i
= 0x50; i
<= 0x6b; i
++) {
3304 outb (i
, dev
.fx_mod_addr
);
3305 outb (0x00, dev
.fx_mod_data
);
3306 if (!wffx_idle()) return (-1);
3309 outb (0x6c, dev
.fx_mod_addr
);
3310 outb (0x40, dev
.fx_mod_data
);
3311 if (!wffx_idle()) return (-1);
3313 outb (0x6d, dev
.fx_mod_addr
);
3314 outb (0x00, dev
.fx_mod_data
);
3315 if (!wffx_idle()) return (-1);
3317 outb (0x6e, dev
.fx_mod_addr
);
3318 outb (0x40, dev
.fx_mod_data
);
3319 if (!wffx_idle()) return (-1);
3321 outb (0x6f, dev
.fx_mod_addr
);
3322 outb (0x40, dev
.fx_mod_data
);
3323 if (!wffx_idle()) return (-1);
3325 for (i
= 0x70; i
<= 0x7f; i
++) {
3326 outb (i
, dev
.fx_mod_addr
);
3327 outb (0xc0, dev
.fx_mod_data
);
3328 if (!wffx_idle()) return (-1);
3331 for (i
= 0x80; i
<= 0xaf; i
++) {
3332 outb (i
, dev
.fx_mod_addr
);
3333 outb (0x00, dev
.fx_mod_data
);
3334 if (!wffx_idle()) return (-1);
3337 for (i
= 0xc0; i
<= 0xdd; i
++) {
3338 outb (i
, dev
.fx_mod_addr
);
3339 outb (0x00, dev
.fx_mod_data
);
3340 if (!wffx_idle()) return (-1);
3343 outb (0xde, dev
.fx_mod_addr
);
3344 outb (0x10, dev
.fx_mod_data
);
3345 if (!wffx_idle()) return (-1);
3346 outb (0xdf, dev
.fx_mod_addr
);
3347 outb (0x10, dev
.fx_mod_data
);
3348 if (!wffx_idle()) return (-1);
3350 for (i
= 0xe0; i
<= 0xef; i
++) {
3351 outb (i
, dev
.fx_mod_addr
);
3352 outb (0x00, dev
.fx_mod_data
);
3353 if (!wffx_idle()) return (-1);
3356 for (i
= 0x00; i
<= 0x0f; i
++) {
3357 outb (0x01, dev
.fx_mod_addr
);
3358 outb (i
, dev
.fx_mod_data
);
3359 outb (0x02, dev
.fx_mod_addr
);
3360 outb (0x01, dev
.fx_mod_data
);
3361 if (!wffx_idle()) return (-1);
3364 outb (0x02, dev
.fx_op
); /* mute on */
3366 /* Now set the coefficients and so forth for the programs above */
3368 for (i
= 0; i
< sizeof (coefficients
); i
+= 4) {
3369 outb (coefficients
[i
], dev
.fx_dsp_page
);
3370 outb (coefficients
[i
+1], dev
.fx_dsp_addr
);
3371 outb (coefficients
[i
+2], dev
.fx_dsp_msb
);
3372 outb (coefficients
[i
+3], dev
.fx_dsp_lsb
);
3373 if (!wffx_idle()) return (-1);
3376 /* Some settings (?) that are too small to bundle into loops */
3378 if (!wffx_idle()) return (-1);
3379 outb (0x1e, dev
.fx_mod_addr
);
3380 outb (0x14, dev
.fx_mod_data
);
3381 if (!wffx_idle()) return (-1);
3382 outb (0xde, dev
.fx_mod_addr
);
3383 outb (0x20, dev
.fx_mod_data
);
3384 if (!wffx_idle()) return (-1);
3385 outb (0xdf, dev
.fx_mod_addr
);
3386 outb (0x20, dev
.fx_mod_data
);
3388 /* some more coefficients */
3390 if (!wffx_idle()) return (-1);
3391 outb (0x06, dev
.fx_dsp_page
);
3392 outb (0x78, dev
.fx_dsp_addr
);
3393 outb (0x00, dev
.fx_dsp_msb
);
3394 outb (0x40, dev
.fx_dsp_lsb
);
3395 if (!wffx_idle()) return (-1);
3396 outb (0x07, dev
.fx_dsp_page
);
3397 outb (0x03, dev
.fx_dsp_addr
);
3398 outb (0x0f, dev
.fx_dsp_msb
);
3399 outb (0xff, dev
.fx_dsp_lsb
);
3400 if (!wffx_idle()) return (-1);
3401 outb (0x07, dev
.fx_dsp_page
);
3402 outb (0x0b, dev
.fx_dsp_addr
);
3403 outb (0x0f, dev
.fx_dsp_msb
);
3404 outb (0xff, dev
.fx_dsp_lsb
);
3405 if (!wffx_idle()) return (-1);
3406 outb (0x07, dev
.fx_dsp_page
);
3407 outb (0x02, dev
.fx_dsp_addr
);
3408 outb (0x00, dev
.fx_dsp_msb
);
3409 outb (0x00, dev
.fx_dsp_lsb
);
3410 if (!wffx_idle()) return (-1);
3411 outb (0x07, dev
.fx_dsp_page
);
3412 outb (0x0a, dev
.fx_dsp_addr
);
3413 outb (0x00, dev
.fx_dsp_msb
);
3414 outb (0x00, dev
.fx_dsp_lsb
);
3415 if (!wffx_idle()) return (-1);
3416 outb (0x07, dev
.fx_dsp_page
);
3417 outb (0x46, dev
.fx_dsp_addr
);
3418 outb (0x00, dev
.fx_dsp_msb
);
3419 outb (0x00, dev
.fx_dsp_lsb
);
3420 if (!wffx_idle()) return (-1);
3421 outb (0x07, dev
.fx_dsp_page
);
3422 outb (0x49, dev
.fx_dsp_addr
);
3423 outb (0x00, dev
.fx_dsp_msb
);
3424 outb (0x00, dev
.fx_dsp_lsb
);
3426 /* Now, for some strange reason, lets reload every page
3427 and all the coefficients over again. I have *NO* idea
3428 why this is done. I do know that no sound is produced
3429 is this phase is omitted.
3432 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3433 outb (0x00, dev
.fx_dsp_page
);
3434 outb (0x10, dev
.fx_dsp_addr
);
3436 for (i
= 0; i
< sizeof (page_zero_v2
); i
+= 2) {
3437 outb (page_zero_v2
[i
], dev
.fx_dsp_msb
);
3438 outb (page_zero_v2
[i
+1], dev
.fx_dsp_lsb
);
3439 if (!wffx_idle()) return (-1);
3442 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3443 outb (0x01, dev
.fx_dsp_page
);
3444 outb (0x10, dev
.fx_dsp_addr
);
3446 for (i
= 0; i
< sizeof (page_one_v2
); i
+= 2) {
3447 outb (page_one_v2
[i
], dev
.fx_dsp_msb
);
3448 outb (page_one_v2
[i
+1], dev
.fx_dsp_lsb
);
3449 if (!wffx_idle()) return (-1);
3452 if (!wffx_idle()) return (-1);
3453 if (!wffx_idle()) return (-1);
3455 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3456 outb (0x02, dev
.fx_dsp_page
);
3457 outb (0x10, dev
.fx_dsp_addr
);
3459 for (i
= 0; i
< sizeof (page_two_v2
); i
++) {
3460 outb (page_two_v2
[i
], dev
.fx_dsp_lsb
);
3461 if (!wffx_idle()) return (-1);
3463 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3464 outb (0x03, dev
.fx_dsp_page
);
3465 outb (0x10, dev
.fx_dsp_addr
);
3467 for (i
= 0; i
< sizeof (page_three_v2
); i
++) {
3468 outb (page_three_v2
[i
], dev
.fx_dsp_lsb
);
3469 if (!wffx_idle()) return (-1);
3472 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3473 outb (0x04, dev
.fx_dsp_page
);
3474 outb (0x10, dev
.fx_dsp_addr
);
3476 for (i
= 0; i
< sizeof (page_four_v2
); i
++) {
3477 outb (page_four_v2
[i
], dev
.fx_dsp_lsb
);
3478 if (!wffx_idle()) return (-1);
3481 outb (FX_LSB_TRANSFER
, dev
.fx_lcr
);
3482 outb (0x06, dev
.fx_dsp_page
);
3484 /* Page six v.2 is algorithmic */
3486 for (i
= 0x10; i
<= 0x3e; i
+= 2) {
3487 outb (i
, dev
.fx_dsp_addr
);
3488 outb (0x00, dev
.fx_dsp_msb
);
3489 outb (0x00, dev
.fx_dsp_lsb
);
3490 if (!wffx_idle()) return (-1);
3493 outb (FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
);
3494 outb (0x07, dev
.fx_dsp_page
);
3495 outb (0x10, dev
.fx_dsp_addr
);
3497 for (i
= 0; i
< sizeof (page_seven_v2
); i
+= 2) {
3498 outb (page_seven_v2
[i
], dev
.fx_dsp_msb
);
3499 outb (page_seven_v2
[i
+1], dev
.fx_dsp_lsb
);
3500 if (!wffx_idle()) return (-1);
3503 for (i
= 0x00; i
< sizeof(mod_v2
); i
+= 2) {
3504 outb (mod_v2
[i
], dev
.fx_mod_addr
);
3505 outb (mod_v2
[i
+1], dev
.fx_mod_data
);
3506 if (!wffx_idle()) return (-1);
3509 for (i
= 0; i
< sizeof (coefficients2
); i
+= 4) {
3510 outb (coefficients2
[i
], dev
.fx_dsp_page
);
3511 outb (coefficients2
[i
+1], dev
.fx_dsp_addr
);
3512 outb (coefficients2
[i
+2], dev
.fx_dsp_msb
);
3513 outb (coefficients2
[i
+3], dev
.fx_dsp_lsb
);
3514 if (!wffx_idle()) return (-1);
3517 for (i
= 0; i
< sizeof (coefficients3
); i
+= 2) {
3520 outb (0x07, dev
.fx_dsp_page
);
3521 x
= (i
% 4) ? 0x4e : 0x4c;
3522 outb (x
, dev
.fx_dsp_addr
);
3523 outb (coefficients3
[i
], dev
.fx_dsp_msb
);
3524 outb (coefficients3
[i
+1], dev
.fx_dsp_lsb
);
3527 outb (0x00, dev
.fx_op
); /* mute off */
3528 if (!wffx_idle()) return (-1);
3534 static int irq
= -1;
3536 MODULE_AUTHOR ("Paul Barton-Davis <pbd@op.net>");
3537 MODULE_DESCRIPTION ("Turtle Beach WaveFront Linux Driver");
3538 MODULE_PARM (io
,"i");
3539 MODULE_PARM (irq
,"i");
3541 static int __init
init_wavfront (void)
3543 printk ("Turtle Beach WaveFront Driver\n"
3544 "Copyright (C) by Hannu Solvainen, "
3545 "Paul Barton-Davis 1993-1998.\n");
3547 /* XXX t'would be lovely to ask the CS4232 for these values, eh ? */
3549 if (io
== -1 || irq
== -1) {
3550 printk (KERN_INFO LOGNAME
"irq and io options must be set.\n");
3554 if (wavefront_interrupt_bits (irq
) < 0) {
3555 printk (KERN_INFO LOGNAME
3556 "IRQ must be 9, 5, 12 or 15 (not %d)\n", irq
);
3560 if (detect_wavefront (irq
, io
) < 0) {
3564 if (install_wavefront () < 0) {
3571 static void __exit
cleanup_wavfront (void)
3573 uninstall_wavefront ();
3576 module_init(init_wavfront
);
3577 module_exit(cleanup_wavfront
);