Changeset 70 for GPL/trunk/alsa-kernel/pci/via82xx.c
- Timestamp:
- Jan 14, 2006, 6:38:48 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/trunk/alsa-kernel/pci/via82xx.c
r34 r70 43 43 * routines for each chipset. 44 44 * 45 * Sep. 26, 2005 46 * - Optimize position calculation for the 823x chips.45 * Sep. 26, 2005 Karsten Wiese <annabellesgarden@yahoo.de> 46 * - Optimize position calculation for the 823x chips. 47 47 */ 48 48 … … 54 54 #include <linux/pci.h> 55 55 #include <linux/slab.h> 56 //#include <linux/gameport.h> 57 #include <linux/moduleparam.h> 56 58 #include <sound/core.h> 57 59 #include <sound/pcm.h> 58 #include <sound/memalloc.h>59 60 #include <sound/pcm_params.h> 60 61 #include <sound/info.h> 61 62 #include <sound/ac97_codec.h> 62 63 #include <sound/mpu401.h> 63 #define SNDRV_GET_ID64 64 #include <sound/initval.h> 65 65 … … 71 71 MODULE_DESCRIPTION("VIA VT82xx audio"); 72 72 MODULE_LICENSE("GPL"); 73 MODULE_CLASSES("{sound}"); 74 MODULE_DEVICES("{{VIA,VT82C686A/B/C,pci},{VIA,VT8233A/C,8235}}"); 73 MODULE_SUPPORTED_DEVICE("{{VIA,VT82C686A/B/C,pci},{VIA,VT8233A/C,8235}}"); 74 75 #ifndef PCI_DEVICE_ID_VIA_8233_5 76 #define PCI_DEVICE_ID_VIA_8233_5 0x3059 77 #endif 75 78 76 79 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE)) … … 78 81 #endif 79 82 80 extern int midi_port; 81 82 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 83 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 84 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 85 static long mpu_port[SNDRV_CARDS] = {-1,-1,0,0,0,0,0,0}; 83 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ 84 static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ 85 static long mpu_port; 86 86 #ifdef SUPPORT_JOYSTICK 87 static int joystick [SNDRV_CARDS] = {1,0,0,0,0,0,0,0};87 static int joystick; 88 88 #endif 89 static int ac97_clock [SNDRV_CARDS] = {REPEAT_SNDRV(48000)};90 static char *ac97_quirk [SNDRV_CARDS];91 static int dxs_support [SNDRV_CARDS];92 93 MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");89 static int ac97_clock = 48000; 90 static char *ac97_quirk; 91 static int dxs_support; 92 93 //module_param(index, int, 0444); 94 94 MODULE_PARM_DESC(index, "Index value for VIA 82xx bridge."); 95 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC); 96 MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s"); 95 //module_param(id, charp, 0444); 97 96 MODULE_PARM_DESC(id, "ID string for VIA 82xx bridge."); 98 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC); 99 MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); 100 MODULE_PARM_DESC(enable, "Enable audio part of VIA 82xx bridge."); 101 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC); 102 MODULE_PARM(mpu_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l"); 97 //module_param(mpu_port, long, 0444); 103 98 MODULE_PARM_DESC(mpu_port, "MPU-401 port. (VT82C686x only)"); 104 MODULE_PARM_SYNTAX(mpu_port, SNDRV_PORT_DESC);105 99 #ifdef SUPPORT_JOYSTICK 106 MODULE_PARM(joystick, "1-" __MODULE_STRING(SNDRV_CARDS) "i");100 //module_param(joystick, bool, 0444); 107 101 MODULE_PARM_DESC(joystick, "Enable joystick. (VT82C686x only)"); 108 MODULE_PARM_SYNTAX(joystick, SNDRV_ENABLE_DESC "," SNDRV_BOOLEAN_FALSE_DESC);109 102 #endif 110 MODULE_PARM(ac97_clock, "1-" __MODULE_STRING(SNDRV_CARDS) "i");103 //module_param(ac97_clock, int, 0444); 111 104 MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz)."); 112 MODULE_PARM_SYNTAX(ac97_clock, SNDRV_ENABLED ",default:48000"); 113 MODULE_PARM(ac97_quirk, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); 105 //module_param(ac97_quirk, charp, 0444); 114 106 MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware."); 115 MODULE_PARM_SYNTAX(ac97_quirk, SNDRV_ENABLED ",allows:{{-1,3}},dialog:list,default:-1"); 116 MODULE_PARM(dxs_support, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); 107 //module_param(dxs_support, int, 0444); 117 108 MODULE_PARM_DESC(dxs_support, "Support for DXS channels (0 = auto, 1 = enable, 2 = disable, 3 = 48k only, 4 = no VRA, 5 = enable any sample rate)"); 118 MODULE_PARM_SYNTAX(dxs_support, SNDRV_ENABLED ",allows:{{0,4}},dialog:list"); 119 120 121 /* pci ids */ 122 #ifndef PCI_DEVICE_ID_VIA_82C686_5 123 #define PCI_DEVICE_ID_VIA_82C686_5 0x3058 124 #endif 125 #ifndef PCI_DEVICE_ID_VIA_8233_5 126 #define PCI_DEVICE_ID_VIA_8233_5 0x3059 127 #endif 109 110 /* just for backward compatibility */ 111 static int enable; 112 //module_param(enable, bool, 0444); 113 128 114 129 115 /* revision numbers for via686 */ … … 141 127 #define VIA_REV_8233A 0x40 /* 1 rec, 1 multi-pb, spdf */ 142 128 #define VIA_REV_8235 0x50 /* 2 rec, 4 pb, 1 multi-pb, spdif */ 143 #define VIA_REV_8237 129 #define VIA_REV_8237 0x60 144 130 145 131 /* … … 153 139 #define VIA_REG_OFFSET_STATUS 0x00 /* byte - channel status */ 154 140 #define VIA_REG_STAT_ACTIVE 0x80 /* RO */ 155 #define VIA8233_SHADOW_STAT_ACTIVE 0x08/* RO */141 #define VIA8233_SHADOW_STAT_ACTIVE 0x08 /* RO */ 156 142 #define VIA_REG_STAT_PAUSED 0x40 /* RO */ 157 143 #define VIA_REG_STAT_TRIGGER_QUEUED 0x08 /* RO */ … … 164 150 #define VIA_REG_CTRL_AUTOSTART 0x20 165 151 #define VIA_REG_CTRL_PAUSE 0x08 /* RW */ 166 #define VIA_REG_CTRL_INT_STOP 0x04 152 #define VIA_REG_CTRL_INT_STOP 0x04 167 153 #define VIA_REG_CTRL_INT_EOL 0x02 168 154 #define VIA_REG_CTRL_INT_FLAG 0x01 … … 188 174 189 175 #define DEFINE_VIA_REGSET(name,val) \ 190 191 192 193 194 195 196 197 198 176 enum {\ 177 VIA_REG_##name##_STATUS = (val),\ 178 VIA_REG_##name##_CONTROL = (val) + 0x01,\ 179 VIA_REG_##name##_TYPE = (val) + 0x02,\ 180 VIA_REG_##name##_TABLE_PTR = (val) + 0x04,\ 181 VIA_REG_##name##_CURR_PTR = (val) + 0x04,\ 182 VIA_REG_##name##_STOP_IDX = (val) + 0x08,\ 183 VIA_REG_##name##_CURR_COUNT = (val) + 0x0c,\ 184 } 199 185 200 186 /* playback block */ … … 287 273 #define VIA_ACLINK_CTRL_SB 0x01 /* via686 only */ 288 274 #define VIA_ACLINK_CTRL_INIT (VIA_ACLINK_CTRL_ENABLE|\ 289 290 291 275 VIA_ACLINK_CTRL_RESET|\ 276 VIA_ACLINK_CTRL_PCM|\ 277 VIA_ACLINK_CTRL_VRA) 292 278 #define VIA_FUNC_ENABLE 0x42 293 279 #define VIA_FUNC_MIDI_PNP 0x80 /* FIXME: it's 0x40 in the datasheet! */ … … 318 304 #define VIA_DXS_48K 3 319 305 #define VIA_DXS_NO_VRA 4 320 #define VIA_DXS_SRC 5 321 322 /* 323 */ 324 325 typedef struct _snd_via82xx via82xx_t; 326 typedef struct via_dev viadev_t; 306 #define VIA_DXS_SRC 5 307 327 308 328 309 /* … … 331 312 332 313 struct snd_via_sg_table { 333 334 314 unsigned int offset; 315 unsigned int size; 335 316 } ; 336 317 337 318 #define VIA_TABLE_SIZE 255 338 319 339 struct via _dev {340 341 342 343 snd_pcm_substream_t*substream;344 345 346 347 348 349 350 351 352 353 int hwptr_done;/* processed frame position in the buffer */354 355 320 struct viadev { 321 unsigned int reg_offset; 322 unsigned long port; 323 int direction; /* playback = 0, capture = 1 */ 324 struct snd_pcm_substream *substream; 325 int running; 326 unsigned int tbl_entries; /* # descriptors */ 327 struct snd_dma_buffer table; 328 struct snd_via_sg_table *idx_table; 329 /* for recovery from the unexpected pointer */ 330 unsigned int lastpos; 331 unsigned int fragsize; 332 unsigned int bufsize; 333 unsigned int bufsize2; 334 int hwptr_done; /* processed frame position in the buffer */ 335 int in_interrupt; 336 int shadow_shift; 356 337 }; 338 357 339 358 340 enum { TYPE_CARD_VIA686 = 1, TYPE_CARD_VIA8233 }; 359 341 enum { TYPE_VIA686, TYPE_VIA8233, TYPE_VIA8233A }; 360 342 361 #define VIA_MAX_DEVS 7/* 4 playback, 1 multi, 2 capture */343 #define VIA_MAX_DEVS 7 /* 4 playback, 1 multi, 2 capture */ 362 344 363 345 struct via_rate_lock { 364 365 366 346 spinlock_t lock; 347 int rate; 348 int used; 367 349 }; 368 350 369 struct _snd_via82xx { 370 int irq; 371 372 unsigned long port; 373 struct resource *res_port; 374 struct resource *mpu_res; 375 int chip_type; 376 unsigned char revision; 377 378 unsigned char old_legacy; 379 unsigned char old_legacy_cfg; 380 351 struct via82xx { 352 int irq; 353 354 unsigned long port; 355 struct resource *mpu_res; 356 int chip_type; 357 unsigned char revision; 358 359 unsigned char old_legacy; 360 unsigned char old_legacy_cfg; 381 361 #ifdef CONFIG_PM 382 383 384 385 386 362 unsigned char legacy_saved; 363 unsigned char legacy_cfg_saved; 364 unsigned char spdif_ctrl_saved; 365 unsigned char capture_src_saved[2]; 366 unsigned int mpu_port_saved; 387 367 #endif 388 unsigned char playback_volume[2]; /* for VIA8233/C/8235; default = 0 */ 389 390 unsigned int intr_mask; /* SGD_SHADOW mask to check interrupts */ 391 392 struct pci_dev *pci; 393 snd_card_t *card; 394 395 unsigned int num_devs; 396 unsigned int playback_devno, multi_devno, capture_devno; 397 viadev_t devs[VIA_MAX_DEVS]; 398 struct via_rate_lock rates[2]; /* playback and capture */ 399 unsigned int dxs_fixed: 1; /* DXS channel accepts only 48kHz */ 400 unsigned int no_vra: 1; /* no need to set VRA on DXS channels */ 401 unsigned int dxs_src: 1; /* use full SRC capabilities of DXS */ 402 unsigned int spdif_on: 1; /* only spdif rates work to external DACs */ 403 404 snd_pcm_t *pcms[2]; 405 snd_rawmidi_t *rmidi; 406 407 ac97_bus_t *ac97_bus; 408 ac97_t *ac97; 409 unsigned int ac97_clock; 410 unsigned int ac97_secondary; /* secondary AC'97 codec is present */ 411 412 spinlock_t reg_lock; 413 snd_info_entry_t *proc_entry; 368 369 unsigned char playback_volume[4][2]; /* for VIA8233/C/8235; default = 0 */ 370 unsigned char playback_volume_c[2]; /* for VIA8233/C/8235; default = 0 */ 371 372 unsigned int intr_mask; /* SGD_SHADOW mask to check interrupts */ 373 374 struct pci_dev *pci; 375 struct snd_card *card; 376 377 unsigned int num_devs; 378 unsigned int playback_devno, multi_devno, capture_devno; 379 struct viadev devs[VIA_MAX_DEVS]; 380 struct via_rate_lock rates[2]; /* playback and capture */ 381 unsigned int dxs_fixed: 1; /* DXS channel accepts only 48kHz */ 382 unsigned int no_vra: 1; /* no need to set VRA on DXS channels */ 383 unsigned int dxs_src: 1; /* use full SRC capabilities of DXS */ 384 unsigned int spdif_on: 1; /* only spdif rates work to external DACs */ 385 386 struct snd_pcm *pcms[2]; 387 struct snd_rawmidi *rmidi; 388 389 struct snd_ac97_bus *ac97_bus; 390 struct snd_ac97 *ac97; 391 unsigned int ac97_clock; 392 unsigned int ac97_secondary; /* secondary AC'97 codec is present */ 393 394 spinlock_t reg_lock; 395 struct snd_info_entry *proc_entry; 414 396 415 397 #ifdef SUPPORT_JOYSTICK 416 struct gameport gameport; 417 struct resource *res_joystick; 398 struct gameport *gameport; 418 399 #endif 419 400 }; 420 401 421 402 static struct pci_device_id snd_via82xx_ids[] = { 422 423 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA686, },/* 686A */424 425 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA8233, },/* VT8233 */426 403 /* 0x1106, 0x3058 */ 404 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA686, }, /* 686A */ 405 /* 0x1106, 0x3059 */ 406 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA8233, }, /* VT8233 */ 407 { 0, } 427 408 }; 428 409 … … 437 418 * fragsize = period size in bytes 438 419 */ 439 static int build_via_table(viadev_t *dev, snd_pcm_substream_t *substream, 440 struct pci_dev *pci, 441 unsigned int periods, unsigned int fragsize) 442 { 443 unsigned int i, idx, ofs, rest; 444 via82xx_t *chip = snd_pcm_substream_chip(substream); 445 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream); 446 447 if (dev->table.area == NULL) { 448 /* the start of each lists must be aligned to 8 bytes, 449 * but the kernel pages are much bigger, so we don't care 450 */ 451 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), 452 PAGE_ALIGN(VIA_TABLE_SIZE * 2 * 8), 453 &dev->table) < 0) 454 return -ENOMEM; 455 } 456 if (! dev->idx_table) { 457 dev->idx_table = kmalloc(sizeof(*dev->idx_table) * VIA_TABLE_SIZE, GFP_KERNEL); 458 if (! dev->idx_table) 459 return -ENOMEM; 460 } 461 462 /* fill the entries */ 463 idx = 0; 464 ofs = 0; 465 for (i = 0; i < periods; i++) { 466 rest = fragsize; 467 /* fill descriptors for a period. 468 * a period can be split to several descriptors if it's 469 * over page boundary. 470 */ 471 do { 472 unsigned int r; 473 unsigned int flag; 474 475 if (idx >= VIA_TABLE_SIZE) { 476 snd_printk(KERN_ERR "via82xx: too much table size!\n"); 477 return -EINVAL; 478 } 479 ((u32 *)dev->table.area)[idx << 1] = cpu_to_le32((u32)snd_pcm_sgbuf_get_addr(sgbuf, ofs)); 480 r = PAGE_SIZE - (ofs % PAGE_SIZE); 481 if (rest < r) 482 r = rest; 483 rest -= r; 484 if (! rest) { 485 if (i == periods - 1) 486 flag = VIA_TBL_BIT_EOL; /* buffer boundary */ 487 else 488 flag = VIA_TBL_BIT_FLAG; /* period boundary */ 489 } else 490 flag = 0; /* period continues to the next */ 491 // printk("via: tbl %d: at %d size %d (rest %d)\n", idx, ofs, r, rest); 492 ((u32 *)dev->table.area)[(idx<<1) + 1] = cpu_to_le32(r | flag); 493 dev->idx_table[idx].offset = ofs; 494 dev->idx_table[idx].size = r; 495 ofs += r; 496 idx++; 497 } while (rest > 0); 498 } 499 dev->tbl_entries = idx; 500 dev->bufsize = periods * fragsize; 501 dev->bufsize2 = dev->bufsize / 2; 502 dev->fragsize = fragsize; 503 return 0; 504 } 505 506 static int clean_via_table(viadev_t *dev, snd_pcm_substream_t *substream, 507 struct pci_dev *pci) 508 { 509 if (dev->table.area) { 510 snd_dma_free_pages(&dev->table); 511 dev->table.area = NULL; 512 } 513 if (dev->idx_table) { 514 kfree(dev->idx_table); 515 dev->idx_table = NULL; 516 } 517 return 0; 420 static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substream, 421 struct pci_dev *pci, 422 unsigned int periods, unsigned int fragsize) 423 { 424 unsigned int i, idx, ofs, rest; 425 struct via82xx *chip = snd_pcm_substream_chip(substream); 426 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream); 427 428 if (dev->table.area == NULL) { 429 /* the start of each lists must be aligned to 8 bytes, 430 * but the kernel pages are much bigger, so we don't care 431 */ 432 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), 433 PAGE_ALIGN(VIA_TABLE_SIZE * 2 * 8), 434 &dev->table) < 0) 435 return -ENOMEM; 436 } 437 if (! dev->idx_table) { 438 dev->idx_table = kmalloc(sizeof(*dev->idx_table) * VIA_TABLE_SIZE, GFP_KERNEL); 439 if (! dev->idx_table) 440 return -ENOMEM; 441 } 442 443 /* fill the entries */ 444 idx = 0; 445 ofs = 0; 446 for (i = 0; i < periods; i++) { 447 rest = fragsize; 448 /* fill descriptors for a period. 449 * a period can be split to several descriptors if it's 450 * over page boundary. 451 */ 452 do { 453 unsigned int r; 454 unsigned int flag; 455 456 if (idx >= VIA_TABLE_SIZE) { 457 snd_printk(KERN_ERR "via82xx: too much table size!\n"); 458 return -EINVAL; 459 } 460 ((u32 *)dev->table.area)[idx << 1] = cpu_to_le32((u32)snd_pcm_sgbuf_get_addr(sgbuf, ofs)); 461 r = PAGE_SIZE - (ofs % PAGE_SIZE); 462 if (rest < r) 463 r = rest; 464 rest -= r; 465 if (! rest) { 466 if (i == periods - 1) 467 flag = VIA_TBL_BIT_EOL; /* buffer boundary */ 468 else 469 flag = VIA_TBL_BIT_FLAG; /* period boundary */ 470 } else 471 flag = 0; /* period continues to the next */ 472 // printk("via: tbl %d: at %d size %d (rest %d)\n", idx, ofs, r, rest); 473 ((u32 *)dev->table.area)[(idx<<1) + 1] = cpu_to_le32(r | flag); 474 dev->idx_table[idx].offset = ofs; 475 dev->idx_table[idx].size = r; 476 ofs += r; 477 idx++; 478 } while (rest > 0); 479 } 480 dev->tbl_entries = idx; 481 dev->bufsize = periods * fragsize; 482 dev->bufsize2 = dev->bufsize / 2; 483 dev->fragsize = fragsize; 484 return 0; 485 } 486 487 488 static int clean_via_table(struct viadev *dev, struct snd_pcm_substream *substream, 489 struct pci_dev *pci) 490 { 491 if (dev->table.area) { 492 snd_dma_free_pages(&dev->table); 493 dev->table.area = NULL; 494 } 495 kfree(dev->idx_table); 496 dev->idx_table = NULL; 497 return 0; 518 498 } 519 499 … … 522 502 */ 523 503 524 static inline unsigned int snd_via82xx_codec_xread(via82xx_t *chip) 525 { 526 return inl(VIAREG(chip, AC97)); 527 } 528 529 static inline void snd_via82xx_codec_xwrite(via82xx_t *chip, unsigned int val) 530 { 531 outl(val, VIAREG(chip, AC97)); 532 } 533 534 static int snd_via82xx_codec_ready(via82xx_t *chip, int secondary) 535 { 536 unsigned int timeout = 1000; /* 1ms */ 537 unsigned int val; 538 539 while (timeout-- > 0) { 540 udelay(1); 541 if (!((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)) 542 return val & 0xffff; 543 } 544 snd_printk("codec_ready: codec %i is not ready [0x%x]\n", secondary, snd_via82xx_codec_xread(chip)); 545 return -EIO; 546 } 547 548 static int snd_via82xx_codec_valid(via82xx_t *chip, int secondary) 549 { 550 unsigned int timeout = 1000; /* 1ms */ 551 unsigned int val, val1; 552 unsigned int stat = !secondary ? VIA_REG_AC97_PRIMARY_VALID : 553 VIA_REG_AC97_SECONDARY_VALID; 554 555 while (timeout-- > 0) { 556 val = snd_via82xx_codec_xread(chip); 557 val1 = val & (VIA_REG_AC97_BUSY | stat); 558 if (val1 == stat) 559 return val & 0xffff; 560 udelay(1); 561 } 562 return -EIO; 563 } 564 565 static void snd_via82xx_codec_wait(ac97_t *ac97) 566 { 567 via82xx_t *chip = ac97->private_data; 568 int err; 569 err = snd_via82xx_codec_ready(chip, ac97->num); 570 /* here we need to wait fairly for long time.. */ 571 msleep(500); 572 } 573 574 static void snd_via82xx_codec_write(ac97_t *ac97, 575 unsigned short reg, 576 unsigned short val) 577 { 578 via82xx_t *chip = ac97->private_data; 579 unsigned int xval; 580 581 xval = !ac97->num ? VIA_REG_AC97_CODEC_ID_PRIMARY : VIA_REG_AC97_CODEC_ID_SECONDARY; 582 xval <<= VIA_REG_AC97_CODEC_ID_SHIFT; 583 xval |= reg << VIA_REG_AC97_CMD_SHIFT; 584 xval |= val << VIA_REG_AC97_DATA_SHIFT; 585 snd_via82xx_codec_xwrite(chip, xval); 586 snd_via82xx_codec_ready(chip, ac97->num); 587 } 588 589 static unsigned short snd_via82xx_codec_read(ac97_t *ac97, unsigned short reg) 590 { 591 via82xx_t *chip = ac97->private_data; 592 unsigned int xval, val = 0xffff; 593 int again = 0; 594 595 xval = ac97->num << VIA_REG_AC97_CODEC_ID_SHIFT; 596 xval |= ac97->num ? VIA_REG_AC97_SECONDARY_VALID : VIA_REG_AC97_PRIMARY_VALID; 597 xval |= VIA_REG_AC97_READ; 598 xval |= (reg & 0x7f) << VIA_REG_AC97_CMD_SHIFT; 599 while (1) { 600 if (again++ > 3) { 601 snd_printk("codec_read: codec %i is not valid [0x%x]\n", ac97->num, snd_via82xx_codec_xread(chip)); 602 return 0xffff; 603 } 604 snd_via82xx_codec_xwrite(chip, xval); 605 udelay (20); 606 if (snd_via82xx_codec_valid(chip, ac97->num) >= 0) { 607 udelay(25); 608 val = snd_via82xx_codec_xread(chip); 609 break; 610 } 611 } 612 return val & 0xffff; 613 } 614 615 static void snd_via82xx_channel_reset(via82xx_t *chip, viadev_t *viadev) 616 { 617 outb(VIA_REG_CTRL_PAUSE | VIA_REG_CTRL_TERMINATE | VIA_REG_CTRL_RESET, 618 VIADEV_REG(viadev, OFFSET_CONTROL)); 619 inb(VIADEV_REG(viadev, OFFSET_CONTROL)); 620 udelay(50); 621 /* disable interrupts */ 622 outb(0x00, VIADEV_REG(viadev, OFFSET_CONTROL)); 623 /* clear interrupts */ 624 outb(0x03, VIADEV_REG(viadev, OFFSET_STATUS)); 625 outb(0x00, VIADEV_REG(viadev, OFFSET_TYPE)); /* for via686 */ 626 // outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR)); 627 viadev->lastpos = 0; 628 viadev->hwptr_done = 0; 504 static inline unsigned int snd_via82xx_codec_xread(struct via82xx *chip) 505 { 506 return inl(VIAREG(chip, AC97)); 507 } 508 509 static inline void snd_via82xx_codec_xwrite(struct via82xx *chip, unsigned int val) 510 { 511 outl(val, VIAREG(chip, AC97)); 512 } 513 514 static int snd_via82xx_codec_ready(struct via82xx *chip, int secondary) 515 { 516 unsigned int timeout = 1000; /* 1ms */ 517 unsigned int val; 518 519 while (timeout-- > 0) { 520 udelay(1); 521 if (!((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)) 522 return val & 0xffff; 523 } 524 snd_printk(KERN_ERR "codec_ready: codec %i is not ready [0x%x]\n", 525 secondary, snd_via82xx_codec_xread(chip)); 526 return -EIO; 527 } 528 529 static int snd_via82xx_codec_valid(struct via82xx *chip, int secondary) 530 { 531 unsigned int timeout = 1000; /* 1ms */ 532 unsigned int val, val1; 533 unsigned int stat = !secondary ? VIA_REG_AC97_PRIMARY_VALID : 534 VIA_REG_AC97_SECONDARY_VALID; 535 536 while (timeout-- > 0) { 537 val = snd_via82xx_codec_xread(chip); 538 val1 = val & (VIA_REG_AC97_BUSY | stat); 539 if (val1 == stat) 540 return val & 0xffff; 541 udelay(1); 542 } 543 return -EIO; 544 } 545 546 static void snd_via82xx_codec_wait(struct snd_ac97 *ac97) 547 { 548 struct via82xx *chip = ac97->private_data; 549 int err; 550 err = snd_via82xx_codec_ready(chip, ac97->num); 551 /* here we need to wait fairly for long time.. */ 552 msleep(500); 553 } 554 555 static void snd_via82xx_codec_write(struct snd_ac97 *ac97, 556 unsigned short reg, 557 unsigned short val) 558 { 559 struct via82xx *chip = ac97->private_data; 560 unsigned int xval; 561 562 xval = !ac97->num ? VIA_REG_AC97_CODEC_ID_PRIMARY : VIA_REG_AC97_CODEC_ID_SECONDARY; 563 xval <<= VIA_REG_AC97_CODEC_ID_SHIFT; 564 xval |= reg << VIA_REG_AC97_CMD_SHIFT; 565 xval |= val << VIA_REG_AC97_DATA_SHIFT; 566 snd_via82xx_codec_xwrite(chip, xval); 567 snd_via82xx_codec_ready(chip, ac97->num); 568 } 569 570 static unsigned short snd_via82xx_codec_read(struct snd_ac97 *ac97, unsigned short reg) 571 { 572 struct via82xx *chip = ac97->private_data; 573 unsigned int xval, val = 0xffff; 574 int again = 0; 575 576 xval = ac97->num << VIA_REG_AC97_CODEC_ID_SHIFT; 577 xval |= ac97->num ? VIA_REG_AC97_SECONDARY_VALID : VIA_REG_AC97_PRIMARY_VALID; 578 xval |= VIA_REG_AC97_READ; 579 xval |= (reg & 0x7f) << VIA_REG_AC97_CMD_SHIFT; 580 while (1) { 581 if (again++ > 3) { 582 snd_printk(KERN_ERR "codec_read: codec %i is not valid [0x%x]\n", 583 ac97->num, snd_via82xx_codec_xread(chip)); 584 return 0xffff; 585 } 586 snd_via82xx_codec_xwrite(chip, xval); 587 udelay (20); 588 if (snd_via82xx_codec_valid(chip, ac97->num) >= 0) { 589 udelay(25); 590 val = snd_via82xx_codec_xread(chip); 591 break; 592 } 593 } 594 return val & 0xffff; 595 } 596 597 static void snd_via82xx_channel_reset(struct via82xx *chip, struct viadev *viadev) 598 { 599 outb(VIA_REG_CTRL_PAUSE | VIA_REG_CTRL_TERMINATE | VIA_REG_CTRL_RESET, 600 VIADEV_REG(viadev, OFFSET_CONTROL)); 601 inb(VIADEV_REG(viadev, OFFSET_CONTROL)); 602 udelay(50); 603 /* disable interrupts */ 604 outb(0x00, VIADEV_REG(viadev, OFFSET_CONTROL)); 605 /* clear interrupts */ 606 outb(0x03, VIADEV_REG(viadev, OFFSET_STATUS)); 607 outb(0x00, VIADEV_REG(viadev, OFFSET_TYPE)); /* for via686 */ 608 // outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR)); 609 viadev->lastpos = 0; 610 viadev->hwptr_done = 0; 629 611 } 630 612 … … 634 616 * Used for 686 and 8233A 635 617 */ 636 637 618 static irqreturn_t snd_via686_interrupt(int irq, void *dev_id, struct pt_regs *regs) 638 619 { 639 via82xx_t *chip = dev_id; 640 unsigned int status; 641 unsigned int i; 642 #ifdef TARGET_OS2 643 int fOurIrq = FALSE; 620 struct via82xx *chip = dev_id; 621 unsigned int status; 622 unsigned int i; 623 624 status = inl(VIAREG(chip, SGD_SHADOW)); 625 if (! (status & chip->intr_mask)) { 626 if (chip->rmidi) 627 /* check mpu401 interrupt */ 628 return snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs); 629 return IRQ_NONE; 630 } 631 632 /* check status for each stream */ 633 spin_lock(&chip->reg_lock); 634 for (i = 0; i < chip->num_devs; i++) { 635 struct viadev *viadev = &chip->devs[i]; 636 unsigned char c_status = inb(VIADEV_REG(viadev, OFFSET_STATUS)); 637 if (! (c_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG|VIA_REG_STAT_STOPPED))) 638 continue; 639 if (viadev->substream && viadev->running) { 640 /* 641 * Update hwptr_done based on 'period elapsed' 642 * interrupts. We'll use it, when the chip returns 0 643 * for OFFSET_CURR_COUNT. 644 */ 645 if (c_status & VIA_REG_STAT_EOL) 646 viadev->hwptr_done = 0; 647 else 648 viadev->hwptr_done += viadev->fragsize; 649 viadev->in_interrupt = c_status; 650 spin_unlock(&chip->reg_lock); 651 snd_pcm_period_elapsed(viadev->substream); 652 spin_lock(&chip->reg_lock); 653 viadev->in_interrupt = 0; 654 } 655 outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */ 656 } 657 spin_unlock(&chip->reg_lock); 658 return IRQ_HANDLED; 659 } 660 661 /* 662 * Interrupt handler 663 */ 664 static irqreturn_t snd_via8233_interrupt(int irq, void *dev_id, struct pt_regs *regs) 665 { 666 struct via82xx *chip = dev_id; 667 unsigned int status; 668 unsigned int i; 669 int irqreturn = 0; 670 671 /* check status for each stream */ 672 spin_lock(&chip->reg_lock); 673 status = inl(VIAREG(chip, SGD_SHADOW)); 674 675 for (i = 0; i < chip->num_devs; i++) { 676 struct viadev *viadev = &chip->devs[i]; 677 struct snd_pcm_substream *substream; 678 unsigned char c_status, shadow_status; 679 680 shadow_status = (status >> viadev->shadow_shift) & 681 (VIA8233_SHADOW_STAT_ACTIVE|VIA_REG_STAT_EOL| 682 VIA_REG_STAT_FLAG); 683 c_status = shadow_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG); 684 if (!c_status) 685 continue; 686 687 substream = viadev->substream; 688 if (substream && viadev->running) { 689 /* 690 * Update hwptr_done based on 'period elapsed' 691 * interrupts. We'll use it, when the chip returns 0 692 * for OFFSET_CURR_COUNT. 693 */ 694 if (c_status & VIA_REG_STAT_EOL) 695 viadev->hwptr_done = 0; 696 else 697 viadev->hwptr_done += viadev->fragsize; 698 viadev->in_interrupt = c_status; 699 if (shadow_status & VIA8233_SHADOW_STAT_ACTIVE) 700 viadev->in_interrupt |= VIA_REG_STAT_ACTIVE; 701 spin_unlock(&chip->reg_lock); 702 703 snd_pcm_period_elapsed(substream); 704 705 spin_lock(&chip->reg_lock); 706 viadev->in_interrupt = 0; 707 } 708 outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */ 709 irqreturn = 1; 710 } 711 spin_unlock(&chip->reg_lock); 712 return IRQ_RETVAL(irqreturn); 713 } 714 715 /* 716 * PCM callbacks 717 */ 718 719 /* 720 * trigger callback 721 */ 722 static int snd_via82xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 723 { 724 struct via82xx *chip = snd_pcm_substream_chip(substream); 725 struct viadev *viadev = substream->runtime->private_data; 726 unsigned char val; 727 728 if (chip->chip_type != TYPE_VIA686) 729 val = VIA_REG_CTRL_INT; 730 else 731 val = 0; 732 switch (cmd) { 733 case SNDRV_PCM_TRIGGER_START: 734 case SNDRV_PCM_TRIGGER_RESUME: 735 val |= VIA_REG_CTRL_START; 736 viadev->running = 1; 737 break; 738 case SNDRV_PCM_TRIGGER_STOP: 739 case SNDRV_PCM_TRIGGER_SUSPEND: 740 val = VIA_REG_CTRL_TERMINATE; 741 viadev->running = 0; 742 break; 743 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 744 val |= VIA_REG_CTRL_PAUSE; 745 viadev->running = 0; 746 break; 747 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 748 viadev->running = 1; 749 break; 750 default: 751 return -EINVAL; 752 } 753 outb(val, VIADEV_REG(viadev, OFFSET_CONTROL)); 754 if (cmd == SNDRV_PCM_TRIGGER_STOP) 755 snd_via82xx_channel_reset(chip, viadev); 756 return 0; 757 } 758 759 760 /* 761 * pointer callbacks 762 */ 763 764 /* 765 * calculate the linear position at the given sg-buffer index and the rest count 766 */ 767 768 #define check_invalid_pos(viadev,pos) \ 769 ((pos) < viadev->lastpos && ((pos) >= viadev->bufsize2 ||\ 770 viadev->lastpos < viadev->bufsize2)) 771 772 static inline unsigned int calc_linear_pos(struct viadev *viadev, unsigned int idx, 773 unsigned int count) 774 { 775 unsigned int size, base, res; 776 777 size = viadev->idx_table[idx].size; 778 base = viadev->idx_table[idx].offset; 779 res = base + size - count; 780 if (res >= viadev->bufsize) 781 res -= viadev->bufsize; 782 783 /* check the validity of the calculated position */ 784 if (size < count) { 785 snd_printd(KERN_ERR "invalid via82xx_cur_ptr (size = %d, count = %d)\n", 786 (int)size, (int)count); 787 res = viadev->lastpos; 788 } else { 789 if (! count) { 790 /* Some mobos report count = 0 on the DMA boundary, 791 * i.e. count = size indeed. 792 * Let's check whether this step is above the expected size. 793 */ 794 int delta = res - viadev->lastpos; 795 if (delta < 0) 796 delta += viadev->bufsize; 797 if ((unsigned int)delta > viadev->fragsize) 798 res = base; 799 } 800 if (check_invalid_pos(viadev, res)) { 801 #ifdef POINTER_DEBUG 802 printk(KERN_DEBUG "fail: idx = %i/%i, lastpos = 0x%x, " 803 "bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, " 804 "count = 0x%x\n", idx, viadev->tbl_entries, 805 viadev->lastpos, viadev->bufsize2, 806 viadev->idx_table[idx].offset, 807 viadev->idx_table[idx].size, count); 644 808 #endif 645 646 #if 0 647 /* FIXME: does it work on via823x? */ 648 if (chip->chip_type != TYPE_VIA686) 649 goto _skip_sgd; 650 #endif 651 status = inl(VIAREG(chip, SGD_SHADOW)); 652 if (! (status & chip->intr_mask)) { 653 if (chip->rmidi) 654 /* check mpu401 interrupt */ 655 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs); 656 return IRQ_NONE; 657 } 658 // _skip_sgd: 659 #ifdef TARGET_OS2 660 fOurIrq = TRUE; 661 #endif //TARGET_OS2 662 663 /* check status for each stream */ 664 spin_lock(&chip->reg_lock); 665 for (i = 0; i < chip->num_devs; i++) { 666 viadev_t *viadev = &chip->devs[i]; 667 unsigned char c_status = inb(VIADEV_REG(viadev, OFFSET_STATUS)); 668 if (! (c_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG|VIA_REG_STAT_STOPPED))) 669 continue; 670 if (viadev->substream && viadev->running) { 671 /* 672 * Update hwptr_done based on 'period elapsed' 673 * interrupts. We'll use it, when the chip returns 0 674 * for OFFSET_CURR_COUNT. 675 */ 676 if (c_status & VIA_REG_STAT_EOL) 677 viadev->hwptr_done = 0; 678 else 679 viadev->hwptr_done += viadev->fragsize; 680 viadev->in_interrupt = c_status; 681 spin_unlock(&chip->reg_lock); 682 snd_pcm_period_elapsed(viadev->substream); 683 spin_lock(&chip->reg_lock); 684 viadev->in_interrupt = 0; 685 } 686 outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */ 687 } 688 spin_unlock(&chip->reg_lock); 689 #ifdef TARGET_OS2 690 if (fOurIrq) { 691 eoi_irq(irq); 692 } 693 #endif //TARGET_OS2 694 return IRQ_HANDLED; 695 } 696 697 /* 698 * Interrupt handler 699 */ 700 static irqreturn_t snd_via8233_interrupt(int irq, void *dev_id, struct pt_regs *regs) 701 { 702 via82xx_t *chip = dev_id; 703 unsigned int status; 704 unsigned int i; 705 int irqreturn = 0; 706 707 /* check status for each stream */ 708 spin_lock(&chip->reg_lock); 709 status = inl(VIAREG(chip, SGD_SHADOW)); 710 711 for (i = 0; i < chip->num_devs; i++) { 712 viadev_t *viadev = &chip->devs[i]; 713 snd_pcm_substream_t *substream; 714 unsigned char c_status, shadow_status; 715 716 shadow_status = (status >> viadev->shadow_shift) & 717 (VIA8233_SHADOW_STAT_ACTIVE|VIA_REG_STAT_EOL| 718 VIA_REG_STAT_FLAG); 719 c_status = shadow_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG); 720 if (!c_status) 721 continue; 722 723 substream = viadev->substream; 724 if (substream && viadev->running) { 725 /* 726 * Update hwptr_done based on 'period elapsed' 727 * interrupts. We'll use it, when the chip returns 0 728 * for OFFSET_CURR_COUNT. 729 */ 730 if (c_status & VIA_REG_STAT_EOL) 731 viadev->hwptr_done = 0; 732 else 733 viadev->hwptr_done += viadev->fragsize; 734 viadev->in_interrupt = c_status; 735 if (shadow_status & VIA8233_SHADOW_STAT_ACTIVE) 736 viadev->in_interrupt |= VIA_REG_STAT_ACTIVE; 737 spin_unlock(&chip->reg_lock); 738 739 snd_pcm_period_elapsed(substream); 740 741 spin_lock(&chip->reg_lock); 742 viadev->in_interrupt = 0; 743 } 744 outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */ 745 irqreturn = 1; 746 } 747 spin_unlock(&chip->reg_lock); 748 #ifdef TARGET_OS2 749 eoi_irq(irq); 750 #endif //TARGET_OS2 751 return IRQ_HANDLED; 752 } 753 754 /* 755 * PCM callbacks 756 */ 757 758 /* 759 * trigger callback 760 */ 761 static int snd_via82xx_pcm_trigger(snd_pcm_substream_t * substream, int cmd) 762 { 763 via82xx_t *chip = snd_pcm_substream_chip(substream); 764 viadev_t *viadev = (viadev_t *)substream->runtime->private_data; 765 unsigned char val; 766 767 if (chip->chip_type != TYPE_VIA686) 768 val = VIA_REG_CTRL_INT; 769 else 770 val = 0; 771 switch (cmd) { 772 case SNDRV_PCM_TRIGGER_START: 773 case SNDRV_PCM_TRIGGER_RESUME: 774 val |= VIA_REG_CTRL_START; 775 viadev->running = 1; 776 break; 777 case SNDRV_PCM_TRIGGER_STOP: 778 case SNDRV_PCM_TRIGGER_SUSPEND: 779 val = VIA_REG_CTRL_TERMINATE; 780 viadev->running = 0; 781 break; 782 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 783 val |= VIA_REG_CTRL_PAUSE; 784 viadev->running = 0; 785 break; 786 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 787 viadev->running = 1; 788 break; 789 default: 790 return -EINVAL; 791 } 792 outb(val, VIADEV_REG(viadev, OFFSET_CONTROL)); 793 if (cmd == SNDRV_PCM_TRIGGER_STOP) 794 snd_via82xx_channel_reset(chip, viadev); 795 return 0; 796 } 797 798 799 /* 800 * pointer callbacks 801 */ 802 803 /* 804 * calculate the linear position at the given sg-buffer index and the rest count 805 */ 806 807 #define check_invalid_pos(viadev,pos) \ 808 ((pos) < viadev->lastpos && ((pos) >= viadev->bufsize2 || viadev->lastpos < viadev->bufsize2)) 809 810 static inline unsigned int calc_linear_pos(viadev_t *viadev, unsigned int idx, unsigned int count) 811 { 812 unsigned int size, base, res; 813 814 size = viadev->idx_table[idx].size; 815 base = viadev->idx_table[idx].offset; 816 res = base + size - count; 817 if (res >= viadev->bufsize) 818 res -= viadev->bufsize; 819 820 /* check the validity of the calculated position */ 821 if (size < count) { 822 snd_printd(KERN_ERR "invalid via82xx_cur_ptr (size = %d, count = %d)\n", (int)size, (int)count); 823 res = viadev->lastpos; 824 } else { 825 if (! count) { 826 /* Some mobos report count = 0 on the DMA boundary, 827 * i.e. count = size indeed. 828 * Let's check whether this step is above the expected size. 829 */ 830 int delta = res - viadev->lastpos; 831 if (delta < 0) 832 delta += viadev->bufsize; 833 if ((unsigned int)delta > viadev->fragsize) 834 res = base; 835 } 836 if (check_invalid_pos(viadev, res)) { 837 #ifdef POINTER_DEBUG 838 printk(KERN_DEBUG "fail: idx = %i/%i, lastpos = 0x%x, bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, count = 0x%x\n", idx, viadev->tbl_entries, viadev->lastpos, viadev->bufsize2, viadev->idx_table[idx].offset, viadev->idx_table[idx].size, count); 839 #endif 840 /* count register returns full size when end of buffer is reached */ 841 res = base + size; 842 if (check_invalid_pos(viadev, res)) { 843 snd_printd(KERN_ERR "invalid via82xx_cur_ptr (2), using last valid pointer\n"); 844 res = viadev->lastpos; 845 } 846 } 847 } 848 return res; 809 /* count register returns full size when end of buffer is reached */ 810 res = base + size; 811 if (check_invalid_pos(viadev, res)) { 812 snd_printd(KERN_ERR "invalid via82xx_cur_ptr (2), " 813 "using last valid pointer\n"); 814 res = viadev->lastpos; 815 } 816 } 817 } 818 return res; 849 819 } 850 820 … … 852 822 * get the current pointer on via686 853 823 */ 854 static snd_pcm_uframes_t snd_via686_pcm_pointer(snd_pcm_substream_t *substream) 855 { 856 via82xx_t *chip = snd_pcm_substream_chip(substream); 857 viadev_t *viadev = (viadev_t *)substream->runtime->private_data; 858 unsigned int idx, ptr, count, res; 859 int timeout = 5000; 824 static snd_pcm_uframes_t snd_via686_pcm_pointer(struct snd_pcm_substream *substream) 825 { 826 struct via82xx *chip = snd_pcm_substream_chip(substream); 827 struct viadev *viadev = substream->runtime->private_data; 828 unsigned int idx, ptr, count, res; 860 829 861 830 snd_assert(viadev->tbl_entries, return 0); … … 863 832 return 0; 864 833 865 spin_lock(&chip->reg_lock); 866 do { 867 count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)) & 0xffffff; 868 /* some mobos read 0 count */ 869 if ((count & 0xffffff) || ! viadev->running) 870 break; 871 } while (--timeout); 872 if (! timeout) 873 snd_printd(KERN_ERR "zero position is read\n"); 834 spin_lock(&chip->reg_lock); 835 count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)) & 0xffffff; 874 836 /* The via686a does not have the current index register, 875 837 * so we need to calculate the index from CURR_PTR. … … 880 842 else /* CURR_PTR holds the address + 8 */ 881 843 idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) % viadev->tbl_entries; 882 883 844 res = calc_linear_pos(viadev, idx, count); 845 viadev->lastpos = res; /* remember the last position */ 884 846 spin_unlock(&chip->reg_lock); 885 847 … … 890 852 * get the current pointer on via823x 891 853 */ 892 static snd_pcm_uframes_t snd_via8233_pcm_pointer(s nd_pcm_substream_t*substream)893 { 894 via82xx_t*chip = snd_pcm_substream_chip(substream);895 viadev_t *viadev = (viadev_t *)substream->runtime->private_data;854 static snd_pcm_uframes_t snd_via8233_pcm_pointer(struct snd_pcm_substream *substream) 855 { 856 struct via82xx *chip = snd_pcm_substream_chip(substream); 857 struct viadev *viadev = substream->runtime->private_data; 896 858 unsigned int idx, count, res; 897 898 859 int status; 860 899 861 snd_assert(viadev->tbl_entries, return 0); 862 900 863 spin_lock(&chip->reg_lock); 901 count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)); 902 status = viadev->in_interrupt; 903 if (!status) 904 status = inb(VIADEV_REG(viadev, OFFSET_STATUS)); 905 if (!(status & VIA_REG_STAT_ACTIVE)) { 906 res = 0; 907 goto unlock; 908 } 909 if (count & 0xffffff) { 910 idx = count >> 24; 911 if (idx >= viadev->tbl_entries) { 864 count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)); 865 status = viadev->in_interrupt; 866 if (!status) 867 status = inb(VIADEV_REG(viadev, OFFSET_STATUS)); 868 869 if (!(status & VIA_REG_STAT_ACTIVE)) { 870 res = 0; 871 goto unlock; 872 } 873 if (count & 0xffffff) { 874 idx = count >> 24; 875 if (idx >= viadev->tbl_entries) { 912 876 #ifdef POINTER_DEBUG 913 printk("fail: invalid idx = %i/%i\n", idx, viadev->tbl_entries); 877 printk(KERN_DEBUG "fail: invalid idx = %i/%i\n", idx, 878 viadev->tbl_entries); 914 879 #endif 915 res = viadev->lastpos; 880 res = viadev->lastpos; 881 } else { 882 count &= 0xffffff; 883 res = calc_linear_pos(viadev, idx, count); 884 } 916 885 } else { 917 count &= 0xffffff; 918 res = calc_linear_pos(viadev, idx, count); 919 } 920 } else { 921 res = viadev->hwptr_done; 922 if (!viadev->in_interrupt) { 923 if (status & VIA_REG_STAT_EOL) { 924 res = 0; 925 } else 926 if (status & VIA_REG_STAT_FLAG) { 927 res += viadev->fragsize; 928 } 929 } 930 } 931 unlock: 932 viadev->lastpos = res; 886 res = viadev->hwptr_done; 887 if (!viadev->in_interrupt) { 888 if (status & VIA_REG_STAT_EOL) { 889 res = 0; 890 } else 891 if (status & VIA_REG_STAT_FLAG) { 892 res += viadev->fragsize; 893 } 894 } 895 } 896 unlock: 897 viadev->lastpos = res; 933 898 spin_unlock(&chip->reg_lock); 934 899 … … 941 906 * allocate the buffer and build up the buffer description table 942 907 */ 943 static int snd_via82xx_hw_params(s nd_pcm_substream_t *substream,944 snd_pcm_hw_params_t *hw_params)945 { 946 via82xx_t*chip = snd_pcm_substream_chip(substream);947 viadev_t *viadev = (viadev_t *)substream->runtime->private_data;948 949 950 951 952 953 954 955 956 957 958 959 908 static int snd_via82xx_hw_params(struct snd_pcm_substream *substream, 909 struct snd_pcm_hw_params *hw_params) 910 { 911 struct via82xx *chip = snd_pcm_substream_chip(substream); 912 struct viadev *viadev = substream->runtime->private_data; 913 int err; 914 915 err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); 916 if (err < 0) 917 return err; 918 err = build_via_table(viadev, substream, chip->pci, 919 params_periods(hw_params), 920 params_period_bytes(hw_params)); 921 if (err < 0) 922 return err; 923 924 return 0; 960 925 } 961 926 … … 964 929 * clean up the buffer description table and release the buffer 965 930 */ 966 static int snd_via82xx_hw_free(snd_pcm_substream_t * substream) 967 { 968 via82xx_t *chip = snd_pcm_substream_chip(substream); 969 viadev_t *viadev = (viadev_t *)substream->runtime->private_data; 970 971 clean_via_table(viadev, substream, chip->pci); 972 snd_pcm_lib_free_pages(substream); 973 return 0; 974 } 931 static int snd_via82xx_hw_free(struct snd_pcm_substream *substream) 932 { 933 struct via82xx *chip = snd_pcm_substream_chip(substream); 934 struct viadev *viadev = substream->runtime->private_data; 935 936 clean_via_table(viadev, substream, chip->pci); 937 snd_pcm_lib_free_pages(substream); 938 return 0; 939 } 940 975 941 976 942 /* 977 943 * set up the table pointer 978 944 */ 979 static void snd_via82xx_set_table_ptr( via82xx_t *chip, viadev_t*viadev)945 static void snd_via82xx_set_table_ptr(struct via82xx *chip, struct viadev *viadev) 980 946 { 981 947 snd_via82xx_codec_ready(chip, 0); … … 984 950 snd_via82xx_codec_ready(chip, 0); 985 951 } 952 986 953 /* 987 954 * prepare callback for playback and capture on via686 988 955 */ 989 static void via686_setup_format(via82xx_t *chip, viadev_t *viadev, snd_pcm_runtime_t *runtime) 990 { 991 snd_via82xx_channel_reset(chip, viadev); 992 /* this must be set after channel_reset */ 993 snd_via82xx_set_table_ptr(chip, viadev); 994 outb(VIA_REG_TYPE_AUTOSTART | 995 (runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA_REG_TYPE_16BIT : 0) | 996 (runtime->channels > 1 ? VIA_REG_TYPE_STEREO : 0) | 997 ((viadev->reg_offset & 0x10) == 0 ? VIA_REG_TYPE_INT_LSAMPLE : 0) | 998 VIA_REG_TYPE_INT_EOL | 999 VIA_REG_TYPE_INT_FLAG, VIADEV_REG(viadev, OFFSET_TYPE)); 1000 } 1001 1002 static int snd_via686_playback_prepare(snd_pcm_substream_t *substream) 1003 { 1004 via82xx_t *chip = snd_pcm_substream_chip(substream); 1005 viadev_t *viadev = (viadev_t *)substream->runtime->private_data; 1006 snd_pcm_runtime_t *runtime = substream->runtime; 1007 1008 snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate); 1009 snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate); 1010 via686_setup_format(chip, viadev, runtime); 1011 return 0; 1012 } 1013 1014 static int snd_via686_capture_prepare(snd_pcm_substream_t *substream) 1015 { 1016 via82xx_t *chip = snd_pcm_substream_chip(substream); 1017 viadev_t *viadev = (viadev_t *)substream->runtime->private_data; 1018 snd_pcm_runtime_t *runtime = substream->runtime; 1019 1020 snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate); 1021 via686_setup_format(chip, viadev, runtime); 1022 return 0; 956 static void via686_setup_format(struct via82xx *chip, struct viadev *viadev, 957 struct snd_pcm_runtime *runtime) 958 { 959 snd_via82xx_channel_reset(chip, viadev); 960 /* this must be set after channel_reset */ 961 snd_via82xx_set_table_ptr(chip, viadev); 962 outb(VIA_REG_TYPE_AUTOSTART | 963 (runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA_REG_TYPE_16BIT : 0) | 964 (runtime->channels > 1 ? VIA_REG_TYPE_STEREO : 0) | 965 ((viadev->reg_offset & 0x10) == 0 ? VIA_REG_TYPE_INT_LSAMPLE : 0) | 966 VIA_REG_TYPE_INT_EOL | 967 VIA_REG_TYPE_INT_FLAG, VIADEV_REG(viadev, OFFSET_TYPE)); 968 } 969 970 static int snd_via686_playback_prepare(struct snd_pcm_substream *substream) 971 { 972 struct via82xx *chip = snd_pcm_substream_chip(substream); 973 struct viadev *viadev = substream->runtime->private_data; 974 struct snd_pcm_runtime *runtime = substream->runtime; 975 976 snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate); 977 snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate); 978 via686_setup_format(chip, viadev, runtime); 979 return 0; 980 } 981 982 static int snd_via686_capture_prepare(struct snd_pcm_substream *substream) 983 { 984 struct via82xx *chip = snd_pcm_substream_chip(substream); 985 struct viadev *viadev = substream->runtime->private_data; 986 struct snd_pcm_runtime *runtime = substream->runtime; 987 988 snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate); 989 via686_setup_format(chip, viadev, runtime); 990 return 0; 1023 991 } 1024 992 … … 1028 996 static int via_lock_rate(struct via_rate_lock *rec, int rate) 1029 997 { 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 998 int changed = 0; 999 1000 spin_lock_irq(&rec->lock); 1001 if (rec->rate != rate) { 1002 if (rec->rate && rec->used > 1) /* already set */ 1003 changed = -EINVAL; 1004 else { 1005 rec->rate = rate; 1006 changed = 1; 1007 } 1008 } 1009 spin_unlock_irq(&rec->lock); 1010 return changed; 1043 1011 } 1044 1012 … … 1046 1014 * prepare callback for DSX playback on via823x 1047 1015 */ 1048 static int snd_via8233_playback_prepare(snd_pcm_substream_t *substream) 1049 { 1050 via82xx_t *chip = snd_pcm_substream_chip(substream); 1051 viadev_t *viadev = (viadev_t *)substream->runtime->private_data; 1052 snd_pcm_runtime_t *runtime = substream->runtime; 1053 int ac97_rate = chip->dxs_src ? 48000 : runtime->rate; 1054 int rate_changed; 1055 u32 rbits; 1056 1057 if ((rate_changed = via_lock_rate(&chip->rates[0], ac97_rate)) < 0) 1058 return rate_changed; 1059 if (rate_changed) 1060 snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, 1061 chip->no_vra ? 48000 : runtime->rate); 1062 if (chip->spdif_on && viadev->reg_offset == 0x30) 1063 snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate); 1064 if (runtime->rate == 48000) 1065 rbits = 0xfffff; 1066 else 1067 rbits = (0x100000 / 48000) * runtime->rate + ((0x100000 % 48000) * runtime->rate) / 48000; 1068 1069 snd_assert((rbits & ~0xfffff) == 0, return -EINVAL); 1070 snd_via82xx_channel_reset(chip, viadev); 1071 snd_via82xx_set_table_ptr(chip, viadev); 1072 outb(chip->playback_volume[0], VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_L)); 1073 outb(chip->playback_volume[1], VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_R)); 1074 outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) | /* format */ 1075 (runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) | /* stereo */ 1076 rbits | /* rate */ 1077 0xff000000, /* STOP index is never reached */ 1078 VIADEV_REG(viadev, OFFSET_STOP_IDX)); 1079 udelay(20); 1080 snd_via82xx_codec_ready(chip, 0); 1081 return 0; 1016 static int snd_via8233_playback_prepare(struct snd_pcm_substream *substream) 1017 { 1018 struct via82xx *chip = snd_pcm_substream_chip(substream); 1019 struct viadev *viadev = substream->runtime->private_data; 1020 struct snd_pcm_runtime *runtime = substream->runtime; 1021 int ac97_rate = chip->dxs_src ? 48000 : runtime->rate; 1022 int rate_changed; 1023 u32 rbits; 1024 1025 if ((rate_changed = via_lock_rate(&chip->rates[0], ac97_rate)) < 0) 1026 return rate_changed; 1027 if (rate_changed) 1028 snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, 1029 chip->no_vra ? 48000 : runtime->rate); 1030 if (chip->spdif_on && viadev->reg_offset == 0x30) 1031 snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate); 1032 1033 if (runtime->rate == 48000) 1034 rbits = 0xfffff; 1035 else 1036 rbits = (0x100000 / 48000) * runtime->rate + 1037 ((0x100000 % 48000) * runtime->rate) / 48000; 1038 snd_assert((rbits & ~0xfffff) == 0, return -EINVAL); 1039 snd_via82xx_channel_reset(chip, viadev); 1040 snd_via82xx_set_table_ptr(chip, viadev); 1041 outb(chip->playback_volume[viadev->reg_offset / 0x10][0], 1042 VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_L)); 1043 outb(chip->playback_volume[viadev->reg_offset / 0x10][1], 1044 VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_R)); 1045 outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) | /* format */ 1046 (runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) | /* stereo */ 1047 rbits | /* rate */ 1048 0xff000000, /* STOP index is never reached */ 1049 VIADEV_REG(viadev, OFFSET_STOP_IDX)); 1050 udelay(20); 1051 snd_via82xx_codec_ready(chip, 0); 1052 return 0; 1082 1053 } 1083 1054 … … 1085 1056 * prepare callback for multi-channel playback on via823x 1086 1057 */ 1087 static int snd_via8233_multi_prepare(snd_pcm_substream_t *substream) 1088 { 1089 via82xx_t *chip = snd_pcm_substream_chip(substream); 1090 viadev_t *viadev = (viadev_t *)substream->runtime->private_data; 1091 snd_pcm_runtime_t *runtime = substream->runtime; 1092 unsigned int slots; 1093 int fmt; 1094 1095 if (via_lock_rate(&chip->rates[0], runtime->rate) < 0) 1096 return -EINVAL; 1097 snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate); 1098 snd_ac97_set_rate(chip->ac97, AC97_PCM_SURR_DAC_RATE, runtime->rate); 1099 snd_ac97_set_rate(chip->ac97, AC97_PCM_LFE_DAC_RATE, runtime->rate); 1100 snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate); 1101 snd_via82xx_channel_reset(chip, viadev); 1102 snd_via82xx_set_table_ptr(chip, viadev); 1103 1104 fmt = (runtime->format == SNDRV_PCM_FORMAT_S16_LE) ? VIA_REG_MULTPLAY_FMT_16BIT : VIA_REG_MULTPLAY_FMT_8BIT; 1105 fmt |= runtime->channels << 4; 1106 outb(fmt, VIADEV_REG(viadev, OFS_MULTPLAY_FORMAT)); 1058 static int snd_via8233_multi_prepare(struct snd_pcm_substream *substream) 1059 { 1060 struct via82xx *chip = snd_pcm_substream_chip(substream); 1061 struct viadev *viadev = substream->runtime->private_data; 1062 struct snd_pcm_runtime *runtime = substream->runtime; 1063 unsigned int slots; 1064 int fmt; 1065 1066 if (via_lock_rate(&chip->rates[0], runtime->rate) < 0) 1067 return -EINVAL; 1068 snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate); 1069 snd_ac97_set_rate(chip->ac97, AC97_PCM_SURR_DAC_RATE, runtime->rate); 1070 snd_ac97_set_rate(chip->ac97, AC97_PCM_LFE_DAC_RATE, runtime->rate); 1071 snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate); 1072 snd_via82xx_channel_reset(chip, viadev); 1073 snd_via82xx_set_table_ptr(chip, viadev); 1074 1075 fmt = (runtime->format == SNDRV_PCM_FORMAT_S16_LE) ? 1076 VIA_REG_MULTPLAY_FMT_16BIT : VIA_REG_MULTPLAY_FMT_8BIT; 1077 fmt |= runtime->channels << 4; 1078 outb(fmt, VIADEV_REG(viadev, OFS_MULTPLAY_FORMAT)); 1107 1079 #if 0 1108 1109 1110 1080 if (chip->revision == VIA_REV_8233A) 1081 slots = 0; 1082 else 1111 1083 #endif 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1084 { 1085 /* set sample number to slot 3, 4, 7, 8, 6, 9 (for VIA8233/C,8235) */ 1086 /* corresponding to FL, FR, RL, RR, C, LFE ?? */ 1087 switch (runtime->channels) { 1088 case 1: slots = (1<<0) | (1<<4); break; 1089 case 2: slots = (1<<0) | (2<<4); break; 1090 case 3: slots = (1<<0) | (2<<4) | (5<<8); break; 1091 case 4: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12); break; 1092 case 5: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12) | (5<<16); break; 1093 case 6: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12) | (5<<16) | (6<<20); break; 1094 default: slots = 0; break; 1095 } 1096 } 1097 /* STOP index is never reached */ 1098 outl(0xff000000 | slots, VIADEV_REG(viadev, OFFSET_STOP_IDX)); 1099 udelay(20); 1100 snd_via82xx_codec_ready(chip, 0); 1101 return 0; 1130 1102 } 1131 1103 … … 1133 1105 * prepare callback for capture on via823x 1134 1106 */ 1135 static int snd_via8233_capture_prepare(s nd_pcm_substream_t*substream)1136 { 1137 via82xx_t*chip = snd_pcm_substream_chip(substream);1138 viadev_t *viadev = (viadev_t *)substream->runtime->private_data;1139 snd_pcm_runtime_t*runtime = substream->runtime;1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1107 static int snd_via8233_capture_prepare(struct snd_pcm_substream *substream) 1108 { 1109 struct via82xx *chip = snd_pcm_substream_chip(substream); 1110 struct viadev *viadev = substream->runtime->private_data; 1111 struct snd_pcm_runtime *runtime = substream->runtime; 1112 1113 if (via_lock_rate(&chip->rates[1], runtime->rate) < 0) 1114 return -EINVAL; 1115 snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate); 1116 snd_via82xx_channel_reset(chip, viadev); 1117 snd_via82xx_set_table_ptr(chip, viadev); 1118 outb(VIA_REG_CAPTURE_FIFO_ENABLE, VIADEV_REG(viadev, OFS_CAPTURE_FIFO)); 1119 outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) | 1120 (runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) | 1121 0xff000000, /* STOP index is never reached */ 1122 VIADEV_REG(viadev, OFFSET_STOP_IDX)); 1123 udelay(20); 1124 snd_via82xx_codec_ready(chip, 0); 1125 return 0; 1154 1126 } 1155 1127 … … 1158 1130 * pcm hardware definition, identical for both playback and capture 1159 1131 */ 1160 static s nd_pcm_hardware_tsnd_via82xx_hw =1161 { 1162 /* info: */(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |1163 1164 1165 /*SNDRV_PCM_INFO_RESUME |*/1166 1167 /* formats: */SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,1168 /* rates: */SNDRV_PCM_RATE_48000,1169 /* rate_min: */48000,1170 /* rate_max: */48000,1171 /* channels_min: */1,1172 /* channels_max: */2,1173 /* buffer_bytes_max: */128 * 1024,1174 /* period_bytes_min: */32,1175 /* period_bytes_max: */128 * 1024,1176 /* periods_min: */2,1177 /* periods_max: */VIA_TABLE_SIZE / 2,1178 /* fifo_size: */0,1132 static struct snd_pcm_hardware snd_via82xx_hw = 1133 { 1134 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 1135 SNDRV_PCM_INFO_BLOCK_TRANSFER | 1136 SNDRV_PCM_INFO_MMAP_VALID | 1137 /* SNDRV_PCM_INFO_RESUME | */ 1138 SNDRV_PCM_INFO_PAUSE), 1139 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, 1140 .rates = SNDRV_PCM_RATE_48000, 1141 .rate_min = 48000, 1142 .rate_max = 48000, 1143 .channels_min = 1, 1144 .channels_max = 2, 1145 .buffer_bytes_max = 128 * 1024, 1146 .period_bytes_min = 32, 1147 .period_bytes_max = 128 * 1024, 1148 .periods_min = 2, 1149 .periods_max = VIA_TABLE_SIZE / 2, 1150 .fifo_size = 0, 1179 1151 }; 1180 1152 … … 1183 1155 * open callback skeleton 1184 1156 */ 1185 static int snd_via82xx_pcm_open(via82xx_t *chip, viadev_t *viadev, snd_pcm_substream_t * substream) 1186 { 1187 snd_pcm_runtime_t *runtime = substream->runtime; 1188 int err; 1189 struct via_rate_lock *ratep; 1190 1191 runtime->hw = snd_via82xx_hw; 1192 1193 /* set the hw rate condition */ 1194 ratep = &chip->rates[viadev->direction]; 1195 spin_lock_irq(&ratep->lock); 1196 ratep->used++; 1197 if (chip->spdif_on && viadev->reg_offset == 0x30) { 1198 /* DXS#3 and spdif is on */ 1199 runtime->hw.rates = chip->ac97->rates[AC97_RATES_SPDIF]; 1200 snd_pcm_limit_hw_rates(runtime); 1201 } else if (chip->dxs_fixed && viadev->reg_offset < 0x40) { 1202 /* fixed DXS playback rate */ 1203 runtime->hw.rates = SNDRV_PCM_RATE_48000; 1204 runtime->hw.rate_min = runtime->hw.rate_max = 48000; 1205 } else if (chip->dxs_src && viadev->reg_offset < 0x40) { 1206 /* use full SRC capabilities of DXS */ 1207 runtime->hw.rates = (SNDRV_PCM_RATE_CONTINUOUS | 1208 SNDRV_PCM_RATE_8000_48000); 1209 runtime->hw.rate_min = 8000; 1210 runtime->hw.rate_max = 48000; 1211 } else if (! ratep->rate) { 1212 int idx = viadev->direction ? AC97_RATES_ADC : AC97_RATES_FRONT_DAC; 1213 runtime->hw.rates = chip->ac97->rates[idx]; 1214 snd_pcm_limit_hw_rates(runtime); 1215 } else { 1216 /* a fixed rate */ 1217 runtime->hw.rates = SNDRV_PCM_RATE_KNOT; 1218 runtime->hw.rate_max = runtime->hw.rate_min = ratep->rate; 1219 } 1220 spin_unlock_irq(&ratep->lock); 1221 1222 /* we may remove following constaint when we modify table entries 1223 in interrupt */ 1224 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 1225 return err; 1226 1227 runtime->private_data = viadev; 1228 viadev->substream = substream; 1229 1230 return 0; 1231 } 1157 static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev, 1158 struct snd_pcm_substream *substream) 1159 { 1160 struct snd_pcm_runtime *runtime = substream->runtime; 1161 int err; 1162 struct via_rate_lock *ratep; 1163 1164 runtime->hw = snd_via82xx_hw; 1165 1166 /* set the hw rate condition */ 1167 ratep = &chip->rates[viadev->direction]; 1168 spin_lock_irq(&ratep->lock); 1169 ratep->used++; 1170 if (chip->spdif_on && viadev->reg_offset == 0x30) { 1171 /* DXS#3 and spdif is on */ 1172 runtime->hw.rates = chip->ac97->rates[AC97_RATES_SPDIF]; 1173 snd_pcm_limit_hw_rates(runtime); 1174 } else if (chip->dxs_fixed && viadev->reg_offset < 0x40) { 1175 /* fixed DXS playback rate */ 1176 runtime->hw.rates = SNDRV_PCM_RATE_48000; 1177 runtime->hw.rate_min = runtime->hw.rate_max = 48000; 1178 } else if (chip->dxs_src && viadev->reg_offset < 0x40) { 1179 /* use full SRC capabilities of DXS */ 1180 runtime->hw.rates = (SNDRV_PCM_RATE_CONTINUOUS | 1181 SNDRV_PCM_RATE_8000_48000); 1182 runtime->hw.rate_min = 8000; 1183 runtime->hw.rate_max = 48000; 1184 } else if (! ratep->rate) { 1185 int idx = viadev->direction ? AC97_RATES_ADC : AC97_RATES_FRONT_DAC; 1186 runtime->hw.rates = chip->ac97->rates[idx]; 1187 snd_pcm_limit_hw_rates(runtime); 1188 } else { 1189 /* a fixed rate */ 1190 runtime->hw.rates = SNDRV_PCM_RATE_KNOT; 1191 runtime->hw.rate_max = runtime->hw.rate_min = ratep->rate; 1192 } 1193 spin_unlock_irq(&ratep->lock); 1194 1195 /* we may remove following constaint when we modify table entries 1196 in interrupt */ 1197 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 1198 return err; 1199 1200 runtime->private_data = viadev; 1201 viadev->substream = substream; 1202 1203 return 0; 1204 } 1205 1232 1206 1233 1207 /* 1234 1208 * open callback for playback on via686 and via823x DSX 1235 1209 */ 1236 static int snd_via82xx_playback_open(snd_pcm_substream_t * substream) 1237 { 1238 via82xx_t *chip = snd_pcm_substream_chip(substream); 1239 viadev_t *viadev = &chip->devs[chip->playback_devno + substream->number]; 1240 int err; 1241 1242 if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0) 1243 return err; 1244 return 0; 1245 } 1246 1210 static int snd_via82xx_playback_open(struct snd_pcm_substream *substream) 1211 { 1212 struct via82xx *chip = snd_pcm_substream_chip(substream); 1213 struct viadev *viadev = &chip->devs[chip->playback_devno + substream->number]; 1214 int err; 1215 1216 if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0) 1217 return err; 1218 return 0; 1219 } 1247 1220 1248 1221 /* 1249 1222 * open callback for playback on via823x multi-channel 1250 1223 */ 1251 static int snd_via8233_multi_open(snd_pcm_substream_t * substream) 1252 { 1253 via82xx_t *chip = snd_pcm_substream_chip(substream); 1254 viadev_t *viadev = &chip->devs[chip->multi_devno]; 1255 int err; 1256 /* channels constraint for VIA8233A 1257 * 3 and 5 channels are not supported 1258 */ 1259 static unsigned int channels[] = { 1260 1, 2, 4, 6 1261 }; 1262 static snd_pcm_hw_constraint_list_t hw_constraints_channels = { 1263 /*.count = */ARRAY_SIZE(channels), 1264 /*.list = */channels, 1265 /*.mask = */0, 1266 }; 1267 1268 if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0) 1269 return err; 1270 substream->runtime->hw.channels_max = 6; 1271 if (chip->revision == VIA_REV_8233A) 1272 snd_pcm_hw_constraint_list(substream->runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &hw_constraints_channels); 1273 return 0; 1224 static int snd_via8233_multi_open(struct snd_pcm_substream *substream) 1225 { 1226 struct via82xx *chip = snd_pcm_substream_chip(substream); 1227 struct viadev *viadev = &chip->devs[chip->multi_devno]; 1228 int err; 1229 /* channels constraint for VIA8233A 1230 * 3 and 5 channels are not supported 1231 */ 1232 static unsigned int channels[] = { 1233 1, 2, 4, 6 1234 }; 1235 static struct snd_pcm_hw_constraint_list hw_constraints_channels = { 1236 .count = ARRAY_SIZE(channels), 1237 .list = channels, 1238 .mask = 0, 1239 }; 1240 1241 if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0) 1242 return err; 1243 substream->runtime->hw.channels_max = 6; 1244 if (chip->revision == VIA_REV_8233A) 1245 snd_pcm_hw_constraint_list(substream->runtime, 0, 1246 SNDRV_PCM_HW_PARAM_CHANNELS, 1247 &hw_constraints_channels); 1248 return 0; 1274 1249 } 1275 1250 … … 1277 1252 * open callback for capture on via686 and via823x 1278 1253 */ 1279 static int snd_via82xx_capture_open(s nd_pcm_substream_t *substream)1280 { 1281 via82xx_t*chip = snd_pcm_substream_chip(substream);1282 viadev_t*viadev = &chip->devs[chip->capture_devno + substream->pcm->device];1283 1284 1254 static int snd_via82xx_capture_open(struct snd_pcm_substream *substream) 1255 { 1256 struct via82xx *chip = snd_pcm_substream_chip(substream); 1257 struct viadev *viadev = &chip->devs[chip->capture_devno + substream->pcm->device]; 1258 1259 return snd_via82xx_pcm_open(chip, viadev, substream); 1285 1260 } 1286 1261 … … 1288 1263 * close callback 1289 1264 */ 1290 static int snd_via82xx_pcm_close(s nd_pcm_substream_t *substream)1291 { 1292 via82xx_t*chip = snd_pcm_substream_chip(substream);1293 viadev_t *viadev = (viadev_t *)substream->runtime->private_data;1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1265 static int snd_via82xx_pcm_close(struct snd_pcm_substream *substream) 1266 { 1267 struct via82xx *chip = snd_pcm_substream_chip(substream); 1268 struct viadev *viadev = substream->runtime->private_data; 1269 struct via_rate_lock *ratep; 1270 1271 /* release the rate lock */ 1272 ratep = &chip->rates[viadev->direction]; 1273 spin_lock_irq(&ratep->lock); 1274 ratep->used--; 1275 if (! ratep->used) 1276 ratep->rate = 0; 1277 spin_unlock_irq(&ratep->lock); 1278 1279 viadev->substream = NULL; 1280 return 0; 1306 1281 } 1307 1282 1308 1283 1309 1284 /* via686 playback callbacks */ 1310 static s nd_pcm_ops_tsnd_via686_playback_ops = {1311 /* .open = */snd_via82xx_playback_open,1312 /* .close = */snd_via82xx_pcm_close,1313 /* .ioctl = */snd_pcm_lib_ioctl,1314 /* .hw_params = */snd_via82xx_hw_params,1315 /* .hw_free = */snd_via82xx_hw_free,1316 /* .prepare = */snd_via686_playback_prepare,1317 /* .trigger = */snd_via82xx_pcm_trigger,1318 /* .pointer = */ snd_via686_pcm_pointer,0,0,1319 /* .page = */ snd_pcm_sgbuf_ops_page,0 1285 static struct snd_pcm_ops snd_via686_playback_ops = { 1286 .open = snd_via82xx_playback_open, 1287 .close = snd_via82xx_pcm_close, 1288 .ioctl = snd_pcm_lib_ioctl, 1289 .hw_params = snd_via82xx_hw_params, 1290 .hw_free = snd_via82xx_hw_free, 1291 .prepare = snd_via686_playback_prepare, 1292 .trigger = snd_via82xx_pcm_trigger, 1293 .pointer = snd_via686_pcm_pointer, 1294 .page = snd_pcm_sgbuf_ops_page, 1320 1295 }; 1321 1296 1322 1297 /* via686 capture callbacks */ 1323 static s nd_pcm_ops_tsnd_via686_capture_ops = {1324 /* .open = */snd_via82xx_capture_open,1325 /* .close = */snd_via82xx_pcm_close,1326 /* .ioctl = */snd_pcm_lib_ioctl,1327 /* .hw_params = */snd_via82xx_hw_params,1328 /* .hw_free = */snd_via82xx_hw_free,1329 /* .prepare = */snd_via686_capture_prepare,1330 /* .trigger = */snd_via82xx_pcm_trigger,1331 /* .pointer = */ snd_via686_pcm_pointer,0,0,1332 /* .page = */ snd_pcm_sgbuf_ops_page,0 1298 static struct snd_pcm_ops snd_via686_capture_ops = { 1299 .open = snd_via82xx_capture_open, 1300 .close = snd_via82xx_pcm_close, 1301 .ioctl = snd_pcm_lib_ioctl, 1302 .hw_params = snd_via82xx_hw_params, 1303 .hw_free = snd_via82xx_hw_free, 1304 .prepare = snd_via686_capture_prepare, 1305 .trigger = snd_via82xx_pcm_trigger, 1306 .pointer = snd_via686_pcm_pointer, 1307 .page = snd_pcm_sgbuf_ops_page, 1333 1308 }; 1334 1309 1335 1310 /* via823x DSX playback callbacks */ 1336 static s nd_pcm_ops_tsnd_via8233_playback_ops = {1337 /* .open = */snd_via82xx_playback_open,1338 /* .close = */snd_via82xx_pcm_close,1339 /* .ioctl = */snd_pcm_lib_ioctl,1340 /* .hw_params = */snd_via82xx_hw_params,1341 /* .hw_free = */snd_via82xx_hw_free,1342 /* .prepare = */snd_via8233_playback_prepare,1343 /* .trigger = */snd_via82xx_pcm_trigger,1344 /* .pointer = */ snd_via8233_pcm_pointer,0,0,1345 /* .page = */ snd_pcm_sgbuf_ops_page,0 1311 static struct snd_pcm_ops snd_via8233_playback_ops = { 1312 .open = snd_via82xx_playback_open, 1313 .close = snd_via82xx_pcm_close, 1314 .ioctl = snd_pcm_lib_ioctl, 1315 .hw_params = snd_via82xx_hw_params, 1316 .hw_free = snd_via82xx_hw_free, 1317 .prepare = snd_via8233_playback_prepare, 1318 .trigger = snd_via82xx_pcm_trigger, 1319 .pointer = snd_via8233_pcm_pointer, 1320 .page = snd_pcm_sgbuf_ops_page, 1346 1321 }; 1347 1322 1348 1323 /* via823x multi-channel playback callbacks */ 1349 static s nd_pcm_ops_tsnd_via8233_multi_ops = {1350 /* .open = */snd_via8233_multi_open,1351 /* .close = */snd_via82xx_pcm_close,1352 /* .ioctl = */snd_pcm_lib_ioctl,1353 /* .hw_params = */snd_via82xx_hw_params,1354 /* .hw_free = */snd_via82xx_hw_free,1355 /* .prepare = */snd_via8233_multi_prepare,1356 /* .trigger = */snd_via82xx_pcm_trigger,1357 /* .pointer = */ snd_via8233_pcm_pointer,0,0,1358 /* .page = */ snd_pcm_sgbuf_ops_page,0 1324 static struct snd_pcm_ops snd_via8233_multi_ops = { 1325 .open = snd_via8233_multi_open, 1326 .close = snd_via82xx_pcm_close, 1327 .ioctl = snd_pcm_lib_ioctl, 1328 .hw_params = snd_via82xx_hw_params, 1329 .hw_free = snd_via82xx_hw_free, 1330 .prepare = snd_via8233_multi_prepare, 1331 .trigger = snd_via82xx_pcm_trigger, 1332 .pointer = snd_via8233_pcm_pointer, 1333 .page = snd_pcm_sgbuf_ops_page, 1359 1334 }; 1360 1335 1361 1336 /* via823x capture callbacks */ 1362 static s nd_pcm_ops_tsnd_via8233_capture_ops = {1363 /* .open = */snd_via82xx_capture_open,1364 /* .close = */snd_via82xx_pcm_close,1365 /* .ioctl = */snd_pcm_lib_ioctl,1366 /* .hw_params = */snd_via82xx_hw_params,1367 /* .hw_free = */snd_via82xx_hw_free,1368 /* .prepare = */snd_via8233_capture_prepare,1369 /* .trigger = */snd_via82xx_pcm_trigger,1370 /* .pointer = */ snd_via8233_pcm_pointer,0,0,1371 /* .page = */ snd_pcm_sgbuf_ops_page,0 1337 static struct snd_pcm_ops snd_via8233_capture_ops = { 1338 .open = snd_via82xx_capture_open, 1339 .close = snd_via82xx_pcm_close, 1340 .ioctl = snd_pcm_lib_ioctl, 1341 .hw_params = snd_via82xx_hw_params, 1342 .hw_free = snd_via82xx_hw_free, 1343 .prepare = snd_via8233_capture_prepare, 1344 .trigger = snd_via82xx_pcm_trigger, 1345 .pointer = snd_via8233_pcm_pointer, 1346 .page = snd_pcm_sgbuf_ops_page, 1372 1347 }; 1373 1348 1374 static void init_viadev(via82xx_t *chip, int idx, unsigned int reg_offset, int shadow_pos, int direction) 1375 { 1376 chip->devs[idx].reg_offset = reg_offset; 1377 chip->devs[idx].shadow_shift = shadow_pos * 4; 1378 chip->devs[idx].direction = direction; 1379 chip->devs[idx].port = chip->port + reg_offset; 1349 1350 static void init_viadev(struct via82xx *chip, int idx, unsigned int reg_offset, 1351 int shadow_pos, int direction) 1352 { 1353 chip->devs[idx].reg_offset = reg_offset; 1354 chip->devs[idx].shadow_shift = shadow_pos * 4; 1355 chip->devs[idx].direction = direction; 1356 chip->devs[idx].port = chip->port + reg_offset; 1380 1357 } 1381 1358 … … 1383 1360 * create pcm instances for VIA8233, 8233C and 8235 (not 8233A) 1384 1361 */ 1385 static int __devinit snd_via8233_pcm_new(via82xx_t *chip) 1386 { 1387 snd_pcm_t *pcm; 1388 int i, err; 1389 1390 chip->playback_devno = 0; /* x 4 */ 1391 chip->multi_devno = 4; /* x 1 */ 1392 chip->capture_devno = 5; /* x 2 */ 1393 chip->num_devs = 7; 1394 chip->intr_mask = 0x33033333; /* FLAG|EOL for rec0-1, mc, sdx0-3 */ 1395 1396 /* PCM #0: 4 DSX playbacks and 1 capture */ 1397 err = snd_pcm_new(chip->card, chip->card->shortname, 0, 4, 1, &pcm); 1398 if (err < 0) 1399 return err; 1400 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_playback_ops); 1401 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops); 1402 pcm->private_data = chip; 1403 strcpy(pcm->name, chip->card->shortname); 1404 chip->pcms[0] = pcm; 1405 /* set up playbacks */ 1406 for (i = 0; i < 4; i++) 1407 init_viadev(chip, i, 0x10 * i, i, 0); 1408 /* capture */ 1409 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1); 1410 1411 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1412 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) 1413 return err; 1414 1415 /* PCM #1: multi-channel playback and 2nd capture */ 1416 err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 1, &pcm); 1417 if (err < 0) 1418 return err; 1419 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_multi_ops); 1420 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops); 1421 pcm->private_data = chip; 1422 strcpy(pcm->name, chip->card->shortname); 1423 chip->pcms[1] = pcm; 1424 /* set up playback */ 1425 init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0); 1426 /* set up capture */ 1427 init_viadev(chip, chip->capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 7, 1); 1428 1429 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1430 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) 1431 return err; 1432 1433 return 0; 1362 static int __devinit snd_via8233_pcm_new(struct via82xx *chip) 1363 { 1364 struct snd_pcm *pcm; 1365 int i, err; 1366 1367 chip->playback_devno = 0; /* x 4 */ 1368 chip->multi_devno = 4; /* x 1 */ 1369 chip->capture_devno = 5; /* x 2 */ 1370 chip->num_devs = 7; 1371 chip->intr_mask = 0x33033333; /* FLAG|EOL for rec0-1, mc, sdx0-3 */ 1372 1373 /* PCM #0: 4 DSX playbacks and 1 capture */ 1374 err = snd_pcm_new(chip->card, chip->card->shortname, 0, 4, 1, &pcm); 1375 if (err < 0) 1376 return err; 1377 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_playback_ops); 1378 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops); 1379 pcm->private_data = chip; 1380 strcpy(pcm->name, chip->card->shortname); 1381 chip->pcms[0] = pcm; 1382 /* set up playbacks */ 1383 for (i = 0; i < 4; i++) 1384 init_viadev(chip, i, 0x10 * i, i, 0); 1385 /* capture */ 1386 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1); 1387 1388 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1389 snd_dma_pci_data(chip->pci), 1390 64*1024, 128*1024)) < 0) 1391 return err; 1392 1393 /* PCM #1: multi-channel playback and 2nd capture */ 1394 err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 1, &pcm); 1395 if (err < 0) 1396 return err; 1397 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_multi_ops); 1398 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops); 1399 pcm->private_data = chip; 1400 strcpy(pcm->name, chip->card->shortname); 1401 chip->pcms[1] = pcm; 1402 /* set up playback */ 1403 init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0); 1404 /* set up capture */ 1405 init_viadev(chip, chip->capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 7, 1); 1406 1407 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1408 snd_dma_pci_data(chip->pci), 1409 64*1024, 128*1024)) < 0) 1410 return err; 1411 1412 return 0; 1434 1413 } 1435 1414 … … 1437 1416 * create pcm instances for VIA8233A 1438 1417 */ 1439 static int __devinit snd_via8233a_pcm_new(via82xx_t *chip) 1440 { 1441 snd_pcm_t *pcm; 1442 int err; 1443 1444 chip->multi_devno = 0; 1445 chip->playback_devno = 1; 1446 chip->capture_devno = 2; 1447 chip->num_devs = 3; 1448 chip->intr_mask = 0x03033000; /* FLAG|EOL for rec0, mc, sdx3 */ 1449 1450 /* PCM #0: multi-channel playback and capture */ 1451 err = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm); 1452 if (err < 0) 1453 return err; 1454 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_multi_ops); 1455 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops); 1456 pcm->private_data = chip; 1457 strcpy(pcm->name, chip->card->shortname); 1458 chip->pcms[0] = pcm; 1459 /* set up playback */ 1460 init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0); 1461 /* capture */ 1462 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1); 1463 1464 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1465 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) 1466 return err; 1467 1468 /* SPDIF supported? */ 1469 if (! ac97_can_spdif(chip->ac97)) 1470 return 0; 1471 1472 /* PCM #1: DXS3 playback (for spdif) */ 1473 err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 0, &pcm); 1474 if (err < 0) 1475 return err; 1476 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_playback_ops); 1477 pcm->private_data = chip; 1478 strcpy(pcm->name, chip->card->shortname); 1479 chip->pcms[1] = pcm; 1480 /* set up playback */ 1481 init_viadev(chip, chip->playback_devno, 0x30, 3, 0); 1482 1483 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1484 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) 1485 return err; 1486 1487 return 0; 1418 static int __devinit snd_via8233a_pcm_new(struct via82xx *chip) 1419 { 1420 struct snd_pcm *pcm; 1421 int err; 1422 1423 chip->multi_devno = 0; 1424 chip->playback_devno = 1; 1425 chip->capture_devno = 2; 1426 chip->num_devs = 3; 1427 chip->intr_mask = 0x03033000; /* FLAG|EOL for rec0, mc, sdx3 */ 1428 1429 /* PCM #0: multi-channel playback and capture */ 1430 err = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm); 1431 if (err < 0) 1432 return err; 1433 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_multi_ops); 1434 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops); 1435 pcm->private_data = chip; 1436 strcpy(pcm->name, chip->card->shortname); 1437 chip->pcms[0] = pcm; 1438 /* set up playback */ 1439 init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0); 1440 /* capture */ 1441 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1); 1442 1443 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1444 snd_dma_pci_data(chip->pci), 1445 64*1024, 128*1024)) < 0) 1446 return err; 1447 1448 /* SPDIF supported? */ 1449 if (! ac97_can_spdif(chip->ac97)) 1450 return 0; 1451 1452 /* PCM #1: DXS3 playback (for spdif) */ 1453 err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 0, &pcm); 1454 if (err < 0) 1455 return err; 1456 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_playback_ops); 1457 pcm->private_data = chip; 1458 strcpy(pcm->name, chip->card->shortname); 1459 chip->pcms[1] = pcm; 1460 /* set up playback */ 1461 init_viadev(chip, chip->playback_devno, 0x30, 3, 0); 1462 1463 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1464 snd_dma_pci_data(chip->pci), 1465 64*1024, 128*1024)) < 0) 1466 return err; 1467 1468 return 0; 1488 1469 } 1489 1470 … … 1491 1472 * create a pcm instance for via686a/b 1492 1473 */ 1493 static int __devinit snd_via686_pcm_new(via82xx_t *chip) 1494 { 1495 snd_pcm_t *pcm; 1496 int err; 1497 1498 chip->playback_devno = 0; 1499 chip->capture_devno = 1; 1500 chip->num_devs = 2; 1501 chip->intr_mask = 0x77; /* FLAG | EOL for PB, CP, FM */ 1502 1503 err = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm); 1504 if (err < 0) 1505 return err; 1506 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via686_playback_ops); 1507 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via686_capture_ops); 1508 pcm->private_data = chip; 1509 strcpy(pcm->name, chip->card->shortname); 1510 chip->pcms[0] = pcm; 1511 init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0, 0); 1512 init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 0, 1); 1513 1514 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1515 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) 1516 return err; 1517 1518 return 0; 1474 static int __devinit snd_via686_pcm_new(struct via82xx *chip) 1475 { 1476 struct snd_pcm *pcm; 1477 int err; 1478 1479 chip->playback_devno = 0; 1480 chip->capture_devno = 1; 1481 chip->num_devs = 2; 1482 chip->intr_mask = 0x77; /* FLAG | EOL for PB, CP, FM */ 1483 1484 err = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm); 1485 if (err < 0) 1486 return err; 1487 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via686_playback_ops); 1488 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via686_capture_ops); 1489 pcm->private_data = chip; 1490 strcpy(pcm->name, chip->card->shortname); 1491 chip->pcms[0] = pcm; 1492 init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0, 0); 1493 init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 0, 1); 1494 1495 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1496 snd_dma_pci_data(chip->pci), 1497 64*1024, 128*1024)) < 0) 1498 return err; 1499 1500 return 0; 1519 1501 } 1520 1502 … … 1524 1506 */ 1525 1507 1526 static int snd_via8233_capture_source_info(s nd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)1527 { 1528 /* formerly they were "Line" and "Mic", but it looks like that they 1529 * have nothing to do with the actual physical connections... 1530 */ 1531 static char *texts[2] = { 1532 "Input1", "Input2" 1533 }; 1534 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;1535 uinfo->count = 1;1536 uinfo->value.enumerated.items = 2;1537 if (uinfo->value.enumerated.item >= 2) 1538 uinfo->value.enumerated.item = 1; 1539 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);1540 return 0;1541 } 1542 1543 static int snd_via8233_capture_source_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 1544 { 1545 via82xx_t *chip = snd_kcontrol_chip(kcontrol); 1546 unsigned long port = chip->port + (kcontrol->id.index ? (VIA_REG_CAPTURE_CHANNEL + 0x10) : VIA_REG_CAPTURE_CHANNEL); 1547 ucontrol->value.enumerated.item[0] = inb(port) & VIA_REG_CAPTURE_CHANNEL_MIC ? 1 : 0;1548 return 0;1549 } 1550 1551 static int snd_via8233_capture_source_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 1552 { 1553 via82xx_t *chip = snd_kcontrol_chip(kcontrol); 1554 unsigned long port = chip->port + (kcontrol->id.index ? (VIA_REG_CAPTURE_CHANNEL + 0x10) : VIA_REG_CAPTURE_CHANNEL); 1555 u8 val, oval; 1556 1557 spin_lock_irq(&chip->reg_lock);1558 oval = inb(port);1559 val = oval & ~VIA_REG_CAPTURE_CHANNEL_MIC; 1560 if (ucontrol->value.enumerated.item[0]) 1561 val |= VIA_REG_CAPTURE_CHANNEL_MIC;1562 if (val != oval) 1563 outb(val, port); 1564 spin_unlock_irq(&chip->reg_lock);1565 return val != oval; 1566 } 1567 1568 static snd_kcontrol_new_t snd_via8233_capture_source __devinitdata = { 1569 /* .iface = */ SNDRV_CTL_ELEM_IFACE_MIXER, 1570 0,0, 1571 /* .name = */ "Input Source Select", 1572 0,0,0,1573 /* .info = */ snd_via8233_capture_source_info,1574 /* .get = */ snd_via8233_capture_source_get,1575 /* .put = */ snd_via8233_capture_source_put,1576 0 1508 static int snd_via8233_capture_source_info(struct snd_kcontrol *kcontrol, 1509 struct snd_ctl_elem_info *uinfo) 1510 { 1511 /* formerly they were "Line" and "Mic", but it looks like that they 1512 * have nothing to do with the actual physical connections... 1513 */ 1514 static char *texts[2] = { 1515 "Input1", "Input2" 1516 }; 1517 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1518 uinfo->count = 1; 1519 uinfo->value.enumerated.items = 2; 1520 if (uinfo->value.enumerated.item >= 2) 1521 uinfo->value.enumerated.item = 1; 1522 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1523 return 0; 1524 } 1525 1526 static int snd_via8233_capture_source_get(struct snd_kcontrol *kcontrol, 1527 struct snd_ctl_elem_value *ucontrol) 1528 { 1529 struct via82xx *chip = snd_kcontrol_chip(kcontrol); 1530 unsigned long port = chip->port + (kcontrol->id.index ? (VIA_REG_CAPTURE_CHANNEL + 0x10) : VIA_REG_CAPTURE_CHANNEL); 1531 ucontrol->value.enumerated.item[0] = inb(port) & VIA_REG_CAPTURE_CHANNEL_MIC ? 1 : 0; 1532 return 0; 1533 } 1534 1535 static int snd_via8233_capture_source_put(struct snd_kcontrol *kcontrol, 1536 struct snd_ctl_elem_value *ucontrol) 1537 { 1538 struct via82xx *chip = snd_kcontrol_chip(kcontrol); 1539 unsigned long port = chip->port + (kcontrol->id.index ? (VIA_REG_CAPTURE_CHANNEL + 0x10) : VIA_REG_CAPTURE_CHANNEL); 1540 u8 val, oval; 1541 1542 spin_lock_irq(&chip->reg_lock); 1543 oval = inb(port); 1544 val = oval & ~VIA_REG_CAPTURE_CHANNEL_MIC; 1545 if (ucontrol->value.enumerated.item[0]) 1546 val |= VIA_REG_CAPTURE_CHANNEL_MIC; 1547 if (val != oval) 1548 outb(val, port); 1549 spin_unlock_irq(&chip->reg_lock); 1550 return val != oval; 1551 } 1552 1553 static struct snd_kcontrol_new snd_via8233_capture_source __devinitdata = { 1554 .name = "Input Source Select", 1555 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1556 .info = snd_via8233_capture_source_info, 1557 .get = snd_via8233_capture_source_get, 1558 .put = snd_via8233_capture_source_put, 1577 1559 }; 1578 1560 1579 static int snd_via8233_dxs3_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) 1580 { 1581 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 1582 uinfo->count = 1; 1583 uinfo->value.integer.min = 0; 1584 uinfo->value.integer.max = 1; 1585 return 0; 1586 } 1587 1588 static int snd_via8233_dxs3_spdif_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 1589 { 1590 via82xx_t *chip = snd_kcontrol_chip(kcontrol); 1591 u8 val; 1592 1593 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val); 1594 ucontrol->value.integer.value[0] = (val & VIA8233_SPDIF_DX3) ? 1 : 0; 1595 return 0; 1596 } 1597 1598 static int snd_via8233_dxs3_spdif_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 1599 { 1600 via82xx_t *chip = snd_kcontrol_chip(kcontrol); 1601 u8 val, oval; 1602 1603 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &oval); 1604 val = oval & ~VIA8233_SPDIF_DX3; 1605 if (ucontrol->value.integer.value[0]) 1606 val |= VIA8233_SPDIF_DX3; 1607 if (val != oval) { 1608 pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, val); 1609 return 1; 1610 } 1611 return 0; 1612 } 1613 1614 static snd_kcontrol_new_t snd_via8233_dxs3_spdif_control __devinitdata = { 1615 /*.iface = */SNDRV_CTL_ELEM_IFACE_MIXER,0,0, 1616 SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH), 1617 0,0,0, 1618 /*.info = */snd_via8233_dxs3_spdif_info, 1619 /*.get = */snd_via8233_dxs3_spdif_get, 1620 /*.put = */snd_via8233_dxs3_spdif_put,0 1561 static int snd_via8233_dxs3_spdif_info(struct snd_kcontrol *kcontrol, 1562 struct snd_ctl_elem_info *uinfo) 1563 { 1564 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 1565 uinfo->count = 1; 1566 uinfo->value.integer.min = 0; 1567 uinfo->value.integer.max = 1; 1568 return 0; 1569 } 1570 1571 static int snd_via8233_dxs3_spdif_get(struct snd_kcontrol *kcontrol, 1572 struct snd_ctl_elem_value *ucontrol) 1573 { 1574 struct via82xx *chip = snd_kcontrol_chip(kcontrol); 1575 u8 val; 1576 1577 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val); 1578 ucontrol->value.integer.value[0] = (val & VIA8233_SPDIF_DX3) ? 1 : 0; 1579 return 0; 1580 } 1581 1582 static int snd_via8233_dxs3_spdif_put(struct snd_kcontrol *kcontrol, 1583 struct snd_ctl_elem_value *ucontrol) 1584 { 1585 struct via82xx *chip = snd_kcontrol_chip(kcontrol); 1586 u8 val, oval; 1587 1588 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &oval); 1589 val = oval & ~VIA8233_SPDIF_DX3; 1590 if (ucontrol->value.integer.value[0]) 1591 val |= VIA8233_SPDIF_DX3; 1592 /* save the spdif flag for rate filtering */ 1593 chip->spdif_on = ucontrol->value.integer.value[0] ? 1 : 0; 1594 if (val != oval) { 1595 pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, val); 1596 return 1; 1597 } 1598 return 0; 1599 } 1600 1601 static struct snd_kcontrol_new snd_via8233_dxs3_spdif_control __devinitdata = { 1602 .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH), 1603 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1604 .info = snd_via8233_dxs3_spdif_info, 1605 .get = snd_via8233_dxs3_spdif_get, 1606 .put = snd_via8233_dxs3_spdif_put, 1621 1607 }; 1622 1608 1623 static int snd_via8233_dxs_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) 1624 { 1625 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1626 uinfo->count = 2; 1627 uinfo->value.integer.min = 0; 1628 uinfo->value.integer.max = VIA_DXS_MAX_VOLUME; 1629 return 0; 1630 } 1631 1632 static int snd_via8233_dxs_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 1633 { 1634 via82xx_t *chip = snd_kcontrol_chip(kcontrol); 1635 unsigned int idx = snd_ctl_get_ioff(kcontrol, &ucontrol->id); 1636 ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume[0]; 1637 ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume[1]; 1638 return 0; 1639 } 1640 1641 static int snd_via8233_dxs_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 1642 { 1643 via82xx_t *chip = snd_kcontrol_chip(kcontrol); 1644 unsigned int idx; 1645 unsigned char val; 1646 int i, change = 0; 1647 1648 for (i = 0; i < 2; i++) { 1649 val = ucontrol->value.integer.value[i]; 1650 if (val > VIA_DXS_MAX_VOLUME) 1651 val = VIA_DXS_MAX_VOLUME; 1652 val = VIA_DXS_MAX_VOLUME - val; 1653 if (val != chip->playback_volume[i]) { 1654 change = 1; 1655 chip->playback_volume[i] = val; 1656 for (idx = 0; idx < 4; idx++) { 1657 unsigned long port = chip->port + 0x10 * idx; 1658 outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i); 1659 } 1660 } 1661 } 1662 return change; 1663 } 1664 1665 static snd_kcontrol_new_t snd_via8233_dxs_volume_control __devinitdata = { 1666 /*.iface = */SNDRV_CTL_ELEM_IFACE_MIXER,0,0, 1667 /*.name = */"PCM Playback Volume",0,0, 1668 /*.count = */0, 1669 /*.info = */snd_via8233_dxs_volume_info, 1670 /*.get = */snd_via8233_dxs_volume_get, 1671 /*.put = */snd_via8233_dxs_volume_put,0 1609 static int snd_via8233_dxs_volume_info(struct snd_kcontrol *kcontrol, 1610 struct snd_ctl_elem_info *uinfo) 1611 { 1612 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1613 uinfo->count = 2; 1614 uinfo->value.integer.min = 0; 1615 uinfo->value.integer.max = VIA_DXS_MAX_VOLUME; 1616 return 0; 1617 } 1618 1619 static int snd_via8233_dxs_volume_get(struct snd_kcontrol *kcontrol, 1620 struct snd_ctl_elem_value *ucontrol) 1621 { 1622 struct via82xx *chip = snd_kcontrol_chip(kcontrol); 1623 unsigned int idx = snd_ctl_get_ioff(kcontrol, &ucontrol->id); 1624 1625 ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][0]; 1626 ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][1]; 1627 return 0; 1628 } 1629 1630 static int snd_via8233_pcmdxs_volume_get(struct snd_kcontrol *kcontrol, 1631 struct snd_ctl_elem_value *ucontrol) 1632 { 1633 struct via82xx *chip = snd_kcontrol_chip(kcontrol); 1634 ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[0]; 1635 ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[1]; 1636 return 0; 1637 } 1638 1639 static int snd_via8233_dxs_volume_put(struct snd_kcontrol *kcontrol, 1640 struct snd_ctl_elem_value *ucontrol) 1641 { 1642 struct via82xx *chip = snd_kcontrol_chip(kcontrol); 1643 unsigned int idx = snd_ctl_get_ioff(kcontrol, &ucontrol->id); 1644 unsigned long port = chip->port + 0x10 * idx; 1645 unsigned char val; 1646 int i, change = 0; 1647 1648 for (i = 0; i < 2; i++) { 1649 val = ucontrol->value.integer.value[i]; 1650 if (val > VIA_DXS_MAX_VOLUME) 1651 val = VIA_DXS_MAX_VOLUME; 1652 val = VIA_DXS_MAX_VOLUME - val; 1653 change |= val != chip->playback_volume[idx][i]; 1654 if (change) { 1655 chip->playback_volume[idx][i] = val; 1656 outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i); 1657 } 1658 } 1659 return change; 1660 } 1661 1662 static int snd_via8233_pcmdxs_volume_put(struct snd_kcontrol *kcontrol, 1663 struct snd_ctl_elem_value *ucontrol) 1664 { 1665 struct via82xx *chip = snd_kcontrol_chip(kcontrol); 1666 unsigned int idx; 1667 unsigned char val; 1668 int i, change = 0; 1669 1670 for (i = 0; i < 2; i++) { 1671 val = ucontrol->value.integer.value[i]; 1672 if (val > VIA_DXS_MAX_VOLUME) 1673 val = VIA_DXS_MAX_VOLUME; 1674 val = VIA_DXS_MAX_VOLUME - val; 1675 if (val != chip->playback_volume_c[i]) { 1676 change = 1; 1677 chip->playback_volume_c[i] = val; 1678 for (idx = 0; idx < 4; idx++) { 1679 unsigned long port = chip->port + 0x10 * idx; 1680 chip->playback_volume[idx][i] = val; 1681 outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i); 1682 } 1683 } 1684 } 1685 return change; 1686 } 1687 1688 static struct snd_kcontrol_new snd_via8233_pcmdxs_volume_control __devinitdata = { 1689 .name = "PCM Playback Volume", 1690 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1691 .info = snd_via8233_dxs_volume_info, 1692 .get = snd_via8233_pcmdxs_volume_get, 1693 .put = snd_via8233_pcmdxs_volume_put, 1672 1694 }; 1673 1695 1674 /* 1675 */ 1676 1677 static void snd_via82xx_mixer_free_ac97_bus(ac97_bus_t *bus) 1678 { 1679 via82xx_t *chip = bus->private_data; 1680 chip->ac97_bus = NULL; 1681 } 1682 1683 static void snd_via82xx_mixer_free_ac97(ac97_t *ac97) 1684 { 1685 via82xx_t *chip = ac97->private_data; 1686 chip->ac97 = NULL; 1696 static struct snd_kcontrol_new snd_via8233_dxs_volume_control __devinitdata = { 1697 .name = "VIA DXS Playback Volume", 1698 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1699 .count = 4, 1700 .info = snd_via8233_dxs_volume_info, 1701 .get = snd_via8233_dxs_volume_get, 1702 .put = snd_via8233_dxs_volume_put, 1703 }; 1704 1705 /* 1706 */ 1707 1708 static void snd_via82xx_mixer_free_ac97_bus(struct snd_ac97_bus *bus) 1709 { 1710 struct via82xx *chip = bus->private_data; 1711 chip->ac97_bus = NULL; 1712 } 1713 1714 static void snd_via82xx_mixer_free_ac97(struct snd_ac97 *ac97) 1715 { 1716 struct via82xx *chip = ac97->private_data; 1717 chip->ac97 = NULL; 1687 1718 } 1688 1719 1689 1720 static struct ac97_quirk ac97_quirks[] = { 1690 { 1691 0x1106, 1692 0x4161, 1693 0, 0x56494161, /* VT1612A */ 1694 "Soltek SL-75DRV5", 1695 AC97_TUNE_NONE 1696 }, 1697 { 1698 /*.vendor = */0x1106, 1699 /*.device = */0x4161, 0, 0, 1700 /*.name = */"ASRock K7VT2", 1701 /*.type = */AC97_TUNE_HP_ONLY 1702 }, 1703 { 1704 0x1019, 1705 0x0a81, 0, 0, 1706 "ECS K7VTA3", 1707 AC97_TUNE_HP_ONLY 1708 }, 1709 { 1710 /*.vendor =*/ 0x1019, 1711 /*.device =*/0x0a85,0,0, 1712 /*.name = */"ECS L7VMM2", 1713 /*.type = */AC97_TUNE_HP_ONLY 1714 }, 1715 { /*.vendor = */0x1849, 1716 /*.device = */0x3059, 0, 0, 1717 /*.name = */"ASRock K7VM2", 1718 /*.type = */AC97_TUNE_HP_ONLY /* VT1616 */ 1719 }, 1720 { 1721 0x14cd, 1722 0x7002, 0, 0, 1723 "Unknown", 1724 AC97_TUNE_ALC_JACK 1725 }, 1726 { 1727 0x1071, 1728 0x8590, 0, 0, 1729 "Mitac Mobo", 1730 AC97_TUNE_ALC_JACK 1731 }, 1732 { 1733 0x161f, 1734 0x202b, 0, 0, 1735 "Arima Notebook", 1736 AC97_TUNE_HP_ONLY, 1737 }, 1738 { 0 } /* terminator */ 1721 { 1722 .subvendor = 0x1106, 1723 .subdevice = 0x4161, 1724 .codec_id = 0x56494161, /* VT1612A */ 1725 .name = "Soltek SL-75DRV5", 1726 .type = AC97_TUNE_NONE 1727 }, 1728 { /* FIXME: which codec? */ 1729 .subvendor = 0x1106, 1730 .subdevice = 0x4161, 1731 .name = "ASRock K7VT2", 1732 .type = AC97_TUNE_HP_ONLY 1733 }, 1734 { 1735 .subvendor = 0x1019, 1736 .subdevice = 0x0a81, 1737 .name = "ECS K7VTA3", 1738 .type = AC97_TUNE_HP_ONLY 1739 }, 1740 { 1741 .subvendor = 0x1019, 1742 .subdevice = 0x0a85, 1743 .name = "ECS L7VMM2", 1744 .type = AC97_TUNE_HP_ONLY 1745 }, 1746 { 1747 .subvendor = 0x1849, 1748 .subdevice = 0x3059, 1749 .name = "ASRock K7VM2", 1750 .type = AC97_TUNE_HP_ONLY /* VT1616 */ 1751 }, 1752 { 1753 .subvendor = 0x14cd, 1754 .subdevice = 0x7002, 1755 .name = "Unknown", 1756 .type = AC97_TUNE_ALC_JACK 1757 }, 1758 { 1759 .subvendor = 0x1071, 1760 .subdevice = 0x8590, 1761 .name = "Mitac Mobo", 1762 .type = AC97_TUNE_ALC_JACK 1763 }, 1764 { 1765 .subvendor = 0x161f, 1766 .subdevice = 0x202b, 1767 .name = "Arima Notebook", 1768 .type = AC97_TUNE_HP_ONLY, 1769 }, 1770 { 1771 .subvendor = 0x161f, 1772 .subdevice = 0x2032, 1773 .name = "Targa Traveller 811", 1774 .type = AC97_TUNE_HP_ONLY, 1775 }, 1776 {0} /* terminator */ 1739 1777 }; 1740 1778 1741 static int __devinit snd_via82xx_mixer_new(via82xx_t *chip, const char* ac97_quirk) 1742 { 1743 ac97_template_t ac97; 1744 int err; 1745 static ac97_bus_ops_t ops = { 1746 0,snd_via82xx_codec_write, 1747 snd_via82xx_codec_read, 1748 snd_via82xx_codec_wait,0 1749 }; 1750 1751 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus)) < 0) 1752 return err; 1753 1754 chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus; 1755 chip->ac97_bus->clock = chip->ac97_clock; 1756 chip->ac97_bus->shared_type = AC97_SHARED_TYPE_VIA; 1757 1758 memset(&ac97, 0, sizeof(ac97)); 1759 ac97.private_data = chip; 1760 ac97.private_free = snd_via82xx_mixer_free_ac97; 1761 ac97.pci = chip->pci; 1762 if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0) 1763 return err; 1764 1765 snd_ac97_tune_hardware(chip->ac97, ac97_quirks, ac97_quirk); 1766 1767 if (chip->chip_type != TYPE_VIA686) { 1768 /* use slot 10/11 */ 1769 snd_ac97_update_bits(chip->ac97, AC97_EXTENDED_STATUS, 0x03 << 4, 0x03 << 4); 1770 } 1771 1772 return 0; 1773 } 1774 1775 /* 1776 * 1777 */ 1778 1779 static int snd_via8233_init_misc(via82xx_t *chip, int dev) 1780 { 1781 int i, err, caps; 1782 unsigned char val; 1783 1784 caps = chip->chip_type == TYPE_VIA8233A ? 1 : 2; 1785 for (i = 0; i < caps; i++) { 1786 snd_via8233_capture_source.index = i; 1787 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_capture_source, chip)); 1788 if (err < 0) 1789 return err; 1790 } 1791 if (ac97_can_spdif(chip->ac97)) { 1792 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs3_spdif_control, chip)); 1793 if (err < 0) 1794 return err; 1795 } 1796 if (chip->chip_type != TYPE_VIA8233A) { 1797 /* when no h/w PCM volume control is found, use DXS volume control 1798 * as the PCM vol control 1799 */ 1800 snd_ctl_elem_id_t sid; 1801 memset(&sid, 0, sizeof(sid)); 1802 strcpy(sid.name, "PCM Playback Volume"); 1803 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 1804 if (! snd_ctl_find_id(chip->card, &sid)) { 1805 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs_volume_control, chip)); 1806 if (err < 0) 1807 return err; 1808 } 1809 } 1810 1811 /* select spdif data slot 10/11 */ 1812 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val); 1813 val = (val & ~VIA8233_SPDIF_SLOT_MASK) | VIA8233_SPDIF_SLOT_1011; 1814 val &= ~VIA8233_SPDIF_DX3; /* SPDIF off as default */ 1815 pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, val); 1816 1817 return 0; 1818 } 1819 1820 static int snd_via686_init_misc(via82xx_t *chip, int dev) 1821 { 1822 unsigned char legacy, legacy_cfg; 1823 int rev_h = 0; 1824 1825 legacy = chip->old_legacy; 1826 legacy_cfg = chip->old_legacy_cfg; 1827 legacy |= VIA_FUNC_MIDI_IRQMASK; /* FIXME: correct? (disable MIDI) */ 1828 legacy &= ~VIA_FUNC_ENABLE_GAME; /* disable joystick */ 1829 if (chip->revision >= VIA_REV_686_H) { 1830 rev_h = 1; 1831 if (mpu_port[dev] >= 0x200) { /* force MIDI */ 1832 mpu_port[dev] &= 0xfffc; 1833 pci_write_config_dword(chip->pci, 0x18, mpu_port[dev] | 0x01); 1834 #ifdef CONFIG_PM 1835 chip->mpu_port_saved = mpu_port[dev]; 1836 #endif 1837 } else { 1838 mpu_port[dev] = pci_resource_start(chip->pci, 2); 1839 } 1840 } else { 1841 switch (mpu_port[dev]) { /* force MIDI */ 1842 case 0x300: 1843 case 0x310: 1844 case 0x320: 1845 case 0x330: 1846 legacy_cfg &= ~(3 << 2); 1847 legacy_cfg |= (mpu_port[dev] & 0x0030) >> 2; 1848 break; 1849 default: /* no, use BIOS settings */ 1850 if (legacy & VIA_FUNC_ENABLE_MIDI) 1851 mpu_port[dev] = 0x300 + ((legacy_cfg & 0x000c) << 2); 1852 break; 1853 } 1854 } 1855 if (mpu_port[dev] >= 0x200 && 1856 (chip->mpu_res = request_region(mpu_port[dev], 2, "VIA82xx MPU401")) != NULL) { 1857 if (rev_h) 1858 legacy |= VIA_FUNC_MIDI_PNP; /* enable PCI I/O 2 */ 1859 legacy |= VIA_FUNC_ENABLE_MIDI; 1860 } else { 1861 if (rev_h) 1862 legacy &= ~VIA_FUNC_MIDI_PNP; /* disable PCI I/O 2 */ 1863 legacy &= ~VIA_FUNC_ENABLE_MIDI; 1864 mpu_port[dev] = 0; 1865 } 1866 1779 static int __devinit snd_via82xx_mixer_new(struct via82xx *chip, const char *quirk_override) 1780 { 1781 struct snd_ac97_template ac97; 1782 int err; 1783 static struct snd_ac97_bus_ops ops = { 1784 .write = snd_via82xx_codec_write, 1785 .read = snd_via82xx_codec_read, 1786 .wait = snd_via82xx_codec_wait, 1787 }; 1788 1789 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus)) < 0) 1790 return err; 1791 chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus; 1792 chip->ac97_bus->clock = chip->ac97_clock; 1793 1794 memset(&ac97, 0, sizeof(ac97)); 1795 ac97.private_data = chip; 1796 ac97.private_free = snd_via82xx_mixer_free_ac97; 1797 ac97.pci = chip->pci; 1798 ac97.scaps = AC97_SCAP_SKIP_MODEM; 1799 if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0) 1800 return err; 1801 1802 snd_ac97_tune_hardware(chip->ac97, ac97_quirks, quirk_override); 1803 1804 if (chip->chip_type != TYPE_VIA686) { 1805 /* use slot 10/11 */ 1806 snd_ac97_update_bits(chip->ac97, AC97_EXTENDED_STATUS, 0x03 << 4, 0x03 << 4); 1807 } 1808 1809 return 0; 1810 } 1867 1811 1868 1812 #ifdef SUPPORT_JOYSTICK 1869 1813 #define JOYSTICK_ADDR 0x200 1870 if (joystick[dev] && 1871 (chip->res_joystick = request_region(JOYSTICK_ADDR, 8, "VIA686 gameport")) != NULL) { 1872 legacy |= VIA_FUNC_ENABLE_GAME; 1873 chip->gameport.io = JOYSTICK_ADDR; 1874 } 1814 static int __devinit snd_via686_create_gameport(struct via82xx *chip, unsigned char *legacy) 1815 { 1816 struct gameport *gp; 1817 struct resource *r; 1818 1819 if (!joystick) 1820 return -ENODEV; 1821 1822 r = request_region(JOYSTICK_ADDR, 8, "VIA686 gameport"); 1823 if (!r) { 1824 printk(KERN_WARNING "via82xx: cannot reserve joystick port 0x%#x\n", 1825 JOYSTICK_ADDR); 1826 return -EBUSY; 1827 } 1828 1829 chip->gameport = gp = gameport_allocate_port(); 1830 if (!gp) { 1831 printk(KERN_ERR "via82xx: cannot allocate memory for gameport\n"); 1832 release_and_free_resource(r); 1833 return -ENOMEM; 1834 } 1835 1836 gameport_set_name(gp, "VIA686 Gameport"); 1837 gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci)); 1838 gameport_set_dev_parent(gp, &chip->pci->dev); 1839 gp->io = JOYSTICK_ADDR; 1840 gameport_set_port_data(gp, r); 1841 1842 /* Enable legacy joystick port */ 1843 *legacy |= VIA_FUNC_ENABLE_GAME; 1844 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, *legacy); 1845 1846 gameport_register_port(chip->gameport); 1847 1848 return 0; 1849 } 1850 1851 static void snd_via686_free_gameport(struct via82xx *chip) 1852 { 1853 if (chip->gameport) { 1854 struct resource *r = gameport_get_port_data(chip->gameport); 1855 1856 gameport_unregister_port(chip->gameport); 1857 chip->gameport = NULL; 1858 release_and_free_resource(r); 1859 } 1860 } 1861 #else 1862 static inline int snd_via686_create_gameport(struct via82xx *chip, unsigned char *legacy) 1863 { 1864 return -ENOSYS; 1865 } 1866 static inline void snd_via686_free_gameport(struct via82xx *chip) { } 1875 1867 #endif 1876 legacy |= VIA_FUNC_ENABLE_GAME; // by vladest 1877 1878 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy); 1879 pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg); 1880 #if 1 // disabled by vladest due trap in mpu uart 1881 if (chip->mpu_res) { 1882 if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A, 1883 mpu_port[dev], 1, 1884 chip->irq, 0, &chip->rmidi) < 0) { 1885 printk(KERN_WARNING "unable to initialize MPU-401 at 0x%lx, skipping\n", mpu_port[dev]); 1886 legacy &= ~VIA_FUNC_ENABLE_MIDI; 1887 } else { 1888 legacy &= ~VIA_FUNC_MIDI_IRQMASK; /* enable MIDI interrupt */ 1889 } 1890 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy); 1891 } 1868 1869 1870 /* 1871 * 1872 */ 1873 1874 static int __devinit snd_via8233_init_misc(struct via82xx *chip) 1875 { 1876 int i, err, caps; 1877 unsigned char val; 1878 1879 caps = chip->chip_type == TYPE_VIA8233A ? 1 : 2; 1880 for (i = 0; i < caps; i++) { 1881 snd_via8233_capture_source.index = i; 1882 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_capture_source, chip)); 1883 if (err < 0) 1884 return err; 1885 } 1886 if (ac97_can_spdif(chip->ac97)) { 1887 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs3_spdif_control, chip)); 1888 if (err < 0) 1889 return err; 1890 } 1891 if (chip->chip_type != TYPE_VIA8233A) { 1892 /* when no h/w PCM volume control is found, use DXS volume control 1893 * as the PCM vol control 1894 */ 1895 struct snd_ctl_elem_id sid; 1896 memset(&sid, 0, sizeof(sid)); 1897 strcpy(sid.name, "PCM Playback Volume"); 1898 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 1899 if (! snd_ctl_find_id(chip->card, &sid)) { 1900 snd_printd(KERN_INFO "Using DXS as PCM Playback\n"); 1901 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_pcmdxs_volume_control, chip)); 1902 if (err < 0) 1903 return err; 1904 } 1905 else /* Using DXS when PCM emulation is enabled is really weird */ 1906 { 1907 /* Standalone DXS controls */ 1908 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs_volume_control, chip)); 1909 if (err < 0) 1910 return err; 1911 } 1912 } 1913 /* select spdif data slot 10/11 */ 1914 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val); 1915 val = (val & ~VIA8233_SPDIF_SLOT_MASK) | VIA8233_SPDIF_SLOT_1011; 1916 val &= ~VIA8233_SPDIF_DX3; /* SPDIF off as default */ 1917 pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, val); 1918 1919 return 0; 1920 } 1921 1922 static int __devinit snd_via686_init_misc(struct via82xx *chip) 1923 { 1924 unsigned char legacy, legacy_cfg; 1925 int rev_h = 0; 1926 1927 legacy = chip->old_legacy; 1928 legacy_cfg = chip->old_legacy_cfg; 1929 legacy |= VIA_FUNC_MIDI_IRQMASK; /* FIXME: correct? (disable MIDI) */ 1930 legacy &= ~VIA_FUNC_ENABLE_GAME; /* disable joystick */ 1931 if (chip->revision >= VIA_REV_686_H) { 1932 rev_h = 1; 1933 if (mpu_port >= 0x200) { /* force MIDI */ 1934 mpu_port &= 0xfffc; 1935 pci_write_config_dword(chip->pci, 0x18, mpu_port | 0x01); 1936 #ifdef CONFIG_PM 1937 chip->mpu_port_saved = mpu_port; 1892 1938 #endif 1893 #ifdef SUPPORT_JOYSTICK 1894 if (chip->res_joystick) 1895 gameport_register_port(&chip->gameport); 1939 } else { 1940 mpu_port = pci_resource_start(chip->pci, 2); 1941 } 1942 } else { 1943 switch (mpu_port) { /* force MIDI */ 1944 case 0x300: 1945 case 0x310: 1946 case 0x320: 1947 case 0x330: 1948 legacy_cfg &= ~(3 << 2); 1949 legacy_cfg |= (mpu_port & 0x0030) >> 2; 1950 break; 1951 default: /* no, use BIOS settings */ 1952 if (legacy & VIA_FUNC_ENABLE_MIDI) 1953 mpu_port = 0x300 + ((legacy_cfg & 0x000c) << 2); 1954 break; 1955 } 1956 } 1957 if (mpu_port >= 0x200 && 1958 (chip->mpu_res = request_region(mpu_port, 2, "VIA82xx MPU401")) 1959 != NULL) { 1960 if (rev_h) 1961 legacy |= VIA_FUNC_MIDI_PNP; /* enable PCI I/O 2 */ 1962 legacy |= VIA_FUNC_ENABLE_MIDI; 1963 } else { 1964 if (rev_h) 1965 legacy &= ~VIA_FUNC_MIDI_PNP; /* disable PCI I/O 2 */ 1966 legacy &= ~VIA_FUNC_ENABLE_MIDI; 1967 mpu_port = 0; 1968 } 1969 1970 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy); 1971 pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg); 1972 if (chip->mpu_res) { 1973 if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A, 1974 mpu_port, 1, 1975 chip->irq, 0, &chip->rmidi) < 0) { 1976 printk(KERN_WARNING "unable to initialize MPU-401" 1977 " at 0x%lx, skipping\n", mpu_port); 1978 legacy &= ~VIA_FUNC_ENABLE_MIDI; 1979 } else { 1980 legacy &= ~VIA_FUNC_MIDI_IRQMASK; /* enable MIDI interrupt */ 1981 } 1982 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy); 1983 } 1984 1985 snd_via686_create_gameport(chip, &legacy); 1986 1987 #ifdef CONFIG_PM 1988 chip->legacy_saved = legacy; 1989 chip->legacy_cfg_saved = legacy_cfg; 1896 1990 #endif 1897 1991 1992 return 0; 1993 } 1994 1995 1996 /* 1997 * proc interface 1998 */ 1999 static void snd_via82xx_proc_read(struct snd_info_entry *entry, 2000 struct snd_info_buffer *buffer) 2001 { 2002 struct via82xx *chip = entry->private_data; 2003 int i; 2004 2005 snd_iprintf(buffer, "%s\n\n", chip->card->longname); 2006 for (i = 0; i < 0xa0; i += 4) { 2007 snd_iprintf(buffer, "%02x: %08x\n", i, inl(chip->port + i)); 2008 } 2009 } 2010 2011 static void __devinit snd_via82xx_proc_init(struct via82xx *chip) 2012 { 2013 struct snd_info_entry *entry; 2014 2015 if (! snd_card_proc_new(chip->card, "via82xx", &entry)) 2016 snd_info_set_text_ops(entry, chip, 1024, snd_via82xx_proc_read); 2017 } 2018 2019 /* 2020 * 2021 */ 2022 2023 static int snd_via82xx_chip_init(struct via82xx *chip) 2024 { 2025 unsigned int val; 2026 unsigned long end_time; 2027 unsigned char pval; 2028 2029 #if 0 /* broken on K7M? */ 2030 if (chip->chip_type == TYPE_VIA686) 2031 /* disable all legacy ports */ 2032 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, 0); 2033 #endif 2034 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval); 2035 if (! (pval & VIA_ACLINK_C00_READY)) { /* codec not ready? */ 2036 /* deassert ACLink reset, force SYNC */ 2037 pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, 2038 VIA_ACLINK_CTRL_ENABLE | 2039 VIA_ACLINK_CTRL_RESET | 2040 VIA_ACLINK_CTRL_SYNC); 2041 udelay(100); 2042 #if 1 /* FIXME: should we do full reset here for all chip models? */ 2043 pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, 0x00); 2044 udelay(100); 2045 #else 2046 /* deassert ACLink reset, force SYNC (warm AC'97 reset) */ 2047 pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, 2048 VIA_ACLINK_CTRL_RESET|VIA_ACLINK_CTRL_SYNC); 2049 udelay(2); 2050 #endif 2051 /* ACLink on, deassert ACLink reset, VSR, SGD data out */ 2052 /* note - FM data out has trouble with non VRA codecs !! */ 2053 pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, VIA_ACLINK_CTRL_INIT); 2054 udelay(100); 2055 } 2056 2057 /* Make sure VRA is enabled, in case we didn't do a 2058 * complete codec reset, above */ 2059 pci_read_config_byte(chip->pci, VIA_ACLINK_CTRL, &pval); 2060 if ((pval & VIA_ACLINK_CTRL_INIT) != VIA_ACLINK_CTRL_INIT) { 2061 /* ACLink on, deassert ACLink reset, VSR, SGD data out */ 2062 /* note - FM data out has trouble with non VRA codecs !! */ 2063 pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, VIA_ACLINK_CTRL_INIT); 2064 udelay(100); 2065 } 2066 2067 /* wait until codec ready */ 2068 end_time = jiffies + msecs_to_jiffies(750); 2069 do { 2070 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval); 2071 if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */ 2072 break; 2073 schedule_timeout_uninterruptible(1); 2074 } while (time_before(jiffies, end_time)); 2075 2076 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY) 2077 snd_printk(KERN_ERR "AC'97 codec is not ready [0x%x]\n", val); 2078 2079 #if 0 /* FIXME: we don't support the second codec yet so skip the detection now.. */ 2080 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 2081 VIA_REG_AC97_SECONDARY_VALID | 2082 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); 2083 end_time = jiffies + msecs_to_jiffies(750); 2084 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 2085 VIA_REG_AC97_SECONDARY_VALID | 2086 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); 2087 do { 2088 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_SECONDARY_VALID) { 2089 chip->ac97_secondary = 1; 2090 goto __ac97_ok2; 2091 } 2092 schedule_timeout_interruptible(1); 2093 } while (time_before(jiffies, end_time)); 2094 /* This is ok, the most of motherboards have only one codec */ 2095 2096 __ac97_ok2: 2097 #endif 2098 2099 if (chip->chip_type == TYPE_VIA686) { 2100 /* route FM trap to IRQ, disable FM trap */ 2101 pci_write_config_byte(chip->pci, VIA_FM_NMI_CTRL, 0); 2102 /* disable all GPI interrupts */ 2103 outl(0, VIAREG(chip, GPI_INTR)); 2104 } 2105 2106 if (chip->chip_type != TYPE_VIA686) { 2107 /* Workaround for Award BIOS bug: 2108 * DXS channels don't work properly with VRA if MC97 is disabled. 2109 */ 2110 struct pci_dev *pci; 2111 pci = pci_get_device(0x1106, 0x3068, NULL); /* MC97 */ 2112 if (pci) { 2113 unsigned char data; 2114 pci_read_config_byte(pci, 0x44, &data); 2115 pci_write_config_byte(pci, 0x44, data | 0x40); 2116 pci_dev_put(pci); 2117 } 2118 } 2119 2120 if (chip->chip_type != TYPE_VIA8233A) { 2121 int i, idx; 2122 for (idx = 0; idx < 4; idx++) { 2123 unsigned long port = chip->port + 0x10 * idx; 2124 for (i = 0; i < 2; i++) { 2125 chip->playback_volume[idx][i]=chip->playback_volume_c[i]; 2126 outb(chip->playback_volume_c[i], 2127 port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i); 2128 } 2129 } 2130 } 2131 2132 return 0; 2133 } 2134 1898 2135 #ifdef CONFIG_PM 1899 chip->legacy_saved = legacy; 1900 chip->legacy_cfg_saved = legacy_cfg; 2136 /* 2137 * power management 2138 */ 2139 static int snd_via82xx_suspend(struct pci_dev *pci, pm_message_t state) 2140 { 2141 struct snd_card *card = pci_get_drvdata(pci); 2142 struct via82xx *chip = card->private_data; 2143 int i; 2144 2145 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 2146 for (i = 0; i < 2; i++) 2147 snd_pcm_suspend_all(chip->pcms[i]); 2148 for (i = 0; i < chip->num_devs; i++) 2149 snd_via82xx_channel_reset(chip, &chip->devs[i]); 2150 synchronize_irq(chip->irq); 2151 snd_ac97_suspend(chip->ac97); 2152 2153 /* save misc values */ 2154 if (chip->chip_type != TYPE_VIA686) { 2155 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &chip->spdif_ctrl_saved); 2156 chip->capture_src_saved[0] = inb(chip->port + VIA_REG_CAPTURE_CHANNEL); 2157 chip->capture_src_saved[1] = inb(chip->port + VIA_REG_CAPTURE_CHANNEL + 0x10); 2158 } 2159 2160 pci_set_power_state(pci, PCI_D3hot); 2161 pci_disable_device(pci); 2162 pci_save_state(pci); 2163 return 0; 2164 } 2165 2166 static int snd_via82xx_resume(struct pci_dev *pci) 2167 { 2168 struct snd_card *card = pci_get_drvdata(pci); 2169 struct via82xx *chip = card->private_data; 2170 int i; 2171 2172 pci_restore_state(pci); 2173 pci_enable_device(pci); 2174 pci_set_power_state(pci, PCI_D0); 2175 2176 snd_via82xx_chip_init(chip); 2177 2178 if (chip->chip_type == TYPE_VIA686) { 2179 if (chip->mpu_port_saved) 2180 pci_write_config_dword(chip->pci, 0x18, chip->mpu_port_saved | 0x01); 2181 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, chip->legacy_saved); 2182 pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, chip->legacy_cfg_saved); 2183 } else { 2184 pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, chip->spdif_ctrl_saved); 2185 outb(chip->capture_src_saved[0], chip->port + VIA_REG_CAPTURE_CHANNEL); 2186 outb(chip->capture_src_saved[1], chip->port + VIA_REG_CAPTURE_CHANNEL + 0x10); 2187 } 2188 2189 snd_ac97_resume(chip->ac97); 2190 2191 for (i = 0; i < chip->num_devs; i++) 2192 snd_via82xx_channel_reset(chip, &chip->devs[i]); 2193 2194 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 2195 return 0; 2196 } 2197 #endif /* CONFIG_PM */ 2198 2199 static int snd_via82xx_free(struct via82xx *chip) 2200 { 2201 unsigned int i; 2202 2203 if (chip->irq < 0) 2204 goto __end_hw; 2205 /* disable interrupts */ 2206 for (i = 0; i < chip->num_devs; i++) 2207 snd_via82xx_channel_reset(chip, &chip->devs[i]); 2208 synchronize_irq(chip->irq); 2209 __end_hw: 2210 if (chip->irq >= 0) 2211 free_irq(chip->irq, chip); 2212 release_and_free_resource(chip->mpu_res); 2213 pci_release_regions(chip->pci); 2214 2215 if (chip->chip_type == TYPE_VIA686) { 2216 snd_via686_free_gameport(chip); 2217 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, chip->old_legacy); 2218 pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, chip->old_legacy_cfg); 2219 } 2220 pci_disable_device(chip->pci); 2221 kfree(chip); 2222 return 0; 2223 } 2224 2225 static int snd_via82xx_dev_free(struct snd_device *device) 2226 { 2227 struct via82xx *chip = device->device_data; 2228 return snd_via82xx_free(chip); 2229 } 2230 2231 static int __devinit snd_via82xx_create(struct snd_card *card, 2232 struct pci_dev *pci, 2233 int chip_type, 2234 int revision, 2235 unsigned int ac97_clock, 2236 struct via82xx ** r_via) 2237 { 2238 struct via82xx *chip; 2239 int err; 2240 static struct snd_device_ops ops = { 2241 .dev_free = snd_via82xx_dev_free, 2242 }; 2243 2244 if ((err = pci_enable_device(pci)) < 0) 2245 return err; 2246 2247 if ((chip = kzalloc(sizeof(*chip), GFP_KERNEL)) == NULL) { 2248 pci_disable_device(pci); 2249 return -ENOMEM; 2250 } 2251 2252 chip->chip_type = chip_type; 2253 chip->revision = revision; 2254 2255 spin_lock_init(&chip->reg_lock); 2256 spin_lock_init(&chip->rates[0].lock); 2257 spin_lock_init(&chip->rates[1].lock); 2258 chip->card = card; 2259 chip->pci = pci; 2260 chip->irq = -1; 2261 2262 pci_read_config_byte(pci, VIA_FUNC_ENABLE, &chip->old_legacy); 2263 pci_read_config_byte(pci, VIA_PNP_CONTROL, &chip->old_legacy_cfg); 2264 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, 2265 chip->old_legacy & ~(VIA_FUNC_ENABLE_SB|VIA_FUNC_ENABLE_FM)); 2266 2267 if ((err = pci_request_regions(pci, card->driver)) < 0) { 2268 kfree(chip); 2269 pci_disable_device(pci); 2270 return err; 2271 } 2272 chip->port = pci_resource_start(pci, 0); 2273 if (request_irq(pci->irq, 2274 chip_type == TYPE_VIA8233 ? 2275 snd_via8233_interrupt : snd_via686_interrupt, 2276 SA_INTERRUPT|SA_SHIRQ, 2277 card->driver, chip)) { 2278 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 2279 snd_via82xx_free(chip); 2280 return -EBUSY; 2281 } 2282 chip->irq = pci->irq; 2283 if (ac97_clock >= 8000 && ac97_clock <= 48000) 2284 chip->ac97_clock = ac97_clock; 2285 synchronize_irq(chip->irq); 2286 2287 if ((err = snd_via82xx_chip_init(chip)) < 0) { 2288 snd_via82xx_free(chip); 2289 return err; 2290 } 2291 2292 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 2293 snd_via82xx_free(chip); 2294 return err; 2295 } 2296 2297 /* The 8233 ac97 controller does not implement the master bit 2298 * in the pci command register. IMHO this is a violation of the PCI spec. 2299 * We call pci_set_master here because it does not hurt. */ 2300 pci_set_master(pci); 2301 2302 snd_card_set_dev(card, &pci->dev); 2303 2304 *r_via = chip; 2305 return 0; 2306 } 2307 2308 struct via823x_info { 2309 int revision; 2310 char *name; 2311 int type; 2312 }; 2313 static struct via823x_info via823x_cards[] __devinitdata = { 2314 { VIA_REV_PRE_8233, "VIA 8233-Pre", TYPE_VIA8233 }, 2315 { VIA_REV_8233C, "VIA 8233C", TYPE_VIA8233 }, 2316 { VIA_REV_8233, "VIA 8233", TYPE_VIA8233 }, 2317 { VIA_REV_8233A, "VIA 8233A", TYPE_VIA8233A }, 2318 { VIA_REV_8235, "VIA 8235", TYPE_VIA8233 }, 2319 { VIA_REV_8237, "VIA 8237", TYPE_VIA8233 }, 2320 }; 2321 2322 /* 2323 * auto detection of DXS channel supports. 2324 */ 2325 struct dxs_whitelist { 2326 unsigned short subvendor; 2327 unsigned short subdevice; 2328 unsigned short mask; 2329 short action; /* new dxs_support value */ 2330 }; 2331 2332 static int __devinit check_dxs_list(struct pci_dev *pci) 2333 { 2334 static struct dxs_whitelist whitelist[] = { 2335 { .subvendor = 0x1005, .subdevice = 0x4710, .action = VIA_DXS_ENABLE }, /* Avance Logic Mobo */ 2336 { .subvendor = 0x1019, .subdevice = 0x0996, .action = VIA_DXS_48K }, 2337 { .subvendor = 0x1019, .subdevice = 0x0a81, .action = VIA_DXS_NO_VRA }, /* ECS K7VTA3 v8.0 */ 2338 { .subvendor = 0x1019, .subdevice = 0x0a85, .action = VIA_DXS_NO_VRA }, /* ECS L7VMM2 */ 2339 { .subvendor = 0x1019, .subdevice = 0xa101, .action = VIA_DXS_SRC }, 2340 { .subvendor = 0x1025, .subdevice = 0x0033, .action = VIA_DXS_NO_VRA }, /* Acer Inspire 1353LM */ 2341 { .subvendor = 0x1025, .subdevice = 0x0046, .action = VIA_DXS_SRC }, /* Acer Aspire 1524 WLMi */ 2342 { .subvendor = 0x1043, .subdevice = 0x8095, .action = VIA_DXS_NO_VRA }, /* ASUS A7V8X (FIXME: possibly VIA_DXS_ENABLE?)*/ 2343 { .subvendor = 0x1043, .subdevice = 0x80a1, .action = VIA_DXS_NO_VRA }, /* ASUS A7V8-X */ 2344 { .subvendor = 0x1043, .subdevice = 0x80b0, .action = VIA_DXS_NO_VRA }, /* ASUS A7V600 & K8V*/ 2345 { .subvendor = 0x1043, .subdevice = 0x810d, .action = VIA_DXS_SRC }, /* ASUS */ 2346 { .subvendor = 0x1043, .subdevice = 0x812a, .action = VIA_DXS_SRC }, /* ASUS A8V Deluxe */ 2347 { .subvendor = 0x1043, .subdevice = 0x8174, .action = VIA_DXS_SRC }, /* ASUS */ 2348 { .subvendor = 0x1071, .subdevice = 0x8375, .action = VIA_DXS_NO_VRA }, /* Vobis/Yakumo/Mitac notebook */ 2349 { .subvendor = 0x1071, .subdevice = 0x8399, .action = VIA_DXS_NO_VRA }, /* Umax AB 595T (VIA K8N800A - VT8237) */ 2350 { .subvendor = 0x10cf, .subdevice = 0x118e, .action = VIA_DXS_ENABLE }, /* FSC laptop */ 2351 { .subvendor = 0x1106, .subdevice = 0x4161, .action = VIA_DXS_NO_VRA }, /* ASRock K7VT2 */ 2352 { .subvendor = 0x1106, .subdevice = 0x4552, .action = VIA_DXS_NO_VRA }, /* QDI Kudoz 7X/600-6AL */ 2353 { .subvendor = 0x1106, .subdevice = 0xaa01, .action = VIA_DXS_NO_VRA }, /* EPIA MII */ 2354 { .subvendor = 0x1106, .subdevice = 0xc001, .action = VIA_DXS_SRC }, /* Insight P4-ITX */ 2355 { .subvendor = 0x1297, .subdevice = 0xa232, .action = VIA_DXS_ENABLE }, /* Shuttle ?? */ 2356 { .subvendor = 0x1297, .subdevice = 0xc160, .action = VIA_DXS_ENABLE }, /* Shuttle SK41G */ 2357 { .subvendor = 0x1458, .subdevice = 0xa002, .action = VIA_DXS_ENABLE }, /* Gigabyte GA-7VAXP */ 2358 { .subvendor = 0x1462, .subdevice = 0x0080, .action = VIA_DXS_SRC }, /* MSI K8T Neo-FIS2R */ 2359 { .subvendor = 0x1462, .subdevice = 0x0430, .action = VIA_DXS_SRC }, /* MSI 7142 (K8MM-V) */ 2360 { .subvendor = 0x1462, .subdevice = 0x0470, .action = VIA_DXS_SRC }, /* MSI KT880 Delta-FSR */ 2361 { .subvendor = 0x1462, .subdevice = 0x3800, .action = VIA_DXS_ENABLE }, /* MSI KT266 */ 2362 { .subvendor = 0x1462, .subdevice = 0x5901, .action = VIA_DXS_NO_VRA }, /* MSI KT6 Delta-SR */ 2363 { .subvendor = 0x1462, .subdevice = 0x7023, .action = VIA_DXS_NO_VRA }, /* MSI K8T Neo2-FI */ 2364 { .subvendor = 0x1462, .subdevice = 0x7120, .action = VIA_DXS_ENABLE }, /* MSI KT4V */ 2365 { .subvendor = 0x1462, .subdevice = 0x7142, .action = VIA_DXS_ENABLE }, /* MSI K8MM-V */ 2366 { .subvendor = 0x147b, .subdevice = 0x1401, .action = VIA_DXS_ENABLE }, /* ABIT KD7(-RAID) */ 2367 { .subvendor = 0x147b, .subdevice = 0x1411, .action = VIA_DXS_ENABLE }, /* ABIT VA-20 */ 2368 { .subvendor = 0x147b, .subdevice = 0x1413, .action = VIA_DXS_ENABLE }, /* ABIT KV8 Pro */ 2369 { .subvendor = 0x147b, .subdevice = 0x1415, .action = VIA_DXS_NO_VRA }, /* Abit AV8 */ 2370 { .subvendor = 0x14ff, .subdevice = 0x0403, .action = VIA_DXS_ENABLE }, /* Twinhead mobo */ 2371 { .subvendor = 0x14ff, .subdevice = 0x0408, .action = VIA_DXS_SRC }, /* Twinhead laptop */ 2372 { .subvendor = 0x1558, .subdevice = 0x4701, .action = VIA_DXS_SRC }, /* Clevo D470 */ 2373 { .subvendor = 0x1584, .subdevice = 0x8120, .action = VIA_DXS_ENABLE }, /* Gericom/Targa/Vobis/Uniwill laptop */ 2374 { .subvendor = 0x1584, .subdevice = 0x8123, .action = VIA_DXS_NO_VRA }, /* Uniwill (Targa Visionary XP-210) */ 2375 { .subvendor = 0x161f, .subdevice = 0x202b, .action = VIA_DXS_NO_VRA }, /* Amira Note book */ 2376 { .subvendor = 0x161f, .subdevice = 0x2032, .action = VIA_DXS_48K }, /* m680x machines */ 2377 { .subvendor = 0x1631, .subdevice = 0xe004, .action = VIA_DXS_ENABLE }, /* Easy Note 3174, Packard Bell */ 2378 { .subvendor = 0x1695, .subdevice = 0x3005, .action = VIA_DXS_ENABLE }, /* EPoX EP-8K9A */ 2379 { .subvendor = 0x16f3, .subdevice = 0x6405, .action = VIA_DXS_SRC }, /* Jetway K8M8MS */ 2380 { .subvendor = 0x1849, .subdevice = 0x3059, .action = VIA_DXS_NO_VRA }, /* ASRock K7VM2 */ 2381 { .subvendor = 0x1849, .subdevice = 0x9761, .action = VIA_DXS_SRC }, /* ASRock mobo(?) */ 2382 { .subvendor = 0x1919, .subdevice = 0x200a, .action = VIA_DXS_NO_VRA }, /* Soltek SL-K8Tpro-939 */ 2383 { .subvendor = 0x4005, .subdevice = 0x4710, .action = VIA_DXS_SRC }, /* MSI K7T266 Pro2 (MS-6380 V2.0) BIOS 3.7 */ 2384 {0} /* terminator */ 2385 }; 2386 struct dxs_whitelist *w; 2387 unsigned short subsystem_vendor; 2388 unsigned short subsystem_device; 2389 2390 pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor); 2391 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &subsystem_device); 2392 2393 for (w = whitelist; w->subvendor; w++) { 2394 if (w->subvendor != subsystem_vendor) 2395 continue; 2396 if (w->mask) { 2397 if ((w->mask & subsystem_device) == w->subdevice) 2398 return w->action; 2399 } else { 2400 if (subsystem_device == w->subdevice) 2401 return w->action; 2402 } 2403 } 2404 2405 /* 2406 * not detected, try 48k rate only to be sure. 2407 */ 2408 printk(KERN_INFO "via82xx: Assuming DXS channels with 48k fixed sample rate.\n"); 2409 printk(KERN_INFO " Please try dxs_support=5 option\n"); 2410 printk(KERN_INFO " and report if it works on your machine.\n"); 2411 printk(KERN_INFO " For more details, read ALSA-Configuration.txt.\n"); 2412 return VIA_DXS_48K; 2413 }; 2414 2415 static int __devinit snd_via82xx_probe(struct pci_dev *pci, 2416 const struct pci_device_id *pci_id) 2417 { 2418 struct snd_card *card; 2419 struct via82xx *chip; 2420 unsigned char revision; 2421 int chip_type = 0, card_type; 2422 unsigned int i; 2423 int err; 2424 2425 card = snd_card_new(index, id, THIS_MODULE, 0); 2426 if (card == NULL) 2427 return -ENOMEM; 2428 2429 card_type = pci_id->driver_data; 2430 pci_read_config_byte(pci, PCI_REVISION_ID, &revision); 2431 switch (card_type) { 2432 case TYPE_CARD_VIA686: 2433 strcpy(card->driver, "VIA686A"); 2434 sprintf(card->shortname, "VIA 82C686A/B rev%x", revision); 2435 chip_type = TYPE_VIA686; 2436 break; 2437 case TYPE_CARD_VIA8233: 2438 chip_type = TYPE_VIA8233; 2439 sprintf(card->shortname, "VIA 823x rev%x", revision); 2440 for (i = 0; i < ARRAY_SIZE(via823x_cards); i++) { 2441 if (revision == via823x_cards[i].revision) { 2442 chip_type = via823x_cards[i].type; 2443 strcpy(card->shortname, via823x_cards[i].name); 2444 break; 2445 } 2446 } 2447 if (chip_type != TYPE_VIA8233A) { 2448 if (dxs_support == VIA_DXS_AUTO) 2449 dxs_support = check_dxs_list(pci); 2450 /* force to use VIA8233 or 8233A model according to 2451 * dxs_support module option 2452 */ 2453 if (dxs_support == VIA_DXS_DISABLE) 2454 chip_type = TYPE_VIA8233A; 2455 else 2456 chip_type = TYPE_VIA8233; 2457 } 2458 if (chip_type == TYPE_VIA8233A) 2459 strcpy(card->driver, "VIA8233A"); 2460 else if (revision >= VIA_REV_8237) 2461 strcpy(card->driver, "VIA8237"); /* no slog assignment */ 2462 else 2463 strcpy(card->driver, "VIA8233"); 2464 break; 2465 default: 2466 snd_printk(KERN_ERR "invalid card type %d\n", card_type); 2467 err = -EINVAL; 2468 goto __error; 2469 } 2470 2471 if ((err = snd_via82xx_create(card, pci, chip_type, revision, 2472 ac97_clock, &chip)) < 0) 2473 goto __error; 2474 card->private_data = chip; 2475 if ((err = snd_via82xx_mixer_new(chip, ac97_quirk)) < 0) 2476 goto __error; 2477 2478 if (chip_type == TYPE_VIA686) { 2479 if ((err = snd_via686_pcm_new(chip)) < 0 || 2480 (err = snd_via686_init_misc(chip)) < 0) 2481 goto __error; 2482 } else { 2483 if (chip_type == TYPE_VIA8233A) { 2484 if ((err = snd_via8233a_pcm_new(chip)) < 0) 2485 goto __error; 2486 // chip->dxs_fixed = 1; /* FIXME: use 48k for DXS #3? */ 2487 } else { 2488 if ((err = snd_via8233_pcm_new(chip)) < 0) 2489 goto __error; 2490 if (dxs_support == VIA_DXS_48K) 2491 chip->dxs_fixed = 1; 2492 else if (dxs_support == VIA_DXS_NO_VRA) 2493 chip->no_vra = 1; 2494 else if (dxs_support == VIA_DXS_SRC) { 2495 chip->no_vra = 1; 2496 chip->dxs_src = 1; 2497 } 2498 } 2499 if ((err = snd_via8233_init_misc(chip)) < 0) 2500 goto __error; 2501 } 2502 2503 /* disable interrupts */ 2504 for (i = 0; i < chip->num_devs; i++) 2505 snd_via82xx_channel_reset(chip, &chip->devs[i]); 2506 2507 sprintf(card->longname, 2508 "%s with %s at %#lx, irq %d", card->shortname, 2509 snd_ac97_get_short_name(chip->ac97), chip->port, chip->irq); 2510 2511 snd_via82xx_proc_init(chip); 2512 2513 if ((err = snd_card_register(card)) < 0) { 2514 snd_card_free(card); 2515 return err; 2516 } 2517 pci_set_drvdata(pci, card); 2518 return 0; 2519 2520 __error: 2521 snd_card_free(card); 2522 return err; 2523 } 2524 2525 static void __devexit snd_via82xx_remove(struct pci_dev *pci) 2526 { 2527 snd_card_free(pci_get_drvdata(pci)); 2528 pci_set_drvdata(pci, NULL); 2529 } 2530 2531 static struct pci_driver driver = { 2532 .name = "VIA 82xx Audio", 2533 .id_table = snd_via82xx_ids, 2534 .probe = snd_via82xx_probe, 2535 .remove = __devexit_p(snd_via82xx_remove), 2536 #ifdef CONFIG_PM 2537 .suspend = snd_via82xx_suspend, 2538 .resume = snd_via82xx_resume, 1901 2539 #endif 1902 1903 return 0;1904 }1905 1906 1907 /*1908 * proc interface1909 */1910 static void snd_via82xx_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)1911 {1912 via82xx_t *chip = entry->private_data;1913 int i;1914 1915 snd_iprintf(buffer, "%s\n\n", chip->card->longname);1916 for (i = 0; i < 0xa0; i += 4) {1917 snd_iprintf(buffer, "%02x: %08x\n", i, inl(chip->port + i));1918 }1919 }1920 1921 static void __devinit snd_via82xx_proc_init(via82xx_t *chip)1922 {1923 snd_info_entry_t *entry;1924 1925 if (! snd_card_proc_new(chip->card, "via82xx", &entry))1926 snd_info_set_text_ops(entry, chip, 1024, snd_via82xx_proc_read);1927 }1928 1929 /*1930 *1931 */1932 1933 static int __devinit snd_via82xx_chip_init(via82xx_t *chip)1934 {1935 unsigned int val;1936 unsigned long end_time;1937 unsigned char pval;1938 1939 #if 0 /* broken on K7M? */1940 if (chip->chip_type == TYPE_VIA686)1941 /* disable all legacy ports */1942 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, 0);1943 #endif1944 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval);1945 if (! (pval & VIA_ACLINK_C00_READY)) { /* codec not ready? */1946 /* deassert ACLink reset, force SYNC */1947 pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL,1948 VIA_ACLINK_CTRL_ENABLE |1949 VIA_ACLINK_CTRL_RESET |1950 VIA_ACLINK_CTRL_SYNC);1951 udelay(100);1952 #if 1 /* FIXME: should we do full reset here for all chip models? */1953 pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, 0x00);1954 udelay(100);1955 #else1956 /* deassert ACLink reset, force SYNC (warm AC'97 reset) */1957 pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL,1958 VIA_ACLINK_CTRL_RESET|VIA_ACLINK_CTRL_SYNC);1959 udelay(2);1960 #endif1961 /* ACLink on, deassert ACLink reset, VSR, SGD data out */1962 /* note - FM data out has trouble with non VRA codecs !! */1963 pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, VIA_ACLINK_CTRL_INIT);1964 udelay(100);1965 }1966 1967 /* Make sure VRA is enabled, in case we didn't do a1968 * complete codec reset, above */1969 pci_read_config_byte(chip->pci, VIA_ACLINK_CTRL, &pval);1970 if ((pval & VIA_ACLINK_CTRL_INIT) != VIA_ACLINK_CTRL_INIT) {1971 /* ACLink on, deassert ACLink reset, VSR, SGD data out */1972 /* note - FM data out has trouble with non VRA codecs !! */1973 pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, VIA_ACLINK_CTRL_INIT);1974 udelay(100);1975 }1976 1977 /* wait until codec ready */1978 end_time = jiffies + msecs_to_jiffies(750);1979 do {1980 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval);1981 if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */1982 break;1983 set_current_state(TASK_UNINTERRUPTIBLE);1984 schedule_timeout(1);1985 } while (time_before(jiffies, end_time));1986 1987 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)1988 snd_printk("AC'97 codec is not ready [0x%x]\n", val);1989 1990 #if 0 /* FIXME: we don't support the second codec yet so skip the detection now.. */1991 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ |1992 VIA_REG_AC97_SECONDARY_VALID |1993 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT));1994 end_time = jiffies + msecs_to_jiffies(750);1995 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ |1996 VIA_REG_AC97_SECONDARY_VALID |1997 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT));1998 do {1999 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_SECONDARY_VALID) {2000 chip->ac97_secondary = 1;2001 goto __ac97_ok2;2002 }2003 set_current_state(TASK_INTERRUPTIBLE);2004 schedule_timeout(1);2005 } while (time_before(jiffies, end_time));2006 /* This is ok, the most of motherboards have only one codec */2007 2008 __ac97_ok2:2009 #endif2010 2011 if (chip->chip_type == TYPE_VIA686) {2012 /* route FM trap to IRQ, disable FM trap */2013 pci_write_config_byte(chip->pci, VIA_FM_NMI_CTRL, 0);2014 /* disable all GPI interrupts */2015 outl(0, VIAREG(chip, GPI_INTR));2016 }2017 2018 if (chip->chip_type != TYPE_VIA686) {2019 /* Workaround for Award BIOS bug:2020 * DXS channels don't work properly with VRA if MC97 is disabled.2021 */2022 struct pci_dev *pci;2023 pci = pci_find_device(0x1106, 0x3068, NULL); /* MC97 */2024 if (pci) {2025 unsigned char data;2026 pci_read_config_byte(pci, 0x44, &data);2027 pci_write_config_byte(pci, 0x44, data | 0x40);2028 }2029 }2030 2031 if (chip->chip_type != TYPE_VIA8233A) {2032 int i, idx;2033 for (idx = 0; idx < 4; idx++) {2034 unsigned long port = chip->port + 0x10 * idx;2035 for (i = 0; i < 2; i++)2036 outb(chip->playback_volume[i], port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);2037 }2038 }2039 2040 return 0;2041 }2042 2043 #ifdef CONFIG_PM2044 /*2045 * power management2046 */2047 static int snd_via82xx_suspend(snd_card_t *card, unsigned int state)2048 {2049 via82xx_t *chip = card->pm_private_data;2050 int i;2051 2052 for (i = 0; i < 2; i++)2053 if (chip->pcms[i])2054 snd_pcm_suspend_all(chip->pcms[i]);2055 for (i = 0; i < chip->num_devs; i++)2056 snd_via82xx_channel_reset(chip, &chip->devs[i]);2057 synchronize_irq(chip->irq);2058 snd_ac97_suspend(chip->ac97);2059 2060 /* save misc values */2061 if (chip->chip_type != TYPE_VIA686) {2062 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &chip->spdif_ctrl_saved);2063 chip->capture_src_saved[0] = inb(chip->port + VIA_REG_CAPTURE_CHANNEL);2064 chip->capture_src_saved[1] = inb(chip->port + VIA_REG_CAPTURE_CHANNEL + 0x10);2065 }2066 2067 pci_set_power_state(chip->pci, 3);2068 pci_disable_device(chip->pci);2069 return 0;2070 }2071 2072 static int snd_via82xx_resume(snd_card_t *card, unsigned int state)2073 {2074 via82xx_t *chip = card->pm_private_data;2075 int i;2076 2077 pci_enable_device(chip->pci);2078 pci_set_power_state(chip->pci, 0);2079 2080 snd_via82xx_chip_init(chip);2081 2082 if (chip->chip_type == TYPE_VIA686) {2083 if (chip->mpu_port_saved)2084 pci_write_config_dword(chip->pci, 0x18, chip->mpu_port_saved | 0x01);2085 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, chip->legacy_saved);2086 pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, chip->legacy_cfg_saved);2087 } else {2088 pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, chip->spdif_ctrl_saved);2089 outb(chip->capture_src_saved[0], chip->port + VIA_REG_CAPTURE_CHANNEL);2090 outb(chip->capture_src_saved[1], chip->port + VIA_REG_CAPTURE_CHANNEL + 0x10);2091 }2092 2093 snd_ac97_resume(chip->ac97);2094 2095 for (i = 0; i < chip->num_devs; i++)2096 snd_via82xx_channel_reset(chip, &chip->devs[i]);2097 2098 return 0;2099 }2100 #endif /* CONFIG_PM */2101 2102 static int snd_via82xx_free(via82xx_t *chip)2103 {2104 unsigned int i;2105 2106 if (chip->irq < 0)2107 goto __end_hw;2108 /* disable interrupts */2109 for (i = 0; i < chip->num_devs; i++)2110 snd_via82xx_channel_reset(chip, &chip->devs[i]);2111 synchronize_irq(chip->irq);2112 __end_hw:2113 if (chip->irq >= 0)2114 free_irq(chip->irq, (void *)chip);2115 if (chip->mpu_res) {2116 release_resource(chip->mpu_res);2117 kfree_nocheck(chip->mpu_res);2118 }2119 pci_release_regions(chip->pci);2120 if (chip->chip_type == TYPE_VIA686) {2121 #ifdef SUPPORT_JOYSTICK2122 if (chip->res_joystick) {2123 gameport_unregister_port(&chip->gameport);2124 release_resource(chip->res_joystick);2125 kfree_nocheck(chip->res_joystick);2126 }2127 #endif2128 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, chip->old_legacy);2129 pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, chip->old_legacy_cfg);2130 }2131 2132 kfree(chip);2133 return 0;2134 }2135 2136 static int snd_via82xx_dev_free(snd_device_t *device)2137 {2138 via82xx_t *chip = device->device_data;2139 return snd_via82xx_free(chip);2140 }2141 2142 static int __devinit snd_via82xx_create(snd_card_t * card,2143 struct pci_dev *pci,2144 int chip_type,2145 int revision,2146 unsigned int ac97_clock,2147 via82xx_t ** r_via)2148 {2149 via82xx_t *chip;2150 int err;2151 static snd_device_ops_t ops = {2152 snd_via82xx_dev_free,0,0,02153 };2154 2155 if ((err = pci_enable_device(pci)) < 0)2156 return err;2157 2158 if ((chip = (via82xx_t *)kzalloc(sizeof(*chip), GFP_KERNEL)) == NULL)2159 return -ENOMEM;2160 2161 chip->chip_type = chip_type;2162 chip->revision = revision;2163 2164 spin_lock_init(&chip->reg_lock);2165 spin_lock_init(&chip->rates[0].lock);2166 spin_lock_init(&chip->rates[1].lock);2167 chip->card = card;2168 chip->pci = pci;2169 chip->irq = -1;2170 2171 pci_read_config_byte(pci, VIA_FUNC_ENABLE, &chip->old_legacy);2172 pci_read_config_byte(pci, VIA_PNP_CONTROL, &chip->old_legacy_cfg);2173 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE,2174 chip->old_legacy & ~(VIA_FUNC_ENABLE_SB|VIA_FUNC_ENABLE_FM));2175 2176 if ((err = pci_request_regions(pci, card->driver)) < 0) {2177 kfree(chip);2178 return err;2179 }2180 chip->port = pci_resource_start(pci, 0);2181 if (request_irq(pci->irq,2182 chip_type == TYPE_VIA8233 ?2183 snd_via8233_interrupt : snd_via686_interrupt,2184 SA_INTERRUPT|SA_SHIRQ,2185 card->driver, (void *)chip)) {2186 snd_printk("unable to grab IRQ %d\n", pci->irq);2187 snd_via82xx_free(chip);2188 return -EBUSY;2189 }2190 chip->irq = pci->irq;2191 if (ac97_clock >= 8000 && ac97_clock <= 48000)2192 chip->ac97_clock = ac97_clock;2193 synchronize_irq(chip->irq);2194 2195 if ((err = snd_via82xx_chip_init(chip)) < 0) {2196 snd_via82xx_free(chip);2197 return err;2198 }2199 2200 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {2201 snd_via82xx_free(chip);2202 return err;2203 }2204 2205 /* The 8233 ac97 controller does not implement the master bit2206 * in the pci command register. IMHO this is a violation of the PCI spec.2207 * We call pci_set_master here because it does not hurt. */2208 pci_set_master(pci);2209 2210 *r_via = chip;2211 return 0;2212 }2213 2214 typedef struct via823x_info {2215 int revision;2216 char *name;2217 int type;2218 2540 }; 2219 2541 2220 static struct via823x_info via823x_cards[] __devinitdata = {2221 { VIA_REV_PRE_8233, "VIA 8233-Pre", TYPE_VIA8233 },2222 { VIA_REV_8233C, "VIA 8233C", TYPE_VIA8233 },2223 { VIA_REV_8233, "VIA 8233", TYPE_VIA8233 },2224 { VIA_REV_8233A, "VIA 8233A", TYPE_VIA8233A },2225 { VIA_REV_8235, "VIA 8235", TYPE_VIA8233 },2226 { VIA_REV_8237, "VIA 8237", TYPE_VIA8233 },2227 };2228 2229 /*2230 * auto detection of DXS channel supports.2231 */2232 struct dxs_whitelist {2233 unsigned short subvendor;2234 unsigned short subdevice;2235 unsigned short mask;2236 short action; /* new dxs_support value */2237 };2238 2239 static int __devinit check_dxs_list(struct pci_dev *pci)2240 {2241 2242 static struct dxs_whitelist whitelist[] = {2243 { 0x1005, 0x4710, 0, VIA_DXS_ENABLE }, /* Avance Logic Mobo */2244 { 0x1019, 0x0996, 0, VIA_DXS_48K },2245 { 0x1019, 0x0a81, 0, VIA_DXS_NO_VRA }, /* ECS K7VTA3 v8.0 */2246 { 0x1019, 0x0a85, 0, VIA_DXS_NO_VRA }, /* ECS L7VMM2 */2247 { .subvendor = 0x1019, .subdevice = 0xa101, .action = VIA_DXS_SRC },2248 { 0x1025, 0x0033, 0, VIA_DXS_NO_VRA }, /* Acer Inspire 1353LM */2249 { .subvendor = 0x1025, .subdevice = 0x0046, .action = VIA_DXS_SRC }, /* Acer Aspire 1524 WLMi */2250 { 0x1043, 0x8095, 0, VIA_DXS_NO_VRA }, /* ASUS A7V8X (FIXME: possibly VIA_DXS_ENABLE?)*/2251 { 0x1043, 0x80a1, 0, VIA_DXS_NO_VRA }, /* ASUS A7V8-X */2252 { 0x1043, 0x80b0, 0, VIA_DXS_ENABLE }, /* ASUS A7V600 */2253 { 0x1043, 0x812a, 0, VIA_DXS_SRC }, /* ASUS A8V Deluxe */2254 { 0x1071, 0x8375, 0, VIA_DXS_NO_VRA }, /* Vobis/Yakumo/Mitac notebook */2255 { 0x1071, 0x8399, 0, VIA_DXS_NO_VRA }, /* Umax AB 595T (VIA K8N800A - VT8237) */2256 { 0x10cf, 0x118e, 0, VIA_DXS_ENABLE }, /* FSC laptop */2257 { 0x1106, 0x4161, 0, VIA_DXS_NO_VRA }, /* ASRock K7VT2 */2258 { 0x1106, 0x4552, 0, VIA_DXS_NO_VRA }, /* QDI Kudoz 7X/600-6AL */2259 { 0x1106, 0xaa01, 0, VIA_DXS_NO_VRA }, /* EPIA MII */2260 { 0x1106, 0xc001, 0, VIA_DXS_SRC }, /* Insight P4-ITX */2261 { 0x1297, 0xa232, 0, VIA_DXS_ENABLE }, /* Shuttle ?? */2262 { 0x1297, 0xc160, 0, VIA_DXS_ENABLE }, /* Shuttle SK41G */2263 { 0x1458, 0xa002, 0, VIA_DXS_ENABLE }, /* Gigabyte GA-7VAXP */2264 { 0x1462, 0x0080, 0, VIA_DXS_SRC }, /* MSI K8T Neo-FIS2R */2265 { .subvendor = 0x1462, .subdevice = 0x0430, .action = VIA_DXS_SRC }, /* MSI 7142 (K8MM-V) */2266 { 0x1462, 0x3800, 0, VIA_DXS_ENABLE }, /* MSI KT266 */2267 { 0x1462, 0x5901, 0, VIA_DXS_NO_VRA }, /* MSI KT6 Delta-SR */2268 { 0x1462, 0x7023, 0, VIA_DXS_NO_VRA }, /* MSI K8T Neo2-FI */2269 { 0x1462, 0x7120, 0, VIA_DXS_ENABLE }, /* MSI KT4V */2270 { .subvendor = 0x1462, .subdevice = 0x7142, .action = VIA_DXS_ENABLE }, /* MSI K8MM-V */2271 { 0x147b, 0x1401, 0, VIA_DXS_ENABLE }, /* ABIT KD7(-RAID) */2272 { 0x147b, 0x1411, 0, VIA_DXS_ENABLE }, /* ABIT VA-20 */2273 { 0x147b, 0x1413, 0, VIA_DXS_ENABLE }, /* ABIT KV8 Pro */2274 { 0x147b, 0x1415, 0, VIA_DXS_NO_VRA }, /* Abit AV8 */2275 { 0x14ff, 0x0403, 0, VIA_DXS_ENABLE }, /* Twinhead mobo */2276 { .subvendor = 0x14ff, .subdevice = 0x0408, .action = VIA_DXS_SRC }, /* Twinhead laptop */2277 { .subvendor = 0x1558, .subdevice = 0x4701, .action = VIA_DXS_SRC }, /* Clevo D470 */2278 { 0x1584, 0x8120, 0, VIA_DXS_ENABLE }, /* Gericom/Targa/Vobis/Uniwill laptop */2279 { 0x1584, 0x8123, 0, VIA_DXS_NO_VRA }, /* Uniwill (Targa Visionary XP-210) */2280 { 0x1631, 0xe004, 0, VIA_DXS_ENABLE }, /* Easy Note 3174, Packard Bell */2281 { 0x1695, 0x3005, 0, VIA_DXS_ENABLE }, /* EPoX EP-8K9A */2282 { 0x1695, 0x300C, 0, VIA_DXS_48K }, /* LewHoo */2283 { 0x161f, 0x202b, 0, VIA_DXS_NO_VRA }, /* Amira Note book */2284 { 0x161f, 0x2032, 0, VIA_DXS_48K }, /* m680x machines */2285 { 0x1849, 0x3059, 0, VIA_DXS_NO_VRA }, /* ASRock K7VM2 */2286 { 0x1919, 0x200a, 0, VIA_DXS_NO_VRA }, /* Soltek SL-K8Tpro-939 */2287 { 0x4005, 0x4710, 0, VIA_DXS_SRC }, /* MSI K7T266 Pro2 (MS-6380 V2.0) BIOS 3.7 */2288 { 0 } /* terminator */2289 };2290 struct dxs_whitelist *w;2291 unsigned short subsystem_vendor;2292 unsigned short subsystem_device;2293 2294 pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor);2295 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &subsystem_device);2296 2297 for (w = whitelist; w->subvendor; w++) {2298 if (w->subvendor != subsystem_vendor)2299 continue;2300 if (w->mask) {2301 if ((w->mask & subsystem_device) == w->subdevice)2302 return w->action;2303 } else {2304 if (subsystem_device == w->subdevice)2305 return w->action;2306 }2307 }2308 2309 /*2310 * not detected, try 48k rate only to be sure.2311 */2312 printk(KERN_INFO "via82xx: Assuming DXS channels with 48k fixed sample rate.\n");2313 printk(KERN_INFO " Please try dxs_support=1 or dxs_support=4 option\n");2314 printk(KERN_INFO " and report if it works on your machine.\n");2315 return VIA_DXS_48K;2316 };2317 2318 static int __devinit snd_via82xx_probe(struct pci_dev *pci,2319 const struct pci_device_id *pci_id)2320 {2321 static int dev;2322 snd_card_t *card;2323 via82xx_t *chip;2324 unsigned char revision;2325 int chip_type = 0, card_type;2326 unsigned int i;2327 int err;2328 u16 val;2329 2330 if (dev >= SNDRV_CARDS)2331 return -ENODEV;2332 if (!enable[dev]) {2333 dev++;2334 return -ENOENT;2335 }2336 2337 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);2338 if (card == NULL)2339 return -ENOMEM;2340 2341 card_type = pci_id->driver_data;2342 pci_read_config_byte(pci, PCI_REVISION_ID, &revision);2343 switch (card_type) {2344 case TYPE_CARD_VIA686:2345 strcpy(card->driver, "VIA686A");2346 sprintf(card->shortname, "VIA 82C686A/B rev%x", revision);2347 chip_type = TYPE_VIA686;2348 break;2349 case TYPE_CARD_VIA8233:2350 chip_type = TYPE_VIA8233;2351 sprintf(card->shortname, "VIA 823x rev%x", revision);2352 for (i = 0; i < ARRAY_SIZE(via823x_cards); i++) {2353 if (revision == via823x_cards[i].revision) {2354 chip_type = via823x_cards[i].type;2355 strcpy(card->shortname, via823x_cards[i].name);2356 break;2357 }2358 }2359 if (chip_type != TYPE_VIA8233A) {2360 if (dxs_support[dev] == VIA_DXS_AUTO)2361 dxs_support[dev] = check_dxs_list(pci);2362 /* force to use VIA8233 or 8233A model according to2363 * dxs_support module option2364 */2365 if (dxs_support[dev] == VIA_DXS_DISABLE)2366 chip_type = TYPE_VIA8233A;2367 else2368 chip_type = TYPE_VIA8233;2369 }2370 if (chip_type == TYPE_VIA8233A)2371 strcpy(card->driver, "VIA8233A");2372 else if (revision >= VIA_REV_8237)2373 strcpy(card->driver, "VIA8237"); /* no slog assignment */2374 else2375 strcpy(card->driver, "VIA8233");2376 2377 break;2378 default:2379 snd_printk(KERN_ERR "invalid card type %d\n", card_type);2380 err = -EINVAL;2381 goto __error;2382 }2383 2384 if ((err = snd_via82xx_create(card, pci, chip_type, revision, ac97_clock[dev], &chip)) < 0)2385 goto __error;2386 if ((err = snd_via82xx_mixer_new(chip, ac97_quirk[dev])) < 0)2387 goto __error;2388 2389 if (chip_type == TYPE_VIA686) {2390 if ((err = snd_via686_pcm_new(chip)) < 0 ||2391 (err = snd_via686_init_misc(chip, dev)) < 0)2392 goto __error;2393 } else {2394 if (chip_type == TYPE_VIA8233A) {2395 if ((err = snd_via8233a_pcm_new(chip)) < 0)2396 goto __error;2397 // chip->dxs_fixed = 1; /* use 48k for DXS #3 */2398 } else {2399 if ((err = snd_via8233_pcm_new(chip)) < 0)2400 goto __error;2401 if (dxs_support[dev] == VIA_DXS_48K)2402 chip->dxs_fixed = 1;2403 else if (dxs_support[dev] == VIA_DXS_NO_VRA)2404 chip->no_vra = 1;2405 else if (dxs_support[dev] == VIA_DXS_SRC) {2406 chip->no_vra = 1;2407 chip->dxs_src = 1;2408 }2409 }2410 if ((err = snd_via8233_init_misc(chip, dev)) < 0)2411 goto __error;2412 }2413 2414 snd_card_set_pm_callback(card, snd_via82xx_suspend, snd_via82xx_resume, chip);2415 2416 /* disable interrupts */2417 for (i = 0; i < chip->num_devs; i++)2418 snd_via82xx_channel_reset(chip, &chip->devs[i]);2419 2420 sprintf(card->longname, "%s at 0x%lx, irq %d",2421 card->shortname, chip->port, chip->irq);2422 2423 snd_via82xx_proc_init(chip);2424 2425 if ((err = snd_card_register(card)) < 0) {2426 snd_card_free(card);2427 return err;2428 }2429 pci_set_drvdata(pci, card);2430 dev++;2431 return 0;2432 2433 __error:2434 snd_card_free(card);2435 return err;2436 }2437 2438 static void __devexit snd_via82xx_remove(struct pci_dev *pci)2439 {2440 snd_card_free(pci_get_drvdata(pci));2441 pci_set_drvdata(pci, NULL);2442 }2443 2444 static struct pci_driver driver = {2445 0,0,0,"VIA 82xx Audio",2446 snd_via82xx_ids,2447 snd_via82xx_probe,2448 snd_via82xx_remove,2449 SND_PCI_PM_CALLBACKS2450 };2451 2452 2542 static int __init alsa_card_via82xx_init(void) 2453 2543 { 2454 int err; 2455 2456 #ifdef TARGET_OS2 2457 if (midi_port > 0) mpu_port[0] = midi_port; 2458 #endif 2459 if ((err = pci_module_init(&driver)) < 0) { 2460 #ifdef MODULE 2461 // printk(KERN_ERR "VIA 82xx soundcard not found or device busy\n"); 2462 #endif 2463 return err; 2464 } 2465 return 0; 2544 return pci_register_driver(&driver); 2466 2545 } 2467 2546 2468 2547 static void __exit alsa_card_via82xx_exit(void) 2469 2548 { 2470 2549 pci_unregister_driver(&driver); 2471 2550 } 2472 2551 2473 2552 module_init(alsa_card_via82xx_init) 2474 2553 module_exit(alsa_card_via82xx_exit) 2475 2476 #ifndef MODULE2477 2478 /* format is: snd-via82xx=enable,index,id,2479 mpu_port,joystick,ac97_clock,dxs_support */2480 2481 static int __init alsa_card_via82xx_setup(char *str)2482 {2483 static unsigned __initdata nr_dev = 0;2484 2485 if (nr_dev >= SNDRV_CARDS)2486 return 0;2487 (void)(get_option(&str,&enable[nr_dev]) == 2 &&2488 get_option(&str,&index[nr_dev]) == 2 &&2489 get_id(&str,&id[nr_dev]) == 2 &&2490 get_option_long(&str,&mpu_port[nr_dev]) == 2 &&2491 #ifdef SUPPORT_JOYSTICK2492 get_option(&str,&joystick[nr_dev]) == 2 &&2493 #endif2494 get_option(&str,&ac97_quirk[nr_dev]) == 2 &&2495 get_option(&str,&ac97_clock[nr_dev]) == 2 &&2496 get_option(&str,&dxs_support[nr_dev]) == 2);2497 nr_dev++;2498 return 1;2499 }2500 2501 __setup("snd-via82xx=", alsa_card_via82xx_setup);2502 2503 #endif /* ifndef MODULE */
Note:
See TracChangeset
for help on using the changeset viewer.