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