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/ctype.h>
28 #include <linux/string.h>
29 #include <linux/bitops.h>
30 #include <sound/core.h>
31 #include <sound/jack.h>
32 #include "hda_codec.h"
33 #include "hda_local.h"
34 #include "hda_auto_parser.h"
36 #include "hda_generic.h"
39 /* initialize hda_gen_spec struct */
40 int snd_hda_gen_spec_init(struct hda_gen_spec *spec)
42 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
43 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
44 mutex_init(&spec->pcm_mutex);
47 EXPORT_SYMBOL_HDA(snd_hda_gen_spec_init);
49 struct snd_kcontrol_new *
50 snd_hda_gen_add_kctl(struct hda_gen_spec *spec, const char *name,
51 const struct snd_kcontrol_new *temp)
53 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
58 knew->name = kstrdup(name, GFP_KERNEL);
60 knew->name = kstrdup(knew->name, GFP_KERNEL);
65 EXPORT_SYMBOL_HDA(snd_hda_gen_add_kctl);
67 static void free_kctls(struct hda_gen_spec *spec)
69 if (spec->kctls.list) {
70 struct snd_kcontrol_new *kctl = spec->kctls.list;
72 for (i = 0; i < spec->kctls.used; i++)
75 snd_array_free(&spec->kctls);
78 void snd_hda_gen_spec_free(struct hda_gen_spec *spec)
83 snd_array_free(&spec->paths);
85 EXPORT_SYMBOL_HDA(snd_hda_gen_spec_free);
90 static void parse_user_hints(struct hda_codec *codec)
92 struct hda_gen_spec *spec = codec->spec;
95 val = snd_hda_get_bool_hint(codec, "jack_detect");
97 codec->no_jack_detect = !val;
98 val = snd_hda_get_bool_hint(codec, "inv_jack_detect");
100 codec->inv_jack_detect = !!val;
101 val = snd_hda_get_bool_hint(codec, "trigger_sense");
103 codec->no_trigger_sense = !val;
104 val = snd_hda_get_bool_hint(codec, "inv_eapd");
106 codec->inv_eapd = !!val;
107 val = snd_hda_get_bool_hint(codec, "pcm_format_first");
109 codec->pcm_format_first = !!val;
110 val = snd_hda_get_bool_hint(codec, "sticky_stream");
112 codec->no_sticky_stream = !val;
113 val = snd_hda_get_bool_hint(codec, "spdif_status_reset");
115 codec->spdif_status_reset = !!val;
116 val = snd_hda_get_bool_hint(codec, "pin_amp_workaround");
118 codec->pin_amp_workaround = !!val;
119 val = snd_hda_get_bool_hint(codec, "single_adc_amp");
121 codec->single_adc_amp = !!val;
123 val = snd_hda_get_bool_hint(codec, "auto_mute");
125 spec->suppress_auto_mute = !val;
126 val = snd_hda_get_bool_hint(codec, "auto_mic");
128 spec->suppress_auto_mic = !val;
129 val = snd_hda_get_bool_hint(codec, "line_in_auto_switch");
131 spec->line_in_auto_switch = !!val;
132 val = snd_hda_get_bool_hint(codec, "need_dac_fix");
134 spec->need_dac_fix = !!val;
135 val = snd_hda_get_bool_hint(codec, "primary_hp");
137 spec->no_primary_hp = !val;
138 val = snd_hda_get_bool_hint(codec, "multi_cap_vol");
140 spec->multi_cap_vol = !!val;
141 val = snd_hda_get_bool_hint(codec, "inv_dmic_split");
143 spec->inv_dmic_split = !!val;
144 val = snd_hda_get_bool_hint(codec, "indep_hp");
146 spec->indep_hp = !!val;
147 val = snd_hda_get_bool_hint(codec, "add_stereo_mix_input");
149 spec->add_stereo_mix_input = !!val;
150 val = snd_hda_get_bool_hint(codec, "add_out_jack_modes");
152 spec->add_out_jack_modes = !!val;
153 val = snd_hda_get_bool_hint(codec, "add_in_jack_modes");
155 spec->add_in_jack_modes = !!val;
157 if (!snd_hda_get_int_hint(codec, "mixer_nid", &val))
158 spec->mixer_nid = val;
162 * pin control value accesses
165 #define update_pin_ctl(codec, pin, val) \
166 snd_hda_codec_update_cache(codec, pin, 0, \
167 AC_VERB_SET_PIN_WIDGET_CONTROL, val)
169 /* restore the pinctl based on the cached value */
170 static inline void restore_pin_ctl(struct hda_codec *codec, hda_nid_t pin)
172 update_pin_ctl(codec, pin, snd_hda_codec_get_pin_target(codec, pin));
175 /* set the pinctl target value and write it if requested */
176 static void set_pin_target(struct hda_codec *codec, hda_nid_t pin,
177 unsigned int val, bool do_write)
181 val = snd_hda_correct_pin_ctl(codec, pin, val);
182 snd_hda_codec_set_pin_target(codec, pin, val);
184 update_pin_ctl(codec, pin, val);
187 /* set pinctl target values for all given pins */
188 static void set_pin_targets(struct hda_codec *codec, int num_pins,
189 hda_nid_t *pins, unsigned int val)
192 for (i = 0; i < num_pins; i++)
193 set_pin_target(codec, pins[i], val, false);
200 /* return the position of NID in the list, or -1 if not found */
201 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
204 for (i = 0; i < nums; i++)
210 /* return true if the given NID is contained in the path */
211 static bool is_nid_contained(struct nid_path *path, hda_nid_t nid)
213 return find_idx_in_nid_list(nid, path->path, path->depth) >= 0;
216 static struct nid_path *get_nid_path(struct hda_codec *codec,
217 hda_nid_t from_nid, hda_nid_t to_nid,
220 struct hda_gen_spec *spec = codec->spec;
223 for (i = 0; i < spec->paths.used; i++) {
224 struct nid_path *path = snd_array_elem(&spec->paths, i);
225 if (path->depth <= 0)
227 if ((!from_nid || path->path[0] == from_nid) &&
228 (!to_nid || path->path[path->depth - 1] == to_nid)) {
230 (anchor_nid > 0 && is_nid_contained(path, anchor_nid)) ||
231 (anchor_nid < 0 && !is_nid_contained(path, anchor_nid)))
238 /* get the path between the given NIDs;
239 * passing 0 to either @pin or @dac behaves as a wildcard
241 struct nid_path *snd_hda_get_nid_path(struct hda_codec *codec,
242 hda_nid_t from_nid, hda_nid_t to_nid)
244 return get_nid_path(codec, from_nid, to_nid, 0);
246 EXPORT_SYMBOL_HDA(snd_hda_get_nid_path);
248 /* get the index number corresponding to the path instance;
249 * the index starts from 1, for easier checking the invalid value
251 int snd_hda_get_path_idx(struct hda_codec *codec, struct nid_path *path)
253 struct hda_gen_spec *spec = codec->spec;
254 struct nid_path *array = spec->paths.list;
257 if (!spec->paths.used)
260 if (idx < 0 || idx >= spec->paths.used)
265 /* get the path instance corresponding to the given index number */
266 struct nid_path *snd_hda_get_path_from_idx(struct hda_codec *codec, int idx)
268 struct hda_gen_spec *spec = codec->spec;
270 if (idx <= 0 || idx > spec->paths.used)
272 return snd_array_elem(&spec->paths, idx - 1);
275 /* check whether the given DAC is already found in any existing paths */
276 static bool is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
278 struct hda_gen_spec *spec = codec->spec;
281 for (i = 0; i < spec->paths.used; i++) {
282 struct nid_path *path = snd_array_elem(&spec->paths, i);
283 if (path->path[0] == nid)
289 /* check whether the given two widgets can be connected */
290 static bool is_reachable_path(struct hda_codec *codec,
291 hda_nid_t from_nid, hda_nid_t to_nid)
293 if (!from_nid || !to_nid)
295 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
298 /* nid, dir and idx */
299 #define AMP_VAL_COMPARE_MASK (0xffff | (1U << 18) | (0x0f << 19))
301 /* check whether the given ctl is already assigned in any path elements */
302 static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
304 struct hda_gen_spec *spec = codec->spec;
307 val &= AMP_VAL_COMPARE_MASK;
308 for (i = 0; i < spec->paths.used; i++) {
309 struct nid_path *path = snd_array_elem(&spec->paths, i);
310 if ((path->ctls[type] & AMP_VAL_COMPARE_MASK) == val)
316 /* check whether a control with the given (nid, dir, idx) was assigned */
317 static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
318 int dir, int idx, int type)
320 unsigned int val = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir);
321 return is_ctl_used(codec, val, type);
324 static void print_nid_path(const char *pfx, struct nid_path *path)
331 for (i = 0; i < path->depth; i++) {
333 sprintf(tmp, ":%02x", path->path[i]);
334 strlcat(buf, tmp, sizeof(buf));
336 snd_printdd("%s path: depth=%d %s\n", pfx, path->depth, buf);
339 /* called recursively */
340 static bool __parse_nid_path(struct hda_codec *codec,
341 hda_nid_t from_nid, hda_nid_t to_nid,
342 int anchor_nid, struct nid_path *path,
345 const hda_nid_t *conn;
348 if (to_nid == anchor_nid)
349 anchor_nid = 0; /* anchor passed */
350 else if (to_nid == (hda_nid_t)(-anchor_nid))
351 return false; /* hit the exclusive nid */
353 nums = snd_hda_get_conn_list(codec, to_nid, &conn);
354 for (i = 0; i < nums; i++) {
355 if (conn[i] != from_nid) {
356 /* special case: when from_nid is 0,
357 * try to find an empty DAC
360 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
361 is_dac_already_used(codec, conn[i]))
364 /* anchor is not requested or already passed? */
368 if (depth >= MAX_NID_PATH_DEPTH)
370 for (i = 0; i < nums; i++) {
372 type = get_wcaps_type(get_wcaps(codec, conn[i]));
373 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
376 if (__parse_nid_path(codec, from_nid, conn[i],
377 anchor_nid, path, depth + 1))
383 path->path[path->depth] = conn[i];
384 path->idx[path->depth + 1] = i;
385 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
386 path->multi[path->depth + 1] = 1;
391 /* parse the widget path from the given nid to the target nid;
392 * when @from_nid is 0, try to find an empty DAC;
393 * when @anchor_nid is set to a positive value, only paths through the widget
394 * with the given value are evaluated.
395 * when @anchor_nid is set to a negative value, paths through the widget
396 * with the negative of given value are excluded, only other paths are chosen.
397 * when @anchor_nid is zero, no special handling about path selection.
399 bool snd_hda_parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
400 hda_nid_t to_nid, int anchor_nid,
401 struct nid_path *path)
403 if (__parse_nid_path(codec, from_nid, to_nid, anchor_nid, path, 1)) {
404 path->path[path->depth] = to_nid;
410 EXPORT_SYMBOL_HDA(snd_hda_parse_nid_path);
413 * parse the path between the given NIDs and add to the path list.
414 * if no valid path is found, return NULL
417 snd_hda_add_new_path(struct hda_codec *codec, hda_nid_t from_nid,
418 hda_nid_t to_nid, int anchor_nid)
420 struct hda_gen_spec *spec = codec->spec;
421 struct nid_path *path;
423 if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid))
426 /* check whether the path has been already added */
427 path = get_nid_path(codec, from_nid, to_nid, anchor_nid);
431 path = snd_array_new(&spec->paths);
434 memset(path, 0, sizeof(*path));
435 if (snd_hda_parse_nid_path(codec, from_nid, to_nid, anchor_nid, path))
441 EXPORT_SYMBOL_HDA(snd_hda_add_new_path);
443 /* clear the given path as invalid so that it won't be picked up later */
444 static void invalidate_nid_path(struct hda_codec *codec, int idx)
446 struct nid_path *path = snd_hda_get_path_from_idx(codec, idx);
449 memset(path, 0, sizeof(*path));
452 /* look for an empty DAC slot */
453 static hda_nid_t look_for_dac(struct hda_codec *codec, hda_nid_t pin,
456 struct hda_gen_spec *spec = codec->spec;
460 for (i = 0; i < spec->num_all_dacs; i++) {
461 hda_nid_t nid = spec->all_dacs[i];
462 if (!nid || is_dac_already_used(codec, nid))
464 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
465 if (is_digital != cap_digital)
467 if (is_reachable_path(codec, nid, pin))
473 /* replace the channels in the composed amp value with the given number */
474 static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
476 val &= ~(0x3U << 16);
481 /* check whether the widget has the given amp capability for the direction */
482 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
483 int dir, unsigned int bits)
487 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
488 if (query_amp_caps(codec, nid, dir) & bits)
493 static bool same_amp_caps(struct hda_codec *codec, hda_nid_t nid1,
494 hda_nid_t nid2, int dir)
496 if (!(get_wcaps(codec, nid1) & (1 << (dir + 1))))
497 return !(get_wcaps(codec, nid2) & (1 << (dir + 1)));
498 return (query_amp_caps(codec, nid1, dir) ==
499 query_amp_caps(codec, nid2, dir));
502 #define nid_has_mute(codec, nid, dir) \
503 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
504 #define nid_has_volume(codec, nid, dir) \
505 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
507 /* look for a widget suitable for assigning a mute switch in the path */
508 static hda_nid_t look_for_out_mute_nid(struct hda_codec *codec,
509 struct nid_path *path)
513 for (i = path->depth - 1; i >= 0; i--) {
514 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
515 return path->path[i];
516 if (i != path->depth - 1 && i != 0 &&
517 nid_has_mute(codec, path->path[i], HDA_INPUT))
518 return path->path[i];
523 /* look for a widget suitable for assigning a volume ctl in the path */
524 static hda_nid_t look_for_out_vol_nid(struct hda_codec *codec,
525 struct nid_path *path)
529 for (i = path->depth - 1; i >= 0; i--) {
530 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
531 return path->path[i];
537 * path activation / deactivation
540 /* can have the amp-in capability? */
541 static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
543 hda_nid_t nid = path->path[idx];
544 unsigned int caps = get_wcaps(codec, nid);
545 unsigned int type = get_wcaps_type(caps);
547 if (!(caps & AC_WCAP_IN_AMP))
549 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
554 /* can have the amp-out capability? */
555 static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
557 hda_nid_t nid = path->path[idx];
558 unsigned int caps = get_wcaps(codec, nid);
559 unsigned int type = get_wcaps_type(caps);
561 if (!(caps & AC_WCAP_OUT_AMP))
563 if (type == AC_WID_PIN && !idx) /* only for output pins */
568 /* check whether the given (nid,dir,idx) is active */
569 static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
570 unsigned int idx, unsigned int dir)
572 struct hda_gen_spec *spec = codec->spec;
575 for (n = 0; n < spec->paths.used; n++) {
576 struct nid_path *path = snd_array_elem(&spec->paths, n);
579 for (i = 0; i < path->depth; i++) {
580 if (path->path[i] == nid) {
581 if (dir == HDA_OUTPUT || path->idx[i] == idx)
590 /* get the default amp value for the target state */
591 static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
592 int dir, unsigned int caps, bool enable)
594 unsigned int val = 0;
596 if (caps & AC_AMPCAP_NUM_STEPS) {
599 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
601 if (caps & AC_AMPCAP_MUTE) {
608 /* initialize the amp value (only at the first time) */
609 static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
611 unsigned int caps = query_amp_caps(codec, nid, dir);
612 int val = get_amp_val_to_activate(codec, nid, dir, caps, false);
613 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
616 /* calculate amp value mask we can modify;
617 * if the given amp is controlled by mixers, don't touch it
619 static unsigned int get_amp_mask_to_modify(struct hda_codec *codec,
620 hda_nid_t nid, int dir, int idx,
623 unsigned int mask = 0xff;
625 if (caps & AC_AMPCAP_MUTE) {
626 if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_MUTE_CTL))
629 if (caps & AC_AMPCAP_NUM_STEPS) {
630 if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
631 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
637 static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
638 int idx, int idx_to_check, bool enable)
641 unsigned int mask, val;
643 if (!enable && is_active_nid(codec, nid, dir, idx))
646 caps = query_amp_caps(codec, nid, dir);
647 val = get_amp_val_to_activate(codec, nid, dir, caps, enable);
648 mask = get_amp_mask_to_modify(codec, nid, dir, idx_to_check, caps);
653 snd_hda_codec_amp_stereo(codec, nid, dir, idx, mask, val);
656 static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
659 hda_nid_t nid = path->path[i];
660 init_amp(codec, nid, HDA_OUTPUT, 0);
661 activate_amp(codec, nid, HDA_OUTPUT, 0, 0, enable);
664 static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
665 int i, bool enable, bool add_aamix)
667 struct hda_gen_spec *spec = codec->spec;
668 const hda_nid_t *conn;
671 hda_nid_t nid = path->path[i];
673 nums = snd_hda_get_conn_list(codec, nid, &conn);
674 type = get_wcaps_type(get_wcaps(codec, nid));
675 if (type == AC_WID_PIN ||
676 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
682 for (n = 0; n < nums; n++)
683 init_amp(codec, nid, HDA_INPUT, n);
685 /* here is a little bit tricky in comparison with activate_amp_out();
686 * when aa-mixer is available, we need to enable the path as well
688 for (n = 0; n < nums; n++) {
689 if (n != idx && (!add_aamix || conn[n] != spec->mixer_nid))
691 activate_amp(codec, nid, HDA_INPUT, n, idx, enable);
695 /* activate or deactivate the given path
696 * if @add_aamix is set, enable the input from aa-mix NID as well (if any)
698 void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
699 bool enable, bool add_aamix)
704 path->active = false;
706 for (i = path->depth - 1; i >= 0; i--) {
707 if (enable && path->multi[i])
708 snd_hda_codec_write_cache(codec, path->path[i], 0,
709 AC_VERB_SET_CONNECT_SEL,
711 if (has_amp_in(codec, path, i))
712 activate_amp_in(codec, path, i, enable, add_aamix);
713 if (has_amp_out(codec, path, i))
714 activate_amp_out(codec, path, i, enable);
720 EXPORT_SYMBOL_HDA(snd_hda_activate_path);
722 /* turn on/off EAPD on the given pin */
723 static void set_pin_eapd(struct hda_codec *codec, hda_nid_t pin, bool enable)
725 struct hda_gen_spec *spec = codec->spec;
726 if (spec->own_eapd_ctl ||
727 !(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD))
731 snd_hda_codec_update_cache(codec, pin, 0,
732 AC_VERB_SET_EAPD_BTLENABLE,
733 enable ? 0x02 : 0x00);
738 * Helper functions for creating mixer ctl elements
746 static const struct snd_kcontrol_new control_templates[] = {
747 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
748 HDA_CODEC_MUTE(NULL, 0, 0, 0),
749 HDA_BIND_MUTE(NULL, 0, 0, 0),
752 /* add dynamic controls from template */
753 static struct snd_kcontrol_new *
754 add_control(struct hda_gen_spec *spec, int type, const char *name,
755 int cidx, unsigned long val)
757 struct snd_kcontrol_new *knew;
759 knew = snd_hda_gen_add_kctl(spec, name, &control_templates[type]);
763 if (get_amp_nid_(val))
764 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
765 knew->private_value = val;
769 static int add_control_with_pfx(struct hda_gen_spec *spec, int type,
770 const char *pfx, const char *dir,
771 const char *sfx, int cidx, unsigned long val)
774 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
775 if (!add_control(spec, type, name, cidx, val))
780 #define add_pb_vol_ctrl(spec, type, pfx, val) \
781 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
782 #define add_pb_sw_ctrl(spec, type, pfx, val) \
783 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
784 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
785 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
786 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
787 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
789 static int add_vol_ctl(struct hda_codec *codec, const char *pfx, int cidx,
790 unsigned int chs, struct nid_path *path)
795 val = path->ctls[NID_PATH_VOL_CTL];
798 val = amp_val_replace_channels(val, chs);
799 return __add_pb_vol_ctrl(codec->spec, HDA_CTL_WIDGET_VOL, pfx, cidx, val);
802 /* return the channel bits suitable for the given path->ctls[] */
803 static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
806 int chs = 1; /* mono (left only) */
808 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
809 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
810 chs = 3; /* stereo */
815 static int add_stereo_vol(struct hda_codec *codec, const char *pfx, int cidx,
816 struct nid_path *path)
818 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
819 return add_vol_ctl(codec, pfx, cidx, chs, path);
822 /* create a mute-switch for the given mixer widget;
823 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
825 static int add_sw_ctl(struct hda_codec *codec, const char *pfx, int cidx,
826 unsigned int chs, struct nid_path *path)
829 int type = HDA_CTL_WIDGET_MUTE;
833 val = path->ctls[NID_PATH_MUTE_CTL];
836 val = amp_val_replace_channels(val, chs);
837 if (get_amp_direction_(val) == HDA_INPUT) {
838 hda_nid_t nid = get_amp_nid_(val);
839 int nums = snd_hda_get_num_conns(codec, nid);
841 type = HDA_CTL_BIND_MUTE;
845 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
848 static int add_stereo_sw(struct hda_codec *codec, const char *pfx,
849 int cidx, struct nid_path *path)
851 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
852 return add_sw_ctl(codec, pfx, cidx, chs, path);
855 /* any ctl assigned to the path with the given index? */
856 static bool path_has_mixer(struct hda_codec *codec, int path_idx, int ctl_type)
858 struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
859 return path && path->ctls[ctl_type];
862 static const char * const channel_name[4] = {
863 "Front", "Surround", "CLFE", "Side"
866 /* give some appropriate ctl name prefix for the given line out channel */
867 static const char *get_line_out_pfx(struct hda_codec *codec, int ch,
868 int *index, int ctl_type)
870 struct hda_gen_spec *spec = codec->spec;
871 struct auto_pin_cfg *cfg = &spec->autocfg;
874 if (cfg->line_outs == 1 && !spec->multi_ios &&
875 !cfg->hp_outs && !cfg->speaker_outs)
876 return spec->vmaster_mute.hook ? "PCM" : "Master";
878 /* if there is really a single DAC used in the whole output paths,
879 * use it master (or "PCM" if a vmaster hook is present)
881 if (spec->multiout.num_dacs == 1 && !spec->mixer_nid &&
882 !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0])
883 return spec->vmaster_mute.hook ? "PCM" : "Master";
885 /* multi-io channels */
886 if (ch >= cfg->line_outs)
887 return channel_name[ch];
889 switch (cfg->line_out_type) {
890 case AUTO_PIN_SPEAKER_OUT:
891 /* if the primary channel vol/mute is shared with HP volume,
892 * don't name it as Speaker
894 if (!ch && cfg->hp_outs &&
895 !path_has_mixer(codec, spec->hp_paths[0], ctl_type))
897 if (cfg->line_outs == 1)
899 if (cfg->line_outs == 2)
900 return ch ? "Bass Speaker" : "Speaker";
902 case AUTO_PIN_HP_OUT:
903 /* if the primary channel vol/mute is shared with spk volume,
904 * don't name it as Headphone
906 if (!ch && cfg->speaker_outs &&
907 !path_has_mixer(codec, spec->speaker_paths[0], ctl_type))
909 /* for multi-io case, only the primary out */
910 if (ch && spec->multi_ios)
916 /* for a single channel output, we don't have to name the channel */
917 if (cfg->line_outs == 1 && !spec->multi_ios)
920 if (ch >= ARRAY_SIZE(channel_name)) {
925 return channel_name[ch];
932 /* badness definition */
934 /* No primary DAC is found for the main output */
935 BAD_NO_PRIMARY_DAC = 0x10000,
936 /* No DAC is found for the extra output */
938 /* No possible multi-ios */
939 BAD_MULTI_IO = 0x103,
940 /* No individual DAC for extra output */
941 BAD_NO_EXTRA_DAC = 0x102,
942 /* No individual DAC for extra surrounds */
943 BAD_NO_EXTRA_SURR_DAC = 0x101,
944 /* Primary DAC shared with main surrounds */
945 BAD_SHARED_SURROUND = 0x100,
946 /* Primary DAC shared with main CLFE */
947 BAD_SHARED_CLFE = 0x10,
948 /* Primary DAC shared with extra surrounds */
949 BAD_SHARED_EXTRA_SURROUND = 0x10,
950 /* Volume widget is shared */
951 BAD_SHARED_VOL = 0x10,
954 /* look for widgets in the given path which are appropriate for
955 * volume and mute controls, and assign the values to ctls[].
957 * When no appropriate widget is found in the path, the badness value
958 * is incremented depending on the situation. The function returns the
959 * total badness for both volume and mute controls.
961 static int assign_out_path_ctls(struct hda_codec *codec, struct nid_path *path)
968 return BAD_SHARED_VOL * 2;
970 if (path->ctls[NID_PATH_VOL_CTL] ||
971 path->ctls[NID_PATH_MUTE_CTL])
972 return 0; /* already evaluated */
974 nid = look_for_out_vol_nid(codec, path);
976 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
977 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
978 badness += BAD_SHARED_VOL;
980 path->ctls[NID_PATH_VOL_CTL] = val;
982 badness += BAD_SHARED_VOL;
983 nid = look_for_out_mute_nid(codec, path);
985 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
986 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
987 nid_has_mute(codec, nid, HDA_OUTPUT))
988 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
990 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
991 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
992 badness += BAD_SHARED_VOL;
994 path->ctls[NID_PATH_MUTE_CTL] = val;
996 badness += BAD_SHARED_VOL;
1000 struct badness_table {
1001 int no_primary_dac; /* no primary DAC */
1002 int no_dac; /* no secondary DACs */
1003 int shared_primary; /* primary DAC is shared with main output */
1004 int shared_surr; /* secondary DAC shared with main or primary */
1005 int shared_clfe; /* third DAC shared with main or primary */
1006 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
1009 static struct badness_table main_out_badness = {
1010 .no_primary_dac = BAD_NO_PRIMARY_DAC,
1011 .no_dac = BAD_NO_DAC,
1012 .shared_primary = BAD_NO_PRIMARY_DAC,
1013 .shared_surr = BAD_SHARED_SURROUND,
1014 .shared_clfe = BAD_SHARED_CLFE,
1015 .shared_surr_main = BAD_SHARED_SURROUND,
1018 static struct badness_table extra_out_badness = {
1019 .no_primary_dac = BAD_NO_DAC,
1020 .no_dac = BAD_NO_DAC,
1021 .shared_primary = BAD_NO_EXTRA_DAC,
1022 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
1023 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
1024 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
1027 /* get the DAC of the primary output corresponding to the given array index */
1028 static hda_nid_t get_primary_out(struct hda_codec *codec, int idx)
1030 struct hda_gen_spec *spec = codec->spec;
1031 struct auto_pin_cfg *cfg = &spec->autocfg;
1033 if (cfg->line_outs > idx)
1034 return spec->private_dac_nids[idx];
1035 idx -= cfg->line_outs;
1036 if (spec->multi_ios > idx)
1037 return spec->multi_io[idx].dac;
1041 /* return the DAC if it's reachable, otherwise zero */
1042 static inline hda_nid_t try_dac(struct hda_codec *codec,
1043 hda_nid_t dac, hda_nid_t pin)
1045 return is_reachable_path(codec, dac, pin) ? dac : 0;
1048 /* try to assign DACs to pins and return the resultant badness */
1049 static int try_assign_dacs(struct hda_codec *codec, int num_outs,
1050 const hda_nid_t *pins, hda_nid_t *dacs,
1052 const struct badness_table *bad)
1054 struct hda_gen_spec *spec = codec->spec;
1062 for (i = 0; i < num_outs; i++) {
1063 struct nid_path *path;
1064 hda_nid_t pin = pins[i];
1066 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1068 badness += assign_out_path_ctls(codec, path);
1072 dacs[i] = look_for_dac(codec, pin, false);
1073 if (!dacs[i] && !i) {
1074 /* try to steal the DAC of surrounds for the front */
1075 for (j = 1; j < num_outs; j++) {
1076 if (is_reachable_path(codec, dacs[j], pin)) {
1079 invalidate_nid_path(codec, path_idx[j]);
1088 dac = try_dac(codec, get_primary_out(codec, i), pin);
1090 dac = try_dac(codec, dacs[0], pin);
1092 dac = try_dac(codec, get_primary_out(codec, i), pin);
1095 badness += bad->shared_primary;
1097 badness += bad->shared_surr;
1099 badness += bad->shared_clfe;
1100 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
1101 dac = spec->private_dac_nids[0];
1102 badness += bad->shared_surr_main;
1104 badness += bad->no_primary_dac;
1106 badness += bad->no_dac;
1108 path = snd_hda_add_new_path(codec, dac, pin, -spec->mixer_nid);
1109 if (!path && !i && spec->mixer_nid) {
1110 /* try with aamix */
1111 path = snd_hda_add_new_path(codec, dac, pin, 0);
1116 print_nid_path("output", path);
1117 path->active = true;
1118 path_idx[i] = snd_hda_get_path_idx(codec, path);
1119 badness += assign_out_path_ctls(codec, path);
1126 /* return NID if the given pin has only a single connection to a certain DAC */
1127 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
1129 struct hda_gen_spec *spec = codec->spec;
1131 hda_nid_t nid_found = 0;
1133 for (i = 0; i < spec->num_all_dacs; i++) {
1134 hda_nid_t nid = spec->all_dacs[i];
1135 if (!nid || is_dac_already_used(codec, nid))
1137 if (is_reachable_path(codec, nid, pin)) {
1146 /* check whether the given pin can be a multi-io pin */
1147 static bool can_be_multiio_pin(struct hda_codec *codec,
1148 unsigned int location, hda_nid_t nid)
1150 unsigned int defcfg, caps;
1152 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1153 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
1155 if (location && get_defcfg_location(defcfg) != location)
1157 caps = snd_hda_query_pin_caps(codec, nid);
1158 if (!(caps & AC_PINCAP_OUT))
1163 /* count the number of input pins that are capable to be multi-io */
1164 static int count_multiio_pins(struct hda_codec *codec, hda_nid_t reference_pin)
1166 struct hda_gen_spec *spec = codec->spec;
1167 struct auto_pin_cfg *cfg = &spec->autocfg;
1168 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1169 unsigned int location = get_defcfg_location(defcfg);
1173 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
1174 for (i = 0; i < cfg->num_inputs; i++) {
1175 if (cfg->inputs[i].type != type)
1177 if (can_be_multiio_pin(codec, location,
1178 cfg->inputs[i].pin))
1188 * When hardwired is set, try to fill ony hardwired pins, and returns
1189 * zero if any pins are filled, non-zero if nothing found.
1190 * When hardwired is off, try to fill possible input pins, and returns
1191 * the badness value.
1193 static int fill_multi_ios(struct hda_codec *codec,
1194 hda_nid_t reference_pin,
1197 struct hda_gen_spec *spec = codec->spec;
1198 struct auto_pin_cfg *cfg = &spec->autocfg;
1199 int type, i, j, num_pins, old_pins;
1200 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1201 unsigned int location = get_defcfg_location(defcfg);
1203 struct nid_path *path;
1205 old_pins = spec->multi_ios;
1209 num_pins = count_multiio_pins(codec, reference_pin);
1213 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
1214 for (i = 0; i < cfg->num_inputs; i++) {
1215 hda_nid_t nid = cfg->inputs[i].pin;
1218 if (cfg->inputs[i].type != type)
1220 if (!can_be_multiio_pin(codec, location, nid))
1222 for (j = 0; j < spec->multi_ios; j++) {
1223 if (nid == spec->multi_io[j].pin)
1226 if (j < spec->multi_ios)
1230 dac = get_dac_if_single(codec, nid);
1232 dac = look_for_dac(codec, nid, false);
1237 path = snd_hda_add_new_path(codec, dac, nid,
1243 print_nid_path("multiio", path);
1244 spec->multi_io[spec->multi_ios].pin = nid;
1245 spec->multi_io[spec->multi_ios].dac = dac;
1246 spec->out_paths[cfg->line_outs + spec->multi_ios] =
1247 snd_hda_get_path_idx(codec, path);
1249 if (spec->multi_ios >= 2)
1255 badness = BAD_MULTI_IO;
1256 if (old_pins == spec->multi_ios) {
1258 return 1; /* nothing found */
1260 return badness; /* no badness if nothing found */
1262 if (!hardwired && spec->multi_ios < 2) {
1263 /* cancel newly assigned paths */
1264 spec->paths.used -= spec->multi_ios - old_pins;
1265 spec->multi_ios = old_pins;
1269 /* assign volume and mute controls */
1270 for (i = old_pins; i < spec->multi_ios; i++) {
1271 path = snd_hda_get_path_from_idx(codec, spec->out_paths[cfg->line_outs + i]);
1272 badness += assign_out_path_ctls(codec, path);
1278 /* map DACs for all pins in the list if they are single connections */
1279 static bool map_singles(struct hda_codec *codec, int outs,
1280 const hda_nid_t *pins, hda_nid_t *dacs, int *path_idx)
1282 struct hda_gen_spec *spec = codec->spec;
1285 for (i = 0; i < outs; i++) {
1286 struct nid_path *path;
1290 dac = get_dac_if_single(codec, pins[i]);
1293 path = snd_hda_add_new_path(codec, dac, pins[i],
1295 if (!path && !i && spec->mixer_nid)
1296 path = snd_hda_add_new_path(codec, dac, pins[i], 0);
1300 print_nid_path("output", path);
1301 path->active = true;
1302 path_idx[i] = snd_hda_get_path_idx(codec, path);
1308 /* create a new path including aamix if available, and return its index */
1309 static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
1311 struct hda_gen_spec *spec = codec->spec;
1312 struct nid_path *path;
1314 path = snd_hda_get_path_from_idx(codec, path_idx);
1315 if (!path || !path->depth ||
1316 is_nid_contained(path, spec->mixer_nid))
1318 path = snd_hda_add_new_path(codec, path->path[0],
1319 path->path[path->depth - 1],
1323 print_nid_path("output-aamix", path);
1324 path->active = false; /* unused as default */
1325 return snd_hda_get_path_idx(codec, path);
1328 /* fill the empty entries in the dac array for speaker/hp with the
1329 * shared dac pointed by the paths
1331 static void refill_shared_dacs(struct hda_codec *codec, int num_outs,
1332 hda_nid_t *dacs, int *path_idx)
1334 struct nid_path *path;
1337 for (i = 0; i < num_outs; i++) {
1340 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1343 dacs[i] = path->path[0];
1347 /* fill in the dac_nids table from the parsed pin configuration */
1348 static int fill_and_eval_dacs(struct hda_codec *codec,
1349 bool fill_hardwired,
1350 bool fill_mio_first)
1352 struct hda_gen_spec *spec = codec->spec;
1353 struct auto_pin_cfg *cfg = &spec->autocfg;
1354 int i, err, badness;
1357 /* set num_dacs once to full for look_for_dac() */
1358 spec->multiout.num_dacs = cfg->line_outs;
1359 spec->multiout.dac_nids = spec->private_dac_nids;
1360 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
1361 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
1362 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
1363 spec->multi_ios = 0;
1364 snd_array_free(&spec->paths);
1366 /* clear path indices */
1367 memset(spec->out_paths, 0, sizeof(spec->out_paths));
1368 memset(spec->hp_paths, 0, sizeof(spec->hp_paths));
1369 memset(spec->speaker_paths, 0, sizeof(spec->speaker_paths));
1370 memset(spec->aamix_out_paths, 0, sizeof(spec->aamix_out_paths));
1371 memset(spec->digout_paths, 0, sizeof(spec->digout_paths));
1372 memset(spec->input_paths, 0, sizeof(spec->input_paths));
1373 memset(spec->loopback_paths, 0, sizeof(spec->loopback_paths));
1374 memset(&spec->digin_path, 0, sizeof(spec->digin_path));
1378 /* fill hard-wired DACs first */
1379 if (fill_hardwired) {
1382 mapped = map_singles(codec, cfg->line_outs,
1384 spec->private_dac_nids,
1386 mapped |= map_singles(codec, cfg->hp_outs,
1388 spec->multiout.hp_out_nid,
1390 mapped |= map_singles(codec, cfg->speaker_outs,
1392 spec->multiout.extra_out_nid,
1393 spec->speaker_paths);
1394 if (fill_mio_first && cfg->line_outs == 1 &&
1395 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1396 err = fill_multi_ios(codec, cfg->line_out_pins[0], true);
1403 badness += try_assign_dacs(codec, cfg->line_outs, cfg->line_out_pins,
1404 spec->private_dac_nids, spec->out_paths,
1407 if (fill_mio_first &&
1408 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1409 /* try to fill multi-io first */
1410 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1413 /* we don't count badness at this stage yet */
1416 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
1417 err = try_assign_dacs(codec, cfg->hp_outs, cfg->hp_pins,
1418 spec->multiout.hp_out_nid,
1420 &extra_out_badness);
1425 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1426 err = try_assign_dacs(codec, cfg->speaker_outs,
1428 spec->multiout.extra_out_nid,
1429 spec->speaker_paths,
1430 &extra_out_badness);
1435 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1436 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1442 if (spec->mixer_nid) {
1443 spec->aamix_out_paths[0] =
1444 check_aamix_out_path(codec, spec->out_paths[0]);
1445 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1446 spec->aamix_out_paths[1] =
1447 check_aamix_out_path(codec, spec->hp_paths[0]);
1448 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1449 spec->aamix_out_paths[2] =
1450 check_aamix_out_path(codec, spec->speaker_paths[0]);
1453 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
1454 if (count_multiio_pins(codec, cfg->hp_pins[0]) >= 2)
1455 spec->multi_ios = 1; /* give badness */
1457 /* re-count num_dacs and squash invalid entries */
1458 spec->multiout.num_dacs = 0;
1459 for (i = 0; i < cfg->line_outs; i++) {
1460 if (spec->private_dac_nids[i])
1461 spec->multiout.num_dacs++;
1463 memmove(spec->private_dac_nids + i,
1464 spec->private_dac_nids + i + 1,
1465 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
1466 spec->private_dac_nids[cfg->line_outs - 1] = 0;
1470 spec->ext_channel_count = spec->min_channel_count =
1471 spec->multiout.num_dacs * 2;
1473 if (spec->multi_ios == 2) {
1474 for (i = 0; i < 2; i++)
1475 spec->private_dac_nids[spec->multiout.num_dacs++] =
1476 spec->multi_io[i].dac;
1477 } else if (spec->multi_ios) {
1478 spec->multi_ios = 0;
1479 badness += BAD_MULTI_IO;
1482 /* re-fill the shared DAC for speaker / headphone */
1483 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1484 refill_shared_dacs(codec, cfg->hp_outs,
1485 spec->multiout.hp_out_nid,
1487 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1488 refill_shared_dacs(codec, cfg->speaker_outs,
1489 spec->multiout.extra_out_nid,
1490 spec->speaker_paths);
1492 /* set initial pinctl targets */
1493 if (spec->prefer_hp_amp || cfg->line_out_type == AUTO_PIN_HP_OUT)
1497 set_pin_targets(codec, cfg->line_outs, cfg->line_out_pins, val);
1498 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1499 set_pin_targets(codec, cfg->hp_outs, cfg->hp_pins, PIN_HP);
1500 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1501 val = spec->prefer_hp_amp ? PIN_HP : PIN_OUT;
1502 set_pin_targets(codec, cfg->speaker_outs,
1503 cfg->speaker_pins, val);
1509 #define DEBUG_BADNESS
1511 #ifdef DEBUG_BADNESS
1512 #define debug_badness snd_printdd
1514 #define debug_badness(...)
1517 static void debug_show_configs(struct hda_gen_spec *spec, struct auto_pin_cfg *cfg)
1519 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
1520 cfg->line_out_pins[0], cfg->line_out_pins[1],
1521 cfg->line_out_pins[2], cfg->line_out_pins[3],
1522 spec->multiout.dac_nids[0],
1523 spec->multiout.dac_nids[1],
1524 spec->multiout.dac_nids[2],
1525 spec->multiout.dac_nids[3]);
1526 if (spec->multi_ios > 0)
1527 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
1529 spec->multi_io[0].pin, spec->multi_io[1].pin,
1530 spec->multi_io[0].dac, spec->multi_io[1].dac);
1531 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
1532 cfg->hp_pins[0], cfg->hp_pins[1],
1533 cfg->hp_pins[2], cfg->hp_pins[3],
1534 spec->multiout.hp_out_nid[0],
1535 spec->multiout.hp_out_nid[1],
1536 spec->multiout.hp_out_nid[2],
1537 spec->multiout.hp_out_nid[3]);
1538 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
1539 cfg->speaker_pins[0], cfg->speaker_pins[1],
1540 cfg->speaker_pins[2], cfg->speaker_pins[3],
1541 spec->multiout.extra_out_nid[0],
1542 spec->multiout.extra_out_nid[1],
1543 spec->multiout.extra_out_nid[2],
1544 spec->multiout.extra_out_nid[3]);
1547 /* find all available DACs of the codec */
1548 static void fill_all_dac_nids(struct hda_codec *codec)
1550 struct hda_gen_spec *spec = codec->spec;
1552 hda_nid_t nid = codec->start_nid;
1554 spec->num_all_dacs = 0;
1555 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
1556 for (i = 0; i < codec->num_nodes; i++, nid++) {
1557 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
1559 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
1560 snd_printk(KERN_ERR "hda: Too many DACs!\n");
1563 spec->all_dacs[spec->num_all_dacs++] = nid;
1567 static int parse_output_paths(struct hda_codec *codec)
1569 struct hda_gen_spec *spec = codec->spec;
1570 struct auto_pin_cfg *cfg = &spec->autocfg;
1571 struct auto_pin_cfg *best_cfg;
1572 int best_badness = INT_MAX;
1574 bool fill_hardwired = true, fill_mio_first = true;
1575 bool best_wired = true, best_mio = true;
1576 bool hp_spk_swapped = false;
1578 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
1584 badness = fill_and_eval_dacs(codec, fill_hardwired,
1590 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
1591 cfg->line_out_type, fill_hardwired, fill_mio_first,
1593 debug_show_configs(spec, cfg);
1594 if (badness < best_badness) {
1595 best_badness = badness;
1597 best_wired = fill_hardwired;
1598 best_mio = fill_mio_first;
1602 fill_mio_first = !fill_mio_first;
1603 if (!fill_mio_first)
1605 fill_hardwired = !fill_hardwired;
1606 if (!fill_hardwired)
1610 hp_spk_swapped = true;
1611 if (cfg->speaker_outs > 0 &&
1612 cfg->line_out_type == AUTO_PIN_HP_OUT) {
1613 cfg->hp_outs = cfg->line_outs;
1614 memcpy(cfg->hp_pins, cfg->line_out_pins,
1615 sizeof(cfg->hp_pins));
1616 cfg->line_outs = cfg->speaker_outs;
1617 memcpy(cfg->line_out_pins, cfg->speaker_pins,
1618 sizeof(cfg->speaker_pins));
1619 cfg->speaker_outs = 0;
1620 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
1621 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
1622 fill_hardwired = true;
1625 if (cfg->hp_outs > 0 &&
1626 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
1627 cfg->speaker_outs = cfg->line_outs;
1628 memcpy(cfg->speaker_pins, cfg->line_out_pins,
1629 sizeof(cfg->speaker_pins));
1630 cfg->line_outs = cfg->hp_outs;
1631 memcpy(cfg->line_out_pins, cfg->hp_pins,
1632 sizeof(cfg->hp_pins));
1634 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
1635 cfg->line_out_type = AUTO_PIN_HP_OUT;
1636 fill_hardwired = true;
1643 debug_badness("==> restoring best_cfg\n");
1645 fill_and_eval_dacs(codec, best_wired, best_mio);
1647 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
1648 cfg->line_out_type, best_wired, best_mio);
1649 debug_show_configs(spec, cfg);
1651 if (cfg->line_out_pins[0]) {
1652 struct nid_path *path;
1653 path = snd_hda_get_path_from_idx(codec, spec->out_paths[0]);
1655 spec->vmaster_nid = look_for_out_vol_nid(codec, path);
1656 if (spec->vmaster_nid)
1657 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1658 HDA_OUTPUT, spec->vmaster_tlv);
1665 /* add playback controls from the parsed DAC table */
1666 static int create_multi_out_ctls(struct hda_codec *codec,
1667 const struct auto_pin_cfg *cfg)
1669 struct hda_gen_spec *spec = codec->spec;
1670 int i, err, noutputs;
1672 noutputs = cfg->line_outs;
1673 if (spec->multi_ios > 0 && cfg->line_outs < 3)
1674 noutputs += spec->multi_ios;
1676 for (i = 0; i < noutputs; i++) {
1679 struct nid_path *path;
1681 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
1685 name = get_line_out_pfx(codec, i, &index, NID_PATH_VOL_CTL);
1686 if (!name || !strcmp(name, "CLFE")) {
1688 err = add_vol_ctl(codec, "Center", 0, 1, path);
1691 err = add_vol_ctl(codec, "LFE", 0, 2, path);
1695 err = add_stereo_vol(codec, name, index, path);
1700 name = get_line_out_pfx(codec, i, &index, NID_PATH_MUTE_CTL);
1701 if (!name || !strcmp(name, "CLFE")) {
1702 err = add_sw_ctl(codec, "Center", 0, 1, path);
1705 err = add_sw_ctl(codec, "LFE", 0, 2, path);
1709 err = add_stereo_sw(codec, name, index, path);
1717 static int create_extra_out(struct hda_codec *codec, int path_idx,
1718 const char *pfx, int cidx)
1720 struct nid_path *path;
1723 path = snd_hda_get_path_from_idx(codec, path_idx);
1726 err = add_stereo_vol(codec, pfx, cidx, path);
1729 err = add_stereo_sw(codec, pfx, cidx, path);
1735 /* add playback controls for speaker and HP outputs */
1736 static int create_extra_outs(struct hda_codec *codec, int num_pins,
1737 const int *paths, const char *pfx)
1741 for (i = 0; i < num_pins; i++) {
1746 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker"))
1747 name = "Bass Speaker";
1748 else if (num_pins >= 3) {
1749 snprintf(tmp, sizeof(tmp), "%s %s",
1750 pfx, channel_name[i]);
1756 err = create_extra_out(codec, paths[i], name, idx);
1763 static int create_hp_out_ctls(struct hda_codec *codec)
1765 struct hda_gen_spec *spec = codec->spec;
1766 return create_extra_outs(codec, spec->autocfg.hp_outs,
1771 static int create_speaker_out_ctls(struct hda_codec *codec)
1773 struct hda_gen_spec *spec = codec->spec;
1774 return create_extra_outs(codec, spec->autocfg.speaker_outs,
1775 spec->speaker_paths,
1780 * independent HP controls
1783 static int indep_hp_info(struct snd_kcontrol *kcontrol,
1784 struct snd_ctl_elem_info *uinfo)
1786 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
1789 static int indep_hp_get(struct snd_kcontrol *kcontrol,
1790 struct snd_ctl_elem_value *ucontrol)
1792 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1793 struct hda_gen_spec *spec = codec->spec;
1794 ucontrol->value.enumerated.item[0] = spec->indep_hp_enabled;
1798 static int indep_hp_put(struct snd_kcontrol *kcontrol,
1799 struct snd_ctl_elem_value *ucontrol)
1801 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1802 struct hda_gen_spec *spec = codec->spec;
1803 unsigned int select = ucontrol->value.enumerated.item[0];
1806 mutex_lock(&spec->pcm_mutex);
1807 if (spec->active_streams) {
1812 if (spec->indep_hp_enabled != select) {
1813 spec->indep_hp_enabled = select;
1814 if (spec->indep_hp_enabled)
1815 spec->multiout.hp_out_nid[0] = 0;
1817 spec->multiout.hp_out_nid[0] = spec->alt_dac_nid;
1821 mutex_unlock(&spec->pcm_mutex);
1825 static const struct snd_kcontrol_new indep_hp_ctl = {
1826 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1827 .name = "Independent HP",
1828 .info = indep_hp_info,
1829 .get = indep_hp_get,
1830 .put = indep_hp_put,
1834 static int create_indep_hp_ctls(struct hda_codec *codec)
1836 struct hda_gen_spec *spec = codec->spec;
1838 if (!spec->indep_hp)
1840 if (!spec->multiout.hp_out_nid[0]) {
1845 spec->indep_hp_enabled = false;
1846 spec->alt_dac_nid = spec->multiout.hp_out_nid[0];
1847 if (!snd_hda_gen_add_kctl(spec, NULL, &indep_hp_ctl))
1853 * channel mode enum control
1856 static int ch_mode_info(struct snd_kcontrol *kcontrol,
1857 struct snd_ctl_elem_info *uinfo)
1859 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1860 struct hda_gen_spec *spec = codec->spec;
1863 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1865 uinfo->value.enumerated.items = spec->multi_ios + 1;
1866 if (uinfo->value.enumerated.item > spec->multi_ios)
1867 uinfo->value.enumerated.item = spec->multi_ios;
1868 chs = uinfo->value.enumerated.item * 2 + spec->min_channel_count;
1869 sprintf(uinfo->value.enumerated.name, "%dch", chs);
1873 static int ch_mode_get(struct snd_kcontrol *kcontrol,
1874 struct snd_ctl_elem_value *ucontrol)
1876 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1877 struct hda_gen_spec *spec = codec->spec;
1878 ucontrol->value.enumerated.item[0] =
1879 (spec->ext_channel_count - spec->min_channel_count) / 2;
1883 static inline struct nid_path *
1884 get_multiio_path(struct hda_codec *codec, int idx)
1886 struct hda_gen_spec *spec = codec->spec;
1887 return snd_hda_get_path_from_idx(codec,
1888 spec->out_paths[spec->autocfg.line_outs + idx]);
1891 static void update_automute_all(struct hda_codec *codec);
1893 static int set_multi_io(struct hda_codec *codec, int idx, bool output)
1895 struct hda_gen_spec *spec = codec->spec;
1896 hda_nid_t nid = spec->multi_io[idx].pin;
1897 struct nid_path *path;
1899 path = get_multiio_path(codec, idx);
1903 if (path->active == output)
1907 set_pin_target(codec, nid, PIN_OUT, true);
1908 snd_hda_activate_path(codec, path, true, true);
1909 set_pin_eapd(codec, nid, true);
1911 set_pin_eapd(codec, nid, false);
1912 snd_hda_activate_path(codec, path, false, true);
1913 set_pin_target(codec, nid, spec->multi_io[idx].ctl_in, true);
1916 /* update jack retasking in case it modifies any of them */
1917 update_automute_all(codec);
1922 static int ch_mode_put(struct snd_kcontrol *kcontrol,
1923 struct snd_ctl_elem_value *ucontrol)
1925 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1926 struct hda_gen_spec *spec = codec->spec;
1929 ch = ucontrol->value.enumerated.item[0];
1930 if (ch < 0 || ch > spec->multi_ios)
1932 if (ch == (spec->ext_channel_count - spec->min_channel_count) / 2)
1934 spec->ext_channel_count = ch * 2 + spec->min_channel_count;
1935 for (i = 0; i < spec->multi_ios; i++)
1936 set_multi_io(codec, i, i < ch);
1937 spec->multiout.max_channels = max(spec->ext_channel_count,
1938 spec->const_channel_count);
1939 if (spec->need_dac_fix)
1940 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
1944 static const struct snd_kcontrol_new channel_mode_enum = {
1945 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1946 .name = "Channel Mode",
1947 .info = ch_mode_info,
1952 static int create_multi_channel_mode(struct hda_codec *codec)
1954 struct hda_gen_spec *spec = codec->spec;
1956 if (spec->multi_ios > 0) {
1957 if (!snd_hda_gen_add_kctl(spec, NULL, &channel_mode_enum))
1964 * aamix loopback enable/disable switch
1967 #define loopback_mixing_info indep_hp_info
1969 static int loopback_mixing_get(struct snd_kcontrol *kcontrol,
1970 struct snd_ctl_elem_value *ucontrol)
1972 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1973 struct hda_gen_spec *spec = codec->spec;
1974 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
1978 static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
1979 int nomix_path_idx, int mix_path_idx)
1981 struct nid_path *nomix_path, *mix_path;
1983 nomix_path = snd_hda_get_path_from_idx(codec, nomix_path_idx);
1984 mix_path = snd_hda_get_path_from_idx(codec, mix_path_idx);
1985 if (!nomix_path || !mix_path)
1988 snd_hda_activate_path(codec, nomix_path, false, true);
1989 snd_hda_activate_path(codec, mix_path, true, true);
1991 snd_hda_activate_path(codec, mix_path, false, true);
1992 snd_hda_activate_path(codec, nomix_path, true, true);
1996 static int loopback_mixing_put(struct snd_kcontrol *kcontrol,
1997 struct snd_ctl_elem_value *ucontrol)
1999 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2000 struct hda_gen_spec *spec = codec->spec;
2001 unsigned int val = ucontrol->value.enumerated.item[0];
2003 if (val == spec->aamix_mode)
2005 spec->aamix_mode = val;
2006 update_aamix_paths(codec, val, spec->out_paths[0],
2007 spec->aamix_out_paths[0]);
2008 update_aamix_paths(codec, val, spec->hp_paths[0],
2009 spec->aamix_out_paths[1]);
2010 update_aamix_paths(codec, val, spec->speaker_paths[0],
2011 spec->aamix_out_paths[2]);
2015 static const struct snd_kcontrol_new loopback_mixing_enum = {
2016 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2017 .name = "Loopback Mixing",
2018 .info = loopback_mixing_info,
2019 .get = loopback_mixing_get,
2020 .put = loopback_mixing_put,
2023 static int create_loopback_mixing_ctl(struct hda_codec *codec)
2025 struct hda_gen_spec *spec = codec->spec;
2027 if (!spec->mixer_nid)
2029 if (!(spec->aamix_out_paths[0] || spec->aamix_out_paths[1] ||
2030 spec->aamix_out_paths[2]))
2032 if (!snd_hda_gen_add_kctl(spec, NULL, &loopback_mixing_enum))
2038 * shared headphone/mic handling
2041 static void call_update_outputs(struct hda_codec *codec);
2043 /* for shared I/O, change the pin-control accordingly */
2044 static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
2046 struct hda_gen_spec *spec = codec->spec;
2048 hda_nid_t pin = spec->autocfg.inputs[1].pin;
2049 /* NOTE: this assumes that there are only two inputs, the
2050 * first is the real internal mic and the second is HP/mic jack.
2053 val = snd_hda_get_default_vref(codec, pin);
2055 /* This pin does not have vref caps - let's enable vref on pin 0x18
2056 instead, as suggested by Realtek */
2057 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
2058 const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
2059 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
2060 if (vref_val != AC_PINCTL_VREF_HIZ)
2061 snd_hda_set_pin_ctl_cache(codec, vref_pin,
2062 PIN_IN | (set_as_mic ? vref_val : 0));
2065 val = set_as_mic ? val | PIN_IN : PIN_HP;
2066 set_pin_target(codec, pin, val, true);
2068 spec->automute_speaker = !set_as_mic;
2069 call_update_outputs(codec);
2072 /* create a shared input with the headphone out */
2073 static int create_shared_input(struct hda_codec *codec)
2075 struct hda_gen_spec *spec = codec->spec;
2076 struct auto_pin_cfg *cfg = &spec->autocfg;
2077 unsigned int defcfg;
2080 /* only one internal input pin? */
2081 if (cfg->num_inputs != 1)
2083 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2084 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2087 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2088 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2089 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2090 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2092 return 0; /* both not available */
2094 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2095 return 0; /* no input */
2097 cfg->inputs[1].pin = nid;
2098 cfg->inputs[1].type = AUTO_PIN_MIC;
2099 cfg->num_inputs = 2;
2100 spec->shared_mic_hp = 1;
2101 snd_printdd("hda-codec: Enable shared I/O jack on NID 0x%x\n", nid);
2108 static int out_jack_mode_info(struct snd_kcontrol *kcontrol,
2109 struct snd_ctl_elem_info *uinfo)
2111 static const char * const texts[] = {
2112 "Line Out", "Headphone Out",
2114 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts);
2117 static int out_jack_mode_get(struct snd_kcontrol *kcontrol,
2118 struct snd_ctl_elem_value *ucontrol)
2120 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2121 hda_nid_t nid = kcontrol->private_value;
2122 if (snd_hda_codec_get_pin_target(codec, nid) == PIN_HP)
2123 ucontrol->value.enumerated.item[0] = 1;
2125 ucontrol->value.enumerated.item[0] = 0;
2129 static int out_jack_mode_put(struct snd_kcontrol *kcontrol,
2130 struct snd_ctl_elem_value *ucontrol)
2132 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2133 hda_nid_t nid = kcontrol->private_value;
2136 val = ucontrol->value.enumerated.item[0] ? PIN_HP : PIN_OUT;
2137 if (snd_hda_codec_get_pin_target(codec, nid) == val)
2139 snd_hda_set_pin_ctl_cache(codec, nid, val);
2143 static const struct snd_kcontrol_new out_jack_mode_enum = {
2144 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2145 .info = out_jack_mode_info,
2146 .get = out_jack_mode_get,
2147 .put = out_jack_mode_put,
2150 static bool find_kctl_name(struct hda_codec *codec, const char *name, int idx)
2152 struct hda_gen_spec *spec = codec->spec;
2155 for (i = 0; i < spec->kctls.used; i++) {
2156 struct snd_kcontrol_new *kctl = snd_array_elem(&spec->kctls, i);
2157 if (!strcmp(kctl->name, name) && kctl->index == idx)
2163 static void get_jack_mode_name(struct hda_codec *codec, hda_nid_t pin,
2164 char *name, size_t name_len)
2166 struct hda_gen_spec *spec = codec->spec;
2169 snd_hda_get_pin_label(codec, pin, &spec->autocfg, name, name_len, &idx);
2170 strlcat(name, " Jack Mode", name_len);
2172 for (; find_kctl_name(codec, name, idx); idx++)
2176 static int create_out_jack_modes(struct hda_codec *codec, int num_pins,
2179 struct hda_gen_spec *spec = codec->spec;
2182 for (i = 0; i < num_pins; i++) {
2183 hda_nid_t pin = pins[i];
2184 unsigned int pincap = snd_hda_query_pin_caps(codec, pin);
2185 if ((pincap & AC_PINCAP_OUT) && (pincap & AC_PINCAP_HP_DRV)) {
2186 struct snd_kcontrol_new *knew;
2188 get_jack_mode_name(codec, pin, name, sizeof(name));
2189 knew = snd_hda_gen_add_kctl(spec, name,
2190 &out_jack_mode_enum);
2193 knew->private_value = pin;
2204 /* from AC_PINCTL_VREF_HIZ to AC_PINCTL_VREF_100 */
2207 static const char * const vref_texts[NUM_VREFS] = {
2208 "Line In", "Mic 50pc Bias", "Mic 0V Bias",
2209 "", "Mic 80pc Bias", "Mic 100pc Bias"
2212 static unsigned int get_vref_caps(struct hda_codec *codec, hda_nid_t pin)
2214 unsigned int pincap;
2216 pincap = snd_hda_query_pin_caps(codec, pin);
2217 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2218 /* filter out unusual vrefs */
2219 pincap &= ~(AC_PINCAP_VREF_GRD | AC_PINCAP_VREF_100);
2223 /* convert from the enum item index to the vref ctl index (0=HIZ, 1=50%...) */
2224 static int get_vref_idx(unsigned int vref_caps, unsigned int item_idx)
2226 unsigned int i, n = 0;
2228 for (i = 0; i < NUM_VREFS; i++) {
2229 if (vref_caps & (1 << i)) {
2238 /* convert back from the vref ctl index to the enum item index */
2239 static int cvt_from_vref_idx(unsigned int vref_caps, unsigned int idx)
2241 unsigned int i, n = 0;
2243 for (i = 0; i < NUM_VREFS; i++) {
2246 if (vref_caps & (1 << i))
2252 static int in_jack_mode_info(struct snd_kcontrol *kcontrol,
2253 struct snd_ctl_elem_info *uinfo)
2255 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2256 hda_nid_t nid = kcontrol->private_value;
2257 unsigned int vref_caps = get_vref_caps(codec, nid);
2259 snd_hda_enum_helper_info(kcontrol, uinfo, hweight32(vref_caps),
2261 /* set the right text */
2262 strcpy(uinfo->value.enumerated.name,
2263 vref_texts[get_vref_idx(vref_caps, uinfo->value.enumerated.item)]);
2267 static int in_jack_mode_get(struct snd_kcontrol *kcontrol,
2268 struct snd_ctl_elem_value *ucontrol)
2270 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2271 hda_nid_t nid = kcontrol->private_value;
2272 unsigned int vref_caps = get_vref_caps(codec, nid);
2275 idx = snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_VREFEN;
2276 ucontrol->value.enumerated.item[0] = cvt_from_vref_idx(vref_caps, idx);
2280 static int in_jack_mode_put(struct snd_kcontrol *kcontrol,
2281 struct snd_ctl_elem_value *ucontrol)
2283 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2284 hda_nid_t nid = kcontrol->private_value;
2285 unsigned int vref_caps = get_vref_caps(codec, nid);
2286 unsigned int val, idx;
2288 val = snd_hda_codec_get_pin_target(codec, nid);
2289 idx = cvt_from_vref_idx(vref_caps, val & AC_PINCTL_VREFEN);
2290 if (idx == ucontrol->value.enumerated.item[0])
2293 val &= ~AC_PINCTL_VREFEN;
2294 val |= get_vref_idx(vref_caps, ucontrol->value.enumerated.item[0]);
2295 snd_hda_set_pin_ctl_cache(codec, nid, val);
2299 static const struct snd_kcontrol_new in_jack_mode_enum = {
2300 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2301 .info = in_jack_mode_info,
2302 .get = in_jack_mode_get,
2303 .put = in_jack_mode_put,
2306 static int create_in_jack_mode(struct hda_codec *codec, hda_nid_t pin)
2308 struct hda_gen_spec *spec = codec->spec;
2309 unsigned int defcfg;
2310 struct snd_kcontrol_new *knew;
2313 /* no jack mode for fixed pins */
2314 defcfg = snd_hda_codec_get_pincfg(codec, pin);
2315 if (snd_hda_get_input_pin_attr(defcfg) == INPUT_PIN_ATTR_INT)
2318 /* no multiple vref caps? */
2319 if (hweight32(get_vref_caps(codec, pin)) <= 1)
2322 get_jack_mode_name(codec, pin, name, sizeof(name));
2323 knew = snd_hda_gen_add_kctl(spec, name, &in_jack_mode_enum);
2326 knew->private_value = pin;
2336 /* add the powersave loopback-list entry */
2337 static void add_loopback_list(struct hda_gen_spec *spec, hda_nid_t mix, int idx)
2339 struct hda_amp_list *list;
2341 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2343 list = spec->loopback_list + spec->num_loopbacks;
2345 list->dir = HDA_INPUT;
2347 spec->num_loopbacks++;
2348 spec->loopback.amplist = spec->loopback_list;
2351 #define add_loopback_list(spec, mix, idx) /* NOP */
2354 /* create input playback/capture controls for the given pin */
2355 static int new_analog_input(struct hda_codec *codec, int input_idx,
2356 hda_nid_t pin, const char *ctlname, int ctlidx,
2359 struct hda_gen_spec *spec = codec->spec;
2360 struct nid_path *path;
2364 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2365 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2366 return 0; /* no need for analog loopback */
2368 path = snd_hda_add_new_path(codec, pin, mix_nid, 0);
2371 print_nid_path("loopback", path);
2372 spec->loopback_paths[input_idx] = snd_hda_get_path_idx(codec, path);
2374 idx = path->idx[path->depth - 1];
2375 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
2376 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2377 err = __add_pb_vol_ctrl(spec, HDA_CTL_WIDGET_VOL, ctlname, ctlidx, val);
2380 path->ctls[NID_PATH_VOL_CTL] = val;
2383 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
2384 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2385 err = __add_pb_sw_ctrl(spec, HDA_CTL_WIDGET_MUTE, ctlname, ctlidx, val);
2388 path->ctls[NID_PATH_MUTE_CTL] = val;
2391 path->active = true;
2392 add_loopback_list(spec, mix_nid, idx);
2396 static int is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2398 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2399 return (pincap & AC_PINCAP_IN) != 0;
2402 /* Parse the codec tree and retrieve ADCs */
2403 static int fill_adc_nids(struct hda_codec *codec)
2405 struct hda_gen_spec *spec = codec->spec;
2407 hda_nid_t *adc_nids = spec->adc_nids;
2408 int max_nums = ARRAY_SIZE(spec->adc_nids);
2411 nid = codec->start_nid;
2412 for (i = 0; i < codec->num_nodes; i++, nid++) {
2413 unsigned int caps = get_wcaps(codec, nid);
2414 int type = get_wcaps_type(caps);
2416 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2418 adc_nids[nums] = nid;
2419 if (++nums >= max_nums)
2422 spec->num_adc_nids = nums;
2424 /* copy the detected ADCs to all_adcs[] */
2425 spec->num_all_adcs = nums;
2426 memcpy(spec->all_adcs, spec->adc_nids, nums * sizeof(hda_nid_t));
2431 /* filter out invalid adc_nids that don't give all active input pins;
2432 * if needed, check whether dynamic ADC-switching is available
2434 static int check_dyn_adc_switch(struct hda_codec *codec)
2436 struct hda_gen_spec *spec = codec->spec;
2437 struct hda_input_mux *imux = &spec->input_mux;
2438 unsigned int ok_bits;
2444 for (n = 0; n < spec->num_adc_nids; n++) {
2445 for (i = 0; i < imux->num_items; i++) {
2446 if (!spec->input_paths[i][n])
2449 if (i >= imux->num_items) {
2450 ok_bits |= (1 << n);
2456 if (spec->shared_mic_hp) {
2457 spec->shared_mic_hp = 0;
2458 imux->num_items = 1;
2462 /* check whether ADC-switch is possible */
2463 for (i = 0; i < imux->num_items; i++) {
2464 for (n = 0; n < spec->num_adc_nids; n++) {
2465 if (spec->input_paths[i][n]) {
2466 spec->dyn_adc_idx[i] = n;
2472 snd_printdd("hda-codec: enabling ADC switching\n");
2473 spec->dyn_adc_switch = 1;
2474 } else if (nums != spec->num_adc_nids) {
2475 /* shrink the invalid adcs and input paths */
2477 for (n = 0; n < spec->num_adc_nids; n++) {
2478 if (!(ok_bits & (1 << n)))
2481 spec->adc_nids[nums] = spec->adc_nids[n];
2482 for (i = 0; i < imux->num_items; i++) {
2483 invalidate_nid_path(codec,
2484 spec->input_paths[i][nums]);
2485 spec->input_paths[i][nums] =
2486 spec->input_paths[i][n];
2491 spec->num_adc_nids = nums;
2494 if (imux->num_items == 1 || spec->shared_mic_hp) {
2495 snd_printdd("hda-codec: reducing to a single ADC\n");
2496 spec->num_adc_nids = 1; /* reduce to a single ADC */
2499 /* single index for individual volumes ctls */
2500 if (!spec->dyn_adc_switch && spec->multi_cap_vol)
2501 spec->num_adc_nids = 1;
2506 /* parse capture source paths from the given pin and create imux items */
2507 static int parse_capture_source(struct hda_codec *codec, hda_nid_t pin,
2508 int cfg_idx, int num_adcs,
2509 const char *label, int anchor)
2511 struct hda_gen_spec *spec = codec->spec;
2512 struct hda_input_mux *imux = &spec->input_mux;
2513 int imux_idx = imux->num_items;
2514 bool imux_added = false;
2517 for (c = 0; c < num_adcs; c++) {
2518 struct nid_path *path;
2519 hda_nid_t adc = spec->adc_nids[c];
2521 if (!is_reachable_path(codec, pin, adc))
2523 path = snd_hda_add_new_path(codec, pin, adc, anchor);
2526 print_nid_path("input", path);
2527 spec->input_paths[imux_idx][c] =
2528 snd_hda_get_path_idx(codec, path);
2531 spec->imux_pins[imux->num_items] = pin;
2532 snd_hda_add_imux_item(imux, label, cfg_idx, NULL);
2541 * create playback/capture controls for input pins
2544 /* fill the label for each input at first */
2545 static int fill_input_pin_labels(struct hda_codec *codec)
2547 struct hda_gen_spec *spec = codec->spec;
2548 const struct auto_pin_cfg *cfg = &spec->autocfg;
2551 for (i = 0; i < cfg->num_inputs; i++) {
2552 hda_nid_t pin = cfg->inputs[i].pin;
2556 if (!is_input_pin(codec, pin))
2559 label = hda_get_autocfg_input_label(codec, cfg, i);
2561 for (j = i - 1; j >= 0; j--) {
2562 if (spec->input_labels[j] &&
2563 !strcmp(spec->input_labels[j], label)) {
2564 idx = spec->input_label_idxs[j] + 1;
2569 spec->input_labels[i] = label;
2570 spec->input_label_idxs[i] = idx;
2576 #define CFG_IDX_MIX 99 /* a dummy cfg->input idx for stereo mix */
2578 static int create_input_ctls(struct hda_codec *codec)
2580 struct hda_gen_spec *spec = codec->spec;
2581 const struct auto_pin_cfg *cfg = &spec->autocfg;
2582 hda_nid_t mixer = spec->mixer_nid;
2587 num_adcs = fill_adc_nids(codec);
2591 err = fill_input_pin_labels(codec);
2595 for (i = 0; i < cfg->num_inputs; i++) {
2598 pin = cfg->inputs[i].pin;
2599 if (!is_input_pin(codec, pin))
2603 if (cfg->inputs[i].type == AUTO_PIN_MIC)
2604 val |= snd_hda_get_default_vref(codec, pin);
2605 set_pin_target(codec, pin, val, false);
2608 if (is_reachable_path(codec, pin, mixer)) {
2609 err = new_analog_input(codec, i, pin,
2610 spec->input_labels[i],
2611 spec->input_label_idxs[i],
2618 err = parse_capture_source(codec, pin, i, num_adcs,
2619 spec->input_labels[i], -mixer);
2623 if (spec->add_in_jack_modes) {
2624 err = create_in_jack_mode(codec, pin);
2630 if (mixer && spec->add_stereo_mix_input) {
2631 err = parse_capture_source(codec, mixer, CFG_IDX_MIX, num_adcs,
2645 /* get the input path specified by the given adc and imux indices */
2646 static struct nid_path *get_input_path(struct hda_codec *codec, int adc_idx, int imux_idx)
2648 struct hda_gen_spec *spec = codec->spec;
2649 if (imux_idx < 0 || imux_idx >= HDA_MAX_NUM_INPUTS) {
2653 if (spec->dyn_adc_switch)
2654 adc_idx = spec->dyn_adc_idx[imux_idx];
2655 if (adc_idx < 0 || adc_idx >= AUTO_CFG_MAX_INS) {
2659 return snd_hda_get_path_from_idx(codec, spec->input_paths[imux_idx][adc_idx]);
2662 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
2665 static int mux_enum_info(struct snd_kcontrol *kcontrol,
2666 struct snd_ctl_elem_info *uinfo)
2668 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2669 struct hda_gen_spec *spec = codec->spec;
2670 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
2673 static int mux_enum_get(struct snd_kcontrol *kcontrol,
2674 struct snd_ctl_elem_value *ucontrol)
2676 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2677 struct hda_gen_spec *spec = codec->spec;
2678 unsigned int adc_idx = kcontrol->id.index;
2680 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
2684 static int mux_enum_put(struct snd_kcontrol *kcontrol,
2685 struct snd_ctl_elem_value *ucontrol)
2687 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2688 unsigned int adc_idx = kcontrol->id.index;
2689 return mux_select(codec, adc_idx,
2690 ucontrol->value.enumerated.item[0]);
2693 static const struct snd_kcontrol_new cap_src_temp = {
2694 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2695 .name = "Input Source",
2696 .info = mux_enum_info,
2697 .get = mux_enum_get,
2698 .put = mux_enum_put,
2702 * capture volume and capture switch ctls
2705 typedef int (*put_call_t)(struct snd_kcontrol *kcontrol,
2706 struct snd_ctl_elem_value *ucontrol);
2708 /* call the given amp update function for all amps in the imux list at once */
2709 static int cap_put_caller(struct snd_kcontrol *kcontrol,
2710 struct snd_ctl_elem_value *ucontrol,
2711 put_call_t func, int type)
2713 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2714 struct hda_gen_spec *spec = codec->spec;
2715 const struct hda_input_mux *imux;
2716 struct nid_path *path;
2717 int i, adc_idx, err = 0;
2719 imux = &spec->input_mux;
2720 adc_idx = kcontrol->id.index;
2721 mutex_lock(&codec->control_mutex);
2722 /* we use the cache-only update at first since multiple input paths
2723 * may shared the same amp; by updating only caches, the redundant
2724 * writes to hardware can be reduced.
2726 codec->cached_write = 1;
2727 for (i = 0; i < imux->num_items; i++) {
2728 path = get_input_path(codec, adc_idx, i);
2729 if (!path || !path->ctls[type])
2731 kcontrol->private_value = path->ctls[type];
2732 err = func(kcontrol, ucontrol);
2737 codec->cached_write = 0;
2738 mutex_unlock(&codec->control_mutex);
2739 snd_hda_codec_flush_amp_cache(codec); /* flush the updates */
2740 if (err >= 0 && spec->cap_sync_hook)
2741 spec->cap_sync_hook(codec, ucontrol);
2745 /* capture volume ctl callbacks */
2746 #define cap_vol_info snd_hda_mixer_amp_volume_info
2747 #define cap_vol_get snd_hda_mixer_amp_volume_get
2748 #define cap_vol_tlv snd_hda_mixer_amp_tlv
2750 static int cap_vol_put(struct snd_kcontrol *kcontrol,
2751 struct snd_ctl_elem_value *ucontrol)
2753 return cap_put_caller(kcontrol, ucontrol,
2754 snd_hda_mixer_amp_volume_put,
2758 static const struct snd_kcontrol_new cap_vol_temp = {
2759 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2760 .name = "Capture Volume",
2761 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
2762 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2763 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
2764 .info = cap_vol_info,
2767 .tlv = { .c = cap_vol_tlv },
2770 /* capture switch ctl callbacks */
2771 #define cap_sw_info snd_ctl_boolean_stereo_info
2772 #define cap_sw_get snd_hda_mixer_amp_switch_get
2774 static int cap_sw_put(struct snd_kcontrol *kcontrol,
2775 struct snd_ctl_elem_value *ucontrol)
2777 return cap_put_caller(kcontrol, ucontrol,
2778 snd_hda_mixer_amp_switch_put,
2782 static const struct snd_kcontrol_new cap_sw_temp = {
2783 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2784 .name = "Capture Switch",
2785 .info = cap_sw_info,
2790 static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
2795 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
2796 for (depth = 0; depth < 3; depth++) {
2797 if (depth >= path->depth)
2799 i = path->depth - depth - 1;
2800 nid = path->path[i];
2801 if (!path->ctls[NID_PATH_VOL_CTL]) {
2802 if (nid_has_volume(codec, nid, HDA_OUTPUT))
2803 path->ctls[NID_PATH_VOL_CTL] =
2804 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2805 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
2806 int idx = path->idx[i];
2807 if (!depth && codec->single_adc_amp)
2809 path->ctls[NID_PATH_VOL_CTL] =
2810 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2813 if (!path->ctls[NID_PATH_MUTE_CTL]) {
2814 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2815 path->ctls[NID_PATH_MUTE_CTL] =
2816 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2817 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
2818 int idx = path->idx[i];
2819 if (!depth && codec->single_adc_amp)
2821 path->ctls[NID_PATH_MUTE_CTL] =
2822 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2829 static bool is_inv_dmic_pin(struct hda_codec *codec, hda_nid_t nid)
2831 struct hda_gen_spec *spec = codec->spec;
2832 struct auto_pin_cfg *cfg = &spec->autocfg;
2836 if (!spec->inv_dmic_split)
2838 for (i = 0; i < cfg->num_inputs; i++) {
2839 if (cfg->inputs[i].pin != nid)
2841 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2843 val = snd_hda_codec_get_pincfg(codec, nid);
2844 return snd_hda_get_input_pin_attr(val) == INPUT_PIN_ATTR_INT;
2849 /* capture switch put callback for a single control with hook call */
2850 static int cap_single_sw_put(struct snd_kcontrol *kcontrol,
2851 struct snd_ctl_elem_value *ucontrol)
2853 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2854 struct hda_gen_spec *spec = codec->spec;
2857 ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
2861 if (spec->cap_sync_hook)
2862 spec->cap_sync_hook(codec, ucontrol);
2867 static int add_single_cap_ctl(struct hda_codec *codec, const char *label,
2868 int idx, bool is_switch, unsigned int ctl,
2871 struct hda_gen_spec *spec = codec->spec;
2873 int type = is_switch ? HDA_CTL_WIDGET_MUTE : HDA_CTL_WIDGET_VOL;
2874 const char *sfx = is_switch ? "Switch" : "Volume";
2875 unsigned int chs = inv_dmic ? 1 : 3;
2876 struct snd_kcontrol_new *knew;
2882 snprintf(tmpname, sizeof(tmpname),
2883 "%s Capture %s", label, sfx);
2885 snprintf(tmpname, sizeof(tmpname),
2887 knew = add_control(spec, type, tmpname, idx,
2888 amp_val_replace_channels(ctl, chs));
2892 knew->put = cap_single_sw_put;
2896 /* Make independent right kcontrol */
2898 snprintf(tmpname, sizeof(tmpname),
2899 "Inverted %s Capture %s", label, sfx);
2901 snprintf(tmpname, sizeof(tmpname),
2902 "Inverted Capture %s", sfx);
2903 knew = add_control(spec, type, tmpname, idx,
2904 amp_val_replace_channels(ctl, 2));
2908 knew->put = cap_single_sw_put;
2912 /* create single (and simple) capture volume and switch controls */
2913 static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx,
2914 unsigned int vol_ctl, unsigned int sw_ctl,
2918 err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl, inv_dmic);
2921 err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl, inv_dmic);
2927 /* create bound capture volume and switch controls */
2928 static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx,
2929 unsigned int vol_ctl, unsigned int sw_ctl)
2931 struct hda_gen_spec *spec = codec->spec;
2932 struct snd_kcontrol_new *knew;
2935 knew = snd_hda_gen_add_kctl(spec, NULL, &cap_vol_temp);
2939 knew->private_value = vol_ctl;
2940 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2943 knew = snd_hda_gen_add_kctl(spec, NULL, &cap_sw_temp);
2947 knew->private_value = sw_ctl;
2948 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2953 /* return the vol ctl when used first in the imux list */
2954 static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type)
2956 struct nid_path *path;
2960 path = get_input_path(codec, 0, idx);
2963 ctl = path->ctls[type];
2966 for (i = 0; i < idx - 1; i++) {
2967 path = get_input_path(codec, 0, i);
2968 if (path && path->ctls[type] == ctl)
2974 /* create individual capture volume and switch controls per input */
2975 static int create_multi_cap_vol_ctl(struct hda_codec *codec)
2977 struct hda_gen_spec *spec = codec->spec;
2978 struct hda_input_mux *imux = &spec->input_mux;
2981 for (i = 0; i < imux->num_items; i++) {
2985 idx = imux->items[i].index;
2986 if (idx >= spec->autocfg.num_inputs)
2988 inv_dmic = is_inv_dmic_pin(codec, spec->imux_pins[i]);
2990 for (type = 0; type < 2; type++) {
2991 err = add_single_cap_ctl(codec,
2992 spec->input_labels[idx],
2993 spec->input_label_idxs[idx],
2995 get_first_cap_ctl(codec, i, type),
3004 static int create_capture_mixers(struct hda_codec *codec)
3006 struct hda_gen_spec *spec = codec->spec;
3007 struct hda_input_mux *imux = &spec->input_mux;
3008 int i, n, nums, err;
3010 if (spec->dyn_adc_switch)
3013 nums = spec->num_adc_nids;
3015 if (!spec->auto_mic && imux->num_items > 1) {
3016 struct snd_kcontrol_new *knew;
3018 name = nums > 1 ? "Input Source" : "Capture Source";
3019 knew = snd_hda_gen_add_kctl(spec, name, &cap_src_temp);
3025 for (n = 0; n < nums; n++) {
3027 bool multi_cap_vol = spec->multi_cap_vol;
3028 bool inv_dmic = false;
3032 for (i = 0; i < imux->num_items; i++) {
3033 struct nid_path *path;
3034 path = get_input_path(codec, n, i);
3037 parse_capvol_in_path(codec, path);
3039 vol = path->ctls[NID_PATH_VOL_CTL];
3040 else if (vol != path->ctls[NID_PATH_VOL_CTL]) {
3042 if (!same_amp_caps(codec, vol,
3043 path->ctls[NID_PATH_VOL_CTL], HDA_INPUT))
3044 multi_cap_vol = true;
3047 sw = path->ctls[NID_PATH_MUTE_CTL];
3048 else if (sw != path->ctls[NID_PATH_MUTE_CTL]) {
3050 if (!same_amp_caps(codec, sw,
3051 path->ctls[NID_PATH_MUTE_CTL], HDA_INPUT))
3052 multi_cap_vol = true;
3054 if (is_inv_dmic_pin(codec, spec->imux_pins[i]))
3059 err = create_single_cap_vol_ctl(codec, n, vol, sw,
3061 else if (!multi_cap_vol)
3062 err = create_bind_cap_vol_ctl(codec, n, vol, sw);
3064 err = create_multi_cap_vol_ctl(codec);
3073 * add mic boosts if needed
3076 /* check whether the given amp is feasible as a boost volume */
3077 static bool check_boost_vol(struct hda_codec *codec, hda_nid_t nid,
3082 if (!nid_has_volume(codec, nid, dir) ||
3083 is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
3084 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
3087 step = (query_amp_caps(codec, nid, dir) & AC_AMPCAP_STEP_SIZE)
3088 >> AC_AMPCAP_STEP_SIZE_SHIFT;
3094 /* look for a boost amp in a widget close to the pin */
3095 static unsigned int look_for_boost_amp(struct hda_codec *codec,
3096 struct nid_path *path)
3098 unsigned int val = 0;
3102 for (depth = 0; depth < 3; depth++) {
3103 if (depth >= path->depth - 1)
3105 nid = path->path[depth];
3106 if (depth && check_boost_vol(codec, nid, HDA_OUTPUT, 0)) {
3107 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3109 } else if (check_boost_vol(codec, nid, HDA_INPUT,
3110 path->idx[depth])) {
3111 val = HDA_COMPOSE_AMP_VAL(nid, 3, path->idx[depth],
3120 static int parse_mic_boost(struct hda_codec *codec)
3122 struct hda_gen_spec *spec = codec->spec;
3123 struct auto_pin_cfg *cfg = &spec->autocfg;
3124 struct hda_input_mux *imux = &spec->input_mux;
3127 if (!spec->num_adc_nids)
3130 for (i = 0; i < imux->num_items; i++) {
3131 struct nid_path *path;
3134 char boost_label[44];
3136 idx = imux->items[i].index;
3137 if (idx >= imux->num_items)
3140 /* check only line-in and mic pins */
3141 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
3144 path = get_input_path(codec, 0, i);
3148 val = look_for_boost_amp(codec, path);
3152 /* create a boost control */
3153 snprintf(boost_label, sizeof(boost_label),
3154 "%s Boost Volume", spec->input_labels[idx]);
3155 if (!add_control(spec, HDA_CTL_WIDGET_VOL, boost_label,
3156 spec->input_label_idxs[idx], val))
3159 path->ctls[NID_PATH_BOOST_CTL] = val;
3165 * parse digital I/Os and set up NIDs in BIOS auto-parse mode
3167 static void parse_digital(struct hda_codec *codec)
3169 struct hda_gen_spec *spec = codec->spec;
3170 struct nid_path *path;
3172 hda_nid_t dig_nid, pin;
3174 /* support multiple SPDIFs; the secondary is set up as a slave */
3176 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3177 pin = spec->autocfg.dig_out_pins[i];
3178 dig_nid = look_for_dac(codec, pin, true);
3181 path = snd_hda_add_new_path(codec, dig_nid, pin, 0);
3184 print_nid_path("digout", path);
3185 path->active = true;
3186 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
3187 set_pin_target(codec, pin, PIN_OUT, false);
3189 spec->multiout.dig_out_nid = dig_nid;
3190 spec->dig_out_type = spec->autocfg.dig_out_type[0];
3192 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
3193 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
3195 spec->slave_dig_outs[nums - 1] = dig_nid;
3200 if (spec->autocfg.dig_in_pin) {
3201 pin = spec->autocfg.dig_in_pin;
3202 dig_nid = codec->start_nid;
3203 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3204 unsigned int wcaps = get_wcaps(codec, dig_nid);
3205 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3207 if (!(wcaps & AC_WCAP_DIGITAL))
3209 path = snd_hda_add_new_path(codec, pin, dig_nid, 0);
3211 print_nid_path("digin", path);
3212 path->active = true;
3213 spec->dig_in_nid = dig_nid;
3214 spec->digin_path = snd_hda_get_path_idx(codec, path);
3215 set_pin_target(codec, pin, PIN_IN, false);
3224 * input MUX handling
3227 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur);
3229 /* select the given imux item; either unmute exclusively or select the route */
3230 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3233 struct hda_gen_spec *spec = codec->spec;
3234 const struct hda_input_mux *imux;
3235 struct nid_path *path;
3237 imux = &spec->input_mux;
3238 if (!imux->num_items)
3241 if (idx >= imux->num_items)
3242 idx = imux->num_items - 1;
3243 if (spec->cur_mux[adc_idx] == idx)
3246 path = get_input_path(codec, adc_idx, spec->cur_mux[adc_idx]);
3250 snd_hda_activate_path(codec, path, false, false);
3252 spec->cur_mux[adc_idx] = idx;
3254 if (spec->shared_mic_hp)
3255 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
3257 if (spec->dyn_adc_switch)
3258 dyn_adc_pcm_resetup(codec, idx);
3260 path = get_input_path(codec, adc_idx, idx);
3265 snd_hda_activate_path(codec, path, true, false);
3266 if (spec->cap_sync_hook)
3267 spec->cap_sync_hook(codec, NULL);
3273 * Jack detections for HP auto-mute and mic-switch
3276 /* check each pin in the given array; returns true if any of them is plugged */
3277 static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3281 for (i = 0; i < num_pins; i++) {
3282 hda_nid_t nid = pins[i];
3285 /* don't detect pins retasked as inputs */
3286 if (snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_IN_EN)
3288 present |= snd_hda_jack_detect(codec, nid);
3293 /* standard HP/line-out auto-mute helper */
3294 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
3297 struct hda_gen_spec *spec = codec->spec;
3300 for (i = 0; i < num_pins; i++) {
3301 hda_nid_t nid = pins[i];
3305 /* don't reset VREF value in case it's controlling
3306 * the amp (see alc861_fixup_asus_amp_vref_0f())
3308 if (spec->keep_vref_in_automute)
3309 val = snd_hda_codec_get_pin_target(codec, nid) & ~PIN_HP;
3313 val |= snd_hda_codec_get_pin_target(codec, nid);
3314 /* here we call update_pin_ctl() so that the pinctl is changed
3315 * without changing the pinctl target value;
3316 * the original target value will be still referred at the
3317 * init / resume again
3319 update_pin_ctl(codec, nid, val);
3320 set_pin_eapd(codec, nid, !mute);
3324 /* Toggle outputs muting */
3325 void snd_hda_gen_update_outputs(struct hda_codec *codec)
3327 struct hda_gen_spec *spec = codec->spec;
3330 /* Control HP pins/amps depending on master_mute state;
3331 * in general, HP pins/amps control should be enabled in all cases,
3332 * but currently set only for master_mute, just to be safe
3334 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
3335 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
3336 spec->autocfg.hp_pins, spec->master_mute);
3338 if (!spec->automute_speaker)
3341 on = spec->hp_jack_present | spec->line_jack_present;
3342 on |= spec->master_mute;
3343 spec->speaker_muted = on;
3344 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
3345 spec->autocfg.speaker_pins, on);
3347 /* toggle line-out mutes if needed, too */
3348 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3349 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
3350 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
3352 if (!spec->automute_lo)
3355 on = spec->hp_jack_present;
3356 on |= spec->master_mute;
3357 spec->line_out_muted = on;
3358 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
3359 spec->autocfg.line_out_pins, on);
3361 EXPORT_SYMBOL_HDA(snd_hda_gen_update_outputs);
3363 static void call_update_outputs(struct hda_codec *codec)
3365 struct hda_gen_spec *spec = codec->spec;
3366 if (spec->automute_hook)
3367 spec->automute_hook(codec);
3369 snd_hda_gen_update_outputs(codec);
3372 /* standard HP-automute helper */
3373 void snd_hda_gen_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
3375 struct hda_gen_spec *spec = codec->spec;
3377 spec->hp_jack_present =
3378 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
3379 spec->autocfg.hp_pins);
3380 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
3382 call_update_outputs(codec);
3384 EXPORT_SYMBOL_HDA(snd_hda_gen_hp_automute);
3386 /* standard line-out-automute helper */
3387 void snd_hda_gen_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
3389 struct hda_gen_spec *spec = codec->spec;
3391 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3393 /* check LO jack only when it's different from HP */
3394 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
3397 spec->line_jack_present =
3398 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
3399 spec->autocfg.line_out_pins);
3400 if (!spec->automute_speaker || !spec->detect_lo)
3402 call_update_outputs(codec);
3404 EXPORT_SYMBOL_HDA(snd_hda_gen_line_automute);
3406 /* standard mic auto-switch helper */
3407 void snd_hda_gen_mic_autoswitch(struct hda_codec *codec, struct hda_jack_tbl *jack)
3409 struct hda_gen_spec *spec = codec->spec;
3412 if (!spec->auto_mic)
3415 for (i = spec->am_num_entries - 1; i > 0; i--) {
3416 hda_nid_t pin = spec->am_entry[i].pin;
3417 /* don't detect pins retasked as outputs */
3418 if (snd_hda_codec_get_pin_target(codec, pin) & AC_PINCTL_OUT_EN)
3420 if (snd_hda_jack_detect(codec, pin)) {
3421 mux_select(codec, 0, spec->am_entry[i].idx);
3425 mux_select(codec, 0, spec->am_entry[0].idx);
3427 EXPORT_SYMBOL_HDA(snd_hda_gen_mic_autoswitch);
3429 /* update jack retasking */
3430 static void update_automute_all(struct hda_codec *codec)
3432 struct hda_gen_spec *spec = codec->spec;
3434 if (spec->hp_automute_hook)
3435 spec->hp_automute_hook(codec, NULL);
3437 snd_hda_gen_hp_automute(codec, NULL);
3438 if (spec->line_automute_hook)
3439 spec->line_automute_hook(codec, NULL);
3441 snd_hda_gen_line_automute(codec, NULL);
3442 if (spec->mic_autoswitch_hook)
3443 spec->mic_autoswitch_hook(codec, NULL);
3445 snd_hda_gen_mic_autoswitch(codec, NULL);
3449 * Auto-Mute mode mixer enum support
3451 static int automute_mode_info(struct snd_kcontrol *kcontrol,
3452 struct snd_ctl_elem_info *uinfo)
3454 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3455 struct hda_gen_spec *spec = codec->spec;
3456 static const char * const texts3[] = {
3457 "Disabled", "Speaker Only", "Line Out+Speaker"
3460 if (spec->automute_speaker_possible && spec->automute_lo_possible)
3461 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
3462 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
3465 static int automute_mode_get(struct snd_kcontrol *kcontrol,
3466 struct snd_ctl_elem_value *ucontrol)
3468 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3469 struct hda_gen_spec *spec = codec->spec;
3470 unsigned int val = 0;
3471 if (spec->automute_speaker)
3473 if (spec->automute_lo)
3476 ucontrol->value.enumerated.item[0] = val;
3480 static int automute_mode_put(struct snd_kcontrol *kcontrol,
3481 struct snd_ctl_elem_value *ucontrol)
3483 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3484 struct hda_gen_spec *spec = codec->spec;
3486 switch (ucontrol->value.enumerated.item[0]) {
3488 if (!spec->automute_speaker && !spec->automute_lo)
3490 spec->automute_speaker = 0;
3491 spec->automute_lo = 0;
3494 if (spec->automute_speaker_possible) {
3495 if (!spec->automute_lo && spec->automute_speaker)
3497 spec->automute_speaker = 1;
3498 spec->automute_lo = 0;
3499 } else if (spec->automute_lo_possible) {
3500 if (spec->automute_lo)
3502 spec->automute_lo = 1;
3507 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
3509 if (spec->automute_speaker && spec->automute_lo)
3511 spec->automute_speaker = 1;
3512 spec->automute_lo = 1;
3517 call_update_outputs(codec);
3521 static const struct snd_kcontrol_new automute_mode_enum = {
3522 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3523 .name = "Auto-Mute Mode",
3524 .info = automute_mode_info,
3525 .get = automute_mode_get,
3526 .put = automute_mode_put,
3529 static int add_automute_mode_enum(struct hda_codec *codec)
3531 struct hda_gen_spec *spec = codec->spec;
3533 if (!snd_hda_gen_add_kctl(spec, NULL, &automute_mode_enum))
3539 * Check the availability of HP/line-out auto-mute;
3540 * Set up appropriately if really supported
3542 static int check_auto_mute_availability(struct hda_codec *codec)
3544 struct hda_gen_spec *spec = codec->spec;
3545 struct auto_pin_cfg *cfg = &spec->autocfg;
3549 if (spec->suppress_auto_mute)
3552 if (cfg->hp_pins[0])
3554 if (cfg->line_out_pins[0])
3556 if (cfg->speaker_pins[0])
3558 if (present < 2) /* need two different output types */
3561 if (!cfg->speaker_pins[0] &&
3562 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3563 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3564 sizeof(cfg->speaker_pins));
3565 cfg->speaker_outs = cfg->line_outs;
3568 if (!cfg->hp_pins[0] &&
3569 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3570 memcpy(cfg->hp_pins, cfg->line_out_pins,
3571 sizeof(cfg->hp_pins));
3572 cfg->hp_outs = cfg->line_outs;
3575 for (i = 0; i < cfg->hp_outs; i++) {
3576 hda_nid_t nid = cfg->hp_pins[i];
3577 if (!is_jack_detectable(codec, nid))
3579 snd_printdd("hda-codec: Enable HP auto-muting on NID 0x%x\n",
3581 snd_hda_jack_detect_enable_callback(codec, nid, HDA_GEN_HP_EVENT,
3582 spec->hp_automute_hook ?
3583 spec->hp_automute_hook :
3584 snd_hda_gen_hp_automute);
3585 spec->detect_hp = 1;
3588 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
3589 if (cfg->speaker_outs)
3590 for (i = 0; i < cfg->line_outs; i++) {
3591 hda_nid_t nid = cfg->line_out_pins[i];
3592 if (!is_jack_detectable(codec, nid))
3594 snd_printdd("hda-codec: Enable Line-Out auto-muting on NID 0x%x\n", nid);
3595 snd_hda_jack_detect_enable_callback(codec, nid,
3596 HDA_GEN_FRONT_EVENT,
3597 spec->line_automute_hook ?
3598 spec->line_automute_hook :
3599 snd_hda_gen_line_automute);
3600 spec->detect_lo = 1;
3602 spec->automute_lo_possible = spec->detect_hp;
3605 spec->automute_speaker_possible = cfg->speaker_outs &&
3606 (spec->detect_hp || spec->detect_lo);
3608 spec->automute_lo = spec->automute_lo_possible;
3609 spec->automute_speaker = spec->automute_speaker_possible;
3611 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
3612 /* create a control for automute mode */
3613 err = add_automute_mode_enum(codec);
3620 /* check whether all auto-mic pins are valid; setup indices if OK */
3621 static bool auto_mic_check_imux(struct hda_codec *codec)
3623 struct hda_gen_spec *spec = codec->spec;
3624 const struct hda_input_mux *imux;
3627 imux = &spec->input_mux;
3628 for (i = 0; i < spec->am_num_entries; i++) {
3629 spec->am_entry[i].idx =
3630 find_idx_in_nid_list(spec->am_entry[i].pin,
3631 spec->imux_pins, imux->num_items);
3632 if (spec->am_entry[i].idx < 0)
3633 return false; /* no corresponding imux */
3636 /* we don't need the jack detection for the first pin */
3637 for (i = 1; i < spec->am_num_entries; i++)
3638 snd_hda_jack_detect_enable_callback(codec,
3639 spec->am_entry[i].pin,
3641 spec->mic_autoswitch_hook ?
3642 spec->mic_autoswitch_hook :
3643 snd_hda_gen_mic_autoswitch);
3647 static int compare_attr(const void *ap, const void *bp)
3649 const struct automic_entry *a = ap;
3650 const struct automic_entry *b = bp;
3651 return (int)(a->attr - b->attr);
3655 * Check the availability of auto-mic switch;
3656 * Set up if really supported
3658 static int check_auto_mic_availability(struct hda_codec *codec)
3660 struct hda_gen_spec *spec = codec->spec;
3661 struct auto_pin_cfg *cfg = &spec->autocfg;
3665 if (spec->suppress_auto_mic)
3670 for (i = 0; i < cfg->num_inputs; i++) {
3671 hda_nid_t nid = cfg->inputs[i].pin;
3673 attr = snd_hda_codec_get_pincfg(codec, nid);
3674 attr = snd_hda_get_input_pin_attr(attr);
3675 if (types & (1 << attr))
3676 return 0; /* already occupied */
3678 case INPUT_PIN_ATTR_INT:
3679 if (cfg->inputs[i].type != AUTO_PIN_MIC)
3680 return 0; /* invalid type */
3682 case INPUT_PIN_ATTR_UNUSED:
3683 return 0; /* invalid entry */
3685 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
3686 return 0; /* invalid type */
3687 if (!spec->line_in_auto_switch &&
3688 cfg->inputs[i].type != AUTO_PIN_MIC)
3689 return 0; /* only mic is allowed */
3690 if (!is_jack_detectable(codec, nid))
3691 return 0; /* no unsol support */
3694 if (num_pins >= MAX_AUTO_MIC_PINS)
3696 types |= (1 << attr);
3697 spec->am_entry[num_pins].pin = nid;
3698 spec->am_entry[num_pins].attr = attr;
3705 spec->am_num_entries = num_pins;
3706 /* sort the am_entry in the order of attr so that the pin with a
3707 * higher attr will be selected when the jack is plugged.
3709 sort(spec->am_entry, num_pins, sizeof(spec->am_entry[0]),
3710 compare_attr, NULL);
3712 if (!auto_mic_check_imux(codec))
3716 spec->num_adc_nids = 1;
3717 spec->cur_mux[0] = spec->am_entry[0].idx;
3718 snd_printdd("hda-codec: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
3719 spec->am_entry[0].pin,
3720 spec->am_entry[1].pin,
3721 spec->am_entry[2].pin);
3728 * Parse the given BIOS configuration and set up the hda_gen_spec
3730 * return 1 if successful, 0 if the proper config is not found,
3731 * or a negative error code
3733 int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
3734 struct auto_pin_cfg *cfg)
3736 struct hda_gen_spec *spec = codec->spec;
3739 parse_user_hints(codec);
3741 if (cfg != &spec->autocfg) {
3742 spec->autocfg = *cfg;
3743 cfg = &spec->autocfg;
3746 fill_all_dac_nids(codec);
3748 if (!cfg->line_outs) {
3749 if (cfg->dig_outs || cfg->dig_in_pin) {
3750 spec->multiout.max_channels = 2;
3751 spec->no_analog = 1;
3754 return 0; /* can't find valid BIOS pin config */
3757 if (!spec->no_primary_hp &&
3758 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3759 cfg->line_outs <= cfg->hp_outs) {
3760 /* use HP as primary out */
3761 cfg->speaker_outs = cfg->line_outs;
3762 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3763 sizeof(cfg->speaker_pins));
3764 cfg->line_outs = cfg->hp_outs;
3765 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3767 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3768 cfg->line_out_type = AUTO_PIN_HP_OUT;
3771 err = parse_output_paths(codec);
3774 err = create_multi_channel_mode(codec);
3777 err = create_multi_out_ctls(codec, cfg);
3780 err = create_hp_out_ctls(codec);
3783 err = create_speaker_out_ctls(codec);
3786 err = create_indep_hp_ctls(codec);
3789 err = create_loopback_mixing_ctl(codec);
3792 err = create_shared_input(codec);
3795 err = create_input_ctls(codec);
3799 spec->const_channel_count = spec->ext_channel_count;
3800 /* check the multiple speaker and headphone pins */
3801 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
3802 spec->const_channel_count = max(spec->const_channel_count,
3803 cfg->speaker_outs * 2);
3804 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3805 spec->const_channel_count = max(spec->const_channel_count,
3807 spec->multiout.max_channels = max(spec->ext_channel_count,
3808 spec->const_channel_count);
3810 err = check_auto_mute_availability(codec);
3814 err = check_dyn_adc_switch(codec);
3818 if (!spec->shared_mic_hp) {
3819 err = check_auto_mic_availability(codec);
3824 err = create_capture_mixers(codec);
3828 err = parse_mic_boost(codec);
3832 if (spec->add_out_jack_modes) {
3833 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3834 err = create_out_jack_modes(codec, cfg->line_outs,
3835 cfg->line_out_pins);
3839 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
3840 err = create_out_jack_modes(codec, cfg->hp_outs,
3848 parse_digital(codec);
3852 EXPORT_SYMBOL_HDA(snd_hda_gen_parse_auto_config);
3856 * Build control elements
3859 /* slave controls for virtual master */
3860 static const char * const slave_pfxs[] = {
3861 "Front", "Surround", "Center", "LFE", "Side",
3862 "Headphone", "Speaker", "Mono", "Line Out",
3863 "CLFE", "Bass Speaker", "PCM",
3864 "Speaker Front", "Speaker Surround", "Speaker CLFE", "Speaker Side",
3865 "Headphone Front", "Headphone Surround", "Headphone CLFE",
3870 int snd_hda_gen_build_controls(struct hda_codec *codec)
3872 struct hda_gen_spec *spec = codec->spec;
3875 if (spec->kctls.used) {
3876 err = snd_hda_add_new_ctls(codec, spec->kctls.list);
3881 if (spec->multiout.dig_out_nid) {
3882 err = snd_hda_create_dig_out_ctls(codec,
3883 spec->multiout.dig_out_nid,
3884 spec->multiout.dig_out_nid,
3885 spec->pcm_rec[1].pcm_type);
3888 if (!spec->no_analog) {
3889 err = snd_hda_create_spdif_share_sw(codec,
3893 spec->multiout.share_spdif = 1;
3896 if (spec->dig_in_nid) {
3897 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
3902 /* if we have no master control, let's create it */
3903 if (!spec->no_analog &&
3904 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
3905 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
3906 spec->vmaster_tlv, slave_pfxs,
3911 if (!spec->no_analog &&
3912 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
3913 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
3916 true, &spec->vmaster_mute.sw_kctl);
3919 if (spec->vmaster_mute.hook)
3920 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
3921 spec->vmaster_mute_enum);
3924 free_kctls(spec); /* no longer needed */
3926 if (spec->shared_mic_hp) {
3928 int nid = spec->autocfg.inputs[1].pin;
3929 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
3932 err = snd_hda_jack_detect_enable(codec, nid, 0);
3937 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
3943 EXPORT_SYMBOL_HDA(snd_hda_gen_build_controls);
3950 static void call_pcm_playback_hook(struct hda_pcm_stream *hinfo,
3951 struct hda_codec *codec,
3952 struct snd_pcm_substream *substream,
3955 struct hda_gen_spec *spec = codec->spec;
3956 if (spec->pcm_playback_hook)
3957 spec->pcm_playback_hook(hinfo, codec, substream, action);
3960 static void call_pcm_capture_hook(struct hda_pcm_stream *hinfo,
3961 struct hda_codec *codec,
3962 struct snd_pcm_substream *substream,
3965 struct hda_gen_spec *spec = codec->spec;
3966 if (spec->pcm_capture_hook)
3967 spec->pcm_capture_hook(hinfo, codec, substream, action);
3971 * Analog playback callbacks
3973 static int playback_pcm_open(struct hda_pcm_stream *hinfo,
3974 struct hda_codec *codec,
3975 struct snd_pcm_substream *substream)
3977 struct hda_gen_spec *spec = codec->spec;
3980 mutex_lock(&spec->pcm_mutex);
3981 err = snd_hda_multi_out_analog_open(codec,
3982 &spec->multiout, substream,
3985 spec->active_streams |= 1 << STREAM_MULTI_OUT;
3986 call_pcm_playback_hook(hinfo, codec, substream,
3987 HDA_GEN_PCM_ACT_OPEN);
3989 mutex_unlock(&spec->pcm_mutex);
3993 static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3994 struct hda_codec *codec,
3995 unsigned int stream_tag,
3996 unsigned int format,
3997 struct snd_pcm_substream *substream)
3999 struct hda_gen_spec *spec = codec->spec;
4002 err = snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
4003 stream_tag, format, substream);
4005 call_pcm_playback_hook(hinfo, codec, substream,
4006 HDA_GEN_PCM_ACT_PREPARE);
4010 static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
4011 struct hda_codec *codec,
4012 struct snd_pcm_substream *substream)
4014 struct hda_gen_spec *spec = codec->spec;
4017 err = snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
4019 call_pcm_playback_hook(hinfo, codec, substream,
4020 HDA_GEN_PCM_ACT_CLEANUP);
4024 static int playback_pcm_close(struct hda_pcm_stream *hinfo,
4025 struct hda_codec *codec,
4026 struct snd_pcm_substream *substream)
4028 struct hda_gen_spec *spec = codec->spec;
4029 mutex_lock(&spec->pcm_mutex);
4030 spec->active_streams &= ~(1 << STREAM_MULTI_OUT);
4031 call_pcm_playback_hook(hinfo, codec, substream,
4032 HDA_GEN_PCM_ACT_CLOSE);
4033 mutex_unlock(&spec->pcm_mutex);
4037 static int capture_pcm_open(struct hda_pcm_stream *hinfo,
4038 struct hda_codec *codec,
4039 struct snd_pcm_substream *substream)
4041 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_OPEN);
4045 static int capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4046 struct hda_codec *codec,
4047 unsigned int stream_tag,
4048 unsigned int format,
4049 struct snd_pcm_substream *substream)
4051 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
4052 call_pcm_capture_hook(hinfo, codec, substream,
4053 HDA_GEN_PCM_ACT_PREPARE);
4057 static int capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4058 struct hda_codec *codec,
4059 struct snd_pcm_substream *substream)
4061 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
4062 call_pcm_capture_hook(hinfo, codec, substream,
4063 HDA_GEN_PCM_ACT_CLEANUP);
4067 static int capture_pcm_close(struct hda_pcm_stream *hinfo,
4068 struct hda_codec *codec,
4069 struct snd_pcm_substream *substream)
4071 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLOSE);
4075 static int alt_playback_pcm_open(struct hda_pcm_stream *hinfo,
4076 struct hda_codec *codec,
4077 struct snd_pcm_substream *substream)
4079 struct hda_gen_spec *spec = codec->spec;
4082 mutex_lock(&spec->pcm_mutex);
4083 if (!spec->indep_hp_enabled)
4086 spec->active_streams |= 1 << STREAM_INDEP_HP;
4087 call_pcm_playback_hook(hinfo, codec, substream,
4088 HDA_GEN_PCM_ACT_OPEN);
4089 mutex_unlock(&spec->pcm_mutex);
4093 static int alt_playback_pcm_close(struct hda_pcm_stream *hinfo,
4094 struct hda_codec *codec,
4095 struct snd_pcm_substream *substream)
4097 struct hda_gen_spec *spec = codec->spec;
4098 mutex_lock(&spec->pcm_mutex);
4099 spec->active_streams &= ~(1 << STREAM_INDEP_HP);
4100 call_pcm_playback_hook(hinfo, codec, substream,
4101 HDA_GEN_PCM_ACT_CLOSE);
4102 mutex_unlock(&spec->pcm_mutex);
4106 static int alt_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4107 struct hda_codec *codec,
4108 unsigned int stream_tag,
4109 unsigned int format,
4110 struct snd_pcm_substream *substream)
4112 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
4113 call_pcm_playback_hook(hinfo, codec, substream,
4114 HDA_GEN_PCM_ACT_PREPARE);
4118 static int alt_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
4119 struct hda_codec *codec,
4120 struct snd_pcm_substream *substream)
4122 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
4123 call_pcm_playback_hook(hinfo, codec, substream,
4124 HDA_GEN_PCM_ACT_CLEANUP);
4131 static int dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
4132 struct hda_codec *codec,
4133 struct snd_pcm_substream *substream)
4135 struct hda_gen_spec *spec = codec->spec;
4136 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
4139 static int dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4140 struct hda_codec *codec,
4141 unsigned int stream_tag,
4142 unsigned int format,
4143 struct snd_pcm_substream *substream)
4145 struct hda_gen_spec *spec = codec->spec;
4146 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
4147 stream_tag, format, substream);
4150 static int dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
4151 struct hda_codec *codec,
4152 struct snd_pcm_substream *substream)
4154 struct hda_gen_spec *spec = codec->spec;
4155 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
4158 static int dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
4159 struct hda_codec *codec,
4160 struct snd_pcm_substream *substream)
4162 struct hda_gen_spec *spec = codec->spec;
4163 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
4169 #define alt_capture_pcm_open capture_pcm_open
4170 #define alt_capture_pcm_close capture_pcm_close
4172 static int alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4173 struct hda_codec *codec,
4174 unsigned int stream_tag,
4175 unsigned int format,
4176 struct snd_pcm_substream *substream)
4178 struct hda_gen_spec *spec = codec->spec;
4180 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
4181 stream_tag, 0, format);
4182 call_pcm_capture_hook(hinfo, codec, substream,
4183 HDA_GEN_PCM_ACT_PREPARE);
4187 static int alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4188 struct hda_codec *codec,
4189 struct snd_pcm_substream *substream)
4191 struct hda_gen_spec *spec = codec->spec;
4193 snd_hda_codec_cleanup_stream(codec,
4194 spec->adc_nids[substream->number + 1]);
4195 call_pcm_capture_hook(hinfo, codec, substream,
4196 HDA_GEN_PCM_ACT_CLEANUP);
4202 static const struct hda_pcm_stream pcm_analog_playback = {
4206 /* NID is set in build_pcms */
4208 .open = playback_pcm_open,
4209 .close = playback_pcm_close,
4210 .prepare = playback_pcm_prepare,
4211 .cleanup = playback_pcm_cleanup
4215 static const struct hda_pcm_stream pcm_analog_capture = {
4219 /* NID is set in build_pcms */
4221 .open = capture_pcm_open,
4222 .close = capture_pcm_close,
4223 .prepare = capture_pcm_prepare,
4224 .cleanup = capture_pcm_cleanup
4228 static const struct hda_pcm_stream pcm_analog_alt_playback = {
4232 /* NID is set in build_pcms */
4234 .open = alt_playback_pcm_open,
4235 .close = alt_playback_pcm_close,
4236 .prepare = alt_playback_pcm_prepare,
4237 .cleanup = alt_playback_pcm_cleanup
4241 static const struct hda_pcm_stream pcm_analog_alt_capture = {
4242 .substreams = 2, /* can be overridden */
4245 /* NID is set in build_pcms */
4247 .open = alt_capture_pcm_open,
4248 .close = alt_capture_pcm_close,
4249 .prepare = alt_capture_pcm_prepare,
4250 .cleanup = alt_capture_pcm_cleanup
4254 static const struct hda_pcm_stream pcm_digital_playback = {
4258 /* NID is set in build_pcms */
4260 .open = dig_playback_pcm_open,
4261 .close = dig_playback_pcm_close,
4262 .prepare = dig_playback_pcm_prepare,
4263 .cleanup = dig_playback_pcm_cleanup
4267 static const struct hda_pcm_stream pcm_digital_capture = {
4271 /* NID is set in build_pcms */
4274 /* Used by build_pcms to flag that a PCM has no playback stream */
4275 static const struct hda_pcm_stream pcm_null_stream = {
4282 * dynamic changing ADC PCM streams
4284 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
4286 struct hda_gen_spec *spec = codec->spec;
4287 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
4289 if (spec->cur_adc && spec->cur_adc != new_adc) {
4290 /* stream is running, let's swap the current ADC */
4291 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
4292 spec->cur_adc = new_adc;
4293 snd_hda_codec_setup_stream(codec, new_adc,
4294 spec->cur_adc_stream_tag, 0,
4295 spec->cur_adc_format);
4301 /* analog capture with dynamic dual-adc changes */
4302 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4303 struct hda_codec *codec,
4304 unsigned int stream_tag,
4305 unsigned int format,
4306 struct snd_pcm_substream *substream)
4308 struct hda_gen_spec *spec = codec->spec;
4309 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
4310 spec->cur_adc_stream_tag = stream_tag;
4311 spec->cur_adc_format = format;
4312 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
4316 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4317 struct hda_codec *codec,
4318 struct snd_pcm_substream *substream)
4320 struct hda_gen_spec *spec = codec->spec;
4321 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
4326 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
4330 .nid = 0, /* fill later */
4332 .prepare = dyn_adc_capture_pcm_prepare,
4333 .cleanup = dyn_adc_capture_pcm_cleanup
4337 static void fill_pcm_stream_name(char *str, size_t len, const char *sfx,
4338 const char *chip_name)
4344 strlcpy(str, chip_name, len);
4346 /* drop non-alnum chars after a space */
4347 for (p = strchr(str, ' '); p; p = strchr(p + 1, ' ')) {
4348 if (!isalnum(p[1])) {
4353 strlcat(str, sfx, len);
4356 /* build PCM streams based on the parsed results */
4357 int snd_hda_gen_build_pcms(struct hda_codec *codec)
4359 struct hda_gen_spec *spec = codec->spec;
4360 struct hda_pcm *info = spec->pcm_rec;
4361 const struct hda_pcm_stream *p;
4362 bool have_multi_adcs;
4364 codec->num_pcms = 1;
4365 codec->pcm_info = info;
4367 if (spec->no_analog)
4370 fill_pcm_stream_name(spec->stream_name_analog,
4371 sizeof(spec->stream_name_analog),
4372 " Analog", codec->chip_name);
4373 info->name = spec->stream_name_analog;
4375 if (spec->multiout.num_dacs > 0) {
4376 p = spec->stream_analog_playback;
4378 p = &pcm_analog_playback;
4379 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
4380 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
4381 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
4382 spec->multiout.max_channels;
4383 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
4384 spec->autocfg.line_outs == 2)
4385 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
4388 if (spec->num_adc_nids) {
4389 p = spec->stream_analog_capture;
4391 if (spec->dyn_adc_switch)
4392 p = &dyn_adc_pcm_analog_capture;
4394 p = &pcm_analog_capture;
4396 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
4397 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
4401 /* SPDIF for stream index #1 */
4402 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
4403 fill_pcm_stream_name(spec->stream_name_digital,
4404 sizeof(spec->stream_name_digital),
4405 " Digital", codec->chip_name);
4406 codec->num_pcms = 2;
4407 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
4408 info = spec->pcm_rec + 1;
4409 info->name = spec->stream_name_digital;
4410 if (spec->dig_out_type)
4411 info->pcm_type = spec->dig_out_type;
4413 info->pcm_type = HDA_PCM_TYPE_SPDIF;
4414 if (spec->multiout.dig_out_nid) {
4415 p = spec->stream_digital_playback;
4417 p = &pcm_digital_playback;
4418 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
4419 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
4421 if (spec->dig_in_nid) {
4422 p = spec->stream_digital_capture;
4424 p = &pcm_digital_capture;
4425 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
4426 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
4430 if (spec->no_analog)
4433 /* If the use of more than one ADC is requested for the current
4434 * model, configure a second analog capture-only PCM.
4436 have_multi_adcs = (spec->num_adc_nids > 1) &&
4437 !spec->dyn_adc_switch && !spec->auto_mic;
4438 /* Additional Analaog capture for index #2 */
4439 if (spec->alt_dac_nid || have_multi_adcs) {
4440 codec->num_pcms = 3;
4441 info = spec->pcm_rec + 2;
4442 info->name = spec->stream_name_analog;
4443 if (spec->alt_dac_nid) {
4444 p = spec->stream_analog_alt_playback;
4446 p = &pcm_analog_alt_playback;
4447 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
4448 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
4451 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
4453 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
4455 if (have_multi_adcs) {
4456 p = spec->stream_analog_alt_capture;
4458 p = &pcm_analog_alt_capture;
4459 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
4460 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
4462 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
4463 spec->num_adc_nids - 1;
4465 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
4467 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
4473 EXPORT_SYMBOL_HDA(snd_hda_gen_build_pcms);
4477 * Standard auto-parser initializations
4480 /* configure the given path as a proper output */
4481 static void set_output_and_unmute(struct hda_codec *codec, int path_idx)
4483 struct nid_path *path;
4486 path = snd_hda_get_path_from_idx(codec, path_idx);
4487 if (!path || !path->depth)
4489 pin = path->path[path->depth - 1];
4490 restore_pin_ctl(codec, pin);
4491 snd_hda_activate_path(codec, path, path->active, true);
4492 set_pin_eapd(codec, pin, path->active);
4495 /* initialize primary output paths */
4496 static void init_multi_out(struct hda_codec *codec)
4498 struct hda_gen_spec *spec = codec->spec;
4501 for (i = 0; i < spec->autocfg.line_outs; i++)
4502 set_output_and_unmute(codec, spec->out_paths[i]);
4506 static void __init_extra_out(struct hda_codec *codec, int num_outs, int *paths)
4510 for (i = 0; i < num_outs; i++)
4511 set_output_and_unmute(codec, paths[i]);
4514 /* initialize hp and speaker paths */
4515 static void init_extra_out(struct hda_codec *codec)
4517 struct hda_gen_spec *spec = codec->spec;
4519 if (spec->autocfg.line_out_type != AUTO_PIN_HP_OUT)
4520 __init_extra_out(codec, spec->autocfg.hp_outs, spec->hp_paths);
4521 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT)
4522 __init_extra_out(codec, spec->autocfg.speaker_outs,
4523 spec->speaker_paths);
4526 /* initialize multi-io paths */
4527 static void init_multi_io(struct hda_codec *codec)
4529 struct hda_gen_spec *spec = codec->spec;
4532 for (i = 0; i < spec->multi_ios; i++) {
4533 hda_nid_t pin = spec->multi_io[i].pin;
4534 struct nid_path *path;
4535 path = get_multiio_path(codec, i);
4538 if (!spec->multi_io[i].ctl_in)
4539 spec->multi_io[i].ctl_in =
4540 snd_hda_codec_get_pin_target(codec, pin);
4541 snd_hda_activate_path(codec, path, path->active, true);
4545 /* set up input pins and loopback paths */
4546 static void init_analog_input(struct hda_codec *codec)
4548 struct hda_gen_spec *spec = codec->spec;
4549 struct auto_pin_cfg *cfg = &spec->autocfg;
4552 for (i = 0; i < cfg->num_inputs; i++) {
4553 hda_nid_t nid = cfg->inputs[i].pin;
4554 if (is_input_pin(codec, nid))
4555 restore_pin_ctl(codec, nid);
4557 /* init loopback inputs */
4558 if (spec->mixer_nid) {
4559 struct nid_path *path;
4560 path = snd_hda_get_path_from_idx(codec, spec->loopback_paths[i]);
4562 snd_hda_activate_path(codec, path,
4563 path->active, false);
4568 /* initialize ADC paths */
4569 static void init_input_src(struct hda_codec *codec)
4571 struct hda_gen_spec *spec = codec->spec;
4572 struct hda_input_mux *imux = &spec->input_mux;
4573 struct nid_path *path;
4576 if (spec->dyn_adc_switch)
4579 nums = spec->num_adc_nids;
4581 for (c = 0; c < nums; c++) {
4582 for (i = 0; i < imux->num_items; i++) {
4583 path = get_input_path(codec, c, i);
4585 bool active = path->active;
4586 if (i == spec->cur_mux[c])
4588 snd_hda_activate_path(codec, path, active, false);
4593 if (spec->shared_mic_hp)
4594 update_shared_mic_hp(codec, spec->cur_mux[0]);
4596 if (spec->cap_sync_hook)
4597 spec->cap_sync_hook(codec, NULL);
4600 /* set right pin controls for digital I/O */
4601 static void init_digital(struct hda_codec *codec)
4603 struct hda_gen_spec *spec = codec->spec;
4607 for (i = 0; i < spec->autocfg.dig_outs; i++)
4608 set_output_and_unmute(codec, spec->digout_paths[i]);
4609 pin = spec->autocfg.dig_in_pin;
4611 struct nid_path *path;
4612 restore_pin_ctl(codec, pin);
4613 path = snd_hda_get_path_from_idx(codec, spec->digin_path);
4615 snd_hda_activate_path(codec, path, path->active, false);
4619 /* clear unsol-event tags on unused pins; Conexant codecs seem to leave
4620 * invalid unsol tags by some reason
4622 static void clear_unsol_on_unused_pins(struct hda_codec *codec)
4626 for (i = 0; i < codec->init_pins.used; i++) {
4627 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
4628 hda_nid_t nid = pin->nid;
4629 if (is_jack_detectable(codec, nid) &&
4630 !snd_hda_jack_tbl_get(codec, nid))
4631 snd_hda_codec_update_cache(codec, nid, 0,
4632 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
4637 * initialize the generic spec;
4638 * this can be put as patch_ops.init function
4640 int snd_hda_gen_init(struct hda_codec *codec)
4642 struct hda_gen_spec *spec = codec->spec;
4644 if (spec->init_hook)
4645 spec->init_hook(codec);
4647 snd_hda_apply_verbs(codec);
4649 codec->cached_write = 1;
4651 init_multi_out(codec);
4652 init_extra_out(codec);
4653 init_multi_io(codec);
4654 init_analog_input(codec);
4655 init_input_src(codec);
4656 init_digital(codec);
4658 clear_unsol_on_unused_pins(codec);
4660 /* call init functions of standard auto-mute helpers */
4661 update_automute_all(codec);
4663 snd_hda_codec_flush_amp_cache(codec);
4664 snd_hda_codec_flush_cmd_cache(codec);
4666 if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook)
4667 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4669 hda_call_check_power_status(codec, 0x01);
4672 EXPORT_SYMBOL_HDA(snd_hda_gen_init);
4675 * free the generic spec;
4676 * this can be put as patch_ops.free function
4678 void snd_hda_gen_free(struct hda_codec *codec)
4680 snd_hda_gen_spec_free(codec->spec);
4684 EXPORT_SYMBOL_HDA(snd_hda_gen_free);
4688 * check the loopback power save state;
4689 * this can be put as patch_ops.check_power_status function
4691 int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid)
4693 struct hda_gen_spec *spec = codec->spec;
4694 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
4696 EXPORT_SYMBOL_HDA(snd_hda_gen_check_power_status);
4701 * the generic codec support
4704 static const struct hda_codec_ops generic_patch_ops = {
4705 .build_controls = snd_hda_gen_build_controls,
4706 .build_pcms = snd_hda_gen_build_pcms,
4707 .init = snd_hda_gen_init,
4708 .free = snd_hda_gen_free,
4709 .unsol_event = snd_hda_jack_unsol_event,
4711 .check_power_status = snd_hda_gen_check_power_status,
4715 int snd_hda_parse_generic_codec(struct hda_codec *codec)
4717 struct hda_gen_spec *spec;
4720 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4723 snd_hda_gen_spec_init(spec);
4726 err = snd_hda_parse_pin_defcfg(codec, &spec->autocfg, NULL, 0);
4730 err = snd_hda_gen_parse_auto_config(codec, &spec->autocfg);
4734 codec->patch_ops = generic_patch_ops;
4738 snd_hda_gen_free(codec);
4741 EXPORT_SYMBOL_HDA(snd_hda_parse_generic_codec);