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