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