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