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 static bool same_amp_caps(struct hda_codec *codec, hda_nid_t nid1,
523 hda_nid_t nid2, int dir)
525 if (!(get_wcaps(codec, nid1) & (1 << (dir + 1))))
526 return !(get_wcaps(codec, nid2) & (1 << (dir + 1)));
527 return (query_amp_caps(codec, nid1, dir) ==
528 query_amp_caps(codec, nid2, dir));
531 /* look for a widget suitable for assigning a mute switch in the path */
532 static hda_nid_t look_for_out_mute_nid(struct hda_codec *codec,
533 struct nid_path *path)
537 for (i = path->depth - 1; i >= 0; i--) {
538 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
539 return path->path[i];
540 if (i != path->depth - 1 && i != 0 &&
541 nid_has_mute(codec, path->path[i], HDA_INPUT))
542 return path->path[i];
547 /* look for a widget suitable for assigning a volume ctl in the path */
548 static hda_nid_t look_for_out_vol_nid(struct hda_codec *codec,
549 struct nid_path *path)
551 struct hda_gen_spec *spec = codec->spec;
554 for (i = path->depth - 1; i >= 0; i--) {
555 hda_nid_t nid = path->path[i];
556 if ((spec->out_vol_mask >> nid) & 1)
558 if (nid_has_volume(codec, nid, HDA_OUTPUT))
565 * path activation / deactivation
568 /* can have the amp-in capability? */
569 static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
571 hda_nid_t nid = path->path[idx];
572 unsigned int caps = get_wcaps(codec, nid);
573 unsigned int type = get_wcaps_type(caps);
575 if (!(caps & AC_WCAP_IN_AMP))
577 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
582 /* can have the amp-out capability? */
583 static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
585 hda_nid_t nid = path->path[idx];
586 unsigned int caps = get_wcaps(codec, nid);
587 unsigned int type = get_wcaps_type(caps);
589 if (!(caps & AC_WCAP_OUT_AMP))
591 if (type == AC_WID_PIN && !idx) /* only for output pins */
596 /* check whether the given (nid,dir,idx) is active */
597 static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
598 unsigned int dir, unsigned int idx)
600 struct hda_gen_spec *spec = codec->spec;
603 for (n = 0; n < spec->paths.used; n++) {
604 struct nid_path *path = snd_array_elem(&spec->paths, n);
607 for (i = 0; i < path->depth; i++) {
608 if (path->path[i] == nid) {
609 if (dir == HDA_OUTPUT || path->idx[i] == idx)
618 /* check whether the NID is referred by any active paths */
619 #define is_active_nid_for_any(codec, nid) \
620 is_active_nid(codec, nid, HDA_OUTPUT, 0)
622 /* get the default amp value for the target state */
623 static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
624 int dir, unsigned int caps, bool enable)
626 unsigned int val = 0;
628 if (caps & AC_AMPCAP_NUM_STEPS) {
631 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
633 if (caps & (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)) {
640 /* initialize the amp value (only at the first time) */
641 static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
643 unsigned int caps = query_amp_caps(codec, nid, dir);
644 int val = get_amp_val_to_activate(codec, nid, dir, caps, false);
645 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
648 /* calculate amp value mask we can modify;
649 * if the given amp is controlled by mixers, don't touch it
651 static unsigned int get_amp_mask_to_modify(struct hda_codec *codec,
652 hda_nid_t nid, int dir, int idx,
655 unsigned int mask = 0xff;
657 if (caps & (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)) {
658 if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_MUTE_CTL))
661 if (caps & AC_AMPCAP_NUM_STEPS) {
662 if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
663 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
669 static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
670 int idx, int idx_to_check, bool enable)
673 unsigned int mask, val;
675 if (!enable && is_active_nid(codec, nid, dir, idx_to_check))
678 caps = query_amp_caps(codec, nid, dir);
679 val = get_amp_val_to_activate(codec, nid, dir, caps, enable);
680 mask = get_amp_mask_to_modify(codec, nid, dir, idx_to_check, caps);
685 snd_hda_codec_amp_stereo(codec, nid, dir, idx, mask, val);
688 static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
691 hda_nid_t nid = path->path[i];
692 init_amp(codec, nid, HDA_OUTPUT, 0);
693 activate_amp(codec, nid, HDA_OUTPUT, 0, 0, enable);
696 static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
697 int i, bool enable, bool add_aamix)
699 struct hda_gen_spec *spec = codec->spec;
700 const hda_nid_t *conn;
703 hda_nid_t nid = path->path[i];
705 nums = snd_hda_get_conn_list(codec, nid, &conn);
706 type = get_wcaps_type(get_wcaps(codec, nid));
707 if (type == AC_WID_PIN ||
708 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
714 for (n = 0; n < nums; n++)
715 init_amp(codec, nid, HDA_INPUT, n);
717 /* here is a little bit tricky in comparison with activate_amp_out();
718 * when aa-mixer is available, we need to enable the path as well
720 for (n = 0; n < nums; n++) {
721 if (n != idx && (!add_aamix || conn[n] != spec->mixer_merge_nid))
723 activate_amp(codec, nid, HDA_INPUT, n, idx, enable);
727 /* activate or deactivate the given path
728 * if @add_aamix is set, enable the input from aa-mix NID as well (if any)
730 void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
731 bool enable, bool add_aamix)
733 struct hda_gen_spec *spec = codec->spec;
737 path->active = false;
739 for (i = path->depth - 1; i >= 0; i--) {
740 hda_nid_t nid = path->path[i];
741 if (enable && spec->power_down_unused) {
742 /* make sure the widget is powered up */
743 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0))
744 snd_hda_codec_write(codec, nid, 0,
745 AC_VERB_SET_POWER_STATE,
748 if (enable && path->multi[i])
749 snd_hda_codec_update_cache(codec, nid, 0,
750 AC_VERB_SET_CONNECT_SEL,
752 if (has_amp_in(codec, path, i))
753 activate_amp_in(codec, path, i, enable, add_aamix);
754 if (has_amp_out(codec, path, i))
755 activate_amp_out(codec, path, i, enable);
761 EXPORT_SYMBOL_GPL(snd_hda_activate_path);
763 /* if the given path is inactive, put widgets into D3 (only if suitable) */
764 static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path)
766 struct hda_gen_spec *spec = codec->spec;
767 bool changed = false;
770 if (!spec->power_down_unused || path->active)
773 for (i = 0; i < path->depth; i++) {
774 hda_nid_t nid = path->path[i];
775 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D3) &&
776 !is_active_nid_for_any(codec, nid)) {
777 snd_hda_codec_write(codec, nid, 0,
778 AC_VERB_SET_POWER_STATE,
786 snd_hda_codec_read(codec, path->path[0], 0,
787 AC_VERB_GET_POWER_STATE, 0);
791 /* turn on/off EAPD on the given pin */
792 static void set_pin_eapd(struct hda_codec *codec, hda_nid_t pin, bool enable)
794 struct hda_gen_spec *spec = codec->spec;
795 if (spec->own_eapd_ctl ||
796 !(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD))
798 if (spec->keep_eapd_on && !enable)
802 snd_hda_codec_update_cache(codec, pin, 0,
803 AC_VERB_SET_EAPD_BTLENABLE,
804 enable ? 0x02 : 0x00);
807 /* re-initialize the path specified by the given path index */
808 static void resume_path_from_idx(struct hda_codec *codec, int path_idx)
810 struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
812 snd_hda_activate_path(codec, path, path->active, false);
817 * Helper functions for creating mixer ctl elements
820 static int hda_gen_mixer_mute_put(struct snd_kcontrol *kcontrol,
821 struct snd_ctl_elem_value *ucontrol);
822 static int hda_gen_bind_mute_put(struct snd_kcontrol *kcontrol,
823 struct snd_ctl_elem_value *ucontrol);
830 static const struct snd_kcontrol_new control_templates[] = {
831 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
832 /* only the put callback is replaced for handling the special mute */
834 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
835 .subdevice = HDA_SUBDEV_AMP_FLAG,
836 .info = snd_hda_mixer_amp_switch_info,
837 .get = snd_hda_mixer_amp_switch_get,
838 .put = hda_gen_mixer_mute_put, /* replaced */
839 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0),
842 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
843 .info = snd_hda_mixer_amp_switch_info,
844 .get = snd_hda_mixer_bind_switch_get,
845 .put = hda_gen_bind_mute_put, /* replaced */
846 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0),
850 /* add dynamic controls from template */
851 static struct snd_kcontrol_new *
852 add_control(struct hda_gen_spec *spec, int type, const char *name,
853 int cidx, unsigned long val)
855 struct snd_kcontrol_new *knew;
857 knew = snd_hda_gen_add_kctl(spec, name, &control_templates[type]);
861 if (get_amp_nid_(val))
862 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
863 knew->private_value = val;
867 static int add_control_with_pfx(struct hda_gen_spec *spec, int type,
868 const char *pfx, const char *dir,
869 const char *sfx, int cidx, unsigned long val)
871 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
872 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
873 if (!add_control(spec, type, name, cidx, val))
878 #define add_pb_vol_ctrl(spec, type, pfx, val) \
879 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
880 #define add_pb_sw_ctrl(spec, type, pfx, val) \
881 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
882 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
883 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
884 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
885 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
887 static int add_vol_ctl(struct hda_codec *codec, const char *pfx, int cidx,
888 unsigned int chs, struct nid_path *path)
893 val = path->ctls[NID_PATH_VOL_CTL];
896 val = amp_val_replace_channels(val, chs);
897 return __add_pb_vol_ctrl(codec->spec, HDA_CTL_WIDGET_VOL, pfx, cidx, val);
900 /* return the channel bits suitable for the given path->ctls[] */
901 static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
904 int chs = 1; /* mono (left only) */
906 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
907 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
908 chs = 3; /* stereo */
913 static int add_stereo_vol(struct hda_codec *codec, const char *pfx, int cidx,
914 struct nid_path *path)
916 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
917 return add_vol_ctl(codec, pfx, cidx, chs, path);
920 /* create a mute-switch for the given mixer widget;
921 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
923 static int add_sw_ctl(struct hda_codec *codec, const char *pfx, int cidx,
924 unsigned int chs, struct nid_path *path)
927 int type = HDA_CTL_WIDGET_MUTE;
931 val = path->ctls[NID_PATH_MUTE_CTL];
934 val = amp_val_replace_channels(val, chs);
935 if (get_amp_direction_(val) == HDA_INPUT) {
936 hda_nid_t nid = get_amp_nid_(val);
937 int nums = snd_hda_get_num_conns(codec, nid);
939 type = HDA_CTL_BIND_MUTE;
943 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
946 static int add_stereo_sw(struct hda_codec *codec, const char *pfx,
947 int cidx, struct nid_path *path)
949 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
950 return add_sw_ctl(codec, pfx, cidx, chs, path);
953 /* playback mute control with the software mute bit check */
954 static void sync_auto_mute_bits(struct snd_kcontrol *kcontrol,
955 struct snd_ctl_elem_value *ucontrol)
957 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
958 struct hda_gen_spec *spec = codec->spec;
960 if (spec->auto_mute_via_amp) {
961 hda_nid_t nid = get_amp_nid(kcontrol);
962 bool enabled = !((spec->mute_bits >> nid) & 1);
963 ucontrol->value.integer.value[0] &= enabled;
964 ucontrol->value.integer.value[1] &= enabled;
968 static int hda_gen_mixer_mute_put(struct snd_kcontrol *kcontrol,
969 struct snd_ctl_elem_value *ucontrol)
971 sync_auto_mute_bits(kcontrol, ucontrol);
972 return snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
975 static int hda_gen_bind_mute_put(struct snd_kcontrol *kcontrol,
976 struct snd_ctl_elem_value *ucontrol)
978 sync_auto_mute_bits(kcontrol, ucontrol);
979 return snd_hda_mixer_bind_switch_put(kcontrol, ucontrol);
982 /* any ctl assigned to the path with the given index? */
983 static bool path_has_mixer(struct hda_codec *codec, int path_idx, int ctl_type)
985 struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
986 return path && path->ctls[ctl_type];
989 static const char * const channel_name[4] = {
990 "Front", "Surround", "CLFE", "Side"
993 /* give some appropriate ctl name prefix for the given line out channel */
994 static const char *get_line_out_pfx(struct hda_codec *codec, int ch,
995 int *index, int ctl_type)
997 struct hda_gen_spec *spec = codec->spec;
998 struct auto_pin_cfg *cfg = &spec->autocfg;
1001 if (cfg->line_outs == 1 && !spec->multi_ios &&
1002 !cfg->hp_outs && !cfg->speaker_outs)
1003 return spec->vmaster_mute.hook ? "PCM" : "Master";
1005 /* if there is really a single DAC used in the whole output paths,
1006 * use it master (or "PCM" if a vmaster hook is present)
1008 if (spec->multiout.num_dacs == 1 && !spec->mixer_nid &&
1009 !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0])
1010 return spec->vmaster_mute.hook ? "PCM" : "Master";
1012 /* multi-io channels */
1013 if (ch >= cfg->line_outs)
1014 return channel_name[ch];
1016 switch (cfg->line_out_type) {
1017 case AUTO_PIN_SPEAKER_OUT:
1018 /* if the primary channel vol/mute is shared with HP volume,
1019 * don't name it as Speaker
1021 if (!ch && cfg->hp_outs &&
1022 !path_has_mixer(codec, spec->hp_paths[0], ctl_type))
1024 if (cfg->line_outs == 1)
1026 if (cfg->line_outs == 2)
1027 return ch ? "Bass Speaker" : "Speaker";
1029 case AUTO_PIN_HP_OUT:
1030 /* if the primary channel vol/mute is shared with spk volume,
1031 * don't name it as Headphone
1033 if (!ch && cfg->speaker_outs &&
1034 !path_has_mixer(codec, spec->speaker_paths[0], ctl_type))
1036 /* for multi-io case, only the primary out */
1037 if (ch && spec->multi_ios)
1041 case AUTO_PIN_LINE_OUT:
1042 /* This deals with the case where we have two DACs and
1043 * one LO, one HP and one Speaker */
1044 if (!ch && cfg->speaker_outs && cfg->hp_outs) {
1045 bool hp_lo_shared = !path_has_mixer(codec, spec->hp_paths[0], ctl_type);
1046 bool spk_lo_shared = !path_has_mixer(codec, spec->speaker_paths[0], ctl_type);
1047 if (hp_lo_shared && spk_lo_shared)
1048 return spec->vmaster_mute.hook ? "PCM" : "Master";
1050 return "Headphone+LO";
1052 return "Speaker+LO";
1056 /* for a single channel output, we don't have to name the channel */
1057 if (cfg->line_outs == 1 && !spec->multi_ios)
1060 if (ch >= ARRAY_SIZE(channel_name)) {
1065 return channel_name[ch];
1069 * Parse output paths
1072 /* badness definition */
1074 /* No primary DAC is found for the main output */
1075 BAD_NO_PRIMARY_DAC = 0x10000,
1076 /* No DAC is found for the extra output */
1077 BAD_NO_DAC = 0x4000,
1078 /* No possible multi-ios */
1079 BAD_MULTI_IO = 0x120,
1080 /* No individual DAC for extra output */
1081 BAD_NO_EXTRA_DAC = 0x102,
1082 /* No individual DAC for extra surrounds */
1083 BAD_NO_EXTRA_SURR_DAC = 0x101,
1084 /* Primary DAC shared with main surrounds */
1085 BAD_SHARED_SURROUND = 0x100,
1086 /* No independent HP possible */
1087 BAD_NO_INDEP_HP = 0x10,
1088 /* Primary DAC shared with main CLFE */
1089 BAD_SHARED_CLFE = 0x10,
1090 /* Primary DAC shared with extra surrounds */
1091 BAD_SHARED_EXTRA_SURROUND = 0x10,
1092 /* Volume widget is shared */
1093 BAD_SHARED_VOL = 0x10,
1096 /* look for widgets in the given path which are appropriate for
1097 * volume and mute controls, and assign the values to ctls[].
1099 * When no appropriate widget is found in the path, the badness value
1100 * is incremented depending on the situation. The function returns the
1101 * total badness for both volume and mute controls.
1103 static int assign_out_path_ctls(struct hda_codec *codec, struct nid_path *path)
1105 struct hda_gen_spec *spec = codec->spec;
1111 return BAD_SHARED_VOL * 2;
1113 if (path->ctls[NID_PATH_VOL_CTL] ||
1114 path->ctls[NID_PATH_MUTE_CTL])
1115 return 0; /* already evaluated */
1117 nid = look_for_out_vol_nid(codec, path);
1119 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
1120 if (spec->dac_min_mute)
1121 val |= HDA_AMP_VAL_MIN_MUTE;
1122 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
1123 badness += BAD_SHARED_VOL;
1125 path->ctls[NID_PATH_VOL_CTL] = val;
1127 badness += BAD_SHARED_VOL;
1128 nid = look_for_out_mute_nid(codec, path);
1130 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
1131 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
1132 nid_has_mute(codec, nid, HDA_OUTPUT))
1133 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
1135 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
1136 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
1137 badness += BAD_SHARED_VOL;
1139 path->ctls[NID_PATH_MUTE_CTL] = val;
1141 badness += BAD_SHARED_VOL;
1145 const struct badness_table hda_main_out_badness = {
1146 .no_primary_dac = BAD_NO_PRIMARY_DAC,
1147 .no_dac = BAD_NO_DAC,
1148 .shared_primary = BAD_NO_PRIMARY_DAC,
1149 .shared_surr = BAD_SHARED_SURROUND,
1150 .shared_clfe = BAD_SHARED_CLFE,
1151 .shared_surr_main = BAD_SHARED_SURROUND,
1153 EXPORT_SYMBOL_GPL(hda_main_out_badness);
1155 const struct badness_table hda_extra_out_badness = {
1156 .no_primary_dac = BAD_NO_DAC,
1157 .no_dac = BAD_NO_DAC,
1158 .shared_primary = BAD_NO_EXTRA_DAC,
1159 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
1160 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
1161 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
1163 EXPORT_SYMBOL_GPL(hda_extra_out_badness);
1165 /* get the DAC of the primary output corresponding to the given array index */
1166 static hda_nid_t get_primary_out(struct hda_codec *codec, int idx)
1168 struct hda_gen_spec *spec = codec->spec;
1169 struct auto_pin_cfg *cfg = &spec->autocfg;
1171 if (cfg->line_outs > idx)
1172 return spec->private_dac_nids[idx];
1173 idx -= cfg->line_outs;
1174 if (spec->multi_ios > idx)
1175 return spec->multi_io[idx].dac;
1179 /* return the DAC if it's reachable, otherwise zero */
1180 static inline hda_nid_t try_dac(struct hda_codec *codec,
1181 hda_nid_t dac, hda_nid_t pin)
1183 return is_reachable_path(codec, dac, pin) ? dac : 0;
1186 /* try to assign DACs to pins and return the resultant badness */
1187 static int try_assign_dacs(struct hda_codec *codec, int num_outs,
1188 const hda_nid_t *pins, hda_nid_t *dacs,
1190 const struct badness_table *bad)
1192 struct hda_gen_spec *spec = codec->spec;
1200 for (i = 0; i < num_outs; i++) {
1201 struct nid_path *path;
1202 hda_nid_t pin = pins[i];
1204 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1206 badness += assign_out_path_ctls(codec, path);
1210 dacs[i] = get_preferred_dac(codec, pin);
1212 if (is_dac_already_used(codec, dacs[i]))
1213 badness += bad->shared_primary;
1217 dacs[i] = look_for_dac(codec, pin, false);
1218 if (!dacs[i] && !i) {
1219 /* try to steal the DAC of surrounds for the front */
1220 for (j = 1; j < num_outs; j++) {
1221 if (is_reachable_path(codec, dacs[j], pin)) {
1224 invalidate_nid_path(codec, path_idx[j]);
1233 dac = try_dac(codec, get_primary_out(codec, i), pin);
1235 dac = try_dac(codec, dacs[0], pin);
1237 dac = try_dac(codec, get_primary_out(codec, i), pin);
1240 badness += bad->shared_primary;
1242 badness += bad->shared_surr;
1244 badness += bad->shared_clfe;
1245 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
1246 dac = spec->private_dac_nids[0];
1247 badness += bad->shared_surr_main;
1249 badness += bad->no_primary_dac;
1251 badness += bad->no_dac;
1255 path = snd_hda_add_new_path(codec, dac, pin, -spec->mixer_nid);
1256 if (!path && !i && spec->mixer_nid) {
1257 /* try with aamix */
1258 path = snd_hda_add_new_path(codec, dac, pin, 0);
1262 badness += bad->no_dac;
1264 /* print_nid_path(codec, "output", path); */
1265 path->active = true;
1266 path_idx[i] = snd_hda_get_path_idx(codec, path);
1267 badness += assign_out_path_ctls(codec, path);
1274 /* return NID if the given pin has only a single connection to a certain DAC */
1275 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
1277 struct hda_gen_spec *spec = codec->spec;
1279 hda_nid_t nid_found = 0;
1281 for (i = 0; i < spec->num_all_dacs; i++) {
1282 hda_nid_t nid = spec->all_dacs[i];
1283 if (!nid || is_dac_already_used(codec, nid))
1285 if (is_reachable_path(codec, nid, pin)) {
1294 /* check whether the given pin can be a multi-io pin */
1295 static bool can_be_multiio_pin(struct hda_codec *codec,
1296 unsigned int location, hda_nid_t nid)
1298 unsigned int defcfg, caps;
1300 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1301 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
1303 if (location && get_defcfg_location(defcfg) != location)
1305 caps = snd_hda_query_pin_caps(codec, nid);
1306 if (!(caps & AC_PINCAP_OUT))
1311 /* count the number of input pins that are capable to be multi-io */
1312 static int count_multiio_pins(struct hda_codec *codec, hda_nid_t reference_pin)
1314 struct hda_gen_spec *spec = codec->spec;
1315 struct auto_pin_cfg *cfg = &spec->autocfg;
1316 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1317 unsigned int location = get_defcfg_location(defcfg);
1321 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
1322 for (i = 0; i < cfg->num_inputs; i++) {
1323 if (cfg->inputs[i].type != type)
1325 if (can_be_multiio_pin(codec, location,
1326 cfg->inputs[i].pin))
1336 * When hardwired is set, try to fill ony hardwired pins, and returns
1337 * zero if any pins are filled, non-zero if nothing found.
1338 * When hardwired is off, try to fill possible input pins, and returns
1339 * the badness value.
1341 static int fill_multi_ios(struct hda_codec *codec,
1342 hda_nid_t reference_pin,
1345 struct hda_gen_spec *spec = codec->spec;
1346 struct auto_pin_cfg *cfg = &spec->autocfg;
1347 int type, i, j, num_pins, old_pins;
1348 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1349 unsigned int location = get_defcfg_location(defcfg);
1351 struct nid_path *path;
1353 old_pins = spec->multi_ios;
1357 num_pins = count_multiio_pins(codec, reference_pin);
1361 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
1362 for (i = 0; i < cfg->num_inputs; i++) {
1363 hda_nid_t nid = cfg->inputs[i].pin;
1366 if (cfg->inputs[i].type != type)
1368 if (!can_be_multiio_pin(codec, location, nid))
1370 for (j = 0; j < spec->multi_ios; j++) {
1371 if (nid == spec->multi_io[j].pin)
1374 if (j < spec->multi_ios)
1378 dac = get_dac_if_single(codec, nid);
1380 dac = look_for_dac(codec, nid, false);
1385 path = snd_hda_add_new_path(codec, dac, nid,
1391 /* print_nid_path(codec, "multiio", path); */
1392 spec->multi_io[spec->multi_ios].pin = nid;
1393 spec->multi_io[spec->multi_ios].dac = dac;
1394 spec->out_paths[cfg->line_outs + spec->multi_ios] =
1395 snd_hda_get_path_idx(codec, path);
1397 if (spec->multi_ios >= 2)
1403 badness = BAD_MULTI_IO;
1404 if (old_pins == spec->multi_ios) {
1406 return 1; /* nothing found */
1408 return badness; /* no badness if nothing found */
1410 if (!hardwired && spec->multi_ios < 2) {
1411 /* cancel newly assigned paths */
1412 spec->paths.used -= spec->multi_ios - old_pins;
1413 spec->multi_ios = old_pins;
1417 /* assign volume and mute controls */
1418 for (i = old_pins; i < spec->multi_ios; i++) {
1419 path = snd_hda_get_path_from_idx(codec, spec->out_paths[cfg->line_outs + i]);
1420 badness += assign_out_path_ctls(codec, path);
1426 /* map DACs for all pins in the list if they are single connections */
1427 static bool map_singles(struct hda_codec *codec, int outs,
1428 const hda_nid_t *pins, hda_nid_t *dacs, int *path_idx)
1430 struct hda_gen_spec *spec = codec->spec;
1433 for (i = 0; i < outs; i++) {
1434 struct nid_path *path;
1438 dac = get_dac_if_single(codec, pins[i]);
1441 path = snd_hda_add_new_path(codec, dac, pins[i],
1443 if (!path && !i && spec->mixer_nid)
1444 path = snd_hda_add_new_path(codec, dac, pins[i], 0);
1448 /* print_nid_path(codec, "output", path); */
1449 path->active = true;
1450 path_idx[i] = snd_hda_get_path_idx(codec, path);
1456 /* create a new path including aamix if available, and return its index */
1457 static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
1459 struct hda_gen_spec *spec = codec->spec;
1460 struct nid_path *path;
1461 hda_nid_t path_dac, dac, pin;
1463 path = snd_hda_get_path_from_idx(codec, path_idx);
1464 if (!path || !path->depth ||
1465 is_nid_contained(path, spec->mixer_nid))
1467 path_dac = path->path[0];
1468 dac = spec->private_dac_nids[0];
1469 pin = path->path[path->depth - 1];
1470 path = snd_hda_add_new_path(codec, dac, pin, spec->mixer_nid);
1472 if (dac != path_dac)
1474 else if (spec->multiout.hp_out_nid[0])
1475 dac = spec->multiout.hp_out_nid[0];
1476 else if (spec->multiout.extra_out_nid[0])
1477 dac = spec->multiout.extra_out_nid[0];
1481 path = snd_hda_add_new_path(codec, dac, pin,
1486 /* print_nid_path(codec, "output-aamix", path); */
1487 path->active = false; /* unused as default */
1488 return snd_hda_get_path_idx(codec, path);
1491 /* check whether the independent HP is available with the current config */
1492 static bool indep_hp_possible(struct hda_codec *codec)
1494 struct hda_gen_spec *spec = codec->spec;
1495 struct auto_pin_cfg *cfg = &spec->autocfg;
1496 struct nid_path *path;
1499 if (cfg->line_out_type == AUTO_PIN_HP_OUT)
1500 idx = spec->out_paths[0];
1502 idx = spec->hp_paths[0];
1503 path = snd_hda_get_path_from_idx(codec, idx);
1507 /* assume no path conflicts unless aamix is involved */
1508 if (!spec->mixer_nid || !is_nid_contained(path, spec->mixer_nid))
1511 /* check whether output paths contain aamix */
1512 for (i = 0; i < cfg->line_outs; i++) {
1513 if (spec->out_paths[i] == idx)
1515 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
1516 if (path && is_nid_contained(path, spec->mixer_nid))
1519 for (i = 0; i < cfg->speaker_outs; i++) {
1520 path = snd_hda_get_path_from_idx(codec, spec->speaker_paths[i]);
1521 if (path && is_nid_contained(path, spec->mixer_nid))
1528 /* fill the empty entries in the dac array for speaker/hp with the
1529 * shared dac pointed by the paths
1531 static void refill_shared_dacs(struct hda_codec *codec, int num_outs,
1532 hda_nid_t *dacs, int *path_idx)
1534 struct nid_path *path;
1537 for (i = 0; i < num_outs; i++) {
1540 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1543 dacs[i] = path->path[0];
1547 /* fill in the dac_nids table from the parsed pin configuration */
1548 static int fill_and_eval_dacs(struct hda_codec *codec,
1549 bool fill_hardwired,
1550 bool fill_mio_first)
1552 struct hda_gen_spec *spec = codec->spec;
1553 struct auto_pin_cfg *cfg = &spec->autocfg;
1554 int i, err, badness;
1556 /* set num_dacs once to full for look_for_dac() */
1557 spec->multiout.num_dacs = cfg->line_outs;
1558 spec->multiout.dac_nids = spec->private_dac_nids;
1559 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
1560 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
1561 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
1562 spec->multi_ios = 0;
1563 snd_array_free(&spec->paths);
1565 /* clear path indices */
1566 memset(spec->out_paths, 0, sizeof(spec->out_paths));
1567 memset(spec->hp_paths, 0, sizeof(spec->hp_paths));
1568 memset(spec->speaker_paths, 0, sizeof(spec->speaker_paths));
1569 memset(spec->aamix_out_paths, 0, sizeof(spec->aamix_out_paths));
1570 memset(spec->digout_paths, 0, sizeof(spec->digout_paths));
1571 memset(spec->input_paths, 0, sizeof(spec->input_paths));
1572 memset(spec->loopback_paths, 0, sizeof(spec->loopback_paths));
1573 memset(&spec->digin_path, 0, sizeof(spec->digin_path));
1577 /* fill hard-wired DACs first */
1578 if (fill_hardwired) {
1581 mapped = map_singles(codec, cfg->line_outs,
1583 spec->private_dac_nids,
1585 mapped |= map_singles(codec, cfg->hp_outs,
1587 spec->multiout.hp_out_nid,
1589 mapped |= map_singles(codec, cfg->speaker_outs,
1591 spec->multiout.extra_out_nid,
1592 spec->speaker_paths);
1593 if (!spec->no_multi_io &&
1594 fill_mio_first && cfg->line_outs == 1 &&
1595 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1596 err = fill_multi_ios(codec, cfg->line_out_pins[0], true);
1603 badness += try_assign_dacs(codec, cfg->line_outs, cfg->line_out_pins,
1604 spec->private_dac_nids, spec->out_paths,
1605 spec->main_out_badness);
1607 if (!spec->no_multi_io && fill_mio_first &&
1608 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1609 /* try to fill multi-io first */
1610 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1613 /* we don't count badness at this stage yet */
1616 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
1617 err = try_assign_dacs(codec, cfg->hp_outs, cfg->hp_pins,
1618 spec->multiout.hp_out_nid,
1620 spec->extra_out_badness);
1625 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1626 err = try_assign_dacs(codec, cfg->speaker_outs,
1628 spec->multiout.extra_out_nid,
1629 spec->speaker_paths,
1630 spec->extra_out_badness);
1635 if (!spec->no_multi_io &&
1636 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1637 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1643 if (spec->mixer_nid) {
1644 spec->aamix_out_paths[0] =
1645 check_aamix_out_path(codec, spec->out_paths[0]);
1646 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1647 spec->aamix_out_paths[1] =
1648 check_aamix_out_path(codec, spec->hp_paths[0]);
1649 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1650 spec->aamix_out_paths[2] =
1651 check_aamix_out_path(codec, spec->speaker_paths[0]);
1654 if (!spec->no_multi_io &&
1655 cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
1656 if (count_multiio_pins(codec, cfg->hp_pins[0]) >= 2)
1657 spec->multi_ios = 1; /* give badness */
1659 /* re-count num_dacs and squash invalid entries */
1660 spec->multiout.num_dacs = 0;
1661 for (i = 0; i < cfg->line_outs; i++) {
1662 if (spec->private_dac_nids[i])
1663 spec->multiout.num_dacs++;
1665 memmove(spec->private_dac_nids + i,
1666 spec->private_dac_nids + i + 1,
1667 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
1668 spec->private_dac_nids[cfg->line_outs - 1] = 0;
1672 spec->ext_channel_count = spec->min_channel_count =
1673 spec->multiout.num_dacs * 2;
1675 if (spec->multi_ios == 2) {
1676 for (i = 0; i < 2; i++)
1677 spec->private_dac_nids[spec->multiout.num_dacs++] =
1678 spec->multi_io[i].dac;
1679 } else if (spec->multi_ios) {
1680 spec->multi_ios = 0;
1681 badness += BAD_MULTI_IO;
1684 if (spec->indep_hp && !indep_hp_possible(codec))
1685 badness += BAD_NO_INDEP_HP;
1687 /* re-fill the shared DAC for speaker / headphone */
1688 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1689 refill_shared_dacs(codec, cfg->hp_outs,
1690 spec->multiout.hp_out_nid,
1692 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1693 refill_shared_dacs(codec, cfg->speaker_outs,
1694 spec->multiout.extra_out_nid,
1695 spec->speaker_paths);
1700 #define DEBUG_BADNESS
1702 #ifdef DEBUG_BADNESS
1703 #define debug_badness(fmt, ...) \
1704 codec_dbg(codec, fmt, ##__VA_ARGS__)
1706 #define debug_badness(fmt, ...) \
1707 do { if (0) codec_dbg(codec, fmt, ##__VA_ARGS__); } while (0)
1710 #ifdef DEBUG_BADNESS
1711 static inline void print_nid_path_idx(struct hda_codec *codec,
1712 const char *pfx, int idx)
1714 struct nid_path *path;
1716 path = snd_hda_get_path_from_idx(codec, idx);
1718 print_nid_path(codec, pfx, path);
1721 static void debug_show_configs(struct hda_codec *codec,
1722 struct auto_pin_cfg *cfg)
1724 struct hda_gen_spec *spec = codec->spec;
1725 static const char * const lo_type[3] = { "LO", "SP", "HP" };
1728 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x (type %s)\n",
1729 cfg->line_out_pins[0], cfg->line_out_pins[1],
1730 cfg->line_out_pins[2], cfg->line_out_pins[3],
1731 spec->multiout.dac_nids[0],
1732 spec->multiout.dac_nids[1],
1733 spec->multiout.dac_nids[2],
1734 spec->multiout.dac_nids[3],
1735 lo_type[cfg->line_out_type]);
1736 for (i = 0; i < cfg->line_outs; i++)
1737 print_nid_path_idx(codec, " out", spec->out_paths[i]);
1738 if (spec->multi_ios > 0)
1739 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
1741 spec->multi_io[0].pin, spec->multi_io[1].pin,
1742 spec->multi_io[0].dac, spec->multi_io[1].dac);
1743 for (i = 0; i < spec->multi_ios; i++)
1744 print_nid_path_idx(codec, " mio",
1745 spec->out_paths[cfg->line_outs + i]);
1747 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
1748 cfg->hp_pins[0], cfg->hp_pins[1],
1749 cfg->hp_pins[2], cfg->hp_pins[3],
1750 spec->multiout.hp_out_nid[0],
1751 spec->multiout.hp_out_nid[1],
1752 spec->multiout.hp_out_nid[2],
1753 spec->multiout.hp_out_nid[3]);
1754 for (i = 0; i < cfg->hp_outs; i++)
1755 print_nid_path_idx(codec, " hp ", spec->hp_paths[i]);
1756 if (cfg->speaker_outs)
1757 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
1758 cfg->speaker_pins[0], cfg->speaker_pins[1],
1759 cfg->speaker_pins[2], cfg->speaker_pins[3],
1760 spec->multiout.extra_out_nid[0],
1761 spec->multiout.extra_out_nid[1],
1762 spec->multiout.extra_out_nid[2],
1763 spec->multiout.extra_out_nid[3]);
1764 for (i = 0; i < cfg->speaker_outs; i++)
1765 print_nid_path_idx(codec, " spk", spec->speaker_paths[i]);
1766 for (i = 0; i < 3; i++)
1767 print_nid_path_idx(codec, " mix", spec->aamix_out_paths[i]);
1770 #define debug_show_configs(codec, cfg) /* NOP */
1773 /* find all available DACs of the codec */
1774 static void fill_all_dac_nids(struct hda_codec *codec)
1776 struct hda_gen_spec *spec = codec->spec;
1778 hda_nid_t nid = codec->start_nid;
1780 spec->num_all_dacs = 0;
1781 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
1782 for (i = 0; i < codec->num_nodes; i++, nid++) {
1783 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
1785 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
1786 codec_err(codec, "Too many DACs!\n");
1789 spec->all_dacs[spec->num_all_dacs++] = nid;
1793 static int parse_output_paths(struct hda_codec *codec)
1795 struct hda_gen_spec *spec = codec->spec;
1796 struct auto_pin_cfg *cfg = &spec->autocfg;
1797 struct auto_pin_cfg *best_cfg;
1799 int best_badness = INT_MAX;
1801 bool fill_hardwired = true, fill_mio_first = true;
1802 bool best_wired = true, best_mio = true;
1803 bool hp_spk_swapped = false;
1805 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
1811 badness = fill_and_eval_dacs(codec, fill_hardwired,
1817 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
1818 cfg->line_out_type, fill_hardwired, fill_mio_first,
1820 debug_show_configs(codec, cfg);
1821 if (badness < best_badness) {
1822 best_badness = badness;
1824 best_wired = fill_hardwired;
1825 best_mio = fill_mio_first;
1829 fill_mio_first = !fill_mio_first;
1830 if (!fill_mio_first)
1832 fill_hardwired = !fill_hardwired;
1833 if (!fill_hardwired)
1837 hp_spk_swapped = true;
1838 if (cfg->speaker_outs > 0 &&
1839 cfg->line_out_type == AUTO_PIN_HP_OUT) {
1840 cfg->hp_outs = cfg->line_outs;
1841 memcpy(cfg->hp_pins, cfg->line_out_pins,
1842 sizeof(cfg->hp_pins));
1843 cfg->line_outs = cfg->speaker_outs;
1844 memcpy(cfg->line_out_pins, cfg->speaker_pins,
1845 sizeof(cfg->speaker_pins));
1846 cfg->speaker_outs = 0;
1847 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
1848 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
1849 fill_hardwired = true;
1852 if (cfg->hp_outs > 0 &&
1853 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
1854 cfg->speaker_outs = cfg->line_outs;
1855 memcpy(cfg->speaker_pins, cfg->line_out_pins,
1856 sizeof(cfg->speaker_pins));
1857 cfg->line_outs = cfg->hp_outs;
1858 memcpy(cfg->line_out_pins, cfg->hp_pins,
1859 sizeof(cfg->hp_pins));
1861 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
1862 cfg->line_out_type = AUTO_PIN_HP_OUT;
1863 fill_hardwired = true;
1870 debug_badness("==> restoring best_cfg\n");
1872 fill_and_eval_dacs(codec, best_wired, best_mio);
1874 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
1875 cfg->line_out_type, best_wired, best_mio);
1876 debug_show_configs(codec, cfg);
1878 if (cfg->line_out_pins[0]) {
1879 struct nid_path *path;
1880 path = snd_hda_get_path_from_idx(codec, spec->out_paths[0]);
1882 spec->vmaster_nid = look_for_out_vol_nid(codec, path);
1883 if (spec->vmaster_nid) {
1884 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1885 HDA_OUTPUT, spec->vmaster_tlv);
1886 if (spec->dac_min_mute)
1887 spec->vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
1891 /* set initial pinctl targets */
1892 if (spec->prefer_hp_amp || cfg->line_out_type == AUTO_PIN_HP_OUT)
1896 set_pin_targets(codec, cfg->line_outs, cfg->line_out_pins, val);
1897 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1898 set_pin_targets(codec, cfg->hp_outs, cfg->hp_pins, PIN_HP);
1899 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1900 val = spec->prefer_hp_amp ? PIN_HP : PIN_OUT;
1901 set_pin_targets(codec, cfg->speaker_outs,
1902 cfg->speaker_pins, val);
1905 /* clear indep_hp flag if not available */
1906 if (spec->indep_hp && !indep_hp_possible(codec))
1913 /* add playback controls from the parsed DAC table */
1914 static int create_multi_out_ctls(struct hda_codec *codec,
1915 const struct auto_pin_cfg *cfg)
1917 struct hda_gen_spec *spec = codec->spec;
1918 int i, err, noutputs;
1920 noutputs = cfg->line_outs;
1921 if (spec->multi_ios > 0 && cfg->line_outs < 3)
1922 noutputs += spec->multi_ios;
1924 for (i = 0; i < noutputs; i++) {
1927 struct nid_path *path;
1929 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
1933 name = get_line_out_pfx(codec, i, &index, NID_PATH_VOL_CTL);
1934 if (!name || !strcmp(name, "CLFE")) {
1936 err = add_vol_ctl(codec, "Center", 0, 1, path);
1939 err = add_vol_ctl(codec, "LFE", 0, 2, path);
1943 err = add_stereo_vol(codec, name, index, path);
1948 name = get_line_out_pfx(codec, i, &index, NID_PATH_MUTE_CTL);
1949 if (!name || !strcmp(name, "CLFE")) {
1950 err = add_sw_ctl(codec, "Center", 0, 1, path);
1953 err = add_sw_ctl(codec, "LFE", 0, 2, path);
1957 err = add_stereo_sw(codec, name, index, path);
1965 static int create_extra_out(struct hda_codec *codec, int path_idx,
1966 const char *pfx, int cidx)
1968 struct nid_path *path;
1971 path = snd_hda_get_path_from_idx(codec, path_idx);
1974 err = add_stereo_vol(codec, pfx, cidx, path);
1977 err = add_stereo_sw(codec, pfx, cidx, path);
1983 /* add playback controls for speaker and HP outputs */
1984 static int create_extra_outs(struct hda_codec *codec, int num_pins,
1985 const int *paths, const char *pfx)
1989 for (i = 0; i < num_pins; i++) {
1991 char tmp[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
1994 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker"))
1995 name = "Bass Speaker";
1996 else if (num_pins >= 3) {
1997 snprintf(tmp, sizeof(tmp), "%s %s",
1998 pfx, channel_name[i]);
2004 err = create_extra_out(codec, paths[i], name, idx);
2011 static int create_hp_out_ctls(struct hda_codec *codec)
2013 struct hda_gen_spec *spec = codec->spec;
2014 return create_extra_outs(codec, spec->autocfg.hp_outs,
2019 static int create_speaker_out_ctls(struct hda_codec *codec)
2021 struct hda_gen_spec *spec = codec->spec;
2022 return create_extra_outs(codec, spec->autocfg.speaker_outs,
2023 spec->speaker_paths,
2028 * independent HP controls
2031 static void call_hp_automute(struct hda_codec *codec,
2032 struct hda_jack_callback *jack);
2033 static int indep_hp_info(struct snd_kcontrol *kcontrol,
2034 struct snd_ctl_elem_info *uinfo)
2036 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
2039 static int indep_hp_get(struct snd_kcontrol *kcontrol,
2040 struct snd_ctl_elem_value *ucontrol)
2042 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2043 struct hda_gen_spec *spec = codec->spec;
2044 ucontrol->value.enumerated.item[0] = spec->indep_hp_enabled;
2048 static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
2049 int nomix_path_idx, int mix_path_idx,
2052 static int indep_hp_put(struct snd_kcontrol *kcontrol,
2053 struct snd_ctl_elem_value *ucontrol)
2055 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2056 struct hda_gen_spec *spec = codec->spec;
2057 unsigned int select = ucontrol->value.enumerated.item[0];
2060 mutex_lock(&spec->pcm_mutex);
2061 if (spec->active_streams) {
2066 if (spec->indep_hp_enabled != select) {
2068 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
2069 dacp = &spec->private_dac_nids[0];
2071 dacp = &spec->multiout.hp_out_nid[0];
2073 /* update HP aamix paths in case it conflicts with indep HP */
2074 if (spec->have_aamix_ctl) {
2075 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
2076 update_aamix_paths(codec, spec->aamix_mode,
2078 spec->aamix_out_paths[0],
2079 spec->autocfg.line_out_type);
2081 update_aamix_paths(codec, spec->aamix_mode,
2083 spec->aamix_out_paths[1],
2087 spec->indep_hp_enabled = select;
2088 if (spec->indep_hp_enabled)
2091 *dacp = spec->alt_dac_nid;
2093 call_hp_automute(codec, NULL);
2097 mutex_unlock(&spec->pcm_mutex);
2101 static const struct snd_kcontrol_new indep_hp_ctl = {
2102 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2103 .name = "Independent HP",
2104 .info = indep_hp_info,
2105 .get = indep_hp_get,
2106 .put = indep_hp_put,
2110 static int create_indep_hp_ctls(struct hda_codec *codec)
2112 struct hda_gen_spec *spec = codec->spec;
2115 if (!spec->indep_hp)
2117 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
2118 dac = spec->multiout.dac_nids[0];
2120 dac = spec->multiout.hp_out_nid[0];
2126 spec->indep_hp_enabled = false;
2127 spec->alt_dac_nid = dac;
2128 if (!snd_hda_gen_add_kctl(spec, NULL, &indep_hp_ctl))
2134 * channel mode enum control
2137 static int ch_mode_info(struct snd_kcontrol *kcontrol,
2138 struct snd_ctl_elem_info *uinfo)
2140 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2141 struct hda_gen_spec *spec = codec->spec;
2144 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2146 uinfo->value.enumerated.items = spec->multi_ios + 1;
2147 if (uinfo->value.enumerated.item > spec->multi_ios)
2148 uinfo->value.enumerated.item = spec->multi_ios;
2149 chs = uinfo->value.enumerated.item * 2 + spec->min_channel_count;
2150 sprintf(uinfo->value.enumerated.name, "%dch", chs);
2154 static int ch_mode_get(struct snd_kcontrol *kcontrol,
2155 struct snd_ctl_elem_value *ucontrol)
2157 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2158 struct hda_gen_spec *spec = codec->spec;
2159 ucontrol->value.enumerated.item[0] =
2160 (spec->ext_channel_count - spec->min_channel_count) / 2;
2164 static inline struct nid_path *
2165 get_multiio_path(struct hda_codec *codec, int idx)
2167 struct hda_gen_spec *spec = codec->spec;
2168 return snd_hda_get_path_from_idx(codec,
2169 spec->out_paths[spec->autocfg.line_outs + idx]);
2172 static void update_automute_all(struct hda_codec *codec);
2174 /* Default value to be passed as aamix argument for snd_hda_activate_path();
2175 * used for output paths
2177 static bool aamix_default(struct hda_gen_spec *spec)
2179 return !spec->have_aamix_ctl || spec->aamix_mode;
2182 static int set_multi_io(struct hda_codec *codec, int idx, bool output)
2184 struct hda_gen_spec *spec = codec->spec;
2185 hda_nid_t nid = spec->multi_io[idx].pin;
2186 struct nid_path *path;
2188 path = get_multiio_path(codec, idx);
2192 if (path->active == output)
2196 set_pin_target(codec, nid, PIN_OUT, true);
2197 snd_hda_activate_path(codec, path, true, aamix_default(spec));
2198 set_pin_eapd(codec, nid, true);
2200 set_pin_eapd(codec, nid, false);
2201 snd_hda_activate_path(codec, path, false, aamix_default(spec));
2202 set_pin_target(codec, nid, spec->multi_io[idx].ctl_in, true);
2203 path_power_down_sync(codec, path);
2206 /* update jack retasking in case it modifies any of them */
2207 update_automute_all(codec);
2212 static int ch_mode_put(struct snd_kcontrol *kcontrol,
2213 struct snd_ctl_elem_value *ucontrol)
2215 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2216 struct hda_gen_spec *spec = codec->spec;
2219 ch = ucontrol->value.enumerated.item[0];
2220 if (ch < 0 || ch > spec->multi_ios)
2222 if (ch == (spec->ext_channel_count - spec->min_channel_count) / 2)
2224 spec->ext_channel_count = ch * 2 + spec->min_channel_count;
2225 for (i = 0; i < spec->multi_ios; i++)
2226 set_multi_io(codec, i, i < ch);
2227 spec->multiout.max_channels = max(spec->ext_channel_count,
2228 spec->const_channel_count);
2229 if (spec->need_dac_fix)
2230 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
2234 static const struct snd_kcontrol_new channel_mode_enum = {
2235 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2236 .name = "Channel Mode",
2237 .info = ch_mode_info,
2242 static int create_multi_channel_mode(struct hda_codec *codec)
2244 struct hda_gen_spec *spec = codec->spec;
2246 if (spec->multi_ios > 0) {
2247 if (!snd_hda_gen_add_kctl(spec, NULL, &channel_mode_enum))
2254 * aamix loopback enable/disable switch
2257 #define loopback_mixing_info indep_hp_info
2259 static int loopback_mixing_get(struct snd_kcontrol *kcontrol,
2260 struct snd_ctl_elem_value *ucontrol)
2262 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2263 struct hda_gen_spec *spec = codec->spec;
2264 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2268 static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
2269 int nomix_path_idx, int mix_path_idx,
2272 struct hda_gen_spec *spec = codec->spec;
2273 struct nid_path *nomix_path, *mix_path;
2275 nomix_path = snd_hda_get_path_from_idx(codec, nomix_path_idx);
2276 mix_path = snd_hda_get_path_from_idx(codec, mix_path_idx);
2277 if (!nomix_path || !mix_path)
2280 /* if HP aamix path is driven from a different DAC and the
2281 * independent HP mode is ON, can't turn on aamix path
2283 if (out_type == AUTO_PIN_HP_OUT && spec->indep_hp_enabled &&
2284 mix_path->path[0] != spec->alt_dac_nid)
2288 snd_hda_activate_path(codec, nomix_path, false, true);
2289 snd_hda_activate_path(codec, mix_path, true, true);
2290 path_power_down_sync(codec, nomix_path);
2292 snd_hda_activate_path(codec, mix_path, false, false);
2293 snd_hda_activate_path(codec, nomix_path, true, false);
2294 path_power_down_sync(codec, mix_path);
2298 static int loopback_mixing_put(struct snd_kcontrol *kcontrol,
2299 struct snd_ctl_elem_value *ucontrol)
2301 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2302 struct hda_gen_spec *spec = codec->spec;
2303 unsigned int val = ucontrol->value.enumerated.item[0];
2305 if (val == spec->aamix_mode)
2307 spec->aamix_mode = val;
2308 update_aamix_paths(codec, val, spec->out_paths[0],
2309 spec->aamix_out_paths[0],
2310 spec->autocfg.line_out_type);
2311 update_aamix_paths(codec, val, spec->hp_paths[0],
2312 spec->aamix_out_paths[1],
2314 update_aamix_paths(codec, val, spec->speaker_paths[0],
2315 spec->aamix_out_paths[2],
2316 AUTO_PIN_SPEAKER_OUT);
2320 static const struct snd_kcontrol_new loopback_mixing_enum = {
2321 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2322 .name = "Loopback Mixing",
2323 .info = loopback_mixing_info,
2324 .get = loopback_mixing_get,
2325 .put = loopback_mixing_put,
2328 static int create_loopback_mixing_ctl(struct hda_codec *codec)
2330 struct hda_gen_spec *spec = codec->spec;
2332 if (!spec->mixer_nid)
2334 if (!(spec->aamix_out_paths[0] || spec->aamix_out_paths[1] ||
2335 spec->aamix_out_paths[2]))
2337 if (!snd_hda_gen_add_kctl(spec, NULL, &loopback_mixing_enum))
2339 spec->have_aamix_ctl = 1;
2344 * shared headphone/mic handling
2347 static void call_update_outputs(struct hda_codec *codec);
2349 /* for shared I/O, change the pin-control accordingly */
2350 static void update_hp_mic(struct hda_codec *codec, int adc_mux, bool force)
2352 struct hda_gen_spec *spec = codec->spec;
2357 pin = spec->hp_mic_pin;
2358 as_mic = spec->cur_mux[adc_mux] == spec->hp_mic_mux_idx;
2361 val = snd_hda_codec_get_pin_target(codec, pin);
2371 val = snd_hda_get_default_vref(codec, pin);
2372 /* if the HP pin doesn't support VREF and the codec driver gives an
2373 * alternative pin, set up the VREF on that pin instead
2375 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
2376 const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
2377 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
2378 if (vref_val != AC_PINCTL_VREF_HIZ)
2379 snd_hda_set_pin_ctl_cache(codec, vref_pin,
2380 PIN_IN | (as_mic ? vref_val : 0));
2383 if (!spec->hp_mic_jack_modes) {
2388 set_pin_target(codec, pin, val, true);
2389 call_hp_automute(codec, NULL);
2393 /* create a shared input with the headphone out */
2394 static int create_hp_mic(struct hda_codec *codec)
2396 struct hda_gen_spec *spec = codec->spec;
2397 struct auto_pin_cfg *cfg = &spec->autocfg;
2398 unsigned int defcfg;
2401 if (!spec->hp_mic) {
2402 if (spec->suppress_hp_mic_detect)
2404 /* automatic detection: only if no input or a single internal
2405 * input pin is found, try to detect the shared hp/mic
2407 if (cfg->num_inputs > 1)
2409 else if (cfg->num_inputs == 1) {
2410 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2411 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2416 spec->hp_mic = 0; /* clear once */
2417 if (cfg->num_inputs >= AUTO_CFG_MAX_INS)
2421 if (cfg->line_out_type == AUTO_PIN_HP_OUT && cfg->line_outs > 0)
2422 nid = cfg->line_out_pins[0];
2423 else if (cfg->hp_outs > 0)
2424 nid = cfg->hp_pins[0];
2428 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2429 return 0; /* no input */
2431 cfg->inputs[cfg->num_inputs].pin = nid;
2432 cfg->inputs[cfg->num_inputs].type = AUTO_PIN_MIC;
2433 cfg->inputs[cfg->num_inputs].is_headphone_mic = 1;
2436 spec->hp_mic_pin = nid;
2437 /* we can't handle auto-mic together with HP-mic */
2438 spec->suppress_auto_mic = 1;
2439 codec_dbg(codec, "Enable shared I/O jack on NID 0x%x\n", nid);
2447 static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin);
2449 static const char * const out_jack_texts[] = {
2450 "Line Out", "Headphone Out",
2453 static int out_jack_mode_info(struct snd_kcontrol *kcontrol,
2454 struct snd_ctl_elem_info *uinfo)
2456 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, out_jack_texts);
2459 static int out_jack_mode_get(struct snd_kcontrol *kcontrol,
2460 struct snd_ctl_elem_value *ucontrol)
2462 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2463 hda_nid_t nid = kcontrol->private_value;
2464 if (snd_hda_codec_get_pin_target(codec, nid) == PIN_HP)
2465 ucontrol->value.enumerated.item[0] = 1;
2467 ucontrol->value.enumerated.item[0] = 0;
2471 static int out_jack_mode_put(struct snd_kcontrol *kcontrol,
2472 struct snd_ctl_elem_value *ucontrol)
2474 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2475 hda_nid_t nid = kcontrol->private_value;
2478 val = ucontrol->value.enumerated.item[0] ? PIN_HP : PIN_OUT;
2479 if (snd_hda_codec_get_pin_target(codec, nid) == val)
2481 snd_hda_set_pin_ctl_cache(codec, nid, val);
2485 static const struct snd_kcontrol_new out_jack_mode_enum = {
2486 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2487 .info = out_jack_mode_info,
2488 .get = out_jack_mode_get,
2489 .put = out_jack_mode_put,
2492 static bool find_kctl_name(struct hda_codec *codec, const char *name, int idx)
2494 struct hda_gen_spec *spec = codec->spec;
2497 for (i = 0; i < spec->kctls.used; i++) {
2498 struct snd_kcontrol_new *kctl = snd_array_elem(&spec->kctls, i);
2499 if (!strcmp(kctl->name, name) && kctl->index == idx)
2505 static void get_jack_mode_name(struct hda_codec *codec, hda_nid_t pin,
2506 char *name, size_t name_len)
2508 struct hda_gen_spec *spec = codec->spec;
2511 snd_hda_get_pin_label(codec, pin, &spec->autocfg, name, name_len, &idx);
2512 strlcat(name, " Jack Mode", name_len);
2514 for (; find_kctl_name(codec, name, idx); idx++)
2518 static int get_out_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2520 struct hda_gen_spec *spec = codec->spec;
2521 if (spec->add_jack_modes) {
2522 unsigned int pincap = snd_hda_query_pin_caps(codec, pin);
2523 if ((pincap & AC_PINCAP_OUT) && (pincap & AC_PINCAP_HP_DRV))
2529 static int create_out_jack_modes(struct hda_codec *codec, int num_pins,
2532 struct hda_gen_spec *spec = codec->spec;
2535 for (i = 0; i < num_pins; i++) {
2536 hda_nid_t pin = pins[i];
2537 if (pin == spec->hp_mic_pin)
2539 if (get_out_jack_num_items(codec, pin) > 1) {
2540 struct snd_kcontrol_new *knew;
2541 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
2542 get_jack_mode_name(codec, pin, name, sizeof(name));
2543 knew = snd_hda_gen_add_kctl(spec, name,
2544 &out_jack_mode_enum);
2547 knew->private_value = pin;
2558 /* from AC_PINCTL_VREF_HIZ to AC_PINCTL_VREF_100 */
2561 static const char * const vref_texts[NUM_VREFS] = {
2562 "Line In", "Mic 50pc Bias", "Mic 0V Bias",
2563 "", "Mic 80pc Bias", "Mic 100pc Bias"
2566 static unsigned int get_vref_caps(struct hda_codec *codec, hda_nid_t pin)
2568 unsigned int pincap;
2570 pincap = snd_hda_query_pin_caps(codec, pin);
2571 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2572 /* filter out unusual vrefs */
2573 pincap &= ~(AC_PINCAP_VREF_GRD | AC_PINCAP_VREF_100);
2577 /* convert from the enum item index to the vref ctl index (0=HIZ, 1=50%...) */
2578 static int get_vref_idx(unsigned int vref_caps, unsigned int item_idx)
2580 unsigned int i, n = 0;
2582 for (i = 0; i < NUM_VREFS; i++) {
2583 if (vref_caps & (1 << i)) {
2592 /* convert back from the vref ctl index to the enum item index */
2593 static int cvt_from_vref_idx(unsigned int vref_caps, unsigned int idx)
2595 unsigned int i, n = 0;
2597 for (i = 0; i < NUM_VREFS; i++) {
2600 if (vref_caps & (1 << i))
2606 static int in_jack_mode_info(struct snd_kcontrol *kcontrol,
2607 struct snd_ctl_elem_info *uinfo)
2609 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2610 hda_nid_t nid = kcontrol->private_value;
2611 unsigned int vref_caps = get_vref_caps(codec, nid);
2613 snd_hda_enum_helper_info(kcontrol, uinfo, hweight32(vref_caps),
2615 /* set the right text */
2616 strcpy(uinfo->value.enumerated.name,
2617 vref_texts[get_vref_idx(vref_caps, uinfo->value.enumerated.item)]);
2621 static int in_jack_mode_get(struct snd_kcontrol *kcontrol,
2622 struct snd_ctl_elem_value *ucontrol)
2624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2625 hda_nid_t nid = kcontrol->private_value;
2626 unsigned int vref_caps = get_vref_caps(codec, nid);
2629 idx = snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_VREFEN;
2630 ucontrol->value.enumerated.item[0] = cvt_from_vref_idx(vref_caps, idx);
2634 static int in_jack_mode_put(struct snd_kcontrol *kcontrol,
2635 struct snd_ctl_elem_value *ucontrol)
2637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2638 hda_nid_t nid = kcontrol->private_value;
2639 unsigned int vref_caps = get_vref_caps(codec, nid);
2640 unsigned int val, idx;
2642 val = snd_hda_codec_get_pin_target(codec, nid);
2643 idx = cvt_from_vref_idx(vref_caps, val & AC_PINCTL_VREFEN);
2644 if (idx == ucontrol->value.enumerated.item[0])
2647 val &= ~AC_PINCTL_VREFEN;
2648 val |= get_vref_idx(vref_caps, ucontrol->value.enumerated.item[0]);
2649 snd_hda_set_pin_ctl_cache(codec, nid, val);
2653 static const struct snd_kcontrol_new in_jack_mode_enum = {
2654 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2655 .info = in_jack_mode_info,
2656 .get = in_jack_mode_get,
2657 .put = in_jack_mode_put,
2660 static int get_in_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2662 struct hda_gen_spec *spec = codec->spec;
2664 if (spec->add_jack_modes)
2665 nitems = hweight32(get_vref_caps(codec, pin));
2666 return nitems ? nitems : 1;
2669 static int create_in_jack_mode(struct hda_codec *codec, hda_nid_t pin)
2671 struct hda_gen_spec *spec = codec->spec;
2672 struct snd_kcontrol_new *knew;
2673 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
2674 unsigned int defcfg;
2676 if (pin == spec->hp_mic_pin)
2677 return 0; /* already done in create_out_jack_mode() */
2679 /* no jack mode for fixed pins */
2680 defcfg = snd_hda_codec_get_pincfg(codec, pin);
2681 if (snd_hda_get_input_pin_attr(defcfg) == INPUT_PIN_ATTR_INT)
2684 /* no multiple vref caps? */
2685 if (get_in_jack_num_items(codec, pin) <= 1)
2688 get_jack_mode_name(codec, pin, name, sizeof(name));
2689 knew = snd_hda_gen_add_kctl(spec, name, &in_jack_mode_enum);
2692 knew->private_value = pin;
2697 * HP/mic shared jack mode
2699 static int hp_mic_jack_mode_info(struct snd_kcontrol *kcontrol,
2700 struct snd_ctl_elem_info *uinfo)
2702 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2703 hda_nid_t nid = kcontrol->private_value;
2704 int out_jacks = get_out_jack_num_items(codec, nid);
2705 int in_jacks = get_in_jack_num_items(codec, nid);
2706 const char *text = NULL;
2709 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2711 uinfo->value.enumerated.items = out_jacks + in_jacks;
2712 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2713 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2714 idx = uinfo->value.enumerated.item;
2715 if (idx < out_jacks) {
2717 text = out_jack_texts[idx];
2719 text = "Headphone Out";
2723 unsigned int vref_caps = get_vref_caps(codec, nid);
2724 text = vref_texts[get_vref_idx(vref_caps, idx)];
2729 strcpy(uinfo->value.enumerated.name, text);
2733 static int get_cur_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t nid)
2735 int out_jacks = get_out_jack_num_items(codec, nid);
2736 int in_jacks = get_in_jack_num_items(codec, nid);
2737 unsigned int val = snd_hda_codec_get_pin_target(codec, nid);
2740 if (val & PIN_OUT) {
2741 if (out_jacks > 1 && val == PIN_HP)
2743 } else if (val & PIN_IN) {
2746 unsigned int vref_caps = get_vref_caps(codec, nid);
2747 val &= AC_PINCTL_VREFEN;
2748 idx += cvt_from_vref_idx(vref_caps, val);
2754 static int hp_mic_jack_mode_get(struct snd_kcontrol *kcontrol,
2755 struct snd_ctl_elem_value *ucontrol)
2757 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2758 hda_nid_t nid = kcontrol->private_value;
2759 ucontrol->value.enumerated.item[0] =
2760 get_cur_hp_mic_jack_mode(codec, nid);
2764 static int hp_mic_jack_mode_put(struct snd_kcontrol *kcontrol,
2765 struct snd_ctl_elem_value *ucontrol)
2767 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2768 hda_nid_t nid = kcontrol->private_value;
2769 int out_jacks = get_out_jack_num_items(codec, nid);
2770 int in_jacks = get_in_jack_num_items(codec, nid);
2771 unsigned int val, oldval, idx;
2773 oldval = get_cur_hp_mic_jack_mode(codec, nid);
2774 idx = ucontrol->value.enumerated.item[0];
2778 if (idx < out_jacks) {
2780 val = idx ? PIN_HP : PIN_OUT;
2786 unsigned int vref_caps = get_vref_caps(codec, nid);
2787 val = snd_hda_codec_get_pin_target(codec, nid);
2788 val &= ~(AC_PINCTL_VREFEN | PIN_HP);
2789 val |= get_vref_idx(vref_caps, idx) | PIN_IN;
2791 val = snd_hda_get_default_vref(codec, nid) | PIN_IN;
2793 snd_hda_set_pin_ctl_cache(codec, nid, val);
2794 call_hp_automute(codec, NULL);
2799 static const struct snd_kcontrol_new hp_mic_jack_mode_enum = {
2800 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2801 .info = hp_mic_jack_mode_info,
2802 .get = hp_mic_jack_mode_get,
2803 .put = hp_mic_jack_mode_put,
2806 static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin)
2808 struct hda_gen_spec *spec = codec->spec;
2809 struct snd_kcontrol_new *knew;
2811 knew = snd_hda_gen_add_kctl(spec, "Headphone Mic Jack Mode",
2812 &hp_mic_jack_mode_enum);
2815 knew->private_value = pin;
2816 spec->hp_mic_jack_modes = 1;
2824 /* add the powersave loopback-list entry */
2825 static int add_loopback_list(struct hda_gen_spec *spec, hda_nid_t mix, int idx)
2827 struct hda_amp_list *list;
2829 list = snd_array_new(&spec->loopback_list);
2833 list->dir = HDA_INPUT;
2835 spec->loopback.amplist = spec->loopback_list.list;
2839 /* return true if either a volume or a mute amp is found for the given
2840 * aamix path; the amp has to be either in the mixer node or its direct leaf
2842 static bool look_for_mix_leaf_ctls(struct hda_codec *codec, hda_nid_t mix_nid,
2843 hda_nid_t pin, unsigned int *mix_val,
2844 unsigned int *mute_val)
2847 const hda_nid_t *list;
2850 idx = snd_hda_get_conn_index(codec, mix_nid, pin, true);
2854 *mix_val = *mute_val = 0;
2855 if (nid_has_volume(codec, mix_nid, HDA_INPUT))
2856 *mix_val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2857 if (nid_has_mute(codec, mix_nid, HDA_INPUT))
2858 *mute_val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2859 if (*mix_val && *mute_val)
2862 /* check leaf node */
2863 num_conns = snd_hda_get_conn_list(codec, mix_nid, &list);
2864 if (num_conns < idx)
2867 if (!*mix_val && nid_has_volume(codec, nid, HDA_OUTPUT) &&
2868 !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_VOL_CTL))
2869 *mix_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2870 if (!*mute_val && nid_has_mute(codec, nid, HDA_OUTPUT) &&
2871 !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_MUTE_CTL))
2872 *mute_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2874 return *mix_val || *mute_val;
2877 /* create input playback/capture controls for the given pin */
2878 static int new_analog_input(struct hda_codec *codec, int input_idx,
2879 hda_nid_t pin, const char *ctlname, int ctlidx,
2882 struct hda_gen_spec *spec = codec->spec;
2883 struct nid_path *path;
2884 unsigned int mix_val, mute_val;
2887 if (!look_for_mix_leaf_ctls(codec, mix_nid, pin, &mix_val, &mute_val))
2890 path = snd_hda_add_new_path(codec, pin, mix_nid, 0);
2893 print_nid_path(codec, "loopback", path);
2894 spec->loopback_paths[input_idx] = snd_hda_get_path_idx(codec, path);
2896 idx = path->idx[path->depth - 1];
2898 err = __add_pb_vol_ctrl(spec, HDA_CTL_WIDGET_VOL, ctlname, ctlidx, mix_val);
2901 path->ctls[NID_PATH_VOL_CTL] = mix_val;
2905 err = __add_pb_sw_ctrl(spec, HDA_CTL_WIDGET_MUTE, ctlname, ctlidx, mute_val);
2908 path->ctls[NID_PATH_MUTE_CTL] = mute_val;
2911 path->active = true;
2912 err = add_loopback_list(spec, mix_nid, idx);
2916 if (spec->mixer_nid != spec->mixer_merge_nid &&
2917 !spec->loopback_merge_path) {
2918 path = snd_hda_add_new_path(codec, spec->mixer_nid,
2919 spec->mixer_merge_nid, 0);
2921 print_nid_path(codec, "loopback-merge", path);
2922 path->active = true;
2923 spec->loopback_merge_path =
2924 snd_hda_get_path_idx(codec, path);
2931 static int is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2933 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2934 return (pincap & AC_PINCAP_IN) != 0;
2937 /* Parse the codec tree and retrieve ADCs */
2938 static int fill_adc_nids(struct hda_codec *codec)
2940 struct hda_gen_spec *spec = codec->spec;
2942 hda_nid_t *adc_nids = spec->adc_nids;
2943 int max_nums = ARRAY_SIZE(spec->adc_nids);
2946 nid = codec->start_nid;
2947 for (i = 0; i < codec->num_nodes; i++, nid++) {
2948 unsigned int caps = get_wcaps(codec, nid);
2949 int type = get_wcaps_type(caps);
2951 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2953 adc_nids[nums] = nid;
2954 if (++nums >= max_nums)
2957 spec->num_adc_nids = nums;
2959 /* copy the detected ADCs to all_adcs[] */
2960 spec->num_all_adcs = nums;
2961 memcpy(spec->all_adcs, spec->adc_nids, nums * sizeof(hda_nid_t));
2966 /* filter out invalid adc_nids that don't give all active input pins;
2967 * if needed, check whether dynamic ADC-switching is available
2969 static int check_dyn_adc_switch(struct hda_codec *codec)
2971 struct hda_gen_spec *spec = codec->spec;
2972 struct hda_input_mux *imux = &spec->input_mux;
2973 unsigned int ok_bits;
2978 for (n = 0; n < spec->num_adc_nids; n++) {
2979 for (i = 0; i < imux->num_items; i++) {
2980 if (!spec->input_paths[i][n])
2983 if (i >= imux->num_items) {
2984 ok_bits |= (1 << n);
2990 /* check whether ADC-switch is possible */
2991 for (i = 0; i < imux->num_items; i++) {
2992 for (n = 0; n < spec->num_adc_nids; n++) {
2993 if (spec->input_paths[i][n]) {
2994 spec->dyn_adc_idx[i] = n;
3000 codec_dbg(codec, "enabling ADC switching\n");
3001 spec->dyn_adc_switch = 1;
3002 } else if (nums != spec->num_adc_nids) {
3003 /* shrink the invalid adcs and input paths */
3005 for (n = 0; n < spec->num_adc_nids; n++) {
3006 if (!(ok_bits & (1 << n)))
3009 spec->adc_nids[nums] = spec->adc_nids[n];
3010 for (i = 0; i < imux->num_items; i++) {
3011 invalidate_nid_path(codec,
3012 spec->input_paths[i][nums]);
3013 spec->input_paths[i][nums] =
3014 spec->input_paths[i][n];
3019 spec->num_adc_nids = nums;
3022 if (imux->num_items == 1 ||
3023 (imux->num_items == 2 && spec->hp_mic)) {
3024 codec_dbg(codec, "reducing to a single ADC\n");
3025 spec->num_adc_nids = 1; /* reduce to a single ADC */
3028 /* single index for individual volumes ctls */
3029 if (!spec->dyn_adc_switch && spec->multi_cap_vol)
3030 spec->num_adc_nids = 1;
3035 /* parse capture source paths from the given pin and create imux items */
3036 static int parse_capture_source(struct hda_codec *codec, hda_nid_t pin,
3037 int cfg_idx, int num_adcs,
3038 const char *label, int anchor)
3040 struct hda_gen_spec *spec = codec->spec;
3041 struct hda_input_mux *imux = &spec->input_mux;
3042 int imux_idx = imux->num_items;
3043 bool imux_added = false;
3046 for (c = 0; c < num_adcs; c++) {
3047 struct nid_path *path;
3048 hda_nid_t adc = spec->adc_nids[c];
3050 if (!is_reachable_path(codec, pin, adc))
3052 path = snd_hda_add_new_path(codec, pin, adc, anchor);
3055 print_nid_path(codec, "input", path);
3056 spec->input_paths[imux_idx][c] =
3057 snd_hda_get_path_idx(codec, path);
3060 if (spec->hp_mic_pin == pin)
3061 spec->hp_mic_mux_idx = imux->num_items;
3062 spec->imux_pins[imux->num_items] = pin;
3063 snd_hda_add_imux_item(codec, imux, label, cfg_idx, NULL);
3065 if (spec->dyn_adc_switch)
3066 spec->dyn_adc_idx[imux_idx] = c;
3074 * create playback/capture controls for input pins
3077 /* fill the label for each input at first */
3078 static int fill_input_pin_labels(struct hda_codec *codec)
3080 struct hda_gen_spec *spec = codec->spec;
3081 const struct auto_pin_cfg *cfg = &spec->autocfg;
3084 for (i = 0; i < cfg->num_inputs; i++) {
3085 hda_nid_t pin = cfg->inputs[i].pin;
3089 if (!is_input_pin(codec, pin))
3092 label = hda_get_autocfg_input_label(codec, cfg, i);
3094 for (j = i - 1; j >= 0; j--) {
3095 if (spec->input_labels[j] &&
3096 !strcmp(spec->input_labels[j], label)) {
3097 idx = spec->input_label_idxs[j] + 1;
3102 spec->input_labels[i] = label;
3103 spec->input_label_idxs[i] = idx;
3109 #define CFG_IDX_MIX 99 /* a dummy cfg->input idx for stereo mix */
3111 static int create_input_ctls(struct hda_codec *codec)
3113 struct hda_gen_spec *spec = codec->spec;
3114 const struct auto_pin_cfg *cfg = &spec->autocfg;
3115 hda_nid_t mixer = spec->mixer_nid;
3120 num_adcs = fill_adc_nids(codec);
3124 err = fill_input_pin_labels(codec);
3128 for (i = 0; i < cfg->num_inputs; i++) {
3131 pin = cfg->inputs[i].pin;
3132 if (!is_input_pin(codec, pin))
3136 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3137 val |= snd_hda_get_default_vref(codec, pin);
3138 if (pin != spec->hp_mic_pin)
3139 set_pin_target(codec, pin, val, false);
3142 if (is_reachable_path(codec, pin, mixer)) {
3143 err = new_analog_input(codec, i, pin,
3144 spec->input_labels[i],
3145 spec->input_label_idxs[i],
3152 err = parse_capture_source(codec, pin, i, num_adcs,
3153 spec->input_labels[i], -mixer);
3157 if (spec->add_jack_modes) {
3158 err = create_in_jack_mode(codec, pin);
3164 /* add stereo mix when explicitly enabled via hint */
3165 if (mixer && spec->add_stereo_mix_input &&
3166 snd_hda_get_bool_hint(codec, "add_stereo_mix_input") > 0) {
3167 err = parse_capture_source(codec, mixer, CFG_IDX_MIX, num_adcs,
3181 /* get the input path specified by the given adc and imux indices */
3182 static struct nid_path *get_input_path(struct hda_codec *codec, int adc_idx, int imux_idx)
3184 struct hda_gen_spec *spec = codec->spec;
3185 if (imux_idx < 0 || imux_idx >= HDA_MAX_NUM_INPUTS) {
3189 if (spec->dyn_adc_switch)
3190 adc_idx = spec->dyn_adc_idx[imux_idx];
3191 if (adc_idx < 0 || adc_idx >= AUTO_CFG_MAX_INS) {
3195 return snd_hda_get_path_from_idx(codec, spec->input_paths[imux_idx][adc_idx]);
3198 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3201 static int mux_enum_info(struct snd_kcontrol *kcontrol,
3202 struct snd_ctl_elem_info *uinfo)
3204 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3205 struct hda_gen_spec *spec = codec->spec;
3206 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
3209 static int mux_enum_get(struct snd_kcontrol *kcontrol,
3210 struct snd_ctl_elem_value *ucontrol)
3212 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3213 struct hda_gen_spec *spec = codec->spec;
3214 /* the ctls are created at once with multiple counts */
3215 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
3217 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
3221 static int mux_enum_put(struct snd_kcontrol *kcontrol,
3222 struct snd_ctl_elem_value *ucontrol)
3224 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3225 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
3226 return mux_select(codec, adc_idx,
3227 ucontrol->value.enumerated.item[0]);
3230 static const struct snd_kcontrol_new cap_src_temp = {
3231 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3232 .name = "Input Source",
3233 .info = mux_enum_info,
3234 .get = mux_enum_get,
3235 .put = mux_enum_put,
3239 * capture volume and capture switch ctls
3242 typedef int (*put_call_t)(struct snd_kcontrol *kcontrol,
3243 struct snd_ctl_elem_value *ucontrol);
3245 /* call the given amp update function for all amps in the imux list at once */
3246 static int cap_put_caller(struct snd_kcontrol *kcontrol,
3247 struct snd_ctl_elem_value *ucontrol,
3248 put_call_t func, int type)
3250 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3251 struct hda_gen_spec *spec = codec->spec;
3252 const struct hda_input_mux *imux;
3253 struct nid_path *path;
3254 int i, adc_idx, err = 0;
3256 imux = &spec->input_mux;
3257 adc_idx = kcontrol->id.index;
3258 mutex_lock(&codec->control_mutex);
3259 /* we use the cache-only update at first since multiple input paths
3260 * may shared the same amp; by updating only caches, the redundant
3261 * writes to hardware can be reduced.
3263 codec->cached_write = 1;
3264 for (i = 0; i < imux->num_items; i++) {
3265 path = get_input_path(codec, adc_idx, i);
3266 if (!path || !path->ctls[type])
3268 kcontrol->private_value = path->ctls[type];
3269 err = func(kcontrol, ucontrol);
3274 codec->cached_write = 0;
3275 mutex_unlock(&codec->control_mutex);
3276 snd_hda_codec_flush_cache(codec); /* flush the updates */
3277 if (err >= 0 && spec->cap_sync_hook)
3278 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3282 /* capture volume ctl callbacks */
3283 #define cap_vol_info snd_hda_mixer_amp_volume_info
3284 #define cap_vol_get snd_hda_mixer_amp_volume_get
3285 #define cap_vol_tlv snd_hda_mixer_amp_tlv
3287 static int cap_vol_put(struct snd_kcontrol *kcontrol,
3288 struct snd_ctl_elem_value *ucontrol)
3290 return cap_put_caller(kcontrol, ucontrol,
3291 snd_hda_mixer_amp_volume_put,
3295 static const struct snd_kcontrol_new cap_vol_temp = {
3296 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3297 .name = "Capture Volume",
3298 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
3299 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
3300 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
3301 .info = cap_vol_info,
3304 .tlv = { .c = cap_vol_tlv },
3307 /* capture switch ctl callbacks */
3308 #define cap_sw_info snd_ctl_boolean_stereo_info
3309 #define cap_sw_get snd_hda_mixer_amp_switch_get
3311 static int cap_sw_put(struct snd_kcontrol *kcontrol,
3312 struct snd_ctl_elem_value *ucontrol)
3314 return cap_put_caller(kcontrol, ucontrol,
3315 snd_hda_mixer_amp_switch_put,
3319 static const struct snd_kcontrol_new cap_sw_temp = {
3320 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3321 .name = "Capture Switch",
3322 .info = cap_sw_info,
3327 static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
3332 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
3333 for (depth = 0; depth < 3; depth++) {
3334 if (depth >= path->depth)
3336 i = path->depth - depth - 1;
3337 nid = path->path[i];
3338 if (!path->ctls[NID_PATH_VOL_CTL]) {
3339 if (nid_has_volume(codec, nid, HDA_OUTPUT))
3340 path->ctls[NID_PATH_VOL_CTL] =
3341 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3342 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
3343 int idx = path->idx[i];
3344 if (!depth && codec->single_adc_amp)
3346 path->ctls[NID_PATH_VOL_CTL] =
3347 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
3350 if (!path->ctls[NID_PATH_MUTE_CTL]) {
3351 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3352 path->ctls[NID_PATH_MUTE_CTL] =
3353 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3354 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
3355 int idx = path->idx[i];
3356 if (!depth && codec->single_adc_amp)
3358 path->ctls[NID_PATH_MUTE_CTL] =
3359 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
3366 static bool is_inv_dmic_pin(struct hda_codec *codec, hda_nid_t nid)
3368 struct hda_gen_spec *spec = codec->spec;
3369 struct auto_pin_cfg *cfg = &spec->autocfg;
3373 if (!spec->inv_dmic_split)
3375 for (i = 0; i < cfg->num_inputs; i++) {
3376 if (cfg->inputs[i].pin != nid)
3378 if (cfg->inputs[i].type != AUTO_PIN_MIC)
3380 val = snd_hda_codec_get_pincfg(codec, nid);
3381 return snd_hda_get_input_pin_attr(val) == INPUT_PIN_ATTR_INT;
3386 /* capture switch put callback for a single control with hook call */
3387 static int cap_single_sw_put(struct snd_kcontrol *kcontrol,
3388 struct snd_ctl_elem_value *ucontrol)
3390 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3391 struct hda_gen_spec *spec = codec->spec;
3394 ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3398 if (spec->cap_sync_hook)
3399 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3404 static int add_single_cap_ctl(struct hda_codec *codec, const char *label,
3405 int idx, bool is_switch, unsigned int ctl,
3408 struct hda_gen_spec *spec = codec->spec;
3409 char tmpname[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3410 int type = is_switch ? HDA_CTL_WIDGET_MUTE : HDA_CTL_WIDGET_VOL;
3411 const char *sfx = is_switch ? "Switch" : "Volume";
3412 unsigned int chs = inv_dmic ? 1 : 3;
3413 struct snd_kcontrol_new *knew;
3419 snprintf(tmpname, sizeof(tmpname),
3420 "%s Capture %s", label, sfx);
3422 snprintf(tmpname, sizeof(tmpname),
3424 knew = add_control(spec, type, tmpname, idx,
3425 amp_val_replace_channels(ctl, chs));
3429 knew->put = cap_single_sw_put;
3433 /* Make independent right kcontrol */
3435 snprintf(tmpname, sizeof(tmpname),
3436 "Inverted %s Capture %s", label, sfx);
3438 snprintf(tmpname, sizeof(tmpname),
3439 "Inverted Capture %s", sfx);
3440 knew = add_control(spec, type, tmpname, idx,
3441 amp_val_replace_channels(ctl, 2));
3445 knew->put = cap_single_sw_put;
3449 /* create single (and simple) capture volume and switch controls */
3450 static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx,
3451 unsigned int vol_ctl, unsigned int sw_ctl,
3455 err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl, inv_dmic);
3458 err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl, inv_dmic);
3464 /* create bound capture volume and switch controls */
3465 static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx,
3466 unsigned int vol_ctl, unsigned int sw_ctl)
3468 struct hda_gen_spec *spec = codec->spec;
3469 struct snd_kcontrol_new *knew;
3472 knew = snd_hda_gen_add_kctl(spec, NULL, &cap_vol_temp);
3476 knew->private_value = vol_ctl;
3477 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
3480 knew = snd_hda_gen_add_kctl(spec, NULL, &cap_sw_temp);
3484 knew->private_value = sw_ctl;
3485 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
3490 /* return the vol ctl when used first in the imux list */
3491 static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type)
3493 struct nid_path *path;
3497 path = get_input_path(codec, 0, idx);
3500 ctl = path->ctls[type];
3503 for (i = 0; i < idx - 1; i++) {
3504 path = get_input_path(codec, 0, i);
3505 if (path && path->ctls[type] == ctl)
3511 /* create individual capture volume and switch controls per input */
3512 static int create_multi_cap_vol_ctl(struct hda_codec *codec)
3514 struct hda_gen_spec *spec = codec->spec;
3515 struct hda_input_mux *imux = &spec->input_mux;
3518 for (i = 0; i < imux->num_items; i++) {
3522 idx = imux->items[i].index;
3523 if (idx >= spec->autocfg.num_inputs)
3525 inv_dmic = is_inv_dmic_pin(codec, spec->imux_pins[i]);
3527 for (type = 0; type < 2; type++) {
3528 err = add_single_cap_ctl(codec,
3529 spec->input_labels[idx],
3530 spec->input_label_idxs[idx],
3532 get_first_cap_ctl(codec, i, type),
3541 static int create_capture_mixers(struct hda_codec *codec)
3543 struct hda_gen_spec *spec = codec->spec;
3544 struct hda_input_mux *imux = &spec->input_mux;
3545 int i, n, nums, err;
3547 if (spec->dyn_adc_switch)
3550 nums = spec->num_adc_nids;
3552 if (!spec->auto_mic && imux->num_items > 1) {
3553 struct snd_kcontrol_new *knew;
3555 name = nums > 1 ? "Input Source" : "Capture Source";
3556 knew = snd_hda_gen_add_kctl(spec, name, &cap_src_temp);
3562 for (n = 0; n < nums; n++) {
3564 bool multi_cap_vol = spec->multi_cap_vol;
3565 bool inv_dmic = false;
3569 for (i = 0; i < imux->num_items; i++) {
3570 struct nid_path *path;
3571 path = get_input_path(codec, n, i);
3574 parse_capvol_in_path(codec, path);
3576 vol = path->ctls[NID_PATH_VOL_CTL];
3577 else if (vol != path->ctls[NID_PATH_VOL_CTL]) {
3579 if (!same_amp_caps(codec, vol,
3580 path->ctls[NID_PATH_VOL_CTL], HDA_INPUT))
3581 multi_cap_vol = true;
3584 sw = path->ctls[NID_PATH_MUTE_CTL];
3585 else if (sw != path->ctls[NID_PATH_MUTE_CTL]) {
3587 if (!same_amp_caps(codec, sw,
3588 path->ctls[NID_PATH_MUTE_CTL], HDA_INPUT))
3589 multi_cap_vol = true;
3591 if (is_inv_dmic_pin(codec, spec->imux_pins[i]))
3596 err = create_single_cap_vol_ctl(codec, n, vol, sw,
3598 else if (!multi_cap_vol && !inv_dmic)
3599 err = create_bind_cap_vol_ctl(codec, n, vol, sw);
3601 err = create_multi_cap_vol_ctl(codec);
3610 * add mic boosts if needed
3613 /* check whether the given amp is feasible as a boost volume */
3614 static bool check_boost_vol(struct hda_codec *codec, hda_nid_t nid,
3619 if (!nid_has_volume(codec, nid, dir) ||
3620 is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
3621 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
3624 step = (query_amp_caps(codec, nid, dir) & AC_AMPCAP_STEP_SIZE)
3625 >> AC_AMPCAP_STEP_SIZE_SHIFT;
3631 /* look for a boost amp in a widget close to the pin */
3632 static unsigned int look_for_boost_amp(struct hda_codec *codec,
3633 struct nid_path *path)
3635 unsigned int val = 0;
3639 for (depth = 0; depth < 3; depth++) {
3640 if (depth >= path->depth - 1)
3642 nid = path->path[depth];
3643 if (depth && check_boost_vol(codec, nid, HDA_OUTPUT, 0)) {
3644 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3646 } else if (check_boost_vol(codec, nid, HDA_INPUT,
3647 path->idx[depth])) {
3648 val = HDA_COMPOSE_AMP_VAL(nid, 3, path->idx[depth],
3657 static int parse_mic_boost(struct hda_codec *codec)
3659 struct hda_gen_spec *spec = codec->spec;
3660 struct auto_pin_cfg *cfg = &spec->autocfg;
3661 struct hda_input_mux *imux = &spec->input_mux;
3664 if (!spec->num_adc_nids)
3667 for (i = 0; i < imux->num_items; i++) {
3668 struct nid_path *path;
3671 char boost_label[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3673 idx = imux->items[i].index;
3674 if (idx >= imux->num_items)
3677 /* check only line-in and mic pins */
3678 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
3681 path = get_input_path(codec, 0, i);
3685 val = look_for_boost_amp(codec, path);
3689 /* create a boost control */
3690 snprintf(boost_label, sizeof(boost_label),
3691 "%s Boost Volume", spec->input_labels[idx]);
3692 if (!add_control(spec, HDA_CTL_WIDGET_VOL, boost_label,
3693 spec->input_label_idxs[idx], val))
3696 path->ctls[NID_PATH_BOOST_CTL] = val;
3702 * parse digital I/Os and set up NIDs in BIOS auto-parse mode
3704 static void parse_digital(struct hda_codec *codec)
3706 struct hda_gen_spec *spec = codec->spec;
3707 struct nid_path *path;
3709 hda_nid_t dig_nid, pin;
3711 /* support multiple SPDIFs; the secondary is set up as a slave */
3713 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3714 pin = spec->autocfg.dig_out_pins[i];
3715 dig_nid = look_for_dac(codec, pin, true);
3718 path = snd_hda_add_new_path(codec, dig_nid, pin, 0);
3721 print_nid_path(codec, "digout", path);
3722 path->active = true;
3723 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
3724 set_pin_target(codec, pin, PIN_OUT, false);
3726 spec->multiout.dig_out_nid = dig_nid;
3727 spec->dig_out_type = spec->autocfg.dig_out_type[0];
3729 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
3730 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
3732 spec->slave_dig_outs[nums - 1] = dig_nid;
3737 if (spec->autocfg.dig_in_pin) {
3738 pin = spec->autocfg.dig_in_pin;
3739 dig_nid = codec->start_nid;
3740 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3741 unsigned int wcaps = get_wcaps(codec, dig_nid);
3742 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3744 if (!(wcaps & AC_WCAP_DIGITAL))
3746 path = snd_hda_add_new_path(codec, pin, dig_nid, 0);
3748 print_nid_path(codec, "digin", path);
3749 path->active = true;
3750 spec->dig_in_nid = dig_nid;
3751 spec->digin_path = snd_hda_get_path_idx(codec, path);
3752 set_pin_target(codec, pin, PIN_IN, false);
3761 * input MUX handling
3764 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur);
3766 /* select the given imux item; either unmute exclusively or select the route */
3767 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3770 struct hda_gen_spec *spec = codec->spec;
3771 const struct hda_input_mux *imux;
3772 struct nid_path *old_path, *path;
3774 imux = &spec->input_mux;
3775 if (!imux->num_items)
3778 if (idx >= imux->num_items)
3779 idx = imux->num_items - 1;
3780 if (spec->cur_mux[adc_idx] == idx)
3783 old_path = get_input_path(codec, adc_idx, spec->cur_mux[adc_idx]);
3786 if (old_path->active)
3787 snd_hda_activate_path(codec, old_path, false, false);
3789 spec->cur_mux[adc_idx] = idx;
3792 update_hp_mic(codec, adc_idx, false);
3794 if (spec->dyn_adc_switch)
3795 dyn_adc_pcm_resetup(codec, idx);
3797 path = get_input_path(codec, adc_idx, idx);
3802 snd_hda_activate_path(codec, path, true, false);
3803 if (spec->cap_sync_hook)
3804 spec->cap_sync_hook(codec, NULL, NULL);
3805 path_power_down_sync(codec, old_path);
3811 * Jack detections for HP auto-mute and mic-switch
3814 /* check each pin in the given array; returns true if any of them is plugged */
3815 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3818 bool present = false;
3820 for (i = 0; i < num_pins; i++) {
3821 hda_nid_t nid = pins[i];
3824 /* don't detect pins retasked as inputs */
3825 if (snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_IN_EN)
3827 if (snd_hda_jack_detect_state(codec, nid) == HDA_JACK_PRESENT)
3833 /* standard HP/line-out auto-mute helper */
3834 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
3835 int *paths, bool mute)
3837 struct hda_gen_spec *spec = codec->spec;
3840 for (i = 0; i < num_pins; i++) {
3841 hda_nid_t nid = pins[i];
3842 unsigned int val, oldval;
3846 if (spec->auto_mute_via_amp) {
3847 struct nid_path *path;
3850 path = snd_hda_get_path_from_idx(codec, paths[i]);
3853 mute_nid = get_amp_nid_(path->ctls[NID_PATH_MUTE_CTL]);
3857 spec->mute_bits |= (1ULL << mute_nid);
3859 spec->mute_bits &= ~(1ULL << mute_nid);
3860 set_pin_eapd(codec, nid, !mute);
3864 oldval = snd_hda_codec_get_pin_target(codec, nid);
3865 if (oldval & PIN_IN)
3866 continue; /* no mute for inputs */
3867 /* don't reset VREF value in case it's controlling
3868 * the amp (see alc861_fixup_asus_amp_vref_0f())
3870 if (spec->keep_vref_in_automute)
3871 val = oldval & ~PIN_HP;
3876 /* here we call update_pin_ctl() so that the pinctl is changed
3877 * without changing the pinctl target value;
3878 * the original target value will be still referred at the
3879 * init / resume again
3881 update_pin_ctl(codec, nid, val);
3882 set_pin_eapd(codec, nid, !mute);
3886 /* Toggle outputs muting */
3887 void snd_hda_gen_update_outputs(struct hda_codec *codec)
3889 struct hda_gen_spec *spec = codec->spec;
3893 /* Control HP pins/amps depending on master_mute state;
3894 * in general, HP pins/amps control should be enabled in all cases,
3895 * but currently set only for master_mute, just to be safe
3897 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3898 paths = spec->out_paths;
3900 paths = spec->hp_paths;
3901 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
3902 spec->autocfg.hp_pins, paths, spec->master_mute);
3904 if (!spec->automute_speaker)
3907 on = spec->hp_jack_present | spec->line_jack_present;
3908 on |= spec->master_mute;
3909 spec->speaker_muted = on;
3910 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3911 paths = spec->out_paths;
3913 paths = spec->speaker_paths;
3914 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
3915 spec->autocfg.speaker_pins, paths, on);
3917 /* toggle line-out mutes if needed, too */
3918 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3919 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
3920 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
3922 if (!spec->automute_lo)
3925 on = spec->hp_jack_present;
3926 on |= spec->master_mute;
3927 spec->line_out_muted = on;
3928 paths = spec->out_paths;
3929 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
3930 spec->autocfg.line_out_pins, paths, on);
3932 EXPORT_SYMBOL_GPL(snd_hda_gen_update_outputs);
3934 static void call_update_outputs(struct hda_codec *codec)
3936 struct hda_gen_spec *spec = codec->spec;
3937 if (spec->automute_hook)
3938 spec->automute_hook(codec);
3940 snd_hda_gen_update_outputs(codec);
3942 /* sync the whole vmaster slaves to reflect the new auto-mute status */
3943 if (spec->auto_mute_via_amp && !codec->bus->shutdown)
3944 snd_ctl_sync_vmaster(spec->vmaster_mute.sw_kctl, false);
3947 /* standard HP-automute helper */
3948 void snd_hda_gen_hp_automute(struct hda_codec *codec,
3949 struct hda_jack_callback *jack)
3951 struct hda_gen_spec *spec = codec->spec;
3952 hda_nid_t *pins = spec->autocfg.hp_pins;
3953 int num_pins = ARRAY_SIZE(spec->autocfg.hp_pins);
3955 /* No detection for the first HP jack during indep-HP mode */
3956 if (spec->indep_hp_enabled) {
3961 spec->hp_jack_present = detect_jacks(codec, num_pins, pins);
3962 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
3964 call_update_outputs(codec);
3966 EXPORT_SYMBOL_GPL(snd_hda_gen_hp_automute);
3968 /* standard line-out-automute helper */
3969 void snd_hda_gen_line_automute(struct hda_codec *codec,
3970 struct hda_jack_callback *jack)
3972 struct hda_gen_spec *spec = codec->spec;
3974 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3976 /* check LO jack only when it's different from HP */
3977 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
3980 spec->line_jack_present =
3981 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
3982 spec->autocfg.line_out_pins);
3983 if (!spec->automute_speaker || !spec->detect_lo)
3985 call_update_outputs(codec);
3987 EXPORT_SYMBOL_GPL(snd_hda_gen_line_automute);
3989 /* standard mic auto-switch helper */
3990 void snd_hda_gen_mic_autoswitch(struct hda_codec *codec,
3991 struct hda_jack_callback *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,
4015 struct hda_jack_callback *jack)
4017 struct hda_gen_spec *spec = codec->spec;
4018 if (spec->hp_automute_hook)
4019 spec->hp_automute_hook(codec, jack);
4021 snd_hda_gen_hp_automute(codec, jack);
4024 static void call_line_automute(struct hda_codec *codec,
4025 struct hda_jack_callback *jack)
4027 struct hda_gen_spec *spec = codec->spec;
4028 if (spec->line_automute_hook)
4029 spec->line_automute_hook(codec, jack);
4031 snd_hda_gen_line_automute(codec, jack);
4034 static void call_mic_autoswitch(struct hda_codec *codec,
4035 struct hda_jack_callback *jack)
4037 struct hda_gen_spec *spec = codec->spec;
4038 if (spec->mic_autoswitch_hook)
4039 spec->mic_autoswitch_hook(codec, jack);
4041 snd_hda_gen_mic_autoswitch(codec, jack);
4044 /* update jack retasking */
4045 static void update_automute_all(struct hda_codec *codec)
4047 call_hp_automute(codec, NULL);
4048 call_line_automute(codec, NULL);
4049 call_mic_autoswitch(codec, NULL);
4053 * Auto-Mute mode mixer enum support
4055 static int automute_mode_info(struct snd_kcontrol *kcontrol,
4056 struct snd_ctl_elem_info *uinfo)
4058 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4059 struct hda_gen_spec *spec = codec->spec;
4060 static const char * const texts3[] = {
4061 "Disabled", "Speaker Only", "Line Out+Speaker"
4064 if (spec->automute_speaker_possible && spec->automute_lo_possible)
4065 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
4066 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
4069 static int automute_mode_get(struct snd_kcontrol *kcontrol,
4070 struct snd_ctl_elem_value *ucontrol)
4072 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4073 struct hda_gen_spec *spec = codec->spec;
4074 unsigned int val = 0;
4075 if (spec->automute_speaker)
4077 if (spec->automute_lo)
4080 ucontrol->value.enumerated.item[0] = val;
4084 static int automute_mode_put(struct snd_kcontrol *kcontrol,
4085 struct snd_ctl_elem_value *ucontrol)
4087 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4088 struct hda_gen_spec *spec = codec->spec;
4090 switch (ucontrol->value.enumerated.item[0]) {
4092 if (!spec->automute_speaker && !spec->automute_lo)
4094 spec->automute_speaker = 0;
4095 spec->automute_lo = 0;
4098 if (spec->automute_speaker_possible) {
4099 if (!spec->automute_lo && spec->automute_speaker)
4101 spec->automute_speaker = 1;
4102 spec->automute_lo = 0;
4103 } else if (spec->automute_lo_possible) {
4104 if (spec->automute_lo)
4106 spec->automute_lo = 1;
4111 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
4113 if (spec->automute_speaker && spec->automute_lo)
4115 spec->automute_speaker = 1;
4116 spec->automute_lo = 1;
4121 call_update_outputs(codec);
4125 static const struct snd_kcontrol_new automute_mode_enum = {
4126 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4127 .name = "Auto-Mute Mode",
4128 .info = automute_mode_info,
4129 .get = automute_mode_get,
4130 .put = automute_mode_put,
4133 static int add_automute_mode_enum(struct hda_codec *codec)
4135 struct hda_gen_spec *spec = codec->spec;
4137 if (!snd_hda_gen_add_kctl(spec, NULL, &automute_mode_enum))
4143 * Check the availability of HP/line-out auto-mute;
4144 * Set up appropriately if really supported
4146 static int check_auto_mute_availability(struct hda_codec *codec)
4148 struct hda_gen_spec *spec = codec->spec;
4149 struct auto_pin_cfg *cfg = &spec->autocfg;
4153 if (spec->suppress_auto_mute)
4156 if (cfg->hp_pins[0])
4158 if (cfg->line_out_pins[0])
4160 if (cfg->speaker_pins[0])
4162 if (present < 2) /* need two different output types */
4165 if (!cfg->speaker_pins[0] &&
4166 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
4167 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4168 sizeof(cfg->speaker_pins));
4169 cfg->speaker_outs = cfg->line_outs;
4172 if (!cfg->hp_pins[0] &&
4173 cfg->line_out_type == AUTO_PIN_HP_OUT) {
4174 memcpy(cfg->hp_pins, cfg->line_out_pins,
4175 sizeof(cfg->hp_pins));
4176 cfg->hp_outs = cfg->line_outs;
4179 for (i = 0; i < cfg->hp_outs; i++) {
4180 hda_nid_t nid = cfg->hp_pins[i];
4181 if (!is_jack_detectable(codec, nid))
4183 codec_dbg(codec, "Enable HP auto-muting on NID 0x%x\n", nid);
4184 snd_hda_jack_detect_enable_callback(codec, nid,
4186 spec->detect_hp = 1;
4189 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
4190 if (cfg->speaker_outs)
4191 for (i = 0; i < cfg->line_outs; i++) {
4192 hda_nid_t nid = cfg->line_out_pins[i];
4193 if (!is_jack_detectable(codec, nid))
4195 codec_dbg(codec, "Enable Line-Out auto-muting on NID 0x%x\n", nid);
4196 snd_hda_jack_detect_enable_callback(codec, nid,
4197 call_line_automute);
4198 spec->detect_lo = 1;
4200 spec->automute_lo_possible = spec->detect_hp;
4203 spec->automute_speaker_possible = cfg->speaker_outs &&
4204 (spec->detect_hp || spec->detect_lo);
4206 spec->automute_lo = spec->automute_lo_possible;
4207 spec->automute_speaker = spec->automute_speaker_possible;
4209 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
4210 /* create a control for automute mode */
4211 err = add_automute_mode_enum(codec);
4218 /* check whether all auto-mic pins are valid; setup indices if OK */
4219 static bool auto_mic_check_imux(struct hda_codec *codec)
4221 struct hda_gen_spec *spec = codec->spec;
4222 const struct hda_input_mux *imux;
4225 imux = &spec->input_mux;
4226 for (i = 0; i < spec->am_num_entries; i++) {
4227 spec->am_entry[i].idx =
4228 find_idx_in_nid_list(spec->am_entry[i].pin,
4229 spec->imux_pins, imux->num_items);
4230 if (spec->am_entry[i].idx < 0)
4231 return false; /* no corresponding imux */
4234 /* we don't need the jack detection for the first pin */
4235 for (i = 1; i < spec->am_num_entries; i++)
4236 snd_hda_jack_detect_enable_callback(codec,
4237 spec->am_entry[i].pin,
4238 call_mic_autoswitch);
4242 static int compare_attr(const void *ap, const void *bp)
4244 const struct automic_entry *a = ap;
4245 const struct automic_entry *b = bp;
4246 return (int)(a->attr - b->attr);
4250 * Check the availability of auto-mic switch;
4251 * Set up if really supported
4253 static int check_auto_mic_availability(struct hda_codec *codec)
4255 struct hda_gen_spec *spec = codec->spec;
4256 struct auto_pin_cfg *cfg = &spec->autocfg;
4260 if (spec->suppress_auto_mic)
4265 for (i = 0; i < cfg->num_inputs; i++) {
4266 hda_nid_t nid = cfg->inputs[i].pin;
4268 attr = snd_hda_codec_get_pincfg(codec, nid);
4269 attr = snd_hda_get_input_pin_attr(attr);
4270 if (types & (1 << attr))
4271 return 0; /* already occupied */
4273 case INPUT_PIN_ATTR_INT:
4274 if (cfg->inputs[i].type != AUTO_PIN_MIC)
4275 return 0; /* invalid type */
4277 case INPUT_PIN_ATTR_UNUSED:
4278 return 0; /* invalid entry */
4280 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
4281 return 0; /* invalid type */
4282 if (!spec->line_in_auto_switch &&
4283 cfg->inputs[i].type != AUTO_PIN_MIC)
4284 return 0; /* only mic is allowed */
4285 if (!is_jack_detectable(codec, nid))
4286 return 0; /* no unsol support */
4289 if (num_pins >= MAX_AUTO_MIC_PINS)
4291 types |= (1 << attr);
4292 spec->am_entry[num_pins].pin = nid;
4293 spec->am_entry[num_pins].attr = attr;
4300 spec->am_num_entries = num_pins;
4301 /* sort the am_entry in the order of attr so that the pin with a
4302 * higher attr will be selected when the jack is plugged.
4304 sort(spec->am_entry, num_pins, sizeof(spec->am_entry[0]),
4305 compare_attr, NULL);
4307 if (!auto_mic_check_imux(codec))
4311 spec->num_adc_nids = 1;
4312 spec->cur_mux[0] = spec->am_entry[0].idx;
4313 codec_dbg(codec, "Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
4314 spec->am_entry[0].pin,
4315 spec->am_entry[1].pin,
4316 spec->am_entry[2].pin);
4321 /* power_filter hook; make inactive widgets into power down */
4322 unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
4324 unsigned int power_state)
4326 if (power_state != AC_PWRST_D0 || nid == codec->afg)
4328 if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER)
4330 if (is_active_nid_for_any(codec, nid))
4334 EXPORT_SYMBOL_GPL(snd_hda_gen_path_power_filter);
4336 /* mute all aamix inputs initially; parse up to the first leaves */
4337 static void mute_all_mixer_nid(struct hda_codec *codec, hda_nid_t mix)
4340 const hda_nid_t *conn;
4343 nums = snd_hda_get_conn_list(codec, mix, &conn);
4344 has_amp = nid_has_mute(codec, mix, HDA_INPUT);
4345 for (i = 0; i < nums; i++) {
4347 snd_hda_codec_amp_stereo(codec, mix,
4349 0xff, HDA_AMP_MUTE);
4350 else if (nid_has_volume(codec, conn[i], HDA_OUTPUT))
4351 snd_hda_codec_amp_stereo(codec, conn[i],
4353 0xff, HDA_AMP_MUTE);
4358 * Parse the given BIOS configuration and set up the hda_gen_spec
4360 * return 1 if successful, 0 if the proper config is not found,
4361 * or a negative error code
4363 int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4364 struct auto_pin_cfg *cfg)
4366 struct hda_gen_spec *spec = codec->spec;
4369 parse_user_hints(codec);
4371 if (spec->mixer_nid && !spec->mixer_merge_nid)
4372 spec->mixer_merge_nid = spec->mixer_nid;
4374 if (cfg != &spec->autocfg) {
4375 spec->autocfg = *cfg;
4376 cfg = &spec->autocfg;
4379 if (!spec->main_out_badness)
4380 spec->main_out_badness = &hda_main_out_badness;
4381 if (!spec->extra_out_badness)
4382 spec->extra_out_badness = &hda_extra_out_badness;
4384 fill_all_dac_nids(codec);
4386 if (!cfg->line_outs) {
4387 if (cfg->dig_outs || cfg->dig_in_pin) {
4388 spec->multiout.max_channels = 2;
4389 spec->no_analog = 1;
4392 if (!cfg->num_inputs && !cfg->dig_in_pin)
4393 return 0; /* can't find valid BIOS pin config */
4396 if (!spec->no_primary_hp &&
4397 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4398 cfg->line_outs <= cfg->hp_outs) {
4399 /* use HP as primary out */
4400 cfg->speaker_outs = cfg->line_outs;
4401 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4402 sizeof(cfg->speaker_pins));
4403 cfg->line_outs = cfg->hp_outs;
4404 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4406 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4407 cfg->line_out_type = AUTO_PIN_HP_OUT;
4410 err = parse_output_paths(codec);
4413 err = create_multi_channel_mode(codec);
4416 err = create_multi_out_ctls(codec, cfg);
4419 err = create_hp_out_ctls(codec);
4422 err = create_speaker_out_ctls(codec);
4425 err = create_indep_hp_ctls(codec);
4428 err = create_loopback_mixing_ctl(codec);
4431 err = create_hp_mic(codec);
4434 err = create_input_ctls(codec);
4438 spec->const_channel_count = spec->ext_channel_count;
4439 /* check the multiple speaker and headphone pins */
4440 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
4441 spec->const_channel_count = max(spec->const_channel_count,
4442 cfg->speaker_outs * 2);
4443 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
4444 spec->const_channel_count = max(spec->const_channel_count,
4446 spec->multiout.max_channels = max(spec->ext_channel_count,
4447 spec->const_channel_count);
4449 err = check_auto_mute_availability(codec);
4453 err = check_dyn_adc_switch(codec);
4457 err = check_auto_mic_availability(codec);
4461 /* add stereo mix if available and not enabled yet */
4462 if (!spec->auto_mic && spec->mixer_nid &&
4463 spec->add_stereo_mix_input &&
4464 spec->input_mux.num_items > 1 &&
4465 snd_hda_get_bool_hint(codec, "add_stereo_mix_input") < 0) {
4466 err = parse_capture_source(codec, spec->mixer_nid,
4467 CFG_IDX_MIX, spec->num_all_adcs,
4474 err = create_capture_mixers(codec);
4478 err = parse_mic_boost(codec);
4482 /* create "Headphone Mic Jack Mode" if no input selection is
4483 * available (or user specifies add_jack_modes hint)
4485 if (spec->hp_mic_pin &&
4486 (spec->auto_mic || spec->input_mux.num_items == 1 ||
4487 spec->add_jack_modes)) {
4488 err = create_hp_mic_jack_mode(codec, spec->hp_mic_pin);
4493 if (spec->add_jack_modes) {
4494 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
4495 err = create_out_jack_modes(codec, cfg->line_outs,
4496 cfg->line_out_pins);
4500 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
4501 err = create_out_jack_modes(codec, cfg->hp_outs,
4508 /* mute all aamix input initially */
4509 if (spec->mixer_nid)
4510 mute_all_mixer_nid(codec, spec->mixer_nid);
4513 parse_digital(codec);
4515 if (spec->power_down_unused)
4516 codec->power_filter = snd_hda_gen_path_power_filter;
4518 if (!spec->no_analog && spec->beep_nid) {
4519 err = snd_hda_attach_beep_device(codec, spec->beep_nid);
4526 EXPORT_SYMBOL_GPL(snd_hda_gen_parse_auto_config);
4530 * Build control elements
4533 /* slave controls for virtual master */
4534 static const char * const slave_pfxs[] = {
4535 "Front", "Surround", "Center", "LFE", "Side",
4536 "Headphone", "Speaker", "Mono", "Line Out",
4537 "CLFE", "Bass Speaker", "PCM",
4538 "Speaker Front", "Speaker Surround", "Speaker CLFE", "Speaker Side",
4539 "Headphone Front", "Headphone Surround", "Headphone CLFE",
4540 "Headphone Side", "Headphone+LO", "Speaker+LO",
4544 int snd_hda_gen_build_controls(struct hda_codec *codec)
4546 struct hda_gen_spec *spec = codec->spec;
4549 if (spec->kctls.used) {
4550 err = snd_hda_add_new_ctls(codec, spec->kctls.list);
4555 if (spec->multiout.dig_out_nid) {
4556 err = snd_hda_create_dig_out_ctls(codec,
4557 spec->multiout.dig_out_nid,
4558 spec->multiout.dig_out_nid,
4559 spec->pcm_rec[1].pcm_type);
4562 if (!spec->no_analog) {
4563 err = snd_hda_create_spdif_share_sw(codec,
4567 spec->multiout.share_spdif = 1;
4570 if (spec->dig_in_nid) {
4571 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
4576 /* if we have no master control, let's create it */
4577 if (!spec->no_analog &&
4578 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
4579 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
4580 spec->vmaster_tlv, slave_pfxs,
4585 if (!spec->no_analog &&
4586 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
4587 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
4590 true, &spec->vmaster_mute.sw_kctl);
4593 if (spec->vmaster_mute.hook) {
4594 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4595 spec->vmaster_mute_enum);
4596 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4600 free_kctls(spec); /* no longer needed */
4602 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4608 EXPORT_SYMBOL_GPL(snd_hda_gen_build_controls);
4615 static void call_pcm_playback_hook(struct hda_pcm_stream *hinfo,
4616 struct hda_codec *codec,
4617 struct snd_pcm_substream *substream,
4620 struct hda_gen_spec *spec = codec->spec;
4621 if (spec->pcm_playback_hook)
4622 spec->pcm_playback_hook(hinfo, codec, substream, action);
4625 static void call_pcm_capture_hook(struct hda_pcm_stream *hinfo,
4626 struct hda_codec *codec,
4627 struct snd_pcm_substream *substream,
4630 struct hda_gen_spec *spec = codec->spec;
4631 if (spec->pcm_capture_hook)
4632 spec->pcm_capture_hook(hinfo, codec, substream, action);
4636 * Analog playback callbacks
4638 static int playback_pcm_open(struct hda_pcm_stream *hinfo,
4639 struct hda_codec *codec,
4640 struct snd_pcm_substream *substream)
4642 struct hda_gen_spec *spec = codec->spec;
4645 mutex_lock(&spec->pcm_mutex);
4646 err = snd_hda_multi_out_analog_open(codec,
4647 &spec->multiout, substream,
4650 spec->active_streams |= 1 << STREAM_MULTI_OUT;
4651 call_pcm_playback_hook(hinfo, codec, substream,
4652 HDA_GEN_PCM_ACT_OPEN);
4654 mutex_unlock(&spec->pcm_mutex);
4658 static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4659 struct hda_codec *codec,
4660 unsigned int stream_tag,
4661 unsigned int format,
4662 struct snd_pcm_substream *substream)
4664 struct hda_gen_spec *spec = codec->spec;
4667 err = snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
4668 stream_tag, format, substream);
4670 call_pcm_playback_hook(hinfo, codec, substream,
4671 HDA_GEN_PCM_ACT_PREPARE);
4675 static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
4676 struct hda_codec *codec,
4677 struct snd_pcm_substream *substream)
4679 struct hda_gen_spec *spec = codec->spec;
4682 err = snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
4684 call_pcm_playback_hook(hinfo, codec, substream,
4685 HDA_GEN_PCM_ACT_CLEANUP);
4689 static int playback_pcm_close(struct hda_pcm_stream *hinfo,
4690 struct hda_codec *codec,
4691 struct snd_pcm_substream *substream)
4693 struct hda_gen_spec *spec = codec->spec;
4694 mutex_lock(&spec->pcm_mutex);
4695 spec->active_streams &= ~(1 << STREAM_MULTI_OUT);
4696 call_pcm_playback_hook(hinfo, codec, substream,
4697 HDA_GEN_PCM_ACT_CLOSE);
4698 mutex_unlock(&spec->pcm_mutex);
4702 static int capture_pcm_open(struct hda_pcm_stream *hinfo,
4703 struct hda_codec *codec,
4704 struct snd_pcm_substream *substream)
4706 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_OPEN);
4710 static int capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4711 struct hda_codec *codec,
4712 unsigned int stream_tag,
4713 unsigned int format,
4714 struct snd_pcm_substream *substream)
4716 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
4717 call_pcm_capture_hook(hinfo, codec, substream,
4718 HDA_GEN_PCM_ACT_PREPARE);
4722 static int capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4723 struct hda_codec *codec,
4724 struct snd_pcm_substream *substream)
4726 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
4727 call_pcm_capture_hook(hinfo, codec, substream,
4728 HDA_GEN_PCM_ACT_CLEANUP);
4732 static int capture_pcm_close(struct hda_pcm_stream *hinfo,
4733 struct hda_codec *codec,
4734 struct snd_pcm_substream *substream)
4736 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLOSE);
4740 static int alt_playback_pcm_open(struct hda_pcm_stream *hinfo,
4741 struct hda_codec *codec,
4742 struct snd_pcm_substream *substream)
4744 struct hda_gen_spec *spec = codec->spec;
4747 mutex_lock(&spec->pcm_mutex);
4748 if (!spec->indep_hp_enabled)
4751 spec->active_streams |= 1 << STREAM_INDEP_HP;
4752 call_pcm_playback_hook(hinfo, codec, substream,
4753 HDA_GEN_PCM_ACT_OPEN);
4754 mutex_unlock(&spec->pcm_mutex);
4758 static int alt_playback_pcm_close(struct hda_pcm_stream *hinfo,
4759 struct hda_codec *codec,
4760 struct snd_pcm_substream *substream)
4762 struct hda_gen_spec *spec = codec->spec;
4763 mutex_lock(&spec->pcm_mutex);
4764 spec->active_streams &= ~(1 << STREAM_INDEP_HP);
4765 call_pcm_playback_hook(hinfo, codec, substream,
4766 HDA_GEN_PCM_ACT_CLOSE);
4767 mutex_unlock(&spec->pcm_mutex);
4771 static int alt_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4772 struct hda_codec *codec,
4773 unsigned int stream_tag,
4774 unsigned int format,
4775 struct snd_pcm_substream *substream)
4777 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
4778 call_pcm_playback_hook(hinfo, codec, substream,
4779 HDA_GEN_PCM_ACT_PREPARE);
4783 static int alt_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
4784 struct hda_codec *codec,
4785 struct snd_pcm_substream *substream)
4787 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
4788 call_pcm_playback_hook(hinfo, codec, substream,
4789 HDA_GEN_PCM_ACT_CLEANUP);
4796 static int dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
4797 struct hda_codec *codec,
4798 struct snd_pcm_substream *substream)
4800 struct hda_gen_spec *spec = codec->spec;
4801 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
4804 static int dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4805 struct hda_codec *codec,
4806 unsigned int stream_tag,
4807 unsigned int format,
4808 struct snd_pcm_substream *substream)
4810 struct hda_gen_spec *spec = codec->spec;
4811 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
4812 stream_tag, format, substream);
4815 static int dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
4816 struct hda_codec *codec,
4817 struct snd_pcm_substream *substream)
4819 struct hda_gen_spec *spec = codec->spec;
4820 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
4823 static int dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
4824 struct hda_codec *codec,
4825 struct snd_pcm_substream *substream)
4827 struct hda_gen_spec *spec = codec->spec;
4828 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
4834 #define alt_capture_pcm_open capture_pcm_open
4835 #define alt_capture_pcm_close capture_pcm_close
4837 static int alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4838 struct hda_codec *codec,
4839 unsigned int stream_tag,
4840 unsigned int format,
4841 struct snd_pcm_substream *substream)
4843 struct hda_gen_spec *spec = codec->spec;
4845 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
4846 stream_tag, 0, format);
4847 call_pcm_capture_hook(hinfo, codec, substream,
4848 HDA_GEN_PCM_ACT_PREPARE);
4852 static int alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4853 struct hda_codec *codec,
4854 struct snd_pcm_substream *substream)
4856 struct hda_gen_spec *spec = codec->spec;
4858 snd_hda_codec_cleanup_stream(codec,
4859 spec->adc_nids[substream->number + 1]);
4860 call_pcm_capture_hook(hinfo, codec, substream,
4861 HDA_GEN_PCM_ACT_CLEANUP);
4867 static const struct hda_pcm_stream pcm_analog_playback = {
4871 /* NID is set in build_pcms */
4873 .open = playback_pcm_open,
4874 .close = playback_pcm_close,
4875 .prepare = playback_pcm_prepare,
4876 .cleanup = playback_pcm_cleanup
4880 static const struct hda_pcm_stream pcm_analog_capture = {
4884 /* NID is set in build_pcms */
4886 .open = capture_pcm_open,
4887 .close = capture_pcm_close,
4888 .prepare = capture_pcm_prepare,
4889 .cleanup = capture_pcm_cleanup
4893 static const struct hda_pcm_stream pcm_analog_alt_playback = {
4897 /* NID is set in build_pcms */
4899 .open = alt_playback_pcm_open,
4900 .close = alt_playback_pcm_close,
4901 .prepare = alt_playback_pcm_prepare,
4902 .cleanup = alt_playback_pcm_cleanup
4906 static const struct hda_pcm_stream pcm_analog_alt_capture = {
4907 .substreams = 2, /* can be overridden */
4910 /* NID is set in build_pcms */
4912 .open = alt_capture_pcm_open,
4913 .close = alt_capture_pcm_close,
4914 .prepare = alt_capture_pcm_prepare,
4915 .cleanup = alt_capture_pcm_cleanup
4919 static const struct hda_pcm_stream pcm_digital_playback = {
4923 /* NID is set in build_pcms */
4925 .open = dig_playback_pcm_open,
4926 .close = dig_playback_pcm_close,
4927 .prepare = dig_playback_pcm_prepare,
4928 .cleanup = dig_playback_pcm_cleanup
4932 static const struct hda_pcm_stream pcm_digital_capture = {
4936 /* NID is set in build_pcms */
4939 /* Used by build_pcms to flag that a PCM has no playback stream */
4940 static const struct hda_pcm_stream pcm_null_stream = {
4947 * dynamic changing ADC PCM streams
4949 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
4951 struct hda_gen_spec *spec = codec->spec;
4952 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
4954 if (spec->cur_adc && spec->cur_adc != new_adc) {
4955 /* stream is running, let's swap the current ADC */
4956 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
4957 spec->cur_adc = new_adc;
4958 snd_hda_codec_setup_stream(codec, new_adc,
4959 spec->cur_adc_stream_tag, 0,
4960 spec->cur_adc_format);
4966 /* analog capture with dynamic dual-adc changes */
4967 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4968 struct hda_codec *codec,
4969 unsigned int stream_tag,
4970 unsigned int format,
4971 struct snd_pcm_substream *substream)
4973 struct hda_gen_spec *spec = codec->spec;
4974 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
4975 spec->cur_adc_stream_tag = stream_tag;
4976 spec->cur_adc_format = format;
4977 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
4981 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4982 struct hda_codec *codec,
4983 struct snd_pcm_substream *substream)
4985 struct hda_gen_spec *spec = codec->spec;
4986 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
4991 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
4995 .nid = 0, /* fill later */
4997 .prepare = dyn_adc_capture_pcm_prepare,
4998 .cleanup = dyn_adc_capture_pcm_cleanup
5002 static void fill_pcm_stream_name(char *str, size_t len, const char *sfx,
5003 const char *chip_name)
5009 strlcpy(str, chip_name, len);
5011 /* drop non-alnum chars after a space */
5012 for (p = strchr(str, ' '); p; p = strchr(p + 1, ' ')) {
5013 if (!isalnum(p[1])) {
5018 strlcat(str, sfx, len);
5021 /* build PCM streams based on the parsed results */
5022 int snd_hda_gen_build_pcms(struct hda_codec *codec)
5024 struct hda_gen_spec *spec = codec->spec;
5025 struct hda_pcm *info = spec->pcm_rec;
5026 const struct hda_pcm_stream *p;
5027 bool have_multi_adcs;
5029 codec->num_pcms = 1;
5030 codec->pcm_info = info;
5032 if (spec->no_analog)
5035 fill_pcm_stream_name(spec->stream_name_analog,
5036 sizeof(spec->stream_name_analog),
5037 " Analog", codec->chip_name);
5038 info->name = spec->stream_name_analog;
5040 if (spec->multiout.num_dacs > 0) {
5041 p = spec->stream_analog_playback;
5043 p = &pcm_analog_playback;
5044 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
5045 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
5046 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
5047 spec->multiout.max_channels;
5048 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
5049 spec->autocfg.line_outs == 2)
5050 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
5053 if (spec->num_adc_nids) {
5054 p = spec->stream_analog_capture;
5056 if (spec->dyn_adc_switch)
5057 p = &dyn_adc_pcm_analog_capture;
5059 p = &pcm_analog_capture;
5061 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
5062 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
5066 /* SPDIF for stream index #1 */
5067 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
5068 fill_pcm_stream_name(spec->stream_name_digital,
5069 sizeof(spec->stream_name_digital),
5070 " Digital", codec->chip_name);
5071 codec->num_pcms = 2;
5072 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
5073 info = spec->pcm_rec + 1;
5074 info->name = spec->stream_name_digital;
5075 if (spec->dig_out_type)
5076 info->pcm_type = spec->dig_out_type;
5078 info->pcm_type = HDA_PCM_TYPE_SPDIF;
5079 if (spec->multiout.dig_out_nid) {
5080 p = spec->stream_digital_playback;
5082 p = &pcm_digital_playback;
5083 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
5084 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
5086 if (spec->dig_in_nid) {
5087 p = spec->stream_digital_capture;
5089 p = &pcm_digital_capture;
5090 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
5091 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
5095 if (spec->no_analog)
5098 /* If the use of more than one ADC is requested for the current
5099 * model, configure a second analog capture-only PCM.
5101 have_multi_adcs = (spec->num_adc_nids > 1) &&
5102 !spec->dyn_adc_switch && !spec->auto_mic;
5103 /* Additional Analaog capture for index #2 */
5104 if (spec->alt_dac_nid || have_multi_adcs) {
5105 fill_pcm_stream_name(spec->stream_name_alt_analog,
5106 sizeof(spec->stream_name_alt_analog),
5107 " Alt Analog", codec->chip_name);
5108 codec->num_pcms = 3;
5109 info = spec->pcm_rec + 2;
5110 info->name = spec->stream_name_alt_analog;
5111 if (spec->alt_dac_nid) {
5112 p = spec->stream_analog_alt_playback;
5114 p = &pcm_analog_alt_playback;
5115 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
5116 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
5119 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
5121 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
5123 if (have_multi_adcs) {
5124 p = spec->stream_analog_alt_capture;
5126 p = &pcm_analog_alt_capture;
5127 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
5128 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
5130 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
5131 spec->num_adc_nids - 1;
5133 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
5135 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
5141 EXPORT_SYMBOL_GPL(snd_hda_gen_build_pcms);
5145 * Standard auto-parser initializations
5148 /* configure the given path as a proper output */
5149 static void set_output_and_unmute(struct hda_codec *codec, int path_idx)
5151 struct nid_path *path;
5154 path = snd_hda_get_path_from_idx(codec, path_idx);
5155 if (!path || !path->depth)
5157 pin = path->path[path->depth - 1];
5158 restore_pin_ctl(codec, pin);
5159 snd_hda_activate_path(codec, path, path->active,
5160 aamix_default(codec->spec));
5161 set_pin_eapd(codec, pin, path->active);
5164 /* initialize primary output paths */
5165 static void init_multi_out(struct hda_codec *codec)
5167 struct hda_gen_spec *spec = codec->spec;
5170 for (i = 0; i < spec->autocfg.line_outs; i++)
5171 set_output_and_unmute(codec, spec->out_paths[i]);
5175 static void __init_extra_out(struct hda_codec *codec, int num_outs, int *paths)
5179 for (i = 0; i < num_outs; i++)
5180 set_output_and_unmute(codec, paths[i]);
5183 /* initialize hp and speaker paths */
5184 static void init_extra_out(struct hda_codec *codec)
5186 struct hda_gen_spec *spec = codec->spec;
5188 if (spec->autocfg.line_out_type != AUTO_PIN_HP_OUT)
5189 __init_extra_out(codec, spec->autocfg.hp_outs, spec->hp_paths);
5190 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT)
5191 __init_extra_out(codec, spec->autocfg.speaker_outs,
5192 spec->speaker_paths);
5195 /* initialize multi-io paths */
5196 static void init_multi_io(struct hda_codec *codec)
5198 struct hda_gen_spec *spec = codec->spec;
5201 for (i = 0; i < spec->multi_ios; i++) {
5202 hda_nid_t pin = spec->multi_io[i].pin;
5203 struct nid_path *path;
5204 path = get_multiio_path(codec, i);
5207 if (!spec->multi_io[i].ctl_in)
5208 spec->multi_io[i].ctl_in =
5209 snd_hda_codec_get_pin_target(codec, pin);
5210 snd_hda_activate_path(codec, path, path->active,
5211 aamix_default(spec));
5215 static void init_aamix_paths(struct hda_codec *codec)
5217 struct hda_gen_spec *spec = codec->spec;
5219 if (!spec->have_aamix_ctl)
5221 update_aamix_paths(codec, spec->aamix_mode, spec->out_paths[0],
5222 spec->aamix_out_paths[0],
5223 spec->autocfg.line_out_type);
5224 update_aamix_paths(codec, spec->aamix_mode, spec->hp_paths[0],
5225 spec->aamix_out_paths[1],
5227 update_aamix_paths(codec, spec->aamix_mode, spec->speaker_paths[0],
5228 spec->aamix_out_paths[2],
5229 AUTO_PIN_SPEAKER_OUT);
5232 /* set up input pins and loopback paths */
5233 static void init_analog_input(struct hda_codec *codec)
5235 struct hda_gen_spec *spec = codec->spec;
5236 struct auto_pin_cfg *cfg = &spec->autocfg;
5239 for (i = 0; i < cfg->num_inputs; i++) {
5240 hda_nid_t nid = cfg->inputs[i].pin;
5241 if (is_input_pin(codec, nid))
5242 restore_pin_ctl(codec, nid);
5244 /* init loopback inputs */
5245 if (spec->mixer_nid) {
5246 resume_path_from_idx(codec, spec->loopback_paths[i]);
5247 resume_path_from_idx(codec, spec->loopback_merge_path);
5252 /* initialize ADC paths */
5253 static void init_input_src(struct hda_codec *codec)
5255 struct hda_gen_spec *spec = codec->spec;
5256 struct hda_input_mux *imux = &spec->input_mux;
5257 struct nid_path *path;
5260 if (spec->dyn_adc_switch)
5263 nums = spec->num_adc_nids;
5265 for (c = 0; c < nums; c++) {
5266 for (i = 0; i < imux->num_items; i++) {
5267 path = get_input_path(codec, c, i);
5269 bool active = path->active;
5270 if (i == spec->cur_mux[c])
5272 snd_hda_activate_path(codec, path, active, false);
5276 update_hp_mic(codec, c, true);
5279 if (spec->cap_sync_hook)
5280 spec->cap_sync_hook(codec, NULL, NULL);
5283 /* set right pin controls for digital I/O */
5284 static void init_digital(struct hda_codec *codec)
5286 struct hda_gen_spec *spec = codec->spec;
5290 for (i = 0; i < spec->autocfg.dig_outs; i++)
5291 set_output_and_unmute(codec, spec->digout_paths[i]);
5292 pin = spec->autocfg.dig_in_pin;
5294 restore_pin_ctl(codec, pin);
5295 resume_path_from_idx(codec, spec->digin_path);
5299 /* clear unsol-event tags on unused pins; Conexant codecs seem to leave
5300 * invalid unsol tags by some reason
5302 static void clear_unsol_on_unused_pins(struct hda_codec *codec)
5306 for (i = 0; i < codec->init_pins.used; i++) {
5307 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
5308 hda_nid_t nid = pin->nid;
5309 if (is_jack_detectable(codec, nid) &&
5310 !snd_hda_jack_tbl_get(codec, nid))
5311 snd_hda_codec_update_cache(codec, nid, 0,
5312 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
5317 * initialize the generic spec;
5318 * this can be put as patch_ops.init function
5320 int snd_hda_gen_init(struct hda_codec *codec)
5322 struct hda_gen_spec *spec = codec->spec;
5324 if (spec->init_hook)
5325 spec->init_hook(codec);
5327 snd_hda_apply_verbs(codec);
5329 codec->cached_write = 1;
5331 init_multi_out(codec);
5332 init_extra_out(codec);
5333 init_multi_io(codec);
5334 init_aamix_paths(codec);
5335 init_analog_input(codec);
5336 init_input_src(codec);
5337 init_digital(codec);
5339 clear_unsol_on_unused_pins(codec);
5341 /* call init functions of standard auto-mute helpers */
5342 update_automute_all(codec);
5344 snd_hda_codec_flush_cache(codec);
5346 if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook)
5347 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
5349 hda_call_check_power_status(codec, 0x01);
5352 EXPORT_SYMBOL_GPL(snd_hda_gen_init);
5355 * free the generic spec;
5356 * this can be put as patch_ops.free function
5358 void snd_hda_gen_free(struct hda_codec *codec)
5360 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
5361 snd_hda_gen_spec_free(codec->spec);
5365 EXPORT_SYMBOL_GPL(snd_hda_gen_free);
5369 * check the loopback power save state;
5370 * this can be put as patch_ops.check_power_status function
5372 int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid)
5374 struct hda_gen_spec *spec = codec->spec;
5375 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
5377 EXPORT_SYMBOL_GPL(snd_hda_gen_check_power_status);
5382 * the generic codec support
5385 static const struct hda_codec_ops generic_patch_ops = {
5386 .build_controls = snd_hda_gen_build_controls,
5387 .build_pcms = snd_hda_gen_build_pcms,
5388 .init = snd_hda_gen_init,
5389 .free = snd_hda_gen_free,
5390 .unsol_event = snd_hda_jack_unsol_event,
5392 .check_power_status = snd_hda_gen_check_power_status,
5396 int snd_hda_parse_generic_codec(struct hda_codec *codec)
5398 struct hda_gen_spec *spec;
5401 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5404 snd_hda_gen_spec_init(spec);
5407 err = snd_hda_parse_pin_defcfg(codec, &spec->autocfg, NULL, 0);
5411 err = snd_hda_gen_parse_auto_config(codec, &spec->autocfg);
5415 codec->patch_ops = generic_patch_ops;
5419 snd_hda_gen_free(codec);
5422 EXPORT_SYMBOL_GPL(snd_hda_parse_generic_codec);
5424 MODULE_LICENSE("GPL");
5425 MODULE_DESCRIPTION("Generic HD-audio codec parser");