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