diff options
Diffstat (limited to 'sound/pci/hda/hda_intel.c')
-rw-r--r-- | sound/pci/hda/hda_intel.c | 348 |
1 files changed, 176 insertions, 172 deletions
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 35722ec920cb..f04de115ee11 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c | |||
@@ -58,6 +58,7 @@ static char *model[SNDRV_CARDS]; | |||
58 | static int position_fix[SNDRV_CARDS]; | 58 | static int position_fix[SNDRV_CARDS]; |
59 | static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; | 59 | static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; |
60 | static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; | 60 | static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; |
61 | static int probe_only[SNDRV_CARDS]; | ||
61 | static int single_cmd; | 62 | static int single_cmd; |
62 | static int enable_msi; | 63 | static int enable_msi; |
63 | 64 | ||
@@ -76,6 +77,8 @@ module_param_array(bdl_pos_adj, int, NULL, 0644); | |||
76 | MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset."); | 77 | MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset."); |
77 | module_param_array(probe_mask, int, NULL, 0444); | 78 | module_param_array(probe_mask, int, NULL, 0444); |
78 | MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1)."); | 79 | MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1)."); |
80 | module_param_array(probe_only, bool, NULL, 0444); | ||
81 | MODULE_PARM_DESC(probe_only, "Only probing and no codec initialization."); | ||
79 | module_param(single_cmd, bool, 0444); | 82 | module_param(single_cmd, bool, 0444); |
80 | MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs " | 83 | MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs " |
81 | "(for debugging only)."); | 84 | "(for debugging only)."); |
@@ -83,7 +86,10 @@ module_param(enable_msi, int, 0444); | |||
83 | MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)"); | 86 | MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)"); |
84 | 87 | ||
85 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 88 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
86 | /* power_save option is defined in hda_codec.c */ | 89 | static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT; |
90 | module_param(power_save, int, 0644); | ||
91 | MODULE_PARM_DESC(power_save, "Automatic power-saving timeout " | ||
92 | "(in second, 0 = disable)."); | ||
87 | 93 | ||
88 | /* reset the HD-audio controller in power save mode. | 94 | /* reset the HD-audio controller in power save mode. |
89 | * this may give more power-saving, but will take longer time to | 95 | * this may give more power-saving, but will take longer time to |
@@ -292,6 +298,8 @@ enum { | |||
292 | /* Define VIA HD Audio Device ID*/ | 298 | /* Define VIA HD Audio Device ID*/ |
293 | #define VIA_HDAC_DEVICE_ID 0x3288 | 299 | #define VIA_HDAC_DEVICE_ID 0x3288 |
294 | 300 | ||
301 | /* HD Audio class code */ | ||
302 | #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403 | ||
295 | 303 | ||
296 | /* | 304 | /* |
297 | */ | 305 | */ |
@@ -392,6 +400,7 @@ struct azx { | |||
392 | unsigned int msi :1; | 400 | unsigned int msi :1; |
393 | unsigned int irq_pending_warned :1; | 401 | unsigned int irq_pending_warned :1; |
394 | unsigned int via_dmapos_patch :1; /* enable DMA-position fix for VIA */ | 402 | unsigned int via_dmapos_patch :1; /* enable DMA-position fix for VIA */ |
403 | unsigned int probing :1; /* codec probing phase */ | ||
395 | 404 | ||
396 | /* for debugging */ | 405 | /* for debugging */ |
397 | unsigned int last_cmd; /* last issued command (to sync) */ | 406 | unsigned int last_cmd; /* last issued command (to sync) */ |
@@ -414,6 +423,7 @@ enum { | |||
414 | AZX_DRIVER_ULI, | 423 | AZX_DRIVER_ULI, |
415 | AZX_DRIVER_NVIDIA, | 424 | AZX_DRIVER_NVIDIA, |
416 | AZX_DRIVER_TERA, | 425 | AZX_DRIVER_TERA, |
426 | AZX_DRIVER_GENERIC, | ||
417 | AZX_NUM_DRIVERS, /* keep this as last entry */ | 427 | AZX_NUM_DRIVERS, /* keep this as last entry */ |
418 | }; | 428 | }; |
419 | 429 | ||
@@ -427,6 +437,7 @@ static char *driver_short_names[] __devinitdata = { | |||
427 | [AZX_DRIVER_ULI] = "HDA ULI M5461", | 437 | [AZX_DRIVER_ULI] = "HDA ULI M5461", |
428 | [AZX_DRIVER_NVIDIA] = "HDA NVidia", | 438 | [AZX_DRIVER_NVIDIA] = "HDA NVidia", |
429 | [AZX_DRIVER_TERA] = "HDA Teradici", | 439 | [AZX_DRIVER_TERA] = "HDA Teradici", |
440 | [AZX_DRIVER_GENERIC] = "HD-Audio Generic", | ||
430 | }; | 441 | }; |
431 | 442 | ||
432 | /* | 443 | /* |
@@ -527,9 +538,9 @@ static void azx_free_cmd_io(struct azx *chip) | |||
527 | } | 538 | } |
528 | 539 | ||
529 | /* send a command */ | 540 | /* send a command */ |
530 | static int azx_corb_send_cmd(struct hda_codec *codec, u32 val) | 541 | static int azx_corb_send_cmd(struct hda_bus *bus, u32 val) |
531 | { | 542 | { |
532 | struct azx *chip = codec->bus->private_data; | 543 | struct azx *chip = bus->private_data; |
533 | unsigned int wp; | 544 | unsigned int wp; |
534 | 545 | ||
535 | /* add command to corb */ | 546 | /* add command to corb */ |
@@ -577,9 +588,9 @@ static void azx_update_rirb(struct azx *chip) | |||
577 | } | 588 | } |
578 | 589 | ||
579 | /* receive a response */ | 590 | /* receive a response */ |
580 | static unsigned int azx_rirb_get_response(struct hda_codec *codec) | 591 | static unsigned int azx_rirb_get_response(struct hda_bus *bus) |
581 | { | 592 | { |
582 | struct azx *chip = codec->bus->private_data; | 593 | struct azx *chip = bus->private_data; |
583 | unsigned long timeout; | 594 | unsigned long timeout; |
584 | 595 | ||
585 | again: | 596 | again: |
@@ -596,7 +607,7 @@ static unsigned int azx_rirb_get_response(struct hda_codec *codec) | |||
596 | } | 607 | } |
597 | if (time_after(jiffies, timeout)) | 608 | if (time_after(jiffies, timeout)) |
598 | break; | 609 | break; |
599 | if (codec->bus->needs_damn_long_delay) | 610 | if (bus->needs_damn_long_delay) |
600 | msleep(2); /* temporary workaround */ | 611 | msleep(2); /* temporary workaround */ |
601 | else { | 612 | else { |
602 | udelay(10); | 613 | udelay(10); |
@@ -624,6 +635,14 @@ static unsigned int azx_rirb_get_response(struct hda_codec *codec) | |||
624 | goto again; | 635 | goto again; |
625 | } | 636 | } |
626 | 637 | ||
638 | if (chip->probing) { | ||
639 | /* If this critical timeout happens during the codec probing | ||
640 | * phase, this is likely an access to a non-existing codec | ||
641 | * slot. Better to return an error and reset the system. | ||
642 | */ | ||
643 | return -1; | ||
644 | } | ||
645 | |||
627 | snd_printk(KERN_ERR "hda_intel: azx_get_response timeout, " | 646 | snd_printk(KERN_ERR "hda_intel: azx_get_response timeout, " |
628 | "switching to single_cmd mode: last cmd=0x%08x\n", | 647 | "switching to single_cmd mode: last cmd=0x%08x\n", |
629 | chip->last_cmd); | 648 | chip->last_cmd); |
@@ -646,9 +665,9 @@ static unsigned int azx_rirb_get_response(struct hda_codec *codec) | |||
646 | */ | 665 | */ |
647 | 666 | ||
648 | /* send a command */ | 667 | /* send a command */ |
649 | static int azx_single_send_cmd(struct hda_codec *codec, u32 val) | 668 | static int azx_single_send_cmd(struct hda_bus *bus, u32 val) |
650 | { | 669 | { |
651 | struct azx *chip = codec->bus->private_data; | 670 | struct azx *chip = bus->private_data; |
652 | int timeout = 50; | 671 | int timeout = 50; |
653 | 672 | ||
654 | while (timeout--) { | 673 | while (timeout--) { |
@@ -671,9 +690,9 @@ static int azx_single_send_cmd(struct hda_codec *codec, u32 val) | |||
671 | } | 690 | } |
672 | 691 | ||
673 | /* receive a response */ | 692 | /* receive a response */ |
674 | static unsigned int azx_single_get_response(struct hda_codec *codec) | 693 | static unsigned int azx_single_get_response(struct hda_bus *bus) |
675 | { | 694 | { |
676 | struct azx *chip = codec->bus->private_data; | 695 | struct azx *chip = bus->private_data; |
677 | int timeout = 50; | 696 | int timeout = 50; |
678 | 697 | ||
679 | while (timeout--) { | 698 | while (timeout--) { |
@@ -696,38 +715,29 @@ static unsigned int azx_single_get_response(struct hda_codec *codec) | |||
696 | */ | 715 | */ |
697 | 716 | ||
698 | /* send a command */ | 717 | /* send a command */ |
699 | static int azx_send_cmd(struct hda_codec *codec, hda_nid_t nid, | 718 | static int azx_send_cmd(struct hda_bus *bus, unsigned int val) |
700 | int direct, unsigned int verb, | ||
701 | unsigned int para) | ||
702 | { | 719 | { |
703 | struct azx *chip = codec->bus->private_data; | 720 | struct azx *chip = bus->private_data; |
704 | u32 val; | ||
705 | |||
706 | val = (u32)(codec->addr & 0x0f) << 28; | ||
707 | val |= (u32)direct << 27; | ||
708 | val |= (u32)nid << 20; | ||
709 | val |= verb << 8; | ||
710 | val |= para; | ||
711 | chip->last_cmd = val; | ||
712 | 721 | ||
722 | chip->last_cmd = val; | ||
713 | if (chip->single_cmd) | 723 | if (chip->single_cmd) |
714 | return azx_single_send_cmd(codec, val); | 724 | return azx_single_send_cmd(bus, val); |
715 | else | 725 | else |
716 | return azx_corb_send_cmd(codec, val); | 726 | return azx_corb_send_cmd(bus, val); |
717 | } | 727 | } |
718 | 728 | ||
719 | /* get a response */ | 729 | /* get a response */ |
720 | static unsigned int azx_get_response(struct hda_codec *codec) | 730 | static unsigned int azx_get_response(struct hda_bus *bus) |
721 | { | 731 | { |
722 | struct azx *chip = codec->bus->private_data; | 732 | struct azx *chip = bus->private_data; |
723 | if (chip->single_cmd) | 733 | if (chip->single_cmd) |
724 | return azx_single_get_response(codec); | 734 | return azx_single_get_response(bus); |
725 | else | 735 | else |
726 | return azx_rirb_get_response(codec); | 736 | return azx_rirb_get_response(bus); |
727 | } | 737 | } |
728 | 738 | ||
729 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 739 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
730 | static void azx_power_notify(struct hda_codec *codec); | 740 | static void azx_power_notify(struct hda_bus *bus); |
731 | #endif | 741 | #endif |
732 | 742 | ||
733 | /* reset codec link */ | 743 | /* reset codec link */ |
@@ -1184,6 +1194,28 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev) | |||
1184 | return 0; | 1194 | return 0; |
1185 | } | 1195 | } |
1186 | 1196 | ||
1197 | /* | ||
1198 | * Probe the given codec address | ||
1199 | */ | ||
1200 | static int probe_codec(struct azx *chip, int addr) | ||
1201 | { | ||
1202 | unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) | | ||
1203 | (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; | ||
1204 | unsigned int res; | ||
1205 | |||
1206 | chip->probing = 1; | ||
1207 | azx_send_cmd(chip->bus, cmd); | ||
1208 | res = azx_get_response(chip->bus); | ||
1209 | chip->probing = 0; | ||
1210 | if (res == -1) | ||
1211 | return -EIO; | ||
1212 | snd_printdd("hda_intel: codec #%d probed OK\n", addr); | ||
1213 | return 0; | ||
1214 | } | ||
1215 | |||
1216 | static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, | ||
1217 | struct hda_pcm *cpcm); | ||
1218 | static void azx_stop_chip(struct azx *chip); | ||
1187 | 1219 | ||
1188 | /* | 1220 | /* |
1189 | * Codec initialization | 1221 | * Codec initialization |
@@ -1194,21 +1226,13 @@ static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] __devinitdata = { | |||
1194 | [AZX_DRIVER_TERA] = 1, | 1226 | [AZX_DRIVER_TERA] = 1, |
1195 | }; | 1227 | }; |
1196 | 1228 | ||
1197 | /* number of slots to probe as default | ||
1198 | * this can be different from azx_max_codecs[] -- e.g. some boards | ||
1199 | * report wrongly the non-existing 4th slot availability | ||
1200 | */ | ||
1201 | static unsigned int azx_default_codecs[AZX_NUM_DRIVERS] __devinitdata = { | ||
1202 | [AZX_DRIVER_ICH] = 3, | ||
1203 | [AZX_DRIVER_ATI] = 3, | ||
1204 | }; | ||
1205 | |||
1206 | static int __devinit azx_codec_create(struct azx *chip, const char *model, | 1229 | static int __devinit azx_codec_create(struct azx *chip, const char *model, |
1207 | unsigned int codec_probe_mask) | 1230 | unsigned int codec_probe_mask, |
1231 | int no_init) | ||
1208 | { | 1232 | { |
1209 | struct hda_bus_template bus_temp; | 1233 | struct hda_bus_template bus_temp; |
1210 | int c, codecs, audio_codecs, err; | 1234 | int c, codecs, err; |
1211 | int def_slots, max_slots; | 1235 | int max_slots; |
1212 | 1236 | ||
1213 | memset(&bus_temp, 0, sizeof(bus_temp)); | 1237 | memset(&bus_temp, 0, sizeof(bus_temp)); |
1214 | bus_temp.private_data = chip; | 1238 | bus_temp.private_data = chip; |
@@ -1216,7 +1240,9 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model, | |||
1216 | bus_temp.pci = chip->pci; | 1240 | bus_temp.pci = chip->pci; |
1217 | bus_temp.ops.command = azx_send_cmd; | 1241 | bus_temp.ops.command = azx_send_cmd; |
1218 | bus_temp.ops.get_response = azx_get_response; | 1242 | bus_temp.ops.get_response = azx_get_response; |
1243 | bus_temp.ops.attach_pcm = azx_attach_pcm_stream; | ||
1219 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 1244 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1245 | bus_temp.power_save = &power_save; | ||
1220 | bus_temp.ops.pm_notify = azx_power_notify; | 1246 | bus_temp.ops.pm_notify = azx_power_notify; |
1221 | #endif | 1247 | #endif |
1222 | 1248 | ||
@@ -1227,33 +1253,43 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model, | |||
1227 | if (chip->driver_type == AZX_DRIVER_NVIDIA) | 1253 | if (chip->driver_type == AZX_DRIVER_NVIDIA) |
1228 | chip->bus->needs_damn_long_delay = 1; | 1254 | chip->bus->needs_damn_long_delay = 1; |
1229 | 1255 | ||
1230 | codecs = audio_codecs = 0; | 1256 | codecs = 0; |
1231 | max_slots = azx_max_codecs[chip->driver_type]; | 1257 | max_slots = azx_max_codecs[chip->driver_type]; |
1232 | if (!max_slots) | 1258 | if (!max_slots) |
1233 | max_slots = AZX_MAX_CODECS; | 1259 | max_slots = AZX_MAX_CODECS; |
1234 | def_slots = azx_default_codecs[chip->driver_type]; | 1260 | |
1235 | if (!def_slots) | 1261 | /* First try to probe all given codec slots */ |
1236 | def_slots = max_slots; | 1262 | for (c = 0; c < max_slots; c++) { |
1237 | for (c = 0; c < def_slots; c++) { | 1263 | if ((chip->codec_mask & (1 << c)) & codec_probe_mask) { |
1264 | if (probe_codec(chip, c) < 0) { | ||
1265 | /* Some BIOSen give you wrong codec addresses | ||
1266 | * that don't exist | ||
1267 | */ | ||
1268 | snd_printk(KERN_WARNING | ||
1269 | "hda_intel: Codec #%d probe error; " | ||
1270 | "disabling it...\n", c); | ||
1271 | chip->codec_mask &= ~(1 << c); | ||
1272 | /* More badly, accessing to a non-existing | ||
1273 | * codec often screws up the controller chip, | ||
1274 | * and distrubs the further communications. | ||
1275 | * Thus if an error occurs during probing, | ||
1276 | * better to reset the controller chip to | ||
1277 | * get back to the sanity state. | ||
1278 | */ | ||
1279 | azx_stop_chip(chip); | ||
1280 | azx_init_chip(chip); | ||
1281 | } | ||
1282 | } | ||
1283 | } | ||
1284 | |||
1285 | /* Then create codec instances */ | ||
1286 | for (c = 0; c < max_slots; c++) { | ||
1238 | if ((chip->codec_mask & (1 << c)) & codec_probe_mask) { | 1287 | if ((chip->codec_mask & (1 << c)) & codec_probe_mask) { |
1239 | struct hda_codec *codec; | 1288 | struct hda_codec *codec; |
1240 | err = snd_hda_codec_new(chip->bus, c, &codec); | 1289 | err = snd_hda_codec_new(chip->bus, c, !no_init, &codec); |
1241 | if (err < 0) | 1290 | if (err < 0) |
1242 | continue; | 1291 | continue; |
1243 | codecs++; | 1292 | codecs++; |
1244 | if (codec->afg) | ||
1245 | audio_codecs++; | ||
1246 | } | ||
1247 | } | ||
1248 | if (!audio_codecs) { | ||
1249 | /* probe additional slots if no codec is found */ | ||
1250 | for (; c < max_slots; c++) { | ||
1251 | if ((chip->codec_mask & (1 << c)) & codec_probe_mask) { | ||
1252 | err = snd_hda_codec_new(chip->bus, c, NULL); | ||
1253 | if (err < 0) | ||
1254 | continue; | ||
1255 | codecs++; | ||
1256 | } | ||
1257 | } | 1293 | } |
1258 | } | 1294 | } |
1259 | if (!codecs) { | 1295 | if (!codecs) { |
@@ -1722,111 +1758,59 @@ static struct snd_pcm_ops azx_pcm_ops = { | |||
1722 | 1758 | ||
1723 | static void azx_pcm_free(struct snd_pcm *pcm) | 1759 | static void azx_pcm_free(struct snd_pcm *pcm) |
1724 | { | 1760 | { |
1725 | kfree(pcm->private_data); | 1761 | struct azx_pcm *apcm = pcm->private_data; |
1762 | if (apcm) { | ||
1763 | apcm->chip->pcm[pcm->device] = NULL; | ||
1764 | kfree(apcm); | ||
1765 | } | ||
1726 | } | 1766 | } |
1727 | 1767 | ||
1728 | static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec, | 1768 | static int |
1729 | struct hda_pcm *cpcm) | 1769 | azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, |
1770 | struct hda_pcm *cpcm) | ||
1730 | { | 1771 | { |
1731 | int err; | 1772 | struct azx *chip = bus->private_data; |
1732 | struct snd_pcm *pcm; | 1773 | struct snd_pcm *pcm; |
1733 | struct azx_pcm *apcm; | 1774 | struct azx_pcm *apcm; |
1775 | int pcm_dev = cpcm->device; | ||
1776 | int s, err; | ||
1734 | 1777 | ||
1735 | /* if no substreams are defined for both playback and capture, | 1778 | if (pcm_dev >= AZX_MAX_PCMS) { |
1736 | * it's just a placeholder. ignore it. | 1779 | snd_printk(KERN_ERR SFX "Invalid PCM device number %d\n", |
1737 | */ | 1780 | pcm_dev); |
1738 | if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams) | ||
1739 | return 0; | ||
1740 | |||
1741 | if (snd_BUG_ON(!cpcm->name)) | ||
1742 | return -EINVAL; | 1781 | return -EINVAL; |
1743 | 1782 | } | |
1744 | err = snd_pcm_new(chip->card, cpcm->name, cpcm->device, | 1783 | if (chip->pcm[pcm_dev]) { |
1745 | cpcm->stream[0].substreams, | 1784 | snd_printk(KERN_ERR SFX "PCM %d already exists\n", pcm_dev); |
1746 | cpcm->stream[1].substreams, | 1785 | return -EBUSY; |
1786 | } | ||
1787 | err = snd_pcm_new(chip->card, cpcm->name, pcm_dev, | ||
1788 | cpcm->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams, | ||
1789 | cpcm->stream[SNDRV_PCM_STREAM_CAPTURE].substreams, | ||
1747 | &pcm); | 1790 | &pcm); |
1748 | if (err < 0) | 1791 | if (err < 0) |
1749 | return err; | 1792 | return err; |
1750 | strcpy(pcm->name, cpcm->name); | 1793 | strcpy(pcm->name, cpcm->name); |
1751 | apcm = kmalloc(sizeof(*apcm), GFP_KERNEL); | 1794 | apcm = kzalloc(sizeof(*apcm), GFP_KERNEL); |
1752 | if (apcm == NULL) | 1795 | if (apcm == NULL) |
1753 | return -ENOMEM; | 1796 | return -ENOMEM; |
1754 | apcm->chip = chip; | 1797 | apcm->chip = chip; |
1755 | apcm->codec = codec; | 1798 | apcm->codec = codec; |
1756 | apcm->hinfo[0] = &cpcm->stream[0]; | ||
1757 | apcm->hinfo[1] = &cpcm->stream[1]; | ||
1758 | pcm->private_data = apcm; | 1799 | pcm->private_data = apcm; |
1759 | pcm->private_free = azx_pcm_free; | 1800 | pcm->private_free = azx_pcm_free; |
1760 | if (cpcm->stream[0].substreams) | 1801 | if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM) |
1761 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &azx_pcm_ops); | 1802 | pcm->dev_class = SNDRV_PCM_CLASS_MODEM; |
1762 | if (cpcm->stream[1].substreams) | 1803 | chip->pcm[pcm_dev] = pcm; |
1763 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &azx_pcm_ops); | 1804 | cpcm->pcm = pcm; |
1805 | for (s = 0; s < 2; s++) { | ||
1806 | apcm->hinfo[s] = &cpcm->stream[s]; | ||
1807 | if (cpcm->stream[s].substreams) | ||
1808 | snd_pcm_set_ops(pcm, s, &azx_pcm_ops); | ||
1809 | } | ||
1810 | /* buffer pre-allocation */ | ||
1764 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, | 1811 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, |
1765 | snd_dma_pci_data(chip->pci), | 1812 | snd_dma_pci_data(chip->pci), |
1766 | 1024 * 64, 32 * 1024 * 1024); | 1813 | 1024 * 64, 32 * 1024 * 1024); |
1767 | chip->pcm[cpcm->device] = pcm; | ||
1768 | return 0; | ||
1769 | } | ||
1770 | |||
1771 | static int __devinit azx_pcm_create(struct azx *chip) | ||
1772 | { | ||
1773 | static const char *dev_name[HDA_PCM_NTYPES] = { | ||
1774 | "Audio", "SPDIF", "HDMI", "Modem" | ||
1775 | }; | ||
1776 | /* starting device index for each PCM type */ | ||
1777 | static int dev_idx[HDA_PCM_NTYPES] = { | ||
1778 | [HDA_PCM_TYPE_AUDIO] = 0, | ||
1779 | [HDA_PCM_TYPE_SPDIF] = 1, | ||
1780 | [HDA_PCM_TYPE_HDMI] = 3, | ||
1781 | [HDA_PCM_TYPE_MODEM] = 6 | ||
1782 | }; | ||
1783 | /* normal audio device indices; not linear to keep compatibility */ | ||
1784 | static int audio_idx[4] = { 0, 2, 4, 5 }; | ||
1785 | struct hda_codec *codec; | ||
1786 | int c, err; | ||
1787 | int num_devs[HDA_PCM_NTYPES]; | ||
1788 | |||
1789 | err = snd_hda_build_pcms(chip->bus); | ||
1790 | if (err < 0) | ||
1791 | return err; | ||
1792 | |||
1793 | /* create audio PCMs */ | ||
1794 | memset(num_devs, 0, sizeof(num_devs)); | ||
1795 | list_for_each_entry(codec, &chip->bus->codec_list, list) { | ||
1796 | for (c = 0; c < codec->num_pcms; c++) { | ||
1797 | struct hda_pcm *cpcm = &codec->pcm_info[c]; | ||
1798 | int type = cpcm->pcm_type; | ||
1799 | switch (type) { | ||
1800 | case HDA_PCM_TYPE_AUDIO: | ||
1801 | if (num_devs[type] >= ARRAY_SIZE(audio_idx)) { | ||
1802 | snd_printk(KERN_WARNING | ||
1803 | "Too many audio devices\n"); | ||
1804 | continue; | ||
1805 | } | ||
1806 | cpcm->device = audio_idx[num_devs[type]]; | ||
1807 | break; | ||
1808 | case HDA_PCM_TYPE_SPDIF: | ||
1809 | case HDA_PCM_TYPE_HDMI: | ||
1810 | case HDA_PCM_TYPE_MODEM: | ||
1811 | if (num_devs[type]) { | ||
1812 | snd_printk(KERN_WARNING | ||
1813 | "%s already defined\n", | ||
1814 | dev_name[type]); | ||
1815 | continue; | ||
1816 | } | ||
1817 | cpcm->device = dev_idx[type]; | ||
1818 | break; | ||
1819 | default: | ||
1820 | snd_printk(KERN_WARNING | ||
1821 | "Invalid PCM type %d\n", type); | ||
1822 | continue; | ||
1823 | } | ||
1824 | num_devs[type]++; | ||
1825 | err = create_codec_pcm(chip, codec, cpcm); | ||
1826 | if (err < 0) | ||
1827 | return err; | ||
1828 | } | ||
1829 | } | ||
1830 | return 0; | 1814 | return 0; |
1831 | } | 1815 | } |
1832 | 1816 | ||
@@ -1903,13 +1887,13 @@ static void azx_stop_chip(struct azx *chip) | |||
1903 | 1887 | ||
1904 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 1888 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1905 | /* power-up/down the controller */ | 1889 | /* power-up/down the controller */ |
1906 | static void azx_power_notify(struct hda_codec *codec) | 1890 | static void azx_power_notify(struct hda_bus *bus) |
1907 | { | 1891 | { |
1908 | struct azx *chip = codec->bus->private_data; | 1892 | struct azx *chip = bus->private_data; |
1909 | struct hda_codec *c; | 1893 | struct hda_codec *c; |
1910 | int power_on = 0; | 1894 | int power_on = 0; |
1911 | 1895 | ||
1912 | list_for_each_entry(c, &codec->bus->codec_list, list) { | 1896 | list_for_each_entry(c, &bus->codec_list, list) { |
1913 | if (c->power_on) { | 1897 | if (c->power_on) { |
1914 | power_on = 1; | 1898 | power_on = 1; |
1915 | break; | 1899 | break; |
@@ -1926,6 +1910,18 @@ static void azx_power_notify(struct hda_codec *codec) | |||
1926 | /* | 1910 | /* |
1927 | * power management | 1911 | * power management |
1928 | */ | 1912 | */ |
1913 | |||
1914 | static int snd_hda_codecs_inuse(struct hda_bus *bus) | ||
1915 | { | ||
1916 | struct hda_codec *codec; | ||
1917 | |||
1918 | list_for_each_entry(codec, &bus->codec_list, list) { | ||
1919 | if (snd_hda_codec_needs_resume(codec)) | ||
1920 | return 1; | ||
1921 | } | ||
1922 | return 0; | ||
1923 | } | ||
1924 | |||
1929 | static int azx_suspend(struct pci_dev *pci, pm_message_t state) | 1925 | static int azx_suspend(struct pci_dev *pci, pm_message_t state) |
1930 | { | 1926 | { |
1931 | struct snd_card *card = pci_get_drvdata(pci); | 1927 | struct snd_card *card = pci_get_drvdata(pci); |
@@ -1951,13 +1947,16 @@ static int azx_suspend(struct pci_dev *pci, pm_message_t state) | |||
1951 | return 0; | 1947 | return 0; |
1952 | } | 1948 | } |
1953 | 1949 | ||
1950 | static int azx_resume_early(struct pci_dev *pci) | ||
1951 | { | ||
1952 | return pci_restore_state(pci); | ||
1953 | } | ||
1954 | |||
1954 | static int azx_resume(struct pci_dev *pci) | 1955 | static int azx_resume(struct pci_dev *pci) |
1955 | { | 1956 | { |
1956 | struct snd_card *card = pci_get_drvdata(pci); | 1957 | struct snd_card *card = pci_get_drvdata(pci); |
1957 | struct azx *chip = card->private_data; | 1958 | struct azx *chip = card->private_data; |
1958 | 1959 | ||
1959 | pci_set_power_state(pci, PCI_D0); | ||
1960 | pci_restore_state(pci); | ||
1961 | if (pci_enable_device(pci) < 0) { | 1960 | if (pci_enable_device(pci) < 0) { |
1962 | printk(KERN_ERR "hda-intel: pci_enable_device failed, " | 1961 | printk(KERN_ERR "hda-intel: pci_enable_device failed, " |
1963 | "disabling device\n"); | 1962 | "disabling device\n"); |
@@ -2095,6 +2094,10 @@ static struct snd_pci_quirk probe_mask_list[] __devinitdata = { | |||
2095 | SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01), | 2094 | SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01), |
2096 | SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01), | 2095 | SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01), |
2097 | SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01), | 2096 | SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01), |
2097 | /* broken BIOS */ | ||
2098 | SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01), | ||
2099 | /* including bogus ALC268 in slot#2 that conflicts with ALC888 */ | ||
2100 | SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01), | ||
2098 | {} | 2101 | {} |
2099 | }; | 2102 | }; |
2100 | 2103 | ||
@@ -2229,6 +2232,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
2229 | chip->playback_streams = ATIHDMI_NUM_PLAYBACK; | 2232 | chip->playback_streams = ATIHDMI_NUM_PLAYBACK; |
2230 | chip->capture_streams = ATIHDMI_NUM_CAPTURE; | 2233 | chip->capture_streams = ATIHDMI_NUM_CAPTURE; |
2231 | break; | 2234 | break; |
2235 | case AZX_DRIVER_GENERIC: | ||
2232 | default: | 2236 | default: |
2233 | chip->playback_streams = ICH6_NUM_PLAYBACK; | 2237 | chip->playback_streams = ICH6_NUM_PLAYBACK; |
2234 | chip->capture_streams = ICH6_NUM_CAPTURE; | 2238 | chip->capture_streams = ICH6_NUM_CAPTURE; |
@@ -2338,40 +2342,31 @@ static int __devinit azx_probe(struct pci_dev *pci, | |||
2338 | } | 2342 | } |
2339 | 2343 | ||
2340 | err = azx_create(card, pci, dev, pci_id->driver_data, &chip); | 2344 | err = azx_create(card, pci, dev, pci_id->driver_data, &chip); |
2341 | if (err < 0) { | 2345 | if (err < 0) |
2342 | snd_card_free(card); | 2346 | goto out_free; |
2343 | return err; | ||
2344 | } | ||
2345 | card->private_data = chip; | 2347 | card->private_data = chip; |
2346 | 2348 | ||
2347 | /* create codec instances */ | 2349 | /* create codec instances */ |
2348 | err = azx_codec_create(chip, model[dev], probe_mask[dev]); | 2350 | err = azx_codec_create(chip, model[dev], probe_mask[dev], |
2349 | if (err < 0) { | 2351 | probe_only[dev]); |
2350 | snd_card_free(card); | 2352 | if (err < 0) |
2351 | return err; | 2353 | goto out_free; |
2352 | } | ||
2353 | 2354 | ||
2354 | /* create PCM streams */ | 2355 | /* create PCM streams */ |
2355 | err = azx_pcm_create(chip); | 2356 | err = snd_hda_build_pcms(chip->bus); |
2356 | if (err < 0) { | 2357 | if (err < 0) |
2357 | snd_card_free(card); | 2358 | goto out_free; |
2358 | return err; | ||
2359 | } | ||
2360 | 2359 | ||
2361 | /* create mixer controls */ | 2360 | /* create mixer controls */ |
2362 | err = azx_mixer_create(chip); | 2361 | err = azx_mixer_create(chip); |
2363 | if (err < 0) { | 2362 | if (err < 0) |
2364 | snd_card_free(card); | 2363 | goto out_free; |
2365 | return err; | ||
2366 | } | ||
2367 | 2364 | ||
2368 | snd_card_set_dev(card, &pci->dev); | 2365 | snd_card_set_dev(card, &pci->dev); |
2369 | 2366 | ||
2370 | err = snd_card_register(card); | 2367 | err = snd_card_register(card); |
2371 | if (err < 0) { | 2368 | if (err < 0) |
2372 | snd_card_free(card); | 2369 | goto out_free; |
2373 | return err; | ||
2374 | } | ||
2375 | 2370 | ||
2376 | pci_set_drvdata(pci, card); | 2371 | pci_set_drvdata(pci, card); |
2377 | chip->running = 1; | 2372 | chip->running = 1; |
@@ -2380,6 +2375,9 @@ static int __devinit azx_probe(struct pci_dev *pci, | |||
2380 | 2375 | ||
2381 | dev++; | 2376 | dev++; |
2382 | return err; | 2377 | return err; |
2378 | out_free: | ||
2379 | snd_card_free(card); | ||
2380 | return err; | ||
2383 | } | 2381 | } |
2384 | 2382 | ||
2385 | static void __devexit azx_remove(struct pci_dev *pci) | 2383 | static void __devexit azx_remove(struct pci_dev *pci) |
@@ -2453,6 +2451,11 @@ static struct pci_device_id azx_ids[] = { | |||
2453 | { PCI_DEVICE(0x10de, 0x0bd7), .driver_data = AZX_DRIVER_NVIDIA }, | 2451 | { PCI_DEVICE(0x10de, 0x0bd7), .driver_data = AZX_DRIVER_NVIDIA }, |
2454 | /* Teradici */ | 2452 | /* Teradici */ |
2455 | { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA }, | 2453 | { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA }, |
2454 | /* AMD Generic, PCI class code and Vendor ID for HD Audio */ | ||
2455 | { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID), | ||
2456 | .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, | ||
2457 | .class_mask = 0xffffff, | ||
2458 | .driver_data = AZX_DRIVER_GENERIC }, | ||
2456 | { 0, } | 2459 | { 0, } |
2457 | }; | 2460 | }; |
2458 | MODULE_DEVICE_TABLE(pci, azx_ids); | 2461 | MODULE_DEVICE_TABLE(pci, azx_ids); |
@@ -2465,6 +2468,7 @@ static struct pci_driver driver = { | |||
2465 | .remove = __devexit_p(azx_remove), | 2468 | .remove = __devexit_p(azx_remove), |
2466 | #ifdef CONFIG_PM | 2469 | #ifdef CONFIG_PM |
2467 | .suspend = azx_suspend, | 2470 | .suspend = azx_suspend, |
2471 | .resume_early = azx_resume_early, | ||
2468 | .resume = azx_resume, | 2472 | .resume = azx_resume, |
2469 | #endif | 2473 | #endif |
2470 | }; | 2474 | }; |