1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Universal Interface for Intel High Definition Audio Codec
5 * Generic widget tree parser
7 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
10 #include <linux/init.h>
11 #include <linux/slab.h>
12 #include <linux/export.h>
13 #include <linux/sort.h>
14 #include <linux/delay.h>
15 #include <linux/ctype.h>
16 #include <linux/string.h>
17 #include <linux/bitops.h>
18 #include <linux/module.h>
19 #include <linux/leds.h>
20 #include <sound/core.h>
21 #include <sound/jack.h>
22 #include <sound/tlv.h>
23 #include <sound/hda_codec.h>
24 #include "hda_local.h"
25 #include "hda_auto_parser.h"
28 #include "hda_generic.h"
32 * snd_hda_gen_spec_init - initialize hda_gen_spec struct
33 * @spec: hda_gen_spec object to initialize
35 * Initialize the given hda_gen_spec object.
37 int snd_hda_gen_spec_init(struct hda_gen_spec *spec)
39 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
40 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
41 snd_array_init(&spec->loopback_list, sizeof(struct hda_amp_list), 8);
42 mutex_init(&spec->pcm_mutex);
45 EXPORT_SYMBOL_GPL(snd_hda_gen_spec_init);
48 * snd_hda_gen_add_kctl - Add a new kctl_new struct from the template
49 * @spec: hda_gen_spec object
50 * @name: name string to override the template, NULL if unchanged
51 * @temp: template for the new kctl
53 * Add a new kctl (actually snd_kcontrol_new to be instantiated later)
54 * element based on the given snd_kcontrol_new template @temp and the
55 * name string @name to the list in @spec.
56 * Returns the newly created object or NULL as error.
58 struct snd_kcontrol_new *
59 snd_hda_gen_add_kctl(struct hda_gen_spec *spec, const char *name,
60 const struct snd_kcontrol_new *temp)
62 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
67 knew->name = kstrdup(name, GFP_KERNEL);
69 knew->name = kstrdup(knew->name, GFP_KERNEL);
74 EXPORT_SYMBOL_GPL(snd_hda_gen_add_kctl);
76 static void free_kctls(struct hda_gen_spec *spec)
78 if (spec->kctls.list) {
79 struct snd_kcontrol_new *kctl = spec->kctls.list;
81 for (i = 0; i < spec->kctls.used; i++)
84 snd_array_free(&spec->kctls);
87 static void snd_hda_gen_spec_free(struct hda_gen_spec *spec)
92 snd_array_free(&spec->paths);
93 snd_array_free(&spec->loopback_list);
99 static void parse_user_hints(struct hda_codec *codec)
101 struct hda_gen_spec *spec = codec->spec;
104 val = snd_hda_get_bool_hint(codec, "jack_detect");
106 codec->no_jack_detect = !val;
107 val = snd_hda_get_bool_hint(codec, "inv_jack_detect");
109 codec->inv_jack_detect = !!val;
110 val = snd_hda_get_bool_hint(codec, "trigger_sense");
112 codec->no_trigger_sense = !val;
113 val = snd_hda_get_bool_hint(codec, "inv_eapd");
115 codec->inv_eapd = !!val;
116 val = snd_hda_get_bool_hint(codec, "pcm_format_first");
118 codec->pcm_format_first = !!val;
119 val = snd_hda_get_bool_hint(codec, "sticky_stream");
121 codec->no_sticky_stream = !val;
122 val = snd_hda_get_bool_hint(codec, "spdif_status_reset");
124 codec->spdif_status_reset = !!val;
125 val = snd_hda_get_bool_hint(codec, "pin_amp_workaround");
127 codec->pin_amp_workaround = !!val;
128 val = snd_hda_get_bool_hint(codec, "single_adc_amp");
130 codec->single_adc_amp = !!val;
131 val = snd_hda_get_bool_hint(codec, "power_save_node");
133 codec->power_save_node = !!val;
135 val = snd_hda_get_bool_hint(codec, "auto_mute");
137 spec->suppress_auto_mute = !val;
138 val = snd_hda_get_bool_hint(codec, "auto_mic");
140 spec->suppress_auto_mic = !val;
141 val = snd_hda_get_bool_hint(codec, "line_in_auto_switch");
143 spec->line_in_auto_switch = !!val;
144 val = snd_hda_get_bool_hint(codec, "auto_mute_via_amp");
146 spec->auto_mute_via_amp = !!val;
147 val = snd_hda_get_bool_hint(codec, "need_dac_fix");
149 spec->need_dac_fix = !!val;
150 val = snd_hda_get_bool_hint(codec, "primary_hp");
152 spec->no_primary_hp = !val;
153 val = snd_hda_get_bool_hint(codec, "multi_io");
155 spec->no_multi_io = !val;
156 val = snd_hda_get_bool_hint(codec, "multi_cap_vol");
158 spec->multi_cap_vol = !!val;
159 val = snd_hda_get_bool_hint(codec, "inv_dmic_split");
161 spec->inv_dmic_split = !!val;
162 val = snd_hda_get_bool_hint(codec, "indep_hp");
164 spec->indep_hp = !!val;
165 val = snd_hda_get_bool_hint(codec, "add_stereo_mix_input");
167 spec->add_stereo_mix_input = !!val;
168 /* the following two are just for compatibility */
169 val = snd_hda_get_bool_hint(codec, "add_out_jack_modes");
171 spec->add_jack_modes = !!val;
172 val = snd_hda_get_bool_hint(codec, "add_in_jack_modes");
174 spec->add_jack_modes = !!val;
175 val = snd_hda_get_bool_hint(codec, "add_jack_modes");
177 spec->add_jack_modes = !!val;
178 val = snd_hda_get_bool_hint(codec, "power_down_unused");
180 spec->power_down_unused = !!val;
181 val = snd_hda_get_bool_hint(codec, "add_hp_mic");
183 spec->hp_mic = !!val;
184 val = snd_hda_get_bool_hint(codec, "hp_mic_detect");
186 spec->suppress_hp_mic_detect = !val;
187 val = snd_hda_get_bool_hint(codec, "vmaster");
189 spec->suppress_vmaster = !val;
191 if (!snd_hda_get_int_hint(codec, "mixer_nid", &val))
192 spec->mixer_nid = val;
196 * pin control value accesses
199 #define update_pin_ctl(codec, pin, val) \
200 snd_hda_codec_write_cache(codec, pin, 0, \
201 AC_VERB_SET_PIN_WIDGET_CONTROL, val)
203 /* restore the pinctl based on the cached value */
204 static inline void restore_pin_ctl(struct hda_codec *codec, hda_nid_t pin)
206 update_pin_ctl(codec, pin, snd_hda_codec_get_pin_target(codec, pin));
209 /* set the pinctl target value and write it if requested */
210 static void set_pin_target(struct hda_codec *codec, hda_nid_t pin,
211 unsigned int val, bool do_write)
215 val = snd_hda_correct_pin_ctl(codec, pin, val);
216 snd_hda_codec_set_pin_target(codec, pin, val);
218 update_pin_ctl(codec, pin, val);
221 /* set pinctl target values for all given pins */
222 static void set_pin_targets(struct hda_codec *codec, int num_pins,
223 hda_nid_t *pins, unsigned int val)
226 for (i = 0; i < num_pins; i++)
227 set_pin_target(codec, pins[i], val, false);
234 /* return the position of NID in the list, or -1 if not found */
235 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
238 for (i = 0; i < nums; i++)
244 /* return true if the given NID is contained in the path */
245 static bool is_nid_contained(struct nid_path *path, hda_nid_t nid)
247 return find_idx_in_nid_list(nid, path->path, path->depth) >= 0;
250 static struct nid_path *get_nid_path(struct hda_codec *codec,
251 hda_nid_t from_nid, hda_nid_t to_nid,
254 struct hda_gen_spec *spec = codec->spec;
255 struct nid_path *path;
258 snd_array_for_each(&spec->paths, i, path) {
259 if (path->depth <= 0)
261 if ((!from_nid || path->path[0] == from_nid) &&
262 (!to_nid || path->path[path->depth - 1] == to_nid)) {
264 (anchor_nid > 0 && is_nid_contained(path, anchor_nid)) ||
265 (anchor_nid < 0 && !is_nid_contained(path, anchor_nid)))
273 * snd_hda_get_path_idx - get the index number corresponding to the path
275 * @codec: the HDA codec
276 * @path: nid_path object
278 * The returned index starts from 1, i.e. the actual array index with offset 1,
279 * and zero is handled as an invalid path
281 int snd_hda_get_path_idx(struct hda_codec *codec, struct nid_path *path)
283 struct hda_gen_spec *spec = codec->spec;
284 struct nid_path *array = spec->paths.list;
287 if (!spec->paths.used)
290 if (idx < 0 || idx >= spec->paths.used)
294 EXPORT_SYMBOL_GPL(snd_hda_get_path_idx);
297 * snd_hda_get_path_from_idx - get the path instance corresponding to the
299 * @codec: the HDA codec
300 * @idx: the path index
302 struct nid_path *snd_hda_get_path_from_idx(struct hda_codec *codec, int idx)
304 struct hda_gen_spec *spec = codec->spec;
306 if (idx <= 0 || idx > spec->paths.used)
308 return snd_array_elem(&spec->paths, idx - 1);
310 EXPORT_SYMBOL_GPL(snd_hda_get_path_from_idx);
312 /* check whether the given DAC is already found in any existing paths */
313 static bool is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
315 struct hda_gen_spec *spec = codec->spec;
316 const struct nid_path *path;
319 snd_array_for_each(&spec->paths, i, path) {
320 if (path->path[0] == nid)
326 /* check whether the given two widgets can be connected */
327 static bool is_reachable_path(struct hda_codec *codec,
328 hda_nid_t from_nid, hda_nid_t to_nid)
330 if (!from_nid || !to_nid)
332 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
335 /* nid, dir and idx */
336 #define AMP_VAL_COMPARE_MASK (0xffff | (1U << 18) | (0x0f << 19))
338 /* check whether the given ctl is already assigned in any path elements */
339 static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
341 struct hda_gen_spec *spec = codec->spec;
342 const struct nid_path *path;
345 val &= AMP_VAL_COMPARE_MASK;
346 snd_array_for_each(&spec->paths, i, path) {
347 if ((path->ctls[type] & AMP_VAL_COMPARE_MASK) == val)
353 /* check whether a control with the given (nid, dir, idx) was assigned */
354 static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
355 int dir, int idx, int type)
357 unsigned int val = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir);
358 return is_ctl_used(codec, val, type);
361 static void print_nid_path(struct hda_codec *codec,
362 const char *pfx, struct nid_path *path)
369 for (i = 0; i < path->depth; i++)
370 pos += scnprintf(pos, sizeof(buf) - (pos - buf), "%s%02x",
371 pos != buf ? ":" : "",
374 codec_dbg(codec, "%s path: depth=%d '%s'\n", pfx, path->depth, buf);
377 /* called recursively */
378 static bool __parse_nid_path(struct hda_codec *codec,
379 hda_nid_t from_nid, hda_nid_t to_nid,
380 int anchor_nid, struct nid_path *path,
383 const hda_nid_t *conn;
386 if (to_nid == anchor_nid)
387 anchor_nid = 0; /* anchor passed */
388 else if (to_nid == (hda_nid_t)(-anchor_nid))
389 return false; /* hit the exclusive nid */
391 nums = snd_hda_get_conn_list(codec, to_nid, &conn);
392 for (i = 0; i < nums; i++) {
393 if (conn[i] != from_nid) {
394 /* special case: when from_nid is 0,
395 * try to find an empty DAC
398 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
399 is_dac_already_used(codec, conn[i]))
402 /* anchor is not requested or already passed? */
406 if (depth >= MAX_NID_PATH_DEPTH)
408 for (i = 0; i < nums; i++) {
410 type = get_wcaps_type(get_wcaps(codec, conn[i]));
411 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
414 if (__parse_nid_path(codec, from_nid, conn[i],
415 anchor_nid, path, depth + 1))
421 path->path[path->depth] = conn[i];
422 path->idx[path->depth + 1] = i;
423 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
424 path->multi[path->depth + 1] = 1;
430 * snd_hda_parse_nid_path - parse the widget path from the given nid to
432 * @codec: the HDA codec
433 * @from_nid: the NID where the path start from
434 * @to_nid: the NID where the path ends at
435 * @anchor_nid: the anchor indication
436 * @path: the path object to store the result
438 * Returns true if a matching path is found.
440 * The parsing behavior depends on parameters:
441 * when @from_nid is 0, try to find an empty DAC;
442 * when @anchor_nid is set to a positive value, only paths through the widget
443 * with the given value are evaluated.
444 * when @anchor_nid is set to a negative value, paths through the widget
445 * with the negative of given value are excluded, only other paths are chosen.
446 * when @anchor_nid is zero, no special handling about path selection.
448 static bool snd_hda_parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
449 hda_nid_t to_nid, int anchor_nid,
450 struct nid_path *path)
452 if (__parse_nid_path(codec, from_nid, to_nid, anchor_nid, path, 1)) {
453 path->path[path->depth] = to_nid;
461 * snd_hda_add_new_path - parse the path between the given NIDs and
462 * add to the path list
463 * @codec: the HDA codec
464 * @from_nid: the NID where the path start from
465 * @to_nid: the NID where the path ends at
466 * @anchor_nid: the anchor indication, see snd_hda_parse_nid_path()
468 * If no valid path is found, returns NULL.
471 snd_hda_add_new_path(struct hda_codec *codec, hda_nid_t from_nid,
472 hda_nid_t to_nid, int anchor_nid)
474 struct hda_gen_spec *spec = codec->spec;
475 struct nid_path *path;
477 if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid))
480 /* check whether the path has been already added */
481 path = get_nid_path(codec, from_nid, to_nid, anchor_nid);
485 path = snd_array_new(&spec->paths);
488 memset(path, 0, sizeof(*path));
489 if (snd_hda_parse_nid_path(codec, from_nid, to_nid, anchor_nid, path))
495 EXPORT_SYMBOL_GPL(snd_hda_add_new_path);
497 /* clear the given path as invalid so that it won't be picked up later */
498 static void invalidate_nid_path(struct hda_codec *codec, int idx)
500 struct nid_path *path = snd_hda_get_path_from_idx(codec, idx);
503 memset(path, 0, sizeof(*path));
506 /* return a DAC if paired to the given pin by codec driver */
507 static hda_nid_t get_preferred_dac(struct hda_codec *codec, hda_nid_t pin)
509 struct hda_gen_spec *spec = codec->spec;
510 const hda_nid_t *list = spec->preferred_dacs;
514 for (; *list; list += 2)
520 /* look for an empty DAC slot */
521 static hda_nid_t look_for_dac(struct hda_codec *codec, hda_nid_t pin,
524 struct hda_gen_spec *spec = codec->spec;
528 for (i = 0; i < spec->num_all_dacs; i++) {
529 hda_nid_t nid = spec->all_dacs[i];
530 if (!nid || is_dac_already_used(codec, nid))
532 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
533 if (is_digital != cap_digital)
535 if (is_reachable_path(codec, nid, pin))
541 /* replace the channels in the composed amp value with the given number */
542 static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
544 val &= ~(0x3U << 16);
549 static bool same_amp_caps(struct hda_codec *codec, hda_nid_t nid1,
550 hda_nid_t nid2, int dir)
552 if (!(get_wcaps(codec, nid1) & (1 << (dir + 1))))
553 return !(get_wcaps(codec, nid2) & (1 << (dir + 1)));
554 return (query_amp_caps(codec, nid1, dir) ==
555 query_amp_caps(codec, nid2, dir));
558 /* look for a widget suitable for assigning a mute switch in the path */
559 static hda_nid_t look_for_out_mute_nid(struct hda_codec *codec,
560 struct nid_path *path)
564 for (i = path->depth - 1; i >= 0; i--) {
565 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
566 return path->path[i];
567 if (i != path->depth - 1 && i != 0 &&
568 nid_has_mute(codec, path->path[i], HDA_INPUT))
569 return path->path[i];
574 /* look for a widget suitable for assigning a volume ctl in the path */
575 static hda_nid_t look_for_out_vol_nid(struct hda_codec *codec,
576 struct nid_path *path)
578 struct hda_gen_spec *spec = codec->spec;
581 for (i = path->depth - 1; i >= 0; i--) {
582 hda_nid_t nid = path->path[i];
583 if ((spec->out_vol_mask >> nid) & 1)
585 if (nid_has_volume(codec, nid, HDA_OUTPUT))
592 * path activation / deactivation
595 /* can have the amp-in capability? */
596 static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
598 hda_nid_t nid = path->path[idx];
599 unsigned int caps = get_wcaps(codec, nid);
600 unsigned int type = get_wcaps_type(caps);
602 if (!(caps & AC_WCAP_IN_AMP))
604 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
609 /* can have the amp-out capability? */
610 static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
612 hda_nid_t nid = path->path[idx];
613 unsigned int caps = get_wcaps(codec, nid);
614 unsigned int type = get_wcaps_type(caps);
616 if (!(caps & AC_WCAP_OUT_AMP))
618 if (type == AC_WID_PIN && !idx) /* only for output pins */
623 /* check whether the given (nid,dir,idx) is active */
624 static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
625 unsigned int dir, unsigned int idx)
627 struct hda_gen_spec *spec = codec->spec;
628 int type = get_wcaps_type(get_wcaps(codec, nid));
629 const struct nid_path *path;
632 if (nid == codec->core.afg)
635 snd_array_for_each(&spec->paths, n, path) {
638 if (codec->power_save_node) {
639 if (!path->stream_enabled)
641 /* ignore unplugged paths except for DAC/ADC */
642 if (!(path->pin_enabled || path->pin_fixed) &&
643 type != AC_WID_AUD_OUT && type != AC_WID_AUD_IN)
646 for (i = 0; i < path->depth; i++) {
647 if (path->path[i] == nid) {
648 if (dir == HDA_OUTPUT || idx == -1 ||
658 /* check whether the NID is referred by any active paths */
659 #define is_active_nid_for_any(codec, nid) \
660 is_active_nid(codec, nid, HDA_OUTPUT, -1)
662 /* get the default amp value for the target state */
663 static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
664 int dir, unsigned int caps, bool enable)
666 unsigned int val = 0;
668 if (caps & AC_AMPCAP_NUM_STEPS) {
671 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
673 if (caps & (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)) {
680 /* is this a stereo widget or a stereo-to-mono mix? */
681 static bool is_stereo_amps(struct hda_codec *codec, hda_nid_t nid, int dir)
683 unsigned int wcaps = get_wcaps(codec, nid);
686 if (wcaps & AC_WCAP_STEREO)
688 if (dir != HDA_INPUT || get_wcaps_type(wcaps) != AC_WID_AUD_MIX)
690 if (snd_hda_get_num_conns(codec, nid) != 1)
692 if (snd_hda_get_connections(codec, nid, &conn, 1) < 0)
694 return !!(get_wcaps(codec, conn) & AC_WCAP_STEREO);
697 /* initialize the amp value (only at the first time) */
698 static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
700 unsigned int caps = query_amp_caps(codec, nid, dir);
701 int val = get_amp_val_to_activate(codec, nid, dir, caps, false);
703 if (is_stereo_amps(codec, nid, dir))
704 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
706 snd_hda_codec_amp_init(codec, nid, 0, dir, idx, 0xff, val);
709 /* update the amp, doing in stereo or mono depending on NID */
710 static int update_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx,
711 unsigned int mask, unsigned int val)
713 if (is_stereo_amps(codec, nid, dir))
714 return snd_hda_codec_amp_stereo(codec, nid, dir, idx,
717 return snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
721 /* calculate amp value mask we can modify;
722 * if the given amp is controlled by mixers, don't touch it
724 static unsigned int get_amp_mask_to_modify(struct hda_codec *codec,
725 hda_nid_t nid, int dir, int idx,
728 unsigned int mask = 0xff;
730 if (caps & (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)) {
731 if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_MUTE_CTL))
734 if (caps & AC_AMPCAP_NUM_STEPS) {
735 if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
736 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
742 static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
743 int idx, int idx_to_check, bool enable)
746 unsigned int mask, val;
748 caps = query_amp_caps(codec, nid, dir);
749 val = get_amp_val_to_activate(codec, nid, dir, caps, enable);
750 mask = get_amp_mask_to_modify(codec, nid, dir, idx_to_check, caps);
755 update_amp(codec, nid, dir, idx, mask, val);
758 static void check_and_activate_amp(struct hda_codec *codec, hda_nid_t nid,
759 int dir, int idx, int idx_to_check,
762 /* check whether the given amp is still used by others */
763 if (!enable && is_active_nid(codec, nid, dir, idx_to_check))
765 activate_amp(codec, nid, dir, idx, idx_to_check, enable);
768 static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
771 hda_nid_t nid = path->path[i];
772 init_amp(codec, nid, HDA_OUTPUT, 0);
773 check_and_activate_amp(codec, nid, HDA_OUTPUT, 0, 0, enable);
776 static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
777 int i, bool enable, bool add_aamix)
779 struct hda_gen_spec *spec = codec->spec;
780 const hda_nid_t *conn;
783 hda_nid_t nid = path->path[i];
785 nums = snd_hda_get_conn_list(codec, nid, &conn);
788 type = get_wcaps_type(get_wcaps(codec, nid));
789 if (type == AC_WID_PIN ||
790 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
796 for (n = 0; n < nums; n++)
797 init_amp(codec, nid, HDA_INPUT, n);
799 /* here is a little bit tricky in comparison with activate_amp_out();
800 * when aa-mixer is available, we need to enable the path as well
802 for (n = 0; n < nums; n++) {
804 if (conn[n] != spec->mixer_merge_nid)
806 /* when aamix is disabled, force to off */
808 activate_amp(codec, nid, HDA_INPUT, n, n, false);
812 check_and_activate_amp(codec, nid, HDA_INPUT, n, idx, enable);
816 /* sync power of each widget in the the given path */
817 static hda_nid_t path_power_update(struct hda_codec *codec,
818 struct nid_path *path,
819 bool allow_powerdown)
821 hda_nid_t nid, changed = 0;
824 for (i = 0; i < path->depth; i++) {
826 if (!(get_wcaps(codec, nid) & AC_WCAP_POWER))
828 if (nid == codec->core.afg)
830 if (!allow_powerdown || is_active_nid_for_any(codec, nid))
834 power = snd_hda_codec_read(codec, nid, 0,
835 AC_VERB_GET_POWER_STATE, 0);
836 if (power != (state | (state << 4))) {
837 snd_hda_codec_write(codec, nid, 0,
838 AC_VERB_SET_POWER_STATE, state);
840 /* all known codecs seem to be capable to handl
841 * widgets state even in D3, so far.
842 * if any new codecs need to restore the widget
843 * states after D0 transition, call the function
847 if (state == AC_PWRST_D0)
848 snd_hdac_regmap_sync_node(&codec->core, nid);
855 /* do sync with the last power state change */
856 static void sync_power_state_change(struct hda_codec *codec, hda_nid_t nid)
860 snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
865 * snd_hda_activate_path - activate or deactivate the given path
866 * @codec: the HDA codec
867 * @path: the path to activate/deactivate
868 * @enable: flag to activate or not
869 * @add_aamix: enable the input from aamix NID
871 * If @add_aamix is set, enable the input from aa-mix NID as well (if any).
873 void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
874 bool enable, bool add_aamix)
876 struct hda_gen_spec *spec = codec->spec;
879 path->active = enable;
881 /* make sure the widget is powered up */
882 if (enable && (spec->power_down_unused || codec->power_save_node))
883 path_power_update(codec, path, codec->power_save_node);
885 for (i = path->depth - 1; i >= 0; i--) {
886 hda_nid_t nid = path->path[i];
888 if (enable && path->multi[i])
889 snd_hda_codec_write_cache(codec, nid, 0,
890 AC_VERB_SET_CONNECT_SEL,
892 if (has_amp_in(codec, path, i))
893 activate_amp_in(codec, path, i, enable, add_aamix);
894 if (has_amp_out(codec, path, i))
895 activate_amp_out(codec, path, i, enable);
898 EXPORT_SYMBOL_GPL(snd_hda_activate_path);
900 /* if the given path is inactive, put widgets into D3 (only if suitable) */
901 static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path)
903 struct hda_gen_spec *spec = codec->spec;
905 if (!(spec->power_down_unused || codec->power_save_node) || path->active)
907 sync_power_state_change(codec, path_power_update(codec, path, true));
910 /* turn on/off EAPD on the given pin */
911 static void set_pin_eapd(struct hda_codec *codec, hda_nid_t pin, bool enable)
913 struct hda_gen_spec *spec = codec->spec;
914 if (spec->own_eapd_ctl ||
915 !(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD))
917 if (spec->keep_eapd_on && !enable)
921 snd_hda_codec_write_cache(codec, pin, 0,
922 AC_VERB_SET_EAPD_BTLENABLE,
923 enable ? 0x02 : 0x00);
926 /* re-initialize the path specified by the given path index */
927 static void resume_path_from_idx(struct hda_codec *codec, int path_idx)
929 struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
931 snd_hda_activate_path(codec, path, path->active, false);
936 * Helper functions for creating mixer ctl elements
939 static int hda_gen_mixer_mute_put(struct snd_kcontrol *kcontrol,
940 struct snd_ctl_elem_value *ucontrol);
941 static int hda_gen_bind_mute_get(struct snd_kcontrol *kcontrol,
942 struct snd_ctl_elem_value *ucontrol);
943 static int hda_gen_bind_mute_put(struct snd_kcontrol *kcontrol,
944 struct snd_ctl_elem_value *ucontrol);
951 static const struct snd_kcontrol_new control_templates[] = {
952 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
953 /* only the put callback is replaced for handling the special mute */
955 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
956 .subdevice = HDA_SUBDEV_AMP_FLAG,
957 .info = snd_hda_mixer_amp_switch_info,
958 .get = snd_hda_mixer_amp_switch_get,
959 .put = hda_gen_mixer_mute_put, /* replaced */
960 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0),
963 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
964 .info = snd_hda_mixer_amp_switch_info,
965 .get = hda_gen_bind_mute_get,
966 .put = hda_gen_bind_mute_put, /* replaced */
967 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0),
971 /* add dynamic controls from template */
972 static struct snd_kcontrol_new *
973 add_control(struct hda_gen_spec *spec, int type, const char *name,
974 int cidx, unsigned long val)
976 struct snd_kcontrol_new *knew;
978 knew = snd_hda_gen_add_kctl(spec, name, &control_templates[type]);
982 if (get_amp_nid_(val))
983 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
984 knew->private_value = val;
988 static int add_control_with_pfx(struct hda_gen_spec *spec, int type,
989 const char *pfx, const char *dir,
990 const char *sfx, int cidx, unsigned long val)
992 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
993 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
994 if (!add_control(spec, type, name, cidx, val))
999 #define add_pb_vol_ctrl(spec, type, pfx, val) \
1000 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
1001 #define add_pb_sw_ctrl(spec, type, pfx, val) \
1002 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
1003 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
1004 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
1005 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
1006 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
1008 static int add_vol_ctl(struct hda_codec *codec, const char *pfx, int cidx,
1009 unsigned int chs, struct nid_path *path)
1014 val = path->ctls[NID_PATH_VOL_CTL];
1017 val = amp_val_replace_channels(val, chs);
1018 return __add_pb_vol_ctrl(codec->spec, HDA_CTL_WIDGET_VOL, pfx, cidx, val);
1021 /* return the channel bits suitable for the given path->ctls[] */
1022 static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
1025 int chs = 1; /* mono (left only) */
1027 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
1028 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
1029 chs = 3; /* stereo */
1034 static int add_stereo_vol(struct hda_codec *codec, const char *pfx, int cidx,
1035 struct nid_path *path)
1037 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
1038 return add_vol_ctl(codec, pfx, cidx, chs, path);
1041 /* create a mute-switch for the given mixer widget;
1042 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
1044 static int add_sw_ctl(struct hda_codec *codec, const char *pfx, int cidx,
1045 unsigned int chs, struct nid_path *path)
1048 int type = HDA_CTL_WIDGET_MUTE;
1052 val = path->ctls[NID_PATH_MUTE_CTL];
1055 val = amp_val_replace_channels(val, chs);
1056 if (get_amp_direction_(val) == HDA_INPUT) {
1057 hda_nid_t nid = get_amp_nid_(val);
1058 int nums = snd_hda_get_num_conns(codec, nid);
1060 type = HDA_CTL_BIND_MUTE;
1064 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
1067 static int add_stereo_sw(struct hda_codec *codec, const char *pfx,
1068 int cidx, struct nid_path *path)
1070 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
1071 return add_sw_ctl(codec, pfx, cidx, chs, path);
1074 /* playback mute control with the software mute bit check */
1075 static void sync_auto_mute_bits(struct snd_kcontrol *kcontrol,
1076 struct snd_ctl_elem_value *ucontrol)
1078 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1079 struct hda_gen_spec *spec = codec->spec;
1081 if (spec->auto_mute_via_amp) {
1082 hda_nid_t nid = get_amp_nid(kcontrol);
1083 bool enabled = !((spec->mute_bits >> nid) & 1);
1084 ucontrol->value.integer.value[0] &= enabled;
1085 ucontrol->value.integer.value[1] &= enabled;
1089 static int hda_gen_mixer_mute_put(struct snd_kcontrol *kcontrol,
1090 struct snd_ctl_elem_value *ucontrol)
1092 sync_auto_mute_bits(kcontrol, ucontrol);
1093 return snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
1097 * Bound mute controls
1099 #define AMP_VAL_IDX_SHIFT 19
1100 #define AMP_VAL_IDX_MASK (0x0f<<19)
1102 static int hda_gen_bind_mute_get(struct snd_kcontrol *kcontrol,
1103 struct snd_ctl_elem_value *ucontrol)
1105 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1109 mutex_lock(&codec->control_mutex);
1110 pval = kcontrol->private_value;
1111 kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */
1112 err = snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
1113 kcontrol->private_value = pval;
1114 mutex_unlock(&codec->control_mutex);
1118 static int hda_gen_bind_mute_put(struct snd_kcontrol *kcontrol,
1119 struct snd_ctl_elem_value *ucontrol)
1121 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1123 int i, indices, err = 0, change = 0;
1125 sync_auto_mute_bits(kcontrol, ucontrol);
1127 mutex_lock(&codec->control_mutex);
1128 pval = kcontrol->private_value;
1129 indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT;
1130 for (i = 0; i < indices; i++) {
1131 kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) |
1132 (i << AMP_VAL_IDX_SHIFT);
1133 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
1138 kcontrol->private_value = pval;
1139 mutex_unlock(&codec->control_mutex);
1140 return err < 0 ? err : change;
1143 /* any ctl assigned to the path with the given index? */
1144 static bool path_has_mixer(struct hda_codec *codec, int path_idx, int ctl_type)
1146 struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
1147 return path && path->ctls[ctl_type];
1150 static const char * const channel_name[4] = {
1151 "Front", "Surround", "CLFE", "Side"
1154 /* give some appropriate ctl name prefix for the given line out channel */
1155 static const char *get_line_out_pfx(struct hda_codec *codec, int ch,
1156 int *index, int ctl_type)
1158 struct hda_gen_spec *spec = codec->spec;
1159 struct auto_pin_cfg *cfg = &spec->autocfg;
1162 if (cfg->line_outs == 1 && !spec->multi_ios &&
1163 !codec->force_pin_prefix &&
1164 !cfg->hp_outs && !cfg->speaker_outs)
1165 return spec->vmaster_mute.hook ? "PCM" : "Master";
1167 /* if there is really a single DAC used in the whole output paths,
1168 * use it master (or "PCM" if a vmaster hook is present)
1170 if (spec->multiout.num_dacs == 1 && !spec->mixer_nid &&
1171 !codec->force_pin_prefix &&
1172 !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0])
1173 return spec->vmaster_mute.hook ? "PCM" : "Master";
1175 /* multi-io channels */
1176 if (ch >= cfg->line_outs)
1177 return channel_name[ch];
1179 switch (cfg->line_out_type) {
1180 case AUTO_PIN_SPEAKER_OUT:
1181 /* if the primary channel vol/mute is shared with HP volume,
1182 * don't name it as Speaker
1184 if (!ch && cfg->hp_outs &&
1185 !path_has_mixer(codec, spec->hp_paths[0], ctl_type))
1187 if (cfg->line_outs == 1)
1189 if (cfg->line_outs == 2)
1190 return ch ? "Bass Speaker" : "Speaker";
1192 case AUTO_PIN_HP_OUT:
1193 /* if the primary channel vol/mute is shared with spk volume,
1194 * don't name it as Headphone
1196 if (!ch && cfg->speaker_outs &&
1197 !path_has_mixer(codec, spec->speaker_paths[0], ctl_type))
1199 /* for multi-io case, only the primary out */
1200 if (ch && spec->multi_ios)
1204 case AUTO_PIN_LINE_OUT:
1205 /* This deals with the case where we have two DACs and
1206 * one LO, one HP and one Speaker */
1207 if (!ch && cfg->speaker_outs && cfg->hp_outs) {
1208 bool hp_lo_shared = !path_has_mixer(codec, spec->hp_paths[0], ctl_type);
1209 bool spk_lo_shared = !path_has_mixer(codec, spec->speaker_paths[0], ctl_type);
1210 if (hp_lo_shared && spk_lo_shared)
1211 return spec->vmaster_mute.hook ? "PCM" : "Master";
1213 return "Headphone+LO";
1215 return "Speaker+LO";
1219 /* for a single channel output, we don't have to name the channel */
1220 if (cfg->line_outs == 1 && !spec->multi_ios)
1223 if (ch >= ARRAY_SIZE(channel_name)) {
1228 return channel_name[ch];
1232 * Parse output paths
1235 /* badness definition */
1237 /* No primary DAC is found for the main output */
1238 BAD_NO_PRIMARY_DAC = 0x10000,
1239 /* No DAC is found for the extra output */
1240 BAD_NO_DAC = 0x4000,
1241 /* No possible multi-ios */
1242 BAD_MULTI_IO = 0x120,
1243 /* No individual DAC for extra output */
1244 BAD_NO_EXTRA_DAC = 0x102,
1245 /* No individual DAC for extra surrounds */
1246 BAD_NO_EXTRA_SURR_DAC = 0x101,
1247 /* Primary DAC shared with main surrounds */
1248 BAD_SHARED_SURROUND = 0x100,
1249 /* No independent HP possible */
1250 BAD_NO_INDEP_HP = 0x10,
1251 /* Primary DAC shared with main CLFE */
1252 BAD_SHARED_CLFE = 0x10,
1253 /* Primary DAC shared with extra surrounds */
1254 BAD_SHARED_EXTRA_SURROUND = 0x10,
1255 /* Volume widget is shared */
1256 BAD_SHARED_VOL = 0x10,
1259 /* look for widgets in the given path which are appropriate for
1260 * volume and mute controls, and assign the values to ctls[].
1262 * When no appropriate widget is found in the path, the badness value
1263 * is incremented depending on the situation. The function returns the
1264 * total badness for both volume and mute controls.
1266 static int assign_out_path_ctls(struct hda_codec *codec, struct nid_path *path)
1268 struct hda_gen_spec *spec = codec->spec;
1274 return BAD_SHARED_VOL * 2;
1276 if (path->ctls[NID_PATH_VOL_CTL] ||
1277 path->ctls[NID_PATH_MUTE_CTL])
1278 return 0; /* already evaluated */
1280 nid = look_for_out_vol_nid(codec, path);
1282 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
1283 if (spec->dac_min_mute)
1284 val |= HDA_AMP_VAL_MIN_MUTE;
1285 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
1286 badness += BAD_SHARED_VOL;
1288 path->ctls[NID_PATH_VOL_CTL] = val;
1290 badness += BAD_SHARED_VOL;
1291 nid = look_for_out_mute_nid(codec, path);
1293 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
1294 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
1295 nid_has_mute(codec, nid, HDA_OUTPUT))
1296 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
1298 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
1299 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
1300 badness += BAD_SHARED_VOL;
1302 path->ctls[NID_PATH_MUTE_CTL] = val;
1304 badness += BAD_SHARED_VOL;
1308 const struct badness_table hda_main_out_badness = {
1309 .no_primary_dac = BAD_NO_PRIMARY_DAC,
1310 .no_dac = BAD_NO_DAC,
1311 .shared_primary = BAD_NO_PRIMARY_DAC,
1312 .shared_surr = BAD_SHARED_SURROUND,
1313 .shared_clfe = BAD_SHARED_CLFE,
1314 .shared_surr_main = BAD_SHARED_SURROUND,
1316 EXPORT_SYMBOL_GPL(hda_main_out_badness);
1318 const struct badness_table hda_extra_out_badness = {
1319 .no_primary_dac = BAD_NO_DAC,
1320 .no_dac = BAD_NO_DAC,
1321 .shared_primary = BAD_NO_EXTRA_DAC,
1322 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
1323 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
1324 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
1326 EXPORT_SYMBOL_GPL(hda_extra_out_badness);
1328 /* get the DAC of the primary output corresponding to the given array index */
1329 static hda_nid_t get_primary_out(struct hda_codec *codec, int idx)
1331 struct hda_gen_spec *spec = codec->spec;
1332 struct auto_pin_cfg *cfg = &spec->autocfg;
1334 if (cfg->line_outs > idx)
1335 return spec->private_dac_nids[idx];
1336 idx -= cfg->line_outs;
1337 if (spec->multi_ios > idx)
1338 return spec->multi_io[idx].dac;
1342 /* return the DAC if it's reachable, otherwise zero */
1343 static inline hda_nid_t try_dac(struct hda_codec *codec,
1344 hda_nid_t dac, hda_nid_t pin)
1346 return is_reachable_path(codec, dac, pin) ? dac : 0;
1349 /* try to assign DACs to pins and return the resultant badness */
1350 static int try_assign_dacs(struct hda_codec *codec, int num_outs,
1351 const hda_nid_t *pins, hda_nid_t *dacs,
1353 const struct badness_table *bad)
1355 struct hda_gen_spec *spec = codec->spec;
1363 for (i = 0; i < num_outs; i++) {
1364 struct nid_path *path;
1365 hda_nid_t pin = pins[i];
1367 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1369 badness += assign_out_path_ctls(codec, path);
1373 dacs[i] = get_preferred_dac(codec, pin);
1375 if (is_dac_already_used(codec, dacs[i]))
1376 badness += bad->shared_primary;
1380 dacs[i] = look_for_dac(codec, pin, false);
1381 if (!dacs[i] && !i) {
1382 /* try to steal the DAC of surrounds for the front */
1383 for (j = 1; j < num_outs; j++) {
1384 if (is_reachable_path(codec, dacs[j], pin)) {
1387 invalidate_nid_path(codec, path_idx[j]);
1396 dac = try_dac(codec, get_primary_out(codec, i), pin);
1398 dac = try_dac(codec, dacs[0], pin);
1400 dac = try_dac(codec, get_primary_out(codec, i), pin);
1403 badness += bad->shared_primary;
1405 badness += bad->shared_surr;
1407 badness += bad->shared_clfe;
1408 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
1409 dac = spec->private_dac_nids[0];
1410 badness += bad->shared_surr_main;
1412 badness += bad->no_primary_dac;
1414 badness += bad->no_dac;
1418 path = snd_hda_add_new_path(codec, dac, pin, -spec->mixer_nid);
1419 if (!path && !i && spec->mixer_nid) {
1420 /* try with aamix */
1421 path = snd_hda_add_new_path(codec, dac, pin, 0);
1425 badness += bad->no_dac;
1427 /* print_nid_path(codec, "output", path); */
1428 path->active = true;
1429 path_idx[i] = snd_hda_get_path_idx(codec, path);
1430 badness += assign_out_path_ctls(codec, path);
1437 /* return NID if the given pin has only a single connection to a certain DAC */
1438 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
1440 struct hda_gen_spec *spec = codec->spec;
1442 hda_nid_t nid_found = 0;
1444 for (i = 0; i < spec->num_all_dacs; i++) {
1445 hda_nid_t nid = spec->all_dacs[i];
1446 if (!nid || is_dac_already_used(codec, nid))
1448 if (is_reachable_path(codec, nid, pin)) {
1457 /* check whether the given pin can be a multi-io pin */
1458 static bool can_be_multiio_pin(struct hda_codec *codec,
1459 unsigned int location, hda_nid_t nid)
1461 unsigned int defcfg, caps;
1463 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1464 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
1466 if (location && get_defcfg_location(defcfg) != location)
1468 caps = snd_hda_query_pin_caps(codec, nid);
1469 if (!(caps & AC_PINCAP_OUT))
1474 /* count the number of input pins that are capable to be multi-io */
1475 static int count_multiio_pins(struct hda_codec *codec, hda_nid_t reference_pin)
1477 struct hda_gen_spec *spec = codec->spec;
1478 struct auto_pin_cfg *cfg = &spec->autocfg;
1479 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1480 unsigned int location = get_defcfg_location(defcfg);
1484 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
1485 for (i = 0; i < cfg->num_inputs; i++) {
1486 if (cfg->inputs[i].type != type)
1488 if (can_be_multiio_pin(codec, location,
1489 cfg->inputs[i].pin))
1499 * When hardwired is set, try to fill ony hardwired pins, and returns
1500 * zero if any pins are filled, non-zero if nothing found.
1501 * When hardwired is off, try to fill possible input pins, and returns
1502 * the badness value.
1504 static int fill_multi_ios(struct hda_codec *codec,
1505 hda_nid_t reference_pin,
1508 struct hda_gen_spec *spec = codec->spec;
1509 struct auto_pin_cfg *cfg = &spec->autocfg;
1510 int type, i, j, num_pins, old_pins;
1511 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1512 unsigned int location = get_defcfg_location(defcfg);
1514 struct nid_path *path;
1516 old_pins = spec->multi_ios;
1520 num_pins = count_multiio_pins(codec, reference_pin);
1524 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
1525 for (i = 0; i < cfg->num_inputs; i++) {
1526 hda_nid_t nid = cfg->inputs[i].pin;
1529 if (cfg->inputs[i].type != type)
1531 if (!can_be_multiio_pin(codec, location, nid))
1533 for (j = 0; j < spec->multi_ios; j++) {
1534 if (nid == spec->multi_io[j].pin)
1537 if (j < spec->multi_ios)
1541 dac = get_dac_if_single(codec, nid);
1543 dac = look_for_dac(codec, nid, false);
1548 path = snd_hda_add_new_path(codec, dac, nid,
1554 /* print_nid_path(codec, "multiio", path); */
1555 spec->multi_io[spec->multi_ios].pin = nid;
1556 spec->multi_io[spec->multi_ios].dac = dac;
1557 spec->out_paths[cfg->line_outs + spec->multi_ios] =
1558 snd_hda_get_path_idx(codec, path);
1560 if (spec->multi_ios >= 2)
1566 badness = BAD_MULTI_IO;
1567 if (old_pins == spec->multi_ios) {
1569 return 1; /* nothing found */
1571 return badness; /* no badness if nothing found */
1573 if (!hardwired && spec->multi_ios < 2) {
1574 /* cancel newly assigned paths */
1575 spec->paths.used -= spec->multi_ios - old_pins;
1576 spec->multi_ios = old_pins;
1580 /* assign volume and mute controls */
1581 for (i = old_pins; i < spec->multi_ios; i++) {
1582 path = snd_hda_get_path_from_idx(codec, spec->out_paths[cfg->line_outs + i]);
1583 badness += assign_out_path_ctls(codec, path);
1589 /* map DACs for all pins in the list if they are single connections */
1590 static bool map_singles(struct hda_codec *codec, int outs,
1591 const hda_nid_t *pins, hda_nid_t *dacs, int *path_idx)
1593 struct hda_gen_spec *spec = codec->spec;
1596 for (i = 0; i < outs; i++) {
1597 struct nid_path *path;
1601 dac = get_dac_if_single(codec, pins[i]);
1604 path = snd_hda_add_new_path(codec, dac, pins[i],
1606 if (!path && !i && spec->mixer_nid)
1607 path = snd_hda_add_new_path(codec, dac, pins[i], 0);
1611 /* print_nid_path(codec, "output", path); */
1612 path->active = true;
1613 path_idx[i] = snd_hda_get_path_idx(codec, path);
1619 static inline bool has_aamix_out_paths(struct hda_gen_spec *spec)
1621 return spec->aamix_out_paths[0] || spec->aamix_out_paths[1] ||
1622 spec->aamix_out_paths[2];
1625 /* create a new path including aamix if available, and return its index */
1626 static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
1628 struct hda_gen_spec *spec = codec->spec;
1629 struct nid_path *path;
1630 hda_nid_t path_dac, dac, pin;
1632 path = snd_hda_get_path_from_idx(codec, path_idx);
1633 if (!path || !path->depth ||
1634 is_nid_contained(path, spec->mixer_nid))
1636 path_dac = path->path[0];
1637 dac = spec->private_dac_nids[0];
1638 pin = path->path[path->depth - 1];
1639 path = snd_hda_add_new_path(codec, dac, pin, spec->mixer_nid);
1641 if (dac != path_dac)
1643 else if (spec->multiout.hp_out_nid[0])
1644 dac = spec->multiout.hp_out_nid[0];
1645 else if (spec->multiout.extra_out_nid[0])
1646 dac = spec->multiout.extra_out_nid[0];
1650 path = snd_hda_add_new_path(codec, dac, pin,
1655 /* print_nid_path(codec, "output-aamix", path); */
1656 path->active = false; /* unused as default */
1657 path->pin_fixed = true; /* static route */
1658 return snd_hda_get_path_idx(codec, path);
1661 /* check whether the independent HP is available with the current config */
1662 static bool indep_hp_possible(struct hda_codec *codec)
1664 struct hda_gen_spec *spec = codec->spec;
1665 struct auto_pin_cfg *cfg = &spec->autocfg;
1666 struct nid_path *path;
1669 if (cfg->line_out_type == AUTO_PIN_HP_OUT)
1670 idx = spec->out_paths[0];
1672 idx = spec->hp_paths[0];
1673 path = snd_hda_get_path_from_idx(codec, idx);
1677 /* assume no path conflicts unless aamix is involved */
1678 if (!spec->mixer_nid || !is_nid_contained(path, spec->mixer_nid))
1681 /* check whether output paths contain aamix */
1682 for (i = 0; i < cfg->line_outs; i++) {
1683 if (spec->out_paths[i] == idx)
1685 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
1686 if (path && is_nid_contained(path, spec->mixer_nid))
1689 for (i = 0; i < cfg->speaker_outs; i++) {
1690 path = snd_hda_get_path_from_idx(codec, spec->speaker_paths[i]);
1691 if (path && is_nid_contained(path, spec->mixer_nid))
1698 /* fill the empty entries in the dac array for speaker/hp with the
1699 * shared dac pointed by the paths
1701 static void refill_shared_dacs(struct hda_codec *codec, int num_outs,
1702 hda_nid_t *dacs, int *path_idx)
1704 struct nid_path *path;
1707 for (i = 0; i < num_outs; i++) {
1710 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1713 dacs[i] = path->path[0];
1717 /* fill in the dac_nids table from the parsed pin configuration */
1718 static int fill_and_eval_dacs(struct hda_codec *codec,
1719 bool fill_hardwired,
1720 bool fill_mio_first)
1722 struct hda_gen_spec *spec = codec->spec;
1723 struct auto_pin_cfg *cfg = &spec->autocfg;
1724 int i, err, badness;
1726 /* set num_dacs once to full for look_for_dac() */
1727 spec->multiout.num_dacs = cfg->line_outs;
1728 spec->multiout.dac_nids = spec->private_dac_nids;
1729 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
1730 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
1731 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
1732 spec->multi_ios = 0;
1733 snd_array_free(&spec->paths);
1735 /* clear path indices */
1736 memset(spec->out_paths, 0, sizeof(spec->out_paths));
1737 memset(spec->hp_paths, 0, sizeof(spec->hp_paths));
1738 memset(spec->speaker_paths, 0, sizeof(spec->speaker_paths));
1739 memset(spec->aamix_out_paths, 0, sizeof(spec->aamix_out_paths));
1740 memset(spec->digout_paths, 0, sizeof(spec->digout_paths));
1741 memset(spec->input_paths, 0, sizeof(spec->input_paths));
1742 memset(spec->loopback_paths, 0, sizeof(spec->loopback_paths));
1743 memset(&spec->digin_path, 0, sizeof(spec->digin_path));
1747 /* fill hard-wired DACs first */
1748 if (fill_hardwired) {
1751 mapped = map_singles(codec, cfg->line_outs,
1753 spec->private_dac_nids,
1755 mapped |= map_singles(codec, cfg->hp_outs,
1757 spec->multiout.hp_out_nid,
1759 mapped |= map_singles(codec, cfg->speaker_outs,
1761 spec->multiout.extra_out_nid,
1762 spec->speaker_paths);
1763 if (!spec->no_multi_io &&
1764 fill_mio_first && cfg->line_outs == 1 &&
1765 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1766 err = fill_multi_ios(codec, cfg->line_out_pins[0], true);
1773 badness += try_assign_dacs(codec, cfg->line_outs, cfg->line_out_pins,
1774 spec->private_dac_nids, spec->out_paths,
1775 spec->main_out_badness);
1777 if (!spec->no_multi_io && fill_mio_first &&
1778 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1779 /* try to fill multi-io first */
1780 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1783 /* we don't count badness at this stage yet */
1786 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
1787 err = try_assign_dacs(codec, cfg->hp_outs, cfg->hp_pins,
1788 spec->multiout.hp_out_nid,
1790 spec->extra_out_badness);
1795 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1796 err = try_assign_dacs(codec, cfg->speaker_outs,
1798 spec->multiout.extra_out_nid,
1799 spec->speaker_paths,
1800 spec->extra_out_badness);
1805 if (!spec->no_multi_io &&
1806 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1807 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1813 if (spec->mixer_nid) {
1814 spec->aamix_out_paths[0] =
1815 check_aamix_out_path(codec, spec->out_paths[0]);
1816 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1817 spec->aamix_out_paths[1] =
1818 check_aamix_out_path(codec, spec->hp_paths[0]);
1819 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1820 spec->aamix_out_paths[2] =
1821 check_aamix_out_path(codec, spec->speaker_paths[0]);
1824 if (!spec->no_multi_io &&
1825 cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
1826 if (count_multiio_pins(codec, cfg->hp_pins[0]) >= 2)
1827 spec->multi_ios = 1; /* give badness */
1829 /* re-count num_dacs and squash invalid entries */
1830 spec->multiout.num_dacs = 0;
1831 for (i = 0; i < cfg->line_outs; i++) {
1832 if (spec->private_dac_nids[i])
1833 spec->multiout.num_dacs++;
1835 memmove(spec->private_dac_nids + i,
1836 spec->private_dac_nids + i + 1,
1837 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
1838 spec->private_dac_nids[cfg->line_outs - 1] = 0;
1842 spec->ext_channel_count = spec->min_channel_count =
1843 spec->multiout.num_dacs * 2;
1845 if (spec->multi_ios == 2) {
1846 for (i = 0; i < 2; i++)
1847 spec->private_dac_nids[spec->multiout.num_dacs++] =
1848 spec->multi_io[i].dac;
1849 } else if (spec->multi_ios) {
1850 spec->multi_ios = 0;
1851 badness += BAD_MULTI_IO;
1854 if (spec->indep_hp && !indep_hp_possible(codec))
1855 badness += BAD_NO_INDEP_HP;
1857 /* re-fill the shared DAC for speaker / headphone */
1858 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1859 refill_shared_dacs(codec, cfg->hp_outs,
1860 spec->multiout.hp_out_nid,
1862 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1863 refill_shared_dacs(codec, cfg->speaker_outs,
1864 spec->multiout.extra_out_nid,
1865 spec->speaker_paths);
1870 #define DEBUG_BADNESS
1872 #ifdef DEBUG_BADNESS
1873 #define debug_badness(fmt, ...) \
1874 codec_dbg(codec, fmt, ##__VA_ARGS__)
1876 #define debug_badness(fmt, ...) \
1877 do { if (0) codec_dbg(codec, fmt, ##__VA_ARGS__); } while (0)
1880 #ifdef DEBUG_BADNESS
1881 static inline void print_nid_path_idx(struct hda_codec *codec,
1882 const char *pfx, int idx)
1884 struct nid_path *path;
1886 path = snd_hda_get_path_from_idx(codec, idx);
1888 print_nid_path(codec, pfx, path);
1891 static void debug_show_configs(struct hda_codec *codec,
1892 struct auto_pin_cfg *cfg)
1894 struct hda_gen_spec *spec = codec->spec;
1895 static const char * const lo_type[3] = { "LO", "SP", "HP" };
1898 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x (type %s)\n",
1899 cfg->line_out_pins[0], cfg->line_out_pins[1],
1900 cfg->line_out_pins[2], cfg->line_out_pins[3],
1901 spec->multiout.dac_nids[0],
1902 spec->multiout.dac_nids[1],
1903 spec->multiout.dac_nids[2],
1904 spec->multiout.dac_nids[3],
1905 lo_type[cfg->line_out_type]);
1906 for (i = 0; i < cfg->line_outs; i++)
1907 print_nid_path_idx(codec, " out", spec->out_paths[i]);
1908 if (spec->multi_ios > 0)
1909 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
1911 spec->multi_io[0].pin, spec->multi_io[1].pin,
1912 spec->multi_io[0].dac, spec->multi_io[1].dac);
1913 for (i = 0; i < spec->multi_ios; i++)
1914 print_nid_path_idx(codec, " mio",
1915 spec->out_paths[cfg->line_outs + i]);
1917 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
1918 cfg->hp_pins[0], cfg->hp_pins[1],
1919 cfg->hp_pins[2], cfg->hp_pins[3],
1920 spec->multiout.hp_out_nid[0],
1921 spec->multiout.hp_out_nid[1],
1922 spec->multiout.hp_out_nid[2],
1923 spec->multiout.hp_out_nid[3]);
1924 for (i = 0; i < cfg->hp_outs; i++)
1925 print_nid_path_idx(codec, " hp ", spec->hp_paths[i]);
1926 if (cfg->speaker_outs)
1927 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
1928 cfg->speaker_pins[0], cfg->speaker_pins[1],
1929 cfg->speaker_pins[2], cfg->speaker_pins[3],
1930 spec->multiout.extra_out_nid[0],
1931 spec->multiout.extra_out_nid[1],
1932 spec->multiout.extra_out_nid[2],
1933 spec->multiout.extra_out_nid[3]);
1934 for (i = 0; i < cfg->speaker_outs; i++)
1935 print_nid_path_idx(codec, " spk", spec->speaker_paths[i]);
1936 for (i = 0; i < 3; i++)
1937 print_nid_path_idx(codec, " mix", spec->aamix_out_paths[i]);
1940 #define debug_show_configs(codec, cfg) /* NOP */
1943 /* find all available DACs of the codec */
1944 static void fill_all_dac_nids(struct hda_codec *codec)
1946 struct hda_gen_spec *spec = codec->spec;
1949 spec->num_all_dacs = 0;
1950 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
1951 for_each_hda_codec_node(nid, codec) {
1952 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
1954 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
1955 codec_err(codec, "Too many DACs!\n");
1958 spec->all_dacs[spec->num_all_dacs++] = nid;
1962 static int parse_output_paths(struct hda_codec *codec)
1964 struct hda_gen_spec *spec = codec->spec;
1965 struct auto_pin_cfg *cfg = &spec->autocfg;
1966 struct auto_pin_cfg *best_cfg;
1968 int best_badness = INT_MAX;
1970 bool fill_hardwired = true, fill_mio_first = true;
1971 bool best_wired = true, best_mio = true;
1972 bool hp_spk_swapped = false;
1974 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
1980 badness = fill_and_eval_dacs(codec, fill_hardwired,
1986 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
1987 cfg->line_out_type, fill_hardwired, fill_mio_first,
1989 debug_show_configs(codec, cfg);
1990 if (badness < best_badness) {
1991 best_badness = badness;
1993 best_wired = fill_hardwired;
1994 best_mio = fill_mio_first;
1998 fill_mio_first = !fill_mio_first;
1999 if (!fill_mio_first)
2001 fill_hardwired = !fill_hardwired;
2002 if (!fill_hardwired)
2006 hp_spk_swapped = true;
2007 if (cfg->speaker_outs > 0 &&
2008 cfg->line_out_type == AUTO_PIN_HP_OUT) {
2009 cfg->hp_outs = cfg->line_outs;
2010 memcpy(cfg->hp_pins, cfg->line_out_pins,
2011 sizeof(cfg->hp_pins));
2012 cfg->line_outs = cfg->speaker_outs;
2013 memcpy(cfg->line_out_pins, cfg->speaker_pins,
2014 sizeof(cfg->speaker_pins));
2015 cfg->speaker_outs = 0;
2016 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
2017 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
2018 fill_hardwired = true;
2021 if (cfg->hp_outs > 0 &&
2022 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
2023 cfg->speaker_outs = cfg->line_outs;
2024 memcpy(cfg->speaker_pins, cfg->line_out_pins,
2025 sizeof(cfg->speaker_pins));
2026 cfg->line_outs = cfg->hp_outs;
2027 memcpy(cfg->line_out_pins, cfg->hp_pins,
2028 sizeof(cfg->hp_pins));
2030 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
2031 cfg->line_out_type = AUTO_PIN_HP_OUT;
2032 fill_hardwired = true;
2039 debug_badness("==> restoring best_cfg\n");
2041 fill_and_eval_dacs(codec, best_wired, best_mio);
2043 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
2044 cfg->line_out_type, best_wired, best_mio);
2045 debug_show_configs(codec, cfg);
2047 if (cfg->line_out_pins[0]) {
2048 struct nid_path *path;
2049 path = snd_hda_get_path_from_idx(codec, spec->out_paths[0]);
2051 spec->vmaster_nid = look_for_out_vol_nid(codec, path);
2052 if (spec->vmaster_nid) {
2053 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2054 HDA_OUTPUT, spec->vmaster_tlv);
2055 if (spec->dac_min_mute)
2056 spec->vmaster_tlv[SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP] |= TLV_DB_SCALE_MUTE;
2060 /* set initial pinctl targets */
2061 if (spec->prefer_hp_amp || cfg->line_out_type == AUTO_PIN_HP_OUT)
2065 set_pin_targets(codec, cfg->line_outs, cfg->line_out_pins, val);
2066 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
2067 set_pin_targets(codec, cfg->hp_outs, cfg->hp_pins, PIN_HP);
2068 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
2069 val = spec->prefer_hp_amp ? PIN_HP : PIN_OUT;
2070 set_pin_targets(codec, cfg->speaker_outs,
2071 cfg->speaker_pins, val);
2074 /* clear indep_hp flag if not available */
2075 if (spec->indep_hp && !indep_hp_possible(codec))
2082 /* add playback controls from the parsed DAC table */
2083 static int create_multi_out_ctls(struct hda_codec *codec,
2084 const struct auto_pin_cfg *cfg)
2086 struct hda_gen_spec *spec = codec->spec;
2087 int i, err, noutputs;
2089 noutputs = cfg->line_outs;
2090 if (spec->multi_ios > 0 && cfg->line_outs < 3)
2091 noutputs += spec->multi_ios;
2093 for (i = 0; i < noutputs; i++) {
2096 struct nid_path *path;
2098 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
2102 name = get_line_out_pfx(codec, i, &index, NID_PATH_VOL_CTL);
2103 if (!name || !strcmp(name, "CLFE")) {
2105 err = add_vol_ctl(codec, "Center", 0, 1, path);
2108 err = add_vol_ctl(codec, "LFE", 0, 2, path);
2112 err = add_stereo_vol(codec, name, index, path);
2117 name = get_line_out_pfx(codec, i, &index, NID_PATH_MUTE_CTL);
2118 if (!name || !strcmp(name, "CLFE")) {
2119 err = add_sw_ctl(codec, "Center", 0, 1, path);
2122 err = add_sw_ctl(codec, "LFE", 0, 2, path);
2126 err = add_stereo_sw(codec, name, index, path);
2134 static int create_extra_out(struct hda_codec *codec, int path_idx,
2135 const char *pfx, int cidx)
2137 struct nid_path *path;
2140 path = snd_hda_get_path_from_idx(codec, path_idx);
2143 err = add_stereo_vol(codec, pfx, cidx, path);
2146 err = add_stereo_sw(codec, pfx, cidx, path);
2152 /* add playback controls for speaker and HP outputs */
2153 static int create_extra_outs(struct hda_codec *codec, int num_pins,
2154 const int *paths, const char *pfx)
2158 for (i = 0; i < num_pins; i++) {
2160 char tmp[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
2163 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker"))
2164 name = "Bass Speaker";
2165 else if (num_pins >= 3) {
2166 snprintf(tmp, sizeof(tmp), "%s %s",
2167 pfx, channel_name[i]);
2173 err = create_extra_out(codec, paths[i], name, idx);
2180 static int create_hp_out_ctls(struct hda_codec *codec)
2182 struct hda_gen_spec *spec = codec->spec;
2183 return create_extra_outs(codec, spec->autocfg.hp_outs,
2188 static int create_speaker_out_ctls(struct hda_codec *codec)
2190 struct hda_gen_spec *spec = codec->spec;
2191 return create_extra_outs(codec, spec->autocfg.speaker_outs,
2192 spec->speaker_paths,
2197 * independent HP controls
2200 static void call_hp_automute(struct hda_codec *codec,
2201 struct hda_jack_callback *jack);
2202 static int indep_hp_info(struct snd_kcontrol *kcontrol,
2203 struct snd_ctl_elem_info *uinfo)
2205 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
2208 static int indep_hp_get(struct snd_kcontrol *kcontrol,
2209 struct snd_ctl_elem_value *ucontrol)
2211 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2212 struct hda_gen_spec *spec = codec->spec;
2213 ucontrol->value.enumerated.item[0] = spec->indep_hp_enabled;
2217 static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
2218 int nomix_path_idx, int mix_path_idx,
2221 static int indep_hp_put(struct snd_kcontrol *kcontrol,
2222 struct snd_ctl_elem_value *ucontrol)
2224 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2225 struct hda_gen_spec *spec = codec->spec;
2226 unsigned int select = ucontrol->value.enumerated.item[0];
2229 mutex_lock(&spec->pcm_mutex);
2230 if (spec->active_streams) {
2235 if (spec->indep_hp_enabled != select) {
2237 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
2238 dacp = &spec->private_dac_nids[0];
2240 dacp = &spec->multiout.hp_out_nid[0];
2242 /* update HP aamix paths in case it conflicts with indep HP */
2243 if (spec->have_aamix_ctl) {
2244 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
2245 update_aamix_paths(codec, spec->aamix_mode,
2247 spec->aamix_out_paths[0],
2248 spec->autocfg.line_out_type);
2250 update_aamix_paths(codec, spec->aamix_mode,
2252 spec->aamix_out_paths[1],
2256 spec->indep_hp_enabled = select;
2257 if (spec->indep_hp_enabled)
2260 *dacp = spec->alt_dac_nid;
2262 call_hp_automute(codec, NULL);
2266 mutex_unlock(&spec->pcm_mutex);
2270 static const struct snd_kcontrol_new indep_hp_ctl = {
2271 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2272 .name = "Independent HP",
2273 .info = indep_hp_info,
2274 .get = indep_hp_get,
2275 .put = indep_hp_put,
2279 static int create_indep_hp_ctls(struct hda_codec *codec)
2281 struct hda_gen_spec *spec = codec->spec;
2284 if (!spec->indep_hp)
2286 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
2287 dac = spec->multiout.dac_nids[0];
2289 dac = spec->multiout.hp_out_nid[0];
2295 spec->indep_hp_enabled = false;
2296 spec->alt_dac_nid = dac;
2297 if (!snd_hda_gen_add_kctl(spec, NULL, &indep_hp_ctl))
2303 * channel mode enum control
2306 static int ch_mode_info(struct snd_kcontrol *kcontrol,
2307 struct snd_ctl_elem_info *uinfo)
2309 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2310 struct hda_gen_spec *spec = codec->spec;
2313 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2315 uinfo->value.enumerated.items = spec->multi_ios + 1;
2316 if (uinfo->value.enumerated.item > spec->multi_ios)
2317 uinfo->value.enumerated.item = spec->multi_ios;
2318 chs = uinfo->value.enumerated.item * 2 + spec->min_channel_count;
2319 sprintf(uinfo->value.enumerated.name, "%dch", chs);
2323 static int ch_mode_get(struct snd_kcontrol *kcontrol,
2324 struct snd_ctl_elem_value *ucontrol)
2326 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2327 struct hda_gen_spec *spec = codec->spec;
2328 ucontrol->value.enumerated.item[0] =
2329 (spec->ext_channel_count - spec->min_channel_count) / 2;
2333 static inline struct nid_path *
2334 get_multiio_path(struct hda_codec *codec, int idx)
2336 struct hda_gen_spec *spec = codec->spec;
2337 return snd_hda_get_path_from_idx(codec,
2338 spec->out_paths[spec->autocfg.line_outs + idx]);
2341 static void update_automute_all(struct hda_codec *codec);
2343 /* Default value to be passed as aamix argument for snd_hda_activate_path();
2344 * used for output paths
2346 static bool aamix_default(struct hda_gen_spec *spec)
2348 return !spec->have_aamix_ctl || spec->aamix_mode;
2351 static int set_multi_io(struct hda_codec *codec, int idx, bool output)
2353 struct hda_gen_spec *spec = codec->spec;
2354 hda_nid_t nid = spec->multi_io[idx].pin;
2355 struct nid_path *path;
2357 path = get_multiio_path(codec, idx);
2361 if (path->active == output)
2365 set_pin_target(codec, nid, PIN_OUT, true);
2366 snd_hda_activate_path(codec, path, true, aamix_default(spec));
2367 set_pin_eapd(codec, nid, true);
2369 set_pin_eapd(codec, nid, false);
2370 snd_hda_activate_path(codec, path, false, aamix_default(spec));
2371 set_pin_target(codec, nid, spec->multi_io[idx].ctl_in, true);
2372 path_power_down_sync(codec, path);
2375 /* update jack retasking in case it modifies any of them */
2376 update_automute_all(codec);
2381 static int ch_mode_put(struct snd_kcontrol *kcontrol,
2382 struct snd_ctl_elem_value *ucontrol)
2384 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2385 struct hda_gen_spec *spec = codec->spec;
2388 ch = ucontrol->value.enumerated.item[0];
2389 if (ch < 0 || ch > spec->multi_ios)
2391 if (ch == (spec->ext_channel_count - spec->min_channel_count) / 2)
2393 spec->ext_channel_count = ch * 2 + spec->min_channel_count;
2394 for (i = 0; i < spec->multi_ios; i++)
2395 set_multi_io(codec, i, i < ch);
2396 spec->multiout.max_channels = max(spec->ext_channel_count,
2397 spec->const_channel_count);
2398 if (spec->need_dac_fix)
2399 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
2403 static const struct snd_kcontrol_new channel_mode_enum = {
2404 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2405 .name = "Channel Mode",
2406 .info = ch_mode_info,
2411 static int create_multi_channel_mode(struct hda_codec *codec)
2413 struct hda_gen_spec *spec = codec->spec;
2415 if (spec->multi_ios > 0) {
2416 if (!snd_hda_gen_add_kctl(spec, NULL, &channel_mode_enum))
2423 * aamix loopback enable/disable switch
2426 #define loopback_mixing_info indep_hp_info
2428 static int loopback_mixing_get(struct snd_kcontrol *kcontrol,
2429 struct snd_ctl_elem_value *ucontrol)
2431 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2432 struct hda_gen_spec *spec = codec->spec;
2433 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2437 static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
2438 int nomix_path_idx, int mix_path_idx,
2441 struct hda_gen_spec *spec = codec->spec;
2442 struct nid_path *nomix_path, *mix_path;
2444 nomix_path = snd_hda_get_path_from_idx(codec, nomix_path_idx);
2445 mix_path = snd_hda_get_path_from_idx(codec, mix_path_idx);
2446 if (!nomix_path || !mix_path)
2449 /* if HP aamix path is driven from a different DAC and the
2450 * independent HP mode is ON, can't turn on aamix path
2452 if (out_type == AUTO_PIN_HP_OUT && spec->indep_hp_enabled &&
2453 mix_path->path[0] != spec->alt_dac_nid)
2457 snd_hda_activate_path(codec, nomix_path, false, true);
2458 snd_hda_activate_path(codec, mix_path, true, true);
2459 path_power_down_sync(codec, nomix_path);
2461 snd_hda_activate_path(codec, mix_path, false, false);
2462 snd_hda_activate_path(codec, nomix_path, true, false);
2463 path_power_down_sync(codec, mix_path);
2467 /* re-initialize the output paths; only called from loopback_mixing_put() */
2468 static void update_output_paths(struct hda_codec *codec, int num_outs,
2471 struct hda_gen_spec *spec = codec->spec;
2472 struct nid_path *path;
2475 for (i = 0; i < num_outs; i++) {
2476 path = snd_hda_get_path_from_idx(codec, paths[i]);
2478 snd_hda_activate_path(codec, path, path->active,
2483 static int loopback_mixing_put(struct snd_kcontrol *kcontrol,
2484 struct snd_ctl_elem_value *ucontrol)
2486 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2487 struct hda_gen_spec *spec = codec->spec;
2488 const struct auto_pin_cfg *cfg = &spec->autocfg;
2489 unsigned int val = ucontrol->value.enumerated.item[0];
2491 if (val == spec->aamix_mode)
2493 spec->aamix_mode = val;
2494 if (has_aamix_out_paths(spec)) {
2495 update_aamix_paths(codec, val, spec->out_paths[0],
2496 spec->aamix_out_paths[0],
2497 cfg->line_out_type);
2498 update_aamix_paths(codec, val, spec->hp_paths[0],
2499 spec->aamix_out_paths[1],
2501 update_aamix_paths(codec, val, spec->speaker_paths[0],
2502 spec->aamix_out_paths[2],
2503 AUTO_PIN_SPEAKER_OUT);
2505 update_output_paths(codec, cfg->line_outs, spec->out_paths);
2506 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
2507 update_output_paths(codec, cfg->hp_outs, spec->hp_paths);
2508 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
2509 update_output_paths(codec, cfg->speaker_outs,
2510 spec->speaker_paths);
2515 static const struct snd_kcontrol_new loopback_mixing_enum = {
2516 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2517 .name = "Loopback Mixing",
2518 .info = loopback_mixing_info,
2519 .get = loopback_mixing_get,
2520 .put = loopback_mixing_put,
2523 static int create_loopback_mixing_ctl(struct hda_codec *codec)
2525 struct hda_gen_spec *spec = codec->spec;
2527 if (!spec->mixer_nid)
2529 if (!snd_hda_gen_add_kctl(spec, NULL, &loopback_mixing_enum))
2531 spec->have_aamix_ctl = 1;
2536 * shared headphone/mic handling
2539 static void call_update_outputs(struct hda_codec *codec);
2541 /* for shared I/O, change the pin-control accordingly */
2542 static void update_hp_mic(struct hda_codec *codec, int adc_mux, bool force)
2544 struct hda_gen_spec *spec = codec->spec;
2549 pin = spec->hp_mic_pin;
2550 as_mic = spec->cur_mux[adc_mux] == spec->hp_mic_mux_idx;
2553 val = snd_hda_codec_get_pin_target(codec, pin);
2563 val = snd_hda_get_default_vref(codec, pin);
2564 /* if the HP pin doesn't support VREF and the codec driver gives an
2565 * alternative pin, set up the VREF on that pin instead
2567 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
2568 const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
2569 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
2570 if (vref_val != AC_PINCTL_VREF_HIZ)
2571 snd_hda_set_pin_ctl_cache(codec, vref_pin,
2572 PIN_IN | (as_mic ? vref_val : 0));
2575 if (!spec->hp_mic_jack_modes) {
2580 set_pin_target(codec, pin, val, true);
2581 call_hp_automute(codec, NULL);
2585 /* create a shared input with the headphone out */
2586 static int create_hp_mic(struct hda_codec *codec)
2588 struct hda_gen_spec *spec = codec->spec;
2589 struct auto_pin_cfg *cfg = &spec->autocfg;
2590 unsigned int defcfg;
2593 if (!spec->hp_mic) {
2594 if (spec->suppress_hp_mic_detect)
2596 /* automatic detection: only if no input or a single internal
2597 * input pin is found, try to detect the shared hp/mic
2599 if (cfg->num_inputs > 1)
2601 else if (cfg->num_inputs == 1) {
2602 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2603 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2608 spec->hp_mic = 0; /* clear once */
2609 if (cfg->num_inputs >= AUTO_CFG_MAX_INS)
2613 if (cfg->line_out_type == AUTO_PIN_HP_OUT && cfg->line_outs > 0)
2614 nid = cfg->line_out_pins[0];
2615 else if (cfg->hp_outs > 0)
2616 nid = cfg->hp_pins[0];
2620 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2621 return 0; /* no input */
2623 cfg->inputs[cfg->num_inputs].pin = nid;
2624 cfg->inputs[cfg->num_inputs].type = AUTO_PIN_MIC;
2625 cfg->inputs[cfg->num_inputs].is_headphone_mic = 1;
2628 spec->hp_mic_pin = nid;
2629 /* we can't handle auto-mic together with HP-mic */
2630 spec->suppress_auto_mic = 1;
2631 codec_dbg(codec, "Enable shared I/O jack on NID 0x%x\n", nid);
2639 static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin);
2641 static const char * const out_jack_texts[] = {
2642 "Line Out", "Headphone Out",
2645 static int out_jack_mode_info(struct snd_kcontrol *kcontrol,
2646 struct snd_ctl_elem_info *uinfo)
2648 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, out_jack_texts);
2651 static int out_jack_mode_get(struct snd_kcontrol *kcontrol,
2652 struct snd_ctl_elem_value *ucontrol)
2654 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2655 hda_nid_t nid = kcontrol->private_value;
2656 if (snd_hda_codec_get_pin_target(codec, nid) == PIN_HP)
2657 ucontrol->value.enumerated.item[0] = 1;
2659 ucontrol->value.enumerated.item[0] = 0;
2663 static int out_jack_mode_put(struct snd_kcontrol *kcontrol,
2664 struct snd_ctl_elem_value *ucontrol)
2666 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2667 hda_nid_t nid = kcontrol->private_value;
2670 val = ucontrol->value.enumerated.item[0] ? PIN_HP : PIN_OUT;
2671 if (snd_hda_codec_get_pin_target(codec, nid) == val)
2673 snd_hda_set_pin_ctl_cache(codec, nid, val);
2677 static const struct snd_kcontrol_new out_jack_mode_enum = {
2678 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2679 .info = out_jack_mode_info,
2680 .get = out_jack_mode_get,
2681 .put = out_jack_mode_put,
2684 static bool find_kctl_name(struct hda_codec *codec, const char *name, int idx)
2686 struct hda_gen_spec *spec = codec->spec;
2687 const struct snd_kcontrol_new *kctl;
2690 snd_array_for_each(&spec->kctls, i, kctl) {
2691 if (!strcmp(kctl->name, name) && kctl->index == idx)
2697 static void get_jack_mode_name(struct hda_codec *codec, hda_nid_t pin,
2698 char *name, size_t name_len)
2700 struct hda_gen_spec *spec = codec->spec;
2703 snd_hda_get_pin_label(codec, pin, &spec->autocfg, name, name_len, &idx);
2704 strlcat(name, " Jack Mode", name_len);
2706 for (; find_kctl_name(codec, name, idx); idx++)
2710 static int get_out_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2712 struct hda_gen_spec *spec = codec->spec;
2713 if (spec->add_jack_modes) {
2714 unsigned int pincap = snd_hda_query_pin_caps(codec, pin);
2715 if ((pincap & AC_PINCAP_OUT) && (pincap & AC_PINCAP_HP_DRV))
2721 static int create_out_jack_modes(struct hda_codec *codec, int num_pins,
2724 struct hda_gen_spec *spec = codec->spec;
2727 for (i = 0; i < num_pins; i++) {
2728 hda_nid_t pin = pins[i];
2729 if (pin == spec->hp_mic_pin)
2731 if (get_out_jack_num_items(codec, pin) > 1) {
2732 struct snd_kcontrol_new *knew;
2733 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
2734 get_jack_mode_name(codec, pin, name, sizeof(name));
2735 knew = snd_hda_gen_add_kctl(spec, name,
2736 &out_jack_mode_enum);
2739 knew->private_value = pin;
2750 /* from AC_PINCTL_VREF_HIZ to AC_PINCTL_VREF_100 */
2753 static const char * const vref_texts[NUM_VREFS] = {
2754 "Line In", "Mic 50pc Bias", "Mic 0V Bias",
2755 "", "Mic 80pc Bias", "Mic 100pc Bias"
2758 static unsigned int get_vref_caps(struct hda_codec *codec, hda_nid_t pin)
2760 unsigned int pincap;
2762 pincap = snd_hda_query_pin_caps(codec, pin);
2763 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2764 /* filter out unusual vrefs */
2765 pincap &= ~(AC_PINCAP_VREF_GRD | AC_PINCAP_VREF_100);
2769 /* convert from the enum item index to the vref ctl index (0=HIZ, 1=50%...) */
2770 static int get_vref_idx(unsigned int vref_caps, unsigned int item_idx)
2772 unsigned int i, n = 0;
2774 for (i = 0; i < NUM_VREFS; i++) {
2775 if (vref_caps & (1 << i)) {
2784 /* convert back from the vref ctl index to the enum item index */
2785 static int cvt_from_vref_idx(unsigned int vref_caps, unsigned int idx)
2787 unsigned int i, n = 0;
2789 for (i = 0; i < NUM_VREFS; i++) {
2792 if (vref_caps & (1 << i))
2798 static int in_jack_mode_info(struct snd_kcontrol *kcontrol,
2799 struct snd_ctl_elem_info *uinfo)
2801 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2802 hda_nid_t nid = kcontrol->private_value;
2803 unsigned int vref_caps = get_vref_caps(codec, nid);
2805 snd_hda_enum_helper_info(kcontrol, uinfo, hweight32(vref_caps),
2807 /* set the right text */
2808 strcpy(uinfo->value.enumerated.name,
2809 vref_texts[get_vref_idx(vref_caps, uinfo->value.enumerated.item)]);
2813 static int in_jack_mode_get(struct snd_kcontrol *kcontrol,
2814 struct snd_ctl_elem_value *ucontrol)
2816 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2817 hda_nid_t nid = kcontrol->private_value;
2818 unsigned int vref_caps = get_vref_caps(codec, nid);
2821 idx = snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_VREFEN;
2822 ucontrol->value.enumerated.item[0] = cvt_from_vref_idx(vref_caps, idx);
2826 static int in_jack_mode_put(struct snd_kcontrol *kcontrol,
2827 struct snd_ctl_elem_value *ucontrol)
2829 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2830 hda_nid_t nid = kcontrol->private_value;
2831 unsigned int vref_caps = get_vref_caps(codec, nid);
2832 unsigned int val, idx;
2834 val = snd_hda_codec_get_pin_target(codec, nid);
2835 idx = cvt_from_vref_idx(vref_caps, val & AC_PINCTL_VREFEN);
2836 if (idx == ucontrol->value.enumerated.item[0])
2839 val &= ~AC_PINCTL_VREFEN;
2840 val |= get_vref_idx(vref_caps, ucontrol->value.enumerated.item[0]);
2841 snd_hda_set_pin_ctl_cache(codec, nid, val);
2845 static const struct snd_kcontrol_new in_jack_mode_enum = {
2846 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2847 .info = in_jack_mode_info,
2848 .get = in_jack_mode_get,
2849 .put = in_jack_mode_put,
2852 static int get_in_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2854 struct hda_gen_spec *spec = codec->spec;
2856 if (spec->add_jack_modes)
2857 nitems = hweight32(get_vref_caps(codec, pin));
2858 return nitems ? nitems : 1;
2861 static int create_in_jack_mode(struct hda_codec *codec, hda_nid_t pin)
2863 struct hda_gen_spec *spec = codec->spec;
2864 struct snd_kcontrol_new *knew;
2865 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
2866 unsigned int defcfg;
2868 if (pin == spec->hp_mic_pin)
2869 return 0; /* already done in create_out_jack_mode() */
2871 /* no jack mode for fixed pins */
2872 defcfg = snd_hda_codec_get_pincfg(codec, pin);
2873 if (snd_hda_get_input_pin_attr(defcfg) == INPUT_PIN_ATTR_INT)
2876 /* no multiple vref caps? */
2877 if (get_in_jack_num_items(codec, pin) <= 1)
2880 get_jack_mode_name(codec, pin, name, sizeof(name));
2881 knew = snd_hda_gen_add_kctl(spec, name, &in_jack_mode_enum);
2884 knew->private_value = pin;
2889 * HP/mic shared jack mode
2891 static int hp_mic_jack_mode_info(struct snd_kcontrol *kcontrol,
2892 struct snd_ctl_elem_info *uinfo)
2894 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2895 hda_nid_t nid = kcontrol->private_value;
2896 int out_jacks = get_out_jack_num_items(codec, nid);
2897 int in_jacks = get_in_jack_num_items(codec, nid);
2898 const char *text = NULL;
2901 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2903 uinfo->value.enumerated.items = out_jacks + in_jacks;
2904 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2905 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2906 idx = uinfo->value.enumerated.item;
2907 if (idx < out_jacks) {
2909 text = out_jack_texts[idx];
2911 text = "Headphone Out";
2915 unsigned int vref_caps = get_vref_caps(codec, nid);
2916 text = vref_texts[get_vref_idx(vref_caps, idx)];
2921 strcpy(uinfo->value.enumerated.name, text);
2925 static int get_cur_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t nid)
2927 int out_jacks = get_out_jack_num_items(codec, nid);
2928 int in_jacks = get_in_jack_num_items(codec, nid);
2929 unsigned int val = snd_hda_codec_get_pin_target(codec, nid);
2932 if (val & PIN_OUT) {
2933 if (out_jacks > 1 && val == PIN_HP)
2935 } else if (val & PIN_IN) {
2938 unsigned int vref_caps = get_vref_caps(codec, nid);
2939 val &= AC_PINCTL_VREFEN;
2940 idx += cvt_from_vref_idx(vref_caps, val);
2946 static int hp_mic_jack_mode_get(struct snd_kcontrol *kcontrol,
2947 struct snd_ctl_elem_value *ucontrol)
2949 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2950 hda_nid_t nid = kcontrol->private_value;
2951 ucontrol->value.enumerated.item[0] =
2952 get_cur_hp_mic_jack_mode(codec, nid);
2956 static int hp_mic_jack_mode_put(struct snd_kcontrol *kcontrol,
2957 struct snd_ctl_elem_value *ucontrol)
2959 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2960 hda_nid_t nid = kcontrol->private_value;
2961 int out_jacks = get_out_jack_num_items(codec, nid);
2962 int in_jacks = get_in_jack_num_items(codec, nid);
2963 unsigned int val, oldval, idx;
2965 oldval = get_cur_hp_mic_jack_mode(codec, nid);
2966 idx = ucontrol->value.enumerated.item[0];
2970 if (idx < out_jacks) {
2972 val = idx ? PIN_HP : PIN_OUT;
2978 unsigned int vref_caps = get_vref_caps(codec, nid);
2979 val = snd_hda_codec_get_pin_target(codec, nid);
2980 val &= ~(AC_PINCTL_VREFEN | PIN_HP);
2981 val |= get_vref_idx(vref_caps, idx) | PIN_IN;
2983 val = snd_hda_get_default_vref(codec, nid) | PIN_IN;
2985 snd_hda_set_pin_ctl_cache(codec, nid, val);
2986 call_hp_automute(codec, NULL);
2991 static const struct snd_kcontrol_new hp_mic_jack_mode_enum = {
2992 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2993 .info = hp_mic_jack_mode_info,
2994 .get = hp_mic_jack_mode_get,
2995 .put = hp_mic_jack_mode_put,
2998 static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin)
3000 struct hda_gen_spec *spec = codec->spec;
3001 struct snd_kcontrol_new *knew;
3003 knew = snd_hda_gen_add_kctl(spec, "Headphone Mic Jack Mode",
3004 &hp_mic_jack_mode_enum);
3007 knew->private_value = pin;
3008 spec->hp_mic_jack_modes = 1;
3016 /* add the powersave loopback-list entry */
3017 static int add_loopback_list(struct hda_gen_spec *spec, hda_nid_t mix, int idx)
3019 struct hda_amp_list *list;
3021 list = snd_array_new(&spec->loopback_list);
3025 list->dir = HDA_INPUT;
3027 spec->loopback.amplist = spec->loopback_list.list;
3031 /* return true if either a volume or a mute amp is found for the given
3032 * aamix path; the amp has to be either in the mixer node or its direct leaf
3034 static bool look_for_mix_leaf_ctls(struct hda_codec *codec, hda_nid_t mix_nid,
3035 hda_nid_t pin, unsigned int *mix_val,
3036 unsigned int *mute_val)
3039 const hda_nid_t *list;
3042 idx = snd_hda_get_conn_index(codec, mix_nid, pin, true);
3046 *mix_val = *mute_val = 0;
3047 if (nid_has_volume(codec, mix_nid, HDA_INPUT))
3048 *mix_val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
3049 if (nid_has_mute(codec, mix_nid, HDA_INPUT))
3050 *mute_val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
3051 if (*mix_val && *mute_val)
3054 /* check leaf node */
3055 num_conns = snd_hda_get_conn_list(codec, mix_nid, &list);
3056 if (num_conns < idx)
3059 if (!*mix_val && nid_has_volume(codec, nid, HDA_OUTPUT) &&
3060 !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_VOL_CTL))
3061 *mix_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3062 if (!*mute_val && nid_has_mute(codec, nid, HDA_OUTPUT) &&
3063 !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_MUTE_CTL))
3064 *mute_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3066 return *mix_val || *mute_val;
3069 /* create input playback/capture controls for the given pin */
3070 static int new_analog_input(struct hda_codec *codec, int input_idx,
3071 hda_nid_t pin, const char *ctlname, int ctlidx,
3074 struct hda_gen_spec *spec = codec->spec;
3075 struct nid_path *path;
3076 unsigned int mix_val, mute_val;
3079 if (!look_for_mix_leaf_ctls(codec, mix_nid, pin, &mix_val, &mute_val))
3082 path = snd_hda_add_new_path(codec, pin, mix_nid, 0);
3085 print_nid_path(codec, "loopback", path);
3086 spec->loopback_paths[input_idx] = snd_hda_get_path_idx(codec, path);
3088 idx = path->idx[path->depth - 1];
3090 err = __add_pb_vol_ctrl(spec, HDA_CTL_WIDGET_VOL, ctlname, ctlidx, mix_val);
3093 path->ctls[NID_PATH_VOL_CTL] = mix_val;
3097 err = __add_pb_sw_ctrl(spec, HDA_CTL_WIDGET_MUTE, ctlname, ctlidx, mute_val);
3100 path->ctls[NID_PATH_MUTE_CTL] = mute_val;
3103 path->active = true;
3104 path->stream_enabled = true; /* no DAC/ADC involved */
3105 err = add_loopback_list(spec, mix_nid, idx);
3109 if (spec->mixer_nid != spec->mixer_merge_nid &&
3110 !spec->loopback_merge_path) {
3111 path = snd_hda_add_new_path(codec, spec->mixer_nid,
3112 spec->mixer_merge_nid, 0);
3114 print_nid_path(codec, "loopback-merge", path);
3115 path->active = true;
3116 path->pin_fixed = true; /* static route */
3117 path->stream_enabled = true; /* no DAC/ADC involved */
3118 spec->loopback_merge_path =
3119 snd_hda_get_path_idx(codec, path);
3126 static int is_input_pin(struct hda_codec *codec, hda_nid_t nid)
3128 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
3129 return (pincap & AC_PINCAP_IN) != 0;
3132 /* Parse the codec tree and retrieve ADCs */
3133 static int fill_adc_nids(struct hda_codec *codec)
3135 struct hda_gen_spec *spec = codec->spec;
3137 hda_nid_t *adc_nids = spec->adc_nids;
3138 int max_nums = ARRAY_SIZE(spec->adc_nids);
3141 for_each_hda_codec_node(nid, codec) {
3142 unsigned int caps = get_wcaps(codec, nid);
3143 int type = get_wcaps_type(caps);
3145 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
3147 adc_nids[nums] = nid;
3148 if (++nums >= max_nums)
3151 spec->num_adc_nids = nums;
3153 /* copy the detected ADCs to all_adcs[] */
3154 spec->num_all_adcs = nums;
3155 memcpy(spec->all_adcs, spec->adc_nids, nums * sizeof(hda_nid_t));
3160 /* filter out invalid adc_nids that don't give all active input pins;
3161 * if needed, check whether dynamic ADC-switching is available
3163 static int check_dyn_adc_switch(struct hda_codec *codec)
3165 struct hda_gen_spec *spec = codec->spec;
3166 struct hda_input_mux *imux = &spec->input_mux;
3167 unsigned int ok_bits;
3172 for (n = 0; n < spec->num_adc_nids; n++) {
3173 for (i = 0; i < imux->num_items; i++) {
3174 if (!spec->input_paths[i][n])
3177 if (i >= imux->num_items) {
3178 ok_bits |= (1 << n);
3184 /* check whether ADC-switch is possible */
3185 for (i = 0; i < imux->num_items; i++) {
3186 for (n = 0; n < spec->num_adc_nids; n++) {
3187 if (spec->input_paths[i][n]) {
3188 spec->dyn_adc_idx[i] = n;
3194 codec_dbg(codec, "enabling ADC switching\n");
3195 spec->dyn_adc_switch = 1;
3196 } else if (nums != spec->num_adc_nids) {
3197 /* shrink the invalid adcs and input paths */
3199 for (n = 0; n < spec->num_adc_nids; n++) {
3200 if (!(ok_bits & (1 << n)))
3203 spec->adc_nids[nums] = spec->adc_nids[n];
3204 for (i = 0; i < imux->num_items; i++) {
3205 invalidate_nid_path(codec,
3206 spec->input_paths[i][nums]);
3207 spec->input_paths[i][nums] =
3208 spec->input_paths[i][n];
3209 spec->input_paths[i][n] = 0;
3214 spec->num_adc_nids = nums;
3217 if (imux->num_items == 1 ||
3218 (imux->num_items == 2 && spec->hp_mic)) {
3219 codec_dbg(codec, "reducing to a single ADC\n");
3220 spec->num_adc_nids = 1; /* reduce to a single ADC */
3223 /* single index for individual volumes ctls */
3224 if (!spec->dyn_adc_switch && spec->multi_cap_vol)
3225 spec->num_adc_nids = 1;
3230 /* parse capture source paths from the given pin and create imux items */
3231 static int parse_capture_source(struct hda_codec *codec, hda_nid_t pin,
3232 int cfg_idx, int num_adcs,
3233 const char *label, int anchor)
3235 struct hda_gen_spec *spec = codec->spec;
3236 struct hda_input_mux *imux = &spec->input_mux;
3237 int imux_idx = imux->num_items;
3238 bool imux_added = false;
3241 for (c = 0; c < num_adcs; c++) {
3242 struct nid_path *path;
3243 hda_nid_t adc = spec->adc_nids[c];
3245 if (!is_reachable_path(codec, pin, adc))
3247 path = snd_hda_add_new_path(codec, pin, adc, anchor);
3250 print_nid_path(codec, "input", path);
3251 spec->input_paths[imux_idx][c] =
3252 snd_hda_get_path_idx(codec, path);
3255 if (spec->hp_mic_pin == pin)
3256 spec->hp_mic_mux_idx = imux->num_items;
3257 spec->imux_pins[imux->num_items] = pin;
3258 snd_hda_add_imux_item(codec, imux, label, cfg_idx, NULL);
3260 if (spec->dyn_adc_switch)
3261 spec->dyn_adc_idx[imux_idx] = c;
3269 * create playback/capture controls for input pins
3272 /* fill the label for each input at first */
3273 static int fill_input_pin_labels(struct hda_codec *codec)
3275 struct hda_gen_spec *spec = codec->spec;
3276 const struct auto_pin_cfg *cfg = &spec->autocfg;
3279 for (i = 0; i < cfg->num_inputs; i++) {
3280 hda_nid_t pin = cfg->inputs[i].pin;
3284 if (!is_input_pin(codec, pin))
3287 label = hda_get_autocfg_input_label(codec, cfg, i);
3289 for (j = i - 1; j >= 0; j--) {
3290 if (spec->input_labels[j] &&
3291 !strcmp(spec->input_labels[j], label)) {
3292 idx = spec->input_label_idxs[j] + 1;
3297 spec->input_labels[i] = label;
3298 spec->input_label_idxs[i] = idx;
3304 #define CFG_IDX_MIX 99 /* a dummy cfg->input idx for stereo mix */
3306 static int create_input_ctls(struct hda_codec *codec)
3308 struct hda_gen_spec *spec = codec->spec;
3309 const struct auto_pin_cfg *cfg = &spec->autocfg;
3310 hda_nid_t mixer = spec->mixer_nid;
3315 num_adcs = fill_adc_nids(codec);
3319 err = fill_input_pin_labels(codec);
3323 for (i = 0; i < cfg->num_inputs; i++) {
3326 pin = cfg->inputs[i].pin;
3327 if (!is_input_pin(codec, pin))
3331 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3332 val |= snd_hda_get_default_vref(codec, pin);
3333 if (pin != spec->hp_mic_pin &&
3334 !snd_hda_codec_get_pin_target(codec, pin))
3335 set_pin_target(codec, pin, val, false);
3338 if (is_reachable_path(codec, pin, mixer)) {
3339 err = new_analog_input(codec, i, pin,
3340 spec->input_labels[i],
3341 spec->input_label_idxs[i],
3348 err = parse_capture_source(codec, pin, i, num_adcs,
3349 spec->input_labels[i], -mixer);
3353 if (spec->add_jack_modes) {
3354 err = create_in_jack_mode(codec, pin);
3360 /* add stereo mix when explicitly enabled via hint */
3361 if (mixer && spec->add_stereo_mix_input == HDA_HINT_STEREO_MIX_ENABLE) {
3362 err = parse_capture_source(codec, mixer, CFG_IDX_MIX, num_adcs,
3367 spec->suppress_auto_mic = 1;
3378 /* get the input path specified by the given adc and imux indices */
3379 static struct nid_path *get_input_path(struct hda_codec *codec, int adc_idx, int imux_idx)
3381 struct hda_gen_spec *spec = codec->spec;
3382 if (imux_idx < 0 || imux_idx >= HDA_MAX_NUM_INPUTS) {
3386 if (spec->dyn_adc_switch)
3387 adc_idx = spec->dyn_adc_idx[imux_idx];
3388 if (adc_idx < 0 || adc_idx >= AUTO_CFG_MAX_INS) {
3392 return snd_hda_get_path_from_idx(codec, spec->input_paths[imux_idx][adc_idx]);
3395 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3398 static int mux_enum_info(struct snd_kcontrol *kcontrol,
3399 struct snd_ctl_elem_info *uinfo)
3401 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3402 struct hda_gen_spec *spec = codec->spec;
3403 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
3406 static int mux_enum_get(struct snd_kcontrol *kcontrol,
3407 struct snd_ctl_elem_value *ucontrol)
3409 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3410 struct hda_gen_spec *spec = codec->spec;
3411 /* the ctls are created at once with multiple counts */
3412 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
3414 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
3418 static int mux_enum_put(struct snd_kcontrol *kcontrol,
3419 struct snd_ctl_elem_value *ucontrol)
3421 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3422 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
3423 return mux_select(codec, adc_idx,
3424 ucontrol->value.enumerated.item[0]);
3427 static const struct snd_kcontrol_new cap_src_temp = {
3428 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3429 .name = "Input Source",
3430 .info = mux_enum_info,
3431 .get = mux_enum_get,
3432 .put = mux_enum_put,
3436 * capture volume and capture switch ctls
3439 typedef int (*put_call_t)(struct snd_kcontrol *kcontrol,
3440 struct snd_ctl_elem_value *ucontrol);
3442 /* call the given amp update function for all amps in the imux list at once */
3443 static int cap_put_caller(struct snd_kcontrol *kcontrol,
3444 struct snd_ctl_elem_value *ucontrol,
3445 put_call_t func, int type)
3447 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3448 struct hda_gen_spec *spec = codec->spec;
3449 const struct hda_input_mux *imux;
3450 struct nid_path *path;
3451 int i, adc_idx, err = 0;
3453 imux = &spec->input_mux;
3454 adc_idx = kcontrol->id.index;
3455 mutex_lock(&codec->control_mutex);
3456 for (i = 0; i < imux->num_items; i++) {
3457 path = get_input_path(codec, adc_idx, i);
3458 if (!path || !path->ctls[type])
3460 kcontrol->private_value = path->ctls[type];
3461 err = func(kcontrol, ucontrol);
3465 mutex_unlock(&codec->control_mutex);
3466 if (err >= 0 && spec->cap_sync_hook)
3467 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3471 /* capture volume ctl callbacks */
3472 #define cap_vol_info snd_hda_mixer_amp_volume_info
3473 #define cap_vol_get snd_hda_mixer_amp_volume_get
3474 #define cap_vol_tlv snd_hda_mixer_amp_tlv
3476 static int cap_vol_put(struct snd_kcontrol *kcontrol,
3477 struct snd_ctl_elem_value *ucontrol)
3479 return cap_put_caller(kcontrol, ucontrol,
3480 snd_hda_mixer_amp_volume_put,
3484 static const struct snd_kcontrol_new cap_vol_temp = {
3485 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3486 .name = "Capture Volume",
3487 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
3488 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
3489 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
3490 .info = cap_vol_info,
3493 .tlv = { .c = cap_vol_tlv },
3496 /* capture switch ctl callbacks */
3497 #define cap_sw_info snd_ctl_boolean_stereo_info
3498 #define cap_sw_get snd_hda_mixer_amp_switch_get
3500 static int cap_sw_put(struct snd_kcontrol *kcontrol,
3501 struct snd_ctl_elem_value *ucontrol)
3503 return cap_put_caller(kcontrol, ucontrol,
3504 snd_hda_mixer_amp_switch_put,
3508 static const struct snd_kcontrol_new cap_sw_temp = {
3509 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3510 .name = "Capture Switch",
3511 .info = cap_sw_info,
3516 static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
3521 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
3522 for (depth = 0; depth < 3; depth++) {
3523 if (depth >= path->depth)
3525 i = path->depth - depth - 1;
3526 nid = path->path[i];
3527 if (!path->ctls[NID_PATH_VOL_CTL]) {
3528 if (nid_has_volume(codec, nid, HDA_OUTPUT))
3529 path->ctls[NID_PATH_VOL_CTL] =
3530 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3531 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
3532 int idx = path->idx[i];
3533 if (!depth && codec->single_adc_amp)
3535 path->ctls[NID_PATH_VOL_CTL] =
3536 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
3539 if (!path->ctls[NID_PATH_MUTE_CTL]) {
3540 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3541 path->ctls[NID_PATH_MUTE_CTL] =
3542 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3543 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
3544 int idx = path->idx[i];
3545 if (!depth && codec->single_adc_amp)
3547 path->ctls[NID_PATH_MUTE_CTL] =
3548 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
3555 static bool is_inv_dmic_pin(struct hda_codec *codec, hda_nid_t nid)
3557 struct hda_gen_spec *spec = codec->spec;
3558 struct auto_pin_cfg *cfg = &spec->autocfg;
3562 if (!spec->inv_dmic_split)
3564 for (i = 0; i < cfg->num_inputs; i++) {
3565 if (cfg->inputs[i].pin != nid)
3567 if (cfg->inputs[i].type != AUTO_PIN_MIC)
3569 val = snd_hda_codec_get_pincfg(codec, nid);
3570 return snd_hda_get_input_pin_attr(val) == INPUT_PIN_ATTR_INT;
3575 /* capture switch put callback for a single control with hook call */
3576 static int cap_single_sw_put(struct snd_kcontrol *kcontrol,
3577 struct snd_ctl_elem_value *ucontrol)
3579 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3580 struct hda_gen_spec *spec = codec->spec;
3583 ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3587 if (spec->cap_sync_hook)
3588 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3593 static int add_single_cap_ctl(struct hda_codec *codec, const char *label,
3594 int idx, bool is_switch, unsigned int ctl,
3597 struct hda_gen_spec *spec = codec->spec;
3598 char tmpname[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3599 int type = is_switch ? HDA_CTL_WIDGET_MUTE : HDA_CTL_WIDGET_VOL;
3600 const char *sfx = is_switch ? "Switch" : "Volume";
3601 unsigned int chs = inv_dmic ? 1 : 3;
3602 struct snd_kcontrol_new *knew;
3608 snprintf(tmpname, sizeof(tmpname),
3609 "%s Capture %s", label, sfx);
3611 snprintf(tmpname, sizeof(tmpname),
3613 knew = add_control(spec, type, tmpname, idx,
3614 amp_val_replace_channels(ctl, chs));
3618 knew->put = cap_single_sw_put;
3622 /* Make independent right kcontrol */
3624 snprintf(tmpname, sizeof(tmpname),
3625 "Inverted %s Capture %s", label, sfx);
3627 snprintf(tmpname, sizeof(tmpname),
3628 "Inverted Capture %s", sfx);
3629 knew = add_control(spec, type, tmpname, idx,
3630 amp_val_replace_channels(ctl, 2));
3634 knew->put = cap_single_sw_put;
3638 /* create single (and simple) capture volume and switch controls */
3639 static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx,
3640 unsigned int vol_ctl, unsigned int sw_ctl,
3644 err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl, inv_dmic);
3647 err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl, inv_dmic);
3653 /* create bound capture volume and switch controls */
3654 static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx,
3655 unsigned int vol_ctl, unsigned int sw_ctl)
3657 struct hda_gen_spec *spec = codec->spec;
3658 struct snd_kcontrol_new *knew;
3661 knew = snd_hda_gen_add_kctl(spec, NULL, &cap_vol_temp);
3665 knew->private_value = vol_ctl;
3666 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
3669 knew = snd_hda_gen_add_kctl(spec, NULL, &cap_sw_temp);
3673 knew->private_value = sw_ctl;
3674 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
3679 /* return the vol ctl when used first in the imux list */
3680 static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type)
3682 struct nid_path *path;
3686 path = get_input_path(codec, 0, idx);
3689 ctl = path->ctls[type];
3692 for (i = 0; i < idx - 1; i++) {
3693 path = get_input_path(codec, 0, i);
3694 if (path && path->ctls[type] == ctl)
3700 /* create individual capture volume and switch controls per input */
3701 static int create_multi_cap_vol_ctl(struct hda_codec *codec)
3703 struct hda_gen_spec *spec = codec->spec;
3704 struct hda_input_mux *imux = &spec->input_mux;
3707 for (i = 0; i < imux->num_items; i++) {
3711 idx = imux->items[i].index;
3712 if (idx >= spec->autocfg.num_inputs)
3714 inv_dmic = is_inv_dmic_pin(codec, spec->imux_pins[i]);
3716 for (type = 0; type < 2; type++) {
3717 err = add_single_cap_ctl(codec,
3718 spec->input_labels[idx],
3719 spec->input_label_idxs[idx],
3721 get_first_cap_ctl(codec, i, type),
3730 static int create_capture_mixers(struct hda_codec *codec)
3732 struct hda_gen_spec *spec = codec->spec;
3733 struct hda_input_mux *imux = &spec->input_mux;
3734 int i, n, nums, err;
3736 if (spec->dyn_adc_switch)
3739 nums = spec->num_adc_nids;
3741 if (!spec->auto_mic && imux->num_items > 1) {
3742 struct snd_kcontrol_new *knew;
3744 name = nums > 1 ? "Input Source" : "Capture Source";
3745 knew = snd_hda_gen_add_kctl(spec, name, &cap_src_temp);
3751 for (n = 0; n < nums; n++) {
3753 bool multi_cap_vol = spec->multi_cap_vol;
3754 bool inv_dmic = false;
3758 for (i = 0; i < imux->num_items; i++) {
3759 struct nid_path *path;
3760 path = get_input_path(codec, n, i);
3763 parse_capvol_in_path(codec, path);
3765 vol = path->ctls[NID_PATH_VOL_CTL];
3766 else if (vol != path->ctls[NID_PATH_VOL_CTL]) {
3768 if (!same_amp_caps(codec, vol,
3769 path->ctls[NID_PATH_VOL_CTL], HDA_INPUT))
3770 multi_cap_vol = true;
3773 sw = path->ctls[NID_PATH_MUTE_CTL];
3774 else if (sw != path->ctls[NID_PATH_MUTE_CTL]) {
3776 if (!same_amp_caps(codec, sw,
3777 path->ctls[NID_PATH_MUTE_CTL], HDA_INPUT))
3778 multi_cap_vol = true;
3780 if (is_inv_dmic_pin(codec, spec->imux_pins[i]))
3785 err = create_single_cap_vol_ctl(codec, n, vol, sw,
3787 else if (!multi_cap_vol && !inv_dmic)
3788 err = create_bind_cap_vol_ctl(codec, n, vol, sw);
3790 err = create_multi_cap_vol_ctl(codec);
3799 * add mic boosts if needed
3802 /* check whether the given amp is feasible as a boost volume */
3803 static bool check_boost_vol(struct hda_codec *codec, hda_nid_t nid,
3808 if (!nid_has_volume(codec, nid, dir) ||
3809 is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
3810 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
3813 step = (query_amp_caps(codec, nid, dir) & AC_AMPCAP_STEP_SIZE)
3814 >> AC_AMPCAP_STEP_SIZE_SHIFT;
3820 /* look for a boost amp in a widget close to the pin */
3821 static unsigned int look_for_boost_amp(struct hda_codec *codec,
3822 struct nid_path *path)
3824 unsigned int val = 0;
3828 for (depth = 0; depth < 3; depth++) {
3829 if (depth >= path->depth - 1)
3831 nid = path->path[depth];
3832 if (depth && check_boost_vol(codec, nid, HDA_OUTPUT, 0)) {
3833 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3835 } else if (check_boost_vol(codec, nid, HDA_INPUT,
3836 path->idx[depth])) {
3837 val = HDA_COMPOSE_AMP_VAL(nid, 3, path->idx[depth],
3846 static int parse_mic_boost(struct hda_codec *codec)
3848 struct hda_gen_spec *spec = codec->spec;
3849 struct auto_pin_cfg *cfg = &spec->autocfg;
3850 struct hda_input_mux *imux = &spec->input_mux;
3853 if (!spec->num_adc_nids)
3856 for (i = 0; i < imux->num_items; i++) {
3857 struct nid_path *path;
3860 char boost_label[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3862 idx = imux->items[i].index;
3863 if (idx >= imux->num_items)
3866 /* check only line-in and mic pins */
3867 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
3870 path = get_input_path(codec, 0, i);
3874 val = look_for_boost_amp(codec, path);
3878 /* create a boost control */
3879 snprintf(boost_label, sizeof(boost_label),
3880 "%s Boost Volume", spec->input_labels[idx]);
3881 if (!add_control(spec, HDA_CTL_WIDGET_VOL, boost_label,
3882 spec->input_label_idxs[idx], val))
3885 path->ctls[NID_PATH_BOOST_CTL] = val;
3890 #ifdef CONFIG_SND_HDA_GENERIC_LEDS
3892 * mic mute LED hook helpers
3897 MICMUTE_LED_FOLLOW_CAPTURE,
3898 MICMUTE_LED_FOLLOW_MUTE,
3901 static void call_micmute_led_update(struct hda_codec *codec)
3903 struct hda_gen_spec *spec = codec->spec;
3906 switch (spec->micmute_led.led_mode) {
3907 case MICMUTE_LED_ON:
3910 case MICMUTE_LED_OFF:
3913 case MICMUTE_LED_FOLLOW_CAPTURE:
3914 val = !!spec->micmute_led.capture;
3916 case MICMUTE_LED_FOLLOW_MUTE:
3918 val = !spec->micmute_led.capture;
3922 if (val == spec->micmute_led.led_value)
3924 spec->micmute_led.led_value = val;
3925 if (spec->micmute_led.update)
3926 spec->micmute_led.update(codec);
3927 ledtrig_audio_set(LED_AUDIO_MICMUTE,
3928 spec->micmute_led.led_value ? LED_ON : LED_OFF);
3931 static void update_micmute_led(struct hda_codec *codec,
3932 struct snd_kcontrol *kcontrol,
3933 struct snd_ctl_elem_value *ucontrol)
3935 struct hda_gen_spec *spec = codec->spec;
3938 if (spec->micmute_led.old_hook)
3939 spec->micmute_led.old_hook(codec, kcontrol, ucontrol);
3943 mask = 1U << snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
3944 if (!strcmp("Capture Switch", ucontrol->id.name)) {
3945 /* TODO: How do I verify if it's a mono or stereo here? */
3946 if (ucontrol->value.integer.value[0] ||
3947 ucontrol->value.integer.value[1])
3948 spec->micmute_led.capture |= mask;
3950 spec->micmute_led.capture &= ~mask;
3951 call_micmute_led_update(codec);
3955 static int micmute_led_mode_info(struct snd_kcontrol *kcontrol,
3956 struct snd_ctl_elem_info *uinfo)
3958 static const char * const texts[] = {
3959 "On", "Off", "Follow Capture", "Follow Mute",
3962 return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
3965 static int micmute_led_mode_get(struct snd_kcontrol *kcontrol,
3966 struct snd_ctl_elem_value *ucontrol)
3968 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3969 struct hda_gen_spec *spec = codec->spec;
3971 ucontrol->value.enumerated.item[0] = spec->micmute_led.led_mode;
3975 static int micmute_led_mode_put(struct snd_kcontrol *kcontrol,
3976 struct snd_ctl_elem_value *ucontrol)
3978 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3979 struct hda_gen_spec *spec = codec->spec;
3982 mode = ucontrol->value.enumerated.item[0];
3983 if (mode > MICMUTE_LED_FOLLOW_MUTE)
3984 mode = MICMUTE_LED_FOLLOW_MUTE;
3985 if (mode == spec->micmute_led.led_mode)
3987 spec->micmute_led.led_mode = mode;
3988 call_micmute_led_update(codec);
3992 static const struct snd_kcontrol_new micmute_led_mode_ctl = {
3993 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3994 .name = "Mic Mute-LED Mode",
3995 .info = micmute_led_mode_info,
3996 .get = micmute_led_mode_get,
3997 .put = micmute_led_mode_put,
4001 * snd_hda_gen_add_micmute_led - helper for setting up mic mute LED hook
4002 * @codec: the HDA codec
4003 * @hook: the callback for updating LED
4005 * Called from the codec drivers for offering the mic mute LED controls.
4006 * When established, it sets up cap_sync_hook and triggers the callback at
4007 * each time when the capture mixer switch changes. The callback is supposed
4008 * to update the LED accordingly.
4010 * Returns 0 if the hook is established or a negative error code.
4012 int snd_hda_gen_add_micmute_led(struct hda_codec *codec,
4013 void (*hook)(struct hda_codec *))
4015 struct hda_gen_spec *spec = codec->spec;
4017 spec->micmute_led.led_mode = MICMUTE_LED_FOLLOW_MUTE;
4018 spec->micmute_led.capture = 0;
4019 spec->micmute_led.led_value = 0;
4020 spec->micmute_led.old_hook = spec->cap_sync_hook;
4021 spec->micmute_led.update = hook;
4022 spec->cap_sync_hook = update_micmute_led;
4023 if (!snd_hda_gen_add_kctl(spec, NULL, &micmute_led_mode_ctl))
4027 EXPORT_SYMBOL_GPL(snd_hda_gen_add_micmute_led);
4030 * snd_dha_gen_add_micmute_led_cdev - Create a LED classdev and enable as mic-mute LED
4031 * @codec: the HDA codec
4032 * @callback: the callback for LED classdev brightness_set_blocking
4034 * Called from the codec drivers for offering the mic mute LED controls.
4035 * This creates a LED classdev and sets up the cap_sync_hook that is called at
4036 * each time when the capture mixer switch changes.
4038 * When NULL is passed to @callback, no classdev is created but only the
4039 * LED-trigger is set up.
4041 * Returns 0 or a negative error.
4043 int snd_hda_gen_add_micmute_led_cdev(struct hda_codec *codec,
4044 int (*callback)(struct led_classdev *,
4045 enum led_brightness))
4048 struct led_classdev *cdev;
4051 cdev = devm_kzalloc(&codec->core.dev, sizeof(*cdev), GFP_KERNEL);
4055 cdev->name = "hda::micmute";
4056 cdev->max_brightness = 1;
4057 cdev->default_trigger = "audio-micmute";
4058 cdev->brightness_set_blocking = callback;
4059 cdev->brightness = ledtrig_audio_get(LED_AUDIO_MICMUTE);
4061 err = devm_led_classdev_register(&codec->core.dev, cdev);
4063 codec_warn(codec, "failed to create a mic-mute LED cdev\n");
4068 return snd_hda_gen_add_micmute_led(codec, NULL);
4070 EXPORT_SYMBOL_GPL(snd_hda_gen_add_micmute_led_cdev);
4071 #endif /* CONFIG_SND_HDA_GENERIC_LEDS */
4074 * parse digital I/Os and set up NIDs in BIOS auto-parse mode
4076 static void parse_digital(struct hda_codec *codec)
4078 struct hda_gen_spec *spec = codec->spec;
4079 struct nid_path *path;
4081 hda_nid_t dig_nid, pin;
4083 /* support multiple SPDIFs; the secondary is set up as a slave */
4085 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4086 pin = spec->autocfg.dig_out_pins[i];
4087 dig_nid = look_for_dac(codec, pin, true);
4090 path = snd_hda_add_new_path(codec, dig_nid, pin, 0);
4093 print_nid_path(codec, "digout", path);
4094 path->active = true;
4095 path->pin_fixed = true; /* no jack detection */
4096 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
4097 set_pin_target(codec, pin, PIN_OUT, false);
4099 spec->multiout.dig_out_nid = dig_nid;
4100 spec->dig_out_type = spec->autocfg.dig_out_type[0];
4102 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4103 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
4105 spec->slave_dig_outs[nums - 1] = dig_nid;
4110 if (spec->autocfg.dig_in_pin) {
4111 pin = spec->autocfg.dig_in_pin;
4112 for_each_hda_codec_node(dig_nid, codec) {
4113 unsigned int wcaps = get_wcaps(codec, dig_nid);
4114 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
4116 if (!(wcaps & AC_WCAP_DIGITAL))
4118 path = snd_hda_add_new_path(codec, pin, dig_nid, 0);
4120 print_nid_path(codec, "digin", path);
4121 path->active = true;
4122 path->pin_fixed = true; /* no jack */
4123 spec->dig_in_nid = dig_nid;
4124 spec->digin_path = snd_hda_get_path_idx(codec, path);
4125 set_pin_target(codec, pin, PIN_IN, false);
4134 * input MUX handling
4137 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur);
4139 /* select the given imux item; either unmute exclusively or select the route */
4140 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
4143 struct hda_gen_spec *spec = codec->spec;
4144 const struct hda_input_mux *imux;
4145 struct nid_path *old_path, *path;
4147 imux = &spec->input_mux;
4148 if (!imux->num_items)
4151 if (idx >= imux->num_items)
4152 idx = imux->num_items - 1;
4153 if (spec->cur_mux[adc_idx] == idx)
4156 old_path = get_input_path(codec, adc_idx, spec->cur_mux[adc_idx]);
4159 if (old_path->active)
4160 snd_hda_activate_path(codec, old_path, false, false);
4162 spec->cur_mux[adc_idx] = idx;
4165 update_hp_mic(codec, adc_idx, false);
4167 if (spec->dyn_adc_switch)
4168 dyn_adc_pcm_resetup(codec, idx);
4170 path = get_input_path(codec, adc_idx, idx);
4175 snd_hda_activate_path(codec, path, true, false);
4176 if (spec->cap_sync_hook)
4177 spec->cap_sync_hook(codec, NULL, NULL);
4178 path_power_down_sync(codec, old_path);
4182 /* power up/down widgets in the all paths that match with the given NID
4183 * as terminals (either start- or endpoint)
4185 * returns the last changed NID, or zero if unchanged.
4187 static hda_nid_t set_path_power(struct hda_codec *codec, hda_nid_t nid,
4188 int pin_state, int stream_state)
4190 struct hda_gen_spec *spec = codec->spec;
4191 hda_nid_t last, changed = 0;
4192 struct nid_path *path;
4195 snd_array_for_each(&spec->paths, n, path) {
4198 if (path->path[0] == nid ||
4199 path->path[path->depth - 1] == nid) {
4200 bool pin_old = path->pin_enabled;
4201 bool stream_old = path->stream_enabled;
4204 path->pin_enabled = pin_state;
4205 if (stream_state >= 0)
4206 path->stream_enabled = stream_state;
4207 if ((!path->pin_fixed && path->pin_enabled != pin_old)
4208 || path->stream_enabled != stream_old) {
4209 last = path_power_update(codec, path, true);
4218 /* check the jack status for power control */
4219 static bool detect_pin_state(struct hda_codec *codec, hda_nid_t pin)
4221 if (!is_jack_detectable(codec, pin))
4223 return snd_hda_jack_detect_state(codec, pin) != HDA_JACK_NOT_PRESENT;
4226 /* power up/down the paths of the given pin according to the jack state;
4227 * power = 0/1 : only power up/down if it matches with the jack state,
4228 * < 0 : force power up/down to follow the jack sate
4230 * returns the last changed NID, or zero if unchanged.
4232 static hda_nid_t set_pin_power_jack(struct hda_codec *codec, hda_nid_t pin,
4237 if (!codec->power_save_node)
4240 on = detect_pin_state(codec, pin);
4242 if (power >= 0 && on != power)
4244 return set_path_power(codec, pin, on, -1);
4247 static void pin_power_callback(struct hda_codec *codec,
4248 struct hda_jack_callback *jack,
4251 if (jack && jack->nid)
4252 sync_power_state_change(codec,
4253 set_pin_power_jack(codec, jack->nid, on));
4256 /* callback only doing power up -- called at first */
4257 static void pin_power_up_callback(struct hda_codec *codec,
4258 struct hda_jack_callback *jack)
4260 pin_power_callback(codec, jack, true);
4263 /* callback only doing power down -- called at last */
4264 static void pin_power_down_callback(struct hda_codec *codec,
4265 struct hda_jack_callback *jack)
4267 pin_power_callback(codec, jack, false);
4270 /* set up the power up/down callbacks */
4271 static void add_pin_power_ctls(struct hda_codec *codec, int num_pins,
4272 const hda_nid_t *pins, bool on)
4275 hda_jack_callback_fn cb =
4276 on ? pin_power_up_callback : pin_power_down_callback;
4278 for (i = 0; i < num_pins && pins[i]; i++) {
4279 if (is_jack_detectable(codec, pins[i]))
4280 snd_hda_jack_detect_enable_callback(codec, pins[i], cb);
4282 set_path_power(codec, pins[i], true, -1);
4286 /* enabled power callback to each available I/O pin with jack detections;
4287 * the digital I/O pins are excluded because of the unreliable detectsion
4289 static void add_all_pin_power_ctls(struct hda_codec *codec, bool on)
4291 struct hda_gen_spec *spec = codec->spec;
4292 struct auto_pin_cfg *cfg = &spec->autocfg;
4295 if (!codec->power_save_node)
4297 add_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins, on);
4298 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
4299 add_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins, on);
4300 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
4301 add_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins, on);
4302 for (i = 0; i < cfg->num_inputs; i++)
4303 add_pin_power_ctls(codec, 1, &cfg->inputs[i].pin, on);
4306 /* sync path power up/down with the jack states of given pins */
4307 static void sync_pin_power_ctls(struct hda_codec *codec, int num_pins,
4308 const hda_nid_t *pins)
4312 for (i = 0; i < num_pins && pins[i]; i++)
4313 if (is_jack_detectable(codec, pins[i]))
4314 set_pin_power_jack(codec, pins[i], -1);
4317 /* sync path power up/down with pins; called at init and resume */
4318 static void sync_all_pin_power_ctls(struct hda_codec *codec)
4320 struct hda_gen_spec *spec = codec->spec;
4321 struct auto_pin_cfg *cfg = &spec->autocfg;
4324 if (!codec->power_save_node)
4326 sync_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins);
4327 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
4328 sync_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins);
4329 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
4330 sync_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins);
4331 for (i = 0; i < cfg->num_inputs; i++)
4332 sync_pin_power_ctls(codec, 1, &cfg->inputs[i].pin);
4335 /* add fake paths if not present yet */
4336 static int add_fake_paths(struct hda_codec *codec, hda_nid_t nid,
4337 int num_pins, const hda_nid_t *pins)
4339 struct hda_gen_spec *spec = codec->spec;
4340 struct nid_path *path;
4343 for (i = 0; i < num_pins; i++) {
4346 if (get_nid_path(codec, nid, pins[i], 0))
4348 path = snd_array_new(&spec->paths);
4351 memset(path, 0, sizeof(*path));
4353 path->path[0] = nid;
4354 path->path[1] = pins[i];
4355 path->active = true;
4360 /* create fake paths to all outputs from beep */
4361 static int add_fake_beep_paths(struct hda_codec *codec)
4363 struct hda_gen_spec *spec = codec->spec;
4364 struct auto_pin_cfg *cfg = &spec->autocfg;
4365 hda_nid_t nid = spec->beep_nid;
4368 if (!codec->power_save_node || !nid)
4370 err = add_fake_paths(codec, nid, cfg->line_outs, cfg->line_out_pins);
4373 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
4374 err = add_fake_paths(codec, nid, cfg->hp_outs, cfg->hp_pins);
4378 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
4379 err = add_fake_paths(codec, nid, cfg->speaker_outs,
4387 /* power up/down beep widget and its output paths */
4388 static void beep_power_hook(struct hda_beep *beep, bool on)
4390 set_path_power(beep->codec, beep->nid, -1, on);
4394 * snd_hda_gen_fix_pin_power - Fix the power of the given pin widget to D0
4395 * @codec: the HDA codec
4396 * @pin: NID of pin to fix
4398 int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin)
4400 struct hda_gen_spec *spec = codec->spec;
4401 struct nid_path *path;
4403 path = snd_array_new(&spec->paths);
4406 memset(path, 0, sizeof(*path));
4408 path->path[0] = pin;
4409 path->active = true;
4410 path->pin_fixed = true;
4411 path->stream_enabled = true;
4414 EXPORT_SYMBOL_GPL(snd_hda_gen_fix_pin_power);
4417 * Jack detections for HP auto-mute and mic-switch
4420 /* check each pin in the given array; returns true if any of them is plugged */
4421 static bool detect_jacks(struct hda_codec *codec, int num_pins, const hda_nid_t *pins)
4424 bool present = false;
4426 for (i = 0; i < num_pins; i++) {
4427 hda_nid_t nid = pins[i];
4430 /* don't detect pins retasked as inputs */
4431 if (snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_IN_EN)
4433 if (snd_hda_jack_detect_state(codec, nid) == HDA_JACK_PRESENT)
4439 /* standard HP/line-out auto-mute helper */
4440 static void do_automute(struct hda_codec *codec, int num_pins, const hda_nid_t *pins,
4441 int *paths, bool mute)
4443 struct hda_gen_spec *spec = codec->spec;
4446 for (i = 0; i < num_pins; i++) {
4447 hda_nid_t nid = pins[i];
4448 unsigned int val, oldval;
4452 oldval = snd_hda_codec_get_pin_target(codec, nid);
4453 if (oldval & PIN_IN)
4454 continue; /* no mute for inputs */
4456 if (spec->auto_mute_via_amp) {
4457 struct nid_path *path;
4460 path = snd_hda_get_path_from_idx(codec, paths[i]);
4463 mute_nid = get_amp_nid_(path->ctls[NID_PATH_MUTE_CTL]);
4467 spec->mute_bits |= (1ULL << mute_nid);
4469 spec->mute_bits &= ~(1ULL << mute_nid);
4472 /* don't reset VREF value in case it's controlling
4473 * the amp (see alc861_fixup_asus_amp_vref_0f())
4475 if (spec->keep_vref_in_automute)
4476 val = oldval & ~PIN_HP;
4481 /* here we call update_pin_ctl() so that the pinctl is
4482 * changed without changing the pinctl target value;
4483 * the original target value will be still referred at
4484 * the init / resume again
4486 update_pin_ctl(codec, nid, val);
4489 set_pin_eapd(codec, nid, !mute);
4490 if (codec->power_save_node) {
4493 on = detect_pin_state(codec, nid);
4494 set_path_power(codec, nid, on, -1);
4500 * snd_hda_gen_update_outputs - Toggle outputs muting
4501 * @codec: the HDA codec
4503 * Update the mute status of all outputs based on the current jack states.
4505 void snd_hda_gen_update_outputs(struct hda_codec *codec)
4507 struct hda_gen_spec *spec = codec->spec;
4511 /* Control HP pins/amps depending on master_mute state;
4512 * in general, HP pins/amps control should be enabled in all cases,
4513 * but currently set only for master_mute, just to be safe
4515 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
4516 paths = spec->out_paths;
4518 paths = spec->hp_paths;
4519 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
4520 spec->autocfg.hp_pins, paths, spec->master_mute);
4522 if (!spec->automute_speaker)
4525 on = spec->hp_jack_present | spec->line_jack_present;
4526 on |= spec->master_mute;
4527 spec->speaker_muted = on;
4528 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4529 paths = spec->out_paths;
4531 paths = spec->speaker_paths;
4532 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
4533 spec->autocfg.speaker_pins, paths, on);
4535 /* toggle line-out mutes if needed, too */
4536 /* if LO is a copy of either HP or Speaker, don't need to handle it */
4537 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
4538 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
4540 if (!spec->automute_lo)
4543 on = spec->hp_jack_present;
4544 on |= spec->master_mute;
4545 spec->line_out_muted = on;
4546 paths = spec->out_paths;
4547 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
4548 spec->autocfg.line_out_pins, paths, on);
4550 EXPORT_SYMBOL_GPL(snd_hda_gen_update_outputs);
4552 static void call_update_outputs(struct hda_codec *codec)
4554 struct hda_gen_spec *spec = codec->spec;
4555 if (spec->automute_hook)
4556 spec->automute_hook(codec);
4558 snd_hda_gen_update_outputs(codec);
4560 /* sync the whole vmaster slaves to reflect the new auto-mute status */
4561 if (spec->auto_mute_via_amp && !codec->bus->shutdown)
4562 snd_ctl_sync_vmaster(spec->vmaster_mute.sw_kctl, false);
4566 * snd_hda_gen_hp_automute - standard HP-automute helper
4567 * @codec: the HDA codec
4568 * @jack: jack object, NULL for the whole
4570 void snd_hda_gen_hp_automute(struct hda_codec *codec,
4571 struct hda_jack_callback *jack)
4573 struct hda_gen_spec *spec = codec->spec;
4574 hda_nid_t *pins = spec->autocfg.hp_pins;
4575 int num_pins = ARRAY_SIZE(spec->autocfg.hp_pins);
4577 /* No detection for the first HP jack during indep-HP mode */
4578 if (spec->indep_hp_enabled) {
4583 spec->hp_jack_present = detect_jacks(codec, num_pins, pins);
4584 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
4586 call_update_outputs(codec);
4588 EXPORT_SYMBOL_GPL(snd_hda_gen_hp_automute);
4591 * snd_hda_gen_line_automute - standard line-out-automute helper
4592 * @codec: the HDA codec
4593 * @jack: jack object, NULL for the whole
4595 void snd_hda_gen_line_automute(struct hda_codec *codec,
4596 struct hda_jack_callback *jack)
4598 struct hda_gen_spec *spec = codec->spec;
4600 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4602 /* check LO jack only when it's different from HP */
4603 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
4606 spec->line_jack_present =
4607 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
4608 spec->autocfg.line_out_pins);
4609 if (!spec->automute_speaker || !spec->detect_lo)
4611 call_update_outputs(codec);
4613 EXPORT_SYMBOL_GPL(snd_hda_gen_line_automute);
4616 * snd_hda_gen_mic_autoswitch - standard mic auto-switch helper
4617 * @codec: the HDA codec
4618 * @jack: jack object, NULL for the whole
4620 void snd_hda_gen_mic_autoswitch(struct hda_codec *codec,
4621 struct hda_jack_callback *jack)
4623 struct hda_gen_spec *spec = codec->spec;
4626 if (!spec->auto_mic)
4629 for (i = spec->am_num_entries - 1; i > 0; i--) {
4630 hda_nid_t pin = spec->am_entry[i].pin;
4631 /* don't detect pins retasked as outputs */
4632 if (snd_hda_codec_get_pin_target(codec, pin) & AC_PINCTL_OUT_EN)
4634 if (snd_hda_jack_detect_state(codec, pin) == HDA_JACK_PRESENT) {
4635 mux_select(codec, 0, spec->am_entry[i].idx);
4639 mux_select(codec, 0, spec->am_entry[0].idx);
4641 EXPORT_SYMBOL_GPL(snd_hda_gen_mic_autoswitch);
4643 /* call appropriate hooks */
4644 static void call_hp_automute(struct hda_codec *codec,
4645 struct hda_jack_callback *jack)
4647 struct hda_gen_spec *spec = codec->spec;
4648 if (spec->hp_automute_hook)
4649 spec->hp_automute_hook(codec, jack);
4651 snd_hda_gen_hp_automute(codec, jack);
4654 static void call_line_automute(struct hda_codec *codec,
4655 struct hda_jack_callback *jack)
4657 struct hda_gen_spec *spec = codec->spec;
4658 if (spec->line_automute_hook)
4659 spec->line_automute_hook(codec, jack);
4661 snd_hda_gen_line_automute(codec, jack);
4664 static void call_mic_autoswitch(struct hda_codec *codec,
4665 struct hda_jack_callback *jack)
4667 struct hda_gen_spec *spec = codec->spec;
4668 if (spec->mic_autoswitch_hook)
4669 spec->mic_autoswitch_hook(codec, jack);
4671 snd_hda_gen_mic_autoswitch(codec, jack);
4674 /* update jack retasking */
4675 static void update_automute_all(struct hda_codec *codec)
4677 call_hp_automute(codec, NULL);
4678 call_line_automute(codec, NULL);
4679 call_mic_autoswitch(codec, NULL);
4683 * Auto-Mute mode mixer enum support
4685 static int automute_mode_info(struct snd_kcontrol *kcontrol,
4686 struct snd_ctl_elem_info *uinfo)
4688 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4689 struct hda_gen_spec *spec = codec->spec;
4690 static const char * const texts3[] = {
4691 "Disabled", "Speaker Only", "Line Out+Speaker"
4694 if (spec->automute_speaker_possible && spec->automute_lo_possible)
4695 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
4696 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
4699 static int automute_mode_get(struct snd_kcontrol *kcontrol,
4700 struct snd_ctl_elem_value *ucontrol)
4702 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4703 struct hda_gen_spec *spec = codec->spec;
4704 unsigned int val = 0;
4705 if (spec->automute_speaker)
4707 if (spec->automute_lo)
4710 ucontrol->value.enumerated.item[0] = val;
4714 static int automute_mode_put(struct snd_kcontrol *kcontrol,
4715 struct snd_ctl_elem_value *ucontrol)
4717 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4718 struct hda_gen_spec *spec = codec->spec;
4720 switch (ucontrol->value.enumerated.item[0]) {
4722 if (!spec->automute_speaker && !spec->automute_lo)
4724 spec->automute_speaker = 0;
4725 spec->automute_lo = 0;
4728 if (spec->automute_speaker_possible) {
4729 if (!spec->automute_lo && spec->automute_speaker)
4731 spec->automute_speaker = 1;
4732 spec->automute_lo = 0;
4733 } else if (spec->automute_lo_possible) {
4734 if (spec->automute_lo)
4736 spec->automute_lo = 1;
4741 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
4743 if (spec->automute_speaker && spec->automute_lo)
4745 spec->automute_speaker = 1;
4746 spec->automute_lo = 1;
4751 call_update_outputs(codec);
4755 static const struct snd_kcontrol_new automute_mode_enum = {
4756 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4757 .name = "Auto-Mute Mode",
4758 .info = automute_mode_info,
4759 .get = automute_mode_get,
4760 .put = automute_mode_put,
4763 static int add_automute_mode_enum(struct hda_codec *codec)
4765 struct hda_gen_spec *spec = codec->spec;
4767 if (!snd_hda_gen_add_kctl(spec, NULL, &automute_mode_enum))
4773 * Check the availability of HP/line-out auto-mute;
4774 * Set up appropriately if really supported
4776 static int check_auto_mute_availability(struct hda_codec *codec)
4778 struct hda_gen_spec *spec = codec->spec;
4779 struct auto_pin_cfg *cfg = &spec->autocfg;
4783 if (spec->suppress_auto_mute)
4786 if (cfg->hp_pins[0])
4788 if (cfg->line_out_pins[0])
4790 if (cfg->speaker_pins[0])
4792 if (present < 2) /* need two different output types */
4795 if (!cfg->speaker_pins[0] &&
4796 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
4797 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4798 sizeof(cfg->speaker_pins));
4799 cfg->speaker_outs = cfg->line_outs;
4802 if (!cfg->hp_pins[0] &&
4803 cfg->line_out_type == AUTO_PIN_HP_OUT) {
4804 memcpy(cfg->hp_pins, cfg->line_out_pins,
4805 sizeof(cfg->hp_pins));
4806 cfg->hp_outs = cfg->line_outs;
4809 for (i = 0; i < cfg->hp_outs; i++) {
4810 hda_nid_t nid = cfg->hp_pins[i];
4811 if (!is_jack_detectable(codec, nid))
4813 codec_dbg(codec, "Enable HP auto-muting on NID 0x%x\n", nid);
4814 snd_hda_jack_detect_enable_callback(codec, nid,
4816 spec->detect_hp = 1;
4819 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
4820 if (cfg->speaker_outs)
4821 for (i = 0; i < cfg->line_outs; i++) {
4822 hda_nid_t nid = cfg->line_out_pins[i];
4823 if (!is_jack_detectable(codec, nid))
4825 codec_dbg(codec, "Enable Line-Out auto-muting on NID 0x%x\n", nid);
4826 snd_hda_jack_detect_enable_callback(codec, nid,
4827 call_line_automute);
4828 spec->detect_lo = 1;
4830 spec->automute_lo_possible = spec->detect_hp;
4833 spec->automute_speaker_possible = cfg->speaker_outs &&
4834 (spec->detect_hp || spec->detect_lo);
4836 spec->automute_lo = spec->automute_lo_possible;
4837 spec->automute_speaker = spec->automute_speaker_possible;
4839 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
4840 /* create a control for automute mode */
4841 err = add_automute_mode_enum(codec);
4848 /* check whether all auto-mic pins are valid; setup indices if OK */
4849 static bool auto_mic_check_imux(struct hda_codec *codec)
4851 struct hda_gen_spec *spec = codec->spec;
4852 const struct hda_input_mux *imux;
4855 imux = &spec->input_mux;
4856 for (i = 0; i < spec->am_num_entries; i++) {
4857 spec->am_entry[i].idx =
4858 find_idx_in_nid_list(spec->am_entry[i].pin,
4859 spec->imux_pins, imux->num_items);
4860 if (spec->am_entry[i].idx < 0)
4861 return false; /* no corresponding imux */
4864 /* we don't need the jack detection for the first pin */
4865 for (i = 1; i < spec->am_num_entries; i++)
4866 snd_hda_jack_detect_enable_callback(codec,
4867 spec->am_entry[i].pin,
4868 call_mic_autoswitch);
4872 static int compare_attr(const void *ap, const void *bp)
4874 const struct automic_entry *a = ap;
4875 const struct automic_entry *b = bp;
4876 return (int)(a->attr - b->attr);
4880 * Check the availability of auto-mic switch;
4881 * Set up if really supported
4883 static int check_auto_mic_availability(struct hda_codec *codec)
4885 struct hda_gen_spec *spec = codec->spec;
4886 struct auto_pin_cfg *cfg = &spec->autocfg;
4890 if (spec->suppress_auto_mic)
4895 for (i = 0; i < cfg->num_inputs; i++) {
4896 hda_nid_t nid = cfg->inputs[i].pin;
4898 attr = snd_hda_codec_get_pincfg(codec, nid);
4899 attr = snd_hda_get_input_pin_attr(attr);
4900 if (types & (1 << attr))
4901 return 0; /* already occupied */
4903 case INPUT_PIN_ATTR_INT:
4904 if (cfg->inputs[i].type != AUTO_PIN_MIC)
4905 return 0; /* invalid type */
4907 case INPUT_PIN_ATTR_UNUSED:
4908 return 0; /* invalid entry */
4910 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
4911 return 0; /* invalid type */
4912 if (!spec->line_in_auto_switch &&
4913 cfg->inputs[i].type != AUTO_PIN_MIC)
4914 return 0; /* only mic is allowed */
4915 if (!is_jack_detectable(codec, nid))
4916 return 0; /* no unsol support */
4919 if (num_pins >= MAX_AUTO_MIC_PINS)
4921 types |= (1 << attr);
4922 spec->am_entry[num_pins].pin = nid;
4923 spec->am_entry[num_pins].attr = attr;
4930 spec->am_num_entries = num_pins;
4931 /* sort the am_entry in the order of attr so that the pin with a
4932 * higher attr will be selected when the jack is plugged.
4934 sort(spec->am_entry, num_pins, sizeof(spec->am_entry[0]),
4935 compare_attr, NULL);
4937 if (!auto_mic_check_imux(codec))
4941 spec->num_adc_nids = 1;
4942 spec->cur_mux[0] = spec->am_entry[0].idx;
4943 codec_dbg(codec, "Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
4944 spec->am_entry[0].pin,
4945 spec->am_entry[1].pin,
4946 spec->am_entry[2].pin);
4952 * snd_hda_gen_path_power_filter - power_filter hook to make inactive widgets
4954 * @codec: the HDA codec
4955 * @nid: NID to evalute
4956 * @power_state: target power state
4958 unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
4960 unsigned int power_state)
4962 struct hda_gen_spec *spec = codec->spec;
4964 if (!spec->power_down_unused && !codec->power_save_node)
4966 if (power_state != AC_PWRST_D0 || nid == codec->core.afg)
4968 if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER)
4970 if (is_active_nid_for_any(codec, nid))
4974 EXPORT_SYMBOL_GPL(snd_hda_gen_path_power_filter);
4976 /* mute all aamix inputs initially; parse up to the first leaves */
4977 static void mute_all_mixer_nid(struct hda_codec *codec, hda_nid_t mix)
4980 const hda_nid_t *conn;
4983 nums = snd_hda_get_conn_list(codec, mix, &conn);
4984 has_amp = nid_has_mute(codec, mix, HDA_INPUT);
4985 for (i = 0; i < nums; i++) {
4987 update_amp(codec, mix, HDA_INPUT, i,
4988 0xff, HDA_AMP_MUTE);
4989 else if (nid_has_volume(codec, conn[i], HDA_OUTPUT))
4990 update_amp(codec, conn[i], HDA_OUTPUT, 0,
4991 0xff, HDA_AMP_MUTE);
4996 * snd_hda_gen_stream_pm - Stream power management callback
4997 * @codec: the HDA codec
4998 * @nid: audio widget
4999 * @on: power on/off flag
5001 * Set this in patch_ops.stream_pm. Only valid with power_save_node flag.
5003 void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on)
5005 if (codec->power_save_node)
5006 set_path_power(codec, nid, -1, on);
5008 EXPORT_SYMBOL_GPL(snd_hda_gen_stream_pm);
5011 * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and
5012 * set up the hda_gen_spec
5013 * @codec: the HDA codec
5014 * @cfg: Parsed pin configuration
5016 * return 1 if successful, 0 if the proper config is not found,
5017 * or a negative error code
5019 int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
5020 struct auto_pin_cfg *cfg)
5022 struct hda_gen_spec *spec = codec->spec;
5025 parse_user_hints(codec);
5027 if (spec->mixer_nid && !spec->mixer_merge_nid)
5028 spec->mixer_merge_nid = spec->mixer_nid;
5030 if (cfg != &spec->autocfg) {
5031 spec->autocfg = *cfg;
5032 cfg = &spec->autocfg;
5035 if (!spec->main_out_badness)
5036 spec->main_out_badness = &hda_main_out_badness;
5037 if (!spec->extra_out_badness)
5038 spec->extra_out_badness = &hda_extra_out_badness;
5040 fill_all_dac_nids(codec);
5042 if (!cfg->line_outs) {
5043 if (cfg->dig_outs || cfg->dig_in_pin) {
5044 spec->multiout.max_channels = 2;
5045 spec->no_analog = 1;
5048 if (!cfg->num_inputs && !cfg->dig_in_pin)
5049 return 0; /* can't find valid BIOS pin config */
5052 if (!spec->no_primary_hp &&
5053 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
5054 cfg->line_outs <= cfg->hp_outs) {
5055 /* use HP as primary out */
5056 cfg->speaker_outs = cfg->line_outs;
5057 memcpy(cfg->speaker_pins, cfg->line_out_pins,
5058 sizeof(cfg->speaker_pins));
5059 cfg->line_outs = cfg->hp_outs;
5060 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
5062 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
5063 cfg->line_out_type = AUTO_PIN_HP_OUT;
5066 err = parse_output_paths(codec);
5069 err = create_multi_channel_mode(codec);
5072 err = create_multi_out_ctls(codec, cfg);
5075 err = create_hp_out_ctls(codec);
5078 err = create_speaker_out_ctls(codec);
5081 err = create_indep_hp_ctls(codec);
5084 err = create_loopback_mixing_ctl(codec);
5087 err = create_hp_mic(codec);
5090 err = create_input_ctls(codec);
5094 /* add power-down pin callbacks at first */
5095 add_all_pin_power_ctls(codec, false);
5097 spec->const_channel_count = spec->ext_channel_count;
5098 /* check the multiple speaker and headphone pins */
5099 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
5100 spec->const_channel_count = max(spec->const_channel_count,
5101 cfg->speaker_outs * 2);
5102 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
5103 spec->const_channel_count = max(spec->const_channel_count,
5105 spec->multiout.max_channels = max(spec->ext_channel_count,
5106 spec->const_channel_count);
5108 err = check_auto_mute_availability(codec);
5112 err = check_dyn_adc_switch(codec);
5116 err = check_auto_mic_availability(codec);
5120 /* add stereo mix if available and not enabled yet */
5121 if (!spec->auto_mic && spec->mixer_nid &&
5122 spec->add_stereo_mix_input == HDA_HINT_STEREO_MIX_AUTO &&
5123 spec->input_mux.num_items > 1) {
5124 err = parse_capture_source(codec, spec->mixer_nid,
5125 CFG_IDX_MIX, spec->num_all_adcs,
5132 err = create_capture_mixers(codec);
5136 err = parse_mic_boost(codec);
5140 /* create "Headphone Mic Jack Mode" if no input selection is
5141 * available (or user specifies add_jack_modes hint)
5143 if (spec->hp_mic_pin &&
5144 (spec->auto_mic || spec->input_mux.num_items == 1 ||
5145 spec->add_jack_modes)) {
5146 err = create_hp_mic_jack_mode(codec, spec->hp_mic_pin);
5151 if (spec->add_jack_modes) {
5152 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
5153 err = create_out_jack_modes(codec, cfg->line_outs,
5154 cfg->line_out_pins);
5158 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
5159 err = create_out_jack_modes(codec, cfg->hp_outs,
5166 /* add power-up pin callbacks at last */
5167 add_all_pin_power_ctls(codec, true);
5169 /* mute all aamix input initially */
5170 if (spec->mixer_nid)
5171 mute_all_mixer_nid(codec, spec->mixer_nid);
5174 parse_digital(codec);
5176 if (spec->power_down_unused || codec->power_save_node) {
5177 if (!codec->power_filter)
5178 codec->power_filter = snd_hda_gen_path_power_filter;
5179 if (!codec->patch_ops.stream_pm)
5180 codec->patch_ops.stream_pm = snd_hda_gen_stream_pm;
5183 if (!spec->no_analog && spec->beep_nid) {
5184 err = snd_hda_attach_beep_device(codec, spec->beep_nid);
5187 if (codec->beep && codec->power_save_node) {
5188 err = add_fake_beep_paths(codec);
5191 codec->beep->power_hook = beep_power_hook;
5197 EXPORT_SYMBOL_GPL(snd_hda_gen_parse_auto_config);
5201 * Build control elements
5204 /* slave controls for virtual master */
5205 static const char * const slave_pfxs[] = {
5206 "Front", "Surround", "Center", "LFE", "Side",
5207 "Headphone", "Speaker", "Mono", "Line Out",
5208 "CLFE", "Bass Speaker", "PCM",
5209 "Speaker Front", "Speaker Surround", "Speaker CLFE", "Speaker Side",
5210 "Headphone Front", "Headphone Surround", "Headphone CLFE",
5211 "Headphone Side", "Headphone+LO", "Speaker+LO",
5216 * snd_hda_gen_build_controls - Build controls from the parsed results
5217 * @codec: the HDA codec
5219 * Pass this to build_controls patch_ops.
5221 int snd_hda_gen_build_controls(struct hda_codec *codec)
5223 struct hda_gen_spec *spec = codec->spec;
5226 if (spec->kctls.used) {
5227 err = snd_hda_add_new_ctls(codec, spec->kctls.list);
5232 if (spec->multiout.dig_out_nid) {
5233 err = snd_hda_create_dig_out_ctls(codec,
5234 spec->multiout.dig_out_nid,
5235 spec->multiout.dig_out_nid,
5236 spec->pcm_rec[1]->pcm_type);
5239 if (!spec->no_analog) {
5240 err = snd_hda_create_spdif_share_sw(codec,
5244 spec->multiout.share_spdif = 1;
5247 if (spec->dig_in_nid) {
5248 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
5253 /* if we have no master control, let's create it */
5254 if (!spec->no_analog && !spec->suppress_vmaster &&
5255 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
5256 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
5257 spec->vmaster_tlv, slave_pfxs,
5262 if (!spec->no_analog && !spec->suppress_vmaster &&
5263 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
5264 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
5267 true, &spec->vmaster_mute.sw_kctl);
5270 if (spec->vmaster_mute.hook) {
5271 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
5272 spec->vmaster_mute_enum);
5273 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
5277 free_kctls(spec); /* no longer needed */
5279 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
5285 EXPORT_SYMBOL_GPL(snd_hda_gen_build_controls);
5292 static void call_pcm_playback_hook(struct hda_pcm_stream *hinfo,
5293 struct hda_codec *codec,
5294 struct snd_pcm_substream *substream,
5297 struct hda_gen_spec *spec = codec->spec;
5298 if (spec->pcm_playback_hook)
5299 spec->pcm_playback_hook(hinfo, codec, substream, action);
5302 static void call_pcm_capture_hook(struct hda_pcm_stream *hinfo,
5303 struct hda_codec *codec,
5304 struct snd_pcm_substream *substream,
5307 struct hda_gen_spec *spec = codec->spec;
5308 if (spec->pcm_capture_hook)
5309 spec->pcm_capture_hook(hinfo, codec, substream, action);
5313 * Analog playback callbacks
5315 static int playback_pcm_open(struct hda_pcm_stream *hinfo,
5316 struct hda_codec *codec,
5317 struct snd_pcm_substream *substream)
5319 struct hda_gen_spec *spec = codec->spec;
5322 mutex_lock(&spec->pcm_mutex);
5323 err = snd_hda_multi_out_analog_open(codec,
5324 &spec->multiout, substream,
5327 spec->active_streams |= 1 << STREAM_MULTI_OUT;
5328 call_pcm_playback_hook(hinfo, codec, substream,
5329 HDA_GEN_PCM_ACT_OPEN);
5331 mutex_unlock(&spec->pcm_mutex);
5335 static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
5336 struct hda_codec *codec,
5337 unsigned int stream_tag,
5338 unsigned int format,
5339 struct snd_pcm_substream *substream)
5341 struct hda_gen_spec *spec = codec->spec;
5344 err = snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
5345 stream_tag, format, substream);
5347 call_pcm_playback_hook(hinfo, codec, substream,
5348 HDA_GEN_PCM_ACT_PREPARE);
5352 static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
5353 struct hda_codec *codec,
5354 struct snd_pcm_substream *substream)
5356 struct hda_gen_spec *spec = codec->spec;
5359 err = snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
5361 call_pcm_playback_hook(hinfo, codec, substream,
5362 HDA_GEN_PCM_ACT_CLEANUP);
5366 static int playback_pcm_close(struct hda_pcm_stream *hinfo,
5367 struct hda_codec *codec,
5368 struct snd_pcm_substream *substream)
5370 struct hda_gen_spec *spec = codec->spec;
5371 mutex_lock(&spec->pcm_mutex);
5372 spec->active_streams &= ~(1 << STREAM_MULTI_OUT);
5373 call_pcm_playback_hook(hinfo, codec, substream,
5374 HDA_GEN_PCM_ACT_CLOSE);
5375 mutex_unlock(&spec->pcm_mutex);
5379 static int capture_pcm_open(struct hda_pcm_stream *hinfo,
5380 struct hda_codec *codec,
5381 struct snd_pcm_substream *substream)
5383 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_OPEN);
5387 static int capture_pcm_prepare(struct hda_pcm_stream *hinfo,
5388 struct hda_codec *codec,
5389 unsigned int stream_tag,
5390 unsigned int format,
5391 struct snd_pcm_substream *substream)
5393 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
5394 call_pcm_capture_hook(hinfo, codec, substream,
5395 HDA_GEN_PCM_ACT_PREPARE);
5399 static int capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
5400 struct hda_codec *codec,
5401 struct snd_pcm_substream *substream)
5403 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
5404 call_pcm_capture_hook(hinfo, codec, substream,
5405 HDA_GEN_PCM_ACT_CLEANUP);
5409 static int capture_pcm_close(struct hda_pcm_stream *hinfo,
5410 struct hda_codec *codec,
5411 struct snd_pcm_substream *substream)
5413 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLOSE);
5417 static int alt_playback_pcm_open(struct hda_pcm_stream *hinfo,
5418 struct hda_codec *codec,
5419 struct snd_pcm_substream *substream)
5421 struct hda_gen_spec *spec = codec->spec;
5424 mutex_lock(&spec->pcm_mutex);
5425 if (spec->indep_hp && !spec->indep_hp_enabled)
5428 spec->active_streams |= 1 << STREAM_INDEP_HP;
5429 call_pcm_playback_hook(hinfo, codec, substream,
5430 HDA_GEN_PCM_ACT_OPEN);
5431 mutex_unlock(&spec->pcm_mutex);
5435 static int alt_playback_pcm_close(struct hda_pcm_stream *hinfo,
5436 struct hda_codec *codec,
5437 struct snd_pcm_substream *substream)
5439 struct hda_gen_spec *spec = codec->spec;
5440 mutex_lock(&spec->pcm_mutex);
5441 spec->active_streams &= ~(1 << STREAM_INDEP_HP);
5442 call_pcm_playback_hook(hinfo, codec, substream,
5443 HDA_GEN_PCM_ACT_CLOSE);
5444 mutex_unlock(&spec->pcm_mutex);
5448 static int alt_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
5449 struct hda_codec *codec,
5450 unsigned int stream_tag,
5451 unsigned int format,
5452 struct snd_pcm_substream *substream)
5454 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
5455 call_pcm_playback_hook(hinfo, codec, substream,
5456 HDA_GEN_PCM_ACT_PREPARE);
5460 static int alt_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
5461 struct hda_codec *codec,
5462 struct snd_pcm_substream *substream)
5464 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
5465 call_pcm_playback_hook(hinfo, codec, substream,
5466 HDA_GEN_PCM_ACT_CLEANUP);
5473 static int dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
5474 struct hda_codec *codec,
5475 struct snd_pcm_substream *substream)
5477 struct hda_gen_spec *spec = codec->spec;
5478 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
5481 static int dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
5482 struct hda_codec *codec,
5483 unsigned int stream_tag,
5484 unsigned int format,
5485 struct snd_pcm_substream *substream)
5487 struct hda_gen_spec *spec = codec->spec;
5488 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
5489 stream_tag, format, substream);
5492 static int dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
5493 struct hda_codec *codec,
5494 struct snd_pcm_substream *substream)
5496 struct hda_gen_spec *spec = codec->spec;
5497 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
5500 static int dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
5501 struct hda_codec *codec,
5502 struct snd_pcm_substream *substream)
5504 struct hda_gen_spec *spec = codec->spec;
5505 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
5511 #define alt_capture_pcm_open capture_pcm_open
5512 #define alt_capture_pcm_close capture_pcm_close
5514 static int alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
5515 struct hda_codec *codec,
5516 unsigned int stream_tag,
5517 unsigned int format,
5518 struct snd_pcm_substream *substream)
5520 struct hda_gen_spec *spec = codec->spec;
5522 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
5523 stream_tag, 0, format);
5524 call_pcm_capture_hook(hinfo, codec, substream,
5525 HDA_GEN_PCM_ACT_PREPARE);
5529 static int alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
5530 struct hda_codec *codec,
5531 struct snd_pcm_substream *substream)
5533 struct hda_gen_spec *spec = codec->spec;
5535 snd_hda_codec_cleanup_stream(codec,
5536 spec->adc_nids[substream->number + 1]);
5537 call_pcm_capture_hook(hinfo, codec, substream,
5538 HDA_GEN_PCM_ACT_CLEANUP);
5544 static const struct hda_pcm_stream pcm_analog_playback = {
5548 /* NID is set in build_pcms */
5550 .open = playback_pcm_open,
5551 .close = playback_pcm_close,
5552 .prepare = playback_pcm_prepare,
5553 .cleanup = playback_pcm_cleanup
5557 static const struct hda_pcm_stream pcm_analog_capture = {
5561 /* NID is set in build_pcms */
5563 .open = capture_pcm_open,
5564 .close = capture_pcm_close,
5565 .prepare = capture_pcm_prepare,
5566 .cleanup = capture_pcm_cleanup
5570 static const struct hda_pcm_stream pcm_analog_alt_playback = {
5574 /* NID is set in build_pcms */
5576 .open = alt_playback_pcm_open,
5577 .close = alt_playback_pcm_close,
5578 .prepare = alt_playback_pcm_prepare,
5579 .cleanup = alt_playback_pcm_cleanup
5583 static const struct hda_pcm_stream pcm_analog_alt_capture = {
5584 .substreams = 2, /* can be overridden */
5587 /* NID is set in build_pcms */
5589 .open = alt_capture_pcm_open,
5590 .close = alt_capture_pcm_close,
5591 .prepare = alt_capture_pcm_prepare,
5592 .cleanup = alt_capture_pcm_cleanup
5596 static const struct hda_pcm_stream pcm_digital_playback = {
5600 /* NID is set in build_pcms */
5602 .open = dig_playback_pcm_open,
5603 .close = dig_playback_pcm_close,
5604 .prepare = dig_playback_pcm_prepare,
5605 .cleanup = dig_playback_pcm_cleanup
5609 static const struct hda_pcm_stream pcm_digital_capture = {
5613 /* NID is set in build_pcms */
5616 /* Used by build_pcms to flag that a PCM has no playback stream */
5617 static const struct hda_pcm_stream pcm_null_stream = {
5624 * dynamic changing ADC PCM streams
5626 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
5628 struct hda_gen_spec *spec = codec->spec;
5629 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
5631 if (spec->cur_adc && spec->cur_adc != new_adc) {
5632 /* stream is running, let's swap the current ADC */
5633 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
5634 spec->cur_adc = new_adc;
5635 snd_hda_codec_setup_stream(codec, new_adc,
5636 spec->cur_adc_stream_tag, 0,
5637 spec->cur_adc_format);
5643 /* analog capture with dynamic dual-adc changes */
5644 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
5645 struct hda_codec *codec,
5646 unsigned int stream_tag,
5647 unsigned int format,
5648 struct snd_pcm_substream *substream)
5650 struct hda_gen_spec *spec = codec->spec;
5651 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
5652 spec->cur_adc_stream_tag = stream_tag;
5653 spec->cur_adc_format = format;
5654 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
5655 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_PREPARE);
5659 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
5660 struct hda_codec *codec,
5661 struct snd_pcm_substream *substream)
5663 struct hda_gen_spec *spec = codec->spec;
5664 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
5666 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLEANUP);
5670 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
5674 .nid = 0, /* fill later */
5676 .prepare = dyn_adc_capture_pcm_prepare,
5677 .cleanup = dyn_adc_capture_pcm_cleanup
5681 static void fill_pcm_stream_name(char *str, size_t len, const char *sfx,
5682 const char *chip_name)
5688 strlcpy(str, chip_name, len);
5690 /* drop non-alnum chars after a space */
5691 for (p = strchr(str, ' '); p; p = strchr(p + 1, ' ')) {
5692 if (!isalnum(p[1])) {
5697 strlcat(str, sfx, len);
5700 /* copy PCM stream info from @default_str, and override non-NULL entries
5701 * from @spec_str and @nid
5703 static void setup_pcm_stream(struct hda_pcm_stream *str,
5704 const struct hda_pcm_stream *default_str,
5705 const struct hda_pcm_stream *spec_str,
5708 *str = *default_str;
5712 if (spec_str->substreams)
5713 str->substreams = spec_str->substreams;
5714 if (spec_str->channels_min)
5715 str->channels_min = spec_str->channels_min;
5716 if (spec_str->channels_max)
5717 str->channels_max = spec_str->channels_max;
5718 if (spec_str->rates)
5719 str->rates = spec_str->rates;
5720 if (spec_str->formats)
5721 str->formats = spec_str->formats;
5722 if (spec_str->maxbps)
5723 str->maxbps = spec_str->maxbps;
5728 * snd_hda_gen_build_pcms - build PCM streams based on the parsed results
5729 * @codec: the HDA codec
5731 * Pass this to build_pcms patch_ops.
5733 int snd_hda_gen_build_pcms(struct hda_codec *codec)
5735 struct hda_gen_spec *spec = codec->spec;
5736 struct hda_pcm *info;
5737 bool have_multi_adcs;
5739 if (spec->no_analog)
5742 fill_pcm_stream_name(spec->stream_name_analog,
5743 sizeof(spec->stream_name_analog),
5744 " Analog", codec->core.chip_name);
5745 info = snd_hda_codec_pcm_new(codec, "%s", spec->stream_name_analog);
5748 spec->pcm_rec[0] = info;
5750 if (spec->multiout.num_dacs > 0) {
5751 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5752 &pcm_analog_playback,
5753 spec->stream_analog_playback,
5754 spec->multiout.dac_nids[0]);
5755 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
5756 spec->multiout.max_channels;
5757 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
5758 spec->autocfg.line_outs == 2)
5759 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
5762 if (spec->num_adc_nids) {
5763 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5764 (spec->dyn_adc_switch ?
5765 &dyn_adc_pcm_analog_capture : &pcm_analog_capture),
5766 spec->stream_analog_capture,
5771 /* SPDIF for stream index #1 */
5772 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
5773 fill_pcm_stream_name(spec->stream_name_digital,
5774 sizeof(spec->stream_name_digital),
5775 " Digital", codec->core.chip_name);
5776 info = snd_hda_codec_pcm_new(codec, "%s",
5777 spec->stream_name_digital);
5780 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
5781 spec->pcm_rec[1] = info;
5782 if (spec->dig_out_type)
5783 info->pcm_type = spec->dig_out_type;
5785 info->pcm_type = HDA_PCM_TYPE_SPDIF;
5786 if (spec->multiout.dig_out_nid)
5787 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5788 &pcm_digital_playback,
5789 spec->stream_digital_playback,
5790 spec->multiout.dig_out_nid);
5791 if (spec->dig_in_nid)
5792 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5793 &pcm_digital_capture,
5794 spec->stream_digital_capture,
5798 if (spec->no_analog)
5801 /* If the use of more than one ADC is requested for the current
5802 * model, configure a second analog capture-only PCM.
5804 have_multi_adcs = (spec->num_adc_nids > 1) &&
5805 !spec->dyn_adc_switch && !spec->auto_mic;
5806 /* Additional Analaog capture for index #2 */
5807 if (spec->alt_dac_nid || have_multi_adcs) {
5808 fill_pcm_stream_name(spec->stream_name_alt_analog,
5809 sizeof(spec->stream_name_alt_analog),
5810 " Alt Analog", codec->core.chip_name);
5811 info = snd_hda_codec_pcm_new(codec, "%s",
5812 spec->stream_name_alt_analog);
5815 spec->pcm_rec[2] = info;
5816 if (spec->alt_dac_nid)
5817 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5818 &pcm_analog_alt_playback,
5819 spec->stream_analog_alt_playback,
5822 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5823 &pcm_null_stream, NULL, 0);
5824 if (have_multi_adcs) {
5825 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5826 &pcm_analog_alt_capture,
5827 spec->stream_analog_alt_capture,
5829 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
5830 spec->num_adc_nids - 1;
5832 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5833 &pcm_null_stream, NULL, 0);
5839 EXPORT_SYMBOL_GPL(snd_hda_gen_build_pcms);
5843 * Standard auto-parser initializations
5846 /* configure the given path as a proper output */
5847 static void set_output_and_unmute(struct hda_codec *codec, int path_idx)
5849 struct nid_path *path;
5852 path = snd_hda_get_path_from_idx(codec, path_idx);
5853 if (!path || !path->depth)
5855 pin = path->path[path->depth - 1];
5856 restore_pin_ctl(codec, pin);
5857 snd_hda_activate_path(codec, path, path->active,
5858 aamix_default(codec->spec));
5859 set_pin_eapd(codec, pin, path->active);
5862 /* initialize primary output paths */
5863 static void init_multi_out(struct hda_codec *codec)
5865 struct hda_gen_spec *spec = codec->spec;
5868 for (i = 0; i < spec->autocfg.line_outs; i++)
5869 set_output_and_unmute(codec, spec->out_paths[i]);
5873 static void __init_extra_out(struct hda_codec *codec, int num_outs, int *paths)
5877 for (i = 0; i < num_outs; i++)
5878 set_output_and_unmute(codec, paths[i]);
5881 /* initialize hp and speaker paths */
5882 static void init_extra_out(struct hda_codec *codec)
5884 struct hda_gen_spec *spec = codec->spec;
5886 if (spec->autocfg.line_out_type != AUTO_PIN_HP_OUT)
5887 __init_extra_out(codec, spec->autocfg.hp_outs, spec->hp_paths);
5888 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT)
5889 __init_extra_out(codec, spec->autocfg.speaker_outs,
5890 spec->speaker_paths);
5893 /* initialize multi-io paths */
5894 static void init_multi_io(struct hda_codec *codec)
5896 struct hda_gen_spec *spec = codec->spec;
5899 for (i = 0; i < spec->multi_ios; i++) {
5900 hda_nid_t pin = spec->multi_io[i].pin;
5901 struct nid_path *path;
5902 path = get_multiio_path(codec, i);
5905 if (!spec->multi_io[i].ctl_in)
5906 spec->multi_io[i].ctl_in =
5907 snd_hda_codec_get_pin_target(codec, pin);
5908 snd_hda_activate_path(codec, path, path->active,
5909 aamix_default(spec));
5913 static void init_aamix_paths(struct hda_codec *codec)
5915 struct hda_gen_spec *spec = codec->spec;
5917 if (!spec->have_aamix_ctl)
5919 if (!has_aamix_out_paths(spec))
5921 update_aamix_paths(codec, spec->aamix_mode, spec->out_paths[0],
5922 spec->aamix_out_paths[0],
5923 spec->autocfg.line_out_type);
5924 update_aamix_paths(codec, spec->aamix_mode, spec->hp_paths[0],
5925 spec->aamix_out_paths[1],
5927 update_aamix_paths(codec, spec->aamix_mode, spec->speaker_paths[0],
5928 spec->aamix_out_paths[2],
5929 AUTO_PIN_SPEAKER_OUT);
5932 /* set up input pins and loopback paths */
5933 static void init_analog_input(struct hda_codec *codec)
5935 struct hda_gen_spec *spec = codec->spec;
5936 struct auto_pin_cfg *cfg = &spec->autocfg;
5939 for (i = 0; i < cfg->num_inputs; i++) {
5940 hda_nid_t nid = cfg->inputs[i].pin;
5941 if (is_input_pin(codec, nid))
5942 restore_pin_ctl(codec, nid);
5944 /* init loopback inputs */
5945 if (spec->mixer_nid) {
5946 resume_path_from_idx(codec, spec->loopback_paths[i]);
5947 resume_path_from_idx(codec, spec->loopback_merge_path);
5952 /* initialize ADC paths */
5953 static void init_input_src(struct hda_codec *codec)
5955 struct hda_gen_spec *spec = codec->spec;
5956 struct hda_input_mux *imux = &spec->input_mux;
5957 struct nid_path *path;
5960 if (spec->dyn_adc_switch)
5963 nums = spec->num_adc_nids;
5965 for (c = 0; c < nums; c++) {
5966 for (i = 0; i < imux->num_items; i++) {
5967 path = get_input_path(codec, c, i);
5969 bool active = path->active;
5970 if (i == spec->cur_mux[c])
5972 snd_hda_activate_path(codec, path, active, false);
5976 update_hp_mic(codec, c, true);
5979 if (spec->cap_sync_hook)
5980 spec->cap_sync_hook(codec, NULL, NULL);
5983 /* set right pin controls for digital I/O */
5984 static void init_digital(struct hda_codec *codec)
5986 struct hda_gen_spec *spec = codec->spec;
5990 for (i = 0; i < spec->autocfg.dig_outs; i++)
5991 set_output_and_unmute(codec, spec->digout_paths[i]);
5992 pin = spec->autocfg.dig_in_pin;
5994 restore_pin_ctl(codec, pin);
5995 resume_path_from_idx(codec, spec->digin_path);
5999 /* clear unsol-event tags on unused pins; Conexant codecs seem to leave
6000 * invalid unsol tags by some reason
6002 static void clear_unsol_on_unused_pins(struct hda_codec *codec)
6004 const struct hda_pincfg *pin;
6007 snd_array_for_each(&codec->init_pins, i, pin) {
6008 hda_nid_t nid = pin->nid;
6009 if (is_jack_detectable(codec, nid) &&
6010 !snd_hda_jack_tbl_get(codec, nid))
6011 snd_hda_codec_write_cache(codec, nid, 0,
6012 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
6017 * snd_hda_gen_init - initialize the generic spec
6018 * @codec: the HDA codec
6020 * This can be put as patch_ops init function.
6022 int snd_hda_gen_init(struct hda_codec *codec)
6024 struct hda_gen_spec *spec = codec->spec;
6026 if (spec->init_hook)
6027 spec->init_hook(codec);
6029 if (!spec->skip_verbs)
6030 snd_hda_apply_verbs(codec);
6032 init_multi_out(codec);
6033 init_extra_out(codec);
6034 init_multi_io(codec);
6035 init_aamix_paths(codec);
6036 init_analog_input(codec);
6037 init_input_src(codec);
6038 init_digital(codec);
6040 clear_unsol_on_unused_pins(codec);
6042 sync_all_pin_power_ctls(codec);
6044 /* call init functions of standard auto-mute helpers */
6045 update_automute_all(codec);
6047 snd_hda_regmap_sync(codec);
6049 if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook)
6050 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6052 hda_call_check_power_status(codec, 0x01);
6055 EXPORT_SYMBOL_GPL(snd_hda_gen_init);
6058 * snd_hda_gen_free - free the generic spec
6059 * @codec: the HDA codec
6061 * This can be put as patch_ops free function.
6063 void snd_hda_gen_free(struct hda_codec *codec)
6065 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
6066 snd_hda_gen_spec_free(codec->spec);
6070 EXPORT_SYMBOL_GPL(snd_hda_gen_free);
6073 * snd_hda_gen_reboot_notify - Make codec enter D3 before rebooting
6074 * @codec: the HDA codec
6076 * This can be put as patch_ops reboot_notify function.
6078 void snd_hda_gen_reboot_notify(struct hda_codec *codec)
6080 /* Make the codec enter D3 to avoid spurious noises from the internal
6081 * speaker during (and after) reboot
6083 snd_hda_codec_set_power_to_all(codec, codec->core.afg, AC_PWRST_D3);
6084 snd_hda_codec_write(codec, codec->core.afg, 0,
6085 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6088 EXPORT_SYMBOL_GPL(snd_hda_gen_reboot_notify);
6092 * snd_hda_gen_check_power_status - check the loopback power save state
6093 * @codec: the HDA codec
6094 * @nid: NID to inspect
6096 * This can be put as patch_ops check_power_status function.
6098 int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid)
6100 struct hda_gen_spec *spec = codec->spec;
6101 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
6103 EXPORT_SYMBOL_GPL(snd_hda_gen_check_power_status);
6108 * the generic codec support
6111 static const struct hda_codec_ops generic_patch_ops = {
6112 .build_controls = snd_hda_gen_build_controls,
6113 .build_pcms = snd_hda_gen_build_pcms,
6114 .init = snd_hda_gen_init,
6115 .free = snd_hda_gen_free,
6116 .unsol_event = snd_hda_jack_unsol_event,
6117 .reboot_notify = snd_hda_gen_reboot_notify,
6119 .check_power_status = snd_hda_gen_check_power_status,
6124 * snd_hda_parse_generic_codec - Generic codec parser
6125 * @codec: the HDA codec
6127 static int snd_hda_parse_generic_codec(struct hda_codec *codec)
6129 struct hda_gen_spec *spec;
6132 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6135 snd_hda_gen_spec_init(spec);
6138 err = snd_hda_parse_pin_defcfg(codec, &spec->autocfg, NULL, 0);
6142 err = snd_hda_gen_parse_auto_config(codec, &spec->autocfg);
6146 codec->patch_ops = generic_patch_ops;
6150 snd_hda_gen_free(codec);
6154 static const struct hda_device_id snd_hda_id_generic[] = {
6155 HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC, "Generic", snd_hda_parse_generic_codec),
6158 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_generic);
6160 static struct hda_codec_driver generic_driver = {
6161 .id = snd_hda_id_generic,
6164 module_hda_codec_driver(generic_driver);
6166 MODULE_LICENSE("GPL");
6167 MODULE_DESCRIPTION("Generic HD-audio codec parser");