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/ioport.h> 80 #include <linux/interrupt.h> 81 #include <linux/config.h> 83 #include <linux/delay.h> 85 #include"sound_config.h" 87 #include <linux/wavefront.h> 90 * This sucks, hopefully it'll get standardised 93 #if defined(__alpha__) 95 #define LOOPS_PER_TICK cpu_data[smp_processor_id()].loops_per_jiffy 97 #define LOOPS_PER_TICK loops_per_sec 101 #if defined(__i386__) 102 #define LOOPS_PER_TICK current_cpu_data.loops_per_jiffy 105 #define _MIDI_SYNTH_C_ 106 #define MIDI_SYNTH_NAME"WaveFront MIDI" 107 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT 108 #include"midi_synth.h" 110 /* Compile-time control of the extent to which OSS is supported. 112 I consider /dev/sequencer to be an anachronism, but given its 113 widespread usage by various Linux MIDI software, it seems worth 114 offering support to it if its not too painful. Instead of using 115 /dev/sequencer, I recommend: 117 for synth programming and patch loading: /dev/synthNN 118 for kernel-synchronized MIDI sequencing: the ALSA sequencer 119 for direct MIDI control: /dev/midiNN 121 I have never tried static compilation into the kernel. The #if's 122 for this are really just notes to myself about what the code is 126 #define OSS_SUPPORT_SEQ 0x1/* use of /dev/sequencer */ 127 #define OSS_SUPPORT_STATIC_INSTALL 0x2/* static compilation into kernel */ 129 #define OSS_SUPPORT_LEVEL 0x1/* just /dev/sequencer for now */ 131 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ 132 static int(*midi_load_patch
) (int devno
,int format
,const char*addr
, 133 int offs
,int count
,int pmgr_flag
) = NULL
; 134 #endif OSS_SUPPORT_SEQ 136 /* if WF_DEBUG not defined, no run-time debugging messages will 137 be available via the debug flag setting. Given the current 138 beta state of the driver, this will remain set until a future 146 /* Thank goodness for gcc's preprocessor ... */ 148 #define DPRINT(cond, format, args...) \ 149 if ((dev.debug & (cond)) == (cond)) { \ 150 printk (KERN_DEBUG LOGNAME format, ## args); \ 153 #define DPRINT(cond, format, args...) 156 #define LOGNAME"WaveFront: " 158 /* bitmasks for WaveFront status port value */ 160 #define STAT_RINTR_ENABLED 0x01 161 #define STAT_CAN_READ 0x02 162 #define STAT_INTR_READ 0x04 163 #define STAT_WINTR_ENABLED 0x10 164 #define STAT_CAN_WRITE 0x20 165 #define STAT_INTR_WRITE 0x40 167 /*** Module-accessible parameters ***************************************/ 169 int wf_raw
=0;/* we normally check for "raw state" to firmware 170 loading. if set, then during driver loading, the 171 state of the board is ignored, and we reset the 172 board and load the firmware anyway. 175 int fx_raw
=1;/* if this is zero, we'll leave the FX processor in 176 whatever state it is when the driver is loaded. 177 The default is to download the microprogram and 178 associated coefficients to set it up for "default" 179 operation, whatever that means. 182 int debug_default
=0;/* you can set this to control debugging 183 during driver loading. it takes any combination 184 of the WF_DEBUG_* flags defined in 188 /* XXX this needs to be made firmware and hardware version dependent */ 190 char*ospath
="/etc/sound/wavefront.os";/* where to find a processed 191 version of the WaveFront OS 194 int wait_usecs
=150;/* This magic number seems to give pretty optimal 195 throughput based on my limited experimentation. 196 If you want to play around with it and find a better 197 value, be my guest. Remember, the idea is to 198 get a number that causes us to just busy wait 199 for as many WaveFront commands as possible, without 200 coming up with a number so large that we hog the 203 Specifically, with this number, out of about 134,000 204 status waits, only about 250 result in a sleep. 207 int sleep_interval
=100;/* HZ/sleep_interval seconds per sleep */ 208 int sleep_tries
=50;/* number of times we'll try to sleep */ 210 int reset_time
=2;/* hundreths of a second we wait after a HW reset for 211 the expected interrupt. 214 int ramcheck_time
=20;/* time in seconds to wait while ROM code 218 int osrun_time
=10;/* time in seconds we wait for the OS to 222 MODULE_PARM(wf_raw
,"i"); 223 MODULE_PARM(fx_raw
,"i"); 224 MODULE_PARM(debug_default
,"i"); 225 MODULE_PARM(wait_usecs
,"i"); 226 MODULE_PARM(sleep_interval
,"i"); 227 MODULE_PARM(sleep_tries
,"i"); 228 MODULE_PARM(ospath
,"s"); 229 MODULE_PARM(reset_time
,"i"); 230 MODULE_PARM(ramcheck_time
,"i"); 231 MODULE_PARM(osrun_time
,"i"); 233 /***************************************************************************/ 235 /* Note: because this module doesn't export any symbols, this really isn't 236 a global variable, even if it looks like one. I was quite confused by 237 this when I started writing this as a (newer) module -- pbd. 241 int devno
;/* device number from kernel */ 242 int irq
;/* "you were one, one of the few ..." */ 243 int base
;/* low i/o port address */ 245 #define mpu_data_port base 246 #define mpu_command_port base + 1/* write semantics */ 247 #define mpu_status_port base + 1/* read semantics */ 248 #define data_port base + 2 249 #define status_port base + 3/* read semantics */ 250 #define control_port base + 3/* write semantics */ 251 #define block_port base + 4/* 16 bit, writeonly */ 252 #define last_block_port base + 6/* 16 bit, writeonly */ 254 /* FX ports. These are mapped through the ICS2115 to the YS225. 255 The ICS2115 takes care of flipping the relevant pins on the 256 YS225 so that access to each of these ports does the right 257 thing. Note: these are NOT documented by Turtle Beach. 260 #define fx_status base + 8 261 #define fx_op base + 8 262 #define fx_lcr base + 9 263 #define fx_dsp_addr base + 0xa 264 #define fx_dsp_page base + 0xb 265 #define fx_dsp_lsb base + 0xc 266 #define fx_dsp_msb base + 0xd 267 #define fx_mod_addr base + 0xe 268 #define fx_mod_data base + 0xf 270 volatileint irq_ok
;/* set by interrupt handler */ 271 volatileint irq_cnt
;/* ditto */ 272 int opened
;/* flag, holds open(2) mode */ 273 char debug
;/* debugging flags */ 274 int freemem
;/* installed RAM, in bytes */ 276 int synth_dev
;/* devno for "raw" synth */ 277 int mididev
;/* devno for internal MIDI */ 278 int ext_mididev
;/* devno for external MIDI */ 279 int fx_mididev
;/* devno for FX MIDI interface */ 280 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ 281 int oss_dev
;/* devno for OSS sequencer synth */ 282 #endif OSS_SUPPORT_SEQ 284 char fw_version
[2];/* major = [0], minor = [1] */ 285 char hw_version
[2];/* major = [0], minor = [1] */ 286 char israw
;/* needs Motorola microcode */ 287 char has_fx
;/* has FX processor (Tropez+) */ 288 char prog_status
[WF_MAX_PROGRAM
];/* WF_SLOT_* */ 289 char patch_status
[WF_MAX_PATCH
];/* WF_SLOT_* */ 290 char sample_status
[WF_MAX_SAMPLE
];/* WF_ST_* | WF_SLOT_* */ 291 int samples_used
;/* how many */ 292 char interrupts_on
;/* h/w MPU interrupts enabled ? */ 293 char rom_samples_rdonly
;/* can we write on ROM samples */ 294 wait_queue_head_t interrupt_sleeper
; 297 static intdetect_wffx(void); 298 static intwffx_ioctl(wavefront_fx_info
*); 299 static intwffx_init(void); 301 static intwavefront_delete_sample(int sampnum
); 302 static intwavefront_find_free_sample(void); 306 externintvirtual_midi_enable(void); 307 externintvirtual_midi_disable(void); 308 externintdetect_wf_mpu(int,int); 309 externintinstall_wf_mpu(void); 310 externintuninstall_wf_mpu(void); 315 unsigned int read_cnt
; 316 unsigned int write_cnt
; 323 } wavefront_errors
[] = { 324 {0x01,"Bad sample number"}, 325 {0x02,"Out of sample memory"}, 326 {0x03,"Bad patch number"}, 327 {0x04,"Error in number of voices"}, 328 {0x06,"Sample load already in progress"}, 329 {0x0B,"No sample load request pending"}, 330 {0x0E,"Bad MIDI channel number"}, 331 {0x10,"Download Record Error"}, 338 static wavefront_command wavefront_commands
[] = { 339 { WFC_SET_SYNTHVOL
,"set synthesizer volume",0,1, NEEDS_ACK
}, 340 { WFC_GET_SYNTHVOL
,"get synthesizer volume",1,0,0}, 341 { WFC_SET_NVOICES
,"set number of voices",0,1, NEEDS_ACK
}, 342 { WFC_GET_NVOICES
,"get number of voices",1,0,0}, 343 { WFC_SET_TUNING
,"set synthesizer tuning",0,2, NEEDS_ACK
}, 344 { WFC_GET_TUNING
,"get synthesizer tuning",2,0,0}, 345 { WFC_DISABLE_CHANNEL
,"disable synth channel",0,1, NEEDS_ACK
}, 346 { WFC_ENABLE_CHANNEL
,"enable synth channel",0,1, NEEDS_ACK
}, 347 { WFC_GET_CHANNEL_STATUS
,"get synth channel status",3,0,0}, 348 { WFC_MISYNTH_OFF
,"disable midi-in to synth",0,0, NEEDS_ACK
}, 349 { WFC_MISYNTH_ON
,"enable midi-in to synth",0,0, NEEDS_ACK
}, 350 { WFC_VMIDI_ON
,"enable virtual midi mode",0,0, NEEDS_ACK
}, 351 { WFC_VMIDI_OFF
,"disable virtual midi mode",0,0, NEEDS_ACK
}, 352 { WFC_MIDI_STATUS
,"report midi status",1,0,0}, 353 { WFC_FIRMWARE_VERSION
,"report firmware version",2,0,0}, 354 { WFC_HARDWARE_VERSION
,"report hardware version",2,0,0}, 355 { WFC_GET_NSAMPLES
,"report number of samples",2,0,0}, 356 { WFC_INSTOUT_LEVELS
,"report instantaneous output levels",7,0,0}, 357 { WFC_PEAKOUT_LEVELS
,"report peak output levels",7,0,0}, 358 { WFC_DOWNLOAD_SAMPLE
,"download sample", 359 0, WF_SAMPLE_BYTES
, NEEDS_ACK
}, 360 { WFC_DOWNLOAD_BLOCK
,"download block",0,0, NEEDS_ACK
}, 361 { WFC_DOWNLOAD_SAMPLE_HEADER
,"download sample header", 362 0, WF_SAMPLE_HDR_BYTES
, NEEDS_ACK
}, 363 { WFC_UPLOAD_SAMPLE_HEADER
,"upload sample header",13,2,0}, 365 /* This command requires a variable number of bytes to be written. 366 There is a hack in wavefront_cmd() to support this. The actual 367 count is passed in as the read buffer ptr, cast appropriately. 371 { WFC_DOWNLOAD_MULTISAMPLE
,"download multisample",0,0, NEEDS_ACK
}, 373 /* This one is a hack as well. We just read the first byte of the 374 response, don't fetch an ACK, and leave the rest to the 375 calling function. Ugly, ugly, ugly. 378 { WFC_UPLOAD_MULTISAMPLE
,"upload multisample",2,1,0}, 379 { WFC_DOWNLOAD_SAMPLE_ALIAS
,"download sample alias", 380 0, WF_ALIAS_BYTES
, NEEDS_ACK
}, 381 { WFC_UPLOAD_SAMPLE_ALIAS
,"upload sample alias", WF_ALIAS_BYTES
,2,0}, 382 { WFC_DELETE_SAMPLE
,"delete sample",0,2, NEEDS_ACK
}, 383 { WFC_IDENTIFY_SAMPLE_TYPE
,"identify sample type",5,2,0}, 384 { WFC_UPLOAD_SAMPLE_PARAMS
,"upload sample parameters"}, 385 { WFC_REPORT_FREE_MEMORY
,"report free memory",4,0,0}, 386 { WFC_DOWNLOAD_PATCH
,"download patch",0,134, NEEDS_ACK
}, 387 { WFC_UPLOAD_PATCH
,"upload patch",132,2,0}, 388 { WFC_DOWNLOAD_PROGRAM
,"download program",0,33, NEEDS_ACK
}, 389 { WFC_UPLOAD_PROGRAM
,"upload program",32,1,0}, 390 { WFC_DOWNLOAD_EDRUM_PROGRAM
,"download enhanced drum program",0,9, 392 { WFC_UPLOAD_EDRUM_PROGRAM
,"upload enhanced drum program",8,1,0}, 393 { WFC_SET_EDRUM_CHANNEL
,"set enhanced drum program channel", 395 { WFC_DISABLE_DRUM_PROGRAM
,"disable drum program",0,1, NEEDS_ACK
}, 396 { WFC_REPORT_CHANNEL_PROGRAMS
,"report channel program numbers", 398 { WFC_NOOP
,"the no-op command",0,0, NEEDS_ACK
}, 403 wavefront_errorstr(int errnum
) 408 for(i
=0; wavefront_errors
[i
].errstr
; i
++) { 409 if(wavefront_errors
[i
].errno
== errnum
) { 410 return wavefront_errors
[i
].errstr
; 414 return"Unknown WaveFront error"; 417 static wavefront_command
* 418 wavefront_get_command(int cmd
) 423 for(i
=0; wavefront_commands
[i
].cmd
!=0; i
++) { 424 if(cmd
== wavefront_commands
[i
].cmd
) { 425 return&wavefront_commands
[i
]; 429 return(wavefront_command
*)0; 433 wavefront_status(void) 436 returninb(dev
.status_port
); 440 wavefront_sleep(int limit
) 443 current
->state
= TASK_INTERRUPTIBLE
; 444 schedule_timeout(limit
); 446 returnsignal_pending(current
); 450 wavefront_wait(int mask
) 454 static int short_loop_cnt
=0; 456 /* Compute the loop count that lets us sleep for about the 457 right amount of time, cache issues, bus speeds and all 458 other issues being unequal but largely irrelevant. 461 if(short_loop_cnt
==0) { 462 short_loop_cnt
= wait_usecs
* 463 (LOOPS_PER_TICK
/ (1000000/ HZ
)); 466 /* Spin for a short period of time, because >99% of all 467 requests to the WaveFront can be serviced inline like this. 470 for(i
=0; i
< short_loop_cnt
; i
++) { 471 if(wavefront_status() & mask
) { 476 for(i
=0; i
< sleep_tries
; i
++) { 478 if(wavefront_status() & mask
) { 482 if(wavefront_sleep(HZ
/sleep_interval
)) { 494 if(wavefront_wait(STAT_CAN_READ
)) 495 returninb(dev
.data_port
); 497 DPRINT(WF_DEBUG_DATA
,"read timeout.\n"); 503 wavefront_write(unsigned char data
) 506 if(wavefront_wait(STAT_CAN_WRITE
)) { 507 outb(data
, dev
.data_port
); 511 DPRINT(WF_DEBUG_DATA
,"write timeout.\n"); 517 wavefront_cmd(int cmd
,unsigned char*rbuf
,unsigned char*wbuf
) 523 wavefront_command
*wfcmd
; 525 if((wfcmd
=wavefront_get_command(cmd
)) == (wavefront_command
*)0) { 526 printk(KERN_WARNING LOGNAME
"command 0x%x not supported.\n", 531 /* Hack to handle the one variable-size write command. See 532 wavefront_send_multisample() for the other half of this 533 gross and ugly strategy. 536 if(cmd
== WFC_DOWNLOAD_MULTISAMPLE
) { 537 wfcmd
->write_cnt
= (unsigned int) rbuf
; 541 DPRINT(WF_DEBUG_CMD
,"0x%x [%s] (%d,%d,%d)\n", 542 cmd
, wfcmd
->action
, wfcmd
->read_cnt
, 543 wfcmd
->write_cnt
, wfcmd
->need_ack
); 545 if(wavefront_write(cmd
)) { 546 DPRINT((WF_DEBUG_IO
|WF_DEBUG_CMD
),"cannot request " 552 if(wfcmd
->write_cnt
>0) { 553 DPRINT(WF_DEBUG_DATA
,"writing %d bytes " 555 wfcmd
->write_cnt
, cmd
); 557 for(i
=0; i
< wfcmd
->write_cnt
; i
++) { 558 if(wavefront_write(wbuf
[i
])) { 559 DPRINT(WF_DEBUG_IO
,"bad write for byte " 560 "%d of 0x%x [%s].\n", 561 i
, cmd
, wfcmd
->action
); 565 DPRINT(WF_DEBUG_DATA
,"write[%d] = 0x%x\n", 570 if(wfcmd
->read_cnt
>0) { 571 DPRINT(WF_DEBUG_DATA
,"reading %d ints " 573 wfcmd
->read_cnt
, cmd
); 575 for(i
=0; i
< wfcmd
->read_cnt
; i
++) { 577 if((c
=wavefront_read()) == -1) { 578 DPRINT(WF_DEBUG_IO
,"bad read for byte " 579 "%d of 0x%x [%s].\n", 580 i
, cmd
, wfcmd
->action
); 584 /* Now handle errors. Lots of special cases here */ 587 if((c
=wavefront_read()) == -1) { 588 DPRINT(WF_DEBUG_IO
,"bad read for " 597 /* Can you believe this madness ? */ 600 wfcmd
->cmd
== WFC_IDENTIFY_SAMPLE_TYPE
) { 601 rbuf
[0] = WF_ST_EMPTY
; 605 wfcmd
->cmd
== WFC_UPLOAD_PATCH
) { 610 wfcmd
->cmd
== WFC_UPLOAD_PROGRAM
) { 616 DPRINT(WF_DEBUG_IO
,"error %d (%s) " 622 wavefront_errorstr(c
), 633 DPRINT(WF_DEBUG_DATA
,"read[%d] = 0x%x\n",i
, rbuf
[i
]); 637 if((wfcmd
->read_cnt
==0&& wfcmd
->write_cnt
==0) || wfcmd
->need_ack
) { 639 DPRINT(WF_DEBUG_CMD
,"reading ACK for 0x%x\n", cmd
); 641 /* Some commands need an ACK, but return zero instead 642 of the standard value. 645 if((ack
=wavefront_read()) ==0) { 651 DPRINT(WF_DEBUG_IO
,"cannot read ack for " 657 int err
= -1;/* something unknown */ 659 if(ack
==0xff) {/* explicit error */ 661 if((err
=wavefront_read()) == -1) { 662 DPRINT(WF_DEBUG_DATA
, 669 DPRINT(WF_DEBUG_IO
,"0x%x [%s] " 670 "failed (0x%x, 0x%x, %s)\n", 671 cmd
, wfcmd
->action
, ack
, err
, 672 wavefront_errorstr(err
)); 678 DPRINT(WF_DEBUG_DATA
,"ack received " 683 DPRINT(WF_DEBUG_CMD
,"0x%x [%s] does not need " 685 cmd
, wfcmd
->action
, wfcmd
->read_cnt
, 686 wfcmd
->write_cnt
, wfcmd
->need_ack
); 693 /*********************************************************************** 694 WaveFront: data munging 696 Things here are wierd. All data written to the board cannot 697 have its most significant bit set. Any data item with values 698 potentially > 0x7F (127) must be split across multiple bytes. 700 Sometimes, we need to munge numeric values that are represented on 701 the x86 side as 8-32 bit values. Sometimes, we need to munge data 702 that is represented on the x86 side as an array of bytes. The most 703 efficient approach to handling both cases seems to be to use 2 704 different functions for munging and 2 for de-munging. This avoids 705 wierd casting and worrying about bit-level offsets. 707 **********************************************************************/ 711 munge_int32(unsigned int src
, 713 unsigned int dst_size
) 717 for(i
=0;i
< dst_size
; i
++) { 718 *dst
= src
&0x7F;/* Mask high bit of LSB */ 719 src
= src
>>7;/* Rotate Right 7 bits */ 720 /* Note: we leave the upper bits in place */ 728 demunge_int32(unsigned char* src
,int src_size
) 734 for(i
= src_size
-1; i
>=0; i
--) { 735 outval
=(outval
<<7)+src
[i
]; 743 munge_buf(unsigned char*src
,unsigned char*dst
,unsigned int dst_size
) 747 unsigned int last
= dst_size
/2; 749 for(i
=0; i
< last
; i
++) { 750 *dst
++ = src
[i
] &0x7f; 758 demunge_buf(unsigned char*src
,unsigned char*dst
,unsigned int src_bytes
) 762 unsigned char*end
= src
+ src_bytes
; 764 end
= src
+ src_bytes
; 766 /* NOTE: src and dst *CAN* point to the same address */ 768 for(i
=0; src
!= end
; i
++) { 770 dst
[i
] |= (*src
++)<<7; 776 /*********************************************************************** 777 WaveFront: sample, patch and program management. 778 ***********************************************************************/ 781 wavefront_delete_sample(int sample_num
) 784 unsigned char wbuf
[2]; 787 wbuf
[0] = sample_num
&0x7f; 788 wbuf
[1] = sample_num
>>7; 790 if((x
=wavefront_cmd(WFC_DELETE_SAMPLE
,0, wbuf
)) ==0) { 791 dev
.sample_status
[sample_num
] = WF_ST_EMPTY
; 798 wavefront_get_sample_status(int assume_rom
) 802 unsigned char rbuf
[32], wbuf
[32]; 803 unsigned int sc_real
, sc_alias
, sc_multi
; 805 /* check sample status */ 807 if(wavefront_cmd(WFC_GET_NSAMPLES
, rbuf
, wbuf
)) { 808 printk(KERN_WARNING LOGNAME
"cannot request sample count.\n"); 812 sc_real
= sc_alias
= sc_multi
= dev
.samples_used
=0; 814 for(i
=0; i
< WF_MAX_SAMPLE
; i
++) { 819 if(wavefront_cmd(WFC_IDENTIFY_SAMPLE_TYPE
, rbuf
, wbuf
)) { 820 printk(KERN_WARNING LOGNAME
821 "cannot identify sample " 822 "type of slot %d\n", i
); 823 dev
.sample_status
[i
] = WF_ST_EMPTY
; 827 dev
.sample_status
[i
] = (WF_SLOT_FILLED
|rbuf
[0]); 830 dev
.sample_status
[i
] |= WF_SLOT_ROM
; 833 switch(rbuf
[0] & WF_ST_MASK
) { 837 case WF_ST_MULTISAMPLE
: 847 printk(KERN_WARNING LOGNAME
"unknown sample type for " 852 if(rbuf
[0] != WF_ST_EMPTY
) { 857 printk(KERN_INFO LOGNAME
858 "%d samples used (%d real, %d aliases, %d multi), " 859 "%d empty\n", dev
.samples_used
, sc_real
, sc_alias
, sc_multi
, 860 WF_MAX_SAMPLE
- dev
.samples_used
); 868 wavefront_get_patch_status(void) 871 unsigned char patchbuf
[WF_PATCH_BYTES
]; 872 unsigned char patchnum
[2]; 876 for(i
=0; i
< WF_MAX_PATCH
; i
++) { 877 patchnum
[0] = i
&0x7f; 880 if((x
=wavefront_cmd(WFC_UPLOAD_PATCH
, patchbuf
, 883 dev
.patch_status
[i
] |= WF_SLOT_FILLED
; 884 p
= (wavefront_patch
*) patchbuf
; 886 [p
->sample_number
|(p
->sample_msb
<<7)] |= 889 }else if(x
==3) {/* Bad patch number */ 890 dev
.patch_status
[i
] =0; 892 printk(KERN_ERR LOGNAME
"upload patch " 894 dev
.patch_status
[i
] =0; 899 /* program status has already filled in slot_used bits */ 901 for(i
=0, cnt
=0, cnt2
=0; i
< WF_MAX_PATCH
; i
++) { 902 if(dev
.patch_status
[i
] & WF_SLOT_FILLED
) { 905 if(dev
.patch_status
[i
] & WF_SLOT_USED
) { 910 printk(KERN_INFO LOGNAME
911 "%d patch slots filled, %d in use\n", cnt
, cnt2
); 917 wavefront_get_program_status(void) 920 unsigned char progbuf
[WF_PROGRAM_BYTES
]; 921 wavefront_program prog
; 922 unsigned char prognum
; 925 for(i
=0; i
< WF_MAX_PROGRAM
; i
++) { 928 if((x
=wavefront_cmd(WFC_UPLOAD_PROGRAM
, progbuf
, 931 dev
.prog_status
[i
] |= WF_SLOT_USED
; 933 demunge_buf(progbuf
, (unsigned char*) &prog
, 936 for(l
=0; l
< WF_NUM_LAYERS
; l
++) { 937 if(prog
.layer
[l
].mute
) { 939 [prog
.layer
[l
].patch_number
] |= 943 }else if(x
==1) {/* Bad program number */ 944 dev
.prog_status
[i
] =0; 946 printk(KERN_ERR LOGNAME
"upload program " 948 dev
.prog_status
[i
] =0; 952 for(i
=0, cnt
=0; i
< WF_MAX_PROGRAM
; i
++) { 953 if(dev
.prog_status
[i
]) { 958 printk(KERN_INFO LOGNAME
"%d programs slots in use\n", cnt
); 964 wavefront_send_patch(wavefront_patch_info
*header
) 967 unsigned char buf
[WF_PATCH_BYTES
+2]; 970 DPRINT(WF_DEBUG_LOAD_PATCH
,"downloading patch %d\n", 973 dev
.patch_status
[header
->number
] |= WF_SLOT_FILLED
; 976 bptr
=munge_int32(header
->number
, buf
,2); 977 munge_buf((unsigned char*)&header
->hdr
.p
, bptr
, WF_PATCH_BYTES
); 979 if(wavefront_cmd(WFC_DOWNLOAD_PATCH
,0, buf
)) { 980 printk(KERN_ERR LOGNAME
"download patch failed\n"); 988 wavefront_send_program(wavefront_patch_info
*header
) 991 unsigned char buf
[WF_PROGRAM_BYTES
+1]; 994 DPRINT(WF_DEBUG_LOAD_PATCH
,"downloading program %d\n", 997 dev
.prog_status
[header
->number
] = WF_SLOT_USED
; 999 /* XXX need to zero existing SLOT_USED bit for program_status[i] 1000 where `i' is the program that's being (potentially) overwritten. 1003 for(i
=0; i
< WF_NUM_LAYERS
; i
++) { 1004 if(header
->hdr
.pr
.layer
[i
].mute
) { 1005 dev
.patch_status
[header
->hdr
.pr
.layer
[i
].patch_number
] |= 1008 /* XXX need to mark SLOT_USED for sample used by 1009 patch_number, but this means we have to load it. Ick. 1014 buf
[0] = header
->number
; 1015 munge_buf((unsigned char*)&header
->hdr
.pr
, &buf
[1], WF_PROGRAM_BYTES
); 1017 if(wavefront_cmd(WFC_DOWNLOAD_PROGRAM
,0, buf
)) { 1018 printk(KERN_WARNING LOGNAME
"download patch failed\n"); 1026 wavefront_freemem(void) 1031 if(wavefront_cmd(WFC_REPORT_FREE_MEMORY
, rbuf
,0)) { 1032 printk(KERN_WARNING LOGNAME
"can't get memory stats.\n"); 1035 returndemunge_int32(rbuf
,4); 1040 wavefront_send_sample(wavefront_patch_info
*header
, 1042 int data_is_unsigned
) 1045 /* samples are downloaded via a 16-bit wide i/o port 1046 (you could think of it as 2 adjacent 8-bit wide ports 1047 but its less efficient that way). therefore, all 1048 the blocksizes and so forth listed in the documentation, 1049 and used conventionally to refer to sample sizes, 1050 which are given in 8-bit units (bytes), need to be 1054 UINT16 sample_short
; 1056 UINT16
*data_end
=0; 1058 const int max_blksize
=4096/2; 1059 unsigned int written
; 1060 unsigned int blocksize
; 1063 unsigned char sample_hdr
[WF_SAMPLE_HDR_BYTES
]; 1064 unsigned char*shptr
; 1066 int initial_skip
=0; 1068 DPRINT(WF_DEBUG_LOAD_PATCH
,"sample %sdownload for slot %d, " 1069 "type %d, %d bytes from 0x%x\n", 1070 header
->size
?"":"header ", 1071 header
->number
, header
->subkey
, 1073 (int) header
->dataptr
); 1075 if(header
->number
== WAVEFRONT_FIND_FREE_SAMPLE_SLOT
) { 1078 if((x
=wavefront_find_free_sample()) <0) { 1081 printk(KERN_DEBUG LOGNAME
"unspecified sample => %d\n", x
); 1087 /* XXX its a debatable point whether or not RDONLY semantics 1088 on the ROM samples should cover just the sample data or 1089 the sample header. For now, it only covers the sample data, 1090 so anyone is free at all times to rewrite sample headers. 1092 My reason for this is that we have the sample headers 1093 available in the WFB file for General MIDI, and so these 1094 can always be reset if needed. The sample data, however, 1095 cannot be recovered without a complete reset and firmware 1096 reload of the ICS2115, which is a very expensive operation. 1098 So, doing things this way allows us to honor the notion of 1099 "RESETSAMPLES" reasonably cheaply. Note however, that this 1100 is done purely at user level: there is no WFB parser in 1101 this driver, and so a complete reset (back to General MIDI, 1102 or theoretically some other configuration) is the 1103 responsibility of the user level library. 1105 To try to do this in the kernel would be a little 1106 crazy: we'd need 158K of kernel space just to hold 1107 a copy of the patch/program/sample header data. 1110 if(dev
.rom_samples_rdonly
) { 1111 if(dev
.sample_status
[header
->number
] & WF_SLOT_ROM
) { 1112 printk(KERN_ERR LOGNAME
"sample slot %d " 1113 "write protected\n", 1119 wavefront_delete_sample(header
->number
); 1123 dev
.freemem
=wavefront_freemem(); 1125 if(dev
.freemem
< header
->size
) { 1126 printk(KERN_ERR LOGNAME
1127 "insufficient memory to " 1128 "load %d byte sample.\n", 1135 skip
=WF_GET_CHANNEL(&header
->hdr
.s
); 1137 if(skip
>0&& header
->hdr
.s
.SampleResolution
!= LINEAR_16BIT
) { 1138 printk(KERN_ERR LOGNAME
"channel selection only " 1139 "possible on 16-bit samples"); 1174 DPRINT(WF_DEBUG_LOAD_PATCH
,"channel selection: %d => " 1175 "initial skip = %d, skip = %d\n", 1176 WF_GET_CHANNEL(&header
->hdr
.s
), 1177 initial_skip
, skip
); 1179 /* Be safe, and zero the "Unused" bits ... */ 1181 WF_SET_CHANNEL(&header
->hdr
.s
,0); 1183 /* adjust size for 16 bit samples by dividing by two. We always 1184 send 16 bits per write, even for 8 bit samples, so the length 1185 is always half the size of the sample data in bytes. 1188 length
= header
->size
/2; 1190 /* the data we're sent has not been munged, and in fact, the 1191 header we have to send isn't just a munged copy either. 1192 so, build the sample header right here. 1195 shptr
= &sample_hdr
[0]; 1197 shptr
=munge_int32(header
->number
, shptr
,2); 1200 shptr
=munge_int32(length
, shptr
,4); 1203 /* Yes, a 4 byte result doesn't contain all of the offset bits, 1204 but the offset only uses 24 bits. 1207 shptr
=munge_int32(*((UINT32
*) &header
->hdr
.s
.sampleStartOffset
), 1209 shptr
=munge_int32(*((UINT32
*) &header
->hdr
.s
.loopStartOffset
), 1211 shptr
=munge_int32(*((UINT32
*) &header
->hdr
.s
.loopEndOffset
), 1213 shptr
=munge_int32(*((UINT32
*) &header
->hdr
.s
.sampleEndOffset
), 1216 /* This one is truly wierd. What kind of wierdo decided that in 1217 a system dominated by 16 and 32 bit integers, they would use 1221 shptr
=munge_int32(header
->hdr
.s
.FrequencyBias
, shptr
,3); 1223 /* Why is this nybblified, when the MSB is *always* zero ? 1224 Anyway, we can't take address of bitfield, so make a 1225 good-faith guess at where it starts. 1228 shptr
=munge_int32(*(&header
->hdr
.s
.FrequencyBias
+1), 1231 if(wavefront_cmd(header
->size
? 1232 WFC_DOWNLOAD_SAMPLE
: WFC_DOWNLOAD_SAMPLE_HEADER
, 1234 printk(KERN_WARNING LOGNAME
"sample %sdownload refused.\n", 1235 header
->size
?"":"header "); 1239 if(header
->size
==0) { 1240 goto sent
;/* Sorry. Just had to have one somewhere */ 1243 data_end
= dataptr
+ length
; 1245 /* Do any initial skip over an unused channel's data */ 1247 dataptr
+= initial_skip
; 1249 for(written
=0, blocknum
=0; 1250 written
< length
; written
+= max_blksize
, blocknum
++) { 1252 if((length
- written
) > max_blksize
) { 1253 blocksize
= max_blksize
; 1255 /* round to nearest 16-byte value */ 1256 blocksize
= ((length
-written
+7)&~0x7); 1259 if(wavefront_cmd(WFC_DOWNLOAD_BLOCK
,0,0)) { 1260 printk(KERN_WARNING LOGNAME
"download block " 1261 "request refused.\n"); 1265 for(i
=0; i
< blocksize
; i
++) { 1267 if(dataptr
< data_end
) { 1269 __get_user(sample_short
, dataptr
); 1272 if(data_is_unsigned
) {/* GUS ? */ 1274 if(WF_SAMPLE_IS_8BIT(&header
->hdr
.s
)) { 1282 &sample_short
)[0] +=0x7f; 1284 &sample_short
)[1] +=0x7f; 1293 sample_short
+=0x7fff; 1299 /* In padding section of final block: 1301 Don't fetch unsupplied data from 1302 user space, just continue with 1303 whatever the final value was. 1307 if(i
< blocksize
-1) { 1308 outw(sample_short
, dev
.block_port
); 1310 outw(sample_short
, dev
.last_block_port
); 1314 /* Get "DMA page acknowledge", even though its really 1315 nothing to do with DMA at all. 1318 if((dma_ack
=wavefront_read()) != WF_DMA_ACK
) { 1320 printk(KERN_ERR LOGNAME
"upload sample " 1321 "DMA ack timeout\n"); 1324 printk(KERN_ERR LOGNAME
"upload sample " 1325 "DMA ack error 0x%x\n", 1332 dev
.sample_status
[header
->number
] = (WF_SLOT_FILLED
|WF_ST_SAMPLE
); 1334 /* Note, label is here because sending the sample header shouldn't 1335 alter the sample_status info at all. 1343 wavefront_send_alias(wavefront_patch_info
*header
) 1346 unsigned char alias_hdr
[WF_ALIAS_BYTES
]; 1348 DPRINT(WF_DEBUG_LOAD_PATCH
,"download alias, %d is " 1351 header
->hdr
.a
.OriginalSample
); 1353 munge_int32(header
->number
, &alias_hdr
[0],2); 1354 munge_int32(header
->hdr
.a
.OriginalSample
, &alias_hdr
[2],2); 1355 munge_int32(*((unsigned int*)&header
->hdr
.a
.sampleStartOffset
), 1357 munge_int32(*((unsigned int*)&header
->hdr
.a
.loopStartOffset
), 1359 munge_int32(*((unsigned int*)&header
->hdr
.a
.loopEndOffset
), 1361 munge_int32(*((unsigned int*)&header
->hdr
.a
.sampleEndOffset
), 1363 munge_int32(header
->hdr
.a
.FrequencyBias
, &alias_hdr
[20],3); 1364 munge_int32(*(&header
->hdr
.a
.FrequencyBias
+1), &alias_hdr
[23],2); 1366 if(wavefront_cmd(WFC_DOWNLOAD_SAMPLE_ALIAS
,0, alias_hdr
)) { 1367 printk(KERN_ERR LOGNAME
"download alias failed.\n"); 1371 dev
.sample_status
[header
->number
] = (WF_SLOT_FILLED
|WF_ST_ALIAS
); 1377 wavefront_send_multisample(wavefront_patch_info
*header
) 1381 unsigned char msample_hdr
[WF_MSAMPLE_BYTES
]; 1383 munge_int32(header
->number
, &msample_hdr
[0],2); 1385 /* You'll recall at this point that the "number of samples" value 1386 in a wavefront_multisample struct is actually the log2 of the 1387 real number of samples. 1390 num_samples
= (1<<(header
->hdr
.ms
.NumberOfSamples
&7)); 1391 msample_hdr
[2] = (unsigned char) header
->hdr
.ms
.NumberOfSamples
; 1393 DPRINT(WF_DEBUG_LOAD_PATCH
,"multi %d with %d=%d samples\n", 1395 header
->hdr
.ms
.NumberOfSamples
, 1398 for(i
=0; i
< num_samples
; i
++) { 1399 DPRINT(WF_DEBUG_LOAD_PATCH
|WF_DEBUG_DATA
,"sample[%d] = %d\n", 1400 i
, header
->hdr
.ms
.SampleNumber
[i
]); 1401 munge_int32(header
->hdr
.ms
.SampleNumber
[i
], 1402 &msample_hdr
[3+(i
*2)],2); 1405 /* Need a hack here to pass in the number of bytes 1406 to be written to the synth. This is ugly, and perhaps 1407 one day, I'll fix it. 1410 if(wavefront_cmd(WFC_DOWNLOAD_MULTISAMPLE
, 1411 (unsigned char*) ((num_samples
*2)+3), 1413 printk(KERN_ERR LOGNAME
"download of multisample failed.\n"); 1417 dev
.sample_status
[header
->number
] = (WF_SLOT_FILLED
|WF_ST_MULTISAMPLE
); 1423 wavefront_fetch_multisample(wavefront_patch_info
*header
) 1426 unsigned char log_ns
[1]; 1427 unsigned char number
[2]; 1430 munge_int32(header
->number
, number
,2); 1432 if(wavefront_cmd(WFC_UPLOAD_MULTISAMPLE
, log_ns
, number
)) { 1433 printk(KERN_ERR LOGNAME
"upload multisample failed.\n"); 1437 DPRINT(WF_DEBUG_DATA
,"msample %d has %d samples\n", 1438 header
->number
, log_ns
[0]); 1440 header
->hdr
.ms
.NumberOfSamples
= log_ns
[0]; 1442 /* get the number of samples ... */ 1444 num_samples
= (1<< log_ns
[0]); 1446 for(i
=0; i
< num_samples
; i
++) { 1449 if((d
[0] =wavefront_read()) == -1) { 1450 printk(KERN_ERR LOGNAME
"upload multisample failed " 1451 "during sample loop.\n"); 1455 if((d
[1] =wavefront_read()) == -1) { 1456 printk(KERN_ERR LOGNAME
"upload multisample failed " 1457 "during sample loop.\n"); 1461 header
->hdr
.ms
.SampleNumber
[i
] = 1462 demunge_int32((unsigned char*) d
,2); 1464 DPRINT(WF_DEBUG_DATA
,"msample sample[%d] = %d\n", 1465 i
, header
->hdr
.ms
.SampleNumber
[i
]); 1473 wavefront_send_drum(wavefront_patch_info
*header
) 1476 unsigned char drumbuf
[WF_DRUM_BYTES
]; 1477 wavefront_drum
*drum
= &header
->hdr
.d
; 1480 DPRINT(WF_DEBUG_LOAD_PATCH
,"downloading edrum for MIDI " 1481 "note %d, patch = %d\n", 1482 header
->number
, drum
->PatchNumber
); 1484 drumbuf
[0] = header
->number
&0x7f; 1486 for(i
=0; i
<4; i
++) { 1487 munge_int32(((unsigned char*)drum
)[i
], &drumbuf
[1+(i
*2)],2); 1490 if(wavefront_cmd(WFC_DOWNLOAD_EDRUM_PROGRAM
,0, drumbuf
)) { 1491 printk(KERN_ERR LOGNAME
"download drum failed.\n"); 1499 wavefront_find_free_sample(void) 1504 for(i
=0; i
< WF_MAX_SAMPLE
; i
++) { 1505 if(!(dev
.sample_status
[i
] & WF_SLOT_FILLED
)) { 1509 printk(KERN_WARNING LOGNAME
"no free sample slots!\n"); 1514 wavefront_find_free_patch(void) 1519 for(i
=0; i
< WF_MAX_PATCH
; i
++) { 1520 if(!(dev
.patch_status
[i
] & WF_SLOT_FILLED
)) { 1524 printk(KERN_WARNING LOGNAME
"no free patch slots!\n"); 1532 int tbl
[]={0,0,2048,3246,4096,4755,5294,5749,6143, 1533 6492,6803,7084,7342,7578,7797,8001,8192, 1534 8371,8540,8699,8851,8995,9132,9264,9390, 1535 9510,9626,9738,9845,9949,10049,10146}; 1538 /* Returns 2048*log2(n) */ 1540 /* FIXME: this is like doing integer math 1541 on quantum particles (RuN) */ 1557 wavefront_load_gus_patch(int devno
,int format
,const char*addr
, 1558 int offs
,int count
,int pmgr_flag
) 1560 struct patch_info guspatch
; 1561 wavefront_patch_info samp
, pat
, prog
; 1562 wavefront_patch
*patp
; 1563 wavefront_sample
*sampp
; 1564 wavefront_program
*progp
; 1569 /* Copy in the header of the GUS patch */ 1571 sizeof_patch
= (long) &guspatch
.data
[0] - (long) &guspatch
; 1572 copy_from_user(&((char*) &guspatch
)[offs
], 1573 &(addr
)[offs
], sizeof_patch
- offs
); 1575 if((i
=wavefront_find_free_patch()) == -1) { 1579 pat
.subkey
= WF_ST_PATCH
; 1582 if((i
=wavefront_find_free_sample()) == -1) { 1586 samp
.subkey
= WF_ST_SAMPLE
; 1587 samp
.size
= guspatch
.len
; 1588 sampp
= &samp
.hdr
.s
; 1590 prog
.number
= guspatch
.instr_no
; 1591 progp
= &prog
.hdr
.pr
; 1593 /* Setup the patch structure */ 1595 patp
->amplitude_bias
=guspatch
.volume
; 1597 patp
->sample_number
= samp
.number
&0xff; 1598 patp
->sample_msb
= samp
.number
>>8; 1599 patp
->pitch_bend
=/*12*/0; 1602 patp
->nohold
=(guspatch
.mode
& WAVE_SUSTAIN_ON
) ?0:1; 1603 patp
->frequency_bias
=0; 1608 patp
->fm_src1
=WF_MOD_MOD_WHEEL
; 1609 patp
->am_src
=WF_MOD_PRESSURE
; 1610 patp
->am_amount
=127; 1611 patp
->fc1_mod_amount
=0; 1612 patp
->fc2_mod_amount
=0; 1615 patp
->envelope1
.attack_level
=127; 1616 patp
->envelope1
.decay1_level
=127; 1617 patp
->envelope1
.decay2_level
=127; 1618 patp
->envelope1
.sustain_level
=127; 1619 patp
->envelope1
.release_level
=0; 1620 patp
->envelope2
.attack_velocity
=127; 1621 patp
->envelope2
.attack_level
=127; 1622 patp
->envelope2
.decay1_level
=127; 1623 patp
->envelope2
.decay2_level
=127; 1624 patp
->envelope2
.sustain_level
=127; 1625 patp
->envelope2
.release_level
=0; 1626 patp
->envelope2
.attack_velocity
=127; 1629 /* Program for this patch */ 1631 progp
->layer
[0].patch_number
= pat
.number
;/* XXX is this right ? */ 1632 progp
->layer
[0].mute
=1; 1633 progp
->layer
[0].pan_or_mod
=1; 1634 progp
->layer
[0].pan
=7; 1635 progp
->layer
[0].mix_level
=127/* guspatch.volume */; 1636 progp
->layer
[0].split_type
=0; 1637 progp
->layer
[0].split_point
=0; 1638 progp
->layer
[0].play_below
=0; 1640 for(i
=1; i
<4; i
++) { 1641 progp
->layer
[i
].mute
=0; 1646 sampp
->SampleResolution
=((~guspatch
.mode
& WAVE_16_BITS
)<<1); 1649 note_to_freq(base_note
) < guspatch
.base_note
; 1652 if((guspatch
.base_note
-note_to_freq(base_note
)) 1653 >(note_to_freq(base_note
)-guspatch
.base_note
)) 1656 printk(KERN_DEBUG
"ref freq=%d,base note=%d\n", 1660 sampp
->FrequencyBias
= (29550-log2_2048(guspatch
.base_freq
) 1662 printk(KERN_DEBUG
"Freq Bias is %d\n", sampp
->FrequencyBias
); 1663 sampp
->Loop
=(guspatch
.mode
& WAVE_LOOPING
) ?1:0; 1664 sampp
->sampleStartOffset
.Fraction
=0; 1665 sampp
->sampleStartOffset
.Integer
=0; 1666 sampp
->loopStartOffset
.Fraction
=0; 1667 sampp
->loopStartOffset
.Integer
=guspatch
.loop_start
1668 >>((guspatch
.mode
&WAVE_16_BITS
) ?1:0); 1669 sampp
->loopEndOffset
.Fraction
=0; 1670 sampp
->loopEndOffset
.Integer
=guspatch
.loop_end
1671 >>((guspatch
.mode
&WAVE_16_BITS
) ?1:0); 1672 sampp
->sampleEndOffset
.Fraction
=0; 1673 sampp
->sampleEndOffset
.Integer
=guspatch
.len
>> (guspatch
.mode
&1); 1674 sampp
->Bidirectional
=(guspatch
.mode
&WAVE_BIDIR_LOOP
) ?1:0; 1675 sampp
->Reverse
=(guspatch
.mode
&WAVE_LOOP_BACK
) ?1:0; 1677 /* Now ship it down */ 1679 wavefront_send_sample(&samp
, 1680 (unsigned short*) &(addr
)[sizeof_patch
], 1681 (guspatch
.mode
& WAVE_UNSIGNED
) ?1:0); 1682 wavefront_send_patch(&pat
); 1683 wavefront_send_program(&prog
); 1685 /* Now pan as best we can ... use the slave/internal MIDI device 1686 number if it exists (since it talks to the WaveFront), or the 1690 if(dev
.mididev
>0) { 1691 midi_synth_controller(dev
.mididev
, guspatch
.instr_no
,10, 1692 ((guspatch
.panning
<<4) >127) ? 1693 127: (guspatch
.panning
<<4)); 1700 wavefront_load_patch(const char*addr
) 1704 wavefront_patch_info header
; 1706 if(copy_from_user(&header
, addr
,sizeof(wavefront_patch_info
) - 1707 sizeof(wavefront_any
))) { 1708 printk(KERN_WARNING LOGNAME
"bad address for load patch.\n"); 1712 DPRINT(WF_DEBUG_LOAD_PATCH
,"download " 1714 "Sample number: %d " 1715 "Sample size: %d\n", 1720 switch(header
.subkey
) { 1721 case WF_ST_SAMPLE
:/* sample or sample_header, based on patch->size */ 1723 copy_from_user((unsigned char*) &header
.hdr
.s
, 1724 (unsigned char*) header
.hdrptr
, 1725 sizeof(wavefront_sample
)); 1727 returnwavefront_send_sample(&header
, header
.dataptr
,0); 1729 case WF_ST_MULTISAMPLE
: 1731 copy_from_user((unsigned char*) &header
.hdr
.s
, 1732 (unsigned char*) header
.hdrptr
, 1733 sizeof(wavefront_multisample
)); 1735 returnwavefront_send_multisample(&header
); 1740 copy_from_user((unsigned char*) &header
.hdr
.a
, 1741 (unsigned char*) header
.hdrptr
, 1742 sizeof(wavefront_alias
)); 1744 returnwavefront_send_alias(&header
); 1747 copy_from_user((unsigned char*) &header
.hdr
.d
, 1748 (unsigned char*) header
.hdrptr
, 1749 sizeof(wavefront_drum
)); 1751 returnwavefront_send_drum(&header
); 1754 copy_from_user((unsigned char*) &header
.hdr
.p
, 1755 (unsigned char*) header
.hdrptr
, 1756 sizeof(wavefront_patch
)); 1758 returnwavefront_send_patch(&header
); 1761 copy_from_user((unsigned char*) &header
.hdr
.pr
, 1762 (unsigned char*) header
.hdrptr
, 1763 sizeof(wavefront_program
)); 1765 returnwavefront_send_program(&header
); 1768 printk(KERN_ERR LOGNAME
"unknown patch type %d.\n", 1776 /*********************************************************************** 1777 WaveFront: /dev/sequencer{,2} and other hardware-dependent interfaces 1778 ***********************************************************************/ 1781 process_sample_hdr(UCHAR8
*buf
) 1789 /* The board doesn't send us an exact copy of a "wavefront_sample" 1790 in response to an Upload Sample Header command. Instead, we 1791 have to convert the data format back into our data structure, 1792 just as in the Download Sample command, where we have to do 1793 something very similar in the reverse direction. 1796 *((UINT32
*) &s
.sampleStartOffset
) =demunge_int32(ptr
,4); ptr
+=4; 1797 *((UINT32
*) &s
.loopStartOffset
) =demunge_int32(ptr
,4); ptr
+=4; 1798 *((UINT32
*) &s
.loopEndOffset
) =demunge_int32(ptr
,4); ptr
+=4; 1799 *((UINT32
*) &s
.sampleEndOffset
) =demunge_int32(ptr
,4); ptr
+=4; 1800 *((UINT32
*) &s
.FrequencyBias
) =demunge_int32(ptr
,3); ptr
+=3; 1802 s
.SampleResolution
= *ptr
&0x3; 1804 s
.Bidirectional
= *ptr
&0x10; 1805 s
.Reverse
= *ptr
&0x40; 1807 /* Now copy it back to where it came from */ 1809 memcpy(buf
, (unsigned char*) &s
,sizeof(wavefront_sample
)); 1813 wavefront_synth_control(int cmd
, wavefront_control
*wc
) 1816 unsigned char patchnumbuf
[2]; 1819 DPRINT(WF_DEBUG_CMD
,"synth control with " 1820 "cmd 0x%x\n", wc
->cmd
); 1822 /* Pre-handling of or for various commands */ 1825 case WFC_DISABLE_INTERRUPTS
: 1826 printk(KERN_INFO LOGNAME
"interrupts disabled.\n"); 1827 outb(0x80|0x20, dev
.control_port
); 1828 dev
.interrupts_on
=0; 1831 case WFC_ENABLE_INTERRUPTS
: 1832 printk(KERN_INFO LOGNAME
"interrupts enabled.\n"); 1833 outb(0x80|0x40|0x20, dev
.control_port
); 1834 dev
.interrupts_on
=1; 1837 case WFC_INTERRUPT_STATUS
: 1838 wc
->rbuf
[0] = dev
.interrupts_on
; 1841 case WFC_ROMSAMPLES_RDONLY
: 1842 dev
.rom_samples_rdonly
= wc
->wbuf
[0]; 1846 case WFC_IDENTIFY_SLOT_TYPE
: 1847 i
= wc
->wbuf
[0] | (wc
->wbuf
[1] <<7); 1848 if(i
<0|| i
>= WF_MAX_SAMPLE
) { 1849 printk(KERN_WARNING LOGNAME
"invalid slot ID %d\n", 1851 wc
->status
= EINVAL
; 1854 wc
->rbuf
[0] = dev
.sample_status
[i
]; 1858 case WFC_DEBUG_DRIVER
: 1859 dev
.debug
= wc
->wbuf
[0]; 1860 printk(KERN_INFO LOGNAME
"debug = 0x%x\n", dev
.debug
); 1864 wffx_ioctl((wavefront_fx_info
*) &wc
->wbuf
[0]); 1867 case WFC_UPLOAD_PATCH
: 1868 munge_int32(*((UINT32
*) wc
->wbuf
), patchnumbuf
,2); 1869 memcpy(wc
->wbuf
, patchnumbuf
,2); 1872 case WFC_UPLOAD_MULTISAMPLE
: 1873 /* multisamples have to be handled differently, and 1874 cannot be dealt with properly by wavefront_cmd() alone. 1876 wc
->status
= wavefront_fetch_multisample
1877 ((wavefront_patch_info
*) wc
->rbuf
); 1880 case WFC_UPLOAD_SAMPLE_ALIAS
: 1881 printk(KERN_INFO LOGNAME
"support for sample alias upload " 1882 "being considered.\n"); 1883 wc
->status
= EINVAL
; 1887 wc
->status
=wavefront_cmd(wc
->cmd
, wc
->rbuf
, wc
->wbuf
); 1889 /* Post-handling of certain commands. 1891 In particular, if the command was an upload, demunge the data 1892 so that the user-level doesn't have to think about it. 1895 if(wc
->status
==0) { 1897 /* intercept any freemem requests so that we know 1898 we are always current with the user-level view 1902 case WFC_REPORT_FREE_MEMORY
: 1903 dev
.freemem
=demunge_int32(wc
->rbuf
,4); 1906 case WFC_UPLOAD_PATCH
: 1907 demunge_buf(wc
->rbuf
, wc
->rbuf
, WF_PATCH_BYTES
); 1910 case WFC_UPLOAD_PROGRAM
: 1911 demunge_buf(wc
->rbuf
, wc
->rbuf
, WF_PROGRAM_BYTES
); 1914 case WFC_UPLOAD_EDRUM_PROGRAM
: 1915 demunge_buf(wc
->rbuf
, wc
->rbuf
, WF_DRUM_BYTES
-1); 1918 case WFC_UPLOAD_SAMPLE_HEADER
: 1919 process_sample_hdr(wc
->rbuf
); 1922 case WFC_UPLOAD_SAMPLE_ALIAS
: 1923 printk(KERN_INFO LOGNAME
"support for " 1924 "sample aliases still " 1925 "being considered.\n"); 1929 if(virtual_midi_disable() <0) { 1935 if(virtual_midi_enable() <0) { 1946 /***********************************************************************/ 1947 /* WaveFront: Linux file system interface (for access via raw synth) */ 1948 /***********************************************************************/ 1951 wavefront_llseek(struct file
*file
, loff_t offset
,int origin
) 1957 wavefront_open(struct inode
*inode
,struct file
*file
) 1960 dev
.opened
= file
->f_flags
; 1965 wavefront_release(struct inode
*inode
,struct file
*file
) 1975 wavefront_ioctl(struct inode
*inode
,struct file
*file
, 1976 unsigned int cmd
,unsigned long arg
) 1978 wavefront_control wc
; 1984 copy_from_user(&wc
, (void*) arg
,sizeof(wc
)); 1986 if((err
=wavefront_synth_control(cmd
, &wc
)) ==0) { 1987 copy_to_user((void*) arg
, &wc
,sizeof(wc
)); 1992 case WFCTL_LOAD_SPP
: 1993 returnwavefront_load_patch((const char*) arg
); 1996 printk(KERN_WARNING LOGNAME
"invalid ioctl %#x\n", cmd
); 2003 static/*const*/struct file_operations wavefront_fops
= { 2005 llseek
: wavefront_llseek
, 2006 ioctl
: wavefront_ioctl
, 2007 open
: wavefront_open
, 2008 release
: wavefront_release
, 2012 /***********************************************************************/ 2013 /* WaveFront: OSS installation and support interface */ 2014 /***********************************************************************/ 2016 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ 2018 static struct synth_info wavefront_info
= 2019 {"Turtle Beach WaveFront",0, SYNTH_TYPE_SAMPLE
, SAMPLE_TYPE_WAVEFRONT
, 2020 0,32,0,0, SYNTH_CAP_INPUT
}; 2023 wavefront_oss_open(int devno
,int mode
) 2031 wavefront_oss_close(int devno
) 2040 wavefront_oss_ioctl(int devno
,unsigned int cmd
, caddr_t arg
) 2043 wavefront_control wc
; 2047 case SNDCTL_SYNTH_INFO
: 2048 memcpy(&((char*) arg
)[0], &wavefront_info
, 2049 sizeof(wavefront_info
)); 2053 case SNDCTL_SEQ_RESETSAMPLES
: 2054 printk(KERN_WARNING LOGNAME
"driver cannot reset samples.\n"); 2055 return0;/* don't force an error */ 2058 case SNDCTL_SEQ_PERCMODE
: 2059 return0;/* don't force an error */ 2062 case SNDCTL_SYNTH_MEMAVL
: 2063 if((dev
.freemem
=wavefront_freemem()) <0) { 2064 printk(KERN_ERR LOGNAME
"cannot get memory size\n"); 2071 case SNDCTL_SYNTH_CONTROL
: 2072 copy_from_user(&wc
, arg
,sizeof(wc
)); 2074 if((err
=wavefront_synth_control(cmd
, &wc
)) ==0) { 2075 copy_to_user(arg
, &wc
,sizeof(wc
)); 2086 wavefront_oss_load_patch(int devno
,int format
,const char*addr
, 2087 int offs
,int count
,int pmgr_flag
) 2090 if(format
== SYSEX_PATCH
) {/* Handled by midi_synth.c */ 2091 if(midi_load_patch
== NULL
) { 2092 printk(KERN_ERR LOGNAME
2093 "SYSEX not loadable: " 2094 "no midi patch loader!\n"); 2098 returnmidi_load_patch(devno
, format
, addr
, 2099 offs
, count
, pmgr_flag
); 2101 }else if(format
== GUS_PATCH
) { 2102 returnwavefront_load_gus_patch(devno
, format
, 2103 addr
, offs
, count
, pmgr_flag
); 2105 }else if(format
!= WAVEFRONT_PATCH
) { 2106 printk(KERN_ERR LOGNAME
"unknown patch format %d\n", format
); 2110 if(count
<sizeof(wavefront_patch_info
)) { 2111 printk(KERN_ERR LOGNAME
"sample header too short\n"); 2115 /* "addr" points to a user-space wavefront_patch_info */ 2117 returnwavefront_load_patch(addr
); 2120 static struct synth_operations wavefront_operations
= 2124 info
: &wavefront_info
, 2126 synth_type
: SYNTH_TYPE_SAMPLE
, 2127 synth_subtype
: SAMPLE_TYPE_WAVEFRONT
, 2128 open
: wavefront_oss_open
, 2129 close
: wavefront_oss_close
, 2130 ioctl
: wavefront_oss_ioctl
, 2131 kill_note
: midi_synth_kill_note
, 2132 start_note
: midi_synth_start_note
, 2133 set_instr
: midi_synth_set_instr
, 2134 reset
: midi_synth_reset
, 2135 load_patch
: midi_synth_load_patch
, 2136 aftertouch
: midi_synth_aftertouch
, 2137 controller
: midi_synth_controller
, 2138 panning
: midi_synth_panning
, 2139 bender
: midi_synth_bender
, 2140 setup_voice
: midi_synth_setup_voice
2142 #endif OSS_SUPPORT_SEQ 2144 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_STATIC_INSTALL 2146 static void __init
attach_wavefront(struct address_info
*hw_config
) 2148 (void)install_wavefront(); 2151 static int __init
probe_wavefront(struct address_info
*hw_config
) 2153 return!detect_wavefront(hw_config
->irq
, hw_config
->io_base
); 2156 static void __exit
unload_wavefront(struct address_info
*hw_config
) 2158 (void)uninstall_wavefront(); 2161 #endif OSS_SUPPORT_STATIC_INSTALL 2163 /***********************************************************************/ 2164 /* WaveFront: Linux modular sound kernel installation interface */ 2165 /***********************************************************************/ 2168 wavefrontintr(int irq
,void*dev_id
,struct pt_regs
*dummy
) 2170 struct wf_config
*hw
= dev_id
; 2173 Some comments on interrupts. I attempted a version of this 2174 driver that used interrupts throughout the code instead of 2175 doing busy and/or sleep-waiting. Alas, it appears that once 2176 the Motorola firmware is downloaded, the card *never* 2177 generates an RX interrupt. These are successfully generated 2178 during firmware loading, and after that wavefront_status() 2179 reports that an interrupt is pending on the card from time 2180 to time, but it never seems to be delivered to this 2181 driver. Note also that wavefront_status() continues to 2182 report that RX interrupts are enabled, suggesting that I 2183 didn't goof up and disable them by mistake. 2185 Thus, I stepped back to a prior version of 2186 wavefront_wait(), the only place where this really 2187 matters. Its sad, but I've looked through the code to check 2188 on things, and I really feel certain that the Motorola 2189 firmware prevents RX-ready interrupts. 2192 if((wavefront_status() & (STAT_INTR_READ
|STAT_INTR_WRITE
)) ==0) { 2198 wake_up_interruptible(&hw
->interrupt_sleeper
); 2203 0 Host Rx Interrupt Enable (1=Enabled) 2204 1 Host Rx Register Full (1=Full) 2205 2 Host Rx Interrupt Pending (1=Interrupt) 2207 4 Host Tx Interrupt (1=Enabled) 2208 5 Host Tx Register empty (1=Empty) 2209 6 Host Tx Interrupt Pending (1=Interrupt) 2214 wavefront_interrupt_bits(int irq
) 2234 printk(KERN_WARNING LOGNAME
"invalid IRQ %d\n", irq
); 2242 wavefront_should_cause_interrupt(int val
,int port
,int timeout
) 2245 unsigned long flags
; 2251 interruptible_sleep_on_timeout(&dev
.interrupt_sleeper
, timeout
); 2252 restore_flags(flags
); 2255 static int __init
wavefront_hw_reset(void) 2259 unsigned long irq_mask
; 2262 /* IRQ already checked in init_module() */ 2264 bits
=wavefront_interrupt_bits(dev
.irq
); 2266 printk(KERN_DEBUG LOGNAME
"autodetecting WaveFront IRQ\n"); 2270 irq_mask
=probe_irq_on(); 2272 outb(0x0, dev
.control_port
); 2273 outb(0x80|0x40| bits
, dev
.data_port
); 2274 wavefront_should_cause_interrupt(0x80|0x40|0x10|0x1, 2276 (reset_time
*HZ
)/100); 2278 reported_irq
=probe_irq_off(irq_mask
); 2280 if(reported_irq
!= dev
.irq
) { 2281 if(reported_irq
==0) { 2282 printk(KERN_ERR LOGNAME
2283 "No unassigned interrupts detected " 2284 "after h/w reset\n"); 2285 }else if(reported_irq
<0) { 2286 printk(KERN_ERR LOGNAME
2287 "Multiple unassigned interrupts detected " 2288 "after h/w reset\n"); 2290 printk(KERN_ERR LOGNAME
"autodetected IRQ %d not the " 2291 "value provided (%d)\n", reported_irq
, 2297 printk(KERN_INFO LOGNAME
"autodetected IRQ at %d\n", 2301 if(request_irq(dev
.irq
, wavefrontintr
, 2302 SA_INTERRUPT
|SA_SHIRQ
, 2303 "wavefront synth", &dev
) <0) { 2304 printk(KERN_WARNING LOGNAME
"IRQ %d not available!\n", 2309 /* try reset of port */ 2311 outb(0x0, dev
.control_port
); 2313 /* At this point, the board is in reset, and the H/W initialization 2314 register is accessed at the same address as the data port. 2316 Bit 7 - Enable IRQ Driver 2317 0 - Tri-state the Wave-Board drivers for the PC Bus IRQs 2318 1 - Enable IRQ selected by bits 5:3 to be driven onto the PC Bus. 2320 Bit 6 - MIDI Interface Select 2322 0 - Use the MIDI Input from the 26-pin WaveBlaster 2323 compatible header as the serial MIDI source 2324 1 - Use the MIDI Input from the 9-pin D connector as the 2327 Bits 5:3 - IRQ Selection 2338 Bit 0 - Disable Boot ROM 2339 0 - memory accesses to 03FC30-03FFFFH utilize the internal Boot ROM 2340 1 - memory accesses to 03FC30-03FFFFH are directed to external 2345 /* configure hardware: IRQ, enable interrupts, 2346 plus external 9-pin MIDI interface selected 2349 outb(0x80|0x40| bits
, dev
.data_port
); 2353 0 Host Rx Interrupt Enable (1=Enabled) 0x1 2357 4 Host Tx Interrupt Enable 0x10 2358 5 Mute (0=Mute; 1=Play) 0x20 2359 6 Master Interrupt Enable (1=Enabled) 0x40 2360 7 Master Reset (0=Reset; 1=Run) 0x80 2362 Take us out of reset, mute output, master + TX + RX interrupts on. 2364 We'll get an interrupt presumably to tell us that the TX 2368 wavefront_should_cause_interrupt(0x80|0x40|0x10|0x1, 2370 (reset_time
*HZ
)/100); 2372 /* Note: data port is now the data port, not the h/w initialization 2377 printk(KERN_WARNING LOGNAME
2378 "intr not received after h/w un-reset.\n"); 2382 dev
.interrupts_on
=1; 2384 /* Note: data port is now the data port, not the h/w initialization 2387 At this point, only "HW VERSION" or "DOWNLOAD OS" commands 2388 will work. So, issue one of them, and wait for TX 2389 interrupt. This can take a *long* time after a cold boot, 2390 while the ISC ROM does its RAM test. The SDK says up to 4 2391 seconds - with 12MB of RAM on a Tropez+, it takes a lot 2392 longer than that (~16secs). Note that the card understands 2393 the difference between a warm and a cold boot, so 2394 subsequent ISC2115 reboots (say, caused by module 2395 reloading) will get through this much faster. 2397 XXX Interesting question: why is no RX interrupt received first ? 2400 wavefront_should_cause_interrupt(WFC_HARDWARE_VERSION
, 2401 dev
.data_port
, ramcheck_time
*HZ
); 2404 printk(KERN_WARNING LOGNAME
2405 "post-RAM-check interrupt not received.\n"); 2409 if(!wavefront_wait(STAT_CAN_READ
)) { 2410 printk(KERN_WARNING LOGNAME
2411 "no response to HW version cmd.\n"); 2415 if((hwv
[0] =wavefront_read()) == -1) { 2416 printk(KERN_WARNING LOGNAME
2417 "board not responding correctly.\n"); 2421 if(hwv
[0] ==0xFF) {/* NAK */ 2423 /* Board's RAM test failed. Try to read error code, 2424 and tell us about it either way. 2427 if((hwv
[0] =wavefront_read()) == -1) { 2428 printk(KERN_WARNING LOGNAME
"on-board RAM test failed " 2429 "(bad error code).\n"); 2431 printk(KERN_WARNING LOGNAME
"on-board RAM test failed " 2432 "(error code: 0x%x).\n", 2438 /* We're OK, just get the next byte of the HW version response */ 2440 if((hwv
[1] =wavefront_read()) == -1) { 2441 printk(KERN_WARNING LOGNAME
"incorrect h/w response.\n"); 2445 printk(KERN_INFO LOGNAME
"hardware version %d.%d\n", 2453 free_irq(dev
.irq
, &dev
); 2459 static int __init
detect_wavefront(int irq
,int io_base
) 2461 unsigned char rbuf
[4], wbuf
[4]; 2463 /* TB docs say the device takes up 8 ports, but we know that 2464 if there is an FX device present (i.e. a Tropez+) it really 2468 if(check_region(io_base
,16)) { 2469 printk(KERN_ERR LOGNAME
"IO address range 0x%x - 0x%x " 2470 "already in use - ignored\n", dev
.base
, 2478 dev
.debug
= debug_default
; 2479 dev
.interrupts_on
=0; 2481 dev
.rom_samples_rdonly
=1;/* XXX default lock on ROM sample slots */ 2483 if(wavefront_cmd(WFC_FIRMWARE_VERSION
, rbuf
, wbuf
) ==0) { 2485 dev
.fw_version
[0] = rbuf
[0]; 2486 dev
.fw_version
[1] = rbuf
[1]; 2487 printk(KERN_INFO LOGNAME
2488 "firmware %d.%d already loaded.\n", 2491 /* check that a command actually works */ 2493 if(wavefront_cmd(WFC_HARDWARE_VERSION
, 2495 dev
.hw_version
[0] = rbuf
[0]; 2496 dev
.hw_version
[1] = rbuf
[1]; 2498 printk(KERN_WARNING LOGNAME
"not raw, but no " 2499 "hardware version!\n"); 2506 printk(KERN_INFO LOGNAME
2507 "reloading firmware anyway.\n"); 2514 printk(KERN_INFO LOGNAME
2515 "no response to firmware probe, assume raw.\n"); 2519 init_waitqueue_head(&dev
.interrupt_sleeper
); 2521 if(wavefront_hw_reset()) { 2522 printk(KERN_WARNING LOGNAME
"hardware reset failed\n"); 2526 /* Check for FX device, present only on Tropez+ */ 2528 dev
.has_fx
= (detect_wffx() ==0); 2534 #define __KERNEL_SYSCALLS__ 2535 #include <linux/fs.h> 2536 #include <linux/mm.h> 2537 #include <linux/malloc.h> 2538 #include <linux/unistd.h> 2539 #include <asm/uaccess.h> 2544 wavefront_download_firmware(char*path
) 2547 unsigned char section
[WF_SECTION_MAX
]; 2548 char section_length
;/* yes, just a char; max value is WF_SECTION_MAX */ 2549 int section_cnt_downloaded
=0; 2555 /* This tries to be a bit cleverer than the stuff Alan Cox did for 2556 the generic sound firmware, in that it actually knows 2557 something about the structure of the Motorola firmware. In 2558 particular, it uses a version that has been stripped of the 2559 20K of useless header information, and had section lengths 2560 added, making it possible to load the entire OS without any 2561 [kv]malloc() activity, since the longest entity we ever read is 2562 42 bytes (well, WF_SECTION_MAX) long. 2568 if((fd
=open(path
,0,0)) <0) { 2569 printk(KERN_WARNING LOGNAME
"Unable to load\"%s\".\n", 2577 if((x
=read(fd
, §ion_length
,sizeof(section_length
))) != 2578 sizeof(section_length
)) { 2579 printk(KERN_ERR LOGNAME
"firmware read error.\n"); 2583 if(section_length
==0) { 2587 if(read(fd
, section
, section_length
) != section_length
) { 2588 printk(KERN_ERR LOGNAME
"firmware section " 2595 if(wavefront_write(WFC_DOWNLOAD_OS
)) { 2599 for(i
=0; i
< section_length
; i
++) { 2600 if(wavefront_write(section
[i
])) { 2607 if(wavefront_wait(STAT_CAN_READ
)) { 2609 if((c
=inb(dev
.data_port
)) != WF_ACK
) { 2611 printk(KERN_ERR LOGNAME
"download " 2612 "of section #%d not " 2613 "acknowledged, ack = 0x%x\n", 2614 section_cnt_downloaded
+1, c
); 2620 printk(KERN_ERR LOGNAME
"time out for firmware ACK.\n"); 2633 printk(KERN_ERR
"\nWaveFront: firmware download failed!!!\n"); 2637 static int __init
wavefront_config_midi(void) 2639 unsigned char rbuf
[4], wbuf
[4]; 2641 if(detect_wf_mpu(dev
.irq
, dev
.base
) <0) { 2642 printk(KERN_WARNING LOGNAME
2643 "could not find working MIDI device\n"); 2647 if((dev
.mididev
=install_wf_mpu()) <0) { 2648 printk(KERN_WARNING LOGNAME
2649 "MIDI interfaces not configured\n"); 2653 /* Route external MIDI to WaveFront synth (by default) */ 2655 if(wavefront_cmd(WFC_MISYNTH_ON
, rbuf
, wbuf
)) { 2656 printk(KERN_WARNING LOGNAME
2657 "cannot enable MIDI-IN to synth routing.\n"); 2662 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ 2663 /* Get the regular MIDI patch loading function, so we can 2664 use it if we ever get handed a SYSEX patch. This is 2665 unlikely, because its so damn slow, but we may as well 2666 leave this functionality from maui.c behind, since it 2667 could be useful for sequencer applications that can 2668 only use MIDI to do patch loading. 2671 if(midi_devs
[dev
.mididev
]->converter
!= NULL
) { 2672 midi_load_patch
= midi_devs
[dev
.mididev
]->converter
->load_patch
; 2673 midi_devs
[dev
.mididev
]->converter
->load_patch
= 2674 &wavefront_oss_load_patch
; 2677 #endif OSS_SUPPORT_SEQ 2679 /* Turn on Virtual MIDI, but first *always* turn it off, 2680 since otherwise consectutive reloads of the driver will 2681 never cause the hardware to generate the initial "internal" or 2682 "external" source bytes in the MIDI data stream. This 2683 is pretty important, since the internal hardware generally will 2684 be used to generate none or very little MIDI output, and 2685 thus the only source of MIDI data is actually external. Without 2686 the switch bytes, the driver will think it all comes from 2687 the internal interface. Duh. 2690 if(wavefront_cmd(WFC_VMIDI_OFF
, rbuf
, wbuf
)) { 2691 printk(KERN_WARNING LOGNAME
2692 "virtual MIDI mode not disabled\n"); 2693 return0;/* We're OK, but missing the external MIDI dev */ 2696 if((dev
.ext_mididev
=virtual_midi_enable()) <0) { 2697 printk(KERN_WARNING LOGNAME
"no virtual MIDI access.\n"); 2699 if(wavefront_cmd(WFC_VMIDI_ON
, rbuf
, wbuf
)) { 2700 printk(KERN_WARNING LOGNAME
2701 "cannot enable virtual MIDI mode.\n"); 2702 virtual_midi_disable(); 2709 static int __init
wavefront_do_reset(int atboot
) 2713 if(!atboot
&&wavefront_hw_reset()) { 2714 printk(KERN_WARNING LOGNAME
"hw reset failed.\n"); 2719 if(wavefront_download_firmware(ospath
)) { 2725 /* Wait for the OS to get running. The protocol for 2726 this is non-obvious, and was determined by 2727 using port-IO tracing in DOSemu and some 2728 experimentation here. 2730 Rather than using timed waits, use interrupts creatively. 2733 wavefront_should_cause_interrupt(WFC_NOOP
, 2738 printk(KERN_WARNING LOGNAME
2739 "no post-OS interrupt.\n"); 2743 /* Now, do it again ! */ 2745 wavefront_should_cause_interrupt(WFC_NOOP
, 2746 dev
.data_port
, (10*HZ
)); 2749 printk(KERN_WARNING LOGNAME
2750 "no post-OS interrupt(2).\n"); 2754 /* OK, no (RX/TX) interrupts any more, but leave mute 2758 outb(0x80|0x40, dev
.control_port
); 2760 /* No need for the IRQ anymore */ 2762 free_irq(dev
.irq
, &dev
); 2766 if(dev
.has_fx
&& fx_raw
) { 2770 /* SETUPSND.EXE asks for sample memory config here, but since i 2771 have no idea how to interpret the result, we'll forget 2775 if((dev
.freemem
=wavefront_freemem()) <0) { 2779 printk(KERN_INFO LOGNAME
"available DRAM %dk\n", dev
.freemem
/1024); 2781 if(wavefront_write(0xf0) || 2782 wavefront_write(1) || 2783 (wavefront_read() <0)) { 2785 printk(KERN_WARNING LOGNAME
"MPU emulation mode not set.\n"); 2791 if(wavefront_cmd(WFC_SET_NVOICES
,0, voices
)) { 2792 printk(KERN_WARNING LOGNAME
2793 "cannot set number of voices to 32.\n"); 2801 /* reset that sucker so that it doesn't bother us. */ 2803 outb(0x0, dev
.control_port
); 2804 dev
.interrupts_on
=0; 2806 free_irq(dev
.irq
, &dev
); 2811 static int __init
wavefront_init(int atboot
) 2813 int samples_are_from_rom
; 2816 samples_are_from_rom
=1; 2818 /* XXX is this always true ? */ 2819 samples_are_from_rom
=0; 2822 if(dev
.israw
|| fx_raw
) { 2823 if(wavefront_do_reset(atboot
)) { 2828 wavefront_get_sample_status(samples_are_from_rom
); 2829 wavefront_get_program_status(); 2830 wavefront_get_patch_status(); 2832 /* Start normal operation: unreset, master interrupt enabled, no mute 2835 outb(0x80|0x40|0x20, dev
.control_port
); 2840 static int __init
install_wavefront(void) 2843 if((dev
.synth_dev
=register_sound_synth(&wavefront_fops
, -1)) <0) { 2844 printk(KERN_ERR LOGNAME
"cannot register raw synth\n"); 2848 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ 2849 if((dev
.oss_dev
=sound_alloc_synthdev()) == -1) { 2850 printk(KERN_ERR LOGNAME
"Too many sequencers\n"); 2853 synth_devs
[dev
.oss_dev
] = &wavefront_operations
; 2855 #endif OSS_SUPPORT_SEQ 2857 if(wavefront_init(1) <0) { 2858 printk(KERN_WARNING LOGNAME
"initialization failed.\n"); 2860 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ 2861 sound_unload_synthdev(dev
.oss_dev
); 2862 #endif OSS_SUPPORT_SEQ 2867 request_region(dev
.base
+2,6,"wavefront synth"); 2870 request_region(dev
.base
+8,8,"wavefront fx"); 2873 if(wavefront_config_midi()) { 2874 printk(KERN_WARNING LOGNAME
"could not initialize MIDI.\n"); 2880 static void __exit
uninstall_wavefront(void) 2882 /* the first two i/o addresses are freed by the wf_mpu code */ 2883 release_region(dev
.base
+2,6); 2886 release_region(dev
.base
+8,8); 2889 unregister_sound_synth(dev
.synth_dev
); 2891 #if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ 2892 sound_unload_synthdev(dev
.oss_dev
); 2893 #endif OSS_SUPPORT_SEQ 2897 /***********************************************************************/ 2898 /* WaveFront FX control */ 2899 /***********************************************************************/ 2903 /* Control bits for the Load Control Register 2906 #define FX_LSB_TRANSFER 0x01/* transfer after DSP LSB byte written */ 2907 #define FX_MSB_TRANSFER 0x02/* transfer after DSP MSB byte written */ 2908 #define FX_AUTO_INCR 0x04/* auto-increment DSP address after transfer */ 2915 unsigned int x
=0x80; 2917 for(i
=0; i
<1000; i
++) { 2918 x
=inb(dev
.fx_status
); 2925 printk(KERN_ERR LOGNAME
"FX device never idle.\n"); 2932 int __init
detect_wffx(void) 2934 /* This is a crude check, but its the best one I have for now. 2935 Certainly on the Maui and the Tropez, wffx_idle() will 2936 report "never idle", which suggests that this test should 2940 if(inb(dev
.fx_status
) &0x80) { 2941 printk(KERN_INFO LOGNAME
"Hmm, probably a Maui or Tropez.\n"); 2948 int __init
attach_wffx(void) 2950 if((dev
.fx_mididev
=sound_alloc_mididev()) <0) { 2951 printk(KERN_WARNING LOGNAME
"cannot install FX Midi driver\n"); 2959 wffx_mute(int onoff
) 2966 outb(onoff
?0x02:0x00, dev
.fx_op
); 2970 wffx_memset(int page
, 2971 int addr
,int cnt
,unsigned short*data
) 2973 if(page
<0|| page
>7) { 2974 printk(KERN_ERR LOGNAME
"FX memset: " 2975 "page must be >= 0 and <= 7\n"); 2979 if(addr
<0|| addr
>0x7f) { 2980 printk(KERN_ERR LOGNAME
"FX memset: " 2981 "addr must be >= 0 and <= 7f\n"); 2987 outb(FX_LSB_TRANSFER
, dev
.fx_lcr
); 2988 outb(page
, dev
.fx_dsp_page
); 2989 outb(addr
, dev
.fx_dsp_addr
); 2990 outb((data
[0] >>8), dev
.fx_dsp_msb
); 2991 outb((data
[0] &0xff), dev
.fx_dsp_lsb
); 2993 printk(KERN_INFO LOGNAME
"FX: addr %d:%x set to 0x%x\n", 2994 page
, addr
, data
[0]); 2999 outb(FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
); 3000 outb(page
, dev
.fx_dsp_page
); 3001 outb(addr
, dev
.fx_dsp_addr
); 3003 for(i
=0; i
< cnt
; i
++) { 3004 outb((data
[i
] >>8), dev
.fx_dsp_msb
); 3005 outb((data
[i
] &0xff), dev
.fx_dsp_lsb
); 3012 printk(KERN_WARNING LOGNAME
3014 "(0x%x, 0x%x, 0x%x, %d) incomplete\n", 3015 page
, addr
, (int) data
, cnt
); 3024 wffx_ioctl(wavefront_fx_info
*r
) 3027 unsigned short page_data
[256]; 3030 switch(r
->request
) { 3032 wffx_mute(r
->data
[0]); 3037 if(r
->data
[2] <=0) { 3038 printk(KERN_ERR LOGNAME
"cannot write " 3039 "<= 0 bytes to FX\n"); 3041 }else if(r
->data
[2] ==1) { 3042 pd
= (unsigned short*) &r
->data
[3]; 3044 if(r
->data
[2] >sizeof(page_data
)) { 3045 printk(KERN_ERR LOGNAME
"cannot write " 3046 "> 255 bytes to FX\n"); 3049 copy_from_user(page_data
, (unsigned char*) r
->data
[3], 3054 returnwffx_memset(r
->data
[0],/* page */ 3055 r
->data
[1],/* addr */ 3056 r
->data
[2],/* cnt */ 3060 printk(KERN_WARNING LOGNAME
3061 "FX: ioctl %d not yet supported\n", 3067 /* YSS225 initialization. 3069 This code was developed using DOSEMU. The Turtle Beach SETUPSND 3070 utility was run with I/O tracing in DOSEMU enabled, and a reconstruction 3071 of the port I/O done, using the Yamaha faxback document as a guide 3072 to add more logic to the code. Its really pretty wierd. 3074 There was an alternative approach of just dumping the whole I/O 3075 sequence as a series of port/value pairs and a simple loop 3076 that output it. However, I hope that eventually I'll get more 3077 control over what this code does, and so I tried to stick with 3078 a somewhat "algorithmic" approach. 3081 static int __init
wffx_init(void) 3086 /* Set all bits for all channels on the MOD unit to zero */ 3087 /* XXX But why do this twice ? */ 3089 for(j
=0; j
<2; j
++) { 3090 for(i
=0x10; i
<=0xff; i
++) { 3096 outb(i
, dev
.fx_mod_addr
); 3097 outb(0x0, dev
.fx_mod_data
); 3101 if(!wffx_idle())return(-1); 3102 outb(0x02, dev
.fx_op
);/* mute on */ 3104 if(!wffx_idle())return(-1); 3105 outb(0x07, dev
.fx_dsp_page
); 3106 outb(0x44, dev
.fx_dsp_addr
); 3107 outb(0x00, dev
.fx_dsp_msb
); 3108 outb(0x00, dev
.fx_dsp_lsb
); 3109 if(!wffx_idle())return(-1); 3110 outb(0x07, dev
.fx_dsp_page
); 3111 outb(0x42, dev
.fx_dsp_addr
); 3112 outb(0x00, dev
.fx_dsp_msb
); 3113 outb(0x00, dev
.fx_dsp_lsb
); 3114 if(!wffx_idle())return(-1); 3115 outb(0x07, dev
.fx_dsp_page
); 3116 outb(0x43, dev
.fx_dsp_addr
); 3117 outb(0x00, dev
.fx_dsp_msb
); 3118 outb(0x00, dev
.fx_dsp_lsb
); 3119 if(!wffx_idle())return(-1); 3120 outb(0x07, dev
.fx_dsp_page
); 3121 outb(0x7c, dev
.fx_dsp_addr
); 3122 outb(0x00, dev
.fx_dsp_msb
); 3123 outb(0x00, dev
.fx_dsp_lsb
); 3124 if(!wffx_idle())return(-1); 3125 outb(0x07, dev
.fx_dsp_page
); 3126 outb(0x7e, dev
.fx_dsp_addr
); 3127 outb(0x00, dev
.fx_dsp_msb
); 3128 outb(0x00, dev
.fx_dsp_lsb
); 3129 if(!wffx_idle())return(-1); 3130 outb(0x07, dev
.fx_dsp_page
); 3131 outb(0x46, dev
.fx_dsp_addr
); 3132 outb(0x00, dev
.fx_dsp_msb
); 3133 outb(0x00, dev
.fx_dsp_lsb
); 3134 if(!wffx_idle())return(-1); 3135 outb(0x07, dev
.fx_dsp_page
); 3136 outb(0x49, dev
.fx_dsp_addr
); 3137 outb(0x00, dev
.fx_dsp_msb
); 3138 outb(0x00, dev
.fx_dsp_lsb
); 3139 if(!wffx_idle())return(-1); 3140 outb(0x07, dev
.fx_dsp_page
); 3141 outb(0x47, dev
.fx_dsp_addr
); 3142 outb(0x00, dev
.fx_dsp_msb
); 3143 outb(0x00, dev
.fx_dsp_lsb
); 3144 if(!wffx_idle())return(-1); 3145 outb(0x07, dev
.fx_dsp_page
); 3146 outb(0x4a, dev
.fx_dsp_addr
); 3147 outb(0x00, dev
.fx_dsp_msb
); 3148 outb(0x00, dev
.fx_dsp_lsb
); 3150 /* either because of stupidity by TB's programmers, or because it 3151 actually does something, rezero the MOD page. 3153 for(i
=0x10; i
<=0xff; i
++) { 3159 outb(i
, dev
.fx_mod_addr
); 3160 outb(0x0, dev
.fx_mod_data
); 3162 /* load page zero */ 3164 outb(FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
); 3165 outb(0x00, dev
.fx_dsp_page
); 3166 outb(0x00, dev
.fx_dsp_addr
); 3168 for(i
=0; i
<sizeof(page_zero
); i
+=2) { 3169 outb(page_zero
[i
], dev
.fx_dsp_msb
); 3170 outb(page_zero
[i
+1], dev
.fx_dsp_lsb
); 3171 if(!wffx_idle())return(-1); 3174 /* Now load page one */ 3176 outb(FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
); 3177 outb(0x01, dev
.fx_dsp_page
); 3178 outb(0x00, dev
.fx_dsp_addr
); 3180 for(i
=0; i
<sizeof(page_one
); i
+=2) { 3181 outb(page_one
[i
], dev
.fx_dsp_msb
); 3182 outb(page_one
[i
+1], dev
.fx_dsp_lsb
); 3183 if(!wffx_idle())return(-1); 3186 outb(FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
); 3187 outb(0x02, dev
.fx_dsp_page
); 3188 outb(0x00, dev
.fx_dsp_addr
); 3190 for(i
=0; i
<sizeof(page_two
); i
++) { 3191 outb(page_two
[i
], dev
.fx_dsp_lsb
); 3192 if(!wffx_idle())return(-1); 3195 outb(FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
); 3196 outb(0x03, dev
.fx_dsp_page
); 3197 outb(0x00, dev
.fx_dsp_addr
); 3199 for(i
=0; i
<sizeof(page_three
); i
++) { 3200 outb(page_three
[i
], dev
.fx_dsp_lsb
); 3201 if(!wffx_idle())return(-1); 3204 outb(FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
); 3205 outb(0x04, dev
.fx_dsp_page
); 3206 outb(0x00, dev
.fx_dsp_addr
); 3208 for(i
=0; i
<sizeof(page_four
); i
++) { 3209 outb(page_four
[i
], dev
.fx_dsp_lsb
); 3210 if(!wffx_idle())return(-1); 3213 /* Load memory area (page six) */ 3215 outb(FX_LSB_TRANSFER
, dev
.fx_lcr
); 3216 outb(0x06, dev
.fx_dsp_page
); 3218 for(i
=0; i
<sizeof(page_six
); i
+=3) { 3219 outb(page_six
[i
], dev
.fx_dsp_addr
); 3220 outb(page_six
[i
+1], dev
.fx_dsp_msb
); 3221 outb(page_six
[i
+2], dev
.fx_dsp_lsb
); 3222 if(!wffx_idle())return(-1); 3225 outb(FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
); 3226 outb(0x07, dev
.fx_dsp_page
); 3227 outb(0x00, dev
.fx_dsp_addr
); 3229 for(i
=0; i
<sizeof(page_seven
); i
+=2) { 3230 outb(page_seven
[i
], dev
.fx_dsp_msb
); 3231 outb(page_seven
[i
+1], dev
.fx_dsp_lsb
); 3232 if(!wffx_idle())return(-1); 3235 /* Now setup the MOD area. We do this algorithmically in order to 3236 save a little data space. It could be done in the same fashion 3240 for(i
=0x00; i
<=0x0f; i
++) { 3241 outb(0x01, dev
.fx_mod_addr
); 3242 outb(i
, dev
.fx_mod_data
); 3243 if(!wffx_idle())return(-1); 3244 outb(0x02, dev
.fx_mod_addr
); 3245 outb(0x00, dev
.fx_mod_data
); 3246 if(!wffx_idle())return(-1); 3249 for(i
=0xb0; i
<=0xbf; i
++) { 3250 outb(i
, dev
.fx_mod_addr
); 3251 outb(0x20, dev
.fx_mod_data
); 3252 if(!wffx_idle())return(-1); 3255 for(i
=0xf0; i
<=0xff; i
++) { 3256 outb(i
, dev
.fx_mod_addr
); 3257 outb(0x20, dev
.fx_mod_data
); 3258 if(!wffx_idle())return(-1); 3261 for(i
=0x10; i
<=0x1d; i
++) { 3262 outb(i
, dev
.fx_mod_addr
); 3263 outb(0xff, dev
.fx_mod_data
); 3264 if(!wffx_idle())return(-1); 3267 outb(0x1e, dev
.fx_mod_addr
); 3268 outb(0x40, dev
.fx_mod_data
); 3269 if(!wffx_idle())return(-1); 3271 for(i
=0x1f; i
<=0x2d; i
++) { 3272 outb(i
, dev
.fx_mod_addr
); 3273 outb(0xff, dev
.fx_mod_data
); 3274 if(!wffx_idle())return(-1); 3277 outb(0x2e, dev
.fx_mod_addr
); 3278 outb(0x00, dev
.fx_mod_data
); 3279 if(!wffx_idle())return(-1); 3281 for(i
=0x2f; i
<=0x3e; i
++) { 3282 outb(i
, dev
.fx_mod_addr
); 3283 outb(0x00, dev
.fx_mod_data
); 3284 if(!wffx_idle())return(-1); 3287 outb(0x3f, dev
.fx_mod_addr
); 3288 outb(0x20, dev
.fx_mod_data
); 3289 if(!wffx_idle())return(-1); 3291 for(i
=0x40; i
<=0x4d; i
++) { 3292 outb(i
, dev
.fx_mod_addr
); 3293 outb(0x00, dev
.fx_mod_data
); 3294 if(!wffx_idle())return(-1); 3297 outb(0x4e, dev
.fx_mod_addr
); 3298 outb(0x0e, dev
.fx_mod_data
); 3299 if(!wffx_idle())return(-1); 3300 outb(0x4f, dev
.fx_mod_addr
); 3301 outb(0x0e, dev
.fx_mod_data
); 3302 if(!wffx_idle())return(-1); 3305 for(i
=0x50; i
<=0x6b; i
++) { 3306 outb(i
, dev
.fx_mod_addr
); 3307 outb(0x00, dev
.fx_mod_data
); 3308 if(!wffx_idle())return(-1); 3311 outb(0x6c, dev
.fx_mod_addr
); 3312 outb(0x40, dev
.fx_mod_data
); 3313 if(!wffx_idle())return(-1); 3315 outb(0x6d, dev
.fx_mod_addr
); 3316 outb(0x00, dev
.fx_mod_data
); 3317 if(!wffx_idle())return(-1); 3319 outb(0x6e, dev
.fx_mod_addr
); 3320 outb(0x40, dev
.fx_mod_data
); 3321 if(!wffx_idle())return(-1); 3323 outb(0x6f, dev
.fx_mod_addr
); 3324 outb(0x40, dev
.fx_mod_data
); 3325 if(!wffx_idle())return(-1); 3327 for(i
=0x70; i
<=0x7f; i
++) { 3328 outb(i
, dev
.fx_mod_addr
); 3329 outb(0xc0, dev
.fx_mod_data
); 3330 if(!wffx_idle())return(-1); 3333 for(i
=0x80; i
<=0xaf; i
++) { 3334 outb(i
, dev
.fx_mod_addr
); 3335 outb(0x00, dev
.fx_mod_data
); 3336 if(!wffx_idle())return(-1); 3339 for(i
=0xc0; i
<=0xdd; i
++) { 3340 outb(i
, dev
.fx_mod_addr
); 3341 outb(0x00, dev
.fx_mod_data
); 3342 if(!wffx_idle())return(-1); 3345 outb(0xde, dev
.fx_mod_addr
); 3346 outb(0x10, dev
.fx_mod_data
); 3347 if(!wffx_idle())return(-1); 3348 outb(0xdf, dev
.fx_mod_addr
); 3349 outb(0x10, dev
.fx_mod_data
); 3350 if(!wffx_idle())return(-1); 3352 for(i
=0xe0; i
<=0xef; i
++) { 3353 outb(i
, dev
.fx_mod_addr
); 3354 outb(0x00, dev
.fx_mod_data
); 3355 if(!wffx_idle())return(-1); 3358 for(i
=0x00; i
<=0x0f; i
++) { 3359 outb(0x01, dev
.fx_mod_addr
); 3360 outb(i
, dev
.fx_mod_data
); 3361 outb(0x02, dev
.fx_mod_addr
); 3362 outb(0x01, dev
.fx_mod_data
); 3363 if(!wffx_idle())return(-1); 3366 outb(0x02, dev
.fx_op
);/* mute on */ 3368 /* Now set the coefficients and so forth for the programs above */ 3370 for(i
=0; i
<sizeof(coefficients
); i
+=4) { 3371 outb(coefficients
[i
], dev
.fx_dsp_page
); 3372 outb(coefficients
[i
+1], dev
.fx_dsp_addr
); 3373 outb(coefficients
[i
+2], dev
.fx_dsp_msb
); 3374 outb(coefficients
[i
+3], dev
.fx_dsp_lsb
); 3375 if(!wffx_idle())return(-1); 3378 /* Some settings (?) that are too small to bundle into loops */ 3380 if(!wffx_idle())return(-1); 3381 outb(0x1e, dev
.fx_mod_addr
); 3382 outb(0x14, dev
.fx_mod_data
); 3383 if(!wffx_idle())return(-1); 3384 outb(0xde, dev
.fx_mod_addr
); 3385 outb(0x20, dev
.fx_mod_data
); 3386 if(!wffx_idle())return(-1); 3387 outb(0xdf, dev
.fx_mod_addr
); 3388 outb(0x20, dev
.fx_mod_data
); 3390 /* some more coefficients */ 3392 if(!wffx_idle())return(-1); 3393 outb(0x06, dev
.fx_dsp_page
); 3394 outb(0x78, dev
.fx_dsp_addr
); 3395 outb(0x00, dev
.fx_dsp_msb
); 3396 outb(0x40, dev
.fx_dsp_lsb
); 3397 if(!wffx_idle())return(-1); 3398 outb(0x07, dev
.fx_dsp_page
); 3399 outb(0x03, dev
.fx_dsp_addr
); 3400 outb(0x0f, dev
.fx_dsp_msb
); 3401 outb(0xff, dev
.fx_dsp_lsb
); 3402 if(!wffx_idle())return(-1); 3403 outb(0x07, dev
.fx_dsp_page
); 3404 outb(0x0b, dev
.fx_dsp_addr
); 3405 outb(0x0f, dev
.fx_dsp_msb
); 3406 outb(0xff, dev
.fx_dsp_lsb
); 3407 if(!wffx_idle())return(-1); 3408 outb(0x07, dev
.fx_dsp_page
); 3409 outb(0x02, dev
.fx_dsp_addr
); 3410 outb(0x00, dev
.fx_dsp_msb
); 3411 outb(0x00, dev
.fx_dsp_lsb
); 3412 if(!wffx_idle())return(-1); 3413 outb(0x07, dev
.fx_dsp_page
); 3414 outb(0x0a, dev
.fx_dsp_addr
); 3415 outb(0x00, dev
.fx_dsp_msb
); 3416 outb(0x00, dev
.fx_dsp_lsb
); 3417 if(!wffx_idle())return(-1); 3418 outb(0x07, dev
.fx_dsp_page
); 3419 outb(0x46, dev
.fx_dsp_addr
); 3420 outb(0x00, dev
.fx_dsp_msb
); 3421 outb(0x00, dev
.fx_dsp_lsb
); 3422 if(!wffx_idle())return(-1); 3423 outb(0x07, dev
.fx_dsp_page
); 3424 outb(0x49, dev
.fx_dsp_addr
); 3425 outb(0x00, dev
.fx_dsp_msb
); 3426 outb(0x00, dev
.fx_dsp_lsb
); 3428 /* Now, for some strange reason, lets reload every page 3429 and all the coefficients over again. I have *NO* idea 3430 why this is done. I do know that no sound is produced 3431 is this phase is omitted. 3434 outb(FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
); 3435 outb(0x00, dev
.fx_dsp_page
); 3436 outb(0x10, dev
.fx_dsp_addr
); 3438 for(i
=0; i
<sizeof(page_zero_v2
); i
+=2) { 3439 outb(page_zero_v2
[i
], dev
.fx_dsp_msb
); 3440 outb(page_zero_v2
[i
+1], dev
.fx_dsp_lsb
); 3441 if(!wffx_idle())return(-1); 3444 outb(FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
); 3445 outb(0x01, dev
.fx_dsp_page
); 3446 outb(0x10, dev
.fx_dsp_addr
); 3448 for(i
=0; i
<sizeof(page_one_v2
); i
+=2) { 3449 outb(page_one_v2
[i
], dev
.fx_dsp_msb
); 3450 outb(page_one_v2
[i
+1], dev
.fx_dsp_lsb
); 3451 if(!wffx_idle())return(-1); 3454 if(!wffx_idle())return(-1); 3455 if(!wffx_idle())return(-1); 3457 outb(FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
); 3458 outb(0x02, dev
.fx_dsp_page
); 3459 outb(0x10, dev
.fx_dsp_addr
); 3461 for(i
=0; i
<sizeof(page_two_v2
); i
++) { 3462 outb(page_two_v2
[i
], dev
.fx_dsp_lsb
); 3463 if(!wffx_idle())return(-1); 3465 outb(FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
); 3466 outb(0x03, dev
.fx_dsp_page
); 3467 outb(0x10, dev
.fx_dsp_addr
); 3469 for(i
=0; i
<sizeof(page_three_v2
); i
++) { 3470 outb(page_three_v2
[i
], dev
.fx_dsp_lsb
); 3471 if(!wffx_idle())return(-1); 3474 outb(FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
); 3475 outb(0x04, dev
.fx_dsp_page
); 3476 outb(0x10, dev
.fx_dsp_addr
); 3478 for(i
=0; i
<sizeof(page_four_v2
); i
++) { 3479 outb(page_four_v2
[i
], dev
.fx_dsp_lsb
); 3480 if(!wffx_idle())return(-1); 3483 outb(FX_LSB_TRANSFER
, dev
.fx_lcr
); 3484 outb(0x06, dev
.fx_dsp_page
); 3486 /* Page six v.2 is algorithmic */ 3488 for(i
=0x10; i
<=0x3e; i
+=2) { 3489 outb(i
, dev
.fx_dsp_addr
); 3490 outb(0x00, dev
.fx_dsp_msb
); 3491 outb(0x00, dev
.fx_dsp_lsb
); 3492 if(!wffx_idle())return(-1); 3495 outb(FX_AUTO_INCR
|FX_LSB_TRANSFER
, dev
.fx_lcr
); 3496 outb(0x07, dev
.fx_dsp_page
); 3497 outb(0x10, dev
.fx_dsp_addr
); 3499 for(i
=0; i
<sizeof(page_seven_v2
); i
+=2) { 3500 outb(page_seven_v2
[i
], dev
.fx_dsp_msb
); 3501 outb(page_seven_v2
[i
+1], dev
.fx_dsp_lsb
); 3502 if(!wffx_idle())return(-1); 3505 for(i
=0x00; i
<sizeof(mod_v2
); i
+=2) { 3506 outb(mod_v2
[i
], dev
.fx_mod_addr
); 3507 outb(mod_v2
[i
+1], dev
.fx_mod_data
); 3508 if(!wffx_idle())return(-1); 3511 for(i
=0; i
<sizeof(coefficients2
); i
+=4) { 3512 outb(coefficients2
[i
], dev
.fx_dsp_page
); 3513 outb(coefficients2
[i
+1], dev
.fx_dsp_addr
); 3514 outb(coefficients2
[i
+2], dev
.fx_dsp_msb
); 3515 outb(coefficients2
[i
+3], dev
.fx_dsp_lsb
); 3516 if(!wffx_idle())return(-1); 3519 for(i
=0; i
<sizeof(coefficients3
); i
+=2) { 3522 outb(0x07, dev
.fx_dsp_page
); 3523 x
= (i
%4) ?0x4e:0x4c; 3524 outb(x
, dev
.fx_dsp_addr
); 3525 outb(coefficients3
[i
], dev
.fx_dsp_msb
); 3526 outb(coefficients3
[i
+1], dev
.fx_dsp_lsb
); 3529 outb(0x00, dev
.fx_op
);/* mute off */ 3530 if(!wffx_idle())return(-1); 3536 static int irq
= -1; 3538 MODULE_AUTHOR("Paul Barton-Davis <pbd@op.net>"); 3539 MODULE_DESCRIPTION("Turtle Beach WaveFront Linux Driver"); 3540 MODULE_PARM(io
,"i"); 3541 MODULE_PARM(irq
,"i"); 3543 static int __init
init_wavfront(void) 3545 printk("Turtle Beach WaveFront Driver\n" 3546 "Copyright (C) by Hannu Solvainen, " 3547 "Paul Barton-Davis 1993-1998.\n"); 3549 /* XXX t'would be lovely to ask the CS4232 for these values, eh ? */ 3551 if(io
== -1|| irq
== -1) { 3552 printk(KERN_INFO LOGNAME
"irq and io options must be set.\n"); 3556 if(wavefront_interrupt_bits(irq
) <0) { 3557 printk(KERN_INFO LOGNAME
3558 "IRQ must be 9, 5, 12 or 15 (not %d)\n", irq
); 3562 if(detect_wavefront(irq
, io
) <0) { 3566 if(install_wavefront() <0) { 3573 static void __exit
cleanup_wavfront(void) 3575 uninstall_wavefront(); 3578 module_init(init_wavfront
); 3579 module_exit(cleanup_wavfront
);