Lines Matching full:codec
3 * Universal Interface for Intel High Definition Audio Codec
105 static void parse_user_hints(struct hda_codec *codec)
107 struct hda_gen_spec *spec = codec->spec;
110 val = snd_hda_get_bool_hint(codec, "jack_detect");
112 codec->no_jack_detect = !val;
113 val = snd_hda_get_bool_hint(codec, "inv_jack_detect");
115 codec->inv_jack_detect = !!val;
116 val = snd_hda_get_bool_hint(codec, "trigger_sense");
118 codec->no_trigger_sense = !val;
119 val = snd_hda_get_bool_hint(codec, "inv_eapd");
121 codec->inv_eapd = !!val;
122 val = snd_hda_get_bool_hint(codec, "pcm_format_first");
124 codec->pcm_format_first = !!val;
125 val = snd_hda_get_bool_hint(codec, "sticky_stream");
127 codec->no_sticky_stream = !val;
128 val = snd_hda_get_bool_hint(codec, "spdif_status_reset");
130 codec->spdif_status_reset = !!val;
131 val = snd_hda_get_bool_hint(codec, "pin_amp_workaround");
133 codec->pin_amp_workaround = !!val;
134 val = snd_hda_get_bool_hint(codec, "single_adc_amp");
136 codec->single_adc_amp = !!val;
137 val = snd_hda_get_bool_hint(codec, "power_save_node");
139 codec->power_save_node = !!val;
141 val = snd_hda_get_bool_hint(codec, "auto_mute");
144 val = snd_hda_get_bool_hint(codec, "auto_mic");
147 val = snd_hda_get_bool_hint(codec, "line_in_auto_switch");
150 val = snd_hda_get_bool_hint(codec, "auto_mute_via_amp");
153 val = snd_hda_get_bool_hint(codec, "need_dac_fix");
156 val = snd_hda_get_bool_hint(codec, "primary_hp");
159 val = snd_hda_get_bool_hint(codec, "multi_io");
162 val = snd_hda_get_bool_hint(codec, "multi_cap_vol");
165 val = snd_hda_get_bool_hint(codec, "inv_dmic_split");
168 val = snd_hda_get_bool_hint(codec, "indep_hp");
171 val = snd_hda_get_bool_hint(codec, "add_stereo_mix_input");
175 val = snd_hda_get_bool_hint(codec, "add_out_jack_modes");
178 val = snd_hda_get_bool_hint(codec, "add_in_jack_modes");
181 val = snd_hda_get_bool_hint(codec, "add_jack_modes");
184 val = snd_hda_get_bool_hint(codec, "power_down_unused");
187 val = snd_hda_get_bool_hint(codec, "add_hp_mic");
190 val = snd_hda_get_bool_hint(codec, "hp_mic_detect");
193 val = snd_hda_get_bool_hint(codec, "vmaster");
197 if (!snd_hda_get_int_hint(codec, "mixer_nid", &val))
205 #define update_pin_ctl(codec, pin, val) \
206 snd_hda_codec_write_cache(codec, pin, 0, \
210 static inline void restore_pin_ctl(struct hda_codec *codec, hda_nid_t pin)
212 update_pin_ctl(codec, pin, snd_hda_codec_get_pin_target(codec, pin));
216 static void set_pin_target(struct hda_codec *codec, hda_nid_t pin,
221 val = snd_hda_correct_pin_ctl(codec, pin, val);
222 snd_hda_codec_set_pin_target(codec, pin, val);
224 update_pin_ctl(codec, pin, val);
228 static void set_pin_targets(struct hda_codec *codec, int num_pins,
233 set_pin_target(codec, pins[i], val, false);
256 static struct nid_path *get_nid_path(struct hda_codec *codec,
260 struct hda_gen_spec *spec = codec->spec;
281 * @codec: the HDA codec
287 int snd_hda_get_path_idx(struct hda_codec *codec, struct nid_path *path)
289 struct hda_gen_spec *spec = codec->spec;
305 * @codec: the HDA codec
308 struct nid_path *snd_hda_get_path_from_idx(struct hda_codec *codec, int idx)
310 struct hda_gen_spec *spec = codec->spec;
319 static bool is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
321 struct hda_gen_spec *spec = codec->spec;
333 static bool is_reachable_path(struct hda_codec *codec,
338 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
345 static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
347 struct hda_gen_spec *spec = codec->spec;
360 static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
364 return is_ctl_used(codec, val, type);
367 static void print_nid_path(struct hda_codec *codec,
380 codec_dbg(codec, "%s path: depth=%d '%s'\n", pfx, path->depth, buf);
384 static bool __parse_nid_path(struct hda_codec *codec,
397 nums = snd_hda_get_conn_list(codec, to_nid, &conn);
404 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
405 is_dac_already_used(codec, conn[i]))
416 type = get_wcaps_type(get_wcaps(codec, conn[i]));
420 if (__parse_nid_path(codec, from_nid, conn[i],
429 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
438 * @codec: the HDA codec
454 static bool snd_hda_parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
458 if (__parse_nid_path(codec, from_nid, to_nid, anchor_nid, path, 1)) {
469 * @codec: the HDA codec
477 snd_hda_add_new_path(struct hda_codec *codec, hda_nid_t from_nid,
480 struct hda_gen_spec *spec = codec->spec;
483 if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid))
487 path = get_nid_path(codec, from_nid, to_nid, anchor_nid);
495 if (snd_hda_parse_nid_path(codec, from_nid, to_nid, anchor_nid, path))
504 static void invalidate_nid_path(struct hda_codec *codec, int idx)
506 struct nid_path *path = snd_hda_get_path_from_idx(codec, idx);
512 /* return a DAC if paired to the given pin by codec driver */
513 static hda_nid_t get_preferred_dac(struct hda_codec *codec, hda_nid_t pin)
515 struct hda_gen_spec *spec = codec->spec;
527 static hda_nid_t look_for_dac(struct hda_codec *codec, hda_nid_t pin,
530 struct hda_gen_spec *spec = codec->spec;
536 if (!nid || is_dac_already_used(codec, nid))
538 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
541 if (is_reachable_path(codec, nid, pin))
555 static bool same_amp_caps(struct hda_codec *codec, hda_nid_t nid1,
558 if (!(get_wcaps(codec, nid1) & (1 << (dir + 1))))
559 return !(get_wcaps(codec, nid2) & (1 << (dir + 1)));
560 return (query_amp_caps(codec, nid1, dir) ==
561 query_amp_caps(codec, nid2, dir));
565 static hda_nid_t look_for_out_mute_nid(struct hda_codec *codec,
571 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
574 nid_has_mute(codec, path->path[i], HDA_INPUT))
581 static hda_nid_t look_for_out_vol_nid(struct hda_codec *codec,
584 struct hda_gen_spec *spec = codec->spec;
591 if (nid_has_volume(codec, nid, HDA_OUTPUT))
602 static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
605 unsigned int caps = get_wcaps(codec, nid);
616 static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
619 unsigned int caps = get_wcaps(codec, nid);
630 static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
633 struct hda_gen_spec *spec = codec->spec;
634 int type = get_wcaps_type(get_wcaps(codec, nid));
638 if (nid == codec->core.afg)
644 if (codec->power_save_node) {
665 #define is_active_nid_for_any(codec, nid) \
666 is_active_nid(codec, nid, HDA_OUTPUT, -1)
669 static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
687 static bool is_stereo_amps(struct hda_codec *codec, hda_nid_t nid, int dir)
689 unsigned int wcaps = get_wcaps(codec, nid);
696 if (snd_hda_get_num_conns(codec, nid) != 1)
698 if (snd_hda_get_connections(codec, nid, &conn, 1) < 0)
700 return !!(get_wcaps(codec, conn) & AC_WCAP_STEREO);
704 static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
706 unsigned int caps = query_amp_caps(codec, nid, dir);
707 int val = get_amp_val_to_activate(codec, nid, dir, caps, false);
709 if (is_stereo_amps(codec, nid, dir))
710 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
712 snd_hda_codec_amp_init(codec, nid, 0, dir, idx, 0xff, val);
716 static int update_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx,
719 if (is_stereo_amps(codec, nid, dir))
720 return snd_hda_codec_amp_stereo(codec, nid, dir, idx,
723 return snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
730 static unsigned int get_amp_mask_to_modify(struct hda_codec *codec,
737 if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_MUTE_CTL))
741 if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
742 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
748 static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
754 caps = query_amp_caps(codec, nid, dir);
755 val = get_amp_val_to_activate(codec, nid, dir, caps, enable);
756 mask = get_amp_mask_to_modify(codec, nid, dir, idx_to_check, caps);
761 update_amp(codec, nid, dir, idx, mask, val);
764 static void check_and_activate_amp(struct hda_codec *codec, hda_nid_t nid,
769 if (!enable && is_active_nid(codec, nid, dir, idx_to_check))
771 activate_amp(codec, nid, dir, idx, idx_to_check, enable);
774 static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
778 init_amp(codec, nid, HDA_OUTPUT, 0);
779 check_and_activate_amp(codec, nid, HDA_OUTPUT, 0, 0, enable);
782 static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
785 struct hda_gen_spec *spec = codec->spec;
791 nums = snd_hda_get_conn_list(codec, nid, &conn);
794 type = get_wcaps_type(get_wcaps(codec, nid));
796 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
803 init_amp(codec, nid, HDA_INPUT, n);
814 activate_amp(codec, nid, HDA_INPUT, n, n, false);
818 check_and_activate_amp(codec, nid, HDA_INPUT, n, idx, enable);
823 static hda_nid_t path_power_update(struct hda_codec *codec,
832 if (!(get_wcaps(codec, nid) & AC_WCAP_POWER))
834 if (nid == codec->core.afg)
836 if (!allow_powerdown || is_active_nid_for_any(codec, nid))
840 power = snd_hda_codec_read(codec, nid, 0,
843 snd_hda_codec_write(codec, nid, 0,
854 snd_hdac_regmap_sync_node(&codec->core, nid);
862 static void sync_power_state_change(struct hda_codec *codec, hda_nid_t nid)
866 snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
872 * @codec: the HDA codec
879 void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
882 struct hda_gen_spec *spec = codec->spec;
888 if (enable && (spec->power_down_unused || codec->power_save_node))
889 path_power_update(codec, path, codec->power_save_node);
895 snd_hda_codec_write_cache(codec, nid, 0,
898 if (has_amp_in(codec, path, i))
899 activate_amp_in(codec, path, i, enable, add_aamix);
900 if (has_amp_out(codec, path, i))
901 activate_amp_out(codec, path, i, enable);
907 static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path)
909 struct hda_gen_spec *spec = codec->spec;
911 if (!(spec->power_down_unused || codec->power_save_node) || path->active)
913 sync_power_state_change(codec, path_power_update(codec, path, true));
917 static void set_pin_eapd(struct hda_codec *codec, hda_nid_t pin, bool enable)
919 struct hda_gen_spec *spec = codec->spec;
921 !(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD))
925 if (codec->inv_eapd)
927 snd_hda_codec_write_cache(codec, pin, 0,
933 static void resume_path_from_idx(struct hda_codec *codec, int path_idx)
935 struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
937 snd_hda_activate_path(codec, path, path->active, false);
1020 static int add_vol_ctl(struct hda_codec *codec, const char *pfx, int cidx,
1030 return __add_pb_vol_ctrl(codec->spec, HDA_CTL_WIDGET_VOL, pfx, cidx, val);
1034 static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
1040 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
1046 static int add_stereo_vol(struct hda_codec *codec, const char *pfx, int cidx,
1049 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
1050 return add_vol_ctl(codec, pfx, cidx, chs, path);
1056 static int add_sw_ctl(struct hda_codec *codec, const char *pfx, int cidx,
1070 int nums = snd_hda_get_num_conns(codec, nid);
1076 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
1079 static int add_stereo_sw(struct hda_codec *codec, const char *pfx,
1082 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
1083 return add_sw_ctl(codec, pfx, cidx, chs, path);
1090 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1091 struct hda_gen_spec *spec = codec->spec;
1117 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1121 guard(mutex)(&codec->control_mutex);
1132 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1138 guard(mutex)(&codec->control_mutex);
1154 static bool path_has_mixer(struct hda_codec *codec, int path_idx, int ctl_type)
1156 struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
1165 static const char *get_line_out_pfx(struct hda_codec *codec, int ch,
1168 struct hda_gen_spec *spec = codec->spec;
1173 !codec->force_pin_prefix &&
1181 !codec->force_pin_prefix &&
1195 !path_has_mixer(codec, spec->hp_paths[0], ctl_type))
1207 !path_has_mixer(codec, spec->speaker_paths[0], ctl_type))
1222 spk_lo_shared = !path_has_mixer(codec,
1225 hp_lo_shared = !path_has_mixer(codec, spec->hp_paths[0], ctl_type);
1283 static int assign_out_path_ctls(struct hda_codec *codec, struct nid_path *path)
1285 struct hda_gen_spec *spec = codec->spec;
1297 nid = look_for_out_vol_nid(codec, path);
1302 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
1308 nid = look_for_out_mute_nid(codec, path);
1310 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
1312 nid_has_mute(codec, nid, HDA_OUTPUT))
1316 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
1346 static hda_nid_t get_primary_out(struct hda_codec *codec, int idx)
1348 struct hda_gen_spec *spec = codec->spec;
1360 static inline hda_nid_t try_dac(struct hda_codec *codec,
1363 return is_reachable_path(codec, dac, pin) ? dac : 0;
1367 static int try_assign_dacs(struct hda_codec *codec, int num_outs,
1372 struct hda_gen_spec *spec = codec->spec;
1385 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1387 badness += assign_out_path_ctls(codec, path);
1392 dacs[i] = get_preferred_dac(codec, pin);
1394 if (is_dac_already_used(codec, dacs[i]))
1401 dacs[i] = look_for_dac(codec, pin, false);
1405 if (is_reachable_path(codec, dacs[j], pin)) {
1408 invalidate_nid_path(codec, path_idx[j]);
1417 dac = try_dac(codec, get_primary_out(codec, i), pin);
1419 dac = try_dac(codec, dacs[0], pin);
1421 dac = try_dac(codec, get_primary_out(codec, i), pin);
1429 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
1439 path = snd_hda_add_new_path(codec, dac, pin, -spec->mixer_nid);
1442 path = snd_hda_add_new_path(codec, dac, pin, 0);
1448 /* print_nid_path(codec, "output", path); */
1450 path_idx[i] = snd_hda_get_path_idx(codec, path);
1451 badness += assign_out_path_ctls(codec, path);
1459 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
1461 struct hda_gen_spec *spec = codec->spec;
1467 if (!nid || is_dac_already_used(codec, nid))
1469 if (is_reachable_path(codec, nid, pin)) {
1479 static bool can_be_multiio_pin(struct hda_codec *codec,
1484 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1489 caps = snd_hda_query_pin_caps(codec, nid);
1496 static int count_multiio_pins(struct hda_codec *codec, hda_nid_t reference_pin)
1498 struct hda_gen_spec *spec = codec->spec;
1500 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1509 if (can_be_multiio_pin(codec, location,
1525 static int fill_multi_ios(struct hda_codec *codec,
1529 struct hda_gen_spec *spec = codec->spec;
1532 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1541 num_pins = count_multiio_pins(codec, reference_pin);
1552 if (!can_be_multiio_pin(codec, location, nid))
1562 dac = get_dac_if_single(codec, nid);
1564 dac = look_for_dac(codec, nid, false);
1569 path = snd_hda_add_new_path(codec, dac, nid,
1575 /* print_nid_path(codec, "multiio", path); */
1579 snd_hda_get_path_idx(codec, path);
1603 path = snd_hda_get_path_from_idx(codec, spec->out_paths[cfg->line_outs + i]);
1604 badness += assign_out_path_ctls(codec, path);
1611 static bool map_singles(struct hda_codec *codec, int outs,
1614 struct hda_gen_spec *spec = codec->spec;
1622 dac = get_dac_if_single(codec, pins[i]);
1625 path = snd_hda_add_new_path(codec, dac, pins[i],
1628 path = snd_hda_add_new_path(codec, dac, pins[i], 0);
1632 /* print_nid_path(codec, "output", path); */
1634 path_idx[i] = snd_hda_get_path_idx(codec, path);
1647 static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
1649 struct hda_gen_spec *spec = codec->spec;
1653 path = snd_hda_get_path_from_idx(codec, path_idx);
1660 path = snd_hda_add_new_path(codec, dac, pin, spec->mixer_nid);
1671 path = snd_hda_add_new_path(codec, dac, pin,
1676 /* print_nid_path(codec, "output-aamix", path); */
1679 return snd_hda_get_path_idx(codec, path);
1683 static bool indep_hp_possible(struct hda_codec *codec)
1685 struct hda_gen_spec *spec = codec->spec;
1694 path = snd_hda_get_path_from_idx(codec, idx);
1706 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
1711 path = snd_hda_get_path_from_idx(codec, spec->speaker_paths[i]);
1722 static void refill_shared_dacs(struct hda_codec *codec, int num_outs,
1731 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1739 static int fill_and_eval_dacs(struct hda_codec *codec,
1743 struct hda_gen_spec *spec = codec->spec;
1772 mapped = map_singles(codec, cfg->line_outs,
1776 mapped |= map_singles(codec, cfg->hp_outs,
1780 mapped |= map_singles(codec, cfg->speaker_outs,
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,
1801 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1808 err = try_assign_dacs(codec, cfg->hp_outs, cfg->hp_pins,
1817 err = try_assign_dacs(codec, cfg->speaker_outs,
1828 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1836 check_aamix_out_path(codec, spec->out_paths[0]);
1839 check_aamix_out_path(codec, spec->hp_paths[0]);
1842 check_aamix_out_path(codec, spec->speaker_paths[0]);
1847 if (count_multiio_pins(codec, cfg->hp_pins[0]) >= 2)
1875 if (spec->indep_hp && !indep_hp_possible(codec))
1880 refill_shared_dacs(codec, cfg->hp_outs,
1884 refill_shared_dacs(codec, cfg->speaker_outs,
1895 codec_dbg(codec, fmt, ##__VA_ARGS__)
1898 do { if (0) codec_dbg(codec, fmt, ##__VA_ARGS__); } while (0)
1902 static inline void print_nid_path_idx(struct hda_codec *codec,
1907 path = snd_hda_get_path_from_idx(codec, idx);
1909 print_nid_path(codec, pfx, path);
1912 static void debug_show_configs(struct hda_codec *codec,
1915 struct hda_gen_spec *spec = codec->spec;
1928 print_nid_path_idx(codec, " out", spec->out_paths[i]);
1935 print_nid_path_idx(codec, " mio",
1946 print_nid_path_idx(codec, " hp ", spec->hp_paths[i]);
1956 print_nid_path_idx(codec, " spk", spec->speaker_paths[i]);
1958 print_nid_path_idx(codec, " mix", spec->aamix_out_paths[i]);
1961 #define debug_show_configs(codec, cfg) /* NOP */
1964 /* find all available DACs of the codec */
1965 static void fill_all_dac_nids(struct hda_codec *codec)
1967 struct hda_gen_spec *spec = codec->spec;
1972 for_each_hda_codec_node(nid, codec) {
1973 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
1976 codec_err(codec, "Too many DACs!\n");
1983 static int parse_output_paths(struct hda_codec *codec)
1985 struct hda_gen_spec *spec = codec->spec;
2001 badness = fill_and_eval_dacs(codec, fill_hardwired,
2008 debug_show_configs(codec, cfg);
2060 fill_and_eval_dacs(codec, best_wired, best_mio);
2064 debug_show_configs(codec, cfg);
2068 path = snd_hda_get_path_from_idx(codec, spec->out_paths[0]);
2070 spec->vmaster_nid = look_for_out_vol_nid(codec, path);
2072 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2084 set_pin_targets(codec, cfg->line_outs, cfg->line_out_pins, val);
2086 set_pin_targets(codec, cfg->hp_outs, cfg->hp_pins, PIN_HP);
2089 set_pin_targets(codec, cfg->speaker_outs,
2094 if (spec->indep_hp && !indep_hp_possible(codec))
2101 static int create_multi_out_ctls(struct hda_codec *codec,
2104 struct hda_gen_spec *spec = codec->spec;
2116 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
2120 name = get_line_out_pfx(codec, i, &index, NID_PATH_VOL_CTL);
2123 err = add_vol_ctl(codec, "Center", 0, 1, path);
2126 err = add_vol_ctl(codec, "LFE", 0, 2, path);
2130 err = add_stereo_vol(codec, name, index, path);
2135 name = get_line_out_pfx(codec, i, &index, NID_PATH_MUTE_CTL);
2137 err = add_sw_ctl(codec, "Center", 0, 1, path);
2140 err = add_sw_ctl(codec, "LFE", 0, 2, path);
2144 err = add_stereo_sw(codec, name, index, path);
2152 static int create_extra_out(struct hda_codec *codec, int path_idx,
2158 path = snd_hda_get_path_from_idx(codec, path_idx);
2161 err = add_stereo_vol(codec, pfx, cidx, path);
2164 err = add_stereo_sw(codec, pfx, cidx, path);
2171 static int create_extra_outs(struct hda_codec *codec, int num_pins,
2191 err = create_extra_out(codec, paths[i], name, idx);
2198 static int create_hp_out_ctls(struct hda_codec *codec)
2200 struct hda_gen_spec *spec = codec->spec;
2201 return create_extra_outs(codec, spec->autocfg.hp_outs,
2206 static int create_speaker_out_ctls(struct hda_codec *codec)
2208 struct hda_gen_spec *spec = codec->spec;
2209 return create_extra_outs(codec, spec->autocfg.speaker_outs,
2218 static void call_hp_automute(struct hda_codec *codec,
2229 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2230 struct hda_gen_spec *spec = codec->spec;
2235 static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
2242 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2243 struct hda_gen_spec *spec = codec->spec;
2261 update_aamix_paths(codec, spec->aamix_mode,
2266 update_aamix_paths(codec, spec->aamix_mode,
2278 call_hp_automute(codec, NULL);
2293 static int create_indep_hp_ctls(struct hda_codec *codec)
2295 struct hda_gen_spec *spec = codec->spec;
2323 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2324 struct hda_gen_spec *spec = codec->spec;
2340 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2341 struct hda_gen_spec *spec = codec->spec;
2348 get_multiio_path(struct hda_codec *codec, int idx)
2350 struct hda_gen_spec *spec = codec->spec;
2351 return snd_hda_get_path_from_idx(codec,
2355 static void update_automute_all(struct hda_codec *codec);
2365 static int set_multi_io(struct hda_codec *codec, int idx, bool output)
2367 struct hda_gen_spec *spec = codec->spec;
2371 path = get_multiio_path(codec, idx);
2379 set_pin_target(codec, nid, PIN_OUT, true);
2380 snd_hda_activate_path(codec, path, true, aamix_default(spec));
2381 set_pin_eapd(codec, nid, true);
2383 set_pin_eapd(codec, nid, false);
2384 snd_hda_activate_path(codec, path, false, aamix_default(spec));
2385 set_pin_target(codec, nid, spec->multi_io[idx].ctl_in, true);
2386 path_power_down_sync(codec, path);
2390 update_automute_all(codec);
2398 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2399 struct hda_gen_spec *spec = codec->spec;
2409 set_multi_io(codec, i, i < ch);
2425 static int create_multi_channel_mode(struct hda_codec *codec)
2427 struct hda_gen_spec *spec = codec->spec;
2445 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2446 struct hda_gen_spec *spec = codec->spec;
2451 static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
2455 struct hda_gen_spec *spec = codec->spec;
2458 nomix_path = snd_hda_get_path_from_idx(codec, nomix_path_idx);
2459 mix_path = snd_hda_get_path_from_idx(codec, mix_path_idx);
2471 snd_hda_activate_path(codec, nomix_path, false, true);
2472 snd_hda_activate_path(codec, mix_path, true, true);
2473 path_power_down_sync(codec, nomix_path);
2475 snd_hda_activate_path(codec, mix_path, false, false);
2476 snd_hda_activate_path(codec, nomix_path, true, false);
2477 path_power_down_sync(codec, mix_path);
2482 static void update_output_paths(struct hda_codec *codec, int num_outs,
2485 struct hda_gen_spec *spec = codec->spec;
2490 path = snd_hda_get_path_from_idx(codec, paths[i]);
2492 snd_hda_activate_path(codec, path, path->active,
2500 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2501 struct hda_gen_spec *spec = codec->spec;
2509 update_aamix_paths(codec, val, spec->out_paths[0],
2512 update_aamix_paths(codec, val, spec->hp_paths[0],
2515 update_aamix_paths(codec, val, spec->speaker_paths[0],
2519 update_output_paths(codec, cfg->line_outs, spec->out_paths);
2521 update_output_paths(codec, cfg->hp_outs, spec->hp_paths);
2523 update_output_paths(codec, cfg->speaker_outs,
2537 static int create_loopback_mixing_ctl(struct hda_codec *codec)
2539 struct hda_gen_spec *spec = codec->spec;
2553 static void call_update_outputs(struct hda_codec *codec);
2556 static void update_hp_mic(struct hda_codec *codec, int adc_mux, bool force)
2558 struct hda_gen_spec *spec = codec->spec;
2567 val = snd_hda_codec_get_pin_target(codec, pin);
2577 val = snd_hda_get_default_vref(codec, pin);
2578 /* if the HP pin doesn't support VREF and the codec driver gives an
2583 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
2585 snd_hda_set_pin_ctl_cache(codec, vref_pin,
2594 set_pin_target(codec, pin, val, true);
2595 call_hp_automute(codec, NULL);
2600 static int create_hp_mic(struct hda_codec *codec)
2602 struct hda_gen_spec *spec = codec->spec;
2616 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2634 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2645 codec_dbg(codec, "Enable shared I/O jack on NID 0x%x\n", nid);
2653 static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin);
2668 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2670 if (snd_hda_codec_get_pin_target(codec, nid) == PIN_HP)
2680 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2685 if (snd_hda_codec_get_pin_target(codec, nid) == val)
2687 snd_hda_set_pin_ctl_cache(codec, nid, val);
2698 static bool find_kctl_name(struct hda_codec *codec, const char *name, int idx)
2700 struct hda_gen_spec *spec = codec->spec;
2711 static void get_jack_mode_name(struct hda_codec *codec, hda_nid_t pin,
2714 struct hda_gen_spec *spec = codec->spec;
2717 snd_hda_get_pin_label(codec, pin, &spec->autocfg, name, name_len, &idx);
2720 for (; find_kctl_name(codec, name, idx); idx++)
2724 static int get_out_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2726 struct hda_gen_spec *spec = codec->spec;
2728 unsigned int pincap = snd_hda_query_pin_caps(codec, pin);
2735 static int create_out_jack_modes(struct hda_codec *codec, int num_pins,
2738 struct hda_gen_spec *spec = codec->spec;
2745 if (get_out_jack_num_items(codec, pin) > 1) {
2748 get_jack_mode_name(codec, pin, name, sizeof(name));
2772 static unsigned int get_vref_caps(struct hda_codec *codec, hda_nid_t pin)
2776 pincap = snd_hda_query_pin_caps(codec, pin);
2815 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2817 unsigned int vref_caps = get_vref_caps(codec, nid);
2830 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2832 unsigned int vref_caps = get_vref_caps(codec, nid);
2835 idx = snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_VREFEN;
2843 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2845 unsigned int vref_caps = get_vref_caps(codec, nid);
2848 val = snd_hda_codec_get_pin_target(codec, nid);
2855 snd_hda_set_pin_ctl_cache(codec, nid, val);
2866 static int get_in_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2868 struct hda_gen_spec *spec = codec->spec;
2871 nitems = hweight32(get_vref_caps(codec, pin));
2875 static int create_in_jack_mode(struct hda_codec *codec, hda_nid_t pin)
2877 struct hda_gen_spec *spec = codec->spec;
2886 defcfg = snd_hda_codec_get_pincfg(codec, pin);
2891 if (get_in_jack_num_items(codec, pin) <= 1)
2894 get_jack_mode_name(codec, pin, name, sizeof(name));
2908 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2910 int out_jacks = get_out_jack_num_items(codec, nid);
2911 int in_jacks = get_in_jack_num_items(codec, nid);
2929 unsigned int vref_caps = get_vref_caps(codec, nid);
2939 static int get_cur_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t nid)
2941 int out_jacks = get_out_jack_num_items(codec, nid);
2942 int in_jacks = get_in_jack_num_items(codec, nid);
2943 unsigned int val = snd_hda_codec_get_pin_target(codec, nid);
2952 unsigned int vref_caps = get_vref_caps(codec, nid);
2963 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2966 get_cur_hp_mic_jack_mode(codec, nid);
2973 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2975 int out_jacks = get_out_jack_num_items(codec, nid);
2976 int in_jacks = get_in_jack_num_items(codec, nid);
2979 oldval = get_cur_hp_mic_jack_mode(codec, nid);
2992 unsigned int vref_caps = get_vref_caps(codec, nid);
2993 val = snd_hda_codec_get_pin_target(codec, nid);
2997 val = snd_hda_get_default_vref(codec, nid) | PIN_IN;
2999 snd_hda_set_pin_ctl_cache(codec, nid, val);
3000 call_hp_automute(codec, NULL);
3012 static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin)
3014 struct hda_gen_spec *spec = codec->spec;
3048 static bool look_for_mix_leaf_ctls(struct hda_codec *codec, hda_nid_t mix_nid,
3056 idx = snd_hda_get_conn_index(codec, mix_nid, pin, true);
3061 if (nid_has_volume(codec, mix_nid, HDA_INPUT))
3063 if (nid_has_mute(codec, mix_nid, HDA_INPUT))
3069 num_conns = snd_hda_get_conn_list(codec, mix_nid, &list);
3073 if (!*mix_val && nid_has_volume(codec, nid, HDA_OUTPUT) &&
3074 !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_VOL_CTL))
3076 if (!*mute_val && nid_has_mute(codec, nid, HDA_OUTPUT) &&
3077 !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_MUTE_CTL))
3084 static int new_analog_input(struct hda_codec *codec, int input_idx,
3088 struct hda_gen_spec *spec = codec->spec;
3093 if (!look_for_mix_leaf_ctls(codec, mix_nid, pin, &mix_val, &mute_val))
3096 path = snd_hda_add_new_path(codec, pin, mix_nid, 0);
3099 print_nid_path(codec, "loopback", path);
3100 spec->loopback_paths[input_idx] = snd_hda_get_path_idx(codec, path);
3125 path = snd_hda_add_new_path(codec, spec->mixer_nid,
3128 print_nid_path(codec, "loopback-merge", path);
3133 snd_hda_get_path_idx(codec, path);
3140 static int is_input_pin(struct hda_codec *codec, hda_nid_t nid)
3142 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
3146 /* Parse the codec tree and retrieve ADCs */
3147 static int fill_adc_nids(struct hda_codec *codec)
3149 struct hda_gen_spec *spec = codec->spec;
3155 for_each_hda_codec_node(nid, codec) {
3156 unsigned int caps = get_wcaps(codec, nid);
3177 static int check_dyn_adc_switch(struct hda_codec *codec)
3179 struct hda_gen_spec *spec = codec->spec;
3208 codec_dbg(codec, "enabling ADC switching\n");
3219 invalidate_nid_path(codec,
3233 codec_dbg(codec, "reducing to a single ADC\n");
3245 static int parse_capture_source(struct hda_codec *codec, hda_nid_t pin,
3249 struct hda_gen_spec *spec = codec->spec;
3259 if (!is_reachable_path(codec, pin, adc))
3261 path = snd_hda_add_new_path(codec, pin, adc, anchor);
3264 print_nid_path(codec, "input", path);
3266 snd_hda_get_path_idx(codec, path);
3272 snd_hda_add_imux_item(codec, imux, label, cfg_idx, NULL);
3287 static int fill_input_pin_labels(struct hda_codec *codec)
3289 struct hda_gen_spec *spec = codec->spec;
3298 if (!is_input_pin(codec, pin))
3301 label = hda_get_autocfg_input_label(codec, cfg, i);
3320 static int create_input_ctls(struct hda_codec *codec)
3322 struct hda_gen_spec *spec = codec->spec;
3329 num_adcs = fill_adc_nids(codec);
3333 err = fill_input_pin_labels(codec);
3341 if (!is_input_pin(codec, pin))
3346 val |= snd_hda_get_default_vref(codec, pin);
3348 !snd_hda_codec_get_pin_target(codec, pin))
3349 set_pin_target(codec, pin, val, false);
3352 if (is_reachable_path(codec, pin, mixer)) {
3353 err = new_analog_input(codec, i, pin,
3362 err = parse_capture_source(codec, pin, i, num_adcs,
3368 err = create_in_jack_mode(codec, pin);
3376 err = parse_capture_source(codec, mixer, CFG_IDX_MIX, num_adcs,
3393 static struct nid_path *get_input_path(struct hda_codec *codec, int adc_idx, int imux_idx)
3395 struct hda_gen_spec *spec = codec->spec;
3406 return snd_hda_get_path_from_idx(codec, spec->input_paths[imux_idx][adc_idx]);
3409 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3415 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3416 struct hda_gen_spec *spec = codec->spec;
3423 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3424 struct hda_gen_spec *spec = codec->spec;
3435 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3437 return mux_select(codec, adc_idx,
3461 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3462 struct hda_gen_spec *spec = codec->spec;
3469 scoped_guard(mutex, &codec->control_mutex) {
3471 path = get_input_path(codec, adc_idx, i);
3483 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3533 static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
3545 if (nid_has_volume(codec, nid, HDA_OUTPUT))
3548 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
3550 if (!depth && codec->single_adc_amp)
3557 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3560 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
3562 if (!depth && codec->single_adc_amp)
3572 static bool is_inv_dmic_pin(struct hda_codec *codec, hda_nid_t nid)
3574 struct hda_gen_spec *spec = codec->spec;
3586 val = snd_hda_codec_get_pincfg(codec, nid);
3596 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3597 struct hda_gen_spec *spec = codec->spec;
3605 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3610 static int add_single_cap_ctl(struct hda_codec *codec, const char *label,
3614 struct hda_gen_spec *spec = codec->spec;
3662 static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx,
3667 err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl, inv_dmic);
3670 err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl, inv_dmic);
3677 static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx,
3680 struct hda_gen_spec *spec = codec->spec;
3705 static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type)
3711 path = get_input_path(codec, 0, idx);
3718 path = get_input_path(codec, 0, i);
3726 static int create_multi_cap_vol_ctl(struct hda_codec *codec)
3728 struct hda_gen_spec *spec = codec->spec;
3739 inv_dmic = is_inv_dmic_pin(codec, spec->imux_pins[i]);
3742 err = add_single_cap_ctl(codec,
3746 get_first_cap_ctl(codec, i, type),
3755 static int create_capture_mixers(struct hda_codec *codec)
3757 struct hda_gen_spec *spec = codec->spec;
3785 path = get_input_path(codec, n, i);
3788 parse_capvol_in_path(codec, path);
3793 if (!same_amp_caps(codec, vol,
3801 if (!same_amp_caps(codec, sw,
3805 if (is_inv_dmic_pin(codec, spec->imux_pins[i]))
3810 err = create_single_cap_vol_ctl(codec, n, vol, sw,
3813 err = create_bind_cap_vol_ctl(codec, n, vol, sw);
3815 err = create_multi_cap_vol_ctl(codec);
3828 static bool check_boost_vol(struct hda_codec *codec, hda_nid_t nid,
3833 if (!nid_has_volume(codec, nid, dir) ||
3834 is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
3835 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
3838 step = (query_amp_caps(codec, nid, dir) & AC_AMPCAP_STEP_SIZE)
3846 static unsigned int look_for_boost_amp(struct hda_codec *codec,
3857 if (depth && check_boost_vol(codec, nid, HDA_OUTPUT, 0)) {
3860 } else if (check_boost_vol(codec, nid, HDA_INPUT,
3871 static int parse_mic_boost(struct hda_codec *codec)
3873 struct hda_gen_spec *spec = codec->spec;
3895 path = get_input_path(codec, 0, i);
3899 val = look_for_boost_amp(codec, path);
3920 static int create_mute_led_cdev(struct hda_codec *codec,
3925 struct hda_gen_spec *spec = codec->spec;
3930 cdev = devm_kzalloc(&codec->core.dev, sizeof(*cdev), GFP_KERNEL);
3940 err = led_classdev_register(&codec->core.dev, cdev);
3949 * @codec: the HDA codec
3952 int snd_hda_gen_add_mute_led_cdev(struct hda_codec *codec,
3956 struct hda_gen_spec *spec = codec->spec;
3960 err = create_mute_led_cdev(codec, callback, false);
3962 codec_warn(codec, "failed to create a mute LED cdev\n");
3968 codec_err(codec, "vmaster hook already present before cdev!\n");
3977 * @codec: the HDA codec
3980 * Called from the codec drivers for offering the mic mute LED controls.
3989 int snd_hda_gen_add_micmute_led_cdev(struct hda_codec *codec,
3993 struct hda_gen_spec *spec = codec->spec;
3997 err = create_mute_led_cdev(codec, callback, true);
3999 codec_warn(codec, "failed to create a mic-mute LED cdev\n");
4013 static void parse_digital(struct hda_codec *codec)
4015 struct hda_gen_spec *spec = codec->spec;
4024 dig_nid = look_for_dac(codec, pin, true);
4027 path = snd_hda_add_new_path(codec, dig_nid, pin, 0);
4030 print_nid_path(codec, "digout", path);
4033 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
4034 set_pin_target(codec, pin, PIN_OUT, false);
4049 for_each_hda_codec_node(dig_nid, codec) {
4050 unsigned int wcaps = get_wcaps(codec, dig_nid);
4055 path = snd_hda_add_new_path(codec, pin, dig_nid, 0);
4057 print_nid_path(codec, "digin", path);
4061 spec->digin_path = snd_hda_get_path_idx(codec, path);
4062 set_pin_target(codec, pin, PIN_IN, false);
4074 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur);
4077 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
4080 struct hda_gen_spec *spec = codec->spec;
4093 old_path = get_input_path(codec, adc_idx, spec->cur_mux[adc_idx]);
4097 snd_hda_activate_path(codec, old_path, false, false);
4102 update_hp_mic(codec, adc_idx, false);
4105 dyn_adc_pcm_resetup(codec, idx);
4107 path = get_input_path(codec, adc_idx, idx);
4112 snd_hda_activate_path(codec, path, true, false);
4114 spec->cap_sync_hook(codec, NULL, NULL);
4115 path_power_down_sync(codec, old_path);
4124 static hda_nid_t set_path_power(struct hda_codec *codec, hda_nid_t nid,
4127 struct hda_gen_spec *spec = codec->spec;
4146 last = path_power_update(codec, path, true);
4156 static bool detect_pin_state(struct hda_codec *codec, hda_nid_t pin)
4158 if (!is_jack_detectable(codec, pin))
4160 return snd_hda_jack_detect_state(codec, pin) != HDA_JACK_NOT_PRESENT;
4169 static hda_nid_t set_pin_power_jack(struct hda_codec *codec, hda_nid_t pin,
4174 if (!codec->power_save_node)
4177 on = detect_pin_state(codec, pin);
4181 return set_path_power(codec, pin, on, -1);
4184 static void pin_power_callback(struct hda_codec *codec,
4189 sync_power_state_change(codec,
4190 set_pin_power_jack(codec, jack->nid, on));
4194 static void pin_power_up_callback(struct hda_codec *codec,
4197 pin_power_callback(codec, jack, true);
4201 static void pin_power_down_callback(struct hda_codec *codec,
4204 pin_power_callback(codec, jack, false);
4208 static void add_pin_power_ctls(struct hda_codec *codec, int num_pins,
4216 if (is_jack_detectable(codec, pins[i]))
4217 snd_hda_jack_detect_enable_callback(codec, pins[i], cb);
4219 set_path_power(codec, pins[i], true, -1);
4226 static void add_all_pin_power_ctls(struct hda_codec *codec, bool on)
4228 struct hda_gen_spec *spec = codec->spec;
4232 if (!codec->power_save_node)
4234 add_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins, on);
4236 add_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins, on);
4238 add_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins, on);
4240 add_pin_power_ctls(codec, 1, &cfg->inputs[i].pin, on);
4244 static void sync_pin_power_ctls(struct hda_codec *codec, int num_pins,
4250 if (is_jack_detectable(codec, pins[i]))
4251 set_pin_power_jack(codec, pins[i], -1);
4255 static void sync_all_pin_power_ctls(struct hda_codec *codec)
4257 struct hda_gen_spec *spec = codec->spec;
4261 if (!codec->power_save_node)
4263 sync_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins);
4265 sync_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins);
4267 sync_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins);
4269 sync_pin_power_ctls(codec, 1, &cfg->inputs[i].pin);
4273 static int add_fake_paths(struct hda_codec *codec, hda_nid_t nid,
4276 struct hda_gen_spec *spec = codec->spec;
4283 if (get_nid_path(codec, nid, pins[i], 0))
4298 static int add_fake_beep_paths(struct hda_codec *codec)
4300 struct hda_gen_spec *spec = codec->spec;
4305 if (!codec->power_save_node || !nid)
4307 err = add_fake_paths(codec, nid, cfg->line_outs, cfg->line_out_pins);
4311 err = add_fake_paths(codec, nid, cfg->hp_outs, cfg->hp_pins);
4316 err = add_fake_paths(codec, nid, cfg->speaker_outs,
4327 set_path_power(beep->codec, beep->nid, -1, on);
4332 * @codec: the HDA codec
4335 int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin)
4337 struct hda_gen_spec *spec = codec->spec;
4358 static bool detect_jacks(struct hda_codec *codec, int num_pins, const hda_nid_t *pins)
4368 if (snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_IN_EN)
4370 if (snd_hda_jack_detect_state(codec, nid) == HDA_JACK_PRESENT)
4377 static void do_automute(struct hda_codec *codec, int num_pins, const hda_nid_t *pins,
4380 struct hda_gen_spec *spec = codec->spec;
4389 oldval = snd_hda_codec_get_pin_target(codec, nid);
4397 path = snd_hda_get_path_from_idx(codec, paths[i]);
4423 update_pin_ctl(codec, nid, val);
4426 set_pin_eapd(codec, nid, !mute);
4427 if (codec->power_save_node) {
4430 on = detect_pin_state(codec, nid);
4431 set_path_power(codec, nid, on, -1);
4438 * @codec: the HDA codec
4442 void snd_hda_gen_update_outputs(struct hda_codec *codec)
4444 struct hda_gen_spec *spec = codec->spec;
4456 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
4469 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
4484 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
4489 static void call_update_outputs(struct hda_codec *codec)
4491 struct hda_gen_spec *spec = codec->spec;
4493 spec->automute_hook(codec);
4495 snd_hda_gen_update_outputs(codec);
4498 if (spec->auto_mute_via_amp && !codec->bus->shutdown)
4504 * @codec: the HDA codec
4507 void snd_hda_gen_hp_automute(struct hda_codec *codec,
4510 struct hda_gen_spec *spec = codec->spec;
4520 spec->hp_jack_present = detect_jacks(codec, num_pins, pins);
4523 call_update_outputs(codec);
4529 * @codec: the HDA codec
4532 void snd_hda_gen_line_automute(struct hda_codec *codec,
4535 struct hda_gen_spec *spec = codec->spec;
4544 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
4548 call_update_outputs(codec);
4554 * @codec: the HDA codec
4557 void snd_hda_gen_mic_autoswitch(struct hda_codec *codec,
4560 struct hda_gen_spec *spec = codec->spec;
4569 if (snd_hda_codec_get_pin_target(codec, pin) & AC_PINCTL_OUT_EN)
4571 if (snd_hda_jack_detect_state(codec, pin) == HDA_JACK_PRESENT) {
4572 mux_select(codec, 0, spec->am_entry[i].idx);
4576 mux_select(codec, 0, spec->am_entry[0].idx);
4581 static void call_hp_automute(struct hda_codec *codec,
4584 struct hda_gen_spec *spec = codec->spec;
4586 spec->hp_automute_hook(codec, jack);
4588 snd_hda_gen_hp_automute(codec, jack);
4591 static void call_line_automute(struct hda_codec *codec,
4594 struct hda_gen_spec *spec = codec->spec;
4596 spec->line_automute_hook(codec, jack);
4598 snd_hda_gen_line_automute(codec, jack);
4601 static void call_mic_autoswitch(struct hda_codec *codec,
4604 struct hda_gen_spec *spec = codec->spec;
4606 spec->mic_autoswitch_hook(codec, jack);
4608 snd_hda_gen_mic_autoswitch(codec, jack);
4612 static void update_automute_all(struct hda_codec *codec)
4614 call_hp_automute(codec, NULL);
4615 call_line_automute(codec, NULL);
4616 call_mic_autoswitch(codec, NULL);
4625 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4626 struct hda_gen_spec *spec = codec->spec;
4639 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4640 struct hda_gen_spec *spec = codec->spec;
4654 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4655 struct hda_gen_spec *spec = codec->spec;
4688 call_update_outputs(codec);
4700 static int add_automute_mode_enum(struct hda_codec *codec)
4702 struct hda_gen_spec *spec = codec->spec;
4713 static int check_auto_mute_availability(struct hda_codec *codec)
4715 struct hda_gen_spec *spec = codec->spec;
4748 if (!is_jack_detectable(codec, nid))
4750 codec_dbg(codec, "Enable HP auto-muting on NID 0x%x\n", nid);
4751 snd_hda_jack_detect_enable_callback(codec, nid,
4760 if (!is_jack_detectable(codec, nid))
4762 codec_dbg(codec, "Enable Line-Out auto-muting on NID 0x%x\n", nid);
4763 snd_hda_jack_detect_enable_callback(codec, nid,
4778 err = add_automute_mode_enum(codec);
4786 static bool auto_mic_check_imux(struct hda_codec *codec)
4788 struct hda_gen_spec *spec = codec->spec;
4803 snd_hda_jack_detect_enable_callback(codec,
4820 static int check_auto_mic_availability(struct hda_codec *codec)
4822 struct hda_gen_spec *spec = codec->spec;
4835 attr = snd_hda_codec_get_pincfg(codec, nid);
4852 if (!is_jack_detectable(codec, nid))
4874 if (!auto_mic_check_imux(codec))
4880 codec_dbg(codec, "Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
4891 * @codec: the HDA codec
4895 unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
4899 struct hda_gen_spec *spec = codec->spec;
4901 if (!spec->power_down_unused && !codec->power_save_node)
4903 if (power_state != AC_PWRST_D0 || nid == codec->core.afg)
4905 if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER)
4907 if (is_active_nid_for_any(codec, nid))
4914 static void mute_all_mixer_nid(struct hda_codec *codec, hda_nid_t mix)
4920 nums = snd_hda_get_conn_list(codec, mix, &conn);
4921 has_amp = nid_has_mute(codec, mix, HDA_INPUT);
4924 update_amp(codec, mix, HDA_INPUT, i,
4926 else if (nid_has_volume(codec, conn[i], HDA_OUTPUT))
4927 update_amp(codec, conn[i], HDA_OUTPUT, 0,
4934 * @codec: the HDA codec
4940 void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on)
4942 if (codec->power_save_node)
4943 set_path_power(codec, nid, -1, on);
4948 static bool force_mute_output_path(struct hda_codec *codec, hda_nid_t nid)
4952 if (!nid_has_mute(codec, nid, HDA_OUTPUT))
4954 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4955 snd_hda_codec_amp_read(codec, nid, 1, HDA_OUTPUT, 0) &
4960 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4968 * @codec: the HDA codec
4977 bool snd_hda_gen_shutup_speakers(struct hda_codec *codec)
4979 struct hda_gen_spec *spec = codec->spec;
4986 if (!snd_hdac_is_power_on(&codec->core))
4998 path = snd_hda_get_path_from_idx(codec, paths[i]);
5002 if (force_mute_output_path(codec, path->path[p]))
5013 * @codec: the HDA codec
5019 int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
5022 struct hda_gen_spec *spec = codec->spec;
5025 parse_user_hints(codec);
5043 fill_all_dac_nids(codec);
5069 err = parse_output_paths(codec);
5072 err = create_multi_channel_mode(codec);
5075 err = create_multi_out_ctls(codec, cfg);
5078 err = create_hp_out_ctls(codec);
5081 err = create_speaker_out_ctls(codec);
5084 err = create_indep_hp_ctls(codec);
5087 err = create_loopback_mixing_ctl(codec);
5090 err = create_hp_mic(codec);
5093 err = create_input_ctls(codec);
5098 add_all_pin_power_ctls(codec, false);
5111 err = check_auto_mute_availability(codec);
5115 err = check_dyn_adc_switch(codec);
5119 err = check_auto_mic_availability(codec);
5127 err = parse_capture_source(codec, spec->mixer_nid,
5135 err = create_capture_mixers(codec);
5139 err = parse_mic_boost(codec);
5149 err = create_hp_mic_jack_mode(codec, spec->hp_mic_pin);
5156 err = create_out_jack_modes(codec, cfg->line_outs,
5162 err = create_out_jack_modes(codec, cfg->hp_outs,
5170 add_all_pin_power_ctls(codec, true);
5174 mute_all_mixer_nid(codec, spec->mixer_nid);
5177 parse_digital(codec);
5179 if (spec->power_down_unused || codec->power_save_node) {
5180 if (!codec->power_filter)
5181 codec->power_filter = snd_hda_gen_path_power_filter;
5185 err = snd_hda_attach_beep_device(codec, spec->beep_nid);
5188 if (codec->beep && codec->power_save_node) {
5189 err = add_fake_beep_paths(codec);
5192 codec->beep->power_hook = beep_power_hook;
5218 * @codec: the HDA codec
5222 int snd_hda_gen_build_controls(struct hda_codec *codec)
5224 struct hda_gen_spec *spec = codec->spec;
5228 err = snd_hda_add_new_ctls(codec, spec->kctls.list);
5234 err = snd_hda_create_dig_out_ctls(codec,
5241 err = snd_hda_create_spdif_share_sw(codec,
5249 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
5256 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
5257 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
5264 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
5265 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
5274 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute);
5281 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
5295 struct hda_codec *codec,
5299 struct hda_gen_spec *spec = codec->spec;
5301 spec->pcm_playback_hook(hinfo, codec, substream, action);
5305 struct hda_codec *codec,
5309 struct hda_gen_spec *spec = codec->spec;
5311 spec->pcm_capture_hook(hinfo, codec, substream, action);
5318 struct hda_codec *codec,
5321 struct hda_gen_spec *spec = codec->spec;
5325 err = snd_hda_multi_out_analog_open(codec,
5332 call_pcm_playback_hook(hinfo, codec, substream,
5338 struct hda_codec *codec,
5343 struct hda_gen_spec *spec = codec->spec;
5346 err = snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
5349 call_pcm_playback_hook(hinfo, codec, substream,
5355 struct hda_codec *codec,
5358 struct hda_gen_spec *spec = codec->spec;
5361 err = snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
5363 call_pcm_playback_hook(hinfo, codec, substream,
5369 struct hda_codec *codec,
5372 struct hda_gen_spec *spec = codec->spec;
5376 call_pcm_playback_hook(hinfo, codec, substream,
5382 struct hda_codec *codec,
5385 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_OPEN);
5390 struct hda_codec *codec,
5395 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
5396 call_pcm_capture_hook(hinfo, codec, substream,
5402 struct hda_codec *codec,
5405 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
5406 call_pcm_capture_hook(hinfo, codec, substream,
5412 struct hda_codec *codec,
5415 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLOSE);
5420 struct hda_codec *codec,
5423 struct hda_gen_spec *spec = codec->spec;
5431 call_pcm_playback_hook(hinfo, codec, substream,
5437 struct hda_codec *codec,
5440 struct hda_gen_spec *spec = codec->spec;
5444 call_pcm_playback_hook(hinfo, codec, substream,
5450 struct hda_codec *codec,
5455 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
5456 call_pcm_playback_hook(hinfo, codec, substream,
5462 struct hda_codec *codec,
5465 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
5466 call_pcm_playback_hook(hinfo, codec, substream,
5475 struct hda_codec *codec,
5478 struct hda_gen_spec *spec = codec->spec;
5479 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
5483 struct hda_codec *codec,
5488 struct hda_gen_spec *spec = codec->spec;
5489 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
5494 struct hda_codec *codec,
5497 struct hda_gen_spec *spec = codec->spec;
5498 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
5502 struct hda_codec *codec,
5505 struct hda_gen_spec *spec = codec->spec;
5506 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
5516 struct hda_codec *codec,
5521 struct hda_gen_spec *spec = codec->spec;
5523 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
5525 call_pcm_capture_hook(hinfo, codec, substream,
5531 struct hda_codec *codec,
5534 struct hda_gen_spec *spec = codec->spec;
5536 snd_hda_codec_cleanup_stream(codec,
5538 call_pcm_capture_hook(hinfo, codec, substream,
5627 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
5629 struct hda_gen_spec *spec = codec->spec;
5634 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
5636 snd_hda_codec_setup_stream(codec, new_adc,
5646 struct hda_codec *codec,
5651 struct hda_gen_spec *spec = codec->spec;
5655 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
5656 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_PREPARE);
5661 struct hda_codec *codec,
5664 struct hda_gen_spec *spec = codec->spec;
5665 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
5667 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLEANUP);
5730 * @codec: the HDA codec
5734 int snd_hda_gen_build_pcms(struct hda_codec *codec)
5736 struct hda_gen_spec *spec = codec->spec;
5745 " Analog", codec->core.chip_name);
5746 info = snd_hda_codec_pcm_new(codec, "%s", spec->stream_name_analog);
5776 " Digital", codec->core.chip_name);
5777 info = snd_hda_codec_pcm_new(codec, "%s",
5781 codec->follower_dig_outs = spec->multiout.follower_dig_outs;
5811 " Alt Analog", codec->core.chip_name);
5812 info = snd_hda_codec_pcm_new(codec, "%s",
5848 static void set_output_and_unmute(struct hda_codec *codec, int path_idx)
5853 path = snd_hda_get_path_from_idx(codec, path_idx);
5857 restore_pin_ctl(codec, pin);
5858 snd_hda_activate_path(codec, path, path->active,
5859 aamix_default(codec->spec));
5860 set_pin_eapd(codec, pin, path->active);
5864 static void init_multi_out(struct hda_codec *codec)
5866 struct hda_gen_spec *spec = codec->spec;
5870 set_output_and_unmute(codec, spec->out_paths[i]);
5874 static void __init_extra_out(struct hda_codec *codec, int num_outs, int *paths)
5879 set_output_and_unmute(codec, paths[i]);
5883 static void init_extra_out(struct hda_codec *codec)
5885 struct hda_gen_spec *spec = codec->spec;
5888 __init_extra_out(codec, spec->autocfg.hp_outs, spec->hp_paths);
5890 __init_extra_out(codec, spec->autocfg.speaker_outs,
5895 static void init_multi_io(struct hda_codec *codec)
5897 struct hda_gen_spec *spec = codec->spec;
5903 path = get_multiio_path(codec, i);
5908 snd_hda_codec_get_pin_target(codec, pin);
5909 snd_hda_activate_path(codec, path, path->active,
5914 static void init_aamix_paths(struct hda_codec *codec)
5916 struct hda_gen_spec *spec = codec->spec;
5922 update_aamix_paths(codec, spec->aamix_mode, spec->out_paths[0],
5925 update_aamix_paths(codec, spec->aamix_mode, spec->hp_paths[0],
5928 update_aamix_paths(codec, spec->aamix_mode, spec->speaker_paths[0],
5934 static void init_analog_input(struct hda_codec *codec)
5936 struct hda_gen_spec *spec = codec->spec;
5942 if (is_input_pin(codec, nid))
5943 restore_pin_ctl(codec, nid);
5947 resume_path_from_idx(codec, spec->loopback_paths[i]);
5948 resume_path_from_idx(codec, spec->loopback_merge_path);
5954 static void init_input_src(struct hda_codec *codec)
5956 struct hda_gen_spec *spec = codec->spec;
5968 path = get_input_path(codec, c, i);
5973 snd_hda_activate_path(codec, path, active, false);
5977 update_hp_mic(codec, c, true);
5981 spec->cap_sync_hook(codec, NULL, NULL);
5985 static void init_digital(struct hda_codec *codec)
5987 struct hda_gen_spec *spec = codec->spec;
5992 set_output_and_unmute(codec, spec->digout_paths[i]);
5995 restore_pin_ctl(codec, pin);
5996 resume_path_from_idx(codec, spec->digin_path);
6003 static void clear_unsol_on_unused_pins(struct hda_codec *codec)
6008 snd_array_for_each(&codec->init_pins, i, pin) {
6010 if (is_jack_detectable(codec, nid) &&
6011 !snd_hda_jack_tbl_get(codec, nid))
6012 snd_hda_codec_write_cache(codec, nid, 0,
6019 * @codec: the HDA codec
6023 int snd_hda_gen_init(struct hda_codec *codec)
6025 struct hda_gen_spec *spec = codec->spec;
6028 spec->init_hook(codec);
6031 snd_hda_apply_verbs(codec);
6033 init_multi_out(codec);
6034 init_extra_out(codec);
6035 init_multi_io(codec);
6036 init_aamix_paths(codec);
6037 init_analog_input(codec);
6038 init_input_src(codec);
6039 init_digital(codec);
6041 clear_unsol_on_unused_pins(codec);
6043 sync_all_pin_power_ctls(codec);
6046 update_automute_all(codec);
6048 snd_hda_regmap_sync(codec);
6053 hda_call_check_power_status(codec, 0x01);
6060 * @codec: the HDA codec
6064 void snd_hda_gen_remove(struct hda_codec *codec)
6066 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
6067 snd_hda_gen_spec_free(codec->spec);
6068 kfree(codec->spec);
6069 codec->spec = NULL;
6075 * @codec: the HDA codec
6080 int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid)
6082 struct hda_gen_spec *spec = codec->spec;
6083 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
6089 * the generic codec support
6092 static int snd_hda_gen_probe(struct hda_codec *codec,
6102 codec->spec = spec;
6104 err = snd_hda_parse_pin_defcfg(codec, &spec->autocfg, NULL, 0);
6108 err = snd_hda_gen_parse_auto_config(codec, &spec->autocfg);
6115 snd_hda_gen_remove(codec);
6145 MODULE_DESCRIPTION("Generic HD-audio codec parser");