diff options
author | Takashi Iwai <tiwai@suse.de> | 2012-12-19 09:22:24 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2013-01-12 02:31:03 -0500 |
commit | 08c189f2c5523eda847cddb89eb8f44c0b957431 (patch) | |
tree | df0359ed346f9f8ea92e0ab98590769738ee9909 /sound/pci/hda/patch_realtek.c | |
parent | 5d550e15be0a960c7ff5dbcf12b5a454e70403b6 (diff) |
ALSA: hda - Use generic parser codes for Realtek driver
The next migration step is to use the common code in generic driver
for Realtek driver. This is no drastic change and there should be no
real functional changes, as the generic parser code comes from Realtek
driver originally.
As Realtek driver requires the generic parser code, it needs a
reverse-selection of CONFIG_SND_HDA_GENERIC kconfig.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/patch_realtek.c')
-rw-r--r-- | sound/pci/hda/patch_realtek.c | 3760 |
1 files changed, 126 insertions, 3634 deletions
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index c85899d50404..896bc2cc9293 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c | |||
@@ -36,12 +36,10 @@ | |||
36 | #include "hda_auto_parser.h" | 36 | #include "hda_auto_parser.h" |
37 | #include "hda_beep.h" | 37 | #include "hda_beep.h" |
38 | #include "hda_jack.h" | 38 | #include "hda_jack.h" |
39 | #include "hda_generic.h" | ||
39 | 40 | ||
40 | /* unsol event tags */ | 41 | /* unsol event tags */ |
41 | #define ALC_FRONT_EVENT 0x01 | 42 | #define ALC_DCVOL_EVENT 0x08 |
42 | #define ALC_DCVOL_EVENT 0x02 | ||
43 | #define ALC_HP_EVENT 0x04 | ||
44 | #define ALC_MIC_EVENT 0x08 | ||
45 | 43 | ||
46 | /* for GPIO Poll */ | 44 | /* for GPIO Poll */ |
47 | #define GPIO_MASK 0x03 | 45 | #define GPIO_MASK 0x03 |
@@ -68,12 +66,6 @@ struct alc_customize_define { | |||
68 | unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */ | 66 | unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */ |
69 | }; | 67 | }; |
70 | 68 | ||
71 | struct alc_multi_io { | ||
72 | hda_nid_t pin; /* multi-io widget pin NID */ | ||
73 | hda_nid_t dac; /* DAC to be connected */ | ||
74 | unsigned int ctl_in; /* cached input-pin control value */ | ||
75 | }; | ||
76 | |||
77 | /* make compatible with old code */ | 69 | /* make compatible with old code */ |
78 | #define alc_apply_pincfgs snd_hda_apply_pincfgs | 70 | #define alc_apply_pincfgs snd_hda_apply_pincfgs |
79 | #define alc_apply_fixup snd_hda_apply_fixup | 71 | #define alc_apply_fixup snd_hda_apply_fixup |
@@ -91,112 +83,21 @@ struct alc_multi_io { | |||
91 | #define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT | 83 | #define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT |
92 | #define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD | 84 | #define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD |
93 | 85 | ||
94 | #define MAX_AUTO_MIC_PINS 3 | ||
95 | |||
96 | struct alc_automic_entry { | ||
97 | hda_nid_t pin; /* pin */ | ||
98 | int idx; /* imux index, -1 = invalid */ | ||
99 | unsigned int attr; /* pin attribute (INPUT_PIN_ATTR_*) */ | ||
100 | }; | ||
101 | |||
102 | #define MAX_NID_PATH_DEPTH 5 | ||
103 | |||
104 | enum { | ||
105 | NID_PATH_VOL_CTL, | ||
106 | NID_PATH_MUTE_CTL, | ||
107 | NID_PATH_BOOST_CTL, | ||
108 | NID_PATH_NUM_CTLS | ||
109 | }; | ||
110 | |||
111 | /* Widget connection path | ||
112 | * | ||
113 | * For output, stored in the order of DAC -> ... -> pin, | ||
114 | * for input, pin -> ... -> ADC. | ||
115 | * | ||
116 | * idx[i] contains the source index number to select on of the widget path[i]; | ||
117 | * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget | ||
118 | * multi[] indicates whether it's a selector widget with multi-connectors | ||
119 | * (i.e. the connection selection is mandatory) | ||
120 | * vol_ctl and mute_ctl contains the NIDs for the assigned mixers | ||
121 | */ | ||
122 | struct nid_path { | ||
123 | int depth; | ||
124 | hda_nid_t path[MAX_NID_PATH_DEPTH]; | ||
125 | unsigned char idx[MAX_NID_PATH_DEPTH]; | ||
126 | unsigned char multi[MAX_NID_PATH_DEPTH]; | ||
127 | unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */ | ||
128 | bool active; | ||
129 | }; | ||
130 | |||
131 | struct alc_spec { | 86 | struct alc_spec { |
87 | struct hda_gen_spec gen; /* must be at head */ | ||
88 | |||
132 | /* codec parameterization */ | 89 | /* codec parameterization */ |
133 | const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ | 90 | const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ |
134 | unsigned int num_mixers; | 91 | unsigned int num_mixers; |
135 | unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ | 92 | unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ |
136 | 93 | ||
137 | char stream_name_analog[32]; /* analog PCM stream */ | ||
138 | const struct hda_pcm_stream *stream_analog_playback; | ||
139 | const struct hda_pcm_stream *stream_analog_capture; | ||
140 | const struct hda_pcm_stream *stream_analog_alt_playback; | ||
141 | const struct hda_pcm_stream *stream_analog_alt_capture; | ||
142 | |||
143 | char stream_name_digital[32]; /* digital PCM stream */ | ||
144 | const struct hda_pcm_stream *stream_digital_playback; | ||
145 | const struct hda_pcm_stream *stream_digital_capture; | ||
146 | |||
147 | /* playback */ | ||
148 | struct hda_multi_out multiout; /* playback set-up | ||
149 | * max_channels, dacs must be set | ||
150 | * dig_out_nid and hp_nid are optional | ||
151 | */ | ||
152 | hda_nid_t alt_dac_nid; | ||
153 | hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */ | ||
154 | int dig_out_type; | ||
155 | |||
156 | /* capture */ | ||
157 | unsigned int num_adc_nids; | ||
158 | hda_nid_t adc_nids[AUTO_CFG_MAX_OUTS]; | ||
159 | hda_nid_t dig_in_nid; /* digital-in NID; optional */ | ||
160 | hda_nid_t mixer_nid; /* analog-mixer NID */ | ||
161 | |||
162 | /* capture setup for dynamic dual-adc switch */ | ||
163 | hda_nid_t cur_adc; | ||
164 | unsigned int cur_adc_stream_tag; | ||
165 | unsigned int cur_adc_format; | ||
166 | |||
167 | /* capture source */ | ||
168 | struct hda_input_mux input_mux; | ||
169 | unsigned int cur_mux[3]; | ||
170 | |||
171 | /* channel model */ | ||
172 | const struct hda_channel_mode *channel_mode; | ||
173 | int num_channel_mode; | ||
174 | int const_channel_count; /* min. channel count (for speakers) */ | ||
175 | int ext_channel_count; /* current channel count for multi-io */ | ||
176 | |||
177 | /* PCM information */ | ||
178 | struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */ | ||
179 | |||
180 | /* dynamic controls, init_verbs and input_mux */ | ||
181 | struct auto_pin_cfg autocfg; | ||
182 | struct alc_customize_define cdefine; | 94 | struct alc_customize_define cdefine; |
183 | struct snd_array kctls; | 95 | unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */ |
184 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; | ||
185 | hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS]; | ||
186 | unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS]; | ||
187 | hda_nid_t inv_dmic_pin; | ||
188 | hda_nid_t shared_mic_vref_pin; | ||
189 | 96 | ||
190 | /* DAC list */ | 97 | /* inverted dmic fix */ |
191 | int num_all_dacs; | 98 | unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */ |
192 | hda_nid_t all_dacs[16]; | 99 | unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */ |
193 | 100 | hda_nid_t inv_dmic_pin; | |
194 | /* path list */ | ||
195 | struct snd_array paths; | ||
196 | |||
197 | /* auto-mic stuff */ | ||
198 | int am_num_entries; | ||
199 | struct alc_automic_entry am_entry[MAX_AUTO_MIC_PINS]; | ||
200 | 101 | ||
201 | /* hooks */ | 102 | /* hooks */ |
202 | void (*init_hook)(struct hda_codec *codec); | 103 | void (*init_hook)(struct hda_codec *codec); |
@@ -204,224 +105,16 @@ struct alc_spec { | |||
204 | void (*power_hook)(struct hda_codec *codec); | 105 | void (*power_hook)(struct hda_codec *codec); |
205 | #endif | 106 | #endif |
206 | void (*shutup)(struct hda_codec *codec); | 107 | void (*shutup)(struct hda_codec *codec); |
207 | void (*automute_hook)(struct hda_codec *codec); | ||
208 | |||
209 | /* for pin sensing */ | ||
210 | unsigned int hp_jack_present:1; | ||
211 | unsigned int line_jack_present:1; | ||
212 | unsigned int master_mute:1; | ||
213 | unsigned int auto_mic:1; | ||
214 | unsigned int automute_speaker:1; /* automute speaker outputs */ | ||
215 | unsigned int automute_lo:1; /* automute LO outputs */ | ||
216 | unsigned int detect_hp:1; /* Headphone detection enabled */ | ||
217 | unsigned int detect_lo:1; /* Line-out detection enabled */ | ||
218 | unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */ | ||
219 | unsigned int automute_lo_possible:1; /* there are line outs and HP */ | ||
220 | unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */ | ||
221 | unsigned int line_in_auto_switch:1; /* allow line-in auto switch */ | ||
222 | |||
223 | /* other flags */ | ||
224 | unsigned int need_dac_fix:1; /* need to limit DACs for multi channels */ | ||
225 | unsigned int no_analog :1; /* digital I/O only */ | ||
226 | unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */ | ||
227 | unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */ | ||
228 | unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */ | ||
229 | unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */ | ||
230 | unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */ | ||
231 | unsigned int multi_cap_vol:1; /* allow multiple capture xxx volumes */ | ||
232 | unsigned int inv_dmic_split:1; /* inverted dmic w/a for conexant */ | ||
233 | |||
234 | unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */ | ||
235 | 108 | ||
236 | int init_amp; | 109 | int init_amp; |
237 | int codec_variant; /* flag for other variants */ | 110 | int codec_variant; /* flag for other variants */ |
238 | 111 | ||
239 | /* for virtual master */ | ||
240 | hda_nid_t vmaster_nid; | ||
241 | struct hda_vmaster_mute_hook vmaster_mute; | ||
242 | #ifdef CONFIG_PM | ||
243 | struct hda_loopback_check loopback; | ||
244 | int num_loopbacks; | ||
245 | struct hda_amp_list loopback_list[8]; | ||
246 | #endif | ||
247 | |||
248 | /* for PLL fix */ | 112 | /* for PLL fix */ |
249 | hda_nid_t pll_nid; | 113 | hda_nid_t pll_nid; |
250 | unsigned int pll_coef_idx, pll_coef_bit; | 114 | unsigned int pll_coef_idx, pll_coef_bit; |
251 | unsigned int coef0; | 115 | unsigned int coef0; |
252 | |||
253 | /* multi-io */ | ||
254 | int multi_ios; | ||
255 | struct alc_multi_io multi_io[4]; | ||
256 | |||
257 | /* bind volumes */ | ||
258 | struct snd_array bind_ctls; | ||
259 | }; | 116 | }; |
260 | 117 | ||
261 | static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, | ||
262 | int dir, unsigned int bits) | ||
263 | { | ||
264 | if (!nid) | ||
265 | return false; | ||
266 | if (get_wcaps(codec, nid) & (1 << (dir + 1))) | ||
267 | if (query_amp_caps(codec, nid, dir) & bits) | ||
268 | return true; | ||
269 | return false; | ||
270 | } | ||
271 | |||
272 | #define nid_has_mute(codec, nid, dir) \ | ||
273 | check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE) | ||
274 | #define nid_has_volume(codec, nid, dir) \ | ||
275 | check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS) | ||
276 | |||
277 | static struct nid_path * | ||
278 | get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid); | ||
279 | static void activate_path(struct hda_codec *codec, struct nid_path *path, | ||
280 | bool enable, bool add_aamix); | ||
281 | |||
282 | /* | ||
283 | * input MUX handling | ||
284 | */ | ||
285 | static int alc_mux_enum_info(struct snd_kcontrol *kcontrol, | ||
286 | struct snd_ctl_elem_info *uinfo) | ||
287 | { | ||
288 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
289 | struct alc_spec *spec = codec->spec; | ||
290 | return snd_hda_input_mux_info(&spec->input_mux, uinfo); | ||
291 | } | ||
292 | |||
293 | static int alc_mux_enum_get(struct snd_kcontrol *kcontrol, | ||
294 | struct snd_ctl_elem_value *ucontrol) | ||
295 | { | ||
296 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
297 | struct alc_spec *spec = codec->spec; | ||
298 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | ||
299 | |||
300 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; | ||
301 | return 0; | ||
302 | } | ||
303 | |||
304 | static hda_nid_t get_adc_nid(struct hda_codec *codec, int adc_idx, int imux_idx) | ||
305 | { | ||
306 | struct alc_spec *spec = codec->spec; | ||
307 | if (spec->dyn_adc_switch) | ||
308 | adc_idx = spec->dyn_adc_idx[imux_idx]; | ||
309 | return spec->adc_nids[adc_idx]; | ||
310 | } | ||
311 | |||
312 | static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur) | ||
313 | { | ||
314 | struct alc_spec *spec = codec->spec; | ||
315 | hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]]; | ||
316 | |||
317 | if (spec->cur_adc && spec->cur_adc != new_adc) { | ||
318 | /* stream is running, let's swap the current ADC */ | ||
319 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); | ||
320 | spec->cur_adc = new_adc; | ||
321 | snd_hda_codec_setup_stream(codec, new_adc, | ||
322 | spec->cur_adc_stream_tag, 0, | ||
323 | spec->cur_adc_format); | ||
324 | return true; | ||
325 | } | ||
326 | return false; | ||
327 | } | ||
328 | |||
329 | static void call_update_outputs(struct hda_codec *codec); | ||
330 | static void alc_inv_dmic_sync(struct hda_codec *codec, bool force); | ||
331 | static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx); | ||
332 | |||
333 | /* for shared I/O, change the pin-control accordingly */ | ||
334 | static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic) | ||
335 | { | ||
336 | struct alc_spec *spec = codec->spec; | ||
337 | unsigned int val; | ||
338 | hda_nid_t pin = spec->autocfg.inputs[1].pin; | ||
339 | /* NOTE: this assumes that there are only two inputs, the | ||
340 | * first is the real internal mic and the second is HP/mic jack. | ||
341 | */ | ||
342 | |||
343 | val = snd_hda_get_default_vref(codec, pin); | ||
344 | |||
345 | /* This pin does not have vref caps - let's enable vref on pin 0x18 | ||
346 | instead, as suggested by Realtek */ | ||
347 | if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) { | ||
348 | const hda_nid_t vref_pin = spec->shared_mic_vref_pin; | ||
349 | unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin); | ||
350 | if (vref_val != AC_PINCTL_VREF_HIZ) | ||
351 | snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0)); | ||
352 | } | ||
353 | |||
354 | val = set_as_mic ? val | PIN_IN : PIN_HP; | ||
355 | snd_hda_set_pin_ctl(codec, pin, val); | ||
356 | |||
357 | spec->automute_speaker = !set_as_mic; | ||
358 | call_update_outputs(codec); | ||
359 | } | ||
360 | |||
361 | /* select the given imux item; either unmute exclusively or select the route */ | ||
362 | static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx, | ||
363 | unsigned int idx) | ||
364 | { | ||
365 | struct alc_spec *spec = codec->spec; | ||
366 | const struct hda_input_mux *imux; | ||
367 | struct nid_path *path; | ||
368 | |||
369 | imux = &spec->input_mux; | ||
370 | if (!imux->num_items) | ||
371 | return 0; | ||
372 | |||
373 | if (idx >= imux->num_items) | ||
374 | idx = imux->num_items - 1; | ||
375 | if (spec->cur_mux[adc_idx] == idx) | ||
376 | return 0; | ||
377 | |||
378 | path = get_nid_path(codec, spec->imux_pins[spec->cur_mux[adc_idx]], | ||
379 | spec->adc_nids[adc_idx]); | ||
380 | if (!path) | ||
381 | return 0; | ||
382 | if (path->active) | ||
383 | activate_path(codec, path, false, false); | ||
384 | |||
385 | spec->cur_mux[adc_idx] = idx; | ||
386 | |||
387 | if (spec->shared_mic_hp) | ||
388 | update_shared_mic_hp(codec, spec->cur_mux[adc_idx]); | ||
389 | |||
390 | if (spec->dyn_adc_switch) | ||
391 | alc_dyn_adc_pcm_resetup(codec, idx); | ||
392 | |||
393 | path = get_nid_path(codec, spec->imux_pins[idx], | ||
394 | get_adc_nid(codec, adc_idx, idx)); | ||
395 | if (!path) | ||
396 | return 0; | ||
397 | if (path->active) | ||
398 | return 0; | ||
399 | activate_path(codec, path, true, false); | ||
400 | alc_inv_dmic_sync(codec, true); | ||
401 | return 1; | ||
402 | } | ||
403 | |||
404 | static int alc_mux_enum_put(struct snd_kcontrol *kcontrol, | ||
405 | struct snd_ctl_elem_value *ucontrol) | ||
406 | { | ||
407 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
408 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | ||
409 | return alc_mux_select(codec, adc_idx, | ||
410 | ucontrol->value.enumerated.item[0]); | ||
411 | } | ||
412 | |||
413 | /* | ||
414 | * set up the input pin config (depending on the given auto-pin type) | ||
415 | */ | ||
416 | static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid, | ||
417 | int auto_pin_type) | ||
418 | { | ||
419 | unsigned int val = PIN_IN; | ||
420 | if (auto_pin_type == AUTO_PIN_MIC) | ||
421 | val |= snd_hda_get_default_vref(codec, nid); | ||
422 | snd_hda_set_pin_ctl(codec, nid, val); | ||
423 | } | ||
424 | |||
425 | /* | 118 | /* |
426 | * Append the given mixer and verb elements for the later use | 119 | * Append the given mixer and verb elements for the later use |
427 | * The mixer array is referred in build_controls(), and init_verbs are | 120 | * The mixer array is referred in build_controls(), and init_verbs are |
@@ -491,146 +184,6 @@ static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid, | |||
491 | alc_fix_pll(codec); | 184 | alc_fix_pll(codec); |
492 | } | 185 | } |
493 | 186 | ||
494 | /* | ||
495 | * Jack detections for HP auto-mute and mic-switch | ||
496 | */ | ||
497 | |||
498 | /* check each pin in the given array; returns true if any of them is plugged */ | ||
499 | static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) | ||
500 | { | ||
501 | int i, present = 0; | ||
502 | |||
503 | for (i = 0; i < num_pins; i++) { | ||
504 | hda_nid_t nid = pins[i]; | ||
505 | if (!nid) | ||
506 | break; | ||
507 | present |= snd_hda_jack_detect(codec, nid); | ||
508 | } | ||
509 | return present; | ||
510 | } | ||
511 | |||
512 | /* standard HP/line-out auto-mute helper */ | ||
513 | static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins, | ||
514 | bool mute, bool hp_out) | ||
515 | { | ||
516 | struct alc_spec *spec = codec->spec; | ||
517 | unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT); | ||
518 | int i; | ||
519 | |||
520 | for (i = 0; i < num_pins; i++) { | ||
521 | hda_nid_t nid = pins[i]; | ||
522 | unsigned int val; | ||
523 | if (!nid) | ||
524 | break; | ||
525 | /* don't reset VREF value in case it's controlling | ||
526 | * the amp (see alc861_fixup_asus_amp_vref_0f()) | ||
527 | */ | ||
528 | if (spec->keep_vref_in_automute) { | ||
529 | val = snd_hda_codec_read(codec, nid, 0, | ||
530 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | ||
531 | val &= ~PIN_HP; | ||
532 | } else | ||
533 | val = 0; | ||
534 | val |= pin_bits; | ||
535 | snd_hda_set_pin_ctl(codec, nid, val); | ||
536 | } | ||
537 | } | ||
538 | |||
539 | /* Toggle outputs muting */ | ||
540 | static void update_outputs(struct hda_codec *codec) | ||
541 | { | ||
542 | struct alc_spec *spec = codec->spec; | ||
543 | int on; | ||
544 | |||
545 | /* Control HP pins/amps depending on master_mute state; | ||
546 | * in general, HP pins/amps control should be enabled in all cases, | ||
547 | * but currently set only for master_mute, just to be safe | ||
548 | */ | ||
549 | if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */ | ||
550 | do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins), | ||
551 | spec->autocfg.hp_pins, spec->master_mute, true); | ||
552 | |||
553 | if (!spec->automute_speaker) | ||
554 | on = 0; | ||
555 | else | ||
556 | on = spec->hp_jack_present | spec->line_jack_present; | ||
557 | on |= spec->master_mute; | ||
558 | do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins), | ||
559 | spec->autocfg.speaker_pins, on, false); | ||
560 | |||
561 | /* toggle line-out mutes if needed, too */ | ||
562 | /* if LO is a copy of either HP or Speaker, don't need to handle it */ | ||
563 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] || | ||
564 | spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0]) | ||
565 | return; | ||
566 | if (!spec->automute_lo) | ||
567 | on = 0; | ||
568 | else | ||
569 | on = spec->hp_jack_present; | ||
570 | on |= spec->master_mute; | ||
571 | do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), | ||
572 | spec->autocfg.line_out_pins, on, false); | ||
573 | } | ||
574 | |||
575 | static void call_update_outputs(struct hda_codec *codec) | ||
576 | { | ||
577 | struct alc_spec *spec = codec->spec; | ||
578 | if (spec->automute_hook) | ||
579 | spec->automute_hook(codec); | ||
580 | else | ||
581 | update_outputs(codec); | ||
582 | } | ||
583 | |||
584 | /* standard HP-automute helper */ | ||
585 | static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack) | ||
586 | { | ||
587 | struct alc_spec *spec = codec->spec; | ||
588 | |||
589 | spec->hp_jack_present = | ||
590 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins), | ||
591 | spec->autocfg.hp_pins); | ||
592 | if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo)) | ||
593 | return; | ||
594 | call_update_outputs(codec); | ||
595 | } | ||
596 | |||
597 | /* standard line-out-automute helper */ | ||
598 | static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack) | ||
599 | { | ||
600 | struct alc_spec *spec = codec->spec; | ||
601 | |||
602 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) | ||
603 | return; | ||
604 | /* check LO jack only when it's different from HP */ | ||
605 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0]) | ||
606 | return; | ||
607 | |||
608 | spec->line_jack_present = | ||
609 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), | ||
610 | spec->autocfg.line_out_pins); | ||
611 | if (!spec->automute_speaker || !spec->detect_lo) | ||
612 | return; | ||
613 | call_update_outputs(codec); | ||
614 | } | ||
615 | |||
616 | /* standard mic auto-switch helper */ | ||
617 | static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack) | ||
618 | { | ||
619 | struct alc_spec *spec = codec->spec; | ||
620 | int i; | ||
621 | |||
622 | if (!spec->auto_mic) | ||
623 | return; | ||
624 | |||
625 | for (i = spec->am_num_entries - 1; i > 0; i--) { | ||
626 | if (snd_hda_jack_detect(codec, spec->am_entry[i].pin)) { | ||
627 | alc_mux_select(codec, 0, spec->am_entry[i].idx); | ||
628 | return; | ||
629 | } | ||
630 | } | ||
631 | alc_mux_select(codec, 0, spec->am_entry[0].idx); | ||
632 | } | ||
633 | |||
634 | /* update the master volume per volume-knob's unsol event */ | 187 | /* update the master volume per volume-knob's unsol event */ |
635 | static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack) | 188 | static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack) |
636 | { | 189 | { |
@@ -780,298 +333,6 @@ static void alc_auto_init_amp(struct hda_codec *codec, int type) | |||
780 | } | 333 | } |
781 | } | 334 | } |
782 | 335 | ||
783 | /* | ||
784 | * Auto-Mute mode mixer enum support | ||
785 | */ | ||
786 | static int alc_automute_mode_info(struct snd_kcontrol *kcontrol, | ||
787 | struct snd_ctl_elem_info *uinfo) | ||
788 | { | ||
789 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
790 | struct alc_spec *spec = codec->spec; | ||
791 | static const char * const texts3[] = { | ||
792 | "Disabled", "Speaker Only", "Line Out+Speaker" | ||
793 | }; | ||
794 | |||
795 | if (spec->automute_speaker_possible && spec->automute_lo_possible) | ||
796 | return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3); | ||
797 | return snd_hda_enum_bool_helper_info(kcontrol, uinfo); | ||
798 | } | ||
799 | |||
800 | static int alc_automute_mode_get(struct snd_kcontrol *kcontrol, | ||
801 | struct snd_ctl_elem_value *ucontrol) | ||
802 | { | ||
803 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
804 | struct alc_spec *spec = codec->spec; | ||
805 | unsigned int val = 0; | ||
806 | if (spec->automute_speaker) | ||
807 | val++; | ||
808 | if (spec->automute_lo) | ||
809 | val++; | ||
810 | |||
811 | ucontrol->value.enumerated.item[0] = val; | ||
812 | return 0; | ||
813 | } | ||
814 | |||
815 | static int alc_automute_mode_put(struct snd_kcontrol *kcontrol, | ||
816 | struct snd_ctl_elem_value *ucontrol) | ||
817 | { | ||
818 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
819 | struct alc_spec *spec = codec->spec; | ||
820 | |||
821 | switch (ucontrol->value.enumerated.item[0]) { | ||
822 | case 0: | ||
823 | if (!spec->automute_speaker && !spec->automute_lo) | ||
824 | return 0; | ||
825 | spec->automute_speaker = 0; | ||
826 | spec->automute_lo = 0; | ||
827 | break; | ||
828 | case 1: | ||
829 | if (spec->automute_speaker_possible) { | ||
830 | if (!spec->automute_lo && spec->automute_speaker) | ||
831 | return 0; | ||
832 | spec->automute_speaker = 1; | ||
833 | spec->automute_lo = 0; | ||
834 | } else if (spec->automute_lo_possible) { | ||
835 | if (spec->automute_lo) | ||
836 | return 0; | ||
837 | spec->automute_lo = 1; | ||
838 | } else | ||
839 | return -EINVAL; | ||
840 | break; | ||
841 | case 2: | ||
842 | if (!spec->automute_lo_possible || !spec->automute_speaker_possible) | ||
843 | return -EINVAL; | ||
844 | if (spec->automute_speaker && spec->automute_lo) | ||
845 | return 0; | ||
846 | spec->automute_speaker = 1; | ||
847 | spec->automute_lo = 1; | ||
848 | break; | ||
849 | default: | ||
850 | return -EINVAL; | ||
851 | } | ||
852 | call_update_outputs(codec); | ||
853 | return 1; | ||
854 | } | ||
855 | |||
856 | static const struct snd_kcontrol_new alc_automute_mode_enum = { | ||
857 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
858 | .name = "Auto-Mute Mode", | ||
859 | .info = alc_automute_mode_info, | ||
860 | .get = alc_automute_mode_get, | ||
861 | .put = alc_automute_mode_put, | ||
862 | }; | ||
863 | |||
864 | static struct snd_kcontrol_new * | ||
865 | alc_kcontrol_new(struct alc_spec *spec, const char *name, | ||
866 | const struct snd_kcontrol_new *temp) | ||
867 | { | ||
868 | struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls); | ||
869 | if (!knew) | ||
870 | return NULL; | ||
871 | *knew = *temp; | ||
872 | if (name) | ||
873 | knew->name = kstrdup(name, GFP_KERNEL); | ||
874 | else if (knew->name) | ||
875 | knew->name = kstrdup(knew->name, GFP_KERNEL); | ||
876 | if (!knew->name) | ||
877 | return NULL; | ||
878 | return knew; | ||
879 | } | ||
880 | |||
881 | static int alc_add_automute_mode_enum(struct hda_codec *codec) | ||
882 | { | ||
883 | struct alc_spec *spec = codec->spec; | ||
884 | |||
885 | if (!alc_kcontrol_new(spec, NULL, &alc_automute_mode_enum)) | ||
886 | return -ENOMEM; | ||
887 | return 0; | ||
888 | } | ||
889 | |||
890 | /* | ||
891 | * Check the availability of HP/line-out auto-mute; | ||
892 | * Set up appropriately if really supported | ||
893 | */ | ||
894 | static int alc_init_automute(struct hda_codec *codec) | ||
895 | { | ||
896 | struct alc_spec *spec = codec->spec; | ||
897 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
898 | int present = 0; | ||
899 | int i, err; | ||
900 | |||
901 | if (cfg->hp_pins[0]) | ||
902 | present++; | ||
903 | if (cfg->line_out_pins[0]) | ||
904 | present++; | ||
905 | if (cfg->speaker_pins[0]) | ||
906 | present++; | ||
907 | if (present < 2) /* need two different output types */ | ||
908 | return 0; | ||
909 | |||
910 | if (!cfg->speaker_pins[0] && | ||
911 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { | ||
912 | memcpy(cfg->speaker_pins, cfg->line_out_pins, | ||
913 | sizeof(cfg->speaker_pins)); | ||
914 | cfg->speaker_outs = cfg->line_outs; | ||
915 | } | ||
916 | |||
917 | if (!cfg->hp_pins[0] && | ||
918 | cfg->line_out_type == AUTO_PIN_HP_OUT) { | ||
919 | memcpy(cfg->hp_pins, cfg->line_out_pins, | ||
920 | sizeof(cfg->hp_pins)); | ||
921 | cfg->hp_outs = cfg->line_outs; | ||
922 | } | ||
923 | |||
924 | for (i = 0; i < cfg->hp_outs; i++) { | ||
925 | hda_nid_t nid = cfg->hp_pins[i]; | ||
926 | if (!is_jack_detectable(codec, nid)) | ||
927 | continue; | ||
928 | snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n", | ||
929 | nid); | ||
930 | snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT, | ||
931 | alc_hp_automute); | ||
932 | spec->detect_hp = 1; | ||
933 | } | ||
934 | |||
935 | if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) { | ||
936 | if (cfg->speaker_outs) | ||
937 | for (i = 0; i < cfg->line_outs; i++) { | ||
938 | hda_nid_t nid = cfg->line_out_pins[i]; | ||
939 | if (!is_jack_detectable(codec, nid)) | ||
940 | continue; | ||
941 | snd_printdd("realtek: Enable Line-Out " | ||
942 | "auto-muting on NID 0x%x\n", nid); | ||
943 | snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT, | ||
944 | alc_line_automute); | ||
945 | spec->detect_lo = 1; | ||
946 | } | ||
947 | spec->automute_lo_possible = spec->detect_hp; | ||
948 | } | ||
949 | |||
950 | spec->automute_speaker_possible = cfg->speaker_outs && | ||
951 | (spec->detect_hp || spec->detect_lo); | ||
952 | |||
953 | spec->automute_lo = spec->automute_lo_possible; | ||
954 | spec->automute_speaker = spec->automute_speaker_possible; | ||
955 | |||
956 | if (spec->automute_speaker_possible || spec->automute_lo_possible) { | ||
957 | /* create a control for automute mode */ | ||
958 | err = alc_add_automute_mode_enum(codec); | ||
959 | if (err < 0) | ||
960 | return err; | ||
961 | } | ||
962 | return 0; | ||
963 | } | ||
964 | |||
965 | /* return the position of NID in the list, or -1 if not found */ | ||
966 | static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) | ||
967 | { | ||
968 | int i; | ||
969 | for (i = 0; i < nums; i++) | ||
970 | if (list[i] == nid) | ||
971 | return i; | ||
972 | return -1; | ||
973 | } | ||
974 | |||
975 | /* check whether all auto-mic pins are valid; setup indices if OK */ | ||
976 | static bool alc_auto_mic_check_imux(struct hda_codec *codec) | ||
977 | { | ||
978 | struct alc_spec *spec = codec->spec; | ||
979 | const struct hda_input_mux *imux; | ||
980 | int i; | ||
981 | |||
982 | imux = &spec->input_mux; | ||
983 | for (i = 0; i < spec->am_num_entries; i++) { | ||
984 | spec->am_entry[i].idx = | ||
985 | find_idx_in_nid_list(spec->am_entry[i].pin, | ||
986 | spec->imux_pins, imux->num_items); | ||
987 | if (spec->am_entry[i].idx < 0) | ||
988 | return false; /* no corresponding imux */ | ||
989 | } | ||
990 | |||
991 | /* we don't need the jack detection for the first pin */ | ||
992 | for (i = 1; i < spec->am_num_entries; i++) | ||
993 | snd_hda_jack_detect_enable_callback(codec, | ||
994 | spec->am_entry[i].pin, | ||
995 | ALC_MIC_EVENT, | ||
996 | alc_mic_automute); | ||
997 | return true; | ||
998 | } | ||
999 | |||
1000 | static int compare_attr(const void *ap, const void *bp) | ||
1001 | { | ||
1002 | const struct alc_automic_entry *a = ap; | ||
1003 | const struct alc_automic_entry *b = bp; | ||
1004 | return (int)(a->attr - b->attr); | ||
1005 | } | ||
1006 | |||
1007 | /* | ||
1008 | * Check the availability of auto-mic switch; | ||
1009 | * Set up if really supported | ||
1010 | */ | ||
1011 | static int alc_init_auto_mic(struct hda_codec *codec) | ||
1012 | { | ||
1013 | struct alc_spec *spec = codec->spec; | ||
1014 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
1015 | unsigned int types; | ||
1016 | int i, num_pins; | ||
1017 | |||
1018 | types = 0; | ||
1019 | num_pins = 0; | ||
1020 | for (i = 0; i < cfg->num_inputs; i++) { | ||
1021 | hda_nid_t nid = cfg->inputs[i].pin; | ||
1022 | unsigned int attr; | ||
1023 | attr = snd_hda_codec_get_pincfg(codec, nid); | ||
1024 | attr = snd_hda_get_input_pin_attr(attr); | ||
1025 | if (types & (1 << attr)) | ||
1026 | return 0; /* already occupied */ | ||
1027 | switch (attr) { | ||
1028 | case INPUT_PIN_ATTR_INT: | ||
1029 | if (cfg->inputs[i].type != AUTO_PIN_MIC) | ||
1030 | return 0; /* invalid type */ | ||
1031 | break; | ||
1032 | case INPUT_PIN_ATTR_UNUSED: | ||
1033 | return 0; /* invalid entry */ | ||
1034 | default: | ||
1035 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) | ||
1036 | return 0; /* invalid type */ | ||
1037 | if (!spec->line_in_auto_switch && | ||
1038 | cfg->inputs[i].type != AUTO_PIN_MIC) | ||
1039 | return 0; /* only mic is allowed */ | ||
1040 | if (!is_jack_detectable(codec, nid)) | ||
1041 | return 0; /* no unsol support */ | ||
1042 | break; | ||
1043 | } | ||
1044 | if (num_pins >= MAX_AUTO_MIC_PINS) | ||
1045 | return 0; | ||
1046 | types |= (1 << attr); | ||
1047 | spec->am_entry[num_pins].pin = nid; | ||
1048 | spec->am_entry[num_pins].attr = attr; | ||
1049 | num_pins++; | ||
1050 | } | ||
1051 | |||
1052 | if (num_pins < 2) | ||
1053 | return 0; | ||
1054 | |||
1055 | spec->am_num_entries = num_pins; | ||
1056 | /* sort the am_entry in the order of attr so that the pin with a | ||
1057 | * higher attr will be selected when the jack is plugged. | ||
1058 | */ | ||
1059 | sort(spec->am_entry, num_pins, sizeof(spec->am_entry[0]), | ||
1060 | compare_attr, NULL); | ||
1061 | |||
1062 | if (!alc_auto_mic_check_imux(codec)) | ||
1063 | return 0; | ||
1064 | |||
1065 | spec->auto_mic = 1; | ||
1066 | spec->num_adc_nids = 1; | ||
1067 | spec->cur_mux[0] = spec->am_entry[0].idx; | ||
1068 | snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n", | ||
1069 | spec->am_entry[0].pin, | ||
1070 | spec->am_entry[1].pin, | ||
1071 | spec->am_entry[2].pin); | ||
1072 | |||
1073 | return 0; | ||
1074 | } | ||
1075 | 336 | ||
1076 | /* | 337 | /* |
1077 | * Realtek SSID verification | 338 | * Realtek SSID verification |
@@ -1157,6 +418,15 @@ do_sku: | |||
1157 | return 0; | 418 | return 0; |
1158 | } | 419 | } |
1159 | 420 | ||
421 | /* return the position of NID in the list, or -1 if not found */ | ||
422 | static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) | ||
423 | { | ||
424 | int i; | ||
425 | for (i = 0; i < nums; i++) | ||
426 | if (list[i] == nid) | ||
427 | return i; | ||
428 | return -1; | ||
429 | } | ||
1160 | /* return true if the given NID is found in the list */ | 430 | /* return true if the given NID is found in the list */ |
1161 | static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) | 431 | static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
1162 | { | 432 | { |
@@ -1259,9 +529,9 @@ do_sku: | |||
1259 | * 15 : 1 --> enable the function "Mute internal speaker | 529 | * 15 : 1 --> enable the function "Mute internal speaker |
1260 | * when the external headphone out jack is plugged" | 530 | * when the external headphone out jack is plugged" |
1261 | */ | 531 | */ |
1262 | if (!spec->autocfg.hp_pins[0] && | 532 | if (!spec->gen.autocfg.hp_pins[0] && |
1263 | !(spec->autocfg.line_out_pins[0] && | 533 | !(spec->gen.autocfg.line_out_pins[0] && |
1264 | spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) { | 534 | spec->gen.autocfg.line_out_type == AUTO_PIN_HP_OUT)) { |
1265 | hda_nid_t nid; | 535 | hda_nid_t nid; |
1266 | tmp = (ass >> 11) & 0x3; /* HP to chassis */ | 536 | tmp = (ass >> 11) & 0x3; /* HP to chassis */ |
1267 | if (tmp == 0) | 537 | if (tmp == 0) |
@@ -1274,10 +544,10 @@ do_sku: | |||
1274 | nid = porti; | 544 | nid = porti; |
1275 | else | 545 | else |
1276 | return 1; | 546 | return 1; |
1277 | if (found_in_nid_list(nid, spec->autocfg.line_out_pins, | 547 | if (found_in_nid_list(nid, spec->gen.autocfg.line_out_pins, |
1278 | spec->autocfg.line_outs)) | 548 | spec->gen.autocfg.line_outs)) |
1279 | return 1; | 549 | return 1; |
1280 | spec->autocfg.hp_pins[0] = nid; | 550 | spec->gen.autocfg.hp_pins[0] = nid; |
1281 | } | 551 | } |
1282 | return 1; | 552 | return 1; |
1283 | } | 553 | } |
@@ -1326,170 +596,35 @@ static unsigned int alc_get_coef0(struct hda_codec *codec) | |||
1326 | return spec->coef0; | 596 | return spec->coef0; |
1327 | } | 597 | } |
1328 | 598 | ||
1329 | static void alc_auto_set_output_and_unmute(struct hda_codec *codec, | ||
1330 | hda_nid_t pin, int pin_type, | ||
1331 | hda_nid_t dac); | ||
1332 | static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin, | ||
1333 | bool is_digital); | ||
1334 | static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid, | ||
1335 | hda_nid_t to_nid, int with_aa_mix, | ||
1336 | struct nid_path *path); | ||
1337 | static struct nid_path *add_new_nid_path(struct hda_codec *codec, | ||
1338 | hda_nid_t from_nid, hda_nid_t to_nid, | ||
1339 | int with_aa_mix); | ||
1340 | |||
1341 | /* | 599 | /* |
1342 | * Digital I/O handling | ||
1343 | */ | 600 | */ |
1344 | 601 | ||
1345 | /* set right pin controls for digital I/O */ | 602 | static hda_nid_t get_adc_nid(struct hda_codec *codec, int adc_idx, int imux_idx) |
1346 | static void alc_auto_init_digital(struct hda_codec *codec) | ||
1347 | { | ||
1348 | struct alc_spec *spec = codec->spec; | ||
1349 | int i; | ||
1350 | hda_nid_t pin; | ||
1351 | |||
1352 | for (i = 0; i < spec->autocfg.dig_outs; i++) { | ||
1353 | pin = spec->autocfg.dig_out_pins[i]; | ||
1354 | if (!pin) | ||
1355 | continue; | ||
1356 | alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0); | ||
1357 | } | ||
1358 | pin = spec->autocfg.dig_in_pin; | ||
1359 | if (pin) | ||
1360 | snd_hda_set_pin_ctl(codec, pin, PIN_IN); | ||
1361 | } | ||
1362 | |||
1363 | /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */ | ||
1364 | static void alc_auto_parse_digital(struct hda_codec *codec) | ||
1365 | { | ||
1366 | struct alc_spec *spec = codec->spec; | ||
1367 | int i, nums; | ||
1368 | hda_nid_t dig_nid; | ||
1369 | |||
1370 | /* support multiple SPDIFs; the secondary is set up as a slave */ | ||
1371 | nums = 0; | ||
1372 | for (i = 0; i < spec->autocfg.dig_outs; i++) { | ||
1373 | hda_nid_t pin = spec->autocfg.dig_out_pins[i]; | ||
1374 | dig_nid = alc_auto_look_for_dac(codec, pin, true); | ||
1375 | if (!dig_nid) | ||
1376 | continue; | ||
1377 | if (!add_new_nid_path(codec, dig_nid, pin, 2)) | ||
1378 | continue; | ||
1379 | if (!nums) { | ||
1380 | spec->multiout.dig_out_nid = dig_nid; | ||
1381 | spec->dig_out_type = spec->autocfg.dig_out_type[0]; | ||
1382 | } else { | ||
1383 | spec->multiout.slave_dig_outs = spec->slave_dig_outs; | ||
1384 | if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1) | ||
1385 | break; | ||
1386 | spec->slave_dig_outs[nums - 1] = dig_nid; | ||
1387 | } | ||
1388 | nums++; | ||
1389 | } | ||
1390 | |||
1391 | if (spec->autocfg.dig_in_pin) { | ||
1392 | dig_nid = codec->start_nid; | ||
1393 | for (i = 0; i < codec->num_nodes; i++, dig_nid++) { | ||
1394 | struct nid_path *path; | ||
1395 | unsigned int wcaps = get_wcaps(codec, dig_nid); | ||
1396 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) | ||
1397 | continue; | ||
1398 | if (!(wcaps & AC_WCAP_DIGITAL)) | ||
1399 | continue; | ||
1400 | path = add_new_nid_path(codec, spec->autocfg.dig_in_pin, | ||
1401 | dig_nid, 2); | ||
1402 | if (path) { | ||
1403 | path->active = true; | ||
1404 | spec->dig_in_nid = dig_nid; | ||
1405 | break; | ||
1406 | } | ||
1407 | } | ||
1408 | } | ||
1409 | } | ||
1410 | |||
1411 | /* | ||
1412 | * capture mixer elements | ||
1413 | */ | ||
1414 | #define alc_cap_vol_info snd_hda_mixer_amp_volume_info | ||
1415 | #define alc_cap_vol_get snd_hda_mixer_amp_volume_get | ||
1416 | #define alc_cap_vol_tlv snd_hda_mixer_amp_tlv | ||
1417 | |||
1418 | typedef int (*put_call_t)(struct snd_kcontrol *kcontrol, | ||
1419 | struct snd_ctl_elem_value *ucontrol); | ||
1420 | |||
1421 | static int alc_cap_put_caller(struct snd_kcontrol *kcontrol, | ||
1422 | struct snd_ctl_elem_value *ucontrol, | ||
1423 | put_call_t func, int type) | ||
1424 | { | ||
1425 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
1426 | struct alc_spec *spec = codec->spec; | ||
1427 | const struct hda_input_mux *imux; | ||
1428 | struct nid_path *path; | ||
1429 | int i, adc_idx, err = 0; | ||
1430 | |||
1431 | imux = &spec->input_mux; | ||
1432 | adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | ||
1433 | mutex_lock(&codec->control_mutex); | ||
1434 | codec->cached_write = 1; | ||
1435 | for (i = 0; i < imux->num_items; i++) { | ||
1436 | path = get_nid_path(codec, spec->imux_pins[i], | ||
1437 | get_adc_nid(codec, adc_idx, i)); | ||
1438 | if (!path->ctls[type]) | ||
1439 | continue; | ||
1440 | kcontrol->private_value = path->ctls[type]; | ||
1441 | err = func(kcontrol, ucontrol); | ||
1442 | if (err < 0) | ||
1443 | goto error; | ||
1444 | } | ||
1445 | error: | ||
1446 | codec->cached_write = 0; | ||
1447 | mutex_unlock(&codec->control_mutex); | ||
1448 | snd_hda_codec_resume_amp(codec); | ||
1449 | if (err >= 0 && type == NID_PATH_MUTE_CTL && | ||
1450 | spec->inv_dmic_fixup && spec->inv_dmic_muted) | ||
1451 | alc_inv_dmic_sync_adc(codec, adc_idx); | ||
1452 | return err; | ||
1453 | } | ||
1454 | |||
1455 | static int alc_cap_vol_put(struct snd_kcontrol *kcontrol, | ||
1456 | struct snd_ctl_elem_value *ucontrol) | ||
1457 | { | ||
1458 | return alc_cap_put_caller(kcontrol, ucontrol, | ||
1459 | snd_hda_mixer_amp_volume_put, | ||
1460 | NID_PATH_VOL_CTL); | ||
1461 | } | ||
1462 | |||
1463 | /* capture mixer elements */ | ||
1464 | #define alc_cap_sw_info snd_ctl_boolean_stereo_info | ||
1465 | #define alc_cap_sw_get snd_hda_mixer_amp_switch_get | ||
1466 | |||
1467 | static int alc_cap_sw_put(struct snd_kcontrol *kcontrol, | ||
1468 | struct snd_ctl_elem_value *ucontrol) | ||
1469 | { | 603 | { |
1470 | return alc_cap_put_caller(kcontrol, ucontrol, | 604 | struct hda_gen_spec *spec = codec->spec; |
1471 | snd_hda_mixer_amp_switch_put, | 605 | if (spec->dyn_adc_switch) |
1472 | NID_PATH_MUTE_CTL); | 606 | adc_idx = spec->dyn_adc_idx[imux_idx]; |
607 | return spec->adc_nids[adc_idx]; | ||
1473 | } | 608 | } |
1474 | 609 | ||
1475 | static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx) | 610 | static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx) |
1476 | { | 611 | { |
1477 | struct alc_spec *spec = codec->spec; | 612 | struct alc_spec *spec = codec->spec; |
1478 | struct hda_input_mux *imux = &spec->input_mux; | 613 | struct hda_input_mux *imux = &spec->gen.input_mux; |
1479 | struct nid_path *path; | 614 | struct nid_path *path; |
1480 | hda_nid_t nid; | 615 | hda_nid_t nid; |
1481 | int i, dir, parm; | 616 | int i, dir, parm; |
1482 | unsigned int val; | 617 | unsigned int val; |
1483 | 618 | ||
1484 | for (i = 0; i < imux->num_items; i++) { | 619 | for (i = 0; i < imux->num_items; i++) { |
1485 | if (spec->imux_pins[i] == spec->inv_dmic_pin) | 620 | if (spec->gen.imux_pins[i] == spec->inv_dmic_pin) |
1486 | break; | 621 | break; |
1487 | } | 622 | } |
1488 | if (i >= imux->num_items) | 623 | if (i >= imux->num_items) |
1489 | return; | 624 | return; |
1490 | 625 | ||
1491 | path = get_nid_path(codec, spec->inv_dmic_pin, | 626 | path = snd_hda_get_nid_path(codec, spec->inv_dmic_pin, |
1492 | get_adc_nid(codec, adc_idx, i)); | 627 | get_adc_nid(codec, adc_idx, i)); |
1493 | val = path->ctls[NID_PATH_MUTE_CTL]; | 628 | val = path->ctls[NID_PATH_MUTE_CTL]; |
1494 | if (!val) | 629 | if (!val) |
1495 | return; | 630 | return; |
@@ -1531,12 +666,12 @@ static void alc_inv_dmic_sync(struct hda_codec *codec, bool force) | |||
1531 | return; | 666 | return; |
1532 | if (!spec->inv_dmic_muted && !force) | 667 | if (!spec->inv_dmic_muted && !force) |
1533 | return; | 668 | return; |
1534 | nums = spec->dyn_adc_switch ? 1 : spec->num_adc_nids; | 669 | nums = spec->gen.dyn_adc_switch ? 1 : spec->gen.num_adc_nids; |
1535 | for (src = 0; src < nums; src++) { | 670 | for (src = 0; src < nums; src++) { |
1536 | bool dmic_fixup = false; | 671 | bool dmic_fixup = false; |
1537 | 672 | ||
1538 | if (spec->inv_dmic_muted && | 673 | if (spec->inv_dmic_muted && |
1539 | spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin) | 674 | spec->gen.imux_pins[spec->gen.cur_mux[src]] == spec->inv_dmic_pin) |
1540 | dmic_fixup = true; | 675 | dmic_fixup = true; |
1541 | if (!dmic_fixup && !force) | 676 | if (!dmic_fixup && !force) |
1542 | continue; | 677 | continue; |
@@ -1544,6 +679,11 @@ static void alc_inv_dmic_sync(struct hda_codec *codec, bool force) | |||
1544 | } | 679 | } |
1545 | } | 680 | } |
1546 | 681 | ||
682 | static void alc_inv_dmic_hook(struct hda_codec *codec) | ||
683 | { | ||
684 | alc_inv_dmic_sync(codec, false); | ||
685 | } | ||
686 | |||
1547 | static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol, | 687 | static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol, |
1548 | struct snd_ctl_elem_value *ucontrol) | 688 | struct snd_ctl_elem_value *ucontrol) |
1549 | { | 689 | { |
@@ -1580,11 +720,12 @@ static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid) | |||
1580 | { | 720 | { |
1581 | struct alc_spec *spec = codec->spec; | 721 | struct alc_spec *spec = codec->spec; |
1582 | 722 | ||
1583 | if (!alc_kcontrol_new(spec, NULL, &alc_inv_dmic_sw)) | 723 | if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &alc_inv_dmic_sw)) |
1584 | return -ENOMEM; | 724 | return -ENOMEM; |
1585 | spec->inv_dmic_fixup = 1; | 725 | spec->inv_dmic_fixup = 1; |
1586 | spec->inv_dmic_muted = 0; | 726 | spec->inv_dmic_muted = 0; |
1587 | spec->inv_dmic_pin = nid; | 727 | spec->inv_dmic_pin = nid; |
728 | spec->gen.cap_sync_hook = alc_inv_dmic_hook; | ||
1588 | return 0; | 729 | return 0; |
1589 | } | 730 | } |
1590 | 731 | ||
@@ -1596,25 +737,6 @@ static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec, | |||
1596 | alc_add_inv_dmic_mixer(codec, 0x12); | 737 | alc_add_inv_dmic_mixer(codec, 0x12); |
1597 | } | 738 | } |
1598 | 739 | ||
1599 | /* | ||
1600 | * virtual master controls | ||
1601 | */ | ||
1602 | |||
1603 | /* | ||
1604 | * slave controls for virtual master | ||
1605 | */ | ||
1606 | static const char * const alc_slave_pfxs[] = { | ||
1607 | "Front", "Surround", "Center", "LFE", "Side", | ||
1608 | "Headphone", "Speaker", "Mono", "Line Out", | ||
1609 | "CLFE", "Bass Speaker", "PCM", | ||
1610 | NULL, | ||
1611 | }; | ||
1612 | |||
1613 | /* | ||
1614 | * build control elements | ||
1615 | */ | ||
1616 | |||
1617 | static void alc_free_kctls(struct hda_codec *codec); | ||
1618 | 740 | ||
1619 | #ifdef CONFIG_SND_HDA_INPUT_BEEP | 741 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
1620 | /* additional beep mixers; the actual parameters are overwritten at build */ | 742 | /* additional beep mixers; the actual parameters are overwritten at build */ |
@@ -1630,31 +752,15 @@ static int alc_build_controls(struct hda_codec *codec) | |||
1630 | struct alc_spec *spec = codec->spec; | 752 | struct alc_spec *spec = codec->spec; |
1631 | int i, err; | 753 | int i, err; |
1632 | 754 | ||
755 | err = snd_hda_gen_build_controls(codec); | ||
756 | if (err < 0) | ||
757 | return err; | ||
758 | |||
1633 | for (i = 0; i < spec->num_mixers; i++) { | 759 | for (i = 0; i < spec->num_mixers; i++) { |
1634 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | 760 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
1635 | if (err < 0) | 761 | if (err < 0) |
1636 | return err; | 762 | return err; |
1637 | } | 763 | } |
1638 | if (spec->multiout.dig_out_nid) { | ||
1639 | err = snd_hda_create_dig_out_ctls(codec, | ||
1640 | spec->multiout.dig_out_nid, | ||
1641 | spec->multiout.dig_out_nid, | ||
1642 | spec->pcm_rec[1].pcm_type); | ||
1643 | if (err < 0) | ||
1644 | return err; | ||
1645 | if (!spec->no_analog) { | ||
1646 | err = snd_hda_create_spdif_share_sw(codec, | ||
1647 | &spec->multiout); | ||
1648 | if (err < 0) | ||
1649 | return err; | ||
1650 | spec->multiout.share_spdif = 1; | ||
1651 | } | ||
1652 | } | ||
1653 | if (spec->dig_in_nid) { | ||
1654 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); | ||
1655 | if (err < 0) | ||
1656 | return err; | ||
1657 | } | ||
1658 | 764 | ||
1659 | #ifdef CONFIG_SND_HDA_INPUT_BEEP | 765 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
1660 | /* create beep controls if needed */ | 766 | /* create beep controls if needed */ |
@@ -1673,47 +779,6 @@ static int alc_build_controls(struct hda_codec *codec) | |||
1673 | } | 779 | } |
1674 | #endif | 780 | #endif |
1675 | 781 | ||
1676 | /* if we have no master control, let's create it */ | ||
1677 | if (!spec->no_analog && | ||
1678 | !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { | ||
1679 | unsigned int vmaster_tlv[4]; | ||
1680 | snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, | ||
1681 | HDA_OUTPUT, vmaster_tlv); | ||
1682 | err = snd_hda_add_vmaster(codec, "Master Playback Volume", | ||
1683 | vmaster_tlv, alc_slave_pfxs, | ||
1684 | "Playback Volume"); | ||
1685 | if (err < 0) | ||
1686 | return err; | ||
1687 | } | ||
1688 | if (!spec->no_analog && | ||
1689 | !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { | ||
1690 | err = __snd_hda_add_vmaster(codec, "Master Playback Switch", | ||
1691 | NULL, alc_slave_pfxs, | ||
1692 | "Playback Switch", | ||
1693 | true, &spec->vmaster_mute.sw_kctl); | ||
1694 | if (err < 0) | ||
1695 | return err; | ||
1696 | if (spec->vmaster_mute.hook) | ||
1697 | snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true); | ||
1698 | } | ||
1699 | |||
1700 | alc_free_kctls(codec); /* no longer needed */ | ||
1701 | |||
1702 | if (spec->shared_mic_hp) { | ||
1703 | int err; | ||
1704 | int nid = spec->autocfg.inputs[1].pin; | ||
1705 | err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0); | ||
1706 | if (err < 0) | ||
1707 | return err; | ||
1708 | err = snd_hda_jack_detect_enable(codec, nid, 0); | ||
1709 | if (err < 0) | ||
1710 | return err; | ||
1711 | } | ||
1712 | |||
1713 | err = snd_hda_jack_add_kctls(codec, &spec->autocfg); | ||
1714 | if (err < 0) | ||
1715 | return err; | ||
1716 | |||
1717 | alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD); | 782 | alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD); |
1718 | return 0; | 783 | return 0; |
1719 | } | 784 | } |
@@ -1723,8 +788,6 @@ static int alc_build_controls(struct hda_codec *codec) | |||
1723 | * Common callbacks | 788 | * Common callbacks |
1724 | */ | 789 | */ |
1725 | 790 | ||
1726 | static void alc_auto_init_std(struct hda_codec *codec); | ||
1727 | |||
1728 | static int alc_init(struct hda_codec *codec) | 791 | static int alc_init(struct hda_codec *codec) |
1729 | { | 792 | { |
1730 | struct alc_spec *spec = codec->spec; | 793 | struct alc_spec *spec = codec->spec; |
@@ -1735,15 +798,10 @@ static int alc_init(struct hda_codec *codec) | |||
1735 | alc_fix_pll(codec); | 798 | alc_fix_pll(codec); |
1736 | alc_auto_init_amp(codec, spec->init_amp); | 799 | alc_auto_init_amp(codec, spec->init_amp); |
1737 | 800 | ||
1738 | snd_hda_apply_verbs(codec); | 801 | snd_hda_gen_init(codec); |
1739 | alc_auto_init_std(codec); | ||
1740 | |||
1741 | if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook) | ||
1742 | snd_hda_sync_vmaster_hook(&spec->vmaster_mute); | ||
1743 | 802 | ||
1744 | alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT); | 803 | alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT); |
1745 | 804 | ||
1746 | hda_call_check_power_status(codec, 0x01); | ||
1747 | return 0; | 805 | return 0; |
1748 | } | 806 | } |
1749 | 807 | ||
@@ -1751,336 +809,10 @@ static int alc_init(struct hda_codec *codec) | |||
1751 | static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid) | 809 | static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
1752 | { | 810 | { |
1753 | struct alc_spec *spec = codec->spec; | 811 | struct alc_spec *spec = codec->spec; |
1754 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); | 812 | return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid); |
1755 | } | 813 | } |
1756 | #endif | 814 | #endif |
1757 | 815 | ||
1758 | /* | ||
1759 | * Analog playback callbacks | ||
1760 | */ | ||
1761 | static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo, | ||
1762 | struct hda_codec *codec, | ||
1763 | struct snd_pcm_substream *substream) | ||
1764 | { | ||
1765 | struct alc_spec *spec = codec->spec; | ||
1766 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, | ||
1767 | hinfo); | ||
1768 | } | ||
1769 | |||
1770 | static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | ||
1771 | struct hda_codec *codec, | ||
1772 | unsigned int stream_tag, | ||
1773 | unsigned int format, | ||
1774 | struct snd_pcm_substream *substream) | ||
1775 | { | ||
1776 | struct alc_spec *spec = codec->spec; | ||
1777 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, | ||
1778 | stream_tag, format, substream); | ||
1779 | } | ||
1780 | |||
1781 | static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | ||
1782 | struct hda_codec *codec, | ||
1783 | struct snd_pcm_substream *substream) | ||
1784 | { | ||
1785 | struct alc_spec *spec = codec->spec; | ||
1786 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | ||
1787 | } | ||
1788 | |||
1789 | /* | ||
1790 | * Digital out | ||
1791 | */ | ||
1792 | static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | ||
1793 | struct hda_codec *codec, | ||
1794 | struct snd_pcm_substream *substream) | ||
1795 | { | ||
1796 | struct alc_spec *spec = codec->spec; | ||
1797 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | ||
1798 | } | ||
1799 | |||
1800 | static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | ||
1801 | struct hda_codec *codec, | ||
1802 | unsigned int stream_tag, | ||
1803 | unsigned int format, | ||
1804 | struct snd_pcm_substream *substream) | ||
1805 | { | ||
1806 | struct alc_spec *spec = codec->spec; | ||
1807 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, | ||
1808 | stream_tag, format, substream); | ||
1809 | } | ||
1810 | |||
1811 | static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | ||
1812 | struct hda_codec *codec, | ||
1813 | struct snd_pcm_substream *substream) | ||
1814 | { | ||
1815 | struct alc_spec *spec = codec->spec; | ||
1816 | return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); | ||
1817 | } | ||
1818 | |||
1819 | static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, | ||
1820 | struct hda_codec *codec, | ||
1821 | struct snd_pcm_substream *substream) | ||
1822 | { | ||
1823 | struct alc_spec *spec = codec->spec; | ||
1824 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | ||
1825 | } | ||
1826 | |||
1827 | /* | ||
1828 | * Analog capture | ||
1829 | */ | ||
1830 | static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | ||
1831 | struct hda_codec *codec, | ||
1832 | unsigned int stream_tag, | ||
1833 | unsigned int format, | ||
1834 | struct snd_pcm_substream *substream) | ||
1835 | { | ||
1836 | struct alc_spec *spec = codec->spec; | ||
1837 | |||
1838 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1], | ||
1839 | stream_tag, 0, format); | ||
1840 | return 0; | ||
1841 | } | ||
1842 | |||
1843 | static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | ||
1844 | struct hda_codec *codec, | ||
1845 | struct snd_pcm_substream *substream) | ||
1846 | { | ||
1847 | struct alc_spec *spec = codec->spec; | ||
1848 | |||
1849 | snd_hda_codec_cleanup_stream(codec, | ||
1850 | spec->adc_nids[substream->number + 1]); | ||
1851 | return 0; | ||
1852 | } | ||
1853 | |||
1854 | /* analog capture with dynamic dual-adc changes */ | ||
1855 | static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | ||
1856 | struct hda_codec *codec, | ||
1857 | unsigned int stream_tag, | ||
1858 | unsigned int format, | ||
1859 | struct snd_pcm_substream *substream) | ||
1860 | { | ||
1861 | struct alc_spec *spec = codec->spec; | ||
1862 | spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]]; | ||
1863 | spec->cur_adc_stream_tag = stream_tag; | ||
1864 | spec->cur_adc_format = format; | ||
1865 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); | ||
1866 | return 0; | ||
1867 | } | ||
1868 | |||
1869 | static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | ||
1870 | struct hda_codec *codec, | ||
1871 | struct snd_pcm_substream *substream) | ||
1872 | { | ||
1873 | struct alc_spec *spec = codec->spec; | ||
1874 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); | ||
1875 | spec->cur_adc = 0; | ||
1876 | return 0; | ||
1877 | } | ||
1878 | |||
1879 | static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = { | ||
1880 | .substreams = 1, | ||
1881 | .channels_min = 2, | ||
1882 | .channels_max = 2, | ||
1883 | .nid = 0, /* fill later */ | ||
1884 | .ops = { | ||
1885 | .prepare = dyn_adc_capture_pcm_prepare, | ||
1886 | .cleanup = dyn_adc_capture_pcm_cleanup | ||
1887 | }, | ||
1888 | }; | ||
1889 | |||
1890 | /* | ||
1891 | */ | ||
1892 | static const struct hda_pcm_stream alc_pcm_analog_playback = { | ||
1893 | .substreams = 1, | ||
1894 | .channels_min = 2, | ||
1895 | .channels_max = 8, | ||
1896 | /* NID is set in alc_build_pcms */ | ||
1897 | .ops = { | ||
1898 | .open = alc_playback_pcm_open, | ||
1899 | .prepare = alc_playback_pcm_prepare, | ||
1900 | .cleanup = alc_playback_pcm_cleanup | ||
1901 | }, | ||
1902 | }; | ||
1903 | |||
1904 | static const struct hda_pcm_stream alc_pcm_analog_capture = { | ||
1905 | .substreams = 1, | ||
1906 | .channels_min = 2, | ||
1907 | .channels_max = 2, | ||
1908 | /* NID is set in alc_build_pcms */ | ||
1909 | }; | ||
1910 | |||
1911 | static const struct hda_pcm_stream alc_pcm_analog_alt_playback = { | ||
1912 | .substreams = 1, | ||
1913 | .channels_min = 2, | ||
1914 | .channels_max = 2, | ||
1915 | /* NID is set in alc_build_pcms */ | ||
1916 | }; | ||
1917 | |||
1918 | static const struct hda_pcm_stream alc_pcm_analog_alt_capture = { | ||
1919 | .substreams = 2, /* can be overridden */ | ||
1920 | .channels_min = 2, | ||
1921 | .channels_max = 2, | ||
1922 | /* NID is set in alc_build_pcms */ | ||
1923 | .ops = { | ||
1924 | .prepare = alc_alt_capture_pcm_prepare, | ||
1925 | .cleanup = alc_alt_capture_pcm_cleanup | ||
1926 | }, | ||
1927 | }; | ||
1928 | |||
1929 | static const struct hda_pcm_stream alc_pcm_digital_playback = { | ||
1930 | .substreams = 1, | ||
1931 | .channels_min = 2, | ||
1932 | .channels_max = 2, | ||
1933 | /* NID is set in alc_build_pcms */ | ||
1934 | .ops = { | ||
1935 | .open = alc_dig_playback_pcm_open, | ||
1936 | .close = alc_dig_playback_pcm_close, | ||
1937 | .prepare = alc_dig_playback_pcm_prepare, | ||
1938 | .cleanup = alc_dig_playback_pcm_cleanup | ||
1939 | }, | ||
1940 | }; | ||
1941 | |||
1942 | static const struct hda_pcm_stream alc_pcm_digital_capture = { | ||
1943 | .substreams = 1, | ||
1944 | .channels_min = 2, | ||
1945 | .channels_max = 2, | ||
1946 | /* NID is set in alc_build_pcms */ | ||
1947 | }; | ||
1948 | |||
1949 | /* Used by alc_build_pcms to flag that a PCM has no playback stream */ | ||
1950 | static const struct hda_pcm_stream alc_pcm_null_stream = { | ||
1951 | .substreams = 0, | ||
1952 | .channels_min = 0, | ||
1953 | .channels_max = 0, | ||
1954 | }; | ||
1955 | |||
1956 | static int alc_build_pcms(struct hda_codec *codec) | ||
1957 | { | ||
1958 | struct alc_spec *spec = codec->spec; | ||
1959 | struct hda_pcm *info = spec->pcm_rec; | ||
1960 | const struct hda_pcm_stream *p; | ||
1961 | bool have_multi_adcs; | ||
1962 | int i; | ||
1963 | |||
1964 | codec->num_pcms = 1; | ||
1965 | codec->pcm_info = info; | ||
1966 | |||
1967 | if (spec->no_analog) | ||
1968 | goto skip_analog; | ||
1969 | |||
1970 | snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), | ||
1971 | "%s Analog", codec->chip_name); | ||
1972 | info->name = spec->stream_name_analog; | ||
1973 | |||
1974 | if (spec->multiout.num_dacs > 0) { | ||
1975 | p = spec->stream_analog_playback; | ||
1976 | if (!p) | ||
1977 | p = &alc_pcm_analog_playback; | ||
1978 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | ||
1979 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; | ||
1980 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = | ||
1981 | spec->multiout.max_channels; | ||
1982 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT && | ||
1983 | spec->autocfg.line_outs == 2) | ||
1984 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap = | ||
1985 | snd_pcm_2_1_chmaps; | ||
1986 | } | ||
1987 | if (spec->num_adc_nids) { | ||
1988 | p = spec->stream_analog_capture; | ||
1989 | if (!p) { | ||
1990 | if (spec->dyn_adc_switch) | ||
1991 | p = &dyn_adc_pcm_analog_capture; | ||
1992 | else | ||
1993 | p = &alc_pcm_analog_capture; | ||
1994 | } | ||
1995 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; | ||
1996 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; | ||
1997 | } | ||
1998 | |||
1999 | if (spec->channel_mode) { | ||
2000 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0; | ||
2001 | for (i = 0; i < spec->num_channel_mode; i++) { | ||
2002 | if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) { | ||
2003 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels; | ||
2004 | } | ||
2005 | } | ||
2006 | } | ||
2007 | |||
2008 | skip_analog: | ||
2009 | /* SPDIF for stream index #1 */ | ||
2010 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { | ||
2011 | snprintf(spec->stream_name_digital, | ||
2012 | sizeof(spec->stream_name_digital), | ||
2013 | "%s Digital", codec->chip_name); | ||
2014 | codec->num_pcms = 2; | ||
2015 | codec->slave_dig_outs = spec->multiout.slave_dig_outs; | ||
2016 | info = spec->pcm_rec + 1; | ||
2017 | info->name = spec->stream_name_digital; | ||
2018 | if (spec->dig_out_type) | ||
2019 | info->pcm_type = spec->dig_out_type; | ||
2020 | else | ||
2021 | info->pcm_type = HDA_PCM_TYPE_SPDIF; | ||
2022 | if (spec->multiout.dig_out_nid) { | ||
2023 | p = spec->stream_digital_playback; | ||
2024 | if (!p) | ||
2025 | p = &alc_pcm_digital_playback; | ||
2026 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | ||
2027 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; | ||
2028 | } | ||
2029 | if (spec->dig_in_nid) { | ||
2030 | p = spec->stream_digital_capture; | ||
2031 | if (!p) | ||
2032 | p = &alc_pcm_digital_capture; | ||
2033 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; | ||
2034 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; | ||
2035 | } | ||
2036 | /* FIXME: do we need this for all Realtek codec models? */ | ||
2037 | codec->spdif_status_reset = 1; | ||
2038 | } | ||
2039 | |||
2040 | if (spec->no_analog) | ||
2041 | return 0; | ||
2042 | |||
2043 | /* If the use of more than one ADC is requested for the current | ||
2044 | * model, configure a second analog capture-only PCM. | ||
2045 | */ | ||
2046 | have_multi_adcs = (spec->num_adc_nids > 1) && | ||
2047 | !spec->dyn_adc_switch && !spec->auto_mic; | ||
2048 | /* Additional Analaog capture for index #2 */ | ||
2049 | if (spec->alt_dac_nid || have_multi_adcs) { | ||
2050 | codec->num_pcms = 3; | ||
2051 | info = spec->pcm_rec + 2; | ||
2052 | info->name = spec->stream_name_analog; | ||
2053 | if (spec->alt_dac_nid) { | ||
2054 | p = spec->stream_analog_alt_playback; | ||
2055 | if (!p) | ||
2056 | p = &alc_pcm_analog_alt_playback; | ||
2057 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; | ||
2058 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | ||
2059 | spec->alt_dac_nid; | ||
2060 | } else { | ||
2061 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = | ||
2062 | alc_pcm_null_stream; | ||
2063 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0; | ||
2064 | } | ||
2065 | if (have_multi_adcs) { | ||
2066 | p = spec->stream_analog_alt_capture; | ||
2067 | if (!p) | ||
2068 | p = &alc_pcm_analog_alt_capture; | ||
2069 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; | ||
2070 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = | ||
2071 | spec->adc_nids[1]; | ||
2072 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = | ||
2073 | spec->num_adc_nids - 1; | ||
2074 | } else { | ||
2075 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | ||
2076 | alc_pcm_null_stream; | ||
2077 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0; | ||
2078 | } | ||
2079 | } | ||
2080 | |||
2081 | return 0; | ||
2082 | } | ||
2083 | |||
2084 | static inline void alc_shutup(struct hda_codec *codec) | 816 | static inline void alc_shutup(struct hda_codec *codec) |
2085 | { | 817 | { |
2086 | struct alc_spec *spec = codec->spec; | 818 | struct alc_spec *spec = codec->spec; |
@@ -2090,31 +822,6 @@ static inline void alc_shutup(struct hda_codec *codec) | |||
2090 | snd_hda_shutup_pins(codec); | 822 | snd_hda_shutup_pins(codec); |
2091 | } | 823 | } |
2092 | 824 | ||
2093 | static void alc_free_kctls(struct hda_codec *codec) | ||
2094 | { | ||
2095 | struct alc_spec *spec = codec->spec; | ||
2096 | |||
2097 | if (spec->kctls.list) { | ||
2098 | struct snd_kcontrol_new *kctl = spec->kctls.list; | ||
2099 | int i; | ||
2100 | for (i = 0; i < spec->kctls.used; i++) | ||
2101 | kfree(kctl[i].name); | ||
2102 | } | ||
2103 | snd_array_free(&spec->kctls); | ||
2104 | } | ||
2105 | |||
2106 | static void alc_free_bind_ctls(struct hda_codec *codec) | ||
2107 | { | ||
2108 | struct alc_spec *spec = codec->spec; | ||
2109 | if (spec->bind_ctls.list) { | ||
2110 | struct hda_bind_ctls **ctl = spec->bind_ctls.list; | ||
2111 | int i; | ||
2112 | for (i = 0; i < spec->bind_ctls.used; i++) | ||
2113 | kfree(ctl[i]); | ||
2114 | } | ||
2115 | snd_array_free(&spec->bind_ctls); | ||
2116 | } | ||
2117 | |||
2118 | static void alc_free(struct hda_codec *codec) | 825 | static void alc_free(struct hda_codec *codec) |
2119 | { | 826 | { |
2120 | struct alc_spec *spec = codec->spec; | 827 | struct alc_spec *spec = codec->spec; |
@@ -2122,11 +829,9 @@ static void alc_free(struct hda_codec *codec) | |||
2122 | if (!spec) | 829 | if (!spec) |
2123 | return; | 830 | return; |
2124 | 831 | ||
2125 | alc_free_kctls(codec); | 832 | snd_hda_gen_spec_free(&spec->gen); |
2126 | alc_free_bind_ctls(codec); | ||
2127 | snd_array_free(&spec->paths); | ||
2128 | kfree(spec); | ||
2129 | snd_hda_detach_beep_device(codec); | 833 | snd_hda_detach_beep_device(codec); |
834 | kfree(spec); | ||
2130 | } | 835 | } |
2131 | 836 | ||
2132 | #ifdef CONFIG_PM | 837 | #ifdef CONFIG_PM |
@@ -2162,7 +867,7 @@ static int alc_resume(struct hda_codec *codec) | |||
2162 | */ | 867 | */ |
2163 | static const struct hda_codec_ops alc_patch_ops = { | 868 | static const struct hda_codec_ops alc_patch_ops = { |
2164 | .build_controls = alc_build_controls, | 869 | .build_controls = alc_build_controls, |
2165 | .build_pcms = alc_build_pcms, | 870 | .build_pcms = snd_hda_gen_build_pcms, |
2166 | .init = alc_init, | 871 | .init = alc_init, |
2167 | .free = alc_free, | 872 | .free = alc_free, |
2168 | .unsol_event = snd_hda_jack_unsol_event, | 873 | .unsol_event = snd_hda_jack_unsol_event, |
@@ -2231,2169 +936,6 @@ static int alc_codec_rename_from_preset(struct hda_codec *codec) | |||
2231 | return 0; | 936 | return 0; |
2232 | } | 937 | } |
2233 | 938 | ||
2234 | /* | ||
2235 | * Automatic parse of I/O pins from the BIOS configuration | ||
2236 | */ | ||
2237 | |||
2238 | enum { | ||
2239 | ALC_CTL_WIDGET_VOL, | ||
2240 | ALC_CTL_WIDGET_MUTE, | ||
2241 | ALC_CTL_BIND_MUTE, | ||
2242 | ALC_CTL_BIND_VOL, | ||
2243 | ALC_CTL_BIND_SW, | ||
2244 | }; | ||
2245 | static const struct snd_kcontrol_new alc_control_templates[] = { | ||
2246 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), | ||
2247 | HDA_CODEC_MUTE(NULL, 0, 0, 0), | ||
2248 | HDA_BIND_MUTE(NULL, 0, 0, 0), | ||
2249 | HDA_BIND_VOL(NULL, 0), | ||
2250 | HDA_BIND_SW(NULL, 0), | ||
2251 | }; | ||
2252 | |||
2253 | /* add dynamic controls */ | ||
2254 | static int add_control(struct alc_spec *spec, int type, const char *name, | ||
2255 | int cidx, unsigned long val) | ||
2256 | { | ||
2257 | struct snd_kcontrol_new *knew; | ||
2258 | |||
2259 | knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]); | ||
2260 | if (!knew) | ||
2261 | return -ENOMEM; | ||
2262 | knew->index = cidx; | ||
2263 | if (get_amp_nid_(val)) | ||
2264 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; | ||
2265 | knew->private_value = val; | ||
2266 | return 0; | ||
2267 | } | ||
2268 | |||
2269 | static int add_control_with_pfx(struct alc_spec *spec, int type, | ||
2270 | const char *pfx, const char *dir, | ||
2271 | const char *sfx, int cidx, unsigned long val) | ||
2272 | { | ||
2273 | char name[32]; | ||
2274 | snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx); | ||
2275 | return add_control(spec, type, name, cidx, val); | ||
2276 | } | ||
2277 | |||
2278 | #define add_pb_vol_ctrl(spec, type, pfx, val) \ | ||
2279 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val) | ||
2280 | #define add_pb_sw_ctrl(spec, type, pfx, val) \ | ||
2281 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val) | ||
2282 | #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \ | ||
2283 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val) | ||
2284 | #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \ | ||
2285 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val) | ||
2286 | |||
2287 | static const char * const channel_name[4] = { | ||
2288 | "Front", "Surround", "CLFE", "Side" | ||
2289 | }; | ||
2290 | |||
2291 | static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch, | ||
2292 | bool can_be_master, int *index) | ||
2293 | { | ||
2294 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
2295 | |||
2296 | *index = 0; | ||
2297 | if (cfg->line_outs == 1 && !spec->multi_ios && | ||
2298 | !cfg->hp_outs && !cfg->speaker_outs && can_be_master) | ||
2299 | return spec->vmaster_mute.hook ? "PCM" : "Master"; | ||
2300 | |||
2301 | /* if there is really a single DAC used in the whole output paths, | ||
2302 | * use it master (or "PCM" if a vmaster hook is present) | ||
2303 | */ | ||
2304 | if (spec->multiout.num_dacs == 1 && !spec->mixer_nid && | ||
2305 | !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0]) | ||
2306 | return spec->vmaster_mute.hook ? "PCM" : "Master"; | ||
2307 | |||
2308 | switch (cfg->line_out_type) { | ||
2309 | case AUTO_PIN_SPEAKER_OUT: | ||
2310 | if (cfg->line_outs == 1) | ||
2311 | return "Speaker"; | ||
2312 | if (cfg->line_outs == 2) | ||
2313 | return ch ? "Bass Speaker" : "Speaker"; | ||
2314 | break; | ||
2315 | case AUTO_PIN_HP_OUT: | ||
2316 | /* for multi-io case, only the primary out */ | ||
2317 | if (ch && spec->multi_ios) | ||
2318 | break; | ||
2319 | *index = ch; | ||
2320 | return "Headphone"; | ||
2321 | default: | ||
2322 | if (cfg->line_outs == 1 && !spec->multi_ios) | ||
2323 | return "PCM"; | ||
2324 | break; | ||
2325 | } | ||
2326 | if (ch >= ARRAY_SIZE(channel_name)) { | ||
2327 | snd_BUG(); | ||
2328 | return "PCM"; | ||
2329 | } | ||
2330 | |||
2331 | return channel_name[ch]; | ||
2332 | } | ||
2333 | |||
2334 | #ifdef CONFIG_PM | ||
2335 | /* add the powersave loopback-list entry */ | ||
2336 | static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx) | ||
2337 | { | ||
2338 | struct hda_amp_list *list; | ||
2339 | |||
2340 | if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1) | ||
2341 | return; | ||
2342 | list = spec->loopback_list + spec->num_loopbacks; | ||
2343 | list->nid = mix; | ||
2344 | list->dir = HDA_INPUT; | ||
2345 | list->idx = idx; | ||
2346 | spec->num_loopbacks++; | ||
2347 | spec->loopback.amplist = spec->loopback_list; | ||
2348 | } | ||
2349 | #else | ||
2350 | #define add_loopback_list(spec, mix, idx) /* NOP */ | ||
2351 | #endif | ||
2352 | |||
2353 | /* create input playback/capture controls for the given pin */ | ||
2354 | static int new_analog_input(struct hda_codec *codec, hda_nid_t pin, | ||
2355 | const char *ctlname, int ctlidx, | ||
2356 | hda_nid_t mix_nid) | ||
2357 | { | ||
2358 | struct alc_spec *spec = codec->spec; | ||
2359 | struct nid_path *path; | ||
2360 | unsigned int val; | ||
2361 | int err, idx; | ||
2362 | |||
2363 | if (!nid_has_volume(codec, mix_nid, HDA_INPUT) && | ||
2364 | !nid_has_mute(codec, mix_nid, HDA_INPUT)) | ||
2365 | return 0; /* no need for analog loopback */ | ||
2366 | |||
2367 | path = add_new_nid_path(codec, pin, mix_nid, 2); | ||
2368 | if (!path) | ||
2369 | return -EINVAL; | ||
2370 | |||
2371 | idx = path->idx[path->depth - 1]; | ||
2372 | if (nid_has_volume(codec, mix_nid, HDA_INPUT)) { | ||
2373 | val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT); | ||
2374 | err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, val); | ||
2375 | if (err < 0) | ||
2376 | return err; | ||
2377 | path->ctls[NID_PATH_VOL_CTL] = val; | ||
2378 | } | ||
2379 | |||
2380 | if (nid_has_mute(codec, mix_nid, HDA_INPUT)) { | ||
2381 | val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT); | ||
2382 | err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, val); | ||
2383 | if (err < 0) | ||
2384 | return err; | ||
2385 | path->ctls[NID_PATH_MUTE_CTL] = val; | ||
2386 | } | ||
2387 | |||
2388 | path->active = true; | ||
2389 | add_loopback_list(spec, mix_nid, idx); | ||
2390 | return 0; | ||
2391 | } | ||
2392 | |||
2393 | static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid) | ||
2394 | { | ||
2395 | unsigned int pincap = snd_hda_query_pin_caps(codec, nid); | ||
2396 | return (pincap & AC_PINCAP_IN) != 0; | ||
2397 | } | ||
2398 | |||
2399 | /* check whether the given two widgets can be connected */ | ||
2400 | static bool is_reachable_path(struct hda_codec *codec, | ||
2401 | hda_nid_t from_nid, hda_nid_t to_nid) | ||
2402 | { | ||
2403 | if (!from_nid || !to_nid) | ||
2404 | return false; | ||
2405 | return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0; | ||
2406 | } | ||
2407 | |||
2408 | /* Parse the codec tree and retrieve ADCs */ | ||
2409 | static int alc_auto_fill_adc_nids(struct hda_codec *codec) | ||
2410 | { | ||
2411 | struct alc_spec *spec = codec->spec; | ||
2412 | hda_nid_t nid; | ||
2413 | hda_nid_t *adc_nids = spec->adc_nids; | ||
2414 | int max_nums = ARRAY_SIZE(spec->adc_nids); | ||
2415 | int i, nums = 0; | ||
2416 | |||
2417 | nid = codec->start_nid; | ||
2418 | for (i = 0; i < codec->num_nodes; i++, nid++) { | ||
2419 | unsigned int caps = get_wcaps(codec, nid); | ||
2420 | int type = get_wcaps_type(caps); | ||
2421 | |||
2422 | if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL)) | ||
2423 | continue; | ||
2424 | adc_nids[nums] = nid; | ||
2425 | if (++nums >= max_nums) | ||
2426 | break; | ||
2427 | } | ||
2428 | spec->num_adc_nids = nums; | ||
2429 | return nums; | ||
2430 | } | ||
2431 | |||
2432 | /* filter out invalid adc_nids that don't give all active input pins; | ||
2433 | * if needed, check whether dynamic ADC-switching is available | ||
2434 | */ | ||
2435 | static int check_dyn_adc_switch(struct hda_codec *codec) | ||
2436 | { | ||
2437 | struct alc_spec *spec = codec->spec; | ||
2438 | struct hda_input_mux *imux = &spec->input_mux; | ||
2439 | hda_nid_t adc_nids[ARRAY_SIZE(spec->adc_nids)]; | ||
2440 | int i, n, nums; | ||
2441 | hda_nid_t pin, adc; | ||
2442 | |||
2443 | again: | ||
2444 | nums = 0; | ||
2445 | for (n = 0; n < spec->num_adc_nids; n++) { | ||
2446 | adc = spec->adc_nids[n]; | ||
2447 | for (i = 0; i < imux->num_items; i++) { | ||
2448 | pin = spec->imux_pins[i]; | ||
2449 | if (!is_reachable_path(codec, pin, adc)) | ||
2450 | break; | ||
2451 | } | ||
2452 | if (i >= imux->num_items) | ||
2453 | adc_nids[nums++] = adc; | ||
2454 | } | ||
2455 | |||
2456 | if (!nums) { | ||
2457 | if (spec->shared_mic_hp) { | ||
2458 | spec->shared_mic_hp = 0; | ||
2459 | imux->num_items = 1; | ||
2460 | goto again; | ||
2461 | } | ||
2462 | |||
2463 | /* check whether ADC-switch is possible */ | ||
2464 | for (i = 0; i < imux->num_items; i++) { | ||
2465 | pin = spec->imux_pins[i]; | ||
2466 | for (n = 0; n < spec->num_adc_nids; n++) { | ||
2467 | adc = spec->adc_nids[n]; | ||
2468 | if (is_reachable_path(codec, pin, adc)) { | ||
2469 | spec->dyn_adc_idx[i] = n; | ||
2470 | break; | ||
2471 | } | ||
2472 | } | ||
2473 | } | ||
2474 | |||
2475 | snd_printdd("realtek: enabling ADC switching\n"); | ||
2476 | spec->dyn_adc_switch = 1; | ||
2477 | } else if (nums != spec->num_adc_nids) { | ||
2478 | memcpy(spec->adc_nids, adc_nids, nums * sizeof(hda_nid_t)); | ||
2479 | spec->num_adc_nids = nums; | ||
2480 | } | ||
2481 | |||
2482 | if (imux->num_items == 1 || spec->shared_mic_hp) { | ||
2483 | snd_printdd("realtek: reducing to a single ADC\n"); | ||
2484 | spec->num_adc_nids = 1; /* reduce to a single ADC */ | ||
2485 | } | ||
2486 | |||
2487 | /* single index for individual volumes ctls */ | ||
2488 | if (!spec->dyn_adc_switch && spec->multi_cap_vol) | ||
2489 | spec->num_adc_nids = 1; | ||
2490 | |||
2491 | return 0; | ||
2492 | } | ||
2493 | |||
2494 | /* templates for capture controls */ | ||
2495 | static const struct snd_kcontrol_new cap_src_temp = { | ||
2496 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
2497 | .name = "Input Source", | ||
2498 | .info = alc_mux_enum_info, | ||
2499 | .get = alc_mux_enum_get, | ||
2500 | .put = alc_mux_enum_put, | ||
2501 | }; | ||
2502 | |||
2503 | static const struct snd_kcontrol_new cap_vol_temp = { | ||
2504 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
2505 | .name = "Capture Volume", | ||
2506 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | | ||
2507 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | | ||
2508 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), | ||
2509 | .info = alc_cap_vol_info, | ||
2510 | .get = alc_cap_vol_get, | ||
2511 | .put = alc_cap_vol_put, | ||
2512 | .tlv = { .c = alc_cap_vol_tlv }, | ||
2513 | }; | ||
2514 | |||
2515 | static const struct snd_kcontrol_new cap_sw_temp = { | ||
2516 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
2517 | .name = "Capture Switch", | ||
2518 | .info = alc_cap_sw_info, | ||
2519 | .get = alc_cap_sw_get, | ||
2520 | .put = alc_cap_sw_put, | ||
2521 | }; | ||
2522 | |||
2523 | static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path) | ||
2524 | { | ||
2525 | hda_nid_t nid; | ||
2526 | int i, depth; | ||
2527 | |||
2528 | path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0; | ||
2529 | for (depth = 0; depth < 3; depth++) { | ||
2530 | if (depth >= path->depth) | ||
2531 | return -EINVAL; | ||
2532 | i = path->depth - depth - 1; | ||
2533 | nid = path->path[i]; | ||
2534 | if (!path->ctls[NID_PATH_VOL_CTL]) { | ||
2535 | if (nid_has_volume(codec, nid, HDA_OUTPUT)) | ||
2536 | path->ctls[NID_PATH_VOL_CTL] = | ||
2537 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); | ||
2538 | else if (nid_has_volume(codec, nid, HDA_INPUT)) { | ||
2539 | int idx = path->idx[i]; | ||
2540 | if (!depth && codec->single_adc_amp) | ||
2541 | idx = 0; | ||
2542 | path->ctls[NID_PATH_VOL_CTL] = | ||
2543 | HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT); | ||
2544 | } | ||
2545 | } | ||
2546 | if (!path->ctls[NID_PATH_MUTE_CTL]) { | ||
2547 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) | ||
2548 | path->ctls[NID_PATH_MUTE_CTL] = | ||
2549 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); | ||
2550 | else if (nid_has_mute(codec, nid, HDA_INPUT)) { | ||
2551 | int idx = path->idx[i]; | ||
2552 | if (!depth && codec->single_adc_amp) | ||
2553 | idx = 0; | ||
2554 | path->ctls[NID_PATH_MUTE_CTL] = | ||
2555 | HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT); | ||
2556 | } | ||
2557 | } | ||
2558 | } | ||
2559 | return 0; | ||
2560 | } | ||
2561 | |||
2562 | static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs); | ||
2563 | |||
2564 | static int add_single_cap_ctl(struct hda_codec *codec, const char *label, | ||
2565 | int idx, bool is_switch, unsigned int ctl, | ||
2566 | bool inv_dmic) | ||
2567 | { | ||
2568 | struct alc_spec *spec = codec->spec; | ||
2569 | char tmpname[44]; | ||
2570 | int type = is_switch ? ALC_CTL_WIDGET_MUTE : ALC_CTL_WIDGET_VOL; | ||
2571 | const char *sfx = is_switch ? "Switch" : "Volume"; | ||
2572 | unsigned int chs = inv_dmic ? 1 : 3; | ||
2573 | int err; | ||
2574 | |||
2575 | if (!ctl) | ||
2576 | return 0; | ||
2577 | |||
2578 | if (label) | ||
2579 | snprintf(tmpname, sizeof(tmpname), | ||
2580 | "%s Capture %s", label, sfx); | ||
2581 | else | ||
2582 | snprintf(tmpname, sizeof(tmpname), | ||
2583 | "Capture %s", sfx); | ||
2584 | err = add_control(spec, type, tmpname, idx, | ||
2585 | amp_val_replace_channels(ctl, chs)); | ||
2586 | if (err < 0 || chs == 3) | ||
2587 | return err; | ||
2588 | |||
2589 | /* Make independent right kcontrol */ | ||
2590 | if (label) | ||
2591 | snprintf(tmpname, sizeof(tmpname), | ||
2592 | "Inverted %s Capture %s", label, sfx); | ||
2593 | else | ||
2594 | snprintf(tmpname, sizeof(tmpname), | ||
2595 | "Inverted Capture %s", sfx); | ||
2596 | return add_control(spec, type, tmpname, idx, | ||
2597 | amp_val_replace_channels(ctl, 2)); | ||
2598 | } | ||
2599 | |||
2600 | static bool is_inv_dmic_pin(struct hda_codec *codec, hda_nid_t nid) | ||
2601 | { | ||
2602 | struct alc_spec *spec = codec->spec; | ||
2603 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
2604 | unsigned int val; | ||
2605 | int i; | ||
2606 | |||
2607 | if (!spec->inv_dmic_split) | ||
2608 | return false; | ||
2609 | for (i = 0; i < cfg->num_inputs; i++) { | ||
2610 | if (cfg->inputs[i].pin != nid) | ||
2611 | continue; | ||
2612 | if (cfg->inputs[i].type != AUTO_PIN_MIC) | ||
2613 | return false; | ||
2614 | val = snd_hda_codec_get_pincfg(codec, nid); | ||
2615 | return snd_hda_get_input_pin_attr(val) == INPUT_PIN_ATTR_INT; | ||
2616 | } | ||
2617 | return false; | ||
2618 | } | ||
2619 | |||
2620 | /* create single (and simple) capture volume and switch controls */ | ||
2621 | static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx, | ||
2622 | unsigned int vol_ctl, unsigned int sw_ctl, | ||
2623 | bool inv_dmic) | ||
2624 | { | ||
2625 | int err; | ||
2626 | err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl, inv_dmic); | ||
2627 | if (err < 0) | ||
2628 | return err; | ||
2629 | err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl, inv_dmic); | ||
2630 | if (err < 0) | ||
2631 | return err; | ||
2632 | return 0; | ||
2633 | } | ||
2634 | |||
2635 | /* create bound capture volume and switch controls */ | ||
2636 | static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx, | ||
2637 | unsigned int vol_ctl, unsigned int sw_ctl) | ||
2638 | { | ||
2639 | struct alc_spec *spec = codec->spec; | ||
2640 | struct snd_kcontrol_new *knew; | ||
2641 | |||
2642 | if (vol_ctl) { | ||
2643 | knew = alc_kcontrol_new(spec, NULL, &cap_vol_temp); | ||
2644 | if (!knew) | ||
2645 | return -ENOMEM; | ||
2646 | knew->index = idx; | ||
2647 | knew->private_value = vol_ctl; | ||
2648 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; | ||
2649 | } | ||
2650 | if (sw_ctl) { | ||
2651 | knew = alc_kcontrol_new(spec, NULL, &cap_sw_temp); | ||
2652 | if (!knew) | ||
2653 | return -ENOMEM; | ||
2654 | knew->index = idx; | ||
2655 | knew->private_value = sw_ctl; | ||
2656 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; | ||
2657 | } | ||
2658 | return 0; | ||
2659 | } | ||
2660 | |||
2661 | /* return the vol ctl when used first in the imux list */ | ||
2662 | static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type) | ||
2663 | { | ||
2664 | struct alc_spec *spec = codec->spec; | ||
2665 | struct nid_path *path; | ||
2666 | unsigned int ctl; | ||
2667 | int i; | ||
2668 | |||
2669 | path = get_nid_path(codec, spec->imux_pins[idx], | ||
2670 | get_adc_nid(codec, 0, idx)); | ||
2671 | if (!path) | ||
2672 | return 0; | ||
2673 | ctl = path->ctls[type]; | ||
2674 | if (!ctl) | ||
2675 | return 0; | ||
2676 | for (i = 0; i < idx - 1; i++) { | ||
2677 | path = get_nid_path(codec, spec->imux_pins[i], | ||
2678 | get_adc_nid(codec, 0, i)); | ||
2679 | if (path && path->ctls[type] == ctl) | ||
2680 | return 0; | ||
2681 | } | ||
2682 | return ctl; | ||
2683 | } | ||
2684 | |||
2685 | /* create individual capture volume and switch controls per input */ | ||
2686 | static int create_multi_cap_vol_ctl(struct hda_codec *codec) | ||
2687 | { | ||
2688 | struct alc_spec *spec = codec->spec; | ||
2689 | struct hda_input_mux *imux = &spec->input_mux; | ||
2690 | int i, err, type, type_idx = 0; | ||
2691 | const char *prev_label = NULL; | ||
2692 | |||
2693 | for (i = 0; i < imux->num_items; i++) { | ||
2694 | const char *label; | ||
2695 | bool inv_dmic; | ||
2696 | label = hda_get_autocfg_input_label(codec, &spec->autocfg, i); | ||
2697 | if (prev_label && !strcmp(label, prev_label)) | ||
2698 | type_idx++; | ||
2699 | else | ||
2700 | type_idx = 0; | ||
2701 | prev_label = label; | ||
2702 | inv_dmic = is_inv_dmic_pin(codec, spec->imux_pins[i]); | ||
2703 | |||
2704 | for (type = 0; type < 2; type++) { | ||
2705 | err = add_single_cap_ctl(codec, label, type_idx, type, | ||
2706 | get_first_cap_ctl(codec, i, type), | ||
2707 | inv_dmic); | ||
2708 | if (err < 0) | ||
2709 | return err; | ||
2710 | } | ||
2711 | } | ||
2712 | return 0; | ||
2713 | } | ||
2714 | |||
2715 | static int create_capture_mixers(struct hda_codec *codec) | ||
2716 | { | ||
2717 | struct alc_spec *spec = codec->spec; | ||
2718 | struct hda_input_mux *imux = &spec->input_mux; | ||
2719 | int i, n, nums, err; | ||
2720 | |||
2721 | if (spec->dyn_adc_switch) | ||
2722 | nums = 1; | ||
2723 | else | ||
2724 | nums = spec->num_adc_nids; | ||
2725 | |||
2726 | if (!spec->auto_mic && imux->num_items > 1) { | ||
2727 | struct snd_kcontrol_new *knew; | ||
2728 | knew = alc_kcontrol_new(spec, NULL, &cap_src_temp); | ||
2729 | if (!knew) | ||
2730 | return -ENOMEM; | ||
2731 | knew->count = nums; | ||
2732 | } | ||
2733 | |||
2734 | for (n = 0; n < nums; n++) { | ||
2735 | bool multi = false; | ||
2736 | bool inv_dmic = false; | ||
2737 | int vol, sw; | ||
2738 | |||
2739 | vol = sw = 0; | ||
2740 | for (i = 0; i < imux->num_items; i++) { | ||
2741 | struct nid_path *path; | ||
2742 | path = get_nid_path(codec, spec->imux_pins[i], | ||
2743 | get_adc_nid(codec, n, i)); | ||
2744 | if (!path) | ||
2745 | continue; | ||
2746 | parse_capvol_in_path(codec, path); | ||
2747 | if (!vol) | ||
2748 | vol = path->ctls[NID_PATH_VOL_CTL]; | ||
2749 | else if (vol != path->ctls[NID_PATH_VOL_CTL]) | ||
2750 | multi = true; | ||
2751 | if (!sw) | ||
2752 | sw = path->ctls[NID_PATH_MUTE_CTL]; | ||
2753 | else if (sw != path->ctls[NID_PATH_MUTE_CTL]) | ||
2754 | multi = true; | ||
2755 | if (is_inv_dmic_pin(codec, spec->imux_pins[i])) | ||
2756 | inv_dmic = true; | ||
2757 | } | ||
2758 | |||
2759 | if (!multi) | ||
2760 | err = create_single_cap_vol_ctl(codec, n, vol, sw, | ||
2761 | inv_dmic); | ||
2762 | else if (!spec->multi_cap_vol) | ||
2763 | err = create_bind_cap_vol_ctl(codec, n, vol, sw); | ||
2764 | else | ||
2765 | err = create_multi_cap_vol_ctl(codec); | ||
2766 | if (err < 0) | ||
2767 | return err; | ||
2768 | } | ||
2769 | |||
2770 | return 0; | ||
2771 | } | ||
2772 | |||
2773 | /* create playback/capture controls for input pins */ | ||
2774 | static int alc_auto_create_input_ctls(struct hda_codec *codec) | ||
2775 | { | ||
2776 | struct alc_spec *spec = codec->spec; | ||
2777 | const struct auto_pin_cfg *cfg = &spec->autocfg; | ||
2778 | hda_nid_t mixer = spec->mixer_nid; | ||
2779 | struct hda_input_mux *imux = &spec->input_mux; | ||
2780 | int num_adcs; | ||
2781 | int i, c, err, type_idx = 0; | ||
2782 | const char *prev_label = NULL; | ||
2783 | |||
2784 | num_adcs = alc_auto_fill_adc_nids(codec); | ||
2785 | if (num_adcs < 0) | ||
2786 | return 0; | ||
2787 | |||
2788 | for (i = 0; i < cfg->num_inputs; i++) { | ||
2789 | hda_nid_t pin; | ||
2790 | const char *label; | ||
2791 | bool imux_added; | ||
2792 | |||
2793 | pin = cfg->inputs[i].pin; | ||
2794 | if (!alc_is_input_pin(codec, pin)) | ||
2795 | continue; | ||
2796 | |||
2797 | label = hda_get_autocfg_input_label(codec, cfg, i); | ||
2798 | if (spec->shared_mic_hp && !strcmp(label, "Misc")) | ||
2799 | label = "Headphone Mic"; | ||
2800 | if (prev_label && !strcmp(label, prev_label)) | ||
2801 | type_idx++; | ||
2802 | else | ||
2803 | type_idx = 0; | ||
2804 | prev_label = label; | ||
2805 | |||
2806 | if (mixer) { | ||
2807 | if (is_reachable_path(codec, pin, mixer)) { | ||
2808 | err = new_analog_input(codec, pin, | ||
2809 | label, type_idx, mixer); | ||
2810 | if (err < 0) | ||
2811 | return err; | ||
2812 | } | ||
2813 | } | ||
2814 | |||
2815 | imux_added = false; | ||
2816 | for (c = 0; c < num_adcs; c++) { | ||
2817 | struct nid_path *path; | ||
2818 | hda_nid_t adc = spec->adc_nids[c]; | ||
2819 | |||
2820 | if (!is_reachable_path(codec, pin, adc)) | ||
2821 | continue; | ||
2822 | path = snd_array_new(&spec->paths); | ||
2823 | if (!path) | ||
2824 | return -ENOMEM; | ||
2825 | memset(path, 0, sizeof(*path)); | ||
2826 | if (!parse_nid_path(codec, pin, adc, 2, path)) { | ||
2827 | snd_printd(KERN_ERR | ||
2828 | "invalid input path 0x%x -> 0x%x\n", | ||
2829 | pin, adc); | ||
2830 | spec->paths.used--; | ||
2831 | continue; | ||
2832 | } | ||
2833 | |||
2834 | if (!imux_added) { | ||
2835 | spec->imux_pins[imux->num_items] = pin; | ||
2836 | snd_hda_add_imux_item(imux, label, | ||
2837 | imux->num_items, NULL); | ||
2838 | imux_added = true; | ||
2839 | } | ||
2840 | } | ||
2841 | } | ||
2842 | |||
2843 | return 0; | ||
2844 | } | ||
2845 | |||
2846 | /* create a shared input with the headphone out */ | ||
2847 | static int alc_auto_create_shared_input(struct hda_codec *codec) | ||
2848 | { | ||
2849 | struct alc_spec *spec = codec->spec; | ||
2850 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
2851 | unsigned int defcfg; | ||
2852 | hda_nid_t nid; | ||
2853 | |||
2854 | /* only one internal input pin? */ | ||
2855 | if (cfg->num_inputs != 1) | ||
2856 | return 0; | ||
2857 | defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin); | ||
2858 | if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT) | ||
2859 | return 0; | ||
2860 | |||
2861 | if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) | ||
2862 | nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */ | ||
2863 | else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT) | ||
2864 | nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */ | ||
2865 | else | ||
2866 | return 0; /* both not available */ | ||
2867 | |||
2868 | if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN)) | ||
2869 | return 0; /* no input */ | ||
2870 | |||
2871 | cfg->inputs[1].pin = nid; | ||
2872 | cfg->inputs[1].type = AUTO_PIN_MIC; | ||
2873 | cfg->num_inputs = 2; | ||
2874 | spec->shared_mic_hp = 1; | ||
2875 | snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid); | ||
2876 | return 0; | ||
2877 | } | ||
2878 | |||
2879 | static int get_pin_type(int line_out_type) | ||
2880 | { | ||
2881 | if (line_out_type == AUTO_PIN_HP_OUT) | ||
2882 | return PIN_HP; | ||
2883 | else | ||
2884 | return PIN_OUT; | ||
2885 | } | ||
2886 | |||
2887 | static void alc_auto_init_analog_input(struct hda_codec *codec) | ||
2888 | { | ||
2889 | struct alc_spec *spec = codec->spec; | ||
2890 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
2891 | int i; | ||
2892 | |||
2893 | for (i = 0; i < cfg->num_inputs; i++) { | ||
2894 | hda_nid_t nid = cfg->inputs[i].pin; | ||
2895 | if (alc_is_input_pin(codec, nid)) | ||
2896 | alc_set_input_pin(codec, nid, cfg->inputs[i].type); | ||
2897 | |||
2898 | /* mute loopback inputs */ | ||
2899 | if (spec->mixer_nid) { | ||
2900 | struct nid_path *path; | ||
2901 | path = get_nid_path(codec, nid, spec->mixer_nid); | ||
2902 | if (path) | ||
2903 | activate_path(codec, path, path->active, false); | ||
2904 | } | ||
2905 | } | ||
2906 | } | ||
2907 | |||
2908 | static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid) | ||
2909 | { | ||
2910 | struct alc_spec *spec = codec->spec; | ||
2911 | int i; | ||
2912 | |||
2913 | for (i = 0; i < spec->paths.used; i++) { | ||
2914 | struct nid_path *path = snd_array_elem(&spec->paths, i); | ||
2915 | if (path->path[0] == nid) | ||
2916 | return true; | ||
2917 | } | ||
2918 | return false; | ||
2919 | } | ||
2920 | |||
2921 | /* look for an empty DAC slot */ | ||
2922 | static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin, | ||
2923 | bool is_digital) | ||
2924 | { | ||
2925 | struct alc_spec *spec = codec->spec; | ||
2926 | bool cap_digital; | ||
2927 | int i; | ||
2928 | |||
2929 | for (i = 0; i < spec->num_all_dacs; i++) { | ||
2930 | hda_nid_t nid = spec->all_dacs[i]; | ||
2931 | if (!nid || alc_is_dac_already_used(codec, nid)) | ||
2932 | continue; | ||
2933 | cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL); | ||
2934 | if (is_digital != cap_digital) | ||
2935 | continue; | ||
2936 | if (is_reachable_path(codec, nid, pin)) | ||
2937 | return nid; | ||
2938 | } | ||
2939 | return 0; | ||
2940 | } | ||
2941 | |||
2942 | /* called recursively */ | ||
2943 | static bool __parse_nid_path(struct hda_codec *codec, | ||
2944 | hda_nid_t from_nid, hda_nid_t to_nid, | ||
2945 | int with_aa_mix, struct nid_path *path, int depth) | ||
2946 | { | ||
2947 | struct alc_spec *spec = codec->spec; | ||
2948 | hda_nid_t conn[16]; | ||
2949 | int i, nums; | ||
2950 | |||
2951 | if (to_nid == spec->mixer_nid) { | ||
2952 | if (!with_aa_mix) | ||
2953 | return false; | ||
2954 | with_aa_mix = 2; /* mark aa-mix is included */ | ||
2955 | } | ||
2956 | |||
2957 | nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn)); | ||
2958 | for (i = 0; i < nums; i++) { | ||
2959 | if (conn[i] != from_nid) { | ||
2960 | /* special case: when from_nid is 0, | ||
2961 | * try to find an empty DAC | ||
2962 | */ | ||
2963 | if (from_nid || | ||
2964 | get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT || | ||
2965 | alc_is_dac_already_used(codec, conn[i])) | ||
2966 | continue; | ||
2967 | } | ||
2968 | /* aa-mix is requested but not included? */ | ||
2969 | if (!(spec->mixer_nid && with_aa_mix == 1)) | ||
2970 | goto found; | ||
2971 | } | ||
2972 | if (depth >= MAX_NID_PATH_DEPTH) | ||
2973 | return false; | ||
2974 | for (i = 0; i < nums; i++) { | ||
2975 | unsigned int type; | ||
2976 | type = get_wcaps_type(get_wcaps(codec, conn[i])); | ||
2977 | if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN || | ||
2978 | type == AC_WID_PIN) | ||
2979 | continue; | ||
2980 | if (__parse_nid_path(codec, from_nid, conn[i], | ||
2981 | with_aa_mix, path, depth + 1)) | ||
2982 | goto found; | ||
2983 | } | ||
2984 | return false; | ||
2985 | |||
2986 | found: | ||
2987 | path->path[path->depth] = conn[i]; | ||
2988 | path->idx[path->depth + 1] = i; | ||
2989 | if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX) | ||
2990 | path->multi[path->depth + 1] = 1; | ||
2991 | path->depth++; | ||
2992 | return true; | ||
2993 | } | ||
2994 | |||
2995 | /* parse the widget path from the given nid to the target nid; | ||
2996 | * when @from_nid is 0, try to find an empty DAC; | ||
2997 | * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded. | ||
2998 | * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded. | ||
2999 | * when @with_aa_mix is 2, no special handling about spec->mixer_nid. | ||
3000 | */ | ||
3001 | static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid, | ||
3002 | hda_nid_t to_nid, int with_aa_mix, | ||
3003 | struct nid_path *path) | ||
3004 | { | ||
3005 | if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) { | ||
3006 | path->path[path->depth] = to_nid; | ||
3007 | path->depth++; | ||
3008 | #if 0 | ||
3009 | snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n", | ||
3010 | path->depth, path->path[0], path->path[1], | ||
3011 | path->path[2], path->path[3], path->path[4]); | ||
3012 | #endif | ||
3013 | return true; | ||
3014 | } | ||
3015 | return false; | ||
3016 | } | ||
3017 | |||
3018 | static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin) | ||
3019 | { | ||
3020 | struct alc_spec *spec = codec->spec; | ||
3021 | int i; | ||
3022 | hda_nid_t nid_found = 0; | ||
3023 | |||
3024 | for (i = 0; i < spec->num_all_dacs; i++) { | ||
3025 | hda_nid_t nid = spec->all_dacs[i]; | ||
3026 | if (!nid || alc_is_dac_already_used(codec, nid)) | ||
3027 | continue; | ||
3028 | if (is_reachable_path(codec, nid, pin)) { | ||
3029 | if (nid_found) | ||
3030 | return 0; | ||
3031 | nid_found = nid; | ||
3032 | } | ||
3033 | } | ||
3034 | return nid_found; | ||
3035 | } | ||
3036 | |||
3037 | static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type) | ||
3038 | { | ||
3039 | struct alc_spec *spec = codec->spec; | ||
3040 | int i; | ||
3041 | |||
3042 | for (i = 0; i < spec->paths.used; i++) { | ||
3043 | struct nid_path *path = snd_array_elem(&spec->paths, i); | ||
3044 | if (path->ctls[type] == val) | ||
3045 | return true; | ||
3046 | } | ||
3047 | return false; | ||
3048 | } | ||
3049 | |||
3050 | /* badness definition */ | ||
3051 | enum { | ||
3052 | /* No primary DAC is found for the main output */ | ||
3053 | BAD_NO_PRIMARY_DAC = 0x10000, | ||
3054 | /* No DAC is found for the extra output */ | ||
3055 | BAD_NO_DAC = 0x4000, | ||
3056 | /* No possible multi-ios */ | ||
3057 | BAD_MULTI_IO = 0x103, | ||
3058 | /* No individual DAC for extra output */ | ||
3059 | BAD_NO_EXTRA_DAC = 0x102, | ||
3060 | /* No individual DAC for extra surrounds */ | ||
3061 | BAD_NO_EXTRA_SURR_DAC = 0x101, | ||
3062 | /* Primary DAC shared with main surrounds */ | ||
3063 | BAD_SHARED_SURROUND = 0x100, | ||
3064 | /* Primary DAC shared with main CLFE */ | ||
3065 | BAD_SHARED_CLFE = 0x10, | ||
3066 | /* Primary DAC shared with extra surrounds */ | ||
3067 | BAD_SHARED_EXTRA_SURROUND = 0x10, | ||
3068 | /* Volume widget is shared */ | ||
3069 | BAD_SHARED_VOL = 0x10, | ||
3070 | }; | ||
3071 | |||
3072 | static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec, | ||
3073 | struct nid_path *path); | ||
3074 | static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec, | ||
3075 | struct nid_path *path); | ||
3076 | |||
3077 | static struct nid_path *add_new_nid_path(struct hda_codec *codec, | ||
3078 | hda_nid_t from_nid, hda_nid_t to_nid, | ||
3079 | int with_aa_mix) | ||
3080 | { | ||
3081 | struct alc_spec *spec = codec->spec; | ||
3082 | struct nid_path *path; | ||
3083 | |||
3084 | if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid)) | ||
3085 | return NULL; | ||
3086 | |||
3087 | path = snd_array_new(&spec->paths); | ||
3088 | if (!path) | ||
3089 | return NULL; | ||
3090 | memset(path, 0, sizeof(*path)); | ||
3091 | if (parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path)) | ||
3092 | return path; | ||
3093 | /* push back */ | ||
3094 | spec->paths.used--; | ||
3095 | return NULL; | ||
3096 | } | ||
3097 | |||
3098 | /* get the path between the given NIDs; | ||
3099 | * passing 0 to either @pin or @dac behaves as a wildcard | ||
3100 | */ | ||
3101 | static struct nid_path * | ||
3102 | get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid) | ||
3103 | { | ||
3104 | struct alc_spec *spec = codec->spec; | ||
3105 | int i; | ||
3106 | |||
3107 | for (i = 0; i < spec->paths.used; i++) { | ||
3108 | struct nid_path *path = snd_array_elem(&spec->paths, i); | ||
3109 | if (path->depth <= 0) | ||
3110 | continue; | ||
3111 | if ((!from_nid || path->path[0] == from_nid) && | ||
3112 | (!to_nid || path->path[path->depth - 1] == to_nid)) | ||
3113 | return path; | ||
3114 | } | ||
3115 | return NULL; | ||
3116 | } | ||
3117 | |||
3118 | /* look for widgets in the path between the given NIDs appropriate for | ||
3119 | * volume and mute controls, and assign the values to ctls[]. | ||
3120 | * | ||
3121 | * When no appropriate widget is found in the path, the badness value | ||
3122 | * is incremented depending on the situation. The function returns the | ||
3123 | * total badness for both volume and mute controls. | ||
3124 | */ | ||
3125 | static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin, | ||
3126 | hda_nid_t dac) | ||
3127 | { | ||
3128 | struct nid_path *path = get_nid_path(codec, dac, pin); | ||
3129 | hda_nid_t nid; | ||
3130 | unsigned int val; | ||
3131 | int badness = 0; | ||
3132 | |||
3133 | if (!path) | ||
3134 | return BAD_SHARED_VOL * 2; | ||
3135 | nid = alc_look_for_out_vol_nid(codec, path); | ||
3136 | if (nid) { | ||
3137 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); | ||
3138 | if (is_ctl_used(codec, val, NID_PATH_VOL_CTL)) | ||
3139 | badness += BAD_SHARED_VOL; | ||
3140 | else | ||
3141 | path->ctls[NID_PATH_VOL_CTL] = val; | ||
3142 | } else | ||
3143 | badness += BAD_SHARED_VOL; | ||
3144 | nid = alc_look_for_out_mute_nid(codec, path); | ||
3145 | if (nid) { | ||
3146 | unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid)); | ||
3147 | if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT || | ||
3148 | nid_has_mute(codec, nid, HDA_OUTPUT)) | ||
3149 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); | ||
3150 | else | ||
3151 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT); | ||
3152 | if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL)) | ||
3153 | badness += BAD_SHARED_VOL; | ||
3154 | else | ||
3155 | path->ctls[NID_PATH_MUTE_CTL] = val; | ||
3156 | } else | ||
3157 | badness += BAD_SHARED_VOL; | ||
3158 | return badness; | ||
3159 | } | ||
3160 | |||
3161 | struct badness_table { | ||
3162 | int no_primary_dac; /* no primary DAC */ | ||
3163 | int no_dac; /* no secondary DACs */ | ||
3164 | int shared_primary; /* primary DAC is shared with main output */ | ||
3165 | int shared_surr; /* secondary DAC shared with main or primary */ | ||
3166 | int shared_clfe; /* third DAC shared with main or primary */ | ||
3167 | int shared_surr_main; /* secondary DAC sahred with main/DAC0 */ | ||
3168 | }; | ||
3169 | |||
3170 | static struct badness_table main_out_badness = { | ||
3171 | .no_primary_dac = BAD_NO_PRIMARY_DAC, | ||
3172 | .no_dac = BAD_NO_DAC, | ||
3173 | .shared_primary = BAD_NO_PRIMARY_DAC, | ||
3174 | .shared_surr = BAD_SHARED_SURROUND, | ||
3175 | .shared_clfe = BAD_SHARED_CLFE, | ||
3176 | .shared_surr_main = BAD_SHARED_SURROUND, | ||
3177 | }; | ||
3178 | |||
3179 | static struct badness_table extra_out_badness = { | ||
3180 | .no_primary_dac = BAD_NO_DAC, | ||
3181 | .no_dac = BAD_NO_DAC, | ||
3182 | .shared_primary = BAD_NO_EXTRA_DAC, | ||
3183 | .shared_surr = BAD_SHARED_EXTRA_SURROUND, | ||
3184 | .shared_clfe = BAD_SHARED_EXTRA_SURROUND, | ||
3185 | .shared_surr_main = BAD_NO_EXTRA_SURR_DAC, | ||
3186 | }; | ||
3187 | |||
3188 | /* try to assign DACs to pins and return the resultant badness */ | ||
3189 | static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs, | ||
3190 | const hda_nid_t *pins, hda_nid_t *dacs, | ||
3191 | const struct badness_table *bad) | ||
3192 | { | ||
3193 | struct alc_spec *spec = codec->spec; | ||
3194 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
3195 | int i, j; | ||
3196 | int badness = 0; | ||
3197 | hda_nid_t dac; | ||
3198 | |||
3199 | if (!num_outs) | ||
3200 | return 0; | ||
3201 | |||
3202 | for (i = 0; i < num_outs; i++) { | ||
3203 | hda_nid_t pin = pins[i]; | ||
3204 | if (!dacs[i]) | ||
3205 | dacs[i] = alc_auto_look_for_dac(codec, pin, false); | ||
3206 | if (!dacs[i] && !i) { | ||
3207 | for (j = 1; j < num_outs; j++) { | ||
3208 | if (is_reachable_path(codec, dacs[j], pin)) { | ||
3209 | dacs[0] = dacs[j]; | ||
3210 | dacs[j] = 0; | ||
3211 | break; | ||
3212 | } | ||
3213 | } | ||
3214 | } | ||
3215 | dac = dacs[i]; | ||
3216 | if (!dac) { | ||
3217 | if (is_reachable_path(codec, dacs[0], pin)) | ||
3218 | dac = dacs[0]; | ||
3219 | else if (cfg->line_outs > i && | ||
3220 | is_reachable_path(codec, spec->private_dac_nids[i], pin)) | ||
3221 | dac = spec->private_dac_nids[i]; | ||
3222 | if (dac) { | ||
3223 | if (!i) | ||
3224 | badness += bad->shared_primary; | ||
3225 | else if (i == 1) | ||
3226 | badness += bad->shared_surr; | ||
3227 | else | ||
3228 | badness += bad->shared_clfe; | ||
3229 | } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) { | ||
3230 | dac = spec->private_dac_nids[0]; | ||
3231 | badness += bad->shared_surr_main; | ||
3232 | } else if (!i) | ||
3233 | badness += bad->no_primary_dac; | ||
3234 | else | ||
3235 | badness += bad->no_dac; | ||
3236 | } | ||
3237 | if (!add_new_nid_path(codec, dac, pin, 0)) | ||
3238 | dac = dacs[i] = 0; | ||
3239 | if (dac) | ||
3240 | badness += assign_out_path_ctls(codec, pin, dac); | ||
3241 | } | ||
3242 | |||
3243 | return badness; | ||
3244 | } | ||
3245 | |||
3246 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, | ||
3247 | hda_nid_t reference_pin, | ||
3248 | bool hardwired, int offset); | ||
3249 | |||
3250 | static bool alc_map_singles(struct hda_codec *codec, int outs, | ||
3251 | const hda_nid_t *pins, hda_nid_t *dacs) | ||
3252 | { | ||
3253 | int i; | ||
3254 | bool found = false; | ||
3255 | for (i = 0; i < outs; i++) { | ||
3256 | hda_nid_t dac; | ||
3257 | if (dacs[i]) | ||
3258 | continue; | ||
3259 | dac = get_dac_if_single(codec, pins[i]); | ||
3260 | if (!dac) | ||
3261 | continue; | ||
3262 | if (add_new_nid_path(codec, dac, pins[i], 0)) { | ||
3263 | dacs[i] = dac; | ||
3264 | found = true; | ||
3265 | } | ||
3266 | } | ||
3267 | return found; | ||
3268 | } | ||
3269 | |||
3270 | /* fill in the dac_nids table from the parsed pin configuration */ | ||
3271 | static int fill_and_eval_dacs(struct hda_codec *codec, | ||
3272 | bool fill_hardwired, | ||
3273 | bool fill_mio_first) | ||
3274 | { | ||
3275 | struct alc_spec *spec = codec->spec; | ||
3276 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
3277 | int i, err, badness; | ||
3278 | |||
3279 | /* set num_dacs once to full for alc_auto_look_for_dac() */ | ||
3280 | spec->multiout.num_dacs = cfg->line_outs; | ||
3281 | spec->multiout.dac_nids = spec->private_dac_nids; | ||
3282 | memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids)); | ||
3283 | memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid)); | ||
3284 | memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid)); | ||
3285 | spec->multi_ios = 0; | ||
3286 | snd_array_free(&spec->paths); | ||
3287 | badness = 0; | ||
3288 | |||
3289 | /* fill hard-wired DACs first */ | ||
3290 | if (fill_hardwired) { | ||
3291 | bool mapped; | ||
3292 | do { | ||
3293 | mapped = alc_map_singles(codec, cfg->line_outs, | ||
3294 | cfg->line_out_pins, | ||
3295 | spec->private_dac_nids); | ||
3296 | mapped |= alc_map_singles(codec, cfg->hp_outs, | ||
3297 | cfg->hp_pins, | ||
3298 | spec->multiout.hp_out_nid); | ||
3299 | mapped |= alc_map_singles(codec, cfg->speaker_outs, | ||
3300 | cfg->speaker_pins, | ||
3301 | spec->multiout.extra_out_nid); | ||
3302 | if (fill_mio_first && cfg->line_outs == 1 && | ||
3303 | cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { | ||
3304 | err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0); | ||
3305 | if (!err) | ||
3306 | mapped = true; | ||
3307 | } | ||
3308 | } while (mapped); | ||
3309 | } | ||
3310 | |||
3311 | badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins, | ||
3312 | spec->private_dac_nids, | ||
3313 | &main_out_badness); | ||
3314 | |||
3315 | /* re-count num_dacs and squash invalid entries */ | ||
3316 | spec->multiout.num_dacs = 0; | ||
3317 | for (i = 0; i < cfg->line_outs; i++) { | ||
3318 | if (spec->private_dac_nids[i]) | ||
3319 | spec->multiout.num_dacs++; | ||
3320 | else { | ||
3321 | memmove(spec->private_dac_nids + i, | ||
3322 | spec->private_dac_nids + i + 1, | ||
3323 | sizeof(hda_nid_t) * (cfg->line_outs - i - 1)); | ||
3324 | spec->private_dac_nids[cfg->line_outs - 1] = 0; | ||
3325 | } | ||
3326 | } | ||
3327 | |||
3328 | if (fill_mio_first && | ||
3329 | cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { | ||
3330 | /* try to fill multi-io first */ | ||
3331 | err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0); | ||
3332 | if (err < 0) | ||
3333 | return err; | ||
3334 | /* we don't count badness at this stage yet */ | ||
3335 | } | ||
3336 | |||
3337 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) { | ||
3338 | err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins, | ||
3339 | spec->multiout.hp_out_nid, | ||
3340 | &extra_out_badness); | ||
3341 | if (err < 0) | ||
3342 | return err; | ||
3343 | badness += err; | ||
3344 | } | ||
3345 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { | ||
3346 | err = alc_auto_fill_dacs(codec, cfg->speaker_outs, | ||
3347 | cfg->speaker_pins, | ||
3348 | spec->multiout.extra_out_nid, | ||
3349 | &extra_out_badness); | ||
3350 | if (err < 0) | ||
3351 | return err; | ||
3352 | badness += err; | ||
3353 | } | ||
3354 | if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { | ||
3355 | err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0); | ||
3356 | if (err < 0) | ||
3357 | return err; | ||
3358 | badness += err; | ||
3359 | } | ||
3360 | if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { | ||
3361 | /* try multi-ios with HP + inputs */ | ||
3362 | int offset = 0; | ||
3363 | if (cfg->line_outs >= 3) | ||
3364 | offset = 1; | ||
3365 | err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false, | ||
3366 | offset); | ||
3367 | if (err < 0) | ||
3368 | return err; | ||
3369 | badness += err; | ||
3370 | } | ||
3371 | |||
3372 | if (spec->multi_ios == 2) { | ||
3373 | for (i = 0; i < 2; i++) | ||
3374 | spec->private_dac_nids[spec->multiout.num_dacs++] = | ||
3375 | spec->multi_io[i].dac; | ||
3376 | spec->ext_channel_count = 2; | ||
3377 | } else if (spec->multi_ios) { | ||
3378 | spec->multi_ios = 0; | ||
3379 | badness += BAD_MULTI_IO; | ||
3380 | } | ||
3381 | |||
3382 | return badness; | ||
3383 | } | ||
3384 | |||
3385 | #define DEBUG_BADNESS | ||
3386 | |||
3387 | #ifdef DEBUG_BADNESS | ||
3388 | #define debug_badness snd_printdd | ||
3389 | #else | ||
3390 | #define debug_badness(...) | ||
3391 | #endif | ||
3392 | |||
3393 | static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg) | ||
3394 | { | ||
3395 | debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n", | ||
3396 | cfg->line_out_pins[0], cfg->line_out_pins[1], | ||
3397 | cfg->line_out_pins[2], cfg->line_out_pins[2], | ||
3398 | spec->multiout.dac_nids[0], | ||
3399 | spec->multiout.dac_nids[1], | ||
3400 | spec->multiout.dac_nids[2], | ||
3401 | spec->multiout.dac_nids[3]); | ||
3402 | if (spec->multi_ios > 0) | ||
3403 | debug_badness("multi_ios(%d) = %x/%x : %x/%x\n", | ||
3404 | spec->multi_ios, | ||
3405 | spec->multi_io[0].pin, spec->multi_io[1].pin, | ||
3406 | spec->multi_io[0].dac, spec->multi_io[1].dac); | ||
3407 | debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n", | ||
3408 | cfg->hp_pins[0], cfg->hp_pins[1], | ||
3409 | cfg->hp_pins[2], cfg->hp_pins[2], | ||
3410 | spec->multiout.hp_out_nid[0], | ||
3411 | spec->multiout.hp_out_nid[1], | ||
3412 | spec->multiout.hp_out_nid[2], | ||
3413 | spec->multiout.hp_out_nid[3]); | ||
3414 | debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n", | ||
3415 | cfg->speaker_pins[0], cfg->speaker_pins[1], | ||
3416 | cfg->speaker_pins[2], cfg->speaker_pins[3], | ||
3417 | spec->multiout.extra_out_nid[0], | ||
3418 | spec->multiout.extra_out_nid[1], | ||
3419 | spec->multiout.extra_out_nid[2], | ||
3420 | spec->multiout.extra_out_nid[3]); | ||
3421 | } | ||
3422 | |||
3423 | /* find all available DACs of the codec */ | ||
3424 | static void alc_fill_all_nids(struct hda_codec *codec) | ||
3425 | { | ||
3426 | struct alc_spec *spec = codec->spec; | ||
3427 | int i; | ||
3428 | hda_nid_t nid = codec->start_nid; | ||
3429 | |||
3430 | spec->num_all_dacs = 0; | ||
3431 | memset(spec->all_dacs, 0, sizeof(spec->all_dacs)); | ||
3432 | for (i = 0; i < codec->num_nodes; i++, nid++) { | ||
3433 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT) | ||
3434 | continue; | ||
3435 | if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) { | ||
3436 | snd_printk(KERN_ERR "hda: Too many DACs!\n"); | ||
3437 | break; | ||
3438 | } | ||
3439 | spec->all_dacs[spec->num_all_dacs++] = nid; | ||
3440 | } | ||
3441 | } | ||
3442 | |||
3443 | static int alc_auto_fill_dac_nids(struct hda_codec *codec) | ||
3444 | { | ||
3445 | struct alc_spec *spec = codec->spec; | ||
3446 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
3447 | struct auto_pin_cfg *best_cfg; | ||
3448 | int best_badness = INT_MAX; | ||
3449 | int badness; | ||
3450 | bool fill_hardwired = true, fill_mio_first = true; | ||
3451 | bool best_wired = true, best_mio = true; | ||
3452 | bool hp_spk_swapped = false; | ||
3453 | |||
3454 | alc_fill_all_nids(codec); | ||
3455 | |||
3456 | best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL); | ||
3457 | if (!best_cfg) | ||
3458 | return -ENOMEM; | ||
3459 | *best_cfg = *cfg; | ||
3460 | |||
3461 | for (;;) { | ||
3462 | badness = fill_and_eval_dacs(codec, fill_hardwired, | ||
3463 | fill_mio_first); | ||
3464 | if (badness < 0) { | ||
3465 | kfree(best_cfg); | ||
3466 | return badness; | ||
3467 | } | ||
3468 | debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n", | ||
3469 | cfg->line_out_type, fill_hardwired, fill_mio_first, | ||
3470 | badness); | ||
3471 | debug_show_configs(spec, cfg); | ||
3472 | if (badness < best_badness) { | ||
3473 | best_badness = badness; | ||
3474 | *best_cfg = *cfg; | ||
3475 | best_wired = fill_hardwired; | ||
3476 | best_mio = fill_mio_first; | ||
3477 | } | ||
3478 | if (!badness) | ||
3479 | break; | ||
3480 | fill_mio_first = !fill_mio_first; | ||
3481 | if (!fill_mio_first) | ||
3482 | continue; | ||
3483 | fill_hardwired = !fill_hardwired; | ||
3484 | if (!fill_hardwired) | ||
3485 | continue; | ||
3486 | if (hp_spk_swapped) | ||
3487 | break; | ||
3488 | hp_spk_swapped = true; | ||
3489 | if (cfg->speaker_outs > 0 && | ||
3490 | cfg->line_out_type == AUTO_PIN_HP_OUT) { | ||
3491 | cfg->hp_outs = cfg->line_outs; | ||
3492 | memcpy(cfg->hp_pins, cfg->line_out_pins, | ||
3493 | sizeof(cfg->hp_pins)); | ||
3494 | cfg->line_outs = cfg->speaker_outs; | ||
3495 | memcpy(cfg->line_out_pins, cfg->speaker_pins, | ||
3496 | sizeof(cfg->speaker_pins)); | ||
3497 | cfg->speaker_outs = 0; | ||
3498 | memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins)); | ||
3499 | cfg->line_out_type = AUTO_PIN_SPEAKER_OUT; | ||
3500 | fill_hardwired = true; | ||
3501 | continue; | ||
3502 | } | ||
3503 | if (cfg->hp_outs > 0 && | ||
3504 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { | ||
3505 | cfg->speaker_outs = cfg->line_outs; | ||
3506 | memcpy(cfg->speaker_pins, cfg->line_out_pins, | ||
3507 | sizeof(cfg->speaker_pins)); | ||
3508 | cfg->line_outs = cfg->hp_outs; | ||
3509 | memcpy(cfg->line_out_pins, cfg->hp_pins, | ||
3510 | sizeof(cfg->hp_pins)); | ||
3511 | cfg->hp_outs = 0; | ||
3512 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); | ||
3513 | cfg->line_out_type = AUTO_PIN_HP_OUT; | ||
3514 | fill_hardwired = true; | ||
3515 | continue; | ||
3516 | } | ||
3517 | break; | ||
3518 | } | ||
3519 | |||
3520 | if (badness) { | ||
3521 | *cfg = *best_cfg; | ||
3522 | fill_and_eval_dacs(codec, best_wired, best_mio); | ||
3523 | } | ||
3524 | debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n", | ||
3525 | cfg->line_out_type, best_wired, best_mio); | ||
3526 | debug_show_configs(spec, cfg); | ||
3527 | |||
3528 | if (cfg->line_out_pins[0]) { | ||
3529 | struct nid_path *path = get_nid_path(codec, | ||
3530 | spec->multiout.dac_nids[0], | ||
3531 | cfg->line_out_pins[0]); | ||
3532 | if (path) | ||
3533 | spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path); | ||
3534 | } | ||
3535 | |||
3536 | kfree(best_cfg); | ||
3537 | return 0; | ||
3538 | } | ||
3539 | |||
3540 | /* replace the channels in the composed amp value with the given number */ | ||
3541 | static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs) | ||
3542 | { | ||
3543 | val &= ~(0x3U << 16); | ||
3544 | val |= chs << 16; | ||
3545 | return val; | ||
3546 | } | ||
3547 | |||
3548 | static int alc_auto_add_vol_ctl(struct hda_codec *codec, | ||
3549 | const char *pfx, int cidx, | ||
3550 | unsigned int chs, | ||
3551 | struct nid_path *path) | ||
3552 | { | ||
3553 | unsigned int val; | ||
3554 | if (!path) | ||
3555 | return 0; | ||
3556 | val = path->ctls[NID_PATH_VOL_CTL]; | ||
3557 | if (!val) | ||
3558 | return 0; | ||
3559 | val = amp_val_replace_channels(val, chs); | ||
3560 | return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val); | ||
3561 | } | ||
3562 | |||
3563 | /* return the channel bits suitable for the given path->ctls[] */ | ||
3564 | static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path, | ||
3565 | int type) | ||
3566 | { | ||
3567 | int chs = 1; /* mono (left only) */ | ||
3568 | if (path) { | ||
3569 | hda_nid_t nid = get_amp_nid_(path->ctls[type]); | ||
3570 | if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO)) | ||
3571 | chs = 3; /* stereo */ | ||
3572 | } | ||
3573 | return chs; | ||
3574 | } | ||
3575 | |||
3576 | static int alc_auto_add_stereo_vol(struct hda_codec *codec, | ||
3577 | const char *pfx, int cidx, | ||
3578 | struct nid_path *path) | ||
3579 | { | ||
3580 | int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL); | ||
3581 | return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path); | ||
3582 | } | ||
3583 | |||
3584 | /* create a mute-switch for the given mixer widget; | ||
3585 | * if it has multiple sources (e.g. DAC and loopback), create a bind-mute | ||
3586 | */ | ||
3587 | static int alc_auto_add_sw_ctl(struct hda_codec *codec, | ||
3588 | const char *pfx, int cidx, | ||
3589 | unsigned int chs, | ||
3590 | struct nid_path *path) | ||
3591 | { | ||
3592 | unsigned int val; | ||
3593 | int type = ALC_CTL_WIDGET_MUTE; | ||
3594 | |||
3595 | if (!path) | ||
3596 | return 0; | ||
3597 | val = path->ctls[NID_PATH_MUTE_CTL]; | ||
3598 | if (!val) | ||
3599 | return 0; | ||
3600 | val = amp_val_replace_channels(val, chs); | ||
3601 | if (get_amp_direction_(val) == HDA_INPUT) { | ||
3602 | hda_nid_t nid = get_amp_nid_(val); | ||
3603 | int nums = snd_hda_get_num_conns(codec, nid); | ||
3604 | if (nums > 1) { | ||
3605 | type = ALC_CTL_BIND_MUTE; | ||
3606 | val |= nums << 19; | ||
3607 | } | ||
3608 | } | ||
3609 | return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val); | ||
3610 | } | ||
3611 | |||
3612 | static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx, | ||
3613 | int cidx, struct nid_path *path) | ||
3614 | { | ||
3615 | int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL); | ||
3616 | return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path); | ||
3617 | } | ||
3618 | |||
3619 | static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec, | ||
3620 | struct nid_path *path) | ||
3621 | { | ||
3622 | int i; | ||
3623 | |||
3624 | for (i = path->depth - 1; i >= 0; i--) { | ||
3625 | if (nid_has_mute(codec, path->path[i], HDA_OUTPUT)) | ||
3626 | return path->path[i]; | ||
3627 | if (i != path->depth - 1 && i != 0 && | ||
3628 | nid_has_mute(codec, path->path[i], HDA_INPUT)) | ||
3629 | return path->path[i]; | ||
3630 | } | ||
3631 | return 0; | ||
3632 | } | ||
3633 | |||
3634 | static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec, | ||
3635 | struct nid_path *path) | ||
3636 | { | ||
3637 | int i; | ||
3638 | |||
3639 | for (i = path->depth - 1; i >= 0; i--) { | ||
3640 | if (nid_has_volume(codec, path->path[i], HDA_OUTPUT)) | ||
3641 | return path->path[i]; | ||
3642 | } | ||
3643 | return 0; | ||
3644 | } | ||
3645 | |||
3646 | /* add playback controls from the parsed DAC table */ | ||
3647 | static int alc_auto_create_multi_out_ctls(struct hda_codec *codec, | ||
3648 | const struct auto_pin_cfg *cfg) | ||
3649 | { | ||
3650 | struct alc_spec *spec = codec->spec; | ||
3651 | int i, err, noutputs; | ||
3652 | |||
3653 | noutputs = cfg->line_outs; | ||
3654 | if (spec->multi_ios > 0 && cfg->line_outs < 3) | ||
3655 | noutputs += spec->multi_ios; | ||
3656 | |||
3657 | for (i = 0; i < noutputs; i++) { | ||
3658 | const char *name; | ||
3659 | int index; | ||
3660 | hda_nid_t dac, pin; | ||
3661 | struct nid_path *path; | ||
3662 | |||
3663 | dac = spec->multiout.dac_nids[i]; | ||
3664 | if (!dac) | ||
3665 | continue; | ||
3666 | if (i >= cfg->line_outs) { | ||
3667 | pin = spec->multi_io[i - 1].pin; | ||
3668 | index = 0; | ||
3669 | name = channel_name[i]; | ||
3670 | } else { | ||
3671 | pin = cfg->line_out_pins[i]; | ||
3672 | name = alc_get_line_out_pfx(spec, i, true, &index); | ||
3673 | } | ||
3674 | |||
3675 | path = get_nid_path(codec, dac, pin); | ||
3676 | if (!path) | ||
3677 | continue; | ||
3678 | if (!name || !strcmp(name, "CLFE")) { | ||
3679 | /* Center/LFE */ | ||
3680 | err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path); | ||
3681 | if (err < 0) | ||
3682 | return err; | ||
3683 | err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path); | ||
3684 | if (err < 0) | ||
3685 | return err; | ||
3686 | err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path); | ||
3687 | if (err < 0) | ||
3688 | return err; | ||
3689 | err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path); | ||
3690 | if (err < 0) | ||
3691 | return err; | ||
3692 | } else { | ||
3693 | err = alc_auto_add_stereo_vol(codec, name, index, path); | ||
3694 | if (err < 0) | ||
3695 | return err; | ||
3696 | err = alc_auto_add_stereo_sw(codec, name, index, path); | ||
3697 | if (err < 0) | ||
3698 | return err; | ||
3699 | } | ||
3700 | } | ||
3701 | return 0; | ||
3702 | } | ||
3703 | |||
3704 | static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin, | ||
3705 | hda_nid_t dac, const char *pfx, | ||
3706 | int cidx) | ||
3707 | { | ||
3708 | struct nid_path *path; | ||
3709 | int err; | ||
3710 | |||
3711 | path = get_nid_path(codec, dac, pin); | ||
3712 | if (!path) | ||
3713 | return 0; | ||
3714 | /* bind volume control will be created in the case of dac = 0 */ | ||
3715 | if (dac) { | ||
3716 | err = alc_auto_add_stereo_vol(codec, pfx, cidx, path); | ||
3717 | if (err < 0) | ||
3718 | return err; | ||
3719 | } | ||
3720 | err = alc_auto_add_stereo_sw(codec, pfx, cidx, path); | ||
3721 | if (err < 0) | ||
3722 | return err; | ||
3723 | return 0; | ||
3724 | } | ||
3725 | |||
3726 | static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec, | ||
3727 | unsigned int nums, | ||
3728 | struct hda_ctl_ops *ops) | ||
3729 | { | ||
3730 | struct alc_spec *spec = codec->spec; | ||
3731 | struct hda_bind_ctls **ctlp, *ctl; | ||
3732 | ctlp = snd_array_new(&spec->bind_ctls); | ||
3733 | if (!ctlp) | ||
3734 | return NULL; | ||
3735 | ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL); | ||
3736 | *ctlp = ctl; | ||
3737 | if (ctl) | ||
3738 | ctl->ops = ops; | ||
3739 | return ctl; | ||
3740 | } | ||
3741 | |||
3742 | /* add playback controls for speaker and HP outputs */ | ||
3743 | static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins, | ||
3744 | const hda_nid_t *pins, | ||
3745 | const hda_nid_t *dacs, | ||
3746 | const char *pfx) | ||
3747 | { | ||
3748 | struct alc_spec *spec = codec->spec; | ||
3749 | struct hda_bind_ctls *ctl; | ||
3750 | char name[32]; | ||
3751 | int i, n, err; | ||
3752 | |||
3753 | if (!num_pins || !pins[0]) | ||
3754 | return 0; | ||
3755 | |||
3756 | if (num_pins == 1) { | ||
3757 | hda_nid_t dac = *dacs; | ||
3758 | if (!dac) | ||
3759 | dac = spec->multiout.dac_nids[0]; | ||
3760 | return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0); | ||
3761 | } | ||
3762 | |||
3763 | for (i = 0; i < num_pins; i++) { | ||
3764 | hda_nid_t dac; | ||
3765 | if (dacs[num_pins - 1]) | ||
3766 | dac = dacs[i]; /* with individual volumes */ | ||
3767 | else | ||
3768 | dac = 0; | ||
3769 | if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) { | ||
3770 | err = alc_auto_create_extra_out(codec, pins[i], dac, | ||
3771 | "Bass Speaker", 0); | ||
3772 | } else if (num_pins >= 3) { | ||
3773 | snprintf(name, sizeof(name), "%s %s", | ||
3774 | pfx, channel_name[i]); | ||
3775 | err = alc_auto_create_extra_out(codec, pins[i], dac, | ||
3776 | name, 0); | ||
3777 | } else { | ||
3778 | err = alc_auto_create_extra_out(codec, pins[i], dac, | ||
3779 | pfx, i); | ||
3780 | } | ||
3781 | if (err < 0) | ||
3782 | return err; | ||
3783 | } | ||
3784 | if (dacs[num_pins - 1]) | ||
3785 | return 0; | ||
3786 | |||
3787 | /* Let's create a bind-controls for volumes */ | ||
3788 | ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol); | ||
3789 | if (!ctl) | ||
3790 | return -ENOMEM; | ||
3791 | n = 0; | ||
3792 | for (i = 0; i < num_pins; i++) { | ||
3793 | hda_nid_t vol; | ||
3794 | struct nid_path *path; | ||
3795 | if (!pins[i] || !dacs[i]) | ||
3796 | continue; | ||
3797 | path = get_nid_path(codec, dacs[i], pins[i]); | ||
3798 | if (!path) | ||
3799 | continue; | ||
3800 | vol = alc_look_for_out_vol_nid(codec, path); | ||
3801 | if (vol) | ||
3802 | ctl->values[n++] = | ||
3803 | HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT); | ||
3804 | } | ||
3805 | if (n) { | ||
3806 | snprintf(name, sizeof(name), "%s Playback Volume", pfx); | ||
3807 | err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl); | ||
3808 | if (err < 0) | ||
3809 | return err; | ||
3810 | } | ||
3811 | return 0; | ||
3812 | } | ||
3813 | |||
3814 | static int alc_auto_create_hp_out(struct hda_codec *codec) | ||
3815 | { | ||
3816 | struct alc_spec *spec = codec->spec; | ||
3817 | return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs, | ||
3818 | spec->autocfg.hp_pins, | ||
3819 | spec->multiout.hp_out_nid, | ||
3820 | "Headphone"); | ||
3821 | } | ||
3822 | |||
3823 | static int alc_auto_create_speaker_out(struct hda_codec *codec) | ||
3824 | { | ||
3825 | struct alc_spec *spec = codec->spec; | ||
3826 | return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs, | ||
3827 | spec->autocfg.speaker_pins, | ||
3828 | spec->multiout.extra_out_nid, | ||
3829 | "Speaker"); | ||
3830 | } | ||
3831 | |||
3832 | /* check whether a control with the given (nid, dir, idx) was assigned */ | ||
3833 | static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid, | ||
3834 | int dir, int idx) | ||
3835 | { | ||
3836 | struct alc_spec *spec = codec->spec; | ||
3837 | int i, type; | ||
3838 | |||
3839 | for (i = 0; i < spec->paths.used; i++) { | ||
3840 | struct nid_path *p = snd_array_elem(&spec->paths, i); | ||
3841 | if (p->depth <= 0) | ||
3842 | continue; | ||
3843 | for (type = 0; type < NID_PATH_NUM_CTLS; type++) { | ||
3844 | unsigned int val = p->ctls[type]; | ||
3845 | if (get_amp_nid_(val) == nid && | ||
3846 | get_amp_direction_(val) == dir && | ||
3847 | get_amp_index_(val) == idx) | ||
3848 | return true; | ||
3849 | } | ||
3850 | } | ||
3851 | return false; | ||
3852 | } | ||
3853 | |||
3854 | /* can have the amp-in capability? */ | ||
3855 | static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx) | ||
3856 | { | ||
3857 | hda_nid_t nid = path->path[idx]; | ||
3858 | unsigned int caps = get_wcaps(codec, nid); | ||
3859 | unsigned int type = get_wcaps_type(caps); | ||
3860 | |||
3861 | if (!(caps & AC_WCAP_IN_AMP)) | ||
3862 | return false; | ||
3863 | if (type == AC_WID_PIN && idx > 0) /* only for input pins */ | ||
3864 | return false; | ||
3865 | return true; | ||
3866 | } | ||
3867 | |||
3868 | /* can have the amp-out capability? */ | ||
3869 | static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx) | ||
3870 | { | ||
3871 | hda_nid_t nid = path->path[idx]; | ||
3872 | unsigned int caps = get_wcaps(codec, nid); | ||
3873 | unsigned int type = get_wcaps_type(caps); | ||
3874 | |||
3875 | if (!(caps & AC_WCAP_OUT_AMP)) | ||
3876 | return false; | ||
3877 | if (type == AC_WID_PIN && !idx) /* only for output pins */ | ||
3878 | return false; | ||
3879 | return true; | ||
3880 | } | ||
3881 | |||
3882 | /* check whether the given (nid,dir,idx) is active */ | ||
3883 | static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid, | ||
3884 | unsigned int idx, unsigned int dir) | ||
3885 | { | ||
3886 | struct alc_spec *spec = codec->spec; | ||
3887 | int i, n; | ||
3888 | |||
3889 | for (n = 0; n < spec->paths.used; n++) { | ||
3890 | struct nid_path *path = snd_array_elem(&spec->paths, n); | ||
3891 | if (!path->active) | ||
3892 | continue; | ||
3893 | for (i = 0; i < path->depth; i++) { | ||
3894 | if (path->path[i] == nid) { | ||
3895 | if (dir == HDA_OUTPUT || path->idx[i] == idx) | ||
3896 | return true; | ||
3897 | break; | ||
3898 | } | ||
3899 | } | ||
3900 | } | ||
3901 | return false; | ||
3902 | } | ||
3903 | |||
3904 | /* get the default amp value for the target state */ | ||
3905 | static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid, | ||
3906 | int dir, bool enable) | ||
3907 | { | ||
3908 | unsigned int caps; | ||
3909 | unsigned int val = 0; | ||
3910 | |||
3911 | caps = query_amp_caps(codec, nid, dir); | ||
3912 | if (caps & AC_AMPCAP_NUM_STEPS) { | ||
3913 | /* set to 0dB */ | ||
3914 | if (enable) | ||
3915 | val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT; | ||
3916 | } | ||
3917 | if (caps & AC_AMPCAP_MUTE) { | ||
3918 | if (!enable) | ||
3919 | val |= HDA_AMP_MUTE; | ||
3920 | } | ||
3921 | return val; | ||
3922 | } | ||
3923 | |||
3924 | /* initialize the amp value (only at the first time) */ | ||
3925 | static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx) | ||
3926 | { | ||
3927 | int val = get_amp_val_to_activate(codec, nid, dir, false); | ||
3928 | snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val); | ||
3929 | } | ||
3930 | |||
3931 | static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir, | ||
3932 | int idx, bool enable) | ||
3933 | { | ||
3934 | int val; | ||
3935 | if (is_ctl_associated(codec, nid, dir, idx) || | ||
3936 | is_active_nid(codec, nid, dir, idx)) | ||
3937 | return; | ||
3938 | val = get_amp_val_to_activate(codec, nid, dir, enable); | ||
3939 | snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val); | ||
3940 | } | ||
3941 | |||
3942 | static void activate_amp_out(struct hda_codec *codec, struct nid_path *path, | ||
3943 | int i, bool enable) | ||
3944 | { | ||
3945 | hda_nid_t nid = path->path[i]; | ||
3946 | init_amp(codec, nid, HDA_OUTPUT, 0); | ||
3947 | activate_amp(codec, nid, HDA_OUTPUT, 0, enable); | ||
3948 | } | ||
3949 | |||
3950 | static void activate_amp_in(struct hda_codec *codec, struct nid_path *path, | ||
3951 | int i, bool enable, bool add_aamix) | ||
3952 | { | ||
3953 | struct alc_spec *spec = codec->spec; | ||
3954 | hda_nid_t conn[16]; | ||
3955 | int n, nums, idx; | ||
3956 | int type; | ||
3957 | hda_nid_t nid = path->path[i]; | ||
3958 | |||
3959 | nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn)); | ||
3960 | type = get_wcaps_type(get_wcaps(codec, nid)); | ||
3961 | if (type == AC_WID_PIN || | ||
3962 | (type == AC_WID_AUD_IN && codec->single_adc_amp)) { | ||
3963 | nums = 1; | ||
3964 | idx = 0; | ||
3965 | } else | ||
3966 | idx = path->idx[i]; | ||
3967 | |||
3968 | for (n = 0; n < nums; n++) | ||
3969 | init_amp(codec, nid, HDA_INPUT, n); | ||
3970 | |||
3971 | if (is_ctl_associated(codec, nid, HDA_INPUT, idx)) | ||
3972 | return; | ||
3973 | |||
3974 | /* here is a little bit tricky in comparison with activate_amp_out(); | ||
3975 | * when aa-mixer is available, we need to enable the path as well | ||
3976 | */ | ||
3977 | for (n = 0; n < nums; n++) { | ||
3978 | if (n != idx && (!add_aamix || conn[n] != spec->mixer_nid)) | ||
3979 | continue; | ||
3980 | activate_amp(codec, nid, HDA_INPUT, n, enable); | ||
3981 | } | ||
3982 | } | ||
3983 | |||
3984 | static void activate_path(struct hda_codec *codec, struct nid_path *path, | ||
3985 | bool enable, bool add_aamix) | ||
3986 | { | ||
3987 | int i; | ||
3988 | |||
3989 | if (!enable) | ||
3990 | path->active = false; | ||
3991 | |||
3992 | for (i = path->depth - 1; i >= 0; i--) { | ||
3993 | if (enable && path->multi[i]) | ||
3994 | snd_hda_codec_write_cache(codec, path->path[i], 0, | ||
3995 | AC_VERB_SET_CONNECT_SEL, | ||
3996 | path->idx[i]); | ||
3997 | if (has_amp_in(codec, path, i)) | ||
3998 | activate_amp_in(codec, path, i, enable, add_aamix); | ||
3999 | if (has_amp_out(codec, path, i)) | ||
4000 | activate_amp_out(codec, path, i, enable); | ||
4001 | } | ||
4002 | |||
4003 | if (enable) | ||
4004 | path->active = true; | ||
4005 | } | ||
4006 | |||
4007 | /* configure the path from the given dac to the pin as the proper output */ | ||
4008 | static void alc_auto_set_output_and_unmute(struct hda_codec *codec, | ||
4009 | hda_nid_t pin, int pin_type, | ||
4010 | hda_nid_t dac) | ||
4011 | { | ||
4012 | struct nid_path *path; | ||
4013 | |||
4014 | snd_hda_set_pin_ctl_cache(codec, pin, pin_type); | ||
4015 | path = get_nid_path(codec, dac, pin); | ||
4016 | if (!path) | ||
4017 | return; | ||
4018 | if (path->active) | ||
4019 | return; | ||
4020 | activate_path(codec, path, true, true); | ||
4021 | } | ||
4022 | |||
4023 | static void alc_auto_init_multi_out(struct hda_codec *codec) | ||
4024 | { | ||
4025 | struct alc_spec *spec = codec->spec; | ||
4026 | int pin_type = get_pin_type(spec->autocfg.line_out_type); | ||
4027 | int i; | ||
4028 | |||
4029 | for (i = 0; i <= HDA_SIDE; i++) { | ||
4030 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; | ||
4031 | if (nid) | ||
4032 | alc_auto_set_output_and_unmute(codec, nid, pin_type, | ||
4033 | spec->multiout.dac_nids[i]); | ||
4034 | |||
4035 | } | ||
4036 | } | ||
4037 | |||
4038 | static void alc_auto_init_extra_out(struct hda_codec *codec) | ||
4039 | { | ||
4040 | struct alc_spec *spec = codec->spec; | ||
4041 | int i; | ||
4042 | hda_nid_t pin, dac; | ||
4043 | |||
4044 | for (i = 0; i < spec->autocfg.hp_outs; i++) { | ||
4045 | if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT) | ||
4046 | break; | ||
4047 | pin = spec->autocfg.hp_pins[i]; | ||
4048 | if (!pin) | ||
4049 | break; | ||
4050 | dac = spec->multiout.hp_out_nid[i]; | ||
4051 | if (!dac) { | ||
4052 | if (i > 0 && spec->multiout.hp_out_nid[0]) | ||
4053 | dac = spec->multiout.hp_out_nid[0]; | ||
4054 | else | ||
4055 | dac = spec->multiout.dac_nids[0]; | ||
4056 | } | ||
4057 | alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac); | ||
4058 | } | ||
4059 | for (i = 0; i < spec->autocfg.speaker_outs; i++) { | ||
4060 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) | ||
4061 | break; | ||
4062 | pin = spec->autocfg.speaker_pins[i]; | ||
4063 | if (!pin) | ||
4064 | break; | ||
4065 | dac = spec->multiout.extra_out_nid[i]; | ||
4066 | if (!dac) { | ||
4067 | if (i > 0 && spec->multiout.extra_out_nid[0]) | ||
4068 | dac = spec->multiout.extra_out_nid[0]; | ||
4069 | else | ||
4070 | dac = spec->multiout.dac_nids[0]; | ||
4071 | } | ||
4072 | alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac); | ||
4073 | } | ||
4074 | } | ||
4075 | |||
4076 | /* check whether the given pin can be a multi-io pin */ | ||
4077 | static bool can_be_multiio_pin(struct hda_codec *codec, | ||
4078 | unsigned int location, hda_nid_t nid) | ||
4079 | { | ||
4080 | unsigned int defcfg, caps; | ||
4081 | |||
4082 | defcfg = snd_hda_codec_get_pincfg(codec, nid); | ||
4083 | if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX) | ||
4084 | return false; | ||
4085 | if (location && get_defcfg_location(defcfg) != location) | ||
4086 | return false; | ||
4087 | caps = snd_hda_query_pin_caps(codec, nid); | ||
4088 | if (!(caps & AC_PINCAP_OUT)) | ||
4089 | return false; | ||
4090 | return true; | ||
4091 | } | ||
4092 | |||
4093 | /* | ||
4094 | * multi-io helper | ||
4095 | * | ||
4096 | * When hardwired is set, try to fill ony hardwired pins, and returns | ||
4097 | * zero if any pins are filled, non-zero if nothing found. | ||
4098 | * When hardwired is off, try to fill possible input pins, and returns | ||
4099 | * the badness value. | ||
4100 | */ | ||
4101 | static int alc_auto_fill_multi_ios(struct hda_codec *codec, | ||
4102 | hda_nid_t reference_pin, | ||
4103 | bool hardwired, int offset) | ||
4104 | { | ||
4105 | struct alc_spec *spec = codec->spec; | ||
4106 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
4107 | int type, i, j, dacs, num_pins, old_pins; | ||
4108 | unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin); | ||
4109 | unsigned int location = get_defcfg_location(defcfg); | ||
4110 | int badness = 0; | ||
4111 | |||
4112 | old_pins = spec->multi_ios; | ||
4113 | if (old_pins >= 2) | ||
4114 | goto end_fill; | ||
4115 | |||
4116 | num_pins = 0; | ||
4117 | for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { | ||
4118 | for (i = 0; i < cfg->num_inputs; i++) { | ||
4119 | if (cfg->inputs[i].type != type) | ||
4120 | continue; | ||
4121 | if (can_be_multiio_pin(codec, location, | ||
4122 | cfg->inputs[i].pin)) | ||
4123 | num_pins++; | ||
4124 | } | ||
4125 | } | ||
4126 | if (num_pins < 2) | ||
4127 | goto end_fill; | ||
4128 | |||
4129 | dacs = spec->multiout.num_dacs; | ||
4130 | for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { | ||
4131 | for (i = 0; i < cfg->num_inputs; i++) { | ||
4132 | hda_nid_t nid = cfg->inputs[i].pin; | ||
4133 | hda_nid_t dac = 0; | ||
4134 | |||
4135 | if (cfg->inputs[i].type != type) | ||
4136 | continue; | ||
4137 | if (!can_be_multiio_pin(codec, location, nid)) | ||
4138 | continue; | ||
4139 | for (j = 0; j < spec->multi_ios; j++) { | ||
4140 | if (nid == spec->multi_io[j].pin) | ||
4141 | break; | ||
4142 | } | ||
4143 | if (j < spec->multi_ios) | ||
4144 | continue; | ||
4145 | |||
4146 | if (offset && offset + spec->multi_ios < dacs) { | ||
4147 | dac = spec->private_dac_nids[offset + spec->multi_ios]; | ||
4148 | if (!is_reachable_path(codec, dac, nid)) | ||
4149 | dac = 0; | ||
4150 | } | ||
4151 | if (hardwired) | ||
4152 | dac = get_dac_if_single(codec, nid); | ||
4153 | else if (!dac) | ||
4154 | dac = alc_auto_look_for_dac(codec, nid, false); | ||
4155 | if (!dac) { | ||
4156 | badness++; | ||
4157 | continue; | ||
4158 | } | ||
4159 | if (!add_new_nid_path(codec, dac, nid, 0)) { | ||
4160 | badness++; | ||
4161 | continue; | ||
4162 | } | ||
4163 | spec->multi_io[spec->multi_ios].pin = nid; | ||
4164 | spec->multi_io[spec->multi_ios].dac = dac; | ||
4165 | spec->multi_ios++; | ||
4166 | if (spec->multi_ios >= 2) | ||
4167 | break; | ||
4168 | } | ||
4169 | } | ||
4170 | end_fill: | ||
4171 | if (badness) | ||
4172 | badness = BAD_MULTI_IO; | ||
4173 | if (old_pins == spec->multi_ios) { | ||
4174 | if (hardwired) | ||
4175 | return 1; /* nothing found */ | ||
4176 | else | ||
4177 | return badness; /* no badness if nothing found */ | ||
4178 | } | ||
4179 | if (!hardwired && spec->multi_ios < 2) { | ||
4180 | /* cancel newly assigned paths */ | ||
4181 | spec->paths.used -= spec->multi_ios - old_pins; | ||
4182 | spec->multi_ios = old_pins; | ||
4183 | return badness; | ||
4184 | } | ||
4185 | |||
4186 | /* assign volume and mute controls */ | ||
4187 | for (i = old_pins; i < spec->multi_ios; i++) | ||
4188 | badness += assign_out_path_ctls(codec, spec->multi_io[i].pin, | ||
4189 | spec->multi_io[i].dac); | ||
4190 | |||
4191 | return badness; | ||
4192 | } | ||
4193 | |||
4194 | static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol, | ||
4195 | struct snd_ctl_elem_info *uinfo) | ||
4196 | { | ||
4197 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
4198 | struct alc_spec *spec = codec->spec; | ||
4199 | |||
4200 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
4201 | uinfo->count = 1; | ||
4202 | uinfo->value.enumerated.items = spec->multi_ios + 1; | ||
4203 | if (uinfo->value.enumerated.item > spec->multi_ios) | ||
4204 | uinfo->value.enumerated.item = spec->multi_ios; | ||
4205 | sprintf(uinfo->value.enumerated.name, "%dch", | ||
4206 | (uinfo->value.enumerated.item + 1) * 2); | ||
4207 | return 0; | ||
4208 | } | ||
4209 | |||
4210 | static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol, | ||
4211 | struct snd_ctl_elem_value *ucontrol) | ||
4212 | { | ||
4213 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
4214 | struct alc_spec *spec = codec->spec; | ||
4215 | ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2; | ||
4216 | return 0; | ||
4217 | } | ||
4218 | |||
4219 | static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output) | ||
4220 | { | ||
4221 | struct alc_spec *spec = codec->spec; | ||
4222 | hda_nid_t nid = spec->multi_io[idx].pin; | ||
4223 | struct nid_path *path; | ||
4224 | |||
4225 | path = get_nid_path(codec, spec->multi_io[idx].dac, nid); | ||
4226 | if (!path) | ||
4227 | return -EINVAL; | ||
4228 | |||
4229 | if (path->active == output) | ||
4230 | return 0; | ||
4231 | |||
4232 | if (output) { | ||
4233 | snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT); | ||
4234 | activate_path(codec, path, true, true); | ||
4235 | } else { | ||
4236 | activate_path(codec, path, false, true); | ||
4237 | snd_hda_set_pin_ctl_cache(codec, nid, | ||
4238 | spec->multi_io[idx].ctl_in); | ||
4239 | } | ||
4240 | return 0; | ||
4241 | } | ||
4242 | |||
4243 | static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol, | ||
4244 | struct snd_ctl_elem_value *ucontrol) | ||
4245 | { | ||
4246 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
4247 | struct alc_spec *spec = codec->spec; | ||
4248 | int i, ch; | ||
4249 | |||
4250 | ch = ucontrol->value.enumerated.item[0]; | ||
4251 | if (ch < 0 || ch > spec->multi_ios) | ||
4252 | return -EINVAL; | ||
4253 | if (ch == (spec->ext_channel_count - 1) / 2) | ||
4254 | return 0; | ||
4255 | spec->ext_channel_count = (ch + 1) * 2; | ||
4256 | for (i = 0; i < spec->multi_ios; i++) | ||
4257 | alc_set_multi_io(codec, i, i < ch); | ||
4258 | spec->multiout.max_channels = max(spec->ext_channel_count, | ||
4259 | spec->const_channel_count); | ||
4260 | if (spec->need_dac_fix) | ||
4261 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; | ||
4262 | return 1; | ||
4263 | } | ||
4264 | |||
4265 | static const struct snd_kcontrol_new alc_auto_channel_mode_enum = { | ||
4266 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
4267 | .name = "Channel Mode", | ||
4268 | .info = alc_auto_ch_mode_info, | ||
4269 | .get = alc_auto_ch_mode_get, | ||
4270 | .put = alc_auto_ch_mode_put, | ||
4271 | }; | ||
4272 | |||
4273 | static int alc_auto_add_multi_channel_mode(struct hda_codec *codec) | ||
4274 | { | ||
4275 | struct alc_spec *spec = codec->spec; | ||
4276 | |||
4277 | if (spec->multi_ios > 0) { | ||
4278 | if (!alc_kcontrol_new(spec, NULL, &alc_auto_channel_mode_enum)) | ||
4279 | return -ENOMEM; | ||
4280 | } | ||
4281 | return 0; | ||
4282 | } | ||
4283 | |||
4284 | static void alc_auto_init_multi_io(struct hda_codec *codec) | ||
4285 | { | ||
4286 | struct alc_spec *spec = codec->spec; | ||
4287 | int i; | ||
4288 | |||
4289 | for (i = 0; i < spec->multi_ios; i++) { | ||
4290 | hda_nid_t pin = spec->multi_io[i].pin; | ||
4291 | struct nid_path *path; | ||
4292 | path = get_nid_path(codec, spec->multi_io[i].dac, pin); | ||
4293 | if (!path) | ||
4294 | continue; | ||
4295 | if (!spec->multi_io[i].ctl_in) | ||
4296 | spec->multi_io[i].ctl_in = | ||
4297 | snd_hda_codec_update_cache(codec, pin, 0, | ||
4298 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | ||
4299 | activate_path(codec, path, path->active, true); | ||
4300 | } | ||
4301 | } | ||
4302 | |||
4303 | /* | ||
4304 | * initialize ADC paths | ||
4305 | */ | ||
4306 | static void alc_auto_init_input_src(struct hda_codec *codec) | ||
4307 | { | ||
4308 | struct alc_spec *spec = codec->spec; | ||
4309 | struct hda_input_mux *imux = &spec->input_mux; | ||
4310 | struct nid_path *path; | ||
4311 | int i, c, nums; | ||
4312 | |||
4313 | if (spec->dyn_adc_switch) | ||
4314 | nums = 1; | ||
4315 | else | ||
4316 | nums = spec->num_adc_nids; | ||
4317 | |||
4318 | for (c = 0; c < nums; c++) { | ||
4319 | for (i = 0; i < imux->num_items; i++) { | ||
4320 | path = get_nid_path(codec, spec->imux_pins[i], | ||
4321 | get_adc_nid(codec, c, i)); | ||
4322 | if (path) { | ||
4323 | bool active = path->active; | ||
4324 | if (i == spec->cur_mux[c]) | ||
4325 | active = true; | ||
4326 | activate_path(codec, path, active, false); | ||
4327 | } | ||
4328 | } | ||
4329 | } | ||
4330 | |||
4331 | alc_inv_dmic_sync(codec, true); | ||
4332 | if (spec->shared_mic_hp) | ||
4333 | update_shared_mic_hp(codec, spec->cur_mux[0]); | ||
4334 | } | ||
4335 | |||
4336 | /* add mic boosts if needed */ | ||
4337 | static int alc_auto_add_mic_boost(struct hda_codec *codec) | ||
4338 | { | ||
4339 | struct alc_spec *spec = codec->spec; | ||
4340 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
4341 | int i, err; | ||
4342 | int type_idx = 0; | ||
4343 | hda_nid_t nid; | ||
4344 | const char *prev_label = NULL; | ||
4345 | |||
4346 | for (i = 0; i < cfg->num_inputs; i++) { | ||
4347 | if (cfg->inputs[i].type > AUTO_PIN_MIC) | ||
4348 | break; | ||
4349 | nid = cfg->inputs[i].pin; | ||
4350 | if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { | ||
4351 | const char *label; | ||
4352 | char boost_label[32]; | ||
4353 | struct nid_path *path; | ||
4354 | unsigned int val; | ||
4355 | |||
4356 | label = hda_get_autocfg_input_label(codec, cfg, i); | ||
4357 | if (spec->shared_mic_hp && !strcmp(label, "Misc")) | ||
4358 | label = "Headphone Mic"; | ||
4359 | if (prev_label && !strcmp(label, prev_label)) | ||
4360 | type_idx++; | ||
4361 | else | ||
4362 | type_idx = 0; | ||
4363 | prev_label = label; | ||
4364 | |||
4365 | snprintf(boost_label, sizeof(boost_label), | ||
4366 | "%s Boost Volume", label); | ||
4367 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT); | ||
4368 | err = add_control(spec, ALC_CTL_WIDGET_VOL, | ||
4369 | boost_label, type_idx, val); | ||
4370 | if (err < 0) | ||
4371 | return err; | ||
4372 | |||
4373 | path = get_nid_path(codec, nid, 0); | ||
4374 | if (path) | ||
4375 | path->ctls[NID_PATH_BOOST_CTL] = val; | ||
4376 | } | ||
4377 | } | ||
4378 | return 0; | ||
4379 | } | ||
4380 | |||
4381 | /* | ||
4382 | * standard auto-parser initializations | ||
4383 | */ | ||
4384 | static void alc_auto_init_std(struct hda_codec *codec) | ||
4385 | { | ||
4386 | alc_auto_init_multi_out(codec); | ||
4387 | alc_auto_init_extra_out(codec); | ||
4388 | alc_auto_init_multi_io(codec); | ||
4389 | alc_auto_init_analog_input(codec); | ||
4390 | alc_auto_init_input_src(codec); | ||
4391 | alc_auto_init_digital(codec); | ||
4392 | /* call init functions of standard auto-mute helpers */ | ||
4393 | alc_hp_automute(codec, NULL); | ||
4394 | alc_line_automute(codec, NULL); | ||
4395 | alc_mic_automute(codec, NULL); | ||
4396 | } | ||
4397 | 939 | ||
4398 | /* | 940 | /* |
4399 | * Digital-beep handlers | 941 | * Digital-beep handlers |
@@ -4436,102 +978,20 @@ static int alc_parse_auto_config(struct hda_codec *codec, | |||
4436 | const hda_nid_t *ssid_nids) | 978 | const hda_nid_t *ssid_nids) |
4437 | { | 979 | { |
4438 | struct alc_spec *spec = codec->spec; | 980 | struct alc_spec *spec = codec->spec; |
4439 | struct auto_pin_cfg *cfg = &spec->autocfg; | 981 | struct auto_pin_cfg *cfg = &spec->gen.autocfg; |
4440 | int err; | 982 | int err; |
4441 | 983 | ||
4442 | err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids, | 984 | err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids, |
4443 | spec->parse_flags); | 985 | spec->parse_flags); |
4444 | if (err < 0) | 986 | if (err < 0) |
4445 | return err; | 987 | return err; |
4446 | if (!cfg->line_outs) { | ||
4447 | if (cfg->dig_outs || cfg->dig_in_pin) { | ||
4448 | spec->multiout.max_channels = 2; | ||
4449 | spec->no_analog = 1; | ||
4450 | goto dig_only; | ||
4451 | } | ||
4452 | return 0; /* can't find valid BIOS pin config */ | ||
4453 | } | ||
4454 | |||
4455 | if (!spec->no_primary_hp && | ||
4456 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && | ||
4457 | cfg->line_outs <= cfg->hp_outs) { | ||
4458 | /* use HP as primary out */ | ||
4459 | cfg->speaker_outs = cfg->line_outs; | ||
4460 | memcpy(cfg->speaker_pins, cfg->line_out_pins, | ||
4461 | sizeof(cfg->speaker_pins)); | ||
4462 | cfg->line_outs = cfg->hp_outs; | ||
4463 | memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins)); | ||
4464 | cfg->hp_outs = 0; | ||
4465 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); | ||
4466 | cfg->line_out_type = AUTO_PIN_HP_OUT; | ||
4467 | } | ||
4468 | |||
4469 | err = alc_auto_fill_dac_nids(codec); | ||
4470 | if (err < 0) | ||
4471 | return err; | ||
4472 | err = alc_auto_add_multi_channel_mode(codec); | ||
4473 | if (err < 0) | ||
4474 | return err; | ||
4475 | err = alc_auto_create_multi_out_ctls(codec, cfg); | ||
4476 | if (err < 0) | ||
4477 | return err; | ||
4478 | err = alc_auto_create_hp_out(codec); | ||
4479 | if (err < 0) | ||
4480 | return err; | ||
4481 | err = alc_auto_create_speaker_out(codec); | ||
4482 | if (err < 0) | ||
4483 | return err; | ||
4484 | err = alc_auto_create_shared_input(codec); | ||
4485 | if (err < 0) | ||
4486 | return err; | ||
4487 | err = alc_auto_create_input_ctls(codec); | ||
4488 | if (err < 0) | ||
4489 | return err; | ||
4490 | |||
4491 | /* check the multiple speaker pins */ | ||
4492 | if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) | ||
4493 | spec->const_channel_count = cfg->line_outs * 2; | ||
4494 | else | ||
4495 | spec->const_channel_count = cfg->speaker_outs * 2; | ||
4496 | |||
4497 | if (spec->multi_ios > 0) | ||
4498 | spec->multiout.max_channels = max(spec->ext_channel_count, | ||
4499 | spec->const_channel_count); | ||
4500 | else | ||
4501 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | ||
4502 | |||
4503 | dig_only: | ||
4504 | alc_auto_parse_digital(codec); | ||
4505 | 988 | ||
4506 | if (ssid_nids) | 989 | if (ssid_nids) |
4507 | alc_ssid_check(codec, ssid_nids); | 990 | alc_ssid_check(codec, ssid_nids); |
4508 | 991 | ||
4509 | if (!spec->no_analog) { | 992 | err = snd_hda_gen_parse_auto_config(codec, cfg); |
4510 | err = alc_init_automute(codec); | 993 | if (err < 0) |
4511 | if (err < 0) | 994 | return err; |
4512 | return err; | ||
4513 | |||
4514 | err = check_dyn_adc_switch(codec); | ||
4515 | if (err < 0) | ||
4516 | return err; | ||
4517 | |||
4518 | if (!spec->shared_mic_hp) { | ||
4519 | err = alc_init_auto_mic(codec); | ||
4520 | if (err < 0) | ||
4521 | return err; | ||
4522 | } | ||
4523 | |||
4524 | err = create_capture_mixers(codec); | ||
4525 | if (err < 0) | ||
4526 | return err; | ||
4527 | |||
4528 | err = alc_auto_add_mic_boost(codec); | ||
4529 | if (err < 0) | ||
4530 | return err; | ||
4531 | } | ||
4532 | |||
4533 | if (spec->kctls.list) | ||
4534 | add_mixer(spec, spec->kctls.list); | ||
4535 | 995 | ||
4536 | return 1; | 996 | return 1; |
4537 | } | 997 | } |
@@ -4545,11 +1005,12 @@ static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid) | |||
4545 | if (!spec) | 1005 | if (!spec) |
4546 | return -ENOMEM; | 1006 | return -ENOMEM; |
4547 | codec->spec = spec; | 1007 | codec->spec = spec; |
1008 | snd_hda_gen_spec_init(&spec->gen); | ||
1009 | spec->gen.mixer_nid = mixer_nid; | ||
1010 | spec->gen.own_eapd_ctl = 1; | ||
4548 | codec->single_adc_amp = 1; | 1011 | codec->single_adc_amp = 1; |
4549 | spec->mixer_nid = mixer_nid; | 1012 | /* FIXME: do we need this for all Realtek codec models? */ |
4550 | snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32); | 1013 | codec->spdif_status_reset = 1; |
4551 | snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8); | ||
4552 | snd_array_init(&spec->paths, sizeof(struct nid_path), 8); | ||
4553 | 1014 | ||
4554 | err = alc_codec_rename_from_preset(codec); | 1015 | err = alc_codec_rename_from_preset(codec); |
4555 | if (err < 0) { | 1016 | if (err < 0) { |
@@ -4945,7 +1406,7 @@ static int patch_alc880(struct hda_codec *codec) | |||
4945 | return err; | 1406 | return err; |
4946 | 1407 | ||
4947 | spec = codec->spec; | 1408 | spec = codec->spec; |
4948 | spec->need_dac_fix = 1; | 1409 | spec->gen.need_dac_fix = 1; |
4949 | 1410 | ||
4950 | alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl, | 1411 | alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl, |
4951 | alc880_fixups); | 1412 | alc880_fixups); |
@@ -4956,7 +1417,7 @@ static int patch_alc880(struct hda_codec *codec) | |||
4956 | if (err < 0) | 1417 | if (err < 0) |
4957 | goto error; | 1418 | goto error; |
4958 | 1419 | ||
4959 | if (!spec->no_analog) { | 1420 | if (!spec->gen.no_analog) { |
4960 | err = snd_hda_attach_beep_device(codec, 0x1); | 1421 | err = snd_hda_attach_beep_device(codec, 0x1); |
4961 | if (err < 0) | 1422 | if (err < 0) |
4962 | goto error; | 1423 | goto error; |
@@ -5005,7 +1466,7 @@ static void alc260_gpio1_automute(struct hda_codec *codec) | |||
5005 | { | 1466 | { |
5006 | struct alc_spec *spec = codec->spec; | 1467 | struct alc_spec *spec = codec->spec; |
5007 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, | 1468 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, |
5008 | spec->hp_jack_present); | 1469 | spec->gen.hp_jack_present); |
5009 | } | 1470 | } |
5010 | 1471 | ||
5011 | static void alc260_fixup_gpio1_toggle(struct hda_codec *codec, | 1472 | static void alc260_fixup_gpio1_toggle(struct hda_codec *codec, |
@@ -5016,12 +1477,12 @@ static void alc260_fixup_gpio1_toggle(struct hda_codec *codec, | |||
5016 | /* although the machine has only one output pin, we need to | 1477 | /* although the machine has only one output pin, we need to |
5017 | * toggle GPIO1 according to the jack state | 1478 | * toggle GPIO1 according to the jack state |
5018 | */ | 1479 | */ |
5019 | spec->automute_hook = alc260_gpio1_automute; | 1480 | spec->gen.automute_hook = alc260_gpio1_automute; |
5020 | spec->detect_hp = 1; | 1481 | spec->gen.detect_hp = 1; |
5021 | spec->automute_speaker = 1; | 1482 | spec->gen.automute_speaker = 1; |
5022 | spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */ | 1483 | spec->gen.autocfg.hp_pins[0] = 0x0f; /* copy it for automute */ |
5023 | snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT, | 1484 | snd_hda_jack_detect_enable_callback(codec, 0x0f, HDA_GEN_HP_EVENT, |
5024 | alc_hp_automute); | 1485 | snd_hda_gen_hp_automute); |
5025 | snd_hda_add_verbs(codec, alc_gpio1_init_verbs); | 1486 | snd_hda_add_verbs(codec, alc_gpio1_init_verbs); |
5026 | } | 1487 | } |
5027 | } | 1488 | } |
@@ -5147,7 +1608,7 @@ static int patch_alc260(struct hda_codec *codec) | |||
5147 | if (err < 0) | 1608 | if (err < 0) |
5148 | goto error; | 1609 | goto error; |
5149 | 1610 | ||
5150 | if (!spec->no_analog) { | 1611 | if (!spec->gen.no_analog) { |
5151 | err = snd_hda_attach_beep_device(codec, 0x1); | 1612 | err = snd_hda_attach_beep_device(codec, 0x1); |
5152 | if (err < 0) | 1613 | if (err < 0) |
5153 | goto error; | 1614 | goto error; |
@@ -5304,7 +1765,7 @@ static void alc889_fixup_mbp_vref(struct hda_codec *codec, | |||
5304 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | 1765 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
5305 | val |= AC_PINCTL_VREF_80; | 1766 | val |= AC_PINCTL_VREF_80; |
5306 | snd_hda_set_pin_ctl(codec, nids[i], val); | 1767 | snd_hda_set_pin_ctl(codec, nids[i], val); |
5307 | spec->keep_vref_in_automute = 1; | 1768 | spec->gen.keep_vref_in_automute = 1; |
5308 | break; | 1769 | break; |
5309 | } | 1770 | } |
5310 | } | 1771 | } |
@@ -5326,7 +1787,7 @@ static void alc889_fixup_imac91_vref(struct hda_codec *codec, | |||
5326 | val |= AC_PINCTL_VREF_50; | 1787 | val |= AC_PINCTL_VREF_50; |
5327 | snd_hda_set_pin_ctl(codec, nids[i], val); | 1788 | snd_hda_set_pin_ctl(codec, nids[i], val); |
5328 | } | 1789 | } |
5329 | spec->keep_vref_in_automute = 1; | 1790 | spec->gen.keep_vref_in_automute = 1; |
5330 | } | 1791 | } |
5331 | 1792 | ||
5332 | /* Don't take HP output as primary | 1793 | /* Don't take HP output as primary |
@@ -5337,7 +1798,7 @@ static void alc882_fixup_no_primary_hp(struct hda_codec *codec, | |||
5337 | { | 1798 | { |
5338 | struct alc_spec *spec = codec->spec; | 1799 | struct alc_spec *spec = codec->spec; |
5339 | if (action == ALC_FIXUP_ACT_PRE_PROBE) | 1800 | if (action == ALC_FIXUP_ACT_PRE_PROBE) |
5340 | spec->no_primary_hp = 1; | 1801 | spec->gen.no_primary_hp = 1; |
5341 | } | 1802 | } |
5342 | 1803 | ||
5343 | static const struct alc_fixup alc882_fixups[] = { | 1804 | static const struct alc_fixup alc882_fixups[] = { |
@@ -5656,7 +2117,7 @@ static int patch_alc882(struct hda_codec *codec) | |||
5656 | if (err < 0) | 2117 | if (err < 0) |
5657 | goto error; | 2118 | goto error; |
5658 | 2119 | ||
5659 | if (!spec->no_analog && has_cdefine_beep(codec)) { | 2120 | if (!spec->gen.no_analog && has_cdefine_beep(codec)) { |
5660 | err = snd_hda_attach_beep_device(codec, 0x1); | 2121 | err = snd_hda_attach_beep_device(codec, 0x1); |
5661 | if (err < 0) | 2122 | if (err < 0) |
5662 | goto error; | 2123 | goto error; |
@@ -5782,7 +2243,7 @@ static int patch_alc262(struct hda_codec *codec) | |||
5782 | return err; | 2243 | return err; |
5783 | 2244 | ||
5784 | spec = codec->spec; | 2245 | spec = codec->spec; |
5785 | spec->shared_mic_vref_pin = 0x18; | 2246 | spec->gen.shared_mic_vref_pin = 0x18; |
5786 | 2247 | ||
5787 | #if 0 | 2248 | #if 0 |
5788 | /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is | 2249 | /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is |
@@ -5809,7 +2270,7 @@ static int patch_alc262(struct hda_codec *codec) | |||
5809 | if (err < 0) | 2270 | if (err < 0) |
5810 | goto error; | 2271 | goto error; |
5811 | 2272 | ||
5812 | if (!spec->no_analog && has_cdefine_beep(codec)) { | 2273 | if (!spec->gen.no_analog && has_cdefine_beep(codec)) { |
5813 | err = snd_hda_attach_beep_device(codec, 0x1); | 2274 | err = snd_hda_attach_beep_device(codec, 0x1); |
5814 | if (err < 0) | 2275 | if (err < 0) |
5815 | goto error; | 2276 | goto error; |
@@ -5897,7 +2358,8 @@ static int alc268_parse_auto_config(struct hda_codec *codec) | |||
5897 | struct alc_spec *spec = codec->spec; | 2358 | struct alc_spec *spec = codec->spec; |
5898 | int err = alc_parse_auto_config(codec, NULL, alc268_ssids); | 2359 | int err = alc_parse_auto_config(codec, NULL, alc268_ssids); |
5899 | if (err > 0) { | 2360 | if (err > 0) { |
5900 | if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) { | 2361 | if (!spec->gen.no_analog && |
2362 | spec->gen.autocfg.speaker_pins[0] != 0x1d) { | ||
5901 | add_mixer(spec, alc268_beep_mixer); | 2363 | add_mixer(spec, alc268_beep_mixer); |
5902 | snd_hda_add_verbs(codec, alc268_beep_init_verbs); | 2364 | snd_hda_add_verbs(codec, alc268_beep_init_verbs); |
5903 | } | 2365 | } |
@@ -5963,6 +2425,35 @@ static int patch_alc268(struct hda_codec *codec) | |||
5963 | /* | 2425 | /* |
5964 | * ALC269 | 2426 | * ALC269 |
5965 | */ | 2427 | */ |
2428 | |||
2429 | static int playback_pcm_open(struct hda_pcm_stream *hinfo, | ||
2430 | struct hda_codec *codec, | ||
2431 | struct snd_pcm_substream *substream) | ||
2432 | { | ||
2433 | struct hda_gen_spec *spec = codec->spec; | ||
2434 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, | ||
2435 | hinfo); | ||
2436 | } | ||
2437 | |||
2438 | static int playback_pcm_prepare(struct hda_pcm_stream *hinfo, | ||
2439 | struct hda_codec *codec, | ||
2440 | unsigned int stream_tag, | ||
2441 | unsigned int format, | ||
2442 | struct snd_pcm_substream *substream) | ||
2443 | { | ||
2444 | struct hda_gen_spec *spec = codec->spec; | ||
2445 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, | ||
2446 | stream_tag, format, substream); | ||
2447 | } | ||
2448 | |||
2449 | static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | ||
2450 | struct hda_codec *codec, | ||
2451 | struct snd_pcm_substream *substream) | ||
2452 | { | ||
2453 | struct hda_gen_spec *spec = codec->spec; | ||
2454 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | ||
2455 | } | ||
2456 | |||
5966 | static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { | 2457 | static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { |
5967 | .substreams = 1, | 2458 | .substreams = 1, |
5968 | .channels_min = 2, | 2459 | .channels_min = 2, |
@@ -5970,9 +2461,9 @@ static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { | |||
5970 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ | 2461 | .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ |
5971 | /* NID is set in alc_build_pcms */ | 2462 | /* NID is set in alc_build_pcms */ |
5972 | .ops = { | 2463 | .ops = { |
5973 | .open = alc_playback_pcm_open, | 2464 | .open = playback_pcm_open, |
5974 | .prepare = alc_playback_pcm_prepare, | 2465 | .prepare = playback_pcm_prepare, |
5975 | .cleanup = alc_playback_pcm_cleanup | 2466 | .cleanup = playback_pcm_cleanup |
5976 | }, | 2467 | }, |
5977 | }; | 2468 | }; |
5978 | 2469 | ||
@@ -6127,8 +2618,8 @@ static void alc269_fixup_pcm_44k(struct hda_codec *codec, | |||
6127 | /* Due to a hardware problem on Lenovo Ideadpad, we need to | 2618 | /* Due to a hardware problem on Lenovo Ideadpad, we need to |
6128 | * fix the sample rate of analog I/O to 44.1kHz | 2619 | * fix the sample rate of analog I/O to 44.1kHz |
6129 | */ | 2620 | */ |
6130 | spec->stream_analog_playback = &alc269_44k_pcm_analog_playback; | 2621 | spec->gen.stream_analog_playback = &alc269_44k_pcm_analog_playback; |
6131 | spec->stream_analog_capture = &alc269_44k_pcm_analog_capture; | 2622 | spec->gen.stream_analog_capture = &alc269_44k_pcm_analog_capture; |
6132 | } | 2623 | } |
6133 | 2624 | ||
6134 | static void alc269_fixup_stereo_dmic(struct hda_codec *codec, | 2625 | static void alc269_fixup_stereo_dmic(struct hda_codec *codec, |
@@ -6149,7 +2640,7 @@ static void alc269_fixup_stereo_dmic(struct hda_codec *codec, | |||
6149 | 2640 | ||
6150 | static void alc269_quanta_automute(struct hda_codec *codec) | 2641 | static void alc269_quanta_automute(struct hda_codec *codec) |
6151 | { | 2642 | { |
6152 | update_outputs(codec); | 2643 | snd_hda_gen_update_outputs(codec); |
6153 | 2644 | ||
6154 | snd_hda_codec_write(codec, 0x20, 0, | 2645 | snd_hda_codec_write(codec, 0x20, 0, |
6155 | AC_VERB_SET_COEF_INDEX, 0x0c); | 2646 | AC_VERB_SET_COEF_INDEX, 0x0c); |
@@ -6168,7 +2659,7 @@ static void alc269_fixup_quanta_mute(struct hda_codec *codec, | |||
6168 | struct alc_spec *spec = codec->spec; | 2659 | struct alc_spec *spec = codec->spec; |
6169 | if (action != ALC_FIXUP_ACT_PROBE) | 2660 | if (action != ALC_FIXUP_ACT_PROBE) |
6170 | return; | 2661 | return; |
6171 | spec->automute_hook = alc269_quanta_automute; | 2662 | spec->gen.automute_hook = alc269_quanta_automute; |
6172 | } | 2663 | } |
6173 | 2664 | ||
6174 | /* update mute-LED according to the speaker mute state via mic1 VREF pin */ | 2665 | /* update mute-LED according to the speaker mute state via mic1 VREF pin */ |
@@ -6185,7 +2676,7 @@ static void alc269_fixup_mic1_mute(struct hda_codec *codec, | |||
6185 | { | 2676 | { |
6186 | struct alc_spec *spec = codec->spec; | 2677 | struct alc_spec *spec = codec->spec; |
6187 | if (action == ALC_FIXUP_ACT_PROBE) | 2678 | if (action == ALC_FIXUP_ACT_PROBE) |
6188 | spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook; | 2679 | spec->gen.vmaster_mute.hook = alc269_fixup_mic1_mute_hook; |
6189 | } | 2680 | } |
6190 | 2681 | ||
6191 | /* update mute-LED according to the speaker mute state via mic2 VREF pin */ | 2682 | /* update mute-LED according to the speaker mute state via mic2 VREF pin */ |
@@ -6201,7 +2692,7 @@ static void alc269_fixup_mic2_mute(struct hda_codec *codec, | |||
6201 | { | 2692 | { |
6202 | struct alc_spec *spec = codec->spec; | 2693 | struct alc_spec *spec = codec->spec; |
6203 | if (action == ALC_FIXUP_ACT_PROBE) | 2694 | if (action == ALC_FIXUP_ACT_PROBE) |
6204 | spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook; | 2695 | spec->gen.vmaster_mute.hook = alc269_fixup_mic2_mute_hook; |
6205 | } | 2696 | } |
6206 | 2697 | ||
6207 | static void alc271_hp_gate_mic_jack(struct hda_codec *codec, | 2698 | static void alc271_hp_gate_mic_jack(struct hda_codec *codec, |
@@ -6210,11 +2701,12 @@ static void alc271_hp_gate_mic_jack(struct hda_codec *codec, | |||
6210 | { | 2701 | { |
6211 | struct alc_spec *spec = codec->spec; | 2702 | struct alc_spec *spec = codec->spec; |
6212 | 2703 | ||
6213 | if (snd_BUG_ON(!spec->am_entry[1].pin || !spec->autocfg.hp_pins[0])) | 2704 | if (snd_BUG_ON(!spec->gen.am_entry[1].pin || |
2705 | !spec->gen.autocfg.hp_pins[0])) | ||
6214 | return; | 2706 | return; |
6215 | if (action == ALC_FIXUP_ACT_PROBE) | 2707 | if (action == ALC_FIXUP_ACT_PROBE) |
6216 | snd_hda_jack_set_gating_jack(codec, spec->am_entry[1].pin, | 2708 | snd_hda_jack_set_gating_jack(codec, spec->gen.am_entry[1].pin, |
6217 | spec->autocfg.hp_pins[0]); | 2709 | spec->gen.autocfg.hp_pins[0]); |
6218 | } | 2710 | } |
6219 | 2711 | ||
6220 | enum { | 2712 | enum { |
@@ -6560,7 +3052,7 @@ static int patch_alc269(struct hda_codec *codec) | |||
6560 | return err; | 3052 | return err; |
6561 | 3053 | ||
6562 | spec = codec->spec; | 3054 | spec = codec->spec; |
6563 | spec->shared_mic_vref_pin = 0x18; | 3055 | spec->gen.shared_mic_vref_pin = 0x18; |
6564 | 3056 | ||
6565 | alc_pick_fixup(codec, alc269_fixup_models, | 3057 | alc_pick_fixup(codec, alc269_fixup_models, |
6566 | alc269_fixup_tbl, alc269_fixups); | 3058 | alc269_fixup_tbl, alc269_fixups); |
@@ -6615,7 +3107,7 @@ static int patch_alc269(struct hda_codec *codec) | |||
6615 | if (err < 0) | 3107 | if (err < 0) |
6616 | goto error; | 3108 | goto error; |
6617 | 3109 | ||
6618 | if (!spec->no_analog && has_cdefine_beep(codec)) { | 3110 | if (!spec->gen.no_analog && has_cdefine_beep(codec)) { |
6619 | err = snd_hda_attach_beep_device(codec, 0x1); | 3111 | err = snd_hda_attach_beep_device(codec, 0x1); |
6620 | if (err < 0) | 3112 | if (err < 0) |
6621 | goto error; | 3113 | goto error; |
@@ -6671,7 +3163,7 @@ static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec, | |||
6671 | val |= AC_PINCTL_IN_EN; | 3163 | val |= AC_PINCTL_IN_EN; |
6672 | val |= AC_PINCTL_VREF_50; | 3164 | val |= AC_PINCTL_VREF_50; |
6673 | snd_hda_set_pin_ctl(codec, 0x0f, val); | 3165 | snd_hda_set_pin_ctl(codec, 0x0f, val); |
6674 | spec->keep_vref_in_automute = 1; | 3166 | spec->gen.keep_vref_in_automute = 1; |
6675 | } | 3167 | } |
6676 | 3168 | ||
6677 | /* suppress the jack-detection */ | 3169 | /* suppress the jack-detection */ |
@@ -6738,7 +3230,7 @@ static int patch_alc861(struct hda_codec *codec) | |||
6738 | if (err < 0) | 3230 | if (err < 0) |
6739 | goto error; | 3231 | goto error; |
6740 | 3232 | ||
6741 | if (!spec->no_analog) { | 3233 | if (!spec->gen.no_analog) { |
6742 | err = snd_hda_attach_beep_device(codec, 0x23); | 3234 | err = snd_hda_attach_beep_device(codec, 0x23); |
6743 | if (err < 0) | 3235 | if (err < 0) |
6744 | goto error; | 3236 | goto error; |
@@ -6833,7 +3325,7 @@ static int patch_alc861vd(struct hda_codec *codec) | |||
6833 | if (err < 0) | 3325 | if (err < 0) |
6834 | goto error; | 3326 | goto error; |
6835 | 3327 | ||
6836 | if (!spec->no_analog) { | 3328 | if (!spec->gen.no_analog) { |
6837 | err = snd_hda_attach_beep_device(codec, 0x23); | 3329 | err = snd_hda_attach_beep_device(codec, 0x23); |
6838 | if (err < 0) | 3330 | if (err < 0) |
6839 | goto error; | 3331 | goto error; |
@@ -7232,7 +3724,7 @@ static int patch_alc662(struct hda_codec *codec) | |||
7232 | if (err < 0) | 3724 | if (err < 0) |
7233 | goto error; | 3725 | goto error; |
7234 | 3726 | ||
7235 | if (!spec->no_analog && has_cdefine_beep(codec)) { | 3727 | if (!spec->gen.no_analog && has_cdefine_beep(codec)) { |
7236 | err = snd_hda_attach_beep_device(codec, 0x1); | 3728 | err = snd_hda_attach_beep_device(codec, 0x1); |
7237 | if (err < 0) | 3729 | if (err < 0) |
7238 | goto error; | 3730 | goto error; |