Lines Matching +full:adc +full:- +full:alt +full:- +full:channel
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];
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)
647 /* ignore unplugged paths except for DAC/ADC */
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);
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);
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;
1121 mutex_lock(&codec->control_mutex);
1122 pval = kcontrol->private_value;
1123 kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */
1125 kcontrol->private_value = pval;
1126 mutex_unlock(&codec->control_mutex);
1139 mutex_lock(&codec->control_mutex);
1140 pval = kcontrol->private_value;
1143 kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) |
1150 kcontrol->private_value = pval;
1151 mutex_unlock(&codec->control_mutex);
1159 return path && path->ctls[ctl_type];
1166 /* give some appropriate ctl name prefix for the given line out channel */
1170 struct hda_gen_spec *spec = codec->spec;
1171 struct auto_pin_cfg *cfg = &spec->autocfg;
1174 if (cfg->line_outs == 1 && !spec->multi_ios &&
1175 !codec->force_pin_prefix &&
1176 !cfg->hp_outs && !cfg->speaker_outs)
1177 return spec->vmaster_mute.hook ? "PCM" : "Master";
1182 if (spec->multiout.num_dacs == 1 && !spec->mixer_nid &&
1183 !codec->force_pin_prefix &&
1184 !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0])
1185 return spec->vmaster_mute.hook ? "PCM" : "Master";
1187 /* multi-io channels */
1188 if (ch >= cfg->line_outs)
1191 switch (cfg->line_out_type) {
1193 /* if the primary channel vol/mute is shared with HP volume,
1196 if (!ch && cfg->hp_outs &&
1197 !path_has_mixer(codec, spec->hp_paths[0], ctl_type))
1199 if (cfg->line_outs == 1)
1201 if (cfg->line_outs == 2)
1205 /* if the primary channel vol/mute is shared with spk volume,
1208 if (!ch && cfg->speaker_outs &&
1209 !path_has_mixer(codec, spec->speaker_paths[0], ctl_type))
1211 /* for multi-io case, only the primary out */
1212 if (ch && spec->multi_ios)
1223 if (cfg->speaker_outs)
1225 spec->speaker_paths[0], ctl_type);
1226 if (cfg->hp_outs)
1227 hp_lo_shared = !path_has_mixer(codec, spec->hp_paths[0], ctl_type);
1229 return spec->vmaster_mute.hook ? "PCM" : "Master";
1237 /* for a single channel output, we don't have to name the channel */
1238 if (cfg->line_outs == 1 && !spec->multi_ios)
1260 /* No possible multi-ios */
1287 struct hda_gen_spec *spec = codec->spec;
1295 if (path->ctls[NID_PATH_VOL_CTL] ||
1296 path->ctls[NID_PATH_MUTE_CTL])
1302 if (spec->dac_min_mute)
1307 path->ctls[NID_PATH_VOL_CTL] = val;
1321 path->ctls[NID_PATH_MUTE_CTL] = val;
1350 struct hda_gen_spec *spec = codec->spec;
1351 struct auto_pin_cfg *cfg = &spec->autocfg;
1353 if (cfg->line_outs > idx)
1354 return spec->private_dac_nids[idx];
1355 idx -= cfg->line_outs;
1356 if (spec->multi_ios > idx)
1357 return spec->multi_io[idx].dac;
1374 struct hda_gen_spec *spec = codec->spec;
1386 if (!spec->preferred_dacs) {
1397 badness += bad->shared_primary;
1398 } else if (spec->preferred_dacs) {
1426 badness += bad->shared_primary;
1428 badness += bad->shared_surr;
1430 badness += bad->shared_clfe;
1431 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
1432 dac = spec->private_dac_nids[0];
1433 badness += bad->shared_surr_main;
1435 badness += bad->no_primary_dac;
1437 badness += bad->no_dac;
1441 path = snd_hda_add_new_path(codec, dac, pin, -spec->mixer_nid);
1442 if (!path && !i && spec->mixer_nid) {
1448 badness += bad->no_dac;
1451 path->active = true;
1463 struct hda_gen_spec *spec = codec->spec;
1467 for (i = 0; i < spec->num_all_dacs; i++) {
1468 hda_nid_t nid = spec->all_dacs[i];
1480 /* check whether the given pin can be a multi-io pin */
1497 /* count the number of input pins that are capable to be multi-io */
1500 struct hda_gen_spec *spec = codec->spec;
1501 struct auto_pin_cfg *cfg = &spec->autocfg;
1507 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
1508 for (i = 0; i < cfg->num_inputs; i++) {
1509 if (cfg->inputs[i].type != type)
1512 cfg->inputs[i].pin))
1520 * multi-io helper
1523 * zero if any pins are filled, non-zero if nothing found.
1531 struct hda_gen_spec *spec = codec->spec;
1532 struct auto_pin_cfg *cfg = &spec->autocfg;
1539 old_pins = spec->multi_ios;
1547 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
1548 for (i = 0; i < cfg->num_inputs; i++) {
1549 hda_nid_t nid = cfg->inputs[i].pin;
1552 if (cfg->inputs[i].type != type)
1556 for (j = 0; j < spec->multi_ios; j++) {
1557 if (nid == spec->multi_io[j].pin)
1560 if (j < spec->multi_ios)
1572 -spec->mixer_nid);
1578 spec->multi_io[spec->multi_ios].pin = nid;
1579 spec->multi_io[spec->multi_ios].dac = dac;
1580 spec->out_paths[cfg->line_outs + spec->multi_ios] =
1582 spec->multi_ios++;
1583 if (spec->multi_ios >= 2)
1590 if (old_pins == spec->multi_ios) {
1596 if (!hardwired && spec->multi_ios < 2) {
1598 spec->paths.used -= spec->multi_ios - old_pins;
1599 spec->multi_ios = old_pins;
1604 for (i = old_pins; i < spec->multi_ios; i++) {
1605 path = snd_hda_get_path_from_idx(codec, spec->out_paths[cfg->line_outs + i]);
1616 struct hda_gen_spec *spec = codec->spec;
1628 -spec->mixer_nid);
1629 if (!path && !i && spec->mixer_nid)
1635 path->active = true;
1644 return spec->aamix_out_paths[0] || spec->aamix_out_paths[1] ||
1645 spec->aamix_out_paths[2];
1651 struct hda_gen_spec *spec = codec->spec;
1656 if (!path || !path->depth ||
1657 is_nid_contained(path, spec->mixer_nid))
1659 path_dac = path->path[0];
1660 dac = spec->private_dac_nids[0];
1661 pin = path->path[path->depth - 1];
1662 path = snd_hda_add_new_path(codec, dac, pin, spec->mixer_nid);
1666 else if (spec->multiout.hp_out_nid[0])
1667 dac = spec->multiout.hp_out_nid[0];
1668 else if (spec->multiout.extra_out_nid[0])
1669 dac = spec->multiout.extra_out_nid[0];
1674 spec->mixer_nid);
1678 /* print_nid_path(codec, "output-aamix", path); */
1679 path->active = false; /* unused as default */
1680 path->pin_fixed = true; /* static route */
1687 struct hda_gen_spec *spec = codec->spec;
1688 struct auto_pin_cfg *cfg = &spec->autocfg;
1692 if (cfg->line_out_type == AUTO_PIN_HP_OUT)
1693 idx = spec->out_paths[0];
1695 idx = spec->hp_paths[0];
1701 if (!spec->mixer_nid || !is_nid_contained(path, spec->mixer_nid))
1705 for (i = 0; i < cfg->line_outs; i++) {
1706 if (spec->out_paths[i] == idx)
1708 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
1709 if (path && is_nid_contained(path, spec->mixer_nid))
1712 for (i = 0; i < cfg->speaker_outs; i++) {
1713 path = snd_hda_get_path_from_idx(codec, spec->speaker_paths[i]);
1714 if (path && is_nid_contained(path, spec->mixer_nid))
1736 dacs[i] = path->path[0];
1745 struct hda_gen_spec *spec = codec->spec;
1746 struct auto_pin_cfg *cfg = &spec->autocfg;
1750 spec->multiout.num_dacs = cfg->line_outs;
1751 spec->multiout.dac_nids = spec->private_dac_nids;
1752 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
1753 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
1754 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
1755 spec->multi_ios = 0;
1756 snd_array_free(&spec->paths);
1759 memset(spec->out_paths, 0, sizeof(spec->out_paths));
1760 memset(spec->hp_paths, 0, sizeof(spec->hp_paths));
1761 memset(spec->speaker_paths, 0, sizeof(spec->speaker_paths));
1762 memset(spec->aamix_out_paths, 0, sizeof(spec->aamix_out_paths));
1763 memset(spec->digout_paths, 0, sizeof(spec->digout_paths));
1764 memset(spec->input_paths, 0, sizeof(spec->input_paths));
1765 memset(spec->loopback_paths, 0, sizeof(spec->loopback_paths));
1766 memset(&spec->digin_path, 0, sizeof(spec->digin_path));
1770 /* fill hard-wired DACs first */
1774 mapped = map_singles(codec, cfg->line_outs,
1775 cfg->line_out_pins,
1776 spec->private_dac_nids,
1777 spec->out_paths);
1778 mapped |= map_singles(codec, cfg->hp_outs,
1779 cfg->hp_pins,
1780 spec->multiout.hp_out_nid,
1781 spec->hp_paths);
1782 mapped |= map_singles(codec, cfg->speaker_outs,
1783 cfg->speaker_pins,
1784 spec->multiout.extra_out_nid,
1785 spec->speaker_paths);
1786 if (!spec->no_multi_io &&
1787 fill_mio_first && cfg->line_outs == 1 &&
1788 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1789 err = fill_multi_ios(codec, cfg->line_out_pins[0], true);
1796 badness += try_assign_dacs(codec, cfg->line_outs, cfg->line_out_pins,
1797 spec->private_dac_nids, spec->out_paths,
1798 spec->main_out_badness);
1800 if (!spec->no_multi_io && fill_mio_first &&
1801 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1802 /* try to fill multi-io first */
1803 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1809 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
1810 err = try_assign_dacs(codec, cfg->hp_outs, cfg->hp_pins,
1811 spec->multiout.hp_out_nid,
1812 spec->hp_paths,
1813 spec->extra_out_badness);
1818 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1819 err = try_assign_dacs(codec, cfg->speaker_outs,
1820 cfg->speaker_pins,
1821 spec->multiout.extra_out_nid,
1822 spec->speaker_paths,
1823 spec->extra_out_badness);
1828 if (!spec->no_multi_io &&
1829 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1830 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1836 if (spec->mixer_nid) {
1837 spec->aamix_out_paths[0] =
1838 check_aamix_out_path(codec, spec->out_paths[0]);
1839 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1840 spec->aamix_out_paths[1] =
1841 check_aamix_out_path(codec, spec->hp_paths[0]);
1842 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1843 spec->aamix_out_paths[2] =
1844 check_aamix_out_path(codec, spec->speaker_paths[0]);
1847 if (!spec->no_multi_io &&
1848 cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
1849 if (count_multiio_pins(codec, cfg->hp_pins[0]) >= 2)
1850 spec->multi_ios = 1; /* give badness */
1852 /* re-count num_dacs and squash invalid entries */
1853 spec->multiout.num_dacs = 0;
1854 for (i = 0; i < cfg->line_outs; i++) {
1855 if (spec->private_dac_nids[i])
1856 spec->multiout.num_dacs++;
1858 memmove(spec->private_dac_nids + i,
1859 spec->private_dac_nids + i + 1,
1860 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
1861 spec->private_dac_nids[cfg->line_outs - 1] = 0;
1865 spec->ext_channel_count = spec->min_channel_count =
1866 spec->multiout.num_dacs * 2;
1868 if (spec->multi_ios == 2) {
1870 spec->private_dac_nids[spec->multiout.num_dacs++] =
1871 spec->multi_io[i].dac;
1872 } else if (spec->multi_ios) {
1873 spec->multi_ios = 0;
1877 if (spec->indep_hp && !indep_hp_possible(codec))
1880 /* re-fill the shared DAC for speaker / headphone */
1881 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1882 refill_shared_dacs(codec, cfg->hp_outs,
1883 spec->multiout.hp_out_nid,
1884 spec->hp_paths);
1885 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1886 refill_shared_dacs(codec, cfg->speaker_outs,
1887 spec->multiout.extra_out_nid,
1888 spec->speaker_paths);
1917 struct hda_gen_spec *spec = codec->spec;
1922 cfg->line_out_pins[0], cfg->line_out_pins[1],
1923 cfg->line_out_pins[2], cfg->line_out_pins[3],
1924 spec->multiout.dac_nids[0],
1925 spec->multiout.dac_nids[1],
1926 spec->multiout.dac_nids[2],
1927 spec->multiout.dac_nids[3],
1928 lo_type[cfg->line_out_type]);
1929 for (i = 0; i < cfg->line_outs; i++)
1930 print_nid_path_idx(codec, " out", spec->out_paths[i]);
1931 if (spec->multi_ios > 0)
1933 spec->multi_ios,
1934 spec->multi_io[0].pin, spec->multi_io[1].pin,
1935 spec->multi_io[0].dac, spec->multi_io[1].dac);
1936 for (i = 0; i < spec->multi_ios; i++)
1938 spec->out_paths[cfg->line_outs + i]);
1939 if (cfg->hp_outs)
1941 cfg->hp_pins[0], cfg->hp_pins[1],
1942 cfg->hp_pins[2], cfg->hp_pins[3],
1943 spec->multiout.hp_out_nid[0],
1944 spec->multiout.hp_out_nid[1],
1945 spec->multiout.hp_out_nid[2],
1946 spec->multiout.hp_out_nid[3]);
1947 for (i = 0; i < cfg->hp_outs; i++)
1948 print_nid_path_idx(codec, " hp ", spec->hp_paths[i]);
1949 if (cfg->speaker_outs)
1951 cfg->speaker_pins[0], cfg->speaker_pins[1],
1952 cfg->speaker_pins[2], cfg->speaker_pins[3],
1953 spec->multiout.extra_out_nid[0],
1954 spec->multiout.extra_out_nid[1],
1955 spec->multiout.extra_out_nid[2],
1956 spec->multiout.extra_out_nid[3]);
1957 for (i = 0; i < cfg->speaker_outs; i++)
1958 print_nid_path_idx(codec, " spk", spec->speaker_paths[i]);
1960 print_nid_path_idx(codec, " mix", spec->aamix_out_paths[i]);
1969 struct hda_gen_spec *spec = codec->spec;
1972 spec->num_all_dacs = 0;
1973 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
1977 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
1981 spec->all_dacs[spec->num_all_dacs++] = nid;
1987 struct hda_gen_spec *spec = codec->spec;
1988 struct auto_pin_cfg *cfg = &spec->autocfg;
1999 return -ENOMEM;
2010 cfg->line_out_type, fill_hardwired, fill_mio_first,
2030 if (cfg->speaker_outs > 0 &&
2031 cfg->line_out_type == AUTO_PIN_HP_OUT) {
2032 cfg->hp_outs = cfg->line_outs;
2033 memcpy(cfg->hp_pins, cfg->line_out_pins,
2034 sizeof(cfg->hp_pins));
2035 cfg->line_outs = cfg->speaker_outs;
2036 memcpy(cfg->line_out_pins, cfg->speaker_pins,
2037 sizeof(cfg->speaker_pins));
2038 cfg->speaker_outs = 0;
2039 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
2040 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
2044 if (cfg->hp_outs > 0 &&
2045 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
2046 cfg->speaker_outs = cfg->line_outs;
2047 memcpy(cfg->speaker_pins, cfg->line_out_pins,
2048 sizeof(cfg->speaker_pins));
2049 cfg->line_outs = cfg->hp_outs;
2050 memcpy(cfg->line_out_pins, cfg->hp_pins,
2051 sizeof(cfg->hp_pins));
2052 cfg->hp_outs = 0;
2053 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
2054 cfg->line_out_type = AUTO_PIN_HP_OUT;
2067 cfg->line_out_type, best_wired, best_mio);
2070 if (cfg->line_out_pins[0]) {
2072 path = snd_hda_get_path_from_idx(codec, spec->out_paths[0]);
2074 spec->vmaster_nid = look_for_out_vol_nid(codec, path);
2075 if (spec->vmaster_nid) {
2076 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2077 HDA_OUTPUT, spec->vmaster_tlv);
2078 if (spec->dac_min_mute)
2079 spec->vmaster_tlv[SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP] |= TLV_DB_SCALE_MUTE;
2084 if (spec->prefer_hp_amp || cfg->line_out_type == AUTO_PIN_HP_OUT)
2088 set_pin_targets(codec, cfg->line_outs, cfg->line_out_pins, val);
2089 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
2090 set_pin_targets(codec, cfg->hp_outs, cfg->hp_pins, PIN_HP);
2091 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
2092 val = spec->prefer_hp_amp ? PIN_HP : PIN_OUT;
2093 set_pin_targets(codec, cfg->speaker_outs,
2094 cfg->speaker_pins, val);
2098 if (spec->indep_hp && !indep_hp_possible(codec))
2099 spec->indep_hp = 0;
2109 struct hda_gen_spec *spec = codec->spec;
2112 noutputs = cfg->line_outs;
2113 if (spec->multi_ios > 0 && cfg->line_outs < 3)
2114 noutputs += spec->multi_ios;
2121 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
2205 struct hda_gen_spec *spec = codec->spec;
2206 return create_extra_outs(codec, spec->autocfg.hp_outs,
2207 spec->hp_paths,
2213 struct hda_gen_spec *spec = codec->spec;
2214 return create_extra_outs(codec, spec->autocfg.speaker_outs,
2215 spec->speaker_paths,
2235 struct hda_gen_spec *spec = codec->spec;
2236 ucontrol->value.enumerated.item[0] = spec->indep_hp_enabled;
2248 struct hda_gen_spec *spec = codec->spec;
2249 unsigned int select = ucontrol->value.enumerated.item[0];
2252 mutex_lock(&spec->pcm_mutex);
2253 if (spec->active_streams) {
2254 ret = -EBUSY;
2258 if (spec->indep_hp_enabled != select) {
2260 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
2261 dacp = &spec->private_dac_nids[0];
2263 dacp = &spec->multiout.hp_out_nid[0];
2266 if (spec->have_aamix_ctl) {
2267 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
2268 update_aamix_paths(codec, spec->aamix_mode,
2269 spec->out_paths[0],
2270 spec->aamix_out_paths[0],
2271 spec->autocfg.line_out_type);
2273 update_aamix_paths(codec, spec->aamix_mode,
2274 spec->hp_paths[0],
2275 spec->aamix_out_paths[1],
2279 spec->indep_hp_enabled = select;
2280 if (spec->indep_hp_enabled)
2283 *dacp = spec->alt_dac_nid;
2289 mutex_unlock(&spec->pcm_mutex);
2304 struct hda_gen_spec *spec = codec->spec;
2307 if (!spec->indep_hp)
2309 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
2310 dac = spec->multiout.dac_nids[0];
2312 dac = spec->multiout.hp_out_nid[0];
2314 spec->indep_hp = 0;
2318 spec->indep_hp_enabled = false;
2319 spec->alt_dac_nid = dac;
2321 return -ENOMEM;
2326 * channel mode enum control
2333 struct hda_gen_spec *spec = codec->spec;
2336 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2337 uinfo->count = 1;
2338 uinfo->value.enumerated.items = spec->multi_ios + 1;
2339 if (uinfo->value.enumerated.item > spec->multi_ios)
2340 uinfo->value.enumerated.item = spec->multi_ios;
2341 chs = uinfo->value.enumerated.item * 2 + spec->min_channel_count;
2342 sprintf(uinfo->value.enumerated.name, "%dch", chs);
2350 struct hda_gen_spec *spec = codec->spec;
2351 ucontrol->value.enumerated.item[0] =
2352 (spec->ext_channel_count - spec->min_channel_count) / 2;
2359 struct hda_gen_spec *spec = codec->spec;
2361 spec->out_paths[spec->autocfg.line_outs + idx]);
2371 return !spec->have_aamix_ctl || spec->aamix_mode;
2376 struct hda_gen_spec *spec = codec->spec;
2377 hda_nid_t nid = spec->multi_io[idx].pin;
2382 return -EINVAL;
2384 if (path->active == output)
2394 set_pin_target(codec, nid, spec->multi_io[idx].ctl_in, true);
2408 struct hda_gen_spec *spec = codec->spec;
2411 ch = ucontrol->value.enumerated.item[0];
2412 if (ch < 0 || ch > spec->multi_ios)
2413 return -EINVAL;
2414 if (ch == (spec->ext_channel_count - spec->min_channel_count) / 2)
2416 spec->ext_channel_count = ch * 2 + spec->min_channel_count;
2417 for (i = 0; i < spec->multi_ios; i++)
2419 spec->multiout.max_channels = max(spec->ext_channel_count,
2420 spec->const_channel_count);
2421 if (spec->need_dac_fix)
2422 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
2428 .name = "Channel Mode",
2436 struct hda_gen_spec *spec = codec->spec;
2438 if (spec->multi_ios > 0) {
2440 return -ENOMEM;
2455 struct hda_gen_spec *spec = codec->spec;
2456 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2464 struct hda_gen_spec *spec = codec->spec;
2475 if (out_type == AUTO_PIN_HP_OUT && spec->indep_hp_enabled &&
2476 mix_path->path[0] != spec->alt_dac_nid)
2490 /* re-initialize the output paths; only called from loopback_mixing_put() */
2494 struct hda_gen_spec *spec = codec->spec;
2501 snd_hda_activate_path(codec, path, path->active,
2502 spec->aamix_mode);
2510 struct hda_gen_spec *spec = codec->spec;
2511 const struct auto_pin_cfg *cfg = &spec->autocfg;
2512 unsigned int val = ucontrol->value.enumerated.item[0];
2514 if (val == spec->aamix_mode)
2516 spec->aamix_mode = val;
2518 update_aamix_paths(codec, val, spec->out_paths[0],
2519 spec->aamix_out_paths[0],
2520 cfg->line_out_type);
2521 update_aamix_paths(codec, val, spec->hp_paths[0],
2522 spec->aamix_out_paths[1],
2524 update_aamix_paths(codec, val, spec->speaker_paths[0],
2525 spec->aamix_out_paths[2],
2528 update_output_paths(codec, cfg->line_outs, spec->out_paths);
2529 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
2530 update_output_paths(codec, cfg->hp_outs, spec->hp_paths);
2531 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
2532 update_output_paths(codec, cfg->speaker_outs,
2533 spec->speaker_paths);
2548 struct hda_gen_spec *spec = codec->spec;
2550 if (!spec->mixer_nid)
2553 return -ENOMEM;
2554 spec->have_aamix_ctl = 1;
2564 /* for shared I/O, change the pin-control accordingly */
2567 struct hda_gen_spec *spec = codec->spec;
2572 pin = spec->hp_mic_pin;
2573 as_mic = spec->cur_mux[adc_mux] == spec->hp_mic_mux_idx;
2590 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
2591 const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
2598 if (!spec->hp_mic_jack_modes) {
2611 struct hda_gen_spec *spec = codec->spec;
2612 struct auto_pin_cfg *cfg = &spec->autocfg;
2616 if (!spec->hp_mic) {
2617 if (spec->suppress_hp_mic_detect)
2622 if (cfg->num_inputs > 1)
2624 else if (cfg->num_inputs == 1) {
2625 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2631 spec->hp_mic = 0; /* clear once */
2632 if (cfg->num_inputs >= AUTO_CFG_MAX_INS)
2636 if (cfg->line_out_type == AUTO_PIN_HP_OUT && cfg->line_outs > 0)
2637 nid = cfg->line_out_pins[0];
2638 else if (cfg->hp_outs > 0)
2639 nid = cfg->hp_pins[0];
2646 cfg->inputs[cfg->num_inputs].pin = nid;
2647 cfg->inputs[cfg->num_inputs].type = AUTO_PIN_MIC;
2648 cfg->inputs[cfg->num_inputs].is_headphone_mic = 1;
2649 cfg->num_inputs++;
2650 spec->hp_mic = 1;
2651 spec->hp_mic_pin = nid;
2652 /* we can't handle auto-mic together with HP-mic */
2653 spec->suppress_auto_mic = 1;
2678 hda_nid_t nid = kcontrol->private_value;
2680 ucontrol->value.enumerated.item[0] = 1;
2682 ucontrol->value.enumerated.item[0] = 0;
2690 hda_nid_t nid = kcontrol->private_value;
2693 val = ucontrol->value.enumerated.item[0] ? PIN_HP : PIN_OUT;
2709 struct hda_gen_spec *spec = codec->spec;
2713 snd_array_for_each(&spec->kctls, i, kctl) {
2714 if (!strcmp(kctl->name, name) && kctl->index == idx)
2723 struct hda_gen_spec *spec = codec->spec;
2726 snd_hda_get_pin_label(codec, pin, &spec->autocfg, name, name_len, &idx);
2735 struct hda_gen_spec *spec = codec->spec;
2736 if (spec->add_jack_modes) {
2747 struct hda_gen_spec *spec = codec->spec;
2752 if (pin == spec->hp_mic_pin)
2761 return -ENOMEM;
2762 knew->private_value = pin;
2825 hda_nid_t nid = kcontrol->private_value;
2831 strcpy(uinfo->value.enumerated.name,
2832 vref_texts[get_vref_idx(vref_caps, uinfo->value.enumerated.item)]);
2840 hda_nid_t nid = kcontrol->private_value;
2845 ucontrol->value.enumerated.item[0] = cvt_from_vref_idx(vref_caps, idx);
2853 hda_nid_t nid = kcontrol->private_value;
2859 if (idx == ucontrol->value.enumerated.item[0])
2863 val |= get_vref_idx(vref_caps, ucontrol->value.enumerated.item[0]);
2877 struct hda_gen_spec *spec = codec->spec;
2879 if (spec->add_jack_modes)
2886 struct hda_gen_spec *spec = codec->spec;
2891 if (pin == spec->hp_mic_pin)
2906 return -ENOMEM;
2907 knew->private_value = pin;
2918 hda_nid_t nid = kcontrol->private_value;
2924 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2925 uinfo->count = 1;
2926 uinfo->value.enumerated.items = out_jacks + in_jacks;
2927 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2928 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2929 idx = uinfo->value.enumerated.item;
2936 idx -= out_jacks;
2944 strcpy(uinfo->value.enumerated.name, text);
2973 hda_nid_t nid = kcontrol->private_value;
2974 ucontrol->value.enumerated.item[0] =
2983 hda_nid_t nid = kcontrol->private_value;
2989 idx = ucontrol->value.enumerated.item[0];
2999 idx -= out_jacks;
3023 struct hda_gen_spec *spec = codec->spec;
3029 return -ENOMEM;
3030 knew->private_value = pin;
3031 spec->hp_mic_jack_modes = 1;
3039 /* add the powersave loopback-list entry */
3044 list = snd_array_new(&spec->loopback_list);
3046 return -ENOMEM;
3047 list->nid = mix;
3048 list->dir = HDA_INPUT;
3049 list->idx = idx;
3050 spec->loopback.amplist = spec->loopback_list.list;
3097 struct hda_gen_spec *spec = codec->spec;
3107 return -EINVAL;
3109 spec->loopback_paths[input_idx] = snd_hda_get_path_idx(codec, path);
3111 idx = path->idx[path->depth - 1];
3116 path->ctls[NID_PATH_VOL_CTL] = mix_val;
3123 path->ctls[NID_PATH_MUTE_CTL] = mute_val;
3126 path->active = true;
3127 path->stream_enabled = true; /* no DAC/ADC involved */
3132 if (spec->mixer_nid != spec->mixer_merge_nid &&
3133 !spec->loopback_merge_path) {
3134 path = snd_hda_add_new_path(codec, spec->mixer_nid,
3135 spec->mixer_merge_nid, 0);
3137 print_nid_path(codec, "loopback-merge", path);
3138 path->active = true;
3139 path->pin_fixed = true; /* static route */
3140 path->stream_enabled = true; /* no DAC/ADC involved */
3141 spec->loopback_merge_path =
3158 struct hda_gen_spec *spec = codec->spec;
3160 hda_nid_t *adc_nids = spec->adc_nids;
3161 int max_nums = ARRAY_SIZE(spec->adc_nids);
3174 spec->num_adc_nids = nums;
3177 spec->num_all_adcs = nums;
3178 memcpy(spec->all_adcs, spec->adc_nids, nums * sizeof(hda_nid_t));
3184 * if needed, check whether dynamic ADC-switching is available
3188 struct hda_gen_spec *spec = codec->spec;
3189 struct hda_input_mux *imux = &spec->input_mux;
3195 for (n = 0; n < spec->num_adc_nids; n++) {
3196 for (i = 0; i < imux->num_items; i++) {
3197 if (!spec->input_paths[i][n])
3200 if (i >= imux->num_items) {
3207 /* check whether ADC-switch is possible */
3208 for (i = 0; i < imux->num_items; i++) {
3209 for (n = 0; n < spec->num_adc_nids; n++) {
3210 if (spec->input_paths[i][n]) {
3211 spec->dyn_adc_idx[i] = n;
3217 codec_dbg(codec, "enabling ADC switching\n");
3218 spec->dyn_adc_switch = 1;
3219 } else if (nums != spec->num_adc_nids) {
3222 for (n = 0; n < spec->num_adc_nids; n++) {
3226 spec->adc_nids[nums] = spec->adc_nids[n];
3227 for (i = 0; i < imux->num_items; i++) {
3229 spec->input_paths[i][nums]);
3230 spec->input_paths[i][nums] =
3231 spec->input_paths[i][n];
3232 spec->input_paths[i][n] = 0;
3237 spec->num_adc_nids = nums;
3240 if (imux->num_items == 1 ||
3241 (imux->num_items == 2 && spec->hp_mic)) {
3242 codec_dbg(codec, "reducing to a single ADC\n");
3243 spec->num_adc_nids = 1; /* reduce to a single ADC */
3247 if (!spec->dyn_adc_switch && spec->multi_cap_vol)
3248 spec->num_adc_nids = 1;
3258 struct hda_gen_spec *spec = codec->spec;
3259 struct hda_input_mux *imux = &spec->input_mux;
3260 int imux_idx = imux->num_items;
3266 hda_nid_t adc = spec->adc_nids[c];
3268 if (!is_reachable_path(codec, pin, adc))
3270 path = snd_hda_add_new_path(codec, pin, adc, anchor);
3274 spec->input_paths[imux_idx][c] =
3278 if (spec->hp_mic_pin == pin)
3279 spec->hp_mic_mux_idx = imux->num_items;
3280 spec->imux_pins[imux->num_items] = pin;
3283 if (spec->dyn_adc_switch)
3284 spec->dyn_adc_idx[imux_idx] = c;
3298 struct hda_gen_spec *spec = codec->spec;
3299 const struct auto_pin_cfg *cfg = &spec->autocfg;
3302 for (i = 0; i < cfg->num_inputs; i++) {
3303 hda_nid_t pin = cfg->inputs[i].pin;
3312 for (j = i - 1; j >= 0; j--) {
3313 if (spec->input_labels[j] &&
3314 !strcmp(spec->input_labels[j], label)) {
3315 idx = spec->input_label_idxs[j] + 1;
3320 spec->input_labels[i] = label;
3321 spec->input_label_idxs[i] = idx;
3327 #define CFG_IDX_MIX 99 /* a dummy cfg->input idx for stereo mix */
3331 struct hda_gen_spec *spec = codec->spec;
3332 const struct auto_pin_cfg *cfg = &spec->autocfg;
3333 hda_nid_t mixer = spec->mixer_nid;
3346 for (i = 0; i < cfg->num_inputs; i++) {
3349 pin = cfg->inputs[i].pin;
3354 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3356 if (pin != spec->hp_mic_pin &&
3363 spec->input_labels[i],
3364 spec->input_label_idxs[i],
3372 spec->input_labels[i], -mixer);
3376 if (spec->add_jack_modes) {
3384 if (mixer && spec->add_stereo_mix_input == HDA_HINT_STEREO_MIX_ENABLE) {
3390 spec->suppress_auto_mic = 1;
3401 /* get the input path specified by the given adc and imux indices */
3404 struct hda_gen_spec *spec = codec->spec;
3409 if (spec->dyn_adc_switch)
3410 adc_idx = spec->dyn_adc_idx[imux_idx];
3415 return snd_hda_get_path_from_idx(codec, spec->input_paths[imux_idx][adc_idx]);
3425 struct hda_gen_spec *spec = codec->spec;
3426 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
3433 struct hda_gen_spec *spec = codec->spec;
3435 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
3437 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
3445 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
3447 ucontrol->value.enumerated.item[0]);
3471 struct hda_gen_spec *spec = codec->spec;
3476 imux = &spec->input_mux;
3477 adc_idx = kcontrol->id.index;
3478 mutex_lock(&codec->control_mutex);
3479 for (i = 0; i < imux->num_items; i++) {
3481 if (!path || !path->ctls[type])
3483 kcontrol->private_value = path->ctls[type];
3492 mutex_unlock(&codec->control_mutex);
3493 if (err >= 0 && spec->cap_sync_hook)
3494 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3549 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
3551 if (depth >= path->depth)
3552 return -EINVAL;
3553 i = path->depth - depth - 1;
3554 nid = path->path[i];
3555 if (!path->ctls[NID_PATH_VOL_CTL]) {
3557 path->ctls[NID_PATH_VOL_CTL] =
3560 int idx = path->idx[i];
3561 if (!depth && codec->single_adc_amp)
3563 path->ctls[NID_PATH_VOL_CTL] =
3567 if (!path->ctls[NID_PATH_MUTE_CTL]) {
3569 path->ctls[NID_PATH_MUTE_CTL] =
3572 int idx = path->idx[i];
3573 if (!depth && codec->single_adc_amp)
3575 path->ctls[NID_PATH_MUTE_CTL] =
3585 struct hda_gen_spec *spec = codec->spec;
3586 struct auto_pin_cfg *cfg = &spec->autocfg;
3590 if (!spec->inv_dmic_split)
3592 for (i = 0; i < cfg->num_inputs; i++) {
3593 if (cfg->inputs[i].pin != nid)
3595 if (cfg->inputs[i].type != AUTO_PIN_MIC)
3608 struct hda_gen_spec *spec = codec->spec;
3615 if (spec->cap_sync_hook)
3616 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3625 struct hda_gen_spec *spec = codec->spec;
3644 return -ENOMEM;
3646 knew->put = cap_single_sw_put;
3647 if (spec->mic_mute_led)
3648 knew->access |= SNDRV_CTL_ELEM_ACCESS_MIC_LED;
3663 return -ENOMEM;
3665 knew->put = cap_single_sw_put;
3666 if (spec->mic_mute_led)
3667 knew->access |= SNDRV_CTL_ELEM_ACCESS_MIC_LED;
3691 struct hda_gen_spec *spec = codec->spec;
3697 return -ENOMEM;
3698 knew->index = idx;
3699 knew->private_value = vol_ctl;
3700 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
3705 return -ENOMEM;
3706 knew->index = idx;
3707 knew->private_value = sw_ctl;
3708 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
3709 if (spec->mic_mute_led)
3710 knew->access |= SNDRV_CTL_ELEM_ACCESS_MIC_LED;
3725 ctl = path->ctls[type];
3728 for (i = 0; i < idx - 1; i++) {
3730 if (path && path->ctls[type] == ctl)
3739 struct hda_gen_spec *spec = codec->spec;
3740 struct hda_input_mux *imux = &spec->input_mux;
3743 for (i = 0; i < imux->num_items; i++) {
3747 idx = imux->items[i].index;
3748 if (idx >= spec->autocfg.num_inputs)
3750 inv_dmic = is_inv_dmic_pin(codec, spec->imux_pins[i]);
3754 spec->input_labels[idx],
3755 spec->input_label_idxs[idx],
3768 struct hda_gen_spec *spec = codec->spec;
3769 struct hda_input_mux *imux = &spec->input_mux;
3772 if (spec->dyn_adc_switch)
3775 nums = spec->num_adc_nids;
3777 if (!spec->auto_mic && imux->num_items > 1) {
3783 return -ENOMEM;
3784 knew->count = nums;
3789 bool multi_cap_vol = spec->multi_cap_vol;
3794 for (i = 0; i < imux->num_items; i++) {
3801 vol = path->ctls[NID_PATH_VOL_CTL];
3802 else if (vol != path->ctls[NID_PATH_VOL_CTL]) {
3805 path->ctls[NID_PATH_VOL_CTL], HDA_INPUT))
3809 sw = path->ctls[NID_PATH_MUTE_CTL];
3810 else if (sw != path->ctls[NID_PATH_MUTE_CTL]) {
3813 path->ctls[NID_PATH_MUTE_CTL], HDA_INPUT))
3816 if (is_inv_dmic_pin(codec, spec->imux_pins[i]))
3865 if (depth >= path->depth - 1)
3867 nid = path->path[depth];
3872 path->idx[depth])) {
3873 val = HDA_COMPOSE_AMP_VAL(nid, 3, path->idx[depth],
3884 struct hda_gen_spec *spec = codec->spec;
3885 struct auto_pin_cfg *cfg = &spec->autocfg;
3886 struct hda_input_mux *imux = &spec->input_mux;
3889 if (!spec->num_adc_nids)
3892 for (i = 0; i < imux->num_items; i++) {
3898 idx = imux->items[i].index;
3899 if (idx >= imux->num_items)
3902 /* check only line-in and mic pins */
3903 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
3916 "%s Boost Volume", spec->input_labels[idx]);
3918 spec->input_label_idxs[idx], val))
3919 return -ENOMEM;
3921 path->ctls[NID_PATH_BOOST_CTL] = val;
3936 struct hda_gen_spec *spec = codec->spec;
3941 cdev = devm_kzalloc(&codec->core.dev, sizeof(*cdev), GFP_KERNEL);
3943 return -ENOMEM;
3945 cdev->name = micmute ? "hda::micmute" : "hda::mute";
3946 cdev->max_brightness = 1;
3947 cdev->default_trigger = micmute ? "audio-micmute" : "audio-mute";
3948 cdev->brightness_set_blocking = callback;
3949 cdev->flags = LED_CORE_SUSPENDRESUME;
3951 err = led_classdev_register(&codec->core.dev, cdev);
3954 spec->led_cdevs[idx] = cdev;
3959 * snd_hda_gen_add_mute_led_cdev - Create a LED classdev and enable as vmaster mute LED
3967 struct hda_gen_spec *spec = codec->spec;
3978 if (spec->vmaster_mute.hook)
3981 spec->vmaster_mute_led = 1;
3987 * snd_hda_gen_add_micmute_led_cdev - Create a LED classdev and enable as mic-mute LED
3996 * LED-trigger is set up.
4004 struct hda_gen_spec *spec = codec->spec;
4010 codec_warn(codec, "failed to create a mic-mute LED cdev\n");
4015 spec->mic_mute_led = 1;
4022 * parse digital I/Os and set up NIDs in BIOS auto-parse mode
4026 struct hda_gen_spec *spec = codec->spec;
4033 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4034 pin = spec->autocfg.dig_out_pins[i];
4042 path->active = true;
4043 path->pin_fixed = true; /* no jack detection */
4044 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
4047 spec->multiout.dig_out_nid = dig_nid;
4048 spec->dig_out_type = spec->autocfg.dig_out_type[0];
4050 spec->multiout.follower_dig_outs = spec->follower_dig_outs;
4051 if (nums >= ARRAY_SIZE(spec->follower_dig_outs) - 1)
4053 spec->follower_dig_outs[nums - 1] = dig_nid;
4058 if (spec->autocfg.dig_in_pin) {
4059 pin = spec->autocfg.dig_in_pin;
4069 path->active = true;
4070 path->pin_fixed = true; /* no jack */
4071 spec->dig_in_nid = dig_nid;
4072 spec->digin_path = snd_hda_get_path_idx(codec, path);
4091 struct hda_gen_spec *spec = codec->spec;
4095 imux = &spec->input_mux;
4096 if (!imux->num_items)
4099 if (idx >= imux->num_items)
4100 idx = imux->num_items - 1;
4101 if (spec->cur_mux[adc_idx] == idx)
4104 old_path = get_input_path(codec, adc_idx, spec->cur_mux[adc_idx]);
4107 if (old_path->active)
4110 spec->cur_mux[adc_idx] = idx;
4112 if (spec->hp_mic)
4115 if (spec->dyn_adc_switch)
4121 if (path->active)
4124 if (spec->cap_sync_hook)
4125 spec->cap_sync_hook(codec, NULL, NULL);
4131 * as terminals (either start- or endpoint)
4138 struct hda_gen_spec *spec = codec->spec;
4143 snd_array_for_each(&spec->paths, n, path) {
4144 if (!path->depth)
4146 if (path->path[0] == nid ||
4147 path->path[path->depth - 1] == nid) {
4148 bool pin_old = path->pin_enabled;
4149 bool stream_old = path->stream_enabled;
4152 path->pin_enabled = pin_state;
4154 path->stream_enabled = stream_state;
4155 if ((!path->pin_fixed && path->pin_enabled != pin_old)
4156 || path->stream_enabled != stream_old) {
4185 if (!codec->power_save_node)
4192 return set_path_power(codec, pin, on, -1);
4199 if (jack && jack->nid)
4201 set_pin_power_jack(codec, jack->nid, on));
4204 /* callback only doing power up -- called at first */
4211 /* callback only doing power down -- called at last */
4230 set_path_power(codec, pins[i], true, -1);
4239 struct hda_gen_spec *spec = codec->spec;
4240 struct auto_pin_cfg *cfg = &spec->autocfg;
4243 if (!codec->power_save_node)
4245 add_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins, on);
4246 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
4247 add_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins, on);
4248 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
4249 add_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins, on);
4250 for (i = 0; i < cfg->num_inputs; i++)
4251 add_pin_power_ctls(codec, 1, &cfg->inputs[i].pin, on);
4262 set_pin_power_jack(codec, pins[i], -1);
4268 struct hda_gen_spec *spec = codec->spec;
4269 struct auto_pin_cfg *cfg = &spec->autocfg;
4272 if (!codec->power_save_node)
4274 sync_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins);
4275 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
4276 sync_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins);
4277 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
4278 sync_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins);
4279 for (i = 0; i < cfg->num_inputs; i++)
4280 sync_pin_power_ctls(codec, 1, &cfg->inputs[i].pin);
4287 struct hda_gen_spec *spec = codec->spec;
4296 path = snd_array_new(&spec->paths);
4298 return -ENOMEM;
4300 path->depth = 2;
4301 path->path[0] = nid;
4302 path->path[1] = pins[i];
4303 path->active = true;
4311 struct hda_gen_spec *spec = codec->spec;
4312 struct auto_pin_cfg *cfg = &spec->autocfg;
4313 hda_nid_t nid = spec->beep_nid;
4316 if (!codec->power_save_node || !nid)
4318 err = add_fake_paths(codec, nid, cfg->line_outs, cfg->line_out_pins);
4321 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
4322 err = add_fake_paths(codec, nid, cfg->hp_outs, cfg->hp_pins);
4326 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
4327 err = add_fake_paths(codec, nid, cfg->speaker_outs,
4328 cfg->speaker_pins);
4338 set_path_power(beep->codec, beep->nid, -1, on);
4342 * snd_hda_gen_fix_pin_power - Fix the power of the given pin widget to D0
4348 struct hda_gen_spec *spec = codec->spec;
4351 path = snd_array_new(&spec->paths);
4353 return -ENOMEM;
4355 path->depth = 1;
4356 path->path[0] = pin;
4357 path->active = true;
4358 path->pin_fixed = true;
4359 path->stream_enabled = true;
4365 * Jack detections for HP auto-mute and mic-switch
4387 /* standard HP/line-out auto-mute helper */
4391 struct hda_gen_spec *spec = codec->spec;
4404 if (spec->auto_mute_via_amp) {
4411 mute_nid = get_amp_nid_(path->ctls[NID_PATH_MUTE_CTL]);
4415 spec->mute_bits |= (1ULL << mute_nid);
4417 spec->mute_bits &= ~(1ULL << mute_nid);
4423 if (spec->keep_vref_in_automute)
4438 if (codec->power_save_node) {
4442 set_path_power(codec, nid, on, -1);
4448 * snd_hda_gen_update_outputs - Toggle outputs muting
4455 struct hda_gen_spec *spec = codec->spec;
4463 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
4464 paths = spec->out_paths;
4466 paths = spec->hp_paths;
4467 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
4468 spec->autocfg.hp_pins, paths, spec->master_mute);
4470 if (!spec->automute_speaker)
4473 on = spec->hp_jack_present | spec->line_jack_present;
4474 on |= spec->master_mute;
4475 spec->speaker_muted = on;
4476 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4477 paths = spec->out_paths;
4479 paths = spec->speaker_paths;
4480 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
4481 spec->autocfg.speaker_pins, paths, on);
4483 /* toggle line-out mutes if needed, too */
4485 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
4486 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
4488 if (!spec->automute_lo)
4491 on = spec->hp_jack_present;
4492 on |= spec->master_mute;
4493 spec->line_out_muted = on;
4494 paths = spec->out_paths;
4495 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
4496 spec->autocfg.line_out_pins, paths, on);
4502 struct hda_gen_spec *spec = codec->spec;
4503 if (spec->automute_hook)
4504 spec->automute_hook(codec);
4508 /* sync the whole vmaster followers to reflect the new auto-mute status */
4509 if (spec->auto_mute_via_amp && !codec->bus->shutdown)
4510 snd_ctl_sync_vmaster(spec->vmaster_mute.sw_kctl, false);
4514 * snd_hda_gen_hp_automute - standard HP-automute helper
4521 struct hda_gen_spec *spec = codec->spec;
4522 hda_nid_t *pins = spec->autocfg.hp_pins;
4523 int num_pins = ARRAY_SIZE(spec->autocfg.hp_pins);
4525 /* No detection for the first HP jack during indep-HP mode */
4526 if (spec->indep_hp_enabled) {
4528 num_pins--;
4531 spec->hp_jack_present = detect_jacks(codec, num_pins, pins);
4532 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
4539 * snd_hda_gen_line_automute - standard line-out-automute helper
4546 struct hda_gen_spec *spec = codec->spec;
4548 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4551 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
4554 spec->line_jack_present =
4555 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
4556 spec->autocfg.line_out_pins);
4557 if (!spec->automute_speaker || !spec->detect_lo)
4564 * snd_hda_gen_mic_autoswitch - standard mic auto-switch helper
4571 struct hda_gen_spec *spec = codec->spec;
4574 if (!spec->auto_mic)
4577 for (i = spec->am_num_entries - 1; i > 0; i--) {
4578 hda_nid_t pin = spec->am_entry[i].pin;
4583 mux_select(codec, 0, spec->am_entry[i].idx);
4587 mux_select(codec, 0, spec->am_entry[0].idx);
4595 struct hda_gen_spec *spec = codec->spec;
4596 if (spec->hp_automute_hook)
4597 spec->hp_automute_hook(codec, jack);
4605 struct hda_gen_spec *spec = codec->spec;
4606 if (spec->line_automute_hook)
4607 spec->line_automute_hook(codec, jack);
4615 struct hda_gen_spec *spec = codec->spec;
4616 if (spec->mic_autoswitch_hook)
4617 spec->mic_autoswitch_hook(codec, jack);
4631 * Auto-Mute mode mixer enum support
4637 struct hda_gen_spec *spec = codec->spec;
4642 if (spec->automute_speaker_possible && spec->automute_lo_possible)
4651 struct hda_gen_spec *spec = codec->spec;
4653 if (spec->automute_speaker)
4655 if (spec->automute_lo)
4658 ucontrol->value.enumerated.item[0] = val;
4666 struct hda_gen_spec *spec = codec->spec;
4668 switch (ucontrol->value.enumerated.item[0]) {
4670 if (!spec->automute_speaker && !spec->automute_lo)
4672 spec->automute_speaker = 0;
4673 spec->automute_lo = 0;
4676 if (spec->automute_speaker_possible) {
4677 if (!spec->automute_lo && spec->automute_speaker)
4679 spec->automute_speaker = 1;
4680 spec->automute_lo = 0;
4681 } else if (spec->automute_lo_possible) {
4682 if (spec->automute_lo)
4684 spec->automute_lo = 1;
4686 return -EINVAL;
4689 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
4690 return -EINVAL;
4691 if (spec->automute_speaker && spec->automute_lo)
4693 spec->automute_speaker = 1;
4694 spec->automute_lo = 1;
4697 return -EINVAL;
4705 .name = "Auto-Mute Mode",
4713 struct hda_gen_spec *spec = codec->spec;
4716 return -ENOMEM;
4721 * Check the availability of HP/line-out auto-mute;
4726 struct hda_gen_spec *spec = codec->spec;
4727 struct auto_pin_cfg *cfg = &spec->autocfg;
4731 if (spec->suppress_auto_mute)
4734 if (cfg->hp_pins[0])
4736 if (cfg->line_out_pins[0])
4738 if (cfg->speaker_pins[0])
4743 if (!cfg->speaker_pins[0] &&
4744 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
4745 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4746 sizeof(cfg->speaker_pins));
4747 cfg->speaker_outs = cfg->line_outs;
4750 if (!cfg->hp_pins[0] &&
4751 cfg->line_out_type == AUTO_PIN_HP_OUT) {
4752 memcpy(cfg->hp_pins, cfg->line_out_pins,
4753 sizeof(cfg->hp_pins));
4754 cfg->hp_outs = cfg->line_outs;
4757 for (i = 0; i < cfg->hp_outs; i++) {
4758 hda_nid_t nid = cfg->hp_pins[i];
4761 codec_dbg(codec, "Enable HP auto-muting on NID 0x%x\n", nid);
4764 spec->detect_hp = 1;
4767 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
4768 if (cfg->speaker_outs)
4769 for (i = 0; i < cfg->line_outs; i++) {
4770 hda_nid_t nid = cfg->line_out_pins[i];
4773 codec_dbg(codec, "Enable Line-Out auto-muting on NID 0x%x\n", nid);
4776 spec->detect_lo = 1;
4778 spec->automute_lo_possible = spec->detect_hp;
4781 spec->automute_speaker_possible = cfg->speaker_outs &&
4782 (spec->detect_hp || spec->detect_lo);
4784 spec->automute_lo = spec->automute_lo_possible;
4785 spec->automute_speaker = spec->automute_speaker_possible;
4787 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
4796 /* check whether all auto-mic pins are valid; setup indices if OK */
4799 struct hda_gen_spec *spec = codec->spec;
4803 imux = &spec->input_mux;
4804 for (i = 0; i < spec->am_num_entries; i++) {
4805 spec->am_entry[i].idx =
4806 find_idx_in_nid_list(spec->am_entry[i].pin,
4807 spec->imux_pins, imux->num_items);
4808 if (spec->am_entry[i].idx < 0)
4813 for (i = 1; i < spec->am_num_entries; i++)
4815 spec->am_entry[i].pin,
4824 return (int)(a->attr - b->attr);
4828 * Check the availability of auto-mic switch;
4833 struct hda_gen_spec *spec = codec->spec;
4834 struct auto_pin_cfg *cfg = &spec->autocfg;
4838 if (spec->suppress_auto_mic)
4843 for (i = 0; i < cfg->num_inputs; i++) {
4844 hda_nid_t nid = cfg->inputs[i].pin;
4852 if (cfg->inputs[i].type != AUTO_PIN_MIC)
4858 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
4860 if (!spec->line_in_auto_switch &&
4861 cfg->inputs[i].type != AUTO_PIN_MIC)
4870 spec->am_entry[num_pins].pin = nid;
4871 spec->am_entry[num_pins].attr = attr;
4878 spec->am_num_entries = num_pins;
4882 sort(spec->am_entry, num_pins, sizeof(spec->am_entry[0]),
4888 spec->auto_mic = 1;
4889 spec->num_adc_nids = 1;
4890 spec->cur_mux[0] = spec->am_entry[0].idx;
4891 codec_dbg(codec, "Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
4892 spec->am_entry[0].pin,
4893 spec->am_entry[1].pin,
4894 spec->am_entry[2].pin);
4900 * snd_hda_gen_path_power_filter - power_filter hook to make inactive widgets
4910 struct hda_gen_spec *spec = codec->spec;
4912 if (!spec->power_down_unused && !codec->power_save_node)
4914 if (power_state != AC_PWRST_D0 || nid == codec->core.afg)
4944 * snd_hda_gen_stream_pm - Stream power management callback
4953 if (codec->power_save_node)
4954 set_path_power(codec, nid, -1, on);
4978 * snd_hda_gen_shutup_speakers - Forcibly mute the speaker outputs
4990 struct hda_gen_spec *spec = codec->spec;
4997 if (!snd_hdac_is_power_on(&codec->core))
5000 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) {
5001 paths = spec->out_paths;
5002 num_paths = spec->autocfg.line_outs;
5004 paths = spec->speaker_paths;
5005 num_paths = spec->autocfg.speaker_outs;
5012 for (p = 0; p < path->depth; p++)
5013 if (force_mute_output_path(codec, path->path[p]))
5022 * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and
5033 struct hda_gen_spec *spec = codec->spec;
5038 if (spec->vmaster_mute_led || spec->mic_mute_led)
5041 if (spec->mixer_nid && !spec->mixer_merge_nid)
5042 spec->mixer_merge_nid = spec->mixer_nid;
5044 if (cfg != &spec->autocfg) {
5045 spec->autocfg = *cfg;
5046 cfg = &spec->autocfg;
5049 if (!spec->main_out_badness)
5050 spec->main_out_badness = &hda_main_out_badness;
5051 if (!spec->extra_out_badness)
5052 spec->extra_out_badness = &hda_extra_out_badness;
5056 if (!cfg->line_outs) {
5057 if (cfg->dig_outs || cfg->dig_in_pin) {
5058 spec->multiout.max_channels = 2;
5059 spec->no_analog = 1;
5062 if (!cfg->num_inputs && !cfg->dig_in_pin)
5066 if (!spec->no_primary_hp &&
5067 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
5068 cfg->line_outs <= cfg->hp_outs) {
5070 cfg->speaker_outs = cfg->line_outs;
5071 memcpy(cfg->speaker_pins, cfg->line_out_pins,
5072 sizeof(cfg->speaker_pins));
5073 cfg->line_outs = cfg->hp_outs;
5074 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
5075 cfg->hp_outs = 0;
5076 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
5077 cfg->line_out_type = AUTO_PIN_HP_OUT;
5108 /* add power-down pin callbacks at first */
5111 spec->const_channel_count = spec->ext_channel_count;
5113 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
5114 spec->const_channel_count = max(spec->const_channel_count,
5115 cfg->speaker_outs * 2);
5116 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
5117 spec->const_channel_count = max(spec->const_channel_count,
5118 cfg->hp_outs * 2);
5119 spec->multiout.max_channels = max(spec->ext_channel_count,
5120 spec->const_channel_count);
5135 if (!spec->auto_mic && spec->mixer_nid &&
5136 spec->add_stereo_mix_input == HDA_HINT_STEREO_MIX_AUTO &&
5137 spec->input_mux.num_items > 1) {
5138 err = parse_capture_source(codec, spec->mixer_nid,
5139 CFG_IDX_MIX, spec->num_all_adcs,
5157 if (spec->hp_mic_pin &&
5158 (spec->auto_mic || spec->input_mux.num_items == 1 ||
5159 spec->add_jack_modes)) {
5160 err = create_hp_mic_jack_mode(codec, spec->hp_mic_pin);
5165 if (spec->add_jack_modes) {
5166 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
5167 err = create_out_jack_modes(codec, cfg->line_outs,
5168 cfg->line_out_pins);
5172 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
5173 err = create_out_jack_modes(codec, cfg->hp_outs,
5174 cfg->hp_pins);
5180 /* add power-up pin callbacks at last */
5184 if (spec->mixer_nid)
5185 mute_all_mixer_nid(codec, spec->mixer_nid);
5190 if (spec->power_down_unused || codec->power_save_node) {
5191 if (!codec->power_filter)
5192 codec->power_filter = snd_hda_gen_path_power_filter;
5193 if (!codec->patch_ops.stream_pm)
5194 codec->patch_ops.stream_pm = snd_hda_gen_stream_pm;
5197 if (!spec->no_analog && spec->beep_nid) {
5198 err = snd_hda_attach_beep_device(codec, spec->beep_nid);
5201 if (codec->beep && codec->power_save_node) {
5205 codec->beep->power_hook = beep_power_hook;
5230 * snd_hda_gen_build_controls - Build controls from the parsed results
5237 struct hda_gen_spec *spec = codec->spec;
5240 if (spec->kctls.used) {
5241 err = snd_hda_add_new_ctls(codec, spec->kctls.list);
5246 if (spec->multiout.dig_out_nid) {
5248 spec->multiout.dig_out_nid,
5249 spec->multiout.dig_out_nid,
5250 spec->pcm_rec[1]->pcm_type);
5253 if (!spec->no_analog) {
5255 &spec->multiout);
5258 spec->multiout.share_spdif = 1;
5261 if (spec->dig_in_nid) {
5262 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
5268 if (!spec->no_analog && !spec->suppress_vmaster &&
5271 spec->vmaster_tlv, follower_pfxs,
5276 if (!spec->no_analog && !spec->suppress_vmaster &&
5281 spec->vmaster_mute_led ?
5283 &spec->vmaster_mute.sw_kctl);
5286 if (spec->vmaster_mute.hook) {
5287 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute);
5288 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
5294 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
5312 struct hda_gen_spec *spec = codec->spec;
5313 if (spec->pcm_playback_hook)
5314 spec->pcm_playback_hook(hinfo, codec, substream, action);
5322 struct hda_gen_spec *spec = codec->spec;
5323 if (spec->pcm_capture_hook)
5324 spec->pcm_capture_hook(hinfo, codec, substream, action);
5334 struct hda_gen_spec *spec = codec->spec;
5337 mutex_lock(&spec->pcm_mutex);
5339 &spec->multiout, substream,
5342 spec->active_streams |= 1 << STREAM_MULTI_OUT;
5346 mutex_unlock(&spec->pcm_mutex);
5356 struct hda_gen_spec *spec = codec->spec;
5359 err = snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
5371 struct hda_gen_spec *spec = codec->spec;
5374 err = snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
5385 struct hda_gen_spec *spec = codec->spec;
5386 mutex_lock(&spec->pcm_mutex);
5387 spec->active_streams &= ~(1 << STREAM_MULTI_OUT);
5390 mutex_unlock(&spec->pcm_mutex);
5408 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
5418 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
5436 struct hda_gen_spec *spec = codec->spec;
5439 mutex_lock(&spec->pcm_mutex);
5440 if (spec->indep_hp && !spec->indep_hp_enabled)
5441 err = -EBUSY;
5443 spec->active_streams |= 1 << STREAM_INDEP_HP;
5446 mutex_unlock(&spec->pcm_mutex);
5454 struct hda_gen_spec *spec = codec->spec;
5455 mutex_lock(&spec->pcm_mutex);
5456 spec->active_streams &= ~(1 << STREAM_INDEP_HP);
5459 mutex_unlock(&spec->pcm_mutex);
5469 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
5479 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
5492 struct hda_gen_spec *spec = codec->spec;
5493 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
5502 struct hda_gen_spec *spec = codec->spec;
5503 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
5511 struct hda_gen_spec *spec = codec->spec;
5512 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
5519 struct hda_gen_spec *spec = codec->spec;
5520 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
5535 struct hda_gen_spec *spec = codec->spec;
5537 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
5548 struct hda_gen_spec *spec = codec->spec;
5551 spec->adc_nids[substream->number + 1]);
5639 * dynamic changing ADC PCM streams
5643 struct hda_gen_spec *spec = codec->spec;
5644 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
5646 if (spec->cur_adc && spec->cur_adc != new_adc) {
5647 /* stream is running, let's swap the current ADC */
5648 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
5649 spec->cur_adc = new_adc;
5651 spec->cur_adc_stream_tag, 0,
5652 spec->cur_adc_format);
5658 /* analog capture with dynamic dual-adc changes */
5665 struct hda_gen_spec *spec = codec->spec;
5666 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
5667 spec->cur_adc_stream_tag = stream_tag;
5668 spec->cur_adc_format = format;
5669 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
5678 struct hda_gen_spec *spec = codec->spec;
5679 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
5680 spec->cur_adc = 0;
5705 /* drop non-alnum chars after a space */
5715 /* copy PCM stream info from @default_str, and override non-NULL entries
5725 str->nid = nid;
5727 if (spec_str->substreams)
5728 str->substreams = spec_str->substreams;
5729 if (spec_str->channels_min)
5730 str->channels_min = spec_str->channels_min;
5731 if (spec_str->channels_max)
5732 str->channels_max = spec_str->channels_max;
5733 if (spec_str->rates)
5734 str->rates = spec_str->rates;
5735 if (spec_str->formats)
5736 str->formats = spec_str->formats;
5737 if (spec_str->maxbps)
5738 str->maxbps = spec_str->maxbps;
5743 * snd_hda_gen_build_pcms - build PCM streams based on the parsed results
5750 struct hda_gen_spec *spec = codec->spec;
5754 if (spec->no_analog)
5757 fill_pcm_stream_name(spec->stream_name_analog,
5758 sizeof(spec->stream_name_analog),
5759 " Analog", codec->core.chip_name);
5760 info = snd_hda_codec_pcm_new(codec, "%s", spec->stream_name_analog);
5762 return -ENOMEM;
5763 spec->pcm_rec[0] = info;
5765 if (spec->multiout.num_dacs > 0) {
5766 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5768 spec->stream_analog_playback,
5769 spec->multiout.dac_nids[0]);
5770 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
5771 spec->multiout.max_channels;
5772 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
5773 spec->autocfg.line_outs == 2)
5774 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
5777 if (spec->num_adc_nids) {
5778 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5779 (spec->dyn_adc_switch ?
5781 spec->stream_analog_capture,
5782 spec->adc_nids[0]);
5787 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
5788 fill_pcm_stream_name(spec->stream_name_digital,
5789 sizeof(spec->stream_name_digital),
5790 " Digital", codec->core.chip_name);
5792 spec->stream_name_digital);
5794 return -ENOMEM;
5795 codec->follower_dig_outs = spec->multiout.follower_dig_outs;
5796 spec->pcm_rec[1] = info;
5797 if (spec->dig_out_type)
5798 info->pcm_type = spec->dig_out_type;
5800 info->pcm_type = HDA_PCM_TYPE_SPDIF;
5801 if (spec->multiout.dig_out_nid)
5802 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5804 spec->stream_digital_playback,
5805 spec->multiout.dig_out_nid);
5806 if (spec->dig_in_nid)
5807 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5809 spec->stream_digital_capture,
5810 spec->dig_in_nid);
5813 if (spec->no_analog)
5816 /* If the use of more than one ADC is requested for the current
5817 * model, configure a second analog capture-only PCM.
5819 have_multi_adcs = (spec->num_adc_nids > 1) &&
5820 !spec->dyn_adc_switch && !spec->auto_mic;
5822 if (spec->alt_dac_nid || have_multi_adcs) {
5823 fill_pcm_stream_name(spec->stream_name_alt_analog,
5824 sizeof(spec->stream_name_alt_analog),
5825 " Alt Analog", codec->core.chip_name);
5827 spec->stream_name_alt_analog);
5829 return -ENOMEM;
5830 spec->pcm_rec[2] = info;
5831 if (spec->alt_dac_nid)
5832 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5834 spec->stream_analog_alt_playback,
5835 spec->alt_dac_nid);
5837 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5840 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5842 spec->stream_analog_alt_capture,
5843 spec->adc_nids[1]);
5844 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
5845 spec->num_adc_nids - 1;
5847 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5858 * Standard auto-parser initializations
5868 if (!path || !path->depth)
5870 pin = path->path[path->depth - 1];
5872 snd_hda_activate_path(codec, path, path->active,
5873 aamix_default(codec->spec));
5874 set_pin_eapd(codec, pin, path->active);
5880 struct hda_gen_spec *spec = codec->spec;
5883 for (i = 0; i < spec->autocfg.line_outs; i++)
5884 set_output_and_unmute(codec, spec->out_paths[i]);
5899 struct hda_gen_spec *spec = codec->spec;
5901 if (spec->autocfg.line_out_type != AUTO_PIN_HP_OUT)
5902 __init_extra_out(codec, spec->autocfg.hp_outs, spec->hp_paths);
5903 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT)
5904 __init_extra_out(codec, spec->autocfg.speaker_outs,
5905 spec->speaker_paths);
5908 /* initialize multi-io paths */
5911 struct hda_gen_spec *spec = codec->spec;
5914 for (i = 0; i < spec->multi_ios; i++) {
5915 hda_nid_t pin = spec->multi_io[i].pin;
5920 if (!spec->multi_io[i].ctl_in)
5921 spec->multi_io[i].ctl_in =
5923 snd_hda_activate_path(codec, path, path->active,
5930 struct hda_gen_spec *spec = codec->spec;
5932 if (!spec->have_aamix_ctl)
5936 update_aamix_paths(codec, spec->aamix_mode, spec->out_paths[0],
5937 spec->aamix_out_paths[0],
5938 spec->autocfg.line_out_type);
5939 update_aamix_paths(codec, spec->aamix_mode, spec->hp_paths[0],
5940 spec->aamix_out_paths[1],
5942 update_aamix_paths(codec, spec->aamix_mode, spec->speaker_paths[0],
5943 spec->aamix_out_paths[2],
5950 struct hda_gen_spec *spec = codec->spec;
5951 struct auto_pin_cfg *cfg = &spec->autocfg;
5954 for (i = 0; i < cfg->num_inputs; i++) {
5955 hda_nid_t nid = cfg->inputs[i].pin;
5960 if (spec->mixer_nid) {
5961 resume_path_from_idx(codec, spec->loopback_paths[i]);
5962 resume_path_from_idx(codec, spec->loopback_merge_path);
5967 /* initialize ADC paths */
5970 struct hda_gen_spec *spec = codec->spec;
5971 struct hda_input_mux *imux = &spec->input_mux;
5975 if (spec->dyn_adc_switch)
5978 nums = spec->num_adc_nids;
5981 for (i = 0; i < imux->num_items; i++) {
5984 bool active = path->active;
5985 if (i == spec->cur_mux[c])
5990 if (spec->hp_mic)
5994 if (spec->cap_sync_hook)
5995 spec->cap_sync_hook(codec, NULL, NULL);
6001 struct hda_gen_spec *spec = codec->spec;
6005 for (i = 0; i < spec->autocfg.dig_outs; i++)
6006 set_output_and_unmute(codec, spec->digout_paths[i]);
6007 pin = spec->autocfg.dig_in_pin;
6010 resume_path_from_idx(codec, spec->digin_path);
6014 /* clear unsol-event tags on unused pins; Conexant codecs seem to leave
6022 snd_array_for_each(&codec->init_pins, i, pin) {
6023 hda_nid_t nid = pin->nid;
6032 * snd_hda_gen_init - initialize the generic spec
6039 struct hda_gen_spec *spec = codec->spec;
6041 if (spec->init_hook)
6042 spec->init_hook(codec);
6044 if (!spec->skip_verbs)
6059 /* call init functions of standard auto-mute helpers */
6064 if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook)
6065 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6073 * snd_hda_gen_free - free the generic spec
6081 snd_hda_gen_spec_free(codec->spec);
6082 kfree(codec->spec);
6083 codec->spec = NULL;
6088 * snd_hda_gen_check_power_status - check the loopback power save state
6096 struct hda_gen_spec *spec = codec->spec;
6097 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
6116 * snd_hda_parse_generic_codec - Generic codec parser
6126 return -ENOMEM;
6128 codec->spec = spec;
6130 err = snd_hda_parse_pin_defcfg(codec, &spec->autocfg, NULL, 0);
6134 err = snd_hda_gen_parse_auto_config(codec, &spec->autocfg);
6138 codec->patch_ops = generic_patch_ops;
6159 MODULE_DESCRIPTION("Generic HD-audio codec parser");