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