aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/patch_realtek.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-02-21 14:34:25 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-21 14:34:25 -0500
commit460dc1eecf37263c8e3b17685ef236f0d236facb (patch)
tree1d20e367cefccddb969b48afaab140b8125cea4e /sound/pci/hda/patch_realtek.c
parent024e4ec1856d57bb78c06ec903d29dcf716f5f47 (diff)
parentb531f81b0d70ffbe8d70500512483227cc532608 (diff)
Merge tag 'sound-3.9' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
Pull sound updates from Takashi Iwai: "The biggest change in this update is the unification of HD-audio codec parsers. Now the HD-audio codec is parsed in a generic parser code which is invoked by each HD-audio codec driver. Some background information is found in David Henningsson's blog entry: http://voices.canonical.com/david.henningsson/2013/01/18/upcoming-changes-to-the-intel-hda-drivers/ Other than that, some random updates/fixes like USB-audio and a bunch of small AoC updates as usual. Highlights: - Unification of HD-audio parser code (aka generic parser) - Support of new Intel HD-audio controller, new IDT codecs - Fixes for HD-audio HDMI audio hotplug - Haswell HDMI audio fixup - Support of Creative CA0132 DSP code - A few fixes of HDSP driver - USB-audio fix for Roland A-PRO, M-Audio FT C600 - Support PM for aloop driver (and fixes Oops) - Compress API updates for gapless playback support For ASoC part: - Support for a wider range of hardware in the compressed stream code - The ability to mute capture streams as well as playback streams while inactive - DT support for AK4642, FSI, Samsung I2S and WM8962 - AC'97 support for Tegra - New driver for max98090, replacing the stub which was there - A new driver from Dialog Note that due to dependencies, DTification of DMA support for Samsung platforms (used only by the and I2S driver and SPI) is merged here as well." Fix up trivial conflict in drivers/spi/spi-s3c64xx.c due to removed code being changed. * tag 'sound-3.9' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound: (453 commits) ALSA: usb: Fix Processing Unit Descriptor parsers ALSA: hda - hdmi: Notify userspace when ELD control changes ALSA: hda - hdmi: Protect ELD buffer ALSA: hda - hdmi: Refactor hdmi_eld into parsed_hdmi_eld ALSA: hda - hdmi: Do not expose eld data when eld is invalid ALSA: hda - hdmi: ELD shouldn't be valid after unplug ALSA: hda - Fix the silent speaker output on Fujitsu S7020 laptop ALSA: hda - add quirks for mute LED on two HP machines ALSA: usb/quirks, fix out-of-bounds access ASoC: codecs: Add da7213 codec ALSA: au88x0 - Define channel map for au88x0 ALSA: compress: add support for gapless playback ALSA: hda - Remove speaker clicks on CX20549 ALSA: hda - Disable runtime PM for Intel 5 Series/3400 ALSA: hda - Increase badness for missing multi-io ASoC: arizona: Automatically manage input mutes ALSA: hda - Fix broken workaround for HDMI/SPDIF conflicts ALSA: hda/ca0132 - Add missing \n to debug prints ALSA: hda/ca0132 - Fix type of INVALID_CHIP_ADDRESS ALSA: hda - update documentation for no-primary-hp fixup ...
Diffstat (limited to 'sound/pci/hda/patch_realtek.c')
-rw-r--r--sound/pci/hda/patch_realtek.c4349
1 files changed, 534 insertions, 3815 deletions
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 5faaad219a7f..61478fd82565 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -27,6 +27,7 @@
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/pci.h> 29#include <linux/pci.h>
30#include <linux/dmi.h>
30#include <linux/module.h> 31#include <linux/module.h>
31#include <sound/core.h> 32#include <sound/core.h>
32#include <sound/jack.h> 33#include <sound/jack.h>
@@ -35,12 +36,10 @@
35#include "hda_auto_parser.h" 36#include "hda_auto_parser.h"
36#include "hda_beep.h" 37#include "hda_beep.h"
37#include "hda_jack.h" 38#include "hda_jack.h"
39#include "hda_generic.h"
38 40
39/* unsol event tags */ 41/* unsol event tags */
40#define ALC_FRONT_EVENT 0x01 42#define ALC_DCVOL_EVENT 0x08
41#define ALC_DCVOL_EVENT 0x02
42#define ALC_HP_EVENT 0x04
43#define ALC_MIC_EVENT 0x08
44 43
45/* for GPIO Poll */ 44/* for GPIO Poll */
46#define GPIO_MASK 0x03 45#define GPIO_MASK 0x03
@@ -67,355 +66,42 @@ struct alc_customize_define {
67 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */ 66 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
68}; 67};
69 68
70struct alc_multi_io {
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
74};
75
76enum {
77 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
80};
81
82#define MAX_VOL_NIDS 0x40
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
102struct alc_spec { 69struct alc_spec {
103 struct hda_gen_spec gen; 70 struct hda_gen_spec gen; /* must be at head */
104 71
105 /* codec parameterization */ 72 /* codec parameterization */
106 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ 73 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
107 unsigned int num_mixers; 74 unsigned int num_mixers;
108 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
109 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ 75 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
110 76
111 char stream_name_analog[32]; /* analog PCM stream */
112 const struct hda_pcm_stream *stream_analog_playback;
113 const struct hda_pcm_stream *stream_analog_capture;
114 const struct hda_pcm_stream *stream_analog_alt_playback;
115 const struct hda_pcm_stream *stream_analog_alt_capture;
116
117 char stream_name_digital[32]; /* digital PCM stream */
118 const struct hda_pcm_stream *stream_digital_playback;
119 const struct hda_pcm_stream *stream_digital_capture;
120
121 /* playback */
122 struct hda_multi_out multiout; /* playback set-up
123 * max_channels, dacs must be set
124 * dig_out_nid and hp_nid are optional
125 */
126 hda_nid_t alt_dac_nid;
127 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
128 int dig_out_type;
129
130 /* capture */
131 unsigned int num_adc_nids;
132 const hda_nid_t *adc_nids;
133 const hda_nid_t *capsrc_nids;
134 hda_nid_t dig_in_nid; /* digital-in NID; optional */
135 hda_nid_t mixer_nid; /* analog-mixer NID */
136 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
137 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
138
139 /* capture setup for dynamic dual-adc switch */
140 hda_nid_t cur_adc;
141 unsigned int cur_adc_stream_tag;
142 unsigned int cur_adc_format;
143
144 /* capture source */
145 unsigned int num_mux_defs;
146 const struct hda_input_mux *input_mux;
147 unsigned int cur_mux[3];
148 hda_nid_t ext_mic_pin;
149 hda_nid_t dock_mic_pin;
150 hda_nid_t int_mic_pin;
151
152 /* channel model */
153 const struct hda_channel_mode *channel_mode;
154 int num_channel_mode;
155 int need_dac_fix;
156 int const_channel_count; /* min. channel count (for speakers) */
157 int ext_channel_count; /* current channel count for multi-io */
158
159 /* PCM information */
160 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
161
162 /* dynamic controls, init_verbs and input_mux */
163 struct auto_pin_cfg autocfg;
164 struct alc_customize_define cdefine; 77 struct alc_customize_define cdefine;
165 struct snd_array kctls; 78 unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
166 struct hda_input_mux private_imux[3]; 79
167 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 80 /* inverted dmic fix */
168 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS]; 81 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
169 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS]; 82 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
170 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
171 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
172 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
173 hda_nid_t inv_dmic_pin; 83 hda_nid_t inv_dmic_pin;
174 84
85 /* mute LED for HP laptops, see alc269_fixup_mic_mute_hook() */
86 int mute_led_polarity;
87 hda_nid_t mute_led_nid;
88
175 /* hooks */ 89 /* hooks */
176 void (*init_hook)(struct hda_codec *codec); 90 void (*init_hook)(struct hda_codec *codec);
177#ifdef CONFIG_PM 91#ifdef CONFIG_PM
178 void (*power_hook)(struct hda_codec *codec); 92 void (*power_hook)(struct hda_codec *codec);
179#endif 93#endif
180 void (*shutup)(struct hda_codec *codec); 94 void (*shutup)(struct hda_codec *codec);
181 void (*automute_hook)(struct hda_codec *codec);
182
183 /* for pin sensing */
184 unsigned int hp_jack_present:1;
185 unsigned int line_jack_present:1;
186 unsigned int master_mute:1;
187 unsigned int auto_mic:1;
188 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
189 unsigned int automute_speaker:1; /* automute speaker outputs */
190 unsigned int automute_lo:1; /* automute LO outputs */
191 unsigned int detect_hp:1; /* Headphone detection enabled */
192 unsigned int detect_lo:1; /* Line-out detection enabled */
193 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
194 unsigned int automute_lo_possible:1; /* there are line outs and HP */
195 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
196
197 /* other flags */
198 unsigned int no_analog :1; /* digital I/O only */
199 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
200 unsigned int single_input_src:1;
201 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
202 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
203 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
204 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
205 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
206 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
207
208 /* auto-mute control */
209 int automute_mode;
210 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
211 95
212 int init_amp; 96 int init_amp;
213 int codec_variant; /* flag for other variants */ 97 int codec_variant; /* flag for other variants */
214 98
215 /* for virtual master */
216 hda_nid_t vmaster_nid;
217 struct hda_vmaster_mute_hook vmaster_mute;
218#ifdef CONFIG_PM
219 struct hda_loopback_check loopback;
220 int num_loopbacks;
221 struct hda_amp_list loopback_list[8];
222#endif
223
224 /* for PLL fix */ 99 /* for PLL fix */
225 hda_nid_t pll_nid; 100 hda_nid_t pll_nid;
226 unsigned int pll_coef_idx, pll_coef_bit; 101 unsigned int pll_coef_idx, pll_coef_bit;
227 unsigned int coef0; 102 unsigned int coef0;
228
229 /* multi-io */
230 int multi_ios;
231 struct alc_multi_io multi_io[4];
232
233 /* bind volumes */
234 struct snd_array bind_ctls;
235}; 103};
236 104
237static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
238 int dir, unsigned int bits)
239{
240 if (!nid)
241 return false;
242 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
243 if (query_amp_caps(codec, nid, dir) & bits)
244 return true;
245 return false;
246}
247
248#define nid_has_mute(codec, nid, dir) \
249 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
250#define nid_has_volume(codec, nid, dir) \
251 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
252
253/*
254 * input MUX handling
255 */
256static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_info *uinfo)
258{
259 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
260 struct alc_spec *spec = codec->spec;
261 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
262 if (mux_idx >= spec->num_mux_defs)
263 mux_idx = 0;
264 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
265 mux_idx = 0;
266 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
267}
268
269static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
270 struct snd_ctl_elem_value *ucontrol)
271{
272 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
273 struct alc_spec *spec = codec->spec;
274 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
275
276 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
277 return 0;
278}
279
280static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
281{
282 struct alc_spec *spec = codec->spec;
283 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
284
285 if (spec->cur_adc && spec->cur_adc != new_adc) {
286 /* stream is running, let's swap the current ADC */
287 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
288 spec->cur_adc = new_adc;
289 snd_hda_codec_setup_stream(codec, new_adc,
290 spec->cur_adc_stream_tag, 0,
291 spec->cur_adc_format);
292 return true;
293 }
294 return false;
295}
296
297static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
298{
299 return spec->capsrc_nids ?
300 spec->capsrc_nids[idx] : spec->adc_nids[idx];
301}
302
303static void call_update_outputs(struct hda_codec *codec);
304static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
305
306/* for shared I/O, change the pin-control accordingly */
307static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
308{
309 struct alc_spec *spec = codec->spec;
310 unsigned int val;
311 hda_nid_t pin = spec->autocfg.inputs[1].pin;
312 /* NOTE: this assumes that there are only two inputs, the
313 * first is the real internal mic and the second is HP/mic jack.
314 */
315
316 val = snd_hda_get_default_vref(codec, pin);
317
318 /* This pin does not have vref caps - let's enable vref on pin 0x18
319 instead, as suggested by Realtek */
320 if (val == AC_PINCTL_VREF_HIZ) {
321 const hda_nid_t vref_pin = 0x18;
322 /* Sanity check pin 0x18 */
323 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
324 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
325 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
326 if (vref_val != AC_PINCTL_VREF_HIZ)
327 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
328 }
329 }
330
331 val = set_as_mic ? val | PIN_IN : PIN_HP;
332 snd_hda_set_pin_ctl(codec, pin, val);
333
334 spec->automute_speaker = !set_as_mic;
335 call_update_outputs(codec);
336}
337
338/* select the given imux item; either unmute exclusively or select the route */
339static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
340 unsigned int idx, bool force)
341{
342 struct alc_spec *spec = codec->spec;
343 const struct hda_input_mux *imux;
344 unsigned int mux_idx;
345 int i, type, num_conns;
346 hda_nid_t nid;
347
348 if (!spec->input_mux)
349 return 0;
350
351 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
352 imux = &spec->input_mux[mux_idx];
353 if (!imux->num_items && mux_idx > 0)
354 imux = &spec->input_mux[0];
355 if (!imux->num_items)
356 return 0;
357
358 if (idx >= imux->num_items)
359 idx = imux->num_items - 1;
360 if (spec->cur_mux[adc_idx] == idx && !force)
361 return 0;
362 spec->cur_mux[adc_idx] = idx;
363
364 if (spec->shared_mic_hp)
365 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
366
367 if (spec->dyn_adc_switch) {
368 alc_dyn_adc_pcm_resetup(codec, idx);
369 adc_idx = spec->dyn_adc_idx[idx];
370 }
371
372 nid = get_capsrc(spec, adc_idx);
373
374 /* no selection? */
375 num_conns = snd_hda_get_num_conns(codec, nid);
376 if (num_conns <= 1)
377 return 1;
378
379 type = get_wcaps_type(get_wcaps(codec, nid));
380 if (type == AC_WID_AUD_MIX) {
381 /* Matrix-mixer style (e.g. ALC882) */
382 int active = imux->items[idx].index;
383 for (i = 0; i < num_conns; i++) {
384 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
385 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
386 HDA_AMP_MUTE, v);
387 }
388 } else {
389 /* MUX style (e.g. ALC880) */
390 snd_hda_codec_write_cache(codec, nid, 0,
391 AC_VERB_SET_CONNECT_SEL,
392 imux->items[idx].index);
393 }
394 alc_inv_dmic_sync(codec, true);
395 return 1;
396}
397
398static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
399 struct snd_ctl_elem_value *ucontrol)
400{
401 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
402 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
403 return alc_mux_select(codec, adc_idx,
404 ucontrol->value.enumerated.item[0], false);
405}
406
407/*
408 * set up the input pin config (depending on the given auto-pin type)
409 */
410static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
411 int auto_pin_type)
412{
413 unsigned int val = PIN_IN;
414 if (auto_pin_type == AUTO_PIN_MIC)
415 val |= snd_hda_get_default_vref(codec, nid);
416 snd_hda_set_pin_ctl(codec, nid, val);
417}
418
419/* 105/*
420 * Append the given mixer and verb elements for the later use 106 * Append the given mixer and verb elements for the later use
421 * The mixer array is referred in build_controls(), and init_verbs are 107 * The mixer array is referred in build_controls(), and init_verbs are
@@ -485,171 +171,6 @@ static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
485 alc_fix_pll(codec); 171 alc_fix_pll(codec);
486} 172}
487 173
488/*
489 * Jack detections for HP auto-mute and mic-switch
490 */
491
492/* check each pin in the given array; returns true if any of them is plugged */
493static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
494{
495 int i, present = 0;
496
497 for (i = 0; i < num_pins; i++) {
498 hda_nid_t nid = pins[i];
499 if (!nid)
500 break;
501 present |= snd_hda_jack_detect(codec, nid);
502 }
503 return present;
504}
505
506/* standard HP/line-out auto-mute helper */
507static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
508 bool mute, bool hp_out)
509{
510 struct alc_spec *spec = codec->spec;
511 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
512 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
513 int i;
514
515 for (i = 0; i < num_pins; i++) {
516 hda_nid_t nid = pins[i];
517 unsigned int val;
518 if (!nid)
519 break;
520 switch (spec->automute_mode) {
521 case ALC_AUTOMUTE_PIN:
522 /* don't reset VREF value in case it's controlling
523 * the amp (see alc861_fixup_asus_amp_vref_0f())
524 */
525 if (spec->keep_vref_in_automute) {
526 val = snd_hda_codec_read(codec, nid, 0,
527 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
528 val &= ~PIN_HP;
529 } else
530 val = 0;
531 val |= pin_bits;
532 snd_hda_set_pin_ctl(codec, nid, val);
533 break;
534 case ALC_AUTOMUTE_AMP:
535 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
536 HDA_AMP_MUTE, mute_bits);
537 break;
538 case ALC_AUTOMUTE_MIXER:
539 nid = spec->automute_mixer_nid[i];
540 if (!nid)
541 break;
542 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
543 HDA_AMP_MUTE, mute_bits);
544 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
545 HDA_AMP_MUTE, mute_bits);
546 break;
547 }
548 }
549}
550
551/* Toggle outputs muting */
552static void update_outputs(struct hda_codec *codec)
553{
554 struct alc_spec *spec = codec->spec;
555 int on;
556
557 /* Control HP pins/amps depending on master_mute state;
558 * in general, HP pins/amps control should be enabled in all cases,
559 * but currently set only for master_mute, just to be safe
560 */
561 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
562 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
563 spec->autocfg.hp_pins, spec->master_mute, true);
564
565 if (!spec->automute_speaker)
566 on = 0;
567 else
568 on = spec->hp_jack_present | spec->line_jack_present;
569 on |= spec->master_mute;
570 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
571 spec->autocfg.speaker_pins, on, false);
572
573 /* toggle line-out mutes if needed, too */
574 /* if LO is a copy of either HP or Speaker, don't need to handle it */
575 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
576 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
577 return;
578 if (!spec->automute_lo)
579 on = 0;
580 else
581 on = spec->hp_jack_present;
582 on |= spec->master_mute;
583 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
584 spec->autocfg.line_out_pins, on, false);
585}
586
587static void call_update_outputs(struct hda_codec *codec)
588{
589 struct alc_spec *spec = codec->spec;
590 if (spec->automute_hook)
591 spec->automute_hook(codec);
592 else
593 update_outputs(codec);
594}
595
596/* standard HP-automute helper */
597static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
598{
599 struct alc_spec *spec = codec->spec;
600
601 spec->hp_jack_present =
602 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
603 spec->autocfg.hp_pins);
604 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
605 return;
606 call_update_outputs(codec);
607}
608
609/* standard line-out-automute helper */
610static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
611{
612 struct alc_spec *spec = codec->spec;
613
614 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
615 return;
616 /* check LO jack only when it's different from HP */
617 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
618 return;
619
620 spec->line_jack_present =
621 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
622 spec->autocfg.line_out_pins);
623 if (!spec->automute_speaker || !spec->detect_lo)
624 return;
625 call_update_outputs(codec);
626}
627
628#define get_connection_index(codec, mux, nid) \
629 snd_hda_get_conn_index(codec, mux, nid, 0)
630
631/* standard mic auto-switch helper */
632static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
633{
634 struct alc_spec *spec = codec->spec;
635 hda_nid_t *pins = spec->imux_pins;
636
637 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
638 return;
639 if (snd_BUG_ON(!spec->adc_nids))
640 return;
641 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
642 return;
643
644 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
645 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
646 else if (spec->dock_mic_idx >= 0 &&
647 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
648 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
649 else
650 alc_mux_select(codec, 0, spec->int_mic_idx, false);
651}
652
653/* update the master volume per volume-knob's unsol event */ 174/* update the master volume per volume-knob's unsol event */
654static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack) 175static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
655{ 176{
@@ -679,14 +200,6 @@ static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
679 snd_hda_jack_unsol_event(codec, res >> 2); 200 snd_hda_jack_unsol_event(codec, res >> 2);
680} 201}
681 202
682/* call init functions of standard auto-mute helpers */
683static void alc_inithook(struct hda_codec *codec)
684{
685 alc_hp_automute(codec, NULL);
686 alc_line_automute(codec, NULL);
687 alc_mic_automute(codec, NULL);
688}
689
690/* additional initialization for ALC888 variants */ 203/* additional initialization for ALC888 variants */
691static void alc888_coef_init(struct hda_codec *codec) 204static void alc888_coef_init(struct hda_codec *codec)
692{ 205{
@@ -807,366 +320,6 @@ static void alc_auto_init_amp(struct hda_codec *codec, int type)
807 } 320 }
808} 321}
809 322
810/*
811 * Auto-Mute mode mixer enum support
812 */
813static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
814 struct snd_ctl_elem_info *uinfo)
815{
816 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
817 struct alc_spec *spec = codec->spec;
818 static const char * const texts3[] = {
819 "Disabled", "Speaker Only", "Line Out+Speaker"
820 };
821
822 if (spec->automute_speaker_possible && spec->automute_lo_possible)
823 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
824 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
825}
826
827static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
828 struct snd_ctl_elem_value *ucontrol)
829{
830 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
831 struct alc_spec *spec = codec->spec;
832 unsigned int val = 0;
833 if (spec->automute_speaker)
834 val++;
835 if (spec->automute_lo)
836 val++;
837
838 ucontrol->value.enumerated.item[0] = val;
839 return 0;
840}
841
842static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
843 struct snd_ctl_elem_value *ucontrol)
844{
845 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
846 struct alc_spec *spec = codec->spec;
847
848 switch (ucontrol->value.enumerated.item[0]) {
849 case 0:
850 if (!spec->automute_speaker && !spec->automute_lo)
851 return 0;
852 spec->automute_speaker = 0;
853 spec->automute_lo = 0;
854 break;
855 case 1:
856 if (spec->automute_speaker_possible) {
857 if (!spec->automute_lo && spec->automute_speaker)
858 return 0;
859 spec->automute_speaker = 1;
860 spec->automute_lo = 0;
861 } else if (spec->automute_lo_possible) {
862 if (spec->automute_lo)
863 return 0;
864 spec->automute_lo = 1;
865 } else
866 return -EINVAL;
867 break;
868 case 2:
869 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
870 return -EINVAL;
871 if (spec->automute_speaker && spec->automute_lo)
872 return 0;
873 spec->automute_speaker = 1;
874 spec->automute_lo = 1;
875 break;
876 default:
877 return -EINVAL;
878 }
879 call_update_outputs(codec);
880 return 1;
881}
882
883static const struct snd_kcontrol_new alc_automute_mode_enum = {
884 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
885 .name = "Auto-Mute Mode",
886 .info = alc_automute_mode_info,
887 .get = alc_automute_mode_get,
888 .put = alc_automute_mode_put,
889};
890
891static struct snd_kcontrol_new *
892alc_kcontrol_new(struct alc_spec *spec, const char *name,
893 const struct snd_kcontrol_new *temp)
894{
895 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
896 if (!knew)
897 return NULL;
898 *knew = *temp;
899 knew->name = kstrdup(name, GFP_KERNEL);
900 if (!knew->name)
901 return NULL;
902 return knew;
903}
904
905static int alc_add_automute_mode_enum(struct hda_codec *codec)
906{
907 struct alc_spec *spec = codec->spec;
908
909 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
910 return -ENOMEM;
911 return 0;
912}
913
914/*
915 * Check the availability of HP/line-out auto-mute;
916 * Set up appropriately if really supported
917 */
918static int alc_init_automute(struct hda_codec *codec)
919{
920 struct alc_spec *spec = codec->spec;
921 struct auto_pin_cfg *cfg = &spec->autocfg;
922 int present = 0;
923 int i, err;
924
925 if (cfg->hp_pins[0])
926 present++;
927 if (cfg->line_out_pins[0])
928 present++;
929 if (cfg->speaker_pins[0])
930 present++;
931 if (present < 2) /* need two different output types */
932 return 0;
933
934 if (!cfg->speaker_pins[0] &&
935 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
936 memcpy(cfg->speaker_pins, cfg->line_out_pins,
937 sizeof(cfg->speaker_pins));
938 cfg->speaker_outs = cfg->line_outs;
939 }
940
941 if (!cfg->hp_pins[0] &&
942 cfg->line_out_type == AUTO_PIN_HP_OUT) {
943 memcpy(cfg->hp_pins, cfg->line_out_pins,
944 sizeof(cfg->hp_pins));
945 cfg->hp_outs = cfg->line_outs;
946 }
947
948 spec->automute_mode = ALC_AUTOMUTE_PIN;
949
950 for (i = 0; i < cfg->hp_outs; i++) {
951 hda_nid_t nid = cfg->hp_pins[i];
952 if (!is_jack_detectable(codec, nid))
953 continue;
954 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
955 nid);
956 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
957 alc_hp_automute);
958 spec->detect_hp = 1;
959 }
960
961 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
962 if (cfg->speaker_outs)
963 for (i = 0; i < cfg->line_outs; i++) {
964 hda_nid_t nid = cfg->line_out_pins[i];
965 if (!is_jack_detectable(codec, nid))
966 continue;
967 snd_printdd("realtek: Enable Line-Out "
968 "auto-muting on NID 0x%x\n", nid);
969 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
970 alc_line_automute);
971 spec->detect_lo = 1;
972 }
973 spec->automute_lo_possible = spec->detect_hp;
974 }
975
976 spec->automute_speaker_possible = cfg->speaker_outs &&
977 (spec->detect_hp || spec->detect_lo);
978
979 spec->automute_lo = spec->automute_lo_possible;
980 spec->automute_speaker = spec->automute_speaker_possible;
981
982 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
983 /* create a control for automute mode */
984 err = alc_add_automute_mode_enum(codec);
985 if (err < 0)
986 return err;
987 }
988 return 0;
989}
990
991/* return the position of NID in the list, or -1 if not found */
992static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
993{
994 int i;
995 for (i = 0; i < nums; i++)
996 if (list[i] == nid)
997 return i;
998 return -1;
999}
1000
1001/* check whether dynamic ADC-switching is available */
1002static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1003{
1004 struct alc_spec *spec = codec->spec;
1005 struct hda_input_mux *imux = &spec->private_imux[0];
1006 int i, n, idx;
1007 hda_nid_t cap, pin;
1008
1009 if (imux != spec->input_mux) /* no dynamic imux? */
1010 return false;
1011
1012 for (n = 0; n < spec->num_adc_nids; n++) {
1013 cap = spec->private_capsrc_nids[n];
1014 for (i = 0; i < imux->num_items; i++) {
1015 pin = spec->imux_pins[i];
1016 if (!pin)
1017 return false;
1018 if (get_connection_index(codec, cap, pin) < 0)
1019 break;
1020 }
1021 if (i >= imux->num_items)
1022 return true; /* no ADC-switch is needed */
1023 }
1024
1025 for (i = 0; i < imux->num_items; i++) {
1026 pin = spec->imux_pins[i];
1027 for (n = 0; n < spec->num_adc_nids; n++) {
1028 cap = spec->private_capsrc_nids[n];
1029 idx = get_connection_index(codec, cap, pin);
1030 if (idx >= 0) {
1031 imux->items[i].index = idx;
1032 spec->dyn_adc_idx[i] = n;
1033 break;
1034 }
1035 }
1036 }
1037
1038 snd_printdd("realtek: enabling ADC switching\n");
1039 spec->dyn_adc_switch = 1;
1040 return true;
1041}
1042
1043/* check whether all auto-mic pins are valid; setup indices if OK */
1044static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1045{
1046 struct alc_spec *spec = codec->spec;
1047 const struct hda_input_mux *imux;
1048
1049 if (!spec->auto_mic)
1050 return false;
1051 if (spec->auto_mic_valid_imux)
1052 return true; /* already checked */
1053
1054 /* fill up imux indices */
1055 if (!alc_check_dyn_adc_switch(codec)) {
1056 spec->auto_mic = 0;
1057 return false;
1058 }
1059
1060 imux = spec->input_mux;
1061 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1062 spec->imux_pins, imux->num_items);
1063 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1064 spec->imux_pins, imux->num_items);
1065 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1066 spec->imux_pins, imux->num_items);
1067 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1068 spec->auto_mic = 0;
1069 return false; /* no corresponding imux */
1070 }
1071
1072 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1073 ALC_MIC_EVENT, alc_mic_automute);
1074 if (spec->dock_mic_pin)
1075 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1076 ALC_MIC_EVENT,
1077 alc_mic_automute);
1078
1079 spec->auto_mic_valid_imux = 1;
1080 spec->auto_mic = 1;
1081 return true;
1082}
1083
1084/*
1085 * Check the availability of auto-mic switch;
1086 * Set up if really supported
1087 */
1088static int alc_init_auto_mic(struct hda_codec *codec)
1089{
1090 struct alc_spec *spec = codec->spec;
1091 struct auto_pin_cfg *cfg = &spec->autocfg;
1092 hda_nid_t fixed, ext, dock;
1093 int i;
1094
1095 if (spec->shared_mic_hp)
1096 return 0; /* no auto-mic for the shared I/O */
1097
1098 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1099
1100 fixed = ext = dock = 0;
1101 for (i = 0; i < cfg->num_inputs; i++) {
1102 hda_nid_t nid = cfg->inputs[i].pin;
1103 unsigned int defcfg;
1104 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1105 switch (snd_hda_get_input_pin_attr(defcfg)) {
1106 case INPUT_PIN_ATTR_INT:
1107 if (fixed)
1108 return 0; /* already occupied */
1109 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1110 return 0; /* invalid type */
1111 fixed = nid;
1112 break;
1113 case INPUT_PIN_ATTR_UNUSED:
1114 return 0; /* invalid entry */
1115 case INPUT_PIN_ATTR_DOCK:
1116 if (dock)
1117 return 0; /* already occupied */
1118 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1119 return 0; /* invalid type */
1120 dock = nid;
1121 break;
1122 default:
1123 if (ext)
1124 return 0; /* already occupied */
1125 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1126 return 0; /* invalid type */
1127 ext = nid;
1128 break;
1129 }
1130 }
1131 if (!ext && dock) {
1132 ext = dock;
1133 dock = 0;
1134 }
1135 if (!ext || !fixed)
1136 return 0;
1137 if (!is_jack_detectable(codec, ext))
1138 return 0; /* no unsol support */
1139 if (dock && !is_jack_detectable(codec, dock))
1140 return 0; /* no unsol support */
1141
1142 /* check imux indices */
1143 spec->ext_mic_pin = ext;
1144 spec->int_mic_pin = fixed;
1145 spec->dock_mic_pin = dock;
1146
1147 spec->auto_mic = 1;
1148 if (!alc_auto_mic_check_imux(codec))
1149 return 0;
1150
1151 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1152 ext, fixed, dock);
1153
1154 return 0;
1155}
1156
1157/* check the availabilities of auto-mute and auto-mic switches */
1158static int alc_auto_check_switches(struct hda_codec *codec)
1159{
1160 int err;
1161
1162 err = alc_init_automute(codec);
1163 if (err < 0)
1164 return err;
1165 err = alc_init_auto_mic(codec);
1166 if (err < 0)
1167 return err;
1168 return 0;
1169}
1170 323
1171/* 324/*
1172 * Realtek SSID verification 325 * Realtek SSID verification
@@ -1252,6 +405,15 @@ do_sku:
1252 return 0; 405 return 0;
1253} 406}
1254 407
408/* return the position of NID in the list, or -1 if not found */
409static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
410{
411 int i;
412 for (i = 0; i < nums; i++)
413 if (list[i] == nid)
414 return i;
415 return -1;
416}
1255/* return true if the given NID is found in the list */ 417/* return true if the given NID is found in the list */
1256static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) 418static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1257{ 419{
@@ -1354,9 +516,9 @@ do_sku:
1354 * 15 : 1 --> enable the function "Mute internal speaker 516 * 15 : 1 --> enable the function "Mute internal speaker
1355 * when the external headphone out jack is plugged" 517 * when the external headphone out jack is plugged"
1356 */ 518 */
1357 if (!spec->autocfg.hp_pins[0] && 519 if (!spec->gen.autocfg.hp_pins[0] &&
1358 !(spec->autocfg.line_out_pins[0] && 520 !(spec->gen.autocfg.line_out_pins[0] &&
1359 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) { 521 spec->gen.autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1360 hda_nid_t nid; 522 hda_nid_t nid;
1361 tmp = (ass >> 11) & 0x3; /* HP to chassis */ 523 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1362 if (tmp == 0) 524 if (tmp == 0)
@@ -1369,10 +531,10 @@ do_sku:
1369 nid = porti; 531 nid = porti;
1370 else 532 else
1371 return 1; 533 return 1;
1372 if (found_in_nid_list(nid, spec->autocfg.line_out_pins, 534 if (found_in_nid_list(nid, spec->gen.autocfg.line_out_pins,
1373 spec->autocfg.line_outs)) 535 spec->gen.autocfg.line_outs))
1374 return 1; 536 return 1;
1375 spec->autocfg.hp_pins[0] = nid; 537 spec->gen.autocfg.hp_pins[0] = nid;
1376 } 538 }
1377 return 1; 539 return 1;
1378} 540}
@@ -1422,252 +584,54 @@ static unsigned int alc_get_coef0(struct hda_codec *codec)
1422} 584}
1423 585
1424/* 586/*
1425 * Digital I/O handling
1426 */ 587 */
1427 588
1428/* set right pin controls for digital I/O */ 589static hda_nid_t get_adc_nid(struct hda_codec *codec, int adc_idx, int imux_idx)
1429static void alc_auto_init_digital(struct hda_codec *codec)
1430{ 590{
1431 struct alc_spec *spec = codec->spec; 591 struct hda_gen_spec *spec = codec->spec;
1432 int i; 592 if (spec->dyn_adc_switch)
1433 hda_nid_t pin, dac; 593 adc_idx = spec->dyn_adc_idx[imux_idx];
1434 594 return spec->adc_nids[adc_idx];
1435 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1436 pin = spec->autocfg.dig_out_pins[i];
1437 if (!pin)
1438 continue;
1439 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
1440 if (!i)
1441 dac = spec->multiout.dig_out_nid;
1442 else
1443 dac = spec->slave_dig_outs[i - 1];
1444 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1445 continue;
1446 snd_hda_codec_write(codec, dac, 0,
1447 AC_VERB_SET_AMP_GAIN_MUTE,
1448 AMP_OUT_UNMUTE);
1449 }
1450 pin = spec->autocfg.dig_in_pin;
1451 if (pin)
1452 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
1453}
1454
1455/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1456static void alc_auto_parse_digital(struct hda_codec *codec)
1457{
1458 struct alc_spec *spec = codec->spec;
1459 int i, err, nums;
1460 hda_nid_t dig_nid;
1461
1462 /* support multiple SPDIFs; the secondary is set up as a slave */
1463 nums = 0;
1464 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1465 hda_nid_t conn[4];
1466 err = snd_hda_get_connections(codec,
1467 spec->autocfg.dig_out_pins[i],
1468 conn, ARRAY_SIZE(conn));
1469 if (err <= 0)
1470 continue;
1471 dig_nid = conn[0]; /* assume the first element is audio-out */
1472 if (!nums) {
1473 spec->multiout.dig_out_nid = dig_nid;
1474 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1475 } else {
1476 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1477 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1478 break;
1479 spec->slave_dig_outs[nums - 1] = dig_nid;
1480 }
1481 nums++;
1482 }
1483
1484 if (spec->autocfg.dig_in_pin) {
1485 dig_nid = codec->start_nid;
1486 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1487 unsigned int wcaps = get_wcaps(codec, dig_nid);
1488 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1489 continue;
1490 if (!(wcaps & AC_WCAP_DIGITAL))
1491 continue;
1492 if (!(wcaps & AC_WCAP_CONN_LIST))
1493 continue;
1494 err = get_connection_index(codec, dig_nid,
1495 spec->autocfg.dig_in_pin);
1496 if (err >= 0) {
1497 spec->dig_in_nid = dig_nid;
1498 break;
1499 }
1500 }
1501 }
1502}
1503
1504/*
1505 * capture mixer elements
1506 */
1507static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1508 struct snd_ctl_elem_info *uinfo)
1509{
1510 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1511 struct alc_spec *spec = codec->spec;
1512 unsigned long val;
1513 int err;
1514
1515 mutex_lock(&codec->control_mutex);
1516 if (spec->vol_in_capsrc)
1517 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1518 else
1519 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1520 kcontrol->private_value = val;
1521 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1522 mutex_unlock(&codec->control_mutex);
1523 return err;
1524}
1525
1526static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1527 unsigned int size, unsigned int __user *tlv)
1528{
1529 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1530 struct alc_spec *spec = codec->spec;
1531 unsigned long val;
1532 int err;
1533
1534 mutex_lock(&codec->control_mutex);
1535 if (spec->vol_in_capsrc)
1536 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1537 else
1538 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1539 kcontrol->private_value = val;
1540 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1541 mutex_unlock(&codec->control_mutex);
1542 return err;
1543} 595}
1544 596
1545typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol, 597static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx)
1546 struct snd_ctl_elem_value *ucontrol);
1547
1548static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1549 struct snd_ctl_elem_value *ucontrol,
1550 getput_call_t func, bool is_put)
1551{ 598{
1552 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1553 struct alc_spec *spec = codec->spec; 599 struct alc_spec *spec = codec->spec;
1554 int i, err = 0; 600 struct hda_input_mux *imux = &spec->gen.input_mux;
1555 601 struct nid_path *path;
1556 mutex_lock(&codec->control_mutex); 602 hda_nid_t nid;
1557 if (is_put && spec->dyn_adc_switch) { 603 int i, dir, parm;
1558 for (i = 0; i < spec->num_adc_nids; i++) { 604 unsigned int val;
1559 kcontrol->private_value =
1560 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1561 3, 0, HDA_INPUT);
1562 err = func(kcontrol, ucontrol);
1563 if (err < 0)
1564 goto error;
1565 }
1566 } else {
1567 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1568 if (spec->vol_in_capsrc)
1569 kcontrol->private_value =
1570 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1571 3, 0, HDA_OUTPUT);
1572 else
1573 kcontrol->private_value =
1574 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1575 3, 0, HDA_INPUT);
1576 err = func(kcontrol, ucontrol);
1577 }
1578 if (err >= 0 && is_put)
1579 alc_inv_dmic_sync(codec, false);
1580 error:
1581 mutex_unlock(&codec->control_mutex);
1582 return err;
1583}
1584
1585static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1586 struct snd_ctl_elem_value *ucontrol)
1587{
1588 return alc_cap_getput_caller(kcontrol, ucontrol,
1589 snd_hda_mixer_amp_volume_get, false);
1590}
1591
1592static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1593 struct snd_ctl_elem_value *ucontrol)
1594{
1595 return alc_cap_getput_caller(kcontrol, ucontrol,
1596 snd_hda_mixer_amp_volume_put, true);
1597}
1598
1599/* capture mixer elements */
1600#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1601
1602static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1603 struct snd_ctl_elem_value *ucontrol)
1604{
1605 return alc_cap_getput_caller(kcontrol, ucontrol,
1606 snd_hda_mixer_amp_switch_get, false);
1607}
1608
1609static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1610 struct snd_ctl_elem_value *ucontrol)
1611{
1612 return alc_cap_getput_caller(kcontrol, ucontrol,
1613 snd_hda_mixer_amp_switch_put, true);
1614}
1615 605
1616#define _DEFINE_CAPMIX(num) \ 606 for (i = 0; i < imux->num_items; i++) {
1617 { \ 607 if (spec->gen.imux_pins[i] == spec->inv_dmic_pin)
1618 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 608 break;
1619 .name = "Capture Switch", \
1620 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1621 .count = num, \
1622 .info = alc_cap_sw_info, \
1623 .get = alc_cap_sw_get, \
1624 .put = alc_cap_sw_put, \
1625 }, \
1626 { \
1627 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1628 .name = "Capture Volume", \
1629 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1630 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1631 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1632 .count = num, \
1633 .info = alc_cap_vol_info, \
1634 .get = alc_cap_vol_get, \
1635 .put = alc_cap_vol_put, \
1636 .tlv = { .c = alc_cap_vol_tlv }, \
1637 } 609 }
610 if (i >= imux->num_items)
611 return;
1638 612
1639#define _DEFINE_CAPSRC(num) \ 613 path = snd_hda_get_nid_path(codec, spec->inv_dmic_pin,
1640 { \ 614 get_adc_nid(codec, adc_idx, i));
1641 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 615 val = path->ctls[NID_PATH_MUTE_CTL];
1642 /* .name = "Capture Source", */ \ 616 if (!val)
1643 .name = "Input Source", \ 617 return;
1644 .count = num, \ 618 nid = get_amp_nid_(val);
1645 .info = alc_mux_enum_info, \ 619 dir = get_amp_direction_(val);
1646 .get = alc_mux_enum_get, \ 620 parm = AC_AMP_SET_RIGHT |
1647 .put = alc_mux_enum_put, \ 621 (dir == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT);
1648 }
1649 622
1650#define DEFINE_CAPMIX(num) \ 623 /* flush all cached amps at first */
1651static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \ 624 snd_hda_codec_flush_cache(codec);
1652 _DEFINE_CAPMIX(num), \
1653 _DEFINE_CAPSRC(num), \
1654 { } /* end */ \
1655}
1656 625
1657#define DEFINE_CAPMIX_NOSRC(num) \ 626 /* we care only right channel */
1658static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \ 627 val = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1659 _DEFINE_CAPMIX(num), \ 628 if (val & 0x80) /* if already muted, we don't need to touch */
1660 { } /* end */ \ 629 return;
630 val |= 0x80;
631 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
632 parm | val);
1661} 633}
1662 634
1663/* up to three ADCs */
1664DEFINE_CAPMIX(1);
1665DEFINE_CAPMIX(2);
1666DEFINE_CAPMIX(3);
1667DEFINE_CAPMIX_NOSRC(1);
1668DEFINE_CAPMIX_NOSRC(2);
1669DEFINE_CAPMIX_NOSRC(3);
1670
1671/* 635/*
1672 * Inverted digital-mic handling 636 * Inverted digital-mic handling
1673 * 637 *
@@ -1686,43 +650,31 @@ DEFINE_CAPMIX_NOSRC(3);
1686static void alc_inv_dmic_sync(struct hda_codec *codec, bool force) 650static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1687{ 651{
1688 struct alc_spec *spec = codec->spec; 652 struct alc_spec *spec = codec->spec;
1689 int i; 653 int src, nums;
1690 654
1691 if (!spec->inv_dmic_fixup) 655 if (!spec->inv_dmic_fixup)
1692 return; 656 return;
1693 if (!spec->inv_dmic_muted && !force) 657 if (!spec->inv_dmic_muted && !force)
1694 return; 658 return;
1695 for (i = 0; i < spec->num_adc_nids; i++) { 659 nums = spec->gen.dyn_adc_switch ? 1 : spec->gen.num_adc_nids;
1696 int src = spec->dyn_adc_switch ? 0 : i; 660 for (src = 0; src < nums; src++) {
1697 bool dmic_fixup = false; 661 bool dmic_fixup = false;
1698 hda_nid_t nid;
1699 int parm, dir, v;
1700 662
1701 if (spec->inv_dmic_muted && 663 if (spec->inv_dmic_muted &&
1702 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin) 664 spec->gen.imux_pins[spec->gen.cur_mux[src]] == spec->inv_dmic_pin)
1703 dmic_fixup = true; 665 dmic_fixup = true;
1704 if (!dmic_fixup && !force) 666 if (!dmic_fixup && !force)
1705 continue; 667 continue;
1706 if (spec->vol_in_capsrc) { 668 alc_inv_dmic_sync_adc(codec, src);
1707 nid = spec->capsrc_nids[i];
1708 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1709 dir = HDA_OUTPUT;
1710 } else {
1711 nid = spec->adc_nids[i];
1712 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1713 dir = HDA_INPUT;
1714 }
1715 /* we care only right channel */
1716 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1717 if (v & 0x80) /* if already muted, we don't need to touch */
1718 continue;
1719 if (dmic_fixup) /* add mute for d-mic */
1720 v |= 0x80;
1721 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1722 parm | v);
1723 } 669 }
1724} 670}
1725 671
672static void alc_inv_dmic_hook(struct hda_codec *codec,
673 struct snd_ctl_elem_value *ucontrol)
674{
675 alc_inv_dmic_sync(codec, false);
676}
677
1726static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol, 678static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1727 struct snd_ctl_elem_value *ucontrol) 679 struct snd_ctl_elem_value *ucontrol)
1728{ 680{
@@ -1749,6 +701,7 @@ static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1749 701
1750static const struct snd_kcontrol_new alc_inv_dmic_sw = { 702static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1751 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 703 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
704 .name = "Inverted Internal Mic Capture Switch",
1752 .info = snd_ctl_boolean_mono_info, 705 .info = snd_ctl_boolean_mono_info,
1753 .get = alc_inv_dmic_sw_get, 706 .get = alc_inv_dmic_sw_get,
1754 .put = alc_inv_dmic_sw_put, 707 .put = alc_inv_dmic_sw_put,
@@ -1758,51 +711,23 @@ static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1758{ 711{
1759 struct alc_spec *spec = codec->spec; 712 struct alc_spec *spec = codec->spec;
1760 713
1761 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch", 714 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &alc_inv_dmic_sw))
1762 &alc_inv_dmic_sw))
1763 return -ENOMEM; 715 return -ENOMEM;
1764 spec->inv_dmic_fixup = 1; 716 spec->inv_dmic_fixup = 1;
1765 spec->inv_dmic_muted = 0; 717 spec->inv_dmic_muted = 0;
1766 spec->inv_dmic_pin = nid; 718 spec->inv_dmic_pin = nid;
719 spec->gen.cap_sync_hook = alc_inv_dmic_hook;
1767 return 0; 720 return 0;
1768} 721}
1769 722
1770/* typically the digital mic is put at node 0x12 */ 723/* typically the digital mic is put at node 0x12 */
1771static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec, 724static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1772 const struct alc_fixup *fix, int action) 725 const struct hda_fixup *fix, int action)
1773{ 726{
1774 if (action == ALC_FIXUP_ACT_PROBE) 727 if (action == HDA_FIXUP_ACT_PROBE)
1775 alc_add_inv_dmic_mixer(codec, 0x12); 728 alc_add_inv_dmic_mixer(codec, 0x12);
1776} 729}
1777 730
1778/*
1779 * virtual master controls
1780 */
1781
1782/*
1783 * slave controls for virtual master
1784 */
1785static const char * const alc_slave_pfxs[] = {
1786 "Front", "Surround", "Center", "LFE", "Side",
1787 "Headphone", "Speaker", "Mono", "Line Out",
1788 "CLFE", "Bass Speaker", "PCM",
1789 NULL,
1790};
1791
1792/*
1793 * build control elements
1794 */
1795
1796#define NID_MAPPING (-1)
1797
1798#define SUBDEV_SPEAKER_ (0 << 6)
1799#define SUBDEV_HP_ (1 << 6)
1800#define SUBDEV_LINE_ (2 << 6)
1801#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1802#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1803#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1804
1805static void alc_free_kctls(struct hda_codec *codec);
1806 731
1807#ifdef CONFIG_SND_HDA_INPUT_BEEP 732#ifdef CONFIG_SND_HDA_INPUT_BEEP
1808/* additional beep mixers; the actual parameters are overwritten at build */ 733/* additional beep mixers; the actual parameters are overwritten at build */
@@ -1813,45 +738,20 @@ static const struct snd_kcontrol_new alc_beep_mixer[] = {
1813}; 738};
1814#endif 739#endif
1815 740
1816static int __alc_build_controls(struct hda_codec *codec) 741static int alc_build_controls(struct hda_codec *codec)
1817{ 742{
1818 struct alc_spec *spec = codec->spec; 743 struct alc_spec *spec = codec->spec;
1819 struct snd_kcontrol *kctl = NULL; 744 int i, err;
1820 const struct snd_kcontrol_new *knew; 745
1821 int i, j, err; 746 err = snd_hda_gen_build_controls(codec);
1822 unsigned int u; 747 if (err < 0)
1823 hda_nid_t nid; 748 return err;
1824 749
1825 for (i = 0; i < spec->num_mixers; i++) { 750 for (i = 0; i < spec->num_mixers; i++) {
1826 err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 751 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1827 if (err < 0) 752 if (err < 0)
1828 return err; 753 return err;
1829 } 754 }
1830 if (spec->cap_mixer) {
1831 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1832 if (err < 0)
1833 return err;
1834 }
1835 if (spec->multiout.dig_out_nid) {
1836 err = snd_hda_create_dig_out_ctls(codec,
1837 spec->multiout.dig_out_nid,
1838 spec->multiout.dig_out_nid,
1839 spec->pcm_rec[1].pcm_type);
1840 if (err < 0)
1841 return err;
1842 if (!spec->no_analog) {
1843 err = snd_hda_create_spdif_share_sw(codec,
1844 &spec->multiout);
1845 if (err < 0)
1846 return err;
1847 spec->multiout.share_spdif = 1;
1848 }
1849 }
1850 if (spec->dig_in_nid) {
1851 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1852 if (err < 0)
1853 return err;
1854 }
1855 755
1856#ifdef CONFIG_SND_HDA_INPUT_BEEP 756#ifdef CONFIG_SND_HDA_INPUT_BEEP
1857 /* create beep controls if needed */ 757 /* create beep controls if needed */
@@ -1870,130 +770,7 @@ static int __alc_build_controls(struct hda_codec *codec)
1870 } 770 }
1871#endif 771#endif
1872 772
1873 /* if we have no master control, let's create it */ 773 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_BUILD);
1874 if (!spec->no_analog &&
1875 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1876 unsigned int vmaster_tlv[4];
1877 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1878 HDA_OUTPUT, vmaster_tlv);
1879 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1880 vmaster_tlv, alc_slave_pfxs,
1881 "Playback Volume");
1882 if (err < 0)
1883 return err;
1884 }
1885 if (!spec->no_analog &&
1886 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1887 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1888 NULL, alc_slave_pfxs,
1889 "Playback Switch",
1890 true, &spec->vmaster_mute.sw_kctl);
1891 if (err < 0)
1892 return err;
1893 }
1894
1895 /* assign Capture Source enums to NID */
1896 if (spec->capsrc_nids || spec->adc_nids) {
1897 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1898 if (!kctl)
1899 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1900 for (i = 0; kctl && i < kctl->count; i++) {
1901 err = snd_hda_add_nid(codec, kctl, i,
1902 get_capsrc(spec, i));
1903 if (err < 0)
1904 return err;
1905 }
1906 }
1907 if (spec->cap_mixer && spec->adc_nids) {
1908 const char *kname = kctl ? kctl->id.name : NULL;
1909 for (knew = spec->cap_mixer; knew->name; knew++) {
1910 if (kname && strcmp(knew->name, kname) == 0)
1911 continue;
1912 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1913 for (i = 0; kctl && i < kctl->count; i++) {
1914 err = snd_hda_add_nid(codec, kctl, i,
1915 spec->adc_nids[i]);
1916 if (err < 0)
1917 return err;
1918 }
1919 }
1920 }
1921
1922 /* other nid->control mapping */
1923 for (i = 0; i < spec->num_mixers; i++) {
1924 for (knew = spec->mixers[i]; knew->name; knew++) {
1925 if (knew->iface != NID_MAPPING)
1926 continue;
1927 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1928 if (kctl == NULL)
1929 continue;
1930 u = knew->subdevice;
1931 for (j = 0; j < 4; j++, u >>= 8) {
1932 nid = u & 0x3f;
1933 if (nid == 0)
1934 continue;
1935 switch (u & 0xc0) {
1936 case SUBDEV_SPEAKER_:
1937 nid = spec->autocfg.speaker_pins[nid];
1938 break;
1939 case SUBDEV_LINE_:
1940 nid = spec->autocfg.line_out_pins[nid];
1941 break;
1942 case SUBDEV_HP_:
1943 nid = spec->autocfg.hp_pins[nid];
1944 break;
1945 default:
1946 continue;
1947 }
1948 err = snd_hda_add_nid(codec, kctl, 0, nid);
1949 if (err < 0)
1950 return err;
1951 }
1952 u = knew->private_value;
1953 for (j = 0; j < 4; j++, u >>= 8) {
1954 nid = u & 0xff;
1955 if (nid == 0)
1956 continue;
1957 err = snd_hda_add_nid(codec, kctl, 0, nid);
1958 if (err < 0)
1959 return err;
1960 }
1961 }
1962 }
1963
1964 alc_free_kctls(codec); /* no longer needed */
1965
1966 return 0;
1967}
1968
1969static int alc_build_jacks(struct hda_codec *codec)
1970{
1971 struct alc_spec *spec = codec->spec;
1972
1973 if (spec->shared_mic_hp) {
1974 int err;
1975 int nid = spec->autocfg.inputs[1].pin;
1976 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1977 if (err < 0)
1978 return err;
1979 err = snd_hda_jack_detect_enable(codec, nid, 0);
1980 if (err < 0)
1981 return err;
1982 }
1983
1984 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
1985}
1986
1987static int alc_build_controls(struct hda_codec *codec)
1988{
1989 int err = __alc_build_controls(codec);
1990 if (err < 0)
1991 return err;
1992
1993 err = alc_build_jacks(codec);
1994 if (err < 0)
1995 return err;
1996 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1997 return 0; 774 return 0;
1998} 775}
1999 776
@@ -2002,9 +779,6 @@ static int alc_build_controls(struct hda_codec *codec)
2002 * Common callbacks 779 * Common callbacks
2003 */ 780 */
2004 781
2005static void alc_init_special_input_src(struct hda_codec *codec);
2006static void alc_auto_init_std(struct hda_codec *codec);
2007
2008static int alc_init(struct hda_codec *codec) 782static int alc_init(struct hda_codec *codec)
2009{ 783{
2010 struct alc_spec *spec = codec->spec; 784 struct alc_spec *spec = codec->spec;
@@ -2015,347 +789,9 @@ static int alc_init(struct hda_codec *codec)
2015 alc_fix_pll(codec); 789 alc_fix_pll(codec);
2016 alc_auto_init_amp(codec, spec->init_amp); 790 alc_auto_init_amp(codec, spec->init_amp);
2017 791
2018 snd_hda_gen_apply_verbs(codec); 792 snd_hda_gen_init(codec);
2019 alc_init_special_input_src(codec);
2020 alc_auto_init_std(codec);
2021
2022 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2023
2024 hda_call_check_power_status(codec, 0x01);
2025 return 0;
2026}
2027
2028#ifdef CONFIG_PM
2029static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2030{
2031 struct alc_spec *spec = codec->spec;
2032 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2033}
2034#endif
2035
2036/*
2037 * Analog playback callbacks
2038 */
2039static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2040 struct hda_codec *codec,
2041 struct snd_pcm_substream *substream)
2042{
2043 struct alc_spec *spec = codec->spec;
2044 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2045 hinfo);
2046}
2047
2048static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2049 struct hda_codec *codec,
2050 unsigned int stream_tag,
2051 unsigned int format,
2052 struct snd_pcm_substream *substream)
2053{
2054 struct alc_spec *spec = codec->spec;
2055 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2056 stream_tag, format, substream);
2057}
2058 793
2059static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 794 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
2060 struct hda_codec *codec,
2061 struct snd_pcm_substream *substream)
2062{
2063 struct alc_spec *spec = codec->spec;
2064 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2065}
2066
2067/*
2068 * Digital out
2069 */
2070static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2071 struct hda_codec *codec,
2072 struct snd_pcm_substream *substream)
2073{
2074 struct alc_spec *spec = codec->spec;
2075 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2076}
2077
2078static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2079 struct hda_codec *codec,
2080 unsigned int stream_tag,
2081 unsigned int format,
2082 struct snd_pcm_substream *substream)
2083{
2084 struct alc_spec *spec = codec->spec;
2085 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2086 stream_tag, format, substream);
2087}
2088
2089static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2090 struct hda_codec *codec,
2091 struct snd_pcm_substream *substream)
2092{
2093 struct alc_spec *spec = codec->spec;
2094 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2095}
2096
2097static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2098 struct hda_codec *codec,
2099 struct snd_pcm_substream *substream)
2100{
2101 struct alc_spec *spec = codec->spec;
2102 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2103}
2104
2105/*
2106 * Analog capture
2107 */
2108static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2109 struct hda_codec *codec,
2110 unsigned int stream_tag,
2111 unsigned int format,
2112 struct snd_pcm_substream *substream)
2113{
2114 struct alc_spec *spec = codec->spec;
2115
2116 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2117 stream_tag, 0, format);
2118 return 0;
2119}
2120
2121static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2122 struct hda_codec *codec,
2123 struct snd_pcm_substream *substream)
2124{
2125 struct alc_spec *spec = codec->spec;
2126
2127 snd_hda_codec_cleanup_stream(codec,
2128 spec->adc_nids[substream->number + 1]);
2129 return 0;
2130}
2131
2132/* analog capture with dynamic dual-adc changes */
2133static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2134 struct hda_codec *codec,
2135 unsigned int stream_tag,
2136 unsigned int format,
2137 struct snd_pcm_substream *substream)
2138{
2139 struct alc_spec *spec = codec->spec;
2140 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2141 spec->cur_adc_stream_tag = stream_tag;
2142 spec->cur_adc_format = format;
2143 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2144 return 0;
2145}
2146
2147static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2148 struct hda_codec *codec,
2149 struct snd_pcm_substream *substream)
2150{
2151 struct alc_spec *spec = codec->spec;
2152 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2153 spec->cur_adc = 0;
2154 return 0;
2155}
2156
2157static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2158 .substreams = 1,
2159 .channels_min = 2,
2160 .channels_max = 2,
2161 .nid = 0, /* fill later */
2162 .ops = {
2163 .prepare = dyn_adc_capture_pcm_prepare,
2164 .cleanup = dyn_adc_capture_pcm_cleanup
2165 },
2166};
2167
2168/*
2169 */
2170static const struct hda_pcm_stream alc_pcm_analog_playback = {
2171 .substreams = 1,
2172 .channels_min = 2,
2173 .channels_max = 8,
2174 /* NID is set in alc_build_pcms */
2175 .ops = {
2176 .open = alc_playback_pcm_open,
2177 .prepare = alc_playback_pcm_prepare,
2178 .cleanup = alc_playback_pcm_cleanup
2179 },
2180};
2181
2182static const struct hda_pcm_stream alc_pcm_analog_capture = {
2183 .substreams = 1,
2184 .channels_min = 2,
2185 .channels_max = 2,
2186 /* NID is set in alc_build_pcms */
2187};
2188
2189static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2190 .substreams = 1,
2191 .channels_min = 2,
2192 .channels_max = 2,
2193 /* NID is set in alc_build_pcms */
2194};
2195
2196static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2197 .substreams = 2, /* can be overridden */
2198 .channels_min = 2,
2199 .channels_max = 2,
2200 /* NID is set in alc_build_pcms */
2201 .ops = {
2202 .prepare = alc_alt_capture_pcm_prepare,
2203 .cleanup = alc_alt_capture_pcm_cleanup
2204 },
2205};
2206
2207static const struct hda_pcm_stream alc_pcm_digital_playback = {
2208 .substreams = 1,
2209 .channels_min = 2,
2210 .channels_max = 2,
2211 /* NID is set in alc_build_pcms */
2212 .ops = {
2213 .open = alc_dig_playback_pcm_open,
2214 .close = alc_dig_playback_pcm_close,
2215 .prepare = alc_dig_playback_pcm_prepare,
2216 .cleanup = alc_dig_playback_pcm_cleanup
2217 },
2218};
2219
2220static const struct hda_pcm_stream alc_pcm_digital_capture = {
2221 .substreams = 1,
2222 .channels_min = 2,
2223 .channels_max = 2,
2224 /* NID is set in alc_build_pcms */
2225};
2226
2227/* Used by alc_build_pcms to flag that a PCM has no playback stream */
2228static const struct hda_pcm_stream alc_pcm_null_stream = {
2229 .substreams = 0,
2230 .channels_min = 0,
2231 .channels_max = 0,
2232};
2233
2234static int alc_build_pcms(struct hda_codec *codec)
2235{
2236 struct alc_spec *spec = codec->spec;
2237 struct hda_pcm *info = spec->pcm_rec;
2238 const struct hda_pcm_stream *p;
2239 bool have_multi_adcs;
2240 int i;
2241
2242 codec->num_pcms = 1;
2243 codec->pcm_info = info;
2244
2245 if (spec->no_analog)
2246 goto skip_analog;
2247
2248 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2249 "%s Analog", codec->chip_name);
2250 info->name = spec->stream_name_analog;
2251
2252 if (spec->multiout.num_dacs > 0) {
2253 p = spec->stream_analog_playback;
2254 if (!p)
2255 p = &alc_pcm_analog_playback;
2256 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2257 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2258 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2259 spec->multiout.max_channels;
2260 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2261 spec->autocfg.line_outs == 2)
2262 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2263 snd_pcm_2_1_chmaps;
2264 }
2265 if (spec->adc_nids) {
2266 p = spec->stream_analog_capture;
2267 if (!p) {
2268 if (spec->dyn_adc_switch)
2269 p = &dyn_adc_pcm_analog_capture;
2270 else
2271 p = &alc_pcm_analog_capture;
2272 }
2273 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2274 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2275 }
2276
2277 if (spec->channel_mode) {
2278 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2279 for (i = 0; i < spec->num_channel_mode; i++) {
2280 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2281 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2282 }
2283 }
2284 }
2285
2286 skip_analog:
2287 /* SPDIF for stream index #1 */
2288 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2289 snprintf(spec->stream_name_digital,
2290 sizeof(spec->stream_name_digital),
2291 "%s Digital", codec->chip_name);
2292 codec->num_pcms = 2;
2293 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2294 info = spec->pcm_rec + 1;
2295 info->name = spec->stream_name_digital;
2296 if (spec->dig_out_type)
2297 info->pcm_type = spec->dig_out_type;
2298 else
2299 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2300 if (spec->multiout.dig_out_nid) {
2301 p = spec->stream_digital_playback;
2302 if (!p)
2303 p = &alc_pcm_digital_playback;
2304 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2305 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2306 }
2307 if (spec->dig_in_nid) {
2308 p = spec->stream_digital_capture;
2309 if (!p)
2310 p = &alc_pcm_digital_capture;
2311 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2312 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2313 }
2314 /* FIXME: do we need this for all Realtek codec models? */
2315 codec->spdif_status_reset = 1;
2316 }
2317
2318 if (spec->no_analog)
2319 return 0;
2320
2321 /* If the use of more than one ADC is requested for the current
2322 * model, configure a second analog capture-only PCM.
2323 */
2324 have_multi_adcs = (spec->num_adc_nids > 1) &&
2325 !spec->dyn_adc_switch && !spec->auto_mic &&
2326 (!spec->input_mux || spec->input_mux->num_items > 1);
2327 /* Additional Analaog capture for index #2 */
2328 if (spec->alt_dac_nid || have_multi_adcs) {
2329 codec->num_pcms = 3;
2330 info = spec->pcm_rec + 2;
2331 info->name = spec->stream_name_analog;
2332 if (spec->alt_dac_nid) {
2333 p = spec->stream_analog_alt_playback;
2334 if (!p)
2335 p = &alc_pcm_analog_alt_playback;
2336 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2337 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2338 spec->alt_dac_nid;
2339 } else {
2340 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2341 alc_pcm_null_stream;
2342 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2343 }
2344 if (have_multi_adcs) {
2345 p = spec->stream_analog_alt_capture;
2346 if (!p)
2347 p = &alc_pcm_analog_alt_capture;
2348 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2349 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2350 spec->adc_nids[1];
2351 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2352 spec->num_adc_nids - 1;
2353 } else {
2354 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2355 alc_pcm_null_stream;
2356 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2357 }
2358 }
2359 795
2360 return 0; 796 return 0;
2361} 797}
@@ -2369,31 +805,6 @@ static inline void alc_shutup(struct hda_codec *codec)
2369 snd_hda_shutup_pins(codec); 805 snd_hda_shutup_pins(codec);
2370} 806}
2371 807
2372static void alc_free_kctls(struct hda_codec *codec)
2373{
2374 struct alc_spec *spec = codec->spec;
2375
2376 if (spec->kctls.list) {
2377 struct snd_kcontrol_new *kctl = spec->kctls.list;
2378 int i;
2379 for (i = 0; i < spec->kctls.used; i++)
2380 kfree(kctl[i].name);
2381 }
2382 snd_array_free(&spec->kctls);
2383}
2384
2385static void alc_free_bind_ctls(struct hda_codec *codec)
2386{
2387 struct alc_spec *spec = codec->spec;
2388 if (spec->bind_ctls.list) {
2389 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2390 int i;
2391 for (i = 0; i < spec->bind_ctls.used; i++)
2392 kfree(ctl[i]);
2393 }
2394 snd_array_free(&spec->bind_ctls);
2395}
2396
2397static void alc_free(struct hda_codec *codec) 808static void alc_free(struct hda_codec *codec)
2398{ 809{
2399 struct alc_spec *spec = codec->spec; 810 struct alc_spec *spec = codec->spec;
@@ -2401,11 +812,9 @@ static void alc_free(struct hda_codec *codec)
2401 if (!spec) 812 if (!spec)
2402 return; 813 return;
2403 814
2404 alc_free_kctls(codec); 815 snd_hda_gen_spec_free(&spec->gen);
2405 alc_free_bind_ctls(codec);
2406 snd_hda_gen_free(&spec->gen);
2407 kfree(spec);
2408 snd_hda_detach_beep_device(codec); 816 snd_hda_detach_beep_device(codec);
817 kfree(spec);
2409} 818}
2410 819
2411#ifdef CONFIG_PM 820#ifdef CONFIG_PM
@@ -2441,16 +850,14 @@ static int alc_resume(struct hda_codec *codec)
2441 */ 850 */
2442static const struct hda_codec_ops alc_patch_ops = { 851static const struct hda_codec_ops alc_patch_ops = {
2443 .build_controls = alc_build_controls, 852 .build_controls = alc_build_controls,
2444 .build_pcms = alc_build_pcms, 853 .build_pcms = snd_hda_gen_build_pcms,
2445 .init = alc_init, 854 .init = alc_init,
2446 .free = alc_free, 855 .free = alc_free,
2447 .unsol_event = snd_hda_jack_unsol_event, 856 .unsol_event = snd_hda_jack_unsol_event,
2448#ifdef CONFIG_PM 857#ifdef CONFIG_PM
2449 .resume = alc_resume, 858 .resume = alc_resume,
2450#endif
2451#ifdef CONFIG_PM
2452 .suspend = alc_suspend, 859 .suspend = alc_suspend,
2453 .check_power_status = alc_check_power_status, 860 .check_power_status = snd_hda_gen_check_power_status,
2454#endif 861#endif
2455 .reboot_notify = alc_shutup, 862 .reboot_notify = alc_shutup,
2456}; 863};
@@ -2510,1727 +917,6 @@ static int alc_codec_rename_from_preset(struct hda_codec *codec)
2510 return 0; 917 return 0;
2511} 918}
2512 919
2513/*
2514 * Automatic parse of I/O pins from the BIOS configuration
2515 */
2516
2517enum {
2518 ALC_CTL_WIDGET_VOL,
2519 ALC_CTL_WIDGET_MUTE,
2520 ALC_CTL_BIND_MUTE,
2521 ALC_CTL_BIND_VOL,
2522 ALC_CTL_BIND_SW,
2523};
2524static const struct snd_kcontrol_new alc_control_templates[] = {
2525 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2526 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2527 HDA_BIND_MUTE(NULL, 0, 0, 0),
2528 HDA_BIND_VOL(NULL, 0),
2529 HDA_BIND_SW(NULL, 0),
2530};
2531
2532/* add dynamic controls */
2533static int add_control(struct alc_spec *spec, int type, const char *name,
2534 int cidx, unsigned long val)
2535{
2536 struct snd_kcontrol_new *knew;
2537
2538 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
2539 if (!knew)
2540 return -ENOMEM;
2541 knew->index = cidx;
2542 if (get_amp_nid_(val))
2543 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2544 knew->private_value = val;
2545 return 0;
2546}
2547
2548static int add_control_with_pfx(struct alc_spec *spec, int type,
2549 const char *pfx, const char *dir,
2550 const char *sfx, int cidx, unsigned long val)
2551{
2552 char name[32];
2553 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2554 return add_control(spec, type, name, cidx, val);
2555}
2556
2557#define add_pb_vol_ctrl(spec, type, pfx, val) \
2558 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2559#define add_pb_sw_ctrl(spec, type, pfx, val) \
2560 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2561#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2562 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2563#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2564 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2565
2566static const char * const channel_name[4] = {
2567 "Front", "Surround", "CLFE", "Side"
2568};
2569
2570static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2571 bool can_be_master, int *index)
2572{
2573 struct auto_pin_cfg *cfg = &spec->autocfg;
2574
2575 *index = 0;
2576 if (cfg->line_outs == 1 && !spec->multi_ios &&
2577 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2578 return "Master";
2579
2580 switch (cfg->line_out_type) {
2581 case AUTO_PIN_SPEAKER_OUT:
2582 if (cfg->line_outs == 1)
2583 return "Speaker";
2584 if (cfg->line_outs == 2)
2585 return ch ? "Bass Speaker" : "Speaker";
2586 break;
2587 case AUTO_PIN_HP_OUT:
2588 /* for multi-io case, only the primary out */
2589 if (ch && spec->multi_ios)
2590 break;
2591 *index = ch;
2592 return "Headphone";
2593 default:
2594 if (cfg->line_outs == 1 && !spec->multi_ios)
2595 return "PCM";
2596 break;
2597 }
2598 if (ch >= ARRAY_SIZE(channel_name)) {
2599 snd_BUG();
2600 return "PCM";
2601 }
2602
2603 return channel_name[ch];
2604}
2605
2606#ifdef CONFIG_PM
2607/* add the powersave loopback-list entry */
2608static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2609{
2610 struct hda_amp_list *list;
2611
2612 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2613 return;
2614 list = spec->loopback_list + spec->num_loopbacks;
2615 list->nid = mix;
2616 list->dir = HDA_INPUT;
2617 list->idx = idx;
2618 spec->num_loopbacks++;
2619 spec->loopback.amplist = spec->loopback_list;
2620}
2621#else
2622#define add_loopback_list(spec, mix, idx) /* NOP */
2623#endif
2624
2625/* create input playback/capture controls for the given pin */
2626static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2627 const char *ctlname, int ctlidx,
2628 int idx, hda_nid_t mix_nid)
2629{
2630 int err;
2631
2632 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2633 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2634 if (err < 0)
2635 return err;
2636 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2637 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2638 if (err < 0)
2639 return err;
2640 add_loopback_list(spec, mix_nid, idx);
2641 return 0;
2642}
2643
2644static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2645{
2646 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2647 return (pincap & AC_PINCAP_IN) != 0;
2648}
2649
2650/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2651static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2652{
2653 struct alc_spec *spec = codec->spec;
2654 hda_nid_t nid;
2655 hda_nid_t *adc_nids = spec->private_adc_nids;
2656 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2657 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2658 int i, nums = 0;
2659
2660 nid = codec->start_nid;
2661 for (i = 0; i < codec->num_nodes; i++, nid++) {
2662 hda_nid_t src;
2663 unsigned int caps = get_wcaps(codec, nid);
2664 int type = get_wcaps_type(caps);
2665
2666 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2667 continue;
2668 adc_nids[nums] = nid;
2669 cap_nids[nums] = nid;
2670 src = nid;
2671 for (;;) {
2672 int n;
2673 type = get_wcaps_type(get_wcaps(codec, src));
2674 if (type == AC_WID_PIN)
2675 break;
2676 if (type == AC_WID_AUD_SEL) {
2677 cap_nids[nums] = src;
2678 break;
2679 }
2680 n = snd_hda_get_num_conns(codec, src);
2681 if (n > 1) {
2682 cap_nids[nums] = src;
2683 break;
2684 } else if (n != 1)
2685 break;
2686 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2687 break;
2688 }
2689 if (++nums >= max_nums)
2690 break;
2691 }
2692 spec->adc_nids = spec->private_adc_nids;
2693 spec->capsrc_nids = spec->private_capsrc_nids;
2694 spec->num_adc_nids = nums;
2695 return nums;
2696}
2697
2698/* create playback/capture controls for input pins */
2699static int alc_auto_create_input_ctls(struct hda_codec *codec)
2700{
2701 struct alc_spec *spec = codec->spec;
2702 const struct auto_pin_cfg *cfg = &spec->autocfg;
2703 hda_nid_t mixer = spec->mixer_nid;
2704 struct hda_input_mux *imux = &spec->private_imux[0];
2705 int num_adcs;
2706 int i, c, err, idx, type_idx = 0;
2707 const char *prev_label = NULL;
2708
2709 num_adcs = alc_auto_fill_adc_caps(codec);
2710 if (num_adcs < 0)
2711 return 0;
2712
2713 for (i = 0; i < cfg->num_inputs; i++) {
2714 hda_nid_t pin;
2715 const char *label;
2716
2717 pin = cfg->inputs[i].pin;
2718 if (!alc_is_input_pin(codec, pin))
2719 continue;
2720
2721 label = hda_get_autocfg_input_label(codec, cfg, i);
2722 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2723 label = "Headphone Mic";
2724 if (prev_label && !strcmp(label, prev_label))
2725 type_idx++;
2726 else
2727 type_idx = 0;
2728 prev_label = label;
2729
2730 if (mixer) {
2731 idx = get_connection_index(codec, mixer, pin);
2732 if (idx >= 0) {
2733 err = new_analog_input(spec, pin,
2734 label, type_idx,
2735 idx, mixer);
2736 if (err < 0)
2737 return err;
2738 }
2739 }
2740
2741 for (c = 0; c < num_adcs; c++) {
2742 hda_nid_t cap = get_capsrc(spec, c);
2743 idx = get_connection_index(codec, cap, pin);
2744 if (idx >= 0) {
2745 spec->imux_pins[imux->num_items] = pin;
2746 snd_hda_add_imux_item(imux, label, idx, NULL);
2747 break;
2748 }
2749 }
2750 }
2751
2752 spec->num_mux_defs = 1;
2753 spec->input_mux = imux;
2754
2755 return 0;
2756}
2757
2758/* create a shared input with the headphone out */
2759static int alc_auto_create_shared_input(struct hda_codec *codec)
2760{
2761 struct alc_spec *spec = codec->spec;
2762 struct auto_pin_cfg *cfg = &spec->autocfg;
2763 unsigned int defcfg;
2764 hda_nid_t nid;
2765
2766 /* only one internal input pin? */
2767 if (cfg->num_inputs != 1)
2768 return 0;
2769 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2770 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2771 return 0;
2772
2773 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2774 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2775 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2776 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2777 else
2778 return 0; /* both not available */
2779
2780 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2781 return 0; /* no input */
2782
2783 cfg->inputs[1].pin = nid;
2784 cfg->inputs[1].type = AUTO_PIN_MIC;
2785 cfg->num_inputs = 2;
2786 spec->shared_mic_hp = 1;
2787 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2788 return 0;
2789}
2790
2791static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2792 unsigned int pin_type)
2793{
2794 snd_hda_set_pin_ctl(codec, nid, pin_type);
2795 /* unmute pin */
2796 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2797 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2798 AMP_OUT_UNMUTE);
2799}
2800
2801static int get_pin_type(int line_out_type)
2802{
2803 if (line_out_type == AUTO_PIN_HP_OUT)
2804 return PIN_HP;
2805 else
2806 return PIN_OUT;
2807}
2808
2809static void alc_auto_init_analog_input(struct hda_codec *codec)
2810{
2811 struct alc_spec *spec = codec->spec;
2812 struct auto_pin_cfg *cfg = &spec->autocfg;
2813 int i;
2814
2815 for (i = 0; i < cfg->num_inputs; i++) {
2816 hda_nid_t nid = cfg->inputs[i].pin;
2817 if (alc_is_input_pin(codec, nid)) {
2818 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2819 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2820 snd_hda_codec_write(codec, nid, 0,
2821 AC_VERB_SET_AMP_GAIN_MUTE,
2822 AMP_OUT_MUTE);
2823 }
2824 }
2825
2826 /* mute all loopback inputs */
2827 if (spec->mixer_nid) {
2828 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
2829 for (i = 0; i < nums; i++)
2830 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2831 AC_VERB_SET_AMP_GAIN_MUTE,
2832 AMP_IN_MUTE(i));
2833 }
2834}
2835
2836/* convert from MIX nid to DAC */
2837static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2838{
2839 hda_nid_t list[5];
2840 int i, num;
2841
2842 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2843 return nid;
2844 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2845 for (i = 0; i < num; i++) {
2846 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2847 return list[i];
2848 }
2849 return 0;
2850}
2851
2852/* go down to the selector widget before the mixer */
2853static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2854{
2855 hda_nid_t srcs[5];
2856 int num = snd_hda_get_connections(codec, pin, srcs,
2857 ARRAY_SIZE(srcs));
2858 if (num != 1 ||
2859 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2860 return pin;
2861 return srcs[0];
2862}
2863
2864/* get MIX nid connected to the given pin targeted to DAC */
2865static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2866 hda_nid_t dac)
2867{
2868 hda_nid_t mix[5];
2869 int i, num;
2870
2871 pin = alc_go_down_to_selector(codec, pin);
2872 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2873 for (i = 0; i < num; i++) {
2874 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2875 return mix[i];
2876 }
2877 return 0;
2878}
2879
2880/* select the connection from pin to DAC if needed */
2881static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2882 hda_nid_t dac)
2883{
2884 hda_nid_t mix[5];
2885 int i, num;
2886
2887 pin = alc_go_down_to_selector(codec, pin);
2888 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2889 if (num < 2)
2890 return 0;
2891 for (i = 0; i < num; i++) {
2892 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2893 snd_hda_codec_update_cache(codec, pin, 0,
2894 AC_VERB_SET_CONNECT_SEL, i);
2895 return 0;
2896 }
2897 }
2898 return 0;
2899}
2900
2901static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2902{
2903 struct alc_spec *spec = codec->spec;
2904 int i;
2905 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2906 ARRAY_SIZE(spec->private_dac_nids)) ||
2907 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2908 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2909 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2910 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2911 return true;
2912 for (i = 0; i < spec->multi_ios; i++) {
2913 if (spec->multi_io[i].dac == nid)
2914 return true;
2915 }
2916 return false;
2917}
2918
2919/* look for an empty DAC slot */
2920static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2921{
2922 hda_nid_t srcs[5];
2923 int i, num;
2924
2925 pin = alc_go_down_to_selector(codec, pin);
2926 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2927 for (i = 0; i < num; i++) {
2928 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2929 if (!nid)
2930 continue;
2931 if (!alc_is_dac_already_used(codec, nid))
2932 return nid;
2933 }
2934 return 0;
2935}
2936
2937/* check whether the DAC is reachable from the pin */
2938static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2939 hda_nid_t pin, hda_nid_t dac)
2940{
2941 hda_nid_t srcs[5];
2942 int i, num;
2943
2944 if (!pin || !dac)
2945 return false;
2946 pin = alc_go_down_to_selector(codec, pin);
2947 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2948 for (i = 0; i < num; i++) {
2949 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2950 if (nid == dac)
2951 return true;
2952 }
2953 return false;
2954}
2955
2956static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2957{
2958 struct alc_spec *spec = codec->spec;
2959 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2960 hda_nid_t nid, nid_found, srcs[5];
2961 int i, num = snd_hda_get_connections(codec, sel, srcs,
2962 ARRAY_SIZE(srcs));
2963 if (num == 1)
2964 return alc_auto_look_for_dac(codec, pin);
2965 nid_found = 0;
2966 for (i = 0; i < num; i++) {
2967 if (srcs[i] == spec->mixer_nid)
2968 continue;
2969 nid = alc_auto_mix_to_dac(codec, srcs[i]);
2970 if (nid && !alc_is_dac_already_used(codec, nid)) {
2971 if (nid_found)
2972 return 0;
2973 nid_found = nid;
2974 }
2975 }
2976 return nid_found;
2977}
2978
2979/* mark up volume and mute control NIDs: used during badness parsing and
2980 * at creating actual controls
2981 */
2982static inline unsigned int get_ctl_pos(unsigned int data)
2983{
2984 hda_nid_t nid = get_amp_nid_(data);
2985 unsigned int dir;
2986 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
2987 return 0;
2988 dir = get_amp_direction_(data);
2989 return (nid << 1) | dir;
2990}
2991
2992#define is_ctl_used(bits, data) \
2993 test_bit(get_ctl_pos(data), bits)
2994#define mark_ctl_usage(bits, data) \
2995 set_bit(get_ctl_pos(data), bits)
2996
2997static void clear_vol_marks(struct hda_codec *codec)
2998{
2999 struct alc_spec *spec = codec->spec;
3000 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3001 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3002}
3003
3004/* badness definition */
3005enum {
3006 /* No primary DAC is found for the main output */
3007 BAD_NO_PRIMARY_DAC = 0x10000,
3008 /* No DAC is found for the extra output */
3009 BAD_NO_DAC = 0x4000,
3010 /* No possible multi-ios */
3011 BAD_MULTI_IO = 0x103,
3012 /* No individual DAC for extra output */
3013 BAD_NO_EXTRA_DAC = 0x102,
3014 /* No individual DAC for extra surrounds */
3015 BAD_NO_EXTRA_SURR_DAC = 0x101,
3016 /* Primary DAC shared with main surrounds */
3017 BAD_SHARED_SURROUND = 0x100,
3018 /* Primary DAC shared with main CLFE */
3019 BAD_SHARED_CLFE = 0x10,
3020 /* Primary DAC shared with extra surrounds */
3021 BAD_SHARED_EXTRA_SURROUND = 0x10,
3022 /* Volume widget is shared */
3023 BAD_SHARED_VOL = 0x10,
3024};
3025
3026static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3027 hda_nid_t pin, hda_nid_t dac);
3028static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3029 hda_nid_t pin, hda_nid_t dac);
3030
3031static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3032 hda_nid_t dac)
3033{
3034 struct alc_spec *spec = codec->spec;
3035 hda_nid_t nid;
3036 unsigned int val;
3037 int badness = 0;
3038
3039 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3040 if (nid) {
3041 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3042 if (is_ctl_used(spec->vol_ctls, nid))
3043 badness += BAD_SHARED_VOL;
3044 else
3045 mark_ctl_usage(spec->vol_ctls, val);
3046 } else
3047 badness += BAD_SHARED_VOL;
3048 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3049 if (nid) {
3050 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3051 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3052 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3053 else
3054 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3055 if (is_ctl_used(spec->sw_ctls, val))
3056 badness += BAD_SHARED_VOL;
3057 else
3058 mark_ctl_usage(spec->sw_ctls, val);
3059 } else
3060 badness += BAD_SHARED_VOL;
3061 return badness;
3062}
3063
3064struct badness_table {
3065 int no_primary_dac; /* no primary DAC */
3066 int no_dac; /* no secondary DACs */
3067 int shared_primary; /* primary DAC is shared with main output */
3068 int shared_surr; /* secondary DAC shared with main or primary */
3069 int shared_clfe; /* third DAC shared with main or primary */
3070 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3071};
3072
3073static struct badness_table main_out_badness = {
3074 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3075 .no_dac = BAD_NO_DAC,
3076 .shared_primary = BAD_NO_PRIMARY_DAC,
3077 .shared_surr = BAD_SHARED_SURROUND,
3078 .shared_clfe = BAD_SHARED_CLFE,
3079 .shared_surr_main = BAD_SHARED_SURROUND,
3080};
3081
3082static struct badness_table extra_out_badness = {
3083 .no_primary_dac = BAD_NO_DAC,
3084 .no_dac = BAD_NO_DAC,
3085 .shared_primary = BAD_NO_EXTRA_DAC,
3086 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3087 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3088 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3089};
3090
3091/* try to assign DACs to pins and return the resultant badness */
3092static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3093 const hda_nid_t *pins, hda_nid_t *dacs,
3094 const struct badness_table *bad)
3095{
3096 struct alc_spec *spec = codec->spec;
3097 struct auto_pin_cfg *cfg = &spec->autocfg;
3098 int i, j;
3099 int badness = 0;
3100 hda_nid_t dac;
3101
3102 if (!num_outs)
3103 return 0;
3104
3105 for (i = 0; i < num_outs; i++) {
3106 hda_nid_t pin = pins[i];
3107 if (!dacs[i])
3108 dacs[i] = alc_auto_look_for_dac(codec, pin);
3109 if (!dacs[i] && !i) {
3110 for (j = 1; j < num_outs; j++) {
3111 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3112 dacs[0] = dacs[j];
3113 dacs[j] = 0;
3114 break;
3115 }
3116 }
3117 }
3118 dac = dacs[i];
3119 if (!dac) {
3120 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
3121 dac = dacs[0];
3122 else if (cfg->line_outs > i &&
3123 alc_auto_is_dac_reachable(codec, pin,
3124 spec->private_dac_nids[i]))
3125 dac = spec->private_dac_nids[i];
3126 if (dac) {
3127 if (!i)
3128 badness += bad->shared_primary;
3129 else if (i == 1)
3130 badness += bad->shared_surr;
3131 else
3132 badness += bad->shared_clfe;
3133 } else if (alc_auto_is_dac_reachable(codec, pin,
3134 spec->private_dac_nids[0])) {
3135 dac = spec->private_dac_nids[0];
3136 badness += bad->shared_surr_main;
3137 } else if (!i)
3138 badness += bad->no_primary_dac;
3139 else
3140 badness += bad->no_dac;
3141 }
3142 if (dac)
3143 badness += eval_shared_vol_badness(codec, pin, dac);
3144 }
3145
3146 return badness;
3147}
3148
3149static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3150 hda_nid_t reference_pin,
3151 bool hardwired, int offset);
3152
3153static bool alc_map_singles(struct hda_codec *codec, int outs,
3154 const hda_nid_t *pins, hda_nid_t *dacs)
3155{
3156 int i;
3157 bool found = false;
3158 for (i = 0; i < outs; i++) {
3159 if (dacs[i])
3160 continue;
3161 dacs[i] = get_dac_if_single(codec, pins[i]);
3162 if (dacs[i])
3163 found = true;
3164 }
3165 return found;
3166}
3167
3168/* fill in the dac_nids table from the parsed pin configuration */
3169static int fill_and_eval_dacs(struct hda_codec *codec,
3170 bool fill_hardwired,
3171 bool fill_mio_first)
3172{
3173 struct alc_spec *spec = codec->spec;
3174 struct auto_pin_cfg *cfg = &spec->autocfg;
3175 int i, err, badness;
3176
3177 /* set num_dacs once to full for alc_auto_look_for_dac() */
3178 spec->multiout.num_dacs = cfg->line_outs;
3179 spec->multiout.dac_nids = spec->private_dac_nids;
3180 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3181 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3182 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
3183 spec->multi_ios = 0;
3184 clear_vol_marks(codec);
3185 badness = 0;
3186
3187 /* fill hard-wired DACs first */
3188 if (fill_hardwired) {
3189 bool mapped;
3190 do {
3191 mapped = alc_map_singles(codec, cfg->line_outs,
3192 cfg->line_out_pins,
3193 spec->private_dac_nids);
3194 mapped |= alc_map_singles(codec, cfg->hp_outs,
3195 cfg->hp_pins,
3196 spec->multiout.hp_out_nid);
3197 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3198 cfg->speaker_pins,
3199 spec->multiout.extra_out_nid);
3200 if (fill_mio_first && cfg->line_outs == 1 &&
3201 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3202 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3203 if (!err)
3204 mapped = true;
3205 }
3206 } while (mapped);
3207 }
3208
3209 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3210 spec->private_dac_nids,
3211 &main_out_badness);
3212
3213 /* re-count num_dacs and squash invalid entries */
3214 spec->multiout.num_dacs = 0;
3215 for (i = 0; i < cfg->line_outs; i++) {
3216 if (spec->private_dac_nids[i])
3217 spec->multiout.num_dacs++;
3218 else {
3219 memmove(spec->private_dac_nids + i,
3220 spec->private_dac_nids + i + 1,
3221 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3222 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3223 }
3224 }
3225
3226 if (fill_mio_first &&
3227 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3228 /* try to fill multi-io first */
3229 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3230 if (err < 0)
3231 return err;
3232 /* we don't count badness at this stage yet */
3233 }
3234
3235 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
3236 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3237 spec->multiout.hp_out_nid,
3238 &extra_out_badness);
3239 if (err < 0)
3240 return err;
3241 badness += err;
3242 }
3243 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3244 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3245 cfg->speaker_pins,
3246 spec->multiout.extra_out_nid,
3247 &extra_out_badness);
3248 if (err < 0)
3249 return err;
3250 badness += err;
3251 }
3252 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3253 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3254 if (err < 0)
3255 return err;
3256 badness += err;
3257 }
3258 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3259 /* try multi-ios with HP + inputs */
3260 int offset = 0;
3261 if (cfg->line_outs >= 3)
3262 offset = 1;
3263 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3264 offset);
3265 if (err < 0)
3266 return err;
3267 badness += err;
3268 }
3269
3270 if (spec->multi_ios == 2) {
3271 for (i = 0; i < 2; i++)
3272 spec->private_dac_nids[spec->multiout.num_dacs++] =
3273 spec->multi_io[i].dac;
3274 spec->ext_channel_count = 2;
3275 } else if (spec->multi_ios) {
3276 spec->multi_ios = 0;
3277 badness += BAD_MULTI_IO;
3278 }
3279
3280 return badness;
3281}
3282
3283#define DEBUG_BADNESS
3284
3285#ifdef DEBUG_BADNESS
3286#define debug_badness snd_printdd
3287#else
3288#define debug_badness(...)
3289#endif
3290
3291static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3292{
3293 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3294 cfg->line_out_pins[0], cfg->line_out_pins[1],
3295 cfg->line_out_pins[2], cfg->line_out_pins[2],
3296 spec->multiout.dac_nids[0],
3297 spec->multiout.dac_nids[1],
3298 spec->multiout.dac_nids[2],
3299 spec->multiout.dac_nids[3]);
3300 if (spec->multi_ios > 0)
3301 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3302 spec->multi_ios,
3303 spec->multi_io[0].pin, spec->multi_io[1].pin,
3304 spec->multi_io[0].dac, spec->multi_io[1].dac);
3305 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3306 cfg->hp_pins[0], cfg->hp_pins[1],
3307 cfg->hp_pins[2], cfg->hp_pins[2],
3308 spec->multiout.hp_out_nid[0],
3309 spec->multiout.hp_out_nid[1],
3310 spec->multiout.hp_out_nid[2],
3311 spec->multiout.hp_out_nid[3]);
3312 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3313 cfg->speaker_pins[0], cfg->speaker_pins[1],
3314 cfg->speaker_pins[2], cfg->speaker_pins[3],
3315 spec->multiout.extra_out_nid[0],
3316 spec->multiout.extra_out_nid[1],
3317 spec->multiout.extra_out_nid[2],
3318 spec->multiout.extra_out_nid[3]);
3319}
3320
3321static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3322{
3323 struct alc_spec *spec = codec->spec;
3324 struct auto_pin_cfg *cfg = &spec->autocfg;
3325 struct auto_pin_cfg *best_cfg;
3326 int best_badness = INT_MAX;
3327 int badness;
3328 bool fill_hardwired = true, fill_mio_first = true;
3329 bool best_wired = true, best_mio = true;
3330 bool hp_spk_swapped = false;
3331
3332 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3333 if (!best_cfg)
3334 return -ENOMEM;
3335 *best_cfg = *cfg;
3336
3337 for (;;) {
3338 badness = fill_and_eval_dacs(codec, fill_hardwired,
3339 fill_mio_first);
3340 if (badness < 0) {
3341 kfree(best_cfg);
3342 return badness;
3343 }
3344 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3345 cfg->line_out_type, fill_hardwired, fill_mio_first,
3346 badness);
3347 debug_show_configs(spec, cfg);
3348 if (badness < best_badness) {
3349 best_badness = badness;
3350 *best_cfg = *cfg;
3351 best_wired = fill_hardwired;
3352 best_mio = fill_mio_first;
3353 }
3354 if (!badness)
3355 break;
3356 fill_mio_first = !fill_mio_first;
3357 if (!fill_mio_first)
3358 continue;
3359 fill_hardwired = !fill_hardwired;
3360 if (!fill_hardwired)
3361 continue;
3362 if (hp_spk_swapped)
3363 break;
3364 hp_spk_swapped = true;
3365 if (cfg->speaker_outs > 0 &&
3366 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3367 cfg->hp_outs = cfg->line_outs;
3368 memcpy(cfg->hp_pins, cfg->line_out_pins,
3369 sizeof(cfg->hp_pins));
3370 cfg->line_outs = cfg->speaker_outs;
3371 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3372 sizeof(cfg->speaker_pins));
3373 cfg->speaker_outs = 0;
3374 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3375 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3376 fill_hardwired = true;
3377 continue;
3378 }
3379 if (cfg->hp_outs > 0 &&
3380 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3381 cfg->speaker_outs = cfg->line_outs;
3382 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3383 sizeof(cfg->speaker_pins));
3384 cfg->line_outs = cfg->hp_outs;
3385 memcpy(cfg->line_out_pins, cfg->hp_pins,
3386 sizeof(cfg->hp_pins));
3387 cfg->hp_outs = 0;
3388 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3389 cfg->line_out_type = AUTO_PIN_HP_OUT;
3390 fill_hardwired = true;
3391 continue;
3392 }
3393 break;
3394 }
3395
3396 if (badness) {
3397 *cfg = *best_cfg;
3398 fill_and_eval_dacs(codec, best_wired, best_mio);
3399 }
3400 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3401 cfg->line_out_type, best_wired, best_mio);
3402 debug_show_configs(spec, cfg);
3403
3404 if (cfg->line_out_pins[0])
3405 spec->vmaster_nid =
3406 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3407 spec->multiout.dac_nids[0]);
3408
3409 /* clear the bitmap flags for creating controls */
3410 clear_vol_marks(codec);
3411 kfree(best_cfg);
3412 return 0;
3413}
3414
3415static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3416 const char *pfx, int cidx,
3417 hda_nid_t nid, unsigned int chs)
3418{
3419 struct alc_spec *spec = codec->spec;
3420 unsigned int val;
3421 if (!nid)
3422 return 0;
3423 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3424 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3425 return 0;
3426 mark_ctl_usage(spec->vol_ctls, val);
3427 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3428 val);
3429}
3430
3431static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3432 const char *pfx, int cidx,
3433 hda_nid_t nid)
3434{
3435 int chs = 1;
3436 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3437 chs = 3;
3438 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3439}
3440
3441/* create a mute-switch for the given mixer widget;
3442 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3443 */
3444static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3445 const char *pfx, int cidx,
3446 hda_nid_t nid, unsigned int chs)
3447{
3448 struct alc_spec *spec = codec->spec;
3449 int wid_type;
3450 int type;
3451 unsigned long val;
3452 if (!nid)
3453 return 0;
3454 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3455 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3456 type = ALC_CTL_WIDGET_MUTE;
3457 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3458 } else if (snd_hda_get_num_conns(codec, nid) == 1) {
3459 type = ALC_CTL_WIDGET_MUTE;
3460 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3461 } else {
3462 type = ALC_CTL_BIND_MUTE;
3463 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3464 }
3465 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3466 return 0;
3467 mark_ctl_usage(spec->sw_ctls, val);
3468 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3469}
3470
3471static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3472 int cidx, hda_nid_t nid)
3473{
3474 int chs = 1;
3475 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3476 chs = 3;
3477 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3478}
3479
3480static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3481 hda_nid_t pin, hda_nid_t dac)
3482{
3483 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3484 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3485 return pin;
3486 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3487 return mix;
3488 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3489 return dac;
3490 return 0;
3491}
3492
3493static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3494 hda_nid_t pin, hda_nid_t dac)
3495{
3496 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3497 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3498 return dac;
3499 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3500 return mix;
3501 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3502 return pin;
3503 return 0;
3504}
3505
3506/* add playback controls from the parsed DAC table */
3507static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3508 const struct auto_pin_cfg *cfg)
3509{
3510 struct alc_spec *spec = codec->spec;
3511 int i, err, noutputs;
3512
3513 noutputs = cfg->line_outs;
3514 if (spec->multi_ios > 0 && cfg->line_outs < 3)
3515 noutputs += spec->multi_ios;
3516
3517 for (i = 0; i < noutputs; i++) {
3518 const char *name;
3519 int index;
3520 hda_nid_t dac, pin;
3521 hda_nid_t sw, vol;
3522
3523 dac = spec->multiout.dac_nids[i];
3524 if (!dac)
3525 continue;
3526 if (i >= cfg->line_outs) {
3527 pin = spec->multi_io[i - 1].pin;
3528 index = 0;
3529 name = channel_name[i];
3530 } else {
3531 pin = cfg->line_out_pins[i];
3532 name = alc_get_line_out_pfx(spec, i, true, &index);
3533 }
3534
3535 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3536 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3537 if (!name || !strcmp(name, "CLFE")) {
3538 /* Center/LFE */
3539 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3540 if (err < 0)
3541 return err;
3542 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3543 if (err < 0)
3544 return err;
3545 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3546 if (err < 0)
3547 return err;
3548 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3549 if (err < 0)
3550 return err;
3551 } else {
3552 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3553 if (err < 0)
3554 return err;
3555 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3556 if (err < 0)
3557 return err;
3558 }
3559 }
3560 return 0;
3561}
3562
3563static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3564 hda_nid_t dac, const char *pfx,
3565 int cidx)
3566{
3567 struct alc_spec *spec = codec->spec;
3568 hda_nid_t sw, vol;
3569 int err;
3570
3571 if (!dac) {
3572 unsigned int val;
3573 /* the corresponding DAC is already occupied */
3574 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3575 return 0; /* no way */
3576 /* create a switch only */
3577 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3578 if (is_ctl_used(spec->sw_ctls, val))
3579 return 0; /* already created */
3580 mark_ctl_usage(spec->sw_ctls, val);
3581 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
3582 }
3583
3584 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3585 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3586 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
3587 if (err < 0)
3588 return err;
3589 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
3590 if (err < 0)
3591 return err;
3592 return 0;
3593}
3594
3595static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3596 unsigned int nums,
3597 struct hda_ctl_ops *ops)
3598{
3599 struct alc_spec *spec = codec->spec;
3600 struct hda_bind_ctls **ctlp, *ctl;
3601 ctlp = snd_array_new(&spec->bind_ctls);
3602 if (!ctlp)
3603 return NULL;
3604 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3605 *ctlp = ctl;
3606 if (ctl)
3607 ctl->ops = ops;
3608 return ctl;
3609}
3610
3611/* add playback controls for speaker and HP outputs */
3612static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3613 const hda_nid_t *pins,
3614 const hda_nid_t *dacs,
3615 const char *pfx)
3616{
3617 struct alc_spec *spec = codec->spec;
3618 struct hda_bind_ctls *ctl;
3619 char name[32];
3620 int i, n, err;
3621
3622 if (!num_pins || !pins[0])
3623 return 0;
3624
3625 if (num_pins == 1) {
3626 hda_nid_t dac = *dacs;
3627 if (!dac)
3628 dac = spec->multiout.dac_nids[0];
3629 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3630 }
3631
3632 for (i = 0; i < num_pins; i++) {
3633 hda_nid_t dac;
3634 if (dacs[num_pins - 1])
3635 dac = dacs[i]; /* with individual volumes */
3636 else
3637 dac = 0;
3638 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3639 err = alc_auto_create_extra_out(codec, pins[i], dac,
3640 "Bass Speaker", 0);
3641 } else if (num_pins >= 3) {
3642 snprintf(name, sizeof(name), "%s %s",
3643 pfx, channel_name[i]);
3644 err = alc_auto_create_extra_out(codec, pins[i], dac,
3645 name, 0);
3646 } else {
3647 err = alc_auto_create_extra_out(codec, pins[i], dac,
3648 pfx, i);
3649 }
3650 if (err < 0)
3651 return err;
3652 }
3653 if (dacs[num_pins - 1])
3654 return 0;
3655
3656 /* Let's create a bind-controls for volumes */
3657 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3658 if (!ctl)
3659 return -ENOMEM;
3660 n = 0;
3661 for (i = 0; i < num_pins; i++) {
3662 hda_nid_t vol;
3663 if (!pins[i] || !dacs[i])
3664 continue;
3665 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3666 if (vol)
3667 ctl->values[n++] =
3668 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3669 }
3670 if (n) {
3671 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3672 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3673 if (err < 0)
3674 return err;
3675 }
3676 return 0;
3677}
3678
3679static int alc_auto_create_hp_out(struct hda_codec *codec)
3680{
3681 struct alc_spec *spec = codec->spec;
3682 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3683 spec->autocfg.hp_pins,
3684 spec->multiout.hp_out_nid,
3685 "Headphone");
3686}
3687
3688static int alc_auto_create_speaker_out(struct hda_codec *codec)
3689{
3690 struct alc_spec *spec = codec->spec;
3691 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3692 spec->autocfg.speaker_pins,
3693 spec->multiout.extra_out_nid,
3694 "Speaker");
3695}
3696
3697static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3698 hda_nid_t pin, int pin_type,
3699 hda_nid_t dac)
3700{
3701 int i, num;
3702 hda_nid_t nid, mix = 0;
3703 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3704
3705 alc_set_pin_output(codec, pin, pin_type);
3706 nid = alc_go_down_to_selector(codec, pin);
3707 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3708 for (i = 0; i < num; i++) {
3709 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3710 continue;
3711 mix = srcs[i];
3712 break;
3713 }
3714 if (!mix)
3715 return;
3716
3717 /* need the manual connection? */
3718 if (num > 1)
3719 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3720 /* unmute mixer widget inputs */
3721 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3722 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3723 AMP_IN_UNMUTE(0));
3724 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3725 AMP_IN_UNMUTE(1));
3726 }
3727 /* initialize volume */
3728 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3729 if (nid)
3730 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3731 AMP_OUT_ZERO);
3732
3733 /* unmute DAC if it's not assigned to a mixer */
3734 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3735 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3736 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3737 AMP_OUT_ZERO);
3738}
3739
3740static void alc_auto_init_multi_out(struct hda_codec *codec)
3741{
3742 struct alc_spec *spec = codec->spec;
3743 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3744 int i;
3745
3746 for (i = 0; i <= HDA_SIDE; i++) {
3747 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3748 if (nid)
3749 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3750 spec->multiout.dac_nids[i]);
3751 }
3752}
3753
3754static void alc_auto_init_extra_out(struct hda_codec *codec)
3755{
3756 struct alc_spec *spec = codec->spec;
3757 int i;
3758 hda_nid_t pin, dac;
3759
3760 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3761 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3762 break;
3763 pin = spec->autocfg.hp_pins[i];
3764 if (!pin)
3765 break;
3766 dac = spec->multiout.hp_out_nid[i];
3767 if (!dac) {
3768 if (i > 0 && spec->multiout.hp_out_nid[0])
3769 dac = spec->multiout.hp_out_nid[0];
3770 else
3771 dac = spec->multiout.dac_nids[0];
3772 }
3773 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3774 }
3775 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3776 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3777 break;
3778 pin = spec->autocfg.speaker_pins[i];
3779 if (!pin)
3780 break;
3781 dac = spec->multiout.extra_out_nid[i];
3782 if (!dac) {
3783 if (i > 0 && spec->multiout.extra_out_nid[0])
3784 dac = spec->multiout.extra_out_nid[0];
3785 else
3786 dac = spec->multiout.dac_nids[0];
3787 }
3788 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3789 }
3790}
3791
3792/* check whether the given pin can be a multi-io pin */
3793static bool can_be_multiio_pin(struct hda_codec *codec,
3794 unsigned int location, hda_nid_t nid)
3795{
3796 unsigned int defcfg, caps;
3797
3798 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3799 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3800 return false;
3801 if (location && get_defcfg_location(defcfg) != location)
3802 return false;
3803 caps = snd_hda_query_pin_caps(codec, nid);
3804 if (!(caps & AC_PINCAP_OUT))
3805 return false;
3806 return true;
3807}
3808
3809/*
3810 * multi-io helper
3811 *
3812 * When hardwired is set, try to fill ony hardwired pins, and returns
3813 * zero if any pins are filled, non-zero if nothing found.
3814 * When hardwired is off, try to fill possible input pins, and returns
3815 * the badness value.
3816 */
3817static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3818 hda_nid_t reference_pin,
3819 bool hardwired, int offset)
3820{
3821 struct alc_spec *spec = codec->spec;
3822 struct auto_pin_cfg *cfg = &spec->autocfg;
3823 int type, i, j, dacs, num_pins, old_pins;
3824 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3825 unsigned int location = get_defcfg_location(defcfg);
3826 int badness = 0;
3827
3828 old_pins = spec->multi_ios;
3829 if (old_pins >= 2)
3830 goto end_fill;
3831
3832 num_pins = 0;
3833 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3834 for (i = 0; i < cfg->num_inputs; i++) {
3835 if (cfg->inputs[i].type != type)
3836 continue;
3837 if (can_be_multiio_pin(codec, location,
3838 cfg->inputs[i].pin))
3839 num_pins++;
3840 }
3841 }
3842 if (num_pins < 2)
3843 goto end_fill;
3844
3845 dacs = spec->multiout.num_dacs;
3846 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3847 for (i = 0; i < cfg->num_inputs; i++) {
3848 hda_nid_t nid = cfg->inputs[i].pin;
3849 hda_nid_t dac = 0;
3850
3851 if (cfg->inputs[i].type != type)
3852 continue;
3853 if (!can_be_multiio_pin(codec, location, nid))
3854 continue;
3855 for (j = 0; j < spec->multi_ios; j++) {
3856 if (nid == spec->multi_io[j].pin)
3857 break;
3858 }
3859 if (j < spec->multi_ios)
3860 continue;
3861
3862 if (offset && offset + spec->multi_ios < dacs) {
3863 dac = spec->private_dac_nids[offset + spec->multi_ios];
3864 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3865 dac = 0;
3866 }
3867 if (hardwired)
3868 dac = get_dac_if_single(codec, nid);
3869 else if (!dac)
3870 dac = alc_auto_look_for_dac(codec, nid);
3871 if (!dac) {
3872 badness++;
3873 continue;
3874 }
3875 spec->multi_io[spec->multi_ios].pin = nid;
3876 spec->multi_io[spec->multi_ios].dac = dac;
3877 spec->multi_ios++;
3878 if (spec->multi_ios >= 2)
3879 break;
3880 }
3881 }
3882 end_fill:
3883 if (badness)
3884 badness = BAD_MULTI_IO;
3885 if (old_pins == spec->multi_ios) {
3886 if (hardwired)
3887 return 1; /* nothing found */
3888 else
3889 return badness; /* no badness if nothing found */
3890 }
3891 if (!hardwired && spec->multi_ios < 2) {
3892 spec->multi_ios = old_pins;
3893 return badness;
3894 }
3895
3896 return 0;
3897}
3898
3899static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3900 struct snd_ctl_elem_info *uinfo)
3901{
3902 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3903 struct alc_spec *spec = codec->spec;
3904
3905 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3906 uinfo->count = 1;
3907 uinfo->value.enumerated.items = spec->multi_ios + 1;
3908 if (uinfo->value.enumerated.item > spec->multi_ios)
3909 uinfo->value.enumerated.item = spec->multi_ios;
3910 sprintf(uinfo->value.enumerated.name, "%dch",
3911 (uinfo->value.enumerated.item + 1) * 2);
3912 return 0;
3913}
3914
3915static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3916 struct snd_ctl_elem_value *ucontrol)
3917{
3918 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3919 struct alc_spec *spec = codec->spec;
3920 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3921 return 0;
3922}
3923
3924static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3925{
3926 struct alc_spec *spec = codec->spec;
3927 hda_nid_t nid = spec->multi_io[idx].pin;
3928
3929 if (!spec->multi_io[idx].ctl_in)
3930 spec->multi_io[idx].ctl_in =
3931 snd_hda_codec_read(codec, nid, 0,
3932 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3933 if (output) {
3934 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
3935 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3936 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3937 HDA_AMP_MUTE, 0);
3938 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3939 } else {
3940 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3941 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3942 HDA_AMP_MUTE, HDA_AMP_MUTE);
3943 snd_hda_set_pin_ctl_cache(codec, nid,
3944 spec->multi_io[idx].ctl_in);
3945 }
3946 return 0;
3947}
3948
3949static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3950 struct snd_ctl_elem_value *ucontrol)
3951{
3952 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3953 struct alc_spec *spec = codec->spec;
3954 int i, ch;
3955
3956 ch = ucontrol->value.enumerated.item[0];
3957 if (ch < 0 || ch > spec->multi_ios)
3958 return -EINVAL;
3959 if (ch == (spec->ext_channel_count - 1) / 2)
3960 return 0;
3961 spec->ext_channel_count = (ch + 1) * 2;
3962 for (i = 0; i < spec->multi_ios; i++)
3963 alc_set_multi_io(codec, i, i < ch);
3964 spec->multiout.max_channels = max(spec->ext_channel_count,
3965 spec->const_channel_count);
3966 if (spec->need_dac_fix)
3967 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3968 return 1;
3969}
3970
3971static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3972 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3973 .name = "Channel Mode",
3974 .info = alc_auto_ch_mode_info,
3975 .get = alc_auto_ch_mode_get,
3976 .put = alc_auto_ch_mode_put,
3977};
3978
3979static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3980{
3981 struct alc_spec *spec = codec->spec;
3982
3983 if (spec->multi_ios > 0) {
3984 if (!alc_kcontrol_new(spec, "Channel Mode",
3985 &alc_auto_channel_mode_enum))
3986 return -ENOMEM;
3987 }
3988 return 0;
3989}
3990
3991/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3992 * active input pins
3993 */
3994static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3995{
3996 struct alc_spec *spec = codec->spec;
3997 const struct hda_input_mux *imux;
3998 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3999 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4000 int i, n, nums;
4001
4002 imux = spec->input_mux;
4003 if (!imux)
4004 return;
4005 if (spec->dyn_adc_switch)
4006 return;
4007
4008 again:
4009 nums = 0;
4010 for (n = 0; n < spec->num_adc_nids; n++) {
4011 hda_nid_t cap = spec->private_capsrc_nids[n];
4012 int num_conns = snd_hda_get_num_conns(codec, cap);
4013 for (i = 0; i < imux->num_items; i++) {
4014 hda_nid_t pin = spec->imux_pins[i];
4015 if (pin) {
4016 if (get_connection_index(codec, cap, pin) < 0)
4017 break;
4018 } else if (num_conns <= imux->items[i].index)
4019 break;
4020 }
4021 if (i >= imux->num_items) {
4022 adc_nids[nums] = spec->private_adc_nids[n];
4023 capsrc_nids[nums++] = cap;
4024 }
4025 }
4026 if (!nums) {
4027 /* check whether ADC-switch is possible */
4028 if (!alc_check_dyn_adc_switch(codec)) {
4029 if (spec->shared_mic_hp) {
4030 spec->shared_mic_hp = 0;
4031 spec->private_imux[0].num_items = 1;
4032 goto again;
4033 }
4034 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4035 " using fallback 0x%x\n",
4036 codec->chip_name, spec->private_adc_nids[0]);
4037 spec->num_adc_nids = 1;
4038 spec->auto_mic = 0;
4039 return;
4040 }
4041 } else if (nums != spec->num_adc_nids) {
4042 memcpy(spec->private_adc_nids, adc_nids,
4043 nums * sizeof(hda_nid_t));
4044 memcpy(spec->private_capsrc_nids, capsrc_nids,
4045 nums * sizeof(hda_nid_t));
4046 spec->num_adc_nids = nums;
4047 }
4048
4049 if (spec->auto_mic)
4050 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
4051 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
4052 spec->num_adc_nids = 1; /* reduce to a single ADC */
4053}
4054
4055/*
4056 * initialize ADC paths
4057 */
4058static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4059{
4060 struct alc_spec *spec = codec->spec;
4061 hda_nid_t nid;
4062
4063 nid = spec->adc_nids[adc_idx];
4064 /* mute ADC */
4065 if (nid_has_mute(codec, nid, HDA_INPUT)) {
4066 snd_hda_codec_write(codec, nid, 0,
4067 AC_VERB_SET_AMP_GAIN_MUTE,
4068 AMP_IN_MUTE(0));
4069 return;
4070 }
4071 if (!spec->capsrc_nids)
4072 return;
4073 nid = spec->capsrc_nids[adc_idx];
4074 if (nid_has_mute(codec, nid, HDA_OUTPUT))
4075 snd_hda_codec_write(codec, nid, 0,
4076 AC_VERB_SET_AMP_GAIN_MUTE,
4077 AMP_OUT_MUTE);
4078}
4079
4080static void alc_auto_init_input_src(struct hda_codec *codec)
4081{
4082 struct alc_spec *spec = codec->spec;
4083 int c, nums;
4084
4085 for (c = 0; c < spec->num_adc_nids; c++)
4086 alc_auto_init_adc(codec, c);
4087 if (spec->dyn_adc_switch)
4088 nums = 1;
4089 else
4090 nums = spec->num_adc_nids;
4091 for (c = 0; c < nums; c++)
4092 alc_mux_select(codec, c, spec->cur_mux[c], true);
4093}
4094
4095/* add mic boosts if needed */
4096static int alc_auto_add_mic_boost(struct hda_codec *codec)
4097{
4098 struct alc_spec *spec = codec->spec;
4099 struct auto_pin_cfg *cfg = &spec->autocfg;
4100 int i, err;
4101 int type_idx = 0;
4102 hda_nid_t nid;
4103 const char *prev_label = NULL;
4104
4105 for (i = 0; i < cfg->num_inputs; i++) {
4106 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4107 break;
4108 nid = cfg->inputs[i].pin;
4109 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4110 const char *label;
4111 char boost_label[32];
4112
4113 label = hda_get_autocfg_input_label(codec, cfg, i);
4114 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4115 label = "Headphone Mic";
4116 if (prev_label && !strcmp(label, prev_label))
4117 type_idx++;
4118 else
4119 type_idx = 0;
4120 prev_label = label;
4121
4122 snprintf(boost_label, sizeof(boost_label),
4123 "%s Boost Volume", label);
4124 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4125 boost_label, type_idx,
4126 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4127 if (err < 0)
4128 return err;
4129 }
4130 }
4131 return 0;
4132}
4133
4134/* select or unmute the given capsrc route */
4135static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4136 int idx)
4137{
4138 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4139 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4140 HDA_AMP_MUTE, 0);
4141 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
4142 snd_hda_codec_write_cache(codec, cap, 0,
4143 AC_VERB_SET_CONNECT_SEL, idx);
4144 }
4145}
4146
4147/* set the default connection to that pin */
4148static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4149{
4150 struct alc_spec *spec = codec->spec;
4151 int i;
4152
4153 if (!pin)
4154 return 0;
4155 for (i = 0; i < spec->num_adc_nids; i++) {
4156 hda_nid_t cap = get_capsrc(spec, i);
4157 int idx;
4158
4159 idx = get_connection_index(codec, cap, pin);
4160 if (idx < 0)
4161 continue;
4162 select_or_unmute_capsrc(codec, cap, idx);
4163 return i; /* return the found index */
4164 }
4165 return -1; /* not found */
4166}
4167
4168/* initialize some special cases for input sources */
4169static void alc_init_special_input_src(struct hda_codec *codec)
4170{
4171 struct alc_spec *spec = codec->spec;
4172 int i;
4173
4174 for (i = 0; i < spec->autocfg.num_inputs; i++)
4175 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4176}
4177
4178/* assign appropriate capture mixers */
4179static void set_capture_mixer(struct hda_codec *codec)
4180{
4181 struct alc_spec *spec = codec->spec;
4182 static const struct snd_kcontrol_new *caps[2][3] = {
4183 { alc_capture_mixer_nosrc1,
4184 alc_capture_mixer_nosrc2,
4185 alc_capture_mixer_nosrc3 },
4186 { alc_capture_mixer1,
4187 alc_capture_mixer2,
4188 alc_capture_mixer3 },
4189 };
4190
4191 /* check whether either of ADC or MUX has a volume control */
4192 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
4193 if (!spec->capsrc_nids)
4194 return; /* no volume */
4195 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
4196 return; /* no volume in capsrc, too */
4197 spec->vol_in_capsrc = 1;
4198 }
4199
4200 if (spec->num_adc_nids > 0) {
4201 int mux = 0;
4202 int num_adcs = 0;
4203
4204 if (spec->input_mux && spec->input_mux->num_items > 1)
4205 mux = 1;
4206 if (spec->auto_mic) {
4207 num_adcs = 1;
4208 mux = 0;
4209 } else if (spec->dyn_adc_switch)
4210 num_adcs = 1;
4211 if (!num_adcs) {
4212 if (spec->num_adc_nids > 3)
4213 spec->num_adc_nids = 3;
4214 else if (!spec->num_adc_nids)
4215 return;
4216 num_adcs = spec->num_adc_nids;
4217 }
4218 spec->cap_mixer = caps[mux][num_adcs - 1];
4219 }
4220}
4221
4222/*
4223 * standard auto-parser initializations
4224 */
4225static void alc_auto_init_std(struct hda_codec *codec)
4226{
4227 alc_auto_init_multi_out(codec);
4228 alc_auto_init_extra_out(codec);
4229 alc_auto_init_analog_input(codec);
4230 alc_auto_init_input_src(codec);
4231 alc_auto_init_digital(codec);
4232 alc_inithook(codec);
4233}
4234 920
4235/* 921/*
4236 * Digital-beep handlers 922 * Digital-beep handlers
@@ -4273,93 +959,20 @@ static int alc_parse_auto_config(struct hda_codec *codec,
4273 const hda_nid_t *ssid_nids) 959 const hda_nid_t *ssid_nids)
4274{ 960{
4275 struct alc_spec *spec = codec->spec; 961 struct alc_spec *spec = codec->spec;
4276 struct auto_pin_cfg *cfg = &spec->autocfg; 962 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
4277 int err; 963 int err;
4278 964
4279 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids, 965 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4280 spec->parse_flags); 966 spec->parse_flags);
4281 if (err < 0) 967 if (err < 0)
4282 return err; 968 return err;
4283 if (!cfg->line_outs) {
4284 if (cfg->dig_outs || cfg->dig_in_pin) {
4285 spec->multiout.max_channels = 2;
4286 spec->no_analog = 1;
4287 goto dig_only;
4288 }
4289 return 0; /* can't find valid BIOS pin config */
4290 }
4291
4292 if (!spec->no_primary_hp &&
4293 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4294 cfg->line_outs <= cfg->hp_outs) {
4295 /* use HP as primary out */
4296 cfg->speaker_outs = cfg->line_outs;
4297 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4298 sizeof(cfg->speaker_pins));
4299 cfg->line_outs = cfg->hp_outs;
4300 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4301 cfg->hp_outs = 0;
4302 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4303 cfg->line_out_type = AUTO_PIN_HP_OUT;
4304 }
4305
4306 err = alc_auto_fill_dac_nids(codec);
4307 if (err < 0)
4308 return err;
4309 err = alc_auto_add_multi_channel_mode(codec);
4310 if (err < 0)
4311 return err;
4312 err = alc_auto_create_multi_out_ctls(codec, cfg);
4313 if (err < 0)
4314 return err;
4315 err = alc_auto_create_hp_out(codec);
4316 if (err < 0)
4317 return err;
4318 err = alc_auto_create_speaker_out(codec);
4319 if (err < 0)
4320 return err;
4321 err = alc_auto_create_shared_input(codec);
4322 if (err < 0)
4323 return err;
4324 err = alc_auto_create_input_ctls(codec);
4325 if (err < 0)
4326 return err;
4327
4328 /* check the multiple speaker pins */
4329 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4330 spec->const_channel_count = cfg->line_outs * 2;
4331 else
4332 spec->const_channel_count = cfg->speaker_outs * 2;
4333
4334 if (spec->multi_ios > 0)
4335 spec->multiout.max_channels = max(spec->ext_channel_count,
4336 spec->const_channel_count);
4337 else
4338 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4339
4340 dig_only:
4341 alc_auto_parse_digital(codec);
4342
4343 if (!spec->no_analog)
4344 alc_remove_invalid_adc_nids(codec);
4345 969
4346 if (ssid_nids) 970 if (ssid_nids)
4347 alc_ssid_check(codec, ssid_nids); 971 alc_ssid_check(codec, ssid_nids);
4348 972
4349 if (!spec->no_analog) { 973 err = snd_hda_gen_parse_auto_config(codec, cfg);
4350 err = alc_auto_check_switches(codec); 974 if (err < 0)
4351 if (err < 0) 975 return err;
4352 return err;
4353 err = alc_auto_add_mic_boost(codec);
4354 if (err < 0)
4355 return err;
4356 }
4357
4358 if (spec->kctls.list)
4359 add_mixer(spec, spec->kctls.list);
4360
4361 if (!spec->no_analog && !spec->cap_mixer)
4362 set_capture_mixer(codec);
4363 976
4364 return 1; 977 return 1;
4365} 978}
@@ -4373,11 +986,12 @@ static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4373 if (!spec) 986 if (!spec)
4374 return -ENOMEM; 987 return -ENOMEM;
4375 codec->spec = spec; 988 codec->spec = spec;
989 snd_hda_gen_spec_init(&spec->gen);
990 spec->gen.mixer_nid = mixer_nid;
991 spec->gen.own_eapd_ctl = 1;
4376 codec->single_adc_amp = 1; 992 codec->single_adc_amp = 1;
4377 spec->mixer_nid = mixer_nid; 993 /* FIXME: do we need this for all Realtek codec models? */
4378 snd_hda_gen_init(&spec->gen); 994 codec->spdif_status_reset = 1;
4379 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4380 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
4381 995
4382 err = alc_codec_rename_from_preset(codec); 996 err = alc_codec_rename_from_preset(codec);
4383 if (err < 0) { 997 if (err < 0) {
@@ -4420,27 +1034,28 @@ enum {
4420 ALC880_FIXUP_6ST_BASE, 1034 ALC880_FIXUP_6ST_BASE,
4421 ALC880_FIXUP_6ST, 1035 ALC880_FIXUP_6ST,
4422 ALC880_FIXUP_6ST_DIG, 1036 ALC880_FIXUP_6ST_DIG,
1037 ALC880_FIXUP_6ST_AUTOMUTE,
4423}; 1038};
4424 1039
4425/* enable the volume-knob widget support on NID 0x21 */ 1040/* enable the volume-knob widget support on NID 0x21 */
4426static void alc880_fixup_vol_knob(struct hda_codec *codec, 1041static void alc880_fixup_vol_knob(struct hda_codec *codec,
4427 const struct alc_fixup *fix, int action) 1042 const struct hda_fixup *fix, int action)
4428{ 1043{
4429 if (action == ALC_FIXUP_ACT_PROBE) 1044 if (action == HDA_FIXUP_ACT_PROBE)
4430 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master); 1045 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
4431} 1046}
4432 1047
4433static const struct alc_fixup alc880_fixups[] = { 1048static const struct hda_fixup alc880_fixups[] = {
4434 [ALC880_FIXUP_GPIO1] = { 1049 [ALC880_FIXUP_GPIO1] = {
4435 .type = ALC_FIXUP_VERBS, 1050 .type = HDA_FIXUP_VERBS,
4436 .v.verbs = alc_gpio1_init_verbs, 1051 .v.verbs = alc_gpio1_init_verbs,
4437 }, 1052 },
4438 [ALC880_FIXUP_GPIO2] = { 1053 [ALC880_FIXUP_GPIO2] = {
4439 .type = ALC_FIXUP_VERBS, 1054 .type = HDA_FIXUP_VERBS,
4440 .v.verbs = alc_gpio2_init_verbs, 1055 .v.verbs = alc_gpio2_init_verbs,
4441 }, 1056 },
4442 [ALC880_FIXUP_MEDION_RIM] = { 1057 [ALC880_FIXUP_MEDION_RIM] = {
4443 .type = ALC_FIXUP_VERBS, 1058 .type = HDA_FIXUP_VERBS,
4444 .v.verbs = (const struct hda_verb[]) { 1059 .v.verbs = (const struct hda_verb[]) {
4445 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1060 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4446 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 }, 1061 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
@@ -4450,8 +1065,8 @@ static const struct alc_fixup alc880_fixups[] = {
4450 .chain_id = ALC880_FIXUP_GPIO2, 1065 .chain_id = ALC880_FIXUP_GPIO2,
4451 }, 1066 },
4452 [ALC880_FIXUP_LG] = { 1067 [ALC880_FIXUP_LG] = {
4453 .type = ALC_FIXUP_PINS, 1068 .type = HDA_FIXUP_PINS,
4454 .v.pins = (const struct alc_pincfg[]) { 1069 .v.pins = (const struct hda_pintbl[]) {
4455 /* disable bogus unused pins */ 1070 /* disable bogus unused pins */
4456 { 0x16, 0x411111f0 }, 1071 { 0x16, 0x411111f0 },
4457 { 0x18, 0x411111f0 }, 1072 { 0x18, 0x411111f0 },
@@ -4460,8 +1075,8 @@ static const struct alc_fixup alc880_fixups[] = {
4460 } 1075 }
4461 }, 1076 },
4462 [ALC880_FIXUP_W810] = { 1077 [ALC880_FIXUP_W810] = {
4463 .type = ALC_FIXUP_PINS, 1078 .type = HDA_FIXUP_PINS,
4464 .v.pins = (const struct alc_pincfg[]) { 1079 .v.pins = (const struct hda_pintbl[]) {
4465 /* disable bogus unused pins */ 1080 /* disable bogus unused pins */
4466 { 0x17, 0x411111f0 }, 1081 { 0x17, 0x411111f0 },
4467 { } 1082 { }
@@ -4470,7 +1085,7 @@ static const struct alc_fixup alc880_fixups[] = {
4470 .chain_id = ALC880_FIXUP_GPIO2, 1085 .chain_id = ALC880_FIXUP_GPIO2,
4471 }, 1086 },
4472 [ALC880_FIXUP_EAPD_COEF] = { 1087 [ALC880_FIXUP_EAPD_COEF] = {
4473 .type = ALC_FIXUP_VERBS, 1088 .type = HDA_FIXUP_VERBS,
4474 .v.verbs = (const struct hda_verb[]) { 1089 .v.verbs = (const struct hda_verb[]) {
4475 /* change to EAPD mode */ 1090 /* change to EAPD mode */
4476 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1091 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
@@ -4479,7 +1094,7 @@ static const struct alc_fixup alc880_fixups[] = {
4479 }, 1094 },
4480 }, 1095 },
4481 [ALC880_FIXUP_TCL_S700] = { 1096 [ALC880_FIXUP_TCL_S700] = {
4482 .type = ALC_FIXUP_VERBS, 1097 .type = HDA_FIXUP_VERBS,
4483 .v.verbs = (const struct hda_verb[]) { 1098 .v.verbs = (const struct hda_verb[]) {
4484 /* change to EAPD mode */ 1099 /* change to EAPD mode */
4485 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1100 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
@@ -4490,13 +1105,13 @@ static const struct alc_fixup alc880_fixups[] = {
4490 .chain_id = ALC880_FIXUP_GPIO2, 1105 .chain_id = ALC880_FIXUP_GPIO2,
4491 }, 1106 },
4492 [ALC880_FIXUP_VOL_KNOB] = { 1107 [ALC880_FIXUP_VOL_KNOB] = {
4493 .type = ALC_FIXUP_FUNC, 1108 .type = HDA_FIXUP_FUNC,
4494 .v.func = alc880_fixup_vol_knob, 1109 .v.func = alc880_fixup_vol_knob,
4495 }, 1110 },
4496 [ALC880_FIXUP_FUJITSU] = { 1111 [ALC880_FIXUP_FUJITSU] = {
4497 /* override all pins as BIOS on old Amilo is broken */ 1112 /* override all pins as BIOS on old Amilo is broken */
4498 .type = ALC_FIXUP_PINS, 1113 .type = HDA_FIXUP_PINS,
4499 .v.pins = (const struct alc_pincfg[]) { 1114 .v.pins = (const struct hda_pintbl[]) {
4500 { 0x14, 0x0121411f }, /* HP */ 1115 { 0x14, 0x0121411f }, /* HP */
4501 { 0x15, 0x99030120 }, /* speaker */ 1116 { 0x15, 0x99030120 }, /* speaker */
4502 { 0x16, 0x99030130 }, /* bass speaker */ 1117 { 0x16, 0x99030130 }, /* bass speaker */
@@ -4515,8 +1130,8 @@ static const struct alc_fixup alc880_fixups[] = {
4515 }, 1130 },
4516 [ALC880_FIXUP_F1734] = { 1131 [ALC880_FIXUP_F1734] = {
4517 /* almost compatible with FUJITSU, but no bass and SPDIF */ 1132 /* almost compatible with FUJITSU, but no bass and SPDIF */
4518 .type = ALC_FIXUP_PINS, 1133 .type = HDA_FIXUP_PINS,
4519 .v.pins = (const struct alc_pincfg[]) { 1134 .v.pins = (const struct hda_pintbl[]) {
4520 { 0x14, 0x0121411f }, /* HP */ 1135 { 0x14, 0x0121411f }, /* HP */
4521 { 0x15, 0x99030120 }, /* speaker */ 1136 { 0x15, 0x99030120 }, /* speaker */
4522 { 0x16, 0x411111f0 }, /* N/A */ 1137 { 0x16, 0x411111f0 }, /* N/A */
@@ -4535,8 +1150,8 @@ static const struct alc_fixup alc880_fixups[] = {
4535 }, 1150 },
4536 [ALC880_FIXUP_UNIWILL] = { 1151 [ALC880_FIXUP_UNIWILL] = {
4537 /* need to fix HP and speaker pins to be parsed correctly */ 1152 /* need to fix HP and speaker pins to be parsed correctly */
4538 .type = ALC_FIXUP_PINS, 1153 .type = HDA_FIXUP_PINS,
4539 .v.pins = (const struct alc_pincfg[]) { 1154 .v.pins = (const struct hda_pintbl[]) {
4540 { 0x14, 0x0121411f }, /* HP */ 1155 { 0x14, 0x0121411f }, /* HP */
4541 { 0x15, 0x99030120 }, /* speaker */ 1156 { 0x15, 0x99030120 }, /* speaker */
4542 { 0x16, 0x99030130 }, /* bass speaker */ 1157 { 0x16, 0x99030130 }, /* bass speaker */
@@ -4544,8 +1159,8 @@ static const struct alc_fixup alc880_fixups[] = {
4544 }, 1159 },
4545 }, 1160 },
4546 [ALC880_FIXUP_UNIWILL_DIG] = { 1161 [ALC880_FIXUP_UNIWILL_DIG] = {
4547 .type = ALC_FIXUP_PINS, 1162 .type = HDA_FIXUP_PINS,
4548 .v.pins = (const struct alc_pincfg[]) { 1163 .v.pins = (const struct hda_pintbl[]) {
4549 /* disable bogus unused pins */ 1164 /* disable bogus unused pins */
4550 { 0x17, 0x411111f0 }, 1165 { 0x17, 0x411111f0 },
4551 { 0x19, 0x411111f0 }, 1166 { 0x19, 0x411111f0 },
@@ -4555,8 +1170,8 @@ static const struct alc_fixup alc880_fixups[] = {
4555 } 1170 }
4556 }, 1171 },
4557 [ALC880_FIXUP_Z71V] = { 1172 [ALC880_FIXUP_Z71V] = {
4558 .type = ALC_FIXUP_PINS, 1173 .type = HDA_FIXUP_PINS,
4559 .v.pins = (const struct alc_pincfg[]) { 1174 .v.pins = (const struct hda_pintbl[]) {
4560 /* set up the whole pins as BIOS is utterly broken */ 1175 /* set up the whole pins as BIOS is utterly broken */
4561 { 0x14, 0x99030120 }, /* speaker */ 1176 { 0x14, 0x99030120 }, /* speaker */
4562 { 0x15, 0x0121411f }, /* HP */ 1177 { 0x15, 0x0121411f }, /* HP */
@@ -4573,8 +1188,8 @@ static const struct alc_fixup alc880_fixups[] = {
4573 } 1188 }
4574 }, 1189 },
4575 [ALC880_FIXUP_3ST_BASE] = { 1190 [ALC880_FIXUP_3ST_BASE] = {
4576 .type = ALC_FIXUP_PINS, 1191 .type = HDA_FIXUP_PINS,
4577 .v.pins = (const struct alc_pincfg[]) { 1192 .v.pins = (const struct hda_pintbl[]) {
4578 { 0x14, 0x01014010 }, /* line-out */ 1193 { 0x14, 0x01014010 }, /* line-out */
4579 { 0x15, 0x411111f0 }, /* N/A */ 1194 { 0x15, 0x411111f0 }, /* N/A */
4580 { 0x16, 0x411111f0 }, /* N/A */ 1195 { 0x16, 0x411111f0 }, /* N/A */
@@ -4591,8 +1206,8 @@ static const struct alc_fixup alc880_fixups[] = {
4591 } 1206 }
4592 }, 1207 },
4593 [ALC880_FIXUP_3ST] = { 1208 [ALC880_FIXUP_3ST] = {
4594 .type = ALC_FIXUP_PINS, 1209 .type = HDA_FIXUP_PINS,
4595 .v.pins = (const struct alc_pincfg[]) { 1210 .v.pins = (const struct hda_pintbl[]) {
4596 { 0x1e, 0x411111f0 }, /* N/A */ 1211 { 0x1e, 0x411111f0 }, /* N/A */
4597 { } 1212 { }
4598 }, 1213 },
@@ -4600,8 +1215,8 @@ static const struct alc_fixup alc880_fixups[] = {
4600 .chain_id = ALC880_FIXUP_3ST_BASE, 1215 .chain_id = ALC880_FIXUP_3ST_BASE,
4601 }, 1216 },
4602 [ALC880_FIXUP_3ST_DIG] = { 1217 [ALC880_FIXUP_3ST_DIG] = {
4603 .type = ALC_FIXUP_PINS, 1218 .type = HDA_FIXUP_PINS,
4604 .v.pins = (const struct alc_pincfg[]) { 1219 .v.pins = (const struct hda_pintbl[]) {
4605 { 0x1e, 0x0144111e }, /* SPDIF */ 1220 { 0x1e, 0x0144111e }, /* SPDIF */
4606 { } 1221 { }
4607 }, 1222 },
@@ -4609,8 +1224,8 @@ static const struct alc_fixup alc880_fixups[] = {
4609 .chain_id = ALC880_FIXUP_3ST_BASE, 1224 .chain_id = ALC880_FIXUP_3ST_BASE,
4610 }, 1225 },
4611 [ALC880_FIXUP_5ST_BASE] = { 1226 [ALC880_FIXUP_5ST_BASE] = {
4612 .type = ALC_FIXUP_PINS, 1227 .type = HDA_FIXUP_PINS,
4613 .v.pins = (const struct alc_pincfg[]) { 1228 .v.pins = (const struct hda_pintbl[]) {
4614 { 0x14, 0x01014010 }, /* front */ 1229 { 0x14, 0x01014010 }, /* front */
4615 { 0x15, 0x411111f0 }, /* N/A */ 1230 { 0x15, 0x411111f0 }, /* N/A */
4616 { 0x16, 0x01011411 }, /* CLFE */ 1231 { 0x16, 0x01011411 }, /* CLFE */
@@ -4627,8 +1242,8 @@ static const struct alc_fixup alc880_fixups[] = {
4627 } 1242 }
4628 }, 1243 },
4629 [ALC880_FIXUP_5ST] = { 1244 [ALC880_FIXUP_5ST] = {
4630 .type = ALC_FIXUP_PINS, 1245 .type = HDA_FIXUP_PINS,
4631 .v.pins = (const struct alc_pincfg[]) { 1246 .v.pins = (const struct hda_pintbl[]) {
4632 { 0x1e, 0x411111f0 }, /* N/A */ 1247 { 0x1e, 0x411111f0 }, /* N/A */
4633 { } 1248 { }
4634 }, 1249 },
@@ -4636,8 +1251,8 @@ static const struct alc_fixup alc880_fixups[] = {
4636 .chain_id = ALC880_FIXUP_5ST_BASE, 1251 .chain_id = ALC880_FIXUP_5ST_BASE,
4637 }, 1252 },
4638 [ALC880_FIXUP_5ST_DIG] = { 1253 [ALC880_FIXUP_5ST_DIG] = {
4639 .type = ALC_FIXUP_PINS, 1254 .type = HDA_FIXUP_PINS,
4640 .v.pins = (const struct alc_pincfg[]) { 1255 .v.pins = (const struct hda_pintbl[]) {
4641 { 0x1e, 0x0144111e }, /* SPDIF */ 1256 { 0x1e, 0x0144111e }, /* SPDIF */
4642 { } 1257 { }
4643 }, 1258 },
@@ -4645,8 +1260,8 @@ static const struct alc_fixup alc880_fixups[] = {
4645 .chain_id = ALC880_FIXUP_5ST_BASE, 1260 .chain_id = ALC880_FIXUP_5ST_BASE,
4646 }, 1261 },
4647 [ALC880_FIXUP_6ST_BASE] = { 1262 [ALC880_FIXUP_6ST_BASE] = {
4648 .type = ALC_FIXUP_PINS, 1263 .type = HDA_FIXUP_PINS,
4649 .v.pins = (const struct alc_pincfg[]) { 1264 .v.pins = (const struct hda_pintbl[]) {
4650 { 0x14, 0x01014010 }, /* front */ 1265 { 0x14, 0x01014010 }, /* front */
4651 { 0x15, 0x01016412 }, /* surr */ 1266 { 0x15, 0x01016412 }, /* surr */
4652 { 0x16, 0x01011411 }, /* CLFE */ 1267 { 0x16, 0x01011411 }, /* CLFE */
@@ -4663,8 +1278,8 @@ static const struct alc_fixup alc880_fixups[] = {
4663 } 1278 }
4664 }, 1279 },
4665 [ALC880_FIXUP_6ST] = { 1280 [ALC880_FIXUP_6ST] = {
4666 .type = ALC_FIXUP_PINS, 1281 .type = HDA_FIXUP_PINS,
4667 .v.pins = (const struct alc_pincfg[]) { 1282 .v.pins = (const struct hda_pintbl[]) {
4668 { 0x1e, 0x411111f0 }, /* N/A */ 1283 { 0x1e, 0x411111f0 }, /* N/A */
4669 { } 1284 { }
4670 }, 1285 },
@@ -4672,14 +1287,23 @@ static const struct alc_fixup alc880_fixups[] = {
4672 .chain_id = ALC880_FIXUP_6ST_BASE, 1287 .chain_id = ALC880_FIXUP_6ST_BASE,
4673 }, 1288 },
4674 [ALC880_FIXUP_6ST_DIG] = { 1289 [ALC880_FIXUP_6ST_DIG] = {
4675 .type = ALC_FIXUP_PINS, 1290 .type = HDA_FIXUP_PINS,
4676 .v.pins = (const struct alc_pincfg[]) { 1291 .v.pins = (const struct hda_pintbl[]) {
4677 { 0x1e, 0x0144111e }, /* SPDIF */ 1292 { 0x1e, 0x0144111e }, /* SPDIF */
4678 { } 1293 { }
4679 }, 1294 },
4680 .chained = true, 1295 .chained = true,
4681 .chain_id = ALC880_FIXUP_6ST_BASE, 1296 .chain_id = ALC880_FIXUP_6ST_BASE,
4682 }, 1297 },
1298 [ALC880_FIXUP_6ST_AUTOMUTE] = {
1299 .type = HDA_FIXUP_PINS,
1300 .v.pins = (const struct hda_pintbl[]) {
1301 { 0x1b, 0x0121401f }, /* HP with jack detect */
1302 { }
1303 },
1304 .chained_before = true,
1305 .chain_id = ALC880_FIXUP_6ST_BASE,
1306 },
4683}; 1307};
4684 1308
4685static const struct snd_pci_quirk alc880_fixup_tbl[] = { 1309static const struct snd_pci_quirk alc880_fixup_tbl[] = {
@@ -4694,7 +1318,7 @@ static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4694 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB), 1318 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
4695 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810), 1319 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
4696 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM), 1320 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4697 SND_PCI_QUIRK(0x1631, 0xe011, "PB 13201056", ALC880_FIXUP_6ST), 1321 SND_PCI_QUIRK(0x1631, 0xe011, "PB 13201056", ALC880_FIXUP_6ST_AUTOMUTE),
4698 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734), 1322 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
4699 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU), 1323 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
4700 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734), 1324 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
@@ -4750,13 +1374,14 @@ static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4750 {} 1374 {}
4751}; 1375};
4752 1376
4753static const struct alc_model_fixup alc880_fixup_models[] = { 1377static const struct hda_model_fixup alc880_fixup_models[] = {
4754 {.id = ALC880_FIXUP_3ST, .name = "3stack"}, 1378 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4755 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"}, 1379 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4756 {.id = ALC880_FIXUP_5ST, .name = "5stack"}, 1380 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4757 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"}, 1381 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4758 {.id = ALC880_FIXUP_6ST, .name = "6stack"}, 1382 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4759 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"}, 1383 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
1384 {.id = ALC880_FIXUP_6ST_AUTOMUTE, .name = "6stack-automute"},
4760 {} 1385 {}
4761}; 1386};
4762 1387
@@ -4774,18 +1399,18 @@ static int patch_alc880(struct hda_codec *codec)
4774 return err; 1399 return err;
4775 1400
4776 spec = codec->spec; 1401 spec = codec->spec;
4777 spec->need_dac_fix = 1; 1402 spec->gen.need_dac_fix = 1;
4778 1403
4779 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl, 1404 snd_hda_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4780 alc880_fixups); 1405 alc880_fixups);
4781 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 1406 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4782 1407
4783 /* automatic parse from the BIOS config */ 1408 /* automatic parse from the BIOS config */
4784 err = alc880_parse_auto_config(codec); 1409 err = alc880_parse_auto_config(codec);
4785 if (err < 0) 1410 if (err < 0)
4786 goto error; 1411 goto error;
4787 1412
4788 if (!spec->no_analog) { 1413 if (!spec->gen.no_analog) {
4789 err = snd_hda_attach_beep_device(codec, 0x1); 1414 err = snd_hda_attach_beep_device(codec, 0x1);
4790 if (err < 0) 1415 if (err < 0)
4791 goto error; 1416 goto error;
@@ -4796,7 +1421,7 @@ static int patch_alc880(struct hda_codec *codec)
4796 codec->patch_ops.unsol_event = alc880_unsol_event; 1421 codec->patch_ops.unsol_event = alc880_unsol_event;
4797 1422
4798 1423
4799 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 1424 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
4800 1425
4801 return 0; 1426 return 0;
4802 1427
@@ -4828,38 +1453,39 @@ enum {
4828 ALC260_FIXUP_REPLACER, 1453 ALC260_FIXUP_REPLACER,
4829 ALC260_FIXUP_HP_B1900, 1454 ALC260_FIXUP_HP_B1900,
4830 ALC260_FIXUP_KN1, 1455 ALC260_FIXUP_KN1,
1456 ALC260_FIXUP_FSC_S7020,
4831}; 1457};
4832 1458
4833static void alc260_gpio1_automute(struct hda_codec *codec) 1459static void alc260_gpio1_automute(struct hda_codec *codec)
4834{ 1460{
4835 struct alc_spec *spec = codec->spec; 1461 struct alc_spec *spec = codec->spec;
4836 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 1462 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4837 spec->hp_jack_present); 1463 spec->gen.hp_jack_present);
4838} 1464}
4839 1465
4840static void alc260_fixup_gpio1_toggle(struct hda_codec *codec, 1466static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4841 const struct alc_fixup *fix, int action) 1467 const struct hda_fixup *fix, int action)
4842{ 1468{
4843 struct alc_spec *spec = codec->spec; 1469 struct alc_spec *spec = codec->spec;
4844 if (action == ALC_FIXUP_ACT_PROBE) { 1470 if (action == HDA_FIXUP_ACT_PROBE) {
4845 /* although the machine has only one output pin, we need to 1471 /* although the machine has only one output pin, we need to
4846 * toggle GPIO1 according to the jack state 1472 * toggle GPIO1 according to the jack state
4847 */ 1473 */
4848 spec->automute_hook = alc260_gpio1_automute; 1474 spec->gen.automute_hook = alc260_gpio1_automute;
4849 spec->detect_hp = 1; 1475 spec->gen.detect_hp = 1;
4850 spec->automute_speaker = 1; 1476 spec->gen.automute_speaker = 1;
4851 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */ 1477 spec->gen.autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4852 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT, 1478 snd_hda_jack_detect_enable_callback(codec, 0x0f, HDA_GEN_HP_EVENT,
4853 alc_hp_automute); 1479 snd_hda_gen_hp_automute);
4854 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs); 1480 snd_hda_add_verbs(codec, alc_gpio1_init_verbs);
4855 } 1481 }
4856} 1482}
4857 1483
4858static void alc260_fixup_kn1(struct hda_codec *codec, 1484static void alc260_fixup_kn1(struct hda_codec *codec,
4859 const struct alc_fixup *fix, int action) 1485 const struct hda_fixup *fix, int action)
4860{ 1486{
4861 struct alc_spec *spec = codec->spec; 1487 struct alc_spec *spec = codec->spec;
4862 static const struct alc_pincfg pincfgs[] = { 1488 static const struct hda_pintbl pincfgs[] = {
4863 { 0x0f, 0x02214000 }, /* HP/speaker */ 1489 { 0x0f, 0x02214000 }, /* HP/speaker */
4864 { 0x12, 0x90a60160 }, /* int mic */ 1490 { 0x12, 0x90a60160 }, /* int mic */
4865 { 0x13, 0x02a19000 }, /* ext mic */ 1491 { 0x13, 0x02a19000 }, /* ext mic */
@@ -4876,32 +1502,47 @@ static void alc260_fixup_kn1(struct hda_codec *codec,
4876 }; 1502 };
4877 1503
4878 switch (action) { 1504 switch (action) {
4879 case ALC_FIXUP_ACT_PRE_PROBE: 1505 case HDA_FIXUP_ACT_PRE_PROBE:
4880 alc_apply_pincfgs(codec, pincfgs); 1506 snd_hda_apply_pincfgs(codec, pincfgs);
4881 break; 1507 break;
4882 case ALC_FIXUP_ACT_PROBE: 1508 case HDA_FIXUP_ACT_PROBE:
4883 spec->init_amp = ALC_INIT_NONE; 1509 spec->init_amp = ALC_INIT_NONE;
4884 break; 1510 break;
4885 } 1511 }
4886} 1512}
4887 1513
4888static const struct alc_fixup alc260_fixups[] = { 1514static void alc260_fixup_fsc_s7020(struct hda_codec *codec,
1515 const struct hda_fixup *fix, int action)
1516{
1517 struct alc_spec *spec = codec->spec;
1518
1519 switch (action) {
1520 case HDA_FIXUP_ACT_PRE_PROBE:
1521 spec->gen.add_out_jack_modes = 1;
1522 break;
1523 case HDA_FIXUP_ACT_PROBE:
1524 spec->init_amp = ALC_INIT_NONE;
1525 break;
1526 }
1527}
1528
1529static const struct hda_fixup alc260_fixups[] = {
4889 [ALC260_FIXUP_HP_DC5750] = { 1530 [ALC260_FIXUP_HP_DC5750] = {
4890 .type = ALC_FIXUP_PINS, 1531 .type = HDA_FIXUP_PINS,
4891 .v.pins = (const struct alc_pincfg[]) { 1532 .v.pins = (const struct hda_pintbl[]) {
4892 { 0x11, 0x90130110 }, /* speaker */ 1533 { 0x11, 0x90130110 }, /* speaker */
4893 { } 1534 { }
4894 } 1535 }
4895 }, 1536 },
4896 [ALC260_FIXUP_HP_PIN_0F] = { 1537 [ALC260_FIXUP_HP_PIN_0F] = {
4897 .type = ALC_FIXUP_PINS, 1538 .type = HDA_FIXUP_PINS,
4898 .v.pins = (const struct alc_pincfg[]) { 1539 .v.pins = (const struct hda_pintbl[]) {
4899 { 0x0f, 0x01214000 }, /* HP */ 1540 { 0x0f, 0x01214000 }, /* HP */
4900 { } 1541 { }
4901 } 1542 }
4902 }, 1543 },
4903 [ALC260_FIXUP_COEF] = { 1544 [ALC260_FIXUP_COEF] = {
4904 .type = ALC_FIXUP_VERBS, 1545 .type = HDA_FIXUP_VERBS,
4905 .v.verbs = (const struct hda_verb[]) { 1546 .v.verbs = (const struct hda_verb[]) {
4906 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1547 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4907 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 }, 1548 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
@@ -4911,17 +1552,17 @@ static const struct alc_fixup alc260_fixups[] = {
4911 .chain_id = ALC260_FIXUP_HP_PIN_0F, 1552 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4912 }, 1553 },
4913 [ALC260_FIXUP_GPIO1] = { 1554 [ALC260_FIXUP_GPIO1] = {
4914 .type = ALC_FIXUP_VERBS, 1555 .type = HDA_FIXUP_VERBS,
4915 .v.verbs = alc_gpio1_init_verbs, 1556 .v.verbs = alc_gpio1_init_verbs,
4916 }, 1557 },
4917 [ALC260_FIXUP_GPIO1_TOGGLE] = { 1558 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4918 .type = ALC_FIXUP_FUNC, 1559 .type = HDA_FIXUP_FUNC,
4919 .v.func = alc260_fixup_gpio1_toggle, 1560 .v.func = alc260_fixup_gpio1_toggle,
4920 .chained = true, 1561 .chained = true,
4921 .chain_id = ALC260_FIXUP_HP_PIN_0F, 1562 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4922 }, 1563 },
4923 [ALC260_FIXUP_REPLACER] = { 1564 [ALC260_FIXUP_REPLACER] = {
4924 .type = ALC_FIXUP_VERBS, 1565 .type = HDA_FIXUP_VERBS,
4925 .v.verbs = (const struct hda_verb[]) { 1566 .v.verbs = (const struct hda_verb[]) {
4926 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1567 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4927 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, 1568 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
@@ -4931,15 +1572,19 @@ static const struct alc_fixup alc260_fixups[] = {
4931 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE, 1572 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4932 }, 1573 },
4933 [ALC260_FIXUP_HP_B1900] = { 1574 [ALC260_FIXUP_HP_B1900] = {
4934 .type = ALC_FIXUP_FUNC, 1575 .type = HDA_FIXUP_FUNC,
4935 .v.func = alc260_fixup_gpio1_toggle, 1576 .v.func = alc260_fixup_gpio1_toggle,
4936 .chained = true, 1577 .chained = true,
4937 .chain_id = ALC260_FIXUP_COEF, 1578 .chain_id = ALC260_FIXUP_COEF,
4938 }, 1579 },
4939 [ALC260_FIXUP_KN1] = { 1580 [ALC260_FIXUP_KN1] = {
4940 .type = ALC_FIXUP_FUNC, 1581 .type = HDA_FIXUP_FUNC,
4941 .v.func = alc260_fixup_kn1, 1582 .v.func = alc260_fixup_kn1,
4942 }, 1583 },
1584 [ALC260_FIXUP_FSC_S7020] = {
1585 .type = HDA_FIXUP_FUNC,
1586 .v.func = alc260_fixup_fsc_s7020,
1587 },
4943}; 1588};
4944 1589
4945static const struct snd_pci_quirk alc260_fixup_tbl[] = { 1590static const struct snd_pci_quirk alc260_fixup_tbl[] = {
@@ -4948,6 +1593,7 @@ static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4948 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1), 1593 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
4949 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750), 1594 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
4950 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900), 1595 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
1596 SND_PCI_QUIRK(0x10cf, 0x1326, "FSC LifeBook S7020", ALC260_FIXUP_FSC_S7020),
4951 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1), 1597 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
4952 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1), 1598 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
4953 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER), 1599 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
@@ -4967,16 +1613,21 @@ static int patch_alc260(struct hda_codec *codec)
4967 return err; 1613 return err;
4968 1614
4969 spec = codec->spec; 1615 spec = codec->spec;
1616 /* as quite a few machines require HP amp for speaker outputs,
1617 * it's easier to enable it unconditionally; even if it's unneeded,
1618 * it's almost harmless.
1619 */
1620 spec->gen.prefer_hp_amp = 1;
4970 1621
4971 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); 1622 snd_hda_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4972 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 1623 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4973 1624
4974 /* automatic parse from the BIOS config */ 1625 /* automatic parse from the BIOS config */
4975 err = alc260_parse_auto_config(codec); 1626 err = alc260_parse_auto_config(codec);
4976 if (err < 0) 1627 if (err < 0)
4977 goto error; 1628 goto error;
4978 1629
4979 if (!spec->no_analog) { 1630 if (!spec->gen.no_analog) {
4980 err = snd_hda_attach_beep_device(codec, 0x1); 1631 err = snd_hda_attach_beep_device(codec, 0x1);
4981 if (err < 0) 1632 if (err < 0)
4982 goto error; 1633 goto error;
@@ -4986,7 +1637,7 @@ static int patch_alc260(struct hda_codec *codec)
4986 codec->patch_ops = alc_patch_ops; 1637 codec->patch_ops = alc_patch_ops;
4987 spec->shutup = alc_eapd_shutup; 1638 spec->shutup = alc_eapd_shutup;
4988 1639
4989 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 1640 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
4990 1641
4991 return 0; 1642 return 0;
4992 1643
@@ -5040,9 +1691,9 @@ enum {
5040}; 1691};
5041 1692
5042static void alc889_fixup_coef(struct hda_codec *codec, 1693static void alc889_fixup_coef(struct hda_codec *codec,
5043 const struct alc_fixup *fix, int action) 1694 const struct hda_fixup *fix, int action)
5044{ 1695{
5045 if (action != ALC_FIXUP_ACT_INIT) 1696 if (action != HDA_FIXUP_ACT_INIT)
5046 return; 1697 return;
5047 alc889_coef_init(codec); 1698 alc889_coef_init(codec);
5048} 1699}
@@ -5082,9 +1733,9 @@ static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5082 1733
5083/* set up GPIO at initialization */ 1734/* set up GPIO at initialization */
5084static void alc885_fixup_macpro_gpio(struct hda_codec *codec, 1735static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5085 const struct alc_fixup *fix, int action) 1736 const struct hda_fixup *fix, int action)
5086{ 1737{
5087 if (action != ALC_FIXUP_ACT_INIT) 1738 if (action != HDA_FIXUP_ACT_INIT)
5088 return; 1739 return;
5089 alc882_gpio_mute(codec, 0, 0); 1740 alc882_gpio_mute(codec, 0, 0);
5090 alc882_gpio_mute(codec, 1, 0); 1741 alc882_gpio_mute(codec, 1, 0);
@@ -5095,9 +1746,9 @@ static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5095 * work correctly (bko#42740) 1746 * work correctly (bko#42740)
5096 */ 1747 */
5097static void alc889_fixup_dac_route(struct hda_codec *codec, 1748static void alc889_fixup_dac_route(struct hda_codec *codec,
5098 const struct alc_fixup *fix, int action) 1749 const struct hda_fixup *fix, int action)
5099{ 1750{
5100 if (action == ALC_FIXUP_ACT_PRE_PROBE) { 1751 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
5101 /* fake the connections during parsing the tree */ 1752 /* fake the connections during parsing the tree */
5102 hda_nid_t conn1[2] = { 0x0c, 0x0d }; 1753 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5103 hda_nid_t conn2[2] = { 0x0e, 0x0f }; 1754 hda_nid_t conn2[2] = { 0x0e, 0x0f };
@@ -5105,7 +1756,7 @@ static void alc889_fixup_dac_route(struct hda_codec *codec,
5105 snd_hda_override_conn_list(codec, 0x15, 2, conn1); 1756 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5106 snd_hda_override_conn_list(codec, 0x18, 2, conn2); 1757 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5107 snd_hda_override_conn_list(codec, 0x1a, 2, conn2); 1758 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
5108 } else if (action == ALC_FIXUP_ACT_PROBE) { 1759 } else if (action == HDA_FIXUP_ACT_PROBE) {
5109 /* restore the connections */ 1760 /* restore the connections */
5110 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 }; 1761 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5111 snd_hda_override_conn_list(codec, 0x14, 5, conn); 1762 snd_hda_override_conn_list(codec, 0x14, 5, conn);
@@ -5117,62 +1768,61 @@ static void alc889_fixup_dac_route(struct hda_codec *codec,
5117 1768
5118/* Set VREF on HP pin */ 1769/* Set VREF on HP pin */
5119static void alc889_fixup_mbp_vref(struct hda_codec *codec, 1770static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5120 const struct alc_fixup *fix, int action) 1771 const struct hda_fixup *fix, int action)
5121{ 1772{
5122 struct alc_spec *spec = codec->spec; 1773 struct alc_spec *spec = codec->spec;
5123 static hda_nid_t nids[2] = { 0x14, 0x15 }; 1774 static hda_nid_t nids[2] = { 0x14, 0x15 };
5124 int i; 1775 int i;
5125 1776
5126 if (action != ALC_FIXUP_ACT_INIT) 1777 if (action != HDA_FIXUP_ACT_INIT)
5127 return; 1778 return;
5128 for (i = 0; i < ARRAY_SIZE(nids); i++) { 1779 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5129 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]); 1780 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5130 if (get_defcfg_device(val) != AC_JACK_HP_OUT) 1781 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5131 continue; 1782 continue;
5132 val = snd_hda_codec_read(codec, nids[i], 0, 1783 val = snd_hda_codec_get_pin_target(codec, nids[i]);
5133 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5134 val |= AC_PINCTL_VREF_80; 1784 val |= AC_PINCTL_VREF_80;
5135 snd_hda_set_pin_ctl(codec, nids[i], val); 1785 snd_hda_set_pin_ctl(codec, nids[i], val);
5136 spec->keep_vref_in_automute = 1; 1786 spec->gen.keep_vref_in_automute = 1;
5137 break; 1787 break;
5138 } 1788 }
5139} 1789}
5140 1790
5141/* Set VREF on speaker pins on imac91 */ 1791/* Set VREF on speaker pins on imac91 */
5142static void alc889_fixup_imac91_vref(struct hda_codec *codec, 1792static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5143 const struct alc_fixup *fix, int action) 1793 const struct hda_fixup *fix, int action)
5144{ 1794{
5145 struct alc_spec *spec = codec->spec; 1795 struct alc_spec *spec = codec->spec;
5146 static hda_nid_t nids[2] = { 0x18, 0x1a }; 1796 static hda_nid_t nids[2] = { 0x18, 0x1a };
5147 int i; 1797 int i;
5148 1798
5149 if (action != ALC_FIXUP_ACT_INIT) 1799 if (action != HDA_FIXUP_ACT_INIT)
5150 return; 1800 return;
5151 for (i = 0; i < ARRAY_SIZE(nids); i++) { 1801 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5152 unsigned int val; 1802 unsigned int val;
5153 val = snd_hda_codec_read(codec, nids[i], 0, 1803 val = snd_hda_codec_get_pin_target(codec, nids[i]);
5154 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5155 val |= AC_PINCTL_VREF_50; 1804 val |= AC_PINCTL_VREF_50;
5156 snd_hda_set_pin_ctl(codec, nids[i], val); 1805 snd_hda_set_pin_ctl(codec, nids[i], val);
5157 } 1806 }
5158 spec->keep_vref_in_automute = 1; 1807 spec->gen.keep_vref_in_automute = 1;
5159} 1808}
5160 1809
5161/* Don't take HP output as primary 1810/* Don't take HP output as primary
5162 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05 1811 * Strangely, the speaker output doesn't work on Vaio Z and some Vaio
1812 * all-in-one desktop PCs (for example VGC-LN51JGB) through DAC 0x05
5163 */ 1813 */
5164static void alc882_fixup_no_primary_hp(struct hda_codec *codec, 1814static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5165 const struct alc_fixup *fix, int action) 1815 const struct hda_fixup *fix, int action)
5166{ 1816{
5167 struct alc_spec *spec = codec->spec; 1817 struct alc_spec *spec = codec->spec;
5168 if (action == ALC_FIXUP_ACT_PRE_PROBE) 1818 if (action == HDA_FIXUP_ACT_PRE_PROBE)
5169 spec->no_primary_hp = 1; 1819 spec->gen.no_primary_hp = 1;
5170} 1820}
5171 1821
5172static const struct alc_fixup alc882_fixups[] = { 1822static const struct hda_fixup alc882_fixups[] = {
5173 [ALC882_FIXUP_ABIT_AW9D_MAX] = { 1823 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
5174 .type = ALC_FIXUP_PINS, 1824 .type = HDA_FIXUP_PINS,
5175 .v.pins = (const struct alc_pincfg[]) { 1825 .v.pins = (const struct hda_pintbl[]) {
5176 { 0x15, 0x01080104 }, /* side */ 1826 { 0x15, 0x01080104 }, /* side */
5177 { 0x16, 0x01011012 }, /* rear */ 1827 { 0x16, 0x01011012 }, /* rear */
5178 { 0x17, 0x01016011 }, /* clfe */ 1828 { 0x17, 0x01016011 }, /* clfe */
@@ -5180,47 +1830,47 @@ static const struct alc_fixup alc882_fixups[] = {
5180 } 1830 }
5181 }, 1831 },
5182 [ALC882_FIXUP_LENOVO_Y530] = { 1832 [ALC882_FIXUP_LENOVO_Y530] = {
5183 .type = ALC_FIXUP_PINS, 1833 .type = HDA_FIXUP_PINS,
5184 .v.pins = (const struct alc_pincfg[]) { 1834 .v.pins = (const struct hda_pintbl[]) {
5185 { 0x15, 0x99130112 }, /* rear int speakers */ 1835 { 0x15, 0x99130112 }, /* rear int speakers */
5186 { 0x16, 0x99130111 }, /* subwoofer */ 1836 { 0x16, 0x99130111 }, /* subwoofer */
5187 { } 1837 { }
5188 } 1838 }
5189 }, 1839 },
5190 [ALC882_FIXUP_PB_M5210] = { 1840 [ALC882_FIXUP_PB_M5210] = {
5191 .type = ALC_FIXUP_VERBS, 1841 .type = HDA_FIXUP_PINCTLS,
5192 .v.verbs = (const struct hda_verb[]) { 1842 .v.pins = (const struct hda_pintbl[]) {
5193 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, 1843 { 0x19, PIN_VREF50 },
5194 {} 1844 {}
5195 } 1845 }
5196 }, 1846 },
5197 [ALC882_FIXUP_ACER_ASPIRE_7736] = { 1847 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
5198 .type = ALC_FIXUP_FUNC, 1848 .type = HDA_FIXUP_FUNC,
5199 .v.func = alc_fixup_sku_ignore, 1849 .v.func = alc_fixup_sku_ignore,
5200 }, 1850 },
5201 [ALC882_FIXUP_ASUS_W90V] = { 1851 [ALC882_FIXUP_ASUS_W90V] = {
5202 .type = ALC_FIXUP_PINS, 1852 .type = HDA_FIXUP_PINS,
5203 .v.pins = (const struct alc_pincfg[]) { 1853 .v.pins = (const struct hda_pintbl[]) {
5204 { 0x16, 0x99130110 }, /* fix sequence for CLFE */ 1854 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5205 { } 1855 { }
5206 } 1856 }
5207 }, 1857 },
5208 [ALC889_FIXUP_CD] = { 1858 [ALC889_FIXUP_CD] = {
5209 .type = ALC_FIXUP_PINS, 1859 .type = HDA_FIXUP_PINS,
5210 .v.pins = (const struct alc_pincfg[]) { 1860 .v.pins = (const struct hda_pintbl[]) {
5211 { 0x1c, 0x993301f0 }, /* CD */ 1861 { 0x1c, 0x993301f0 }, /* CD */
5212 { } 1862 { }
5213 } 1863 }
5214 }, 1864 },
5215 [ALC889_FIXUP_VAIO_TT] = { 1865 [ALC889_FIXUP_VAIO_TT] = {
5216 .type = ALC_FIXUP_PINS, 1866 .type = HDA_FIXUP_PINS,
5217 .v.pins = (const struct alc_pincfg[]) { 1867 .v.pins = (const struct hda_pintbl[]) {
5218 { 0x17, 0x90170111 }, /* hidden surround speaker */ 1868 { 0x17, 0x90170111 }, /* hidden surround speaker */
5219 { } 1869 { }
5220 } 1870 }
5221 }, 1871 },
5222 [ALC888_FIXUP_EEE1601] = { 1872 [ALC888_FIXUP_EEE1601] = {
5223 .type = ALC_FIXUP_VERBS, 1873 .type = HDA_FIXUP_VERBS,
5224 .v.verbs = (const struct hda_verb[]) { 1874 .v.verbs = (const struct hda_verb[]) {
5225 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b }, 1875 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5226 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 }, 1876 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
@@ -5228,7 +1878,7 @@ static const struct alc_fixup alc882_fixups[] = {
5228 } 1878 }
5229 }, 1879 },
5230 [ALC882_FIXUP_EAPD] = { 1880 [ALC882_FIXUP_EAPD] = {
5231 .type = ALC_FIXUP_VERBS, 1881 .type = HDA_FIXUP_VERBS,
5232 .v.verbs = (const struct hda_verb[]) { 1882 .v.verbs = (const struct hda_verb[]) {
5233 /* change to EAPD mode */ 1883 /* change to EAPD mode */
5234 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1884 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
@@ -5237,7 +1887,7 @@ static const struct alc_fixup alc882_fixups[] = {
5237 } 1887 }
5238 }, 1888 },
5239 [ALC883_FIXUP_EAPD] = { 1889 [ALC883_FIXUP_EAPD] = {
5240 .type = ALC_FIXUP_VERBS, 1890 .type = HDA_FIXUP_VERBS,
5241 .v.verbs = (const struct hda_verb[]) { 1891 .v.verbs = (const struct hda_verb[]) {
5242 /* change to EAPD mode */ 1892 /* change to EAPD mode */
5243 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1893 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
@@ -5246,7 +1896,7 @@ static const struct alc_fixup alc882_fixups[] = {
5246 } 1896 }
5247 }, 1897 },
5248 [ALC883_FIXUP_ACER_EAPD] = { 1898 [ALC883_FIXUP_ACER_EAPD] = {
5249 .type = ALC_FIXUP_VERBS, 1899 .type = HDA_FIXUP_VERBS,
5250 .v.verbs = (const struct hda_verb[]) { 1900 .v.verbs = (const struct hda_verb[]) {
5251 /* eanable EAPD on Acer laptops */ 1901 /* eanable EAPD on Acer laptops */
5252 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1902 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
@@ -5255,30 +1905,30 @@ static const struct alc_fixup alc882_fixups[] = {
5255 } 1905 }
5256 }, 1906 },
5257 [ALC882_FIXUP_GPIO1] = { 1907 [ALC882_FIXUP_GPIO1] = {
5258 .type = ALC_FIXUP_VERBS, 1908 .type = HDA_FIXUP_VERBS,
5259 .v.verbs = alc_gpio1_init_verbs, 1909 .v.verbs = alc_gpio1_init_verbs,
5260 }, 1910 },
5261 [ALC882_FIXUP_GPIO2] = { 1911 [ALC882_FIXUP_GPIO2] = {
5262 .type = ALC_FIXUP_VERBS, 1912 .type = HDA_FIXUP_VERBS,
5263 .v.verbs = alc_gpio2_init_verbs, 1913 .v.verbs = alc_gpio2_init_verbs,
5264 }, 1914 },
5265 [ALC882_FIXUP_GPIO3] = { 1915 [ALC882_FIXUP_GPIO3] = {
5266 .type = ALC_FIXUP_VERBS, 1916 .type = HDA_FIXUP_VERBS,
5267 .v.verbs = alc_gpio3_init_verbs, 1917 .v.verbs = alc_gpio3_init_verbs,
5268 }, 1918 },
5269 [ALC882_FIXUP_ASUS_W2JC] = { 1919 [ALC882_FIXUP_ASUS_W2JC] = {
5270 .type = ALC_FIXUP_VERBS, 1920 .type = HDA_FIXUP_VERBS,
5271 .v.verbs = alc_gpio1_init_verbs, 1921 .v.verbs = alc_gpio1_init_verbs,
5272 .chained = true, 1922 .chained = true,
5273 .chain_id = ALC882_FIXUP_EAPD, 1923 .chain_id = ALC882_FIXUP_EAPD,
5274 }, 1924 },
5275 [ALC889_FIXUP_COEF] = { 1925 [ALC889_FIXUP_COEF] = {
5276 .type = ALC_FIXUP_FUNC, 1926 .type = HDA_FIXUP_FUNC,
5277 .v.func = alc889_fixup_coef, 1927 .v.func = alc889_fixup_coef,
5278 }, 1928 },
5279 [ALC882_FIXUP_ACER_ASPIRE_4930G] = { 1929 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5280 .type = ALC_FIXUP_PINS, 1930 .type = HDA_FIXUP_PINS,
5281 .v.pins = (const struct alc_pincfg[]) { 1931 .v.pins = (const struct hda_pintbl[]) {
5282 { 0x16, 0x99130111 }, /* CLFE speaker */ 1932 { 0x16, 0x99130111 }, /* CLFE speaker */
5283 { 0x17, 0x99130112 }, /* surround speaker */ 1933 { 0x17, 0x99130112 }, /* surround speaker */
5284 { } 1934 { }
@@ -5287,8 +1937,8 @@ static const struct alc_fixup alc882_fixups[] = {
5287 .chain_id = ALC882_FIXUP_GPIO1, 1937 .chain_id = ALC882_FIXUP_GPIO1,
5288 }, 1938 },
5289 [ALC882_FIXUP_ACER_ASPIRE_8930G] = { 1939 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5290 .type = ALC_FIXUP_PINS, 1940 .type = HDA_FIXUP_PINS,
5291 .v.pins = (const struct alc_pincfg[]) { 1941 .v.pins = (const struct hda_pintbl[]) {
5292 { 0x16, 0x99130111 }, /* CLFE speaker */ 1942 { 0x16, 0x99130111 }, /* CLFE speaker */
5293 { 0x1b, 0x99130112 }, /* surround speaker */ 1943 { 0x1b, 0x99130112 }, /* surround speaker */
5294 { } 1944 { }
@@ -5298,7 +1948,7 @@ static const struct alc_fixup alc882_fixups[] = {
5298 }, 1948 },
5299 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = { 1949 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5300 /* additional init verbs for Acer Aspire 8930G */ 1950 /* additional init verbs for Acer Aspire 8930G */
5301 .type = ALC_FIXUP_VERBS, 1951 .type = HDA_FIXUP_VERBS,
5302 .v.verbs = (const struct hda_verb[]) { 1952 .v.verbs = (const struct hda_verb[]) {
5303 /* Enable all DACs */ 1953 /* Enable all DACs */
5304 /* DAC DISABLE/MUTE 1? */ 1954 /* DAC DISABLE/MUTE 1? */
@@ -5332,31 +1982,31 @@ static const struct alc_fixup alc882_fixups[] = {
5332 .chain_id = ALC882_FIXUP_GPIO1, 1982 .chain_id = ALC882_FIXUP_GPIO1,
5333 }, 1983 },
5334 [ALC885_FIXUP_MACPRO_GPIO] = { 1984 [ALC885_FIXUP_MACPRO_GPIO] = {
5335 .type = ALC_FIXUP_FUNC, 1985 .type = HDA_FIXUP_FUNC,
5336 .v.func = alc885_fixup_macpro_gpio, 1986 .v.func = alc885_fixup_macpro_gpio,
5337 }, 1987 },
5338 [ALC889_FIXUP_DAC_ROUTE] = { 1988 [ALC889_FIXUP_DAC_ROUTE] = {
5339 .type = ALC_FIXUP_FUNC, 1989 .type = HDA_FIXUP_FUNC,
5340 .v.func = alc889_fixup_dac_route, 1990 .v.func = alc889_fixup_dac_route,
5341 }, 1991 },
5342 [ALC889_FIXUP_MBP_VREF] = { 1992 [ALC889_FIXUP_MBP_VREF] = {
5343 .type = ALC_FIXUP_FUNC, 1993 .type = HDA_FIXUP_FUNC,
5344 .v.func = alc889_fixup_mbp_vref, 1994 .v.func = alc889_fixup_mbp_vref,
5345 .chained = true, 1995 .chained = true,
5346 .chain_id = ALC882_FIXUP_GPIO1, 1996 .chain_id = ALC882_FIXUP_GPIO1,
5347 }, 1997 },
5348 [ALC889_FIXUP_IMAC91_VREF] = { 1998 [ALC889_FIXUP_IMAC91_VREF] = {
5349 .type = ALC_FIXUP_FUNC, 1999 .type = HDA_FIXUP_FUNC,
5350 .v.func = alc889_fixup_imac91_vref, 2000 .v.func = alc889_fixup_imac91_vref,
5351 .chained = true, 2001 .chained = true,
5352 .chain_id = ALC882_FIXUP_GPIO1, 2002 .chain_id = ALC882_FIXUP_GPIO1,
5353 }, 2003 },
5354 [ALC882_FIXUP_INV_DMIC] = { 2004 [ALC882_FIXUP_INV_DMIC] = {
5355 .type = ALC_FIXUP_FUNC, 2005 .type = HDA_FIXUP_FUNC,
5356 .v.func = alc_fixup_inv_dmic_0x12, 2006 .v.func = alc_fixup_inv_dmic_0x12,
5357 }, 2007 },
5358 [ALC882_FIXUP_NO_PRIMARY_HP] = { 2008 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5359 .type = ALC_FIXUP_FUNC, 2009 .type = HDA_FIXUP_FUNC,
5360 .v.func = alc882_fixup_no_primary_hp, 2010 .v.func = alc882_fixup_no_primary_hp,
5361 }, 2011 },
5362}; 2012};
@@ -5394,6 +2044,7 @@ static const struct snd_pci_quirk alc882_fixup_tbl[] = {
5394 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601), 2044 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
5395 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT), 2045 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
5396 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP), 2046 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
2047 SND_PCI_QUIRK(0x104d, 0x9043, "Sony Vaio VGC-LN51JGB", ALC882_FIXUP_NO_PRIMARY_HP),
5397 2048
5398 /* All Apple entries are in codec SSIDs */ 2049 /* All Apple entries are in codec SSIDs */
5399 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF), 2050 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
@@ -5431,7 +2082,7 @@ static const struct snd_pci_quirk alc882_fixup_tbl[] = {
5431 {} 2082 {}
5432}; 2083};
5433 2084
5434static const struct alc_model_fixup alc882_fixup_models[] = { 2085static const struct hda_model_fixup alc882_fixup_models[] = {
5435 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"}, 2086 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5436 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"}, 2087 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5437 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"}, 2088 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
@@ -5474,9 +2125,9 @@ static int patch_alc882(struct hda_codec *codec)
5474 break; 2125 break;
5475 } 2126 }
5476 2127
5477 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl, 2128 snd_hda_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5478 alc882_fixups); 2129 alc882_fixups);
5479 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 2130 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5480 2131
5481 alc_auto_parse_customize_define(codec); 2132 alc_auto_parse_customize_define(codec);
5482 2133
@@ -5485,7 +2136,7 @@ static int patch_alc882(struct hda_codec *codec)
5485 if (err < 0) 2136 if (err < 0)
5486 goto error; 2137 goto error;
5487 2138
5488 if (!spec->no_analog && has_cdefine_beep(codec)) { 2139 if (!spec->gen.no_analog && has_cdefine_beep(codec)) {
5489 err = snd_hda_attach_beep_device(codec, 0x1); 2140 err = snd_hda_attach_beep_device(codec, 0x1);
5490 if (err < 0) 2141 if (err < 0)
5491 goto error; 2142 goto error;
@@ -5494,7 +2145,7 @@ static int patch_alc882(struct hda_codec *codec)
5494 2145
5495 codec->patch_ops = alc_patch_ops; 2146 codec->patch_ops = alc_patch_ops;
5496 2147
5497 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 2148 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5498 2149
5499 return 0; 2150 return 0;
5500 2151
@@ -5519,6 +2170,7 @@ static int alc262_parse_auto_config(struct hda_codec *codec)
5519 */ 2170 */
5520enum { 2171enum {
5521 ALC262_FIXUP_FSC_H270, 2172 ALC262_FIXUP_FSC_H270,
2173 ALC262_FIXUP_FSC_S7110,
5522 ALC262_FIXUP_HP_Z200, 2174 ALC262_FIXUP_HP_Z200,
5523 ALC262_FIXUP_TYAN, 2175 ALC262_FIXUP_TYAN,
5524 ALC262_FIXUP_LENOVO_3000, 2176 ALC262_FIXUP_LENOVO_3000,
@@ -5527,41 +2179,50 @@ enum {
5527 ALC262_FIXUP_INV_DMIC, 2179 ALC262_FIXUP_INV_DMIC,
5528}; 2180};
5529 2181
5530static const struct alc_fixup alc262_fixups[] = { 2182static const struct hda_fixup alc262_fixups[] = {
5531 [ALC262_FIXUP_FSC_H270] = { 2183 [ALC262_FIXUP_FSC_H270] = {
5532 .type = ALC_FIXUP_PINS, 2184 .type = HDA_FIXUP_PINS,
5533 .v.pins = (const struct alc_pincfg[]) { 2185 .v.pins = (const struct hda_pintbl[]) {
5534 { 0x14, 0x99130110 }, /* speaker */ 2186 { 0x14, 0x99130110 }, /* speaker */
5535 { 0x15, 0x0221142f }, /* front HP */ 2187 { 0x15, 0x0221142f }, /* front HP */
5536 { 0x1b, 0x0121141f }, /* rear HP */ 2188 { 0x1b, 0x0121141f }, /* rear HP */
5537 { } 2189 { }
5538 } 2190 }
5539 }, 2191 },
2192 [ALC262_FIXUP_FSC_S7110] = {
2193 .type = HDA_FIXUP_PINS,
2194 .v.pins = (const struct hda_pintbl[]) {
2195 { 0x15, 0x90170110 }, /* speaker */
2196 { }
2197 },
2198 .chained = true,
2199 .chain_id = ALC262_FIXUP_BENQ,
2200 },
5540 [ALC262_FIXUP_HP_Z200] = { 2201 [ALC262_FIXUP_HP_Z200] = {
5541 .type = ALC_FIXUP_PINS, 2202 .type = HDA_FIXUP_PINS,
5542 .v.pins = (const struct alc_pincfg[]) { 2203 .v.pins = (const struct hda_pintbl[]) {
5543 { 0x16, 0x99130120 }, /* internal speaker */ 2204 { 0x16, 0x99130120 }, /* internal speaker */
5544 { } 2205 { }
5545 } 2206 }
5546 }, 2207 },
5547 [ALC262_FIXUP_TYAN] = { 2208 [ALC262_FIXUP_TYAN] = {
5548 .type = ALC_FIXUP_PINS, 2209 .type = HDA_FIXUP_PINS,
5549 .v.pins = (const struct alc_pincfg[]) { 2210 .v.pins = (const struct hda_pintbl[]) {
5550 { 0x14, 0x1993e1f0 }, /* int AUX */ 2211 { 0x14, 0x1993e1f0 }, /* int AUX */
5551 { } 2212 { }
5552 } 2213 }
5553 }, 2214 },
5554 [ALC262_FIXUP_LENOVO_3000] = { 2215 [ALC262_FIXUP_LENOVO_3000] = {
5555 .type = ALC_FIXUP_VERBS, 2216 .type = HDA_FIXUP_PINCTLS,
5556 .v.verbs = (const struct hda_verb[]) { 2217 .v.pins = (const struct hda_pintbl[]) {
5557 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, 2218 { 0x19, PIN_VREF50 },
5558 {} 2219 {}
5559 }, 2220 },
5560 .chained = true, 2221 .chained = true,
5561 .chain_id = ALC262_FIXUP_BENQ, 2222 .chain_id = ALC262_FIXUP_BENQ,
5562 }, 2223 },
5563 [ALC262_FIXUP_BENQ] = { 2224 [ALC262_FIXUP_BENQ] = {
5564 .type = ALC_FIXUP_VERBS, 2225 .type = HDA_FIXUP_VERBS,
5565 .v.verbs = (const struct hda_verb[]) { 2226 .v.verbs = (const struct hda_verb[]) {
5566 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 2227 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5567 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 }, 2228 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
@@ -5569,7 +2230,7 @@ static const struct alc_fixup alc262_fixups[] = {
5569 } 2230 }
5570 }, 2231 },
5571 [ALC262_FIXUP_BENQ_T31] = { 2232 [ALC262_FIXUP_BENQ_T31] = {
5572 .type = ALC_FIXUP_VERBS, 2233 .type = HDA_FIXUP_VERBS,
5573 .v.verbs = (const struct hda_verb[]) { 2234 .v.verbs = (const struct hda_verb[]) {
5574 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 2235 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5575 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, 2236 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
@@ -5577,14 +2238,14 @@ static const struct alc_fixup alc262_fixups[] = {
5577 } 2238 }
5578 }, 2239 },
5579 [ALC262_FIXUP_INV_DMIC] = { 2240 [ALC262_FIXUP_INV_DMIC] = {
5580 .type = ALC_FIXUP_FUNC, 2241 .type = HDA_FIXUP_FUNC,
5581 .v.func = alc_fixup_inv_dmic_0x12, 2242 .v.func = alc_fixup_inv_dmic_0x12,
5582 }, 2243 },
5583}; 2244};
5584 2245
5585static const struct snd_pci_quirk alc262_fixup_tbl[] = { 2246static const struct snd_pci_quirk alc262_fixup_tbl[] = {
5586 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200), 2247 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
5587 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ), 2248 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu Lifebook S7110", ALC262_FIXUP_FSC_S7110),
5588 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ), 2249 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
5589 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN), 2250 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5590 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270), 2251 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
@@ -5594,7 +2255,7 @@ static const struct snd_pci_quirk alc262_fixup_tbl[] = {
5594 {} 2255 {}
5595}; 2256};
5596 2257
5597static const struct alc_model_fixup alc262_fixup_models[] = { 2258static const struct hda_model_fixup alc262_fixup_models[] = {
5598 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"}, 2259 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5599 {} 2260 {}
5600}; 2261};
@@ -5611,6 +2272,7 @@ static int patch_alc262(struct hda_codec *codec)
5611 return err; 2272 return err;
5612 2273
5613 spec = codec->spec; 2274 spec = codec->spec;
2275 spec->gen.shared_mic_vref_pin = 0x18;
5614 2276
5615#if 0 2277#if 0
5616 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is 2278 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
@@ -5626,9 +2288,9 @@ static int patch_alc262(struct hda_codec *codec)
5626#endif 2288#endif
5627 alc_fix_pll_init(codec, 0x20, 0x0a, 10); 2289 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5628 2290
5629 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl, 2291 snd_hda_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5630 alc262_fixups); 2292 alc262_fixups);
5631 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 2293 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5632 2294
5633 alc_auto_parse_customize_define(codec); 2295 alc_auto_parse_customize_define(codec);
5634 2296
@@ -5637,7 +2299,7 @@ static int patch_alc262(struct hda_codec *codec)
5637 if (err < 0) 2299 if (err < 0)
5638 goto error; 2300 goto error;
5639 2301
5640 if (!spec->no_analog && has_cdefine_beep(codec)) { 2302 if (!spec->gen.no_analog && has_cdefine_beep(codec)) {
5641 err = snd_hda_attach_beep_device(codec, 0x1); 2303 err = snd_hda_attach_beep_device(codec, 0x1);
5642 if (err < 0) 2304 if (err < 0)
5643 goto error; 2305 goto error;
@@ -5647,7 +2309,7 @@ static int patch_alc262(struct hda_codec *codec)
5647 codec->patch_ops = alc_patch_ops; 2309 codec->patch_ops = alc_patch_ops;
5648 spec->shutup = alc_eapd_shutup; 2310 spec->shutup = alc_eapd_shutup;
5649 2311
5650 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 2312 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5651 2313
5652 return 0; 2314 return 0;
5653 2315
@@ -5688,13 +2350,13 @@ enum {
5688 ALC268_FIXUP_HP_EAPD, 2350 ALC268_FIXUP_HP_EAPD,
5689}; 2351};
5690 2352
5691static const struct alc_fixup alc268_fixups[] = { 2353static const struct hda_fixup alc268_fixups[] = {
5692 [ALC268_FIXUP_INV_DMIC] = { 2354 [ALC268_FIXUP_INV_DMIC] = {
5693 .type = ALC_FIXUP_FUNC, 2355 .type = HDA_FIXUP_FUNC,
5694 .v.func = alc_fixup_inv_dmic_0x12, 2356 .v.func = alc_fixup_inv_dmic_0x12,
5695 }, 2357 },
5696 [ALC268_FIXUP_HP_EAPD] = { 2358 [ALC268_FIXUP_HP_EAPD] = {
5697 .type = ALC_FIXUP_VERBS, 2359 .type = HDA_FIXUP_VERBS,
5698 .v.verbs = (const struct hda_verb[]) { 2360 .v.verbs = (const struct hda_verb[]) {
5699 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0}, 2361 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5700 {} 2362 {}
@@ -5702,7 +2364,7 @@ static const struct alc_fixup alc268_fixups[] = {
5702 }, 2364 },
5703}; 2365};
5704 2366
5705static const struct alc_model_fixup alc268_fixup_models[] = { 2367static const struct hda_model_fixup alc268_fixup_models[] = {
5706 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"}, 2368 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
5707 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"}, 2369 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5708 {} 2370 {}
@@ -5726,9 +2388,10 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
5726 struct alc_spec *spec = codec->spec; 2388 struct alc_spec *spec = codec->spec;
5727 int err = alc_parse_auto_config(codec, NULL, alc268_ssids); 2389 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5728 if (err > 0) { 2390 if (err > 0) {
5729 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) { 2391 if (!spec->gen.no_analog &&
2392 spec->gen.autocfg.speaker_pins[0] != 0x1d) {
5730 add_mixer(spec, alc268_beep_mixer); 2393 add_mixer(spec, alc268_beep_mixer);
5731 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs); 2394 snd_hda_add_verbs(codec, alc268_beep_init_verbs);
5732 } 2395 }
5733 } 2396 }
5734 return err; 2397 return err;
@@ -5748,8 +2411,8 @@ static int patch_alc268(struct hda_codec *codec)
5748 2411
5749 spec = codec->spec; 2412 spec = codec->spec;
5750 2413
5751 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups); 2414 snd_hda_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
5752 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 2415 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5753 2416
5754 /* automatic parse from the BIOS config */ 2417 /* automatic parse from the BIOS config */
5755 err = alc268_parse_auto_config(codec); 2418 err = alc268_parse_auto_config(codec);
@@ -5780,7 +2443,7 @@ static int patch_alc268(struct hda_codec *codec)
5780 codec->patch_ops = alc_patch_ops; 2443 codec->patch_ops = alc_patch_ops;
5781 spec->shutup = alc_eapd_shutup; 2444 spec->shutup = alc_eapd_shutup;
5782 2445
5783 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 2446 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5784 2447
5785 return 0; 2448 return 0;
5786 2449
@@ -5792,6 +2455,35 @@ static int patch_alc268(struct hda_codec *codec)
5792/* 2455/*
5793 * ALC269 2456 * ALC269
5794 */ 2457 */
2458
2459static int playback_pcm_open(struct hda_pcm_stream *hinfo,
2460 struct hda_codec *codec,
2461 struct snd_pcm_substream *substream)
2462{
2463 struct hda_gen_spec *spec = codec->spec;
2464 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2465 hinfo);
2466}
2467
2468static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2469 struct hda_codec *codec,
2470 unsigned int stream_tag,
2471 unsigned int format,
2472 struct snd_pcm_substream *substream)
2473{
2474 struct hda_gen_spec *spec = codec->spec;
2475 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2476 stream_tag, format, substream);
2477}
2478
2479static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2480 struct hda_codec *codec,
2481 struct snd_pcm_substream *substream)
2482{
2483 struct hda_gen_spec *spec = codec->spec;
2484 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2485}
2486
5795static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { 2487static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5796 .substreams = 1, 2488 .substreams = 1,
5797 .channels_min = 2, 2489 .channels_min = 2,
@@ -5799,9 +2491,9 @@ static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5799 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ 2491 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5800 /* NID is set in alc_build_pcms */ 2492 /* NID is set in alc_build_pcms */
5801 .ops = { 2493 .ops = {
5802 .open = alc_playback_pcm_open, 2494 .open = playback_pcm_open,
5803 .prepare = alc_playback_pcm_prepare, 2495 .prepare = playback_pcm_prepare,
5804 .cleanup = alc_playback_pcm_cleanup 2496 .cleanup = playback_pcm_cleanup
5805 }, 2497 },
5806}; 2498};
5807 2499
@@ -5909,27 +2601,27 @@ static int alc269_resume(struct hda_codec *codec)
5909#endif /* CONFIG_PM */ 2601#endif /* CONFIG_PM */
5910 2602
5911static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec, 2603static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
5912 const struct alc_fixup *fix, int action) 2604 const struct hda_fixup *fix, int action)
5913{ 2605{
5914 struct alc_spec *spec = codec->spec; 2606 struct alc_spec *spec = codec->spec;
5915 2607
5916 if (action == ALC_FIXUP_ACT_PRE_PROBE) 2608 if (action == HDA_FIXUP_ACT_PRE_PROBE)
5917 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; 2609 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5918} 2610}
5919 2611
5920static void alc269_fixup_hweq(struct hda_codec *codec, 2612static void alc269_fixup_hweq(struct hda_codec *codec,
5921 const struct alc_fixup *fix, int action) 2613 const struct hda_fixup *fix, int action)
5922{ 2614{
5923 int coef; 2615 int coef;
5924 2616
5925 if (action != ALC_FIXUP_ACT_INIT) 2617 if (action != HDA_FIXUP_ACT_INIT)
5926 return; 2618 return;
5927 coef = alc_read_coef_idx(codec, 0x1e); 2619 coef = alc_read_coef_idx(codec, 0x1e);
5928 alc_write_coef_idx(codec, 0x1e, coef | 0x80); 2620 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5929} 2621}
5930 2622
5931static void alc271_fixup_dmic(struct hda_codec *codec, 2623static void alc271_fixup_dmic(struct hda_codec *codec,
5932 const struct alc_fixup *fix, int action) 2624 const struct hda_fixup *fix, int action)
5933{ 2625{
5934 static const struct hda_verb verbs[] = { 2626 static const struct hda_verb verbs[] = {
5935 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d}, 2627 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
@@ -5946,26 +2638,26 @@ static void alc271_fixup_dmic(struct hda_codec *codec,
5946} 2638}
5947 2639
5948static void alc269_fixup_pcm_44k(struct hda_codec *codec, 2640static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5949 const struct alc_fixup *fix, int action) 2641 const struct hda_fixup *fix, int action)
5950{ 2642{
5951 struct alc_spec *spec = codec->spec; 2643 struct alc_spec *spec = codec->spec;
5952 2644
5953 if (action != ALC_FIXUP_ACT_PROBE) 2645 if (action != HDA_FIXUP_ACT_PROBE)
5954 return; 2646 return;
5955 2647
5956 /* Due to a hardware problem on Lenovo Ideadpad, we need to 2648 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5957 * fix the sample rate of analog I/O to 44.1kHz 2649 * fix the sample rate of analog I/O to 44.1kHz
5958 */ 2650 */
5959 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback; 2651 spec->gen.stream_analog_playback = &alc269_44k_pcm_analog_playback;
5960 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture; 2652 spec->gen.stream_analog_capture = &alc269_44k_pcm_analog_capture;
5961} 2653}
5962 2654
5963static void alc269_fixup_stereo_dmic(struct hda_codec *codec, 2655static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5964 const struct alc_fixup *fix, int action) 2656 const struct hda_fixup *fix, int action)
5965{ 2657{
5966 int coef; 2658 int coef;
5967 2659
5968 if (action != ALC_FIXUP_ACT_INIT) 2660 if (action != HDA_FIXUP_ACT_INIT)
5969 return; 2661 return;
5970 /* The digital-mic unit sends PDM (differential signal) instead of 2662 /* The digital-mic unit sends PDM (differential signal) instead of
5971 * the standard PCM, thus you can't record a valid mono stream as is. 2663 * the standard PCM, thus you can't record a valid mono stream as is.
@@ -5978,7 +2670,7 @@ static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5978 2670
5979static void alc269_quanta_automute(struct hda_codec *codec) 2671static void alc269_quanta_automute(struct hda_codec *codec)
5980{ 2672{
5981 update_outputs(codec); 2673 snd_hda_gen_update_outputs(codec);
5982 2674
5983 snd_hda_codec_write(codec, 0x20, 0, 2675 snd_hda_codec_write(codec, 0x20, 0,
5984 AC_VERB_SET_COEF_INDEX, 0x0c); 2676 AC_VERB_SET_COEF_INDEX, 0x0c);
@@ -5992,70 +2684,91 @@ static void alc269_quanta_automute(struct hda_codec *codec)
5992} 2684}
5993 2685
5994static void alc269_fixup_quanta_mute(struct hda_codec *codec, 2686static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5995 const struct alc_fixup *fix, int action) 2687 const struct hda_fixup *fix, int action)
5996{ 2688{
5997 struct alc_spec *spec = codec->spec; 2689 struct alc_spec *spec = codec->spec;
5998 if (action != ALC_FIXUP_ACT_PROBE) 2690 if (action != HDA_FIXUP_ACT_PROBE)
5999 return; 2691 return;
6000 spec->automute_hook = alc269_quanta_automute; 2692 spec->gen.automute_hook = alc269_quanta_automute;
6001} 2693}
6002 2694
6003/* update mute-LED according to the speaker mute state via mic1 VREF pin */ 2695/* update mute-LED according to the speaker mute state via mic VREF pin */
6004static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled) 2696static void alc269_fixup_mic_mute_hook(void *private_data, int enabled)
6005{ 2697{
6006 struct hda_codec *codec = private_data; 2698 struct hda_codec *codec = private_data;
6007 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ? 2699 struct alc_spec *spec = codec->spec;
6008 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80); 2700 unsigned int pinval;
6009 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval); 2701
2702 if (spec->mute_led_polarity)
2703 enabled = !enabled;
2704 pinval = AC_PINCTL_IN_EN |
2705 (enabled ? AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
2706 if (spec->mute_led_nid)
2707 snd_hda_set_pin_ctl_cache(codec, spec->mute_led_nid, pinval);
6010} 2708}
6011 2709
6012static void alc269_fixup_mic1_mute(struct hda_codec *codec, 2710static void alc269_fixup_hp_mute_led(struct hda_codec *codec,
6013 const struct alc_fixup *fix, int action) 2711 const struct hda_fixup *fix, int action)
6014{ 2712{
6015 struct alc_spec *spec = codec->spec; 2713 struct alc_spec *spec = codec->spec;
6016 switch (action) { 2714 const struct dmi_device *dev = NULL;
6017 case ALC_FIXUP_ACT_BUILD: 2715
6018 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook; 2716 if (action != HDA_FIXUP_ACT_PRE_PROBE)
6019 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true); 2717 return;
6020 /* fallthru */ 2718
6021 case ALC_FIXUP_ACT_INIT: 2719 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
6022 snd_hda_sync_vmaster_hook(&spec->vmaster_mute); 2720 int pol, pin;
2721 if (sscanf(dev->name, "HP_Mute_LED_%d_%x", &pol, &pin) != 2)
2722 continue;
2723 if (pin < 0x0a || pin >= 0x10)
2724 break;
2725 spec->mute_led_polarity = pol;
2726 spec->mute_led_nid = pin - 0x0a + 0x18;
2727 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
2728 spec->gen.vmaster_mute_enum = 1;
2729 snd_printd("Detected mute LED for %x:%d\n", spec->mute_led_nid,
2730 spec->mute_led_polarity);
6023 break; 2731 break;
6024 } 2732 }
6025} 2733}
6026 2734
6027/* update mute-LED according to the speaker mute state via mic2 VREF pin */ 2735static void alc269_fixup_hp_mute_led_mic1(struct hda_codec *codec,
6028static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled) 2736 const struct hda_fixup *fix, int action)
6029{ 2737{
6030 struct hda_codec *codec = private_data; 2738 struct alc_spec *spec = codec->spec;
6031 unsigned int pinval = enabled ? 0x20 : 0x24; 2739 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
6032 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval); 2740 spec->mute_led_polarity = 0;
2741 spec->mute_led_nid = 0x18;
2742 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
2743 spec->gen.vmaster_mute_enum = 1;
2744 }
6033} 2745}
6034 2746
6035static void alc269_fixup_mic2_mute(struct hda_codec *codec, 2747static void alc269_fixup_hp_mute_led_mic2(struct hda_codec *codec,
6036 const struct alc_fixup *fix, int action) 2748 const struct hda_fixup *fix, int action)
6037{ 2749{
6038 struct alc_spec *spec = codec->spec; 2750 struct alc_spec *spec = codec->spec;
6039 switch (action) { 2751 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
6040 case ALC_FIXUP_ACT_BUILD: 2752 spec->mute_led_polarity = 0;
6041 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook; 2753 spec->mute_led_nid = 0x19;
6042 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true); 2754 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
6043 /* fallthru */ 2755 spec->gen.vmaster_mute_enum = 1;
6044 case ALC_FIXUP_ACT_INIT:
6045 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6046 break;
6047 } 2756 }
6048} 2757}
6049 2758
6050static void alc271_hp_gate_mic_jack(struct hda_codec *codec, 2759static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6051 const struct alc_fixup *fix, 2760 const struct hda_fixup *fix,
6052 int action) 2761 int action)
6053{ 2762{
6054 struct alc_spec *spec = codec->spec; 2763 struct alc_spec *spec = codec->spec;
6055 2764
6056 if (action == ALC_FIXUP_ACT_PROBE) 2765 if (action == HDA_FIXUP_ACT_PROBE) {
6057 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin, 2766 if (snd_BUG_ON(!spec->gen.am_entry[1].pin ||
6058 spec->autocfg.hp_pins[0]); 2767 !spec->gen.autocfg.hp_pins[0]))
2768 return;
2769 snd_hda_jack_set_gating_jack(codec, spec->gen.am_entry[1].pin,
2770 spec->gen.autocfg.hp_pins[0]);
2771 }
6059} 2772}
6060 2773
6061enum { 2774enum {
@@ -6075,8 +2788,9 @@ enum {
6075 ALC269_FIXUP_DMIC, 2788 ALC269_FIXUP_DMIC,
6076 ALC269VB_FIXUP_AMIC, 2789 ALC269VB_FIXUP_AMIC,
6077 ALC269VB_FIXUP_DMIC, 2790 ALC269VB_FIXUP_DMIC,
6078 ALC269_FIXUP_MIC1_MUTE_LED, 2791 ALC269_FIXUP_HP_MUTE_LED,
6079 ALC269_FIXUP_MIC2_MUTE_LED, 2792 ALC269_FIXUP_HP_MUTE_LED_MIC1,
2793 ALC269_FIXUP_HP_MUTE_LED_MIC2,
6080 ALC269_FIXUP_INV_DMIC, 2794 ALC269_FIXUP_INV_DMIC,
6081 ALC269_FIXUP_LENOVO_DOCK, 2795 ALC269_FIXUP_LENOVO_DOCK,
6082 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT, 2796 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
@@ -6084,16 +2798,16 @@ enum {
6084 ALC271_FIXUP_HP_GATE_MIC_JACK, 2798 ALC271_FIXUP_HP_GATE_MIC_JACK,
6085}; 2799};
6086 2800
6087static const struct alc_fixup alc269_fixups[] = { 2801static const struct hda_fixup alc269_fixups[] = {
6088 [ALC269_FIXUP_SONY_VAIO] = { 2802 [ALC269_FIXUP_SONY_VAIO] = {
6089 .type = ALC_FIXUP_VERBS, 2803 .type = HDA_FIXUP_PINCTLS,
6090 .v.verbs = (const struct hda_verb[]) { 2804 .v.pins = (const struct hda_pintbl[]) {
6091 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD}, 2805 {0x19, PIN_VREFGRD},
6092 {} 2806 {}
6093 } 2807 }
6094 }, 2808 },
6095 [ALC275_FIXUP_SONY_VAIO_GPIO2] = { 2809 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6096 .type = ALC_FIXUP_VERBS, 2810 .type = HDA_FIXUP_VERBS,
6097 .v.verbs = (const struct hda_verb[]) { 2811 .v.verbs = (const struct hda_verb[]) {
6098 {0x01, AC_VERB_SET_GPIO_MASK, 0x04}, 2812 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6099 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04}, 2813 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
@@ -6104,7 +2818,7 @@ static const struct alc_fixup alc269_fixups[] = {
6104 .chain_id = ALC269_FIXUP_SONY_VAIO 2818 .chain_id = ALC269_FIXUP_SONY_VAIO
6105 }, 2819 },
6106 [ALC269_FIXUP_DELL_M101Z] = { 2820 [ALC269_FIXUP_DELL_M101Z] = {
6107 .type = ALC_FIXUP_VERBS, 2821 .type = HDA_FIXUP_VERBS,
6108 .v.verbs = (const struct hda_verb[]) { 2822 .v.verbs = (const struct hda_verb[]) {
6109 /* Enables internal speaker */ 2823 /* Enables internal speaker */
6110 {0x20, AC_VERB_SET_COEF_INDEX, 13}, 2824 {0x20, AC_VERB_SET_COEF_INDEX, 13},
@@ -6113,50 +2827,50 @@ static const struct alc_fixup alc269_fixups[] = {
6113 } 2827 }
6114 }, 2828 },
6115 [ALC269_FIXUP_SKU_IGNORE] = { 2829 [ALC269_FIXUP_SKU_IGNORE] = {
6116 .type = ALC_FIXUP_FUNC, 2830 .type = HDA_FIXUP_FUNC,
6117 .v.func = alc_fixup_sku_ignore, 2831 .v.func = alc_fixup_sku_ignore,
6118 }, 2832 },
6119 [ALC269_FIXUP_ASUS_G73JW] = { 2833 [ALC269_FIXUP_ASUS_G73JW] = {
6120 .type = ALC_FIXUP_PINS, 2834 .type = HDA_FIXUP_PINS,
6121 .v.pins = (const struct alc_pincfg[]) { 2835 .v.pins = (const struct hda_pintbl[]) {
6122 { 0x17, 0x99130111 }, /* subwoofer */ 2836 { 0x17, 0x99130111 }, /* subwoofer */
6123 { } 2837 { }
6124 } 2838 }
6125 }, 2839 },
6126 [ALC269_FIXUP_LENOVO_EAPD] = { 2840 [ALC269_FIXUP_LENOVO_EAPD] = {
6127 .type = ALC_FIXUP_VERBS, 2841 .type = HDA_FIXUP_VERBS,
6128 .v.verbs = (const struct hda_verb[]) { 2842 .v.verbs = (const struct hda_verb[]) {
6129 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, 2843 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6130 {} 2844 {}
6131 } 2845 }
6132 }, 2846 },
6133 [ALC275_FIXUP_SONY_HWEQ] = { 2847 [ALC275_FIXUP_SONY_HWEQ] = {
6134 .type = ALC_FIXUP_FUNC, 2848 .type = HDA_FIXUP_FUNC,
6135 .v.func = alc269_fixup_hweq, 2849 .v.func = alc269_fixup_hweq,
6136 .chained = true, 2850 .chained = true,
6137 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2 2851 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6138 }, 2852 },
6139 [ALC271_FIXUP_DMIC] = { 2853 [ALC271_FIXUP_DMIC] = {
6140 .type = ALC_FIXUP_FUNC, 2854 .type = HDA_FIXUP_FUNC,
6141 .v.func = alc271_fixup_dmic, 2855 .v.func = alc271_fixup_dmic,
6142 }, 2856 },
6143 [ALC269_FIXUP_PCM_44K] = { 2857 [ALC269_FIXUP_PCM_44K] = {
6144 .type = ALC_FIXUP_FUNC, 2858 .type = HDA_FIXUP_FUNC,
6145 .v.func = alc269_fixup_pcm_44k, 2859 .v.func = alc269_fixup_pcm_44k,
6146 .chained = true, 2860 .chained = true,
6147 .chain_id = ALC269_FIXUP_QUANTA_MUTE 2861 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6148 }, 2862 },
6149 [ALC269_FIXUP_STEREO_DMIC] = { 2863 [ALC269_FIXUP_STEREO_DMIC] = {
6150 .type = ALC_FIXUP_FUNC, 2864 .type = HDA_FIXUP_FUNC,
6151 .v.func = alc269_fixup_stereo_dmic, 2865 .v.func = alc269_fixup_stereo_dmic,
6152 }, 2866 },
6153 [ALC269_FIXUP_QUANTA_MUTE] = { 2867 [ALC269_FIXUP_QUANTA_MUTE] = {
6154 .type = ALC_FIXUP_FUNC, 2868 .type = HDA_FIXUP_FUNC,
6155 .v.func = alc269_fixup_quanta_mute, 2869 .v.func = alc269_fixup_quanta_mute,
6156 }, 2870 },
6157 [ALC269_FIXUP_LIFEBOOK] = { 2871 [ALC269_FIXUP_LIFEBOOK] = {
6158 .type = ALC_FIXUP_PINS, 2872 .type = HDA_FIXUP_PINS,
6159 .v.pins = (const struct alc_pincfg[]) { 2873 .v.pins = (const struct hda_pintbl[]) {
6160 { 0x1a, 0x2101103f }, /* dock line-out */ 2874 { 0x1a, 0x2101103f }, /* dock line-out */
6161 { 0x1b, 0x23a11040 }, /* dock mic-in */ 2875 { 0x1b, 0x23a11040 }, /* dock mic-in */
6162 { } 2876 { }
@@ -6165,8 +2879,8 @@ static const struct alc_fixup alc269_fixups[] = {
6165 .chain_id = ALC269_FIXUP_QUANTA_MUTE 2879 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6166 }, 2880 },
6167 [ALC269_FIXUP_AMIC] = { 2881 [ALC269_FIXUP_AMIC] = {
6168 .type = ALC_FIXUP_PINS, 2882 .type = HDA_FIXUP_PINS,
6169 .v.pins = (const struct alc_pincfg[]) { 2883 .v.pins = (const struct hda_pintbl[]) {
6170 { 0x14, 0x99130110 }, /* speaker */ 2884 { 0x14, 0x99130110 }, /* speaker */
6171 { 0x15, 0x0121401f }, /* HP out */ 2885 { 0x15, 0x0121401f }, /* HP out */
6172 { 0x18, 0x01a19c20 }, /* mic */ 2886 { 0x18, 0x01a19c20 }, /* mic */
@@ -6175,8 +2889,8 @@ static const struct alc_fixup alc269_fixups[] = {
6175 }, 2889 },
6176 }, 2890 },
6177 [ALC269_FIXUP_DMIC] = { 2891 [ALC269_FIXUP_DMIC] = {
6178 .type = ALC_FIXUP_PINS, 2892 .type = HDA_FIXUP_PINS,
6179 .v.pins = (const struct alc_pincfg[]) { 2893 .v.pins = (const struct hda_pintbl[]) {
6180 { 0x12, 0x99a3092f }, /* int-mic */ 2894 { 0x12, 0x99a3092f }, /* int-mic */
6181 { 0x14, 0x99130110 }, /* speaker */ 2895 { 0x14, 0x99130110 }, /* speaker */
6182 { 0x15, 0x0121401f }, /* HP out */ 2896 { 0x15, 0x0121401f }, /* HP out */
@@ -6185,8 +2899,8 @@ static const struct alc_fixup alc269_fixups[] = {
6185 }, 2899 },
6186 }, 2900 },
6187 [ALC269VB_FIXUP_AMIC] = { 2901 [ALC269VB_FIXUP_AMIC] = {
6188 .type = ALC_FIXUP_PINS, 2902 .type = HDA_FIXUP_PINS,
6189 .v.pins = (const struct alc_pincfg[]) { 2903 .v.pins = (const struct hda_pintbl[]) {
6190 { 0x14, 0x99130110 }, /* speaker */ 2904 { 0x14, 0x99130110 }, /* speaker */
6191 { 0x18, 0x01a19c20 }, /* mic */ 2905 { 0x18, 0x01a19c20 }, /* mic */
6192 { 0x19, 0x99a3092f }, /* int-mic */ 2906 { 0x19, 0x99a3092f }, /* int-mic */
@@ -6195,8 +2909,8 @@ static const struct alc_fixup alc269_fixups[] = {
6195 }, 2909 },
6196 }, 2910 },
6197 [ALC269VB_FIXUP_DMIC] = { 2911 [ALC269VB_FIXUP_DMIC] = {
6198 .type = ALC_FIXUP_PINS, 2912 .type = HDA_FIXUP_PINS,
6199 .v.pins = (const struct alc_pincfg[]) { 2913 .v.pins = (const struct hda_pintbl[]) {
6200 { 0x12, 0x99a3092f }, /* int-mic */ 2914 { 0x12, 0x99a3092f }, /* int-mic */
6201 { 0x14, 0x99130110 }, /* speaker */ 2915 { 0x14, 0x99130110 }, /* speaker */
6202 { 0x18, 0x01a19c20 }, /* mic */ 2916 { 0x18, 0x01a19c20 }, /* mic */
@@ -6204,21 +2918,25 @@ static const struct alc_fixup alc269_fixups[] = {
6204 { } 2918 { }
6205 }, 2919 },
6206 }, 2920 },
6207 [ALC269_FIXUP_MIC1_MUTE_LED] = { 2921 [ALC269_FIXUP_HP_MUTE_LED] = {
6208 .type = ALC_FIXUP_FUNC, 2922 .type = HDA_FIXUP_FUNC,
6209 .v.func = alc269_fixup_mic1_mute, 2923 .v.func = alc269_fixup_hp_mute_led,
6210 }, 2924 },
6211 [ALC269_FIXUP_MIC2_MUTE_LED] = { 2925 [ALC269_FIXUP_HP_MUTE_LED_MIC1] = {
6212 .type = ALC_FIXUP_FUNC, 2926 .type = HDA_FIXUP_FUNC,
6213 .v.func = alc269_fixup_mic2_mute, 2927 .v.func = alc269_fixup_hp_mute_led_mic1,
2928 },
2929 [ALC269_FIXUP_HP_MUTE_LED_MIC2] = {
2930 .type = HDA_FIXUP_FUNC,
2931 .v.func = alc269_fixup_hp_mute_led_mic2,
6214 }, 2932 },
6215 [ALC269_FIXUP_INV_DMIC] = { 2933 [ALC269_FIXUP_INV_DMIC] = {
6216 .type = ALC_FIXUP_FUNC, 2934 .type = HDA_FIXUP_FUNC,
6217 .v.func = alc_fixup_inv_dmic_0x12, 2935 .v.func = alc_fixup_inv_dmic_0x12,
6218 }, 2936 },
6219 [ALC269_FIXUP_LENOVO_DOCK] = { 2937 [ALC269_FIXUP_LENOVO_DOCK] = {
6220 .type = ALC_FIXUP_PINS, 2938 .type = HDA_FIXUP_PINS,
6221 .v.pins = (const struct alc_pincfg[]) { 2939 .v.pins = (const struct hda_pintbl[]) {
6222 { 0x19, 0x23a11040 }, /* dock mic */ 2940 { 0x19, 0x23a11040 }, /* dock mic */
6223 { 0x1b, 0x2121103f }, /* dock headphone */ 2941 { 0x1b, 0x2121103f }, /* dock headphone */
6224 { } 2942 { }
@@ -6227,12 +2945,12 @@ static const struct alc_fixup alc269_fixups[] = {
6227 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT 2945 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6228 }, 2946 },
6229 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = { 2947 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6230 .type = ALC_FIXUP_FUNC, 2948 .type = HDA_FIXUP_FUNC,
6231 .v.func = alc269_fixup_pincfg_no_hp_to_lineout, 2949 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6232 }, 2950 },
6233 [ALC271_FIXUP_AMIC_MIC2] = { 2951 [ALC271_FIXUP_AMIC_MIC2] = {
6234 .type = ALC_FIXUP_PINS, 2952 .type = HDA_FIXUP_PINS,
6235 .v.pins = (const struct alc_pincfg[]) { 2953 .v.pins = (const struct hda_pintbl[]) {
6236 { 0x14, 0x99130110 }, /* speaker */ 2954 { 0x14, 0x99130110 }, /* speaker */
6237 { 0x19, 0x01a19c20 }, /* mic */ 2955 { 0x19, 0x01a19c20 }, /* mic */
6238 { 0x1b, 0x99a7012f }, /* int-mic */ 2956 { 0x1b, 0x99a7012f }, /* int-mic */
@@ -6241,7 +2959,7 @@ static const struct alc_fixup alc269_fixups[] = {
6241 }, 2959 },
6242 }, 2960 },
6243 [ALC271_FIXUP_HP_GATE_MIC_JACK] = { 2961 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6244 .type = ALC_FIXUP_FUNC, 2962 .type = HDA_FIXUP_FUNC,
6245 .v.func = alc271_hp_gate_mic_jack, 2963 .v.func = alc271_hp_gate_mic_jack,
6246 .chained = true, 2964 .chained = true,
6247 .chain_id = ALC271_FIXUP_AMIC_MIC2, 2965 .chain_id = ALC271_FIXUP_AMIC_MIC2,
@@ -6251,9 +2969,10 @@ static const struct alc_fixup alc269_fixups[] = {
6251static const struct snd_pci_quirk alc269_fixup_tbl[] = { 2969static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6252 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC), 2970 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6253 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC), 2971 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
6254 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED), 2972 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
6255 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED), 2973 SND_PCI_QUIRK(0x103c, 0x1973, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6256 SND_PCI_QUIRK(0x103c, 0x1977, "HP Pavilion 14", ALC269_FIXUP_MIC1_MUTE_LED), 2974 SND_PCI_QUIRK(0x103c, 0x1983, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
2975 SND_PCI_QUIRK_VENDOR(0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED),
6257 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC), 2976 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
6258 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC), 2977 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
6259 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW), 2978 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
@@ -6336,7 +3055,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6336 {} 3055 {}
6337}; 3056};
6338 3057
6339static const struct alc_model_fixup alc269_fixup_models[] = { 3058static const struct hda_model_fixup alc269_fixup_models[] = {
6340 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"}, 3059 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6341 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"}, 3060 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
6342 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"}, 3061 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
@@ -6403,10 +3122,11 @@ static int patch_alc269(struct hda_codec *codec)
6403 return err; 3122 return err;
6404 3123
6405 spec = codec->spec; 3124 spec = codec->spec;
3125 spec->gen.shared_mic_vref_pin = 0x18;
6406 3126
6407 alc_pick_fixup(codec, alc269_fixup_models, 3127 snd_hda_pick_fixup(codec, alc269_fixup_models,
6408 alc269_fixup_tbl, alc269_fixups); 3128 alc269_fixup_tbl, alc269_fixups);
6409 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 3129 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
6410 3130
6411 alc_auto_parse_customize_define(codec); 3131 alc_auto_parse_customize_define(codec);
6412 3132
@@ -6457,7 +3177,7 @@ static int patch_alc269(struct hda_codec *codec)
6457 if (err < 0) 3177 if (err < 0)
6458 goto error; 3178 goto error;
6459 3179
6460 if (!spec->no_analog && has_cdefine_beep(codec)) { 3180 if (!spec->gen.no_analog && has_cdefine_beep(codec)) {
6461 err = snd_hda_attach_beep_device(codec, 0x1); 3181 err = snd_hda_attach_beep_device(codec, 0x1);
6462 if (err < 0) 3182 if (err < 0)
6463 goto error; 3183 goto error;
@@ -6470,7 +3190,7 @@ static int patch_alc269(struct hda_codec *codec)
6470#endif 3190#endif
6471 spec->shutup = alc269_shutup; 3191 spec->shutup = alc269_shutup;
6472 3192
6473 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 3193 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
6474 3194
6475 return 0; 3195 return 0;
6476 3196
@@ -6500,49 +3220,48 @@ enum {
6500 3220
6501/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */ 3221/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6502static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec, 3222static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6503 const struct alc_fixup *fix, int action) 3223 const struct hda_fixup *fix, int action)
6504{ 3224{
6505 struct alc_spec *spec = codec->spec; 3225 struct alc_spec *spec = codec->spec;
6506 unsigned int val; 3226 unsigned int val;
6507 3227
6508 if (action != ALC_FIXUP_ACT_INIT) 3228 if (action != HDA_FIXUP_ACT_INIT)
6509 return; 3229 return;
6510 val = snd_hda_codec_read(codec, 0x0f, 0, 3230 val = snd_hda_codec_get_pin_target(codec, 0x0f);
6511 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6512 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))) 3231 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6513 val |= AC_PINCTL_IN_EN; 3232 val |= AC_PINCTL_IN_EN;
6514 val |= AC_PINCTL_VREF_50; 3233 val |= AC_PINCTL_VREF_50;
6515 snd_hda_set_pin_ctl(codec, 0x0f, val); 3234 snd_hda_set_pin_ctl(codec, 0x0f, val);
6516 spec->keep_vref_in_automute = 1; 3235 spec->gen.keep_vref_in_automute = 1;
6517} 3236}
6518 3237
6519/* suppress the jack-detection */ 3238/* suppress the jack-detection */
6520static void alc_fixup_no_jack_detect(struct hda_codec *codec, 3239static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6521 const struct alc_fixup *fix, int action) 3240 const struct hda_fixup *fix, int action)
6522{ 3241{
6523 if (action == ALC_FIXUP_ACT_PRE_PROBE) 3242 if (action == HDA_FIXUP_ACT_PRE_PROBE)
6524 codec->no_jack_detect = 1; 3243 codec->no_jack_detect = 1;
6525} 3244}
6526 3245
6527static const struct alc_fixup alc861_fixups[] = { 3246static const struct hda_fixup alc861_fixups[] = {
6528 [ALC861_FIXUP_FSC_AMILO_PI1505] = { 3247 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
6529 .type = ALC_FIXUP_PINS, 3248 .type = HDA_FIXUP_PINS,
6530 .v.pins = (const struct alc_pincfg[]) { 3249 .v.pins = (const struct hda_pintbl[]) {
6531 { 0x0b, 0x0221101f }, /* HP */ 3250 { 0x0b, 0x0221101f }, /* HP */
6532 { 0x0f, 0x90170310 }, /* speaker */ 3251 { 0x0f, 0x90170310 }, /* speaker */
6533 { } 3252 { }
6534 } 3253 }
6535 }, 3254 },
6536 [ALC861_FIXUP_AMP_VREF_0F] = { 3255 [ALC861_FIXUP_AMP_VREF_0F] = {
6537 .type = ALC_FIXUP_FUNC, 3256 .type = HDA_FIXUP_FUNC,
6538 .v.func = alc861_fixup_asus_amp_vref_0f, 3257 .v.func = alc861_fixup_asus_amp_vref_0f,
6539 }, 3258 },
6540 [ALC861_FIXUP_NO_JACK_DETECT] = { 3259 [ALC861_FIXUP_NO_JACK_DETECT] = {
6541 .type = ALC_FIXUP_FUNC, 3260 .type = HDA_FIXUP_FUNC,
6542 .v.func = alc_fixup_no_jack_detect, 3261 .v.func = alc_fixup_no_jack_detect,
6543 }, 3262 },
6544 [ALC861_FIXUP_ASUS_A6RP] = { 3263 [ALC861_FIXUP_ASUS_A6RP] = {
6545 .type = ALC_FIXUP_FUNC, 3264 .type = HDA_FIXUP_FUNC,
6546 .v.func = alc861_fixup_asus_amp_vref_0f, 3265 .v.func = alc861_fixup_asus_amp_vref_0f,
6547 .chained = true, 3266 .chained = true,
6548 .chain_id = ALC861_FIXUP_NO_JACK_DETECT, 3267 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
@@ -6572,15 +3291,15 @@ static int patch_alc861(struct hda_codec *codec)
6572 3291
6573 spec = codec->spec; 3292 spec = codec->spec;
6574 3293
6575 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); 3294 snd_hda_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6576 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 3295 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
6577 3296
6578 /* automatic parse from the BIOS config */ 3297 /* automatic parse from the BIOS config */
6579 err = alc861_parse_auto_config(codec); 3298 err = alc861_parse_auto_config(codec);
6580 if (err < 0) 3299 if (err < 0)
6581 goto error; 3300 goto error;
6582 3301
6583 if (!spec->no_analog) { 3302 if (!spec->gen.no_analog) {
6584 err = snd_hda_attach_beep_device(codec, 0x23); 3303 err = snd_hda_attach_beep_device(codec, 0x23);
6585 if (err < 0) 3304 if (err < 0)
6586 goto error; 3305 goto error;
@@ -6592,7 +3311,7 @@ static int patch_alc861(struct hda_codec *codec)
6592 spec->power_hook = alc_power_eapd; 3311 spec->power_hook = alc_power_eapd;
6593#endif 3312#endif
6594 3313
6595 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 3314 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
6596 3315
6597 return 0; 3316 return 0;
6598 3317
@@ -6622,17 +3341,17 @@ enum {
6622 3341
6623/* exclude VREF80 */ 3342/* exclude VREF80 */
6624static void alc861vd_fixup_dallas(struct hda_codec *codec, 3343static void alc861vd_fixup_dallas(struct hda_codec *codec,
6625 const struct alc_fixup *fix, int action) 3344 const struct hda_fixup *fix, int action)
6626{ 3345{
6627 if (action == ALC_FIXUP_ACT_PRE_PROBE) { 3346 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
6628 snd_hda_override_pin_caps(codec, 0x18, 0x00000734); 3347 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6629 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c); 3348 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
6630 } 3349 }
6631} 3350}
6632 3351
6633static const struct alc_fixup alc861vd_fixups[] = { 3352static const struct hda_fixup alc861vd_fixups[] = {
6634 [ALC660VD_FIX_ASUS_GPIO1] = { 3353 [ALC660VD_FIX_ASUS_GPIO1] = {
6635 .type = ALC_FIXUP_VERBS, 3354 .type = HDA_FIXUP_VERBS,
6636 .v.verbs = (const struct hda_verb[]) { 3355 .v.verbs = (const struct hda_verb[]) {
6637 /* reset GPIO1 */ 3356 /* reset GPIO1 */
6638 {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, 3357 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
@@ -6642,7 +3361,7 @@ static const struct alc_fixup alc861vd_fixups[] = {
6642 } 3361 }
6643 }, 3362 },
6644 [ALC861VD_FIX_DALLAS] = { 3363 [ALC861VD_FIX_DALLAS] = {
6645 .type = ALC_FIXUP_FUNC, 3364 .type = HDA_FIXUP_FUNC,
6646 .v.func = alc861vd_fixup_dallas, 3365 .v.func = alc861vd_fixup_dallas,
6647 }, 3366 },
6648}; 3367};
@@ -6667,15 +3386,15 @@ static int patch_alc861vd(struct hda_codec *codec)
6667 3386
6668 spec = codec->spec; 3387 spec = codec->spec;
6669 3388
6670 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); 3389 snd_hda_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6671 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 3390 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
6672 3391
6673 /* automatic parse from the BIOS config */ 3392 /* automatic parse from the BIOS config */
6674 err = alc861vd_parse_auto_config(codec); 3393 err = alc861vd_parse_auto_config(codec);
6675 if (err < 0) 3394 if (err < 0)
6676 goto error; 3395 goto error;
6677 3396
6678 if (!spec->no_analog) { 3397 if (!spec->gen.no_analog) {
6679 err = snd_hda_attach_beep_device(codec, 0x23); 3398 err = snd_hda_attach_beep_device(codec, 0x23);
6680 if (err < 0) 3399 if (err < 0)
6681 goto error; 3400 goto error;
@@ -6686,7 +3405,7 @@ static int patch_alc861vd(struct hda_codec *codec)
6686 3405
6687 spec->shutup = alc_eapd_shutup; 3406 spec->shutup = alc_eapd_shutup;
6688 3407
6689 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 3408 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
6690 3409
6691 return 0; 3410 return 0;
6692 3411
@@ -6727,9 +3446,9 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
6727} 3446}
6728 3447
6729static void alc272_fixup_mario(struct hda_codec *codec, 3448static void alc272_fixup_mario(struct hda_codec *codec,
6730 const struct alc_fixup *fix, int action) 3449 const struct hda_fixup *fix, int action)
6731{ 3450{
6732 if (action != ALC_FIXUP_ACT_PROBE) 3451 if (action != HDA_FIXUP_ACT_PRE_PROBE)
6733 return; 3452 return;
6734 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT, 3453 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6735 (0x3b << AC_AMPCAP_OFFSET_SHIFT) | 3454 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
@@ -6760,39 +3479,39 @@ enum {
6760 ALC662_FIXUP_INV_DMIC, 3479 ALC662_FIXUP_INV_DMIC,
6761}; 3480};
6762 3481
6763static const struct alc_fixup alc662_fixups[] = { 3482static const struct hda_fixup alc662_fixups[] = {
6764 [ALC662_FIXUP_ASPIRE] = { 3483 [ALC662_FIXUP_ASPIRE] = {
6765 .type = ALC_FIXUP_PINS, 3484 .type = HDA_FIXUP_PINS,
6766 .v.pins = (const struct alc_pincfg[]) { 3485 .v.pins = (const struct hda_pintbl[]) {
6767 { 0x15, 0x99130112 }, /* subwoofer */ 3486 { 0x15, 0x99130112 }, /* subwoofer */
6768 { } 3487 { }
6769 } 3488 }
6770 }, 3489 },
6771 [ALC662_FIXUP_IDEAPAD] = { 3490 [ALC662_FIXUP_IDEAPAD] = {
6772 .type = ALC_FIXUP_PINS, 3491 .type = HDA_FIXUP_PINS,
6773 .v.pins = (const struct alc_pincfg[]) { 3492 .v.pins = (const struct hda_pintbl[]) {
6774 { 0x17, 0x99130112 }, /* subwoofer */ 3493 { 0x17, 0x99130112 }, /* subwoofer */
6775 { } 3494 { }
6776 } 3495 }
6777 }, 3496 },
6778 [ALC272_FIXUP_MARIO] = { 3497 [ALC272_FIXUP_MARIO] = {
6779 .type = ALC_FIXUP_FUNC, 3498 .type = HDA_FIXUP_FUNC,
6780 .v.func = alc272_fixup_mario, 3499 .v.func = alc272_fixup_mario,
6781 }, 3500 },
6782 [ALC662_FIXUP_CZC_P10T] = { 3501 [ALC662_FIXUP_CZC_P10T] = {
6783 .type = ALC_FIXUP_VERBS, 3502 .type = HDA_FIXUP_VERBS,
6784 .v.verbs = (const struct hda_verb[]) { 3503 .v.verbs = (const struct hda_verb[]) {
6785 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, 3504 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6786 {} 3505 {}
6787 } 3506 }
6788 }, 3507 },
6789 [ALC662_FIXUP_SKU_IGNORE] = { 3508 [ALC662_FIXUP_SKU_IGNORE] = {
6790 .type = ALC_FIXUP_FUNC, 3509 .type = HDA_FIXUP_FUNC,
6791 .v.func = alc_fixup_sku_ignore, 3510 .v.func = alc_fixup_sku_ignore,
6792 }, 3511 },
6793 [ALC662_FIXUP_HP_RP5800] = { 3512 [ALC662_FIXUP_HP_RP5800] = {
6794 .type = ALC_FIXUP_PINS, 3513 .type = HDA_FIXUP_PINS,
6795 .v.pins = (const struct alc_pincfg[]) { 3514 .v.pins = (const struct hda_pintbl[]) {
6796 { 0x14, 0x0221201f }, /* HP out */ 3515 { 0x14, 0x0221201f }, /* HP out */
6797 { } 3516 { }
6798 }, 3517 },
@@ -6800,8 +3519,8 @@ static const struct alc_fixup alc662_fixups[] = {
6800 .chain_id = ALC662_FIXUP_SKU_IGNORE 3519 .chain_id = ALC662_FIXUP_SKU_IGNORE
6801 }, 3520 },
6802 [ALC662_FIXUP_ASUS_MODE1] = { 3521 [ALC662_FIXUP_ASUS_MODE1] = {
6803 .type = ALC_FIXUP_PINS, 3522 .type = HDA_FIXUP_PINS,
6804 .v.pins = (const struct alc_pincfg[]) { 3523 .v.pins = (const struct hda_pintbl[]) {
6805 { 0x14, 0x99130110 }, /* speaker */ 3524 { 0x14, 0x99130110 }, /* speaker */
6806 { 0x18, 0x01a19c20 }, /* mic */ 3525 { 0x18, 0x01a19c20 }, /* mic */
6807 { 0x19, 0x99a3092f }, /* int-mic */ 3526 { 0x19, 0x99a3092f }, /* int-mic */
@@ -6812,8 +3531,8 @@ static const struct alc_fixup alc662_fixups[] = {
6812 .chain_id = ALC662_FIXUP_SKU_IGNORE 3531 .chain_id = ALC662_FIXUP_SKU_IGNORE
6813 }, 3532 },
6814 [ALC662_FIXUP_ASUS_MODE2] = { 3533 [ALC662_FIXUP_ASUS_MODE2] = {
6815 .type = ALC_FIXUP_PINS, 3534 .type = HDA_FIXUP_PINS,
6816 .v.pins = (const struct alc_pincfg[]) { 3535 .v.pins = (const struct hda_pintbl[]) {
6817 { 0x14, 0x99130110 }, /* speaker */ 3536 { 0x14, 0x99130110 }, /* speaker */
6818 { 0x18, 0x01a19820 }, /* mic */ 3537 { 0x18, 0x01a19820 }, /* mic */
6819 { 0x19, 0x99a3092f }, /* int-mic */ 3538 { 0x19, 0x99a3092f }, /* int-mic */
@@ -6824,8 +3543,8 @@ static const struct alc_fixup alc662_fixups[] = {
6824 .chain_id = ALC662_FIXUP_SKU_IGNORE 3543 .chain_id = ALC662_FIXUP_SKU_IGNORE
6825 }, 3544 },
6826 [ALC662_FIXUP_ASUS_MODE3] = { 3545 [ALC662_FIXUP_ASUS_MODE3] = {
6827 .type = ALC_FIXUP_PINS, 3546 .type = HDA_FIXUP_PINS,
6828 .v.pins = (const struct alc_pincfg[]) { 3547 .v.pins = (const struct hda_pintbl[]) {
6829 { 0x14, 0x99130110 }, /* speaker */ 3548 { 0x14, 0x99130110 }, /* speaker */
6830 { 0x15, 0x0121441f }, /* HP */ 3549 { 0x15, 0x0121441f }, /* HP */
6831 { 0x18, 0x01a19840 }, /* mic */ 3550 { 0x18, 0x01a19840 }, /* mic */
@@ -6837,8 +3556,8 @@ static const struct alc_fixup alc662_fixups[] = {
6837 .chain_id = ALC662_FIXUP_SKU_IGNORE 3556 .chain_id = ALC662_FIXUP_SKU_IGNORE
6838 }, 3557 },
6839 [ALC662_FIXUP_ASUS_MODE4] = { 3558 [ALC662_FIXUP_ASUS_MODE4] = {
6840 .type = ALC_FIXUP_PINS, 3559 .type = HDA_FIXUP_PINS,
6841 .v.pins = (const struct alc_pincfg[]) { 3560 .v.pins = (const struct hda_pintbl[]) {
6842 { 0x14, 0x99130110 }, /* speaker */ 3561 { 0x14, 0x99130110 }, /* speaker */
6843 { 0x16, 0x99130111 }, /* speaker */ 3562 { 0x16, 0x99130111 }, /* speaker */
6844 { 0x18, 0x01a19840 }, /* mic */ 3563 { 0x18, 0x01a19840 }, /* mic */
@@ -6850,8 +3569,8 @@ static const struct alc_fixup alc662_fixups[] = {
6850 .chain_id = ALC662_FIXUP_SKU_IGNORE 3569 .chain_id = ALC662_FIXUP_SKU_IGNORE
6851 }, 3570 },
6852 [ALC662_FIXUP_ASUS_MODE5] = { 3571 [ALC662_FIXUP_ASUS_MODE5] = {
6853 .type = ALC_FIXUP_PINS, 3572 .type = HDA_FIXUP_PINS,
6854 .v.pins = (const struct alc_pincfg[]) { 3573 .v.pins = (const struct hda_pintbl[]) {
6855 { 0x14, 0x99130110 }, /* speaker */ 3574 { 0x14, 0x99130110 }, /* speaker */
6856 { 0x15, 0x0121441f }, /* HP */ 3575 { 0x15, 0x0121441f }, /* HP */
6857 { 0x16, 0x99130111 }, /* speaker */ 3576 { 0x16, 0x99130111 }, /* speaker */
@@ -6863,8 +3582,8 @@ static const struct alc_fixup alc662_fixups[] = {
6863 .chain_id = ALC662_FIXUP_SKU_IGNORE 3582 .chain_id = ALC662_FIXUP_SKU_IGNORE
6864 }, 3583 },
6865 [ALC662_FIXUP_ASUS_MODE6] = { 3584 [ALC662_FIXUP_ASUS_MODE6] = {
6866 .type = ALC_FIXUP_PINS, 3585 .type = HDA_FIXUP_PINS,
6867 .v.pins = (const struct alc_pincfg[]) { 3586 .v.pins = (const struct hda_pintbl[]) {
6868 { 0x14, 0x99130110 }, /* speaker */ 3587 { 0x14, 0x99130110 }, /* speaker */
6869 { 0x15, 0x01211420 }, /* HP2 */ 3588 { 0x15, 0x01211420 }, /* HP2 */
6870 { 0x18, 0x01a19840 }, /* mic */ 3589 { 0x18, 0x01a19840 }, /* mic */
@@ -6876,8 +3595,8 @@ static const struct alc_fixup alc662_fixups[] = {
6876 .chain_id = ALC662_FIXUP_SKU_IGNORE 3595 .chain_id = ALC662_FIXUP_SKU_IGNORE
6877 }, 3596 },
6878 [ALC662_FIXUP_ASUS_MODE7] = { 3597 [ALC662_FIXUP_ASUS_MODE7] = {
6879 .type = ALC_FIXUP_PINS, 3598 .type = HDA_FIXUP_PINS,
6880 .v.pins = (const struct alc_pincfg[]) { 3599 .v.pins = (const struct hda_pintbl[]) {
6881 { 0x14, 0x99130110 }, /* speaker */ 3600 { 0x14, 0x99130110 }, /* speaker */
6882 { 0x17, 0x99130111 }, /* speaker */ 3601 { 0x17, 0x99130111 }, /* speaker */
6883 { 0x18, 0x01a19840 }, /* mic */ 3602 { 0x18, 0x01a19840 }, /* mic */
@@ -6890,8 +3609,8 @@ static const struct alc_fixup alc662_fixups[] = {
6890 .chain_id = ALC662_FIXUP_SKU_IGNORE 3609 .chain_id = ALC662_FIXUP_SKU_IGNORE
6891 }, 3610 },
6892 [ALC662_FIXUP_ASUS_MODE8] = { 3611 [ALC662_FIXUP_ASUS_MODE8] = {
6893 .type = ALC_FIXUP_PINS, 3612 .type = HDA_FIXUP_PINS,
6894 .v.pins = (const struct alc_pincfg[]) { 3613 .v.pins = (const struct hda_pintbl[]) {
6895 { 0x14, 0x99130110 }, /* speaker */ 3614 { 0x14, 0x99130110 }, /* speaker */
6896 { 0x12, 0x99a30970 }, /* int-mic */ 3615 { 0x12, 0x99a30970 }, /* int-mic */
6897 { 0x15, 0x01214020 }, /* HP */ 3616 { 0x15, 0x01214020 }, /* HP */
@@ -6904,18 +3623,18 @@ static const struct alc_fixup alc662_fixups[] = {
6904 .chain_id = ALC662_FIXUP_SKU_IGNORE 3623 .chain_id = ALC662_FIXUP_SKU_IGNORE
6905 }, 3624 },
6906 [ALC662_FIXUP_NO_JACK_DETECT] = { 3625 [ALC662_FIXUP_NO_JACK_DETECT] = {
6907 .type = ALC_FIXUP_FUNC, 3626 .type = HDA_FIXUP_FUNC,
6908 .v.func = alc_fixup_no_jack_detect, 3627 .v.func = alc_fixup_no_jack_detect,
6909 }, 3628 },
6910 [ALC662_FIXUP_ZOTAC_Z68] = { 3629 [ALC662_FIXUP_ZOTAC_Z68] = {
6911 .type = ALC_FIXUP_PINS, 3630 .type = HDA_FIXUP_PINS,
6912 .v.pins = (const struct alc_pincfg[]) { 3631 .v.pins = (const struct hda_pintbl[]) {
6913 { 0x1b, 0x02214020 }, /* Front HP */ 3632 { 0x1b, 0x02214020 }, /* Front HP */
6914 { } 3633 { }
6915 } 3634 }
6916 }, 3635 },
6917 [ALC662_FIXUP_INV_DMIC] = { 3636 [ALC662_FIXUP_INV_DMIC] = {
6918 .type = ALC_FIXUP_FUNC, 3637 .type = HDA_FIXUP_FUNC,
6919 .v.func = alc_fixup_inv_dmic_0x12, 3638 .v.func = alc_fixup_inv_dmic_0x12,
6920 }, 3639 },
6921}; 3640};
@@ -6995,7 +3714,7 @@ static const struct snd_pci_quirk alc662_fixup_tbl[] = {
6995 {} 3714 {}
6996}; 3715};
6997 3716
6998static const struct alc_model_fixup alc662_fixup_models[] = { 3717static const struct hda_model_fixup alc662_fixup_models[] = {
6999 {.id = ALC272_FIXUP_MARIO, .name = "mario"}, 3718 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
7000 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"}, 3719 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7001 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"}, 3720 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
@@ -7056,9 +3775,9 @@ static int patch_alc662(struct hda_codec *codec)
7056 spec->init_hook = alc662_fill_coef; 3775 spec->init_hook = alc662_fill_coef;
7057 alc662_fill_coef(codec); 3776 alc662_fill_coef(codec);
7058 3777
7059 alc_pick_fixup(codec, alc662_fixup_models, 3778 snd_hda_pick_fixup(codec, alc662_fixup_models,
7060 alc662_fixup_tbl, alc662_fixups); 3779 alc662_fixup_tbl, alc662_fixups);
7061 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 3780 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
7062 3781
7063 alc_auto_parse_customize_define(codec); 3782 alc_auto_parse_customize_define(codec);
7064 3783
@@ -7074,7 +3793,7 @@ static int patch_alc662(struct hda_codec *codec)
7074 if (err < 0) 3793 if (err < 0)
7075 goto error; 3794 goto error;
7076 3795
7077 if (!spec->no_analog && has_cdefine_beep(codec)) { 3796 if (!spec->gen.no_analog && has_cdefine_beep(codec)) {
7078 err = snd_hda_attach_beep_device(codec, 0x1); 3797 err = snd_hda_attach_beep_device(codec, 0x1);
7079 if (err < 0) 3798 if (err < 0)
7080 goto error; 3799 goto error;
@@ -7096,7 +3815,7 @@ static int patch_alc662(struct hda_codec *codec)
7096 codec->patch_ops = alc_patch_ops; 3815 codec->patch_ops = alc_patch_ops;
7097 spec->shutup = alc_eapd_shutup; 3816 spec->shutup = alc_eapd_shutup;
7098 3817
7099 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 3818 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
7100 3819
7101 return 0; 3820 return 0;
7102 3821