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