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