blob: 4a0b228d70f7b4f46ae37b961549689fd6e0fa8f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 *
Takashi Iwaid01ce992007-07-27 16:52:19 +02003 * hda_intel.c - Implementation of primary alsa driver code base
4 * for Intel HD Audio.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * Copyright(c) 2004 Intel Corporation. All rights reserved.
7 *
8 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
9 * PeiSen Hou <pshou@realtek.com.tw>
10 *
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)
14 * any later version.
15 *
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
19 * more details.
20 *
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.
24 *
25 * CONTACTS:
26 *
27 * Matt Jared matt.jared@intel.com
28 * Andy Kopp andy.kopp@intel.com
29 * Dan Kogan dan.d.kogan@intel.com
30 *
31 * CHANGES:
32 *
33 * 2004.12.01 Major rewrite by tiwai, merged the work of pshou
34 *
35 */
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/delay.h>
38#include <linux/interrupt.h>
Randy Dunlap362775e2005-11-07 14:43:23 +010039#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/module.h>
Andrew Morton24982c52008-03-04 10:08:58 +010041#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/moduleparam.h>
43#include <linux/init.h>
44#include <linux/slab.h>
45#include <linux/pci.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010046#include <linux/mutex.h>
Takashi Iwai0cbf0092008-10-29 16:18:25 +010047#include <linux/reboot.h>
Takashi Iwai27fe48d92011-09-28 17:16:09 +020048#include <linux/io.h>
Mengdong Linb8dfc4622012-08-23 17:32:30 +080049#include <linux/pm_runtime.h>
Pierre-Louis Bossart5d890f52012-10-22 16:42:16 -050050#include <linux/clocksource.h>
51#include <linux/time.h>
Takashi Iwaif4c482a2012-12-04 15:09:23 +010052#include <linux/completion.h>
Pierre-Louis Bossart5d890f52012-10-22 16:42:16 -050053
Takashi Iwai27fe48d92011-09-28 17:16:09 +020054#ifdef CONFIG_X86
55/* for snoop control */
56#include <asm/pgtable.h>
57#include <asm/cacheflush.h>
58#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#include <sound/core.h>
60#include <sound/initval.h>
Takashi Iwai91219472012-04-26 12:13:25 +020061#include <linux/vgaarb.h>
Takashi Iwaia82d51e2012-04-26 12:23:42 +020062#include <linux/vga_switcheroo.h>
Takashi Iwai4918cda2012-08-09 12:33:28 +020063#include <linux/firmware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#include "hda_codec.h"
Wang Xingchao99a20082013-05-30 22:07:10 +080065#include "hda_i915.h"
Dylan Reid05e84872014-02-28 15:41:22 -080066#include "hda_controller.h"
Dylan Reid2538a4f2014-02-28 15:41:12 -080067#include "hda_priv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69
Takashi Iwai5aba4f82008-01-07 15:16:37 +010070static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
71static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
Rusty Russella67ff6a2011-12-15 13:49:36 +103072static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
Takashi Iwai5aba4f82008-01-07 15:16:37 +010073static char *model[SNDRV_CARDS];
Takashi Iwai1dac6692012-09-13 14:59:47 +020074static int position_fix[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
Takashi Iwai5c0d7bc2008-06-10 17:53:35 +020075static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
Takashi Iwai5aba4f82008-01-07 15:16:37 +010076static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
Takashi Iwaid4d9cd032008-12-19 15:19:11 +010077static int probe_only[SNDRV_CARDS];
David Henningsson26a6cb62012-10-09 15:04:21 +020078static int jackpoll_ms[SNDRV_CARDS];
Rusty Russella67ff6a2011-12-15 13:49:36 +103079static bool single_cmd;
Takashi Iwai716238552009-09-28 13:14:04 +020080static int enable_msi = -1;
Takashi Iwai4ea6fbc2009-06-17 09:52:54 +020081#ifdef CONFIG_SND_HDA_PATCH_LOADER
82static char *patch[SNDRV_CARDS];
83#endif
Jaroslav Kysela2dca0bb2009-11-13 18:41:52 +010084#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai0920c9b2012-07-03 16:58:48 +020085static bool beep_mode[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] =
Jaroslav Kysela2dca0bb2009-11-13 18:41:52 +010086 CONFIG_SND_HDA_INPUT_BEEP_MODE};
87#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Takashi Iwai5aba4f82008-01-07 15:16:37 +010089module_param_array(index, int, NULL, 0444);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090MODULE_PARM_DESC(index, "Index value for Intel HD audio interface.");
Takashi Iwai5aba4f82008-01-07 15:16:37 +010091module_param_array(id, charp, NULL, 0444);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092MODULE_PARM_DESC(id, "ID string for Intel HD audio interface.");
Takashi Iwai5aba4f82008-01-07 15:16:37 +010093module_param_array(enable, bool, NULL, 0444);
94MODULE_PARM_DESC(enable, "Enable Intel HD audio interface.");
95module_param_array(model, charp, NULL, 0444);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096MODULE_PARM_DESC(model, "Use the given board model.");
Takashi Iwai5aba4f82008-01-07 15:16:37 +010097module_param_array(position_fix, int, NULL, 0444);
David Henningsson4cb36312010-09-30 10:12:50 +020098MODULE_PARM_DESC(position_fix, "DMA pointer read method."
Takashi Iwai1dac6692012-09-13 14:59:47 +020099 "(-1 = system default, 0 = auto, 1 = LPIB, 2 = POSBUF, 3 = VIACOMBO, 4 = COMBO).");
Takashi Iwai555e2192008-06-10 17:53:34 +0200100module_param_array(bdl_pos_adj, int, NULL, 0644);
101MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset.");
Takashi Iwai5aba4f82008-01-07 15:16:37 +0100102module_param_array(probe_mask, int, NULL, 0444);
Takashi Iwai606ad752005-11-24 16:03:40 +0100103MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1).");
Jaroslav Kysela079e6832010-03-26 11:16:59 +0100104module_param_array(probe_only, int, NULL, 0444);
Takashi Iwaid4d9cd032008-12-19 15:19:11 +0100105MODULE_PARM_DESC(probe_only, "Only probing and no codec initialization.");
David Henningsson26a6cb62012-10-09 15:04:21 +0200106module_param_array(jackpoll_ms, int, NULL, 0444);
107MODULE_PARM_DESC(jackpoll_ms, "Ms between polling for jack events (default = 0, using unsol events only)");
Takashi Iwai27346162006-01-12 18:28:44 +0100108module_param(single_cmd, bool, 0444);
Takashi Iwaid01ce992007-07-27 16:52:19 +0200109MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs "
110 "(for debugging only).");
Takashi Iwaiac9ef6c2012-01-20 12:08:44 +0100111module_param(enable_msi, bint, 0444);
Takashi Iwai134a11f2006-11-10 12:08:37 +0100112MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)");
Takashi Iwai4ea6fbc2009-06-17 09:52:54 +0200113#ifdef CONFIG_SND_HDA_PATCH_LOADER
114module_param_array(patch, charp, NULL, 0444);
115MODULE_PARM_DESC(patch, "Patch file for Intel HD audio interface.");
116#endif
Jaroslav Kysela2dca0bb2009-11-13 18:41:52 +0100117#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai0920c9b2012-07-03 16:58:48 +0200118module_param_array(beep_mode, bool, NULL, 0444);
Jaroslav Kysela2dca0bb2009-11-13 18:41:52 +0100119MODULE_PARM_DESC(beep_mode, "Select HDA Beep registration mode "
Takashi Iwai0920c9b2012-07-03 16:58:48 +0200120 "(0=off, 1=on) (default=1).");
Jaroslav Kysela2dca0bb2009-11-13 18:41:52 +0100121#endif
Takashi Iwai606ad752005-11-24 16:03:40 +0100122
Takashi Iwai83012a72012-08-24 18:38:08 +0200123#ifdef CONFIG_PM
Takashi Iwai65fcd412012-08-14 17:13:32 +0200124static int param_set_xint(const char *val, const struct kernel_param *kp);
125static struct kernel_param_ops param_ops_xint = {
126 .set = param_set_xint,
127 .get = param_get_int,
128};
129#define param_check_xint param_check_int
130
Takashi Iwaifee2fba2008-11-27 12:43:28 +0100131static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
Dylan Reide62a42a2014-02-28 15:41:19 -0800132static int *power_save_addr = &power_save;
Takashi Iwai65fcd412012-08-14 17:13:32 +0200133module_param(power_save, xint, 0644);
Takashi Iwaifee2fba2008-11-27 12:43:28 +0100134MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
135 "(in second, 0 = disable).");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Takashi Iwaidee1b662007-08-13 16:10:30 +0200137/* reset the HD-audio controller in power save mode.
138 * this may give more power-saving, but will take longer time to
139 * wake up.
140 */
Takashi Iwai8fc24422013-04-04 15:35:24 +0200141static bool power_save_controller = 1;
142module_param(power_save_controller, bool, 0644);
Takashi Iwaidee1b662007-08-13 16:10:30 +0200143MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode.");
Dylan Reide62a42a2014-02-28 15:41:19 -0800144#else
145static int *power_save_addr;
Takashi Iwai83012a72012-08-24 18:38:08 +0200146#endif /* CONFIG_PM */
Takashi Iwaidee1b662007-08-13 16:10:30 +0200147
Takashi Iwai7bfe0592012-01-23 17:53:39 +0100148static int align_buffer_size = -1;
149module_param(align_buffer_size, bint, 0644);
Pierre-Louis Bossart2ae66c22011-08-04 10:12:56 -0500150MODULE_PARM_DESC(align_buffer_size,
151 "Force buffer and period sizes to be multiple of 128 bytes.");
152
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200153#ifdef CONFIG_X86
154static bool hda_snoop = true;
155module_param_named(snoop, hda_snoop, bool, 0444);
156MODULE_PARM_DESC(snoop, "Enable/disable snooping");
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200157#else
158#define hda_snoop true
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200159#endif
160
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162MODULE_LICENSE("GPL");
163MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
164 "{Intel, ICH6M},"
Jason Gaston2f1b3812005-05-01 08:58:50 -0700165 "{Intel, ICH7},"
Frederick Lif5d40b32005-05-12 14:55:20 +0200166 "{Intel, ESB2},"
Jason Gastond2981392006-01-10 11:07:37 +0100167 "{Intel, ICH8},"
Jason Gastonf9cc8a82006-11-22 11:53:52 +0100168 "{Intel, ICH9},"
Jason Gastonc34f5a02008-01-29 12:38:49 +0100169 "{Intel, ICH10},"
Seth Heasleyb29c2362008-08-08 15:56:39 -0700170 "{Intel, PCH},"
Seth Heasleyd2f2fcd2010-01-12 17:03:35 -0800171 "{Intel, CPT},"
Seth Heasleyd2edeb72011-04-20 10:59:57 -0700172 "{Intel, PPT},"
Seth Heasley8bc039a2012-01-23 16:24:31 -0800173 "{Intel, LPT},"
James Ralston144dad92012-08-09 09:38:59 -0700174 "{Intel, LPT_LP},"
James Ralston4eeca492013-11-04 09:27:45 -0800175 "{Intel, WPT_LP},"
Wang Xingchaoe926f2c2012-06-13 10:23:51 +0800176 "{Intel, HPT},"
Seth Heasleycea310e2010-09-10 16:29:56 -0700177 "{Intel, PBG},"
Tobin Davis4979bca2008-01-30 08:13:55 +0100178 "{Intel, SCH},"
Takashi Iwaifc20a562005-05-12 15:00:41 +0200179 "{ATI, SB450},"
Felix Kuehling89be83f2006-03-31 12:33:59 +0200180 "{ATI, SB600},"
Felix Kuehling778b6e12006-05-17 11:22:21 +0200181 "{ATI, RS600},"
Felix Kuehling5b15c952006-10-16 12:49:47 +0200182 "{ATI, RS690},"
Wolke Liue6db1112007-04-27 12:20:57 +0200183 "{ATI, RS780},"
184 "{ATI, R600},"
Herton Ronaldo Krzesinski2797f722007-11-05 18:21:56 +0100185 "{ATI, RV630},"
186 "{ATI, RV610},"
Wolke Liu27da1832007-11-16 11:06:30 +0100187 "{ATI, RV670},"
188 "{ATI, RV635},"
189 "{ATI, RV620},"
190 "{ATI, RV770},"
Takashi Iwaifc20a562005-05-12 15:00:41 +0200191 "{VIA, VT8251},"
Takashi Iwai47672312005-08-12 16:44:04 +0200192 "{VIA, VT8237A},"
Takashi Iwai07e4ca52005-08-24 14:14:57 +0200193 "{SiS, SIS966},"
194 "{ULI, M5461}}");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195MODULE_DESCRIPTION("Intel HDA driver");
196
Takashi Iwaia82d51e2012-04-26 12:23:42 +0200197#if defined(CONFIG_PM) && defined(CONFIG_VGA_SWITCHEROO)
Takashi Iwaif8f1bec2014-02-06 18:14:03 +0100198#if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI)
Takashi Iwaia82d51e2012-04-26 12:23:42 +0200199#define SUPPORT_VGA_SWITCHEROO
200#endif
201#endif
202
203
Takashi Iwaicb53c622007-08-10 17:21:45 +0200204/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Takashi Iwai07e4ca52005-08-24 14:14:57 +0200207/* driver types */
208enum {
209 AZX_DRIVER_ICH,
Seth Heasley32679f92010-02-22 17:31:09 -0800210 AZX_DRIVER_PCH,
Tobin Davis4979bca2008-01-30 08:13:55 +0100211 AZX_DRIVER_SCH,
Takashi Iwaifab12852013-11-05 17:54:05 +0100212 AZX_DRIVER_HDMI,
Takashi Iwai07e4ca52005-08-24 14:14:57 +0200213 AZX_DRIVER_ATI,
Felix Kuehling778b6e12006-05-17 11:22:21 +0200214 AZX_DRIVER_ATIHDMI,
Andiry Xu1815b342011-12-14 16:10:27 +0800215 AZX_DRIVER_ATIHDMI_NS,
Takashi Iwai07e4ca52005-08-24 14:14:57 +0200216 AZX_DRIVER_VIA,
217 AZX_DRIVER_SIS,
218 AZX_DRIVER_ULI,
Vinod Gda3fca22005-09-13 18:49:12 +0200219 AZX_DRIVER_NVIDIA,
Kailang Yangf2690022008-05-27 11:44:55 +0200220 AZX_DRIVER_TERA,
Takashi Iwai14d34f12010-10-21 09:03:25 +0200221 AZX_DRIVER_CTX,
Takashi Iwai5ae763b2012-05-08 10:34:08 +0200222 AZX_DRIVER_CTHDA,
Yang, Libinc4da29c2008-11-13 11:07:07 +0100223 AZX_DRIVER_GENERIC,
Takashi Iwai2f5983f2008-09-03 16:00:44 +0200224 AZX_NUM_DRIVERS, /* keep this as last entry */
Takashi Iwai07e4ca52005-08-24 14:14:57 +0200225};
226
Takashi Iwai2ea3c6a2012-11-19 20:03:37 +0100227/* quirks for Intel PCH */
Takashi Iwaid7dab4d2013-01-08 13:51:30 +0100228#define AZX_DCAPS_INTEL_PCH_NOPM \
Takashi Iwai2ea3c6a2012-11-19 20:03:37 +0100229 (AZX_DCAPS_SCH_SNOOP | AZX_DCAPS_BUFSIZE | \
Takashi Iwaid7dab4d2013-01-08 13:51:30 +0100230 AZX_DCAPS_COUNT_LPIB_DELAY)
231
232#define AZX_DCAPS_INTEL_PCH \
233 (AZX_DCAPS_INTEL_PCH_NOPM | AZX_DCAPS_PM_RUNTIME)
Takashi Iwai9477c582011-05-25 09:11:37 +0200234
Takashi Iwai33499a12013-11-05 17:34:46 +0100235#define AZX_DCAPS_INTEL_HASWELL \
236 (AZX_DCAPS_SCH_SNOOP | AZX_DCAPS_ALIGN_BUFSIZE | \
237 AZX_DCAPS_COUNT_LPIB_DELAY | AZX_DCAPS_PM_RUNTIME | \
238 AZX_DCAPS_I915_POWERWELL)
239
Takashi Iwai9477c582011-05-25 09:11:37 +0200240/* quirks for ATI SB / AMD Hudson */
241#define AZX_DCAPS_PRESET_ATI_SB \
242 (AZX_DCAPS_ATI_SNOOP | AZX_DCAPS_NO_TCSEL | \
243 AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB)
244
245/* quirks for ATI/AMD HDMI */
246#define AZX_DCAPS_PRESET_ATI_HDMI \
247 (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB)
248
249/* quirks for Nvidia */
250#define AZX_DCAPS_PRESET_NVIDIA \
Takashi Iwai7bfe0592012-01-23 17:53:39 +0100251 (AZX_DCAPS_NVIDIA_SNOOP | AZX_DCAPS_RIRB_DELAY | AZX_DCAPS_NO_MSI |\
Mike Travis49d9e772013-05-01 14:04:08 -0500252 AZX_DCAPS_ALIGN_BUFSIZE | AZX_DCAPS_NO_64BIT)
Takashi Iwai9477c582011-05-25 09:11:37 +0200253
Takashi Iwai5ae763b2012-05-08 10:34:08 +0200254#define AZX_DCAPS_PRESET_CTHDA \
255 (AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_4K_BDLE_BOUNDARY)
256
Takashi Iwaia82d51e2012-04-26 12:23:42 +0200257/*
258 * VGA-switcher support
259 */
260#ifdef SUPPORT_VGA_SWITCHEROO
Takashi Iwai5cb543d2012-08-09 13:49:23 +0200261#define use_vga_switcheroo(chip) ((chip)->use_vga_switcheroo)
262#else
263#define use_vga_switcheroo(chip) 0
264#endif
265
Takashi Iwai48c8b0e2012-12-07 07:40:35 +0100266static char *driver_short_names[] = {
Takashi Iwai07e4ca52005-08-24 14:14:57 +0200267 [AZX_DRIVER_ICH] = "HDA Intel",
Seth Heasley32679f92010-02-22 17:31:09 -0800268 [AZX_DRIVER_PCH] = "HDA Intel PCH",
Tobin Davis4979bca2008-01-30 08:13:55 +0100269 [AZX_DRIVER_SCH] = "HDA Intel MID",
Takashi Iwaifab12852013-11-05 17:54:05 +0100270 [AZX_DRIVER_HDMI] = "HDA Intel HDMI",
Takashi Iwai07e4ca52005-08-24 14:14:57 +0200271 [AZX_DRIVER_ATI] = "HDA ATI SB",
Felix Kuehling778b6e12006-05-17 11:22:21 +0200272 [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI",
Andiry Xu1815b342011-12-14 16:10:27 +0800273 [AZX_DRIVER_ATIHDMI_NS] = "HDA ATI HDMI",
Takashi Iwai07e4ca52005-08-24 14:14:57 +0200274 [AZX_DRIVER_VIA] = "HDA VIA VT82xx",
275 [AZX_DRIVER_SIS] = "HDA SIS966",
Vinod Gda3fca22005-09-13 18:49:12 +0200276 [AZX_DRIVER_ULI] = "HDA ULI M5461",
277 [AZX_DRIVER_NVIDIA] = "HDA NVidia",
Kailang Yangf2690022008-05-27 11:44:55 +0200278 [AZX_DRIVER_TERA] = "HDA Teradici",
Takashi Iwai14d34f12010-10-21 09:03:25 +0200279 [AZX_DRIVER_CTX] = "HDA Creative",
Takashi Iwai5ae763b2012-05-08 10:34:08 +0200280 [AZX_DRIVER_CTHDA] = "HDA Creative",
Yang, Libinc4da29c2008-11-13 11:07:07 +0100281 [AZX_DRIVER_GENERIC] = "HD-Audio Generic",
Takashi Iwai07e4ca52005-08-24 14:14:57 +0200282};
283
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200284#ifdef CONFIG_X86
Takashi Iwai9ddf1ae2013-01-29 18:07:22 +0100285static void __mark_pages_wc(struct azx *chip, struct snd_dma_buffer *dmab, bool on)
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200286{
Takashi Iwai9ddf1ae2013-01-29 18:07:22 +0100287 int pages;
288
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200289 if (azx_snoop(chip))
290 return;
Takashi Iwai9ddf1ae2013-01-29 18:07:22 +0100291 if (!dmab || !dmab->area || !dmab->bytes)
292 return;
293
294#ifdef CONFIG_SND_DMA_SGBUF
295 if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_SG) {
296 struct snd_sg_buf *sgbuf = dmab->private_data;
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200297 if (on)
Takashi Iwai9ddf1ae2013-01-29 18:07:22 +0100298 set_pages_array_wc(sgbuf->page_table, sgbuf->pages);
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200299 else
Takashi Iwai9ddf1ae2013-01-29 18:07:22 +0100300 set_pages_array_wb(sgbuf->page_table, sgbuf->pages);
301 return;
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200302 }
Takashi Iwai9ddf1ae2013-01-29 18:07:22 +0100303#endif
304
305 pages = (dmab->bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
306 if (on)
307 set_memory_wc((unsigned long)dmab->area, pages);
308 else
309 set_memory_wb((unsigned long)dmab->area, pages);
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200310}
311
312static inline void mark_pages_wc(struct azx *chip, struct snd_dma_buffer *buf,
313 bool on)
314{
Takashi Iwai9ddf1ae2013-01-29 18:07:22 +0100315 __mark_pages_wc(chip, buf, on);
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200316}
317static inline void mark_runtime_wc(struct azx *chip, struct azx_dev *azx_dev,
Takashi Iwai9ddf1ae2013-01-29 18:07:22 +0100318 struct snd_pcm_substream *substream, bool on)
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200319{
320 if (azx_dev->wc_marked != on) {
Takashi Iwai9ddf1ae2013-01-29 18:07:22 +0100321 __mark_pages_wc(chip, snd_pcm_get_dma_buf(substream), on);
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200322 azx_dev->wc_marked = on;
323 }
324}
325#else
326/* NOP for other archs */
327static inline void mark_pages_wc(struct azx *chip, struct snd_dma_buffer *buf,
328 bool on)
329{
330}
331static inline void mark_runtime_wc(struct azx *chip, struct azx_dev *azx_dev,
Takashi Iwai9ddf1ae2013-01-29 18:07:22 +0100332 struct snd_pcm_substream *substream, bool on)
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200333{
334}
335#endif
336
Takashi Iwai68e7fff2006-10-23 13:40:59 +0200337static int azx_acquire_irq(struct azx *chip, int do_disconnect);
Maxim Levitsky1eb6dc72010-02-04 22:21:47 +0200338static int azx_send_cmd(struct hda_bus *bus, unsigned int val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339/*
340 * Interface for HD codec
341 */
342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343/*
344 * CORB / RIRB interface
345 */
Takashi Iwaia98f90f2005-11-17 14:59:02 +0100346static int azx_alloc_cmd_io(struct azx *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
348 int err;
349
350 /* single page (at least 4096 bytes) must suffice for both ringbuffes */
Dylan Reidb419b352014-02-28 15:41:20 -0800351 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
352 PAGE_SIZE, &chip->rb);
353 if (err < 0)
Takashi Iwai4e76a882014-02-25 12:21:03 +0100354 dev_err(chip->card->dev, "cannot allocate CORB/RIRB\n");
Dylan Reidb419b352014-02-28 15:41:20 -0800355 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356}
357
Takashi Iwaia98f90f2005-11-17 14:59:02 +0100358static void azx_init_cmd_io(struct azx *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
David Henningssonca460f82014-02-28 07:56:58 +0100360 int timeout;
361
Wu Fengguangcdb1fbf2009-08-01 18:47:41 +0800362 spin_lock_irq(&chip->reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 /* CORB set up */
364 chip->corb.addr = chip->rb.addr;
365 chip->corb.buf = (u32 *)chip->rb.area;
366 azx_writel(chip, CORBLBASE, (u32)chip->corb.addr);
Takashi Iwai766979e2008-06-13 20:53:56 +0200367 azx_writel(chip, CORBUBASE, upper_32_bits(chip->corb.addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Takashi Iwai07e4ca52005-08-24 14:14:57 +0200369 /* set the corb size to 256 entries (ULI requires explicitly) */
370 azx_writeb(chip, CORBSIZE, 0x02);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 /* set the corb write pointer to 0 */
372 azx_writew(chip, CORBWP, 0);
David Henningssonca460f82014-02-28 07:56:58 +0100373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 /* reset the corb hw read pointer */
Takashi Iwaib21fadb2009-05-28 12:26:15 +0200375 azx_writew(chip, CORBRP, ICH6_CORBRP_RST);
David Henningssonca460f82014-02-28 07:56:58 +0100376 for (timeout = 1000; timeout > 0; timeout--) {
377 if ((azx_readw(chip, CORBRP) & ICH6_CORBRP_RST) == ICH6_CORBRP_RST)
378 break;
379 udelay(1);
380 }
381 if (timeout <= 0)
382 dev_err(chip->card->dev, "CORB reset timeout#1, CORBRP = %d\n",
383 azx_readw(chip, CORBRP));
384
385 azx_writew(chip, CORBRP, 0);
386 for (timeout = 1000; timeout > 0; timeout--) {
387 if (azx_readw(chip, CORBRP) == 0)
388 break;
389 udelay(1);
390 }
391 if (timeout <= 0)
392 dev_err(chip->card->dev, "CORB reset timeout#2, CORBRP = %d\n",
393 azx_readw(chip, CORBRP));
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 /* enable corb dma */
Takashi Iwaib21fadb2009-05-28 12:26:15 +0200396 azx_writeb(chip, CORBCTL, ICH6_CORBCTL_RUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 /* RIRB set up */
399 chip->rirb.addr = chip->rb.addr + 2048;
400 chip->rirb.buf = (u32 *)(chip->rb.area + 2048);
Wu Fengguangdeadff12009-08-01 18:45:16 +0800401 chip->rirb.wp = chip->rirb.rp = 0;
402 memset(chip->rirb.cmds, 0, sizeof(chip->rirb.cmds));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr);
Takashi Iwai766979e2008-06-13 20:53:56 +0200404 azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Takashi Iwai07e4ca52005-08-24 14:14:57 +0200406 /* set the rirb size to 256 entries (ULI requires explicitly) */
407 azx_writeb(chip, RIRBSIZE, 0x02);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 /* reset the rirb hw write pointer */
Takashi Iwaib21fadb2009-05-28 12:26:15 +0200409 azx_writew(chip, RIRBWP, ICH6_RIRBWP_RST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 /* set N=1, get RIRB response interrupt for new entry */
Takashi Iwai9477c582011-05-25 09:11:37 +0200411 if (chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND)
Takashi Iwai14d34f12010-10-21 09:03:25 +0200412 azx_writew(chip, RINTCNT, 0xc0);
413 else
414 azx_writew(chip, RINTCNT, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 /* enable rirb dma and response irq */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 azx_writeb(chip, RIRBCTL, ICH6_RBCTL_DMA_EN | ICH6_RBCTL_IRQ_EN);
Wu Fengguangcdb1fbf2009-08-01 18:47:41 +0800417 spin_unlock_irq(&chip->reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418}
419
Takashi Iwaia98f90f2005-11-17 14:59:02 +0100420static void azx_free_cmd_io(struct azx *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
Wu Fengguangcdb1fbf2009-08-01 18:47:41 +0800422 spin_lock_irq(&chip->reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 /* disable ringbuffer DMAs */
424 azx_writeb(chip, RIRBCTL, 0);
425 azx_writeb(chip, CORBCTL, 0);
Wu Fengguangcdb1fbf2009-08-01 18:47:41 +0800426 spin_unlock_irq(&chip->reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428
Wu Fengguangdeadff12009-08-01 18:45:16 +0800429static unsigned int azx_command_addr(u32 cmd)
430{
431 unsigned int addr = cmd >> 28;
432
433 if (addr >= AZX_MAX_CODECS) {
434 snd_BUG();
435 addr = 0;
436 }
437
438 return addr;
439}
440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441/* send a command */
Takashi Iwai33fa35e2008-11-06 16:50:40 +0100442static int azx_corb_send_cmd(struct hda_bus *bus, u32 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443{
Takashi Iwai33fa35e2008-11-06 16:50:40 +0100444 struct azx *chip = bus->private_data;
Wu Fengguangdeadff12009-08-01 18:45:16 +0800445 unsigned int addr = azx_command_addr(val);
Takashi Iwai3bcce5c2012-12-20 11:17:17 +0100446 unsigned int wp, rp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Wu Fengguangc32649f2009-08-01 18:48:12 +0800448 spin_lock_irq(&chip->reg_lock);
449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 /* add command to corb */
Takashi Iwaicc5ede32012-12-12 11:10:49 +0100451 wp = azx_readw(chip, CORBWP);
452 if (wp == 0xffff) {
453 /* something wrong, controller likely turned to D3 */
454 spin_unlock_irq(&chip->reg_lock);
Takashi Iwai3bcce5c2012-12-20 11:17:17 +0100455 return -EIO;
Takashi Iwaicc5ede32012-12-12 11:10:49 +0100456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 wp++;
458 wp %= ICH6_MAX_CORB_ENTRIES;
459
Takashi Iwai3bcce5c2012-12-20 11:17:17 +0100460 rp = azx_readw(chip, CORBRP);
461 if (wp == rp) {
462 /* oops, it's full */
463 spin_unlock_irq(&chip->reg_lock);
464 return -EAGAIN;
465 }
466
Wu Fengguangdeadff12009-08-01 18:45:16 +0800467 chip->rirb.cmds[addr]++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 chip->corb.buf[wp] = cpu_to_le32(val);
David Henningssonca460f82014-02-28 07:56:58 +0100469 azx_writew(chip, CORBWP, wp);
Wu Fengguangc32649f2009-08-01 18:48:12 +0800470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 spin_unlock_irq(&chip->reg_lock);
472
473 return 0;
474}
475
476#define ICH6_RIRB_EX_UNSOL_EV (1<<4)
477
478/* retrieve RIRB entry - called from interrupt handler */
Takashi Iwaia98f90f2005-11-17 14:59:02 +0100479static void azx_update_rirb(struct azx *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
481 unsigned int rp, wp;
Wu Fengguangdeadff12009-08-01 18:45:16 +0800482 unsigned int addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 u32 res, res_ex;
484
Takashi Iwaicc5ede32012-12-12 11:10:49 +0100485 wp = azx_readw(chip, RIRBWP);
486 if (wp == 0xffff) {
487 /* something wrong, controller likely turned to D3 */
488 return;
489 }
490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 if (wp == chip->rirb.wp)
492 return;
493 chip->rirb.wp = wp;
Wu Fengguangdeadff12009-08-01 18:45:16 +0800494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 while (chip->rirb.rp != wp) {
496 chip->rirb.rp++;
497 chip->rirb.rp %= ICH6_MAX_RIRB_ENTRIES;
498
499 rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */
500 res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]);
501 res = le32_to_cpu(chip->rirb.buf[rp]);
David Henningsson3d692452014-01-29 13:12:31 +0100502 addr = res_ex & 0xf;
503 if ((addr >= AZX_MAX_CODECS) || !(chip->codec_mask & (1 << addr))) {
Takashi Iwai4e76a882014-02-25 12:21:03 +0100504 dev_err(chip->card->dev, "spurious response %#x:%#x, rp = %d, wp = %d",
505 res, res_ex,
506 chip->rirb.rp, wp);
David Henningsson3d692452014-01-29 13:12:31 +0100507 snd_BUG();
508 }
509 else if (res_ex & ICH6_RIRB_EX_UNSOL_EV)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 snd_hda_queue_unsol_event(chip->bus, res, res_ex);
Wu Fengguangdeadff12009-08-01 18:45:16 +0800511 else if (chip->rirb.cmds[addr]) {
512 chip->rirb.res[addr] = res;
Takashi Iwai2add9b92008-03-18 09:47:06 +0100513 smp_wmb();
Wu Fengguangdeadff12009-08-01 18:45:16 +0800514 chip->rirb.cmds[addr]--;
Joe Perches3b70a672013-11-07 11:55:15 -0800515 } else if (printk_ratelimit()) {
Takashi Iwai4e76a882014-02-25 12:21:03 +0100516 dev_err(chip->card->dev, "spurious response %#x:%#x, last cmd=%#08x\n",
517 res, res_ex,
518 chip->last_cmd[addr]);
Joe Perches3b70a672013-11-07 11:55:15 -0800519 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 }
521}
522
523/* receive a response */
Wu Fengguangdeadff12009-08-01 18:45:16 +0800524static unsigned int azx_rirb_get_response(struct hda_bus *bus,
525 unsigned int addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526{
Takashi Iwai33fa35e2008-11-06 16:50:40 +0100527 struct azx *chip = bus->private_data;
Takashi Iwai5c79b1f2006-09-21 13:34:13 +0200528 unsigned long timeout;
David Henningsson32cf4022012-05-04 11:05:55 +0200529 unsigned long loopcounter;
Maxim Levitsky1eb6dc72010-02-04 22:21:47 +0200530 int do_poll = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Takashi Iwai5c79b1f2006-09-21 13:34:13 +0200532 again:
533 timeout = jiffies + msecs_to_jiffies(1000);
David Henningsson32cf4022012-05-04 11:05:55 +0200534
535 for (loopcounter = 0;; loopcounter++) {
Maxim Levitsky1eb6dc72010-02-04 22:21:47 +0200536 if (chip->polling_mode || do_poll) {
Takashi Iwaie96224a2006-08-21 17:57:44 +0200537 spin_lock_irq(&chip->reg_lock);
538 azx_update_rirb(chip);
539 spin_unlock_irq(&chip->reg_lock);
540 }
Wu Fengguangdeadff12009-08-01 18:45:16 +0800541 if (!chip->rirb.cmds[addr]) {
Takashi Iwai2add9b92008-03-18 09:47:06 +0100542 smp_rmb();
Takashi Iwaib6132912009-03-24 07:36:09 +0100543 bus->rirb_error = 0;
Maxim Levitsky1eb6dc72010-02-04 22:21:47 +0200544
545 if (!do_poll)
546 chip->poll_count = 0;
Wu Fengguangdeadff12009-08-01 18:45:16 +0800547 return chip->rirb.res[addr]; /* the last value */
Takashi Iwai2add9b92008-03-18 09:47:06 +0100548 }
Takashi Iwai28a0d9d2008-01-18 15:32:32 +0100549 if (time_after(jiffies, timeout))
550 break;
David Henningsson32cf4022012-05-04 11:05:55 +0200551 if (bus->needs_damn_long_delay || loopcounter > 3000)
Takashi Iwai52987652008-01-16 16:09:47 +0100552 msleep(2); /* temporary workaround */
553 else {
554 udelay(10);
555 cond_resched();
556 }
Takashi Iwai28a0d9d2008-01-18 15:32:32 +0100557 }
Takashi Iwai5c79b1f2006-09-21 13:34:13 +0200558
Takashi Iwai63e51fd2013-06-06 14:20:19 +0200559 if (!bus->no_response_fallback)
560 return -1;
561
Maxim Levitsky1eb6dc72010-02-04 22:21:47 +0200562 if (!chip->polling_mode && chip->poll_count < 2) {
Takashi Iwai4e76a882014-02-25 12:21:03 +0100563 dev_dbg(chip->card->dev,
564 "azx_get_response timeout, polling the codec once: last cmd=0x%08x\n",
565 chip->last_cmd[addr]);
Maxim Levitsky1eb6dc72010-02-04 22:21:47 +0200566 do_poll = 1;
567 chip->poll_count++;
568 goto again;
569 }
570
571
Takashi Iwai23c4a882009-10-30 13:21:49 +0100572 if (!chip->polling_mode) {
Takashi Iwai4e76a882014-02-25 12:21:03 +0100573 dev_warn(chip->card->dev,
574 "azx_get_response timeout, switching to polling mode: last cmd=0x%08x\n",
575 chip->last_cmd[addr]);
Takashi Iwai23c4a882009-10-30 13:21:49 +0100576 chip->polling_mode = 1;
577 goto again;
578 }
579
Takashi Iwai68e7fff2006-10-23 13:40:59 +0200580 if (chip->msi) {
Takashi Iwai4e76a882014-02-25 12:21:03 +0100581 dev_warn(chip->card->dev,
582 "No response from codec, disabling MSI: last cmd=0x%08x\n",
583 chip->last_cmd[addr]);
Dylan Reidf46ea602014-02-28 15:41:16 -0800584 if (chip->ops->disable_msi_reset_irq &&
585 chip->ops->disable_msi_reset_irq(chip) < 0) {
Takashi Iwaib6132912009-03-24 07:36:09 +0100586 bus->rirb_error = 1;
Takashi Iwai68e7fff2006-10-23 13:40:59 +0200587 return -1;
Takashi Iwaib6132912009-03-24 07:36:09 +0100588 }
Takashi Iwai68e7fff2006-10-23 13:40:59 +0200589 goto again;
590 }
591
Takashi Iwai6ce4a3b2008-11-06 17:11:10 +0100592 if (chip->probing) {
593 /* If this critical timeout happens during the codec probing
594 * phase, this is likely an access to a non-existing codec
595 * slot. Better to return an error and reset the system.
596 */
597 return -1;
598 }
599
Takashi Iwai8dd78332009-06-02 01:16:07 +0200600 /* a fatal communication error; need either to reset or to fallback
601 * to the single_cmd mode
602 */
Takashi Iwaib6132912009-03-24 07:36:09 +0100603 bus->rirb_error = 1;
Takashi Iwaib20f3b82009-06-02 01:20:22 +0200604 if (bus->allow_bus_reset && !bus->response_reset && !bus->in_reset) {
Takashi Iwai8dd78332009-06-02 01:16:07 +0200605 bus->response_reset = 1;
606 return -1; /* give a chance to retry */
607 }
608
Takashi Iwai4e76a882014-02-25 12:21:03 +0100609 dev_err(chip->card->dev,
610 "azx_get_response timeout, switching to single_cmd mode: last cmd=0x%08x\n",
611 chip->last_cmd[addr]);
Takashi Iwai8dd78332009-06-02 01:16:07 +0200612 chip->single_cmd = 1;
613 bus->response_reset = 0;
Takashi Iwai1a696972009-11-07 09:49:04 +0100614 /* release CORB/RIRB */
Takashi Iwai4fcd3922009-05-25 18:34:52 +0200615 azx_free_cmd_io(chip);
Takashi Iwai1a696972009-11-07 09:49:04 +0100616 /* disable unsolicited responses */
617 azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_UNSOL);
Takashi Iwai5c79b1f2006-09-21 13:34:13 +0200618 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619}
620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621/*
622 * Use the single immediate command instead of CORB/RIRB for simplicity
623 *
624 * Note: according to Intel, this is not preferred use. The command was
625 * intended for the BIOS only, and may get confused with unsolicited
626 * responses. So, we shouldn't use it for normal operation from the
627 * driver.
628 * I left the codes, however, for debugging/testing purposes.
629 */
630
Takashi Iwaib05a7d42009-05-28 11:59:12 +0200631/* receive a response */
Wu Fengguangdeadff12009-08-01 18:45:16 +0800632static int azx_single_wait_for_response(struct azx *chip, unsigned int addr)
Takashi Iwaib05a7d42009-05-28 11:59:12 +0200633{
634 int timeout = 50;
635
636 while (timeout--) {
637 /* check IRV busy bit */
638 if (azx_readw(chip, IRS) & ICH6_IRS_VALID) {
639 /* reuse rirb.res as the response return value */
Wu Fengguangdeadff12009-08-01 18:45:16 +0800640 chip->rirb.res[addr] = azx_readl(chip, IR);
Takashi Iwaib05a7d42009-05-28 11:59:12 +0200641 return 0;
642 }
643 udelay(1);
644 }
645 if (printk_ratelimit())
Takashi Iwai4e76a882014-02-25 12:21:03 +0100646 dev_dbg(chip->card->dev, "get_response timeout: IRS=0x%x\n",
647 azx_readw(chip, IRS));
Wu Fengguangdeadff12009-08-01 18:45:16 +0800648 chip->rirb.res[addr] = -1;
Takashi Iwaib05a7d42009-05-28 11:59:12 +0200649 return -EIO;
650}
651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652/* send a command */
Takashi Iwai33fa35e2008-11-06 16:50:40 +0100653static int azx_single_send_cmd(struct hda_bus *bus, u32 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654{
Takashi Iwai33fa35e2008-11-06 16:50:40 +0100655 struct azx *chip = bus->private_data;
Wu Fengguangdeadff12009-08-01 18:45:16 +0800656 unsigned int addr = azx_command_addr(val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 int timeout = 50;
658
Takashi Iwai8dd78332009-06-02 01:16:07 +0200659 bus->rirb_error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 while (timeout--) {
661 /* check ICB busy bit */
Takashi Iwaid01ce992007-07-27 16:52:19 +0200662 if (!((azx_readw(chip, IRS) & ICH6_IRS_BUSY))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 /* Clear IRV valid bit */
Takashi Iwaid01ce992007-07-27 16:52:19 +0200664 azx_writew(chip, IRS, azx_readw(chip, IRS) |
665 ICH6_IRS_VALID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 azx_writel(chip, IC, val);
Takashi Iwaid01ce992007-07-27 16:52:19 +0200667 azx_writew(chip, IRS, azx_readw(chip, IRS) |
668 ICH6_IRS_BUSY);
Wu Fengguangdeadff12009-08-01 18:45:16 +0800669 return azx_single_wait_for_response(chip, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 }
671 udelay(1);
672 }
Marc Boucher1cfd52b2008-01-22 15:29:26 +0100673 if (printk_ratelimit())
Takashi Iwai4e76a882014-02-25 12:21:03 +0100674 dev_dbg(chip->card->dev,
675 "send_cmd timeout: IRS=0x%x, val=0x%x\n",
676 azx_readw(chip, IRS), val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 return -EIO;
678}
679
680/* receive a response */
Wu Fengguangdeadff12009-08-01 18:45:16 +0800681static unsigned int azx_single_get_response(struct hda_bus *bus,
682 unsigned int addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683{
Takashi Iwai33fa35e2008-11-06 16:50:40 +0100684 struct azx *chip = bus->private_data;
Wu Fengguangdeadff12009-08-01 18:45:16 +0800685 return chip->rirb.res[addr];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686}
687
Takashi Iwai111d3af2006-02-16 18:17:58 +0100688/*
689 * The below are the main callbacks from hda_codec.
690 *
691 * They are just the skeleton to call sub-callbacks according to the
692 * current setting of chip->single_cmd.
693 */
694
695/* send a command */
Takashi Iwai33fa35e2008-11-06 16:50:40 +0100696static int azx_send_cmd(struct hda_bus *bus, unsigned int val)
Takashi Iwai111d3af2006-02-16 18:17:58 +0100697{
Takashi Iwai33fa35e2008-11-06 16:50:40 +0100698 struct azx *chip = bus->private_data;
Takashi Iwai43bbb6c2007-07-06 20:22:05 +0200699
Takashi Iwaia82d51e2012-04-26 12:23:42 +0200700 if (chip->disabled)
701 return 0;
Wu Fengguangfeb27342009-08-01 19:17:14 +0800702 chip->last_cmd[azx_command_addr(val)] = val;
Takashi Iwai111d3af2006-02-16 18:17:58 +0100703 if (chip->single_cmd)
Takashi Iwai33fa35e2008-11-06 16:50:40 +0100704 return azx_single_send_cmd(bus, val);
Takashi Iwai111d3af2006-02-16 18:17:58 +0100705 else
Takashi Iwai33fa35e2008-11-06 16:50:40 +0100706 return azx_corb_send_cmd(bus, val);
Takashi Iwai111d3af2006-02-16 18:17:58 +0100707}
708
709/* get a response */
Wu Fengguangdeadff12009-08-01 18:45:16 +0800710static unsigned int azx_get_response(struct hda_bus *bus,
711 unsigned int addr)
Takashi Iwai111d3af2006-02-16 18:17:58 +0100712{
Takashi Iwai33fa35e2008-11-06 16:50:40 +0100713 struct azx *chip = bus->private_data;
Takashi Iwaia82d51e2012-04-26 12:23:42 +0200714 if (chip->disabled)
715 return 0;
Takashi Iwai111d3af2006-02-16 18:17:58 +0100716 if (chip->single_cmd)
Wu Fengguangdeadff12009-08-01 18:45:16 +0800717 return azx_single_get_response(bus, addr);
Takashi Iwai111d3af2006-02-16 18:17:58 +0100718 else
Wu Fengguangdeadff12009-08-01 18:45:16 +0800719 return azx_rirb_get_response(bus, addr);
Takashi Iwai111d3af2006-02-16 18:17:58 +0100720}
721
Takashi Iwai83012a72012-08-24 18:38:08 +0200722#ifdef CONFIG_PM
Takashi Iwai68467f52012-08-28 09:14:29 -0700723static void azx_power_notify(struct hda_bus *bus, bool power_up);
Takashi Iwaicb53c622007-08-10 17:21:45 +0200724#endif
Takashi Iwai111d3af2006-02-16 18:17:58 +0100725
Takashi Iwai1d1a4562012-09-20 20:29:13 -0700726#ifdef CONFIG_SND_HDA_DSP_LOADER
727static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
728 unsigned int byte_size,
729 struct snd_dma_buffer *bufp);
730static void azx_load_dsp_trigger(struct hda_bus *bus, bool start);
731static void azx_load_dsp_cleanup(struct hda_bus *bus,
732 struct snd_dma_buffer *dmab);
733#endif
734
Mengdong Lin3af3f352013-06-24 10:18:54 -0400735/* enter link reset */
Mengdong Lin7295b262013-06-25 05:58:49 -0400736static void azx_enter_link_reset(struct azx *chip)
Mengdong Lin3af3f352013-06-24 10:18:54 -0400737{
738 unsigned long timeout;
739
740 /* reset controller */
741 azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_RESET);
742
743 timeout = jiffies + msecs_to_jiffies(100);
744 while ((azx_readb(chip, GCTL) & ICH6_GCTL_RESET) &&
745 time_before(jiffies, timeout))
746 usleep_range(500, 1000);
747}
748
Mengdong Lin7295b262013-06-25 05:58:49 -0400749/* exit link reset */
750static void azx_exit_link_reset(struct azx *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751{
Mengdong Linfa348da2012-12-12 09:16:15 -0500752 unsigned long timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
Mengdong Lin7295b262013-06-25 05:58:49 -0400754 azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET);
755
756 timeout = jiffies + msecs_to_jiffies(100);
757 while (!azx_readb(chip, GCTL) &&
758 time_before(jiffies, timeout))
759 usleep_range(500, 1000);
760}
761
762/* reset codec link */
763static int azx_reset(struct azx *chip, int full_reset)
764{
Jaroslav Kyselacd508fe2010-03-26 10:28:46 +0100765 if (!full_reset)
766 goto __skip;
767
Danny Tholene8a7f132007-09-11 21:41:56 +0200768 /* clear STATESTS */
Wang Xingchaoda7db6a2013-07-22 03:19:18 -0400769 azx_writew(chip, STATESTS, STATESTS_INT_MASK);
Danny Tholene8a7f132007-09-11 21:41:56 +0200770
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 /* reset controller */
Mengdong Lin7295b262013-06-25 05:58:49 -0400772 azx_enter_link_reset(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
774 /* delay for >= 100us for codec PLL to settle per spec
775 * Rev 0.9 section 5.5.1
776 */
Mengdong Linfa348da2012-12-12 09:16:15 -0500777 usleep_range(500, 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779 /* Bring controller out of reset */
Mengdong Lin7295b262013-06-25 05:58:49 -0400780 azx_exit_link_reset(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Pavel Machek927fc862006-08-31 17:03:43 +0200782 /* Brent Chartrand said to wait >= 540us for codecs to initialize */
Mengdong Linfa348da2012-12-12 09:16:15 -0500783 usleep_range(1000, 1200);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Jaroslav Kyselacd508fe2010-03-26 10:28:46 +0100785 __skip:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 /* check to see if controller is ready */
Pavel Machek927fc862006-08-31 17:03:43 +0200787 if (!azx_readb(chip, GCTL)) {
Takashi Iwai4e76a882014-02-25 12:21:03 +0100788 dev_dbg(chip->card->dev, "azx_reset: controller not ready!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 return -EBUSY;
790 }
791
Matt41e2fce2005-07-04 17:49:55 +0200792 /* Accept unsolicited responses */
Takashi Iwai1a696972009-11-07 09:49:04 +0100793 if (!chip->single_cmd)
794 azx_writel(chip, GCTL, azx_readl(chip, GCTL) |
795 ICH6_GCTL_UNSOL);
Matt41e2fce2005-07-04 17:49:55 +0200796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 /* detect codecs */
Pavel Machek927fc862006-08-31 17:03:43 +0200798 if (!chip->codec_mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 chip->codec_mask = azx_readw(chip, STATESTS);
Takashi Iwai4e76a882014-02-25 12:21:03 +0100800 dev_dbg(chip->card->dev, "codec_mask = 0x%x\n",
801 chip->codec_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 }
803
804 return 0;
805}
806
807
808/*
809 * Lowlevel interface
810 */
811
812/* enable interrupts */
Takashi Iwaia98f90f2005-11-17 14:59:02 +0100813static void azx_int_enable(struct azx *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
815 /* enable controller CIE and GIE */
816 azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) |
817 ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN);
818}
819
820/* disable interrupts */
Takashi Iwaia98f90f2005-11-17 14:59:02 +0100821static void azx_int_disable(struct azx *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
823 int i;
824
825 /* disable interrupts in stream descriptor */
Takashi Iwai07e4ca52005-08-24 14:14:57 +0200826 for (i = 0; i < chip->num_streams; i++) {
Takashi Iwaia98f90f2005-11-17 14:59:02 +0100827 struct azx_dev *azx_dev = &chip->azx_dev[i];
Dylan Reid40830812014-02-28 15:41:13 -0800828 azx_sd_writeb(chip, azx_dev, SD_CTL,
829 azx_sd_readb(chip, azx_dev, SD_CTL) &
830 ~SD_INT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 }
832
833 /* disable SIE for all streams */
834 azx_writeb(chip, INTCTL, 0);
835
836 /* disable controller CIE and GIE */
837 azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) &
838 ~(ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN));
839}
840
841/* clear interrupts */
Takashi Iwaia98f90f2005-11-17 14:59:02 +0100842static void azx_int_clear(struct azx *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
844 int i;
845
846 /* clear stream status */
Takashi Iwai07e4ca52005-08-24 14:14:57 +0200847 for (i = 0; i < chip->num_streams; i++) {
Takashi Iwaia98f90f2005-11-17 14:59:02 +0100848 struct azx_dev *azx_dev = &chip->azx_dev[i];
Dylan Reid40830812014-02-28 15:41:13 -0800849 azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 }
851
852 /* clear STATESTS */
Wang Xingchaoda7db6a2013-07-22 03:19:18 -0400853 azx_writew(chip, STATESTS, STATESTS_INT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
855 /* clear rirb status */
856 azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
857
858 /* clear int status */
859 azx_writel(chip, INTSTS, ICH6_INT_CTRL_EN | ICH6_INT_ALL_STREAM);
860}
861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862/*
Takashi Iwaicb53c622007-08-10 17:21:45 +0200863 * reset and start the controller registers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 */
Jaroslav Kyselacd508fe2010-03-26 10:28:46 +0100865static void azx_init_chip(struct azx *chip, int full_reset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866{
Takashi Iwaicb53c622007-08-10 17:21:45 +0200867 if (chip->initialized)
868 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
870 /* reset controller */
Jaroslav Kyselacd508fe2010-03-26 10:28:46 +0100871 azx_reset(chip, full_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
873 /* initialize interrupts */
874 azx_int_clear(chip);
875 azx_int_enable(chip);
876
877 /* initialize the codec command I/O */
Takashi Iwai1a696972009-11-07 09:49:04 +0100878 if (!chip->single_cmd)
879 azx_init_cmd_io(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
Takashi Iwai0be3b5d2005-09-05 17:11:40 +0200881 /* program the position buffer */
882 azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr);
Takashi Iwai766979e2008-06-13 20:53:56 +0200883 azx_writel(chip, DPUBASE, upper_32_bits(chip->posbuf.addr));
Frederick Lif5d40b32005-05-12 14:55:20 +0200884
Takashi Iwaicb53c622007-08-10 17:21:45 +0200885 chip->initialized = 1;
886}
887
888/*
889 * initialize the PCI registers
890 */
891/* update bits in a PCI register byte */
892static void update_pci_byte(struct pci_dev *pci, unsigned int reg,
893 unsigned char mask, unsigned char val)
894{
895 unsigned char data;
896
897 pci_read_config_byte(pci, reg, &data);
898 data &= ~mask;
899 data |= (val & mask);
900 pci_write_config_byte(pci, reg, data);
901}
902
903static void azx_init_pci(struct azx *chip)
904{
905 /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
906 * TCSEL == Traffic Class Select Register, which sets PCI express QOS
907 * Ensuring these bits are 0 clears playback static on some HD Audio
Adam Lackorzynskia09e89f2011-03-10 17:41:56 +0100908 * codecs.
909 * The PCI register TCSEL is defined in the Intel manuals.
Takashi Iwaicb53c622007-08-10 17:21:45 +0200910 */
Linus Torvalds46f2cc82011-05-27 19:45:28 -0700911 if (!(chip->driver_caps & AZX_DCAPS_NO_TCSEL)) {
Takashi Iwai4e76a882014-02-25 12:21:03 +0100912 dev_dbg(chip->card->dev, "Clearing TCSEL\n");
Adam Lackorzynskia09e89f2011-03-10 17:41:56 +0100913 update_pci_byte(chip->pci, ICH6_PCIREG_TCSEL, 0x07, 0);
Takashi Iwai9477c582011-05-25 09:11:37 +0200914 }
Takashi Iwaicb53c622007-08-10 17:21:45 +0200915
Takashi Iwai9477c582011-05-25 09:11:37 +0200916 /* For ATI SB450/600/700/800/900 and AMD Hudson azalia HD audio,
917 * we need to enable snoop.
918 */
919 if (chip->driver_caps & AZX_DCAPS_ATI_SNOOP) {
Takashi Iwai4e76a882014-02-25 12:21:03 +0100920 dev_dbg(chip->card->dev, "Setting ATI snoop: %d\n",
921 azx_snoop(chip));
Takashi Iwaicb53c622007-08-10 17:21:45 +0200922 update_pci_byte(chip->pci,
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200923 ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 0x07,
924 azx_snoop(chip) ? ATI_SB450_HDAUDIO_ENABLE_SNOOP : 0);
Takashi Iwai9477c582011-05-25 09:11:37 +0200925 }
926
927 /* For NVIDIA HDA, enable snoop */
928 if (chip->driver_caps & AZX_DCAPS_NVIDIA_SNOOP) {
Takashi Iwai4e76a882014-02-25 12:21:03 +0100929 dev_dbg(chip->card->dev, "Setting Nvidia snoop: %d\n",
930 azx_snoop(chip));
Takashi Iwaicb53c622007-08-10 17:21:45 +0200931 update_pci_byte(chip->pci,
932 NVIDIA_HDA_TRANSREG_ADDR,
933 0x0f, NVIDIA_HDA_ENABLE_COHBITS);
Peer Chen320dcc32008-08-20 16:43:24 -0700934 update_pci_byte(chip->pci,
935 NVIDIA_HDA_ISTRM_COH,
936 0x01, NVIDIA_HDA_ENABLE_COHBIT);
937 update_pci_byte(chip->pci,
938 NVIDIA_HDA_OSTRM_COH,
939 0x01, NVIDIA_HDA_ENABLE_COHBIT);
Takashi Iwai9477c582011-05-25 09:11:37 +0200940 }
941
942 /* Enable SCH/PCH snoop if needed */
943 if (chip->driver_caps & AZX_DCAPS_SCH_SNOOP) {
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200944 unsigned short snoop;
Takashi Iwai90a5ad52008-02-22 18:36:22 +0100945 pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop);
Takashi Iwai27fe48d92011-09-28 17:16:09 +0200946 if ((!azx_snoop(chip) && !(snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)) ||
947 (azx_snoop(chip) && (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP))) {
948 snoop &= ~INTEL_SCH_HDA_DEVC_NOSNOOP;
949 if (!azx_snoop(chip))
950 snoop |= INTEL_SCH_HDA_DEVC_NOSNOOP;
951 pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC, snoop);
Takashi Iwai90a5ad52008-02-22 18:36:22 +0100952 pci_read_config_word(chip->pci,
953 INTEL_SCH_HDA_DEVC, &snoop);
Takashi Iwai90a5ad52008-02-22 18:36:22 +0100954 }
Takashi Iwai4e76a882014-02-25 12:21:03 +0100955 dev_dbg(chip->card->dev, "SCH snoop: %s\n",
956 (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) ?
957 "Disabled" : "Enabled");
Vinod Gda3fca22005-09-13 18:49:12 +0200958 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959}
960
961
Takashi Iwai9ad593f2008-05-16 12:34:47 +0200962static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev);
963
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964/*
965 * interrupt handler
966 */
David Howells7d12e782006-10-05 14:55:46 +0100967static irqreturn_t azx_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968{
Takashi Iwaia98f90f2005-11-17 14:59:02 +0100969 struct azx *chip = dev_id;
970 struct azx_dev *azx_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 u32 status;
Clemens Ladisch9ef04062010-05-25 09:03:40 +0200972 u8 sd_status;
Jaroslav Kyselafa00e042009-04-10 12:20:45 +0200973 int i, ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Mengdong Linb8dfc4622012-08-23 17:32:30 +0800975#ifdef CONFIG_PM_RUNTIME
Dave Airlie246efa42013-07-29 15:19:29 +1000976 if (chip->driver_caps & AZX_DCAPS_PM_RUNTIME)
Dylan Reid89287562014-02-28 15:41:15 -0800977 if (chip->card->dev->power.runtime_status != RPM_ACTIVE)
Dave Airlie246efa42013-07-29 15:19:29 +1000978 return IRQ_NONE;
Mengdong Linb8dfc4622012-08-23 17:32:30 +0800979#endif
980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 spin_lock(&chip->reg_lock);
982
Dan Carpenter60911062012-05-18 10:36:11 +0300983 if (chip->disabled) {
984 spin_unlock(&chip->reg_lock);
Takashi Iwaia82d51e2012-04-26 12:23:42 +0200985 return IRQ_NONE;
Dan Carpenter60911062012-05-18 10:36:11 +0300986 }
Takashi Iwaia82d51e2012-04-26 12:23:42 +0200987
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 status = azx_readl(chip, INTSTS);
Dave Airlie246efa42013-07-29 15:19:29 +1000989 if (status == 0 || status == 0xffffffff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 spin_unlock(&chip->reg_lock);
991 return IRQ_NONE;
992 }
993
Takashi Iwai07e4ca52005-08-24 14:14:57 +0200994 for (i = 0; i < chip->num_streams; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 azx_dev = &chip->azx_dev[i];
996 if (status & azx_dev->sd_int_sta_mask) {
Dylan Reid40830812014-02-28 15:41:13 -0800997 sd_status = azx_sd_readb(chip, azx_dev, SD_STS);
998 azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK);
Clemens Ladisch9ef04062010-05-25 09:03:40 +0200999 if (!azx_dev->substream || !azx_dev->running ||
1000 !(sd_status & SD_INT_COMPLETE))
Takashi Iwai9ad593f2008-05-16 12:34:47 +02001001 continue;
1002 /* check whether this IRQ is really acceptable */
Jaroslav Kyselafa00e042009-04-10 12:20:45 +02001003 ok = azx_position_ok(chip, azx_dev);
1004 if (ok == 1) {
Takashi Iwai9ad593f2008-05-16 12:34:47 +02001005 azx_dev->irq_pending = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 spin_unlock(&chip->reg_lock);
1007 snd_pcm_period_elapsed(azx_dev->substream);
1008 spin_lock(&chip->reg_lock);
Jaroslav Kyselafa00e042009-04-10 12:20:45 +02001009 } else if (ok == 0 && chip->bus && chip->bus->workq) {
Takashi Iwai9ad593f2008-05-16 12:34:47 +02001010 /* bogus IRQ, process it later */
1011 azx_dev->irq_pending = 1;
Takashi Iwai6acaed32009-01-12 10:09:24 +01001012 queue_work(chip->bus->workq,
1013 &chip->irq_pending_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 }
1015 }
1016 }
1017
1018 /* clear rirb int */
1019 status = azx_readb(chip, RIRBSTS);
1020 if (status & RIRB_INT_MASK) {
Takashi Iwai14d34f12010-10-21 09:03:25 +02001021 if (status & RIRB_INT_RESPONSE) {
Takashi Iwai9477c582011-05-25 09:11:37 +02001022 if (chip->driver_caps & AZX_DCAPS_RIRB_PRE_DELAY)
Takashi Iwai14d34f12010-10-21 09:03:25 +02001023 udelay(80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 azx_update_rirb(chip);
Takashi Iwai14d34f12010-10-21 09:03:25 +02001025 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
1027 }
1028
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 spin_unlock(&chip->reg_lock);
1030
1031 return IRQ_HANDLED;
1032}
1033
Takashi Iwai6ce4a3b2008-11-06 17:11:10 +01001034/*
1035 * Probe the given codec address
1036 */
1037static int probe_codec(struct azx *chip, int addr)
1038{
1039 unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
1040 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
1041 unsigned int res;
1042
Wu Fengguanga678cde2009-08-01 18:46:46 +08001043 mutex_lock(&chip->bus->cmd_mutex);
Takashi Iwai6ce4a3b2008-11-06 17:11:10 +01001044 chip->probing = 1;
1045 azx_send_cmd(chip->bus, cmd);
Wu Fengguangdeadff12009-08-01 18:45:16 +08001046 res = azx_get_response(chip->bus, addr);
Takashi Iwai6ce4a3b2008-11-06 17:11:10 +01001047 chip->probing = 0;
Wu Fengguanga678cde2009-08-01 18:46:46 +08001048 mutex_unlock(&chip->bus->cmd_mutex);
Takashi Iwai6ce4a3b2008-11-06 17:11:10 +01001049 if (res == -1)
1050 return -EIO;
Takashi Iwai4e76a882014-02-25 12:21:03 +01001051 dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr);
Takashi Iwai6ce4a3b2008-11-06 17:11:10 +01001052 return 0;
1053}
1054
Takashi Iwai6ce4a3b2008-11-06 17:11:10 +01001055static void azx_stop_chip(struct azx *chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
Takashi Iwai8dd78332009-06-02 01:16:07 +02001057static void azx_bus_reset(struct hda_bus *bus)
1058{
1059 struct azx *chip = bus->private_data;
Takashi Iwai8dd78332009-06-02 01:16:07 +02001060
1061 bus->in_reset = 1;
1062 azx_stop_chip(chip);
Jaroslav Kyselacd508fe2010-03-26 10:28:46 +01001063 azx_init_chip(chip, 1);
Alexander Beregalov65f75982009-06-04 13:46:16 +04001064#ifdef CONFIG_PM
Takashi Iwai8dd78332009-06-02 01:16:07 +02001065 if (chip->initialized) {
Takashi Iwai01b65bf2011-11-24 14:31:46 +01001066 struct azx_pcm *p;
1067 list_for_each_entry(p, &chip->pcm_list, list)
1068 snd_pcm_suspend_all(p->pcm);
Takashi Iwai8dd78332009-06-02 01:16:07 +02001069 snd_hda_suspend(chip->bus);
1070 snd_hda_resume(chip->bus);
1071 }
Alexander Beregalov65f75982009-06-04 13:46:16 +04001072#endif
Takashi Iwai8dd78332009-06-02 01:16:07 +02001073 bus->in_reset = 0;
1074}
1075
David Henningsson26a6cb62012-10-09 15:04:21 +02001076static int get_jackpoll_interval(struct azx *chip)
1077{
Dylan Reid749ee282014-02-28 15:41:18 -08001078 int i;
David Henningsson26a6cb62012-10-09 15:04:21 +02001079 unsigned int j;
Dylan Reid749ee282014-02-28 15:41:18 -08001080
1081 if (!chip->jackpoll_ms)
1082 return 0;
1083
1084 i = chip->jackpoll_ms[chip->dev_index];
David Henningsson26a6cb62012-10-09 15:04:21 +02001085 if (i == 0)
1086 return 0;
1087 if (i < 50 || i > 60000)
1088 j = 0;
1089 else
1090 j = msecs_to_jiffies(i);
1091 if (j == 0)
Takashi Iwai4e76a882014-02-25 12:21:03 +01001092 dev_warn(chip->card->dev,
1093 "jackpoll_ms value out of range: %d\n", i);
David Henningsson26a6cb62012-10-09 15:04:21 +02001094 return j;
1095}
1096
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097/*
1098 * Codec initialization
1099 */
1100
Dylan Reide62a42a2014-02-28 15:41:19 -08001101static int azx_codec_create(struct azx *chip, const char *model,
1102 unsigned int max_slots,
1103 int *power_save_to)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104{
1105 struct hda_bus_template bus_temp;
Takashi Iwai34c25352008-10-28 11:38:58 +01001106 int c, codecs, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
1108 memset(&bus_temp, 0, sizeof(bus_temp));
1109 bus_temp.private_data = chip;
1110 bus_temp.modelname = model;
1111 bus_temp.pci = chip->pci;
Takashi Iwai111d3af2006-02-16 18:17:58 +01001112 bus_temp.ops.command = azx_send_cmd;
1113 bus_temp.ops.get_response = azx_get_response;
Takashi Iwai176d5332008-07-30 15:01:44 +02001114 bus_temp.ops.attach_pcm = azx_attach_pcm_stream;
Takashi Iwai8dd78332009-06-02 01:16:07 +02001115 bus_temp.ops.bus_reset = azx_bus_reset;
Takashi Iwai83012a72012-08-24 18:38:08 +02001116#ifdef CONFIG_PM
Dylan Reide62a42a2014-02-28 15:41:19 -08001117 bus_temp.power_save = power_save_to;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001118 bus_temp.ops.pm_notify = azx_power_notify;
1119#endif
Takashi Iwai1d1a4562012-09-20 20:29:13 -07001120#ifdef CONFIG_SND_HDA_DSP_LOADER
1121 bus_temp.ops.load_dsp_prepare = azx_load_dsp_prepare;
1122 bus_temp.ops.load_dsp_trigger = azx_load_dsp_trigger;
1123 bus_temp.ops.load_dsp_cleanup = azx_load_dsp_cleanup;
1124#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Takashi Iwaid01ce992007-07-27 16:52:19 +02001126 err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus);
1127 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 return err;
1129
Takashi Iwai9477c582011-05-25 09:11:37 +02001130 if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001131 dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n");
Wei Nidc9c8e22008-09-26 13:55:56 +08001132 chip->bus->needs_damn_long_delay = 1;
Takashi Iwai9477c582011-05-25 09:11:37 +02001133 }
Wei Nidc9c8e22008-09-26 13:55:56 +08001134
Takashi Iwai34c25352008-10-28 11:38:58 +01001135 codecs = 0;
Takashi Iwai2f5983f2008-09-03 16:00:44 +02001136 if (!max_slots)
Wei Ni7445dfc2010-03-03 15:05:53 +08001137 max_slots = AZX_DEFAULT_CODECS;
Takashi Iwai6ce4a3b2008-11-06 17:11:10 +01001138
1139 /* First try to probe all given codec slots */
1140 for (c = 0; c < max_slots; c++) {
Takashi Iwaif1eaaee2009-02-13 08:16:55 +01001141 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
Takashi Iwai6ce4a3b2008-11-06 17:11:10 +01001142 if (probe_codec(chip, c) < 0) {
1143 /* Some BIOSen give you wrong codec addresses
1144 * that don't exist
1145 */
Takashi Iwai4e76a882014-02-25 12:21:03 +01001146 dev_warn(chip->card->dev,
1147 "Codec #%d probe error; disabling it...\n", c);
Takashi Iwai6ce4a3b2008-11-06 17:11:10 +01001148 chip->codec_mask &= ~(1 << c);
1149 /* More badly, accessing to a non-existing
1150 * codec often screws up the controller chip,
Paul Menzel24481582010-02-08 20:37:26 +01001151 * and disturbs the further communications.
Takashi Iwai6ce4a3b2008-11-06 17:11:10 +01001152 * Thus if an error occurs during probing,
1153 * better to reset the controller chip to
1154 * get back to the sanity state.
1155 */
1156 azx_stop_chip(chip);
Jaroslav Kyselacd508fe2010-03-26 10:28:46 +01001157 azx_init_chip(chip, 1);
Takashi Iwai6ce4a3b2008-11-06 17:11:10 +01001158 }
1159 }
1160 }
1161
Takashi Iwaid507cd62011-04-26 15:25:02 +02001162 /* AMD chipsets often cause the communication stalls upon certain
1163 * sequence like the pin-detection. It seems that forcing the synced
1164 * access works around the stall. Grrr...
1165 */
Takashi Iwai9477c582011-05-25 09:11:37 +02001166 if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001167 dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n");
Takashi Iwaid507cd62011-04-26 15:25:02 +02001168 chip->bus->sync_write = 1;
1169 chip->bus->allow_bus_reset = 1;
1170 }
1171
Takashi Iwai6ce4a3b2008-11-06 17:11:10 +01001172 /* Then create codec instances */
Takashi Iwai34c25352008-10-28 11:38:58 +01001173 for (c = 0; c < max_slots; c++) {
Takashi Iwaif1eaaee2009-02-13 08:16:55 +01001174 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
Takashi Iwaibccad142007-04-24 12:23:53 +02001175 struct hda_codec *codec;
Takashi Iwaia1e21c92009-06-17 09:33:52 +02001176 err = snd_hda_codec_new(chip->bus, c, &codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 if (err < 0)
1178 continue;
David Henningsson26a6cb62012-10-09 15:04:21 +02001179 codec->jackpoll_interval = get_jackpoll_interval(chip);
Jaroslav Kysela2dca0bb2009-11-13 18:41:52 +01001180 codec->beep_mode = chip->beep_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 codecs++;
Takashi Iwai19a982b2007-03-21 15:14:35 +01001182 }
1183 }
1184 if (!codecs) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001185 dev_err(chip->card->dev, "no codecs initialized\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 return -ENXIO;
1187 }
Takashi Iwaia1e21c92009-06-17 09:33:52 +02001188 return 0;
1189}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
Takashi Iwaia1e21c92009-06-17 09:33:52 +02001191/* configure each codec instance */
Bill Pembertone23e7a12012-12-06 12:35:10 -05001192static int azx_codec_configure(struct azx *chip)
Takashi Iwaia1e21c92009-06-17 09:33:52 +02001193{
1194 struct hda_codec *codec;
1195 list_for_each_entry(codec, &chip->bus->codec_list, list) {
1196 snd_hda_codec_configure(codec);
1197 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 return 0;
1199}
1200
Takashi Iwai9ad593f2008-05-16 12:34:47 +02001201/*
1202 * Check whether the current DMA position is acceptable for updating
1203 * periods. Returns non-zero if it's OK.
1204 *
1205 * Many HD-audio controllers appear pretty inaccurate about
1206 * the update-IRQ timing. The IRQ is issued before actually the
1207 * data is processed. So, we need to process it afterwords in a
1208 * workqueue.
1209 */
1210static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
1211{
Jaroslav Kyselae5463722010-05-11 10:21:46 +02001212 u32 wallclk;
Takashi Iwai9ad593f2008-05-16 12:34:47 +02001213 unsigned int pos;
1214
Jaroslav Kyselaf48f6062010-05-11 12:10:47 +02001215 wallclk = azx_readl(chip, WALLCLK) - azx_dev->start_wallclk;
1216 if (wallclk < (azx_dev->period_wallclk * 2) / 3)
Jaroslav Kyselafa00e042009-04-10 12:20:45 +02001217 return -1; /* bogus (too early) interrupt */
Jaroslav Kyselafa00e042009-04-10 12:20:45 +02001218
Takashi Iwai798cb7e2011-09-30 08:52:26 +02001219 pos = azx_get_position(chip, azx_dev, true);
Takashi Iwai9ad593f2008-05-16 12:34:47 +02001220
Takashi Iwaid6d8bf52010-02-12 18:17:06 +01001221 if (WARN_ONCE(!azx_dev->period_bytes,
1222 "hda-intel: zero azx_dev->period_bytes"))
Jaroslav Kyselaf48f6062010-05-11 12:10:47 +02001223 return -1; /* this shouldn't happen! */
Jaroslav Kyselaedb39932010-06-02 13:29:17 +02001224 if (wallclk < (azx_dev->period_wallclk * 5) / 4 &&
Jaroslav Kyselaf48f6062010-05-11 12:10:47 +02001225 pos % azx_dev->period_bytes > azx_dev->period_bytes / 2)
1226 /* NG - it's below the first next period boundary */
Dylan Reid9cdc0112014-02-28 15:41:14 -08001227 return chip->bdl_pos_adj[chip->dev_index] ? 0 : -1;
Jaroslav Kyselaedb39932010-06-02 13:29:17 +02001228 azx_dev->start_wallclk += wallclk;
Takashi Iwai9ad593f2008-05-16 12:34:47 +02001229 return 1; /* OK, it's fine */
1230}
1231
1232/*
1233 * The work for pending PCM period updates.
1234 */
1235static void azx_irq_pending_work(struct work_struct *work)
1236{
1237 struct azx *chip = container_of(work, struct azx, irq_pending_work);
Jaroslav Kyselae5463722010-05-11 10:21:46 +02001238 int i, pending, ok;
Takashi Iwai9ad593f2008-05-16 12:34:47 +02001239
Takashi Iwaia6a950a2008-06-10 17:53:35 +02001240 if (!chip->irq_pending_warned) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001241 dev_info(chip->card->dev,
1242 "IRQ timing workaround is activated for card #%d. Suggest a bigger bdl_pos_adj.\n",
1243 chip->card->number);
Takashi Iwaia6a950a2008-06-10 17:53:35 +02001244 chip->irq_pending_warned = 1;
1245 }
1246
Takashi Iwai9ad593f2008-05-16 12:34:47 +02001247 for (;;) {
1248 pending = 0;
1249 spin_lock_irq(&chip->reg_lock);
1250 for (i = 0; i < chip->num_streams; i++) {
1251 struct azx_dev *azx_dev = &chip->azx_dev[i];
1252 if (!azx_dev->irq_pending ||
1253 !azx_dev->substream ||
1254 !azx_dev->running)
1255 continue;
Jaroslav Kyselae5463722010-05-11 10:21:46 +02001256 ok = azx_position_ok(chip, azx_dev);
1257 if (ok > 0) {
Takashi Iwai9ad593f2008-05-16 12:34:47 +02001258 azx_dev->irq_pending = 0;
1259 spin_unlock(&chip->reg_lock);
1260 snd_pcm_period_elapsed(azx_dev->substream);
1261 spin_lock(&chip->reg_lock);
Jaroslav Kyselae5463722010-05-11 10:21:46 +02001262 } else if (ok < 0) {
1263 pending = 0; /* too early */
Takashi Iwai9ad593f2008-05-16 12:34:47 +02001264 } else
1265 pending++;
1266 }
1267 spin_unlock_irq(&chip->reg_lock);
1268 if (!pending)
1269 return;
Takashi Iwai08af4952010-08-03 14:39:04 +02001270 msleep(1);
Takashi Iwai9ad593f2008-05-16 12:34:47 +02001271 }
1272}
1273
1274/* clear irq_pending flags and assure no on-going workq */
1275static void azx_clear_irq_pending(struct azx *chip)
1276{
1277 int i;
1278
1279 spin_lock_irq(&chip->reg_lock);
1280 for (i = 0; i < chip->num_streams; i++)
1281 chip->azx_dev[i].irq_pending = 0;
1282 spin_unlock_irq(&chip->reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283}
1284
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285/*
1286 * mixer creation - all stuff is implemented in hda module
1287 */
Bill Pembertone23e7a12012-12-06 12:35:10 -05001288static int azx_mixer_create(struct azx *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
1290 return snd_hda_build_controls(chip->bus);
1291}
1292
1293
1294/*
1295 * initialize SD streams
1296 */
Bill Pembertone23e7a12012-12-06 12:35:10 -05001297static int azx_init_stream(struct azx *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298{
1299 int i;
1300
1301 /* initialize each stream (aka device)
Takashi Iwaid01ce992007-07-27 16:52:19 +02001302 * assign the starting bdl address to each stream (device)
1303 * and initialize
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 */
Takashi Iwai07e4ca52005-08-24 14:14:57 +02001305 for (i = 0; i < chip->num_streams; i++) {
Takashi Iwaia98f90f2005-11-17 14:59:02 +01001306 struct azx_dev *azx_dev = &chip->azx_dev[i];
Takashi Iwai929861c2006-08-31 16:55:40 +02001307 azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
1309 azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80);
1310 /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */
1311 azx_dev->sd_int_sta_mask = 1 << i;
1312 /* stream tag: must be non-zero and unique */
1313 azx_dev->index = i;
1314 azx_dev->stream_tag = i + 1;
1315 }
1316
1317 return 0;
1318}
1319
Takashi Iwai68e7fff2006-10-23 13:40:59 +02001320static int azx_acquire_irq(struct azx *chip, int do_disconnect)
1321{
Takashi Iwai437a5a42006-11-21 12:14:23 +01001322 if (request_irq(chip->pci->irq, azx_interrupt,
1323 chip->msi ? 0 : IRQF_SHARED,
Takashi Iwai934c2b62011-06-10 16:36:37 +02001324 KBUILD_MODNAME, chip)) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001325 dev_err(chip->card->dev,
1326 "unable to grab IRQ %d, disabling device\n",
1327 chip->pci->irq);
Takashi Iwai68e7fff2006-10-23 13:40:59 +02001328 if (do_disconnect)
1329 snd_card_disconnect(chip->card);
1330 return -1;
1331 }
1332 chip->irq = chip->pci->irq;
Takashi Iwai69e13412006-11-21 12:10:55 +01001333 pci_intx(chip->pci, !chip->msi);
Takashi Iwai68e7fff2006-10-23 13:40:59 +02001334 return 0;
1335}
1336
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
Takashi Iwaicb53c622007-08-10 17:21:45 +02001338static void azx_stop_chip(struct azx *chip)
1339{
Takashi Iwai95e99fd2007-08-13 15:29:04 +02001340 if (!chip->initialized)
Takashi Iwaicb53c622007-08-10 17:21:45 +02001341 return;
1342
1343 /* disable interrupts */
1344 azx_int_disable(chip);
1345 azx_int_clear(chip);
1346
1347 /* disable CORB/RIRB */
1348 azx_free_cmd_io(chip);
1349
1350 /* disable position buffer */
1351 azx_writel(chip, DPLBASE, 0);
1352 azx_writel(chip, DPUBASE, 0);
1353
1354 chip->initialized = 0;
1355}
1356
Takashi Iwai1d1a4562012-09-20 20:29:13 -07001357#ifdef CONFIG_SND_HDA_DSP_LOADER
1358/*
1359 * DSP loading code (e.g. for CA0132)
1360 */
1361
1362/* use the first stream for loading DSP */
1363static struct azx_dev *
1364azx_get_dsp_loader_dev(struct azx *chip)
1365{
1366 return &chip->azx_dev[chip->playback_index_offset];
1367}
1368
1369static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
1370 unsigned int byte_size,
1371 struct snd_dma_buffer *bufp)
1372{
1373 u32 *bdl;
1374 struct azx *chip = bus->private_data;
1375 struct azx_dev *azx_dev;
1376 int err;
1377
Takashi Iwaieb49faa2013-03-15 09:19:11 +01001378 azx_dev = azx_get_dsp_loader_dev(chip);
1379
1380 dsp_lock(azx_dev);
1381 spin_lock_irq(&chip->reg_lock);
1382 if (azx_dev->running || azx_dev->locked) {
1383 spin_unlock_irq(&chip->reg_lock);
1384 err = -EBUSY;
1385 goto unlock;
1386 }
1387 azx_dev->prepared = 0;
1388 chip->saved_azx_dev = *azx_dev;
1389 azx_dev->locked = 1;
1390 spin_unlock_irq(&chip->reg_lock);
Takashi Iwai1d1a4562012-09-20 20:29:13 -07001391
Dylan Reidb419b352014-02-28 15:41:20 -08001392 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV_SG,
1393 byte_size, bufp);
Takashi Iwai1d1a4562012-09-20 20:29:13 -07001394 if (err < 0)
Takashi Iwaieb49faa2013-03-15 09:19:11 +01001395 goto err_alloc;
Takashi Iwai1d1a4562012-09-20 20:29:13 -07001396
Takashi Iwai1d1a4562012-09-20 20:29:13 -07001397 azx_dev->bufsize = byte_size;
1398 azx_dev->period_bytes = byte_size;
1399 azx_dev->format_val = format;
1400
1401 azx_stream_reset(chip, azx_dev);
1402
1403 /* reset BDL address */
Dylan Reid40830812014-02-28 15:41:13 -08001404 azx_sd_writel(chip, azx_dev, SD_BDLPL, 0);
1405 azx_sd_writel(chip, azx_dev, SD_BDLPU, 0);
Takashi Iwai1d1a4562012-09-20 20:29:13 -07001406
1407 azx_dev->frags = 0;
1408 bdl = (u32 *)azx_dev->bdl.area;
1409 err = setup_bdle(chip, bufp, azx_dev, &bdl, 0, byte_size, 0);
1410 if (err < 0)
1411 goto error;
1412
1413 azx_setup_controller(chip, azx_dev);
Takashi Iwaieb49faa2013-03-15 09:19:11 +01001414 dsp_unlock(azx_dev);
Takashi Iwai1d1a4562012-09-20 20:29:13 -07001415 return azx_dev->stream_tag;
1416
1417 error:
Dylan Reidb419b352014-02-28 15:41:20 -08001418 chip->ops->dma_free_pages(chip, bufp);
Takashi Iwaieb49faa2013-03-15 09:19:11 +01001419 err_alloc:
1420 spin_lock_irq(&chip->reg_lock);
1421 if (azx_dev->opened)
1422 *azx_dev = chip->saved_azx_dev;
1423 azx_dev->locked = 0;
1424 spin_unlock_irq(&chip->reg_lock);
1425 unlock:
1426 dsp_unlock(azx_dev);
Takashi Iwai1d1a4562012-09-20 20:29:13 -07001427 return err;
1428}
1429
1430static void azx_load_dsp_trigger(struct hda_bus *bus, bool start)
1431{
1432 struct azx *chip = bus->private_data;
1433 struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip);
1434
1435 if (start)
1436 azx_stream_start(chip, azx_dev);
1437 else
1438 azx_stream_stop(chip, azx_dev);
1439 azx_dev->running = start;
1440}
1441
1442static void azx_load_dsp_cleanup(struct hda_bus *bus,
1443 struct snd_dma_buffer *dmab)
1444{
1445 struct azx *chip = bus->private_data;
1446 struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip);
1447
Takashi Iwaieb49faa2013-03-15 09:19:11 +01001448 if (!dmab->area || !azx_dev->locked)
Takashi Iwaib3667bd2013-02-10 11:58:40 +01001449 return;
1450
Takashi Iwaieb49faa2013-03-15 09:19:11 +01001451 dsp_lock(azx_dev);
Takashi Iwai1d1a4562012-09-20 20:29:13 -07001452 /* reset BDL address */
Dylan Reid40830812014-02-28 15:41:13 -08001453 azx_sd_writel(chip, azx_dev, SD_BDLPL, 0);
1454 azx_sd_writel(chip, azx_dev, SD_BDLPU, 0);
1455 azx_sd_writel(chip, azx_dev, SD_CTL, 0);
Takashi Iwai1d1a4562012-09-20 20:29:13 -07001456 azx_dev->bufsize = 0;
1457 azx_dev->period_bytes = 0;
1458 azx_dev->format_val = 0;
1459
Dylan Reidb419b352014-02-28 15:41:20 -08001460 chip->ops->dma_free_pages(chip, dmab);
Takashi Iwaib3667bd2013-02-10 11:58:40 +01001461 dmab->area = NULL;
Takashi Iwai1d1a4562012-09-20 20:29:13 -07001462
Takashi Iwaieb49faa2013-03-15 09:19:11 +01001463 spin_lock_irq(&chip->reg_lock);
1464 if (azx_dev->opened)
1465 *azx_dev = chip->saved_azx_dev;
1466 azx_dev->locked = 0;
1467 spin_unlock_irq(&chip->reg_lock);
1468 dsp_unlock(azx_dev);
Takashi Iwai1d1a4562012-09-20 20:29:13 -07001469}
1470#endif /* CONFIG_SND_HDA_DSP_LOADER */
1471
Takashi Iwai83012a72012-08-24 18:38:08 +02001472#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02001473/* power-up/down the controller */
Takashi Iwai68467f52012-08-28 09:14:29 -07001474static void azx_power_notify(struct hda_bus *bus, bool power_up)
Takashi Iwaicb53c622007-08-10 17:21:45 +02001475{
Takashi Iwai33fa35e2008-11-06 16:50:40 +01001476 struct azx *chip = bus->private_data;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001477
Takashi Iwai2ea3c6a2012-11-19 20:03:37 +01001478 if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME))
1479 return;
1480
Takashi Iwai68467f52012-08-28 09:14:29 -07001481 if (power_up)
Dylan Reid89287562014-02-28 15:41:15 -08001482 pm_runtime_get_sync(chip->card->dev);
Mengdong Linb8dfc4622012-08-23 17:32:30 +08001483 else
Dylan Reid89287562014-02-28 15:41:15 -08001484 pm_runtime_put_sync(chip->card->dev);
Takashi Iwaicb53c622007-08-10 17:21:45 +02001485}
Takashi Iwai65fcd412012-08-14 17:13:32 +02001486
1487static DEFINE_MUTEX(card_list_lock);
1488static LIST_HEAD(card_list);
1489
1490static void azx_add_card_list(struct azx *chip)
1491{
1492 mutex_lock(&card_list_lock);
1493 list_add(&chip->list, &card_list);
1494 mutex_unlock(&card_list_lock);
1495}
1496
1497static void azx_del_card_list(struct azx *chip)
1498{
1499 mutex_lock(&card_list_lock);
1500 list_del_init(&chip->list);
1501 mutex_unlock(&card_list_lock);
1502}
1503
1504/* trigger power-save check at writing parameter */
1505static int param_set_xint(const char *val, const struct kernel_param *kp)
1506{
1507 struct azx *chip;
1508 struct hda_codec *c;
1509 int prev = power_save;
1510 int ret = param_set_int(val, kp);
1511
1512 if (ret || prev == power_save)
1513 return ret;
1514
1515 mutex_lock(&card_list_lock);
1516 list_for_each_entry(chip, &card_list, list) {
1517 if (!chip->bus || chip->disabled)
1518 continue;
1519 list_for_each_entry(c, &chip->bus->codec_list, list)
1520 snd_hda_power_sync(c);
1521 }
1522 mutex_unlock(&card_list_lock);
1523 return 0;
1524}
1525#else
1526#define azx_add_card_list(chip) /* NOP */
1527#define azx_del_card_list(chip) /* NOP */
Takashi Iwai83012a72012-08-24 18:38:08 +02001528#endif /* CONFIG_PM */
Takashi Iwai5c0b9be2008-12-11 11:47:17 +01001529
Takashi Iwai7ccbde52012-08-14 18:10:09 +02001530#if defined(CONFIG_PM_SLEEP) || defined(SUPPORT_VGA_SWITCHEROO)
Takashi Iwai5c0b9be2008-12-11 11:47:17 +01001531/*
1532 * power management
1533 */
Takashi Iwai68cb2b52012-07-02 15:20:37 +02001534static int azx_suspend(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535{
Takashi Iwai68cb2b52012-07-02 15:20:37 +02001536 struct pci_dev *pci = to_pci_dev(dev);
1537 struct snd_card *card = dev_get_drvdata(dev);
Takashi Iwai421a1252005-11-17 16:11:09 +01001538 struct azx *chip = card->private_data;
Takashi Iwai01b65bf2011-11-24 14:31:46 +01001539 struct azx_pcm *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
Takashi Iwaic5c21522012-12-04 17:01:25 +01001541 if (chip->disabled)
1542 return 0;
1543
Takashi Iwai421a1252005-11-17 16:11:09 +01001544 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
Takashi Iwai9ad593f2008-05-16 12:34:47 +02001545 azx_clear_irq_pending(chip);
Takashi Iwai01b65bf2011-11-24 14:31:46 +01001546 list_for_each_entry(p, &chip->pcm_list, list)
1547 snd_pcm_suspend_all(p->pcm);
Takashi Iwai0b7a2e92007-08-14 15:18:26 +02001548 if (chip->initialized)
Takashi Iwai8dd78332009-06-02 01:16:07 +02001549 snd_hda_suspend(chip->bus);
Takashi Iwaicb53c622007-08-10 17:21:45 +02001550 azx_stop_chip(chip);
Mengdong Lin7295b262013-06-25 05:58:49 -04001551 azx_enter_link_reset(chip);
Takashi Iwai30b35392006-10-11 18:52:53 +02001552 if (chip->irq >= 0) {
Takashi Iwai43001c92006-09-08 12:30:03 +02001553 free_irq(chip->irq, chip);
Takashi Iwai30b35392006-10-11 18:52:53 +02001554 chip->irq = -1;
1555 }
Takashi Iwai68e7fff2006-10-23 13:40:59 +02001556 if (chip->msi)
Takashi Iwai43001c92006-09-08 12:30:03 +02001557 pci_disable_msi(chip->pci);
Takashi Iwai421a1252005-11-17 16:11:09 +01001558 pci_disable_device(pci);
1559 pci_save_state(pci);
Takashi Iwai68cb2b52012-07-02 15:20:37 +02001560 pci_set_power_state(pci, PCI_D3hot);
Wang Xingchao99a20082013-05-30 22:07:10 +08001561 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
1562 hda_display_power(false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 return 0;
1564}
1565
Takashi Iwai68cb2b52012-07-02 15:20:37 +02001566static int azx_resume(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567{
Takashi Iwai68cb2b52012-07-02 15:20:37 +02001568 struct pci_dev *pci = to_pci_dev(dev);
1569 struct snd_card *card = dev_get_drvdata(dev);
Takashi Iwai421a1252005-11-17 16:11:09 +01001570 struct azx *chip = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
Takashi Iwaic5c21522012-12-04 17:01:25 +01001572 if (chip->disabled)
1573 return 0;
1574
Wang Xingchao99a20082013-05-30 22:07:10 +08001575 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
1576 hda_display_power(true);
Takashi Iwaid14a7e02009-02-16 10:13:03 +01001577 pci_set_power_state(pci, PCI_D0);
1578 pci_restore_state(pci);
Takashi Iwai30b35392006-10-11 18:52:53 +02001579 if (pci_enable_device(pci) < 0) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001580 dev_err(chip->card->dev,
1581 "pci_enable_device failed, disabling device\n");
Takashi Iwai30b35392006-10-11 18:52:53 +02001582 snd_card_disconnect(card);
1583 return -EIO;
1584 }
1585 pci_set_master(pci);
Takashi Iwai68e7fff2006-10-23 13:40:59 +02001586 if (chip->msi)
1587 if (pci_enable_msi(pci) < 0)
1588 chip->msi = 0;
1589 if (azx_acquire_irq(chip, 1) < 0)
Takashi Iwai30b35392006-10-11 18:52:53 +02001590 return -EIO;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001591 azx_init_pci(chip);
Maxim Levitskyd804ad92007-09-03 15:28:04 +02001592
Takashi Iwai7f308302012-05-08 16:52:23 +02001593 azx_init_chip(chip, 1);
Maxim Levitskyd804ad92007-09-03 15:28:04 +02001594
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 snd_hda_resume(chip->bus);
Takashi Iwai421a1252005-11-17 16:11:09 +01001596 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 return 0;
1598}
Mengdong Linb8dfc4622012-08-23 17:32:30 +08001599#endif /* CONFIG_PM_SLEEP || SUPPORT_VGA_SWITCHEROO */
1600
1601#ifdef CONFIG_PM_RUNTIME
1602static int azx_runtime_suspend(struct device *dev)
1603{
1604 struct snd_card *card = dev_get_drvdata(dev);
1605 struct azx *chip = card->private_data;
1606
Dave Airlie246efa42013-07-29 15:19:29 +10001607 if (chip->disabled)
1608 return 0;
1609
1610 if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME))
1611 return 0;
1612
Wang Xingchao7d4f6062013-07-25 23:34:46 -04001613 /* enable controller wake up event */
1614 azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) |
1615 STATESTS_INT_MASK);
1616
Mengdong Linb8dfc4622012-08-23 17:32:30 +08001617 azx_stop_chip(chip);
Takashi Iwai873ce8a2013-11-26 11:58:40 +01001618 azx_enter_link_reset(chip);
Mengdong Linb8dfc4622012-08-23 17:32:30 +08001619 azx_clear_irq_pending(chip);
Wang Xingchao99a20082013-05-30 22:07:10 +08001620 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
1621 hda_display_power(false);
Mengdong Linb8dfc4622012-08-23 17:32:30 +08001622 return 0;
1623}
1624
1625static int azx_runtime_resume(struct device *dev)
1626{
1627 struct snd_card *card = dev_get_drvdata(dev);
1628 struct azx *chip = card->private_data;
Wang Xingchao7d4f6062013-07-25 23:34:46 -04001629 struct hda_bus *bus;
1630 struct hda_codec *codec;
1631 int status;
Mengdong Linb8dfc4622012-08-23 17:32:30 +08001632
Dave Airlie246efa42013-07-29 15:19:29 +10001633 if (chip->disabled)
1634 return 0;
1635
1636 if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME))
1637 return 0;
1638
Wang Xingchao99a20082013-05-30 22:07:10 +08001639 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
1640 hda_display_power(true);
Wang Xingchao7d4f6062013-07-25 23:34:46 -04001641
1642 /* Read STATESTS before controller reset */
1643 status = azx_readw(chip, STATESTS);
1644
Mengdong Linb8dfc4622012-08-23 17:32:30 +08001645 azx_init_pci(chip);
1646 azx_init_chip(chip, 1);
Wang Xingchao7d4f6062013-07-25 23:34:46 -04001647
1648 bus = chip->bus;
1649 if (status && bus) {
1650 list_for_each_entry(codec, &bus->codec_list, list)
1651 if (status & (1 << codec->addr))
1652 queue_delayed_work(codec->bus->workq,
1653 &codec->jackpoll_work, codec->jackpoll_interval);
1654 }
1655
1656 /* disable controller Wake Up event*/
1657 azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) &
1658 ~STATESTS_INT_MASK);
1659
Mengdong Linb8dfc4622012-08-23 17:32:30 +08001660 return 0;
1661}
Takashi Iwai6eb827d2012-12-12 11:50:12 +01001662
1663static int azx_runtime_idle(struct device *dev)
1664{
1665 struct snd_card *card = dev_get_drvdata(dev);
1666 struct azx *chip = card->private_data;
1667
Dave Airlie246efa42013-07-29 15:19:29 +10001668 if (chip->disabled)
1669 return 0;
1670
Takashi Iwai6eb827d2012-12-12 11:50:12 +01001671 if (!power_save_controller ||
1672 !(chip->driver_caps & AZX_DCAPS_PM_RUNTIME))
1673 return -EBUSY;
1674
1675 return 0;
1676}
1677
Mengdong Linb8dfc4622012-08-23 17:32:30 +08001678#endif /* CONFIG_PM_RUNTIME */
1679
1680#ifdef CONFIG_PM
1681static const struct dev_pm_ops azx_pm = {
1682 SET_SYSTEM_SLEEP_PM_OPS(azx_suspend, azx_resume)
Takashi Iwai6eb827d2012-12-12 11:50:12 +01001683 SET_RUNTIME_PM_OPS(azx_runtime_suspend, azx_runtime_resume, azx_runtime_idle)
Mengdong Linb8dfc4622012-08-23 17:32:30 +08001684};
1685
Takashi Iwai68cb2b52012-07-02 15:20:37 +02001686#define AZX_PM_OPS &azx_pm
1687#else
Takashi Iwai68cb2b52012-07-02 15:20:37 +02001688#define AZX_PM_OPS NULL
Mengdong Linb8dfc4622012-08-23 17:32:30 +08001689#endif /* CONFIG_PM */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690
1691
1692/*
Takashi Iwai0cbf0092008-10-29 16:18:25 +01001693 * reboot notifier for hang-up problem at power-down
1694 */
1695static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf)
1696{
1697 struct azx *chip = container_of(nb, struct azx, reboot_notifier);
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01001698 snd_hda_bus_reboot_notify(chip->bus);
Takashi Iwai0cbf0092008-10-29 16:18:25 +01001699 azx_stop_chip(chip);
1700 return NOTIFY_OK;
1701}
1702
1703static void azx_notifier_register(struct azx *chip)
1704{
1705 chip->reboot_notifier.notifier_call = azx_halt;
1706 register_reboot_notifier(&chip->reboot_notifier);
1707}
1708
1709static void azx_notifier_unregister(struct azx *chip)
1710{
1711 if (chip->reboot_notifier.notifier_call)
1712 unregister_reboot_notifier(&chip->reboot_notifier);
1713}
1714
Takashi Iwai48c8b0e2012-12-07 07:40:35 +01001715static int azx_probe_continue(struct azx *chip);
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001716
Steven Newbury8393ec4a2012-06-08 13:06:29 +02001717#ifdef SUPPORT_VGA_SWITCHEROO
Bill Pembertone23e7a12012-12-06 12:35:10 -05001718static struct pci_dev *get_bound_vga(struct pci_dev *pci);
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001719
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001720static void azx_vs_set_state(struct pci_dev *pci,
1721 enum vga_switcheroo_state state)
1722{
1723 struct snd_card *card = pci_get_drvdata(pci);
1724 struct azx *chip = card->private_data;
1725 bool disabled;
1726
Takashi Iwaif4c482a2012-12-04 15:09:23 +01001727 wait_for_completion(&chip->probe_wait);
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001728 if (chip->init_failed)
1729 return;
1730
1731 disabled = (state == VGA_SWITCHEROO_OFF);
1732 if (chip->disabled == disabled)
1733 return;
1734
1735 if (!chip->bus) {
1736 chip->disabled = disabled;
1737 if (!disabled) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001738 dev_info(chip->card->dev,
1739 "Start delayed initialization\n");
Takashi Iwai5c906802013-05-30 22:07:09 +08001740 if (azx_probe_continue(chip) < 0) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001741 dev_err(chip->card->dev, "initialization error\n");
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001742 chip->init_failed = true;
1743 }
1744 }
1745 } else {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001746 dev_info(chip->card->dev, "%s via VGA-switcheroo\n",
1747 disabled ? "Disabling" : "Enabling");
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001748 if (disabled) {
Dylan Reid89287562014-02-28 15:41:15 -08001749 pm_runtime_put_sync_suspend(card->dev);
1750 azx_suspend(card->dev);
Dave Airlie246efa42013-07-29 15:19:29 +10001751 /* when we get suspended by vga switcheroo we end up in D3cold,
1752 * however we have no ACPI handle, so pci/acpi can't put us there,
1753 * put ourselves there */
1754 pci->current_state = PCI_D3cold;
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001755 chip->disabled = true;
Takashi Iwai128960a2012-10-12 17:28:18 +02001756 if (snd_hda_lock_devices(chip->bus))
Takashi Iwai4e76a882014-02-25 12:21:03 +01001757 dev_warn(chip->card->dev,
1758 "Cannot lock devices!\n");
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001759 } else {
1760 snd_hda_unlock_devices(chip->bus);
Dylan Reid89287562014-02-28 15:41:15 -08001761 pm_runtime_get_noresume(card->dev);
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001762 chip->disabled = false;
Dylan Reid89287562014-02-28 15:41:15 -08001763 azx_resume(card->dev);
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001764 }
1765 }
1766}
1767
1768static bool azx_vs_can_switch(struct pci_dev *pci)
1769{
1770 struct snd_card *card = pci_get_drvdata(pci);
1771 struct azx *chip = card->private_data;
1772
Takashi Iwaif4c482a2012-12-04 15:09:23 +01001773 wait_for_completion(&chip->probe_wait);
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001774 if (chip->init_failed)
1775 return false;
1776 if (chip->disabled || !chip->bus)
1777 return true;
1778 if (snd_hda_lock_devices(chip->bus))
1779 return false;
1780 snd_hda_unlock_devices(chip->bus);
1781 return true;
1782}
1783
Bill Pembertone23e7a12012-12-06 12:35:10 -05001784static void init_vga_switcheroo(struct azx *chip)
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001785{
1786 struct pci_dev *p = get_bound_vga(chip->pci);
1787 if (p) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001788 dev_info(chip->card->dev,
1789 "Handle VGA-switcheroo audio client\n");
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001790 chip->use_vga_switcheroo = 1;
1791 pci_dev_put(p);
1792 }
1793}
1794
1795static const struct vga_switcheroo_client_ops azx_vs_ops = {
1796 .set_gpu_state = azx_vs_set_state,
1797 .can_switch = azx_vs_can_switch,
1798};
1799
Bill Pembertone23e7a12012-12-06 12:35:10 -05001800static int register_vga_switcheroo(struct azx *chip)
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001801{
Takashi Iwai128960a2012-10-12 17:28:18 +02001802 int err;
1803
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001804 if (!chip->use_vga_switcheroo)
1805 return 0;
1806 /* FIXME: currently only handling DIS controller
1807 * is there any machine with two switchable HDMI audio controllers?
1808 */
Takashi Iwai128960a2012-10-12 17:28:18 +02001809 err = vga_switcheroo_register_audio_client(chip->pci, &azx_vs_ops,
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001810 VGA_SWITCHEROO_DIS,
1811 chip->bus != NULL);
Takashi Iwai128960a2012-10-12 17:28:18 +02001812 if (err < 0)
1813 return err;
1814 chip->vga_switcheroo_registered = 1;
Dave Airlie246efa42013-07-29 15:19:29 +10001815
1816 /* register as an optimus hdmi audio power domain */
Dylan Reid89287562014-02-28 15:41:15 -08001817 vga_switcheroo_init_domain_pm_optimus_hdmi_audio(chip->card->dev,
1818 &chip->hdmi_pm_domain);
Takashi Iwai128960a2012-10-12 17:28:18 +02001819 return 0;
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001820}
1821#else
1822#define init_vga_switcheroo(chip) /* NOP */
1823#define register_vga_switcheroo(chip) 0
Steven Newbury8393ec4a2012-06-08 13:06:29 +02001824#define check_hdmi_disabled(pci) false
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001825#endif /* SUPPORT_VGA_SWITCHER */
1826
Takashi Iwai0cbf0092008-10-29 16:18:25 +01001827/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 * destructor
1829 */
Takashi Iwaia98f90f2005-11-17 14:59:02 +01001830static int azx_free(struct azx *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831{
Wang Xingchaoc67e2222013-05-30 22:07:08 +08001832 struct pci_dev *pci = chip->pci;
Takashi Iwai4ce107b2008-02-06 14:50:19 +01001833 int i;
1834
Wang Xingchaoc67e2222013-05-30 22:07:08 +08001835 if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME)
1836 && chip->running)
1837 pm_runtime_get_noresume(&pci->dev);
1838
Takashi Iwai65fcd412012-08-14 17:13:32 +02001839 azx_del_card_list(chip);
1840
Takashi Iwai0cbf0092008-10-29 16:18:25 +01001841 azx_notifier_unregister(chip);
1842
Takashi Iwaif4c482a2012-12-04 15:09:23 +01001843 chip->init_failed = 1; /* to be sure */
Daniel J Blueman44728e92012-12-18 23:59:33 +08001844 complete_all(&chip->probe_wait);
Takashi Iwaif4c482a2012-12-04 15:09:23 +01001845
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001846 if (use_vga_switcheroo(chip)) {
1847 if (chip->disabled && chip->bus)
1848 snd_hda_unlock_devices(chip->bus);
Takashi Iwai128960a2012-10-12 17:28:18 +02001849 if (chip->vga_switcheroo_registered)
1850 vga_switcheroo_unregister_client(chip->pci);
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001851 }
1852
Takashi Iwaice43fba2005-05-30 20:33:44 +02001853 if (chip->initialized) {
Takashi Iwai9ad593f2008-05-16 12:34:47 +02001854 azx_clear_irq_pending(chip);
Takashi Iwai07e4ca52005-08-24 14:14:57 +02001855 for (i = 0; i < chip->num_streams; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 azx_stream_stop(chip, &chip->azx_dev[i]);
Takashi Iwaicb53c622007-08-10 17:21:45 +02001857 azx_stop_chip(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 }
1859
Jeff Garzikf000fd82008-04-22 13:50:34 +02001860 if (chip->irq >= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 free_irq(chip->irq, (void*)chip);
Takashi Iwai68e7fff2006-10-23 13:40:59 +02001862 if (chip->msi)
Takashi Iwai30b35392006-10-11 18:52:53 +02001863 pci_disable_msi(chip->pci);
Takashi Iwaif079c252006-06-01 11:42:14 +02001864 if (chip->remap_addr)
1865 iounmap(chip->remap_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866
Dylan Reid67908992014-02-28 15:41:23 -08001867 azx_free_stream_pages(chip);
Takashi Iwaia82d51e2012-04-26 12:23:42 +02001868 if (chip->region_requested)
1869 pci_release_regions(chip->pci);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 pci_disable_device(chip->pci);
Takashi Iwai07e4ca52005-08-24 14:14:57 +02001871 kfree(chip->azx_dev);
Takashi Iwai4918cda2012-08-09 12:33:28 +02001872#ifdef CONFIG_SND_HDA_PATCH_LOADER
1873 if (chip->fw)
1874 release_firmware(chip->fw);
1875#endif
Wang Xingchao99a20082013-05-30 22:07:10 +08001876 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
1877 hda_display_power(false);
1878 hda_i915_exit();
1879 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 kfree(chip);
1881
1882 return 0;
1883}
1884
Takashi Iwaia98f90f2005-11-17 14:59:02 +01001885static int azx_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886{
1887 return azx_free(device->device_data);
1888}
1889
Steven Newbury8393ec4a2012-06-08 13:06:29 +02001890#ifdef SUPPORT_VGA_SWITCHEROO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891/*
Takashi Iwai91219472012-04-26 12:13:25 +02001892 * Check of disabled HDMI controller by vga-switcheroo
1893 */
Bill Pembertone23e7a12012-12-06 12:35:10 -05001894static struct pci_dev *get_bound_vga(struct pci_dev *pci)
Takashi Iwai91219472012-04-26 12:13:25 +02001895{
1896 struct pci_dev *p;
1897
1898 /* check only discrete GPU */
1899 switch (pci->vendor) {
1900 case PCI_VENDOR_ID_ATI:
1901 case PCI_VENDOR_ID_AMD:
1902 case PCI_VENDOR_ID_NVIDIA:
1903 if (pci->devfn == 1) {
1904 p = pci_get_domain_bus_and_slot(pci_domain_nr(pci->bus),
1905 pci->bus->number, 0);
1906 if (p) {
1907 if ((p->class >> 8) == PCI_CLASS_DISPLAY_VGA)
1908 return p;
1909 pci_dev_put(p);
1910 }
1911 }
1912 break;
1913 }
1914 return NULL;
1915}
1916
Bill Pembertone23e7a12012-12-06 12:35:10 -05001917static bool check_hdmi_disabled(struct pci_dev *pci)
Takashi Iwai91219472012-04-26 12:13:25 +02001918{
1919 bool vga_inactive = false;
1920 struct pci_dev *p = get_bound_vga(pci);
1921
1922 if (p) {
Takashi Iwai12b78a72012-06-07 12:15:16 +02001923 if (vga_switcheroo_get_client_state(p) == VGA_SWITCHEROO_OFF)
Takashi Iwai91219472012-04-26 12:13:25 +02001924 vga_inactive = true;
1925 pci_dev_put(p);
1926 }
1927 return vga_inactive;
1928}
Steven Newbury8393ec4a2012-06-08 13:06:29 +02001929#endif /* SUPPORT_VGA_SWITCHEROO */
Takashi Iwai91219472012-04-26 12:13:25 +02001930
1931/*
Takashi Iwai3372a152007-02-01 15:46:50 +01001932 * white/black-listing for position_fix
1933 */
Bill Pembertone23e7a12012-12-06 12:35:10 -05001934static struct snd_pci_quirk position_fix_list[] = {
Takashi Iwaid2e1c972008-06-10 17:53:34 +02001935 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
1936 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
Takashi Iwai2f703e72009-12-01 14:17:37 +01001937 SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),
Takashi Iwaid2e1c972008-06-10 17:53:34 +02001938 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
Daniel T Chendd37f8e2010-05-30 01:17:03 -04001939 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB),
Daniel T Chen9f75c1b2010-05-30 13:08:41 -04001940 SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB),
Daniel T Chene96d3122010-05-27 18:32:18 -04001941 SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB),
David Henningssonb01de4f2012-01-12 16:31:14 +01001942 SND_PCI_QUIRK(0x10de, 0xcb89, "Macbook Pro 7,1", POS_FIX_LPIB),
Daniel T Chen61bb42c2010-05-29 11:04:11 -04001943 SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB),
Daniel T Chen9ec8dda2010-03-28 02:34:40 -04001944 SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB),
Takashi Iwai45d4ebf2009-11-30 11:58:30 +01001945 SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),
Takashi Iwai8815cd02010-04-15 09:02:41 +02001946 SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB),
Daniel T Chenb90c0762010-05-30 19:31:41 -04001947 SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB),
Daniel T Chen0e0280d2010-04-21 19:55:43 -04001948 SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB),
Takashi Iwai3372a152007-02-01 15:46:50 +01001949 {}
1950};
1951
Bill Pembertone23e7a12012-12-06 12:35:10 -05001952static int check_position_fix(struct azx *chip, int fix)
Takashi Iwai3372a152007-02-01 15:46:50 +01001953{
1954 const struct snd_pci_quirk *q;
1955
Takashi Iwaic673ba12009-03-17 07:49:14 +01001956 switch (fix) {
Takashi Iwai1dac6692012-09-13 14:59:47 +02001957 case POS_FIX_AUTO:
Takashi Iwaic673ba12009-03-17 07:49:14 +01001958 case POS_FIX_LPIB:
1959 case POS_FIX_POSBUF:
David Henningsson4cb36312010-09-30 10:12:50 +02001960 case POS_FIX_VIACOMBO:
Takashi Iwaia6f2fd52012-02-28 11:58:40 +01001961 case POS_FIX_COMBO:
Takashi Iwaic673ba12009-03-17 07:49:14 +01001962 return fix;
1963 }
1964
Takashi Iwaic673ba12009-03-17 07:49:14 +01001965 q = snd_pci_quirk_lookup(chip->pci, position_fix_list);
1966 if (q) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001967 dev_info(chip->card->dev,
1968 "position_fix set to %d for device %04x:%04x\n",
1969 q->value, q->subvendor, q->subdevice);
Takashi Iwaic673ba12009-03-17 07:49:14 +01001970 return q->value;
Takashi Iwai3372a152007-02-01 15:46:50 +01001971 }
David Henningssonbdd9ef22010-10-04 12:02:14 +02001972
1973 /* Check VIA/ATI HD Audio Controller exist */
Takashi Iwai9477c582011-05-25 09:11:37 +02001974 if (chip->driver_caps & AZX_DCAPS_POSFIX_VIA) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001975 dev_dbg(chip->card->dev, "Using VIACOMBO position fix\n");
David Henningssonbdd9ef22010-10-04 12:02:14 +02001976 return POS_FIX_VIACOMBO;
1977 }
Takashi Iwai9477c582011-05-25 09:11:37 +02001978 if (chip->driver_caps & AZX_DCAPS_POSFIX_LPIB) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001979 dev_dbg(chip->card->dev, "Using LPIB position fix\n");
Takashi Iwai9477c582011-05-25 09:11:37 +02001980 return POS_FIX_LPIB;
1981 }
Takashi Iwaic673ba12009-03-17 07:49:14 +01001982 return POS_FIX_AUTO;
Takashi Iwai3372a152007-02-01 15:46:50 +01001983}
1984
1985/*
Takashi Iwai669ba272007-08-17 09:17:36 +02001986 * black-lists for probe_mask
1987 */
Bill Pembertone23e7a12012-12-06 12:35:10 -05001988static struct snd_pci_quirk probe_mask_list[] = {
Takashi Iwai669ba272007-08-17 09:17:36 +02001989 /* Thinkpad often breaks the controller communication when accessing
1990 * to the non-working (or non-existing) modem codec slot.
1991 */
1992 SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01),
1993 SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01),
1994 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01),
Takashi Iwai0edb9452008-11-07 14:53:09 +01001995 /* broken BIOS */
1996 SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01),
Takashi Iwaief1681d2008-11-24 17:29:28 +01001997 /* including bogus ALC268 in slot#2 that conflicts with ALC888 */
1998 SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01),
Takashi Iwai20db7cb2009-02-13 08:18:48 +01001999 /* forced codec slots */
Ozan Çağlayan93574842009-05-23 15:00:04 +03002000 SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103),
Takashi Iwai20db7cb2009-02-13 08:18:48 +01002001 SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103),
Jaroslav Kyselaf3af9052012-04-26 17:52:35 +02002002 /* WinFast VP200 H (Teradici) user reported broken communication */
2003 SND_PCI_QUIRK(0x3a21, 0x040d, "WinFast VP200 H", 0x101),
Takashi Iwai669ba272007-08-17 09:17:36 +02002004 {}
2005};
2006
Takashi Iwaif1eaaee2009-02-13 08:16:55 +01002007#define AZX_FORCE_CODEC_MASK 0x100
2008
Bill Pembertone23e7a12012-12-06 12:35:10 -05002009static void check_probe_mask(struct azx *chip, int dev)
Takashi Iwai669ba272007-08-17 09:17:36 +02002010{
2011 const struct snd_pci_quirk *q;
2012
Takashi Iwaif1eaaee2009-02-13 08:16:55 +01002013 chip->codec_probe_mask = probe_mask[dev];
2014 if (chip->codec_probe_mask == -1) {
Takashi Iwai669ba272007-08-17 09:17:36 +02002015 q = snd_pci_quirk_lookup(chip->pci, probe_mask_list);
2016 if (q) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002017 dev_info(chip->card->dev,
2018 "probe_mask set to 0x%x for device %04x:%04x\n",
2019 q->value, q->subvendor, q->subdevice);
Takashi Iwaif1eaaee2009-02-13 08:16:55 +01002020 chip->codec_probe_mask = q->value;
Takashi Iwai669ba272007-08-17 09:17:36 +02002021 }
2022 }
Takashi Iwaif1eaaee2009-02-13 08:16:55 +01002023
2024 /* check forced option */
2025 if (chip->codec_probe_mask != -1 &&
2026 (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) {
2027 chip->codec_mask = chip->codec_probe_mask & 0xff;
Takashi Iwai4e76a882014-02-25 12:21:03 +01002028 dev_info(chip->card->dev, "codec_mask forced to 0x%x\n",
2029 chip->codec_mask);
Takashi Iwaif1eaaee2009-02-13 08:16:55 +01002030 }
Takashi Iwai669ba272007-08-17 09:17:36 +02002031}
2032
Takashi Iwai4d8e22e2009-08-11 14:21:26 +02002033/*
Takashi Iwai716238552009-09-28 13:14:04 +02002034 * white/black-list for enable_msi
Takashi Iwai4d8e22e2009-08-11 14:21:26 +02002035 */
Bill Pembertone23e7a12012-12-06 12:35:10 -05002036static struct snd_pci_quirk msi_black_list[] = {
David Henningsson693e0cb2013-12-12 09:52:03 +01002037 SND_PCI_QUIRK(0x103c, 0x2191, "HP", 0), /* AMD Hudson */
2038 SND_PCI_QUIRK(0x103c, 0x2192, "HP", 0), /* AMD Hudson */
2039 SND_PCI_QUIRK(0x103c, 0x21f7, "HP", 0), /* AMD Hudson */
2040 SND_PCI_QUIRK(0x103c, 0x21fa, "HP", 0), /* AMD Hudson */
Takashi Iwai9dc83982009-12-22 08:15:01 +01002041 SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */
Takashi Iwai0a27fcf2010-02-15 17:05:28 +01002042 SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */
Ralf Gerbigecd21622010-03-09 18:25:47 +01002043 SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */
Takashi Iwai83f72152013-09-09 10:20:48 +02002044 SND_PCI_QUIRK(0x1179, 0xfb44, "Toshiba Satellite C870", 0), /* AMD Hudson */
Michele Ballabio4193d132010-03-06 21:06:46 +01002045 SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */
Takashi Iwai38155952010-04-04 12:14:03 +02002046 SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */
Takashi Iwai4d8e22e2009-08-11 14:21:26 +02002047 {}
2048};
2049
Bill Pembertone23e7a12012-12-06 12:35:10 -05002050static void check_msi(struct azx *chip)
Takashi Iwai4d8e22e2009-08-11 14:21:26 +02002051{
2052 const struct snd_pci_quirk *q;
2053
Takashi Iwai716238552009-09-28 13:14:04 +02002054 if (enable_msi >= 0) {
2055 chip->msi = !!enable_msi;
Takashi Iwai4d8e22e2009-08-11 14:21:26 +02002056 return;
Takashi Iwai716238552009-09-28 13:14:04 +02002057 }
2058 chip->msi = 1; /* enable MSI as default */
2059 q = snd_pci_quirk_lookup(chip->pci, msi_black_list);
Takashi Iwai4d8e22e2009-08-11 14:21:26 +02002060 if (q) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002061 dev_info(chip->card->dev,
2062 "msi for device %04x:%04x set to %d\n",
2063 q->subvendor, q->subdevice, q->value);
Takashi Iwai4d8e22e2009-08-11 14:21:26 +02002064 chip->msi = q->value;
Takashi Iwai80c43ed2010-03-15 15:51:53 +01002065 return;
2066 }
2067
2068 /* NVidia chipsets seem to cause troubles with MSI */
Takashi Iwai9477c582011-05-25 09:11:37 +02002069 if (chip->driver_caps & AZX_DCAPS_NO_MSI) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002070 dev_info(chip->card->dev, "Disabling MSI\n");
Takashi Iwai80c43ed2010-03-15 15:51:53 +01002071 chip->msi = 0;
Takashi Iwai4d8e22e2009-08-11 14:21:26 +02002072 }
2073}
2074
Takashi Iwaia1585d72011-12-14 09:27:04 +01002075/* check the snoop mode availability */
Bill Pembertone23e7a12012-12-06 12:35:10 -05002076static void azx_check_snoop_available(struct azx *chip)
Takashi Iwaia1585d72011-12-14 09:27:04 +01002077{
2078 bool snoop = chip->snoop;
2079
2080 switch (chip->driver_type) {
2081 case AZX_DRIVER_VIA:
2082 /* force to non-snoop mode for a new VIA controller
2083 * when BIOS is set
2084 */
2085 if (snoop) {
2086 u8 val;
2087 pci_read_config_byte(chip->pci, 0x42, &val);
2088 if (!(val & 0x80) && chip->pci->revision == 0x30)
2089 snoop = false;
2090 }
2091 break;
2092 case AZX_DRIVER_ATIHDMI_NS:
2093 /* new ATI HDMI requires non-snoop */
2094 snoop = false;
2095 break;
Takashi Iwaic1279f82013-02-07 17:36:22 +01002096 case AZX_DRIVER_CTHDA:
2097 snoop = false;
2098 break;
Takashi Iwaia1585d72011-12-14 09:27:04 +01002099 }
2100
2101 if (snoop != chip->snoop) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002102 dev_info(chip->card->dev, "Force to %s mode\n",
2103 snoop ? "snoop" : "non-snoop");
Takashi Iwaia1585d72011-12-14 09:27:04 +01002104 chip->snoop = snoop;
2105 }
2106}
Takashi Iwai669ba272007-08-17 09:17:36 +02002107
Wang Xingchao99a20082013-05-30 22:07:10 +08002108static void azx_probe_work(struct work_struct *work)
2109{
2110 azx_probe_continue(container_of(work, struct azx, probe_work));
2111}
Wang Xingchao99a20082013-05-30 22:07:10 +08002112
Takashi Iwai669ba272007-08-17 09:17:36 +02002113/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 * constructor
2115 */
Bill Pembertone23e7a12012-12-06 12:35:10 -05002116static int azx_create(struct snd_card *card, struct pci_dev *pci,
2117 int dev, unsigned int driver_caps,
Dylan Reid40830812014-02-28 15:41:13 -08002118 const struct hda_controller_ops *hda_ops,
Bill Pembertone23e7a12012-12-06 12:35:10 -05002119 struct azx **rchip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120{
Takashi Iwaia98f90f2005-11-17 14:59:02 +01002121 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 .dev_free = azx_dev_free,
2123 };
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002124 struct azx *chip;
2125 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
2127 *rchip = NULL;
Tobin Davisbcd72002008-01-15 11:23:55 +01002128
Pavel Machek927fc862006-08-31 17:03:43 +02002129 err = pci_enable_device(pci);
2130 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 return err;
2132
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002133 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
Pavel Machek927fc862006-08-31 17:03:43 +02002134 if (!chip) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002135 dev_err(card->dev, "Cannot allocate chip\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 pci_disable_device(pci);
2137 return -ENOMEM;
2138 }
2139
2140 spin_lock_init(&chip->reg_lock);
Ingo Molnar62932df2006-01-16 16:34:20 +01002141 mutex_init(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 chip->card = card;
2143 chip->pci = pci;
Dylan Reid40830812014-02-28 15:41:13 -08002144 chip->ops = hda_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 chip->irq = -1;
Takashi Iwai9477c582011-05-25 09:11:37 +02002146 chip->driver_caps = driver_caps;
2147 chip->driver_type = driver_caps & 0xff;
Takashi Iwai4d8e22e2009-08-11 14:21:26 +02002148 check_msi(chip);
Takashi Iwai555e2192008-06-10 17:53:34 +02002149 chip->dev_index = dev;
Dylan Reid749ee282014-02-28 15:41:18 -08002150 chip->jackpoll_ms = jackpoll_ms;
Takashi Iwai9ad593f2008-05-16 12:34:47 +02002151 INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work);
Takashi Iwai01b65bf2011-11-24 14:31:46 +01002152 INIT_LIST_HEAD(&chip->pcm_list);
Takashi Iwai65fcd412012-08-14 17:13:32 +02002153 INIT_LIST_HEAD(&chip->list);
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002154 init_vga_switcheroo(chip);
Takashi Iwaif4c482a2012-12-04 15:09:23 +01002155 init_completion(&chip->probe_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156
Shahin Ghazinouribeaffc32010-05-11 08:19:55 +02002157 chip->position_fix[0] = chip->position_fix[1] =
2158 check_position_fix(chip, position_fix[dev]);
Takashi Iwaia6f2fd52012-02-28 11:58:40 +01002159 /* combo mode uses LPIB for playback */
2160 if (chip->position_fix[0] == POS_FIX_COMBO) {
2161 chip->position_fix[0] = POS_FIX_LPIB;
2162 chip->position_fix[1] = POS_FIX_AUTO;
2163 }
2164
Takashi Iwai5aba4f82008-01-07 15:16:37 +01002165 check_probe_mask(chip, dev);
Takashi Iwai3372a152007-02-01 15:46:50 +01002166
Takashi Iwai27346162006-01-12 18:28:44 +01002167 chip->single_cmd = single_cmd;
Takashi Iwai27fe48d92011-09-28 17:16:09 +02002168 chip->snoop = hda_snoop;
Takashi Iwaia1585d72011-12-14 09:27:04 +01002169 azx_check_snoop_available(chip);
Takashi Iwaic74db862005-05-12 14:26:27 +02002170
Takashi Iwai5c0d7bc2008-06-10 17:53:35 +02002171 if (bdl_pos_adj[dev] < 0) {
2172 switch (chip->driver_type) {
Takashi Iwai0c6341a2008-06-13 20:50:27 +02002173 case AZX_DRIVER_ICH:
Seth Heasley32679f92010-02-22 17:31:09 -08002174 case AZX_DRIVER_PCH:
Takashi Iwai0c6341a2008-06-13 20:50:27 +02002175 bdl_pos_adj[dev] = 1;
Takashi Iwai5c0d7bc2008-06-10 17:53:35 +02002176 break;
2177 default:
Takashi Iwai0c6341a2008-06-13 20:50:27 +02002178 bdl_pos_adj[dev] = 32;
Takashi Iwai5c0d7bc2008-06-10 17:53:35 +02002179 break;
2180 }
2181 }
Dylan Reid9cdc0112014-02-28 15:41:14 -08002182 chip->bdl_pos_adj = bdl_pos_adj;
Takashi Iwai5c0d7bc2008-06-10 17:53:35 +02002183
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002184 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
2185 if (err < 0) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002186 dev_err(card->dev, "Error creating device [card]!\n");
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002187 azx_free(chip);
2188 return err;
2189 }
2190
Wang Xingchao99a20082013-05-30 22:07:10 +08002191 /* continue probing in work context as may trigger request module */
2192 INIT_WORK(&chip->probe_work, azx_probe_work);
Wang Xingchao99a20082013-05-30 22:07:10 +08002193
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002194 *rchip = chip;
Wang Xingchao99a20082013-05-30 22:07:10 +08002195
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002196 return 0;
2197}
2198
Takashi Iwai48c8b0e2012-12-07 07:40:35 +01002199static int azx_first_init(struct azx *chip)
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002200{
2201 int dev = chip->dev_index;
2202 struct pci_dev *pci = chip->pci;
2203 struct snd_card *card = chip->card;
Dylan Reid67908992014-02-28 15:41:23 -08002204 int err;
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002205 unsigned short gcap;
2206
Takashi Iwai07e4ca52005-08-24 14:14:57 +02002207#if BITS_PER_LONG != 64
2208 /* Fix up base address on ULI M5461 */
2209 if (chip->driver_type == AZX_DRIVER_ULI) {
2210 u16 tmp3;
2211 pci_read_config_word(pci, 0x40, &tmp3);
2212 pci_write_config_word(pci, 0x40, tmp3 | 0x10);
2213 pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0);
2214 }
2215#endif
2216
Pavel Machek927fc862006-08-31 17:03:43 +02002217 err = pci_request_regions(pci, "ICH HD audio");
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002218 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 return err;
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002220 chip->region_requested = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
Pavel Machek927fc862006-08-31 17:03:43 +02002222 chip->addr = pci_resource_start(pci, 0);
Arjan van de Ven2f5ad542008-09-28 16:20:09 -07002223 chip->remap_addr = pci_ioremap_bar(pci, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 if (chip->remap_addr == NULL) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002225 dev_err(card->dev, "ioremap error\n");
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002226 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 }
2228
Takashi Iwai68e7fff2006-10-23 13:40:59 +02002229 if (chip->msi)
2230 if (pci_enable_msi(pci) < 0)
2231 chip->msi = 0;
Stephen Hemminger7376d012006-08-21 19:17:46 +02002232
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002233 if (azx_acquire_irq(chip, 0) < 0)
2234 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235
2236 pci_set_master(pci);
2237 synchronize_irq(chip->irq);
2238
Tobin Davisbcd72002008-01-15 11:23:55 +01002239 gcap = azx_readw(chip, GCAP);
Takashi Iwai4e76a882014-02-25 12:21:03 +01002240 dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap);
Tobin Davisbcd72002008-01-15 11:23:55 +01002241
Andiry Brienzadc4c2e62009-07-08 13:55:31 +08002242 /* disable SB600 64bit support for safety */
Takashi Iwai9477c582011-05-25 09:11:37 +02002243 if (chip->pci->vendor == PCI_VENDOR_ID_ATI) {
Andiry Brienzadc4c2e62009-07-08 13:55:31 +08002244 struct pci_dev *p_smbus;
2245 p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
2246 PCI_DEVICE_ID_ATI_SBX00_SMBUS,
2247 NULL);
2248 if (p_smbus) {
2249 if (p_smbus->revision < 0x30)
2250 gcap &= ~ICH6_GCAP_64OK;
2251 pci_dev_put(p_smbus);
2252 }
2253 }
Takashi Iwai09240cf2009-03-17 07:47:18 +01002254
Takashi Iwai9477c582011-05-25 09:11:37 +02002255 /* disable 64bit DMA address on some devices */
2256 if (chip->driver_caps & AZX_DCAPS_NO_64BIT) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002257 dev_dbg(card->dev, "Disabling 64bit DMA\n");
Jaroslav Kysela396087e2009-12-09 10:44:47 +01002258 gcap &= ~ICH6_GCAP_64OK;
Takashi Iwai9477c582011-05-25 09:11:37 +02002259 }
Jaroslav Kysela396087e2009-12-09 10:44:47 +01002260
Pierre-Louis Bossart2ae66c22011-08-04 10:12:56 -05002261 /* disable buffer size rounding to 128-byte multiples if supported */
Takashi Iwai7bfe0592012-01-23 17:53:39 +01002262 if (align_buffer_size >= 0)
2263 chip->align_buffer_size = !!align_buffer_size;
2264 else {
2265 if (chip->driver_caps & AZX_DCAPS_BUFSIZE)
2266 chip->align_buffer_size = 0;
2267 else if (chip->driver_caps & AZX_DCAPS_ALIGN_BUFSIZE)
2268 chip->align_buffer_size = 1;
2269 else
2270 chip->align_buffer_size = 1;
2271 }
Pierre-Louis Bossart2ae66c22011-08-04 10:12:56 -05002272
Takashi Iwaicf7aaca2008-02-06 15:05:57 +01002273 /* allow 64bit DMA address if supported by H/W */
Takashi Iwaib21fadb2009-05-28 12:26:15 +02002274 if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64)))
Yang Hongyange9304382009-04-13 14:40:14 -07002275 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64));
Takashi Iwai09240cf2009-03-17 07:47:18 +01002276 else {
Yang Hongyange9304382009-04-13 14:40:14 -07002277 pci_set_dma_mask(pci, DMA_BIT_MASK(32));
2278 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32));
Takashi Iwai09240cf2009-03-17 07:47:18 +01002279 }
Takashi Iwaicf7aaca2008-02-06 15:05:57 +01002280
Takashi Iwai8b6ed8e2008-02-19 11:36:35 +01002281 /* read number of streams from GCAP register instead of using
2282 * hardcoded value
2283 */
2284 chip->capture_streams = (gcap >> 8) & 0x0f;
2285 chip->playback_streams = (gcap >> 12) & 0x0f;
2286 if (!chip->playback_streams && !chip->capture_streams) {
Tobin Davisbcd72002008-01-15 11:23:55 +01002287 /* gcap didn't give any info, switching to old method */
2288
2289 switch (chip->driver_type) {
2290 case AZX_DRIVER_ULI:
2291 chip->playback_streams = ULI_NUM_PLAYBACK;
2292 chip->capture_streams = ULI_NUM_CAPTURE;
Tobin Davisbcd72002008-01-15 11:23:55 +01002293 break;
2294 case AZX_DRIVER_ATIHDMI:
Andiry Xu1815b342011-12-14 16:10:27 +08002295 case AZX_DRIVER_ATIHDMI_NS:
Tobin Davisbcd72002008-01-15 11:23:55 +01002296 chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
2297 chip->capture_streams = ATIHDMI_NUM_CAPTURE;
Tobin Davisbcd72002008-01-15 11:23:55 +01002298 break;
Yang, Libinc4da29c2008-11-13 11:07:07 +01002299 case AZX_DRIVER_GENERIC:
Tobin Davisbcd72002008-01-15 11:23:55 +01002300 default:
2301 chip->playback_streams = ICH6_NUM_PLAYBACK;
2302 chip->capture_streams = ICH6_NUM_CAPTURE;
Tobin Davisbcd72002008-01-15 11:23:55 +01002303 break;
2304 }
Takashi Iwai07e4ca52005-08-24 14:14:57 +02002305 }
Takashi Iwai8b6ed8e2008-02-19 11:36:35 +01002306 chip->capture_index_offset = 0;
2307 chip->playback_index_offset = chip->capture_streams;
Takashi Iwai07e4ca52005-08-24 14:14:57 +02002308 chip->num_streams = chip->playback_streams + chip->capture_streams;
Takashi Iwaid01ce992007-07-27 16:52:19 +02002309 chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev),
2310 GFP_KERNEL);
Pavel Machek927fc862006-08-31 17:03:43 +02002311 if (!chip->azx_dev) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002312 dev_err(card->dev, "cannot malloc azx_dev\n");
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002313 return -ENOMEM;
Takashi Iwai07e4ca52005-08-24 14:14:57 +02002314 }
2315
Dylan Reid67908992014-02-28 15:41:23 -08002316 err = azx_alloc_stream_pages(chip);
2317 if (err < 0)
2318 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 /* allocate CORB/RIRB */
Takashi Iwai81740862009-05-26 15:22:00 +02002320 err = azx_alloc_cmd_io(chip);
2321 if (err < 0)
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002322 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323
2324 /* initialize streams */
2325 azx_init_stream(chip);
2326
2327 /* initialize chip */
Takashi Iwaicb53c622007-08-10 17:21:45 +02002328 azx_init_pci(chip);
Jaroslav Kysela10e77dd2010-03-26 11:04:38 +01002329 azx_init_chip(chip, (probe_only[dev] & 2) == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
2331 /* codec detection */
Pavel Machek927fc862006-08-31 17:03:43 +02002332 if (!chip->codec_mask) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002333 dev_err(card->dev, "no codecs found!\n");
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002334 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 }
2336
Takashi Iwai07e4ca52005-08-24 14:14:57 +02002337 strcpy(card->driver, "HDA-Intel");
Takashi Iwai18cb7102009-04-16 10:22:24 +02002338 strlcpy(card->shortname, driver_short_names[chip->driver_type],
2339 sizeof(card->shortname));
2340 snprintf(card->longname, sizeof(card->longname),
2341 "%s at 0x%lx irq %i",
2342 card->shortname, chip->addr, chip->irq);
Takashi Iwai07e4ca52005-08-24 14:14:57 +02002343
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345}
2346
Takashi Iwaicb53c622007-08-10 17:21:45 +02002347static void power_down_all_codecs(struct azx *chip)
2348{
Takashi Iwai83012a72012-08-24 18:38:08 +02002349#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02002350 /* The codecs were powered up in snd_hda_codec_new().
2351 * Now all initialization done, so turn them down if possible
2352 */
2353 struct hda_codec *codec;
2354 list_for_each_entry(codec, &chip->bus->codec_list, list) {
2355 snd_hda_power_down(codec);
2356 }
2357#endif
2358}
2359
Takashi Iwai97c6a3d2012-08-09 17:40:46 +02002360#ifdef CONFIG_SND_HDA_PATCH_LOADER
Takashi Iwai5cb543d2012-08-09 13:49:23 +02002361/* callback from request_firmware_nowait() */
2362static void azx_firmware_cb(const struct firmware *fw, void *context)
2363{
2364 struct snd_card *card = context;
2365 struct azx *chip = card->private_data;
2366 struct pci_dev *pci = chip->pci;
2367
2368 if (!fw) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002369 dev_err(card->dev, "Cannot load firmware, aborting\n");
Takashi Iwai5cb543d2012-08-09 13:49:23 +02002370 goto error;
2371 }
2372
2373 chip->fw = fw;
2374 if (!chip->disabled) {
2375 /* continue probing */
2376 if (azx_probe_continue(chip))
2377 goto error;
2378 }
2379 return; /* OK */
2380
2381 error:
2382 snd_card_free(card);
2383 pci_set_drvdata(pci, NULL);
2384}
Takashi Iwai97c6a3d2012-08-09 17:40:46 +02002385#endif
Takashi Iwai5cb543d2012-08-09 13:49:23 +02002386
Dylan Reid40830812014-02-28 15:41:13 -08002387/*
2388 * HDA controller ops.
2389 */
2390
2391/* PCI register access. */
2392static void pci_azx_writel(u32 value, u32 *addr)
2393{
2394 writel(value, addr);
2395}
2396
2397static u32 pci_azx_readl(u32 *addr)
2398{
2399 return readl(addr);
2400}
2401
2402static void pci_azx_writew(u16 value, u16 *addr)
2403{
2404 writew(value, addr);
2405}
2406
2407static u16 pci_azx_readw(u16 *addr)
2408{
2409 return readw(addr);
2410}
2411
2412static void pci_azx_writeb(u8 value, u8 *addr)
2413{
2414 writeb(value, addr);
2415}
2416
2417static u8 pci_azx_readb(u8 *addr)
2418{
2419 return readb(addr);
2420}
2421
Dylan Reidf46ea602014-02-28 15:41:16 -08002422static int disable_msi_reset_irq(struct azx *chip)
2423{
2424 int err;
2425
2426 free_irq(chip->irq, chip);
2427 chip->irq = -1;
2428 pci_disable_msi(chip->pci);
2429 chip->msi = 0;
2430 err = azx_acquire_irq(chip, 1);
2431 if (err < 0)
2432 return err;
2433
2434 return 0;
2435}
2436
Dylan Reidb419b352014-02-28 15:41:20 -08002437/* DMA page allocation helpers. */
2438static int dma_alloc_pages(struct azx *chip,
2439 int type,
2440 size_t size,
2441 struct snd_dma_buffer *buf)
2442{
2443 int err;
2444
2445 err = snd_dma_alloc_pages(type,
2446 chip->card->dev,
2447 size, buf);
2448 if (err < 0)
2449 return err;
2450 mark_pages_wc(chip, buf, true);
2451 return 0;
2452}
2453
2454static void dma_free_pages(struct azx *chip, struct snd_dma_buffer *buf)
2455{
2456 mark_pages_wc(chip, buf, false);
2457 snd_dma_free_pages(buf);
2458}
2459
2460static int substream_alloc_pages(struct azx *chip,
2461 struct snd_pcm_substream *substream,
2462 size_t size)
2463{
2464 struct azx_dev *azx_dev = get_azx_dev(substream);
2465 int ret;
2466
2467 mark_runtime_wc(chip, azx_dev, substream, false);
2468 azx_dev->bufsize = 0;
2469 azx_dev->period_bytes = 0;
2470 azx_dev->format_val = 0;
2471 ret = snd_pcm_lib_malloc_pages(substream, size);
2472 if (ret < 0)
2473 return ret;
2474 mark_runtime_wc(chip, azx_dev, substream, true);
2475 return 0;
2476}
2477
2478static int substream_free_pages(struct azx *chip,
2479 struct snd_pcm_substream *substream)
2480{
2481 struct azx_dev *azx_dev = get_azx_dev(substream);
2482 mark_runtime_wc(chip, azx_dev, substream, false);
2483 return snd_pcm_lib_free_pages(substream);
2484}
2485
Dylan Reid8769b2782014-02-28 15:41:21 -08002486static void pcm_mmap_prepare(struct snd_pcm_substream *substream,
2487 struct vm_area_struct *area)
2488{
2489#ifdef CONFIG_X86
2490 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
2491 struct azx *chip = apcm->chip;
2492 if (!azx_snoop(chip))
2493 area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
2494#endif
2495}
2496
Dylan Reid40830812014-02-28 15:41:13 -08002497static const struct hda_controller_ops pci_hda_ops = {
2498 .writel = pci_azx_writel,
2499 .readl = pci_azx_readl,
2500 .writew = pci_azx_writew,
2501 .readw = pci_azx_readw,
2502 .writeb = pci_azx_writeb,
2503 .readb = pci_azx_readb,
Dylan Reidf46ea602014-02-28 15:41:16 -08002504 .disable_msi_reset_irq = disable_msi_reset_irq,
Dylan Reidb419b352014-02-28 15:41:20 -08002505 .dma_alloc_pages = dma_alloc_pages,
2506 .dma_free_pages = dma_free_pages,
2507 .substream_alloc_pages = substream_alloc_pages,
2508 .substream_free_pages = substream_free_pages,
Dylan Reid8769b2782014-02-28 15:41:21 -08002509 .pcm_mmap_prepare = pcm_mmap_prepare,
Dylan Reid40830812014-02-28 15:41:13 -08002510};
2511
Bill Pembertone23e7a12012-12-06 12:35:10 -05002512static int azx_probe(struct pci_dev *pci,
2513 const struct pci_device_id *pci_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514{
Takashi Iwai5aba4f82008-01-07 15:16:37 +01002515 static int dev;
Takashi Iwaia98f90f2005-11-17 14:59:02 +01002516 struct snd_card *card;
2517 struct azx *chip;
Takashi Iwaiaad730d2013-12-02 13:33:57 +01002518 bool schedule_probe;
Pavel Machek927fc862006-08-31 17:03:43 +02002519 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520
Takashi Iwai5aba4f82008-01-07 15:16:37 +01002521 if (dev >= SNDRV_CARDS)
2522 return -ENODEV;
2523 if (!enable[dev]) {
2524 dev++;
2525 return -ENOENT;
2526 }
2527
Takashi Iwai60c57722014-01-29 14:20:19 +01002528 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2529 0, &card);
Takashi Iwaie58de7b2008-12-28 16:44:30 +01002530 if (err < 0) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002531 dev_err(&pci->dev, "Error creating card!\n");
Takashi Iwaie58de7b2008-12-28 16:44:30 +01002532 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 }
2534
Dylan Reid40830812014-02-28 15:41:13 -08002535 err = azx_create(card, pci, dev, pci_id->driver_data,
2536 &pci_hda_ops, &chip);
Wu Fengguang41dda0f2008-11-20 09:24:52 +08002537 if (err < 0)
2538 goto out_free;
Takashi Iwai421a1252005-11-17 16:11:09 +01002539 card->private_data = chip;
Takashi Iwaif4c482a2012-12-04 15:09:23 +01002540
2541 pci_set_drvdata(pci, card);
2542
2543 err = register_vga_switcheroo(chip);
2544 if (err < 0) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002545 dev_err(card->dev, "Error registering VGA-switcheroo client\n");
Takashi Iwaif4c482a2012-12-04 15:09:23 +01002546 goto out_free;
2547 }
2548
2549 if (check_hdmi_disabled(pci)) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002550 dev_info(card->dev, "VGA controller is disabled\n");
2551 dev_info(card->dev, "Delaying initialization\n");
Takashi Iwaif4c482a2012-12-04 15:09:23 +01002552 chip->disabled = true;
2553 }
2554
Takashi Iwaiaad730d2013-12-02 13:33:57 +01002555 schedule_probe = !chip->disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556
Takashi Iwai4918cda2012-08-09 12:33:28 +02002557#ifdef CONFIG_SND_HDA_PATCH_LOADER
2558 if (patch[dev] && *patch[dev]) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002559 dev_info(card->dev, "Applying patch firmware '%s'\n",
2560 patch[dev]);
Takashi Iwai5cb543d2012-08-09 13:49:23 +02002561 err = request_firmware_nowait(THIS_MODULE, true, patch[dev],
2562 &pci->dev, GFP_KERNEL, card,
2563 azx_firmware_cb);
Takashi Iwai4918cda2012-08-09 12:33:28 +02002564 if (err < 0)
2565 goto out_free;
Takashi Iwaiaad730d2013-12-02 13:33:57 +01002566 schedule_probe = false; /* continued in azx_firmware_cb() */
Takashi Iwai4918cda2012-08-09 12:33:28 +02002567 }
2568#endif /* CONFIG_SND_HDA_PATCH_LOADER */
2569
Takashi Iwaiaad730d2013-12-02 13:33:57 +01002570#ifndef CONFIG_SND_HDA_I915
2571 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
Takashi Iwai4e76a882014-02-25 12:21:03 +01002572 dev_err(card->dev, "Haswell must build in CONFIG_SND_HDA_I915\n");
Wang Xingchao99a20082013-05-30 22:07:10 +08002573#endif
Wang Xingchao99a20082013-05-30 22:07:10 +08002574
Takashi Iwaiaad730d2013-12-02 13:33:57 +01002575 if (schedule_probe)
2576 schedule_work(&chip->probe_work);
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002577
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002578 dev++;
Takashi Iwai88d071f2013-12-02 11:12:28 +01002579 if (chip->disabled)
2580 complete_all(&chip->probe_wait);
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002581 return 0;
2582
2583out_free:
2584 snd_card_free(card);
2585 return err;
2586}
2587
Dylan Reide62a42a2014-02-28 15:41:19 -08002588/* number of codec slots for each chipset: 0 = default slots (i.e. 4) */
2589static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] = {
2590 [AZX_DRIVER_NVIDIA] = 8,
2591 [AZX_DRIVER_TERA] = 1,
2592};
2593
Takashi Iwai48c8b0e2012-12-07 07:40:35 +01002594static int azx_probe_continue(struct azx *chip)
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002595{
Wang Xingchaoc67e2222013-05-30 22:07:08 +08002596 struct pci_dev *pci = chip->pci;
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002597 int dev = chip->dev_index;
2598 int err;
2599
Wang Xingchao99a20082013-05-30 22:07:10 +08002600 /* Request power well for Haswell HDA controller and codec */
2601 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
David Henningssonc841ad22013-08-19 13:32:30 +02002602#ifdef CONFIG_SND_HDA_I915
Wang Xingchao99a20082013-05-30 22:07:10 +08002603 err = hda_i915_init();
2604 if (err < 0) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002605 dev_err(chip->card->dev,
2606 "Error request power-well from i915\n");
Wang Xingchao99a20082013-05-30 22:07:10 +08002607 goto out_free;
2608 }
David Henningssonc841ad22013-08-19 13:32:30 +02002609#endif
Wang Xingchao99a20082013-05-30 22:07:10 +08002610 hda_display_power(true);
2611 }
2612
Takashi Iwai5c906802013-05-30 22:07:09 +08002613 err = azx_first_init(chip);
2614 if (err < 0)
2615 goto out_free;
2616
Jaroslav Kysela2dca0bb2009-11-13 18:41:52 +01002617#ifdef CONFIG_SND_HDA_INPUT_BEEP
2618 chip->beep_mode = beep_mode[dev];
2619#endif
2620
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 /* create codec instances */
Dylan Reide62a42a2014-02-28 15:41:19 -08002622 err = azx_codec_create(chip, model[dev],
2623 azx_max_codecs[chip->driver_type],
2624 power_save_addr);
2625
Wu Fengguang41dda0f2008-11-20 09:24:52 +08002626 if (err < 0)
2627 goto out_free;
Takashi Iwai4ea6fbc2009-06-17 09:52:54 +02002628#ifdef CONFIG_SND_HDA_PATCH_LOADER
Takashi Iwai4918cda2012-08-09 12:33:28 +02002629 if (chip->fw) {
2630 err = snd_hda_load_patch(chip->bus, chip->fw->size,
2631 chip->fw->data);
Takashi Iwai4ea6fbc2009-06-17 09:52:54 +02002632 if (err < 0)
2633 goto out_free;
Takashi Iwaie39ae852012-11-22 16:18:13 +01002634#ifndef CONFIG_PM
Takashi Iwai4918cda2012-08-09 12:33:28 +02002635 release_firmware(chip->fw); /* no longer needed */
2636 chip->fw = NULL;
Takashi Iwaie39ae852012-11-22 16:18:13 +01002637#endif
Takashi Iwai4ea6fbc2009-06-17 09:52:54 +02002638 }
2639#endif
Jaroslav Kysela10e77dd2010-03-26 11:04:38 +01002640 if ((probe_only[dev] & 1) == 0) {
Takashi Iwaia1e21c92009-06-17 09:33:52 +02002641 err = azx_codec_configure(chip);
2642 if (err < 0)
2643 goto out_free;
2644 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645
2646 /* create PCM streams */
Takashi Iwai176d5332008-07-30 15:01:44 +02002647 err = snd_hda_build_pcms(chip->bus);
Wu Fengguang41dda0f2008-11-20 09:24:52 +08002648 if (err < 0)
2649 goto out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650
2651 /* create mixer controls */
Takashi Iwaid01ce992007-07-27 16:52:19 +02002652 err = azx_mixer_create(chip);
Wu Fengguang41dda0f2008-11-20 09:24:52 +08002653 if (err < 0)
2654 goto out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
Takashi Iwaia82d51e2012-04-26 12:23:42 +02002656 err = snd_card_register(chip->card);
Wu Fengguang41dda0f2008-11-20 09:24:52 +08002657 if (err < 0)
2658 goto out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659
Takashi Iwaicb53c622007-08-10 17:21:45 +02002660 chip->running = 1;
2661 power_down_all_codecs(chip);
Takashi Iwai0cbf0092008-10-29 16:18:25 +01002662 azx_notifier_register(chip);
Takashi Iwai65fcd412012-08-14 17:13:32 +02002663 azx_add_card_list(chip);
Dave Airlie246efa42013-07-29 15:19:29 +10002664 if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME) || chip->use_vga_switcheroo)
Wang Xingchaoc67e2222013-05-30 22:07:08 +08002665 pm_runtime_put_noidle(&pci->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666
Wu Fengguang41dda0f2008-11-20 09:24:52 +08002667out_free:
Takashi Iwai88d071f2013-12-02 11:12:28 +01002668 if (err < 0)
2669 chip->init_failed = 1;
2670 complete_all(&chip->probe_wait);
Wu Fengguang41dda0f2008-11-20 09:24:52 +08002671 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672}
2673
Bill Pembertone23e7a12012-12-06 12:35:10 -05002674static void azx_remove(struct pci_dev *pci)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675{
Takashi Iwai91219472012-04-26 12:13:25 +02002676 struct snd_card *card = pci_get_drvdata(pci);
Mengdong Linb8dfc4622012-08-23 17:32:30 +08002677
Takashi Iwai91219472012-04-26 12:13:25 +02002678 if (card)
2679 snd_card_free(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680}
2681
2682/* PCI IDs */
Alexey Dobriyancebe41d2010-02-06 00:21:03 +02002683static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
Seth Heasleyd2f2fcd2010-01-12 17:03:35 -08002684 /* CPT */
Takashi Iwai9477c582011-05-25 09:11:37 +02002685 { PCI_DEVICE(0x8086, 0x1c20),
Takashi Iwaid7dab4d2013-01-08 13:51:30 +01002686 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
Seth Heasleycea310e2010-09-10 16:29:56 -07002687 /* PBG */
Takashi Iwai9477c582011-05-25 09:11:37 +02002688 { PCI_DEVICE(0x8086, 0x1d20),
Takashi Iwaid7dab4d2013-01-08 13:51:30 +01002689 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
Seth Heasleyd2edeb72011-04-20 10:59:57 -07002690 /* Panther Point */
Takashi Iwai9477c582011-05-25 09:11:37 +02002691 { PCI_DEVICE(0x8086, 0x1e20),
Takashi Iwaib1920c22013-11-22 12:43:25 +01002692 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
Seth Heasley8bc039a2012-01-23 16:24:31 -08002693 /* Lynx Point */
2694 { PCI_DEVICE(0x8086, 0x8c20),
Takashi Iwai2ea3c6a2012-11-19 20:03:37 +01002695 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
James Ralston884b0882013-02-08 17:29:40 -08002696 /* Wellsburg */
2697 { PCI_DEVICE(0x8086, 0x8d20),
2698 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2699 { PCI_DEVICE(0x8086, 0x8d21),
2700 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
James Ralston144dad92012-08-09 09:38:59 -07002701 /* Lynx Point-LP */
2702 { PCI_DEVICE(0x8086, 0x9c20),
Takashi Iwai2ea3c6a2012-11-19 20:03:37 +01002703 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
James Ralston144dad92012-08-09 09:38:59 -07002704 /* Lynx Point-LP */
2705 { PCI_DEVICE(0x8086, 0x9c21),
Takashi Iwai2ea3c6a2012-11-19 20:03:37 +01002706 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
James Ralston4eeca492013-11-04 09:27:45 -08002707 /* Wildcat Point-LP */
2708 { PCI_DEVICE(0x8086, 0x9ca0),
2709 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
Wang Xingchaoe926f2c2012-06-13 10:23:51 +08002710 /* Haswell */
Wang Xingchao4a7c5162013-02-01 22:42:19 +08002711 { PCI_DEVICE(0x8086, 0x0a0c),
Takashi Iwaifab12852013-11-05 17:54:05 +01002712 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
Wang Xingchaoe926f2c2012-06-13 10:23:51 +08002713 { PCI_DEVICE(0x8086, 0x0c0c),
Takashi Iwaifab12852013-11-05 17:54:05 +01002714 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
Wang Xingchaod279fae2012-09-17 13:10:23 +08002715 { PCI_DEVICE(0x8086, 0x0d0c),
Takashi Iwaifab12852013-11-05 17:54:05 +01002716 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
Mengdong Lin862d7612014-01-08 15:55:14 -05002717 /* Broadwell */
2718 { PCI_DEVICE(0x8086, 0x160c),
2719 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
Pierre-Louis Bossart99df18b2012-09-21 18:39:07 -05002720 /* 5 Series/3400 */
2721 { PCI_DEVICE(0x8086, 0x3b56),
Takashi Iwai2c1350f2013-02-14 09:44:55 +01002722 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
Takashi Iwaif748abc2013-01-29 10:12:23 +01002723 /* Poulsbo */
Takashi Iwai9477c582011-05-25 09:11:37 +02002724 { PCI_DEVICE(0x8086, 0x811b),
Takashi Iwaif748abc2013-01-29 10:12:23 +01002725 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
2726 /* Oaktrail */
Li Peng09904b92011-12-28 15:17:26 +00002727 { PCI_DEVICE(0x8086, 0x080a),
Takashi Iwaif748abc2013-01-29 10:12:23 +01002728 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
Chew, Chiau Eee44007e2013-05-16 15:36:12 +08002729 /* BayTrail */
2730 { PCI_DEVICE(0x8086, 0x0f04),
2731 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM },
David Henningsson645e9032011-12-14 15:52:30 +08002732 /* ICH */
Takashi Iwai8b0bd222011-06-10 14:56:26 +02002733 { PCI_DEVICE(0x8086, 0x2668),
Pierre-Louis Bossart2ae66c22011-08-04 10:12:56 -05002734 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2735 AZX_DCAPS_BUFSIZE }, /* ICH6 */
Takashi Iwai8b0bd222011-06-10 14:56:26 +02002736 { PCI_DEVICE(0x8086, 0x27d8),
Pierre-Louis Bossart2ae66c22011-08-04 10:12:56 -05002737 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2738 AZX_DCAPS_BUFSIZE }, /* ICH7 */
Takashi Iwai8b0bd222011-06-10 14:56:26 +02002739 { PCI_DEVICE(0x8086, 0x269a),
Pierre-Louis Bossart2ae66c22011-08-04 10:12:56 -05002740 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2741 AZX_DCAPS_BUFSIZE }, /* ESB2 */
Takashi Iwai8b0bd222011-06-10 14:56:26 +02002742 { PCI_DEVICE(0x8086, 0x284b),
Pierre-Louis Bossart2ae66c22011-08-04 10:12:56 -05002743 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2744 AZX_DCAPS_BUFSIZE }, /* ICH8 */
Takashi Iwai8b0bd222011-06-10 14:56:26 +02002745 { PCI_DEVICE(0x8086, 0x293e),
Pierre-Louis Bossart2ae66c22011-08-04 10:12:56 -05002746 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2747 AZX_DCAPS_BUFSIZE }, /* ICH9 */
Takashi Iwai8b0bd222011-06-10 14:56:26 +02002748 { PCI_DEVICE(0x8086, 0x293f),
Pierre-Louis Bossart2ae66c22011-08-04 10:12:56 -05002749 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2750 AZX_DCAPS_BUFSIZE }, /* ICH9 */
Takashi Iwai8b0bd222011-06-10 14:56:26 +02002751 { PCI_DEVICE(0x8086, 0x3a3e),
Pierre-Louis Bossart2ae66c22011-08-04 10:12:56 -05002752 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2753 AZX_DCAPS_BUFSIZE }, /* ICH10 */
Takashi Iwai8b0bd222011-06-10 14:56:26 +02002754 { PCI_DEVICE(0x8086, 0x3a6e),
Pierre-Louis Bossart2ae66c22011-08-04 10:12:56 -05002755 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2756 AZX_DCAPS_BUFSIZE }, /* ICH10 */
Takashi Iwaib6864532010-09-15 10:17:26 +02002757 /* Generic Intel */
2758 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID),
2759 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2760 .class_mask = 0xffffff,
Pierre-Louis Bossart2ae66c22011-08-04 10:12:56 -05002761 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_BUFSIZE },
Takashi Iwai9477c582011-05-25 09:11:37 +02002762 /* ATI SB 450/600/700/800/900 */
2763 { PCI_DEVICE(0x1002, 0x437b),
2764 .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB },
2765 { PCI_DEVICE(0x1002, 0x4383),
2766 .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB },
2767 /* AMD Hudson */
2768 { PCI_DEVICE(0x1022, 0x780d),
2769 .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_SB },
Takashi Iwai87218e92008-02-21 08:13:11 +01002770 /* ATI HDMI */
Takashi Iwai9477c582011-05-25 09:11:37 +02002771 { PCI_DEVICE(0x1002, 0x793b),
2772 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2773 { PCI_DEVICE(0x1002, 0x7919),
2774 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2775 { PCI_DEVICE(0x1002, 0x960f),
2776 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2777 { PCI_DEVICE(0x1002, 0x970f),
2778 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2779 { PCI_DEVICE(0x1002, 0xaa00),
2780 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2781 { PCI_DEVICE(0x1002, 0xaa08),
2782 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2783 { PCI_DEVICE(0x1002, 0xaa10),
2784 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2785 { PCI_DEVICE(0x1002, 0xaa18),
2786 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2787 { PCI_DEVICE(0x1002, 0xaa20),
2788 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2789 { PCI_DEVICE(0x1002, 0xaa28),
2790 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2791 { PCI_DEVICE(0x1002, 0xaa30),
2792 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2793 { PCI_DEVICE(0x1002, 0xaa38),
2794 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2795 { PCI_DEVICE(0x1002, 0xaa40),
2796 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2797 { PCI_DEVICE(0x1002, 0xaa48),
2798 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
Clemens Ladischbbaa0d62013-11-05 09:27:10 +01002799 { PCI_DEVICE(0x1002, 0xaa50),
2800 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2801 { PCI_DEVICE(0x1002, 0xaa58),
2802 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2803 { PCI_DEVICE(0x1002, 0xaa60),
2804 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2805 { PCI_DEVICE(0x1002, 0xaa68),
2806 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2807 { PCI_DEVICE(0x1002, 0xaa80),
2808 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2809 { PCI_DEVICE(0x1002, 0xaa88),
2810 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2811 { PCI_DEVICE(0x1002, 0xaa90),
2812 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2813 { PCI_DEVICE(0x1002, 0xaa98),
2814 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
Andiry Xu1815b342011-12-14 16:10:27 +08002815 { PCI_DEVICE(0x1002, 0x9902),
2816 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI },
2817 { PCI_DEVICE(0x1002, 0xaaa0),
2818 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI },
2819 { PCI_DEVICE(0x1002, 0xaaa8),
2820 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI },
2821 { PCI_DEVICE(0x1002, 0xaab0),
2822 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI },
Takashi Iwai87218e92008-02-21 08:13:11 +01002823 /* VIA VT8251/VT8237A */
Takashi Iwai9477c582011-05-25 09:11:37 +02002824 { PCI_DEVICE(0x1106, 0x3288),
2825 .driver_data = AZX_DRIVER_VIA | AZX_DCAPS_POSFIX_VIA },
Annie Liu754fdff2012-06-08 19:18:39 +08002826 /* VIA GFX VT7122/VX900 */
2827 { PCI_DEVICE(0x1106, 0x9170), .driver_data = AZX_DRIVER_GENERIC },
2828 /* VIA GFX VT6122/VX11 */
2829 { PCI_DEVICE(0x1106, 0x9140), .driver_data = AZX_DRIVER_GENERIC },
Takashi Iwai87218e92008-02-21 08:13:11 +01002830 /* SIS966 */
2831 { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS },
2832 /* ULI M5461 */
2833 { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI },
2834 /* NVIDIA MCP */
Takashi Iwai0c2fd1bf42009-12-18 16:41:39 +01002835 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
2836 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2837 .class_mask = 0xffffff,
Takashi Iwai9477c582011-05-25 09:11:37 +02002838 .driver_data = AZX_DRIVER_NVIDIA | AZX_DCAPS_PRESET_NVIDIA },
Kailang Yangf2690022008-05-27 11:44:55 +02002839 /* Teradici */
Takashi Iwai9477c582011-05-25 09:11:37 +02002840 { PCI_DEVICE(0x6549, 0x1200),
2841 .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT },
Lars R. Damerowf0b3da92012-11-02 13:10:39 -07002842 { PCI_DEVICE(0x6549, 0x2200),
2843 .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT },
Takashi Iwai4e01f542009-04-16 08:53:34 +02002844 /* Creative X-Fi (CA0110-IBG) */
Takashi Iwaif2a8eca2012-06-11 15:51:54 +02002845 /* CTHDA chips */
2846 { PCI_DEVICE(0x1102, 0x0010),
2847 .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
2848 { PCI_DEVICE(0x1102, 0x0012),
2849 .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
Takashi Iwai8eeaa2f2014-02-10 09:48:47 +01002850#if !IS_ENABLED(CONFIG_SND_CTXFI)
Takashi Iwai313f6e22009-05-18 12:40:52 +02002851 /* the following entry conflicts with snd-ctxfi driver,
2852 * as ctxfi driver mutates from HD-audio to native mode with
2853 * a special command sequence.
2854 */
Takashi Iwai4e01f542009-04-16 08:53:34 +02002855 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_ANY_ID),
2856 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2857 .class_mask = 0xffffff,
Takashi Iwai9477c582011-05-25 09:11:37 +02002858 .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND |
Takashi Iwai69f9ba92011-11-06 13:49:13 +01002859 AZX_DCAPS_RIRB_PRE_DELAY | AZX_DCAPS_POSFIX_LPIB },
Takashi Iwai313f6e22009-05-18 12:40:52 +02002860#else
2861 /* this entry seems still valid -- i.e. without emu20kx chip */
Takashi Iwai9477c582011-05-25 09:11:37 +02002862 { PCI_DEVICE(0x1102, 0x0009),
2863 .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND |
Takashi Iwai69f9ba92011-11-06 13:49:13 +01002864 AZX_DCAPS_RIRB_PRE_DELAY | AZX_DCAPS_POSFIX_LPIB },
Takashi Iwai313f6e22009-05-18 12:40:52 +02002865#endif
Otavio Salvadore35d4b12010-09-26 23:35:06 -03002866 /* Vortex86MX */
2867 { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC },
Bankim Bhavsar0f0714c52011-01-17 15:23:21 +01002868 /* VMware HDAudio */
2869 { PCI_DEVICE(0x15ad, 0x1977), .driver_data = AZX_DRIVER_GENERIC },
Andiry Brienza9176b672009-07-17 11:32:32 +08002870 /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */
Yang, Libinc4da29c2008-11-13 11:07:07 +01002871 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID),
2872 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2873 .class_mask = 0xffffff,
Takashi Iwai9477c582011-05-25 09:11:37 +02002874 .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI },
Andiry Brienza9176b672009-07-17 11:32:32 +08002875 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID),
2876 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2877 .class_mask = 0xffffff,
Takashi Iwai9477c582011-05-25 09:11:37 +02002878 .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 { 0, }
2880};
2881MODULE_DEVICE_TABLE(pci, azx_ids);
2882
2883/* pci_driver definition */
Takashi Iwaie9f66d92012-04-24 12:25:00 +02002884static struct pci_driver azx_driver = {
Takashi Iwai3733e422011-06-10 16:20:20 +02002885 .name = KBUILD_MODNAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 .id_table = azx_ids,
2887 .probe = azx_probe,
Bill Pembertone23e7a12012-12-06 12:35:10 -05002888 .remove = azx_remove,
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002889 .driver = {
2890 .pm = AZX_PM_OPS,
2891 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892};
2893
Takashi Iwaie9f66d92012-04-24 12:25:00 +02002894module_pci_driver(azx_driver);