27 #include <linux/time.h>
28 #include <linux/wait.h>
31 #include <linux/slab.h>
32 #include <linux/module.h>
37 static int wf_raw = 0;
43 static int fx_raw = 1;
50 static int debug_default = 0;
58 #define DEFAULT_OSPATH "wavefront.os"
61 static int wait_usecs = 150;
74 static int sleep_interval = 100;
75 static int sleep_tries = 50;
77 static int reset_time = 2;
81 static int ramcheck_time = 20;
85 static int osrun_time = 10;
91 MODULE_PARM_DESC(fx_raw,
"if non-zero, assume that the FX process needs help");
97 MODULE_PARM_DESC(sleep_interval,
"how long to sleep when waiting for reply");
99 MODULE_PARM_DESC(sleep_tries,
"how many times to try sleeping during a wait");
103 MODULE_PARM_DESC(reset_time,
"how long to wait for a reset to take effect");
105 MODULE_PARM_DESC(ramcheck_time,
"how many seconds to wait for the RAM test");
107 MODULE_PARM_DESC(osrun_time,
"how many seconds to wait for the ICS2115 OS");
119 #define DPRINT(cond, ...) \
120 if ((dev->debug & (cond)) == (cond)) { \
121 snd_printk (__VA_ARGS__); \
124 #define DPRINT(cond, args...)
127 #define LOGNAME "WaveFront: "
131 #define STAT_RINTR_ENABLED 0x01
132 #define STAT_CAN_READ 0x02
133 #define STAT_INTR_READ 0x04
134 #define STAT_WINTR_ENABLED 0x10
135 #define STAT_CAN_WRITE 0x20
136 #define STAT_INTR_WRITE 0x40
152 } wavefront_errors[] = {
153 { 0x01,
"Bad sample number" },
154 { 0x02,
"Out of sample memory" },
155 { 0x03,
"Bad patch number" },
156 { 0x04,
"Error in number of voices" },
157 { 0x06,
"Sample load already in progress" },
158 { 0x0B,
"No sample load request pending" },
159 { 0x0E,
"Bad MIDI channel number" },
160 { 0x10,
"Download Record Error" },
232 wavefront_errorstr (
int errnum)
237 for (i = 0; wavefront_errors[
i].errstr; i++) {
238 if (wavefront_errors[i].errno == errnum) {
239 return wavefront_errors[
i].errstr;
243 return "Unknown WaveFront error";
247 wavefront_get_command (
int cmd)
252 for (i = 0; wavefront_commands[
i].
cmd != 0; i++) {
253 if (cmd == wavefront_commands[i].cmd) {
254 return &wavefront_commands[
i];
265 return inb (dev->status_port);
269 wavefront_sleep (
int limit)
274 return signal_pending(
current);
287 for (i = 0; i < wait_usecs; i += 5) {
288 if (wavefront_status (dev) & mask) {
294 for (i = 0; i < sleep_tries; i++) {
296 if (wavefront_status (dev) & mask) {
300 if (wavefront_sleep (
HZ/sleep_interval)) {
313 return inb (dev->data_port);
325 outb (data, dev->data_port);
336 int cmd,
unsigned char *rbuf,
unsigned char *wbuf)
344 if ((wfcmd = wavefront_get_command (cmd)) ==
NULL) {
364 if (wavefront_write (dev, cmd)) {
377 if (wavefront_write (dev, wbuf[i])) {
379 "%d of 0x%x [%s].\n",
394 for (i = 0; i < wfcmd->
read_cnt; i++) {
396 if ((c = wavefront_read (dev)) == -1) {
398 "%d of 0x%x [%s].\n",
406 if ((c = wavefront_read (dev)) == -1) {
441 wavefront_errorstr (c),
464 if ((ack = wavefront_read (dev)) == 0) {
480 if ((err = wavefront_read (dev)) == -1) {
489 "failed (0x%x, 0x%x, %s)\n",
490 cmd, wfcmd->
action, ack, err,
491 wavefront_errorstr (err));
528 static unsigned char *
529 munge_int32 (
unsigned int src,
546 demunge_int32 (
unsigned char* src,
int src_size)
552 for (i = src_size - 1; i >= 0; i--) {
553 outval=(outval<<7)+src[i];
561 munge_buf (
unsigned char *src,
unsigned char *dst,
unsigned int dst_size)
565 unsigned int last = dst_size / 2;
567 for (i = 0; i < last; i++) {
568 *dst++ = src[
i] & 0x7f;
569 *dst++ = src[
i] >> 7;
576 demunge_buf (
unsigned char *src,
unsigned char *dst,
unsigned int src_bytes)
580 unsigned char *
end = src + src_bytes;
582 end = src + src_bytes;
586 for (i = 0; src !=
end; i++) {
588 dst[
i] |= (*src++)<<7;
602 unsigned char wbuf[2];
605 wbuf[0] = sample_num & 0x7f;
606 wbuf[1] = sample_num >> 7;
620 unsigned char rbuf[32], wbuf[32];
621 unsigned int sc_real, sc_alias, sc_multi;
626 snd_printk (
"cannot request sample count.\n");
639 "type of slot %d\n", i);
674 snd_printk (
"%d samples used (%d real, %d aliases, %d multi), "
675 "%d empty\n", dev->
samples_used, sc_real, sc_alias, sc_multi,
688 unsigned char patchnum[2];
693 patchnum[0] = i & 0x7f;
694 patchnum[1] = i >> 7;
726 snd_printk (
"%d patch slots filled, %d in use\n", cnt, cnt2);
737 unsigned char prognum;
748 demunge_buf (progbuf, (
unsigned char *) &prog,
752 if (prog.
layer[l].mute) {
754 [prog.
layer[
l].patch_number] |=
773 snd_printk (
"%d programs slots in use\n", cnt);
791 bptr = munge_int32 (header->
number, buf, 2);
850 return demunge_int32 (rbuf, 4);
858 int data_is_unsigned)
870 u16 sample_short = 0;
874 const unsigned int max_blksize = 4096/2;
875 unsigned int written;
876 unsigned int blocksize;
880 unsigned char *shptr;
882 int initial_skip = 0;
885 "type %d, %d bytes from 0x%lx\n",
886 header->
size ?
"" :
"header ",
889 (
unsigned long) header->
dataptr);
894 if ((x = wavefront_find_free_sample (dev)) < 0) {
935 wavefront_delete_sample (dev, header->
number);
939 dev->
freemem = wavefront_freemem (dev);
943 "load %d byte sample.\n",
954 "possible on 16-bit samples");
990 "initial skip = %d, skip = %d\n",
1003 length = header->
size / 2;
1010 shptr = &sample_hdr[0];
1012 shptr = munge_int32 (header->
number, shptr, 2);
1015 shptr = munge_int32 (length, shptr, 4);
1049 NULL, sample_hdr)) {
1051 header->
size ?
"" :
"header ");
1055 if (header->
size == 0) {
1059 data_end = dataptr +
length;
1063 dataptr += initial_skip;
1065 for (written = 0, blocknum = 0;
1066 written <
length; written += max_blksize, blocknum++) {
1068 if ((length - written) > max_blksize) {
1069 blocksize = max_blksize;
1072 blocksize =
ALIGN(length - written, 8);
1077 "request refused.\n");
1081 for (i = 0; i < blocksize; i++) {
1083 if (dataptr < data_end) {
1088 if (data_is_unsigned) {
1098 &sample_short)[0] += 0x7f;
1100 &sample_short)[1] += 0x7f;
1109 sample_short += 0x7fff;
1123 if (i < blocksize - 1) {
1124 outw (sample_short, dev->block_port);
1126 outw (sample_short, dev->last_block_port);
1134 if ((dma_ack = wavefront_read (dev)) !=
WF_DMA_ACK) {
1135 if (dma_ack == -1) {
1137 "DMA ack timeout\n");
1141 "DMA ack error 0x%x\n",
1167 header->
hdr.
a.OriginalSample);
1169 munge_int32 (header->
number, &alias_hdr[0], 2);
1170 munge_int32 (header->
hdr.
a.OriginalSample, &alias_hdr[2], 2);
1171 munge_int32 (*((
unsigned int *)&header->
hdr.
a.sampleStartOffset),
1173 munge_int32 (*((
unsigned int *)&header->
hdr.
a.loopStartOffset),
1175 munge_int32 (*((
unsigned int *)&header->
hdr.
a.loopEndOffset),
1177 munge_int32 (*((
unsigned int *)&header->
hdr.
a.sampleEndOffset),
1179 munge_int32 (header->
hdr.
a.FrequencyBias, &alias_hdr[20], 3);
1180 munge_int32 (*(&header->
hdr.
a.FrequencyBias+1), &alias_hdr[23], 2);
1197 unsigned char *msample_hdr;
1203 munge_int32 (header->
number, &msample_hdr[0], 2);
1218 for (i = 0; i < num_samples; i++) {
1222 &msample_hdr[3+(i*2)], 2);
1231 (
unsigned char *) (
long) ((num_samples*2)+3),
1233 snd_printk (
"download of multisample failed.\n");
1249 unsigned char log_ns[1];
1253 munge_int32 (header->
number, number, 2);
1261 header->
number, log_ns[0]);
1267 num_samples = (1 << log_ns[0]);
1269 for (i = 0; i < num_samples; i++) {
1273 if ((val = wavefront_read (dev)) == -1) {
1275 "during sample loop.\n");
1280 if ((val = wavefront_read (dev)) == -1) {
1282 "during sample loop.\n");
1288 demunge_int32 ((
unsigned char *) d, 2);
1307 "note %d, patch = %d\n",
1310 drumbuf[0] = header->
number & 0x7f;
1312 for (i = 0; i < 4; i++) {
1313 munge_int32 (((
unsigned char *)drum)[i], &drumbuf[1+(i*2)], 2);
1368 snd_printk (
"bad address for load patch.\n");
1375 "Sample number: %d "
1376 "Sample size: %d\n",
1381 switch (header->
subkey) {
1390 err = wavefront_send_sample (dev, header, header->
dataptr, 0);
1401 err = wavefront_send_multisample (dev, header);
1407 sizeof (wavefront_alias))) {
1412 err = wavefront_send_alias (dev, header);
1422 err = wavefront_send_drum (dev, header);
1432 err = wavefront_send_patch (dev, header);
1442 err = wavefront_send_program (dev, header);
1462 process_sample_hdr (
u8 *buf)
1484 s.
Loop = *ptr & 0x8;
1499 unsigned char patchnumbuf[2];
1503 "cmd 0x%x\n", wc->
cmd);
1511 outb (0x80|0x20, dev->control_port);
1517 outb (0x80|0x40|0x20, dev->control_port);
1531 i = wc->
wbuf[0] | (wc->
wbuf[1] << 7);
1532 if (i <0 || i >= WF_MAX_SAMPLE) {
1548 munge_int32 (*((
u32 *) wc->
wbuf), patchnumbuf, 2);
1556 wc->
status = wavefront_fetch_multisample
1561 snd_printk (
"support for sample alias upload "
1562 "being considered.\n");
1599 process_sample_hdr (wc->
rbuf);
1604 "sample aliases still "
1605 "being considered.\n");
1625 if (!try_module_get(hw->
card->module))
1635 module_put(hw->
card->module);
1641 unsigned int cmd,
unsigned long arg)
1663 if (wavefront_load_patch (dev, argp) != 0) {
1673 if (wavefront_synth_control (acard, wc) < 0)
1743 snd_wavefront_interrupt_bits (
int irq)
1772 int val,
int port,
unsigned long timeout)
1777 init_waitqueue_entry(&wait,
current);
1798 bits = snd_wavefront_interrupt_bits (dev->
irq);
1802 outb (0x0, dev->control_port);
1840 outb (0x80 | 0x40 | bits, dev->data_port);
1859 wavefront_should_cause_interrupt(dev, 0x80|0x40|0x10|0x1,
1861 (reset_time*
HZ)/100);
1868 snd_printk (
"intr not received after h/w un-reset.\n");
1889 dev->data_port, ramcheck_time*
HZ);
1892 snd_printk (
"post-RAM-check interrupt not received.\n");
1897 snd_printk (
"no response to HW version cmd.\n");
1901 if ((hwv[0] = wavefront_read (dev)) == -1) {
1902 snd_printk (
"board not responding correctly.\n");
1906 if (hwv[0] == 0xFF) {
1912 if ((hwv[0] = wavefront_read (dev)) == -1) {
1914 "(bad error code).\n");
1917 "(error code: 0x%x).\n",
1925 if ((hwv[1] = wavefront_read (dev)) == -1) {
1944 const unsigned char *
buf;
1946 int section_cnt_downloaded = 0;
1956 buf = firmware->
data;
1959 if (section_length == 0)
1963 "invalid firmware section length %d\n",
1970 if (firmware->
size < len + section_length) {
1980 if (wavefront_write(dev, *buf))
1991 err =
inb(dev->data_port);
1994 "download of section #%d not "
1995 "acknowledged, ack = 0x%x\n",
1996 section_cnt_downloaded + 1, err);
2000 section_cnt_downloaded++;
2019 if (wavefront_reset_to_cleanliness (dev)) {
2025 if (wavefront_download_firmware (dev, ospath)) {
2039 wavefront_should_cause_interrupt (dev,
WFC_NOOP,
2050 wavefront_should_cause_interrupt (dev,
WFC_NOOP,
2051 dev->data_port, (10*
HZ));
2062 outb (0x80|0x40, dev->control_port);
2070 if ((dev->
freemem = wavefront_freemem (dev)) < 0) {
2076 if (wavefront_write (dev, 0xf0) ||
2077 wavefront_write (dev, 1) ||
2078 (wavefront_read (dev) < 0)) {
2080 snd_printk (
"MPU emulation mode not set.\n");
2087 snd_printk (
"cannot set number of voices to 32.\n");
2097 outb (0x0, dev->control_port);
2106 int samples_are_from_rom;
2113 samples_are_from_rom = 1;
2116 samples_are_from_rom = 0;
2119 if (dev->
israw || fx_raw) {
2120 if (wavefront_do_reset (dev)) {
2128 if (dev->
has_fx && fx_raw) {
2132 wavefront_get_sample_status (dev, samples_are_from_rom);
2133 wavefront_get_program_status (dev);
2134 wavefront_get_patch_status (dev);
2139 outb (0x80|0x40|0x20, dev->control_port);
2148 unsigned char rbuf[4], wbuf[4];
2157 dev->
debug = debug_default;
2167 snd_printk (
"firmware %d.%d already loaded.\n",
2178 "hardware version!\n");
2185 snd_printk (
"reloading firmware as you requested.\n");
2192 snd_printk (
"no response to firmware probe, assume raw.\n");