patch-2.3.50 linux/drivers/sound/maui.c

Next file: linux/drivers/sound/mpu401.c
Previous file: linux/drivers/sound/mad16.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.49/linux/drivers/sound/maui.c linux/drivers/sound/maui.c
@@ -2,8 +2,8 @@
  * sound/maui.c
  *
  * The low level driver for Turtle Beach Maui and Tropez.
- */
-/*
+ *
+ *
  * Copyright (C) by Hannu Savolainen 1993-1997
  *
  * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
@@ -13,6 +13,7 @@
  *	Changes:
  *		Alan Cox		General clean up, use kernel IRQ 
  *					system
+ *		Christoph Hellwig	Adapted to module_init/module_exit
  *
  *	Status:
  *		Andrew J. Kroll		Tested 06/01/1999 with:
@@ -32,6 +33,8 @@
 #include "soundmodule.h"
 #include "sound_firmware.h"
 
+#include "mpu401.h"
+
 static int      maui_base = 0x330;
 
 static volatile int irq_ok = 0;
@@ -62,19 +65,14 @@
 	 */
 
 	for (i = 0; i < 100; i++)
-	{
 		if (inb(HOST_STAT_PORT) & mask)
-		{
 			return 1;
-		}
-	}
 
 	/*
 	 * Wait up to 15 seconds with sleeping
 	 */
 
-	for (i = 0; i < 150; i++)
-	{
+	for (i = 0; i < 150; i++) {
 		if (inb(HOST_STAT_PORT) & mask)
 			return 1;
 		current->state = TASK_INTERRUPTIBLE;
@@ -94,8 +92,7 @@
 
 static int maui_write(unsigned char data)
 {
-	if (maui_wait(STAT_TX_AVAIL))
-	{
+	if (maui_wait(STAT_TX_AVAIL)) {
 		outb((data), HOST_DATA_PORT);
 		return 1;
 	}
@@ -116,56 +113,45 @@
 
 	printk(KERN_INFO "Code download (%d bytes): ", maui_osLen);
 
-	for (i = 0; i < maui_osLen; i++)
-	{
-		if (maui_os[i] != '\r')
-		{
-			if (!skip || (maui_os[i] == 'S' && (i == 0 || maui_os[i - 1] == '\n')))
-			{
+	for (i = 0; i < maui_osLen; i++) {
+		if (maui_os[i] != '\r') {
+			if (!skip || (maui_os[i] == 'S' && (i == 0 || maui_os[i - 1] == '\n'))) {
 				skip = 0;
 
 				if (maui_os[i] == '\n')
 					eol_seen = skip = 1;
-				else if (maui_os[i] == 'S')
-				{
+				else if (maui_os[i] == 'S') {
 					if (maui_os[i + 1] == '8')
 						done = 1;
 					if (!maui_write(0xF1))
 						goto failure;
 					if (!maui_write('S'))
 						goto failure;
-				}
-				else
-				{
+				} else {
 					if (!maui_write(maui_os[i]))
 						goto failure;
 				}
 
-				if (eol_seen)
-				{
+				if (eol_seen) {
 					int c = 0;
 					int n;
 
 					eol_seen = 0;
 
-					for (n = 0; n < 2; n++)
-					{
-						if (maui_wait(STAT_RX_AVAIL))
-						{
+					for (n = 0; n < 2; n++) {
+						if (maui_wait(STAT_RX_AVAIL)) {
 							c = inb(HOST_DATA_PORT);
 							break;
 						}
 					}
-					if (c != 0x80)
-					{
+					if (c != 0x80) {
 						printk("Download not acknowledged\n");
 						return 0;
 					}
 					else if (!(lines++ % 10))
 						printk(".");
 
-					if (done)
-					{
+					if (done) {
 						printk("\n");
 						printk(KERN_INFO "Download complete\n");
 						return 1;
@@ -181,15 +167,11 @@
 	return 0;
 }
 
-static int maui_init(int irq)
+static int __init maui_init(int irq)
 {
-#ifdef CONFIG_SMP
-	int i;
-#endif	
 	unsigned char bits;
 
-	switch (irq)
-	{
+	switch (irq) {
 		case 9:
 			bits = 0x00;
 			break;
@@ -215,10 +197,13 @@
 	outb((0xD0), HOST_CTRL_PORT);	/* Cause interrupt */
 
 #ifdef CONFIG_SMP
-	for (i = 0; i < 1000000 && !irq_ok; i++);
-
-	if (!irq_ok)
-		return 0;
+	{
+		int i;
+		for (i = 0; i < 1000000 && !irq_ok; i++)
+			;
+		if (!irq_ok)
+			return 0;
+	}
 #endif
 	outb((0x80), HOST_CTRL_PORT);	/* Leave reset */
 
@@ -233,8 +218,7 @@
 
 	maui_write(0xf0);
 	maui_write(1);
-	if (maui_read() != 0x80)
-	{
+	if (maui_read() != 0x80) {
 		maui_write(0xf0);
 		maui_write(1);
 		if (maui_read() != 0x80)
@@ -244,14 +228,11 @@
 	return 1;
 }
 
-static int maui_short_wait(int mask)
-{
+static int maui_short_wait(int mask) {
 	int i;
 
-	for (i = 0; i < 1000; i++)
-	{
-		if (inb(HOST_STAT_PORT) & mask)
-		{
+	for (i = 0; i < 1000; i++) {
+		if (inb(HOST_STAT_PORT) & mask) {
 			return 1;
 		}
 	}
@@ -274,8 +255,7 @@
 	{
 		  printk(KERN_WARNING "Maui: Unknown patch format\n");
 	}
-	if (count < hdr_size)
-	{
+	if (count < hdr_size) {
 /*		  printk("Maui error: Patch header too short\n");*/
 		  return -EINVAL;
 	}
@@ -289,16 +269,14 @@
 	if(copy_from_user(&((char *) &header)[offs], &(addr)[offs], hdr_size - offs))
 		return -EFAULT;
 
-	if (count < header.len)
-	{
+	if (count < header.len) {
 		  printk(KERN_ERR "Maui warning: Host command record too short (%d<%d)\n", count, (int) header.len);
 		  header.len = count;
 	}
 	left = header.len;
 	src_offs = 0;
 
-	for (i = 0; i < left; i++)
-	{
+	for (i = 0; i < left; i++) {
 		unsigned char   data;
 
 		if(get_user(*(unsigned char *) &data, (unsigned char *) &((addr)[hdr_size + i])))
@@ -310,8 +288,7 @@
 			return -EIO;
 	}
 
-	if ((i = maui_read()) != 0x80)
-	{
+	if ((i = maui_read()) != 0x80) {
 		if (i != -1)
 			printk("Maui: Error status %02x\n", i);
 		return -EIO;
@@ -319,7 +296,7 @@
 	return 0;
 }
 
-int probe_maui(struct address_info *hw_config)
+static int __init probe_maui(struct address_info *hw_config)
 {
 	int i;
 	int tmp1, tmp2, ret;
@@ -337,55 +314,46 @@
 	 * Initialize the processor if necessary
 	 */
 
-	if (maui_osLen > 0)
-	{
+	if (maui_osLen > 0) {
 		if (!(inb(HOST_STAT_PORT) & STAT_TX_AVAIL) ||
 			!maui_write(0x9F) ||	/* Report firmware version */
 			!maui_short_wait(STAT_RX_AVAIL) ||
 			maui_read() == -1 || maui_read() == -1)
-			if (!maui_init(hw_config->irq))
-			{
+			if (!maui_init(hw_config->irq)) {
 				free_irq(hw_config->irq, NULL);
 				return 0;
 			}
 	}
-	if (!maui_write(0xCF))	/* Report hardware version */
-	{
+	if (!maui_write(0xCF))	/* Report hardware version */ {
 		printk(KERN_ERR "No WaveFront firmware detected (card uninitialized?)\n");
 		free_irq(hw_config->irq, NULL);
 		return 0;
 	}
-	if ((tmp1 = maui_read()) == -1 || (tmp2 = maui_read()) == -1)
-	{
+	if ((tmp1 = maui_read()) == -1 || (tmp2 = maui_read()) == -1) {
 		printk(KERN_ERR "No WaveFront firmware detected (card uninitialized?)\n");
 		free_irq(hw_config->irq, NULL);
 		return 0;
 	}
-	if (tmp1 == 0xff || tmp2 == 0xff)
-	{
+	if (tmp1 == 0xff || tmp2 == 0xff) {
 		free_irq(hw_config->irq, NULL);
 		return 0;
 	}
-	if (trace_init)
-		printk(KERN_DEBUG "WaveFront hardware version %d.%d\n", tmp1, tmp2);
+	printk(KERN_DEBUG "WaveFront hardware version %d.%d\n", tmp1, tmp2);
 
 	if (!maui_write(0x9F))	/* Report firmware version */
 		return 0;
 	if ((tmp1 = maui_read()) == -1 || (tmp2 = maui_read()) == -1)
 		return 0;
 
-	if (trace_init)
-		printk(KERN_DEBUG "WaveFront firmware version %d.%d\n", tmp1, tmp2);
+	printk(KERN_DEBUG "WaveFront firmware version %d.%d\n", tmp1, tmp2);
 
 	if (!maui_write(0x85))	/* Report free DRAM */
 		return 0;
 	tmp1 = 0;
-	for (i = 0; i < 4; i++)
-	{
+	for (i = 0; i < 4; i++) {
 		tmp1 |= maui_read() << (7 * i);
 	}
-	if (trace_init)
-		printk(KERN_DEBUG "Available DRAM %dk\n", tmp1 / 1024);
+	printk(KERN_DEBUG "Available DRAM %dk\n", tmp1 / 1024);
 
 	for (i = 0; i < 1000; i++)
 		if (probe_mpu401(hw_config))
@@ -399,7 +367,7 @@
 	return ret;
 }
 
-void attach_maui(struct address_info *hw_config)
+static void __init attach_maui(struct address_info *hw_config)
 {
 	int this_dev;
 
@@ -409,8 +377,7 @@
 	hw_config->name = "Maui";
 	attach_mpu401(hw_config);
 
-	if (hw_config->slots[1] != -1)	/* The MPU401 driver installed itself */
-	{
+	if (hw_config->slots[1] != -1)	/* The MPU401 driver installed itself */ {
 		struct synth_operations *synth;
 
 		this_dev = hw_config->slots[1];
@@ -423,17 +390,15 @@
 		synth = midi_devs[this_dev]->converter;
 		synth->id = "MAUI";
 
-		if (synth != NULL)
-		{
+		if (synth != NULL) {
 			orig_load_patch = synth->load_patch;
 			synth->load_patch = &maui_load_patch;
-		}
-		else
+		} else
 			printk(KERN_ERR "Maui: Can't install patch loader\n");
 	}
 }
 
-void unload_maui(struct address_info *hw_config)
+static void __exit unload_maui(struct address_info *hw_config)
 {
 	int irq = hw_config->irq;
 	release_region(hw_config->io_base + 2, 6);
@@ -445,37 +410,33 @@
 		free_irq(irq, NULL);
 }
 
-#ifdef MODULE
-
-MODULE_PARM(io,"i");
-MODULE_PARM(irq,"i");
-
-EXPORT_NO_SYMBOLS;
+static int fw_load = 0;
 
-int io = -1;
-int irq = -1;
+static struct address_info cfg;
 
-static int fw_load = 0;
+static int __initdata io = -1;
+static int __initdata irq = -1;
 
-struct address_info cfg;
+MODULE_PARM(io,"i");
+MODULE_PARM(irq,"i");
 
 /*
  *	Install a Maui card. Needs mpu401 loaded already.
  */
 
-int init_module(void)
+static int __init init_maui(void)
 {
 	printk(KERN_INFO "Turtle beach Maui and Tropez driver, Copyright (C) by Hannu Savolainen 1993-1996\n");
-	if (io == -1 || irq == -1)
-	{
+
+	cfg.io_base = io;
+	cfg.irq = irq;
+
+	if (cfg.io_base == -1 || cfg.irq == -1) {
 		printk(KERN_INFO "maui: irq and io must be set.\n");
 		return -EINVAL;
 	}
-	cfg.io_base = io;
-	cfg.irq = irq;
 
-	if (maui_os == NULL)
-	{
+	if (maui_os == NULL) {
 		fw_load = 1;
 		maui_osLen = mod_firmware_load("/etc/sound/oswf.mot", (char **) &maui_os);
 	}
@@ -486,11 +447,30 @@
 	return 0;
 }
 
-void cleanup_module(void)
+static void __exit cleanup_maui(void)
 {
 	if (fw_load && maui_os)
 		vfree(maui_os);
 	unload_maui(&cfg);
 	SOUND_LOCK_END;
 }
-#endif /* MODULE */
+
+module_init(init_maui);
+module_exit(cleanup_maui);
+
+#ifndef MODULE
+static int __init setup_maui(char *str)
+{
+        /* io, irq */
+	int ints[3];
+	
+	str = get_options(str, ARRAY_SIZE(ints), ints);
+	
+	io = ints[1];
+	irq = ints[2];
+
+	return 1;
+}
+
+__setup("maui=", setup_maui);
+#endif

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)