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