blob: 3e46572555361d48fd7331de7a9996f574be37e2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Driver for AMD InterWave soundcard
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
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
25#include <sound/driver.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
Takashi Iwai654aa662005-11-17 17:13:43 +010027#include <linux/err.h>
Takashi Iwai5e24c1c2007-02-22 12:50:54 +010028#include <linux/isa.h>
Takashi Iwai654aa662005-11-17 17:13:43 +010029#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/slab.h>
31#include <linux/pnp.h>
32#include <linux/moduleparam.h>
Takashi Iwai654aa662005-11-17 17:13:43 +010033#include <asm/dma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <sound/core.h>
35#include <sound/gus.h>
36#include <sound/cs4231.h>
37#ifdef SNDRV_STB
38#include <sound/tea6330t.h>
39#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#define SNDRV_LEGACY_FIND_FREE_IRQ
41#define SNDRV_LEGACY_FIND_FREE_DMA
42#include <sound/initval.h>
43
44MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
45MODULE_LICENSE("GPL");
46#ifndef SNDRV_STB
47MODULE_DESCRIPTION("AMD InterWave");
48MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Plug & Play},"
49 "{STB,SoundRage32},"
50 "{MED,MED3210},"
51 "{Dynasonix,Dynasonix Pro},"
52 "{Panasonic,PCA761AW}}");
53#else
54MODULE_DESCRIPTION("AMD InterWave STB with TEA6330T");
55MODULE_SUPPORTED_DEVICE("{{AMD,InterWave STB with TEA6330T}}");
56#endif
57
58static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
59static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
60static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
61#ifdef CONFIG_PNP
62static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
63#endif
64static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x210,0x220,0x230,0x240,0x250,0x260 */
65#ifdef SNDRV_STB
66static long port_tc[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x350,0x360,0x370,0x380 */
67#endif
68static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 2,3,5,9,11,12,15 */
69static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
70static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
71static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
72 /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
Takashi Iwai6581f4e2006-05-17 17:14:51 +020073static int midi[SNDRV_CARDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070074static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
Takashi Iwai6581f4e2006-05-17 17:14:51 +020075static int effect[SNDRV_CARDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Takashi Iwai43bcd972005-09-05 17:19:20 +020077#ifdef SNDRV_STB
78#define PFX "interwave-stb: "
Takashi Iwai654aa662005-11-17 17:13:43 +010079#define INTERWAVE_DRIVER "snd_interwave_stb"
80#define INTERWAVE_PNP_DRIVER "interwave-stb"
Takashi Iwai43bcd972005-09-05 17:19:20 +020081#else
82#define PFX "interwave: "
Takashi Iwai654aa662005-11-17 17:13:43 +010083#define INTERWAVE_DRIVER "snd_interwave"
84#define INTERWAVE_PNP_DRIVER "interwave"
Takashi Iwai43bcd972005-09-05 17:19:20 +020085#endif
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087module_param_array(index, int, NULL, 0444);
88MODULE_PARM_DESC(index, "Index value for InterWave soundcard.");
89module_param_array(id, charp, NULL, 0444);
90MODULE_PARM_DESC(id, "ID string for InterWave soundcard.");
91module_param_array(enable, bool, NULL, 0444);
92MODULE_PARM_DESC(enable, "Enable InterWave soundcard.");
93#ifdef CONFIG_PNP
94module_param_array(isapnp, bool, NULL, 0444);
95MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
96#endif
97module_param_array(port, long, NULL, 0444);
98MODULE_PARM_DESC(port, "Port # for InterWave driver.");
99#ifdef SNDRV_STB
100module_param_array(port_tc, long, NULL, 0444);
101MODULE_PARM_DESC(port_tc, "Tone control (TEA6330T - i2c bus) port # for InterWave driver.");
102#endif
103module_param_array(irq, int, NULL, 0444);
104MODULE_PARM_DESC(irq, "IRQ # for InterWave driver.");
105module_param_array(dma1, int, NULL, 0444);
106MODULE_PARM_DESC(dma1, "DMA1 # for InterWave driver.");
107module_param_array(dma2, int, NULL, 0444);
108MODULE_PARM_DESC(dma2, "DMA2 # for InterWave driver.");
109module_param_array(joystick_dac, int, NULL, 0444);
110MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for InterWave driver.");
111module_param_array(midi, int, NULL, 0444);
112MODULE_PARM_DESC(midi, "MIDI UART enable for InterWave driver.");
113module_param_array(pcm_channels, int, NULL, 0444);
114MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for InterWave driver.");
115module_param_array(effect, int, NULL, 0444);
116MODULE_PARM_DESC(effect, "Effects enable for InterWave driver.");
117
118struct snd_interwave {
119 int irq;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100120 struct snd_card *card;
121 struct snd_gus_card *gus;
122 struct snd_cs4231 *cs4231;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#ifdef SNDRV_STB
124 struct resource *i2c_res;
125#endif
126 unsigned short gus_status_reg;
127 unsigned short pcm_status_reg;
128#ifdef CONFIG_PNP
129 struct pnp_dev *dev;
130#ifdef SNDRV_STB
131 struct pnp_dev *devtc;
132#endif
133#endif
134};
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137#ifdef CONFIG_PNP
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100138static int pnp_registered;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140static struct pnp_card_device_id snd_interwave_pnpids[] = {
141#ifndef SNDRV_STB
142 /* Gravis UltraSound Plug & Play */
143 { .id = "GRV0001", .devs = { { .id = "GRV0000" } } },
144 /* STB SoundRage32 */
145 { .id = "STB011a", .devs = { { .id = "STB0010" } } },
146 /* MED3210 */
147 { .id = "DXP3201", .devs = { { .id = "DXP0010" } } },
148 /* Dynasonic Pro */
149 /* This device also have CDC1117:DynaSonix Pro Audio Effects Processor */
150 { .id = "CDC1111", .devs = { { .id = "CDC1112" } } },
151 /* Panasonic PCA761AW Audio Card */
152 { .id = "ADV55ff", .devs = { { .id = "ADV0010" } } },
153 /* InterWave STB without TEA6330T */
154 { .id = "ADV550a", .devs = { { .id = "ADV0010" } } },
155#else
156 /* InterWave STB with TEA6330T */
157 { .id = "ADV550a", .devs = { { .id = "ADV0010" }, { .id = "ADV0015" } } },
158#endif
159 { .id = "" }
160};
161
162MODULE_DEVICE_TABLE(pnp_card, snd_interwave_pnpids);
163
164#endif /* CONFIG_PNP */
165
166
167#ifdef SNDRV_STB
Takashi Iwai5e2da202005-11-17 14:36:44 +0100168static void snd_interwave_i2c_setlines(struct snd_i2c_bus *bus, int ctrl, int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169{
170 unsigned long port = bus->private_value;
171
172#if 0
173 printk("i2c_setlines - 0x%lx <- %i,%i\n", port, ctrl, data);
174#endif
175 outb((data << 1) | ctrl, port);
176 udelay(10);
177}
178
Takashi Iwai5e2da202005-11-17 14:36:44 +0100179static int snd_interwave_i2c_getclockline(struct snd_i2c_bus *bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
181 unsigned long port = bus->private_value;
182 unsigned char res;
183
184 res = inb(port) & 1;
185#if 0
186 printk("i2c_getclockline - 0x%lx -> %i\n", port, res);
187#endif
188 return res;
189}
190
Takashi Iwai5e2da202005-11-17 14:36:44 +0100191static int snd_interwave_i2c_getdataline(struct snd_i2c_bus *bus, int ack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
193 unsigned long port = bus->private_value;
194 unsigned char res;
195
196 if (ack)
197 udelay(10);
198 res = (inb(port) & 2) >> 1;
199#if 0
200 printk("i2c_getdataline - 0x%lx -> %i\n", port, res);
201#endif
202 return res;
203}
204
Takashi Iwai5e2da202005-11-17 14:36:44 +0100205static struct snd_i2c_bit_ops snd_interwave_i2c_bit_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 .setlines = snd_interwave_i2c_setlines,
207 .getclock = snd_interwave_i2c_getclockline,
208 .getdata = snd_interwave_i2c_getdataline,
209};
210
211static int __devinit snd_interwave_detect_stb(struct snd_interwave *iwcard,
Takashi Iwai5e2da202005-11-17 14:36:44 +0100212 struct snd_gus_card * gus, int dev,
213 struct snd_i2c_bus **rbus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
215 unsigned long port;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100216 struct snd_i2c_bus *bus;
217 struct snd_card *card = iwcard->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 char name[32];
219 int err;
220
221 *rbus = NULL;
222 port = port_tc[dev];
223 if (port == SNDRV_AUTO_PORT) {
224 port = 0x350;
225 if (gus->gf1.port == 0x250) {
226 port = 0x360;
227 }
228 while (port <= 0x380) {
229 if ((iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)")) != NULL)
230 break;
231 port += 0x10;
232 }
233 } else {
234 iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)");
235 }
236 if (iwcard->i2c_res == NULL) {
237 snd_printk(KERN_ERR "interwave: can't grab i2c bus port\n");
238 return -ENODEV;
239 }
240
241 sprintf(name, "InterWave-%i", card->number);
242 if ((err = snd_i2c_bus_create(card, name, NULL, &bus)) < 0)
243 return err;
244 bus->private_value = port;
245 bus->hw_ops.bit = &snd_interwave_i2c_bit_ops;
246 if ((err = snd_tea6330t_detect(bus, 0)) < 0)
247 return err;
248 *rbus = bus;
249 return 0;
250}
251#endif
252
253static int __devinit snd_interwave_detect(struct snd_interwave *iwcard,
Takashi Iwai5e2da202005-11-17 14:36:44 +0100254 struct snd_gus_card * gus,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 int dev
256#ifdef SNDRV_STB
Takashi Iwai5e2da202005-11-17 14:36:44 +0100257 , struct snd_i2c_bus **rbus
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258#endif
259 )
260{
261 unsigned long flags;
262 unsigned char rev1, rev2;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200263 int d;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
Takashi Iwai43bcd972005-09-05 17:19:20 +0200266 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
267 snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 return -ENODEV;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200269 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 udelay(160);
271 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
272 udelay(160);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200273 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
274 snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 return -ENODEV;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 spin_lock_irqsave(&gus->reg_lock, flags);
278 rev1 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER);
279 snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, ~rev1);
280 rev2 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER);
281 snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, rev1);
282 spin_unlock_irqrestore(&gus->reg_lock, flags);
283 snd_printdd("[0x%lx] InterWave check - rev1=0x%x, rev2=0x%x\n", gus->gf1.port, rev1, rev2);
284 if ((rev1 & 0xf0) == (rev2 & 0xf0) &&
285 (rev1 & 0x0f) != (rev2 & 0x0f)) {
286 snd_printdd("[0x%lx] InterWave check - passed\n", gus->gf1.port);
287 gus->interwave = 1;
288 strcpy(gus->card->shortname, "AMD InterWave");
289 gus->revision = rev1 >> 4;
290#ifndef SNDRV_STB
291 return 0; /* ok.. We have an InterWave board */
292#else
293 return snd_interwave_detect_stb(iwcard, gus, dev, rbus);
294#endif
295 }
296 snd_printdd("[0x%lx] InterWave check - failed\n", gus->gf1.port);
297 return -ENODEV;
298}
299
David Howells7d12e782006-10-05 14:55:46 +0100300static irqreturn_t snd_interwave_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400302 struct snd_interwave *iwcard = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 int loop, max = 5;
304 int handled = 0;
305
306 do {
307 loop = 0;
308 if (inb(iwcard->gus_status_reg)) {
309 handled = 1;
David Howells7d12e782006-10-05 14:55:46 +0100310 snd_gus_interrupt(irq, iwcard->gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 loop++;
312 }
313 if (inb(iwcard->pcm_status_reg) & 0x01) { /* IRQ bit is set? */
314 handled = 1;
David Howells7d12e782006-10-05 14:55:46 +0100315 snd_cs4231_interrupt(irq, iwcard->cs4231);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 loop++;
317 }
318 } while (loop && --max > 0);
319 return IRQ_RETVAL(handled);
320}
321
Takashi Iwai5e2da202005-11-17 14:36:44 +0100322static void __devinit snd_interwave_reset(struct snd_gus_card * gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
324 snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x00);
325 udelay(160);
326 snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x01);
327 udelay(160);
328}
329
Takashi Iwai5e2da202005-11-17 14:36:44 +0100330static void __devinit snd_interwave_bank_sizes(struct snd_gus_card * gus, int *sizes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
332 unsigned int idx;
333 unsigned int local;
334 unsigned char d;
335
336 for (idx = 0; idx < 4; idx++) {
337 sizes[idx] = 0;
338 d = 0x55;
339 for (local = idx << 22;
340 local < (idx << 22) + 0x400000;
341 local += 0x40000, d++) {
342 snd_gf1_poke(gus, local, d);
343 snd_gf1_poke(gus, local + 1, d + 1);
344#if 0
345 printk("d = 0x%x, local = 0x%x, local + 1 = 0x%x, idx << 22 = 0x%x\n",
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
359 printk("sizes: %i %i %i %i\n", sizes[0], sizes[1], sizes[2], sizes[3]);
360#endif
361}
362
363struct rom_hdr {
364 /* 000 */ unsigned char iwave[8];
365 /* 008 */ unsigned char rom_hdr_revision;
366 /* 009 */ unsigned char series_number;
367 /* 010 */ unsigned char series_name[16];
368 /* 026 */ unsigned char date[10];
369 /* 036 */ unsigned short vendor_revision_major;
370 /* 038 */ unsigned short vendor_revision_minor;
371 /* 040 */ unsigned int rom_size;
372 /* 044 */ unsigned char copyright[128];
373 /* 172 */ unsigned char vendor_name[64];
374 /* 236 */ unsigned char rom_description[128];
375 /* 364 */ unsigned char pad[147];
376 /* 511 */ unsigned char csum;
377};
378
Takashi Iwai5e2da202005-11-17 14:36:44 +0100379static void __devinit snd_interwave_detect_memory(struct snd_gus_card * gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
381 static unsigned int lmc[13] =
382 {
383 0x00000001, 0x00000101, 0x01010101, 0x00000401,
384 0x04040401, 0x00040101, 0x04040101, 0x00000004,
385 0x00000404, 0x04040404, 0x00000010, 0x00001010,
386 0x10101010
387 };
388
389 int bank_pos, pages;
390 unsigned int i, lmct;
391 int psizes[4];
392 unsigned char iwave[8];
393 unsigned char csum;
394
395 snd_interwave_reset(gus);
396 snd_gf1_write8(gus, SNDRV_GF1_GB_GLOBAL_MODE, snd_gf1_read8(gus, SNDRV_GF1_GB_GLOBAL_MODE) | 0x01); /* enhanced mode */
397 snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01); /* DRAM I/O cycles selected */
398 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff10) | 0x004c);
399 /* ok.. simple test of memory size */
400 pages = 0;
401 snd_gf1_poke(gus, 0, 0x55);
402 snd_gf1_poke(gus, 1, 0xaa);
403#if 1
404 if (snd_gf1_peek(gus, 0) == 0x55 && snd_gf1_peek(gus, 1) == 0xaa)
405#else
406 if (0) /* ok.. for testing of 0k RAM */
407#endif
408 {
409 snd_interwave_bank_sizes(gus, psizes);
410 lmct = (psizes[3] << 24) | (psizes[2] << 16) |
411 (psizes[1] << 8) | psizes[0];
412#if 0
413 printk("lmct = 0x%08x\n", lmct);
414#endif
415 for (i = 0; i < ARRAY_SIZE(lmc); i++)
416 if (lmct == lmc[i]) {
417#if 0
418 printk("found !!! %i\n", i);
419#endif
420 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | i);
421 snd_interwave_bank_sizes(gus, psizes);
422 break;
423 }
424 if (i >= ARRAY_SIZE(lmc) && !gus->gf1.enh_mode)
425 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | 2);
426 for (i = 0; i < 4; i++) {
427 gus->gf1.mem_alloc.banks_8[i].address =
428 gus->gf1.mem_alloc.banks_16[i].address = i << 22;
429 gus->gf1.mem_alloc.banks_8[i].size =
430 gus->gf1.mem_alloc.banks_16[i].size = psizes[i] << 18;
431 pages += psizes[i];
432 }
433 }
434 pages <<= 18;
435 gus->gf1.memory = pages;
436
437 snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x03); /* select ROM */
438 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff1f) | (4 << 5));
439 gus->gf1.rom_banks = 0;
440 gus->gf1.rom_memory = 0;
441 for (bank_pos = 0; bank_pos < 16L * 1024L * 1024L; bank_pos += 4L * 1024L * 1024L) {
442 for (i = 0; i < 8; ++i)
443 iwave[i] = snd_gf1_peek(gus, bank_pos + i);
444#ifdef CONFIG_SND_DEBUG_ROM
Takashi Iwai99b359b2005-10-20 18:26:44 +0200445 printk(KERN_DEBUG "ROM at 0x%06x = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", bank_pos,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 iwave[0], iwave[1], iwave[2], iwave[3],
447 iwave[4], iwave[5], iwave[6], iwave[7]);
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 Iwai99b359b2005-10-20 18:26:44 +0200455 printk(KERN_DEBUG "ROM checksum = 0x%x (computed)\n", csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#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 Iwai5e2da202005-11-17 14:36:44 +0100478static void __devinit snd_interwave_init(int dev, struct snd_gus_card * gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
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 Iwai5e2da202005-11-17 14:36:44 +0100500static struct snd_kcontrol_new snd_interwave_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501CS4231_DOUBLE("Master Playback Switch", 0, CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 7, 7, 1, 1),
502CS4231_DOUBLE("Master Playback Volume", 0, CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 0, 0, 31, 1),
503CS4231_DOUBLE("Mic Playback Switch", 0, CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 7, 7, 1, 1),
504CS4231_DOUBLE("Mic Playback Volume", 0, CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 0, 0, 31, 1)
505};
506
Takashi Iwai5e2da202005-11-17 14:36:44 +0100507static int __devinit snd_interwave_mixer(struct snd_cs4231 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508{
Takashi Iwai5e2da202005-11-17 14:36:44 +0100509 struct snd_card *card = chip->card;
510 struct snd_ctl_elem_id id1, id2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 unsigned int idx;
512 int err;
513
514 memset(&id1, 0, sizeof(id1));
515 memset(&id2, 0, sizeof(id2));
516 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
517#if 0
518 /* remove mono microphone controls */
519 strcpy(id1.name, "Mic Playback Switch");
520 if ((err = snd_ctl_remove_id(card, &id1)) < 0)
521 return err;
522 strcpy(id1.name, "Mic Playback Volume");
523 if ((err = snd_ctl_remove_id(card, &id1)) < 0)
524 return err;
525#endif
526 /* add new master and mic controls */
527 for (idx = 0; idx < ARRAY_SIZE(snd_interwave_controls); idx++)
528 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_interwave_controls[idx], chip))) < 0)
529 return err;
530 snd_cs4231_out(chip, CS4231_LINE_LEFT_OUTPUT, 0x9f);
531 snd_cs4231_out(chip, CS4231_LINE_RIGHT_OUTPUT, 0x9f);
532 snd_cs4231_out(chip, CS4231_LEFT_MIC_INPUT, 0x9f);
533 snd_cs4231_out(chip, CS4231_RIGHT_MIC_INPUT, 0x9f);
534 /* reassign AUXA to SYNTHESIZER */
535 strcpy(id1.name, "Aux Playback Switch");
536 strcpy(id2.name, "Synth Playback Switch");
537 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
538 return err;
539 strcpy(id1.name, "Aux Playback Volume");
540 strcpy(id2.name, "Synth Playback Volume");
541 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
542 return err;
543 /* reassign AUXB to CD */
544 strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
545 strcpy(id2.name, "CD Playback Switch");
546 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
547 return err;
548 strcpy(id1.name, "Aux Playback Volume");
549 strcpy(id2.name, "CD Playback Volume");
550 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
551 return err;
552 return 0;
553}
554
555#ifdef CONFIG_PNP
556
557static int __devinit snd_interwave_pnp(int dev, struct snd_interwave *iwcard,
558 struct pnp_card_link *card,
559 const struct pnp_card_device_id *id)
560{
561 struct pnp_dev *pdev;
562 struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
563 int err;
564
Amit Choudhary4a81a212006-10-09 16:02:49 +0200565 if (!cfg)
566 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 iwcard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
568 if (iwcard->dev == NULL) {
569 kfree(cfg);
570 return -EBUSY;
571 }
572#ifdef SNDRV_STB
573 iwcard->devtc = pnp_request_card_device(card, id->devs[1].id, NULL);
574 if (iwcard->devtc == NULL) {
575 kfree(cfg);
576 return -EBUSY;
577 }
578#endif
579 /* Synth & Codec initialization */
580 pdev = iwcard->dev;
581 pnp_init_resource_table(cfg);
582 if (port[dev] != SNDRV_AUTO_PORT) {
583 pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
584 pnp_resource_change(&cfg->port_resource[1], port[dev] + 0x100, 12);
585 pnp_resource_change(&cfg->port_resource[2], port[dev] + 0x10c, 4);
586 }
587 if (dma1[dev] != SNDRV_AUTO_DMA)
588 pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
589 if (dma2[dev] != SNDRV_AUTO_DMA)
590 pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
591 if (dma2[dev] < 0)
592 pnp_resource_change(&cfg->dma_resource[1], 4, 1);
593 if (irq[dev] != SNDRV_AUTO_IRQ)
594 pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
595 if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
596 snd_printk(KERN_ERR "InterWave - Synth - the requested resources are invalid, using auto config\n");
597 err = pnp_activate_dev(pdev);
598 if (err < 0) {
599 kfree(cfg);
600 snd_printk(KERN_ERR "InterWave PnP configure failure (out of resources?)\n");
601 return err;
602 }
603 if (pnp_port_start(pdev, 0) + 0x100 != pnp_port_start(pdev, 1) ||
604 pnp_port_start(pdev, 0) + 0x10c != pnp_port_start(pdev, 2)) {
605 kfree(cfg);
606 snd_printk(KERN_ERR "PnP configure failure (wrong ports)\n");
607 return -ENOENT;
608 }
609 port[dev] = pnp_port_start(pdev, 0);
610 dma1[dev] = pnp_dma(pdev, 0);
611 if (dma2[dev] >= 0)
612 dma2[dev] = pnp_dma(pdev, 1);
613 irq[dev] = pnp_irq(pdev, 0);
Greg Kroah-Hartmanaa0a2dd2006-06-12 14:50:27 -0700614 snd_printdd("isapnp IW: sb port=0x%llx, gf1 port=0x%llx, codec port=0x%llx\n",
615 (unsigned long long)pnp_port_start(pdev, 0),
616 (unsigned long long)pnp_port_start(pdev, 1),
617 (unsigned long long)pnp_port_start(pdev, 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 snd_printdd("isapnp IW: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]);
619#ifdef SNDRV_STB
620 /* Tone Control initialization */
621 pdev = iwcard->devtc;
622 pnp_init_resource_table(cfg);
623 if (port_tc[dev] != SNDRV_AUTO_PORT)
624 pnp_resource_change(&cfg->port_resource[0], port_tc[dev], 1);
625 if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
626 snd_printk(KERN_ERR "InterWave - ToneControl - the requested resources are invalid, using auto config\n");
627 err = pnp_activate_dev(pdev);
628 if (err < 0) {
629 kfree(cfg);
630 snd_printk(KERN_ERR "InterWave ToneControl PnP configure failure (out of resources?)\n");
631 return err;
632 }
633 port_tc[dev] = pnp_port_start(pdev, 0);
634 snd_printdd("isapnp IW: tone control port=0x%lx\n", port_tc[dev]);
635#endif
636 kfree(cfg);
637 return 0;
638}
639#endif /* CONFIG_PNP */
640
Takashi Iwai5e2da202005-11-17 14:36:44 +0100641static void snd_interwave_free(struct snd_card *card)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642{
Takashi Iwai654aa662005-11-17 17:13:43 +0100643 struct snd_interwave *iwcard = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
645 if (iwcard == NULL)
646 return;
647#ifdef SNDRV_STB
Takashi Iwaib1d57762005-10-10 11:56:31 +0200648 release_and_free_resource(iwcard->i2c_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#endif
650 if (iwcard->irq >= 0)
651 free_irq(iwcard->irq, (void *)iwcard);
652}
653
Takashi Iwai654aa662005-11-17 17:13:43 +0100654static struct snd_card *snd_interwave_card_new(int dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655{
Takashi Iwai5e2da202005-11-17 14:36:44 +0100656 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 struct snd_interwave *iwcard;
Takashi Iwai654aa662005-11-17 17:13:43 +0100658
659 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
660 sizeof(struct snd_interwave));
661 if (card == NULL)
662 return NULL;
663 iwcard = card->private_data;
664 iwcard->card = card;
665 iwcard->irq = -1;
666 card->private_free = snd_interwave_free;
667 return card;
668}
669
670static int __devinit snd_interwave_probe(struct snd_card *card, int dev)
671{
672 int xirq, xdma1, xdma2;
673 struct snd_interwave *iwcard = card->private_data;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100674 struct snd_cs4231 *cs4231;
675 struct snd_gus_card *gus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676#ifdef SNDRV_STB
Takashi Iwai5e2da202005-11-17 14:36:44 +0100677 struct snd_i2c_bus *i2c_bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678#endif
Takashi Iwai5e2da202005-11-17 14:36:44 +0100679 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 char *str;
681 int err;
682
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 xirq = irq[dev];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 xdma1 = dma1[dev];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 xdma2 = dma2[dev];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687 if ((err = snd_gus_create(card,
688 port[dev],
689 -xirq, xdma1, xdma2,
690 0, 32,
Takashi Iwai43bcd972005-09-05 17:19:20 +0200691 pcm_channels[dev], effect[dev], &gus)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100692 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200693
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 if ((err = snd_interwave_detect(iwcard, gus, dev
695#ifdef SNDRV_STB
696 , &i2c_bus
697#endif
Takashi Iwai43bcd972005-09-05 17:19:20 +0200698 )) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100699 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200700
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 iwcard->gus_status_reg = gus->gf1.reg_irqstat;
702 iwcard->pcm_status_reg = gus->gf1.port + 0x10c + 2;
703
704 snd_interwave_init(dev, gus);
705 snd_interwave_detect_memory(gus);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200706 if ((err = snd_gus_initialize(gus)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100707 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Thomas Gleixner65ca68b2006-07-01 19:29:46 -0700709 if (request_irq(xirq, snd_interwave_interrupt, IRQF_DISABLED,
Takashi Iwai654aa662005-11-17 17:13:43 +0100710 "InterWave", iwcard)) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200711 snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq);
Takashi Iwai654aa662005-11-17 17:13:43 +0100712 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 }
714 iwcard->irq = xirq;
715
716 if ((err = snd_cs4231_create(card,
717 gus->gf1.port + 0x10c, -1, xirq,
718 xdma2 < 0 ? xdma1 : xdma2, xdma1,
719 CS4231_HW_INTERWAVE,
720 CS4231_HWSHARE_IRQ |
721 CS4231_HWSHARE_DMA1 |
722 CS4231_HWSHARE_DMA2,
Takashi Iwai43bcd972005-09-05 17:19:20 +0200723 &cs4231)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100724 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200725
726 if ((err = snd_cs4231_pcm(cs4231, 0, &pcm)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100727 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 sprintf(pcm->name + strlen(pcm->name), " rev %c", gus->revision + 'A');
730 strcat(pcm->name, " (codec)");
Takashi Iwai43bcd972005-09-05 17:19:20 +0200731
732 if ((err = snd_cs4231_timer(cs4231, 2, NULL)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100733 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200734
735 if ((err = snd_cs4231_mixer(cs4231)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100736 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200737
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 if (pcm_channels[dev] > 0) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200739 if ((err = snd_gf1_pcm_new(gus, 1, 1, NULL)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100740 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 }
Takashi Iwai43bcd972005-09-05 17:19:20 +0200742 if ((err = snd_interwave_mixer(cs4231)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100743 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200744
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745#ifdef SNDRV_STB
746 {
Takashi Iwai5e2da202005-11-17 14:36:44 +0100747 struct snd_ctl_elem_id id1, id2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 memset(&id1, 0, sizeof(id1));
749 memset(&id2, 0, sizeof(id2));
750 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
751 strcpy(id1.name, "Master Playback Switch");
752 strcpy(id2.name, id1.name);
753 id2.index = 1;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200754 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100755 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 strcpy(id1.name, "Master Playback Volume");
757 strcpy(id2.name, id1.name);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200758 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100759 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200760 if ((err = snd_tea6330t_update_mixer(card, i2c_bus, 0, 1)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100761 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 }
763#endif
764
765 gus->uart_enable = midi[dev];
Takashi Iwai43bcd972005-09-05 17:19:20 +0200766 if ((err = snd_gf1_rawmidi_new(gus, 0, NULL)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100767 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769#ifndef SNDRV_STB
770 str = "AMD InterWave";
771 if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8)
772 str = "Dynasonic 3-D";
773#else
774 str = "InterWave STB";
775#endif
776 strcpy(card->driver, str);
777 strcpy(card->shortname, str);
778 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %d",
779 str,
780 gus->gf1.port,
781 xirq,
782 xdma1);
783 if (xdma2 >= 0)
784 sprintf(card->longname + strlen(card->longname), "&%d", xdma2);
785
Takashi Iwai43bcd972005-09-05 17:19:20 +0200786 if ((err = snd_card_register(card)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100787 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
789 iwcard->cs4231 = cs4231;
790 iwcard->gus = gus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792}
793
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100794static int __devinit snd_interwave_isa_probe1(int dev, struct device *devptr)
Takashi Iwai654aa662005-11-17 17:13:43 +0100795{
796 struct snd_card *card;
797 int err;
798
799 card = snd_interwave_card_new(dev);
800 if (! card)
801 return -ENOMEM;
802
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100803 snd_card_set_dev(card, devptr);
Takashi Iwai654aa662005-11-17 17:13:43 +0100804 if ((err = snd_interwave_probe(card, dev)) < 0) {
805 snd_card_free(card);
806 return err;
807 }
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100808 dev_set_drvdata(devptr, card);
Takashi Iwai654aa662005-11-17 17:13:43 +0100809 return 0;
810}
811
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100812static int __devinit snd_interwave_isa_match(struct device *pdev,
813 unsigned int dev)
Takashi Iwai654aa662005-11-17 17:13:43 +0100814{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100815 if (!enable[dev])
816 return 0;
817#ifdef CONFIG_PNP
818 if (isapnp[dev])
819 return 0;
820#endif
821 return 1;
822}
823
824static int __devinit snd_interwave_isa_probe(struct device *pdev,
825 unsigned int dev)
826{
Takashi Iwai654aa662005-11-17 17:13:43 +0100827 int err;
828 static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, -1};
829 static int possible_dmas[] = {0, 1, 3, 5, 6, 7, -1};
830
831 if (irq[dev] == SNDRV_AUTO_IRQ) {
832 if ((irq[dev] = snd_legacy_find_free_irq(possible_irqs)) < 0) {
833 snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
834 return -EBUSY;
835 }
836 }
837 if (dma1[dev] == SNDRV_AUTO_DMA) {
838 if ((dma1[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) {
839 snd_printk(KERN_ERR PFX "unable to find a free DMA1\n");
840 return -EBUSY;
841 }
842 }
843 if (dma2[dev] == SNDRV_AUTO_DMA) {
844 if ((dma2[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) {
845 snd_printk(KERN_ERR PFX "unable to find a free DMA2\n");
846 return -EBUSY;
847 }
848 }
849
850 if (port[dev] != SNDRV_AUTO_PORT)
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100851 return snd_interwave_isa_probe1(dev, pdev);
Takashi Iwai654aa662005-11-17 17:13:43 +0100852 else {
853 static long possible_ports[] = {0x210, 0x220, 0x230, 0x240, 0x250, 0x260};
854 int i;
855 for (i = 0; i < ARRAY_SIZE(possible_ports); i++) {
856 port[dev] = possible_ports[i];
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100857 err = snd_interwave_isa_probe1(dev, pdev);
Takashi Iwai654aa662005-11-17 17:13:43 +0100858 if (! err)
859 return 0;
860 }
861 return err;
862 }
863}
864
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100865static int __devexit snd_interwave_isa_remove(struct device *devptr, unsigned int dev)
Takashi Iwai654aa662005-11-17 17:13:43 +0100866{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100867 snd_card_free(dev_get_drvdata(devptr));
868 dev_set_drvdata(devptr, NULL);
Takashi Iwai654aa662005-11-17 17:13:43 +0100869 return 0;
870}
871
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100872static struct isa_driver snd_interwave_driver = {
873 .match = snd_interwave_isa_match,
874 .probe = snd_interwave_isa_probe,
875 .remove = __devexit_p(snd_interwave_isa_remove),
Takashi Iwai654aa662005-11-17 17:13:43 +0100876 /* FIXME: suspend,resume */
877 .driver = {
878 .name = INTERWAVE_DRIVER
879 },
880};
881
882#ifdef CONFIG_PNP
Takashi Iwai654aa662005-11-17 17:13:43 +0100883static int __devinit snd_interwave_pnp_detect(struct pnp_card_link *pcard,
884 const struct pnp_card_device_id *pid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
886 static int dev;
Takashi Iwai654aa662005-11-17 17:13:43 +0100887 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 int res;
889
890 for ( ; dev < SNDRV_CARDS; dev++) {
Takashi Iwai654aa662005-11-17 17:13:43 +0100891 if (enable[dev] && isapnp[dev])
892 break;
893 }
894 if (dev >= SNDRV_CARDS)
895 return -ENODEV;
896
897 card = snd_interwave_card_new(dev);
898 if (! card)
899 return -ENOMEM;
900
901 if ((res = snd_interwave_pnp(dev, card->private_data, pcard, pid)) < 0) {
902 snd_card_free(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 return res;
904 }
Takashi Iwai654aa662005-11-17 17:13:43 +0100905 snd_card_set_dev(card, &pcard->card->dev);
906 if ((res = snd_interwave_probe(card, dev)) < 0) {
907 snd_card_free(card);
908 return res;
909 }
910 pnp_set_card_drvdata(pcard, card);
911 dev++;
912 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913}
914
915static void __devexit snd_interwave_pnp_remove(struct pnp_card_link * pcard)
916{
Takashi Iwai654aa662005-11-17 17:13:43 +0100917 snd_card_free(pnp_get_card_drvdata(pcard));
918 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919}
920
921static struct pnp_card_driver interwave_pnpc_driver = {
922 .flags = PNP_DRIVER_RES_DISABLE,
Takashi Iwai654aa662005-11-17 17:13:43 +0100923 .name = INTERWAVE_PNP_DRIVER,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 .id_table = snd_interwave_pnpids,
925 .probe = snd_interwave_pnp_detect,
926 .remove = __devexit_p(snd_interwave_pnp_remove),
Takashi Iwai654aa662005-11-17 17:13:43 +0100927 /* FIXME: suspend,resume */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928};
929
930#endif /* CONFIG_PNP */
931
932static int __init alsa_card_interwave_init(void)
933{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100934 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100936 err = isa_register_driver(&snd_interwave_driver, SNDRV_CARDS);
937 if (err < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100938 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939#ifdef CONFIG_PNP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 /* ISA PnP cards */
Bjorn Helgaasebdb71e2006-03-27 01:17:14 -0800941 err = pnp_register_card_driver(&interwave_pnpc_driver);
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100942 if (!err)
Clemens Ladischf7a92752005-12-07 09:13:42 +0100943 pnp_registered = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 return 0;
946}
947
948static void __exit alsa_card_interwave_exit(void)
949{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100950#ifdef CONFIG_PNP
951 if (pnp_registered)
952 pnp_unregister_card_driver(&interwave_pnpc_driver);
953#endif
954 isa_unregister_driver(&snd_interwave_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955}
956
957module_init(alsa_card_interwave_init)
958module_exit(alsa_card_interwave_exit)