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