| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  *  Driver for AMD InterWave soundcard | 
| Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 3 |  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 |  * | 
 | 5 |  * | 
 | 6 |  *   This program is free software; you can redistribute it and/or modify | 
 | 7 |  *   it under the terms of the GNU General Public License as published by | 
 | 8 |  *   the Free Software Foundation; either version 2 of the License, or | 
 | 9 |  *   (at your option) any later version. | 
 | 10 |  * | 
 | 11 |  *   This program is distributed in the hope that it will be useful, | 
 | 12 |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 13 |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 14 |  *   GNU General Public License for more details. | 
 | 15 |  * | 
 | 16 |  *   You should have received a copy of the GNU General Public License | 
 | 17 |  *   along with this program; if not, write to the Free Software | 
 | 18 |  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA | 
 | 19 |  * | 
 | 20 |  *   1999/07/22		Erik Inge Bolso <knan@mo.himolde.no> | 
 | 21 |  *			* mixer group handlers | 
 | 22 |  * | 
 | 23 |  */ | 
 | 24 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/init.h> | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 26 | #include <linux/err.h> | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 27 | #include <linux/isa.h> | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 28 | #include <linux/delay.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/pnp.h> | 
| Paul Gortmaker | 65a7721 | 2011-07-15 13:13:37 -0400 | [diff] [blame] | 30 | #include <linux/module.h> | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 31 | #include <asm/dma.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <sound/core.h> | 
 | 33 | #include <sound/gus.h> | 
| Krzysztof Helt | 61ef19d | 2008-07-31 21:02:42 +0200 | [diff] [blame] | 34 | #include <sound/wss.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #ifdef SNDRV_STB | 
 | 36 | #include <sound/tea6330t.h> | 
 | 37 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #define SNDRV_LEGACY_FIND_FREE_IRQ | 
 | 39 | #define SNDRV_LEGACY_FIND_FREE_DMA | 
 | 40 | #include <sound/initval.h> | 
 | 41 |  | 
| Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 42 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | MODULE_LICENSE("GPL"); | 
 | 44 | #ifndef SNDRV_STB | 
 | 45 | MODULE_DESCRIPTION("AMD InterWave"); | 
 | 46 | MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Plug & Play}," | 
 | 47 | 		"{STB,SoundRage32}," | 
 | 48 | 		"{MED,MED3210}," | 
 | 49 | 		"{Dynasonix,Dynasonix Pro}," | 
 | 50 | 		"{Panasonic,PCA761AW}}"); | 
 | 51 | #else | 
 | 52 | MODULE_DESCRIPTION("AMD InterWave STB with TEA6330T"); | 
 | 53 | MODULE_SUPPORTED_DEVICE("{{AMD,InterWave STB with TEA6330T}}"); | 
 | 54 | #endif | 
 | 55 |  | 
 | 56 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */ | 
 | 57 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */ | 
| Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 58 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #ifdef CONFIG_PNP | 
| Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 60 | static bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #endif | 
 | 62 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* 0x210,0x220,0x230,0x240,0x250,0x260 */ | 
 | 63 | #ifdef SNDRV_STB | 
 | 64 | static long port_tc[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* 0x350,0x360,0x370,0x380 */ | 
 | 65 | #endif | 
 | 66 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;	/* 2,3,5,9,11,12,15 */ | 
 | 67 | static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;	/* 0,1,3,5,6,7 */ | 
 | 68 | static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;	/* 0,1,3,5,6,7 */ | 
 | 69 | static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29}; | 
 | 70 | 				/* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */ | 
| Takashi Iwai | 6581f4e | 2006-05-17 17:14:51 +0200 | [diff] [blame] | 71 | static int midi[SNDRV_CARDS]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; | 
| Takashi Iwai | 6581f4e | 2006-05-17 17:14:51 +0200 | [diff] [blame] | 73 | static int effect[SNDRV_CARDS]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 |  | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 75 | #ifdef SNDRV_STB | 
 | 76 | #define PFX "interwave-stb: " | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 77 | #define INTERWAVE_DRIVER	"snd_interwave_stb" | 
 | 78 | #define INTERWAVE_PNP_DRIVER	"interwave-stb" | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 79 | #else | 
 | 80 | #define PFX "interwave: " | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 81 | #define INTERWAVE_DRIVER	"snd_interwave" | 
 | 82 | #define INTERWAVE_PNP_DRIVER	"interwave" | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 83 | #endif | 
 | 84 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | module_param_array(index, int, NULL, 0444); | 
 | 86 | MODULE_PARM_DESC(index, "Index value for InterWave soundcard."); | 
 | 87 | module_param_array(id, charp, NULL, 0444); | 
 | 88 | MODULE_PARM_DESC(id, "ID string for InterWave soundcard."); | 
 | 89 | module_param_array(enable, bool, NULL, 0444); | 
 | 90 | MODULE_PARM_DESC(enable, "Enable InterWave soundcard."); | 
 | 91 | #ifdef CONFIG_PNP | 
 | 92 | module_param_array(isapnp, bool, NULL, 0444); | 
 | 93 | MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard."); | 
 | 94 | #endif | 
 | 95 | module_param_array(port, long, NULL, 0444); | 
 | 96 | MODULE_PARM_DESC(port, "Port # for InterWave driver."); | 
 | 97 | #ifdef SNDRV_STB | 
 | 98 | module_param_array(port_tc, long, NULL, 0444); | 
 | 99 | MODULE_PARM_DESC(port_tc, "Tone control (TEA6330T - i2c bus) port # for InterWave driver."); | 
 | 100 | #endif | 
 | 101 | module_param_array(irq, int, NULL, 0444); | 
 | 102 | MODULE_PARM_DESC(irq, "IRQ # for InterWave driver."); | 
 | 103 | module_param_array(dma1, int, NULL, 0444); | 
 | 104 | MODULE_PARM_DESC(dma1, "DMA1 # for InterWave driver."); | 
 | 105 | module_param_array(dma2, int, NULL, 0444); | 
 | 106 | MODULE_PARM_DESC(dma2, "DMA2 # for InterWave driver."); | 
 | 107 | module_param_array(joystick_dac, int, NULL, 0444); | 
 | 108 | MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for InterWave driver."); | 
 | 109 | module_param_array(midi, int, NULL, 0444); | 
 | 110 | MODULE_PARM_DESC(midi, "MIDI UART enable for InterWave driver."); | 
 | 111 | module_param_array(pcm_channels, int, NULL, 0444); | 
 | 112 | MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for InterWave driver."); | 
 | 113 | module_param_array(effect, int, NULL, 0444); | 
 | 114 | MODULE_PARM_DESC(effect, "Effects enable for InterWave driver."); | 
 | 115 |  | 
 | 116 | struct snd_interwave { | 
 | 117 | 	int irq; | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 118 | 	struct snd_card *card; | 
 | 119 | 	struct snd_gus_card *gus; | 
| Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 120 | 	struct snd_wss *wss; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | #ifdef SNDRV_STB | 
 | 122 | 	struct resource *i2c_res; | 
 | 123 | #endif | 
 | 124 | 	unsigned short gus_status_reg; | 
 | 125 | 	unsigned short pcm_status_reg; | 
 | 126 | #ifdef CONFIG_PNP | 
 | 127 | 	struct pnp_dev *dev; | 
 | 128 | #ifdef SNDRV_STB | 
 | 129 | 	struct pnp_dev *devtc; | 
 | 130 | #endif | 
 | 131 | #endif | 
 | 132 | }; | 
 | 133 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 |  | 
 | 135 | #ifdef CONFIG_PNP | 
| Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 136 | static int isa_registered; | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 137 | static int pnp_registered; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 |  | 
 | 139 | static struct pnp_card_device_id snd_interwave_pnpids[] = { | 
 | 140 | #ifndef SNDRV_STB | 
 | 141 | 	/* Gravis UltraSound Plug & Play */ | 
 | 142 | 	{ .id = "GRV0001", .devs = { { .id = "GRV0000" } } }, | 
 | 143 | 	/* STB SoundRage32 */ | 
 | 144 | 	{ .id = "STB011a", .devs = { { .id = "STB0010" } } }, | 
 | 145 | 	/* MED3210 */ | 
 | 146 | 	{ .id = "DXP3201", .devs = { { .id = "DXP0010" } } }, | 
 | 147 | 	/* Dynasonic Pro */ | 
 | 148 | 	/* This device also have CDC1117:DynaSonix Pro Audio Effects Processor */ | 
 | 149 | 	{ .id = "CDC1111", .devs = { { .id = "CDC1112" } } }, | 
 | 150 | 	/* Panasonic PCA761AW Audio Card */ | 
 | 151 | 	{ .id = "ADV55ff", .devs = { { .id = "ADV0010" } } }, | 
 | 152 | 	/* InterWave STB without TEA6330T */ | 
 | 153 | 	{ .id = "ADV550a", .devs = { { .id = "ADV0010" } } }, | 
 | 154 | #else | 
 | 155 | 	/* InterWave STB with TEA6330T */ | 
 | 156 | 	{ .id = "ADV550a", .devs = { { .id = "ADV0010" }, { .id = "ADV0015" } } }, | 
 | 157 | #endif | 
 | 158 | 	{ .id = "" } | 
 | 159 | }; | 
 | 160 |  | 
 | 161 | MODULE_DEVICE_TABLE(pnp_card, snd_interwave_pnpids); | 
 | 162 |  | 
 | 163 | #endif /* CONFIG_PNP */ | 
 | 164 |  | 
 | 165 |  | 
 | 166 | #ifdef SNDRV_STB | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 167 | static void snd_interwave_i2c_setlines(struct snd_i2c_bus *bus, int ctrl, int data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | { | 
 | 169 | 	unsigned long port = bus->private_value; | 
 | 170 |  | 
 | 171 | #if 0 | 
| Takashi Iwai | 91f0506 | 2009-02-05 15:46:48 +0100 | [diff] [blame] | 172 | 	printk(KERN_DEBUG "i2c_setlines - 0x%lx <- %i,%i\n", port, ctrl, data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | #endif | 
 | 174 | 	outb((data << 1) | ctrl, port); | 
 | 175 | 	udelay(10); | 
 | 176 | } | 
 | 177 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 178 | static int snd_interwave_i2c_getclockline(struct snd_i2c_bus *bus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | { | 
 | 180 | 	unsigned long port = bus->private_value; | 
 | 181 | 	unsigned char res; | 
 | 182 |  | 
 | 183 | 	res = inb(port) & 1; | 
 | 184 | #if 0 | 
| Takashi Iwai | 91f0506 | 2009-02-05 15:46:48 +0100 | [diff] [blame] | 185 | 	printk(KERN_DEBUG "i2c_getclockline - 0x%lx -> %i\n", port, res); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | #endif | 
 | 187 | 	return res; | 
 | 188 | } | 
 | 189 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 190 | static int snd_interwave_i2c_getdataline(struct snd_i2c_bus *bus, int ack) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { | 
 | 192 | 	unsigned long port = bus->private_value; | 
 | 193 | 	unsigned char res; | 
 | 194 |  | 
 | 195 | 	if (ack) | 
 | 196 | 		udelay(10); | 
 | 197 | 	res = (inb(port) & 2) >> 1; | 
 | 198 | #if 0 | 
| Takashi Iwai | 91f0506 | 2009-02-05 15:46:48 +0100 | [diff] [blame] | 199 | 	printk(KERN_DEBUG "i2c_getdataline - 0x%lx -> %i\n", port, res); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | #endif | 
 | 201 | 	return res; | 
 | 202 | } | 
 | 203 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 204 | static struct snd_i2c_bit_ops snd_interwave_i2c_bit_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | 	.setlines = snd_interwave_i2c_setlines, | 
 | 206 | 	.getclock = snd_interwave_i2c_getclockline, | 
 | 207 | 	.getdata  = snd_interwave_i2c_getdataline, | 
 | 208 | }; | 
 | 209 |  | 
 | 210 | static int __devinit snd_interwave_detect_stb(struct snd_interwave *iwcard, | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 211 | 					      struct snd_gus_card * gus, int dev, | 
 | 212 | 					      struct snd_i2c_bus **rbus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { | 
 | 214 | 	unsigned long port; | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 215 | 	struct snd_i2c_bus *bus; | 
 | 216 | 	struct snd_card *card = iwcard->card; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | 	char name[32]; | 
 | 218 | 	int err; | 
 | 219 |  | 
 | 220 | 	*rbus = NULL; | 
 | 221 | 	port = port_tc[dev]; | 
 | 222 | 	if (port == SNDRV_AUTO_PORT) { | 
 | 223 | 		port = 0x350; | 
 | 224 | 		if (gus->gf1.port == 0x250) { | 
 | 225 | 			port = 0x360; | 
 | 226 | 		} | 
 | 227 | 		while (port <= 0x380) { | 
 | 228 | 			if ((iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)")) != NULL) | 
 | 229 | 				break; | 
 | 230 | 			port += 0x10; | 
 | 231 | 		} | 
 | 232 | 	} else { | 
 | 233 | 		iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)"); | 
 | 234 | 	} | 
 | 235 | 	if (iwcard->i2c_res == NULL) { | 
 | 236 | 		snd_printk(KERN_ERR "interwave: can't grab i2c bus port\n"); | 
 | 237 | 		return -ENODEV; | 
 | 238 | 	} | 
 | 239 |  | 
 | 240 | 	sprintf(name, "InterWave-%i", card->number); | 
 | 241 | 	if ((err = snd_i2c_bus_create(card, name, NULL, &bus)) < 0) | 
 | 242 | 		return err; | 
 | 243 | 	bus->private_value = port; | 
 | 244 | 	bus->hw_ops.bit = &snd_interwave_i2c_bit_ops; | 
 | 245 | 	if ((err = snd_tea6330t_detect(bus, 0)) < 0) | 
 | 246 | 		return err; | 
 | 247 | 	*rbus = bus; | 
 | 248 | 	return 0; | 
 | 249 | } | 
 | 250 | #endif | 
 | 251 |  | 
 | 252 | static int __devinit snd_interwave_detect(struct snd_interwave *iwcard, | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 253 | 				          struct snd_gus_card * gus, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | 				          int dev | 
 | 255 | #ifdef SNDRV_STB | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 256 | 				          , struct snd_i2c_bus **rbus | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | #endif | 
 | 258 | 				          ) | 
 | 259 | { | 
 | 260 | 	unsigned long flags; | 
 | 261 | 	unsigned char rev1, rev2; | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 262 | 	int d; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 |  | 
 | 264 | 	snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0);	/* reset GF1 */ | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 265 | 	if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) { | 
 | 266 | 		snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | 		return -ENODEV; | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 268 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | 	udelay(160); | 
 | 270 | 	snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1);	/* release reset */ | 
 | 271 | 	udelay(160); | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 272 | 	if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) { | 
 | 273 | 		snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | 		return -ENODEV; | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 275 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | 	spin_lock_irqsave(&gus->reg_lock, flags); | 
 | 277 | 	rev1 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER); | 
 | 278 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, ~rev1); | 
 | 279 | 	rev2 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER); | 
 | 280 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, rev1); | 
 | 281 | 	spin_unlock_irqrestore(&gus->reg_lock, flags); | 
 | 282 | 	snd_printdd("[0x%lx] InterWave check - rev1=0x%x, rev2=0x%x\n", gus->gf1.port, rev1, rev2); | 
 | 283 | 	if ((rev1 & 0xf0) == (rev2 & 0xf0) && | 
 | 284 | 	    (rev1 & 0x0f) != (rev2 & 0x0f)) { | 
 | 285 | 		snd_printdd("[0x%lx] InterWave check - passed\n", gus->gf1.port); | 
 | 286 | 		gus->interwave = 1; | 
 | 287 | 		strcpy(gus->card->shortname, "AMD InterWave"); | 
 | 288 | 		gus->revision = rev1 >> 4; | 
 | 289 | #ifndef SNDRV_STB | 
 | 290 | 		return 0;	/* ok.. We have an InterWave board */ | 
 | 291 | #else | 
 | 292 | 		return snd_interwave_detect_stb(iwcard, gus, dev, rbus); | 
 | 293 | #endif | 
 | 294 | 	} | 
 | 295 | 	snd_printdd("[0x%lx] InterWave check - failed\n", gus->gf1.port); | 
 | 296 | 	return -ENODEV; | 
 | 297 | } | 
 | 298 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 299 | static irqreturn_t snd_interwave_interrupt(int irq, void *dev_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { | 
| Jeff Garzik | c7bec5a | 2006-10-06 15:00:58 -0400 | [diff] [blame] | 301 | 	struct snd_interwave *iwcard = dev_id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | 	int loop, max = 5; | 
 | 303 | 	int handled = 0; | 
 | 304 |  | 
 | 305 | 	do { | 
 | 306 | 		loop = 0; | 
 | 307 | 		if (inb(iwcard->gus_status_reg)) { | 
 | 308 | 			handled = 1; | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 309 | 			snd_gus_interrupt(irq, iwcard->gus); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | 			loop++; | 
 | 311 | 		} | 
 | 312 | 		if (inb(iwcard->pcm_status_reg) & 0x01) {	/* IRQ bit is set? */ | 
 | 313 | 			handled = 1; | 
| Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 314 | 			snd_wss_interrupt(irq, iwcard->wss); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | 			loop++; | 
 | 316 | 		} | 
 | 317 | 	} while (loop && --max > 0); | 
 | 318 | 	return IRQ_RETVAL(handled); | 
 | 319 | } | 
 | 320 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 321 | static void __devinit snd_interwave_reset(struct snd_gus_card * gus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { | 
 | 323 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x00); | 
 | 324 | 	udelay(160); | 
 | 325 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x01); | 
 | 326 | 	udelay(160); | 
 | 327 | } | 
 | 328 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 329 | static void __devinit snd_interwave_bank_sizes(struct snd_gus_card * gus, int *sizes) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | { | 
 | 331 | 	unsigned int idx; | 
 | 332 | 	unsigned int local; | 
 | 333 | 	unsigned char d; | 
 | 334 |  | 
 | 335 | 	for (idx = 0; idx < 4; idx++) { | 
 | 336 | 		sizes[idx] = 0; | 
 | 337 | 		d = 0x55; | 
 | 338 | 		for (local = idx << 22; | 
 | 339 | 		     local < (idx << 22) + 0x400000; | 
 | 340 | 		     local += 0x40000, d++) { | 
 | 341 | 			snd_gf1_poke(gus, local, d); | 
 | 342 | 			snd_gf1_poke(gus, local + 1, d + 1); | 
 | 343 | #if 0 | 
| Takashi Iwai | 91f0506 | 2009-02-05 15:46:48 +0100 | [diff] [blame] | 344 | 			printk(KERN_DEBUG "d = 0x%x, local = 0x%x, " | 
 | 345 | 			       "local + 1 = 0x%x, idx << 22 = 0x%x\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | 			       d, | 
 | 347 | 			       snd_gf1_peek(gus, local), | 
 | 348 | 			       snd_gf1_peek(gus, local + 1), | 
 | 349 | 			       snd_gf1_peek(gus, idx << 22)); | 
 | 350 | #endif | 
 | 351 | 			if (snd_gf1_peek(gus, local) != d || | 
 | 352 | 			    snd_gf1_peek(gus, local + 1) != d + 1 || | 
 | 353 | 			    snd_gf1_peek(gus, idx << 22) != 0x55) | 
 | 354 | 				break; | 
 | 355 | 			sizes[idx]++; | 
 | 356 | 		} | 
 | 357 | 	} | 
 | 358 | #if 0 | 
| Takashi Iwai | 91f0506 | 2009-02-05 15:46:48 +0100 | [diff] [blame] | 359 | 	printk(KERN_DEBUG "sizes: %i %i %i %i\n", | 
 | 360 | 	       sizes[0], sizes[1], sizes[2], sizes[3]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | #endif | 
 | 362 | } | 
 | 363 |  | 
 | 364 | struct rom_hdr { | 
 | 365 | 	/* 000 */ unsigned char iwave[8]; | 
 | 366 | 	/* 008 */ unsigned char rom_hdr_revision; | 
 | 367 | 	/* 009 */ unsigned char series_number; | 
 | 368 | 	/* 010 */ unsigned char series_name[16]; | 
 | 369 | 	/* 026 */ unsigned char date[10]; | 
 | 370 | 	/* 036 */ unsigned short vendor_revision_major; | 
 | 371 | 	/* 038 */ unsigned short vendor_revision_minor; | 
 | 372 | 	/* 040 */ unsigned int rom_size; | 
 | 373 | 	/* 044 */ unsigned char copyright[128]; | 
 | 374 | 	/* 172 */ unsigned char vendor_name[64]; | 
 | 375 | 	/* 236 */ unsigned char rom_description[128]; | 
 | 376 | 	/* 364 */ unsigned char pad[147]; | 
 | 377 | 	/* 511 */ unsigned char csum; | 
 | 378 | }; | 
 | 379 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 380 | static void __devinit snd_interwave_detect_memory(struct snd_gus_card * gus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { | 
 | 382 | 	static unsigned int lmc[13] = | 
 | 383 | 	{ | 
 | 384 | 		0x00000001, 0x00000101, 0x01010101, 0x00000401, | 
 | 385 | 		0x04040401, 0x00040101, 0x04040101, 0x00000004, | 
 | 386 | 		0x00000404, 0x04040404, 0x00000010, 0x00001010, | 
 | 387 | 		0x10101010 | 
 | 388 | 	}; | 
 | 389 |  | 
 | 390 | 	int bank_pos, pages; | 
 | 391 | 	unsigned int i, lmct; | 
 | 392 | 	int psizes[4]; | 
 | 393 | 	unsigned char iwave[8]; | 
 | 394 | 	unsigned char csum; | 
 | 395 |  | 
 | 396 | 	snd_interwave_reset(gus); | 
 | 397 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_GLOBAL_MODE, snd_gf1_read8(gus, SNDRV_GF1_GB_GLOBAL_MODE) | 0x01);		/* enhanced mode */ | 
 | 398 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01);	/* DRAM I/O cycles selected */ | 
 | 399 | 	snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff10) | 0x004c); | 
 | 400 | 	/* ok.. simple test of memory size */ | 
 | 401 | 	pages = 0; | 
 | 402 | 	snd_gf1_poke(gus, 0, 0x55); | 
 | 403 | 	snd_gf1_poke(gus, 1, 0xaa); | 
 | 404 | #if 1 | 
 | 405 | 	if (snd_gf1_peek(gus, 0) == 0x55 && snd_gf1_peek(gus, 1) == 0xaa) | 
 | 406 | #else | 
 | 407 | 	if (0)			/* ok.. for testing of 0k RAM */ | 
 | 408 | #endif | 
 | 409 | 	{ | 
 | 410 | 		snd_interwave_bank_sizes(gus, psizes); | 
 | 411 | 		lmct = (psizes[3] << 24) | (psizes[2] << 16) | | 
 | 412 | 		    (psizes[1] << 8) | psizes[0]; | 
 | 413 | #if 0 | 
| Takashi Iwai | 91f0506 | 2009-02-05 15:46:48 +0100 | [diff] [blame] | 414 | 		printk(KERN_DEBUG "lmct = 0x%08x\n", lmct); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | #endif | 
 | 416 | 		for (i = 0; i < ARRAY_SIZE(lmc); i++) | 
 | 417 | 			if (lmct == lmc[i]) { | 
 | 418 | #if 0 | 
| Takashi Iwai | 91f0506 | 2009-02-05 15:46:48 +0100 | [diff] [blame] | 419 | 				printk(KERN_DEBUG "found !!! %i\n", i); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | #endif | 
 | 421 | 				snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | i); | 
 | 422 | 				snd_interwave_bank_sizes(gus, psizes); | 
 | 423 | 				break; | 
 | 424 | 			} | 
 | 425 | 		if (i >= ARRAY_SIZE(lmc) && !gus->gf1.enh_mode) | 
 | 426 | 			 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | 2); | 
 | 427 | 		for (i = 0; i < 4; i++) { | 
 | 428 | 			gus->gf1.mem_alloc.banks_8[i].address = | 
 | 429 | 			    gus->gf1.mem_alloc.banks_16[i].address = i << 22; | 
 | 430 | 			gus->gf1.mem_alloc.banks_8[i].size = | 
 | 431 | 			    gus->gf1.mem_alloc.banks_16[i].size = psizes[i] << 18; | 
 | 432 | 			pages += psizes[i]; | 
 | 433 | 		} | 
 | 434 | 	} | 
 | 435 | 	pages <<= 18; | 
 | 436 | 	gus->gf1.memory = pages; | 
 | 437 |  | 
 | 438 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x03);	/* select ROM */ | 
 | 439 | 	snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff1f) | (4 << 5)); | 
 | 440 | 	gus->gf1.rom_banks = 0; | 
 | 441 | 	gus->gf1.rom_memory = 0; | 
 | 442 | 	for (bank_pos = 0; bank_pos < 16L * 1024L * 1024L; bank_pos += 4L * 1024L * 1024L) { | 
 | 443 | 		for (i = 0; i < 8; ++i) | 
 | 444 | 			iwave[i] = snd_gf1_peek(gus, bank_pos + i); | 
 | 445 | #ifdef CONFIG_SND_DEBUG_ROM | 
| Andy Shevchenko | 793ea49 | 2012-08-02 16:52:41 +0300 | [diff] [blame] | 446 | 		printk(KERN_DEBUG "ROM at 0x%06x = %*phC\n", bank_pos, | 
 | 447 | 				  8, iwave); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | #endif | 
 | 449 | 		if (strncmp(iwave, "INTRWAVE", 8)) | 
 | 450 | 			continue;	/* first check */ | 
 | 451 | 		csum = 0; | 
 | 452 | 		for (i = 0; i < sizeof(struct rom_hdr); i++) | 
 | 453 | 			csum += snd_gf1_peek(gus, bank_pos + i); | 
 | 454 | #ifdef CONFIG_SND_DEBUG_ROM | 
| Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 455 | 		printk(KERN_DEBUG "ROM checksum = 0x%x (computed)\n", csum); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | #endif | 
 | 457 | 		if (csum != 0) | 
 | 458 | 			continue;	/* not valid rom */ | 
 | 459 | 		gus->gf1.rom_banks++; | 
 | 460 | 		gus->gf1.rom_present |= 1 << (bank_pos >> 22); | 
 | 461 | 		gus->gf1.rom_memory = snd_gf1_peek(gus, bank_pos + 40) | | 
 | 462 | 				     (snd_gf1_peek(gus, bank_pos + 41) << 8) | | 
 | 463 | 				     (snd_gf1_peek(gus, bank_pos + 42) << 16) | | 
 | 464 | 				     (snd_gf1_peek(gus, bank_pos + 43) << 24); | 
 | 465 | 	} | 
 | 466 | #if 0 | 
 | 467 | 	if (gus->gf1.rom_memory > 0) { | 
 | 468 | 		if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8) | 
 | 469 | 			gus->card->type = SNDRV_CARD_TYPE_IW_DYNASONIC; | 
 | 470 | 	} | 
 | 471 | #endif | 
 | 472 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x00);	/* select RAM */ | 
 | 473 |  | 
 | 474 | 	if (!gus->gf1.enh_mode) | 
 | 475 | 		snd_interwave_reset(gus); | 
 | 476 | } | 
 | 477 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 478 | static void __devinit snd_interwave_init(int dev, struct snd_gus_card * gus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { | 
 | 480 | 	unsigned long flags; | 
 | 481 |  | 
 | 482 | 	/* ok.. some InterWave specific initialization */ | 
 | 483 | 	spin_lock_irqsave(&gus->reg_lock, flags); | 
 | 484 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, 0x00); | 
 | 485 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_COMPATIBILITY, 0x1f); | 
 | 486 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_DECODE_CONTROL, 0x49); | 
 | 487 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, 0x11); | 
 | 488 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_A, 0x00); | 
 | 489 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_B, 0x30); | 
 | 490 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_EMULATION_IRQ, 0x00); | 
 | 491 | 	spin_unlock_irqrestore(&gus->reg_lock, flags); | 
 | 492 | 	gus->equal_irq = 1; | 
 | 493 | 	gus->codec_flag = 1; | 
 | 494 | 	gus->interwave = 1; | 
 | 495 | 	gus->max_flag = 1; | 
 | 496 | 	gus->joystick_dac = joystick_dac[dev]; | 
 | 497 |  | 
 | 498 | } | 
 | 499 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 500 | static struct snd_kcontrol_new snd_interwave_controls[] = { | 
| Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 501 | WSS_DOUBLE("Master Playback Switch", 0, | 
 | 502 | 		CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 7, 7, 1, 1), | 
 | 503 | WSS_DOUBLE("Master Playback Volume", 0, | 
 | 504 | 		CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 0, 0, 31, 1), | 
 | 505 | WSS_DOUBLE("Mic Playback Switch", 0, | 
 | 506 | 		CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 7, 7, 1, 1), | 
 | 507 | WSS_DOUBLE("Mic Playback Volume", 0, | 
 | 508 | 		CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 0, 0, 31, 1) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | }; | 
 | 510 |  | 
| Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 511 | static int __devinit snd_interwave_mixer(struct snd_wss *chip) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | { | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 513 | 	struct snd_card *card = chip->card; | 
 | 514 | 	struct snd_ctl_elem_id id1, id2; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | 	unsigned int idx; | 
 | 516 | 	int err; | 
 | 517 |  | 
 | 518 | 	memset(&id1, 0, sizeof(id1)); | 
 | 519 | 	memset(&id2, 0, sizeof(id2)); | 
 | 520 | 	id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | 
 | 521 | #if 0 | 
 | 522 | 	/* remove mono microphone controls */ | 
 | 523 | 	strcpy(id1.name, "Mic Playback Switch"); | 
 | 524 | 	if ((err = snd_ctl_remove_id(card, &id1)) < 0) | 
 | 525 | 		return err; | 
 | 526 | 	strcpy(id1.name, "Mic Playback Volume"); | 
 | 527 | 	if ((err = snd_ctl_remove_id(card, &id1)) < 0) | 
 | 528 | 		return err; | 
 | 529 | #endif | 
 | 530 | 	/* add new master and mic controls */ | 
 | 531 | 	for (idx = 0; idx < ARRAY_SIZE(snd_interwave_controls); idx++) | 
 | 532 | 		if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_interwave_controls[idx], chip))) < 0) | 
 | 533 | 			return err; | 
| Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 534 | 	snd_wss_out(chip, CS4231_LINE_LEFT_OUTPUT, 0x9f); | 
 | 535 | 	snd_wss_out(chip, CS4231_LINE_RIGHT_OUTPUT, 0x9f); | 
 | 536 | 	snd_wss_out(chip, CS4231_LEFT_MIC_INPUT, 0x9f); | 
 | 537 | 	snd_wss_out(chip, CS4231_RIGHT_MIC_INPUT, 0x9f); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | 	/* reassign AUXA to SYNTHESIZER */ | 
 | 539 | 	strcpy(id1.name, "Aux Playback Switch"); | 
 | 540 | 	strcpy(id2.name, "Synth Playback Switch"); | 
 | 541 | 	if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) | 
 | 542 | 		return err; | 
 | 543 | 	strcpy(id1.name, "Aux Playback Volume"); | 
 | 544 | 	strcpy(id2.name, "Synth Playback Volume"); | 
 | 545 | 	if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) | 
 | 546 | 		return err; | 
 | 547 | 	/* reassign AUXB to CD */ | 
 | 548 | 	strcpy(id1.name, "Aux Playback Switch"); id1.index = 1; | 
 | 549 | 	strcpy(id2.name, "CD Playback Switch"); | 
 | 550 | 	if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) | 
 | 551 | 		return err; | 
 | 552 | 	strcpy(id1.name, "Aux Playback Volume"); | 
 | 553 | 	strcpy(id2.name, "CD Playback Volume"); | 
 | 554 | 	if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) | 
 | 555 | 		return err; | 
 | 556 | 	return 0; | 
 | 557 | } | 
 | 558 |  | 
 | 559 | #ifdef CONFIG_PNP | 
 | 560 |  | 
 | 561 | static int __devinit snd_interwave_pnp(int dev, struct snd_interwave *iwcard, | 
 | 562 | 				       struct pnp_card_link *card, | 
 | 563 | 				       const struct pnp_card_device_id *id) | 
 | 564 | { | 
 | 565 | 	struct pnp_dev *pdev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | 	int err; | 
 | 567 |  | 
 | 568 | 	iwcard->dev = pnp_request_card_device(card, id->devs[0].id, NULL); | 
| Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 569 | 	if (iwcard->dev == NULL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | 		return -EBUSY; | 
| Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 571 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | #ifdef SNDRV_STB | 
 | 573 | 	iwcard->devtc = pnp_request_card_device(card, id->devs[1].id, NULL); | 
| Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 574 | 	if (iwcard->devtc == NULL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | 		return -EBUSY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | #endif | 
 | 577 | 	/* Synth & Codec initialization */ | 
 | 578 | 	pdev = iwcard->dev; | 
| Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 579 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | 	err = pnp_activate_dev(pdev); | 
 | 581 | 	if (err < 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | 		snd_printk(KERN_ERR "InterWave PnP configure failure (out of resources?)\n"); | 
 | 583 | 		return err; | 
 | 584 | 	} | 
 | 585 | 	if (pnp_port_start(pdev, 0) + 0x100 != pnp_port_start(pdev, 1) || | 
 | 586 | 	    pnp_port_start(pdev, 0) + 0x10c != pnp_port_start(pdev, 2)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | 		snd_printk(KERN_ERR "PnP configure failure (wrong ports)\n"); | 
 | 588 | 		return -ENOENT; | 
 | 589 | 	} | 
 | 590 | 	port[dev] = pnp_port_start(pdev, 0); | 
 | 591 | 	dma1[dev] = pnp_dma(pdev, 0); | 
 | 592 | 	if (dma2[dev] >= 0) | 
 | 593 | 		dma2[dev] = pnp_dma(pdev, 1); | 
 | 594 | 	irq[dev] = pnp_irq(pdev, 0); | 
| Greg Kroah-Hartman | aa0a2dd | 2006-06-12 14:50:27 -0700 | [diff] [blame] | 595 | 	snd_printdd("isapnp IW: sb port=0x%llx, gf1 port=0x%llx, codec port=0x%llx\n", | 
 | 596 | 			(unsigned long long)pnp_port_start(pdev, 0), | 
 | 597 | 			(unsigned long long)pnp_port_start(pdev, 1), | 
 | 598 | 			(unsigned long long)pnp_port_start(pdev, 2)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | 	snd_printdd("isapnp IW: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]); | 
 | 600 | #ifdef SNDRV_STB | 
 | 601 | 	/* Tone Control initialization */ | 
 | 602 | 	pdev = iwcard->devtc; | 
| Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 603 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | 	err = pnp_activate_dev(pdev); | 
 | 605 | 	if (err < 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | 		snd_printk(KERN_ERR "InterWave ToneControl PnP configure failure (out of resources?)\n"); | 
 | 607 | 		return err; | 
 | 608 | 	} | 
 | 609 | 	port_tc[dev] = pnp_port_start(pdev, 0); | 
 | 610 | 	snd_printdd("isapnp IW: tone control port=0x%lx\n", port_tc[dev]); | 
 | 611 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | 	return 0; | 
 | 613 | } | 
 | 614 | #endif /* CONFIG_PNP */ | 
 | 615 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 616 | static void snd_interwave_free(struct snd_card *card) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | { | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 618 | 	struct snd_interwave *iwcard = card->private_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 |  | 
 | 620 | 	if (iwcard == NULL) | 
 | 621 | 		return; | 
 | 622 | #ifdef SNDRV_STB | 
| Takashi Iwai | b1d5776 | 2005-10-10 11:56:31 +0200 | [diff] [blame] | 623 | 	release_and_free_resource(iwcard->i2c_res); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | #endif | 
 | 625 | 	if (iwcard->irq >= 0) | 
 | 626 | 		free_irq(iwcard->irq, (void *)iwcard); | 
 | 627 | } | 
 | 628 |  | 
| Takashi Iwai | 3e7fb9f | 2008-12-28 16:47:30 +0100 | [diff] [blame] | 629 | static int snd_interwave_card_new(int dev, struct snd_card **cardp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 631 | 	struct snd_card *card; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | 	struct snd_interwave *iwcard; | 
| Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 633 | 	int err; | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 634 |  | 
| Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 635 | 	err = snd_card_create(index[dev], id[dev], THIS_MODULE, | 
 | 636 | 			      sizeof(struct snd_interwave), &card); | 
 | 637 | 	if (err < 0) | 
| Takashi Iwai | 3e7fb9f | 2008-12-28 16:47:30 +0100 | [diff] [blame] | 638 | 		return err; | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 639 | 	iwcard = card->private_data; | 
 | 640 | 	iwcard->card = card; | 
 | 641 | 	iwcard->irq = -1; | 
 | 642 | 	card->private_free = snd_interwave_free; | 
| Takashi Iwai | 3e7fb9f | 2008-12-28 16:47:30 +0100 | [diff] [blame] | 643 | 	*cardp = card; | 
 | 644 | 	return 0; | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 645 | } | 
 | 646 |  | 
 | 647 | static int __devinit snd_interwave_probe(struct snd_card *card, int dev) | 
 | 648 | { | 
 | 649 | 	int xirq, xdma1, xdma2; | 
 | 650 | 	struct snd_interwave *iwcard = card->private_data; | 
| Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 651 | 	struct snd_wss *wss; | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 652 | 	struct snd_gus_card *gus; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | #ifdef SNDRV_STB | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 654 | 	struct snd_i2c_bus *i2c_bus; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | #endif | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 656 | 	struct snd_pcm *pcm; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | 	char *str; | 
 | 658 | 	int err; | 
 | 659 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | 	xirq = irq[dev]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | 	xdma1 = dma1[dev]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | 	xdma2 = dma2[dev]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 |  | 
 | 664 | 	if ((err = snd_gus_create(card, | 
 | 665 | 				  port[dev], | 
 | 666 | 				  -xirq, xdma1, xdma2, | 
 | 667 | 				  0, 32, | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 668 | 				  pcm_channels[dev], effect[dev], &gus)) < 0) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 669 | 		return err; | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 670 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | 	if ((err = snd_interwave_detect(iwcard, gus, dev | 
 | 672 | #ifdef SNDRV_STB | 
 | 673 |             , &i2c_bus | 
 | 674 | #endif | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 675 | 	    )) < 0) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 676 | 		return err; | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 677 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | 	iwcard->gus_status_reg = gus->gf1.reg_irqstat; | 
 | 679 | 	iwcard->pcm_status_reg = gus->gf1.port + 0x10c + 2; | 
 | 680 |  | 
 | 681 | 	snd_interwave_init(dev, gus); | 
 | 682 | 	snd_interwave_detect_memory(gus); | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 683 | 	if ((err = snd_gus_initialize(gus)) < 0) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 684 | 		return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 |  | 
| Yong Zhang | 88e24c3 | 2011-09-22 16:59:20 +0800 | [diff] [blame] | 686 | 	if (request_irq(xirq, snd_interwave_interrupt, 0, | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 687 | 			"InterWave", iwcard)) { | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 688 | 		snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq); | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 689 | 		return -EBUSY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | 	} | 
 | 691 | 	iwcard->irq = xirq; | 
 | 692 |  | 
| Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 693 | 	err = snd_wss_create(card, | 
 | 694 | 			     gus->gf1.port + 0x10c, -1, xirq, | 
 | 695 | 			     xdma2 < 0 ? xdma1 : xdma2, xdma1, | 
 | 696 | 			     WSS_HW_INTERWAVE, | 
 | 697 | 			     WSS_HWSHARE_IRQ | | 
 | 698 | 			     WSS_HWSHARE_DMA1 | | 
 | 699 | 			     WSS_HWSHARE_DMA2, | 
 | 700 | 			     &wss); | 
 | 701 | 	if (err < 0) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 702 | 		return err; | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 703 |  | 
| Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 704 | 	err = snd_wss_pcm(wss, 0, &pcm); | 
 | 705 | 	if (err < 0) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 706 | 		return err; | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 707 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | 	sprintf(pcm->name + strlen(pcm->name), " rev %c", gus->revision + 'A'); | 
 | 709 | 	strcat(pcm->name, " (codec)"); | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 710 |  | 
| Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 711 | 	err = snd_wss_timer(wss, 2, NULL); | 
 | 712 | 	if (err < 0) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 713 | 		return err; | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 714 |  | 
| Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 715 | 	err = snd_wss_mixer(wss); | 
 | 716 | 	if (err < 0) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 717 | 		return err; | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 718 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | 	if (pcm_channels[dev] > 0) { | 
| Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 720 | 		err = snd_gf1_pcm_new(gus, 1, 1, NULL); | 
 | 721 | 		if (err < 0) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 722 | 			return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | 	} | 
| Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 724 | 	err = snd_interwave_mixer(wss); | 
 | 725 | 	if (err < 0) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 726 | 		return err; | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 727 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | #ifdef SNDRV_STB | 
 | 729 | 	{ | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 730 | 		struct snd_ctl_elem_id id1, id2; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | 		memset(&id1, 0, sizeof(id1)); | 
 | 732 | 		memset(&id2, 0, sizeof(id2)); | 
 | 733 | 		id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | 
 | 734 | 		strcpy(id1.name, "Master Playback Switch"); | 
 | 735 | 		strcpy(id2.name, id1.name); | 
 | 736 | 		id2.index = 1; | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 737 | 		if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 738 | 			return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | 		strcpy(id1.name, "Master Playback Volume"); | 
 | 740 | 		strcpy(id2.name, id1.name); | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 741 | 		if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 742 | 			return err; | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 743 | 		if ((err = snd_tea6330t_update_mixer(card, i2c_bus, 0, 1)) < 0) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 744 | 			return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | 	} | 
 | 746 | #endif | 
 | 747 |  | 
 | 748 | 	gus->uart_enable = midi[dev]; | 
| Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 749 | 	if ((err = snd_gf1_rawmidi_new(gus, 0, NULL)) < 0) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 750 | 		return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 |  | 
 | 752 | #ifndef SNDRV_STB | 
 | 753 | 	str = "AMD InterWave"; | 
 | 754 | 	if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8) | 
 | 755 | 		str = "Dynasonic 3-D"; | 
 | 756 | #else | 
 | 757 | 	str = "InterWave STB"; | 
 | 758 | #endif | 
 | 759 | 	strcpy(card->driver, str); | 
 | 760 | 	strcpy(card->shortname, str); | 
 | 761 | 	sprintf(card->longname, "%s at 0x%lx, irq %i, dma %d", | 
 | 762 | 		str, | 
 | 763 | 		gus->gf1.port, | 
 | 764 | 		xirq, | 
 | 765 | 		xdma1); | 
 | 766 | 	if (xdma2 >= 0) | 
 | 767 | 		sprintf(card->longname + strlen(card->longname), "&%d", xdma2); | 
 | 768 |  | 
| Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 769 | 	err = snd_card_register(card); | 
 | 770 | 	if (err < 0) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 771 | 		return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | 	 | 
| Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 773 | 	iwcard->wss = wss; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | 	iwcard->gus = gus; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | } | 
 | 777 |  | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 778 | static int __devinit snd_interwave_isa_probe1(int dev, struct device *devptr) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 779 | { | 
 | 780 | 	struct snd_card *card; | 
 | 781 | 	int err; | 
 | 782 |  | 
| Takashi Iwai | 3e7fb9f | 2008-12-28 16:47:30 +0100 | [diff] [blame] | 783 | 	err = snd_interwave_card_new(dev, &card); | 
 | 784 | 	if (err < 0) | 
 | 785 | 		return err; | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 786 |  | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 787 | 	snd_card_set_dev(card, devptr); | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 788 | 	if ((err = snd_interwave_probe(card, dev)) < 0) { | 
 | 789 | 		snd_card_free(card); | 
 | 790 | 		return err; | 
 | 791 | 	} | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 792 | 	dev_set_drvdata(devptr, card); | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 793 | 	return 0; | 
 | 794 | } | 
 | 795 |  | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 796 | static int __devinit snd_interwave_isa_match(struct device *pdev, | 
 | 797 | 					     unsigned int dev) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 798 | { | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 799 | 	if (!enable[dev]) | 
 | 800 | 		return 0; | 
 | 801 | #ifdef CONFIG_PNP | 
 | 802 | 	if (isapnp[dev]) | 
 | 803 | 		return 0; | 
 | 804 | #endif | 
 | 805 | 	return 1; | 
 | 806 | } | 
 | 807 |  | 
 | 808 | static int __devinit snd_interwave_isa_probe(struct device *pdev, | 
 | 809 | 					     unsigned int dev) | 
 | 810 | { | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 811 | 	int err; | 
 | 812 | 	static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, -1}; | 
 | 813 | 	static int possible_dmas[] = {0, 1, 3, 5, 6, 7, -1}; | 
 | 814 |  | 
 | 815 | 	if (irq[dev] == SNDRV_AUTO_IRQ) { | 
 | 816 | 		if ((irq[dev] = snd_legacy_find_free_irq(possible_irqs)) < 0) { | 
 | 817 | 			snd_printk(KERN_ERR PFX "unable to find a free IRQ\n"); | 
 | 818 | 			return -EBUSY; | 
 | 819 | 		} | 
 | 820 | 	} | 
 | 821 | 	if (dma1[dev] == SNDRV_AUTO_DMA) { | 
 | 822 | 		if ((dma1[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) { | 
 | 823 | 			snd_printk(KERN_ERR PFX "unable to find a free DMA1\n"); | 
 | 824 | 			return -EBUSY; | 
 | 825 | 		} | 
 | 826 | 	} | 
 | 827 | 	if (dma2[dev] == SNDRV_AUTO_DMA) { | 
 | 828 | 		if ((dma2[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) { | 
 | 829 | 			snd_printk(KERN_ERR PFX "unable to find a free DMA2\n"); | 
 | 830 | 			return -EBUSY; | 
 | 831 | 		} | 
 | 832 | 	} | 
 | 833 |  | 
 | 834 | 	if (port[dev] != SNDRV_AUTO_PORT) | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 835 | 		return snd_interwave_isa_probe1(dev, pdev); | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 836 | 	else { | 
 | 837 | 		static long possible_ports[] = {0x210, 0x220, 0x230, 0x240, 0x250, 0x260}; | 
 | 838 | 		int i; | 
 | 839 | 		for (i = 0; i < ARRAY_SIZE(possible_ports); i++) { | 
 | 840 | 			port[dev] = possible_ports[i]; | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 841 | 			err = snd_interwave_isa_probe1(dev, pdev); | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 842 | 			if (! err) | 
 | 843 | 				return 0; | 
 | 844 | 		} | 
 | 845 | 		return err; | 
 | 846 | 	} | 
 | 847 | } | 
 | 848 |  | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 849 | static int __devexit snd_interwave_isa_remove(struct device *devptr, unsigned int dev) | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 850 | { | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 851 | 	snd_card_free(dev_get_drvdata(devptr)); | 
 | 852 | 	dev_set_drvdata(devptr, NULL); | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 853 | 	return 0; | 
 | 854 | } | 
 | 855 |  | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 856 | static struct isa_driver snd_interwave_driver = { | 
 | 857 | 	.match		= snd_interwave_isa_match, | 
 | 858 | 	.probe		= snd_interwave_isa_probe, | 
 | 859 | 	.remove		= __devexit_p(snd_interwave_isa_remove), | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 860 | 	/* FIXME: suspend,resume */ | 
 | 861 | 	.driver		= { | 
 | 862 | 		.name	= INTERWAVE_DRIVER | 
 | 863 | 	}, | 
 | 864 | }; | 
 | 865 |  | 
 | 866 | #ifdef CONFIG_PNP | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 867 | static int __devinit snd_interwave_pnp_detect(struct pnp_card_link *pcard, | 
 | 868 | 					      const struct pnp_card_device_id *pid) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | { | 
 | 870 | 	static int dev; | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 871 | 	struct snd_card *card; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | 	int res; | 
 | 873 |  | 
 | 874 | 	for ( ; dev < SNDRV_CARDS; dev++) { | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 875 | 		if (enable[dev] && isapnp[dev]) | 
 | 876 | 			break; | 
 | 877 | 	} | 
 | 878 | 	if (dev >= SNDRV_CARDS) | 
 | 879 | 		return -ENODEV; | 
 | 880 | 				 | 
| Takashi Iwai | 3e7fb9f | 2008-12-28 16:47:30 +0100 | [diff] [blame] | 881 | 	res = snd_interwave_card_new(dev, &card); | 
 | 882 | 	if (res < 0) | 
 | 883 | 		return res; | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 884 |  | 
 | 885 | 	if ((res = snd_interwave_pnp(dev, card->private_data, pcard, pid)) < 0) { | 
 | 886 | 		snd_card_free(card); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | 		return res; | 
 | 888 | 	} | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 889 | 	snd_card_set_dev(card, &pcard->card->dev); | 
 | 890 | 	if ((res = snd_interwave_probe(card, dev)) < 0) { | 
 | 891 | 		snd_card_free(card); | 
 | 892 | 		return res; | 
 | 893 | 	} | 
 | 894 | 	pnp_set_card_drvdata(pcard, card); | 
 | 895 | 	dev++; | 
 | 896 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | } | 
 | 898 |  | 
 | 899 | static void __devexit snd_interwave_pnp_remove(struct pnp_card_link * pcard) | 
 | 900 | { | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 901 | 	snd_card_free(pnp_get_card_drvdata(pcard)); | 
 | 902 | 	pnp_set_card_drvdata(pcard, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | } | 
 | 904 |  | 
 | 905 | static struct pnp_card_driver interwave_pnpc_driver = { | 
 | 906 | 	.flags = PNP_DRIVER_RES_DISABLE, | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 907 | 	.name = INTERWAVE_PNP_DRIVER, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | 	.id_table = snd_interwave_pnpids, | 
 | 909 | 	.probe = snd_interwave_pnp_detect, | 
 | 910 | 	.remove = __devexit_p(snd_interwave_pnp_remove), | 
| Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 911 | 	/* FIXME: suspend,resume */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | }; | 
 | 913 |  | 
 | 914 | #endif /* CONFIG_PNP */ | 
 | 915 |  | 
 | 916 | static int __init alsa_card_interwave_init(void) | 
 | 917 | { | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 918 | 	int err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 |  | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 920 | 	err = isa_register_driver(&snd_interwave_driver, SNDRV_CARDS); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | #ifdef CONFIG_PNP | 
| Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 922 | 	if (!err) | 
 | 923 | 		isa_registered = 1; | 
 | 924 |  | 
| Bjorn Helgaas | ebdb71e | 2006-03-27 01:17:14 -0800 | [diff] [blame] | 925 | 	err = pnp_register_card_driver(&interwave_pnpc_driver); | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 926 | 	if (!err) | 
| Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 927 | 		pnp_registered = 1; | 
| Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 928 |  | 
 | 929 | 	if (isa_registered) | 
 | 930 | 		err = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | #endif | 
| Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 932 | 	return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | } | 
 | 934 |  | 
 | 935 | static void __exit alsa_card_interwave_exit(void) | 
 | 936 | { | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 937 | #ifdef CONFIG_PNP | 
 | 938 | 	if (pnp_registered) | 
 | 939 | 		pnp_unregister_card_driver(&interwave_pnpc_driver); | 
| Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 940 | 	if (isa_registered) | 
| Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 941 | #endif | 
| Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 942 | 		isa_unregister_driver(&snd_interwave_driver); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | } | 
 | 944 |  | 
 | 945 | module_init(alsa_card_interwave_init) | 
 | 946 | module_exit(alsa_card_interwave_exit) |