]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Universal Interface for Intel High Definition Audio Codec | |
3 | * | |
1d045db9 | 4 | * HD audio interface patch for Realtek ALC codecs |
1da177e4 | 5 | * |
df694daa KY |
6 | * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw> |
7 | * PeiSen Hou <pshou@realtek.com.tw> | |
1da177e4 | 8 | * Takashi Iwai <tiwai@suse.de> |
7cf51e48 | 9 | * Jonathan Woithe <jwoithe@physics.adelaide.edu.au> |
1da177e4 LT |
10 | * |
11 | * This driver is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or | |
14 | * (at your option) any later version. | |
15 | * | |
16 | * This driver is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 | */ | |
25 | ||
1da177e4 LT |
26 | #include <linux/init.h> |
27 | #include <linux/delay.h> | |
28 | #include <linux/slab.h> | |
29 | #include <linux/pci.h> | |
30 | #include <sound/core.h> | |
9ad0e496 | 31 | #include <sound/jack.h> |
1da177e4 LT |
32 | #include "hda_codec.h" |
33 | #include "hda_local.h" | |
680cd536 | 34 | #include "hda_beep.h" |
1da177e4 | 35 | |
1d045db9 TI |
36 | /* unsol event tags */ |
37 | #define ALC_FRONT_EVENT 0x01 | |
38 | #define ALC_DCVOL_EVENT 0x02 | |
39 | #define ALC_HP_EVENT 0x04 | |
40 | #define ALC_MIC_EVENT 0x08 | |
d4a86d81 | 41 | |
df694daa KY |
42 | /* for GPIO Poll */ |
43 | #define GPIO_MASK 0x03 | |
44 | ||
4a79ba34 TI |
45 | /* extra amp-initialization sequence types */ |
46 | enum { | |
47 | ALC_INIT_NONE, | |
48 | ALC_INIT_DEFAULT, | |
49 | ALC_INIT_GPIO1, | |
50 | ALC_INIT_GPIO2, | |
51 | ALC_INIT_GPIO3, | |
52 | }; | |
53 | ||
da00c244 KY |
54 | struct alc_customize_define { |
55 | unsigned int sku_cfg; | |
56 | unsigned char port_connectivity; | |
57 | unsigned char check_sum; | |
58 | unsigned char customization; | |
59 | unsigned char external_amp; | |
60 | unsigned int enable_pcbeep:1; | |
61 | unsigned int platform_type:1; | |
62 | unsigned int swap:1; | |
63 | unsigned int override:1; | |
90622917 | 64 | unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */ |
da00c244 KY |
65 | }; |
66 | ||
b5bfbc67 TI |
67 | struct alc_fixup; |
68 | ||
ce764ab2 TI |
69 | struct alc_multi_io { |
70 | hda_nid_t pin; /* multi-io widget pin NID */ | |
71 | hda_nid_t dac; /* DAC to be connected */ | |
72 | unsigned int ctl_in; /* cached input-pin control value */ | |
73 | }; | |
74 | ||
d922b51d | 75 | enum { |
3b8510ce TI |
76 | ALC_AUTOMUTE_PIN, /* change the pin control */ |
77 | ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */ | |
78 | ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */ | |
d922b51d TI |
79 | }; |
80 | ||
1da177e4 LT |
81 | struct alc_spec { |
82 | /* codec parameterization */ | |
a9111321 | 83 | const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ |
1da177e4 | 84 | unsigned int num_mixers; |
a9111321 | 85 | const struct snd_kcontrol_new *cap_mixer; /* capture mixer */ |
45bdd1c1 | 86 | unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ |
1da177e4 | 87 | |
2d9c6482 | 88 | const struct hda_verb *init_verbs[10]; /* initialization verbs |
9c7f852e TI |
89 | * don't forget NULL |
90 | * termination! | |
e9edcee0 TI |
91 | */ |
92 | unsigned int num_init_verbs; | |
1da177e4 | 93 | |
aa563af7 | 94 | char stream_name_analog[32]; /* analog PCM stream */ |
a9111321 TI |
95 | const struct hda_pcm_stream *stream_analog_playback; |
96 | const struct hda_pcm_stream *stream_analog_capture; | |
97 | const struct hda_pcm_stream *stream_analog_alt_playback; | |
98 | const struct hda_pcm_stream *stream_analog_alt_capture; | |
1da177e4 | 99 | |
aa563af7 | 100 | char stream_name_digital[32]; /* digital PCM stream */ |
a9111321 TI |
101 | const struct hda_pcm_stream *stream_digital_playback; |
102 | const struct hda_pcm_stream *stream_digital_capture; | |
1da177e4 LT |
103 | |
104 | /* playback */ | |
16ded525 TI |
105 | struct hda_multi_out multiout; /* playback set-up |
106 | * max_channels, dacs must be set | |
107 | * dig_out_nid and hp_nid are optional | |
108 | */ | |
6330079f | 109 | hda_nid_t alt_dac_nid; |
6a05ac4a | 110 | hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */ |
8c441982 | 111 | int dig_out_type; |
1da177e4 LT |
112 | |
113 | /* capture */ | |
114 | unsigned int num_adc_nids; | |
4c6d72d1 TI |
115 | const hda_nid_t *adc_nids; |
116 | const hda_nid_t *capsrc_nids; | |
16ded525 | 117 | hda_nid_t dig_in_nid; /* digital-in NID; optional */ |
1f0f4b80 | 118 | hda_nid_t mixer_nid; /* analog-mixer NID */ |
1da177e4 | 119 | |
840b64c0 | 120 | /* capture setup for dynamic dual-adc switch */ |
840b64c0 TI |
121 | hda_nid_t cur_adc; |
122 | unsigned int cur_adc_stream_tag; | |
123 | unsigned int cur_adc_format; | |
124 | ||
1da177e4 | 125 | /* capture source */ |
a1e8d2da | 126 | unsigned int num_mux_defs; |
1da177e4 LT |
127 | const struct hda_input_mux *input_mux; |
128 | unsigned int cur_mux[3]; | |
21268961 TI |
129 | hda_nid_t ext_mic_pin; |
130 | hda_nid_t dock_mic_pin; | |
131 | hda_nid_t int_mic_pin; | |
1da177e4 LT |
132 | |
133 | /* channel model */ | |
d2a6d7dc | 134 | const struct hda_channel_mode *channel_mode; |
1da177e4 | 135 | int num_channel_mode; |
4e195a7b | 136 | int need_dac_fix; |
3b315d70 HM |
137 | int const_channel_count; |
138 | int ext_channel_count; | |
1da177e4 LT |
139 | |
140 | /* PCM information */ | |
4c5186ed | 141 | struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */ |
41e41f1f | 142 | |
e9edcee0 TI |
143 | /* dynamic controls, init_verbs and input_mux */ |
144 | struct auto_pin_cfg autocfg; | |
da00c244 | 145 | struct alc_customize_define cdefine; |
603c4019 | 146 | struct snd_array kctls; |
61b9b9b1 | 147 | struct hda_input_mux private_imux[3]; |
41923e44 | 148 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
4953550a TI |
149 | hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS]; |
150 | hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS]; | |
21268961 TI |
151 | hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS]; |
152 | unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS]; | |
153 | int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */ | |
834be88d | 154 | |
ae6b813a TI |
155 | /* hooks */ |
156 | void (*init_hook)(struct hda_codec *codec); | |
157 | void (*unsol_event)(struct hda_codec *codec, unsigned int res); | |
f5de24b0 | 158 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
c97259df | 159 | void (*power_hook)(struct hda_codec *codec); |
f5de24b0 | 160 | #endif |
1c716153 | 161 | void (*shutup)(struct hda_codec *codec); |
ae6b813a | 162 | |
834be88d | 163 | /* for pin sensing */ |
834be88d | 164 | unsigned int jack_present: 1; |
e6a5e1b7 | 165 | unsigned int line_jack_present:1; |
e9427969 | 166 | unsigned int master_mute:1; |
6c819492 | 167 | unsigned int auto_mic:1; |
21268961 | 168 | unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */ |
d922b51d | 169 | unsigned int automute:1; /* HP automute enabled */ |
e6a5e1b7 TI |
170 | unsigned int detect_line:1; /* Line-out detection enabled */ |
171 | unsigned int automute_lines:1; /* automute line-out as well */ | |
ae8a60a5 | 172 | unsigned int automute_hp_lo:1; /* both HP and LO available */ |
cb53c626 | 173 | |
e64f14f4 TI |
174 | /* other flags */ |
175 | unsigned int no_analog :1; /* digital I/O only */ | |
21268961 | 176 | unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */ |
584c0c4c | 177 | unsigned int single_input_src:1; |
d6cc9fab | 178 | unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */ |
d922b51d TI |
179 | |
180 | /* auto-mute control */ | |
181 | int automute_mode; | |
3b8510ce | 182 | hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS]; |
d922b51d | 183 | |
4a79ba34 | 184 | int init_amp; |
d433a678 | 185 | int codec_variant; /* flag for other variants */ |
e64f14f4 | 186 | |
2134ea4f TI |
187 | /* for virtual master */ |
188 | hda_nid_t vmaster_nid; | |
cb53c626 TI |
189 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
190 | struct hda_loopback_check loopback; | |
191 | #endif | |
2c3bf9ab TI |
192 | |
193 | /* for PLL fix */ | |
194 | hda_nid_t pll_nid; | |
195 | unsigned int pll_coef_idx, pll_coef_bit; | |
b5bfbc67 TI |
196 | |
197 | /* fix-up list */ | |
198 | int fixup_id; | |
199 | const struct alc_fixup *fixup_list; | |
200 | const char *fixup_name; | |
ce764ab2 TI |
201 | |
202 | /* multi-io */ | |
203 | int multi_ios; | |
204 | struct alc_multi_io multi_io[4]; | |
df694daa KY |
205 | }; |
206 | ||
1d045db9 | 207 | #define ALC_MODEL_AUTO 0 /* common for all chips */ |
1da177e4 | 208 | |
44c02400 TI |
209 | static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, |
210 | int dir, unsigned int bits) | |
211 | { | |
212 | if (!nid) | |
213 | return false; | |
214 | if (get_wcaps(codec, nid) & (1 << (dir + 1))) | |
215 | if (query_amp_caps(codec, nid, dir) & bits) | |
216 | return true; | |
217 | return false; | |
218 | } | |
219 | ||
220 | #define nid_has_mute(codec, nid, dir) \ | |
221 | check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE) | |
222 | #define nid_has_volume(codec, nid, dir) \ | |
223 | check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS) | |
224 | ||
1da177e4 LT |
225 | /* |
226 | * input MUX handling | |
227 | */ | |
9c7f852e TI |
228 | static int alc_mux_enum_info(struct snd_kcontrol *kcontrol, |
229 | struct snd_ctl_elem_info *uinfo) | |
1da177e4 LT |
230 | { |
231 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
232 | struct alc_spec *spec = codec->spec; | |
a1e8d2da JW |
233 | unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id); |
234 | if (mux_idx >= spec->num_mux_defs) | |
235 | mux_idx = 0; | |
5311114d TI |
236 | if (!spec->input_mux[mux_idx].num_items && mux_idx > 0) |
237 | mux_idx = 0; | |
a1e8d2da | 238 | return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo); |
1da177e4 LT |
239 | } |
240 | ||
9c7f852e TI |
241 | static int alc_mux_enum_get(struct snd_kcontrol *kcontrol, |
242 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 LT |
243 | { |
244 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
245 | struct alc_spec *spec = codec->spec; | |
246 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
247 | ||
248 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; | |
249 | return 0; | |
250 | } | |
251 | ||
21268961 TI |
252 | static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur) |
253 | { | |
254 | struct alc_spec *spec = codec->spec; | |
255 | hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]]; | |
256 | ||
257 | if (spec->cur_adc && spec->cur_adc != new_adc) { | |
258 | /* stream is running, let's swap the current ADC */ | |
259 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); | |
260 | spec->cur_adc = new_adc; | |
261 | snd_hda_codec_setup_stream(codec, new_adc, | |
262 | spec->cur_adc_stream_tag, 0, | |
263 | spec->cur_adc_format); | |
264 | return true; | |
265 | } | |
266 | return false; | |
267 | } | |
268 | ||
269 | /* select the given imux item; either unmute exclusively or select the route */ | |
270 | static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx, | |
271 | unsigned int idx, bool force) | |
1da177e4 | 272 | { |
1da177e4 | 273 | struct alc_spec *spec = codec->spec; |
cd896c33 | 274 | const struct hda_input_mux *imux; |
cd896c33 | 275 | unsigned int mux_idx; |
21268961 TI |
276 | int i, type; |
277 | hda_nid_t nid; | |
1da177e4 | 278 | |
cd896c33 TI |
279 | mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; |
280 | imux = &spec->input_mux[mux_idx]; | |
5311114d TI |
281 | if (!imux->num_items && mux_idx > 0) |
282 | imux = &spec->input_mux[0]; | |
cd896c33 | 283 | |
21268961 TI |
284 | if (idx >= imux->num_items) |
285 | idx = imux->num_items - 1; | |
286 | if (spec->cur_mux[adc_idx] == idx && !force) | |
287 | return 0; | |
288 | spec->cur_mux[adc_idx] = idx; | |
289 | ||
290 | if (spec->dyn_adc_switch) { | |
291 | alc_dyn_adc_pcm_resetup(codec, idx); | |
292 | adc_idx = spec->dyn_adc_idx[idx]; | |
293 | } | |
294 | ||
295 | nid = spec->capsrc_nids ? | |
296 | spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx]; | |
297 | ||
298 | /* no selection? */ | |
299 | if (snd_hda_get_conn_list(codec, nid, NULL) <= 1) | |
300 | return 1; | |
301 | ||
a22d543a | 302 | type = get_wcaps_type(get_wcaps(codec, nid)); |
0169b6b3 | 303 | if (type == AC_WID_AUD_MIX) { |
54cbc9ab | 304 | /* Matrix-mixer style (e.g. ALC882) */ |
54cbc9ab TI |
305 | for (i = 0; i < imux->num_items; i++) { |
306 | unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE; | |
307 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, | |
308 | imux->items[i].index, | |
309 | HDA_AMP_MUTE, v); | |
310 | } | |
54cbc9ab TI |
311 | } else { |
312 | /* MUX style (e.g. ALC880) */ | |
21268961 TI |
313 | snd_hda_codec_write_cache(codec, nid, 0, |
314 | AC_VERB_SET_CONNECT_SEL, | |
315 | imux->items[idx].index); | |
54cbc9ab | 316 | } |
21268961 TI |
317 | return 1; |
318 | } | |
319 | ||
320 | static int alc_mux_enum_put(struct snd_kcontrol *kcontrol, | |
321 | struct snd_ctl_elem_value *ucontrol) | |
322 | { | |
323 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
324 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
325 | return alc_mux_select(codec, adc_idx, | |
326 | ucontrol->value.enumerated.item[0], false); | |
54cbc9ab | 327 | } |
e9edcee0 | 328 | |
23f0c048 TI |
329 | /* |
330 | * set up the input pin config (depending on the given auto-pin type) | |
331 | */ | |
332 | static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid, | |
333 | int auto_pin_type) | |
334 | { | |
335 | unsigned int val = PIN_IN; | |
336 | ||
86e2959a | 337 | if (auto_pin_type == AUTO_PIN_MIC) { |
23f0c048 | 338 | unsigned int pincap; |
954a29c8 TI |
339 | unsigned int oldval; |
340 | oldval = snd_hda_codec_read(codec, nid, 0, | |
341 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | |
1327a32b | 342 | pincap = snd_hda_query_pin_caps(codec, nid); |
23f0c048 | 343 | pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; |
954a29c8 TI |
344 | /* if the default pin setup is vref50, we give it priority */ |
345 | if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50) | |
23f0c048 | 346 | val = PIN_VREF80; |
461c6c3a TI |
347 | else if (pincap & AC_PINCAP_VREF_50) |
348 | val = PIN_VREF50; | |
349 | else if (pincap & AC_PINCAP_VREF_100) | |
350 | val = PIN_VREF100; | |
351 | else if (pincap & AC_PINCAP_VREF_GRD) | |
352 | val = PIN_VREFGRD; | |
23f0c048 TI |
353 | } |
354 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val); | |
355 | } | |
356 | ||
d88897ea | 357 | /* |
1d045db9 TI |
358 | * Append the given mixer and verb elements for the later use |
359 | * The mixer array is referred in build_controls(), and init_verbs are | |
360 | * called in init(). | |
d88897ea | 361 | */ |
a9111321 | 362 | static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix) |
d88897ea TI |
363 | { |
364 | if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers))) | |
365 | return; | |
366 | spec->mixers[spec->num_mixers++] = mix; | |
367 | } | |
368 | ||
369 | static void add_verb(struct alc_spec *spec, const struct hda_verb *verb) | |
370 | { | |
371 | if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs))) | |
372 | return; | |
373 | spec->init_verbs[spec->num_init_verbs++] = verb; | |
374 | } | |
375 | ||
df694daa | 376 | /* |
1d045db9 | 377 | * GPIO setup tables, used in initialization |
df694daa | 378 | */ |
bc9f98a9 | 379 | /* Enable GPIO mask and set output */ |
a9111321 | 380 | static const struct hda_verb alc_gpio1_init_verbs[] = { |
bc9f98a9 KY |
381 | {0x01, AC_VERB_SET_GPIO_MASK, 0x01}, |
382 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, | |
383 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, | |
384 | { } | |
385 | }; | |
386 | ||
a9111321 | 387 | static const struct hda_verb alc_gpio2_init_verbs[] = { |
bc9f98a9 KY |
388 | {0x01, AC_VERB_SET_GPIO_MASK, 0x02}, |
389 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02}, | |
390 | {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, | |
391 | { } | |
392 | }; | |
393 | ||
a9111321 | 394 | static const struct hda_verb alc_gpio3_init_verbs[] = { |
bdd148a3 KY |
395 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, |
396 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03}, | |
397 | {0x01, AC_VERB_SET_GPIO_DATA, 0x03}, | |
398 | { } | |
399 | }; | |
400 | ||
2c3bf9ab TI |
401 | /* |
402 | * Fix hardware PLL issue | |
403 | * On some codecs, the analog PLL gating control must be off while | |
404 | * the default value is 1. | |
405 | */ | |
406 | static void alc_fix_pll(struct hda_codec *codec) | |
407 | { | |
408 | struct alc_spec *spec = codec->spec; | |
409 | unsigned int val; | |
410 | ||
411 | if (!spec->pll_nid) | |
412 | return; | |
413 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, | |
414 | spec->pll_coef_idx); | |
415 | val = snd_hda_codec_read(codec, spec->pll_nid, 0, | |
416 | AC_VERB_GET_PROC_COEF, 0); | |
417 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX, | |
418 | spec->pll_coef_idx); | |
419 | snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF, | |
420 | val & ~(1 << spec->pll_coef_bit)); | |
421 | } | |
422 | ||
423 | static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid, | |
424 | unsigned int coef_idx, unsigned int coef_bit) | |
425 | { | |
426 | struct alc_spec *spec = codec->spec; | |
427 | spec->pll_nid = nid; | |
428 | spec->pll_coef_idx = coef_idx; | |
429 | spec->pll_coef_bit = coef_bit; | |
430 | alc_fix_pll(codec); | |
431 | } | |
432 | ||
1d045db9 TI |
433 | /* |
434 | * Jack-reporting via input-jack layer | |
435 | */ | |
436 | ||
437 | /* initialization of jacks; currently checks only a few known pins */ | |
9ad0e496 KY |
438 | static int alc_init_jacks(struct hda_codec *codec) |
439 | { | |
cd372fb3 | 440 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
9ad0e496 KY |
441 | struct alc_spec *spec = codec->spec; |
442 | int err; | |
443 | unsigned int hp_nid = spec->autocfg.hp_pins[0]; | |
21268961 TI |
444 | unsigned int mic_nid = spec->ext_mic_pin; |
445 | unsigned int dock_nid = spec->dock_mic_pin; | |
9ad0e496 | 446 | |
265a0247 | 447 | if (hp_nid) { |
cd372fb3 TI |
448 | err = snd_hda_input_jack_add(codec, hp_nid, |
449 | SND_JACK_HEADPHONE, NULL); | |
265a0247 TI |
450 | if (err < 0) |
451 | return err; | |
cd372fb3 | 452 | snd_hda_input_jack_report(codec, hp_nid); |
265a0247 | 453 | } |
9ad0e496 | 454 | |
265a0247 | 455 | if (mic_nid) { |
cd372fb3 TI |
456 | err = snd_hda_input_jack_add(codec, mic_nid, |
457 | SND_JACK_MICROPHONE, NULL); | |
265a0247 TI |
458 | if (err < 0) |
459 | return err; | |
cd372fb3 | 460 | snd_hda_input_jack_report(codec, mic_nid); |
265a0247 | 461 | } |
8ed99d97 TI |
462 | if (dock_nid) { |
463 | err = snd_hda_input_jack_add(codec, dock_nid, | |
464 | SND_JACK_MICROPHONE, NULL); | |
465 | if (err < 0) | |
466 | return err; | |
467 | snd_hda_input_jack_report(codec, dock_nid); | |
468 | } | |
cd372fb3 | 469 | #endif /* CONFIG_SND_HDA_INPUT_JACK */ |
9ad0e496 KY |
470 | return 0; |
471 | } | |
9ad0e496 | 472 | |
1d045db9 TI |
473 | /* |
474 | * Jack detections for HP auto-mute and mic-switch | |
475 | */ | |
476 | ||
477 | /* check each pin in the given array; returns true if any of them is plugged */ | |
478 | static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) | |
c9b58006 | 479 | { |
e6a5e1b7 | 480 | int i, present = 0; |
c9b58006 | 481 | |
e6a5e1b7 TI |
482 | for (i = 0; i < num_pins; i++) { |
483 | hda_nid_t nid = pins[i]; | |
bb35febd TI |
484 | if (!nid) |
485 | break; | |
cd372fb3 | 486 | snd_hda_input_jack_report(codec, nid); |
e6a5e1b7 | 487 | present |= snd_hda_jack_detect(codec, nid); |
bb35febd | 488 | } |
e6a5e1b7 TI |
489 | return present; |
490 | } | |
bb35febd | 491 | |
1d045db9 | 492 | /* standard HP/line-out auto-mute helper */ |
e6a5e1b7 | 493 | static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins, |
e9427969 | 494 | bool mute, bool hp_out) |
e6a5e1b7 TI |
495 | { |
496 | struct alc_spec *spec = codec->spec; | |
497 | unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0; | |
e9427969 | 498 | unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT); |
e6a5e1b7 TI |
499 | int i; |
500 | ||
501 | for (i = 0; i < num_pins; i++) { | |
502 | hda_nid_t nid = pins[i]; | |
a9fd4f3f TI |
503 | if (!nid) |
504 | break; | |
3b8510ce TI |
505 | switch (spec->automute_mode) { |
506 | case ALC_AUTOMUTE_PIN: | |
bb35febd | 507 | snd_hda_codec_write(codec, nid, 0, |
e6a5e1b7 TI |
508 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
509 | pin_bits); | |
3b8510ce TI |
510 | break; |
511 | case ALC_AUTOMUTE_AMP: | |
bb35febd | 512 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
e6a5e1b7 | 513 | HDA_AMP_MUTE, mute_bits); |
3b8510ce TI |
514 | break; |
515 | case ALC_AUTOMUTE_MIXER: | |
516 | nid = spec->automute_mixer_nid[i]; | |
517 | if (!nid) | |
518 | break; | |
519 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0, | |
e6a5e1b7 | 520 | HDA_AMP_MUTE, mute_bits); |
3b8510ce | 521 | snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1, |
e6a5e1b7 | 522 | HDA_AMP_MUTE, mute_bits); |
3b8510ce | 523 | break; |
bb35febd | 524 | } |
a9fd4f3f | 525 | } |
c9b58006 KY |
526 | } |
527 | ||
e6a5e1b7 TI |
528 | /* Toggle internal speakers muting */ |
529 | static void update_speakers(struct hda_codec *codec) | |
530 | { | |
531 | struct alc_spec *spec = codec->spec; | |
1a1455de | 532 | int on; |
e6a5e1b7 | 533 | |
c0a20263 TI |
534 | /* Control HP pins/amps depending on master_mute state; |
535 | * in general, HP pins/amps control should be enabled in all cases, | |
536 | * but currently set only for master_mute, just to be safe | |
537 | */ | |
538 | do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins), | |
539 | spec->autocfg.hp_pins, spec->master_mute, true); | |
540 | ||
1a1455de TI |
541 | if (!spec->automute) |
542 | on = 0; | |
543 | else | |
544 | on = spec->jack_present | spec->line_jack_present; | |
545 | on |= spec->master_mute; | |
e6a5e1b7 | 546 | do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins), |
1a1455de | 547 | spec->autocfg.speaker_pins, on, false); |
e6a5e1b7 TI |
548 | |
549 | /* toggle line-out mutes if needed, too */ | |
1a1455de TI |
550 | /* if LO is a copy of either HP or Speaker, don't need to handle it */ |
551 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] || | |
552 | spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0]) | |
e6a5e1b7 | 553 | return; |
1a1455de TI |
554 | if (!spec->automute_lines || !spec->automute) |
555 | on = 0; | |
556 | else | |
557 | on = spec->jack_present; | |
558 | on |= spec->master_mute; | |
e6a5e1b7 | 559 | do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
1a1455de | 560 | spec->autocfg.line_out_pins, on, false); |
e6a5e1b7 TI |
561 | } |
562 | ||
1d045db9 | 563 | /* standard HP-automute helper */ |
e6a5e1b7 TI |
564 | static void alc_hp_automute(struct hda_codec *codec) |
565 | { | |
566 | struct alc_spec *spec = codec->spec; | |
567 | ||
568 | if (!spec->automute) | |
569 | return; | |
570 | spec->jack_present = | |
571 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins), | |
572 | spec->autocfg.hp_pins); | |
573 | update_speakers(codec); | |
574 | } | |
575 | ||
1d045db9 | 576 | /* standard line-out-automute helper */ |
e6a5e1b7 TI |
577 | static void alc_line_automute(struct hda_codec *codec) |
578 | { | |
579 | struct alc_spec *spec = codec->spec; | |
580 | ||
581 | if (!spec->automute || !spec->detect_line) | |
582 | return; | |
583 | spec->line_jack_present = | |
584 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), | |
585 | spec->autocfg.line_out_pins); | |
586 | update_speakers(codec); | |
587 | } | |
588 | ||
8d087c76 TI |
589 | #define get_connection_index(codec, mux, nid) \ |
590 | snd_hda_get_conn_index(codec, mux, nid, 0) | |
6c819492 | 591 | |
1d045db9 | 592 | /* standard mic auto-switch helper */ |
7fb0d78f KY |
593 | static void alc_mic_automute(struct hda_codec *codec) |
594 | { | |
595 | struct alc_spec *spec = codec->spec; | |
21268961 | 596 | hda_nid_t *pins = spec->imux_pins; |
6c819492 | 597 | |
21268961 | 598 | if (!spec->auto_mic || !spec->auto_mic_valid_imux) |
6c819492 TI |
599 | return; |
600 | if (snd_BUG_ON(!spec->adc_nids)) | |
601 | return; | |
21268961 | 602 | if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0)) |
840b64c0 | 603 | return; |
6c819492 | 604 | |
21268961 TI |
605 | if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx])) |
606 | alc_mux_select(codec, 0, spec->ext_mic_idx, false); | |
607 | else if (spec->dock_mic_idx >= 0 && | |
608 | snd_hda_jack_detect(codec, pins[spec->dock_mic_idx])) | |
609 | alc_mux_select(codec, 0, spec->dock_mic_idx, false); | |
610 | else | |
611 | alc_mux_select(codec, 0, spec->int_mic_idx, false); | |
6c819492 | 612 | |
21268961 TI |
613 | snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]); |
614 | if (spec->dock_mic_idx >= 0) | |
615 | snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]); | |
7fb0d78f KY |
616 | } |
617 | ||
c9b58006 KY |
618 | /* unsolicited event for HP jack sensing */ |
619 | static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res) | |
620 | { | |
621 | if (codec->vendor_id == 0x10ec0880) | |
622 | res >>= 28; | |
623 | else | |
624 | res >>= 26; | |
a9fd4f3f | 625 | switch (res) { |
1d045db9 | 626 | case ALC_HP_EVENT: |
d922b51d | 627 | alc_hp_automute(codec); |
a9fd4f3f | 628 | break; |
1d045db9 | 629 | case ALC_FRONT_EVENT: |
e6a5e1b7 TI |
630 | alc_line_automute(codec); |
631 | break; | |
1d045db9 | 632 | case ALC_MIC_EVENT: |
7fb0d78f | 633 | alc_mic_automute(codec); |
a9fd4f3f TI |
634 | break; |
635 | } | |
7fb0d78f KY |
636 | } |
637 | ||
1d045db9 | 638 | /* call init functions of standard auto-mute helpers */ |
7fb0d78f KY |
639 | static void alc_inithook(struct hda_codec *codec) |
640 | { | |
d922b51d | 641 | alc_hp_automute(codec); |
e6a5e1b7 | 642 | alc_line_automute(codec); |
7fb0d78f | 643 | alc_mic_automute(codec); |
c9b58006 KY |
644 | } |
645 | ||
f9423e7a KY |
646 | /* additional initialization for ALC888 variants */ |
647 | static void alc888_coef_init(struct hda_codec *codec) | |
648 | { | |
649 | unsigned int tmp; | |
650 | ||
651 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0); | |
652 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); | |
653 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); | |
37db623a | 654 | if ((tmp & 0xf0) == 0x20) |
f9423e7a KY |
655 | /* alc888S-VC */ |
656 | snd_hda_codec_read(codec, 0x20, 0, | |
657 | AC_VERB_SET_PROC_COEF, 0x830); | |
658 | else | |
659 | /* alc888-VB */ | |
660 | snd_hda_codec_read(codec, 0x20, 0, | |
661 | AC_VERB_SET_PROC_COEF, 0x3030); | |
662 | } | |
663 | ||
1d045db9 | 664 | /* additional initialization for ALC889 variants */ |
87a8c370 JK |
665 | static void alc889_coef_init(struct hda_codec *codec) |
666 | { | |
667 | unsigned int tmp; | |
668 | ||
669 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); | |
670 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); | |
671 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); | |
672 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010); | |
673 | } | |
674 | ||
3fb4a508 TI |
675 | /* turn on/off EAPD control (only if available) */ |
676 | static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on) | |
677 | { | |
678 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) | |
679 | return; | |
680 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) | |
681 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE, | |
682 | on ? 2 : 0); | |
683 | } | |
684 | ||
691f1fcc TI |
685 | /* turn on/off EAPD controls of the codec */ |
686 | static void alc_auto_setup_eapd(struct hda_codec *codec, bool on) | |
687 | { | |
688 | /* We currently only handle front, HP */ | |
39fa84e9 TI |
689 | static hda_nid_t pins[] = { |
690 | 0x0f, 0x10, 0x14, 0x15, 0 | |
691 | }; | |
692 | hda_nid_t *p; | |
693 | for (p = pins; *p; p++) | |
694 | set_eapd(codec, *p, on); | |
691f1fcc TI |
695 | } |
696 | ||
1c716153 TI |
697 | /* generic shutup callback; |
698 | * just turning off EPAD and a little pause for avoiding pop-noise | |
699 | */ | |
700 | static void alc_eapd_shutup(struct hda_codec *codec) | |
701 | { | |
702 | alc_auto_setup_eapd(codec, false); | |
703 | msleep(200); | |
704 | } | |
705 | ||
1d045db9 | 706 | /* generic EAPD initialization */ |
4a79ba34 | 707 | static void alc_auto_init_amp(struct hda_codec *codec, int type) |
bc9f98a9 | 708 | { |
4a79ba34 | 709 | unsigned int tmp; |
bc9f98a9 | 710 | |
39fa84e9 | 711 | alc_auto_setup_eapd(codec, true); |
4a79ba34 TI |
712 | switch (type) { |
713 | case ALC_INIT_GPIO1: | |
bc9f98a9 KY |
714 | snd_hda_sequence_write(codec, alc_gpio1_init_verbs); |
715 | break; | |
4a79ba34 | 716 | case ALC_INIT_GPIO2: |
bc9f98a9 KY |
717 | snd_hda_sequence_write(codec, alc_gpio2_init_verbs); |
718 | break; | |
4a79ba34 | 719 | case ALC_INIT_GPIO3: |
bdd148a3 KY |
720 | snd_hda_sequence_write(codec, alc_gpio3_init_verbs); |
721 | break; | |
4a79ba34 | 722 | case ALC_INIT_DEFAULT: |
c9b58006 KY |
723 | switch (codec->vendor_id) { |
724 | case 0x10ec0260: | |
725 | snd_hda_codec_write(codec, 0x1a, 0, | |
726 | AC_VERB_SET_COEF_INDEX, 7); | |
727 | tmp = snd_hda_codec_read(codec, 0x1a, 0, | |
728 | AC_VERB_GET_PROC_COEF, 0); | |
729 | snd_hda_codec_write(codec, 0x1a, 0, | |
730 | AC_VERB_SET_COEF_INDEX, 7); | |
731 | snd_hda_codec_write(codec, 0x1a, 0, | |
732 | AC_VERB_SET_PROC_COEF, | |
733 | tmp | 0x2010); | |
734 | break; | |
735 | case 0x10ec0262: | |
736 | case 0x10ec0880: | |
737 | case 0x10ec0882: | |
738 | case 0x10ec0883: | |
739 | case 0x10ec0885: | |
4a5a4c56 | 740 | case 0x10ec0887: |
20b67ddd | 741 | /*case 0x10ec0889:*/ /* this causes an SPDIF problem */ |
87a8c370 | 742 | alc889_coef_init(codec); |
c9b58006 | 743 | break; |
f9423e7a | 744 | case 0x10ec0888: |
4a79ba34 | 745 | alc888_coef_init(codec); |
f9423e7a | 746 | break; |
0aea778e | 747 | #if 0 /* XXX: This may cause the silent output on speaker on some machines */ |
c9b58006 KY |
748 | case 0x10ec0267: |
749 | case 0x10ec0268: | |
750 | snd_hda_codec_write(codec, 0x20, 0, | |
751 | AC_VERB_SET_COEF_INDEX, 7); | |
752 | tmp = snd_hda_codec_read(codec, 0x20, 0, | |
753 | AC_VERB_GET_PROC_COEF, 0); | |
754 | snd_hda_codec_write(codec, 0x20, 0, | |
ea1fb29a | 755 | AC_VERB_SET_COEF_INDEX, 7); |
c9b58006 KY |
756 | snd_hda_codec_write(codec, 0x20, 0, |
757 | AC_VERB_SET_PROC_COEF, | |
758 | tmp | 0x3000); | |
759 | break; | |
0aea778e | 760 | #endif /* XXX */ |
bc9f98a9 | 761 | } |
4a79ba34 TI |
762 | break; |
763 | } | |
764 | } | |
765 | ||
1d045db9 TI |
766 | /* |
767 | * Auto-Mute mode mixer enum support | |
768 | */ | |
1a1455de TI |
769 | static int alc_automute_mode_info(struct snd_kcontrol *kcontrol, |
770 | struct snd_ctl_elem_info *uinfo) | |
771 | { | |
ae8a60a5 TI |
772 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
773 | struct alc_spec *spec = codec->spec; | |
774 | static const char * const texts2[] = { | |
775 | "Disabled", "Enabled" | |
776 | }; | |
777 | static const char * const texts3[] = { | |
1a1455de TI |
778 | "Disabled", "Speaker Only", "Line-Out+Speaker" |
779 | }; | |
ae8a60a5 | 780 | const char * const *texts; |
1a1455de TI |
781 | |
782 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
783 | uinfo->count = 1; | |
ae8a60a5 TI |
784 | if (spec->automute_hp_lo) { |
785 | uinfo->value.enumerated.items = 3; | |
786 | texts = texts3; | |
787 | } else { | |
788 | uinfo->value.enumerated.items = 2; | |
789 | texts = texts2; | |
790 | } | |
791 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) | |
792 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; | |
1a1455de TI |
793 | strcpy(uinfo->value.enumerated.name, |
794 | texts[uinfo->value.enumerated.item]); | |
795 | return 0; | |
796 | } | |
797 | ||
798 | static int alc_automute_mode_get(struct snd_kcontrol *kcontrol, | |
799 | struct snd_ctl_elem_value *ucontrol) | |
800 | { | |
801 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
802 | struct alc_spec *spec = codec->spec; | |
803 | unsigned int val; | |
804 | if (!spec->automute) | |
805 | val = 0; | |
806 | else if (!spec->automute_lines) | |
807 | val = 1; | |
808 | else | |
809 | val = 2; | |
810 | ucontrol->value.enumerated.item[0] = val; | |
811 | return 0; | |
812 | } | |
813 | ||
814 | static int alc_automute_mode_put(struct snd_kcontrol *kcontrol, | |
815 | struct snd_ctl_elem_value *ucontrol) | |
816 | { | |
817 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
818 | struct alc_spec *spec = codec->spec; | |
819 | ||
820 | switch (ucontrol->value.enumerated.item[0]) { | |
821 | case 0: | |
822 | if (!spec->automute) | |
823 | return 0; | |
824 | spec->automute = 0; | |
825 | break; | |
826 | case 1: | |
827 | if (spec->automute && !spec->automute_lines) | |
828 | return 0; | |
829 | spec->automute = 1; | |
830 | spec->automute_lines = 0; | |
831 | break; | |
832 | case 2: | |
ae8a60a5 TI |
833 | if (!spec->automute_hp_lo) |
834 | return -EINVAL; | |
1a1455de TI |
835 | if (spec->automute && spec->automute_lines) |
836 | return 0; | |
837 | spec->automute = 1; | |
838 | spec->automute_lines = 1; | |
839 | break; | |
840 | default: | |
841 | return -EINVAL; | |
842 | } | |
843 | update_speakers(codec); | |
844 | return 1; | |
845 | } | |
846 | ||
a9111321 | 847 | static const struct snd_kcontrol_new alc_automute_mode_enum = { |
1a1455de TI |
848 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
849 | .name = "Auto-Mute Mode", | |
850 | .info = alc_automute_mode_info, | |
851 | .get = alc_automute_mode_get, | |
852 | .put = alc_automute_mode_put, | |
853 | }; | |
854 | ||
1d045db9 TI |
855 | static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec) |
856 | { | |
857 | snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32); | |
858 | return snd_array_new(&spec->kctls); | |
859 | } | |
1a1455de TI |
860 | |
861 | static int alc_add_automute_mode_enum(struct hda_codec *codec) | |
862 | { | |
863 | struct alc_spec *spec = codec->spec; | |
864 | struct snd_kcontrol_new *knew; | |
865 | ||
866 | knew = alc_kcontrol_new(spec); | |
867 | if (!knew) | |
868 | return -ENOMEM; | |
869 | *knew = alc_automute_mode_enum; | |
870 | knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL); | |
871 | if (!knew->name) | |
872 | return -ENOMEM; | |
873 | return 0; | |
874 | } | |
875 | ||
1d045db9 TI |
876 | /* |
877 | * Check the availability of HP/line-out auto-mute; | |
878 | * Set up appropriately if really supported | |
879 | */ | |
4a79ba34 TI |
880 | static void alc_init_auto_hp(struct hda_codec *codec) |
881 | { | |
882 | struct alc_spec *spec = codec->spec; | |
bb35febd | 883 | struct auto_pin_cfg *cfg = &spec->autocfg; |
1daf5f46 | 884 | int present = 0; |
bb35febd | 885 | int i; |
4a79ba34 | 886 | |
1daf5f46 TI |
887 | if (cfg->hp_pins[0]) |
888 | present++; | |
889 | if (cfg->line_out_pins[0]) | |
890 | present++; | |
891 | if (cfg->speaker_pins[0]) | |
892 | present++; | |
893 | if (present < 2) /* need two different output types */ | |
894 | return; | |
ae8a60a5 TI |
895 | if (present == 3) |
896 | spec->automute_hp_lo = 1; /* both HP and LO automute */ | |
4a79ba34 | 897 | |
bb35febd | 898 | if (!cfg->speaker_pins[0]) { |
bb35febd TI |
899 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
900 | sizeof(cfg->speaker_pins)); | |
901 | cfg->speaker_outs = cfg->line_outs; | |
902 | } | |
903 | ||
904 | if (!cfg->hp_pins[0]) { | |
905 | memcpy(cfg->hp_pins, cfg->line_out_pins, | |
906 | sizeof(cfg->hp_pins)); | |
907 | cfg->hp_outs = cfg->line_outs; | |
4a79ba34 TI |
908 | } |
909 | ||
bb35febd | 910 | for (i = 0; i < cfg->hp_outs; i++) { |
1a1455de | 911 | hda_nid_t nid = cfg->hp_pins[i]; |
06dec228 | 912 | if (!is_jack_detectable(codec, nid)) |
1a1455de | 913 | continue; |
bb35febd | 914 | snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n", |
1a1455de TI |
915 | nid); |
916 | snd_hda_codec_write_cache(codec, nid, 0, | |
4a79ba34 | 917 | AC_VERB_SET_UNSOLICITED_ENABLE, |
1d045db9 | 918 | AC_USRSP_EN | ALC_HP_EVENT); |
d922b51d TI |
919 | spec->automute = 1; |
920 | spec->automute_mode = ALC_AUTOMUTE_PIN; | |
bb35febd | 921 | } |
1a1455de TI |
922 | if (spec->automute && cfg->line_out_pins[0] && |
923 | cfg->line_out_pins[0] != cfg->hp_pins[0] && | |
924 | cfg->line_out_pins[0] != cfg->speaker_pins[0]) { | |
925 | for (i = 0; i < cfg->line_outs; i++) { | |
926 | hda_nid_t nid = cfg->line_out_pins[i]; | |
06dec228 | 927 | if (!is_jack_detectable(codec, nid)) |
1a1455de TI |
928 | continue; |
929 | snd_printdd("realtek: Enable Line-Out auto-muting " | |
930 | "on NID 0x%x\n", nid); | |
931 | snd_hda_codec_write_cache(codec, nid, 0, | |
932 | AC_VERB_SET_UNSOLICITED_ENABLE, | |
1d045db9 | 933 | AC_USRSP_EN | ALC_FRONT_EVENT); |
1a1455de TI |
934 | spec->detect_line = 1; |
935 | } | |
52d3cb88 | 936 | spec->automute_lines = spec->detect_line; |
ae8a60a5 TI |
937 | } |
938 | ||
939 | if (spec->automute) { | |
1a1455de TI |
940 | /* create a control for automute mode */ |
941 | alc_add_automute_mode_enum(codec); | |
ae8a60a5 | 942 | spec->unsol_event = alc_sku_unsol_event; |
1a1455de | 943 | } |
4a79ba34 TI |
944 | } |
945 | ||
1d045db9 | 946 | /* return the position of NID in the list, or -1 if not found */ |
21268961 TI |
947 | static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
948 | { | |
949 | int i; | |
950 | for (i = 0; i < nums; i++) | |
951 | if (list[i] == nid) | |
952 | return i; | |
953 | return -1; | |
954 | } | |
955 | ||
1d045db9 TI |
956 | /* check whether dynamic ADC-switching is available */ |
957 | static bool alc_check_dyn_adc_switch(struct hda_codec *codec) | |
958 | { | |
959 | struct alc_spec *spec = codec->spec; | |
960 | struct hda_input_mux *imux = &spec->private_imux[0]; | |
961 | int i, n, idx; | |
962 | hda_nid_t cap, pin; | |
963 | ||
964 | if (imux != spec->input_mux) /* no dynamic imux? */ | |
965 | return false; | |
966 | ||
967 | for (n = 0; n < spec->num_adc_nids; n++) { | |
968 | cap = spec->private_capsrc_nids[n]; | |
969 | for (i = 0; i < imux->num_items; i++) { | |
970 | pin = spec->imux_pins[i]; | |
971 | if (!pin) | |
972 | return false; | |
973 | if (get_connection_index(codec, cap, pin) < 0) | |
974 | break; | |
975 | } | |
976 | if (i >= imux->num_items) | |
268ff6fb | 977 | return true; /* no ADC-switch is needed */ |
1d045db9 TI |
978 | } |
979 | ||
980 | for (i = 0; i < imux->num_items; i++) { | |
981 | pin = spec->imux_pins[i]; | |
982 | for (n = 0; n < spec->num_adc_nids; n++) { | |
983 | cap = spec->private_capsrc_nids[n]; | |
984 | idx = get_connection_index(codec, cap, pin); | |
985 | if (idx >= 0) { | |
986 | imux->items[i].index = idx; | |
987 | spec->dyn_adc_idx[i] = n; | |
988 | break; | |
989 | } | |
990 | } | |
991 | } | |
992 | ||
993 | snd_printdd("realtek: enabling ADC switching\n"); | |
994 | spec->dyn_adc_switch = 1; | |
995 | return true; | |
996 | } | |
21268961 TI |
997 | |
998 | /* rebuild imux for matching with the given auto-mic pins (if not yet) */ | |
999 | static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec) | |
1000 | { | |
1001 | struct alc_spec *spec = codec->spec; | |
1002 | struct hda_input_mux *imux; | |
1003 | static char * const texts[3] = { | |
1004 | "Mic", "Internal Mic", "Dock Mic" | |
1005 | }; | |
1006 | int i; | |
1007 | ||
1008 | if (!spec->auto_mic) | |
1009 | return false; | |
1010 | imux = &spec->private_imux[0]; | |
1011 | if (spec->input_mux == imux) | |
1012 | return true; | |
1013 | spec->imux_pins[0] = spec->ext_mic_pin; | |
1014 | spec->imux_pins[1] = spec->int_mic_pin; | |
1015 | spec->imux_pins[2] = spec->dock_mic_pin; | |
1016 | for (i = 0; i < 3; i++) { | |
1017 | strcpy(imux->items[i].label, texts[i]); | |
1018 | if (spec->imux_pins[i]) | |
1019 | imux->num_items = i + 1; | |
1020 | } | |
1021 | spec->num_mux_defs = 1; | |
1022 | spec->input_mux = imux; | |
1023 | return true; | |
1024 | } | |
1025 | ||
1026 | /* check whether all auto-mic pins are valid; setup indices if OK */ | |
1027 | static bool alc_auto_mic_check_imux(struct hda_codec *codec) | |
1028 | { | |
1029 | struct alc_spec *spec = codec->spec; | |
1030 | const struct hda_input_mux *imux; | |
1031 | ||
1032 | if (!spec->auto_mic) | |
1033 | return false; | |
1034 | if (spec->auto_mic_valid_imux) | |
1035 | return true; /* already checked */ | |
1036 | ||
1037 | /* fill up imux indices */ | |
1038 | if (!alc_check_dyn_adc_switch(codec)) { | |
1039 | spec->auto_mic = 0; | |
1040 | return false; | |
1041 | } | |
1042 | ||
1043 | imux = spec->input_mux; | |
1044 | spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin, | |
1045 | spec->imux_pins, imux->num_items); | |
1046 | spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin, | |
1047 | spec->imux_pins, imux->num_items); | |
1048 | spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin, | |
1049 | spec->imux_pins, imux->num_items); | |
1050 | if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) { | |
1051 | spec->auto_mic = 0; | |
1052 | return false; /* no corresponding imux */ | |
1053 | } | |
1054 | ||
1055 | snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0, | |
1056 | AC_VERB_SET_UNSOLICITED_ENABLE, | |
1d045db9 | 1057 | AC_USRSP_EN | ALC_MIC_EVENT); |
21268961 TI |
1058 | if (spec->dock_mic_pin) |
1059 | snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0, | |
1060 | AC_VERB_SET_UNSOLICITED_ENABLE, | |
1d045db9 | 1061 | AC_USRSP_EN | ALC_MIC_EVENT); |
21268961 TI |
1062 | |
1063 | spec->auto_mic_valid_imux = 1; | |
1064 | spec->auto_mic = 1; | |
1065 | return true; | |
1066 | } | |
1067 | ||
1d045db9 TI |
1068 | /* |
1069 | * Check the availability of auto-mic switch; | |
1070 | * Set up if really supported | |
1071 | */ | |
6c819492 TI |
1072 | static void alc_init_auto_mic(struct hda_codec *codec) |
1073 | { | |
1074 | struct alc_spec *spec = codec->spec; | |
1075 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
8ed99d97 | 1076 | hda_nid_t fixed, ext, dock; |
6c819492 TI |
1077 | int i; |
1078 | ||
21268961 TI |
1079 | spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1; |
1080 | ||
8ed99d97 | 1081 | fixed = ext = dock = 0; |
66ceeb6b TI |
1082 | for (i = 0; i < cfg->num_inputs; i++) { |
1083 | hda_nid_t nid = cfg->inputs[i].pin; | |
6c819492 | 1084 | unsigned int defcfg; |
6c819492 | 1085 | defcfg = snd_hda_codec_get_pincfg(codec, nid); |
99ae28be TI |
1086 | switch (snd_hda_get_input_pin_attr(defcfg)) { |
1087 | case INPUT_PIN_ATTR_INT: | |
6c819492 TI |
1088 | if (fixed) |
1089 | return; /* already occupied */ | |
8ed99d97 TI |
1090 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
1091 | return; /* invalid type */ | |
6c819492 TI |
1092 | fixed = nid; |
1093 | break; | |
99ae28be TI |
1094 | case INPUT_PIN_ATTR_UNUSED: |
1095 | return; /* invalid entry */ | |
8ed99d97 TI |
1096 | case INPUT_PIN_ATTR_DOCK: |
1097 | if (dock) | |
1098 | return; /* already occupied */ | |
1099 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) | |
1100 | return; /* invalid type */ | |
1101 | dock = nid; | |
1102 | break; | |
99ae28be | 1103 | default: |
6c819492 TI |
1104 | if (ext) |
1105 | return; /* already occupied */ | |
8ed99d97 TI |
1106 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
1107 | return; /* invalid type */ | |
6c819492 TI |
1108 | ext = nid; |
1109 | break; | |
6c819492 TI |
1110 | } |
1111 | } | |
8ed99d97 TI |
1112 | if (!ext && dock) { |
1113 | ext = dock; | |
1114 | dock = 0; | |
1115 | } | |
eaa9b3a7 TI |
1116 | if (!ext || !fixed) |
1117 | return; | |
e35d9d6a | 1118 | if (!is_jack_detectable(codec, ext)) |
6c819492 | 1119 | return; /* no unsol support */ |
8ed99d97 TI |
1120 | if (dock && !is_jack_detectable(codec, dock)) |
1121 | return; /* no unsol support */ | |
21268961 TI |
1122 | |
1123 | /* check imux indices */ | |
1124 | spec->ext_mic_pin = ext; | |
1125 | spec->int_mic_pin = fixed; | |
1126 | spec->dock_mic_pin = dock; | |
1127 | ||
1128 | spec->auto_mic = 1; | |
1129 | if (!alc_auto_mic_check_imux(codec)) | |
1130 | return; | |
1131 | ||
8ed99d97 TI |
1132 | snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n", |
1133 | ext, fixed, dock); | |
6c819492 TI |
1134 | spec->unsol_event = alc_sku_unsol_event; |
1135 | } | |
1136 | ||
1d045db9 TI |
1137 | /* check the availabilities of auto-mute and auto-mic switches */ |
1138 | static void alc_auto_check_switches(struct hda_codec *codec) | |
1139 | { | |
1140 | alc_init_auto_hp(codec); | |
1141 | alc_init_auto_mic(codec); | |
1142 | } | |
1143 | ||
1144 | /* | |
1145 | * Realtek SSID verification | |
1146 | */ | |
1147 | ||
90622917 DH |
1148 | /* Could be any non-zero and even value. When used as fixup, tells |
1149 | * the driver to ignore any present sku defines. | |
1150 | */ | |
1151 | #define ALC_FIXUP_SKU_IGNORE (2) | |
1152 | ||
da00c244 KY |
1153 | static int alc_auto_parse_customize_define(struct hda_codec *codec) |
1154 | { | |
1155 | unsigned int ass, tmp, i; | |
7fb56223 | 1156 | unsigned nid = 0; |
da00c244 KY |
1157 | struct alc_spec *spec = codec->spec; |
1158 | ||
b6cbe517 TI |
1159 | spec->cdefine.enable_pcbeep = 1; /* assume always enabled */ |
1160 | ||
90622917 DH |
1161 | if (spec->cdefine.fixup) { |
1162 | ass = spec->cdefine.sku_cfg; | |
1163 | if (ass == ALC_FIXUP_SKU_IGNORE) | |
1164 | return -1; | |
1165 | goto do_sku; | |
1166 | } | |
1167 | ||
da00c244 | 1168 | ass = codec->subsystem_id & 0xffff; |
b6cbe517 | 1169 | if (ass != codec->bus->pci->subsystem_device && (ass & 1)) |
da00c244 KY |
1170 | goto do_sku; |
1171 | ||
1172 | nid = 0x1d; | |
1173 | if (codec->vendor_id == 0x10ec0260) | |
1174 | nid = 0x17; | |
1175 | ass = snd_hda_codec_get_pincfg(codec, nid); | |
1176 | ||
1177 | if (!(ass & 1)) { | |
1178 | printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n", | |
1179 | codec->chip_name, ass); | |
1180 | return -1; | |
1181 | } | |
1182 | ||
1183 | /* check sum */ | |
1184 | tmp = 0; | |
1185 | for (i = 1; i < 16; i++) { | |
1186 | if ((ass >> i) & 1) | |
1187 | tmp++; | |
1188 | } | |
1189 | if (((ass >> 16) & 0xf) != tmp) | |
1190 | return -1; | |
1191 | ||
1192 | spec->cdefine.port_connectivity = ass >> 30; | |
1193 | spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20; | |
1194 | spec->cdefine.check_sum = (ass >> 16) & 0xf; | |
1195 | spec->cdefine.customization = ass >> 8; | |
1196 | do_sku: | |
1197 | spec->cdefine.sku_cfg = ass; | |
1198 | spec->cdefine.external_amp = (ass & 0x38) >> 3; | |
1199 | spec->cdefine.platform_type = (ass & 0x4) >> 2; | |
1200 | spec->cdefine.swap = (ass & 0x2) >> 1; | |
1201 | spec->cdefine.override = ass & 0x1; | |
1202 | ||
1203 | snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n", | |
1204 | nid, spec->cdefine.sku_cfg); | |
1205 | snd_printd("SKU: port_connectivity=0x%x\n", | |
1206 | spec->cdefine.port_connectivity); | |
1207 | snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep); | |
1208 | snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum); | |
1209 | snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization); | |
1210 | snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp); | |
1211 | snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type); | |
1212 | snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap); | |
1213 | snd_printd("SKU: override=0x%x\n", spec->cdefine.override); | |
1214 | ||
1215 | return 0; | |
1216 | } | |
1217 | ||
1d045db9 | 1218 | /* return true if the given NID is found in the list */ |
3af9ee6b TI |
1219 | static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
1220 | { | |
21268961 | 1221 | return find_idx_in_nid_list(nid, list, nums) >= 0; |
3af9ee6b TI |
1222 | } |
1223 | ||
4a79ba34 TI |
1224 | /* check subsystem ID and set up device-specific initialization; |
1225 | * return 1 if initialized, 0 if invalid SSID | |
1226 | */ | |
1227 | /* 32-bit subsystem ID for BIOS loading in HD Audio codec. | |
1228 | * 31 ~ 16 : Manufacture ID | |
1229 | * 15 ~ 8 : SKU ID | |
1230 | * 7 ~ 0 : Assembly ID | |
1231 | * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36 | |
1232 | */ | |
1233 | static int alc_subsystem_id(struct hda_codec *codec, | |
1234 | hda_nid_t porta, hda_nid_t porte, | |
6227cdce | 1235 | hda_nid_t portd, hda_nid_t porti) |
4a79ba34 TI |
1236 | { |
1237 | unsigned int ass, tmp, i; | |
1238 | unsigned nid; | |
1239 | struct alc_spec *spec = codec->spec; | |
1240 | ||
90622917 DH |
1241 | if (spec->cdefine.fixup) { |
1242 | ass = spec->cdefine.sku_cfg; | |
1243 | if (ass == ALC_FIXUP_SKU_IGNORE) | |
1244 | return 0; | |
1245 | goto do_sku; | |
1246 | } | |
1247 | ||
4a79ba34 TI |
1248 | ass = codec->subsystem_id & 0xffff; |
1249 | if ((ass != codec->bus->pci->subsystem_device) && (ass & 1)) | |
1250 | goto do_sku; | |
1251 | ||
1252 | /* invalid SSID, check the special NID pin defcfg instead */ | |
1253 | /* | |
def319f9 | 1254 | * 31~30 : port connectivity |
4a79ba34 TI |
1255 | * 29~21 : reserve |
1256 | * 20 : PCBEEP input | |
1257 | * 19~16 : Check sum (15:1) | |
1258 | * 15~1 : Custom | |
1259 | * 0 : override | |
1260 | */ | |
1261 | nid = 0x1d; | |
1262 | if (codec->vendor_id == 0x10ec0260) | |
1263 | nid = 0x17; | |
1264 | ass = snd_hda_codec_get_pincfg(codec, nid); | |
1265 | snd_printd("realtek: No valid SSID, " | |
1266 | "checking pincfg 0x%08x for NID 0x%x\n", | |
cb6605c1 | 1267 | ass, nid); |
6227cdce | 1268 | if (!(ass & 1)) |
4a79ba34 TI |
1269 | return 0; |
1270 | if ((ass >> 30) != 1) /* no physical connection */ | |
1271 | return 0; | |
1272 | ||
1273 | /* check sum */ | |
1274 | tmp = 0; | |
1275 | for (i = 1; i < 16; i++) { | |
1276 | if ((ass >> i) & 1) | |
1277 | tmp++; | |
1278 | } | |
1279 | if (((ass >> 16) & 0xf) != tmp) | |
1280 | return 0; | |
1281 | do_sku: | |
1282 | snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n", | |
1283 | ass & 0xffff, codec->vendor_id); | |
1284 | /* | |
1285 | * 0 : override | |
1286 | * 1 : Swap Jack | |
1287 | * 2 : 0 --> Desktop, 1 --> Laptop | |
1288 | * 3~5 : External Amplifier control | |
1289 | * 7~6 : Reserved | |
1290 | */ | |
1291 | tmp = (ass & 0x38) >> 3; /* external Amp control */ | |
1292 | switch (tmp) { | |
1293 | case 1: | |
1294 | spec->init_amp = ALC_INIT_GPIO1; | |
1295 | break; | |
1296 | case 3: | |
1297 | spec->init_amp = ALC_INIT_GPIO2; | |
1298 | break; | |
1299 | case 7: | |
1300 | spec->init_amp = ALC_INIT_GPIO3; | |
1301 | break; | |
1302 | case 5: | |
5a8cfb4e | 1303 | default: |
4a79ba34 | 1304 | spec->init_amp = ALC_INIT_DEFAULT; |
bc9f98a9 KY |
1305 | break; |
1306 | } | |
ea1fb29a | 1307 | |
8c427226 | 1308 | /* is laptop or Desktop and enable the function "Mute internal speaker |
c9b58006 KY |
1309 | * when the external headphone out jack is plugged" |
1310 | */ | |
8c427226 | 1311 | if (!(ass & 0x8000)) |
4a79ba34 | 1312 | return 1; |
c9b58006 KY |
1313 | /* |
1314 | * 10~8 : Jack location | |
1315 | * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered | |
1316 | * 14~13: Resvered | |
1317 | * 15 : 1 --> enable the function "Mute internal speaker | |
1318 | * when the external headphone out jack is plugged" | |
1319 | */ | |
c9b58006 | 1320 | if (!spec->autocfg.hp_pins[0]) { |
01d4825d | 1321 | hda_nid_t nid; |
c9b58006 KY |
1322 | tmp = (ass >> 11) & 0x3; /* HP to chassis */ |
1323 | if (tmp == 0) | |
01d4825d | 1324 | nid = porta; |
c9b58006 | 1325 | else if (tmp == 1) |
01d4825d | 1326 | nid = porte; |
c9b58006 | 1327 | else if (tmp == 2) |
01d4825d | 1328 | nid = portd; |
6227cdce KY |
1329 | else if (tmp == 3) |
1330 | nid = porti; | |
c9b58006 | 1331 | else |
4a79ba34 | 1332 | return 1; |
3af9ee6b TI |
1333 | if (found_in_nid_list(nid, spec->autocfg.line_out_pins, |
1334 | spec->autocfg.line_outs)) | |
1335 | return 1; | |
01d4825d | 1336 | spec->autocfg.hp_pins[0] = nid; |
c9b58006 | 1337 | } |
4a79ba34 TI |
1338 | return 1; |
1339 | } | |
ea1fb29a | 1340 | |
3e6179b8 TI |
1341 | /* Check the validity of ALC subsystem-id |
1342 | * ports contains an array of 4 pin NIDs for port-A, E, D and I */ | |
1343 | static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports) | |
4a79ba34 | 1344 | { |
3e6179b8 | 1345 | if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) { |
4a79ba34 TI |
1346 | struct alc_spec *spec = codec->spec; |
1347 | snd_printd("realtek: " | |
1348 | "Enable default setup for auto mode as fallback\n"); | |
1349 | spec->init_amp = ALC_INIT_DEFAULT; | |
4a79ba34 | 1350 | } |
21268961 | 1351 | } |
1a1455de | 1352 | |
f95474ec | 1353 | /* |
f8f25ba3 | 1354 | * Fix-up pin default configurations and add default verbs |
f95474ec TI |
1355 | */ |
1356 | ||
1357 | struct alc_pincfg { | |
1358 | hda_nid_t nid; | |
1359 | u32 val; | |
1360 | }; | |
1361 | ||
e1eb5f10 TB |
1362 | struct alc_model_fixup { |
1363 | const int id; | |
1364 | const char *name; | |
1365 | }; | |
1366 | ||
f8f25ba3 | 1367 | struct alc_fixup { |
b5bfbc67 | 1368 | int type; |
361fe6e9 TI |
1369 | bool chained; |
1370 | int chain_id; | |
b5bfbc67 TI |
1371 | union { |
1372 | unsigned int sku; | |
1373 | const struct alc_pincfg *pins; | |
1374 | const struct hda_verb *verbs; | |
1375 | void (*func)(struct hda_codec *codec, | |
1376 | const struct alc_fixup *fix, | |
1377 | int action); | |
1378 | } v; | |
f8f25ba3 TI |
1379 | }; |
1380 | ||
b5bfbc67 TI |
1381 | enum { |
1382 | ALC_FIXUP_INVALID, | |
1383 | ALC_FIXUP_SKU, | |
1384 | ALC_FIXUP_PINS, | |
1385 | ALC_FIXUP_VERBS, | |
1386 | ALC_FIXUP_FUNC, | |
1387 | }; | |
1388 | ||
1389 | enum { | |
1390 | ALC_FIXUP_ACT_PRE_PROBE, | |
1391 | ALC_FIXUP_ACT_PROBE, | |
58701120 | 1392 | ALC_FIXUP_ACT_INIT, |
b5bfbc67 TI |
1393 | }; |
1394 | ||
1395 | static void alc_apply_fixup(struct hda_codec *codec, int action) | |
f95474ec | 1396 | { |
b5bfbc67 TI |
1397 | struct alc_spec *spec = codec->spec; |
1398 | int id = spec->fixup_id; | |
aa1d0c52 | 1399 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
b5bfbc67 | 1400 | const char *modelname = spec->fixup_name; |
aa1d0c52 | 1401 | #endif |
b5bfbc67 | 1402 | int depth = 0; |
f95474ec | 1403 | |
b5bfbc67 TI |
1404 | if (!spec->fixup_list) |
1405 | return; | |
1406 | ||
1407 | while (id >= 0) { | |
1408 | const struct alc_fixup *fix = spec->fixup_list + id; | |
1409 | const struct alc_pincfg *cfg; | |
1410 | ||
1411 | switch (fix->type) { | |
1412 | case ALC_FIXUP_SKU: | |
1413 | if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku) | |
1414 | break;; | |
1415 | snd_printdd(KERN_INFO "hda_codec: %s: " | |
1416 | "Apply sku override for %s\n", | |
1417 | codec->chip_name, modelname); | |
1418 | spec->cdefine.sku_cfg = fix->v.sku; | |
1419 | spec->cdefine.fixup = 1; | |
1420 | break; | |
1421 | case ALC_FIXUP_PINS: | |
1422 | cfg = fix->v.pins; | |
1423 | if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg) | |
1424 | break; | |
1425 | snd_printdd(KERN_INFO "hda_codec: %s: " | |
1426 | "Apply pincfg for %s\n", | |
1427 | codec->chip_name, modelname); | |
1428 | for (; cfg->nid; cfg++) | |
1429 | snd_hda_codec_set_pincfg(codec, cfg->nid, | |
1430 | cfg->val); | |
1431 | break; | |
1432 | case ALC_FIXUP_VERBS: | |
1433 | if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs) | |
1434 | break; | |
1435 | snd_printdd(KERN_INFO "hda_codec: %s: " | |
1436 | "Apply fix-verbs for %s\n", | |
1437 | codec->chip_name, modelname); | |
1438 | add_verb(codec->spec, fix->v.verbs); | |
1439 | break; | |
1440 | case ALC_FIXUP_FUNC: | |
1441 | if (!fix->v.func) | |
1442 | break; | |
1443 | snd_printdd(KERN_INFO "hda_codec: %s: " | |
1444 | "Apply fix-func for %s\n", | |
1445 | codec->chip_name, modelname); | |
1446 | fix->v.func(codec, fix, action); | |
1447 | break; | |
1448 | default: | |
1449 | snd_printk(KERN_ERR "hda_codec: %s: " | |
1450 | "Invalid fixup type %d\n", | |
1451 | codec->chip_name, fix->type); | |
1452 | break; | |
1453 | } | |
24af2b1c | 1454 | if (!fix->chained) |
b5bfbc67 TI |
1455 | break; |
1456 | if (++depth > 10) | |
1457 | break; | |
24af2b1c | 1458 | id = fix->chain_id; |
9d57883f | 1459 | } |
f95474ec TI |
1460 | } |
1461 | ||
e1eb5f10 | 1462 | static void alc_pick_fixup(struct hda_codec *codec, |
b5bfbc67 TI |
1463 | const struct alc_model_fixup *models, |
1464 | const struct snd_pci_quirk *quirk, | |
1465 | const struct alc_fixup *fixlist) | |
e1eb5f10 | 1466 | { |
b5bfbc67 TI |
1467 | struct alc_spec *spec = codec->spec; |
1468 | int id = -1; | |
1469 | const char *name = NULL; | |
e1eb5f10 | 1470 | |
e1eb5f10 TB |
1471 | if (codec->modelname && models) { |
1472 | while (models->name) { | |
1473 | if (!strcmp(codec->modelname, models->name)) { | |
b5bfbc67 TI |
1474 | id = models->id; |
1475 | name = models->name; | |
e1eb5f10 TB |
1476 | break; |
1477 | } | |
1478 | models++; | |
1479 | } | |
b5bfbc67 TI |
1480 | } |
1481 | if (id < 0) { | |
1482 | quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk); | |
1483 | if (quirk) { | |
1484 | id = quirk->value; | |
1485 | #ifdef CONFIG_SND_DEBUG_VERBOSE | |
1486 | name = quirk->name; | |
1487 | #endif | |
1488 | } | |
1489 | } | |
1490 | ||
1491 | spec->fixup_id = id; | |
1492 | if (id >= 0) { | |
1493 | spec->fixup_list = fixlist; | |
1494 | spec->fixup_name = name; | |
e1eb5f10 | 1495 | } |
f95474ec TI |
1496 | } |
1497 | ||
1d045db9 TI |
1498 | /* |
1499 | * COEF access helper functions | |
1500 | */ | |
274693f3 KY |
1501 | static int alc_read_coef_idx(struct hda_codec *codec, |
1502 | unsigned int coef_idx) | |
1503 | { | |
1504 | unsigned int val; | |
1505 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, | |
1506 | coef_idx); | |
1507 | val = snd_hda_codec_read(codec, 0x20, 0, | |
1508 | AC_VERB_GET_PROC_COEF, 0); | |
1509 | return val; | |
1510 | } | |
1511 | ||
977ddd6b KY |
1512 | static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx, |
1513 | unsigned int coef_val) | |
1514 | { | |
1515 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, | |
1516 | coef_idx); | |
1517 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, | |
1518 | coef_val); | |
1519 | } | |
1520 | ||
1d045db9 TI |
1521 | /* |
1522 | * Digital I/O handling | |
1523 | */ | |
1524 | ||
757899ac TI |
1525 | /* set right pin controls for digital I/O */ |
1526 | static void alc_auto_init_digital(struct hda_codec *codec) | |
1527 | { | |
1528 | struct alc_spec *spec = codec->spec; | |
1529 | int i; | |
1f0f4b80 | 1530 | hda_nid_t pin, dac; |
757899ac TI |
1531 | |
1532 | for (i = 0; i < spec->autocfg.dig_outs; i++) { | |
1533 | pin = spec->autocfg.dig_out_pins[i]; | |
1f0f4b80 TI |
1534 | if (!pin) |
1535 | continue; | |
1536 | snd_hda_codec_write(codec, pin, 0, | |
1537 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); | |
1538 | if (!i) | |
1539 | dac = spec->multiout.dig_out_nid; | |
1540 | else | |
1541 | dac = spec->slave_dig_outs[i - 1]; | |
1542 | if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP)) | |
1543 | continue; | |
1544 | snd_hda_codec_write(codec, dac, 0, | |
1545 | AC_VERB_SET_AMP_GAIN_MUTE, | |
1546 | AMP_OUT_UNMUTE); | |
757899ac TI |
1547 | } |
1548 | pin = spec->autocfg.dig_in_pin; | |
1549 | if (pin) | |
1550 | snd_hda_codec_write(codec, pin, 0, | |
1551 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
1552 | PIN_IN); | |
1553 | } | |
1554 | ||
1555 | /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */ | |
1556 | static void alc_auto_parse_digital(struct hda_codec *codec) | |
1557 | { | |
1558 | struct alc_spec *spec = codec->spec; | |
1559 | int i, err; | |
1560 | hda_nid_t dig_nid; | |
1561 | ||
1562 | /* support multiple SPDIFs; the secondary is set up as a slave */ | |
1563 | for (i = 0; i < spec->autocfg.dig_outs; i++) { | |
a926757f | 1564 | hda_nid_t conn[4]; |
757899ac TI |
1565 | err = snd_hda_get_connections(codec, |
1566 | spec->autocfg.dig_out_pins[i], | |
a926757f | 1567 | conn, ARRAY_SIZE(conn)); |
757899ac TI |
1568 | if (err < 0) |
1569 | continue; | |
a926757f | 1570 | dig_nid = conn[0]; /* assume the first element is audio-out */ |
757899ac TI |
1571 | if (!i) { |
1572 | spec->multiout.dig_out_nid = dig_nid; | |
1573 | spec->dig_out_type = spec->autocfg.dig_out_type[0]; | |
1574 | } else { | |
1575 | spec->multiout.slave_dig_outs = spec->slave_dig_outs; | |
1576 | if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1) | |
1577 | break; | |
1578 | spec->slave_dig_outs[i - 1] = dig_nid; | |
1579 | } | |
1580 | } | |
1581 | ||
1582 | if (spec->autocfg.dig_in_pin) { | |
01fdf180 TI |
1583 | dig_nid = codec->start_nid; |
1584 | for (i = 0; i < codec->num_nodes; i++, dig_nid++) { | |
1585 | unsigned int wcaps = get_wcaps(codec, dig_nid); | |
1586 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) | |
1587 | continue; | |
1588 | if (!(wcaps & AC_WCAP_DIGITAL)) | |
1589 | continue; | |
1590 | if (!(wcaps & AC_WCAP_CONN_LIST)) | |
1591 | continue; | |
1592 | err = get_connection_index(codec, dig_nid, | |
1593 | spec->autocfg.dig_in_pin); | |
1594 | if (err >= 0) { | |
1595 | spec->dig_in_nid = dig_nid; | |
1596 | break; | |
1597 | } | |
1598 | } | |
757899ac TI |
1599 | } |
1600 | } | |
1601 | ||
ef8ef5fb | 1602 | /* |
1d045db9 | 1603 | * capture mixer elements |
ef8ef5fb | 1604 | */ |
f9e336f6 TI |
1605 | static int alc_cap_vol_info(struct snd_kcontrol *kcontrol, |
1606 | struct snd_ctl_elem_info *uinfo) | |
1607 | { | |
1608 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1609 | struct alc_spec *spec = codec->spec; | |
d6cc9fab | 1610 | unsigned long val; |
f9e336f6 | 1611 | int err; |
1da177e4 | 1612 | |
5a9e02e9 | 1613 | mutex_lock(&codec->control_mutex); |
d6cc9fab TI |
1614 | if (spec->vol_in_capsrc) |
1615 | val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT); | |
1616 | else | |
1617 | val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT); | |
1618 | kcontrol->private_value = val; | |
f9e336f6 | 1619 | err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo); |
5a9e02e9 | 1620 | mutex_unlock(&codec->control_mutex); |
f9e336f6 TI |
1621 | return err; |
1622 | } | |
1623 | ||
1624 | static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, | |
1625 | unsigned int size, unsigned int __user *tlv) | |
1626 | { | |
1627 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1628 | struct alc_spec *spec = codec->spec; | |
d6cc9fab | 1629 | unsigned long val; |
f9e336f6 | 1630 | int err; |
1da177e4 | 1631 | |
5a9e02e9 | 1632 | mutex_lock(&codec->control_mutex); |
d6cc9fab TI |
1633 | if (spec->vol_in_capsrc) |
1634 | val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT); | |
1635 | else | |
1636 | val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT); | |
1637 | kcontrol->private_value = val; | |
f9e336f6 | 1638 | err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv); |
5a9e02e9 | 1639 | mutex_unlock(&codec->control_mutex); |
f9e336f6 TI |
1640 | return err; |
1641 | } | |
1642 | ||
1643 | typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol, | |
1644 | struct snd_ctl_elem_value *ucontrol); | |
1645 | ||
1646 | static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol, | |
1647 | struct snd_ctl_elem_value *ucontrol, | |
9c7a083d | 1648 | getput_call_t func, bool check_adc_switch) |
f9e336f6 TI |
1649 | { |
1650 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1651 | struct alc_spec *spec = codec->spec; | |
21268961 | 1652 | int i, err = 0; |
f9e336f6 | 1653 | |
5a9e02e9 | 1654 | mutex_lock(&codec->control_mutex); |
21268961 | 1655 | if (check_adc_switch && spec->dyn_adc_switch) { |
9c7a083d TI |
1656 | for (i = 0; i < spec->num_adc_nids; i++) { |
1657 | kcontrol->private_value = | |
1658 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], | |
1659 | 3, 0, HDA_INPUT); | |
1660 | err = func(kcontrol, ucontrol); | |
1661 | if (err < 0) | |
1662 | goto error; | |
1663 | } | |
1664 | } else { | |
1665 | i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
d6cc9fab TI |
1666 | if (spec->vol_in_capsrc) |
1667 | kcontrol->private_value = | |
1668 | HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i], | |
1669 | 3, 0, HDA_OUTPUT); | |
1670 | else | |
1671 | kcontrol->private_value = | |
21268961 TI |
1672 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], |
1673 | 3, 0, HDA_INPUT); | |
9c7a083d TI |
1674 | err = func(kcontrol, ucontrol); |
1675 | } | |
1676 | error: | |
5a9e02e9 | 1677 | mutex_unlock(&codec->control_mutex); |
f9e336f6 TI |
1678 | return err; |
1679 | } | |
1680 | ||
1681 | static int alc_cap_vol_get(struct snd_kcontrol *kcontrol, | |
1682 | struct snd_ctl_elem_value *ucontrol) | |
1683 | { | |
1684 | return alc_cap_getput_caller(kcontrol, ucontrol, | |
9c7a083d | 1685 | snd_hda_mixer_amp_volume_get, false); |
f9e336f6 TI |
1686 | } |
1687 | ||
1688 | static int alc_cap_vol_put(struct snd_kcontrol *kcontrol, | |
1689 | struct snd_ctl_elem_value *ucontrol) | |
1690 | { | |
1691 | return alc_cap_getput_caller(kcontrol, ucontrol, | |
9c7a083d | 1692 | snd_hda_mixer_amp_volume_put, true); |
f9e336f6 TI |
1693 | } |
1694 | ||
1695 | /* capture mixer elements */ | |
1696 | #define alc_cap_sw_info snd_ctl_boolean_stereo_info | |
1697 | ||
1698 | static int alc_cap_sw_get(struct snd_kcontrol *kcontrol, | |
1699 | struct snd_ctl_elem_value *ucontrol) | |
1700 | { | |
1701 | return alc_cap_getput_caller(kcontrol, ucontrol, | |
9c7a083d | 1702 | snd_hda_mixer_amp_switch_get, false); |
f9e336f6 TI |
1703 | } |
1704 | ||
1705 | static int alc_cap_sw_put(struct snd_kcontrol *kcontrol, | |
1706 | struct snd_ctl_elem_value *ucontrol) | |
1707 | { | |
1708 | return alc_cap_getput_caller(kcontrol, ucontrol, | |
9c7a083d | 1709 | snd_hda_mixer_amp_switch_put, true); |
f9e336f6 TI |
1710 | } |
1711 | ||
a23b688f | 1712 | #define _DEFINE_CAPMIX(num) \ |
f9e336f6 TI |
1713 | { \ |
1714 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
1715 | .name = "Capture Switch", \ | |
1716 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \ | |
1717 | .count = num, \ | |
1718 | .info = alc_cap_sw_info, \ | |
1719 | .get = alc_cap_sw_get, \ | |
1720 | .put = alc_cap_sw_put, \ | |
1721 | }, \ | |
1722 | { \ | |
1723 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
1724 | .name = "Capture Volume", \ | |
1725 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \ | |
1726 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ | |
1727 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \ | |
1728 | .count = num, \ | |
1729 | .info = alc_cap_vol_info, \ | |
1730 | .get = alc_cap_vol_get, \ | |
1731 | .put = alc_cap_vol_put, \ | |
1732 | .tlv = { .c = alc_cap_vol_tlv }, \ | |
a23b688f TI |
1733 | } |
1734 | ||
1735 | #define _DEFINE_CAPSRC(num) \ | |
3c3e9892 TI |
1736 | { \ |
1737 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
1738 | /* .name = "Capture Source", */ \ | |
1739 | .name = "Input Source", \ | |
1740 | .count = num, \ | |
1741 | .info = alc_mux_enum_info, \ | |
1742 | .get = alc_mux_enum_get, \ | |
1743 | .put = alc_mux_enum_put, \ | |
a23b688f TI |
1744 | } |
1745 | ||
1746 | #define DEFINE_CAPMIX(num) \ | |
a9111321 | 1747 | static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \ |
a23b688f TI |
1748 | _DEFINE_CAPMIX(num), \ |
1749 | _DEFINE_CAPSRC(num), \ | |
1750 | { } /* end */ \ | |
1751 | } | |
1752 | ||
1753 | #define DEFINE_CAPMIX_NOSRC(num) \ | |
a9111321 | 1754 | static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \ |
a23b688f TI |
1755 | _DEFINE_CAPMIX(num), \ |
1756 | { } /* end */ \ | |
f9e336f6 TI |
1757 | } |
1758 | ||
1759 | /* up to three ADCs */ | |
1760 | DEFINE_CAPMIX(1); | |
1761 | DEFINE_CAPMIX(2); | |
1762 | DEFINE_CAPMIX(3); | |
a23b688f TI |
1763 | DEFINE_CAPMIX_NOSRC(1); |
1764 | DEFINE_CAPMIX_NOSRC(2); | |
1765 | DEFINE_CAPMIX_NOSRC(3); | |
e9edcee0 TI |
1766 | |
1767 | /* | |
1d045db9 | 1768 | * virtual master controls |
e9edcee0 TI |
1769 | */ |
1770 | ||
e9edcee0 | 1771 | /* |
1d045db9 | 1772 | * slave controls for virtual master |
e9edcee0 | 1773 | */ |
1d045db9 TI |
1774 | static const char * const alc_slave_vols[] = { |
1775 | "Front Playback Volume", | |
1776 | "Surround Playback Volume", | |
1777 | "Center Playback Volume", | |
1778 | "LFE Playback Volume", | |
1779 | "Side Playback Volume", | |
1780 | "Headphone Playback Volume", | |
1781 | "Speaker Playback Volume", | |
1782 | "Mono Playback Volume", | |
1783 | "Line-Out Playback Volume", | |
1784 | NULL, | |
e9edcee0 TI |
1785 | }; |
1786 | ||
1d045db9 TI |
1787 | static const char * const alc_slave_sws[] = { |
1788 | "Front Playback Switch", | |
1789 | "Surround Playback Switch", | |
1790 | "Center Playback Switch", | |
1791 | "LFE Playback Switch", | |
1792 | "Side Playback Switch", | |
1793 | "Headphone Playback Switch", | |
1794 | "Speaker Playback Switch", | |
1795 | "Mono Playback Switch", | |
1796 | "IEC958 Playback Switch", | |
1797 | "Line-Out Playback Switch", | |
1798 | NULL, | |
16ded525 TI |
1799 | }; |
1800 | ||
e9edcee0 | 1801 | /* |
1d045db9 | 1802 | * build control elements |
e9edcee0 TI |
1803 | */ |
1804 | ||
1d045db9 | 1805 | #define NID_MAPPING (-1) |
e9edcee0 | 1806 | |
1d045db9 TI |
1807 | #define SUBDEV_SPEAKER_ (0 << 6) |
1808 | #define SUBDEV_HP_ (1 << 6) | |
1809 | #define SUBDEV_LINE_ (2 << 6) | |
1810 | #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f)) | |
1811 | #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f)) | |
1812 | #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f)) | |
e9edcee0 | 1813 | |
1d045db9 | 1814 | static void alc_free_kctls(struct hda_codec *codec); |
e9edcee0 | 1815 | |
1d045db9 TI |
1816 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
1817 | /* additional beep mixers; the actual parameters are overwritten at build */ | |
1818 | static const struct snd_kcontrol_new alc_beep_mixer[] = { | |
1819 | HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT), | |
1820 | HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT), | |
16ded525 TI |
1821 | { } /* end */ |
1822 | }; | |
1d045db9 | 1823 | #endif |
16ded525 | 1824 | |
1d045db9 TI |
1825 | static int alc_build_controls(struct hda_codec *codec) |
1826 | { | |
1827 | struct alc_spec *spec = codec->spec; | |
1828 | struct snd_kcontrol *kctl = NULL; | |
1829 | const struct snd_kcontrol_new *knew; | |
1830 | int i, j, err; | |
1831 | unsigned int u; | |
1832 | hda_nid_t nid; | |
1da177e4 LT |
1833 | |
1834 | for (i = 0; i < spec->num_mixers; i++) { | |
1835 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | |
1836 | if (err < 0) | |
1837 | return err; | |
1838 | } | |
f9e336f6 TI |
1839 | if (spec->cap_mixer) { |
1840 | err = snd_hda_add_new_ctls(codec, spec->cap_mixer); | |
1841 | if (err < 0) | |
1842 | return err; | |
1843 | } | |
1da177e4 | 1844 | if (spec->multiout.dig_out_nid) { |
9c7f852e | 1845 | err = snd_hda_create_spdif_out_ctls(codec, |
74b654c9 | 1846 | spec->multiout.dig_out_nid, |
9c7f852e | 1847 | spec->multiout.dig_out_nid); |
1da177e4 LT |
1848 | if (err < 0) |
1849 | return err; | |
e64f14f4 TI |
1850 | if (!spec->no_analog) { |
1851 | err = snd_hda_create_spdif_share_sw(codec, | |
1852 | &spec->multiout); | |
1853 | if (err < 0) | |
1854 | return err; | |
1855 | spec->multiout.share_spdif = 1; | |
1856 | } | |
1da177e4 LT |
1857 | } |
1858 | if (spec->dig_in_nid) { | |
1859 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); | |
1860 | if (err < 0) | |
1861 | return err; | |
1862 | } | |
2134ea4f | 1863 | |
67d634c0 | 1864 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
45bdd1c1 TI |
1865 | /* create beep controls if needed */ |
1866 | if (spec->beep_amp) { | |
a9111321 | 1867 | const struct snd_kcontrol_new *knew; |
45bdd1c1 TI |
1868 | for (knew = alc_beep_mixer; knew->name; knew++) { |
1869 | struct snd_kcontrol *kctl; | |
1870 | kctl = snd_ctl_new1(knew, codec); | |
1871 | if (!kctl) | |
1872 | return -ENOMEM; | |
1873 | kctl->private_value = spec->beep_amp; | |
5e26dfd0 | 1874 | err = snd_hda_ctl_add(codec, 0, kctl); |
45bdd1c1 TI |
1875 | if (err < 0) |
1876 | return err; | |
1877 | } | |
1878 | } | |
67d634c0 | 1879 | #endif |
45bdd1c1 | 1880 | |
2134ea4f | 1881 | /* if we have no master control, let's create it */ |
e64f14f4 TI |
1882 | if (!spec->no_analog && |
1883 | !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { | |
1c82ed1b | 1884 | unsigned int vmaster_tlv[4]; |
2134ea4f | 1885 | snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, |
1c82ed1b | 1886 | HDA_OUTPUT, vmaster_tlv); |
2134ea4f | 1887 | err = snd_hda_add_vmaster(codec, "Master Playback Volume", |
1c82ed1b | 1888 | vmaster_tlv, alc_slave_vols); |
2134ea4f TI |
1889 | if (err < 0) |
1890 | return err; | |
1891 | } | |
e64f14f4 TI |
1892 | if (!spec->no_analog && |
1893 | !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { | |
2134ea4f TI |
1894 | err = snd_hda_add_vmaster(codec, "Master Playback Switch", |
1895 | NULL, alc_slave_sws); | |
1896 | if (err < 0) | |
1897 | return err; | |
1898 | } | |
1899 | ||
5b0cb1d8 | 1900 | /* assign Capture Source enums to NID */ |
fbe618f2 TI |
1901 | if (spec->capsrc_nids || spec->adc_nids) { |
1902 | kctl = snd_hda_find_mixer_ctl(codec, "Capture Source"); | |
1903 | if (!kctl) | |
1904 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); | |
1905 | for (i = 0; kctl && i < kctl->count; i++) { | |
4c6d72d1 | 1906 | const hda_nid_t *nids = spec->capsrc_nids; |
fbe618f2 TI |
1907 | if (!nids) |
1908 | nids = spec->adc_nids; | |
1909 | err = snd_hda_add_nid(codec, kctl, i, nids[i]); | |
1910 | if (err < 0) | |
1911 | return err; | |
1912 | } | |
5b0cb1d8 JK |
1913 | } |
1914 | if (spec->cap_mixer) { | |
1915 | const char *kname = kctl ? kctl->id.name : NULL; | |
1916 | for (knew = spec->cap_mixer; knew->name; knew++) { | |
1917 | if (kname && strcmp(knew->name, kname) == 0) | |
1918 | continue; | |
1919 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); | |
1920 | for (i = 0; kctl && i < kctl->count; i++) { | |
1921 | err = snd_hda_add_nid(codec, kctl, i, | |
1922 | spec->adc_nids[i]); | |
1923 | if (err < 0) | |
1924 | return err; | |
1925 | } | |
1926 | } | |
1927 | } | |
1928 | ||
1929 | /* other nid->control mapping */ | |
1930 | for (i = 0; i < spec->num_mixers; i++) { | |
1931 | for (knew = spec->mixers[i]; knew->name; knew++) { | |
1932 | if (knew->iface != NID_MAPPING) | |
1933 | continue; | |
1934 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); | |
1935 | if (kctl == NULL) | |
1936 | continue; | |
1937 | u = knew->subdevice; | |
1938 | for (j = 0; j < 4; j++, u >>= 8) { | |
1939 | nid = u & 0x3f; | |
1940 | if (nid == 0) | |
1941 | continue; | |
1942 | switch (u & 0xc0) { | |
1943 | case SUBDEV_SPEAKER_: | |
1944 | nid = spec->autocfg.speaker_pins[nid]; | |
1945 | break; | |
1946 | case SUBDEV_LINE_: | |
1947 | nid = spec->autocfg.line_out_pins[nid]; | |
1948 | break; | |
1949 | case SUBDEV_HP_: | |
1950 | nid = spec->autocfg.hp_pins[nid]; | |
1951 | break; | |
1952 | default: | |
1953 | continue; | |
1954 | } | |
1955 | err = snd_hda_add_nid(codec, kctl, 0, nid); | |
1956 | if (err < 0) | |
1957 | return err; | |
1958 | } | |
1959 | u = knew->private_value; | |
1960 | for (j = 0; j < 4; j++, u >>= 8) { | |
1961 | nid = u & 0xff; | |
1962 | if (nid == 0) | |
1963 | continue; | |
1964 | err = snd_hda_add_nid(codec, kctl, 0, nid); | |
1965 | if (err < 0) | |
1966 | return err; | |
1967 | } | |
1968 | } | |
1969 | } | |
bae84e70 TI |
1970 | |
1971 | alc_free_kctls(codec); /* no longer needed */ | |
1972 | ||
1da177e4 LT |
1973 | return 0; |
1974 | } | |
1975 | ||
e9edcee0 | 1976 | |
1da177e4 | 1977 | /* |
1d045db9 | 1978 | * Common callbacks |
e9edcee0 | 1979 | */ |
1da177e4 | 1980 | |
1d045db9 | 1981 | static void alc_init_special_input_src(struct hda_codec *codec); |
1da177e4 | 1982 | |
1d045db9 TI |
1983 | static int alc_init(struct hda_codec *codec) |
1984 | { | |
1985 | struct alc_spec *spec = codec->spec; | |
1986 | unsigned int i; | |
1da177e4 | 1987 | |
1d045db9 TI |
1988 | alc_fix_pll(codec); |
1989 | alc_auto_init_amp(codec, spec->init_amp); | |
1da177e4 | 1990 | |
1d045db9 TI |
1991 | for (i = 0; i < spec->num_init_verbs; i++) |
1992 | snd_hda_sequence_write(codec, spec->init_verbs[i]); | |
1993 | alc_init_special_input_src(codec); | |
dfc0ff62 | 1994 | |
1d045db9 TI |
1995 | if (spec->init_hook) |
1996 | spec->init_hook(codec); | |
16ded525 | 1997 | |
1d045db9 | 1998 | alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT); |
16ded525 | 1999 | |
1d045db9 TI |
2000 | hda_call_check_power_status(codec, 0x01); |
2001 | return 0; | |
2002 | } | |
ea1fb29a | 2003 | |
1d045db9 TI |
2004 | static void alc_unsol_event(struct hda_codec *codec, unsigned int res) |
2005 | { | |
2006 | struct alc_spec *spec = codec->spec; | |
e9edcee0 | 2007 | |
1d045db9 TI |
2008 | if (spec->unsol_event) |
2009 | spec->unsol_event(codec, res); | |
2010 | } | |
ccc656ce | 2011 | |
1d045db9 TI |
2012 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
2013 | static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid) | |
2014 | { | |
2015 | struct alc_spec *spec = codec->spec; | |
2016 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); | |
2017 | } | |
2018 | #endif | |
ccc656ce KY |
2019 | |
2020 | /* | |
1d045db9 | 2021 | * Analog playback callbacks |
ccc656ce | 2022 | */ |
1d045db9 TI |
2023 | static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo, |
2024 | struct hda_codec *codec, | |
2025 | struct snd_pcm_substream *substream) | |
458a4fab | 2026 | { |
1d045db9 TI |
2027 | struct alc_spec *spec = codec->spec; |
2028 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, | |
2029 | hinfo); | |
458a4fab TI |
2030 | } |
2031 | ||
1d045db9 TI |
2032 | static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
2033 | struct hda_codec *codec, | |
2034 | unsigned int stream_tag, | |
2035 | unsigned int format, | |
2036 | struct snd_pcm_substream *substream) | |
458a4fab | 2037 | { |
a9fd4f3f | 2038 | struct alc_spec *spec = codec->spec; |
1d045db9 TI |
2039 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, |
2040 | stream_tag, format, substream); | |
4f5d1706 TI |
2041 | } |
2042 | ||
1d045db9 TI |
2043 | static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
2044 | struct hda_codec *codec, | |
2045 | struct snd_pcm_substream *substream) | |
4f5d1706 | 2046 | { |
1d045db9 TI |
2047 | struct alc_spec *spec = codec->spec; |
2048 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | |
ccc656ce KY |
2049 | } |
2050 | ||
1d045db9 TI |
2051 | /* |
2052 | * Digital out | |
2053 | */ | |
2054 | static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
2055 | struct hda_codec *codec, | |
2056 | struct snd_pcm_substream *substream) | |
ccc656ce | 2057 | { |
1d045db9 TI |
2058 | struct alc_spec *spec = codec->spec; |
2059 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | |
ccc656ce KY |
2060 | } |
2061 | ||
1d045db9 TI |
2062 | static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
2063 | struct hda_codec *codec, | |
2064 | unsigned int stream_tag, | |
2065 | unsigned int format, | |
2066 | struct snd_pcm_substream *substream) | |
ccc656ce | 2067 | { |
a9fd4f3f | 2068 | struct alc_spec *spec = codec->spec; |
1d045db9 TI |
2069 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
2070 | stream_tag, format, substream); | |
ccc656ce KY |
2071 | } |
2072 | ||
1d045db9 TI |
2073 | static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
2074 | struct hda_codec *codec, | |
2075 | struct snd_pcm_substream *substream) | |
ccc656ce | 2076 | { |
1d045db9 TI |
2077 | struct alc_spec *spec = codec->spec; |
2078 | return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); | |
ccc656ce | 2079 | } |
47fd830a | 2080 | |
1d045db9 TI |
2081 | static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
2082 | struct hda_codec *codec, | |
2083 | struct snd_pcm_substream *substream) | |
ccc656ce | 2084 | { |
1d045db9 TI |
2085 | struct alc_spec *spec = codec->spec; |
2086 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | |
ccc656ce KY |
2087 | } |
2088 | ||
e9edcee0 | 2089 | /* |
1d045db9 | 2090 | * Analog capture |
e9edcee0 | 2091 | */ |
1d045db9 TI |
2092 | static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
2093 | struct hda_codec *codec, | |
2094 | unsigned int stream_tag, | |
2095 | unsigned int format, | |
2096 | struct snd_pcm_substream *substream) | |
2097 | { | |
2098 | struct alc_spec *spec = codec->spec; | |
1da177e4 | 2099 | |
6330079f | 2100 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1], |
1da177e4 LT |
2101 | stream_tag, 0, format); |
2102 | return 0; | |
2103 | } | |
2104 | ||
c2d986b0 | 2105 | static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
1da177e4 | 2106 | struct hda_codec *codec, |
c8b6bf9b | 2107 | struct snd_pcm_substream *substream) |
1da177e4 LT |
2108 | { |
2109 | struct alc_spec *spec = codec->spec; | |
2110 | ||
888afa15 TI |
2111 | snd_hda_codec_cleanup_stream(codec, |
2112 | spec->adc_nids[substream->number + 1]); | |
1da177e4 LT |
2113 | return 0; |
2114 | } | |
2115 | ||
840b64c0 | 2116 | /* analog capture with dynamic dual-adc changes */ |
21268961 | 2117 | static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
840b64c0 TI |
2118 | struct hda_codec *codec, |
2119 | unsigned int stream_tag, | |
2120 | unsigned int format, | |
2121 | struct snd_pcm_substream *substream) | |
2122 | { | |
2123 | struct alc_spec *spec = codec->spec; | |
21268961 | 2124 | spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]]; |
840b64c0 TI |
2125 | spec->cur_adc_stream_tag = stream_tag; |
2126 | spec->cur_adc_format = format; | |
2127 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); | |
2128 | return 0; | |
2129 | } | |
2130 | ||
21268961 | 2131 | static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
840b64c0 TI |
2132 | struct hda_codec *codec, |
2133 | struct snd_pcm_substream *substream) | |
2134 | { | |
2135 | struct alc_spec *spec = codec->spec; | |
2136 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); | |
2137 | spec->cur_adc = 0; | |
2138 | return 0; | |
2139 | } | |
2140 | ||
21268961 | 2141 | static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = { |
840b64c0 TI |
2142 | .substreams = 1, |
2143 | .channels_min = 2, | |
2144 | .channels_max = 2, | |
2145 | .nid = 0, /* fill later */ | |
2146 | .ops = { | |
21268961 TI |
2147 | .prepare = dyn_adc_capture_pcm_prepare, |
2148 | .cleanup = dyn_adc_capture_pcm_cleanup | |
840b64c0 TI |
2149 | }, |
2150 | }; | |
1da177e4 LT |
2151 | |
2152 | /* | |
2153 | */ | |
c2d986b0 | 2154 | static const struct hda_pcm_stream alc_pcm_analog_playback = { |
1da177e4 LT |
2155 | .substreams = 1, |
2156 | .channels_min = 2, | |
2157 | .channels_max = 8, | |
e9edcee0 | 2158 | /* NID is set in alc_build_pcms */ |
1da177e4 | 2159 | .ops = { |
c2d986b0 TI |
2160 | .open = alc_playback_pcm_open, |
2161 | .prepare = alc_playback_pcm_prepare, | |
2162 | .cleanup = alc_playback_pcm_cleanup | |
1da177e4 LT |
2163 | }, |
2164 | }; | |
2165 | ||
c2d986b0 | 2166 | static const struct hda_pcm_stream alc_pcm_analog_capture = { |
6330079f TI |
2167 | .substreams = 1, |
2168 | .channels_min = 2, | |
2169 | .channels_max = 2, | |
2170 | /* NID is set in alc_build_pcms */ | |
2171 | }; | |
2172 | ||
c2d986b0 | 2173 | static const struct hda_pcm_stream alc_pcm_analog_alt_playback = { |
6330079f TI |
2174 | .substreams = 1, |
2175 | .channels_min = 2, | |
2176 | .channels_max = 2, | |
2177 | /* NID is set in alc_build_pcms */ | |
2178 | }; | |
2179 | ||
c2d986b0 | 2180 | static const struct hda_pcm_stream alc_pcm_analog_alt_capture = { |
6330079f | 2181 | .substreams = 2, /* can be overridden */ |
1da177e4 LT |
2182 | .channels_min = 2, |
2183 | .channels_max = 2, | |
e9edcee0 | 2184 | /* NID is set in alc_build_pcms */ |
1da177e4 | 2185 | .ops = { |
c2d986b0 TI |
2186 | .prepare = alc_alt_capture_pcm_prepare, |
2187 | .cleanup = alc_alt_capture_pcm_cleanup | |
1da177e4 LT |
2188 | }, |
2189 | }; | |
2190 | ||
c2d986b0 | 2191 | static const struct hda_pcm_stream alc_pcm_digital_playback = { |
1da177e4 LT |
2192 | .substreams = 1, |
2193 | .channels_min = 2, | |
2194 | .channels_max = 2, | |
2195 | /* NID is set in alc_build_pcms */ | |
2196 | .ops = { | |
c2d986b0 TI |
2197 | .open = alc_dig_playback_pcm_open, |
2198 | .close = alc_dig_playback_pcm_close, | |
2199 | .prepare = alc_dig_playback_pcm_prepare, | |
2200 | .cleanup = alc_dig_playback_pcm_cleanup | |
1da177e4 LT |
2201 | }, |
2202 | }; | |
2203 | ||
c2d986b0 | 2204 | static const struct hda_pcm_stream alc_pcm_digital_capture = { |
1da177e4 LT |
2205 | .substreams = 1, |
2206 | .channels_min = 2, | |
2207 | .channels_max = 2, | |
2208 | /* NID is set in alc_build_pcms */ | |
2209 | }; | |
2210 | ||
4c5186ed | 2211 | /* Used by alc_build_pcms to flag that a PCM has no playback stream */ |
a9111321 | 2212 | static const struct hda_pcm_stream alc_pcm_null_stream = { |
4c5186ed JW |
2213 | .substreams = 0, |
2214 | .channels_min = 0, | |
2215 | .channels_max = 0, | |
2216 | }; | |
2217 | ||
1da177e4 LT |
2218 | static int alc_build_pcms(struct hda_codec *codec) |
2219 | { | |
2220 | struct alc_spec *spec = codec->spec; | |
2221 | struct hda_pcm *info = spec->pcm_rec; | |
c2d986b0 | 2222 | const struct hda_pcm_stream *p; |
1da177e4 LT |
2223 | int i; |
2224 | ||
2225 | codec->num_pcms = 1; | |
2226 | codec->pcm_info = info; | |
2227 | ||
e64f14f4 TI |
2228 | if (spec->no_analog) |
2229 | goto skip_analog; | |
2230 | ||
812a2cca TI |
2231 | snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), |
2232 | "%s Analog", codec->chip_name); | |
1da177e4 | 2233 | info->name = spec->stream_name_analog; |
274693f3 | 2234 | |
c2d986b0 TI |
2235 | if (spec->multiout.dac_nids > 0) { |
2236 | p = spec->stream_analog_playback; | |
2237 | if (!p) | |
2238 | p = &alc_pcm_analog_playback; | |
2239 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | |
4a471b7d TI |
2240 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; |
2241 | } | |
c2d986b0 TI |
2242 | if (spec->adc_nids) { |
2243 | p = spec->stream_analog_capture; | |
21268961 TI |
2244 | if (!p) { |
2245 | if (spec->dyn_adc_switch) | |
2246 | p = &dyn_adc_pcm_analog_capture; | |
2247 | else | |
2248 | p = &alc_pcm_analog_capture; | |
2249 | } | |
c2d986b0 | 2250 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
4a471b7d TI |
2251 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
2252 | } | |
2253 | ||
2254 | if (spec->channel_mode) { | |
2255 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0; | |
2256 | for (i = 0; i < spec->num_channel_mode; i++) { | |
2257 | if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) { | |
2258 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels; | |
2259 | } | |
1da177e4 LT |
2260 | } |
2261 | } | |
2262 | ||
e64f14f4 | 2263 | skip_analog: |
e08a007d | 2264 | /* SPDIF for stream index #1 */ |
1da177e4 | 2265 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
812a2cca TI |
2266 | snprintf(spec->stream_name_digital, |
2267 | sizeof(spec->stream_name_digital), | |
2268 | "%s Digital", codec->chip_name); | |
e08a007d | 2269 | codec->num_pcms = 2; |
b25c9da1 | 2270 | codec->slave_dig_outs = spec->multiout.slave_dig_outs; |
c06134d7 | 2271 | info = spec->pcm_rec + 1; |
1da177e4 | 2272 | info->name = spec->stream_name_digital; |
8c441982 TI |
2273 | if (spec->dig_out_type) |
2274 | info->pcm_type = spec->dig_out_type; | |
2275 | else | |
2276 | info->pcm_type = HDA_PCM_TYPE_SPDIF; | |
c2d986b0 TI |
2277 | if (spec->multiout.dig_out_nid) { |
2278 | p = spec->stream_digital_playback; | |
2279 | if (!p) | |
2280 | p = &alc_pcm_digital_playback; | |
2281 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | |
1da177e4 LT |
2282 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; |
2283 | } | |
c2d986b0 TI |
2284 | if (spec->dig_in_nid) { |
2285 | p = spec->stream_digital_capture; | |
2286 | if (!p) | |
2287 | p = &alc_pcm_digital_capture; | |
2288 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; | |
1da177e4 LT |
2289 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; |
2290 | } | |
963f803f TI |
2291 | /* FIXME: do we need this for all Realtek codec models? */ |
2292 | codec->spdif_status_reset = 1; | |
1da177e4 LT |
2293 | } |
2294 | ||
e64f14f4 TI |
2295 | if (spec->no_analog) |
2296 | return 0; | |
2297 | ||
e08a007d TI |
2298 | /* If the use of more than one ADC is requested for the current |
2299 | * model, configure a second analog capture-only PCM. | |
2300 | */ | |
2301 | /* Additional Analaog capture for index #2 */ | |
c2d986b0 | 2302 | if (spec->alt_dac_nid || spec->num_adc_nids > 1) { |
e08a007d | 2303 | codec->num_pcms = 3; |
c06134d7 | 2304 | info = spec->pcm_rec + 2; |
e08a007d | 2305 | info->name = spec->stream_name_analog; |
6330079f | 2306 | if (spec->alt_dac_nid) { |
c2d986b0 TI |
2307 | p = spec->stream_analog_alt_playback; |
2308 | if (!p) | |
2309 | p = &alc_pcm_analog_alt_playback; | |
2310 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | |
6330079f TI |
2311 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
2312 | spec->alt_dac_nid; | |
2313 | } else { | |
2314 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = | |
2315 | alc_pcm_null_stream; | |
2316 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0; | |
2317 | } | |
c2d986b0 TI |
2318 | if (spec->num_adc_nids > 1) { |
2319 | p = spec->stream_analog_alt_capture; | |
2320 | if (!p) | |
2321 | p = &alc_pcm_analog_alt_capture; | |
2322 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; | |
6330079f TI |
2323 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
2324 | spec->adc_nids[1]; | |
2325 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = | |
2326 | spec->num_adc_nids - 1; | |
2327 | } else { | |
2328 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | |
2329 | alc_pcm_null_stream; | |
2330 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0; | |
e08a007d TI |
2331 | } |
2332 | } | |
2333 | ||
1da177e4 LT |
2334 | return 0; |
2335 | } | |
2336 | ||
a4e09aa3 TI |
2337 | static inline void alc_shutup(struct hda_codec *codec) |
2338 | { | |
1c716153 TI |
2339 | struct alc_spec *spec = codec->spec; |
2340 | ||
2341 | if (spec && spec->shutup) | |
2342 | spec->shutup(codec); | |
a4e09aa3 TI |
2343 | snd_hda_shutup_pins(codec); |
2344 | } | |
2345 | ||
603c4019 TI |
2346 | static void alc_free_kctls(struct hda_codec *codec) |
2347 | { | |
2348 | struct alc_spec *spec = codec->spec; | |
2349 | ||
2350 | if (spec->kctls.list) { | |
2351 | struct snd_kcontrol_new *kctl = spec->kctls.list; | |
2352 | int i; | |
2353 | for (i = 0; i < spec->kctls.used; i++) | |
2354 | kfree(kctl[i].name); | |
2355 | } | |
2356 | snd_array_free(&spec->kctls); | |
2357 | } | |
2358 | ||
1da177e4 LT |
2359 | static void alc_free(struct hda_codec *codec) |
2360 | { | |
e9edcee0 | 2361 | struct alc_spec *spec = codec->spec; |
e9edcee0 | 2362 | |
f12ab1e0 | 2363 | if (!spec) |
e9edcee0 TI |
2364 | return; |
2365 | ||
a4e09aa3 | 2366 | alc_shutup(codec); |
cd372fb3 | 2367 | snd_hda_input_jack_free(codec); |
603c4019 | 2368 | alc_free_kctls(codec); |
e9edcee0 | 2369 | kfree(spec); |
680cd536 | 2370 | snd_hda_detach_beep_device(codec); |
1da177e4 LT |
2371 | } |
2372 | ||
f5de24b0 | 2373 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
c97259df DC |
2374 | static void alc_power_eapd(struct hda_codec *codec) |
2375 | { | |
691f1fcc | 2376 | alc_auto_setup_eapd(codec, false); |
c97259df DC |
2377 | } |
2378 | ||
f5de24b0 HM |
2379 | static int alc_suspend(struct hda_codec *codec, pm_message_t state) |
2380 | { | |
2381 | struct alc_spec *spec = codec->spec; | |
a4e09aa3 | 2382 | alc_shutup(codec); |
f5de24b0 | 2383 | if (spec && spec->power_hook) |
c97259df | 2384 | spec->power_hook(codec); |
f5de24b0 HM |
2385 | return 0; |
2386 | } | |
2387 | #endif | |
2388 | ||
e044c39a | 2389 | #ifdef SND_HDA_NEEDS_RESUME |
e044c39a TI |
2390 | static int alc_resume(struct hda_codec *codec) |
2391 | { | |
1c716153 | 2392 | msleep(150); /* to avoid pop noise */ |
e044c39a TI |
2393 | codec->patch_ops.init(codec); |
2394 | snd_hda_codec_resume_amp(codec); | |
2395 | snd_hda_codec_resume_cache(codec); | |
9e5341b9 | 2396 | hda_call_check_power_status(codec, 0x01); |
e044c39a TI |
2397 | return 0; |
2398 | } | |
e044c39a TI |
2399 | #endif |
2400 | ||
1da177e4 LT |
2401 | /* |
2402 | */ | |
a9111321 | 2403 | static const struct hda_codec_ops alc_patch_ops = { |
1da177e4 LT |
2404 | .build_controls = alc_build_controls, |
2405 | .build_pcms = alc_build_pcms, | |
2406 | .init = alc_init, | |
2407 | .free = alc_free, | |
ae6b813a | 2408 | .unsol_event = alc_unsol_event, |
e044c39a TI |
2409 | #ifdef SND_HDA_NEEDS_RESUME |
2410 | .resume = alc_resume, | |
2411 | #endif | |
cb53c626 | 2412 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
f5de24b0 | 2413 | .suspend = alc_suspend, |
cb53c626 TI |
2414 | .check_power_status = alc_check_power_status, |
2415 | #endif | |
c97259df | 2416 | .reboot_notify = alc_shutup, |
1da177e4 LT |
2417 | }; |
2418 | ||
c027ddcd KY |
2419 | /* replace the codec chip_name with the given string */ |
2420 | static int alc_codec_rename(struct hda_codec *codec, const char *name) | |
2421 | { | |
2422 | kfree(codec->chip_name); | |
2423 | codec->chip_name = kstrdup(name, GFP_KERNEL); | |
2424 | if (!codec->chip_name) { | |
2425 | alc_free(codec); | |
2426 | return -ENOMEM; | |
2427 | } | |
2428 | return 0; | |
2429 | } | |
2430 | ||
2fa522be | 2431 | /* |
1d045db9 | 2432 | * Automatic parse of I/O pins from the BIOS configuration |
2fa522be | 2433 | */ |
2fa522be | 2434 | |
1d045db9 TI |
2435 | enum { |
2436 | ALC_CTL_WIDGET_VOL, | |
2437 | ALC_CTL_WIDGET_MUTE, | |
2438 | ALC_CTL_BIND_MUTE, | |
2fa522be | 2439 | }; |
1d045db9 TI |
2440 | static const struct snd_kcontrol_new alc_control_templates[] = { |
2441 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), | |
2442 | HDA_CODEC_MUTE(NULL, 0, 0, 0), | |
2443 | HDA_BIND_MUTE(NULL, 0, 0, 0), | |
2fa522be TI |
2444 | }; |
2445 | ||
1d045db9 TI |
2446 | /* add dynamic controls */ |
2447 | static int add_control(struct alc_spec *spec, int type, const char *name, | |
2448 | int cidx, unsigned long val) | |
e9edcee0 | 2449 | { |
c8b6bf9b | 2450 | struct snd_kcontrol_new *knew; |
e9edcee0 | 2451 | |
ce764ab2 | 2452 | knew = alc_kcontrol_new(spec); |
603c4019 TI |
2453 | if (!knew) |
2454 | return -ENOMEM; | |
1d045db9 | 2455 | *knew = alc_control_templates[type]; |
543537bd | 2456 | knew->name = kstrdup(name, GFP_KERNEL); |
f12ab1e0 | 2457 | if (!knew->name) |
e9edcee0 | 2458 | return -ENOMEM; |
66ceeb6b | 2459 | knew->index = cidx; |
4d02d1b6 | 2460 | if (get_amp_nid_(val)) |
5e26dfd0 | 2461 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
e9edcee0 | 2462 | knew->private_value = val; |
e9edcee0 TI |
2463 | return 0; |
2464 | } | |
2465 | ||
0afe5f89 TI |
2466 | static int add_control_with_pfx(struct alc_spec *spec, int type, |
2467 | const char *pfx, const char *dir, | |
66ceeb6b | 2468 | const char *sfx, int cidx, unsigned long val) |
0afe5f89 TI |
2469 | { |
2470 | char name[32]; | |
2471 | snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx); | |
66ceeb6b | 2472 | return add_control(spec, type, name, cidx, val); |
0afe5f89 TI |
2473 | } |
2474 | ||
66ceeb6b TI |
2475 | #define add_pb_vol_ctrl(spec, type, pfx, val) \ |
2476 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val) | |
2477 | #define add_pb_sw_ctrl(spec, type, pfx, val) \ | |
2478 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val) | |
2479 | #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \ | |
2480 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val) | |
2481 | #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \ | |
2482 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val) | |
0afe5f89 | 2483 | |
6843ca16 TI |
2484 | static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch, |
2485 | bool can_be_master, int *index) | |
bcb2f0f5 | 2486 | { |
ce764ab2 | 2487 | struct auto_pin_cfg *cfg = &spec->autocfg; |
6843ca16 TI |
2488 | static const char * const chname[4] = { |
2489 | "Front", "Surround", NULL /*CLFE*/, "Side" | |
2490 | }; | |
ce764ab2 | 2491 | |
6843ca16 | 2492 | *index = 0; |
ce764ab2 TI |
2493 | if (cfg->line_outs == 1 && !spec->multi_ios && |
2494 | !cfg->hp_outs && !cfg->speaker_outs && can_be_master) | |
bcb2f0f5 TI |
2495 | return "Master"; |
2496 | ||
2497 | switch (cfg->line_out_type) { | |
2498 | case AUTO_PIN_SPEAKER_OUT: | |
ebbeb3d6 DH |
2499 | if (cfg->line_outs == 1) |
2500 | return "Speaker"; | |
2501 | break; | |
bcb2f0f5 | 2502 | case AUTO_PIN_HP_OUT: |
6843ca16 TI |
2503 | /* for multi-io case, only the primary out */ |
2504 | if (ch && spec->multi_ios) | |
2505 | break; | |
2506 | *index = ch; | |
bcb2f0f5 TI |
2507 | return "Headphone"; |
2508 | default: | |
ce764ab2 | 2509 | if (cfg->line_outs == 1 && !spec->multi_ios) |
bcb2f0f5 TI |
2510 | return "PCM"; |
2511 | break; | |
2512 | } | |
6843ca16 | 2513 | return chname[ch]; |
bcb2f0f5 TI |
2514 | } |
2515 | ||
e9edcee0 | 2516 | /* create input playback/capture controls for the given pin */ |
f12ab1e0 | 2517 | static int new_analog_input(struct alc_spec *spec, hda_nid_t pin, |
66ceeb6b | 2518 | const char *ctlname, int ctlidx, |
df694daa | 2519 | int idx, hda_nid_t mix_nid) |
e9edcee0 | 2520 | { |
df694daa | 2521 | int err; |
e9edcee0 | 2522 | |
66ceeb6b | 2523 | err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, |
f12ab1e0 TI |
2524 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
2525 | if (err < 0) | |
e9edcee0 | 2526 | return err; |
66ceeb6b | 2527 | err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, |
f12ab1e0 TI |
2528 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
2529 | if (err < 0) | |
e9edcee0 TI |
2530 | return err; |
2531 | return 0; | |
2532 | } | |
2533 | ||
05f5f477 TI |
2534 | static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid) |
2535 | { | |
2536 | unsigned int pincap = snd_hda_query_pin_caps(codec, nid); | |
2537 | return (pincap & AC_PINCAP_IN) != 0; | |
2538 | } | |
2539 | ||
1d045db9 | 2540 | /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */ |
d6cc9fab | 2541 | static int alc_auto_fill_adc_caps(struct hda_codec *codec) |
b7821709 | 2542 | { |
d6cc9fab | 2543 | struct alc_spec *spec = codec->spec; |
b7821709 | 2544 | hda_nid_t nid; |
d6cc9fab TI |
2545 | hda_nid_t *adc_nids = spec->private_adc_nids; |
2546 | hda_nid_t *cap_nids = spec->private_capsrc_nids; | |
2547 | int max_nums = ARRAY_SIZE(spec->private_adc_nids); | |
2548 | bool indep_capsrc = false; | |
b7821709 TI |
2549 | int i, nums = 0; |
2550 | ||
2551 | nid = codec->start_nid; | |
2552 | for (i = 0; i < codec->num_nodes; i++, nid++) { | |
2553 | hda_nid_t src; | |
2554 | const hda_nid_t *list; | |
2555 | unsigned int caps = get_wcaps(codec, nid); | |
2556 | int type = get_wcaps_type(caps); | |
2557 | ||
2558 | if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL)) | |
2559 | continue; | |
2560 | adc_nids[nums] = nid; | |
2561 | cap_nids[nums] = nid; | |
2562 | src = nid; | |
2563 | for (;;) { | |
2564 | int n; | |
2565 | type = get_wcaps_type(get_wcaps(codec, src)); | |
2566 | if (type == AC_WID_PIN) | |
2567 | break; | |
2568 | if (type == AC_WID_AUD_SEL) { | |
2569 | cap_nids[nums] = src; | |
d6cc9fab | 2570 | indep_capsrc = true; |
b7821709 TI |
2571 | break; |
2572 | } | |
2573 | n = snd_hda_get_conn_list(codec, src, &list); | |
2574 | if (n > 1) { | |
2575 | cap_nids[nums] = src; | |
d6cc9fab | 2576 | indep_capsrc = true; |
b7821709 TI |
2577 | break; |
2578 | } else if (n != 1) | |
2579 | break; | |
2580 | src = *list; | |
2581 | } | |
2582 | if (++nums >= max_nums) | |
2583 | break; | |
2584 | } | |
d6cc9fab | 2585 | spec->adc_nids = spec->private_adc_nids; |
21268961 | 2586 | spec->capsrc_nids = spec->private_capsrc_nids; |
d6cc9fab | 2587 | spec->num_adc_nids = nums; |
b7821709 TI |
2588 | return nums; |
2589 | } | |
2590 | ||
e9edcee0 | 2591 | /* create playback/capture controls for input pins */ |
b7821709 | 2592 | static int alc_auto_create_input_ctls(struct hda_codec *codec) |
e9edcee0 | 2593 | { |
05f5f477 | 2594 | struct alc_spec *spec = codec->spec; |
b7821709 TI |
2595 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
2596 | hda_nid_t mixer = spec->mixer_nid; | |
61b9b9b1 | 2597 | struct hda_input_mux *imux = &spec->private_imux[0]; |
b7821709 | 2598 | int num_adcs; |
b7821709 | 2599 | int i, c, err, idx, type_idx = 0; |
5322bf27 | 2600 | const char *prev_label = NULL; |
e9edcee0 | 2601 | |
d6cc9fab | 2602 | num_adcs = alc_auto_fill_adc_caps(codec); |
b7821709 TI |
2603 | if (num_adcs < 0) |
2604 | return 0; | |
2605 | ||
66ceeb6b | 2606 | for (i = 0; i < cfg->num_inputs; i++) { |
05f5f477 | 2607 | hda_nid_t pin; |
10a20af7 | 2608 | const char *label; |
05f5f477 | 2609 | |
66ceeb6b | 2610 | pin = cfg->inputs[i].pin; |
05f5f477 TI |
2611 | if (!alc_is_input_pin(codec, pin)) |
2612 | continue; | |
2613 | ||
5322bf27 DH |
2614 | label = hda_get_autocfg_input_label(codec, cfg, i); |
2615 | if (prev_label && !strcmp(label, prev_label)) | |
66ceeb6b TI |
2616 | type_idx++; |
2617 | else | |
2618 | type_idx = 0; | |
5322bf27 DH |
2619 | prev_label = label; |
2620 | ||
05f5f477 TI |
2621 | if (mixer) { |
2622 | idx = get_connection_index(codec, mixer, pin); | |
2623 | if (idx >= 0) { | |
2624 | err = new_analog_input(spec, pin, | |
10a20af7 TI |
2625 | label, type_idx, |
2626 | idx, mixer); | |
05f5f477 TI |
2627 | if (err < 0) |
2628 | return err; | |
2629 | } | |
2630 | } | |
2631 | ||
b7821709 | 2632 | for (c = 0; c < num_adcs; c++) { |
d6cc9fab TI |
2633 | hda_nid_t cap = spec->capsrc_nids ? |
2634 | spec->capsrc_nids[c] : spec->adc_nids[c]; | |
2635 | idx = get_connection_index(codec, cap, pin); | |
b7821709 | 2636 | if (idx >= 0) { |
21268961 | 2637 | spec->imux_pins[imux->num_items] = pin; |
b7821709 TI |
2638 | snd_hda_add_imux_item(imux, label, idx, NULL); |
2639 | break; | |
2640 | } | |
2641 | } | |
e9edcee0 | 2642 | } |
21268961 TI |
2643 | |
2644 | spec->num_mux_defs = 1; | |
2645 | spec->input_mux = imux; | |
2646 | ||
e9edcee0 TI |
2647 | return 0; |
2648 | } | |
2649 | ||
f6c7e546 TI |
2650 | static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid, |
2651 | unsigned int pin_type) | |
2652 | { | |
2653 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | |
2654 | pin_type); | |
2655 | /* unmute pin */ | |
44c02400 TI |
2656 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
2657 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, | |
d260cdf6 | 2658 | AMP_OUT_UNMUTE); |
f6c7e546 TI |
2659 | } |
2660 | ||
baba8ee9 TI |
2661 | static int get_pin_type(int line_out_type) |
2662 | { | |
2663 | if (line_out_type == AUTO_PIN_HP_OUT) | |
2664 | return PIN_HP; | |
2665 | else | |
2666 | return PIN_OUT; | |
2667 | } | |
2668 | ||
0a7f5320 | 2669 | static void alc_auto_init_analog_input(struct hda_codec *codec) |
e9edcee0 TI |
2670 | { |
2671 | struct alc_spec *spec = codec->spec; | |
66ceeb6b | 2672 | struct auto_pin_cfg *cfg = &spec->autocfg; |
e9edcee0 TI |
2673 | int i; |
2674 | ||
66ceeb6b TI |
2675 | for (i = 0; i < cfg->num_inputs; i++) { |
2676 | hda_nid_t nid = cfg->inputs[i].pin; | |
05f5f477 | 2677 | if (alc_is_input_pin(codec, nid)) { |
30ea098f | 2678 | alc_set_input_pin(codec, nid, cfg->inputs[i].type); |
1f0f4b80 | 2679 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
f12ab1e0 TI |
2680 | snd_hda_codec_write(codec, nid, 0, |
2681 | AC_VERB_SET_AMP_GAIN_MUTE, | |
e9edcee0 TI |
2682 | AMP_OUT_MUTE); |
2683 | } | |
2684 | } | |
1f0f4b80 TI |
2685 | |
2686 | /* mute all loopback inputs */ | |
2687 | if (spec->mixer_nid) { | |
2688 | int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL); | |
2689 | for (i = 0; i < nums; i++) | |
2690 | snd_hda_codec_write(codec, spec->mixer_nid, 0, | |
2691 | AC_VERB_SET_AMP_GAIN_MUTE, | |
2692 | AMP_IN_MUTE(i)); | |
2693 | } | |
e9edcee0 TI |
2694 | } |
2695 | ||
1d045db9 TI |
2696 | /* convert from MIX nid to DAC */ |
2697 | static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid) | |
e9edcee0 | 2698 | { |
1d045db9 TI |
2699 | hda_nid_t list[5]; |
2700 | int i, num; | |
4a79ba34 | 2701 | |
afcd5515 TI |
2702 | if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT) |
2703 | return nid; | |
1d045db9 TI |
2704 | num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list)); |
2705 | for (i = 0; i < num; i++) { | |
2706 | if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT) | |
2707 | return list[i]; | |
2708 | } | |
2709 | return 0; | |
e9edcee0 TI |
2710 | } |
2711 | ||
1d045db9 TI |
2712 | /* go down to the selector widget before the mixer */ |
2713 | static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin) | |
e9edcee0 | 2714 | { |
1d045db9 TI |
2715 | hda_nid_t srcs[5]; |
2716 | int num = snd_hda_get_connections(codec, pin, srcs, | |
2717 | ARRAY_SIZE(srcs)); | |
2718 | if (num != 1 || | |
2719 | get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL) | |
2720 | return pin; | |
2721 | return srcs[0]; | |
e9edcee0 TI |
2722 | } |
2723 | ||
1d045db9 TI |
2724 | /* get MIX nid connected to the given pin targeted to DAC */ |
2725 | static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin, | |
2726 | hda_nid_t dac) | |
748cce43 | 2727 | { |
1d045db9 TI |
2728 | hda_nid_t mix[5]; |
2729 | int i, num; | |
2730 | ||
2731 | pin = alc_go_down_to_selector(codec, pin); | |
2732 | num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix)); | |
2733 | for (i = 0; i < num; i++) { | |
2734 | if (alc_auto_mix_to_dac(codec, mix[i]) == dac) | |
2735 | return mix[i]; | |
748cce43 | 2736 | } |
1d045db9 | 2737 | return 0; |
748cce43 TI |
2738 | } |
2739 | ||
1d045db9 TI |
2740 | /* select the connection from pin to DAC if needed */ |
2741 | static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin, | |
2742 | hda_nid_t dac) | |
eaa9b3a7 | 2743 | { |
1d045db9 TI |
2744 | hda_nid_t mix[5]; |
2745 | int i, num; | |
eaa9b3a7 | 2746 | |
1d045db9 TI |
2747 | pin = alc_go_down_to_selector(codec, pin); |
2748 | num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix)); | |
2749 | if (num < 2) | |
8ed99d97 | 2750 | return 0; |
1d045db9 TI |
2751 | for (i = 0; i < num; i++) { |
2752 | if (alc_auto_mix_to_dac(codec, mix[i]) == dac) { | |
2753 | snd_hda_codec_update_cache(codec, pin, 0, | |
2754 | AC_VERB_SET_CONNECT_SEL, i); | |
2755 | return 0; | |
2756 | } | |
840b64c0 | 2757 | } |
1d045db9 | 2758 | return 0; |
840b64c0 TI |
2759 | } |
2760 | ||
1d045db9 TI |
2761 | /* look for an empty DAC slot */ |
2762 | static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin) | |
584c0c4c TI |
2763 | { |
2764 | struct alc_spec *spec = codec->spec; | |
1d045db9 TI |
2765 | hda_nid_t srcs[5]; |
2766 | int i, num; | |
21268961 | 2767 | |
1d045db9 TI |
2768 | pin = alc_go_down_to_selector(codec, pin); |
2769 | num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs)); | |
2770 | for (i = 0; i < num; i++) { | |
2771 | hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]); | |
2772 | if (!nid) | |
2773 | continue; | |
2774 | if (found_in_nid_list(nid, spec->multiout.dac_nids, | |
2775 | spec->multiout.num_dacs)) | |
2776 | continue; | |
2777 | if (spec->multiout.hp_nid == nid) | |
2778 | continue; | |
2779 | if (found_in_nid_list(nid, spec->multiout.extra_out_nid, | |
2780 | ARRAY_SIZE(spec->multiout.extra_out_nid))) | |
2781 | continue; | |
2782 | return nid; | |
2783 | } | |
2784 | return 0; | |
584c0c4c TI |
2785 | } |
2786 | ||
1d045db9 | 2787 | static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin) |
f9e336f6 | 2788 | { |
1d045db9 TI |
2789 | hda_nid_t sel = alc_go_down_to_selector(codec, pin); |
2790 | if (snd_hda_get_conn_list(codec, sel, NULL) == 1) | |
2791 | return alc_auto_look_for_dac(codec, pin); | |
2792 | return 0; | |
f9e336f6 TI |
2793 | } |
2794 | ||
1d045db9 TI |
2795 | /* fill in the dac_nids table from the parsed pin configuration */ |
2796 | static int alc_auto_fill_dac_nids(struct hda_codec *codec) | |
21268961 TI |
2797 | { |
2798 | struct alc_spec *spec = codec->spec; | |
1d045db9 TI |
2799 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
2800 | bool redone = false; | |
2801 | int i; | |
21268961 | 2802 | |
1d045db9 TI |
2803 | again: |
2804 | spec->multiout.num_dacs = 0; | |
2805 | spec->multiout.hp_nid = 0; | |
2806 | spec->multiout.extra_out_nid[0] = 0; | |
2807 | memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids)); | |
2808 | spec->multiout.dac_nids = spec->private_dac_nids; | |
21268961 | 2809 | |
1d045db9 TI |
2810 | /* fill hard-wired DACs first */ |
2811 | if (!redone) { | |
2812 | for (i = 0; i < cfg->line_outs; i++) | |
2813 | spec->private_dac_nids[i] = | |
2814 | get_dac_if_single(codec, cfg->line_out_pins[i]); | |
2815 | if (cfg->hp_outs) | |
2816 | spec->multiout.hp_nid = | |
2817 | get_dac_if_single(codec, cfg->hp_pins[0]); | |
2818 | if (cfg->speaker_outs) | |
2819 | spec->multiout.extra_out_nid[0] = | |
2820 | get_dac_if_single(codec, cfg->speaker_pins[0]); | |
21268961 TI |
2821 | } |
2822 | ||
1d045db9 TI |
2823 | for (i = 0; i < cfg->line_outs; i++) { |
2824 | hda_nid_t pin = cfg->line_out_pins[i]; | |
2825 | if (spec->private_dac_nids[i]) | |
2826 | continue; | |
2827 | spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin); | |
2828 | if (!spec->private_dac_nids[i] && !redone) { | |
2829 | /* if we can't find primary DACs, re-probe without | |
2830 | * checking the hard-wired DACs | |
2831 | */ | |
2832 | redone = true; | |
2833 | goto again; | |
21268961 TI |
2834 | } |
2835 | } | |
2836 | ||
1d045db9 TI |
2837 | for (i = 0; i < cfg->line_outs; i++) { |
2838 | if (spec->private_dac_nids[i]) | |
2839 | spec->multiout.num_dacs++; | |
2840 | else | |
2841 | memmove(spec->private_dac_nids + i, | |
2842 | spec->private_dac_nids + i + 1, | |
2843 | sizeof(hda_nid_t) * (cfg->line_outs - i - 1)); | |
2844 | } | |
2845 | ||
2846 | if (cfg->hp_outs && !spec->multiout.hp_nid) | |
2847 | spec->multiout.hp_nid = | |
2848 | alc_auto_look_for_dac(codec, cfg->hp_pins[0]); | |
2849 | if (cfg->speaker_outs && !spec->multiout.extra_out_nid[0]) | |
2850 | spec->multiout.extra_out_nid[0] = | |
2851 | alc_auto_look_for_dac(codec, cfg->speaker_pins[0]); | |
2852 | ||
2853 | return 0; | |
21268961 TI |
2854 | } |
2855 | ||
1d045db9 TI |
2856 | static int alc_auto_add_vol_ctl(struct hda_codec *codec, |
2857 | const char *pfx, int cidx, | |
2858 | hda_nid_t nid, unsigned int chs) | |
6694635d | 2859 | { |
afcd5515 TI |
2860 | if (!nid) |
2861 | return 0; | |
1d045db9 TI |
2862 | return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, |
2863 | HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); | |
2864 | } | |
6694635d | 2865 | |
1d045db9 TI |
2866 | #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \ |
2867 | alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3) | |
21268961 | 2868 | |
1d045db9 TI |
2869 | /* create a mute-switch for the given mixer widget; |
2870 | * if it has multiple sources (e.g. DAC and loopback), create a bind-mute | |
2871 | */ | |
2872 | static int alc_auto_add_sw_ctl(struct hda_codec *codec, | |
2873 | const char *pfx, int cidx, | |
2874 | hda_nid_t nid, unsigned int chs) | |
2875 | { | |
afcd5515 | 2876 | int wid_type; |
1d045db9 TI |
2877 | int type; |
2878 | unsigned long val; | |
afcd5515 TI |
2879 | if (!nid) |
2880 | return 0; | |
2881 | wid_type = get_wcaps_type(get_wcaps(codec, nid)); | |
2882 | if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) { | |
2883 | type = ALC_CTL_WIDGET_MUTE; | |
2884 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); | |
2885 | } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) { | |
1d045db9 TI |
2886 | type = ALC_CTL_WIDGET_MUTE; |
2887 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT); | |
2888 | } else { | |
2889 | type = ALC_CTL_BIND_MUTE; | |
2890 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT); | |
6694635d | 2891 | } |
1d045db9 | 2892 | return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val); |
6694635d TI |
2893 | } |
2894 | ||
1d045db9 TI |
2895 | #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \ |
2896 | alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3) | |
dc1eae25 | 2897 | |
afcd5515 TI |
2898 | static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec, |
2899 | hda_nid_t pin, hda_nid_t dac) | |
2900 | { | |
2901 | hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac); | |
2902 | if (nid_has_mute(codec, pin, HDA_OUTPUT)) | |
2903 | return pin; | |
2904 | else if (mix && nid_has_mute(codec, mix, HDA_INPUT)) | |
2905 | return mix; | |
2906 | else if (nid_has_mute(codec, dac, HDA_OUTPUT)) | |
2907 | return dac; | |
2908 | return 0; | |
2909 | } | |
2910 | ||
2911 | static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec, | |
2912 | hda_nid_t pin, hda_nid_t dac) | |
2913 | { | |
2914 | hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac); | |
2915 | if (nid_has_volume(codec, dac, HDA_OUTPUT)) | |
2916 | return dac; | |
2917 | else if (nid_has_volume(codec, mix, HDA_OUTPUT)) | |
2918 | return mix; | |
2919 | else if (nid_has_volume(codec, pin, HDA_OUTPUT)) | |
2920 | return pin; | |
2921 | return 0; | |
2922 | } | |
2923 | ||
1d045db9 TI |
2924 | /* add playback controls from the parsed DAC table */ |
2925 | static int alc_auto_create_multi_out_ctls(struct hda_codec *codec, | |
2926 | const struct auto_pin_cfg *cfg) | |
dc1eae25 TI |
2927 | { |
2928 | struct alc_spec *spec = codec->spec; | |
1d045db9 | 2929 | int i, err, noutputs; |
1f0f4b80 | 2930 | |
1d045db9 TI |
2931 | noutputs = cfg->line_outs; |
2932 | if (spec->multi_ios > 0) | |
2933 | noutputs += spec->multi_ios; | |
1da177e4 | 2934 | |
1d045db9 TI |
2935 | for (i = 0; i < noutputs; i++) { |
2936 | const char *name; | |
2937 | int index; | |
afcd5515 TI |
2938 | hda_nid_t dac, pin; |
2939 | hda_nid_t sw, vol; | |
2940 | ||
2941 | dac = spec->multiout.dac_nids[i]; | |
2942 | if (!dac) | |
1d045db9 TI |
2943 | continue; |
2944 | if (i >= cfg->line_outs) | |
2945 | pin = spec->multi_io[i - 1].pin; | |
2946 | else | |
2947 | pin = cfg->line_out_pins[i]; | |
afcd5515 TI |
2948 | |
2949 | sw = alc_look_for_out_mute_nid(codec, pin, dac); | |
2950 | vol = alc_look_for_out_vol_nid(codec, pin, dac); | |
1d045db9 TI |
2951 | name = alc_get_line_out_pfx(spec, i, true, &index); |
2952 | if (!name) { | |
2953 | /* Center/LFE */ | |
afcd5515 | 2954 | err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1); |
1d045db9 TI |
2955 | if (err < 0) |
2956 | return err; | |
afcd5515 | 2957 | err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2); |
1d045db9 TI |
2958 | if (err < 0) |
2959 | return err; | |
afcd5515 | 2960 | err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1); |
1d045db9 TI |
2961 | if (err < 0) |
2962 | return err; | |
afcd5515 | 2963 | err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2); |
1d045db9 TI |
2964 | if (err < 0) |
2965 | return err; | |
2966 | } else { | |
afcd5515 | 2967 | err = alc_auto_add_stereo_vol(codec, name, index, vol); |
1d045db9 TI |
2968 | if (err < 0) |
2969 | return err; | |
afcd5515 | 2970 | err = alc_auto_add_stereo_sw(codec, name, index, sw); |
1d045db9 TI |
2971 | if (err < 0) |
2972 | return err; | |
e9edcee0 | 2973 | } |
1da177e4 | 2974 | } |
1d045db9 TI |
2975 | return 0; |
2976 | } | |
1da177e4 | 2977 | |
1d045db9 TI |
2978 | /* add playback controls for speaker and HP outputs */ |
2979 | static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin, | |
2980 | hda_nid_t dac, const char *pfx) | |
2981 | { | |
2982 | struct alc_spec *spec = codec->spec; | |
afcd5515 | 2983 | hda_nid_t sw, vol; |
1d045db9 | 2984 | int err; |
1da177e4 | 2985 | |
1d045db9 TI |
2986 | if (!pin) |
2987 | return 0; | |
2988 | if (!dac) { | |
2989 | /* the corresponding DAC is already occupied */ | |
2990 | if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)) | |
2991 | return 0; /* no way */ | |
2992 | /* create a switch only */ | |
2993 | return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, | |
2994 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
e9edcee0 | 2995 | } |
1da177e4 | 2996 | |
afcd5515 TI |
2997 | sw = alc_look_for_out_mute_nid(codec, pin, dac); |
2998 | vol = alc_look_for_out_vol_nid(codec, pin, dac); | |
2999 | err = alc_auto_add_stereo_vol(codec, pfx, 0, vol); | |
1d045db9 TI |
3000 | if (err < 0) |
3001 | return err; | |
afcd5515 | 3002 | err = alc_auto_add_stereo_sw(codec, pfx, 0, sw); |
1d045db9 TI |
3003 | if (err < 0) |
3004 | return err; | |
1da177e4 LT |
3005 | return 0; |
3006 | } | |
3007 | ||
1d045db9 | 3008 | static int alc_auto_create_hp_out(struct hda_codec *codec) |
bec15c3a | 3009 | { |
1d045db9 TI |
3010 | struct alc_spec *spec = codec->spec; |
3011 | return alc_auto_create_extra_out(codec, spec->autocfg.hp_pins[0], | |
3012 | spec->multiout.hp_nid, | |
3013 | "Headphone"); | |
bec15c3a TI |
3014 | } |
3015 | ||
1d045db9 | 3016 | static int alc_auto_create_speaker_out(struct hda_codec *codec) |
bec15c3a | 3017 | { |
bec15c3a | 3018 | struct alc_spec *spec = codec->spec; |
1d045db9 TI |
3019 | return alc_auto_create_extra_out(codec, spec->autocfg.speaker_pins[0], |
3020 | spec->multiout.extra_out_nid[0], | |
3021 | "Speaker"); | |
bec15c3a TI |
3022 | } |
3023 | ||
1d045db9 | 3024 | static void alc_auto_set_output_and_unmute(struct hda_codec *codec, |
afcd5515 | 3025 | hda_nid_t pin, int pin_type, |
1d045db9 | 3026 | hda_nid_t dac) |
bec15c3a | 3027 | { |
1d045db9 | 3028 | int i, num; |
afcd5515 | 3029 | hda_nid_t nid, mix = 0; |
1d045db9 | 3030 | hda_nid_t srcs[HDA_MAX_CONNECTIONS]; |
bec15c3a | 3031 | |
afcd5515 TI |
3032 | alc_set_pin_output(codec, pin, pin_type); |
3033 | nid = alc_go_down_to_selector(codec, pin); | |
1d045db9 TI |
3034 | num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs)); |
3035 | for (i = 0; i < num; i++) { | |
3036 | if (alc_auto_mix_to_dac(codec, srcs[i]) != dac) | |
3037 | continue; | |
3038 | mix = srcs[i]; | |
3039 | break; | |
3040 | } | |
3041 | if (!mix) | |
3042 | return; | |
bec15c3a | 3043 | |
1d045db9 TI |
3044 | /* need the manual connection? */ |
3045 | if (num > 1) | |
3046 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i); | |
3047 | /* unmute mixer widget inputs */ | |
afcd5515 TI |
3048 | if (nid_has_mute(codec, mix, HDA_INPUT)) { |
3049 | snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE, | |
1d045db9 | 3050 | AMP_IN_UNMUTE(0)); |
afcd5515 | 3051 | snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
1d045db9 | 3052 | AMP_IN_UNMUTE(1)); |
afcd5515 | 3053 | } |
1d045db9 | 3054 | /* initialize volume */ |
afcd5515 TI |
3055 | nid = alc_look_for_out_vol_nid(codec, pin, dac); |
3056 | if (nid) | |
3057 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, | |
3058 | AMP_OUT_ZERO); | |
1d045db9 | 3059 | } |
bec15c3a | 3060 | |
1d045db9 | 3061 | static void alc_auto_init_multi_out(struct hda_codec *codec) |
bec15c3a TI |
3062 | { |
3063 | struct alc_spec *spec = codec->spec; | |
1d045db9 TI |
3064 | int pin_type = get_pin_type(spec->autocfg.line_out_type); |
3065 | int i; | |
bec15c3a | 3066 | |
1d045db9 TI |
3067 | for (i = 0; i <= HDA_SIDE; i++) { |
3068 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; | |
3069 | if (nid) | |
3070 | alc_auto_set_output_and_unmute(codec, nid, pin_type, | |
3071 | spec->multiout.dac_nids[i]); | |
3072 | } | |
bec15c3a TI |
3073 | } |
3074 | ||
1d045db9 | 3075 | static void alc_auto_init_extra_out(struct hda_codec *codec) |
e9427969 TI |
3076 | { |
3077 | struct alc_spec *spec = codec->spec; | |
1d045db9 | 3078 | hda_nid_t pin; |
e9427969 | 3079 | |
1d045db9 TI |
3080 | pin = spec->autocfg.hp_pins[0]; |
3081 | if (pin) | |
3082 | alc_auto_set_output_and_unmute(codec, pin, PIN_HP, | |
3083 | spec->multiout.hp_nid); | |
3084 | pin = spec->autocfg.speaker_pins[0]; | |
3085 | if (pin) | |
3086 | alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, | |
3087 | spec->multiout.extra_out_nid[0]); | |
bc9f98a9 KY |
3088 | } |
3089 | ||
df694daa | 3090 | /* |
1d045db9 | 3091 | * multi-io helper |
df694daa | 3092 | */ |
1d045db9 TI |
3093 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, |
3094 | unsigned int location) | |
df694daa | 3095 | { |
1d045db9 TI |
3096 | struct alc_spec *spec = codec->spec; |
3097 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
3098 | int type, i, num_pins = 0; | |
ea1fb29a | 3099 | |
1d045db9 TI |
3100 | for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { |
3101 | for (i = 0; i < cfg->num_inputs; i++) { | |
3102 | hda_nid_t nid = cfg->inputs[i].pin; | |
3103 | hda_nid_t dac; | |
3104 | unsigned int defcfg, caps; | |
3105 | if (cfg->inputs[i].type != type) | |
3106 | continue; | |
3107 | defcfg = snd_hda_codec_get_pincfg(codec, nid); | |
3108 | if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX) | |
3109 | continue; | |
3110 | if (location && get_defcfg_location(defcfg) != location) | |
3111 | continue; | |
3112 | caps = snd_hda_query_pin_caps(codec, nid); | |
3113 | if (!(caps & AC_PINCAP_OUT)) | |
3114 | continue; | |
3115 | dac = alc_auto_look_for_dac(codec, nid); | |
3116 | if (!dac) | |
3117 | continue; | |
3118 | spec->multi_io[num_pins].pin = nid; | |
3119 | spec->multi_io[num_pins].dac = dac; | |
3120 | num_pins++; | |
3121 | spec->private_dac_nids[spec->multiout.num_dacs++] = dac; | |
3122 | } | |
863b4518 | 3123 | } |
df694daa | 3124 | spec->multiout.num_dacs = 1; |
1d045db9 TI |
3125 | if (num_pins < 2) |
3126 | return 0; | |
3127 | return num_pins; | |
a361d84b KY |
3128 | } |
3129 | ||
1d045db9 TI |
3130 | static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol, |
3131 | struct snd_ctl_elem_info *uinfo) | |
a361d84b | 3132 | { |
1d045db9 | 3133 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
a361d84b | 3134 | struct alc_spec *spec = codec->spec; |
a361d84b | 3135 | |
1d045db9 TI |
3136 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
3137 | uinfo->count = 1; | |
3138 | uinfo->value.enumerated.items = spec->multi_ios + 1; | |
3139 | if (uinfo->value.enumerated.item > spec->multi_ios) | |
3140 | uinfo->value.enumerated.item = spec->multi_ios; | |
3141 | sprintf(uinfo->value.enumerated.name, "%dch", | |
3142 | (uinfo->value.enumerated.item + 1) * 2); | |
3143 | return 0; | |
3144 | } | |
a361d84b | 3145 | |
1d045db9 TI |
3146 | static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol, |
3147 | struct snd_ctl_elem_value *ucontrol) | |
3148 | { | |
3149 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
3150 | struct alc_spec *spec = codec->spec; | |
3151 | ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2; | |
3152 | return 0; | |
3153 | } | |
a361d84b | 3154 | |
1d045db9 TI |
3155 | static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output) |
3156 | { | |
3157 | struct alc_spec *spec = codec->spec; | |
3158 | hda_nid_t nid = spec->multi_io[idx].pin; | |
a361d84b | 3159 | |
1d045db9 TI |
3160 | if (!spec->multi_io[idx].ctl_in) |
3161 | spec->multi_io[idx].ctl_in = | |
3162 | snd_hda_codec_read(codec, nid, 0, | |
3163 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | |
3164 | if (output) { | |
3165 | snd_hda_codec_update_cache(codec, nid, 0, | |
3166 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
3167 | PIN_OUT); | |
3168 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) | |
3169 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, | |
3170 | HDA_AMP_MUTE, 0); | |
3171 | alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac); | |
3172 | } else { | |
3173 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) | |
3174 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, | |
3175 | HDA_AMP_MUTE, HDA_AMP_MUTE); | |
3176 | snd_hda_codec_update_cache(codec, nid, 0, | |
3177 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
3178 | spec->multi_io[idx].ctl_in); | |
4f574b7b | 3179 | } |
1d045db9 | 3180 | return 0; |
a361d84b KY |
3181 | } |
3182 | ||
1d045db9 TI |
3183 | static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol, |
3184 | struct snd_ctl_elem_value *ucontrol) | |
a361d84b | 3185 | { |
1d045db9 | 3186 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
f6c7e546 | 3187 | struct alc_spec *spec = codec->spec; |
1d045db9 | 3188 | int i, ch; |
a361d84b | 3189 | |
1d045db9 TI |
3190 | ch = ucontrol->value.enumerated.item[0]; |
3191 | if (ch < 0 || ch > spec->multi_ios) | |
3192 | return -EINVAL; | |
3193 | if (ch == (spec->ext_channel_count - 1) / 2) | |
3194 | return 0; | |
3195 | spec->ext_channel_count = (ch + 1) * 2; | |
3196 | for (i = 0; i < spec->multi_ios; i++) | |
3197 | alc_set_multi_io(codec, i, i < ch); | |
3198 | spec->multiout.max_channels = spec->ext_channel_count; | |
3199 | return 1; | |
3200 | } | |
3abf2f36 | 3201 | |
1d045db9 TI |
3202 | static const struct snd_kcontrol_new alc_auto_channel_mode_enum = { |
3203 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
3204 | .name = "Channel Mode", | |
3205 | .info = alc_auto_ch_mode_info, | |
3206 | .get = alc_auto_ch_mode_get, | |
3207 | .put = alc_auto_ch_mode_put, | |
a361d84b KY |
3208 | }; |
3209 | ||
1d045db9 TI |
3210 | static int alc_auto_add_multi_channel_mode(struct hda_codec *codec, |
3211 | int (*fill_dac)(struct hda_codec *)) | |
a361d84b | 3212 | { |
1d045db9 TI |
3213 | struct alc_spec *spec = codec->spec; |
3214 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
3215 | unsigned int location, defcfg; | |
3216 | int num_pins; | |
a361d84b | 3217 | |
1d045db9 TI |
3218 | if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && cfg->hp_outs == 1) { |
3219 | /* use HP as primary out */ | |
3220 | cfg->speaker_outs = cfg->line_outs; | |
3221 | memcpy(cfg->speaker_pins, cfg->line_out_pins, | |
3222 | sizeof(cfg->speaker_pins)); | |
3223 | cfg->line_outs = cfg->hp_outs; | |
3224 | memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins)); | |
3225 | cfg->hp_outs = 0; | |
3226 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); | |
3227 | cfg->line_out_type = AUTO_PIN_HP_OUT; | |
3228 | if (fill_dac) | |
3229 | fill_dac(codec); | |
3230 | } | |
3231 | if (cfg->line_outs != 1 || | |
3232 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) | |
3233 | return 0; | |
a361d84b | 3234 | |
1d045db9 TI |
3235 | defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]); |
3236 | location = get_defcfg_location(defcfg); | |
1f0f4b80 | 3237 | |
1d045db9 TI |
3238 | num_pins = alc_auto_fill_multi_ios(codec, location); |
3239 | if (num_pins > 0) { | |
3240 | struct snd_kcontrol_new *knew; | |
a361d84b | 3241 | |
1d045db9 TI |
3242 | knew = alc_kcontrol_new(spec); |
3243 | if (!knew) | |
3244 | return -ENOMEM; | |
3245 | *knew = alc_auto_channel_mode_enum; | |
3246 | knew->name = kstrdup("Channel Mode", GFP_KERNEL); | |
3247 | if (!knew->name) | |
3248 | return -ENOMEM; | |
3abf2f36 | 3249 | |
1d045db9 TI |
3250 | spec->multi_ios = num_pins; |
3251 | spec->ext_channel_count = 2; | |
3252 | spec->multiout.num_dacs = num_pins + 1; | |
a361d84b | 3253 | } |
1d045db9 TI |
3254 | return 0; |
3255 | } | |
a361d84b | 3256 | |
1d045db9 TI |
3257 | /* filter out invalid adc_nids (and capsrc_nids) that don't give all |
3258 | * active input pins | |
3259 | */ | |
3260 | static void alc_remove_invalid_adc_nids(struct hda_codec *codec) | |
3261 | { | |
3262 | struct alc_spec *spec = codec->spec; | |
3263 | const struct hda_input_mux *imux; | |
3264 | hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)]; | |
3265 | hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)]; | |
3266 | int i, n, nums; | |
a361d84b | 3267 | |
1d045db9 TI |
3268 | imux = spec->input_mux; |
3269 | if (!imux) | |
3270 | return; | |
3271 | if (spec->dyn_adc_switch) | |
3272 | return; | |
a361d84b | 3273 | |
1d045db9 TI |
3274 | nums = 0; |
3275 | for (n = 0; n < spec->num_adc_nids; n++) { | |
3276 | hda_nid_t cap = spec->private_capsrc_nids[n]; | |
3277 | int num_conns = snd_hda_get_conn_list(codec, cap, NULL); | |
3278 | for (i = 0; i < imux->num_items; i++) { | |
3279 | hda_nid_t pin = spec->imux_pins[i]; | |
3280 | if (pin) { | |
3281 | if (get_connection_index(codec, cap, pin) < 0) | |
3282 | break; | |
3283 | } else if (num_conns <= imux->items[i].index) | |
3284 | break; | |
3285 | } | |
3286 | if (i >= imux->num_items) { | |
3287 | adc_nids[nums] = spec->private_adc_nids[n]; | |
3288 | capsrc_nids[nums++] = cap; | |
22971e3a TI |
3289 | } |
3290 | } | |
1d045db9 TI |
3291 | if (!nums) { |
3292 | /* check whether ADC-switch is possible */ | |
3293 | if (!alc_check_dyn_adc_switch(codec)) { | |
3294 | printk(KERN_WARNING "hda_codec: %s: no valid ADC found;" | |
3295 | " using fallback 0x%x\n", | |
3296 | codec->chip_name, spec->private_adc_nids[0]); | |
3297 | spec->num_adc_nids = 1; | |
3298 | spec->auto_mic = 0; | |
3299 | return; | |
22971e3a | 3300 | } |
1d045db9 TI |
3301 | } else if (nums != spec->num_adc_nids) { |
3302 | memcpy(spec->private_adc_nids, adc_nids, | |
3303 | nums * sizeof(hda_nid_t)); | |
3304 | memcpy(spec->private_capsrc_nids, capsrc_nids, | |
3305 | nums * sizeof(hda_nid_t)); | |
3306 | spec->num_adc_nids = nums; | |
22971e3a | 3307 | } |
aef9d318 | 3308 | |
1d045db9 TI |
3309 | if (spec->auto_mic) |
3310 | alc_auto_mic_check_imux(codec); /* check auto-mic setups */ | |
3311 | else if (spec->input_mux->num_items == 1) | |
3312 | spec->num_adc_nids = 1; /* reduce to a single ADC */ | |
3313 | } | |
3314 | ||
3315 | /* | |
3316 | * initialize ADC paths | |
3317 | */ | |
3318 | static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx) | |
3319 | { | |
3320 | struct alc_spec *spec = codec->spec; | |
3321 | hda_nid_t nid; | |
3322 | ||
3323 | nid = spec->adc_nids[adc_idx]; | |
3324 | /* mute ADC */ | |
44c02400 | 3325 | if (nid_has_mute(codec, nid, HDA_INPUT)) { |
1d045db9 TI |
3326 | snd_hda_codec_write(codec, nid, 0, |
3327 | AC_VERB_SET_AMP_GAIN_MUTE, | |
3328 | AMP_IN_MUTE(0)); | |
3329 | return; | |
a361d84b | 3330 | } |
1d045db9 TI |
3331 | if (!spec->capsrc_nids) |
3332 | return; | |
3333 | nid = spec->capsrc_nids[adc_idx]; | |
44c02400 | 3334 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
1d045db9 TI |
3335 | snd_hda_codec_write(codec, nid, 0, |
3336 | AC_VERB_SET_AMP_GAIN_MUTE, | |
3337 | AMP_OUT_MUTE); | |
3338 | } | |
2134ea4f | 3339 | |
1d045db9 TI |
3340 | static void alc_auto_init_input_src(struct hda_codec *codec) |
3341 | { | |
3342 | struct alc_spec *spec = codec->spec; | |
3343 | int c, nums; | |
d6cc9fab | 3344 | |
1d045db9 TI |
3345 | for (c = 0; c < spec->num_adc_nids; c++) |
3346 | alc_auto_init_adc(codec, c); | |
3347 | if (spec->dyn_adc_switch) | |
3348 | nums = 1; | |
3349 | else | |
3350 | nums = spec->num_adc_nids; | |
3351 | for (c = 0; c < nums; c++) | |
3352 | alc_mux_select(codec, 0, spec->cur_mux[c], true); | |
3353 | } | |
2134ea4f | 3354 | |
1d045db9 TI |
3355 | /* add mic boosts if needed */ |
3356 | static int alc_auto_add_mic_boost(struct hda_codec *codec) | |
3357 | { | |
3358 | struct alc_spec *spec = codec->spec; | |
3359 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
3360 | int i, err; | |
3361 | int type_idx = 0; | |
3362 | hda_nid_t nid; | |
3363 | const char *prev_label = NULL; | |
ea1fb29a | 3364 | |
1d045db9 TI |
3365 | for (i = 0; i < cfg->num_inputs; i++) { |
3366 | if (cfg->inputs[i].type > AUTO_PIN_MIC) | |
3367 | break; | |
3368 | nid = cfg->inputs[i].pin; | |
3369 | if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { | |
3370 | const char *label; | |
3371 | char boost_label[32]; | |
3372 | ||
3373 | label = hda_get_autocfg_input_label(codec, cfg, i); | |
3374 | if (prev_label && !strcmp(label, prev_label)) | |
3375 | type_idx++; | |
3376 | else | |
3377 | type_idx = 0; | |
3378 | prev_label = label; | |
bf1b0225 | 3379 | |
1d045db9 TI |
3380 | snprintf(boost_label, sizeof(boost_label), |
3381 | "%s Boost Volume", label); | |
3382 | err = add_control(spec, ALC_CTL_WIDGET_VOL, | |
3383 | boost_label, type_idx, | |
3384 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT)); | |
3385 | if (err < 0) | |
3386 | return err; | |
3387 | } | |
3388 | } | |
a361d84b KY |
3389 | return 0; |
3390 | } | |
3391 | ||
1d045db9 TI |
3392 | /* select or unmute the given capsrc route */ |
3393 | static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap, | |
3394 | int idx) | |
3395 | { | |
3396 | if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) { | |
3397 | snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx, | |
3398 | HDA_AMP_MUTE, 0); | |
3399 | } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) { | |
3400 | snd_hda_codec_write_cache(codec, cap, 0, | |
3401 | AC_VERB_SET_CONNECT_SEL, idx); | |
3402 | } | |
3403 | } | |
f6a92248 | 3404 | |
1d045db9 TI |
3405 | /* set the default connection to that pin */ |
3406 | static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin) | |
3407 | { | |
3408 | struct alc_spec *spec = codec->spec; | |
3409 | int i; | |
f6a92248 | 3410 | |
1d045db9 TI |
3411 | if (!pin) |
3412 | return 0; | |
3413 | for (i = 0; i < spec->num_adc_nids; i++) { | |
3414 | hda_nid_t cap = spec->capsrc_nids ? | |
3415 | spec->capsrc_nids[i] : spec->adc_nids[i]; | |
3416 | int idx; | |
f53281e6 | 3417 | |
1d045db9 TI |
3418 | idx = get_connection_index(codec, cap, pin); |
3419 | if (idx < 0) | |
3420 | continue; | |
3421 | select_or_unmute_capsrc(codec, cap, idx); | |
3422 | return i; /* return the found index */ | |
3423 | } | |
3424 | return -1; /* not found */ | |
3425 | } | |
e01bf509 | 3426 | |
1d045db9 TI |
3427 | /* initialize some special cases for input sources */ |
3428 | static void alc_init_special_input_src(struct hda_codec *codec) | |
3429 | { | |
3430 | struct alc_spec *spec = codec->spec; | |
3431 | int i; | |
84898e87 | 3432 | |
1d045db9 TI |
3433 | for (i = 0; i < spec->autocfg.num_inputs; i++) |
3434 | init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin); | |
3435 | } | |
84898e87 | 3436 | |
1d045db9 TI |
3437 | /* assign appropriate capture mixers */ |
3438 | static void set_capture_mixer(struct hda_codec *codec) | |
3439 | { | |
3440 | struct alc_spec *spec = codec->spec; | |
3441 | static const struct snd_kcontrol_new *caps[2][3] = { | |
3442 | { alc_capture_mixer_nosrc1, | |
3443 | alc_capture_mixer_nosrc2, | |
3444 | alc_capture_mixer_nosrc3 }, | |
3445 | { alc_capture_mixer1, | |
3446 | alc_capture_mixer2, | |
3447 | alc_capture_mixer3 }, | |
3448 | }; | |
f6a92248 | 3449 | |
1d045db9 | 3450 | /* check whether either of ADC or MUX has a volume control */ |
44c02400 | 3451 | if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) { |
1d045db9 TI |
3452 | if (!spec->capsrc_nids) |
3453 | return; /* no volume */ | |
44c02400 | 3454 | if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT)) |
1d045db9 TI |
3455 | return; /* no volume in capsrc, too */ |
3456 | spec->vol_in_capsrc = 1; | |
3457 | } | |
60db6b53 | 3458 | |
1d045db9 TI |
3459 | if (spec->num_adc_nids > 0) { |
3460 | int mux = 0; | |
3461 | int num_adcs = 0; | |
64154835 | 3462 | |
1d045db9 TI |
3463 | if (spec->input_mux && spec->input_mux->num_items > 1) |
3464 | mux = 1; | |
3465 | if (spec->auto_mic) { | |
3466 | num_adcs = 1; | |
3467 | mux = 0; | |
3468 | } else if (spec->dyn_adc_switch) | |
3469 | num_adcs = 1; | |
3470 | if (!num_adcs) { | |
3471 | if (spec->num_adc_nids > 3) | |
3472 | spec->num_adc_nids = 3; | |
3473 | else if (!spec->num_adc_nids) | |
3474 | return; | |
3475 | num_adcs = spec->num_adc_nids; | |
3476 | } | |
3477 | spec->cap_mixer = caps[mux][num_adcs - 1]; | |
3478 | } | |
3479 | } | |
f53281e6 | 3480 | |
e4770629 TI |
3481 | /* |
3482 | * standard auto-parser initializations | |
3483 | */ | |
3484 | static void alc_auto_init_std(struct hda_codec *codec) | |
3485 | { | |
3486 | struct alc_spec *spec = codec->spec; | |
3487 | alc_auto_init_multi_out(codec); | |
3488 | alc_auto_init_extra_out(codec); | |
3489 | alc_auto_init_analog_input(codec); | |
3490 | alc_auto_init_input_src(codec); | |
3491 | alc_auto_init_digital(codec); | |
3492 | if (spec->unsol_event) | |
3493 | alc_inithook(codec); | |
3494 | } | |
3495 | ||
1d045db9 TI |
3496 | /* |
3497 | * Digital-beep handlers | |
3498 | */ | |
3499 | #ifdef CONFIG_SND_HDA_INPUT_BEEP | |
3500 | #define set_beep_amp(spec, nid, idx, dir) \ | |
3501 | ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir)) | |
84898e87 | 3502 | |
1d045db9 TI |
3503 | static const struct snd_pci_quirk beep_white_list[] = { |
3504 | SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1), | |
3505 | SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1), | |
3506 | SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1), | |
3507 | SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1), | |
3508 | SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1), | |
3509 | {} | |
fe3eb0a7 KY |
3510 | }; |
3511 | ||
1d045db9 TI |
3512 | static inline int has_cdefine_beep(struct hda_codec *codec) |
3513 | { | |
3514 | struct alc_spec *spec = codec->spec; | |
3515 | const struct snd_pci_quirk *q; | |
3516 | q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list); | |
3517 | if (q) | |
3518 | return q->value; | |
3519 | return spec->cdefine.enable_pcbeep; | |
3520 | } | |
3521 | #else | |
3522 | #define set_beep_amp(spec, nid, idx, dir) /* NOP */ | |
3523 | #define has_cdefine_beep(codec) 0 | |
3524 | #endif | |
84898e87 | 3525 | |
1d045db9 TI |
3526 | /* parse the BIOS configuration and set up the alc_spec */ |
3527 | /* return 1 if successful, 0 if the proper config is not found, | |
3528 | * or a negative error code | |
3529 | */ | |
3e6179b8 TI |
3530 | static int alc_parse_auto_config(struct hda_codec *codec, |
3531 | const hda_nid_t *ignore_nids, | |
3532 | const hda_nid_t *ssid_nids) | |
1d045db9 TI |
3533 | { |
3534 | struct alc_spec *spec = codec->spec; | |
3535 | int err; | |
26f5df26 | 3536 | |
1d045db9 | 3537 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, |
3e6179b8 | 3538 | ignore_nids); |
1d045db9 TI |
3539 | if (err < 0) |
3540 | return err; | |
3e6179b8 TI |
3541 | if (!spec->autocfg.line_outs) { |
3542 | if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) { | |
3543 | spec->multiout.max_channels = 2; | |
3544 | spec->no_analog = 1; | |
3545 | goto dig_only; | |
3546 | } | |
1d045db9 | 3547 | return 0; /* can't find valid BIOS pin config */ |
3e6179b8 | 3548 | } |
1d045db9 | 3549 | err = alc_auto_fill_dac_nids(codec); |
3e6179b8 TI |
3550 | if (err < 0) |
3551 | return err; | |
3552 | err = alc_auto_add_multi_channel_mode(codec, alc_auto_fill_dac_nids); | |
1d045db9 TI |
3553 | if (err < 0) |
3554 | return err; | |
3555 | err = alc_auto_create_multi_out_ctls(codec, &spec->autocfg); | |
3556 | if (err < 0) | |
3557 | return err; | |
3558 | err = alc_auto_create_hp_out(codec); | |
3559 | if (err < 0) | |
3560 | return err; | |
3561 | err = alc_auto_create_speaker_out(codec); | |
3562 | if (err < 0) | |
3563 | return err; | |
3564 | err = alc_auto_create_input_ctls(codec); | |
3565 | if (err < 0) | |
3566 | return err; | |
84898e87 | 3567 | |
1d045db9 | 3568 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
f53281e6 | 3569 | |
3e6179b8 | 3570 | dig_only: |
1d045db9 | 3571 | alc_auto_parse_digital(codec); |
f6a92248 | 3572 | |
3e6179b8 TI |
3573 | if (!spec->no_analog) |
3574 | alc_remove_invalid_adc_nids(codec); | |
3575 | ||
3576 | if (ssid_nids) | |
3577 | alc_ssid_check(codec, ssid_nids); | |
64154835 | 3578 | |
3e6179b8 TI |
3579 | if (!spec->no_analog) { |
3580 | alc_auto_check_switches(codec); | |
3581 | err = alc_auto_add_mic_boost(codec); | |
3582 | if (err < 0) | |
3583 | return err; | |
3584 | } | |
f6a92248 | 3585 | |
3e6179b8 TI |
3586 | if (spec->kctls.list) |
3587 | add_mixer(spec, spec->kctls.list); | |
f6a92248 | 3588 | |
1d045db9 | 3589 | return 1; |
60db6b53 | 3590 | } |
f6a92248 | 3591 | |
3e6179b8 TI |
3592 | static int alc880_parse_auto_config(struct hda_codec *codec) |
3593 | { | |
3594 | static const hda_nid_t alc880_ignore[] = { 0x1d, 0 }; | |
3595 | static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 }; | |
3596 | return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids); | |
3597 | } | |
3598 | ||
1d045db9 TI |
3599 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
3600 | static const struct hda_amp_list alc880_loopbacks[] = { | |
3601 | { 0x0b, HDA_INPUT, 0 }, | |
3602 | { 0x0b, HDA_INPUT, 1 }, | |
3603 | { 0x0b, HDA_INPUT, 2 }, | |
3604 | { 0x0b, HDA_INPUT, 3 }, | |
3605 | { 0x0b, HDA_INPUT, 4 }, | |
3606 | { } /* end */ | |
3607 | }; | |
3608 | #endif | |
f6a92248 | 3609 | |
1d045db9 TI |
3610 | /* |
3611 | * board setups | |
3612 | */ | |
3613 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
3614 | #define alc_board_config \ | |
3615 | snd_hda_check_board_config | |
3616 | #define alc_board_codec_sid_config \ | |
3617 | snd_hda_check_board_codec_sid_config | |
3618 | #include "alc_quirks.c" | |
3619 | #else | |
3620 | #define alc_board_config(codec, nums, models, tbl) -1 | |
3621 | #define alc_board_codec_sid_config(codec, nums, models, tbl) -1 | |
3622 | #define setup_preset(codec, x) /* NOP */ | |
3623 | #endif | |
64154835 | 3624 | |
1d045db9 TI |
3625 | /* |
3626 | * OK, here we have finally the patch for ALC880 | |
3627 | */ | |
3628 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
3629 | #include "alc880_quirks.c" | |
3630 | #endif | |
4f5d1706 | 3631 | |
1d045db9 | 3632 | static int patch_alc880(struct hda_codec *codec) |
60db6b53 | 3633 | { |
1d045db9 TI |
3634 | struct alc_spec *spec; |
3635 | int board_config; | |
3636 | int err; | |
f6a92248 | 3637 | |
1d045db9 TI |
3638 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
3639 | if (spec == NULL) | |
3640 | return -ENOMEM; | |
3b8510ce | 3641 | |
1d045db9 | 3642 | codec->spec = spec; |
64154835 | 3643 | |
1d045db9 | 3644 | spec->mixer_nid = 0x0b; |
f53281e6 | 3645 | |
1d045db9 TI |
3646 | board_config = alc_board_config(codec, ALC880_MODEL_LAST, |
3647 | alc880_models, alc880_cfg_tbl); | |
3648 | if (board_config < 0) { | |
3649 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", | |
3650 | codec->chip_name); | |
3651 | board_config = ALC_MODEL_AUTO; | |
3652 | } | |
f53281e6 | 3653 | |
1d045db9 TI |
3654 | if (board_config == ALC_MODEL_AUTO) { |
3655 | /* automatic parse from the BIOS config */ | |
3656 | err = alc880_parse_auto_config(codec); | |
3657 | if (err < 0) { | |
3658 | alc_free(codec); | |
3659 | return err; | |
3660 | } | |
3661 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
3662 | else if (!err) { | |
3663 | printk(KERN_INFO | |
3664 | "hda_codec: Cannot set up configuration " | |
3665 | "from BIOS. Using 3-stack mode...\n"); | |
3666 | board_config = ALC880_3ST; | |
3667 | } | |
3668 | #endif | |
3669 | } | |
84898e87 | 3670 | |
1d045db9 TI |
3671 | if (board_config != ALC_MODEL_AUTO) |
3672 | setup_preset(codec, &alc880_presets[board_config]); | |
fe3eb0a7 | 3673 | |
3e6179b8 | 3674 | if (!spec->no_analog && !spec->adc_nids && spec->input_mux) { |
1d045db9 TI |
3675 | alc_auto_fill_adc_caps(codec); |
3676 | alc_rebuild_imux_for_auto_mic(codec); | |
3677 | alc_remove_invalid_adc_nids(codec); | |
3678 | } | |
3e6179b8 TI |
3679 | |
3680 | if (!spec->no_analog && !spec->cap_mixer) | |
3681 | set_capture_mixer(codec); | |
3682 | ||
3683 | if (!spec->no_analog) { | |
3684 | err = snd_hda_attach_beep_device(codec, 0x1); | |
3685 | if (err < 0) { | |
3686 | alc_free(codec); | |
3687 | return err; | |
3688 | } | |
3689 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); | |
3690 | } | |
f53281e6 | 3691 | |
1d045db9 | 3692 | spec->vmaster_nid = 0x0c; |
84898e87 | 3693 | |
1d045db9 TI |
3694 | codec->patch_ops = alc_patch_ops; |
3695 | if (board_config == ALC_MODEL_AUTO) | |
e4770629 | 3696 | spec->init_hook = alc_auto_init_std; |
1d045db9 TI |
3697 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
3698 | if (!spec->loopback.amplist) | |
3699 | spec->loopback.amplist = alc880_loopbacks; | |
3700 | #endif | |
f53281e6 | 3701 | |
1d045db9 | 3702 | return 0; |
226b1ec8 KY |
3703 | } |
3704 | ||
1d045db9 | 3705 | |
60db6b53 | 3706 | /* |
1d045db9 | 3707 | * ALC260 support |
60db6b53 | 3708 | */ |
1d045db9 | 3709 | static int alc260_parse_auto_config(struct hda_codec *codec) |
f6a92248 | 3710 | { |
1d045db9 | 3711 | static const hda_nid_t alc260_ignore[] = { 0x17, 0 }; |
3e6179b8 TI |
3712 | static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 }; |
3713 | return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids); | |
f6a92248 KY |
3714 | } |
3715 | ||
1d045db9 TI |
3716 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
3717 | static const struct hda_amp_list alc260_loopbacks[] = { | |
3718 | { 0x07, HDA_INPUT, 0 }, | |
3719 | { 0x07, HDA_INPUT, 1 }, | |
3720 | { 0x07, HDA_INPUT, 2 }, | |
3721 | { 0x07, HDA_INPUT, 3 }, | |
3722 | { 0x07, HDA_INPUT, 4 }, | |
3723 | { } /* end */ | |
3724 | }; | |
3725 | #endif | |
0ec33d1f | 3726 | |
1d045db9 TI |
3727 | /* |
3728 | * Pin config fixes | |
3729 | */ | |
3730 | enum { | |
3731 | PINFIX_HP_DC5750, | |
3732 | }; | |
3733 | ||
3734 | static const struct alc_fixup alc260_fixups[] = { | |
3735 | [PINFIX_HP_DC5750] = { | |
3736 | .type = ALC_FIXUP_PINS, | |
3737 | .v.pins = (const struct alc_pincfg[]) { | |
3738 | { 0x11, 0x90130110 }, /* speaker */ | |
3739 | { } | |
3740 | } | |
3741 | }, | |
3742 | }; | |
3743 | ||
3744 | static const struct snd_pci_quirk alc260_fixup_tbl[] = { | |
3745 | SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750), | |
3746 | {} | |
3747 | }; | |
3748 | ||
3749 | /* | |
3750 | */ | |
3751 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
3752 | #include "alc260_quirks.c" | |
3753 | #endif | |
3754 | ||
3755 | static int patch_alc260(struct hda_codec *codec) | |
977ddd6b | 3756 | { |
1d045db9 TI |
3757 | struct alc_spec *spec; |
3758 | int err, board_config; | |
3759 | ||
3760 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
3761 | if (spec == NULL) | |
3762 | return -ENOMEM; | |
3763 | ||
3764 | codec->spec = spec; | |
3765 | ||
3766 | spec->mixer_nid = 0x07; | |
3767 | ||
3768 | board_config = alc_board_config(codec, ALC260_MODEL_LAST, | |
3769 | alc260_models, alc260_cfg_tbl); | |
3770 | if (board_config < 0) { | |
3771 | snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", | |
3772 | codec->chip_name); | |
3773 | board_config = ALC_MODEL_AUTO; | |
977ddd6b | 3774 | } |
0ec33d1f | 3775 | |
1d045db9 TI |
3776 | if (board_config == ALC_MODEL_AUTO) { |
3777 | alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); | |
3778 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
977ddd6b KY |
3779 | } |
3780 | ||
1d045db9 TI |
3781 | if (board_config == ALC_MODEL_AUTO) { |
3782 | /* automatic parse from the BIOS config */ | |
3783 | err = alc260_parse_auto_config(codec); | |
3784 | if (err < 0) { | |
3785 | alc_free(codec); | |
3786 | return err; | |
3787 | } | |
3788 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
3789 | else if (!err) { | |
3790 | printk(KERN_INFO | |
3791 | "hda_codec: Cannot set up configuration " | |
3792 | "from BIOS. Using base mode...\n"); | |
3793 | board_config = ALC260_BASIC; | |
3794 | } | |
3795 | #endif | |
3796 | } | |
977ddd6b | 3797 | |
1d045db9 TI |
3798 | if (board_config != ALC_MODEL_AUTO) |
3799 | setup_preset(codec, &alc260_presets[board_config]); | |
977ddd6b | 3800 | |
3e6179b8 | 3801 | if (!spec->no_analog && !spec->adc_nids && spec->input_mux) { |
1d045db9 TI |
3802 | alc_auto_fill_adc_caps(codec); |
3803 | alc_rebuild_imux_for_auto_mic(codec); | |
3804 | alc_remove_invalid_adc_nids(codec); | |
3805 | } | |
3e6179b8 TI |
3806 | |
3807 | if (!spec->no_analog && !spec->cap_mixer) | |
3808 | set_capture_mixer(codec); | |
3809 | ||
3810 | if (!spec->no_analog) { | |
3811 | err = snd_hda_attach_beep_device(codec, 0x1); | |
3812 | if (err < 0) { | |
3813 | alc_free(codec); | |
3814 | return err; | |
3815 | } | |
3816 | set_beep_amp(spec, 0x07, 0x05, HDA_INPUT); | |
3817 | } | |
977ddd6b | 3818 | |
1d045db9 | 3819 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
1a99d4a4 | 3820 | |
1d045db9 | 3821 | spec->vmaster_nid = 0x08; |
1a99d4a4 | 3822 | |
1d045db9 TI |
3823 | codec->patch_ops = alc_patch_ops; |
3824 | if (board_config == ALC_MODEL_AUTO) | |
8452a982 | 3825 | spec->init_hook = alc_auto_init_std; |
1d045db9 TI |
3826 | spec->shutup = alc_eapd_shutup; |
3827 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
3828 | if (!spec->loopback.amplist) | |
3829 | spec->loopback.amplist = alc260_loopbacks; | |
3830 | #endif | |
6981d184 | 3831 | |
1d045db9 | 3832 | return 0; |
6981d184 TI |
3833 | } |
3834 | ||
1d045db9 TI |
3835 | |
3836 | /* | |
3837 | * ALC882/883/885/888/889 support | |
3838 | * | |
3839 | * ALC882 is almost identical with ALC880 but has cleaner and more flexible | |
3840 | * configuration. Each pin widget can choose any input DACs and a mixer. | |
3841 | * Each ADC is connected from a mixer of all inputs. This makes possible | |
3842 | * 6-channel independent captures. | |
3843 | * | |
3844 | * In addition, an independent DAC for the multi-playback (not used in this | |
3845 | * driver yet). | |
3846 | */ | |
3847 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
3848 | #define alc882_loopbacks alc880_loopbacks | |
3849 | #endif | |
3850 | ||
3851 | /* | |
3852 | * Pin config fixes | |
3853 | */ | |
ff818c24 | 3854 | enum { |
1d045db9 TI |
3855 | PINFIX_ABIT_AW9D_MAX, |
3856 | PINFIX_LENOVO_Y530, | |
3857 | PINFIX_PB_M5210, | |
3858 | PINFIX_ACER_ASPIRE_7736, | |
ff818c24 TI |
3859 | }; |
3860 | ||
1d045db9 TI |
3861 | static const struct alc_fixup alc882_fixups[] = { |
3862 | [PINFIX_ABIT_AW9D_MAX] = { | |
3863 | .type = ALC_FIXUP_PINS, | |
3864 | .v.pins = (const struct alc_pincfg[]) { | |
3865 | { 0x15, 0x01080104 }, /* side */ | |
3866 | { 0x16, 0x01011012 }, /* rear */ | |
3867 | { 0x17, 0x01016011 }, /* clfe */ | |
2785591a | 3868 | { } |
145a902b DH |
3869 | } |
3870 | }, | |
1d045db9 | 3871 | [PINFIX_LENOVO_Y530] = { |
b5bfbc67 TI |
3872 | .type = ALC_FIXUP_PINS, |
3873 | .v.pins = (const struct alc_pincfg[]) { | |
1d045db9 TI |
3874 | { 0x15, 0x99130112 }, /* rear int speakers */ |
3875 | { 0x16, 0x99130111 }, /* subwoofer */ | |
ac612407 DH |
3876 | { } |
3877 | } | |
3878 | }, | |
1d045db9 | 3879 | [PINFIX_PB_M5210] = { |
b5bfbc67 TI |
3880 | .type = ALC_FIXUP_VERBS, |
3881 | .v.verbs = (const struct hda_verb[]) { | |
1d045db9 | 3882 | { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, |
357f915e KY |
3883 | {} |
3884 | } | |
3885 | }, | |
1d045db9 TI |
3886 | [PINFIX_ACER_ASPIRE_7736] = { |
3887 | .type = ALC_FIXUP_SKU, | |
3888 | .v.sku = ALC_FIXUP_SKU_IGNORE, | |
6981d184 | 3889 | }, |
ff818c24 TI |
3890 | }; |
3891 | ||
1d045db9 TI |
3892 | static const struct snd_pci_quirk alc882_fixup_tbl[] = { |
3893 | SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210), | |
3894 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530), | |
3895 | SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX), | |
3896 | SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736), | |
ff818c24 TI |
3897 | {} |
3898 | }; | |
3899 | ||
f6a92248 | 3900 | /* |
1d045db9 | 3901 | * BIOS auto configuration |
f6a92248 | 3902 | */ |
1d045db9 TI |
3903 | /* almost identical with ALC880 parser... */ |
3904 | static int alc882_parse_auto_config(struct hda_codec *codec) | |
3905 | { | |
1d045db9 | 3906 | static const hda_nid_t alc882_ignore[] = { 0x1d, 0 }; |
3e6179b8 TI |
3907 | static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
3908 | return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids); | |
1d045db9 | 3909 | } |
b896b4eb | 3910 | |
1d045db9 TI |
3911 | /* |
3912 | */ | |
3913 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
3914 | #include "alc882_quirks.c" | |
3915 | #endif | |
3916 | ||
3917 | static int patch_alc882(struct hda_codec *codec) | |
f6a92248 KY |
3918 | { |
3919 | struct alc_spec *spec; | |
1d045db9 | 3920 | int err, board_config; |
f6a92248 KY |
3921 | |
3922 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
3923 | if (spec == NULL) | |
3924 | return -ENOMEM; | |
3925 | ||
3926 | codec->spec = spec; | |
3927 | ||
1f0f4b80 TI |
3928 | spec->mixer_nid = 0x0b; |
3929 | ||
1d045db9 TI |
3930 | switch (codec->vendor_id) { |
3931 | case 0x10ec0882: | |
3932 | case 0x10ec0885: | |
3933 | break; | |
3934 | default: | |
3935 | /* ALC883 and variants */ | |
3936 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); | |
3937 | break; | |
c793bec5 | 3938 | } |
977ddd6b | 3939 | |
1d045db9 TI |
3940 | board_config = alc_board_config(codec, ALC882_MODEL_LAST, |
3941 | alc882_models, alc882_cfg_tbl); | |
3942 | ||
3943 | if (board_config < 0) | |
3944 | board_config = alc_board_codec_sid_config(codec, | |
3945 | ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl); | |
f6a92248 KY |
3946 | |
3947 | if (board_config < 0) { | |
9a11f1aa TI |
3948 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
3949 | codec->chip_name); | |
1d045db9 | 3950 | board_config = ALC_MODEL_AUTO; |
f6a92248 KY |
3951 | } |
3952 | ||
1d045db9 TI |
3953 | if (board_config == ALC_MODEL_AUTO) { |
3954 | alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups); | |
b5bfbc67 TI |
3955 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
3956 | } | |
ff818c24 | 3957 | |
1d045db9 TI |
3958 | alc_auto_parse_customize_define(codec); |
3959 | ||
3960 | if (board_config == ALC_MODEL_AUTO) { | |
f6a92248 | 3961 | /* automatic parse from the BIOS config */ |
1d045db9 | 3962 | err = alc882_parse_auto_config(codec); |
f6a92248 KY |
3963 | if (err < 0) { |
3964 | alc_free(codec); | |
3965 | return err; | |
1d045db9 TI |
3966 | } |
3967 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
3968 | else if (!err) { | |
f6a92248 KY |
3969 | printk(KERN_INFO |
3970 | "hda_codec: Cannot set up configuration " | |
3971 | "from BIOS. Using base mode...\n"); | |
1d045db9 | 3972 | board_config = ALC882_3ST_DIG; |
f6a92248 | 3973 | } |
1d045db9 | 3974 | #endif |
f6a92248 KY |
3975 | } |
3976 | ||
1d045db9 TI |
3977 | if (board_config != ALC_MODEL_AUTO) |
3978 | setup_preset(codec, &alc882_presets[board_config]); | |
f6a92248 | 3979 | |
3e6179b8 | 3980 | if (!spec->no_analog && !spec->adc_nids && spec->input_mux) { |
d6cc9fab | 3981 | alc_auto_fill_adc_caps(codec); |
21268961 | 3982 | alc_rebuild_imux_for_auto_mic(codec); |
d6cc9fab | 3983 | alc_remove_invalid_adc_nids(codec); |
84898e87 KY |
3984 | } |
3985 | ||
3e6179b8 TI |
3986 | if (!spec->no_analog && !spec->cap_mixer) |
3987 | set_capture_mixer(codec); | |
1d045db9 | 3988 | |
3e6179b8 TI |
3989 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
3990 | err = snd_hda_attach_beep_device(codec, 0x1); | |
3991 | if (err < 0) { | |
3992 | alc_free(codec); | |
3993 | return err; | |
3994 | } | |
1d045db9 | 3995 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
3e6179b8 | 3996 | } |
f6a92248 | 3997 | |
b5bfbc67 | 3998 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
ff818c24 | 3999 | |
1d045db9 | 4000 | spec->vmaster_nid = 0x0c; |
100d5eb3 | 4001 | |
f6a92248 | 4002 | codec->patch_ops = alc_patch_ops; |
1d045db9 | 4003 | if (board_config == ALC_MODEL_AUTO) |
e4770629 | 4004 | spec->init_hook = alc_auto_init_std; |
bf1b0225 KY |
4005 | |
4006 | alc_init_jacks(codec); | |
f6a92248 KY |
4007 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
4008 | if (!spec->loopback.amplist) | |
1d045db9 | 4009 | spec->loopback.amplist = alc882_loopbacks; |
f6a92248 KY |
4010 | #endif |
4011 | ||
4012 | return 0; | |
4013 | } | |
4014 | ||
df694daa | 4015 | |
df694daa | 4016 | /* |
1d045db9 | 4017 | * ALC262 support |
df694daa | 4018 | */ |
1d045db9 | 4019 | static int alc262_parse_auto_config(struct hda_codec *codec) |
df694daa | 4020 | { |
1d045db9 | 4021 | static const hda_nid_t alc262_ignore[] = { 0x1d, 0 }; |
3e6179b8 TI |
4022 | static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
4023 | return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids); | |
df694daa KY |
4024 | } |
4025 | ||
df694daa | 4026 | /* |
1d045db9 | 4027 | * Pin config fixes |
df694daa | 4028 | */ |
cfc9b06f | 4029 | enum { |
1d045db9 TI |
4030 | PINFIX_FSC_H270, |
4031 | PINFIX_HP_Z200, | |
cfc9b06f TI |
4032 | }; |
4033 | ||
1d045db9 TI |
4034 | static const struct alc_fixup alc262_fixups[] = { |
4035 | [PINFIX_FSC_H270] = { | |
b5bfbc67 TI |
4036 | .type = ALC_FIXUP_PINS, |
4037 | .v.pins = (const struct alc_pincfg[]) { | |
1d045db9 TI |
4038 | { 0x14, 0x99130110 }, /* speaker */ |
4039 | { 0x15, 0x0221142f }, /* front HP */ | |
4040 | { 0x1b, 0x0121141f }, /* rear HP */ | |
4041 | { } | |
4042 | } | |
4043 | }, | |
4044 | [PINFIX_HP_Z200] = { | |
4045 | .type = ALC_FIXUP_PINS, | |
4046 | .v.pins = (const struct alc_pincfg[]) { | |
4047 | { 0x16, 0x99130120 }, /* internal speaker */ | |
73413b12 TI |
4048 | { } |
4049 | } | |
cfc9b06f TI |
4050 | }, |
4051 | }; | |
4052 | ||
1d045db9 TI |
4053 | static const struct snd_pci_quirk alc262_fixup_tbl[] = { |
4054 | SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200), | |
4055 | SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270), | |
cfc9b06f TI |
4056 | {} |
4057 | }; | |
df694daa | 4058 | |
1d045db9 TI |
4059 | |
4060 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
4061 | #define alc262_loopbacks alc880_loopbacks | |
4062 | #endif | |
4063 | ||
1d045db9 TI |
4064 | /* |
4065 | */ | |
4066 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
4067 | #include "alc262_quirks.c" | |
4068 | #endif | |
4069 | ||
4070 | static int patch_alc262(struct hda_codec *codec) | |
df694daa KY |
4071 | { |
4072 | struct alc_spec *spec; | |
4073 | int board_config; | |
4074 | int err; | |
4075 | ||
dc041e0b | 4076 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
df694daa KY |
4077 | if (spec == NULL) |
4078 | return -ENOMEM; | |
4079 | ||
f12ab1e0 | 4080 | codec->spec = spec; |
df694daa | 4081 | |
1d045db9 TI |
4082 | spec->mixer_nid = 0x0b; |
4083 | ||
4084 | #if 0 | |
4085 | /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is | |
4086 | * under-run | |
4087 | */ | |
4088 | { | |
4089 | int tmp; | |
4090 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); | |
4091 | tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); | |
4092 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7); | |
4093 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80); | |
4094 | } | |
4095 | #endif | |
4096 | alc_auto_parse_customize_define(codec); | |
1f0f4b80 | 4097 | |
1d045db9 TI |
4098 | alc_fix_pll_init(codec, 0x20, 0x0a, 10); |
4099 | ||
4100 | board_config = alc_board_config(codec, ALC262_MODEL_LAST, | |
4101 | alc262_models, alc262_cfg_tbl); | |
9c7f852e | 4102 | |
f5fcc13c | 4103 | if (board_config < 0) { |
9a11f1aa TI |
4104 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
4105 | codec->chip_name); | |
1d045db9 | 4106 | board_config = ALC_MODEL_AUTO; |
df694daa KY |
4107 | } |
4108 | ||
1d045db9 TI |
4109 | if (board_config == ALC_MODEL_AUTO) { |
4110 | alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups); | |
b5bfbc67 TI |
4111 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
4112 | } | |
cfc9b06f | 4113 | |
1d045db9 | 4114 | if (board_config == ALC_MODEL_AUTO) { |
df694daa | 4115 | /* automatic parse from the BIOS config */ |
1d045db9 | 4116 | err = alc262_parse_auto_config(codec); |
df694daa KY |
4117 | if (err < 0) { |
4118 | alc_free(codec); | |
4119 | return err; | |
1d045db9 TI |
4120 | } |
4121 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
4122 | else if (!err) { | |
9c7f852e TI |
4123 | printk(KERN_INFO |
4124 | "hda_codec: Cannot set up configuration " | |
4125 | "from BIOS. Using base mode...\n"); | |
1d045db9 | 4126 | board_config = ALC262_BASIC; |
df694daa | 4127 | } |
1d045db9 | 4128 | #endif |
df694daa KY |
4129 | } |
4130 | ||
1d045db9 TI |
4131 | if (board_config != ALC_MODEL_AUTO) |
4132 | setup_preset(codec, &alc262_presets[board_config]); | |
df694daa | 4133 | |
3e6179b8 | 4134 | if (!spec->no_analog && !spec->adc_nids && spec->input_mux) { |
21268961 TI |
4135 | alc_auto_fill_adc_caps(codec); |
4136 | alc_rebuild_imux_for_auto_mic(codec); | |
4137 | alc_remove_invalid_adc_nids(codec); | |
4138 | } | |
3e6179b8 TI |
4139 | |
4140 | if (!spec->no_analog && !spec->cap_mixer) | |
c7a8eb10 | 4141 | set_capture_mixer(codec); |
3e6179b8 TI |
4142 | |
4143 | if (!spec->no_analog && has_cdefine_beep(codec)) { | |
4144 | err = snd_hda_attach_beep_device(codec, 0x1); | |
4145 | if (err < 0) { | |
4146 | alc_free(codec); | |
4147 | return err; | |
4148 | } | |
1d045db9 | 4149 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); |
3e6179b8 | 4150 | } |
2134ea4f | 4151 | |
b5bfbc67 | 4152 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
7fa90e87 | 4153 | |
1d045db9 TI |
4154 | spec->vmaster_nid = 0x0c; |
4155 | ||
df694daa | 4156 | codec->patch_ops = alc_patch_ops; |
1d045db9 | 4157 | if (board_config == ALC_MODEL_AUTO) |
e4770629 | 4158 | spec->init_hook = alc_auto_init_std; |
1d045db9 TI |
4159 | spec->shutup = alc_eapd_shutup; |
4160 | ||
4161 | alc_init_jacks(codec); | |
cb53c626 TI |
4162 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
4163 | if (!spec->loopback.amplist) | |
1d045db9 | 4164 | spec->loopback.amplist = alc262_loopbacks; |
cb53c626 | 4165 | #endif |
ea1fb29a | 4166 | |
1da177e4 LT |
4167 | return 0; |
4168 | } | |
4169 | ||
f32610ed | 4170 | /* |
1d045db9 | 4171 | * ALC268 |
f32610ed | 4172 | */ |
1d045db9 TI |
4173 | /* bind Beep switches of both NID 0x0f and 0x10 */ |
4174 | static const struct hda_bind_ctls alc268_bind_beep_sw = { | |
4175 | .ops = &snd_hda_bind_sw, | |
4176 | .values = { | |
4177 | HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT), | |
4178 | HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT), | |
4179 | 0 | |
4180 | }, | |
f32610ed JS |
4181 | }; |
4182 | ||
1d045db9 TI |
4183 | static const struct snd_kcontrol_new alc268_beep_mixer[] = { |
4184 | HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT), | |
4185 | HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw), | |
4186 | { } | |
f32610ed JS |
4187 | }; |
4188 | ||
1d045db9 TI |
4189 | /* set PCBEEP vol = 0, mute connections */ |
4190 | static const struct hda_verb alc268_beep_init_verbs[] = { | |
4191 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4192 | {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
4193 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
4194 | { } | |
f32610ed JS |
4195 | }; |
4196 | ||
4197 | /* | |
4198 | * BIOS auto configuration | |
4199 | */ | |
1d045db9 | 4200 | static int alc268_parse_auto_config(struct hda_codec *codec) |
f32610ed | 4201 | { |
3e6179b8 | 4202 | static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
f32610ed | 4203 | struct alc_spec *spec = codec->spec; |
3e6179b8 TI |
4204 | int err = alc_parse_auto_config(codec, NULL, alc268_ssids); |
4205 | if (err > 0) { | |
4206 | if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) { | |
4207 | add_mixer(spec, alc268_beep_mixer); | |
4208 | add_verb(spec, alc268_beep_init_verbs); | |
1d045db9 | 4209 | } |
1d045db9 | 4210 | } |
3e6179b8 | 4211 | return err; |
f32610ed JS |
4212 | } |
4213 | ||
1d045db9 TI |
4214 | /* |
4215 | */ | |
4216 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
4217 | #include "alc268_quirks.c" | |
4218 | #endif | |
f8f25ba3 | 4219 | |
1d045db9 | 4220 | static int patch_alc268(struct hda_codec *codec) |
f32610ed JS |
4221 | { |
4222 | struct alc_spec *spec; | |
1d045db9 TI |
4223 | int board_config; |
4224 | int i, has_beep, err; | |
f32610ed JS |
4225 | |
4226 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
4227 | if (spec == NULL) | |
4228 | return -ENOMEM; | |
4229 | ||
4230 | codec->spec = spec; | |
4231 | ||
1d045db9 | 4232 | /* ALC268 has no aa-loopback mixer */ |
1f0f4b80 | 4233 | |
1d045db9 TI |
4234 | board_config = alc_board_config(codec, ALC268_MODEL_LAST, |
4235 | alc268_models, alc268_cfg_tbl); | |
f32610ed | 4236 | |
1d045db9 TI |
4237 | if (board_config < 0) |
4238 | board_config = alc_board_codec_sid_config(codec, | |
4239 | ALC268_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl); | |
4240 | ||
4241 | if (board_config < 0) { | |
9a11f1aa TI |
4242 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
4243 | codec->chip_name); | |
1d045db9 | 4244 | board_config = ALC_MODEL_AUTO; |
b5bfbc67 | 4245 | } |
f8f25ba3 | 4246 | |
1d045db9 | 4247 | if (board_config == ALC_MODEL_AUTO) { |
f32610ed | 4248 | /* automatic parse from the BIOS config */ |
1d045db9 | 4249 | err = alc268_parse_auto_config(codec); |
f32610ed JS |
4250 | if (err < 0) { |
4251 | alc_free(codec); | |
4252 | return err; | |
1d045db9 TI |
4253 | } |
4254 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
4255 | else if (!err) { | |
f32610ed JS |
4256 | printk(KERN_INFO |
4257 | "hda_codec: Cannot set up configuration " | |
4258 | "from BIOS. Using base mode...\n"); | |
1d045db9 | 4259 | board_config = ALC268_3ST; |
f32610ed | 4260 | } |
1d045db9 | 4261 | #endif |
f32610ed JS |
4262 | } |
4263 | ||
1d045db9 TI |
4264 | if (board_config != ALC_MODEL_AUTO) |
4265 | setup_preset(codec, &alc268_presets[board_config]); | |
680cd536 | 4266 | |
1d045db9 TI |
4267 | has_beep = 0; |
4268 | for (i = 0; i < spec->num_mixers; i++) { | |
4269 | if (spec->mixers[i] == alc268_beep_mixer) { | |
4270 | has_beep = 1; | |
4271 | break; | |
4272 | } | |
4273 | } | |
f32610ed | 4274 | |
1d045db9 TI |
4275 | if (has_beep) { |
4276 | err = snd_hda_attach_beep_device(codec, 0x1); | |
4277 | if (err < 0) { | |
4278 | alc_free(codec); | |
4279 | return err; | |
4280 | } | |
4281 | if (!query_amp_caps(codec, 0x1d, HDA_INPUT)) | |
4282 | /* override the amp caps for beep generator */ | |
4283 | snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT, | |
4284 | (0x0c << AC_AMPCAP_OFFSET_SHIFT) | | |
4285 | (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) | | |
4286 | (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) | | |
4287 | (0 << AC_AMPCAP_MUTE_SHIFT)); | |
2f893286 KY |
4288 | } |
4289 | ||
1d045db9 | 4290 | if (!spec->no_analog && !spec->adc_nids && spec->input_mux) { |
d6cc9fab | 4291 | alc_auto_fill_adc_caps(codec); |
21268961 | 4292 | alc_rebuild_imux_for_auto_mic(codec); |
d6cc9fab | 4293 | alc_remove_invalid_adc_nids(codec); |
dd704698 | 4294 | } |
f32610ed | 4295 | |
3e6179b8 | 4296 | if (!spec->no_analog && !spec->cap_mixer) |
1d045db9 | 4297 | set_capture_mixer(codec); |
f32610ed | 4298 | |
2134ea4f TI |
4299 | spec->vmaster_nid = 0x02; |
4300 | ||
f32610ed | 4301 | codec->patch_ops = alc_patch_ops; |
1d045db9 | 4302 | if (board_config == ALC_MODEL_AUTO) |
be9bc37b | 4303 | spec->init_hook = alc_auto_init_std; |
1c716153 | 4304 | spec->shutup = alc_eapd_shutup; |
1d045db9 TI |
4305 | |
4306 | alc_init_jacks(codec); | |
f32610ed JS |
4307 | |
4308 | return 0; | |
4309 | } | |
4310 | ||
bc9f98a9 | 4311 | /* |
1d045db9 | 4312 | * ALC269 |
bc9f98a9 | 4313 | */ |
1d045db9 TI |
4314 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
4315 | #define alc269_loopbacks alc880_loopbacks | |
4316 | #endif | |
e1406348 | 4317 | |
1d045db9 TI |
4318 | static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { |
4319 | .substreams = 1, | |
4320 | .channels_min = 2, | |
4321 | .channels_max = 8, | |
4322 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ | |
4323 | /* NID is set in alc_build_pcms */ | |
4324 | .ops = { | |
4325 | .open = alc_playback_pcm_open, | |
4326 | .prepare = alc_playback_pcm_prepare, | |
4327 | .cleanup = alc_playback_pcm_cleanup | |
bc9f98a9 KY |
4328 | }, |
4329 | }; | |
4330 | ||
1d045db9 TI |
4331 | static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = { |
4332 | .substreams = 1, | |
4333 | .channels_min = 2, | |
4334 | .channels_max = 2, | |
4335 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ | |
4336 | /* NID is set in alc_build_pcms */ | |
bc9f98a9 | 4337 | }; |
291702f0 | 4338 | |
1d045db9 TI |
4339 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
4340 | static int alc269_mic2_for_mute_led(struct hda_codec *codec) | |
4341 | { | |
4342 | switch (codec->subsystem_id) { | |
4343 | case 0x103c1586: | |
4344 | return 1; | |
4345 | } | |
4346 | return 0; | |
4347 | } | |
6dda9f4a | 4348 | |
1d045db9 TI |
4349 | static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid) |
4350 | { | |
4351 | /* update mute-LED according to the speaker mute state */ | |
4352 | if (nid == 0x01 || nid == 0x14) { | |
4353 | int pinval; | |
4354 | if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) & | |
4355 | HDA_AMP_MUTE) | |
4356 | pinval = 0x24; | |
4357 | else | |
4358 | pinval = 0x20; | |
4359 | /* mic2 vref pin is used for mute LED control */ | |
4360 | snd_hda_codec_update_cache(codec, 0x19, 0, | |
4361 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
4362 | pinval); | |
4363 | } | |
4364 | return alc_check_power_status(codec, nid); | |
4365 | } | |
4366 | #endif /* CONFIG_SND_HDA_POWER_SAVE */ | |
9541ba1d | 4367 | |
1d045db9 TI |
4368 | /* different alc269-variants */ |
4369 | enum { | |
4370 | ALC269_TYPE_ALC269VA, | |
4371 | ALC269_TYPE_ALC269VB, | |
4372 | ALC269_TYPE_ALC269VC, | |
bc9f98a9 KY |
4373 | }; |
4374 | ||
4375 | /* | |
1d045db9 | 4376 | * BIOS auto configuration |
bc9f98a9 | 4377 | */ |
1d045db9 TI |
4378 | static int alc269_parse_auto_config(struct hda_codec *codec) |
4379 | { | |
1d045db9 | 4380 | static const hda_nid_t alc269_ignore[] = { 0x1d, 0 }; |
3e6179b8 TI |
4381 | static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 }; |
4382 | static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 }; | |
4383 | struct alc_spec *spec = codec->spec; | |
4384 | const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ? | |
4385 | alc269va_ssids : alc269_ssids; | |
bc9f98a9 | 4386 | |
3e6179b8 | 4387 | return alc_parse_auto_config(codec, alc269_ignore, ssids); |
1d045db9 | 4388 | } |
bc9f98a9 | 4389 | |
1d045db9 TI |
4390 | static void alc269_toggle_power_output(struct hda_codec *codec, int power_up) |
4391 | { | |
4392 | int val = alc_read_coef_idx(codec, 0x04); | |
4393 | if (power_up) | |
4394 | val |= 1 << 11; | |
4395 | else | |
4396 | val &= ~(1 << 11); | |
4397 | alc_write_coef_idx(codec, 0x04, val); | |
4398 | } | |
291702f0 | 4399 | |
1d045db9 TI |
4400 | static void alc269_shutup(struct hda_codec *codec) |
4401 | { | |
4402 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) | |
4403 | alc269_toggle_power_output(codec, 0); | |
4404 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) { | |
4405 | alc269_toggle_power_output(codec, 0); | |
4406 | msleep(150); | |
4407 | } | |
4408 | } | |
291702f0 | 4409 | |
1d045db9 TI |
4410 | #ifdef SND_HDA_NEEDS_RESUME |
4411 | static int alc269_resume(struct hda_codec *codec) | |
4412 | { | |
4413 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) { | |
4414 | alc269_toggle_power_output(codec, 0); | |
4415 | msleep(150); | |
4416 | } | |
8c427226 | 4417 | |
1d045db9 | 4418 | codec->patch_ops.init(codec); |
f1d4e28b | 4419 | |
1d045db9 TI |
4420 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) { |
4421 | alc269_toggle_power_output(codec, 1); | |
4422 | msleep(200); | |
4423 | } | |
f1d4e28b | 4424 | |
1d045db9 TI |
4425 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) |
4426 | alc269_toggle_power_output(codec, 1); | |
f1d4e28b | 4427 | |
1d045db9 TI |
4428 | snd_hda_codec_resume_amp(codec); |
4429 | snd_hda_codec_resume_cache(codec); | |
4430 | hda_call_check_power_status(codec, 0x01); | |
4431 | return 0; | |
4432 | } | |
4433 | #endif /* SND_HDA_NEEDS_RESUME */ | |
f1d4e28b | 4434 | |
1d045db9 TI |
4435 | static void alc269_fixup_hweq(struct hda_codec *codec, |
4436 | const struct alc_fixup *fix, int action) | |
4437 | { | |
4438 | int coef; | |
f1d4e28b | 4439 | |
1d045db9 TI |
4440 | if (action != ALC_FIXUP_ACT_INIT) |
4441 | return; | |
4442 | coef = alc_read_coef_idx(codec, 0x1e); | |
4443 | alc_write_coef_idx(codec, 0x1e, coef | 0x80); | |
4444 | } | |
f1d4e28b | 4445 | |
1d045db9 TI |
4446 | static void alc271_fixup_dmic(struct hda_codec *codec, |
4447 | const struct alc_fixup *fix, int action) | |
4448 | { | |
4449 | static const struct hda_verb verbs[] = { | |
4450 | {0x20, AC_VERB_SET_COEF_INDEX, 0x0d}, | |
4451 | {0x20, AC_VERB_SET_PROC_COEF, 0x4000}, | |
4452 | {} | |
4453 | }; | |
4454 | unsigned int cfg; | |
f1d4e28b | 4455 | |
1d045db9 TI |
4456 | if (strcmp(codec->chip_name, "ALC271X")) |
4457 | return; | |
4458 | cfg = snd_hda_codec_get_pincfg(codec, 0x12); | |
4459 | if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED) | |
4460 | snd_hda_sequence_write(codec, verbs); | |
4461 | } | |
f1d4e28b | 4462 | |
1d045db9 TI |
4463 | enum { |
4464 | ALC269_FIXUP_SONY_VAIO, | |
4465 | ALC275_FIXUP_SONY_VAIO_GPIO2, | |
4466 | ALC269_FIXUP_DELL_M101Z, | |
4467 | ALC269_FIXUP_SKU_IGNORE, | |
4468 | ALC269_FIXUP_ASUS_G73JW, | |
4469 | ALC269_FIXUP_LENOVO_EAPD, | |
4470 | ALC275_FIXUP_SONY_HWEQ, | |
4471 | ALC271_FIXUP_DMIC, | |
f1d4e28b KY |
4472 | }; |
4473 | ||
1d045db9 TI |
4474 | static const struct alc_fixup alc269_fixups[] = { |
4475 | [ALC269_FIXUP_SONY_VAIO] = { | |
4476 | .type = ALC_FIXUP_VERBS, | |
4477 | .v.verbs = (const struct hda_verb[]) { | |
4478 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD}, | |
4479 | {} | |
4480 | } | |
f1d4e28b | 4481 | }, |
1d045db9 TI |
4482 | [ALC275_FIXUP_SONY_VAIO_GPIO2] = { |
4483 | .type = ALC_FIXUP_VERBS, | |
4484 | .v.verbs = (const struct hda_verb[]) { | |
4485 | {0x01, AC_VERB_SET_GPIO_MASK, 0x04}, | |
4486 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04}, | |
4487 | {0x01, AC_VERB_SET_GPIO_DATA, 0x00}, | |
4488 | { } | |
4489 | }, | |
4490 | .chained = true, | |
4491 | .chain_id = ALC269_FIXUP_SONY_VAIO | |
4492 | }, | |
4493 | [ALC269_FIXUP_DELL_M101Z] = { | |
4494 | .type = ALC_FIXUP_VERBS, | |
4495 | .v.verbs = (const struct hda_verb[]) { | |
4496 | /* Enables internal speaker */ | |
4497 | {0x20, AC_VERB_SET_COEF_INDEX, 13}, | |
4498 | {0x20, AC_VERB_SET_PROC_COEF, 0x4040}, | |
4499 | {} | |
4500 | } | |
4501 | }, | |
4502 | [ALC269_FIXUP_SKU_IGNORE] = { | |
4503 | .type = ALC_FIXUP_SKU, | |
4504 | .v.sku = ALC_FIXUP_SKU_IGNORE, | |
4505 | }, | |
4506 | [ALC269_FIXUP_ASUS_G73JW] = { | |
4507 | .type = ALC_FIXUP_PINS, | |
4508 | .v.pins = (const struct alc_pincfg[]) { | |
4509 | { 0x17, 0x99130111 }, /* subwoofer */ | |
4510 | { } | |
4511 | } | |
4512 | }, | |
4513 | [ALC269_FIXUP_LENOVO_EAPD] = { | |
4514 | .type = ALC_FIXUP_VERBS, | |
4515 | .v.verbs = (const struct hda_verb[]) { | |
4516 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, | |
4517 | {} | |
4518 | } | |
4519 | }, | |
4520 | [ALC275_FIXUP_SONY_HWEQ] = { | |
4521 | .type = ALC_FIXUP_FUNC, | |
4522 | .v.func = alc269_fixup_hweq, | |
4523 | .chained = true, | |
4524 | .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2 | |
4525 | }, | |
4526 | [ALC271_FIXUP_DMIC] = { | |
4527 | .type = ALC_FIXUP_FUNC, | |
4528 | .v.func = alc271_fixup_dmic, | |
f1d4e28b KY |
4529 | }, |
4530 | }; | |
4531 | ||
1d045db9 TI |
4532 | static const struct snd_pci_quirk alc269_fixup_tbl[] = { |
4533 | SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2), | |
4534 | SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), | |
4535 | SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), | |
4536 | SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO), | |
4537 | SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z), | |
4538 | SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC), | |
4539 | SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE), | |
4540 | SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE), | |
4541 | SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE), | |
4542 | SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE), | |
4543 | SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE), | |
4544 | SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW), | |
4545 | SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD), | |
4546 | {} | |
6dda9f4a KY |
4547 | }; |
4548 | ||
6dda9f4a | 4549 | |
1d045db9 TI |
4550 | static int alc269_fill_coef(struct hda_codec *codec) |
4551 | { | |
4552 | int val; | |
ebb83eeb | 4553 | |
1d045db9 TI |
4554 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) < 0x015) { |
4555 | alc_write_coef_idx(codec, 0xf, 0x960b); | |
4556 | alc_write_coef_idx(codec, 0xe, 0x8817); | |
4557 | } | |
ebb83eeb | 4558 | |
1d045db9 TI |
4559 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x016) { |
4560 | alc_write_coef_idx(codec, 0xf, 0x960b); | |
4561 | alc_write_coef_idx(codec, 0xe, 0x8814); | |
4562 | } | |
ebb83eeb | 4563 | |
1d045db9 TI |
4564 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) { |
4565 | val = alc_read_coef_idx(codec, 0x04); | |
4566 | /* Power up output pin */ | |
4567 | alc_write_coef_idx(codec, 0x04, val | (1<<11)); | |
4568 | } | |
ebb83eeb | 4569 | |
1d045db9 TI |
4570 | if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) { |
4571 | val = alc_read_coef_idx(codec, 0xd); | |
4572 | if ((val & 0x0c00) >> 10 != 0x1) { | |
4573 | /* Capless ramp up clock control */ | |
4574 | alc_write_coef_idx(codec, 0xd, val | (1<<10)); | |
4575 | } | |
4576 | val = alc_read_coef_idx(codec, 0x17); | |
4577 | if ((val & 0x01c0) >> 6 != 0x4) { | |
4578 | /* Class D power on reset */ | |
4579 | alc_write_coef_idx(codec, 0x17, val | (1<<7)); | |
4580 | } | |
4581 | } | |
ebb83eeb | 4582 | |
1d045db9 TI |
4583 | val = alc_read_coef_idx(codec, 0xd); /* Class D */ |
4584 | alc_write_coef_idx(codec, 0xd, val | (1<<14)); | |
bc9f98a9 | 4585 | |
1d045db9 TI |
4586 | val = alc_read_coef_idx(codec, 0x4); /* HP */ |
4587 | alc_write_coef_idx(codec, 0x4, val | (1<<11)); | |
6dda9f4a | 4588 | |
1d045db9 TI |
4589 | return 0; |
4590 | } | |
a7f2371f | 4591 | |
1d045db9 TI |
4592 | /* |
4593 | */ | |
4594 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
4595 | #include "alc269_quirks.c" | |
4596 | #endif | |
bc9f98a9 | 4597 | |
1d045db9 TI |
4598 | static int patch_alc269(struct hda_codec *codec) |
4599 | { | |
4600 | struct alc_spec *spec; | |
4601 | int board_config, coef; | |
4602 | int err; | |
291702f0 | 4603 | |
1d045db9 TI |
4604 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
4605 | if (spec == NULL) | |
4606 | return -ENOMEM; | |
bc9f98a9 | 4607 | |
1d045db9 | 4608 | codec->spec = spec; |
8c427226 | 4609 | |
1d045db9 | 4610 | spec->mixer_nid = 0x0b; |
f1d4e28b | 4611 | |
1d045db9 | 4612 | alc_auto_parse_customize_define(codec); |
f1d4e28b | 4613 | |
1d045db9 TI |
4614 | if (codec->vendor_id == 0x10ec0269) { |
4615 | spec->codec_variant = ALC269_TYPE_ALC269VA; | |
4616 | coef = alc_read_coef_idx(codec, 0); | |
4617 | if ((coef & 0x00f0) == 0x0010) { | |
4618 | if (codec->bus->pci->subsystem_vendor == 0x1025 && | |
4619 | spec->cdefine.platform_type == 1) { | |
4620 | alc_codec_rename(codec, "ALC271X"); | |
4621 | } else if ((coef & 0xf000) == 0x2000) { | |
4622 | alc_codec_rename(codec, "ALC259"); | |
4623 | } else if ((coef & 0xf000) == 0x3000) { | |
4624 | alc_codec_rename(codec, "ALC258"); | |
4625 | } else if ((coef & 0xfff0) == 0x3010) { | |
4626 | alc_codec_rename(codec, "ALC277"); | |
4627 | } else { | |
4628 | alc_codec_rename(codec, "ALC269VB"); | |
4629 | } | |
4630 | spec->codec_variant = ALC269_TYPE_ALC269VB; | |
4631 | } else if ((coef & 0x00f0) == 0x0020) { | |
4632 | if (coef == 0xa023) | |
4633 | alc_codec_rename(codec, "ALC259"); | |
4634 | else if (coef == 0x6023) | |
4635 | alc_codec_rename(codec, "ALC281X"); | |
4636 | else if (codec->bus->pci->subsystem_vendor == 0x17aa && | |
4637 | codec->bus->pci->subsystem_device == 0x21f3) | |
4638 | alc_codec_rename(codec, "ALC3202"); | |
4639 | else | |
4640 | alc_codec_rename(codec, "ALC269VC"); | |
4641 | spec->codec_variant = ALC269_TYPE_ALC269VC; | |
4642 | } else | |
4643 | alc_fix_pll_init(codec, 0x20, 0x04, 15); | |
4644 | alc269_fill_coef(codec); | |
4645 | } | |
6dda9f4a | 4646 | |
1d045db9 TI |
4647 | board_config = alc_board_config(codec, ALC269_MODEL_LAST, |
4648 | alc269_models, alc269_cfg_tbl); | |
6dda9f4a | 4649 | |
1d045db9 TI |
4650 | if (board_config < 0) { |
4651 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", | |
4652 | codec->chip_name); | |
4653 | board_config = ALC_MODEL_AUTO; | |
4654 | } | |
f1d4e28b | 4655 | |
1d045db9 TI |
4656 | if (board_config == ALC_MODEL_AUTO) { |
4657 | alc_pick_fixup(codec, NULL, alc269_fixup_tbl, alc269_fixups); | |
4658 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
4659 | } | |
6dda9f4a | 4660 | |
1d045db9 TI |
4661 | if (board_config == ALC_MODEL_AUTO) { |
4662 | /* automatic parse from the BIOS config */ | |
4663 | err = alc269_parse_auto_config(codec); | |
4664 | if (err < 0) { | |
4665 | alc_free(codec); | |
4666 | return err; | |
4667 | } | |
4668 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
4669 | else if (!err) { | |
4670 | printk(KERN_INFO | |
4671 | "hda_codec: Cannot set up configuration " | |
4672 | "from BIOS. Using base mode...\n"); | |
4673 | board_config = ALC269_BASIC; | |
4674 | } | |
4675 | #endif | |
4676 | } | |
6dda9f4a | 4677 | |
1d045db9 TI |
4678 | if (board_config != ALC_MODEL_AUTO) |
4679 | setup_preset(codec, &alc269_presets[board_config]); | |
6dda9f4a | 4680 | |
1d045db9 TI |
4681 | #if 0 |
4682 | if (board_config == ALC269_QUANTA_FL1) { | |
4683 | /* Due to a hardware problem on Lenovo Ideadpad, we need to | |
4684 | * fix the sample rate of analog I/O to 44.1kHz | |
4685 | */ | |
4686 | spec->stream_analog_playback = &alc269_44k_pcm_analog_playback; | |
4687 | spec->stream_analog_capture = &alc269_44k_pcm_analog_capture; | |
4688 | } | |
4689 | #endif | |
6dda9f4a | 4690 | |
3e6179b8 | 4691 | if (!spec->no_analog && !spec->adc_nids && spec->input_mux) { |
1d045db9 TI |
4692 | alc_auto_fill_adc_caps(codec); |
4693 | alc_rebuild_imux_for_auto_mic(codec); | |
4694 | alc_remove_invalid_adc_nids(codec); | |
4695 | } | |
6dda9f4a | 4696 | |
3e6179b8 | 4697 | if (!spec->no_analog && !spec->cap_mixer) |
1d045db9 | 4698 | set_capture_mixer(codec); |
3e6179b8 TI |
4699 | |
4700 | if (!spec->no_analog && has_cdefine_beep(codec)) { | |
4701 | err = snd_hda_attach_beep_device(codec, 0x1); | |
4702 | if (err < 0) { | |
4703 | alc_free(codec); | |
4704 | return err; | |
4705 | } | |
1d045db9 | 4706 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); |
3e6179b8 | 4707 | } |
f1d4e28b | 4708 | |
1d045db9 | 4709 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
622e84cd | 4710 | |
1d045db9 | 4711 | spec->vmaster_nid = 0x02; |
622e84cd | 4712 | |
1d045db9 TI |
4713 | codec->patch_ops = alc_patch_ops; |
4714 | #ifdef SND_HDA_NEEDS_RESUME | |
4715 | codec->patch_ops.resume = alc269_resume; | |
4716 | #endif | |
4717 | if (board_config == ALC_MODEL_AUTO) | |
be9bc37b | 4718 | spec->init_hook = alc_auto_init_std; |
1d045db9 | 4719 | spec->shutup = alc269_shutup; |
ebb83eeb | 4720 | |
1d045db9 TI |
4721 | alc_init_jacks(codec); |
4722 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
4723 | if (!spec->loopback.amplist) | |
4724 | spec->loopback.amplist = alc269_loopbacks; | |
4725 | if (alc269_mic2_for_mute_led(codec)) | |
4726 | codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps; | |
4727 | #endif | |
ebb83eeb | 4728 | |
1d045db9 TI |
4729 | return 0; |
4730 | } | |
f1d4e28b | 4731 | |
1d045db9 TI |
4732 | /* |
4733 | * ALC861 | |
4734 | */ | |
622e84cd | 4735 | |
1d045db9 | 4736 | static int alc861_parse_auto_config(struct hda_codec *codec) |
6dda9f4a | 4737 | { |
1d045db9 | 4738 | static const hda_nid_t alc861_ignore[] = { 0x1d, 0 }; |
3e6179b8 TI |
4739 | static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 }; |
4740 | return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids); | |
604401a9 TI |
4741 | } |
4742 | ||
1d045db9 TI |
4743 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
4744 | static const struct hda_amp_list alc861_loopbacks[] = { | |
4745 | { 0x15, HDA_INPUT, 0 }, | |
4746 | { 0x15, HDA_INPUT, 1 }, | |
4747 | { 0x15, HDA_INPUT, 2 }, | |
4748 | { 0x15, HDA_INPUT, 3 }, | |
4749 | { } /* end */ | |
4750 | }; | |
4751 | #endif | |
ce764ab2 | 4752 | |
ce764ab2 | 4753 | |
1d045db9 TI |
4754 | /* Pin config fixes */ |
4755 | enum { | |
4756 | PINFIX_FSC_AMILO_PI1505, | |
4757 | }; | |
7085ec12 | 4758 | |
1d045db9 TI |
4759 | static const struct alc_fixup alc861_fixups[] = { |
4760 | [PINFIX_FSC_AMILO_PI1505] = { | |
4761 | .type = ALC_FIXUP_PINS, | |
4762 | .v.pins = (const struct alc_pincfg[]) { | |
4763 | { 0x0b, 0x0221101f }, /* HP */ | |
4764 | { 0x0f, 0x90170310 }, /* speaker */ | |
4765 | { } | |
4766 | } | |
4767 | }, | |
4768 | }; | |
7085ec12 | 4769 | |
1d045db9 TI |
4770 | static const struct snd_pci_quirk alc861_fixup_tbl[] = { |
4771 | SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505), | |
4772 | {} | |
4773 | }; | |
3af9ee6b | 4774 | |
1d045db9 TI |
4775 | /* |
4776 | */ | |
4777 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
4778 | #include "alc861_quirks.c" | |
4779 | #endif | |
4780 | ||
4781 | static int patch_alc861(struct hda_codec *codec) | |
7085ec12 | 4782 | { |
1d045db9 TI |
4783 | struct alc_spec *spec; |
4784 | int board_config; | |
4785 | int err; | |
7085ec12 | 4786 | |
1d045db9 TI |
4787 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
4788 | if (spec == NULL) | |
4789 | return -ENOMEM; | |
3af9ee6b | 4790 | |
1d045db9 TI |
4791 | codec->spec = spec; |
4792 | ||
4793 | spec->mixer_nid = 0x15; | |
4794 | ||
4795 | board_config = alc_board_config(codec, ALC861_MODEL_LAST, | |
4796 | alc861_models, alc861_cfg_tbl); | |
4797 | ||
4798 | if (board_config < 0) { | |
4799 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", | |
4800 | codec->chip_name); | |
4801 | board_config = ALC_MODEL_AUTO; | |
3af9ee6b TI |
4802 | } |
4803 | ||
1d045db9 TI |
4804 | if (board_config == ALC_MODEL_AUTO) { |
4805 | alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); | |
4806 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
4807 | } | |
4808 | ||
4809 | if (board_config == ALC_MODEL_AUTO) { | |
4810 | /* automatic parse from the BIOS config */ | |
4811 | err = alc861_parse_auto_config(codec); | |
4812 | if (err < 0) { | |
4813 | alc_free(codec); | |
4814 | return err; | |
4815 | } | |
4816 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
4817 | else if (!err) { | |
4818 | printk(KERN_INFO | |
4819 | "hda_codec: Cannot set up configuration " | |
4820 | "from BIOS. Using base mode...\n"); | |
4821 | board_config = ALC861_3ST_DIG; | |
3af9ee6b | 4822 | } |
1d045db9 | 4823 | #endif |
3af9ee6b TI |
4824 | } |
4825 | ||
1d045db9 TI |
4826 | if (board_config != ALC_MODEL_AUTO) |
4827 | setup_preset(codec, &alc861_presets[board_config]); | |
bb8bf4d4 | 4828 | |
3e6179b8 | 4829 | if (!spec->no_analog && !spec->adc_nids && spec->input_mux) { |
1d045db9 TI |
4830 | alc_auto_fill_adc_caps(codec); |
4831 | alc_rebuild_imux_for_auto_mic(codec); | |
4832 | alc_remove_invalid_adc_nids(codec); | |
4833 | } | |
7085ec12 | 4834 | |
3e6179b8 | 4835 | if (!spec->no_analog && !spec->cap_mixer) |
1d045db9 | 4836 | set_capture_mixer(codec); |
3e6179b8 TI |
4837 | |
4838 | if (!spec->no_analog) { | |
4839 | err = snd_hda_attach_beep_device(codec, 0x23); | |
4840 | if (err < 0) { | |
4841 | alc_free(codec); | |
4842 | return err; | |
4843 | } | |
4844 | set_beep_amp(spec, 0x23, 0, HDA_OUTPUT); | |
4845 | } | |
7085ec12 | 4846 | |
1d045db9 | 4847 | spec->vmaster_nid = 0x03; |
97aaab7b | 4848 | |
1d045db9 TI |
4849 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
4850 | ||
4851 | codec->patch_ops = alc_patch_ops; | |
4852 | if (board_config == ALC_MODEL_AUTO) { | |
72dcd8e7 | 4853 | spec->init_hook = alc_auto_init_std; |
1d045db9 TI |
4854 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
4855 | spec->power_hook = alc_power_eapd; | |
4856 | #endif | |
97aaab7b | 4857 | } |
1d045db9 TI |
4858 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
4859 | if (!spec->loopback.amplist) | |
4860 | spec->loopback.amplist = alc861_loopbacks; | |
4861 | #endif | |
4862 | ||
4863 | return 0; | |
7085ec12 TI |
4864 | } |
4865 | ||
1d045db9 TI |
4866 | /* |
4867 | * ALC861-VD support | |
4868 | * | |
4869 | * Based on ALC882 | |
4870 | * | |
4871 | * In addition, an independent DAC | |
4872 | */ | |
4873 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
4874 | #define alc861vd_loopbacks alc880_loopbacks | |
4875 | #endif | |
4876 | ||
1d045db9 | 4877 | static int alc861vd_parse_auto_config(struct hda_codec *codec) |
bc9f98a9 | 4878 | { |
1d045db9 | 4879 | static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 }; |
3e6179b8 TI |
4880 | static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 }; |
4881 | return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids); | |
ce764ab2 TI |
4882 | } |
4883 | ||
1d045db9 TI |
4884 | enum { |
4885 | ALC660VD_FIX_ASUS_GPIO1 | |
4886 | }; | |
ce764ab2 | 4887 | |
1d045db9 TI |
4888 | /* reset GPIO1 */ |
4889 | static const struct alc_fixup alc861vd_fixups[] = { | |
4890 | [ALC660VD_FIX_ASUS_GPIO1] = { | |
4891 | .type = ALC_FIXUP_VERBS, | |
4892 | .v.verbs = (const struct hda_verb[]) { | |
4893 | {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, | |
4894 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, | |
4895 | {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, | |
4896 | { } | |
4897 | } | |
4898 | }, | |
4899 | }; | |
ce764ab2 | 4900 | |
1d045db9 TI |
4901 | static const struct snd_pci_quirk alc861vd_fixup_tbl[] = { |
4902 | SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1), | |
4903 | {} | |
4904 | }; | |
ce764ab2 | 4905 | |
1d045db9 TI |
4906 | static const struct hda_verb alc660vd_eapd_verbs[] = { |
4907 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2}, | |
4908 | {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2}, | |
4909 | { } | |
ce764ab2 TI |
4910 | }; |
4911 | ||
1d045db9 TI |
4912 | /* |
4913 | */ | |
4914 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
4915 | #include "alc861vd_quirks.c" | |
4916 | #endif | |
4917 | ||
4918 | static int patch_alc861vd(struct hda_codec *codec) | |
ce764ab2 | 4919 | { |
1d045db9 TI |
4920 | struct alc_spec *spec; |
4921 | int err, board_config; | |
ce764ab2 | 4922 | |
1d045db9 TI |
4923 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
4924 | if (spec == NULL) | |
4925 | return -ENOMEM; | |
4926 | ||
4927 | codec->spec = spec; | |
4928 | ||
4929 | spec->mixer_nid = 0x0b; | |
4930 | ||
4931 | board_config = alc_board_config(codec, ALC861VD_MODEL_LAST, | |
4932 | alc861vd_models, alc861vd_cfg_tbl); | |
4933 | ||
4934 | if (board_config < 0) { | |
4935 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", | |
4936 | codec->chip_name); | |
4937 | board_config = ALC_MODEL_AUTO; | |
3fccdfd8 | 4938 | } |
ce764ab2 | 4939 | |
1d045db9 TI |
4940 | if (board_config == ALC_MODEL_AUTO) { |
4941 | alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); | |
4942 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
4943 | } | |
ce764ab2 | 4944 | |
1d045db9 TI |
4945 | if (board_config == ALC_MODEL_AUTO) { |
4946 | /* automatic parse from the BIOS config */ | |
4947 | err = alc861vd_parse_auto_config(codec); | |
4948 | if (err < 0) { | |
4949 | alc_free(codec); | |
4950 | return err; | |
4951 | } | |
4952 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
4953 | else if (!err) { | |
4954 | printk(KERN_INFO | |
4955 | "hda_codec: Cannot set up configuration " | |
4956 | "from BIOS. Using base mode...\n"); | |
4957 | board_config = ALC861VD_3ST; | |
4958 | } | |
4959 | #endif | |
4960 | } | |
ce764ab2 | 4961 | |
1d045db9 TI |
4962 | if (board_config != ALC_MODEL_AUTO) |
4963 | setup_preset(codec, &alc861vd_presets[board_config]); | |
4964 | ||
4965 | if (codec->vendor_id == 0x10ec0660) { | |
4966 | /* always turn on EAPD */ | |
4967 | add_verb(spec, alc660vd_eapd_verbs); | |
4968 | } | |
4969 | ||
3e6179b8 | 4970 | if (!spec->no_analog && !spec->adc_nids && spec->input_mux) { |
1d045db9 TI |
4971 | alc_auto_fill_adc_caps(codec); |
4972 | alc_rebuild_imux_for_auto_mic(codec); | |
4973 | alc_remove_invalid_adc_nids(codec); | |
ce764ab2 | 4974 | } |
1d045db9 | 4975 | |
3e6179b8 TI |
4976 | if (!spec->no_analog && !spec->cap_mixer) |
4977 | set_capture_mixer(codec); | |
4978 | ||
4979 | if (!spec->no_analog) { | |
4980 | err = snd_hda_attach_beep_device(codec, 0x23); | |
4981 | if (err < 0) { | |
4982 | alc_free(codec); | |
4983 | return err; | |
4984 | } | |
4985 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); | |
4986 | } | |
1d045db9 TI |
4987 | |
4988 | spec->vmaster_nid = 0x02; | |
4989 | ||
4990 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); | |
4991 | ||
4992 | codec->patch_ops = alc_patch_ops; | |
4993 | ||
4994 | if (board_config == ALC_MODEL_AUTO) | |
e4770629 | 4995 | spec->init_hook = alc_auto_init_std; |
1d045db9 TI |
4996 | spec->shutup = alc_eapd_shutup; |
4997 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
4998 | if (!spec->loopback.amplist) | |
4999 | spec->loopback.amplist = alc861vd_loopbacks; | |
5000 | #endif | |
5001 | ||
ce764ab2 TI |
5002 | return 0; |
5003 | } | |
5004 | ||
1d045db9 TI |
5005 | /* |
5006 | * ALC662 support | |
5007 | * | |
5008 | * ALC662 is almost identical with ALC880 but has cleaner and more flexible | |
5009 | * configuration. Each pin widget can choose any input DACs and a mixer. | |
5010 | * Each ADC is connected from a mixer of all inputs. This makes possible | |
5011 | * 6-channel independent captures. | |
5012 | * | |
5013 | * In addition, an independent DAC for the multi-playback (not used in this | |
5014 | * driver yet). | |
5015 | */ | |
5016 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
5017 | #define alc662_loopbacks alc880_loopbacks | |
5018 | #endif | |
5019 | ||
5020 | /* | |
5021 | * BIOS auto configuration | |
5022 | */ | |
5023 | ||
bc9f98a9 KY |
5024 | static int alc662_parse_auto_config(struct hda_codec *codec) |
5025 | { | |
4c6d72d1 | 5026 | static const hda_nid_t alc662_ignore[] = { 0x1d, 0 }; |
3e6179b8 TI |
5027 | static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 }; |
5028 | static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 }; | |
5029 | const hda_nid_t *ssids; | |
ee979a14 | 5030 | |
6227cdce KY |
5031 | if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 || |
5032 | codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670) | |
3e6179b8 | 5033 | ssids = alc663_ssids; |
6227cdce | 5034 | else |
3e6179b8 TI |
5035 | ssids = alc662_ssids; |
5036 | return alc_parse_auto_config(codec, alc662_ignore, ssids); | |
bc9f98a9 KY |
5037 | } |
5038 | ||
6be7948f | 5039 | static void alc272_fixup_mario(struct hda_codec *codec, |
b5bfbc67 | 5040 | const struct alc_fixup *fix, int action) |
6fc398cb | 5041 | { |
b5bfbc67 | 5042 | if (action != ALC_FIXUP_ACT_PROBE) |
6fc398cb | 5043 | return; |
6be7948f TB |
5044 | if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT, |
5045 | (0x3b << AC_AMPCAP_OFFSET_SHIFT) | | |
5046 | (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) | | |
5047 | (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) | | |
5048 | (0 << AC_AMPCAP_MUTE_SHIFT))) | |
5049 | printk(KERN_WARNING | |
5050 | "hda_codec: failed to override amp caps for NID 0x2\n"); | |
5051 | } | |
5052 | ||
6cb3b707 | 5053 | enum { |
2df03514 | 5054 | ALC662_FIXUP_ASPIRE, |
6cb3b707 | 5055 | ALC662_FIXUP_IDEAPAD, |
6be7948f | 5056 | ALC272_FIXUP_MARIO, |
d2ebd479 | 5057 | ALC662_FIXUP_CZC_P10T, |
94024cd1 | 5058 | ALC662_FIXUP_SKU_IGNORE, |
e59ea3ed | 5059 | ALC662_FIXUP_HP_RP5800, |
6cb3b707 DH |
5060 | }; |
5061 | ||
5062 | static const struct alc_fixup alc662_fixups[] = { | |
2df03514 | 5063 | [ALC662_FIXUP_ASPIRE] = { |
b5bfbc67 TI |
5064 | .type = ALC_FIXUP_PINS, |
5065 | .v.pins = (const struct alc_pincfg[]) { | |
2df03514 DC |
5066 | { 0x15, 0x99130112 }, /* subwoofer */ |
5067 | { } | |
5068 | } | |
5069 | }, | |
6cb3b707 | 5070 | [ALC662_FIXUP_IDEAPAD] = { |
b5bfbc67 TI |
5071 | .type = ALC_FIXUP_PINS, |
5072 | .v.pins = (const struct alc_pincfg[]) { | |
6cb3b707 DH |
5073 | { 0x17, 0x99130112 }, /* subwoofer */ |
5074 | { } | |
5075 | } | |
5076 | }, | |
6be7948f | 5077 | [ALC272_FIXUP_MARIO] = { |
b5bfbc67 TI |
5078 | .type = ALC_FIXUP_FUNC, |
5079 | .v.func = alc272_fixup_mario, | |
d2ebd479 AA |
5080 | }, |
5081 | [ALC662_FIXUP_CZC_P10T] = { | |
5082 | .type = ALC_FIXUP_VERBS, | |
5083 | .v.verbs = (const struct hda_verb[]) { | |
5084 | {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, | |
5085 | {} | |
5086 | } | |
5087 | }, | |
94024cd1 DH |
5088 | [ALC662_FIXUP_SKU_IGNORE] = { |
5089 | .type = ALC_FIXUP_SKU, | |
5090 | .v.sku = ALC_FIXUP_SKU_IGNORE, | |
c6b35874 | 5091 | }, |
e59ea3ed TI |
5092 | [ALC662_FIXUP_HP_RP5800] = { |
5093 | .type = ALC_FIXUP_PINS, | |
5094 | .v.pins = (const struct alc_pincfg[]) { | |
5095 | { 0x14, 0x0221201f }, /* HP out */ | |
5096 | { } | |
5097 | }, | |
5098 | .chained = true, | |
5099 | .chain_id = ALC662_FIXUP_SKU_IGNORE | |
5100 | }, | |
6cb3b707 DH |
5101 | }; |
5102 | ||
a9111321 | 5103 | static const struct snd_pci_quirk alc662_fixup_tbl[] = { |
a6c47a85 | 5104 | SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE), |
94024cd1 | 5105 | SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE), |
2df03514 | 5106 | SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE), |
e59ea3ed | 5107 | SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), |
a0e90acc | 5108 | SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD), |
d4118588 | 5109 | SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD), |
6cb3b707 | 5110 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD), |
d2ebd479 | 5111 | SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T), |
6cb3b707 DH |
5112 | {} |
5113 | }; | |
5114 | ||
6be7948f TB |
5115 | static const struct alc_model_fixup alc662_fixup_models[] = { |
5116 | {.id = ALC272_FIXUP_MARIO, .name = "mario"}, | |
5117 | {} | |
5118 | }; | |
6cb3b707 DH |
5119 | |
5120 | ||
1d045db9 TI |
5121 | /* |
5122 | */ | |
5123 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
5124 | #include "alc662_quirks.c" | |
5125 | #endif | |
5126 | ||
bc9f98a9 KY |
5127 | static int patch_alc662(struct hda_codec *codec) |
5128 | { | |
5129 | struct alc_spec *spec; | |
5130 | int err, board_config; | |
693194f3 | 5131 | int coef; |
bc9f98a9 KY |
5132 | |
5133 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
5134 | if (!spec) | |
5135 | return -ENOMEM; | |
5136 | ||
5137 | codec->spec = spec; | |
5138 | ||
1f0f4b80 TI |
5139 | spec->mixer_nid = 0x0b; |
5140 | ||
da00c244 KY |
5141 | alc_auto_parse_customize_define(codec); |
5142 | ||
2c3bf9ab TI |
5143 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
5144 | ||
693194f3 KY |
5145 | coef = alc_read_coef_idx(codec, 0); |
5146 | if (coef == 0x8020 || coef == 0x8011) | |
c027ddcd | 5147 | alc_codec_rename(codec, "ALC661"); |
693194f3 KY |
5148 | else if (coef & (1 << 14) && |
5149 | codec->bus->pci->subsystem_vendor == 0x1025 && | |
5150 | spec->cdefine.platform_type == 1) | |
c027ddcd | 5151 | alc_codec_rename(codec, "ALC272X"); |
693194f3 KY |
5152 | else if (coef == 0x4011) |
5153 | alc_codec_rename(codec, "ALC656"); | |
274693f3 | 5154 | |
1d045db9 TI |
5155 | board_config = alc_board_config(codec, ALC662_MODEL_LAST, |
5156 | alc662_models, alc662_cfg_tbl); | |
bc9f98a9 | 5157 | if (board_config < 0) { |
9a11f1aa TI |
5158 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
5159 | codec->chip_name); | |
1d045db9 | 5160 | board_config = ALC_MODEL_AUTO; |
bc9f98a9 KY |
5161 | } |
5162 | ||
1d045db9 | 5163 | if (board_config == ALC_MODEL_AUTO) { |
b5bfbc67 TI |
5164 | alc_pick_fixup(codec, alc662_fixup_models, |
5165 | alc662_fixup_tbl, alc662_fixups); | |
5166 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | |
bc9f98a9 KY |
5167 | /* automatic parse from the BIOS config */ |
5168 | err = alc662_parse_auto_config(codec); | |
5169 | if (err < 0) { | |
5170 | alc_free(codec); | |
5171 | return err; | |
1d045db9 TI |
5172 | } |
5173 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
5174 | else if (!err) { | |
bc9f98a9 KY |
5175 | printk(KERN_INFO |
5176 | "hda_codec: Cannot set up configuration " | |
5177 | "from BIOS. Using base mode...\n"); | |
5178 | board_config = ALC662_3ST_2ch_DIG; | |
5179 | } | |
1d045db9 | 5180 | #endif |
bc9f98a9 KY |
5181 | } |
5182 | ||
1d045db9 | 5183 | if (board_config != ALC_MODEL_AUTO) |
e9c364c0 | 5184 | setup_preset(codec, &alc662_presets[board_config]); |
bc9f98a9 | 5185 | |
3e6179b8 | 5186 | if (!spec->no_analog && !spec->adc_nids && spec->input_mux) { |
d6cc9fab | 5187 | alc_auto_fill_adc_caps(codec); |
21268961 | 5188 | alc_rebuild_imux_for_auto_mic(codec); |
d6cc9fab | 5189 | alc_remove_invalid_adc_nids(codec); |
dd704698 | 5190 | } |
bc9f98a9 | 5191 | |
3e6179b8 | 5192 | if (!spec->no_analog && !spec->cap_mixer) |
b59bdf3b | 5193 | set_capture_mixer(codec); |
cec27c89 | 5194 | |
3e6179b8 TI |
5195 | if (!spec->no_analog && has_cdefine_beep(codec)) { |
5196 | err = snd_hda_attach_beep_device(codec, 0x1); | |
5197 | if (err < 0) { | |
5198 | alc_free(codec); | |
5199 | return err; | |
5200 | } | |
da00c244 KY |
5201 | switch (codec->vendor_id) { |
5202 | case 0x10ec0662: | |
5203 | set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); | |
5204 | break; | |
5205 | case 0x10ec0272: | |
5206 | case 0x10ec0663: | |
5207 | case 0x10ec0665: | |
5208 | set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); | |
5209 | break; | |
5210 | case 0x10ec0273: | |
5211 | set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT); | |
5212 | break; | |
5213 | } | |
cec27c89 | 5214 | } |
2134ea4f TI |
5215 | spec->vmaster_nid = 0x02; |
5216 | ||
b5bfbc67 TI |
5217 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); |
5218 | ||
bc9f98a9 | 5219 | codec->patch_ops = alc_patch_ops; |
1d045db9 | 5220 | if (board_config == ALC_MODEL_AUTO) |
e4770629 | 5221 | spec->init_hook = alc_auto_init_std; |
1c716153 | 5222 | spec->shutup = alc_eapd_shutup; |
6cb3b707 | 5223 | |
bf1b0225 KY |
5224 | alc_init_jacks(codec); |
5225 | ||
cb53c626 TI |
5226 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
5227 | if (!spec->loopback.amplist) | |
5228 | spec->loopback.amplist = alc662_loopbacks; | |
5229 | #endif | |
bc9f98a9 KY |
5230 | |
5231 | return 0; | |
5232 | } | |
5233 | ||
274693f3 KY |
5234 | static int patch_alc888(struct hda_codec *codec) |
5235 | { | |
5236 | if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){ | |
5237 | kfree(codec->chip_name); | |
01e0f137 KY |
5238 | if (codec->vendor_id == 0x10ec0887) |
5239 | codec->chip_name = kstrdup("ALC887-VD", GFP_KERNEL); | |
5240 | else | |
5241 | codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL); | |
ac2c92e0 TI |
5242 | if (!codec->chip_name) { |
5243 | alc_free(codec); | |
274693f3 | 5244 | return -ENOMEM; |
ac2c92e0 TI |
5245 | } |
5246 | return patch_alc662(codec); | |
274693f3 | 5247 | } |
ac2c92e0 | 5248 | return patch_alc882(codec); |
274693f3 KY |
5249 | } |
5250 | ||
b478b998 KY |
5251 | static int patch_alc899(struct hda_codec *codec) |
5252 | { | |
5253 | if ((alc_read_coef_idx(codec, 0) & 0x2000) != 0x2000) { | |
5254 | kfree(codec->chip_name); | |
5255 | codec->chip_name = kstrdup("ALC898", GFP_KERNEL); | |
5256 | } | |
5257 | return patch_alc882(codec); | |
5258 | } | |
5259 | ||
d1eb57f4 KY |
5260 | /* |
5261 | * ALC680 support | |
5262 | */ | |
d1eb57f4 | 5263 | |
d1eb57f4 KY |
5264 | static int alc680_parse_auto_config(struct hda_codec *codec) |
5265 | { | |
3e6179b8 | 5266 | return alc_parse_auto_config(codec, NULL, NULL); |
d1eb57f4 KY |
5267 | } |
5268 | ||
d1eb57f4 | 5269 | /* |
d1eb57f4 | 5270 | */ |
1d045db9 TI |
5271 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
5272 | #include "alc680_quirks.c" | |
5273 | #endif | |
d1eb57f4 KY |
5274 | |
5275 | static int patch_alc680(struct hda_codec *codec) | |
5276 | { | |
5277 | struct alc_spec *spec; | |
5278 | int board_config; | |
5279 | int err; | |
5280 | ||
5281 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
5282 | if (spec == NULL) | |
5283 | return -ENOMEM; | |
5284 | ||
5285 | codec->spec = spec; | |
5286 | ||
1f0f4b80 TI |
5287 | /* ALC680 has no aa-loopback mixer */ |
5288 | ||
1d045db9 TI |
5289 | board_config = alc_board_config(codec, ALC680_MODEL_LAST, |
5290 | alc680_models, alc680_cfg_tbl); | |
d1eb57f4 | 5291 | |
1d045db9 | 5292 | if (board_config < 0) { |
d1eb57f4 KY |
5293 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
5294 | codec->chip_name); | |
1d045db9 | 5295 | board_config = ALC_MODEL_AUTO; |
d1eb57f4 KY |
5296 | } |
5297 | ||
1d045db9 | 5298 | if (board_config == ALC_MODEL_AUTO) { |
d1eb57f4 KY |
5299 | /* automatic parse from the BIOS config */ |
5300 | err = alc680_parse_auto_config(codec); | |
5301 | if (err < 0) { | |
5302 | alc_free(codec); | |
5303 | return err; | |
1d045db9 TI |
5304 | } |
5305 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS | |
5306 | else if (!err) { | |
d1eb57f4 KY |
5307 | printk(KERN_INFO |
5308 | "hda_codec: Cannot set up configuration " | |
5309 | "from BIOS. Using base mode...\n"); | |
5310 | board_config = ALC680_BASE; | |
5311 | } | |
1d045db9 | 5312 | #endif |
d1eb57f4 KY |
5313 | } |
5314 | ||
1d045db9 | 5315 | if (board_config != ALC_MODEL_AUTO) { |
d1eb57f4 | 5316 | setup_preset(codec, &alc680_presets[board_config]); |
1d045db9 | 5317 | #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS |
21268961 | 5318 | spec->stream_analog_capture = &alc680_pcm_analog_auto_capture; |
1d045db9 | 5319 | #endif |
21268961 | 5320 | } |
d1eb57f4 | 5321 | |
3e6179b8 | 5322 | if (!spec->no_analog && !spec->adc_nids && spec->input_mux) { |
d6cc9fab | 5323 | alc_auto_fill_adc_caps(codec); |
21268961 | 5324 | alc_rebuild_imux_for_auto_mic(codec); |
d6cc9fab | 5325 | alc_remove_invalid_adc_nids(codec); |
d1eb57f4 KY |
5326 | } |
5327 | ||
3e6179b8 | 5328 | if (!spec->no_analog && !spec->cap_mixer) |
d1eb57f4 KY |
5329 | set_capture_mixer(codec); |
5330 | ||
5331 | spec->vmaster_nid = 0x02; | |
5332 | ||
5333 | codec->patch_ops = alc_patch_ops; | |
1d045db9 | 5334 | if (board_config == ALC_MODEL_AUTO) |
e4770629 | 5335 | spec->init_hook = alc_auto_init_std; |
d1eb57f4 KY |
5336 | |
5337 | return 0; | |
5338 | } | |
5339 | ||
1da177e4 LT |
5340 | /* |
5341 | * patch entries | |
5342 | */ | |
a9111321 | 5343 | static const struct hda_codec_preset snd_hda_preset_realtek[] = { |
296f0338 | 5344 | { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 }, |
1da177e4 | 5345 | { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 }, |
df694daa | 5346 | { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 }, |
f6a92248 | 5347 | { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 }, |
a361d84b | 5348 | { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 }, |
f6a92248 | 5349 | { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 }, |
ebb83eeb | 5350 | { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 }, |
01afd41f | 5351 | { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 }, |
ebb83eeb | 5352 | { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 }, |
296f0338 | 5353 | { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 }, |
f32610ed | 5354 | { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660", |
bc9f98a9 | 5355 | .patch = patch_alc861 }, |
f32610ed JS |
5356 | { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd }, |
5357 | { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 }, | |
5358 | { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd }, | |
bc9f98a9 | 5359 | { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2", |
4953550a | 5360 | .patch = patch_alc882 }, |
bc9f98a9 KY |
5361 | { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1", |
5362 | .patch = patch_alc662 }, | |
6dda9f4a | 5363 | { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 }, |
cec27c89 | 5364 | { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 }, |
6227cdce | 5365 | { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 }, |
d1eb57f4 | 5366 | { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 }, |
f32610ed | 5367 | { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, |
1da177e4 | 5368 | { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, |
4953550a | 5369 | { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 }, |
669faba2 | 5370 | { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A", |
4953550a | 5371 | .patch = patch_alc882 }, |
cb308f97 | 5372 | { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A", |
4953550a | 5373 | .patch = patch_alc882 }, |
df694daa | 5374 | { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, |
01e0f137 | 5375 | { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc888 }, |
4442608d | 5376 | { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", |
4953550a | 5377 | .patch = patch_alc882 }, |
274693f3 | 5378 | { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 }, |
4953550a | 5379 | { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 }, |
274693f3 | 5380 | { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 }, |
b478b998 | 5381 | { .id = 0x10ec0899, .name = "ALC899", .patch = patch_alc899 }, |
1da177e4 LT |
5382 | {} /* terminator */ |
5383 | }; | |
1289e9e8 TI |
5384 | |
5385 | MODULE_ALIAS("snd-hda-codec-id:10ec*"); | |
5386 | ||
5387 | MODULE_LICENSE("GPL"); | |
5388 | MODULE_DESCRIPTION("Realtek HD-audio codec"); | |
5389 | ||
5390 | static struct hda_codec_preset_list realtek_list = { | |
5391 | .preset = snd_hda_preset_realtek, | |
5392 | .owner = THIS_MODULE, | |
5393 | }; | |
5394 | ||
5395 | static int __init patch_realtek_init(void) | |
5396 | { | |
5397 | return snd_hda_add_codec_preset(&realtek_list); | |
5398 | } | |
5399 | ||
5400 | static void __exit patch_realtek_exit(void) | |
5401 | { | |
5402 | snd_hda_delete_codec_preset(&realtek_list); | |
5403 | } | |
5404 | ||
5405 | module_init(patch_realtek_init) | |
5406 | module_exit(patch_realtek_exit) |