Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Universal Interface for Intel High Definition Audio Codec | |
3 | * | |
1d045db9 | 4 | * HD audio interface patch for Realtek ALC codecs |
1da177e4 | 5 | * |
df694daa KY |
6 | * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw> |
7 | * PeiSen Hou <pshou@realtek.com.tw> | |
1da177e4 | 8 | * Takashi Iwai <tiwai@suse.de> |
409a3e98 | 9 | * Jonathan Woithe <jwoithe@just42.net> |
1da177e4 LT |
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 | ||
1da177e4 LT |
26 | #include <linux/init.h> |
27 | #include <linux/delay.h> | |
28 | #include <linux/slab.h> | |
29 | #include <linux/pci.h> | |
da155d5b | 30 | #include <linux/module.h> |
1da177e4 | 31 | #include <sound/core.h> |
9ad0e496 | 32 | #include <sound/jack.h> |
1da177e4 LT |
33 | #include "hda_codec.h" |
34 | #include "hda_local.h" | |
23d30f28 | 35 | #include "hda_auto_parser.h" |
680cd536 | 36 | #include "hda_beep.h" |
1835a0f9 | 37 | #include "hda_jack.h" |
1da177e4 | 38 | |
1d045db9 TI |
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 | |
d4a86d81 | 44 | |
df694daa KY |
45 | /* for GPIO Poll */ |
46 | #define GPIO_MASK 0x03 | |
47 | ||
4a79ba34 TI |
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 | ||
da00c244 KY |
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; | |
90622917 | 67 | unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */ |
da00c244 KY |
68 | }; |
69 | ||
ce764ab2 TI |
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 | ||
23d30f28 TI |
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 | ||
30dcd3b4 TI |
94 | #define MAX_NID_PATH_DEPTH 5 |
95 | ||
8dd48678 TI |
96 | enum { |
97 | NID_PATH_VOL_CTL, | |
98 | NID_PATH_MUTE_CTL, | |
99 | NID_PATH_BOOST_CTL, | |
100 | NID_PATH_NUM_CTLS | |
101 | }; | |
102 | ||
36f0fd54 TI |
103 | /* Widget connection path |
104 | * | |
105 | * For output, stored in the order of DAC -> ... -> pin, | |
106 | * for input, pin -> ... -> ADC. | |
107 | * | |
95e960ce TI |
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 | |
30dcd3b4 TI |
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]; | |
8dd48678 | 119 | unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */ |
130e5f06 | 120 | bool active; |
30dcd3b4 TI |
121 | }; |
122 | ||
1da177e4 | 123 | struct alc_spec { |
23d30f28 TI |
124 | struct hda_gen_spec gen; |
125 | ||
1da177e4 | 126 | /* codec parameterization */ |
a9111321 | 127 | const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ |
1da177e4 | 128 | unsigned int num_mixers; |
45bdd1c1 | 129 | unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ |
1da177e4 | 130 | |
aa563af7 | 131 | char stream_name_analog[32]; /* analog PCM stream */ |
a9111321 TI |
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; | |
1da177e4 | 136 | |
aa563af7 | 137 | char stream_name_digital[32]; /* digital PCM stream */ |
a9111321 TI |
138 | const struct hda_pcm_stream *stream_digital_playback; |
139 | const struct hda_pcm_stream *stream_digital_capture; | |
1da177e4 LT |
140 | |
141 | /* playback */ | |
16ded525 TI |
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 | */ | |
6330079f | 146 | hda_nid_t alt_dac_nid; |
6a05ac4a | 147 | hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */ |
8c441982 | 148 | int dig_out_type; |
1da177e4 LT |
149 | |
150 | /* capture */ | |
151 | unsigned int num_adc_nids; | |
27d31536 | 152 | hda_nid_t adc_nids[AUTO_CFG_MAX_OUTS]; |
16ded525 | 153 | hda_nid_t dig_in_nid; /* digital-in NID; optional */ |
1f0f4b80 | 154 | hda_nid_t mixer_nid; /* analog-mixer NID */ |
1da177e4 | 155 | |
840b64c0 | 156 | /* capture setup for dynamic dual-adc switch */ |
840b64c0 TI |
157 | hda_nid_t cur_adc; |
158 | unsigned int cur_adc_stream_tag; | |
159 | unsigned int cur_adc_format; | |
160 | ||
1da177e4 | 161 | /* capture source */ |
27d31536 | 162 | struct hda_input_mux input_mux; |
1da177e4 | 163 | unsigned int cur_mux[3]; |
21268961 TI |
164 | hda_nid_t ext_mic_pin; |
165 | hda_nid_t dock_mic_pin; | |
166 | hda_nid_t int_mic_pin; | |
1da177e4 LT |
167 | |
168 | /* channel model */ | |
d2a6d7dc | 169 | const struct hda_channel_mode *channel_mode; |
1da177e4 | 170 | int num_channel_mode; |
b6adb57d TI |
171 | int const_channel_count; /* min. channel count (for speakers) */ |
172 | int ext_channel_count; /* current channel count for multi-io */ | |
1da177e4 LT |
173 | |
174 | /* PCM information */ | |
4c5186ed | 175 | struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */ |
41e41f1f | 176 | |
e9edcee0 TI |
177 | /* dynamic controls, init_verbs and input_mux */ |
178 | struct auto_pin_cfg autocfg; | |
da00c244 | 179 | struct alc_customize_define cdefine; |
603c4019 | 180 | struct snd_array kctls; |
41923e44 | 181 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
21268961 TI |
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 */ | |
125821ae | 185 | hda_nid_t inv_dmic_pin; |
37c04207 | 186 | hda_nid_t shared_mic_vref_pin; |
81fede89 | 187 | int inv_dmic_split_idx; /* used internally for inv_dmic_split */ |
834be88d | 188 | |
463419de TI |
189 | /* DAC list */ |
190 | int num_all_dacs; | |
191 | hda_nid_t all_dacs[16]; | |
192 | ||
c9967f1c TI |
193 | /* path list */ |
194 | struct snd_array paths; | |
c2fd19c2 | 195 | |
ae6b813a TI |
196 | /* hooks */ |
197 | void (*init_hook)(struct hda_codec *codec); | |
83012a7c | 198 | #ifdef CONFIG_PM |
c97259df | 199 | void (*power_hook)(struct hda_codec *codec); |
f5de24b0 | 200 | #endif |
1c716153 | 201 | void (*shutup)(struct hda_codec *codec); |
24519911 | 202 | void (*automute_hook)(struct hda_codec *codec); |
ae6b813a | 203 | |
834be88d | 204 | /* for pin sensing */ |
42cf0d01 | 205 | unsigned int hp_jack_present:1; |
e6a5e1b7 | 206 | unsigned int line_jack_present:1; |
e9427969 | 207 | unsigned int master_mute:1; |
6c819492 | 208 | unsigned int auto_mic:1; |
42cf0d01 DH |
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 */ | |
31150f23 | 215 | unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */ |
cb53c626 | 216 | |
e64f14f4 | 217 | /* other flags */ |
20c18f56 | 218 | unsigned int need_dac_fix:1; /* need to limit DACs for multi channels */ |
e64f14f4 | 219 | unsigned int no_analog :1; /* digital I/O only */ |
21268961 | 220 | unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */ |
24de183e | 221 | unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */ |
125821ae TI |
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? */ | |
e427c237 | 224 | unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */ |
9bf387b6 | 225 | unsigned int multi_cap_vol:1; /* allow multiple capture xxx volumes */ |
81fede89 | 226 | unsigned int inv_dmic_split:1; /* inverted dmic w/a for conexant */ |
d922b51d | 227 | |
20c18f56 | 228 | unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */ |
d922b51d | 229 | |
4a79ba34 | 230 | int init_amp; |
d433a678 | 231 | int codec_variant; /* flag for other variants */ |
e64f14f4 | 232 | |
2134ea4f TI |
233 | /* for virtual master */ |
234 | hda_nid_t vmaster_nid; | |
d2f344b5 | 235 | struct hda_vmaster_mute_hook vmaster_mute; |
83012a7c | 236 | #ifdef CONFIG_PM |
cb53c626 | 237 | struct hda_loopback_check loopback; |
164f73ee TI |
238 | int num_loopbacks; |
239 | struct hda_amp_list loopback_list[8]; | |
cb53c626 | 240 | #endif |
2c3bf9ab TI |
241 | |
242 | /* for PLL fix */ | |
243 | hda_nid_t pll_nid; | |
244 | unsigned int pll_coef_idx, pll_coef_bit; | |
1bb7e43e | 245 | unsigned int coef0; |
b5bfbc67 | 246 | |
ce764ab2 TI |
247 | /* multi-io */ |
248 | int multi_ios; | |
249 | struct alc_multi_io multi_io[4]; | |
23c09b00 TI |
250 | |
251 | /* bind volumes */ | |
252 | struct snd_array bind_ctls; | |
df694daa KY |
253 | }; |
254 | ||
44c02400 TI |
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 | ||
666a70d4 TI |
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 | ||
1da177e4 LT |
276 | /* |
277 | * input MUX handling | |
278 | */ | |
9c7f852e TI |
279 | static int alc_mux_enum_info(struct snd_kcontrol *kcontrol, |
280 | struct snd_ctl_elem_info *uinfo) | |
1da177e4 LT |
281 | { |
282 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
283 | struct alc_spec *spec = codec->spec; | |
27d31536 | 284 | return snd_hda_input_mux_info(&spec->input_mux, uinfo); |
1da177e4 LT |
285 | } |
286 | ||
9c7f852e TI |
287 | static int alc_mux_enum_get(struct snd_kcontrol *kcontrol, |
288 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 LT |
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 | ||
666a70d4 TI |
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 | ||
21268961 TI |
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 | ||
24de183e | 323 | static void call_update_outputs(struct hda_codec *codec); |
125821ae | 324 | static void alc_inv_dmic_sync(struct hda_codec *codec, bool force); |
666a70d4 | 325 | static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx); |
24de183e | 326 | |
00227f15 DH |
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 */ | |
37c04207 TI |
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)); | |
00227f15 DH |
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 | } | |
24de183e | 354 | |
21268961 TI |
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) | |
1da177e4 | 358 | { |
1da177e4 | 359 | struct alc_spec *spec = codec->spec; |
cd896c33 | 360 | const struct hda_input_mux *imux; |
666a70d4 | 361 | struct nid_path *path; |
5803a326 | 362 | |
27d31536 TI |
363 | imux = &spec->input_mux; |
364 | if (!imux->num_items) | |
cce4aa37 | 365 | return 0; |
cd896c33 | 366 | |
21268961 TI |
367 | if (idx >= imux->num_items) |
368 | idx = imux->num_items - 1; | |
369 | if (spec->cur_mux[adc_idx] == idx && !force) | |
370 | return 0; | |
666a70d4 TI |
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 | ||
21268961 TI |
379 | spec->cur_mux[adc_idx] = idx; |
380 | ||
00227f15 DH |
381 | if (spec->shared_mic_hp) |
382 | update_shared_mic_hp(codec, spec->cur_mux[adc_idx]); | |
24de183e | 383 | |
666a70d4 | 384 | if (spec->dyn_adc_switch) |
21268961 | 385 | alc_dyn_adc_pcm_resetup(codec, idx); |
21268961 | 386 | |
666a70d4 TI |
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); | |
125821ae | 394 | alc_inv_dmic_sync(codec, true); |
21268961 TI |
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); | |
54cbc9ab | 405 | } |
e9edcee0 | 406 | |
23f0c048 TI |
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; | |
4740860b TI |
414 | if (auto_pin_type == AUTO_PIN_MIC) |
415 | val |= snd_hda_get_default_vref(codec, nid); | |
cdd03ced | 416 | snd_hda_set_pin_ctl(codec, nid, val); |
23f0c048 TI |
417 | } |
418 | ||
d88897ea | 419 | /* |
1d045db9 TI |
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(). | |
d88897ea | 423 | */ |
a9111321 | 424 | static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix) |
d88897ea TI |
425 | { |
426 | if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers))) | |
427 | return; | |
428 | spec->mixers[spec->num_mixers++] = mix; | |
429 | } | |
430 | ||
df694daa | 431 | /* |
1d045db9 | 432 | * GPIO setup tables, used in initialization |
df694daa | 433 | */ |
bc9f98a9 | 434 | /* Enable GPIO mask and set output */ |
a9111321 | 435 | static const struct hda_verb alc_gpio1_init_verbs[] = { |
bc9f98a9 KY |
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 | ||
a9111321 | 442 | static const struct hda_verb alc_gpio2_init_verbs[] = { |
bc9f98a9 KY |
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 | ||
a9111321 | 449 | static const struct hda_verb alc_gpio3_init_verbs[] = { |
bdd148a3 KY |
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 | ||
2c3bf9ab TI |
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 | ||
1d045db9 TI |
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) | |
c9b58006 | 494 | { |
e6a5e1b7 | 495 | int i, present = 0; |
c9b58006 | 496 | |
e6a5e1b7 TI |
497 | for (i = 0; i < num_pins; i++) { |
498 | hda_nid_t nid = pins[i]; | |
bb35febd TI |
499 | if (!nid) |
500 | break; | |
e6a5e1b7 | 501 | present |= snd_hda_jack_detect(codec, nid); |
bb35febd | 502 | } |
e6a5e1b7 TI |
503 | return present; |
504 | } | |
bb35febd | 505 | |
1d045db9 | 506 | /* standard HP/line-out auto-mute helper */ |
e6a5e1b7 | 507 | static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins, |
e9427969 | 508 | bool mute, bool hp_out) |
e6a5e1b7 TI |
509 | { |
510 | struct alc_spec *spec = codec->spec; | |
e9427969 | 511 | unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT); |
e6a5e1b7 TI |
512 | int i; |
513 | ||
514 | for (i = 0; i < num_pins; i++) { | |
515 | hda_nid_t nid = pins[i]; | |
31150f23 | 516 | unsigned int val; |
a9fd4f3f TI |
517 | if (!nid) |
518 | break; | |
b8a47c79 TI |
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, | |
31150f23 | 524 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
b8a47c79 TI |
525 | val &= ~PIN_HP; |
526 | } else | |
527 | val = 0; | |
528 | val |= pin_bits; | |
529 | snd_hda_set_pin_ctl(codec, nid, val); | |
a9fd4f3f | 530 | } |
c9b58006 KY |
531 | } |
532 | ||
42cf0d01 DH |
533 | /* Toggle outputs muting */ |
534 | static void update_outputs(struct hda_codec *codec) | |
e6a5e1b7 TI |
535 | { |
536 | struct alc_spec *spec = codec->spec; | |
1a1455de | 537 | int on; |
e6a5e1b7 | 538 | |
c0a20263 TI |
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 | */ | |
24de183e TI |
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), | |
c0a20263 TI |
545 | spec->autocfg.hp_pins, spec->master_mute, true); |
546 | ||
42cf0d01 | 547 | if (!spec->automute_speaker) |
1a1455de TI |
548 | on = 0; |
549 | else | |
42cf0d01 | 550 | on = spec->hp_jack_present | spec->line_jack_present; |
1a1455de | 551 | on |= spec->master_mute; |
e6a5e1b7 | 552 | do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins), |
1a1455de | 553 | spec->autocfg.speaker_pins, on, false); |
e6a5e1b7 TI |
554 | |
555 | /* toggle line-out mutes if needed, too */ | |
1a1455de TI |
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]) | |
e6a5e1b7 | 559 | return; |
42cf0d01 | 560 | if (!spec->automute_lo) |
1a1455de TI |
561 | on = 0; |
562 | else | |
42cf0d01 | 563 | on = spec->hp_jack_present; |
1a1455de | 564 | on |= spec->master_mute; |
e6a5e1b7 | 565 | do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
1a1455de | 566 | spec->autocfg.line_out_pins, on, false); |
e6a5e1b7 TI |
567 | } |
568 | ||
42cf0d01 | 569 | static void call_update_outputs(struct hda_codec *codec) |
24519911 TI |
570 | { |
571 | struct alc_spec *spec = codec->spec; | |
572 | if (spec->automute_hook) | |
573 | spec->automute_hook(codec); | |
574 | else | |
42cf0d01 | 575 | update_outputs(codec); |
24519911 TI |
576 | } |
577 | ||
1d045db9 | 578 | /* standard HP-automute helper */ |
29adc4b9 | 579 | static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack) |
e6a5e1b7 TI |
580 | { |
581 | struct alc_spec *spec = codec->spec; | |
582 | ||
42cf0d01 | 583 | spec->hp_jack_present = |
e6a5e1b7 TI |
584 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins), |
585 | spec->autocfg.hp_pins); | |
42cf0d01 | 586 | if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo)) |
3c715a98 | 587 | return; |
42cf0d01 | 588 | call_update_outputs(codec); |
e6a5e1b7 TI |
589 | } |
590 | ||
1d045db9 | 591 | /* standard line-out-automute helper */ |
29adc4b9 | 592 | static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack) |
e6a5e1b7 TI |
593 | { |
594 | struct alc_spec *spec = codec->spec; | |
595 | ||
f7f4b232 DH |
596 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) |
597 | return; | |
e0d32e33 TI |
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 | ||
e6a5e1b7 TI |
602 | spec->line_jack_present = |
603 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), | |
604 | spec->autocfg.line_out_pins); | |
42cf0d01 | 605 | if (!spec->automute_speaker || !spec->detect_lo) |
3c715a98 | 606 | return; |
42cf0d01 | 607 | call_update_outputs(codec); |
e6a5e1b7 TI |
608 | } |
609 | ||
1d045db9 | 610 | /* standard mic auto-switch helper */ |
29adc4b9 | 611 | static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack) |
7fb0d78f KY |
612 | { |
613 | struct alc_spec *spec = codec->spec; | |
21268961 | 614 | hda_nid_t *pins = spec->imux_pins; |
6c819492 | 615 | |
480967db | 616 | if (!spec->auto_mic) |
6c819492 | 617 | return; |
21268961 | 618 | if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0)) |
840b64c0 | 619 | return; |
6c819492 | 620 | |
21268961 TI |
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); | |
7fb0d78f KY |
628 | } |
629 | ||
cf5a2279 | 630 | /* update the master volume per volume-knob's unsol event */ |
29adc4b9 | 631 | static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack) |
cf5a2279 TI |
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; | |
29adc4b9 | 643 | val = snd_hda_codec_read(codec, jack->nid, 0, |
cf5a2279 TI |
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 | ||
29adc4b9 | 652 | static void alc880_unsol_event(struct hda_codec *codec, unsigned int res) |
f21d78e2 | 653 | { |
29adc4b9 DH |
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); | |
f21d78e2 TI |
657 | } |
658 | ||
f9423e7a KY |
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); | |
37db623a | 667 | if ((tmp & 0xf0) == 0x20) |
f9423e7a KY |
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 | ||
1d045db9 | 677 | /* additional initialization for ALC889 variants */ |
87a8c370 JK |
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 | ||
3fb4a508 TI |
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 | ||
691f1fcc TI |
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 */ | |
39fa84e9 TI |
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); | |
691f1fcc TI |
708 | } |
709 | ||
1c716153 TI |
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 | ||
1d045db9 | 719 | /* generic EAPD initialization */ |
4a79ba34 | 720 | static void alc_auto_init_amp(struct hda_codec *codec, int type) |
bc9f98a9 | 721 | { |
4a79ba34 | 722 | unsigned int tmp; |
bc9f98a9 | 723 | |
39fa84e9 | 724 | alc_auto_setup_eapd(codec, true); |
4a79ba34 TI |
725 | switch (type) { |
726 | case ALC_INIT_GPIO1: | |
bc9f98a9 KY |
727 | snd_hda_sequence_write(codec, alc_gpio1_init_verbs); |
728 | break; | |
4a79ba34 | 729 | case ALC_INIT_GPIO2: |
bc9f98a9 KY |
730 | snd_hda_sequence_write(codec, alc_gpio2_init_verbs); |
731 | break; | |
4a79ba34 | 732 | case ALC_INIT_GPIO3: |
bdd148a3 KY |
733 | snd_hda_sequence_write(codec, alc_gpio3_init_verbs); |
734 | break; | |
4a79ba34 | 735 | case ALC_INIT_DEFAULT: |
c9b58006 KY |
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: | |
4a5a4c56 | 753 | case 0x10ec0887: |
20b67ddd | 754 | /*case 0x10ec0889:*/ /* this causes an SPDIF problem */ |
87a8c370 | 755 | alc889_coef_init(codec); |
c9b58006 | 756 | break; |
f9423e7a | 757 | case 0x10ec0888: |
4a79ba34 | 758 | alc888_coef_init(codec); |
f9423e7a | 759 | break; |
0aea778e | 760 | #if 0 /* XXX: This may cause the silent output on speaker on some machines */ |
c9b58006 KY |
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, | |
ea1fb29a | 768 | AC_VERB_SET_COEF_INDEX, 7); |
c9b58006 KY |
769 | snd_hda_codec_write(codec, 0x20, 0, |
770 | AC_VERB_SET_PROC_COEF, | |
771 | tmp | 0x3000); | |
772 | break; | |
0aea778e | 773 | #endif /* XXX */ |
bc9f98a9 | 774 | } |
4a79ba34 TI |
775 | break; |
776 | } | |
777 | } | |
778 | ||
1d045db9 TI |
779 | /* |
780 | * Auto-Mute mode mixer enum support | |
781 | */ | |
1a1455de TI |
782 | static int alc_automute_mode_info(struct snd_kcontrol *kcontrol, |
783 | struct snd_ctl_elem_info *uinfo) | |
784 | { | |
ae8a60a5 TI |
785 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
786 | struct alc_spec *spec = codec->spec; | |
ae8a60a5 | 787 | static const char * const texts3[] = { |
e49a3434 | 788 | "Disabled", "Speaker Only", "Line Out+Speaker" |
1a1455de TI |
789 | }; |
790 | ||
dda415d4 TI |
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); | |
1a1455de TI |
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; | |
42cf0d01 DH |
801 | unsigned int val = 0; |
802 | if (spec->automute_speaker) | |
803 | val++; | |
804 | if (spec->automute_lo) | |
805 | val++; | |
806 | ||
1a1455de TI |
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: | |
42cf0d01 | 819 | if (!spec->automute_speaker && !spec->automute_lo) |
1a1455de | 820 | return 0; |
42cf0d01 DH |
821 | spec->automute_speaker = 0; |
822 | spec->automute_lo = 0; | |
1a1455de TI |
823 | break; |
824 | case 1: | |
42cf0d01 DH |
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; | |
1a1455de TI |
836 | break; |
837 | case 2: | |
42cf0d01 | 838 | if (!spec->automute_lo_possible || !spec->automute_speaker_possible) |
ae8a60a5 | 839 | return -EINVAL; |
42cf0d01 | 840 | if (spec->automute_speaker && spec->automute_lo) |
1a1455de | 841 | return 0; |
42cf0d01 DH |
842 | spec->automute_speaker = 1; |
843 | spec->automute_lo = 1; | |
1a1455de TI |
844 | break; |
845 | default: | |
846 | return -EINVAL; | |
847 | } | |
42cf0d01 | 848 | call_update_outputs(codec); |
1a1455de TI |
849 | return 1; |
850 | } | |
851 | ||
a9111321 | 852 | static const struct snd_kcontrol_new alc_automute_mode_enum = { |
1a1455de TI |
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 | ||
668d1e96 TI |
860 | static struct snd_kcontrol_new * |
861 | alc_kcontrol_new(struct alc_spec *spec, const char *name, | |
862 | const struct snd_kcontrol_new *temp) | |
1d045db9 | 863 | { |
668d1e96 TI |
864 | struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls); |
865 | if (!knew) | |
866 | return NULL; | |
867 | *knew = *temp; | |
bc549767 TI |
868 | if (name) |
869 | knew->name = kstrdup(name, GFP_KERNEL); | |
870 | else if (knew->name) | |
871 | knew->name = kstrdup(knew->name, GFP_KERNEL); | |
668d1e96 TI |
872 | if (!knew->name) |
873 | return NULL; | |
874 | return knew; | |
1d045db9 | 875 | } |
1a1455de TI |
876 | |
877 | static int alc_add_automute_mode_enum(struct hda_codec *codec) | |
878 | { | |
879 | struct alc_spec *spec = codec->spec; | |
1a1455de | 880 | |
bc549767 | 881 | if (!alc_kcontrol_new(spec, NULL, &alc_automute_mode_enum)) |
1a1455de TI |
882 | return -ENOMEM; |
883 | return 0; | |
884 | } | |
885 | ||
1d045db9 TI |
886 | /* |
887 | * Check the availability of HP/line-out auto-mute; | |
888 | * Set up appropriately if really supported | |
889 | */ | |
475c3d21 | 890 | static int alc_init_automute(struct hda_codec *codec) |
4a79ba34 TI |
891 | { |
892 | struct alc_spec *spec = codec->spec; | |
bb35febd | 893 | struct auto_pin_cfg *cfg = &spec->autocfg; |
1daf5f46 | 894 | int present = 0; |
475c3d21 | 895 | int i, err; |
4a79ba34 | 896 | |
1daf5f46 TI |
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 */ | |
475c3d21 | 904 | return 0; |
4a79ba34 | 905 | |
c48a8fb0 TI |
906 | if (!cfg->speaker_pins[0] && |
907 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { | |
bb35febd TI |
908 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
909 | sizeof(cfg->speaker_pins)); | |
910 | cfg->speaker_outs = cfg->line_outs; | |
911 | } | |
912 | ||
c48a8fb0 TI |
913 | if (!cfg->hp_pins[0] && |
914 | cfg->line_out_type == AUTO_PIN_HP_OUT) { | |
bb35febd TI |
915 | memcpy(cfg->hp_pins, cfg->line_out_pins, |
916 | sizeof(cfg->hp_pins)); | |
917 | cfg->hp_outs = cfg->line_outs; | |
4a79ba34 TI |
918 | } |
919 | ||
bb35febd | 920 | for (i = 0; i < cfg->hp_outs; i++) { |
1a1455de | 921 | hda_nid_t nid = cfg->hp_pins[i]; |
06dec228 | 922 | if (!is_jack_detectable(codec, nid)) |
1a1455de | 923 | continue; |
bb35febd | 924 | snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n", |
1a1455de | 925 | nid); |
29adc4b9 DH |
926 | snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT, |
927 | alc_hp_automute); | |
42cf0d01 DH |
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); | |
29adc4b9 DH |
939 | snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT, |
940 | alc_line_automute); | |
42cf0d01 | 941 | spec->detect_lo = 1; |
29adc4b9 | 942 | } |
42cf0d01 | 943 | spec->automute_lo_possible = spec->detect_hp; |
ae8a60a5 TI |
944 | } |
945 | ||
42cf0d01 DH |
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 | ||
475c3d21 | 952 | if (spec->automute_speaker_possible || spec->automute_lo_possible) { |
1a1455de | 953 | /* create a control for automute mode */ |
475c3d21 TI |
954 | err = alc_add_automute_mode_enum(codec); |
955 | if (err < 0) | |
956 | return err; | |
957 | } | |
958 | return 0; | |
4a79ba34 TI |
959 | } |
960 | ||
1d045db9 | 961 | /* return the position of NID in the list, or -1 if not found */ |
21268961 TI |
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 | ||
21268961 TI |
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 | ||
27d31536 | 977 | imux = &spec->input_mux; |
21268961 TI |
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); | |
666a70d4 | 984 | if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) |
21268961 | 985 | return false; /* no corresponding imux */ |
21268961 | 986 | |
29adc4b9 DH |
987 | snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin, |
988 | ALC_MIC_EVENT, alc_mic_automute); | |
21268961 | 989 | if (spec->dock_mic_pin) |
29adc4b9 DH |
990 | snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin, |
991 | ALC_MIC_EVENT, | |
992 | alc_mic_automute); | |
21268961 TI |
993 | return true; |
994 | } | |
995 | ||
1d045db9 TI |
996 | /* |
997 | * Check the availability of auto-mic switch; | |
998 | * Set up if really supported | |
999 | */ | |
475c3d21 | 1000 | static int alc_init_auto_mic(struct hda_codec *codec) |
6c819492 TI |
1001 | { |
1002 | struct alc_spec *spec = codec->spec; | |
1003 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
8ed99d97 | 1004 | hda_nid_t fixed, ext, dock; |
6c819492 TI |
1005 | int i; |
1006 | ||
21268961 TI |
1007 | spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1; |
1008 | ||
8ed99d97 | 1009 | fixed = ext = dock = 0; |
66ceeb6b TI |
1010 | for (i = 0; i < cfg->num_inputs; i++) { |
1011 | hda_nid_t nid = cfg->inputs[i].pin; | |
6c819492 | 1012 | unsigned int defcfg; |
6c819492 | 1013 | defcfg = snd_hda_codec_get_pincfg(codec, nid); |
99ae28be TI |
1014 | switch (snd_hda_get_input_pin_attr(defcfg)) { |
1015 | case INPUT_PIN_ATTR_INT: | |
6c819492 | 1016 | if (fixed) |
475c3d21 | 1017 | return 0; /* already occupied */ |
8ed99d97 | 1018 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
475c3d21 | 1019 | return 0; /* invalid type */ |
6c819492 TI |
1020 | fixed = nid; |
1021 | break; | |
99ae28be | 1022 | case INPUT_PIN_ATTR_UNUSED: |
475c3d21 | 1023 | return 0; /* invalid entry */ |
8ed99d97 TI |
1024 | case INPUT_PIN_ATTR_DOCK: |
1025 | if (dock) | |
475c3d21 | 1026 | return 0; /* already occupied */ |
8ed99d97 | 1027 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) |
475c3d21 | 1028 | return 0; /* invalid type */ |
8ed99d97 TI |
1029 | dock = nid; |
1030 | break; | |
99ae28be | 1031 | default: |
6c819492 | 1032 | if (ext) |
475c3d21 | 1033 | return 0; /* already occupied */ |
8ed99d97 | 1034 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
475c3d21 | 1035 | return 0; /* invalid type */ |
6c819492 TI |
1036 | ext = nid; |
1037 | break; | |
6c819492 TI |
1038 | } |
1039 | } | |
8ed99d97 TI |
1040 | if (!ext && dock) { |
1041 | ext = dock; | |
1042 | dock = 0; | |
1043 | } | |
eaa9b3a7 | 1044 | if (!ext || !fixed) |
475c3d21 | 1045 | return 0; |
e35d9d6a | 1046 | if (!is_jack_detectable(codec, ext)) |
475c3d21 | 1047 | return 0; /* no unsol support */ |
8ed99d97 | 1048 | if (dock && !is_jack_detectable(codec, dock)) |
475c3d21 | 1049 | return 0; /* no unsol support */ |
21268961 TI |
1050 | |
1051 | /* check imux indices */ | |
1052 | spec->ext_mic_pin = ext; | |
1053 | spec->int_mic_pin = fixed; | |
1054 | spec->dock_mic_pin = dock; | |
1055 | ||
21268961 | 1056 | if (!alc_auto_mic_check_imux(codec)) |
475c3d21 | 1057 | return 0; |
21268961 | 1058 | |
666a70d4 TI |
1059 | spec->auto_mic = 1; |
1060 | spec->num_adc_nids = 1; | |
1061 | spec->cur_mux[0] = spec->int_mic_idx; | |
8ed99d97 TI |
1062 | snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n", |
1063 | ext, fixed, dock); | |
475c3d21 TI |
1064 | |
1065 | return 0; | |
6c819492 TI |
1066 | } |
1067 | ||
1d045db9 TI |
1068 | /* |
1069 | * Realtek SSID verification | |
1070 | */ | |
1071 | ||
90622917 DH |
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 | ||
23d30f28 TI |
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 | ||
da00c244 KY |
1087 | static int alc_auto_parse_customize_define(struct hda_codec *codec) |
1088 | { | |
1089 | unsigned int ass, tmp, i; | |
7fb56223 | 1090 | unsigned nid = 0; |
da00c244 KY |
1091 | struct alc_spec *spec = codec->spec; |
1092 | ||
b6cbe517 TI |
1093 | spec->cdefine.enable_pcbeep = 1; /* assume always enabled */ |
1094 | ||
90622917 DH |
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 | ||
da00c244 | 1102 | ass = codec->subsystem_id & 0xffff; |
b6cbe517 | 1103 | if (ass != codec->bus->pci->subsystem_device && (ass & 1)) |
da00c244 KY |
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 | ||
1d045db9 | 1152 | /* return true if the given NID is found in the list */ |
3af9ee6b TI |
1153 | static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
1154 | { | |
21268961 | 1155 | return find_idx_in_nid_list(nid, list, nums) >= 0; |
3af9ee6b TI |
1156 | } |
1157 | ||
4a79ba34 TI |
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, | |
6227cdce | 1169 | hda_nid_t portd, hda_nid_t porti) |
4a79ba34 TI |
1170 | { |
1171 | unsigned int ass, tmp, i; | |
1172 | unsigned nid; | |
1173 | struct alc_spec *spec = codec->spec; | |
1174 | ||
90622917 DH |
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 | ||
4a79ba34 TI |
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 | /* | |
def319f9 | 1188 | * 31~30 : port connectivity |
4a79ba34 TI |
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", | |
cb6605c1 | 1201 | ass, nid); |
6227cdce | 1202 | if (!(ass & 1)) |
4a79ba34 TI |
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: | |
5a8cfb4e | 1237 | default: |
4a79ba34 | 1238 | spec->init_amp = ALC_INIT_DEFAULT; |
bc9f98a9 KY |
1239 | break; |
1240 | } | |
ea1fb29a | 1241 | |
8c427226 | 1242 | /* is laptop or Desktop and enable the function "Mute internal speaker |
c9b58006 KY |
1243 | * when the external headphone out jack is plugged" |
1244 | */ | |
8c427226 | 1245 | if (!(ass & 0x8000)) |
4a79ba34 | 1246 | return 1; |
c9b58006 KY |
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 | */ | |
5fe6e015 TI |
1254 | if (!spec->autocfg.hp_pins[0] && |
1255 | !(spec->autocfg.line_out_pins[0] && | |
1256 | spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) { | |
01d4825d | 1257 | hda_nid_t nid; |
c9b58006 KY |
1258 | tmp = (ass >> 11) & 0x3; /* HP to chassis */ |
1259 | if (tmp == 0) | |
01d4825d | 1260 | nid = porta; |
c9b58006 | 1261 | else if (tmp == 1) |
01d4825d | 1262 | nid = porte; |
c9b58006 | 1263 | else if (tmp == 2) |
01d4825d | 1264 | nid = portd; |
6227cdce KY |
1265 | else if (tmp == 3) |
1266 | nid = porti; | |
c9b58006 | 1267 | else |
4a79ba34 | 1268 | return 1; |
3af9ee6b TI |
1269 | if (found_in_nid_list(nid, spec->autocfg.line_out_pins, |
1270 | spec->autocfg.line_outs)) | |
1271 | return 1; | |
01d4825d | 1272 | spec->autocfg.hp_pins[0] = nid; |
c9b58006 | 1273 | } |
4a79ba34 TI |
1274 | return 1; |
1275 | } | |
ea1fb29a | 1276 | |
3e6179b8 TI |
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) | |
4a79ba34 | 1280 | { |
3e6179b8 | 1281 | if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) { |
4a79ba34 TI |
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; | |
4a79ba34 | 1286 | } |
21268961 | 1287 | } |
1a1455de | 1288 | |
1d045db9 TI |
1289 | /* |
1290 | * COEF access helper functions | |
1291 | */ | |
274693f3 KY |
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 | ||
977ddd6b KY |
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 | ||
1bb7e43e TI |
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 | ||
fef7fbbc TI |
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); | |
965ccebc TI |
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); | |
fef7fbbc | 1332 | |
1d045db9 TI |
1333 | /* |
1334 | * Digital I/O handling | |
1335 | */ | |
1336 | ||
757899ac TI |
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; | |
fef7fbbc | 1342 | hda_nid_t pin; |
757899ac TI |
1343 | |
1344 | for (i = 0; i < spec->autocfg.dig_outs; i++) { | |
1345 | pin = spec->autocfg.dig_out_pins[i]; | |
1f0f4b80 TI |
1346 | if (!pin) |
1347 | continue; | |
fef7fbbc | 1348 | alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0); |
757899ac TI |
1349 | } |
1350 | pin = spec->autocfg.dig_in_pin; | |
1351 | if (pin) | |
cdd03ced | 1352 | snd_hda_set_pin_ctl(codec, pin, PIN_IN); |
757899ac TI |
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; | |
965ccebc | 1359 | int i, nums; |
757899ac TI |
1360 | hda_nid_t dig_nid; |
1361 | ||
1362 | /* support multiple SPDIFs; the secondary is set up as a slave */ | |
51e4152a | 1363 | nums = 0; |
757899ac | 1364 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
fef7fbbc TI |
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) | |
757899ac | 1368 | continue; |
965ccebc TI |
1369 | if (!add_new_nid_path(codec, dig_nid, pin, 2)) |
1370 | continue; | |
51e4152a | 1371 | if (!nums) { |
757899ac TI |
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; | |
51e4152a | 1376 | if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1) |
757899ac | 1377 | break; |
51e4152a | 1378 | spec->slave_dig_outs[nums - 1] = dig_nid; |
757899ac | 1379 | } |
51e4152a | 1380 | nums++; |
757899ac TI |
1381 | } |
1382 | ||
1383 | if (spec->autocfg.dig_in_pin) { | |
01fdf180 TI |
1384 | dig_nid = codec->start_nid; |
1385 | for (i = 0; i < codec->num_nodes; i++, dig_nid++) { | |
df1d1fb0 | 1386 | struct nid_path *path; |
01fdf180 TI |
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; | |
df1d1fb0 TI |
1392 | path = add_new_nid_path(codec, spec->autocfg.dig_in_pin, |
1393 | dig_nid, 2); | |
1394 | if (path) { | |
1395 | path->active = true; | |
01fdf180 TI |
1396 | spec->dig_in_nid = dig_nid; |
1397 | break; | |
1398 | } | |
1399 | } | |
757899ac TI |
1400 | } |
1401 | } | |
1402 | ||
ef8ef5fb | 1403 | /* |
1d045db9 | 1404 | * capture mixer elements |
ef8ef5fb | 1405 | */ |
666a70d4 TI |
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 | |
f9e336f6 | 1409 | |
666a70d4 TI |
1410 | typedef int (*put_call_t)(struct snd_kcontrol *kcontrol, |
1411 | struct snd_ctl_elem_value *ucontrol); | |
f9e336f6 | 1412 | |
666a70d4 TI |
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) | |
f9e336f6 TI |
1416 | { |
1417 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1418 | struct alc_spec *spec = codec->spec; | |
666a70d4 TI |
1419 | const struct hda_input_mux *imux; |
1420 | struct nid_path *path; | |
1421 | int i, adc_idx, err = 0; | |
f9e336f6 | 1422 | |
27d31536 | 1423 | imux = &spec->input_mux; |
666a70d4 | 1424 | adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
5a9e02e9 | 1425 | mutex_lock(&codec->control_mutex); |
666a70d4 TI |
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]; | |
9c7a083d | 1433 | err = func(kcontrol, ucontrol); |
666a70d4 TI |
1434 | if (err < 0) |
1435 | goto error; | |
9c7a083d TI |
1436 | } |
1437 | error: | |
666a70d4 | 1438 | codec->cached_write = 0; |
5a9e02e9 | 1439 | mutex_unlock(&codec->control_mutex); |
666a70d4 TI |
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); | |
f9e336f6 TI |
1444 | return err; |
1445 | } | |
1446 | ||
f9e336f6 TI |
1447 | static int alc_cap_vol_put(struct snd_kcontrol *kcontrol, |
1448 | struct snd_ctl_elem_value *ucontrol) | |
1449 | { | |
666a70d4 TI |
1450 | return alc_cap_put_caller(kcontrol, ucontrol, |
1451 | snd_hda_mixer_amp_volume_put, | |
1452 | NID_PATH_VOL_CTL); | |
f9e336f6 TI |
1453 | } |
1454 | ||
1455 | /* capture mixer elements */ | |
1456 | #define alc_cap_sw_info snd_ctl_boolean_stereo_info | |
666a70d4 | 1457 | #define alc_cap_sw_get snd_hda_mixer_amp_switch_get |
f9e336f6 | 1458 | |
666a70d4 | 1459 | static int alc_cap_sw_put(struct snd_kcontrol *kcontrol, |
f9e336f6 TI |
1460 | struct snd_ctl_elem_value *ucontrol) |
1461 | { | |
666a70d4 TI |
1462 | return alc_cap_put_caller(kcontrol, ucontrol, |
1463 | snd_hda_mixer_amp_switch_put, | |
1464 | NID_PATH_MUTE_CTL); | |
f9e336f6 TI |
1465 | } |
1466 | ||
666a70d4 | 1467 | static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx) |
f9e336f6 | 1468 | { |
666a70d4 | 1469 | struct alc_spec *spec = codec->spec; |
27d31536 | 1470 | struct hda_input_mux *imux = &spec->input_mux; |
666a70d4 TI |
1471 | struct nid_path *path; |
1472 | hda_nid_t nid; | |
1473 | int i, dir, parm; | |
1474 | unsigned int val; | |
a23b688f | 1475 | |
666a70d4 TI |
1476 | for (i = 0; i < imux->num_items; i++) { |
1477 | if (spec->imux_pins[i] == spec->inv_dmic_pin) | |
1478 | break; | |
a23b688f | 1479 | } |
666a70d4 TI |
1480 | if (i >= imux->num_items) |
1481 | return; | |
a23b688f | 1482 | |
666a70d4 TI |
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); | |
f9e336f6 TI |
1500 | } |
1501 | ||
125821ae TI |
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; | |
666a70d4 | 1520 | int src, nums; |
125821ae TI |
1521 | |
1522 | if (!spec->inv_dmic_fixup) | |
1523 | return; | |
1524 | if (!spec->inv_dmic_muted && !force) | |
1525 | return; | |
666a70d4 TI |
1526 | nums = spec->dyn_adc_switch ? 1 : spec->num_adc_nids; |
1527 | for (src = 0; src < nums; src++) { | |
125821ae | 1528 | bool dmic_fixup = false; |
125821ae TI |
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; | |
666a70d4 | 1535 | alc_inv_dmic_sync_adc(codec, src); |
125821ae TI |
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, | |
bc549767 | 1565 | .name = "Inverted Internal Mic Capture Switch", |
125821ae TI |
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; | |
668d1e96 | 1574 | |
bc549767 | 1575 | if (!alc_kcontrol_new(spec, NULL, &alc_inv_dmic_sw)) |
125821ae TI |
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 | ||
6e72aa5f TI |
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 | ||
e9edcee0 | 1591 | /* |
1d045db9 | 1592 | * virtual master controls |
e9edcee0 TI |
1593 | */ |
1594 | ||
e9edcee0 | 1595 | /* |
1d045db9 | 1596 | * slave controls for virtual master |
e9edcee0 | 1597 | */ |
9322ca54 TI |
1598 | static const char * const alc_slave_pfxs[] = { |
1599 | "Front", "Surround", "Center", "LFE", "Side", | |
7c589750 | 1600 | "Headphone", "Speaker", "Mono", "Line Out", |
9322ca54 | 1601 | "CLFE", "Bass Speaker", "PCM", |
1d045db9 | 1602 | NULL, |
16ded525 TI |
1603 | }; |
1604 | ||
e9edcee0 | 1605 | /* |
1d045db9 | 1606 | * build control elements |
e9edcee0 TI |
1607 | */ |
1608 | ||
1d045db9 | 1609 | static void alc_free_kctls(struct hda_codec *codec); |
e9edcee0 | 1610 | |
1d045db9 TI |
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), | |
16ded525 TI |
1616 | { } /* end */ |
1617 | }; | |
1d045db9 | 1618 | #endif |
16ded525 | 1619 | |
2eab694a | 1620 | static int alc_build_controls(struct hda_codec *codec) |
1d045db9 TI |
1621 | { |
1622 | struct alc_spec *spec = codec->spec; | |
666a70d4 | 1623 | int i, err; |
1da177e4 LT |
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 | } | |
1da177e4 | 1630 | if (spec->multiout.dig_out_nid) { |
dcda5806 TI |
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); | |
1da177e4 LT |
1635 | if (err < 0) |
1636 | return err; | |
e64f14f4 TI |
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 | } | |
1da177e4 LT |
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 | } | |
2134ea4f | 1650 | |
67d634c0 | 1651 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
45bdd1c1 TI |
1652 | /* create beep controls if needed */ |
1653 | if (spec->beep_amp) { | |
a9111321 | 1654 | const struct snd_kcontrol_new *knew; |
45bdd1c1 TI |
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; | |
5e26dfd0 | 1661 | err = snd_hda_ctl_add(codec, 0, kctl); |
45bdd1c1 TI |
1662 | if (err < 0) |
1663 | return err; | |
1664 | } | |
1665 | } | |
67d634c0 | 1666 | #endif |
45bdd1c1 | 1667 | |
2134ea4f | 1668 | /* if we have no master control, let's create it */ |
e64f14f4 TI |
1669 | if (!spec->no_analog && |
1670 | !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { | |
1c82ed1b | 1671 | unsigned int vmaster_tlv[4]; |
2134ea4f | 1672 | snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, |
1c82ed1b | 1673 | HDA_OUTPUT, vmaster_tlv); |
2134ea4f | 1674 | err = snd_hda_add_vmaster(codec, "Master Playback Volume", |
9322ca54 TI |
1675 | vmaster_tlv, alc_slave_pfxs, |
1676 | "Playback Volume"); | |
2134ea4f TI |
1677 | if (err < 0) |
1678 | return err; | |
1679 | } | |
e64f14f4 TI |
1680 | if (!spec->no_analog && |
1681 | !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { | |
420b0feb TI |
1682 | err = __snd_hda_add_vmaster(codec, "Master Playback Switch", |
1683 | NULL, alc_slave_pfxs, | |
1684 | "Playback Switch", | |
d2f344b5 | 1685 | true, &spec->vmaster_mute.sw_kctl); |
2134ea4f TI |
1686 | if (err < 0) |
1687 | return err; | |
3bd7b644 TI |
1688 | if (spec->vmaster_mute.hook) |
1689 | snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true); | |
2134ea4f TI |
1690 | } |
1691 | ||
bae84e70 TI |
1692 | alc_free_kctls(codec); /* no longer needed */ |
1693 | ||
5780b627 DH |
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 | ||
2eab694a | 1705 | err = snd_hda_jack_add_kctls(codec, &spec->autocfg); |
01a61e12 TI |
1706 | if (err < 0) |
1707 | return err; | |
5780b627 | 1708 | |
420b0feb TI |
1709 | alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD); |
1710 | return 0; | |
1da177e4 LT |
1711 | } |
1712 | ||
e9edcee0 | 1713 | |
1da177e4 | 1714 | /* |
1d045db9 | 1715 | * Common callbacks |
e9edcee0 | 1716 | */ |
1da177e4 | 1717 | |
070cff4c | 1718 | static void alc_auto_init_std(struct hda_codec *codec); |
1da177e4 | 1719 | |
1d045db9 TI |
1720 | static int alc_init(struct hda_codec *codec) |
1721 | { | |
1722 | struct alc_spec *spec = codec->spec; | |
1da177e4 | 1723 | |
546bb678 TI |
1724 | if (spec->init_hook) |
1725 | spec->init_hook(codec); | |
526af6eb | 1726 | |
1d045db9 TI |
1727 | alc_fix_pll(codec); |
1728 | alc_auto_init_amp(codec, spec->init_amp); | |
1da177e4 | 1729 | |
2e8b2b29 | 1730 | snd_hda_gen_apply_verbs(codec); |
070cff4c | 1731 | alc_auto_init_std(codec); |
dfc0ff62 | 1732 | |
3bd7b644 TI |
1733 | if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook) |
1734 | snd_hda_sync_vmaster_hook(&spec->vmaster_mute); | |
1735 | ||
1d045db9 | 1736 | alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT); |
16ded525 | 1737 | |
1d045db9 TI |
1738 | hda_call_check_power_status(codec, 0x01); |
1739 | return 0; | |
1740 | } | |
ea1fb29a | 1741 | |
83012a7c | 1742 | #ifdef CONFIG_PM |
1d045db9 TI |
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 | |
ccc656ce KY |
1749 | |
1750 | /* | |
1d045db9 | 1751 | * Analog playback callbacks |
ccc656ce | 1752 | */ |
1d045db9 TI |
1753 | static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo, |
1754 | struct hda_codec *codec, | |
1755 | struct snd_pcm_substream *substream) | |
458a4fab | 1756 | { |
1d045db9 TI |
1757 | struct alc_spec *spec = codec->spec; |
1758 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, | |
1759 | hinfo); | |
458a4fab TI |
1760 | } |
1761 | ||
1d045db9 TI |
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) | |
458a4fab | 1767 | { |
a9fd4f3f | 1768 | struct alc_spec *spec = codec->spec; |
1d045db9 TI |
1769 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, |
1770 | stream_tag, format, substream); | |
4f5d1706 TI |
1771 | } |
1772 | ||
1d045db9 TI |
1773 | static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
1774 | struct hda_codec *codec, | |
1775 | struct snd_pcm_substream *substream) | |
4f5d1706 | 1776 | { |
1d045db9 TI |
1777 | struct alc_spec *spec = codec->spec; |
1778 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | |
ccc656ce KY |
1779 | } |
1780 | ||
1d045db9 TI |
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) | |
ccc656ce | 1787 | { |
1d045db9 TI |
1788 | struct alc_spec *spec = codec->spec; |
1789 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | |
ccc656ce KY |
1790 | } |
1791 | ||
1d045db9 TI |
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) | |
ccc656ce | 1797 | { |
a9fd4f3f | 1798 | struct alc_spec *spec = codec->spec; |
1d045db9 TI |
1799 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
1800 | stream_tag, format, substream); | |
ccc656ce KY |
1801 | } |
1802 | ||
1d045db9 TI |
1803 | static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
1804 | struct hda_codec *codec, | |
1805 | struct snd_pcm_substream *substream) | |
ccc656ce | 1806 | { |
1d045db9 TI |
1807 | struct alc_spec *spec = codec->spec; |
1808 | return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); | |
ccc656ce | 1809 | } |
47fd830a | 1810 | |
1d045db9 TI |
1811 | static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
1812 | struct hda_codec *codec, | |
1813 | struct snd_pcm_substream *substream) | |
ccc656ce | 1814 | { |
1d045db9 TI |
1815 | struct alc_spec *spec = codec->spec; |
1816 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | |
ccc656ce KY |
1817 | } |
1818 | ||
e9edcee0 | 1819 | /* |
1d045db9 | 1820 | * Analog capture |
e9edcee0 | 1821 | */ |
1d045db9 TI |
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; | |
1da177e4 | 1829 | |
6330079f | 1830 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1], |
1da177e4 LT |
1831 | stream_tag, 0, format); |
1832 | return 0; | |
1833 | } | |
1834 | ||
c2d986b0 | 1835 | static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
1da177e4 | 1836 | struct hda_codec *codec, |
c8b6bf9b | 1837 | struct snd_pcm_substream *substream) |
1da177e4 LT |
1838 | { |
1839 | struct alc_spec *spec = codec->spec; | |
1840 | ||
888afa15 TI |
1841 | snd_hda_codec_cleanup_stream(codec, |
1842 | spec->adc_nids[substream->number + 1]); | |
1da177e4 LT |
1843 | return 0; |
1844 | } | |
1845 | ||
840b64c0 | 1846 | /* analog capture with dynamic dual-adc changes */ |
21268961 | 1847 | static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
840b64c0 TI |
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; | |
21268961 | 1854 | spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]]; |
840b64c0 TI |
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 | ||
21268961 | 1861 | static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
840b64c0 TI |
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 | ||
21268961 | 1871 | static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = { |
840b64c0 TI |
1872 | .substreams = 1, |
1873 | .channels_min = 2, | |
1874 | .channels_max = 2, | |
1875 | .nid = 0, /* fill later */ | |
1876 | .ops = { | |
21268961 TI |
1877 | .prepare = dyn_adc_capture_pcm_prepare, |
1878 | .cleanup = dyn_adc_capture_pcm_cleanup | |
840b64c0 TI |
1879 | }, |
1880 | }; | |
1da177e4 LT |
1881 | |
1882 | /* | |
1883 | */ | |
c2d986b0 | 1884 | static const struct hda_pcm_stream alc_pcm_analog_playback = { |
1da177e4 LT |
1885 | .substreams = 1, |
1886 | .channels_min = 2, | |
1887 | .channels_max = 8, | |
e9edcee0 | 1888 | /* NID is set in alc_build_pcms */ |
1da177e4 | 1889 | .ops = { |
c2d986b0 TI |
1890 | .open = alc_playback_pcm_open, |
1891 | .prepare = alc_playback_pcm_prepare, | |
1892 | .cleanup = alc_playback_pcm_cleanup | |
1da177e4 LT |
1893 | }, |
1894 | }; | |
1895 | ||
c2d986b0 | 1896 | static const struct hda_pcm_stream alc_pcm_analog_capture = { |
6330079f TI |
1897 | .substreams = 1, |
1898 | .channels_min = 2, | |
1899 | .channels_max = 2, | |
1900 | /* NID is set in alc_build_pcms */ | |
1901 | }; | |
1902 | ||
c2d986b0 | 1903 | static const struct hda_pcm_stream alc_pcm_analog_alt_playback = { |
6330079f TI |
1904 | .substreams = 1, |
1905 | .channels_min = 2, | |
1906 | .channels_max = 2, | |
1907 | /* NID is set in alc_build_pcms */ | |
1908 | }; | |
1909 | ||
c2d986b0 | 1910 | static const struct hda_pcm_stream alc_pcm_analog_alt_capture = { |
6330079f | 1911 | .substreams = 2, /* can be overridden */ |
1da177e4 LT |
1912 | .channels_min = 2, |
1913 | .channels_max = 2, | |
e9edcee0 | 1914 | /* NID is set in alc_build_pcms */ |
1da177e4 | 1915 | .ops = { |
c2d986b0 TI |
1916 | .prepare = alc_alt_capture_pcm_prepare, |
1917 | .cleanup = alc_alt_capture_pcm_cleanup | |
1da177e4 LT |
1918 | }, |
1919 | }; | |
1920 | ||
c2d986b0 | 1921 | static const struct hda_pcm_stream alc_pcm_digital_playback = { |
1da177e4 LT |
1922 | .substreams = 1, |
1923 | .channels_min = 2, | |
1924 | .channels_max = 2, | |
1925 | /* NID is set in alc_build_pcms */ | |
1926 | .ops = { | |
c2d986b0 TI |
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 | |
1da177e4 LT |
1931 | }, |
1932 | }; | |
1933 | ||
c2d986b0 | 1934 | static const struct hda_pcm_stream alc_pcm_digital_capture = { |
1da177e4 LT |
1935 | .substreams = 1, |
1936 | .channels_min = 2, | |
1937 | .channels_max = 2, | |
1938 | /* NID is set in alc_build_pcms */ | |
1939 | }; | |
1940 | ||
4c5186ed | 1941 | /* Used by alc_build_pcms to flag that a PCM has no playback stream */ |
a9111321 | 1942 | static const struct hda_pcm_stream alc_pcm_null_stream = { |
4c5186ed JW |
1943 | .substreams = 0, |
1944 | .channels_min = 0, | |
1945 | .channels_max = 0, | |
1946 | }; | |
1947 | ||
1da177e4 LT |
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; | |
c2d986b0 | 1952 | const struct hda_pcm_stream *p; |
1fa17573 | 1953 | bool have_multi_adcs; |
1da177e4 LT |
1954 | int i; |
1955 | ||
1956 | codec->num_pcms = 1; | |
1957 | codec->pcm_info = info; | |
1958 | ||
e64f14f4 TI |
1959 | if (spec->no_analog) |
1960 | goto skip_analog; | |
1961 | ||
812a2cca TI |
1962 | snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), |
1963 | "%s Analog", codec->chip_name); | |
1da177e4 | 1964 | info->name = spec->stream_name_analog; |
274693f3 | 1965 | |
eedec3d3 | 1966 | if (spec->multiout.num_dacs > 0) { |
c2d986b0 TI |
1967 | p = spec->stream_analog_playback; |
1968 | if (!p) | |
1969 | p = &alc_pcm_analog_playback; | |
1970 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | |
4a471b7d | 1971 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; |
9c9a5175 TI |
1972 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
1973 | spec->multiout.max_channels; | |
ee81abb6 TI |
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; | |
4a471b7d | 1978 | } |
27d31536 | 1979 | if (spec->num_adc_nids) { |
c2d986b0 | 1980 | p = spec->stream_analog_capture; |
21268961 TI |
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 | } | |
c2d986b0 | 1987 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
4a471b7d TI |
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 | } | |
1da177e4 LT |
1997 | } |
1998 | } | |
1999 | ||
e64f14f4 | 2000 | skip_analog: |
e08a007d | 2001 | /* SPDIF for stream index #1 */ |
1da177e4 | 2002 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
812a2cca TI |
2003 | snprintf(spec->stream_name_digital, |
2004 | sizeof(spec->stream_name_digital), | |
2005 | "%s Digital", codec->chip_name); | |
e08a007d | 2006 | codec->num_pcms = 2; |
b25c9da1 | 2007 | codec->slave_dig_outs = spec->multiout.slave_dig_outs; |
c06134d7 | 2008 | info = spec->pcm_rec + 1; |
1da177e4 | 2009 | info->name = spec->stream_name_digital; |
8c441982 TI |
2010 | if (spec->dig_out_type) |
2011 | info->pcm_type = spec->dig_out_type; | |
2012 | else | |
2013 | info->pcm_type = HDA_PCM_TYPE_SPDIF; | |
c2d986b0 TI |
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; | |
1da177e4 LT |
2019 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; |
2020 | } | |
c2d986b0 TI |
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; | |
1da177e4 LT |
2026 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; |
2027 | } | |
963f803f TI |
2028 | /* FIXME: do we need this for all Realtek codec models? */ |
2029 | codec->spdif_status_reset = 1; | |
1da177e4 LT |
2030 | } |
2031 | ||
e64f14f4 TI |
2032 | if (spec->no_analog) |
2033 | return 0; | |
2034 | ||
e08a007d TI |
2035 | /* If the use of more than one ADC is requested for the current |
2036 | * model, configure a second analog capture-only PCM. | |
2037 | */ | |
1fa17573 | 2038 | have_multi_adcs = (spec->num_adc_nids > 1) && |
27d31536 | 2039 | !spec->dyn_adc_switch && !spec->auto_mic; |
e08a007d | 2040 | /* Additional Analaog capture for index #2 */ |
1fa17573 | 2041 | if (spec->alt_dac_nid || have_multi_adcs) { |
e08a007d | 2042 | codec->num_pcms = 3; |
c06134d7 | 2043 | info = spec->pcm_rec + 2; |
e08a007d | 2044 | info->name = spec->stream_name_analog; |
6330079f | 2045 | if (spec->alt_dac_nid) { |
c2d986b0 TI |
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; | |
6330079f TI |
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 | } | |
1fa17573 | 2057 | if (have_multi_adcs) { |
c2d986b0 TI |
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; | |
6330079f TI |
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; | |
e08a007d TI |
2070 | } |
2071 | } | |
2072 | ||
1da177e4 LT |
2073 | return 0; |
2074 | } | |
2075 | ||
a4e09aa3 TI |
2076 | static inline void alc_shutup(struct hda_codec *codec) |
2077 | { | |
1c716153 TI |
2078 | struct alc_spec *spec = codec->spec; |
2079 | ||
2080 | if (spec && spec->shutup) | |
2081 | spec->shutup(codec); | |
a4e09aa3 TI |
2082 | snd_hda_shutup_pins(codec); |
2083 | } | |
2084 | ||
603c4019 TI |
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 | ||
23c09b00 TI |
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 | ||
1da177e4 LT |
2110 | static void alc_free(struct hda_codec *codec) |
2111 | { | |
e9edcee0 | 2112 | struct alc_spec *spec = codec->spec; |
e9edcee0 | 2113 | |
f12ab1e0 | 2114 | if (!spec) |
e9edcee0 TI |
2115 | return; |
2116 | ||
603c4019 | 2117 | alc_free_kctls(codec); |
23c09b00 | 2118 | alc_free_bind_ctls(codec); |
c9967f1c | 2119 | snd_array_free(&spec->paths); |
ee48df57 | 2120 | snd_hda_gen_free(&spec->gen); |
e9edcee0 | 2121 | kfree(spec); |
680cd536 | 2122 | snd_hda_detach_beep_device(codec); |
1da177e4 LT |
2123 | } |
2124 | ||
83012a7c | 2125 | #ifdef CONFIG_PM |
c97259df DC |
2126 | static void alc_power_eapd(struct hda_codec *codec) |
2127 | { | |
691f1fcc | 2128 | alc_auto_setup_eapd(codec, false); |
c97259df DC |
2129 | } |
2130 | ||
68cb2b55 | 2131 | static int alc_suspend(struct hda_codec *codec) |
f5de24b0 HM |
2132 | { |
2133 | struct alc_spec *spec = codec->spec; | |
a4e09aa3 | 2134 | alc_shutup(codec); |
f5de24b0 | 2135 | if (spec && spec->power_hook) |
c97259df | 2136 | spec->power_hook(codec); |
f5de24b0 HM |
2137 | return 0; |
2138 | } | |
2139 | #endif | |
2140 | ||
2a43952a | 2141 | #ifdef CONFIG_PM |
e044c39a TI |
2142 | static int alc_resume(struct hda_codec *codec) |
2143 | { | |
1c716153 | 2144 | msleep(150); /* to avoid pop noise */ |
e044c39a TI |
2145 | codec->patch_ops.init(codec); |
2146 | snd_hda_codec_resume_amp(codec); | |
2147 | snd_hda_codec_resume_cache(codec); | |
125821ae | 2148 | alc_inv_dmic_sync(codec, true); |
9e5341b9 | 2149 | hda_call_check_power_status(codec, 0x01); |
e044c39a TI |
2150 | return 0; |
2151 | } | |
e044c39a TI |
2152 | #endif |
2153 | ||
1da177e4 LT |
2154 | /* |
2155 | */ | |
a9111321 | 2156 | static const struct hda_codec_ops alc_patch_ops = { |
1da177e4 LT |
2157 | .build_controls = alc_build_controls, |
2158 | .build_pcms = alc_build_pcms, | |
2159 | .init = alc_init, | |
2160 | .free = alc_free, | |
29adc4b9 | 2161 | .unsol_event = snd_hda_jack_unsol_event, |
2a43952a | 2162 | #ifdef CONFIG_PM |
e044c39a TI |
2163 | .resume = alc_resume, |
2164 | #endif | |
83012a7c | 2165 | #ifdef CONFIG_PM |
f5de24b0 | 2166 | .suspend = alc_suspend, |
cb53c626 TI |
2167 | .check_power_status = alc_check_power_status, |
2168 | #endif | |
c97259df | 2169 | .reboot_notify = alc_shutup, |
1da177e4 LT |
2170 | }; |
2171 | ||
29adc4b9 | 2172 | |
c027ddcd KY |
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 | ||
e16fb6d1 TI |
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" }, | |
adcc70b2 | 2203 | { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" }, |
e16fb6d1 TI |
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; | |
e16fb6d1 TI |
2217 | |
2218 | for (p = rename_tbl; p->vendor_id; p++) { | |
2219 | if (p->vendor_id != codec->vendor_id) | |
2220 | continue; | |
1bb7e43e | 2221 | if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits) |
e16fb6d1 TI |
2222 | return alc_codec_rename(codec, p->name); |
2223 | } | |
2224 | return 0; | |
2225 | } | |
2226 | ||
2fa522be | 2227 | /* |
1d045db9 | 2228 | * Automatic parse of I/O pins from the BIOS configuration |
2fa522be | 2229 | */ |
2fa522be | 2230 | |
1d045db9 TI |
2231 | enum { |
2232 | ALC_CTL_WIDGET_VOL, | |
2233 | ALC_CTL_WIDGET_MUTE, | |
2234 | ALC_CTL_BIND_MUTE, | |
23c09b00 TI |
2235 | ALC_CTL_BIND_VOL, |
2236 | ALC_CTL_BIND_SW, | |
2fa522be | 2237 | }; |
1d045db9 TI |
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), | |
23c09b00 TI |
2242 | HDA_BIND_VOL(NULL, 0), |
2243 | HDA_BIND_SW(NULL, 0), | |
2fa522be TI |
2244 | }; |
2245 | ||
1d045db9 TI |
2246 | /* add dynamic controls */ |
2247 | static int add_control(struct alc_spec *spec, int type, const char *name, | |
2248 | int cidx, unsigned long val) | |
e9edcee0 | 2249 | { |
c8b6bf9b | 2250 | struct snd_kcontrol_new *knew; |
e9edcee0 | 2251 | |
668d1e96 | 2252 | knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]); |
603c4019 TI |
2253 | if (!knew) |
2254 | return -ENOMEM; | |
66ceeb6b | 2255 | knew->index = cidx; |
4d02d1b6 | 2256 | if (get_amp_nid_(val)) |
5e26dfd0 | 2257 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
e9edcee0 | 2258 | knew->private_value = val; |
e9edcee0 TI |
2259 | return 0; |
2260 | } | |
2261 | ||
0afe5f89 TI |
2262 | static int add_control_with_pfx(struct alc_spec *spec, int type, |
2263 | const char *pfx, const char *dir, | |
66ceeb6b | 2264 | const char *sfx, int cidx, unsigned long val) |
0afe5f89 TI |
2265 | { |
2266 | char name[32]; | |
2267 | snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx); | |
66ceeb6b | 2268 | return add_control(spec, type, name, cidx, val); |
0afe5f89 TI |
2269 | } |
2270 | ||
66ceeb6b TI |
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) | |
0afe5f89 | 2279 | |
23c09b00 TI |
2280 | static const char * const channel_name[4] = { |
2281 | "Front", "Surround", "CLFE", "Side" | |
2282 | }; | |
2283 | ||
6843ca16 TI |
2284 | static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch, |
2285 | bool can_be_master, int *index) | |
bcb2f0f5 | 2286 | { |
ce764ab2 TI |
2287 | struct auto_pin_cfg *cfg = &spec->autocfg; |
2288 | ||
6843ca16 | 2289 | *index = 0; |
ce764ab2 TI |
2290 | if (cfg->line_outs == 1 && !spec->multi_ios && |
2291 | !cfg->hp_outs && !cfg->speaker_outs && can_be_master) | |
52a8efab TI |
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"; | |
bcb2f0f5 TI |
2300 | |
2301 | switch (cfg->line_out_type) { | |
2302 | case AUTO_PIN_SPEAKER_OUT: | |
ebbeb3d6 DH |
2303 | if (cfg->line_outs == 1) |
2304 | return "Speaker"; | |
fbabc246 TI |
2305 | if (cfg->line_outs == 2) |
2306 | return ch ? "Bass Speaker" : "Speaker"; | |
ebbeb3d6 | 2307 | break; |
bcb2f0f5 | 2308 | case AUTO_PIN_HP_OUT: |
6843ca16 TI |
2309 | /* for multi-io case, only the primary out */ |
2310 | if (ch && spec->multi_ios) | |
2311 | break; | |
2312 | *index = ch; | |
bcb2f0f5 TI |
2313 | return "Headphone"; |
2314 | default: | |
ce764ab2 | 2315 | if (cfg->line_outs == 1 && !spec->multi_ios) |
bcb2f0f5 TI |
2316 | return "PCM"; |
2317 | break; | |
2318 | } | |
71aa5ebe DH |
2319 | if (ch >= ARRAY_SIZE(channel_name)) { |
2320 | snd_BUG(); | |
23c09b00 | 2321 | return "PCM"; |
71aa5ebe | 2322 | } |
23c09b00 TI |
2323 | |
2324 | return channel_name[ch]; | |
bcb2f0f5 TI |
2325 | } |
2326 | ||
83012a7c | 2327 | #ifdef CONFIG_PM |
164f73ee TI |
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 | ||
e9edcee0 | 2346 | /* create input playback/capture controls for the given pin */ |
c2fd19c2 | 2347 | static int new_analog_input(struct hda_codec *codec, hda_nid_t pin, |
66ceeb6b | 2348 | const char *ctlname, int ctlidx, |
c2fd19c2 | 2349 | hda_nid_t mix_nid) |
e9edcee0 | 2350 | { |
c2fd19c2 TI |
2351 | struct alc_spec *spec = codec->spec; |
2352 | struct nid_path *path; | |
829f69ea | 2353 | unsigned int val; |
c2fd19c2 TI |
2354 | int err, idx; |
2355 | ||
bd32f782 TI |
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 | ||
965ccebc | 2360 | path = add_new_nid_path(codec, pin, mix_nid, 2); |
c2fd19c2 | 2361 | if (!path) |
c2fd19c2 | 2362 | return -EINVAL; |
e9edcee0 | 2363 | |
c2fd19c2 | 2364 | idx = path->idx[path->depth - 1]; |
bd32f782 | 2365 | if (nid_has_volume(codec, mix_nid, HDA_INPUT)) { |
829f69ea TI |
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); | |
bd32f782 TI |
2368 | if (err < 0) |
2369 | return err; | |
829f69ea | 2370 | path->ctls[NID_PATH_VOL_CTL] = val; |
bd32f782 TI |
2371 | } |
2372 | ||
2373 | if (nid_has_mute(codec, mix_nid, HDA_INPUT)) { | |
829f69ea TI |
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); | |
bd32f782 TI |
2376 | if (err < 0) |
2377 | return err; | |
829f69ea | 2378 | path->ctls[NID_PATH_MUTE_CTL] = val; |
bd32f782 TI |
2379 | } |
2380 | ||
829f69ea | 2381 | path->active = true; |
164f73ee | 2382 | add_loopback_list(spec, mix_nid, idx); |
e9edcee0 TI |
2383 | return 0; |
2384 | } | |
2385 | ||
05f5f477 TI |
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 | ||
c2fd19c2 TI |
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 | ||
666a70d4 TI |
2401 | /* Parse the codec tree and retrieve ADCs */ |
2402 | static int alc_auto_fill_adc_nids(struct hda_codec *codec) | |
b7821709 | 2403 | { |
d6cc9fab | 2404 | struct alc_spec *spec = codec->spec; |
b7821709 | 2405 | hda_nid_t nid; |
27d31536 TI |
2406 | hda_nid_t *adc_nids = spec->adc_nids; |
2407 | int max_nums = ARRAY_SIZE(spec->adc_nids); | |
b7821709 TI |
2408 | int i, nums = 0; |
2409 | ||
2410 | nid = codec->start_nid; | |
2411 | for (i = 0; i < codec->num_nodes; i++, nid++) { | |
b7821709 TI |
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; | |
b7821709 TI |
2418 | if (++nums >= max_nums) |
2419 | break; | |
2420 | } | |
d6cc9fab | 2421 | spec->num_adc_nids = nums; |
b7821709 TI |
2422 | return nums; |
2423 | } | |
2424 | ||
666a70d4 TI |
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; | |
27d31536 TI |
2431 | struct hda_input_mux *imux = &spec->input_mux; |
2432 | hda_nid_t adc_nids[ARRAY_SIZE(spec->adc_nids)]; | |
666a70d4 TI |
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; | |
27d31536 | 2452 | imux->num_items = 1; |
666a70d4 TI |
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) { | |
27d31536 | 2471 | memcpy(spec->adc_nids, adc_nids, nums * sizeof(hda_nid_t)); |
666a70d4 TI |
2472 | spec->num_adc_nids = nums; |
2473 | } | |
2474 | ||
27d31536 | 2475 | if (imux->num_items == 1 || spec->shared_mic_hp) { |
666a70d4 TI |
2476 | snd_printdd("realtek: reducing to a single ADC\n"); |
2477 | spec->num_adc_nids = 1; /* reduce to a single ADC */ | |
2478 | } | |
2479 | ||
9bf387b6 TI |
2480 | /* single index for individual volumes ctls */ |
2481 | if (!spec->dyn_adc_switch && spec->multi_cap_vol) | |
2482 | spec->num_adc_nids = 1; | |
2483 | ||
666a70d4 TI |
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 | ||
81fede89 TI |
2555 | static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs); |
2556 | ||
9bf387b6 TI |
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"; | |
81fede89 TI |
2564 | unsigned int chs; |
2565 | int err; | |
9bf387b6 TI |
2566 | |
2567 | if (!ctl) | |
2568 | return 0; | |
2569 | ||
81fede89 TI |
2570 | if (idx == spec->inv_dmic_split_idx) |
2571 | chs = 1; | |
2572 | else | |
2573 | chs = 3; | |
2574 | ||
9bf387b6 TI |
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); | |
81fede89 TI |
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)); | |
9bf387b6 TI |
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 | ||
666a70d4 TI |
2688 | static int create_capture_mixers(struct hda_codec *codec) |
2689 | { | |
2690 | struct alc_spec *spec = codec->spec; | |
27d31536 | 2691 | struct hda_input_mux *imux = &spec->input_mux; |
9bf387b6 | 2692 | int i, n, nums, err; |
666a70d4 TI |
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) { | |
9bf387b6 | 2700 | struct snd_kcontrol_new *knew; |
bc549767 | 2701 | knew = alc_kcontrol_new(spec, NULL, &cap_src_temp); |
666a70d4 TI |
2702 | if (!knew) |
2703 | return -ENOMEM; | |
2704 | knew->count = nums; | |
2705 | } | |
2706 | ||
2707 | for (n = 0; n < nums; n++) { | |
9bf387b6 | 2708 | bool multi = false; |
666a70d4 TI |
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]; | |
9bf387b6 TI |
2721 | else if (vol != path->ctls[NID_PATH_VOL_CTL]) |
2722 | multi = true; | |
666a70d4 TI |
2723 | if (!sw) |
2724 | sw = path->ctls[NID_PATH_MUTE_CTL]; | |
9bf387b6 TI |
2725 | else if (sw != path->ctls[NID_PATH_MUTE_CTL]) |
2726 | multi = true; | |
666a70d4 TI |
2727 | } |
2728 | ||
9bf387b6 TI |
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; | |
666a70d4 TI |
2737 | } |
2738 | ||
2739 | return 0; | |
2740 | } | |
2741 | ||
e9edcee0 | 2742 | /* create playback/capture controls for input pins */ |
b7821709 | 2743 | static int alc_auto_create_input_ctls(struct hda_codec *codec) |
e9edcee0 | 2744 | { |
05f5f477 | 2745 | struct alc_spec *spec = codec->spec; |
b7821709 TI |
2746 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
2747 | hda_nid_t mixer = spec->mixer_nid; | |
27d31536 | 2748 | struct hda_input_mux *imux = &spec->input_mux; |
b7821709 | 2749 | int num_adcs; |
666a70d4 | 2750 | int i, c, err, type_idx = 0; |
5322bf27 | 2751 | const char *prev_label = NULL; |
e9edcee0 | 2752 | |
666a70d4 | 2753 | num_adcs = alc_auto_fill_adc_nids(codec); |
b7821709 TI |
2754 | if (num_adcs < 0) |
2755 | return 0; | |
2756 | ||
81fede89 | 2757 | spec->inv_dmic_split_idx = -1; |
66ceeb6b | 2758 | for (i = 0; i < cfg->num_inputs; i++) { |
05f5f477 | 2759 | hda_nid_t pin; |
10a20af7 | 2760 | const char *label; |
666a70d4 | 2761 | bool imux_added; |
05f5f477 | 2762 | |
66ceeb6b | 2763 | pin = cfg->inputs[i].pin; |
05f5f477 TI |
2764 | if (!alc_is_input_pin(codec, pin)) |
2765 | continue; | |
2766 | ||
5322bf27 | 2767 | label = hda_get_autocfg_input_label(codec, cfg, i); |
24de183e TI |
2768 | if (spec->shared_mic_hp && !strcmp(label, "Misc")) |
2769 | label = "Headphone Mic"; | |
5322bf27 | 2770 | if (prev_label && !strcmp(label, prev_label)) |
66ceeb6b TI |
2771 | type_idx++; |
2772 | else | |
2773 | type_idx = 0; | |
5322bf27 DH |
2774 | prev_label = label; |
2775 | ||
05f5f477 | 2776 | if (mixer) { |
c2fd19c2 TI |
2777 | if (is_reachable_path(codec, pin, mixer)) { |
2778 | err = new_analog_input(codec, pin, | |
2779 | label, type_idx, mixer); | |
05f5f477 TI |
2780 | if (err < 0) |
2781 | return err; | |
2782 | } | |
2783 | } | |
2784 | ||
666a70d4 | 2785 | imux_added = false; |
b7821709 | 2786 | for (c = 0; c < num_adcs; c++) { |
666a70d4 TI |
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; | |
b7821709 TI |
2809 | } |
2810 | } | |
81fede89 TI |
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 | } | |
e9edcee0 | 2819 | } |
21268961 | 2820 | |
e9edcee0 TI |
2821 | return 0; |
2822 | } | |
2823 | ||
24de183e TI |
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 | ||
baba8ee9 TI |
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 | ||
0a7f5320 | 2865 | static void alc_auto_init_analog_input(struct hda_codec *codec) |
e9edcee0 TI |
2866 | { |
2867 | struct alc_spec *spec = codec->spec; | |
66ceeb6b | 2868 | struct auto_pin_cfg *cfg = &spec->autocfg; |
e9edcee0 TI |
2869 | int i; |
2870 | ||
66ceeb6b TI |
2871 | for (i = 0; i < cfg->num_inputs; i++) { |
2872 | hda_nid_t nid = cfg->inputs[i].pin; | |
62343997 | 2873 | if (alc_is_input_pin(codec, nid)) |
30ea098f | 2874 | alc_set_input_pin(codec, nid, cfg->inputs[i].type); |
1f0f4b80 | 2875 | |
829f69ea TI |
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) | |
666a70d4 | 2881 | activate_path(codec, path, path->active, false); |
829f69ea | 2882 | } |
1f0f4b80 | 2883 | } |
e9edcee0 TI |
2884 | } |
2885 | ||
185d99f1 TI |
2886 | static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid) |
2887 | { | |
2888 | struct alc_spec *spec = codec->spec; | |
276dd70b | 2889 | int i; |
30dcd3b4 | 2890 | |
c9967f1c TI |
2891 | for (i = 0; i < spec->paths.used; i++) { |
2892 | struct nid_path *path = snd_array_elem(&spec->paths, i); | |
30dcd3b4 | 2893 | if (path->path[0] == nid) |
276dd70b TI |
2894 | return true; |
2895 | } | |
185d99f1 TI |
2896 | return false; |
2897 | } | |
2898 | ||
1d045db9 | 2899 | /* look for an empty DAC slot */ |
fef7fbbc TI |
2900 | static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin, |
2901 | bool is_digital) | |
584c0c4c | 2902 | { |
463419de | 2903 | struct alc_spec *spec = codec->spec; |
fef7fbbc | 2904 | bool cap_digital; |
463419de | 2905 | int i; |
21268961 | 2906 | |
463419de TI |
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)) | |
1d045db9 | 2910 | continue; |
fef7fbbc TI |
2911 | cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL); |
2912 | if (is_digital != cap_digital) | |
2913 | continue; | |
9c64076e | 2914 | if (is_reachable_path(codec, nid, pin)) |
185d99f1 | 2915 | return nid; |
1d045db9 TI |
2916 | } |
2917 | return 0; | |
584c0c4c TI |
2918 | } |
2919 | ||
30dcd3b4 | 2920 | /* called recursively */ |
36f0fd54 TI |
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) | |
30dcd3b4 TI |
2924 | { |
2925 | struct alc_spec *spec = codec->spec; | |
36f0fd54 | 2926 | hda_nid_t conn[16]; |
30dcd3b4 TI |
2927 | int i, nums; |
2928 | ||
36f0fd54 | 2929 | if (to_nid == spec->mixer_nid) { |
30dcd3b4 TI |
2930 | if (!with_aa_mix) |
2931 | return false; | |
2932 | with_aa_mix = 2; /* mark aa-mix is included */ | |
2933 | } | |
2934 | ||
36f0fd54 | 2935 | nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn)); |
30dcd3b4 | 2936 | for (i = 0; i < nums; i++) { |
36f0fd54 TI |
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; | |
30dcd3b4 | 2945 | } |
36f0fd54 TI |
2946 | /* aa-mix is requested but not included? */ |
2947 | if (!(spec->mixer_nid && with_aa_mix == 1)) | |
2948 | goto found; | |
30dcd3b4 TI |
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])); | |
36f0fd54 TI |
2955 | if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN || |
2956 | type == AC_WID_PIN) | |
30dcd3b4 | 2957 | continue; |
36f0fd54 TI |
2958 | if (__parse_nid_path(codec, from_nid, conn[i], |
2959 | with_aa_mix, path, depth + 1)) | |
30dcd3b4 TI |
2960 | goto found; |
2961 | } | |
2962 | return false; | |
2963 | ||
2964 | found: | |
2965 | path->path[path->depth] = conn[i]; | |
95e960ce | 2966 | path->idx[path->depth + 1] = i; |
36f0fd54 | 2967 | if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX) |
95e960ce | 2968 | path->multi[path->depth + 1] = 1; |
30dcd3b4 TI |
2969 | path->depth++; |
2970 | return true; | |
2971 | } | |
2972 | ||
36f0fd54 TI |
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. | |
30dcd3b4 | 2978 | */ |
36f0fd54 TI |
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) | |
30dcd3b4 | 2982 | { |
36f0fd54 TI |
2983 | if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) { |
2984 | path->path[path->depth] = to_nid; | |
30dcd3b4 TI |
2985 | path->depth++; |
2986 | #if 0 | |
36f0fd54 | 2987 | snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n", |
30dcd3b4 TI |
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 | ||
1d045db9 | 2996 | static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin) |
f9e336f6 | 2997 | { |
140547ef | 2998 | struct alc_spec *spec = codec->spec; |
463419de TI |
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)) | |
185d99f1 | 3005 | continue; |
9c64076e | 3006 | if (is_reachable_path(codec, nid, pin)) { |
185d99f1 TI |
3007 | if (nid_found) |
3008 | return 0; | |
3009 | nid_found = nid; | |
3010 | } | |
3011 | } | |
3012 | return nid_found; | |
f9e336f6 TI |
3013 | } |
3014 | ||
ba811127 | 3015 | static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type) |
1c4a54b4 | 3016 | { |
ba811127 TI |
3017 | struct alc_spec *spec = codec->spec; |
3018 | int i; | |
1c4a54b4 | 3019 | |
c9967f1c TI |
3020 | for (i = 0; i < spec->paths.used; i++) { |
3021 | struct nid_path *path = snd_array_elem(&spec->paths, i); | |
ba811127 TI |
3022 | if (path->ctls[type] == val) |
3023 | return true; | |
3024 | } | |
3025 | return false; | |
3026 | } | |
1c4a54b4 | 3027 | |
1c4a54b4 TI |
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, | |
276dd70b TI |
3034 | /* No possible multi-ios */ |
3035 | BAD_MULTI_IO = 0x103, | |
1c4a54b4 | 3036 | /* No individual DAC for extra output */ |
276dd70b | 3037 | BAD_NO_EXTRA_DAC = 0x102, |
1c4a54b4 | 3038 | /* No individual DAC for extra surrounds */ |
276dd70b | 3039 | BAD_NO_EXTRA_SURR_DAC = 0x101, |
1c4a54b4 TI |
3040 | /* Primary DAC shared with main surrounds */ |
3041 | BAD_SHARED_SURROUND = 0x100, | |
1c4a54b4 TI |
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, | |
276dd70b TI |
3046 | /* Volume widget is shared */ |
3047 | BAD_SHARED_VOL = 0x10, | |
1c4a54b4 TI |
3048 | }; |
3049 | ||
3050 | static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec, | |
ba811127 | 3051 | struct nid_path *path); |
1c4a54b4 | 3052 | static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec, |
ba811127 | 3053 | struct nid_path *path); |
1c4a54b4 | 3054 | |
965ccebc TI |
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) | |
30dcd3b4 TI |
3058 | { |
3059 | struct alc_spec *spec = codec->spec; | |
3060 | struct nid_path *path; | |
3061 | ||
965ccebc TI |
3062 | if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid)) |
3063 | return NULL; | |
3064 | ||
c9967f1c | 3065 | path = snd_array_new(&spec->paths); |
30dcd3b4 | 3066 | if (!path) |
965ccebc | 3067 | return NULL; |
30dcd3b4 | 3068 | memset(path, 0, sizeof(*path)); |
965ccebc TI |
3069 | if (parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path)) |
3070 | return path; | |
30dcd3b4 | 3071 | /* push back */ |
c9967f1c | 3072 | spec->paths.used--; |
965ccebc | 3073 | return NULL; |
30dcd3b4 TI |
3074 | } |
3075 | ||
6518f7ac | 3076 | /* get the path between the given NIDs; |
ba811127 TI |
3077 | * passing 0 to either @pin or @dac behaves as a wildcard |
3078 | */ | |
6518f7ac TI |
3079 | static struct nid_path * |
3080 | get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid) | |
ba811127 TI |
3081 | { |
3082 | struct alc_spec *spec = codec->spec; | |
3083 | int i; | |
3084 | ||
c9967f1c TI |
3085 | for (i = 0; i < spec->paths.used; i++) { |
3086 | struct nid_path *path = snd_array_elem(&spec->paths, i); | |
ba811127 TI |
3087 | if (path->depth <= 0) |
3088 | continue; | |
6518f7ac TI |
3089 | if ((!from_nid || path->path[0] == from_nid) && |
3090 | (!to_nid || path->path[path->depth - 1] == to_nid)) | |
ba811127 TI |
3091 | return path; |
3092 | } | |
3093 | return NULL; | |
3094 | } | |
3095 | ||
792cf2fa TI |
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) | |
1c4a54b4 | 3105 | { |
6518f7ac | 3106 | struct nid_path *path = get_nid_path(codec, dac, pin); |
1c4a54b4 TI |
3107 | hda_nid_t nid; |
3108 | unsigned int val; | |
3109 | int badness = 0; | |
3110 | ||
ba811127 TI |
3111 | if (!path) |
3112 | return BAD_SHARED_VOL * 2; | |
3113 | nid = alc_look_for_out_vol_nid(codec, path); | |
1c4a54b4 TI |
3114 | if (nid) { |
3115 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); | |
ba811127 | 3116 | if (is_ctl_used(codec, val, NID_PATH_VOL_CTL)) |
1c4a54b4 TI |
3117 | badness += BAD_SHARED_VOL; |
3118 | else | |
ba811127 | 3119 | path->ctls[NID_PATH_VOL_CTL] = val; |
1c4a54b4 TI |
3120 | } else |
3121 | badness += BAD_SHARED_VOL; | |
ba811127 | 3122 | nid = alc_look_for_out_mute_nid(codec, path); |
1c4a54b4 TI |
3123 | if (nid) { |
3124 | unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid)); | |
792cf2fa TI |
3125 | if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT || |
3126 | nid_has_mute(codec, nid, HDA_OUTPUT)) | |
1c4a54b4 TI |
3127 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); |
3128 | else | |
3129 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT); | |
ba811127 | 3130 | if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL)) |
1c4a54b4 TI |
3131 | badness += BAD_SHARED_VOL; |
3132 | else | |
ba811127 | 3133 | path->ctls[NID_PATH_MUTE_CTL] = val; |
1c4a54b4 TI |
3134 | } else |
3135 | badness += BAD_SHARED_VOL; | |
3136 | return badness; | |
3137 | } | |
3138 | ||
dc31b58d TI |
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) | |
c267468e | 3170 | { |
1c4a54b4 | 3171 | struct alc_spec *spec = codec->spec; |
dc31b58d TI |
3172 | struct auto_pin_cfg *cfg = &spec->autocfg; |
3173 | int i, j; | |
1c4a54b4 TI |
3174 | int badness = 0; |
3175 | hda_nid_t dac; | |
c267468e | 3176 | |
185d99f1 TI |
3177 | if (!num_outs) |
3178 | return 0; | |
3179 | ||
dc31b58d TI |
3180 | for (i = 0; i < num_outs; i++) { |
3181 | hda_nid_t pin = pins[i]; | |
3182 | if (!dacs[i]) | |
fef7fbbc | 3183 | dacs[i] = alc_auto_look_for_dac(codec, pin, false); |
dc31b58d TI |
3184 | if (!dacs[i] && !i) { |
3185 | for (j = 1; j < num_outs; j++) { | |
9c64076e | 3186 | if (is_reachable_path(codec, dacs[j], pin)) { |
dc31b58d TI |
3187 | dacs[0] = dacs[j]; |
3188 | dacs[j] = 0; | |
3189 | break; | |
3190 | } | |
185d99f1 | 3191 | } |
1c4a54b4 | 3192 | } |
1c4a54b4 | 3193 | dac = dacs[i]; |
1c4a54b4 | 3194 | if (!dac) { |
9c64076e | 3195 | if (is_reachable_path(codec, dacs[0], pin)) |
1c4a54b4 | 3196 | dac = dacs[0]; |
dc31b58d | 3197 | else if (cfg->line_outs > i && |
9c64076e | 3198 | is_reachable_path(codec, spec->private_dac_nids[i], pin)) |
dc31b58d TI |
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; | |
9c64076e | 3207 | } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) { |
1c4a54b4 | 3208 | dac = spec->private_dac_nids[0]; |
dc31b58d TI |
3209 | badness += bad->shared_surr_main; |
3210 | } else if (!i) | |
3211 | badness += bad->no_primary_dac; | |
3212 | else | |
3213 | badness += bad->no_dac; | |
1c4a54b4 | 3214 | } |
965ccebc | 3215 | if (!add_new_nid_path(codec, dac, pin, 0)) |
30dcd3b4 | 3216 | dac = dacs[i] = 0; |
1c4a54b4 | 3217 | if (dac) |
792cf2fa | 3218 | badness += assign_out_path_ctls(codec, pin, dac); |
c267468e | 3219 | } |
dc31b58d | 3220 | |
1c4a54b4 | 3221 | return badness; |
c267468e TI |
3222 | } |
3223 | ||
3224 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, | |
276dd70b TI |
3225 | hda_nid_t reference_pin, |
3226 | bool hardwired, int offset); | |
c267468e | 3227 | |
185d99f1 TI |
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++) { | |
30dcd3b4 | 3234 | hda_nid_t dac; |
185d99f1 TI |
3235 | if (dacs[i]) |
3236 | continue; | |
30dcd3b4 TI |
3237 | dac = get_dac_if_single(codec, pins[i]); |
3238 | if (!dac) | |
3239 | continue; | |
965ccebc | 3240 | if (add_new_nid_path(codec, dac, pins[i], 0)) { |
30dcd3b4 | 3241 | dacs[i] = dac; |
185d99f1 | 3242 | found = true; |
30dcd3b4 | 3243 | } |
185d99f1 TI |
3244 | } |
3245 | return found; | |
3246 | } | |
3247 | ||
1d045db9 | 3248 | /* fill in the dac_nids table from the parsed pin configuration */ |
1c4a54b4 | 3249 | static int fill_and_eval_dacs(struct hda_codec *codec, |
276dd70b TI |
3250 | bool fill_hardwired, |
3251 | bool fill_mio_first) | |
21268961 TI |
3252 | { |
3253 | struct alc_spec *spec = codec->spec; | |
0a34b42b | 3254 | struct auto_pin_cfg *cfg = &spec->autocfg; |
dc31b58d | 3255 | int i, err, badness; |
21268961 | 3256 | |
8f398ae7 TI |
3257 | /* set num_dacs once to full for alc_auto_look_for_dac() */ |
3258 | spec->multiout.num_dacs = cfg->line_outs; | |
1d045db9 | 3259 | spec->multiout.dac_nids = spec->private_dac_nids; |
1c4a54b4 TI |
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)); | |
0a34b42b | 3263 | spec->multi_ios = 0; |
c9967f1c | 3264 | snd_array_free(&spec->paths); |
1c4a54b4 | 3265 | badness = 0; |
21268961 | 3266 | |
1d045db9 | 3267 | /* fill hard-wired DACs first */ |
1c4a54b4 | 3268 | if (fill_hardwired) { |
185d99f1 TI |
3269 | bool mapped; |
3270 | do { | |
3271 | mapped = alc_map_singles(codec, cfg->line_outs, | |
276dd70b TI |
3272 | cfg->line_out_pins, |
3273 | spec->private_dac_nids); | |
185d99f1 TI |
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); | |
276dd70b TI |
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 | } | |
185d99f1 | 3286 | } while (mapped); |
21268961 TI |
3287 | } |
3288 | ||
dc31b58d TI |
3289 | badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins, |
3290 | spec->private_dac_nids, | |
3291 | &main_out_badness); | |
21268961 | 3292 | |
8f398ae7 TI |
3293 | /* re-count num_dacs and squash invalid entries */ |
3294 | spec->multiout.num_dacs = 0; | |
1d045db9 TI |
3295 | for (i = 0; i < cfg->line_outs; i++) { |
3296 | if (spec->private_dac_nids[i]) | |
3297 | spec->multiout.num_dacs++; | |
0a34b42b | 3298 | else { |
1d045db9 TI |
3299 | memmove(spec->private_dac_nids + i, |
3300 | spec->private_dac_nids + i + 1, | |
3301 | sizeof(hda_nid_t) * (cfg->line_outs - i - 1)); | |
0a34b42b TI |
3302 | spec->private_dac_nids[cfg->line_outs - 1] = 0; |
3303 | } | |
1d045db9 TI |
3304 | } |
3305 | ||
276dd70b TI |
3306 | if (fill_mio_first && |
3307 | cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { | |
c267468e | 3308 | /* try to fill multi-io first */ |
276dd70b | 3309 | err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0); |
1c4a54b4 TI |
3310 | if (err < 0) |
3311 | return err; | |
276dd70b | 3312 | /* we don't count badness at this stage yet */ |
c267468e | 3313 | } |
23c09b00 | 3314 | |
1c4a54b4 | 3315 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) { |
dc31b58d TI |
3316 | err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins, |
3317 | spec->multiout.hp_out_nid, | |
3318 | &extra_out_badness); | |
1c4a54b4 TI |
3319 | if (err < 0) |
3320 | return err; | |
3321 | badness += err; | |
3322 | } | |
0a34b42b | 3323 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
dc31b58d TI |
3324 | err = alc_auto_fill_dacs(codec, cfg->speaker_outs, |
3325 | cfg->speaker_pins, | |
3326 | spec->multiout.extra_out_nid, | |
3327 | &extra_out_badness); | |
1c4a54b4 TI |
3328 | if (err < 0) |
3329 | return err; | |
3330 | badness += err; | |
3331 | } | |
276dd70b TI |
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) { | |
1c4a54b4 | 3339 | /* try multi-ios with HP + inputs */ |
f568291e TI |
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); | |
1c4a54b4 TI |
3345 | if (err < 0) |
3346 | return err; | |
3347 | badness += err; | |
3348 | } | |
3349 | ||
276dd70b TI |
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 | ||
1c4a54b4 TI |
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]); | |
6f453040 TI |
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); | |
1c4a54b4 TI |
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 | ||
463419de TI |
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 | ||
1c4a54b4 TI |
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; | |
276dd70b TI |
3428 | bool fill_hardwired = true, fill_mio_first = true; |
3429 | bool best_wired = true, best_mio = true; | |
1c4a54b4 TI |
3430 | bool hp_spk_swapped = false; |
3431 | ||
463419de TI |
3432 | alc_fill_all_nids(codec); |
3433 | ||
1c4a54b4 TI |
3434 | best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL); |
3435 | if (!best_cfg) | |
3436 | return -ENOMEM; | |
3437 | *best_cfg = *cfg; | |
3438 | ||
3439 | for (;;) { | |
276dd70b TI |
3440 | badness = fill_and_eval_dacs(codec, fill_hardwired, |
3441 | fill_mio_first); | |
7d7eb9ea JJ |
3442 | if (badness < 0) { |
3443 | kfree(best_cfg); | |
1c4a54b4 | 3444 | return badness; |
7d7eb9ea | 3445 | } |
276dd70b TI |
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); | |
1c4a54b4 TI |
3449 | debug_show_configs(spec, cfg); |
3450 | if (badness < best_badness) { | |
3451 | best_badness = badness; | |
3452 | *best_cfg = *cfg; | |
3453 | best_wired = fill_hardwired; | |
276dd70b | 3454 | best_mio = fill_mio_first; |
1c4a54b4 TI |
3455 | } |
3456 | if (!badness) | |
3457 | break; | |
276dd70b TI |
3458 | fill_mio_first = !fill_mio_first; |
3459 | if (!fill_mio_first) | |
3460 | continue; | |
3461 | fill_hardwired = !fill_hardwired; | |
3462 | if (!fill_hardwired) | |
1c4a54b4 | 3463 | continue; |
1c4a54b4 TI |
3464 | if (hp_spk_swapped) |
3465 | break; | |
3466 | hp_spk_swapped = true; | |
3467 | if (cfg->speaker_outs > 0 && | |
0a34b42b TI |
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; | |
1c4a54b4 TI |
3478 | fill_hardwired = true; |
3479 | continue; | |
7d7eb9ea | 3480 | } |
1c4a54b4 TI |
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; | |
7d7eb9ea | 3494 | } |
1c4a54b4 | 3495 | break; |
0a34b42b | 3496 | } |
23c09b00 | 3497 | |
1c4a54b4 TI |
3498 | if (badness) { |
3499 | *cfg = *best_cfg; | |
276dd70b | 3500 | fill_and_eval_dacs(codec, best_wired, best_mio); |
07b18f69 | 3501 | } |
276dd70b TI |
3502 | debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n", |
3503 | cfg->line_out_type, best_wired, best_mio); | |
1c4a54b4 | 3504 | debug_show_configs(spec, cfg); |
07b18f69 | 3505 | |
ba811127 | 3506 | if (cfg->line_out_pins[0]) { |
6518f7ac TI |
3507 | struct nid_path *path = get_nid_path(codec, |
3508 | spec->multiout.dac_nids[0], | |
3509 | cfg->line_out_pins[0]); | |
ba811127 TI |
3510 | if (path) |
3511 | spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path); | |
3512 | } | |
23c09b00 | 3513 | |
1c4a54b4 TI |
3514 | kfree(best_cfg); |
3515 | return 0; | |
527e4d73 TI |
3516 | } |
3517 | ||
792cf2fa TI |
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 | ||
1d045db9 | 3526 | static int alc_auto_add_vol_ctl(struct hda_codec *codec, |
ba811127 | 3527 | const char *pfx, int cidx, |
792cf2fa | 3528 | unsigned int chs, |
ba811127 | 3529 | struct nid_path *path) |
6694635d | 3530 | { |
527e4d73 | 3531 | unsigned int val; |
792cf2fa | 3532 | if (!path) |
afcd5515 | 3533 | return 0; |
792cf2fa TI |
3534 | val = path->ctls[NID_PATH_VOL_CTL]; |
3535 | if (!val) | |
527e4d73 | 3536 | return 0; |
792cf2fa TI |
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; | |
1d045db9 | 3552 | } |
6694635d | 3553 | |
e29d3778 TI |
3554 | static int alc_auto_add_stereo_vol(struct hda_codec *codec, |
3555 | const char *pfx, int cidx, | |
792cf2fa | 3556 | struct nid_path *path) |
e29d3778 | 3557 | { |
792cf2fa TI |
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); | |
e29d3778 | 3560 | } |
21268961 | 3561 | |
1d045db9 TI |
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, | |
ba811127 | 3566 | const char *pfx, int cidx, |
792cf2fa | 3567 | unsigned int chs, |
ba811127 | 3568 | struct nid_path *path) |
1d045db9 | 3569 | { |
792cf2fa TI |
3570 | unsigned int val; |
3571 | int type = ALC_CTL_WIDGET_MUTE; | |
3572 | ||
3573 | if (!path) | |
afcd5515 | 3574 | return 0; |
792cf2fa TI |
3575 | val = path->ctls[NID_PATH_MUTE_CTL]; |
3576 | if (!val) | |
527e4d73 | 3577 | return 0; |
792cf2fa TI |
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); | |
9366ede7 TI |
3581 | int nums = snd_hda_get_num_conns(codec, nid); |
3582 | if (nums > 1) { | |
792cf2fa | 3583 | type = ALC_CTL_BIND_MUTE; |
9366ede7 | 3584 | val |= nums << 19; |
792cf2fa TI |
3585 | } |
3586 | } | |
1d045db9 | 3587 | return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val); |
6694635d TI |
3588 | } |
3589 | ||
e29d3778 | 3590 | static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx, |
792cf2fa | 3591 | int cidx, struct nid_path *path) |
e29d3778 | 3592 | { |
792cf2fa TI |
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); | |
e29d3778 | 3595 | } |
dc1eae25 | 3596 | |
afcd5515 | 3597 | static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec, |
ba811127 | 3598 | struct nid_path *path) |
afcd5515 | 3599 | { |
ba811127 TI |
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 | } | |
afcd5515 TI |
3609 | return 0; |
3610 | } | |
3611 | ||
3612 | static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec, | |
ba811127 TI |
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 | } | |
afcd5515 TI |
3621 | return 0; |
3622 | } | |
3623 | ||
1d045db9 TI |
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) | |
dc1eae25 TI |
3627 | { |
3628 | struct alc_spec *spec = codec->spec; | |
1d045db9 | 3629 | int i, err, noutputs; |
1f0f4b80 | 3630 | |
1d045db9 | 3631 | noutputs = cfg->line_outs; |
b90bf1de | 3632 | if (spec->multi_ios > 0 && cfg->line_outs < 3) |
1d045db9 | 3633 | noutputs += spec->multi_ios; |
1da177e4 | 3634 | |
1d045db9 TI |
3635 | for (i = 0; i < noutputs; i++) { |
3636 | const char *name; | |
3637 | int index; | |
afcd5515 | 3638 | hda_nid_t dac, pin; |
ba811127 | 3639 | struct nid_path *path; |
afcd5515 TI |
3640 | |
3641 | dac = spec->multiout.dac_nids[i]; | |
3642 | if (!dac) | |
1d045db9 | 3643 | continue; |
689cabf6 | 3644 | if (i >= cfg->line_outs) { |
1d045db9 | 3645 | pin = spec->multi_io[i - 1].pin; |
689cabf6 TI |
3646 | index = 0; |
3647 | name = channel_name[i]; | |
3648 | } else { | |
1d045db9 | 3649 | pin = cfg->line_out_pins[i]; |
689cabf6 TI |
3650 | name = alc_get_line_out_pfx(spec, i, true, &index); |
3651 | } | |
afcd5515 | 3652 | |
6518f7ac | 3653 | path = get_nid_path(codec, dac, pin); |
ba811127 TI |
3654 | if (!path) |
3655 | continue; | |
9c4e84d3 | 3656 | if (!name || !strcmp(name, "CLFE")) { |
1d045db9 | 3657 | /* Center/LFE */ |
792cf2fa | 3658 | err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path); |
1d045db9 TI |
3659 | if (err < 0) |
3660 | return err; | |
792cf2fa | 3661 | err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path); |
1d045db9 TI |
3662 | if (err < 0) |
3663 | return err; | |
792cf2fa | 3664 | err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path); |
1d045db9 TI |
3665 | if (err < 0) |
3666 | return err; | |
792cf2fa | 3667 | err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path); |
1d045db9 TI |
3668 | if (err < 0) |
3669 | return err; | |
3670 | } else { | |
792cf2fa | 3671 | err = alc_auto_add_stereo_vol(codec, name, index, path); |
1d045db9 TI |
3672 | if (err < 0) |
3673 | return err; | |
792cf2fa | 3674 | err = alc_auto_add_stereo_sw(codec, name, index, path); |
1d045db9 TI |
3675 | if (err < 0) |
3676 | return err; | |
e9edcee0 | 3677 | } |
1da177e4 | 3678 | } |
1d045db9 TI |
3679 | return 0; |
3680 | } | |
1da177e4 | 3681 | |
1d045db9 | 3682 | static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin, |
766ddee6 TI |
3683 | hda_nid_t dac, const char *pfx, |
3684 | int cidx) | |
1d045db9 | 3685 | { |
ba811127 | 3686 | struct nid_path *path; |
1d045db9 | 3687 | int err; |
1da177e4 | 3688 | |
6518f7ac | 3689 | path = get_nid_path(codec, dac, pin); |
ba811127 TI |
3690 | if (!path) |
3691 | return 0; | |
792cf2fa TI |
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; | |
e9edcee0 | 3697 | } |
792cf2fa | 3698 | err = alc_auto_add_stereo_sw(codec, pfx, cidx, path); |
1d045db9 TI |
3699 | if (err < 0) |
3700 | return err; | |
1da177e4 LT |
3701 | return 0; |
3702 | } | |
3703 | ||
23c09b00 TI |
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; | |
23c09b00 TI |
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 | ||
527e4d73 TI |
3734 | if (num_pins == 1) { |
3735 | hda_nid_t dac = *dacs; | |
3736 | if (!dac) | |
3737 | dac = spec->multiout.dac_nids[0]; | |
766ddee6 | 3738 | return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0); |
527e4d73 | 3739 | } |
23c09b00 | 3740 | |
23c09b00 | 3741 | for (i = 0; i < num_pins; i++) { |
c96f0bf4 TI |
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 | } | |
23c09b00 TI |
3759 | if (err < 0) |
3760 | return err; | |
3761 | } | |
c96f0bf4 TI |
3762 | if (dacs[num_pins - 1]) |
3763 | return 0; | |
23c09b00 | 3764 | |
c96f0bf4 | 3765 | /* Let's create a bind-controls for volumes */ |
23c09b00 TI |
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; | |
ba811127 | 3772 | struct nid_path *path; |
23c09b00 TI |
3773 | if (!pins[i] || !dacs[i]) |
3774 | continue; | |
6518f7ac | 3775 | path = get_nid_path(codec, dacs[i], pins[i]); |
ba811127 TI |
3776 | if (!path) |
3777 | continue; | |
3778 | vol = alc_look_for_out_vol_nid(codec, path); | |
23c09b00 TI |
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 | ||
1d045db9 | 3792 | static int alc_auto_create_hp_out(struct hda_codec *codec) |
bec15c3a | 3793 | { |
1d045db9 | 3794 | struct alc_spec *spec = codec->spec; |
e23832ac TI |
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"); | |
bec15c3a TI |
3799 | } |
3800 | ||
1d045db9 | 3801 | static int alc_auto_create_speaker_out(struct hda_codec *codec) |
bec15c3a | 3802 | { |
bec15c3a | 3803 | struct alc_spec *spec = codec->spec; |
23c09b00 TI |
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"); | |
bec15c3a TI |
3808 | } |
3809 | ||
c9967f1c TI |
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) | |
bec15c3a | 3813 | { |
c9967f1c | 3814 | struct alc_spec *spec = codec->spec; |
78e635c9 | 3815 | int i, type; |
bec15c3a | 3816 | |
c9967f1c TI |
3817 | for (i = 0; i < spec->paths.used; i++) { |
3818 | struct nid_path *p = snd_array_elem(&spec->paths, i); | |
130e5f06 | 3819 | if (p->depth <= 0) |
1d045db9 | 3820 | continue; |
8dd48678 | 3821 | for (type = 0; type < NID_PATH_NUM_CTLS; type++) { |
c9967f1c TI |
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; | |
130e5f06 TI |
3827 | } |
3828 | } | |
3829 | return false; | |
3830 | } | |
3831 | ||
130e5f06 TI |
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 | ||
c9967f1c TI |
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) | |
130e5f06 | 3863 | { |
c9967f1c | 3864 | struct alc_spec *spec = codec->spec; |
130e5f06 TI |
3865 | int i, n; |
3866 | ||
c9967f1c TI |
3867 | for (n = 0; n < spec->paths.used; n++) { |
3868 | struct nid_path *path = snd_array_elem(&spec->paths, n); | |
130e5f06 TI |
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) | |
78e635c9 | 3874 | return true; |
130e5f06 | 3875 | break; |
78e635c9 TI |
3876 | } |
3877 | } | |
1d045db9 | 3878 | } |
78e635c9 TI |
3879 | return false; |
3880 | } | |
3881 | ||
130e5f06 TI |
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) | |
78e635c9 | 3885 | { |
130e5f06 | 3886 | unsigned int caps; |
78e635c9 TI |
3887 | unsigned int val = 0; |
3888 | ||
3889 | caps = query_amp_caps(codec, nid, dir); | |
3890 | if (caps & AC_AMPCAP_NUM_STEPS) { | |
130e5f06 TI |
3891 | /* set to 0dB */ |
3892 | if (enable) | |
3893 | val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT; | |
78e635c9 TI |
3894 | } |
3895 | if (caps & AC_AMPCAP_MUTE) { | |
130e5f06 | 3896 | if (!enable) |
78e635c9 | 3897 | val |= HDA_AMP_MUTE; |
afcd5515 | 3898 | } |
78e635c9 TI |
3899 | return val; |
3900 | } | |
3901 | ||
130e5f06 TI |
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, | |
666a70d4 | 3929 | int i, bool enable, bool add_aamix) |
78e635c9 | 3930 | { |
9366ede7 | 3931 | struct alc_spec *spec = codec->spec; |
130e5f06 | 3932 | hda_nid_t conn[16]; |
0250f7cb | 3933 | int n, nums, idx; |
666a70d4 | 3934 | int type; |
130e5f06 | 3935 | hda_nid_t nid = path->path[i]; |
78e635c9 | 3936 | |
130e5f06 | 3937 | nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn)); |
666a70d4 TI |
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)) { | |
0250f7cb TI |
3941 | nums = 1; |
3942 | idx = 0; | |
3943 | } else | |
3944 | idx = path->idx[i]; | |
3945 | ||
130e5f06 TI |
3946 | for (n = 0; n < nums; n++) |
3947 | init_amp(codec, nid, HDA_INPUT, n); | |
3948 | ||
0250f7cb | 3949 | if (is_ctl_associated(codec, nid, HDA_INPUT, idx)) |
130e5f06 TI |
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++) { | |
666a70d4 | 3956 | if (n != idx && (!add_aamix || conn[n] != spec->mixer_nid)) |
130e5f06 TI |
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, | |
666a70d4 | 3963 | bool enable, bool add_aamix) |
130e5f06 TI |
3964 | { |
3965 | int i; | |
3966 | ||
130e5f06 TI |
3967 | if (!enable) |
3968 | path->active = false; | |
3969 | ||
78e635c9 | 3970 | for (i = path->depth - 1; i >= 0; i--) { |
183a444a | 3971 | if (enable && path->multi[i]) |
130e5f06 | 3972 | snd_hda_codec_write_cache(codec, path->path[i], 0, |
78e635c9 | 3973 | AC_VERB_SET_CONNECT_SEL, |
95e960ce | 3974 | path->idx[i]); |
130e5f06 | 3975 | if (has_amp_in(codec, path, i)) |
666a70d4 | 3976 | activate_amp_in(codec, path, i, enable, add_aamix); |
130e5f06 TI |
3977 | if (has_amp_out(codec, path, i)) |
3978 | activate_amp_out(codec, path, i, enable); | |
78e635c9 | 3979 | } |
130e5f06 TI |
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); | |
6518f7ac | 3993 | path = get_nid_path(codec, dac, pin); |
130e5f06 TI |
3994 | if (!path) |
3995 | return; | |
3ebf1e94 TI |
3996 | if (path->active) |
3997 | return; | |
666a70d4 | 3998 | activate_path(codec, path, true, true); |
1d045db9 | 3999 | } |
bec15c3a | 4000 | |
1d045db9 | 4001 | static void alc_auto_init_multi_out(struct hda_codec *codec) |
bec15c3a TI |
4002 | { |
4003 | struct alc_spec *spec = codec->spec; | |
1d045db9 TI |
4004 | int pin_type = get_pin_type(spec->autocfg.line_out_type); |
4005 | int i; | |
bec15c3a | 4006 | |
1d045db9 TI |
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, | |
130e5f06 | 4011 | spec->multiout.dac_nids[i]); |
78e635c9 | 4012 | |
1d045db9 | 4013 | } |
bec15c3a TI |
4014 | } |
4015 | ||
1d045db9 | 4016 | static void alc_auto_init_extra_out(struct hda_codec *codec) |
e9427969 TI |
4017 | { |
4018 | struct alc_spec *spec = codec->spec; | |
8cd0775d | 4019 | int i; |
675c1aa3 | 4020 | hda_nid_t pin, dac; |
e9427969 | 4021 | |
636030e9 | 4022 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
716eef03 TI |
4023 | if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT) |
4024 | break; | |
e23832ac TI |
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 | } | |
130e5f06 | 4035 | alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac); |
675c1aa3 | 4036 | } |
8cd0775d | 4037 | for (i = 0; i < spec->autocfg.speaker_outs; i++) { |
716eef03 TI |
4038 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) |
4039 | break; | |
8cd0775d TI |
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 | } | |
130e5f06 | 4050 | alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac); |
675c1aa3 | 4051 | } |
bc9f98a9 KY |
4052 | } |
4053 | ||
276dd70b TI |
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 | ||
df694daa | 4071 | /* |
1d045db9 | 4072 | * multi-io helper |
276dd70b TI |
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. | |
df694daa | 4078 | */ |
1d045db9 | 4079 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, |
276dd70b TI |
4080 | hda_nid_t reference_pin, |
4081 | bool hardwired, int offset) | |
df694daa | 4082 | { |
1d045db9 TI |
4083 | struct alc_spec *spec = codec->spec; |
4084 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
276dd70b TI |
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); | |
1c4a54b4 | 4088 | int badness = 0; |
ea1fb29a | 4089 | |
276dd70b TI |
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 | ||
07b18f69 | 4107 | dacs = spec->multiout.num_dacs; |
1d045db9 TI |
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; | |
07b18f69 | 4111 | hda_nid_t dac = 0; |
276dd70b | 4112 | |
1d045db9 TI |
4113 | if (cfg->inputs[i].type != type) |
4114 | continue; | |
276dd70b | 4115 | if (!can_be_multiio_pin(codec, location, nid)) |
1d045db9 | 4116 | continue; |
276dd70b TI |
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) | |
1d045db9 | 4122 | continue; |
276dd70b TI |
4123 | |
4124 | if (offset && offset + spec->multi_ios < dacs) { | |
4125 | dac = spec->private_dac_nids[offset + spec->multi_ios]; | |
9c64076e | 4126 | if (!is_reachable_path(codec, dac, nid)) |
07b18f69 TI |
4127 | dac = 0; |
4128 | } | |
276dd70b TI |
4129 | if (hardwired) |
4130 | dac = get_dac_if_single(codec, nid); | |
4131 | else if (!dac) | |
fef7fbbc | 4132 | dac = alc_auto_look_for_dac(codec, nid, false); |
1c4a54b4 | 4133 | if (!dac) { |
276dd70b | 4134 | badness++; |
1d045db9 | 4135 | continue; |
1c4a54b4 | 4136 | } |
965ccebc | 4137 | if (!add_new_nid_path(codec, dac, nid, 0)) { |
30dcd3b4 TI |
4138 | badness++; |
4139 | continue; | |
4140 | } | |
276dd70b TI |
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) | |
1c4a54b4 | 4145 | break; |
1d045db9 | 4146 | } |
863b4518 | 4147 | } |
276dd70b TI |
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) { | |
30dcd3b4 | 4158 | /* cancel newly assigned paths */ |
c9967f1c | 4159 | spec->paths.used -= spec->multi_ios - old_pins; |
276dd70b | 4160 | spec->multi_ios = old_pins; |
1c4a54b4 | 4161 | return badness; |
c267468e | 4162 | } |
1c4a54b4 | 4163 | |
792cf2fa TI |
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; | |
a361d84b KY |
4170 | } |
4171 | ||
1d045db9 TI |
4172 | static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol, |
4173 | struct snd_ctl_elem_info *uinfo) | |
a361d84b | 4174 | { |
1d045db9 | 4175 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
a361d84b | 4176 | struct alc_spec *spec = codec->spec; |
a361d84b | 4177 | |
1d045db9 TI |
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 | } | |
a361d84b | 4187 | |
1d045db9 TI |
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 | } | |
a361d84b | 4196 | |
1d045db9 TI |
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; | |
130e5f06 TI |
4201 | struct nid_path *path; |
4202 | ||
6518f7ac | 4203 | path = get_nid_path(codec, spec->multi_io[idx].dac, nid); |
130e5f06 TI |
4204 | if (!path) |
4205 | return -EINVAL; | |
a361d84b | 4206 | |
3ebf1e94 TI |
4207 | if (path->active == output) |
4208 | return 0; | |
130e5f06 | 4209 | |
1d045db9 | 4210 | if (output) { |
cdd03ced | 4211 | snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT); |
666a70d4 | 4212 | activate_path(codec, path, true, true); |
1d045db9 | 4213 | } else { |
666a70d4 | 4214 | activate_path(codec, path, false, true); |
cdd03ced TI |
4215 | snd_hda_set_pin_ctl_cache(codec, nid, |
4216 | spec->multi_io[idx].ctl_in); | |
4f574b7b | 4217 | } |
1d045db9 | 4218 | return 0; |
a361d84b KY |
4219 | } |
4220 | ||
1d045db9 TI |
4221 | static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol, |
4222 | struct snd_ctl_elem_value *ucontrol) | |
a361d84b | 4223 | { |
1d045db9 | 4224 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
f6c7e546 | 4225 | struct alc_spec *spec = codec->spec; |
1d045db9 | 4226 | int i, ch; |
a361d84b | 4227 | |
1d045db9 TI |
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); | |
b6adb57d TI |
4236 | spec->multiout.max_channels = max(spec->ext_channel_count, |
4237 | spec->const_channel_count); | |
4238 | if (spec->need_dac_fix) | |
7b1655f5 | 4239 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; |
1d045db9 TI |
4240 | return 1; |
4241 | } | |
3abf2f36 | 4242 | |
1d045db9 TI |
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, | |
a361d84b KY |
4249 | }; |
4250 | ||
23c09b00 | 4251 | static int alc_auto_add_multi_channel_mode(struct hda_codec *codec) |
a361d84b | 4252 | { |
1d045db9 | 4253 | struct alc_spec *spec = codec->spec; |
a361d84b | 4254 | |
c267468e | 4255 | if (spec->multi_ios > 0) { |
bc549767 | 4256 | if (!alc_kcontrol_new(spec, NULL, &alc_auto_channel_mode_enum)) |
1d045db9 | 4257 | return -ENOMEM; |
a361d84b | 4258 | } |
1d045db9 TI |
4259 | return 0; |
4260 | } | |
a361d84b | 4261 | |
3ebf1e94 TI |
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); | |
666a70d4 | 4277 | activate_path(codec, path, path->active, true); |
22971e3a | 4278 | } |
1d045db9 TI |
4279 | } |
4280 | ||
4281 | /* | |
4282 | * initialize ADC paths | |
4283 | */ | |
1d045db9 TI |
4284 | static void alc_auto_init_input_src(struct hda_codec *codec) |
4285 | { | |
4286 | struct alc_spec *spec = codec->spec; | |
27d31536 | 4287 | struct hda_input_mux *imux = &spec->input_mux; |
666a70d4 TI |
4288 | struct nid_path *path; |
4289 | int i, c, nums; | |
d6cc9fab | 4290 | |
1d045db9 TI |
4291 | if (spec->dyn_adc_switch) |
4292 | nums = 1; | |
4293 | else | |
4294 | nums = spec->num_adc_nids; | |
666a70d4 TI |
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]); | |
1d045db9 | 4312 | } |
2134ea4f | 4313 | |
1d045db9 TI |
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; | |
ea1fb29a | 4323 | |
1d045db9 TI |
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]; | |
8dd48678 TI |
4331 | struct nid_path *path; |
4332 | unsigned int val; | |
1d045db9 TI |
4333 | |
4334 | label = hda_get_autocfg_input_label(codec, cfg, i); | |
24de183e TI |
4335 | if (spec->shared_mic_hp && !strcmp(label, "Misc")) |
4336 | label = "Headphone Mic"; | |
1d045db9 TI |
4337 | if (prev_label && !strcmp(label, prev_label)) |
4338 | type_idx++; | |
4339 | else | |
4340 | type_idx = 0; | |
4341 | prev_label = label; | |
bf1b0225 | 4342 | |
1d045db9 TI |
4343 | snprintf(boost_label, sizeof(boost_label), |
4344 | "%s Boost Volume", label); | |
8dd48678 | 4345 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT); |
1d045db9 | 4346 | err = add_control(spec, ALC_CTL_WIDGET_VOL, |
8dd48678 | 4347 | boost_label, type_idx, val); |
1d045db9 TI |
4348 | if (err < 0) |
4349 | return err; | |
8dd48678 TI |
4350 | |
4351 | path = get_nid_path(codec, nid, 0); | |
4352 | if (path) | |
4353 | path->ctls[NID_PATH_BOOST_CTL] = val; | |
1d045db9 TI |
4354 | } |
4355 | } | |
a361d84b KY |
4356 | return 0; |
4357 | } | |
4358 | ||
e4770629 TI |
4359 | /* |
4360 | * standard auto-parser initializations | |
4361 | */ | |
4362 | static void alc_auto_init_std(struct hda_codec *codec) | |
4363 | { | |
e4770629 TI |
4364 | alc_auto_init_multi_out(codec); |
4365 | alc_auto_init_extra_out(codec); | |
3ebf1e94 | 4366 | alc_auto_init_multi_io(codec); |
e4770629 TI |
4367 | alc_auto_init_analog_input(codec); |
4368 | alc_auto_init_input_src(codec); | |
4369 | alc_auto_init_digital(codec); | |
2eab694a TI |
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); | |
e4770629 TI |
4374 | } |
4375 | ||
1d045db9 TI |
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)) | |
84898e87 | 4382 | |
1d045db9 | 4383 | static const struct snd_pci_quirk beep_white_list[] = { |
7110005e | 4384 | SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1), |
1d045db9 TI |
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), | |
78f8baf1 | 4389 | SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1), |
1d045db9 TI |
4390 | SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1), |
4391 | {} | |
fe3eb0a7 KY |
4392 | }; |
4393 | ||
1d045db9 TI |
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 | |
84898e87 | 4407 | |
1d045db9 TI |
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 | */ | |
3e6179b8 TI |
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) | |
1d045db9 TI |
4415 | { |
4416 | struct alc_spec *spec = codec->spec; | |
23c09b00 | 4417 | struct auto_pin_cfg *cfg = &spec->autocfg; |
1d045db9 | 4418 | int err; |
26f5df26 | 4419 | |
53c334ad TI |
4420 | err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids, |
4421 | spec->parse_flags); | |
1d045db9 TI |
4422 | if (err < 0) |
4423 | return err; | |
23c09b00 TI |
4424 | if (!cfg->line_outs) { |
4425 | if (cfg->dig_outs || cfg->dig_in_pin) { | |
3e6179b8 TI |
4426 | spec->multiout.max_channels = 2; |
4427 | spec->no_analog = 1; | |
4428 | goto dig_only; | |
4429 | } | |
1d045db9 | 4430 | return 0; /* can't find valid BIOS pin config */ |
3e6179b8 | 4431 | } |
23c09b00 | 4432 | |
e427c237 TI |
4433 | if (!spec->no_primary_hp && |
4434 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && | |
06503670 | 4435 | cfg->line_outs <= cfg->hp_outs) { |
23c09b00 TI |
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 | ||
1d045db9 | 4447 | err = alc_auto_fill_dac_nids(codec); |
3e6179b8 TI |
4448 | if (err < 0) |
4449 | return err; | |
23c09b00 | 4450 | err = alc_auto_add_multi_channel_mode(codec); |
1d045db9 TI |
4451 | if (err < 0) |
4452 | return err; | |
23c09b00 | 4453 | err = alc_auto_create_multi_out_ctls(codec, cfg); |
1d045db9 TI |
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); | |
24de183e TI |
4460 | if (err < 0) |
4461 | return err; | |
4462 | err = alc_auto_create_shared_input(codec); | |
1d045db9 TI |
4463 | if (err < 0) |
4464 | return err; | |
4465 | err = alc_auto_create_input_ctls(codec); | |
4466 | if (err < 0) | |
4467 | return err; | |
84898e87 | 4468 | |
b6adb57d TI |
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; | |
f53281e6 | 4480 | |
3e6179b8 | 4481 | dig_only: |
1d045db9 | 4482 | alc_auto_parse_digital(codec); |
f6a92248 | 4483 | |
3e6179b8 TI |
4484 | if (ssid_nids) |
4485 | alc_ssid_check(codec, ssid_nids); | |
64154835 | 4486 | |
3e6179b8 | 4487 | if (!spec->no_analog) { |
666a70d4 | 4488 | err = alc_init_automute(codec); |
475c3d21 TI |
4489 | if (err < 0) |
4490 | return err; | |
666a70d4 TI |
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 | ||
3e6179b8 TI |
4506 | err = alc_auto_add_mic_boost(codec); |
4507 | if (err < 0) | |
4508 | return err; | |
4509 | } | |
f6a92248 | 4510 | |
3e6179b8 TI |
4511 | if (spec->kctls.list) |
4512 | add_mixer(spec, spec->kctls.list); | |
f6a92248 | 4513 | |
1d045db9 | 4514 | return 1; |
60db6b53 | 4515 | } |
f6a92248 | 4516 | |
3de95173 TI |
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; | |
1098b7c2 | 4526 | codec->single_adc_amp = 1; |
3de95173 | 4527 | spec->mixer_nid = mixer_nid; |
ee48df57 | 4528 | snd_hda_gen_init(&spec->gen); |
361dab3e TI |
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); | |
c9967f1c | 4531 | snd_array_init(&spec->paths, sizeof(struct nid_path), 8); |
3de95173 TI |
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 | ||
3e6179b8 TI |
4541 | static int alc880_parse_auto_config(struct hda_codec *codec) |
4542 | { | |
4543 | static const hda_nid_t alc880_ignore[] = { 0x1d, 0 }; | |
7d7eb9ea | 4544 | static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
3e6179b8 TI |
4545 | return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids); |
4546 | } | |
4547 | ||
ee3b2969 TI |
4548 | /* |
4549 | * ALC880 fix-ups | |
4550 | */ | |
4551 | enum { | |
411225a0 | 4552 | ALC880_FIXUP_GPIO1, |
ee3b2969 TI |
4553 | ALC880_FIXUP_GPIO2, |
4554 | ALC880_FIXUP_MEDION_RIM, | |
dc6af52d | 4555 | ALC880_FIXUP_LG, |
f02aab5d | 4556 | ALC880_FIXUP_W810, |
27e917f8 | 4557 | ALC880_FIXUP_EAPD_COEF, |
b9368f5c | 4558 | ALC880_FIXUP_TCL_S700, |
cf5a2279 TI |
4559 | ALC880_FIXUP_VOL_KNOB, |
4560 | ALC880_FIXUP_FUJITSU, | |
ba533818 | 4561 | ALC880_FIXUP_F1734, |
817de92f | 4562 | ALC880_FIXUP_UNIWILL, |
967b88c4 | 4563 | ALC880_FIXUP_UNIWILL_DIG, |
96e225f6 | 4564 | ALC880_FIXUP_Z71V, |
67b6ec31 TI |
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, | |
ee3b2969 TI |
4574 | }; |
4575 | ||
cf5a2279 TI |
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) | |
29adc4b9 | 4581 | snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master); |
cf5a2279 TI |
4582 | } |
4583 | ||
ee3b2969 | 4584 | static const struct alc_fixup alc880_fixups[] = { |
411225a0 TI |
4585 | [ALC880_FIXUP_GPIO1] = { |
4586 | .type = ALC_FIXUP_VERBS, | |
4587 | .v.verbs = alc_gpio1_init_verbs, | |
4588 | }, | |
ee3b2969 TI |
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 | }, | |
dc6af52d TI |
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 | }, | |
f02aab5d TI |
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 | }, | |
27e917f8 TI |
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 | }, | |
b9368f5c TI |
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 | }, | |
cf5a2279 TI |
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 | }, | |
ba533818 TI |
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 | }, | |
817de92f TI |
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 | }, | |
967b88c4 TI |
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 | }, | |
96e225f6 TI |
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 | }, | |
67b6ec31 TI |
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 | }, | |
ee3b2969 TI |
4834 | }; |
4835 | ||
4836 | static const struct snd_pci_quirk alc880_fixup_tbl[] = { | |
f02aab5d | 4837 | SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810), |
96e225f6 | 4838 | SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V), |
29e3fdcc TI |
4839 | SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1), |
4840 | SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2), | |
27e917f8 | 4841 | SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF), |
967b88c4 | 4842 | SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG), |
ba533818 | 4843 | SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734), |
817de92f | 4844 | SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL), |
7833c7e8 | 4845 | SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB), |
f02aab5d | 4846 | SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810), |
ee3b2969 | 4847 | SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM), |
ba533818 | 4848 | SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734), |
cf5a2279 | 4849 | SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU), |
ba533818 | 4850 | SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734), |
cf5a2279 | 4851 | SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU), |
dc6af52d TI |
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), | |
b9368f5c | 4855 | SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700), |
67b6ec31 TI |
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"}, | |
ee3b2969 TI |
4910 | {} |
4911 | }; | |
4912 | ||
4913 | ||
1d045db9 TI |
4914 | /* |
4915 | * OK, here we have finally the patch for ALC880 | |
4916 | */ | |
1d045db9 | 4917 | static int patch_alc880(struct hda_codec *codec) |
60db6b53 | 4918 | { |
1d045db9 | 4919 | struct alc_spec *spec; |
1d045db9 | 4920 | int err; |
f6a92248 | 4921 | |
3de95173 TI |
4922 | err = alc_alloc_spec(codec, 0x0b); |
4923 | if (err < 0) | |
4924 | return err; | |
64154835 | 4925 | |
3de95173 | 4926 | spec = codec->spec; |
7b1655f5 | 4927 | spec->need_dac_fix = 1; |
f53281e6 | 4928 | |
67b6ec31 TI |
4929 | alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl, |
4930 | alc880_fixups); | |
4931 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
ee3b2969 | 4932 | |
67b6ec31 TI |
4933 | /* automatic parse from the BIOS config */ |
4934 | err = alc880_parse_auto_config(codec); | |
4935 | if (err < 0) | |
4936 | goto error; | |
fe3eb0a7 | 4937 | |
3e6179b8 TI |
4938 | if (!spec->no_analog) { |
4939 | err = snd_hda_attach_beep_device(codec, 0x1); | |
e16fb6d1 TI |
4940 | if (err < 0) |
4941 | goto error; | |
3e6179b8 TI |
4942 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
4943 | } | |
f53281e6 | 4944 | |
1d045db9 | 4945 | codec->patch_ops = alc_patch_ops; |
29adc4b9 DH |
4946 | codec->patch_ops.unsol_event = alc880_unsol_event; |
4947 | ||
f53281e6 | 4948 | |
589876e2 TI |
4949 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
4950 | ||
1d045db9 | 4951 | return 0; |
e16fb6d1 TI |
4952 | |
4953 | error: | |
4954 | alc_free(codec); | |
4955 | return err; | |
226b1ec8 KY |
4956 | } |
4957 | ||
1d045db9 | 4958 | |
60db6b53 | 4959 | /* |
1d045db9 | 4960 | * ALC260 support |
60db6b53 | 4961 | */ |
1d045db9 | 4962 | static int alc260_parse_auto_config(struct hda_codec *codec) |
f6a92248 | 4963 | { |
1d045db9 | 4964 | static const hda_nid_t alc260_ignore[] = { 0x17, 0 }; |
3e6179b8 TI |
4965 | static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 }; |
4966 | return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids); | |
f6a92248 KY |
4967 | } |
4968 | ||
1d045db9 TI |
4969 | /* |
4970 | * Pin config fixes | |
4971 | */ | |
4972 | enum { | |
ca8f0424 TI |
4973 | ALC260_FIXUP_HP_DC5750, |
4974 | ALC260_FIXUP_HP_PIN_0F, | |
4975 | ALC260_FIXUP_COEF, | |
15317ab2 | 4976 | ALC260_FIXUP_GPIO1, |
20f7d928 TI |
4977 | ALC260_FIXUP_GPIO1_TOGGLE, |
4978 | ALC260_FIXUP_REPLACER, | |
0a1c4fa2 | 4979 | ALC260_FIXUP_HP_B1900, |
118cb4a4 | 4980 | ALC260_FIXUP_KN1, |
1d045db9 TI |
4981 | }; |
4982 | ||
20f7d928 TI |
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 */ | |
29adc4b9 DH |
5002 | snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT, |
5003 | alc_hp_automute); | |
23d30f28 | 5004 | snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs); |
20f7d928 TI |
5005 | } |
5006 | } | |
5007 | ||
118cb4a4 TI |
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 | ||
1d045db9 | 5038 | static const struct alc_fixup alc260_fixups[] = { |
ca8f0424 | 5039 | [ALC260_FIXUP_HP_DC5750] = { |
1d045db9 TI |
5040 | .type = ALC_FIXUP_PINS, |
5041 | .v.pins = (const struct alc_pincfg[]) { | |
5042 | { 0x11, 0x90130110 }, /* speaker */ | |
5043 | { } | |
5044 | } | |
5045 | }, | |
ca8f0424 TI |
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 | }, | |
15317ab2 TI |
5063 | [ALC260_FIXUP_GPIO1] = { |
5064 | .type = ALC_FIXUP_VERBS, | |
5065 | .v.verbs = alc_gpio1_init_verbs, | |
5066 | }, | |
20f7d928 TI |
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 | }, | |
0a1c4fa2 TI |
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, | |
118cb4a4 TI |
5088 | }, |
5089 | [ALC260_FIXUP_KN1] = { | |
5090 | .type = ALC_FIXUP_FUNC, | |
5091 | .v.func = alc260_fixup_kn1, | |
5092 | }, | |
1d045db9 TI |
5093 | }; |
5094 | ||
5095 | static const struct snd_pci_quirk alc260_fixup_tbl[] = { | |
15317ab2 | 5096 | SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1), |
ca8f0424 | 5097 | SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF), |
15317ab2 | 5098 | SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1), |
ca8f0424 | 5099 | SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750), |
0a1c4fa2 | 5100 | SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900), |
b1f58085 | 5101 | SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1), |
118cb4a4 | 5102 | SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1), |
20f7d928 | 5103 | SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER), |
ca8f0424 | 5104 | SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF), |
1d045db9 TI |
5105 | {} |
5106 | }; | |
5107 | ||
5108 | /* | |
5109 | */ | |
1d045db9 | 5110 | static int patch_alc260(struct hda_codec *codec) |
977ddd6b | 5111 | { |
1d045db9 | 5112 | struct alc_spec *spec; |
c3c2c9e7 | 5113 | int err; |
1d045db9 | 5114 | |
3de95173 TI |
5115 | err = alc_alloc_spec(codec, 0x07); |
5116 | if (err < 0) | |
5117 | return err; | |
1d045db9 | 5118 | |
3de95173 | 5119 | spec = codec->spec; |
1d045db9 | 5120 | |
c3c2c9e7 TI |
5121 | alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); |
5122 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
977ddd6b | 5123 | |
c3c2c9e7 TI |
5124 | /* automatic parse from the BIOS config */ |
5125 | err = alc260_parse_auto_config(codec); | |
5126 | if (err < 0) | |
5127 | goto error; | |
977ddd6b | 5128 | |
3e6179b8 TI |
5129 | if (!spec->no_analog) { |
5130 | err = snd_hda_attach_beep_device(codec, 0x1); | |
e16fb6d1 TI |
5131 | if (err < 0) |
5132 | goto error; | |
3e6179b8 TI |
5133 | set_beep_amp(spec, 0x07, 0x05, HDA_INPUT); |
5134 | } | |
977ddd6b | 5135 | |
1d045db9 | 5136 | codec->patch_ops = alc_patch_ops; |
1d045db9 | 5137 | spec->shutup = alc_eapd_shutup; |
6981d184 | 5138 | |
589876e2 TI |
5139 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
5140 | ||
1d045db9 | 5141 | return 0; |
e16fb6d1 TI |
5142 | |
5143 | error: | |
5144 | alc_free(codec); | |
5145 | return err; | |
6981d184 TI |
5146 | } |
5147 | ||
1d045db9 TI |
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 | */ | |
1d045db9 TI |
5160 | |
5161 | /* | |
5162 | * Pin config fixes | |
5163 | */ | |
ff818c24 | 5164 | enum { |
5c0ebfbe TI |
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, | |
8f239214 | 5170 | ALC889_FIXUP_CD, |
5c0ebfbe | 5171 | ALC889_FIXUP_VAIO_TT, |
0e7cc2e7 | 5172 | ALC888_FIXUP_EEE1601, |
177943a3 | 5173 | ALC882_FIXUP_EAPD, |
7a6069bf | 5174 | ALC883_FIXUP_EAPD, |
8812c4f9 | 5175 | ALC883_FIXUP_ACER_EAPD, |
1a97b7f2 TI |
5176 | ALC882_FIXUP_GPIO1, |
5177 | ALC882_FIXUP_GPIO2, | |
eb844d51 | 5178 | ALC882_FIXUP_GPIO3, |
68ef0561 TI |
5179 | ALC889_FIXUP_COEF, |
5180 | ALC882_FIXUP_ASUS_W2JC, | |
c3e837bb TI |
5181 | ALC882_FIXUP_ACER_ASPIRE_4930G, |
5182 | ALC882_FIXUP_ACER_ASPIRE_8930G, | |
5183 | ALC882_FIXUP_ASPIRE_8930G_VERBS, | |
5671087f | 5184 | ALC885_FIXUP_MACPRO_GPIO, |
02a237b2 | 5185 | ALC889_FIXUP_DAC_ROUTE, |
1a97b7f2 TI |
5186 | ALC889_FIXUP_MBP_VREF, |
5187 | ALC889_FIXUP_IMAC91_VREF, | |
6e72aa5f | 5188 | ALC882_FIXUP_INV_DMIC, |
e427c237 | 5189 | ALC882_FIXUP_NO_PRIMARY_HP, |
ff818c24 TI |
5190 | }; |
5191 | ||
68ef0561 TI |
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 | ||
5671087f TI |
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 | ||
02a237b2 TI |
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) { | |
ef8d60fb | 5251 | /* fake the connections during parsing the tree */ |
02a237b2 TI |
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); | |
ef8d60fb TI |
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); | |
02a237b2 TI |
5265 | } |
5266 | } | |
5267 | ||
1a97b7f2 TI |
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; | |
cdd03ced | 5285 | snd_hda_set_pin_ctl(codec, nids[i], val); |
1a97b7f2 TI |
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; | |
cdd03ced | 5306 | snd_hda_set_pin_ctl(codec, nids[i], val); |
1a97b7f2 TI |
5307 | } |
5308 | spec->keep_vref_in_automute = 1; | |
5309 | } | |
5310 | ||
e427c237 TI |
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 | ||
1d045db9 | 5322 | static const struct alc_fixup alc882_fixups[] = { |
5c0ebfbe | 5323 | [ALC882_FIXUP_ABIT_AW9D_MAX] = { |
1d045db9 TI |
5324 | .type = ALC_FIXUP_PINS, |
5325 | .v.pins = (const struct alc_pincfg[]) { | |
5326 | { 0x15, 0x01080104 }, /* side */ | |
5327 | { 0x16, 0x01011012 }, /* rear */ | |
5328 | { 0x17, 0x01016011 }, /* clfe */ | |
2785591a | 5329 | { } |
145a902b DH |
5330 | } |
5331 | }, | |
5c0ebfbe | 5332 | [ALC882_FIXUP_LENOVO_Y530] = { |
b5bfbc67 TI |
5333 | .type = ALC_FIXUP_PINS, |
5334 | .v.pins = (const struct alc_pincfg[]) { | |
1d045db9 TI |
5335 | { 0x15, 0x99130112 }, /* rear int speakers */ |
5336 | { 0x16, 0x99130111 }, /* subwoofer */ | |
ac612407 DH |
5337 | { } |
5338 | } | |
5339 | }, | |
5c0ebfbe | 5340 | [ALC882_FIXUP_PB_M5210] = { |
b5bfbc67 TI |
5341 | .type = ALC_FIXUP_VERBS, |
5342 | .v.verbs = (const struct hda_verb[]) { | |
1d045db9 | 5343 | { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, |
357f915e KY |
5344 | {} |
5345 | } | |
5346 | }, | |
5c0ebfbe | 5347 | [ALC882_FIXUP_ACER_ASPIRE_7736] = { |
23d30f28 TI |
5348 | .type = ALC_FIXUP_FUNC, |
5349 | .v.func = alc_fixup_sku_ignore, | |
6981d184 | 5350 | }, |
5c0ebfbe | 5351 | [ALC882_FIXUP_ASUS_W90V] = { |
5cdf745e TI |
5352 | .type = ALC_FIXUP_PINS, |
5353 | .v.pins = (const struct alc_pincfg[]) { | |
5354 | { 0x16, 0x99130110 }, /* fix sequence for CLFE */ | |
5355 | { } | |
5356 | } | |
5357 | }, | |
8f239214 MB |
5358 | [ALC889_FIXUP_CD] = { |
5359 | .type = ALC_FIXUP_PINS, | |
5360 | .v.pins = (const struct alc_pincfg[]) { | |
5361 | { 0x1c, 0x993301f0 }, /* CD */ | |
5362 | { } | |
5363 | } | |
5364 | }, | |
5c0ebfbe TI |
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 | }, | |
0e7cc2e7 TI |
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 | } | |
177943a3 TI |
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 | }, | |
7a6069bf TI |
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 | }, | |
8812c4f9 TI |
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 | }, | |
1a97b7f2 TI |
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 | }, | |
eb844d51 TI |
5415 | [ALC882_FIXUP_GPIO3] = { |
5416 | .type = ALC_FIXUP_VERBS, | |
5417 | .v.verbs = alc_gpio3_init_verbs, | |
5418 | }, | |
68ef0561 TI |
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 | }, | |
c3e837bb TI |
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 | { } | |
038d4fef TI |
5435 | }, |
5436 | .chained = true, | |
5437 | .chain_id = ALC882_FIXUP_GPIO1, | |
c3e837bb TI |
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 | { } | |
038d4fef TI |
5480 | }, |
5481 | .chained = true, | |
5482 | .chain_id = ALC882_FIXUP_GPIO1, | |
c3e837bb | 5483 | }, |
5671087f TI |
5484 | [ALC885_FIXUP_MACPRO_GPIO] = { |
5485 | .type = ALC_FIXUP_FUNC, | |
5486 | .v.func = alc885_fixup_macpro_gpio, | |
5487 | }, | |
02a237b2 TI |
5488 | [ALC889_FIXUP_DAC_ROUTE] = { |
5489 | .type = ALC_FIXUP_FUNC, | |
5490 | .v.func = alc889_fixup_dac_route, | |
5491 | }, | |
1a97b7f2 TI |
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 | }, | |
6e72aa5f TI |
5504 | [ALC882_FIXUP_INV_DMIC] = { |
5505 | .type = ALC_FIXUP_FUNC, | |
5506 | .v.func = alc_fixup_inv_dmic_0x12, | |
5507 | }, | |
e427c237 TI |
5508 | [ALC882_FIXUP_NO_PRIMARY_HP] = { |
5509 | .type = ALC_FIXUP_FUNC, | |
5510 | .v.func = alc882_fixup_no_primary_hp, | |
5511 | }, | |
ff818c24 TI |
5512 | }; |
5513 | ||
1d045db9 | 5514 | static const struct snd_pci_quirk alc882_fixup_tbl[] = { |
8812c4f9 TI |
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), | |
c3e837bb TI |
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), | |
5c0ebfbe | 5535 | SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210), |
f5c53d89 TI |
5536 | SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G", |
5537 | ALC882_FIXUP_ACER_ASPIRE_4930G), | |
02a237b2 | 5538 | SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE), |
fe97da1f | 5539 | SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G), |
ac9b1cdd | 5540 | SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736), |
177943a3 | 5541 | SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD), |
5c0ebfbe | 5542 | SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V), |
68ef0561 | 5543 | SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC), |
0e7cc2e7 | 5544 | SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601), |
ac9b1cdd | 5545 | SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT), |
e427c237 | 5546 | SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP), |
5671087f TI |
5547 | |
5548 | /* All Apple entries are in codec SSIDs */ | |
1a97b7f2 TI |
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), | |
5671087f TI |
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), | |
1a97b7f2 TI |
5555 | SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF), |
5556 | SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF), | |
5671087f | 5557 | SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD), |
1a97b7f2 TI |
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), | |
5671087f | 5562 | SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO), |
1a97b7f2 TI |
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), | |
29ebe402 | 5566 | SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO), |
05193639 | 5567 | SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF), |
1a97b7f2 TI |
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), | |
5671087f | 5571 | |
7a6069bf | 5572 | SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD), |
bca40138 | 5573 | SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD), |
eb844d51 | 5574 | SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3), |
8f239214 | 5575 | SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD), |
5c0ebfbe | 5576 | SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX), |
7a6069bf TI |
5577 | SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD), |
5578 | SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD), | |
ac9b1cdd | 5579 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530), |
68ef0561 | 5580 | SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF), |
ff818c24 TI |
5581 | {} |
5582 | }; | |
5583 | ||
912093bc TI |
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"}, | |
6e72aa5f | 5588 | {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"}, |
e427c237 | 5589 | {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"}, |
912093bc TI |
5590 | {} |
5591 | }; | |
5592 | ||
f6a92248 | 5593 | /* |
1d045db9 | 5594 | * BIOS auto configuration |
f6a92248 | 5595 | */ |
1d045db9 TI |
5596 | /* almost identical with ALC880 parser... */ |
5597 | static int alc882_parse_auto_config(struct hda_codec *codec) | |
5598 | { | |
1d045db9 | 5599 | static const hda_nid_t alc882_ignore[] = { 0x1d, 0 }; |
3e6179b8 TI |
5600 | static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
5601 | return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids); | |
1d045db9 | 5602 | } |
b896b4eb | 5603 | |
1d045db9 TI |
5604 | /* |
5605 | */ | |
1d045db9 | 5606 | static int patch_alc882(struct hda_codec *codec) |
f6a92248 KY |
5607 | { |
5608 | struct alc_spec *spec; | |
1a97b7f2 | 5609 | int err; |
f6a92248 | 5610 | |
3de95173 TI |
5611 | err = alc_alloc_spec(codec, 0x0b); |
5612 | if (err < 0) | |
5613 | return err; | |
f6a92248 | 5614 | |
3de95173 | 5615 | spec = codec->spec; |
1f0f4b80 | 5616 | |
1d045db9 TI |
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; | |
c793bec5 | 5625 | } |
977ddd6b | 5626 | |
912093bc TI |
5627 | alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl, |
5628 | alc882_fixups); | |
1a97b7f2 | 5629 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
ff818c24 | 5630 | |
1d045db9 TI |
5631 | alc_auto_parse_customize_define(codec); |
5632 | ||
1a97b7f2 TI |
5633 | /* automatic parse from the BIOS config */ |
5634 | err = alc882_parse_auto_config(codec); | |
5635 | if (err < 0) | |
5636 | goto error; | |
f6a92248 | 5637 | |
3e6179b8 TI |
5638 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
5639 | err = snd_hda_attach_beep_device(codec, 0x1); | |
e16fb6d1 TI |
5640 | if (err < 0) |
5641 | goto error; | |
1d045db9 | 5642 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
3e6179b8 | 5643 | } |
f6a92248 KY |
5644 | |
5645 | codec->patch_ops = alc_patch_ops; | |
bf1b0225 | 5646 | |
589876e2 TI |
5647 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
5648 | ||
f6a92248 | 5649 | return 0; |
e16fb6d1 TI |
5650 | |
5651 | error: | |
5652 | alc_free(codec); | |
5653 | return err; | |
f6a92248 KY |
5654 | } |
5655 | ||
df694daa | 5656 | |
df694daa | 5657 | /* |
1d045db9 | 5658 | * ALC262 support |
df694daa | 5659 | */ |
1d045db9 | 5660 | static int alc262_parse_auto_config(struct hda_codec *codec) |
df694daa | 5661 | { |
1d045db9 | 5662 | static const hda_nid_t alc262_ignore[] = { 0x1d, 0 }; |
3e6179b8 TI |
5663 | static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
5664 | return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids); | |
df694daa KY |
5665 | } |
5666 | ||
df694daa | 5667 | /* |
1d045db9 | 5668 | * Pin config fixes |
df694daa | 5669 | */ |
cfc9b06f | 5670 | enum { |
ea4e7af1 TI |
5671 | ALC262_FIXUP_FSC_H270, |
5672 | ALC262_FIXUP_HP_Z200, | |
5673 | ALC262_FIXUP_TYAN, | |
c470150c | 5674 | ALC262_FIXUP_LENOVO_3000, |
b42590b8 TI |
5675 | ALC262_FIXUP_BENQ, |
5676 | ALC262_FIXUP_BENQ_T31, | |
6e72aa5f | 5677 | ALC262_FIXUP_INV_DMIC, |
cfc9b06f TI |
5678 | }; |
5679 | ||
1d045db9 | 5680 | static const struct alc_fixup alc262_fixups[] = { |
ea4e7af1 | 5681 | [ALC262_FIXUP_FSC_H270] = { |
b5bfbc67 TI |
5682 | .type = ALC_FIXUP_PINS, |
5683 | .v.pins = (const struct alc_pincfg[]) { | |
1d045db9 TI |
5684 | { 0x14, 0x99130110 }, /* speaker */ |
5685 | { 0x15, 0x0221142f }, /* front HP */ | |
5686 | { 0x1b, 0x0121141f }, /* rear HP */ | |
5687 | { } | |
5688 | } | |
5689 | }, | |
ea4e7af1 | 5690 | [ALC262_FIXUP_HP_Z200] = { |
1d045db9 TI |
5691 | .type = ALC_FIXUP_PINS, |
5692 | .v.pins = (const struct alc_pincfg[]) { | |
5693 | { 0x16, 0x99130120 }, /* internal speaker */ | |
73413b12 TI |
5694 | { } |
5695 | } | |
cfc9b06f | 5696 | }, |
ea4e7af1 TI |
5697 | [ALC262_FIXUP_TYAN] = { |
5698 | .type = ALC_FIXUP_PINS, | |
5699 | .v.pins = (const struct alc_pincfg[]) { | |
5700 | { 0x14, 0x1993e1f0 }, /* int AUX */ | |
5701 | { } | |
5702 | } | |
5703 | }, | |
c470150c TI |
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 }, | |
b42590b8 TI |
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[]) { | |
c470150c TI |
5716 | { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, |
5717 | { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 }, | |
5718 | {} | |
5719 | } | |
5720 | }, | |
b42590b8 TI |
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 | }, | |
6e72aa5f TI |
5729 | [ALC262_FIXUP_INV_DMIC] = { |
5730 | .type = ALC_FIXUP_FUNC, | |
5731 | .v.func = alc_fixup_inv_dmic_0x12, | |
5732 | }, | |
cfc9b06f TI |
5733 | }; |
5734 | ||
1d045db9 | 5735 | static const struct snd_pci_quirk alc262_fixup_tbl[] = { |
ea4e7af1 | 5736 | SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200), |
3dcd3be3 TI |
5737 | SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ), |
5738 | SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ), | |
ea4e7af1 TI |
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), | |
c470150c | 5741 | SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000), |
b42590b8 TI |
5742 | SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ), |
5743 | SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31), | |
cfc9b06f TI |
5744 | {} |
5745 | }; | |
df694daa | 5746 | |
6e72aa5f TI |
5747 | static const struct alc_model_fixup alc262_fixup_models[] = { |
5748 | {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"}, | |
5749 | {} | |
5750 | }; | |
1d045db9 | 5751 | |
1d045db9 TI |
5752 | /* |
5753 | */ | |
1d045db9 | 5754 | static int patch_alc262(struct hda_codec *codec) |
df694daa KY |
5755 | { |
5756 | struct alc_spec *spec; | |
df694daa KY |
5757 | int err; |
5758 | ||
3de95173 TI |
5759 | err = alc_alloc_spec(codec, 0x0b); |
5760 | if (err < 0) | |
5761 | return err; | |
df694daa | 5762 | |
3de95173 | 5763 | spec = codec->spec; |
37c04207 | 5764 | spec->shared_mic_vref_pin = 0x18; |
1d045db9 TI |
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 | |
1d045db9 TI |
5778 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); |
5779 | ||
6e72aa5f TI |
5780 | alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl, |
5781 | alc262_fixups); | |
42399f7a | 5782 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
9c7f852e | 5783 | |
af741c15 TI |
5784 | alc_auto_parse_customize_define(codec); |
5785 | ||
42399f7a TI |
5786 | /* automatic parse from the BIOS config */ |
5787 | err = alc262_parse_auto_config(codec); | |
5788 | if (err < 0) | |
5789 | goto error; | |
df694daa | 5790 | |
3e6179b8 TI |
5791 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
5792 | err = snd_hda_attach_beep_device(codec, 0x1); | |
e16fb6d1 TI |
5793 | if (err < 0) |
5794 | goto error; | |
1d045db9 | 5795 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
3e6179b8 | 5796 | } |
2134ea4f | 5797 | |
df694daa | 5798 | codec->patch_ops = alc_patch_ops; |
1d045db9 TI |
5799 | spec->shutup = alc_eapd_shutup; |
5800 | ||
589876e2 TI |
5801 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
5802 | ||
1da177e4 | 5803 | return 0; |
e16fb6d1 TI |
5804 | |
5805 | error: | |
5806 | alc_free(codec); | |
5807 | return err; | |
1da177e4 LT |
5808 | } |
5809 | ||
f32610ed | 5810 | /* |
1d045db9 | 5811 | * ALC268 |
f32610ed | 5812 | */ |
1d045db9 TI |
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 | }, | |
f32610ed JS |
5821 | }; |
5822 | ||
1d045db9 TI |
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 | { } | |
f32610ed JS |
5827 | }; |
5828 | ||
1d045db9 TI |
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 | { } | |
f32610ed JS |
5835 | }; |
5836 | ||
6e72aa5f TI |
5837 | enum { |
5838 | ALC268_FIXUP_INV_DMIC, | |
cb766404 | 5839 | ALC268_FIXUP_HP_EAPD, |
6e72aa5f TI |
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 | }, | |
cb766404 TI |
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 | }, | |
6e72aa5f TI |
5854 | }; |
5855 | ||
5856 | static const struct alc_model_fixup alc268_fixup_models[] = { | |
5857 | {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"}, | |
cb766404 TI |
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), | |
6e72aa5f TI |
5867 | {} |
5868 | }; | |
5869 | ||
f32610ed JS |
5870 | /* |
5871 | * BIOS auto configuration | |
5872 | */ | |
1d045db9 | 5873 | static int alc268_parse_auto_config(struct hda_codec *codec) |
f32610ed | 5874 | { |
3e6179b8 | 5875 | static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
f32610ed | 5876 | struct alc_spec *spec = codec->spec; |
3e6179b8 TI |
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); | |
23d30f28 | 5881 | snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs); |
1d045db9 | 5882 | } |
1d045db9 | 5883 | } |
3e6179b8 | 5884 | return err; |
f32610ed JS |
5885 | } |
5886 | ||
1d045db9 TI |
5887 | /* |
5888 | */ | |
1d045db9 | 5889 | static int patch_alc268(struct hda_codec *codec) |
f32610ed JS |
5890 | { |
5891 | struct alc_spec *spec; | |
1d045db9 | 5892 | int i, has_beep, err; |
f32610ed | 5893 | |
1d045db9 | 5894 | /* ALC268 has no aa-loopback mixer */ |
3de95173 TI |
5895 | err = alc_alloc_spec(codec, 0); |
5896 | if (err < 0) | |
5897 | return err; | |
5898 | ||
5899 | spec = codec->spec; | |
1f0f4b80 | 5900 | |
cb766404 | 5901 | alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups); |
6e72aa5f TI |
5902 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
5903 | ||
6ebb8053 TI |
5904 | /* automatic parse from the BIOS config */ |
5905 | err = alc268_parse_auto_config(codec); | |
e16fb6d1 TI |
5906 | if (err < 0) |
5907 | goto error; | |
f32610ed | 5908 | |
1d045db9 TI |
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 | } | |
f32610ed | 5916 | |
1d045db9 TI |
5917 | if (has_beep) { |
5918 | err = snd_hda_attach_beep_device(codec, 0x1); | |
e16fb6d1 TI |
5919 | if (err < 0) |
5920 | goto error; | |
1d045db9 TI |
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)); | |
2f893286 KY |
5928 | } |
5929 | ||
f32610ed | 5930 | codec->patch_ops = alc_patch_ops; |
1c716153 | 5931 | spec->shutup = alc_eapd_shutup; |
1d045db9 | 5932 | |
6e72aa5f TI |
5933 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
5934 | ||
f32610ed | 5935 | return 0; |
e16fb6d1 TI |
5936 | |
5937 | error: | |
5938 | alc_free(codec); | |
5939 | return err; | |
f32610ed JS |
5940 | } |
5941 | ||
bc9f98a9 | 5942 | /* |
1d045db9 | 5943 | * ALC269 |
bc9f98a9 | 5944 | */ |
1d045db9 TI |
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 | |
bc9f98a9 KY |
5955 | }, |
5956 | }; | |
5957 | ||
1d045db9 TI |
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 */ | |
bc9f98a9 | 5964 | }; |
291702f0 | 5965 | |
1d045db9 TI |
5966 | /* different alc269-variants */ |
5967 | enum { | |
5968 | ALC269_TYPE_ALC269VA, | |
5969 | ALC269_TYPE_ALC269VB, | |
5970 | ALC269_TYPE_ALC269VC, | |
adcc70b2 | 5971 | ALC269_TYPE_ALC269VD, |
065380f0 KY |
5972 | ALC269_TYPE_ALC280, |
5973 | ALC269_TYPE_ALC282, | |
5974 | ALC269_TYPE_ALC284, | |
bc9f98a9 KY |
5975 | }; |
5976 | ||
5977 | /* | |
1d045db9 | 5978 | * BIOS auto configuration |
bc9f98a9 | 5979 | */ |
1d045db9 TI |
5980 | static int alc269_parse_auto_config(struct hda_codec *codec) |
5981 | { | |
1d045db9 | 5982 | static const hda_nid_t alc269_ignore[] = { 0x1d, 0 }; |
3e6179b8 TI |
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; | |
adcc70b2 KY |
5986 | const hda_nid_t *ssids; |
5987 | ||
5988 | switch (spec->codec_variant) { | |
5989 | case ALC269_TYPE_ALC269VA: | |
5990 | case ALC269_TYPE_ALC269VC: | |
065380f0 KY |
5991 | case ALC269_TYPE_ALC280: |
5992 | case ALC269_TYPE_ALC284: | |
adcc70b2 KY |
5993 | ssids = alc269va_ssids; |
5994 | break; | |
5995 | case ALC269_TYPE_ALC269VB: | |
5996 | case ALC269_TYPE_ALC269VD: | |
065380f0 | 5997 | case ALC269_TYPE_ALC282: |
adcc70b2 KY |
5998 | ssids = alc269_ssids; |
5999 | break; | |
6000 | default: | |
6001 | ssids = alc269_ssids; | |
6002 | break; | |
6003 | } | |
bc9f98a9 | 6004 | |
3e6179b8 | 6005 | return alc_parse_auto_config(codec, alc269_ignore, ssids); |
1d045db9 | 6006 | } |
bc9f98a9 | 6007 | |
1387e2d1 | 6008 | static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up) |
1d045db9 TI |
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 | } | |
291702f0 | 6017 | |
1d045db9 TI |
6018 | static void alc269_shutup(struct hda_codec *codec) |
6019 | { | |
adcc70b2 KY |
6020 | struct alc_spec *spec = codec->spec; |
6021 | ||
6022 | if (spec->codec_variant != ALC269_TYPE_ALC269VB) | |
6023 | return; | |
6024 | ||
1387e2d1 KY |
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) { | |
1d045db9 TI |
6029 | msleep(150); |
6030 | } | |
6031 | } | |
291702f0 | 6032 | |
2a43952a | 6033 | #ifdef CONFIG_PM |
1d045db9 TI |
6034 | static int alc269_resume(struct hda_codec *codec) |
6035 | { | |
adcc70b2 KY |
6036 | struct alc_spec *spec = codec->spec; |
6037 | ||
1387e2d1 KY |
6038 | if (spec->codec_variant == ALC269_TYPE_ALC269VB) |
6039 | alc269vb_toggle_power_output(codec, 0); | |
6040 | if (spec->codec_variant == ALC269_TYPE_ALC269VB && | |
adcc70b2 | 6041 | (alc_get_coef0(codec) & 0x00ff) == 0x018) { |
1d045db9 TI |
6042 | msleep(150); |
6043 | } | |
8c427226 | 6044 | |
1d045db9 | 6045 | codec->patch_ops.init(codec); |
f1d4e28b | 6046 | |
1387e2d1 KY |
6047 | if (spec->codec_variant == ALC269_TYPE_ALC269VB) |
6048 | alc269vb_toggle_power_output(codec, 1); | |
6049 | if (spec->codec_variant == ALC269_TYPE_ALC269VB && | |
adcc70b2 | 6050 | (alc_get_coef0(codec) & 0x00ff) == 0x017) { |
1d045db9 TI |
6051 | msleep(200); |
6052 | } | |
f1d4e28b | 6053 | |
1d045db9 TI |
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 | } | |
2a43952a | 6059 | #endif /* CONFIG_PM */ |
f1d4e28b | 6060 | |
108cc108 DH |
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 | ||
1d045db9 TI |
6070 | static void alc269_fixup_hweq(struct hda_codec *codec, |
6071 | const struct alc_fixup *fix, int action) | |
6072 | { | |
6073 | int coef; | |
f1d4e28b | 6074 | |
1d045db9 TI |
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 | } | |
f1d4e28b | 6080 | |
1d045db9 TI |
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; | |
f1d4e28b | 6090 | |
1d045db9 TI |
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 | } | |
f1d4e28b | 6097 | |
017f2a10 TI |
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 | ||
adabb3ec TI |
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 | ||
24519911 TI |
6129 | static void alc269_quanta_automute(struct hda_codec *codec) |
6130 | { | |
42cf0d01 | 6131 | update_outputs(codec); |
24519911 TI |
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 | ||
6d3cd5d4 DH |
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; | |
3bd7b644 | 6166 | if (action == ALC_FIXUP_ACT_PROBE) |
6d3cd5d4 | 6167 | spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook; |
6d3cd5d4 DH |
6168 | } |
6169 | ||
420b0feb TI |
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; | |
cdd03ced | 6175 | snd_hda_set_pin_ctl_cache(codec, 0x19, pinval); |
420b0feb TI |
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; | |
3bd7b644 | 6182 | if (action == ALC_FIXUP_ACT_PROBE) |
d2f344b5 | 6183 | spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook; |
420b0feb TI |
6184 | } |
6185 | ||
08a978db DR |
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 | } | |
693b613d | 6196 | |
1d045db9 TI |
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, | |
017f2a10 | 6206 | ALC269_FIXUP_PCM_44K, |
adabb3ec | 6207 | ALC269_FIXUP_STEREO_DMIC, |
24519911 TI |
6208 | ALC269_FIXUP_QUANTA_MUTE, |
6209 | ALC269_FIXUP_LIFEBOOK, | |
a4297b5d TI |
6210 | ALC269_FIXUP_AMIC, |
6211 | ALC269_FIXUP_DMIC, | |
6212 | ALC269VB_FIXUP_AMIC, | |
6213 | ALC269VB_FIXUP_DMIC, | |
6d3cd5d4 | 6214 | ALC269_FIXUP_MIC1_MUTE_LED, |
420b0feb | 6215 | ALC269_FIXUP_MIC2_MUTE_LED, |
693b613d | 6216 | ALC269_FIXUP_INV_DMIC, |
108cc108 DH |
6217 | ALC269_FIXUP_LENOVO_DOCK, |
6218 | ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT, | |
08a978db DR |
6219 | ALC271_FIXUP_AMIC_MIC2, |
6220 | ALC271_FIXUP_HP_GATE_MIC_JACK, | |
f1d4e28b KY |
6221 | }; |
6222 | ||
1d045db9 TI |
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 | } | |
f1d4e28b | 6230 | }, |
1d045db9 TI |
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] = { | |
23d30f28 TI |
6252 | .type = ALC_FIXUP_FUNC, |
6253 | .v.func = alc_fixup_sku_ignore, | |
1d045db9 TI |
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, | |
f1d4e28b | 6278 | }, |
017f2a10 TI |
6279 | [ALC269_FIXUP_PCM_44K] = { |
6280 | .type = ALC_FIXUP_FUNC, | |
6281 | .v.func = alc269_fixup_pcm_44k, | |
012e7eb1 DH |
6282 | .chained = true, |
6283 | .chain_id = ALC269_FIXUP_QUANTA_MUTE | |
017f2a10 | 6284 | }, |
adabb3ec TI |
6285 | [ALC269_FIXUP_STEREO_DMIC] = { |
6286 | .type = ALC_FIXUP_FUNC, | |
6287 | .v.func = alc269_fixup_stereo_dmic, | |
6288 | }, | |
24519911 TI |
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 | }, | |
a4297b5d TI |
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 | }, | |
2267ea97 | 6333 | [ALC269VB_FIXUP_DMIC] = { |
a4297b5d TI |
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 | }, | |
6d3cd5d4 DH |
6343 | [ALC269_FIXUP_MIC1_MUTE_LED] = { |
6344 | .type = ALC_FIXUP_FUNC, | |
6345 | .v.func = alc269_fixup_mic1_mute, | |
6346 | }, | |
420b0feb TI |
6347 | [ALC269_FIXUP_MIC2_MUTE_LED] = { |
6348 | .type = ALC_FIXUP_FUNC, | |
6349 | .v.func = alc269_fixup_mic2_mute, | |
6350 | }, | |
693b613d DH |
6351 | [ALC269_FIXUP_INV_DMIC] = { |
6352 | .type = ALC_FIXUP_FUNC, | |
6e72aa5f | 6353 | .v.func = alc_fixup_inv_dmic_0x12, |
693b613d | 6354 | }, |
108cc108 DH |
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 | }, | |
08a978db DR |
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 | }, | |
f1d4e28b KY |
6385 | }; |
6386 | ||
1d045db9 | 6387 | static const struct snd_pci_quirk alc269_fixup_tbl[] = { |
693b613d DH |
6388 | SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC), |
6389 | SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC), | |
420b0feb | 6390 | SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED), |
6d3cd5d4 | 6391 | SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED), |
5ac57550 | 6392 | SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC), |
148728f1 | 6393 | SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC), |
017f2a10 | 6394 | SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW), |
693b613d | 6395 | SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC), |
adabb3ec TI |
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), | |
1d045db9 TI |
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), | |
08a978db | 6406 | SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK), |
1d045db9 | 6407 | SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC), |
24519911 | 6408 | SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK), |
1d045db9 TI |
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), | |
707fba3f | 6414 | SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK), |
c8415a48 | 6415 | SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK), |
84f98fdf | 6416 | SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK), |
4407be6b | 6417 | SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK), |
108cc108 | 6418 | SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK), |
012e7eb1 | 6419 | SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K), |
1d045db9 | 6420 | SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD), |
a4297b5d | 6421 | |
a7f3eedc | 6422 | #if 0 |
a4297b5d TI |
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. | |
7d7eb9ea | 6427 | */ |
a4297b5d TI |
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), | |
a4297b5d TI |
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"}, | |
6e72aa5f TI |
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"}, | |
108cc108 | 6479 | {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"}, |
1d045db9 | 6480 | {} |
6dda9f4a KY |
6481 | }; |
6482 | ||
6dda9f4a | 6483 | |
546bb678 | 6484 | static void alc269_fill_coef(struct hda_codec *codec) |
1d045db9 | 6485 | { |
526af6eb | 6486 | struct alc_spec *spec = codec->spec; |
1d045db9 | 6487 | int val; |
ebb83eeb | 6488 | |
526af6eb | 6489 | if (spec->codec_variant != ALC269_TYPE_ALC269VB) |
546bb678 | 6490 | return; |
526af6eb | 6491 | |
1bb7e43e | 6492 | if ((alc_get_coef0(codec) & 0x00ff) < 0x015) { |
1d045db9 TI |
6493 | alc_write_coef_idx(codec, 0xf, 0x960b); |
6494 | alc_write_coef_idx(codec, 0xe, 0x8817); | |
6495 | } | |
ebb83eeb | 6496 | |
1bb7e43e | 6497 | if ((alc_get_coef0(codec) & 0x00ff) == 0x016) { |
1d045db9 TI |
6498 | alc_write_coef_idx(codec, 0xf, 0x960b); |
6499 | alc_write_coef_idx(codec, 0xe, 0x8814); | |
6500 | } | |
ebb83eeb | 6501 | |
1bb7e43e | 6502 | if ((alc_get_coef0(codec) & 0x00ff) == 0x017) { |
1d045db9 TI |
6503 | val = alc_read_coef_idx(codec, 0x04); |
6504 | /* Power up output pin */ | |
6505 | alc_write_coef_idx(codec, 0x04, val | (1<<11)); | |
6506 | } | |
ebb83eeb | 6507 | |
1bb7e43e | 6508 | if ((alc_get_coef0(codec) & 0x00ff) == 0x018) { |
1d045db9 TI |
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 | } | |
ebb83eeb | 6520 | |
1d045db9 TI |
6521 | val = alc_read_coef_idx(codec, 0xd); /* Class D */ |
6522 | alc_write_coef_idx(codec, 0xd, val | (1<<14)); | |
bc9f98a9 | 6523 | |
1d045db9 TI |
6524 | val = alc_read_coef_idx(codec, 0x4); /* HP */ |
6525 | alc_write_coef_idx(codec, 0x4, val | (1<<11)); | |
1d045db9 | 6526 | } |
a7f2371f | 6527 | |
1d045db9 TI |
6528 | /* |
6529 | */ | |
1d045db9 TI |
6530 | static int patch_alc269(struct hda_codec *codec) |
6531 | { | |
6532 | struct alc_spec *spec; | |
3de95173 | 6533 | int err; |
f1d4e28b | 6534 | |
3de95173 | 6535 | err = alc_alloc_spec(codec, 0x0b); |
e16fb6d1 | 6536 | if (err < 0) |
3de95173 TI |
6537 | return err; |
6538 | ||
6539 | spec = codec->spec; | |
37c04207 | 6540 | spec->shared_mic_vref_pin = 0x18; |
e16fb6d1 | 6541 | |
9f720bb9 HRK |
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 | ||
065380f0 KY |
6548 | switch (codec->vendor_id) { |
6549 | case 0x10ec0269: | |
1d045db9 | 6550 | spec->codec_variant = ALC269_TYPE_ALC269VA; |
1bb7e43e TI |
6551 | switch (alc_get_coef0(codec) & 0x00f0) { |
6552 | case 0x0010: | |
1d045db9 | 6553 | if (codec->bus->pci->subsystem_vendor == 0x1025 && |
e16fb6d1 | 6554 | spec->cdefine.platform_type == 1) |
20ca0c35 | 6555 | err = alc_codec_rename(codec, "ALC271X"); |
1d045db9 | 6556 | spec->codec_variant = ALC269_TYPE_ALC269VB; |
1bb7e43e TI |
6557 | break; |
6558 | case 0x0020: | |
e16fb6d1 TI |
6559 | if (codec->bus->pci->subsystem_vendor == 0x17aa && |
6560 | codec->bus->pci->subsystem_device == 0x21f3) | |
20ca0c35 | 6561 | err = alc_codec_rename(codec, "ALC3202"); |
1d045db9 | 6562 | spec->codec_variant = ALC269_TYPE_ALC269VC; |
1bb7e43e | 6563 | break; |
adcc70b2 KY |
6564 | case 0x0030: |
6565 | spec->codec_variant = ALC269_TYPE_ALC269VD; | |
6566 | break; | |
1bb7e43e | 6567 | default: |
1d045db9 | 6568 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
1bb7e43e | 6569 | } |
e16fb6d1 TI |
6570 | if (err < 0) |
6571 | goto error; | |
546bb678 | 6572 | spec->init_hook = alc269_fill_coef; |
1d045db9 | 6573 | alc269_fill_coef(codec); |
065380f0 KY |
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; | |
1d045db9 | 6588 | } |
6dda9f4a | 6589 | |
a4297b5d TI |
6590 | /* automatic parse from the BIOS config */ |
6591 | err = alc269_parse_auto_config(codec); | |
e16fb6d1 TI |
6592 | if (err < 0) |
6593 | goto error; | |
6dda9f4a | 6594 | |
3e6179b8 TI |
6595 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
6596 | err = snd_hda_attach_beep_device(codec, 0x1); | |
e16fb6d1 TI |
6597 | if (err < 0) |
6598 | goto error; | |
1d045db9 | 6599 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); |
3e6179b8 | 6600 | } |
f1d4e28b | 6601 | |
1d045db9 | 6602 | codec->patch_ops = alc_patch_ops; |
2a43952a | 6603 | #ifdef CONFIG_PM |
1d045db9 TI |
6604 | codec->patch_ops.resume = alc269_resume; |
6605 | #endif | |
1d045db9 | 6606 | spec->shutup = alc269_shutup; |
ebb83eeb | 6607 | |
589876e2 TI |
6608 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
6609 | ||
1d045db9 | 6610 | return 0; |
e16fb6d1 TI |
6611 | |
6612 | error: | |
6613 | alc_free(codec); | |
6614 | return err; | |
1d045db9 | 6615 | } |
f1d4e28b | 6616 | |
1d045db9 TI |
6617 | /* |
6618 | * ALC861 | |
6619 | */ | |
622e84cd | 6620 | |
1d045db9 | 6621 | static int alc861_parse_auto_config(struct hda_codec *codec) |
6dda9f4a | 6622 | { |
1d045db9 | 6623 | static const hda_nid_t alc861_ignore[] = { 0x1d, 0 }; |
3e6179b8 TI |
6624 | static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 }; |
6625 | return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids); | |
604401a9 TI |
6626 | } |
6627 | ||
1d045db9 TI |
6628 | /* Pin config fixes */ |
6629 | enum { | |
e652f4c8 TI |
6630 | ALC861_FIXUP_FSC_AMILO_PI1505, |
6631 | ALC861_FIXUP_AMP_VREF_0F, | |
6632 | ALC861_FIXUP_NO_JACK_DETECT, | |
6633 | ALC861_FIXUP_ASUS_A6RP, | |
1d045db9 | 6634 | }; |
7085ec12 | 6635 | |
31150f23 TI |
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; | |
cdd03ced | 6650 | snd_hda_set_pin_ctl(codec, 0x0f, val); |
31150f23 TI |
6651 | spec->keep_vref_in_automute = 1; |
6652 | } | |
6653 | ||
e652f4c8 TI |
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; | |
7d7eb9ea | 6660 | } |
e652f4c8 | 6661 | |
1d045db9 | 6662 | static const struct alc_fixup alc861_fixups[] = { |
e652f4c8 | 6663 | [ALC861_FIXUP_FSC_AMILO_PI1505] = { |
1d045db9 TI |
6664 | .type = ALC_FIXUP_PINS, |
6665 | .v.pins = (const struct alc_pincfg[]) { | |
6666 | { 0x0b, 0x0221101f }, /* HP */ | |
6667 | { 0x0f, 0x90170310 }, /* speaker */ | |
6668 | { } | |
6669 | } | |
6670 | }, | |
e652f4c8 | 6671 | [ALC861_FIXUP_AMP_VREF_0F] = { |
31150f23 TI |
6672 | .type = ALC_FIXUP_FUNC, |
6673 | .v.func = alc861_fixup_asus_amp_vref_0f, | |
3b25eb69 | 6674 | }, |
e652f4c8 TI |
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 | } | |
1d045db9 | 6685 | }; |
7085ec12 | 6686 | |
1d045db9 | 6687 | static const struct snd_pci_quirk alc861_fixup_tbl[] = { |
e652f4c8 TI |
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), | |
1d045db9 TI |
6694 | {} |
6695 | }; | |
3af9ee6b | 6696 | |
1d045db9 TI |
6697 | /* |
6698 | */ | |
1d045db9 | 6699 | static int patch_alc861(struct hda_codec *codec) |
7085ec12 | 6700 | { |
1d045db9 | 6701 | struct alc_spec *spec; |
1d045db9 | 6702 | int err; |
7085ec12 | 6703 | |
3de95173 TI |
6704 | err = alc_alloc_spec(codec, 0x15); |
6705 | if (err < 0) | |
6706 | return err; | |
1d045db9 | 6707 | |
3de95173 | 6708 | spec = codec->spec; |
1d045db9 | 6709 | |
cb4e4824 TI |
6710 | alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); |
6711 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
3af9ee6b | 6712 | |
cb4e4824 TI |
6713 | /* automatic parse from the BIOS config */ |
6714 | err = alc861_parse_auto_config(codec); | |
e16fb6d1 TI |
6715 | if (err < 0) |
6716 | goto error; | |
3af9ee6b | 6717 | |
3e6179b8 TI |
6718 | if (!spec->no_analog) { |
6719 | err = snd_hda_attach_beep_device(codec, 0x23); | |
e16fb6d1 TI |
6720 | if (err < 0) |
6721 | goto error; | |
3e6179b8 TI |
6722 | set_beep_amp(spec, 0x23, 0, HDA_OUTPUT); |
6723 | } | |
7085ec12 | 6724 | |
1d045db9 | 6725 | codec->patch_ops = alc_patch_ops; |
83012a7c | 6726 | #ifdef CONFIG_PM |
cb4e4824 | 6727 | spec->power_hook = alc_power_eapd; |
1d045db9 TI |
6728 | #endif |
6729 | ||
589876e2 TI |
6730 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
6731 | ||
1d045db9 | 6732 | return 0; |
e16fb6d1 TI |
6733 | |
6734 | error: | |
6735 | alc_free(codec); | |
6736 | return err; | |
7085ec12 TI |
6737 | } |
6738 | ||
1d045db9 TI |
6739 | /* |
6740 | * ALC861-VD support | |
6741 | * | |
6742 | * Based on ALC882 | |
6743 | * | |
6744 | * In addition, an independent DAC | |
6745 | */ | |
1d045db9 | 6746 | static int alc861vd_parse_auto_config(struct hda_codec *codec) |
bc9f98a9 | 6747 | { |
1d045db9 | 6748 | static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 }; |
3e6179b8 TI |
6749 | static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
6750 | return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids); | |
ce764ab2 TI |
6751 | } |
6752 | ||
1d045db9 | 6753 | enum { |
8fdcb6fe TI |
6754 | ALC660VD_FIX_ASUS_GPIO1, |
6755 | ALC861VD_FIX_DALLAS, | |
1d045db9 | 6756 | }; |
ce764ab2 | 6757 | |
8fdcb6fe TI |
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) { | |
b78562b1 TI |
6763 | snd_hda_override_pin_caps(codec, 0x18, 0x00000734); |
6764 | snd_hda_override_pin_caps(codec, 0x19, 0x0000073c); | |
8fdcb6fe TI |
6765 | } |
6766 | } | |
6767 | ||
1d045db9 TI |
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[]) { | |
8fdcb6fe | 6772 | /* reset GPIO1 */ |
1d045db9 TI |
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 | }, | |
8fdcb6fe TI |
6779 | [ALC861VD_FIX_DALLAS] = { |
6780 | .type = ALC_FIXUP_FUNC, | |
6781 | .v.func = alc861vd_fixup_dallas, | |
6782 | }, | |
1d045db9 | 6783 | }; |
ce764ab2 | 6784 | |
1d045db9 | 6785 | static const struct snd_pci_quirk alc861vd_fixup_tbl[] = { |
8fdcb6fe | 6786 | SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS), |
1d045db9 | 6787 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1), |
8fdcb6fe | 6788 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS), |
1d045db9 TI |
6789 | {} |
6790 | }; | |
ce764ab2 | 6791 | |
1d045db9 TI |
6792 | /* |
6793 | */ | |
1d045db9 | 6794 | static int patch_alc861vd(struct hda_codec *codec) |
ce764ab2 | 6795 | { |
1d045db9 | 6796 | struct alc_spec *spec; |
cb4e4824 | 6797 | int err; |
ce764ab2 | 6798 | |
3de95173 TI |
6799 | err = alc_alloc_spec(codec, 0x0b); |
6800 | if (err < 0) | |
6801 | return err; | |
1d045db9 | 6802 | |
3de95173 | 6803 | spec = codec->spec; |
1d045db9 | 6804 | |
cb4e4824 TI |
6805 | alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); |
6806 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
1d045db9 | 6807 | |
cb4e4824 TI |
6808 | /* automatic parse from the BIOS config */ |
6809 | err = alc861vd_parse_auto_config(codec); | |
e16fb6d1 TI |
6810 | if (err < 0) |
6811 | goto error; | |
ce764ab2 | 6812 | |
3e6179b8 TI |
6813 | if (!spec->no_analog) { |
6814 | err = snd_hda_attach_beep_device(codec, 0x23); | |
e16fb6d1 TI |
6815 | if (err < 0) |
6816 | goto error; | |
3e6179b8 TI |
6817 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
6818 | } | |
1d045db9 | 6819 | |
1d045db9 TI |
6820 | codec->patch_ops = alc_patch_ops; |
6821 | ||
1d045db9 | 6822 | spec->shutup = alc_eapd_shutup; |
1d045db9 | 6823 | |
589876e2 TI |
6824 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
6825 | ||
ce764ab2 | 6826 | return 0; |
e16fb6d1 TI |
6827 | |
6828 | error: | |
6829 | alc_free(codec); | |
6830 | return err; | |
ce764ab2 TI |
6831 | } |
6832 | ||
1d045db9 TI |
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 | */ | |
1d045db9 TI |
6844 | |
6845 | /* | |
6846 | * BIOS auto configuration | |
6847 | */ | |
6848 | ||
bc9f98a9 KY |
6849 | static int alc662_parse_auto_config(struct hda_codec *codec) |
6850 | { | |
4c6d72d1 | 6851 | static const hda_nid_t alc662_ignore[] = { 0x1d, 0 }; |
3e6179b8 TI |
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; | |
ee979a14 | 6855 | |
6227cdce KY |
6856 | if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 || |
6857 | codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670) | |
3e6179b8 | 6858 | ssids = alc663_ssids; |
6227cdce | 6859 | else |
3e6179b8 TI |
6860 | ssids = alc662_ssids; |
6861 | return alc_parse_auto_config(codec, alc662_ignore, ssids); | |
bc9f98a9 KY |
6862 | } |
6863 | ||
6be7948f | 6864 | static void alc272_fixup_mario(struct hda_codec *codec, |
b5bfbc67 | 6865 | const struct alc_fixup *fix, int action) |
6fc398cb | 6866 | { |
b5bfbc67 | 6867 | if (action != ALC_FIXUP_ACT_PROBE) |
6fc398cb | 6868 | return; |
6be7948f TB |
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 | ||
6cb3b707 | 6878 | enum { |
2df03514 | 6879 | ALC662_FIXUP_ASPIRE, |
6cb3b707 | 6880 | ALC662_FIXUP_IDEAPAD, |
6be7948f | 6881 | ALC272_FIXUP_MARIO, |
d2ebd479 | 6882 | ALC662_FIXUP_CZC_P10T, |
94024cd1 | 6883 | ALC662_FIXUP_SKU_IGNORE, |
e59ea3ed | 6884 | ALC662_FIXUP_HP_RP5800, |
53c334ad TI |
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, | |
1565cc35 | 6893 | ALC662_FIXUP_NO_JACK_DETECT, |
edfe3bfc | 6894 | ALC662_FIXUP_ZOTAC_Z68, |
125821ae | 6895 | ALC662_FIXUP_INV_DMIC, |
6cb3b707 DH |
6896 | }; |
6897 | ||
6898 | static const struct alc_fixup alc662_fixups[] = { | |
2df03514 | 6899 | [ALC662_FIXUP_ASPIRE] = { |
b5bfbc67 TI |
6900 | .type = ALC_FIXUP_PINS, |
6901 | .v.pins = (const struct alc_pincfg[]) { | |
2df03514 DC |
6902 | { 0x15, 0x99130112 }, /* subwoofer */ |
6903 | { } | |
6904 | } | |
6905 | }, | |
6cb3b707 | 6906 | [ALC662_FIXUP_IDEAPAD] = { |
b5bfbc67 TI |
6907 | .type = ALC_FIXUP_PINS, |
6908 | .v.pins = (const struct alc_pincfg[]) { | |
6cb3b707 DH |
6909 | { 0x17, 0x99130112 }, /* subwoofer */ |
6910 | { } | |
6911 | } | |
6912 | }, | |
6be7948f | 6913 | [ALC272_FIXUP_MARIO] = { |
b5bfbc67 TI |
6914 | .type = ALC_FIXUP_FUNC, |
6915 | .v.func = alc272_fixup_mario, | |
d2ebd479 AA |
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 | }, | |
94024cd1 | 6924 | [ALC662_FIXUP_SKU_IGNORE] = { |
23d30f28 TI |
6925 | .type = ALC_FIXUP_FUNC, |
6926 | .v.func = alc_fixup_sku_ignore, | |
c6b35874 | 6927 | }, |
e59ea3ed TI |
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 | }, | |
53c334ad TI |
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] = { | |
2996bdba TI |
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 | }, | |
53c334ad TI |
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 | |
2996bdba | 7040 | }, |
1565cc35 TI |
7041 | [ALC662_FIXUP_NO_JACK_DETECT] = { |
7042 | .type = ALC_FIXUP_FUNC, | |
7043 | .v.func = alc_fixup_no_jack_detect, | |
7044 | }, | |
edfe3bfc DH |
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 | }, | |
125821ae TI |
7052 | [ALC662_FIXUP_INV_DMIC] = { |
7053 | .type = ALC_FIXUP_FUNC, | |
6e72aa5f | 7054 | .v.func = alc_fixup_inv_dmic_0x12, |
125821ae | 7055 | }, |
6cb3b707 DH |
7056 | }; |
7057 | ||
a9111321 | 7058 | static const struct snd_pci_quirk alc662_fixup_tbl[] = { |
53c334ad | 7059 | SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2), |
a6c47a85 | 7060 | SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE), |
94024cd1 | 7061 | SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE), |
125821ae | 7062 | SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC), |
2df03514 | 7063 | SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE), |
e59ea3ed | 7064 | SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), |
1565cc35 | 7065 | SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT), |
53c334ad | 7066 | SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2), |
a0e90acc | 7067 | SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD), |
d4118588 | 7068 | SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD), |
6cb3b707 | 7069 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD), |
edfe3bfc | 7070 | SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68), |
d2ebd479 | 7071 | SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T), |
53c334ad TI |
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. | |
7d7eb9ea | 7078 | */ |
53c334ad TI |
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 | |
6cb3b707 DH |
7130 | {} |
7131 | }; | |
7132 | ||
6be7948f TB |
7133 | static const struct alc_model_fixup alc662_fixup_models[] = { |
7134 | {.id = ALC272_FIXUP_MARIO, .name = "mario"}, | |
53c334ad TI |
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"}, | |
6e72aa5f | 7143 | {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"}, |
6be7948f TB |
7144 | {} |
7145 | }; | |
6cb3b707 | 7146 | |
8663ff75 KY |
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 | } | |
6cb3b707 | 7172 | |
1d045db9 TI |
7173 | /* |
7174 | */ | |
bc9f98a9 KY |
7175 | static int patch_alc662(struct hda_codec *codec) |
7176 | { | |
7177 | struct alc_spec *spec; | |
3de95173 | 7178 | int err; |
bc9f98a9 | 7179 | |
3de95173 TI |
7180 | err = alc_alloc_spec(codec, 0x0b); |
7181 | if (err < 0) | |
7182 | return err; | |
bc9f98a9 | 7183 | |
3de95173 | 7184 | spec = codec->spec; |
1f0f4b80 | 7185 | |
53c334ad TI |
7186 | /* handle multiple HPs as is */ |
7187 | spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; | |
7188 | ||
2c3bf9ab TI |
7189 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
7190 | ||
8663ff75 KY |
7191 | spec->init_hook = alc662_fill_coef; |
7192 | alc662_fill_coef(codec); | |
7193 | ||
8e5a0509 TI |
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 | ||
1bb7e43e | 7200 | if ((alc_get_coef0(codec) & (1 << 14)) && |
e16fb6d1 TI |
7201 | codec->bus->pci->subsystem_vendor == 0x1025 && |
7202 | spec->cdefine.platform_type == 1) { | |
7203 | if (alc_codec_rename(codec, "ALC272X") < 0) | |
7204 | goto error; | |
20ca0c35 | 7205 | } |
274693f3 | 7206 | |
b9c5106c TI |
7207 | /* automatic parse from the BIOS config */ |
7208 | err = alc662_parse_auto_config(codec); | |
e16fb6d1 TI |
7209 | if (err < 0) |
7210 | goto error; | |
bc9f98a9 | 7211 | |
3e6179b8 TI |
7212 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
7213 | err = snd_hda_attach_beep_device(codec, 0x1); | |
e16fb6d1 TI |
7214 | if (err < 0) |
7215 | goto error; | |
da00c244 KY |
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 | } | |
cec27c89 | 7229 | } |
2134ea4f | 7230 | |
bc9f98a9 | 7231 | codec->patch_ops = alc_patch_ops; |
1c716153 | 7232 | spec->shutup = alc_eapd_shutup; |
6cb3b707 | 7233 | |
589876e2 TI |
7234 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
7235 | ||
bc9f98a9 | 7236 | return 0; |
801f49d3 | 7237 | |
e16fb6d1 TI |
7238 | error: |
7239 | alc_free(codec); | |
7240 | return err; | |
b478b998 KY |
7241 | } |
7242 | ||
d1eb57f4 KY |
7243 | /* |
7244 | * ALC680 support | |
7245 | */ | |
d1eb57f4 | 7246 | |
d1eb57f4 KY |
7247 | static int alc680_parse_auto_config(struct hda_codec *codec) |
7248 | { | |
3e6179b8 | 7249 | return alc_parse_auto_config(codec, NULL, NULL); |
d1eb57f4 KY |
7250 | } |
7251 | ||
d1eb57f4 | 7252 | /* |
d1eb57f4 | 7253 | */ |
d1eb57f4 KY |
7254 | static int patch_alc680(struct hda_codec *codec) |
7255 | { | |
d1eb57f4 KY |
7256 | int err; |
7257 | ||
1f0f4b80 | 7258 | /* ALC680 has no aa-loopback mixer */ |
3de95173 TI |
7259 | err = alc_alloc_spec(codec, 0); |
7260 | if (err < 0) | |
7261 | return err; | |
1f0f4b80 | 7262 | |
1ebec5f2 TI |
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; | |
d1eb57f4 KY |
7268 | } |
7269 | ||
d1eb57f4 | 7270 | codec->patch_ops = alc_patch_ops; |
d1eb57f4 KY |
7271 | |
7272 | return 0; | |
7273 | } | |
7274 | ||
1da177e4 LT |
7275 | /* |
7276 | * patch entries | |
7277 | */ | |
a9111321 | 7278 | static const struct hda_codec_preset snd_hda_preset_realtek[] = { |
296f0338 | 7279 | { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 }, |
1da177e4 | 7280 | { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 }, |
df694daa | 7281 | { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 }, |
f6a92248 | 7282 | { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 }, |
a361d84b | 7283 | { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 }, |
f6a92248 | 7284 | { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 }, |
ebb83eeb | 7285 | { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 }, |
01afd41f | 7286 | { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 }, |
ebb83eeb | 7287 | { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 }, |
296f0338 | 7288 | { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 }, |
befae82e | 7289 | { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 }, |
4e01ec63 | 7290 | { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 }, |
7ff34ad8 | 7291 | { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 }, |
065380f0 | 7292 | { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 }, |
7ff34ad8 | 7293 | { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 }, |
af02dde8 | 7294 | { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 }, |
f32610ed | 7295 | { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660", |
bc9f98a9 | 7296 | .patch = patch_alc861 }, |
f32610ed JS |
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 }, | |
bc9f98a9 | 7300 | { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2", |
4953550a | 7301 | .patch = patch_alc882 }, |
bc9f98a9 KY |
7302 | { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1", |
7303 | .patch = patch_alc662 }, | |
cc667a72 DH |
7304 | { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3", |
7305 | .patch = patch_alc662 }, | |
6dda9f4a | 7306 | { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 }, |
cec27c89 | 7307 | { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 }, |
19a62823 | 7308 | { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 }, |
6227cdce | 7309 | { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 }, |
d1eb57f4 | 7310 | { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 }, |
f32610ed | 7311 | { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, |
1da177e4 | 7312 | { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, |
4953550a | 7313 | { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 }, |
669faba2 | 7314 | { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A", |
4953550a | 7315 | .patch = patch_alc882 }, |
cb308f97 | 7316 | { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A", |
4953550a | 7317 | .patch = patch_alc882 }, |
df694daa | 7318 | { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, |
e16fb6d1 | 7319 | { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 }, |
4442608d | 7320 | { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", |
4953550a | 7321 | .patch = patch_alc882 }, |
e16fb6d1 | 7322 | { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 }, |
4953550a | 7323 | { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 }, |
274693f3 | 7324 | { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 }, |
e16fb6d1 | 7325 | { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 }, |
19a62823 | 7326 | { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 }, |
1da177e4 LT |
7327 | {} /* terminator */ |
7328 | }; | |
1289e9e8 TI |
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) |