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;
1314 chip->bus.shutdown = 1;
1318 static int azx_dev_free(struct snd_device *device)
1320 return azx_free(device->device_data);
1323 #ifdef SUPPORT_VGA_SWITCHEROO
1325 * Check of disabled HDMI controller by vga_switcheroo
1327 static struct pci_dev *get_bound_vga(struct pci_dev *pci)
1331 /* check only discrete GPU */
1332 switch (pci->vendor) {
1333 case PCI_VENDOR_ID_ATI:
1334 case PCI_VENDOR_ID_AMD:
1335 case PCI_VENDOR_ID_NVIDIA:
1336 if (pci->devfn == 1) {
1337 p = pci_get_domain_bus_and_slot(pci_domain_nr(pci->bus),
1338 pci->bus->number, 0);
1340 if ((p->class >> 8) == PCI_CLASS_DISPLAY_VGA)
1350 static bool check_hdmi_disabled(struct pci_dev *pci)
1352 bool vga_inactive = false;
1353 struct pci_dev *p = get_bound_vga(pci);
1356 if (vga_switcheroo_get_client_state(p) == VGA_SWITCHEROO_OFF)
1357 vga_inactive = true;
1360 return vga_inactive;
1362 #endif /* SUPPORT_VGA_SWITCHEROO */
1365 * white/black-listing for position_fix
1367 static struct snd_pci_quirk position_fix_list[] = {
1368 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
1369 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
1370 SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),
1371 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
1372 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB),
1373 SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB),
1374 SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB),
1375 SND_PCI_QUIRK(0x10de, 0xcb89, "Macbook Pro 7,1", POS_FIX_LPIB),
1376 SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB),
1377 SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB),
1378 SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),
1379 SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB),
1380 SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB),
1381 SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB),
1385 static int check_position_fix(struct azx *chip, int fix)
1387 const struct snd_pci_quirk *q;
1392 case POS_FIX_POSBUF:
1393 case POS_FIX_VIACOMBO:
1398 q = snd_pci_quirk_lookup(chip->pci, position_fix_list);
1400 dev_info(chip->card->dev,
1401 "position_fix set to %d for device %04x:%04x\n",
1402 q->value, q->subvendor, q->subdevice);
1406 /* Check VIA/ATI HD Audio Controller exist */
1407 if (chip->driver_caps & AZX_DCAPS_POSFIX_VIA) {
1408 dev_dbg(chip->card->dev, "Using VIACOMBO position fix\n");
1409 return POS_FIX_VIACOMBO;
1411 if (chip->driver_caps & AZX_DCAPS_POSFIX_LPIB) {
1412 dev_dbg(chip->card->dev, "Using LPIB position fix\n");
1413 return POS_FIX_LPIB;
1415 return POS_FIX_AUTO;
1418 static void assign_position_fix(struct azx *chip, int fix)
1420 static azx_get_pos_callback_t callbacks[] = {
1421 [POS_FIX_AUTO] = NULL,
1422 [POS_FIX_LPIB] = azx_get_pos_lpib,
1423 [POS_FIX_POSBUF] = azx_get_pos_posbuf,
1424 [POS_FIX_VIACOMBO] = azx_via_get_position,
1425 [POS_FIX_COMBO] = azx_get_pos_lpib,
1428 chip->get_position[0] = chip->get_position[1] = callbacks[fix];
1430 /* combo mode uses LPIB only for playback */
1431 if (fix == POS_FIX_COMBO)
1432 chip->get_position[1] = NULL;
1434 if (fix == POS_FIX_POSBUF &&
1435 (chip->driver_caps & AZX_DCAPS_COUNT_LPIB_DELAY)) {
1436 chip->get_delay[0] = chip->get_delay[1] =
1437 azx_get_delay_from_lpib;
1443 * black-lists for probe_mask
1445 static struct snd_pci_quirk probe_mask_list[] = {
1446 /* Thinkpad often breaks the controller communication when accessing
1447 * to the non-working (or non-existing) modem codec slot.
1449 SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01),
1450 SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01),
1451 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01),
1453 SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01),
1454 /* including bogus ALC268 in slot#2 that conflicts with ALC888 */
1455 SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01),
1456 /* forced codec slots */
1457 SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103),
1458 SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103),
1459 /* WinFast VP200 H (Teradici) user reported broken communication */
1460 SND_PCI_QUIRK(0x3a21, 0x040d, "WinFast VP200 H", 0x101),
1464 #define AZX_FORCE_CODEC_MASK 0x100
1466 static void check_probe_mask(struct azx *chip, int dev)
1468 const struct snd_pci_quirk *q;
1470 chip->codec_probe_mask = probe_mask[dev];
1471 if (chip->codec_probe_mask == -1) {
1472 q = snd_pci_quirk_lookup(chip->pci, probe_mask_list);
1474 dev_info(chip->card->dev,
1475 "probe_mask set to 0x%x for device %04x:%04x\n",
1476 q->value, q->subvendor, q->subdevice);
1477 chip->codec_probe_mask = q->value;
1481 /* check forced option */
1482 if (chip->codec_probe_mask != -1 &&
1483 (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) {
1484 azx_bus(chip)->codec_mask = chip->codec_probe_mask & 0xff;
1485 dev_info(chip->card->dev, "codec_mask forced to 0x%x\n",
1486 (int)azx_bus(chip)->codec_mask);
1491 * white/black-list for enable_msi
1493 static struct snd_pci_quirk msi_black_list[] = {
1494 SND_PCI_QUIRK(0x103c, 0x2191, "HP", 0), /* AMD Hudson */
1495 SND_PCI_QUIRK(0x103c, 0x2192, "HP", 0), /* AMD Hudson */
1496 SND_PCI_QUIRK(0x103c, 0x21f7, "HP", 0), /* AMD Hudson */
1497 SND_PCI_QUIRK(0x103c, 0x21fa, "HP", 0), /* AMD Hudson */
1498 SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */
1499 SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */
1500 SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */
1501 SND_PCI_QUIRK(0x1179, 0xfb44, "Toshiba Satellite C870", 0), /* AMD Hudson */
1502 SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */
1503 SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */
1507 static void check_msi(struct azx *chip)
1509 const struct snd_pci_quirk *q;
1511 if (enable_msi >= 0) {
1512 chip->msi = !!enable_msi;
1515 chip->msi = 1; /* enable MSI as default */
1516 q = snd_pci_quirk_lookup(chip->pci, msi_black_list);
1518 dev_info(chip->card->dev,
1519 "msi for device %04x:%04x set to %d\n",
1520 q->subvendor, q->subdevice, q->value);
1521 chip->msi = q->value;
1525 /* NVidia chipsets seem to cause troubles with MSI */
1526 if (chip->driver_caps & AZX_DCAPS_NO_MSI) {
1527 dev_info(chip->card->dev, "Disabling MSI\n");
1532 /* check the snoop mode availability */
1533 static void azx_check_snoop_available(struct azx *chip)
1535 int snoop = hda_snoop;
1538 dev_info(chip->card->dev, "Force to %s mode by module option\n",
1539 snoop ? "snoop" : "non-snoop");
1540 chip->snoop = snoop;
1541 chip->uc_buffer = !snoop;
1546 if (azx_get_snoop_type(chip) == AZX_SNOOP_TYPE_NONE &&
1547 chip->driver_type == AZX_DRIVER_VIA) {
1548 /* force to non-snoop mode for a new VIA controller
1552 pci_read_config_byte(chip->pci, 0x42, &val);
1553 if (!(val & 0x80) && (chip->pci->revision == 0x30 ||
1554 chip->pci->revision == 0x20))
1558 if (chip->driver_caps & AZX_DCAPS_SNOOP_OFF)
1561 chip->snoop = snoop;
1563 dev_info(chip->card->dev, "Force to non-snoop mode\n");
1564 /* C-Media requires non-cached pages only for CORB/RIRB */
1565 if (chip->driver_type != AZX_DRIVER_CMEDIA)
1566 chip->uc_buffer = true;
1570 static void azx_probe_work(struct work_struct *work)
1572 struct hda_intel *hda = container_of(work, struct hda_intel, probe_work);
1573 azx_probe_continue(&hda->chip);
1579 static const struct hdac_io_ops pci_hda_io_ops;
1580 static const struct hda_controller_ops pci_hda_ops;
1582 static int azx_create(struct snd_card *card, struct pci_dev *pci,
1583 int dev, unsigned int driver_caps,
1586 static struct snd_device_ops ops = {
1587 .dev_disconnect = azx_dev_disconnect,
1588 .dev_free = azx_dev_free,
1590 struct hda_intel *hda;
1596 err = pci_enable_device(pci);
1600 hda = kzalloc(sizeof(*hda), GFP_KERNEL);
1602 pci_disable_device(pci);
1607 mutex_init(&chip->open_mutex);
1610 chip->ops = &pci_hda_ops;
1611 chip->driver_caps = driver_caps;
1612 chip->driver_type = driver_caps & 0xff;
1614 chip->dev_index = dev;
1615 chip->jackpoll_ms = jackpoll_ms;
1616 INIT_LIST_HEAD(&chip->pcm_list);
1617 INIT_WORK(&hda->irq_pending_work, azx_irq_pending_work);
1618 INIT_LIST_HEAD(&hda->list);
1619 init_vga_switcheroo(chip);
1620 init_completion(&hda->probe_wait);
1622 assign_position_fix(chip, check_position_fix(chip, position_fix[dev]));
1624 check_probe_mask(chip, dev);
1626 chip->single_cmd = single_cmd;
1627 azx_check_snoop_available(chip);
1629 if (bdl_pos_adj[dev] < 0) {
1630 switch (chip->driver_type) {
1631 case AZX_DRIVER_ICH:
1632 case AZX_DRIVER_PCH:
1633 bdl_pos_adj[dev] = 1;
1636 bdl_pos_adj[dev] = 32;
1640 chip->bdl_pos_adj = bdl_pos_adj;
1642 err = azx_bus_init(chip, model[dev], &pci_hda_io_ops);
1645 pci_disable_device(pci);
1649 if (chip->driver_type == AZX_DRIVER_NVIDIA) {
1650 dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n");
1651 chip->bus.needs_damn_long_delay = 1;
1654 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
1656 dev_err(card->dev, "Error creating device [card]!\n");
1661 /* continue probing in work context as may trigger request module */
1662 INIT_WORK(&hda->probe_work, azx_probe_work);
1669 static int azx_first_init(struct azx *chip)
1671 int dev = chip->dev_index;
1672 struct pci_dev *pci = chip->pci;
1673 struct snd_card *card = chip->card;
1674 struct hdac_bus *bus = azx_bus(chip);
1676 unsigned short gcap;
1677 unsigned int dma_bits = 64;
1679 #if BITS_PER_LONG != 64
1680 /* Fix up base address on ULI M5461 */
1681 if (chip->driver_type == AZX_DRIVER_ULI) {
1683 pci_read_config_word(pci, 0x40, &tmp3);
1684 pci_write_config_word(pci, 0x40, tmp3 | 0x10);
1685 pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0);
1689 err = pci_request_regions(pci, "ICH HD audio");
1692 chip->region_requested = 1;
1694 bus->addr = pci_resource_start(pci, 0);
1695 bus->remap_addr = pci_ioremap_bar(pci, 0);
1696 if (bus->remap_addr == NULL) {
1697 dev_err(card->dev, "ioremap error\n");
1702 if (chip->driver_caps & AZX_DCAPS_NO_MSI64) {
1703 dev_dbg(card->dev, "Disabling 64bit MSI\n");
1704 pci->no_64bit_msi = true;
1706 if (pci_enable_msi(pci) < 0)
1710 pci_set_master(pci);
1711 synchronize_irq(bus->irq);
1713 gcap = azx_readw(chip, GCAP);
1714 dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap);
1716 /* AMD devices support 40 or 48bit DMA, take the safe one */
1717 if (chip->pci->vendor == PCI_VENDOR_ID_AMD)
1720 /* disable SB600 64bit support for safety */
1721 if (chip->pci->vendor == PCI_VENDOR_ID_ATI) {
1722 struct pci_dev *p_smbus;
1724 p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
1725 PCI_DEVICE_ID_ATI_SBX00_SMBUS,
1728 if (p_smbus->revision < 0x30)
1729 gcap &= ~AZX_GCAP_64OK;
1730 pci_dev_put(p_smbus);
1734 /* NVidia hardware normally only supports up to 40 bits of DMA */
1735 if (chip->pci->vendor == PCI_VENDOR_ID_NVIDIA)
1738 /* disable 64bit DMA address on some devices */
1739 if (chip->driver_caps & AZX_DCAPS_NO_64BIT) {
1740 dev_dbg(card->dev, "Disabling 64bit DMA\n");
1741 gcap &= ~AZX_GCAP_64OK;
1744 /* disable buffer size rounding to 128-byte multiples if supported */
1745 if (align_buffer_size >= 0)
1746 chip->align_buffer_size = !!align_buffer_size;
1748 if (chip->driver_caps & AZX_DCAPS_NO_ALIGN_BUFSIZE)
1749 chip->align_buffer_size = 0;
1751 chip->align_buffer_size = 1;
1754 /* allow 64bit DMA address if supported by H/W */
1755 if (!(gcap & AZX_GCAP_64OK))
1757 if (!dma_set_mask(&pci->dev, DMA_BIT_MASK(dma_bits))) {
1758 dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(dma_bits));
1760 dma_set_mask(&pci->dev, DMA_BIT_MASK(32));
1761 dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32));
1764 /* read number of streams from GCAP register instead of using
1767 chip->capture_streams = (gcap >> 8) & 0x0f;
1768 chip->playback_streams = (gcap >> 12) & 0x0f;
1769 if (!chip->playback_streams && !chip->capture_streams) {
1770 /* gcap didn't give any info, switching to old method */
1772 switch (chip->driver_type) {
1773 case AZX_DRIVER_ULI:
1774 chip->playback_streams = ULI_NUM_PLAYBACK;
1775 chip->capture_streams = ULI_NUM_CAPTURE;
1777 case AZX_DRIVER_ATIHDMI:
1778 case AZX_DRIVER_ATIHDMI_NS:
1779 chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
1780 chip->capture_streams = ATIHDMI_NUM_CAPTURE;
1782 case AZX_DRIVER_GENERIC:
1784 chip->playback_streams = ICH6_NUM_PLAYBACK;
1785 chip->capture_streams = ICH6_NUM_CAPTURE;
1789 chip->capture_index_offset = 0;
1790 chip->playback_index_offset = chip->capture_streams;
1791 chip->num_streams = chip->playback_streams + chip->capture_streams;
1793 /* initialize streams */
1794 err = azx_init_streams(chip);
1798 err = azx_alloc_stream_pages(chip);
1802 /* initialize chip */
1805 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
1806 struct hda_intel *hda;
1808 hda = container_of(chip, struct hda_intel, chip);
1809 haswell_set_bclk(hda);
1812 hda_intel_init_chip(chip, (probe_only[dev] & 2) == 0);
1814 /* codec detection */
1815 if (!azx_bus(chip)->codec_mask) {
1816 dev_err(card->dev, "no codecs found!\n");
1820 if (azx_acquire_irq(chip, 0) < 0)
1823 strcpy(card->driver, "HDA-Intel");
1824 strlcpy(card->shortname, driver_short_names[chip->driver_type],
1825 sizeof(card->shortname));
1826 snprintf(card->longname, sizeof(card->longname),
1827 "%s at 0x%lx irq %i",
1828 card->shortname, bus->addr, bus->irq);
1833 #ifdef CONFIG_SND_HDA_PATCH_LOADER
1834 /* callback from request_firmware_nowait() */
1835 static void azx_firmware_cb(const struct firmware *fw, void *context)
1837 struct snd_card *card = context;
1838 struct azx *chip = card->private_data;
1839 struct pci_dev *pci = chip->pci;
1842 dev_err(card->dev, "Cannot load firmware, aborting\n");
1847 if (!chip->disabled) {
1848 /* continue probing */
1849 if (azx_probe_continue(chip))
1855 snd_card_free(card);
1856 pci_set_drvdata(pci, NULL);
1861 * HDA controller ops.
1864 /* PCI register access. */
1865 static void pci_azx_writel(u32 value, u32 __iomem *addr)
1867 writel(value, addr);
1870 static u32 pci_azx_readl(u32 __iomem *addr)
1875 static void pci_azx_writew(u16 value, u16 __iomem *addr)
1877 writew(value, addr);
1880 static u16 pci_azx_readw(u16 __iomem *addr)
1885 static void pci_azx_writeb(u8 value, u8 __iomem *addr)
1887 writeb(value, addr);
1890 static u8 pci_azx_readb(u8 __iomem *addr)
1895 static int disable_msi_reset_irq(struct azx *chip)
1897 struct hdac_bus *bus = azx_bus(chip);
1900 free_irq(bus->irq, chip);
1902 pci_disable_msi(chip->pci);
1904 err = azx_acquire_irq(chip, 1);
1911 /* DMA page allocation helpers. */
1912 static int dma_alloc_pages(struct hdac_bus *bus,
1915 struct snd_dma_buffer *buf)
1917 struct azx *chip = bus_to_azx(bus);
1920 err = snd_dma_alloc_pages(type,
1925 mark_pages_wc(chip, buf, true);
1929 static void dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
1931 struct azx *chip = bus_to_azx(bus);
1933 mark_pages_wc(chip, buf, false);
1934 snd_dma_free_pages(buf);
1937 static int substream_alloc_pages(struct azx *chip,
1938 struct snd_pcm_substream *substream,
1941 struct azx_dev *azx_dev = get_azx_dev(substream);
1944 mark_runtime_wc(chip, azx_dev, substream, false);
1945 ret = snd_pcm_lib_malloc_pages(substream, size);
1948 mark_runtime_wc(chip, azx_dev, substream, true);
1952 static int substream_free_pages(struct azx *chip,
1953 struct snd_pcm_substream *substream)
1955 struct azx_dev *azx_dev = get_azx_dev(substream);
1956 mark_runtime_wc(chip, azx_dev, substream, false);
1957 return snd_pcm_lib_free_pages(substream);
1960 static void pcm_mmap_prepare(struct snd_pcm_substream *substream,
1961 struct vm_area_struct *area)
1964 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
1965 struct azx *chip = apcm->chip;
1966 if (chip->uc_buffer)
1967 area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
1971 static const struct hdac_io_ops pci_hda_io_ops = {
1972 .reg_writel = pci_azx_writel,
1973 .reg_readl = pci_azx_readl,
1974 .reg_writew = pci_azx_writew,
1975 .reg_readw = pci_azx_readw,
1976 .reg_writeb = pci_azx_writeb,
1977 .reg_readb = pci_azx_readb,
1978 .dma_alloc_pages = dma_alloc_pages,
1979 .dma_free_pages = dma_free_pages,
1982 static const struct hda_controller_ops pci_hda_ops = {
1983 .disable_msi_reset_irq = disable_msi_reset_irq,
1984 .substream_alloc_pages = substream_alloc_pages,
1985 .substream_free_pages = substream_free_pages,
1986 .pcm_mmap_prepare = pcm_mmap_prepare,
1987 .position_check = azx_position_check,
1988 .link_power = azx_intel_link_power,
1991 static int azx_probe(struct pci_dev *pci,
1992 const struct pci_device_id *pci_id)
1995 struct snd_card *card;
1996 struct hda_intel *hda;
1998 bool schedule_probe;
2001 if (dev >= SNDRV_CARDS)
2008 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2011 dev_err(&pci->dev, "Error creating card!\n");
2015 err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
2018 card->private_data = chip;
2019 hda = container_of(chip, struct hda_intel, chip);
2021 pci_set_drvdata(pci, card);
2023 err = register_vga_switcheroo(chip);
2025 dev_err(card->dev, "Error registering vga_switcheroo client\n");
2029 if (check_hdmi_disabled(pci)) {
2030 dev_info(card->dev, "VGA controller is disabled\n");
2031 dev_info(card->dev, "Delaying initialization\n");
2032 chip->disabled = true;
2035 schedule_probe = !chip->disabled;
2037 #ifdef CONFIG_SND_HDA_PATCH_LOADER
2038 if (patch[dev] && *patch[dev]) {
2039 dev_info(card->dev, "Applying patch firmware '%s'\n",
2041 err = request_firmware_nowait(THIS_MODULE, true, patch[dev],
2042 &pci->dev, GFP_KERNEL, card,
2046 schedule_probe = false; /* continued in azx_firmware_cb() */
2048 #endif /* CONFIG_SND_HDA_PATCH_LOADER */
2050 #ifndef CONFIG_SND_HDA_I915
2051 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
2052 dev_err(card->dev, "Haswell must build in CONFIG_SND_HDA_I915\n");
2056 schedule_work(&hda->probe_work);
2060 complete_all(&hda->probe_wait);
2064 snd_card_free(card);
2069 /* On some boards setting power_save to a non 0 value leads to clicking /
2070 * popping sounds when ever we enter/leave powersaving mode. Ideally we would
2071 * figure out how to avoid these sounds, but that is not always feasible.
2072 * So we keep a list of devices where we disable powersaving as its known
2073 * to causes problems on these devices.
2075 static struct snd_pci_quirk power_save_blacklist[] = {
2076 /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
2077 SND_PCI_QUIRK(0x1849, 0xc892, "Asrock B85M-ITX", 0),
2078 /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */
2079 SND_PCI_QUIRK(0x1043, 0x8733, "Asus Prime X370-Pro", 0),
2080 /* https://bugzilla.redhat.com/show_bug.cgi?id=1572975 */
2081 SND_PCI_QUIRK(0x17aa, 0x36a7, "Lenovo C50 All in one", 0),
2082 /* https://bugzilla.kernel.org/show_bug.cgi?id=198611 */
2083 SND_PCI_QUIRK(0x17aa, 0x2227, "Lenovo X1 Carbon 3rd Gen", 0),
2086 #endif /* CONFIG_PM */
2088 /* number of codec slots for each chipset: 0 = default slots (i.e. 4) */
2089 static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] = {
2090 [AZX_DRIVER_NVIDIA] = 8,
2091 [AZX_DRIVER_TERA] = 1,
2094 static int azx_probe_continue(struct azx *chip)
2096 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
2097 struct hdac_bus *bus = azx_bus(chip);
2098 struct pci_dev *pci = chip->pci;
2099 int dev = chip->dev_index;
2103 to_hda_bus(bus)->bus_probing = 1;
2104 hda->probe_continued = 1;
2106 /* Request display power well for the HDA controller or codec. For
2107 * Haswell/Broadwell, both the display HDA controller and codec need
2108 * this power. For other platforms, like Baytrail/Braswell, only the
2109 * display codec needs the power and it can be released after probe.
2111 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
2112 /* HSW/BDW controllers need this power */
2113 if (CONTROLLER_IN_GPU(pci))
2114 hda->need_i915_power = 1;
2116 err = snd_hdac_i915_init(bus);
2118 /* if the controller is bound only with HDMI/DP
2119 * (for HSW and BDW), we need to abort the probe;
2120 * for other chips, still continue probing as other
2121 * codecs can be on the same link.
2123 if (CONTROLLER_IN_GPU(pci)) {
2124 dev_err(chip->card->dev,
2125 "HSW/BDW HD-audio HDMI/DP requires binding with gfx driver\n");
2131 err = snd_hdac_display_power(bus, true);
2133 dev_err(chip->card->dev,
2134 "Cannot turn on display power on i915\n");
2135 goto i915_power_fail;
2140 err = azx_first_init(chip);
2144 #ifdef CONFIG_SND_HDA_INPUT_BEEP
2145 chip->beep_mode = beep_mode[dev];
2148 /* create codec instances */
2149 err = azx_probe_codecs(chip, azx_max_codecs[chip->driver_type]);
2153 #ifdef CONFIG_SND_HDA_PATCH_LOADER
2155 err = snd_hda_load_patch(&chip->bus, chip->fw->size,
2160 release_firmware(chip->fw); /* no longer needed */
2165 if ((probe_only[dev] & 1) == 0) {
2166 err = azx_codec_configure(chip);
2171 err = snd_card_register(chip->card);
2176 azx_add_card_list(chip);
2181 const struct snd_pci_quirk *q;
2183 q = snd_pci_quirk_lookup(chip->pci, power_save_blacklist);
2185 dev_info(chip->card->dev, "device %04x:%04x is on the power_save blacklist, forcing power_save to 0\n",
2186 q->subvendor, q->subdevice);
2190 #endif /* CONFIG_PM */
2191 snd_hda_set_power_save(&chip->bus, val * 1000);
2192 if (azx_has_pm_runtime(chip) || hda->use_vga_switcheroo)
2193 pm_runtime_put_noidle(&pci->dev);
2196 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL
2197 && !hda->need_i915_power)
2198 snd_hdac_display_power(bus, false);
2202 hda->init_failed = 1;
2203 complete_all(&hda->probe_wait);
2204 to_hda_bus(bus)->bus_probing = 0;
2208 static void azx_remove(struct pci_dev *pci)
2210 struct snd_card *card = pci_get_drvdata(pci);
2212 struct hda_intel *hda;
2215 /* cancel the pending probing work */
2216 chip = card->private_data;
2217 hda = container_of(chip, struct hda_intel, chip);
2218 /* FIXME: below is an ugly workaround.
2219 * Both device_release_driver() and driver_probe_device()
2220 * take *both* the device's and its parent's lock before
2221 * calling the remove() and probe() callbacks. The codec
2222 * probe takes the locks of both the codec itself and its
2223 * parent, i.e. the PCI controller dev. Meanwhile, when
2224 * the PCI controller is unbound, it takes its lock, too
2225 * ==> ouch, a deadlock!
2226 * As a workaround, we unlock temporarily here the controller
2227 * device during cancel_work_sync() call.
2229 device_unlock(&pci->dev);
2230 cancel_work_sync(&hda->probe_work);
2231 device_lock(&pci->dev);
2233 snd_card_free(card);
2237 static void azx_shutdown(struct pci_dev *pci)
2239 struct snd_card *card = pci_get_drvdata(pci);
2244 chip = card->private_data;
2245 if (chip && chip->running)
2246 azx_stop_chip(chip);
2250 static const struct pci_device_id azx_ids[] = {
2252 { PCI_DEVICE(0x8086, 0x1c20),
2253 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
2255 { PCI_DEVICE(0x8086, 0x1d20),
2256 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
2258 { PCI_DEVICE(0x8086, 0x1e20),
2259 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
2261 { PCI_DEVICE(0x8086, 0x8c20),
2262 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2264 { PCI_DEVICE(0x8086, 0x8ca0),
2265 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2267 { PCI_DEVICE(0x8086, 0x8d20),
2268 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2269 { PCI_DEVICE(0x8086, 0x8d21),
2270 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2272 { PCI_DEVICE(0x8086, 0xa1f0),
2273 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
2274 { PCI_DEVICE(0x8086, 0xa270),
2275 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
2277 { PCI_DEVICE(0x8086, 0x9c20),
2278 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2280 { PCI_DEVICE(0x8086, 0x9c21),
2281 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2282 /* Wildcat Point-LP */
2283 { PCI_DEVICE(0x8086, 0x9ca0),
2284 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2286 { PCI_DEVICE(0x8086, 0xa170),
2287 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
2288 /* Sunrise Point-LP */
2289 { PCI_DEVICE(0x8086, 0x9d70),
2290 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
2292 { PCI_DEVICE(0x8086, 0xa171),
2293 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
2295 { PCI_DEVICE(0x8086, 0x9d71),
2296 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
2298 { PCI_DEVICE(0x8086, 0xa2f0),
2299 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE },
2300 /* Broxton-P(Apollolake) */
2301 { PCI_DEVICE(0x8086, 0x5a98),
2302 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BROXTON },
2304 { PCI_DEVICE(0x8086, 0x1a98),
2305 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BROXTON },
2307 { PCI_DEVICE(0x8086, 0x0a0c),
2308 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
2309 { PCI_DEVICE(0x8086, 0x0c0c),
2310 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
2311 { PCI_DEVICE(0x8086, 0x0d0c),
2312 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
2314 { PCI_DEVICE(0x8086, 0x160c),
2315 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_BROADWELL },
2317 { PCI_DEVICE(0x8086, 0x3b56),
2318 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
2320 { PCI_DEVICE(0x8086, 0x811b),
2321 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
2323 { PCI_DEVICE(0x8086, 0x080a),
2324 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
2326 { PCI_DEVICE(0x8086, 0x0f04),
2327 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BAYTRAIL },
2329 { PCI_DEVICE(0x8086, 0x2284),
2330 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BRASWELL },
2332 { PCI_DEVICE(0x8086, 0x2668),
2333 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2335 { PCI_DEVICE(0x8086, 0x27d8),
2336 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2338 { PCI_DEVICE(0x8086, 0x269a),
2339 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2341 { PCI_DEVICE(0x8086, 0x284b),
2342 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2344 { PCI_DEVICE(0x8086, 0x293e),
2345 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2347 { PCI_DEVICE(0x8086, 0x293f),
2348 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2350 { PCI_DEVICE(0x8086, 0x3a3e),
2351 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2353 { PCI_DEVICE(0x8086, 0x3a6e),
2354 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
2356 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID),
2357 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2358 .class_mask = 0xffffff,
2359 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_NO_ALIGN_BUFSIZE },
2360 /* ATI SB 450/600/700/800/900 */
2361 { PCI_DEVICE(0x1002, 0x437b),
2362 .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB },
2363 { PCI_DEVICE(0x1002, 0x4383),
2364 .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB },
2366 { PCI_DEVICE(0x1022, 0x780d),
2367 .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_SB },
2369 { PCI_DEVICE(0x1022, 0x157a),
2370 .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_SB |
2371 AZX_DCAPS_PM_RUNTIME },
2373 { PCI_DEVICE(0x1022, 0x15e3),
2374 .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_SB |
2375 AZX_DCAPS_PM_RUNTIME },
2377 { PCI_DEVICE(0x1002, 0x0002),
2378 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2379 { PCI_DEVICE(0x1002, 0x1308),
2380 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2381 { PCI_DEVICE(0x1002, 0x157a),
2382 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2383 { PCI_DEVICE(0x1002, 0x15b3),
2384 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2385 { PCI_DEVICE(0x1002, 0x793b),
2386 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2387 { PCI_DEVICE(0x1002, 0x7919),
2388 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2389 { PCI_DEVICE(0x1002, 0x960f),
2390 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2391 { PCI_DEVICE(0x1002, 0x970f),
2392 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2393 { PCI_DEVICE(0x1002, 0x9840),
2394 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2395 { PCI_DEVICE(0x1002, 0xaa00),
2396 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2397 { PCI_DEVICE(0x1002, 0xaa08),
2398 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2399 { PCI_DEVICE(0x1002, 0xaa10),
2400 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2401 { PCI_DEVICE(0x1002, 0xaa18),
2402 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2403 { PCI_DEVICE(0x1002, 0xaa20),
2404 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2405 { PCI_DEVICE(0x1002, 0xaa28),
2406 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2407 { PCI_DEVICE(0x1002, 0xaa30),
2408 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2409 { PCI_DEVICE(0x1002, 0xaa38),
2410 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2411 { PCI_DEVICE(0x1002, 0xaa40),
2412 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2413 { PCI_DEVICE(0x1002, 0xaa48),
2414 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2415 { PCI_DEVICE(0x1002, 0xaa50),
2416 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2417 { PCI_DEVICE(0x1002, 0xaa58),
2418 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2419 { PCI_DEVICE(0x1002, 0xaa60),
2420 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2421 { PCI_DEVICE(0x1002, 0xaa68),
2422 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2423 { PCI_DEVICE(0x1002, 0xaa80),
2424 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2425 { PCI_DEVICE(0x1002, 0xaa88),
2426 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2427 { PCI_DEVICE(0x1002, 0xaa90),
2428 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2429 { PCI_DEVICE(0x1002, 0xaa98),
2430 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2431 { PCI_DEVICE(0x1002, 0x9902),
2432 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2433 { PCI_DEVICE(0x1002, 0xaaa0),
2434 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2435 { PCI_DEVICE(0x1002, 0xaaa8),
2436 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2437 { PCI_DEVICE(0x1002, 0xaab0),
2438 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2439 { PCI_DEVICE(0x1002, 0xaac0),
2440 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2441 { PCI_DEVICE(0x1002, 0xaac8),
2442 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2443 { PCI_DEVICE(0x1002, 0xaad8),
2444 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2445 { PCI_DEVICE(0x1002, 0xaae8),
2446 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2447 { PCI_DEVICE(0x1002, 0xaae0),
2448 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2449 { PCI_DEVICE(0x1002, 0xaaf0),
2450 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2451 /* VIA VT8251/VT8237A */
2452 { PCI_DEVICE(0x1106, 0x3288),
2453 .driver_data = AZX_DRIVER_VIA | AZX_DCAPS_POSFIX_VIA },
2454 /* VIA GFX VT7122/VX900 */
2455 { PCI_DEVICE(0x1106, 0x9170), .driver_data = AZX_DRIVER_GENERIC },
2456 /* VIA GFX VT6122/VX11 */
2457 { PCI_DEVICE(0x1106, 0x9140), .driver_data = AZX_DRIVER_GENERIC },
2459 { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS },
2461 { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI },
2463 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
2464 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2465 .class_mask = 0xffffff,
2466 .driver_data = AZX_DRIVER_NVIDIA | AZX_DCAPS_PRESET_NVIDIA },
2468 { PCI_DEVICE(0x6549, 0x1200),
2469 .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT },
2470 { PCI_DEVICE(0x6549, 0x2200),
2471 .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT },
2472 /* Creative X-Fi (CA0110-IBG) */
2474 { PCI_DEVICE(0x1102, 0x0010),
2475 .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
2476 { PCI_DEVICE(0x1102, 0x0012),
2477 .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
2478 #if !IS_ENABLED(CONFIG_SND_CTXFI)
2479 /* the following entry conflicts with snd-ctxfi driver,
2480 * as ctxfi driver mutates from HD-audio to native mode with
2481 * a special command sequence.
2483 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_ANY_ID),
2484 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2485 .class_mask = 0xffffff,
2486 .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND |
2487 AZX_DCAPS_NO_64BIT | AZX_DCAPS_POSFIX_LPIB },
2489 /* this entry seems still valid -- i.e. without emu20kx chip */
2490 { PCI_DEVICE(0x1102, 0x0009),
2491 .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND |
2492 AZX_DCAPS_NO_64BIT | AZX_DCAPS_POSFIX_LPIB },
2495 { PCI_DEVICE(0x13f6, 0x5011),
2496 .driver_data = AZX_DRIVER_CMEDIA |
2497 AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_SNOOP_OFF },
2499 { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC },
2500 /* VMware HDAudio */
2501 { PCI_DEVICE(0x15ad, 0x1977), .driver_data = AZX_DRIVER_GENERIC },
2502 /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */
2503 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID),
2504 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2505 .class_mask = 0xffffff,
2506 .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI },
2507 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID),
2508 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2509 .class_mask = 0xffffff,
2510 .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI },
2513 MODULE_DEVICE_TABLE(pci, azx_ids);
2515 /* pci_driver definition */
2516 static struct pci_driver azx_driver = {
2517 .name = KBUILD_MODNAME,
2518 .id_table = azx_ids,
2520 .remove = azx_remove,
2521 .shutdown = azx_shutdown,
2527 module_pci_driver(azx_driver);