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