Lines Matching +full:merge +full:- +full:mute

1 // SPDX-License-Identifier: GPL-2.0-or-later
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]);
107 struct hda_gen_spec *spec = codec->spec;
112 codec->no_jack_detect = !val;
115 codec->inv_jack_detect = !!val;
118 codec->no_trigger_sense = !val;
121 codec->inv_eapd = !!val;
124 codec->pcm_format_first = !!val;
127 codec->no_sticky_stream = !val;
130 codec->spdif_status_reset = !!val;
133 codec->pin_amp_workaround = !!val;
136 codec->single_adc_amp = !!val;
139 codec->power_save_node = !!val;
143 spec->suppress_auto_mute = !val;
146 spec->suppress_auto_mic = !val;
149 spec->line_in_auto_switch = !!val;
152 spec->auto_mute_via_amp = !!val;
155 spec->need_dac_fix = !!val;
158 spec->no_primary_hp = !val;
161 spec->no_multi_io = !val;
164 spec->multi_cap_vol = !!val;
167 spec->inv_dmic_split = !!val;
170 spec->indep_hp = !!val;
173 spec->add_stereo_mix_input = !!val;
177 spec->add_jack_modes = !!val;
180 spec->add_jack_modes = !!val;
183 spec->add_jack_modes = !!val;
186 spec->power_down_unused = !!val;
189 spec->hp_mic = !!val;
192 spec->suppress_hp_mic_detect = !val;
195 spec->suppress_vmaster = !val;
198 spec->mixer_nid = val;
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;
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
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
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);
321 struct hda_gen_spec *spec = codec->spec;
325 snd_array_for_each(&spec->paths, i, path) {
326 if (path->path[0] == nid)
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)
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);
394 else if (to_nid == (hda_nid_t)(-anchor_nid))
427 path->path[path->depth] = conn[i];
428 path->idx[path->depth + 1] = i;
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
459 path->path[path->depth] = to_nid;
460 path->depth++;
467 * snd_hda_add_new_path - parse the path between the given NIDs and
480 struct hda_gen_spec *spec = codec->spec;
491 path = snd_array_new(&spec->paths);
498 spec->paths.used--;
515 struct hda_gen_spec *spec = codec->spec;
516 const hda_nid_t *list = spec->preferred_dacs;
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];
564 /* look for a widget suitable for assigning a mute switch in the path */
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];
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)
601 /* can have the amp-in capability? */
604 hda_nid_t nid = path->path[idx];
615 /* can have the amp-out capability? */
618 hda_nid_t nid = path->path[idx];
633 struct hda_gen_spec *spec = codec->spec;
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)
666 is_active_nid(codec, nid, HDA_OUTPUT, -1)
686 /* is this a stereo widget or a stereo-to-mono mix? */
777 hda_nid_t nid = path->path[i];
785 struct hda_gen_spec *spec = codec->spec;
789 hda_nid_t nid = path->path[i];
796 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
800 idx = path->idx[i];
806 * when aa-mixer is available, we need to enable the path as well
810 if (conn[n] != spec->mixer_merge_nid)
830 for (i = 0; i < path->depth; i++) {
831 nid = path->path[i];
834 if (nid == codec->core.afg)
854 snd_hdac_regmap_sync_node(&codec->core, nid);
871 * snd_hda_activate_path - activate or deactivate the given path
877 * If @add_aamix is set, enable the input from aa-mix NID as well (if any).
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])
897 path->idx[i]);
909 struct hda_gen_spec *spec = codec->spec;
911 if (!(spec->power_down_unused || codec->power_save_node) || path->active)
919 struct hda_gen_spec *spec = codec->spec;
920 if (spec->own_eapd_ctl ||
923 if (spec->keep_eapd_on && !enable)
925 if (codec->inv_eapd)
932 /* re-initialize the path specified by the given path index */
937 snd_hda_activate_path(codec, path, path->active, false);
959 /* only the put callback is replaced for handling the special mute */
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;
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[] */
1039 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
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
1064 val = path->ctls[NID_PATH_MUTE_CTL];
1076 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
1086 /* playback mute control with the software mute bit check */
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;
1109 * Bound mute controls
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;
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;
1157 return path && path->ctls[ctl_type];
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) {
1191 /* if the primary channel vol/mute is shared with HP volume,
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)
1203 /* if the primary channel vol/mute is shared with spk volume,
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)
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 */
1277 * volume and mute controls, and assign the values to ctls[].
1281 * total badness for both volume and mute controls.
1285 struct hda_gen_spec *spec = codec->spec;
1293 if (path->ctls[NID_PATH_VOL_CTL] ||
1294 path->ctls[NID_PATH_MUTE_CTL])
1300 if (spec->dac_min_mute)
1305 path->ctls[NID_PATH_VOL_CTL] = val;
1319 path->ctls[NID_PATH_MUTE_CTL] = val;
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;
1372 struct hda_gen_spec *spec = codec->spec;
1384 if (!spec->preferred_dacs) {
1395 badness += bad->shared_primary;
1396 } else if (spec->preferred_dacs) {
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) {
1446 badness += bad->no_dac;
1449 path->active = true;
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];
1478 /* check whether the given pin can be a multi-io pin */
1495 /* count the number of input pins that are capable to be multi-io */
1498 struct hda_gen_spec *spec = codec->spec;
1499 struct auto_pin_cfg *cfg = &spec->autocfg;
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)
1510 cfg->inputs[i].pin))
1518 * multi-io helper
1521 * zero if any pins are filled, non-zero if nothing found.
1529 struct hda_gen_spec *spec = codec->spec;
1530 struct auto_pin_cfg *cfg = &spec->autocfg;
1537 old_pins = spec->multi_ios;
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)
1554 for (j = 0; j < spec->multi_ios; j++) {
1555 if (nid == spec->multi_io[j].pin)
1558 if (j < spec->multi_ios)
1570 -spec->mixer_nid);
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] =
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;
1601 /* assign volume and mute controls */
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]);
1614 struct hda_gen_spec *spec = codec->spec;
1626 -spec->mixer_nid);
1627 if (!path && !i && spec->mixer_nid)
1633 path->active = true;
1642 return spec->aamix_out_paths[0] || spec->aamix_out_paths[1] ||
1643 spec->aamix_out_paths[2];
1649 struct hda_gen_spec *spec = codec->spec;
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];
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 */
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];
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))
1734 dacs[i] = path->path[0];
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) {
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);
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++)
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]);
1967 struct hda_gen_spec *spec = codec->spec;
1970 spec->num_all_dacs = 0;
1971 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
1975 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
1979 spec->all_dacs[spec->num_all_dacs++] = nid;
1985 struct hda_gen_spec *spec = codec->spec;
1986 struct auto_pin_cfg *cfg = &spec->autocfg;
1997 return -ENOMEM;
2006 cfg->line_out_type, fill_hardwired, fill_mio_first,
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;
2063 cfg->line_out_type, best_wired, best_mio);
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;
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]);
2200 struct hda_gen_spec *spec = codec->spec;
2201 return create_extra_outs(codec, spec->autocfg.hp_outs,
2202 spec->hp_paths,
2208 struct hda_gen_spec *spec = codec->spec;
2209 return create_extra_outs(codec, spec->autocfg.speaker_outs,
2210 spec->speaker_paths,
2230 struct hda_gen_spec *spec = codec->spec;
2231 ucontrol->value.enumerated.item[0] = spec->indep_hp_enabled;
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;
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;
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);
2341 struct hda_gen_spec *spec = codec->spec;
2342 ucontrol->value.enumerated.item[0] =
2343 (spec->ext_channel_count - spec->min_channel_count) / 2;
2350 struct hda_gen_spec *spec = codec->spec;
2352 spec->out_paths[spec->autocfg.line_outs + idx]);
2362 return !spec->have_aamix_ctl || spec->aamix_mode;
2367 struct hda_gen_spec *spec = codec->spec;
2368 hda_nid_t nid = spec->multi_io[idx].pin;
2373 return -EINVAL;
2375 if (path->active == output)
2385 set_pin_target(codec, nid, spec->multi_io[idx].ctl_in, true);
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++)
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;
2427 struct hda_gen_spec *spec = codec->spec;
2429 if (spec->multi_ios > 0) {
2431 return -ENOMEM;
2446 struct hda_gen_spec *spec = codec->spec;
2447 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2455 struct hda_gen_spec *spec = codec->spec;
2466 if (out_type == AUTO_PIN_HP_OUT && spec->indep_hp_enabled &&
2467 mix_path->path[0] != spec->alt_dac_nid)
2481 /* re-initialize the output paths; only called from loopback_mixing_put() */
2485 struct hda_gen_spec *spec = codec->spec;
2492 snd_hda_activate_path(codec, path, path->active,
2493 spec->aamix_mode);
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);
2539 struct hda_gen_spec *spec = codec->spec;
2541 if (!spec->mixer_nid)
2544 return -ENOMEM;
2545 spec->have_aamix_ctl = 1;
2555 /* for shared I/O, change the pin-control accordingly */
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;
2581 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
2582 const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
2589 if (!spec->hp_mic_jack_modes) {
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];
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;
2669 hda_nid_t nid = kcontrol->private_value;
2671 ucontrol->value.enumerated.item[0] = 1;
2673 ucontrol->value.enumerated.item[0] = 0;
2681 hda_nid_t nid = kcontrol->private_value;
2684 val = ucontrol->value.enumerated.item[0] ? PIN_HP : PIN_OUT;
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)
2714 struct hda_gen_spec *spec = codec->spec;
2717 snd_hda_get_pin_label(codec, pin, &spec->autocfg, name, name_len, &idx);
2726 struct hda_gen_spec *spec = codec->spec;
2727 if (spec->add_jack_modes) {
2738 struct hda_gen_spec *spec = codec->spec;
2743 if (pin == spec->hp_mic_pin)
2752 return -ENOMEM;
2753 knew->private_value = pin;
2816 hda_nid_t nid = kcontrol->private_value;
2822 strscpy(uinfo->value.enumerated.name,
2823 vref_texts[get_vref_idx(vref_caps, uinfo->value.enumerated.item)]);
2831 hda_nid_t nid = kcontrol->private_value;
2836 ucontrol->value.enumerated.item[0] = cvt_from_vref_idx(vref_caps, idx);
2844 hda_nid_t nid = kcontrol->private_value;
2850 if (idx == ucontrol->value.enumerated.item[0])
2854 val |= get_vref_idx(vref_caps, ucontrol->value.enumerated.item[0]);
2868 struct hda_gen_spec *spec = codec->spec;
2870 if (spec->add_jack_modes)
2877 struct hda_gen_spec *spec = codec->spec;
2882 if (pin == spec->hp_mic_pin)
2897 return -ENOMEM;
2898 knew->private_value = pin;
2909 hda_nid_t nid = kcontrol->private_value;
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;
2935 strscpy(uinfo->value.enumerated.name, text);
2964 hda_nid_t nid = kcontrol->private_value;
2965 ucontrol->value.enumerated.item[0] =
2974 hda_nid_t nid = kcontrol->private_value;
2980 idx = ucontrol->value.enumerated.item[0];
2990 idx -= out_jacks;
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;
3045 /* return true if either a volume or a mute amp is found for the given
3088 struct hda_gen_spec *spec = codec->spec;
3098 return -EINVAL;
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 =
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);
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
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;
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++) {
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)) {
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;
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];
3265 spec->input_paths[imux_idx][c] =
3269 if (spec->hp_mic_pin == pin)
3270 spec->hp_mic_mux_idx = imux->num_items;
3271 spec->imux_pins[imux->num_items] = pin;
3274 if (spec->dyn_adc_switch)
3275 spec->dyn_adc_idx[imux_idx] = c;
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;
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 */
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;
3337 for (i = 0; i < cfg->num_inputs; i++) {
3340 pin = cfg->inputs[i].pin;
3345 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3347 if (pin != spec->hp_mic_pin &&
3354 spec->input_labels[i],
3355 spec->input_label_idxs[i],
3363 spec->input_labels[i], -mixer);
3367 if (spec->add_jack_modes) {
3375 if (mixer && spec->add_stereo_mix_input == HDA_HINT_STEREO_MIX_ENABLE) {
3381 spec->suppress_auto_mic = 1;
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]);
3416 struct hda_gen_spec *spec = codec->spec;
3417 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
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];
3436 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
3438 ucontrol->value.enumerated.item[0]);
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++) {
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);
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]) {
3546 path->ctls[NID_PATH_VOL_CTL] =
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]) {
3558 path->ctls[NID_PATH_MUTE_CTL] =
3561 int idx = path->idx[i];
3562 if (!depth && codec->single_adc_amp)
3564 path->ctls[NID_PATH_MUTE_CTL] =
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)
3597 struct hda_gen_spec *spec = codec->spec;
3604 if (spec->cap_sync_hook)
3605 spec->cap_sync_hook(codec, kcontrol, ucontrol);
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;
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;
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;
3714 ctl = path->ctls[type];
3717 for (i = 0; i < idx - 1; i++) {
3719 if (path && path->ctls[type] == ctl)
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]);
3743 spec->input_labels[idx],
3744 spec->input_label_idxs[idx],
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++) {
3790 vol = path->ctls[NID_PATH_VOL_CTL];
3791 else if (vol != path->ctls[NID_PATH_VOL_CTL]) {
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]) {
3802 path->ctls[NID_PATH_MUTE_CTL], HDA_INPUT))
3805 if (is_inv_dmic_pin(codec, spec->imux_pins[i]))
3854 if (depth >= path->depth - 1)
3856 nid = path->path[depth];
3861 path->idx[depth])) {
3862 val = HDA_COMPOSE_AMP_VAL(nid, 3, path->idx[depth],
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)
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;
3917 * vmaster mute LED hook helpers
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
3956 struct hda_gen_spec *spec = codec->spec;
3962 codec_warn(codec, "failed to create a mute LED cdev\n");
3967 if (spec->vmaster_mute.hook)
3970 spec->vmaster_mute_led = 1;
3976 * snd_hda_gen_add_micmute_led_cdev - Create a LED classdev and enable as mic-mute LED
3980 * Called from the codec drivers for offering the mic mute LED controls.
3985 * LED-trigger is set up.
3993 struct hda_gen_spec *spec = codec->spec;
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
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];
4031 path->active = true;
4032 path->pin_fixed = true; /* no jack detection */
4033 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
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;
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);
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)
4099 spec->cur_mux[adc_idx] = idx;
4101 if (spec->hp_mic)
4104 if (spec->dyn_adc_switch)
4110 if (path->active)
4113 if (spec->cap_sync_hook)
4114 spec->cap_sync_hook(codec, NULL, NULL);
4120 * as terminals (either start- or endpoint)
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) {
4174 if (!codec->power_save_node)
4181 return set_path_power(codec, pin, on, -1);
4188 if (jack && jack->nid)
4190 set_pin_power_jack(codec, jack->nid, on));
4193 /* callback only doing power up -- called at first */
4200 /* callback only doing power down -- called at last */
4219 set_path_power(codec, pins[i], true, -1);
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);
4251 set_pin_power_jack(codec, pins[i], -1);
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);
4276 struct hda_gen_spec *spec = codec->spec;
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;
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
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
4376 /* standard HP/line-out auto-mute helper */
4378 int *paths, bool mute)
4380 struct hda_gen_spec *spec = codec->spec;
4391 continue; /* no mute for inputs */
4393 if (spec->auto_mute_via_amp) {
4400 mute_nid = get_amp_nid_(path->ctls[NID_PATH_MUTE_CTL]);
4403 if (mute)
4404 spec->mute_bits |= (1ULL << mute_nid);
4406 spec->mute_bits &= ~(1ULL << mute_nid);
4412 if (spec->keep_vref_in_automute)
4416 if (!mute)
4426 set_pin_eapd(codec, nid, !mute);
4427 if (codec->power_save_node) {
4428 bool on = !mute;
4431 set_path_power(codec, nid, on, -1);
4437 * snd_hda_gen_update_outputs - Toggle outputs muting
4440 * Update the mute status of all outputs based on the current jack states.
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);
4491 struct hda_gen_spec *spec = codec->spec;
4492 if (spec->automute_hook)
4493 spec->automute_hook(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
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))
4528 * snd_hda_gen_line_automute - standard line-out-automute helper
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)
4553 * snd_hda_gen_mic_autoswitch - standard mic auto-switch helper
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;
4572 mux_select(codec, 0, spec->am_entry[i].idx);
4576 mux_select(codec, 0, spec->am_entry[0].idx);
4584 struct hda_gen_spec *spec = codec->spec;
4585 if (spec->hp_automute_hook)
4586 spec->hp_automute_hook(codec, jack);
4594 struct hda_gen_spec *spec = codec->spec;
4595 if (spec->line_automute_hook)
4596 spec->line_automute_hook(codec, jack);
4604 struct hda_gen_spec *spec = codec->spec;
4605 if (spec->mic_autoswitch_hook)
4606 spec->mic_autoswitch_hook(codec, jack);
4620 * Auto-Mute mode mixer enum support
4626 struct hda_gen_spec *spec = codec->spec;
4631 if (spec->automute_speaker_possible && spec->automute_lo_possible)
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;
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;
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;
4694 .name = "Auto-Mute Mode",
4702 struct hda_gen_spec *spec = codec->spec;
4705 return -ENOMEM;
4710 * Check the availability of HP/line-out auto-mute;
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])
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];
4750 codec_dbg(codec, "Enable HP auto-muting on NID 0x%x\n", 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];
4762 codec_dbg(codec, "Enable Line-Out auto-muting on NID 0x%x\n", 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) {
4785 /* check whether all auto-mic pins are valid; setup indices if OK */
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++)
4804 spec->am_entry[i].pin,
4813 return (int)(a->attr - b->attr);
4817 * Check the availability of auto-mic switch;
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;
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)
4859 spec->am_entry[num_pins].pin = nid;
4860 spec->am_entry[num_pins].attr = attr;
4867 spec->am_num_entries = num_pins;
4871 sort(spec->am_entry, num_pins, sizeof(spec->am_entry[0]),
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
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)
4913 /* mute all aamix inputs initially; parse up to the first leaves */
4933 * snd_hda_gen_stream_pm - Stream power management callback
4942 if (codec->power_save_node)
4943 set_path_power(codec, nid, -1, on);
4947 /* forcibly mute the speaker output without caching; return true if updated */
4953 return false; /* no mute, skip */
4967 * snd_hda_gen_shutup_speakers - Forcibly mute the speaker outputs
4970 * Forcibly mute the speaker outputs, to be called at suspend or shutdown.
4972 * The mute state done by this function isn't cached, hence the original state
4975 * Return true if the mute state has been changed.
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;
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
5022 struct hda_gen_spec *spec = codec->spec;
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;
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;
5097 /* add power-down pin callbacks at first */
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);
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,
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 */
5172 /* mute all aamix input initially */
5173 if (spec->mixer_nid)
5174 mute_all_mixer_nid(codec, spec->mixer_nid);
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) {
5192 codec->beep->power_hook = beep_power_hook;
5217 * snd_hda_gen_build_controls - Build controls from the parsed results
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) {
5235 spec->multiout.dig_out_nid,
5236 spec->multiout.dig_out_nid,
5237 spec->pcm_rec[1]->pcm_type);
5240 if (!spec->no_analog) {
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 &&
5258 spec->vmaster_tlv, follower_pfxs,
5263 if (!spec->no_analog && !spec->suppress_vmaster &&
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);
5299 struct hda_gen_spec *spec = codec->spec;
5300 if (spec->pcm_playback_hook)
5301 spec->pcm_playback_hook(hinfo, codec, substream, action);
5309 struct hda_gen_spec *spec = codec->spec;
5310 if (spec->pcm_capture_hook)
5311 spec->pcm_capture_hook(hinfo, codec, substream, action);
5321 struct hda_gen_spec *spec = codec->spec;
5324 guard(mutex)(&spec->pcm_mutex);
5326 &spec->multiout, substream,
5331 spec->active_streams |= 1 << STREAM_MULTI_OUT;
5343 struct hda_gen_spec *spec = codec->spec;
5346 err = snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
5358 struct hda_gen_spec *spec = codec->spec;
5361 err = snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
5372 struct hda_gen_spec *spec = codec->spec;
5374 guard(mutex)(&spec->pcm_mutex);
5375 spec->active_streams &= ~(1 << STREAM_MULTI_OUT);
5395 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
5405 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
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;
5440 struct hda_gen_spec *spec = codec->spec;
5442 guard(mutex)(&spec->pcm_mutex);
5443 spec->active_streams &= ~(1 << STREAM_INDEP_HP);
5455 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
5465 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
5478 struct hda_gen_spec *spec = codec->spec;
5479 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
5488 struct hda_gen_spec *spec = codec->spec;
5489 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
5497 struct hda_gen_spec *spec = codec->spec;
5498 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
5505 struct hda_gen_spec *spec = codec->spec;
5506 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
5521 struct hda_gen_spec *spec = codec->spec;
5523 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
5534 struct hda_gen_spec *spec = codec->spec;
5537 spec->adc_nids[substream->number + 1]);
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;
5637 spec->cur_adc_stream_tag, 0,
5638 spec->cur_adc_format);
5644 /* analog capture with dynamic dual-adc changes */
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);
5664 struct hda_gen_spec *spec = codec->spec;
5665 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
5666 spec->cur_adc = 0;
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
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);
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;
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);
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
5854 if (!path || !path->depth)
5856 pin = path->path[path->depth - 1];
5858 snd_hda_activate_path(codec, path, path->active,
5859 aamix_default(codec->spec));
5860 set_pin_eapd(codec, pin, path->active);
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]);
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 */
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;
5906 if (!spec->multi_io[i].ctl_in)
5907 spec->multi_io[i].ctl_in =
5909 snd_hda_activate_path(codec, path, path->active,
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],
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;
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);
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++) {
5970 bool active = path->active;
5971 if (i == spec->cur_mux[c])
5976 if (spec->hp_mic)
5980 if (spec->cap_sync_hook)
5981 spec->cap_sync_hook(codec, NULL, NULL);
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;
5996 resume_path_from_idx(codec, spec->digin_path);
6000 /* clear unsol-event tags on unused pins; Conexant codecs seem to leave
6008 snd_array_for_each(&codec->init_pins, i, pin) {
6009 hda_nid_t nid = pin->nid;
6018 * snd_hda_gen_init - initialize the generic spec
6025 struct hda_gen_spec *spec = codec->spec;
6027 if (spec->init_hook)
6028 spec->init_hook(codec);
6030 if (!spec->skip_verbs)
6045 /* call init functions of standard auto-mute helpers */
6050 if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook)
6051 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6059 * snd_hda_gen_remove - free the generic spec
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
6082 struct hda_gen_spec *spec = codec->spec;
6083 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
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);
6145 MODULE_DESCRIPTION("Generic HD-audio codec parser");