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