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);
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 mutex_lock(&codec->control_mutex);
1126 mutex_unlock(&codec->control_mutex);
1133 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1139 mutex_lock(&codec->control_mutex);
1151 mutex_unlock(&codec->control_mutex);
1156 static bool path_has_mixer(struct hda_codec *codec, int path_idx, int ctl_type)
1158 struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
1167 static const char *get_line_out_pfx(struct hda_codec *codec, int ch,
1170 struct hda_gen_spec *spec = codec->spec;
1175 !codec->force_pin_prefix &&
1183 !codec->force_pin_prefix &&
1197 !path_has_mixer(codec, spec->hp_paths[0], ctl_type))
1209 !path_has_mixer(codec, spec->speaker_paths[0], ctl_type))
1224 spk_lo_shared = !path_has_mixer(codec,
1227 hp_lo_shared = !path_has_mixer(codec, spec->hp_paths[0], ctl_type);
1285 static int assign_out_path_ctls(struct hda_codec *codec, struct nid_path *path)
1287 struct hda_gen_spec *spec = codec->spec;
1299 nid = look_for_out_vol_nid(codec, path);
1304 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
1310 nid = look_for_out_mute_nid(codec, path);
1312 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
1314 nid_has_mute(codec, nid, HDA_OUTPUT))
1318 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
1348 static hda_nid_t get_primary_out(struct hda_codec *codec, int idx)
1350 struct hda_gen_spec *spec = codec->spec;
1362 static inline hda_nid_t try_dac(struct hda_codec *codec,
1365 return is_reachable_path(codec, dac, pin) ? dac : 0;
1369 static int try_assign_dacs(struct hda_codec *codec, int num_outs,
1374 struct hda_gen_spec *spec = codec->spec;
1387 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1389 badness += assign_out_path_ctls(codec, path);
1394 dacs[i] = get_preferred_dac(codec, pin);
1396 if (is_dac_already_used(codec, dacs[i]))
1403 dacs[i] = look_for_dac(codec, pin, false);
1407 if (is_reachable_path(codec, dacs[j], pin)) {
1410 invalidate_nid_path(codec, path_idx[j]);
1419 dac = try_dac(codec, get_primary_out(codec, i), pin);
1421 dac = try_dac(codec, dacs[0], pin);
1423 dac = try_dac(codec, get_primary_out(codec, i), pin);
1431 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
1441 path = snd_hda_add_new_path(codec, dac, pin, -spec->mixer_nid);
1444 path = snd_hda_add_new_path(codec, dac, pin, 0);
1450 /* print_nid_path(codec, "output", path); */
1452 path_idx[i] = snd_hda_get_path_idx(codec, path);
1453 badness += assign_out_path_ctls(codec, path);
1461 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
1463 struct hda_gen_spec *spec = codec->spec;
1469 if (!nid || is_dac_already_used(codec, nid))
1471 if (is_reachable_path(codec, nid, pin)) {
1481 static bool can_be_multiio_pin(struct hda_codec *codec,
1486 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1491 caps = snd_hda_query_pin_caps(codec, nid);
1498 static int count_multiio_pins(struct hda_codec *codec, hda_nid_t reference_pin)
1500 struct hda_gen_spec *spec = codec->spec;
1502 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1511 if (can_be_multiio_pin(codec, location,
1527 static int fill_multi_ios(struct hda_codec *codec,
1531 struct hda_gen_spec *spec = codec->spec;
1534 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1543 num_pins = count_multiio_pins(codec, reference_pin);
1554 if (!can_be_multiio_pin(codec, location, nid))
1564 dac = get_dac_if_single(codec, nid);
1566 dac = look_for_dac(codec, nid, false);
1571 path = snd_hda_add_new_path(codec, dac, nid,
1577 /* print_nid_path(codec, "multiio", path); */
1581 snd_hda_get_path_idx(codec, path);
1605 path = snd_hda_get_path_from_idx(codec, spec->out_paths[cfg->line_outs + i]);
1606 badness += assign_out_path_ctls(codec, path);
1613 static bool map_singles(struct hda_codec *codec, int outs,
1616 struct hda_gen_spec *spec = codec->spec;
1624 dac = get_dac_if_single(codec, pins[i]);
1627 path = snd_hda_add_new_path(codec, dac, pins[i],
1630 path = snd_hda_add_new_path(codec, dac, pins[i], 0);
1634 /* print_nid_path(codec, "output", path); */
1636 path_idx[i] = snd_hda_get_path_idx(codec, path);
1649 static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
1651 struct hda_gen_spec *spec = codec->spec;
1655 path = snd_hda_get_path_from_idx(codec, path_idx);
1662 path = snd_hda_add_new_path(codec, dac, pin, spec->mixer_nid);
1673 path = snd_hda_add_new_path(codec, dac, pin,
1678 /* print_nid_path(codec, "output-aamix", path); */
1681 return snd_hda_get_path_idx(codec, path);
1685 static bool indep_hp_possible(struct hda_codec *codec)
1687 struct hda_gen_spec *spec = codec->spec;
1696 path = snd_hda_get_path_from_idx(codec, idx);
1708 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
1713 path = snd_hda_get_path_from_idx(codec, spec->speaker_paths[i]);
1724 static void refill_shared_dacs(struct hda_codec *codec, int num_outs,
1733 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1741 static int fill_and_eval_dacs(struct hda_codec *codec,
1745 struct hda_gen_spec *spec = codec->spec;
1774 mapped = map_singles(codec, cfg->line_outs,
1778 mapped |= map_singles(codec, cfg->hp_outs,
1782 mapped |= map_singles(codec, cfg->speaker_outs,
1789 err = fill_multi_ios(codec, cfg->line_out_pins[0], true);
1796 badness += try_assign_dacs(codec, cfg->line_outs, cfg->line_out_pins,
1803 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1810 err = try_assign_dacs(codec, cfg->hp_outs, cfg->hp_pins,
1819 err = try_assign_dacs(codec, cfg->speaker_outs,
1830 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1838 check_aamix_out_path(codec, spec->out_paths[0]);
1841 check_aamix_out_path(codec, spec->hp_paths[0]);
1844 check_aamix_out_path(codec, spec->speaker_paths[0]);
1849 if (count_multiio_pins(codec, cfg->hp_pins[0]) >= 2)
1877 if (spec->indep_hp && !indep_hp_possible(codec))
1882 refill_shared_dacs(codec, cfg->hp_outs,
1886 refill_shared_dacs(codec, cfg->speaker_outs,
1897 codec_dbg(codec, fmt, ##__VA_ARGS__)
1900 do { if (0) codec_dbg(codec, fmt, ##__VA_ARGS__); } while (0)
1904 static inline void print_nid_path_idx(struct hda_codec *codec,
1909 path = snd_hda_get_path_from_idx(codec, idx);
1911 print_nid_path(codec, pfx, path);
1914 static void debug_show_configs(struct hda_codec *codec,
1917 struct hda_gen_spec *spec = codec->spec;
1930 print_nid_path_idx(codec, " out", spec->out_paths[i]);
1937 print_nid_path_idx(codec, " mio",
1948 print_nid_path_idx(codec, " hp ", spec->hp_paths[i]);
1958 print_nid_path_idx(codec, " spk", spec->speaker_paths[i]);
1960 print_nid_path_idx(codec, " mix", spec->aamix_out_paths[i]);
1963 #define debug_show_configs(codec, cfg) /* NOP */
1966 /* find all available DACs of the codec */
1967 static void fill_all_dac_nids(struct hda_codec *codec)
1969 struct hda_gen_spec *spec = codec->spec;
1974 for_each_hda_codec_node(nid, codec) {
1975 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
1978 codec_err(codec, "Too many DACs!\n");
1985 static int parse_output_paths(struct hda_codec *codec)
1987 struct hda_gen_spec *spec = codec->spec;
2003 badness = fill_and_eval_dacs(codec, fill_hardwired,
2012 debug_show_configs(codec, cfg);
2064 fill_and_eval_dacs(codec, best_wired, best_mio);
2068 debug_show_configs(codec, cfg);
2072 path = snd_hda_get_path_from_idx(codec, spec->out_paths[0]);
2074 spec->vmaster_nid = look_for_out_vol_nid(codec, path);
2076 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2088 set_pin_targets(codec, cfg->line_outs, cfg->line_out_pins, val);
2090 set_pin_targets(codec, cfg->hp_outs, cfg->hp_pins, PIN_HP);
2093 set_pin_targets(codec, cfg->speaker_outs,
2098 if (spec->indep_hp && !indep_hp_possible(codec))
2106 static int create_multi_out_ctls(struct hda_codec *codec,
2109 struct hda_gen_spec *spec = codec->spec;
2121 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
2125 name = get_line_out_pfx(codec, i, &index, NID_PATH_VOL_CTL);
2128 err = add_vol_ctl(codec, "Center", 0, 1, path);
2131 err = add_vol_ctl(codec, "LFE", 0, 2, path);
2135 err = add_stereo_vol(codec, name, index, path);
2140 name = get_line_out_pfx(codec, i, &index, NID_PATH_MUTE_CTL);
2142 err = add_sw_ctl(codec, "Center", 0, 1, path);
2145 err = add_sw_ctl(codec, "LFE", 0, 2, path);
2149 err = add_stereo_sw(codec, name, index, path);
2157 static int create_extra_out(struct hda_codec *codec, int path_idx,
2163 path = snd_hda_get_path_from_idx(codec, path_idx);
2166 err = add_stereo_vol(codec, pfx, cidx, path);
2169 err = add_stereo_sw(codec, pfx, cidx, path);
2176 static int create_extra_outs(struct hda_codec *codec, int num_pins,
2196 err = create_extra_out(codec, paths[i], name, idx);
2203 static int create_hp_out_ctls(struct hda_codec *codec)
2205 struct hda_gen_spec *spec = codec->spec;
2206 return create_extra_outs(codec, spec->autocfg.hp_outs,
2211 static int create_speaker_out_ctls(struct hda_codec *codec)
2213 struct hda_gen_spec *spec = codec->spec;
2214 return create_extra_outs(codec, spec->autocfg.speaker_outs,
2223 static void call_hp_automute(struct hda_codec *codec,
2234 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2235 struct hda_gen_spec *spec = codec->spec;
2240 static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
2247 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2248 struct hda_gen_spec *spec = codec->spec;
2268 update_aamix_paths(codec, spec->aamix_mode,
2273 update_aamix_paths(codec, spec->aamix_mode,
2285 call_hp_automute(codec, NULL);
2302 static int create_indep_hp_ctls(struct hda_codec *codec)
2304 struct hda_gen_spec *spec = codec->spec;
2332 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2333 struct hda_gen_spec *spec = codec->spec;
2349 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2350 struct hda_gen_spec *spec = codec->spec;
2357 get_multiio_path(struct hda_codec *codec, int idx)
2359 struct hda_gen_spec *spec = codec->spec;
2360 return snd_hda_get_path_from_idx(codec,
2364 static void update_automute_all(struct hda_codec *codec);
2374 static int set_multi_io(struct hda_codec *codec, int idx, bool output)
2376 struct hda_gen_spec *spec = codec->spec;
2380 path = get_multiio_path(codec, idx);
2388 set_pin_target(codec, nid, PIN_OUT, true);
2389 snd_hda_activate_path(codec, path, true, aamix_default(spec));
2390 set_pin_eapd(codec, nid, true);
2392 set_pin_eapd(codec, nid, false);
2393 snd_hda_activate_path(codec, path, false, aamix_default(spec));
2394 set_pin_target(codec, nid, spec->multi_io[idx].ctl_in, true);
2395 path_power_down_sync(codec, path);
2399 update_automute_all(codec);
2407 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2408 struct hda_gen_spec *spec = codec->spec;
2418 set_multi_io(codec, i, i < ch);
2434 static int create_multi_channel_mode(struct hda_codec *codec)
2436 struct hda_gen_spec *spec = codec->spec;
2454 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2455 struct hda_gen_spec *spec = codec->spec;
2460 static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
2464 struct hda_gen_spec *spec = codec->spec;
2467 nomix_path = snd_hda_get_path_from_idx(codec, nomix_path_idx);
2468 mix_path = snd_hda_get_path_from_idx(codec, mix_path_idx);
2480 snd_hda_activate_path(codec, nomix_path, false, true);
2481 snd_hda_activate_path(codec, mix_path, true, true);
2482 path_power_down_sync(codec, nomix_path);
2484 snd_hda_activate_path(codec, mix_path, false, false);
2485 snd_hda_activate_path(codec, nomix_path, true, false);
2486 path_power_down_sync(codec, mix_path);
2491 static void update_output_paths(struct hda_codec *codec, int num_outs,
2494 struct hda_gen_spec *spec = codec->spec;
2499 path = snd_hda_get_path_from_idx(codec, paths[i]);
2501 snd_hda_activate_path(codec, path, path->active,
2509 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2510 struct hda_gen_spec *spec = codec->spec;
2518 update_aamix_paths(codec, val, spec->out_paths[0],
2521 update_aamix_paths(codec, val, spec->hp_paths[0],
2524 update_aamix_paths(codec, val, spec->speaker_paths[0],
2528 update_output_paths(codec, cfg->line_outs, spec->out_paths);
2530 update_output_paths(codec, cfg->hp_outs, spec->hp_paths);
2532 update_output_paths(codec, cfg->speaker_outs,
2546 static int create_loopback_mixing_ctl(struct hda_codec *codec)
2548 struct hda_gen_spec *spec = codec->spec;
2562 static void call_update_outputs(struct hda_codec *codec);
2565 static void update_hp_mic(struct hda_codec *codec, int adc_mux, bool force)
2567 struct hda_gen_spec *spec = codec->spec;
2576 val = snd_hda_codec_get_pin_target(codec, pin);
2586 val = snd_hda_get_default_vref(codec, pin);
2587 /* if the HP pin doesn't support VREF and the codec driver gives an
2592 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
2594 snd_hda_set_pin_ctl_cache(codec, vref_pin,
2603 set_pin_target(codec, pin, val, true);
2604 call_hp_automute(codec, NULL);
2609 static int create_hp_mic(struct hda_codec *codec)
2611 struct hda_gen_spec *spec = codec->spec;
2625 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2643 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2654 codec_dbg(codec, "Enable shared I/O jack on NID 0x%x\n", nid);
2662 static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin);
2677 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2679 if (snd_hda_codec_get_pin_target(codec, nid) == PIN_HP)
2689 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2694 if (snd_hda_codec_get_pin_target(codec, nid) == val)
2696 snd_hda_set_pin_ctl_cache(codec, nid, val);
2707 static bool find_kctl_name(struct hda_codec *codec, const char *name, int idx)
2709 struct hda_gen_spec *spec = codec->spec;
2720 static void get_jack_mode_name(struct hda_codec *codec, hda_nid_t pin,
2723 struct hda_gen_spec *spec = codec->spec;
2726 snd_hda_get_pin_label(codec, pin, &spec->autocfg, name, name_len, &idx);
2729 for (; find_kctl_name(codec, name, idx); idx++)
2733 static int get_out_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2735 struct hda_gen_spec *spec = codec->spec;
2737 unsigned int pincap = snd_hda_query_pin_caps(codec, pin);
2744 static int create_out_jack_modes(struct hda_codec *codec, int num_pins,
2747 struct hda_gen_spec *spec = codec->spec;
2754 if (get_out_jack_num_items(codec, pin) > 1) {
2757 get_jack_mode_name(codec, pin, name, sizeof(name));
2781 static unsigned int get_vref_caps(struct hda_codec *codec, hda_nid_t pin)
2785 pincap = snd_hda_query_pin_caps(codec, pin);
2824 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2826 unsigned int vref_caps = get_vref_caps(codec, nid);
2839 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2841 unsigned int vref_caps = get_vref_caps(codec, nid);
2844 idx = snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_VREFEN;
2852 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2854 unsigned int vref_caps = get_vref_caps(codec, nid);
2857 val = snd_hda_codec_get_pin_target(codec, nid);
2864 snd_hda_set_pin_ctl_cache(codec, nid, val);
2875 static int get_in_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
2877 struct hda_gen_spec *spec = codec->spec;
2880 nitems = hweight32(get_vref_caps(codec, pin));
2884 static int create_in_jack_mode(struct hda_codec *codec, hda_nid_t pin)
2886 struct hda_gen_spec *spec = codec->spec;
2895 defcfg = snd_hda_codec_get_pincfg(codec, pin);
2900 if (get_in_jack_num_items(codec, pin) <= 1)
2903 get_jack_mode_name(codec, pin, name, sizeof(name));
2917 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2919 int out_jacks = get_out_jack_num_items(codec, nid);
2920 int in_jacks = get_in_jack_num_items(codec, nid);
2938 unsigned int vref_caps = get_vref_caps(codec, nid);
2948 static int get_cur_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t nid)
2950 int out_jacks = get_out_jack_num_items(codec, nid);
2951 int in_jacks = get_in_jack_num_items(codec, nid);
2952 unsigned int val = snd_hda_codec_get_pin_target(codec, nid);
2961 unsigned int vref_caps = get_vref_caps(codec, nid);
2972 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2975 get_cur_hp_mic_jack_mode(codec, nid);
2982 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2984 int out_jacks = get_out_jack_num_items(codec, nid);
2985 int in_jacks = get_in_jack_num_items(codec, nid);
2988 oldval = get_cur_hp_mic_jack_mode(codec, nid);
3001 unsigned int vref_caps = get_vref_caps(codec, nid);
3002 val = snd_hda_codec_get_pin_target(codec, nid);
3006 val = snd_hda_get_default_vref(codec, nid) | PIN_IN;
3008 snd_hda_set_pin_ctl_cache(codec, nid, val);
3009 call_hp_automute(codec, NULL);
3021 static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin)
3023 struct hda_gen_spec *spec = codec->spec;
3057 static bool look_for_mix_leaf_ctls(struct hda_codec *codec, hda_nid_t mix_nid,
3065 idx = snd_hda_get_conn_index(codec, mix_nid, pin, true);
3070 if (nid_has_volume(codec, mix_nid, HDA_INPUT))
3072 if (nid_has_mute(codec, mix_nid, HDA_INPUT))
3078 num_conns = snd_hda_get_conn_list(codec, mix_nid, &list);
3082 if (!*mix_val && nid_has_volume(codec, nid, HDA_OUTPUT) &&
3083 !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_VOL_CTL))
3085 if (!*mute_val && nid_has_mute(codec, nid, HDA_OUTPUT) &&
3086 !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_MUTE_CTL))
3093 static int new_analog_input(struct hda_codec *codec, int input_idx,
3097 struct hda_gen_spec *spec = codec->spec;
3102 if (!look_for_mix_leaf_ctls(codec, mix_nid, pin, &mix_val, &mute_val))
3105 path = snd_hda_add_new_path(codec, pin, mix_nid, 0);
3108 print_nid_path(codec, "loopback", path);
3109 spec->loopback_paths[input_idx] = snd_hda_get_path_idx(codec, path);
3134 path = snd_hda_add_new_path(codec, spec->mixer_nid,
3137 print_nid_path(codec, "loopback-merge", path);
3142 snd_hda_get_path_idx(codec, path);
3149 static int is_input_pin(struct hda_codec *codec, hda_nid_t nid)
3151 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
3155 /* Parse the codec tree and retrieve ADCs */
3156 static int fill_adc_nids(struct hda_codec *codec)
3158 struct hda_gen_spec *spec = codec->spec;
3164 for_each_hda_codec_node(nid, codec) {
3165 unsigned int caps = get_wcaps(codec, nid);
3186 static int check_dyn_adc_switch(struct hda_codec *codec)
3188 struct hda_gen_spec *spec = codec->spec;
3217 codec_dbg(codec, "enabling ADC switching\n");
3228 invalidate_nid_path(codec,
3242 codec_dbg(codec, "reducing to a single ADC\n");
3254 static int parse_capture_source(struct hda_codec *codec, hda_nid_t pin,
3258 struct hda_gen_spec *spec = codec->spec;
3268 if (!is_reachable_path(codec, pin, adc))
3270 path = snd_hda_add_new_path(codec, pin, adc, anchor);
3273 print_nid_path(codec, "input", path);
3275 snd_hda_get_path_idx(codec, path);
3281 snd_hda_add_imux_item(codec, imux, label, cfg_idx, NULL);
3296 static int fill_input_pin_labels(struct hda_codec *codec)
3298 struct hda_gen_spec *spec = codec->spec;
3307 if (!is_input_pin(codec, pin))
3310 label = hda_get_autocfg_input_label(codec, cfg, i);
3329 static int create_input_ctls(struct hda_codec *codec)
3331 struct hda_gen_spec *spec = codec->spec;
3338 num_adcs = fill_adc_nids(codec);
3342 err = fill_input_pin_labels(codec);
3350 if (!is_input_pin(codec, pin))
3355 val |= snd_hda_get_default_vref(codec, pin);
3357 !snd_hda_codec_get_pin_target(codec, pin))
3358 set_pin_target(codec, pin, val, false);
3361 if (is_reachable_path(codec, pin, mixer)) {
3362 err = new_analog_input(codec, i, pin,
3371 err = parse_capture_source(codec, pin, i, num_adcs,
3377 err = create_in_jack_mode(codec, pin);
3385 err = parse_capture_source(codec, mixer, CFG_IDX_MIX, num_adcs,
3402 static struct nid_path *get_input_path(struct hda_codec *codec, int adc_idx, int imux_idx)
3404 struct hda_gen_spec *spec = codec->spec;
3415 return snd_hda_get_path_from_idx(codec, spec->input_paths[imux_idx][adc_idx]);
3418 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3424 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3425 struct hda_gen_spec *spec = codec->spec;
3432 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3433 struct hda_gen_spec *spec = codec->spec;
3444 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3446 return mux_select(codec, adc_idx,
3470 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3471 struct hda_gen_spec *spec = codec->spec;
3478 mutex_lock(&codec->control_mutex);
3480 path = get_input_path(codec, adc_idx, i);
3492 mutex_unlock(&codec->control_mutex);
3494 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3544 static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
3556 if (nid_has_volume(codec, nid, HDA_OUTPUT))
3559 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
3561 if (!depth && codec->single_adc_amp)
3568 if (nid_has_mute(codec, nid, HDA_OUTPUT))
3571 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
3573 if (!depth && codec->single_adc_amp)
3583 static bool is_inv_dmic_pin(struct hda_codec *codec, hda_nid_t nid)
3585 struct hda_gen_spec *spec = codec->spec;
3597 val = snd_hda_codec_get_pincfg(codec, nid);
3607 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3608 struct hda_gen_spec *spec = codec->spec;
3616 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3621 static int add_single_cap_ctl(struct hda_codec *codec, const char *label,
3625 struct hda_gen_spec *spec = codec->spec;
3673 static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx,
3678 err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl, inv_dmic);
3681 err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl, inv_dmic);
3688 static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx,
3691 struct hda_gen_spec *spec = codec->spec;
3716 static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type)
3722 path = get_input_path(codec, 0, idx);
3729 path = get_input_path(codec, 0, i);
3737 static int create_multi_cap_vol_ctl(struct hda_codec *codec)
3739 struct hda_gen_spec *spec = codec->spec;
3750 inv_dmic = is_inv_dmic_pin(codec, spec->imux_pins[i]);
3753 err = add_single_cap_ctl(codec,
3757 get_first_cap_ctl(codec, i, type),
3766 static int create_capture_mixers(struct hda_codec *codec)
3768 struct hda_gen_spec *spec = codec->spec;
3796 path = get_input_path(codec, n, i);
3799 parse_capvol_in_path(codec, path);
3804 if (!same_amp_caps(codec, vol,
3812 if (!same_amp_caps(codec, sw,
3816 if (is_inv_dmic_pin(codec, spec->imux_pins[i]))
3821 err = create_single_cap_vol_ctl(codec, n, vol, sw,
3824 err = create_bind_cap_vol_ctl(codec, n, vol, sw);
3826 err = create_multi_cap_vol_ctl(codec);
3839 static bool check_boost_vol(struct hda_codec *codec, hda_nid_t nid,
3844 if (!nid_has_volume(codec, nid, dir) ||
3845 is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
3846 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
3849 step = (query_amp_caps(codec, nid, dir) & AC_AMPCAP_STEP_SIZE)
3857 static unsigned int look_for_boost_amp(struct hda_codec *codec,
3868 if (depth && check_boost_vol(codec, nid, HDA_OUTPUT, 0)) {
3871 } else if (check_boost_vol(codec, nid, HDA_INPUT,
3882 static int parse_mic_boost(struct hda_codec *codec)
3884 struct hda_gen_spec *spec = codec->spec;
3906 path = get_input_path(codec, 0, i);
3910 val = look_for_boost_amp(codec, path);
3931 static int create_mute_led_cdev(struct hda_codec *codec,
3936 struct hda_gen_spec *spec = codec->spec;
3941 cdev = devm_kzalloc(&codec->core.dev, sizeof(*cdev), GFP_KERNEL);
3952 err = led_classdev_register(&codec->core.dev, cdev);
3961 * @codec: the HDA codec
3964 int snd_hda_gen_add_mute_led_cdev(struct hda_codec *codec,
3968 struct hda_gen_spec *spec = codec->spec;
3972 err = create_mute_led_cdev(codec, callback, false);
3974 codec_warn(codec, "failed to create a mute LED cdev\n");
3980 codec_err(codec, "vmaster hook already present before cdev!\n");
3989 * @codec: the HDA codec
3992 * Called from the codec drivers for offering the mic mute LED controls.
4001 int snd_hda_gen_add_micmute_led_cdev(struct hda_codec *codec,
4005 struct hda_gen_spec *spec = codec->spec;
4009 err = create_mute_led_cdev(codec, callback, true);
4011 codec_warn(codec, "failed to create a mic-mute LED cdev\n");
4025 static void parse_digital(struct hda_codec *codec)
4027 struct hda_gen_spec *spec = codec->spec;
4036 dig_nid = look_for_dac(codec, pin, true);
4039 path = snd_hda_add_new_path(codec, dig_nid, pin, 0);
4042 print_nid_path(codec, "digout", path);
4045 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
4046 set_pin_target(codec, pin, PIN_OUT, false);
4061 for_each_hda_codec_node(dig_nid, codec) {
4062 unsigned int wcaps = get_wcaps(codec, dig_nid);
4067 path = snd_hda_add_new_path(codec, pin, dig_nid, 0);
4069 print_nid_path(codec, "digin", path);
4073 spec->digin_path = snd_hda_get_path_idx(codec, path);
4074 set_pin_target(codec, pin, PIN_IN, false);
4086 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur);
4089 static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
4092 struct hda_gen_spec *spec = codec->spec;
4105 old_path = get_input_path(codec, adc_idx, spec->cur_mux[adc_idx]);
4109 snd_hda_activate_path(codec, old_path, false, false);
4114 update_hp_mic(codec, adc_idx, false);
4117 dyn_adc_pcm_resetup(codec, idx);
4119 path = get_input_path(codec, adc_idx, idx);
4124 snd_hda_activate_path(codec, path, true, false);
4126 spec->cap_sync_hook(codec, NULL, NULL);
4127 path_power_down_sync(codec, old_path);
4136 static hda_nid_t set_path_power(struct hda_codec *codec, hda_nid_t nid,
4139 struct hda_gen_spec *spec = codec->spec;
4158 last = path_power_update(codec, path, true);
4168 static bool detect_pin_state(struct hda_codec *codec, hda_nid_t pin)
4170 if (!is_jack_detectable(codec, pin))
4172 return snd_hda_jack_detect_state(codec, pin) != HDA_JACK_NOT_PRESENT;
4181 static hda_nid_t set_pin_power_jack(struct hda_codec *codec, hda_nid_t pin,
4186 if (!codec->power_save_node)
4189 on = detect_pin_state(codec, pin);
4193 return set_path_power(codec, pin, on, -1);
4196 static void pin_power_callback(struct hda_codec *codec,
4201 sync_power_state_change(codec,
4202 set_pin_power_jack(codec, jack->nid, on));
4206 static void pin_power_up_callback(struct hda_codec *codec,
4209 pin_power_callback(codec, jack, true);
4213 static void pin_power_down_callback(struct hda_codec *codec,
4216 pin_power_callback(codec, jack, false);
4220 static void add_pin_power_ctls(struct hda_codec *codec, int num_pins,
4228 if (is_jack_detectable(codec, pins[i]))
4229 snd_hda_jack_detect_enable_callback(codec, pins[i], cb);
4231 set_path_power(codec, pins[i], true, -1);
4238 static void add_all_pin_power_ctls(struct hda_codec *codec, bool on)
4240 struct hda_gen_spec *spec = codec->spec;
4244 if (!codec->power_save_node)
4246 add_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins, on);
4248 add_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins, on);
4250 add_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins, on);
4252 add_pin_power_ctls(codec, 1, &cfg->inputs[i].pin, on);
4256 static void sync_pin_power_ctls(struct hda_codec *codec, int num_pins,
4262 if (is_jack_detectable(codec, pins[i]))
4263 set_pin_power_jack(codec, pins[i], -1);
4267 static void sync_all_pin_power_ctls(struct hda_codec *codec)
4269 struct hda_gen_spec *spec = codec->spec;
4273 if (!codec->power_save_node)
4275 sync_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins);
4277 sync_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins);
4279 sync_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins);
4281 sync_pin_power_ctls(codec, 1, &cfg->inputs[i].pin);
4285 static int add_fake_paths(struct hda_codec *codec, hda_nid_t nid,
4288 struct hda_gen_spec *spec = codec->spec;
4295 if (get_nid_path(codec, nid, pins[i], 0))
4310 static int add_fake_beep_paths(struct hda_codec *codec)
4312 struct hda_gen_spec *spec = codec->spec;
4317 if (!codec->power_save_node || !nid)
4319 err = add_fake_paths(codec, nid, cfg->line_outs, cfg->line_out_pins);
4323 err = add_fake_paths(codec, nid, cfg->hp_outs, cfg->hp_pins);
4328 err = add_fake_paths(codec, nid, cfg->speaker_outs,
4339 set_path_power(beep->codec, beep->nid, -1, on);
4344 * @codec: the HDA codec
4347 int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin)
4349 struct hda_gen_spec *spec = codec->spec;
4370 static bool detect_jacks(struct hda_codec *codec, int num_pins, const hda_nid_t *pins)
4380 if (snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_IN_EN)
4382 if (snd_hda_jack_detect_state(codec, nid) == HDA_JACK_PRESENT)
4389 static void do_automute(struct hda_codec *codec, int num_pins, const hda_nid_t *pins,
4392 struct hda_gen_spec *spec = codec->spec;
4401 oldval = snd_hda_codec_get_pin_target(codec, nid);
4409 path = snd_hda_get_path_from_idx(codec, paths[i]);
4435 update_pin_ctl(codec, nid, val);
4438 set_pin_eapd(codec, nid, !mute);
4439 if (codec->power_save_node) {
4442 on = detect_pin_state(codec, nid);
4443 set_path_power(codec, nid, on, -1);
4450 * @codec: the HDA codec
4454 void snd_hda_gen_update_outputs(struct hda_codec *codec)
4456 struct hda_gen_spec *spec = codec->spec;
4468 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
4481 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
4496 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
4501 static void call_update_outputs(struct hda_codec *codec)
4503 struct hda_gen_spec *spec = codec->spec;
4505 spec->automute_hook(codec);
4507 snd_hda_gen_update_outputs(codec);
4510 if (spec->auto_mute_via_amp && !codec->bus->shutdown)
4516 * @codec: the HDA codec
4519 void snd_hda_gen_hp_automute(struct hda_codec *codec,
4522 struct hda_gen_spec *spec = codec->spec;
4532 spec->hp_jack_present = detect_jacks(codec, num_pins, pins);
4535 call_update_outputs(codec);
4541 * @codec: the HDA codec
4544 void snd_hda_gen_line_automute(struct hda_codec *codec,
4547 struct hda_gen_spec *spec = codec->spec;
4556 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
4560 call_update_outputs(codec);
4566 * @codec: the HDA codec
4569 void snd_hda_gen_mic_autoswitch(struct hda_codec *codec,
4572 struct hda_gen_spec *spec = codec->spec;
4581 if (snd_hda_codec_get_pin_target(codec, pin) & AC_PINCTL_OUT_EN)
4583 if (snd_hda_jack_detect_state(codec, pin) == HDA_JACK_PRESENT) {
4584 mux_select(codec, 0, spec->am_entry[i].idx);
4588 mux_select(codec, 0, spec->am_entry[0].idx);
4593 static void call_hp_automute(struct hda_codec *codec,
4596 struct hda_gen_spec *spec = codec->spec;
4598 spec->hp_automute_hook(codec, jack);
4600 snd_hda_gen_hp_automute(codec, jack);
4603 static void call_line_automute(struct hda_codec *codec,
4606 struct hda_gen_spec *spec = codec->spec;
4608 spec->line_automute_hook(codec, jack);
4610 snd_hda_gen_line_automute(codec, jack);
4613 static void call_mic_autoswitch(struct hda_codec *codec,
4616 struct hda_gen_spec *spec = codec->spec;
4618 spec->mic_autoswitch_hook(codec, jack);
4620 snd_hda_gen_mic_autoswitch(codec, jack);
4624 static void update_automute_all(struct hda_codec *codec)
4626 call_hp_automute(codec, NULL);
4627 call_line_automute(codec, NULL);
4628 call_mic_autoswitch(codec, NULL);
4637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4638 struct hda_gen_spec *spec = codec->spec;
4651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4652 struct hda_gen_spec *spec = codec->spec;
4666 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4667 struct hda_gen_spec *spec = codec->spec;
4700 call_update_outputs(codec);
4712 static int add_automute_mode_enum(struct hda_codec *codec)
4714 struct hda_gen_spec *spec = codec->spec;
4725 static int check_auto_mute_availability(struct hda_codec *codec)
4727 struct hda_gen_spec *spec = codec->spec;
4760 if (!is_jack_detectable(codec, nid))
4762 codec_dbg(codec, "Enable HP auto-muting on NID 0x%x\n", nid);
4763 snd_hda_jack_detect_enable_callback(codec, nid,
4772 if (!is_jack_detectable(codec, nid))
4774 codec_dbg(codec, "Enable Line-Out auto-muting on NID 0x%x\n", nid);
4775 snd_hda_jack_detect_enable_callback(codec, nid,
4790 err = add_automute_mode_enum(codec);
4798 static bool auto_mic_check_imux(struct hda_codec *codec)
4800 struct hda_gen_spec *spec = codec->spec;
4815 snd_hda_jack_detect_enable_callback(codec,
4832 static int check_auto_mic_availability(struct hda_codec *codec)
4834 struct hda_gen_spec *spec = codec->spec;
4847 attr = snd_hda_codec_get_pincfg(codec, nid);
4864 if (!is_jack_detectable(codec, nid))
4886 if (!auto_mic_check_imux(codec))
4892 codec_dbg(codec, "Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
4903 * @codec: the HDA codec
4907 unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
4911 struct hda_gen_spec *spec = codec->spec;
4913 if (!spec->power_down_unused && !codec->power_save_node)
4915 if (power_state != AC_PWRST_D0 || nid == codec->core.afg)
4917 if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER)
4919 if (is_active_nid_for_any(codec, nid))
4926 static void mute_all_mixer_nid(struct hda_codec *codec, hda_nid_t mix)
4932 nums = snd_hda_get_conn_list(codec, mix, &conn);
4933 has_amp = nid_has_mute(codec, mix, HDA_INPUT);
4936 update_amp(codec, mix, HDA_INPUT, i,
4938 else if (nid_has_volume(codec, conn[i], HDA_OUTPUT))
4939 update_amp(codec, conn[i], HDA_OUTPUT, 0,
4946 * @codec: the HDA codec
4952 void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on)
4954 if (codec->power_save_node)
4955 set_path_power(codec, nid, -1, on);
4962 * @codec: the HDA codec
4968 int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4971 struct hda_gen_spec *spec = codec->spec;
4974 parse_user_hints(codec);
4992 fill_all_dac_nids(codec);
5018 err = parse_output_paths(codec);
5021 err = create_multi_channel_mode(codec);
5024 err = create_multi_out_ctls(codec, cfg);
5027 err = create_hp_out_ctls(codec);
5030 err = create_speaker_out_ctls(codec);
5033 err = create_indep_hp_ctls(codec);
5036 err = create_loopback_mixing_ctl(codec);
5039 err = create_hp_mic(codec);
5042 err = create_input_ctls(codec);
5047 add_all_pin_power_ctls(codec, false);
5060 err = check_auto_mute_availability(codec);
5064 err = check_dyn_adc_switch(codec);
5068 err = check_auto_mic_availability(codec);
5076 err = parse_capture_source(codec, spec->mixer_nid,
5084 err = create_capture_mixers(codec);
5088 err = parse_mic_boost(codec);
5098 err = create_hp_mic_jack_mode(codec, spec->hp_mic_pin);
5105 err = create_out_jack_modes(codec, cfg->line_outs,
5111 err = create_out_jack_modes(codec, cfg->hp_outs,
5119 add_all_pin_power_ctls(codec, true);
5123 mute_all_mixer_nid(codec, spec->mixer_nid);
5126 parse_digital(codec);
5128 if (spec->power_down_unused || codec->power_save_node) {
5129 if (!codec->power_filter)
5130 codec->power_filter = snd_hda_gen_path_power_filter;
5131 if (!codec->patch_ops.stream_pm)
5132 codec->patch_ops.stream_pm = snd_hda_gen_stream_pm;
5136 err = snd_hda_attach_beep_device(codec, spec->beep_nid);
5139 if (codec->beep && codec->power_save_node) {
5140 err = add_fake_beep_paths(codec);
5143 codec->beep->power_hook = beep_power_hook;
5169 * @codec: the HDA codec
5173 int snd_hda_gen_build_controls(struct hda_codec *codec)
5175 struct hda_gen_spec *spec = codec->spec;
5179 err = snd_hda_add_new_ctls(codec, spec->kctls.list);
5185 err = snd_hda_create_dig_out_ctls(codec,
5192 err = snd_hda_create_spdif_share_sw(codec,
5200 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
5207 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
5208 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
5215 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
5216 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
5225 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute);
5232 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
5246 struct hda_codec *codec,
5250 struct hda_gen_spec *spec = codec->spec;
5252 spec->pcm_playback_hook(hinfo, codec, substream, action);
5256 struct hda_codec *codec,
5260 struct hda_gen_spec *spec = codec->spec;
5262 spec->pcm_capture_hook(hinfo, codec, substream, action);
5269 struct hda_codec *codec,
5272 struct hda_gen_spec *spec = codec->spec;
5276 err = snd_hda_multi_out_analog_open(codec,
5281 call_pcm_playback_hook(hinfo, codec, substream,
5289 struct hda_codec *codec,
5294 struct hda_gen_spec *spec = codec->spec;
5297 err = snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
5300 call_pcm_playback_hook(hinfo, codec, substream,
5306 struct hda_codec *codec,
5309 struct hda_gen_spec *spec = codec->spec;
5312 err = snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
5314 call_pcm_playback_hook(hinfo, codec, substream,
5320 struct hda_codec *codec,
5323 struct hda_gen_spec *spec = codec->spec;
5326 call_pcm_playback_hook(hinfo, codec, substream,
5333 struct hda_codec *codec,
5336 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_OPEN);
5341 struct hda_codec *codec,
5346 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
5347 call_pcm_capture_hook(hinfo, codec, substream,
5353 struct hda_codec *codec,
5356 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
5357 call_pcm_capture_hook(hinfo, codec, substream,
5363 struct hda_codec *codec,
5366 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLOSE);
5371 struct hda_codec *codec,
5374 struct hda_gen_spec *spec = codec->spec;
5382 call_pcm_playback_hook(hinfo, codec, substream,
5389 struct hda_codec *codec,
5392 struct hda_gen_spec *spec = codec->spec;
5395 call_pcm_playback_hook(hinfo, codec, substream,
5402 struct hda_codec *codec,
5407 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
5408 call_pcm_playback_hook(hinfo, codec, substream,
5414 struct hda_codec *codec,
5417 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
5418 call_pcm_playback_hook(hinfo, codec, substream,
5427 struct hda_codec *codec,
5430 struct hda_gen_spec *spec = codec->spec;
5431 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
5435 struct hda_codec *codec,
5440 struct hda_gen_spec *spec = codec->spec;
5441 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
5446 struct hda_codec *codec,
5449 struct hda_gen_spec *spec = codec->spec;
5450 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
5454 struct hda_codec *codec,
5457 struct hda_gen_spec *spec = codec->spec;
5458 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
5468 struct hda_codec *codec,
5473 struct hda_gen_spec *spec = codec->spec;
5475 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
5477 call_pcm_capture_hook(hinfo, codec, substream,
5483 struct hda_codec *codec,
5486 struct hda_gen_spec *spec = codec->spec;
5488 snd_hda_codec_cleanup_stream(codec,
5490 call_pcm_capture_hook(hinfo, codec, substream,
5579 static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
5581 struct hda_gen_spec *spec = codec->spec;
5586 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
5588 snd_hda_codec_setup_stream(codec, new_adc,
5598 struct hda_codec *codec,
5603 struct hda_gen_spec *spec = codec->spec;
5607 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
5608 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_PREPARE);
5613 struct hda_codec *codec,
5616 struct hda_gen_spec *spec = codec->spec;
5617 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
5619 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLEANUP);
5682 * @codec: the HDA codec
5686 int snd_hda_gen_build_pcms(struct hda_codec *codec)
5688 struct hda_gen_spec *spec = codec->spec;
5697 " Analog", codec->core.chip_name);
5698 info = snd_hda_codec_pcm_new(codec, "%s", spec->stream_name_analog);
5728 " Digital", codec->core.chip_name);
5729 info = snd_hda_codec_pcm_new(codec, "%s",
5733 codec->follower_dig_outs = spec->multiout.follower_dig_outs;
5763 " Alt Analog", codec->core.chip_name);
5764 info = snd_hda_codec_pcm_new(codec, "%s",
5800 static void set_output_and_unmute(struct hda_codec *codec, int path_idx)
5805 path = snd_hda_get_path_from_idx(codec, path_idx);
5809 restore_pin_ctl(codec, pin);
5810 snd_hda_activate_path(codec, path, path->active,
5811 aamix_default(codec->spec));
5812 set_pin_eapd(codec, pin, path->active);
5816 static void init_multi_out(struct hda_codec *codec)
5818 struct hda_gen_spec *spec = codec->spec;
5822 set_output_and_unmute(codec, spec->out_paths[i]);
5826 static void __init_extra_out(struct hda_codec *codec, int num_outs, int *paths)
5831 set_output_and_unmute(codec, paths[i]);
5835 static void init_extra_out(struct hda_codec *codec)
5837 struct hda_gen_spec *spec = codec->spec;
5840 __init_extra_out(codec, spec->autocfg.hp_outs, spec->hp_paths);
5842 __init_extra_out(codec, spec->autocfg.speaker_outs,
5847 static void init_multi_io(struct hda_codec *codec)
5849 struct hda_gen_spec *spec = codec->spec;
5855 path = get_multiio_path(codec, i);
5860 snd_hda_codec_get_pin_target(codec, pin);
5861 snd_hda_activate_path(codec, path, path->active,
5866 static void init_aamix_paths(struct hda_codec *codec)
5868 struct hda_gen_spec *spec = codec->spec;
5874 update_aamix_paths(codec, spec->aamix_mode, spec->out_paths[0],
5877 update_aamix_paths(codec, spec->aamix_mode, spec->hp_paths[0],
5880 update_aamix_paths(codec, spec->aamix_mode, spec->speaker_paths[0],
5886 static void init_analog_input(struct hda_codec *codec)
5888 struct hda_gen_spec *spec = codec->spec;
5894 if (is_input_pin(codec, nid))
5895 restore_pin_ctl(codec, nid);
5899 resume_path_from_idx(codec, spec->loopback_paths[i]);
5900 resume_path_from_idx(codec, spec->loopback_merge_path);
5906 static void init_input_src(struct hda_codec *codec)
5908 struct hda_gen_spec *spec = codec->spec;
5920 path = get_input_path(codec, c, i);
5925 snd_hda_activate_path(codec, path, active, false);
5929 update_hp_mic(codec, c, true);
5933 spec->cap_sync_hook(codec, NULL, NULL);
5937 static void init_digital(struct hda_codec *codec)
5939 struct hda_gen_spec *spec = codec->spec;
5944 set_output_and_unmute(codec, spec->digout_paths[i]);
5947 restore_pin_ctl(codec, pin);
5948 resume_path_from_idx(codec, spec->digin_path);
5955 static void clear_unsol_on_unused_pins(struct hda_codec *codec)
5960 snd_array_for_each(&codec->init_pins, i, pin) {
5962 if (is_jack_detectable(codec, nid) &&
5963 !snd_hda_jack_tbl_get(codec, nid))
5964 snd_hda_codec_write_cache(codec, nid, 0,
5971 * @codec: the HDA codec
5975 int snd_hda_gen_init(struct hda_codec *codec)
5977 struct hda_gen_spec *spec = codec->spec;
5980 spec->init_hook(codec);
5983 snd_hda_apply_verbs(codec);
5985 init_multi_out(codec);
5986 init_extra_out(codec);
5987 init_multi_io(codec);
5988 init_aamix_paths(codec);
5989 init_analog_input(codec);
5990 init_input_src(codec);
5991 init_digital(codec);
5993 clear_unsol_on_unused_pins(codec);
5995 sync_all_pin_power_ctls(codec);
5998 update_automute_all(codec);
6000 snd_hda_regmap_sync(codec);
6005 hda_call_check_power_status(codec, 0x01);
6012 * @codec: the HDA codec
6016 void snd_hda_gen_free(struct hda_codec *codec)
6018 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
6019 snd_hda_gen_spec_free(codec->spec);
6020 kfree(codec->spec);
6021 codec->spec = NULL;
6028 * @codec: the HDA codec
6033 int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid)
6035 struct hda_gen_spec *spec = codec->spec;
6036 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
6043 * the generic codec support
6058 * snd_hda_parse_generic_codec - Generic codec parser
6059 * @codec: the HDA codec
6061 static int snd_hda_parse_generic_codec(struct hda_codec *codec)
6070 codec->spec = spec;
6072 err = snd_hda_parse_pin_defcfg(codec, &spec->autocfg, NULL, 0);
6076 err = snd_hda_gen_parse_auto_config(codec, &spec->autocfg);
6080 codec->patch_ops = generic_patch_ops;
6084 snd_hda_gen_free(codec);
6101 MODULE_DESCRIPTION("Generic HD-audio codec parser");