Lines Matching refs:codec

78 	struct hda_codec *codec;
99 int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid,
102 void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid,
107 int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid,
110 int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid,
114 void (*pin_cvt_fixup)(struct hda_codec *codec,
132 struct hda_codec *codec;
172 /* hdmi interrupt trigger control flag for Nvidia codec */
197 static inline bool codec_has_acomp(struct hda_codec *codec)
199 struct hdmi_spec *spec = codec->spec;
203 #define codec_has_acomp(codec) false
251 static int pin_id_to_pin_index(struct hda_codec *codec,
254 struct hdmi_spec *spec = codec->spec;
272 codec_warn(codec, "HDMI: pin NID 0x%x not registered\n", pin_nid);
276 static int hinfo_to_pcm_index(struct hda_codec *codec,
279 struct hdmi_spec *spec = codec->spec;
286 codec_warn(codec, "HDMI: hinfo %p not tied to a PCM\n", hinfo);
290 static int hinfo_to_pin_index(struct hda_codec *codec,
293 struct hdmi_spec *spec = codec->spec;
304 codec_dbg(codec, "HDMI: hinfo %p (pcm %d) not registered\n", hinfo,
305 hinfo_to_pcm_index(codec, hinfo));
323 static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid)
325 struct hdmi_spec *spec = codec->spec;
332 codec_warn(codec, "HDMI: cvt NID 0x%x not registered\n", cvt_nid);
339 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
340 struct hdmi_spec *spec = codec->spec;
366 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
367 struct hdmi_spec *spec = codec->spec;
411 static int hdmi_create_eld_ctl(struct hda_codec *codec, int pcm_idx,
415 struct hdmi_spec *spec = codec->spec;
418 kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
427 err = snd_hda_ctl_add(codec, 0, kctl);
436 static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
441 val = snd_hda_codec_read(codec, pin_nid, 0,
449 static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
456 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
459 static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
462 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
465 static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
467 struct hdmi_spec *spec = codec->spec;
471 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
472 snd_hda_codec_write(codec, pin_nid, 0,
484 snd_hda_codec_write(codec, pin_nid, 0,
517 struct hda_codec *codec = per_pin->codec;
521 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
522 err = snd_card_proc_new(codec->card, name, &entry);
536 if (!per_pin->codec->bus->shutdown) {
559 static void hdmi_start_infoframe_trans(struct hda_codec *codec,
562 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
563 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
570 static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
573 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
574 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
578 static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
584 size = snd_hdmi_get_eld_size(codec, pin_nid);
585 codec_dbg(codec, "HDMI: ELD buf size is %d\n", size);
588 size = snd_hda_codec_read(codec, pin_nid, 0,
590 codec_dbg(codec, "HDMI: DIP GP[%d] buf size is %d\n", i, size);
595 static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
602 size = snd_hda_codec_read(codec, pin_nid, 0,
607 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
609 hdmi_write_dip_byte(codec, pin_nid, 0x0);
610 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
612 codec_dbg(codec, "dip index %d: %d != %d\n",
617 codec_dbg(codec,
638 static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
644 hdmi_debug_dip_size(codec, pin_nid);
645 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
647 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
649 hdmi_write_dip_byte(codec, pin_nid, dip[i]);
652 static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
658 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
659 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
664 val = snd_hda_codec_read(codec, pin_nid, 0,
673 static int hdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
676 snd_hda_set_dev_select(codec, nid, dev_id);
678 return snd_hdmi_get_eld(codec, nid, buf, eld_size);
681 static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
686 struct hdmi_spec *spec = codec->spec;
716 codec_dbg(codec, "HDMI: unknown connection type at pin NID 0x%x\n", pin_nid);
720 snd_hda_set_dev_select(codec, pin_nid, dev_id);
727 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
729 codec_dbg(codec, "%s: pin NID=0x%x channels=%d ca=0x%02x\n",
731 hdmi_stop_infoframe_trans(codec, pin_nid);
732 hdmi_fill_audio_infoframe(codec, pin_nid,
734 hdmi_start_infoframe_trans(codec, pin_nid);
738 static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
742 struct hdmi_spec *spec = codec->spec;
754 snd_hda_set_dev_select(codec, pin_nid, dev_id);
757 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
758 snd_hda_codec_write(codec, pin_nid, 0,
764 ca = snd_hdac_channel_allocation(&codec->core,
770 chmap->ops.set_channel_count(&codec->core, per_pin->cvt_nid,
781 spec->ops.pin_setup_infoframe(codec, pin_nid, dev_id,
793 static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid,
796 struct hdmi_spec *spec = codec->spec;
797 int pin_idx = pin_id_to_pin_index(codec, nid, dev_id);
806 static void jack_callback(struct hda_codec *codec,
810 if (codec_has_acomp(codec))
813 check_presence_and_report(codec, jack->nid, jack->dev_id);
816 static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res,
821 codec_dbg(codec,
823 codec->addr, jack->nid, jack->dev_id, !!(res & AC_UNSOL_RES_IA),
826 check_presence_and_report(codec, jack->nid, jack->dev_id);
829 static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
836 codec_info(codec,
838 codec->addr,
854 static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
860 if (codec_has_acomp(codec))
863 if (codec->dp_mst) {
867 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, dev_entry);
869 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, 0);
873 codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag);
878 hdmi_intrinsic_event(codec, res, jack);
880 hdmi_non_intrinsic_event(codec, res);
883 static void haswell_verify_D0(struct hda_codec *codec,
891 if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0))
892 snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
894 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) {
895 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
898 pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
900 codec_dbg(codec, "Haswell HDMI audio: Power for NID 0x%x is now D%d\n", nid, pwr);
912 static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
917 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
918 snd_hda_set_dev_select(codec, pin_nid, dev_id);
919 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
931 codec_dbg(codec,
938 snd_hda_codec_write(codec, pin_nid, 0,
947 static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
951 struct hdmi_spec *spec = codec->spec;
955 err = spec->ops.pin_hbr_setup(codec, pin_nid, dev_id,
959 codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n");
970 param = snd_hda_codec_read(codec, cvt_nid, 0,
979 snd_hda_codec_write(codec, cvt_nid, 0,
983 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
992 static int hdmi_choose_cvt(struct hda_codec *codec,
996 struct hdmi_spec *spec = codec->spec;
1008 cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid);
1050 static void intel_verify_pin_cvt_connect(struct hda_codec *codec,
1057 curr = snd_hda_codec_read(codec, pin_nid, 0,
1060 snd_hda_codec_write_cache(codec, pin_nid, 0,
1088 static void intel_not_share_assigned_cvt(struct hda_codec *codec,
1092 struct hdmi_spec *spec = codec->spec;
1122 dev_num = snd_hda_get_num_devices(codec, per_pin->pin_nid) + 1;
1134 dev_id_saved = snd_hda_get_dev_select(codec, nid);
1135 snd_hda_set_dev_select(codec, nid, per_pin->dev_id);
1136 curr = snd_hda_codec_read(codec, nid, 0,
1139 snd_hda_set_dev_select(codec, nid, dev_id_saved);
1145 * connection list are in the same order as in the codec.
1150 codec_dbg(codec,
1153 snd_hda_codec_write_cache(codec, nid, 0,
1159 snd_hda_set_dev_select(codec, nid, dev_id_saved);
1164 static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,
1168 struct hdmi_spec *spec = codec->spec;
1177 intel_not_share_assigned_cvt(codec, pin_nid, dev_id, mux_idx);
1181 static void pin_cvt_fixup(struct hda_codec *codec,
1185 struct hdmi_spec *spec = codec->spec;
1188 spec->ops.pin_cvt_fixup(codec, per_pin, cvt_nid);
1193 struct hda_codec *codec,
1196 struct hdmi_spec *spec = codec->spec;
1202 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1206 err = hdmi_choose_cvt(codec, -1, &cvt_idx, false);
1214 pin_cvt_fixup(codec, NULL, per_cvt->cvt_nid);
1241 struct hda_codec *codec,
1244 struct hdmi_spec *spec = codec->spec;
1253 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1258 pin_idx = hinfo_to_pin_index(codec, hinfo);
1263 err = hdmi_pcm_open_no_pin(hinfo, codec, substream);
1267 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, false);
1281 if (get_wcaps(codec, per_cvt->cvt_nid) & AC_WCAP_STRIPE)
1284 snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id);
1285 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1290 pin_cvt_fixup(codec, per_pin, 0);
1292 snd_hda_spdif_ctls_assign(codec, pcm_idx, per_cvt->cvt_nid);
1309 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
1331 static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
1333 struct hdmi_spec *spec = codec->spec;
1339 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
1340 codec_warn(codec,
1342 pin_nid, get_wcaps(codec, pin_nid));
1346 snd_hda_set_dev_select(codec, pin_nid, dev_id);
1353 conns = snd_hda_get_raw_connections(codec, pin_nid,
1427 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid);
1432 struct hda_codec *codec = per_pin->codec;
1455 snd_hda_set_dev_select(codec, per_pin->pin_nid,
1457 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1461 snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid);
1463 non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid);
1469 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
1476 snd_hda_spdif_ctls_unassign(per_pin->codec, per_pin->pcm_idx);
1485 static struct snd_jack *pin_idx_to_pcm_jack(struct hda_codec *codec,
1488 struct hdmi_spec *spec = codec->spec;
1500 static void update_eld(struct hda_codec *codec,
1506 struct hdmi_spec *spec = codec->spec;
1514 snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer,
1537 pcm_jack = pin_idx_to_pcm_jack(codec, per_pin);
1555 pcm_jack = pin_idx_to_pcm_jack(codec, per_pin);
1558 snd_hdmi_show_eld(codec, &eld->info);
1585 pin_cvt_fixup(codec, per_pin, 0);
1586 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1590 snd_ctl_notify(codec->card,
1605 struct hda_codec *codec = per_pin->codec;
1606 struct hdmi_spec *spec = codec->spec;
1608 struct device *dev = hda_codec_dev(codec);
1627 ret = snd_hda_power_up_pm(codec);
1631 present = snd_hda_jack_pin_sense(codec, pin_nid, dev_id);
1640 codec_dbg(codec,
1642 codec->addr, pin_nid, eld->monitor_present, eld->eld_valid);
1645 if (spec->ops.pin_get_eld(codec, pin_nid, dev_id,
1650 update_eld(codec, per_pin, eld, repoll);
1653 snd_hda_power_down_pm(codec);
1661 static void silent_stream_enable_i915(struct hda_codec *codec,
1666 snd_hdac_sync_audio_rate(&codec->core, per_pin->pin_nid,
1672 snd_hda_codec_setup_stream(codec, per_pin->cvt_nid,
1675 snd_hda_codec_setup_stream(codec, per_pin->cvt_nid, I915_SILENT_FMT_MASK, 0, format);
1678 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1681 static void silent_stream_set_kae(struct hda_codec *codec,
1687 codec_dbg(codec, "HDMI: KAE %d cvt-NID=0x%x\n", enable, per_pin->cvt_nid);
1689 param = snd_hda_codec_read(codec, per_pin->cvt_nid, 0, AC_VERB_GET_DIGI_CONVERT_1, 0);
1697 snd_hda_codec_write(codec, per_pin->cvt_nid, 0, AC_VERB_SET_DIGI_CONVERT_3, param);
1700 static void silent_stream_enable(struct hda_codec *codec,
1703 struct hdmi_spec *spec = codec->spec;
1713 err = snd_hda_power_up_pm(codec);
1715 codec_err(codec,
1716 "Failed to power up codec for silent stream enable ret=[%d]\n", err);
1717 snd_hda_power_down_pm(codec);
1724 codec_dbg(codec, "hdmi: PCM already open, no silent stream\n");
1729 pin_idx = pin_id_to_pin_index(codec, per_pin->pin_nid, per_pin->dev_id);
1730 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, true);
1732 codec_err(codec, "hdmi: no free converter to enable silent mode\n");
1741 codec_dbg(codec, "hdmi: enabling silent stream pin-NID=0x%x cvt-NID=0x%x\n",
1744 snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id);
1745 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1750 pin_cvt_fixup(codec, per_pin, 0);
1754 silent_stream_enable_i915(codec, per_pin);
1755 silent_stream_set_kae(codec, per_pin, true);
1758 silent_stream_enable_i915(codec, per_pin);
1769 snd_hda_power_down_pm(codec);
1772 static void silent_stream_disable(struct hda_codec *codec,
1775 struct hdmi_spec *spec = codec->spec;
1779 err = snd_hda_power_up_pm(codec);
1781 codec_err(codec,
1782 "Failed to power up codec for silent stream disable ret=[%d]\n",
1784 snd_hda_power_down_pm(codec);
1792 codec_dbg(codec, "HDMI: disable silent stream on pin-NID=0x%x cvt-NID=0x%x\n",
1795 cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid);
1803 snd_hda_power_down_pm(codec);
1805 silent_stream_set_kae(codec, per_pin, false);
1814 snd_hda_power_down_pm(codec);
1818 static void sync_eld_via_acomp(struct hda_codec *codec,
1821 struct hdmi_spec *spec = codec->spec;
1828 eld->eld_size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid,
1832 update_eld(codec, per_pin, eld, 0);
1838 silent_stream_enable(codec, per_pin);
1840 silent_stream_disable(codec, per_pin);
1846 struct hda_codec *codec = per_pin->codec;
1848 if (!codec_has_acomp(codec))
1851 sync_eld_via_acomp(codec, per_pin);
1858 struct hda_codec *codec = per_pin->codec;
1859 struct hdmi_spec *spec = codec->spec;
1862 jack = snd_hda_jack_tbl_get_mst(codec, per_pin->pin_nid,
1875 static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1877 struct hdmi_spec *spec = codec->spec;
1884 caps = snd_hda_query_pin_caps(codec, pin_nid);
1892 config = snd_hda_codec_get_pincfg(codec, pin_nid);
1909 } else if (codec->dp_mst) {
1910 dev_num = snd_hda_get_num_devices(codec, pin_nid) + 1;
1941 snd_hda_set_dev_select(codec, pin_nid, i);
1942 err = hdmi_read_pin_conn(codec, pin_idx);
1945 if (!is_jack_detectable(codec, pin_nid))
1946 codec_warn(codec, "HDMI: pin NID 0x%x - jack not detectable\n", pin_nid);
1954 static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1956 struct hdmi_spec *spec = codec->spec;
1961 chans = get_wcaps(codec, cvt_nid);
1976 err = snd_hda_query_supported_pcm(codec, cvt_nid,
2004 static int hdmi_parse_codec(struct hda_codec *codec)
2006 struct hdmi_spec *spec = codec->spec;
2012 nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &start_nid);
2014 codec_warn(codec, "HDMI: failed to get afg sub nodes\n");
2021 q = snd_pci_quirk_lookup(codec->bus->pci, force_connect_list);
2033 caps = get_wcaps(codec, nid);
2039 hdmi_add_cvt(codec, nid);
2046 caps = get_wcaps(codec, nid);
2052 hdmi_add_pin(codec, nid);
2060 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
2065 mutex_lock(&codec->spdif_mutex);
2066 spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
2071 mutex_unlock(&codec->spdif_mutex);
2075 mutex_unlock(&codec->spdif_mutex);
2084 struct hda_codec *codec,
2090 struct hdmi_spec *spec = codec->spec;
2099 pin_idx = hinfo_to_pin_index(codec, hinfo);
2104 pin_cvt_fixup(codec, NULL, cvt_nid);
2105 snd_hda_codec_setup_stream(codec, cvt_nid,
2120 pin_cvt_fixup(codec, per_pin, 0);
2124 if (codec_has_acomp(codec))
2125 snd_hdac_sync_audio_rate(&codec->core, per_pin->pin_nid,
2128 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
2133 if (get_wcaps(codec, cvt_nid) & AC_WCAP_STRIPE) {
2134 stripe = snd_hdac_get_stream_stripe_ctl(&codec->bus->core,
2136 snd_hda_codec_write(codec, cvt_nid, 0,
2141 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
2144 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2146 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
2148 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
2154 err = spec->ops.setup_stream(codec, cvt_nid, per_pin->pin_nid,
2162 struct hda_codec *codec,
2165 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
2170 struct hda_codec *codec,
2173 struct hdmi_spec *spec = codec->spec;
2182 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
2187 cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid);
2198 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
2200 pin_idx = hinfo_to_pin_index(codec, hinfo);
2211 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2213 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
2215 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
2244 struct hda_codec *codec = hdac_to_hda_codec(hdac);
2245 struct hdmi_spec *spec = codec->spec;
2257 struct hda_codec *codec = hdac_to_hda_codec(hdac);
2258 struct hdmi_spec *spec = codec->spec;
2271 struct hda_codec *codec = hdac_to_hda_codec(hdac);
2272 struct hdmi_spec *spec = codec->spec;
2281 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
2287 struct hda_codec *codec = hdac_to_hda_codec(hdac);
2288 struct hdmi_spec *spec = codec->spec;
2294 static int generic_hdmi_build_pcms(struct hda_codec *codec)
2296 struct hdmi_spec *spec = codec->spec;
2299 /* limit the PCM devices to the codec converters or available PINs */
2301 codec_dbg(codec, "hdmi: pcm_num set to %d\n", pcm_num);
2308 info = snd_hda_codec_pcm_new(codec, "HDMI %d", idx);
2341 static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx)
2344 struct hdmi_spec *spec = codec->spec;
2352 err = snd_jack_new(codec->card, hdmi_str, SND_JACK_AVOUT, &jack,
2363 static int generic_hdmi_build_controls(struct hda_codec *codec)
2365 struct hdmi_spec *spec = codec->spec;
2376 err = generic_hdmi_build_jack(codec, pcm_idx);
2383 err = snd_hda_create_dig_out_ctls(codec,
2388 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
2393 err = hdmi_create_eld_ctl(codec, pcm_idx, dev);
2427 static int generic_hdmi_init_per_pins(struct hda_codec *codec)
2429 struct hdmi_spec *spec = codec->spec;
2435 per_pin->codec = codec;
2443 static int generic_hdmi_init(struct hda_codec *codec)
2445 struct hdmi_spec *spec = codec->spec;
2454 snd_hda_set_dev_select(codec, pin_nid, dev_id);
2455 hdmi_init_pin(codec, pin_nid);
2456 if (codec_has_acomp(codec))
2458 snd_hda_jack_detect_enable_callback_mst(codec, pin_nid, dev_id,
2477 static void generic_spec_free(struct hda_codec *codec)
2479 struct hdmi_spec *spec = codec->spec;
2484 codec->spec = NULL;
2486 codec->dp_mst = false;
2489 static void generic_hdmi_free(struct hda_codec *codec)
2491 struct hdmi_spec *spec = codec->spec;
2495 snd_hdac_acomp_exit(&codec->bus->core);
2496 } else if (codec_has_acomp(codec)) {
2497 snd_hdac_acomp_register_notifier(&codec->bus->core, NULL);
2499 codec->relaxed_resume = 0;
2510 snd_device_free(codec->card, spec->pcm_rec[pcm_idx].jack);
2513 generic_spec_free(codec);
2517 static int generic_hdmi_suspend(struct hda_codec *codec)
2519 struct hdmi_spec *spec = codec->spec;
2529 static int generic_hdmi_resume(struct hda_codec *codec)
2531 struct hdmi_spec *spec = codec->spec;
2534 codec->patch_ops.init(codec);
2535 snd_hda_regmap_sync(codec);
2564 /* allocate codec->spec and assign/initialize generic parser ops */
2565 static int alloc_generic_hdmi(struct hda_codec *codec)
2573 spec->codec = codec;
2578 snd_hdac_register_chmap_ops(&codec->core, &spec->chmap);
2585 codec->spec = spec;
2588 codec->patch_ops = generic_hdmi_patch_ops;
2594 static int patch_generic_hdmi(struct hda_codec *codec)
2598 err = alloc_generic_hdmi(codec);
2602 err = hdmi_parse_codec(codec);
2604 generic_spec_free(codec);
2608 generic_hdmi_init_per_pins(codec);
2617 static void reprogram_jack_detect(struct hda_codec *codec, hda_nid_t nid,
2622 tbl = snd_hda_jack_tbl_get_mst(codec, nid, dev_id);
2628 snd_hda_codec_write_cache(codec, nid, 0,
2643 spec->codec->relaxed_resume = use_acomp;
2644 spec->codec->bus->keep_power = 0;
2647 reprogram_jack_detect(spec->codec,
2684 struct hda_codec *codec = audio_ptr;
2685 struct hdmi_spec *spec = codec->spec;
2686 hda_nid_t pin_nid = spec->port2pin(codec, port);
2690 if (get_wcaps_type(get_wcaps(codec, pin_nid)) != AC_WID_PIN)
2695 if (codec->core.dev.power.power_state.event == PM_EVENT_SUSPEND)
2698 check_presence_and_report(codec, pin_nid, dev_id);
2702 static void setup_drm_audio_ops(struct hda_codec *codec,
2705 struct hdmi_spec *spec = codec->spec;
2707 spec->drm_audio_ops.audio_ptr = codec;
2720 static void generic_acomp_init(struct hda_codec *codec,
2724 struct hdmi_spec *spec = codec->spec;
2727 codec_info(codec, "audio component disabled by module option\n");
2732 setup_drm_audio_ops(codec, ops);
2733 if (!snd_hdac_acomp_init(&codec->bus->core, &spec->drm_audio_ops,
2740 * Intel codec parsers and helpers
2748 static void intel_haswell_enable_all_pins(struct hda_codec *codec,
2752 struct hdmi_spec *spec = codec->spec;
2754 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2760 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2766 snd_hda_codec_update_widgets(codec);
2769 static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
2772 struct hdmi_spec *spec = codec->spec;
2774 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2781 snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB);
2782 snd_hda_codec_write_cache(codec, spec->vendor_nid, 0,
2789 static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2793 intel_haswell_enable_all_pins(codec, false);
2794 intel_haswell_fixup_enable_dp12(codec);
2797 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
2798 snd_hda_codec_set_power_to_all(codec, fg, power_state);
2812 static int intel_base_nid(struct hda_codec *codec)
2814 switch (codec->core.vendor_id) {
2826 struct hda_codec *codec = audio_ptr;
2827 struct hdmi_spec *spec = codec->spec;
2831 base_nid = intel_base_nid(codec);
2846 codec_info(codec, "Can't find the HDMI/DP port for pin NID 0x%x\n", pin_nid);
2850 static int intel_port2pin(struct hda_codec *codec, int port)
2852 struct hdmi_spec *spec = codec->spec;
2858 return port + intel_base_nid(codec) - 1;
2868 struct hda_codec *codec = audio_ptr;
2872 pin_nid = intel_port2pin(codec, port);
2878 if (codec->core.dev.power.power_state.event == PM_EVENT_SUSPEND)
2881 snd_hdac_i915_set_bclk(&codec->bus->core);
2882 check_presence_and_report(codec, pin_nid, dev_id);
2891 static void register_i915_notifier(struct hda_codec *codec)
2893 struct hdmi_spec *spec = codec->spec;
2897 setup_drm_audio_ops(codec, &intel_audio_ops);
2898 snd_hdac_acomp_register_notifier(&codec->bus->core,
2901 codec->relaxed_resume = 1;
2905 static int i915_hsw_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
2909 struct hdmi_spec *spec = codec->spec;
2910 int pin_idx = pin_id_to_pin_index(codec, pin_nid, dev_id);
2919 haswell_verify_D0(codec, cvt_nid, pin_nid);
2922 silent_stream_set_kae(codec, per_pin, false);
2923 /* wait for pending transfers in codec to clear */
2927 res = hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id,
2932 silent_stream_set_kae(codec, per_pin, true);
2939 static void i915_pin_cvt_fixup(struct hda_codec *codec,
2944 haswell_verify_D0(codec, per_pin->cvt_nid, per_pin->pin_nid);
2945 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2947 intel_verify_pin_cvt_connect(codec, per_pin);
2948 intel_not_share_assigned_cvt(codec, per_pin->pin_nid,
2951 intel_not_share_assigned_cvt_nid(codec, 0, 0, cvt_nid);
2956 static int i915_adlp_hdmi_suspend(struct hda_codec *codec)
2958 struct hdmi_spec *spec = codec->spec;
2962 res = generic_hdmi_suspend(codec);
2975 * stream-id should remain programmed when codec goes
2978 codec->no_stream_clean_at_suspend = 1;
2984 codec->forced_resume = 1;
2986 codec_dbg(codec, "HDMI: KAE active at suspend\n");
2988 codec->no_stream_clean_at_suspend = 0;
2989 codec->forced_resume = 0;
2995 static int i915_adlp_hdmi_resume(struct hda_codec *codec)
2997 struct hdmi_spec *spec = codec->spec;
3000 res = generic_hdmi_resume(codec);
3003 if (!codec->no_stream_clean_at_suspend)
3011 * the codec setting may have been lost. Re-enable
3017 param = snd_hda_codec_read(codec, per_pin->cvt_nid, 0,
3020 codec_dbg(codec, "HDMI: KAE: restore stream id\n");
3021 silent_stream_enable_i915(codec, per_pin);
3024 param = snd_hda_codec_read(codec, per_pin->cvt_nid, 0,
3027 codec_dbg(codec, "HDMI: KAE: restore DIG3_KAE\n");
3028 silent_stream_set_kae(codec, per_pin, true);
3038 static int alloc_intel_hdmi(struct hda_codec *codec)
3043 if (!codec->bus->core.audio_component) {
3044 codec_info(codec, "No i915 binding for Intel HDMI/DP codec\n");
3046 codec->probe_id = HDA_CODEC_ID_SKIP_PROBE;
3050 err = alloc_generic_hdmi(codec);
3054 codec->patch_ops.unsol_event = NULL;
3059 static int parse_intel_hdmi(struct hda_codec *codec)
3064 err = hdmi_parse_codec(codec);
3068 generic_spec_free(codec);
3072 generic_hdmi_init_per_pins(codec);
3073 register_i915_notifier(codec);
3078 static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid,
3085 err = alloc_intel_hdmi(codec);
3088 spec = codec->spec;
3089 codec->dp_mst = true;
3096 intel_haswell_enable_all_pins(codec, true);
3097 intel_haswell_fixup_enable_dp12(codec);
3099 codec->display_power_control = 1;
3101 codec->patch_ops.set_power_state = haswell_set_power_state;
3102 codec->depop_delay = 0;
3103 codec->auto_runtime_pm = 1;
3115 return parse_intel_hdmi(codec);
3118 static int patch_i915_hsw_hdmi(struct hda_codec *codec)
3120 return intel_hsw_common_init(codec, 0x08, NULL, 0, 3,
3124 static int patch_i915_glk_hdmi(struct hda_codec *codec)
3131 return intel_hsw_common_init(codec, 0x0b, NULL, 0, 3, false);
3134 static int patch_i915_icl_hdmi(struct hda_codec *codec)
3142 return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map), 3,
3146 static int patch_i915_tgl_hdmi(struct hda_codec *codec)
3154 return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map), 4,
3158 static int patch_i915_adlp_hdmi(struct hda_codec *codec)
3163 res = patch_i915_tgl_hdmi(codec);
3165 spec = codec->spec;
3171 codec->patch_ops.resume = i915_adlp_hdmi_resume;
3172 codec->patch_ops.suspend = i915_adlp_hdmi_suspend;
3181 static int patch_i915_byt_hdmi(struct hda_codec *codec)
3186 err = alloc_intel_hdmi(codec);
3189 spec = codec->spec;
3191 /* For Valleyview/Cherryview, only the display codec is in the display
3194 codec->display_power_control = 1;
3196 codec->depop_delay = 0;
3197 codec->auto_runtime_pm = 1;
3201 return parse_intel_hdmi(codec);
3205 static int patch_i915_cpt_hdmi(struct hda_codec *codec)
3209 err = alloc_intel_hdmi(codec);
3212 return parse_intel_hdmi(codec);
3219 static int simple_playback_build_pcms(struct hda_codec *codec)
3221 struct hdmi_spec *spec = codec->spec;
3228 chans = get_wcaps(codec, per_cvt->cvt_nid);
3231 info = snd_hda_codec_pcm_new(codec, "HDMI 0");
3246 static void simple_hdmi_unsol_event(struct hda_codec *codec,
3249 snd_hda_jack_set_dirty_all(codec);
3250 snd_hda_jack_report_sync(codec);
3258 static int simple_playback_build_controls(struct hda_codec *codec)
3260 struct hdmi_spec *spec = codec->spec;
3265 err = snd_hda_create_dig_out_ctls(codec, per_cvt->cvt_nid,
3270 return simple_hdmi_build_jack(codec, 0);
3273 static int simple_playback_init(struct hda_codec *codec)
3275 struct hdmi_spec *spec = codec->spec;
3279 snd_hda_codec_write(codec, pin, 0,
3282 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
3283 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3285 snd_hda_jack_detect_enable(codec, pin, per_pin->dev_id);
3289 static void simple_playback_free(struct hda_codec *codec)
3291 struct hdmi_spec *spec = codec->spec;
3350 static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
3352 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
3356 static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
3358 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
3383 struct hda_codec *codec,
3386 struct hdmi_spec *spec = codec->spec;
3389 switch (codec->preset->vendor_id) {
3412 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3416 struct hda_codec *codec,
3419 struct hdmi_spec *spec = codec->spec;
3420 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3424 struct hda_codec *codec,
3429 struct hdmi_spec *spec = codec->spec;
3430 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3453 static int patch_simple_hdmi(struct hda_codec *codec,
3464 spec->codec = codec;
3465 codec->spec = spec;
3476 simple_playback_free(codec);
3483 codec->patch_ops = simple_hdmi_patch_ops;
3488 static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
3513 snd_hda_codec_write(codec, 0x1, 0,
3516 snd_hda_codec_write(codec, 0x1, 0,
3522 struct hda_codec *codec,
3525 struct hdmi_spec *spec = codec->spec;
3528 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
3532 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
3535 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
3541 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
3543 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3547 struct hda_codec *codec,
3555 struct hdmi_spec *spec = codec->spec;
3559 mutex_lock(&codec->spdif_mutex);
3561 spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid);
3568 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
3569 snd_hda_codec_write(codec,
3576 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
3580 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
3585 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
3586 snd_hda_codec_write(codec,
3591 snd_hda_codec_write(codec,
3606 if (codec->spdif_status_reset &&
3608 snd_hda_codec_write(codec,
3614 snd_hda_codec_write(codec,
3620 snd_hda_codec_write(codec,
3627 if (codec->spdif_status_reset &&
3629 snd_hda_codec_write(codec,
3634 snd_hda_codec_write(codec,
3641 nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
3643 mutex_unlock(&codec->spdif_mutex);
3662 static int patch_nvhdmi_2ch(struct hda_codec *codec)
3665 int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
3670 codec->patch_ops.init = nvhdmi_7x_init_2ch;
3671 /* override the PCM rates, etc, as the codec doesn't give full list */
3672 spec = codec->spec;
3680 static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
3682 struct hdmi_spec *spec = codec->spec;
3683 int err = simple_playback_build_pcms(codec);
3691 static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
3693 struct hdmi_spec *spec = codec->spec;
3698 err = simple_playback_build_controls(codec);
3709 switch (codec->preset->vendor_id) {
3722 static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
3725 int err = patch_nvhdmi_2ch(codec);
3728 spec = codec->spec;
3731 codec->patch_ops.init = nvhdmi_7x_init_8ch;
3732 codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
3733 codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
3737 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
3778 static int nvhdmi_port2pin(struct hda_codec *codec, int port)
3790 static int patch_nvhdmi(struct hda_codec *codec)
3795 err = alloc_generic_hdmi(codec);
3798 codec->dp_mst = true;
3800 spec = codec->spec;
3802 err = hdmi_parse_codec(codec);
3804 generic_spec_free(codec);
3808 generic_hdmi_init_per_pins(codec);
3817 codec->link_down_at_suspend = 1;
3819 generic_acomp_init(codec, &nvhdmi_audio_ops, nvhdmi_port2pin);
3824 static int patch_nvhdmi_legacy(struct hda_codec *codec)
3829 err = patch_generic_hdmi(codec);
3833 spec = codec->spec;
3841 codec->link_down_at_suspend = 1;
3847 * The HDA codec on NVIDIA Tegra contains two scratch registers that are
3856 * The SCRATCH0 register is used to notify the HDMI codec of changes in audio
3858 * be raised in the HDMI codec. The remainder of the bits is arbitrary. This
3889 * the format is invalidated so that the HDMI codec can be disabled.
3891 static void tegra_hdmi_set_format(struct hda_codec *codec,
3897 struct hdmi_spec *spec = codec->spec;
3900 * Tegra HDA codec design from TEGRA234 chip onwards support DP MST.
3903 * scratch register read/write for DP MST supported Tegra HDA codec.
3905 if (codec->dp_mst)
3909 value = snd_hda_codec_read(codec, nid, 0,
3914 snd_hda_codec_write(codec, nid, 0,
3917 snd_hda_codec_write(codec, nid, 0,
3922 snd_hda_codec_write(codec, nid, 0,
3941 snd_hda_codec_write(codec, nid, 0,
3943 snd_hda_codec_write(codec, nid, 0,
3948 * in the HDMI codec. The HDMI driver will use that as trigger
3953 snd_hda_codec_write(codec, nid, 0,
3959 struct hda_codec *codec,
3966 err = generic_hdmi_playback_pcm_prepare(hinfo, codec, stream_tag,
3971 /* notify the HDMI codec of the format change */
3972 tegra_hdmi_set_format(codec, hinfo->nid, format);
3978 struct hda_codec *codec,
3981 /* invalidate the format in the HDMI codec */
3982 tegra_hdmi_set_format(codec, hinfo->nid, 0);
3984 return generic_hdmi_playback_pcm_cleanup(hinfo, codec, substream);
3987 static struct hda_pcm *hda_find_pcm_by_type(struct hda_codec *codec, int type)
3989 struct hdmi_spec *spec = codec->spec;
4002 static int tegra_hdmi_build_pcms(struct hda_codec *codec)
4008 err = generic_hdmi_build_pcms(codec);
4012 pcm = hda_find_pcm_by_type(codec, HDA_PCM_TYPE_HDMI);
4018 * codec about format changes.
4027 static int tegra_hdmi_init(struct hda_codec *codec)
4029 struct hdmi_spec *spec = codec->spec;
4032 err = hdmi_parse_codec(codec);
4034 generic_spec_free(codec);
4039 snd_hda_codec_write(codec, spec->cvt_nids[i], 0,
4043 generic_hdmi_init_per_pins(codec);
4045 codec->depop_delay = 10;
4046 codec->patch_ops.build_pcms = tegra_hdmi_build_pcms;
4059 static int patch_tegra_hdmi(struct hda_codec *codec)
4063 err = alloc_generic_hdmi(codec);
4067 return tegra_hdmi_init(codec);
4070 static int patch_tegra234_hdmi(struct hda_codec *codec)
4075 err = alloc_generic_hdmi(codec);
4079 codec->dp_mst = true;
4080 spec = codec->spec;
4084 return tegra_hdmi_init(codec);
4091 #define is_amdhdmi_rev3_or_later(codec) \
4092 ((codec)->core.vendor_id == 0x1002aa01 && \
4093 ((codec)->core.revision_id & 0xff00) >= 0x0300)
4094 #define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec)
4134 static int atihdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
4139 return snd_hdmi_get_eld_ati(codec, nid, buf, eld_size,
4140 is_amdhdmi_rev3_or_later(codec));
4143 static void atihdmi_pin_setup_infoframe(struct hda_codec *codec,
4148 snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_CHANNEL_ALLOCATION, ca);
4219 struct hda_codec *codec = hdac_to_hda_codec(hdac);
4226 if (!has_amd_full_remap_support(codec)) {
4249 return snd_hda_codec_write(codec, pin_nid, 0, verb, ati_channel_setup);
4255 struct hda_codec *codec = hdac_to_hda_codec(hdac);
4264 if (!has_amd_full_remap_support(codec)) {
4274 ati_channel_setup = snd_hda_codec_read(codec, pin_nid, 0, verb, 0);
4337 static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
4344 hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0);
4351 codec_dbg(codec,
4358 snd_hda_codec_write(codec, pin_nid, 0,
4368 static int atihdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
4372 if (is_amdhdmi_rev3_or_later(codec)) {
4378 snd_hda_codec_write(codec, cvt_nid, 0, ATI_VERB_SET_RAMP_RATE, ramp_rate);
4381 return hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id,
4386 static int atihdmi_init(struct hda_codec *codec)
4388 struct hdmi_spec *spec = codec->spec;
4391 err = generic_hdmi_init(codec);
4400 snd_hda_codec_write(codec, per_pin->pin_nid, 0, ATI_VERB_SET_DOWNMIX_INFO, 0);
4403 if (has_amd_full_remap_support(codec))
4404 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
4408 codec->auto_runtime_pm = 1;
4421 static int atihdmi_port2pin(struct hda_codec *codec, int port)
4433 static int patch_atihdmi(struct hda_codec *codec)
4439 err = patch_generic_hdmi(codec);
4444 codec->patch_ops.init = atihdmi_init;
4446 spec = codec->spec;
4458 if (!has_amd_full_remap_support(codec)) {
4481 codec->link_down_at_suspend = 1;
4483 generic_acomp_init(codec, &atihdmi_audio_ops, atihdmi_port2pin);
4492 static int patch_via_hdmi(struct hda_codec *codec)
4494 return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
4497 static int patch_gf_hdmi(struct hda_codec *codec)
4501 err = patch_generic_hdmi(codec);
4506 * Glenfly GPUs have two codecs, stream switches from one codec to
4509 codec->no_sticky_stream = 1;
4658 MODULE_DESCRIPTION("HDMI HD-audio codec");
4659 MODULE_ALIAS("snd-hda-codec-intelhdmi");
4660 MODULE_ALIAS("snd-hda-codec-nvhdmi");
4661 MODULE_ALIAS("snd-hda-codec-atihdmi");