Lines Matching defs: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);
1014 static int add_vol_ctl(struct hda_codec *codec, const char *pfx, int cidx,
1024 return __add_pb_vol_ctrl(codec->spec, HDA_CTL_WIDGET_VOL, pfx, cidx, val);
1028 static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
1034 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
1040 static int add_stereo_vol(struct hda_codec *codec, const char *pfx, int cidx,
1043 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
1044 return add_vol_ctl(codec, pfx, cidx, chs, path);
1050 static int add_sw_ctl(struct hda_codec *codec, const char *pfx, int cidx,
1064 int nums = snd_hda_get_num_conns(codec, nid);
1070 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
1073 static int add_stereo_sw(struct hda_codec *codec, const char *pfx,
1076 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
1077 return add_sw_ctl(codec, pfx, cidx, chs, path);
1084 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1085 struct hda_gen_spec *spec = codec->spec;
1111 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1115 mutex_lock(&codec->control_mutex);
1120 mutex_unlock(&codec->control_mutex);
1127 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1133 mutex_lock(&codec->control_mutex);
1145 mutex_unlock(&codec->control_mutex);
1150 static bool path_has_mixer(struct hda_codec *codec, int path_idx, int ctl_type)
1152 struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
1161 static const char *get_line_out_pfx(struct hda_codec *codec, int ch,
1164 struct hda_gen_spec *spec = codec->spec;
1169 !codec->force_pin_prefix &&
1177 !codec->force_pin_prefix &&
1191 !path_has_mixer(codec, spec->hp_paths[0], ctl_type))
1203 !path_has_mixer(codec, spec->speaker_paths[0], ctl_type))
1218 spk_lo_shared = !path_has_mixer(codec,
1221 hp_lo_shared = !path_has_mixer(codec, spec->hp_paths[0], ctl_type);
1279 static int assign_out_path_ctls(struct hda_codec *codec, struct nid_path *path)
1281 struct hda_gen_spec *spec = codec->spec;
1293 nid = look_for_out_vol_nid(codec, path);
1298 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
1304 nid = look_for_out_mute_nid(codec, path);
1306 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
1308 nid_has_mute(codec, nid, HDA_OUTPUT))
1312 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
1342 static hda_nid_t get_primary_out(struct hda_codec *codec, int idx)
1344 struct hda_gen_spec *spec = codec->spec;
1356 static inline hda_nid_t try_dac(struct hda_codec *codec,
1359 return is_reachable_path(codec, dac, pin) ? dac : 0;
1363 static int try_assign_dacs(struct hda_codec *codec, int num_outs,
1368 struct hda_gen_spec *spec = codec->spec;
1381 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1383 badness += assign_out_path_ctls(codec, path);
1388 dacs[i] = get_preferred_dac(codec, pin);
1390 if (is_dac_already_used(codec, dacs[i]))
1397 dacs[i] = look_for_dac(codec, pin, false);
1401 if (is_reachable_path(codec, dacs[j], pin)) {
1404 invalidate_nid_path(codec, path_idx[j]);
1413 dac = try_dac(codec, get_primary_out(codec, i), pin);
1415 dac = try_dac(codec, dacs[0], pin);
1417 dac = try_dac(codec, get_primary_out(codec, i), pin);
1425 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
1435 path = snd_hda_add_new_path(codec, dac, pin, -spec->mixer_nid);
1438 path = snd_hda_add_new_path(codec, dac, pin, 0);
1444 /* print_nid_path(codec, "output", path); */
1446 path_idx[i] = snd_hda_get_path_idx(codec, path);
1447 badness += assign_out_path_ctls(codec, path);
1455 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
1457 struct hda_gen_spec *spec = codec->spec;
1463 if (!nid || is_dac_already_used(codec, nid))
1465 if (is_reachable_path(codec, nid, pin)) {
1475 static bool can_be_multiio_pin(struct hda_codec *codec,
1480 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1485 caps = snd_hda_query_pin_caps(codec, nid);
1492 static int count_multiio_pins(struct hda_codec *codec, hda_nid_t reference_pin)
1494 struct hda_gen_spec *spec = codec->spec;
1496 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1505 if (can_be_multiio_pin(codec, location,
1521 static int fill_multi_ios(struct hda_codec *codec,
1525 struct hda_gen_spec *spec = codec->spec;
1528 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1537 num_pins = count_multiio_pins(codec, reference_pin);
1548 if (!can_be_multiio_pin(codec, location, nid))
1558 dac = get_dac_if_single(codec, nid);
1560 dac = look_for_dac(codec, nid, false);
1565 path = snd_hda_add_new_path(codec, dac, nid,
1571 /* print_nid_path(codec, "multiio", path); */
1575 snd_hda_get_path_idx(codec, path);
1599 path = snd_hda_get_path_from_idx(codec, spec->out_paths[cfg->line_outs + i]);
1600 badness += assign_out_path_ctls(codec, path);
1607 static bool map_singles(struct hda_codec *codec, int outs,
1610 struct hda_gen_spec *spec = codec->spec;
1618 dac = get_dac_if_single(codec, pins[i]);
1621 path = snd_hda_add_new_path(codec, dac, pins[i],
1624 path = snd_hda_add_new_path(codec, dac, pins[i], 0);
1628 /* print_nid_path(codec, "output", path); */
1630 path_idx[i] = snd_hda_get_path_idx(codec, path);
1643 static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
1645 struct hda_gen_spec *spec = codec->spec;
1649 path = snd_hda_get_path_from_idx(codec, path_idx);
1656 path = snd_hda_add_new_path(codec, dac, pin, spec->mixer_nid);
1667 path = snd_hda_add_new_path(codec, dac, pin,
1672 /* print_nid_path(codec, "output-aamix", path); */
1675 return snd_hda_get_path_idx(codec, path);
1679 static bool indep_hp_possible(struct hda_codec *codec)
1681 struct hda_gen_spec *spec = codec->spec;
1690 path = snd_hda_get_path_from_idx(codec, idx);
1702 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
1707 path = snd_hda_get_path_from_idx(codec, spec->speaker_paths[i]);
1718 static void refill_shared_dacs(struct hda_codec *codec, int num_outs,
1727 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1735 static int fill_and_eval_dacs(struct hda_codec *codec,
1739 struct hda_gen_spec *spec = codec->spec;
1768 mapped = map_singles(codec, cfg->line_outs,
1772 mapped |= map_singles(codec, cfg->hp_outs,
1776 mapped |= map_singles(codec, cfg->speaker_outs,
1783 err = fill_multi_ios(codec, cfg->line_out_pins[0], true);
1790 badness += try_assign_dacs(codec, cfg->line_outs, cfg->line_out_pins,
1797 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1804 err = try_assign_dacs(codec, cfg->hp_outs, cfg->hp_pins,
1813 err = try_assign_dacs(codec, cfg->speaker_outs,
1824 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1832 check_aamix_out_path(codec, spec->out_paths[0]);
1835 check_aamix_out_path(codec, spec->hp_paths[0]);
1838 check_aamix_out_path(codec, spec->speaker_paths[0]);
1843 if (count_multiio_pins(codec, cfg->hp_pins[0]) >= 2)
1871 if (spec->indep_hp && !indep_hp_possible(codec))
1876 refill_shared_dacs(codec, cfg->hp_outs,
1880 refill_shared_dacs(codec, cfg->speaker_outs,
1891 codec_dbg(codec, fmt, ##__VA_ARGS__)
1894 do { if (0) codec_dbg(codec, fmt, ##__VA_ARGS__); } while (0)
1898 static inline void print_nid_path_idx(struct hda_codec *codec,
1903 path = snd_hda_get_path_from_idx(codec, idx);
1905 print_nid_path(codec, pfx, path);
1908 static void debug_show_configs(struct hda_codec *codec,
1911 struct hda_gen_spec *spec = codec->spec;
1924 print_nid_path_idx(codec, " out", spec->out_paths[i]);
1931 print_nid_path_idx(codec, " mio",
1942 print_nid_path_idx(codec, " hp ", spec->hp_paths[i]);
1952 print_nid_path_idx(codec, " spk", spec->speaker_paths[i]);
1954 print_nid_path_idx(codec, " mix", spec->aamix_out_paths[i]);
1957 #define debug_show_configs(codec, cfg) /* NOP */
1960 /* find all available DACs of the codec */
1961 static void fill_all_dac_nids(struct hda_codec *codec)
1963 struct hda_gen_spec *spec = codec->spec;
1968 for_each_hda_codec_node(nid, codec) {
1969 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
1972 codec_err(codec, "Too many DACs!\n");
1979 static int parse_output_paths(struct hda_codec *codec)
1981 struct hda_gen_spec *spec = codec->spec;
1997 badness = fill_and_eval_dacs(codec, fill_hardwired,
2006 debug_show_configs(codec, cfg);
2058 fill_and_eval_dacs(codec, best_wired, best_mio);
2062 debug_show_configs(codec, cfg);
2066 path = snd_hda_get_path_from_idx(codec, spec->out_paths[0]);
2068 spec->vmaster_nid = look_for_out_vol_nid(codec, path);
2070 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2082 set_pin_targets(codec, cfg->line_outs, cfg->line_out_pins, val);
2084 set_pin_targets(codec, cfg->hp_outs, cfg->hp_pins, PIN_HP);
2087 set_pin_targets(codec, cfg->speaker_outs,
2092 if (spec->indep_hp && !indep_hp_possible(codec))
2100 static int create_multi_out_ctls(struct hda_codec *codec,
2103 struct hda_gen_spec *spec = codec->spec;
2115 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
2119 name = get_line_out_pfx(codec, i, &index, NID_PATH_VOL_CTL);
2122 err = add_vol_ctl(codec, "Center", 0, 1, path);
2125 err = add_vol_ctl(codec, "LFE", 0, 2, path);
2129 err = add_stereo_vol(codec, name, index, path);
2134 name = get_line_out_pfx(codec, i, &index, NID_PATH_MUTE_CTL);
2136 err = add_sw_ctl(codec, "Center", 0, 1, path);
2139 err = add_sw_ctl(codec, "LFE", 0, 2, path);
2143 err = add_stereo_sw(codec, name, index, path);
2151 static int create_extra_out(struct hda_codec *codec, int path_idx,
2157 path = snd_hda_get_path_from_idx(codec, path_idx);
2160 err = add_stereo_vol(codec, pfx, cidx, path);
2163 err = add_stereo_sw(codec, pfx, cidx, path);
2170 static int create_extra_outs(struct hda_codec *codec, int num_pins,
2190 err = create_extra_out(codec, paths[i], name, idx);
2197 static int create_hp_out_ctls(struct hda_codec *codec)
2199 struct hda_gen_spec *spec = codec->spec;
2200 return create_extra_outs(codec, spec->autocfg.hp_outs,
2205 static int create_speaker_out_ctls(struct hda_codec *codec)
2207 struct hda_gen_spec *spec = codec->spec;
2208 return create_extra_outs(codec, spec->autocfg.speaker_outs,
2217 static void call_hp_automute(struct hda_codec *codec,
2228 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2229 struct hda_gen_spec *spec = codec->spec;
2234 static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
2241 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2242 struct hda_gen_spec *spec = codec->spec;
2262 update_aamix_paths(codec, spec->aamix_mode,
2267 update_aamix_paths(codec, spec->aamix_mode,
2279 call_hp_automute(codec, NULL);
2296 static int create_indep_hp_ctls(struct hda_codec *codec)
2298 struct hda_gen_spec *spec = codec->spec;
2326 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2327 struct hda_gen_spec *spec = codec->spec;
2343 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2344 struct hda_gen_spec *spec = codec->spec;
2351 get_multiio_path(struct hda_codec *codec, int idx)
2353 struct hda_gen_spec *spec = codec->spec;
2354 return snd_hda_get_path_from_idx(codec,
2358 static void update_automute_all(struct hda_codec *codec);
2368 static int set_multi_io(struct hda_codec *codec, int idx, bool output)
2370 struct hda_gen_spec *spec = codec->spec;
2374 path = get_multiio_path(codec, idx);
2382 set_pin_target(codec, nid, PIN_OUT, true);
2383 snd_hda_activate_path(codec, path, true, aamix_default(spec));
2384 set_pin_eapd(codec, nid, true);
2386 set_pin_eapd(codec, nid, false);
2387 snd_hda_activate_path(codec, path, false, aamix_default(spec));
2388 set_pin_target(codec, nid, spec->multi_io[idx].ctl_in, true);
2389 path_power_down_sync(codec, path);
2393 update_automute_all(codec);
2401 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2402 struct hda_gen_spec *spec = codec->spec;
2412 set_multi_io(codec, i, i < ch);
2428 static int create_multi_channel_mode(struct hda_codec *codec)
2430 struct hda_gen_spec *spec = codec->spec;
2448 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2449 struct hda_gen_spec *spec = codec->spec;
2454 static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
2458 struct hda_gen_spec *spec = codec->spec;
2461 nomix_path = snd_hda_get_path_from_idx(codec, nomix_path_idx);
2462 mix_path = snd_hda_get_path_from_idx(codec, mix_path_idx);
2474 snd_hda_activate_path(codec, nomix_path, false, true);
2475 snd_hda_activate_path(codec, mix_path, true, true);
2476 path_power_down_sync(codec, nomix_path);
2478 snd_hda_activate_path(codec, mix_path, false, false);
2479 snd_hda_activate_path(codec, nomix_path, true, false);
2480 path_power_down_sync(codec, mix_path);
2485 static void update_output_paths(struct hda_codec *codec, int num_outs,
2488 struct hda_gen_spec *spec = codec->spec;
2493 path = snd_hda_get_path_from_idx(codec, paths[i]);
2495 snd_hda_activate_path(codec, path, path->active,
2503 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2504 struct hda_gen_spec *spec = codec->spec;
2512 update_aamix_paths(codec, val, spec->out_paths[0],
2515 update_aamix_paths(codec, val, spec->hp_paths[0],
2518 update_aamix_paths(codec, val, spec->speaker_paths[0],
2522 update_output_paths(codec, cfg->line_outs, spec->out_paths);
2524 update_output_paths(codec, cfg->hp_outs, spec->hp_paths);
2526 update_output_paths(codec, cfg->speaker_outs,
2540 static int create_loopback_mixing_ctl(struct hda_codec *codec)
2542 struct hda_gen_spec *spec = codec->spec;
2556 static void call_update_outputs(struct hda_codec *codec);
2559 static void update_hp_mic(struct hda_codec *codec, int adc_mux, bool force)
2561 struct hda_gen_spec *spec = codec->spec;
2570 val = snd_hda_codec_get_pin_target(codec, pin);
2580 val = snd_hda_get_default_vref(codec, pin);
2581 /* if the HP pin doesn't support VREF and the codec driver gives an
2586 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
2588 snd_hda_set_pin_ctl_cache(codec, vref_pin,
2597 set_pin_target(codec, pin, val, true);
2598 call_hp_automute(codec, NULL);
2603 static int create_hp_mic(struct hda_codec *codec)
2605 struct hda_gen_spec *spec = codec->spec;
2619 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2637 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2648 codec_dbg(codec, "Enable shared I/O jack on NID 0x%x\n", nid);
2656 static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin);
2671 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2673 if (snd_hda_codec_get_pin_target(codec, nid) == PIN_HP)
2683 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2688 if (snd_hda_codec_get_pin_target(codec, nid) == val)
2690 snd_hda_set_pin_ctl_cache(codec, nid, val);
2701 static bool find_kctl_name(struct hda_codec *codec, const char *name, int idx)
2703 struct hda_gen_spec *spec = codec->spec;
2714 static void get_jack_mode_name(struct hda_codec *codec, hda_nid_t pin,
2717 struct hda_gen_spec *spec = codec->spec;
2720 snd_hda_get_pin_label(codec, pin, &spec->autocfg, name, name_len, &idx);
2723 for (; find_kctl_name(codec, name, idx); idx++)
2727 static int get_out_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2729 struct hda_gen_spec *spec = codec->spec;
2731 unsigned int pincap = snd_hda_query_pin_caps(codec, pin);
2738 static int create_out_jack_modes(struct hda_codec *codec, int num_pins,
2741 struct hda_gen_spec *spec = codec->spec;
2748 if (get_out_jack_num_items(codec, pin) > 1) {
2751 get_jack_mode_name(codec, pin, name, sizeof(name));
2775 static unsigned int get_vref_caps(struct hda_codec *codec, hda_nid_t pin)
2779 pincap = snd_hda_query_pin_caps(codec, pin);
2818 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2820 unsigned int vref_caps = get_vref_caps(codec, nid);
2833 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2835 unsigned int vref_caps = get_vref_caps(codec, nid);
2838 idx = snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_VREFEN;
2846 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2848 unsigned int vref_caps = get_vref_caps(codec, nid);
2851 val = snd_hda_codec_get_pin_target(codec, nid);
2858 snd_hda_set_pin_ctl_cache(codec, nid, val);
2869 static int get_in_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2871 struct hda_gen_spec *spec = codec->spec;
2874 nitems = hweight32(get_vref_caps(codec, pin));
2878 static int create_in_jack_mode(struct hda_codec *codec, hda_nid_t pin)
2880 struct hda_gen_spec *spec = codec->spec;
2889 defcfg = snd_hda_codec_get_pincfg(codec, pin);
2894 if (get_in_jack_num_items(codec, pin) <= 1)
2897 get_jack_mode_name(codec, pin, name, sizeof(name));
2911 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2913 int out_jacks = get_out_jack_num_items(codec, nid);
2914 int in_jacks = get_in_jack_num_items(codec, nid);
2932 unsigned int vref_caps = get_vref_caps(codec, nid);
2942 static int get_cur_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t nid)
2944 int out_jacks = get_out_jack_num_items(codec, nid);
2945 int in_jacks = get_in_jack_num_items(codec, nid);
2946 unsigned int val = snd_hda_codec_get_pin_target(codec, nid);
2955 unsigned int vref_caps = get_vref_caps(codec, nid);
2966 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2969 get_cur_hp_mic_jack_mode(codec, nid);
2976 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2978 int out_jacks = get_out_jack_num_items(codec, nid);
2979 int in_jacks = get_in_jack_num_items(codec, nid);
2982 oldval = get_cur_hp_mic_jack_mode(codec, nid);
2995 unsigned int vref_caps = get_vref_caps(codec, nid);
2996 val = snd_hda_codec_get_pin_target(codec, nid);
3000 val = snd_hda_get_default_vref(codec, nid) | PIN_IN;
3002 snd_hda_set_pin_ctl_cache(codec, nid, val);
3003 call_hp_automute(codec, NULL);
3015 static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin)
3017 struct hda_gen_spec *spec = codec->spec;
3051 static bool look_for_mix_leaf_ctls(struct hda_codec *codec, hda_nid_t mix_nid,
3059 idx = snd_hda_get_conn_index(codec, mix_nid, pin, true);
3064 if (nid_has_volume(codec, mix_nid, HDA_INPUT))
3066 if (nid_has_mute(codec, mix_nid, HDA_INPUT))
3072 num_conns = snd_hda_get_conn_list(codec, mix_nid, &list);
3076 if (!*mix_val && nid_has_volume(codec, nid, HDA_OUTPUT) &&
3077 !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_VOL_CTL))
3079 if (!*mute_val && nid_has_mute(codec, nid, HDA_OUTPUT) &&
3080 !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_MUTE_CTL))
3087 static int new_analog_input(struct hda_codec *codec, int input_idx,
3091 struct hda_gen_spec *spec = codec->spec;
3096 if (!look_for_mix_leaf_ctls(codec, mix_nid, pin, &mix_val, &mute_val))
3099 path = snd_hda_add_new_path(codec, pin, mix_nid, 0);
3102 print_nid_path(codec, "loopback", path);
3103 spec->loopback_paths[input_idx] = snd_hda_get_path_idx(codec, path);
3128 path = snd_hda_add_new_path(codec, spec->mixer_nid,
3131 print_nid_path(codec, "loopback-merge", path);
3136 snd_hda_get_path_idx(codec, path);
3143 static int is_input_pin(struct hda_codec *codec, hda_nid_t nid)
3145 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
3149 /* Parse the codec tree and retrieve ADCs */
3150 static int fill_adc_nids(struct hda_codec *codec)
3152 struct hda_gen_spec *spec = codec->spec;
3158 for_each_hda_codec_node(nid, codec) {
3159 unsigned int caps = get_wcaps(codec, nid);
3180 static int check_dyn_adc_switch(struct hda_codec *codec)
3182 struct hda_gen_spec *spec = codec->spec;
3211 codec_dbg(codec, "enabling ADC switching\n");
3222 invalidate_nid_path(codec,
3236 codec_dbg(codec, "reducing to a single ADC\n");
3248 static int parse_capture_source(struct hda_codec *codec, hda_nid_t pin,
3252 struct hda_gen_spec *spec = codec->spec;
3262 if (!is_reachable_path(codec, pin, adc))
3264 path = snd_hda_add_new_path(codec, pin, adc, anchor);
3267 print_nid_path(codec, "input", path);
3269 snd_hda_get_path_idx(codec, path);
3275 snd_hda_add_imux_item(codec, imux, label, cfg_idx, NULL);
3290 static int fill_input_pin_labels(struct hda_codec *codec)
3292 struct hda_gen_spec *spec = codec->spec;
3301 if (!is_input_pin(codec, pin))
3304 label = hda_get_autocfg_input_label(codec, cfg, i);
3323 static int create_input_ctls(struct hda_codec *codec)
3325 struct hda_gen_spec *spec = codec->spec;
3332 num_adcs = fill_adc_nids(codec);
3336 err = fill_input_pin_labels(codec);
3344 if (!is_input_pin(codec, pin))
3349 val |= snd_hda_get_default_vref(codec, pin);
3351 !snd_hda_codec_get_pin_target(codec, pin))
3352 set_pin_target(codec, pin, val, false);
3355 if (is_reachable_path(codec, pin, mixer)) {
3356 err = new_analog_input(codec, i, pin,
3365 err = parse_capture_source(codec, pin, i, num_adcs,
3371 err = create_in_jack_mode(codec, pin);
3379 err = parse_capture_source(codec, mixer, CFG_IDX_MIX, num_adcs,
3396 static struct nid_path *get_input_path(struct hda_codec *codec, int adc_idx, int imux_idx)
3398 struct hda_gen_spec *spec = codec->spec;
3409 return snd_hda_get_path_from_idx(codec, spec->input_paths[imux_idx][adc_idx]);
3412 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3418 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3419 struct hda_gen_spec *spec = codec->spec;
3426 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3427 struct hda_gen_spec *spec = codec->spec;
3438 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3440 return mux_select(codec, adc_idx,
3464 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3465 struct hda_gen_spec *spec = codec->spec;
3472 mutex_lock(&codec->control_mutex);
3474 path = get_input_path(codec, adc_idx, i);
3486 mutex_unlock(&codec->control_mutex);
3488 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3537 static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
3549 if (nid_has_volume(codec, nid, HDA_OUTPUT))
3552 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
3554 if (!depth && codec->single_adc_amp)
3561 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3564 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
3566 if (!depth && codec->single_adc_amp)
3576 static bool is_inv_dmic_pin(struct hda_codec *codec, hda_nid_t nid)
3578 struct hda_gen_spec *spec = codec->spec;
3590 val = snd_hda_codec_get_pincfg(codec, nid);
3600 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3601 struct hda_gen_spec *spec = codec->spec;
3609 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3614 static int add_single_cap_ctl(struct hda_codec *codec, const char *label,
3618 struct hda_gen_spec *spec = codec->spec;
3660 static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx,
3665 err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl, inv_dmic);
3668 err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl, inv_dmic);
3675 static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx,
3678 struct hda_gen_spec *spec = codec->spec;
3701 static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type)
3707 path = get_input_path(codec, 0, idx);
3714 path = get_input_path(codec, 0, i);
3722 static int create_multi_cap_vol_ctl(struct hda_codec *codec)
3724 struct hda_gen_spec *spec = codec->spec;
3735 inv_dmic = is_inv_dmic_pin(codec, spec->imux_pins[i]);
3738 err = add_single_cap_ctl(codec,
3742 get_first_cap_ctl(codec, i, type),
3751 static int create_capture_mixers(struct hda_codec *codec)
3753 struct hda_gen_spec *spec = codec->spec;
3781 path = get_input_path(codec, n, i);
3784 parse_capvol_in_path(codec, path);
3789 if (!same_amp_caps(codec, vol,
3797 if (!same_amp_caps(codec, sw,
3801 if (is_inv_dmic_pin(codec, spec->imux_pins[i]))
3806 err = create_single_cap_vol_ctl(codec, n, vol, sw,
3809 err = create_bind_cap_vol_ctl(codec, n, vol, sw);
3811 err = create_multi_cap_vol_ctl(codec);
3824 static bool check_boost_vol(struct hda_codec *codec, hda_nid_t nid,
3829 if (!nid_has_volume(codec, nid, dir) ||
3830 is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
3831 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
3834 step = (query_amp_caps(codec, nid, dir) & AC_AMPCAP_STEP_SIZE)
3842 static unsigned int look_for_boost_amp(struct hda_codec *codec,
3853 if (depth && check_boost_vol(codec, nid, HDA_OUTPUT, 0)) {
3856 } else if (check_boost_vol(codec, nid, HDA_INPUT,
3867 static int parse_mic_boost(struct hda_codec *codec)
3869 struct hda_gen_spec *spec = codec->spec;
3891 path = get_input_path(codec, 0, i);
3895 val = look_for_boost_amp(codec, path);
3916 static int create_mute_led_cdev(struct hda_codec *codec,
3921 struct hda_gen_spec *spec = codec->spec;
3926 cdev = devm_kzalloc(&codec->core.dev, sizeof(*cdev), GFP_KERNEL);
3937 err = led_classdev_register(&codec->core.dev, cdev);
3951 * @codec: the HDA codec
3954 int snd_hda_gen_add_mute_led_cdev(struct hda_codec *codec,
3958 struct hda_gen_spec *spec = codec->spec;
3962 err = create_mute_led_cdev(codec, callback, false);
3964 codec_warn(codec, "failed to create a mute LED cdev\n");
3970 codec_err(codec, "vmaster hook already present before cdev!\n");
3988 static void call_micmute_led_update(struct hda_codec *codec)
3990 struct hda_gen_spec *spec = codec->spec;
4016 static void update_micmute_led(struct hda_codec *codec,
4020 struct hda_gen_spec *spec = codec->spec;
4024 spec->micmute_led.old_hook(codec, kcontrol, ucontrol);
4036 call_micmute_led_update(codec);
4053 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4054 struct hda_gen_spec *spec = codec->spec;
4063 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4064 struct hda_gen_spec *spec = codec->spec;
4073 call_micmute_led_update(codec);
4086 static int add_micmute_led_hook(struct hda_codec *codec)
4088 struct hda_gen_spec *spec = codec->spec;
4102 * @codec: the HDA codec
4105 * Called from the codec drivers for offering the mic mute LED controls.
4114 int snd_hda_gen_add_micmute_led_cdev(struct hda_codec *codec,
4121 err = create_mute_led_cdev(codec, callback, true);
4123 codec_warn(codec, "failed to create a mic-mute LED cdev\n");
4128 return add_micmute_led_hook(codec);
4136 static void parse_digital(struct hda_codec *codec)
4138 struct hda_gen_spec *spec = codec->spec;
4147 dig_nid = look_for_dac(codec, pin, true);
4150 path = snd_hda_add_new_path(codec, dig_nid, pin, 0);
4153 print_nid_path(codec, "digout", path);
4156 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
4157 set_pin_target(codec, pin, PIN_OUT, false);
4172 for_each_hda_codec_node(dig_nid, codec) {
4173 unsigned int wcaps = get_wcaps(codec, dig_nid);
4178 path = snd_hda_add_new_path(codec, pin, dig_nid, 0);
4180 print_nid_path(codec, "digin", path);
4184 spec->digin_path = snd_hda_get_path_idx(codec, path);
4185 set_pin_target(codec, pin, PIN_IN, false);
4197 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur);
4200 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
4203 struct hda_gen_spec *spec = codec->spec;
4216 old_path = get_input_path(codec, adc_idx, spec->cur_mux[adc_idx]);
4220 snd_hda_activate_path(codec, old_path, false, false);
4225 update_hp_mic(codec, adc_idx, false);
4228 dyn_adc_pcm_resetup(codec, idx);
4230 path = get_input_path(codec, adc_idx, idx);
4235 snd_hda_activate_path(codec, path, true, false);
4237 spec->cap_sync_hook(codec, NULL, NULL);
4238 path_power_down_sync(codec, old_path);
4247 static hda_nid_t set_path_power(struct hda_codec *codec, hda_nid_t nid,
4250 struct hda_gen_spec *spec = codec->spec;
4269 last = path_power_update(codec, path, true);
4279 static bool detect_pin_state(struct hda_codec *codec, hda_nid_t pin)
4281 if (!is_jack_detectable(codec, pin))
4283 return snd_hda_jack_detect_state(codec, pin) != HDA_JACK_NOT_PRESENT;
4292 static hda_nid_t set_pin_power_jack(struct hda_codec *codec, hda_nid_t pin,
4297 if (!codec->power_save_node)
4300 on = detect_pin_state(codec, pin);
4304 return set_path_power(codec, pin, on, -1);
4307 static void pin_power_callback(struct hda_codec *codec,
4312 sync_power_state_change(codec,
4313 set_pin_power_jack(codec, jack->nid, on));
4317 static void pin_power_up_callback(struct hda_codec *codec,
4320 pin_power_callback(codec, jack, true);
4324 static void pin_power_down_callback(struct hda_codec *codec,
4327 pin_power_callback(codec, jack, false);
4331 static void add_pin_power_ctls(struct hda_codec *codec, int num_pins,
4339 if (is_jack_detectable(codec, pins[i]))
4340 snd_hda_jack_detect_enable_callback(codec, pins[i], cb);
4342 set_path_power(codec, pins[i], true, -1);
4349 static void add_all_pin_power_ctls(struct hda_codec *codec, bool on)
4351 struct hda_gen_spec *spec = codec->spec;
4355 if (!codec->power_save_node)
4357 add_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins, on);
4359 add_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins, on);
4361 add_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins, on);
4363 add_pin_power_ctls(codec, 1, &cfg->inputs[i].pin, on);
4367 static void sync_pin_power_ctls(struct hda_codec *codec, int num_pins,
4373 if (is_jack_detectable(codec, pins[i]))
4374 set_pin_power_jack(codec, pins[i], -1);
4378 static void sync_all_pin_power_ctls(struct hda_codec *codec)
4380 struct hda_gen_spec *spec = codec->spec;
4384 if (!codec->power_save_node)
4386 sync_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins);
4388 sync_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins);
4390 sync_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins);
4392 sync_pin_power_ctls(codec, 1, &cfg->inputs[i].pin);
4396 static int add_fake_paths(struct hda_codec *codec, hda_nid_t nid,
4399 struct hda_gen_spec *spec = codec->spec;
4406 if (get_nid_path(codec, nid, pins[i], 0))
4421 static int add_fake_beep_paths(struct hda_codec *codec)
4423 struct hda_gen_spec *spec = codec->spec;
4428 if (!codec->power_save_node || !nid)
4430 err = add_fake_paths(codec, nid, cfg->line_outs, cfg->line_out_pins);
4434 err = add_fake_paths(codec, nid, cfg->hp_outs, cfg->hp_pins);
4439 err = add_fake_paths(codec, nid, cfg->speaker_outs,
4450 set_path_power(beep->codec, beep->nid, -1, on);
4455 * @codec: the HDA codec
4458 int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin)
4460 struct hda_gen_spec *spec = codec->spec;
4481 static bool detect_jacks(struct hda_codec *codec, int num_pins, const hda_nid_t *pins)
4491 if (snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_IN_EN)
4493 if (snd_hda_jack_detect_state(codec, nid) == HDA_JACK_PRESENT)
4500 static void do_automute(struct hda_codec *codec, int num_pins, const hda_nid_t *pins,
4503 struct hda_gen_spec *spec = codec->spec;
4512 oldval = snd_hda_codec_get_pin_target(codec, nid);
4520 path = snd_hda_get_path_from_idx(codec, paths[i]);
4546 update_pin_ctl(codec, nid, val);
4549 set_pin_eapd(codec, nid, !mute);
4550 if (codec->power_save_node) {
4553 on = detect_pin_state(codec, nid);
4554 set_path_power(codec, nid, on, -1);
4561 * @codec: the HDA codec
4565 void snd_hda_gen_update_outputs(struct hda_codec *codec)
4567 struct hda_gen_spec *spec = codec->spec;
4579 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
4592 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
4607 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
4612 static void call_update_outputs(struct hda_codec *codec)
4614 struct hda_gen_spec *spec = codec->spec;
4616 spec->automute_hook(codec);
4618 snd_hda_gen_update_outputs(codec);
4621 if (spec->auto_mute_via_amp && !codec->bus->shutdown)
4627 * @codec: the HDA codec
4630 void snd_hda_gen_hp_automute(struct hda_codec *codec,
4633 struct hda_gen_spec *spec = codec->spec;
4643 spec->hp_jack_present = detect_jacks(codec, num_pins, pins);
4646 call_update_outputs(codec);
4652 * @codec: the HDA codec
4655 void snd_hda_gen_line_automute(struct hda_codec *codec,
4658 struct hda_gen_spec *spec = codec->spec;
4667 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
4671 call_update_outputs(codec);
4677 * @codec: the HDA codec
4680 void snd_hda_gen_mic_autoswitch(struct hda_codec *codec,
4683 struct hda_gen_spec *spec = codec->spec;
4692 if (snd_hda_codec_get_pin_target(codec, pin) & AC_PINCTL_OUT_EN)
4694 if (snd_hda_jack_detect_state(codec, pin) == HDA_JACK_PRESENT) {
4695 mux_select(codec, 0, spec->am_entry[i].idx);
4699 mux_select(codec, 0, spec->am_entry[0].idx);
4704 static void call_hp_automute(struct hda_codec *codec,
4707 struct hda_gen_spec *spec = codec->spec;
4709 spec->hp_automute_hook(codec, jack);
4711 snd_hda_gen_hp_automute(codec, jack);
4714 static void call_line_automute(struct hda_codec *codec,
4717 struct hda_gen_spec *spec = codec->spec;
4719 spec->line_automute_hook(codec, jack);
4721 snd_hda_gen_line_automute(codec, jack);
4724 static void call_mic_autoswitch(struct hda_codec *codec,
4727 struct hda_gen_spec *spec = codec->spec;
4729 spec->mic_autoswitch_hook(codec, jack);
4731 snd_hda_gen_mic_autoswitch(codec, jack);
4735 static void update_automute_all(struct hda_codec *codec)
4737 call_hp_automute(codec, NULL);
4738 call_line_automute(codec, NULL);
4739 call_mic_autoswitch(codec, NULL);
4748 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4749 struct hda_gen_spec *spec = codec->spec;
4762 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4763 struct hda_gen_spec *spec = codec->spec;
4777 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4778 struct hda_gen_spec *spec = codec->spec;
4811 call_update_outputs(codec);
4823 static int add_automute_mode_enum(struct hda_codec *codec)
4825 struct hda_gen_spec *spec = codec->spec;
4836 static int check_auto_mute_availability(struct hda_codec *codec)
4838 struct hda_gen_spec *spec = codec->spec;
4871 if (!is_jack_detectable(codec, nid))
4873 codec_dbg(codec, "Enable HP auto-muting on NID 0x%x\n", nid);
4874 snd_hda_jack_detect_enable_callback(codec, nid,
4883 if (!is_jack_detectable(codec, nid))
4885 codec_dbg(codec, "Enable Line-Out auto-muting on NID 0x%x\n", nid);
4886 snd_hda_jack_detect_enable_callback(codec, nid,
4901 err = add_automute_mode_enum(codec);
4909 static bool auto_mic_check_imux(struct hda_codec *codec)
4911 struct hda_gen_spec *spec = codec->spec;
4926 snd_hda_jack_detect_enable_callback(codec,
4943 static int check_auto_mic_availability(struct hda_codec *codec)
4945 struct hda_gen_spec *spec = codec->spec;
4958 attr = snd_hda_codec_get_pincfg(codec, nid);
4975 if (!is_jack_detectable(codec, nid))
4997 if (!auto_mic_check_imux(codec))
5003 codec_dbg(codec, "Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
5014 * @codec: the HDA codec
5018 unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
5022 struct hda_gen_spec *spec = codec->spec;
5024 if (!spec->power_down_unused && !codec->power_save_node)
5026 if (power_state != AC_PWRST_D0 || nid == codec->core.afg)
5028 if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER)
5030 if (is_active_nid_for_any(codec, nid))
5037 static void mute_all_mixer_nid(struct hda_codec *codec, hda_nid_t mix)
5043 nums = snd_hda_get_conn_list(codec, mix, &conn);
5044 has_amp = nid_has_mute(codec, mix, HDA_INPUT);
5047 update_amp(codec, mix, HDA_INPUT, i,
5049 else if (nid_has_volume(codec, conn[i], HDA_OUTPUT))
5050 update_amp(codec, conn[i], HDA_OUTPUT, 0,
5057 * @codec: the HDA codec
5063 void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on)
5065 if (codec->power_save_node)
5066 set_path_power(codec, nid, -1, on);
5073 * @codec: the HDA codec
5079 int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
5082 struct hda_gen_spec *spec = codec->spec;
5085 parse_user_hints(codec);
5100 fill_all_dac_nids(codec);
5126 err = parse_output_paths(codec);
5129 err = create_multi_channel_mode(codec);
5132 err = create_multi_out_ctls(codec, cfg);
5135 err = create_hp_out_ctls(codec);
5138 err = create_speaker_out_ctls(codec);
5141 err = create_indep_hp_ctls(codec);
5144 err = create_loopback_mixing_ctl(codec);
5147 err = create_hp_mic(codec);
5150 err = create_input_ctls(codec);
5155 add_all_pin_power_ctls(codec, false);
5168 err = check_auto_mute_availability(codec);
5172 err = check_dyn_adc_switch(codec);
5176 err = check_auto_mic_availability(codec);
5184 err = parse_capture_source(codec, spec->mixer_nid,
5192 err = create_capture_mixers(codec);
5196 err = parse_mic_boost(codec);
5206 err = create_hp_mic_jack_mode(codec, spec->hp_mic_pin);
5213 err = create_out_jack_modes(codec, cfg->line_outs,
5219 err = create_out_jack_modes(codec, cfg->hp_outs,
5227 add_all_pin_power_ctls(codec, true);
5231 mute_all_mixer_nid(codec, spec->mixer_nid);
5234 parse_digital(codec);
5236 if (spec->power_down_unused || codec->power_save_node) {
5237 if (!codec->power_filter)
5238 codec->power_filter = snd_hda_gen_path_power_filter;
5239 if (!codec->patch_ops.stream_pm)
5240 codec->patch_ops.stream_pm = snd_hda_gen_stream_pm;
5244 err = snd_hda_attach_beep_device(codec, spec->beep_nid);
5247 if (codec->beep && codec->power_save_node) {
5248 err = add_fake_beep_paths(codec);
5251 codec->beep->power_hook = beep_power_hook;
5277 * @codec: the HDA codec
5281 int snd_hda_gen_build_controls(struct hda_codec *codec)
5283 struct hda_gen_spec *spec = codec->spec;
5287 err = snd_hda_add_new_ctls(codec, spec->kctls.list);
5293 err = snd_hda_create_dig_out_ctls(codec,
5300 err = snd_hda_create_spdif_share_sw(codec,
5308 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
5315 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
5316 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
5323 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
5324 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
5331 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
5339 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
5353 struct hda_codec *codec,
5357 struct hda_gen_spec *spec = codec->spec;
5359 spec->pcm_playback_hook(hinfo, codec, substream, action);
5363 struct hda_codec *codec,
5367 struct hda_gen_spec *spec = codec->spec;
5369 spec->pcm_capture_hook(hinfo, codec, substream, action);
5376 struct hda_codec *codec,
5379 struct hda_gen_spec *spec = codec->spec;
5383 err = snd_hda_multi_out_analog_open(codec,
5388 call_pcm_playback_hook(hinfo, codec, substream,
5396 struct hda_codec *codec,
5401 struct hda_gen_spec *spec = codec->spec;
5404 err = snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
5407 call_pcm_playback_hook(hinfo, codec, substream,
5413 struct hda_codec *codec,
5416 struct hda_gen_spec *spec = codec->spec;
5419 err = snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
5421 call_pcm_playback_hook(hinfo, codec, substream,
5427 struct hda_codec *codec,
5430 struct hda_gen_spec *spec = codec->spec;
5433 call_pcm_playback_hook(hinfo, codec, substream,
5440 struct hda_codec *codec,
5443 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_OPEN);
5448 struct hda_codec *codec,
5453 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
5454 call_pcm_capture_hook(hinfo, codec, substream,
5460 struct hda_codec *codec,
5463 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
5464 call_pcm_capture_hook(hinfo, codec, substream,
5470 struct hda_codec *codec,
5473 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLOSE);
5478 struct hda_codec *codec,
5481 struct hda_gen_spec *spec = codec->spec;
5489 call_pcm_playback_hook(hinfo, codec, substream,
5496 struct hda_codec *codec,
5499 struct hda_gen_spec *spec = codec->spec;
5502 call_pcm_playback_hook(hinfo, codec, substream,
5509 struct hda_codec *codec,
5514 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
5515 call_pcm_playback_hook(hinfo, codec, substream,
5521 struct hda_codec *codec,
5524 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
5525 call_pcm_playback_hook(hinfo, codec, substream,
5534 struct hda_codec *codec,
5537 struct hda_gen_spec *spec = codec->spec;
5538 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
5542 struct hda_codec *codec,
5547 struct hda_gen_spec *spec = codec->spec;
5548 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
5553 struct hda_codec *codec,
5556 struct hda_gen_spec *spec = codec->spec;
5557 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
5561 struct hda_codec *codec,
5564 struct hda_gen_spec *spec = codec->spec;
5565 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
5575 struct hda_codec *codec,
5580 struct hda_gen_spec *spec = codec->spec;
5582 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
5584 call_pcm_capture_hook(hinfo, codec, substream,
5590 struct hda_codec *codec,
5593 struct hda_gen_spec *spec = codec->spec;
5595 snd_hda_codec_cleanup_stream(codec,
5597 call_pcm_capture_hook(hinfo, codec, substream,
5686 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
5688 struct hda_gen_spec *spec = codec->spec;
5693 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
5695 snd_hda_codec_setup_stream(codec, new_adc,
5705 struct hda_codec *codec,
5710 struct hda_gen_spec *spec = codec->spec;
5714 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
5715 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_PREPARE);
5720 struct hda_codec *codec,
5723 struct hda_gen_spec *spec = codec->spec;
5724 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
5726 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLEANUP);
5789 * @codec: the HDA codec
5793 int snd_hda_gen_build_pcms(struct hda_codec *codec)
5795 struct hda_gen_spec *spec = codec->spec;
5804 " Analog", codec->core.chip_name);
5805 info = snd_hda_codec_pcm_new(codec, "%s", spec->stream_name_analog);
5835 " Digital", codec->core.chip_name);
5836 info = snd_hda_codec_pcm_new(codec, "%s",
5840 codec->follower_dig_outs = spec->multiout.follower_dig_outs;
5870 " Alt Analog", codec->core.chip_name);
5871 info = snd_hda_codec_pcm_new(codec, "%s",
5907 static void set_output_and_unmute(struct hda_codec *codec, int path_idx)
5912 path = snd_hda_get_path_from_idx(codec, path_idx);
5916 restore_pin_ctl(codec, pin);
5917 snd_hda_activate_path(codec, path, path->active,
5918 aamix_default(codec->spec));
5919 set_pin_eapd(codec, pin, path->active);
5923 static void init_multi_out(struct hda_codec *codec)
5925 struct hda_gen_spec *spec = codec->spec;
5929 set_output_and_unmute(codec, spec->out_paths[i]);
5933 static void __init_extra_out(struct hda_codec *codec, int num_outs, int *paths)
5938 set_output_and_unmute(codec, paths[i]);
5942 static void init_extra_out(struct hda_codec *codec)
5944 struct hda_gen_spec *spec = codec->spec;
5947 __init_extra_out(codec, spec->autocfg.hp_outs, spec->hp_paths);
5949 __init_extra_out(codec, spec->autocfg.speaker_outs,
5954 static void init_multi_io(struct hda_codec *codec)
5956 struct hda_gen_spec *spec = codec->spec;
5962 path = get_multiio_path(codec, i);
5967 snd_hda_codec_get_pin_target(codec, pin);
5968 snd_hda_activate_path(codec, path, path->active,
5973 static void init_aamix_paths(struct hda_codec *codec)
5975 struct hda_gen_spec *spec = codec->spec;
5981 update_aamix_paths(codec, spec->aamix_mode, spec->out_paths[0],
5984 update_aamix_paths(codec, spec->aamix_mode, spec->hp_paths[0],
5987 update_aamix_paths(codec, spec->aamix_mode, spec->speaker_paths[0],
5993 static void init_analog_input(struct hda_codec *codec)
5995 struct hda_gen_spec *spec = codec->spec;
6001 if (is_input_pin(codec, nid))
6002 restore_pin_ctl(codec, nid);
6006 resume_path_from_idx(codec, spec->loopback_paths[i]);
6007 resume_path_from_idx(codec, spec->loopback_merge_path);
6013 static void init_input_src(struct hda_codec *codec)
6015 struct hda_gen_spec *spec = codec->spec;
6027 path = get_input_path(codec, c, i);
6032 snd_hda_activate_path(codec, path, active, false);
6036 update_hp_mic(codec, c, true);
6040 spec->cap_sync_hook(codec, NULL, NULL);
6044 static void init_digital(struct hda_codec *codec)
6046 struct hda_gen_spec *spec = codec->spec;
6051 set_output_and_unmute(codec, spec->digout_paths[i]);
6054 restore_pin_ctl(codec, pin);
6055 resume_path_from_idx(codec, spec->digin_path);
6062 static void clear_unsol_on_unused_pins(struct hda_codec *codec)
6067 snd_array_for_each(&codec->init_pins, i, pin) {
6069 if (is_jack_detectable(codec, nid) &&
6070 !snd_hda_jack_tbl_get(codec, nid))
6071 snd_hda_codec_write_cache(codec, nid, 0,
6078 * @codec: the HDA codec
6082 int snd_hda_gen_init(struct hda_codec *codec)
6084 struct hda_gen_spec *spec = codec->spec;
6087 spec->init_hook(codec);
6090 snd_hda_apply_verbs(codec);
6092 init_multi_out(codec);
6093 init_extra_out(codec);
6094 init_multi_io(codec);
6095 init_aamix_paths(codec);
6096 init_analog_input(codec);
6097 init_input_src(codec);
6098 init_digital(codec);
6100 clear_unsol_on_unused_pins(codec);
6102 sync_all_pin_power_ctls(codec);
6105 update_automute_all(codec);
6107 snd_hda_regmap_sync(codec);
6112 hda_call_check_power_status(codec, 0x01);
6119 * @codec: the HDA codec
6123 void snd_hda_gen_free(struct hda_codec *codec)
6125 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
6126 snd_hda_gen_spec_free(codec->spec);
6127 kfree(codec->spec);
6128 codec->spec = NULL;
6133 * snd_hda_gen_reboot_notify - Make codec enter D3 before rebooting
6134 * @codec: the HDA codec
6138 void snd_hda_gen_reboot_notify(struct hda_codec *codec)
6140 /* Make the codec enter D3 to avoid spurious noises from the internal
6143 snd_hda_codec_set_power_to_all(codec, codec->core.afg, AC_PWRST_D3);
6144 snd_hda_codec_write(codec, codec->core.afg, 0,
6153 * @codec: the HDA codec
6158 int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid)
6160 struct hda_gen_spec *spec = codec->spec;
6161 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
6168 * the generic codec support
6184 * snd_hda_parse_generic_codec - Generic codec parser
6185 * @codec: the HDA codec
6187 static int snd_hda_parse_generic_codec(struct hda_codec *codec)
6196 codec->spec = spec;
6198 err = snd_hda_parse_pin_defcfg(codec, &spec->autocfg, NULL, 0);
6202 err = snd_hda_gen_parse_auto_config(codec, &spec->autocfg);
6206 codec->patch_ops = generic_patch_ops;
6210 snd_hda_gen_free(codec);
6227 MODULE_DESCRIPTION("Generic HD-audio codec parser");