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