1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for AMD InterWave soundcard
4 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
6 * 1999/07/22 Erik Inge Bolso <knan@mo.himolde.no>
7 * * mixer group handlers
10 #include <linux/init.h>
11 #include <linux/err.h>
12 #include <linux/isa.h>
13 #include <linux/delay.h>
14 #include <linux/pnp.h>
15 #include <linux/module.h>
17 #include <sound/core.h>
18 #include <sound/gus.h>
19 #include <sound/wss.h>
21 #include <sound/tea6330t.h>
23 #define SNDRV_LEGACY_FIND_FREE_IRQ
24 #define SNDRV_LEGACY_FIND_FREE_DMA
25 #include <sound/initval.h>
27 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
28 MODULE_LICENSE("GPL");
30 MODULE_DESCRIPTION("AMD InterWave");
32 MODULE_DESCRIPTION("AMD InterWave STB with TEA6330T");
35 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
36 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
37 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
39 static bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
41 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x210,0x220,0x230,0x240,0x250,0x260 */
43 static long port_tc[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x350,0x360,0x370,0x380 */
45 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 2,3,5,9,11,12,15 */
46 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
47 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
48 static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
49 /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
50 static int midi[SNDRV_CARDS];
51 static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
52 static int effect[SNDRV_CARDS];
55 #define PFX "interwave-stb: "
56 #define INTERWAVE_DRIVER "snd_interwave_stb"
57 #define INTERWAVE_PNP_DRIVER "interwave-stb"
59 #define PFX "interwave: "
60 #define INTERWAVE_DRIVER "snd_interwave"
61 #define INTERWAVE_PNP_DRIVER "interwave"
64 module_param_array(index, int, NULL, 0444);
65 MODULE_PARM_DESC(index, "Index value for InterWave soundcard.");
66 module_param_array(id, charp, NULL, 0444);
67 MODULE_PARM_DESC(id, "ID string for InterWave soundcard.");
68 module_param_array(enable, bool, NULL, 0444);
69 MODULE_PARM_DESC(enable, "Enable InterWave soundcard.");
71 module_param_array(isapnp, bool, NULL, 0444);
72 MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
74 module_param_hw_array(port, long, ioport, NULL, 0444);
75 MODULE_PARM_DESC(port, "Port # for InterWave driver.");
77 module_param_hw_array(port_tc, long, ioport, NULL, 0444);
78 MODULE_PARM_DESC(port_tc, "Tone control (TEA6330T - i2c bus) port # for InterWave driver.");
80 module_param_hw_array(irq, int, irq, NULL, 0444);
81 MODULE_PARM_DESC(irq, "IRQ # for InterWave driver.");
82 module_param_hw_array(dma1, int, dma, NULL, 0444);
83 MODULE_PARM_DESC(dma1, "DMA1 # for InterWave driver.");
84 module_param_hw_array(dma2, int, dma, NULL, 0444);
85 MODULE_PARM_DESC(dma2, "DMA2 # for InterWave driver.");
86 module_param_array(joystick_dac, int, NULL, 0444);
87 MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for InterWave driver.");
88 module_param_array(midi, int, NULL, 0444);
89 MODULE_PARM_DESC(midi, "MIDI UART enable for InterWave driver.");
90 module_param_array(pcm_channels, int, NULL, 0444);
91 MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for InterWave driver.");
92 module_param_array(effect, int, NULL, 0444);
93 MODULE_PARM_DESC(effect, "Effects enable for InterWave driver.");
95 struct snd_interwave {
97 struct snd_card *card;
98 struct snd_gus_card *gus;
101 struct resource *i2c_res;
103 unsigned short gus_status_reg;
104 unsigned short pcm_status_reg;
108 struct pnp_dev *devtc;
115 static int isa_registered;
116 static int pnp_registered;
118 static const struct pnp_card_device_id snd_interwave_pnpids[] = {
120 /* Gravis UltraSound Plug & Play */
121 { .id = "GRV0001", .devs = { { .id = "GRV0000" } } },
122 /* STB SoundRage32 */
123 { .id = "STB011a", .devs = { { .id = "STB0010" } } },
125 { .id = "DXP3201", .devs = { { .id = "DXP0010" } } },
127 /* This device also have CDC1117:DynaSonix Pro Audio Effects Processor */
128 { .id = "CDC1111", .devs = { { .id = "CDC1112" } } },
129 /* Panasonic PCA761AW Audio Card */
130 { .id = "ADV55ff", .devs = { { .id = "ADV0010" } } },
131 /* InterWave STB without TEA6330T */
132 { .id = "ADV550a", .devs = { { .id = "ADV0010" } } },
134 /* InterWave STB with TEA6330T */
135 { .id = "ADV550a", .devs = { { .id = "ADV0010" }, { .id = "ADV0015" } } },
140 MODULE_DEVICE_TABLE(pnp_card, snd_interwave_pnpids);
142 #endif /* CONFIG_PNP */
146 static void snd_interwave_i2c_setlines(struct snd_i2c_bus *bus, int ctrl, int data)
148 unsigned long port = bus->private_value;
151 printk(KERN_DEBUG "i2c_setlines - 0x%lx <- %i,%i\n", port, ctrl, data);
153 outb((data << 1) | ctrl, port);
157 static int snd_interwave_i2c_getclockline(struct snd_i2c_bus *bus)
159 unsigned long port = bus->private_value;
164 printk(KERN_DEBUG "i2c_getclockline - 0x%lx -> %i\n", port, res);
169 static int snd_interwave_i2c_getdataline(struct snd_i2c_bus *bus, int ack)
171 unsigned long port = bus->private_value;
176 res = (inb(port) & 2) >> 1;
178 printk(KERN_DEBUG "i2c_getdataline - 0x%lx -> %i\n", port, res);
183 static struct snd_i2c_bit_ops snd_interwave_i2c_bit_ops = {
184 .setlines = snd_interwave_i2c_setlines,
185 .getclock = snd_interwave_i2c_getclockline,
186 .getdata = snd_interwave_i2c_getdataline,
189 static int snd_interwave_detect_stb(struct snd_interwave *iwcard,
190 struct snd_gus_card *gus, int dev,
191 struct snd_i2c_bus **rbus)
194 struct snd_i2c_bus *bus;
195 struct snd_card *card = iwcard->card;
201 if (port == SNDRV_AUTO_PORT) {
203 if (gus->gf1.port == 0x250) {
206 while (port <= 0x380) {
207 iwcard->i2c_res = devm_request_region(card->dev, port, 1,
208 "InterWave (I2C bus)");
214 iwcard->i2c_res = devm_request_region(card->dev, port, 1,
215 "InterWave (I2C bus)");
217 if (iwcard->i2c_res == NULL) {
218 snd_printk(KERN_ERR "interwave: can't grab i2c bus port\n");
222 sprintf(name, "InterWave-%i", card->number);
223 err = snd_i2c_bus_create(card, name, NULL, &bus);
226 bus->private_value = port;
227 bus->hw_ops.bit = &snd_interwave_i2c_bit_ops;
228 err = snd_tea6330t_detect(bus, 0);
236 static int snd_interwave_detect(struct snd_interwave *iwcard,
237 struct snd_gus_card *gus,
240 , struct snd_i2c_bus **rbus
245 unsigned char rev1, rev2;
248 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
249 d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET);
250 if ((d & 0x07) != 0) {
251 snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
255 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
257 d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET);
258 if ((d & 0x07) != 1) {
259 snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
262 spin_lock_irqsave(&gus->reg_lock, flags);
263 rev1 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER);
264 snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, ~rev1);
265 rev2 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER);
266 snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, rev1);
267 spin_unlock_irqrestore(&gus->reg_lock, flags);
268 snd_printdd("[0x%lx] InterWave check - rev1=0x%x, rev2=0x%x\n", gus->gf1.port, rev1, rev2);
269 if ((rev1 & 0xf0) == (rev2 & 0xf0) &&
270 (rev1 & 0x0f) != (rev2 & 0x0f)) {
271 snd_printdd("[0x%lx] InterWave check - passed\n", gus->gf1.port);
273 strcpy(gus->card->shortname, "AMD InterWave");
274 gus->revision = rev1 >> 4;
276 return 0; /* ok.. We have an InterWave board */
278 return snd_interwave_detect_stb(iwcard, gus, dev, rbus);
281 snd_printdd("[0x%lx] InterWave check - failed\n", gus->gf1.port);
285 static irqreturn_t snd_interwave_interrupt(int irq, void *dev_id)
287 struct snd_interwave *iwcard = dev_id;
293 if (inb(iwcard->gus_status_reg)) {
295 snd_gus_interrupt(irq, iwcard->gus);
298 if (inb(iwcard->pcm_status_reg) & 0x01) { /* IRQ bit is set? */
300 snd_wss_interrupt(irq, iwcard->wss);
303 } while (loop && --max > 0);
304 return IRQ_RETVAL(handled);
307 static void snd_interwave_reset(struct snd_gus_card *gus)
309 snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x00);
311 snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x01);
315 static void snd_interwave_bank_sizes(struct snd_gus_card *gus, int *sizes)
321 for (idx = 0; idx < 4; idx++) {
324 for (local = idx << 22;
325 local < (idx << 22) + 0x400000;
326 local += 0x40000, d++) {
327 snd_gf1_poke(gus, local, d);
328 snd_gf1_poke(gus, local + 1, d + 1);
330 printk(KERN_DEBUG "d = 0x%x, local = 0x%x, "
331 "local + 1 = 0x%x, idx << 22 = 0x%x\n",
333 snd_gf1_peek(gus, local),
334 snd_gf1_peek(gus, local + 1),
335 snd_gf1_peek(gus, idx << 22));
337 if (snd_gf1_peek(gus, local) != d ||
338 snd_gf1_peek(gus, local + 1) != d + 1 ||
339 snd_gf1_peek(gus, idx << 22) != 0x55)
345 printk(KERN_DEBUG "sizes: %i %i %i %i\n",
346 sizes[0], sizes[1], sizes[2], sizes[3]);
351 /* 000 */ unsigned char iwave[8];
352 /* 008 */ unsigned char rom_hdr_revision;
353 /* 009 */ unsigned char series_number;
354 /* 010 */ unsigned char series_name[16];
355 /* 026 */ unsigned char date[10];
356 /* 036 */ unsigned short vendor_revision_major;
357 /* 038 */ unsigned short vendor_revision_minor;
358 /* 040 */ unsigned int rom_size;
359 /* 044 */ unsigned char copyright[128];
360 /* 172 */ unsigned char vendor_name[64];
361 /* 236 */ unsigned char rom_description[128];
362 /* 364 */ unsigned char pad[147];
363 /* 511 */ unsigned char csum;
366 static void snd_interwave_detect_memory(struct snd_gus_card *gus)
368 static const unsigned int lmc[13] =
370 0x00000001, 0x00000101, 0x01010101, 0x00000401,
371 0x04040401, 0x00040101, 0x04040101, 0x00000004,
372 0x00000404, 0x04040404, 0x00000010, 0x00001010,
377 unsigned int i, lmct;
379 unsigned char iwave[8];
382 snd_interwave_reset(gus);
383 snd_gf1_write8(gus, SNDRV_GF1_GB_GLOBAL_MODE, snd_gf1_read8(gus, SNDRV_GF1_GB_GLOBAL_MODE) | 0x01); /* enhanced mode */
384 snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01); /* DRAM I/O cycles selected */
385 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff10) | 0x004c);
386 /* ok.. simple test of memory size */
388 snd_gf1_poke(gus, 0, 0x55);
389 snd_gf1_poke(gus, 1, 0xaa);
391 if (snd_gf1_peek(gus, 0) == 0x55 && snd_gf1_peek(gus, 1) == 0xaa)
393 if (0) /* ok.. for testing of 0k RAM */
396 snd_interwave_bank_sizes(gus, psizes);
397 lmct = (psizes[3] << 24) | (psizes[2] << 16) |
398 (psizes[1] << 8) | psizes[0];
400 printk(KERN_DEBUG "lmct = 0x%08x\n", lmct);
402 for (i = 0; i < ARRAY_SIZE(lmc); i++)
403 if (lmct == lmc[i]) {
405 printk(KERN_DEBUG "found !!! %i\n", i);
407 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | i);
408 snd_interwave_bank_sizes(gus, psizes);
411 if (i >= ARRAY_SIZE(lmc) && !gus->gf1.enh_mode)
412 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | 2);
413 for (i = 0; i < 4; i++) {
414 gus->gf1.mem_alloc.banks_8[i].address =
415 gus->gf1.mem_alloc.banks_16[i].address = i << 22;
416 gus->gf1.mem_alloc.banks_8[i].size =
417 gus->gf1.mem_alloc.banks_16[i].size = psizes[i] << 18;
422 gus->gf1.memory = pages;
424 snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x03); /* select ROM */
425 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff1f) | (4 << 5));
426 gus->gf1.rom_banks = 0;
427 gus->gf1.rom_memory = 0;
428 for (bank_pos = 0; bank_pos < 16L * 1024L * 1024L; bank_pos += 4L * 1024L * 1024L) {
429 for (i = 0; i < 8; ++i)
430 iwave[i] = snd_gf1_peek(gus, bank_pos + i);
431 if (strncmp(iwave, "INTRWAVE", 8))
432 continue; /* first check */
434 for (i = 0; i < sizeof(struct rom_hdr); i++)
435 csum += snd_gf1_peek(gus, bank_pos + i);
437 continue; /* not valid rom */
438 gus->gf1.rom_banks++;
439 gus->gf1.rom_present |= 1 << (bank_pos >> 22);
440 gus->gf1.rom_memory = snd_gf1_peek(gus, bank_pos + 40) |
441 (snd_gf1_peek(gus, bank_pos + 41) << 8) |
442 (snd_gf1_peek(gus, bank_pos + 42) << 16) |
443 (snd_gf1_peek(gus, bank_pos + 43) << 24);
446 if (gus->gf1.rom_memory > 0) {
447 if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8)
448 gus->card->type = SNDRV_CARD_TYPE_IW_DYNASONIC;
451 snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x00); /* select RAM */
453 if (!gus->gf1.enh_mode)
454 snd_interwave_reset(gus);
457 static void snd_interwave_init(int dev, struct snd_gus_card *gus)
461 /* ok.. some InterWave specific initialization */
462 spin_lock_irqsave(&gus->reg_lock, flags);
463 snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, 0x00);
464 snd_gf1_write8(gus, SNDRV_GF1_GB_COMPATIBILITY, 0x1f);
465 snd_gf1_write8(gus, SNDRV_GF1_GB_DECODE_CONTROL, 0x49);
466 snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, 0x11);
467 snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_A, 0x00);
468 snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_B, 0x30);
469 snd_gf1_write8(gus, SNDRV_GF1_GB_EMULATION_IRQ, 0x00);
470 spin_unlock_irqrestore(&gus->reg_lock, flags);
475 gus->joystick_dac = joystick_dac[dev];
479 static const struct snd_kcontrol_new snd_interwave_controls[] = {
480 WSS_DOUBLE("Master Playback Switch", 0,
481 CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 7, 7, 1, 1),
482 WSS_DOUBLE("Master Playback Volume", 0,
483 CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 0, 0, 31, 1),
484 WSS_DOUBLE("Mic Playback Switch", 0,
485 CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 7, 7, 1, 1),
486 WSS_DOUBLE("Mic Playback Volume", 0,
487 CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 0, 0, 31, 1)
490 static int snd_interwave_mixer(struct snd_wss *chip)
492 struct snd_card *card = chip->card;
493 struct snd_ctl_elem_id id1, id2;
497 memset(&id1, 0, sizeof(id1));
498 memset(&id2, 0, sizeof(id2));
499 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
501 /* remove mono microphone controls */
502 strcpy(id1.name, "Mic Playback Switch");
503 err = snd_ctl_remove_id(card, &id1);
506 strcpy(id1.name, "Mic Playback Volume");
507 err = snd_ctl_remove_id(card, &id1);
511 /* add new master and mic controls */
512 for (idx = 0; idx < ARRAY_SIZE(snd_interwave_controls); idx++) {
513 err = snd_ctl_add(card, snd_ctl_new1(&snd_interwave_controls[idx], chip));
517 snd_wss_out(chip, CS4231_LINE_LEFT_OUTPUT, 0x9f);
518 snd_wss_out(chip, CS4231_LINE_RIGHT_OUTPUT, 0x9f);
519 snd_wss_out(chip, CS4231_LEFT_MIC_INPUT, 0x9f);
520 snd_wss_out(chip, CS4231_RIGHT_MIC_INPUT, 0x9f);
521 /* reassign AUXA to SYNTHESIZER */
522 strcpy(id1.name, "Aux Playback Switch");
523 strcpy(id2.name, "Synth Playback Switch");
524 err = snd_ctl_rename_id(card, &id1, &id2);
527 strcpy(id1.name, "Aux Playback Volume");
528 strcpy(id2.name, "Synth Playback Volume");
529 err = snd_ctl_rename_id(card, &id1, &id2);
532 /* reassign AUXB to CD */
533 strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
534 strcpy(id2.name, "CD Playback Switch");
535 err = snd_ctl_rename_id(card, &id1, &id2);
538 strcpy(id1.name, "Aux Playback Volume");
539 strcpy(id2.name, "CD Playback Volume");
540 err = snd_ctl_rename_id(card, &id1, &id2);
548 static int snd_interwave_pnp(int dev, struct snd_interwave *iwcard,
549 struct pnp_card_link *card,
550 const struct pnp_card_device_id *id)
552 struct pnp_dev *pdev;
555 iwcard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
556 if (iwcard->dev == NULL)
560 iwcard->devtc = pnp_request_card_device(card, id->devs[1].id, NULL);
561 if (iwcard->devtc == NULL)
564 /* Synth & Codec initialization */
567 err = pnp_activate_dev(pdev);
569 snd_printk(KERN_ERR "InterWave PnP configure failure (out of resources?)\n");
572 if (pnp_port_start(pdev, 0) + 0x100 != pnp_port_start(pdev, 1) ||
573 pnp_port_start(pdev, 0) + 0x10c != pnp_port_start(pdev, 2)) {
574 snd_printk(KERN_ERR "PnP configure failure (wrong ports)\n");
577 port[dev] = pnp_port_start(pdev, 0);
578 dma1[dev] = pnp_dma(pdev, 0);
580 dma2[dev] = pnp_dma(pdev, 1);
581 irq[dev] = pnp_irq(pdev, 0);
582 snd_printdd("isapnp IW: sb port=0x%llx, gf1 port=0x%llx, codec port=0x%llx\n",
583 (unsigned long long)pnp_port_start(pdev, 0),
584 (unsigned long long)pnp_port_start(pdev, 1),
585 (unsigned long long)pnp_port_start(pdev, 2));
586 snd_printdd("isapnp IW: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]);
588 /* Tone Control initialization */
589 pdev = iwcard->devtc;
591 err = pnp_activate_dev(pdev);
593 snd_printk(KERN_ERR "InterWave ToneControl PnP configure failure (out of resources?)\n");
596 port_tc[dev] = pnp_port_start(pdev, 0);
597 snd_printdd("isapnp IW: tone control port=0x%lx\n", port_tc[dev]);
601 #endif /* CONFIG_PNP */
603 static int snd_interwave_card_new(struct device *pdev, int dev,
604 struct snd_card **cardp)
606 struct snd_card *card;
607 struct snd_interwave *iwcard;
610 err = snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE,
611 sizeof(struct snd_interwave), &card);
614 iwcard = card->private_data;
621 static int snd_interwave_probe_gus(struct snd_card *card, int dev,
622 struct snd_gus_card **gusp)
624 return snd_gus_create(card, port[dev], -irq[dev], dma1[dev], dma2[dev],
625 0, 32, pcm_channels[dev], effect[dev], gusp);
628 static int snd_interwave_probe(struct snd_card *card, int dev,
629 struct snd_gus_card *gus)
631 int xirq, xdma1, xdma2;
632 struct snd_interwave *iwcard = card->private_data;
635 struct snd_i2c_bus *i2c_bus;
644 err = snd_interwave_detect(iwcard, gus, dev
652 iwcard->gus_status_reg = gus->gf1.reg_irqstat;
653 iwcard->pcm_status_reg = gus->gf1.port + 0x10c + 2;
655 snd_interwave_init(dev, gus);
656 snd_interwave_detect_memory(gus);
657 err = snd_gus_initialize(gus);
661 if (devm_request_irq(card->dev, xirq, snd_interwave_interrupt, 0,
662 "InterWave", iwcard)) {
663 snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq);
667 card->sync_irq = iwcard->irq;
669 err = snd_wss_create(card,
670 gus->gf1.port + 0x10c, -1, xirq,
671 xdma2 < 0 ? xdma1 : xdma2, xdma1,
680 err = snd_wss_pcm(wss, 0);
684 sprintf(wss->pcm->name + strlen(wss->pcm->name), " rev %c",
685 gus->revision + 'A');
686 strcat(wss->pcm->name, " (codec)");
688 err = snd_wss_timer(wss, 2);
692 err = snd_wss_mixer(wss);
696 if (pcm_channels[dev] > 0) {
697 err = snd_gf1_pcm_new(gus, 1, 1);
701 err = snd_interwave_mixer(wss);
707 struct snd_ctl_elem_id id1, id2;
708 memset(&id1, 0, sizeof(id1));
709 memset(&id2, 0, sizeof(id2));
710 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
711 strcpy(id1.name, "Master Playback Switch");
712 strcpy(id2.name, id1.name);
714 err = snd_ctl_rename_id(card, &id1, &id2);
717 strcpy(id1.name, "Master Playback Volume");
718 strcpy(id2.name, id1.name);
719 err = snd_ctl_rename_id(card, &id1, &id2);
722 err = snd_tea6330t_update_mixer(card, i2c_bus, 0, 1);
728 gus->uart_enable = midi[dev];
729 err = snd_gf1_rawmidi_new(gus, 0);
734 str = "AMD InterWave";
735 if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8)
736 str = "Dynasonic 3-D";
738 str = "InterWave STB";
740 strcpy(card->driver, str);
741 strcpy(card->shortname, str);
742 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %d",
748 sprintf(card->longname + strlen(card->longname), "&%d", xdma2);
750 err = snd_card_register(card);
759 static int snd_interwave_isa_match(struct device *pdev,
771 static int snd_interwave_isa_probe(struct device *pdev,
774 struct snd_card *card;
775 struct snd_gus_card *gus;
777 static const int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, -1};
778 static const int possible_dmas[] = {0, 1, 3, 5, 6, 7, -1};
780 if (irq[dev] == SNDRV_AUTO_IRQ) {
781 irq[dev] = snd_legacy_find_free_irq(possible_irqs);
783 snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
787 if (dma1[dev] == SNDRV_AUTO_DMA) {
788 dma1[dev] = snd_legacy_find_free_dma(possible_dmas);
790 snd_printk(KERN_ERR PFX "unable to find a free DMA1\n");
794 if (dma2[dev] == SNDRV_AUTO_DMA) {
795 dma2[dev] = snd_legacy_find_free_dma(possible_dmas);
797 snd_printk(KERN_ERR PFX "unable to find a free DMA2\n");
802 err = snd_interwave_card_new(pdev, dev, &card);
806 if (port[dev] != SNDRV_AUTO_PORT)
807 err = snd_interwave_probe_gus(card, dev, &gus);
809 static const long possible_ports[] = {0x210, 0x220, 0x230, 0x240, 0x250, 0x260};
811 for (i = 0; i < ARRAY_SIZE(possible_ports); i++) {
812 port[dev] = possible_ports[i];
813 err = snd_interwave_probe_gus(card, dev, &gus);
821 err = snd_interwave_probe(card, dev, gus);
825 dev_set_drvdata(pdev, card);
829 static struct isa_driver snd_interwave_driver = {
830 .match = snd_interwave_isa_match,
831 .probe = snd_interwave_isa_probe,
832 /* FIXME: suspend,resume */
834 .name = INTERWAVE_DRIVER
839 static int snd_interwave_pnp_detect(struct pnp_card_link *pcard,
840 const struct pnp_card_device_id *pid)
843 struct snd_card *card;
844 struct snd_gus_card *gus;
847 for ( ; dev < SNDRV_CARDS; dev++) {
848 if (enable[dev] && isapnp[dev])
851 if (dev >= SNDRV_CARDS)
854 res = snd_interwave_card_new(&pcard->card->dev, dev, &card);
858 res = snd_interwave_pnp(dev, card->private_data, pcard, pid);
861 res = snd_interwave_probe_gus(card, dev, &gus);
864 res = snd_interwave_probe(card, dev, gus);
867 pnp_set_card_drvdata(pcard, card);
872 static struct pnp_card_driver interwave_pnpc_driver = {
873 .flags = PNP_DRIVER_RES_DISABLE,
874 .name = INTERWAVE_PNP_DRIVER,
875 .id_table = snd_interwave_pnpids,
876 .probe = snd_interwave_pnp_detect,
877 /* FIXME: suspend,resume */
880 #endif /* CONFIG_PNP */
882 static int __init alsa_card_interwave_init(void)
886 err = isa_register_driver(&snd_interwave_driver, SNDRV_CARDS);
891 err = pnp_register_card_driver(&interwave_pnpc_driver);
901 static void __exit alsa_card_interwave_exit(void)
905 pnp_unregister_card_driver(&interwave_pnpc_driver);
908 isa_unregister_driver(&snd_interwave_driver);
911 module_init(alsa_card_interwave_init)
912 module_exit(alsa_card_interwave_exit)