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