aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-05-23 16:05:43 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-05-23 16:05:43 -0400
commit2e341ca686042aa464efa755447e7bcee91d1eb6 (patch)
treec6b16b6b6a6e871fa04396cb2c7eb759bcad5be3 /sound/pci/hda
parent927ad551031798d4cba49766549600bbb33872d7 (diff)
parent85e184e4c3cd3e2285ceab91ff8f0cac094e8a85 (diff)
Merge tag 'sound-3.5' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
Pull sound updates from Takashi Iwai: "This is the first big chunk for 3.5 merges of sound stuff. There are a few big changes in different areas. First off, the streaming logic of USB-audio endpoints has been largely rewritten for the better support of "implicit feedback". If anything about USB got broken, this change has to be checked. For HD-audio, the resume procedure was changed; instead of delaying the resume of the hardware until the first use, now waking up immediately at resume. This is for buggy BIOS. For ASoC, dynamic PCM support and the improved support for digital links between off-SoC devices are major framework changes. Some highlights are below: * HD-audio - Avoid accesses of invalid pin-control bits that may stall the codec - V-ref setup cleanups - Fix the races in power-saving code - Fix the races in codec cache hashes and connection lists - Split some common codes for BIOS auto-parser to hda_auto_parser.c - Changed the PM resume code to wake up immediately for buggy BIOS - Creative SoundCore3D support - Add Conexant CX20751/2/3/4 codec support * ASoC - Dynamic PCM support, allowing support for SoCs with internal routing through components with tight sequencing and formatting constraints within their internal paths or where there are multiple components connected with CPU managed DMA controllers inside the SoC. - Greatly improved support for direct digital links between off-SoC devices, providing a much simpler way of connecting things like digital basebands to CODECs. - Much more fine grained and robust locking, cleaning up some of the confusion that crept in with multi-component. - CPU support for nVidia Tegra 30 I2S and audio hub controllers and ST-Ericsson MSP I2S controolers - New CODEC drivers for Cirrus CS42L52, LAPIS Semiconductor ML26124, Texas Instruments LM49453. - Some regmap changes needed by the Tegra I2S driver. - mc13783 audio support. * Misc - Rewrite with module_pci_driver() - Xonar DGX support for snd-oxygen - Improvement of packet handling in snd-firewire driver - New USB-endpoint streaming logic - Enhanced M-audio FTU quirks and relevant cleanups - Increment the support of OSS devices to 256 - snd-aloop accuracy improvement There are a few more pending changes for 3.5, but they will be sent slightly later as partly depending on the changes of DRM." Fix up conflicts in regmap (due to duplicate patches, with some further updates then having already come in from the regmap tree). Also some fairly trivial context conflicts in the imx and mcx soc drivers. * tag 'sound-3.5' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound: (280 commits) ALSA: snd-usb: fix stream info output in /proc ALSA: pcm - Add proper state checks to snd_pcm_drain() ALSA: sh: Fix up namespace collision in sh_dac_audio. ALSA: hda/realtek - Fix unused variable compile warning ASoC: sh: fsi: enable chip specific data transfer mode ASoC: sh: fsi: call fsi_hw_startup/shutdown from fsi_dai_trigger() ASoC: sh: fsi: use same format for IN/OUT ASoC: sh: fsi: add fsi_version() and removed meaningless version check ASoC: sh: fsi: use register field macro name on IN/OUT_DMAC ASoC: tegra: Add machine driver for WM8753 codec ALSA: hda - Fix possible races of accesses to connection list array ASoC: OMAP: HDMI: Introduce codec ARM: mx31_3ds: Add sound support ASoC: imx-mc13783 cleanup mx31moboard: Add sound support ASoC: mc13783 codec cleanups ASoC: add imx-mc13783 sound support ASoC: Add mc13783 codec mfd: mc13xxx: add codec platform data ASoC: don't flip master of DT-instantiated DAI links ...
Diffstat (limited to 'sound/pci/hda')
-rw-r--r--sound/pci/hda/Makefile2
-rw-r--r--sound/pci/hda/hda_auto_parser.c760
-rw-r--r--sound/pci/hda/hda_auto_parser.h160
-rw-r--r--sound/pci/hda/hda_codec.c1027
-rw-r--r--sound/pci/hda/hda_codec.h15
-rw-r--r--sound/pci/hda/hda_intel.c57
-rw-r--r--sound/pci/hda/hda_jack.c1
-rw-r--r--sound/pci/hda/hda_jack.h2
-rw-r--r--sound/pci/hda/hda_local.h122
-rw-r--r--sound/pci/hda/patch_analog.c14
-rw-r--r--sound/pci/hda/patch_ca0110.c8
-rw-r--r--sound/pci/hda/patch_ca0132.c9
-rw-r--r--sound/pci/hda/patch_cirrus.c30
-rw-r--r--sound/pci/hda/patch_cmedia.c1
-rw-r--r--sound/pci/hda/patch_conexant.c186
-rw-r--r--sound/pci/hda/patch_hdmi.c4
-rw-r--r--sound/pci/hda/patch_realtek.c465
-rw-r--r--sound/pci/hda/patch_sigmatel.c120
-rw-r--r--sound/pci/hda/patch_via.c33
19 files changed, 1616 insertions, 1400 deletions
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index ace157cc3d15..bd4149f1aaf4 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -1,6 +1,6 @@
1snd-hda-intel-objs := hda_intel.o 1snd-hda-intel-objs := hda_intel.o
2 2
3snd-hda-codec-y := hda_codec.o hda_jack.o 3snd-hda-codec-y := hda_codec.o hda_jack.o hda_auto_parser.o
4snd-hda-codec-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o 4snd-hda-codec-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o
5snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o 5snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o
6snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o 6snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
diff --git a/sound/pci/hda/hda_auto_parser.c b/sound/pci/hda/hda_auto_parser.c
new file mode 100644
index 000000000000..6e9ef3e25093
--- /dev/null
+++ b/sound/pci/hda/hda_auto_parser.c
@@ -0,0 +1,760 @@
1/*
2 * BIOS auto-parser helper functions for HD-audio
3 *
4 * Copyright (c) 2012 Takashi Iwai <tiwai@suse.de>
5 *
6 * This driver is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/slab.h>
13#include <linux/export.h>
14#include <sound/core.h>
15#include "hda_codec.h"
16#include "hda_local.h"
17#include "hda_auto_parser.h"
18
19#define SFX "hda_codec: "
20
21/*
22 * Helper for automatic pin configuration
23 */
24
25static int is_in_nid_list(hda_nid_t nid, const hda_nid_t *list)
26{
27 for (; *list; list++)
28 if (*list == nid)
29 return 1;
30 return 0;
31}
32
33
34/*
35 * Sort an associated group of pins according to their sequence numbers.
36 */
37static void sort_pins_by_sequence(hda_nid_t *pins, short *sequences,
38 int num_pins)
39{
40 int i, j;
41 short seq;
42 hda_nid_t nid;
43
44 for (i = 0; i < num_pins; i++) {
45 for (j = i + 1; j < num_pins; j++) {
46 if (sequences[i] > sequences[j]) {
47 seq = sequences[i];
48 sequences[i] = sequences[j];
49 sequences[j] = seq;
50 nid = pins[i];
51 pins[i] = pins[j];
52 pins[j] = nid;
53 }
54 }
55 }
56}
57
58
59/* add the found input-pin to the cfg->inputs[] table */
60static void add_auto_cfg_input_pin(struct auto_pin_cfg *cfg, hda_nid_t nid,
61 int type)
62{
63 if (cfg->num_inputs < AUTO_CFG_MAX_INS) {
64 cfg->inputs[cfg->num_inputs].pin = nid;
65 cfg->inputs[cfg->num_inputs].type = type;
66 cfg->num_inputs++;
67 }
68}
69
70/* sort inputs in the order of AUTO_PIN_* type */
71static void sort_autocfg_input_pins(struct auto_pin_cfg *cfg)
72{
73 int i, j;
74
75 for (i = 0; i < cfg->num_inputs; i++) {
76 for (j = i + 1; j < cfg->num_inputs; j++) {
77 if (cfg->inputs[i].type > cfg->inputs[j].type) {
78 struct auto_pin_cfg_item tmp;
79 tmp = cfg->inputs[i];
80 cfg->inputs[i] = cfg->inputs[j];
81 cfg->inputs[j] = tmp;
82 }
83 }
84 }
85}
86
87/* Reorder the surround channels
88 * ALSA sequence is front/surr/clfe/side
89 * HDA sequence is:
90 * 4-ch: front/surr => OK as it is
91 * 6-ch: front/clfe/surr
92 * 8-ch: front/clfe/rear/side|fc
93 */
94static void reorder_outputs(unsigned int nums, hda_nid_t *pins)
95{
96 hda_nid_t nid;
97
98 switch (nums) {
99 case 3:
100 case 4:
101 nid = pins[1];
102 pins[1] = pins[2];
103 pins[2] = nid;
104 break;
105 }
106}
107
108/*
109 * Parse all pin widgets and store the useful pin nids to cfg
110 *
111 * The number of line-outs or any primary output is stored in line_outs,
112 * and the corresponding output pins are assigned to line_out_pins[],
113 * in the order of front, rear, CLFE, side, ...
114 *
115 * If more extra outputs (speaker and headphone) are found, the pins are
116 * assisnged to hp_pins[] and speaker_pins[], respectively. If no line-out jack
117 * is detected, one of speaker of HP pins is assigned as the primary
118 * output, i.e. to line_out_pins[0]. So, line_outs is always positive
119 * if any analog output exists.
120 *
121 * The analog input pins are assigned to inputs array.
122 * The digital input/output pins are assigned to dig_in_pin and dig_out_pin,
123 * respectively.
124 */
125int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
126 struct auto_pin_cfg *cfg,
127 const hda_nid_t *ignore_nids,
128 unsigned int cond_flags)
129{
130 hda_nid_t nid, end_nid;
131 short seq, assoc_line_out;
132 short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)];
133 short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)];
134 short sequences_hp[ARRAY_SIZE(cfg->hp_pins)];
135 int i;
136
137 memset(cfg, 0, sizeof(*cfg));
138
139 memset(sequences_line_out, 0, sizeof(sequences_line_out));
140 memset(sequences_speaker, 0, sizeof(sequences_speaker));
141 memset(sequences_hp, 0, sizeof(sequences_hp));
142 assoc_line_out = 0;
143
144 codec->ignore_misc_bit = true;
145 end_nid = codec->start_nid + codec->num_nodes;
146 for (nid = codec->start_nid; nid < end_nid; nid++) {
147 unsigned int wid_caps = get_wcaps(codec, nid);
148 unsigned int wid_type = get_wcaps_type(wid_caps);
149 unsigned int def_conf;
150 short assoc, loc, conn, dev;
151
152 /* read all default configuration for pin complex */
153 if (wid_type != AC_WID_PIN)
154 continue;
155 /* ignore the given nids (e.g. pc-beep returns error) */
156 if (ignore_nids && is_in_nid_list(nid, ignore_nids))
157 continue;
158
159 def_conf = snd_hda_codec_get_pincfg(codec, nid);
160 if (!(get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) &
161 AC_DEFCFG_MISC_NO_PRESENCE))
162 codec->ignore_misc_bit = false;
163 conn = get_defcfg_connect(def_conf);
164 if (conn == AC_JACK_PORT_NONE)
165 continue;
166 loc = get_defcfg_location(def_conf);
167 dev = get_defcfg_device(def_conf);
168
169 /* workaround for buggy BIOS setups */
170 if (dev == AC_JACK_LINE_OUT) {
171 if (conn == AC_JACK_PORT_FIXED)
172 dev = AC_JACK_SPEAKER;
173 }
174
175 switch (dev) {
176 case AC_JACK_LINE_OUT:
177 seq = get_defcfg_sequence(def_conf);
178 assoc = get_defcfg_association(def_conf);
179
180 if (!(wid_caps & AC_WCAP_STEREO))
181 if (!cfg->mono_out_pin)
182 cfg->mono_out_pin = nid;
183 if (!assoc)
184 continue;
185 if (!assoc_line_out)
186 assoc_line_out = assoc;
187 else if (assoc_line_out != assoc)
188 continue;
189 if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins))
190 continue;
191 cfg->line_out_pins[cfg->line_outs] = nid;
192 sequences_line_out[cfg->line_outs] = seq;
193 cfg->line_outs++;
194 break;
195 case AC_JACK_SPEAKER:
196 seq = get_defcfg_sequence(def_conf);
197 assoc = get_defcfg_association(def_conf);
198 if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins))
199 continue;
200 cfg->speaker_pins[cfg->speaker_outs] = nid;
201 sequences_speaker[cfg->speaker_outs] = (assoc << 4) | seq;
202 cfg->speaker_outs++;
203 break;
204 case AC_JACK_HP_OUT:
205 seq = get_defcfg_sequence(def_conf);
206 assoc = get_defcfg_association(def_conf);
207 if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins))
208 continue;
209 cfg->hp_pins[cfg->hp_outs] = nid;
210 sequences_hp[cfg->hp_outs] = (assoc << 4) | seq;
211 cfg->hp_outs++;
212 break;
213 case AC_JACK_MIC_IN:
214 add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_MIC);
215 break;
216 case AC_JACK_LINE_IN:
217 add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_LINE_IN);
218 break;
219 case AC_JACK_CD:
220 add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_CD);
221 break;
222 case AC_JACK_AUX:
223 add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_AUX);
224 break;
225 case AC_JACK_SPDIF_OUT:
226 case AC_JACK_DIG_OTHER_OUT:
227 if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins))
228 continue;
229 cfg->dig_out_pins[cfg->dig_outs] = nid;
230 cfg->dig_out_type[cfg->dig_outs] =
231 (loc == AC_JACK_LOC_HDMI) ?
232 HDA_PCM_TYPE_HDMI : HDA_PCM_TYPE_SPDIF;
233 cfg->dig_outs++;
234 break;
235 case AC_JACK_SPDIF_IN:
236 case AC_JACK_DIG_OTHER_IN:
237 cfg->dig_in_pin = nid;
238 if (loc == AC_JACK_LOC_HDMI)
239 cfg->dig_in_type = HDA_PCM_TYPE_HDMI;
240 else
241 cfg->dig_in_type = HDA_PCM_TYPE_SPDIF;
242 break;
243 }
244 }
245
246 /* FIX-UP:
247 * If no line-out is defined but multiple HPs are found,
248 * some of them might be the real line-outs.
249 */
250 if (!cfg->line_outs && cfg->hp_outs > 1 &&
251 !(cond_flags & HDA_PINCFG_NO_HP_FIXUP)) {
252 int i = 0;
253 while (i < cfg->hp_outs) {
254 /* The real HPs should have the sequence 0x0f */
255 if ((sequences_hp[i] & 0x0f) == 0x0f) {
256 i++;
257 continue;
258 }
259 /* Move it to the line-out table */
260 cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i];
261 sequences_line_out[cfg->line_outs] = sequences_hp[i];
262 cfg->line_outs++;
263 cfg->hp_outs--;
264 memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1,
265 sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i));
266 memmove(sequences_hp + i, sequences_hp + i + 1,
267 sizeof(sequences_hp[0]) * (cfg->hp_outs - i));
268 }
269 memset(cfg->hp_pins + cfg->hp_outs, 0,
270 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - cfg->hp_outs));
271 if (!cfg->hp_outs)
272 cfg->line_out_type = AUTO_PIN_HP_OUT;
273
274 }
275
276 /* sort by sequence */
277 sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out,
278 cfg->line_outs);
279 sort_pins_by_sequence(cfg->speaker_pins, sequences_speaker,
280 cfg->speaker_outs);
281 sort_pins_by_sequence(cfg->hp_pins, sequences_hp,
282 cfg->hp_outs);
283
284 /*
285 * FIX-UP: if no line-outs are detected, try to use speaker or HP pin
286 * as a primary output
287 */
288 if (!cfg->line_outs &&
289 !(cond_flags & HDA_PINCFG_NO_LO_FIXUP)) {
290 if (cfg->speaker_outs) {
291 cfg->line_outs = cfg->speaker_outs;
292 memcpy(cfg->line_out_pins, cfg->speaker_pins,
293 sizeof(cfg->speaker_pins));
294 cfg->speaker_outs = 0;
295 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
296 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
297 } else if (cfg->hp_outs) {
298 cfg->line_outs = cfg->hp_outs;
299 memcpy(cfg->line_out_pins, cfg->hp_pins,
300 sizeof(cfg->hp_pins));
301 cfg->hp_outs = 0;
302 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
303 cfg->line_out_type = AUTO_PIN_HP_OUT;
304 }
305 }
306
307 reorder_outputs(cfg->line_outs, cfg->line_out_pins);
308 reorder_outputs(cfg->hp_outs, cfg->hp_pins);
309 reorder_outputs(cfg->speaker_outs, cfg->speaker_pins);
310
311 sort_autocfg_input_pins(cfg);
312
313 /*
314 * debug prints of the parsed results
315 */
316 snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n",
317 cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1],
318 cfg->line_out_pins[2], cfg->line_out_pins[3],
319 cfg->line_out_pins[4],
320 cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" :
321 (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ?
322 "speaker" : "line"));
323 snd_printd(" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
324 cfg->speaker_outs, cfg->speaker_pins[0],
325 cfg->speaker_pins[1], cfg->speaker_pins[2],
326 cfg->speaker_pins[3], cfg->speaker_pins[4]);
327 snd_printd(" hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
328 cfg->hp_outs, cfg->hp_pins[0],
329 cfg->hp_pins[1], cfg->hp_pins[2],
330 cfg->hp_pins[3], cfg->hp_pins[4]);
331 snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin);
332 if (cfg->dig_outs)
333 snd_printd(" dig-out=0x%x/0x%x\n",
334 cfg->dig_out_pins[0], cfg->dig_out_pins[1]);
335 snd_printd(" inputs:");
336 for (i = 0; i < cfg->num_inputs; i++) {
337 snd_printd(" %s=0x%x",
338 hda_get_autocfg_input_label(codec, cfg, i),
339 cfg->inputs[i].pin);
340 }
341 snd_printd("\n");
342 if (cfg->dig_in_pin)
343 snd_printd(" dig-in=0x%x\n", cfg->dig_in_pin);
344
345 return 0;
346}
347EXPORT_SYMBOL_HDA(snd_hda_parse_pin_defcfg);
348
349int snd_hda_get_input_pin_attr(unsigned int def_conf)
350{
351 unsigned int loc = get_defcfg_location(def_conf);
352 unsigned int conn = get_defcfg_connect(def_conf);
353 if (conn == AC_JACK_PORT_NONE)
354 return INPUT_PIN_ATTR_UNUSED;
355 /* Windows may claim the internal mic to be BOTH, too */
356 if (conn == AC_JACK_PORT_FIXED || conn == AC_JACK_PORT_BOTH)
357 return INPUT_PIN_ATTR_INT;
358 if ((loc & 0x30) == AC_JACK_LOC_INTERNAL)
359 return INPUT_PIN_ATTR_INT;
360 if ((loc & 0x30) == AC_JACK_LOC_SEPARATE)
361 return INPUT_PIN_ATTR_DOCK;
362 if (loc == AC_JACK_LOC_REAR)
363 return INPUT_PIN_ATTR_REAR;
364 if (loc == AC_JACK_LOC_FRONT)
365 return INPUT_PIN_ATTR_FRONT;
366 return INPUT_PIN_ATTR_NORMAL;
367}
368EXPORT_SYMBOL_HDA(snd_hda_get_input_pin_attr);
369
370/**
371 * hda_get_input_pin_label - Give a label for the given input pin
372 *
373 * When check_location is true, the function checks the pin location
374 * for mic and line-in pins, and set an appropriate prefix like "Front",
375 * "Rear", "Internal".
376 */
377
378static const char *hda_get_input_pin_label(struct hda_codec *codec,
379 hda_nid_t pin, bool check_location)
380{
381 unsigned int def_conf;
382 static const char * const mic_names[] = {
383 "Internal Mic", "Dock Mic", "Mic", "Front Mic", "Rear Mic",
384 };
385 int attr;
386
387 def_conf = snd_hda_codec_get_pincfg(codec, pin);
388
389 switch (get_defcfg_device(def_conf)) {
390 case AC_JACK_MIC_IN:
391 if (!check_location)
392 return "Mic";
393 attr = snd_hda_get_input_pin_attr(def_conf);
394 if (!attr)
395 return "None";
396 return mic_names[attr - 1];
397 case AC_JACK_LINE_IN:
398 if (!check_location)
399 return "Line";
400 attr = snd_hda_get_input_pin_attr(def_conf);
401 if (!attr)
402 return "None";
403 if (attr == INPUT_PIN_ATTR_DOCK)
404 return "Dock Line";
405 return "Line";
406 case AC_JACK_AUX:
407 return "Aux";
408 case AC_JACK_CD:
409 return "CD";
410 case AC_JACK_SPDIF_IN:
411 return "SPDIF In";
412 case AC_JACK_DIG_OTHER_IN:
413 return "Digital In";
414 default:
415 return "Misc";
416 }
417}
418
419/* Check whether the location prefix needs to be added to the label.
420 * If all mic-jacks are in the same location (e.g. rear panel), we don't
421 * have to put "Front" prefix to each label. In such a case, returns false.
422 */
423static int check_mic_location_need(struct hda_codec *codec,
424 const struct auto_pin_cfg *cfg,
425 int input)
426{
427 unsigned int defc;
428 int i, attr, attr2;
429
430 defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[input].pin);
431 attr = snd_hda_get_input_pin_attr(defc);
432 /* for internal or docking mics, we need locations */
433 if (attr <= INPUT_PIN_ATTR_NORMAL)
434 return 1;
435
436 attr = 0;
437 for (i = 0; i < cfg->num_inputs; i++) {
438 defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[i].pin);
439 attr2 = snd_hda_get_input_pin_attr(defc);
440 if (attr2 >= INPUT_PIN_ATTR_NORMAL) {
441 if (attr && attr != attr2)
442 return 1; /* different locations found */
443 attr = attr2;
444 }
445 }
446 return 0;
447}
448
449/**
450 * hda_get_autocfg_input_label - Get a label for the given input
451 *
452 * Get a label for the given input pin defined by the autocfg item.
453 * Unlike hda_get_input_pin_label(), this function checks all inputs
454 * defined in autocfg and avoids the redundant mic/line prefix as much as
455 * possible.
456 */
457const char *hda_get_autocfg_input_label(struct hda_codec *codec,
458 const struct auto_pin_cfg *cfg,
459 int input)
460{
461 int type = cfg->inputs[input].type;
462 int has_multiple_pins = 0;
463
464 if ((input > 0 && cfg->inputs[input - 1].type == type) ||
465 (input < cfg->num_inputs - 1 && cfg->inputs[input + 1].type == type))
466 has_multiple_pins = 1;
467 if (has_multiple_pins && type == AUTO_PIN_MIC)
468 has_multiple_pins &= check_mic_location_need(codec, cfg, input);
469 return hda_get_input_pin_label(codec, cfg->inputs[input].pin,
470 has_multiple_pins);
471}
472EXPORT_SYMBOL_HDA(hda_get_autocfg_input_label);
473
474/* return the position of NID in the list, or -1 if not found */
475static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
476{
477 int i;
478 for (i = 0; i < nums; i++)
479 if (list[i] == nid)
480 return i;
481 return -1;
482}
483
484/* get a unique suffix or an index number */
485static const char *check_output_sfx(hda_nid_t nid, const hda_nid_t *pins,
486 int num_pins, int *indexp)
487{
488 static const char * const channel_sfx[] = {
489 " Front", " Surround", " CLFE", " Side"
490 };
491 int i;
492
493 i = find_idx_in_nid_list(nid, pins, num_pins);
494 if (i < 0)
495 return NULL;
496 if (num_pins == 1)
497 return "";
498 if (num_pins > ARRAY_SIZE(channel_sfx)) {
499 if (indexp)
500 *indexp = i;
501 return "";
502 }
503 return channel_sfx[i];
504}
505
506static int fill_audio_out_name(struct hda_codec *codec, hda_nid_t nid,
507 const struct auto_pin_cfg *cfg,
508 const char *name, char *label, int maxlen,
509 int *indexp)
510{
511 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
512 int attr = snd_hda_get_input_pin_attr(def_conf);
513 const char *pfx = "", *sfx = "";
514
515 /* handle as a speaker if it's a fixed line-out */
516 if (!strcmp(name, "Line Out") && attr == INPUT_PIN_ATTR_INT)
517 name = "Speaker";
518 /* check the location */
519 switch (attr) {
520 case INPUT_PIN_ATTR_DOCK:
521 pfx = "Dock ";
522 break;
523 case INPUT_PIN_ATTR_FRONT:
524 pfx = "Front ";
525 break;
526 }
527 if (cfg) {
528 /* try to give a unique suffix if needed */
529 sfx = check_output_sfx(nid, cfg->line_out_pins, cfg->line_outs,
530 indexp);
531 if (!sfx)
532 sfx = check_output_sfx(nid, cfg->speaker_pins, cfg->speaker_outs,
533 indexp);
534 if (!sfx) {
535 /* don't add channel suffix for Headphone controls */
536 int idx = find_idx_in_nid_list(nid, cfg->hp_pins,
537 cfg->hp_outs);
538 if (idx >= 0)
539 *indexp = idx;
540 sfx = "";
541 }
542 }
543 snprintf(label, maxlen, "%s%s%s", pfx, name, sfx);
544 return 1;
545}
546
547/**
548 * snd_hda_get_pin_label - Get a label for the given I/O pin
549 *
550 * Get a label for the given pin. This function works for both input and
551 * output pins. When @cfg is given as non-NULL, the function tries to get
552 * an optimized label using hda_get_autocfg_input_label().
553 *
554 * This function tries to give a unique label string for the pin as much as
555 * possible. For example, when the multiple line-outs are present, it adds
556 * the channel suffix like "Front", "Surround", etc (only when @cfg is given).
557 * If no unique name with a suffix is available and @indexp is non-NULL, the
558 * index number is stored in the pointer.
559 */
560int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
561 const struct auto_pin_cfg *cfg,
562 char *label, int maxlen, int *indexp)
563{
564 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
565 const char *name = NULL;
566 int i;
567
568 if (indexp)
569 *indexp = 0;
570 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
571 return 0;
572
573 switch (get_defcfg_device(def_conf)) {
574 case AC_JACK_LINE_OUT:
575 return fill_audio_out_name(codec, nid, cfg, "Line Out",
576 label, maxlen, indexp);
577 case AC_JACK_SPEAKER:
578 return fill_audio_out_name(codec, nid, cfg, "Speaker",
579 label, maxlen, indexp);
580 case AC_JACK_HP_OUT:
581 return fill_audio_out_name(codec, nid, cfg, "Headphone",
582 label, maxlen, indexp);
583 case AC_JACK_SPDIF_OUT:
584 case AC_JACK_DIG_OTHER_OUT:
585 if (get_defcfg_location(def_conf) == AC_JACK_LOC_HDMI)
586 name = "HDMI";
587 else
588 name = "SPDIF";
589 if (cfg && indexp) {
590 i = find_idx_in_nid_list(nid, cfg->dig_out_pins,
591 cfg->dig_outs);
592 if (i >= 0)
593 *indexp = i;
594 }
595 break;
596 default:
597 if (cfg) {
598 for (i = 0; i < cfg->num_inputs; i++) {
599 if (cfg->inputs[i].pin != nid)
600 continue;
601 name = hda_get_autocfg_input_label(codec, cfg, i);
602 if (name)
603 break;
604 }
605 }
606 if (!name)
607 name = hda_get_input_pin_label(codec, nid, true);
608 break;
609 }
610 if (!name)
611 return 0;
612 strlcpy(label, name, maxlen);
613 return 1;
614}
615EXPORT_SYMBOL_HDA(snd_hda_get_pin_label);
616
617int snd_hda_gen_add_verbs(struct hda_gen_spec *spec,
618 const struct hda_verb *list)
619{
620 const struct hda_verb **v;
621 snd_array_init(&spec->verbs, sizeof(struct hda_verb *), 8);
622 v = snd_array_new(&spec->verbs);
623 if (!v)
624 return -ENOMEM;
625 *v = list;
626 return 0;
627}
628EXPORT_SYMBOL_HDA(snd_hda_gen_add_verbs);
629
630void snd_hda_gen_apply_verbs(struct hda_codec *codec)
631{
632 struct hda_gen_spec *spec = codec->spec;
633 int i;
634 for (i = 0; i < spec->verbs.used; i++) {
635 struct hda_verb **v = snd_array_elem(&spec->verbs, i);
636 snd_hda_sequence_write(codec, *v);
637 }
638}
639EXPORT_SYMBOL_HDA(snd_hda_gen_apply_verbs);
640
641void snd_hda_apply_pincfgs(struct hda_codec *codec,
642 const struct hda_pintbl *cfg)
643{
644 for (; cfg->nid; cfg++)
645 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
646}
647EXPORT_SYMBOL_HDA(snd_hda_apply_pincfgs);
648
649void snd_hda_apply_fixup(struct hda_codec *codec, int action)
650{
651 struct hda_gen_spec *spec = codec->spec;
652 int id = spec->fixup_id;
653#ifdef CONFIG_SND_DEBUG_VERBOSE
654 const char *modelname = spec->fixup_name;
655#endif
656 int depth = 0;
657
658 if (!spec->fixup_list)
659 return;
660
661 while (id >= 0) {
662 const struct hda_fixup *fix = spec->fixup_list + id;
663
664 switch (fix->type) {
665 case HDA_FIXUP_PINS:
666 if (action != HDA_FIXUP_ACT_PRE_PROBE || !fix->v.pins)
667 break;
668 snd_printdd(KERN_INFO SFX
669 "%s: Apply pincfg for %s\n",
670 codec->chip_name, modelname);
671 snd_hda_apply_pincfgs(codec, fix->v.pins);
672 break;
673 case HDA_FIXUP_VERBS:
674 if (action != HDA_FIXUP_ACT_PROBE || !fix->v.verbs)
675 break;
676 snd_printdd(KERN_INFO SFX
677 "%s: Apply fix-verbs for %s\n",
678 codec->chip_name, modelname);
679 snd_hda_gen_add_verbs(codec->spec, fix->v.verbs);
680 break;
681 case HDA_FIXUP_FUNC:
682 if (!fix->v.func)
683 break;
684 snd_printdd(KERN_INFO SFX
685 "%s: Apply fix-func for %s\n",
686 codec->chip_name, modelname);
687 fix->v.func(codec, fix, action);
688 break;
689 default:
690 snd_printk(KERN_ERR SFX
691 "%s: Invalid fixup type %d\n",
692 codec->chip_name, fix->type);
693 break;
694 }
695 if (!fix->chained)
696 break;
697 if (++depth > 10)
698 break;
699 id = fix->chain_id;
700 }
701}
702EXPORT_SYMBOL_HDA(snd_hda_apply_fixup);
703
704void snd_hda_pick_fixup(struct hda_codec *codec,
705 const struct hda_model_fixup *models,
706 const struct snd_pci_quirk *quirk,
707 const struct hda_fixup *fixlist)
708{
709 struct hda_gen_spec *spec = codec->spec;
710 const struct snd_pci_quirk *q;
711 int id = -1;
712 const char *name = NULL;
713
714 /* when model=nofixup is given, don't pick up any fixups */
715 if (codec->modelname && !strcmp(codec->modelname, "nofixup")) {
716 spec->fixup_list = NULL;
717 spec->fixup_id = -1;
718 return;
719 }
720
721 if (codec->modelname && models) {
722 while (models->name) {
723 if (!strcmp(codec->modelname, models->name)) {
724 id = models->id;
725 name = models->name;
726 break;
727 }
728 models++;
729 }
730 }
731 if (id < 0) {
732 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
733 if (q) {
734 id = q->value;
735#ifdef CONFIG_SND_DEBUG_VERBOSE
736 name = q->name;
737#endif
738 }
739 }
740 if (id < 0) {
741 for (q = quirk; q->subvendor; q++) {
742 unsigned int vendorid =
743 q->subdevice | (q->subvendor << 16);
744 if (vendorid == codec->subsystem_id) {
745 id = q->value;
746#ifdef CONFIG_SND_DEBUG_VERBOSE
747 name = q->name;
748#endif
749 break;
750 }
751 }
752 }
753
754 spec->fixup_id = id;
755 if (id >= 0) {
756 spec->fixup_list = fixlist;
757 spec->fixup_name = name;
758 }
759}
760EXPORT_SYMBOL_HDA(snd_hda_pick_fixup);
diff --git a/sound/pci/hda/hda_auto_parser.h b/sound/pci/hda/hda_auto_parser.h
new file mode 100644
index 000000000000..2a7889dfbd1b
--- /dev/null
+++ b/sound/pci/hda/hda_auto_parser.h
@@ -0,0 +1,160 @@
1/*
2 * BIOS auto-parser helper functions for HD-audio
3 *
4 * Copyright (c) 2012 Takashi Iwai <tiwai@suse.de>
5 *
6 * This driver is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#ifndef __SOUND_HDA_AUTO_PARSER_H
13#define __SOUND_HDA_AUTO_PARSER_H
14
15/*
16 * Helper for automatic pin configuration
17 */
18
19enum {
20 AUTO_PIN_MIC,
21 AUTO_PIN_LINE_IN,
22 AUTO_PIN_CD,
23 AUTO_PIN_AUX,
24 AUTO_PIN_LAST
25};
26
27enum {
28 AUTO_PIN_LINE_OUT,
29 AUTO_PIN_SPEAKER_OUT,
30 AUTO_PIN_HP_OUT
31};
32
33#define AUTO_CFG_MAX_OUTS HDA_MAX_OUTS
34#define AUTO_CFG_MAX_INS 8
35
36struct auto_pin_cfg_item {
37 hda_nid_t pin;
38 int type;
39};
40
41struct auto_pin_cfg;
42const char *hda_get_autocfg_input_label(struct hda_codec *codec,
43 const struct auto_pin_cfg *cfg,
44 int input);
45int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
46 const struct auto_pin_cfg *cfg,
47 char *label, int maxlen, int *indexp);
48
49enum {
50 INPUT_PIN_ATTR_UNUSED, /* pin not connected */
51 INPUT_PIN_ATTR_INT, /* internal mic/line-in */
52 INPUT_PIN_ATTR_DOCK, /* docking mic/line-in */
53 INPUT_PIN_ATTR_NORMAL, /* mic/line-in jack */
54 INPUT_PIN_ATTR_FRONT, /* mic/line-in jack in front */
55 INPUT_PIN_ATTR_REAR, /* mic/line-in jack in rear */
56};
57
58int snd_hda_get_input_pin_attr(unsigned int def_conf);
59
60struct auto_pin_cfg {
61 int line_outs;
62 /* sorted in the order of Front/Surr/CLFE/Side */
63 hda_nid_t line_out_pins[AUTO_CFG_MAX_OUTS];
64 int speaker_outs;
65 hda_nid_t speaker_pins[AUTO_CFG_MAX_OUTS];
66 int hp_outs;
67 int line_out_type; /* AUTO_PIN_XXX_OUT */
68 hda_nid_t hp_pins[AUTO_CFG_MAX_OUTS];
69 int num_inputs;
70 struct auto_pin_cfg_item inputs[AUTO_CFG_MAX_INS];
71 int dig_outs;
72 hda_nid_t dig_out_pins[2];
73 hda_nid_t dig_in_pin;
74 hda_nid_t mono_out_pin;
75 int dig_out_type[2]; /* HDA_PCM_TYPE_XXX */
76 int dig_in_type; /* HDA_PCM_TYPE_XXX */
77};
78
79/* bit-flags for snd_hda_parse_pin_def_config() behavior */
80#define HDA_PINCFG_NO_HP_FIXUP (1 << 0) /* no HP-split */
81#define HDA_PINCFG_NO_LO_FIXUP (1 << 1) /* don't take other outs as LO */
82
83int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
84 struct auto_pin_cfg *cfg,
85 const hda_nid_t *ignore_nids,
86 unsigned int cond_flags);
87
88/* older function */
89#define snd_hda_parse_pin_def_config(codec, cfg, ignore) \
90 snd_hda_parse_pin_defcfg(codec, cfg, ignore, 0)
91
92/*
93 */
94
95struct hda_gen_spec {
96 /* fix-up list */
97 int fixup_id;
98 const struct hda_fixup *fixup_list;
99 const char *fixup_name;
100
101 /* additional init verbs */
102 struct snd_array verbs;
103};
104
105
106/*
107 * Fix-up pin default configurations and add default verbs
108 */
109
110struct hda_pintbl {
111 hda_nid_t nid;
112 u32 val;
113};
114
115struct hda_model_fixup {
116 const int id;
117 const char *name;
118};
119
120struct hda_fixup {
121 int type;
122 bool chained;
123 int chain_id;
124 union {
125 const struct hda_pintbl *pins;
126 const struct hda_verb *verbs;
127 void (*func)(struct hda_codec *codec,
128 const struct hda_fixup *fix,
129 int action);
130 } v;
131};
132
133/* fixup types */
134enum {
135 HDA_FIXUP_INVALID,
136 HDA_FIXUP_PINS,
137 HDA_FIXUP_VERBS,
138 HDA_FIXUP_FUNC,
139};
140
141/* fixup action definitions */
142enum {
143 HDA_FIXUP_ACT_PRE_PROBE,
144 HDA_FIXUP_ACT_PROBE,
145 HDA_FIXUP_ACT_INIT,
146 HDA_FIXUP_ACT_BUILD,
147};
148
149int snd_hda_gen_add_verbs(struct hda_gen_spec *spec,
150 const struct hda_verb *list);
151void snd_hda_gen_apply_verbs(struct hda_codec *codec);
152void snd_hda_apply_pincfgs(struct hda_codec *codec,
153 const struct hda_pintbl *cfg);
154void snd_hda_apply_fixup(struct hda_codec *codec, int action);
155void snd_hda_pick_fixup(struct hda_codec *codec,
156 const struct hda_model_fixup *models,
157 const struct snd_pci_quirk *quirk,
158 const struct hda_fixup *fixlist);
159
160#endif /* __SOUND_HDA_AUTO_PARSER_H */
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 841475cc13b6..eb09a3348325 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -334,78 +334,67 @@ static hda_nid_t *lookup_conn_list(struct snd_array *array, hda_nid_t nid)
334 return NULL; 334 return NULL;
335} 335}
336 336
337/* read the connection and add to the cache */
338static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid)
339{
340 hda_nid_t list[HDA_MAX_CONNECTIONS];
341 int len;
342
343 len = snd_hda_get_raw_connections(codec, nid, list, ARRAY_SIZE(list));
344 if (len < 0)
345 return len;
346 return snd_hda_override_conn_list(codec, nid, len, list);
347}
348
337/** 349/**
338 * snd_hda_get_conn_list - get connection list 350 * snd_hda_get_connections - copy connection list
339 * @codec: the HDA codec 351 * @codec: the HDA codec
340 * @nid: NID to parse 352 * @nid: NID to parse
341 * @listp: the pointer to store NID list 353 * @conn_list: connection list array; when NULL, checks only the size
354 * @max_conns: max. number of connections to store
342 * 355 *
343 * Parses the connection list of the given widget and stores the list 356 * Parses the connection list of the given widget and stores the list
344 * of NIDs. 357 * of NIDs.
345 * 358 *
346 * Returns the number of connections, or a negative error code. 359 * Returns the number of connections, or a negative error code.
347 */ 360 */
348int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, 361int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
349 const hda_nid_t **listp) 362 hda_nid_t *conn_list, int max_conns)
350{ 363{
351 struct snd_array *array = &codec->conn_lists; 364 struct snd_array *array = &codec->conn_lists;
352 int len, err; 365 int len;
353 hda_nid_t list[HDA_MAX_CONNECTIONS];
354 hda_nid_t *p; 366 hda_nid_t *p;
355 bool added = false; 367 bool added = false;
356 368
357 again: 369 again:
370 mutex_lock(&codec->hash_mutex);
371 len = -1;
358 /* if the connection-list is already cached, read it */ 372 /* if the connection-list is already cached, read it */
359 p = lookup_conn_list(array, nid); 373 p = lookup_conn_list(array, nid);
360 if (p) { 374 if (p) {
361 if (listp) 375 len = p[1];
362 *listp = p + 2; 376 if (conn_list && len > max_conns) {
363 return p[1]; 377 snd_printk(KERN_ERR "hda_codec: "
378 "Too many connections %d for NID 0x%x\n",
379 len, nid);
380 mutex_unlock(&codec->hash_mutex);
381 return -EINVAL;
382 }
383 if (conn_list && len)
384 memcpy(conn_list, p + 2, len * sizeof(hda_nid_t));
364 } 385 }
386 mutex_unlock(&codec->hash_mutex);
387 if (len >= 0)
388 return len;
365 if (snd_BUG_ON(added)) 389 if (snd_BUG_ON(added))
366 return -EINVAL; 390 return -EINVAL;
367 391
368 /* read the connection and add to the cache */ 392 len = read_and_add_raw_conns(codec, nid);
369 len = snd_hda_get_raw_connections(codec, nid, list, HDA_MAX_CONNECTIONS);
370 if (len < 0) 393 if (len < 0)
371 return len; 394 return len;
372 err = snd_hda_override_conn_list(codec, nid, len, list);
373 if (err < 0)
374 return err;
375 added = true; 395 added = true;
376 goto again; 396 goto again;
377} 397}
378EXPORT_SYMBOL_HDA(snd_hda_get_conn_list);
379
380/**
381 * snd_hda_get_connections - copy connection list
382 * @codec: the HDA codec
383 * @nid: NID to parse
384 * @conn_list: connection list array
385 * @max_conns: max. number of connections to store
386 *
387 * Parses the connection list of the given widget and stores the list
388 * of NIDs.
389 *
390 * Returns the number of connections, or a negative error code.
391 */
392int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
393 hda_nid_t *conn_list, int max_conns)
394{
395 const hda_nid_t *list;
396 int len = snd_hda_get_conn_list(codec, nid, &list);
397
398 if (len <= 0)
399 return len;
400 if (len > max_conns) {
401 snd_printk(KERN_ERR "hda_codec: "
402 "Too many connections %d for NID 0x%x\n",
403 len, nid);
404 return -EINVAL;
405 }
406 memcpy(conn_list, list, len * sizeof(hda_nid_t));
407 return len;
408}
409EXPORT_SYMBOL_HDA(snd_hda_get_connections); 398EXPORT_SYMBOL_HDA(snd_hda_get_connections);
410 399
411/** 400/**
@@ -543,6 +532,7 @@ int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
543 hda_nid_t *p; 532 hda_nid_t *p;
544 int i, old_used; 533 int i, old_used;
545 534
535 mutex_lock(&codec->hash_mutex);
546 p = lookup_conn_list(array, nid); 536 p = lookup_conn_list(array, nid);
547 if (p) 537 if (p)
548 *p = -1; /* invalidate the old entry */ 538 *p = -1; /* invalidate the old entry */
@@ -553,10 +543,12 @@ int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
553 for (i = 0; i < len; i++) 543 for (i = 0; i < len; i++)
554 if (!add_conn_list(array, list[i])) 544 if (!add_conn_list(array, list[i]))
555 goto error_add; 545 goto error_add;
546 mutex_unlock(&codec->hash_mutex);
556 return 0; 547 return 0;
557 548
558 error_add: 549 error_add:
559 array->used = old_used; 550 array->used = old_used;
551 mutex_unlock(&codec->hash_mutex);
560 return -ENOMEM; 552 return -ENOMEM;
561} 553}
562EXPORT_SYMBOL_HDA(snd_hda_override_conn_list); 554EXPORT_SYMBOL_HDA(snd_hda_override_conn_list);
@@ -1255,6 +1247,7 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus,
1255 codec->addr = codec_addr; 1247 codec->addr = codec_addr;
1256 mutex_init(&codec->spdif_mutex); 1248 mutex_init(&codec->spdif_mutex);
1257 mutex_init(&codec->control_mutex); 1249 mutex_init(&codec->control_mutex);
1250 mutex_init(&codec->hash_mutex);
1258 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); 1251 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
1259 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); 1252 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
1260 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); 1253 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32);
@@ -1264,15 +1257,9 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus,
1264 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); 1257 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8);
1265 snd_array_init(&codec->conn_lists, sizeof(hda_nid_t), 64); 1258 snd_array_init(&codec->conn_lists, sizeof(hda_nid_t), 64);
1266 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16); 1259 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16);
1267 if (codec->bus->modelname) {
1268 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
1269 if (!codec->modelname) {
1270 snd_hda_codec_free(codec);
1271 return -ENODEV;
1272 }
1273 }
1274 1260
1275#ifdef CONFIG_SND_HDA_POWER_SAVE 1261#ifdef CONFIG_SND_HDA_POWER_SAVE
1262 spin_lock_init(&codec->power_lock);
1276 INIT_DELAYED_WORK(&codec->power_work, hda_power_work); 1263 INIT_DELAYED_WORK(&codec->power_work, hda_power_work);
1277 /* snd_hda_codec_new() marks the codec as power-up, and leave it as is. 1264 /* snd_hda_codec_new() marks the codec as power-up, and leave it as is.
1278 * the caller has to power down appropriatley after initialization 1265 * the caller has to power down appropriatley after initialization
@@ -1281,6 +1268,14 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus,
1281 hda_keep_power_on(codec); 1268 hda_keep_power_on(codec);
1282#endif 1269#endif
1283 1270
1271 if (codec->bus->modelname) {
1272 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
1273 if (!codec->modelname) {
1274 snd_hda_codec_free(codec);
1275 return -ENODEV;
1276 }
1277 }
1278
1284 list_add_tail(&codec->list, &bus->codec_list); 1279 list_add_tail(&codec->list, &bus->codec_list);
1285 bus->caddr_tbl[codec_addr] = codec; 1280 bus->caddr_tbl[codec_addr] = codec;
1286 1281
@@ -1603,6 +1598,60 @@ get_alloc_amp_hash(struct hda_codec *codec, u32 key)
1603 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key); 1598 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key);
1604} 1599}
1605 1600
1601/* overwrite the value with the key in the caps hash */
1602static int write_caps_hash(struct hda_codec *codec, u32 key, unsigned int val)
1603{
1604 struct hda_amp_info *info;
1605
1606 mutex_lock(&codec->hash_mutex);
1607 info = get_alloc_amp_hash(codec, key);
1608 if (!info) {
1609 mutex_unlock(&codec->hash_mutex);
1610 return -EINVAL;
1611 }
1612 info->amp_caps = val;
1613 info->head.val |= INFO_AMP_CAPS;
1614 mutex_unlock(&codec->hash_mutex);
1615 return 0;
1616}
1617
1618/* query the value from the caps hash; if not found, fetch the current
1619 * value from the given function and store in the hash
1620 */
1621static unsigned int
1622query_caps_hash(struct hda_codec *codec, hda_nid_t nid, int dir, u32 key,
1623 unsigned int (*func)(struct hda_codec *, hda_nid_t, int))
1624{
1625 struct hda_amp_info *info;
1626 unsigned int val;
1627
1628 mutex_lock(&codec->hash_mutex);
1629 info = get_alloc_amp_hash(codec, key);
1630 if (!info) {
1631 mutex_unlock(&codec->hash_mutex);
1632 return 0;
1633 }
1634 if (!(info->head.val & INFO_AMP_CAPS)) {
1635 mutex_unlock(&codec->hash_mutex); /* for reentrance */
1636 val = func(codec, nid, dir);
1637 write_caps_hash(codec, key, val);
1638 } else {
1639 val = info->amp_caps;
1640 mutex_unlock(&codec->hash_mutex);
1641 }
1642 return val;
1643}
1644
1645static unsigned int read_amp_cap(struct hda_codec *codec, hda_nid_t nid,
1646 int direction)
1647{
1648 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD))
1649 nid = codec->afg;
1650 return snd_hda_param_read(codec, nid,
1651 direction == HDA_OUTPUT ?
1652 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
1653}
1654
1606/** 1655/**
1607 * query_amp_caps - query AMP capabilities 1656 * query_amp_caps - query AMP capabilities
1608 * @codec: the HD-auio codec 1657 * @codec: the HD-auio codec
@@ -1617,22 +1666,9 @@ get_alloc_amp_hash(struct hda_codec *codec, u32 key)
1617 */ 1666 */
1618u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) 1667u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1619{ 1668{
1620 struct hda_amp_info *info; 1669 return query_caps_hash(codec, nid, direction,
1621 1670 HDA_HASH_KEY(nid, direction, 0),
1622 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, 0)); 1671 read_amp_cap);
1623 if (!info)
1624 return 0;
1625 if (!(info->head.val & INFO_AMP_CAPS)) {
1626 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD))
1627 nid = codec->afg;
1628 info->amp_caps = snd_hda_param_read(codec, nid,
1629 direction == HDA_OUTPUT ?
1630 AC_PAR_AMP_OUT_CAP :
1631 AC_PAR_AMP_IN_CAP);
1632 if (info->amp_caps)
1633 info->head.val |= INFO_AMP_CAPS;
1634 }
1635 return info->amp_caps;
1636} 1672}
1637EXPORT_SYMBOL_HDA(query_amp_caps); 1673EXPORT_SYMBOL_HDA(query_amp_caps);
1638 1674
@@ -1652,34 +1688,12 @@ EXPORT_SYMBOL_HDA(query_amp_caps);
1652int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 1688int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
1653 unsigned int caps) 1689 unsigned int caps)
1654{ 1690{
1655 struct hda_amp_info *info; 1691 return write_caps_hash(codec, HDA_HASH_KEY(nid, dir, 0), caps);
1656
1657 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, dir, 0));
1658 if (!info)
1659 return -EINVAL;
1660 info->amp_caps = caps;
1661 info->head.val |= INFO_AMP_CAPS;
1662 return 0;
1663} 1692}
1664EXPORT_SYMBOL_HDA(snd_hda_override_amp_caps); 1693EXPORT_SYMBOL_HDA(snd_hda_override_amp_caps);
1665 1694
1666static unsigned int 1695static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid,
1667query_caps_hash(struct hda_codec *codec, hda_nid_t nid, u32 key, 1696 int dir)
1668 unsigned int (*func)(struct hda_codec *, hda_nid_t))
1669{
1670 struct hda_amp_info *info;
1671
1672 info = get_alloc_amp_hash(codec, key);
1673 if (!info)
1674 return 0;
1675 if (!info->head.val) {
1676 info->head.val |= INFO_AMP_CAPS;
1677 info->amp_caps = func(codec, nid);
1678 }
1679 return info->amp_caps;
1680}
1681
1682static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid)
1683{ 1697{
1684 return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); 1698 return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
1685} 1699}
@@ -1697,7 +1711,7 @@ static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid)
1697 */ 1711 */
1698u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) 1712u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
1699{ 1713{
1700 return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid), 1714 return query_caps_hash(codec, nid, 0, HDA_HASH_PINCAP_KEY(nid),
1701 read_pin_cap); 1715 read_pin_cap);
1702} 1716}
1703EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps); 1717EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps);
@@ -1715,41 +1729,47 @@ EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps);
1715int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, 1729int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
1716 unsigned int caps) 1730 unsigned int caps)
1717{ 1731{
1718 struct hda_amp_info *info; 1732 return write_caps_hash(codec, HDA_HASH_PINCAP_KEY(nid), caps);
1719 info = get_alloc_amp_hash(codec, HDA_HASH_PINCAP_KEY(nid));
1720 if (!info)
1721 return -ENOMEM;
1722 info->amp_caps = caps;
1723 info->head.val |= INFO_AMP_CAPS;
1724 return 0;
1725} 1733}
1726EXPORT_SYMBOL_HDA(snd_hda_override_pin_caps); 1734EXPORT_SYMBOL_HDA(snd_hda_override_pin_caps);
1727 1735
1728/* 1736/* read or sync the hash value with the current value;
1729 * read the current volume to info 1737 * call within hash_mutex
1730 * if the cache exists, read the cache value.
1731 */ 1738 */
1732static unsigned int get_vol_mute(struct hda_codec *codec, 1739static struct hda_amp_info *
1733 struct hda_amp_info *info, hda_nid_t nid, 1740update_amp_hash(struct hda_codec *codec, hda_nid_t nid, int ch,
1734 int ch, int direction, int index) 1741 int direction, int index)
1735{ 1742{
1736 u32 val, parm; 1743 struct hda_amp_info *info;
1737 1744 unsigned int parm, val = 0;
1738 if (info->head.val & INFO_AMP_VOL(ch)) 1745 bool val_read = false;
1739 return info->vol[ch];
1740 1746
1741 parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT; 1747 retry:
1742 parm |= direction == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT; 1748 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index));
1743 parm |= index; 1749 if (!info)
1744 val = snd_hda_codec_read(codec, nid, 0, 1750 return NULL;
1751 if (!(info->head.val & INFO_AMP_VOL(ch))) {
1752 if (!val_read) {
1753 mutex_unlock(&codec->hash_mutex);
1754 parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT;
1755 parm |= direction == HDA_OUTPUT ?
1756 AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
1757 parm |= index;
1758 val = snd_hda_codec_read(codec, nid, 0,
1745 AC_VERB_GET_AMP_GAIN_MUTE, parm); 1759 AC_VERB_GET_AMP_GAIN_MUTE, parm);
1746 info->vol[ch] = val & 0xff; 1760 val &= 0xff;
1747 info->head.val |= INFO_AMP_VOL(ch); 1761 val_read = true;
1748 return info->vol[ch]; 1762 mutex_lock(&codec->hash_mutex);
1763 goto retry;
1764 }
1765 info->vol[ch] = val;
1766 info->head.val |= INFO_AMP_VOL(ch);
1767 }
1768 return info;
1749} 1769}
1750 1770
1751/* 1771/*
1752 * write the current volume in info to the h/w and update the cache 1772 * write the current volume in info to the h/w
1753 */ 1773 */
1754static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info, 1774static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
1755 hda_nid_t nid, int ch, int direction, int index, 1775 hda_nid_t nid, int ch, int direction, int index,
@@ -1766,7 +1786,6 @@ static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
1766 else 1786 else
1767 parm |= val; 1787 parm |= val;
1768 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, parm); 1788 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, parm);
1769 info->vol[ch] = val;
1770} 1789}
1771 1790
1772/** 1791/**
@@ -1783,10 +1802,14 @@ int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
1783 int direction, int index) 1802 int direction, int index)
1784{ 1803{
1785 struct hda_amp_info *info; 1804 struct hda_amp_info *info;
1786 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index)); 1805 unsigned int val = 0;
1787 if (!info) 1806
1788 return 0; 1807 mutex_lock(&codec->hash_mutex);
1789 return get_vol_mute(codec, info, nid, ch, direction, index); 1808 info = update_amp_hash(codec, nid, ch, direction, index);
1809 if (info)
1810 val = info->vol[ch];
1811 mutex_unlock(&codec->hash_mutex);
1812 return val;
1790} 1813}
1791EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read); 1814EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read);
1792 1815
@@ -1808,15 +1831,23 @@ int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1808{ 1831{
1809 struct hda_amp_info *info; 1832 struct hda_amp_info *info;
1810 1833
1811 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, idx));
1812 if (!info)
1813 return 0;
1814 if (snd_BUG_ON(mask & ~0xff)) 1834 if (snd_BUG_ON(mask & ~0xff))
1815 mask &= 0xff; 1835 mask &= 0xff;
1816 val &= mask; 1836 val &= mask;
1817 val |= get_vol_mute(codec, info, nid, ch, direction, idx) & ~mask; 1837
1818 if (info->vol[ch] == val) 1838 mutex_lock(&codec->hash_mutex);
1839 info = update_amp_hash(codec, nid, ch, direction, idx);
1840 if (!info) {
1841 mutex_unlock(&codec->hash_mutex);
1842 return 0;
1843 }
1844 val |= info->vol[ch] & ~mask;
1845 if (info->vol[ch] == val) {
1846 mutex_unlock(&codec->hash_mutex);
1819 return 0; 1847 return 0;
1848 }
1849 info->vol[ch] = val;
1850 mutex_unlock(&codec->hash_mutex);
1820 put_vol_mute(codec, info, nid, ch, direction, idx, val); 1851 put_vol_mute(codec, info, nid, ch, direction, idx, val);
1821 return 1; 1852 return 1;
1822} 1853}
@@ -2263,7 +2294,10 @@ int snd_hda_codec_reset(struct hda_codec *codec)
2263 /* OK, let it free */ 2294 /* OK, let it free */
2264 2295
2265#ifdef CONFIG_SND_HDA_POWER_SAVE 2296#ifdef CONFIG_SND_HDA_POWER_SAVE
2266 cancel_delayed_work(&codec->power_work); 2297 cancel_delayed_work_sync(&codec->power_work);
2298 codec->power_on = 0;
2299 codec->power_transition = 0;
2300 codec->power_jiffies = jiffies;
2267 flush_workqueue(codec->bus->workq); 2301 flush_workqueue(codec->bus->workq);
2268#endif 2302#endif
2269 snd_hda_ctls_clear(codec); 2303 snd_hda_ctls_clear(codec);
@@ -2859,12 +2893,15 @@ static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol,
2859{ 2893{
2860 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2894 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2861 int idx = kcontrol->private_value; 2895 int idx = kcontrol->private_value;
2862 struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); 2896 struct hda_spdif_out *spdif;
2863 2897
2898 mutex_lock(&codec->spdif_mutex);
2899 spdif = snd_array_elem(&codec->spdif_out, idx);
2864 ucontrol->value.iec958.status[0] = spdif->status & 0xff; 2900 ucontrol->value.iec958.status[0] = spdif->status & 0xff;
2865 ucontrol->value.iec958.status[1] = (spdif->status >> 8) & 0xff; 2901 ucontrol->value.iec958.status[1] = (spdif->status >> 8) & 0xff;
2866 ucontrol->value.iec958.status[2] = (spdif->status >> 16) & 0xff; 2902 ucontrol->value.iec958.status[2] = (spdif->status >> 16) & 0xff;
2867 ucontrol->value.iec958.status[3] = (spdif->status >> 24) & 0xff; 2903 ucontrol->value.iec958.status[3] = (spdif->status >> 24) & 0xff;
2904 mutex_unlock(&codec->spdif_mutex);
2868 2905
2869 return 0; 2906 return 0;
2870} 2907}
@@ -2950,12 +2987,14 @@ static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,
2950{ 2987{
2951 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2988 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2952 int idx = kcontrol->private_value; 2989 int idx = kcontrol->private_value;
2953 struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); 2990 struct hda_spdif_out *spdif;
2954 hda_nid_t nid = spdif->nid; 2991 hda_nid_t nid;
2955 unsigned short val; 2992 unsigned short val;
2956 int change; 2993 int change;
2957 2994
2958 mutex_lock(&codec->spdif_mutex); 2995 mutex_lock(&codec->spdif_mutex);
2996 spdif = snd_array_elem(&codec->spdif_out, idx);
2997 nid = spdif->nid;
2959 spdif->status = ucontrol->value.iec958.status[0] | 2998 spdif->status = ucontrol->value.iec958.status[0] |
2960 ((unsigned int)ucontrol->value.iec958.status[1] << 8) | 2999 ((unsigned int)ucontrol->value.iec958.status[1] << 8) |
2961 ((unsigned int)ucontrol->value.iec958.status[2] << 16) | 3000 ((unsigned int)ucontrol->value.iec958.status[2] << 16) |
@@ -2977,9 +3016,12 @@ static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol,
2977{ 3016{
2978 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3017 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2979 int idx = kcontrol->private_value; 3018 int idx = kcontrol->private_value;
2980 struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); 3019 struct hda_spdif_out *spdif;
2981 3020
3021 mutex_lock(&codec->spdif_mutex);
3022 spdif = snd_array_elem(&codec->spdif_out, idx);
2982 ucontrol->value.integer.value[0] = spdif->ctls & AC_DIG1_ENABLE; 3023 ucontrol->value.integer.value[0] = spdif->ctls & AC_DIG1_ENABLE;
3024 mutex_unlock(&codec->spdif_mutex);
2983 return 0; 3025 return 0;
2984} 3026}
2985 3027
@@ -2999,12 +3041,14 @@ static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol,
2999{ 3041{
3000 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3042 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3001 int idx = kcontrol->private_value; 3043 int idx = kcontrol->private_value;
3002 struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); 3044 struct hda_spdif_out *spdif;
3003 hda_nid_t nid = spdif->nid; 3045 hda_nid_t nid;
3004 unsigned short val; 3046 unsigned short val;
3005 int change; 3047 int change;
3006 3048
3007 mutex_lock(&codec->spdif_mutex); 3049 mutex_lock(&codec->spdif_mutex);
3050 spdif = snd_array_elem(&codec->spdif_out, idx);
3051 nid = spdif->nid;
3008 val = spdif->ctls & ~AC_DIG1_ENABLE; 3052 val = spdif->ctls & ~AC_DIG1_ENABLE;
3009 if (ucontrol->value.integer.value[0]) 3053 if (ucontrol->value.integer.value[0])
3010 val |= AC_DIG1_ENABLE; 3054 val |= AC_DIG1_ENABLE;
@@ -3092,6 +3136,9 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec,
3092} 3136}
3093EXPORT_SYMBOL_HDA(snd_hda_create_spdif_out_ctls); 3137EXPORT_SYMBOL_HDA(snd_hda_create_spdif_out_ctls);
3094 3138
3139/* get the hda_spdif_out entry from the given NID
3140 * call within spdif_mutex lock
3141 */
3095struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec, 3142struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec,
3096 hda_nid_t nid) 3143 hda_nid_t nid)
3097{ 3144{
@@ -3108,9 +3155,10 @@ EXPORT_SYMBOL_HDA(snd_hda_spdif_out_of_nid);
3108 3155
3109void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx) 3156void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx)
3110{ 3157{
3111 struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); 3158 struct hda_spdif_out *spdif;
3112 3159
3113 mutex_lock(&codec->spdif_mutex); 3160 mutex_lock(&codec->spdif_mutex);
3161 spdif = snd_array_elem(&codec->spdif_out, idx);
3114 spdif->nid = (u16)-1; 3162 spdif->nid = (u16)-1;
3115 mutex_unlock(&codec->spdif_mutex); 3163 mutex_unlock(&codec->spdif_mutex);
3116} 3164}
@@ -3118,10 +3166,11 @@ EXPORT_SYMBOL_HDA(snd_hda_spdif_ctls_unassign);
3118 3166
3119void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid) 3167void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid)
3120{ 3168{
3121 struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); 3169 struct hda_spdif_out *spdif;
3122 unsigned short val; 3170 unsigned short val;
3123 3171
3124 mutex_lock(&codec->spdif_mutex); 3172 mutex_lock(&codec->spdif_mutex);
3173 spdif = snd_array_elem(&codec->spdif_out, idx);
3125 if (spdif->nid != nid) { 3174 if (spdif->nid != nid) {
3126 spdif->nid = nid; 3175 spdif->nid = nid;
3127 val = spdif->ctls; 3176 val = spdif->ctls;
@@ -3486,11 +3535,14 @@ static void hda_call_codec_suspend(struct hda_codec *codec)
3486 codec->afg ? codec->afg : codec->mfg, 3535 codec->afg ? codec->afg : codec->mfg,
3487 AC_PWRST_D3); 3536 AC_PWRST_D3);
3488#ifdef CONFIG_SND_HDA_POWER_SAVE 3537#ifdef CONFIG_SND_HDA_POWER_SAVE
3489 snd_hda_update_power_acct(codec);
3490 cancel_delayed_work(&codec->power_work); 3538 cancel_delayed_work(&codec->power_work);
3539 spin_lock(&codec->power_lock);
3540 snd_hda_update_power_acct(codec);
3541 trace_hda_power_down(codec);
3491 codec->power_on = 0; 3542 codec->power_on = 0;
3492 codec->power_transition = 0; 3543 codec->power_transition = 0;
3493 codec->power_jiffies = jiffies; 3544 codec->power_jiffies = jiffies;
3545 spin_unlock(&codec->power_lock);
3494#endif 3546#endif
3495} 3547}
3496 3548
@@ -3499,6 +3551,10 @@ static void hda_call_codec_suspend(struct hda_codec *codec)
3499 */ 3551 */
3500static void hda_call_codec_resume(struct hda_codec *codec) 3552static void hda_call_codec_resume(struct hda_codec *codec)
3501{ 3553{
3554 /* set as if powered on for avoiding re-entering the resume
3555 * in the resume / power-save sequence
3556 */
3557 hda_keep_power_on(codec);
3502 hda_set_power_state(codec, 3558 hda_set_power_state(codec,
3503 codec->afg ? codec->afg : codec->mfg, 3559 codec->afg ? codec->afg : codec->mfg,
3504 AC_PWRST_D0); 3560 AC_PWRST_D0);
@@ -3514,6 +3570,7 @@ static void hda_call_codec_resume(struct hda_codec *codec)
3514 snd_hda_codec_resume_amp(codec); 3570 snd_hda_codec_resume_amp(codec);
3515 snd_hda_codec_resume_cache(codec); 3571 snd_hda_codec_resume_cache(codec);
3516 } 3572 }
3573 snd_hda_power_down(codec); /* flag down before returning */
3517} 3574}
3518#endif /* CONFIG_PM */ 3575#endif /* CONFIG_PM */
3519 3576
@@ -3665,7 +3722,8 @@ unsigned int snd_hda_calc_stream_format(unsigned int rate,
3665} 3722}
3666EXPORT_SYMBOL_HDA(snd_hda_calc_stream_format); 3723EXPORT_SYMBOL_HDA(snd_hda_calc_stream_format);
3667 3724
3668static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid) 3725static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid,
3726 int dir)
3669{ 3727{
3670 unsigned int val = 0; 3728 unsigned int val = 0;
3671 if (nid != codec->afg && 3729 if (nid != codec->afg &&
@@ -3680,11 +3738,12 @@ static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid)
3680 3738
3681static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid) 3739static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid)
3682{ 3740{
3683 return query_caps_hash(codec, nid, HDA_HASH_PARPCM_KEY(nid), 3741 return query_caps_hash(codec, nid, 0, HDA_HASH_PARPCM_KEY(nid),
3684 get_pcm_param); 3742 get_pcm_param);
3685} 3743}
3686 3744
3687static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid) 3745static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid,
3746 int dir)
3688{ 3747{
3689 unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM); 3748 unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
3690 if (!streams || streams == -1) 3749 if (!streams || streams == -1)
@@ -3696,7 +3755,7 @@ static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid)
3696 3755
3697static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid) 3756static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid)
3698{ 3757{
3699 return query_caps_hash(codec, nid, HDA_HASH_PARSTR_KEY(nid), 3758 return query_caps_hash(codec, nid, 0, HDA_HASH_PARSTR_KEY(nid),
3700 get_stream_param); 3759 get_stream_param);
3701} 3760}
3702 3761
@@ -3775,11 +3834,13 @@ int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
3775 bps = 20; 3834 bps = 20;
3776 } 3835 }
3777 } 3836 }
3837#if 0 /* FIXME: CS4206 doesn't work, which is the only codec supporting float */
3778 if (streams & AC_SUPFMT_FLOAT32) { 3838 if (streams & AC_SUPFMT_FLOAT32) {
3779 formats |= SNDRV_PCM_FMTBIT_FLOAT_LE; 3839 formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
3780 if (!bps) 3840 if (!bps)
3781 bps = 32; 3841 bps = 32;
3782 } 3842 }
3843#endif
3783 if (streams == AC_SUPFMT_AC3) { 3844 if (streams == AC_SUPFMT_AC3) {
3784 /* should be exclusive */ 3845 /* should be exclusive */
3785 /* temporary hack: we have still no proper support 3846 /* temporary hack: we have still no proper support
@@ -4283,12 +4344,18 @@ static void hda_power_work(struct work_struct *work)
4283 container_of(work, struct hda_codec, power_work.work); 4344 container_of(work, struct hda_codec, power_work.work);
4284 struct hda_bus *bus = codec->bus; 4345 struct hda_bus *bus = codec->bus;
4285 4346
4347 spin_lock(&codec->power_lock);
4348 if (codec->power_transition > 0) { /* during power-up sequence? */
4349 spin_unlock(&codec->power_lock);
4350 return;
4351 }
4286 if (!codec->power_on || codec->power_count) { 4352 if (!codec->power_on || codec->power_count) {
4287 codec->power_transition = 0; 4353 codec->power_transition = 0;
4354 spin_unlock(&codec->power_lock);
4288 return; 4355 return;
4289 } 4356 }
4357 spin_unlock(&codec->power_lock);
4290 4358
4291 trace_hda_power_down(codec);
4292 hda_call_codec_suspend(codec); 4359 hda_call_codec_suspend(codec);
4293 if (bus->ops.pm_notify) 4360 if (bus->ops.pm_notify)
4294 bus->ops.pm_notify(bus); 4361 bus->ops.pm_notify(bus);
@@ -4296,9 +4363,11 @@ static void hda_power_work(struct work_struct *work)
4296 4363
4297static void hda_keep_power_on(struct hda_codec *codec) 4364static void hda_keep_power_on(struct hda_codec *codec)
4298{ 4365{
4366 spin_lock(&codec->power_lock);
4299 codec->power_count++; 4367 codec->power_count++;
4300 codec->power_on = 1; 4368 codec->power_on = 1;
4301 codec->power_jiffies = jiffies; 4369 codec->power_jiffies = jiffies;
4370 spin_unlock(&codec->power_lock);
4302} 4371}
4303 4372
4304/* update the power on/off account with the current jiffies */ 4373/* update the power on/off account with the current jiffies */
@@ -4323,19 +4392,31 @@ void snd_hda_power_up(struct hda_codec *codec)
4323{ 4392{
4324 struct hda_bus *bus = codec->bus; 4393 struct hda_bus *bus = codec->bus;
4325 4394
4395 spin_lock(&codec->power_lock);
4326 codec->power_count++; 4396 codec->power_count++;
4327 if (codec->power_on || codec->power_transition) 4397 if (codec->power_on || codec->power_transition > 0) {
4398 spin_unlock(&codec->power_lock);
4328 return; 4399 return;
4400 }
4401 spin_unlock(&codec->power_lock);
4329 4402
4403 cancel_delayed_work_sync(&codec->power_work);
4404
4405 spin_lock(&codec->power_lock);
4330 trace_hda_power_up(codec); 4406 trace_hda_power_up(codec);
4331 snd_hda_update_power_acct(codec); 4407 snd_hda_update_power_acct(codec);
4332 codec->power_on = 1; 4408 codec->power_on = 1;
4333 codec->power_jiffies = jiffies; 4409 codec->power_jiffies = jiffies;
4410 codec->power_transition = 1; /* avoid reentrance */
4411 spin_unlock(&codec->power_lock);
4412
4334 if (bus->ops.pm_notify) 4413 if (bus->ops.pm_notify)
4335 bus->ops.pm_notify(bus); 4414 bus->ops.pm_notify(bus);
4336 hda_call_codec_resume(codec); 4415 hda_call_codec_resume(codec);
4337 cancel_delayed_work(&codec->power_work); 4416
4417 spin_lock(&codec->power_lock);
4338 codec->power_transition = 0; 4418 codec->power_transition = 0;
4419 spin_unlock(&codec->power_lock);
4339} 4420}
4340EXPORT_SYMBOL_HDA(snd_hda_power_up); 4421EXPORT_SYMBOL_HDA(snd_hda_power_up);
4341 4422
@@ -4351,14 +4432,18 @@ EXPORT_SYMBOL_HDA(snd_hda_power_up);
4351 */ 4432 */
4352void snd_hda_power_down(struct hda_codec *codec) 4433void snd_hda_power_down(struct hda_codec *codec)
4353{ 4434{
4435 spin_lock(&codec->power_lock);
4354 --codec->power_count; 4436 --codec->power_count;
4355 if (!codec->power_on || codec->power_count || codec->power_transition) 4437 if (!codec->power_on || codec->power_count || codec->power_transition) {
4438 spin_unlock(&codec->power_lock);
4356 return; 4439 return;
4440 }
4357 if (power_save(codec)) { 4441 if (power_save(codec)) {
4358 codec->power_transition = 1; /* avoid reentrance */ 4442 codec->power_transition = -1; /* avoid reentrance */
4359 queue_delayed_work(codec->bus->workq, &codec->power_work, 4443 queue_delayed_work(codec->bus->workq, &codec->power_work,
4360 msecs_to_jiffies(power_save(codec) * 1000)); 4444 msecs_to_jiffies(power_save(codec) * 1000));
4361 } 4445 }
4446 spin_unlock(&codec->power_lock);
4362} 4447}
4363EXPORT_SYMBOL_HDA(snd_hda_power_down); 4448EXPORT_SYMBOL_HDA(snd_hda_power_down);
4364 4449
@@ -4710,11 +4795,11 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
4710{ 4795{
4711 const hda_nid_t *nids = mout->dac_nids; 4796 const hda_nid_t *nids = mout->dac_nids;
4712 int chs = substream->runtime->channels; 4797 int chs = substream->runtime->channels;
4713 struct hda_spdif_out *spdif = 4798 struct hda_spdif_out *spdif;
4714 snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid);
4715 int i; 4799 int i;
4716 4800
4717 mutex_lock(&codec->spdif_mutex); 4801 mutex_lock(&codec->spdif_mutex);
4802 spdif = snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid);
4718 if (mout->dig_out_nid && mout->share_spdif && 4803 if (mout->dig_out_nid && mout->share_spdif &&
4719 mout->dig_out_used != HDA_DIG_EXCLUSIVE) { 4804 mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
4720 if (chs == 2 && 4805 if (chs == 2 &&
@@ -4795,601 +4880,58 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
4795} 4880}
4796EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_cleanup); 4881EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_cleanup);
4797 4882
4798/*
4799 * Helper for automatic pin configuration
4800 */
4801
4802static int is_in_nid_list(hda_nid_t nid, const hda_nid_t *list)
4803{
4804 for (; *list; list++)
4805 if (*list == nid)
4806 return 1;
4807 return 0;
4808}
4809
4810
4811/*
4812 * Sort an associated group of pins according to their sequence numbers.
4813 */
4814static void sort_pins_by_sequence(hda_nid_t *pins, short *sequences,
4815 int num_pins)
4816{
4817 int i, j;
4818 short seq;
4819 hda_nid_t nid;
4820
4821 for (i = 0; i < num_pins; i++) {
4822 for (j = i + 1; j < num_pins; j++) {
4823 if (sequences[i] > sequences[j]) {
4824 seq = sequences[i];
4825 sequences[i] = sequences[j];
4826 sequences[j] = seq;
4827 nid = pins[i];
4828 pins[i] = pins[j];
4829 pins[j] = nid;
4830 }
4831 }
4832 }
4833}
4834
4835
4836/* add the found input-pin to the cfg->inputs[] table */
4837static void add_auto_cfg_input_pin(struct auto_pin_cfg *cfg, hda_nid_t nid,
4838 int type)
4839{
4840 if (cfg->num_inputs < AUTO_CFG_MAX_INS) {
4841 cfg->inputs[cfg->num_inputs].pin = nid;
4842 cfg->inputs[cfg->num_inputs].type = type;
4843 cfg->num_inputs++;
4844 }
4845}
4846
4847/* sort inputs in the order of AUTO_PIN_* type */
4848static void sort_autocfg_input_pins(struct auto_pin_cfg *cfg)
4849{
4850 int i, j;
4851
4852 for (i = 0; i < cfg->num_inputs; i++) {
4853 for (j = i + 1; j < cfg->num_inputs; j++) {
4854 if (cfg->inputs[i].type > cfg->inputs[j].type) {
4855 struct auto_pin_cfg_item tmp;
4856 tmp = cfg->inputs[i];
4857 cfg->inputs[i] = cfg->inputs[j];
4858 cfg->inputs[j] = tmp;
4859 }
4860 }
4861 }
4862}
4863
4864/* Reorder the surround channels
4865 * ALSA sequence is front/surr/clfe/side
4866 * HDA sequence is:
4867 * 4-ch: front/surr => OK as it is
4868 * 6-ch: front/clfe/surr
4869 * 8-ch: front/clfe/rear/side|fc
4870 */
4871static void reorder_outputs(unsigned int nums, hda_nid_t *pins)
4872{
4873 hda_nid_t nid;
4874
4875 switch (nums) {
4876 case 3:
4877 case 4:
4878 nid = pins[1];
4879 pins[1] = pins[2];
4880 pins[2] = nid;
4881 break;
4882 }
4883}
4884
4885/*
4886 * Parse all pin widgets and store the useful pin nids to cfg
4887 *
4888 * The number of line-outs or any primary output is stored in line_outs,
4889 * and the corresponding output pins are assigned to line_out_pins[],
4890 * in the order of front, rear, CLFE, side, ...
4891 *
4892 * If more extra outputs (speaker and headphone) are found, the pins are
4893 * assisnged to hp_pins[] and speaker_pins[], respectively. If no line-out jack
4894 * is detected, one of speaker of HP pins is assigned as the primary
4895 * output, i.e. to line_out_pins[0]. So, line_outs is always positive
4896 * if any analog output exists.
4897 *
4898 * The analog input pins are assigned to inputs array.
4899 * The digital input/output pins are assigned to dig_in_pin and dig_out_pin,
4900 * respectively.
4901 */
4902int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
4903 struct auto_pin_cfg *cfg,
4904 const hda_nid_t *ignore_nids,
4905 unsigned int cond_flags)
4906{
4907 hda_nid_t nid, end_nid;
4908 short seq, assoc_line_out;
4909 short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)];
4910 short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)];
4911 short sequences_hp[ARRAY_SIZE(cfg->hp_pins)];
4912 int i;
4913
4914 memset(cfg, 0, sizeof(*cfg));
4915
4916 memset(sequences_line_out, 0, sizeof(sequences_line_out));
4917 memset(sequences_speaker, 0, sizeof(sequences_speaker));
4918 memset(sequences_hp, 0, sizeof(sequences_hp));
4919 assoc_line_out = 0;
4920
4921 codec->ignore_misc_bit = true;
4922 end_nid = codec->start_nid + codec->num_nodes;
4923 for (nid = codec->start_nid; nid < end_nid; nid++) {
4924 unsigned int wid_caps = get_wcaps(codec, nid);
4925 unsigned int wid_type = get_wcaps_type(wid_caps);
4926 unsigned int def_conf;
4927 short assoc, loc, conn, dev;
4928
4929 /* read all default configuration for pin complex */
4930 if (wid_type != AC_WID_PIN)
4931 continue;
4932 /* ignore the given nids (e.g. pc-beep returns error) */
4933 if (ignore_nids && is_in_nid_list(nid, ignore_nids))
4934 continue;
4935
4936 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4937 if (!(get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) &
4938 AC_DEFCFG_MISC_NO_PRESENCE))
4939 codec->ignore_misc_bit = false;
4940 conn = get_defcfg_connect(def_conf);
4941 if (conn == AC_JACK_PORT_NONE)
4942 continue;
4943 loc = get_defcfg_location(def_conf);
4944 dev = get_defcfg_device(def_conf);
4945
4946 /* workaround for buggy BIOS setups */
4947 if (dev == AC_JACK_LINE_OUT) {
4948 if (conn == AC_JACK_PORT_FIXED)
4949 dev = AC_JACK_SPEAKER;
4950 }
4951
4952 switch (dev) {
4953 case AC_JACK_LINE_OUT:
4954 seq = get_defcfg_sequence(def_conf);
4955 assoc = get_defcfg_association(def_conf);
4956
4957 if (!(wid_caps & AC_WCAP_STEREO))
4958 if (!cfg->mono_out_pin)
4959 cfg->mono_out_pin = nid;
4960 if (!assoc)
4961 continue;
4962 if (!assoc_line_out)
4963 assoc_line_out = assoc;
4964 else if (assoc_line_out != assoc)
4965 continue;
4966 if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins))
4967 continue;
4968 cfg->line_out_pins[cfg->line_outs] = nid;
4969 sequences_line_out[cfg->line_outs] = seq;
4970 cfg->line_outs++;
4971 break;
4972 case AC_JACK_SPEAKER:
4973 seq = get_defcfg_sequence(def_conf);
4974 assoc = get_defcfg_association(def_conf);
4975 if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins))
4976 continue;
4977 cfg->speaker_pins[cfg->speaker_outs] = nid;
4978 sequences_speaker[cfg->speaker_outs] = (assoc << 4) | seq;
4979 cfg->speaker_outs++;
4980 break;
4981 case AC_JACK_HP_OUT:
4982 seq = get_defcfg_sequence(def_conf);
4983 assoc = get_defcfg_association(def_conf);
4984 if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins))
4985 continue;
4986 cfg->hp_pins[cfg->hp_outs] = nid;
4987 sequences_hp[cfg->hp_outs] = (assoc << 4) | seq;
4988 cfg->hp_outs++;
4989 break;
4990 case AC_JACK_MIC_IN:
4991 add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_MIC);
4992 break;
4993 case AC_JACK_LINE_IN:
4994 add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_LINE_IN);
4995 break;
4996 case AC_JACK_CD:
4997 add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_CD);
4998 break;
4999 case AC_JACK_AUX:
5000 add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_AUX);
5001 break;
5002 case AC_JACK_SPDIF_OUT:
5003 case AC_JACK_DIG_OTHER_OUT:
5004 if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins))
5005 continue;
5006 cfg->dig_out_pins[cfg->dig_outs] = nid;
5007 cfg->dig_out_type[cfg->dig_outs] =
5008 (loc == AC_JACK_LOC_HDMI) ?
5009 HDA_PCM_TYPE_HDMI : HDA_PCM_TYPE_SPDIF;
5010 cfg->dig_outs++;
5011 break;
5012 case AC_JACK_SPDIF_IN:
5013 case AC_JACK_DIG_OTHER_IN:
5014 cfg->dig_in_pin = nid;
5015 if (loc == AC_JACK_LOC_HDMI)
5016 cfg->dig_in_type = HDA_PCM_TYPE_HDMI;
5017 else
5018 cfg->dig_in_type = HDA_PCM_TYPE_SPDIF;
5019 break;
5020 }
5021 }
5022
5023 /* FIX-UP:
5024 * If no line-out is defined but multiple HPs are found,
5025 * some of them might be the real line-outs.
5026 */
5027 if (!cfg->line_outs && cfg->hp_outs > 1 &&
5028 !(cond_flags & HDA_PINCFG_NO_HP_FIXUP)) {
5029 int i = 0;
5030 while (i < cfg->hp_outs) {
5031 /* The real HPs should have the sequence 0x0f */
5032 if ((sequences_hp[i] & 0x0f) == 0x0f) {
5033 i++;
5034 continue;
5035 }
5036 /* Move it to the line-out table */
5037 cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i];
5038 sequences_line_out[cfg->line_outs] = sequences_hp[i];
5039 cfg->line_outs++;
5040 cfg->hp_outs--;
5041 memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1,
5042 sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i));
5043 memmove(sequences_hp + i, sequences_hp + i + 1,
5044 sizeof(sequences_hp[0]) * (cfg->hp_outs - i));
5045 }
5046 memset(cfg->hp_pins + cfg->hp_outs, 0,
5047 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - cfg->hp_outs));
5048 if (!cfg->hp_outs)
5049 cfg->line_out_type = AUTO_PIN_HP_OUT;
5050
5051 }
5052
5053 /* sort by sequence */
5054 sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out,
5055 cfg->line_outs);
5056 sort_pins_by_sequence(cfg->speaker_pins, sequences_speaker,
5057 cfg->speaker_outs);
5058 sort_pins_by_sequence(cfg->hp_pins, sequences_hp,
5059 cfg->hp_outs);
5060
5061 /*
5062 * FIX-UP: if no line-outs are detected, try to use speaker or HP pin
5063 * as a primary output
5064 */
5065 if (!cfg->line_outs &&
5066 !(cond_flags & HDA_PINCFG_NO_LO_FIXUP)) {
5067 if (cfg->speaker_outs) {
5068 cfg->line_outs = cfg->speaker_outs;
5069 memcpy(cfg->line_out_pins, cfg->speaker_pins,
5070 sizeof(cfg->speaker_pins));
5071 cfg->speaker_outs = 0;
5072 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
5073 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
5074 } else if (cfg->hp_outs) {
5075 cfg->line_outs = cfg->hp_outs;
5076 memcpy(cfg->line_out_pins, cfg->hp_pins,
5077 sizeof(cfg->hp_pins));
5078 cfg->hp_outs = 0;
5079 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
5080 cfg->line_out_type = AUTO_PIN_HP_OUT;
5081 }
5082 }
5083
5084 reorder_outputs(cfg->line_outs, cfg->line_out_pins);
5085 reorder_outputs(cfg->hp_outs, cfg->hp_pins);
5086 reorder_outputs(cfg->speaker_outs, cfg->speaker_pins);
5087
5088 sort_autocfg_input_pins(cfg);
5089
5090 /*
5091 * debug prints of the parsed results
5092 */
5093 snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n",
5094 cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1],
5095 cfg->line_out_pins[2], cfg->line_out_pins[3],
5096 cfg->line_out_pins[4],
5097 cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" :
5098 (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ?
5099 "speaker" : "line"));
5100 snd_printd(" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
5101 cfg->speaker_outs, cfg->speaker_pins[0],
5102 cfg->speaker_pins[1], cfg->speaker_pins[2],
5103 cfg->speaker_pins[3], cfg->speaker_pins[4]);
5104 snd_printd(" hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
5105 cfg->hp_outs, cfg->hp_pins[0],
5106 cfg->hp_pins[1], cfg->hp_pins[2],
5107 cfg->hp_pins[3], cfg->hp_pins[4]);
5108 snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin);
5109 if (cfg->dig_outs)
5110 snd_printd(" dig-out=0x%x/0x%x\n",
5111 cfg->dig_out_pins[0], cfg->dig_out_pins[1]);
5112 snd_printd(" inputs:");
5113 for (i = 0; i < cfg->num_inputs; i++) {
5114 snd_printd(" %s=0x%x",
5115 hda_get_autocfg_input_label(codec, cfg, i),
5116 cfg->inputs[i].pin);
5117 }
5118 snd_printd("\n");
5119 if (cfg->dig_in_pin)
5120 snd_printd(" dig-in=0x%x\n", cfg->dig_in_pin);
5121
5122 return 0;
5123}
5124EXPORT_SYMBOL_HDA(snd_hda_parse_pin_defcfg);
5125
5126int snd_hda_get_input_pin_attr(unsigned int def_conf)
5127{
5128 unsigned int loc = get_defcfg_location(def_conf);
5129 unsigned int conn = get_defcfg_connect(def_conf);
5130 if (conn == AC_JACK_PORT_NONE)
5131 return INPUT_PIN_ATTR_UNUSED;
5132 /* Windows may claim the internal mic to be BOTH, too */
5133 if (conn == AC_JACK_PORT_FIXED || conn == AC_JACK_PORT_BOTH)
5134 return INPUT_PIN_ATTR_INT;
5135 if ((loc & 0x30) == AC_JACK_LOC_INTERNAL)
5136 return INPUT_PIN_ATTR_INT;
5137 if ((loc & 0x30) == AC_JACK_LOC_SEPARATE)
5138 return INPUT_PIN_ATTR_DOCK;
5139 if (loc == AC_JACK_LOC_REAR)
5140 return INPUT_PIN_ATTR_REAR;
5141 if (loc == AC_JACK_LOC_FRONT)
5142 return INPUT_PIN_ATTR_FRONT;
5143 return INPUT_PIN_ATTR_NORMAL;
5144}
5145EXPORT_SYMBOL_HDA(snd_hda_get_input_pin_attr);
5146
5147/**
5148 * hda_get_input_pin_label - Give a label for the given input pin
5149 *
5150 * When check_location is true, the function checks the pin location
5151 * for mic and line-in pins, and set an appropriate prefix like "Front",
5152 * "Rear", "Internal".
5153 */
5154
5155static const char *hda_get_input_pin_label(struct hda_codec *codec,
5156 hda_nid_t pin, bool check_location)
5157{
5158 unsigned int def_conf;
5159 static const char * const mic_names[] = {
5160 "Internal Mic", "Dock Mic", "Mic", "Front Mic", "Rear Mic",
5161 };
5162 int attr;
5163
5164 def_conf = snd_hda_codec_get_pincfg(codec, pin);
5165
5166 switch (get_defcfg_device(def_conf)) {
5167 case AC_JACK_MIC_IN:
5168 if (!check_location)
5169 return "Mic";
5170 attr = snd_hda_get_input_pin_attr(def_conf);
5171 if (!attr)
5172 return "None";
5173 return mic_names[attr - 1];
5174 case AC_JACK_LINE_IN:
5175 if (!check_location)
5176 return "Line";
5177 attr = snd_hda_get_input_pin_attr(def_conf);
5178 if (!attr)
5179 return "None";
5180 if (attr == INPUT_PIN_ATTR_DOCK)
5181 return "Dock Line";
5182 return "Line";
5183 case AC_JACK_AUX:
5184 return "Aux";
5185 case AC_JACK_CD:
5186 return "CD";
5187 case AC_JACK_SPDIF_IN:
5188 return "SPDIF In";
5189 case AC_JACK_DIG_OTHER_IN:
5190 return "Digital In";
5191 default:
5192 return "Misc";
5193 }
5194}
5195
5196/* Check whether the location prefix needs to be added to the label.
5197 * If all mic-jacks are in the same location (e.g. rear panel), we don't
5198 * have to put "Front" prefix to each label. In such a case, returns false.
5199 */
5200static int check_mic_location_need(struct hda_codec *codec,
5201 const struct auto_pin_cfg *cfg,
5202 int input)
5203{
5204 unsigned int defc;
5205 int i, attr, attr2;
5206
5207 defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[input].pin);
5208 attr = snd_hda_get_input_pin_attr(defc);
5209 /* for internal or docking mics, we need locations */
5210 if (attr <= INPUT_PIN_ATTR_NORMAL)
5211 return 1;
5212
5213 attr = 0;
5214 for (i = 0; i < cfg->num_inputs; i++) {
5215 defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[i].pin);
5216 attr2 = snd_hda_get_input_pin_attr(defc);
5217 if (attr2 >= INPUT_PIN_ATTR_NORMAL) {
5218 if (attr && attr != attr2)
5219 return 1; /* different locations found */
5220 attr = attr2;
5221 }
5222 }
5223 return 0;
5224}
5225
5226/** 4883/**
5227 * hda_get_autocfg_input_label - Get a label for the given input 4884 * snd_hda_get_default_vref - Get the default (mic) VREF pin bits
5228 * 4885 *
5229 * Get a label for the given input pin defined by the autocfg item. 4886 * Guess the suitable VREF pin bits to be set as the pin-control value.
5230 * Unlike hda_get_input_pin_label(), this function checks all inputs 4887 * Note: the function doesn't set the AC_PINCTL_IN_EN bit.
5231 * defined in autocfg and avoids the redundant mic/line prefix as much as 4888 */
5232 * possible. 4889unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin)
5233 */ 4890{
5234const char *hda_get_autocfg_input_label(struct hda_codec *codec, 4891 unsigned int pincap;
5235 const struct auto_pin_cfg *cfg, 4892 unsigned int oldval;
5236 int input) 4893 oldval = snd_hda_codec_read(codec, pin, 0,
5237{ 4894 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5238 int type = cfg->inputs[input].type; 4895 pincap = snd_hda_query_pin_caps(codec, pin);
5239 int has_multiple_pins = 0; 4896 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
5240 4897 /* Exception: if the default pin setup is vref50, we give it priority */
5241 if ((input > 0 && cfg->inputs[input - 1].type == type) || 4898 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
5242 (input < cfg->num_inputs - 1 && cfg->inputs[input + 1].type == type)) 4899 return AC_PINCTL_VREF_80;
5243 has_multiple_pins = 1; 4900 else if (pincap & AC_PINCAP_VREF_50)
5244 if (has_multiple_pins && type == AUTO_PIN_MIC) 4901 return AC_PINCTL_VREF_50;
5245 has_multiple_pins &= check_mic_location_need(codec, cfg, input); 4902 else if (pincap & AC_PINCAP_VREF_100)
5246 return hda_get_input_pin_label(codec, cfg->inputs[input].pin, 4903 return AC_PINCTL_VREF_100;
5247 has_multiple_pins); 4904 else if (pincap & AC_PINCAP_VREF_GRD)
5248} 4905 return AC_PINCTL_VREF_GRD;
5249EXPORT_SYMBOL_HDA(hda_get_autocfg_input_label); 4906 return AC_PINCTL_VREF_HIZ;
5250 4907}
5251/* return the position of NID in the list, or -1 if not found */ 4908EXPORT_SYMBOL_HDA(snd_hda_get_default_vref);
5252static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) 4909
5253{ 4910int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
5254 int i; 4911 unsigned int val, bool cached)
5255 for (i = 0; i < nums; i++) 4912{
5256 if (list[i] == nid) 4913 if (val) {
5257 return i; 4914 unsigned int cap = snd_hda_query_pin_caps(codec, pin);
5258 return -1; 4915 if (cap && (val & AC_PINCTL_OUT_EN)) {
5259} 4916 if (!(cap & AC_PINCAP_OUT))
5260 4917 val &= ~(AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
5261/* get a unique suffix or an index number */ 4918 else if ((val & AC_PINCTL_HP_EN) &&
5262static const char *check_output_sfx(hda_nid_t nid, const hda_nid_t *pins, 4919 !(cap & AC_PINCAP_HP_DRV))
5263 int num_pins, int *indexp) 4920 val &= ~AC_PINCTL_HP_EN;
5264{
5265 static const char * const channel_sfx[] = {
5266 " Front", " Surround", " CLFE", " Side"
5267 };
5268 int i;
5269
5270 i = find_idx_in_nid_list(nid, pins, num_pins);
5271 if (i < 0)
5272 return NULL;
5273 if (num_pins == 1)
5274 return "";
5275 if (num_pins > ARRAY_SIZE(channel_sfx)) {
5276 if (indexp)
5277 *indexp = i;
5278 return "";
5279 }
5280 return channel_sfx[i];
5281}
5282
5283static int fill_audio_out_name(struct hda_codec *codec, hda_nid_t nid,
5284 const struct auto_pin_cfg *cfg,
5285 const char *name, char *label, int maxlen,
5286 int *indexp)
5287{
5288 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5289 int attr = snd_hda_get_input_pin_attr(def_conf);
5290 const char *pfx = "", *sfx = "";
5291
5292 /* handle as a speaker if it's a fixed line-out */
5293 if (!strcmp(name, "Line Out") && attr == INPUT_PIN_ATTR_INT)
5294 name = "Speaker";
5295 /* check the location */
5296 switch (attr) {
5297 case INPUT_PIN_ATTR_DOCK:
5298 pfx = "Dock ";
5299 break;
5300 case INPUT_PIN_ATTR_FRONT:
5301 pfx = "Front ";
5302 break;
5303 }
5304 if (cfg) {
5305 /* try to give a unique suffix if needed */
5306 sfx = check_output_sfx(nid, cfg->line_out_pins, cfg->line_outs,
5307 indexp);
5308 if (!sfx)
5309 sfx = check_output_sfx(nid, cfg->speaker_pins, cfg->speaker_outs,
5310 indexp);
5311 if (!sfx) {
5312 /* don't add channel suffix for Headphone controls */
5313 int idx = find_idx_in_nid_list(nid, cfg->hp_pins,
5314 cfg->hp_outs);
5315 if (idx >= 0)
5316 *indexp = idx;
5317 sfx = "";
5318 } 4921 }
5319 } 4922 if (cap && (val & AC_PINCTL_IN_EN)) {
5320 snprintf(label, maxlen, "%s%s%s", pfx, name, sfx); 4923 if (!(cap & AC_PINCAP_IN))
5321 return 1; 4924 val &= ~(AC_PINCTL_IN_EN | AC_PINCTL_VREFEN);
5322}
5323
5324/**
5325 * snd_hda_get_pin_label - Get a label for the given I/O pin
5326 *
5327 * Get a label for the given pin. This function works for both input and
5328 * output pins. When @cfg is given as non-NULL, the function tries to get
5329 * an optimized label using hda_get_autocfg_input_label().
5330 *
5331 * This function tries to give a unique label string for the pin as much as
5332 * possible. For example, when the multiple line-outs are present, it adds
5333 * the channel suffix like "Front", "Surround", etc (only when @cfg is given).
5334 * If no unique name with a suffix is available and @indexp is non-NULL, the
5335 * index number is stored in the pointer.
5336 */
5337int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
5338 const struct auto_pin_cfg *cfg,
5339 char *label, int maxlen, int *indexp)
5340{
5341 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5342 const char *name = NULL;
5343 int i;
5344
5345 if (indexp)
5346 *indexp = 0;
5347 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
5348 return 0;
5349
5350 switch (get_defcfg_device(def_conf)) {
5351 case AC_JACK_LINE_OUT:
5352 return fill_audio_out_name(codec, nid, cfg, "Line Out",
5353 label, maxlen, indexp);
5354 case AC_JACK_SPEAKER:
5355 return fill_audio_out_name(codec, nid, cfg, "Speaker",
5356 label, maxlen, indexp);
5357 case AC_JACK_HP_OUT:
5358 return fill_audio_out_name(codec, nid, cfg, "Headphone",
5359 label, maxlen, indexp);
5360 case AC_JACK_SPDIF_OUT:
5361 case AC_JACK_DIG_OTHER_OUT:
5362 if (get_defcfg_location(def_conf) == AC_JACK_LOC_HDMI)
5363 name = "HDMI";
5364 else
5365 name = "SPDIF";
5366 if (cfg && indexp) {
5367 i = find_idx_in_nid_list(nid, cfg->dig_out_pins,
5368 cfg->dig_outs);
5369 if (i >= 0)
5370 *indexp = i;
5371 }
5372 break;
5373 default:
5374 if (cfg) {
5375 for (i = 0; i < cfg->num_inputs; i++) {
5376 if (cfg->inputs[i].pin != nid)
5377 continue;
5378 name = hda_get_autocfg_input_label(codec, cfg, i);
5379 if (name)
5380 break;
5381 }
5382 } 4925 }
5383 if (!name)
5384 name = hda_get_input_pin_label(codec, nid, true);
5385 break;
5386 } 4926 }
5387 if (!name) 4927 if (cached)
5388 return 0; 4928 return snd_hda_codec_update_cache(codec, pin, 0,
5389 strlcpy(label, name, maxlen); 4929 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5390 return 1; 4930 else
4931 return snd_hda_codec_write(codec, pin, 0,
4932 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5391} 4933}
5392EXPORT_SYMBOL_HDA(snd_hda_get_pin_label); 4934EXPORT_SYMBOL_HDA(_snd_hda_set_pin_ctl);
5393 4935
5394/** 4936/**
5395 * snd_hda_add_imux_item - Add an item to input_mux 4937 * snd_hda_add_imux_item - Add an item to input_mux
@@ -5444,8 +4986,6 @@ int snd_hda_suspend(struct hda_bus *bus)
5444 list_for_each_entry(codec, &bus->codec_list, list) { 4986 list_for_each_entry(codec, &bus->codec_list, list) {
5445 if (hda_codec_is_power_on(codec)) 4987 if (hda_codec_is_power_on(codec))
5446 hda_call_codec_suspend(codec); 4988 hda_call_codec_suspend(codec);
5447 if (codec->patch_ops.post_suspend)
5448 codec->patch_ops.post_suspend(codec);
5449 } 4989 }
5450 return 0; 4990 return 0;
5451} 4991}
@@ -5465,10 +5005,7 @@ int snd_hda_resume(struct hda_bus *bus)
5465 struct hda_codec *codec; 5005 struct hda_codec *codec;
5466 5006
5467 list_for_each_entry(codec, &bus->codec_list, list) { 5007 list_for_each_entry(codec, &bus->codec_list, list) {
5468 if (codec->patch_ops.pre_resume) 5008 hda_call_codec_resume(codec);
5469 codec->patch_ops.pre_resume(codec);
5470 if (snd_hda_codec_needs_resume(codec))
5471 hda_call_codec_resume(codec);
5472 } 5009 }
5473 return 0; 5010 return 0;
5474} 5011}
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 56b4f74c0b13..54b52819fb47 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -704,8 +704,6 @@ struct hda_codec_ops {
704 unsigned int power_state); 704 unsigned int power_state);
705#ifdef CONFIG_PM 705#ifdef CONFIG_PM
706 int (*suspend)(struct hda_codec *codec, pm_message_t state); 706 int (*suspend)(struct hda_codec *codec, pm_message_t state);
707 int (*post_suspend)(struct hda_codec *codec);
708 int (*pre_resume)(struct hda_codec *codec);
709 int (*resume)(struct hda_codec *codec); 707 int (*resume)(struct hda_codec *codec);
710#endif 708#endif
711#ifdef CONFIG_SND_HDA_POWER_SAVE 709#ifdef CONFIG_SND_HDA_POWER_SAVE
@@ -829,6 +827,7 @@ struct hda_codec {
829 827
830 struct mutex spdif_mutex; 828 struct mutex spdif_mutex;
831 struct mutex control_mutex; 829 struct mutex control_mutex;
830 struct mutex hash_mutex;
832 struct snd_array spdif_out; 831 struct snd_array spdif_out;
833 unsigned int spdif_in_enable; /* SPDIF input enable? */ 832 unsigned int spdif_in_enable; /* SPDIF input enable? */
834 const hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */ 833 const hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */
@@ -861,12 +860,13 @@ struct hda_codec {
861 unsigned int no_jack_detect:1; /* Machine has no jack-detection */ 860 unsigned int no_jack_detect:1; /* Machine has no jack-detection */
862#ifdef CONFIG_SND_HDA_POWER_SAVE 861#ifdef CONFIG_SND_HDA_POWER_SAVE
863 unsigned int power_on :1; /* current (global) power-state */ 862 unsigned int power_on :1; /* current (global) power-state */
864 unsigned int power_transition :1; /* power-state in transition */ 863 int power_transition; /* power-state in transition */
865 int power_count; /* current (global) power refcount */ 864 int power_count; /* current (global) power refcount */
866 struct delayed_work power_work; /* delayed task for powerdown */ 865 struct delayed_work power_work; /* delayed task for powerdown */
867 unsigned long power_on_acct; 866 unsigned long power_on_acct;
868 unsigned long power_off_acct; 867 unsigned long power_off_acct;
869 unsigned long power_jiffies; 868 unsigned long power_jiffies;
869 spinlock_t power_lock;
870#endif 870#endif
871 871
872 /* codec-specific additional proc output */ 872 /* codec-specific additional proc output */
@@ -911,10 +911,13 @@ int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid,
911 hda_nid_t *start_id); 911 hda_nid_t *start_id);
912int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, 912int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
913 hda_nid_t *conn_list, int max_conns); 913 hda_nid_t *conn_list, int max_conns);
914static inline int
915snd_hda_get_num_conns(struct hda_codec *codec, hda_nid_t nid)
916{
917 return snd_hda_get_connections(codec, nid, NULL, 0);
918}
914int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid, 919int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid,
915 hda_nid_t *conn_list, int max_conns); 920 hda_nid_t *conn_list, int max_conns);
916int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
917 const hda_nid_t **listp);
918int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums, 921int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums,
919 const hda_nid_t *list); 922 const hda_nid_t *list);
920int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux, 923int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
@@ -1051,12 +1054,10 @@ const char *snd_hda_get_jack_location(u32 cfg);
1051#ifdef CONFIG_SND_HDA_POWER_SAVE 1054#ifdef CONFIG_SND_HDA_POWER_SAVE
1052void snd_hda_power_up(struct hda_codec *codec); 1055void snd_hda_power_up(struct hda_codec *codec);
1053void snd_hda_power_down(struct hda_codec *codec); 1056void snd_hda_power_down(struct hda_codec *codec);
1054#define snd_hda_codec_needs_resume(codec) codec->power_count
1055void snd_hda_update_power_acct(struct hda_codec *codec); 1057void snd_hda_update_power_acct(struct hda_codec *codec);
1056#else 1058#else
1057static inline void snd_hda_power_up(struct hda_codec *codec) {} 1059static inline void snd_hda_power_up(struct hda_codec *codec) {}
1058static inline void snd_hda_power_down(struct hda_codec *codec) {} 1060static inline void snd_hda_power_down(struct hda_codec *codec) {}
1059#define snd_hda_codec_needs_resume(codec) 1
1060#endif 1061#endif
1061 1062
1062#ifdef CONFIG_SND_HDA_PATCH_LOADER 1063#ifdef CONFIG_SND_HDA_PATCH_LOADER
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 1f350522bed4..4ab8102f87ea 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -497,6 +497,7 @@ enum {
497 AZX_DRIVER_NVIDIA, 497 AZX_DRIVER_NVIDIA,
498 AZX_DRIVER_TERA, 498 AZX_DRIVER_TERA,
499 AZX_DRIVER_CTX, 499 AZX_DRIVER_CTX,
500 AZX_DRIVER_CTHDA,
500 AZX_DRIVER_GENERIC, 501 AZX_DRIVER_GENERIC,
501 AZX_NUM_DRIVERS, /* keep this as last entry */ 502 AZX_NUM_DRIVERS, /* keep this as last entry */
502}; 503};
@@ -518,6 +519,7 @@ enum {
518#define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */ 519#define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */
519#define AZX_DCAPS_BUFSIZE (1 << 21) /* no buffer size alignment */ 520#define AZX_DCAPS_BUFSIZE (1 << 21) /* no buffer size alignment */
520#define AZX_DCAPS_ALIGN_BUFSIZE (1 << 22) /* buffer size alignment */ 521#define AZX_DCAPS_ALIGN_BUFSIZE (1 << 22) /* buffer size alignment */
522#define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23) /* BDLE in 4k boundary */
521 523
522/* quirks for ATI SB / AMD Hudson */ 524/* quirks for ATI SB / AMD Hudson */
523#define AZX_DCAPS_PRESET_ATI_SB \ 525#define AZX_DCAPS_PRESET_ATI_SB \
@@ -533,6 +535,9 @@ enum {
533 (AZX_DCAPS_NVIDIA_SNOOP | AZX_DCAPS_RIRB_DELAY | AZX_DCAPS_NO_MSI |\ 535 (AZX_DCAPS_NVIDIA_SNOOP | AZX_DCAPS_RIRB_DELAY | AZX_DCAPS_NO_MSI |\
534 AZX_DCAPS_ALIGN_BUFSIZE) 536 AZX_DCAPS_ALIGN_BUFSIZE)
535 537
538#define AZX_DCAPS_PRESET_CTHDA \
539 (AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_4K_BDLE_BOUNDARY)
540
536static char *driver_short_names[] __devinitdata = { 541static char *driver_short_names[] __devinitdata = {
537 [AZX_DRIVER_ICH] = "HDA Intel", 542 [AZX_DRIVER_ICH] = "HDA Intel",
538 [AZX_DRIVER_PCH] = "HDA Intel PCH", 543 [AZX_DRIVER_PCH] = "HDA Intel PCH",
@@ -546,6 +551,7 @@ static char *driver_short_names[] __devinitdata = {
546 [AZX_DRIVER_NVIDIA] = "HDA NVidia", 551 [AZX_DRIVER_NVIDIA] = "HDA NVidia",
547 [AZX_DRIVER_TERA] = "HDA Teradici", 552 [AZX_DRIVER_TERA] = "HDA Teradici",
548 [AZX_DRIVER_CTX] = "HDA Creative", 553 [AZX_DRIVER_CTX] = "HDA Creative",
554 [AZX_DRIVER_CTHDA] = "HDA Creative",
549 [AZX_DRIVER_GENERIC] = "HD-Audio Generic", 555 [AZX_DRIVER_GENERIC] = "HD-Audio Generic",
550}; 556};
551 557
@@ -1285,7 +1291,8 @@ static irqreturn_t azx_interrupt(int irq, void *dev_id)
1285/* 1291/*
1286 * set up a BDL entry 1292 * set up a BDL entry
1287 */ 1293 */
1288static int setup_bdle(struct snd_pcm_substream *substream, 1294static int setup_bdle(struct azx *chip,
1295 struct snd_pcm_substream *substream,
1289 struct azx_dev *azx_dev, u32 **bdlp, 1296 struct azx_dev *azx_dev, u32 **bdlp,
1290 int ofs, int size, int with_ioc) 1297 int ofs, int size, int with_ioc)
1291{ 1298{
@@ -1304,6 +1311,12 @@ static int setup_bdle(struct snd_pcm_substream *substream,
1304 bdl[1] = cpu_to_le32(upper_32_bits(addr)); 1311 bdl[1] = cpu_to_le32(upper_32_bits(addr));
1305 /* program the size field of the BDL entry */ 1312 /* program the size field of the BDL entry */
1306 chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size); 1313 chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size);
1314 /* one BDLE cannot cross 4K boundary on CTHDA chips */
1315 if (chip->driver_caps & AZX_DCAPS_4K_BDLE_BOUNDARY) {
1316 u32 remain = 0x1000 - (ofs & 0xfff);
1317 if (chunk > remain)
1318 chunk = remain;
1319 }
1307 bdl[2] = cpu_to_le32(chunk); 1320 bdl[2] = cpu_to_le32(chunk);
1308 /* program the IOC to enable interrupt 1321 /* program the IOC to enable interrupt
1309 * only when the whole fragment is processed 1322 * only when the whole fragment is processed
@@ -1356,7 +1369,7 @@ static int azx_setup_periods(struct azx *chip,
1356 bdl_pos_adj[chip->dev_index]); 1369 bdl_pos_adj[chip->dev_index]);
1357 pos_adj = 0; 1370 pos_adj = 0;
1358 } else { 1371 } else {
1359 ofs = setup_bdle(substream, azx_dev, 1372 ofs = setup_bdle(chip, substream, azx_dev,
1360 &bdl, ofs, pos_adj, 1373 &bdl, ofs, pos_adj,
1361 !substream->runtime->no_period_wakeup); 1374 !substream->runtime->no_period_wakeup);
1362 if (ofs < 0) 1375 if (ofs < 0)
@@ -1366,10 +1379,10 @@ static int azx_setup_periods(struct azx *chip,
1366 pos_adj = 0; 1379 pos_adj = 0;
1367 for (i = 0; i < periods; i++) { 1380 for (i = 0; i < periods; i++) {
1368 if (i == periods - 1 && pos_adj) 1381 if (i == periods - 1 && pos_adj)
1369 ofs = setup_bdle(substream, azx_dev, &bdl, ofs, 1382 ofs = setup_bdle(chip, substream, azx_dev, &bdl, ofs,
1370 period_bytes - pos_adj, 0); 1383 period_bytes - pos_adj, 0);
1371 else 1384 else
1372 ofs = setup_bdle(substream, azx_dev, &bdl, ofs, 1385 ofs = setup_bdle(chip, substream, azx_dev, &bdl, ofs,
1373 period_bytes, 1386 period_bytes,
1374 !substream->runtime->no_period_wakeup); 1387 !substream->runtime->no_period_wakeup);
1375 if (ofs < 0) 1388 if (ofs < 0)
@@ -2353,17 +2366,6 @@ static void azx_power_notify(struct hda_bus *bus)
2353 * power management 2366 * power management
2354 */ 2367 */
2355 2368
2356static int snd_hda_codecs_inuse(struct hda_bus *bus)
2357{
2358 struct hda_codec *codec;
2359
2360 list_for_each_entry(codec, &bus->codec_list, list) {
2361 if (snd_hda_codec_needs_resume(codec))
2362 return 1;
2363 }
2364 return 0;
2365}
2366
2367static int azx_suspend(struct pci_dev *pci, pm_message_t state) 2369static int azx_suspend(struct pci_dev *pci, pm_message_t state)
2368{ 2370{
2369 struct snd_card *card = pci_get_drvdata(pci); 2371 struct snd_card *card = pci_get_drvdata(pci);
@@ -2410,8 +2412,7 @@ static int azx_resume(struct pci_dev *pci)
2410 return -EIO; 2412 return -EIO;
2411 azx_init_pci(chip); 2413 azx_init_pci(chip);
2412 2414
2413 if (snd_hda_codecs_inuse(chip->bus)) 2415 azx_init_chip(chip, 1);
2414 azx_init_chip(chip, 1);
2415 2416
2416 snd_hda_resume(chip->bus); 2417 snd_hda_resume(chip->bus);
2417 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 2418 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
@@ -2565,6 +2566,8 @@ static struct snd_pci_quirk probe_mask_list[] __devinitdata = {
2565 /* forced codec slots */ 2566 /* forced codec slots */
2566 SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103), 2567 SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103),
2567 SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103), 2568 SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103),
2569 /* WinFast VP200 H (Teradici) user reported broken communication */
2570 SND_PCI_QUIRK(0x3a21, 0x040d, "WinFast VP200 H", 0x101),
2568 {} 2571 {}
2569}; 2572};
2570 2573
@@ -3130,6 +3133,11 @@ static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
3130 .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND | 3133 .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND |
3131 AZX_DCAPS_RIRB_PRE_DELAY | AZX_DCAPS_POSFIX_LPIB }, 3134 AZX_DCAPS_RIRB_PRE_DELAY | AZX_DCAPS_POSFIX_LPIB },
3132#endif 3135#endif
3136 /* CTHDA chips */
3137 { PCI_DEVICE(0x1102, 0x0010),
3138 .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
3139 { PCI_DEVICE(0x1102, 0x0012),
3140 .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
3133 /* Vortex86MX */ 3141 /* Vortex86MX */
3134 { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC }, 3142 { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC },
3135 /* VMware HDAudio */ 3143 /* VMware HDAudio */
@@ -3148,7 +3156,7 @@ static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
3148MODULE_DEVICE_TABLE(pci, azx_ids); 3156MODULE_DEVICE_TABLE(pci, azx_ids);
3149 3157
3150/* pci_driver definition */ 3158/* pci_driver definition */
3151static struct pci_driver driver = { 3159static struct pci_driver azx_driver = {
3152 .name = KBUILD_MODNAME, 3160 .name = KBUILD_MODNAME,
3153 .id_table = azx_ids, 3161 .id_table = azx_ids,
3154 .probe = azx_probe, 3162 .probe = azx_probe,
@@ -3159,15 +3167,4 @@ static struct pci_driver driver = {
3159#endif 3167#endif
3160}; 3168};
3161 3169
3162static int __init alsa_card_azx_init(void) 3170module_pci_driver(azx_driver);
3163{
3164 return pci_register_driver(&driver);
3165}
3166
3167static void __exit alsa_card_azx_exit(void)
3168{
3169 pci_unregister_driver(&driver);
3170}
3171
3172module_init(alsa_card_azx_init)
3173module_exit(alsa_card_azx_exit)
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index d68948499fbc..2dd1c113a4c1 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -17,6 +17,7 @@
17#include <sound/jack.h> 17#include <sound/jack.h>
18#include "hda_codec.h" 18#include "hda_codec.h"
19#include "hda_local.h" 19#include "hda_local.h"
20#include "hda_auto_parser.h"
20#include "hda_jack.h" 21#include "hda_jack.h"
21 22
22bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid) 23bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid)
diff --git a/sound/pci/hda/hda_jack.h b/sound/pci/hda/hda_jack.h
index c66655cf413a..8ae52465ec5d 100644
--- a/sound/pci/hda/hda_jack.h
+++ b/sound/pci/hda/hda_jack.h
@@ -12,6 +12,8 @@
12#ifndef __SOUND_HDA_JACK_H 12#ifndef __SOUND_HDA_JACK_H
13#define __SOUND_HDA_JACK_H 13#define __SOUND_HDA_JACK_H
14 14
15struct auto_pin_cfg;
16
15struct hda_jack_tbl { 17struct hda_jack_tbl {
16 hda_nid_t nid; 18 hda_nid_t nid;
17 unsigned char action; /* event action (0 = none) */ 19 unsigned char action; /* event action (0 = none) */
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 0ec9248165bc..9a096a8e0fc5 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -262,6 +262,8 @@ int snd_hda_input_mux_put(struct hda_codec *codec,
262 const struct hda_input_mux *imux, 262 const struct hda_input_mux *imux,
263 struct snd_ctl_elem_value *ucontrol, hda_nid_t nid, 263 struct snd_ctl_elem_value *ucontrol, hda_nid_t nid,
264 unsigned int *cur_val); 264 unsigned int *cur_val);
265int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label,
266 int index, int *type_index_ret);
265 267
266/* 268/*
267 * Channel mode helper 269 * Channel mode helper
@@ -393,72 +395,7 @@ struct hda_bus_unsolicited {
393 struct hda_bus *bus; 395 struct hda_bus *bus;
394}; 396};
395 397
396/* 398/* helper macros to retrieve pin default-config values */
397 * Helper for automatic pin configuration
398 */
399
400enum {
401 AUTO_PIN_MIC,
402 AUTO_PIN_LINE_IN,
403 AUTO_PIN_CD,
404 AUTO_PIN_AUX,
405 AUTO_PIN_LAST
406};
407
408enum {
409 AUTO_PIN_LINE_OUT,
410 AUTO_PIN_SPEAKER_OUT,
411 AUTO_PIN_HP_OUT
412};
413
414#define AUTO_CFG_MAX_OUTS HDA_MAX_OUTS
415#define AUTO_CFG_MAX_INS 8
416
417struct auto_pin_cfg_item {
418 hda_nid_t pin;
419 int type;
420};
421
422struct auto_pin_cfg;
423const char *hda_get_autocfg_input_label(struct hda_codec *codec,
424 const struct auto_pin_cfg *cfg,
425 int input);
426int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
427 const struct auto_pin_cfg *cfg,
428 char *label, int maxlen, int *indexp);
429int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label,
430 int index, int *type_index_ret);
431
432enum {
433 INPUT_PIN_ATTR_UNUSED, /* pin not connected */
434 INPUT_PIN_ATTR_INT, /* internal mic/line-in */
435 INPUT_PIN_ATTR_DOCK, /* docking mic/line-in */
436 INPUT_PIN_ATTR_NORMAL, /* mic/line-in jack */
437 INPUT_PIN_ATTR_FRONT, /* mic/line-in jack in front */
438 INPUT_PIN_ATTR_REAR, /* mic/line-in jack in rear */
439};
440
441int snd_hda_get_input_pin_attr(unsigned int def_conf);
442
443struct auto_pin_cfg {
444 int line_outs;
445 /* sorted in the order of Front/Surr/CLFE/Side */
446 hda_nid_t line_out_pins[AUTO_CFG_MAX_OUTS];
447 int speaker_outs;
448 hda_nid_t speaker_pins[AUTO_CFG_MAX_OUTS];
449 int hp_outs;
450 int line_out_type; /* AUTO_PIN_XXX_OUT */
451 hda_nid_t hp_pins[AUTO_CFG_MAX_OUTS];
452 int num_inputs;
453 struct auto_pin_cfg_item inputs[AUTO_CFG_MAX_INS];
454 int dig_outs;
455 hda_nid_t dig_out_pins[2];
456 hda_nid_t dig_in_pin;
457 hda_nid_t mono_out_pin;
458 int dig_out_type[2]; /* HDA_PCM_TYPE_XXX */
459 int dig_in_type; /* HDA_PCM_TYPE_XXX */
460};
461
462#define get_defcfg_connect(cfg) \ 399#define get_defcfg_connect(cfg) \
463 ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT) 400 ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
464#define get_defcfg_association(cfg) \ 401#define get_defcfg_association(cfg) \
@@ -472,19 +409,6 @@ struct auto_pin_cfg {
472#define get_defcfg_misc(cfg) \ 409#define get_defcfg_misc(cfg) \
473 ((cfg & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT) 410 ((cfg & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT)
474 411
475/* bit-flags for snd_hda_parse_pin_def_config() behavior */
476#define HDA_PINCFG_NO_HP_FIXUP (1 << 0) /* no HP-split */
477#define HDA_PINCFG_NO_LO_FIXUP (1 << 1) /* don't take other outs as LO */
478
479int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
480 struct auto_pin_cfg *cfg,
481 const hda_nid_t *ignore_nids,
482 unsigned int cond_flags);
483
484/* older function */
485#define snd_hda_parse_pin_def_config(codec, cfg, ignore) \
486 snd_hda_parse_pin_defcfg(codec, cfg, ignore, 0)
487
488/* amp values */ 412/* amp values */
489#define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8)) 413#define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8))
490#define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8)) 414#define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8))
@@ -502,6 +426,46 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
502#define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN) 426#define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN)
503#define PIN_HP_AMP (AC_PINCTL_HP_EN) 427#define PIN_HP_AMP (AC_PINCTL_HP_EN)
504 428
429unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin);
430int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
431 unsigned int val, bool cached);
432
433/**
434 * _snd_hda_set_pin_ctl - Set a pin-control value safely
435 * @codec: the codec instance
436 * @pin: the pin NID to set the control
437 * @val: the pin-control value (AC_PINCTL_* bits)
438 *
439 * This function sets the pin-control value to the given pin, but
440 * filters out the invalid pin-control bits when the pin has no such
441 * capabilities. For example, when PIN_HP is passed but the pin has no
442 * HP-drive capability, the HP bit is omitted.
443 *
444 * The function doesn't check the input VREF capability bits, though.
445 * Use snd_hda_get_default_vref() to guess the right value.
446 * Also, this function is only for analog pins, not for HDMI pins.
447 */
448static inline int
449snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, unsigned int val)
450{
451 return _snd_hda_set_pin_ctl(codec, pin, val, false);
452}
453
454/**
455 * snd_hda_set_pin_ctl_cache - Set a pin-control value safely
456 * @codec: the codec instance
457 * @pin: the pin NID to set the control
458 * @val: the pin-control value (AC_PINCTL_* bits)
459 *
460 * Just like snd_hda_set_pin_ctl() but write to cache as well.
461 */
462static inline int
463snd_hda_set_pin_ctl_cache(struct hda_codec *codec, hda_nid_t pin,
464 unsigned int val)
465{
466 return _snd_hda_set_pin_ctl(codec, pin, val, true);
467}
468
505/* 469/*
506 * get widget capabilities 470 * get widget capabilities
507 */ 471 */
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 7143393927da..d8b2d6dee986 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -28,6 +28,7 @@
28#include <sound/core.h> 28#include <sound/core.h>
29#include "hda_codec.h" 29#include "hda_codec.h"
30#include "hda_local.h" 30#include "hda_local.h"
31#include "hda_auto_parser.h"
31#include "hda_beep.h" 32#include "hda_beep.h"
32#include "hda_jack.h" 33#include "hda_jack.h"
33 34
@@ -1742,9 +1743,7 @@ static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1742 if (! ad198x_eapd_put(kcontrol, ucontrol)) 1743 if (! ad198x_eapd_put(kcontrol, ucontrol))
1743 return 0; 1744 return 0;
1744 /* change speaker pin appropriately */ 1745 /* change speaker pin appropriately */
1745 snd_hda_codec_write(codec, 0x05, 0, 1746 snd_hda_set_pin_ctl(codec, 0x05, spec->cur_eapd ? PIN_OUT : 0);
1746 AC_VERB_SET_PIN_WIDGET_CONTROL,
1747 spec->cur_eapd ? PIN_OUT : 0);
1748 /* toggle HP mute appropriately */ 1747 /* toggle HP mute appropriately */
1749 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0, 1748 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1750 HDA_AMP_MUTE, 1749 HDA_AMP_MUTE,
@@ -3103,7 +3102,7 @@ static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
3103 int dac_idx) 3102 int dac_idx)
3104{ 3103{
3105 /* set as output */ 3104 /* set as output */
3106 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type); 3105 snd_hda_set_pin_ctl(codec, nid, pin_type);
3107 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); 3106 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
3108 switch (nid) { 3107 switch (nid) {
3109 case 0x11: /* port-A - DAC 03 */ 3108 case 0x11: /* port-A - DAC 03 */
@@ -3157,6 +3156,7 @@ static void ad1988_auto_init_analog_input(struct hda_codec *codec)
3157 for (i = 0; i < cfg->num_inputs; i++) { 3156 for (i = 0; i < cfg->num_inputs; i++) {
3158 hda_nid_t nid = cfg->inputs[i].pin; 3157 hda_nid_t nid = cfg->inputs[i].pin;
3159 int type = cfg->inputs[i].type; 3158 int type = cfg->inputs[i].type;
3159 int val;
3160 switch (nid) { 3160 switch (nid) {
3161 case 0x15: /* port-C */ 3161 case 0x15: /* port-C */
3162 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0); 3162 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
@@ -3165,8 +3165,10 @@ static void ad1988_auto_init_analog_input(struct hda_codec *codec)
3165 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0); 3165 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
3166 break; 3166 break;
3167 } 3167 }
3168 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 3168 val = PIN_IN;
3169 type == AUTO_PIN_MIC ? PIN_VREF80 : PIN_IN); 3169 if (type == AUTO_PIN_MIC)
3170 val |= snd_hda_get_default_vref(codec, nid);
3171 snd_hda_set_pin_ctl(codec, nid, val);
3170 if (nid != AD1988_PIN_CD_NID) 3172 if (nid != AD1988_PIN_CD_NID)
3171 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 3173 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3172 AMP_OUT_MUTE); 3174 AMP_OUT_MUTE);
diff --git a/sound/pci/hda/patch_ca0110.c b/sound/pci/hda/patch_ca0110.c
index 09ccfabb4a17..19ae14f739cb 100644
--- a/sound/pci/hda/patch_ca0110.c
+++ b/sound/pci/hda/patch_ca0110.c
@@ -26,6 +26,7 @@
26#include <sound/core.h> 26#include <sound/core.h>
27#include "hda_codec.h" 27#include "hda_codec.h"
28#include "hda_local.h" 28#include "hda_local.h"
29#include "hda_auto_parser.h"
29 30
30/* 31/*
31 */ 32 */
@@ -341,8 +342,7 @@ static int ca0110_build_pcms(struct hda_codec *codec)
341static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac) 342static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
342{ 343{
343 if (pin) { 344 if (pin) {
344 snd_hda_codec_write(codec, pin, 0, 345 snd_hda_set_pin_ctl(codec, pin, PIN_HP);
345 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
346 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP) 346 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
347 snd_hda_codec_write(codec, pin, 0, 347 snd_hda_codec_write(codec, pin, 0,
348 AC_VERB_SET_AMP_GAIN_MUTE, 348 AC_VERB_SET_AMP_GAIN_MUTE,
@@ -356,8 +356,8 @@ static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
356static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc) 356static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
357{ 357{
358 if (pin) { 358 if (pin) {
359 snd_hda_codec_write(codec, pin, 0, 359 snd_hda_set_pin_ctl(codec, pin, PIN_IN |
360 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80); 360 snd_hda_get_default_vref(codec, pin));
361 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP) 361 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
362 snd_hda_codec_write(codec, pin, 0, 362 snd_hda_codec_write(codec, pin, 0,
363 AC_VERB_SET_AMP_GAIN_MUTE, 363 AC_VERB_SET_AMP_GAIN_MUTE,
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index 21d91d580da8..d0d3540e39e7 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -30,6 +30,7 @@
30#include <sound/core.h> 30#include <sound/core.h>
31#include "hda_codec.h" 31#include "hda_codec.h"
32#include "hda_local.h" 32#include "hda_local.h"
33#include "hda_auto_parser.h"
33 34
34#define WIDGET_CHIP_CTRL 0x15 35#define WIDGET_CHIP_CTRL 0x15
35#define WIDGET_DSP_CTRL 0x16 36#define WIDGET_DSP_CTRL 0x16
@@ -239,8 +240,7 @@ enum get_set {
239static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac) 240static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
240{ 241{
241 if (pin) { 242 if (pin) {
242 snd_hda_codec_write(codec, pin, 0, 243 snd_hda_set_pin_ctl(codec, pin, PIN_HP);
243 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
244 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP) 244 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
245 snd_hda_codec_write(codec, pin, 0, 245 snd_hda_codec_write(codec, pin, 0,
246 AC_VERB_SET_AMP_GAIN_MUTE, 246 AC_VERB_SET_AMP_GAIN_MUTE,
@@ -254,9 +254,8 @@ static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
254static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc) 254static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
255{ 255{
256 if (pin) { 256 if (pin) {
257 snd_hda_codec_write(codec, pin, 0, 257 snd_hda_set_pin_ctl(codec, pin, PIN_IN |
258 AC_VERB_SET_PIN_WIDGET_CONTROL, 258 snd_hda_get_default_vref(codec, pin));
259 PIN_VREF80);
260 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP) 259 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
261 snd_hda_codec_write(codec, pin, 0, 260 snd_hda_codec_write(codec, pin, 0,
262 AC_VERB_SET_AMP_GAIN_MUTE, 261 AC_VERB_SET_AMP_GAIN_MUTE,
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index c83ccdba1e5a..9647ed4d7929 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -26,6 +26,7 @@
26#include <sound/core.h> 26#include <sound/core.h>
27#include "hda_codec.h" 27#include "hda_codec.h"
28#include "hda_local.h" 28#include "hda_local.h"
29#include "hda_auto_parser.h"
29#include "hda_jack.h" 30#include "hda_jack.h"
30#include <sound/tlv.h> 31#include <sound/tlv.h>
31 32
@@ -933,8 +934,7 @@ static void cs_automute(struct hda_codec *codec)
933 pin_ctl = 0; 934 pin_ctl = 0;
934 935
935 nid = cfg->speaker_pins[i]; 936 nid = cfg->speaker_pins[i];
936 snd_hda_codec_write(codec, nid, 0, 937 snd_hda_set_pin_ctl(codec, nid, pin_ctl);
937 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_ctl);
938 } 938 }
939 if (spec->gpio_eapd_hp) { 939 if (spec->gpio_eapd_hp) {
940 unsigned int gpio = hp_present ? 940 unsigned int gpio = hp_present ?
@@ -948,16 +948,14 @@ static void cs_automute(struct hda_codec *codec)
948 /* mute HPs if spdif jack (SENSE_B) is present */ 948 /* mute HPs if spdif jack (SENSE_B) is present */
949 for (i = 0; i < cfg->hp_outs; i++) { 949 for (i = 0; i < cfg->hp_outs; i++) {
950 nid = cfg->hp_pins[i]; 950 nid = cfg->hp_pins[i];
951 snd_hda_codec_write(codec, nid, 0, 951 snd_hda_set_pin_ctl(codec, nid,
952 AC_VERB_SET_PIN_WIDGET_CONTROL,
953 (spdif_present && spec->sense_b) ? 0 : PIN_HP); 952 (spdif_present && spec->sense_b) ? 0 : PIN_HP);
954 } 953 }
955 954
956 /* SPDIF TX on/off */ 955 /* SPDIF TX on/off */
957 if (cfg->dig_outs) { 956 if (cfg->dig_outs) {
958 nid = cfg->dig_out_pins[0]; 957 nid = cfg->dig_out_pins[0];
959 snd_hda_codec_write(codec, nid, 0, 958 snd_hda_set_pin_ctl(codec, nid,
960 AC_VERB_SET_PIN_WIDGET_CONTROL,
961 spdif_present ? PIN_OUT : 0); 959 spdif_present ? PIN_OUT : 0);
962 960
963 } 961 }
@@ -1024,13 +1022,11 @@ static void init_output(struct hda_codec *codec)
1024 1022
1025 /* set appropriate pin controls */ 1023 /* set appropriate pin controls */
1026 for (i = 0; i < cfg->line_outs; i++) 1024 for (i = 0; i < cfg->line_outs; i++)
1027 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, 1025 snd_hda_set_pin_ctl(codec, cfg->line_out_pins[i], PIN_OUT);
1028 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1029 /* HP */ 1026 /* HP */
1030 for (i = 0; i < cfg->hp_outs; i++) { 1027 for (i = 0; i < cfg->hp_outs; i++) {
1031 hda_nid_t nid = cfg->hp_pins[i]; 1028 hda_nid_t nid = cfg->hp_pins[i];
1032 snd_hda_codec_write(codec, nid, 0, 1029 snd_hda_set_pin_ctl(codec, nid, PIN_HP);
1033 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
1034 if (!cfg->speaker_outs) 1030 if (!cfg->speaker_outs)
1035 continue; 1031 continue;
1036 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { 1032 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
@@ -1041,8 +1037,7 @@ static void init_output(struct hda_codec *codec)
1041 1037
1042 /* Speaker */ 1038 /* Speaker */
1043 for (i = 0; i < cfg->speaker_outs; i++) 1039 for (i = 0; i < cfg->speaker_outs; i++)
1044 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0, 1040 snd_hda_set_pin_ctl(codec, cfg->speaker_pins[i], PIN_OUT);
1045 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1046 1041
1047 /* SPDIF is enabled on presence detect for CS421x */ 1042 /* SPDIF is enabled on presence detect for CS421x */
1048 if (spec->hp_detect || spec->spdif_detect) 1043 if (spec->hp_detect || spec->spdif_detect)
@@ -1063,14 +1058,9 @@ static void init_input(struct hda_codec *codec)
1063 continue; 1058 continue;
1064 /* set appropriate pin control and mute first */ 1059 /* set appropriate pin control and mute first */
1065 ctl = PIN_IN; 1060 ctl = PIN_IN;
1066 if (cfg->inputs[i].type == AUTO_PIN_MIC) { 1061 if (cfg->inputs[i].type == AUTO_PIN_MIC)
1067 unsigned int caps = snd_hda_query_pin_caps(codec, pin); 1062 ctl |= snd_hda_get_default_vref(codec, pin);
1068 caps >>= AC_PINCAP_VREF_SHIFT; 1063 snd_hda_set_pin_ctl(codec, pin, ctl);
1069 if (caps & AC_PINCAP_VREF_80)
1070 ctl = PIN_VREF80;
1071 }
1072 snd_hda_codec_write(codec, pin, 0,
1073 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
1074 snd_hda_codec_write(codec, spec->adc_nid[i], 0, 1064 snd_hda_codec_write(codec, spec->adc_nid[i], 0,
1075 AC_VERB_SET_AMP_GAIN_MUTE, 1065 AC_VERB_SET_AMP_GAIN_MUTE,
1076 AMP_IN_MUTE(spec->adc_idx[i])); 1066 AMP_IN_MUTE(spec->adc_idx[i]));
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index b6767b4ced44..c8fdaaefe702 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -29,6 +29,7 @@
29#include <sound/core.h> 29#include <sound/core.h>
30#include "hda_codec.h" 30#include "hda_codec.h"
31#include "hda_local.h" 31#include "hda_local.h"
32#include "hda_auto_parser.h"
32#define NUM_PINS 11 33#define NUM_PINS 11
33 34
34 35
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index d906c5b74cf0..3acb5824ad39 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -30,6 +30,7 @@
30 30
31#include "hda_codec.h" 31#include "hda_codec.h"
32#include "hda_local.h" 32#include "hda_local.h"
33#include "hda_auto_parser.h"
33#include "hda_beep.h" 34#include "hda_beep.h"
34#include "hda_jack.h" 35#include "hda_jack.h"
35 36
@@ -66,6 +67,7 @@ struct imux_info {
66}; 67};
67 68
68struct conexant_spec { 69struct conexant_spec {
70 struct hda_gen_spec gen;
69 71
70 const struct snd_kcontrol_new *mixers[5]; 72 const struct snd_kcontrol_new *mixers[5];
71 int num_mixers; 73 int num_mixers;
@@ -141,6 +143,7 @@ struct conexant_spec {
141 unsigned int hp_laptop:1; 143 unsigned int hp_laptop:1;
142 unsigned int asus:1; 144 unsigned int asus:1;
143 unsigned int pin_eapd_ctrls:1; 145 unsigned int pin_eapd_ctrls:1;
146 unsigned int fixup_stereo_dmic:1;
144 147
145 unsigned int adc_switching:1; 148 unsigned int adc_switching:1;
146 149
@@ -1601,17 +1604,13 @@ static void cxt5051_update_speaker(struct hda_codec *codec)
1601 unsigned int pinctl; 1604 unsigned int pinctl;
1602 /* headphone pin */ 1605 /* headphone pin */
1603 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; 1606 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1604 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1607 snd_hda_set_pin_ctl(codec, 0x16, pinctl);
1605 pinctl);
1606 /* speaker pin */ 1608 /* speaker pin */
1607 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1609 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1608 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1610 snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
1609 pinctl);
1610 /* on ideapad there is an additional speaker (subwoofer) to mute */ 1611 /* on ideapad there is an additional speaker (subwoofer) to mute */
1611 if (spec->ideapad) 1612 if (spec->ideapad)
1612 snd_hda_codec_write(codec, 0x1b, 0, 1613 snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
1613 AC_VERB_SET_PIN_WIDGET_CONTROL,
1614 pinctl);
1615} 1614}
1616 1615
1617/* turn on/off EAPD (+ mute HP) as a master switch */ 1616/* turn on/off EAPD (+ mute HP) as a master switch */
@@ -1996,8 +1995,7 @@ static void cxt5066_update_speaker(struct hda_codec *codec)
1996 1995
1997 /* Port A (HP) */ 1996 /* Port A (HP) */
1998 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; 1997 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
1999 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1998 snd_hda_set_pin_ctl(codec, 0x19, pinctl);
2000 pinctl);
2001 1999
2002 /* Port D (HP/LO) */ 2000 /* Port D (HP/LO) */
2003 pinctl = spec->cur_eapd ? spec->port_d_mode : 0; 2001 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
@@ -2010,13 +2008,11 @@ static void cxt5066_update_speaker(struct hda_codec *codec)
2010 if (!hp_port_d_present(spec)) 2008 if (!hp_port_d_present(spec))
2011 pinctl = 0; 2009 pinctl = 0;
2012 } 2010 }
2013 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 2011 snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
2014 pinctl);
2015 2012
2016 /* CLASS_D AMP */ 2013 /* CLASS_D AMP */
2017 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 2014 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2018 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 2015 snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
2019 pinctl);
2020} 2016}
2021 2017
2022/* turn on/off EAPD (+ mute HP) as a master switch */ 2018/* turn on/off EAPD (+ mute HP) as a master switch */
@@ -2047,8 +2043,7 @@ static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2047 /* Even though port F is the DC input, the bias is controlled on port B. 2043 /* Even though port F is the DC input, the bias is controlled on port B.
2048 * we also leave that port as an active input (but unselected) in DC mode 2044 * we also leave that port as an active input (but unselected) in DC mode
2049 * just in case that is necessary to make the bias setting take effect. */ 2045 * just in case that is necessary to make the bias setting take effect. */
2050 return snd_hda_codec_write_cache(codec, 0x1a, 0, 2046 return snd_hda_set_pin_ctl_cache(codec, 0x1a,
2051 AC_VERB_SET_PIN_WIDGET_CONTROL,
2052 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2047 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2053} 2048}
2054 2049
@@ -2081,14 +2076,14 @@ static void cxt5066_olpc_select_mic(struct hda_codec *codec)
2081 } 2076 }
2082 2077
2083 /* disable DC (port F) */ 2078 /* disable DC (port F) */
2084 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); 2079 snd_hda_set_pin_ctl(codec, 0x1e, 0);
2085 2080
2086 /* external mic, port B */ 2081 /* external mic, port B */
2087 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 2082 snd_hda_set_pin_ctl(codec, 0x1a,
2088 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 2083 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
2089 2084
2090 /* internal mic, port C */ 2085 /* internal mic, port C */
2091 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 2086 snd_hda_set_pin_ctl(codec, 0x1b,
2092 spec->ext_mic_present ? 0 : PIN_VREF80); 2087 spec->ext_mic_present ? 0 : PIN_VREF80);
2093} 2088}
2094 2089
@@ -3357,9 +3352,7 @@ static void do_automute(struct hda_codec *codec, int num_pins,
3357 struct conexant_spec *spec = codec->spec; 3352 struct conexant_spec *spec = codec->spec;
3358 int i; 3353 int i;
3359 for (i = 0; i < num_pins; i++) 3354 for (i = 0; i < num_pins; i++)
3360 snd_hda_codec_write(codec, pins[i], 0, 3355 snd_hda_set_pin_ctl(codec, pins[i], on ? PIN_OUT : 0);
3361 AC_VERB_SET_PIN_WIDGET_CONTROL,
3362 on ? PIN_OUT : 0);
3363 if (spec->pin_eapd_ctrls) 3356 if (spec->pin_eapd_ctrls)
3364 cx_auto_turn_eapd(codec, num_pins, pins, on); 3357 cx_auto_turn_eapd(codec, num_pins, pins, on);
3365} 3358}
@@ -3976,8 +3969,7 @@ static void cx_auto_init_output(struct hda_codec *codec)
3976 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) & 3969 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) &
3977 AC_PINCAP_HP_DRV) 3970 AC_PINCAP_HP_DRV)
3978 val |= AC_PINCTL_HP_EN; 3971 val |= AC_PINCTL_HP_EN;
3979 snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 3972 snd_hda_set_pin_ctl(codec, cfg->hp_pins[i], val);
3980 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
3981 } 3973 }
3982 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); 3974 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3983 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); 3975 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
@@ -4030,13 +4022,11 @@ static void cx_auto_init_input(struct hda_codec *codec)
4030 } 4022 }
4031 4023
4032 for (i = 0; i < cfg->num_inputs; i++) { 4024 for (i = 0; i < cfg->num_inputs; i++) {
4033 unsigned int type; 4025 hda_nid_t pin = cfg->inputs[i].pin;
4026 unsigned int type = PIN_IN;
4034 if (cfg->inputs[i].type == AUTO_PIN_MIC) 4027 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4035 type = PIN_VREF80; 4028 type |= snd_hda_get_default_vref(codec, pin);
4036 else 4029 snd_hda_set_pin_ctl(codec, pin, type);
4037 type = PIN_IN;
4038 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4039 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4040 } 4030 }
4041 4031
4042 if (spec->auto_mic) { 4032 if (spec->auto_mic) {
@@ -4063,11 +4053,9 @@ static void cx_auto_init_digital(struct hda_codec *codec)
4063 struct auto_pin_cfg *cfg = &spec->autocfg; 4053 struct auto_pin_cfg *cfg = &spec->autocfg;
4064 4054
4065 if (spec->multiout.dig_out_nid) 4055 if (spec->multiout.dig_out_nid)
4066 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, 4056 snd_hda_set_pin_ctl(codec, cfg->dig_out_pins[0], PIN_OUT);
4067 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4068 if (spec->dig_in_nid) 4057 if (spec->dig_in_nid)
4069 snd_hda_codec_write(codec, cfg->dig_in_pin, 0, 4058 snd_hda_set_pin_ctl(codec, cfg->dig_in_pin, PIN_IN);
4070 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
4071} 4059}
4072 4060
4073static int cx_auto_init(struct hda_codec *codec) 4061static int cx_auto_init(struct hda_codec *codec)
@@ -4084,9 +4072,9 @@ static int cx_auto_init(struct hda_codec *codec)
4084 4072
4085static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, 4073static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
4086 const char *dir, int cidx, 4074 const char *dir, int cidx,
4087 hda_nid_t nid, int hda_dir, int amp_idx) 4075 hda_nid_t nid, int hda_dir, int amp_idx, int chs)
4088{ 4076{
4089 static char name[32]; 4077 static char name[44];
4090 static struct snd_kcontrol_new knew[] = { 4078 static struct snd_kcontrol_new knew[] = {
4091 HDA_CODEC_VOLUME(name, 0, 0, 0), 4079 HDA_CODEC_VOLUME(name, 0, 0, 0),
4092 HDA_CODEC_MUTE(name, 0, 0, 0), 4080 HDA_CODEC_MUTE(name, 0, 0, 0),
@@ -4096,7 +4084,7 @@ static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
4096 4084
4097 for (i = 0; i < 2; i++) { 4085 for (i = 0; i < 2; i++) {
4098 struct snd_kcontrol *kctl; 4086 struct snd_kcontrol *kctl;
4099 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx, 4087 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx,
4100 hda_dir); 4088 hda_dir);
4101 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; 4089 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4102 knew[i].index = cidx; 4090 knew[i].index = cidx;
@@ -4115,7 +4103,7 @@ static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
4115} 4103}
4116 4104
4117#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ 4105#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
4118 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0) 4106 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3)
4119 4107
4120#define cx_auto_add_pb_volume(codec, nid, str, idx) \ 4108#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4121 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) 4109 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
@@ -4185,6 +4173,36 @@ static int cx_auto_build_output_controls(struct hda_codec *codec)
4185 return 0; 4173 return 0;
4186} 4174}
4187 4175
4176/* Returns zero if this is a normal stereo channel, and non-zero if it should
4177 be split in two independent channels.
4178 dest_label must be at least 44 characters. */
4179static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label,
4180 char *dest_label, int nid)
4181{
4182 struct conexant_spec *spec = codec->spec;
4183 int i;
4184
4185 if (!spec->fixup_stereo_dmic)
4186 return 0;
4187
4188 for (i = 0; i < AUTO_CFG_MAX_INS; i++) {
4189 int def_conf;
4190 if (spec->autocfg.inputs[i].pin != nid)
4191 continue;
4192
4193 if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC)
4194 return 0;
4195 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4196 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT)
4197 return 0;
4198
4199 /* Finally found the inverted internal mic! */
4200 snprintf(dest_label, 44, "Inverted %s", label);
4201 return 1;
4202 }
4203 return 0;
4204}
4205
4188static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, 4206static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4189 const char *label, const char *pfx, 4207 const char *label, const char *pfx,
4190 int cidx) 4208 int cidx)
@@ -4193,14 +4211,25 @@ static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4193 int i; 4211 int i;
4194 4212
4195 for (i = 0; i < spec->num_adc_nids; i++) { 4213 for (i = 0; i < spec->num_adc_nids; i++) {
4214 char rightch_label[44];
4196 hda_nid_t adc_nid = spec->adc_nids[i]; 4215 hda_nid_t adc_nid = spec->adc_nids[i];
4197 int idx = get_input_connection(codec, adc_nid, nid); 4216 int idx = get_input_connection(codec, adc_nid, nid);
4198 if (idx < 0) 4217 if (idx < 0)
4199 continue; 4218 continue;
4200 if (codec->single_adc_amp) 4219 if (codec->single_adc_amp)
4201 idx = 0; 4220 idx = 0;
4221
4222 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4223 /* Make two independent kcontrols for left and right */
4224 int err = cx_auto_add_volume_idx(codec, label, pfx,
4225 cidx, adc_nid, HDA_INPUT, idx, 1);
4226 if (err < 0)
4227 return err;
4228 return cx_auto_add_volume_idx(codec, rightch_label, pfx,
4229 cidx, adc_nid, HDA_INPUT, idx, 2);
4230 }
4202 return cx_auto_add_volume_idx(codec, label, pfx, 4231 return cx_auto_add_volume_idx(codec, label, pfx,
4203 cidx, adc_nid, HDA_INPUT, idx); 4232 cidx, adc_nid, HDA_INPUT, idx, 3);
4204 } 4233 }
4205 return 0; 4234 return 0;
4206} 4235}
@@ -4213,9 +4242,19 @@ static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4213 int i, con; 4242 int i, con;
4214 4243
4215 nid = spec->imux_info[idx].pin; 4244 nid = spec->imux_info[idx].pin;
4216 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) 4245 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4246 char rightch_label[44];
4247 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4248 int err = cx_auto_add_volume_idx(codec, label, " Boost",
4249 cidx, nid, HDA_INPUT, 0, 1);
4250 if (err < 0)
4251 return err;
4252 return cx_auto_add_volume_idx(codec, rightch_label, " Boost",
4253 cidx, nid, HDA_INPUT, 0, 2);
4254 }
4217 return cx_auto_add_volume(codec, label, " Boost", cidx, 4255 return cx_auto_add_volume(codec, label, " Boost", cidx,
4218 nid, HDA_INPUT); 4256 nid, HDA_INPUT);
4257 }
4219 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid, 4258 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4220 &mux, false, 0); 4259 &mux, false, 0);
4221 if (con < 0) 4260 if (con < 0)
@@ -4370,37 +4409,21 @@ static const struct hda_codec_ops cx_auto_patch_ops = {
4370/* 4409/*
4371 * pin fix-up 4410 * pin fix-up
4372 */ 4411 */
4373struct cxt_pincfg {
4374 hda_nid_t nid;
4375 u32 val;
4376};
4377
4378static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg)
4379{
4380 for (; cfg->nid; cfg++)
4381 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
4382
4383}
4384
4385static void apply_pin_fixup(struct hda_codec *codec,
4386 const struct snd_pci_quirk *quirk,
4387 const struct cxt_pincfg **table)
4388{
4389 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
4390 if (quirk) {
4391 snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n",
4392 quirk->name);
4393 apply_pincfg(codec, table[quirk->value]);
4394 }
4395}
4396
4397enum { 4412enum {
4398 CXT_PINCFG_LENOVO_X200, 4413 CXT_PINCFG_LENOVO_X200,
4399 CXT_PINCFG_LENOVO_TP410, 4414 CXT_PINCFG_LENOVO_TP410,
4415 CXT_FIXUP_STEREO_DMIC,
4400}; 4416};
4401 4417
4418static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
4419 const struct hda_fixup *fix, int action)
4420{
4421 struct conexant_spec *spec = codec->spec;
4422 spec->fixup_stereo_dmic = 1;
4423}
4424
4402/* ThinkPad X200 & co with cxt5051 */ 4425/* ThinkPad X200 & co with cxt5051 */
4403static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = { 4426static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
4404 { 0x16, 0x042140ff }, /* HP (seq# overridden) */ 4427 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4405 { 0x17, 0x21a11000 }, /* dock-mic */ 4428 { 0x17, 0x21a11000 }, /* dock-mic */
4406 { 0x19, 0x2121103f }, /* dock-HP */ 4429 { 0x19, 0x2121103f }, /* dock-HP */
@@ -4409,16 +4432,26 @@ static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = {
4409}; 4432};
4410 4433
4411/* ThinkPad 410/420/510/520, X201 & co with cxt5066 */ 4434/* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
4412static const struct cxt_pincfg cxt_pincfg_lenovo_tp410[] = { 4435static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
4413 { 0x19, 0x042110ff }, /* HP (seq# overridden) */ 4436 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
4414 { 0x1a, 0x21a190f0 }, /* dock-mic */ 4437 { 0x1a, 0x21a190f0 }, /* dock-mic */
4415 { 0x1c, 0x212140ff }, /* dock-HP */ 4438 { 0x1c, 0x212140ff }, /* dock-HP */
4416 {} 4439 {}
4417}; 4440};
4418 4441
4419static const struct cxt_pincfg *cxt_pincfg_tbl[] = { 4442static const struct hda_fixup cxt_fixups[] = {
4420 [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200, 4443 [CXT_PINCFG_LENOVO_X200] = {
4421 [CXT_PINCFG_LENOVO_TP410] = cxt_pincfg_lenovo_tp410, 4444 .type = HDA_FIXUP_PINS,
4445 .v.pins = cxt_pincfg_lenovo_x200,
4446 },
4447 [CXT_PINCFG_LENOVO_TP410] = {
4448 .type = HDA_FIXUP_PINS,
4449 .v.pins = cxt_pincfg_lenovo_tp410,
4450 },
4451 [CXT_FIXUP_STEREO_DMIC] = {
4452 .type = HDA_FIXUP_FUNC,
4453 .v.func = cxt_fixup_stereo_dmic,
4454 },
4422}; 4455};
4423 4456
4424static const struct snd_pci_quirk cxt5051_fixups[] = { 4457static const struct snd_pci_quirk cxt5051_fixups[] = {
@@ -4432,6 +4465,7 @@ static const struct snd_pci_quirk cxt5066_fixups[] = {
4432 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410), 4465 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
4433 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410), 4466 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
4434 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410), 4467 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
4468 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
4435 {} 4469 {}
4436}; 4470};
4437 4471
@@ -4471,13 +4505,16 @@ static int patch_conexant_auto(struct hda_codec *codec)
4471 case 0x14f15051: 4505 case 0x14f15051:
4472 add_cx5051_fake_mutes(codec); 4506 add_cx5051_fake_mutes(codec);
4473 codec->pin_amp_workaround = 1; 4507 codec->pin_amp_workaround = 1;
4474 apply_pin_fixup(codec, cxt5051_fixups, cxt_pincfg_tbl); 4508 snd_hda_pick_fixup(codec, NULL, cxt5051_fixups, cxt_fixups);
4475 break; 4509 break;
4476 default: 4510 default:
4477 codec->pin_amp_workaround = 1; 4511 codec->pin_amp_workaround = 1;
4478 apply_pin_fixup(codec, cxt5066_fixups, cxt_pincfg_tbl); 4512 snd_hda_pick_fixup(codec, NULL, cxt5066_fixups, cxt_fixups);
4513 break;
4479 } 4514 }
4480 4515
4516 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4517
4481 /* Show mute-led control only on HP laptops 4518 /* Show mute-led control only on HP laptops
4482 * This is a sort of white-list: on HP laptops, EAPD corresponds 4519 * This is a sort of white-list: on HP laptops, EAPD corresponds
4483 * only to the mute-LED without actualy amp function. Meanwhile, 4520 * only to the mute-LED without actualy amp function. Meanwhile,
@@ -4556,6 +4593,12 @@ static const struct hda_codec_preset snd_hda_preset_conexant[] = {
4556 .patch = patch_conexant_auto }, 4593 .patch = patch_conexant_auto },
4557 { .id = 0x14f150b9, .name = "CX20665", 4594 { .id = 0x14f150b9, .name = "CX20665",
4558 .patch = patch_conexant_auto }, 4595 .patch = patch_conexant_auto },
4596 { .id = 0x14f1510f, .name = "CX20751/2",
4597 .patch = patch_conexant_auto },
4598 { .id = 0x14f15110, .name = "CX20751/2",
4599 .patch = patch_conexant_auto },
4600 { .id = 0x14f15111, .name = "CX20753/4",
4601 .patch = patch_conexant_auto },
4559 {} /* terminator */ 4602 {} /* terminator */
4560}; 4603};
4561 4604
@@ -4576,6 +4619,9 @@ MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4576MODULE_ALIAS("snd-hda-codec-id:14f150ac"); 4619MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4577MODULE_ALIAS("snd-hda-codec-id:14f150b8"); 4620MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4578MODULE_ALIAS("snd-hda-codec-id:14f150b9"); 4621MODULE_ALIAS("snd-hda-codec-id:14f150b9");
4622MODULE_ALIAS("snd-hda-codec-id:14f1510f");
4623MODULE_ALIAS("snd-hda-codec-id:14f15110");
4624MODULE_ALIAS("snd-hda-codec-id:14f15111");
4579 4625
4580MODULE_LICENSE("GPL"); 4626MODULE_LICENSE("GPL");
4581MODULE_DESCRIPTION("Conexant HD-audio codec"); 4627MODULE_DESCRIPTION("Conexant HD-audio codec");
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index 83f345f3c961..ad319d4dc32f 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -1592,10 +1592,10 @@ static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
1592 unsigned int dataDCC2, channel_id; 1592 unsigned int dataDCC2, channel_id;
1593 int i; 1593 int i;
1594 struct hdmi_spec *spec = codec->spec; 1594 struct hdmi_spec *spec = codec->spec;
1595 struct hda_spdif_out *spdif = 1595 struct hda_spdif_out *spdif;
1596 snd_hda_spdif_out_of_nid(codec, spec->cvts[0].cvt_nid);
1597 1596
1598 mutex_lock(&codec->spdif_mutex); 1597 mutex_lock(&codec->spdif_mutex);
1598 spdif = snd_hda_spdif_out_of_nid(codec, spec->cvts[0].cvt_nid);
1599 1599
1600 chs = substream->runtime->channels; 1600 chs = substream->runtime->channels;
1601 1601
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 708d47c294ee..ff71dcef08ef 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -32,6 +32,7 @@
32#include <sound/jack.h> 32#include <sound/jack.h>
33#include "hda_codec.h" 33#include "hda_codec.h"
34#include "hda_local.h" 34#include "hda_local.h"
35#include "hda_auto_parser.h"
35#include "hda_beep.h" 36#include "hda_beep.h"
36#include "hda_jack.h" 37#include "hda_jack.h"
37 38
@@ -66,8 +67,6 @@ struct alc_customize_define {
66 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */ 67 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
67}; 68};
68 69
69struct alc_fixup;
70
71struct alc_multi_io { 70struct alc_multi_io {
72 hda_nid_t pin; /* multi-io widget pin NID */ 71 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */ 72 hda_nid_t dac; /* DAC to be connected */
@@ -82,19 +81,33 @@ enum {
82 81
83#define MAX_VOL_NIDS 0x40 82#define MAX_VOL_NIDS 0x40
84 83
84/* make compatible with old code */
85#define alc_apply_pincfgs snd_hda_apply_pincfgs
86#define alc_apply_fixup snd_hda_apply_fixup
87#define alc_pick_fixup snd_hda_pick_fixup
88#define alc_fixup hda_fixup
89#define alc_pincfg hda_pintbl
90#define alc_model_fixup hda_model_fixup
91
92#define ALC_FIXUP_PINS HDA_FIXUP_PINS
93#define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
94#define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
95
96#define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
97#define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
98#define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
99#define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
100
101
85struct alc_spec { 102struct alc_spec {
103 struct hda_gen_spec gen;
104
86 /* codec parameterization */ 105 /* codec parameterization */
87 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ 106 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
88 unsigned int num_mixers; 107 unsigned int num_mixers;
89 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */ 108 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
90 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ 109 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
91 110
92 const struct hda_verb *init_verbs[10]; /* initialization verbs
93 * don't forget NULL
94 * termination!
95 */
96 unsigned int num_init_verbs;
97
98 char stream_name_analog[32]; /* analog PCM stream */ 111 char stream_name_analog[32]; /* analog PCM stream */
99 const struct hda_pcm_stream *stream_analog_playback; 112 const struct hda_pcm_stream *stream_analog_playback;
100 const struct hda_pcm_stream *stream_analog_capture; 113 const struct hda_pcm_stream *stream_analog_capture;
@@ -210,11 +223,6 @@ struct alc_spec {
210 unsigned int pll_coef_idx, pll_coef_bit; 223 unsigned int pll_coef_idx, pll_coef_bit;
211 unsigned int coef0; 224 unsigned int coef0;
212 225
213 /* fix-up list */
214 int fixup_id;
215 const struct alc_fixup *fixup_list;
216 const char *fixup_name;
217
218 /* multi-io */ 226 /* multi-io */
219 int multi_ios; 227 int multi_ios;
220 struct alc_multi_io multi_io[4]; 228 struct alc_multi_io multi_io[4];
@@ -319,13 +327,16 @@ static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
319 327
320 /* for shared I/O, change the pin-control accordingly */ 328 /* for shared I/O, change the pin-control accordingly */
321 if (spec->shared_mic_hp) { 329 if (spec->shared_mic_hp) {
330 unsigned int val;
331 hda_nid_t pin = spec->autocfg.inputs[1].pin;
322 /* NOTE: this assumes that there are only two inputs, the 332 /* NOTE: this assumes that there are only two inputs, the
323 * first is the real internal mic and the second is HP jack. 333 * first is the real internal mic and the second is HP jack.
324 */ 334 */
325 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0, 335 if (spec->cur_mux[adc_idx])
326 AC_VERB_SET_PIN_WIDGET_CONTROL, 336 val = snd_hda_get_default_vref(codec, pin) | PIN_IN;
327 spec->cur_mux[adc_idx] ? 337 else
328 PIN_VREF80 : PIN_HP); 338 val = PIN_HP;
339 snd_hda_set_pin_ctl(codec, pin, val);
329 spec->automute_speaker = !spec->cur_mux[adc_idx]; 340 spec->automute_speaker = !spec->cur_mux[adc_idx];
330 call_update_outputs(codec); 341 call_update_outputs(codec);
331 } 342 }
@@ -338,7 +349,7 @@ static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
338 nid = get_capsrc(spec, adc_idx); 349 nid = get_capsrc(spec, adc_idx);
339 350
340 /* no selection? */ 351 /* no selection? */
341 num_conns = snd_hda_get_conn_list(codec, nid, NULL); 352 num_conns = snd_hda_get_num_conns(codec, nid);
342 if (num_conns <= 1) 353 if (num_conns <= 1)
343 return 1; 354 return 1;
344 355
@@ -376,25 +387,9 @@ static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
376 int auto_pin_type) 387 int auto_pin_type)
377{ 388{
378 unsigned int val = PIN_IN; 389 unsigned int val = PIN_IN;
379 390 if (auto_pin_type == AUTO_PIN_MIC)
380 if (auto_pin_type == AUTO_PIN_MIC) { 391 val |= snd_hda_get_default_vref(codec, nid);
381 unsigned int pincap; 392 snd_hda_set_pin_ctl(codec, nid, val);
382 unsigned int oldval;
383 oldval = snd_hda_codec_read(codec, nid, 0,
384 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
385 pincap = snd_hda_query_pin_caps(codec, nid);
386 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
387 /* if the default pin setup is vref50, we give it priority */
388 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
389 val = PIN_VREF80;
390 else if (pincap & AC_PINCAP_VREF_50)
391 val = PIN_VREF50;
392 else if (pincap & AC_PINCAP_VREF_100)
393 val = PIN_VREF100;
394 else if (pincap & AC_PINCAP_VREF_GRD)
395 val = PIN_VREFGRD;
396 }
397 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
398} 393}
399 394
400/* 395/*
@@ -409,13 +404,6 @@ static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
409 spec->mixers[spec->num_mixers++] = mix; 404 spec->mixers[spec->num_mixers++] = mix;
410} 405}
411 406
412static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
413{
414 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
415 return;
416 spec->init_verbs[spec->num_init_verbs++] = verb;
417}
418
419/* 407/*
420 * GPIO setup tables, used in initialization 408 * GPIO setup tables, used in initialization
421 */ 409 */
@@ -517,9 +505,7 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
517 } else 505 } else
518 val = 0; 506 val = 0;
519 val |= pin_bits; 507 val |= pin_bits;
520 snd_hda_codec_write(codec, nid, 0, 508 snd_hda_set_pin_ctl(codec, nid, val);
521 AC_VERB_SET_PIN_WIDGET_CONTROL,
522 val);
523 break; 509 break;
524 case ALC_AUTOMUTE_AMP: 510 case ALC_AUTOMUTE_AMP:
525 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, 511 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
@@ -1200,6 +1186,16 @@ static void alc_auto_check_switches(struct hda_codec *codec)
1200 */ 1186 */
1201#define ALC_FIXUP_SKU_IGNORE (2) 1187#define ALC_FIXUP_SKU_IGNORE (2)
1202 1188
1189static void alc_fixup_sku_ignore(struct hda_codec *codec,
1190 const struct hda_fixup *fix, int action)
1191{
1192 struct alc_spec *spec = codec->spec;
1193 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1194 spec->cdefine.fixup = 1;
1195 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1196 }
1197}
1198
1203static int alc_auto_parse_customize_define(struct hda_codec *codec) 1199static int alc_auto_parse_customize_define(struct hda_codec *codec)
1204{ 1200{
1205 unsigned int ass, tmp, i; 1201 unsigned int ass, tmp, i;
@@ -1403,178 +1399,6 @@ static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
1403} 1399}
1404 1400
1405/* 1401/*
1406 * Fix-up pin default configurations and add default verbs
1407 */
1408
1409struct alc_pincfg {
1410 hda_nid_t nid;
1411 u32 val;
1412};
1413
1414struct alc_model_fixup {
1415 const int id;
1416 const char *name;
1417};
1418
1419struct alc_fixup {
1420 int type;
1421 bool chained;
1422 int chain_id;
1423 union {
1424 unsigned int sku;
1425 const struct alc_pincfg *pins;
1426 const struct hda_verb *verbs;
1427 void (*func)(struct hda_codec *codec,
1428 const struct alc_fixup *fix,
1429 int action);
1430 } v;
1431};
1432
1433enum {
1434 ALC_FIXUP_INVALID,
1435 ALC_FIXUP_SKU,
1436 ALC_FIXUP_PINS,
1437 ALC_FIXUP_VERBS,
1438 ALC_FIXUP_FUNC,
1439};
1440
1441enum {
1442 ALC_FIXUP_ACT_PRE_PROBE,
1443 ALC_FIXUP_ACT_PROBE,
1444 ALC_FIXUP_ACT_INIT,
1445 ALC_FIXUP_ACT_BUILD,
1446};
1447
1448static void alc_apply_pincfgs(struct hda_codec *codec,
1449 const struct alc_pincfg *cfg)
1450{
1451 for (; cfg->nid; cfg++)
1452 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1453}
1454
1455static void alc_apply_fixup(struct hda_codec *codec, int action)
1456{
1457 struct alc_spec *spec = codec->spec;
1458 int id = spec->fixup_id;
1459#ifdef CONFIG_SND_DEBUG_VERBOSE
1460 const char *modelname = spec->fixup_name;
1461#endif
1462 int depth = 0;
1463
1464 if (!spec->fixup_list)
1465 return;
1466
1467 while (id >= 0) {
1468 const struct alc_fixup *fix = spec->fixup_list + id;
1469 const struct alc_pincfg *cfg;
1470
1471 switch (fix->type) {
1472 case ALC_FIXUP_SKU:
1473 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1474 break;
1475 snd_printdd(KERN_INFO "hda_codec: %s: "
1476 "Apply sku override for %s\n",
1477 codec->chip_name, modelname);
1478 spec->cdefine.sku_cfg = fix->v.sku;
1479 spec->cdefine.fixup = 1;
1480 break;
1481 case ALC_FIXUP_PINS:
1482 cfg = fix->v.pins;
1483 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1484 break;
1485 snd_printdd(KERN_INFO "hda_codec: %s: "
1486 "Apply pincfg for %s\n",
1487 codec->chip_name, modelname);
1488 alc_apply_pincfgs(codec, cfg);
1489 break;
1490 case ALC_FIXUP_VERBS:
1491 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1492 break;
1493 snd_printdd(KERN_INFO "hda_codec: %s: "
1494 "Apply fix-verbs for %s\n",
1495 codec->chip_name, modelname);
1496 add_verb(codec->spec, fix->v.verbs);
1497 break;
1498 case ALC_FIXUP_FUNC:
1499 if (!fix->v.func)
1500 break;
1501 snd_printdd(KERN_INFO "hda_codec: %s: "
1502 "Apply fix-func for %s\n",
1503 codec->chip_name, modelname);
1504 fix->v.func(codec, fix, action);
1505 break;
1506 default:
1507 snd_printk(KERN_ERR "hda_codec: %s: "
1508 "Invalid fixup type %d\n",
1509 codec->chip_name, fix->type);
1510 break;
1511 }
1512 if (!fix->chained)
1513 break;
1514 if (++depth > 10)
1515 break;
1516 id = fix->chain_id;
1517 }
1518}
1519
1520static void alc_pick_fixup(struct hda_codec *codec,
1521 const struct alc_model_fixup *models,
1522 const struct snd_pci_quirk *quirk,
1523 const struct alc_fixup *fixlist)
1524{
1525 struct alc_spec *spec = codec->spec;
1526 const struct snd_pci_quirk *q;
1527 int id = -1;
1528 const char *name = NULL;
1529
1530 /* when model=nofixup is given, don't pick up any fixups */
1531 if (codec->modelname && !strcmp(codec->modelname, "nofixup")) {
1532 spec->fixup_list = NULL;
1533 spec->fixup_id = -1;
1534 return;
1535 }
1536
1537 if (codec->modelname && models) {
1538 while (models->name) {
1539 if (!strcmp(codec->modelname, models->name)) {
1540 id = models->id;
1541 name = models->name;
1542 break;
1543 }
1544 models++;
1545 }
1546 }
1547 if (id < 0) {
1548 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1549 if (q) {
1550 id = q->value;
1551#ifdef CONFIG_SND_DEBUG_VERBOSE
1552 name = q->name;
1553#endif
1554 }
1555 }
1556 if (id < 0) {
1557 for (q = quirk; q->subvendor; q++) {
1558 unsigned int vendorid =
1559 q->subdevice | (q->subvendor << 16);
1560 if (vendorid == codec->subsystem_id) {
1561 id = q->value;
1562#ifdef CONFIG_SND_DEBUG_VERBOSE
1563 name = q->name;
1564#endif
1565 break;
1566 }
1567 }
1568 }
1569
1570 spec->fixup_id = id;
1571 if (id >= 0) {
1572 spec->fixup_list = fixlist;
1573 spec->fixup_name = name;
1574 }
1575}
1576
1577/*
1578 * COEF access helper functions 1402 * COEF access helper functions
1579 */ 1403 */
1580static int alc_read_coef_idx(struct hda_codec *codec, 1404static int alc_read_coef_idx(struct hda_codec *codec,
@@ -1621,8 +1445,7 @@ static void alc_auto_init_digital(struct hda_codec *codec)
1621 pin = spec->autocfg.dig_out_pins[i]; 1445 pin = spec->autocfg.dig_out_pins[i];
1622 if (!pin) 1446 if (!pin)
1623 continue; 1447 continue;
1624 snd_hda_codec_write(codec, pin, 0, 1448 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
1625 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1626 if (!i) 1449 if (!i)
1627 dac = spec->multiout.dig_out_nid; 1450 dac = spec->multiout.dig_out_nid;
1628 else 1451 else
@@ -1635,9 +1458,7 @@ static void alc_auto_init_digital(struct hda_codec *codec)
1635 } 1458 }
1636 pin = spec->autocfg.dig_in_pin; 1459 pin = spec->autocfg.dig_in_pin;
1637 if (pin) 1460 if (pin)
1638 snd_hda_codec_write(codec, pin, 0, 1461 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
1639 AC_VERB_SET_PIN_WIDGET_CONTROL,
1640 PIN_IN);
1641} 1462}
1642 1463
1643/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */ 1464/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
@@ -2068,7 +1889,6 @@ static void alc_auto_init_std(struct hda_codec *codec);
2068static int alc_init(struct hda_codec *codec) 1889static int alc_init(struct hda_codec *codec)
2069{ 1890{
2070 struct alc_spec *spec = codec->spec; 1891 struct alc_spec *spec = codec->spec;
2071 unsigned int i;
2072 1892
2073 if (spec->init_hook) 1893 if (spec->init_hook)
2074 spec->init_hook(codec); 1894 spec->init_hook(codec);
@@ -2076,8 +1896,6 @@ static int alc_init(struct hda_codec *codec)
2076 alc_fix_pll(codec); 1896 alc_fix_pll(codec);
2077 alc_auto_init_amp(codec, spec->init_amp); 1897 alc_auto_init_amp(codec, spec->init_amp);
2078 1898
2079 for (i = 0; i < spec->num_init_verbs; i++)
2080 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2081 alc_init_special_input_src(codec); 1899 alc_init_special_input_src(codec);
2082 alc_auto_init_std(codec); 1900 alc_auto_init_std(codec);
2083 1901
@@ -2725,7 +2543,6 @@ static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2725 nid = codec->start_nid; 2543 nid = codec->start_nid;
2726 for (i = 0; i < codec->num_nodes; i++, nid++) { 2544 for (i = 0; i < codec->num_nodes; i++, nid++) {
2727 hda_nid_t src; 2545 hda_nid_t src;
2728 const hda_nid_t *list;
2729 unsigned int caps = get_wcaps(codec, nid); 2546 unsigned int caps = get_wcaps(codec, nid);
2730 int type = get_wcaps_type(caps); 2547 int type = get_wcaps_type(caps);
2731 2548
@@ -2743,13 +2560,14 @@ static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2743 cap_nids[nums] = src; 2560 cap_nids[nums] = src;
2744 break; 2561 break;
2745 } 2562 }
2746 n = snd_hda_get_conn_list(codec, src, &list); 2563 n = snd_hda_get_num_conns(codec, src);
2747 if (n > 1) { 2564 if (n > 1) {
2748 cap_nids[nums] = src; 2565 cap_nids[nums] = src;
2749 break; 2566 break;
2750 } else if (n != 1) 2567 } else if (n != 1)
2751 break; 2568 break;
2752 src = *list; 2569 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2570 break;
2753 } 2571 }
2754 if (++nums >= max_nums) 2572 if (++nums >= max_nums)
2755 break; 2573 break;
@@ -2856,8 +2674,7 @@ static int alc_auto_create_shared_input(struct hda_codec *codec)
2856static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid, 2674static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2857 unsigned int pin_type) 2675 unsigned int pin_type)
2858{ 2676{
2859 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 2677 snd_hda_set_pin_ctl(codec, nid, pin_type);
2860 pin_type);
2861 /* unmute pin */ 2678 /* unmute pin */
2862 if (nid_has_mute(codec, nid, HDA_OUTPUT)) 2679 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2863 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 2680 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
@@ -2891,7 +2708,7 @@ static void alc_auto_init_analog_input(struct hda_codec *codec)
2891 2708
2892 /* mute all loopback inputs */ 2709 /* mute all loopback inputs */
2893 if (spec->mixer_nid) { 2710 if (spec->mixer_nid) {
2894 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL); 2711 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
2895 for (i = 0; i < nums; i++) 2712 for (i = 0; i < nums; i++)
2896 snd_hda_codec_write(codec, spec->mixer_nid, 0, 2713 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2897 AC_VERB_SET_AMP_GAIN_MUTE, 2714 AC_VERB_SET_AMP_GAIN_MUTE,
@@ -3521,7 +3338,7 @@ static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3521 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) { 3338 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3522 type = ALC_CTL_WIDGET_MUTE; 3339 type = ALC_CTL_WIDGET_MUTE;
3523 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); 3340 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3524 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) { 3341 } else if (snd_hda_get_num_conns(codec, nid) == 1) {
3525 type = ALC_CTL_WIDGET_MUTE; 3342 type = ALC_CTL_WIDGET_MUTE;
3526 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT); 3343 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3527 } else { 3344 } else {
@@ -3998,9 +3815,7 @@ static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3998 snd_hda_codec_read(codec, nid, 0, 3815 snd_hda_codec_read(codec, nid, 0,
3999 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 3816 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4000 if (output) { 3817 if (output) {
4001 snd_hda_codec_update_cache(codec, nid, 0, 3818 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
4002 AC_VERB_SET_PIN_WIDGET_CONTROL,
4003 PIN_OUT);
4004 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) 3819 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4005 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, 3820 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4006 HDA_AMP_MUTE, 0); 3821 HDA_AMP_MUTE, 0);
@@ -4009,9 +3824,8 @@ static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4009 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) 3824 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4010 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, 3825 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4011 HDA_AMP_MUTE, HDA_AMP_MUTE); 3826 HDA_AMP_MUTE, HDA_AMP_MUTE);
4012 snd_hda_codec_update_cache(codec, nid, 0, 3827 snd_hda_set_pin_ctl_cache(codec, nid,
4013 AC_VERB_SET_PIN_WIDGET_CONTROL, 3828 spec->multi_io[idx].ctl_in);
4014 spec->multi_io[idx].ctl_in);
4015 } 3829 }
4016 return 0; 3830 return 0;
4017} 3831}
@@ -4084,7 +3898,7 @@ static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4084 nums = 0; 3898 nums = 0;
4085 for (n = 0; n < spec->num_adc_nids; n++) { 3899 for (n = 0; n < spec->num_adc_nids; n++) {
4086 hda_nid_t cap = spec->private_capsrc_nids[n]; 3900 hda_nid_t cap = spec->private_capsrc_nids[n];
4087 int num_conns = snd_hda_get_conn_list(codec, cap, NULL); 3901 int num_conns = snd_hda_get_num_conns(codec, cap);
4088 for (i = 0; i < imux->num_items; i++) { 3902 for (i = 0; i < imux->num_items; i++) {
4089 hda_nid_t pin = spec->imux_pins[i]; 3903 hda_nid_t pin = spec->imux_pins[i];
4090 if (pin) { 3904 if (pin) {
@@ -4213,7 +4027,7 @@ static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4213 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) { 4027 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4214 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx, 4028 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4215 HDA_AMP_MUTE, 0); 4029 HDA_AMP_MUTE, 0);
4216 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) { 4030 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
4217 snd_hda_codec_write_cache(codec, cap, 0, 4031 snd_hda_codec_write_cache(codec, cap, 0,
4218 AC_VERB_SET_CONNECT_SEL, idx); 4032 AC_VERB_SET_CONNECT_SEL, idx);
4219 } 4033 }
@@ -4427,6 +4241,25 @@ static int alc_parse_auto_config(struct hda_codec *codec,
4427 return 1; 4241 return 1;
4428} 4242}
4429 4243
4244/* common preparation job for alc_spec */
4245static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4246{
4247 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4248 int err;
4249
4250 if (!spec)
4251 return -ENOMEM;
4252 codec->spec = spec;
4253 spec->mixer_nid = mixer_nid;
4254
4255 err = alc_codec_rename_from_preset(codec);
4256 if (err < 0) {
4257 kfree(spec);
4258 return err;
4259 }
4260 return 0;
4261}
4262
4430static int alc880_parse_auto_config(struct hda_codec *codec) 4263static int alc880_parse_auto_config(struct hda_codec *codec)
4431{ 4264{
4432 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 }; 4265 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
@@ -4808,13 +4641,11 @@ static int patch_alc880(struct hda_codec *codec)
4808 struct alc_spec *spec; 4641 struct alc_spec *spec;
4809 int err; 4642 int err;
4810 4643
4811 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4644 err = alc_alloc_spec(codec, 0x0b);
4812 if (spec == NULL) 4645 if (err < 0)
4813 return -ENOMEM; 4646 return err;
4814
4815 codec->spec = spec;
4816 4647
4817 spec->mixer_nid = 0x0b; 4648 spec = codec->spec;
4818 spec->need_dac_fix = 1; 4649 spec->need_dac_fix = 1;
4819 4650
4820 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl, 4651 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
@@ -4890,7 +4721,7 @@ static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4890 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */ 4721 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4891 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT); 4722 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4892 spec->unsol_event = alc_sku_unsol_event; 4723 spec->unsol_event = alc_sku_unsol_event;
4893 add_verb(codec->spec, alc_gpio1_init_verbs); 4724 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
4894 } 4725 }
4895} 4726}
4896 4727
@@ -5001,13 +4832,11 @@ static int patch_alc260(struct hda_codec *codec)
5001 struct alc_spec *spec; 4832 struct alc_spec *spec;
5002 int err; 4833 int err;
5003 4834
5004 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4835 err = alc_alloc_spec(codec, 0x07);
5005 if (spec == NULL) 4836 if (err < 0)
5006 return -ENOMEM; 4837 return err;
5007
5008 codec->spec = spec;
5009 4838
5010 spec->mixer_nid = 0x07; 4839 spec = codec->spec;
5011 4840
5012 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); 4841 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5013 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 4842 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
@@ -5171,8 +5000,7 @@ static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5171 val = snd_hda_codec_read(codec, nids[i], 0, 5000 val = snd_hda_codec_read(codec, nids[i], 0,
5172 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 5001 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5173 val |= AC_PINCTL_VREF_80; 5002 val |= AC_PINCTL_VREF_80;
5174 snd_hda_codec_write(codec, nids[i], 0, 5003 snd_hda_set_pin_ctl(codec, nids[i], val);
5175 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5176 spec->keep_vref_in_automute = 1; 5004 spec->keep_vref_in_automute = 1;
5177 break; 5005 break;
5178 } 5006 }
@@ -5193,8 +5021,7 @@ static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5193 val = snd_hda_codec_read(codec, nids[i], 0, 5021 val = snd_hda_codec_read(codec, nids[i], 0,
5194 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 5022 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5195 val |= AC_PINCTL_VREF_50; 5023 val |= AC_PINCTL_VREF_50;
5196 snd_hda_codec_write(codec, nids[i], 0, 5024 snd_hda_set_pin_ctl(codec, nids[i], val);
5197 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5198 } 5025 }
5199 spec->keep_vref_in_automute = 1; 5026 spec->keep_vref_in_automute = 1;
5200} 5027}
@@ -5225,8 +5052,8 @@ static const struct alc_fixup alc882_fixups[] = {
5225 } 5052 }
5226 }, 5053 },
5227 [ALC882_FIXUP_ACER_ASPIRE_7736] = { 5054 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
5228 .type = ALC_FIXUP_SKU, 5055 .type = ALC_FIXUP_FUNC,
5229 .v.sku = ALC_FIXUP_SKU_IGNORE, 5056 .v.func = alc_fixup_sku_ignore,
5230 }, 5057 },
5231 [ALC882_FIXUP_ASUS_W90V] = { 5058 [ALC882_FIXUP_ASUS_W90V] = {
5232 .type = ALC_FIXUP_PINS, 5059 .type = ALC_FIXUP_PINS,
@@ -5476,13 +5303,11 @@ static int patch_alc882(struct hda_codec *codec)
5476 struct alc_spec *spec; 5303 struct alc_spec *spec;
5477 int err; 5304 int err;
5478 5305
5479 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5306 err = alc_alloc_spec(codec, 0x0b);
5480 if (spec == NULL) 5307 if (err < 0)
5481 return -ENOMEM; 5308 return err;
5482
5483 codec->spec = spec;
5484 5309
5485 spec->mixer_nid = 0x0b; 5310 spec = codec->spec;
5486 5311
5487 switch (codec->vendor_id) { 5312 switch (codec->vendor_id) {
5488 case 0x10ec0882: 5313 case 0x10ec0882:
@@ -5494,10 +5319,6 @@ static int patch_alc882(struct hda_codec *codec)
5494 break; 5319 break;
5495 } 5320 }
5496 5321
5497 err = alc_codec_rename_from_preset(codec);
5498 if (err < 0)
5499 goto error;
5500
5501 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl, 5322 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5502 alc882_fixups); 5323 alc882_fixups);
5503 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 5324 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
@@ -5621,13 +5442,11 @@ static int patch_alc262(struct hda_codec *codec)
5621 struct alc_spec *spec; 5442 struct alc_spec *spec;
5622 int err; 5443 int err;
5623 5444
5624 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5445 err = alc_alloc_spec(codec, 0x0b);
5625 if (spec == NULL) 5446 if (err < 0)
5626 return -ENOMEM; 5447 return err;
5627
5628 codec->spec = spec;
5629 5448
5630 spec->mixer_nid = 0x0b; 5449 spec = codec->spec;
5631 5450
5632#if 0 5451#if 0
5633 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is 5452 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
@@ -5710,7 +5529,7 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
5710 if (err > 0) { 5529 if (err > 0) {
5711 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) { 5530 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5712 add_mixer(spec, alc268_beep_mixer); 5531 add_mixer(spec, alc268_beep_mixer);
5713 add_verb(spec, alc268_beep_init_verbs); 5532 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
5714 } 5533 }
5715 } 5534 }
5716 return err; 5535 return err;
@@ -5723,13 +5542,12 @@ static int patch_alc268(struct hda_codec *codec)
5723 struct alc_spec *spec; 5542 struct alc_spec *spec;
5724 int i, has_beep, err; 5543 int i, has_beep, err;
5725 5544
5726 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5727 if (spec == NULL)
5728 return -ENOMEM;
5729
5730 codec->spec = spec;
5731
5732 /* ALC268 has no aa-loopback mixer */ 5545 /* ALC268 has no aa-loopback mixer */
5546 err = alc_alloc_spec(codec, 0);
5547 if (err < 0)
5548 return err;
5549
5550 spec = codec->spec;
5733 5551
5734 /* automatic parse from the BIOS config */ 5552 /* automatic parse from the BIOS config */
5735 err = alc268_parse_auto_config(codec); 5553 err = alc268_parse_auto_config(codec);
@@ -5946,9 +5764,7 @@ static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
5946{ 5764{
5947 struct hda_codec *codec = private_data; 5765 struct hda_codec *codec = private_data;
5948 unsigned int pinval = enabled ? 0x20 : 0x24; 5766 unsigned int pinval = enabled ? 0x20 : 0x24;
5949 snd_hda_codec_update_cache(codec, 0x19, 0, 5767 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
5950 AC_VERB_SET_PIN_WIDGET_CONTROL,
5951 pinval);
5952} 5768}
5953 5769
5954static void alc269_fixup_mic2_mute(struct hda_codec *codec, 5770static void alc269_fixup_mic2_mute(struct hda_codec *codec,
@@ -6015,8 +5831,8 @@ static const struct alc_fixup alc269_fixups[] = {
6015 } 5831 }
6016 }, 5832 },
6017 [ALC269_FIXUP_SKU_IGNORE] = { 5833 [ALC269_FIXUP_SKU_IGNORE] = {
6018 .type = ALC_FIXUP_SKU, 5834 .type = ALC_FIXUP_FUNC,
6019 .v.sku = ALC_FIXUP_SKU_IGNORE, 5835 .v.func = alc_fixup_sku_ignore,
6020 }, 5836 },
6021 [ALC269_FIXUP_ASUS_G73JW] = { 5837 [ALC269_FIXUP_ASUS_G73JW] = {
6022 .type = ALC_FIXUP_PINS, 5838 .type = ALC_FIXUP_PINS,
@@ -6242,19 +6058,13 @@ static void alc269_fill_coef(struct hda_codec *codec)
6242static int patch_alc269(struct hda_codec *codec) 6058static int patch_alc269(struct hda_codec *codec)
6243{ 6059{
6244 struct alc_spec *spec; 6060 struct alc_spec *spec;
6245 int err = 0; 6061 int err;
6246
6247 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6248 if (spec == NULL)
6249 return -ENOMEM;
6250
6251 codec->spec = spec;
6252
6253 spec->mixer_nid = 0x0b;
6254 6062
6255 err = alc_codec_rename_from_preset(codec); 6063 err = alc_alloc_spec(codec, 0x0b);
6256 if (err < 0) 6064 if (err < 0)
6257 goto error; 6065 return err;
6066
6067 spec = codec->spec;
6258 6068
6259 if (codec->vendor_id == 0x10ec0269) { 6069 if (codec->vendor_id == 0x10ec0269) {
6260 spec->codec_variant = ALC269_TYPE_ALC269VA; 6070 spec->codec_variant = ALC269_TYPE_ALC269VA;
@@ -6346,8 +6156,7 @@ static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6346 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))) 6156 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6347 val |= AC_PINCTL_IN_EN; 6157 val |= AC_PINCTL_IN_EN;
6348 val |= AC_PINCTL_VREF_50; 6158 val |= AC_PINCTL_VREF_50;
6349 snd_hda_codec_write(codec, 0x0f, 0, 6159 snd_hda_set_pin_ctl(codec, 0x0f, val);
6350 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
6351 spec->keep_vref_in_automute = 1; 6160 spec->keep_vref_in_automute = 1;
6352} 6161}
6353 6162
@@ -6401,13 +6210,11 @@ static int patch_alc861(struct hda_codec *codec)
6401 struct alc_spec *spec; 6210 struct alc_spec *spec;
6402 int err; 6211 int err;
6403 6212
6404 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 6213 err = alc_alloc_spec(codec, 0x15);
6405 if (spec == NULL) 6214 if (err < 0)
6406 return -ENOMEM; 6215 return err;
6407
6408 codec->spec = spec;
6409 6216
6410 spec->mixer_nid = 0x15; 6217 spec = codec->spec;
6411 6218
6412 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); 6219 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6413 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 6220 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
@@ -6504,13 +6311,11 @@ static int patch_alc861vd(struct hda_codec *codec)
6504 struct alc_spec *spec; 6311 struct alc_spec *spec;
6505 int err; 6312 int err;
6506 6313
6507 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 6314 err = alc_alloc_spec(codec, 0x0b);
6508 if (spec == NULL) 6315 if (err < 0)
6509 return -ENOMEM; 6316 return err;
6510
6511 codec->spec = spec;
6512 6317
6513 spec->mixer_nid = 0x0b; 6318 spec = codec->spec;
6514 6319
6515 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); 6320 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6516 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 6321 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
@@ -6522,7 +6327,7 @@ static int patch_alc861vd(struct hda_codec *codec)
6522 6327
6523 if (codec->vendor_id == 0x10ec0660) { 6328 if (codec->vendor_id == 0x10ec0660) {
6524 /* always turn on EAPD */ 6329 /* always turn on EAPD */
6525 add_verb(spec, alc660vd_eapd_verbs); 6330 snd_hda_gen_add_verbs(&spec->gen, alc660vd_eapd_verbs);
6526 } 6331 }
6527 6332
6528 if (!spec->no_analog) { 6333 if (!spec->no_analog) {
@@ -6635,8 +6440,8 @@ static const struct alc_fixup alc662_fixups[] = {
6635 } 6440 }
6636 }, 6441 },
6637 [ALC662_FIXUP_SKU_IGNORE] = { 6442 [ALC662_FIXUP_SKU_IGNORE] = {
6638 .type = ALC_FIXUP_SKU, 6443 .type = ALC_FIXUP_FUNC,
6639 .v.sku = ALC_FIXUP_SKU_IGNORE, 6444 .v.func = alc_fixup_sku_ignore,
6640 }, 6445 },
6641 [ALC662_FIXUP_HP_RP5800] = { 6446 [ALC662_FIXUP_HP_RP5800] = {
6642 .type = ALC_FIXUP_PINS, 6447 .type = ALC_FIXUP_PINS,
@@ -6849,25 +6654,19 @@ static const struct alc_model_fixup alc662_fixup_models[] = {
6849static int patch_alc662(struct hda_codec *codec) 6654static int patch_alc662(struct hda_codec *codec)
6850{ 6655{
6851 struct alc_spec *spec; 6656 struct alc_spec *spec;
6852 int err = 0; 6657 int err;
6853
6854 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6855 if (!spec)
6856 return -ENOMEM;
6857 6658
6858 codec->spec = spec; 6659 err = alc_alloc_spec(codec, 0x0b);
6660 if (err < 0)
6661 return err;
6859 6662
6860 spec->mixer_nid = 0x0b; 6663 spec = codec->spec;
6861 6664
6862 /* handle multiple HPs as is */ 6665 /* handle multiple HPs as is */
6863 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; 6666 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6864 6667
6865 alc_fix_pll_init(codec, 0x20, 0x04, 15); 6668 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6866 6669
6867 err = alc_codec_rename_from_preset(codec);
6868 if (err < 0)
6869 goto error;
6870
6871 if ((alc_get_coef0(codec) & (1 << 14)) && 6670 if ((alc_get_coef0(codec) & (1 << 14)) &&
6872 codec->bus->pci->subsystem_vendor == 0x1025 && 6671 codec->bus->pci->subsystem_vendor == 0x1025 &&
6873 spec->cdefine.platform_type == 1) { 6672 spec->cdefine.platform_type == 1) {
@@ -6930,16 +6729,12 @@ static int alc680_parse_auto_config(struct hda_codec *codec)
6930 */ 6729 */
6931static int patch_alc680(struct hda_codec *codec) 6730static int patch_alc680(struct hda_codec *codec)
6932{ 6731{
6933 struct alc_spec *spec;
6934 int err; 6732 int err;
6935 6733
6936 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6937 if (spec == NULL)
6938 return -ENOMEM;
6939
6940 codec->spec = spec;
6941
6942 /* ALC680 has no aa-loopback mixer */ 6734 /* ALC680 has no aa-loopback mixer */
6735 err = alc_alloc_spec(codec, 0);
6736 if (err < 0)
6737 return err;
6943 6738
6944 /* automatic parse from the BIOS config */ 6739 /* automatic parse from the BIOS config */
6945 err = alc680_parse_auto_config(codec); 6740 err = alc680_parse_auto_config(codec);
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 2cb1e08f962a..7db8228f1b88 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -36,6 +36,7 @@
36#include <sound/tlv.h> 36#include <sound/tlv.h>
37#include "hda_codec.h" 37#include "hda_codec.h"
38#include "hda_local.h" 38#include "hda_local.h"
39#include "hda_auto_parser.h"
39#include "hda_beep.h" 40#include "hda_beep.h"
40#include "hda_jack.h" 41#include "hda_jack.h"
41 42
@@ -221,6 +222,7 @@ struct sigmatel_spec {
221 unsigned char aloopback_shift; 222 unsigned char aloopback_shift;
222 223
223 /* power management */ 224 /* power management */
225 unsigned int power_map_bits;
224 unsigned int num_pwrs; 226 unsigned int num_pwrs;
225 const hda_nid_t *pwr_nids; 227 const hda_nid_t *pwr_nids;
226 const hda_nid_t *dac_list; 228 const hda_nid_t *dac_list;
@@ -314,6 +316,9 @@ struct sigmatel_spec {
314 struct hda_vmaster_mute_hook vmaster_mute; 316 struct hda_vmaster_mute_hook vmaster_mute;
315}; 317};
316 318
319#define AC_VERB_IDT_SET_POWER_MAP 0x7ec
320#define AC_VERB_IDT_GET_POWER_MAP 0xfec
321
317static const hda_nid_t stac9200_adc_nids[1] = { 322static const hda_nid_t stac9200_adc_nids[1] = {
318 0x03, 323 0x03,
319}; 324};
@@ -681,8 +686,7 @@ static int stac_vrefout_set(struct hda_codec *codec,
681 pinctl &= ~AC_PINCTL_VREFEN; 686 pinctl &= ~AC_PINCTL_VREFEN;
682 pinctl |= (new_vref & AC_PINCTL_VREFEN); 687 pinctl |= (new_vref & AC_PINCTL_VREFEN);
683 688
684 error = snd_hda_codec_write_cache(codec, nid, 0, 689 error = snd_hda_set_pin_ctl_cache(codec, nid, pinctl);
685 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
686 if (error < 0) 690 if (error < 0)
687 return error; 691 return error;
688 692
@@ -706,8 +710,7 @@ static unsigned int stac92xx_vref_set(struct hda_codec *codec,
706 else 710 else
707 pincfg |= AC_PINCTL_IN_EN; 711 pincfg |= AC_PINCTL_IN_EN;
708 712
709 error = snd_hda_codec_write_cache(codec, nid, 0, 713 error = snd_hda_set_pin_ctl_cache(codec, nid, pincfg);
710 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
711 if (error < 0) 714 if (error < 0)
712 return error; 715 return error;
713 else 716 else
@@ -2505,27 +2508,10 @@ static int stac92xx_build_pcms(struct hda_codec *codec)
2505 return 0; 2508 return 0;
2506} 2509}
2507 2510
2508static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2509 hda_nid_t nid)
2510{
2511 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2512 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2513 if (pincap & AC_PINCAP_VREF_100)
2514 return AC_PINCTL_VREF_100;
2515 if (pincap & AC_PINCAP_VREF_80)
2516 return AC_PINCTL_VREF_80;
2517 if (pincap & AC_PINCAP_VREF_50)
2518 return AC_PINCTL_VREF_50;
2519 if (pincap & AC_PINCAP_VREF_GRD)
2520 return AC_PINCTL_VREF_GRD;
2521 return 0;
2522}
2523
2524static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type) 2511static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2525 2512
2526{ 2513{
2527 snd_hda_codec_write_cache(codec, nid, 0, 2514 snd_hda_set_pin_ctl_cache(codec, nid, pin_type);
2528 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2529} 2515}
2530 2516
2531#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info 2517#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
@@ -2594,7 +2580,7 @@ static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2594 hda_nid_t nid = kcontrol->private_value; 2580 hda_nid_t nid = kcontrol->private_value;
2595 unsigned int vref = stac92xx_vref_get(codec, nid); 2581 unsigned int vref = stac92xx_vref_get(codec, nid);
2596 2582
2597 if (vref == stac92xx_get_default_vref(codec, nid)) 2583 if (vref == snd_hda_get_default_vref(codec, nid))
2598 ucontrol->value.enumerated.item[0] = 0; 2584 ucontrol->value.enumerated.item[0] = 0;
2599 else if (vref == AC_PINCTL_VREF_GRD) 2585 else if (vref == AC_PINCTL_VREF_GRD)
2600 ucontrol->value.enumerated.item[0] = 1; 2586 ucontrol->value.enumerated.item[0] = 1;
@@ -2613,7 +2599,7 @@ static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2613 hda_nid_t nid = kcontrol->private_value; 2599 hda_nid_t nid = kcontrol->private_value;
2614 2600
2615 if (ucontrol->value.enumerated.item[0] == 0) 2601 if (ucontrol->value.enumerated.item[0] == 0)
2616 new_vref = stac92xx_get_default_vref(codec, nid); 2602 new_vref = snd_hda_get_default_vref(codec, nid);
2617 else if (ucontrol->value.enumerated.item[0] == 1) 2603 else if (ucontrol->value.enumerated.item[0] == 1)
2618 new_vref = AC_PINCTL_VREF_GRD; 2604 new_vref = AC_PINCTL_VREF_GRD;
2619 else if (ucontrol->value.enumerated.item[0] == 2) 2605 else if (ucontrol->value.enumerated.item[0] == 2)
@@ -2679,7 +2665,7 @@ static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_
2679 else { 2665 else {
2680 unsigned int pinctl = AC_PINCTL_IN_EN; 2666 unsigned int pinctl = AC_PINCTL_IN_EN;
2681 if (io_idx) /* set VREF for mic */ 2667 if (io_idx) /* set VREF for mic */
2682 pinctl |= stac92xx_get_default_vref(codec, nid); 2668 pinctl |= snd_hda_get_default_vref(codec, nid);
2683 stac92xx_auto_set_pinctl(codec, nid, pinctl); 2669 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2684 } 2670 }
2685 2671
@@ -2847,7 +2833,7 @@ static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2847 char name[22]; 2833 char name[22];
2848 2834
2849 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) { 2835 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
2850 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD 2836 if (snd_hda_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2851 && nid == spec->line_switch) 2837 && nid == spec->line_switch)
2852 control = STAC_CTL_WIDGET_IO_SWITCH; 2838 control = STAC_CTL_WIDGET_IO_SWITCH;
2853 else if (snd_hda_query_pin_caps(codec, nid) 2839 else if (snd_hda_query_pin_caps(codec, nid)
@@ -4250,13 +4236,6 @@ static void stac_store_hints(struct hda_codec *codec)
4250 val = snd_hda_get_bool_hint(codec, "eapd_switch"); 4236 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4251 if (val >= 0) 4237 if (val >= 0)
4252 spec->eapd_switch = val; 4238 spec->eapd_switch = val;
4253 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4254 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
4255 spec->gpio_mask |= spec->gpio_led;
4256 spec->gpio_dir |= spec->gpio_led;
4257 if (spec->gpio_led_polarity)
4258 spec->gpio_data |= spec->gpio_led;
4259 }
4260} 4239}
4261 4240
4262static void stac_issue_unsol_events(struct hda_codec *codec, int num_pins, 4241static void stac_issue_unsol_events(struct hda_codec *codec, int num_pins,
@@ -4354,7 +4333,7 @@ static int stac92xx_init(struct hda_codec *codec)
4354 unsigned int pinctl, conf; 4333 unsigned int pinctl, conf;
4355 if (type == AUTO_PIN_MIC) { 4334 if (type == AUTO_PIN_MIC) {
4356 /* for mic pins, force to initialize */ 4335 /* for mic pins, force to initialize */
4357 pinctl = stac92xx_get_default_vref(codec, nid); 4336 pinctl = snd_hda_get_default_vref(codec, nid);
4358 pinctl |= AC_PINCTL_IN_EN; 4337 pinctl |= AC_PINCTL_IN_EN;
4359 stac92xx_auto_set_pinctl(codec, nid, pinctl); 4338 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4360 } else { 4339 } else {
@@ -4390,10 +4369,18 @@ static int stac92xx_init(struct hda_codec *codec)
4390 hda_nid_t nid = spec->pwr_nids[i]; 4369 hda_nid_t nid = spec->pwr_nids[i];
4391 int pinctl, def_conf; 4370 int pinctl, def_conf;
4392 4371
4372 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4373 def_conf = get_defcfg_connect(def_conf);
4374 if (def_conf == AC_JACK_PORT_NONE) {
4375 /* power off unused ports */
4376 stac_toggle_power_map(codec, nid, 0);
4377 continue;
4378 }
4393 /* power on when no jack detection is available */ 4379 /* power on when no jack detection is available */
4394 /* or when the VREF is used for controlling LED */ 4380 /* or when the VREF is used for controlling LED */
4395 if (!spec->hp_detect || 4381 if (!spec->hp_detect ||
4396 spec->vref_mute_led_nid == nid) { 4382 spec->vref_mute_led_nid == nid ||
4383 !is_jack_detectable(codec, nid)) {
4397 stac_toggle_power_map(codec, nid, 1); 4384 stac_toggle_power_map(codec, nid, 1);
4398 continue; 4385 continue;
4399 } 4386 }
@@ -4411,15 +4398,6 @@ static int stac92xx_init(struct hda_codec *codec)
4411 stac_toggle_power_map(codec, nid, 1); 4398 stac_toggle_power_map(codec, nid, 1);
4412 continue; 4399 continue;
4413 } 4400 }
4414 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4415 def_conf = get_defcfg_connect(def_conf);
4416 /* skip any ports that don't have jacks since presence
4417 * detection is useless */
4418 if (def_conf != AC_JACK_PORT_NONE &&
4419 !is_jack_detectable(codec, nid)) {
4420 stac_toggle_power_map(codec, nid, 1);
4421 continue;
4422 }
4423 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) { 4401 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) {
4424 stac_issue_unsol_event(codec, nid); 4402 stac_issue_unsol_event(codec, nid);
4425 continue; 4403 continue;
@@ -4432,6 +4410,12 @@ static int stac92xx_init(struct hda_codec *codec)
4432 4410
4433 /* sync mute LED */ 4411 /* sync mute LED */
4434 snd_hda_sync_vmaster_hook(&spec->vmaster_mute); 4412 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4413
4414 /* sync the power-map */
4415 if (spec->num_pwrs)
4416 snd_hda_codec_write(codec, codec->afg, 0,
4417 AC_VERB_IDT_SET_POWER_MAP,
4418 spec->power_map_bits);
4435 if (spec->dac_list) 4419 if (spec->dac_list)
4436 stac92xx_power_down(codec); 4420 stac92xx_power_down(codec);
4437 return 0; 4421 return 0;
@@ -4460,8 +4444,7 @@ static void stac92xx_shutup_pins(struct hda_codec *codec)
4460 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); 4444 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
4461 def_conf = snd_hda_codec_get_pincfg(codec, pin->nid); 4445 def_conf = snd_hda_codec_get_pincfg(codec, pin->nid);
4462 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) 4446 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
4463 snd_hda_codec_write(codec, pin->nid, 0, 4447 snd_hda_set_pin_ctl(codec, pin->nid, 0);
4464 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4465 } 4448 }
4466} 4449}
4467 4450
@@ -4517,9 +4500,7 @@ static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4517 4500
4518 pin_ctl |= flag; 4501 pin_ctl |= flag;
4519 if (old_ctl != pin_ctl) 4502 if (old_ctl != pin_ctl)
4520 snd_hda_codec_write_cache(codec, nid, 0, 4503 snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl);
4521 AC_VERB_SET_PIN_WIDGET_CONTROL,
4522 pin_ctl);
4523} 4504}
4524 4505
4525static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid, 4506static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
@@ -4528,9 +4509,7 @@ static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4528 unsigned int pin_ctl = snd_hda_codec_read(codec, nid, 4509 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4529 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00); 4510 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4530 if (pin_ctl & flag) 4511 if (pin_ctl & flag)
4531 snd_hda_codec_write_cache(codec, nid, 0, 4512 snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl & ~flag);
4532 AC_VERB_SET_PIN_WIDGET_CONTROL,
4533 pin_ctl & ~flag);
4534} 4513}
4535 4514
4536static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid) 4515static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
@@ -4682,14 +4661,18 @@ static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4682 4661
4683 idx = 1 << idx; 4662 idx = 1 << idx;
4684 4663
4685 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff; 4664 val = spec->power_map_bits;
4686 if (enable) 4665 if (enable)
4687 val &= ~idx; 4666 val &= ~idx;
4688 else 4667 else
4689 val |= idx; 4668 val |= idx;
4690 4669
4691 /* power down unused output ports */ 4670 /* power down unused output ports */
4692 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val); 4671 if (val != spec->power_map_bits) {
4672 spec->power_map_bits = val;
4673 snd_hda_codec_write(codec, codec->afg, 0,
4674 AC_VERB_IDT_SET_POWER_MAP, val);
4675 }
4693} 4676}
4694 4677
4695static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid) 4678static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
@@ -4866,6 +4849,11 @@ static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity)
4866 struct sigmatel_spec *spec = codec->spec; 4849 struct sigmatel_spec *spec = codec->spec;
4867 const struct dmi_device *dev = NULL; 4850 const struct dmi_device *dev = NULL;
4868 4851
4852 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
4853 get_int_hint(codec, "gpio_led_polarity",
4854 &spec->gpio_led_polarity);
4855 return 1;
4856 }
4869 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) { 4857 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4870 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, 4858 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4871 NULL, dev))) { 4859 NULL, dev))) {
@@ -4952,7 +4940,8 @@ static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4952{ 4940{
4953 if (nid == codec->afg) 4941 if (nid == codec->afg)
4954 snd_iprintf(buffer, "Power-Map: 0x%02x\n", 4942 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4955 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0)); 4943 snd_hda_codec_read(codec, nid, 0,
4944 AC_VERB_IDT_GET_POWER_MAP, 0));
4956} 4945}
4957 4946
4958static void analog_loop_proc_hook(struct snd_info_buffer *buffer, 4947static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
@@ -5009,20 +4998,6 @@ static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
5009 return 0; 4998 return 0;
5010} 4999}
5011 5000
5012static int stac92xx_pre_resume(struct hda_codec *codec)
5013{
5014 struct sigmatel_spec *spec = codec->spec;
5015
5016 /* sync mute LED */
5017 if (spec->vref_mute_led_nid)
5018 stac_vrefout_set(codec, spec->vref_mute_led_nid,
5019 spec->vref_led);
5020 else if (spec->gpio_led)
5021 stac_gpio_set(codec, spec->gpio_mask,
5022 spec->gpio_dir, spec->gpio_data);
5023 return 0;
5024}
5025
5026static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg, 5001static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
5027 unsigned int power_state) 5002 unsigned int power_state)
5028{ 5003{
@@ -5046,7 +5021,6 @@ static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
5046#else 5021#else
5047#define stac92xx_suspend NULL 5022#define stac92xx_suspend NULL
5048#define stac92xx_resume NULL 5023#define stac92xx_resume NULL
5049#define stac92xx_pre_resume NULL
5050#define stac92xx_set_power_state NULL 5024#define stac92xx_set_power_state NULL
5051#endif /* CONFIG_PM */ 5025#endif /* CONFIG_PM */
5052 5026
@@ -5592,9 +5566,6 @@ again:
5592 codec->patch_ops.set_power_state = 5566 codec->patch_ops.set_power_state =
5593 stac92xx_set_power_state; 5567 stac92xx_set_power_state;
5594 } 5568 }
5595#ifdef CONFIG_PM
5596 codec->patch_ops.pre_resume = stac92xx_pre_resume;
5597#endif
5598 } 5569 }
5599 5570
5600 err = stac92xx_parse_auto_config(codec); 5571 err = stac92xx_parse_auto_config(codec);
@@ -5901,9 +5872,6 @@ again:
5901 codec->patch_ops.set_power_state = 5872 codec->patch_ops.set_power_state =
5902 stac92xx_set_power_state; 5873 stac92xx_set_power_state;
5903 } 5874 }
5904#ifdef CONFIG_PM
5905 codec->patch_ops.pre_resume = stac92xx_pre_resume;
5906#endif
5907 } 5875 }
5908 5876
5909 spec->multiout.dac_nids = spec->dac_nids; 5877 spec->multiout.dac_nids = spec->dac_nids;
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index 06214fdc9486..82b368068e08 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -54,6 +54,7 @@
54#include <sound/asoundef.h> 54#include <sound/asoundef.h>
55#include "hda_codec.h" 55#include "hda_codec.h"
56#include "hda_local.h" 56#include "hda_local.h"
57#include "hda_auto_parser.h"
57#include "hda_jack.h" 58#include "hda_jack.h"
58 59
59/* Pin Widget NID */ 60/* Pin Widget NID */
@@ -484,7 +485,7 @@ static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
484 485
485 if (!path) 486 if (!path)
486 return; 487 return;
487 num = snd_hda_get_conn_list(codec, mix_nid, NULL); 488 num = snd_hda_get_num_conns(codec, mix_nid);
488 for (i = 0; i < num; i++) { 489 for (i = 0; i < num; i++) {
489 if (i == idx) 490 if (i == idx)
490 val = AMP_IN_UNMUTE(i); 491 val = AMP_IN_UNMUTE(i);
@@ -532,8 +533,7 @@ static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
532{ 533{
533 if (!pin) 534 if (!pin)
534 return; 535 return;
535 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 536 snd_hda_set_pin_ctl(codec, pin, pin_type);
536 pin_type);
537 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD) 537 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
538 snd_hda_codec_write(codec, pin, 0, 538 snd_hda_codec_write(codec, pin, 0,
539 AC_VERB_SET_EAPD_BTLENABLE, 0x02); 539 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
@@ -662,12 +662,12 @@ static void via_auto_init_analog_input(struct hda_codec *codec)
662 hda_nid_t nid = cfg->inputs[i].pin; 662 hda_nid_t nid = cfg->inputs[i].pin;
663 if (spec->smart51_enabled && is_smart51_pins(codec, nid)) 663 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
664 ctl = PIN_OUT; 664 ctl = PIN_OUT;
665 else if (cfg->inputs[i].type == AUTO_PIN_MIC) 665 else {
666 ctl = PIN_VREF50;
667 else
668 ctl = PIN_IN; 666 ctl = PIN_IN;
669 snd_hda_codec_write(codec, nid, 0, 667 if (cfg->inputs[i].type == AUTO_PIN_MIC)
670 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl); 668 ctl |= snd_hda_get_default_vref(codec, nid);
669 }
670 snd_hda_set_pin_ctl(codec, nid, ctl);
671 } 671 }
672 672
673 /* init input-src */ 673 /* init input-src */
@@ -1006,9 +1006,7 @@ static int via_smart51_put(struct snd_kcontrol *kcontrol,
1006 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 1006 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1007 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); 1007 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1008 parm |= out_in; 1008 parm |= out_in;
1009 snd_hda_codec_write(codec, nid, 0, 1009 snd_hda_set_pin_ctl(codec, nid, parm);
1010 AC_VERB_SET_PIN_WIDGET_CONTROL,
1011 parm);
1012 if (out_in == AC_PINCTL_OUT_EN) { 1010 if (out_in == AC_PINCTL_OUT_EN) {
1013 mute_aa_path(codec, 1); 1011 mute_aa_path(codec, 1);
1014 notify_aa_path_ctls(codec); 1012 notify_aa_path_ctls(codec);
@@ -1647,8 +1645,7 @@ static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1647 parm &= ~AC_PINCTL_OUT_EN; 1645 parm &= ~AC_PINCTL_OUT_EN;
1648 else 1646 else
1649 parm |= AC_PINCTL_OUT_EN; 1647 parm |= AC_PINCTL_OUT_EN;
1650 snd_hda_codec_write(codec, pins[i], 0, 1648 snd_hda_set_pin_ctl(codec, pins[i], parm);
1651 AC_VERB_SET_PIN_WIDGET_CONTROL, parm);
1652 } 1649 }
1653} 1650}
1654 1651
@@ -1709,8 +1706,7 @@ static void via_gpio_control(struct hda_codec *codec)
1709 1706
1710 if (gpio_data == 0x02) { 1707 if (gpio_data == 0x02) {
1711 /* unmute line out */ 1708 /* unmute line out */
1712 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, 1709 snd_hda_set_pin_ctl(codec, spec->autocfg.line_out_pins[0],
1713 AC_VERB_SET_PIN_WIDGET_CONTROL,
1714 PIN_OUT); 1710 PIN_OUT);
1715 if (vol_counter & 0x20) { 1711 if (vol_counter & 0x20) {
1716 /* decrease volume */ 1712 /* decrease volume */
@@ -1728,9 +1724,7 @@ static void via_gpio_control(struct hda_codec *codec)
1728 } 1724 }
1729 } else if (!(gpio_data & 0x02)) { 1725 } else if (!(gpio_data & 0x02)) {
1730 /* mute line out */ 1726 /* mute line out */
1731 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, 1727 snd_hda_set_pin_ctl(codec, spec->autocfg.line_out_pins[0], 0);
1732 AC_VERB_SET_PIN_WIDGET_CONTROL,
1733 0);
1734 } 1728 }
1735} 1729}
1736 1730
@@ -2757,8 +2751,7 @@ static void via_auto_init_dig_in(struct hda_codec *codec)
2757 struct via_spec *spec = codec->spec; 2751 struct via_spec *spec = codec->spec;
2758 if (!spec->dig_in_nid) 2752 if (!spec->dig_in_nid)
2759 return; 2753 return;
2760 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0, 2754 snd_hda_set_pin_ctl(codec, spec->autocfg.dig_in_pin, PIN_IN);
2761 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2762} 2755}
2763 2756
2764/* initialize the unsolicited events */ 2757/* initialize the unsolicited events */