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