2 * Driver for AMD InterWave soundcard
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
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.
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.
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
20 * 1999/07/22 Erik Inge Bolso <knan@mo.himolde.no>
21 * * mixer group handlers
25 #include <linux/init.h>
26 #include <linux/err.h>
27 #include <linux/isa.h>
28 #include <linux/delay.h>
29 #include <linux/pnp.h>
30 #include <linux/module.h>
32 #include <sound/core.h>
33 #include <sound/gus.h>
34 #include <sound/wss.h>
36 #include <sound/tea6330t.h>
38 #define SNDRV_LEGACY_FIND_FREE_IRQ
39 #define SNDRV_LEGACY_FIND_FREE_DMA
40 #include <sound/initval.h>
42 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
43 MODULE_LICENSE("GPL");
45 MODULE_DESCRIPTION("AMD InterWave");
46 MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Plug & Play},"
49 "{Dynasonix,Dynasonix Pro},"
50 "{Panasonic,PCA761AW}}");
52 MODULE_DESCRIPTION("AMD InterWave STB with TEA6330T");
53 MODULE_SUPPORTED_DEVICE("{{AMD,InterWave STB with TEA6330T}}");
56 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
57 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
58 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_ISAPNP
; /* Enable this card */
60 static bool isapnp
[SNDRV_CARDS
] = {[0 ... (SNDRV_CARDS
- 1)] = 1};
62 static long port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
; /* 0x210,0x220,0x230,0x240,0x250,0x260 */
64 static long port_tc
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
; /* 0x350,0x360,0x370,0x380 */
66 static int irq
[SNDRV_CARDS
] = SNDRV_DEFAULT_IRQ
; /* 2,3,5,9,11,12,15 */
67 static int dma1
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* 0,1,3,5,6,7 */
68 static int dma2
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* 0,1,3,5,6,7 */
69 static int joystick_dac
[SNDRV_CARDS
] = {[0 ... (SNDRV_CARDS
- 1)] = 29};
70 /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
71 static int midi
[SNDRV_CARDS
];
72 static int pcm_channels
[SNDRV_CARDS
] = {[0 ... (SNDRV_CARDS
- 1)] = 2};
73 static int effect
[SNDRV_CARDS
];
76 #define PFX "interwave-stb: "
77 #define INTERWAVE_DRIVER "snd_interwave_stb"
78 #define INTERWAVE_PNP_DRIVER "interwave-stb"
80 #define PFX "interwave: "
81 #define INTERWAVE_DRIVER "snd_interwave"
82 #define INTERWAVE_PNP_DRIVER "interwave"
85 module_param_array(index
, int, NULL
, 0444);
86 MODULE_PARM_DESC(index
, "Index value for InterWave soundcard.");
87 module_param_array(id
, charp
, NULL
, 0444);
88 MODULE_PARM_DESC(id
, "ID string for InterWave soundcard.");
89 module_param_array(enable
, bool, NULL
, 0444);
90 MODULE_PARM_DESC(enable
, "Enable InterWave soundcard.");
92 module_param_array(isapnp
, bool, NULL
, 0444);
93 MODULE_PARM_DESC(isapnp
, "ISA PnP detection for specified soundcard.");
95 module_param_array(port
, long, NULL
, 0444);
96 MODULE_PARM_DESC(port
, "Port # for InterWave driver.");
98 module_param_array(port_tc
, long, NULL
, 0444);
99 MODULE_PARM_DESC(port_tc
, "Tone control (TEA6330T - i2c bus) port # for InterWave driver.");
101 module_param_array(irq
, int, NULL
, 0444);
102 MODULE_PARM_DESC(irq
, "IRQ # for InterWave driver.");
103 module_param_array(dma1
, int, NULL
, 0444);
104 MODULE_PARM_DESC(dma1
, "DMA1 # for InterWave driver.");
105 module_param_array(dma2
, int, NULL
, 0444);
106 MODULE_PARM_DESC(dma2
, "DMA2 # for InterWave driver.");
107 module_param_array(joystick_dac
, int, NULL
, 0444);
108 MODULE_PARM_DESC(joystick_dac
, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for InterWave driver.");
109 module_param_array(midi
, int, NULL
, 0444);
110 MODULE_PARM_DESC(midi
, "MIDI UART enable for InterWave driver.");
111 module_param_array(pcm_channels
, int, NULL
, 0444);
112 MODULE_PARM_DESC(pcm_channels
, "Reserved PCM channels for InterWave driver.");
113 module_param_array(effect
, int, NULL
, 0444);
114 MODULE_PARM_DESC(effect
, "Effects enable for InterWave driver.");
116 struct snd_interwave
{
118 struct snd_card
*card
;
119 struct snd_gus_card
*gus
;
122 struct resource
*i2c_res
;
124 unsigned short gus_status_reg
;
125 unsigned short pcm_status_reg
;
129 struct pnp_dev
*devtc
;
136 static int isa_registered
;
137 static int pnp_registered
;
139 static struct pnp_card_device_id snd_interwave_pnpids
[] = {
141 /* Gravis UltraSound Plug & Play */
142 { .id
= "GRV0001", .devs
= { { .id
= "GRV0000" } } },
143 /* STB SoundRage32 */
144 { .id
= "STB011a", .devs
= { { .id
= "STB0010" } } },
146 { .id
= "DXP3201", .devs
= { { .id
= "DXP0010" } } },
148 /* This device also have CDC1117:DynaSonix Pro Audio Effects Processor */
149 { .id
= "CDC1111", .devs
= { { .id
= "CDC1112" } } },
150 /* Panasonic PCA761AW Audio Card */
151 { .id
= "ADV55ff", .devs
= { { .id
= "ADV0010" } } },
152 /* InterWave STB without TEA6330T */
153 { .id
= "ADV550a", .devs
= { { .id
= "ADV0010" } } },
155 /* InterWave STB with TEA6330T */
156 { .id
= "ADV550a", .devs
= { { .id
= "ADV0010" }, { .id
= "ADV0015" } } },
161 MODULE_DEVICE_TABLE(pnp_card
, snd_interwave_pnpids
);
163 #endif /* CONFIG_PNP */
167 static void snd_interwave_i2c_setlines(struct snd_i2c_bus
*bus
, int ctrl
, int data
)
169 unsigned long port
= bus
->private_value
;
172 printk(KERN_DEBUG
"i2c_setlines - 0x%lx <- %i,%i\n", port
, ctrl
, data
);
174 outb((data
<< 1) | ctrl
, port
);
178 static int snd_interwave_i2c_getclockline(struct snd_i2c_bus
*bus
)
180 unsigned long port
= bus
->private_value
;
185 printk(KERN_DEBUG
"i2c_getclockline - 0x%lx -> %i\n", port
, res
);
190 static int snd_interwave_i2c_getdataline(struct snd_i2c_bus
*bus
, int ack
)
192 unsigned long port
= bus
->private_value
;
197 res
= (inb(port
) & 2) >> 1;
199 printk(KERN_DEBUG
"i2c_getdataline - 0x%lx -> %i\n", port
, res
);
204 static struct snd_i2c_bit_ops snd_interwave_i2c_bit_ops
= {
205 .setlines
= snd_interwave_i2c_setlines
,
206 .getclock
= snd_interwave_i2c_getclockline
,
207 .getdata
= snd_interwave_i2c_getdataline
,
210 static int __devinit
snd_interwave_detect_stb(struct snd_interwave
*iwcard
,
211 struct snd_gus_card
* gus
, int dev
,
212 struct snd_i2c_bus
**rbus
)
215 struct snd_i2c_bus
*bus
;
216 struct snd_card
*card
= iwcard
->card
;
222 if (port
== SNDRV_AUTO_PORT
) {
224 if (gus
->gf1
.port
== 0x250) {
227 while (port
<= 0x380) {
228 if ((iwcard
->i2c_res
= request_region(port
, 1, "InterWave (I2C bus)")) != NULL
)
233 iwcard
->i2c_res
= request_region(port
, 1, "InterWave (I2C bus)");
235 if (iwcard
->i2c_res
== NULL
) {
236 snd_printk(KERN_ERR
"interwave: can't grab i2c bus port\n");
240 sprintf(name
, "InterWave-%i", card
->number
);
241 if ((err
= snd_i2c_bus_create(card
, name
, NULL
, &bus
)) < 0)
243 bus
->private_value
= port
;
244 bus
->hw_ops
.bit
= &snd_interwave_i2c_bit_ops
;
245 if ((err
= snd_tea6330t_detect(bus
, 0)) < 0)
252 static int __devinit
snd_interwave_detect(struct snd_interwave
*iwcard
,
253 struct snd_gus_card
* gus
,
256 , struct snd_i2c_bus
**rbus
261 unsigned char rev1
, rev2
;
264 snd_gf1_i_write8(gus
, SNDRV_GF1_GB_RESET
, 0); /* reset GF1 */
265 if (((d
= snd_gf1_i_look8(gus
, SNDRV_GF1_GB_RESET
)) & 0x07) != 0) {
266 snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus
->gf1
.port
, d
);
270 snd_gf1_i_write8(gus
, SNDRV_GF1_GB_RESET
, 1); /* release reset */
272 if (((d
= snd_gf1_i_look8(gus
, SNDRV_GF1_GB_RESET
)) & 0x07) != 1) {
273 snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus
->gf1
.port
, d
);
276 spin_lock_irqsave(&gus
->reg_lock
, flags
);
277 rev1
= snd_gf1_look8(gus
, SNDRV_GF1_GB_VERSION_NUMBER
);
278 snd_gf1_write8(gus
, SNDRV_GF1_GB_VERSION_NUMBER
, ~rev1
);
279 rev2
= snd_gf1_look8(gus
, SNDRV_GF1_GB_VERSION_NUMBER
);
280 snd_gf1_write8(gus
, SNDRV_GF1_GB_VERSION_NUMBER
, rev1
);
281 spin_unlock_irqrestore(&gus
->reg_lock
, flags
);
282 snd_printdd("[0x%lx] InterWave check - rev1=0x%x, rev2=0x%x\n", gus
->gf1
.port
, rev1
, rev2
);
283 if ((rev1
& 0xf0) == (rev2
& 0xf0) &&
284 (rev1
& 0x0f) != (rev2
& 0x0f)) {
285 snd_printdd("[0x%lx] InterWave check - passed\n", gus
->gf1
.port
);
287 strcpy(gus
->card
->shortname
, "AMD InterWave");
288 gus
->revision
= rev1
>> 4;
290 return 0; /* ok.. We have an InterWave board */
292 return snd_interwave_detect_stb(iwcard
, gus
, dev
, rbus
);
295 snd_printdd("[0x%lx] InterWave check - failed\n", gus
->gf1
.port
);
299 static irqreturn_t
snd_interwave_interrupt(int irq
, void *dev_id
)
301 struct snd_interwave
*iwcard
= dev_id
;
307 if (inb(iwcard
->gus_status_reg
)) {
309 snd_gus_interrupt(irq
, iwcard
->gus
);
312 if (inb(iwcard
->pcm_status_reg
) & 0x01) { /* IRQ bit is set? */
314 snd_wss_interrupt(irq
, iwcard
->wss
);
317 } while (loop
&& --max
> 0);
318 return IRQ_RETVAL(handled
);
321 static void __devinit
snd_interwave_reset(struct snd_gus_card
* gus
)
323 snd_gf1_write8(gus
, SNDRV_GF1_GB_RESET
, 0x00);
325 snd_gf1_write8(gus
, SNDRV_GF1_GB_RESET
, 0x01);
329 static void __devinit
snd_interwave_bank_sizes(struct snd_gus_card
* gus
, int *sizes
)
335 for (idx
= 0; idx
< 4; idx
++) {
338 for (local
= idx
<< 22;
339 local
< (idx
<< 22) + 0x400000;
340 local
+= 0x40000, d
++) {
341 snd_gf1_poke(gus
, local
, d
);
342 snd_gf1_poke(gus
, local
+ 1, d
+ 1);
344 printk(KERN_DEBUG
"d = 0x%x, local = 0x%x, "
345 "local + 1 = 0x%x, idx << 22 = 0x%x\n",
347 snd_gf1_peek(gus
, local
),
348 snd_gf1_peek(gus
, local
+ 1),
349 snd_gf1_peek(gus
, idx
<< 22));
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)
359 printk(KERN_DEBUG
"sizes: %i %i %i %i\n",
360 sizes
[0], sizes
[1], sizes
[2], sizes
[3]);
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
;
380 static void __devinit
snd_interwave_detect_memory(struct snd_gus_card
* gus
)
382 static unsigned int lmc
[13] =
384 0x00000001, 0x00000101, 0x01010101, 0x00000401,
385 0x04040401, 0x00040101, 0x04040101, 0x00000004,
386 0x00000404, 0x04040404, 0x00000010, 0x00001010,
391 unsigned int i
, lmct
;
393 unsigned char iwave
[8];
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 */
402 snd_gf1_poke(gus
, 0, 0x55);
403 snd_gf1_poke(gus
, 1, 0xaa);
405 if (snd_gf1_peek(gus
, 0) == 0x55 && snd_gf1_peek(gus
, 1) == 0xaa)
407 if (0) /* ok.. for testing of 0k RAM */
410 snd_interwave_bank_sizes(gus
, psizes
);
411 lmct
= (psizes
[3] << 24) | (psizes
[2] << 16) |
412 (psizes
[1] << 8) | psizes
[0];
414 printk(KERN_DEBUG
"lmct = 0x%08x\n", lmct
);
416 for (i
= 0; i
< ARRAY_SIZE(lmc
); i
++)
417 if (lmct
== lmc
[i
]) {
419 printk(KERN_DEBUG
"found !!! %i\n", i
);
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
);
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;
436 gus
->gf1
.memory
= pages
;
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
446 printk(KERN_DEBUG
"ROM at 0x%06x = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", bank_pos
,
447 iwave
[0], iwave
[1], iwave
[2], iwave
[3],
448 iwave
[4], iwave
[5], iwave
[6], iwave
[7]);
450 if (strncmp(iwave
, "INTRWAVE", 8))
451 continue; /* first check */
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
456 printk(KERN_DEBUG
"ROM checksum = 0x%x (computed)\n", csum
);
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);
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
;
473 snd_gf1_write8(gus
, SNDRV_GF1_GB_MEMORY_CONTROL
, 0x00); /* select RAM */
475 if (!gus
->gf1
.enh_mode
)
476 snd_interwave_reset(gus
);
479 static void __devinit
snd_interwave_init(int dev
, struct snd_gus_card
* gus
)
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
);
497 gus
->joystick_dac
= joystick_dac
[dev
];
501 static struct snd_kcontrol_new snd_interwave_controls
[] = {
502 WSS_DOUBLE("Master Playback Switch", 0,
503 CS4231_LINE_LEFT_OUTPUT
, CS4231_LINE_RIGHT_OUTPUT
, 7, 7, 1, 1),
504 WSS_DOUBLE("Master Playback Volume", 0,
505 CS4231_LINE_LEFT_OUTPUT
, CS4231_LINE_RIGHT_OUTPUT
, 0, 0, 31, 1),
506 WSS_DOUBLE("Mic Playback Switch", 0,
507 CS4231_LEFT_MIC_INPUT
, CS4231_RIGHT_MIC_INPUT
, 7, 7, 1, 1),
508 WSS_DOUBLE("Mic Playback Volume", 0,
509 CS4231_LEFT_MIC_INPUT
, CS4231_RIGHT_MIC_INPUT
, 0, 0, 31, 1)
512 static int __devinit
snd_interwave_mixer(struct snd_wss
*chip
)
514 struct snd_card
*card
= chip
->card
;
515 struct snd_ctl_elem_id id1
, id2
;
519 memset(&id1
, 0, sizeof(id1
));
520 memset(&id2
, 0, sizeof(id2
));
521 id1
.iface
= id2
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
523 /* remove mono microphone controls */
524 strcpy(id1
.name
, "Mic Playback Switch");
525 if ((err
= snd_ctl_remove_id(card
, &id1
)) < 0)
527 strcpy(id1
.name
, "Mic Playback Volume");
528 if ((err
= snd_ctl_remove_id(card
, &id1
)) < 0)
531 /* add new master and mic controls */
532 for (idx
= 0; idx
< ARRAY_SIZE(snd_interwave_controls
); idx
++)
533 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_interwave_controls
[idx
], chip
))) < 0)
535 snd_wss_out(chip
, CS4231_LINE_LEFT_OUTPUT
, 0x9f);
536 snd_wss_out(chip
, CS4231_LINE_RIGHT_OUTPUT
, 0x9f);
537 snd_wss_out(chip
, CS4231_LEFT_MIC_INPUT
, 0x9f);
538 snd_wss_out(chip
, CS4231_RIGHT_MIC_INPUT
, 0x9f);
539 /* reassign AUXA to SYNTHESIZER */
540 strcpy(id1
.name
, "Aux Playback Switch");
541 strcpy(id2
.name
, "Synth Playback Switch");
542 if ((err
= snd_ctl_rename_id(card
, &id1
, &id2
)) < 0)
544 strcpy(id1
.name
, "Aux Playback Volume");
545 strcpy(id2
.name
, "Synth Playback Volume");
546 if ((err
= snd_ctl_rename_id(card
, &id1
, &id2
)) < 0)
548 /* reassign AUXB to CD */
549 strcpy(id1
.name
, "Aux Playback Switch"); id1
.index
= 1;
550 strcpy(id2
.name
, "CD Playback Switch");
551 if ((err
= snd_ctl_rename_id(card
, &id1
, &id2
)) < 0)
553 strcpy(id1
.name
, "Aux Playback Volume");
554 strcpy(id2
.name
, "CD Playback Volume");
555 if ((err
= snd_ctl_rename_id(card
, &id1
, &id2
)) < 0)
562 static int __devinit
snd_interwave_pnp(int dev
, struct snd_interwave
*iwcard
,
563 struct pnp_card_link
*card
,
564 const struct pnp_card_device_id
*id
)
566 struct pnp_dev
*pdev
;
569 iwcard
->dev
= pnp_request_card_device(card
, id
->devs
[0].id
, NULL
);
570 if (iwcard
->dev
== NULL
)
574 iwcard
->devtc
= pnp_request_card_device(card
, id
->devs
[1].id
, NULL
);
575 if (iwcard
->devtc
== NULL
)
578 /* Synth & Codec initialization */
581 err
= pnp_activate_dev(pdev
);
583 snd_printk(KERN_ERR
"InterWave PnP configure failure (out of resources?)\n");
586 if (pnp_port_start(pdev
, 0) + 0x100 != pnp_port_start(pdev
, 1) ||
587 pnp_port_start(pdev
, 0) + 0x10c != pnp_port_start(pdev
, 2)) {
588 snd_printk(KERN_ERR
"PnP configure failure (wrong ports)\n");
591 port
[dev
] = pnp_port_start(pdev
, 0);
592 dma1
[dev
] = pnp_dma(pdev
, 0);
594 dma2
[dev
] = pnp_dma(pdev
, 1);
595 irq
[dev
] = pnp_irq(pdev
, 0);
596 snd_printdd("isapnp IW: sb port=0x%llx, gf1 port=0x%llx, codec port=0x%llx\n",
597 (unsigned long long)pnp_port_start(pdev
, 0),
598 (unsigned long long)pnp_port_start(pdev
, 1),
599 (unsigned long long)pnp_port_start(pdev
, 2));
600 snd_printdd("isapnp IW: dma1=%i, dma2=%i, irq=%i\n", dma1
[dev
], dma2
[dev
], irq
[dev
]);
602 /* Tone Control initialization */
603 pdev
= iwcard
->devtc
;
605 err
= pnp_activate_dev(pdev
);
607 snd_printk(KERN_ERR
"InterWave ToneControl PnP configure failure (out of resources?)\n");
610 port_tc
[dev
] = pnp_port_start(pdev
, 0);
611 snd_printdd("isapnp IW: tone control port=0x%lx\n", port_tc
[dev
]);
615 #endif /* CONFIG_PNP */
617 static void snd_interwave_free(struct snd_card
*card
)
619 struct snd_interwave
*iwcard
= card
->private_data
;
624 release_and_free_resource(iwcard
->i2c_res
);
626 if (iwcard
->irq
>= 0)
627 free_irq(iwcard
->irq
, (void *)iwcard
);
630 static int snd_interwave_card_new(int dev
, struct snd_card
**cardp
)
632 struct snd_card
*card
;
633 struct snd_interwave
*iwcard
;
636 err
= snd_card_create(index
[dev
], id
[dev
], THIS_MODULE
,
637 sizeof(struct snd_interwave
), &card
);
640 iwcard
= card
->private_data
;
643 card
->private_free
= snd_interwave_free
;
648 static int __devinit
snd_interwave_probe(struct snd_card
*card
, int dev
)
650 int xirq
, xdma1
, xdma2
;
651 struct snd_interwave
*iwcard
= card
->private_data
;
653 struct snd_gus_card
*gus
;
655 struct snd_i2c_bus
*i2c_bus
;
665 if ((err
= snd_gus_create(card
,
669 pcm_channels
[dev
], effect
[dev
], &gus
)) < 0)
672 if ((err
= snd_interwave_detect(iwcard
, gus
, dev
679 iwcard
->gus_status_reg
= gus
->gf1
.reg_irqstat
;
680 iwcard
->pcm_status_reg
= gus
->gf1
.port
+ 0x10c + 2;
682 snd_interwave_init(dev
, gus
);
683 snd_interwave_detect_memory(gus
);
684 if ((err
= snd_gus_initialize(gus
)) < 0)
687 if (request_irq(xirq
, snd_interwave_interrupt
, 0,
688 "InterWave", iwcard
)) {
689 snd_printk(KERN_ERR PFX
"unable to grab IRQ %d\n", xirq
);
694 err
= snd_wss_create(card
,
695 gus
->gf1
.port
+ 0x10c, -1, xirq
,
696 xdma2
< 0 ? xdma1
: xdma2
, xdma1
,
705 err
= snd_wss_pcm(wss
, 0, &pcm
);
709 sprintf(pcm
->name
+ strlen(pcm
->name
), " rev %c", gus
->revision
+ 'A');
710 strcat(pcm
->name
, " (codec)");
712 err
= snd_wss_timer(wss
, 2, NULL
);
716 err
= snd_wss_mixer(wss
);
720 if (pcm_channels
[dev
] > 0) {
721 err
= snd_gf1_pcm_new(gus
, 1, 1, NULL
);
725 err
= snd_interwave_mixer(wss
);
731 struct snd_ctl_elem_id id1
, id2
;
732 memset(&id1
, 0, sizeof(id1
));
733 memset(&id2
, 0, sizeof(id2
));
734 id1
.iface
= id2
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
735 strcpy(id1
.name
, "Master Playback Switch");
736 strcpy(id2
.name
, id1
.name
);
738 if ((err
= snd_ctl_rename_id(card
, &id1
, &id2
)) < 0)
740 strcpy(id1
.name
, "Master Playback Volume");
741 strcpy(id2
.name
, id1
.name
);
742 if ((err
= snd_ctl_rename_id(card
, &id1
, &id2
)) < 0)
744 if ((err
= snd_tea6330t_update_mixer(card
, i2c_bus
, 0, 1)) < 0)
749 gus
->uart_enable
= midi
[dev
];
750 if ((err
= snd_gf1_rawmidi_new(gus
, 0, NULL
)) < 0)
754 str
= "AMD InterWave";
755 if (gus
->gf1
.rom_banks
== 1 && gus
->gf1
.rom_present
== 8)
756 str
= "Dynasonic 3-D";
758 str
= "InterWave STB";
760 strcpy(card
->driver
, str
);
761 strcpy(card
->shortname
, str
);
762 sprintf(card
->longname
, "%s at 0x%lx, irq %i, dma %d",
768 sprintf(card
->longname
+ strlen(card
->longname
), "&%d", xdma2
);
770 err
= snd_card_register(card
);
779 static int __devinit
snd_interwave_isa_probe1(int dev
, struct device
*devptr
)
781 struct snd_card
*card
;
784 err
= snd_interwave_card_new(dev
, &card
);
788 snd_card_set_dev(card
, devptr
);
789 if ((err
= snd_interwave_probe(card
, dev
)) < 0) {
793 dev_set_drvdata(devptr
, card
);
797 static int __devinit
snd_interwave_isa_match(struct device
*pdev
,
809 static int __devinit
snd_interwave_isa_probe(struct device
*pdev
,
813 static int possible_irqs
[] = {5, 11, 12, 9, 7, 15, 3, -1};
814 static int possible_dmas
[] = {0, 1, 3, 5, 6, 7, -1};
816 if (irq
[dev
] == SNDRV_AUTO_IRQ
) {
817 if ((irq
[dev
] = snd_legacy_find_free_irq(possible_irqs
)) < 0) {
818 snd_printk(KERN_ERR PFX
"unable to find a free IRQ\n");
822 if (dma1
[dev
] == SNDRV_AUTO_DMA
) {
823 if ((dma1
[dev
] = snd_legacy_find_free_dma(possible_dmas
)) < 0) {
824 snd_printk(KERN_ERR PFX
"unable to find a free DMA1\n");
828 if (dma2
[dev
] == SNDRV_AUTO_DMA
) {
829 if ((dma2
[dev
] = snd_legacy_find_free_dma(possible_dmas
)) < 0) {
830 snd_printk(KERN_ERR PFX
"unable to find a free DMA2\n");
835 if (port
[dev
] != SNDRV_AUTO_PORT
)
836 return snd_interwave_isa_probe1(dev
, pdev
);
838 static long possible_ports
[] = {0x210, 0x220, 0x230, 0x240, 0x250, 0x260};
840 for (i
= 0; i
< ARRAY_SIZE(possible_ports
); i
++) {
841 port
[dev
] = possible_ports
[i
];
842 err
= snd_interwave_isa_probe1(dev
, pdev
);
850 static int __devexit
snd_interwave_isa_remove(struct device
*devptr
, unsigned int dev
)
852 snd_card_free(dev_get_drvdata(devptr
));
853 dev_set_drvdata(devptr
, NULL
);
857 static struct isa_driver snd_interwave_driver
= {
858 .match
= snd_interwave_isa_match
,
859 .probe
= snd_interwave_isa_probe
,
860 .remove
= __devexit_p(snd_interwave_isa_remove
),
861 /* FIXME: suspend,resume */
863 .name
= INTERWAVE_DRIVER
868 static int __devinit
snd_interwave_pnp_detect(struct pnp_card_link
*pcard
,
869 const struct pnp_card_device_id
*pid
)
872 struct snd_card
*card
;
875 for ( ; dev
< SNDRV_CARDS
; dev
++) {
876 if (enable
[dev
] && isapnp
[dev
])
879 if (dev
>= SNDRV_CARDS
)
882 res
= snd_interwave_card_new(dev
, &card
);
886 if ((res
= snd_interwave_pnp(dev
, card
->private_data
, pcard
, pid
)) < 0) {
890 snd_card_set_dev(card
, &pcard
->card
->dev
);
891 if ((res
= snd_interwave_probe(card
, dev
)) < 0) {
895 pnp_set_card_drvdata(pcard
, card
);
900 static void __devexit
snd_interwave_pnp_remove(struct pnp_card_link
* pcard
)
902 snd_card_free(pnp_get_card_drvdata(pcard
));
903 pnp_set_card_drvdata(pcard
, NULL
);
906 static struct pnp_card_driver interwave_pnpc_driver
= {
907 .flags
= PNP_DRIVER_RES_DISABLE
,
908 .name
= INTERWAVE_PNP_DRIVER
,
909 .id_table
= snd_interwave_pnpids
,
910 .probe
= snd_interwave_pnp_detect
,
911 .remove
= __devexit_p(snd_interwave_pnp_remove
),
912 /* FIXME: suspend,resume */
915 #endif /* CONFIG_PNP */
917 static int __init
alsa_card_interwave_init(void)
921 err
= isa_register_driver(&snd_interwave_driver
, SNDRV_CARDS
);
926 err
= pnp_register_card_driver(&interwave_pnpc_driver
);
936 static void __exit
alsa_card_interwave_exit(void)
940 pnp_unregister_card_driver(&interwave_pnpc_driver
);
943 isa_unregister_driver(&snd_interwave_driver
);
946 module_init(alsa_card_interwave_init
)
947 module_exit(alsa_card_interwave_exit
)