Lines Matching +full:pch +full:- +full:msi +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * hda_intel.c - Implementation of primary alsa driver code base
27 #include <linux/dma-mapping.h>
51 #include <sound/intel-dsp-config.h>
54 #include <linux/apple-gmux.h>
109 static int position_fix[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
110 static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
111 static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
114 static int single_cmd = -1;
115 static int enable_msi = -1;
120 static bool beep_mode[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] =
123 static bool dmic_detect = 1;
124 static bool ctl_dev_id = IS_ENABLED(CONFIG_SND_HDA_CTL_DEV_ID) ? 1 : 0;
136 …"(-1 = system default, 0 = auto, 1 = LPIB, 2 = POSBUF, 3 = VIACOMBO, 4 = COMBO, 5 = SKL+, 6 = FIFO…
140 MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1).");
149 MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)");
157 "(0=off, 1=on) (default=1).");
161 "(0=off, 1=on) (default=1); "
162 "deprecated, use snd-intel-dspcfg.dsp_driver option instead");
176 MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
179 static int pm_blacklist = -1;
181 MODULE_PARM_DESC(pm_blacklist, "Enable power-management denylist");
183 /* reset the HD-audio controller in power save mode.
184 * this may give more power-saving, but will take longer time to
187 static bool power_save_controller = 1;
196 static int align_buffer_size = -1;
202 static int hda_snoop = -1;
249 (((chip)->driver_caps & AZX_DCAPS_SNOOP_MASK) >> 10)
256 /* quirks for Intel PCH */
261 /* PCH up to IVB; no runtime PM; bind with i915 gfx */
265 /* PCH for HSW/BDW; with runtime PM */
332 #define use_vga_switcheroo(chip) ((chip)->use_vga_switcheroo)
333 #define needs_eld_notify_link(chip) ((chip)->bus.keep_power)
341 [AZX_DRIVER_PCH] = "HDA Intel PCH",
343 [AZX_DRIVER_SKL] = "HDA Intel PCH", /* kept old name for compatibility */
356 [AZX_DRIVER_CMEDIA] = "HDA C-Media",
359 [AZX_DRIVER_GENERIC] = "HD-Audio Generic",
384 /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44) in azx_init_pci()
390 if (!(chip->driver_caps & AZX_DCAPS_NO_TCSEL)) { in azx_init_pci()
391 dev_dbg(chip->card->dev, "Clearing TCSEL\n"); in azx_init_pci()
392 update_pci_byte(chip->pci, AZX_PCIREG_TCSEL, 0x07, 0); in azx_init_pci()
399 dev_dbg(chip->card->dev, "Setting ATI snoop: %d\n", in azx_init_pci()
401 update_pci_byte(chip->pci, in azx_init_pci()
408 dev_dbg(chip->card->dev, "Setting Nvidia snoop: %d\n", in azx_init_pci()
410 update_pci_byte(chip->pci, in azx_init_pci()
413 update_pci_byte(chip->pci, in azx_init_pci()
416 update_pci_byte(chip->pci, in azx_init_pci()
421 /* Enable SCH/PCH snoop if needed */ in azx_init_pci()
424 pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop); in azx_init_pci()
430 pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC, snoop); in azx_init_pci()
431 pci_read_config_word(chip->pci, in azx_init_pci()
434 dev_dbg(chip->card->dev, "SCH snoop: %s\n", in azx_init_pci()
441 * In BXT-P A0, HD-Audio DMA requests is later than expected,
459 * bit 1: 12 MHz Supported
468 static const int preferred_bits[] = { 2, 3, 1, 4, 5 }; in intel_get_lctl_scf()
472 val = readl(bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCAP); in intel_get_lctl_scf()
476 if (val & (1 << t)) in intel_get_lctl_scf()
480 dev_warn(chip->card->dev, "set audio clock frequency to 6MHz"); in intel_get_lctl_scf()
491 * Changes to LCTL.SCF are only needed for the first multi-link dealing in intel_ml_lctl_set_power()
494 val = readl(bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCTL); in intel_ml_lctl_set_power()
497 writel(val, bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCTL); in intel_ml_lctl_set_power()
501 if (((readl(bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCTL)) & in intel_ml_lctl_set_power()
504 timeout--; in intel_ml_lctl_set_power()
508 return -1; in intel_ml_lctl_set_power()
518 val = readl(bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCTL); in intel_init_lctl()
531 /* 1. turn link down: set SPA to 0 and wait CPA to 0 */ in intel_init_lctl()
540 writel(val, bus->mlcap + AZX_ML_BASE + AZX_REG_ML_LCTL); in intel_init_lctl()
543 /* 4. turn link up: set SPA to 1 and wait CPA to 1 */ in intel_init_lctl()
544 intel_ml_lctl_set_power(chip, 1); in intel_init_lctl()
551 struct pci_dev *pci = chip->pci; in hda_intel_init_chip()
555 if (chip->driver_type == AZX_DRIVER_SKL) { in hda_intel_init_chip()
561 if (chip->driver_type == AZX_DRIVER_SKL) { in hda_intel_init_chip()
573 if (bus->mlcap != NULL) in hda_intel_init_chip()
581 struct snd_pcm_substream *substream = azx_dev->core.substream; in azx_get_delay_from_lpib()
582 int stream = substream->stream; in azx_get_delay_from_lpib()
587 delay = pos - lpib_pos; in azx_get_delay_from_lpib()
589 delay = lpib_pos - pos; in azx_get_delay_from_lpib()
591 if (delay >= azx_dev->core.delay_negative_threshold) in azx_get_delay_from_lpib()
594 delay += azx_dev->core.bufsize; in azx_get_delay_from_lpib()
597 if (delay >= azx_dev->core.period_bytes) { in azx_get_delay_from_lpib()
598 dev_info(chip->card->dev, in azx_get_delay_from_lpib()
600 delay, azx_dev->core.period_bytes); in azx_get_delay_from_lpib()
602 chip->driver_caps &= ~AZX_DCAPS_COUNT_LPIB_DELAY; in azx_get_delay_from_lpib()
603 chip->get_delay[stream] = NULL; in azx_get_delay_from_lpib()
606 return bytes_to_frames(substream->runtime, delay); in azx_get_delay_from_lpib()
618 if (ok == 1) { in azx_position_check()
619 azx_dev->irq_pending = 0; in azx_position_check()
623 azx_dev->irq_pending = 1; in azx_position_check()
624 schedule_work(&hda->irq_pending_work); in azx_position_check()
634 * periods. Returns non-zero if it's OK.
636 * Many HD-audio controllers appear pretty inaccurate about
637 * the update-IRQ timing. The IRQ is issued before actually the
641 * Returns 1 if OK to proceed, 0 for delay handling, -1 for skipping update
645 struct snd_pcm_substream *substream = azx_dev->core.substream; in azx_position_ok()
646 struct snd_pcm_runtime *runtime = substream->runtime; in azx_position_ok()
647 int stream = substream->stream; in azx_position_ok()
656 if (chip->driver_type == AZX_DRIVER_LOONGSON) in azx_position_ok()
657 return 1; in azx_position_ok()
659 wallclk = azx_readl(chip, WALLCLK) - azx_dev->core.start_wallclk; in azx_position_ok()
660 if (wallclk < (azx_dev->core.period_wallclk * 2) / 3) in azx_position_ok()
661 return -1; /* bogus (too early) interrupt */ in azx_position_ok()
663 if (chip->get_position[stream]) in azx_position_ok()
664 pos = chip->get_position[stream](chip, azx_dev); in azx_position_ok()
667 if (!pos || pos == (u32)-1) { in azx_position_ok()
668 dev_info(chip->card->dev, in azx_position_ok()
670 chip->get_position[stream] = azx_get_pos_lpib; in azx_position_ok()
671 if (chip->get_position[0] == azx_get_pos_lpib && in azx_position_ok()
672 chip->get_position[1] == azx_get_pos_lpib) in azx_position_ok()
673 azx_bus(chip)->use_posbuf = false; in azx_position_ok()
675 chip->get_delay[stream] = NULL; in azx_position_ok()
677 chip->get_position[stream] = azx_get_pos_posbuf; in azx_position_ok()
678 if (chip->driver_caps & AZX_DCAPS_COUNT_LPIB_DELAY) in azx_position_ok()
679 chip->get_delay[stream] = azx_get_delay_from_lpib; in azx_position_ok()
683 if (pos >= azx_dev->core.bufsize) in azx_position_ok()
686 if (WARN_ONCE(!azx_dev->core.period_bytes, in azx_position_ok()
687 "hda-intel: zero azx_dev->period_bytes")) in azx_position_ok()
688 return -1; /* this shouldn't happen! */ in azx_position_ok()
689 if (wallclk < (azx_dev->core.period_wallclk * 5) / 4 && in azx_position_ok()
690 pos % azx_dev->core.period_bytes > azx_dev->core.period_bytes / 2) in azx_position_ok()
691 /* NG - it's below the first next period boundary */ in azx_position_ok()
692 return chip->bdl_pos_adj ? 0 : -1; in azx_position_ok()
693 azx_dev->core.start_wallclk += wallclk; in azx_position_ok()
695 if (azx_dev->core.no_period_wakeup) in azx_position_ok()
696 return 1; /* OK, no need to check period boundary */ in azx_position_ok()
698 if (runtime->hw_ptr_base != runtime->hw_ptr_interrupt) in azx_position_ok()
699 return 1; /* OK, already in hwptr updating process */ in azx_position_ok()
703 hwptr = runtime->hw_ptr_base + pos; in azx_position_ok()
704 if (hwptr < runtime->status->hw_ptr) in azx_position_ok()
705 hwptr += runtime->buffer_size; in azx_position_ok()
706 target = runtime->hw_ptr_interrupt + runtime->period_size; in azx_position_ok()
709 return chip->bdl_pos_adj ? 0 : -1; in azx_position_ok()
712 return 1; /* OK, it's fine */ in azx_position_ok()
721 struct azx *chip = &hda->chip; in azx_irq_pending_work()
726 if (!hda->irq_pending_warned) { in azx_irq_pending_work()
727 dev_info(chip->card->dev, in azx_irq_pending_work()
729 chip->card->number); in azx_irq_pending_work()
730 hda->irq_pending_warned = 1; in azx_irq_pending_work()
735 spin_lock_irq(&bus->reg_lock); in azx_irq_pending_work()
736 list_for_each_entry(s, &bus->stream_list, list) { in azx_irq_pending_work()
738 if (!azx_dev->irq_pending || in azx_irq_pending_work()
739 !s->substream || in azx_irq_pending_work()
740 !s->running) in azx_irq_pending_work()
744 azx_dev->irq_pending = 0; in azx_irq_pending_work()
745 spin_unlock(&bus->reg_lock); in azx_irq_pending_work()
746 snd_pcm_period_elapsed(s->substream); in azx_irq_pending_work()
747 spin_lock(&bus->reg_lock); in azx_irq_pending_work()
753 spin_unlock_irq(&bus->reg_lock); in azx_irq_pending_work()
756 msleep(1); in azx_irq_pending_work()
760 /* clear irq_pending flags and assure no on-going workq */
766 spin_lock_irq(&bus->reg_lock); in azx_clear_irq_pending()
767 list_for_each_entry(s, &bus->stream_list, list) { in azx_clear_irq_pending()
769 azx_dev->irq_pending = 0; in azx_clear_irq_pending()
771 spin_unlock_irq(&bus->reg_lock); in azx_clear_irq_pending()
779 if (!chip->msi || pci_alloc_irq_vectors(chip->pci, 1, 1, PCI_IRQ_MSI) < 0) { in azx_acquire_irq()
780 ret = pci_alloc_irq_vectors(chip->pci, 1, 1, PCI_IRQ_INTX); in azx_acquire_irq()
783 chip->msi = 0; in azx_acquire_irq()
786 if (request_irq(chip->pci->irq, azx_interrupt, in azx_acquire_irq()
787 chip->msi ? 0 : IRQF_SHARED, in azx_acquire_irq()
788 chip->card->irq_descr, chip)) { in azx_acquire_irq()
789 dev_err(chip->card->dev, in azx_acquire_irq()
791 chip->pci->irq); in azx_acquire_irq()
793 snd_card_disconnect(chip->card); in azx_acquire_irq()
794 return -1; in azx_acquire_irq()
796 bus->irq = chip->pci->irq; in azx_acquire_irq()
797 chip->card->sync_irq = bus->irq; in azx_acquire_irq()
810 if (azx_dev->core.substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in azx_via_get_position()
819 mod_dma_pos = le32_to_cpu(*azx_dev->core.posbuf); in azx_via_get_position()
820 mod_dma_pos %= azx_dev->core.period_bytes; in azx_via_get_position()
822 fifo_size = azx_stream(azx_dev)->fifo_size; in azx_via_get_position()
824 if (azx_dev->insufficient) { in azx_via_get_position()
829 azx_dev->insufficient = 0; in azx_via_get_position()
833 mini_pos = azx_dev->core.bufsize + link_pos - fifo_size; in azx_via_get_position()
835 mini_pos = link_pos - fifo_size; in azx_via_get_position()
838 mod_mini_pos = mini_pos % azx_dev->core.period_bytes; in azx_via_get_position()
839 mod_link_pos = link_pos % azx_dev->core.period_bytes; in azx_via_get_position()
841 bound_pos = link_pos - mod_link_pos; in azx_via_get_position()
843 bound_pos = mini_pos - mod_mini_pos; in azx_via_get_position()
845 bound_pos = mini_pos - mod_mini_pos + azx_dev->core.period_bytes; in azx_via_get_position()
846 if (bound_pos >= azx_dev->core.bufsize) in azx_via_get_position()
859 struct snd_pcm_substream *substream = azx_dev->core.substream; in azx_get_pos_fifo()
860 struct snd_pcm_runtime *runtime = substream->runtime; in azx_get_pos_fifo()
867 runtime->delay = AMD_FIFO_SIZE; in azx_get_pos_fifo()
869 if (azx_dev->insufficient) { in azx_get_pos_fifo()
872 runtime->delay = bytes_to_frames(runtime, pos); in azx_get_pos_fifo()
874 azx_dev->insufficient = 0; in azx_get_pos_fifo()
879 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { in azx_get_pos_fifo()
881 pos += azx_dev->core.bufsize; in azx_get_pos_fifo()
882 pos -= delay; in azx_get_pos_fifo()
891 struct snd_pcm_substream *substream = azx_dev->core.substream; in azx_get_delay_from_fifo()
894 return substream->runtime->delay; in azx_get_delay_from_fifo()
918 list_add(&hda->list, &card_list); in azx_add_card_list()
926 list_del_init(&hda->list); in azx_del_card_list()
930 /* trigger power-save check at writing parameter */
946 chip = &hda->chip; in param_set_xint()
947 if (!hda->probe_continued || chip->disabled || in param_set_xint()
948 hda->runtime_pm_disabled) in param_set_xint()
950 snd_hda_set_power_save(&chip->bus, power_save * 1000); in param_set_xint()
966 chip = card->private_data; in azx_is_pm_ready()
968 if (chip->disabled || hda->init_failed || !chip->running) in azx_is_pm_ready()
981 if (hda->need_i915_power) in __azx_runtime_resume()
991 if (!chip->pm_prepared) { in __azx_runtime_resume()
992 list_for_each_codec(codec, &chip->bus) { in __azx_runtime_resume()
993 if (codec->relaxed_resume) in __azx_runtime_resume()
996 if (codec->forced_resume || (status & (1 << codec->addr))) in __azx_runtime_resume()
1001 /* power down again for link-controlled chips */ in __azx_runtime_resume()
1002 if (!hda->need_i915_power) in __azx_runtime_resume()
1014 chip = card->private_data; in azx_prepare()
1015 chip->pm_prepared = 1; in azx_prepare()
1018 flush_work(&azx_bus(chip)->unsol_work); in azx_prepare()
1021 * and system suspend, so don't use direct-complete here. in azx_prepare()
1034 chip = card->private_data; in azx_complete()
1036 chip->pm_prepared = 0; in azx_complete()
1047 chip = card->private_data; in azx_suspend()
1062 chip = card->private_data; in azx_resume()
1076 struct azx *chip = card->private_data; in azx_freeze_noirq()
1081 if (chip->driver_type == AZX_DRIVER_SKL) in azx_freeze_noirq()
1090 struct azx *chip = card->private_data; in azx_thaw_noirq()
1095 if (chip->driver_type == AZX_DRIVER_SKL) in azx_thaw_noirq()
1108 chip = card->private_data; in azx_runtime_suspend()
1125 chip = card->private_data; in azx_runtime_resume()
1144 chip = card->private_data; in azx_runtime_idle()
1146 if (chip->disabled || hda->init_failed) in azx_runtime_idle()
1150 azx_bus(chip)->codec_powered || !chip->running) in azx_runtime_idle()
1151 return -EBUSY; in azx_runtime_idle()
1153 /* ELD notification gets broken when HD-audio bus is off */ in azx_runtime_idle()
1155 return -EBUSY; in azx_runtime_idle()
1179 struct azx *chip = card->private_data; in azx_vs_set_state()
1184 wait_for_completion(&hda->probe_wait); in azx_vs_set_state()
1185 if (hda->init_failed) in azx_vs_set_state()
1189 if (chip->disabled == disabled) in azx_vs_set_state()
1192 if (!hda->probe_continued) { in azx_vs_set_state()
1193 chip->disabled = disabled; in azx_vs_set_state()
1195 dev_info(chip->card->dev, in azx_vs_set_state()
1198 dev_err(chip->card->dev, "initialization error\n"); in azx_vs_set_state()
1201 dev_info(chip->card->dev, "%s via vga_switcheroo\n", in azx_vs_set_state()
1204 list_for_each_codec(codec, &chip->bus) { in azx_vs_set_state()
1208 pm_runtime_suspend(card->dev); in azx_vs_set_state()
1209 pm_runtime_disable(card->dev); in azx_vs_set_state()
1213 pci->current_state = PCI_D3cold; in azx_vs_set_state()
1214 chip->disabled = true; in azx_vs_set_state()
1215 if (snd_hda_lock_devices(&chip->bus)) in azx_vs_set_state()
1216 dev_warn(chip->card->dev, in azx_vs_set_state()
1219 snd_hda_unlock_devices(&chip->bus); in azx_vs_set_state()
1220 chip->disabled = false; in azx_vs_set_state()
1221 pm_runtime_enable(card->dev); in azx_vs_set_state()
1222 list_for_each_codec(codec, &chip->bus) { in azx_vs_set_state()
1233 struct azx *chip = card->private_data; in azx_vs_can_switch()
1236 wait_for_completion(&hda->probe_wait); in azx_vs_can_switch()
1237 if (hda->init_failed) in azx_vs_can_switch()
1239 if (chip->disabled || !hda->probe_continued) in azx_vs_can_switch()
1241 if (snd_hda_lock_devices(&chip->bus)) in azx_vs_can_switch()
1243 snd_hda_unlock_devices(&chip->bus); in azx_vs_can_switch()
1256 if (hda->use_vga_switcheroo && !needs_eld_notify_link(chip)) { in setup_vga_switcheroo_runtime_pm()
1257 list_for_each_codec(codec, &chip->bus) in setup_vga_switcheroo_runtime_pm()
1258 codec->auto_runtime_pm = 1; in setup_vga_switcheroo_runtime_pm()
1260 if (chip->running) in setup_vga_switcheroo_runtime_pm()
1269 struct azx *chip = card->private_data; in azx_vs_gpu_bound()
1272 chip->bus.keep_power = 0; in azx_vs_gpu_bound()
1279 struct pci_dev *p = get_bound_vga(chip->pci); in init_vga_switcheroo()
1282 dev_info(chip->card->dev, in init_vga_switcheroo()
1284 hda->use_vga_switcheroo = 1; in init_vga_switcheroo()
1290 chip->bus.keep_power = parent ? !pci_pr3_present(parent) : 1; in init_vga_switcheroo()
1291 chip->driver_caps |= AZX_DCAPS_PM_RUNTIME; in init_vga_switcheroo()
1308 if (!hda->use_vga_switcheroo) in register_vga_switcheroo()
1311 p = get_bound_vga(chip->pci); in register_vga_switcheroo()
1312 err = vga_switcheroo_register_audio_client(chip->pci, &azx_vs_ops, p); in register_vga_switcheroo()
1317 hda->vga_switcheroo_registered = 1; in register_vga_switcheroo()
1333 struct pci_dev *pci = chip->pci; in azx_free()
1337 if (hda->freed) in azx_free()
1340 if (azx_has_pm_runtime(chip) && chip->running) { in azx_free()
1341 pm_runtime_get_noresume(&pci->dev); in azx_free()
1342 pm_runtime_forbid(&pci->dev); in azx_free()
1343 pm_runtime_dont_use_autosuspend(&pci->dev); in azx_free()
1346 chip->running = 0; in azx_free()
1350 hda->init_failed = 1; /* to be sure */ in azx_free()
1351 complete_all(&hda->probe_wait); in azx_free()
1354 if (chip->disabled && hda->probe_continued) in azx_free()
1355 snd_hda_unlock_devices(&chip->bus); in azx_free()
1356 if (hda->vga_switcheroo_registered) { in azx_free()
1357 vga_switcheroo_unregister_client(chip->pci); in azx_free()
1360 * leaving the device probed but non-functional. As long in azx_free()
1366 …dev_warn(&pci->dev, "GPU sound probed, but not operational: please add a quirk to driver_denylist\… in azx_free()
1367 pm_runtime_disable(&pci->dev); in azx_free()
1368 pm_runtime_set_suspended(&pci->dev); in azx_free()
1369 pm_runtime_enable(&pci->dev); in azx_free()
1373 if (bus->chip_init) { in azx_free()
1379 if (bus->irq >= 0) in azx_free()
1380 free_irq(bus->irq, (void*)chip); in azx_free()
1387 release_firmware(chip->fw); in azx_free()
1391 if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT) in azx_free()
1394 hda->freed = 1; in azx_free()
1399 struct azx *chip = device->device_data; in azx_dev_disconnect()
1402 chip->bus.shutdown = 1; in azx_dev_disconnect()
1403 cancel_work_sync(&bus->unsol_work); in azx_dev_disconnect()
1410 azx_free(device->device_data); in azx_dev_free()
1424 if ((pdev->class != PCI_CLASS_DISPLAY_VGA << 8) && in atpx_present()
1425 (pdev->class != PCI_CLASS_DISPLAY_OTHER << 8)) in atpx_present()
1428 dhandle = ACPI_HANDLE(&pdev->dev); in atpx_present()
1454 switch (pci->vendor) { in get_bound_vga()
1457 if (pci->devfn == 1) { in get_bound_vga()
1458 p = pci_get_domain_bus_and_slot(pci_domain_nr(pci->bus), in get_bound_vga()
1459 pci->bus->number, 0); in get_bound_vga()
1466 if (((p->class >> 16) == PCI_BASE_CLASS_DISPLAY) && in get_bound_vga()
1474 if (pci->devfn == 1) { in get_bound_vga()
1475 p = pci_get_domain_bus_and_slot(pci_domain_nr(pci->bus), in get_bound_vga()
1476 pci->bus->number, 0); in get_bound_vga()
1478 if ((p->class >> 16) == PCI_BASE_CLASS_DISPLAY) in get_bound_vga()
1503 * allow/deny-listing for position_fix
1513 SND_PCI_QUIRK(0x10de, 0xcb89, "Macbook Pro 7,1", POS_FIX_LPIB),
1515 SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB),
1516 SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),
1518 SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB),
1519 SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB),
1538 q = snd_pci_quirk_lookup(chip->pci, position_fix_list); in check_position_fix()
1540 dev_info(chip->card->dev, in check_position_fix()
1542 q->value, q->subvendor, q->subdevice); in check_position_fix()
1543 return q->value; in check_position_fix()
1547 if (chip->driver_type == AZX_DRIVER_VIA) { in check_position_fix()
1548 dev_dbg(chip->card->dev, "Using VIACOMBO position fix\n"); in check_position_fix()
1551 if (chip->driver_caps & AZX_DCAPS_AMD_WORKAROUND) { in check_position_fix()
1552 dev_dbg(chip->card->dev, "Using FIFO position fix\n"); in check_position_fix()
1555 if (chip->driver_caps & AZX_DCAPS_POSFIX_LPIB) { in check_position_fix()
1556 dev_dbg(chip->card->dev, "Using LPIB position fix\n"); in check_position_fix()
1559 if (chip->driver_type == AZX_DRIVER_SKL) { in check_position_fix()
1560 dev_dbg(chip->card->dev, "Using SKL position fix\n"); in check_position_fix()
1578 chip->get_position[0] = chip->get_position[1] = callbacks[fix]; in assign_position_fix()
1582 chip->get_position[1] = NULL; in assign_position_fix()
1585 (chip->driver_caps & AZX_DCAPS_COUNT_LPIB_DELAY)) { in assign_position_fix()
1586 chip->get_delay[0] = chip->get_delay[1] = in assign_position_fix()
1591 chip->get_delay[0] = chip->get_delay[1] = in assign_position_fix()
1596 * deny-lists for probe_mask
1600 * to the non-working (or non-existing) modem codec slot.
1624 chip->codec_probe_mask = probe_mask[dev]; in check_probe_mask()
1625 if (chip->codec_probe_mask == -1) { in check_probe_mask()
1626 q = snd_pci_quirk_lookup(chip->pci, probe_mask_list); in check_probe_mask()
1628 dev_info(chip->card->dev, in check_probe_mask()
1630 q->value, q->subvendor, q->subdevice); in check_probe_mask()
1631 chip->codec_probe_mask = q->value; in check_probe_mask()
1636 if (chip->codec_probe_mask != -1 && in check_probe_mask()
1637 (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) { in check_probe_mask()
1638 azx_bus(chip)->codec_mask = chip->codec_probe_mask & 0xff; in check_probe_mask()
1639 dev_info(chip->card->dev, "codec_mask forced to 0x%x\n", in check_probe_mask()
1640 (int)azx_bus(chip)->codec_mask); in check_probe_mask()
1645 * allow/deny-list for enable_msi
1657 SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */
1666 chip->msi = !!enable_msi; in check_msi()
1669 chip->msi = 1; /* enable MSI as default */ in check_msi()
1670 q = snd_pci_quirk_lookup(chip->pci, msi_deny_list); in check_msi()
1672 dev_info(chip->card->dev, in check_msi()
1673 "msi for device %04x:%04x set to %d\n", in check_msi()
1674 q->subvendor, q->subdevice, q->value); in check_msi()
1675 chip->msi = q->value; in check_msi()
1679 /* NVidia chipsets seem to cause troubles with MSI */ in check_msi()
1680 if (chip->driver_caps & AZX_DCAPS_NO_MSI) { in check_msi()
1681 dev_info(chip->card->dev, "Disabling MSI\n"); in check_msi()
1682 chip->msi = 0; in check_msi()
1692 dev_info(chip->card->dev, "Force to %s mode by module option\n", in azx_check_snoop_available()
1693 snoop ? "snoop" : "non-snoop"); in azx_check_snoop_available()
1694 chip->snoop = snoop; in azx_check_snoop_available()
1695 chip->uc_buffer = !snoop; in azx_check_snoop_available()
1701 chip->driver_type == AZX_DRIVER_VIA) { in azx_check_snoop_available()
1702 /* force to non-snoop mode for a new VIA controller in azx_check_snoop_available()
1706 pci_read_config_byte(chip->pci, 0x42, &val); in azx_check_snoop_available()
1707 if (!(val & 0x80) && (chip->pci->revision == 0x30 || in azx_check_snoop_available()
1708 chip->pci->revision == 0x20)) in azx_check_snoop_available()
1712 if (chip->driver_caps & AZX_DCAPS_SNOOP_OFF) in azx_check_snoop_available()
1715 chip->snoop = snoop; in azx_check_snoop_available()
1717 dev_info(chip->card->dev, "Force to non-snoop mode\n"); in azx_check_snoop_available()
1718 /* C-Media requires non-cached pages only for CORB/RIRB */ in azx_check_snoop_available()
1719 if (chip->driver_type != AZX_DRIVER_CMEDIA) in azx_check_snoop_available()
1720 chip->uc_buffer = true; in azx_check_snoop_available()
1727 azx_probe_continue(&hda->chip); in azx_probe_work()
1732 /* some exceptions: Atoms seem problematic with value 1 */ in default_bdl_pos_adj()
1733 if (chip->pci->vendor == PCI_VENDOR_ID_INTEL) { in default_bdl_pos_adj()
1734 switch (chip->pci->device) { in default_bdl_pos_adj()
1743 switch (chip->driver_type) { in default_bdl_pos_adj()
1752 return 1; in default_bdl_pos_adj()
1781 hda = devm_kzalloc(&pci->dev, sizeof(*hda), GFP_KERNEL); in azx_create()
1783 return -ENOMEM; in azx_create()
1785 chip = &hda->chip; in azx_create()
1786 mutex_init(&chip->open_mutex); in azx_create()
1787 chip->card = card; in azx_create()
1788 chip->pci = pci; in azx_create()
1789 chip->ops = &pci_hda_ops; in azx_create()
1790 chip->driver_caps = driver_caps; in azx_create()
1791 chip->driver_type = driver_caps & 0xff; in azx_create()
1793 chip->dev_index = dev; in azx_create()
1795 chip->jackpoll_interval = msecs_to_jiffies(jackpoll_ms[dev]); in azx_create()
1796 INIT_LIST_HEAD(&chip->pcm_list); in azx_create()
1797 INIT_WORK(&hda->irq_pending_work, azx_irq_pending_work); in azx_create()
1798 INIT_LIST_HEAD(&hda->list); in azx_create()
1800 init_completion(&hda->probe_wait); in azx_create()
1805 chip->fallback_to_single_cmd = 1; in azx_create()
1807 chip->single_cmd = single_cmd; in azx_create()
1812 chip->bdl_pos_adj = default_bdl_pos_adj(chip); in azx_create()
1814 chip->bdl_pos_adj = bdl_pos_adj[dev]; in azx_create()
1820 /* use the non-cached pages in non-snoop mode */ in azx_create()
1822 azx_bus(chip)->dma_type = SNDRV_DMA_TYPE_DEV_WC; in azx_create()
1824 if (chip->driver_type == AZX_DRIVER_NVIDIA) { in azx_create()
1825 dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n"); in azx_create()
1826 chip->bus.core.needs_damn_long_delay = 1; in azx_create()
1833 dev_err(card->dev, "Error creating device [card]!\n"); in azx_create()
1839 INIT_DELAYED_WORK(&hda->probe_work, azx_probe_work); in azx_create()
1848 int dev = chip->dev_index; in azx_first_init()
1849 struct pci_dev *pci = chip->pci; in azx_first_init()
1850 struct snd_card *card = chip->card; in azx_first_init()
1858 if (chip->driver_type == AZX_DRIVER_ULI) { in azx_first_init()
1869 if (chip->driver_type == AZX_DRIVER_GFHDMI) in azx_first_init()
1870 bus->polling_mode = 1; in azx_first_init()
1872 if (chip->driver_type == AZX_DRIVER_LOONGSON) { in azx_first_init()
1873 bus->polling_mode = 1; in azx_first_init()
1874 bus->not_use_interrupts = 1; in azx_first_init()
1875 bus->access_sdnctl_in_dword = 1; in azx_first_init()
1876 if (!chip->jackpoll_interval) in azx_first_init()
1877 chip->jackpoll_interval = msecs_to_jiffies(1500); in azx_first_init()
1880 err = pcim_iomap_regions(pci, 1 << 0, "ICH HD audio"); in azx_first_init()
1884 bus->addr = pci_resource_start(pci, 0); in azx_first_init()
1885 bus->remap_addr = pcim_iomap_table(pci)[0]; in azx_first_init()
1887 if (chip->driver_type == AZX_DRIVER_SKL) in azx_first_init()
1896 chip->gts_present = false; in azx_first_init()
1899 if (bus->ppcap && boot_cpu_has(X86_FEATURE_ART)) in azx_first_init()
1900 chip->gts_present = true; in azx_first_init()
1903 if (chip->msi && chip->driver_caps & AZX_DCAPS_NO_MSI64) { in azx_first_init()
1904 dev_dbg(card->dev, "Disabling 64bit MSI\n"); in azx_first_init()
1905 pci->no_64bit_msi = true; in azx_first_init()
1911 dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap); in azx_first_init()
1914 if (chip->pci->vendor == PCI_VENDOR_ID_AMD) in azx_first_init()
1918 if (chip->pci->vendor == PCI_VENDOR_ID_ATI) { in azx_first_init()
1925 if (p_smbus->revision < 0x30) in azx_first_init()
1932 if (chip->pci->vendor == PCI_VENDOR_ID_NVIDIA) in azx_first_init()
1936 if (chip->driver_caps & AZX_DCAPS_NO_64BIT) { in azx_first_init()
1937 dev_dbg(card->dev, "Disabling 64bit DMA\n"); in azx_first_init()
1941 /* disable buffer size rounding to 128-byte multiples if supported */ in azx_first_init()
1943 chip->align_buffer_size = !!align_buffer_size; in azx_first_init()
1945 if (chip->driver_caps & AZX_DCAPS_NO_ALIGN_BUFSIZE) in azx_first_init()
1946 chip->align_buffer_size = 0; in azx_first_init()
1948 chip->align_buffer_size = 1; in azx_first_init()
1954 if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(dma_bits))) in azx_first_init()
1955 dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32)); in azx_first_init()
1956 dma_set_max_seg_size(&pci->dev, UINT_MAX); in azx_first_init()
1961 chip->capture_streams = (gcap >> 8) & 0x0f; in azx_first_init()
1962 chip->playback_streams = (gcap >> 12) & 0x0f; in azx_first_init()
1963 if (!chip->playback_streams && !chip->capture_streams) { in azx_first_init()
1966 switch (chip->driver_type) { in azx_first_init()
1968 chip->playback_streams = ULI_NUM_PLAYBACK; in azx_first_init()
1969 chip->capture_streams = ULI_NUM_CAPTURE; in azx_first_init()
1973 chip->playback_streams = ATIHDMI_NUM_PLAYBACK; in azx_first_init()
1974 chip->capture_streams = ATIHDMI_NUM_CAPTURE; in azx_first_init()
1979 chip->playback_streams = ICH6_NUM_PLAYBACK; in azx_first_init()
1980 chip->capture_streams = ICH6_NUM_CAPTURE; in azx_first_init()
1984 chip->capture_index_offset = 0; in azx_first_init()
1985 chip->playback_index_offset = chip->capture_streams; in azx_first_init()
1986 chip->num_streams = chip->playback_streams + chip->capture_streams; in azx_first_init()
1989 if (chip->num_streams > 15 && in azx_first_init()
1990 (chip->driver_caps & AZX_DCAPS_SEPARATE_STREAM_TAG) == 0) { in azx_first_init()
1991 dev_warn(chip->card->dev, "number of I/O streams is %d, " in azx_first_init()
1992 "forcing separate stream tags", chip->num_streams); in azx_first_init()
1993 chip->driver_caps |= AZX_DCAPS_SEPARATE_STREAM_TAG; in azx_first_init()
2013 if (!azx_bus(chip)->codec_mask) { in azx_first_init()
2014 dev_err(card->dev, "no codecs found!\n"); in azx_first_init()
2019 return -EBUSY; in azx_first_init()
2021 strcpy(card->driver, "HDA-Intel"); in azx_first_init()
2022 strscpy(card->shortname, driver_short_names[chip->driver_type], in azx_first_init()
2023 sizeof(card->shortname)); in azx_first_init()
2024 snprintf(card->longname, sizeof(card->longname), in azx_first_init()
2026 card->shortname, bus->addr, bus->irq); in azx_first_init()
2036 struct azx *chip = card->private_data; in azx_firmware_cb()
2039 chip->fw = fw; in azx_firmware_cb()
2041 dev_err(card->dev, "Cannot load firmware, continue without patching\n"); in azx_firmware_cb()
2042 if (!chip->disabled) { in azx_firmware_cb()
2054 free_irq(bus->irq, chip); in disable_msi_reset_irq()
2055 bus->irq = -1; in disable_msi_reset_irq()
2056 chip->card->sync_irq = -1; in disable_msi_reset_irq()
2057 pci_free_irq_vectors(chip->pci); in disable_msi_reset_irq()
2058 chip->msi = 0; in disable_msi_reset_irq()
2059 err = azx_acquire_irq(chip, 1); in disable_msi_reset_irq()
2067 * some HD-audio PCI entries are exposed without any codecs, and such devices
2072 { PCI_DEVICE_SUB(0x1022, 0x1487, 0x1462, 0xcb59) }, /* MSI TRX40 Creator */
2073 { PCI_DEVICE_SUB(0x1022, 0x1487, 0x1462, 0xcb60) }, /* MSI TRX40 */
2083 /* DMI-based denylist, to be used when:
2084 * - PCI subsystem IDs are zero, impossible to distinguish from valid sound cards.
2085 * - Different modifications of the same laptop use different GPU models.
2118 dev_info(&pci->dev, "Skipping the device on the denylist\n"); in azx_probe()
2119 return -ENODEV; in azx_probe()
2123 if (dmi && pci_match_id(dmi->driver_data, pci)) { in azx_probe()
2124 dev_info(&pci->dev, "Skipping the device on the DMI denylist\n"); in azx_probe()
2125 return -ENODEV; in azx_probe()
2130 return -ENODEV; in azx_probe()
2133 return -ENOENT; in azx_probe()
2142 dev_dbg(&pci->dev, "HDAudio driver not selected, aborting probe\n"); in azx_probe()
2143 return -ENODEV; in azx_probe()
2146 …dev_warn(&pci->dev, "dmic_detect option is deprecated, pass snd-intel-dspcfg.dsp_driver=1 option i… in azx_probe()
2149 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, in azx_probe()
2152 dev_err(&pci->dev, "Error creating card!\n"); in azx_probe()
2156 err = azx_create(card, pci, dev, pci_id->driver_data, &chip); in azx_probe()
2159 card->private_data = chip; in azx_probe()
2166 if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT) { in azx_probe()
2169 if (err == -EPROBE_DEFER) in azx_probe()
2178 dev_err_probe(card->dev, err, in azx_probe()
2179 "HSW/BDW HD-audio HDMI/DP requires binding with gfx driver\n"); in azx_probe()
2184 chip->driver_caps &= ~AZX_DCAPS_I915_COMPONENT; in azx_probe()
2190 hda->need_i915_power = true; in azx_probe()
2194 dev_err(card->dev, "Haswell/Broadwell HDMI/DP must build in CONFIG_SND_HDA_I915\n"); in azx_probe()
2199 dev_err(card->dev, "Error registering vga_switcheroo client\n"); in azx_probe()
2204 dev_info(card->dev, "VGA controller is disabled\n"); in azx_probe()
2205 dev_info(card->dev, "Delaying initialization\n"); in azx_probe()
2206 chip->disabled = true; in azx_probe()
2209 schedule_probe = !chip->disabled; in azx_probe()
2213 dev_info(card->dev, "Applying patch firmware '%s'\n", in azx_probe()
2216 &pci->dev, GFP_KERNEL, card, in azx_probe()
2225 schedule_delayed_work(&hda->probe_work, 0); in azx_probe()
2228 if (chip->disabled) in azx_probe()
2229 complete_all(&hda->probe_wait); in azx_probe()
2246 SND_PCI_QUIRK(0x1849, 0xc892, "Asrock B85M-ITX", 0),
2248 SND_PCI_QUIRK(0x1849, 0x0397, "Asrock N68C-S UCC", 0),
2250 SND_PCI_QUIRK(0x1849, 0x7662, "Asrock H81M-HDS", 0),
2252 SND_PCI_QUIRK(0x1043, 0x8733, "Asus Prime X370-Pro", 0),
2256 /* Note the P55A-UD3 and Z87-D3HP share the subsys id for the HDA dev */
2257 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P55A-UD3 / Z87-D3HP", 0),
2259 SND_PCI_QUIRK(0x8086, 0x2040, "Intel DZ77BH-55K", 0),
2290 q = snd_pci_quirk_lookup(chip->pci, power_save_denylist); in set_default_power_save()
2292 …dev_info(chip->card->dev, "device %04x:%04x is on the power_save denylist, forcing power_save to 0… in set_default_power_save()
2293 q->subvendor, q->subdevice); in set_default_power_save()
2295 hda->runtime_pm_disabled = 1; in set_default_power_save()
2298 dev_info(chip->card->dev, "Forcing power_save to 0 via option\n"); in set_default_power_save()
2301 snd_hda_set_power_save(&chip->bus, val * 1000); in set_default_power_save()
2307 [AZX_DRIVER_TERA] = 1,
2314 struct pci_dev *pci = chip->pci; in azx_probe_continue()
2315 int dev = chip->dev_index; in azx_probe_continue()
2318 if (chip->disabled || hda->init_failed) in azx_probe_continue()
2319 return -EIO; in azx_probe_continue()
2320 if (hda->probe_retry) in azx_probe_continue()
2323 to_hda_bus(bus)->bus_probing = 1; in azx_probe_continue()
2324 hda->probe_continued = 1; in azx_probe_continue()
2338 chip->beep_mode = beep_mode[dev]; in azx_probe_continue()
2341 chip->ctl_dev_id = ctl_dev_id; in azx_probe_continue()
2344 if (bus->codec_mask) { in azx_probe_continue()
2345 err = azx_probe_codecs(chip, azx_max_codecs[chip->driver_type]); in azx_probe_continue()
2351 if (chip->fw) { in azx_probe_continue()
2352 err = snd_hda_load_patch(&chip->bus, chip->fw->size, in azx_probe_continue()
2353 chip->fw->data); in azx_probe_continue()
2360 if (bus->codec_mask && !(probe_only[dev] & 1)) { in azx_probe_continue()
2363 if ((chip->driver_caps & AZX_DCAPS_RETRY_PROBE) && in azx_probe_continue()
2364 ++hda->probe_retry < 60) { in azx_probe_continue()
2365 schedule_delayed_work(&hda->probe_work, in azx_probe_continue()
2369 dev_err(chip->card->dev, "Cannot probe codecs, giving up\n"); in azx_probe_continue()
2374 err = snd_card_register(chip->card); in azx_probe_continue()
2380 chip->running = 1; in azx_probe_continue()
2386 pm_runtime_use_autosuspend(&pci->dev); in azx_probe_continue()
2387 pm_runtime_allow(&pci->dev); in azx_probe_continue()
2388 pm_runtime_put_autosuspend(&pci->dev); in azx_probe_continue()
2394 snd_card_free(chip->card); in azx_probe_continue()
2398 if (!hda->need_i915_power) in azx_probe_continue()
2400 complete_all(&hda->probe_wait); in azx_probe_continue()
2401 to_hda_bus(bus)->bus_probing = 0; in azx_probe_continue()
2402 hda->probe_retry = 0; in azx_probe_continue()
2414 chip = card->private_data; in azx_remove()
2427 device_unlock(&pci->dev); in azx_remove()
2428 cancel_delayed_work_sync(&hda->probe_work); in azx_remove()
2429 device_lock(&pci->dev); in azx_remove()
2431 clear_bit(chip->dev_index, probed_devs); in azx_remove()
2444 chip = card->private_data; in azx_shutdown()
2445 if (chip && chip->running) in azx_shutdown()
2467 /* Lynx Point-LP */
2469 /* Lynx Point-LP */
2471 /* Wildcat Point-LP */
2475 /* Skylake-LP (Sunrise Point-LP) */
2479 /* Kabylake-LP */
2481 /* Kabylake-H */
2487 /* CometLake-LP */
2489 /* CometLake-H */
2492 /* CometLake-S */
2494 /* CometLake-R */
2498 /* Icelake-H */
2505 /* Tigerlake-H */
2513 /* Alderlake-S */
2515 /* Alderlake-P */
2519 /* Alderlake-M */
2521 /* Alderlake-N */
2535 /* Lunarlake-P */
2537 /* Arrow Lake-S */
2543 /* Panther Lake-H */
2545 /* Apollolake (Broxton-P) */
2547 /* Gemini-Lake */
2744 /* Creative X-Fi (CA0110-IBG) */
2751 /* the following entry conflicts with snd-ctxfi driver,
2752 * as ctxfi driver mutates from HD-audio to native mode with
2761 /* this entry seems still valid -- i.e. without emu20kx chip */