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