Lines Matching refs:codec

73 	struct hda_codec *codec;
93 int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid,
96 void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid,
101 int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid,
104 int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid,
108 void (*pin_cvt_fixup)(struct hda_codec *codec,
120 struct hda_codec *codec;
184 static inline bool codec_has_acomp(struct hda_codec *codec)
186 struct hdmi_spec *spec = codec->spec;
190 #define codec_has_acomp(codec) false
238 static int pin_id_to_pin_index(struct hda_codec *codec,
241 struct hdmi_spec *spec = codec->spec;
259 codec_warn(codec, "HDMI: pin nid %d not registered\n", pin_nid);
263 static int hinfo_to_pcm_index(struct hda_codec *codec,
266 struct hdmi_spec *spec = codec->spec;
273 codec_warn(codec, "HDMI: hinfo %p not tied to a PCM\n", hinfo);
277 static int hinfo_to_pin_index(struct hda_codec *codec,
280 struct hdmi_spec *spec = codec->spec;
291 codec_dbg(codec, "HDMI: hinfo %p (pcm %d) not registered\n", hinfo,
292 hinfo_to_pcm_index(codec, hinfo));
310 static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid)
312 struct hdmi_spec *spec = codec->spec;
319 codec_warn(codec, "HDMI: cvt nid %d not registered\n", cvt_nid);
326 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
327 struct hdmi_spec *spec = codec->spec;
353 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
354 struct hdmi_spec *spec = codec->spec;
398 static int hdmi_create_eld_ctl(struct hda_codec *codec, int pcm_idx,
402 struct hdmi_spec *spec = codec->spec;
405 kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
414 err = snd_hda_ctl_add(codec, 0, kctl);
423 static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
428 val = snd_hda_codec_read(codec, pin_nid, 0,
436 static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
443 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
446 static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
449 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
452 static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
454 struct hdmi_spec *spec = codec->spec;
458 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
459 snd_hda_codec_write(codec, pin_nid, 0,
471 snd_hda_codec_write(codec, pin_nid, 0,
503 struct hda_codec *codec = per_pin->codec;
507 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
508 err = snd_card_proc_new(codec->card, name, &entry);
522 if (!per_pin->codec->bus->shutdown) {
545 static void hdmi_start_infoframe_trans(struct hda_codec *codec,
548 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
549 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
556 static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
559 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
560 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
564 static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
570 size = snd_hdmi_get_eld_size(codec, pin_nid);
571 codec_dbg(codec, "HDMI: ELD buf size is %d\n", size);
574 size = snd_hda_codec_read(codec, pin_nid, 0,
576 codec_dbg(codec, "HDMI: DIP GP[%d] buf size is %d\n", i, size);
581 static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
588 size = snd_hda_codec_read(codec, pin_nid, 0,
593 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
595 hdmi_write_dip_byte(codec, pin_nid, 0x0);
596 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
598 codec_dbg(codec, "dip index %d: %d != %d\n",
603 codec_dbg(codec,
624 static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
630 hdmi_debug_dip_size(codec, pin_nid);
631 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
633 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
635 hdmi_write_dip_byte(codec, pin_nid, dip[i]);
638 static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
644 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
648 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
650 val = snd_hda_codec_read(codec, pin_nid, 0,
659 static int hdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
662 snd_hda_set_dev_select(codec, nid, dev_id);
664 return snd_hdmi_get_eld(codec, nid, buf, eld_size);
667 static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
672 struct hdmi_spec *spec = codec->spec;
702 codec_dbg(codec, "HDMI: unknown connection type at pin %d\n",
707 snd_hda_set_dev_select(codec, pin_nid, dev_id);
714 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
716 codec_dbg(codec,
720 hdmi_stop_infoframe_trans(codec, pin_nid);
721 hdmi_fill_audio_infoframe(codec, pin_nid,
723 hdmi_start_infoframe_trans(codec, pin_nid);
727 static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
731 struct hdmi_spec *spec = codec->spec;
743 snd_hda_set_dev_select(codec, pin_nid, dev_id);
746 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
747 snd_hda_codec_write(codec, pin_nid, 0,
753 ca = snd_hdac_channel_allocation(&codec->core,
759 chmap->ops.set_channel_count(&codec->core, per_pin->cvt_nid,
770 spec->ops.pin_setup_infoframe(codec, pin_nid, dev_id,
782 static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid,
785 struct hdmi_spec *spec = codec->spec;
786 int pin_idx = pin_id_to_pin_index(codec, nid, dev_id);
795 static void jack_callback(struct hda_codec *codec,
799 if (codec_has_acomp(codec))
802 check_presence_and_report(codec, jack->nid, jack->dev_id);
805 static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res,
810 codec_dbg(codec,
812 codec->addr, jack->nid, jack->dev_id, !!(res & AC_UNSOL_RES_IA),
815 check_presence_and_report(codec, jack->nid, jack->dev_id);
818 static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
825 codec_info(codec,
827 codec->addr,
843 static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
849 if (codec_has_acomp(codec))
852 if (codec->dp_mst) {
856 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, dev_entry);
858 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, 0);
862 codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag);
867 hdmi_intrinsic_event(codec, res, jack);
869 hdmi_non_intrinsic_event(codec, res);
872 static void haswell_verify_D0(struct hda_codec *codec,
880 if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0))
881 snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
883 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) {
884 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
887 pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
889 codec_dbg(codec, "Haswell HDMI audio: Power for pin 0x%x is now D%d\n", nid, pwr);
901 static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
906 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
907 snd_hda_set_dev_select(codec, pin_nid, dev_id);
908 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
920 codec_dbg(codec,
927 snd_hda_codec_write(codec, pin_nid, 0,
936 static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
940 struct hdmi_spec *spec = codec->spec;
944 err = spec->ops.pin_hbr_setup(codec, pin_nid, dev_id,
948 codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n");
959 param = snd_hda_codec_read(codec, cvt_nid, 0,
968 snd_hda_codec_write(codec, cvt_nid, 0,
972 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
981 static int hdmi_choose_cvt(struct hda_codec *codec,
984 struct hdmi_spec *spec = codec->spec;
996 cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid);
1035 static void intel_verify_pin_cvt_connect(struct hda_codec *codec,
1042 curr = snd_hda_codec_read(codec, pin_nid, 0,
1045 snd_hda_codec_write_cache(codec, pin_nid, 0,
1073 static void intel_not_share_assigned_cvt(struct hda_codec *codec,
1077 struct hdmi_spec *spec = codec->spec;
1107 dev_num = snd_hda_get_num_devices(codec, per_pin->pin_nid) + 1;
1119 dev_id_saved = snd_hda_get_dev_select(codec, nid);
1120 snd_hda_set_dev_select(codec, nid, per_pin->dev_id);
1121 curr = snd_hda_codec_read(codec, nid, 0,
1124 snd_hda_set_dev_select(codec, nid, dev_id_saved);
1130 * connection list are in the same order as in the codec.
1135 codec_dbg(codec,
1138 snd_hda_codec_write_cache(codec, nid, 0,
1144 snd_hda_set_dev_select(codec, nid, dev_id_saved);
1149 static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,
1153 struct hdmi_spec *spec = codec->spec;
1162 intel_not_share_assigned_cvt(codec, pin_nid, dev_id, mux_idx);
1166 static void pin_cvt_fixup(struct hda_codec *codec,
1170 struct hdmi_spec *spec = codec->spec;
1173 spec->ops.pin_cvt_fixup(codec, per_pin, cvt_nid);
1180 struct hda_codec *codec,
1183 struct hdmi_spec *spec = codec->spec;
1189 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1193 err = hdmi_choose_cvt(codec, -1, &cvt_idx);
1201 pin_cvt_fixup(codec, NULL, per_cvt->cvt_nid);
1228 struct hda_codec *codec,
1231 struct hdmi_spec *spec = codec->spec;
1240 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1245 pin_idx = hinfo_to_pin_index(codec, hinfo);
1256 err = hdmi_pcm_open_no_pin(hinfo, codec, substream);
1261 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx);
1276 if (get_wcaps(codec, per_cvt->cvt_nid) & AC_WCAP_STRIPE)
1279 snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id);
1280 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1285 pin_cvt_fixup(codec, per_pin, 0);
1287 snd_hda_spdif_ctls_assign(codec, pcm_idx, per_cvt->cvt_nid);
1304 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
1326 static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
1328 struct hdmi_spec *spec = codec->spec;
1334 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
1335 codec_warn(codec,
1337 pin_nid, get_wcaps(codec, pin_nid));
1341 snd_hda_set_dev_select(codec, pin_nid, dev_id);
1348 conns = snd_hda_get_raw_connections(codec, pin_nid,
1450 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid);
1455 struct hda_codec *codec = per_pin->codec;
1479 snd_hda_set_dev_select(codec, per_pin->pin_nid,
1481 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1485 snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid);
1487 non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid);
1493 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
1500 snd_hda_spdif_ctls_unassign(per_pin->codec, per_pin->pcm_idx);
1509 static struct snd_jack *pin_idx_to_pcm_jack(struct hda_codec *codec,
1512 struct hdmi_spec *spec = codec->spec;
1524 static void update_eld(struct hda_codec *codec,
1530 struct hdmi_spec *spec = codec->spec;
1538 snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer,
1561 pcm_jack = pin_idx_to_pcm_jack(codec, per_pin);
1578 pcm_jack = pin_idx_to_pcm_jack(codec, per_pin);
1581 snd_hdmi_show_eld(codec, &eld->info);
1608 pin_cvt_fixup(codec, per_pin, 0);
1609 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1613 snd_ctl_notify(codec->card,
1628 struct hda_codec *codec = per_pin->codec;
1629 struct hdmi_spec *spec = codec->spec;
1631 struct device *dev = hda_codec_dev(codec);
1650 ret = snd_hda_power_up_pm(codec);
1654 present = snd_hda_jack_pin_sense(codec, pin_nid, dev_id);
1663 codec_dbg(codec,
1665 codec->addr, pin_nid, eld->monitor_present, eld->eld_valid);
1668 if (spec->ops.pin_get_eld(codec, pin_nid, dev_id,
1673 update_eld(codec, per_pin, eld, repoll);
1676 snd_hda_power_down_pm(codec);
1685 static void silent_stream_enable(struct hda_codec *codec,
1688 struct hdmi_spec *spec = codec->spec;
1696 codec_dbg(codec, "hdmi: PCM already open, no silent stream\n");
1700 pin_idx = pin_id_to_pin_index(codec, per_pin->pin_nid, per_pin->dev_id);
1701 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx);
1703 codec_err(codec, "hdmi: no free converter to enable silent mode\n");
1712 codec_dbg(codec, "hdmi: enabling silent stream pin-NID=0x%x cvt-NID=0x%x\n",
1715 snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id);
1716 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1721 pin_cvt_fixup(codec, per_pin, 0);
1723 snd_hdac_sync_audio_rate(&codec->core, per_pin->pin_nid,
1729 snd_hda_codec_setup_stream(codec, per_pin->cvt_nid,
1732 snd_hda_codec_setup_stream(codec, per_pin->cvt_nid, I915_SILENT_FMT_MASK, 0, format);
1735 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1741 static void silent_stream_disable(struct hda_codec *codec,
1744 struct hdmi_spec *spec = codec->spec;
1752 codec_dbg(codec, "HDMI: disable silent stream on pin-NID=0x%x cvt-NID=0x%x\n",
1755 cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid);
1769 static void sync_eld_via_acomp(struct hda_codec *codec,
1772 struct hdmi_spec *spec = codec->spec;
1779 eld->eld_size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid,
1783 update_eld(codec, per_pin, eld, 0);
1796 pm_ret = snd_hda_power_up_pm(codec);
1798 codec_err(codec,
1799 "Monitor plugged-in, Failed to power up codec ret=[%d]\n",
1801 silent_stream_enable(codec, per_pin);
1803 silent_stream_disable(codec, per_pin);
1804 pm_ret = snd_hda_power_down_pm(codec);
1806 codec_err(codec,
1807 "Monitor plugged-out, Failed to power down codec ret=[%d]\n",
1815 struct hda_codec *codec = per_pin->codec;
1817 if (!codec_has_acomp(codec))
1820 sync_eld_via_acomp(codec, per_pin);
1827 struct hda_codec *codec = per_pin->codec;
1828 struct hdmi_spec *spec = codec->spec;
1831 jack = snd_hda_jack_tbl_get_mst(codec, per_pin->pin_nid,
1844 static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1846 struct hdmi_spec *spec = codec->spec;
1853 caps = snd_hda_query_pin_caps(codec, pin_nid);
1861 config = snd_hda_codec_get_pincfg(codec, pin_nid);
1882 } else if (spec->dyn_pcm_assign && codec->dp_mst) {
1883 dev_num = snd_hda_get_num_devices(codec, pin_nid) + 1;
1918 snd_hda_set_dev_select(codec, pin_nid, i);
1919 err = hdmi_read_pin_conn(codec, pin_idx);
1929 static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1931 struct hdmi_spec *spec = codec->spec;
1936 chans = get_wcaps(codec, cvt_nid);
1951 err = snd_hda_query_supported_pcm(codec, cvt_nid,
1978 static int hdmi_parse_codec(struct hda_codec *codec)
1980 struct hdmi_spec *spec = codec->spec;
1986 nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &start_nid);
1988 codec_warn(codec, "HDMI: failed to get afg sub nodes\n");
1992 q = snd_pci_quirk_lookup(codec->bus->pci, force_connect_list);
2004 caps = get_wcaps(codec, nid);
2010 hdmi_add_cvt(codec, nid);
2017 caps = get_wcaps(codec, nid);
2023 hdmi_add_pin(codec, nid);
2031 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
2036 mutex_lock(&codec->spdif_mutex);
2037 spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
2042 mutex_unlock(&codec->spdif_mutex);
2046 mutex_unlock(&codec->spdif_mutex);
2055 struct hda_codec *codec,
2061 struct hdmi_spec *spec = codec->spec;
2070 pin_idx = hinfo_to_pin_index(codec, hinfo);
2076 pin_cvt_fixup(codec, NULL, cvt_nid);
2077 snd_hda_codec_setup_stream(codec, cvt_nid,
2096 pin_cvt_fixup(codec, per_pin, 0);
2100 if (codec_has_acomp(codec))
2101 snd_hdac_sync_audio_rate(&codec->core, per_pin->pin_nid,
2104 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
2109 if (get_wcaps(codec, cvt_nid) & AC_WCAP_STRIPE) {
2110 stripe = snd_hdac_get_stream_stripe_ctl(&codec->bus->core,
2112 snd_hda_codec_write(codec, cvt_nid, 0,
2117 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
2120 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2122 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
2124 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
2130 err = spec->ops.setup_stream(codec, cvt_nid, per_pin->pin_nid,
2138 struct hda_codec *codec,
2141 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
2146 struct hda_codec *codec,
2149 struct hdmi_spec *spec = codec->spec;
2158 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
2163 cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid);
2174 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
2176 pin_idx = hinfo_to_pin_index(codec, hinfo);
2187 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2189 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
2191 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
2220 struct hda_codec *codec = hdac_to_hda_codec(hdac);
2221 struct hdmi_spec *spec = codec->spec;
2233 struct hda_codec *codec = hdac_to_hda_codec(hdac);
2234 struct hdmi_spec *spec = codec->spec;
2247 struct hda_codec *codec = hdac_to_hda_codec(hdac);
2248 struct hdmi_spec *spec = codec->spec;
2257 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
2263 struct hda_codec *codec = hdac_to_hda_codec(hdac);
2264 struct hdmi_spec *spec = codec->spec;
2270 static int generic_hdmi_build_pcms(struct hda_codec *codec)
2272 struct hdmi_spec *spec = codec->spec;
2283 if (spec->dyn_pcm_no_legacy && codec->mst_no_extra_pcms)
2285 else if (codec->mst_no_extra_pcms)
2290 codec_dbg(codec, "hdmi: pcm_num set to %d\n", pcm_num);
2296 info = snd_hda_codec_pcm_new(codec, "HDMI %d", idx);
2324 static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx)
2327 struct hdmi_spec *spec = codec->spec;
2336 !is_jack_detectable(codec, per_pin->pin_nid))
2340 err = snd_jack_new(codec->card, hdmi_str, SND_JACK_AVOUT, &jack,
2351 static int generic_hdmi_build_controls(struct hda_codec *codec)
2353 struct hdmi_spec *spec = codec->spec;
2364 err = generic_hdmi_build_jack(codec, pcm_idx);
2372 err = snd_hda_create_dig_out_ctls(codec,
2378 err = snd_hda_create_dig_out_ctls(codec,
2385 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
2390 err = hdmi_create_eld_ctl(codec, pcm_idx, dev);
2419 static int generic_hdmi_init_per_pins(struct hda_codec *codec)
2421 struct hdmi_spec *spec = codec->spec;
2427 per_pin->codec = codec;
2435 static int generic_hdmi_init(struct hda_codec *codec)
2437 struct hdmi_spec *spec = codec->spec;
2446 snd_hda_set_dev_select(codec, pin_nid, dev_id);
2447 hdmi_init_pin(codec, pin_nid);
2448 if (codec_has_acomp(codec))
2450 snd_hda_jack_detect_enable_callback_mst(codec, pin_nid, dev_id,
2469 static void generic_spec_free(struct hda_codec *codec)
2471 struct hdmi_spec *spec = codec->spec;
2476 codec->spec = NULL;
2478 codec->dp_mst = false;
2481 static void generic_hdmi_free(struct hda_codec *codec)
2483 struct hdmi_spec *spec = codec->spec;
2487 snd_hdac_acomp_exit(&codec->bus->core);
2488 } else if (codec_has_acomp(codec)) {
2489 snd_hdac_acomp_register_notifier(&codec->bus->core, NULL);
2491 codec->relaxed_resume = 0;
2503 snd_device_free(codec->card,
2509 generic_spec_free(codec);
2513 static int generic_hdmi_suspend(struct hda_codec *codec)
2515 struct hdmi_spec *spec = codec->spec;
2525 static int generic_hdmi_resume(struct hda_codec *codec)
2527 struct hdmi_spec *spec = codec->spec;
2530 codec->patch_ops.init(codec);
2531 snd_hda_regmap_sync(codec);
2560 /* allocate codec->spec and assign/initialize generic parser ops */
2561 static int alloc_generic_hdmi(struct hda_codec *codec)
2569 spec->codec = codec;
2574 snd_hdac_register_chmap_ops(&codec->core, &spec->chmap);
2581 codec->spec = spec;
2584 codec->patch_ops = generic_hdmi_patch_ops;
2590 static int patch_generic_hdmi(struct hda_codec *codec)
2594 err = alloc_generic_hdmi(codec);
2598 err = hdmi_parse_codec(codec);
2600 generic_spec_free(codec);
2604 generic_hdmi_init_per_pins(codec);
2613 static void reprogram_jack_detect(struct hda_codec *codec, hda_nid_t nid,
2618 tbl = snd_hda_jack_tbl_get_mst(codec, nid, dev_id);
2624 snd_hda_codec_write_cache(codec, nid, 0,
2639 spec->codec->relaxed_resume = use_acomp;
2640 spec->codec->bus->keep_power = 0;
2643 reprogram_jack_detect(spec->codec,
2680 struct hda_codec *codec = audio_ptr;
2681 struct hdmi_spec *spec = codec->spec;
2682 hda_nid_t pin_nid = spec->port2pin(codec, port);
2686 if (get_wcaps_type(get_wcaps(codec, pin_nid)) != AC_WID_PIN)
2691 if (codec->core.dev.power.power_state.event == PM_EVENT_SUSPEND)
2694 check_presence_and_report(codec, pin_nid, dev_id);
2698 static void setup_drm_audio_ops(struct hda_codec *codec,
2701 struct hdmi_spec *spec = codec->spec;
2703 spec->drm_audio_ops.audio_ptr = codec;
2716 static void generic_acomp_init(struct hda_codec *codec,
2720 struct hdmi_spec *spec = codec->spec;
2723 codec_info(codec, "audio component disabled by module option\n");
2728 setup_drm_audio_ops(codec, ops);
2729 if (!snd_hdac_acomp_init(&codec->bus->core, &spec->drm_audio_ops,
2736 * Intel codec parsers and helpers
2744 static void intel_haswell_enable_all_pins(struct hda_codec *codec,
2748 struct hdmi_spec *spec = codec->spec;
2750 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2756 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2762 snd_hda_codec_update_widgets(codec);
2765 static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
2768 struct hdmi_spec *spec = codec->spec;
2770 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2777 snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB);
2778 snd_hda_codec_write_cache(codec, spec->vendor_nid, 0,
2785 static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2789 intel_haswell_enable_all_pins(codec, false);
2790 intel_haswell_fixup_enable_dp12(codec);
2793 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
2794 snd_hda_codec_set_power_to_all(codec, fg, power_state);
2808 static int intel_base_nid(struct hda_codec *codec)
2810 switch (codec->core.vendor_id) {
2822 struct hda_codec *codec = audio_ptr;
2823 struct hdmi_spec *spec = codec->spec;
2827 base_nid = intel_base_nid(codec);
2842 codec_info(codec, "Can't find the HDMI/DP port for pin %d\n", pin_nid);
2846 static int intel_port2pin(struct hda_codec *codec, int port)
2848 struct hdmi_spec *spec = codec->spec;
2854 return port + intel_base_nid(codec) - 1;
2864 struct hda_codec *codec = audio_ptr;
2868 pin_nid = intel_port2pin(codec, port);
2874 if (codec->core.dev.power.power_state.event == PM_EVENT_SUSPEND)
2877 snd_hdac_i915_set_bclk(&codec->bus->core);
2878 check_presence_and_report(codec, pin_nid, dev_id);
2887 static void register_i915_notifier(struct hda_codec *codec)
2889 struct hdmi_spec *spec = codec->spec;
2893 setup_drm_audio_ops(codec, &intel_audio_ops);
2894 snd_hdac_acomp_register_notifier(&codec->bus->core,
2897 codec->relaxed_resume = 1;
2901 static int i915_hsw_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
2905 haswell_verify_D0(codec, cvt_nid, pin_nid);
2906 return hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id,
2911 static void i915_pin_cvt_fixup(struct hda_codec *codec,
2916 haswell_verify_D0(codec, per_pin->cvt_nid, per_pin->pin_nid);
2917 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2919 intel_verify_pin_cvt_connect(codec, per_pin);
2920 intel_not_share_assigned_cvt(codec, per_pin->pin_nid,
2923 intel_not_share_assigned_cvt_nid(codec, 0, 0, cvt_nid);
2928 static int alloc_intel_hdmi(struct hda_codec *codec)
2933 if (!codec->bus->core.audio_component) {
2934 codec_info(codec, "No i915 binding for Intel HDMI/DP codec\n");
2936 codec->probe_id = HDA_CODEC_ID_SKIP_PROBE;
2940 err = alloc_generic_hdmi(codec);
2944 codec->patch_ops.unsol_event = NULL;
2949 static int parse_intel_hdmi(struct hda_codec *codec)
2954 err = hdmi_parse_codec(codec);
2958 generic_spec_free(codec);
2962 generic_hdmi_init_per_pins(codec);
2963 register_i915_notifier(codec);
2968 static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid,
2974 err = alloc_intel_hdmi(codec);
2977 spec = codec->spec;
2978 codec->dp_mst = true;
2985 intel_haswell_enable_all_pins(codec, true);
2986 intel_haswell_fixup_enable_dp12(codec);
2988 codec->display_power_control = 1;
2990 codec->patch_ops.set_power_state = haswell_set_power_state;
2991 codec->depop_delay = 0;
2992 codec->auto_runtime_pm = 1;
3004 return parse_intel_hdmi(codec);
3007 static int patch_i915_hsw_hdmi(struct hda_codec *codec)
3009 return intel_hsw_common_init(codec, 0x08, NULL, 0);
3012 static int patch_i915_glk_hdmi(struct hda_codec *codec)
3014 return intel_hsw_common_init(codec, 0x0b, NULL, 0);
3017 static int patch_i915_icl_hdmi(struct hda_codec *codec)
3025 return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map));
3028 static int patch_i915_tgl_hdmi(struct hda_codec *codec)
3037 ret = intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map));
3039 struct hdmi_spec *spec = codec->spec;
3048 static int patch_i915_byt_hdmi(struct hda_codec *codec)
3053 err = alloc_intel_hdmi(codec);
3056 spec = codec->spec;
3058 /* For Valleyview/Cherryview, only the display codec is in the display
3061 codec->display_power_control = 1;
3063 codec->depop_delay = 0;
3064 codec->auto_runtime_pm = 1;
3068 return parse_intel_hdmi(codec);
3072 static int patch_i915_cpt_hdmi(struct hda_codec *codec)
3076 err = alloc_intel_hdmi(codec);
3079 return parse_intel_hdmi(codec);
3086 static int simple_playback_build_pcms(struct hda_codec *codec)
3088 struct hdmi_spec *spec = codec->spec;
3095 chans = get_wcaps(codec, per_cvt->cvt_nid);
3098 info = snd_hda_codec_pcm_new(codec, "HDMI 0");
3113 static void simple_hdmi_unsol_event(struct hda_codec *codec,
3116 snd_hda_jack_set_dirty_all(codec);
3117 snd_hda_jack_report_sync(codec);
3125 static int simple_playback_build_controls(struct hda_codec *codec)
3127 struct hdmi_spec *spec = codec->spec;
3132 err = snd_hda_create_dig_out_ctls(codec, per_cvt->cvt_nid,
3137 return simple_hdmi_build_jack(codec, 0);
3140 static int simple_playback_init(struct hda_codec *codec)
3142 struct hdmi_spec *spec = codec->spec;
3146 snd_hda_codec_write(codec, pin, 0,
3149 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
3150 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3152 snd_hda_jack_detect_enable(codec, pin, per_pin->dev_id);
3156 static void simple_playback_free(struct hda_codec *codec)
3158 struct hdmi_spec *spec = codec->spec;
3217 static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
3219 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
3223 static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
3225 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
3250 struct hda_codec *codec,
3253 struct hdmi_spec *spec = codec->spec;
3256 switch (codec->preset->vendor_id) {
3279 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3283 struct hda_codec *codec,
3286 struct hdmi_spec *spec = codec->spec;
3287 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3291 struct hda_codec *codec,
3296 struct hdmi_spec *spec = codec->spec;
3297 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3320 static int patch_simple_hdmi(struct hda_codec *codec,
3331 spec->codec = codec;
3332 codec->spec = spec;
3343 simple_playback_free(codec);
3350 codec->patch_ops = simple_hdmi_patch_ops;
3355 static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
3380 snd_hda_codec_write(codec, 0x1, 0,
3383 snd_hda_codec_write(codec, 0x1, 0,
3389 struct hda_codec *codec,
3392 struct hdmi_spec *spec = codec->spec;
3395 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
3399 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
3402 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
3408 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
3410 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3414 struct hda_codec *codec,
3422 struct hdmi_spec *spec = codec->spec;
3426 mutex_lock(&codec->spdif_mutex);
3428 spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid);
3435 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
3436 snd_hda_codec_write(codec,
3443 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
3447 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
3452 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
3453 snd_hda_codec_write(codec,
3458 snd_hda_codec_write(codec,
3473 if (codec->spdif_status_reset &&
3475 snd_hda_codec_write(codec,
3481 snd_hda_codec_write(codec,
3487 snd_hda_codec_write(codec,
3494 if (codec->spdif_status_reset &&
3496 snd_hda_codec_write(codec,
3501 snd_hda_codec_write(codec,
3508 nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
3510 mutex_unlock(&codec->spdif_mutex);
3529 static int patch_nvhdmi_2ch(struct hda_codec *codec)
3532 int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
3537 codec->patch_ops.init = nvhdmi_7x_init_2ch;
3538 /* override the PCM rates, etc, as the codec doesn't give full list */
3539 spec = codec->spec;
3547 static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
3549 struct hdmi_spec *spec = codec->spec;
3550 int err = simple_playback_build_pcms(codec);
3558 static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
3560 struct hdmi_spec *spec = codec->spec;
3565 err = simple_playback_build_controls(codec);
3576 switch (codec->preset->vendor_id) {
3589 static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
3592 int err = patch_nvhdmi_2ch(codec);
3595 spec = codec->spec;
3598 codec->patch_ops.init = nvhdmi_7x_init_8ch;
3599 codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
3600 codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
3604 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
3645 static int nvhdmi_port2pin(struct hda_codec *codec, int port)
3657 static int patch_nvhdmi(struct hda_codec *codec)
3662 err = alloc_generic_hdmi(codec);
3665 codec->dp_mst = true;
3667 spec = codec->spec;
3670 err = hdmi_parse_codec(codec);
3672 generic_spec_free(codec);
3676 generic_hdmi_init_per_pins(codec);
3685 codec->link_down_at_suspend = 1;
3687 generic_acomp_init(codec, &nvhdmi_audio_ops, nvhdmi_port2pin);
3692 static int patch_nvhdmi_legacy(struct hda_codec *codec)
3697 err = patch_generic_hdmi(codec);
3701 spec = codec->spec;
3709 codec->link_down_at_suspend = 1;
3715 * The HDA codec on NVIDIA Tegra contains two scratch registers that are
3724 * The SCRATCH0 register is used to notify the HDMI codec of changes in audio
3726 * be raised in the HDMI codec. The remainder of the bits is arbitrary. This
3754 * the format is invalidated so that the HDMI codec can be disabled.
3756 static void tegra_hdmi_set_format(struct hda_codec *codec, unsigned int format)
3761 value = snd_hda_codec_read(codec, NVIDIA_AFG_NID, 0,
3766 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3769 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3774 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3788 * HDMI codec. The HDMI driver will use that as trigger to update its
3793 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3798 struct hda_codec *codec,
3805 err = generic_hdmi_playback_pcm_prepare(hinfo, codec, stream_tag,
3810 /* notify the HDMI codec of the format change */
3811 tegra_hdmi_set_format(codec, format);
3817 struct hda_codec *codec,
3820 /* invalidate the format in the HDMI codec */
3821 tegra_hdmi_set_format(codec, 0);
3823 return generic_hdmi_playback_pcm_cleanup(hinfo, codec, substream);
3826 static struct hda_pcm *hda_find_pcm_by_type(struct hda_codec *codec, int type)
3828 struct hdmi_spec *spec = codec->spec;
3841 static int tegra_hdmi_build_pcms(struct hda_codec *codec)
3847 err = generic_hdmi_build_pcms(codec);
3851 pcm = hda_find_pcm_by_type(codec, HDA_PCM_TYPE_HDMI);
3857 * codec about format changes.
3866 static int patch_tegra_hdmi(struct hda_codec *codec)
3871 err = patch_generic_hdmi(codec);
3875 codec->depop_delay = 10;
3876 codec->patch_ops.build_pcms = tegra_hdmi_build_pcms;
3877 spec = codec->spec;
3890 #define is_amdhdmi_rev3_or_later(codec) \
3891 ((codec)->core.vendor_id == 0x1002aa01 && \
3892 ((codec)->core.revision_id & 0xff00) >= 0x0300)
3893 #define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec)
3933 static int atihdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
3938 return snd_hdmi_get_eld_ati(codec, nid, buf, eld_size,
3939 is_amdhdmi_rev3_or_later(codec));
3942 static void atihdmi_pin_setup_infoframe(struct hda_codec *codec,
3947 snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_CHANNEL_ALLOCATION, ca);
4018 struct hda_codec *codec = hdac_to_hda_codec(hdac);
4025 if (!has_amd_full_remap_support(codec)) {
4048 return snd_hda_codec_write(codec, pin_nid, 0, verb, ati_channel_setup);
4054 struct hda_codec *codec = hdac_to_hda_codec(hdac);
4063 if (!has_amd_full_remap_support(codec)) {
4073 ati_channel_setup = snd_hda_codec_read(codec, pin_nid, 0, verb, 0);
4136 static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
4143 hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0);
4150 codec_dbg(codec,
4157 snd_hda_codec_write(codec, pin_nid, 0,
4167 static int atihdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
4171 if (is_amdhdmi_rev3_or_later(codec)) {
4177 snd_hda_codec_write(codec, cvt_nid, 0, ATI_VERB_SET_RAMP_RATE, ramp_rate);
4180 return hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id,
4185 static int atihdmi_init(struct hda_codec *codec)
4187 struct hdmi_spec *spec = codec->spec;
4190 err = generic_hdmi_init(codec);
4199 snd_hda_codec_write(codec, per_pin->pin_nid, 0, ATI_VERB_SET_DOWNMIX_INFO, 0);
4202 if (has_amd_full_remap_support(codec))
4203 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
4207 codec->auto_runtime_pm = 1;
4220 static int atihdmi_port2pin(struct hda_codec *codec, int port)
4232 static int patch_atihdmi(struct hda_codec *codec)
4238 err = patch_generic_hdmi(codec);
4243 codec->patch_ops.init = atihdmi_init;
4245 spec = codec->spec;
4255 if (!has_amd_full_remap_support(codec)) {
4278 codec->link_down_at_suspend = 1;
4280 generic_acomp_init(codec, &atihdmi_audio_ops, atihdmi_port2pin);
4289 static int patch_via_hdmi(struct hda_codec *codec)
4291 return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
4294 static int patch_gf_hdmi(struct hda_codec *codec)
4298 err = patch_generic_hdmi(codec);
4303 * Glenfly GPUs have two codecs, stream switches from one codec to
4306 codec->no_sticky_stream = 1;
4450 MODULE_DESCRIPTION("HDMI HD-audio codec");
4451 MODULE_ALIAS("snd-hda-codec-intelhdmi");
4452 MODULE_ALIAS("snd-hda-codec-nvhdmi");
4453 MODULE_ALIAS("snd-hda-codec-atihdmi");