3 * hda_intel.c - Implementation of primary alsa driver code base
6 * Copyright(c) 2004 Intel Corporation. All rights reserved.
8 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
9 * PeiSen Hou <pshou@realtek.com.tw>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 * You should have received a copy of the GNU General Public License along with
22 * this program; if not, write to the Free Software Foundation, Inc., 59
23 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 * Matt Jared matt.jared@intel.com
28 * Andy Kopp andy.kopp@intel.com
29 * Dan Kogan dan.d.kogan@intel.com
33 * 2004.12.01 Major rewrite by tiwai, merged the work of pshou
37 #include <linux/delay.h>
38 #include <linux/interrupt.h>
39 #include <linux/kernel.h>
40 #include <linux/module.h>
41 #include <linux/dma-mapping.h>
42 #include <linux/moduleparam.h>
43 #include <linux/init.h>
44 #include <linux/slab.h>
45 #include <linux/pci.h>
46 #include <linux/mutex.h>
48 #include <linux/pm_runtime.h>
49 #include <linux/clocksource.h>
50 #include <linux/time.h>
51 #include <linux/completion.h>
54 /* for snoop control */
55 #include <asm/pgtable.h>
56 #include <asm/cacheflush.h>
58 #include <sound/core.h>
59 #include <sound/initval.h>
60 #include <sound/hdaudio.h>
61 #include <sound/hda_i915.h>
62 #include <linux/vgaarb.h>
63 #include <linux/vga_switcheroo.h>
64 #include <linux/firmware.h>
65 #include "hda_codec.h"
66 #include "hda_controller.h"
67 #include "hda_intel.h"
69 #define CREATE_TRACE_POINTS
70 #include "hda_intel_trace.h"
72 /* position fix mode */
81 /* Defines for ATI HD Audio support in SB450 south bridge */
82 #define ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR 0x42
83 #define ATI_SB450_HDAUDIO_ENABLE_SNOOP 0x02
85 /* Defines for Nvidia HDA support */
86 #define NVIDIA_HDA_TRANSREG_ADDR 0x4e
87 #define NVIDIA_HDA_ENABLE_COHBITS 0x0f
88 #define NVIDIA_HDA_ISTRM_COH 0x4d
89 #define NVIDIA_HDA_OSTRM_COH 0x4c
90 #define NVIDIA_HDA_ENABLE_COHBIT 0x01
92 /* Defines for Intel SCH HDA snoop control */
93 #define INTEL_HDA_CGCTL 0x48
94 #define INTEL_HDA_CGCTL_MISCBDCGE (0x1 << 6)
95 #define INTEL_SCH_HDA_DEVC 0x78
96 #define INTEL_SCH_HDA_DEVC_NOSNOOP (0x1<<11)
98 /* Define IN stream 0 FIFO size offset in VIA controller */
99 #define VIA_IN_STREAM0_FIFO_SIZE_OFFSET 0x90
100 /* Define VIA HD Audio Device ID*/
101 #define VIA_HDAC_DEVICE_ID 0x3288
103 /* max number of SDs */
104 /* ICH, ATI and VIA have 4 playback and 4 capture */
105 #define ICH6_NUM_CAPTURE 4
106 #define ICH6_NUM_PLAYBACK 4
108 /* ULI has 6 playback and 5 capture */
109 #define ULI_NUM_CAPTURE 5
110 #define ULI_NUM_PLAYBACK 6
112 /* ATI HDMI may have up to 8 playbacks and 0 capture */
113 #define ATIHDMI_NUM_CAPTURE 0
114 #define ATIHDMI_NUM_PLAYBACK 8
116 /* TERA has 4 playback and 3 capture */
117 #define TERA_NUM_CAPTURE 3
118 #define TERA_NUM_PLAYBACK 4
121 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
122 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
123 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
124 static char *model[SNDRV_CARDS];
125 static int position_fix[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
126 static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
127 static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
128 static int probe_only[SNDRV_CARDS];
129 static int jackpoll_ms[SNDRV_CARDS];
130 static bool single_cmd;
131 static int enable_msi = -1;
132 #ifdef CONFIG_SND_HDA_PATCH_LOADER
133 static char *patch[SNDRV_CARDS];
135 #ifdef CONFIG_SND_HDA_INPUT_BEEP
136 static bool beep_mode[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] =
137 CONFIG_SND_HDA_INPUT_BEEP_MODE};
140 module_param_array(index, int, NULL, 0444);
141 MODULE_PARM_DESC(index, "Index value for Intel HD audio interface.");
142 module_param_array(id, charp, NULL, 0444);
143 MODULE_PARM_DESC(id, "ID string for Intel HD audio interface.");
144 module_param_array(enable, bool, NULL, 0444);
145 MODULE_PARM_DESC(enable, "Enable Intel HD audio interface.");
146 module_param_array(model, charp, NULL, 0444);
147 MODULE_PARM_DESC(model, "Use the given board model.");
148 module_param_array(position_fix, int, NULL, 0444);
149 MODULE_PARM_DESC(position_fix, "DMA pointer read method."
150 "(-1 = system default, 0 = auto, 1 = LPIB, 2 = POSBUF, 3 = VIACOMBO, 4 = COMBO).");
151 module_param_array(bdl_pos_adj, int, NULL, 0644);
152 MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset.");
153 module_param_array(probe_mask, int, NULL, 0444);
154 MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1).");
155 module_param_array(probe_only, int, NULL, 0444);
156 MODULE_PARM_DESC(probe_only, "Only probing and no codec initialization.");
157 module_param_array(jackpoll_ms, int, NULL, 0444);
158 MODULE_PARM_DESC(jackpoll_ms, "Ms between polling for jack events (default = 0, using unsol events only)");
159 module_param(single_cmd, bool, 0444);
160 MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs "
161 "(for debugging only).");
162 module_param(enable_msi, bint, 0444);
163 MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)");
164 #ifdef CONFIG_SND_HDA_PATCH_LOADER
165 module_param_array(patch, charp, NULL, 0444);
166 MODULE_PARM_DESC(patch, "Patch file for Intel HD audio interface.");
168 #ifdef CONFIG_SND_HDA_INPUT_BEEP
169 module_param_array(beep_mode, bool, NULL, 0444);
170 MODULE_PARM_DESC(beep_mode, "Select HDA Beep registration mode "
171 "(0=off, 1=on) (default=1).");
175 static int param_set_xint(const char *val, const struct kernel_param *kp);
176 static const struct kernel_param_ops param_ops_xint = {
177 .set = param_set_xint,
178 .get = param_get_int,
180 #define param_check_xint param_check_int
182 static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
183 module_param(power_save, xint, 0644);
184 MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
185 "(in second, 0 = disable).");
187 static bool pm_blacklist = true;
188 module_param(pm_blacklist, bool, 0644);
189 MODULE_PARM_DESC(pm_blacklist, "Enable power-management blacklist");
191 /* reset the HD-audio controller in power save mode.
192 * this may give more power-saving, but will take longer time to
195 static bool power_save_controller = 1;
196 module_param(power_save_controller, bool, 0644);
197 MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode.");
200 #endif /* CONFIG_PM */
202 static int align_buffer_size = -1;
203 module_param(align_buffer_size, bint, 0644);
204 MODULE_PARM_DESC(align_buffer_size,
205 "Force buffer and period sizes to be multiple of 128 bytes.");
208 static int hda_snoop = -1;
209 module_param_named(snoop, hda_snoop, bint, 0444);
210 MODULE_PARM_DESC(snoop, "Enable/disable snooping");
212 #define hda_snoop true
216 MODULE_LICENSE("GPL");
217 MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
251 MODULE_DESCRIPTION("Intel HDA driver");
253 #if defined(CONFIG_PM) && defined(CONFIG_VGA_SWITCHEROO)
254 #if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI)
255 #define SUPPORT_VGA_SWITCHEROO
271 AZX_DRIVER_ATIHDMI_NS,
281 AZX_NUM_DRIVERS, /* keep this as last entry */
284 #define azx_get_snoop_type(chip) \
285 (((chip)->driver_caps & AZX_DCAPS_SNOOP_MASK) >> 10)
286 #define AZX_DCAPS_SNOOP_TYPE(type) ((AZX_SNOOP_TYPE_ ## type) << 10)
288 /* quirks for old Intel chipsets */
289 #define AZX_DCAPS_INTEL_ICH \
290 (AZX_DCAPS_OLD_SSYNC | AZX_DCAPS_NO_ALIGN_BUFSIZE)
292 /* quirks for Intel PCH */
293 #define AZX_DCAPS_INTEL_PCH_NOPM \
294 (AZX_DCAPS_NO_ALIGN_BUFSIZE | AZX_DCAPS_COUNT_LPIB_DELAY |\
295 AZX_DCAPS_REVERSE_ASSIGN | AZX_DCAPS_SNOOP_TYPE(SCH))
297 #define AZX_DCAPS_INTEL_PCH \
298 (AZX_DCAPS_INTEL_PCH_NOPM | AZX_DCAPS_PM_RUNTIME)
300 #define AZX_DCAPS_INTEL_HASWELL \
301 (/*AZX_DCAPS_ALIGN_BUFSIZE |*/ AZX_DCAPS_COUNT_LPIB_DELAY |\
302 AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_POWERWELL |\
303 AZX_DCAPS_SNOOP_TYPE(SCH))
305 /* Broadwell HDMI can't use position buffer reliably, force to use LPIB */
306 #define AZX_DCAPS_INTEL_BROADWELL \
307 (/*AZX_DCAPS_ALIGN_BUFSIZE |*/ AZX_DCAPS_POSFIX_LPIB |\
308 AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_POWERWELL |\
309 AZX_DCAPS_SNOOP_TYPE(SCH))
311 #define AZX_DCAPS_INTEL_BAYTRAIL \
312 (AZX_DCAPS_INTEL_PCH_NOPM | AZX_DCAPS_I915_POWERWELL)
314 #define AZX_DCAPS_INTEL_BRASWELL \
315 (AZX_DCAPS_INTEL_PCH | AZX_DCAPS_I915_POWERWELL)
317 #define AZX_DCAPS_INTEL_SKYLAKE \
318 (AZX_DCAPS_INTEL_PCH | AZX_DCAPS_SEPARATE_STREAM_TAG |\
319 AZX_DCAPS_I915_POWERWELL)
321 #define AZX_DCAPS_INTEL_BROXTON \
322 (AZX_DCAPS_INTEL_PCH | AZX_DCAPS_SEPARATE_STREAM_TAG |\
323 AZX_DCAPS_I915_POWERWELL)
325 /* quirks for ATI SB / AMD Hudson */
326 #define AZX_DCAPS_PRESET_ATI_SB \
327 (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB |\
328 AZX_DCAPS_SNOOP_TYPE(ATI))
330 /* quirks for ATI/AMD HDMI */
331 #define AZX_DCAPS_PRESET_ATI_HDMI \
332 (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB|\
335 /* quirks for ATI HDMI with snoop off */
336 #define AZX_DCAPS_PRESET_ATI_HDMI_NS \
337 (AZX_DCAPS_PRESET_ATI_HDMI | AZX_DCAPS_SNOOP_OFF)
339 /* quirks for Nvidia */
340 #define AZX_DCAPS_PRESET_NVIDIA \
341 (AZX_DCAPS_NO_MSI | AZX_DCAPS_CORBRP_SELF_CLEAR |\
342 AZX_DCAPS_SNOOP_TYPE(NVIDIA))
344 #define AZX_DCAPS_PRESET_CTHDA \
345 (AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB |\
346 AZX_DCAPS_NO_64BIT |\
347 AZX_DCAPS_4K_BDLE_BOUNDARY | AZX_DCAPS_SNOOP_OFF)
350 * vga_switcheroo support
352 #ifdef SUPPORT_VGA_SWITCHEROO
353 #define use_vga_switcheroo(chip) ((chip)->use_vga_switcheroo)
355 #define use_vga_switcheroo(chip) 0
358 #define CONTROLLER_IN_GPU(pci) (((pci)->device == 0x0a0c) || \
359 ((pci)->device == 0x0c0c) || \
360 ((pci)->device == 0x0d0c) || \
361 ((pci)->device == 0x160c))
363 #define IS_SKL(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0xa170)
364 #define IS_SKL_LP(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x9d70)
365 #define IS_KBL(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0xa171)
366 #define IS_KBL_LP(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x9d71)
367 #define IS_KBL_H(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0xa2f0)
368 #define IS_BXT(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x5a98)
369 #define IS_SKL_PLUS(pci) (IS_SKL(pci) || IS_SKL_LP(pci) || IS_BXT(pci)) || \
370 IS_KBL(pci) || IS_KBL_LP(pci) || IS_KBL_H(pci)
372 static char *driver_short_names[] = {
373 [AZX_DRIVER_ICH] = "HDA Intel",
374 [AZX_DRIVER_PCH] = "HDA Intel PCH",
375 [AZX_DRIVER_SCH] = "HDA Intel MID",
376 [AZX_DRIVER_HDMI] = "HDA Intel HDMI",
377 [AZX_DRIVER_ATI] = "HDA ATI SB",
378 [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI",
379 [AZX_DRIVER_ATIHDMI_NS] = "HDA ATI HDMI",
380 [AZX_DRIVER_VIA] = "HDA VIA VT82xx",
381 [AZX_DRIVER_SIS] = "HDA SIS966",
382 [AZX_DRIVER_ULI] = "HDA ULI M5461",
383 [AZX_DRIVER_NVIDIA] = "HDA NVidia",
384 [AZX_DRIVER_TERA] = "HDA Teradici",
385 [AZX_DRIVER_CTX] = "HDA Creative",
386 [AZX_DRIVER_CTHDA] = "HDA Creative",
387 [AZX_DRIVER_CMEDIA] = "HDA C-Media",
388 [AZX_DRIVER_GENERIC] = "HD-Audio Generic",
392 static void __mark_pages_wc(struct azx *chip, struct snd_dma_buffer *dmab, bool on)
398 if (!dmab || !dmab->area || !dmab->bytes)
401 #ifdef CONFIG_SND_DMA_SGBUF
402 if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_SG) {
403 struct snd_sg_buf *sgbuf = dmab->private_data;
404 if (!chip->uc_buffer)
405 return; /* deal with only CORB/RIRB buffers */
407 set_pages_array_wc(sgbuf->page_table, sgbuf->pages);
409 set_pages_array_wb(sgbuf->page_table, sgbuf->pages);
414 pages = (dmab->bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
416 set_memory_wc((unsigned long)dmab->area, pages);
418 set_memory_wb((unsigned long)dmab->area, pages);
421 static inline void mark_pages_wc(struct azx *chip, struct snd_dma_buffer *buf,
424 __mark_pages_wc(chip, buf, on);
426 static inline void mark_runtime_wc(struct azx *chip, struct azx_dev *azx_dev,
427 struct snd_pcm_substream *substream, bool on)
429 if (azx_dev->wc_marked != on) {
430 __mark_pages_wc(chip, snd_pcm_get_dma_buf(substream), on);
431 azx_dev->wc_marked = on;
435 /* NOP for other archs */
436 static inline void mark_pages_wc(struct azx *chip, struct snd_dma_buffer *buf,
440 static inline void mark_runtime_wc(struct azx *chip, struct azx_dev *azx_dev,
441 struct snd_pcm_substream *substream, bool on)
446 static int azx_acquire_irq(struct azx *chip, int do_disconnect);
449 * initialize the PCI registers
451 /* update bits in a PCI register byte */
452 static void update_pci_byte(struct pci_dev *pci, unsigned int reg,
453 unsigned char mask, unsigned char val)
457 pci_read_config_byte(pci, reg, &data);
459 data |= (val & mask);
460 pci_write_config_byte(pci, reg, data);
463 static void azx_init_pci(struct azx *chip)
465 int snoop_type = azx_get_snoop_type(chip);
467 /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
468 * TCSEL == Traffic Class Select Register, which sets PCI express QOS
469 * Ensuring these bits are 0 clears playback static on some HD Audio
471 * The PCI register TCSEL is defined in the Intel manuals.
473 if (!(chip->driver_caps & AZX_DCAPS_NO_TCSEL)) {
474 dev_dbg(chip->card->dev, "Clearing TCSEL\n");
475 update_pci_byte(chip->pci, AZX_PCIREG_TCSEL, 0x07, 0);
478 /* For ATI SB450/600/700/800/900 and AMD Hudson azalia HD audio,
479 * we need to enable snoop.
481 if (snoop_type == AZX_SNOOP_TYPE_ATI) {
482 dev_dbg(chip->card->dev, "Setting ATI snoop: %d\n",
484 update_pci_byte(chip->pci,
485 ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 0x07,
486 azx_snoop(chip) ? ATI_SB450_HDAUDIO_ENABLE_SNOOP : 0);
489 /* For NVIDIA HDA, enable snoop */
490 if (snoop_type == AZX_SNOOP_TYPE_NVIDIA) {
491 dev_dbg(chip->card->dev, "Setting Nvidia snoop: %d\n",
493 update_pci_byte(chip->pci,
494 NVIDIA_HDA_TRANSREG_ADDR,
495 0x0f, NVIDIA_HDA_ENABLE_COHBITS);
496 update_pci_byte(chip->pci,
497 NVIDIA_HDA_ISTRM_COH,
498 0x01, NVIDIA_HDA_ENABLE_COHBIT);
499 update_pci_byte(chip->pci,
500 NVIDIA_HDA_OSTRM_COH,
501 0x01, NVIDIA_HDA_ENABLE_COHBIT);
504 /* Enable SCH/PCH snoop if needed */
505 if (snoop_type == AZX_SNOOP_TYPE_SCH) {
506 unsigned short snoop;
507 pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop);
508 if ((!azx_snoop(chip) && !(snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)) ||
509 (azx_snoop(chip) && (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP))) {
510 snoop &= ~INTEL_SCH_HDA_DEVC_NOSNOOP;
511 if (!azx_snoop(chip))
512 snoop |= INTEL_SCH_HDA_DEVC_NOSNOOP;
513 pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC, snoop);
514 pci_read_config_word(chip->pci,
515 INTEL_SCH_HDA_DEVC, &snoop);
517 dev_dbg(chip->card->dev, "SCH snoop: %s\n",
518 (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) ?
519 "Disabled" : "Enabled");
524 * In BXT-P A0, HD-Audio DMA requests is later than expected,
525 * and makes an audio stream sensitive to system latencies when
526 * 24/32 bits are playing.
527 * Adjusting threshold of DMA fifo to force the DMA request
528 * sooner to improve latency tolerance at the expense of power.
530 static void bxt_reduce_dma_latency(struct azx *chip)
534 val = azx_readl(chip, SKL_EM4L);
536 azx_writel(chip, SKL_EM4L, val);
539 static void hda_intel_init_chip(struct azx *chip, bool full_reset)
541 struct hdac_bus *bus = azx_bus(chip);
542 struct pci_dev *pci = chip->pci;
545 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
546 snd_hdac_set_codec_wakeup(bus, true);
547 if (IS_SKL_PLUS(pci)) {
548 pci_read_config_dword(pci, INTEL_HDA_CGCTL, &val);
549 val = val & ~INTEL_HDA_CGCTL_MISCBDCGE;
550 pci_write_config_dword(pci, INTEL_HDA_CGCTL, val);
552 azx_init_chip(chip, full_reset);
553 if (IS_SKL_PLUS(pci)) {
554 pci_read_config_dword(pci, INTEL_HDA_CGCTL, &val);
555 val = val | INTEL_HDA_CGCTL_MISCBDCGE;
556 pci_write_config_dword(pci, INTEL_HDA_CGCTL, val);
558 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
559 snd_hdac_set_codec_wakeup(bus, false);
561 /* reduce dma latency to avoid noise */
563 bxt_reduce_dma_latency(chip);
566 /* calculate runtime delay from LPIB */
567 static int azx_get_delay_from_lpib(struct azx *chip, struct azx_dev *azx_dev,
570 struct snd_pcm_substream *substream = azx_dev->core.substream;
571 int stream = substream->stream;
572 unsigned int lpib_pos = azx_get_pos_lpib(chip, azx_dev);
575 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
576 delay = pos - lpib_pos;
578 delay = lpib_pos - pos;
580 if (delay >= azx_dev->core.delay_negative_threshold)
583 delay += azx_dev->core.bufsize;
586 if (delay >= azx_dev->core.period_bytes) {
587 dev_info(chip->card->dev,
588 "Unstable LPIB (%d >= %d); disabling LPIB delay counting\n",
589 delay, azx_dev->core.period_bytes);
591 chip->driver_caps &= ~AZX_DCAPS_COUNT_LPIB_DELAY;
592 chip->get_delay[stream] = NULL;
595 return bytes_to_frames(substream->runtime, delay);
598 static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev);
600 /* called from IRQ */
601 static int azx_position_check(struct azx *chip, struct azx_dev *azx_dev)
603 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
606 ok = azx_position_ok(chip, azx_dev);
608 azx_dev->irq_pending = 0;
610 } else if (ok == 0) {
611 /* bogus IRQ, process it later */
612 azx_dev->irq_pending = 1;
613 schedule_work(&hda->irq_pending_work);
618 /* Enable/disable i915 display power for the link */
619 static int azx_intel_link_power(struct azx *chip, bool enable)
621 struct hdac_bus *bus = azx_bus(chip);
623 return snd_hdac_display_power(bus, enable);
627 * Check whether the current DMA position is acceptable for updating
628 * periods. Returns non-zero if it's OK.
630 * Many HD-audio controllers appear pretty inaccurate about
631 * the update-IRQ timing. The IRQ is issued before actually the
632 * data is processed. So, we need to process it afterwords in a
635 static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
637 struct snd_pcm_substream *substream = azx_dev->core.substream;
638 int stream = substream->stream;
642 wallclk = azx_readl(chip, WALLCLK) - azx_dev->core.start_wallclk;
643 if (wallclk < (azx_dev->core.period_wallclk * 2) / 3)
644 return -1; /* bogus (too early) interrupt */
646 if (chip->get_position[stream])
647 pos = chip->get_position[stream](chip, azx_dev);
648 else { /* use the position buffer as default */
649 pos = azx_get_pos_posbuf(chip, azx_dev);
650 if (!pos || pos == (u32)-1) {
651 dev_info(chip->card->dev,
652 "Invalid position buffer, using LPIB read method instead.\n");
653 chip->get_position[stream] = azx_get_pos_lpib;
654 if (chip->get_position[0] == azx_get_pos_lpib &&
655 chip->get_position[1] == azx_get_pos_lpib)
656 azx_bus(chip)->use_posbuf = false;
657 pos = azx_get_pos_lpib(chip, azx_dev);
658 chip->get_delay[stream] = NULL;
660 chip->get_position[stream] = azx_get_pos_posbuf;
661 if (chip->driver_caps & AZX_DCAPS_COUNT_LPIB_DELAY)
662 chip->get_delay[stream] = azx_get_delay_from_lpib;
666 if (pos >= azx_dev->core.bufsize)
669 if (WARN_ONCE(!azx_dev->core.period_bytes,
670 "hda-intel: zero azx_dev->period_bytes"))
671 return -1; /* this shouldn't happen! */
672 if (wallclk < (azx_dev->core.period_wallclk * 5) / 4 &&
673 pos % azx_dev->core.period_bytes > azx_dev->core.period_bytes / 2)
674 /* NG - it's below the first next period boundary */
675 return chip->bdl_pos_adj[chip->dev_index] ? 0 : -1;
676 azx_dev->core.start_wallclk += wallclk;
677 return 1; /* OK, it's fine */
681 * The work for pending PCM period updates.
683 static void azx_irq_pending_work(struct work_struct *work)
685 struct hda_intel *hda = container_of(work, struct hda_intel, irq_pending_work);
686 struct azx *chip = &hda->chip;
687 struct hdac_bus *bus = azx_bus(chip);
688 struct hdac_stream *s;
691 if (!hda->irq_pending_warned) {
692 dev_info(chip->card->dev,
693 "IRQ timing workaround is activated for card #%d. Suggest a bigger bdl_pos_adj.\n",
695 hda->irq_pending_warned = 1;
700 spin_lock_irq(&bus->reg_lock);
701 list_for_each_entry(s, &bus->stream_list, list) {
702 struct azx_dev *azx_dev = stream_to_azx_dev(s);
703 if (!azx_dev->irq_pending ||
707 ok = azx_position_ok(chip, azx_dev);
709 azx_dev->irq_pending = 0;
710 spin_unlock(&bus->reg_lock);
711 snd_pcm_period_elapsed(s->substream);
712 spin_lock(&bus->reg_lock);
714 pending = 0; /* too early */
718 spin_unlock_irq(&bus->reg_lock);
725 /* clear irq_pending flags and assure no on-going workq */
726 static void azx_clear_irq_pending(struct azx *chip)
728 struct hdac_bus *bus = azx_bus(chip);
729 struct hdac_stream *s;
731 spin_lock_irq(&bus->reg_lock);
732 list_for_each_entry(s, &bus->stream_list, list) {
733 struct azx_dev *azx_dev = stream_to_azx_dev(s);
734 azx_dev->irq_pending = 0;
736 spin_unlock_irq(&bus->reg_lock);
739 static int azx_acquire_irq(struct azx *chip, int do_disconnect)
741 struct hdac_bus *bus = azx_bus(chip);
743 if (request_irq(chip->pci->irq, azx_interrupt,
744 chip->msi ? 0 : IRQF_SHARED,
745 KBUILD_MODNAME, chip)) {
746 dev_err(chip->card->dev,
747 "unable to grab IRQ %d, disabling device\n",
750 snd_card_disconnect(chip->card);
753 bus->irq = chip->pci->irq;
754 pci_intx(chip->pci, !chip->msi);
758 /* get the current DMA position with correction on VIA chips */
759 static unsigned int azx_via_get_position(struct azx *chip,
760 struct azx_dev *azx_dev)
762 unsigned int link_pos, mini_pos, bound_pos;
763 unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos;
764 unsigned int fifo_size;
766 link_pos = snd_hdac_stream_get_pos_lpib(azx_stream(azx_dev));
767 if (azx_dev->core.substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
768 /* Playback, no problem using link position */
774 * use mod to get the DMA position just like old chipset
776 mod_dma_pos = le32_to_cpu(*azx_dev->core.posbuf);
777 mod_dma_pos %= azx_dev->core.period_bytes;
779 /* azx_dev->fifo_size can't get FIFO size of in stream.
780 * Get from base address + offset.
782 fifo_size = readw(azx_bus(chip)->remap_addr +
783 VIA_IN_STREAM0_FIFO_SIZE_OFFSET);
785 if (azx_dev->insufficient) {
786 /* Link position never gather than FIFO size */
787 if (link_pos <= fifo_size)
790 azx_dev->insufficient = 0;
793 if (link_pos <= fifo_size)
794 mini_pos = azx_dev->core.bufsize + link_pos - fifo_size;
796 mini_pos = link_pos - fifo_size;
798 /* Find nearest previous boudary */
799 mod_mini_pos = mini_pos % azx_dev->core.period_bytes;
800 mod_link_pos = link_pos % azx_dev->core.period_bytes;
801 if (mod_link_pos >= fifo_size)
802 bound_pos = link_pos - mod_link_pos;
803 else if (mod_dma_pos >= mod_mini_pos)
804 bound_pos = mini_pos - mod_mini_pos;
806 bound_pos = mini_pos - mod_mini_pos + azx_dev->core.period_bytes;
807 if (bound_pos >= azx_dev->core.bufsize)
811 /* Calculate real DMA position we want */
812 return bound_pos + mod_dma_pos;
816 static DEFINE_MUTEX(card_list_lock);
817 static LIST_HEAD(card_list);
819 static void azx_add_card_list(struct azx *chip)
821 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
822 mutex_lock(&card_list_lock);
823 list_add(&hda->list, &card_list);
824 mutex_unlock(&card_list_lock);
827 static void azx_del_card_list(struct azx *chip)
829 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
830 mutex_lock(&card_list_lock);
831 list_del_init(&hda->list);
832 mutex_unlock(&card_list_lock);
835 /* trigger power-save check at writing parameter */
836 static int param_set_xint(const char *val, const struct kernel_param *kp)
838 struct hda_intel *hda;
840 int prev = power_save;
841 int ret = param_set_int(val, kp);
843 if (ret || prev == power_save)
846 mutex_lock(&card_list_lock);
847 list_for_each_entry(hda, &card_list, list) {
849 if (!hda->probe_continued || chip->disabled)
851 snd_hda_set_power_save(&chip->bus, power_save * 1000);
853 mutex_unlock(&card_list_lock);
857 #define azx_add_card_list(chip) /* NOP */
858 #define azx_del_card_list(chip) /* NOP */
859 #endif /* CONFIG_PM */
861 /* Intel HSW/BDW display HDA controller is in GPU. Both its power and link BCLK
862 * depends on GPU. Two Extended Mode registers EM4 (M value) and EM5 (N Value)
863 * are used to convert CDClk (Core Display Clock) to 24MHz BCLK:
864 * BCLK = CDCLK * M / N
865 * The values will be lost when the display power well is disabled and need to
866 * be restored to avoid abnormal playback speed.
868 static void haswell_set_bclk(struct hda_intel *hda)
870 struct azx *chip = &hda->chip;
872 unsigned int bclk_m, bclk_n;
874 if (!hda->need_i915_power)
877 cdclk_freq = snd_hdac_get_display_clk(azx_bus(chip));
878 switch (cdclk_freq) {
885 default: /* default CDCLK 450MHz */
901 azx_writew(chip, HSW_EM4, bclk_m);
902 azx_writew(chip, HSW_EM5, bclk_n);
905 #if defined(CONFIG_PM_SLEEP) || defined(SUPPORT_VGA_SWITCHEROO)
909 static int azx_suspend(struct device *dev)
911 struct snd_card *card = dev_get_drvdata(dev);
913 struct hda_intel *hda;
914 struct hdac_bus *bus;
919 chip = card->private_data;
920 hda = container_of(chip, struct hda_intel, chip);
921 if (chip->disabled || hda->init_failed || !chip->running)
925 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
926 azx_clear_irq_pending(chip);
928 azx_enter_link_reset(chip);
930 free_irq(bus->irq, chip);
935 pci_disable_msi(chip->pci);
936 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL
937 && hda->need_i915_power)
938 snd_hdac_display_power(bus, false);
940 trace_azx_suspend(chip);
944 static int azx_resume(struct device *dev)
946 struct pci_dev *pci = to_pci_dev(dev);
947 struct snd_card *card = dev_get_drvdata(dev);
949 struct hda_intel *hda;
950 struct hdac_bus *bus;
955 chip = card->private_data;
956 hda = container_of(chip, struct hda_intel, chip);
958 if (chip->disabled || hda->init_failed || !chip->running)
961 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
962 snd_hdac_display_power(bus, true);
963 if (hda->need_i915_power)
964 haswell_set_bclk(hda);
968 if (pci_enable_msi(pci) < 0)
970 if (azx_acquire_irq(chip, 1) < 0)
974 hda_intel_init_chip(chip, true);
976 /* power down again for link-controlled chips */
977 if ((chip->driver_caps & AZX_DCAPS_I915_POWERWELL) &&
978 !hda->need_i915_power)
979 snd_hdac_display_power(bus, false);
981 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
983 trace_azx_resume(chip);
986 #endif /* CONFIG_PM_SLEEP || SUPPORT_VGA_SWITCHEROO */
988 #ifdef CONFIG_PM_SLEEP
989 /* put codec down to D3 at hibernation for Intel SKL+;
990 * otherwise BIOS may still access the codec and screw up the driver
992 static int azx_freeze_noirq(struct device *dev)
994 struct pci_dev *pci = to_pci_dev(dev);
996 if (IS_SKL_PLUS(pci))
997 pci_set_power_state(pci, PCI_D3hot);
1002 static int azx_thaw_noirq(struct device *dev)
1004 struct pci_dev *pci = to_pci_dev(dev);
1006 if (IS_SKL_PLUS(pci))
1007 pci_set_power_state(pci, PCI_D0);
1011 #endif /* CONFIG_PM_SLEEP */
1014 static int azx_runtime_suspend(struct device *dev)
1016 struct snd_card *card = dev_get_drvdata(dev);
1018 struct hda_intel *hda;
1023 chip = card->private_data;
1024 hda = container_of(chip, struct hda_intel, chip);
1025 if (chip->disabled || hda->init_failed)
1028 if (!azx_has_pm_runtime(chip))
1031 /* enable controller wake up event */
1032 azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) |
1035 azx_stop_chip(chip);
1036 azx_enter_link_reset(chip);
1037 azx_clear_irq_pending(chip);
1038 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL
1039 && hda->need_i915_power)
1040 snd_hdac_display_power(azx_bus(chip), false);
1042 trace_azx_runtime_suspend(chip);
1046 static int azx_runtime_resume(struct device *dev)
1048 struct snd_card *card = dev_get_drvdata(dev);
1050 struct hda_intel *hda;
1051 struct hdac_bus *bus;
1052 struct hda_codec *codec;
1058 chip = card->private_data;
1059 hda = container_of(chip, struct hda_intel, chip);
1060 bus = azx_bus(chip);
1061 if (chip->disabled || hda->init_failed)
1064 if (!azx_has_pm_runtime(chip))
1067 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
1068 snd_hdac_display_power(bus, true);
1069 if (hda->need_i915_power)
1070 haswell_set_bclk(hda);
1073 /* Read STATESTS before controller reset */
1074 status = azx_readw(chip, STATESTS);
1077 hda_intel_init_chip(chip, true);
1080 list_for_each_codec(codec, &chip->bus)
1081 if (status & (1 << codec->addr))
1082 schedule_delayed_work(&codec->jackpoll_work,
1083 codec->jackpoll_interval);
1086 /* disable controller Wake Up event*/
1087 azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) &
1088 ~STATESTS_INT_MASK);
1090 /* power down again for link-controlled chips */
1091 if ((chip->driver_caps & AZX_DCAPS_I915_POWERWELL) &&
1092 !hda->need_i915_power)
1093 snd_hdac_display_power(bus, false);
1095 trace_azx_runtime_resume(chip);
1099 static int azx_runtime_idle(struct device *dev)
1101 struct snd_card *card = dev_get_drvdata(dev);
1103 struct hda_intel *hda;
1108 chip = card->private_data;
1109 hda = container_of(chip, struct hda_intel, chip);
1110 if (chip->disabled || hda->init_failed)
1113 if (!power_save_controller || !azx_has_pm_runtime(chip) ||
1114 azx_bus(chip)->codec_powered || !chip->running)
1120 static const struct dev_pm_ops azx_pm = {
1121 SET_SYSTEM_SLEEP_PM_OPS(azx_suspend, azx_resume)
1122 #ifdef CONFIG_PM_SLEEP
1123 .freeze_noirq = azx_freeze_noirq,
1124 .thaw_noirq = azx_thaw_noirq,
1126 SET_RUNTIME_PM_OPS(azx_runtime_suspend, azx_runtime_resume, azx_runtime_idle)
1129 #define AZX_PM_OPS &azx_pm
1131 #define AZX_PM_OPS NULL
1132 #endif /* CONFIG_PM */
1135 static int azx_probe_continue(struct azx *chip);
1137 #ifdef SUPPORT_VGA_SWITCHEROO
1138 static struct pci_dev *get_bound_vga(struct pci_dev *pci);
1140 static void azx_vs_set_state(struct pci_dev *pci,
1141 enum vga_switcheroo_state state)
1143 struct snd_card *card = pci_get_drvdata(pci);
1144 struct azx *chip = card->private_data;
1145 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
1148 wait_for_completion(&hda->probe_wait);
1149 if (hda->init_failed)
1152 disabled = (state == VGA_SWITCHEROO_OFF);
1153 if (chip->disabled == disabled)
1156 if (!hda->probe_continued) {
1157 chip->disabled = disabled;
1159 dev_info(chip->card->dev,
1160 "Start delayed initialization\n");
1161 if (azx_probe_continue(chip) < 0) {
1162 dev_err(chip->card->dev, "initialization error\n");
1163 hda->init_failed = true;
1167 dev_info(chip->card->dev, "%s via vga_switcheroo\n",
1168 disabled ? "Disabling" : "Enabling");
1170 pm_runtime_put_sync_suspend(card->dev);
1171 azx_suspend(card->dev);
1172 /* when we get suspended by vga_switcheroo we end up in D3cold,
1173 * however we have no ACPI handle, so pci/acpi can't put us there,
1174 * put ourselves there */
1175 pci->current_state = PCI_D3cold;
1176 chip->disabled = true;
1177 if (snd_hda_lock_devices(&chip->bus))
1178 dev_warn(chip->card->dev,
1179 "Cannot lock devices!\n");
1181 snd_hda_unlock_devices(&chip->bus);
1182 pm_runtime_get_noresume(card->dev);
1183 chip->disabled = false;
1184 azx_resume(card->dev);
1189 static bool azx_vs_can_switch(struct pci_dev *pci)
1191 struct snd_card *card = pci_get_drvdata(pci);
1192 struct azx *chip = card->private_data;
1193 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
1195 wait_for_completion(&hda->probe_wait);
1196 if (hda->init_failed)
1198 if (chip->disabled || !hda->probe_continued)
1200 if (snd_hda_lock_devices(&chip->bus))
1202 snd_hda_unlock_devices(&chip->bus);
1206 static void init_vga_switcheroo(struct azx *chip)
1208 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
1209 struct pci_dev *p = get_bound_vga(chip->pci);
1211 dev_info(chip->card->dev,
1212 "Handle vga_switcheroo audio client\n");
1213 hda->use_vga_switcheroo = 1;
1218 static const struct vga_switcheroo_client_ops azx_vs_ops = {
1219 .set_gpu_state = azx_vs_set_state,
1220 .can_switch = azx_vs_can_switch,
1223 static int register_vga_switcheroo(struct azx *chip)
1225 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
1228 if (!hda->use_vga_switcheroo)
1230 /* FIXME: currently only handling DIS controller
1231 * is there any machine with two switchable HDMI audio controllers?
1233 err = vga_switcheroo_register_audio_client(chip->pci, &azx_vs_ops,
1234 VGA_SWITCHEROO_DIS);
1237 hda->vga_switcheroo_registered = 1;
1239 /* register as an optimus hdmi audio power domain */
1240 vga_switcheroo_init_domain_pm_optimus_hdmi_audio(chip->card->dev,
1241 &hda->hdmi_pm_domain);
1245 #define init_vga_switcheroo(chip) /* NOP */
1246 #define register_vga_switcheroo(chip) 0
1247 #define check_hdmi_disabled(pci) false
1248 #endif /* SUPPORT_VGA_SWITCHER */
1253 static int azx_free(struct azx *chip)
1255 struct pci_dev *pci = chip->pci;
1256 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
1257 struct hdac_bus *bus = azx_bus(chip);
1259 if (azx_has_pm_runtime(chip) && chip->running)
1260 pm_runtime_get_noresume(&pci->dev);
1262 azx_del_card_list(chip);
1264 hda->init_failed = 1; /* to be sure */
1265 complete_all(&hda->probe_wait);
1267 if (use_vga_switcheroo(hda)) {
1268 if (chip->disabled && hda->probe_continued)
1269 snd_hda_unlock_devices(&chip->bus);
1270 if (hda->vga_switcheroo_registered) {
1271 vga_switcheroo_unregister_client(chip->pci);
1272 vga_switcheroo_fini_domain_pm_ops(chip->card->dev);
1276 if (bus->chip_init) {
1277 azx_clear_irq_pending(chip);
1278 azx_stop_all_streams(chip);
1279 azx_stop_chip(chip);
1283 free_irq(bus->irq, (void*)chip);
1285 pci_disable_msi(chip->pci);
1286 iounmap(bus->remap_addr);
1288 azx_free_stream_pages(chip);
1289 azx_free_streams(chip);
1290 snd_hdac_bus_exit(bus);
1292 if (chip->region_requested)
1293 pci_release_regions(chip->pci);
1295 pci_disable_device(chip->pci);
1296 #ifdef CONFIG_SND_HDA_PATCH_LOADER
1297 release_firmware(chip->fw);
1300 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
1301 if (hda->need_i915_power)
1302 snd_hdac_display_power(bus, false);
1303 snd_hdac_i915_exit(bus);
1310 static int azx_dev_disconnect(struct snd_device *device)
1312 struct azx *chip = device->device_data;
1313 struct hdac_bus *bus = azx_bus(chip);
1315 chip->bus.shutdown = 1;
1316 cancel_work_sync(&bus->unsol_work);
1321 static int azx_dev_free(struct snd_device *device)
1323 return azx_free(device->device_data);
1326 #ifdef SUPPORT_VGA_SWITCHEROO
1328 * Check of disabled HDMI controller by vga_switcheroo
1330 static struct pci_dev *get_bound_vga(struct pci_dev *pci)
1334 /* check only discrete GPU */
1335 switch (pci->vendor) {
1336 case PCI_VENDOR_ID_ATI:
1337 case PCI_VENDOR_ID_AMD:
1338 case PCI_VENDOR_ID_NVIDIA:
1339 if (pci->devfn == 1) {
1340 p = pci_get_domain_bus_and_slot(pci_domain_nr(pci->bus),
1341 pci->bus->number, 0);
1343 if ((p->class >> 8) == PCI_CLASS_DISPLAY_VGA)
1353 static bool check_hdmi_disabled(struct pci_dev *pci)
1355 bool vga_inactive = false;
1356 struct pci_dev *p = get_bound_vga(pci);
1359 if (vga_switcheroo_get_client_state(p) == VGA_SWITCHEROO_OFF)
1360 vga_inactive = true;
1363 return vga_inactive;
1365 #endif /* SUPPORT_VGA_SWITCHEROO */
1368 * white/black-listing for position_fix
1370 static struct snd_pci_quirk position_fix_list[] = {
1371 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
1372 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
1373 SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),
1374 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
1375 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB),
1376 SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB),
1377 SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB),
1378 SND_PCI_QUIRK(0x10de, 0xcb89, "Macbook Pro 7,1", POS_FIX_LPIB),
1379 SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB),
1380 SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB),
1381 SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),
1382 SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB),
1383 SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB),
1384 SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB),
1388 static int check_position_fix(struct azx *chip, int fix)
1390 const struct snd_pci_quirk *q;
1395 case POS_FIX_POSBUF:
1396 case POS_FIX_VIACOMBO:
1401 q = snd_pci_quirk_lookup(chip->pci, position_fix_list);
1403 dev_info(chip->card->dev,
1404 "position_fix set to %d for device %04x:%04x\n",
1405 q->value, q->subvendor, q->subdevice);
1409 /* Check VIA/ATI HD Audio Controller exist */
1410 if (chip->driver_caps & AZX_DCAPS_POSFIX_VIA) {
1411 dev_dbg(chip->card->dev, "Using VIACOMBO position fix\n");
1412 return POS_FIX_VIACOMBO;
1414 if (chip->driver_caps & AZX_DCAPS_POSFIX_LPIB) {
1415 dev_dbg(chip->card->dev, "Using LPIB position fix\n");
1416 return POS_FIX_LPIB;
1418 return POS_FIX_AUTO;
1421 static void assign_position_fix(struct azx *chip, int fix)
1423 static azx_get_pos_callback_t callbacks[] = {
1424 [POS_FIX_AUTO] = NULL,
1425 [POS_FIX_LPIB] = azx_get_pos_lpib,
1426 [POS_FIX_POSBUF] = azx_get_pos_posbuf,
1427 [POS_FIX_VIACOMBO] = azx_via_get_position,
1428 [POS_FIX_COMBO] = azx_get_pos_lpib,
1431 chip->get_position[0] = chip->get_position[1] = callbacks[fix];
1433 /* combo mode uses LPIB only for playback */
1434 if (fix == POS_FIX_COMBO)
1435 chip->get_position[1] = NULL;
1437 if (fix == POS_FIX_POSBUF &&
1438 (chip->driver_caps & AZX_DCAPS_COUNT_LPIB_DELAY)) {
1439 chip->get_delay[0] = chip->get_delay[1] =
1440 azx_get_delay_from_lpib;
1446 * black-lists for probe_mask
1448 static struct snd_pci_quirk probe_mask_list[] = {
1449 /* Thinkpad often breaks the controller communication when accessing
1450 * to the non-working (or non-existing) modem codec slot.
1452 SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01),
1453 SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01),
1454 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01),
1456 SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01),
1457 /* including bogus ALC268 in slot#2 that conflicts with ALC888 */
1458 SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01),
1459 /* forced codec slots */
1460 SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103),
1461 SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103),
1462 /* WinFast VP200 H (Teradici) user reported broken communication */
1463 SND_PCI_QUIRK(0x3a21, 0x040d, "WinFast VP200 H", 0x101),
1467 #define AZX_FORCE_CODEC_MASK 0x100
1469 static void check_probe_mask(struct azx *chip, int dev)
1471 const struct snd_pci_quirk *q;
1473 chip->codec_probe_mask = probe_mask[dev];
1474 if (chip->codec_probe_mask == -1) {
1475 q = snd_pci_quirk_lookup(chip->pci, probe_mask_list);
1477 dev_info(chip->card->dev,
1478 "probe_mask set to 0x%x for device %04x:%04x\n",
1479 q->value, q->subvendor, q->subdevice);
1480 chip->codec_probe_mask = q->value;
1484 /* check forced option */
1485 if (chip->codec_probe_mask != -1 &&
1486 (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) {
1487 azx_bus(chip)->codec_mask = chip->codec_probe_mask & 0xff;
1488 dev_info(chip->card->dev, "codec_mask forced to 0x%x\n",
1489 (int)azx_bus(chip)->codec_mask);
1494 * white/black-list for enable_msi
1496 static struct snd_pci_quirk msi_black_list[] = {
1497 SND_PCI_QUIRK(0x103c, 0x2191, "HP", 0), /* AMD Hudson */
1498 SND_PCI_QUIRK(0x103c, 0x2192, "HP", 0), /* AMD Hudson */
1499 SND_PCI_QUIRK(0x103c, 0x21f7, "HP", 0), /* AMD Hudson */
1500 SND_PCI_QUIRK(0x103c, 0x21fa, "HP", 0), /* AMD Hudson */
1501 SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */
1502 SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */
1503 SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */
1504 SND_PCI_QUIRK(0x1179, 0xfb44, "Toshiba Satellite C870", 0), /* AMD Hudson */
1505 SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */
1506 SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */
1510 static void check_msi(struct azx *chip)
1512 const struct snd_pci_quirk *q;
1514 if (enable_msi >= 0) {
1515 chip->msi = !!enable_msi;
1518 chip->msi = 1; /* enable MSI as default */
1519 q = snd_pci_quirk_lookup(chip->pci, msi_black_list);
1521 dev_info(chip->card->dev,
1522 "msi for device %04x:%04x set to %d\n",
1523 q->subvendor, q->subdevice, q->value);
1524 chip->msi = q->value;
1528 /* NVidia chipsets seem to cause troubles with MSI */
1529 if (chip->driver_caps & AZX_DCAPS_NO_MSI) {
1530 dev_info(chip->card->dev, "Disabling MSI\n");
1535 /* check the snoop mode availability */
1536 static void azx_check_snoop_available(struct azx *chip)
1538 int snoop = hda_snoop;
1541 dev_info(chip->card->dev, "Force to %s mode by module option\n",
1542 snoop ? "snoop" : "non-snoop");
1543 chip->snoop = snoop;
1544 chip->uc_buffer = !snoop;
1549 if (azx_get_snoop_type(chip) == AZX_SNOOP_TYPE_NONE &&
1550 chip->driver_type == AZX_DRIVER_VIA) {
1551 /* force to non-snoop mode for a new VIA controller
1555 pci_read_config_byte(chip->pci, 0x42, &val);
1556 if (!(val & 0x80) && (chip->pci->revision == 0x30 ||
1557 chip->pci->revision == 0x20))
1561 if (chip->driver_caps & AZX_DCAPS_SNOOP_OFF)
1564 chip->snoop = snoop;
1566 dev_info(chip->card->dev, "Force to non-snoop mode\n");
1567 /* C-Media requires non-cached pages only for CORB/RIRB */
1568 if (chip->driver_type != AZX_DRIVER_CMEDIA)
1569 chip->uc_buffer = true;
1573 static void azx_probe_work(struct work_struct *work)
1575 struct hda_intel *hda = container_of(work, struct hda_intel, probe_work);
1576 azx_probe_continue(&hda->chip);
1582 static const struct hdac_io_ops pci_hda_io_ops;
1583 static const struct hda_controller_ops pci_hda_ops;
1585 static int azx_create(struct snd_card *card, struct pci_dev *pci,
1586 int dev, unsigned int driver_caps,
1589 static struct snd_device_ops ops = {
1590 .dev_disconnect = azx_dev_disconnect,
1591 .dev_free = azx_dev_free,
1593 struct hda_intel *hda;
1599 err = pci_enable_device(pci);
1603 hda = kzalloc(sizeof(*hda), GFP_KERNEL);
1605 pci_disable_device(pci);
1610 mutex_init(&chip->open_mutex);
1613 chip->ops = &pci_hda_ops;
1614 chip->driver_caps = driver_caps;
1615 chip->driver_type = driver_caps & 0xff;
1617 chip->dev_index = dev;
1618 chip->jackpoll_ms = jackpoll_ms;
1619 INIT_LIST_HEAD(&chip->pcm_list);
1620 INIT_WORK(&hda->irq_pending_work, azx_irq_pending_work);
1621 INIT_LIST_HEAD(&hda->list);
1622 init_vga_switcheroo(chip);
1623 init_completion(&hda->probe_wait);
1625 assign_position_fix(chip, check_position_fix(chip, position_fix[dev]));
1627 check_probe_mask(chip, dev);
1629 chip->single_cmd = single_cmd;
1630 azx_check_snoop_available(chip);
1632 if (bdl_pos_adj[dev] < 0) {
1633 switch (chip->driver_type) {
1634 case AZX_DRIVER_ICH:
1635 case AZX_DRIVER_PCH:
1636 bdl_pos_adj[dev] = 1;
1639 bdl_pos_adj[dev] = 32;
1643 chip->bdl_pos_adj = bdl_pos_adj;
1645 err = azx_bus_init(chip, model[dev], &pci_hda_io_ops);
1648 pci_disable_device(pci);
1652 if (chip->driver_type == AZX_DRIVER_NVIDIA) {
1653 dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n");
1654 chip->bus.needs_damn_long_delay = 1;
1657 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
1659 dev_err(card->dev, "Error creating device [card]!\n");
1664 /* continue probing in work context as may trigger request module */
1665 INIT_WORK(&hda->probe_work, azx_probe_work);
1672 static int azx_first_init(struct azx *chip)
1674 int dev = chip->dev_index;
1675 struct pci_dev *pci = chip->pci;
1676 struct snd_card *card = chip->card;
1677 struct hdac_bus *bus = azx_bus(chip);
1679 unsigned short gcap;
1680 unsigned int dma_bits = 64;
1682 #if BITS_PER_LONG != 64
1683 /* Fix up base address on ULI M5461 */
1684 if (chip->driver_type == AZX_DRIVER_ULI) {
1686 pci_read_config_word(pci, 0x40, &tmp3);
1687 pci_write_config_word(pci, 0x40, tmp3 | 0x10);
1688 pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0);
1692 err = pci_request_regions(pci, "ICH HD audio");
1695 chip->region_requested = 1;
1697 bus->addr = pci_resource_start(pci, 0);
1698 bus->remap_addr = pci_ioremap_bar(pci, 0);
1699 if (bus->remap_addr == NULL) {
1700 dev_err(card->dev, "ioremap error\n");
1705 if (chip->driver_caps & AZX_DCAPS_NO_MSI64) {
1706 dev_dbg(card->dev, "Disabling 64bit MSI\n");
1707 pci->no_64bit_msi = true;
1709 if (pci_enable_msi(pci) < 0)
1713 pci_set_master(pci);
1714 synchronize_irq(bus->irq);
1716 gcap = azx_readw(chip, GCAP);
1717 dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap);
1719 /* AMD devices support 40 or 48bit DMA, take the safe one */
1720 if (chip->pci->vendor == PCI_VENDOR_ID_AMD)
1723 /* disable SB600 64bit support for safety */
1724 if (chip->pci->vendor == PCI_VENDOR_ID_ATI) {
1725 struct pci_dev *p_smbus;
1727 p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
1728 PCI_DEVICE_ID_ATI_SBX00_SMBUS,
1731 if (p_smbus->revision < 0x30)
1732 gcap &= ~AZX_GCAP_64OK;
1733 pci_dev_put(p_smbus);
1737 /* NVidia hardware normally only supports up to 40 bits of DMA */
1738 if (chip->pci->vendor == PCI_VENDOR_ID_NVIDIA)
1741 /* disable 64bit DMA address on some devices */
1742 if (chip->driver_caps & AZX_DCAPS_NO_64BIT) {
1743 dev_dbg(card->dev, "Disabling 64bit DMA\n");
1744 gcap &= ~AZX_GCAP_64OK;
1747 /* disable buffer size rounding to 128-byte multiples if supported */
1748 if (align_buffer_size >= 0)
1749 chip->align_buffer_size = !!align_buffer_size;
1751 if (chip->driver_caps & AZX_DCAPS_NO_ALIGN_BUFSIZE)
1752 chip->align_buffer_size = 0;
1754 chip->align_buffer_size = 1;
1757 /* allow 64bit DMA address if supported by H/W */
1758 if (!(gcap & AZX_GCAP_64OK))
1760 if (!dma_set_mask(&pci->dev, DMA_BIT_MASK(dma_bits))) {
1761 dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(dma_bits));
1763 dma_set_mask(&pci->dev, DMA_BIT_MASK(32));
1764 dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32));
1767 /* read number of streams from GCAP register instead of using
1770 chip->capture_streams = (gcap >> 8) & 0x0f;
1771 chip->playback_streams = (gcap >> 12) & 0x0f;
1772 if (!chip->playback_streams && !chip->capture_streams) {
1773 /* gcap didn't give any info, switching to old method */
1775 switch (chip->driver_type) {
1776 case AZX_DRIVER_ULI:
1777 chip->playback_streams = ULI_NUM_PLAYBACK;
1778 chip->capture_streams = ULI_NUM_CAPTURE;
1780 case AZX_DRIVER_ATIHDMI:
1781 case AZX_DRIVER_ATIHDMI_NS:
1782 chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
1783 chip->capture_streams = ATIHDMI_NUM_CAPTURE;
1785 case AZX_DRIVER_GENERIC:
1787 chip->playback_streams = ICH6_NUM_PLAYBACK;
1788 chip->capture_streams = ICH6_NUM_CAPTURE;
1792 chip->capture_index_offset = 0;
1793 chip->playback_index_offset = chip->capture_streams;
1794 chip->num_streams = chip->playback_streams + chip->capture_streams;
1796 /* initialize streams */
1797 err = azx_init_streams(chip);
1801 err = azx_alloc_stream_pages(chip);
1805 /* initialize chip */
1808 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
1809 struct hda_intel *hda;
1811 hda = container_of(chip, struct hda_intel, chip);
1812 haswell_set_bclk(hda);
1815 hda_intel_init_chip(chip, (probe_only[dev] & 2) == 0);
1817 /* codec detection */
1818 if (!azx_bus(chip)->codec_mask) {
1819 dev_err(card->dev, "no codecs found!\n");
1823 if (azx_acquire_irq(chip, 0) < 0)
1826 strcpy(card->driver, "HDA-Intel");
1827 strlcpy(card->shortname, driver_short_names[chip->driver_type],
1828 sizeof(card->shortname));
1829 snprintf(card->longname, sizeof(card->longname),
1830 "%s at 0x%lx irq %i",
1831 card->shortname, bus->addr, bus->irq);
1836 #ifdef CONFIG_SND_HDA_PATCH_LOADER
1837 /* callback from request_firmware_nowait() */
1838 static void azx_firmware_cb(const struct firmware *fw, void *context)
1840 struct snd_card *card = context;
1841 struct azx *chip = card->private_data;
1846 dev_err(card->dev, "Cannot load firmware, continue without patching\n");
1847 if (!chip->disabled) {
1848 /* continue probing */
1849 azx_probe_continue(chip);
1855 * HDA controller ops.
1858 /* PCI register access. */
1859 static void pci_azx_writel(u32 value, u32 __iomem *addr)
1861 writel(value, addr);
1864 static u32 pci_azx_readl(u32 __iomem *addr)
1869 static void pci_azx_writew(u16 value, u16 __iomem *addr)
1871 writew(value, addr);
1874 static u16 pci_azx_readw(u16 __iomem *addr)
1879 static void pci_azx_writeb(u8 value, u8 __iomem *addr)
1881 writeb(value, addr);
1884 static u8 pci_azx_readb(u8 __iomem *addr)
1889 static int disable_msi_reset_irq(struct azx *chip)
1891 struct hdac_bus *bus = azx_bus(chip);
1894 free_irq(bus->irq, chip);
1896 pci_disable_msi(chip->pci);
1898 err = azx_acquire_irq(chip, 1);
1905 /* DMA page allocation helpers. */
1906 static int dma_alloc_pages(struct hdac_bus *bus,
1909 struct snd_dma_buffer *buf)
1911 struct azx *chip = bus_to_azx(bus);
1914 err = snd_dma_alloc_pages(type,
1919 mark_pages_wc(chip, buf, true);
1923 static void dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
1925 struct azx *chip = bus_to_azx(bus);
1927 mark_pages_wc(chip, buf, false);
1928 snd_dma_free_pages(buf);
1931 static int substream_alloc_pages(struct azx *chip,
1932 struct snd_pcm_substream *substream,
1935 struct azx_dev *azx_dev = get_azx_dev(substream);
1938 mark_runtime_wc(chip, azx_dev, substream, false);
1939 ret = snd_pcm_lib_malloc_pages(substream, size);
1942 mark_runtime_wc(chip, azx_dev, substream, true);
1946 static int substream_free_pages(struct azx *chip,
1947 struct snd_pcm_substream *substream)
1949 struct azx_dev *azx_dev = get_azx_dev(substream);
1950 mark_runtime_wc(chip, azx_dev, substream, false);
1951 return snd_pcm_lib_free_pages(substream);
1954 static void pcm_mmap_prepare(struct snd_pcm_substream *substream,
1955 struct vm_area_struct *area)
1958 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
1959 struct azx *chip = apcm->chip;
1960 if (chip->uc_buffer)
1961 area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
1965 static const struct hdac_io_ops pci_hda_io_ops = {
1966 .reg_writel = pci_azx_writel,
1967 .reg_readl = pci_azx_readl,
1968 .reg_writew = pci_azx_writew,
1969 .reg_readw = pci_azx_readw,
1970 .reg_writeb = pci_azx_writeb,
1971 .reg_readb = pci_azx_readb,
1972 .dma_alloc_pages = dma_alloc_pages,
1973 .dma_free_pages = dma_free_pages,
1976 /* Blacklist for skipping the whole probe:
1977 * some HD-audio PCI entries are exposed without any codecs, and such devices
1978 * should be ignored from the beginning.
1980 static const struct pci_device_id driver_blacklist[] = {
1981 { PCI_DEVICE_SUB(0x1022, 0x1487, 0x1043, 0x874f) }, /* ASUS ROG Zenith II / Strix */
1982 { PCI_DEVICE_SUB(0x1022, 0x1487, 0x1462, 0xcb59) }, /* MSI TRX40 Creator */
1983 { PCI_DEVICE_SUB(0x1022, 0x1487, 0x1462, 0xcb60) }, /* MSI TRX40 */
1987 static const struct hda_controller_ops pci_hda_ops = {
1988 .disable_msi_reset_irq = disable_msi_reset_irq,
1989 .substream_alloc_pages = substream_alloc_pages,
1990 .substream_free_pages = substream_free_pages,
1991 .pcm_mmap_prepare = pcm_mmap_prepare,
1992 .position_check = azx_position_check,
1993 .link_power = azx_intel_link_power,
1996 static int azx_probe(struct pci_dev *pci,
1997 const struct pci_device_id *pci_id)
2000 struct snd_card *card;
2001 struct hda_intel *hda;
2003 bool schedule_probe;
2006 if (pci_match_id(driver_blacklist, pci)) {
2007 dev_info(&pci->dev, "Skipping the blacklisted device\n");
2011 if (dev >= SNDRV_CARDS)
2018 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2021 dev_err(&pci->dev, "Error creating card!\n");
2025 err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
2028 card->private_data = chip;
2029 hda = container_of(chip, struct hda_intel, chip);
2031 pci_set_drvdata(pci, card);
2033 err = register_vga_switcheroo(chip);
2035 dev_err(card->dev, "Error registering vga_switcheroo client\n");
2039 if (check_hdmi_disabled(pci)) {
2040 dev_info(card->dev, "VGA controller is disabled\n");
2041 dev_info(card->dev, "Delaying initialization\n");
2042 chip->disabled = true;
2045 schedule_probe = !chip->disabled;
2047 #ifdef CONFIG_SND_HDA_PATCH_LOADER
2048 if (patch[dev] && *patch[dev]) {
2049 dev_info(card->dev, "Applying patch firmware '%s'\n",
2051 err = request_firmware_nowait(THIS_MODULE, true, patch[dev],
2052 &pci->dev, GFP_KERNEL, card,
2056 schedule_probe = false; /* continued in azx_firmware_cb() */
2058 #endif /* CONFIG_SND_HDA_PATCH_LOADER */
2060 #ifndef CONFIG_SND_HDA_I915
2061 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
2062 dev_err(card->dev, "Haswell must build in CONFIG_SND_HDA_I915\n");
2066 schedule_work(&hda->probe_work);
2070 complete_all(&hda->probe_wait);
2074 snd_card_free(card);
2079 /* On some boards setting power_save to a non 0 value leads to clicking /
2080 * popping sounds when ever we enter/leave powersaving mode. Ideally we would
2081 * figure out how to avoid these sounds, but that is not always feasible.
2082 * So we keep a list of devices where we disable powersaving as its known
2083 * to causes problems on these devices.
2085 static struct snd_pci_quirk power_save_blacklist[] = {
2086 /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
2087 SND_PCI_QUIRK(0x1849, 0xc892, "Asrock B85M-ITX", 0),
2088 /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
2089 SND_PCI_QUIRK(0x1043, 0x8733, "Asus Prime X370-Pro", 0),
2090 /* https://bugzilla.redhat.com/show_bug.cgi?id=1572975 */
2091 SND_PCI_QUIRK(0x17aa, 0x36a7, "Lenovo C50 All in one", 0),
2092 /* https://bugzilla.kernel.org/show_bug.cgi?id=198611 */
2093 SND_PCI_QUIRK(0x17aa, 0x2227, "Lenovo X1 Carbon 3rd Gen", 0),
2096 #endif /* CONFIG_PM */
2098 /* number of codec slots for each chipset: 0 = default slots (i.e. 4) */
2099 static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] = {
2100 [AZX_DRIVER_NVIDIA] = 8,
2101 [AZX_DRIVER_TERA] = 1,
2104 static int azx_probe_continue(struct azx *chip)
2106 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
2107 struct hdac_bus *bus = azx_bus(chip);
2108 struct pci_dev *pci = chip->pci;
2109 int dev = chip->dev_index;
2113 to_hda_bus(bus)->bus_probing = 1;
2114 hda->probe_continued = 1;
2116 /* Request display power well for the HDA controller or codec. For
2117 * Haswell/Broadwell, both the display HDA controller and codec need
2118 * this power. For other platforms, like Baytrail/Braswell, only the
2119 * display codec needs the power and it can be released after probe.
2121 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
2122 /* HSW/BDW controllers need this power */
2123 if (CONTROLLER_IN_GPU(pci))
2124 hda->need_i915_power = 1;
2126 err = snd_hdac_i915_init(bus);
2128 /* if the controller is bound only with HDMI/DP
2129 * (for HSW and BDW), we need to abort the probe;
2130 * for other chips, still continue probing as other
2131 * codecs can be on the same link.
2133 if (CONTROLLER_IN_GPU(pci)) {
2134 dev_err(chip->card->dev,
2135 "HSW/BDW HD-audio HDMI/DP requires binding with gfx driver\n");
2141 err = snd_hdac_display_power(bus, true);
2143 dev_err(chip->card->dev,
2144 "Cannot turn on display power on i915\n");
2145 goto i915_power_fail;
2150 err = azx_first_init(chip);
2154 #ifdef CONFIG_SND_HDA_INPUT_BEEP
2155 chip->beep_mode = beep_mode[dev];
2158 /* create codec instances */
2159 err = azx_probe_codecs(chip, azx_max_codecs[chip->driver_type]);
2163 #ifdef CONFIG_SND_HDA_PATCH_LOADER
2165 err = snd_hda_load_patch(&chip->bus, chip->fw->size,
2170 release_firmware(chip->fw); /* no longer needed */
2175 if ((probe_only[dev] & 1) == 0) {
2176 err = azx_codec_configure(chip);
2181 err = snd_card_register(chip->card);
2186 azx_add_card_list(chip);
2191 const struct snd_pci_quirk *q;
2193 q = snd_pci_quirk_lookup(chip->pci, power_save_blacklist);
2195 dev_info(chip->card->dev, "device %04x:%04x is on the power_save blacklist, forcing power_save to 0\n",
2196 q->subvendor, q->subdevice);
2200 #endif /* CONFIG_PM */
2201 snd_hda_set_power_save(&chip->bus, val * 1000);
2202 if (azx_has_pm_runtime(chip) || hda->use_vga_switcheroo)
2203 pm_runtime_put_noidle(&pci->dev);
2206 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL
2207 && !hda->need_i915_power)
2208 snd_hdac_display_power(bus, false);
2212 hda->init_failed = 1;
2213 complete_all(&hda->probe_wait);
2214 to_hda_bus(bus)->bus_probing = 0;
2218 static void azx_remove(struct pci_dev *pci)
2220 struct snd_card *card = pci_get_drvdata(pci);
2222 struct hda_intel *hda;
2225 /* cancel the pending probing work */
2226 chip = card->private_data;
2227 hda = container_of(chip, struct hda_intel, chip);
2228 /* FIXME: below is an ugly workaround.
2229 * Both device_release_driver() and driver_probe_device()
2230 * take *both* the device's and its parent's lock before
2231 * calling the remove() and probe() callbacks. The codec
2232 * probe takes the locks of both the codec itself and its
2233 * parent, i.e. the PCI controller dev. Meanwhile, when
2234 * the PCI controller is unbound, it takes its lock, too
2235 * ==> ouch, a deadlock!
2236 * As a workaround, we unlock temporarily here the controller
2237 * device during cancel_work_sync() call.
2239 device_unlock(&pci->dev);
2240 cancel_work_sync(&hda->probe_work);
2241 device_lock(&pci->dev);
2243 snd_card_free(card);
2247 static void azx_shutdown(struct pci_dev *pci)
2249 struct snd_card *card = pci_get_drvdata(pci);
2254 chip = card->private_data;
2255 if (chip && chip->running)
2256 azx_stop_chip(chip);
2260 static const struct pci_device_id azx_ids[] = {
2262 { PCI_DEVICE(0x8086, 0x1c20),
2263 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
2265 { PCI_DEVICE(0x8086, 0x1d20),
2266 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
2268 { PCI_DEVICE(0x8086, 0x1e20),
2269 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
2271 { PCI_DEVICE(0x8086, 0x8c20),
2272 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2274 { PCI_DEVICE(0x8086, 0x8ca0),
2275 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2277 { PCI_DEVICE(0x8086, 0x8d20),
2278 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2279 { PCI_DEVICE(0x8086, 0x8d21),
2280 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2282 { PCI_DEVICE(0x8086, 0xa1f0),
2283 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
2284 { PCI_DEVICE(0x8086, 0xa270),
2285 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
2287 { PCI_DEVICE(0x8086, 0x9c20),
2288 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2290 { PCI_DEVICE(0x8086, 0x9c21),
2291 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2292 /* Wildcat Point-LP */
2293 { PCI_DEVICE(0x8086, 0x9ca0),
2294 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2296 { PCI_DEVICE(0x8086, 0xa170),
2297 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
2298 /* Sunrise Point-LP */
2299 { PCI_DEVICE(0x8086, 0x9d70),
2300 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
2302 { PCI_DEVICE(0x8086, 0xa171),
2303 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
2305 { PCI_DEVICE(0x8086, 0x9d71),
2306 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
2308 { PCI_DEVICE(0x8086, 0xa2f0),
2309 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
2310 /* Broxton-P(Apollolake) */
2311 { PCI_DEVICE(0x8086, 0x5a98),
2312 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BROXTON },
2314 { PCI_DEVICE(0x8086, 0x1a98),
2315 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BROXTON },
2317 { PCI_DEVICE(0x8086, 0x0a0c),
2318 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
2319 { PCI_DEVICE(0x8086, 0x0c0c),
2320 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
2321 { PCI_DEVICE(0x8086, 0x0d0c),
2322 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
2324 { PCI_DEVICE(0x8086, 0x160c),
2325 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_BROADWELL },
2327 { PCI_DEVICE(0x8086, 0x3b56),
2328 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
2330 { PCI_DEVICE(0x8086, 0x811b),
2331 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
2333 { PCI_DEVICE(0x8086, 0x080a),
2334 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
2336 { PCI_DEVICE(0x8086, 0x0f04),
2337 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BAYTRAIL },
2339 { PCI_DEVICE(0x8086, 0x2284),
2340 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BRASWELL },
2342 { PCI_DEVICE(0x8086, 0x2668),
2343 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2345 { PCI_DEVICE(0x8086, 0x27d8),
2346 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2348 { PCI_DEVICE(0x8086, 0x269a),
2349 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2351 { PCI_DEVICE(0x8086, 0x284b),
2352 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2354 { PCI_DEVICE(0x8086, 0x293e),
2355 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2357 { PCI_DEVICE(0x8086, 0x293f),
2358 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2360 { PCI_DEVICE(0x8086, 0x3a3e),
2361 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2363 { PCI_DEVICE(0x8086, 0x3a6e),
2364 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2366 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID),
2367 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2368 .class_mask = 0xffffff,
2369 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_NO_ALIGN_BUFSIZE },
2370 /* ATI SB 450/600/700/800/900 */
2371 { PCI_DEVICE(0x1002, 0x437b),
2372 .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB },
2373 { PCI_DEVICE(0x1002, 0x4383),
2374 .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB },
2376 { PCI_DEVICE(0x1022, 0x780d),
2377 .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_SB },
2379 { PCI_DEVICE(0x1022, 0x157a),
2380 .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_SB |
2381 AZX_DCAPS_PM_RUNTIME },
2383 { PCI_DEVICE(0x1022, 0x15e3),
2384 .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_SB |
2385 AZX_DCAPS_PM_RUNTIME },
2387 { PCI_DEVICE(0x1002, 0x0002),
2388 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2389 { PCI_DEVICE(0x1002, 0x1308),
2390 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2391 { PCI_DEVICE(0x1002, 0x157a),
2392 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2393 { PCI_DEVICE(0x1002, 0x15b3),
2394 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2395 { PCI_DEVICE(0x1002, 0x793b),
2396 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2397 { PCI_DEVICE(0x1002, 0x7919),
2398 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2399 { PCI_DEVICE(0x1002, 0x960f),
2400 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2401 { PCI_DEVICE(0x1002, 0x970f),
2402 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2403 { PCI_DEVICE(0x1002, 0x9840),
2404 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2405 { PCI_DEVICE(0x1002, 0xaa00),
2406 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2407 { PCI_DEVICE(0x1002, 0xaa08),
2408 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2409 { PCI_DEVICE(0x1002, 0xaa10),
2410 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2411 { PCI_DEVICE(0x1002, 0xaa18),
2412 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2413 { PCI_DEVICE(0x1002, 0xaa20),
2414 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2415 { PCI_DEVICE(0x1002, 0xaa28),
2416 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2417 { PCI_DEVICE(0x1002, 0xaa30),
2418 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2419 { PCI_DEVICE(0x1002, 0xaa38),
2420 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2421 { PCI_DEVICE(0x1002, 0xaa40),
2422 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2423 { PCI_DEVICE(0x1002, 0xaa48),
2424 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2425 { PCI_DEVICE(0x1002, 0xaa50),
2426 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2427 { PCI_DEVICE(0x1002, 0xaa58),
2428 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2429 { PCI_DEVICE(0x1002, 0xaa60),
2430 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2431 { PCI_DEVICE(0x1002, 0xaa68),
2432 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2433 { PCI_DEVICE(0x1002, 0xaa80),
2434 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2435 { PCI_DEVICE(0x1002, 0xaa88),
2436 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2437 { PCI_DEVICE(0x1002, 0xaa90),
2438 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2439 { PCI_DEVICE(0x1002, 0xaa98),
2440 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2441 { PCI_DEVICE(0x1002, 0x9902),
2442 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2443 { PCI_DEVICE(0x1002, 0xaaa0),
2444 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2445 { PCI_DEVICE(0x1002, 0xaaa8),
2446 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2447 { PCI_DEVICE(0x1002, 0xaab0),
2448 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2449 { PCI_DEVICE(0x1002, 0xaac0),
2450 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2451 { PCI_DEVICE(0x1002, 0xaac8),
2452 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2453 { PCI_DEVICE(0x1002, 0xaad8),
2454 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2455 { PCI_DEVICE(0x1002, 0xaae8),
2456 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2457 { PCI_DEVICE(0x1002, 0xaae0),
2458 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2459 { PCI_DEVICE(0x1002, 0xaaf0),
2460 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2461 /* VIA VT8251/VT8237A */
2462 { PCI_DEVICE(0x1106, 0x3288),
2463 .driver_data = AZX_DRIVER_VIA | AZX_DCAPS_POSFIX_VIA },
2464 /* VIA GFX VT7122/VX900 */
2465 { PCI_DEVICE(0x1106, 0x9170), .driver_data = AZX_DRIVER_GENERIC },
2466 /* VIA GFX VT6122/VX11 */
2467 { PCI_DEVICE(0x1106, 0x9140), .driver_data = AZX_DRIVER_GENERIC },
2469 { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS },
2471 { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI },
2473 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
2474 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2475 .class_mask = 0xffffff,
2476 .driver_data = AZX_DRIVER_NVIDIA | AZX_DCAPS_PRESET_NVIDIA },
2478 { PCI_DEVICE(0x6549, 0x1200),
2479 .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT },
2480 { PCI_DEVICE(0x6549, 0x2200),
2481 .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT },
2482 /* Creative X-Fi (CA0110-IBG) */
2484 { PCI_DEVICE(0x1102, 0x0010),
2485 .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
2486 { PCI_DEVICE(0x1102, 0x0012),
2487 .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
2488 #if !IS_ENABLED(CONFIG_SND_CTXFI)
2489 /* the following entry conflicts with snd-ctxfi driver,
2490 * as ctxfi driver mutates from HD-audio to native mode with
2491 * a special command sequence.
2493 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_ANY_ID),
2494 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2495 .class_mask = 0xffffff,
2496 .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND |
2497 AZX_DCAPS_NO_64BIT | AZX_DCAPS_POSFIX_LPIB },
2499 /* this entry seems still valid -- i.e. without emu20kx chip */
2500 { PCI_DEVICE(0x1102, 0x0009),
2501 .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND |
2502 AZX_DCAPS_NO_64BIT | AZX_DCAPS_POSFIX_LPIB },
2505 { PCI_DEVICE(0x13f6, 0x5011),
2506 .driver_data = AZX_DRIVER_CMEDIA |
2507 AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_SNOOP_OFF },
2509 { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC },
2510 /* VMware HDAudio */
2511 { PCI_DEVICE(0x15ad, 0x1977), .driver_data = AZX_DRIVER_GENERIC },
2512 /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */
2513 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID),
2514 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2515 .class_mask = 0xffffff,
2516 .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI },
2517 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID),
2518 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2519 .class_mask = 0xffffff,
2520 .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI },
2523 MODULE_DEVICE_TABLE(pci, azx_ids);
2525 /* pci_driver definition */
2526 static struct pci_driver azx_driver = {
2527 .name = KBUILD_MODNAME,
2528 .id_table = azx_ids,
2530 .remove = azx_remove,
2531 .shutdown = azx_shutdown,
2537 module_pci_driver(azx_driver);