blob: 0220cdbe1a2a3866d38d52c5ed81a1b4f6ec5c94 [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
Rene Herman609d7692007-05-15 11:42:56 +0200138static int isa_registered;
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100139static int pnp_registered;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141static struct pnp_card_device_id snd_interwave_pnpids[] = {
142#ifndef SNDRV_STB
143 /* Gravis UltraSound Plug & Play */
144 { .id = "GRV0001", .devs = { { .id = "GRV0000" } } },
145 /* STB SoundRage32 */
146 { .id = "STB011a", .devs = { { .id = "STB0010" } } },
147 /* MED3210 */
148 { .id = "DXP3201", .devs = { { .id = "DXP0010" } } },
149 /* Dynasonic Pro */
150 /* This device also have CDC1117:DynaSonix Pro Audio Effects Processor */
151 { .id = "CDC1111", .devs = { { .id = "CDC1112" } } },
152 /* Panasonic PCA761AW Audio Card */
153 { .id = "ADV55ff", .devs = { { .id = "ADV0010" } } },
154 /* InterWave STB without TEA6330T */
155 { .id = "ADV550a", .devs = { { .id = "ADV0010" } } },
156#else
157 /* InterWave STB with TEA6330T */
158 { .id = "ADV550a", .devs = { { .id = "ADV0010" }, { .id = "ADV0015" } } },
159#endif
160 { .id = "" }
161};
162
163MODULE_DEVICE_TABLE(pnp_card, snd_interwave_pnpids);
164
165#endif /* CONFIG_PNP */
166
167
168#ifdef SNDRV_STB
Takashi Iwai5e2da202005-11-17 14:36:44 +0100169static void snd_interwave_i2c_setlines(struct snd_i2c_bus *bus, int ctrl, int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170{
171 unsigned long port = bus->private_value;
172
173#if 0
174 printk("i2c_setlines - 0x%lx <- %i,%i\n", port, ctrl, data);
175#endif
176 outb((data << 1) | ctrl, port);
177 udelay(10);
178}
179
Takashi Iwai5e2da202005-11-17 14:36:44 +0100180static int snd_interwave_i2c_getclockline(struct snd_i2c_bus *bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
182 unsigned long port = bus->private_value;
183 unsigned char res;
184
185 res = inb(port) & 1;
186#if 0
187 printk("i2c_getclockline - 0x%lx -> %i\n", port, res);
188#endif
189 return res;
190}
191
Takashi Iwai5e2da202005-11-17 14:36:44 +0100192static int snd_interwave_i2c_getdataline(struct snd_i2c_bus *bus, int ack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193{
194 unsigned long port = bus->private_value;
195 unsigned char res;
196
197 if (ack)
198 udelay(10);
199 res = (inb(port) & 2) >> 1;
200#if 0
201 printk("i2c_getdataline - 0x%lx -> %i\n", port, res);
202#endif
203 return res;
204}
205
Takashi Iwai5e2da202005-11-17 14:36:44 +0100206static struct snd_i2c_bit_ops snd_interwave_i2c_bit_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 .setlines = snd_interwave_i2c_setlines,
208 .getclock = snd_interwave_i2c_getclockline,
209 .getdata = snd_interwave_i2c_getdataline,
210};
211
212static int __devinit snd_interwave_detect_stb(struct snd_interwave *iwcard,
Takashi Iwai5e2da202005-11-17 14:36:44 +0100213 struct snd_gus_card * gus, int dev,
214 struct snd_i2c_bus **rbus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
216 unsigned long port;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100217 struct snd_i2c_bus *bus;
218 struct snd_card *card = iwcard->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 char name[32];
220 int err;
221
222 *rbus = NULL;
223 port = port_tc[dev];
224 if (port == SNDRV_AUTO_PORT) {
225 port = 0x350;
226 if (gus->gf1.port == 0x250) {
227 port = 0x360;
228 }
229 while (port <= 0x380) {
230 if ((iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)")) != NULL)
231 break;
232 port += 0x10;
233 }
234 } else {
235 iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)");
236 }
237 if (iwcard->i2c_res == NULL) {
238 snd_printk(KERN_ERR "interwave: can't grab i2c bus port\n");
239 return -ENODEV;
240 }
241
242 sprintf(name, "InterWave-%i", card->number);
243 if ((err = snd_i2c_bus_create(card, name, NULL, &bus)) < 0)
244 return err;
245 bus->private_value = port;
246 bus->hw_ops.bit = &snd_interwave_i2c_bit_ops;
247 if ((err = snd_tea6330t_detect(bus, 0)) < 0)
248 return err;
249 *rbus = bus;
250 return 0;
251}
252#endif
253
254static int __devinit snd_interwave_detect(struct snd_interwave *iwcard,
Takashi Iwai5e2da202005-11-17 14:36:44 +0100255 struct snd_gus_card * gus,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 int dev
257#ifdef SNDRV_STB
Takashi Iwai5e2da202005-11-17 14:36:44 +0100258 , struct snd_i2c_bus **rbus
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259#endif
260 )
261{
262 unsigned long flags;
263 unsigned char rev1, rev2;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200264 int d;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
266 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
Takashi Iwai43bcd972005-09-05 17:19:20 +0200267 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
268 snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 return -ENODEV;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200270 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 udelay(160);
272 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
273 udelay(160);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200274 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
275 snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 return -ENODEV;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 spin_lock_irqsave(&gus->reg_lock, flags);
279 rev1 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER);
280 snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, ~rev1);
281 rev2 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER);
282 snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, rev1);
283 spin_unlock_irqrestore(&gus->reg_lock, flags);
284 snd_printdd("[0x%lx] InterWave check - rev1=0x%x, rev2=0x%x\n", gus->gf1.port, rev1, rev2);
285 if ((rev1 & 0xf0) == (rev2 & 0xf0) &&
286 (rev1 & 0x0f) != (rev2 & 0x0f)) {
287 snd_printdd("[0x%lx] InterWave check - passed\n", gus->gf1.port);
288 gus->interwave = 1;
289 strcpy(gus->card->shortname, "AMD InterWave");
290 gus->revision = rev1 >> 4;
291#ifndef SNDRV_STB
292 return 0; /* ok.. We have an InterWave board */
293#else
294 return snd_interwave_detect_stb(iwcard, gus, dev, rbus);
295#endif
296 }
297 snd_printdd("[0x%lx] InterWave check - failed\n", gus->gf1.port);
298 return -ENODEV;
299}
300
David Howells7d12e782006-10-05 14:55:46 +0100301static irqreturn_t snd_interwave_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400303 struct snd_interwave *iwcard = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 int loop, max = 5;
305 int handled = 0;
306
307 do {
308 loop = 0;
309 if (inb(iwcard->gus_status_reg)) {
310 handled = 1;
David Howells7d12e782006-10-05 14:55:46 +0100311 snd_gus_interrupt(irq, iwcard->gus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 loop++;
313 }
314 if (inb(iwcard->pcm_status_reg) & 0x01) { /* IRQ bit is set? */
315 handled = 1;
David Howells7d12e782006-10-05 14:55:46 +0100316 snd_cs4231_interrupt(irq, iwcard->cs4231);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 loop++;
318 }
319 } while (loop && --max > 0);
320 return IRQ_RETVAL(handled);
321}
322
Takashi Iwai5e2da202005-11-17 14:36:44 +0100323static void __devinit snd_interwave_reset(struct snd_gus_card * gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
325 snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x00);
326 udelay(160);
327 snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x01);
328 udelay(160);
329}
330
Takashi Iwai5e2da202005-11-17 14:36:44 +0100331static void __devinit snd_interwave_bank_sizes(struct snd_gus_card * gus, int *sizes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
333 unsigned int idx;
334 unsigned int local;
335 unsigned char d;
336
337 for (idx = 0; idx < 4; idx++) {
338 sizes[idx] = 0;
339 d = 0x55;
340 for (local = idx << 22;
341 local < (idx << 22) + 0x400000;
342 local += 0x40000, d++) {
343 snd_gf1_poke(gus, local, d);
344 snd_gf1_poke(gus, local + 1, d + 1);
345#if 0
346 printk("d = 0x%x, local = 0x%x, local + 1 = 0x%x, idx << 22 = 0x%x\n",
347 d,
348 snd_gf1_peek(gus, local),
349 snd_gf1_peek(gus, local + 1),
350 snd_gf1_peek(gus, idx << 22));
351#endif
352 if (snd_gf1_peek(gus, local) != d ||
353 snd_gf1_peek(gus, local + 1) != d + 1 ||
354 snd_gf1_peek(gus, idx << 22) != 0x55)
355 break;
356 sizes[idx]++;
357 }
358 }
359#if 0
360 printk("sizes: %i %i %i %i\n", sizes[0], sizes[1], sizes[2], sizes[3]);
361#endif
362}
363
364struct 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 Iwai5e2da202005-11-17 14:36:44 +0100380static void __devinit snd_interwave_detect_memory(struct snd_gus_card * gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
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
414 printk("lmct = 0x%08x\n", lmct);
415#endif
416 for (i = 0; i < ARRAY_SIZE(lmc); i++)
417 if (lmct == lmc[i]) {
418#if 0
419 printk("found !!! %i\n", i);
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
Takashi Iwai99b359b2005-10-20 18:26:44 +0200446 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 -0700447 iwave[0], iwave[1], iwave[2], iwave[3],
448 iwave[4], iwave[5], iwave[6], iwave[7]);
449#endif
450 if (strncmp(iwave, "INTRWAVE", 8))
451 continue; /* first check */
452 csum = 0;
453 for (i = 0; i < sizeof(struct rom_hdr); i++)
454 csum += snd_gf1_peek(gus, bank_pos + i);
455#ifdef CONFIG_SND_DEBUG_ROM
Takashi Iwai99b359b2005-10-20 18:26:44 +0200456 printk(KERN_DEBUG "ROM checksum = 0x%x (computed)\n", csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#endif
458 if (csum != 0)
459 continue; /* not valid rom */
460 gus->gf1.rom_banks++;
461 gus->gf1.rom_present |= 1 << (bank_pos >> 22);
462 gus->gf1.rom_memory = snd_gf1_peek(gus, bank_pos + 40) |
463 (snd_gf1_peek(gus, bank_pos + 41) << 8) |
464 (snd_gf1_peek(gus, bank_pos + 42) << 16) |
465 (snd_gf1_peek(gus, bank_pos + 43) << 24);
466 }
467#if 0
468 if (gus->gf1.rom_memory > 0) {
469 if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8)
470 gus->card->type = SNDRV_CARD_TYPE_IW_DYNASONIC;
471 }
472#endif
473 snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x00); /* select RAM */
474
475 if (!gus->gf1.enh_mode)
476 snd_interwave_reset(gus);
477}
478
Takashi Iwai5e2da202005-11-17 14:36:44 +0100479static void __devinit snd_interwave_init(int dev, struct snd_gus_card * gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
481 unsigned long flags;
482
483 /* ok.. some InterWave specific initialization */
484 spin_lock_irqsave(&gus->reg_lock, flags);
485 snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, 0x00);
486 snd_gf1_write8(gus, SNDRV_GF1_GB_COMPATIBILITY, 0x1f);
487 snd_gf1_write8(gus, SNDRV_GF1_GB_DECODE_CONTROL, 0x49);
488 snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, 0x11);
489 snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_A, 0x00);
490 snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_B, 0x30);
491 snd_gf1_write8(gus, SNDRV_GF1_GB_EMULATION_IRQ, 0x00);
492 spin_unlock_irqrestore(&gus->reg_lock, flags);
493 gus->equal_irq = 1;
494 gus->codec_flag = 1;
495 gus->interwave = 1;
496 gus->max_flag = 1;
497 gus->joystick_dac = joystick_dac[dev];
498
499}
500
Takashi Iwai5e2da202005-11-17 14:36:44 +0100501static struct snd_kcontrol_new snd_interwave_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502CS4231_DOUBLE("Master Playback Switch", 0, CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 7, 7, 1, 1),
503CS4231_DOUBLE("Master Playback Volume", 0, CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 0, 0, 31, 1),
504CS4231_DOUBLE("Mic Playback Switch", 0, CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 7, 7, 1, 1),
505CS4231_DOUBLE("Mic Playback Volume", 0, CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 0, 0, 31, 1)
506};
507
Takashi Iwai5e2da202005-11-17 14:36:44 +0100508static int __devinit snd_interwave_mixer(struct snd_cs4231 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509{
Takashi Iwai5e2da202005-11-17 14:36:44 +0100510 struct snd_card *card = chip->card;
511 struct snd_ctl_elem_id id1, id2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 unsigned int idx;
513 int err;
514
515 memset(&id1, 0, sizeof(id1));
516 memset(&id2, 0, sizeof(id2));
517 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
518#if 0
519 /* remove mono microphone controls */
520 strcpy(id1.name, "Mic Playback Switch");
521 if ((err = snd_ctl_remove_id(card, &id1)) < 0)
522 return err;
523 strcpy(id1.name, "Mic Playback Volume");
524 if ((err = snd_ctl_remove_id(card, &id1)) < 0)
525 return err;
526#endif
527 /* add new master and mic controls */
528 for (idx = 0; idx < ARRAY_SIZE(snd_interwave_controls); idx++)
529 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_interwave_controls[idx], chip))) < 0)
530 return err;
531 snd_cs4231_out(chip, CS4231_LINE_LEFT_OUTPUT, 0x9f);
532 snd_cs4231_out(chip, CS4231_LINE_RIGHT_OUTPUT, 0x9f);
533 snd_cs4231_out(chip, CS4231_LEFT_MIC_INPUT, 0x9f);
534 snd_cs4231_out(chip, CS4231_RIGHT_MIC_INPUT, 0x9f);
535 /* reassign AUXA to SYNTHESIZER */
536 strcpy(id1.name, "Aux Playback Switch");
537 strcpy(id2.name, "Synth Playback Switch");
538 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
539 return err;
540 strcpy(id1.name, "Aux Playback Volume");
541 strcpy(id2.name, "Synth Playback Volume");
542 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
543 return err;
544 /* reassign AUXB to CD */
545 strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
546 strcpy(id2.name, "CD Playback Switch");
547 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
548 return err;
549 strcpy(id1.name, "Aux Playback Volume");
550 strcpy(id2.name, "CD Playback Volume");
551 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
552 return err;
553 return 0;
554}
555
556#ifdef CONFIG_PNP
557
558static int __devinit snd_interwave_pnp(int dev, struct snd_interwave *iwcard,
559 struct pnp_card_link *card,
560 const struct pnp_card_device_id *id)
561{
562 struct pnp_dev *pdev;
563 struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
564 int err;
565
Amit Choudhary4a81a212006-10-09 16:02:49 +0200566 if (!cfg)
567 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 iwcard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
569 if (iwcard->dev == NULL) {
570 kfree(cfg);
571 return -EBUSY;
572 }
573#ifdef SNDRV_STB
574 iwcard->devtc = pnp_request_card_device(card, id->devs[1].id, NULL);
575 if (iwcard->devtc == NULL) {
576 kfree(cfg);
577 return -EBUSY;
578 }
579#endif
580 /* Synth & Codec initialization */
581 pdev = iwcard->dev;
582 pnp_init_resource_table(cfg);
583 if (port[dev] != SNDRV_AUTO_PORT) {
584 pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
585 pnp_resource_change(&cfg->port_resource[1], port[dev] + 0x100, 12);
586 pnp_resource_change(&cfg->port_resource[2], port[dev] + 0x10c, 4);
587 }
588 if (dma1[dev] != SNDRV_AUTO_DMA)
589 pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
590 if (dma2[dev] != SNDRV_AUTO_DMA)
591 pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
592 if (dma2[dev] < 0)
593 pnp_resource_change(&cfg->dma_resource[1], 4, 1);
594 if (irq[dev] != SNDRV_AUTO_IRQ)
595 pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
596 if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
597 snd_printk(KERN_ERR "InterWave - Synth - the requested resources are invalid, using auto config\n");
598 err = pnp_activate_dev(pdev);
599 if (err < 0) {
600 kfree(cfg);
601 snd_printk(KERN_ERR "InterWave PnP configure failure (out of resources?)\n");
602 return err;
603 }
604 if (pnp_port_start(pdev, 0) + 0x100 != pnp_port_start(pdev, 1) ||
605 pnp_port_start(pdev, 0) + 0x10c != pnp_port_start(pdev, 2)) {
606 kfree(cfg);
607 snd_printk(KERN_ERR "PnP configure failure (wrong ports)\n");
608 return -ENOENT;
609 }
610 port[dev] = pnp_port_start(pdev, 0);
611 dma1[dev] = pnp_dma(pdev, 0);
612 if (dma2[dev] >= 0)
613 dma2[dev] = pnp_dma(pdev, 1);
614 irq[dev] = pnp_irq(pdev, 0);
Greg Kroah-Hartmanaa0a2dd2006-06-12 14:50:27 -0700615 snd_printdd("isapnp IW: sb port=0x%llx, gf1 port=0x%llx, codec port=0x%llx\n",
616 (unsigned long long)pnp_port_start(pdev, 0),
617 (unsigned long long)pnp_port_start(pdev, 1),
618 (unsigned long long)pnp_port_start(pdev, 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 snd_printdd("isapnp IW: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]);
620#ifdef SNDRV_STB
621 /* Tone Control initialization */
622 pdev = iwcard->devtc;
623 pnp_init_resource_table(cfg);
624 if (port_tc[dev] != SNDRV_AUTO_PORT)
625 pnp_resource_change(&cfg->port_resource[0], port_tc[dev], 1);
626 if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
627 snd_printk(KERN_ERR "InterWave - ToneControl - the requested resources are invalid, using auto config\n");
628 err = pnp_activate_dev(pdev);
629 if (err < 0) {
630 kfree(cfg);
631 snd_printk(KERN_ERR "InterWave ToneControl PnP configure failure (out of resources?)\n");
632 return err;
633 }
634 port_tc[dev] = pnp_port_start(pdev, 0);
635 snd_printdd("isapnp IW: tone control port=0x%lx\n", port_tc[dev]);
636#endif
637 kfree(cfg);
638 return 0;
639}
640#endif /* CONFIG_PNP */
641
Takashi Iwai5e2da202005-11-17 14:36:44 +0100642static void snd_interwave_free(struct snd_card *card)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643{
Takashi Iwai654aa662005-11-17 17:13:43 +0100644 struct snd_interwave *iwcard = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646 if (iwcard == NULL)
647 return;
648#ifdef SNDRV_STB
Takashi Iwaib1d57762005-10-10 11:56:31 +0200649 release_and_free_resource(iwcard->i2c_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650#endif
651 if (iwcard->irq >= 0)
652 free_irq(iwcard->irq, (void *)iwcard);
653}
654
Takashi Iwai654aa662005-11-17 17:13:43 +0100655static struct snd_card *snd_interwave_card_new(int dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656{
Takashi Iwai5e2da202005-11-17 14:36:44 +0100657 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 struct snd_interwave *iwcard;
Takashi Iwai654aa662005-11-17 17:13:43 +0100659
660 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
661 sizeof(struct snd_interwave));
662 if (card == NULL)
663 return NULL;
664 iwcard = card->private_data;
665 iwcard->card = card;
666 iwcard->irq = -1;
667 card->private_free = snd_interwave_free;
668 return card;
669}
670
671static int __devinit snd_interwave_probe(struct snd_card *card, int dev)
672{
673 int xirq, xdma1, xdma2;
674 struct snd_interwave *iwcard = card->private_data;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100675 struct snd_cs4231 *cs4231;
676 struct snd_gus_card *gus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677#ifdef SNDRV_STB
Takashi Iwai5e2da202005-11-17 14:36:44 +0100678 struct snd_i2c_bus *i2c_bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679#endif
Takashi Iwai5e2da202005-11-17 14:36:44 +0100680 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 char *str;
682 int err;
683
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 xirq = irq[dev];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 xdma1 = dma1[dev];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 xdma2 = dma2[dev];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
688 if ((err = snd_gus_create(card,
689 port[dev],
690 -xirq, xdma1, xdma2,
691 0, 32,
Takashi Iwai43bcd972005-09-05 17:19:20 +0200692 pcm_channels[dev], effect[dev], &gus)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100693 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 if ((err = snd_interwave_detect(iwcard, gus, dev
696#ifdef SNDRV_STB
697 , &i2c_bus
698#endif
Takashi Iwai43bcd972005-09-05 17:19:20 +0200699 )) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100700 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200701
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 iwcard->gus_status_reg = gus->gf1.reg_irqstat;
703 iwcard->pcm_status_reg = gus->gf1.port + 0x10c + 2;
704
705 snd_interwave_init(dev, gus);
706 snd_interwave_detect_memory(gus);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200707 if ((err = snd_gus_initialize(gus)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100708 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Thomas Gleixner65ca68b2006-07-01 19:29:46 -0700710 if (request_irq(xirq, snd_interwave_interrupt, IRQF_DISABLED,
Takashi Iwai654aa662005-11-17 17:13:43 +0100711 "InterWave", iwcard)) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200712 snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq);
Takashi Iwai654aa662005-11-17 17:13:43 +0100713 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 }
715 iwcard->irq = xirq;
716
717 if ((err = snd_cs4231_create(card,
718 gus->gf1.port + 0x10c, -1, xirq,
719 xdma2 < 0 ? xdma1 : xdma2, xdma1,
720 CS4231_HW_INTERWAVE,
721 CS4231_HWSHARE_IRQ |
722 CS4231_HWSHARE_DMA1 |
723 CS4231_HWSHARE_DMA2,
Takashi Iwai43bcd972005-09-05 17:19:20 +0200724 &cs4231)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100725 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200726
727 if ((err = snd_cs4231_pcm(cs4231, 0, &pcm)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100728 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 sprintf(pcm->name + strlen(pcm->name), " rev %c", gus->revision + 'A');
731 strcat(pcm->name, " (codec)");
Takashi Iwai43bcd972005-09-05 17:19:20 +0200732
733 if ((err = snd_cs4231_timer(cs4231, 2, NULL)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100734 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200735
736 if ((err = snd_cs4231_mixer(cs4231)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100737 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 if (pcm_channels[dev] > 0) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200740 if ((err = snd_gf1_pcm_new(gus, 1, 1, NULL)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100741 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 }
Takashi Iwai43bcd972005-09-05 17:19:20 +0200743 if ((err = snd_interwave_mixer(cs4231)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100744 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200745
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746#ifdef SNDRV_STB
747 {
Takashi Iwai5e2da202005-11-17 14:36:44 +0100748 struct snd_ctl_elem_id id1, id2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 memset(&id1, 0, sizeof(id1));
750 memset(&id2, 0, sizeof(id2));
751 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
752 strcpy(id1.name, "Master Playback Switch");
753 strcpy(id2.name, id1.name);
754 id2.index = 1;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200755 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100756 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 strcpy(id1.name, "Master Playback Volume");
758 strcpy(id2.name, id1.name);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200759 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100760 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200761 if ((err = snd_tea6330t_update_mixer(card, i2c_bus, 0, 1)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100762 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 }
764#endif
765
766 gus->uart_enable = midi[dev];
Takashi Iwai43bcd972005-09-05 17:19:20 +0200767 if ((err = snd_gf1_rawmidi_new(gus, 0, NULL)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100768 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
770#ifndef SNDRV_STB
771 str = "AMD InterWave";
772 if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8)
773 str = "Dynasonic 3-D";
774#else
775 str = "InterWave STB";
776#endif
777 strcpy(card->driver, str);
778 strcpy(card->shortname, str);
779 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %d",
780 str,
781 gus->gf1.port,
782 xirq,
783 xdma1);
784 if (xdma2 >= 0)
785 sprintf(card->longname + strlen(card->longname), "&%d", xdma2);
786
Takashi Iwai43bcd972005-09-05 17:19:20 +0200787 if ((err = snd_card_register(card)) < 0)
Takashi Iwai654aa662005-11-17 17:13:43 +0100788 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
790 iwcard->cs4231 = cs4231;
791 iwcard->gus = gus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793}
794
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100795static int __devinit snd_interwave_isa_probe1(int dev, struct device *devptr)
Takashi Iwai654aa662005-11-17 17:13:43 +0100796{
797 struct snd_card *card;
798 int err;
799
800 card = snd_interwave_card_new(dev);
801 if (! card)
802 return -ENOMEM;
803
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100804 snd_card_set_dev(card, devptr);
Takashi Iwai654aa662005-11-17 17:13:43 +0100805 if ((err = snd_interwave_probe(card, dev)) < 0) {
806 snd_card_free(card);
807 return err;
808 }
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100809 dev_set_drvdata(devptr, card);
Takashi Iwai654aa662005-11-17 17:13:43 +0100810 return 0;
811}
812
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100813static int __devinit snd_interwave_isa_match(struct device *pdev,
814 unsigned int dev)
Takashi Iwai654aa662005-11-17 17:13:43 +0100815{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100816 if (!enable[dev])
817 return 0;
818#ifdef CONFIG_PNP
819 if (isapnp[dev])
820 return 0;
821#endif
822 return 1;
823}
824
825static int __devinit snd_interwave_isa_probe(struct device *pdev,
826 unsigned int dev)
827{
Takashi Iwai654aa662005-11-17 17:13:43 +0100828 int err;
829 static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, -1};
830 static int possible_dmas[] = {0, 1, 3, 5, 6, 7, -1};
831
832 if (irq[dev] == SNDRV_AUTO_IRQ) {
833 if ((irq[dev] = snd_legacy_find_free_irq(possible_irqs)) < 0) {
834 snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
835 return -EBUSY;
836 }
837 }
838 if (dma1[dev] == SNDRV_AUTO_DMA) {
839 if ((dma1[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) {
840 snd_printk(KERN_ERR PFX "unable to find a free DMA1\n");
841 return -EBUSY;
842 }
843 }
844 if (dma2[dev] == SNDRV_AUTO_DMA) {
845 if ((dma2[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) {
846 snd_printk(KERN_ERR PFX "unable to find a free DMA2\n");
847 return -EBUSY;
848 }
849 }
850
851 if (port[dev] != SNDRV_AUTO_PORT)
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100852 return snd_interwave_isa_probe1(dev, pdev);
Takashi Iwai654aa662005-11-17 17:13:43 +0100853 else {
854 static long possible_ports[] = {0x210, 0x220, 0x230, 0x240, 0x250, 0x260};
855 int i;
856 for (i = 0; i < ARRAY_SIZE(possible_ports); i++) {
857 port[dev] = possible_ports[i];
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100858 err = snd_interwave_isa_probe1(dev, pdev);
Takashi Iwai654aa662005-11-17 17:13:43 +0100859 if (! err)
860 return 0;
861 }
862 return err;
863 }
864}
865
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100866static int __devexit snd_interwave_isa_remove(struct device *devptr, unsigned int dev)
Takashi Iwai654aa662005-11-17 17:13:43 +0100867{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100868 snd_card_free(dev_get_drvdata(devptr));
869 dev_set_drvdata(devptr, NULL);
Takashi Iwai654aa662005-11-17 17:13:43 +0100870 return 0;
871}
872
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100873static struct isa_driver snd_interwave_driver = {
874 .match = snd_interwave_isa_match,
875 .probe = snd_interwave_isa_probe,
876 .remove = __devexit_p(snd_interwave_isa_remove),
Takashi Iwai654aa662005-11-17 17:13:43 +0100877 /* FIXME: suspend,resume */
878 .driver = {
879 .name = INTERWAVE_DRIVER
880 },
881};
882
883#ifdef CONFIG_PNP
Takashi Iwai654aa662005-11-17 17:13:43 +0100884static int __devinit snd_interwave_pnp_detect(struct pnp_card_link *pcard,
885 const struct pnp_card_device_id *pid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886{
887 static int dev;
Takashi Iwai654aa662005-11-17 17:13:43 +0100888 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 int res;
890
891 for ( ; dev < SNDRV_CARDS; dev++) {
Takashi Iwai654aa662005-11-17 17:13:43 +0100892 if (enable[dev] && isapnp[dev])
893 break;
894 }
895 if (dev >= SNDRV_CARDS)
896 return -ENODEV;
897
898 card = snd_interwave_card_new(dev);
899 if (! card)
900 return -ENOMEM;
901
902 if ((res = snd_interwave_pnp(dev, card->private_data, pcard, pid)) < 0) {
903 snd_card_free(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 return res;
905 }
Takashi Iwai654aa662005-11-17 17:13:43 +0100906 snd_card_set_dev(card, &pcard->card->dev);
907 if ((res = snd_interwave_probe(card, dev)) < 0) {
908 snd_card_free(card);
909 return res;
910 }
911 pnp_set_card_drvdata(pcard, card);
912 dev++;
913 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914}
915
916static void __devexit snd_interwave_pnp_remove(struct pnp_card_link * pcard)
917{
Takashi Iwai654aa662005-11-17 17:13:43 +0100918 snd_card_free(pnp_get_card_drvdata(pcard));
919 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920}
921
922static struct pnp_card_driver interwave_pnpc_driver = {
923 .flags = PNP_DRIVER_RES_DISABLE,
Takashi Iwai654aa662005-11-17 17:13:43 +0100924 .name = INTERWAVE_PNP_DRIVER,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 .id_table = snd_interwave_pnpids,
926 .probe = snd_interwave_pnp_detect,
927 .remove = __devexit_p(snd_interwave_pnp_remove),
Takashi Iwai654aa662005-11-17 17:13:43 +0100928 /* FIXME: suspend,resume */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929};
930
931#endif /* CONFIG_PNP */
932
933static int __init alsa_card_interwave_init(void)
934{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100935 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100937 err = isa_register_driver(&snd_interwave_driver, SNDRV_CARDS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938#ifdef CONFIG_PNP
Rene Herman609d7692007-05-15 11:42:56 +0200939 if (!err)
940 isa_registered = 1;
941
Bjorn Helgaasebdb71e2006-03-27 01:17:14 -0800942 err = pnp_register_card_driver(&interwave_pnpc_driver);
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100943 if (!err)
Clemens Ladischf7a92752005-12-07 09:13:42 +0100944 pnp_registered = 1;
Rene Herman609d7692007-05-15 11:42:56 +0200945
946 if (isa_registered)
947 err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948#endif
Rene Herman609d7692007-05-15 11:42:56 +0200949 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950}
951
952static void __exit alsa_card_interwave_exit(void)
953{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100954#ifdef CONFIG_PNP
955 if (pnp_registered)
956 pnp_unregister_card_driver(&interwave_pnpc_driver);
Rene Herman609d7692007-05-15 11:42:56 +0200957 if (isa_registered)
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100958#endif
Rene Herman609d7692007-05-15 11:42:56 +0200959 isa_unregister_driver(&snd_interwave_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960}
961
962module_init(alsa_card_interwave_init)
963module_exit(alsa_card_interwave_exit)