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