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