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