4 * The low level driver for Turtle Beach Maui and Tropez.
7 * Copyright (C) by Hannu Savolainen 1993-1997
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
14 * Alan Cox General clean up, use kernel IRQ
16 * Christoph Hellwig Adapted to module_init/module_exit
19 * Andrew J. Kroll Tested 06/01/1999 with:
20 * * OSWF.MOT File Version: 1.15
21 * * OSWF.MOT File Dated: 09/12/94
22 * * Older versions will cause problems.
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/init.h>
29 #define USE_SEQ_MACROS
30 #define USE_SIMPLE_MACROS
32 #include "sound_config.h"
33 #include "soundmodule.h"
34 #include "sound_firmware.h"
38 static int maui_base
= 0x330;
40 static volatile int irq_ok
= 0;
43 #define HOST_DATA_PORT (maui_base + 2)
44 #define HOST_STAT_PORT (maui_base + 3)
45 #define HOST_CTRL_PORT (maui_base + 3)
47 #define STAT_TX_INTR 0x40
48 #define STAT_TX_AVAIL 0x20
49 #define STAT_TX_IENA 0x10
50 #define STAT_RX_INTR 0x04
51 #define STAT_RX_AVAIL 0x02
52 #define STAT_RX_IENA 0x01
54 static int (*orig_load_patch
) (int dev
, int format
, const char *addr
,
55 int offs
, int count
, int pmgr_flag
) = NULL
;
57 #include "maui_boot.h"
59 static int maui_wait(int mask
)
64 * Perform a short initial wait without sleeping
67 for (i
= 0; i
< 100; i
++)
68 if (inb(HOST_STAT_PORT
) & mask
)
72 * Wait up to 15 seconds with sleeping
75 for (i
= 0; i
< 150; i
++) {
76 if (inb(HOST_STAT_PORT
) & mask
)
78 current
->state
= TASK_INTERRUPTIBLE
;
79 schedule_timeout(HZ
/ 10);
80 if (signal_pending(current
))
86 static int maui_read(void)
88 if (maui_wait(STAT_RX_AVAIL
))
89 return inb(HOST_DATA_PORT
);
93 static int maui_write(unsigned char data
)
95 if (maui_wait(STAT_TX_AVAIL
)) {
96 outb((data
), HOST_DATA_PORT
);
99 printk(KERN_WARNING
"Maui: Write timeout\n");
103 static void mauiintr(int irq
, void *dev_id
, struct pt_regs
*dummy
)
108 static int download_code(void)
111 int eol_seen
= 0, done
= 0;
114 printk(KERN_INFO
"Code download (%d bytes): ", maui_osLen
);
116 for (i
= 0; i
< maui_osLen
; i
++) {
117 if (maui_os
[i
] != '\r') {
118 if (!skip
|| (maui_os
[i
] == 'S' && (i
== 0 || maui_os
[i
- 1] == '\n'))) {
121 if (maui_os
[i
] == '\n')
123 else if (maui_os
[i
] == 'S') {
124 if (maui_os
[i
+ 1] == '8')
126 if (!maui_write(0xF1))
128 if (!maui_write('S'))
131 if (!maui_write(maui_os
[i
]))
141 for (n
= 0; n
< 2; n
++) {
142 if (maui_wait(STAT_RX_AVAIL
)) {
143 c
= inb(HOST_DATA_PORT
);
148 printk("Download not acknowledged\n");
151 else if (!(lines
++ % 10))
156 printk(KERN_INFO
"Download complete\n");
166 printk(KERN_ERR
"Download failed!!!\n");
170 static int __init
maui_init(int irq
)
189 printk(KERN_ERR
"Maui: Invalid IRQ %d\n", irq
);
192 outb((0x00), HOST_CTRL_PORT
); /* Reset */
193 outb((bits
), HOST_DATA_PORT
); /* Set the IRQ bits */
194 outb((bits
| 0x80), HOST_DATA_PORT
); /* Set the IRQ bits again? */
195 outb((0x80), HOST_CTRL_PORT
); /* Leave reset */
196 outb((0x80), HOST_CTRL_PORT
); /* Leave reset */
197 outb((0xD0), HOST_CTRL_PORT
); /* Cause interrupt */
202 for (i
= 0; i
< 1000000 && !irq_ok
; i
++)
208 outb((0x80), HOST_CTRL_PORT
); /* Leave reset */
210 printk(KERN_INFO
"Turtle Beach Maui initialization\n");
212 if (!download_code())
215 outb((0xE0), HOST_CTRL_PORT
); /* Normal operation */
217 /* Select mpu401 mode */
221 if (maui_read() != 0x80) {
224 if (maui_read() != 0x80)
225 printk(KERN_ERR
"Maui didn't acknowledge set HW mode command\n");
227 printk(KERN_INFO
"Maui initialized OK\n");
231 static int maui_short_wait(int mask
) {
234 for (i
= 0; i
< 1000; i
++) {
235 if (inb(HOST_STAT_PORT
) & mask
) {
242 static int maui_load_patch(int dev
, int format
, const char *addr
,
243 int offs
, int count
, int pmgr_flag
)
246 struct sysex_info header
;
247 unsigned long left
, src_offs
;
248 int hdr_size
= (unsigned long) &header
.data
[0] - (unsigned long) &header
;
251 if (format
== SYSEX_PATCH
) /* Handled by midi_synth.c */
252 return orig_load_patch(dev
, format
, addr
, offs
, count
, pmgr_flag
);
254 if (format
!= MAUI_PATCH
)
256 printk(KERN_WARNING
"Maui: Unknown patch format\n");
258 if (count
< hdr_size
) {
259 /* printk("Maui error: Patch header too short\n");*/
265 * Copy the header from user space but ignore the first bytes which have
266 * been transferred already.
269 if(copy_from_user(&((char *) &header
)[offs
], &(addr
)[offs
], hdr_size
- offs
))
272 if (count
< header
.len
) {
273 printk(KERN_ERR
"Maui warning: Host command record too short (%d<%d)\n", count
, (int) header
.len
);
279 for (i
= 0; i
< left
; i
++) {
282 if(get_user(*(unsigned char *) &data
, (unsigned char *) &((addr
)[hdr_size
+ i
])))
284 if (i
== 0 && !(data
& 0x80))
287 if (maui_write(data
) == -1)
291 if ((i
= maui_read()) != 0x80) {
293 printk("Maui: Error status %02x\n", i
);
299 static int __init
probe_maui(struct address_info
*hw_config
)
304 if (check_region(hw_config
->io_base
, 8))
307 maui_base
= hw_config
->io_base
;
308 maui_osp
= hw_config
->osp
;
310 if (request_irq(hw_config
->irq
, mauiintr
, 0, "Maui", NULL
) < 0)
314 * Initialize the processor if necessary
317 if (maui_osLen
> 0) {
318 if (!(inb(HOST_STAT_PORT
) & STAT_TX_AVAIL
) ||
319 !maui_write(0x9F) || /* Report firmware version */
320 !maui_short_wait(STAT_RX_AVAIL
) ||
321 maui_read() == -1 || maui_read() == -1)
322 if (!maui_init(hw_config
->irq
)) {
323 free_irq(hw_config
->irq
, NULL
);
327 if (!maui_write(0xCF)) /* Report hardware version */ {
328 printk(KERN_ERR
"No WaveFront firmware detected (card uninitialized?)\n");
329 free_irq(hw_config
->irq
, NULL
);
332 if ((tmp1
= maui_read()) == -1 || (tmp2
= maui_read()) == -1) {
333 printk(KERN_ERR
"No WaveFront firmware detected (card uninitialized?)\n");
334 free_irq(hw_config
->irq
, NULL
);
337 if (tmp1
== 0xff || tmp2
== 0xff) {
338 free_irq(hw_config
->irq
, NULL
);
341 printk(KERN_DEBUG
"WaveFront hardware version %d.%d\n", tmp1
, tmp2
);
343 if (!maui_write(0x9F)) /* Report firmware version */
345 if ((tmp1
= maui_read()) == -1 || (tmp2
= maui_read()) == -1)
348 printk(KERN_DEBUG
"WaveFront firmware version %d.%d\n", tmp1
, tmp2
);
350 if (!maui_write(0x85)) /* Report free DRAM */
353 for (i
= 0; i
< 4; i
++) {
354 tmp1
|= maui_read() << (7 * i
);
356 printk(KERN_DEBUG
"Available DRAM %dk\n", tmp1
/ 1024);
358 for (i
= 0; i
< 1000; i
++)
359 if (probe_mpu401(hw_config
))
362 ret
= probe_mpu401(hw_config
);
365 request_region(hw_config
->io_base
+ 2, 6, "Maui");
370 static void __init
attach_maui(struct address_info
*hw_config
)
374 conf_printf("Maui", hw_config
);
376 hw_config
->irq
*= -1;
377 hw_config
->name
= "Maui";
378 attach_mpu401(hw_config
);
380 if (hw_config
->slots
[1] != -1) /* The MPU401 driver installed itself */ {
381 struct synth_operations
*synth
;
383 this_dev
= hw_config
->slots
[1];
386 * Intercept patch loading calls so that they can be handled
387 * by the Maui driver.
390 synth
= midi_devs
[this_dev
]->converter
;
394 orig_load_patch
= synth
->load_patch
;
395 synth
->load_patch
= &maui_load_patch
;
397 printk(KERN_ERR
"Maui: Can't install patch loader\n");
401 static void __exit
unload_maui(struct address_info
*hw_config
)
403 int irq
= hw_config
->irq
;
404 release_region(hw_config
->io_base
+ 2, 6);
405 unload_mpu401(hw_config
);
413 static int fw_load
= 0;
415 static struct address_info cfg
;
417 static int __initdata io
= -1;
418 static int __initdata irq
= -1;
421 MODULE_PARM(irq
,"i");
424 * Install a Maui card. Needs mpu401 loaded already.
427 static int __init
init_maui(void)
429 printk(KERN_INFO
"Turtle beach Maui and Tropez driver, Copyright (C) by Hannu Savolainen 1993-1996\n");
434 if (cfg
.io_base
== -1 || cfg
.irq
== -1) {
435 printk(KERN_INFO
"maui: irq and io must be set.\n");
439 if (maui_os
== NULL
) {
441 maui_osLen
= mod_firmware_load("/etc/sound/oswf.mot", (char **) &maui_os
);
443 if (probe_maui(&cfg
) == 0)
450 static void __exit
cleanup_maui(void)
452 if (fw_load
&& maui_os
)
458 module_init(init_maui
);
459 module_exit(cleanup_maui
);
462 static int __init
setup_maui(char *str
)
467 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
475 __setup("maui=", setup_maui
);