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