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