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
17 * Bartlomiej Zolnierkiewicz
18 * Added __init to download_code()
21 * Andrew J. Kroll Tested 06/01/1999 with:
22 * * OSWF.MOT File Version: 1.15
23 * * OSWF.MOT File Dated: 09/12/94
24 * * Older versions will cause problems.
27 #include <linux/interrupt.h>
28 #include <linux/config.h>
29 #include <linux/module.h>
30 #include <linux/init.h>
32 #define USE_SEQ_MACROS
33 #define USE_SIMPLE_MACROS
35 #include "sound_config.h"
36 #include "sound_firmware.h"
40 static int maui_base
= 0x330;
42 static volatile int irq_ok
;
45 #define HOST_DATA_PORT (maui_base + 2)
46 #define HOST_STAT_PORT (maui_base + 3)
47 #define HOST_CTRL_PORT (maui_base + 3)
49 #define STAT_TX_INTR 0x40
50 #define STAT_TX_AVAIL 0x20
51 #define STAT_TX_IENA 0x10
52 #define STAT_RX_INTR 0x04
53 #define STAT_RX_AVAIL 0x02
54 #define STAT_RX_IENA 0x01
56 static int (*orig_load_patch
)(int dev
, int format
, const char __user
*addr
,
57 int offs
, int count
, int pmgr_flag
) = NULL
;
59 #include "maui_boot.h"
61 static int maui_wait(int mask
)
66 * Perform a short initial wait without sleeping
69 for (i
= 0; i
< 100; i
++)
70 if (inb(HOST_STAT_PORT
) & mask
)
74 * Wait up to 15 seconds with sleeping
77 for (i
= 0; i
< 150; i
++) {
78 if (inb(HOST_STAT_PORT
) & mask
)
80 current
->state
= TASK_INTERRUPTIBLE
;
81 schedule_timeout(HZ
/ 10);
82 if (signal_pending(current
))
88 static int maui_read(void)
90 if (maui_wait(STAT_RX_AVAIL
))
91 return inb(HOST_DATA_PORT
);
95 static int maui_write(unsigned char data
)
97 if (maui_wait(STAT_TX_AVAIL
)) {
98 outb((data
), HOST_DATA_PORT
);
101 printk(KERN_WARNING
"Maui: Write timeout\n");
105 static irqreturn_t
mauiintr(int irq
, void *dev_id
, struct pt_regs
*dummy
)
111 static int __init
download_code(void)
114 int eol_seen
= 0, done
= 0;
117 printk(KERN_INFO
"Code download (%d bytes): ", maui_osLen
);
119 for (i
= 0; i
< maui_osLen
; i
++) {
120 if (maui_os
[i
] != '\r') {
121 if (!skip
|| (maui_os
[i
] == 'S' && (i
== 0 || maui_os
[i
- 1] == '\n'))) {
124 if (maui_os
[i
] == '\n')
126 else if (maui_os
[i
] == 'S') {
127 if (maui_os
[i
+ 1] == '8')
129 if (!maui_write(0xF1))
131 if (!maui_write('S'))
134 if (!maui_write(maui_os
[i
]))
144 for (n
= 0; n
< 2; n
++) {
145 if (maui_wait(STAT_RX_AVAIL
)) {
146 c
= inb(HOST_DATA_PORT
);
151 printk("Download not acknowledged\n");
154 else if (!(lines
++ % 10))
159 printk(KERN_INFO
"Download complete\n");
169 printk(KERN_ERR
"Download failed!!!\n");
173 static int __init
maui_init(int irq
)
192 printk(KERN_ERR
"Maui: Invalid IRQ %d\n", irq
);
195 outb((0x00), HOST_CTRL_PORT
); /* Reset */
196 outb((bits
), HOST_DATA_PORT
); /* Set the IRQ bits */
197 outb((bits
| 0x80), HOST_DATA_PORT
); /* Set the IRQ bits again? */
198 outb((0x80), HOST_CTRL_PORT
); /* Leave reset */
199 outb((0x80), HOST_CTRL_PORT
); /* Leave reset */
200 outb((0xD0), HOST_CTRL_PORT
); /* Cause interrupt */
205 for (i
= 0; i
< 1000000 && !irq_ok
; i
++)
211 outb((0x80), HOST_CTRL_PORT
); /* Leave reset */
213 printk(KERN_INFO
"Turtle Beach Maui initialization\n");
215 if (!download_code())
218 outb((0xE0), HOST_CTRL_PORT
); /* Normal operation */
220 /* Select mpu401 mode */
224 if (maui_read() != 0x80) {
227 if (maui_read() != 0x80)
228 printk(KERN_ERR
"Maui didn't acknowledge set HW mode command\n");
230 printk(KERN_INFO
"Maui initialized OK\n");
234 static int maui_short_wait(int mask
) {
237 for (i
= 0; i
< 1000; i
++) {
238 if (inb(HOST_STAT_PORT
) & mask
) {
245 static int maui_load_patch(int dev
, int format
, const char __user
*addr
,
246 int offs
, int count
, int pmgr_flag
)
249 struct sysex_info header
;
250 unsigned long left
, src_offs
;
251 int hdr_size
= (unsigned long) &header
.data
[0] - (unsigned long) &header
;
254 if (format
== SYSEX_PATCH
) /* Handled by midi_synth.c */
255 return orig_load_patch(dev
, format
, addr
, offs
, count
, pmgr_flag
);
257 if (format
!= MAUI_PATCH
)
259 printk(KERN_WARNING
"Maui: Unknown patch format\n");
261 if (count
< hdr_size
) {
262 /* printk("Maui error: Patch header too short\n");*/
268 * Copy the header from user space but ignore the first bytes which have
269 * been transferred already.
272 if(copy_from_user(&((char *) &header
)[offs
], &(addr
)[offs
], hdr_size
- offs
))
275 if (count
< header
.len
) {
276 printk(KERN_ERR
"Maui warning: Host command record too short (%d<%d)\n", count
, (int) header
.len
);
282 for (i
= 0; i
< left
; i
++) {
285 if(get_user(*(unsigned char *) &data
, (unsigned char __user
*) &((addr
)[hdr_size
+ i
])))
287 if (i
== 0 && !(data
& 0x80))
290 if (maui_write(data
) == -1)
294 if ((i
= maui_read()) != 0x80) {
296 printk("Maui: Error status %02x\n", i
);
302 static int __init
probe_maui(struct address_info
*hw_config
)
304 struct resource
*ports
;
309 ports
= request_region(hw_config
->io_base
, 2, "mpu401");
313 if (!request_region(hw_config
->io_base
+ 2, 6, "Maui"))
316 maui_base
= hw_config
->io_base
;
317 maui_osp
= hw_config
->osp
;
319 if (request_irq(hw_config
->irq
, mauiintr
, 0, "Maui", NULL
) < 0)
323 * Initialize the processor if necessary
326 if (maui_osLen
> 0) {
327 if (!(inb(HOST_STAT_PORT
) & STAT_TX_AVAIL
) ||
328 !maui_write(0x9F) || /* Report firmware version */
329 !maui_short_wait(STAT_RX_AVAIL
) ||
330 maui_read() == -1 || maui_read() == -1)
331 if (!maui_init(hw_config
->irq
))
334 if (!maui_write(0xCF)) /* Report hardware version */ {
335 printk(KERN_ERR
"No WaveFront firmware detected (card uninitialized?)\n");
338 if ((tmp1
= maui_read()) == -1 || (tmp2
= maui_read()) == -1) {
339 printk(KERN_ERR
"No WaveFront firmware detected (card uninitialized?)\n");
342 if (tmp1
== 0xff || tmp2
== 0xff)
344 printk(KERN_DEBUG
"WaveFront hardware version %d.%d\n", tmp1
, tmp2
);
346 if (!maui_write(0x9F)) /* Report firmware version */
348 if ((tmp1
= maui_read()) == -1 || (tmp2
= maui_read()) == -1)
351 printk(KERN_DEBUG
"WaveFront firmware version %d.%d\n", tmp1
, tmp2
);
353 if (!maui_write(0x85)) /* Report free DRAM */
356 for (i
= 0; i
< 4; i
++) {
357 tmp1
|= maui_read() << (7 * i
);
359 printk(KERN_DEBUG
"Available DRAM %dk\n", tmp1
/ 1024);
361 for (i
= 0; i
< 1000; i
++)
362 if (probe_mpu401(hw_config
, ports
))
365 ret
= probe_mpu401(hw_config
, ports
);
369 conf_printf("Maui", hw_config
);
371 hw_config
->irq
*= -1;
372 hw_config
->name
= "Maui";
373 attach_mpu401(hw_config
, THIS_MODULE
);
375 if (hw_config
->slots
[1] != -1) /* The MPU401 driver installed itself */ {
376 struct synth_operations
*synth
;
378 this_dev
= hw_config
->slots
[1];
381 * Intercept patch loading calls so that they can be handled
382 * by the Maui driver.
385 synth
= midi_devs
[this_dev
]->converter
;
388 orig_load_patch
= synth
->load_patch
;
389 synth
->load_patch
= &maui_load_patch
;
391 printk(KERN_ERR
"Maui: Can't install patch loader\n");
396 free_irq(hw_config
->irq
, NULL
);
398 release_region(hw_config
->io_base
+ 2, 6);
400 release_region(hw_config
->io_base
, 2);
404 static void __exit
unload_maui(struct address_info
*hw_config
)
406 int irq
= hw_config
->irq
;
407 release_region(hw_config
->io_base
+ 2, 6);
408 unload_mpu401(hw_config
);
418 static struct address_info cfg
;
420 static int __initdata io
= -1;
421 static int __initdata irq
= -1;
423 module_param(io
, int, 0);
424 module_param(irq
, int, 0);
427 * Install a Maui card. Needs mpu401 loaded already.
430 static int __init
init_maui(void)
432 printk(KERN_INFO
"Turtle beach Maui and Tropez driver, Copyright (C) by Hannu Savolainen 1993-1996\n");
437 if (cfg
.io_base
== -1 || cfg
.irq
== -1) {
438 printk(KERN_INFO
"maui: irq and io must be set.\n");
442 if (maui_os
== NULL
) {
444 maui_osLen
= mod_firmware_load("/etc/sound/oswf.mot", (char **) &maui_os
);
446 if (probe_maui(&cfg
) == 0)
452 static void __exit
cleanup_maui(void)
454 if (fw_load
&& maui_os
)
459 module_init(init_maui
);
460 module_exit(cleanup_maui
);
463 static int __init
setup_maui(char *str
)
468 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
476 __setup("maui=", setup_maui
);
478 MODULE_LICENSE("GPL");