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