Lines Matching +full:codec +full:- +full:2
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Universal Interface for Intel High Definition Audio Codec
32 * snd_hda_gen_spec_init - initialize hda_gen_spec struct
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);
48 * snd_hda_gen_add_kctl - Add a new kctl_new struct from the template
62 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
67 knew->name = kstrdup(name, GFP_KERNEL);
68 else if (knew->name)
69 knew->name = kstrdup(knew->name, GFP_KERNEL);
70 if (!knew->name)
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);
92 snd_array_free(&spec->paths);
93 snd_array_free(&spec->loopback_list);
95 if (spec->led_cdevs[LED_AUDIO_MUTE])
96 led_classdev_unregister(spec->led_cdevs[LED_AUDIO_MUTE]);
97 if (spec->led_cdevs[LED_AUDIO_MICMUTE])
98 led_classdev_unregister(spec->led_cdevs[LED_AUDIO_MICMUTE]);
105 static void parse_user_hints(struct hda_codec *codec)
107 struct hda_gen_spec *spec = codec->spec;
110 val = snd_hda_get_bool_hint(codec, "jack_detect");
112 codec->no_jack_detect = !val;
113 val = snd_hda_get_bool_hint(codec, "inv_jack_detect");
115 codec->inv_jack_detect = !!val;
116 val = snd_hda_get_bool_hint(codec, "trigger_sense");
118 codec->no_trigger_sense = !val;
119 val = snd_hda_get_bool_hint(codec, "inv_eapd");
121 codec->inv_eapd = !!val;
122 val = snd_hda_get_bool_hint(codec, "pcm_format_first");
124 codec->pcm_format_first = !!val;
125 val = snd_hda_get_bool_hint(codec, "sticky_stream");
127 codec->no_sticky_stream = !val;
128 val = snd_hda_get_bool_hint(codec, "spdif_status_reset");
130 codec->spdif_status_reset = !!val;
131 val = snd_hda_get_bool_hint(codec, "pin_amp_workaround");
133 codec->pin_amp_workaround = !!val;
134 val = snd_hda_get_bool_hint(codec, "single_adc_amp");
136 codec->single_adc_amp = !!val;
137 val = snd_hda_get_bool_hint(codec, "power_save_node");
139 codec->power_save_node = !!val;
141 val = snd_hda_get_bool_hint(codec, "auto_mute");
143 spec->suppress_auto_mute = !val;
144 val = snd_hda_get_bool_hint(codec, "auto_mic");
146 spec->suppress_auto_mic = !val;
147 val = snd_hda_get_bool_hint(codec, "line_in_auto_switch");
149 spec->line_in_auto_switch = !!val;
150 val = snd_hda_get_bool_hint(codec, "auto_mute_via_amp");
152 spec->auto_mute_via_amp = !!val;
153 val = snd_hda_get_bool_hint(codec, "need_dac_fix");
155 spec->need_dac_fix = !!val;
156 val = snd_hda_get_bool_hint(codec, "primary_hp");
158 spec->no_primary_hp = !val;
159 val = snd_hda_get_bool_hint(codec, "multi_io");
161 spec->no_multi_io = !val;
162 val = snd_hda_get_bool_hint(codec, "multi_cap_vol");
164 spec->multi_cap_vol = !!val;
165 val = snd_hda_get_bool_hint(codec, "inv_dmic_split");
167 spec->inv_dmic_split = !!val;
168 val = snd_hda_get_bool_hint(codec, "indep_hp");
170 spec->indep_hp = !!val;
171 val = snd_hda_get_bool_hint(codec, "add_stereo_mix_input");
173 spec->add_stereo_mix_input = !!val;
175 val = snd_hda_get_bool_hint(codec, "add_out_jack_modes");
177 spec->add_jack_modes = !!val;
178 val = snd_hda_get_bool_hint(codec, "add_in_jack_modes");
180 spec->add_jack_modes = !!val;
181 val = snd_hda_get_bool_hint(codec, "add_jack_modes");
183 spec->add_jack_modes = !!val;
184 val = snd_hda_get_bool_hint(codec, "power_down_unused");
186 spec->power_down_unused = !!val;
187 val = snd_hda_get_bool_hint(codec, "add_hp_mic");
189 spec->hp_mic = !!val;
190 val = snd_hda_get_bool_hint(codec, "hp_mic_detect");
192 spec->suppress_hp_mic_detect = !val;
193 val = snd_hda_get_bool_hint(codec, "vmaster");
195 spec->suppress_vmaster = !val;
197 if (!snd_hda_get_int_hint(codec, "mixer_nid", &val))
198 spec->mixer_nid = val;
205 #define update_pin_ctl(codec, pin, val) \
206 snd_hda_codec_write_cache(codec, pin, 0, \
210 static inline void restore_pin_ctl(struct hda_codec *codec, hda_nid_t pin)
212 update_pin_ctl(codec, pin, snd_hda_codec_get_pin_target(codec, pin));
216 static void set_pin_target(struct hda_codec *codec, hda_nid_t pin,
221 val = snd_hda_correct_pin_ctl(codec, pin, val);
222 snd_hda_codec_set_pin_target(codec, pin, val);
224 update_pin_ctl(codec, pin, val);
228 static void set_pin_targets(struct hda_codec *codec, int num_pins,
233 set_pin_target(codec, pins[i], val, false);
240 /* return the position of NID in the list, or -1 if not found */
247 return -1;
253 return find_idx_in_nid_list(nid, path->path, path->depth) >= 0;
256 static struct nid_path *get_nid_path(struct hda_codec *codec,
260 struct hda_gen_spec *spec = codec->spec;
264 snd_array_for_each(&spec->paths, i, path) {
265 if (path->depth <= 0)
267 if ((!from_nid || path->path[0] == from_nid) &&
268 (!to_nid || path->path[path->depth - 1] == to_nid)) {
279 * snd_hda_get_path_idx - get the index number corresponding to the path
281 * @codec: the HDA codec
287 int snd_hda_get_path_idx(struct hda_codec *codec, struct nid_path *path)
289 struct hda_gen_spec *spec = codec->spec;
290 struct nid_path *array = spec->paths.list;
293 if (!spec->paths.used)
295 idx = path - array;
296 if (idx < 0 || idx >= spec->paths.used)
303 * snd_hda_get_path_from_idx - get the path instance corresponding to the
305 * @codec: the HDA codec
308 struct nid_path *snd_hda_get_path_from_idx(struct hda_codec *codec, int idx)
310 struct hda_gen_spec *spec = codec->spec;
312 if (idx <= 0 || idx > spec->paths.used)
314 return snd_array_elem(&spec->paths, idx - 1);
319 static bool is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
321 struct hda_gen_spec *spec = codec->spec;
325 snd_array_for_each(&spec->paths, i, path) {
326 if (path->path[0] == nid)
333 static bool is_reachable_path(struct hda_codec *codec,
338 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
345 static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
347 struct hda_gen_spec *spec = codec->spec;
352 snd_array_for_each(&spec->paths, i, path) {
353 if ((path->ctls[type] & AMP_VAL_COMPARE_MASK) == val)
360 static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
364 return is_ctl_used(codec, val, type);
367 static void print_nid_path(struct hda_codec *codec,
375 for (i = 0; i < path->depth; i++)
376 pos += scnprintf(pos, sizeof(buf) - (pos - buf), "%s%02x",
378 path->path[i]);
380 codec_dbg(codec, "%s path: depth=%d '%s'\n", pfx, path->depth, buf);
384 static bool __parse_nid_path(struct hda_codec *codec,
394 else if (to_nid == (hda_nid_t)(-anchor_nid))
397 nums = snd_hda_get_conn_list(codec, to_nid, &conn);
404 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
405 is_dac_already_used(codec, conn[i]))
416 type = get_wcaps_type(get_wcaps(codec, conn[i]));
420 if (__parse_nid_path(codec, from_nid, conn[i],
427 path->path[path->depth] = conn[i];
428 path->idx[path->depth + 1] = i;
429 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
430 path->multi[path->depth + 1] = 1;
431 path->depth++;
436 * snd_hda_parse_nid_path - parse the widget path from the given nid to
438 * @codec: the HDA codec
454 static bool snd_hda_parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
458 if (__parse_nid_path(codec, from_nid, to_nid, anchor_nid, path, 1)) {
459 path->path[path->depth] = to_nid;
460 path->depth++;
467 * snd_hda_add_new_path - parse the path between the given NIDs and
469 * @codec: the HDA codec
477 snd_hda_add_new_path(struct hda_codec *codec, hda_nid_t from_nid,
480 struct hda_gen_spec *spec = codec->spec;
483 if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid))
487 path = get_nid_path(codec, from_nid, to_nid, anchor_nid);
491 path = snd_array_new(&spec->paths);
495 if (snd_hda_parse_nid_path(codec, from_nid, to_nid, anchor_nid, path))
498 spec->paths.used--;
504 static void invalidate_nid_path(struct hda_codec *codec, int idx)
506 struct nid_path *path = snd_hda_get_path_from_idx(codec, idx);
512 /* return a DAC if paired to the given pin by codec driver */
513 static hda_nid_t get_preferred_dac(struct hda_codec *codec, hda_nid_t pin)
515 struct hda_gen_spec *spec = codec->spec;
516 const hda_nid_t *list = spec->preferred_dacs;
520 for (; *list; list += 2)
527 static hda_nid_t look_for_dac(struct hda_codec *codec, hda_nid_t pin,
530 struct hda_gen_spec *spec = codec->spec;
534 for (i = 0; i < spec->num_all_dacs; i++) {
535 hda_nid_t nid = spec->all_dacs[i];
536 if (!nid || is_dac_already_used(codec, nid))
538 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
541 if (is_reachable_path(codec, nid, pin))
555 static bool same_amp_caps(struct hda_codec *codec, hda_nid_t nid1,
558 if (!(get_wcaps(codec, nid1) & (1 << (dir + 1))))
559 return !(get_wcaps(codec, nid2) & (1 << (dir + 1)));
560 return (query_amp_caps(codec, nid1, dir) ==
561 query_amp_caps(codec, nid2, dir));
565 static hda_nid_t look_for_out_mute_nid(struct hda_codec *codec,
570 for (i = path->depth - 1; i >= 0; i--) {
571 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
572 return path->path[i];
573 if (i != path->depth - 1 && i != 0 &&
574 nid_has_mute(codec, path->path[i], HDA_INPUT))
575 return path->path[i];
581 static hda_nid_t look_for_out_vol_nid(struct hda_codec *codec,
584 struct hda_gen_spec *spec = codec->spec;
587 for (i = path->depth - 1; i >= 0; i--) {
588 hda_nid_t nid = path->path[i];
589 if ((spec->out_vol_mask >> nid) & 1)
591 if (nid_has_volume(codec, nid, HDA_OUTPUT))
601 /* can have the amp-in capability? */
602 static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
604 hda_nid_t nid = path->path[idx];
605 unsigned int caps = get_wcaps(codec, nid);
615 /* can have the amp-out capability? */
616 static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
618 hda_nid_t nid = path->path[idx];
619 unsigned int caps = get_wcaps(codec, nid);
630 static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
633 struct hda_gen_spec *spec = codec->spec;
634 int type = get_wcaps_type(get_wcaps(codec, nid));
638 if (nid == codec->core.afg)
641 snd_array_for_each(&spec->paths, n, path) {
642 if (!path->active)
644 if (codec->power_save_node) {
645 if (!path->stream_enabled)
648 if (!(path->pin_enabled || path->pin_fixed) &&
652 for (i = 0; i < path->depth; i++) {
653 if (path->path[i] == nid) {
654 if (dir == HDA_OUTPUT || idx == -1 ||
655 path->idx[i] == idx)
665 #define is_active_nid_for_any(codec, nid) \
666 is_active_nid(codec, nid, HDA_OUTPUT, -1)
669 static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
686 /* is this a stereo widget or a stereo-to-mono mix? */
687 static bool is_stereo_amps(struct hda_codec *codec, hda_nid_t nid, int dir)
689 unsigned int wcaps = get_wcaps(codec, nid);
696 if (snd_hda_get_num_conns(codec, nid) != 1)
698 if (snd_hda_get_connections(codec, nid, &conn, 1) < 0)
700 return !!(get_wcaps(codec, conn) & AC_WCAP_STEREO);
704 static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
706 unsigned int caps = query_amp_caps(codec, nid, dir);
707 int val = get_amp_val_to_activate(codec, nid, dir, caps, false);
709 if (is_stereo_amps(codec, nid, dir))
710 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
712 snd_hda_codec_amp_init(codec, nid, 0, dir, idx, 0xff, val);
716 static int update_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx,
719 if (is_stereo_amps(codec, nid, dir))
720 return snd_hda_codec_amp_stereo(codec, nid, dir, idx,
723 return snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
730 static unsigned int get_amp_mask_to_modify(struct hda_codec *codec,
737 if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_MUTE_CTL))
741 if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
742 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
748 static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
754 caps = query_amp_caps(codec, nid, dir);
755 val = get_amp_val_to_activate(codec, nid, dir, caps, enable);
756 mask = get_amp_mask_to_modify(codec, nid, dir, idx_to_check, caps);
761 update_amp(codec, nid, dir, idx, mask, val);
764 static void check_and_activate_amp(struct hda_codec *codec, hda_nid_t nid,
769 if (!enable && is_active_nid(codec, nid, dir, idx_to_check))
771 activate_amp(codec, nid, dir, idx, idx_to_check, enable);
774 static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
777 hda_nid_t nid = path->path[i];
778 init_amp(codec, nid, HDA_OUTPUT, 0);
779 check_and_activate_amp(codec, nid, HDA_OUTPUT, 0, 0, enable);
782 static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
785 struct hda_gen_spec *spec = codec->spec;
789 hda_nid_t nid = path->path[i];
791 nums = snd_hda_get_conn_list(codec, nid, &conn);
794 type = get_wcaps_type(get_wcaps(codec, nid));
796 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
800 idx = path->idx[i];
803 init_amp(codec, nid, HDA_INPUT, n);
806 * when aa-mixer is available, we need to enable the path as well
810 if (conn[n] != spec->mixer_merge_nid)
814 activate_amp(codec, nid, HDA_INPUT, n, n, false);
818 check_and_activate_amp(codec, nid, HDA_INPUT, n, idx, enable);
823 static hda_nid_t path_power_update(struct hda_codec *codec,
830 for (i = 0; i < path->depth; i++) {
831 nid = path->path[i];
832 if (!(get_wcaps(codec, nid) & AC_WCAP_POWER))
834 if (nid == codec->core.afg)
836 if (!allow_powerdown || is_active_nid_for_any(codec, nid))
840 power = snd_hda_codec_read(codec, nid, 0,
843 snd_hda_codec_write(codec, nid, 0,
854 snd_hdac_regmap_sync_node(&codec->core, nid);
862 static void sync_power_state_change(struct hda_codec *codec, hda_nid_t nid)
866 snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
871 * snd_hda_activate_path - activate or deactivate the given path
872 * @codec: the HDA codec
877 * If @add_aamix is set, enable the input from aa-mix NID as well (if any).
879 void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
882 struct hda_gen_spec *spec = codec->spec;
885 path->active = enable;
888 if (enable && (spec->power_down_unused || codec->power_save_node))
889 path_power_update(codec, path, codec->power_save_node);
891 for (i = path->depth - 1; i >= 0; i--) {
892 hda_nid_t nid = path->path[i];
894 if (enable && path->multi[i])
895 snd_hda_codec_write_cache(codec, nid, 0,
897 path->idx[i]);
898 if (has_amp_in(codec, path, i))
899 activate_amp_in(codec, path, i, enable, add_aamix);
900 if (has_amp_out(codec, path, i))
901 activate_amp_out(codec, path, i, enable);
907 static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path)
909 struct hda_gen_spec *spec = codec->spec;
911 if (!(spec->power_down_unused || codec->power_save_node) || path->active)
913 sync_power_state_change(codec, path_power_update(codec, path, true));
917 static void set_pin_eapd(struct hda_codec *codec, hda_nid_t pin, bool enable)
919 struct hda_gen_spec *spec = codec->spec;
920 if (spec->own_eapd_ctl ||
921 !(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD))
923 if (spec->keep_eapd_on && !enable)
925 if (codec->inv_eapd)
927 snd_hda_codec_write_cache(codec, pin, 0,
932 /* re-initialize the path specified by the given path index */
933 static void resume_path_from_idx(struct hda_codec *codec, int path_idx)
935 struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
937 snd_hda_activate_path(codec, path, path->active, false);
987 knew->index = cidx;
989 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
990 if (knew->access == 0)
991 knew->access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
992 knew->private_value = val;
1005 return -EINVAL;
1007 return -ENOMEM;
1020 static int add_vol_ctl(struct hda_codec *codec, const char *pfx, int cidx,
1026 val = path->ctls[NID_PATH_VOL_CTL];
1030 return __add_pb_vol_ctrl(codec->spec, HDA_CTL_WIDGET_VOL, pfx, cidx, val);
1033 /* return the channel bits suitable for the given path->ctls[] */
1034 static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
1039 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
1040 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
1046 static int add_stereo_vol(struct hda_codec *codec, const char *pfx, int cidx,
1049 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
1050 return add_vol_ctl(codec, pfx, cidx, chs, path);
1053 /* create a mute-switch for the given mixer widget;
1054 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
1056 static int add_sw_ctl(struct hda_codec *codec, const char *pfx, int cidx,
1064 val = path->ctls[NID_PATH_MUTE_CTL];
1070 int nums = snd_hda_get_num_conns(codec, nid);
1076 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
1079 static int add_stereo_sw(struct hda_codec *codec, const char *pfx,
1082 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
1083 return add_sw_ctl(codec, pfx, cidx, chs, path);
1090 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1091 struct hda_gen_spec *spec = codec->spec;
1093 if (spec->auto_mute_via_amp) {
1095 bool enabled = !((spec->mute_bits >> nid) & 1);
1096 ucontrol->value.integer.value[0] &= enabled;
1097 ucontrol->value.integer.value[1] &= enabled;
1117 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1121 guard(mutex)(&codec->control_mutex);
1122 pval = kcontrol->private_value;
1123 kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */
1125 kcontrol->private_value = pval;
1132 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1138 guard(mutex)(&codec->control_mutex);
1139 pval = kcontrol->private_value;
1142 kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) |
1149 kcontrol->private_value = pval;
1154 static bool path_has_mixer(struct hda_codec *codec, int path_idx, int ctl_type)
1156 struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
1157 return path && path->ctls[ctl_type];
1165 static const char *get_line_out_pfx(struct hda_codec *codec, int ch,
1168 struct hda_gen_spec *spec = codec->spec;
1169 struct auto_pin_cfg *cfg = &spec->autocfg;
1172 if (cfg->line_outs == 1 && !spec->multi_ios &&
1173 !codec->force_pin_prefix &&
1174 !cfg->hp_outs && !cfg->speaker_outs)
1175 return spec->vmaster_mute.hook ? "PCM" : "Master";
1180 if (spec->multiout.num_dacs == 1 && !spec->mixer_nid &&
1181 !codec->force_pin_prefix &&
1182 !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0])
1183 return spec->vmaster_mute.hook ? "PCM" : "Master";
1185 /* multi-io channels */
1186 if (ch >= cfg->line_outs)
1189 switch (cfg->line_out_type) {
1194 if (!ch && cfg->hp_outs &&
1195 !path_has_mixer(codec, spec->hp_paths[0], ctl_type))
1197 if (cfg->line_outs == 1)
1199 if (cfg->line_outs == 2)
1206 if (!ch && cfg->speaker_outs &&
1207 !path_has_mixer(codec, spec->speaker_paths[0], ctl_type))
1209 /* for multi-io case, only the primary out */
1210 if (ch && spec->multi_ios)
1221 if (cfg->speaker_outs)
1222 spk_lo_shared = !path_has_mixer(codec,
1223 spec->speaker_paths[0], ctl_type);
1224 if (cfg->hp_outs)
1225 hp_lo_shared = !path_has_mixer(codec, spec->hp_paths[0], ctl_type);
1227 return spec->vmaster_mute.hook ? "PCM" : "Master";
1236 if (cfg->line_outs == 1 && !spec->multi_ios)
1258 /* No possible multi-ios */
1283 static int assign_out_path_ctls(struct hda_codec *codec, struct nid_path *path)
1285 struct hda_gen_spec *spec = codec->spec;
1291 return BAD_SHARED_VOL * 2;
1293 if (path->ctls[NID_PATH_VOL_CTL] ||
1294 path->ctls[NID_PATH_MUTE_CTL])
1297 nid = look_for_out_vol_nid(codec, path);
1300 if (spec->dac_min_mute)
1302 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
1305 path->ctls[NID_PATH_VOL_CTL] = val;
1308 nid = look_for_out_mute_nid(codec, path);
1310 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
1312 nid_has_mute(codec, nid, HDA_OUTPUT))
1316 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
1319 path->ctls[NID_PATH_MUTE_CTL] = val;
1346 static hda_nid_t get_primary_out(struct hda_codec *codec, int idx)
1348 struct hda_gen_spec *spec = codec->spec;
1349 struct auto_pin_cfg *cfg = &spec->autocfg;
1351 if (cfg->line_outs > idx)
1352 return spec->private_dac_nids[idx];
1353 idx -= cfg->line_outs;
1354 if (spec->multi_ios > idx)
1355 return spec->multi_io[idx].dac;
1360 static inline hda_nid_t try_dac(struct hda_codec *codec,
1363 return is_reachable_path(codec, dac, pin) ? dac : 0;
1367 static int try_assign_dacs(struct hda_codec *codec, int num_outs,
1372 struct hda_gen_spec *spec = codec->spec;
1384 if (!spec->preferred_dacs) {
1385 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1387 badness += assign_out_path_ctls(codec, path);
1392 dacs[i] = get_preferred_dac(codec, pin);
1394 if (is_dac_already_used(codec, dacs[i]))
1395 badness += bad->shared_primary;
1396 } else if (spec->preferred_dacs) {
1401 dacs[i] = look_for_dac(codec, pin, false);
1405 if (is_reachable_path(codec, dacs[j], pin)) {
1408 invalidate_nid_path(codec, path_idx[j]);
1416 if (num_outs > 2)
1417 dac = try_dac(codec, get_primary_out(codec, i), pin);
1419 dac = try_dac(codec, dacs[0], pin);
1421 dac = try_dac(codec, get_primary_out(codec, i), pin);
1424 badness += bad->shared_primary;
1426 badness += bad->shared_surr;
1428 badness += bad->shared_clfe;
1429 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
1430 dac = spec->private_dac_nids[0];
1431 badness += bad->shared_surr_main;
1433 badness += bad->no_primary_dac;
1435 badness += bad->no_dac;
1439 path = snd_hda_add_new_path(codec, dac, pin, -spec->mixer_nid);
1440 if (!path && !i && spec->mixer_nid) {
1442 path = snd_hda_add_new_path(codec, dac, pin, 0);
1446 badness += bad->no_dac;
1448 /* print_nid_path(codec, "output", path); */
1449 path->active = true;
1450 path_idx[i] = snd_hda_get_path_idx(codec, path);
1451 badness += assign_out_path_ctls(codec, path);
1459 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
1461 struct hda_gen_spec *spec = codec->spec;
1465 for (i = 0; i < spec->num_all_dacs; i++) {
1466 hda_nid_t nid = spec->all_dacs[i];
1467 if (!nid || is_dac_already_used(codec, nid))
1469 if (is_reachable_path(codec, nid, pin)) {
1478 /* check whether the given pin can be a multi-io pin */
1479 static bool can_be_multiio_pin(struct hda_codec *codec,
1484 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1489 caps = snd_hda_query_pin_caps(codec, nid);
1495 /* count the number of input pins that are capable to be multi-io */
1496 static int count_multiio_pins(struct hda_codec *codec, hda_nid_t reference_pin)
1498 struct hda_gen_spec *spec = codec->spec;
1499 struct auto_pin_cfg *cfg = &spec->autocfg;
1500 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1505 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
1506 for (i = 0; i < cfg->num_inputs; i++) {
1507 if (cfg->inputs[i].type != type)
1509 if (can_be_multiio_pin(codec, location,
1510 cfg->inputs[i].pin))
1518 * multi-io helper
1521 * zero if any pins are filled, non-zero if nothing found.
1525 static int fill_multi_ios(struct hda_codec *codec,
1529 struct hda_gen_spec *spec = codec->spec;
1530 struct auto_pin_cfg *cfg = &spec->autocfg;
1532 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1537 old_pins = spec->multi_ios;
1538 if (old_pins >= 2)
1541 num_pins = count_multiio_pins(codec, reference_pin);
1542 if (num_pins < 2)
1545 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
1546 for (i = 0; i < cfg->num_inputs; i++) {
1547 hda_nid_t nid = cfg->inputs[i].pin;
1550 if (cfg->inputs[i].type != type)
1552 if (!can_be_multiio_pin(codec, location, nid))
1554 for (j = 0; j < spec->multi_ios; j++) {
1555 if (nid == spec->multi_io[j].pin)
1558 if (j < spec->multi_ios)
1562 dac = get_dac_if_single(codec, nid);
1564 dac = look_for_dac(codec, nid, false);
1569 path = snd_hda_add_new_path(codec, dac, nid,
1570 -spec->mixer_nid);
1575 /* print_nid_path(codec, "multiio", path); */
1576 spec->multi_io[spec->multi_ios].pin = nid;
1577 spec->multi_io[spec->multi_ios].dac = dac;
1578 spec->out_paths[cfg->line_outs + spec->multi_ios] =
1579 snd_hda_get_path_idx(codec, path);
1580 spec->multi_ios++;
1581 if (spec->multi_ios >= 2)
1588 if (old_pins == spec->multi_ios) {
1594 if (!hardwired && spec->multi_ios < 2) {
1596 spec->paths.used -= spec->multi_ios - old_pins;
1597 spec->multi_ios = old_pins;
1602 for (i = old_pins; i < spec->multi_ios; i++) {
1603 path = snd_hda_get_path_from_idx(codec, spec->out_paths[cfg->line_outs + i]);
1604 badness += assign_out_path_ctls(codec, path);
1611 static bool map_singles(struct hda_codec *codec, int outs,
1614 struct hda_gen_spec *spec = codec->spec;
1622 dac = get_dac_if_single(codec, pins[i]);
1625 path = snd_hda_add_new_path(codec, dac, pins[i],
1626 -spec->mixer_nid);
1627 if (!path && !i && spec->mixer_nid)
1628 path = snd_hda_add_new_path(codec, dac, pins[i], 0);
1632 /* print_nid_path(codec, "output", path); */
1633 path->active = true;
1634 path_idx[i] = snd_hda_get_path_idx(codec, path);
1642 return spec->aamix_out_paths[0] || spec->aamix_out_paths[1] ||
1643 spec->aamix_out_paths[2];
1647 static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
1649 struct hda_gen_spec *spec = codec->spec;
1653 path = snd_hda_get_path_from_idx(codec, path_idx);
1654 if (!path || !path->depth ||
1655 is_nid_contained(path, spec->mixer_nid))
1657 path_dac = path->path[0];
1658 dac = spec->private_dac_nids[0];
1659 pin = path->path[path->depth - 1];
1660 path = snd_hda_add_new_path(codec, dac, pin, spec->mixer_nid);
1664 else if (spec->multiout.hp_out_nid[0])
1665 dac = spec->multiout.hp_out_nid[0];
1666 else if (spec->multiout.extra_out_nid[0])
1667 dac = spec->multiout.extra_out_nid[0];
1671 path = snd_hda_add_new_path(codec, dac, pin,
1672 spec->mixer_nid);
1676 /* print_nid_path(codec, "output-aamix", path); */
1677 path->active = false; /* unused as default */
1678 path->pin_fixed = true; /* static route */
1679 return snd_hda_get_path_idx(codec, path);
1683 static bool indep_hp_possible(struct hda_codec *codec)
1685 struct hda_gen_spec *spec = codec->spec;
1686 struct auto_pin_cfg *cfg = &spec->autocfg;
1690 if (cfg->line_out_type == AUTO_PIN_HP_OUT)
1691 idx = spec->out_paths[0];
1693 idx = spec->hp_paths[0];
1694 path = snd_hda_get_path_from_idx(codec, idx);
1699 if (!spec->mixer_nid || !is_nid_contained(path, spec->mixer_nid))
1703 for (i = 0; i < cfg->line_outs; i++) {
1704 if (spec->out_paths[i] == idx)
1706 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
1707 if (path && is_nid_contained(path, spec->mixer_nid))
1710 for (i = 0; i < cfg->speaker_outs; i++) {
1711 path = snd_hda_get_path_from_idx(codec, spec->speaker_paths[i]);
1712 if (path && is_nid_contained(path, spec->mixer_nid))
1722 static void refill_shared_dacs(struct hda_codec *codec, int num_outs,
1731 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1734 dacs[i] = path->path[0];
1739 static int fill_and_eval_dacs(struct hda_codec *codec,
1743 struct hda_gen_spec *spec = codec->spec;
1744 struct auto_pin_cfg *cfg = &spec->autocfg;
1748 spec->multiout.num_dacs = cfg->line_outs;
1749 spec->multiout.dac_nids = spec->private_dac_nids;
1750 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
1751 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
1752 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
1753 spec->multi_ios = 0;
1754 snd_array_free(&spec->paths);
1757 memset(spec->out_paths, 0, sizeof(spec->out_paths));
1758 memset(spec->hp_paths, 0, sizeof(spec->hp_paths));
1759 memset(spec->speaker_paths, 0, sizeof(spec->speaker_paths));
1760 memset(spec->aamix_out_paths, 0, sizeof(spec->aamix_out_paths));
1761 memset(spec->digout_paths, 0, sizeof(spec->digout_paths));
1762 memset(spec->input_paths, 0, sizeof(spec->input_paths));
1763 memset(spec->loopback_paths, 0, sizeof(spec->loopback_paths));
1764 memset(&spec->digin_path, 0, sizeof(spec->digin_path));
1768 /* fill hard-wired DACs first */
1772 mapped = map_singles(codec, cfg->line_outs,
1773 cfg->line_out_pins,
1774 spec->private_dac_nids,
1775 spec->out_paths);
1776 mapped |= map_singles(codec, cfg->hp_outs,
1777 cfg->hp_pins,
1778 spec->multiout.hp_out_nid,
1779 spec->hp_paths);
1780 mapped |= map_singles(codec, cfg->speaker_outs,
1781 cfg->speaker_pins,
1782 spec->multiout.extra_out_nid,
1783 spec->speaker_paths);
1784 if (!spec->no_multi_io &&
1785 fill_mio_first && cfg->line_outs == 1 &&
1786 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1787 err = fill_multi_ios(codec, cfg->line_out_pins[0], true);
1794 badness += try_assign_dacs(codec, cfg->line_outs, cfg->line_out_pins,
1795 spec->private_dac_nids, spec->out_paths,
1796 spec->main_out_badness);
1798 if (!spec->no_multi_io && fill_mio_first &&
1799 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1800 /* try to fill multi-io first */
1801 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1807 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
1808 err = try_assign_dacs(codec, cfg->hp_outs, cfg->hp_pins,
1809 spec->multiout.hp_out_nid,
1810 spec->hp_paths,
1811 spec->extra_out_badness);
1816 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1817 err = try_assign_dacs(codec, cfg->speaker_outs,
1818 cfg->speaker_pins,
1819 spec->multiout.extra_out_nid,
1820 spec->speaker_paths,
1821 spec->extra_out_badness);
1826 if (!spec->no_multi_io &&
1827 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1828 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1834 if (spec->mixer_nid) {
1835 spec->aamix_out_paths[0] =
1836 check_aamix_out_path(codec, spec->out_paths[0]);
1837 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1838 spec->aamix_out_paths[1] =
1839 check_aamix_out_path(codec, spec->hp_paths[0]);
1840 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1841 spec->aamix_out_paths[2] =
1842 check_aamix_out_path(codec, spec->speaker_paths[0]);
1845 if (!spec->no_multi_io &&
1846 cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
1847 if (count_multiio_pins(codec, cfg->hp_pins[0]) >= 2)
1848 spec->multi_ios = 1; /* give badness */
1850 /* re-count num_dacs and squash invalid entries */
1851 spec->multiout.num_dacs = 0;
1852 for (i = 0; i < cfg->line_outs; i++) {
1853 if (spec->private_dac_nids[i])
1854 spec->multiout.num_dacs++;
1856 memmove(spec->private_dac_nids + i,
1857 spec->private_dac_nids + i + 1,
1858 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
1859 spec->private_dac_nids[cfg->line_outs - 1] = 0;
1863 spec->ext_channel_count = spec->min_channel_count =
1864 spec->multiout.num_dacs * 2;
1866 if (spec->multi_ios == 2) {
1867 for (i = 0; i < 2; i++)
1868 spec->private_dac_nids[spec->multiout.num_dacs++] =
1869 spec->multi_io[i].dac;
1870 } else if (spec->multi_ios) {
1871 spec->multi_ios = 0;
1875 if (spec->indep_hp && !indep_hp_possible(codec))
1878 /* re-fill the shared DAC for speaker / headphone */
1879 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1880 refill_shared_dacs(codec, cfg->hp_outs,
1881 spec->multiout.hp_out_nid,
1882 spec->hp_paths);
1883 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1884 refill_shared_dacs(codec, cfg->speaker_outs,
1885 spec->multiout.extra_out_nid,
1886 spec->speaker_paths);
1895 codec_dbg(codec, fmt, ##__VA_ARGS__)
1898 do { if (0) codec_dbg(codec, fmt, ##__VA_ARGS__); } while (0)
1902 static inline void print_nid_path_idx(struct hda_codec *codec,
1907 path = snd_hda_get_path_from_idx(codec, idx);
1909 print_nid_path(codec, pfx, path);
1912 static void debug_show_configs(struct hda_codec *codec,
1915 struct hda_gen_spec *spec = codec->spec;
1920 cfg->line_out_pins[0], cfg->line_out_pins[1],
1921 cfg->line_out_pins[2], cfg->line_out_pins[3],
1922 spec->multiout.dac_nids[0],
1923 spec->multiout.dac_nids[1],
1924 spec->multiout.dac_nids[2],
1925 spec->multiout.dac_nids[3],
1926 lo_type[cfg->line_out_type]);
1927 for (i = 0; i < cfg->line_outs; i++)
1928 print_nid_path_idx(codec, " out", spec->out_paths[i]);
1929 if (spec->multi_ios > 0)
1931 spec->multi_ios,
1932 spec->multi_io[0].pin, spec->multi_io[1].pin,
1933 spec->multi_io[0].dac, spec->multi_io[1].dac);
1934 for (i = 0; i < spec->multi_ios; i++)
1935 print_nid_path_idx(codec, " mio",
1936 spec->out_paths[cfg->line_outs + i]);
1937 if (cfg->hp_outs)
1939 cfg->hp_pins[0], cfg->hp_pins[1],
1940 cfg->hp_pins[2], cfg->hp_pins[3],
1941 spec->multiout.hp_out_nid[0],
1942 spec->multiout.hp_out_nid[1],
1943 spec->multiout.hp_out_nid[2],
1944 spec->multiout.hp_out_nid[3]);
1945 for (i = 0; i < cfg->hp_outs; i++)
1946 print_nid_path_idx(codec, " hp ", spec->hp_paths[i]);
1947 if (cfg->speaker_outs)
1949 cfg->speaker_pins[0], cfg->speaker_pins[1],
1950 cfg->speaker_pins[2], cfg->speaker_pins[3],
1951 spec->multiout.extra_out_nid[0],
1952 spec->multiout.extra_out_nid[1],
1953 spec->multiout.extra_out_nid[2],
1954 spec->multiout.extra_out_nid[3]);
1955 for (i = 0; i < cfg->speaker_outs; i++)
1956 print_nid_path_idx(codec, " spk", spec->speaker_paths[i]);
1958 print_nid_path_idx(codec, " mix", spec->aamix_out_paths[i]);
1961 #define debug_show_configs(codec, cfg) /* NOP */
1964 /* find all available DACs of the codec */
1965 static void fill_all_dac_nids(struct hda_codec *codec)
1967 struct hda_gen_spec *spec = codec->spec;
1970 spec->num_all_dacs = 0;
1971 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
1972 for_each_hda_codec_node(nid, codec) {
1973 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
1975 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
1976 codec_err(codec, "Too many DACs!\n");
1979 spec->all_dacs[spec->num_all_dacs++] = nid;
1983 static int parse_output_paths(struct hda_codec *codec)
1985 struct hda_gen_spec *spec = codec->spec;
1986 struct auto_pin_cfg *cfg = &spec->autocfg;
1997 return -ENOMEM;
2001 badness = fill_and_eval_dacs(codec, fill_hardwired,
2006 cfg->line_out_type, fill_hardwired, fill_mio_first,
2008 debug_show_configs(codec, cfg);
2026 if (cfg->speaker_outs > 0 &&
2027 cfg->line_out_type == AUTO_PIN_HP_OUT) {
2028 cfg->hp_outs = cfg->line_outs;
2029 memcpy(cfg->hp_pins, cfg->line_out_pins,
2030 sizeof(cfg->hp_pins));
2031 cfg->line_outs = cfg->speaker_outs;
2032 memcpy(cfg->line_out_pins, cfg->speaker_pins,
2033 sizeof(cfg->speaker_pins));
2034 cfg->speaker_outs = 0;
2035 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
2036 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
2040 if (cfg->hp_outs > 0 &&
2041 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
2042 cfg->speaker_outs = cfg->line_outs;
2043 memcpy(cfg->speaker_pins, cfg->line_out_pins,
2044 sizeof(cfg->speaker_pins));
2045 cfg->line_outs = cfg->hp_outs;
2046 memcpy(cfg->line_out_pins, cfg->hp_pins,
2047 sizeof(cfg->hp_pins));
2048 cfg->hp_outs = 0;
2049 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
2050 cfg->line_out_type = AUTO_PIN_HP_OUT;
2060 fill_and_eval_dacs(codec, best_wired, best_mio);
2063 cfg->line_out_type, best_wired, best_mio);
2064 debug_show_configs(codec, cfg);
2066 if (cfg->line_out_pins[0]) {
2068 path = snd_hda_get_path_from_idx(codec, spec->out_paths[0]);
2070 spec->vmaster_nid = look_for_out_vol_nid(codec, path);
2071 if (spec->vmaster_nid) {
2072 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2073 HDA_OUTPUT, spec->vmaster_tlv);
2074 if (spec->dac_min_mute)
2075 spec->vmaster_tlv[SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP] |= TLV_DB_SCALE_MUTE;
2080 if (spec->prefer_hp_amp || cfg->line_out_type == AUTO_PIN_HP_OUT)
2084 set_pin_targets(codec, cfg->line_outs, cfg->line_out_pins, val);
2085 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
2086 set_pin_targets(codec, cfg->hp_outs, cfg->hp_pins, PIN_HP);
2087 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
2088 val = spec->prefer_hp_amp ? PIN_HP : PIN_OUT;
2089 set_pin_targets(codec, cfg->speaker_outs,
2090 cfg->speaker_pins, val);
2094 if (spec->indep_hp && !indep_hp_possible(codec))
2095 spec->indep_hp = 0;
2101 static int create_multi_out_ctls(struct hda_codec *codec,
2104 struct hda_gen_spec *spec = codec->spec;
2107 noutputs = cfg->line_outs;
2108 if (spec->multi_ios > 0 && cfg->line_outs < 3)
2109 noutputs += spec->multi_ios;
2116 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
2120 name = get_line_out_pfx(codec, i, &index, NID_PATH_VOL_CTL);
2123 err = add_vol_ctl(codec, "Center", 0, 1, path);
2126 err = add_vol_ctl(codec, "LFE", 0, 2, path);
2130 err = add_stereo_vol(codec, name, index, path);
2135 name = get_line_out_pfx(codec, i, &index, NID_PATH_MUTE_CTL);
2137 err = add_sw_ctl(codec, "Center", 0, 1, path);
2140 err = add_sw_ctl(codec, "LFE", 0, 2, path);
2144 err = add_stereo_sw(codec, name, index, path);
2152 static int create_extra_out(struct hda_codec *codec, int path_idx,
2158 path = snd_hda_get_path_from_idx(codec, path_idx);
2161 err = add_stereo_vol(codec, pfx, cidx, path);
2164 err = add_stereo_sw(codec, pfx, cidx, path);
2171 static int create_extra_outs(struct hda_codec *codec, int num_pins,
2181 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker"))
2191 err = create_extra_out(codec, paths[i], name, idx);
2198 static int create_hp_out_ctls(struct hda_codec *codec)
2200 struct hda_gen_spec *spec = codec->spec;
2201 return create_extra_outs(codec, spec->autocfg.hp_outs,
2202 spec->hp_paths,
2206 static int create_speaker_out_ctls(struct hda_codec *codec)
2208 struct hda_gen_spec *spec = codec->spec;
2209 return create_extra_outs(codec, spec->autocfg.speaker_outs,
2210 spec->speaker_paths,
2218 static void call_hp_automute(struct hda_codec *codec,
2229 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2230 struct hda_gen_spec *spec = codec->spec;
2231 ucontrol->value.enumerated.item[0] = spec->indep_hp_enabled;
2235 static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
2242 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2243 struct hda_gen_spec *spec = codec->spec;
2244 unsigned int select = ucontrol->value.enumerated.item[0];
2247 guard(mutex)(&spec->pcm_mutex);
2248 if (spec->active_streams)
2249 return -EBUSY;
2251 if (spec->indep_hp_enabled != select) {
2253 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
2254 dacp = &spec->private_dac_nids[0];
2256 dacp = &spec->multiout.hp_out_nid[0];
2259 if (spec->have_aamix_ctl) {
2260 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
2261 update_aamix_paths(codec, spec->aamix_mode,
2262 spec->out_paths[0],
2263 spec->aamix_out_paths[0],
2264 spec->autocfg.line_out_type);
2266 update_aamix_paths(codec, spec->aamix_mode,
2267 spec->hp_paths[0],
2268 spec->aamix_out_paths[1],
2272 spec->indep_hp_enabled = select;
2273 if (spec->indep_hp_enabled)
2276 *dacp = spec->alt_dac_nid;
2278 call_hp_automute(codec, NULL);
2293 static int create_indep_hp_ctls(struct hda_codec *codec)
2295 struct hda_gen_spec *spec = codec->spec;
2298 if (!spec->indep_hp)
2300 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
2301 dac = spec->multiout.dac_nids[0];
2303 dac = spec->multiout.hp_out_nid[0];
2305 spec->indep_hp = 0;
2309 spec->indep_hp_enabled = false;
2310 spec->alt_dac_nid = dac;
2312 return -ENOMEM;
2323 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2324 struct hda_gen_spec *spec = codec->spec;
2327 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2328 uinfo->count = 1;
2329 uinfo->value.enumerated.items = spec->multi_ios + 1;
2330 if (uinfo->value.enumerated.item > spec->multi_ios)
2331 uinfo->value.enumerated.item = spec->multi_ios;
2332 chs = uinfo->value.enumerated.item * 2 + spec->min_channel_count;
2333 sprintf(uinfo->value.enumerated.name, "%dch", chs);
2340 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2341 struct hda_gen_spec *spec = codec->spec;
2342 ucontrol->value.enumerated.item[0] =
2343 (spec->ext_channel_count - spec->min_channel_count) / 2;
2348 get_multiio_path(struct hda_codec *codec, int idx)
2350 struct hda_gen_spec *spec = codec->spec;
2351 return snd_hda_get_path_from_idx(codec,
2352 spec->out_paths[spec->autocfg.line_outs + idx]);
2355 static void update_automute_all(struct hda_codec *codec);
2362 return !spec->have_aamix_ctl || spec->aamix_mode;
2365 static int set_multi_io(struct hda_codec *codec, int idx, bool output)
2367 struct hda_gen_spec *spec = codec->spec;
2368 hda_nid_t nid = spec->multi_io[idx].pin;
2371 path = get_multiio_path(codec, idx);
2373 return -EINVAL;
2375 if (path->active == output)
2379 set_pin_target(codec, nid, PIN_OUT, true);
2380 snd_hda_activate_path(codec, path, true, aamix_default(spec));
2381 set_pin_eapd(codec, nid, true);
2383 set_pin_eapd(codec, nid, false);
2384 snd_hda_activate_path(codec, path, false, aamix_default(spec));
2385 set_pin_target(codec, nid, spec->multi_io[idx].ctl_in, true);
2386 path_power_down_sync(codec, path);
2390 update_automute_all(codec);
2398 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2399 struct hda_gen_spec *spec = codec->spec;
2402 ch = ucontrol->value.enumerated.item[0];
2403 if (ch < 0 || ch > spec->multi_ios)
2404 return -EINVAL;
2405 if (ch == (spec->ext_channel_count - spec->min_channel_count) / 2)
2407 spec->ext_channel_count = ch * 2 + spec->min_channel_count;
2408 for (i = 0; i < spec->multi_ios; i++)
2409 set_multi_io(codec, i, i < ch);
2410 spec->multiout.max_channels = max(spec->ext_channel_count,
2411 spec->const_channel_count);
2412 if (spec->need_dac_fix)
2413 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
2425 static int create_multi_channel_mode(struct hda_codec *codec)
2427 struct hda_gen_spec *spec = codec->spec;
2429 if (spec->multi_ios > 0) {
2431 return -ENOMEM;
2445 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2446 struct hda_gen_spec *spec = codec->spec;
2447 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2451 static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
2455 struct hda_gen_spec *spec = codec->spec;
2458 nomix_path = snd_hda_get_path_from_idx(codec, nomix_path_idx);
2459 mix_path = snd_hda_get_path_from_idx(codec, mix_path_idx);
2466 if (out_type == AUTO_PIN_HP_OUT && spec->indep_hp_enabled &&
2467 mix_path->path[0] != spec->alt_dac_nid)
2471 snd_hda_activate_path(codec, nomix_path, false, true);
2472 snd_hda_activate_path(codec, mix_path, true, true);
2473 path_power_down_sync(codec, nomix_path);
2475 snd_hda_activate_path(codec, mix_path, false, false);
2476 snd_hda_activate_path(codec, nomix_path, true, false);
2477 path_power_down_sync(codec, mix_path);
2481 /* re-initialize the output paths; only called from loopback_mixing_put() */
2482 static void update_output_paths(struct hda_codec *codec, int num_outs,
2485 struct hda_gen_spec *spec = codec->spec;
2490 path = snd_hda_get_path_from_idx(codec, paths[i]);
2492 snd_hda_activate_path(codec, path, path->active,
2493 spec->aamix_mode);
2500 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2501 struct hda_gen_spec *spec = codec->spec;
2502 const struct auto_pin_cfg *cfg = &spec->autocfg;
2503 unsigned int val = ucontrol->value.enumerated.item[0];
2505 if (val == spec->aamix_mode)
2507 spec->aamix_mode = val;
2509 update_aamix_paths(codec, val, spec->out_paths[0],
2510 spec->aamix_out_paths[0],
2511 cfg->line_out_type);
2512 update_aamix_paths(codec, val, spec->hp_paths[0],
2513 spec->aamix_out_paths[1],
2515 update_aamix_paths(codec, val, spec->speaker_paths[0],
2516 spec->aamix_out_paths[2],
2519 update_output_paths(codec, cfg->line_outs, spec->out_paths);
2520 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
2521 update_output_paths(codec, cfg->hp_outs, spec->hp_paths);
2522 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
2523 update_output_paths(codec, cfg->speaker_outs,
2524 spec->speaker_paths);
2537 static int create_loopback_mixing_ctl(struct hda_codec *codec)
2539 struct hda_gen_spec *spec = codec->spec;
2541 if (!spec->mixer_nid)
2544 return -ENOMEM;
2545 spec->have_aamix_ctl = 1;
2553 static void call_update_outputs(struct hda_codec *codec);
2555 /* for shared I/O, change the pin-control accordingly */
2556 static void update_hp_mic(struct hda_codec *codec, int adc_mux, bool force)
2558 struct hda_gen_spec *spec = codec->spec;
2563 pin = spec->hp_mic_pin;
2564 as_mic = spec->cur_mux[adc_mux] == spec->hp_mic_mux_idx;
2567 val = snd_hda_codec_get_pin_target(codec, pin);
2577 val = snd_hda_get_default_vref(codec, pin);
2578 /* if the HP pin doesn't support VREF and the codec driver gives an
2581 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
2582 const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
2583 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
2585 snd_hda_set_pin_ctl_cache(codec, vref_pin,
2589 if (!spec->hp_mic_jack_modes) {
2594 set_pin_target(codec, pin, val, true);
2595 call_hp_automute(codec, NULL);
2600 static int create_hp_mic(struct hda_codec *codec)
2602 struct hda_gen_spec *spec = codec->spec;
2603 struct auto_pin_cfg *cfg = &spec->autocfg;
2607 if (!spec->hp_mic) {
2608 if (spec->suppress_hp_mic_detect)
2613 if (cfg->num_inputs > 1)
2615 else if (cfg->num_inputs == 1) {
2616 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2622 spec->hp_mic = 0; /* clear once */
2623 if (cfg->num_inputs >= AUTO_CFG_MAX_INS)
2627 if (cfg->line_out_type == AUTO_PIN_HP_OUT && cfg->line_outs > 0)
2628 nid = cfg->line_out_pins[0];
2629 else if (cfg->hp_outs > 0)
2630 nid = cfg->hp_pins[0];
2634 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2637 cfg->inputs[cfg->num_inputs].pin = nid;
2638 cfg->inputs[cfg->num_inputs].type = AUTO_PIN_MIC;
2639 cfg->inputs[cfg->num_inputs].is_headphone_mic = 1;
2640 cfg->num_inputs++;
2641 spec->hp_mic = 1;
2642 spec->hp_mic_pin = nid;
2643 /* we can't handle auto-mic together with HP-mic */
2644 spec->suppress_auto_mic = 1;
2645 codec_dbg(codec, "Enable shared I/O jack on NID 0x%x\n", nid);
2653 static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin);
2662 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, out_jack_texts);
2668 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2669 hda_nid_t nid = kcontrol->private_value;
2670 if (snd_hda_codec_get_pin_target(codec, nid) == PIN_HP)
2671 ucontrol->value.enumerated.item[0] = 1;
2673 ucontrol->value.enumerated.item[0] = 0;
2680 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2681 hda_nid_t nid = kcontrol->private_value;
2684 val = ucontrol->value.enumerated.item[0] ? PIN_HP : PIN_OUT;
2685 if (snd_hda_codec_get_pin_target(codec, nid) == val)
2687 snd_hda_set_pin_ctl_cache(codec, nid, val);
2698 static bool find_kctl_name(struct hda_codec *codec, const char *name, int idx)
2700 struct hda_gen_spec *spec = codec->spec;
2704 snd_array_for_each(&spec->kctls, i, kctl) {
2705 if (!strcmp(kctl->name, name) && kctl->index == idx)
2711 static void get_jack_mode_name(struct hda_codec *codec, hda_nid_t pin,
2714 struct hda_gen_spec *spec = codec->spec;
2717 snd_hda_get_pin_label(codec, pin, &spec->autocfg, name, name_len, &idx);
2720 for (; find_kctl_name(codec, name, idx); idx++)
2724 static int get_out_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2726 struct hda_gen_spec *spec = codec->spec;
2727 if (spec->add_jack_modes) {
2728 unsigned int pincap = snd_hda_query_pin_caps(codec, pin);
2730 return 2;
2735 static int create_out_jack_modes(struct hda_codec *codec, int num_pins,
2738 struct hda_gen_spec *spec = codec->spec;
2743 if (pin == spec->hp_mic_pin)
2745 if (get_out_jack_num_items(codec, pin) > 1) {
2748 get_jack_mode_name(codec, pin, name, sizeof(name));
2752 return -ENOMEM;
2753 knew->private_value = pin;
2772 static unsigned int get_vref_caps(struct hda_codec *codec, hda_nid_t pin)
2776 pincap = snd_hda_query_pin_caps(codec, pin);
2815 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2816 hda_nid_t nid = kcontrol->private_value;
2817 unsigned int vref_caps = get_vref_caps(codec, nid);
2822 strscpy(uinfo->value.enumerated.name,
2823 vref_texts[get_vref_idx(vref_caps, uinfo->value.enumerated.item)]);
2830 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2831 hda_nid_t nid = kcontrol->private_value;
2832 unsigned int vref_caps = get_vref_caps(codec, nid);
2835 idx = snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_VREFEN;
2836 ucontrol->value.enumerated.item[0] = cvt_from_vref_idx(vref_caps, idx);
2843 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2844 hda_nid_t nid = kcontrol->private_value;
2845 unsigned int vref_caps = get_vref_caps(codec, nid);
2848 val = snd_hda_codec_get_pin_target(codec, nid);
2850 if (idx == ucontrol->value.enumerated.item[0])
2854 val |= get_vref_idx(vref_caps, ucontrol->value.enumerated.item[0]);
2855 snd_hda_set_pin_ctl_cache(codec, nid, val);
2866 static int get_in_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2868 struct hda_gen_spec *spec = codec->spec;
2870 if (spec->add_jack_modes)
2871 nitems = hweight32(get_vref_caps(codec, pin));
2875 static int create_in_jack_mode(struct hda_codec *codec, hda_nid_t pin)
2877 struct hda_gen_spec *spec = codec->spec;
2882 if (pin == spec->hp_mic_pin)
2886 defcfg = snd_hda_codec_get_pincfg(codec, pin);
2891 if (get_in_jack_num_items(codec, pin) <= 1)
2894 get_jack_mode_name(codec, pin, name, sizeof(name));
2897 return -ENOMEM;
2898 knew->private_value = pin;
2908 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2909 hda_nid_t nid = kcontrol->private_value;
2910 int out_jacks = get_out_jack_num_items(codec, nid);
2911 int in_jacks = get_in_jack_num_items(codec, nid);
2915 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2916 uinfo->count = 1;
2917 uinfo->value.enumerated.items = out_jacks + in_jacks;
2918 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2919 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2920 idx = uinfo->value.enumerated.item;
2927 idx -= out_jacks;
2929 unsigned int vref_caps = get_vref_caps(codec, nid);
2935 strscpy(uinfo->value.enumerated.name, text);
2939 static int get_cur_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t nid)
2941 int out_jacks = get_out_jack_num_items(codec, nid);
2942 int in_jacks = get_in_jack_num_items(codec, nid);
2943 unsigned int val = snd_hda_codec_get_pin_target(codec, nid);
2952 unsigned int vref_caps = get_vref_caps(codec, nid);
2963 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2964 hda_nid_t nid = kcontrol->private_value;
2965 ucontrol->value.enumerated.item[0] =
2966 get_cur_hp_mic_jack_mode(codec, nid);
2973 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2974 hda_nid_t nid = kcontrol->private_value;
2975 int out_jacks = get_out_jack_num_items(codec, nid);
2976 int in_jacks = get_in_jack_num_items(codec, nid);
2979 oldval = get_cur_hp_mic_jack_mode(codec, nid);
2980 idx = ucontrol->value.enumerated.item[0];
2990 idx -= out_jacks;
2992 unsigned int vref_caps = get_vref_caps(codec, nid);
2993 val = snd_hda_codec_get_pin_target(codec, nid);
2997 val = snd_hda_get_default_vref(codec, nid) | PIN_IN;
2999 snd_hda_set_pin_ctl_cache(codec, nid, val);
3000 call_hp_automute(codec, NULL);
3012 static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin)
3014 struct hda_gen_spec *spec = codec->spec;
3020 return -ENOMEM;
3021 knew->private_value = pin;
3022 spec->hp_mic_jack_modes = 1;
3030 /* add the powersave loopback-list entry */
3035 list = snd_array_new(&spec->loopback_list);
3037 return -ENOMEM;
3038 list->nid = mix;
3039 list->dir = HDA_INPUT;
3040 list->idx = idx;
3041 spec->loopback.amplist = spec->loopback_list.list;
3048 static bool look_for_mix_leaf_ctls(struct hda_codec *codec, hda_nid_t mix_nid,
3056 idx = snd_hda_get_conn_index(codec, mix_nid, pin, true);
3061 if (nid_has_volume(codec, mix_nid, HDA_INPUT))
3063 if (nid_has_mute(codec, mix_nid, HDA_INPUT))
3069 num_conns = snd_hda_get_conn_list(codec, mix_nid, &list);
3073 if (!*mix_val && nid_has_volume(codec, nid, HDA_OUTPUT) &&
3074 !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_VOL_CTL))
3076 if (!*mute_val && nid_has_mute(codec, nid, HDA_OUTPUT) &&
3077 !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_MUTE_CTL))
3084 static int new_analog_input(struct hda_codec *codec, int input_idx,
3088 struct hda_gen_spec *spec = codec->spec;
3093 if (!look_for_mix_leaf_ctls(codec, mix_nid, pin, &mix_val, &mute_val))
3096 path = snd_hda_add_new_path(codec, pin, mix_nid, 0);
3098 return -EINVAL;
3099 print_nid_path(codec, "loopback", path);
3100 spec->loopback_paths[input_idx] = snd_hda_get_path_idx(codec, path);
3102 idx = path->idx[path->depth - 1];
3107 path->ctls[NID_PATH_VOL_CTL] = mix_val;
3114 path->ctls[NID_PATH_MUTE_CTL] = mute_val;
3117 path->active = true;
3118 path->stream_enabled = true; /* no DAC/ADC involved */
3123 if (spec->mixer_nid != spec->mixer_merge_nid &&
3124 !spec->loopback_merge_path) {
3125 path = snd_hda_add_new_path(codec, spec->mixer_nid,
3126 spec->mixer_merge_nid, 0);
3128 print_nid_path(codec, "loopback-merge", path);
3129 path->active = true;
3130 path->pin_fixed = true; /* static route */
3131 path->stream_enabled = true; /* no DAC/ADC involved */
3132 spec->loopback_merge_path =
3133 snd_hda_get_path_idx(codec, path);
3140 static int is_input_pin(struct hda_codec *codec, hda_nid_t nid)
3142 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
3146 /* Parse the codec tree and retrieve ADCs */
3147 static int fill_adc_nids(struct hda_codec *codec)
3149 struct hda_gen_spec *spec = codec->spec;
3151 hda_nid_t *adc_nids = spec->adc_nids;
3152 int max_nums = ARRAY_SIZE(spec->adc_nids);
3155 for_each_hda_codec_node(nid, codec) {
3156 unsigned int caps = get_wcaps(codec, nid);
3165 spec->num_adc_nids = nums;
3168 spec->num_all_adcs = nums;
3169 memcpy(spec->all_adcs, spec->adc_nids, nums * sizeof(hda_nid_t));
3175 * if needed, check whether dynamic ADC-switching is available
3177 static int check_dyn_adc_switch(struct hda_codec *codec)
3179 struct hda_gen_spec *spec = codec->spec;
3180 struct hda_input_mux *imux = &spec->input_mux;
3186 for (n = 0; n < spec->num_adc_nids; n++) {
3187 for (i = 0; i < imux->num_items; i++) {
3188 if (!spec->input_paths[i][n])
3191 if (i >= imux->num_items) {
3198 /* check whether ADC-switch is possible */
3199 for (i = 0; i < imux->num_items; i++) {
3200 for (n = 0; n < spec->num_adc_nids; n++) {
3201 if (spec->input_paths[i][n]) {
3202 spec->dyn_adc_idx[i] = n;
3208 codec_dbg(codec, "enabling ADC switching\n");
3209 spec->dyn_adc_switch = 1;
3210 } else if (nums != spec->num_adc_nids) {
3213 for (n = 0; n < spec->num_adc_nids; n++) {
3217 spec->adc_nids[nums] = spec->adc_nids[n];
3218 for (i = 0; i < imux->num_items; i++) {
3219 invalidate_nid_path(codec,
3220 spec->input_paths[i][nums]);
3221 spec->input_paths[i][nums] =
3222 spec->input_paths[i][n];
3223 spec->input_paths[i][n] = 0;
3228 spec->num_adc_nids = nums;
3231 if (imux->num_items == 1 ||
3232 (imux->num_items == 2 && spec->hp_mic)) {
3233 codec_dbg(codec, "reducing to a single ADC\n");
3234 spec->num_adc_nids = 1; /* reduce to a single ADC */
3238 if (!spec->dyn_adc_switch && spec->multi_cap_vol)
3239 spec->num_adc_nids = 1;
3245 static int parse_capture_source(struct hda_codec *codec, hda_nid_t pin,
3249 struct hda_gen_spec *spec = codec->spec;
3250 struct hda_input_mux *imux = &spec->input_mux;
3251 int imux_idx = imux->num_items;
3257 hda_nid_t adc = spec->adc_nids[c];
3259 if (!is_reachable_path(codec, pin, adc))
3261 path = snd_hda_add_new_path(codec, pin, adc, anchor);
3264 print_nid_path(codec, "input", path);
3265 spec->input_paths[imux_idx][c] =
3266 snd_hda_get_path_idx(codec, path);
3269 if (spec->hp_mic_pin == pin)
3270 spec->hp_mic_mux_idx = imux->num_items;
3271 spec->imux_pins[imux->num_items] = pin;
3272 snd_hda_add_imux_item(codec, imux, label, cfg_idx, NULL);
3274 if (spec->dyn_adc_switch)
3275 spec->dyn_adc_idx[imux_idx] = c;
3287 static int fill_input_pin_labels(struct hda_codec *codec)
3289 struct hda_gen_spec *spec = codec->spec;
3290 const struct auto_pin_cfg *cfg = &spec->autocfg;
3293 for (i = 0; i < cfg->num_inputs; i++) {
3294 hda_nid_t pin = cfg->inputs[i].pin;
3298 if (!is_input_pin(codec, pin))
3301 label = hda_get_autocfg_input_label(codec, cfg, i);
3303 for (j = i - 1; j >= 0; j--) {
3304 if (spec->input_labels[j] &&
3305 !strcmp(spec->input_labels[j], label)) {
3306 idx = spec->input_label_idxs[j] + 1;
3311 spec->input_labels[i] = label;
3312 spec->input_label_idxs[i] = idx;
3318 #define CFG_IDX_MIX 99 /* a dummy cfg->input idx for stereo mix */
3320 static int create_input_ctls(struct hda_codec *codec)
3322 struct hda_gen_spec *spec = codec->spec;
3323 const struct auto_pin_cfg *cfg = &spec->autocfg;
3324 hda_nid_t mixer = spec->mixer_nid;
3329 num_adcs = fill_adc_nids(codec);
3333 err = fill_input_pin_labels(codec);
3337 for (i = 0; i < cfg->num_inputs; i++) {
3340 pin = cfg->inputs[i].pin;
3341 if (!is_input_pin(codec, pin))
3345 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3346 val |= snd_hda_get_default_vref(codec, pin);
3347 if (pin != spec->hp_mic_pin &&
3348 !snd_hda_codec_get_pin_target(codec, pin))
3349 set_pin_target(codec, pin, val, false);
3352 if (is_reachable_path(codec, pin, mixer)) {
3353 err = new_analog_input(codec, i, pin,
3354 spec->input_labels[i],
3355 spec->input_label_idxs[i],
3362 err = parse_capture_source(codec, pin, i, num_adcs,
3363 spec->input_labels[i], -mixer);
3367 if (spec->add_jack_modes) {
3368 err = create_in_jack_mode(codec, pin);
3375 if (mixer && spec->add_stereo_mix_input == HDA_HINT_STEREO_MIX_ENABLE) {
3376 err = parse_capture_source(codec, mixer, CFG_IDX_MIX, num_adcs,
3381 spec->suppress_auto_mic = 1;
3393 static struct nid_path *get_input_path(struct hda_codec *codec, int adc_idx, int imux_idx)
3395 struct hda_gen_spec *spec = codec->spec;
3400 if (spec->dyn_adc_switch)
3401 adc_idx = spec->dyn_adc_idx[imux_idx];
3406 return snd_hda_get_path_from_idx(codec, spec->input_paths[imux_idx][adc_idx]);
3409 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3415 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3416 struct hda_gen_spec *spec = codec->spec;
3417 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
3423 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3424 struct hda_gen_spec *spec = codec->spec;
3426 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
3428 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
3435 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3436 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
3437 return mux_select(codec, adc_idx,
3438 ucontrol->value.enumerated.item[0]);
3461 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3462 struct hda_gen_spec *spec = codec->spec;
3467 imux = &spec->input_mux;
3468 adc_idx = kcontrol->id.index;
3469 scoped_guard(mutex, &codec->control_mutex) {
3470 for (i = 0; i < imux->num_items; i++) {
3471 path = get_input_path(codec, adc_idx, i);
3472 if (!path || !path->ctls[type])
3474 kcontrol->private_value = path->ctls[type];
3482 if (spec->cap_sync_hook)
3483 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3533 static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
3538 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
3540 if (depth >= path->depth)
3541 return -EINVAL;
3542 i = path->depth - depth - 1;
3543 nid = path->path[i];
3544 if (!path->ctls[NID_PATH_VOL_CTL]) {
3545 if (nid_has_volume(codec, nid, HDA_OUTPUT))
3546 path->ctls[NID_PATH_VOL_CTL] =
3548 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
3549 int idx = path->idx[i];
3550 if (!depth && codec->single_adc_amp)
3552 path->ctls[NID_PATH_VOL_CTL] =
3556 if (!path->ctls[NID_PATH_MUTE_CTL]) {
3557 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3558 path->ctls[NID_PATH_MUTE_CTL] =
3560 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
3561 int idx = path->idx[i];
3562 if (!depth && codec->single_adc_amp)
3564 path->ctls[NID_PATH_MUTE_CTL] =
3572 static bool is_inv_dmic_pin(struct hda_codec *codec, hda_nid_t nid)
3574 struct hda_gen_spec *spec = codec->spec;
3575 struct auto_pin_cfg *cfg = &spec->autocfg;
3579 if (!spec->inv_dmic_split)
3581 for (i = 0; i < cfg->num_inputs; i++) {
3582 if (cfg->inputs[i].pin != nid)
3584 if (cfg->inputs[i].type != AUTO_PIN_MIC)
3586 val = snd_hda_codec_get_pincfg(codec, nid);
3596 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3597 struct hda_gen_spec *spec = codec->spec;
3604 if (spec->cap_sync_hook)
3605 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3610 static int add_single_cap_ctl(struct hda_codec *codec, const char *label,
3614 struct hda_gen_spec *spec = codec->spec;
3633 return -ENOMEM;
3635 knew->put = cap_single_sw_put;
3636 if (spec->mic_mute_led)
3637 knew->access |= SNDRV_CTL_ELEM_ACCESS_MIC_LED;
3650 amp_val_replace_channels(ctl, 2));
3652 return -ENOMEM;
3654 knew->put = cap_single_sw_put;
3655 if (spec->mic_mute_led)
3656 knew->access |= SNDRV_CTL_ELEM_ACCESS_MIC_LED;
3662 static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx,
3667 err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl, inv_dmic);
3670 err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl, inv_dmic);
3677 static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx,
3680 struct hda_gen_spec *spec = codec->spec;
3686 return -ENOMEM;
3687 knew->index = idx;
3688 knew->private_value = vol_ctl;
3689 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
3694 return -ENOMEM;
3695 knew->index = idx;
3696 knew->private_value = sw_ctl;
3697 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
3698 if (spec->mic_mute_led)
3699 knew->access |= SNDRV_CTL_ELEM_ACCESS_MIC_LED;
3705 static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type)
3711 path = get_input_path(codec, 0, idx);
3714 ctl = path->ctls[type];
3717 for (i = 0; i < idx - 1; i++) {
3718 path = get_input_path(codec, 0, i);
3719 if (path && path->ctls[type] == ctl)
3726 static int create_multi_cap_vol_ctl(struct hda_codec *codec)
3728 struct hda_gen_spec *spec = codec->spec;
3729 struct hda_input_mux *imux = &spec->input_mux;
3732 for (i = 0; i < imux->num_items; i++) {
3736 idx = imux->items[i].index;
3737 if (idx >= spec->autocfg.num_inputs)
3739 inv_dmic = is_inv_dmic_pin(codec, spec->imux_pins[i]);
3741 for (type = 0; type < 2; type++) {
3742 err = add_single_cap_ctl(codec,
3743 spec->input_labels[idx],
3744 spec->input_label_idxs[idx],
3746 get_first_cap_ctl(codec, i, type),
3755 static int create_capture_mixers(struct hda_codec *codec)
3757 struct hda_gen_spec *spec = codec->spec;
3758 struct hda_input_mux *imux = &spec->input_mux;
3761 if (spec->dyn_adc_switch)
3764 nums = spec->num_adc_nids;
3766 if (!spec->auto_mic && imux->num_items > 1) {
3772 return -ENOMEM;
3773 knew->count = nums;
3778 bool multi_cap_vol = spec->multi_cap_vol;
3783 for (i = 0; i < imux->num_items; i++) {
3785 path = get_input_path(codec, n, i);
3788 parse_capvol_in_path(codec, path);
3790 vol = path->ctls[NID_PATH_VOL_CTL];
3791 else if (vol != path->ctls[NID_PATH_VOL_CTL]) {
3793 if (!same_amp_caps(codec, vol,
3794 path->ctls[NID_PATH_VOL_CTL], HDA_INPUT))
3798 sw = path->ctls[NID_PATH_MUTE_CTL];
3799 else if (sw != path->ctls[NID_PATH_MUTE_CTL]) {
3801 if (!same_amp_caps(codec, sw,
3802 path->ctls[NID_PATH_MUTE_CTL], HDA_INPUT))
3805 if (is_inv_dmic_pin(codec, spec->imux_pins[i]))
3810 err = create_single_cap_vol_ctl(codec, n, vol, sw,
3813 err = create_bind_cap_vol_ctl(codec, n, vol, sw);
3815 err = create_multi_cap_vol_ctl(codec);
3828 static bool check_boost_vol(struct hda_codec *codec, hda_nid_t nid,
3833 if (!nid_has_volume(codec, nid, dir) ||
3834 is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
3835 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
3838 step = (query_amp_caps(codec, nid, dir) & AC_AMPCAP_STEP_SIZE)
3846 static unsigned int look_for_boost_amp(struct hda_codec *codec,
3854 if (depth >= path->depth - 1)
3856 nid = path->path[depth];
3857 if (depth && check_boost_vol(codec, nid, HDA_OUTPUT, 0)) {
3860 } else if (check_boost_vol(codec, nid, HDA_INPUT,
3861 path->idx[depth])) {
3862 val = HDA_COMPOSE_AMP_VAL(nid, 3, path->idx[depth],
3871 static int parse_mic_boost(struct hda_codec *codec)
3873 struct hda_gen_spec *spec = codec->spec;
3874 struct auto_pin_cfg *cfg = &spec->autocfg;
3875 struct hda_input_mux *imux = &spec->input_mux;
3878 if (!spec->num_adc_nids)
3881 for (i = 0; i < imux->num_items; i++) {
3887 idx = imux->items[i].index;
3888 if (idx >= imux->num_items)
3891 /* check only line-in and mic pins */
3892 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
3895 path = get_input_path(codec, 0, i);
3899 val = look_for_boost_amp(codec, path);
3905 "%s Boost Volume", spec->input_labels[idx]);
3907 spec->input_label_idxs[idx], val))
3908 return -ENOMEM;
3910 path->ctls[NID_PATH_BOOST_CTL] = val;
3920 static int create_mute_led_cdev(struct hda_codec *codec,
3925 struct hda_gen_spec *spec = codec->spec;
3930 cdev = devm_kzalloc(&codec->core.dev, sizeof(*cdev), GFP_KERNEL);
3932 return -ENOMEM;
3934 cdev->name = micmute ? "hda::micmute" : "hda::mute";
3935 cdev->max_brightness = 1;
3936 cdev->default_trigger = micmute ? "audio-micmute" : "audio-mute";
3937 cdev->brightness_set_blocking = callback;
3938 cdev->flags = LED_CORE_SUSPENDRESUME;
3940 err = led_classdev_register(&codec->core.dev, cdev);
3943 spec->led_cdevs[idx] = cdev;
3948 * snd_hda_gen_add_mute_led_cdev - Create a LED classdev and enable as vmaster mute LED
3949 * @codec: the HDA codec
3952 int snd_hda_gen_add_mute_led_cdev(struct hda_codec *codec,
3956 struct hda_gen_spec *spec = codec->spec;
3960 err = create_mute_led_cdev(codec, callback, false);
3962 codec_warn(codec, "failed to create a mute LED cdev\n");
3967 if (spec->vmaster_mute.hook)
3968 codec_err(codec, "vmaster hook already present before cdev!\n");
3970 spec->vmaster_mute_led = 1;
3976 * snd_hda_gen_add_micmute_led_cdev - Create a LED classdev and enable as mic-mute LED
3977 * @codec: the HDA codec
3980 * Called from the codec drivers for offering the mic mute LED controls.
3985 * LED-trigger is set up.
3989 int snd_hda_gen_add_micmute_led_cdev(struct hda_codec *codec,
3993 struct hda_gen_spec *spec = codec->spec;
3997 err = create_mute_led_cdev(codec, callback, true);
3999 codec_warn(codec, "failed to create a mic-mute LED cdev\n");
4004 spec->mic_mute_led = 1;
4011 * parse digital I/Os and set up NIDs in BIOS auto-parse mode
4013 static void parse_digital(struct hda_codec *codec)
4015 struct hda_gen_spec *spec = codec->spec;
4022 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4023 pin = spec->autocfg.dig_out_pins[i];
4024 dig_nid = look_for_dac(codec, pin, true);
4027 path = snd_hda_add_new_path(codec, dig_nid, pin, 0);
4030 print_nid_path(codec, "digout", path);
4031 path->active = true;
4032 path->pin_fixed = true; /* no jack detection */
4033 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
4034 set_pin_target(codec, pin, PIN_OUT, false);
4036 spec->multiout.dig_out_nid = dig_nid;
4037 spec->dig_out_type = spec->autocfg.dig_out_type[0];
4039 spec->multiout.follower_dig_outs = spec->follower_dig_outs;
4040 if (nums >= ARRAY_SIZE(spec->follower_dig_outs) - 1)
4042 spec->follower_dig_outs[nums - 1] = dig_nid;
4047 if (spec->autocfg.dig_in_pin) {
4048 pin = spec->autocfg.dig_in_pin;
4049 for_each_hda_codec_node(dig_nid, codec) {
4050 unsigned int wcaps = get_wcaps(codec, dig_nid);
4055 path = snd_hda_add_new_path(codec, pin, dig_nid, 0);
4057 print_nid_path(codec, "digin", path);
4058 path->active = true;
4059 path->pin_fixed = true; /* no jack */
4060 spec->dig_in_nid = dig_nid;
4061 spec->digin_path = snd_hda_get_path_idx(codec, path);
4062 set_pin_target(codec, pin, PIN_IN, false);
4074 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur);
4077 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
4080 struct hda_gen_spec *spec = codec->spec;
4084 imux = &spec->input_mux;
4085 if (!imux->num_items)
4088 if (idx >= imux->num_items)
4089 idx = imux->num_items - 1;
4090 if (spec->cur_mux[adc_idx] == idx)
4093 old_path = get_input_path(codec, adc_idx, spec->cur_mux[adc_idx]);
4096 if (old_path->active)
4097 snd_hda_activate_path(codec, old_path, false, false);
4099 spec->cur_mux[adc_idx] = idx;
4101 if (spec->hp_mic)
4102 update_hp_mic(codec, adc_idx, false);
4104 if (spec->dyn_adc_switch)
4105 dyn_adc_pcm_resetup(codec, idx);
4107 path = get_input_path(codec, adc_idx, idx);
4110 if (path->active)
4112 snd_hda_activate_path(codec, path, true, false);
4113 if (spec->cap_sync_hook)
4114 spec->cap_sync_hook(codec, NULL, NULL);
4115 path_power_down_sync(codec, old_path);
4120 * as terminals (either start- or endpoint)
4124 static hda_nid_t set_path_power(struct hda_codec *codec, hda_nid_t nid,
4127 struct hda_gen_spec *spec = codec->spec;
4132 snd_array_for_each(&spec->paths, n, path) {
4133 if (!path->depth)
4135 if (path->path[0] == nid ||
4136 path->path[path->depth - 1] == nid) {
4137 bool pin_old = path->pin_enabled;
4138 bool stream_old = path->stream_enabled;
4141 path->pin_enabled = pin_state;
4143 path->stream_enabled = stream_state;
4144 if ((!path->pin_fixed && path->pin_enabled != pin_old)
4145 || path->stream_enabled != stream_old) {
4146 last = path_power_update(codec, path, true);
4156 static bool detect_pin_state(struct hda_codec *codec, hda_nid_t pin)
4158 if (!is_jack_detectable(codec, pin))
4160 return snd_hda_jack_detect_state(codec, pin) != HDA_JACK_NOT_PRESENT;
4169 static hda_nid_t set_pin_power_jack(struct hda_codec *codec, hda_nid_t pin,
4174 if (!codec->power_save_node)
4177 on = detect_pin_state(codec, pin);
4181 return set_path_power(codec, pin, on, -1);
4184 static void pin_power_callback(struct hda_codec *codec,
4188 if (jack && jack->nid)
4189 sync_power_state_change(codec,
4190 set_pin_power_jack(codec, jack->nid, on));
4193 /* callback only doing power up -- called at first */
4194 static void pin_power_up_callback(struct hda_codec *codec,
4197 pin_power_callback(codec, jack, true);
4200 /* callback only doing power down -- called at last */
4201 static void pin_power_down_callback(struct hda_codec *codec,
4204 pin_power_callback(codec, jack, false);
4208 static void add_pin_power_ctls(struct hda_codec *codec, int num_pins,
4216 if (is_jack_detectable(codec, pins[i]))
4217 snd_hda_jack_detect_enable_callback(codec, pins[i], cb);
4219 set_path_power(codec, pins[i], true, -1);
4226 static void add_all_pin_power_ctls(struct hda_codec *codec, bool on)
4228 struct hda_gen_spec *spec = codec->spec;
4229 struct auto_pin_cfg *cfg = &spec->autocfg;
4232 if (!codec->power_save_node)
4234 add_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins, on);
4235 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
4236 add_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins, on);
4237 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
4238 add_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins, on);
4239 for (i = 0; i < cfg->num_inputs; i++)
4240 add_pin_power_ctls(codec, 1, &cfg->inputs[i].pin, on);
4244 static void sync_pin_power_ctls(struct hda_codec *codec, int num_pins,
4250 if (is_jack_detectable(codec, pins[i]))
4251 set_pin_power_jack(codec, pins[i], -1);
4255 static void sync_all_pin_power_ctls(struct hda_codec *codec)
4257 struct hda_gen_spec *spec = codec->spec;
4258 struct auto_pin_cfg *cfg = &spec->autocfg;
4261 if (!codec->power_save_node)
4263 sync_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins);
4264 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
4265 sync_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins);
4266 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
4267 sync_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins);
4268 for (i = 0; i < cfg->num_inputs; i++)
4269 sync_pin_power_ctls(codec, 1, &cfg->inputs[i].pin);
4273 static int add_fake_paths(struct hda_codec *codec, hda_nid_t nid,
4276 struct hda_gen_spec *spec = codec->spec;
4283 if (get_nid_path(codec, nid, pins[i], 0))
4285 path = snd_array_new(&spec->paths);
4287 return -ENOMEM;
4289 path->depth = 2;
4290 path->path[0] = nid;
4291 path->path[1] = pins[i];
4292 path->active = true;
4298 static int add_fake_beep_paths(struct hda_codec *codec)
4300 struct hda_gen_spec *spec = codec->spec;
4301 struct auto_pin_cfg *cfg = &spec->autocfg;
4302 hda_nid_t nid = spec->beep_nid;
4305 if (!codec->power_save_node || !nid)
4307 err = add_fake_paths(codec, nid, cfg->line_outs, cfg->line_out_pins);
4310 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
4311 err = add_fake_paths(codec, nid, cfg->hp_outs, cfg->hp_pins);
4315 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
4316 err = add_fake_paths(codec, nid, cfg->speaker_outs,
4317 cfg->speaker_pins);
4327 set_path_power(beep->codec, beep->nid, -1, on);
4331 * snd_hda_gen_fix_pin_power - Fix the power of the given pin widget to D0
4332 * @codec: the HDA codec
4335 int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin)
4337 struct hda_gen_spec *spec = codec->spec;
4340 path = snd_array_new(&spec->paths);
4342 return -ENOMEM;
4344 path->depth = 1;
4345 path->path[0] = pin;
4346 path->active = true;
4347 path->pin_fixed = true;
4348 path->stream_enabled = true;
4354 * Jack detections for HP auto-mute and mic-switch
4358 static bool detect_jacks(struct hda_codec *codec, int num_pins, const hda_nid_t *pins)
4368 if (snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_IN_EN)
4370 if (snd_hda_jack_detect_state(codec, nid) == HDA_JACK_PRESENT)
4376 /* standard HP/line-out auto-mute helper */
4377 static void do_automute(struct hda_codec *codec, int num_pins, const hda_nid_t *pins,
4380 struct hda_gen_spec *spec = codec->spec;
4389 oldval = snd_hda_codec_get_pin_target(codec, nid);
4393 if (spec->auto_mute_via_amp) {
4397 path = snd_hda_get_path_from_idx(codec, paths[i]);
4400 mute_nid = get_amp_nid_(path->ctls[NID_PATH_MUTE_CTL]);
4404 spec->mute_bits |= (1ULL << mute_nid);
4406 spec->mute_bits &= ~(1ULL << mute_nid);
4412 if (spec->keep_vref_in_automute)
4423 update_pin_ctl(codec, nid, val);
4426 set_pin_eapd(codec, nid, !mute);
4427 if (codec->power_save_node) {
4430 on = detect_pin_state(codec, nid);
4431 set_path_power(codec, nid, on, -1);
4437 * snd_hda_gen_update_outputs - Toggle outputs muting
4438 * @codec: the HDA codec
4442 void snd_hda_gen_update_outputs(struct hda_codec *codec)
4444 struct hda_gen_spec *spec = codec->spec;
4452 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
4453 paths = spec->out_paths;
4455 paths = spec->hp_paths;
4456 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
4457 spec->autocfg.hp_pins, paths, spec->master_mute);
4459 if (!spec->automute_speaker)
4462 on = spec->hp_jack_present | spec->line_jack_present;
4463 on |= spec->master_mute;
4464 spec->speaker_muted = on;
4465 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4466 paths = spec->out_paths;
4468 paths = spec->speaker_paths;
4469 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
4470 spec->autocfg.speaker_pins, paths, on);
4472 /* toggle line-out mutes if needed, too */
4474 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
4475 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
4477 if (!spec->automute_lo)
4480 on = spec->hp_jack_present;
4481 on |= spec->master_mute;
4482 spec->line_out_muted = on;
4483 paths = spec->out_paths;
4484 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
4485 spec->autocfg.line_out_pins, paths, on);
4489 static void call_update_outputs(struct hda_codec *codec)
4491 struct hda_gen_spec *spec = codec->spec;
4492 if (spec->automute_hook)
4493 spec->automute_hook(codec);
4495 snd_hda_gen_update_outputs(codec);
4497 /* sync the whole vmaster followers to reflect the new auto-mute status */
4498 if (spec->auto_mute_via_amp && !codec->bus->shutdown)
4499 snd_ctl_sync_vmaster(spec->vmaster_mute.sw_kctl, false);
4503 * snd_hda_gen_hp_automute - standard HP-automute helper
4504 * @codec: the HDA codec
4507 void snd_hda_gen_hp_automute(struct hda_codec *codec,
4510 struct hda_gen_spec *spec = codec->spec;
4511 hda_nid_t *pins = spec->autocfg.hp_pins;
4512 int num_pins = ARRAY_SIZE(spec->autocfg.hp_pins);
4514 /* No detection for the first HP jack during indep-HP mode */
4515 if (spec->indep_hp_enabled) {
4517 num_pins--;
4520 spec->hp_jack_present = detect_jacks(codec, num_pins, pins);
4521 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
4523 call_update_outputs(codec);
4528 * snd_hda_gen_line_automute - standard line-out-automute helper
4529 * @codec: the HDA codec
4532 void snd_hda_gen_line_automute(struct hda_codec *codec,
4535 struct hda_gen_spec *spec = codec->spec;
4537 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4540 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
4543 spec->line_jack_present =
4544 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
4545 spec->autocfg.line_out_pins);
4546 if (!spec->automute_speaker || !spec->detect_lo)
4548 call_update_outputs(codec);
4553 * snd_hda_gen_mic_autoswitch - standard mic auto-switch helper
4554 * @codec: the HDA codec
4557 void snd_hda_gen_mic_autoswitch(struct hda_codec *codec,
4560 struct hda_gen_spec *spec = codec->spec;
4563 if (!spec->auto_mic)
4566 for (i = spec->am_num_entries - 1; i > 0; i--) {
4567 hda_nid_t pin = spec->am_entry[i].pin;
4569 if (snd_hda_codec_get_pin_target(codec, pin) & AC_PINCTL_OUT_EN)
4571 if (snd_hda_jack_detect_state(codec, pin) == HDA_JACK_PRESENT) {
4572 mux_select(codec, 0, spec->am_entry[i].idx);
4576 mux_select(codec, 0, spec->am_entry[0].idx);
4581 static void call_hp_automute(struct hda_codec *codec,
4584 struct hda_gen_spec *spec = codec->spec;
4585 if (spec->hp_automute_hook)
4586 spec->hp_automute_hook(codec, jack);
4588 snd_hda_gen_hp_automute(codec, jack);
4591 static void call_line_automute(struct hda_codec *codec,
4594 struct hda_gen_spec *spec = codec->spec;
4595 if (spec->line_automute_hook)
4596 spec->line_automute_hook(codec, jack);
4598 snd_hda_gen_line_automute(codec, jack);
4601 static void call_mic_autoswitch(struct hda_codec *codec,
4604 struct hda_gen_spec *spec = codec->spec;
4605 if (spec->mic_autoswitch_hook)
4606 spec->mic_autoswitch_hook(codec, jack);
4608 snd_hda_gen_mic_autoswitch(codec, jack);
4612 static void update_automute_all(struct hda_codec *codec)
4614 call_hp_automute(codec, NULL);
4615 call_line_automute(codec, NULL);
4616 call_mic_autoswitch(codec, NULL);
4620 * Auto-Mute mode mixer enum support
4625 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4626 struct hda_gen_spec *spec = codec->spec;
4631 if (spec->automute_speaker_possible && spec->automute_lo_possible)
4639 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4640 struct hda_gen_spec *spec = codec->spec;
4642 if (spec->automute_speaker)
4644 if (spec->automute_lo)
4647 ucontrol->value.enumerated.item[0] = val;
4654 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4655 struct hda_gen_spec *spec = codec->spec;
4657 switch (ucontrol->value.enumerated.item[0]) {
4659 if (!spec->automute_speaker && !spec->automute_lo)
4661 spec->automute_speaker = 0;
4662 spec->automute_lo = 0;
4665 if (spec->automute_speaker_possible) {
4666 if (!spec->automute_lo && spec->automute_speaker)
4668 spec->automute_speaker = 1;
4669 spec->automute_lo = 0;
4670 } else if (spec->automute_lo_possible) {
4671 if (spec->automute_lo)
4673 spec->automute_lo = 1;
4675 return -EINVAL;
4677 case 2:
4678 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
4679 return -EINVAL;
4680 if (spec->automute_speaker && spec->automute_lo)
4682 spec->automute_speaker = 1;
4683 spec->automute_lo = 1;
4686 return -EINVAL;
4688 call_update_outputs(codec);
4694 .name = "Auto-Mute Mode",
4700 static int add_automute_mode_enum(struct hda_codec *codec)
4702 struct hda_gen_spec *spec = codec->spec;
4705 return -ENOMEM;
4710 * Check the availability of HP/line-out auto-mute;
4713 static int check_auto_mute_availability(struct hda_codec *codec)
4715 struct hda_gen_spec *spec = codec->spec;
4716 struct auto_pin_cfg *cfg = &spec->autocfg;
4720 if (spec->suppress_auto_mute)
4723 if (cfg->hp_pins[0])
4725 if (cfg->line_out_pins[0])
4727 if (cfg->speaker_pins[0])
4729 if (present < 2) /* need two different output types */
4732 if (!cfg->speaker_pins[0] &&
4733 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
4734 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4735 sizeof(cfg->speaker_pins));
4736 cfg->speaker_outs = cfg->line_outs;
4739 if (!cfg->hp_pins[0] &&
4740 cfg->line_out_type == AUTO_PIN_HP_OUT) {
4741 memcpy(cfg->hp_pins, cfg->line_out_pins,
4742 sizeof(cfg->hp_pins));
4743 cfg->hp_outs = cfg->line_outs;
4746 for (i = 0; i < cfg->hp_outs; i++) {
4747 hda_nid_t nid = cfg->hp_pins[i];
4748 if (!is_jack_detectable(codec, nid))
4750 codec_dbg(codec, "Enable HP auto-muting on NID 0x%x\n", nid);
4751 snd_hda_jack_detect_enable_callback(codec, nid,
4753 spec->detect_hp = 1;
4756 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
4757 if (cfg->speaker_outs)
4758 for (i = 0; i < cfg->line_outs; i++) {
4759 hda_nid_t nid = cfg->line_out_pins[i];
4760 if (!is_jack_detectable(codec, nid))
4762 codec_dbg(codec, "Enable Line-Out auto-muting on NID 0x%x\n", nid);
4763 snd_hda_jack_detect_enable_callback(codec, nid,
4765 spec->detect_lo = 1;
4767 spec->automute_lo_possible = spec->detect_hp;
4770 spec->automute_speaker_possible = cfg->speaker_outs &&
4771 (spec->detect_hp || spec->detect_lo);
4773 spec->automute_lo = spec->automute_lo_possible;
4774 spec->automute_speaker = spec->automute_speaker_possible;
4776 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
4778 err = add_automute_mode_enum(codec);
4785 /* check whether all auto-mic pins are valid; setup indices if OK */
4786 static bool auto_mic_check_imux(struct hda_codec *codec)
4788 struct hda_gen_spec *spec = codec->spec;
4792 imux = &spec->input_mux;
4793 for (i = 0; i < spec->am_num_entries; i++) {
4794 spec->am_entry[i].idx =
4795 find_idx_in_nid_list(spec->am_entry[i].pin,
4796 spec->imux_pins, imux->num_items);
4797 if (spec->am_entry[i].idx < 0)
4802 for (i = 1; i < spec->am_num_entries; i++)
4803 snd_hda_jack_detect_enable_callback(codec,
4804 spec->am_entry[i].pin,
4813 return (int)(a->attr - b->attr);
4817 * Check the availability of auto-mic switch;
4820 static int check_auto_mic_availability(struct hda_codec *codec)
4822 struct hda_gen_spec *spec = codec->spec;
4823 struct auto_pin_cfg *cfg = &spec->autocfg;
4827 if (spec->suppress_auto_mic)
4832 for (i = 0; i < cfg->num_inputs; i++) {
4833 hda_nid_t nid = cfg->inputs[i].pin;
4835 attr = snd_hda_codec_get_pincfg(codec, nid);
4841 if (cfg->inputs[i].type != AUTO_PIN_MIC)
4847 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
4849 if (!spec->line_in_auto_switch &&
4850 cfg->inputs[i].type != AUTO_PIN_MIC)
4852 if (!is_jack_detectable(codec, nid))
4859 spec->am_entry[num_pins].pin = nid;
4860 spec->am_entry[num_pins].attr = attr;
4864 if (num_pins < 2)
4867 spec->am_num_entries = num_pins;
4871 sort(spec->am_entry, num_pins, sizeof(spec->am_entry[0]),
4874 if (!auto_mic_check_imux(codec))
4877 spec->auto_mic = 1;
4878 spec->num_adc_nids = 1;
4879 spec->cur_mux[0] = spec->am_entry[0].idx;
4880 codec_dbg(codec, "Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
4881 spec->am_entry[0].pin,
4882 spec->am_entry[1].pin,
4883 spec->am_entry[2].pin);
4889 * snd_hda_gen_path_power_filter - power_filter hook to make inactive widgets
4891 * @codec: the HDA codec
4895 unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
4899 struct hda_gen_spec *spec = codec->spec;
4901 if (!spec->power_down_unused && !codec->power_save_node)
4903 if (power_state != AC_PWRST_D0 || nid == codec->core.afg)
4905 if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER)
4907 if (is_active_nid_for_any(codec, nid))
4914 static void mute_all_mixer_nid(struct hda_codec *codec, hda_nid_t mix)
4920 nums = snd_hda_get_conn_list(codec, mix, &conn);
4921 has_amp = nid_has_mute(codec, mix, HDA_INPUT);
4924 update_amp(codec, mix, HDA_INPUT, i,
4926 else if (nid_has_volume(codec, conn[i], HDA_OUTPUT))
4927 update_amp(codec, conn[i], HDA_OUTPUT, 0,
4933 * snd_hda_gen_stream_pm - Stream power management callback
4934 * @codec: the HDA codec
4940 void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on)
4942 if (codec->power_save_node)
4943 set_path_power(codec, nid, -1, on);
4948 static bool force_mute_output_path(struct hda_codec *codec, hda_nid_t nid)
4952 if (!nid_has_mute(codec, nid, HDA_OUTPUT))
4954 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4955 snd_hda_codec_amp_read(codec, nid, 1, HDA_OUTPUT, 0) &
4960 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4967 * snd_hda_gen_shutup_speakers - Forcibly mute the speaker outputs
4968 * @codec: the HDA codec
4977 bool snd_hda_gen_shutup_speakers(struct hda_codec *codec)
4979 struct hda_gen_spec *spec = codec->spec;
4986 if (!snd_hdac_is_power_on(&codec->core))
4989 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) {
4990 paths = spec->out_paths;
4991 num_paths = spec->autocfg.line_outs;
4993 paths = spec->speaker_paths;
4994 num_paths = spec->autocfg.speaker_outs;
4998 path = snd_hda_get_path_from_idx(codec, paths[i]);
5001 for (p = 0; p < path->depth; p++)
5002 if (force_mute_output_path(codec, path->path[p]))
5011 * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and
5013 * @codec: the HDA codec
5019 int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
5022 struct hda_gen_spec *spec = codec->spec;
5025 parse_user_hints(codec);
5027 if (spec->vmaster_mute_led || spec->mic_mute_led)
5030 if (spec->mixer_nid && !spec->mixer_merge_nid)
5031 spec->mixer_merge_nid = spec->mixer_nid;
5033 if (cfg != &spec->autocfg) {
5034 spec->autocfg = *cfg;
5035 cfg = &spec->autocfg;
5038 if (!spec->main_out_badness)
5039 spec->main_out_badness = &hda_main_out_badness;
5040 if (!spec->extra_out_badness)
5041 spec->extra_out_badness = &hda_extra_out_badness;
5043 fill_all_dac_nids(codec);
5045 if (!cfg->line_outs) {
5046 if (cfg->dig_outs || cfg->dig_in_pin) {
5047 spec->multiout.max_channels = 2;
5048 spec->no_analog = 1;
5051 if (!cfg->num_inputs && !cfg->dig_in_pin)
5055 if (!spec->no_primary_hp &&
5056 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
5057 cfg->line_outs <= cfg->hp_outs) {
5059 cfg->speaker_outs = cfg->line_outs;
5060 memcpy(cfg->speaker_pins, cfg->line_out_pins,
5061 sizeof(cfg->speaker_pins));
5062 cfg->line_outs = cfg->hp_outs;
5063 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
5064 cfg->hp_outs = 0;
5065 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
5066 cfg->line_out_type = AUTO_PIN_HP_OUT;
5069 err = parse_output_paths(codec);
5072 err = create_multi_channel_mode(codec);
5075 err = create_multi_out_ctls(codec, cfg);
5078 err = create_hp_out_ctls(codec);
5081 err = create_speaker_out_ctls(codec);
5084 err = create_indep_hp_ctls(codec);
5087 err = create_loopback_mixing_ctl(codec);
5090 err = create_hp_mic(codec);
5093 err = create_input_ctls(codec);
5097 /* add power-down pin callbacks at first */
5098 add_all_pin_power_ctls(codec, false);
5100 spec->const_channel_count = spec->ext_channel_count;
5102 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
5103 spec->const_channel_count = max(spec->const_channel_count,
5104 cfg->speaker_outs * 2);
5105 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
5106 spec->const_channel_count = max(spec->const_channel_count,
5107 cfg->hp_outs * 2);
5108 spec->multiout.max_channels = max(spec->ext_channel_count,
5109 spec->const_channel_count);
5111 err = check_auto_mute_availability(codec);
5115 err = check_dyn_adc_switch(codec);
5119 err = check_auto_mic_availability(codec);
5124 if (!spec->auto_mic && spec->mixer_nid &&
5125 spec->add_stereo_mix_input == HDA_HINT_STEREO_MIX_AUTO &&
5126 spec->input_mux.num_items > 1) {
5127 err = parse_capture_source(codec, spec->mixer_nid,
5128 CFG_IDX_MIX, spec->num_all_adcs,
5135 err = create_capture_mixers(codec);
5139 err = parse_mic_boost(codec);
5146 if (spec->hp_mic_pin &&
5147 (spec->auto_mic || spec->input_mux.num_items == 1 ||
5148 spec->add_jack_modes)) {
5149 err = create_hp_mic_jack_mode(codec, spec->hp_mic_pin);
5154 if (spec->add_jack_modes) {
5155 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
5156 err = create_out_jack_modes(codec, cfg->line_outs,
5157 cfg->line_out_pins);
5161 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
5162 err = create_out_jack_modes(codec, cfg->hp_outs,
5163 cfg->hp_pins);
5169 /* add power-up pin callbacks at last */
5170 add_all_pin_power_ctls(codec, true);
5173 if (spec->mixer_nid)
5174 mute_all_mixer_nid(codec, spec->mixer_nid);
5177 parse_digital(codec);
5179 if (spec->power_down_unused || codec->power_save_node) {
5180 if (!codec->power_filter)
5181 codec->power_filter = snd_hda_gen_path_power_filter;
5184 if (!spec->no_analog && spec->beep_nid) {
5185 err = snd_hda_attach_beep_device(codec, spec->beep_nid);
5188 if (codec->beep && codec->power_save_node) {
5189 err = add_fake_beep_paths(codec);
5192 codec->beep->power_hook = beep_power_hook;
5217 * snd_hda_gen_build_controls - Build controls from the parsed results
5218 * @codec: the HDA codec
5222 int snd_hda_gen_build_controls(struct hda_codec *codec)
5224 struct hda_gen_spec *spec = codec->spec;
5227 if (spec->kctls.used) {
5228 err = snd_hda_add_new_ctls(codec, spec->kctls.list);
5233 if (spec->multiout.dig_out_nid) {
5234 err = snd_hda_create_dig_out_ctls(codec,
5235 spec->multiout.dig_out_nid,
5236 spec->multiout.dig_out_nid,
5237 spec->pcm_rec[1]->pcm_type);
5240 if (!spec->no_analog) {
5241 err = snd_hda_create_spdif_share_sw(codec,
5242 &spec->multiout);
5245 spec->multiout.share_spdif = 1;
5248 if (spec->dig_in_nid) {
5249 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
5255 if (!spec->no_analog && !spec->suppress_vmaster &&
5256 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
5257 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
5258 spec->vmaster_tlv, follower_pfxs,
5263 if (!spec->no_analog && !spec->suppress_vmaster &&
5264 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
5265 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
5268 spec->vmaster_mute_led ?
5270 &spec->vmaster_mute.sw_kctl);
5273 if (spec->vmaster_mute.hook) {
5274 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute);
5275 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
5281 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
5295 struct hda_codec *codec,
5299 struct hda_gen_spec *spec = codec->spec;
5300 if (spec->pcm_playback_hook)
5301 spec->pcm_playback_hook(hinfo, codec, substream, action);
5305 struct hda_codec *codec,
5309 struct hda_gen_spec *spec = codec->spec;
5310 if (spec->pcm_capture_hook)
5311 spec->pcm_capture_hook(hinfo, codec, substream, action);
5318 struct hda_codec *codec,
5321 struct hda_gen_spec *spec = codec->spec;
5324 guard(mutex)(&spec->pcm_mutex);
5325 err = snd_hda_multi_out_analog_open(codec,
5326 &spec->multiout, substream,
5331 spec->active_streams |= 1 << STREAM_MULTI_OUT;
5332 call_pcm_playback_hook(hinfo, codec, substream,
5338 struct hda_codec *codec,
5343 struct hda_gen_spec *spec = codec->spec;
5346 err = snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
5349 call_pcm_playback_hook(hinfo, codec, substream,
5355 struct hda_codec *codec,
5358 struct hda_gen_spec *spec = codec->spec;
5361 err = snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
5363 call_pcm_playback_hook(hinfo, codec, substream,
5369 struct hda_codec *codec,
5372 struct hda_gen_spec *spec = codec->spec;
5374 guard(mutex)(&spec->pcm_mutex);
5375 spec->active_streams &= ~(1 << STREAM_MULTI_OUT);
5376 call_pcm_playback_hook(hinfo, codec, substream,
5382 struct hda_codec *codec,
5385 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_OPEN);
5390 struct hda_codec *codec,
5395 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
5396 call_pcm_capture_hook(hinfo, codec, substream,
5402 struct hda_codec *codec,
5405 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
5406 call_pcm_capture_hook(hinfo, codec, substream,
5412 struct hda_codec *codec,
5415 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLOSE);
5420 struct hda_codec *codec,
5423 struct hda_gen_spec *spec = codec->spec;
5426 guard(mutex)(&spec->pcm_mutex);
5427 if (spec->indep_hp && !spec->indep_hp_enabled)
5428 err = -EBUSY;
5430 spec->active_streams |= 1 << STREAM_INDEP_HP;
5431 call_pcm_playback_hook(hinfo, codec, substream,
5437 struct hda_codec *codec,
5440 struct hda_gen_spec *spec = codec->spec;
5442 guard(mutex)(&spec->pcm_mutex);
5443 spec->active_streams &= ~(1 << STREAM_INDEP_HP);
5444 call_pcm_playback_hook(hinfo, codec, substream,
5450 struct hda_codec *codec,
5455 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
5456 call_pcm_playback_hook(hinfo, codec, substream,
5462 struct hda_codec *codec,
5465 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
5466 call_pcm_playback_hook(hinfo, codec, substream,
5475 struct hda_codec *codec,
5478 struct hda_gen_spec *spec = codec->spec;
5479 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
5483 struct hda_codec *codec,
5488 struct hda_gen_spec *spec = codec->spec;
5489 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
5494 struct hda_codec *codec,
5497 struct hda_gen_spec *spec = codec->spec;
5498 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
5502 struct hda_codec *codec,
5505 struct hda_gen_spec *spec = codec->spec;
5506 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
5516 struct hda_codec *codec,
5521 struct hda_gen_spec *spec = codec->spec;
5523 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
5525 call_pcm_capture_hook(hinfo, codec, substream,
5531 struct hda_codec *codec,
5534 struct hda_gen_spec *spec = codec->spec;
5536 snd_hda_codec_cleanup_stream(codec,
5537 spec->adc_nids[substream->number + 1]);
5538 call_pcm_capture_hook(hinfo, codec, substream,
5547 .channels_min = 2,
5560 .channels_min = 2,
5561 .channels_max = 2,
5573 .channels_min = 2,
5574 .channels_max = 2,
5585 .substreams = 2, /* can be overridden */
5586 .channels_min = 2,
5587 .channels_max = 2,
5599 .channels_min = 2,
5600 .channels_max = 2,
5612 .channels_min = 2,
5613 .channels_max = 2,
5627 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
5629 struct hda_gen_spec *spec = codec->spec;
5630 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
5632 if (spec->cur_adc && spec->cur_adc != new_adc) {
5634 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
5635 spec->cur_adc = new_adc;
5636 snd_hda_codec_setup_stream(codec, new_adc,
5637 spec->cur_adc_stream_tag, 0,
5638 spec->cur_adc_format);
5644 /* analog capture with dynamic dual-adc changes */
5646 struct hda_codec *codec,
5651 struct hda_gen_spec *spec = codec->spec;
5652 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
5653 spec->cur_adc_stream_tag = stream_tag;
5654 spec->cur_adc_format = format;
5655 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
5656 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_PREPARE);
5661 struct hda_codec *codec,
5664 struct hda_gen_spec *spec = codec->spec;
5665 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
5666 spec->cur_adc = 0;
5667 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLEANUP);
5673 .channels_min = 2,
5674 .channels_max = 2,
5691 /* drop non-alnum chars after a space */
5701 /* copy PCM stream info from @default_str, and override non-NULL entries
5711 str->nid = nid;
5713 if (spec_str->substreams)
5714 str->substreams = spec_str->substreams;
5715 if (spec_str->channels_min)
5716 str->channels_min = spec_str->channels_min;
5717 if (spec_str->channels_max)
5718 str->channels_max = spec_str->channels_max;
5719 if (spec_str->rates)
5720 str->rates = spec_str->rates;
5721 if (spec_str->formats)
5722 str->formats = spec_str->formats;
5723 if (spec_str->maxbps)
5724 str->maxbps = spec_str->maxbps;
5729 * snd_hda_gen_build_pcms - build PCM streams based on the parsed results
5730 * @codec: the HDA codec
5734 int snd_hda_gen_build_pcms(struct hda_codec *codec)
5736 struct hda_gen_spec *spec = codec->spec;
5740 if (spec->no_analog)
5743 fill_pcm_stream_name(spec->stream_name_analog,
5744 sizeof(spec->stream_name_analog),
5745 " Analog", codec->core.chip_name);
5746 info = snd_hda_codec_pcm_new(codec, "%s", spec->stream_name_analog);
5748 return -ENOMEM;
5749 spec->pcm_rec[0] = info;
5751 if (spec->multiout.num_dacs > 0) {
5752 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5754 spec->stream_analog_playback,
5755 spec->multiout.dac_nids[0]);
5756 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
5757 spec->multiout.max_channels;
5758 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
5759 spec->autocfg.line_outs == 2)
5760 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
5763 if (spec->num_adc_nids) {
5764 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5765 (spec->dyn_adc_switch ?
5767 spec->stream_analog_capture,
5768 spec->adc_nids[0]);
5773 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
5774 fill_pcm_stream_name(spec->stream_name_digital,
5775 sizeof(spec->stream_name_digital),
5776 " Digital", codec->core.chip_name);
5777 info = snd_hda_codec_pcm_new(codec, "%s",
5778 spec->stream_name_digital);
5780 return -ENOMEM;
5781 codec->follower_dig_outs = spec->multiout.follower_dig_outs;
5782 spec->pcm_rec[1] = info;
5783 if (spec->dig_out_type)
5784 info->pcm_type = spec->dig_out_type;
5786 info->pcm_type = HDA_PCM_TYPE_SPDIF;
5787 if (spec->multiout.dig_out_nid)
5788 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5790 spec->stream_digital_playback,
5791 spec->multiout.dig_out_nid);
5792 if (spec->dig_in_nid)
5793 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5795 spec->stream_digital_capture,
5796 spec->dig_in_nid);
5799 if (spec->no_analog)
5803 * model, configure a second analog capture-only PCM.
5805 have_multi_adcs = (spec->num_adc_nids > 1) &&
5806 !spec->dyn_adc_switch && !spec->auto_mic;
5807 /* Additional Analaog capture for index #2 */
5808 if (spec->alt_dac_nid || have_multi_adcs) {
5809 fill_pcm_stream_name(spec->stream_name_alt_analog,
5810 sizeof(spec->stream_name_alt_analog),
5811 " Alt Analog", codec->core.chip_name);
5812 info = snd_hda_codec_pcm_new(codec, "%s",
5813 spec->stream_name_alt_analog);
5815 return -ENOMEM;
5816 spec->pcm_rec[2] = info;
5817 if (spec->alt_dac_nid)
5818 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5820 spec->stream_analog_alt_playback,
5821 spec->alt_dac_nid);
5823 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5826 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5828 spec->stream_analog_alt_capture,
5829 spec->adc_nids[1]);
5830 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
5831 spec->num_adc_nids - 1;
5833 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5844 * Standard auto-parser initializations
5848 static void set_output_and_unmute(struct hda_codec *codec, int path_idx)
5853 path = snd_hda_get_path_from_idx(codec, path_idx);
5854 if (!path || !path->depth)
5856 pin = path->path[path->depth - 1];
5857 restore_pin_ctl(codec, pin);
5858 snd_hda_activate_path(codec, path, path->active,
5859 aamix_default(codec->spec));
5860 set_pin_eapd(codec, pin, path->active);
5864 static void init_multi_out(struct hda_codec *codec)
5866 struct hda_gen_spec *spec = codec->spec;
5869 for (i = 0; i < spec->autocfg.line_outs; i++)
5870 set_output_and_unmute(codec, spec->out_paths[i]);
5874 static void __init_extra_out(struct hda_codec *codec, int num_outs, int *paths)
5879 set_output_and_unmute(codec, paths[i]);
5883 static void init_extra_out(struct hda_codec *codec)
5885 struct hda_gen_spec *spec = codec->spec;
5887 if (spec->autocfg.line_out_type != AUTO_PIN_HP_OUT)
5888 __init_extra_out(codec, spec->autocfg.hp_outs, spec->hp_paths);
5889 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT)
5890 __init_extra_out(codec, spec->autocfg.speaker_outs,
5891 spec->speaker_paths);
5894 /* initialize multi-io paths */
5895 static void init_multi_io(struct hda_codec *codec)
5897 struct hda_gen_spec *spec = codec->spec;
5900 for (i = 0; i < spec->multi_ios; i++) {
5901 hda_nid_t pin = spec->multi_io[i].pin;
5903 path = get_multiio_path(codec, i);
5906 if (!spec->multi_io[i].ctl_in)
5907 spec->multi_io[i].ctl_in =
5908 snd_hda_codec_get_pin_target(codec, pin);
5909 snd_hda_activate_path(codec, path, path->active,
5914 static void init_aamix_paths(struct hda_codec *codec)
5916 struct hda_gen_spec *spec = codec->spec;
5918 if (!spec->have_aamix_ctl)
5922 update_aamix_paths(codec, spec->aamix_mode, spec->out_paths[0],
5923 spec->aamix_out_paths[0],
5924 spec->autocfg.line_out_type);
5925 update_aamix_paths(codec, spec->aamix_mode, spec->hp_paths[0],
5926 spec->aamix_out_paths[1],
5928 update_aamix_paths(codec, spec->aamix_mode, spec->speaker_paths[0],
5929 spec->aamix_out_paths[2],
5934 static void init_analog_input(struct hda_codec *codec)
5936 struct hda_gen_spec *spec = codec->spec;
5937 struct auto_pin_cfg *cfg = &spec->autocfg;
5940 for (i = 0; i < cfg->num_inputs; i++) {
5941 hda_nid_t nid = cfg->inputs[i].pin;
5942 if (is_input_pin(codec, nid))
5943 restore_pin_ctl(codec, nid);
5946 if (spec->mixer_nid) {
5947 resume_path_from_idx(codec, spec->loopback_paths[i]);
5948 resume_path_from_idx(codec, spec->loopback_merge_path);
5954 static void init_input_src(struct hda_codec *codec)
5956 struct hda_gen_spec *spec = codec->spec;
5957 struct hda_input_mux *imux = &spec->input_mux;
5961 if (spec->dyn_adc_switch)
5964 nums = spec->num_adc_nids;
5967 for (i = 0; i < imux->num_items; i++) {
5968 path = get_input_path(codec, c, i);
5970 bool active = path->active;
5971 if (i == spec->cur_mux[c])
5973 snd_hda_activate_path(codec, path, active, false);
5976 if (spec->hp_mic)
5977 update_hp_mic(codec, c, true);
5980 if (spec->cap_sync_hook)
5981 spec->cap_sync_hook(codec, NULL, NULL);
5985 static void init_digital(struct hda_codec *codec)
5987 struct hda_gen_spec *spec = codec->spec;
5991 for (i = 0; i < spec->autocfg.dig_outs; i++)
5992 set_output_and_unmute(codec, spec->digout_paths[i]);
5993 pin = spec->autocfg.dig_in_pin;
5995 restore_pin_ctl(codec, pin);
5996 resume_path_from_idx(codec, spec->digin_path);
6000 /* clear unsol-event tags on unused pins; Conexant codecs seem to leave
6003 static void clear_unsol_on_unused_pins(struct hda_codec *codec)
6008 snd_array_for_each(&codec->init_pins, i, pin) {
6009 hda_nid_t nid = pin->nid;
6010 if (is_jack_detectable(codec, nid) &&
6011 !snd_hda_jack_tbl_get(codec, nid))
6012 snd_hda_codec_write_cache(codec, nid, 0,
6018 * snd_hda_gen_init - initialize the generic spec
6019 * @codec: the HDA codec
6023 int snd_hda_gen_init(struct hda_codec *codec)
6025 struct hda_gen_spec *spec = codec->spec;
6027 if (spec->init_hook)
6028 spec->init_hook(codec);
6030 if (!spec->skip_verbs)
6031 snd_hda_apply_verbs(codec);
6033 init_multi_out(codec);
6034 init_extra_out(codec);
6035 init_multi_io(codec);
6036 init_aamix_paths(codec);
6037 init_analog_input(codec);
6038 init_input_src(codec);
6039 init_digital(codec);
6041 clear_unsol_on_unused_pins(codec);
6043 sync_all_pin_power_ctls(codec);
6045 /* call init functions of standard auto-mute helpers */
6046 update_automute_all(codec);
6048 snd_hda_regmap_sync(codec);
6050 if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook)
6051 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6053 hda_call_check_power_status(codec, 0x01);
6059 * snd_hda_gen_remove - free the generic spec
6060 * @codec: the HDA codec
6064 void snd_hda_gen_remove(struct hda_codec *codec)
6066 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
6067 snd_hda_gen_spec_free(codec->spec);
6068 kfree(codec->spec);
6069 codec->spec = NULL;
6074 * snd_hda_gen_check_power_status - check the loopback power save state
6075 * @codec: the HDA codec
6080 int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid)
6082 struct hda_gen_spec *spec = codec->spec;
6083 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
6089 * the generic codec support
6092 static int snd_hda_gen_probe(struct hda_codec *codec,
6100 return -ENOMEM;
6102 codec->spec = spec;
6104 err = snd_hda_parse_pin_defcfg(codec, &spec->autocfg, NULL, 0);
6108 err = snd_hda_gen_parse_auto_config(codec, &spec->autocfg);
6115 snd_hda_gen_remove(codec);
6145 MODULE_DESCRIPTION("Generic HD-audio codec parser");