2 * Universal Interface for Intel High Definition Audio Codec
4 * Generic widget tree parser
6 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/init.h>
24 #include <linux/slab.h>
25 #include <linux/export.h>
26 #include <linux/sort.h>
27 #include <linux/delay.h>
28 #include <linux/ctype.h>
29 #include <linux/string.h>
30 #include <linux/bitops.h>
31 #include <linux/module.h>
32 #include <sound/core.h>
33 #include <sound/jack.h>
34 #include <sound/tlv.h>
35 #include "hda_codec.h"
36 #include "hda_local.h"
37 #include "hda_auto_parser.h"
40 #include "hda_generic.h"
43 /* initialize hda_gen_spec struct */
44 int snd_hda_gen_spec_init(struct hda_gen_spec *spec)
46 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
47 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
48 snd_array_init(&spec->loopback_list, sizeof(struct hda_amp_list), 8);
49 mutex_init(&spec->pcm_mutex);
52 EXPORT_SYMBOL_GPL(snd_hda_gen_spec_init);
54 struct snd_kcontrol_new *
55 snd_hda_gen_add_kctl(struct hda_gen_spec *spec, const char *name,
56 const struct snd_kcontrol_new *temp)
58 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
63 knew->name = kstrdup(name, GFP_KERNEL);
65 knew->name = kstrdup(knew->name, GFP_KERNEL);
70 EXPORT_SYMBOL_GPL(snd_hda_gen_add_kctl);
72 static void free_kctls(struct hda_gen_spec *spec)
74 if (spec->kctls.list) {
75 struct snd_kcontrol_new *kctl = spec->kctls.list;
77 for (i = 0; i < spec->kctls.used; i++)
80 snd_array_free(&spec->kctls);
83 static void snd_hda_gen_spec_free(struct hda_gen_spec *spec)
88 snd_array_free(&spec->paths);
89 snd_array_free(&spec->loopback_list);
95 static void parse_user_hints(struct hda_codec *codec)
97 struct hda_gen_spec *spec = codec->spec;
100 val = snd_hda_get_bool_hint(codec, "jack_detect");
102 codec->no_jack_detect = !val;
103 val = snd_hda_get_bool_hint(codec, "inv_jack_detect");
105 codec->inv_jack_detect = !!val;
106 val = snd_hda_get_bool_hint(codec, "trigger_sense");
108 codec->no_trigger_sense = !val;
109 val = snd_hda_get_bool_hint(codec, "inv_eapd");
111 codec->inv_eapd = !!val;
112 val = snd_hda_get_bool_hint(codec, "pcm_format_first");
114 codec->pcm_format_first = !!val;
115 val = snd_hda_get_bool_hint(codec, "sticky_stream");
117 codec->no_sticky_stream = !val;
118 val = snd_hda_get_bool_hint(codec, "spdif_status_reset");
120 codec->spdif_status_reset = !!val;
121 val = snd_hda_get_bool_hint(codec, "pin_amp_workaround");
123 codec->pin_amp_workaround = !!val;
124 val = snd_hda_get_bool_hint(codec, "single_adc_amp");
126 codec->single_adc_amp = !!val;
128 val = snd_hda_get_bool_hint(codec, "auto_mute");
130 spec->suppress_auto_mute = !val;
131 val = snd_hda_get_bool_hint(codec, "auto_mic");
133 spec->suppress_auto_mic = !val;
134 val = snd_hda_get_bool_hint(codec, "line_in_auto_switch");
136 spec->line_in_auto_switch = !!val;
137 val = snd_hda_get_bool_hint(codec, "auto_mute_via_amp");
139 spec->auto_mute_via_amp = !!val;
140 val = snd_hda_get_bool_hint(codec, "need_dac_fix");
142 spec->need_dac_fix = !!val;
143 val = snd_hda_get_bool_hint(codec, "primary_hp");
145 spec->no_primary_hp = !val;
146 val = snd_hda_get_bool_hint(codec, "multi_io");
148 spec->no_multi_io = !val;
149 val = snd_hda_get_bool_hint(codec, "multi_cap_vol");
151 spec->multi_cap_vol = !!val;
152 val = snd_hda_get_bool_hint(codec, "inv_dmic_split");
154 spec->inv_dmic_split = !!val;
155 val = snd_hda_get_bool_hint(codec, "indep_hp");
157 spec->indep_hp = !!val;
158 val = snd_hda_get_bool_hint(codec, "add_stereo_mix_input");
160 spec->add_stereo_mix_input = !!val;
161 /* the following two are just for compatibility */
162 val = snd_hda_get_bool_hint(codec, "add_out_jack_modes");
164 spec->add_jack_modes = !!val;
165 val = snd_hda_get_bool_hint(codec, "add_in_jack_modes");
167 spec->add_jack_modes = !!val;
168 val = snd_hda_get_bool_hint(codec, "add_jack_modes");
170 spec->add_jack_modes = !!val;
171 val = snd_hda_get_bool_hint(codec, "power_down_unused");
173 spec->power_down_unused = !!val;
174 val = snd_hda_get_bool_hint(codec, "add_hp_mic");
176 spec->hp_mic = !!val;
177 val = snd_hda_get_bool_hint(codec, "hp_mic_detect");
179 spec->suppress_hp_mic_detect = !val;
181 if (!snd_hda_get_int_hint(codec, "mixer_nid", &val))
182 spec->mixer_nid = val;
186 * pin control value accesses
189 #define update_pin_ctl(codec, pin, val) \
190 snd_hda_codec_update_cache(codec, pin, 0, \
191 AC_VERB_SET_PIN_WIDGET_CONTROL, val)
193 /* restore the pinctl based on the cached value */
194 static inline void restore_pin_ctl(struct hda_codec *codec, hda_nid_t pin)
196 update_pin_ctl(codec, pin, snd_hda_codec_get_pin_target(codec, pin));
199 /* set the pinctl target value and write it if requested */
200 static void set_pin_target(struct hda_codec *codec, hda_nid_t pin,
201 unsigned int val, bool do_write)
205 val = snd_hda_correct_pin_ctl(codec, pin, val);
206 snd_hda_codec_set_pin_target(codec, pin, val);
208 update_pin_ctl(codec, pin, val);
211 /* set pinctl target values for all given pins */
212 static void set_pin_targets(struct hda_codec *codec, int num_pins,
213 hda_nid_t *pins, unsigned int val)
216 for (i = 0; i < num_pins; i++)
217 set_pin_target(codec, pins[i], val, false);
224 /* return the position of NID in the list, or -1 if not found */
225 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
228 for (i = 0; i < nums; i++)
234 /* return true if the given NID is contained in the path */
235 static bool is_nid_contained(struct nid_path *path, hda_nid_t nid)
237 return find_idx_in_nid_list(nid, path->path, path->depth) >= 0;
240 static struct nid_path *get_nid_path(struct hda_codec *codec,
241 hda_nid_t from_nid, hda_nid_t to_nid,
244 struct hda_gen_spec *spec = codec->spec;
247 for (i = 0; i < spec->paths.used; i++) {
248 struct nid_path *path = snd_array_elem(&spec->paths, i);
249 if (path->depth <= 0)
251 if ((!from_nid || path->path[0] == from_nid) &&
252 (!to_nid || path->path[path->depth - 1] == to_nid)) {
254 (anchor_nid > 0 && is_nid_contained(path, anchor_nid)) ||
255 (anchor_nid < 0 && !is_nid_contained(path, anchor_nid)))
262 /* get the path between the given NIDs;
263 * passing 0 to either @pin or @dac behaves as a wildcard
265 struct nid_path *snd_hda_get_nid_path(struct hda_codec *codec,
266 hda_nid_t from_nid, hda_nid_t to_nid)
268 return get_nid_path(codec, from_nid, to_nid, 0);
270 EXPORT_SYMBOL_GPL(snd_hda_get_nid_path);
272 /* get the index number corresponding to the path instance;
273 * the index starts from 1, for easier checking the invalid value
275 int snd_hda_get_path_idx(struct hda_codec *codec, struct nid_path *path)
277 struct hda_gen_spec *spec = codec->spec;
278 struct nid_path *array = spec->paths.list;
281 if (!spec->paths.used)
284 if (idx < 0 || idx >= spec->paths.used)
288 EXPORT_SYMBOL_GPL(snd_hda_get_path_idx);
290 /* get the path instance corresponding to the given index number */
291 struct nid_path *snd_hda_get_path_from_idx(struct hda_codec *codec, int idx)
293 struct hda_gen_spec *spec = codec->spec;
295 if (idx <= 0 || idx > spec->paths.used)
297 return snd_array_elem(&spec->paths, idx - 1);
299 EXPORT_SYMBOL_GPL(snd_hda_get_path_from_idx);
301 /* check whether the given DAC is already found in any existing paths */
302 static bool is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
304 struct hda_gen_spec *spec = codec->spec;
307 for (i = 0; i < spec->paths.used; i++) {
308 struct nid_path *path = snd_array_elem(&spec->paths, i);
309 if (path->path[0] == nid)
315 /* check whether the given two widgets can be connected */
316 static bool is_reachable_path(struct hda_codec *codec,
317 hda_nid_t from_nid, hda_nid_t to_nid)
319 if (!from_nid || !to_nid)
321 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
324 /* nid, dir and idx */
325 #define AMP_VAL_COMPARE_MASK (0xffff | (1U << 18) | (0x0f << 19))
327 /* check whether the given ctl is already assigned in any path elements */
328 static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
330 struct hda_gen_spec *spec = codec->spec;
333 val &= AMP_VAL_COMPARE_MASK;
334 for (i = 0; i < spec->paths.used; i++) {
335 struct nid_path *path = snd_array_elem(&spec->paths, i);
336 if ((path->ctls[type] & AMP_VAL_COMPARE_MASK) == val)
342 /* check whether a control with the given (nid, dir, idx) was assigned */
343 static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
344 int dir, int idx, int type)
346 unsigned int val = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir);
347 return is_ctl_used(codec, val, type);
350 static void print_nid_path(struct hda_codec *codec,
351 const char *pfx, struct nid_path *path)
358 for (i = 0; i < path->depth; i++)
359 pos += scnprintf(pos, sizeof(buf) - (pos - buf), "%s%02x",
360 pos != buf ? ":" : "",
363 codec_dbg(codec, "%s path: depth=%d '%s'\n", pfx, path->depth, buf);
366 /* called recursively */
367 static bool __parse_nid_path(struct hda_codec *codec,
368 hda_nid_t from_nid, hda_nid_t to_nid,
369 int anchor_nid, struct nid_path *path,
372 const hda_nid_t *conn;
375 if (to_nid == anchor_nid)
376 anchor_nid = 0; /* anchor passed */
377 else if (to_nid == (hda_nid_t)(-anchor_nid))
378 return false; /* hit the exclusive nid */
380 nums = snd_hda_get_conn_list(codec, to_nid, &conn);
381 for (i = 0; i < nums; i++) {
382 if (conn[i] != from_nid) {
383 /* special case: when from_nid is 0,
384 * try to find an empty DAC
387 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
388 is_dac_already_used(codec, conn[i]))
391 /* anchor is not requested or already passed? */
395 if (depth >= MAX_NID_PATH_DEPTH)
397 for (i = 0; i < nums; i++) {
399 type = get_wcaps_type(get_wcaps(codec, conn[i]));
400 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
403 if (__parse_nid_path(codec, from_nid, conn[i],
404 anchor_nid, path, depth + 1))
410 path->path[path->depth] = conn[i];
411 path->idx[path->depth + 1] = i;
412 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
413 path->multi[path->depth + 1] = 1;
418 /* parse the widget path from the given nid to the target nid;
419 * when @from_nid is 0, try to find an empty DAC;
420 * when @anchor_nid is set to a positive value, only paths through the widget
421 * with the given value are evaluated.
422 * when @anchor_nid is set to a negative value, paths through the widget
423 * with the negative of given value are excluded, only other paths are chosen.
424 * when @anchor_nid is zero, no special handling about path selection.
426 bool snd_hda_parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
427 hda_nid_t to_nid, int anchor_nid,
428 struct nid_path *path)
430 if (__parse_nid_path(codec, from_nid, to_nid, anchor_nid, path, 1)) {
431 path->path[path->depth] = to_nid;
437 EXPORT_SYMBOL_GPL(snd_hda_parse_nid_path);
440 * parse the path between the given NIDs and add to the path list.
441 * if no valid path is found, return NULL
444 snd_hda_add_new_path(struct hda_codec *codec, hda_nid_t from_nid,
445 hda_nid_t to_nid, int anchor_nid)
447 struct hda_gen_spec *spec = codec->spec;
448 struct nid_path *path;
450 if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid))
453 /* check whether the path has been already added */
454 path = get_nid_path(codec, from_nid, to_nid, anchor_nid);
458 path = snd_array_new(&spec->paths);
461 memset(path, 0, sizeof(*path));
462 if (snd_hda_parse_nid_path(codec, from_nid, to_nid, anchor_nid, path))
468 EXPORT_SYMBOL_GPL(snd_hda_add_new_path);
470 /* clear the given path as invalid so that it won't be picked up later */
471 static void invalidate_nid_path(struct hda_codec *codec, int idx)
473 struct nid_path *path = snd_hda_get_path_from_idx(codec, idx);
476 memset(path, 0, sizeof(*path));
479 /* return a DAC if paired to the given pin by codec driver */
480 static hda_nid_t get_preferred_dac(struct hda_codec *codec, hda_nid_t pin)
482 struct hda_gen_spec *spec = codec->spec;
483 const hda_nid_t *list = spec->preferred_dacs;
487 for (; *list; list += 2)
493 /* look for an empty DAC slot */
494 static hda_nid_t look_for_dac(struct hda_codec *codec, hda_nid_t pin,
497 struct hda_gen_spec *spec = codec->spec;
501 for (i = 0; i < spec->num_all_dacs; i++) {
502 hda_nid_t nid = spec->all_dacs[i];
503 if (!nid || is_dac_already_used(codec, nid))
505 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
506 if (is_digital != cap_digital)
508 if (is_reachable_path(codec, nid, pin))
514 /* replace the channels in the composed amp value with the given number */
515 static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
517 val &= ~(0x3U << 16);
522 /* check whether the widget has the given amp capability for the direction */
523 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
524 int dir, unsigned int bits)
528 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
529 if (query_amp_caps(codec, nid, dir) & bits)
534 static bool same_amp_caps(struct hda_codec *codec, hda_nid_t nid1,
535 hda_nid_t nid2, int dir)
537 if (!(get_wcaps(codec, nid1) & (1 << (dir + 1))))
538 return !(get_wcaps(codec, nid2) & (1 << (dir + 1)));
539 return (query_amp_caps(codec, nid1, dir) ==
540 query_amp_caps(codec, nid2, dir));
543 #define nid_has_mute(codec, nid, dir) \
544 check_amp_caps(codec, nid, dir, (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE))
545 #define nid_has_volume(codec, nid, dir) \
546 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
548 /* look for a widget suitable for assigning a mute switch in the path */
549 static hda_nid_t look_for_out_mute_nid(struct hda_codec *codec,
550 struct nid_path *path)
554 for (i = path->depth - 1; i >= 0; i--) {
555 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
556 return path->path[i];
557 if (i != path->depth - 1 && i != 0 &&
558 nid_has_mute(codec, path->path[i], HDA_INPUT))
559 return path->path[i];
564 /* look for a widget suitable for assigning a volume ctl in the path */
565 static hda_nid_t look_for_out_vol_nid(struct hda_codec *codec,
566 struct nid_path *path)
568 struct hda_gen_spec *spec = codec->spec;
571 for (i = path->depth - 1; i >= 0; i--) {
572 hda_nid_t nid = path->path[i];
573 if ((spec->out_vol_mask >> nid) & 1)
575 if (nid_has_volume(codec, nid, HDA_OUTPUT))
582 * path activation / deactivation
585 /* can have the amp-in capability? */
586 static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
588 hda_nid_t nid = path->path[idx];
589 unsigned int caps = get_wcaps(codec, nid);
590 unsigned int type = get_wcaps_type(caps);
592 if (!(caps & AC_WCAP_IN_AMP))
594 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
599 /* can have the amp-out capability? */
600 static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
602 hda_nid_t nid = path->path[idx];
603 unsigned int caps = get_wcaps(codec, nid);
604 unsigned int type = get_wcaps_type(caps);
606 if (!(caps & AC_WCAP_OUT_AMP))
608 if (type == AC_WID_PIN && !idx) /* only for output pins */
613 /* check whether the given (nid,dir,idx) is active */
614 static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
615 unsigned int dir, unsigned int idx)
617 struct hda_gen_spec *spec = codec->spec;
620 for (n = 0; n < spec->paths.used; n++) {
621 struct nid_path *path = snd_array_elem(&spec->paths, n);
624 for (i = 0; i < path->depth; i++) {
625 if (path->path[i] == nid) {
626 if (dir == HDA_OUTPUT || path->idx[i] == idx)
635 /* check whether the NID is referred by any active paths */
636 #define is_active_nid_for_any(codec, nid) \
637 is_active_nid(codec, nid, HDA_OUTPUT, 0)
639 /* get the default amp value for the target state */
640 static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
641 int dir, unsigned int caps, bool enable)
643 unsigned int val = 0;
645 if (caps & AC_AMPCAP_NUM_STEPS) {
648 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
650 if (caps & (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)) {
657 /* initialize the amp value (only at the first time) */
658 static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
660 unsigned int caps = query_amp_caps(codec, nid, dir);
661 int val = get_amp_val_to_activate(codec, nid, dir, caps, false);
662 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
665 /* calculate amp value mask we can modify;
666 * if the given amp is controlled by mixers, don't touch it
668 static unsigned int get_amp_mask_to_modify(struct hda_codec *codec,
669 hda_nid_t nid, int dir, int idx,
672 unsigned int mask = 0xff;
674 if (caps & (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)) {
675 if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_MUTE_CTL))
678 if (caps & AC_AMPCAP_NUM_STEPS) {
679 if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
680 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
686 static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
687 int idx, int idx_to_check, bool enable)
690 unsigned int mask, val;
692 if (!enable && is_active_nid(codec, nid, dir, idx_to_check))
695 caps = query_amp_caps(codec, nid, dir);
696 val = get_amp_val_to_activate(codec, nid, dir, caps, enable);
697 mask = get_amp_mask_to_modify(codec, nid, dir, idx_to_check, caps);
702 snd_hda_codec_amp_stereo(codec, nid, dir, idx, mask, val);
705 static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
708 hda_nid_t nid = path->path[i];
709 init_amp(codec, nid, HDA_OUTPUT, 0);
710 activate_amp(codec, nid, HDA_OUTPUT, 0, 0, enable);
713 static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
714 int i, bool enable, bool add_aamix)
716 struct hda_gen_spec *spec = codec->spec;
717 const hda_nid_t *conn;
720 hda_nid_t nid = path->path[i];
722 nums = snd_hda_get_conn_list(codec, nid, &conn);
723 type = get_wcaps_type(get_wcaps(codec, nid));
724 if (type == AC_WID_PIN ||
725 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
731 for (n = 0; n < nums; n++)
732 init_amp(codec, nid, HDA_INPUT, n);
734 /* here is a little bit tricky in comparison with activate_amp_out();
735 * when aa-mixer is available, we need to enable the path as well
737 for (n = 0; n < nums; n++) {
738 if (n != idx && (!add_aamix || conn[n] != spec->mixer_merge_nid))
740 activate_amp(codec, nid, HDA_INPUT, n, idx, enable);
744 /* activate or deactivate the given path
745 * if @add_aamix is set, enable the input from aa-mix NID as well (if any)
747 void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
748 bool enable, bool add_aamix)
750 struct hda_gen_spec *spec = codec->spec;
754 path->active = false;
756 for (i = path->depth - 1; i >= 0; i--) {
757 hda_nid_t nid = path->path[i];
758 if (enable && spec->power_down_unused) {
759 /* make sure the widget is powered up */
760 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0))
761 snd_hda_codec_write(codec, nid, 0,
762 AC_VERB_SET_POWER_STATE,
765 if (enable && path->multi[i])
766 snd_hda_codec_update_cache(codec, nid, 0,
767 AC_VERB_SET_CONNECT_SEL,
769 if (has_amp_in(codec, path, i))
770 activate_amp_in(codec, path, i, enable, add_aamix);
771 if (has_amp_out(codec, path, i))
772 activate_amp_out(codec, path, i, enable);
778 EXPORT_SYMBOL_GPL(snd_hda_activate_path);
780 /* if the given path is inactive, put widgets into D3 (only if suitable) */
781 static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path)
783 struct hda_gen_spec *spec = codec->spec;
784 bool changed = false;
787 if (!spec->power_down_unused || path->active)
790 for (i = 0; i < path->depth; i++) {
791 hda_nid_t nid = path->path[i];
792 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D3) &&
793 !is_active_nid_for_any(codec, nid)) {
794 snd_hda_codec_write(codec, nid, 0,
795 AC_VERB_SET_POWER_STATE,
803 snd_hda_codec_read(codec, path->path[0], 0,
804 AC_VERB_GET_POWER_STATE, 0);
808 /* turn on/off EAPD on the given pin */
809 static void set_pin_eapd(struct hda_codec *codec, hda_nid_t pin, bool enable)
811 struct hda_gen_spec *spec = codec->spec;
812 if (spec->own_eapd_ctl ||
813 !(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD))
815 if (spec->keep_eapd_on && !enable)
819 snd_hda_codec_update_cache(codec, pin, 0,
820 AC_VERB_SET_EAPD_BTLENABLE,
821 enable ? 0x02 : 0x00);
824 /* re-initialize the path specified by the given path index */
825 static void resume_path_from_idx(struct hda_codec *codec, int path_idx)
827 struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
829 snd_hda_activate_path(codec, path, path->active, false);
834 * Helper functions for creating mixer ctl elements
837 static int hda_gen_mixer_mute_put(struct snd_kcontrol *kcontrol,
838 struct snd_ctl_elem_value *ucontrol);
839 static int hda_gen_bind_mute_put(struct snd_kcontrol *kcontrol,
840 struct snd_ctl_elem_value *ucontrol);
847 static const struct snd_kcontrol_new control_templates[] = {
848 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
849 /* only the put callback is replaced for handling the special mute */
851 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
852 .subdevice = HDA_SUBDEV_AMP_FLAG,
853 .info = snd_hda_mixer_amp_switch_info,
854 .get = snd_hda_mixer_amp_switch_get,
855 .put = hda_gen_mixer_mute_put, /* replaced */
856 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0),
859 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
860 .info = snd_hda_mixer_amp_switch_info,
861 .get = snd_hda_mixer_bind_switch_get,
862 .put = hda_gen_bind_mute_put, /* replaced */
863 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0),
867 /* add dynamic controls from template */
868 static struct snd_kcontrol_new *
869 add_control(struct hda_gen_spec *spec, int type, const char *name,
870 int cidx, unsigned long val)
872 struct snd_kcontrol_new *knew;
874 knew = snd_hda_gen_add_kctl(spec, name, &control_templates[type]);
878 if (get_amp_nid_(val))
879 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
880 knew->private_value = val;
884 static int add_control_with_pfx(struct hda_gen_spec *spec, int type,
885 const char *pfx, const char *dir,
886 const char *sfx, int cidx, unsigned long val)
888 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
889 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
890 if (!add_control(spec, type, name, cidx, val))
895 #define add_pb_vol_ctrl(spec, type, pfx, val) \
896 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
897 #define add_pb_sw_ctrl(spec, type, pfx, val) \
898 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
899 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
900 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
901 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
902 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
904 static int add_vol_ctl(struct hda_codec *codec, const char *pfx, int cidx,
905 unsigned int chs, struct nid_path *path)
910 val = path->ctls[NID_PATH_VOL_CTL];
913 val = amp_val_replace_channels(val, chs);
914 return __add_pb_vol_ctrl(codec->spec, HDA_CTL_WIDGET_VOL, pfx, cidx, val);
917 /* return the channel bits suitable for the given path->ctls[] */
918 static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
921 int chs = 1; /* mono (left only) */
923 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
924 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
925 chs = 3; /* stereo */
930 static int add_stereo_vol(struct hda_codec *codec, const char *pfx, int cidx,
931 struct nid_path *path)
933 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
934 return add_vol_ctl(codec, pfx, cidx, chs, path);
937 /* create a mute-switch for the given mixer widget;
938 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
940 static int add_sw_ctl(struct hda_codec *codec, const char *pfx, int cidx,
941 unsigned int chs, struct nid_path *path)
944 int type = HDA_CTL_WIDGET_MUTE;
948 val = path->ctls[NID_PATH_MUTE_CTL];
951 val = amp_val_replace_channels(val, chs);
952 if (get_amp_direction_(val) == HDA_INPUT) {
953 hda_nid_t nid = get_amp_nid_(val);
954 int nums = snd_hda_get_num_conns(codec, nid);
956 type = HDA_CTL_BIND_MUTE;
960 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
963 static int add_stereo_sw(struct hda_codec *codec, const char *pfx,
964 int cidx, struct nid_path *path)
966 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
967 return add_sw_ctl(codec, pfx, cidx, chs, path);
970 /* playback mute control with the software mute bit check */
971 static void sync_auto_mute_bits(struct snd_kcontrol *kcontrol,
972 struct snd_ctl_elem_value *ucontrol)
974 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
975 struct hda_gen_spec *spec = codec->spec;
977 if (spec->auto_mute_via_amp) {
978 hda_nid_t nid = get_amp_nid(kcontrol);
979 bool enabled = !((spec->mute_bits >> nid) & 1);
980 ucontrol->value.integer.value[0] &= enabled;
981 ucontrol->value.integer.value[1] &= enabled;
985 static int hda_gen_mixer_mute_put(struct snd_kcontrol *kcontrol,
986 struct snd_ctl_elem_value *ucontrol)
988 sync_auto_mute_bits(kcontrol, ucontrol);
989 return snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
992 static int hda_gen_bind_mute_put(struct snd_kcontrol *kcontrol,
993 struct snd_ctl_elem_value *ucontrol)
995 sync_auto_mute_bits(kcontrol, ucontrol);
996 return snd_hda_mixer_bind_switch_put(kcontrol, ucontrol);
999 /* any ctl assigned to the path with the given index? */
1000 static bool path_has_mixer(struct hda_codec *codec, int path_idx, int ctl_type)
1002 struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
1003 return path && path->ctls[ctl_type];
1006 static const char * const channel_name[4] = {
1007 "Front", "Surround", "CLFE", "Side"
1010 /* give some appropriate ctl name prefix for the given line out channel */
1011 static const char *get_line_out_pfx(struct hda_codec *codec, int ch,
1012 int *index, int ctl_type)
1014 struct hda_gen_spec *spec = codec->spec;
1015 struct auto_pin_cfg *cfg = &spec->autocfg;
1018 if (cfg->line_outs == 1 && !spec->multi_ios &&
1019 !cfg->hp_outs && !cfg->speaker_outs)
1020 return spec->vmaster_mute.hook ? "PCM" : "Master";
1022 /* if there is really a single DAC used in the whole output paths,
1023 * use it master (or "PCM" if a vmaster hook is present)
1025 if (spec->multiout.num_dacs == 1 && !spec->mixer_nid &&
1026 !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0])
1027 return spec->vmaster_mute.hook ? "PCM" : "Master";
1029 /* multi-io channels */
1030 if (ch >= cfg->line_outs)
1031 return channel_name[ch];
1033 switch (cfg->line_out_type) {
1034 case AUTO_PIN_SPEAKER_OUT:
1035 /* if the primary channel vol/mute is shared with HP volume,
1036 * don't name it as Speaker
1038 if (!ch && cfg->hp_outs &&
1039 !path_has_mixer(codec, spec->hp_paths[0], ctl_type))
1041 if (cfg->line_outs == 1)
1043 if (cfg->line_outs == 2)
1044 return ch ? "Bass Speaker" : "Speaker";
1046 case AUTO_PIN_HP_OUT:
1047 /* if the primary channel vol/mute is shared with spk volume,
1048 * don't name it as Headphone
1050 if (!ch && cfg->speaker_outs &&
1051 !path_has_mixer(codec, spec->speaker_paths[0], ctl_type))
1053 /* for multi-io case, only the primary out */
1054 if (ch && spec->multi_ios)
1060 /* for a single channel output, we don't have to name the channel */
1061 if (cfg->line_outs == 1 && !spec->multi_ios)
1064 if (ch >= ARRAY_SIZE(channel_name)) {
1069 return channel_name[ch];
1073 * Parse output paths
1076 /* badness definition */
1078 /* No primary DAC is found for the main output */
1079 BAD_NO_PRIMARY_DAC = 0x10000,
1080 /* No DAC is found for the extra output */
1081 BAD_NO_DAC = 0x4000,
1082 /* No possible multi-ios */
1083 BAD_MULTI_IO = 0x120,
1084 /* No individual DAC for extra output */
1085 BAD_NO_EXTRA_DAC = 0x102,
1086 /* No individual DAC for extra surrounds */
1087 BAD_NO_EXTRA_SURR_DAC = 0x101,
1088 /* Primary DAC shared with main surrounds */
1089 BAD_SHARED_SURROUND = 0x100,
1090 /* No independent HP possible */
1091 BAD_NO_INDEP_HP = 0x10,
1092 /* Primary DAC shared with main CLFE */
1093 BAD_SHARED_CLFE = 0x10,
1094 /* Primary DAC shared with extra surrounds */
1095 BAD_SHARED_EXTRA_SURROUND = 0x10,
1096 /* Volume widget is shared */
1097 BAD_SHARED_VOL = 0x10,
1100 /* look for widgets in the given path which are appropriate for
1101 * volume and mute controls, and assign the values to ctls[].
1103 * When no appropriate widget is found in the path, the badness value
1104 * is incremented depending on the situation. The function returns the
1105 * total badness for both volume and mute controls.
1107 static int assign_out_path_ctls(struct hda_codec *codec, struct nid_path *path)
1109 struct hda_gen_spec *spec = codec->spec;
1115 return BAD_SHARED_VOL * 2;
1117 if (path->ctls[NID_PATH_VOL_CTL] ||
1118 path->ctls[NID_PATH_MUTE_CTL])
1119 return 0; /* already evaluated */
1121 nid = look_for_out_vol_nid(codec, path);
1123 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
1124 if (spec->dac_min_mute)
1125 val |= HDA_AMP_VAL_MIN_MUTE;
1126 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
1127 badness += BAD_SHARED_VOL;
1129 path->ctls[NID_PATH_VOL_CTL] = val;
1131 badness += BAD_SHARED_VOL;
1132 nid = look_for_out_mute_nid(codec, path);
1134 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
1135 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
1136 nid_has_mute(codec, nid, HDA_OUTPUT))
1137 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
1139 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
1140 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
1141 badness += BAD_SHARED_VOL;
1143 path->ctls[NID_PATH_MUTE_CTL] = val;
1145 badness += BAD_SHARED_VOL;
1149 const struct badness_table hda_main_out_badness = {
1150 .no_primary_dac = BAD_NO_PRIMARY_DAC,
1151 .no_dac = BAD_NO_DAC,
1152 .shared_primary = BAD_NO_PRIMARY_DAC,
1153 .shared_surr = BAD_SHARED_SURROUND,
1154 .shared_clfe = BAD_SHARED_CLFE,
1155 .shared_surr_main = BAD_SHARED_SURROUND,
1157 EXPORT_SYMBOL_GPL(hda_main_out_badness);
1159 const struct badness_table hda_extra_out_badness = {
1160 .no_primary_dac = BAD_NO_DAC,
1161 .no_dac = BAD_NO_DAC,
1162 .shared_primary = BAD_NO_EXTRA_DAC,
1163 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
1164 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
1165 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
1167 EXPORT_SYMBOL_GPL(hda_extra_out_badness);
1169 /* get the DAC of the primary output corresponding to the given array index */
1170 static hda_nid_t get_primary_out(struct hda_codec *codec, int idx)
1172 struct hda_gen_spec *spec = codec->spec;
1173 struct auto_pin_cfg *cfg = &spec->autocfg;
1175 if (cfg->line_outs > idx)
1176 return spec->private_dac_nids[idx];
1177 idx -= cfg->line_outs;
1178 if (spec->multi_ios > idx)
1179 return spec->multi_io[idx].dac;
1183 /* return the DAC if it's reachable, otherwise zero */
1184 static inline hda_nid_t try_dac(struct hda_codec *codec,
1185 hda_nid_t dac, hda_nid_t pin)
1187 return is_reachable_path(codec, dac, pin) ? dac : 0;
1190 /* try to assign DACs to pins and return the resultant badness */
1191 static int try_assign_dacs(struct hda_codec *codec, int num_outs,
1192 const hda_nid_t *pins, hda_nid_t *dacs,
1194 const struct badness_table *bad)
1196 struct hda_gen_spec *spec = codec->spec;
1204 for (i = 0; i < num_outs; i++) {
1205 struct nid_path *path;
1206 hda_nid_t pin = pins[i];
1208 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1210 badness += assign_out_path_ctls(codec, path);
1214 dacs[i] = get_preferred_dac(codec, pin);
1216 if (is_dac_already_used(codec, dacs[i]))
1217 badness += bad->shared_primary;
1221 dacs[i] = look_for_dac(codec, pin, false);
1222 if (!dacs[i] && !i) {
1223 /* try to steal the DAC of surrounds for the front */
1224 for (j = 1; j < num_outs; j++) {
1225 if (is_reachable_path(codec, dacs[j], pin)) {
1228 invalidate_nid_path(codec, path_idx[j]);
1237 dac = try_dac(codec, get_primary_out(codec, i), pin);
1239 dac = try_dac(codec, dacs[0], pin);
1241 dac = try_dac(codec, get_primary_out(codec, i), pin);
1244 badness += bad->shared_primary;
1246 badness += bad->shared_surr;
1248 badness += bad->shared_clfe;
1249 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
1250 dac = spec->private_dac_nids[0];
1251 badness += bad->shared_surr_main;
1253 badness += bad->no_primary_dac;
1255 badness += bad->no_dac;
1259 path = snd_hda_add_new_path(codec, dac, pin, -spec->mixer_nid);
1260 if (!path && !i && spec->mixer_nid) {
1261 /* try with aamix */
1262 path = snd_hda_add_new_path(codec, dac, pin, 0);
1266 badness += bad->no_dac;
1268 /* print_nid_path(codec, "output", path); */
1269 path->active = true;
1270 path_idx[i] = snd_hda_get_path_idx(codec, path);
1271 badness += assign_out_path_ctls(codec, path);
1278 /* return NID if the given pin has only a single connection to a certain DAC */
1279 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
1281 struct hda_gen_spec *spec = codec->spec;
1283 hda_nid_t nid_found = 0;
1285 for (i = 0; i < spec->num_all_dacs; i++) {
1286 hda_nid_t nid = spec->all_dacs[i];
1287 if (!nid || is_dac_already_used(codec, nid))
1289 if (is_reachable_path(codec, nid, pin)) {
1298 /* check whether the given pin can be a multi-io pin */
1299 static bool can_be_multiio_pin(struct hda_codec *codec,
1300 unsigned int location, hda_nid_t nid)
1302 unsigned int defcfg, caps;
1304 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1305 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
1307 if (location && get_defcfg_location(defcfg) != location)
1309 caps = snd_hda_query_pin_caps(codec, nid);
1310 if (!(caps & AC_PINCAP_OUT))
1315 /* count the number of input pins that are capable to be multi-io */
1316 static int count_multiio_pins(struct hda_codec *codec, hda_nid_t reference_pin)
1318 struct hda_gen_spec *spec = codec->spec;
1319 struct auto_pin_cfg *cfg = &spec->autocfg;
1320 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1321 unsigned int location = get_defcfg_location(defcfg);
1325 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
1326 for (i = 0; i < cfg->num_inputs; i++) {
1327 if (cfg->inputs[i].type != type)
1329 if (can_be_multiio_pin(codec, location,
1330 cfg->inputs[i].pin))
1340 * When hardwired is set, try to fill ony hardwired pins, and returns
1341 * zero if any pins are filled, non-zero if nothing found.
1342 * When hardwired is off, try to fill possible input pins, and returns
1343 * the badness value.
1345 static int fill_multi_ios(struct hda_codec *codec,
1346 hda_nid_t reference_pin,
1349 struct hda_gen_spec *spec = codec->spec;
1350 struct auto_pin_cfg *cfg = &spec->autocfg;
1351 int type, i, j, num_pins, old_pins;
1352 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1353 unsigned int location = get_defcfg_location(defcfg);
1355 struct nid_path *path;
1357 old_pins = spec->multi_ios;
1361 num_pins = count_multiio_pins(codec, reference_pin);
1365 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
1366 for (i = 0; i < cfg->num_inputs; i++) {
1367 hda_nid_t nid = cfg->inputs[i].pin;
1370 if (cfg->inputs[i].type != type)
1372 if (!can_be_multiio_pin(codec, location, nid))
1374 for (j = 0; j < spec->multi_ios; j++) {
1375 if (nid == spec->multi_io[j].pin)
1378 if (j < spec->multi_ios)
1382 dac = get_dac_if_single(codec, nid);
1384 dac = look_for_dac(codec, nid, false);
1389 path = snd_hda_add_new_path(codec, dac, nid,
1395 /* print_nid_path(codec, "multiio", path); */
1396 spec->multi_io[spec->multi_ios].pin = nid;
1397 spec->multi_io[spec->multi_ios].dac = dac;
1398 spec->out_paths[cfg->line_outs + spec->multi_ios] =
1399 snd_hda_get_path_idx(codec, path);
1401 if (spec->multi_ios >= 2)
1407 badness = BAD_MULTI_IO;
1408 if (old_pins == spec->multi_ios) {
1410 return 1; /* nothing found */
1412 return badness; /* no badness if nothing found */
1414 if (!hardwired && spec->multi_ios < 2) {
1415 /* cancel newly assigned paths */
1416 spec->paths.used -= spec->multi_ios - old_pins;
1417 spec->multi_ios = old_pins;
1421 /* assign volume and mute controls */
1422 for (i = old_pins; i < spec->multi_ios; i++) {
1423 path = snd_hda_get_path_from_idx(codec, spec->out_paths[cfg->line_outs + i]);
1424 badness += assign_out_path_ctls(codec, path);
1430 /* map DACs for all pins in the list if they are single connections */
1431 static bool map_singles(struct hda_codec *codec, int outs,
1432 const hda_nid_t *pins, hda_nid_t *dacs, int *path_idx)
1434 struct hda_gen_spec *spec = codec->spec;
1437 for (i = 0; i < outs; i++) {
1438 struct nid_path *path;
1442 dac = get_dac_if_single(codec, pins[i]);
1445 path = snd_hda_add_new_path(codec, dac, pins[i],
1447 if (!path && !i && spec->mixer_nid)
1448 path = snd_hda_add_new_path(codec, dac, pins[i], 0);
1452 /* print_nid_path(codec, "output", path); */
1453 path->active = true;
1454 path_idx[i] = snd_hda_get_path_idx(codec, path);
1460 /* create a new path including aamix if available, and return its index */
1461 static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
1463 struct hda_gen_spec *spec = codec->spec;
1464 struct nid_path *path;
1465 hda_nid_t path_dac, dac, pin;
1467 path = snd_hda_get_path_from_idx(codec, path_idx);
1468 if (!path || !path->depth ||
1469 is_nid_contained(path, spec->mixer_nid))
1471 path_dac = path->path[0];
1472 dac = spec->private_dac_nids[0];
1473 pin = path->path[path->depth - 1];
1474 path = snd_hda_add_new_path(codec, dac, pin, spec->mixer_nid);
1476 if (dac != path_dac)
1478 else if (spec->multiout.hp_out_nid[0])
1479 dac = spec->multiout.hp_out_nid[0];
1480 else if (spec->multiout.extra_out_nid[0])
1481 dac = spec->multiout.extra_out_nid[0];
1485 path = snd_hda_add_new_path(codec, dac, pin,
1490 /* print_nid_path(codec, "output-aamix", path); */
1491 path->active = false; /* unused as default */
1492 return snd_hda_get_path_idx(codec, path);
1495 /* check whether the independent HP is available with the current config */
1496 static bool indep_hp_possible(struct hda_codec *codec)
1498 struct hda_gen_spec *spec = codec->spec;
1499 struct auto_pin_cfg *cfg = &spec->autocfg;
1500 struct nid_path *path;
1503 if (cfg->line_out_type == AUTO_PIN_HP_OUT)
1504 idx = spec->out_paths[0];
1506 idx = spec->hp_paths[0];
1507 path = snd_hda_get_path_from_idx(codec, idx);
1511 /* assume no path conflicts unless aamix is involved */
1512 if (!spec->mixer_nid || !is_nid_contained(path, spec->mixer_nid))
1515 /* check whether output paths contain aamix */
1516 for (i = 0; i < cfg->line_outs; i++) {
1517 if (spec->out_paths[i] == idx)
1519 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
1520 if (path && is_nid_contained(path, spec->mixer_nid))
1523 for (i = 0; i < cfg->speaker_outs; i++) {
1524 path = snd_hda_get_path_from_idx(codec, spec->speaker_paths[i]);
1525 if (path && is_nid_contained(path, spec->mixer_nid))
1532 /* fill the empty entries in the dac array for speaker/hp with the
1533 * shared dac pointed by the paths
1535 static void refill_shared_dacs(struct hda_codec *codec, int num_outs,
1536 hda_nid_t *dacs, int *path_idx)
1538 struct nid_path *path;
1541 for (i = 0; i < num_outs; i++) {
1544 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1547 dacs[i] = path->path[0];
1551 /* fill in the dac_nids table from the parsed pin configuration */
1552 static int fill_and_eval_dacs(struct hda_codec *codec,
1553 bool fill_hardwired,
1554 bool fill_mio_first)
1556 struct hda_gen_spec *spec = codec->spec;
1557 struct auto_pin_cfg *cfg = &spec->autocfg;
1558 int i, err, badness;
1560 /* set num_dacs once to full for look_for_dac() */
1561 spec->multiout.num_dacs = cfg->line_outs;
1562 spec->multiout.dac_nids = spec->private_dac_nids;
1563 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
1564 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
1565 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
1566 spec->multi_ios = 0;
1567 snd_array_free(&spec->paths);
1569 /* clear path indices */
1570 memset(spec->out_paths, 0, sizeof(spec->out_paths));
1571 memset(spec->hp_paths, 0, sizeof(spec->hp_paths));
1572 memset(spec->speaker_paths, 0, sizeof(spec->speaker_paths));
1573 memset(spec->aamix_out_paths, 0, sizeof(spec->aamix_out_paths));
1574 memset(spec->digout_paths, 0, sizeof(spec->digout_paths));
1575 memset(spec->input_paths, 0, sizeof(spec->input_paths));
1576 memset(spec->loopback_paths, 0, sizeof(spec->loopback_paths));
1577 memset(&spec->digin_path, 0, sizeof(spec->digin_path));
1581 /* fill hard-wired DACs first */
1582 if (fill_hardwired) {
1585 mapped = map_singles(codec, cfg->line_outs,
1587 spec->private_dac_nids,
1589 mapped |= map_singles(codec, cfg->hp_outs,
1591 spec->multiout.hp_out_nid,
1593 mapped |= map_singles(codec, cfg->speaker_outs,
1595 spec->multiout.extra_out_nid,
1596 spec->speaker_paths);
1597 if (!spec->no_multi_io &&
1598 fill_mio_first && cfg->line_outs == 1 &&
1599 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1600 err = fill_multi_ios(codec, cfg->line_out_pins[0], true);
1607 badness += try_assign_dacs(codec, cfg->line_outs, cfg->line_out_pins,
1608 spec->private_dac_nids, spec->out_paths,
1609 spec->main_out_badness);
1611 if (!spec->no_multi_io && fill_mio_first &&
1612 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1613 /* try to fill multi-io first */
1614 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1617 /* we don't count badness at this stage yet */
1620 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
1621 err = try_assign_dacs(codec, cfg->hp_outs, cfg->hp_pins,
1622 spec->multiout.hp_out_nid,
1624 spec->extra_out_badness);
1629 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1630 err = try_assign_dacs(codec, cfg->speaker_outs,
1632 spec->multiout.extra_out_nid,
1633 spec->speaker_paths,
1634 spec->extra_out_badness);
1639 if (!spec->no_multi_io &&
1640 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1641 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1647 if (spec->mixer_nid) {
1648 spec->aamix_out_paths[0] =
1649 check_aamix_out_path(codec, spec->out_paths[0]);
1650 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1651 spec->aamix_out_paths[1] =
1652 check_aamix_out_path(codec, spec->hp_paths[0]);
1653 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1654 spec->aamix_out_paths[2] =
1655 check_aamix_out_path(codec, spec->speaker_paths[0]);
1658 if (!spec->no_multi_io &&
1659 cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
1660 if (count_multiio_pins(codec, cfg->hp_pins[0]) >= 2)
1661 spec->multi_ios = 1; /* give badness */
1663 /* re-count num_dacs and squash invalid entries */
1664 spec->multiout.num_dacs = 0;
1665 for (i = 0; i < cfg->line_outs; i++) {
1666 if (spec->private_dac_nids[i])
1667 spec->multiout.num_dacs++;
1669 memmove(spec->private_dac_nids + i,
1670 spec->private_dac_nids + i + 1,
1671 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
1672 spec->private_dac_nids[cfg->line_outs - 1] = 0;
1676 spec->ext_channel_count = spec->min_channel_count =
1677 spec->multiout.num_dacs * 2;
1679 if (spec->multi_ios == 2) {
1680 for (i = 0; i < 2; i++)
1681 spec->private_dac_nids[spec->multiout.num_dacs++] =
1682 spec->multi_io[i].dac;
1683 } else if (spec->multi_ios) {
1684 spec->multi_ios = 0;
1685 badness += BAD_MULTI_IO;
1688 if (spec->indep_hp && !indep_hp_possible(codec))
1689 badness += BAD_NO_INDEP_HP;
1691 /* re-fill the shared DAC for speaker / headphone */
1692 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1693 refill_shared_dacs(codec, cfg->hp_outs,
1694 spec->multiout.hp_out_nid,
1696 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1697 refill_shared_dacs(codec, cfg->speaker_outs,
1698 spec->multiout.extra_out_nid,
1699 spec->speaker_paths);
1704 #define DEBUG_BADNESS
1706 #ifdef DEBUG_BADNESS
1707 #define debug_badness(fmt, ...) \
1708 codec_dbg(codec, fmt, ##__VA_ARGS__)
1710 #define debug_badness(fmt, ...) \
1711 do { if (0) codec_dbg(codec, fmt, ##__VA_ARGS__); } while (0)
1714 #ifdef DEBUG_BADNESS
1715 static inline void print_nid_path_idx(struct hda_codec *codec,
1716 const char *pfx, int idx)
1718 struct nid_path *path;
1720 path = snd_hda_get_path_from_idx(codec, idx);
1722 print_nid_path(codec, pfx, path);
1725 static void debug_show_configs(struct hda_codec *codec,
1726 struct auto_pin_cfg *cfg)
1728 struct hda_gen_spec *spec = codec->spec;
1729 static const char * const lo_type[3] = { "LO", "SP", "HP" };
1732 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x (type %s)\n",
1733 cfg->line_out_pins[0], cfg->line_out_pins[1],
1734 cfg->line_out_pins[2], cfg->line_out_pins[3],
1735 spec->multiout.dac_nids[0],
1736 spec->multiout.dac_nids[1],
1737 spec->multiout.dac_nids[2],
1738 spec->multiout.dac_nids[3],
1739 lo_type[cfg->line_out_type]);
1740 for (i = 0; i < cfg->line_outs; i++)
1741 print_nid_path_idx(codec, " out", spec->out_paths[i]);
1742 if (spec->multi_ios > 0)
1743 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
1745 spec->multi_io[0].pin, spec->multi_io[1].pin,
1746 spec->multi_io[0].dac, spec->multi_io[1].dac);
1747 for (i = 0; i < spec->multi_ios; i++)
1748 print_nid_path_idx(codec, " mio",
1749 spec->out_paths[cfg->line_outs + i]);
1751 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
1752 cfg->hp_pins[0], cfg->hp_pins[1],
1753 cfg->hp_pins[2], cfg->hp_pins[3],
1754 spec->multiout.hp_out_nid[0],
1755 spec->multiout.hp_out_nid[1],
1756 spec->multiout.hp_out_nid[2],
1757 spec->multiout.hp_out_nid[3]);
1758 for (i = 0; i < cfg->hp_outs; i++)
1759 print_nid_path_idx(codec, " hp ", spec->hp_paths[i]);
1760 if (cfg->speaker_outs)
1761 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
1762 cfg->speaker_pins[0], cfg->speaker_pins[1],
1763 cfg->speaker_pins[2], cfg->speaker_pins[3],
1764 spec->multiout.extra_out_nid[0],
1765 spec->multiout.extra_out_nid[1],
1766 spec->multiout.extra_out_nid[2],
1767 spec->multiout.extra_out_nid[3]);
1768 for (i = 0; i < cfg->speaker_outs; i++)
1769 print_nid_path_idx(codec, " spk", spec->speaker_paths[i]);
1770 for (i = 0; i < 3; i++)
1771 print_nid_path_idx(codec, " mix", spec->aamix_out_paths[i]);
1774 #define debug_show_configs(codec, cfg) /* NOP */
1777 /* find all available DACs of the codec */
1778 static void fill_all_dac_nids(struct hda_codec *codec)
1780 struct hda_gen_spec *spec = codec->spec;
1782 hda_nid_t nid = codec->start_nid;
1784 spec->num_all_dacs = 0;
1785 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
1786 for (i = 0; i < codec->num_nodes; i++, nid++) {
1787 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
1789 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
1790 codec_err(codec, "Too many DACs!\n");
1793 spec->all_dacs[spec->num_all_dacs++] = nid;
1797 static int parse_output_paths(struct hda_codec *codec)
1799 struct hda_gen_spec *spec = codec->spec;
1800 struct auto_pin_cfg *cfg = &spec->autocfg;
1801 struct auto_pin_cfg *best_cfg;
1803 int best_badness = INT_MAX;
1805 bool fill_hardwired = true, fill_mio_first = true;
1806 bool best_wired = true, best_mio = true;
1807 bool hp_spk_swapped = false;
1809 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
1815 badness = fill_and_eval_dacs(codec, fill_hardwired,
1821 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
1822 cfg->line_out_type, fill_hardwired, fill_mio_first,
1824 debug_show_configs(codec, cfg);
1825 if (badness < best_badness) {
1826 best_badness = badness;
1828 best_wired = fill_hardwired;
1829 best_mio = fill_mio_first;
1833 fill_mio_first = !fill_mio_first;
1834 if (!fill_mio_first)
1836 fill_hardwired = !fill_hardwired;
1837 if (!fill_hardwired)
1841 hp_spk_swapped = true;
1842 if (cfg->speaker_outs > 0 &&
1843 cfg->line_out_type == AUTO_PIN_HP_OUT) {
1844 cfg->hp_outs = cfg->line_outs;
1845 memcpy(cfg->hp_pins, cfg->line_out_pins,
1846 sizeof(cfg->hp_pins));
1847 cfg->line_outs = cfg->speaker_outs;
1848 memcpy(cfg->line_out_pins, cfg->speaker_pins,
1849 sizeof(cfg->speaker_pins));
1850 cfg->speaker_outs = 0;
1851 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
1852 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
1853 fill_hardwired = true;
1856 if (cfg->hp_outs > 0 &&
1857 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
1858 cfg->speaker_outs = cfg->line_outs;
1859 memcpy(cfg->speaker_pins, cfg->line_out_pins,
1860 sizeof(cfg->speaker_pins));
1861 cfg->line_outs = cfg->hp_outs;
1862 memcpy(cfg->line_out_pins, cfg->hp_pins,
1863 sizeof(cfg->hp_pins));
1865 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
1866 cfg->line_out_type = AUTO_PIN_HP_OUT;
1867 fill_hardwired = true;
1874 debug_badness("==> restoring best_cfg\n");
1876 fill_and_eval_dacs(codec, best_wired, best_mio);
1878 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
1879 cfg->line_out_type, best_wired, best_mio);
1880 debug_show_configs(codec, cfg);
1882 if (cfg->line_out_pins[0]) {
1883 struct nid_path *path;
1884 path = snd_hda_get_path_from_idx(codec, spec->out_paths[0]);
1886 spec->vmaster_nid = look_for_out_vol_nid(codec, path);
1887 if (spec->vmaster_nid) {
1888 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1889 HDA_OUTPUT, spec->vmaster_tlv);
1890 if (spec->dac_min_mute)
1891 spec->vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
1895 /* set initial pinctl targets */
1896 if (spec->prefer_hp_amp || cfg->line_out_type == AUTO_PIN_HP_OUT)
1900 set_pin_targets(codec, cfg->line_outs, cfg->line_out_pins, val);
1901 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1902 set_pin_targets(codec, cfg->hp_outs, cfg->hp_pins, PIN_HP);
1903 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1904 val = spec->prefer_hp_amp ? PIN_HP : PIN_OUT;
1905 set_pin_targets(codec, cfg->speaker_outs,
1906 cfg->speaker_pins, val);
1909 /* clear indep_hp flag if not available */
1910 if (spec->indep_hp && !indep_hp_possible(codec))
1917 /* add playback controls from the parsed DAC table */
1918 static int create_multi_out_ctls(struct hda_codec *codec,
1919 const struct auto_pin_cfg *cfg)
1921 struct hda_gen_spec *spec = codec->spec;
1922 int i, err, noutputs;
1924 noutputs = cfg->line_outs;
1925 if (spec->multi_ios > 0 && cfg->line_outs < 3)
1926 noutputs += spec->multi_ios;
1928 for (i = 0; i < noutputs; i++) {
1931 struct nid_path *path;
1933 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
1937 name = get_line_out_pfx(codec, i, &index, NID_PATH_VOL_CTL);
1938 if (!name || !strcmp(name, "CLFE")) {
1940 err = add_vol_ctl(codec, "Center", 0, 1, path);
1943 err = add_vol_ctl(codec, "LFE", 0, 2, path);
1947 err = add_stereo_vol(codec, name, index, path);
1952 name = get_line_out_pfx(codec, i, &index, NID_PATH_MUTE_CTL);
1953 if (!name || !strcmp(name, "CLFE")) {
1954 err = add_sw_ctl(codec, "Center", 0, 1, path);
1957 err = add_sw_ctl(codec, "LFE", 0, 2, path);
1961 err = add_stereo_sw(codec, name, index, path);
1969 static int create_extra_out(struct hda_codec *codec, int path_idx,
1970 const char *pfx, int cidx)
1972 struct nid_path *path;
1975 path = snd_hda_get_path_from_idx(codec, path_idx);
1978 err = add_stereo_vol(codec, pfx, cidx, path);
1981 err = add_stereo_sw(codec, pfx, cidx, path);
1987 /* add playback controls for speaker and HP outputs */
1988 static int create_extra_outs(struct hda_codec *codec, int num_pins,
1989 const int *paths, const char *pfx)
1993 for (i = 0; i < num_pins; i++) {
1995 char tmp[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
1998 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker"))
1999 name = "Bass Speaker";
2000 else if (num_pins >= 3) {
2001 snprintf(tmp, sizeof(tmp), "%s %s",
2002 pfx, channel_name[i]);
2008 err = create_extra_out(codec, paths[i], name, idx);
2015 static int create_hp_out_ctls(struct hda_codec *codec)
2017 struct hda_gen_spec *spec = codec->spec;
2018 return create_extra_outs(codec, spec->autocfg.hp_outs,
2023 static int create_speaker_out_ctls(struct hda_codec *codec)
2025 struct hda_gen_spec *spec = codec->spec;
2026 return create_extra_outs(codec, spec->autocfg.speaker_outs,
2027 spec->speaker_paths,
2032 * independent HP controls
2035 static void call_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack);
2036 static int indep_hp_info(struct snd_kcontrol *kcontrol,
2037 struct snd_ctl_elem_info *uinfo)
2039 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
2042 static int indep_hp_get(struct snd_kcontrol *kcontrol,
2043 struct snd_ctl_elem_value *ucontrol)
2045 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2046 struct hda_gen_spec *spec = codec->spec;
2047 ucontrol->value.enumerated.item[0] = spec->indep_hp_enabled;
2051 static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
2052 int nomix_path_idx, int mix_path_idx,
2055 static int indep_hp_put(struct snd_kcontrol *kcontrol,
2056 struct snd_ctl_elem_value *ucontrol)
2058 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2059 struct hda_gen_spec *spec = codec->spec;
2060 unsigned int select = ucontrol->value.enumerated.item[0];
2063 mutex_lock(&spec->pcm_mutex);
2064 if (spec->active_streams) {
2069 if (spec->indep_hp_enabled != select) {
2071 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
2072 dacp = &spec->private_dac_nids[0];
2074 dacp = &spec->multiout.hp_out_nid[0];
2076 /* update HP aamix paths in case it conflicts with indep HP */
2077 if (spec->have_aamix_ctl) {
2078 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
2079 update_aamix_paths(codec, spec->aamix_mode,
2081 spec->aamix_out_paths[0],
2082 spec->autocfg.line_out_type);
2084 update_aamix_paths(codec, spec->aamix_mode,
2086 spec->aamix_out_paths[1],
2090 spec->indep_hp_enabled = select;
2091 if (spec->indep_hp_enabled)
2094 *dacp = spec->alt_dac_nid;
2096 call_hp_automute(codec, NULL);
2100 mutex_unlock(&spec->pcm_mutex);
2104 static const struct snd_kcontrol_new indep_hp_ctl = {
2105 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2106 .name = "Independent HP",
2107 .info = indep_hp_info,
2108 .get = indep_hp_get,
2109 .put = indep_hp_put,
2113 static int create_indep_hp_ctls(struct hda_codec *codec)
2115 struct hda_gen_spec *spec = codec->spec;
2118 if (!spec->indep_hp)
2120 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
2121 dac = spec->multiout.dac_nids[0];
2123 dac = spec->multiout.hp_out_nid[0];
2129 spec->indep_hp_enabled = false;
2130 spec->alt_dac_nid = dac;
2131 if (!snd_hda_gen_add_kctl(spec, NULL, &indep_hp_ctl))
2137 * channel mode enum control
2140 static int ch_mode_info(struct snd_kcontrol *kcontrol,
2141 struct snd_ctl_elem_info *uinfo)
2143 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2144 struct hda_gen_spec *spec = codec->spec;
2147 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2149 uinfo->value.enumerated.items = spec->multi_ios + 1;
2150 if (uinfo->value.enumerated.item > spec->multi_ios)
2151 uinfo->value.enumerated.item = spec->multi_ios;
2152 chs = uinfo->value.enumerated.item * 2 + spec->min_channel_count;
2153 sprintf(uinfo->value.enumerated.name, "%dch", chs);
2157 static int ch_mode_get(struct snd_kcontrol *kcontrol,
2158 struct snd_ctl_elem_value *ucontrol)
2160 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2161 struct hda_gen_spec *spec = codec->spec;
2162 ucontrol->value.enumerated.item[0] =
2163 (spec->ext_channel_count - spec->min_channel_count) / 2;
2167 static inline struct nid_path *
2168 get_multiio_path(struct hda_codec *codec, int idx)
2170 struct hda_gen_spec *spec = codec->spec;
2171 return snd_hda_get_path_from_idx(codec,
2172 spec->out_paths[spec->autocfg.line_outs + idx]);
2175 static void update_automute_all(struct hda_codec *codec);
2177 /* Default value to be passed as aamix argument for snd_hda_activate_path();
2178 * used for output paths
2180 static bool aamix_default(struct hda_gen_spec *spec)
2182 return !spec->have_aamix_ctl || spec->aamix_mode;
2185 static int set_multi_io(struct hda_codec *codec, int idx, bool output)
2187 struct hda_gen_spec *spec = codec->spec;
2188 hda_nid_t nid = spec->multi_io[idx].pin;
2189 struct nid_path *path;
2191 path = get_multiio_path(codec, idx);
2195 if (path->active == output)
2199 set_pin_target(codec, nid, PIN_OUT, true);
2200 snd_hda_activate_path(codec, path, true, aamix_default(spec));
2201 set_pin_eapd(codec, nid, true);
2203 set_pin_eapd(codec, nid, false);
2204 snd_hda_activate_path(codec, path, false, aamix_default(spec));
2205 set_pin_target(codec, nid, spec->multi_io[idx].ctl_in, true);
2206 path_power_down_sync(codec, path);
2209 /* update jack retasking in case it modifies any of them */
2210 update_automute_all(codec);
2215 static int ch_mode_put(struct snd_kcontrol *kcontrol,
2216 struct snd_ctl_elem_value *ucontrol)
2218 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2219 struct hda_gen_spec *spec = codec->spec;
2222 ch = ucontrol->value.enumerated.item[0];
2223 if (ch < 0 || ch > spec->multi_ios)
2225 if (ch == (spec->ext_channel_count - spec->min_channel_count) / 2)
2227 spec->ext_channel_count = ch * 2 + spec->min_channel_count;
2228 for (i = 0; i < spec->multi_ios; i++)
2229 set_multi_io(codec, i, i < ch);
2230 spec->multiout.max_channels = max(spec->ext_channel_count,
2231 spec->const_channel_count);
2232 if (spec->need_dac_fix)
2233 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
2237 static const struct snd_kcontrol_new channel_mode_enum = {
2238 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2239 .name = "Channel Mode",
2240 .info = ch_mode_info,
2245 static int create_multi_channel_mode(struct hda_codec *codec)
2247 struct hda_gen_spec *spec = codec->spec;
2249 if (spec->multi_ios > 0) {
2250 if (!snd_hda_gen_add_kctl(spec, NULL, &channel_mode_enum))
2257 * aamix loopback enable/disable switch
2260 #define loopback_mixing_info indep_hp_info
2262 static int loopback_mixing_get(struct snd_kcontrol *kcontrol,
2263 struct snd_ctl_elem_value *ucontrol)
2265 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2266 struct hda_gen_spec *spec = codec->spec;
2267 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2271 static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
2272 int nomix_path_idx, int mix_path_idx,
2275 struct hda_gen_spec *spec = codec->spec;
2276 struct nid_path *nomix_path, *mix_path;
2278 nomix_path = snd_hda_get_path_from_idx(codec, nomix_path_idx);
2279 mix_path = snd_hda_get_path_from_idx(codec, mix_path_idx);
2280 if (!nomix_path || !mix_path)
2283 /* if HP aamix path is driven from a different DAC and the
2284 * independent HP mode is ON, can't turn on aamix path
2286 if (out_type == AUTO_PIN_HP_OUT && spec->indep_hp_enabled &&
2287 mix_path->path[0] != spec->alt_dac_nid)
2291 snd_hda_activate_path(codec, nomix_path, false, true);
2292 snd_hda_activate_path(codec, mix_path, true, true);
2293 path_power_down_sync(codec, nomix_path);
2295 snd_hda_activate_path(codec, mix_path, false, false);
2296 snd_hda_activate_path(codec, nomix_path, true, false);
2297 path_power_down_sync(codec, mix_path);
2301 static int loopback_mixing_put(struct snd_kcontrol *kcontrol,
2302 struct snd_ctl_elem_value *ucontrol)
2304 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2305 struct hda_gen_spec *spec = codec->spec;
2306 unsigned int val = ucontrol->value.enumerated.item[0];
2308 if (val == spec->aamix_mode)
2310 spec->aamix_mode = val;
2311 update_aamix_paths(codec, val, spec->out_paths[0],
2312 spec->aamix_out_paths[0],
2313 spec->autocfg.line_out_type);
2314 update_aamix_paths(codec, val, spec->hp_paths[0],
2315 spec->aamix_out_paths[1],
2317 update_aamix_paths(codec, val, spec->speaker_paths[0],
2318 spec->aamix_out_paths[2],
2319 AUTO_PIN_SPEAKER_OUT);
2323 static const struct snd_kcontrol_new loopback_mixing_enum = {
2324 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2325 .name = "Loopback Mixing",
2326 .info = loopback_mixing_info,
2327 .get = loopback_mixing_get,
2328 .put = loopback_mixing_put,
2331 static int create_loopback_mixing_ctl(struct hda_codec *codec)
2333 struct hda_gen_spec *spec = codec->spec;
2335 if (!spec->mixer_nid)
2337 if (!(spec->aamix_out_paths[0] || spec->aamix_out_paths[1] ||
2338 spec->aamix_out_paths[2]))
2340 if (!snd_hda_gen_add_kctl(spec, NULL, &loopback_mixing_enum))
2342 spec->have_aamix_ctl = 1;
2347 * shared headphone/mic handling
2350 static void call_update_outputs(struct hda_codec *codec);
2352 /* for shared I/O, change the pin-control accordingly */
2353 static void update_hp_mic(struct hda_codec *codec, int adc_mux, bool force)
2355 struct hda_gen_spec *spec = codec->spec;
2360 pin = spec->hp_mic_pin;
2361 as_mic = spec->cur_mux[adc_mux] == spec->hp_mic_mux_idx;
2364 val = snd_hda_codec_get_pin_target(codec, pin);
2374 val = snd_hda_get_default_vref(codec, pin);
2375 /* if the HP pin doesn't support VREF and the codec driver gives an
2376 * alternative pin, set up the VREF on that pin instead
2378 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
2379 const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
2380 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
2381 if (vref_val != AC_PINCTL_VREF_HIZ)
2382 snd_hda_set_pin_ctl_cache(codec, vref_pin,
2383 PIN_IN | (as_mic ? vref_val : 0));
2386 if (!spec->hp_mic_jack_modes) {
2391 set_pin_target(codec, pin, val, true);
2392 call_hp_automute(codec, NULL);
2396 /* create a shared input with the headphone out */
2397 static int create_hp_mic(struct hda_codec *codec)
2399 struct hda_gen_spec *spec = codec->spec;
2400 struct auto_pin_cfg *cfg = &spec->autocfg;
2401 unsigned int defcfg;
2404 if (!spec->hp_mic) {
2405 if (spec->suppress_hp_mic_detect)
2407 /* automatic detection: only if no input or a single internal
2408 * input pin is found, try to detect the shared hp/mic
2410 if (cfg->num_inputs > 1)
2412 else if (cfg->num_inputs == 1) {
2413 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2414 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2419 spec->hp_mic = 0; /* clear once */
2420 if (cfg->num_inputs >= AUTO_CFG_MAX_INS)
2424 if (cfg->line_out_type == AUTO_PIN_HP_OUT && cfg->line_outs > 0)
2425 nid = cfg->line_out_pins[0];
2426 else if (cfg->hp_outs > 0)
2427 nid = cfg->hp_pins[0];
2431 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2432 return 0; /* no input */
2434 cfg->inputs[cfg->num_inputs].pin = nid;
2435 cfg->inputs[cfg->num_inputs].type = AUTO_PIN_MIC;
2436 cfg->inputs[cfg->num_inputs].is_headphone_mic = 1;
2439 spec->hp_mic_pin = nid;
2440 /* we can't handle auto-mic together with HP-mic */
2441 spec->suppress_auto_mic = 1;
2442 codec_dbg(codec, "Enable shared I/O jack on NID 0x%x\n", nid);
2450 static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin);
2452 static const char * const out_jack_texts[] = {
2453 "Line Out", "Headphone Out",
2456 static int out_jack_mode_info(struct snd_kcontrol *kcontrol,
2457 struct snd_ctl_elem_info *uinfo)
2459 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, out_jack_texts);
2462 static int out_jack_mode_get(struct snd_kcontrol *kcontrol,
2463 struct snd_ctl_elem_value *ucontrol)
2465 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2466 hda_nid_t nid = kcontrol->private_value;
2467 if (snd_hda_codec_get_pin_target(codec, nid) == PIN_HP)
2468 ucontrol->value.enumerated.item[0] = 1;
2470 ucontrol->value.enumerated.item[0] = 0;
2474 static int out_jack_mode_put(struct snd_kcontrol *kcontrol,
2475 struct snd_ctl_elem_value *ucontrol)
2477 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2478 hda_nid_t nid = kcontrol->private_value;
2481 val = ucontrol->value.enumerated.item[0] ? PIN_HP : PIN_OUT;
2482 if (snd_hda_codec_get_pin_target(codec, nid) == val)
2484 snd_hda_set_pin_ctl_cache(codec, nid, val);
2488 static const struct snd_kcontrol_new out_jack_mode_enum = {
2489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2490 .info = out_jack_mode_info,
2491 .get = out_jack_mode_get,
2492 .put = out_jack_mode_put,
2495 static bool find_kctl_name(struct hda_codec *codec, const char *name, int idx)
2497 struct hda_gen_spec *spec = codec->spec;
2500 for (i = 0; i < spec->kctls.used; i++) {
2501 struct snd_kcontrol_new *kctl = snd_array_elem(&spec->kctls, i);
2502 if (!strcmp(kctl->name, name) && kctl->index == idx)
2508 static void get_jack_mode_name(struct hda_codec *codec, hda_nid_t pin,
2509 char *name, size_t name_len)
2511 struct hda_gen_spec *spec = codec->spec;
2514 snd_hda_get_pin_label(codec, pin, &spec->autocfg, name, name_len, &idx);
2515 strlcat(name, " Jack Mode", name_len);
2517 for (; find_kctl_name(codec, name, idx); idx++)
2521 static int get_out_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2523 struct hda_gen_spec *spec = codec->spec;
2524 if (spec->add_jack_modes) {
2525 unsigned int pincap = snd_hda_query_pin_caps(codec, pin);
2526 if ((pincap & AC_PINCAP_OUT) && (pincap & AC_PINCAP_HP_DRV))
2532 static int create_out_jack_modes(struct hda_codec *codec, int num_pins,
2535 struct hda_gen_spec *spec = codec->spec;
2538 for (i = 0; i < num_pins; i++) {
2539 hda_nid_t pin = pins[i];
2540 if (pin == spec->hp_mic_pin)
2542 if (get_out_jack_num_items(codec, pin) > 1) {
2543 struct snd_kcontrol_new *knew;
2544 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
2545 get_jack_mode_name(codec, pin, name, sizeof(name));
2546 knew = snd_hda_gen_add_kctl(spec, name,
2547 &out_jack_mode_enum);
2550 knew->private_value = pin;
2561 /* from AC_PINCTL_VREF_HIZ to AC_PINCTL_VREF_100 */
2564 static const char * const vref_texts[NUM_VREFS] = {
2565 "Line In", "Mic 50pc Bias", "Mic 0V Bias",
2566 "", "Mic 80pc Bias", "Mic 100pc Bias"
2569 static unsigned int get_vref_caps(struct hda_codec *codec, hda_nid_t pin)
2571 unsigned int pincap;
2573 pincap = snd_hda_query_pin_caps(codec, pin);
2574 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2575 /* filter out unusual vrefs */
2576 pincap &= ~(AC_PINCAP_VREF_GRD | AC_PINCAP_VREF_100);
2580 /* convert from the enum item index to the vref ctl index (0=HIZ, 1=50%...) */
2581 static int get_vref_idx(unsigned int vref_caps, unsigned int item_idx)
2583 unsigned int i, n = 0;
2585 for (i = 0; i < NUM_VREFS; i++) {
2586 if (vref_caps & (1 << i)) {
2595 /* convert back from the vref ctl index to the enum item index */
2596 static int cvt_from_vref_idx(unsigned int vref_caps, unsigned int idx)
2598 unsigned int i, n = 0;
2600 for (i = 0; i < NUM_VREFS; i++) {
2603 if (vref_caps & (1 << i))
2609 static int in_jack_mode_info(struct snd_kcontrol *kcontrol,
2610 struct snd_ctl_elem_info *uinfo)
2612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2613 hda_nid_t nid = kcontrol->private_value;
2614 unsigned int vref_caps = get_vref_caps(codec, nid);
2616 snd_hda_enum_helper_info(kcontrol, uinfo, hweight32(vref_caps),
2618 /* set the right text */
2619 strcpy(uinfo->value.enumerated.name,
2620 vref_texts[get_vref_idx(vref_caps, uinfo->value.enumerated.item)]);
2624 static int in_jack_mode_get(struct snd_kcontrol *kcontrol,
2625 struct snd_ctl_elem_value *ucontrol)
2627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2628 hda_nid_t nid = kcontrol->private_value;
2629 unsigned int vref_caps = get_vref_caps(codec, nid);
2632 idx = snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_VREFEN;
2633 ucontrol->value.enumerated.item[0] = cvt_from_vref_idx(vref_caps, idx);
2637 static int in_jack_mode_put(struct snd_kcontrol *kcontrol,
2638 struct snd_ctl_elem_value *ucontrol)
2640 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2641 hda_nid_t nid = kcontrol->private_value;
2642 unsigned int vref_caps = get_vref_caps(codec, nid);
2643 unsigned int val, idx;
2645 val = snd_hda_codec_get_pin_target(codec, nid);
2646 idx = cvt_from_vref_idx(vref_caps, val & AC_PINCTL_VREFEN);
2647 if (idx == ucontrol->value.enumerated.item[0])
2650 val &= ~AC_PINCTL_VREFEN;
2651 val |= get_vref_idx(vref_caps, ucontrol->value.enumerated.item[0]);
2652 snd_hda_set_pin_ctl_cache(codec, nid, val);
2656 static const struct snd_kcontrol_new in_jack_mode_enum = {
2657 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2658 .info = in_jack_mode_info,
2659 .get = in_jack_mode_get,
2660 .put = in_jack_mode_put,
2663 static int get_in_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2665 struct hda_gen_spec *spec = codec->spec;
2667 if (spec->add_jack_modes)
2668 nitems = hweight32(get_vref_caps(codec, pin));
2669 return nitems ? nitems : 1;
2672 static int create_in_jack_mode(struct hda_codec *codec, hda_nid_t pin)
2674 struct hda_gen_spec *spec = codec->spec;
2675 struct snd_kcontrol_new *knew;
2676 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
2677 unsigned int defcfg;
2679 if (pin == spec->hp_mic_pin)
2680 return 0; /* already done in create_out_jack_mode() */
2682 /* no jack mode for fixed pins */
2683 defcfg = snd_hda_codec_get_pincfg(codec, pin);
2684 if (snd_hda_get_input_pin_attr(defcfg) == INPUT_PIN_ATTR_INT)
2687 /* no multiple vref caps? */
2688 if (get_in_jack_num_items(codec, pin) <= 1)
2691 get_jack_mode_name(codec, pin, name, sizeof(name));
2692 knew = snd_hda_gen_add_kctl(spec, name, &in_jack_mode_enum);
2695 knew->private_value = pin;
2700 * HP/mic shared jack mode
2702 static int hp_mic_jack_mode_info(struct snd_kcontrol *kcontrol,
2703 struct snd_ctl_elem_info *uinfo)
2705 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2706 hda_nid_t nid = kcontrol->private_value;
2707 int out_jacks = get_out_jack_num_items(codec, nid);
2708 int in_jacks = get_in_jack_num_items(codec, nid);
2709 const char *text = NULL;
2712 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2714 uinfo->value.enumerated.items = out_jacks + in_jacks;
2715 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2716 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2717 idx = uinfo->value.enumerated.item;
2718 if (idx < out_jacks) {
2720 text = out_jack_texts[idx];
2722 text = "Headphone Out";
2726 unsigned int vref_caps = get_vref_caps(codec, nid);
2727 text = vref_texts[get_vref_idx(vref_caps, idx)];
2732 strcpy(uinfo->value.enumerated.name, text);
2736 static int get_cur_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t nid)
2738 int out_jacks = get_out_jack_num_items(codec, nid);
2739 int in_jacks = get_in_jack_num_items(codec, nid);
2740 unsigned int val = snd_hda_codec_get_pin_target(codec, nid);
2743 if (val & PIN_OUT) {
2744 if (out_jacks > 1 && val == PIN_HP)
2746 } else if (val & PIN_IN) {
2749 unsigned int vref_caps = get_vref_caps(codec, nid);
2750 val &= AC_PINCTL_VREFEN;
2751 idx += cvt_from_vref_idx(vref_caps, val);
2757 static int hp_mic_jack_mode_get(struct snd_kcontrol *kcontrol,
2758 struct snd_ctl_elem_value *ucontrol)
2760 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2761 hda_nid_t nid = kcontrol->private_value;
2762 ucontrol->value.enumerated.item[0] =
2763 get_cur_hp_mic_jack_mode(codec, nid);
2767 static int hp_mic_jack_mode_put(struct snd_kcontrol *kcontrol,
2768 struct snd_ctl_elem_value *ucontrol)
2770 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2771 hda_nid_t nid = kcontrol->private_value;
2772 int out_jacks = get_out_jack_num_items(codec, nid);
2773 int in_jacks = get_in_jack_num_items(codec, nid);
2774 unsigned int val, oldval, idx;
2776 oldval = get_cur_hp_mic_jack_mode(codec, nid);
2777 idx = ucontrol->value.enumerated.item[0];
2781 if (idx < out_jacks) {
2783 val = idx ? PIN_HP : PIN_OUT;
2789 unsigned int vref_caps = get_vref_caps(codec, nid);
2790 val = snd_hda_codec_get_pin_target(codec, nid);
2791 val &= ~(AC_PINCTL_VREFEN | PIN_HP);
2792 val |= get_vref_idx(vref_caps, idx) | PIN_IN;
2794 val = snd_hda_get_default_vref(codec, nid) | PIN_IN;
2796 snd_hda_set_pin_ctl_cache(codec, nid, val);
2797 call_hp_automute(codec, NULL);
2802 static const struct snd_kcontrol_new hp_mic_jack_mode_enum = {
2803 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2804 .info = hp_mic_jack_mode_info,
2805 .get = hp_mic_jack_mode_get,
2806 .put = hp_mic_jack_mode_put,
2809 static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin)
2811 struct hda_gen_spec *spec = codec->spec;
2812 struct snd_kcontrol_new *knew;
2814 knew = snd_hda_gen_add_kctl(spec, "Headphone Mic Jack Mode",
2815 &hp_mic_jack_mode_enum);
2818 knew->private_value = pin;
2819 spec->hp_mic_jack_modes = 1;
2827 /* add the powersave loopback-list entry */
2828 static int add_loopback_list(struct hda_gen_spec *spec, hda_nid_t mix, int idx)
2830 struct hda_amp_list *list;
2832 list = snd_array_new(&spec->loopback_list);
2836 list->dir = HDA_INPUT;
2838 spec->loopback.amplist = spec->loopback_list.list;
2842 /* return true if either a volume or a mute amp is found for the given
2843 * aamix path; the amp has to be either in the mixer node or its direct leaf
2845 static bool look_for_mix_leaf_ctls(struct hda_codec *codec, hda_nid_t mix_nid,
2846 hda_nid_t pin, unsigned int *mix_val,
2847 unsigned int *mute_val)
2850 const hda_nid_t *list;
2853 idx = snd_hda_get_conn_index(codec, mix_nid, pin, true);
2857 *mix_val = *mute_val = 0;
2858 if (nid_has_volume(codec, mix_nid, HDA_INPUT))
2859 *mix_val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2860 if (nid_has_mute(codec, mix_nid, HDA_INPUT))
2861 *mute_val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2862 if (*mix_val && *mute_val)
2865 /* check leaf node */
2866 num_conns = snd_hda_get_conn_list(codec, mix_nid, &list);
2867 if (num_conns < idx)
2870 if (!*mix_val && nid_has_volume(codec, nid, HDA_OUTPUT) &&
2871 !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_VOL_CTL))
2872 *mix_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2873 if (!*mute_val && nid_has_mute(codec, nid, HDA_OUTPUT) &&
2874 !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_MUTE_CTL))
2875 *mute_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2877 return *mix_val || *mute_val;
2880 /* create input playback/capture controls for the given pin */
2881 static int new_analog_input(struct hda_codec *codec, int input_idx,
2882 hda_nid_t pin, const char *ctlname, int ctlidx,
2885 struct hda_gen_spec *spec = codec->spec;
2886 struct nid_path *path;
2887 unsigned int mix_val, mute_val;
2890 if (!look_for_mix_leaf_ctls(codec, mix_nid, pin, &mix_val, &mute_val))
2893 path = snd_hda_add_new_path(codec, pin, mix_nid, 0);
2896 print_nid_path(codec, "loopback", path);
2897 spec->loopback_paths[input_idx] = snd_hda_get_path_idx(codec, path);
2899 idx = path->idx[path->depth - 1];
2901 err = __add_pb_vol_ctrl(spec, HDA_CTL_WIDGET_VOL, ctlname, ctlidx, mix_val);
2904 path->ctls[NID_PATH_VOL_CTL] = mix_val;
2908 err = __add_pb_sw_ctrl(spec, HDA_CTL_WIDGET_MUTE, ctlname, ctlidx, mute_val);
2911 path->ctls[NID_PATH_MUTE_CTL] = mute_val;
2914 path->active = true;
2915 err = add_loopback_list(spec, mix_nid, idx);
2919 if (spec->mixer_nid != spec->mixer_merge_nid &&
2920 !spec->loopback_merge_path) {
2921 path = snd_hda_add_new_path(codec, spec->mixer_nid,
2922 spec->mixer_merge_nid, 0);
2924 print_nid_path(codec, "loopback-merge", path);
2925 path->active = true;
2926 spec->loopback_merge_path =
2927 snd_hda_get_path_idx(codec, path);
2934 static int is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2936 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2937 return (pincap & AC_PINCAP_IN) != 0;
2940 /* Parse the codec tree and retrieve ADCs */
2941 static int fill_adc_nids(struct hda_codec *codec)
2943 struct hda_gen_spec *spec = codec->spec;
2945 hda_nid_t *adc_nids = spec->adc_nids;
2946 int max_nums = ARRAY_SIZE(spec->adc_nids);
2949 nid = codec->start_nid;
2950 for (i = 0; i < codec->num_nodes; i++, nid++) {
2951 unsigned int caps = get_wcaps(codec, nid);
2952 int type = get_wcaps_type(caps);
2954 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2956 adc_nids[nums] = nid;
2957 if (++nums >= max_nums)
2960 spec->num_adc_nids = nums;
2962 /* copy the detected ADCs to all_adcs[] */
2963 spec->num_all_adcs = nums;
2964 memcpy(spec->all_adcs, spec->adc_nids, nums * sizeof(hda_nid_t));
2969 /* filter out invalid adc_nids that don't give all active input pins;
2970 * if needed, check whether dynamic ADC-switching is available
2972 static int check_dyn_adc_switch(struct hda_codec *codec)
2974 struct hda_gen_spec *spec = codec->spec;
2975 struct hda_input_mux *imux = &spec->input_mux;
2976 unsigned int ok_bits;
2981 for (n = 0; n < spec->num_adc_nids; n++) {
2982 for (i = 0; i < imux->num_items; i++) {
2983 if (!spec->input_paths[i][n])
2986 if (i >= imux->num_items) {
2987 ok_bits |= (1 << n);
2993 /* check whether ADC-switch is possible */
2994 for (i = 0; i < imux->num_items; i++) {
2995 for (n = 0; n < spec->num_adc_nids; n++) {
2996 if (spec->input_paths[i][n]) {
2997 spec->dyn_adc_idx[i] = n;
3003 codec_dbg(codec, "enabling ADC switching\n");
3004 spec->dyn_adc_switch = 1;
3005 } else if (nums != spec->num_adc_nids) {
3006 /* shrink the invalid adcs and input paths */
3008 for (n = 0; n < spec->num_adc_nids; n++) {
3009 if (!(ok_bits & (1 << n)))
3012 spec->adc_nids[nums] = spec->adc_nids[n];
3013 for (i = 0; i < imux->num_items; i++) {
3014 invalidate_nid_path(codec,
3015 spec->input_paths[i][nums]);
3016 spec->input_paths[i][nums] =
3017 spec->input_paths[i][n];
3022 spec->num_adc_nids = nums;
3025 if (imux->num_items == 1 ||
3026 (imux->num_items == 2 && spec->hp_mic)) {
3027 codec_dbg(codec, "reducing to a single ADC\n");
3028 spec->num_adc_nids = 1; /* reduce to a single ADC */
3031 /* single index for individual volumes ctls */
3032 if (!spec->dyn_adc_switch && spec->multi_cap_vol)
3033 spec->num_adc_nids = 1;
3038 /* parse capture source paths from the given pin and create imux items */
3039 static int parse_capture_source(struct hda_codec *codec, hda_nid_t pin,
3040 int cfg_idx, int num_adcs,
3041 const char *label, int anchor)
3043 struct hda_gen_spec *spec = codec->spec;
3044 struct hda_input_mux *imux = &spec->input_mux;
3045 int imux_idx = imux->num_items;
3046 bool imux_added = false;
3049 for (c = 0; c < num_adcs; c++) {
3050 struct nid_path *path;
3051 hda_nid_t adc = spec->adc_nids[c];
3053 if (!is_reachable_path(codec, pin, adc))
3055 path = snd_hda_add_new_path(codec, pin, adc, anchor);
3058 print_nid_path(codec, "input", path);
3059 spec->input_paths[imux_idx][c] =
3060 snd_hda_get_path_idx(codec, path);
3063 if (spec->hp_mic_pin == pin)
3064 spec->hp_mic_mux_idx = imux->num_items;
3065 spec->imux_pins[imux->num_items] = pin;
3066 snd_hda_add_imux_item(codec, imux, label, cfg_idx, NULL);
3068 if (spec->dyn_adc_switch)
3069 spec->dyn_adc_idx[imux_idx] = c;
3077 * create playback/capture controls for input pins
3080 /* fill the label for each input at first */
3081 static int fill_input_pin_labels(struct hda_codec *codec)
3083 struct hda_gen_spec *spec = codec->spec;
3084 const struct auto_pin_cfg *cfg = &spec->autocfg;
3087 for (i = 0; i < cfg->num_inputs; i++) {
3088 hda_nid_t pin = cfg->inputs[i].pin;
3092 if (!is_input_pin(codec, pin))
3095 label = hda_get_autocfg_input_label(codec, cfg, i);
3097 for (j = i - 1; j >= 0; j--) {
3098 if (spec->input_labels[j] &&
3099 !strcmp(spec->input_labels[j], label)) {
3100 idx = spec->input_label_idxs[j] + 1;
3105 spec->input_labels[i] = label;
3106 spec->input_label_idxs[i] = idx;
3112 #define CFG_IDX_MIX 99 /* a dummy cfg->input idx for stereo mix */
3114 static int create_input_ctls(struct hda_codec *codec)
3116 struct hda_gen_spec *spec = codec->spec;
3117 const struct auto_pin_cfg *cfg = &spec->autocfg;
3118 hda_nid_t mixer = spec->mixer_nid;
3123 num_adcs = fill_adc_nids(codec);
3127 err = fill_input_pin_labels(codec);
3131 for (i = 0; i < cfg->num_inputs; i++) {
3134 pin = cfg->inputs[i].pin;
3135 if (!is_input_pin(codec, pin))
3139 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3140 val |= snd_hda_get_default_vref(codec, pin);
3141 if (pin != spec->hp_mic_pin)
3142 set_pin_target(codec, pin, val, false);
3145 if (is_reachable_path(codec, pin, mixer)) {
3146 err = new_analog_input(codec, i, pin,
3147 spec->input_labels[i],
3148 spec->input_label_idxs[i],
3155 err = parse_capture_source(codec, pin, i, num_adcs,
3156 spec->input_labels[i], -mixer);
3160 if (spec->add_jack_modes) {
3161 err = create_in_jack_mode(codec, pin);
3167 /* add stereo mix when explicitly enabled via hint */
3168 if (mixer && spec->add_stereo_mix_input &&
3169 snd_hda_get_bool_hint(codec, "add_stereo_mix_input") > 0) {
3170 err = parse_capture_source(codec, mixer, CFG_IDX_MIX, num_adcs,
3184 /* get the input path specified by the given adc and imux indices */
3185 static struct nid_path *get_input_path(struct hda_codec *codec, int adc_idx, int imux_idx)
3187 struct hda_gen_spec *spec = codec->spec;
3188 if (imux_idx < 0 || imux_idx >= HDA_MAX_NUM_INPUTS) {
3192 if (spec->dyn_adc_switch)
3193 adc_idx = spec->dyn_adc_idx[imux_idx];
3194 if (adc_idx < 0 || adc_idx >= AUTO_CFG_MAX_INS) {
3198 return snd_hda_get_path_from_idx(codec, spec->input_paths[imux_idx][adc_idx]);
3201 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3204 static int mux_enum_info(struct snd_kcontrol *kcontrol,
3205 struct snd_ctl_elem_info *uinfo)
3207 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3208 struct hda_gen_spec *spec = codec->spec;
3209 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
3212 static int mux_enum_get(struct snd_kcontrol *kcontrol,
3213 struct snd_ctl_elem_value *ucontrol)
3215 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3216 struct hda_gen_spec *spec = codec->spec;
3217 /* the ctls are created at once with multiple counts */
3218 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
3220 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
3224 static int mux_enum_put(struct snd_kcontrol *kcontrol,
3225 struct snd_ctl_elem_value *ucontrol)
3227 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3228 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
3229 return mux_select(codec, adc_idx,
3230 ucontrol->value.enumerated.item[0]);
3233 static const struct snd_kcontrol_new cap_src_temp = {
3234 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3235 .name = "Input Source",
3236 .info = mux_enum_info,
3237 .get = mux_enum_get,
3238 .put = mux_enum_put,
3242 * capture volume and capture switch ctls
3245 typedef int (*put_call_t)(struct snd_kcontrol *kcontrol,
3246 struct snd_ctl_elem_value *ucontrol);
3248 /* call the given amp update function for all amps in the imux list at once */
3249 static int cap_put_caller(struct snd_kcontrol *kcontrol,
3250 struct snd_ctl_elem_value *ucontrol,
3251 put_call_t func, int type)
3253 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3254 struct hda_gen_spec *spec = codec->spec;
3255 const struct hda_input_mux *imux;
3256 struct nid_path *path;
3257 int i, adc_idx, err = 0;
3259 imux = &spec->input_mux;
3260 adc_idx = kcontrol->id.index;
3261 mutex_lock(&codec->control_mutex);
3262 /* we use the cache-only update at first since multiple input paths
3263 * may shared the same amp; by updating only caches, the redundant
3264 * writes to hardware can be reduced.
3266 codec->cached_write = 1;
3267 for (i = 0; i < imux->num_items; i++) {
3268 path = get_input_path(codec, adc_idx, i);
3269 if (!path || !path->ctls[type])
3271 kcontrol->private_value = path->ctls[type];
3272 err = func(kcontrol, ucontrol);
3277 codec->cached_write = 0;
3278 mutex_unlock(&codec->control_mutex);
3279 snd_hda_codec_flush_cache(codec); /* flush the updates */
3280 if (err >= 0 && spec->cap_sync_hook)
3281 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3285 /* capture volume ctl callbacks */
3286 #define cap_vol_info snd_hda_mixer_amp_volume_info
3287 #define cap_vol_get snd_hda_mixer_amp_volume_get
3288 #define cap_vol_tlv snd_hda_mixer_amp_tlv
3290 static int cap_vol_put(struct snd_kcontrol *kcontrol,
3291 struct snd_ctl_elem_value *ucontrol)
3293 return cap_put_caller(kcontrol, ucontrol,
3294 snd_hda_mixer_amp_volume_put,
3298 static const struct snd_kcontrol_new cap_vol_temp = {
3299 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3300 .name = "Capture Volume",
3301 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
3302 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
3303 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
3304 .info = cap_vol_info,
3307 .tlv = { .c = cap_vol_tlv },
3310 /* capture switch ctl callbacks */
3311 #define cap_sw_info snd_ctl_boolean_stereo_info
3312 #define cap_sw_get snd_hda_mixer_amp_switch_get
3314 static int cap_sw_put(struct snd_kcontrol *kcontrol,
3315 struct snd_ctl_elem_value *ucontrol)
3317 return cap_put_caller(kcontrol, ucontrol,
3318 snd_hda_mixer_amp_switch_put,
3322 static const struct snd_kcontrol_new cap_sw_temp = {
3323 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3324 .name = "Capture Switch",
3325 .info = cap_sw_info,
3330 static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
3335 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
3336 for (depth = 0; depth < 3; depth++) {
3337 if (depth >= path->depth)
3339 i = path->depth - depth - 1;
3340 nid = path->path[i];
3341 if (!path->ctls[NID_PATH_VOL_CTL]) {
3342 if (nid_has_volume(codec, nid, HDA_OUTPUT))
3343 path->ctls[NID_PATH_VOL_CTL] =
3344 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3345 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
3346 int idx = path->idx[i];
3347 if (!depth && codec->single_adc_amp)
3349 path->ctls[NID_PATH_VOL_CTL] =
3350 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
3353 if (!path->ctls[NID_PATH_MUTE_CTL]) {
3354 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3355 path->ctls[NID_PATH_MUTE_CTL] =
3356 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3357 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
3358 int idx = path->idx[i];
3359 if (!depth && codec->single_adc_amp)
3361 path->ctls[NID_PATH_MUTE_CTL] =
3362 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
3369 static bool is_inv_dmic_pin(struct hda_codec *codec, hda_nid_t nid)
3371 struct hda_gen_spec *spec = codec->spec;
3372 struct auto_pin_cfg *cfg = &spec->autocfg;
3376 if (!spec->inv_dmic_split)
3378 for (i = 0; i < cfg->num_inputs; i++) {
3379 if (cfg->inputs[i].pin != nid)
3381 if (cfg->inputs[i].type != AUTO_PIN_MIC)
3383 val = snd_hda_codec_get_pincfg(codec, nid);
3384 return snd_hda_get_input_pin_attr(val) == INPUT_PIN_ATTR_INT;
3389 /* capture switch put callback for a single control with hook call */
3390 static int cap_single_sw_put(struct snd_kcontrol *kcontrol,
3391 struct snd_ctl_elem_value *ucontrol)
3393 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3394 struct hda_gen_spec *spec = codec->spec;
3397 ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3401 if (spec->cap_sync_hook)
3402 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3407 static int add_single_cap_ctl(struct hda_codec *codec, const char *label,
3408 int idx, bool is_switch, unsigned int ctl,
3411 struct hda_gen_spec *spec = codec->spec;
3412 char tmpname[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3413 int type = is_switch ? HDA_CTL_WIDGET_MUTE : HDA_CTL_WIDGET_VOL;
3414 const char *sfx = is_switch ? "Switch" : "Volume";
3415 unsigned int chs = inv_dmic ? 1 : 3;
3416 struct snd_kcontrol_new *knew;
3422 snprintf(tmpname, sizeof(tmpname),
3423 "%s Capture %s", label, sfx);
3425 snprintf(tmpname, sizeof(tmpname),
3427 knew = add_control(spec, type, tmpname, idx,
3428 amp_val_replace_channels(ctl, chs));
3432 knew->put = cap_single_sw_put;
3436 /* Make independent right kcontrol */
3438 snprintf(tmpname, sizeof(tmpname),
3439 "Inverted %s Capture %s", label, sfx);
3441 snprintf(tmpname, sizeof(tmpname),
3442 "Inverted Capture %s", sfx);
3443 knew = add_control(spec, type, tmpname, idx,
3444 amp_val_replace_channels(ctl, 2));
3448 knew->put = cap_single_sw_put;
3452 /* create single (and simple) capture volume and switch controls */
3453 static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx,
3454 unsigned int vol_ctl, unsigned int sw_ctl,
3458 err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl, inv_dmic);
3461 err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl, inv_dmic);
3467 /* create bound capture volume and switch controls */
3468 static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx,
3469 unsigned int vol_ctl, unsigned int sw_ctl)
3471 struct hda_gen_spec *spec = codec->spec;
3472 struct snd_kcontrol_new *knew;
3475 knew = snd_hda_gen_add_kctl(spec, NULL, &cap_vol_temp);
3479 knew->private_value = vol_ctl;
3480 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
3483 knew = snd_hda_gen_add_kctl(spec, NULL, &cap_sw_temp);
3487 knew->private_value = sw_ctl;
3488 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
3493 /* return the vol ctl when used first in the imux list */
3494 static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type)
3496 struct nid_path *path;
3500 path = get_input_path(codec, 0, idx);
3503 ctl = path->ctls[type];
3506 for (i = 0; i < idx - 1; i++) {
3507 path = get_input_path(codec, 0, i);
3508 if (path && path->ctls[type] == ctl)
3514 /* create individual capture volume and switch controls per input */
3515 static int create_multi_cap_vol_ctl(struct hda_codec *codec)
3517 struct hda_gen_spec *spec = codec->spec;
3518 struct hda_input_mux *imux = &spec->input_mux;
3521 for (i = 0; i < imux->num_items; i++) {
3525 idx = imux->items[i].index;
3526 if (idx >= spec->autocfg.num_inputs)
3528 inv_dmic = is_inv_dmic_pin(codec, spec->imux_pins[i]);
3530 for (type = 0; type < 2; type++) {
3531 err = add_single_cap_ctl(codec,
3532 spec->input_labels[idx],
3533 spec->input_label_idxs[idx],
3535 get_first_cap_ctl(codec, i, type),
3544 static int create_capture_mixers(struct hda_codec *codec)
3546 struct hda_gen_spec *spec = codec->spec;
3547 struct hda_input_mux *imux = &spec->input_mux;
3548 int i, n, nums, err;
3550 if (spec->dyn_adc_switch)
3553 nums = spec->num_adc_nids;
3555 if (!spec->auto_mic && imux->num_items > 1) {
3556 struct snd_kcontrol_new *knew;
3558 name = nums > 1 ? "Input Source" : "Capture Source";
3559 knew = snd_hda_gen_add_kctl(spec, name, &cap_src_temp);
3565 for (n = 0; n < nums; n++) {
3567 bool multi_cap_vol = spec->multi_cap_vol;
3568 bool inv_dmic = false;
3572 for (i = 0; i < imux->num_items; i++) {
3573 struct nid_path *path;
3574 path = get_input_path(codec, n, i);
3577 parse_capvol_in_path(codec, path);
3579 vol = path->ctls[NID_PATH_VOL_CTL];
3580 else if (vol != path->ctls[NID_PATH_VOL_CTL]) {
3582 if (!same_amp_caps(codec, vol,
3583 path->ctls[NID_PATH_VOL_CTL], HDA_INPUT))
3584 multi_cap_vol = true;
3587 sw = path->ctls[NID_PATH_MUTE_CTL];
3588 else if (sw != path->ctls[NID_PATH_MUTE_CTL]) {
3590 if (!same_amp_caps(codec, sw,
3591 path->ctls[NID_PATH_MUTE_CTL], HDA_INPUT))
3592 multi_cap_vol = true;
3594 if (is_inv_dmic_pin(codec, spec->imux_pins[i]))
3599 err = create_single_cap_vol_ctl(codec, n, vol, sw,
3601 else if (!multi_cap_vol && !inv_dmic)
3602 err = create_bind_cap_vol_ctl(codec, n, vol, sw);
3604 err = create_multi_cap_vol_ctl(codec);
3613 * add mic boosts if needed
3616 /* check whether the given amp is feasible as a boost volume */
3617 static bool check_boost_vol(struct hda_codec *codec, hda_nid_t nid,
3622 if (!nid_has_volume(codec, nid, dir) ||
3623 is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
3624 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
3627 step = (query_amp_caps(codec, nid, dir) & AC_AMPCAP_STEP_SIZE)
3628 >> AC_AMPCAP_STEP_SIZE_SHIFT;
3634 /* look for a boost amp in a widget close to the pin */
3635 static unsigned int look_for_boost_amp(struct hda_codec *codec,
3636 struct nid_path *path)
3638 unsigned int val = 0;
3642 for (depth = 0; depth < 3; depth++) {
3643 if (depth >= path->depth - 1)
3645 nid = path->path[depth];
3646 if (depth && check_boost_vol(codec, nid, HDA_OUTPUT, 0)) {
3647 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3649 } else if (check_boost_vol(codec, nid, HDA_INPUT,
3650 path->idx[depth])) {
3651 val = HDA_COMPOSE_AMP_VAL(nid, 3, path->idx[depth],
3660 static int parse_mic_boost(struct hda_codec *codec)
3662 struct hda_gen_spec *spec = codec->spec;
3663 struct auto_pin_cfg *cfg = &spec->autocfg;
3664 struct hda_input_mux *imux = &spec->input_mux;
3667 if (!spec->num_adc_nids)
3670 for (i = 0; i < imux->num_items; i++) {
3671 struct nid_path *path;
3674 char boost_label[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3676 idx = imux->items[i].index;
3677 if (idx >= imux->num_items)
3680 /* check only line-in and mic pins */
3681 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
3684 path = get_input_path(codec, 0, i);
3688 val = look_for_boost_amp(codec, path);
3692 /* create a boost control */
3693 snprintf(boost_label, sizeof(boost_label),
3694 "%s Boost Volume", spec->input_labels[idx]);
3695 if (!add_control(spec, HDA_CTL_WIDGET_VOL, boost_label,
3696 spec->input_label_idxs[idx], val))
3699 path->ctls[NID_PATH_BOOST_CTL] = val;
3705 * parse digital I/Os and set up NIDs in BIOS auto-parse mode
3707 static void parse_digital(struct hda_codec *codec)
3709 struct hda_gen_spec *spec = codec->spec;
3710 struct nid_path *path;
3712 hda_nid_t dig_nid, pin;
3714 /* support multiple SPDIFs; the secondary is set up as a slave */
3716 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3717 pin = spec->autocfg.dig_out_pins[i];
3718 dig_nid = look_for_dac(codec, pin, true);
3721 path = snd_hda_add_new_path(codec, dig_nid, pin, 0);
3724 print_nid_path(codec, "digout", path);
3725 path->active = true;
3726 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
3727 set_pin_target(codec, pin, PIN_OUT, false);
3729 spec->multiout.dig_out_nid = dig_nid;
3730 spec->dig_out_type = spec->autocfg.dig_out_type[0];
3732 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
3733 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
3735 spec->slave_dig_outs[nums - 1] = dig_nid;
3740 if (spec->autocfg.dig_in_pin) {
3741 pin = spec->autocfg.dig_in_pin;
3742 dig_nid = codec->start_nid;
3743 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3744 unsigned int wcaps = get_wcaps(codec, dig_nid);
3745 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3747 if (!(wcaps & AC_WCAP_DIGITAL))
3749 path = snd_hda_add_new_path(codec, pin, dig_nid, 0);
3751 print_nid_path(codec, "digin", path);
3752 path->active = true;
3753 spec->dig_in_nid = dig_nid;
3754 spec->digin_path = snd_hda_get_path_idx(codec, path);
3755 set_pin_target(codec, pin, PIN_IN, false);
3764 * input MUX handling
3767 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur);
3769 /* select the given imux item; either unmute exclusively or select the route */
3770 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3773 struct hda_gen_spec *spec = codec->spec;
3774 const struct hda_input_mux *imux;
3775 struct nid_path *old_path, *path;
3777 imux = &spec->input_mux;
3778 if (!imux->num_items)
3781 if (idx >= imux->num_items)
3782 idx = imux->num_items - 1;
3783 if (spec->cur_mux[adc_idx] == idx)
3786 old_path = get_input_path(codec, adc_idx, spec->cur_mux[adc_idx]);
3789 if (old_path->active)
3790 snd_hda_activate_path(codec, old_path, false, false);
3792 spec->cur_mux[adc_idx] = idx;
3795 update_hp_mic(codec, adc_idx, false);
3797 if (spec->dyn_adc_switch)
3798 dyn_adc_pcm_resetup(codec, idx);
3800 path = get_input_path(codec, adc_idx, idx);
3805 snd_hda_activate_path(codec, path, true, false);
3806 if (spec->cap_sync_hook)
3807 spec->cap_sync_hook(codec, NULL, NULL);
3808 path_power_down_sync(codec, old_path);
3814 * Jack detections for HP auto-mute and mic-switch
3817 /* check each pin in the given array; returns true if any of them is plugged */
3818 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3821 bool present = false;
3823 for (i = 0; i < num_pins; i++) {
3824 hda_nid_t nid = pins[i];
3827 /* don't detect pins retasked as inputs */
3828 if (snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_IN_EN)
3830 if (snd_hda_jack_detect_state(codec, nid) == HDA_JACK_PRESENT)
3836 /* standard HP/line-out auto-mute helper */
3837 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
3838 int *paths, bool mute)
3840 struct hda_gen_spec *spec = codec->spec;
3843 for (i = 0; i < num_pins; i++) {
3844 hda_nid_t nid = pins[i];
3845 unsigned int val, oldval;
3849 if (spec->auto_mute_via_amp) {
3850 struct nid_path *path;
3853 path = snd_hda_get_path_from_idx(codec, paths[i]);
3856 mute_nid = get_amp_nid_(path->ctls[NID_PATH_MUTE_CTL]);
3860 spec->mute_bits |= (1ULL << mute_nid);
3862 spec->mute_bits &= ~(1ULL << mute_nid);
3863 set_pin_eapd(codec, nid, !mute);
3867 oldval = snd_hda_codec_get_pin_target(codec, nid);
3868 if (oldval & PIN_IN)
3869 continue; /* no mute for inputs */
3870 /* don't reset VREF value in case it's controlling
3871 * the amp (see alc861_fixup_asus_amp_vref_0f())
3873 if (spec->keep_vref_in_automute)
3874 val = oldval & ~PIN_HP;
3879 /* here we call update_pin_ctl() so that the pinctl is changed
3880 * without changing the pinctl target value;
3881 * the original target value will be still referred at the
3882 * init / resume again
3884 update_pin_ctl(codec, nid, val);
3885 set_pin_eapd(codec, nid, !mute);
3889 /* Toggle outputs muting */
3890 void snd_hda_gen_update_outputs(struct hda_codec *codec)
3892 struct hda_gen_spec *spec = codec->spec;
3896 /* Control HP pins/amps depending on master_mute state;
3897 * in general, HP pins/amps control should be enabled in all cases,
3898 * but currently set only for master_mute, just to be safe
3900 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3901 paths = spec->out_paths;
3903 paths = spec->hp_paths;
3904 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
3905 spec->autocfg.hp_pins, paths, spec->master_mute);
3907 if (!spec->automute_speaker)
3910 on = spec->hp_jack_present | spec->line_jack_present;
3911 on |= spec->master_mute;
3912 spec->speaker_muted = on;
3913 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3914 paths = spec->out_paths;
3916 paths = spec->speaker_paths;
3917 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
3918 spec->autocfg.speaker_pins, paths, on);
3920 /* toggle line-out mutes if needed, too */
3921 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3922 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
3923 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
3925 if (!spec->automute_lo)
3928 on = spec->hp_jack_present;
3929 on |= spec->master_mute;
3930 spec->line_out_muted = on;
3931 paths = spec->out_paths;
3932 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
3933 spec->autocfg.line_out_pins, paths, on);
3935 EXPORT_SYMBOL_GPL(snd_hda_gen_update_outputs);
3937 static void call_update_outputs(struct hda_codec *codec)
3939 struct hda_gen_spec *spec = codec->spec;
3940 if (spec->automute_hook)
3941 spec->automute_hook(codec);
3943 snd_hda_gen_update_outputs(codec);
3945 /* sync the whole vmaster slaves to reflect the new auto-mute status */
3946 if (spec->auto_mute_via_amp && !codec->bus->shutdown)
3947 snd_ctl_sync_vmaster(spec->vmaster_mute.sw_kctl, false);
3950 /* standard HP-automute helper */
3951 void snd_hda_gen_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
3953 struct hda_gen_spec *spec = codec->spec;
3954 hda_nid_t *pins = spec->autocfg.hp_pins;
3955 int num_pins = ARRAY_SIZE(spec->autocfg.hp_pins);
3957 /* No detection for the first HP jack during indep-HP mode */
3958 if (spec->indep_hp_enabled) {
3963 spec->hp_jack_present = detect_jacks(codec, num_pins, pins);
3964 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
3966 call_update_outputs(codec);
3968 EXPORT_SYMBOL_GPL(snd_hda_gen_hp_automute);
3970 /* standard line-out-automute helper */
3971 void snd_hda_gen_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
3973 struct hda_gen_spec *spec = codec->spec;
3975 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3977 /* check LO jack only when it's different from HP */
3978 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
3981 spec->line_jack_present =
3982 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
3983 spec->autocfg.line_out_pins);
3984 if (!spec->automute_speaker || !spec->detect_lo)
3986 call_update_outputs(codec);
3988 EXPORT_SYMBOL_GPL(snd_hda_gen_line_automute);
3990 /* standard mic auto-switch helper */
3991 void snd_hda_gen_mic_autoswitch(struct hda_codec *codec, struct hda_jack_tbl *jack)
3993 struct hda_gen_spec *spec = codec->spec;
3996 if (!spec->auto_mic)
3999 for (i = spec->am_num_entries - 1; i > 0; i--) {
4000 hda_nid_t pin = spec->am_entry[i].pin;
4001 /* don't detect pins retasked as outputs */
4002 if (snd_hda_codec_get_pin_target(codec, pin) & AC_PINCTL_OUT_EN)
4004 if (snd_hda_jack_detect_state(codec, pin) == HDA_JACK_PRESENT) {
4005 mux_select(codec, 0, spec->am_entry[i].idx);
4009 mux_select(codec, 0, spec->am_entry[0].idx);
4011 EXPORT_SYMBOL_GPL(snd_hda_gen_mic_autoswitch);
4013 /* call appropriate hooks */
4014 static void call_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
4016 struct hda_gen_spec *spec = codec->spec;
4017 if (spec->hp_automute_hook)
4018 spec->hp_automute_hook(codec, jack);
4020 snd_hda_gen_hp_automute(codec, jack);
4023 static void call_line_automute(struct hda_codec *codec,
4024 struct hda_jack_tbl *jack)
4026 struct hda_gen_spec *spec = codec->spec;
4027 if (spec->line_automute_hook)
4028 spec->line_automute_hook(codec, jack);
4030 snd_hda_gen_line_automute(codec, jack);
4033 static void call_mic_autoswitch(struct hda_codec *codec,
4034 struct hda_jack_tbl *jack)
4036 struct hda_gen_spec *spec = codec->spec;
4037 if (spec->mic_autoswitch_hook)
4038 spec->mic_autoswitch_hook(codec, jack);
4040 snd_hda_gen_mic_autoswitch(codec, jack);
4043 /* update jack retasking */
4044 static void update_automute_all(struct hda_codec *codec)
4046 call_hp_automute(codec, NULL);
4047 call_line_automute(codec, NULL);
4048 call_mic_autoswitch(codec, NULL);
4052 * Auto-Mute mode mixer enum support
4054 static int automute_mode_info(struct snd_kcontrol *kcontrol,
4055 struct snd_ctl_elem_info *uinfo)
4057 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4058 struct hda_gen_spec *spec = codec->spec;
4059 static const char * const texts3[] = {
4060 "Disabled", "Speaker Only", "Line Out+Speaker"
4063 if (spec->automute_speaker_possible && spec->automute_lo_possible)
4064 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
4065 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
4068 static int automute_mode_get(struct snd_kcontrol *kcontrol,
4069 struct snd_ctl_elem_value *ucontrol)
4071 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4072 struct hda_gen_spec *spec = codec->spec;
4073 unsigned int val = 0;
4074 if (spec->automute_speaker)
4076 if (spec->automute_lo)
4079 ucontrol->value.enumerated.item[0] = val;
4083 static int automute_mode_put(struct snd_kcontrol *kcontrol,
4084 struct snd_ctl_elem_value *ucontrol)
4086 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4087 struct hda_gen_spec *spec = codec->spec;
4089 switch (ucontrol->value.enumerated.item[0]) {
4091 if (!spec->automute_speaker && !spec->automute_lo)
4093 spec->automute_speaker = 0;
4094 spec->automute_lo = 0;
4097 if (spec->automute_speaker_possible) {
4098 if (!spec->automute_lo && spec->automute_speaker)
4100 spec->automute_speaker = 1;
4101 spec->automute_lo = 0;
4102 } else if (spec->automute_lo_possible) {
4103 if (spec->automute_lo)
4105 spec->automute_lo = 1;
4110 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
4112 if (spec->automute_speaker && spec->automute_lo)
4114 spec->automute_speaker = 1;
4115 spec->automute_lo = 1;
4120 call_update_outputs(codec);
4124 static const struct snd_kcontrol_new automute_mode_enum = {
4125 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4126 .name = "Auto-Mute Mode",
4127 .info = automute_mode_info,
4128 .get = automute_mode_get,
4129 .put = automute_mode_put,
4132 static int add_automute_mode_enum(struct hda_codec *codec)
4134 struct hda_gen_spec *spec = codec->spec;
4136 if (!snd_hda_gen_add_kctl(spec, NULL, &automute_mode_enum))
4142 * Check the availability of HP/line-out auto-mute;
4143 * Set up appropriately if really supported
4145 static int check_auto_mute_availability(struct hda_codec *codec)
4147 struct hda_gen_spec *spec = codec->spec;
4148 struct auto_pin_cfg *cfg = &spec->autocfg;
4152 if (spec->suppress_auto_mute)
4155 if (cfg->hp_pins[0])
4157 if (cfg->line_out_pins[0])
4159 if (cfg->speaker_pins[0])
4161 if (present < 2) /* need two different output types */
4164 if (!cfg->speaker_pins[0] &&
4165 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
4166 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4167 sizeof(cfg->speaker_pins));
4168 cfg->speaker_outs = cfg->line_outs;
4171 if (!cfg->hp_pins[0] &&
4172 cfg->line_out_type == AUTO_PIN_HP_OUT) {
4173 memcpy(cfg->hp_pins, cfg->line_out_pins,
4174 sizeof(cfg->hp_pins));
4175 cfg->hp_outs = cfg->line_outs;
4178 for (i = 0; i < cfg->hp_outs; i++) {
4179 hda_nid_t nid = cfg->hp_pins[i];
4180 if (!is_jack_detectable(codec, nid))
4182 codec_dbg(codec, "Enable HP auto-muting on NID 0x%x\n", nid);
4183 snd_hda_jack_detect_enable_callback(codec, nid,
4185 spec->detect_hp = 1;
4188 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
4189 if (cfg->speaker_outs)
4190 for (i = 0; i < cfg->line_outs; i++) {
4191 hda_nid_t nid = cfg->line_out_pins[i];
4192 if (!is_jack_detectable(codec, nid))
4194 codec_dbg(codec, "Enable Line-Out auto-muting on NID 0x%x\n", nid);
4195 snd_hda_jack_detect_enable_callback(codec, nid,
4196 call_line_automute);
4197 spec->detect_lo = 1;
4199 spec->automute_lo_possible = spec->detect_hp;
4202 spec->automute_speaker_possible = cfg->speaker_outs &&
4203 (spec->detect_hp || spec->detect_lo);
4205 spec->automute_lo = spec->automute_lo_possible;
4206 spec->automute_speaker = spec->automute_speaker_possible;
4208 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
4209 /* create a control for automute mode */
4210 err = add_automute_mode_enum(codec);
4217 /* check whether all auto-mic pins are valid; setup indices if OK */
4218 static bool auto_mic_check_imux(struct hda_codec *codec)
4220 struct hda_gen_spec *spec = codec->spec;
4221 const struct hda_input_mux *imux;
4224 imux = &spec->input_mux;
4225 for (i = 0; i < spec->am_num_entries; i++) {
4226 spec->am_entry[i].idx =
4227 find_idx_in_nid_list(spec->am_entry[i].pin,
4228 spec->imux_pins, imux->num_items);
4229 if (spec->am_entry[i].idx < 0)
4230 return false; /* no corresponding imux */
4233 /* we don't need the jack detection for the first pin */
4234 for (i = 1; i < spec->am_num_entries; i++)
4235 snd_hda_jack_detect_enable_callback(codec,
4236 spec->am_entry[i].pin,
4237 call_mic_autoswitch);
4241 static int compare_attr(const void *ap, const void *bp)
4243 const struct automic_entry *a = ap;
4244 const struct automic_entry *b = bp;
4245 return (int)(a->attr - b->attr);
4249 * Check the availability of auto-mic switch;
4250 * Set up if really supported
4252 static int check_auto_mic_availability(struct hda_codec *codec)
4254 struct hda_gen_spec *spec = codec->spec;
4255 struct auto_pin_cfg *cfg = &spec->autocfg;
4259 if (spec->suppress_auto_mic)
4264 for (i = 0; i < cfg->num_inputs; i++) {
4265 hda_nid_t nid = cfg->inputs[i].pin;
4267 attr = snd_hda_codec_get_pincfg(codec, nid);
4268 attr = snd_hda_get_input_pin_attr(attr);
4269 if (types & (1 << attr))
4270 return 0; /* already occupied */
4272 case INPUT_PIN_ATTR_INT:
4273 if (cfg->inputs[i].type != AUTO_PIN_MIC)
4274 return 0; /* invalid type */
4276 case INPUT_PIN_ATTR_UNUSED:
4277 return 0; /* invalid entry */
4279 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
4280 return 0; /* invalid type */
4281 if (!spec->line_in_auto_switch &&
4282 cfg->inputs[i].type != AUTO_PIN_MIC)
4283 return 0; /* only mic is allowed */
4284 if (!is_jack_detectable(codec, nid))
4285 return 0; /* no unsol support */
4288 if (num_pins >= MAX_AUTO_MIC_PINS)
4290 types |= (1 << attr);
4291 spec->am_entry[num_pins].pin = nid;
4292 spec->am_entry[num_pins].attr = attr;
4299 spec->am_num_entries = num_pins;
4300 /* sort the am_entry in the order of attr so that the pin with a
4301 * higher attr will be selected when the jack is plugged.
4303 sort(spec->am_entry, num_pins, sizeof(spec->am_entry[0]),
4304 compare_attr, NULL);
4306 if (!auto_mic_check_imux(codec))
4310 spec->num_adc_nids = 1;
4311 spec->cur_mux[0] = spec->am_entry[0].idx;
4312 codec_dbg(codec, "Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
4313 spec->am_entry[0].pin,
4314 spec->am_entry[1].pin,
4315 spec->am_entry[2].pin);
4320 /* power_filter hook; make inactive widgets into power down */
4321 unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
4323 unsigned int power_state)
4325 if (power_state != AC_PWRST_D0 || nid == codec->afg)
4327 if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER)
4329 if (is_active_nid_for_any(codec, nid))
4333 EXPORT_SYMBOL_GPL(snd_hda_gen_path_power_filter);
4335 /* mute all aamix inputs initially; parse up to the first leaves */
4336 static void mute_all_mixer_nid(struct hda_codec *codec, hda_nid_t mix)
4339 const hda_nid_t *conn;
4342 nums = snd_hda_get_conn_list(codec, mix, &conn);
4343 has_amp = nid_has_mute(codec, mix, HDA_INPUT);
4344 for (i = 0; i < nums; i++) {
4346 snd_hda_codec_amp_stereo(codec, mix,
4348 0xff, HDA_AMP_MUTE);
4349 else if (nid_has_volume(codec, conn[i], HDA_OUTPUT))
4350 snd_hda_codec_amp_stereo(codec, conn[i],
4352 0xff, HDA_AMP_MUTE);
4357 * Parse the given BIOS configuration and set up the hda_gen_spec
4359 * return 1 if successful, 0 if the proper config is not found,
4360 * or a negative error code
4362 int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4363 struct auto_pin_cfg *cfg)
4365 struct hda_gen_spec *spec = codec->spec;
4368 parse_user_hints(codec);
4370 if (spec->mixer_nid && !spec->mixer_merge_nid)
4371 spec->mixer_merge_nid = spec->mixer_nid;
4373 if (cfg != &spec->autocfg) {
4374 spec->autocfg = *cfg;
4375 cfg = &spec->autocfg;
4378 if (!spec->main_out_badness)
4379 spec->main_out_badness = &hda_main_out_badness;
4380 if (!spec->extra_out_badness)
4381 spec->extra_out_badness = &hda_extra_out_badness;
4383 fill_all_dac_nids(codec);
4385 if (!cfg->line_outs) {
4386 if (cfg->dig_outs || cfg->dig_in_pin) {
4387 spec->multiout.max_channels = 2;
4388 spec->no_analog = 1;
4391 if (!cfg->num_inputs && !cfg->dig_in_pin)
4392 return 0; /* can't find valid BIOS pin config */
4395 if (!spec->no_primary_hp &&
4396 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4397 cfg->line_outs <= cfg->hp_outs) {
4398 /* use HP as primary out */
4399 cfg->speaker_outs = cfg->line_outs;
4400 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4401 sizeof(cfg->speaker_pins));
4402 cfg->line_outs = cfg->hp_outs;
4403 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4405 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4406 cfg->line_out_type = AUTO_PIN_HP_OUT;
4409 err = parse_output_paths(codec);
4412 err = create_multi_channel_mode(codec);
4415 err = create_multi_out_ctls(codec, cfg);
4418 err = create_hp_out_ctls(codec);
4421 err = create_speaker_out_ctls(codec);
4424 err = create_indep_hp_ctls(codec);
4427 err = create_loopback_mixing_ctl(codec);
4430 err = create_hp_mic(codec);
4433 err = create_input_ctls(codec);
4437 spec->const_channel_count = spec->ext_channel_count;
4438 /* check the multiple speaker and headphone pins */
4439 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
4440 spec->const_channel_count = max(spec->const_channel_count,
4441 cfg->speaker_outs * 2);
4442 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
4443 spec->const_channel_count = max(spec->const_channel_count,
4445 spec->multiout.max_channels = max(spec->ext_channel_count,
4446 spec->const_channel_count);
4448 err = check_auto_mute_availability(codec);
4452 err = check_dyn_adc_switch(codec);
4456 err = check_auto_mic_availability(codec);
4460 /* add stereo mix if available and not enabled yet */
4461 if (!spec->auto_mic && spec->mixer_nid &&
4462 spec->add_stereo_mix_input &&
4463 spec->input_mux.num_items > 1 &&
4464 snd_hda_get_bool_hint(codec, "add_stereo_mix_input") < 0) {
4465 err = parse_capture_source(codec, spec->mixer_nid,
4466 CFG_IDX_MIX, spec->num_all_adcs,
4473 err = create_capture_mixers(codec);
4477 err = parse_mic_boost(codec);
4481 /* create "Headphone Mic Jack Mode" if no input selection is
4482 * available (or user specifies add_jack_modes hint)
4484 if (spec->hp_mic_pin &&
4485 (spec->auto_mic || spec->input_mux.num_items == 1 ||
4486 spec->add_jack_modes)) {
4487 err = create_hp_mic_jack_mode(codec, spec->hp_mic_pin);
4492 if (spec->add_jack_modes) {
4493 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
4494 err = create_out_jack_modes(codec, cfg->line_outs,
4495 cfg->line_out_pins);
4499 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
4500 err = create_out_jack_modes(codec, cfg->hp_outs,
4507 /* mute all aamix input initially */
4508 if (spec->mixer_nid)
4509 mute_all_mixer_nid(codec, spec->mixer_nid);
4512 parse_digital(codec);
4514 if (spec->power_down_unused)
4515 codec->power_filter = snd_hda_gen_path_power_filter;
4517 if (!spec->no_analog && spec->beep_nid) {
4518 err = snd_hda_attach_beep_device(codec, spec->beep_nid);
4525 EXPORT_SYMBOL_GPL(snd_hda_gen_parse_auto_config);
4529 * Build control elements
4532 /* slave controls for virtual master */
4533 static const char * const slave_pfxs[] = {
4534 "Front", "Surround", "Center", "LFE", "Side",
4535 "Headphone", "Speaker", "Mono", "Line Out",
4536 "CLFE", "Bass Speaker", "PCM",
4537 "Speaker Front", "Speaker Surround", "Speaker CLFE", "Speaker Side",
4538 "Headphone Front", "Headphone Surround", "Headphone CLFE",
4543 int snd_hda_gen_build_controls(struct hda_codec *codec)
4545 struct hda_gen_spec *spec = codec->spec;
4548 if (spec->kctls.used) {
4549 err = snd_hda_add_new_ctls(codec, spec->kctls.list);
4554 if (spec->multiout.dig_out_nid) {
4555 err = snd_hda_create_dig_out_ctls(codec,
4556 spec->multiout.dig_out_nid,
4557 spec->multiout.dig_out_nid,
4558 spec->pcm_rec[1].pcm_type);
4561 if (!spec->no_analog) {
4562 err = snd_hda_create_spdif_share_sw(codec,
4566 spec->multiout.share_spdif = 1;
4569 if (spec->dig_in_nid) {
4570 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
4575 /* if we have no master control, let's create it */
4576 if (!spec->no_analog &&
4577 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
4578 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
4579 spec->vmaster_tlv, slave_pfxs,
4584 if (!spec->no_analog &&
4585 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
4586 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
4589 true, &spec->vmaster_mute.sw_kctl);
4592 if (spec->vmaster_mute.hook) {
4593 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4594 spec->vmaster_mute_enum);
4595 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4599 free_kctls(spec); /* no longer needed */
4601 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4607 EXPORT_SYMBOL_GPL(snd_hda_gen_build_controls);
4614 static void call_pcm_playback_hook(struct hda_pcm_stream *hinfo,
4615 struct hda_codec *codec,
4616 struct snd_pcm_substream *substream,
4619 struct hda_gen_spec *spec = codec->spec;
4620 if (spec->pcm_playback_hook)
4621 spec->pcm_playback_hook(hinfo, codec, substream, action);
4624 static void call_pcm_capture_hook(struct hda_pcm_stream *hinfo,
4625 struct hda_codec *codec,
4626 struct snd_pcm_substream *substream,
4629 struct hda_gen_spec *spec = codec->spec;
4630 if (spec->pcm_capture_hook)
4631 spec->pcm_capture_hook(hinfo, codec, substream, action);
4635 * Analog playback callbacks
4637 static int playback_pcm_open(struct hda_pcm_stream *hinfo,
4638 struct hda_codec *codec,
4639 struct snd_pcm_substream *substream)
4641 struct hda_gen_spec *spec = codec->spec;
4644 mutex_lock(&spec->pcm_mutex);
4645 err = snd_hda_multi_out_analog_open(codec,
4646 &spec->multiout, substream,
4649 spec->active_streams |= 1 << STREAM_MULTI_OUT;
4650 call_pcm_playback_hook(hinfo, codec, substream,
4651 HDA_GEN_PCM_ACT_OPEN);
4653 mutex_unlock(&spec->pcm_mutex);
4657 static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4658 struct hda_codec *codec,
4659 unsigned int stream_tag,
4660 unsigned int format,
4661 struct snd_pcm_substream *substream)
4663 struct hda_gen_spec *spec = codec->spec;
4666 err = snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
4667 stream_tag, format, substream);
4669 call_pcm_playback_hook(hinfo, codec, substream,
4670 HDA_GEN_PCM_ACT_PREPARE);
4674 static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
4675 struct hda_codec *codec,
4676 struct snd_pcm_substream *substream)
4678 struct hda_gen_spec *spec = codec->spec;
4681 err = snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
4683 call_pcm_playback_hook(hinfo, codec, substream,
4684 HDA_GEN_PCM_ACT_CLEANUP);
4688 static int playback_pcm_close(struct hda_pcm_stream *hinfo,
4689 struct hda_codec *codec,
4690 struct snd_pcm_substream *substream)
4692 struct hda_gen_spec *spec = codec->spec;
4693 mutex_lock(&spec->pcm_mutex);
4694 spec->active_streams &= ~(1 << STREAM_MULTI_OUT);
4695 call_pcm_playback_hook(hinfo, codec, substream,
4696 HDA_GEN_PCM_ACT_CLOSE);
4697 mutex_unlock(&spec->pcm_mutex);
4701 static int capture_pcm_open(struct hda_pcm_stream *hinfo,
4702 struct hda_codec *codec,
4703 struct snd_pcm_substream *substream)
4705 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_OPEN);
4709 static int capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4710 struct hda_codec *codec,
4711 unsigned int stream_tag,
4712 unsigned int format,
4713 struct snd_pcm_substream *substream)
4715 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
4716 call_pcm_capture_hook(hinfo, codec, substream,
4717 HDA_GEN_PCM_ACT_PREPARE);
4721 static int capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4722 struct hda_codec *codec,
4723 struct snd_pcm_substream *substream)
4725 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
4726 call_pcm_capture_hook(hinfo, codec, substream,
4727 HDA_GEN_PCM_ACT_CLEANUP);
4731 static int capture_pcm_close(struct hda_pcm_stream *hinfo,
4732 struct hda_codec *codec,
4733 struct snd_pcm_substream *substream)
4735 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLOSE);
4739 static int alt_playback_pcm_open(struct hda_pcm_stream *hinfo,
4740 struct hda_codec *codec,
4741 struct snd_pcm_substream *substream)
4743 struct hda_gen_spec *spec = codec->spec;
4746 mutex_lock(&spec->pcm_mutex);
4747 if (!spec->indep_hp_enabled)
4750 spec->active_streams |= 1 << STREAM_INDEP_HP;
4751 call_pcm_playback_hook(hinfo, codec, substream,
4752 HDA_GEN_PCM_ACT_OPEN);
4753 mutex_unlock(&spec->pcm_mutex);
4757 static int alt_playback_pcm_close(struct hda_pcm_stream *hinfo,
4758 struct hda_codec *codec,
4759 struct snd_pcm_substream *substream)
4761 struct hda_gen_spec *spec = codec->spec;
4762 mutex_lock(&spec->pcm_mutex);
4763 spec->active_streams &= ~(1 << STREAM_INDEP_HP);
4764 call_pcm_playback_hook(hinfo, codec, substream,
4765 HDA_GEN_PCM_ACT_CLOSE);
4766 mutex_unlock(&spec->pcm_mutex);
4770 static int alt_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4771 struct hda_codec *codec,
4772 unsigned int stream_tag,
4773 unsigned int format,
4774 struct snd_pcm_substream *substream)
4776 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
4777 call_pcm_playback_hook(hinfo, codec, substream,
4778 HDA_GEN_PCM_ACT_PREPARE);
4782 static int alt_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
4783 struct hda_codec *codec,
4784 struct snd_pcm_substream *substream)
4786 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
4787 call_pcm_playback_hook(hinfo, codec, substream,
4788 HDA_GEN_PCM_ACT_CLEANUP);
4795 static int dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
4796 struct hda_codec *codec,
4797 struct snd_pcm_substream *substream)
4799 struct hda_gen_spec *spec = codec->spec;
4800 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
4803 static int dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4804 struct hda_codec *codec,
4805 unsigned int stream_tag,
4806 unsigned int format,
4807 struct snd_pcm_substream *substream)
4809 struct hda_gen_spec *spec = codec->spec;
4810 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
4811 stream_tag, format, substream);
4814 static int dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
4815 struct hda_codec *codec,
4816 struct snd_pcm_substream *substream)
4818 struct hda_gen_spec *spec = codec->spec;
4819 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
4822 static int dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
4823 struct hda_codec *codec,
4824 struct snd_pcm_substream *substream)
4826 struct hda_gen_spec *spec = codec->spec;
4827 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
4833 #define alt_capture_pcm_open capture_pcm_open
4834 #define alt_capture_pcm_close capture_pcm_close
4836 static int alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4837 struct hda_codec *codec,
4838 unsigned int stream_tag,
4839 unsigned int format,
4840 struct snd_pcm_substream *substream)
4842 struct hda_gen_spec *spec = codec->spec;
4844 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
4845 stream_tag, 0, format);
4846 call_pcm_capture_hook(hinfo, codec, substream,
4847 HDA_GEN_PCM_ACT_PREPARE);
4851 static int alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4852 struct hda_codec *codec,
4853 struct snd_pcm_substream *substream)
4855 struct hda_gen_spec *spec = codec->spec;
4857 snd_hda_codec_cleanup_stream(codec,
4858 spec->adc_nids[substream->number + 1]);
4859 call_pcm_capture_hook(hinfo, codec, substream,
4860 HDA_GEN_PCM_ACT_CLEANUP);
4866 static const struct hda_pcm_stream pcm_analog_playback = {
4870 /* NID is set in build_pcms */
4872 .open = playback_pcm_open,
4873 .close = playback_pcm_close,
4874 .prepare = playback_pcm_prepare,
4875 .cleanup = playback_pcm_cleanup
4879 static const struct hda_pcm_stream pcm_analog_capture = {
4883 /* NID is set in build_pcms */
4885 .open = capture_pcm_open,
4886 .close = capture_pcm_close,
4887 .prepare = capture_pcm_prepare,
4888 .cleanup = capture_pcm_cleanup
4892 static const struct hda_pcm_stream pcm_analog_alt_playback = {
4896 /* NID is set in build_pcms */
4898 .open = alt_playback_pcm_open,
4899 .close = alt_playback_pcm_close,
4900 .prepare = alt_playback_pcm_prepare,
4901 .cleanup = alt_playback_pcm_cleanup
4905 static const struct hda_pcm_stream pcm_analog_alt_capture = {
4906 .substreams = 2, /* can be overridden */
4909 /* NID is set in build_pcms */
4911 .open = alt_capture_pcm_open,
4912 .close = alt_capture_pcm_close,
4913 .prepare = alt_capture_pcm_prepare,
4914 .cleanup = alt_capture_pcm_cleanup
4918 static const struct hda_pcm_stream pcm_digital_playback = {
4922 /* NID is set in build_pcms */
4924 .open = dig_playback_pcm_open,
4925 .close = dig_playback_pcm_close,
4926 .prepare = dig_playback_pcm_prepare,
4927 .cleanup = dig_playback_pcm_cleanup
4931 static const struct hda_pcm_stream pcm_digital_capture = {
4935 /* NID is set in build_pcms */
4938 /* Used by build_pcms to flag that a PCM has no playback stream */
4939 static const struct hda_pcm_stream pcm_null_stream = {
4946 * dynamic changing ADC PCM streams
4948 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
4950 struct hda_gen_spec *spec = codec->spec;
4951 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
4953 if (spec->cur_adc && spec->cur_adc != new_adc) {
4954 /* stream is running, let's swap the current ADC */
4955 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
4956 spec->cur_adc = new_adc;
4957 snd_hda_codec_setup_stream(codec, new_adc,
4958 spec->cur_adc_stream_tag, 0,
4959 spec->cur_adc_format);
4965 /* analog capture with dynamic dual-adc changes */
4966 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4967 struct hda_codec *codec,
4968 unsigned int stream_tag,
4969 unsigned int format,
4970 struct snd_pcm_substream *substream)
4972 struct hda_gen_spec *spec = codec->spec;
4973 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
4974 spec->cur_adc_stream_tag = stream_tag;
4975 spec->cur_adc_format = format;
4976 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
4980 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4981 struct hda_codec *codec,
4982 struct snd_pcm_substream *substream)
4984 struct hda_gen_spec *spec = codec->spec;
4985 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
4990 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
4994 .nid = 0, /* fill later */
4996 .prepare = dyn_adc_capture_pcm_prepare,
4997 .cleanup = dyn_adc_capture_pcm_cleanup
5001 static void fill_pcm_stream_name(char *str, size_t len, const char *sfx,
5002 const char *chip_name)
5008 strlcpy(str, chip_name, len);
5010 /* drop non-alnum chars after a space */
5011 for (p = strchr(str, ' '); p; p = strchr(p + 1, ' ')) {
5012 if (!isalnum(p[1])) {
5017 strlcat(str, sfx, len);
5020 /* build PCM streams based on the parsed results */
5021 int snd_hda_gen_build_pcms(struct hda_codec *codec)
5023 struct hda_gen_spec *spec = codec->spec;
5024 struct hda_pcm *info = spec->pcm_rec;
5025 const struct hda_pcm_stream *p;
5026 bool have_multi_adcs;
5028 codec->num_pcms = 1;
5029 codec->pcm_info = info;
5031 if (spec->no_analog)
5034 fill_pcm_stream_name(spec->stream_name_analog,
5035 sizeof(spec->stream_name_analog),
5036 " Analog", codec->chip_name);
5037 info->name = spec->stream_name_analog;
5039 if (spec->multiout.num_dacs > 0) {
5040 p = spec->stream_analog_playback;
5042 p = &pcm_analog_playback;
5043 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
5044 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
5045 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
5046 spec->multiout.max_channels;
5047 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
5048 spec->autocfg.line_outs == 2)
5049 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
5052 if (spec->num_adc_nids) {
5053 p = spec->stream_analog_capture;
5055 if (spec->dyn_adc_switch)
5056 p = &dyn_adc_pcm_analog_capture;
5058 p = &pcm_analog_capture;
5060 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
5061 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
5065 /* SPDIF for stream index #1 */
5066 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
5067 fill_pcm_stream_name(spec->stream_name_digital,
5068 sizeof(spec->stream_name_digital),
5069 " Digital", codec->chip_name);
5070 codec->num_pcms = 2;
5071 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
5072 info = spec->pcm_rec + 1;
5073 info->name = spec->stream_name_digital;
5074 if (spec->dig_out_type)
5075 info->pcm_type = spec->dig_out_type;
5077 info->pcm_type = HDA_PCM_TYPE_SPDIF;
5078 if (spec->multiout.dig_out_nid) {
5079 p = spec->stream_digital_playback;
5081 p = &pcm_digital_playback;
5082 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
5083 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
5085 if (spec->dig_in_nid) {
5086 p = spec->stream_digital_capture;
5088 p = &pcm_digital_capture;
5089 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
5090 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
5094 if (spec->no_analog)
5097 /* If the use of more than one ADC is requested for the current
5098 * model, configure a second analog capture-only PCM.
5100 have_multi_adcs = (spec->num_adc_nids > 1) &&
5101 !spec->dyn_adc_switch && !spec->auto_mic;
5102 /* Additional Analaog capture for index #2 */
5103 if (spec->alt_dac_nid || have_multi_adcs) {
5104 fill_pcm_stream_name(spec->stream_name_alt_analog,
5105 sizeof(spec->stream_name_alt_analog),
5106 " Alt Analog", codec->chip_name);
5107 codec->num_pcms = 3;
5108 info = spec->pcm_rec + 2;
5109 info->name = spec->stream_name_alt_analog;
5110 if (spec->alt_dac_nid) {
5111 p = spec->stream_analog_alt_playback;
5113 p = &pcm_analog_alt_playback;
5114 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
5115 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
5118 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
5120 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
5122 if (have_multi_adcs) {
5123 p = spec->stream_analog_alt_capture;
5125 p = &pcm_analog_alt_capture;
5126 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
5127 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
5129 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
5130 spec->num_adc_nids - 1;
5132 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
5134 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
5140 EXPORT_SYMBOL_GPL(snd_hda_gen_build_pcms);
5144 * Standard auto-parser initializations
5147 /* configure the given path as a proper output */
5148 static void set_output_and_unmute(struct hda_codec *codec, int path_idx)
5150 struct nid_path *path;
5153 path = snd_hda_get_path_from_idx(codec, path_idx);
5154 if (!path || !path->depth)
5156 pin = path->path[path->depth - 1];
5157 restore_pin_ctl(codec, pin);
5158 snd_hda_activate_path(codec, path, path->active,
5159 aamix_default(codec->spec));
5160 set_pin_eapd(codec, pin, path->active);
5163 /* initialize primary output paths */
5164 static void init_multi_out(struct hda_codec *codec)
5166 struct hda_gen_spec *spec = codec->spec;
5169 for (i = 0; i < spec->autocfg.line_outs; i++)
5170 set_output_and_unmute(codec, spec->out_paths[i]);
5174 static void __init_extra_out(struct hda_codec *codec, int num_outs, int *paths)
5178 for (i = 0; i < num_outs; i++)
5179 set_output_and_unmute(codec, paths[i]);
5182 /* initialize hp and speaker paths */
5183 static void init_extra_out(struct hda_codec *codec)
5185 struct hda_gen_spec *spec = codec->spec;
5187 if (spec->autocfg.line_out_type != AUTO_PIN_HP_OUT)
5188 __init_extra_out(codec, spec->autocfg.hp_outs, spec->hp_paths);
5189 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT)
5190 __init_extra_out(codec, spec->autocfg.speaker_outs,
5191 spec->speaker_paths);
5194 /* initialize multi-io paths */
5195 static void init_multi_io(struct hda_codec *codec)
5197 struct hda_gen_spec *spec = codec->spec;
5200 for (i = 0; i < spec->multi_ios; i++) {
5201 hda_nid_t pin = spec->multi_io[i].pin;
5202 struct nid_path *path;
5203 path = get_multiio_path(codec, i);
5206 if (!spec->multi_io[i].ctl_in)
5207 spec->multi_io[i].ctl_in =
5208 snd_hda_codec_get_pin_target(codec, pin);
5209 snd_hda_activate_path(codec, path, path->active,
5210 aamix_default(spec));
5214 static void init_aamix_paths(struct hda_codec *codec)
5216 struct hda_gen_spec *spec = codec->spec;
5218 if (!spec->have_aamix_ctl)
5220 update_aamix_paths(codec, spec->aamix_mode, spec->out_paths[0],
5221 spec->aamix_out_paths[0],
5222 spec->autocfg.line_out_type);
5223 update_aamix_paths(codec, spec->aamix_mode, spec->hp_paths[0],
5224 spec->aamix_out_paths[1],
5226 update_aamix_paths(codec, spec->aamix_mode, spec->speaker_paths[0],
5227 spec->aamix_out_paths[2],
5228 AUTO_PIN_SPEAKER_OUT);
5231 /* set up input pins and loopback paths */
5232 static void init_analog_input(struct hda_codec *codec)
5234 struct hda_gen_spec *spec = codec->spec;
5235 struct auto_pin_cfg *cfg = &spec->autocfg;
5238 for (i = 0; i < cfg->num_inputs; i++) {
5239 hda_nid_t nid = cfg->inputs[i].pin;
5240 if (is_input_pin(codec, nid))
5241 restore_pin_ctl(codec, nid);
5243 /* init loopback inputs */
5244 if (spec->mixer_nid) {
5245 resume_path_from_idx(codec, spec->loopback_paths[i]);
5246 resume_path_from_idx(codec, spec->loopback_merge_path);
5251 /* initialize ADC paths */
5252 static void init_input_src(struct hda_codec *codec)
5254 struct hda_gen_spec *spec = codec->spec;
5255 struct hda_input_mux *imux = &spec->input_mux;
5256 struct nid_path *path;
5259 if (spec->dyn_adc_switch)
5262 nums = spec->num_adc_nids;
5264 for (c = 0; c < nums; c++) {
5265 for (i = 0; i < imux->num_items; i++) {
5266 path = get_input_path(codec, c, i);
5268 bool active = path->active;
5269 if (i == spec->cur_mux[c])
5271 snd_hda_activate_path(codec, path, active, false);
5275 update_hp_mic(codec, c, true);
5278 if (spec->cap_sync_hook)
5279 spec->cap_sync_hook(codec, NULL, NULL);
5282 /* set right pin controls for digital I/O */
5283 static void init_digital(struct hda_codec *codec)
5285 struct hda_gen_spec *spec = codec->spec;
5289 for (i = 0; i < spec->autocfg.dig_outs; i++)
5290 set_output_and_unmute(codec, spec->digout_paths[i]);
5291 pin = spec->autocfg.dig_in_pin;
5293 restore_pin_ctl(codec, pin);
5294 resume_path_from_idx(codec, spec->digin_path);
5298 /* clear unsol-event tags on unused pins; Conexant codecs seem to leave
5299 * invalid unsol tags by some reason
5301 static void clear_unsol_on_unused_pins(struct hda_codec *codec)
5305 for (i = 0; i < codec->init_pins.used; i++) {
5306 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
5307 hda_nid_t nid = pin->nid;
5308 if (is_jack_detectable(codec, nid) &&
5309 !snd_hda_jack_tbl_get(codec, nid))
5310 snd_hda_codec_update_cache(codec, nid, 0,
5311 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
5316 * initialize the generic spec;
5317 * this can be put as patch_ops.init function
5319 int snd_hda_gen_init(struct hda_codec *codec)
5321 struct hda_gen_spec *spec = codec->spec;
5323 if (spec->init_hook)
5324 spec->init_hook(codec);
5326 snd_hda_apply_verbs(codec);
5328 codec->cached_write = 1;
5330 init_multi_out(codec);
5331 init_extra_out(codec);
5332 init_multi_io(codec);
5333 init_aamix_paths(codec);
5334 init_analog_input(codec);
5335 init_input_src(codec);
5336 init_digital(codec);
5338 clear_unsol_on_unused_pins(codec);
5340 /* call init functions of standard auto-mute helpers */
5341 update_automute_all(codec);
5343 snd_hda_codec_flush_cache(codec);
5345 if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook)
5346 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
5348 hda_call_check_power_status(codec, 0x01);
5351 EXPORT_SYMBOL_GPL(snd_hda_gen_init);
5354 * free the generic spec;
5355 * this can be put as patch_ops.free function
5357 void snd_hda_gen_free(struct hda_codec *codec)
5359 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
5360 snd_hda_gen_spec_free(codec->spec);
5364 EXPORT_SYMBOL_GPL(snd_hda_gen_free);
5368 * check the loopback power save state;
5369 * this can be put as patch_ops.check_power_status function
5371 int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid)
5373 struct hda_gen_spec *spec = codec->spec;
5374 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
5376 EXPORT_SYMBOL_GPL(snd_hda_gen_check_power_status);
5381 * the generic codec support
5384 static const struct hda_codec_ops generic_patch_ops = {
5385 .build_controls = snd_hda_gen_build_controls,
5386 .build_pcms = snd_hda_gen_build_pcms,
5387 .init = snd_hda_gen_init,
5388 .free = snd_hda_gen_free,
5389 .unsol_event = snd_hda_jack_unsol_event,
5391 .check_power_status = snd_hda_gen_check_power_status,
5395 int snd_hda_parse_generic_codec(struct hda_codec *codec)
5397 struct hda_gen_spec *spec;
5400 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5403 snd_hda_gen_spec_init(spec);
5406 err = snd_hda_parse_pin_defcfg(codec, &spec->autocfg, NULL, 0);
5410 err = snd_hda_gen_parse_auto_config(codec, &spec->autocfg);
5414 codec->patch_ops = generic_patch_ops;
5418 snd_hda_gen_free(codec);
5421 EXPORT_SYMBOL_GPL(snd_hda_parse_generic_codec);
5423 MODULE_LICENSE("GPL");
5424 MODULE_DESCRIPTION("Generic HD-audio codec parser");