diff options
Diffstat (limited to 'sound/pci/hda/hda_intel.c')
-rw-r--r-- | sound/pci/hda/hda_intel.c | 132 |
1 files changed, 86 insertions, 46 deletions
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 79d63c99f092..e9d4cb4d07e1 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c | |||
@@ -55,6 +55,7 @@ static char *model; | |||
55 | static int position_fix; | 55 | static int position_fix; |
56 | static int probe_mask = -1; | 56 | static int probe_mask = -1; |
57 | static int single_cmd; | 57 | static int single_cmd; |
58 | static int disable_msi; | ||
58 | 59 | ||
59 | module_param(index, int, 0444); | 60 | module_param(index, int, 0444); |
60 | MODULE_PARM_DESC(index, "Index value for Intel HD audio interface."); | 61 | MODULE_PARM_DESC(index, "Index value for Intel HD audio interface."); |
@@ -68,6 +69,8 @@ module_param(probe_mask, int, 0444); | |||
68 | MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1)."); | 69 | MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1)."); |
69 | module_param(single_cmd, bool, 0444); | 70 | module_param(single_cmd, bool, 0444); |
70 | MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs (for debugging only)."); | 71 | MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs (for debugging only)."); |
72 | module_param(disable_msi, int, 0); | ||
73 | MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)"); | ||
71 | 74 | ||
72 | 75 | ||
73 | /* just for backward compatibility */ | 76 | /* just for backward compatibility */ |
@@ -252,7 +255,7 @@ enum { | |||
252 | struct azx_dev { | 255 | struct azx_dev { |
253 | u32 *bdl; /* virtual address of the BDL */ | 256 | u32 *bdl; /* virtual address of the BDL */ |
254 | dma_addr_t bdl_addr; /* physical address of the BDL */ | 257 | dma_addr_t bdl_addr; /* physical address of the BDL */ |
255 | volatile u32 *posbuf; /* position buffer pointer */ | 258 | u32 *posbuf; /* position buffer pointer */ |
256 | 259 | ||
257 | unsigned int bufsize; /* size of the play buffer in bytes */ | 260 | unsigned int bufsize; /* size of the play buffer in bytes */ |
258 | unsigned int fragsize; /* size of each period in bytes */ | 261 | unsigned int fragsize; /* size of each period in bytes */ |
@@ -271,8 +274,8 @@ struct azx_dev { | |||
271 | /* for sanity check of position buffer */ | 274 | /* for sanity check of position buffer */ |
272 | unsigned int period_intr; | 275 | unsigned int period_intr; |
273 | 276 | ||
274 | unsigned int opened: 1; | 277 | unsigned int opened :1; |
275 | unsigned int running: 1; | 278 | unsigned int running :1; |
276 | }; | 279 | }; |
277 | 280 | ||
278 | /* CORB/RIRB */ | 281 | /* CORB/RIRB */ |
@@ -330,8 +333,9 @@ struct azx { | |||
330 | 333 | ||
331 | /* flags */ | 334 | /* flags */ |
332 | int position_fix; | 335 | int position_fix; |
333 | unsigned int initialized: 1; | 336 | unsigned int initialized :1; |
334 | unsigned int single_cmd: 1; | 337 | unsigned int single_cmd :1; |
338 | unsigned int polling_mode :1; | ||
335 | }; | 339 | }; |
336 | 340 | ||
337 | /* driver types */ | 341 | /* driver types */ |
@@ -516,23 +520,36 @@ static void azx_update_rirb(struct azx *chip) | |||
516 | static unsigned int azx_rirb_get_response(struct hda_codec *codec) | 520 | static unsigned int azx_rirb_get_response(struct hda_codec *codec) |
517 | { | 521 | { |
518 | struct azx *chip = codec->bus->private_data; | 522 | struct azx *chip = codec->bus->private_data; |
519 | int timeout = 50; | 523 | unsigned long timeout; |
520 | 524 | ||
521 | while (chip->rirb.cmds) { | 525 | again: |
522 | if (! --timeout) { | 526 | timeout = jiffies + msecs_to_jiffies(1000); |
523 | snd_printk(KERN_ERR | 527 | do { |
524 | "hda_intel: azx_get_response timeout, " | 528 | if (chip->polling_mode) { |
525 | "switching to single_cmd mode...\n"); | 529 | spin_lock_irq(&chip->reg_lock); |
526 | chip->rirb.rp = azx_readb(chip, RIRBWP); | 530 | azx_update_rirb(chip); |
527 | chip->rirb.cmds = 0; | 531 | spin_unlock_irq(&chip->reg_lock); |
528 | /* switch to single_cmd mode */ | ||
529 | chip->single_cmd = 1; | ||
530 | azx_free_cmd_io(chip); | ||
531 | return -1; | ||
532 | } | 532 | } |
533 | msleep(1); | 533 | if (! chip->rirb.cmds) |
534 | return chip->rirb.res; /* the last value */ | ||
535 | schedule_timeout_interruptible(1); | ||
536 | } while (time_after_eq(timeout, jiffies)); | ||
537 | |||
538 | if (!chip->polling_mode) { | ||
539 | snd_printk(KERN_WARNING "hda_intel: azx_get_response timeout, " | ||
540 | "switching to polling mode...\n"); | ||
541 | chip->polling_mode = 1; | ||
542 | goto again; | ||
534 | } | 543 | } |
535 | return chip->rirb.res; /* the last value */ | 544 | |
545 | snd_printk(KERN_ERR "hda_intel: azx_get_response timeout, " | ||
546 | "switching to single_cmd mode...\n"); | ||
547 | chip->rirb.rp = azx_readb(chip, RIRBWP); | ||
548 | chip->rirb.cmds = 0; | ||
549 | /* switch to single_cmd mode */ | ||
550 | chip->single_cmd = 1; | ||
551 | azx_free_cmd_io(chip); | ||
552 | return -1; | ||
536 | } | 553 | } |
537 | 554 | ||
538 | /* | 555 | /* |
@@ -642,14 +659,14 @@ static int azx_reset(struct azx *chip) | |||
642 | azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET); | 659 | azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET); |
643 | 660 | ||
644 | count = 50; | 661 | count = 50; |
645 | while (! azx_readb(chip, GCTL) && --count) | 662 | while (!azx_readb(chip, GCTL) && --count) |
646 | msleep(1); | 663 | msleep(1); |
647 | 664 | ||
648 | /* Brent Chartrand said to wait >= 540us for codecs to intialize */ | 665 | /* Brent Chartrand said to wait >= 540us for codecs to initialize */ |
649 | msleep(1); | 666 | msleep(1); |
650 | 667 | ||
651 | /* check to see if controller is ready */ | 668 | /* check to see if controller is ready */ |
652 | if (! azx_readb(chip, GCTL)) { | 669 | if (!azx_readb(chip, GCTL)) { |
653 | snd_printd("azx_reset: controller not ready!\n"); | 670 | snd_printd("azx_reset: controller not ready!\n"); |
654 | return -EBUSY; | 671 | return -EBUSY; |
655 | } | 672 | } |
@@ -658,7 +675,7 @@ static int azx_reset(struct azx *chip) | |||
658 | azx_writel(chip, GCTL, azx_readl(chip, GCTL) | ICH6_GCTL_UREN); | 675 | azx_writel(chip, GCTL, azx_readl(chip, GCTL) | ICH6_GCTL_UREN); |
659 | 676 | ||
660 | /* detect codecs */ | 677 | /* detect codecs */ |
661 | if (! chip->codec_mask) { | 678 | if (!chip->codec_mask) { |
662 | chip->codec_mask = azx_readw(chip, STATESTS); | 679 | chip->codec_mask = azx_readw(chip, STATESTS); |
663 | snd_printdd("codec_mask = 0x%x\n", chip->codec_mask); | 680 | snd_printdd("codec_mask = 0x%x\n", chip->codec_mask); |
664 | } | 681 | } |
@@ -766,7 +783,7 @@ static void azx_init_chip(struct azx *chip) | |||
766 | azx_int_enable(chip); | 783 | azx_int_enable(chip); |
767 | 784 | ||
768 | /* initialize the codec command I/O */ | 785 | /* initialize the codec command I/O */ |
769 | if (! chip->single_cmd) | 786 | if (!chip->single_cmd) |
770 | azx_init_cmd_io(chip); | 787 | azx_init_cmd_io(chip); |
771 | 788 | ||
772 | /* program the position buffer */ | 789 | /* program the position buffer */ |
@@ -794,7 +811,7 @@ static void azx_init_chip(struct azx *chip) | |||
794 | /* | 811 | /* |
795 | * interrupt handler | 812 | * interrupt handler |
796 | */ | 813 | */ |
797 | static irqreturn_t azx_interrupt(int irq, void* dev_id, struct pt_regs *regs) | 814 | static irqreturn_t azx_interrupt(int irq, void *dev_id, struct pt_regs *regs) |
798 | { | 815 | { |
799 | struct azx *chip = dev_id; | 816 | struct azx *chip = dev_id; |
800 | struct azx_dev *azx_dev; | 817 | struct azx_dev *azx_dev; |
@@ -999,8 +1016,9 @@ static struct snd_pcm_hardware azx_pcm_hw = { | |||
999 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | | 1016 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
1000 | SNDRV_PCM_INFO_BLOCK_TRANSFER | | 1017 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
1001 | SNDRV_PCM_INFO_MMAP_VALID | | 1018 | SNDRV_PCM_INFO_MMAP_VALID | |
1002 | SNDRV_PCM_INFO_PAUSE /*|*/ | 1019 | /* No full-resume yet implemented */ |
1003 | /*SNDRV_PCM_INFO_RESUME*/), | 1020 | /* SNDRV_PCM_INFO_RESUME |*/ |
1021 | SNDRV_PCM_INFO_PAUSE), | ||
1004 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | 1022 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
1005 | .rates = SNDRV_PCM_RATE_48000, | 1023 | .rates = SNDRV_PCM_RATE_48000, |
1006 | .rate_min = 48000, | 1024 | .rate_min = 48000, |
@@ -1178,7 +1196,7 @@ static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) | |||
1178 | if (chip->position_fix == POS_FIX_POSBUF || | 1196 | if (chip->position_fix == POS_FIX_POSBUF || |
1179 | chip->position_fix == POS_FIX_AUTO) { | 1197 | chip->position_fix == POS_FIX_AUTO) { |
1180 | /* use the position buffer */ | 1198 | /* use the position buffer */ |
1181 | pos = *azx_dev->posbuf; | 1199 | pos = le32_to_cpu(*azx_dev->posbuf); |
1182 | if (chip->position_fix == POS_FIX_AUTO && | 1200 | if (chip->position_fix == POS_FIX_AUTO && |
1183 | azx_dev->period_intr == 1 && ! pos) { | 1201 | azx_dev->period_intr == 1 && ! pos) { |
1184 | printk(KERN_WARNING | 1202 | printk(KERN_WARNING |
@@ -1222,7 +1240,12 @@ static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec, | |||
1222 | struct snd_pcm *pcm; | 1240 | struct snd_pcm *pcm; |
1223 | struct azx_pcm *apcm; | 1241 | struct azx_pcm *apcm; |
1224 | 1242 | ||
1225 | snd_assert(cpcm->stream[0].substreams || cpcm->stream[1].substreams, return -EINVAL); | 1243 | /* if no substreams are defined for both playback and capture, |
1244 | * it's just a placeholder. ignore it. | ||
1245 | */ | ||
1246 | if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams) | ||
1247 | return 0; | ||
1248 | |||
1226 | snd_assert(cpcm->name, return -EINVAL); | 1249 | snd_assert(cpcm->name, return -EINVAL); |
1227 | 1250 | ||
1228 | err = snd_pcm_new(chip->card, cpcm->name, pcm_dev, | 1251 | err = snd_pcm_new(chip->card, cpcm->name, pcm_dev, |
@@ -1248,7 +1271,8 @@ static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec, | |||
1248 | snd_dma_pci_data(chip->pci), | 1271 | snd_dma_pci_data(chip->pci), |
1249 | 1024 * 64, 1024 * 128); | 1272 | 1024 * 64, 1024 * 128); |
1250 | chip->pcm[pcm_dev] = pcm; | 1273 | chip->pcm[pcm_dev] = pcm; |
1251 | chip->pcm_devs = pcm_dev + 1; | 1274 | if (chip->pcm_devs < pcm_dev + 1) |
1275 | chip->pcm_devs = pcm_dev + 1; | ||
1252 | 1276 | ||
1253 | return 0; | 1277 | return 0; |
1254 | } | 1278 | } |
@@ -1326,7 +1350,7 @@ static int __devinit azx_init_stream(struct azx *chip) | |||
1326 | struct azx_dev *azx_dev = &chip->azx_dev[i]; | 1350 | struct azx_dev *azx_dev = &chip->azx_dev[i]; |
1327 | azx_dev->bdl = (u32 *)(chip->bdl.area + off); | 1351 | azx_dev->bdl = (u32 *)(chip->bdl.area + off); |
1328 | azx_dev->bdl_addr = chip->bdl.addr + off; | 1352 | azx_dev->bdl_addr = chip->bdl.addr + off; |
1329 | azx_dev->posbuf = (volatile u32 *)(chip->posbuf.area + i * 8); | 1353 | azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8); |
1330 | /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ | 1354 | /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ |
1331 | azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80); | 1355 | azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80); |
1332 | /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */ | 1356 | /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */ |
@@ -1355,6 +1379,10 @@ static int azx_suspend(struct pci_dev *pci, pm_message_t state) | |||
1355 | snd_pcm_suspend_all(chip->pcm[i]); | 1379 | snd_pcm_suspend_all(chip->pcm[i]); |
1356 | snd_hda_suspend(chip->bus, state); | 1380 | snd_hda_suspend(chip->bus, state); |
1357 | azx_free_cmd_io(chip); | 1381 | azx_free_cmd_io(chip); |
1382 | if (chip->irq >= 0) | ||
1383 | free_irq(chip->irq, chip); | ||
1384 | if (!disable_msi) | ||
1385 | pci_disable_msi(chip->pci); | ||
1358 | pci_disable_device(pci); | 1386 | pci_disable_device(pci); |
1359 | pci_save_state(pci); | 1387 | pci_save_state(pci); |
1360 | return 0; | 1388 | return 0; |
@@ -1367,6 +1395,12 @@ static int azx_resume(struct pci_dev *pci) | |||
1367 | 1395 | ||
1368 | pci_restore_state(pci); | 1396 | pci_restore_state(pci); |
1369 | pci_enable_device(pci); | 1397 | pci_enable_device(pci); |
1398 | if (!disable_msi) | ||
1399 | pci_enable_msi(pci); | ||
1400 | /* FIXME: need proper error handling */ | ||
1401 | request_irq(pci->irq, azx_interrupt, IRQF_DISABLED|IRQF_SHARED, | ||
1402 | "HDA Intel", chip); | ||
1403 | chip->irq = pci->irq; | ||
1370 | pci_set_master(pci); | 1404 | pci_set_master(pci); |
1371 | azx_init_chip(chip); | 1405 | azx_init_chip(chip); |
1372 | snd_hda_resume(chip->bus); | 1406 | snd_hda_resume(chip->bus); |
@@ -1398,12 +1432,14 @@ static int azx_free(struct azx *chip) | |||
1398 | azx_writel(chip, DPLBASE, 0); | 1432 | azx_writel(chip, DPLBASE, 0); |
1399 | azx_writel(chip, DPUBASE, 0); | 1433 | azx_writel(chip, DPUBASE, 0); |
1400 | 1434 | ||
1401 | /* wait a little for interrupts to finish */ | 1435 | synchronize_irq(chip->irq); |
1402 | msleep(1); | ||
1403 | } | 1436 | } |
1404 | 1437 | ||
1405 | if (chip->irq >= 0) | 1438 | if (chip->irq >= 0) { |
1406 | free_irq(chip->irq, (void*)chip); | 1439 | free_irq(chip->irq, (void*)chip); |
1440 | if (!disable_msi) | ||
1441 | pci_disable_msi(chip->pci); | ||
1442 | } | ||
1407 | if (chip->remap_addr) | 1443 | if (chip->remap_addr) |
1408 | iounmap(chip->remap_addr); | 1444 | iounmap(chip->remap_addr); |
1409 | 1445 | ||
@@ -1434,19 +1470,19 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
1434 | struct azx **rchip) | 1470 | struct azx **rchip) |
1435 | { | 1471 | { |
1436 | struct azx *chip; | 1472 | struct azx *chip; |
1437 | int err = 0; | 1473 | int err; |
1438 | static struct snd_device_ops ops = { | 1474 | static struct snd_device_ops ops = { |
1439 | .dev_free = azx_dev_free, | 1475 | .dev_free = azx_dev_free, |
1440 | }; | 1476 | }; |
1441 | 1477 | ||
1442 | *rchip = NULL; | 1478 | *rchip = NULL; |
1443 | 1479 | ||
1444 | if ((err = pci_enable_device(pci)) < 0) | 1480 | err = pci_enable_device(pci); |
1481 | if (err < 0) | ||
1445 | return err; | 1482 | return err; |
1446 | 1483 | ||
1447 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); | 1484 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
1448 | 1485 | if (!chip) { | |
1449 | if (NULL == chip) { | ||
1450 | snd_printk(KERN_ERR SFX "cannot allocate chip\n"); | 1486 | snd_printk(KERN_ERR SFX "cannot allocate chip\n"); |
1451 | pci_disable_device(pci); | 1487 | pci_disable_device(pci); |
1452 | return -ENOMEM; | 1488 | return -ENOMEM; |
@@ -1472,13 +1508,14 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
1472 | } | 1508 | } |
1473 | #endif | 1509 | #endif |
1474 | 1510 | ||
1475 | if ((err = pci_request_regions(pci, "ICH HD audio")) < 0) { | 1511 | err = pci_request_regions(pci, "ICH HD audio"); |
1512 | if (err < 0) { | ||
1476 | kfree(chip); | 1513 | kfree(chip); |
1477 | pci_disable_device(pci); | 1514 | pci_disable_device(pci); |
1478 | return err; | 1515 | return err; |
1479 | } | 1516 | } |
1480 | 1517 | ||
1481 | chip->addr = pci_resource_start(pci,0); | 1518 | chip->addr = pci_resource_start(pci, 0); |
1482 | chip->remap_addr = ioremap_nocache(chip->addr, pci_resource_len(pci,0)); | 1519 | chip->remap_addr = ioremap_nocache(chip->addr, pci_resource_len(pci,0)); |
1483 | if (chip->remap_addr == NULL) { | 1520 | if (chip->remap_addr == NULL) { |
1484 | snd_printk(KERN_ERR SFX "ioremap error\n"); | 1521 | snd_printk(KERN_ERR SFX "ioremap error\n"); |
@@ -1486,6 +1523,9 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
1486 | goto errout; | 1523 | goto errout; |
1487 | } | 1524 | } |
1488 | 1525 | ||
1526 | if (!disable_msi) | ||
1527 | pci_enable_msi(pci); | ||
1528 | |||
1489 | if (request_irq(pci->irq, azx_interrupt, IRQF_DISABLED|IRQF_SHARED, | 1529 | if (request_irq(pci->irq, azx_interrupt, IRQF_DISABLED|IRQF_SHARED, |
1490 | "HDA Intel", (void*)chip)) { | 1530 | "HDA Intel", (void*)chip)) { |
1491 | snd_printk(KERN_ERR SFX "unable to grab IRQ %d\n", pci->irq); | 1531 | snd_printk(KERN_ERR SFX "unable to grab IRQ %d\n", pci->irq); |
@@ -1519,7 +1559,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
1519 | } | 1559 | } |
1520 | chip->num_streams = chip->playback_streams + chip->capture_streams; | 1560 | chip->num_streams = chip->playback_streams + chip->capture_streams; |
1521 | chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev), GFP_KERNEL); | 1561 | chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev), GFP_KERNEL); |
1522 | if (! chip->azx_dev) { | 1562 | if (!chip->azx_dev) { |
1523 | snd_printk(KERN_ERR "cannot malloc azx_dev\n"); | 1563 | snd_printk(KERN_ERR "cannot malloc azx_dev\n"); |
1524 | goto errout; | 1564 | goto errout; |
1525 | } | 1565 | } |
@@ -1550,7 +1590,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
1550 | chip->initialized = 1; | 1590 | chip->initialized = 1; |
1551 | 1591 | ||
1552 | /* codec detection */ | 1592 | /* codec detection */ |
1553 | if (! chip->codec_mask) { | 1593 | if (!chip->codec_mask) { |
1554 | snd_printk(KERN_ERR SFX "no codecs found!\n"); | 1594 | snd_printk(KERN_ERR SFX "no codecs found!\n"); |
1555 | err = -ENODEV; | 1595 | err = -ENODEV; |
1556 | goto errout; | 1596 | goto errout; |
@@ -1577,16 +1617,16 @@ static int __devinit azx_probe(struct pci_dev *pci, const struct pci_device_id * | |||
1577 | { | 1617 | { |
1578 | struct snd_card *card; | 1618 | struct snd_card *card; |
1579 | struct azx *chip; | 1619 | struct azx *chip; |
1580 | int err = 0; | 1620 | int err; |
1581 | 1621 | ||
1582 | card = snd_card_new(index, id, THIS_MODULE, 0); | 1622 | card = snd_card_new(index, id, THIS_MODULE, 0); |
1583 | if (NULL == card) { | 1623 | if (!card) { |
1584 | snd_printk(KERN_ERR SFX "Error creating card!\n"); | 1624 | snd_printk(KERN_ERR SFX "Error creating card!\n"); |
1585 | return -ENOMEM; | 1625 | return -ENOMEM; |
1586 | } | 1626 | } |
1587 | 1627 | ||
1588 | if ((err = azx_create(card, pci, pci_id->driver_data, | 1628 | err = azx_create(card, pci, pci_id->driver_data, &chip); |
1589 | &chip)) < 0) { | 1629 | if (err < 0) { |
1590 | snd_card_free(card); | 1630 | snd_card_free(card); |
1591 | return err; | 1631 | return err; |
1592 | } | 1632 | } |