]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Universal Interface for Intel High Definition Audio Codec | |
3 | * | |
4 | * HD audio interface patch for Realtek ALC codecs | |
5 | * | |
6 | * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw> | |
7 | * PeiSen Hou <pshou@realtek.com.tw> | |
8 | * Takashi Iwai <tiwai@suse.de> | |
9 | * Jonathan Woithe <jwoithe@just42.net> | |
10 | * | |
11 | * This driver is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or | |
14 | * (at your option) any later version. | |
15 | * | |
16 | * This driver is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 | */ | |
25 | ||
26 | #include <linux/init.h> | |
27 | #include <linux/delay.h> | |
28 | #include <linux/slab.h> | |
29 | #include <linux/pci.h> | |
30 | #include <linux/module.h> | |
31 | #include <sound/core.h> | |
32 | #include <sound/jack.h> | |
33 | #include "hda_codec.h" | |
34 | #include "hda_local.h" | |
35 | #include "hda_auto_parser.h" | |
36 | #include "hda_beep.h" | |
37 | #include "hda_jack.h" | |
38 | ||
39 | /* unsol event tags */ | |
40 | #define ALC_FRONT_EVENT 0x01 | |
41 | #define ALC_DCVOL_EVENT 0x02 | |
42 | #define ALC_HP_EVENT 0x04 | |
43 | #define ALC_MIC_EVENT 0x08 | |
44 | ||
45 | /* for GPIO Poll */ | |
46 | #define GPIO_MASK 0x03 | |
47 | ||
48 | /* extra amp-initialization sequence types */ | |
49 | enum { | |
50 | ALC_INIT_NONE, | |
51 | ALC_INIT_DEFAULT, | |
52 | ALC_INIT_GPIO1, | |
53 | ALC_INIT_GPIO2, | |
54 | ALC_INIT_GPIO3, | |
55 | }; | |
56 | ||
57 | struct alc_customize_define { | |
58 | unsigned int sku_cfg; | |
59 | unsigned char port_connectivity; | |
60 | unsigned char check_sum; | |
61 | unsigned char customization; | |
62 | unsigned char external_amp; | |
63 | unsigned int enable_pcbeep:1; | |
64 | unsigned int platform_type:1; | |
65 | unsigned int swap:1; | |
66 | unsigned int override:1; | |
67 | unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */ | |
68 | }; | |
69 | ||
70 | struct 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 | ||
76 | /* make compatible with old code */ | |
77 | #define alc_apply_pincfgs snd_hda_apply_pincfgs | |
78 | #define alc_apply_fixup snd_hda_apply_fixup | |
79 | #define alc_pick_fixup snd_hda_pick_fixup | |
80 | #define alc_fixup hda_fixup | |
81 | #define alc_pincfg hda_pintbl | |
82 | #define alc_model_fixup hda_model_fixup | |
83 | ||
84 | #define ALC_FIXUP_PINS HDA_FIXUP_PINS | |
85 | #define ALC_FIXUP_VERBS HDA_FIXUP_VERBS | |
86 | #define ALC_FIXUP_FUNC HDA_FIXUP_FUNC | |
87 | ||
88 | #define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE | |
89 | #define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE | |
90 | #define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT | |
91 | #define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD | |
92 | ||
93 | ||
94 | #define MAX_NID_PATH_DEPTH 5 | |
95 | ||
96 | enum { | |
97 | NID_PATH_VOL_CTL, | |
98 | NID_PATH_MUTE_CTL, | |
99 | NID_PATH_BOOST_CTL, | |
100 | NID_PATH_NUM_CTLS | |
101 | }; | |
102 | ||
103 | /* Widget connection path | |
104 | * | |
105 | * For output, stored in the order of DAC -> ... -> pin, | |
106 | * for input, pin -> ... -> ADC. | |
107 | * | |
108 | * idx[i] contains the source index number to select on of the widget path[i]; | |
109 | * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget | |
110 | * multi[] indicates whether it's a selector widget with multi-connectors | |
111 | * (i.e. the connection selection is mandatory) | |
112 | * vol_ctl and mute_ctl contains the NIDs for the assigned mixers | |
113 | */ | |
114 | struct nid_path { | |
115 | int depth; | |
116 | hda_nid_t path[MAX_NID_PATH_DEPTH]; | |
117 | unsigned char idx[MAX_NID_PATH_DEPTH]; | |
118 | unsigned char multi[MAX_NID_PATH_DEPTH]; | |
119 | unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */ | |
120 | bool active; | |
121 | }; | |
122 | ||
123 | struct alc_spec { | |
124 | struct hda_gen_spec gen; | |
125 | ||
126 | /* codec parameterization */ | |
127 | const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ | |
128 | unsigned int num_mixers; | |
129 | unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ | |
130 | ||
131 | char stream_name_analog[32]; /* analog PCM stream */ | |
132 | const struct hda_pcm_stream *stream_analog_playback; | |
133 | const struct hda_pcm_stream *stream_analog_capture; | |
134 | const struct hda_pcm_stream *stream_analog_alt_playback; | |
135 | const struct hda_pcm_stream *stream_analog_alt_capture; | |
136 | ||
137 | char stream_name_digital[32]; /* digital PCM stream */ | |
138 | const struct hda_pcm_stream *stream_digital_playback; | |
139 | const struct hda_pcm_stream *stream_digital_capture; | |
140 | ||
141 | /* playback */ | |
142 | struct hda_multi_out multiout; /* playback set-up | |
143 | * max_channels, dacs must be set | |
144 | * dig_out_nid and hp_nid are optional | |
145 | */ | |
146 | hda_nid_t alt_dac_nid; | |
147 | hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */ | |
148 | int dig_out_type; | |
149 | ||
150 | /* capture */ | |
151 | unsigned int num_adc_nids; | |
152 | hda_nid_t adc_nids[AUTO_CFG_MAX_OUTS]; | |
153 | hda_nid_t dig_in_nid; /* digital-in NID; optional */ | |
154 | hda_nid_t mixer_nid; /* analog-mixer NID */ | |
155 | ||
156 | /* capture setup for dynamic dual-adc switch */ | |
157 | hda_nid_t cur_adc; | |
158 | unsigned int cur_adc_stream_tag; | |
159 | unsigned int cur_adc_format; | |
160 | ||
161 | /* capture source */ | |
162 | struct hda_input_mux input_mux; | |
163 | unsigned int cur_mux[3]; | |
164 | hda_nid_t ext_mic_pin; | |
165 | hda_nid_t dock_mic_pin; | |
166 | hda_nid_t int_mic_pin; | |
167 | ||
168 | /* channel model */ | |
169 | const struct hda_channel_mode *channel_mode; | |
170 | int num_channel_mode; | |
171 | int const_channel_count; /* min. channel count (for speakers) */ | |
172 | int ext_channel_count; /* current channel count for multi-io */ | |
173 | ||
174 | /* PCM information */ | |
175 | struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */ | |
176 | ||
177 | /* dynamic controls, init_verbs and input_mux */ | |
178 | struct auto_pin_cfg autocfg; | |
179 | struct alc_customize_define cdefine; | |
180 | struct snd_array kctls; | |
181 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; | |
182 | hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS]; | |
183 | unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS]; | |
184 | int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */ | |
185 | hda_nid_t inv_dmic_pin; | |
186 | hda_nid_t shared_mic_vref_pin; | |
187 | int inv_dmic_split_idx; /* used internally for inv_dmic_split */ | |
188 | ||
189 | /* DAC list */ | |
190 | int num_all_dacs; | |
191 | hda_nid_t all_dacs[16]; | |
192 | ||
193 | /* path list */ | |
194 | struct snd_array paths; | |
195 | ||
196 | /* hooks */ | |
197 | void (*init_hook)(struct hda_codec *codec); | |
198 | #ifdef CONFIG_PM | |
199 | void (*power_hook)(struct hda_codec *codec); | |
200 | #endif | |
201 | void (*shutup)(struct hda_codec *codec); | |
202 | void (*automute_hook)(struct hda_codec *codec); | |
203 | ||
204 | /* for pin sensing */ | |
205 | unsigned int hp_jack_present:1; | |
206 | unsigned int line_jack_present:1; | |
207 | unsigned int master_mute:1; | |
208 | unsigned int auto_mic:1; | |
209 | unsigned int automute_speaker:1; /* automute speaker outputs */ | |
210 | unsigned int automute_lo:1; /* automute LO outputs */ | |
211 | unsigned int detect_hp:1; /* Headphone detection enabled */ | |
212 | unsigned int detect_lo:1; /* Line-out detection enabled */ | |
213 | unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */ | |
214 | unsigned int automute_lo_possible:1; /* there are line outs and HP */ | |
215 | unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */ | |
216 | ||
217 | /* other flags */ | |
218 | unsigned int need_dac_fix:1; /* need to limit DACs for multi channels */ | |
219 | unsigned int no_analog :1; /* digital I/O only */ | |
220 | unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */ | |
221 | unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */ | |
222 | unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */ | |
223 | unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */ | |
224 | unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */ | |
225 | unsigned int multi_cap_vol:1; /* allow multiple capture xxx volumes */ | |
226 | unsigned int inv_dmic_split:1; /* inverted dmic w/a for conexant */ | |
227 | ||
228 | unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */ | |
229 | ||
230 | int init_amp; | |
231 | int codec_variant; /* flag for other variants */ | |
232 | ||
233 | /* for virtual master */ | |
234 | hda_nid_t vmaster_nid; | |
235 | struct hda_vmaster_mute_hook vmaster_mute; | |
236 | #ifdef CONFIG_PM | |
237 | struct hda_loopback_check loopback; | |
238 | int num_loopbacks; | |
239 | struct hda_amp_list loopback_list[8]; | |
240 | #endif | |
241 | ||
242 | /* for PLL fix */ | |
243 | hda_nid_t pll_nid; | |
244 | unsigned int pll_coef_idx, pll_coef_bit; | |
245 | unsigned int coef0; | |
246 | ||
247 | /* multi-io */ | |
248 | int multi_ios; | |
249 | struct alc_multi_io multi_io[4]; | |
250 | ||
251 | /* bind volumes */ | |
252 | struct snd_array bind_ctls; | |
253 | }; | |
254 | ||
255 | static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, | |
256 | int dir, unsigned int bits) | |
257 | { | |
258 | if (!nid) | |
259 | return false; | |
260 | if (get_wcaps(codec, nid) & (1 << (dir + 1))) | |
261 | if (query_amp_caps(codec, nid, dir) & bits) | |
262 | return true; | |
263 | return false; | |
264 | } | |
265 | ||
266 | #define nid_has_mute(codec, nid, dir) \ | |
267 | check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE) | |
268 | #define nid_has_volume(codec, nid, dir) \ | |
269 | check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS) | |
270 | ||
271 | static struct nid_path * | |
272 | get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid); | |
273 | static void activate_path(struct hda_codec *codec, struct nid_path *path, | |
274 | bool enable, bool add_aamix); | |
275 | ||
276 | /* | |
277 | * input MUX handling | |
278 | */ | |
279 | static int alc_mux_enum_info(struct snd_kcontrol *kcontrol, | |
280 | struct snd_ctl_elem_info *uinfo) | |
281 | { | |
282 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
283 | struct alc_spec *spec = codec->spec; | |
284 | return snd_hda_input_mux_info(&spec->input_mux, uinfo); | |
285 | } | |
286 | ||
287 | static int alc_mux_enum_get(struct snd_kcontrol *kcontrol, | |
288 | struct snd_ctl_elem_value *ucontrol) | |
289 | { | |
290 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
291 | struct alc_spec *spec = codec->spec; | |
292 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
293 | ||
294 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; | |
295 | return 0; | |
296 | } | |
297 | ||
298 | static hda_nid_t get_adc_nid(struct hda_codec *codec, int adc_idx, int imux_idx) | |
299 | { | |
300 | struct alc_spec *spec = codec->spec; | |
301 | if (spec->dyn_adc_switch) | |
302 | adc_idx = spec->dyn_adc_idx[imux_idx]; | |
303 | return spec->adc_nids[adc_idx]; | |
304 | } | |
305 | ||
306 | static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur) | |
307 | { | |
308 | struct alc_spec *spec = codec->spec; | |
309 | hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]]; | |
310 | ||
311 | if (spec->cur_adc && spec->cur_adc != new_adc) { | |
312 | /* stream is running, let's swap the current ADC */ | |
313 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); | |
314 | spec->cur_adc = new_adc; | |
315 | snd_hda_codec_setup_stream(codec, new_adc, | |
316 | spec->cur_adc_stream_tag, 0, | |
317 | spec->cur_adc_format); | |
318 | return true; | |
319 | } | |
320 | return false; | |
321 | } | |
322 | ||
323 | static void call_update_outputs(struct hda_codec *codec); | |
324 | static void alc_inv_dmic_sync(struct hda_codec *codec, bool force); | |
325 | static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx); | |
326 | ||
327 | /* for shared I/O, change the pin-control accordingly */ | |
328 | static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic) | |
329 | { | |
330 | struct alc_spec *spec = codec->spec; | |
331 | unsigned int val; | |
332 | hda_nid_t pin = spec->autocfg.inputs[1].pin; | |
333 | /* NOTE: this assumes that there are only two inputs, the | |
334 | * first is the real internal mic and the second is HP/mic jack. | |
335 | */ | |
336 | ||
337 | val = snd_hda_get_default_vref(codec, pin); | |
338 | ||
339 | /* This pin does not have vref caps - let's enable vref on pin 0x18 | |
340 | instead, as suggested by Realtek */ | |
341 | if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) { | |
342 | const hda_nid_t vref_pin = spec->shared_mic_vref_pin; | |
343 | unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin); | |
344 | if (vref_val != AC_PINCTL_VREF_HIZ) | |
345 | snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0)); | |
346 | } | |
347 | ||
348 | val = set_as_mic ? val | PIN_IN : PIN_HP; | |
349 | snd_hda_set_pin_ctl(codec, pin, val); | |
350 | ||
351 | spec->automute_speaker = !set_as_mic; | |
352 | call_update_outputs(codec); | |
353 | } | |
354 | ||
355 | /* select the given imux item; either unmute exclusively or select the route */ | |
356 | static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx, | |
357 | unsigned int idx, bool force) | |
358 | { | |
359 | struct alc_spec *spec = codec->spec; | |
360 | const struct hda_input_mux *imux; | |
361 | struct nid_path *path; | |
362 | ||
363 | imux = &spec->input_mux; | |
364 | if (!imux->num_items) | |
365 | return 0; | |
366 | ||
367 | if (idx >= imux->num_items) | |
368 | idx = imux->num_items - 1; | |
369 | if (spec->cur_mux[adc_idx] == idx && !force) | |
370 | return 0; | |
371 | ||
372 | path = get_nid_path(codec, spec->imux_pins[spec->cur_mux[adc_idx]], | |
373 | spec->adc_nids[adc_idx]); | |
374 | if (!path) | |
375 | return 0; | |
376 | if (path->active) | |
377 | activate_path(codec, path, false, false); | |
378 | ||
379 | spec->cur_mux[adc_idx] = idx; | |
380 | ||
381 | if (spec->shared_mic_hp) | |
382 | update_shared_mic_hp(codec, spec->cur_mux[adc_idx]); | |
383 | ||
384 | if (spec->dyn_adc_switch) | |
385 | alc_dyn_adc_pcm_resetup(codec, idx); | |
386 | ||
387 | path = get_nid_path(codec, spec->imux_pins[idx], | |
388 | get_adc_nid(codec, adc_idx, idx)); | |
389 | if (!path) | |
390 | return 0; | |
391 | if (path->active) | |
392 | return 0; | |
393 | activate_path(codec, path, true, false); | |
394 | alc_inv_dmic_sync(codec, true); | |
395 | return 1; | |
396 | } | |
397 | ||
398 | static 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 | */ | |
410 | static 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 | /* | |
420 | * Append the given mixer and verb elements for the later use | |
421 | * The mixer array is referred in build_controls(), and init_verbs are | |
422 | * called in init(). | |
423 | */ | |
424 | static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix) | |
425 | { | |
426 | if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers))) | |
427 | return; | |
428 | spec->mixers[spec->num_mixers++] = mix; | |
429 | } | |
430 | ||
431 | /* | |
432 | * GPIO setup tables, used in initialization | |
433 | */ | |
434 | /* Enable GPIO mask and set output */ | |
435 | static const struct hda_verb alc_gpio1_init_verbs[] = { | |
436 | {0x01, AC_VERB_SET_GPIO_MASK, 0x01}, | |
437 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, | |
438 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, | |
439 | { } | |
440 | }; | |
441 | ||
442 | static const struct hda_verb alc_gpio2_init_verbs[] = { | |
443 | {0x01, AC_VERB_SET_GPIO_MASK, 0x02}, | |
444 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02}, | |
445 | {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, | |
446 | { } | |
447 | }; | |
448 | ||
449 | static const struct hda_verb alc_gpio3_init_verbs[] = { | |
450 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, | |
451 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03}, | |
452 | {0x01, AC_VERB_SET_GPIO_DATA, 0x03}, | |
453 | { } | |
454 | }; | |
455 | ||
456 | /* | |
457 | * Fix hardware PLL issue | |
458 | * On some codecs, the analog PLL gating control must be off while | |
459 | * the default value is 1. | |
460 | */ | |
461 | static void alc_fix_pll(struct hda_codec *codec) | |
462 | { | |
463 | struct alc_spec *spec = codec->spec; | |
464 | unsigned int val; | |
465 | ||
466 | if (!spec->pll_nid) | |
467 | return; | |
468 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, | |
469 | spec->pll_coef_idx); | |
470 | val = snd_hda_codec_read(codec, spec->pll_nid, 0, | |
471 | AC_VERB_GET_PROC_COEF, 0); | |
472 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, | |
473 | spec->pll_coef_idx); | |
474 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF, | |
475 | val & ~(1 << spec->pll_coef_bit)); | |
476 | } | |
477 | ||
478 | static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid, | |
479 | unsigned int coef_idx, unsigned int coef_bit) | |
480 | { | |
481 | struct alc_spec *spec = codec->spec; | |
482 | spec->pll_nid = nid; | |
483 | spec->pll_coef_idx = coef_idx; | |
484 | spec->pll_coef_bit = coef_bit; | |
485 | alc_fix_pll(codec); | |
486 | } | |
487 | ||
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 */ | |
493 | static 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 */ | |
507 | static 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 pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT); | |
512 | int i; | |
513 | ||
514 | for (i = 0; i < num_pins; i++) { | |
515 | hda_nid_t nid = pins[i]; | |
516 | unsigned int val; | |
517 | if (!nid) | |
518 | break; | |
519 | /* don't reset VREF value in case it's controlling | |
520 | * the amp (see alc861_fixup_asus_amp_vref_0f()) | |
521 | */ | |
522 | if (spec->keep_vref_in_automute) { | |
523 | val = snd_hda_codec_read(codec, nid, 0, | |
524 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | |
525 | val &= ~PIN_HP; | |
526 | } else | |
527 | val = 0; | |
528 | val |= pin_bits; | |
529 | snd_hda_set_pin_ctl(codec, nid, val); | |
530 | } | |
531 | } | |
532 | ||
533 | /* Toggle outputs muting */ | |
534 | static void update_outputs(struct hda_codec *codec) | |
535 | { | |
536 | struct alc_spec *spec = codec->spec; | |
537 | int on; | |
538 | ||
539 | /* Control HP pins/amps depending on master_mute state; | |
540 | * in general, HP pins/amps control should be enabled in all cases, | |
541 | * but currently set only for master_mute, just to be safe | |
542 | */ | |
543 | if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */ | |
544 | do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins), | |
545 | spec->autocfg.hp_pins, spec->master_mute, true); | |
546 | ||
547 | if (!spec->automute_speaker) | |
548 | on = 0; | |
549 | else | |
550 | on = spec->hp_jack_present | spec->line_jack_present; | |
551 | on |= spec->master_mute; | |
552 | do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins), | |
553 | spec->autocfg.speaker_pins, on, false); | |
554 | ||
555 | /* toggle line-out mutes if needed, too */ | |
556 | /* if LO is a copy of either HP or Speaker, don't need to handle it */ | |
557 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] || | |
558 | spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0]) | |
559 | return; | |
560 | if (!spec->automute_lo) | |
561 | on = 0; | |
562 | else | |
563 | on = spec->hp_jack_present; | |
564 | on |= spec->master_mute; | |
565 | do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), | |
566 | spec->autocfg.line_out_pins, on, false); | |
567 | } | |
568 | ||
569 | static void call_update_outputs(struct hda_codec *codec) | |
570 | { | |
571 | struct alc_spec *spec = codec->spec; | |
572 | if (spec->automute_hook) | |
573 | spec->automute_hook(codec); | |
574 | else | |
575 | update_outputs(codec); | |
576 | } | |
577 | ||
578 | /* standard HP-automute helper */ | |
579 | static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack) | |
580 | { | |
581 | struct alc_spec *spec = codec->spec; | |
582 | ||
583 | spec->hp_jack_present = | |
584 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins), | |
585 | spec->autocfg.hp_pins); | |
586 | if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo)) | |
587 | return; | |
588 | call_update_outputs(codec); | |
589 | } | |
590 | ||
591 | /* standard line-out-automute helper */ | |
592 | static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack) | |
593 | { | |
594 | struct alc_spec *spec = codec->spec; | |
595 | ||
596 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) | |
597 | return; | |
598 | /* check LO jack only when it's different from HP */ | |
599 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0]) | |
600 | return; | |
601 | ||
602 | spec->line_jack_present = | |
603 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), | |
604 | spec->autocfg.line_out_pins); | |
605 | if (!spec->automute_speaker || !spec->detect_lo) | |
606 | return; | |
607 | call_update_outputs(codec); | |
608 | } | |
609 | ||
610 | /* standard mic auto-switch helper */ | |
611 | static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack) | |
612 | { | |
613 | struct alc_spec *spec = codec->spec; | |
614 | hda_nid_t *pins = spec->imux_pins; | |
615 | ||
616 | if (!spec->auto_mic) | |
617 | return; | |
618 | if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0)) | |
619 | return; | |
620 | ||
621 | if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx])) | |
622 | alc_mux_select(codec, 0, spec->ext_mic_idx, false); | |
623 | else if (spec->dock_mic_idx >= 0 && | |
624 | snd_hda_jack_detect(codec, pins[spec->dock_mic_idx])) | |
625 | alc_mux_select(codec, 0, spec->dock_mic_idx, false); | |
626 | else | |
627 | alc_mux_select(codec, 0, spec->int_mic_idx, false); | |
628 | } | |
629 | ||
630 | /* update the master volume per volume-knob's unsol event */ | |
631 | static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack) | |
632 | { | |
633 | unsigned int val; | |
634 | struct snd_kcontrol *kctl; | |
635 | struct snd_ctl_elem_value *uctl; | |
636 | ||
637 | kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume"); | |
638 | if (!kctl) | |
639 | return; | |
640 | uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); | |
641 | if (!uctl) | |
642 | return; | |
643 | val = snd_hda_codec_read(codec, jack->nid, 0, | |
644 | AC_VERB_GET_VOLUME_KNOB_CONTROL, 0); | |
645 | val &= HDA_AMP_VOLMASK; | |
646 | uctl->value.integer.value[0] = val; | |
647 | uctl->value.integer.value[1] = val; | |
648 | kctl->put(kctl, uctl); | |
649 | kfree(uctl); | |
650 | } | |
651 | ||
652 | static void alc880_unsol_event(struct hda_codec *codec, unsigned int res) | |
653 | { | |
654 | /* For some reason, the res given from ALC880 is broken. | |
655 | Here we adjust it properly. */ | |
656 | snd_hda_jack_unsol_event(codec, res >> 2); | |
657 | } | |
658 | ||
659 | /* additional initialization for ALC888 variants */ | |
660 | static void alc888_coef_init(struct hda_codec *codec) | |
661 | { | |
662 | unsigned int tmp; | |
663 | ||
664 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0); | |
665 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); | |
666 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); | |
667 | if ((tmp & 0xf0) == 0x20) | |
668 | /* alc888S-VC */ | |
669 | snd_hda_codec_read(codec, 0x20, 0, | |
670 | AC_VERB_SET_PROC_COEF, 0x830); | |
671 | else | |
672 | /* alc888-VB */ | |
673 | snd_hda_codec_read(codec, 0x20, 0, | |
674 | AC_VERB_SET_PROC_COEF, 0x3030); | |
675 | } | |
676 | ||
677 | /* additional initialization for ALC889 variants */ | |
678 | static void alc889_coef_init(struct hda_codec *codec) | |
679 | { | |
680 | unsigned int tmp; | |
681 | ||
682 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); | |
683 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); | |
684 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); | |
685 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010); | |
686 | } | |
687 | ||
688 | /* turn on/off EAPD control (only if available) */ | |
689 | static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on) | |
690 | { | |
691 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) | |
692 | return; | |
693 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) | |
694 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE, | |
695 | on ? 2 : 0); | |
696 | } | |
697 | ||
698 | /* turn on/off EAPD controls of the codec */ | |
699 | static void alc_auto_setup_eapd(struct hda_codec *codec, bool on) | |
700 | { | |
701 | /* We currently only handle front, HP */ | |
702 | static hda_nid_t pins[] = { | |
703 | 0x0f, 0x10, 0x14, 0x15, 0 | |
704 | }; | |
705 | hda_nid_t *p; | |
706 | for (p = pins; *p; p++) | |
707 | set_eapd(codec, *p, on); | |
708 | } | |
709 | ||
710 | /* generic shutup callback; | |
711 | * just turning off EPAD and a little pause for avoiding pop-noise | |
712 | */ | |
713 | static void alc_eapd_shutup(struct hda_codec *codec) | |
714 | { | |
715 | alc_auto_setup_eapd(codec, false); | |
716 | msleep(200); | |
717 | } | |
718 | ||
719 | /* generic EAPD initialization */ | |
720 | static void alc_auto_init_amp(struct hda_codec *codec, int type) | |
721 | { | |
722 | unsigned int tmp; | |
723 | ||
724 | alc_auto_setup_eapd(codec, true); | |
725 | switch (type) { | |
726 | case ALC_INIT_GPIO1: | |
727 | snd_hda_sequence_write(codec, alc_gpio1_init_verbs); | |
728 | break; | |
729 | case ALC_INIT_GPIO2: | |
730 | snd_hda_sequence_write(codec, alc_gpio2_init_verbs); | |
731 | break; | |
732 | case ALC_INIT_GPIO3: | |
733 | snd_hda_sequence_write(codec, alc_gpio3_init_verbs); | |
734 | break; | |
735 | case ALC_INIT_DEFAULT: | |
736 | switch (codec->vendor_id) { | |
737 | case 0x10ec0260: | |
738 | snd_hda_codec_write(codec, 0x1a, 0, | |
739 | AC_VERB_SET_COEF_INDEX, 7); | |
740 | tmp = snd_hda_codec_read(codec, 0x1a, 0, | |
741 | AC_VERB_GET_PROC_COEF, 0); | |
742 | snd_hda_codec_write(codec, 0x1a, 0, | |
743 | AC_VERB_SET_COEF_INDEX, 7); | |
744 | snd_hda_codec_write(codec, 0x1a, 0, | |
745 | AC_VERB_SET_PROC_COEF, | |
746 | tmp | 0x2010); | |
747 | break; | |
748 | case 0x10ec0262: | |
749 | case 0x10ec0880: | |
750 | case 0x10ec0882: | |
751 | case 0x10ec0883: | |
752 | case 0x10ec0885: | |
753 | case 0x10ec0887: | |
754 | /*case 0x10ec0889:*/ /* this causes an SPDIF problem */ | |
755 | alc889_coef_init(codec); | |
756 | break; | |
757 | case 0x10ec0888: | |
758 | alc888_coef_init(codec); | |
759 | break; | |
760 | #if 0 /* XXX: This may cause the silent output on speaker on some machines */ | |
761 | case 0x10ec0267: | |
762 | case 0x10ec0268: | |
763 | snd_hda_codec_write(codec, 0x20, 0, | |
764 | AC_VERB_SET_COEF_INDEX, 7); | |
765 | tmp = snd_hda_codec_read(codec, 0x20, 0, | |
766 | AC_VERB_GET_PROC_COEF, 0); | |
767 | snd_hda_codec_write(codec, 0x20, 0, | |
768 | AC_VERB_SET_COEF_INDEX, 7); | |
769 | snd_hda_codec_write(codec, 0x20, 0, | |
770 | AC_VERB_SET_PROC_COEF, | |
771 | tmp | 0x3000); | |
772 | break; | |
773 | #endif /* XXX */ | |
774 | } | |
775 | break; | |
776 | } | |
777 | } | |
778 | ||
779 | /* | |
780 | * Auto-Mute mode mixer enum support | |
781 | */ | |
782 | static int alc_automute_mode_info(struct snd_kcontrol *kcontrol, | |
783 | struct snd_ctl_elem_info *uinfo) | |
784 | { | |
785 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
786 | struct alc_spec *spec = codec->spec; | |
787 | static const char * const texts3[] = { | |
788 | "Disabled", "Speaker Only", "Line Out+Speaker" | |
789 | }; | |
790 | ||
791 | if (spec->automute_speaker_possible && spec->automute_lo_possible) | |
792 | return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3); | |
793 | return snd_hda_enum_bool_helper_info(kcontrol, uinfo); | |
794 | } | |
795 | ||
796 | static int alc_automute_mode_get(struct snd_kcontrol *kcontrol, | |
797 | struct snd_ctl_elem_value *ucontrol) | |
798 | { | |
799 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
800 | struct alc_spec *spec = codec->spec; | |
801 | unsigned int val = 0; | |
802 | if (spec->automute_speaker) | |
803 | val++; | |
804 | if (spec->automute_lo) | |
805 | val++; | |
806 | ||
807 | ucontrol->value.enumerated.item[0] = val; | |
808 | return 0; | |
809 | } | |
810 | ||
811 | static int alc_automute_mode_put(struct snd_kcontrol *kcontrol, | |
812 | struct snd_ctl_elem_value *ucontrol) | |
813 | { | |
814 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
815 | struct alc_spec *spec = codec->spec; | |
816 | ||
817 | switch (ucontrol->value.enumerated.item[0]) { | |
818 | case 0: | |
819 | if (!spec->automute_speaker && !spec->automute_lo) | |
820 | return 0; | |
821 | spec->automute_speaker = 0; | |
822 | spec->automute_lo = 0; | |
823 | break; | |
824 | case 1: | |
825 | if (spec->automute_speaker_possible) { | |
826 | if (!spec->automute_lo && spec->automute_speaker) | |
827 | return 0; | |
828 | spec->automute_speaker = 1; | |
829 | spec->automute_lo = 0; | |
830 | } else if (spec->automute_lo_possible) { | |
831 | if (spec->automute_lo) | |
832 | return 0; | |
833 | spec->automute_lo = 1; | |
834 | } else | |
835 | return -EINVAL; | |
836 | break; | |
837 | case 2: | |
838 | if (!spec->automute_lo_possible || !spec->automute_speaker_possible) | |
839 | return -EINVAL; | |
840 | if (spec->automute_speaker && spec->automute_lo) | |
841 | return 0; | |
842 | spec->automute_speaker = 1; | |
843 | spec->automute_lo = 1; | |
844 | break; | |
845 | default: | |
846 | return -EINVAL; | |
847 | } | |
848 | call_update_outputs(codec); | |
849 | return 1; | |
850 | } | |
851 | ||
852 | static const struct snd_kcontrol_new alc_automute_mode_enum = { | |
853 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
854 | .name = "Auto-Mute Mode", | |
855 | .info = alc_automute_mode_info, | |
856 | .get = alc_automute_mode_get, | |
857 | .put = alc_automute_mode_put, | |
858 | }; | |
859 | ||
860 | static struct snd_kcontrol_new * | |
861 | alc_kcontrol_new(struct alc_spec *spec, const char *name, | |
862 | const struct snd_kcontrol_new *temp) | |
863 | { | |
864 | struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls); | |
865 | if (!knew) | |
866 | return NULL; | |
867 | *knew = *temp; | |
868 | if (name) | |
869 | knew->name = kstrdup(name, GFP_KERNEL); | |
870 | else if (knew->name) | |
871 | knew->name = kstrdup(knew->name, GFP_KERNEL); | |
872 | if (!knew->name) | |
873 | return NULL; | |
874 | return knew; | |
875 | } | |
876 | ||
877 | static int alc_add_automute_mode_enum(struct hda_codec *codec) | |
878 | { | |
879 | struct alc_spec *spec = codec->spec; | |
880 | ||
881 | if (!alc_kcontrol_new(spec, NULL, &alc_automute_mode_enum)) | |
882 | return -ENOMEM; | |
883 | return 0; | |
884 | } | |
885 | ||
886 | /* | |
887 | * Check the availability of HP/line-out auto-mute; | |
888 | * Set up appropriately if really supported | |
889 | */ | |
890 | static int alc_init_automute(struct hda_codec *codec) | |
891 | { | |
892 | struct alc_spec *spec = codec->spec; | |
893 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
894 | int present = 0; | |
895 | int i, err; | |
896 | ||
897 | if (cfg->hp_pins[0]) | |
898 | present++; | |
899 | if (cfg->line_out_pins[0]) | |
900 | present++; | |
901 | if (cfg->speaker_pins[0]) | |
902 | present++; | |
903 | if (present < 2) /* need two different output types */ | |
904 | return 0; | |
905 | ||
906 | if (!cfg->speaker_pins[0] && | |
907 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { | |
908 | memcpy(cfg->speaker_pins, cfg->line_out_pins, | |
909 | sizeof(cfg->speaker_pins)); | |
910 | cfg->speaker_outs = cfg->line_outs; | |
911 | } | |
912 | ||
913 | if (!cfg->hp_pins[0] && | |
914 | cfg->line_out_type == AUTO_PIN_HP_OUT) { | |
915 | memcpy(cfg->hp_pins, cfg->line_out_pins, | |
916 | sizeof(cfg->hp_pins)); | |
917 | cfg->hp_outs = cfg->line_outs; | |
918 | } | |
919 | ||
920 | for (i = 0; i < cfg->hp_outs; i++) { | |
921 | hda_nid_t nid = cfg->hp_pins[i]; | |
922 | if (!is_jack_detectable(codec, nid)) | |
923 | continue; | |
924 | snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n", | |
925 | nid); | |
926 | snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT, | |
927 | alc_hp_automute); | |
928 | spec->detect_hp = 1; | |
929 | } | |
930 | ||
931 | if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) { | |
932 | if (cfg->speaker_outs) | |
933 | for (i = 0; i < cfg->line_outs; i++) { | |
934 | hda_nid_t nid = cfg->line_out_pins[i]; | |
935 | if (!is_jack_detectable(codec, nid)) | |
936 | continue; | |
937 | snd_printdd("realtek: Enable Line-Out " | |
938 | "auto-muting on NID 0x%x\n", nid); | |
939 | snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT, | |
940 | alc_line_automute); | |
941 | spec->detect_lo = 1; | |
942 | } | |
943 | spec->automute_lo_possible = spec->detect_hp; | |
944 | } | |
945 | ||
946 | spec->automute_speaker_possible = cfg->speaker_outs && | |
947 | (spec->detect_hp || spec->detect_lo); | |
948 | ||
949 | spec->automute_lo = spec->automute_lo_possible; | |
950 | spec->automute_speaker = spec->automute_speaker_possible; | |
951 | ||
952 | if (spec->automute_speaker_possible || spec->automute_lo_possible) { | |
953 | /* create a control for automute mode */ | |
954 | err = alc_add_automute_mode_enum(codec); | |
955 | if (err < 0) | |
956 | return err; | |
957 | } | |
958 | return 0; | |
959 | } | |
960 | ||
961 | /* return the position of NID in the list, or -1 if not found */ | |
962 | static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) | |
963 | { | |
964 | int i; | |
965 | for (i = 0; i < nums; i++) | |
966 | if (list[i] == nid) | |
967 | return i; | |
968 | return -1; | |
969 | } | |
970 | ||
971 | /* check whether all auto-mic pins are valid; setup indices if OK */ | |
972 | static bool alc_auto_mic_check_imux(struct hda_codec *codec) | |
973 | { | |
974 | struct alc_spec *spec = codec->spec; | |
975 | const struct hda_input_mux *imux; | |
976 | ||
977 | imux = &spec->input_mux; | |
978 | spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin, | |
979 | spec->imux_pins, imux->num_items); | |
980 | spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin, | |
981 | spec->imux_pins, imux->num_items); | |
982 | spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin, | |
983 | spec->imux_pins, imux->num_items); | |
984 | if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) | |
985 | return false; /* no corresponding imux */ | |
986 | ||
987 | snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin, | |
988 | ALC_MIC_EVENT, alc_mic_automute); | |
989 | if (spec->dock_mic_pin) | |
990 | snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin, | |
991 | ALC_MIC_EVENT, | |
992 | alc_mic_automute); | |
993 | return true; | |
994 | } | |
995 | ||
996 | /* | |
997 | * Check the availability of auto-mic switch; | |
998 | * Set up if really supported | |
999 | */ | |
1000 | static int alc_init_auto_mic(struct hda_codec *codec) | |
1001 | { | |
1002 | struct alc_spec *spec = codec->spec; | |
1003 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
1004 | hda_nid_t fixed, ext, dock; | |
1005 | int i; | |
1006 | ||
1007 | spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1; | |
1008 | ||
1009 | fixed = ext = dock = 0; | |
1010 | for (i = 0; i < cfg->num_inputs; i++) { | |
1011 | hda_nid_t nid = cfg->inputs[i].pin; | |
1012 | unsigned int defcfg; | |
1013 | defcfg = snd_hda_codec_get_pincfg(codec, nid); | |
1014 | switch (snd_hda_get_input_pin_attr(defcfg)) { | |
1015 | case INPUT_PIN_ATTR_INT: | |
1016 | if (fixed) | |
1017 | return 0; /* already occupied */ | |
1018 | if (cfg->inputs[i].type != AUTO_PIN_MIC) | |
1019 | return 0; /* invalid type */ | |
1020 | fixed = nid; | |
1021 | break; | |
1022 | case INPUT_PIN_ATTR_UNUSED: | |
1023 | return 0; /* invalid entry */ | |
1024 | case INPUT_PIN_ATTR_DOCK: | |
1025 | if (dock) | |
1026 | return 0; /* already occupied */ | |
1027 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) | |
1028 | return 0; /* invalid type */ | |
1029 | dock = nid; | |
1030 | break; | |
1031 | default: | |
1032 | if (ext) | |
1033 | return 0; /* already occupied */ | |
1034 | if (cfg->inputs[i].type != AUTO_PIN_MIC) | |
1035 | return 0; /* invalid type */ | |
1036 | ext = nid; | |
1037 | break; | |
1038 | } | |
1039 | } | |
1040 | if (!ext && dock) { | |
1041 | ext = dock; | |
1042 | dock = 0; | |
1043 | } | |
1044 | if (!ext || !fixed) | |
1045 | return 0; | |
1046 | if (!is_jack_detectable(codec, ext)) | |
1047 | return 0; /* no unsol support */ | |
1048 | if (dock && !is_jack_detectable(codec, dock)) | |
1049 | return 0; /* no unsol support */ | |
1050 | ||
1051 | /* check imux indices */ | |
1052 | spec->ext_mic_pin = ext; | |
1053 | spec->int_mic_pin = fixed; | |
1054 | spec->dock_mic_pin = dock; | |
1055 | ||
1056 | if (!alc_auto_mic_check_imux(codec)) | |
1057 | return 0; | |
1058 | ||
1059 | spec->auto_mic = 1; | |
1060 | spec->num_adc_nids = 1; | |
1061 | spec->cur_mux[0] = spec->int_mic_idx; | |
1062 | snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n", | |
1063 | ext, fixed, dock); | |
1064 | ||
1065 | return 0; | |
1066 | } | |
1067 | ||
1068 | /* | |
1069 | * Realtek SSID verification | |
1070 | */ | |
1071 | ||
1072 | /* Could be any non-zero and even value. When used as fixup, tells | |
1073 | * the driver to ignore any present sku defines. | |
1074 | */ | |
1075 | #define ALC_FIXUP_SKU_IGNORE (2) | |
1076 | ||
1077 | static void alc_fixup_sku_ignore(struct hda_codec *codec, | |
1078 | const struct hda_fixup *fix, int action) | |
1079 | { | |
1080 | struct alc_spec *spec = codec->spec; | |
1081 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { | |
1082 | spec->cdefine.fixup = 1; | |
1083 | spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE; | |
1084 | } | |
1085 | } | |
1086 | ||
1087 | static int alc_auto_parse_customize_define(struct hda_codec *codec) | |
1088 | { | |
1089 | unsigned int ass, tmp, i; | |
1090 | unsigned nid = 0; | |
1091 | struct alc_spec *spec = codec->spec; | |
1092 | ||
1093 | spec->cdefine.enable_pcbeep = 1; /* assume always enabled */ | |
1094 | ||
1095 | if (spec->cdefine.fixup) { | |
1096 | ass = spec->cdefine.sku_cfg; | |
1097 | if (ass == ALC_FIXUP_SKU_IGNORE) | |
1098 | return -1; | |
1099 | goto do_sku; | |
1100 | } | |
1101 | ||
1102 | ass = codec->subsystem_id & 0xffff; | |
1103 | if (ass != codec->bus->pci->subsystem_device && (ass & 1)) | |
1104 | goto do_sku; | |
1105 | ||
1106 | nid = 0x1d; | |
1107 | if (codec->vendor_id == 0x10ec0260) | |
1108 | nid = 0x17; | |
1109 | ass = snd_hda_codec_get_pincfg(codec, nid); | |
1110 | ||
1111 | if (!(ass & 1)) { | |
1112 | printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n", | |
1113 | codec->chip_name, ass); | |
1114 | return -1; | |
1115 | } | |
1116 | ||
1117 | /* check sum */ | |
1118 | tmp = 0; | |
1119 | for (i = 1; i < 16; i++) { | |
1120 | if ((ass >> i) & 1) | |
1121 | tmp++; | |
1122 | } | |
1123 | if (((ass >> 16) & 0xf) != tmp) | |
1124 | return -1; | |
1125 | ||
1126 | spec->cdefine.port_connectivity = ass >> 30; | |
1127 | spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20; | |
1128 | spec->cdefine.check_sum = (ass >> 16) & 0xf; | |
1129 | spec->cdefine.customization = ass >> 8; | |
1130 | do_sku: | |
1131 | spec->cdefine.sku_cfg = ass; | |
1132 | spec->cdefine.external_amp = (ass & 0x38) >> 3; | |
1133 | spec->cdefine.platform_type = (ass & 0x4) >> 2; | |
1134 | spec->cdefine.swap = (ass & 0x2) >> 1; | |
1135 | spec->cdefine.override = ass & 0x1; | |
1136 | ||
1137 | snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n", | |
1138 | nid, spec->cdefine.sku_cfg); | |
1139 | snd_printd("SKU: port_connectivity=0x%x\n", | |
1140 | spec->cdefine.port_connectivity); | |
1141 | snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep); | |
1142 | snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum); | |
1143 | snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization); | |
1144 | snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp); | |
1145 | snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type); | |
1146 | snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap); | |
1147 | snd_printd("SKU: override=0x%x\n", spec->cdefine.override); | |
1148 | ||
1149 | return 0; | |
1150 | } | |
1151 | ||
1152 | /* return true if the given NID is found in the list */ | |
1153 | static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) | |
1154 | { | |
1155 | return find_idx_in_nid_list(nid, list, nums) >= 0; | |
1156 | } | |
1157 | ||
1158 | /* check subsystem ID and set up device-specific initialization; | |
1159 | * return 1 if initialized, 0 if invalid SSID | |
1160 | */ | |
1161 | /* 32-bit subsystem ID for BIOS loading in HD Audio codec. | |
1162 | * 31 ~ 16 : Manufacture ID | |
1163 | * 15 ~ 8 : SKU ID | |
1164 | * 7 ~ 0 : Assembly ID | |
1165 | * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36 | |
1166 | */ | |
1167 | static int alc_subsystem_id(struct hda_codec *codec, | |
1168 | hda_nid_t porta, hda_nid_t porte, | |
1169 | hda_nid_t portd, hda_nid_t porti) | |
1170 | { | |
1171 | unsigned int ass, tmp, i; | |
1172 | unsigned nid; | |
1173 | struct alc_spec *spec = codec->spec; | |
1174 | ||
1175 | if (spec->cdefine.fixup) { | |
1176 | ass = spec->cdefine.sku_cfg; | |
1177 | if (ass == ALC_FIXUP_SKU_IGNORE) | |
1178 | return 0; | |
1179 | goto do_sku; | |
1180 | } | |
1181 | ||
1182 | ass = codec->subsystem_id & 0xffff; | |
1183 | if ((ass != codec->bus->pci->subsystem_device) && (ass & 1)) | |
1184 | goto do_sku; | |
1185 | ||
1186 | /* invalid SSID, check the special NID pin defcfg instead */ | |
1187 | /* | |
1188 | * 31~30 : port connectivity | |
1189 | * 29~21 : reserve | |
1190 | * 20 : PCBEEP input | |
1191 | * 19~16 : Check sum (15:1) | |
1192 | * 15~1 : Custom | |
1193 | * 0 : override | |
1194 | */ | |
1195 | nid = 0x1d; | |
1196 | if (codec->vendor_id == 0x10ec0260) | |
1197 | nid = 0x17; | |
1198 | ass = snd_hda_codec_get_pincfg(codec, nid); | |
1199 | snd_printd("realtek: No valid SSID, " | |
1200 | "checking pincfg 0x%08x for NID 0x%x\n", | |
1201 | ass, nid); | |
1202 | if (!(ass & 1)) | |
1203 | return 0; | |
1204 | if ((ass >> 30) != 1) /* no physical connection */ | |
1205 | return 0; | |
1206 | ||
1207 | /* check sum */ | |
1208 | tmp = 0; | |
1209 | for (i = 1; i < 16; i++) { | |
1210 | if ((ass >> i) & 1) | |
1211 | tmp++; | |
1212 | } | |
1213 | if (((ass >> 16) & 0xf) != tmp) | |
1214 | return 0; | |
1215 | do_sku: | |
1216 | snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n", | |
1217 | ass & 0xffff, codec->vendor_id); | |
1218 | /* | |
1219 | * 0 : override | |
1220 | * 1 : Swap Jack | |
1221 | * 2 : 0 --> Desktop, 1 --> Laptop | |
1222 | * 3~5 : External Amplifier control | |
1223 | * 7~6 : Reserved | |
1224 | */ | |
1225 | tmp = (ass & 0x38) >> 3; /* external Amp control */ | |
1226 | switch (tmp) { | |
1227 | case 1: | |
1228 | spec->init_amp = ALC_INIT_GPIO1; | |
1229 | break; | |
1230 | case 3: | |
1231 | spec->init_amp = ALC_INIT_GPIO2; | |
1232 | break; | |
1233 | case 7: | |
1234 | spec->init_amp = ALC_INIT_GPIO3; | |
1235 | break; | |
1236 | case 5: | |
1237 | default: | |
1238 | spec->init_amp = ALC_INIT_DEFAULT; | |
1239 | break; | |
1240 | } | |
1241 | ||
1242 | /* is laptop or Desktop and enable the function "Mute internal speaker | |
1243 | * when the external headphone out jack is plugged" | |
1244 | */ | |
1245 | if (!(ass & 0x8000)) | |
1246 | return 1; | |
1247 | /* | |
1248 | * 10~8 : Jack location | |
1249 | * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered | |
1250 | * 14~13: Resvered | |
1251 | * 15 : 1 --> enable the function "Mute internal speaker | |
1252 | * when the external headphone out jack is plugged" | |
1253 | */ | |
1254 | if (!spec->autocfg.hp_pins[0] && | |
1255 | !(spec->autocfg.line_out_pins[0] && | |
1256 | spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) { | |
1257 | hda_nid_t nid; | |
1258 | tmp = (ass >> 11) & 0x3; /* HP to chassis */ | |
1259 | if (tmp == 0) | |
1260 | nid = porta; | |
1261 | else if (tmp == 1) | |
1262 | nid = porte; | |
1263 | else if (tmp == 2) | |
1264 | nid = portd; | |
1265 | else if (tmp == 3) | |
1266 | nid = porti; | |
1267 | else | |
1268 | return 1; | |
1269 | if (found_in_nid_list(nid, spec->autocfg.line_out_pins, | |
1270 | spec->autocfg.line_outs)) | |
1271 | return 1; | |
1272 | spec->autocfg.hp_pins[0] = nid; | |
1273 | } | |
1274 | return 1; | |
1275 | } | |
1276 | ||
1277 | /* Check the validity of ALC subsystem-id | |
1278 | * ports contains an array of 4 pin NIDs for port-A, E, D and I */ | |
1279 | static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports) | |
1280 | { | |
1281 | if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) { | |
1282 | struct alc_spec *spec = codec->spec; | |
1283 | snd_printd("realtek: " | |
1284 | "Enable default setup for auto mode as fallback\n"); | |
1285 | spec->init_amp = ALC_INIT_DEFAULT; | |
1286 | } | |
1287 | } | |
1288 | ||
1289 | /* | |
1290 | * COEF access helper functions | |
1291 | */ | |
1292 | static int alc_read_coef_idx(struct hda_codec *codec, | |
1293 | unsigned int coef_idx) | |
1294 | { | |
1295 | unsigned int val; | |
1296 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, | |
1297 | coef_idx); | |
1298 | val = snd_hda_codec_read(codec, 0x20, 0, | |
1299 | AC_VERB_GET_PROC_COEF, 0); | |
1300 | return val; | |
1301 | } | |
1302 | ||
1303 | static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx, | |
1304 | unsigned int coef_val) | |
1305 | { | |
1306 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, | |
1307 | coef_idx); | |
1308 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, | |
1309 | coef_val); | |
1310 | } | |
1311 | ||
1312 | /* a special bypass for COEF 0; read the cached value at the second time */ | |
1313 | static unsigned int alc_get_coef0(struct hda_codec *codec) | |
1314 | { | |
1315 | struct alc_spec *spec = codec->spec; | |
1316 | if (!spec->coef0) | |
1317 | spec->coef0 = alc_read_coef_idx(codec, 0); | |
1318 | return spec->coef0; | |
1319 | } | |
1320 | ||
1321 | static void alc_auto_set_output_and_unmute(struct hda_codec *codec, | |
1322 | hda_nid_t pin, int pin_type, | |
1323 | hda_nid_t dac); | |
1324 | static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin, | |
1325 | bool is_digital); | |
1326 | static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid, | |
1327 | hda_nid_t to_nid, int with_aa_mix, | |
1328 | struct nid_path *path); | |
1329 | static struct nid_path *add_new_nid_path(struct hda_codec *codec, | |
1330 | hda_nid_t from_nid, hda_nid_t to_nid, | |
1331 | int with_aa_mix); | |
1332 | ||
1333 | /* | |
1334 | * Digital I/O handling | |
1335 | */ | |
1336 | ||
1337 | /* set right pin controls for digital I/O */ | |
1338 | static void alc_auto_init_digital(struct hda_codec *codec) | |
1339 | { | |
1340 | struct alc_spec *spec = codec->spec; | |
1341 | int i; | |
1342 | hda_nid_t pin; | |
1343 | ||
1344 | for (i = 0; i < spec->autocfg.dig_outs; i++) { | |
1345 | pin = spec->autocfg.dig_out_pins[i]; | |
1346 | if (!pin) | |
1347 | continue; | |
1348 | alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0); | |
1349 | } | |
1350 | pin = spec->autocfg.dig_in_pin; | |
1351 | if (pin) | |
1352 | snd_hda_set_pin_ctl(codec, pin, PIN_IN); | |
1353 | } | |
1354 | ||
1355 | /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */ | |
1356 | static void alc_auto_parse_digital(struct hda_codec *codec) | |
1357 | { | |
1358 | struct alc_spec *spec = codec->spec; | |
1359 | int i, nums; | |
1360 | hda_nid_t dig_nid; | |
1361 | ||
1362 | /* support multiple SPDIFs; the secondary is set up as a slave */ | |
1363 | nums = 0; | |
1364 | for (i = 0; i < spec->autocfg.dig_outs; i++) { | |
1365 | hda_nid_t pin = spec->autocfg.dig_out_pins[i]; | |
1366 | dig_nid = alc_auto_look_for_dac(codec, pin, true); | |
1367 | if (!dig_nid) | |
1368 | continue; | |
1369 | if (!add_new_nid_path(codec, dig_nid, pin, 2)) | |
1370 | continue; | |
1371 | if (!nums) { | |
1372 | spec->multiout.dig_out_nid = dig_nid; | |
1373 | spec->dig_out_type = spec->autocfg.dig_out_type[0]; | |
1374 | } else { | |
1375 | spec->multiout.slave_dig_outs = spec->slave_dig_outs; | |
1376 | if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1) | |
1377 | break; | |
1378 | spec->slave_dig_outs[nums - 1] = dig_nid; | |
1379 | } | |
1380 | nums++; | |
1381 | } | |
1382 | ||
1383 | if (spec->autocfg.dig_in_pin) { | |
1384 | dig_nid = codec->start_nid; | |
1385 | for (i = 0; i < codec->num_nodes; i++, dig_nid++) { | |
1386 | struct nid_path *path; | |
1387 | unsigned int wcaps = get_wcaps(codec, dig_nid); | |
1388 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) | |
1389 | continue; | |
1390 | if (!(wcaps & AC_WCAP_DIGITAL)) | |
1391 | continue; | |
1392 | path = add_new_nid_path(codec, spec->autocfg.dig_in_pin, | |
1393 | dig_nid, 2); | |
1394 | if (path) { | |
1395 | path->active = true; | |
1396 | spec->dig_in_nid = dig_nid; | |
1397 | break; | |
1398 | } | |
1399 | } | |
1400 | } | |
1401 | } | |
1402 | ||
1403 | /* | |
1404 | * capture mixer elements | |
1405 | */ | |
1406 | #define alc_cap_vol_info snd_hda_mixer_amp_volume_info | |
1407 | #define alc_cap_vol_get snd_hda_mixer_amp_volume_get | |
1408 | #define alc_cap_vol_tlv snd_hda_mixer_amp_tlv | |
1409 | ||
1410 | typedef int (*put_call_t)(struct snd_kcontrol *kcontrol, | |
1411 | struct snd_ctl_elem_value *ucontrol); | |
1412 | ||
1413 | static int alc_cap_put_caller(struct snd_kcontrol *kcontrol, | |
1414 | struct snd_ctl_elem_value *ucontrol, | |
1415 | put_call_t func, int type) | |
1416 | { | |
1417 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1418 | struct alc_spec *spec = codec->spec; | |
1419 | const struct hda_input_mux *imux; | |
1420 | struct nid_path *path; | |
1421 | int i, adc_idx, err = 0; | |
1422 | ||
1423 | imux = &spec->input_mux; | |
1424 | adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
1425 | mutex_lock(&codec->control_mutex); | |
1426 | codec->cached_write = 1; | |
1427 | for (i = 0; i < imux->num_items; i++) { | |
1428 | path = get_nid_path(codec, spec->imux_pins[i], | |
1429 | get_adc_nid(codec, adc_idx, i)); | |
1430 | if (!path->ctls[type]) | |
1431 | continue; | |
1432 | kcontrol->private_value = path->ctls[type]; | |
1433 | err = func(kcontrol, ucontrol); | |
1434 | if (err < 0) | |
1435 | goto error; | |
1436 | } | |
1437 | error: | |
1438 | codec->cached_write = 0; | |
1439 | mutex_unlock(&codec->control_mutex); | |
1440 | snd_hda_codec_resume_amp(codec); | |
1441 | if (err >= 0 && type == NID_PATH_MUTE_CTL && | |
1442 | spec->inv_dmic_fixup && spec->inv_dmic_muted) | |
1443 | alc_inv_dmic_sync_adc(codec, adc_idx); | |
1444 | return err; | |
1445 | } | |
1446 | ||
1447 | static int alc_cap_vol_put(struct snd_kcontrol *kcontrol, | |
1448 | struct snd_ctl_elem_value *ucontrol) | |
1449 | { | |
1450 | return alc_cap_put_caller(kcontrol, ucontrol, | |
1451 | snd_hda_mixer_amp_volume_put, | |
1452 | NID_PATH_VOL_CTL); | |
1453 | } | |
1454 | ||
1455 | /* capture mixer elements */ | |
1456 | #define alc_cap_sw_info snd_ctl_boolean_stereo_info | |
1457 | #define alc_cap_sw_get snd_hda_mixer_amp_switch_get | |
1458 | ||
1459 | static int alc_cap_sw_put(struct snd_kcontrol *kcontrol, | |
1460 | struct snd_ctl_elem_value *ucontrol) | |
1461 | { | |
1462 | return alc_cap_put_caller(kcontrol, ucontrol, | |
1463 | snd_hda_mixer_amp_switch_put, | |
1464 | NID_PATH_MUTE_CTL); | |
1465 | } | |
1466 | ||
1467 | static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx) | |
1468 | { | |
1469 | struct alc_spec *spec = codec->spec; | |
1470 | struct hda_input_mux *imux = &spec->input_mux; | |
1471 | struct nid_path *path; | |
1472 | hda_nid_t nid; | |
1473 | int i, dir, parm; | |
1474 | unsigned int val; | |
1475 | ||
1476 | for (i = 0; i < imux->num_items; i++) { | |
1477 | if (spec->imux_pins[i] == spec->inv_dmic_pin) | |
1478 | break; | |
1479 | } | |
1480 | if (i >= imux->num_items) | |
1481 | return; | |
1482 | ||
1483 | path = get_nid_path(codec, spec->inv_dmic_pin, | |
1484 | get_adc_nid(codec, adc_idx, i)); | |
1485 | val = path->ctls[NID_PATH_MUTE_CTL]; | |
1486 | if (!val) | |
1487 | return; | |
1488 | nid = get_amp_nid_(val); | |
1489 | dir = get_amp_direction_(val); | |
1490 | parm = AC_AMP_SET_RIGHT | | |
1491 | (dir == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT); | |
1492 | ||
1493 | /* we care only right channel */ | |
1494 | val = snd_hda_codec_amp_read(codec, nid, 1, dir, 0); | |
1495 | if (val & 0x80) /* if already muted, we don't need to touch */ | |
1496 | return; | |
1497 | val |= 0x80; | |
1498 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, | |
1499 | parm | val); | |
1500 | } | |
1501 | ||
1502 | /* | |
1503 | * Inverted digital-mic handling | |
1504 | * | |
1505 | * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch" | |
1506 | * gives the additional mute only to the right channel of the digital mic | |
1507 | * capture stream. This is a workaround for avoiding the almost silence | |
1508 | * by summing the stereo stream from some (known to be ForteMedia) | |
1509 | * digital mic unit. | |
1510 | * | |
1511 | * The logic is to call alc_inv_dmic_sync() after each action (possibly) | |
1512 | * modifying ADC amp. When the mute flag is set, it mutes the R-channel | |
1513 | * without caching so that the cache can still keep the original value. | |
1514 | * The cached value is then restored when the flag is set off or any other | |
1515 | * than d-mic is used as the current input source. | |
1516 | */ | |
1517 | static void alc_inv_dmic_sync(struct hda_codec *codec, bool force) | |
1518 | { | |
1519 | struct alc_spec *spec = codec->spec; | |
1520 | int src, nums; | |
1521 | ||
1522 | if (!spec->inv_dmic_fixup) | |
1523 | return; | |
1524 | if (!spec->inv_dmic_muted && !force) | |
1525 | return; | |
1526 | nums = spec->dyn_adc_switch ? 1 : spec->num_adc_nids; | |
1527 | for (src = 0; src < nums; src++) { | |
1528 | bool dmic_fixup = false; | |
1529 | ||
1530 | if (spec->inv_dmic_muted && | |
1531 | spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin) | |
1532 | dmic_fixup = true; | |
1533 | if (!dmic_fixup && !force) | |
1534 | continue; | |
1535 | alc_inv_dmic_sync_adc(codec, src); | |
1536 | } | |
1537 | } | |
1538 | ||
1539 | static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol, | |
1540 | struct snd_ctl_elem_value *ucontrol) | |
1541 | { | |
1542 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1543 | struct alc_spec *spec = codec->spec; | |
1544 | ||
1545 | ucontrol->value.integer.value[0] = !spec->inv_dmic_muted; | |
1546 | return 0; | |
1547 | } | |
1548 | ||
1549 | static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol, | |
1550 | struct snd_ctl_elem_value *ucontrol) | |
1551 | { | |
1552 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1553 | struct alc_spec *spec = codec->spec; | |
1554 | unsigned int val = !ucontrol->value.integer.value[0]; | |
1555 | ||
1556 | if (val == spec->inv_dmic_muted) | |
1557 | return 0; | |
1558 | spec->inv_dmic_muted = val; | |
1559 | alc_inv_dmic_sync(codec, true); | |
1560 | return 0; | |
1561 | } | |
1562 | ||
1563 | static const struct snd_kcontrol_new alc_inv_dmic_sw = { | |
1564 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1565 | .name = "Inverted Internal Mic Capture Switch", | |
1566 | .info = snd_ctl_boolean_mono_info, | |
1567 | .get = alc_inv_dmic_sw_get, | |
1568 | .put = alc_inv_dmic_sw_put, | |
1569 | }; | |
1570 | ||
1571 | static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid) | |
1572 | { | |
1573 | struct alc_spec *spec = codec->spec; | |
1574 | ||
1575 | if (!alc_kcontrol_new(spec, NULL, &alc_inv_dmic_sw)) | |
1576 | return -ENOMEM; | |
1577 | spec->inv_dmic_fixup = 1; | |
1578 | spec->inv_dmic_muted = 0; | |
1579 | spec->inv_dmic_pin = nid; | |
1580 | return 0; | |
1581 | } | |
1582 | ||
1583 | /* typically the digital mic is put at node 0x12 */ | |
1584 | static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec, | |
1585 | const struct alc_fixup *fix, int action) | |
1586 | { | |
1587 | if (action == ALC_FIXUP_ACT_PROBE) | |
1588 | alc_add_inv_dmic_mixer(codec, 0x12); | |
1589 | } | |
1590 | ||
1591 | /* | |
1592 | * virtual master controls | |
1593 | */ | |
1594 | ||
1595 | /* | |
1596 | * slave controls for virtual master | |
1597 | */ | |
1598 | static const char * const alc_slave_pfxs[] = { | |
1599 | "Front", "Surround", "Center", "LFE", "Side", | |
1600 | "Headphone", "Speaker", "Mono", "Line Out", | |
1601 | "CLFE", "Bass Speaker", "PCM", | |
1602 | NULL, | |
1603 | }; | |
1604 | ||
1605 | /* | |
1606 | * build control elements | |
1607 | */ | |
1608 | ||
1609 | static void alc_free_kctls(struct hda_codec *codec); | |
1610 | ||
1611 | #ifdef CONFIG_SND_HDA_INPUT_BEEP | |
1612 | /* additional beep mixers; the actual parameters are overwritten at build */ | |
1613 | static const struct snd_kcontrol_new alc_beep_mixer[] = { | |
1614 | HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT), | |
1615 | HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT), | |
1616 | { } /* end */ | |
1617 | }; | |
1618 | #endif | |
1619 | ||
1620 | static int alc_build_controls(struct hda_codec *codec) | |
1621 | { | |
1622 | struct alc_spec *spec = codec->spec; | |
1623 | int i, err; | |
1624 | ||
1625 | for (i = 0; i < spec->num_mixers; i++) { | |
1626 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | |
1627 | if (err < 0) | |
1628 | return err; | |
1629 | } | |
1630 | if (spec->multiout.dig_out_nid) { | |
1631 | err = snd_hda_create_dig_out_ctls(codec, | |
1632 | spec->multiout.dig_out_nid, | |
1633 | spec->multiout.dig_out_nid, | |
1634 | spec->pcm_rec[1].pcm_type); | |
1635 | if (err < 0) | |
1636 | return err; | |
1637 | if (!spec->no_analog) { | |
1638 | err = snd_hda_create_spdif_share_sw(codec, | |
1639 | &spec->multiout); | |
1640 | if (err < 0) | |
1641 | return err; | |
1642 | spec->multiout.share_spdif = 1; | |
1643 | } | |
1644 | } | |
1645 | if (spec->dig_in_nid) { | |
1646 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); | |
1647 | if (err < 0) | |
1648 | return err; | |
1649 | } | |
1650 | ||
1651 | #ifdef CONFIG_SND_HDA_INPUT_BEEP | |
1652 | /* create beep controls if needed */ | |
1653 | if (spec->beep_amp) { | |
1654 | const struct snd_kcontrol_new *knew; | |
1655 | for (knew = alc_beep_mixer; knew->name; knew++) { | |
1656 | struct snd_kcontrol *kctl; | |
1657 | kctl = snd_ctl_new1(knew, codec); | |
1658 | if (!kctl) | |
1659 | return -ENOMEM; | |
1660 | kctl->private_value = spec->beep_amp; | |
1661 | err = snd_hda_ctl_add(codec, 0, kctl); | |
1662 | if (err < 0) | |
1663 | return err; | |
1664 | } | |
1665 | } | |
1666 | #endif | |
1667 | ||
1668 | /* if we have no master control, let's create it */ | |
1669 | if (!spec->no_analog && | |
1670 | !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { | |
1671 | unsigned int vmaster_tlv[4]; | |
1672 | snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, | |
1673 | HDA_OUTPUT, vmaster_tlv); | |
1674 | err = snd_hda_add_vmaster(codec, "Master Playback Volume", | |
1675 | vmaster_tlv, alc_slave_pfxs, | |
1676 | "Playback Volume"); | |
1677 | if (err < 0) | |
1678 | return err; | |
1679 | } | |
1680 | if (!spec->no_analog && | |
1681 | !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { | |
1682 | err = __snd_hda_add_vmaster(codec, "Master Playback Switch", | |
1683 | NULL, alc_slave_pfxs, | |
1684 | "Playback Switch", | |
1685 | true, &spec->vmaster_mute.sw_kctl); | |
1686 | if (err < 0) | |
1687 | return err; | |
1688 | if (spec->vmaster_mute.hook) | |
1689 | snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true); | |
1690 | } | |
1691 | ||
1692 | alc_free_kctls(codec); /* no longer needed */ | |
1693 | ||
1694 | if (spec->shared_mic_hp) { | |
1695 | int err; | |
1696 | int nid = spec->autocfg.inputs[1].pin; | |
1697 | err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0); | |
1698 | if (err < 0) | |
1699 | return err; | |
1700 | err = snd_hda_jack_detect_enable(codec, nid, 0); | |
1701 | if (err < 0) | |
1702 | return err; | |
1703 | } | |
1704 | ||
1705 | err = snd_hda_jack_add_kctls(codec, &spec->autocfg); | |
1706 | if (err < 0) | |
1707 | return err; | |
1708 | ||
1709 | alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD); | |
1710 | return 0; | |
1711 | } | |
1712 | ||
1713 | ||
1714 | /* | |
1715 | * Common callbacks | |
1716 | */ | |
1717 | ||
1718 | static void alc_auto_init_std(struct hda_codec *codec); | |
1719 | ||
1720 | static int alc_init(struct hda_codec *codec) | |
1721 | { | |
1722 | struct alc_spec *spec = codec->spec; | |
1723 | ||
1724 | if (spec->init_hook) | |
1725 | spec->init_hook(codec); | |
1726 | ||
1727 | alc_fix_pll(codec); | |
1728 | alc_auto_init_amp(codec, spec->init_amp); | |
1729 | ||
1730 | snd_hda_gen_apply_verbs(codec); | |
1731 | alc_auto_init_std(codec); | |
1732 | ||
1733 | if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook) | |
1734 | snd_hda_sync_vmaster_hook(&spec->vmaster_mute); | |
1735 | ||
1736 | alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT); | |
1737 | ||
1738 | hda_call_check_power_status(codec, 0x01); | |
1739 | return 0; | |
1740 | } | |
1741 | ||
1742 | #ifdef CONFIG_PM | |
1743 | static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid) | |
1744 | { | |
1745 | struct alc_spec *spec = codec->spec; | |
1746 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); | |
1747 | } | |
1748 | #endif | |
1749 | ||
1750 | /* | |
1751 | * Analog playback callbacks | |
1752 | */ | |
1753 | static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
1754 | struct hda_codec *codec, | |
1755 | struct snd_pcm_substream *substream) | |
1756 | { | |
1757 | struct alc_spec *spec = codec->spec; | |
1758 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, | |
1759 | hinfo); | |
1760 | } | |
1761 | ||
1762 | static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | |
1763 | struct hda_codec *codec, | |
1764 | unsigned int stream_tag, | |
1765 | unsigned int format, | |
1766 | struct snd_pcm_substream *substream) | |
1767 | { | |
1768 | struct alc_spec *spec = codec->spec; | |
1769 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, | |
1770 | stream_tag, format, substream); | |
1771 | } | |
1772 | ||
1773 | static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
1774 | struct hda_codec *codec, | |
1775 | struct snd_pcm_substream *substream) | |
1776 | { | |
1777 | struct alc_spec *spec = codec->spec; | |
1778 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | |
1779 | } | |
1780 | ||
1781 | /* | |
1782 | * Digital out | |
1783 | */ | |
1784 | static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
1785 | struct hda_codec *codec, | |
1786 | struct snd_pcm_substream *substream) | |
1787 | { | |
1788 | struct alc_spec *spec = codec->spec; | |
1789 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | |
1790 | } | |
1791 | ||
1792 | static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | |
1793 | struct hda_codec *codec, | |
1794 | unsigned int stream_tag, | |
1795 | unsigned int format, | |
1796 | struct snd_pcm_substream *substream) | |
1797 | { | |
1798 | struct alc_spec *spec = codec->spec; | |
1799 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, | |
1800 | stream_tag, format, substream); | |
1801 | } | |
1802 | ||
1803 | static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
1804 | struct hda_codec *codec, | |
1805 | struct snd_pcm_substream *substream) | |
1806 | { | |
1807 | struct alc_spec *spec = codec->spec; | |
1808 | return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); | |
1809 | } | |
1810 | ||
1811 | static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, | |
1812 | struct hda_codec *codec, | |
1813 | struct snd_pcm_substream *substream) | |
1814 | { | |
1815 | struct alc_spec *spec = codec->spec; | |
1816 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | |
1817 | } | |
1818 | ||
1819 | /* | |
1820 | * Analog capture | |
1821 | */ | |
1822 | static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | |
1823 | struct hda_codec *codec, | |
1824 | unsigned int stream_tag, | |
1825 | unsigned int format, | |
1826 | struct snd_pcm_substream *substream) | |
1827 | { | |
1828 | struct alc_spec *spec = codec->spec; | |
1829 | ||
1830 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1], | |
1831 | stream_tag, 0, format); | |
1832 | return 0; | |
1833 | } | |
1834 | ||
1835 | static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
1836 | struct hda_codec *codec, | |
1837 | struct snd_pcm_substream *substream) | |
1838 | { | |
1839 | struct alc_spec *spec = codec->spec; | |
1840 | ||
1841 | snd_hda_codec_cleanup_stream(codec, | |
1842 | spec->adc_nids[substream->number + 1]); | |
1843 | return 0; | |
1844 | } | |
1845 | ||
1846 | /* analog capture with dynamic dual-adc changes */ | |
1847 | static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | |
1848 | struct hda_codec *codec, | |
1849 | unsigned int stream_tag, | |
1850 | unsigned int format, | |
1851 | struct snd_pcm_substream *substream) | |
1852 | { | |
1853 | struct alc_spec *spec = codec->spec; | |
1854 | spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]]; | |
1855 | spec->cur_adc_stream_tag = stream_tag; | |
1856 | spec->cur_adc_format = format; | |
1857 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); | |
1858 | return 0; | |
1859 | } | |
1860 | ||
1861 | static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
1862 | struct hda_codec *codec, | |
1863 | struct snd_pcm_substream *substream) | |
1864 | { | |
1865 | struct alc_spec *spec = codec->spec; | |
1866 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); | |
1867 | spec->cur_adc = 0; | |
1868 | return 0; | |
1869 | } | |
1870 | ||
1871 | static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = { | |
1872 | .substreams = 1, | |
1873 | .channels_min = 2, | |
1874 | .channels_max = 2, | |
1875 | .nid = 0, /* fill later */ | |
1876 | .ops = { | |
1877 | .prepare = dyn_adc_capture_pcm_prepare, | |
1878 | .cleanup = dyn_adc_capture_pcm_cleanup | |
1879 | }, | |
1880 | }; | |
1881 | ||
1882 | /* | |
1883 | */ | |
1884 | static const struct hda_pcm_stream alc_pcm_analog_playback = { | |
1885 | .substreams = 1, | |
1886 | .channels_min = 2, | |
1887 | .channels_max = 8, | |
1888 | /* NID is set in alc_build_pcms */ | |
1889 | .ops = { | |
1890 | .open = alc_playback_pcm_open, | |
1891 | .prepare = alc_playback_pcm_prepare, | |
1892 | .cleanup = alc_playback_pcm_cleanup | |
1893 | }, | |
1894 | }; | |
1895 | ||
1896 | static const struct hda_pcm_stream alc_pcm_analog_capture = { | |
1897 | .substreams = 1, | |
1898 | .channels_min = 2, | |
1899 | .channels_max = 2, | |
1900 | /* NID is set in alc_build_pcms */ | |
1901 | }; | |
1902 | ||
1903 | static const struct hda_pcm_stream alc_pcm_analog_alt_playback = { | |
1904 | .substreams = 1, | |
1905 | .channels_min = 2, | |
1906 | .channels_max = 2, | |
1907 | /* NID is set in alc_build_pcms */ | |
1908 | }; | |
1909 | ||
1910 | static const struct hda_pcm_stream alc_pcm_analog_alt_capture = { | |
1911 | .substreams = 2, /* can be overridden */ | |
1912 | .channels_min = 2, | |
1913 | .channels_max = 2, | |
1914 | /* NID is set in alc_build_pcms */ | |
1915 | .ops = { | |
1916 | .prepare = alc_alt_capture_pcm_prepare, | |
1917 | .cleanup = alc_alt_capture_pcm_cleanup | |
1918 | }, | |
1919 | }; | |
1920 | ||
1921 | static const struct hda_pcm_stream alc_pcm_digital_playback = { | |
1922 | .substreams = 1, | |
1923 | .channels_min = 2, | |
1924 | .channels_max = 2, | |
1925 | /* NID is set in alc_build_pcms */ | |
1926 | .ops = { | |
1927 | .open = alc_dig_playback_pcm_open, | |
1928 | .close = alc_dig_playback_pcm_close, | |
1929 | .prepare = alc_dig_playback_pcm_prepare, | |
1930 | .cleanup = alc_dig_playback_pcm_cleanup | |
1931 | }, | |
1932 | }; | |
1933 | ||
1934 | static const struct hda_pcm_stream alc_pcm_digital_capture = { | |
1935 | .substreams = 1, | |
1936 | .channels_min = 2, | |
1937 | .channels_max = 2, | |
1938 | /* NID is set in alc_build_pcms */ | |
1939 | }; | |
1940 | ||
1941 | /* Used by alc_build_pcms to flag that a PCM has no playback stream */ | |
1942 | static const struct hda_pcm_stream alc_pcm_null_stream = { | |
1943 | .substreams = 0, | |
1944 | .channels_min = 0, | |
1945 | .channels_max = 0, | |
1946 | }; | |
1947 | ||
1948 | static int alc_build_pcms(struct hda_codec *codec) | |
1949 | { | |
1950 | struct alc_spec *spec = codec->spec; | |
1951 | struct hda_pcm *info = spec->pcm_rec; | |
1952 | const struct hda_pcm_stream *p; | |
1953 | bool have_multi_adcs; | |
1954 | int i; | |
1955 | ||
1956 | codec->num_pcms = 1; | |
1957 | codec->pcm_info = info; | |
1958 | ||
1959 | if (spec->no_analog) | |
1960 | goto skip_analog; | |
1961 | ||
1962 | snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), | |
1963 | "%s Analog", codec->chip_name); | |
1964 | info->name = spec->stream_name_analog; | |
1965 | ||
1966 | if (spec->multiout.num_dacs > 0) { | |
1967 | p = spec->stream_analog_playback; | |
1968 | if (!p) | |
1969 | p = &alc_pcm_analog_playback; | |
1970 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | |
1971 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; | |
1972 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = | |
1973 | spec->multiout.max_channels; | |
1974 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT && | |
1975 | spec->autocfg.line_outs == 2) | |
1976 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap = | |
1977 | snd_pcm_2_1_chmaps; | |
1978 | } | |
1979 | if (spec->num_adc_nids) { | |
1980 | p = spec->stream_analog_capture; | |
1981 | if (!p) { | |
1982 | if (spec->dyn_adc_switch) | |
1983 | p = &dyn_adc_pcm_analog_capture; | |
1984 | else | |
1985 | p = &alc_pcm_analog_capture; | |
1986 | } | |
1987 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; | |
1988 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; | |
1989 | } | |
1990 | ||
1991 | if (spec->channel_mode) { | |
1992 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0; | |
1993 | for (i = 0; i < spec->num_channel_mode; i++) { | |
1994 | if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) { | |
1995 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels; | |
1996 | } | |
1997 | } | |
1998 | } | |
1999 | ||
2000 | skip_analog: | |
2001 | /* SPDIF for stream index #1 */ | |
2002 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { | |
2003 | snprintf(spec->stream_name_digital, | |
2004 | sizeof(spec->stream_name_digital), | |
2005 | "%s Digital", codec->chip_name); | |
2006 | codec->num_pcms = 2; | |
2007 | codec->slave_dig_outs = spec->multiout.slave_dig_outs; | |
2008 | info = spec->pcm_rec + 1; | |
2009 | info->name = spec->stream_name_digital; | |
2010 | if (spec->dig_out_type) | |
2011 | info->pcm_type = spec->dig_out_type; | |
2012 | else | |
2013 | info->pcm_type = HDA_PCM_TYPE_SPDIF; | |
2014 | if (spec->multiout.dig_out_nid) { | |
2015 | p = spec->stream_digital_playback; | |
2016 | if (!p) | |
2017 | p = &alc_pcm_digital_playback; | |
2018 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | |
2019 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; | |
2020 | } | |
2021 | if (spec->dig_in_nid) { | |
2022 | p = spec->stream_digital_capture; | |
2023 | if (!p) | |
2024 | p = &alc_pcm_digital_capture; | |
2025 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; | |
2026 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; | |
2027 | } | |
2028 | /* FIXME: do we need this for all Realtek codec models? */ | |
2029 | codec->spdif_status_reset = 1; | |
2030 | } | |
2031 | ||
2032 | if (spec->no_analog) | |
2033 | return 0; | |
2034 | ||
2035 | /* If the use of more than one ADC is requested for the current | |
2036 | * model, configure a second analog capture-only PCM. | |
2037 | */ | |
2038 | have_multi_adcs = (spec->num_adc_nids > 1) && | |
2039 | !spec->dyn_adc_switch && !spec->auto_mic; | |
2040 | /* Additional Analaog capture for index #2 */ | |
2041 | if (spec->alt_dac_nid || have_multi_adcs) { | |
2042 | codec->num_pcms = 3; | |
2043 | info = spec->pcm_rec + 2; | |
2044 | info->name = spec->stream_name_analog; | |
2045 | if (spec->alt_dac_nid) { | |
2046 | p = spec->stream_analog_alt_playback; | |
2047 | if (!p) | |
2048 | p = &alc_pcm_analog_alt_playback; | |
2049 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | |
2050 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | |
2051 | spec->alt_dac_nid; | |
2052 | } else { | |
2053 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = | |
2054 | alc_pcm_null_stream; | |
2055 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0; | |
2056 | } | |
2057 | if (have_multi_adcs) { | |
2058 | p = spec->stream_analog_alt_capture; | |
2059 | if (!p) | |
2060 | p = &alc_pcm_analog_alt_capture; | |
2061 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; | |
2062 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = | |
2063 | spec->adc_nids[1]; | |
2064 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = | |
2065 | spec->num_adc_nids - 1; | |
2066 | } else { | |
2067 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | |
2068 | alc_pcm_null_stream; | |
2069 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0; | |
2070 | } | |
2071 | } | |
2072 | ||
2073 | return 0; | |
2074 | } | |
2075 | ||
2076 | static inline void alc_shutup(struct hda_codec *codec) | |
2077 | { | |
2078 | struct alc_spec *spec = codec->spec; | |
2079 | ||
2080 | if (spec && spec->shutup) | |
2081 | spec->shutup(codec); | |
2082 | snd_hda_shutup_pins(codec); | |
2083 | } | |
2084 | ||
2085 | static void alc_free_kctls(struct hda_codec *codec) | |
2086 | { | |
2087 | struct alc_spec *spec = codec->spec; | |
2088 | ||
2089 | if (spec->kctls.list) { | |
2090 | struct snd_kcontrol_new *kctl = spec->kctls.list; | |
2091 | int i; | |
2092 | for (i = 0; i < spec->kctls.used; i++) | |
2093 | kfree(kctl[i].name); | |
2094 | } | |
2095 | snd_array_free(&spec->kctls); | |
2096 | } | |
2097 | ||
2098 | static void alc_free_bind_ctls(struct hda_codec *codec) | |
2099 | { | |
2100 | struct alc_spec *spec = codec->spec; | |
2101 | if (spec->bind_ctls.list) { | |
2102 | struct hda_bind_ctls **ctl = spec->bind_ctls.list; | |
2103 | int i; | |
2104 | for (i = 0; i < spec->bind_ctls.used; i++) | |
2105 | kfree(ctl[i]); | |
2106 | } | |
2107 | snd_array_free(&spec->bind_ctls); | |
2108 | } | |
2109 | ||
2110 | static void alc_free(struct hda_codec *codec) | |
2111 | { | |
2112 | struct alc_spec *spec = codec->spec; | |
2113 | ||
2114 | if (!spec) | |
2115 | return; | |
2116 | ||
2117 | alc_free_kctls(codec); | |
2118 | alc_free_bind_ctls(codec); | |
2119 | snd_array_free(&spec->paths); | |
2120 | snd_hda_gen_free(&spec->gen); | |
2121 | kfree(spec); | |
2122 | snd_hda_detach_beep_device(codec); | |
2123 | } | |
2124 | ||
2125 | #ifdef CONFIG_PM | |
2126 | static void alc_power_eapd(struct hda_codec *codec) | |
2127 | { | |
2128 | alc_auto_setup_eapd(codec, false); | |
2129 | } | |
2130 | ||
2131 | static int alc_suspend(struct hda_codec *codec) | |
2132 | { | |
2133 | struct alc_spec *spec = codec->spec; | |
2134 | alc_shutup(codec); | |
2135 | if (spec && spec->power_hook) | |
2136 | spec->power_hook(codec); | |
2137 | return 0; | |
2138 | } | |
2139 | #endif | |
2140 | ||
2141 | #ifdef CONFIG_PM | |
2142 | static int alc_resume(struct hda_codec *codec) | |
2143 | { | |
2144 | msleep(150); /* to avoid pop noise */ | |
2145 | codec->patch_ops.init(codec); | |
2146 | snd_hda_codec_resume_amp(codec); | |
2147 | snd_hda_codec_resume_cache(codec); | |
2148 | alc_inv_dmic_sync(codec, true); | |
2149 | hda_call_check_power_status(codec, 0x01); | |
2150 | return 0; | |
2151 | } | |
2152 | #endif | |
2153 | ||
2154 | /* | |
2155 | */ | |
2156 | static const struct hda_codec_ops alc_patch_ops = { | |
2157 | .build_controls = alc_build_controls, | |
2158 | .build_pcms = alc_build_pcms, | |
2159 | .init = alc_init, | |
2160 | .free = alc_free, | |
2161 | .unsol_event = snd_hda_jack_unsol_event, | |
2162 | #ifdef CONFIG_PM | |
2163 | .resume = alc_resume, | |
2164 | #endif | |
2165 | #ifdef CONFIG_PM | |
2166 | .suspend = alc_suspend, | |
2167 | .check_power_status = alc_check_power_status, | |
2168 | #endif | |
2169 | .reboot_notify = alc_shutup, | |
2170 | }; | |
2171 | ||
2172 | ||
2173 | /* replace the codec chip_name with the given string */ | |
2174 | static int alc_codec_rename(struct hda_codec *codec, const char *name) | |
2175 | { | |
2176 | kfree(codec->chip_name); | |
2177 | codec->chip_name = kstrdup(name, GFP_KERNEL); | |
2178 | if (!codec->chip_name) { | |
2179 | alc_free(codec); | |
2180 | return -ENOMEM; | |
2181 | } | |
2182 | return 0; | |
2183 | } | |
2184 | ||
2185 | /* | |
2186 | * Rename codecs appropriately from COEF value | |
2187 | */ | |
2188 | struct alc_codec_rename_table { | |
2189 | unsigned int vendor_id; | |
2190 | unsigned short coef_mask; | |
2191 | unsigned short coef_bits; | |
2192 | const char *name; | |
2193 | }; | |
2194 | ||
2195 | static struct alc_codec_rename_table rename_tbl[] = { | |
2196 | { 0x10ec0269, 0xfff0, 0x3010, "ALC277" }, | |
2197 | { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" }, | |
2198 | { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" }, | |
2199 | { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" }, | |
2200 | { 0x10ec0269, 0xffff, 0xa023, "ALC259" }, | |
2201 | { 0x10ec0269, 0xffff, 0x6023, "ALC281X" }, | |
2202 | { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" }, | |
2203 | { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" }, | |
2204 | { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" }, | |
2205 | { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" }, | |
2206 | { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" }, | |
2207 | { 0x10ec0899, 0x2000, 0x2000, "ALC899" }, | |
2208 | { 0x10ec0892, 0xffff, 0x8020, "ALC661" }, | |
2209 | { 0x10ec0892, 0xffff, 0x8011, "ALC661" }, | |
2210 | { 0x10ec0892, 0xffff, 0x4011, "ALC656" }, | |
2211 | { } /* terminator */ | |
2212 | }; | |
2213 | ||
2214 | static int alc_codec_rename_from_preset(struct hda_codec *codec) | |
2215 | { | |
2216 | const struct alc_codec_rename_table *p; | |
2217 | ||
2218 | for (p = rename_tbl; p->vendor_id; p++) { | |
2219 | if (p->vendor_id != codec->vendor_id) | |
2220 | continue; | |
2221 | if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits) | |
2222 | return alc_codec_rename(codec, p->name); | |
2223 | } | |
2224 | return 0; | |
2225 | } | |
2226 | ||
2227 | /* | |
2228 | * Automatic parse of I/O pins from the BIOS configuration | |
2229 | */ | |
2230 | ||
2231 | enum { | |
2232 | ALC_CTL_WIDGET_VOL, | |
2233 | ALC_CTL_WIDGET_MUTE, | |
2234 | ALC_CTL_BIND_MUTE, | |
2235 | ALC_CTL_BIND_VOL, | |
2236 | ALC_CTL_BIND_SW, | |
2237 | }; | |
2238 | static const struct snd_kcontrol_new alc_control_templates[] = { | |
2239 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), | |
2240 | HDA_CODEC_MUTE(NULL, 0, 0, 0), | |
2241 | HDA_BIND_MUTE(NULL, 0, 0, 0), | |
2242 | HDA_BIND_VOL(NULL, 0), | |
2243 | HDA_BIND_SW(NULL, 0), | |
2244 | }; | |
2245 | ||
2246 | /* add dynamic controls */ | |
2247 | static int add_control(struct alc_spec *spec, int type, const char *name, | |
2248 | int cidx, unsigned long val) | |
2249 | { | |
2250 | struct snd_kcontrol_new *knew; | |
2251 | ||
2252 | knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]); | |
2253 | if (!knew) | |
2254 | return -ENOMEM; | |
2255 | knew->index = cidx; | |
2256 | if (get_amp_nid_(val)) | |
2257 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; | |
2258 | knew->private_value = val; | |
2259 | return 0; | |
2260 | } | |
2261 | ||
2262 | static int add_control_with_pfx(struct alc_spec *spec, int type, | |
2263 | const char *pfx, const char *dir, | |
2264 | const char *sfx, int cidx, unsigned long val) | |
2265 | { | |
2266 | char name[32]; | |
2267 | snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx); | |
2268 | return add_control(spec, type, name, cidx, val); | |
2269 | } | |
2270 | ||
2271 | #define add_pb_vol_ctrl(spec, type, pfx, val) \ | |
2272 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val) | |
2273 | #define add_pb_sw_ctrl(spec, type, pfx, val) \ | |
2274 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val) | |
2275 | #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \ | |
2276 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val) | |
2277 | #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \ | |
2278 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val) | |
2279 | ||
2280 | static const char * const channel_name[4] = { | |
2281 | "Front", "Surround", "CLFE", "Side" | |
2282 | }; | |
2283 | ||
2284 | static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch, | |
2285 | bool can_be_master, int *index) | |
2286 | { | |
2287 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
2288 | ||
2289 | *index = 0; | |
2290 | if (cfg->line_outs == 1 && !spec->multi_ios && | |
2291 | !cfg->hp_outs && !cfg->speaker_outs && can_be_master) | |
2292 | return spec->vmaster_mute.hook ? "PCM" : "Master"; | |
2293 | ||
2294 | /* if there is really a single DAC used in the whole output paths, | |
2295 | * use it master (or "PCM" if a vmaster hook is present) | |
2296 | */ | |
2297 | if (spec->multiout.num_dacs == 1 && !spec->mixer_nid && | |
2298 | !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0]) | |
2299 | return spec->vmaster_mute.hook ? "PCM" : "Master"; | |
2300 | ||
2301 | switch (cfg->line_out_type) { | |
2302 | case AUTO_PIN_SPEAKER_OUT: | |
2303 | if (cfg->line_outs == 1) | |
2304 | return "Speaker"; | |
2305 | if (cfg->line_outs == 2) | |
2306 | return ch ? "Bass Speaker" : "Speaker"; | |
2307 | break; | |
2308 | case AUTO_PIN_HP_OUT: | |
2309 | /* for multi-io case, only the primary out */ | |
2310 | if (ch && spec->multi_ios) | |
2311 | break; | |
2312 | *index = ch; | |
2313 | return "Headphone"; | |
2314 | default: | |
2315 | if (cfg->line_outs == 1 && !spec->multi_ios) | |
2316 | return "PCM"; | |
2317 | break; | |
2318 | } | |
2319 | if (ch >= ARRAY_SIZE(channel_name)) { | |
2320 | snd_BUG(); | |
2321 | return "PCM"; | |
2322 | } | |
2323 | ||
2324 | return channel_name[ch]; | |
2325 | } | |
2326 | ||
2327 | #ifdef CONFIG_PM | |
2328 | /* add the powersave loopback-list entry */ | |
2329 | static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx) | |
2330 | { | |
2331 | struct hda_amp_list *list; | |
2332 | ||
2333 | if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1) | |
2334 | return; | |
2335 | list = spec->loopback_list + spec->num_loopbacks; | |
2336 | list->nid = mix; | |
2337 | list->dir = HDA_INPUT; | |
2338 | list->idx = idx; | |
2339 | spec->num_loopbacks++; | |
2340 | spec->loopback.amplist = spec->loopback_list; | |
2341 | } | |
2342 | #else | |
2343 | #define add_loopback_list(spec, mix, idx) /* NOP */ | |
2344 | #endif | |
2345 | ||
2346 | /* create input playback/capture controls for the given pin */ | |
2347 | static int new_analog_input(struct hda_codec *codec, hda_nid_t pin, | |
2348 | const char *ctlname, int ctlidx, | |
2349 | hda_nid_t mix_nid) | |
2350 | { | |
2351 | struct alc_spec *spec = codec->spec; | |
2352 | struct nid_path *path; | |
2353 | unsigned int val; | |
2354 | int err, idx; | |
2355 | ||
2356 | if (!nid_has_volume(codec, mix_nid, HDA_INPUT) && | |
2357 | !nid_has_mute(codec, mix_nid, HDA_INPUT)) | |
2358 | return 0; /* no need for analog loopback */ | |
2359 | ||
2360 | path = add_new_nid_path(codec, pin, mix_nid, 2); | |
2361 | if (!path) | |
2362 | return -EINVAL; | |
2363 | ||
2364 | idx = path->idx[path->depth - 1]; | |
2365 | if (nid_has_volume(codec, mix_nid, HDA_INPUT)) { | |
2366 | val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT); | |
2367 | err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, val); | |
2368 | if (err < 0) | |
2369 | return err; | |
2370 | path->ctls[NID_PATH_VOL_CTL] = val; | |
2371 | } | |
2372 | ||
2373 | if (nid_has_mute(codec, mix_nid, HDA_INPUT)) { | |
2374 | val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT); | |
2375 | err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, val); | |
2376 | if (err < 0) | |
2377 | return err; | |
2378 | path->ctls[NID_PATH_MUTE_CTL] = val; | |
2379 | } | |
2380 | ||
2381 | path->active = true; | |
2382 | add_loopback_list(spec, mix_nid, idx); | |
2383 | return 0; | |
2384 | } | |
2385 | ||
2386 | static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid) | |
2387 | { | |
2388 | unsigned int pincap = snd_hda_query_pin_caps(codec, nid); | |
2389 | return (pincap & AC_PINCAP_IN) != 0; | |
2390 | } | |
2391 | ||
2392 | /* check whether the given two widgets can be connected */ | |
2393 | static bool is_reachable_path(struct hda_codec *codec, | |
2394 | hda_nid_t from_nid, hda_nid_t to_nid) | |
2395 | { | |
2396 | if (!from_nid || !to_nid) | |
2397 | return false; | |
2398 | return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0; | |
2399 | } | |
2400 | ||
2401 | /* Parse the codec tree and retrieve ADCs */ | |
2402 | static int alc_auto_fill_adc_nids(struct hda_codec *codec) | |
2403 | { | |
2404 | struct alc_spec *spec = codec->spec; | |
2405 | hda_nid_t nid; | |
2406 | hda_nid_t *adc_nids = spec->adc_nids; | |
2407 | int max_nums = ARRAY_SIZE(spec->adc_nids); | |
2408 | int i, nums = 0; | |
2409 | ||
2410 | nid = codec->start_nid; | |
2411 | for (i = 0; i < codec->num_nodes; i++, nid++) { | |
2412 | unsigned int caps = get_wcaps(codec, nid); | |
2413 | int type = get_wcaps_type(caps); | |
2414 | ||
2415 | if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL)) | |
2416 | continue; | |
2417 | adc_nids[nums] = nid; | |
2418 | if (++nums >= max_nums) | |
2419 | break; | |
2420 | } | |
2421 | spec->num_adc_nids = nums; | |
2422 | return nums; | |
2423 | } | |
2424 | ||
2425 | /* filter out invalid adc_nids that don't give all active input pins; | |
2426 | * if needed, check whether dynamic ADC-switching is available | |
2427 | */ | |
2428 | static int check_dyn_adc_switch(struct hda_codec *codec) | |
2429 | { | |
2430 | struct alc_spec *spec = codec->spec; | |
2431 | struct hda_input_mux *imux = &spec->input_mux; | |
2432 | hda_nid_t adc_nids[ARRAY_SIZE(spec->adc_nids)]; | |
2433 | int i, n, nums; | |
2434 | hda_nid_t pin, adc; | |
2435 | ||
2436 | again: | |
2437 | nums = 0; | |
2438 | for (n = 0; n < spec->num_adc_nids; n++) { | |
2439 | adc = spec->adc_nids[n]; | |
2440 | for (i = 0; i < imux->num_items; i++) { | |
2441 | pin = spec->imux_pins[i]; | |
2442 | if (!is_reachable_path(codec, pin, adc)) | |
2443 | break; | |
2444 | } | |
2445 | if (i >= imux->num_items) | |
2446 | adc_nids[nums++] = adc; | |
2447 | } | |
2448 | ||
2449 | if (!nums) { | |
2450 | if (spec->shared_mic_hp) { | |
2451 | spec->shared_mic_hp = 0; | |
2452 | imux->num_items = 1; | |
2453 | goto again; | |
2454 | } | |
2455 | ||
2456 | /* check whether ADC-switch is possible */ | |
2457 | for (i = 0; i < imux->num_items; i++) { | |
2458 | pin = spec->imux_pins[i]; | |
2459 | for (n = 0; n < spec->num_adc_nids; n++) { | |
2460 | adc = spec->adc_nids[n]; | |
2461 | if (is_reachable_path(codec, pin, adc)) { | |
2462 | spec->dyn_adc_idx[i] = n; | |
2463 | break; | |
2464 | } | |
2465 | } | |
2466 | } | |
2467 | ||
2468 | snd_printdd("realtek: enabling ADC switching\n"); | |
2469 | spec->dyn_adc_switch = 1; | |
2470 | } else if (nums != spec->num_adc_nids) { | |
2471 | memcpy(spec->adc_nids, adc_nids, nums * sizeof(hda_nid_t)); | |
2472 | spec->num_adc_nids = nums; | |
2473 | } | |
2474 | ||
2475 | if (imux->num_items == 1 || spec->shared_mic_hp) { | |
2476 | snd_printdd("realtek: reducing to a single ADC\n"); | |
2477 | spec->num_adc_nids = 1; /* reduce to a single ADC */ | |
2478 | } | |
2479 | ||
2480 | /* single index for individual volumes ctls */ | |
2481 | if (!spec->dyn_adc_switch && spec->multi_cap_vol) | |
2482 | spec->num_adc_nids = 1; | |
2483 | ||
2484 | return 0; | |
2485 | } | |
2486 | ||
2487 | /* templates for capture controls */ | |
2488 | static const struct snd_kcontrol_new cap_src_temp = { | |
2489 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2490 | .name = "Input Source", | |
2491 | .info = alc_mux_enum_info, | |
2492 | .get = alc_mux_enum_get, | |
2493 | .put = alc_mux_enum_put, | |
2494 | }; | |
2495 | ||
2496 | static const struct snd_kcontrol_new cap_vol_temp = { | |
2497 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2498 | .name = "Capture Volume", | |
2499 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | | |
2500 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | | |
2501 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), | |
2502 | .info = alc_cap_vol_info, | |
2503 | .get = alc_cap_vol_get, | |
2504 | .put = alc_cap_vol_put, | |
2505 | .tlv = { .c = alc_cap_vol_tlv }, | |
2506 | }; | |
2507 | ||
2508 | static const struct snd_kcontrol_new cap_sw_temp = { | |
2509 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2510 | .name = "Capture Switch", | |
2511 | .info = alc_cap_sw_info, | |
2512 | .get = alc_cap_sw_get, | |
2513 | .put = alc_cap_sw_put, | |
2514 | }; | |
2515 | ||
2516 | static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path) | |
2517 | { | |
2518 | hda_nid_t nid; | |
2519 | int i, depth; | |
2520 | ||
2521 | path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0; | |
2522 | for (depth = 0; depth < 3; depth++) { | |
2523 | if (depth >= path->depth) | |
2524 | return -EINVAL; | |
2525 | i = path->depth - depth - 1; | |
2526 | nid = path->path[i]; | |
2527 | if (!path->ctls[NID_PATH_VOL_CTL]) { | |
2528 | if (nid_has_volume(codec, nid, HDA_OUTPUT)) | |
2529 | path->ctls[NID_PATH_VOL_CTL] = | |
2530 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); | |
2531 | else if (nid_has_volume(codec, nid, HDA_INPUT)) { | |
2532 | int idx = path->idx[i]; | |
2533 | if (!depth && codec->single_adc_amp) | |
2534 | idx = 0; | |
2535 | path->ctls[NID_PATH_VOL_CTL] = | |
2536 | HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT); | |
2537 | } | |
2538 | } | |
2539 | if (!path->ctls[NID_PATH_MUTE_CTL]) { | |
2540 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) | |
2541 | path->ctls[NID_PATH_MUTE_CTL] = | |
2542 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); | |
2543 | else if (nid_has_mute(codec, nid, HDA_INPUT)) { | |
2544 | int idx = path->idx[i]; | |
2545 | if (!depth && codec->single_adc_amp) | |
2546 | idx = 0; | |
2547 | path->ctls[NID_PATH_MUTE_CTL] = | |
2548 | HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT); | |
2549 | } | |
2550 | } | |
2551 | } | |
2552 | return 0; | |
2553 | } | |
2554 | ||
2555 | static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs); | |
2556 | ||
2557 | static int add_single_cap_ctl(struct hda_codec *codec, const char *label, | |
2558 | int idx, bool is_switch, unsigned int ctl) | |
2559 | { | |
2560 | struct alc_spec *spec = codec->spec; | |
2561 | char tmpname[44]; | |
2562 | int type = is_switch ? ALC_CTL_WIDGET_MUTE : ALC_CTL_WIDGET_VOL; | |
2563 | const char *sfx = is_switch ? "Switch" : "Volume"; | |
2564 | unsigned int chs; | |
2565 | int err; | |
2566 | ||
2567 | if (!ctl) | |
2568 | return 0; | |
2569 | ||
2570 | if (idx == spec->inv_dmic_split_idx) | |
2571 | chs = 1; | |
2572 | else | |
2573 | chs = 3; | |
2574 | ||
2575 | if (label) | |
2576 | snprintf(tmpname, sizeof(tmpname), | |
2577 | "%s Capture %s", label, sfx); | |
2578 | else | |
2579 | snprintf(tmpname, sizeof(tmpname), | |
2580 | "Capture %s", sfx); | |
2581 | err = add_control(spec, type, tmpname, idx, | |
2582 | amp_val_replace_channels(ctl, chs)); | |
2583 | if (err < 0 || chs == 3) | |
2584 | return err; | |
2585 | ||
2586 | /* Make independent right kcontrol */ | |
2587 | if (label) | |
2588 | snprintf(tmpname, sizeof(tmpname), | |
2589 | "Inverted %s Capture %s", label, sfx); | |
2590 | else | |
2591 | snprintf(tmpname, sizeof(tmpname), | |
2592 | "Inverted Capture %s", sfx); | |
2593 | return add_control(spec, type, tmpname, idx, | |
2594 | amp_val_replace_channels(ctl, 2)); | |
2595 | } | |
2596 | ||
2597 | /* create single (and simple) capture volume and switch controls */ | |
2598 | static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx, | |
2599 | unsigned int vol_ctl, unsigned int sw_ctl) | |
2600 | { | |
2601 | int err; | |
2602 | err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl); | |
2603 | if (err < 0) | |
2604 | return err; | |
2605 | err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl); | |
2606 | if (err < 0) | |
2607 | return err; | |
2608 | return 0; | |
2609 | } | |
2610 | ||
2611 | /* create bound capture volume and switch controls */ | |
2612 | static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx, | |
2613 | unsigned int vol_ctl, unsigned int sw_ctl) | |
2614 | { | |
2615 | struct alc_spec *spec = codec->spec; | |
2616 | struct snd_kcontrol_new *knew; | |
2617 | ||
2618 | if (vol_ctl) { | |
2619 | knew = alc_kcontrol_new(spec, NULL, &cap_vol_temp); | |
2620 | if (!knew) | |
2621 | return -ENOMEM; | |
2622 | knew->index = idx; | |
2623 | knew->private_value = vol_ctl; | |
2624 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; | |
2625 | } | |
2626 | if (sw_ctl) { | |
2627 | knew = alc_kcontrol_new(spec, NULL, &cap_sw_temp); | |
2628 | if (!knew) | |
2629 | return -ENOMEM; | |
2630 | knew->index = idx; | |
2631 | knew->private_value = sw_ctl; | |
2632 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; | |
2633 | } | |
2634 | return 0; | |
2635 | } | |
2636 | ||
2637 | /* return the vol ctl when used first in the imux list */ | |
2638 | static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type) | |
2639 | { | |
2640 | struct alc_spec *spec = codec->spec; | |
2641 | struct nid_path *path; | |
2642 | unsigned int ctl; | |
2643 | int i; | |
2644 | ||
2645 | path = get_nid_path(codec, spec->imux_pins[idx], | |
2646 | get_adc_nid(codec, 0, idx)); | |
2647 | if (!path) | |
2648 | return 0; | |
2649 | ctl = path->ctls[type]; | |
2650 | if (!ctl) | |
2651 | return 0; | |
2652 | for (i = 0; i < idx - 1; i++) { | |
2653 | path = get_nid_path(codec, spec->imux_pins[i], | |
2654 | get_adc_nid(codec, 0, i)); | |
2655 | if (path && path->ctls[type] == ctl) | |
2656 | return 0; | |
2657 | } | |
2658 | return ctl; | |
2659 | } | |
2660 | ||
2661 | /* create individual capture volume and switch controls per input */ | |
2662 | static int create_multi_cap_vol_ctl(struct hda_codec *codec) | |
2663 | { | |
2664 | struct alc_spec *spec = codec->spec; | |
2665 | struct hda_input_mux *imux = &spec->input_mux; | |
2666 | int i, err, type, type_idx = 0; | |
2667 | const char *prev_label = NULL; | |
2668 | ||
2669 | for (i = 0; i < imux->num_items; i++) { | |
2670 | const char *label; | |
2671 | label = hda_get_autocfg_input_label(codec, &spec->autocfg, i); | |
2672 | if (prev_label && !strcmp(label, prev_label)) | |
2673 | type_idx++; | |
2674 | else | |
2675 | type_idx = 0; | |
2676 | prev_label = label; | |
2677 | ||
2678 | for (type = 0; type < 2; type++) { | |
2679 | err = add_single_cap_ctl(codec, label, type_idx, type, | |
2680 | get_first_cap_ctl(codec, i, type)); | |
2681 | if (err < 0) | |
2682 | return err; | |
2683 | } | |
2684 | } | |
2685 | return 0; | |
2686 | } | |
2687 | ||
2688 | static int create_capture_mixers(struct hda_codec *codec) | |
2689 | { | |
2690 | struct alc_spec *spec = codec->spec; | |
2691 | struct hda_input_mux *imux = &spec->input_mux; | |
2692 | int i, n, nums, err; | |
2693 | ||
2694 | if (spec->dyn_adc_switch) | |
2695 | nums = 1; | |
2696 | else | |
2697 | nums = spec->num_adc_nids; | |
2698 | ||
2699 | if (!spec->auto_mic && imux->num_items > 1) { | |
2700 | struct snd_kcontrol_new *knew; | |
2701 | knew = alc_kcontrol_new(spec, NULL, &cap_src_temp); | |
2702 | if (!knew) | |
2703 | return -ENOMEM; | |
2704 | knew->count = nums; | |
2705 | } | |
2706 | ||
2707 | for (n = 0; n < nums; n++) { | |
2708 | bool multi = false; | |
2709 | int vol, sw; | |
2710 | ||
2711 | vol = sw = 0; | |
2712 | for (i = 0; i < imux->num_items; i++) { | |
2713 | struct nid_path *path; | |
2714 | path = get_nid_path(codec, spec->imux_pins[i], | |
2715 | get_adc_nid(codec, n, i)); | |
2716 | if (!path) | |
2717 | continue; | |
2718 | parse_capvol_in_path(codec, path); | |
2719 | if (!vol) | |
2720 | vol = path->ctls[NID_PATH_VOL_CTL]; | |
2721 | else if (vol != path->ctls[NID_PATH_VOL_CTL]) | |
2722 | multi = true; | |
2723 | if (!sw) | |
2724 | sw = path->ctls[NID_PATH_MUTE_CTL]; | |
2725 | else if (sw != path->ctls[NID_PATH_MUTE_CTL]) | |
2726 | multi = true; | |
2727 | } | |
2728 | ||
2729 | if (!multi) | |
2730 | err = create_single_cap_vol_ctl(codec, n, vol, sw); | |
2731 | else if (!spec->multi_cap_vol) | |
2732 | err = create_bind_cap_vol_ctl(codec, n, vol, sw); | |
2733 | else | |
2734 | err = create_multi_cap_vol_ctl(codec); | |
2735 | if (err < 0) | |
2736 | return err; | |
2737 | } | |
2738 | ||
2739 | return 0; | |
2740 | } | |
2741 | ||
2742 | /* create playback/capture controls for input pins */ | |
2743 | static int alc_auto_create_input_ctls(struct hda_codec *codec) | |
2744 | { | |
2745 | struct alc_spec *spec = codec->spec; | |
2746 | const struct auto_pin_cfg *cfg = &spec->autocfg; | |
2747 | hda_nid_t mixer = spec->mixer_nid; | |
2748 | struct hda_input_mux *imux = &spec->input_mux; | |
2749 | int num_adcs; | |
2750 | int i, c, err, type_idx = 0; | |
2751 | const char *prev_label = NULL; | |
2752 | ||
2753 | num_adcs = alc_auto_fill_adc_nids(codec); | |
2754 | if (num_adcs < 0) | |
2755 | return 0; | |
2756 | ||
2757 | spec->inv_dmic_split_idx = -1; | |
2758 | for (i = 0; i < cfg->num_inputs; i++) { | |
2759 | hda_nid_t pin; | |
2760 | const char *label; | |
2761 | bool imux_added; | |
2762 | ||
2763 | pin = cfg->inputs[i].pin; | |
2764 | if (!alc_is_input_pin(codec, pin)) | |
2765 | continue; | |
2766 | ||
2767 | label = hda_get_autocfg_input_label(codec, cfg, i); | |
2768 | if (spec->shared_mic_hp && !strcmp(label, "Misc")) | |
2769 | label = "Headphone Mic"; | |
2770 | if (prev_label && !strcmp(label, prev_label)) | |
2771 | type_idx++; | |
2772 | else | |
2773 | type_idx = 0; | |
2774 | prev_label = label; | |
2775 | ||
2776 | if (mixer) { | |
2777 | if (is_reachable_path(codec, pin, mixer)) { | |
2778 | err = new_analog_input(codec, pin, | |
2779 | label, type_idx, mixer); | |
2780 | if (err < 0) | |
2781 | return err; | |
2782 | } | |
2783 | } | |
2784 | ||
2785 | imux_added = false; | |
2786 | for (c = 0; c < num_adcs; c++) { | |
2787 | struct nid_path *path; | |
2788 | hda_nid_t adc = spec->adc_nids[c]; | |
2789 | ||
2790 | if (!is_reachable_path(codec, pin, adc)) | |
2791 | continue; | |
2792 | path = snd_array_new(&spec->paths); | |
2793 | if (!path) | |
2794 | return -ENOMEM; | |
2795 | memset(path, 0, sizeof(*path)); | |
2796 | if (!parse_nid_path(codec, pin, adc, 2, path)) { | |
2797 | snd_printd(KERN_ERR | |
2798 | "invalid input path 0x%x -> 0x%x\n", | |
2799 | pin, adc); | |
2800 | spec->paths.used--; | |
2801 | continue; | |
2802 | } | |
2803 | ||
2804 | if (!imux_added) { | |
2805 | spec->imux_pins[imux->num_items] = pin; | |
2806 | snd_hda_add_imux_item(imux, label, | |
2807 | imux->num_items, NULL); | |
2808 | imux_added = true; | |
2809 | } | |
2810 | } | |
2811 | ||
2812 | if (spec->inv_dmic_split) { | |
2813 | if (cfg->inputs[i].type == AUTO_PIN_MIC) { | |
2814 | unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); | |
2815 | if (snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT) | |
2816 | spec->inv_dmic_split_idx = i; | |
2817 | } | |
2818 | } | |
2819 | } | |
2820 | ||
2821 | return 0; | |
2822 | } | |
2823 | ||
2824 | /* create a shared input with the headphone out */ | |
2825 | static int alc_auto_create_shared_input(struct hda_codec *codec) | |
2826 | { | |
2827 | struct alc_spec *spec = codec->spec; | |
2828 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
2829 | unsigned int defcfg; | |
2830 | hda_nid_t nid; | |
2831 | ||
2832 | /* only one internal input pin? */ | |
2833 | if (cfg->num_inputs != 1) | |
2834 | return 0; | |
2835 | defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin); | |
2836 | if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT) | |
2837 | return 0; | |
2838 | ||
2839 | if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) | |
2840 | nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */ | |
2841 | else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT) | |
2842 | nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */ | |
2843 | else | |
2844 | return 0; /* both not available */ | |
2845 | ||
2846 | if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN)) | |
2847 | return 0; /* no input */ | |
2848 | ||
2849 | cfg->inputs[1].pin = nid; | |
2850 | cfg->inputs[1].type = AUTO_PIN_MIC; | |
2851 | cfg->num_inputs = 2; | |
2852 | spec->shared_mic_hp = 1; | |
2853 | snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid); | |
2854 | return 0; | |
2855 | } | |
2856 | ||
2857 | static int get_pin_type(int line_out_type) | |
2858 | { | |
2859 | if (line_out_type == AUTO_PIN_HP_OUT) | |
2860 | return PIN_HP; | |
2861 | else | |
2862 | return PIN_OUT; | |
2863 | } | |
2864 | ||
2865 | static void alc_auto_init_analog_input(struct hda_codec *codec) | |
2866 | { | |
2867 | struct alc_spec *spec = codec->spec; | |
2868 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
2869 | int i; | |
2870 | ||
2871 | for (i = 0; i < cfg->num_inputs; i++) { | |
2872 | hda_nid_t nid = cfg->inputs[i].pin; | |
2873 | if (alc_is_input_pin(codec, nid)) | |
2874 | alc_set_input_pin(codec, nid, cfg->inputs[i].type); | |
2875 | ||
2876 | /* mute loopback inputs */ | |
2877 | if (spec->mixer_nid) { | |
2878 | struct nid_path *path; | |
2879 | path = get_nid_path(codec, nid, spec->mixer_nid); | |
2880 | if (path) | |
2881 | activate_path(codec, path, path->active, false); | |
2882 | } | |
2883 | } | |
2884 | } | |
2885 | ||
2886 | static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid) | |
2887 | { | |
2888 | struct alc_spec *spec = codec->spec; | |
2889 | int i; | |
2890 | ||
2891 | for (i = 0; i < spec->paths.used; i++) { | |
2892 | struct nid_path *path = snd_array_elem(&spec->paths, i); | |
2893 | if (path->path[0] == nid) | |
2894 | return true; | |
2895 | } | |
2896 | return false; | |
2897 | } | |
2898 | ||
2899 | /* look for an empty DAC slot */ | |
2900 | static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin, | |
2901 | bool is_digital) | |
2902 | { | |
2903 | struct alc_spec *spec = codec->spec; | |
2904 | bool cap_digital; | |
2905 | int i; | |
2906 | ||
2907 | for (i = 0; i < spec->num_all_dacs; i++) { | |
2908 | hda_nid_t nid = spec->all_dacs[i]; | |
2909 | if (!nid || alc_is_dac_already_used(codec, nid)) | |
2910 | continue; | |
2911 | cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL); | |
2912 | if (is_digital != cap_digital) | |
2913 | continue; | |
2914 | if (is_reachable_path(codec, nid, pin)) | |
2915 | return nid; | |
2916 | } | |
2917 | return 0; | |
2918 | } | |
2919 | ||
2920 | /* called recursively */ | |
2921 | static bool __parse_nid_path(struct hda_codec *codec, | |
2922 | hda_nid_t from_nid, hda_nid_t to_nid, | |
2923 | int with_aa_mix, struct nid_path *path, int depth) | |
2924 | { | |
2925 | struct alc_spec *spec = codec->spec; | |
2926 | hda_nid_t conn[16]; | |
2927 | int i, nums; | |
2928 | ||
2929 | if (to_nid == spec->mixer_nid) { | |
2930 | if (!with_aa_mix) | |
2931 | return false; | |
2932 | with_aa_mix = 2; /* mark aa-mix is included */ | |
2933 | } | |
2934 | ||
2935 | nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn)); | |
2936 | for (i = 0; i < nums; i++) { | |
2937 | if (conn[i] != from_nid) { | |
2938 | /* special case: when from_nid is 0, | |
2939 | * try to find an empty DAC | |
2940 | */ | |
2941 | if (from_nid || | |
2942 | get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT || | |
2943 | alc_is_dac_already_used(codec, conn[i])) | |
2944 | continue; | |
2945 | } | |
2946 | /* aa-mix is requested but not included? */ | |
2947 | if (!(spec->mixer_nid && with_aa_mix == 1)) | |
2948 | goto found; | |
2949 | } | |
2950 | if (depth >= MAX_NID_PATH_DEPTH) | |
2951 | return false; | |
2952 | for (i = 0; i < nums; i++) { | |
2953 | unsigned int type; | |
2954 | type = get_wcaps_type(get_wcaps(codec, conn[i])); | |
2955 | if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN || | |
2956 | type == AC_WID_PIN) | |
2957 | continue; | |
2958 | if (__parse_nid_path(codec, from_nid, conn[i], | |
2959 | with_aa_mix, path, depth + 1)) | |
2960 | goto found; | |
2961 | } | |
2962 | return false; | |
2963 | ||
2964 | found: | |
2965 | path->path[path->depth] = conn[i]; | |
2966 | path->idx[path->depth + 1] = i; | |
2967 | if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX) | |
2968 | path->multi[path->depth + 1] = 1; | |
2969 | path->depth++; | |
2970 | return true; | |
2971 | } | |
2972 | ||
2973 | /* parse the widget path from the given nid to the target nid; | |
2974 | * when @from_nid is 0, try to find an empty DAC; | |
2975 | * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded. | |
2976 | * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded. | |
2977 | * when @with_aa_mix is 2, no special handling about spec->mixer_nid. | |
2978 | */ | |
2979 | static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid, | |
2980 | hda_nid_t to_nid, int with_aa_mix, | |
2981 | struct nid_path *path) | |
2982 | { | |
2983 | if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) { | |
2984 | path->path[path->depth] = to_nid; | |
2985 | path->depth++; | |
2986 | #if 0 | |
2987 | snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n", | |
2988 | path->depth, path->path[0], path->path[1], | |
2989 | path->path[2], path->path[3], path->path[4]); | |
2990 | #endif | |
2991 | return true; | |
2992 | } | |
2993 | return false; | |
2994 | } | |
2995 | ||
2996 | static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin) | |
2997 | { | |
2998 | struct alc_spec *spec = codec->spec; | |
2999 | int i; | |
3000 | hda_nid_t nid_found = 0; | |
3001 | ||
3002 | for (i = 0; i < spec->num_all_dacs; i++) { | |
3003 | hda_nid_t nid = spec->all_dacs[i]; | |
3004 | if (!nid || alc_is_dac_already_used(codec, nid)) | |
3005 | continue; | |
3006 | if (is_reachable_path(codec, nid, pin)) { | |
3007 | if (nid_found) | |
3008 | return 0; | |
3009 | nid_found = nid; | |
3010 | } | |
3011 | } | |
3012 | return nid_found; | |
3013 | } | |
3014 | ||
3015 | static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type) | |
3016 | { | |
3017 | struct alc_spec *spec = codec->spec; | |
3018 | int i; | |
3019 | ||
3020 | for (i = 0; i < spec->paths.used; i++) { | |
3021 | struct nid_path *path = snd_array_elem(&spec->paths, i); | |
3022 | if (path->ctls[type] == val) | |
3023 | return true; | |
3024 | } | |
3025 | return false; | |
3026 | } | |
3027 | ||
3028 | /* badness definition */ | |
3029 | enum { | |
3030 | /* No primary DAC is found for the main output */ | |
3031 | BAD_NO_PRIMARY_DAC = 0x10000, | |
3032 | /* No DAC is found for the extra output */ | |
3033 | BAD_NO_DAC = 0x4000, | |
3034 | /* No possible multi-ios */ | |
3035 | BAD_MULTI_IO = 0x103, | |
3036 | /* No individual DAC for extra output */ | |
3037 | BAD_NO_EXTRA_DAC = 0x102, | |
3038 | /* No individual DAC for extra surrounds */ | |
3039 | BAD_NO_EXTRA_SURR_DAC = 0x101, | |
3040 | /* Primary DAC shared with main surrounds */ | |
3041 | BAD_SHARED_SURROUND = 0x100, | |
3042 | /* Primary DAC shared with main CLFE */ | |
3043 | BAD_SHARED_CLFE = 0x10, | |
3044 | /* Primary DAC shared with extra surrounds */ | |
3045 | BAD_SHARED_EXTRA_SURROUND = 0x10, | |
3046 | /* Volume widget is shared */ | |
3047 | BAD_SHARED_VOL = 0x10, | |
3048 | }; | |
3049 | ||
3050 | static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec, | |
3051 | struct nid_path *path); | |
3052 | static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec, | |
3053 | struct nid_path *path); | |
3054 | ||
3055 | static struct nid_path *add_new_nid_path(struct hda_codec *codec, | |
3056 | hda_nid_t from_nid, hda_nid_t to_nid, | |
3057 | int with_aa_mix) | |
3058 | { | |
3059 | struct alc_spec *spec = codec->spec; | |
3060 | struct nid_path *path; | |
3061 | ||
3062 | if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid)) | |
3063 | return NULL; | |
3064 | ||
3065 | path = snd_array_new(&spec->paths); | |
3066 | if (!path) | |
3067 | return NULL; | |
3068 | memset(path, 0, sizeof(*path)); | |
3069 | if (parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path)) | |
3070 | return path; | |
3071 | /* push back */ | |
3072 | spec->paths.used--; | |
3073 | return NULL; | |
3074 | } | |
3075 | ||
3076 | /* get the path between the given NIDs; | |
3077 | * passing 0 to either @pin or @dac behaves as a wildcard | |
3078 | */ | |
3079 | static struct nid_path * | |
3080 | get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid) | |
3081 | { | |
3082 | struct alc_spec *spec = codec->spec; | |
3083 | int i; | |
3084 | ||
3085 | for (i = 0; i < spec->paths.used; i++) { | |
3086 | struct nid_path *path = snd_array_elem(&spec->paths, i); | |
3087 | if (path->depth <= 0) | |
3088 | continue; | |
3089 | if ((!from_nid || path->path[0] == from_nid) && | |
3090 | (!to_nid || path->path[path->depth - 1] == to_nid)) | |
3091 | return path; | |
3092 | } | |
3093 | return NULL; | |
3094 | } | |
3095 | ||
3096 | /* look for widgets in the path between the given NIDs appropriate for | |
3097 | * volume and mute controls, and assign the values to ctls[]. | |
3098 | * | |
3099 | * When no appropriate widget is found in the path, the badness value | |
3100 | * is incremented depending on the situation. The function returns the | |
3101 | * total badness for both volume and mute controls. | |
3102 | */ | |
3103 | static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin, | |
3104 | hda_nid_t dac) | |
3105 | { | |
3106 | struct nid_path *path = get_nid_path(codec, dac, pin); | |
3107 | hda_nid_t nid; | |
3108 | unsigned int val; | |
3109 | int badness = 0; | |
3110 | ||
3111 | if (!path) | |
3112 | return BAD_SHARED_VOL * 2; | |
3113 | nid = alc_look_for_out_vol_nid(codec, path); | |
3114 | if (nid) { | |
3115 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); | |
3116 | if (is_ctl_used(codec, val, NID_PATH_VOL_CTL)) | |
3117 | badness += BAD_SHARED_VOL; | |
3118 | else | |
3119 | path->ctls[NID_PATH_VOL_CTL] = val; | |
3120 | } else | |
3121 | badness += BAD_SHARED_VOL; | |
3122 | nid = alc_look_for_out_mute_nid(codec, path); | |
3123 | if (nid) { | |
3124 | unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid)); | |
3125 | if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT || | |
3126 | nid_has_mute(codec, nid, HDA_OUTPUT)) | |
3127 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); | |
3128 | else | |
3129 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT); | |
3130 | if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL)) | |
3131 | badness += BAD_SHARED_VOL; | |
3132 | else | |
3133 | path->ctls[NID_PATH_MUTE_CTL] = val; | |
3134 | } else | |
3135 | badness += BAD_SHARED_VOL; | |
3136 | return badness; | |
3137 | } | |
3138 | ||
3139 | struct badness_table { | |
3140 | int no_primary_dac; /* no primary DAC */ | |
3141 | int no_dac; /* no secondary DACs */ | |
3142 | int shared_primary; /* primary DAC is shared with main output */ | |
3143 | int shared_surr; /* secondary DAC shared with main or primary */ | |
3144 | int shared_clfe; /* third DAC shared with main or primary */ | |
3145 | int shared_surr_main; /* secondary DAC sahred with main/DAC0 */ | |
3146 | }; | |
3147 | ||
3148 | static struct badness_table main_out_badness = { | |
3149 | .no_primary_dac = BAD_NO_PRIMARY_DAC, | |
3150 | .no_dac = BAD_NO_DAC, | |
3151 | .shared_primary = BAD_NO_PRIMARY_DAC, | |
3152 | .shared_surr = BAD_SHARED_SURROUND, | |
3153 | .shared_clfe = BAD_SHARED_CLFE, | |
3154 | .shared_surr_main = BAD_SHARED_SURROUND, | |
3155 | }; | |
3156 | ||
3157 | static struct badness_table extra_out_badness = { | |
3158 | .no_primary_dac = BAD_NO_DAC, | |
3159 | .no_dac = BAD_NO_DAC, | |
3160 | .shared_primary = BAD_NO_EXTRA_DAC, | |
3161 | .shared_surr = BAD_SHARED_EXTRA_SURROUND, | |
3162 | .shared_clfe = BAD_SHARED_EXTRA_SURROUND, | |
3163 | .shared_surr_main = BAD_NO_EXTRA_SURR_DAC, | |
3164 | }; | |
3165 | ||
3166 | /* try to assign DACs to pins and return the resultant badness */ | |
3167 | static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs, | |
3168 | const hda_nid_t *pins, hda_nid_t *dacs, | |
3169 | const struct badness_table *bad) | |
3170 | { | |
3171 | struct alc_spec *spec = codec->spec; | |
3172 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
3173 | int i, j; | |
3174 | int badness = 0; | |
3175 | hda_nid_t dac; | |
3176 | ||
3177 | if (!num_outs) | |
3178 | return 0; | |
3179 | ||
3180 | for (i = 0; i < num_outs; i++) { | |
3181 | hda_nid_t pin = pins[i]; | |
3182 | if (!dacs[i]) | |
3183 | dacs[i] = alc_auto_look_for_dac(codec, pin, false); | |
3184 | if (!dacs[i] && !i) { | |
3185 | for (j = 1; j < num_outs; j++) { | |
3186 | if (is_reachable_path(codec, dacs[j], pin)) { | |
3187 | dacs[0] = dacs[j]; | |
3188 | dacs[j] = 0; | |
3189 | break; | |
3190 | } | |
3191 | } | |
3192 | } | |
3193 | dac = dacs[i]; | |
3194 | if (!dac) { | |
3195 | if (is_reachable_path(codec, dacs[0], pin)) | |
3196 | dac = dacs[0]; | |
3197 | else if (cfg->line_outs > i && | |
3198 | is_reachable_path(codec, spec->private_dac_nids[i], pin)) | |
3199 | dac = spec->private_dac_nids[i]; | |
3200 | if (dac) { | |
3201 | if (!i) | |
3202 | badness += bad->shared_primary; | |
3203 | else if (i == 1) | |
3204 | badness += bad->shared_surr; | |
3205 | else | |
3206 | badness += bad->shared_clfe; | |
3207 | } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) { | |
3208 | dac = spec->private_dac_nids[0]; | |
3209 | badness += bad->shared_surr_main; | |
3210 | } else if (!i) | |
3211 | badness += bad->no_primary_dac; | |
3212 | else | |
3213 | badness += bad->no_dac; | |
3214 | } | |
3215 | if (!add_new_nid_path(codec, dac, pin, 0)) | |
3216 | dac = dacs[i] = 0; | |
3217 | if (dac) | |
3218 | badness += assign_out_path_ctls(codec, pin, dac); | |
3219 | } | |
3220 | ||
3221 | return badness; | |
3222 | } | |
3223 | ||
3224 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, | |
3225 | hda_nid_t reference_pin, | |
3226 | bool hardwired, int offset); | |
3227 | ||
3228 | static bool alc_map_singles(struct hda_codec *codec, int outs, | |
3229 | const hda_nid_t *pins, hda_nid_t *dacs) | |
3230 | { | |
3231 | int i; | |
3232 | bool found = false; | |
3233 | for (i = 0; i < outs; i++) { | |
3234 | hda_nid_t dac; | |
3235 | if (dacs[i]) | |
3236 | continue; | |
3237 | dac = get_dac_if_single(codec, pins[i]); | |
3238 | if (!dac) | |
3239 | continue; | |
3240 | if (add_new_nid_path(codec, dac, pins[i], 0)) { | |
3241 | dacs[i] = dac; | |
3242 | found = true; | |
3243 | } | |
3244 | } | |
3245 | return found; | |
3246 | } | |
3247 | ||
3248 | /* fill in the dac_nids table from the parsed pin configuration */ | |
3249 | static int fill_and_eval_dacs(struct hda_codec *codec, | |
3250 | bool fill_hardwired, | |
3251 | bool fill_mio_first) | |
3252 | { | |
3253 | struct alc_spec *spec = codec->spec; | |
3254 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
3255 | int i, err, badness; | |
3256 | ||
3257 | /* set num_dacs once to full for alc_auto_look_for_dac() */ | |
3258 | spec->multiout.num_dacs = cfg->line_outs; | |
3259 | spec->multiout.dac_nids = spec->private_dac_nids; | |
3260 | memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids)); | |
3261 | memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid)); | |
3262 | memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid)); | |
3263 | spec->multi_ios = 0; | |
3264 | snd_array_free(&spec->paths); | |
3265 | badness = 0; | |
3266 | ||
3267 | /* fill hard-wired DACs first */ | |
3268 | if (fill_hardwired) { | |
3269 | bool mapped; | |
3270 | do { | |
3271 | mapped = alc_map_singles(codec, cfg->line_outs, | |
3272 | cfg->line_out_pins, | |
3273 | spec->private_dac_nids); | |
3274 | mapped |= alc_map_singles(codec, cfg->hp_outs, | |
3275 | cfg->hp_pins, | |
3276 | spec->multiout.hp_out_nid); | |
3277 | mapped |= alc_map_singles(codec, cfg->speaker_outs, | |
3278 | cfg->speaker_pins, | |
3279 | spec->multiout.extra_out_nid); | |
3280 | if (fill_mio_first && cfg->line_outs == 1 && | |
3281 | cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { | |
3282 | err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0); | |
3283 | if (!err) | |
3284 | mapped = true; | |
3285 | } | |
3286 | } while (mapped); | |
3287 | } | |
3288 | ||
3289 | badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins, | |
3290 | spec->private_dac_nids, | |
3291 | &main_out_badness); | |
3292 | ||
3293 | /* re-count num_dacs and squash invalid entries */ | |
3294 | spec->multiout.num_dacs = 0; | |
3295 | for (i = 0; i < cfg->line_outs; i++) { | |
3296 | if (spec->private_dac_nids[i]) | |
3297 | spec->multiout.num_dacs++; | |
3298 | else { | |
3299 | memmove(spec->private_dac_nids + i, | |
3300 | spec->private_dac_nids + i + 1, | |
3301 | sizeof(hda_nid_t) * (cfg->line_outs - i - 1)); | |
3302 | spec->private_dac_nids[cfg->line_outs - 1] = 0; | |
3303 | } | |
3304 | } | |
3305 | ||
3306 | if (fill_mio_first && | |
3307 | cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { | |
3308 | /* try to fill multi-io first */ | |
3309 | err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0); | |
3310 | if (err < 0) | |
3311 | return err; | |
3312 | /* we don't count badness at this stage yet */ | |
3313 | } | |
3314 | ||
3315 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) { | |
3316 | err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins, | |
3317 | spec->multiout.hp_out_nid, | |
3318 | &extra_out_badness); | |
3319 | if (err < 0) | |
3320 | return err; | |
3321 | badness += err; | |
3322 | } | |
3323 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { | |
3324 | err = alc_auto_fill_dacs(codec, cfg->speaker_outs, | |
3325 | cfg->speaker_pins, | |
3326 | spec->multiout.extra_out_nid, | |
3327 | &extra_out_badness); | |
3328 | if (err < 0) | |
3329 | return err; | |
3330 | badness += err; | |
3331 | } | |
3332 | if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { | |
3333 | err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0); | |
3334 | if (err < 0) | |
3335 | return err; | |
3336 | badness += err; | |
3337 | } | |
3338 | if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { | |
3339 | /* try multi-ios with HP + inputs */ | |
3340 | int offset = 0; | |
3341 | if (cfg->line_outs >= 3) | |
3342 | offset = 1; | |
3343 | err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false, | |
3344 | offset); | |
3345 | if (err < 0) | |
3346 | return err; | |
3347 | badness += err; | |
3348 | } | |
3349 | ||
3350 | if (spec->multi_ios == 2) { | |
3351 | for (i = 0; i < 2; i++) | |
3352 | spec->private_dac_nids[spec->multiout.num_dacs++] = | |
3353 | spec->multi_io[i].dac; | |
3354 | spec->ext_channel_count = 2; | |
3355 | } else if (spec->multi_ios) { | |
3356 | spec->multi_ios = 0; | |
3357 | badness += BAD_MULTI_IO; | |
3358 | } | |
3359 | ||
3360 | return badness; | |
3361 | } | |
3362 | ||
3363 | #define DEBUG_BADNESS | |
3364 | ||
3365 | #ifdef DEBUG_BADNESS | |
3366 | #define debug_badness snd_printdd | |
3367 | #else | |
3368 | #define debug_badness(...) | |
3369 | #endif | |
3370 | ||
3371 | static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg) | |
3372 | { | |
3373 | debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n", | |
3374 | cfg->line_out_pins[0], cfg->line_out_pins[1], | |
3375 | cfg->line_out_pins[2], cfg->line_out_pins[2], | |
3376 | spec->multiout.dac_nids[0], | |
3377 | spec->multiout.dac_nids[1], | |
3378 | spec->multiout.dac_nids[2], | |
3379 | spec->multiout.dac_nids[3]); | |
3380 | if (spec->multi_ios > 0) | |
3381 | debug_badness("multi_ios(%d) = %x/%x : %x/%x\n", | |
3382 | spec->multi_ios, | |
3383 | spec->multi_io[0].pin, spec->multi_io[1].pin, | |
3384 | spec->multi_io[0].dac, spec->multi_io[1].dac); | |
3385 | debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n", | |
3386 | cfg->hp_pins[0], cfg->hp_pins[1], | |
3387 | cfg->hp_pins[2], cfg->hp_pins[2], | |
3388 | spec->multiout.hp_out_nid[0], | |
3389 | spec->multiout.hp_out_nid[1], | |
3390 | spec->multiout.hp_out_nid[2], | |
3391 | spec->multiout.hp_out_nid[3]); | |
3392 | debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n", | |
3393 | cfg->speaker_pins[0], cfg->speaker_pins[1], | |
3394 | cfg->speaker_pins[2], cfg->speaker_pins[3], | |
3395 | spec->multiout.extra_out_nid[0], | |
3396 | spec->multiout.extra_out_nid[1], | |
3397 | spec->multiout.extra_out_nid[2], | |
3398 | spec->multiout.extra_out_nid[3]); | |
3399 | } | |
3400 | ||
3401 | /* find all available DACs of the codec */ | |
3402 | static void alc_fill_all_nids(struct hda_codec *codec) | |
3403 | { | |
3404 | struct alc_spec *spec = codec->spec; | |
3405 | int i; | |
3406 | hda_nid_t nid = codec->start_nid; | |
3407 | ||
3408 | spec->num_all_dacs = 0; | |
3409 | memset(spec->all_dacs, 0, sizeof(spec->all_dacs)); | |
3410 | for (i = 0; i < codec->num_nodes; i++, nid++) { | |
3411 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT) | |
3412 | continue; | |
3413 | if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) { | |
3414 | snd_printk(KERN_ERR "hda: Too many DACs!\n"); | |
3415 | break; | |
3416 | } | |
3417 | spec->all_dacs[spec->num_all_dacs++] = nid; | |
3418 | } | |
3419 | } | |
3420 | ||
3421 | static int alc_auto_fill_dac_nids(struct hda_codec *codec) | |
3422 | { | |
3423 | struct alc_spec *spec = codec->spec; | |
3424 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
3425 | struct auto_pin_cfg *best_cfg; | |
3426 | int best_badness = INT_MAX; | |
3427 | int badness; | |
3428 | bool fill_hardwired = true, fill_mio_first = true; | |
3429 | bool best_wired = true, best_mio = true; | |
3430 | bool hp_spk_swapped = false; | |
3431 | ||
3432 | alc_fill_all_nids(codec); | |
3433 | ||
3434 | best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL); | |
3435 | if (!best_cfg) | |
3436 | return -ENOMEM; | |
3437 | *best_cfg = *cfg; | |
3438 | ||
3439 | for (;;) { | |
3440 | badness = fill_and_eval_dacs(codec, fill_hardwired, | |
3441 | fill_mio_first); | |
3442 | if (badness < 0) { | |
3443 | kfree(best_cfg); | |
3444 | return badness; | |
3445 | } | |
3446 | debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n", | |
3447 | cfg->line_out_type, fill_hardwired, fill_mio_first, | |
3448 | badness); | |
3449 | debug_show_configs(spec, cfg); | |
3450 | if (badness < best_badness) { | |
3451 | best_badness = badness; | |
3452 | *best_cfg = *cfg; | |
3453 | best_wired = fill_hardwired; | |
3454 | best_mio = fill_mio_first; | |
3455 | } | |
3456 | if (!badness) | |
3457 | break; | |
3458 | fill_mio_first = !fill_mio_first; | |
3459 | if (!fill_mio_first) | |
3460 | continue; | |
3461 | fill_hardwired = !fill_hardwired; | |
3462 | if (!fill_hardwired) | |
3463 | continue; | |
3464 | if (hp_spk_swapped) | |
3465 | break; | |
3466 | hp_spk_swapped = true; | |
3467 | if (cfg->speaker_outs > 0 && | |
3468 | cfg->line_out_type == AUTO_PIN_HP_OUT) { | |
3469 | cfg->hp_outs = cfg->line_outs; | |
3470 | memcpy(cfg->hp_pins, cfg->line_out_pins, | |
3471 | sizeof(cfg->hp_pins)); | |
3472 | cfg->line_outs = cfg->speaker_outs; | |
3473 | memcpy(cfg->line_out_pins, cfg->speaker_pins, | |
3474 | sizeof(cfg->speaker_pins)); | |
3475 | cfg->speaker_outs = 0; | |
3476 | memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins)); | |
3477 | cfg->line_out_type = AUTO_PIN_SPEAKER_OUT; | |
3478 | fill_hardwired = true; | |
3479 | continue; | |
3480 | } | |
3481 | if (cfg->hp_outs > 0 && | |
3482 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { | |
3483 | cfg->speaker_outs = cfg->line_outs; | |
3484 | memcpy(cfg->speaker_pins, cfg->line_out_pins, | |
3485 | sizeof(cfg->speaker_pins)); | |
3486 | cfg->line_outs = cfg->hp_outs; | |
3487 | memcpy(cfg->line_out_pins, cfg->hp_pins, | |
3488 | sizeof(cfg->hp_pins)); | |
3489 | cfg->hp_outs = 0; | |
3490 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); | |
3491 | cfg->line_out_type = AUTO_PIN_HP_OUT; | |
3492 | fill_hardwired = true; | |
3493 | continue; | |
3494 | } | |
3495 | break; | |
3496 | } | |
3497 | ||
3498 | if (badness) { | |
3499 | *cfg = *best_cfg; | |
3500 | fill_and_eval_dacs(codec, best_wired, best_mio); | |
3501 | } | |
3502 | debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n", | |
3503 | cfg->line_out_type, best_wired, best_mio); | |
3504 | debug_show_configs(spec, cfg); | |
3505 | ||
3506 | if (cfg->line_out_pins[0]) { | |
3507 | struct nid_path *path = get_nid_path(codec, | |
3508 | spec->multiout.dac_nids[0], | |
3509 | cfg->line_out_pins[0]); | |
3510 | if (path) | |
3511 | spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path); | |
3512 | } | |
3513 | ||
3514 | kfree(best_cfg); | |
3515 | return 0; | |
3516 | } | |
3517 | ||
3518 | /* replace the channels in the composed amp value with the given number */ | |
3519 | static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs) | |
3520 | { | |
3521 | val &= ~(0x3U << 16); | |
3522 | val |= chs << 16; | |
3523 | return val; | |
3524 | } | |
3525 | ||
3526 | static int alc_auto_add_vol_ctl(struct hda_codec *codec, | |
3527 | const char *pfx, int cidx, | |
3528 | unsigned int chs, | |
3529 | struct nid_path *path) | |
3530 | { | |
3531 | unsigned int val; | |
3532 | if (!path) | |
3533 | return 0; | |
3534 | val = path->ctls[NID_PATH_VOL_CTL]; | |
3535 | if (!val) | |
3536 | return 0; | |
3537 | val = amp_val_replace_channels(val, chs); | |
3538 | return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val); | |
3539 | } | |
3540 | ||
3541 | /* return the channel bits suitable for the given path->ctls[] */ | |
3542 | static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path, | |
3543 | int type) | |
3544 | { | |
3545 | int chs = 1; /* mono (left only) */ | |
3546 | if (path) { | |
3547 | hda_nid_t nid = get_amp_nid_(path->ctls[type]); | |
3548 | if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO)) | |
3549 | chs = 3; /* stereo */ | |
3550 | } | |
3551 | return chs; | |
3552 | } | |
3553 | ||
3554 | static int alc_auto_add_stereo_vol(struct hda_codec *codec, | |
3555 | const char *pfx, int cidx, | |
3556 | struct nid_path *path) | |
3557 | { | |
3558 | int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL); | |
3559 | return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path); | |
3560 | } | |
3561 | ||
3562 | /* create a mute-switch for the given mixer widget; | |
3563 | * if it has multiple sources (e.g. DAC and loopback), create a bind-mute | |
3564 | */ | |
3565 | static int alc_auto_add_sw_ctl(struct hda_codec *codec, | |
3566 | const char *pfx, int cidx, | |
3567 | unsigned int chs, | |
3568 | struct nid_path *path) | |
3569 | { | |
3570 | unsigned int val; | |
3571 | int type = ALC_CTL_WIDGET_MUTE; | |
3572 | ||
3573 | if (!path) | |
3574 | return 0; | |
3575 | val = path->ctls[NID_PATH_MUTE_CTL]; | |
3576 | if (!val) | |
3577 | return 0; | |
3578 | val = amp_val_replace_channels(val, chs); | |
3579 | if (get_amp_direction_(val) == HDA_INPUT) { | |
3580 | hda_nid_t nid = get_amp_nid_(val); | |
3581 | int nums = snd_hda_get_num_conns(codec, nid); | |
3582 | if (nums > 1) { | |
3583 | type = ALC_CTL_BIND_MUTE; | |
3584 | val |= nums << 19; | |
3585 | } | |
3586 | } | |
3587 | return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val); | |
3588 | } | |
3589 | ||
3590 | static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx, | |
3591 | int cidx, struct nid_path *path) | |
3592 | { | |
3593 | int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL); | |
3594 | return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path); | |
3595 | } | |
3596 | ||
3597 | static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec, | |
3598 | struct nid_path *path) | |
3599 | { | |
3600 | int i; | |
3601 | ||
3602 | for (i = path->depth - 1; i >= 0; i--) { | |
3603 | if (nid_has_mute(codec, path->path[i], HDA_OUTPUT)) | |
3604 | return path->path[i]; | |
3605 | if (i != path->depth - 1 && i != 0 && | |
3606 | nid_has_mute(codec, path->path[i], HDA_INPUT)) | |
3607 | return path->path[i]; | |
3608 | } | |
3609 | return 0; | |
3610 | } | |
3611 | ||
3612 | static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec, | |
3613 | struct nid_path *path) | |
3614 | { | |
3615 | int i; | |
3616 | ||
3617 | for (i = path->depth - 1; i >= 0; i--) { | |
3618 | if (nid_has_volume(codec, path->path[i], HDA_OUTPUT)) | |
3619 | return path->path[i]; | |
3620 | } | |
3621 | return 0; | |
3622 | } | |
3623 | ||
3624 | /* add playback controls from the parsed DAC table */ | |
3625 | static int alc_auto_create_multi_out_ctls(struct hda_codec *codec, | |
3626 | const struct auto_pin_cfg *cfg) | |
3627 | { | |
3628 | struct alc_spec *spec = codec->spec; | |
3629 | int i, err, noutputs; | |
3630 | ||
3631 | noutputs = cfg->line_outs; | |
3632 | if (spec->multi_ios > 0 && cfg->line_outs < 3) | |
3633 | noutputs += spec->multi_ios; | |
3634 | ||
3635 | for (i = 0; i < noutputs; i++) { | |
3636 | const char *name; | |
3637 | int index; | |
3638 | hda_nid_t dac, pin; | |
3639 | struct nid_path *path; | |
3640 | ||
3641 | dac = spec->multiout.dac_nids[i]; | |
3642 | if (!dac) | |
3643 | continue; | |
3644 | if (i >= cfg->line_outs) { | |
3645 | pin = spec->multi_io[i - 1].pin; | |
3646 | index = 0; | |
3647 | name = channel_name[i]; | |
3648 | } else { | |
3649 | pin = cfg->line_out_pins[i]; | |
3650 | name = alc_get_line_out_pfx(spec, i, true, &index); | |
3651 | } | |
3652 | ||
3653 | path = get_nid_path(codec, dac, pin); | |
3654 | if (!path) | |
3655 | continue; | |
3656 | if (!name || !strcmp(name, "CLFE")) { | |
3657 | /* Center/LFE */ | |
3658 | err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path); | |
3659 | if (err < 0) | |
3660 | return err; | |
3661 | err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path); | |
3662 | if (err < 0) | |
3663 | return err; | |
3664 | err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path); | |
3665 | if (err < 0) | |
3666 | return err; | |
3667 | err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path); | |
3668 | if (err < 0) | |
3669 | return err; | |
3670 | } else { | |
3671 | err = alc_auto_add_stereo_vol(codec, name, index, path); | |
3672 | if (err < 0) | |
3673 | return err; | |
3674 | err = alc_auto_add_stereo_sw(codec, name, index, path); | |
3675 | if (err < 0) | |
3676 | return err; | |
3677 | } | |
3678 | } | |
3679 | return 0; | |
3680 | } | |
3681 | ||
3682 | static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin, | |
3683 | hda_nid_t dac, const char *pfx, | |
3684 | int cidx) | |
3685 | { | |
3686 | struct nid_path *path; | |
3687 | int err; | |
3688 | ||
3689 | path = get_nid_path(codec, dac, pin); | |
3690 | if (!path) | |
3691 | return 0; | |
3692 | /* bind volume control will be created in the case of dac = 0 */ | |
3693 | if (dac) { | |
3694 | err = alc_auto_add_stereo_vol(codec, pfx, cidx, path); | |
3695 | if (err < 0) | |
3696 | return err; | |
3697 | } | |
3698 | err = alc_auto_add_stereo_sw(codec, pfx, cidx, path); | |
3699 | if (err < 0) | |
3700 | return err; | |
3701 | return 0; | |
3702 | } | |
3703 | ||
3704 | static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec, | |
3705 | unsigned int nums, | |
3706 | struct hda_ctl_ops *ops) | |
3707 | { | |
3708 | struct alc_spec *spec = codec->spec; | |
3709 | struct hda_bind_ctls **ctlp, *ctl; | |
3710 | ctlp = snd_array_new(&spec->bind_ctls); | |
3711 | if (!ctlp) | |
3712 | return NULL; | |
3713 | ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL); | |
3714 | *ctlp = ctl; | |
3715 | if (ctl) | |
3716 | ctl->ops = ops; | |
3717 | return ctl; | |
3718 | } | |
3719 | ||
3720 | /* add playback controls for speaker and HP outputs */ | |
3721 | static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins, | |
3722 | const hda_nid_t *pins, | |
3723 | const hda_nid_t *dacs, | |
3724 | const char *pfx) | |
3725 | { | |
3726 | struct alc_spec *spec = codec->spec; | |
3727 | struct hda_bind_ctls *ctl; | |
3728 | char name[32]; | |
3729 | int i, n, err; | |
3730 | ||
3731 | if (!num_pins || !pins[0]) | |
3732 | return 0; | |
3733 | ||
3734 | if (num_pins == 1) { | |
3735 | hda_nid_t dac = *dacs; | |
3736 | if (!dac) | |
3737 | dac = spec->multiout.dac_nids[0]; | |
3738 | return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0); | |
3739 | } | |
3740 | ||
3741 | for (i = 0; i < num_pins; i++) { | |
3742 | hda_nid_t dac; | |
3743 | if (dacs[num_pins - 1]) | |
3744 | dac = dacs[i]; /* with individual volumes */ | |
3745 | else | |
3746 | dac = 0; | |
3747 | if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) { | |
3748 | err = alc_auto_create_extra_out(codec, pins[i], dac, | |
3749 | "Bass Speaker", 0); | |
3750 | } else if (num_pins >= 3) { | |
3751 | snprintf(name, sizeof(name), "%s %s", | |
3752 | pfx, channel_name[i]); | |
3753 | err = alc_auto_create_extra_out(codec, pins[i], dac, | |
3754 | name, 0); | |
3755 | } else { | |
3756 | err = alc_auto_create_extra_out(codec, pins[i], dac, | |
3757 | pfx, i); | |
3758 | } | |
3759 | if (err < 0) | |
3760 | return err; | |
3761 | } | |
3762 | if (dacs[num_pins - 1]) | |
3763 | return 0; | |
3764 | ||
3765 | /* Let's create a bind-controls for volumes */ | |
3766 | ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol); | |
3767 | if (!ctl) | |
3768 | return -ENOMEM; | |
3769 | n = 0; | |
3770 | for (i = 0; i < num_pins; i++) { | |
3771 | hda_nid_t vol; | |
3772 | struct nid_path *path; | |
3773 | if (!pins[i] || !dacs[i]) | |
3774 | continue; | |
3775 | path = get_nid_path(codec, dacs[i], pins[i]); | |
3776 | if (!path) | |
3777 | continue; | |
3778 | vol = alc_look_for_out_vol_nid(codec, path); | |
3779 | if (vol) | |
3780 | ctl->values[n++] = | |
3781 | HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT); | |
3782 | } | |
3783 | if (n) { | |
3784 | snprintf(name, sizeof(name), "%s Playback Volume", pfx); | |
3785 | err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl); | |
3786 | if (err < 0) | |
3787 | return err; | |
3788 | } | |
3789 | return 0; | |
3790 | } | |
3791 | ||
3792 | static int alc_auto_create_hp_out(struct hda_codec *codec) | |
3793 | { | |
3794 | struct alc_spec *spec = codec->spec; | |
3795 | return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs, | |
3796 | spec->autocfg.hp_pins, | |
3797 | spec->multiout.hp_out_nid, | |
3798 | "Headphone"); | |
3799 | } | |
3800 | ||
3801 | static int alc_auto_create_speaker_out(struct hda_codec *codec) | |
3802 | { | |
3803 | struct alc_spec *spec = codec->spec; | |
3804 | return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs, | |
3805 | spec->autocfg.speaker_pins, | |
3806 | spec->multiout.extra_out_nid, | |
3807 | "Speaker"); | |
3808 | } | |
3809 | ||
3810 | /* check whether a control with the given (nid, dir, idx) was assigned */ | |
3811 | static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid, | |
3812 | int dir, int idx) | |
3813 | { | |
3814 | struct alc_spec *spec = codec->spec; | |
3815 | int i, type; | |
3816 | ||
3817 | for (i = 0; i < spec->paths.used; i++) { | |
3818 | struct nid_path *p = snd_array_elem(&spec->paths, i); | |
3819 | if (p->depth <= 0) | |
3820 | continue; | |
3821 | for (type = 0; type < NID_PATH_NUM_CTLS; type++) { | |
3822 | unsigned int val = p->ctls[type]; | |
3823 | if (get_amp_nid_(val) == nid && | |
3824 | get_amp_direction_(val) == dir && | |
3825 | get_amp_index_(val) == idx) | |
3826 | return true; | |
3827 | } | |
3828 | } | |
3829 | return false; | |
3830 | } | |
3831 | ||
3832 | /* can have the amp-in capability? */ | |
3833 | static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx) | |
3834 | { | |
3835 | hda_nid_t nid = path->path[idx]; | |
3836 | unsigned int caps = get_wcaps(codec, nid); | |
3837 | unsigned int type = get_wcaps_type(caps); | |
3838 | ||
3839 | if (!(caps & AC_WCAP_IN_AMP)) | |
3840 | return false; | |
3841 | if (type == AC_WID_PIN && idx > 0) /* only for input pins */ | |
3842 | return false; | |
3843 | return true; | |
3844 | } | |
3845 | ||
3846 | /* can have the amp-out capability? */ | |
3847 | static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx) | |
3848 | { | |
3849 | hda_nid_t nid = path->path[idx]; | |
3850 | unsigned int caps = get_wcaps(codec, nid); | |
3851 | unsigned int type = get_wcaps_type(caps); | |
3852 | ||
3853 | if (!(caps & AC_WCAP_OUT_AMP)) | |
3854 | return false; | |
3855 | if (type == AC_WID_PIN && !idx) /* only for output pins */ | |
3856 | return false; | |
3857 | return true; | |
3858 | } | |
3859 | ||
3860 | /* check whether the given (nid,dir,idx) is active */ | |
3861 | static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid, | |
3862 | unsigned int idx, unsigned int dir) | |
3863 | { | |
3864 | struct alc_spec *spec = codec->spec; | |
3865 | int i, n; | |
3866 | ||
3867 | for (n = 0; n < spec->paths.used; n++) { | |
3868 | struct nid_path *path = snd_array_elem(&spec->paths, n); | |
3869 | if (!path->active) | |
3870 | continue; | |
3871 | for (i = 0; i < path->depth; i++) { | |
3872 | if (path->path[i] == nid) { | |
3873 | if (dir == HDA_OUTPUT || path->idx[i] == idx) | |
3874 | return true; | |
3875 | break; | |
3876 | } | |
3877 | } | |
3878 | } | |
3879 | return false; | |
3880 | } | |
3881 | ||
3882 | /* get the default amp value for the target state */ | |
3883 | static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid, | |
3884 | int dir, bool enable) | |
3885 | { | |
3886 | unsigned int caps; | |
3887 | unsigned int val = 0; | |
3888 | ||
3889 | caps = query_amp_caps(codec, nid, dir); | |
3890 | if (caps & AC_AMPCAP_NUM_STEPS) { | |
3891 | /* set to 0dB */ | |
3892 | if (enable) | |
3893 | val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT; | |
3894 | } | |
3895 | if (caps & AC_AMPCAP_MUTE) { | |
3896 | if (!enable) | |
3897 | val |= HDA_AMP_MUTE; | |
3898 | } | |
3899 | return val; | |
3900 | } | |
3901 | ||
3902 | /* initialize the amp value (only at the first time) */ | |
3903 | static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx) | |
3904 | { | |
3905 | int val = get_amp_val_to_activate(codec, nid, dir, false); | |
3906 | snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val); | |
3907 | } | |
3908 | ||
3909 | static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir, | |
3910 | int idx, bool enable) | |
3911 | { | |
3912 | int val; | |
3913 | if (is_ctl_associated(codec, nid, dir, idx) || | |
3914 | is_active_nid(codec, nid, dir, idx)) | |
3915 | return; | |
3916 | val = get_amp_val_to_activate(codec, nid, dir, enable); | |
3917 | snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val); | |
3918 | } | |
3919 | ||
3920 | static void activate_amp_out(struct hda_codec *codec, struct nid_path *path, | |
3921 | int i, bool enable) | |
3922 | { | |
3923 | hda_nid_t nid = path->path[i]; | |
3924 | init_amp(codec, nid, HDA_OUTPUT, 0); | |
3925 | activate_amp(codec, nid, HDA_OUTPUT, 0, enable); | |
3926 | } | |
3927 | ||
3928 | static void activate_amp_in(struct hda_codec *codec, struct nid_path *path, | |
3929 | int i, bool enable, bool add_aamix) | |
3930 | { | |
3931 | struct alc_spec *spec = codec->spec; | |
3932 | hda_nid_t conn[16]; | |
3933 | int n, nums, idx; | |
3934 | int type; | |
3935 | hda_nid_t nid = path->path[i]; | |
3936 | ||
3937 | nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn)); | |
3938 | type = get_wcaps_type(get_wcaps(codec, nid)); | |
3939 | if (type == AC_WID_PIN || | |
3940 | (type == AC_WID_AUD_IN && codec->single_adc_amp)) { | |
3941 | nums = 1; | |
3942 | idx = 0; | |
3943 | } else | |
3944 | idx = path->idx[i]; | |
3945 | ||
3946 | for (n = 0; n < nums; n++) | |
3947 | init_amp(codec, nid, HDA_INPUT, n); | |
3948 | ||
3949 | if (is_ctl_associated(codec, nid, HDA_INPUT, idx)) | |
3950 | return; | |
3951 | ||
3952 | /* here is a little bit tricky in comparison with activate_amp_out(); | |
3953 | * when aa-mixer is available, we need to enable the path as well | |
3954 | */ | |
3955 | for (n = 0; n < nums; n++) { | |
3956 | if (n != idx && (!add_aamix || conn[n] != spec->mixer_nid)) | |
3957 | continue; | |
3958 | activate_amp(codec, nid, HDA_INPUT, n, enable); | |
3959 | } | |
3960 | } | |
3961 | ||
3962 | static void activate_path(struct hda_codec *codec, struct nid_path *path, | |
3963 | bool enable, bool add_aamix) | |
3964 | { | |
3965 | int i; | |
3966 | ||
3967 | if (!enable) | |
3968 | path->active = false; | |
3969 | ||
3970 | for (i = path->depth - 1; i >= 0; i--) { | |
3971 | if (enable && path->multi[i]) | |
3972 | snd_hda_codec_write_cache(codec, path->path[i], 0, | |
3973 | AC_VERB_SET_CONNECT_SEL, | |
3974 | path->idx[i]); | |
3975 | if (has_amp_in(codec, path, i)) | |
3976 | activate_amp_in(codec, path, i, enable, add_aamix); | |
3977 | if (has_amp_out(codec, path, i)) | |
3978 | activate_amp_out(codec, path, i, enable); | |
3979 | } | |
3980 | ||
3981 | if (enable) | |
3982 | path->active = true; | |
3983 | } | |
3984 | ||
3985 | /* configure the path from the given dac to the pin as the proper output */ | |
3986 | static void alc_auto_set_output_and_unmute(struct hda_codec *codec, | |
3987 | hda_nid_t pin, int pin_type, | |
3988 | hda_nid_t dac) | |
3989 | { | |
3990 | struct nid_path *path; | |
3991 | ||
3992 | snd_hda_set_pin_ctl_cache(codec, pin, pin_type); | |
3993 | path = get_nid_path(codec, dac, pin); | |
3994 | if (!path) | |
3995 | return; | |
3996 | if (path->active) | |
3997 | return; | |
3998 | activate_path(codec, path, true, true); | |
3999 | } | |
4000 | ||
4001 | static void alc_auto_init_multi_out(struct hda_codec *codec) | |
4002 | { | |
4003 | struct alc_spec *spec = codec->spec; | |
4004 | int pin_type = get_pin_type(spec->autocfg.line_out_type); | |
4005 | int i; | |
4006 | ||
4007 | for (i = 0; i <= HDA_SIDE; i++) { | |
4008 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; | |
4009 | if (nid) | |
4010 | alc_auto_set_output_and_unmute(codec, nid, pin_type, | |
4011 | spec->multiout.dac_nids[i]); | |
4012 | ||
4013 | } | |
4014 | } | |
4015 | ||
4016 | static void alc_auto_init_extra_out(struct hda_codec *codec) | |
4017 | { | |
4018 | struct alc_spec *spec = codec->spec; | |
4019 | int i; | |
4020 | hda_nid_t pin, dac; | |
4021 | ||
4022 | for (i = 0; i < spec->autocfg.hp_outs; i++) { | |
4023 | if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT) | |
4024 | break; | |
4025 | pin = spec->autocfg.hp_pins[i]; | |
4026 | if (!pin) | |
4027 | break; | |
4028 | dac = spec->multiout.hp_out_nid[i]; | |
4029 | if (!dac) { | |
4030 | if (i > 0 && spec->multiout.hp_out_nid[0]) | |
4031 | dac = spec->multiout.hp_out_nid[0]; | |
4032 | else | |
4033 | dac = spec->multiout.dac_nids[0]; | |
4034 | } | |
4035 | alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac); | |
4036 | } | |
4037 | for (i = 0; i < spec->autocfg.speaker_outs; i++) { | |
4038 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) | |
4039 | break; | |
4040 | pin = spec->autocfg.speaker_pins[i]; | |
4041 | if (!pin) | |
4042 | break; | |
4043 | dac = spec->multiout.extra_out_nid[i]; | |
4044 | if (!dac) { | |
4045 | if (i > 0 && spec->multiout.extra_out_nid[0]) | |
4046 | dac = spec->multiout.extra_out_nid[0]; | |
4047 | else | |
4048 | dac = spec->multiout.dac_nids[0]; | |
4049 | } | |
4050 | alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac); | |
4051 | } | |
4052 | } | |
4053 | ||
4054 | /* check whether the given pin can be a multi-io pin */ | |
4055 | static bool can_be_multiio_pin(struct hda_codec *codec, | |
4056 | unsigned int location, hda_nid_t nid) | |
4057 | { | |
4058 | unsigned int defcfg, caps; | |
4059 | ||
4060 | defcfg = snd_hda_codec_get_pincfg(codec, nid); | |
4061 | if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX) | |
4062 | return false; | |
4063 | if (location && get_defcfg_location(defcfg) != location) | |
4064 | return false; | |
4065 | caps = snd_hda_query_pin_caps(codec, nid); | |
4066 | if (!(caps & AC_PINCAP_OUT)) | |
4067 | return false; | |
4068 | return true; | |
4069 | } | |
4070 | ||
4071 | /* | |
4072 | * multi-io helper | |
4073 | * | |
4074 | * When hardwired is set, try to fill ony hardwired pins, and returns | |
4075 | * zero if any pins are filled, non-zero if nothing found. | |
4076 | * When hardwired is off, try to fill possible input pins, and returns | |
4077 | * the badness value. | |
4078 | */ | |
4079 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, | |
4080 | hda_nid_t reference_pin, | |
4081 | bool hardwired, int offset) | |
4082 | { | |
4083 | struct alc_spec *spec = codec->spec; | |
4084 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
4085 | int type, i, j, dacs, num_pins, old_pins; | |
4086 | unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin); | |
4087 | unsigned int location = get_defcfg_location(defcfg); | |
4088 | int badness = 0; | |
4089 | ||
4090 | old_pins = spec->multi_ios; | |
4091 | if (old_pins >= 2) | |
4092 | goto end_fill; | |
4093 | ||
4094 | num_pins = 0; | |
4095 | for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { | |
4096 | for (i = 0; i < cfg->num_inputs; i++) { | |
4097 | if (cfg->inputs[i].type != type) | |
4098 | continue; | |
4099 | if (can_be_multiio_pin(codec, location, | |
4100 | cfg->inputs[i].pin)) | |
4101 | num_pins++; | |
4102 | } | |
4103 | } | |
4104 | if (num_pins < 2) | |
4105 | goto end_fill; | |
4106 | ||
4107 | dacs = spec->multiout.num_dacs; | |
4108 | for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { | |
4109 | for (i = 0; i < cfg->num_inputs; i++) { | |
4110 | hda_nid_t nid = cfg->inputs[i].pin; | |
4111 | hda_nid_t dac = 0; | |
4112 | ||
4113 | if (cfg->inputs[i].type != type) | |
4114 | continue; | |
4115 | if (!can_be_multiio_pin(codec, location, nid)) | |
4116 | continue; | |
4117 | for (j = 0; j < spec->multi_ios; j++) { | |
4118 | if (nid == spec->multi_io[j].pin) | |
4119 | break; | |
4120 | } | |
4121 | if (j < spec->multi_ios) | |
4122 | continue; | |
4123 | ||
4124 | if (offset && offset + spec->multi_ios < dacs) { | |
4125 | dac = spec->private_dac_nids[offset + spec->multi_ios]; | |
4126 | if (!is_reachable_path(codec, dac, nid)) | |
4127 | dac = 0; | |
4128 | } | |
4129 | if (hardwired) | |
4130 | dac = get_dac_if_single(codec, nid); | |
4131 | else if (!dac) | |
4132 | dac = alc_auto_look_for_dac(codec, nid, false); | |
4133 | if (!dac) { | |
4134 | badness++; | |
4135 | continue; | |
4136 | } | |
4137 | if (!add_new_nid_path(codec, dac, nid, 0)) { | |
4138 | badness++; | |
4139 | continue; | |
4140 | } | |
4141 | spec->multi_io[spec->multi_ios].pin = nid; | |
4142 | spec->multi_io[spec->multi_ios].dac = dac; | |
4143 | spec->multi_ios++; | |
4144 | if (spec->multi_ios >= 2) | |
4145 | break; | |
4146 | } | |
4147 | } | |
4148 | end_fill: | |
4149 | if (badness) | |
4150 | badness = BAD_MULTI_IO; | |
4151 | if (old_pins == spec->multi_ios) { | |
4152 | if (hardwired) | |
4153 | return 1; /* nothing found */ | |
4154 | else | |
4155 | return badness; /* no badness if nothing found */ | |
4156 | } | |
4157 | if (!hardwired && spec->multi_ios < 2) { | |
4158 | /* cancel newly assigned paths */ | |
4159 | spec->paths.used -= spec->multi_ios - old_pins; | |
4160 | spec->multi_ios = old_pins; | |
4161 | return badness; | |
4162 | } | |
4163 | ||
4164 | /* assign volume and mute controls */ | |
4165 | for (i = old_pins; i < spec->multi_ios; i++) | |
4166 | badness += assign_out_path_ctls(codec, spec->multi_io[i].pin, | |
4167 | spec->multi_io[i].dac); | |
4168 | ||
4169 | return badness; | |
4170 | } | |
4171 | ||
4172 | static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol, | |
4173 | struct snd_ctl_elem_info *uinfo) | |
4174 | { | |
4175 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
4176 | struct alc_spec *spec = codec->spec; | |
4177 | ||
4178 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
4179 | uinfo->count = 1; | |
4180 | uinfo->value.enumerated.items = spec->multi_ios + 1; | |
4181 | if (uinfo->value.enumerated.item > spec->multi_ios) | |
4182 | uinfo->value.enumerated.item = spec->multi_ios; | |
4183 | sprintf(uinfo->value.enumerated.name, "%dch", | |
4184 | (uinfo->value.enumerated.item + 1) * 2); | |
4185 | return 0; | |
4186 | } | |
4187 | ||
4188 | static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol, | |
4189 | struct snd_ctl_elem_value *ucontrol) | |
4190 | { | |
4191 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
4192 | struct alc_spec *spec = codec->spec; | |
4193 | ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2; | |
4194 | return 0; | |
4195 | } | |
4196 | ||
4197 | static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output) | |
4198 | { | |
4199 | struct alc_spec *spec = codec->spec; | |
4200 | hda_nid_t nid = spec->multi_io[idx].pin; | |
4201 | struct nid_path *path; | |
4202 | ||
4203 | path = get_nid_path(codec, spec->multi_io[idx].dac, nid); | |
4204 | if (!path) | |
4205 | return -EINVAL; | |
4206 | ||
4207 | if (path->active == output) | |
4208 | return 0; | |
4209 | ||
4210 | if (output) { | |
4211 | snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT); | |
4212 | activate_path(codec, path, true, true); | |
4213 | } else { | |
4214 | activate_path(codec, path, false, true); | |
4215 | snd_hda_set_pin_ctl_cache(codec, nid, | |
4216 | spec->multi_io[idx].ctl_in); | |
4217 | } | |
4218 | return 0; | |
4219 | } | |
4220 | ||
4221 | static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol, | |
4222 | struct snd_ctl_elem_value *ucontrol) | |
4223 | { | |
4224 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
4225 | struct alc_spec *spec = codec->spec; | |
4226 | int i, ch; | |
4227 | ||
4228 | ch = ucontrol->value.enumerated.item[0]; | |
4229 | if (ch < 0 || ch > spec->multi_ios) | |
4230 | return -EINVAL; | |
4231 | if (ch == (spec->ext_channel_count - 1) / 2) | |
4232 | return 0; | |
4233 | spec->ext_channel_count = (ch + 1) * 2; | |
4234 | for (i = 0; i < spec->multi_ios; i++) | |
4235 | alc_set_multi_io(codec, i, i < ch); | |
4236 | spec->multiout.max_channels = max(spec->ext_channel_count, | |
4237 | spec->const_channel_count); | |
4238 | if (spec->need_dac_fix) | |
4239 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; | |
4240 | return 1; | |
4241 | } | |
4242 | ||
4243 | static const struct snd_kcontrol_new alc_auto_channel_mode_enum = { | |
4244 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
4245 | .name = "Channel Mode", | |
4246 | .info = alc_auto_ch_mode_info, | |
4247 | .get = alc_auto_ch_mode_get, | |
4248 | .put = alc_auto_ch_mode_put, | |
4249 | }; | |
4250 | ||
4251 | static int alc_auto_add_multi_channel_mode(struct hda_codec *codec) | |
4252 | { | |
4253 | struct alc_spec *spec = codec->spec; | |
4254 | ||
4255 | if (spec->multi_ios > 0) { | |
4256 | if (!alc_kcontrol_new(spec, NULL, &alc_auto_channel_mode_enum)) | |
4257 | return -ENOMEM; | |
4258 | } | |
4259 | return 0; | |
4260 | } | |
4261 | ||
4262 | static void alc_auto_init_multi_io(struct hda_codec *codec) | |
4263 | { | |
4264 | struct alc_spec *spec = codec->spec; | |
4265 | int i; | |
4266 | ||
4267 | for (i = 0; i < spec->multi_ios; i++) { | |
4268 | hda_nid_t pin = spec->multi_io[i].pin; | |
4269 | struct nid_path *path; | |
4270 | path = get_nid_path(codec, spec->multi_io[i].dac, pin); | |
4271 | if (!path) | |
4272 | continue; | |
4273 | if (!spec->multi_io[i].ctl_in) | |
4274 | spec->multi_io[i].ctl_in = | |
4275 | snd_hda_codec_update_cache(codec, pin, 0, | |
4276 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | |
4277 | activate_path(codec, path, path->active, true); | |
4278 | } | |
4279 | } | |
4280 | ||
4281 | /* | |
4282 | * initialize ADC paths | |
4283 | */ | |
4284 | static void alc_auto_init_input_src(struct hda_codec *codec) | |
4285 | { | |
4286 | struct alc_spec *spec = codec->spec; | |
4287 | struct hda_input_mux *imux = &spec->input_mux; | |
4288 | struct nid_path *path; | |
4289 | int i, c, nums; | |
4290 | ||
4291 | if (spec->dyn_adc_switch) | |
4292 | nums = 1; | |
4293 | else | |
4294 | nums = spec->num_adc_nids; | |
4295 | ||
4296 | for (c = 0; c < nums; c++) { | |
4297 | for (i = 0; i < imux->num_items; i++) { | |
4298 | path = get_nid_path(codec, spec->imux_pins[i], | |
4299 | get_adc_nid(codec, c, i)); | |
4300 | if (path) { | |
4301 | bool active = path->active; | |
4302 | if (i == spec->cur_mux[c]) | |
4303 | active = true; | |
4304 | activate_path(codec, path, active, false); | |
4305 | } | |
4306 | } | |
4307 | } | |
4308 | ||
4309 | alc_inv_dmic_sync(codec, true); | |
4310 | if (spec->shared_mic_hp) | |
4311 | update_shared_mic_hp(codec, spec->cur_mux[0]); | |
4312 | } | |
4313 | ||
4314 | /* add mic boosts if needed */ | |
4315 | static int alc_auto_add_mic_boost(struct hda_codec *codec) | |
4316 | { | |
4317 | struct alc_spec *spec = codec->spec; | |
4318 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
4319 | int i, err; | |
4320 | int type_idx = 0; | |
4321 | hda_nid_t nid; | |
4322 | const char *prev_label = NULL; | |
4323 | ||
4324 | for (i = 0; i < cfg->num_inputs; i++) { | |
4325 | if (cfg->inputs[i].type > AUTO_PIN_MIC) | |
4326 | break; | |
4327 | nid = cfg->inputs[i].pin; | |
4328 | if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { | |
4329 | const char *label; | |
4330 | char boost_label[32]; | |
4331 | struct nid_path *path; | |
4332 | unsigned int val; | |
4333 | ||
4334 | label = hda_get_autocfg_input_label(codec, cfg, i); | |
4335 | if (spec->shared_mic_hp && !strcmp(label, "Misc")) | |
4336 | label = "Headphone Mic"; | |
4337 | if (prev_label && !strcmp(label, prev_label)) | |
4338 | type_idx++; | |
4339 | else | |
4340 | type_idx = 0; | |
4341 | prev_label = label; | |
4342 | ||
4343 | snprintf(boost_label, sizeof(boost_label), | |
4344 | "%s Boost Volume", label); | |
4345 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT); | |
4346 | err = add_control(spec, ALC_CTL_WIDGET_VOL, | |
4347 | boost_label, type_idx, val); | |
4348 | if (err < 0) | |
4349 | return err; | |
4350 | ||
4351 | path = get_nid_path(codec, nid, 0); | |
4352 | if (path) | |
4353 | path->ctls[NID_PATH_BOOST_CTL] = val; | |
4354 | } | |
4355 | } | |
4356 | return 0; | |
4357 | } | |
4358 | ||
4359 | /* | |
4360 | * standard auto-parser initializations | |
4361 | */ | |
4362 | static void alc_auto_init_std(struct hda_codec *codec) | |
4363 | { | |
4364 | alc_auto_init_multi_out(codec); | |
4365 | alc_auto_init_extra_out(codec); | |
4366 | alc_auto_init_multi_io(codec); | |
4367 | alc_auto_init_analog_input(codec); | |
4368 | alc_auto_init_input_src(codec); | |
4369 | alc_auto_init_digital(codec); | |
4370 | /* call init functions of standard auto-mute helpers */ | |
4371 | alc_hp_automute(codec, NULL); | |
4372 | alc_line_automute(codec, NULL); | |
4373 | alc_mic_automute(codec, NULL); | |
4374 | } | |
4375 | ||
4376 | /* | |
4377 | * Digital-beep handlers | |
4378 | */ | |
4379 | #ifdef CONFIG_SND_HDA_INPUT_BEEP | |
4380 | #define set_beep_amp(spec, nid, idx, dir) \ | |
4381 | ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir)) | |
4382 | ||
4383 | static const struct snd_pci_quirk beep_white_list[] = { | |
4384 | SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1), | |
4385 | SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1), | |
4386 | SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1), | |
4387 | SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1), | |
4388 | SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1), | |
4389 | SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1), | |
4390 | SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1), | |
4391 | {} | |
4392 | }; | |
4393 | ||
4394 | static inline int has_cdefine_beep(struct hda_codec *codec) | |
4395 | { | |
4396 | struct alc_spec *spec = codec->spec; | |
4397 | const struct snd_pci_quirk *q; | |
4398 | q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list); | |
4399 | if (q) | |
4400 | return q->value; | |
4401 | return spec->cdefine.enable_pcbeep; | |
4402 | } | |
4403 | #else | |
4404 | #define set_beep_amp(spec, nid, idx, dir) /* NOP */ | |
4405 | #define has_cdefine_beep(codec) 0 | |
4406 | #endif | |
4407 | ||
4408 | /* parse the BIOS configuration and set up the alc_spec */ | |
4409 | /* return 1 if successful, 0 if the proper config is not found, | |
4410 | * or a negative error code | |
4411 | */ | |
4412 | static int alc_parse_auto_config(struct hda_codec *codec, | |
4413 | const hda_nid_t *ignore_nids, | |
4414 | const hda_nid_t *ssid_nids) | |
4415 | { | |
4416 | struct alc_spec *spec = codec->spec; | |
4417 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
4418 | int err; | |
4419 | ||
4420 | err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids, | |
4421 | spec->parse_flags); | |
4422 | if (err < 0) | |
4423 | return err; | |
4424 | if (!cfg->line_outs) { | |
4425 | if (cfg->dig_outs || cfg->dig_in_pin) { | |
4426 | spec->multiout.max_channels = 2; | |
4427 | spec->no_analog = 1; | |
4428 | goto dig_only; | |
4429 | } | |
4430 | return 0; /* can't find valid BIOS pin config */ | |
4431 | } | |
4432 | ||
4433 | if (!spec->no_primary_hp && | |
4434 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && | |
4435 | cfg->line_outs <= cfg->hp_outs) { | |
4436 | /* use HP as primary out */ | |
4437 | cfg->speaker_outs = cfg->line_outs; | |
4438 | memcpy(cfg->speaker_pins, cfg->line_out_pins, | |
4439 | sizeof(cfg->speaker_pins)); | |
4440 | cfg->line_outs = cfg->hp_outs; | |
4441 | memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins)); | |
4442 | cfg->hp_outs = 0; | |
4443 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); | |
4444 | cfg->line_out_type = AUTO_PIN_HP_OUT; | |
4445 | } | |
4446 | ||
4447 | err = alc_auto_fill_dac_nids(codec); | |
4448 | if (err < 0) | |
4449 | return err; | |
4450 | err = alc_auto_add_multi_channel_mode(codec); | |
4451 | if (err < 0) | |
4452 | return err; | |
4453 | err = alc_auto_create_multi_out_ctls(codec, cfg); | |
4454 | if (err < 0) | |
4455 | return err; | |
4456 | err = alc_auto_create_hp_out(codec); | |
4457 | if (err < 0) | |
4458 | return err; | |
4459 | err = alc_auto_create_speaker_out(codec); | |
4460 | if (err < 0) | |
4461 | return err; | |
4462 | err = alc_auto_create_shared_input(codec); | |
4463 | if (err < 0) | |
4464 | return err; | |
4465 | err = alc_auto_create_input_ctls(codec); | |
4466 | if (err < 0) | |
4467 | return err; | |
4468 | ||
4469 | /* check the multiple speaker pins */ | |
4470 | if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) | |
4471 | spec->const_channel_count = cfg->line_outs * 2; | |
4472 | else | |
4473 | spec->const_channel_count = cfg->speaker_outs * 2; | |
4474 | ||
4475 | if (spec->multi_ios > 0) | |
4476 | spec->multiout.max_channels = max(spec->ext_channel_count, | |
4477 | spec->const_channel_count); | |
4478 | else | |
4479 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
4480 | ||
4481 | dig_only: | |
4482 | alc_auto_parse_digital(codec); | |
4483 | ||
4484 | if (ssid_nids) | |
4485 | alc_ssid_check(codec, ssid_nids); | |
4486 | ||
4487 | if (!spec->no_analog) { | |
4488 | err = alc_init_automute(codec); | |
4489 | if (err < 0) | |
4490 | return err; | |
4491 | ||
4492 | err = check_dyn_adc_switch(codec); | |
4493 | if (err < 0) | |
4494 | return err; | |
4495 | ||
4496 | if (!spec->shared_mic_hp) { | |
4497 | err = alc_init_auto_mic(codec); | |
4498 | if (err < 0) | |
4499 | return err; | |
4500 | } | |
4501 | ||
4502 | err = create_capture_mixers(codec); | |
4503 | if (err < 0) | |
4504 | return err; | |
4505 | ||
4506 | err = alc_auto_add_mic_boost(codec); | |
4507 | if (err < 0) | |
4508 | return err; | |
4509 | } | |
4510 | ||
4511 | if (spec->kctls.list) | |
4512 | add_mixer(spec, spec->kctls.list); | |
4513 | ||
4514 | return 1; | |
4515 | } | |
4516 | ||
4517 | /* common preparation job for alc_spec */ | |
4518 | static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid) | |
4519 | { | |
4520 | struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
4521 | int err; | |
4522 | ||
4523 | if (!spec) | |
4524 | return -ENOMEM; | |
4525 | codec->spec = spec; | |
4526 | codec->single_adc_amp = 1; | |
4527 | spec->mixer_nid = mixer_nid; | |
4528 | snd_hda_gen_init(&spec->gen); | |
4529 | snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32); | |
4530 | snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8); | |
4531 | snd_array_init(&spec->paths, sizeof(struct nid_path), 8); | |
4532 | ||
4533 | err = alc_codec_rename_from_preset(codec); | |
4534 | if (err < 0) { | |
4535 | kfree(spec); | |
4536 | return err; | |
4537 | } | |
4538 | return 0; | |
4539 | } | |
4540 | ||
4541 | static int alc880_parse_auto_config(struct hda_codec *codec) | |
4542 | { | |
4543 | static const hda_nid_t alc880_ignore[] = { 0x1d, 0 }; | |
4544 | static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 }; | |
4545 | return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids); | |
4546 | } | |
4547 | ||
4548 | /* | |
4549 | * ALC880 fix-ups | |
4550 | */ | |
4551 | enum { | |
4552 | ALC880_FIXUP_GPIO1, | |
4553 | ALC880_FIXUP_GPIO2, | |
4554 | ALC880_FIXUP_MEDION_RIM, | |
4555 | ALC880_FIXUP_LG, | |
4556 | ALC880_FIXUP_W810, | |
4557 | ALC880_FIXUP_EAPD_COEF, | |
4558 | ALC880_FIXUP_TCL_S700, | |
4559 | ALC880_FIXUP_VOL_KNOB, | |
4560 | ALC880_FIXUP_FUJITSU, | |
4561 | ALC880_FIXUP_F1734, | |
4562 | ALC880_FIXUP_UNIWILL, | |
4563 | ALC880_FIXUP_UNIWILL_DIG, | |
4564 | ALC880_FIXUP_Z71V, | |
4565 | ALC880_FIXUP_3ST_BASE, | |
4566 | ALC880_FIXUP_3ST, | |
4567 | ALC880_FIXUP_3ST_DIG, | |
4568 | ALC880_FIXUP_5ST_BASE, | |
4569 | ALC880_FIXUP_5ST, | |
4570 | ALC880_FIXUP_5ST_DIG, | |
4571 | ALC880_FIXUP_6ST_BASE, | |
4572 | ALC880_FIXUP_6ST, | |
4573 | ALC880_FIXUP_6ST_DIG, | |
4574 | }; | |
4575 | ||
4576 | /* enable the volume-knob widget support on NID 0x21 */ | |
4577 | static void alc880_fixup_vol_knob(struct hda_codec *codec, | |
4578 | const struct alc_fixup *fix, int action) | |
4579 | { | |
4580 | if (action == ALC_FIXUP_ACT_PROBE) | |
4581 | snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master); | |
4582 | } | |
4583 | ||
4584 | static const struct alc_fixup alc880_fixups[] = { | |
4585 | [ALC880_FIXUP_GPIO1] = { | |
4586 | .type = ALC_FIXUP_VERBS, | |
4587 | .v.verbs = alc_gpio1_init_verbs, | |
4588 | }, | |
4589 | [ALC880_FIXUP_GPIO2] = { | |
4590 | .type = ALC_FIXUP_VERBS, | |
4591 | .v.verbs = alc_gpio2_init_verbs, | |
4592 | }, | |
4593 | [ALC880_FIXUP_MEDION_RIM] = { | |
4594 | .type = ALC_FIXUP_VERBS, | |
4595 | .v.verbs = (const struct hda_verb[]) { | |
4596 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, | |
4597 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 }, | |
4598 | { } | |
4599 | }, | |
4600 | .chained = true, | |
4601 | .chain_id = ALC880_FIXUP_GPIO2, | |
4602 | }, | |
4603 | [ALC880_FIXUP_LG] = { | |
4604 | .type = ALC_FIXUP_PINS, | |
4605 | .v.pins = (const struct alc_pincfg[]) { | |
4606 | /* disable bogus unused pins */ | |
4607 | { 0x16, 0x411111f0 }, | |
4608 | { 0x18, 0x411111f0 }, | |
4609 | { 0x1a, 0x411111f0 }, | |
4610 | { } | |
4611 | } | |
4612 | }, | |
4613 | [ALC880_FIXUP_W810] = { | |
4614 | .type = ALC_FIXUP_PINS, | |
4615 | .v.pins = (const struct alc_pincfg[]) { | |
4616 | /* disable bogus unused pins */ | |
4617 | { 0x17, 0x411111f0 }, | |
4618 | { } | |
4619 | }, | |
4620 | .chained = true, | |
4621 | .chain_id = ALC880_FIXUP_GPIO2, | |
4622 | }, | |
4623 | [ALC880_FIXUP_EAPD_COEF] = { | |
4624 | .type = ALC_FIXUP_VERBS, | |
4625 | .v.verbs = (const struct hda_verb[]) { | |
4626 | /* change to EAPD mode */ | |
4627 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, | |
4628 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 }, | |
4629 | {} | |
4630 | }, | |
4631 | }, | |
4632 | [ALC880_FIXUP_TCL_S700] = { | |
4633 | .type = ALC_FIXUP_VERBS, | |
4634 | .v.verbs = (const struct hda_verb[]) { | |
4635 | /* change to EAPD mode */ | |
4636 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, | |
4637 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 }, | |
4638 | {} | |
4639 | }, | |
4640 | .chained = true, | |
4641 | .chain_id = ALC880_FIXUP_GPIO2, | |
4642 | }, | |
4643 | [ALC880_FIXUP_VOL_KNOB] = { | |
4644 | .type = ALC_FIXUP_FUNC, | |
4645 | .v.func = alc880_fixup_vol_knob, | |
4646 | }, | |
4647 | [ALC880_FIXUP_FUJITSU] = { | |
4648 | /* override all pins as BIOS on old Amilo is broken */ | |
4649 | .type = ALC_FIXUP_PINS, | |
4650 | .v.pins = (const struct alc_pincfg[]) { | |
4651 | { 0x14, 0x0121411f }, /* HP */ | |
4652 | { 0x15, 0x99030120 }, /* speaker */ | |
4653 | { 0x16, 0x99030130 }, /* bass speaker */ | |
4654 | { 0x17, 0x411111f0 }, /* N/A */ | |
4655 | { 0x18, 0x411111f0 }, /* N/A */ | |
4656 | { 0x19, 0x01a19950 }, /* mic-in */ | |
4657 | { 0x1a, 0x411111f0 }, /* N/A */ | |
4658 | { 0x1b, 0x411111f0 }, /* N/A */ | |
4659 | { 0x1c, 0x411111f0 }, /* N/A */ | |
4660 | { 0x1d, 0x411111f0 }, /* N/A */ | |
4661 | { 0x1e, 0x01454140 }, /* SPDIF out */ | |
4662 | { } | |
4663 | }, | |
4664 | .chained = true, | |
4665 | .chain_id = ALC880_FIXUP_VOL_KNOB, | |
4666 | }, | |
4667 | [ALC880_FIXUP_F1734] = { | |
4668 | /* almost compatible with FUJITSU, but no bass and SPDIF */ | |
4669 | .type = ALC_FIXUP_PINS, | |
4670 | .v.pins = (const struct alc_pincfg[]) { | |
4671 | { 0x14, 0x0121411f }, /* HP */ | |
4672 | { 0x15, 0x99030120 }, /* speaker */ | |
4673 | { 0x16, 0x411111f0 }, /* N/A */ | |
4674 | { 0x17, 0x411111f0 }, /* N/A */ | |
4675 | { 0x18, 0x411111f0 }, /* N/A */ | |
4676 | { 0x19, 0x01a19950 }, /* mic-in */ | |
4677 | { 0x1a, 0x411111f0 }, /* N/A */ | |
4678 | { 0x1b, 0x411111f0 }, /* N/A */ | |
4679 | { 0x1c, 0x411111f0 }, /* N/A */ | |
4680 | { 0x1d, 0x411111f0 }, /* N/A */ | |
4681 | { 0x1e, 0x411111f0 }, /* N/A */ | |
4682 | { } | |
4683 | }, | |
4684 | .chained = true, | |
4685 | .chain_id = ALC880_FIXUP_VOL_KNOB, | |
4686 | }, | |
4687 | [ALC880_FIXUP_UNIWILL] = { | |
4688 | /* need to fix HP and speaker pins to be parsed correctly */ | |
4689 | .type = ALC_FIXUP_PINS, | |
4690 | .v.pins = (const struct alc_pincfg[]) { | |
4691 | { 0x14, 0x0121411f }, /* HP */ | |
4692 | { 0x15, 0x99030120 }, /* speaker */ | |
4693 | { 0x16, 0x99030130 }, /* bass speaker */ | |
4694 | { } | |
4695 | }, | |
4696 | }, | |
4697 | [ALC880_FIXUP_UNIWILL_DIG] = { | |
4698 | .type = ALC_FIXUP_PINS, | |
4699 | .v.pins = (const struct alc_pincfg[]) { | |
4700 | /* disable bogus unused pins */ | |
4701 | { 0x17, 0x411111f0 }, | |
4702 | { 0x19, 0x411111f0 }, | |
4703 | { 0x1b, 0x411111f0 }, | |
4704 | { 0x1f, 0x411111f0 }, | |
4705 | { } | |
4706 | } | |
4707 | }, | |
4708 | [ALC880_FIXUP_Z71V] = { | |
4709 | .type = ALC_FIXUP_PINS, | |
4710 | .v.pins = (const struct alc_pincfg[]) { | |
4711 | /* set up the whole pins as BIOS is utterly broken */ | |
4712 | { 0x14, 0x99030120 }, /* speaker */ | |
4713 | { 0x15, 0x0121411f }, /* HP */ | |
4714 | { 0x16, 0x411111f0 }, /* N/A */ | |
4715 | { 0x17, 0x411111f0 }, /* N/A */ | |
4716 | { 0x18, 0x01a19950 }, /* mic-in */ | |
4717 | { 0x19, 0x411111f0 }, /* N/A */ | |
4718 | { 0x1a, 0x01813031 }, /* line-in */ | |
4719 | { 0x1b, 0x411111f0 }, /* N/A */ | |
4720 | { 0x1c, 0x411111f0 }, /* N/A */ | |
4721 | { 0x1d, 0x411111f0 }, /* N/A */ | |
4722 | { 0x1e, 0x0144111e }, /* SPDIF */ | |
4723 | { } | |
4724 | } | |
4725 | }, | |
4726 | [ALC880_FIXUP_3ST_BASE] = { | |
4727 | .type = ALC_FIXUP_PINS, | |
4728 | .v.pins = (const struct alc_pincfg[]) { | |
4729 | { 0x14, 0x01014010 }, /* line-out */ | |
4730 | { 0x15, 0x411111f0 }, /* N/A */ | |
4731 | { 0x16, 0x411111f0 }, /* N/A */ | |
4732 | { 0x17, 0x411111f0 }, /* N/A */ | |
4733 | { 0x18, 0x01a19c30 }, /* mic-in */ | |
4734 | { 0x19, 0x0121411f }, /* HP */ | |
4735 | { 0x1a, 0x01813031 }, /* line-in */ | |
4736 | { 0x1b, 0x02a19c40 }, /* front-mic */ | |
4737 | { 0x1c, 0x411111f0 }, /* N/A */ | |
4738 | { 0x1d, 0x411111f0 }, /* N/A */ | |
4739 | /* 0x1e is filled in below */ | |
4740 | { 0x1f, 0x411111f0 }, /* N/A */ | |
4741 | { } | |
4742 | } | |
4743 | }, | |
4744 | [ALC880_FIXUP_3ST] = { | |
4745 | .type = ALC_FIXUP_PINS, | |
4746 | .v.pins = (const struct alc_pincfg[]) { | |
4747 | { 0x1e, 0x411111f0 }, /* N/A */ | |
4748 | { } | |
4749 | }, | |
4750 | .chained = true, | |
4751 | .chain_id = ALC880_FIXUP_3ST_BASE, | |
4752 | }, | |
4753 | [ALC880_FIXUP_3ST_DIG] = { | |
4754 | .type = ALC_FIXUP_PINS, | |
4755 | .v.pins = (const struct alc_pincfg[]) { | |
4756 | { 0x1e, 0x0144111e }, /* SPDIF */ | |
4757 | { } | |
4758 | }, | |
4759 | .chained = true, | |
4760 | .chain_id = ALC880_FIXUP_3ST_BASE, | |
4761 | }, | |
4762 | [ALC880_FIXUP_5ST_BASE] = { | |
4763 | .type = ALC_FIXUP_PINS, | |
4764 | .v.pins = (const struct alc_pincfg[]) { | |
4765 | { 0x14, 0x01014010 }, /* front */ | |
4766 | { 0x15, 0x411111f0 }, /* N/A */ | |
4767 | { 0x16, 0x01011411 }, /* CLFE */ | |
4768 | { 0x17, 0x01016412 }, /* surr */ | |
4769 | { 0x18, 0x01a19c30 }, /* mic-in */ | |
4770 | { 0x19, 0x0121411f }, /* HP */ | |
4771 | { 0x1a, 0x01813031 }, /* line-in */ | |
4772 | { 0x1b, 0x02a19c40 }, /* front-mic */ | |
4773 | { 0x1c, 0x411111f0 }, /* N/A */ | |
4774 | { 0x1d, 0x411111f0 }, /* N/A */ | |
4775 | /* 0x1e is filled in below */ | |
4776 | { 0x1f, 0x411111f0 }, /* N/A */ | |
4777 | { } | |
4778 | } | |
4779 | }, | |
4780 | [ALC880_FIXUP_5ST] = { | |
4781 | .type = ALC_FIXUP_PINS, | |
4782 | .v.pins = (const struct alc_pincfg[]) { | |
4783 | { 0x1e, 0x411111f0 }, /* N/A */ | |
4784 | { } | |
4785 | }, | |
4786 | .chained = true, | |
4787 | .chain_id = ALC880_FIXUP_5ST_BASE, | |
4788 | }, | |
4789 | [ALC880_FIXUP_5ST_DIG] = { | |
4790 | .type = ALC_FIXUP_PINS, | |
4791 | .v.pins = (const struct alc_pincfg[]) { | |
4792 | { 0x1e, 0x0144111e }, /* SPDIF */ | |
4793 | { } | |
4794 | }, | |
4795 | .chained = true, | |
4796 | .chain_id = ALC880_FIXUP_5ST_BASE, | |
4797 | }, | |
4798 | [ALC880_FIXUP_6ST_BASE] = { | |
4799 | .type = ALC_FIXUP_PINS, | |
4800 | .v.pins = (const struct alc_pincfg[]) { | |
4801 | { 0x14, 0x01014010 }, /* front */ | |
4802 | { 0x15, 0x01016412 }, /* surr */ | |
4803 | { 0x16, 0x01011411 }, /* CLFE */ | |
4804 | { 0x17, 0x01012414 }, /* side */ | |
4805 | { 0x18, 0x01a19c30 }, /* mic-in */ | |
4806 | { 0x19, 0x02a19c40 }, /* front-mic */ | |
4807 | { 0x1a, 0x01813031 }, /* line-in */ | |
4808 | { 0x1b, 0x0121411f }, /* HP */ | |
4809 | { 0x1c, 0x411111f0 }, /* N/A */ | |
4810 | { 0x1d, 0x411111f0 }, /* N/A */ | |
4811 | /* 0x1e is filled in below */ | |
4812 | { 0x1f, 0x411111f0 }, /* N/A */ | |
4813 | { } | |
4814 | } | |
4815 | }, | |
4816 | [ALC880_FIXUP_6ST] = { | |
4817 | .type = ALC_FIXUP_PINS, | |
4818 | .v.pins = (const struct alc_pincfg[]) { | |
4819 | { 0x1e, 0x411111f0 }, /* N/A */ | |
4820 | { } | |
4821 | }, | |
4822 | .chained = true, | |
4823 | .chain_id = ALC880_FIXUP_6ST_BASE, | |
4824 | }, | |
4825 | [ALC880_FIXUP_6ST_DIG] = { | |
4826 | .type = ALC_FIXUP_PINS, | |
4827 | .v.pins = (const struct alc_pincfg[]) { | |
4828 | { 0x1e, 0x0144111e }, /* SPDIF */ | |
4829 | { } | |
4830 | }, | |
4831 | .chained = true, | |
4832 | .chain_id = ALC880_FIXUP_6ST_BASE, | |
4833 | }, | |
4834 | }; | |
4835 | ||
4836 | static const struct snd_pci_quirk alc880_fixup_tbl[] = { | |
4837 | SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810), | |
4838 | SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V), | |
4839 | SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1), | |
4840 | SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2), | |
4841 | SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF), | |
4842 | SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG), | |
4843 | SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734), | |
4844 | SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL), | |
4845 | SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB), | |
4846 | SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810), | |
4847 | SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM), | |
4848 | SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734), | |
4849 | SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU), | |
4850 | SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734), | |
4851 | SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU), | |
4852 | SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG), | |
4853 | SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG), | |
4854 | SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG), | |
4855 | SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700), | |
4856 | ||
4857 | /* Below is the copied entries from alc880_quirks.c. | |
4858 | * It's not quite sure whether BIOS sets the correct pin-config table | |
4859 | * on these machines, thus they are kept to be compatible with | |
4860 | * the old static quirks. Once when it's confirmed to work without | |
4861 | * these overrides, it'd be better to remove. | |
4862 | */ | |
4863 | SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG), | |
4864 | SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST), | |
4865 | SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG), | |
4866 | SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG), | |
4867 | SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG), | |
4868 | SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG), | |
4869 | SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG), | |
4870 | SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST), | |
4871 | SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG), | |
4872 | SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST), | |
4873 | SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST), | |
4874 | SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST), | |
4875 | SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST), | |
4876 | SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST), | |
4877 | SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG), | |
4878 | SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG), | |
4879 | SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG), | |
4880 | SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG), | |
4881 | SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG), | |
4882 | SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG), | |
4883 | SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG), | |
4884 | SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */ | |
4885 | SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG), | |
4886 | SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG), | |
4887 | SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG), | |
4888 | SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG), | |
4889 | SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG), | |
4890 | SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG), | |
4891 | SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG), | |
4892 | SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG), | |
4893 | SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG), | |
4894 | SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG), | |
4895 | SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG), | |
4896 | /* default Intel */ | |
4897 | SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST), | |
4898 | SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG), | |
4899 | SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG), | |
4900 | {} | |
4901 | }; | |
4902 | ||
4903 | static const struct alc_model_fixup alc880_fixup_models[] = { | |
4904 | {.id = ALC880_FIXUP_3ST, .name = "3stack"}, | |
4905 | {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"}, | |
4906 | {.id = ALC880_FIXUP_5ST, .name = "5stack"}, | |
4907 | {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"}, | |
4908 | {.id = ALC880_FIXUP_6ST, .name = "6stack"}, | |
4909 | {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"}, | |
4910 | {} | |
4911 | }; | |
4912 | ||
4913 | ||
4914 | /* | |
4915 | * OK, here we have finally the patch for ALC880 | |
4916 | */ | |
4917 | static int patch_alc880(struct hda_codec *codec) | |
4918 | { | |
4919 | struct alc_spec *spec; | |
4920 | int err; | |
4921 | ||
4922 | err = alc_alloc_spec(codec, 0x0b); | |
4923 | if (err < 0) | |
4924 | return err; | |
4925 | ||
4926 | spec = codec->spec; | |
4927 | spec->need_dac_fix = 1; | |
4928 | ||
4929 | alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl, | |
4930 | alc880_fixups); | |
4931 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
4932 | ||
4933 | /* automatic parse from the BIOS config */ | |
4934 | err = alc880_parse_auto_config(codec); | |
4935 | if (err < 0) | |
4936 | goto error; | |
4937 | ||
4938 | if (!spec->no_analog) { | |
4939 | err = snd_hda_attach_beep_device(codec, 0x1); | |
4940 | if (err < 0) | |
4941 | goto error; | |
4942 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); | |
4943 | } | |
4944 | ||
4945 | codec->patch_ops = alc_patch_ops; | |
4946 | codec->patch_ops.unsol_event = alc880_unsol_event; | |
4947 | ||
4948 | ||
4949 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); | |
4950 | ||
4951 | return 0; | |
4952 | ||
4953 | error: | |
4954 | alc_free(codec); | |
4955 | return err; | |
4956 | } | |
4957 | ||
4958 | ||
4959 | /* | |
4960 | * ALC260 support | |
4961 | */ | |
4962 | static int alc260_parse_auto_config(struct hda_codec *codec) | |
4963 | { | |
4964 | static const hda_nid_t alc260_ignore[] = { 0x17, 0 }; | |
4965 | static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 }; | |
4966 | return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids); | |
4967 | } | |
4968 | ||
4969 | /* | |
4970 | * Pin config fixes | |
4971 | */ | |
4972 | enum { | |
4973 | ALC260_FIXUP_HP_DC5750, | |
4974 | ALC260_FIXUP_HP_PIN_0F, | |
4975 | ALC260_FIXUP_COEF, | |
4976 | ALC260_FIXUP_GPIO1, | |
4977 | ALC260_FIXUP_GPIO1_TOGGLE, | |
4978 | ALC260_FIXUP_REPLACER, | |
4979 | ALC260_FIXUP_HP_B1900, | |
4980 | ALC260_FIXUP_KN1, | |
4981 | }; | |
4982 | ||
4983 | static void alc260_gpio1_automute(struct hda_codec *codec) | |
4984 | { | |
4985 | struct alc_spec *spec = codec->spec; | |
4986 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, | |
4987 | spec->hp_jack_present); | |
4988 | } | |
4989 | ||
4990 | static void alc260_fixup_gpio1_toggle(struct hda_codec *codec, | |
4991 | const struct alc_fixup *fix, int action) | |
4992 | { | |
4993 | struct alc_spec *spec = codec->spec; | |
4994 | if (action == ALC_FIXUP_ACT_PROBE) { | |
4995 | /* although the machine has only one output pin, we need to | |
4996 | * toggle GPIO1 according to the jack state | |
4997 | */ | |
4998 | spec->automute_hook = alc260_gpio1_automute; | |
4999 | spec->detect_hp = 1; | |
5000 | spec->automute_speaker = 1; | |
5001 | spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */ | |
5002 | snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT, | |
5003 | alc_hp_automute); | |
5004 | snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs); | |
5005 | } | |
5006 | } | |
5007 | ||
5008 | static void alc260_fixup_kn1(struct hda_codec *codec, | |
5009 | const struct alc_fixup *fix, int action) | |
5010 | { | |
5011 | struct alc_spec *spec = codec->spec; | |
5012 | static const struct alc_pincfg pincfgs[] = { | |
5013 | { 0x0f, 0x02214000 }, /* HP/speaker */ | |
5014 | { 0x12, 0x90a60160 }, /* int mic */ | |
5015 | { 0x13, 0x02a19000 }, /* ext mic */ | |
5016 | { 0x18, 0x01446000 }, /* SPDIF out */ | |
5017 | /* disable bogus I/O pins */ | |
5018 | { 0x10, 0x411111f0 }, | |
5019 | { 0x11, 0x411111f0 }, | |
5020 | { 0x14, 0x411111f0 }, | |
5021 | { 0x15, 0x411111f0 }, | |
5022 | { 0x16, 0x411111f0 }, | |
5023 | { 0x17, 0x411111f0 }, | |
5024 | { 0x19, 0x411111f0 }, | |
5025 | { } | |
5026 | }; | |
5027 | ||
5028 | switch (action) { | |
5029 | case ALC_FIXUP_ACT_PRE_PROBE: | |
5030 | alc_apply_pincfgs(codec, pincfgs); | |
5031 | break; | |
5032 | case ALC_FIXUP_ACT_PROBE: | |
5033 | spec->init_amp = ALC_INIT_NONE; | |
5034 | break; | |
5035 | } | |
5036 | } | |
5037 | ||
5038 | static const struct alc_fixup alc260_fixups[] = { | |
5039 | [ALC260_FIXUP_HP_DC5750] = { | |
5040 | .type = ALC_FIXUP_PINS, | |
5041 | .v.pins = (const struct alc_pincfg[]) { | |
5042 | { 0x11, 0x90130110 }, /* speaker */ | |
5043 | { } | |
5044 | } | |
5045 | }, | |
5046 | [ALC260_FIXUP_HP_PIN_0F] = { | |
5047 | .type = ALC_FIXUP_PINS, | |
5048 | .v.pins = (const struct alc_pincfg[]) { | |
5049 | { 0x0f, 0x01214000 }, /* HP */ | |
5050 | { } | |
5051 | } | |
5052 | }, | |
5053 | [ALC260_FIXUP_COEF] = { | |
5054 | .type = ALC_FIXUP_VERBS, | |
5055 | .v.verbs = (const struct hda_verb[]) { | |
5056 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, | |
5057 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 }, | |
5058 | { } | |
5059 | }, | |
5060 | .chained = true, | |
5061 | .chain_id = ALC260_FIXUP_HP_PIN_0F, | |
5062 | }, | |
5063 | [ALC260_FIXUP_GPIO1] = { | |
5064 | .type = ALC_FIXUP_VERBS, | |
5065 | .v.verbs = alc_gpio1_init_verbs, | |
5066 | }, | |
5067 | [ALC260_FIXUP_GPIO1_TOGGLE] = { | |
5068 | .type = ALC_FIXUP_FUNC, | |
5069 | .v.func = alc260_fixup_gpio1_toggle, | |
5070 | .chained = true, | |
5071 | .chain_id = ALC260_FIXUP_HP_PIN_0F, | |
5072 | }, | |
5073 | [ALC260_FIXUP_REPLACER] = { | |
5074 | .type = ALC_FIXUP_VERBS, | |
5075 | .v.verbs = (const struct hda_verb[]) { | |
5076 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, | |
5077 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, | |
5078 | { } | |
5079 | }, | |
5080 | .chained = true, | |
5081 | .chain_id = ALC260_FIXUP_GPIO1_TOGGLE, | |
5082 | }, | |
5083 | [ALC260_FIXUP_HP_B1900] = { | |
5084 | .type = ALC_FIXUP_FUNC, | |
5085 | .v.func = alc260_fixup_gpio1_toggle, | |
5086 | .chained = true, | |
5087 | .chain_id = ALC260_FIXUP_COEF, | |
5088 | }, | |
5089 | [ALC260_FIXUP_KN1] = { | |
5090 | .type = ALC_FIXUP_FUNC, | |
5091 | .v.func = alc260_fixup_kn1, | |
5092 | }, | |
5093 | }; | |
5094 | ||
5095 | static const struct snd_pci_quirk alc260_fixup_tbl[] = { | |
5096 | SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1), | |
5097 | SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF), | |
5098 | SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1), | |
5099 | SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750), | |
5100 | SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900), | |
5101 | SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1), | |
5102 | SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1), | |
5103 | SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER), | |
5104 | SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF), | |
5105 | {} | |
5106 | }; | |
5107 | ||
5108 | /* | |
5109 | */ | |
5110 | static int patch_alc260(struct hda_codec *codec) | |
5111 | { | |
5112 | struct alc_spec *spec; | |
5113 | int err; | |
5114 | ||
5115 | err = alc_alloc_spec(codec, 0x07); | |
5116 | if (err < 0) | |
5117 | return err; | |
5118 | ||
5119 | spec = codec->spec; | |
5120 | ||
5121 | alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); | |
5122 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
5123 | ||
5124 | /* automatic parse from the BIOS config */ | |
5125 | err = alc260_parse_auto_config(codec); | |
5126 | if (err < 0) | |
5127 | goto error; | |
5128 | ||
5129 | if (!spec->no_analog) { | |
5130 | err = snd_hda_attach_beep_device(codec, 0x1); | |
5131 | if (err < 0) | |
5132 | goto error; | |
5133 | set_beep_amp(spec, 0x07, 0x05, HDA_INPUT); | |
5134 | } | |
5135 | ||
5136 | codec->patch_ops = alc_patch_ops; | |
5137 | spec->shutup = alc_eapd_shutup; | |
5138 | ||
5139 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); | |
5140 | ||
5141 | return 0; | |
5142 | ||
5143 | error: | |
5144 | alc_free(codec); | |
5145 | return err; | |
5146 | } | |
5147 | ||
5148 | ||
5149 | /* | |
5150 | * ALC882/883/885/888/889 support | |
5151 | * | |
5152 | * ALC882 is almost identical with ALC880 but has cleaner and more flexible | |
5153 | * configuration. Each pin widget can choose any input DACs and a mixer. | |
5154 | * Each ADC is connected from a mixer of all inputs. This makes possible | |
5155 | * 6-channel independent captures. | |
5156 | * | |
5157 | * In addition, an independent DAC for the multi-playback (not used in this | |
5158 | * driver yet). | |
5159 | */ | |
5160 | ||
5161 | /* | |
5162 | * Pin config fixes | |
5163 | */ | |
5164 | enum { | |
5165 | ALC882_FIXUP_ABIT_AW9D_MAX, | |
5166 | ALC882_FIXUP_LENOVO_Y530, | |
5167 | ALC882_FIXUP_PB_M5210, | |
5168 | ALC882_FIXUP_ACER_ASPIRE_7736, | |
5169 | ALC882_FIXUP_ASUS_W90V, | |
5170 | ALC889_FIXUP_CD, | |
5171 | ALC889_FIXUP_VAIO_TT, | |
5172 | ALC888_FIXUP_EEE1601, | |
5173 | ALC882_FIXUP_EAPD, | |
5174 | ALC883_FIXUP_EAPD, | |
5175 | ALC883_FIXUP_ACER_EAPD, | |
5176 | ALC882_FIXUP_GPIO1, | |
5177 | ALC882_FIXUP_GPIO2, | |
5178 | ALC882_FIXUP_GPIO3, | |
5179 | ALC889_FIXUP_COEF, | |
5180 | ALC882_FIXUP_ASUS_W2JC, | |
5181 | ALC882_FIXUP_ACER_ASPIRE_4930G, | |
5182 | ALC882_FIXUP_ACER_ASPIRE_8930G, | |
5183 | ALC882_FIXUP_ASPIRE_8930G_VERBS, | |
5184 | ALC885_FIXUP_MACPRO_GPIO, | |
5185 | ALC889_FIXUP_DAC_ROUTE, | |
5186 | ALC889_FIXUP_MBP_VREF, | |
5187 | ALC889_FIXUP_IMAC91_VREF, | |
5188 | ALC882_FIXUP_INV_DMIC, | |
5189 | ALC882_FIXUP_NO_PRIMARY_HP, | |
5190 | }; | |
5191 | ||
5192 | static void alc889_fixup_coef(struct hda_codec *codec, | |
5193 | const struct alc_fixup *fix, int action) | |
5194 | { | |
5195 | if (action != ALC_FIXUP_ACT_INIT) | |
5196 | return; | |
5197 | alc889_coef_init(codec); | |
5198 | } | |
5199 | ||
5200 | /* toggle speaker-output according to the hp-jack state */ | |
5201 | static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted) | |
5202 | { | |
5203 | unsigned int gpiostate, gpiomask, gpiodir; | |
5204 | ||
5205 | gpiostate = snd_hda_codec_read(codec, codec->afg, 0, | |
5206 | AC_VERB_GET_GPIO_DATA, 0); | |
5207 | ||
5208 | if (!muted) | |
5209 | gpiostate |= (1 << pin); | |
5210 | else | |
5211 | gpiostate &= ~(1 << pin); | |
5212 | ||
5213 | gpiomask = snd_hda_codec_read(codec, codec->afg, 0, | |
5214 | AC_VERB_GET_GPIO_MASK, 0); | |
5215 | gpiomask |= (1 << pin); | |
5216 | ||
5217 | gpiodir = snd_hda_codec_read(codec, codec->afg, 0, | |
5218 | AC_VERB_GET_GPIO_DIRECTION, 0); | |
5219 | gpiodir |= (1 << pin); | |
5220 | ||
5221 | ||
5222 | snd_hda_codec_write(codec, codec->afg, 0, | |
5223 | AC_VERB_SET_GPIO_MASK, gpiomask); | |
5224 | snd_hda_codec_write(codec, codec->afg, 0, | |
5225 | AC_VERB_SET_GPIO_DIRECTION, gpiodir); | |
5226 | ||
5227 | msleep(1); | |
5228 | ||
5229 | snd_hda_codec_write(codec, codec->afg, 0, | |
5230 | AC_VERB_SET_GPIO_DATA, gpiostate); | |
5231 | } | |
5232 | ||
5233 | /* set up GPIO at initialization */ | |
5234 | static void alc885_fixup_macpro_gpio(struct hda_codec *codec, | |
5235 | const struct alc_fixup *fix, int action) | |
5236 | { | |
5237 | if (action != ALC_FIXUP_ACT_INIT) | |
5238 | return; | |
5239 | alc882_gpio_mute(codec, 0, 0); | |
5240 | alc882_gpio_mute(codec, 1, 0); | |
5241 | } | |
5242 | ||
5243 | /* Fix the connection of some pins for ALC889: | |
5244 | * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't | |
5245 | * work correctly (bko#42740) | |
5246 | */ | |
5247 | static void alc889_fixup_dac_route(struct hda_codec *codec, | |
5248 | const struct alc_fixup *fix, int action) | |
5249 | { | |
5250 | if (action == ALC_FIXUP_ACT_PRE_PROBE) { | |
5251 | /* fake the connections during parsing the tree */ | |
5252 | hda_nid_t conn1[2] = { 0x0c, 0x0d }; | |
5253 | hda_nid_t conn2[2] = { 0x0e, 0x0f }; | |
5254 | snd_hda_override_conn_list(codec, 0x14, 2, conn1); | |
5255 | snd_hda_override_conn_list(codec, 0x15, 2, conn1); | |
5256 | snd_hda_override_conn_list(codec, 0x18, 2, conn2); | |
5257 | snd_hda_override_conn_list(codec, 0x1a, 2, conn2); | |
5258 | } else if (action == ALC_FIXUP_ACT_PROBE) { | |
5259 | /* restore the connections */ | |
5260 | hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 }; | |
5261 | snd_hda_override_conn_list(codec, 0x14, 5, conn); | |
5262 | snd_hda_override_conn_list(codec, 0x15, 5, conn); | |
5263 | snd_hda_override_conn_list(codec, 0x18, 5, conn); | |
5264 | snd_hda_override_conn_list(codec, 0x1a, 5, conn); | |
5265 | } | |
5266 | } | |
5267 | ||
5268 | /* Set VREF on HP pin */ | |
5269 | static void alc889_fixup_mbp_vref(struct hda_codec *codec, | |
5270 | const struct alc_fixup *fix, int action) | |
5271 | { | |
5272 | struct alc_spec *spec = codec->spec; | |
5273 | static hda_nid_t nids[2] = { 0x14, 0x15 }; | |
5274 | int i; | |
5275 | ||
5276 | if (action != ALC_FIXUP_ACT_INIT) | |
5277 | return; | |
5278 | for (i = 0; i < ARRAY_SIZE(nids); i++) { | |
5279 | unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]); | |
5280 | if (get_defcfg_device(val) != AC_JACK_HP_OUT) | |
5281 | continue; | |
5282 | val = snd_hda_codec_read(codec, nids[i], 0, | |
5283 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | |
5284 | val |= AC_PINCTL_VREF_80; | |
5285 | snd_hda_set_pin_ctl(codec, nids[i], val); | |
5286 | spec->keep_vref_in_automute = 1; | |
5287 | break; | |
5288 | } | |
5289 | } | |
5290 | ||
5291 | /* Set VREF on speaker pins on imac91 */ | |
5292 | static void alc889_fixup_imac91_vref(struct hda_codec *codec, | |
5293 | const struct alc_fixup *fix, int action) | |
5294 | { | |
5295 | struct alc_spec *spec = codec->spec; | |
5296 | static hda_nid_t nids[2] = { 0x18, 0x1a }; | |
5297 | int i; | |
5298 | ||
5299 | if (action != ALC_FIXUP_ACT_INIT) | |
5300 | return; | |
5301 | for (i = 0; i < ARRAY_SIZE(nids); i++) { | |
5302 | unsigned int val; | |
5303 | val = snd_hda_codec_read(codec, nids[i], 0, | |
5304 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | |
5305 | val |= AC_PINCTL_VREF_50; | |
5306 | snd_hda_set_pin_ctl(codec, nids[i], val); | |
5307 | } | |
5308 | spec->keep_vref_in_automute = 1; | |
5309 | } | |
5310 | ||
5311 | /* Don't take HP output as primary | |
5312 | * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05 | |
5313 | */ | |
5314 | static void alc882_fixup_no_primary_hp(struct hda_codec *codec, | |
5315 | const struct alc_fixup *fix, int action) | |
5316 | { | |
5317 | struct alc_spec *spec = codec->spec; | |
5318 | if (action == ALC_FIXUP_ACT_PRE_PROBE) | |
5319 | spec->no_primary_hp = 1; | |
5320 | } | |
5321 | ||
5322 | static const struct alc_fixup alc882_fixups[] = { | |
5323 | [ALC882_FIXUP_ABIT_AW9D_MAX] = { | |
5324 | .type = ALC_FIXUP_PINS, | |
5325 | .v.pins = (const struct alc_pincfg[]) { | |
5326 | { 0x15, 0x01080104 }, /* side */ | |
5327 | { 0x16, 0x01011012 }, /* rear */ | |
5328 | { 0x17, 0x01016011 }, /* clfe */ | |
5329 | { } | |
5330 | } | |
5331 | }, | |
5332 | [ALC882_FIXUP_LENOVO_Y530] = { | |
5333 | .type = ALC_FIXUP_PINS, | |
5334 | .v.pins = (const struct alc_pincfg[]) { | |
5335 | { 0x15, 0x99130112 }, /* rear int speakers */ | |
5336 | { 0x16, 0x99130111 }, /* subwoofer */ | |
5337 | { } | |
5338 | } | |
5339 | }, | |
5340 | [ALC882_FIXUP_PB_M5210] = { | |
5341 | .type = ALC_FIXUP_VERBS, | |
5342 | .v.verbs = (const struct hda_verb[]) { | |
5343 | { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, | |
5344 | {} | |
5345 | } | |
5346 | }, | |
5347 | [ALC882_FIXUP_ACER_ASPIRE_7736] = { | |
5348 | .type = ALC_FIXUP_FUNC, | |
5349 | .v.func = alc_fixup_sku_ignore, | |
5350 | }, | |
5351 | [ALC882_FIXUP_ASUS_W90V] = { | |
5352 | .type = ALC_FIXUP_PINS, | |
5353 | .v.pins = (const struct alc_pincfg[]) { | |
5354 | { 0x16, 0x99130110 }, /* fix sequence for CLFE */ | |
5355 | { } | |
5356 | } | |
5357 | }, | |
5358 | [ALC889_FIXUP_CD] = { | |
5359 | .type = ALC_FIXUP_PINS, | |
5360 | .v.pins = (const struct alc_pincfg[]) { | |
5361 | { 0x1c, 0x993301f0 }, /* CD */ | |
5362 | { } | |
5363 | } | |
5364 | }, | |
5365 | [ALC889_FIXUP_VAIO_TT] = { | |
5366 | .type = ALC_FIXUP_PINS, | |
5367 | .v.pins = (const struct alc_pincfg[]) { | |
5368 | { 0x17, 0x90170111 }, /* hidden surround speaker */ | |
5369 | { } | |
5370 | } | |
5371 | }, | |
5372 | [ALC888_FIXUP_EEE1601] = { | |
5373 | .type = ALC_FIXUP_VERBS, | |
5374 | .v.verbs = (const struct hda_verb[]) { | |
5375 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b }, | |
5376 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 }, | |
5377 | { } | |
5378 | } | |
5379 | }, | |
5380 | [ALC882_FIXUP_EAPD] = { | |
5381 | .type = ALC_FIXUP_VERBS, | |
5382 | .v.verbs = (const struct hda_verb[]) { | |
5383 | /* change to EAPD mode */ | |
5384 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, | |
5385 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 }, | |
5386 | { } | |
5387 | } | |
5388 | }, | |
5389 | [ALC883_FIXUP_EAPD] = { | |
5390 | .type = ALC_FIXUP_VERBS, | |
5391 | .v.verbs = (const struct hda_verb[]) { | |
5392 | /* change to EAPD mode */ | |
5393 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, | |
5394 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 }, | |
5395 | { } | |
5396 | } | |
5397 | }, | |
5398 | [ALC883_FIXUP_ACER_EAPD] = { | |
5399 | .type = ALC_FIXUP_VERBS, | |
5400 | .v.verbs = (const struct hda_verb[]) { | |
5401 | /* eanable EAPD on Acer laptops */ | |
5402 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, | |
5403 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, | |
5404 | { } | |
5405 | } | |
5406 | }, | |
5407 | [ALC882_FIXUP_GPIO1] = { | |
5408 | .type = ALC_FIXUP_VERBS, | |
5409 | .v.verbs = alc_gpio1_init_verbs, | |
5410 | }, | |
5411 | [ALC882_FIXUP_GPIO2] = { | |
5412 | .type = ALC_FIXUP_VERBS, | |
5413 | .v.verbs = alc_gpio2_init_verbs, | |
5414 | }, | |
5415 | [ALC882_FIXUP_GPIO3] = { | |
5416 | .type = ALC_FIXUP_VERBS, | |
5417 | .v.verbs = alc_gpio3_init_verbs, | |
5418 | }, | |
5419 | [ALC882_FIXUP_ASUS_W2JC] = { | |
5420 | .type = ALC_FIXUP_VERBS, | |
5421 | .v.verbs = alc_gpio1_init_verbs, | |
5422 | .chained = true, | |
5423 | .chain_id = ALC882_FIXUP_EAPD, | |
5424 | }, | |
5425 | [ALC889_FIXUP_COEF] = { | |
5426 | .type = ALC_FIXUP_FUNC, | |
5427 | .v.func = alc889_fixup_coef, | |
5428 | }, | |
5429 | [ALC882_FIXUP_ACER_ASPIRE_4930G] = { | |
5430 | .type = ALC_FIXUP_PINS, | |
5431 | .v.pins = (const struct alc_pincfg[]) { | |
5432 | { 0x16, 0x99130111 }, /* CLFE speaker */ | |
5433 | { 0x17, 0x99130112 }, /* surround speaker */ | |
5434 | { } | |
5435 | }, | |
5436 | .chained = true, | |
5437 | .chain_id = ALC882_FIXUP_GPIO1, | |
5438 | }, | |
5439 | [ALC882_FIXUP_ACER_ASPIRE_8930G] = { | |
5440 | .type = ALC_FIXUP_PINS, | |
5441 | .v.pins = (const struct alc_pincfg[]) { | |
5442 | { 0x16, 0x99130111 }, /* CLFE speaker */ | |
5443 | { 0x1b, 0x99130112 }, /* surround speaker */ | |
5444 | { } | |
5445 | }, | |
5446 | .chained = true, | |
5447 | .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS, | |
5448 | }, | |
5449 | [ALC882_FIXUP_ASPIRE_8930G_VERBS] = { | |
5450 | /* additional init verbs for Acer Aspire 8930G */ | |
5451 | .type = ALC_FIXUP_VERBS, | |
5452 | .v.verbs = (const struct hda_verb[]) { | |
5453 | /* Enable all DACs */ | |
5454 | /* DAC DISABLE/MUTE 1? */ | |
5455 | /* setting bits 1-5 disables DAC nids 0x02-0x06 | |
5456 | * apparently. Init=0x38 */ | |
5457 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 }, | |
5458 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 }, | |
5459 | /* DAC DISABLE/MUTE 2? */ | |
5460 | /* some bit here disables the other DACs. | |
5461 | * Init=0x4900 */ | |
5462 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 }, | |
5463 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 }, | |
5464 | /* DMIC fix | |
5465 | * This laptop has a stereo digital microphone. | |
5466 | * The mics are only 1cm apart which makes the stereo | |
5467 | * useless. However, either the mic or the ALC889 | |
5468 | * makes the signal become a difference/sum signal | |
5469 | * instead of standard stereo, which is annoying. | |
5470 | * So instead we flip this bit which makes the | |
5471 | * codec replicate the sum signal to both channels, | |
5472 | * turning it into a normal mono mic. | |
5473 | */ | |
5474 | /* DMIC_CONTROL? Init value = 0x0001 */ | |
5475 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b }, | |
5476 | { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 }, | |
5477 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, | |
5478 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, | |
5479 | { } | |
5480 | }, | |
5481 | .chained = true, | |
5482 | .chain_id = ALC882_FIXUP_GPIO1, | |
5483 | }, | |
5484 | [ALC885_FIXUP_MACPRO_GPIO] = { | |
5485 | .type = ALC_FIXUP_FUNC, | |
5486 | .v.func = alc885_fixup_macpro_gpio, | |
5487 | }, | |
5488 | [ALC889_FIXUP_DAC_ROUTE] = { | |
5489 | .type = ALC_FIXUP_FUNC, | |
5490 | .v.func = alc889_fixup_dac_route, | |
5491 | }, | |
5492 | [ALC889_FIXUP_MBP_VREF] = { | |
5493 | .type = ALC_FIXUP_FUNC, | |
5494 | .v.func = alc889_fixup_mbp_vref, | |
5495 | .chained = true, | |
5496 | .chain_id = ALC882_FIXUP_GPIO1, | |
5497 | }, | |
5498 | [ALC889_FIXUP_IMAC91_VREF] = { | |
5499 | .type = ALC_FIXUP_FUNC, | |
5500 | .v.func = alc889_fixup_imac91_vref, | |
5501 | .chained = true, | |
5502 | .chain_id = ALC882_FIXUP_GPIO1, | |
5503 | }, | |
5504 | [ALC882_FIXUP_INV_DMIC] = { | |
5505 | .type = ALC_FIXUP_FUNC, | |
5506 | .v.func = alc_fixup_inv_dmic_0x12, | |
5507 | }, | |
5508 | [ALC882_FIXUP_NO_PRIMARY_HP] = { | |
5509 | .type = ALC_FIXUP_FUNC, | |
5510 | .v.func = alc882_fixup_no_primary_hp, | |
5511 | }, | |
5512 | }; | |
5513 | ||
5514 | static const struct snd_pci_quirk alc882_fixup_tbl[] = { | |
5515 | SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD), | |
5516 | SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD), | |
5517 | SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD), | |
5518 | SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD), | |
5519 | SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD), | |
5520 | SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD), | |
5521 | SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G", | |
5522 | ALC882_FIXUP_ACER_ASPIRE_4930G), | |
5523 | SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G", | |
5524 | ALC882_FIXUP_ACER_ASPIRE_4930G), | |
5525 | SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G", | |
5526 | ALC882_FIXUP_ACER_ASPIRE_8930G), | |
5527 | SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G", | |
5528 | ALC882_FIXUP_ACER_ASPIRE_8930G), | |
5529 | SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G", | |
5530 | ALC882_FIXUP_ACER_ASPIRE_4930G), | |
5531 | SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G", | |
5532 | ALC882_FIXUP_ACER_ASPIRE_4930G), | |
5533 | SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G", | |
5534 | ALC882_FIXUP_ACER_ASPIRE_4930G), | |
5535 | SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210), | |
5536 | SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G", | |
5537 | ALC882_FIXUP_ACER_ASPIRE_4930G), | |
5538 | SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE), | |
5539 | SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G), | |
5540 | SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736), | |
5541 | SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD), | |
5542 | SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V), | |
5543 | SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC), | |
5544 | SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601), | |
5545 | SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT), | |
5546 | SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP), | |
5547 | ||
5548 | /* All Apple entries are in codec SSIDs */ | |
5549 | SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF), | |
5550 | SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF), | |
5551 | SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF), | |
5552 | SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO), | |
5553 | SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO), | |
5554 | SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO), | |
5555 | SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF), | |
5556 | SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF), | |
5557 | SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD), | |
5558 | SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF), | |
5559 | SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF), | |
5560 | SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF), | |
5561 | SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF), | |
5562 | SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO), | |
5563 | SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF), | |
5564 | SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF), | |
5565 | SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF), | |
5566 | SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO), | |
5567 | SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF), | |
5568 | SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF), | |
5569 | SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF), | |
5570 | SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF), | |
5571 | ||
5572 | SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD), | |
5573 | SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD), | |
5574 | SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3), | |
5575 | SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD), | |
5576 | SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX), | |
5577 | SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD), | |
5578 | SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD), | |
5579 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530), | |
5580 | SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF), | |
5581 | {} | |
5582 | }; | |
5583 | ||
5584 | static const struct alc_model_fixup alc882_fixup_models[] = { | |
5585 | {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"}, | |
5586 | {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"}, | |
5587 | {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"}, | |
5588 | {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"}, | |
5589 | {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"}, | |
5590 | {} | |
5591 | }; | |
5592 | ||
5593 | /* | |
5594 | * BIOS auto configuration | |
5595 | */ | |
5596 | /* almost identical with ALC880 parser... */ | |
5597 | static int alc882_parse_auto_config(struct hda_codec *codec) | |
5598 | { | |
5599 | static const hda_nid_t alc882_ignore[] = { 0x1d, 0 }; | |
5600 | static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 }; | |
5601 | return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids); | |
5602 | } | |
5603 | ||
5604 | /* | |
5605 | */ | |
5606 | static int patch_alc882(struct hda_codec *codec) | |
5607 | { | |
5608 | struct alc_spec *spec; | |
5609 | int err; | |
5610 | ||
5611 | err = alc_alloc_spec(codec, 0x0b); | |
5612 | if (err < 0) | |
5613 | return err; | |
5614 | ||
5615 | spec = codec->spec; | |
5616 | ||
5617 | switch (codec->vendor_id) { | |
5618 | case 0x10ec0882: | |
5619 | case 0x10ec0885: | |
5620 | break; | |
5621 | default: | |
5622 | /* ALC883 and variants */ | |
5623 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); | |
5624 | break; | |
5625 | } | |
5626 | ||
5627 | alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl, | |
5628 | alc882_fixups); | |
5629 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
5630 | ||
5631 | alc_auto_parse_customize_define(codec); | |
5632 | ||
5633 | /* automatic parse from the BIOS config */ | |
5634 | err = alc882_parse_auto_config(codec); | |
5635 | if (err < 0) | |
5636 | goto error; | |
5637 | ||
5638 | if (!spec->no_analog && has_cdefine_beep(codec)) { | |
5639 | err = snd_hda_attach_beep_device(codec, 0x1); | |
5640 | if (err < 0) | |
5641 | goto error; | |
5642 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); | |
5643 | } | |
5644 | ||
5645 | codec->patch_ops = alc_patch_ops; | |
5646 | ||
5647 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); | |
5648 | ||
5649 | return 0; | |
5650 | ||
5651 | error: | |
5652 | alc_free(codec); | |
5653 | return err; | |
5654 | } | |
5655 | ||
5656 | ||
5657 | /* | |
5658 | * ALC262 support | |
5659 | */ | |
5660 | static int alc262_parse_auto_config(struct hda_codec *codec) | |
5661 | { | |
5662 | static const hda_nid_t alc262_ignore[] = { 0x1d, 0 }; | |
5663 | static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 }; | |
5664 | return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids); | |
5665 | } | |
5666 | ||
5667 | /* | |
5668 | * Pin config fixes | |
5669 | */ | |
5670 | enum { | |
5671 | ALC262_FIXUP_FSC_H270, | |
5672 | ALC262_FIXUP_HP_Z200, | |
5673 | ALC262_FIXUP_TYAN, | |
5674 | ALC262_FIXUP_LENOVO_3000, | |
5675 | ALC262_FIXUP_BENQ, | |
5676 | ALC262_FIXUP_BENQ_T31, | |
5677 | ALC262_FIXUP_INV_DMIC, | |
5678 | }; | |
5679 | ||
5680 | static const struct alc_fixup alc262_fixups[] = { | |
5681 | [ALC262_FIXUP_FSC_H270] = { | |
5682 | .type = ALC_FIXUP_PINS, | |
5683 | .v.pins = (const struct alc_pincfg[]) { | |
5684 | { 0x14, 0x99130110 }, /* speaker */ | |
5685 | { 0x15, 0x0221142f }, /* front HP */ | |
5686 | { 0x1b, 0x0121141f }, /* rear HP */ | |
5687 | { } | |
5688 | } | |
5689 | }, | |
5690 | [ALC262_FIXUP_HP_Z200] = { | |
5691 | .type = ALC_FIXUP_PINS, | |
5692 | .v.pins = (const struct alc_pincfg[]) { | |
5693 | { 0x16, 0x99130120 }, /* internal speaker */ | |
5694 | { } | |
5695 | } | |
5696 | }, | |
5697 | [ALC262_FIXUP_TYAN] = { | |
5698 | .type = ALC_FIXUP_PINS, | |
5699 | .v.pins = (const struct alc_pincfg[]) { | |
5700 | { 0x14, 0x1993e1f0 }, /* int AUX */ | |
5701 | { } | |
5702 | } | |
5703 | }, | |
5704 | [ALC262_FIXUP_LENOVO_3000] = { | |
5705 | .type = ALC_FIXUP_VERBS, | |
5706 | .v.verbs = (const struct hda_verb[]) { | |
5707 | { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, | |
5708 | {} | |
5709 | }, | |
5710 | .chained = true, | |
5711 | .chain_id = ALC262_FIXUP_BENQ, | |
5712 | }, | |
5713 | [ALC262_FIXUP_BENQ] = { | |
5714 | .type = ALC_FIXUP_VERBS, | |
5715 | .v.verbs = (const struct hda_verb[]) { | |
5716 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, | |
5717 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 }, | |
5718 | {} | |
5719 | } | |
5720 | }, | |
5721 | [ALC262_FIXUP_BENQ_T31] = { | |
5722 | .type = ALC_FIXUP_VERBS, | |
5723 | .v.verbs = (const struct hda_verb[]) { | |
5724 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, | |
5725 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, | |
5726 | {} | |
5727 | } | |
5728 | }, | |
5729 | [ALC262_FIXUP_INV_DMIC] = { | |
5730 | .type = ALC_FIXUP_FUNC, | |
5731 | .v.func = alc_fixup_inv_dmic_0x12, | |
5732 | }, | |
5733 | }; | |
5734 | ||
5735 | static const struct snd_pci_quirk alc262_fixup_tbl[] = { | |
5736 | SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200), | |
5737 | SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ), | |
5738 | SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ), | |
5739 | SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN), | |
5740 | SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270), | |
5741 | SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000), | |
5742 | SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ), | |
5743 | SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31), | |
5744 | {} | |
5745 | }; | |
5746 | ||
5747 | static const struct alc_model_fixup alc262_fixup_models[] = { | |
5748 | {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"}, | |
5749 | {} | |
5750 | }; | |
5751 | ||
5752 | /* | |
5753 | */ | |
5754 | static int patch_alc262(struct hda_codec *codec) | |
5755 | { | |
5756 | struct alc_spec *spec; | |
5757 | int err; | |
5758 | ||
5759 | err = alc_alloc_spec(codec, 0x0b); | |
5760 | if (err < 0) | |
5761 | return err; | |
5762 | ||
5763 | spec = codec->spec; | |
5764 | spec->shared_mic_vref_pin = 0x18; | |
5765 | ||
5766 | #if 0 | |
5767 | /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is | |
5768 | * under-run | |
5769 | */ | |
5770 | { | |
5771 | int tmp; | |
5772 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); | |
5773 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); | |
5774 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); | |
5775 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80); | |
5776 | } | |
5777 | #endif | |
5778 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); | |
5779 | ||
5780 | alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl, | |
5781 | alc262_fixups); | |
5782 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
5783 | ||
5784 | alc_auto_parse_customize_define(codec); | |
5785 | ||
5786 | /* automatic parse from the BIOS config */ | |
5787 | err = alc262_parse_auto_config(codec); | |
5788 | if (err < 0) | |
5789 | goto error; | |
5790 | ||
5791 | if (!spec->no_analog && has_cdefine_beep(codec)) { | |
5792 | err = snd_hda_attach_beep_device(codec, 0x1); | |
5793 | if (err < 0) | |
5794 | goto error; | |
5795 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); | |
5796 | } | |
5797 | ||
5798 | codec->patch_ops = alc_patch_ops; | |
5799 | spec->shutup = alc_eapd_shutup; | |
5800 | ||
5801 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); | |
5802 | ||
5803 | return 0; | |
5804 | ||
5805 | error: | |
5806 | alc_free(codec); | |
5807 | return err; | |
5808 | } | |
5809 | ||
5810 | /* | |
5811 | * ALC268 | |
5812 | */ | |
5813 | /* bind Beep switches of both NID 0x0f and 0x10 */ | |
5814 | static const struct hda_bind_ctls alc268_bind_beep_sw = { | |
5815 | .ops = &snd_hda_bind_sw, | |
5816 | .values = { | |
5817 | HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT), | |
5818 | HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT), | |
5819 | 0 | |
5820 | }, | |
5821 | }; | |
5822 | ||
5823 | static const struct snd_kcontrol_new alc268_beep_mixer[] = { | |
5824 | HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT), | |
5825 | HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw), | |
5826 | { } | |
5827 | }; | |
5828 | ||
5829 | /* set PCBEEP vol = 0, mute connections */ | |
5830 | static const struct hda_verb alc268_beep_init_verbs[] = { | |
5831 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5832 | {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
5833 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
5834 | { } | |
5835 | }; | |
5836 | ||
5837 | enum { | |
5838 | ALC268_FIXUP_INV_DMIC, | |
5839 | ALC268_FIXUP_HP_EAPD, | |
5840 | }; | |
5841 | ||
5842 | static const struct alc_fixup alc268_fixups[] = { | |
5843 | [ALC268_FIXUP_INV_DMIC] = { | |
5844 | .type = ALC_FIXUP_FUNC, | |
5845 | .v.func = alc_fixup_inv_dmic_0x12, | |
5846 | }, | |
5847 | [ALC268_FIXUP_HP_EAPD] = { | |
5848 | .type = ALC_FIXUP_VERBS, | |
5849 | .v.verbs = (const struct hda_verb[]) { | |
5850 | {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0}, | |
5851 | {} | |
5852 | } | |
5853 | }, | |
5854 | }; | |
5855 | ||
5856 | static const struct alc_model_fixup alc268_fixup_models[] = { | |
5857 | {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"}, | |
5858 | {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"}, | |
5859 | {} | |
5860 | }; | |
5861 | ||
5862 | static const struct snd_pci_quirk alc268_fixup_tbl[] = { | |
5863 | /* below is codec SSID since multiple Toshiba laptops have the | |
5864 | * same PCI SSID 1179:ff00 | |
5865 | */ | |
5866 | SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD), | |
5867 | {} | |
5868 | }; | |
5869 | ||
5870 | /* | |
5871 | * BIOS auto configuration | |
5872 | */ | |
5873 | static int alc268_parse_auto_config(struct hda_codec *codec) | |
5874 | { | |
5875 | static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 }; | |
5876 | struct alc_spec *spec = codec->spec; | |
5877 | int err = alc_parse_auto_config(codec, NULL, alc268_ssids); | |
5878 | if (err > 0) { | |
5879 | if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) { | |
5880 | add_mixer(spec, alc268_beep_mixer); | |
5881 | snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs); | |
5882 | } | |
5883 | } | |
5884 | return err; | |
5885 | } | |
5886 | ||
5887 | /* | |
5888 | */ | |
5889 | static int patch_alc268(struct hda_codec *codec) | |
5890 | { | |
5891 | struct alc_spec *spec; | |
5892 | int i, has_beep, err; | |
5893 | ||
5894 | /* ALC268 has no aa-loopback mixer */ | |
5895 | err = alc_alloc_spec(codec, 0); | |
5896 | if (err < 0) | |
5897 | return err; | |
5898 | ||
5899 | spec = codec->spec; | |
5900 | ||
5901 | alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups); | |
5902 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
5903 | ||
5904 | /* automatic parse from the BIOS config */ | |
5905 | err = alc268_parse_auto_config(codec); | |
5906 | if (err < 0) | |
5907 | goto error; | |
5908 | ||
5909 | has_beep = 0; | |
5910 | for (i = 0; i < spec->num_mixers; i++) { | |
5911 | if (spec->mixers[i] == alc268_beep_mixer) { | |
5912 | has_beep = 1; | |
5913 | break; | |
5914 | } | |
5915 | } | |
5916 | ||
5917 | if (has_beep) { | |
5918 | err = snd_hda_attach_beep_device(codec, 0x1); | |
5919 | if (err < 0) | |
5920 | goto error; | |
5921 | if (!query_amp_caps(codec, 0x1d, HDA_INPUT)) | |
5922 | /* override the amp caps for beep generator */ | |
5923 | snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT, | |
5924 | (0x0c << AC_AMPCAP_OFFSET_SHIFT) | | |
5925 | (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) | | |
5926 | (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) | | |
5927 | (0 << AC_AMPCAP_MUTE_SHIFT)); | |
5928 | } | |
5929 | ||
5930 | codec->patch_ops = alc_patch_ops; | |
5931 | spec->shutup = alc_eapd_shutup; | |
5932 | ||
5933 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); | |
5934 | ||
5935 | return 0; | |
5936 | ||
5937 | error: | |
5938 | alc_free(codec); | |
5939 | return err; | |
5940 | } | |
5941 | ||
5942 | /* | |
5943 | * ALC269 | |
5944 | */ | |
5945 | static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { | |
5946 | .substreams = 1, | |
5947 | .channels_min = 2, | |
5948 | .channels_max = 8, | |
5949 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ | |
5950 | /* NID is set in alc_build_pcms */ | |
5951 | .ops = { | |
5952 | .open = alc_playback_pcm_open, | |
5953 | .prepare = alc_playback_pcm_prepare, | |
5954 | .cleanup = alc_playback_pcm_cleanup | |
5955 | }, | |
5956 | }; | |
5957 | ||
5958 | static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = { | |
5959 | .substreams = 1, | |
5960 | .channels_min = 2, | |
5961 | .channels_max = 2, | |
5962 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ | |
5963 | /* NID is set in alc_build_pcms */ | |
5964 | }; | |
5965 | ||
5966 | /* different alc269-variants */ | |
5967 | enum { | |
5968 | ALC269_TYPE_ALC269VA, | |
5969 | ALC269_TYPE_ALC269VB, | |
5970 | ALC269_TYPE_ALC269VC, | |
5971 | ALC269_TYPE_ALC269VD, | |
5972 | ALC269_TYPE_ALC280, | |
5973 | ALC269_TYPE_ALC282, | |
5974 | ALC269_TYPE_ALC284, | |
5975 | }; | |
5976 | ||
5977 | /* | |
5978 | * BIOS auto configuration | |
5979 | */ | |
5980 | static int alc269_parse_auto_config(struct hda_codec *codec) | |
5981 | { | |
5982 | static const hda_nid_t alc269_ignore[] = { 0x1d, 0 }; | |
5983 | static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 }; | |
5984 | static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 }; | |
5985 | struct alc_spec *spec = codec->spec; | |
5986 | const hda_nid_t *ssids; | |
5987 | ||
5988 | switch (spec->codec_variant) { | |
5989 | case ALC269_TYPE_ALC269VA: | |
5990 | case ALC269_TYPE_ALC269VC: | |
5991 | case ALC269_TYPE_ALC280: | |
5992 | case ALC269_TYPE_ALC284: | |
5993 | ssids = alc269va_ssids; | |
5994 | break; | |
5995 | case ALC269_TYPE_ALC269VB: | |
5996 | case ALC269_TYPE_ALC269VD: | |
5997 | case ALC269_TYPE_ALC282: | |
5998 | ssids = alc269_ssids; | |
5999 | break; | |
6000 | default: | |
6001 | ssids = alc269_ssids; | |
6002 | break; | |
6003 | } | |
6004 | ||
6005 | return alc_parse_auto_config(codec, alc269_ignore, ssids); | |
6006 | } | |
6007 | ||
6008 | static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up) | |
6009 | { | |
6010 | int val = alc_read_coef_idx(codec, 0x04); | |
6011 | if (power_up) | |
6012 | val |= 1 << 11; | |
6013 | else | |
6014 | val &= ~(1 << 11); | |
6015 | alc_write_coef_idx(codec, 0x04, val); | |
6016 | } | |
6017 | ||
6018 | static void alc269_shutup(struct hda_codec *codec) | |
6019 | { | |
6020 | struct alc_spec *spec = codec->spec; | |
6021 | ||
6022 | if (spec->codec_variant != ALC269_TYPE_ALC269VB) | |
6023 | return; | |
6024 | ||
6025 | if (spec->codec_variant == ALC269_TYPE_ALC269VB) | |
6026 | alc269vb_toggle_power_output(codec, 0); | |
6027 | if (spec->codec_variant == ALC269_TYPE_ALC269VB && | |
6028 | (alc_get_coef0(codec) & 0x00ff) == 0x018) { | |
6029 | msleep(150); | |
6030 | } | |
6031 | } | |
6032 | ||
6033 | #ifdef CONFIG_PM | |
6034 | static int alc269_resume(struct hda_codec *codec) | |
6035 | { | |
6036 | struct alc_spec *spec = codec->spec; | |
6037 | ||
6038 | if (spec->codec_variant == ALC269_TYPE_ALC269VB) | |
6039 | alc269vb_toggle_power_output(codec, 0); | |
6040 | if (spec->codec_variant == ALC269_TYPE_ALC269VB && | |
6041 | (alc_get_coef0(codec) & 0x00ff) == 0x018) { | |
6042 | msleep(150); | |
6043 | } | |
6044 | ||
6045 | codec->patch_ops.init(codec); | |
6046 | ||
6047 | if (spec->codec_variant == ALC269_TYPE_ALC269VB) | |
6048 | alc269vb_toggle_power_output(codec, 1); | |
6049 | if (spec->codec_variant == ALC269_TYPE_ALC269VB && | |
6050 | (alc_get_coef0(codec) & 0x00ff) == 0x017) { | |
6051 | msleep(200); | |
6052 | } | |
6053 | ||
6054 | snd_hda_codec_resume_amp(codec); | |
6055 | snd_hda_codec_resume_cache(codec); | |
6056 | hda_call_check_power_status(codec, 0x01); | |
6057 | return 0; | |
6058 | } | |
6059 | #endif /* CONFIG_PM */ | |
6060 | ||
6061 | static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec, | |
6062 | const struct alc_fixup *fix, int action) | |
6063 | { | |
6064 | struct alc_spec *spec = codec->spec; | |
6065 | ||
6066 | if (action == ALC_FIXUP_ACT_PRE_PROBE) | |
6067 | spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; | |
6068 | } | |
6069 | ||
6070 | static void alc269_fixup_hweq(struct hda_codec *codec, | |
6071 | const struct alc_fixup *fix, int action) | |
6072 | { | |
6073 | int coef; | |
6074 | ||
6075 | if (action != ALC_FIXUP_ACT_INIT) | |
6076 | return; | |
6077 | coef = alc_read_coef_idx(codec, 0x1e); | |
6078 | alc_write_coef_idx(codec, 0x1e, coef | 0x80); | |
6079 | } | |
6080 | ||
6081 | static void alc271_fixup_dmic(struct hda_codec *codec, | |
6082 | const struct alc_fixup *fix, int action) | |
6083 | { | |
6084 | static const struct hda_verb verbs[] = { | |
6085 | {0x20, AC_VERB_SET_COEF_INDEX, 0x0d}, | |
6086 | {0x20, AC_VERB_SET_PROC_COEF, 0x4000}, | |
6087 | {} | |
6088 | }; | |
6089 | unsigned int cfg; | |
6090 | ||
6091 | if (strcmp(codec->chip_name, "ALC271X")) | |
6092 | return; | |
6093 | cfg = snd_hda_codec_get_pincfg(codec, 0x12); | |
6094 | if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED) | |
6095 | snd_hda_sequence_write(codec, verbs); | |
6096 | } | |
6097 | ||
6098 | static void alc269_fixup_pcm_44k(struct hda_codec *codec, | |
6099 | const struct alc_fixup *fix, int action) | |
6100 | { | |
6101 | struct alc_spec *spec = codec->spec; | |
6102 | ||
6103 | if (action != ALC_FIXUP_ACT_PROBE) | |
6104 | return; | |
6105 | ||
6106 | /* Due to a hardware problem on Lenovo Ideadpad, we need to | |
6107 | * fix the sample rate of analog I/O to 44.1kHz | |
6108 | */ | |
6109 | spec->stream_analog_playback = &alc269_44k_pcm_analog_playback; | |
6110 | spec->stream_analog_capture = &alc269_44k_pcm_analog_capture; | |
6111 | } | |
6112 | ||
6113 | static void alc269_fixup_stereo_dmic(struct hda_codec *codec, | |
6114 | const struct alc_fixup *fix, int action) | |
6115 | { | |
6116 | int coef; | |
6117 | ||
6118 | if (action != ALC_FIXUP_ACT_INIT) | |
6119 | return; | |
6120 | /* The digital-mic unit sends PDM (differential signal) instead of | |
6121 | * the standard PCM, thus you can't record a valid mono stream as is. | |
6122 | * Below is a workaround specific to ALC269 to control the dmic | |
6123 | * signal source as mono. | |
6124 | */ | |
6125 | coef = alc_read_coef_idx(codec, 0x07); | |
6126 | alc_write_coef_idx(codec, 0x07, coef | 0x80); | |
6127 | } | |
6128 | ||
6129 | static void alc269_quanta_automute(struct hda_codec *codec) | |
6130 | { | |
6131 | update_outputs(codec); | |
6132 | ||
6133 | snd_hda_codec_write(codec, 0x20, 0, | |
6134 | AC_VERB_SET_COEF_INDEX, 0x0c); | |
6135 | snd_hda_codec_write(codec, 0x20, 0, | |
6136 | AC_VERB_SET_PROC_COEF, 0x680); | |
6137 | ||
6138 | snd_hda_codec_write(codec, 0x20, 0, | |
6139 | AC_VERB_SET_COEF_INDEX, 0x0c); | |
6140 | snd_hda_codec_write(codec, 0x20, 0, | |
6141 | AC_VERB_SET_PROC_COEF, 0x480); | |
6142 | } | |
6143 | ||
6144 | static void alc269_fixup_quanta_mute(struct hda_codec *codec, | |
6145 | const struct alc_fixup *fix, int action) | |
6146 | { | |
6147 | struct alc_spec *spec = codec->spec; | |
6148 | if (action != ALC_FIXUP_ACT_PROBE) | |
6149 | return; | |
6150 | spec->automute_hook = alc269_quanta_automute; | |
6151 | } | |
6152 | ||
6153 | /* update mute-LED according to the speaker mute state via mic1 VREF pin */ | |
6154 | static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled) | |
6155 | { | |
6156 | struct hda_codec *codec = private_data; | |
6157 | unsigned int pinval = AC_PINCTL_IN_EN + (enabled ? | |
6158 | AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80); | |
6159 | snd_hda_set_pin_ctl_cache(codec, 0x18, pinval); | |
6160 | } | |
6161 | ||
6162 | static void alc269_fixup_mic1_mute(struct hda_codec *codec, | |
6163 | const struct alc_fixup *fix, int action) | |
6164 | { | |
6165 | struct alc_spec *spec = codec->spec; | |
6166 | if (action == ALC_FIXUP_ACT_PROBE) | |
6167 | spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook; | |
6168 | } | |
6169 | ||
6170 | /* update mute-LED according to the speaker mute state via mic2 VREF pin */ | |
6171 | static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled) | |
6172 | { | |
6173 | struct hda_codec *codec = private_data; | |
6174 | unsigned int pinval = enabled ? 0x20 : 0x24; | |
6175 | snd_hda_set_pin_ctl_cache(codec, 0x19, pinval); | |
6176 | } | |
6177 | ||
6178 | static void alc269_fixup_mic2_mute(struct hda_codec *codec, | |
6179 | const struct alc_fixup *fix, int action) | |
6180 | { | |
6181 | struct alc_spec *spec = codec->spec; | |
6182 | if (action == ALC_FIXUP_ACT_PROBE) | |
6183 | spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook; | |
6184 | } | |
6185 | ||
6186 | static void alc271_hp_gate_mic_jack(struct hda_codec *codec, | |
6187 | const struct alc_fixup *fix, | |
6188 | int action) | |
6189 | { | |
6190 | struct alc_spec *spec = codec->spec; | |
6191 | ||
6192 | if (action == ALC_FIXUP_ACT_PROBE) | |
6193 | snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin, | |
6194 | spec->autocfg.hp_pins[0]); | |
6195 | } | |
6196 | ||
6197 | enum { | |
6198 | ALC269_FIXUP_SONY_VAIO, | |
6199 | ALC275_FIXUP_SONY_VAIO_GPIO2, | |
6200 | ALC269_FIXUP_DELL_M101Z, | |
6201 | ALC269_FIXUP_SKU_IGNORE, | |
6202 | ALC269_FIXUP_ASUS_G73JW, | |
6203 | ALC269_FIXUP_LENOVO_EAPD, | |
6204 | ALC275_FIXUP_SONY_HWEQ, | |
6205 | ALC271_FIXUP_DMIC, | |
6206 | ALC269_FIXUP_PCM_44K, | |
6207 | ALC269_FIXUP_STEREO_DMIC, | |
6208 | ALC269_FIXUP_QUANTA_MUTE, | |
6209 | ALC269_FIXUP_LIFEBOOK, | |
6210 | ALC269_FIXUP_AMIC, | |
6211 | ALC269_FIXUP_DMIC, | |
6212 | ALC269VB_FIXUP_AMIC, | |
6213 | ALC269VB_FIXUP_DMIC, | |
6214 | ALC269_FIXUP_MIC1_MUTE_LED, | |
6215 | ALC269_FIXUP_MIC2_MUTE_LED, | |
6216 | ALC269_FIXUP_INV_DMIC, | |
6217 | ALC269_FIXUP_LENOVO_DOCK, | |
6218 | ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT, | |
6219 | ALC271_FIXUP_AMIC_MIC2, | |
6220 | ALC271_FIXUP_HP_GATE_MIC_JACK, | |
6221 | }; | |
6222 | ||
6223 | static const struct alc_fixup alc269_fixups[] = { | |
6224 | [ALC269_FIXUP_SONY_VAIO] = { | |
6225 | .type = ALC_FIXUP_VERBS, | |
6226 | .v.verbs = (const struct hda_verb[]) { | |
6227 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD}, | |
6228 | {} | |
6229 | } | |
6230 | }, | |
6231 | [ALC275_FIXUP_SONY_VAIO_GPIO2] = { | |
6232 | .type = ALC_FIXUP_VERBS, | |
6233 | .v.verbs = (const struct hda_verb[]) { | |
6234 | {0x01, AC_VERB_SET_GPIO_MASK, 0x04}, | |
6235 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04}, | |
6236 | {0x01, AC_VERB_SET_GPIO_DATA, 0x00}, | |
6237 | { } | |
6238 | }, | |
6239 | .chained = true, | |
6240 | .chain_id = ALC269_FIXUP_SONY_VAIO | |
6241 | }, | |
6242 | [ALC269_FIXUP_DELL_M101Z] = { | |
6243 | .type = ALC_FIXUP_VERBS, | |
6244 | .v.verbs = (const struct hda_verb[]) { | |
6245 | /* Enables internal speaker */ | |
6246 | {0x20, AC_VERB_SET_COEF_INDEX, 13}, | |
6247 | {0x20, AC_VERB_SET_PROC_COEF, 0x4040}, | |
6248 | {} | |
6249 | } | |
6250 | }, | |
6251 | [ALC269_FIXUP_SKU_IGNORE] = { | |
6252 | .type = ALC_FIXUP_FUNC, | |
6253 | .v.func = alc_fixup_sku_ignore, | |
6254 | }, | |
6255 | [ALC269_FIXUP_ASUS_G73JW] = { | |
6256 | .type = ALC_FIXUP_PINS, | |
6257 | .v.pins = (const struct alc_pincfg[]) { | |
6258 | { 0x17, 0x99130111 }, /* subwoofer */ | |
6259 | { } | |
6260 | } | |
6261 | }, | |
6262 | [ALC269_FIXUP_LENOVO_EAPD] = { | |
6263 | .type = ALC_FIXUP_VERBS, | |
6264 | .v.verbs = (const struct hda_verb[]) { | |
6265 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, | |
6266 | {} | |
6267 | } | |
6268 | }, | |
6269 | [ALC275_FIXUP_SONY_HWEQ] = { | |
6270 | .type = ALC_FIXUP_FUNC, | |
6271 | .v.func = alc269_fixup_hweq, | |
6272 | .chained = true, | |
6273 | .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2 | |
6274 | }, | |
6275 | [ALC271_FIXUP_DMIC] = { | |
6276 | .type = ALC_FIXUP_FUNC, | |
6277 | .v.func = alc271_fixup_dmic, | |
6278 | }, | |
6279 | [ALC269_FIXUP_PCM_44K] = { | |
6280 | .type = ALC_FIXUP_FUNC, | |
6281 | .v.func = alc269_fixup_pcm_44k, | |
6282 | .chained = true, | |
6283 | .chain_id = ALC269_FIXUP_QUANTA_MUTE | |
6284 | }, | |
6285 | [ALC269_FIXUP_STEREO_DMIC] = { | |
6286 | .type = ALC_FIXUP_FUNC, | |
6287 | .v.func = alc269_fixup_stereo_dmic, | |
6288 | }, | |
6289 | [ALC269_FIXUP_QUANTA_MUTE] = { | |
6290 | .type = ALC_FIXUP_FUNC, | |
6291 | .v.func = alc269_fixup_quanta_mute, | |
6292 | }, | |
6293 | [ALC269_FIXUP_LIFEBOOK] = { | |
6294 | .type = ALC_FIXUP_PINS, | |
6295 | .v.pins = (const struct alc_pincfg[]) { | |
6296 | { 0x1a, 0x2101103f }, /* dock line-out */ | |
6297 | { 0x1b, 0x23a11040 }, /* dock mic-in */ | |
6298 | { } | |
6299 | }, | |
6300 | .chained = true, | |
6301 | .chain_id = ALC269_FIXUP_QUANTA_MUTE | |
6302 | }, | |
6303 | [ALC269_FIXUP_AMIC] = { | |
6304 | .type = ALC_FIXUP_PINS, | |
6305 | .v.pins = (const struct alc_pincfg[]) { | |
6306 | { 0x14, 0x99130110 }, /* speaker */ | |
6307 | { 0x15, 0x0121401f }, /* HP out */ | |
6308 | { 0x18, 0x01a19c20 }, /* mic */ | |
6309 | { 0x19, 0x99a3092f }, /* int-mic */ | |
6310 | { } | |
6311 | }, | |
6312 | }, | |
6313 | [ALC269_FIXUP_DMIC] = { | |
6314 | .type = ALC_FIXUP_PINS, | |
6315 | .v.pins = (const struct alc_pincfg[]) { | |
6316 | { 0x12, 0x99a3092f }, /* int-mic */ | |
6317 | { 0x14, 0x99130110 }, /* speaker */ | |
6318 | { 0x15, 0x0121401f }, /* HP out */ | |
6319 | { 0x18, 0x01a19c20 }, /* mic */ | |
6320 | { } | |
6321 | }, | |
6322 | }, | |
6323 | [ALC269VB_FIXUP_AMIC] = { | |
6324 | .type = ALC_FIXUP_PINS, | |
6325 | .v.pins = (const struct alc_pincfg[]) { | |
6326 | { 0x14, 0x99130110 }, /* speaker */ | |
6327 | { 0x18, 0x01a19c20 }, /* mic */ | |
6328 | { 0x19, 0x99a3092f }, /* int-mic */ | |
6329 | { 0x21, 0x0121401f }, /* HP out */ | |
6330 | { } | |
6331 | }, | |
6332 | }, | |
6333 | [ALC269VB_FIXUP_DMIC] = { | |
6334 | .type = ALC_FIXUP_PINS, | |
6335 | .v.pins = (const struct alc_pincfg[]) { | |
6336 | { 0x12, 0x99a3092f }, /* int-mic */ | |
6337 | { 0x14, 0x99130110 }, /* speaker */ | |
6338 | { 0x18, 0x01a19c20 }, /* mic */ | |
6339 | { 0x21, 0x0121401f }, /* HP out */ | |
6340 | { } | |
6341 | }, | |
6342 | }, | |
6343 | [ALC269_FIXUP_MIC1_MUTE_LED] = { | |
6344 | .type = ALC_FIXUP_FUNC, | |
6345 | .v.func = alc269_fixup_mic1_mute, | |
6346 | }, | |
6347 | [ALC269_FIXUP_MIC2_MUTE_LED] = { | |
6348 | .type = ALC_FIXUP_FUNC, | |
6349 | .v.func = alc269_fixup_mic2_mute, | |
6350 | }, | |
6351 | [ALC269_FIXUP_INV_DMIC] = { | |
6352 | .type = ALC_FIXUP_FUNC, | |
6353 | .v.func = alc_fixup_inv_dmic_0x12, | |
6354 | }, | |
6355 | [ALC269_FIXUP_LENOVO_DOCK] = { | |
6356 | .type = ALC_FIXUP_PINS, | |
6357 | .v.pins = (const struct alc_pincfg[]) { | |
6358 | { 0x19, 0x23a11040 }, /* dock mic */ | |
6359 | { 0x1b, 0x2121103f }, /* dock headphone */ | |
6360 | { } | |
6361 | }, | |
6362 | .chained = true, | |
6363 | .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT | |
6364 | }, | |
6365 | [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = { | |
6366 | .type = ALC_FIXUP_FUNC, | |
6367 | .v.func = alc269_fixup_pincfg_no_hp_to_lineout, | |
6368 | }, | |
6369 | [ALC271_FIXUP_AMIC_MIC2] = { | |
6370 | .type = ALC_FIXUP_PINS, | |
6371 | .v.pins = (const struct alc_pincfg[]) { | |
6372 | { 0x14, 0x99130110 }, /* speaker */ | |
6373 | { 0x19, 0x01a19c20 }, /* mic */ | |
6374 | { 0x1b, 0x99a7012f }, /* int-mic */ | |
6375 | { 0x21, 0x0121401f }, /* HP out */ | |
6376 | { } | |
6377 | }, | |
6378 | }, | |
6379 | [ALC271_FIXUP_HP_GATE_MIC_JACK] = { | |
6380 | .type = ALC_FIXUP_FUNC, | |
6381 | .v.func = alc271_hp_gate_mic_jack, | |
6382 | .chained = true, | |
6383 | .chain_id = ALC271_FIXUP_AMIC_MIC2, | |
6384 | }, | |
6385 | }; | |
6386 | ||
6387 | static const struct snd_pci_quirk alc269_fixup_tbl[] = { | |
6388 | SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC), | |
6389 | SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC), | |
6390 | SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED), | |
6391 | SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED), | |
6392 | SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC), | |
6393 | SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC), | |
6394 | SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW), | |
6395 | SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC), | |
6396 | SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC), | |
6397 | SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC), | |
6398 | SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC), | |
6399 | SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), | |
6400 | SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), | |
6401 | SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2), | |
6402 | SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), | |
6403 | SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), | |
6404 | SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO), | |
6405 | SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z), | |
6406 | SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK), | |
6407 | SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC), | |
6408 | SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK), | |
6409 | SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE), | |
6410 | SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE), | |
6411 | SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE), | |
6412 | SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE), | |
6413 | SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE), | |
6414 | SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK), | |
6415 | SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK), | |
6416 | SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK), | |
6417 | SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK), | |
6418 | SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK), | |
6419 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K), | |
6420 | SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD), | |
6421 | ||
6422 | #if 0 | |
6423 | /* Below is a quirk table taken from the old code. | |
6424 | * Basically the device should work as is without the fixup table. | |
6425 | * If BIOS doesn't give a proper info, enable the corresponding | |
6426 | * fixup entry. | |
6427 | */ | |
6428 | SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A", | |
6429 | ALC269_FIXUP_AMIC), | |
6430 | SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC), | |
6431 | SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC), | |
6432 | SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC), | |
6433 | SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC), | |
6434 | SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC), | |
6435 | SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC), | |
6436 | SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC), | |
6437 | SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC), | |
6438 | SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC), | |
6439 | SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC), | |
6440 | SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC), | |
6441 | SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC), | |
6442 | SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC), | |
6443 | SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC), | |
6444 | SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC), | |
6445 | SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC), | |
6446 | SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC), | |
6447 | SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC), | |
6448 | SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC), | |
6449 | SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC), | |
6450 | SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC), | |
6451 | SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC), | |
6452 | SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC), | |
6453 | SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC), | |
6454 | SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC), | |
6455 | SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC), | |
6456 | SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC), | |
6457 | SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC), | |
6458 | SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC), | |
6459 | SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC), | |
6460 | SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC), | |
6461 | SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC), | |
6462 | SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC), | |
6463 | SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC), | |
6464 | SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC), | |
6465 | SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC), | |
6466 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC), | |
6467 | SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC), | |
6468 | SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC), | |
6469 | #endif | |
6470 | {} | |
6471 | }; | |
6472 | ||
6473 | static const struct alc_model_fixup alc269_fixup_models[] = { | |
6474 | {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"}, | |
6475 | {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"}, | |
6476 | {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"}, | |
6477 | {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"}, | |
6478 | {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"}, | |
6479 | {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"}, | |
6480 | {} | |
6481 | }; | |
6482 | ||
6483 | ||
6484 | static void alc269_fill_coef(struct hda_codec *codec) | |
6485 | { | |
6486 | struct alc_spec *spec = codec->spec; | |
6487 | int val; | |
6488 | ||
6489 | if (spec->codec_variant != ALC269_TYPE_ALC269VB) | |
6490 | return; | |
6491 | ||
6492 | if ((alc_get_coef0(codec) & 0x00ff) < 0x015) { | |
6493 | alc_write_coef_idx(codec, 0xf, 0x960b); | |
6494 | alc_write_coef_idx(codec, 0xe, 0x8817); | |
6495 | } | |
6496 | ||
6497 | if ((alc_get_coef0(codec) & 0x00ff) == 0x016) { | |
6498 | alc_write_coef_idx(codec, 0xf, 0x960b); | |
6499 | alc_write_coef_idx(codec, 0xe, 0x8814); | |
6500 | } | |
6501 | ||
6502 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) { | |
6503 | val = alc_read_coef_idx(codec, 0x04); | |
6504 | /* Power up output pin */ | |
6505 | alc_write_coef_idx(codec, 0x04, val | (1<<11)); | |
6506 | } | |
6507 | ||
6508 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { | |
6509 | val = alc_read_coef_idx(codec, 0xd); | |
6510 | if ((val & 0x0c00) >> 10 != 0x1) { | |
6511 | /* Capless ramp up clock control */ | |
6512 | alc_write_coef_idx(codec, 0xd, val | (1<<10)); | |
6513 | } | |
6514 | val = alc_read_coef_idx(codec, 0x17); | |
6515 | if ((val & 0x01c0) >> 6 != 0x4) { | |
6516 | /* Class D power on reset */ | |
6517 | alc_write_coef_idx(codec, 0x17, val | (1<<7)); | |
6518 | } | |
6519 | } | |
6520 | ||
6521 | val = alc_read_coef_idx(codec, 0xd); /* Class D */ | |
6522 | alc_write_coef_idx(codec, 0xd, val | (1<<14)); | |
6523 | ||
6524 | val = alc_read_coef_idx(codec, 0x4); /* HP */ | |
6525 | alc_write_coef_idx(codec, 0x4, val | (1<<11)); | |
6526 | } | |
6527 | ||
6528 | /* | |
6529 | */ | |
6530 | static int patch_alc269(struct hda_codec *codec) | |
6531 | { | |
6532 | struct alc_spec *spec; | |
6533 | int err; | |
6534 | ||
6535 | err = alc_alloc_spec(codec, 0x0b); | |
6536 | if (err < 0) | |
6537 | return err; | |
6538 | ||
6539 | spec = codec->spec; | |
6540 | spec->shared_mic_vref_pin = 0x18; | |
6541 | ||
6542 | alc_pick_fixup(codec, alc269_fixup_models, | |
6543 | alc269_fixup_tbl, alc269_fixups); | |
6544 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
6545 | ||
6546 | alc_auto_parse_customize_define(codec); | |
6547 | ||
6548 | switch (codec->vendor_id) { | |
6549 | case 0x10ec0269: | |
6550 | spec->codec_variant = ALC269_TYPE_ALC269VA; | |
6551 | switch (alc_get_coef0(codec) & 0x00f0) { | |
6552 | case 0x0010: | |
6553 | if (codec->bus->pci->subsystem_vendor == 0x1025 && | |
6554 | spec->cdefine.platform_type == 1) | |
6555 | err = alc_codec_rename(codec, "ALC271X"); | |
6556 | spec->codec_variant = ALC269_TYPE_ALC269VB; | |
6557 | break; | |
6558 | case 0x0020: | |
6559 | if (codec->bus->pci->subsystem_vendor == 0x17aa && | |
6560 | codec->bus->pci->subsystem_device == 0x21f3) | |
6561 | err = alc_codec_rename(codec, "ALC3202"); | |
6562 | spec->codec_variant = ALC269_TYPE_ALC269VC; | |
6563 | break; | |
6564 | case 0x0030: | |
6565 | spec->codec_variant = ALC269_TYPE_ALC269VD; | |
6566 | break; | |
6567 | default: | |
6568 | alc_fix_pll_init(codec, 0x20, 0x04, 15); | |
6569 | } | |
6570 | if (err < 0) | |
6571 | goto error; | |
6572 | spec->init_hook = alc269_fill_coef; | |
6573 | alc269_fill_coef(codec); | |
6574 | break; | |
6575 | ||
6576 | case 0x10ec0280: | |
6577 | case 0x10ec0290: | |
6578 | spec->codec_variant = ALC269_TYPE_ALC280; | |
6579 | break; | |
6580 | case 0x10ec0282: | |
6581 | case 0x10ec0283: | |
6582 | spec->codec_variant = ALC269_TYPE_ALC282; | |
6583 | break; | |
6584 | case 0x10ec0284: | |
6585 | case 0x10ec0292: | |
6586 | spec->codec_variant = ALC269_TYPE_ALC284; | |
6587 | break; | |
6588 | } | |
6589 | ||
6590 | /* automatic parse from the BIOS config */ | |
6591 | err = alc269_parse_auto_config(codec); | |
6592 | if (err < 0) | |
6593 | goto error; | |
6594 | ||
6595 | if (!spec->no_analog && has_cdefine_beep(codec)) { | |
6596 | err = snd_hda_attach_beep_device(codec, 0x1); | |
6597 | if (err < 0) | |
6598 | goto error; | |
6599 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); | |
6600 | } | |
6601 | ||
6602 | codec->patch_ops = alc_patch_ops; | |
6603 | #ifdef CONFIG_PM | |
6604 | codec->patch_ops.resume = alc269_resume; | |
6605 | #endif | |
6606 | spec->shutup = alc269_shutup; | |
6607 | ||
6608 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); | |
6609 | ||
6610 | return 0; | |
6611 | ||
6612 | error: | |
6613 | alc_free(codec); | |
6614 | return err; | |
6615 | } | |
6616 | ||
6617 | /* | |
6618 | * ALC861 | |
6619 | */ | |
6620 | ||
6621 | static int alc861_parse_auto_config(struct hda_codec *codec) | |
6622 | { | |
6623 | static const hda_nid_t alc861_ignore[] = { 0x1d, 0 }; | |
6624 | static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 }; | |
6625 | return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids); | |
6626 | } | |
6627 | ||
6628 | /* Pin config fixes */ | |
6629 | enum { | |
6630 | ALC861_FIXUP_FSC_AMILO_PI1505, | |
6631 | ALC861_FIXUP_AMP_VREF_0F, | |
6632 | ALC861_FIXUP_NO_JACK_DETECT, | |
6633 | ALC861_FIXUP_ASUS_A6RP, | |
6634 | }; | |
6635 | ||
6636 | /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */ | |
6637 | static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec, | |
6638 | const struct alc_fixup *fix, int action) | |
6639 | { | |
6640 | struct alc_spec *spec = codec->spec; | |
6641 | unsigned int val; | |
6642 | ||
6643 | if (action != ALC_FIXUP_ACT_INIT) | |
6644 | return; | |
6645 | val = snd_hda_codec_read(codec, 0x0f, 0, | |
6646 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | |
6647 | if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))) | |
6648 | val |= AC_PINCTL_IN_EN; | |
6649 | val |= AC_PINCTL_VREF_50; | |
6650 | snd_hda_set_pin_ctl(codec, 0x0f, val); | |
6651 | spec->keep_vref_in_automute = 1; | |
6652 | } | |
6653 | ||
6654 | /* suppress the jack-detection */ | |
6655 | static void alc_fixup_no_jack_detect(struct hda_codec *codec, | |
6656 | const struct alc_fixup *fix, int action) | |
6657 | { | |
6658 | if (action == ALC_FIXUP_ACT_PRE_PROBE) | |
6659 | codec->no_jack_detect = 1; | |
6660 | } | |
6661 | ||
6662 | static const struct alc_fixup alc861_fixups[] = { | |
6663 | [ALC861_FIXUP_FSC_AMILO_PI1505] = { | |
6664 | .type = ALC_FIXUP_PINS, | |
6665 | .v.pins = (const struct alc_pincfg[]) { | |
6666 | { 0x0b, 0x0221101f }, /* HP */ | |
6667 | { 0x0f, 0x90170310 }, /* speaker */ | |
6668 | { } | |
6669 | } | |
6670 | }, | |
6671 | [ALC861_FIXUP_AMP_VREF_0F] = { | |
6672 | .type = ALC_FIXUP_FUNC, | |
6673 | .v.func = alc861_fixup_asus_amp_vref_0f, | |
6674 | }, | |
6675 | [ALC861_FIXUP_NO_JACK_DETECT] = { | |
6676 | .type = ALC_FIXUP_FUNC, | |
6677 | .v.func = alc_fixup_no_jack_detect, | |
6678 | }, | |
6679 | [ALC861_FIXUP_ASUS_A6RP] = { | |
6680 | .type = ALC_FIXUP_FUNC, | |
6681 | .v.func = alc861_fixup_asus_amp_vref_0f, | |
6682 | .chained = true, | |
6683 | .chain_id = ALC861_FIXUP_NO_JACK_DETECT, | |
6684 | } | |
6685 | }; | |
6686 | ||
6687 | static const struct snd_pci_quirk alc861_fixup_tbl[] = { | |
6688 | SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP), | |
6689 | SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F), | |
6690 | SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT), | |
6691 | SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F), | |
6692 | SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F), | |
6693 | SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505), | |
6694 | {} | |
6695 | }; | |
6696 | ||
6697 | /* | |
6698 | */ | |
6699 | static int patch_alc861(struct hda_codec *codec) | |
6700 | { | |
6701 | struct alc_spec *spec; | |
6702 | int err; | |
6703 | ||
6704 | err = alc_alloc_spec(codec, 0x15); | |
6705 | if (err < 0) | |
6706 | return err; | |
6707 | ||
6708 | spec = codec->spec; | |
6709 | ||
6710 | alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); | |
6711 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
6712 | ||
6713 | /* automatic parse from the BIOS config */ | |
6714 | err = alc861_parse_auto_config(codec); | |
6715 | if (err < 0) | |
6716 | goto error; | |
6717 | ||
6718 | if (!spec->no_analog) { | |
6719 | err = snd_hda_attach_beep_device(codec, 0x23); | |
6720 | if (err < 0) | |
6721 | goto error; | |
6722 | set_beep_amp(spec, 0x23, 0, HDA_OUTPUT); | |
6723 | } | |
6724 | ||
6725 | codec->patch_ops = alc_patch_ops; | |
6726 | #ifdef CONFIG_PM | |
6727 | spec->power_hook = alc_power_eapd; | |
6728 | #endif | |
6729 | ||
6730 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); | |
6731 | ||
6732 | return 0; | |
6733 | ||
6734 | error: | |
6735 | alc_free(codec); | |
6736 | return err; | |
6737 | } | |
6738 | ||
6739 | /* | |
6740 | * ALC861-VD support | |
6741 | * | |
6742 | * Based on ALC882 | |
6743 | * | |
6744 | * In addition, an independent DAC | |
6745 | */ | |
6746 | static int alc861vd_parse_auto_config(struct hda_codec *codec) | |
6747 | { | |
6748 | static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 }; | |
6749 | static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 }; | |
6750 | return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids); | |
6751 | } | |
6752 | ||
6753 | enum { | |
6754 | ALC660VD_FIX_ASUS_GPIO1, | |
6755 | ALC861VD_FIX_DALLAS, | |
6756 | }; | |
6757 | ||
6758 | /* exclude VREF80 */ | |
6759 | static void alc861vd_fixup_dallas(struct hda_codec *codec, | |
6760 | const struct alc_fixup *fix, int action) | |
6761 | { | |
6762 | if (action == ALC_FIXUP_ACT_PRE_PROBE) { | |
6763 | snd_hda_override_pin_caps(codec, 0x18, 0x00000734); | |
6764 | snd_hda_override_pin_caps(codec, 0x19, 0x0000073c); | |
6765 | } | |
6766 | } | |
6767 | ||
6768 | static const struct alc_fixup alc861vd_fixups[] = { | |
6769 | [ALC660VD_FIX_ASUS_GPIO1] = { | |
6770 | .type = ALC_FIXUP_VERBS, | |
6771 | .v.verbs = (const struct hda_verb[]) { | |
6772 | /* reset GPIO1 */ | |
6773 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, | |
6774 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, | |
6775 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, | |
6776 | { } | |
6777 | } | |
6778 | }, | |
6779 | [ALC861VD_FIX_DALLAS] = { | |
6780 | .type = ALC_FIXUP_FUNC, | |
6781 | .v.func = alc861vd_fixup_dallas, | |
6782 | }, | |
6783 | }; | |
6784 | ||
6785 | static const struct snd_pci_quirk alc861vd_fixup_tbl[] = { | |
6786 | SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS), | |
6787 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1), | |
6788 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS), | |
6789 | {} | |
6790 | }; | |
6791 | ||
6792 | /* | |
6793 | */ | |
6794 | static int patch_alc861vd(struct hda_codec *codec) | |
6795 | { | |
6796 | struct alc_spec *spec; | |
6797 | int err; | |
6798 | ||
6799 | err = alc_alloc_spec(codec, 0x0b); | |
6800 | if (err < 0) | |
6801 | return err; | |
6802 | ||
6803 | spec = codec->spec; | |
6804 | ||
6805 | alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); | |
6806 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
6807 | ||
6808 | /* automatic parse from the BIOS config */ | |
6809 | err = alc861vd_parse_auto_config(codec); | |
6810 | if (err < 0) | |
6811 | goto error; | |
6812 | ||
6813 | if (!spec->no_analog) { | |
6814 | err = snd_hda_attach_beep_device(codec, 0x23); | |
6815 | if (err < 0) | |
6816 | goto error; | |
6817 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); | |
6818 | } | |
6819 | ||
6820 | codec->patch_ops = alc_patch_ops; | |
6821 | ||
6822 | spec->shutup = alc_eapd_shutup; | |
6823 | ||
6824 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); | |
6825 | ||
6826 | return 0; | |
6827 | ||
6828 | error: | |
6829 | alc_free(codec); | |
6830 | return err; | |
6831 | } | |
6832 | ||
6833 | /* | |
6834 | * ALC662 support | |
6835 | * | |
6836 | * ALC662 is almost identical with ALC880 but has cleaner and more flexible | |
6837 | * configuration. Each pin widget can choose any input DACs and a mixer. | |
6838 | * Each ADC is connected from a mixer of all inputs. This makes possible | |
6839 | * 6-channel independent captures. | |
6840 | * | |
6841 | * In addition, an independent DAC for the multi-playback (not used in this | |
6842 | * driver yet). | |
6843 | */ | |
6844 | ||
6845 | /* | |
6846 | * BIOS auto configuration | |
6847 | */ | |
6848 | ||
6849 | static int alc662_parse_auto_config(struct hda_codec *codec) | |
6850 | { | |
6851 | static const hda_nid_t alc662_ignore[] = { 0x1d, 0 }; | |
6852 | static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 }; | |
6853 | static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 }; | |
6854 | const hda_nid_t *ssids; | |
6855 | ||
6856 | if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 || | |
6857 | codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670) | |
6858 | ssids = alc663_ssids; | |
6859 | else | |
6860 | ssids = alc662_ssids; | |
6861 | return alc_parse_auto_config(codec, alc662_ignore, ssids); | |
6862 | } | |
6863 | ||
6864 | static void alc272_fixup_mario(struct hda_codec *codec, | |
6865 | const struct alc_fixup *fix, int action) | |
6866 | { | |
6867 | if (action != ALC_FIXUP_ACT_PROBE) | |
6868 | return; | |
6869 | if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT, | |
6870 | (0x3b << AC_AMPCAP_OFFSET_SHIFT) | | |
6871 | (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) | | |
6872 | (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) | | |
6873 | (0 << AC_AMPCAP_MUTE_SHIFT))) | |
6874 | printk(KERN_WARNING | |
6875 | "hda_codec: failed to override amp caps for NID 0x2\n"); | |
6876 | } | |
6877 | ||
6878 | enum { | |
6879 | ALC662_FIXUP_ASPIRE, | |
6880 | ALC662_FIXUP_IDEAPAD, | |
6881 | ALC272_FIXUP_MARIO, | |
6882 | ALC662_FIXUP_CZC_P10T, | |
6883 | ALC662_FIXUP_SKU_IGNORE, | |
6884 | ALC662_FIXUP_HP_RP5800, | |
6885 | ALC662_FIXUP_ASUS_MODE1, | |
6886 | ALC662_FIXUP_ASUS_MODE2, | |
6887 | ALC662_FIXUP_ASUS_MODE3, | |
6888 | ALC662_FIXUP_ASUS_MODE4, | |
6889 | ALC662_FIXUP_ASUS_MODE5, | |
6890 | ALC662_FIXUP_ASUS_MODE6, | |
6891 | ALC662_FIXUP_ASUS_MODE7, | |
6892 | ALC662_FIXUP_ASUS_MODE8, | |
6893 | ALC662_FIXUP_NO_JACK_DETECT, | |
6894 | ALC662_FIXUP_ZOTAC_Z68, | |
6895 | ALC662_FIXUP_INV_DMIC, | |
6896 | }; | |
6897 | ||
6898 | static const struct alc_fixup alc662_fixups[] = { | |
6899 | [ALC662_FIXUP_ASPIRE] = { | |
6900 | .type = ALC_FIXUP_PINS, | |
6901 | .v.pins = (const struct alc_pincfg[]) { | |
6902 | { 0x15, 0x99130112 }, /* subwoofer */ | |
6903 | { } | |
6904 | } | |
6905 | }, | |
6906 | [ALC662_FIXUP_IDEAPAD] = { | |
6907 | .type = ALC_FIXUP_PINS, | |
6908 | .v.pins = (const struct alc_pincfg[]) { | |
6909 | { 0x17, 0x99130112 }, /* subwoofer */ | |
6910 | { } | |
6911 | } | |
6912 | }, | |
6913 | [ALC272_FIXUP_MARIO] = { | |
6914 | .type = ALC_FIXUP_FUNC, | |
6915 | .v.func = alc272_fixup_mario, | |
6916 | }, | |
6917 | [ALC662_FIXUP_CZC_P10T] = { | |
6918 | .type = ALC_FIXUP_VERBS, | |
6919 | .v.verbs = (const struct hda_verb[]) { | |
6920 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, | |
6921 | {} | |
6922 | } | |
6923 | }, | |
6924 | [ALC662_FIXUP_SKU_IGNORE] = { | |
6925 | .type = ALC_FIXUP_FUNC, | |
6926 | .v.func = alc_fixup_sku_ignore, | |
6927 | }, | |
6928 | [ALC662_FIXUP_HP_RP5800] = { | |
6929 | .type = ALC_FIXUP_PINS, | |
6930 | .v.pins = (const struct alc_pincfg[]) { | |
6931 | { 0x14, 0x0221201f }, /* HP out */ | |
6932 | { } | |
6933 | }, | |
6934 | .chained = true, | |
6935 | .chain_id = ALC662_FIXUP_SKU_IGNORE | |
6936 | }, | |
6937 | [ALC662_FIXUP_ASUS_MODE1] = { | |
6938 | .type = ALC_FIXUP_PINS, | |
6939 | .v.pins = (const struct alc_pincfg[]) { | |
6940 | { 0x14, 0x99130110 }, /* speaker */ | |
6941 | { 0x18, 0x01a19c20 }, /* mic */ | |
6942 | { 0x19, 0x99a3092f }, /* int-mic */ | |
6943 | { 0x21, 0x0121401f }, /* HP out */ | |
6944 | { } | |
6945 | }, | |
6946 | .chained = true, | |
6947 | .chain_id = ALC662_FIXUP_SKU_IGNORE | |
6948 | }, | |
6949 | [ALC662_FIXUP_ASUS_MODE2] = { | |
6950 | .type = ALC_FIXUP_PINS, | |
6951 | .v.pins = (const struct alc_pincfg[]) { | |
6952 | { 0x14, 0x99130110 }, /* speaker */ | |
6953 | { 0x18, 0x01a19820 }, /* mic */ | |
6954 | { 0x19, 0x99a3092f }, /* int-mic */ | |
6955 | { 0x1b, 0x0121401f }, /* HP out */ | |
6956 | { } | |
6957 | }, | |
6958 | .chained = true, | |
6959 | .chain_id = ALC662_FIXUP_SKU_IGNORE | |
6960 | }, | |
6961 | [ALC662_FIXUP_ASUS_MODE3] = { | |
6962 | .type = ALC_FIXUP_PINS, | |
6963 | .v.pins = (const struct alc_pincfg[]) { | |
6964 | { 0x14, 0x99130110 }, /* speaker */ | |
6965 | { 0x15, 0x0121441f }, /* HP */ | |
6966 | { 0x18, 0x01a19840 }, /* mic */ | |
6967 | { 0x19, 0x99a3094f }, /* int-mic */ | |
6968 | { 0x21, 0x01211420 }, /* HP2 */ | |
6969 | { } | |
6970 | }, | |
6971 | .chained = true, | |
6972 | .chain_id = ALC662_FIXUP_SKU_IGNORE | |
6973 | }, | |
6974 | [ALC662_FIXUP_ASUS_MODE4] = { | |
6975 | .type = ALC_FIXUP_PINS, | |
6976 | .v.pins = (const struct alc_pincfg[]) { | |
6977 | { 0x14, 0x99130110 }, /* speaker */ | |
6978 | { 0x16, 0x99130111 }, /* speaker */ | |
6979 | { 0x18, 0x01a19840 }, /* mic */ | |
6980 | { 0x19, 0x99a3094f }, /* int-mic */ | |
6981 | { 0x21, 0x0121441f }, /* HP */ | |
6982 | { } | |
6983 | }, | |
6984 | .chained = true, | |
6985 | .chain_id = ALC662_FIXUP_SKU_IGNORE | |
6986 | }, | |
6987 | [ALC662_FIXUP_ASUS_MODE5] = { | |
6988 | .type = ALC_FIXUP_PINS, | |
6989 | .v.pins = (const struct alc_pincfg[]) { | |
6990 | { 0x14, 0x99130110 }, /* speaker */ | |
6991 | { 0x15, 0x0121441f }, /* HP */ | |
6992 | { 0x16, 0x99130111 }, /* speaker */ | |
6993 | { 0x18, 0x01a19840 }, /* mic */ | |
6994 | { 0x19, 0x99a3094f }, /* int-mic */ | |
6995 | { } | |
6996 | }, | |
6997 | .chained = true, | |
6998 | .chain_id = ALC662_FIXUP_SKU_IGNORE | |
6999 | }, | |
7000 | [ALC662_FIXUP_ASUS_MODE6] = { | |
7001 | .type = ALC_FIXUP_PINS, | |
7002 | .v.pins = (const struct alc_pincfg[]) { | |
7003 | { 0x14, 0x99130110 }, /* speaker */ | |
7004 | { 0x15, 0x01211420 }, /* HP2 */ | |
7005 | { 0x18, 0x01a19840 }, /* mic */ | |
7006 | { 0x19, 0x99a3094f }, /* int-mic */ | |
7007 | { 0x1b, 0x0121441f }, /* HP */ | |
7008 | { } | |
7009 | }, | |
7010 | .chained = true, | |
7011 | .chain_id = ALC662_FIXUP_SKU_IGNORE | |
7012 | }, | |
7013 | [ALC662_FIXUP_ASUS_MODE7] = { | |
7014 | .type = ALC_FIXUP_PINS, | |
7015 | .v.pins = (const struct alc_pincfg[]) { | |
7016 | { 0x14, 0x99130110 }, /* speaker */ | |
7017 | { 0x17, 0x99130111 }, /* speaker */ | |
7018 | { 0x18, 0x01a19840 }, /* mic */ | |
7019 | { 0x19, 0x99a3094f }, /* int-mic */ | |
7020 | { 0x1b, 0x01214020 }, /* HP */ | |
7021 | { 0x21, 0x0121401f }, /* HP */ | |
7022 | { } | |
7023 | }, | |
7024 | .chained = true, | |
7025 | .chain_id = ALC662_FIXUP_SKU_IGNORE | |
7026 | }, | |
7027 | [ALC662_FIXUP_ASUS_MODE8] = { | |
7028 | .type = ALC_FIXUP_PINS, | |
7029 | .v.pins = (const struct alc_pincfg[]) { | |
7030 | { 0x14, 0x99130110 }, /* speaker */ | |
7031 | { 0x12, 0x99a30970 }, /* int-mic */ | |
7032 | { 0x15, 0x01214020 }, /* HP */ | |
7033 | { 0x17, 0x99130111 }, /* speaker */ | |
7034 | { 0x18, 0x01a19840 }, /* mic */ | |
7035 | { 0x21, 0x0121401f }, /* HP */ | |
7036 | { } | |
7037 | }, | |
7038 | .chained = true, | |
7039 | .chain_id = ALC662_FIXUP_SKU_IGNORE | |
7040 | }, | |
7041 | [ALC662_FIXUP_NO_JACK_DETECT] = { | |
7042 | .type = ALC_FIXUP_FUNC, | |
7043 | .v.func = alc_fixup_no_jack_detect, | |
7044 | }, | |
7045 | [ALC662_FIXUP_ZOTAC_Z68] = { | |
7046 | .type = ALC_FIXUP_PINS, | |
7047 | .v.pins = (const struct alc_pincfg[]) { | |
7048 | { 0x1b, 0x02214020 }, /* Front HP */ | |
7049 | { } | |
7050 | } | |
7051 | }, | |
7052 | [ALC662_FIXUP_INV_DMIC] = { | |
7053 | .type = ALC_FIXUP_FUNC, | |
7054 | .v.func = alc_fixup_inv_dmic_0x12, | |
7055 | }, | |
7056 | }; | |
7057 | ||
7058 | static const struct snd_pci_quirk alc662_fixup_tbl[] = { | |
7059 | SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2), | |
7060 | SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE), | |
7061 | SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE), | |
7062 | SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC), | |
7063 | SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE), | |
7064 | SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), | |
7065 | SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT), | |
7066 | SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2), | |
7067 | SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD), | |
7068 | SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD), | |
7069 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD), | |
7070 | SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68), | |
7071 | SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T), | |
7072 | ||
7073 | #if 0 | |
7074 | /* Below is a quirk table taken from the old code. | |
7075 | * Basically the device should work as is without the fixup table. | |
7076 | * If BIOS doesn't give a proper info, enable the corresponding | |
7077 | * fixup entry. | |
7078 | */ | |
7079 | SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1), | |
7080 | SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3), | |
7081 | SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1), | |
7082 | SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3), | |
7083 | SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), | |
7084 | SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), | |
7085 | SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), | |
7086 | SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1), | |
7087 | SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1), | |
7088 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), | |
7089 | SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7), | |
7090 | SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7), | |
7091 | SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8), | |
7092 | SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3), | |
7093 | SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1), | |
7094 | SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), | |
7095 | SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2), | |
7096 | SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1), | |
7097 | SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), | |
7098 | SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), | |
7099 | SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), | |
7100 | SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), | |
7101 | SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1), | |
7102 | SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3), | |
7103 | SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2), | |
7104 | SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), | |
7105 | SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5), | |
7106 | SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6), | |
7107 | SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), | |
7108 | SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1), | |
7109 | SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), | |
7110 | SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), | |
7111 | SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3), | |
7112 | SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3), | |
7113 | SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1), | |
7114 | SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1), | |
7115 | SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1), | |
7116 | SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1), | |
7117 | SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1), | |
7118 | SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2), | |
7119 | SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2), | |
7120 | SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1), | |
7121 | SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), | |
7122 | SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3), | |
7123 | SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1), | |
7124 | SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1), | |
7125 | SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1), | |
7126 | SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2), | |
7127 | SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1), | |
7128 | SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4), | |
7129 | #endif | |
7130 | {} | |
7131 | }; | |
7132 | ||
7133 | static const struct alc_model_fixup alc662_fixup_models[] = { | |
7134 | {.id = ALC272_FIXUP_MARIO, .name = "mario"}, | |
7135 | {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"}, | |
7136 | {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"}, | |
7137 | {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"}, | |
7138 | {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"}, | |
7139 | {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"}, | |
7140 | {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"}, | |
7141 | {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"}, | |
7142 | {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"}, | |
7143 | {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"}, | |
7144 | {} | |
7145 | }; | |
7146 | ||
7147 | static void alc662_fill_coef(struct hda_codec *codec) | |
7148 | { | |
7149 | int val, coef; | |
7150 | ||
7151 | coef = alc_get_coef0(codec); | |
7152 | ||
7153 | switch (codec->vendor_id) { | |
7154 | case 0x10ec0662: | |
7155 | if ((coef & 0x00f0) == 0x0030) { | |
7156 | val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */ | |
7157 | alc_write_coef_idx(codec, 0x4, val & ~(1<<10)); | |
7158 | } | |
7159 | break; | |
7160 | case 0x10ec0272: | |
7161 | case 0x10ec0273: | |
7162 | case 0x10ec0663: | |
7163 | case 0x10ec0665: | |
7164 | case 0x10ec0670: | |
7165 | case 0x10ec0671: | |
7166 | case 0x10ec0672: | |
7167 | val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */ | |
7168 | alc_write_coef_idx(codec, 0xd, val | (1<<14)); | |
7169 | break; | |
7170 | } | |
7171 | } | |
7172 | ||
7173 | /* | |
7174 | */ | |
7175 | static int patch_alc662(struct hda_codec *codec) | |
7176 | { | |
7177 | struct alc_spec *spec; | |
7178 | int err; | |
7179 | ||
7180 | err = alc_alloc_spec(codec, 0x0b); | |
7181 | if (err < 0) | |
7182 | return err; | |
7183 | ||
7184 | spec = codec->spec; | |
7185 | ||
7186 | /* handle multiple HPs as is */ | |
7187 | spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; | |
7188 | ||
7189 | alc_fix_pll_init(codec, 0x20, 0x04, 15); | |
7190 | ||
7191 | spec->init_hook = alc662_fill_coef; | |
7192 | alc662_fill_coef(codec); | |
7193 | ||
7194 | alc_pick_fixup(codec, alc662_fixup_models, | |
7195 | alc662_fixup_tbl, alc662_fixups); | |
7196 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
7197 | ||
7198 | alc_auto_parse_customize_define(codec); | |
7199 | ||
7200 | if ((alc_get_coef0(codec) & (1 << 14)) && | |
7201 | codec->bus->pci->subsystem_vendor == 0x1025 && | |
7202 | spec->cdefine.platform_type == 1) { | |
7203 | if (alc_codec_rename(codec, "ALC272X") < 0) | |
7204 | goto error; | |
7205 | } | |
7206 | ||
7207 | /* automatic parse from the BIOS config */ | |
7208 | err = alc662_parse_auto_config(codec); | |
7209 | if (err < 0) | |
7210 | goto error; | |
7211 | ||
7212 | if (!spec->no_analog && has_cdefine_beep(codec)) { | |
7213 | err = snd_hda_attach_beep_device(codec, 0x1); | |
7214 | if (err < 0) | |
7215 | goto error; | |
7216 | switch (codec->vendor_id) { | |
7217 | case 0x10ec0662: | |
7218 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); | |
7219 | break; | |
7220 | case 0x10ec0272: | |
7221 | case 0x10ec0663: | |
7222 | case 0x10ec0665: | |
7223 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); | |
7224 | break; | |
7225 | case 0x10ec0273: | |
7226 | set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT); | |
7227 | break; | |
7228 | } | |
7229 | } | |
7230 | ||
7231 | codec->patch_ops = alc_patch_ops; | |
7232 | spec->shutup = alc_eapd_shutup; | |
7233 | ||
7234 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); | |
7235 | ||
7236 | return 0; | |
7237 | ||
7238 | error: | |
7239 | alc_free(codec); | |
7240 | return err; | |
7241 | } | |
7242 | ||
7243 | /* | |
7244 | * ALC680 support | |
7245 | */ | |
7246 | ||
7247 | static int alc680_parse_auto_config(struct hda_codec *codec) | |
7248 | { | |
7249 | return alc_parse_auto_config(codec, NULL, NULL); | |
7250 | } | |
7251 | ||
7252 | /* | |
7253 | */ | |
7254 | static int patch_alc680(struct hda_codec *codec) | |
7255 | { | |
7256 | int err; | |
7257 | ||
7258 | /* ALC680 has no aa-loopback mixer */ | |
7259 | err = alc_alloc_spec(codec, 0); | |
7260 | if (err < 0) | |
7261 | return err; | |
7262 | ||
7263 | /* automatic parse from the BIOS config */ | |
7264 | err = alc680_parse_auto_config(codec); | |
7265 | if (err < 0) { | |
7266 | alc_free(codec); | |
7267 | return err; | |
7268 | } | |
7269 | ||
7270 | codec->patch_ops = alc_patch_ops; | |
7271 | ||
7272 | return 0; | |
7273 | } | |
7274 | ||
7275 | /* | |
7276 | * patch entries | |
7277 | */ | |
7278 | static const struct hda_codec_preset snd_hda_preset_realtek[] = { | |
7279 | { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 }, | |
7280 | { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 }, | |
7281 | { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 }, | |
7282 | { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 }, | |
7283 | { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 }, | |
7284 | { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 }, | |
7285 | { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 }, | |
7286 | { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 }, | |
7287 | { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 }, | |
7288 | { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 }, | |
7289 | { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 }, | |
7290 | { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 }, | |
7291 | { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 }, | |
7292 | { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 }, | |
7293 | { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 }, | |
7294 | { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 }, | |
7295 | { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660", | |
7296 | .patch = patch_alc861 }, | |
7297 | { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd }, | |
7298 | { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 }, | |
7299 | { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd }, | |
7300 | { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2", | |
7301 | .patch = patch_alc882 }, | |
7302 | { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1", | |
7303 | .patch = patch_alc662 }, | |
7304 | { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3", | |
7305 | .patch = patch_alc662 }, | |
7306 | { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 }, | |
7307 | { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 }, | |
7308 | { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 }, | |
7309 | { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 }, | |
7310 | { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 }, | |
7311 | { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, | |
7312 | { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, | |
7313 | { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 }, | |
7314 | { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A", | |
7315 | .patch = patch_alc882 }, | |
7316 | { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A", | |
7317 | .patch = patch_alc882 }, | |
7318 | { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, | |
7319 | { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 }, | |
7320 | { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", | |
7321 | .patch = patch_alc882 }, | |
7322 | { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 }, | |
7323 | { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 }, | |
7324 | { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 }, | |
7325 | { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 }, | |
7326 | { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 }, | |
7327 | {} /* terminator */ | |
7328 | }; | |
7329 | ||
7330 | MODULE_ALIAS("snd-hda-codec-id:10ec*"); | |
7331 | ||
7332 | MODULE_LICENSE("GPL"); | |
7333 | MODULE_DESCRIPTION("Realtek HD-audio codec"); | |
7334 | ||
7335 | static struct hda_codec_preset_list realtek_list = { | |
7336 | .preset = snd_hda_preset_realtek, | |
7337 | .owner = THIS_MODULE, | |
7338 | }; | |
7339 | ||
7340 | static int __init patch_realtek_init(void) | |
7341 | { | |
7342 | return snd_hda_add_codec_preset(&realtek_list); | |
7343 | } | |
7344 | ||
7345 | static void __exit patch_realtek_exit(void) | |
7346 | { | |
7347 | snd_hda_delete_codec_preset(&realtek_list); | |
7348 | } | |
7349 | ||
7350 | module_init(patch_realtek_init) | |
7351 | module_exit(patch_realtek_exit) |