1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * patch_hdmi.c - routines for HDMI/DisplayPort codecs
6 * Copyright(c) 2008-2010 Intel Corporation. All rights reserved.
7 * Copyright (c) 2006 ATI Technologies Inc.
8 * Copyright (c) 2008 NVIDIA Corp. All rights reserved.
9 * Copyright (c) 2008 Wei Ni <wni@nvidia.com>
10 * Copyright (c) 2013 Anssi Hannula <anssi.hannula@iki.fi>
13 * Wu Fengguang <wfg@linux.intel.com>
16 * Wu Fengguang <wfg@linux.intel.com>
19 #include <linux/init.h>
20 #include <linux/delay.h>
21 #include <linux/pci.h>
22 #include <linux/slab.h>
23 #include <linux/module.h>
24 #include <linux/pm_runtime.h>
25 #include <sound/core.h>
26 #include <sound/jack.h>
27 #include <sound/asoundef.h>
28 #include <sound/tlv.h>
29 #include <sound/hdaudio.h>
30 #include <sound/hda_i915.h>
31 #include <sound/hda_chmap.h>
32 #include <sound/hda_codec.h>
33 #include "hda_local.h"
36 static bool static_hdmi_pcm;
37 module_param(static_hdmi_pcm, bool, 0644);
38 MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
40 struct hdmi_spec_per_cvt {
43 unsigned int channels_min;
44 unsigned int channels_max;
50 /* max. connections to a widget */
51 #define HDA_MAX_CONNECTIONS 32
53 struct hdmi_spec_per_pin {
56 /* pin idx, different device entries on the same pin use the same idx */
59 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
63 struct hda_codec *codec;
64 struct hdmi_eld sink_eld;
66 struct delayed_work work;
67 struct hdmi_pcm *pcm; /* pointer to spec->pcm_rec[n] dynamically*/
68 int pcm_idx; /* which pcm is attached. -1 means no pcm is attached */
70 bool setup; /* the stream has been set up by prepare callback */
71 int channels; /* current number of channels */
73 bool chmap_set; /* channel-map override by ALSA API? */
74 unsigned char chmap[8]; /* ALSA API channel-map */
75 #ifdef CONFIG_SND_PROC_FS
76 struct snd_info_entry *proc_entry;
80 /* operations used by generic code that can be overridden by patches */
82 int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid,
83 int dev_id, unsigned char *buf, int *eld_size);
85 void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid,
87 int ca, int active_channels, int conn_type);
89 /* enable/disable HBR (HD passthrough) */
90 int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid,
91 int dev_id, bool hbr);
93 int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid,
94 hda_nid_t pin_nid, int dev_id, u32 stream_tag,
97 void (*pin_cvt_fixup)(struct hda_codec *codec,
98 struct hdmi_spec_per_pin *per_pin,
104 struct snd_jack *jack;
105 struct snd_kcontrol *eld_ctl;
109 struct hda_codec *codec;
111 struct snd_array cvts; /* struct hdmi_spec_per_cvt */
112 hda_nid_t cvt_nids[4]; /* only for haswell fix */
115 * num_pins is the number of virtual pins
116 * for example, there are 3 pins, and each pin
117 * has 4 device entries, then the num_pins is 12
121 * num_nids is the number of real pins
122 * In the above example, num_nids is 3
126 * dev_num is the number of device entries
128 * In the above example, dev_num is 4
131 struct snd_array pins; /* struct hdmi_spec_per_pin */
132 struct hdmi_pcm pcm_rec[16];
133 struct mutex pcm_lock;
134 struct mutex bind_lock; /* for audio component binding */
135 /* pcm_bitmap means which pcms have been assigned to pins*/
136 unsigned long pcm_bitmap;
137 int pcm_used; /* counter of pcm_rec[] */
138 /* bitmap shows whether the pcm is opened in user space
139 * bit 0 means the first playback PCM (PCM3);
140 * bit 1 means the second playback PCM, and so on.
142 unsigned long pcm_in_use;
144 struct hdmi_eld temp_eld;
149 bool intel_hsw_fixup; /* apply Intel platform-specific fixups */
151 * Non-generic VIA/NVIDIA specific
153 struct hda_multi_out multiout;
154 struct hda_pcm_stream pcm_playback;
156 bool use_jack_detect; /* jack detection enabled */
157 bool use_acomp_notifier; /* use eld_notify callback for hotplug */
158 bool acomp_registered; /* audio component registered in this driver */
159 struct drm_audio_component_audio_ops drm_audio_ops;
160 int (*port2pin)(struct hda_codec *, int); /* reverse port/pin mapping */
162 struct hdac_chmap chmap;
163 hda_nid_t vendor_nid;
168 #ifdef CONFIG_SND_HDA_COMPONENT
169 static inline bool codec_has_acomp(struct hda_codec *codec)
171 struct hdmi_spec *spec = codec->spec;
172 return spec->use_acomp_notifier;
175 #define codec_has_acomp(codec) false
178 struct hdmi_audio_infoframe {
185 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
189 u8 LFEPBL01_LSV36_DM_INH7;
192 struct dp_audio_infoframe {
195 u8 ver; /* 0x11 << 2 */
197 u8 CC02_CT47; /* match with HDMI infoframe from this on */
201 u8 LFEPBL01_LSV36_DM_INH7;
204 union audio_infoframe {
205 struct hdmi_audio_infoframe hdmi;
206 struct dp_audio_infoframe dp;
214 #define get_pin(spec, idx) \
215 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx))
216 #define get_cvt(spec, idx) \
217 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx))
218 /* obtain hdmi_pcm object assigned to idx */
219 #define get_hdmi_pcm(spec, idx) (&(spec)->pcm_rec[idx])
220 /* obtain hda_pcm object assigned to idx */
221 #define get_pcm_rec(spec, idx) (get_hdmi_pcm(spec, idx)->pcm)
223 static int pin_id_to_pin_index(struct hda_codec *codec,
224 hda_nid_t pin_nid, int dev_id)
226 struct hdmi_spec *spec = codec->spec;
228 struct hdmi_spec_per_pin *per_pin;
231 * (dev_id == -1) means it is NON-MST pin
232 * return the first virtual pin on this port
237 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
238 per_pin = get_pin(spec, pin_idx);
239 if ((per_pin->pin_nid == pin_nid) &&
240 (per_pin->dev_id == dev_id))
244 codec_warn(codec, "HDMI: pin nid %d not registered\n", pin_nid);
248 static int hinfo_to_pcm_index(struct hda_codec *codec,
249 struct hda_pcm_stream *hinfo)
251 struct hdmi_spec *spec = codec->spec;
254 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++)
255 if (get_pcm_rec(spec, pcm_idx)->stream == hinfo)
258 codec_warn(codec, "HDMI: hinfo %p not registered\n", hinfo);
262 static int hinfo_to_pin_index(struct hda_codec *codec,
263 struct hda_pcm_stream *hinfo)
265 struct hdmi_spec *spec = codec->spec;
266 struct hdmi_spec_per_pin *per_pin;
269 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
270 per_pin = get_pin(spec, pin_idx);
272 per_pin->pcm->pcm->stream == hinfo)
276 codec_dbg(codec, "HDMI: hinfo %p not registered\n", hinfo);
280 static struct hdmi_spec_per_pin *pcm_idx_to_pin(struct hdmi_spec *spec,
284 struct hdmi_spec_per_pin *per_pin;
286 for (i = 0; i < spec->num_pins; i++) {
287 per_pin = get_pin(spec, i);
288 if (per_pin->pcm_idx == pcm_idx)
294 static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid)
296 struct hdmi_spec *spec = codec->spec;
299 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
300 if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid)
303 codec_warn(codec, "HDMI: cvt nid %d not registered\n", cvt_nid);
307 static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
308 struct snd_ctl_elem_info *uinfo)
310 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
311 struct hdmi_spec *spec = codec->spec;
312 struct hdmi_spec_per_pin *per_pin;
313 struct hdmi_eld *eld;
316 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
318 pcm_idx = kcontrol->private_value;
319 mutex_lock(&spec->pcm_lock);
320 per_pin = pcm_idx_to_pin(spec, pcm_idx);
322 /* no pin is bound to the pcm */
326 eld = &per_pin->sink_eld;
327 uinfo->count = eld->eld_valid ? eld->eld_size : 0;
330 mutex_unlock(&spec->pcm_lock);
334 static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
335 struct snd_ctl_elem_value *ucontrol)
337 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
338 struct hdmi_spec *spec = codec->spec;
339 struct hdmi_spec_per_pin *per_pin;
340 struct hdmi_eld *eld;
344 pcm_idx = kcontrol->private_value;
345 mutex_lock(&spec->pcm_lock);
346 per_pin = pcm_idx_to_pin(spec, pcm_idx);
348 /* no pin is bound to the pcm */
349 memset(ucontrol->value.bytes.data, 0,
350 ARRAY_SIZE(ucontrol->value.bytes.data));
354 eld = &per_pin->sink_eld;
355 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data) ||
356 eld->eld_size > ELD_MAX_SIZE) {
362 memset(ucontrol->value.bytes.data, 0,
363 ARRAY_SIZE(ucontrol->value.bytes.data));
365 memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
369 mutex_unlock(&spec->pcm_lock);
373 static const struct snd_kcontrol_new eld_bytes_ctl = {
374 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
375 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
377 .info = hdmi_eld_ctl_info,
378 .get = hdmi_eld_ctl_get,
381 static int hdmi_create_eld_ctl(struct hda_codec *codec, int pcm_idx,
384 struct snd_kcontrol *kctl;
385 struct hdmi_spec *spec = codec->spec;
388 kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
391 kctl->private_value = pcm_idx;
392 kctl->id.device = device;
394 /* no pin nid is associated with the kctl now
395 * tbd: associate pin nid to eld ctl later
397 err = snd_hda_ctl_add(codec, 0, kctl);
401 get_hdmi_pcm(spec, pcm_idx)->eld_ctl = kctl;
406 static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
407 int *packet_index, int *byte_index)
411 val = snd_hda_codec_read(codec, pin_nid, 0,
412 AC_VERB_GET_HDMI_DIP_INDEX, 0);
414 *packet_index = val >> 5;
415 *byte_index = val & 0x1f;
419 static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
420 int packet_index, int byte_index)
424 val = (packet_index << 5) | (byte_index & 0x1f);
426 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
429 static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
432 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
435 static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
437 struct hdmi_spec *spec = codec->spec;
441 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
442 snd_hda_codec_write(codec, pin_nid, 0,
443 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
445 if (spec->dyn_pin_out)
446 /* Disable pin out until stream is active */
449 /* Enable pin out: some machines with GM965 gets broken output
450 * when the pin is disabled or changed while using with HDMI
454 snd_hda_codec_write(codec, pin_nid, 0,
455 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_out);
462 #ifdef CONFIG_SND_PROC_FS
463 static void print_eld_info(struct snd_info_entry *entry,
464 struct snd_info_buffer *buffer)
466 struct hdmi_spec_per_pin *per_pin = entry->private_data;
468 mutex_lock(&per_pin->lock);
469 snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer);
470 mutex_unlock(&per_pin->lock);
473 static void write_eld_info(struct snd_info_entry *entry,
474 struct snd_info_buffer *buffer)
476 struct hdmi_spec_per_pin *per_pin = entry->private_data;
478 mutex_lock(&per_pin->lock);
479 snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer);
480 mutex_unlock(&per_pin->lock);
483 static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
486 struct hda_codec *codec = per_pin->codec;
487 struct snd_info_entry *entry;
490 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
491 err = snd_card_proc_new(codec->card, name, &entry);
495 snd_info_set_text_ops(entry, per_pin, print_eld_info);
496 entry->c.text.write = write_eld_info;
498 per_pin->proc_entry = entry;
503 static void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
505 if (!per_pin->codec->bus->shutdown) {
506 snd_info_free_entry(per_pin->proc_entry);
507 per_pin->proc_entry = NULL;
511 static inline int eld_proc_new(struct hdmi_spec_per_pin *per_pin,
516 static inline void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
522 * Audio InfoFrame routines
526 * Enable Audio InfoFrame Transmission
528 static void hdmi_start_infoframe_trans(struct hda_codec *codec,
531 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
532 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
537 * Disable Audio InfoFrame Transmission
539 static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
542 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
543 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
547 static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
549 #ifdef CONFIG_SND_DEBUG_VERBOSE
553 size = snd_hdmi_get_eld_size(codec, pin_nid);
554 codec_dbg(codec, "HDMI: ELD buf size is %d\n", size);
556 for (i = 0; i < 8; i++) {
557 size = snd_hda_codec_read(codec, pin_nid, 0,
558 AC_VERB_GET_HDMI_DIP_SIZE, i);
559 codec_dbg(codec, "HDMI: DIP GP[%d] buf size is %d\n", i, size);
564 static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
570 for (i = 0; i < 8; i++) {
571 size = snd_hda_codec_read(codec, pin_nid, 0,
572 AC_VERB_GET_HDMI_DIP_SIZE, i);
576 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
577 for (j = 1; j < 1000; j++) {
578 hdmi_write_dip_byte(codec, pin_nid, 0x0);
579 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
581 codec_dbg(codec, "dip index %d: %d != %d\n",
583 if (bi == 0) /* byte index wrapped around */
587 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
593 static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
595 u8 *bytes = (u8 *)hdmi_ai;
599 hdmi_ai->checksum = 0;
601 for (i = 0; i < sizeof(*hdmi_ai); i++)
604 hdmi_ai->checksum = -sum;
607 static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
613 hdmi_debug_dip_size(codec, pin_nid);
614 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
616 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
617 for (i = 0; i < size; i++)
618 hdmi_write_dip_byte(codec, pin_nid, dip[i]);
621 static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
627 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
631 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
632 for (i = 0; i < size; i++) {
633 val = snd_hda_codec_read(codec, pin_nid, 0,
634 AC_VERB_GET_HDMI_DIP_DATA, 0);
642 static int hdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
643 int dev_id, unsigned char *buf, int *eld_size)
645 snd_hda_set_dev_select(codec, nid, dev_id);
647 return snd_hdmi_get_eld(codec, nid, buf, eld_size);
650 static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
651 hda_nid_t pin_nid, int dev_id,
652 int ca, int active_channels,
655 union audio_infoframe ai;
657 memset(&ai, 0, sizeof(ai));
658 if (conn_type == 0) { /* HDMI */
659 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
661 hdmi_ai->type = 0x84;
664 hdmi_ai->CC02_CT47 = active_channels - 1;
666 hdmi_checksum_audio_infoframe(hdmi_ai);
667 } else if (conn_type == 1) { /* DisplayPort */
668 struct dp_audio_infoframe *dp_ai = &ai.dp;
672 dp_ai->ver = 0x11 << 2;
673 dp_ai->CC02_CT47 = active_channels - 1;
676 codec_dbg(codec, "HDMI: unknown connection type at pin %d\n",
681 snd_hda_set_dev_select(codec, pin_nid, dev_id);
684 * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
685 * sizeof(*dp_ai) to avoid partial match/update problems when
686 * the user switches between HDMI/DP monitors.
688 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
691 "hdmi_pin_setup_infoframe: pin=%d channels=%d ca=0x%02x\n",
693 active_channels, ca);
694 hdmi_stop_infoframe_trans(codec, pin_nid);
695 hdmi_fill_audio_infoframe(codec, pin_nid,
696 ai.bytes, sizeof(ai));
697 hdmi_start_infoframe_trans(codec, pin_nid);
701 static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
702 struct hdmi_spec_per_pin *per_pin,
705 struct hdmi_spec *spec = codec->spec;
706 struct hdac_chmap *chmap = &spec->chmap;
707 hda_nid_t pin_nid = per_pin->pin_nid;
708 int dev_id = per_pin->dev_id;
709 int channels = per_pin->channels;
711 struct hdmi_eld *eld;
717 snd_hda_set_dev_select(codec, pin_nid, dev_id);
719 /* some HW (e.g. HSW+) needs reprogramming the amp at each time */
720 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
721 snd_hda_codec_write(codec, pin_nid, 0,
722 AC_VERB_SET_AMP_GAIN_MUTE,
725 eld = &per_pin->sink_eld;
727 ca = snd_hdac_channel_allocation(&codec->core,
728 eld->info.spk_alloc, channels,
729 per_pin->chmap_set, non_pcm, per_pin->chmap);
731 active_channels = snd_hdac_get_active_channels(ca);
733 chmap->ops.set_channel_count(&codec->core, per_pin->cvt_nid,
737 * always configure channel mapping, it may have been changed by the
738 * user in the meantime
740 snd_hdac_setup_channel_mapping(&spec->chmap,
741 pin_nid, non_pcm, ca, channels,
742 per_pin->chmap, per_pin->chmap_set);
744 spec->ops.pin_setup_infoframe(codec, pin_nid, dev_id,
745 ca, active_channels, eld->info.conn_type);
747 per_pin->non_pcm = non_pcm;
754 static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
756 static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid,
759 struct hdmi_spec *spec = codec->spec;
760 int pin_idx = pin_id_to_pin_index(codec, nid, dev_id);
764 mutex_lock(&spec->pcm_lock);
765 if (hdmi_present_sense(get_pin(spec, pin_idx), 1))
766 snd_hda_jack_report_sync(codec);
767 mutex_unlock(&spec->pcm_lock);
770 static void jack_callback(struct hda_codec *codec,
771 struct hda_jack_callback *jack)
773 /* stop polling when notification is enabled */
774 if (codec_has_acomp(codec))
777 check_presence_and_report(codec, jack->nid, jack->dev_id);
780 static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
782 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
783 struct hda_jack_tbl *jack;
787 (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
789 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, dev_entry);
791 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, 0);
795 jack->jack_dirty = 1;
798 "HDMI hot plug event: Codec=%d Pin=%d Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n",
799 codec->addr, jack->nid, jack->dev_id, !!(res & AC_UNSOL_RES_IA),
800 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
802 check_presence_and_report(codec, jack->nid, jack->dev_id);
805 static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
807 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
808 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
809 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
810 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
813 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
828 static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
830 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
831 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
832 struct hda_jack_tbl *jack;
834 if (codec_has_acomp(codec))
839 (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
841 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, dev_entry);
843 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, 0);
847 codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag);
852 hdmi_intrinsic_event(codec, res);
854 hdmi_non_intrinsic_event(codec, res);
857 static void haswell_verify_D0(struct hda_codec *codec,
858 hda_nid_t cvt_nid, hda_nid_t nid)
862 /* For Haswell, the converter 1/2 may keep in D3 state after bootup,
863 * thus pins could only choose converter 0 for use. Make sure the
864 * converters are in correct power state */
865 if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0))
866 snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
868 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) {
869 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
872 pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
873 pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
874 codec_dbg(codec, "Haswell HDMI audio: Power for pin 0x%x is now D%d\n", nid, pwr);
882 /* HBR should be Non-PCM, 8 channels */
883 #define is_hbr_format(format) \
884 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
886 static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
887 int dev_id, bool hbr)
889 int pinctl, new_pinctl;
891 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
892 snd_hda_set_dev_select(codec, pin_nid, dev_id);
893 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
894 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
897 return hbr ? -EINVAL : 0;
899 new_pinctl = pinctl & ~AC_PINCTL_EPT;
901 new_pinctl |= AC_PINCTL_EPT_HBR;
903 new_pinctl |= AC_PINCTL_EPT_NATIVE;
906 "hdmi_pin_hbr_setup: NID=0x%x, %spinctl=0x%x\n",
908 pinctl == new_pinctl ? "" : "new-",
911 if (pinctl != new_pinctl)
912 snd_hda_codec_write(codec, pin_nid, 0,
913 AC_VERB_SET_PIN_WIDGET_CONTROL,
921 static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
922 hda_nid_t pin_nid, int dev_id,
923 u32 stream_tag, int format)
925 struct hdmi_spec *spec = codec->spec;
929 err = spec->ops.pin_hbr_setup(codec, pin_nid, dev_id,
930 is_hbr_format(format));
933 codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n");
937 if (spec->intel_hsw_fixup) {
940 * on recent platforms IEC Coding Type is required for HBR
941 * support, read current Digital Converter settings and set
942 * ICT bitfield if needed.
944 param = snd_hda_codec_read(codec, cvt_nid, 0,
945 AC_VERB_GET_DIGI_CONVERT_1, 0);
947 param = (param >> 16) & ~(AC_DIG3_ICT);
949 /* on recent platforms ICT mode is required for HBR support */
950 if (is_hbr_format(format))
953 snd_hda_codec_write(codec, cvt_nid, 0,
954 AC_VERB_SET_DIGI_CONVERT_3, param);
957 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
961 /* Try to find an available converter
962 * If pin_idx is less then zero, just try to find an available converter.
963 * Otherwise, try to find an available converter and get the cvt mux index
966 static int hdmi_choose_cvt(struct hda_codec *codec,
967 int pin_idx, int *cvt_id)
969 struct hdmi_spec *spec = codec->spec;
970 struct hdmi_spec_per_pin *per_pin;
971 struct hdmi_spec_per_cvt *per_cvt = NULL;
972 int cvt_idx, mux_idx = 0;
974 /* pin_idx < 0 means no pin will be bound to the converter */
978 per_pin = get_pin(spec, pin_idx);
980 /* Dynamically assign converter to stream */
981 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
982 per_cvt = get_cvt(spec, cvt_idx);
984 /* Must not already be assigned */
985 if (per_cvt->assigned)
989 /* Must be in pin's mux's list of converters */
990 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
991 if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid)
993 /* Not in mux list */
994 if (mux_idx == per_pin->num_mux_nids)
999 /* No free converters */
1000 if (cvt_idx == spec->num_cvts)
1003 if (per_pin != NULL)
1004 per_pin->mux_idx = mux_idx;
1012 /* Assure the pin select the right convetor */
1013 static void intel_verify_pin_cvt_connect(struct hda_codec *codec,
1014 struct hdmi_spec_per_pin *per_pin)
1016 hda_nid_t pin_nid = per_pin->pin_nid;
1019 mux_idx = per_pin->mux_idx;
1020 curr = snd_hda_codec_read(codec, pin_nid, 0,
1021 AC_VERB_GET_CONNECT_SEL, 0);
1022 if (curr != mux_idx)
1023 snd_hda_codec_write_cache(codec, pin_nid, 0,
1024 AC_VERB_SET_CONNECT_SEL,
1028 /* get the mux index for the converter of the pins
1029 * converter's mux index is the same for all pins on Intel platform
1031 static int intel_cvt_id_to_mux_idx(struct hdmi_spec *spec,
1036 for (i = 0; i < spec->num_cvts; i++)
1037 if (spec->cvt_nids[i] == cvt_nid)
1042 /* Intel HDMI workaround to fix audio routing issue:
1043 * For some Intel display codecs, pins share the same connection list.
1044 * So a conveter can be selected by multiple pins and playback on any of these
1045 * pins will generate sound on the external display, because audio flows from
1046 * the same converter to the display pipeline. Also muting one pin may make
1047 * other pins have no sound output.
1048 * So this function assures that an assigned converter for a pin is not selected
1049 * by any other pins.
1051 static void intel_not_share_assigned_cvt(struct hda_codec *codec,
1053 int dev_id, int mux_idx)
1055 struct hdmi_spec *spec = codec->spec;
1058 struct hdmi_spec_per_cvt *per_cvt;
1059 struct hdmi_spec_per_pin *per_pin;
1062 /* configure the pins connections */
1063 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1067 per_pin = get_pin(spec, pin_idx);
1069 * pin not connected to monitor
1070 * no need to operate on it
1075 if ((per_pin->pin_nid == pin_nid) &&
1076 (per_pin->dev_id == dev_id))
1080 * if per_pin->dev_id >= dev_num,
1081 * snd_hda_get_dev_select() will fail,
1082 * and the following operation is unpredictable.
1083 * So skip this situation.
1085 dev_num = snd_hda_get_num_devices(codec, per_pin->pin_nid) + 1;
1086 if (per_pin->dev_id >= dev_num)
1089 nid = per_pin->pin_nid;
1092 * Calling this function should not impact
1093 * on the device entry selection
1094 * So let's save the dev id for each pin,
1095 * and restore it when return
1097 dev_id_saved = snd_hda_get_dev_select(codec, nid);
1098 snd_hda_set_dev_select(codec, nid, per_pin->dev_id);
1099 curr = snd_hda_codec_read(codec, nid, 0,
1100 AC_VERB_GET_CONNECT_SEL, 0);
1101 if (curr != mux_idx) {
1102 snd_hda_set_dev_select(codec, nid, dev_id_saved);
1107 /* choose an unassigned converter. The conveters in the
1108 * connection list are in the same order as in the codec.
1110 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
1111 per_cvt = get_cvt(spec, cvt_idx);
1112 if (!per_cvt->assigned) {
1114 "choose cvt %d for pin nid %d\n",
1116 snd_hda_codec_write_cache(codec, nid, 0,
1117 AC_VERB_SET_CONNECT_SEL,
1122 snd_hda_set_dev_select(codec, nid, dev_id_saved);
1126 /* A wrapper of intel_not_share_asigned_cvt() */
1127 static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,
1128 hda_nid_t pin_nid, int dev_id, hda_nid_t cvt_nid)
1131 struct hdmi_spec *spec = codec->spec;
1133 /* On Intel platform, the mapping of converter nid to
1134 * mux index of the pins are always the same.
1135 * The pin nid may be 0, this means all pins will not
1136 * share the converter.
1138 mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid);
1140 intel_not_share_assigned_cvt(codec, pin_nid, dev_id, mux_idx);
1143 /* skeleton caller of pin_cvt_fixup ops */
1144 static void pin_cvt_fixup(struct hda_codec *codec,
1145 struct hdmi_spec_per_pin *per_pin,
1148 struct hdmi_spec *spec = codec->spec;
1150 if (spec->ops.pin_cvt_fixup)
1151 spec->ops.pin_cvt_fixup(codec, per_pin, cvt_nid);
1154 /* called in hdmi_pcm_open when no pin is assigned to the PCM
1155 * in dyn_pcm_assign mode.
1157 static int hdmi_pcm_open_no_pin(struct hda_pcm_stream *hinfo,
1158 struct hda_codec *codec,
1159 struct snd_pcm_substream *substream)
1161 struct hdmi_spec *spec = codec->spec;
1162 struct snd_pcm_runtime *runtime = substream->runtime;
1163 int cvt_idx, pcm_idx;
1164 struct hdmi_spec_per_cvt *per_cvt = NULL;
1167 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1171 err = hdmi_choose_cvt(codec, -1, &cvt_idx);
1175 per_cvt = get_cvt(spec, cvt_idx);
1176 per_cvt->assigned = 1;
1177 hinfo->nid = per_cvt->cvt_nid;
1179 pin_cvt_fixup(codec, NULL, per_cvt->cvt_nid);
1181 set_bit(pcm_idx, &spec->pcm_in_use);
1182 /* todo: setup spdif ctls assign */
1184 /* Initially set the converter's capabilities */
1185 hinfo->channels_min = per_cvt->channels_min;
1186 hinfo->channels_max = per_cvt->channels_max;
1187 hinfo->rates = per_cvt->rates;
1188 hinfo->formats = per_cvt->formats;
1189 hinfo->maxbps = per_cvt->maxbps;
1191 /* Store the updated parameters */
1192 runtime->hw.channels_min = hinfo->channels_min;
1193 runtime->hw.channels_max = hinfo->channels_max;
1194 runtime->hw.formats = hinfo->formats;
1195 runtime->hw.rates = hinfo->rates;
1197 snd_pcm_hw_constraint_step(substream->runtime, 0,
1198 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
1205 static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1206 struct hda_codec *codec,
1207 struct snd_pcm_substream *substream)
1209 struct hdmi_spec *spec = codec->spec;
1210 struct snd_pcm_runtime *runtime = substream->runtime;
1211 int pin_idx, cvt_idx, pcm_idx;
1212 struct hdmi_spec_per_pin *per_pin;
1213 struct hdmi_eld *eld;
1214 struct hdmi_spec_per_cvt *per_cvt = NULL;
1217 /* Validate hinfo */
1218 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1222 mutex_lock(&spec->pcm_lock);
1223 pin_idx = hinfo_to_pin_index(codec, hinfo);
1224 if (!spec->dyn_pcm_assign) {
1225 if (snd_BUG_ON(pin_idx < 0)) {
1230 /* no pin is assigned to the PCM
1231 * PA need pcm open successfully when probe
1234 err = hdmi_pcm_open_no_pin(hinfo, codec, substream);
1239 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx);
1243 per_cvt = get_cvt(spec, cvt_idx);
1244 /* Claim converter */
1245 per_cvt->assigned = 1;
1247 set_bit(pcm_idx, &spec->pcm_in_use);
1248 per_pin = get_pin(spec, pin_idx);
1249 per_pin->cvt_nid = per_cvt->cvt_nid;
1250 hinfo->nid = per_cvt->cvt_nid;
1252 snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id);
1253 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1254 AC_VERB_SET_CONNECT_SEL,
1257 /* configure unused pins to choose other converters */
1258 pin_cvt_fixup(codec, per_pin, 0);
1260 snd_hda_spdif_ctls_assign(codec, pcm_idx, per_cvt->cvt_nid);
1262 /* Initially set the converter's capabilities */
1263 hinfo->channels_min = per_cvt->channels_min;
1264 hinfo->channels_max = per_cvt->channels_max;
1265 hinfo->rates = per_cvt->rates;
1266 hinfo->formats = per_cvt->formats;
1267 hinfo->maxbps = per_cvt->maxbps;
1269 eld = &per_pin->sink_eld;
1270 /* Restrict capabilities by ELD if this isn't disabled */
1271 if (!static_hdmi_pcm && eld->eld_valid) {
1272 snd_hdmi_eld_update_pcm_info(&eld->info, hinfo);
1273 if (hinfo->channels_min > hinfo->channels_max ||
1274 !hinfo->rates || !hinfo->formats) {
1275 per_cvt->assigned = 0;
1277 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
1283 /* Store the updated parameters */
1284 runtime->hw.channels_min = hinfo->channels_min;
1285 runtime->hw.channels_max = hinfo->channels_max;
1286 runtime->hw.formats = hinfo->formats;
1287 runtime->hw.rates = hinfo->rates;
1289 snd_pcm_hw_constraint_step(substream->runtime, 0,
1290 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
1292 mutex_unlock(&spec->pcm_lock);
1297 * HDA/HDMI auto parsing
1299 static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
1301 struct hdmi_spec *spec = codec->spec;
1302 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1303 hda_nid_t pin_nid = per_pin->pin_nid;
1304 int dev_id = per_pin->dev_id;
1306 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
1308 "HDMI: pin %d wcaps %#x does not support connection list\n",
1309 pin_nid, get_wcaps(codec, pin_nid));
1313 snd_hda_set_dev_select(codec, pin_nid, dev_id);
1315 /* all the device entries on the same pin have the same conn list */
1316 per_pin->num_mux_nids =
1317 snd_hda_get_raw_connections(codec, pin_nid, per_pin->mux_nids,
1318 HDA_MAX_CONNECTIONS);
1323 static int hdmi_find_pcm_slot(struct hdmi_spec *spec,
1324 struct hdmi_spec_per_pin *per_pin)
1329 * generic_hdmi_build_pcms() allocates (num_nids + dev_num - 1)
1332 * The per_pin of pin_nid_idx=n and dev_id=m prefers to get pcm-n
1333 * if m==0. This guarantees that dynamic pcm assignments are compatible
1334 * with the legacy static per_pin-pmc assignment that existed in the
1335 * days before DP-MST.
1337 * per_pin of m!=0 prefers to get pcm=(num_nids + (m - 1)).
1339 if (per_pin->dev_id == 0 &&
1340 !test_bit(per_pin->pin_nid_idx, &spec->pcm_bitmap))
1341 return per_pin->pin_nid_idx;
1343 if (per_pin->dev_id != 0 &&
1344 !(test_bit(spec->num_nids + (per_pin->dev_id - 1),
1345 &spec->pcm_bitmap))) {
1346 return spec->num_nids + (per_pin->dev_id - 1);
1349 /* have a second try; check the area over num_nids */
1350 for (i = spec->num_nids; i < spec->pcm_used; i++) {
1351 if (!test_bit(i, &spec->pcm_bitmap))
1355 /* the last try; check the empty slots in pins */
1356 for (i = 0; i < spec->num_nids; i++) {
1357 if (!test_bit(i, &spec->pcm_bitmap))
1363 static void hdmi_attach_hda_pcm(struct hdmi_spec *spec,
1364 struct hdmi_spec_per_pin *per_pin)
1368 /* pcm already be attached to the pin */
1371 idx = hdmi_find_pcm_slot(spec, per_pin);
1374 per_pin->pcm_idx = idx;
1375 per_pin->pcm = get_hdmi_pcm(spec, idx);
1376 set_bit(idx, &spec->pcm_bitmap);
1379 static void hdmi_detach_hda_pcm(struct hdmi_spec *spec,
1380 struct hdmi_spec_per_pin *per_pin)
1384 /* pcm already be detached from the pin */
1387 idx = per_pin->pcm_idx;
1388 per_pin->pcm_idx = -1;
1389 per_pin->pcm = NULL;
1390 if (idx >= 0 && idx < spec->pcm_used)
1391 clear_bit(idx, &spec->pcm_bitmap);
1394 static int hdmi_get_pin_cvt_mux(struct hdmi_spec *spec,
1395 struct hdmi_spec_per_pin *per_pin, hda_nid_t cvt_nid)
1399 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
1400 if (per_pin->mux_nids[mux_idx] == cvt_nid)
1405 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid);
1407 static void hdmi_pcm_setup_pin(struct hdmi_spec *spec,
1408 struct hdmi_spec_per_pin *per_pin)
1410 struct hda_codec *codec = per_pin->codec;
1411 struct hda_pcm *pcm;
1412 struct hda_pcm_stream *hinfo;
1413 struct snd_pcm_substream *substream;
1417 if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
1418 pcm = get_pcm_rec(spec, per_pin->pcm_idx);
1423 if (!test_bit(per_pin->pcm_idx, &spec->pcm_in_use))
1426 /* hdmi audio only uses playback and one substream */
1427 hinfo = pcm->stream;
1428 substream = pcm->pcm->streams[0].substream;
1430 per_pin->cvt_nid = hinfo->nid;
1432 mux_idx = hdmi_get_pin_cvt_mux(spec, per_pin, hinfo->nid);
1433 if (mux_idx < per_pin->num_mux_nids) {
1434 snd_hda_set_dev_select(codec, per_pin->pin_nid,
1436 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1437 AC_VERB_SET_CONNECT_SEL,
1440 snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid);
1442 non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid);
1443 if (substream->runtime)
1444 per_pin->channels = substream->runtime->channels;
1445 per_pin->setup = true;
1446 per_pin->mux_idx = mux_idx;
1448 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
1451 static void hdmi_pcm_reset_pin(struct hdmi_spec *spec,
1452 struct hdmi_spec_per_pin *per_pin)
1454 if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
1455 snd_hda_spdif_ctls_unassign(per_pin->codec, per_pin->pcm_idx);
1457 per_pin->chmap_set = false;
1458 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
1460 per_pin->setup = false;
1461 per_pin->channels = 0;
1464 /* update per_pin ELD from the given new ELD;
1465 * setup info frame and notification accordingly
1467 static bool update_eld(struct hda_codec *codec,
1468 struct hdmi_spec_per_pin *per_pin,
1469 struct hdmi_eld *eld)
1471 struct hdmi_eld *pin_eld = &per_pin->sink_eld;
1472 struct hdmi_spec *spec = codec->spec;
1473 bool old_eld_valid = pin_eld->eld_valid;
1477 /* for monitor disconnection, save pcm_idx firstly */
1478 pcm_idx = per_pin->pcm_idx;
1479 if (spec->dyn_pcm_assign) {
1480 if (eld->eld_valid) {
1481 hdmi_attach_hda_pcm(spec, per_pin);
1482 hdmi_pcm_setup_pin(spec, per_pin);
1484 hdmi_pcm_reset_pin(spec, per_pin);
1485 hdmi_detach_hda_pcm(spec, per_pin);
1488 /* if pcm_idx == -1, it means this is in monitor connection event
1489 * we can get the correct pcm_idx now.
1492 pcm_idx = per_pin->pcm_idx;
1495 snd_hdmi_show_eld(codec, &eld->info);
1497 eld_changed = (pin_eld->eld_valid != eld->eld_valid);
1498 eld_changed |= (pin_eld->monitor_present != eld->monitor_present);
1499 if (!eld_changed && eld->eld_valid && pin_eld->eld_valid)
1500 if (pin_eld->eld_size != eld->eld_size ||
1501 memcmp(pin_eld->eld_buffer, eld->eld_buffer,
1502 eld->eld_size) != 0)
1506 pin_eld->monitor_present = eld->monitor_present;
1507 pin_eld->eld_valid = eld->eld_valid;
1508 pin_eld->eld_size = eld->eld_size;
1510 memcpy(pin_eld->eld_buffer, eld->eld_buffer,
1512 pin_eld->info = eld->info;
1516 * Re-setup pin and infoframe. This is needed e.g. when
1517 * - sink is first plugged-in
1518 * - transcoder can change during stream playback on Haswell
1519 * and this can make HW reset converter selection on a pin.
1521 if (eld->eld_valid && !old_eld_valid && per_pin->setup) {
1522 pin_cvt_fixup(codec, per_pin, 0);
1523 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1526 if (eld_changed && pcm_idx >= 0)
1527 snd_ctl_notify(codec->card,
1528 SNDRV_CTL_EVENT_MASK_VALUE |
1529 SNDRV_CTL_EVENT_MASK_INFO,
1530 &get_hdmi_pcm(spec, pcm_idx)->eld_ctl->id);
1534 /* update ELD and jack state via HD-audio verbs */
1535 static bool hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin,
1538 struct hda_jack_tbl *jack;
1539 struct hda_codec *codec = per_pin->codec;
1540 struct hdmi_spec *spec = codec->spec;
1541 struct hdmi_eld *eld = &spec->temp_eld;
1542 hda_nid_t pin_nid = per_pin->pin_nid;
1543 int dev_id = per_pin->dev_id;
1545 * Always execute a GetPinSense verb here, even when called from
1546 * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
1547 * response's PD bit is not the real PD value, but indicates that
1548 * the real PD value changed. An older version of the HD-audio
1549 * specification worked this way. Hence, we just ignore the data in
1550 * the unsolicited response to avoid custom WARs.
1554 bool do_repoll = false;
1556 present = snd_hda_jack_pin_sense(codec, pin_nid, dev_id);
1558 mutex_lock(&per_pin->lock);
1559 eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
1560 if (eld->monitor_present)
1561 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
1563 eld->eld_valid = false;
1566 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
1567 codec->addr, pin_nid, eld->monitor_present, eld->eld_valid);
1569 if (eld->eld_valid) {
1570 if (spec->ops.pin_get_eld(codec, pin_nid, dev_id,
1571 eld->eld_buffer, &eld->eld_size) < 0)
1572 eld->eld_valid = false;
1574 if (snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer,
1576 eld->eld_valid = false;
1578 if (!eld->eld_valid && repoll)
1583 schedule_delayed_work(&per_pin->work, msecs_to_jiffies(300));
1585 update_eld(codec, per_pin, eld);
1587 ret = !repoll || !eld->monitor_present || eld->eld_valid;
1589 jack = snd_hda_jack_tbl_get_mst(codec, pin_nid, per_pin->dev_id);
1591 jack->block_report = !ret;
1592 jack->pin_sense = (eld->monitor_present && eld->eld_valid) ?
1593 AC_PINSENSE_PRESENCE : 0;
1595 mutex_unlock(&per_pin->lock);
1599 static struct snd_jack *pin_idx_to_jack(struct hda_codec *codec,
1600 struct hdmi_spec_per_pin *per_pin)
1602 struct hdmi_spec *spec = codec->spec;
1603 struct snd_jack *jack = NULL;
1604 struct hda_jack_tbl *jack_tbl;
1606 /* if !dyn_pcm_assign, get jack from hda_jack_tbl
1607 * in !dyn_pcm_assign case, spec->pcm_rec[].jack is not
1608 * NULL even after snd_hda_jack_tbl_clear() is called to
1609 * free snd_jack. This may cause access invalid memory
1610 * when calling snd_jack_report
1612 if (per_pin->pcm_idx >= 0 && spec->dyn_pcm_assign)
1613 jack = spec->pcm_rec[per_pin->pcm_idx].jack;
1614 else if (!spec->dyn_pcm_assign) {
1616 * jack tbl doesn't support DP MST
1617 * DP MST will use dyn_pcm_assign,
1618 * so DP MST will never come here
1620 jack_tbl = snd_hda_jack_tbl_get_mst(codec, per_pin->pin_nid,
1623 jack = jack_tbl->jack;
1628 /* update ELD and jack state via audio component */
1629 static void sync_eld_via_acomp(struct hda_codec *codec,
1630 struct hdmi_spec_per_pin *per_pin)
1632 struct hdmi_spec *spec = codec->spec;
1633 struct hdmi_eld *eld = &spec->temp_eld;
1634 struct snd_jack *jack = NULL;
1638 mutex_lock(&per_pin->lock);
1639 eld->monitor_present = false;
1640 size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid,
1641 per_pin->dev_id, &eld->monitor_present,
1642 eld->eld_buffer, ELD_MAX_SIZE);
1644 size = min(size, ELD_MAX_SIZE);
1645 if (snd_hdmi_parse_eld(codec, &eld->info,
1646 eld->eld_buffer, size) < 0)
1651 eld->eld_valid = true;
1652 eld->eld_size = size;
1654 eld->eld_valid = false;
1658 /* pcm_idx >=0 before update_eld() means it is in monitor
1659 * disconnected event. Jack must be fetched before update_eld()
1661 jack = pin_idx_to_jack(codec, per_pin);
1662 changed = update_eld(codec, per_pin, eld);
1664 jack = pin_idx_to_jack(codec, per_pin);
1665 if (changed && jack)
1666 snd_jack_report(jack,
1667 (eld->monitor_present && eld->eld_valid) ?
1668 SND_JACK_AVOUT : 0);
1669 mutex_unlock(&per_pin->lock);
1672 static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1674 struct hda_codec *codec = per_pin->codec;
1677 /* no temporary power up/down needed for component notifier */
1678 if (!codec_has_acomp(codec)) {
1679 ret = snd_hda_power_up_pm(codec);
1680 if (ret < 0 && pm_runtime_suspended(hda_codec_dev(codec))) {
1681 snd_hda_power_down_pm(codec);
1684 ret = hdmi_present_sense_via_verbs(per_pin, repoll);
1685 snd_hda_power_down_pm(codec);
1687 sync_eld_via_acomp(codec, per_pin);
1688 ret = false; /* don't call snd_hda_jack_report_sync() */
1694 static void hdmi_repoll_eld(struct work_struct *work)
1696 struct hdmi_spec_per_pin *per_pin =
1697 container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
1698 struct hda_codec *codec = per_pin->codec;
1699 struct hdmi_spec *spec = codec->spec;
1700 struct hda_jack_tbl *jack;
1702 jack = snd_hda_jack_tbl_get_mst(codec, per_pin->pin_nid,
1705 jack->jack_dirty = 1;
1707 if (per_pin->repoll_count++ > 6)
1708 per_pin->repoll_count = 0;
1710 mutex_lock(&spec->pcm_lock);
1711 if (hdmi_present_sense(per_pin, per_pin->repoll_count))
1712 snd_hda_jack_report_sync(per_pin->codec);
1713 mutex_unlock(&spec->pcm_lock);
1716 static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
1719 static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1721 struct hdmi_spec *spec = codec->spec;
1722 unsigned int caps, config;
1724 struct hdmi_spec_per_pin *per_pin;
1728 caps = snd_hda_query_pin_caps(codec, pin_nid);
1729 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
1733 * For DP MST audio, Configuration Default is the same for
1734 * all device entries on the same pin
1736 config = snd_hda_codec_get_pincfg(codec, pin_nid);
1737 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
1741 * To simplify the implementation, malloc all
1742 * the virtual pins in the initialization statically
1744 if (spec->intel_hsw_fixup) {
1746 * On Intel platforms, device entries number is
1747 * changed dynamically. If there is a DP MST
1748 * hub connected, the device entries number is 3.
1749 * Otherwise, it is 1.
1750 * Here we manually set dev_num to 3, so that
1751 * we can initialize all the device entries when
1752 * bootup statically.
1756 } else if (spec->dyn_pcm_assign && codec->dp_mst) {
1757 dev_num = snd_hda_get_num_devices(codec, pin_nid) + 1;
1759 * spec->dev_num is the maxinum number of device entries
1760 * among all the pins
1762 spec->dev_num = (spec->dev_num > dev_num) ?
1763 spec->dev_num : dev_num;
1766 * If the platform doesn't support DP MST,
1767 * manually set dev_num to 1. This means
1768 * the pin has only one device entry.
1774 for (i = 0; i < dev_num; i++) {
1775 pin_idx = spec->num_pins;
1776 per_pin = snd_array_new(&spec->pins);
1781 if (spec->dyn_pcm_assign) {
1782 per_pin->pcm = NULL;
1783 per_pin->pcm_idx = -1;
1785 per_pin->pcm = get_hdmi_pcm(spec, pin_idx);
1786 per_pin->pcm_idx = pin_idx;
1788 per_pin->pin_nid = pin_nid;
1789 per_pin->pin_nid_idx = spec->num_nids;
1790 per_pin->dev_id = i;
1791 per_pin->non_pcm = false;
1792 snd_hda_set_dev_select(codec, pin_nid, i);
1793 if (spec->intel_hsw_fixup)
1794 intel_haswell_fixup_connect_list(codec, pin_nid);
1795 err = hdmi_read_pin_conn(codec, pin_idx);
1805 static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1807 struct hdmi_spec *spec = codec->spec;
1808 struct hdmi_spec_per_cvt *per_cvt;
1812 chans = get_wcaps(codec, cvt_nid);
1813 chans = get_wcaps_channels(chans);
1815 per_cvt = snd_array_new(&spec->cvts);
1819 per_cvt->cvt_nid = cvt_nid;
1820 per_cvt->channels_min = 2;
1822 per_cvt->channels_max = chans;
1823 if (chans > spec->chmap.channels_max)
1824 spec->chmap.channels_max = chans;
1827 err = snd_hda_query_supported_pcm(codec, cvt_nid,
1834 if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids))
1835 spec->cvt_nids[spec->num_cvts] = cvt_nid;
1841 static int hdmi_parse_codec(struct hda_codec *codec)
1846 nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &nid);
1847 if (!nid || nodes < 0) {
1848 codec_warn(codec, "HDMI: failed to get afg sub nodes\n");
1852 for (i = 0; i < nodes; i++, nid++) {
1856 caps = get_wcaps(codec, nid);
1857 type = get_wcaps_type(caps);
1859 if (!(caps & AC_WCAP_DIGITAL))
1863 case AC_WID_AUD_OUT:
1864 hdmi_add_cvt(codec, nid);
1867 hdmi_add_pin(codec, nid);
1877 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1879 struct hda_spdif_out *spdif;
1882 mutex_lock(&codec->spdif_mutex);
1883 spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
1884 /* Add sanity check to pass klockwork check.
1885 * This should never happen.
1887 if (WARN_ON(spdif == NULL))
1889 non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO);
1890 mutex_unlock(&codec->spdif_mutex);
1898 static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1899 struct hda_codec *codec,
1900 unsigned int stream_tag,
1901 unsigned int format,
1902 struct snd_pcm_substream *substream)
1904 hda_nid_t cvt_nid = hinfo->nid;
1905 struct hdmi_spec *spec = codec->spec;
1907 struct hdmi_spec_per_pin *per_pin;
1908 struct snd_pcm_runtime *runtime = substream->runtime;
1913 mutex_lock(&spec->pcm_lock);
1914 pin_idx = hinfo_to_pin_index(codec, hinfo);
1915 if (spec->dyn_pcm_assign && pin_idx < 0) {
1916 /* when dyn_pcm_assign and pcm is not bound to a pin
1917 * skip pin setup and return 0 to make audio playback
1920 pin_cvt_fixup(codec, NULL, cvt_nid);
1921 snd_hda_codec_setup_stream(codec, cvt_nid,
1922 stream_tag, 0, format);
1926 if (snd_BUG_ON(pin_idx < 0)) {
1930 per_pin = get_pin(spec, pin_idx);
1932 /* Verify pin:cvt selections to avoid silent audio after S3.
1933 * After S3, the audio driver restores pin:cvt selections
1934 * but this can happen before gfx is ready and such selection
1935 * is overlooked by HW. Thus multiple pins can share a same
1936 * default convertor and mute control will affect each other,
1937 * which can cause a resumed audio playback become silent
1940 pin_cvt_fixup(codec, per_pin, 0);
1942 /* Call sync_audio_rate to set the N/CTS/M manually if necessary */
1943 /* Todo: add DP1.2 MST audio support later */
1944 if (codec_has_acomp(codec))
1945 snd_hdac_sync_audio_rate(&codec->core, per_pin->pin_nid,
1946 per_pin->dev_id, runtime->rate);
1948 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
1949 mutex_lock(&per_pin->lock);
1950 per_pin->channels = substream->runtime->channels;
1951 per_pin->setup = true;
1953 if (get_wcaps(codec, cvt_nid) & AC_WCAP_STRIPE) {
1954 stripe = snd_hdac_get_stream_stripe_ctl(&codec->bus->core,
1956 snd_hda_codec_write(codec, cvt_nid, 0,
1957 AC_VERB_SET_STRIPE_CONTROL,
1961 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
1962 mutex_unlock(&per_pin->lock);
1963 if (spec->dyn_pin_out) {
1964 snd_hda_set_dev_select(codec, per_pin->pin_nid,
1966 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
1967 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1968 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
1969 AC_VERB_SET_PIN_WIDGET_CONTROL,
1973 /* snd_hda_set_dev_select() has been called before */
1974 err = spec->ops.setup_stream(codec, cvt_nid, per_pin->pin_nid,
1975 per_pin->dev_id, stream_tag, format);
1977 mutex_unlock(&spec->pcm_lock);
1981 static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1982 struct hda_codec *codec,
1983 struct snd_pcm_substream *substream)
1985 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
1989 static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1990 struct hda_codec *codec,
1991 struct snd_pcm_substream *substream)
1993 struct hdmi_spec *spec = codec->spec;
1994 int cvt_idx, pin_idx, pcm_idx;
1995 struct hdmi_spec_per_cvt *per_cvt;
1996 struct hdmi_spec_per_pin *per_pin;
2001 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
2002 if (snd_BUG_ON(pcm_idx < 0))
2004 cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid);
2005 if (snd_BUG_ON(cvt_idx < 0))
2007 per_cvt = get_cvt(spec, cvt_idx);
2009 snd_BUG_ON(!per_cvt->assigned);
2010 per_cvt->assigned = 0;
2013 mutex_lock(&spec->pcm_lock);
2014 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
2015 clear_bit(pcm_idx, &spec->pcm_in_use);
2016 pin_idx = hinfo_to_pin_index(codec, hinfo);
2017 if (spec->dyn_pcm_assign && pin_idx < 0)
2020 if (snd_BUG_ON(pin_idx < 0)) {
2024 per_pin = get_pin(spec, pin_idx);
2026 if (spec->dyn_pin_out) {
2027 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2029 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
2030 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2031 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
2032 AC_VERB_SET_PIN_WIDGET_CONTROL,
2036 mutex_lock(&per_pin->lock);
2037 per_pin->chmap_set = false;
2038 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
2040 per_pin->setup = false;
2041 per_pin->channels = 0;
2042 mutex_unlock(&per_pin->lock);
2044 mutex_unlock(&spec->pcm_lock);
2050 static const struct hda_pcm_ops generic_ops = {
2051 .open = hdmi_pcm_open,
2052 .close = hdmi_pcm_close,
2053 .prepare = generic_hdmi_playback_pcm_prepare,
2054 .cleanup = generic_hdmi_playback_pcm_cleanup,
2057 static int hdmi_get_spk_alloc(struct hdac_device *hdac, int pcm_idx)
2059 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
2060 struct hdmi_spec *spec = codec->spec;
2061 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2066 return per_pin->sink_eld.info.spk_alloc;
2069 static void hdmi_get_chmap(struct hdac_device *hdac, int pcm_idx,
2070 unsigned char *chmap)
2072 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
2073 struct hdmi_spec *spec = codec->spec;
2074 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2076 /* chmap is already set to 0 in caller */
2080 memcpy(chmap, per_pin->chmap, ARRAY_SIZE(per_pin->chmap));
2083 static void hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx,
2084 unsigned char *chmap, int prepared)
2086 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
2087 struct hdmi_spec *spec = codec->spec;
2088 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2092 mutex_lock(&per_pin->lock);
2093 per_pin->chmap_set = true;
2094 memcpy(per_pin->chmap, chmap, ARRAY_SIZE(per_pin->chmap));
2096 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
2097 mutex_unlock(&per_pin->lock);
2100 static bool is_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx)
2102 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
2103 struct hdmi_spec *spec = codec->spec;
2104 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2106 return per_pin ? true:false;
2109 static int generic_hdmi_build_pcms(struct hda_codec *codec)
2111 struct hdmi_spec *spec = codec->spec;
2115 * for non-mst mode, pcm number is the same as before
2116 * for DP MST mode without extra PCM, pcm number is same
2117 * for DP MST mode with extra PCMs, pcm number is
2118 * (nid number + dev_num - 1)
2119 * dev_num is the device entry number in a pin
2122 if (codec->mst_no_extra_pcms)
2123 pcm_num = spec->num_nids;
2125 pcm_num = spec->num_nids + spec->dev_num - 1;
2127 codec_dbg(codec, "hdmi: pcm_num set to %d\n", pcm_num);
2129 for (idx = 0; idx < pcm_num; idx++) {
2130 struct hda_pcm *info;
2131 struct hda_pcm_stream *pstr;
2133 info = snd_hda_codec_pcm_new(codec, "HDMI %d", idx);
2137 spec->pcm_rec[idx].pcm = info;
2139 info->pcm_type = HDA_PCM_TYPE_HDMI;
2140 info->own_chmap = true;
2142 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
2143 pstr->substreams = 1;
2144 pstr->ops = generic_ops;
2145 /* pcm number is less than 16 */
2146 if (spec->pcm_used >= 16)
2148 /* other pstr fields are set in open */
2154 static void free_hdmi_jack_priv(struct snd_jack *jack)
2156 struct hdmi_pcm *pcm = jack->private_data;
2161 static int add_hdmi_jack_kctl(struct hda_codec *codec,
2162 struct hdmi_spec *spec,
2166 struct snd_jack *jack;
2169 err = snd_jack_new(codec->card, name, SND_JACK_AVOUT, &jack,
2174 spec->pcm_rec[pcm_idx].jack = jack;
2175 jack->private_data = &spec->pcm_rec[pcm_idx];
2176 jack->private_free = free_hdmi_jack_priv;
2180 static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx)
2182 char hdmi_str[32] = "HDMI/DP";
2183 struct hdmi_spec *spec = codec->spec;
2184 struct hdmi_spec_per_pin *per_pin;
2185 struct hda_jack_tbl *jack;
2186 int pcmdev = get_pcm_rec(spec, pcm_idx)->device;
2191 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
2193 if (spec->dyn_pcm_assign)
2194 return add_hdmi_jack_kctl(codec, spec, pcm_idx, hdmi_str);
2196 /* for !dyn_pcm_assign, we still use hda_jack for compatibility */
2197 /* if !dyn_pcm_assign, it must be non-MST mode.
2198 * This means pcms and pins are statically mapped.
2199 * And pcm_idx is pin_idx.
2201 per_pin = get_pin(spec, pcm_idx);
2202 phantom_jack = !is_jack_detectable(codec, per_pin->pin_nid);
2204 strncat(hdmi_str, " Phantom",
2205 sizeof(hdmi_str) - strlen(hdmi_str) - 1);
2206 ret = snd_hda_jack_add_kctl_mst(codec, per_pin->pin_nid,
2207 per_pin->dev_id, hdmi_str, phantom_jack,
2211 jack = snd_hda_jack_tbl_get_mst(codec, per_pin->pin_nid,
2215 /* assign jack->jack to pcm_rec[].jack to
2216 * align with dyn_pcm_assign mode
2218 spec->pcm_rec[pcm_idx].jack = jack->jack;
2222 static int generic_hdmi_build_controls(struct hda_codec *codec)
2224 struct hdmi_spec *spec = codec->spec;
2226 int pin_idx, pcm_idx;
2228 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2229 if (!get_pcm_rec(spec, pcm_idx)->pcm) {
2230 /* no PCM: mark this for skipping permanently */
2231 set_bit(pcm_idx, &spec->pcm_bitmap);
2235 err = generic_hdmi_build_jack(codec, pcm_idx);
2239 /* create the spdif for each pcm
2240 * pin will be bound when monitor is connected
2242 if (spec->dyn_pcm_assign)
2243 err = snd_hda_create_dig_out_ctls(codec,
2244 0, spec->cvt_nids[0],
2247 struct hdmi_spec_per_pin *per_pin =
2248 get_pin(spec, pcm_idx);
2249 err = snd_hda_create_dig_out_ctls(codec,
2251 per_pin->mux_nids[0],
2256 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
2258 dev = get_pcm_rec(spec, pcm_idx)->device;
2259 if (dev != SNDRV_PCM_INVALID_DEVICE) {
2260 /* add control for ELD Bytes */
2261 err = hdmi_create_eld_ctl(codec, pcm_idx, dev);
2267 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2268 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2270 hdmi_present_sense(per_pin, 0);
2273 /* add channel maps */
2274 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2275 struct hda_pcm *pcm;
2277 pcm = get_pcm_rec(spec, pcm_idx);
2278 if (!pcm || !pcm->pcm)
2280 err = snd_hdac_add_chmap_ctls(pcm->pcm, pcm_idx, &spec->chmap);
2288 static int generic_hdmi_init_per_pins(struct hda_codec *codec)
2290 struct hdmi_spec *spec = codec->spec;
2293 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2294 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2296 per_pin->codec = codec;
2297 mutex_init(&per_pin->lock);
2298 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
2299 eld_proc_new(per_pin, pin_idx);
2304 static int generic_hdmi_init(struct hda_codec *codec)
2306 struct hdmi_spec *spec = codec->spec;
2309 mutex_lock(&spec->bind_lock);
2310 spec->use_jack_detect = !codec->jackpoll_interval;
2311 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2312 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2313 hda_nid_t pin_nid = per_pin->pin_nid;
2314 int dev_id = per_pin->dev_id;
2316 snd_hda_set_dev_select(codec, pin_nid, dev_id);
2317 hdmi_init_pin(codec, pin_nid);
2318 if (codec_has_acomp(codec))
2320 if (spec->use_jack_detect)
2321 snd_hda_jack_detect_enable(codec, pin_nid, dev_id);
2323 snd_hda_jack_detect_enable_callback_mst(codec, pin_nid,
2327 mutex_unlock(&spec->bind_lock);
2331 static void hdmi_array_init(struct hdmi_spec *spec, int nums)
2333 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums);
2334 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums);
2337 static void hdmi_array_free(struct hdmi_spec *spec)
2339 snd_array_free(&spec->pins);
2340 snd_array_free(&spec->cvts);
2343 static void generic_spec_free(struct hda_codec *codec)
2345 struct hdmi_spec *spec = codec->spec;
2348 hdmi_array_free(spec);
2352 codec->dp_mst = false;
2355 static void generic_hdmi_free(struct hda_codec *codec)
2357 struct hdmi_spec *spec = codec->spec;
2358 int pin_idx, pcm_idx;
2360 if (spec->acomp_registered) {
2361 snd_hdac_acomp_exit(&codec->bus->core);
2362 } else if (codec_has_acomp(codec)) {
2363 snd_hdac_acomp_register_notifier(&codec->bus->core, NULL);
2364 codec->relaxed_resume = 0;
2367 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2368 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2369 cancel_delayed_work_sync(&per_pin->work);
2370 eld_proc_free(per_pin);
2373 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2374 if (spec->pcm_rec[pcm_idx].jack == NULL)
2376 if (spec->dyn_pcm_assign)
2377 snd_device_free(codec->card,
2378 spec->pcm_rec[pcm_idx].jack);
2380 spec->pcm_rec[pcm_idx].jack = NULL;
2383 generic_spec_free(codec);
2387 static int generic_hdmi_resume(struct hda_codec *codec)
2389 struct hdmi_spec *spec = codec->spec;
2392 codec->patch_ops.init(codec);
2393 regcache_sync(codec->core.regmap);
2395 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2396 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2397 hdmi_present_sense(per_pin, 1);
2403 static const struct hda_codec_ops generic_hdmi_patch_ops = {
2404 .init = generic_hdmi_init,
2405 .free = generic_hdmi_free,
2406 .build_pcms = generic_hdmi_build_pcms,
2407 .build_controls = generic_hdmi_build_controls,
2408 .unsol_event = hdmi_unsol_event,
2410 .resume = generic_hdmi_resume,
2414 static const struct hdmi_ops generic_standard_hdmi_ops = {
2415 .pin_get_eld = hdmi_pin_get_eld,
2416 .pin_setup_infoframe = hdmi_pin_setup_infoframe,
2417 .pin_hbr_setup = hdmi_pin_hbr_setup,
2418 .setup_stream = hdmi_setup_stream,
2421 /* allocate codec->spec and assign/initialize generic parser ops */
2422 static int alloc_generic_hdmi(struct hda_codec *codec)
2424 struct hdmi_spec *spec;
2426 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2430 spec->codec = codec;
2431 spec->ops = generic_standard_hdmi_ops;
2432 spec->dev_num = 1; /* initialize to 1 */
2433 mutex_init(&spec->pcm_lock);
2434 mutex_init(&spec->bind_lock);
2435 snd_hdac_register_chmap_ops(&codec->core, &spec->chmap);
2437 spec->chmap.ops.get_chmap = hdmi_get_chmap;
2438 spec->chmap.ops.set_chmap = hdmi_set_chmap;
2439 spec->chmap.ops.is_pcm_attached = is_hdmi_pcm_attached;
2440 spec->chmap.ops.get_spk_alloc = hdmi_get_spk_alloc,
2443 hdmi_array_init(spec, 4);
2445 codec->patch_ops = generic_hdmi_patch_ops;
2450 /* generic HDMI parser */
2451 static int patch_generic_hdmi(struct hda_codec *codec)
2455 err = alloc_generic_hdmi(codec);
2459 err = hdmi_parse_codec(codec);
2461 generic_spec_free(codec);
2465 generic_hdmi_init_per_pins(codec);
2470 * generic audio component binding
2473 /* turn on / off the unsol event jack detection dynamically */
2474 static void reprogram_jack_detect(struct hda_codec *codec, hda_nid_t nid,
2475 int dev_id, bool use_acomp)
2477 struct hda_jack_tbl *tbl;
2479 tbl = snd_hda_jack_tbl_get_mst(codec, nid, dev_id);
2481 /* clear unsol even if component notifier is used, or re-enable
2482 * if notifier is cleared
2484 unsigned int val = use_acomp ? 0 : (AC_USRSP_EN | tbl->tag);
2485 snd_hda_codec_write_cache(codec, nid, 0,
2486 AC_VERB_SET_UNSOLICITED_ENABLE, val);
2488 /* if no jack entry was defined beforehand, create a new one
2489 * at need (i.e. only when notifier is cleared)
2492 snd_hda_jack_detect_enable(codec, nid, dev_id);
2496 /* set up / clear component notifier dynamically */
2497 static void generic_acomp_notifier_set(struct drm_audio_component *acomp,
2500 struct hdmi_spec *spec;
2503 spec = container_of(acomp->audio_ops, struct hdmi_spec, drm_audio_ops);
2504 mutex_lock(&spec->bind_lock);
2505 spec->use_acomp_notifier = use_acomp;
2506 spec->codec->relaxed_resume = use_acomp;
2507 /* reprogram each jack detection logic depending on the notifier */
2508 if (spec->use_jack_detect) {
2509 for (i = 0; i < spec->num_pins; i++)
2510 reprogram_jack_detect(spec->codec,
2511 get_pin(spec, i)->pin_nid,
2512 get_pin(spec, i)->dev_id,
2515 mutex_unlock(&spec->bind_lock);
2518 /* enable / disable the notifier via master bind / unbind */
2519 static int generic_acomp_master_bind(struct device *dev,
2520 struct drm_audio_component *acomp)
2522 generic_acomp_notifier_set(acomp, true);
2526 static void generic_acomp_master_unbind(struct device *dev,
2527 struct drm_audio_component *acomp)
2529 generic_acomp_notifier_set(acomp, false);
2532 /* check whether both HD-audio and DRM PCI devices belong to the same bus */
2533 static int match_bound_vga(struct device *dev, int subtype, void *data)
2535 struct hdac_bus *bus = data;
2536 struct pci_dev *pci, *master;
2538 if (!dev_is_pci(dev) || !dev_is_pci(bus->dev))
2540 master = to_pci_dev(bus->dev);
2541 pci = to_pci_dev(dev);
2542 return master->bus == pci->bus;
2545 /* audio component notifier for AMD/Nvidia HDMI codecs */
2546 static void generic_acomp_pin_eld_notify(void *audio_ptr, int port, int dev_id)
2548 struct hda_codec *codec = audio_ptr;
2549 struct hdmi_spec *spec = codec->spec;
2550 hda_nid_t pin_nid = spec->port2pin(codec, port);
2554 if (get_wcaps_type(get_wcaps(codec, pin_nid)) != AC_WID_PIN)
2556 /* skip notification during system suspend (but not in runtime PM);
2557 * the state will be updated at resume
2559 if (snd_power_get_state(codec->card) != SNDRV_CTL_POWER_D0)
2561 /* ditto during suspend/resume process itself */
2562 if (snd_hdac_is_in_pm(&codec->core))
2565 check_presence_and_report(codec, pin_nid, dev_id);
2568 /* set up the private drm_audio_ops from the template */
2569 static void setup_drm_audio_ops(struct hda_codec *codec,
2570 const struct drm_audio_component_audio_ops *ops)
2572 struct hdmi_spec *spec = codec->spec;
2574 spec->drm_audio_ops.audio_ptr = codec;
2575 /* intel_audio_codec_enable() or intel_audio_codec_disable()
2576 * will call pin_eld_notify with using audio_ptr pointer
2577 * We need make sure audio_ptr is really setup
2580 spec->drm_audio_ops.pin2port = ops->pin2port;
2581 spec->drm_audio_ops.pin_eld_notify = ops->pin_eld_notify;
2582 spec->drm_audio_ops.master_bind = ops->master_bind;
2583 spec->drm_audio_ops.master_unbind = ops->master_unbind;
2586 /* initialize the generic HDMI audio component */
2587 static void generic_acomp_init(struct hda_codec *codec,
2588 const struct drm_audio_component_audio_ops *ops,
2589 int (*port2pin)(struct hda_codec *, int))
2591 struct hdmi_spec *spec = codec->spec;
2593 spec->port2pin = port2pin;
2594 setup_drm_audio_ops(codec, ops);
2595 if (!snd_hdac_acomp_init(&codec->bus->core, &spec->drm_audio_ops,
2596 match_bound_vga, 0)) {
2597 spec->acomp_registered = true;
2598 codec->bus->keep_power = 0;
2603 * Intel codec parsers and helpers
2606 static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
2609 struct hdmi_spec *spec = codec->spec;
2613 nconns = snd_hda_get_raw_connections(codec, nid, conns,
2615 if (nconns == spec->num_cvts &&
2616 !memcmp(conns, spec->cvt_nids, spec->num_cvts * sizeof(hda_nid_t)))
2619 /* override pins connection list */
2620 codec_dbg(codec, "hdmi: haswell: override pin connection 0x%x\n", nid);
2621 snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids);
2624 #define INTEL_GET_VENDOR_VERB 0xf81
2625 #define INTEL_SET_VENDOR_VERB 0x781
2626 #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
2627 #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
2629 static void intel_haswell_enable_all_pins(struct hda_codec *codec,
2632 unsigned int vendor_param;
2633 struct hdmi_spec *spec = codec->spec;
2635 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2636 INTEL_GET_VENDOR_VERB, 0);
2637 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
2640 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
2641 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2642 INTEL_SET_VENDOR_VERB, vendor_param);
2643 if (vendor_param == -1)
2647 snd_hda_codec_update_widgets(codec);
2650 static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
2652 unsigned int vendor_param;
2653 struct hdmi_spec *spec = codec->spec;
2655 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2656 INTEL_GET_VENDOR_VERB, 0);
2657 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
2660 /* enable DP1.2 mode */
2661 vendor_param |= INTEL_EN_DP12;
2662 snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB);
2663 snd_hda_codec_write_cache(codec, spec->vendor_nid, 0,
2664 INTEL_SET_VENDOR_VERB, vendor_param);
2667 /* Haswell needs to re-issue the vendor-specific verbs before turning to D0.
2668 * Otherwise you may get severe h/w communication errors.
2670 static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2671 unsigned int power_state)
2673 if (power_state == AC_PWRST_D0) {
2674 intel_haswell_enable_all_pins(codec, false);
2675 intel_haswell_fixup_enable_dp12(codec);
2678 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
2679 snd_hda_codec_set_power_to_all(codec, fg, power_state);
2682 /* There is a fixed mapping between audio pin node and display port.
2683 * on SNB, IVY, HSW, BSW, SKL, BXT, KBL:
2684 * Pin Widget 5 - PORT B (port = 1 in i915 driver)
2685 * Pin Widget 6 - PORT C (port = 2 in i915 driver)
2686 * Pin Widget 7 - PORT D (port = 3 in i915 driver)
2689 * Pin Widget 4 - PORT B (port = 1 in i915 driver)
2690 * Pin Widget 5 - PORT C (port = 2 in i915 driver)
2691 * Pin Widget 6 - PORT D (port = 3 in i915 driver)
2693 static int intel_base_nid(struct hda_codec *codec)
2695 switch (codec->core.vendor_id) {
2696 case 0x80860054: /* ILK */
2697 case 0x80862804: /* ILK */
2698 case 0x80862882: /* VLV */
2705 static int intel_pin2port(void *audio_ptr, int pin_nid)
2707 struct hda_codec *codec = audio_ptr;
2708 struct hdmi_spec *spec = codec->spec;
2711 if (!spec->port_num) {
2712 base_nid = intel_base_nid(codec);
2713 if (WARN_ON(pin_nid < base_nid || pin_nid >= base_nid + 3))
2715 return pin_nid - base_nid + 1;
2719 * looking for the pin number in the mapping table and return
2720 * the index which indicate the port number
2722 for (i = 0; i < spec->port_num; i++) {
2723 if (pin_nid == spec->port_map[i])
2727 codec_info(codec, "Can't find the HDMI/DP port for pin %d\n", pin_nid);
2731 static int intel_port2pin(struct hda_codec *codec, int port)
2733 struct hdmi_spec *spec = codec->spec;
2735 if (!spec->port_num) {
2736 /* we assume only from port-B to port-D */
2737 if (port < 1 || port > 3)
2739 return port + intel_base_nid(codec) - 1;
2742 if (port < 0 || port >= spec->port_num)
2744 return spec->port_map[port];
2747 static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe)
2749 struct hda_codec *codec = audio_ptr;
2753 pin_nid = intel_port2pin(codec, port);
2756 /* skip notification during system suspend (but not in runtime PM);
2757 * the state will be updated at resume
2759 if (snd_power_get_state(codec->card) != SNDRV_CTL_POWER_D0)
2761 /* ditto during suspend/resume process itself */
2762 if (snd_hdac_is_in_pm(&codec->core))
2765 snd_hdac_i915_set_bclk(&codec->bus->core);
2766 check_presence_and_report(codec, pin_nid, dev_id);
2769 static const struct drm_audio_component_audio_ops intel_audio_ops = {
2770 .pin2port = intel_pin2port,
2771 .pin_eld_notify = intel_pin_eld_notify,
2774 /* register i915 component pin_eld_notify callback */
2775 static void register_i915_notifier(struct hda_codec *codec)
2777 struct hdmi_spec *spec = codec->spec;
2779 spec->use_acomp_notifier = true;
2780 spec->port2pin = intel_port2pin;
2781 setup_drm_audio_ops(codec, &intel_audio_ops);
2782 snd_hdac_acomp_register_notifier(&codec->bus->core,
2783 &spec->drm_audio_ops);
2784 /* no need for forcible resume for jack check thanks to notifier */
2785 codec->relaxed_resume = 1;
2788 /* setup_stream ops override for HSW+ */
2789 static int i915_hsw_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
2790 hda_nid_t pin_nid, int dev_id, u32 stream_tag,
2793 haswell_verify_D0(codec, cvt_nid, pin_nid);
2794 return hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id,
2795 stream_tag, format);
2798 /* pin_cvt_fixup ops override for HSW+ and VLV+ */
2799 static void i915_pin_cvt_fixup(struct hda_codec *codec,
2800 struct hdmi_spec_per_pin *per_pin,
2804 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2806 intel_verify_pin_cvt_connect(codec, per_pin);
2807 intel_not_share_assigned_cvt(codec, per_pin->pin_nid,
2808 per_pin->dev_id, per_pin->mux_idx);
2810 intel_not_share_assigned_cvt_nid(codec, 0, 0, cvt_nid);
2814 /* precondition and allocation for Intel codecs */
2815 static int alloc_intel_hdmi(struct hda_codec *codec)
2819 /* requires i915 binding */
2820 if (!codec->bus->core.audio_component) {
2821 codec_info(codec, "No i915 binding for Intel HDMI/DP codec\n");
2822 /* set probe_id here to prevent generic fallback binding */
2823 codec->probe_id = HDA_CODEC_ID_SKIP_PROBE;
2827 err = alloc_generic_hdmi(codec);
2830 /* no need to handle unsol events */
2831 codec->patch_ops.unsol_event = NULL;
2835 /* parse and post-process for Intel codecs */
2836 static int parse_intel_hdmi(struct hda_codec *codec)
2840 err = hdmi_parse_codec(codec);
2842 generic_spec_free(codec);
2846 generic_hdmi_init_per_pins(codec);
2847 register_i915_notifier(codec);
2851 /* Intel Haswell and onwards; audio component with eld notifier */
2852 static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid,
2853 const int *port_map, int port_num)
2855 struct hdmi_spec *spec;
2858 err = alloc_intel_hdmi(codec);
2862 codec->dp_mst = true;
2863 spec->dyn_pcm_assign = true;
2864 spec->vendor_nid = vendor_nid;
2865 spec->port_map = port_map;
2866 spec->port_num = port_num;
2867 spec->intel_hsw_fixup = true;
2869 intel_haswell_enable_all_pins(codec, true);
2870 intel_haswell_fixup_enable_dp12(codec);
2872 codec->display_power_control = 1;
2874 codec->patch_ops.set_power_state = haswell_set_power_state;
2875 codec->depop_delay = 0;
2876 codec->auto_runtime_pm = 1;
2878 spec->ops.setup_stream = i915_hsw_setup_stream;
2879 spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup;
2881 return parse_intel_hdmi(codec);
2884 static int patch_i915_hsw_hdmi(struct hda_codec *codec)
2886 return intel_hsw_common_init(codec, 0x08, NULL, 0);
2889 static int patch_i915_glk_hdmi(struct hda_codec *codec)
2891 return intel_hsw_common_init(codec, 0x0b, NULL, 0);
2894 static int patch_i915_icl_hdmi(struct hda_codec *codec)
2897 * pin to port mapping table where the value indicate the pin number and
2898 * the index indicate the port number.
2900 static const int map[] = {0x0, 0x4, 0x6, 0x8, 0xa, 0xb};
2902 return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map));
2905 static int patch_i915_tgl_hdmi(struct hda_codec *codec)
2908 * pin to port mapping table where the value indicate the pin number and
2909 * the index indicate the port number.
2911 static const int map[] = {0x4, 0x6, 0x8, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
2913 return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map));
2916 /* Intel Baytrail and Braswell; with eld notifier */
2917 static int patch_i915_byt_hdmi(struct hda_codec *codec)
2919 struct hdmi_spec *spec;
2922 err = alloc_intel_hdmi(codec);
2927 /* For Valleyview/Cherryview, only the display codec is in the display
2928 * power well and can use link_power ops to request/release the power.
2930 codec->display_power_control = 1;
2932 codec->depop_delay = 0;
2933 codec->auto_runtime_pm = 1;
2935 spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup;
2937 return parse_intel_hdmi(codec);
2940 /* Intel IronLake, SandyBridge and IvyBridge; with eld notifier */
2941 static int patch_i915_cpt_hdmi(struct hda_codec *codec)
2945 err = alloc_intel_hdmi(codec);
2948 return parse_intel_hdmi(codec);
2952 * Shared non-generic implementations
2955 static int simple_playback_build_pcms(struct hda_codec *codec)
2957 struct hdmi_spec *spec = codec->spec;
2958 struct hda_pcm *info;
2960 struct hda_pcm_stream *pstr;
2961 struct hdmi_spec_per_cvt *per_cvt;
2963 per_cvt = get_cvt(spec, 0);
2964 chans = get_wcaps(codec, per_cvt->cvt_nid);
2965 chans = get_wcaps_channels(chans);
2967 info = snd_hda_codec_pcm_new(codec, "HDMI 0");
2970 spec->pcm_rec[0].pcm = info;
2971 info->pcm_type = HDA_PCM_TYPE_HDMI;
2972 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
2973 *pstr = spec->pcm_playback;
2974 pstr->nid = per_cvt->cvt_nid;
2975 if (pstr->channels_max <= 2 && chans && chans <= 16)
2976 pstr->channels_max = chans;
2981 /* unsolicited event for jack sensing */
2982 static void simple_hdmi_unsol_event(struct hda_codec *codec,
2985 snd_hda_jack_set_dirty_all(codec);
2986 snd_hda_jack_report_sync(codec);
2989 /* generic_hdmi_build_jack can be used for simple_hdmi, too,
2990 * as long as spec->pins[] is set correctly
2992 #define simple_hdmi_build_jack generic_hdmi_build_jack
2994 static int simple_playback_build_controls(struct hda_codec *codec)
2996 struct hdmi_spec *spec = codec->spec;
2997 struct hdmi_spec_per_cvt *per_cvt;
3000 per_cvt = get_cvt(spec, 0);
3001 err = snd_hda_create_dig_out_ctls(codec, per_cvt->cvt_nid,
3006 return simple_hdmi_build_jack(codec, 0);
3009 static int simple_playback_init(struct hda_codec *codec)
3011 struct hdmi_spec *spec = codec->spec;
3012 struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0);
3013 hda_nid_t pin = per_pin->pin_nid;
3015 snd_hda_codec_write(codec, pin, 0,
3016 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3017 /* some codecs require to unmute the pin */
3018 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
3019 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3021 snd_hda_jack_detect_enable(codec, pin, per_pin->dev_id);
3025 static void simple_playback_free(struct hda_codec *codec)
3027 struct hdmi_spec *spec = codec->spec;
3029 hdmi_array_free(spec);
3034 * Nvidia specific implementations
3037 #define Nv_VERB_SET_Channel_Allocation 0xF79
3038 #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
3039 #define Nv_VERB_SET_Audio_Protection_On 0xF98
3040 #define Nv_VERB_SET_Audio_Protection_Off 0xF99
3042 #define nvhdmi_master_con_nid_7x 0x04
3043 #define nvhdmi_master_pin_nid_7x 0x05
3045 static const hda_nid_t nvhdmi_con_nids_7x[4] = {
3046 /*front, rear, clfe, rear_surr */
3050 static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = {
3051 /* set audio protect on */
3052 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
3053 /* enable digital output on pin widget */
3054 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3058 static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = {
3059 /* set audio protect on */
3060 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
3061 /* enable digital output on pin widget */
3062 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3063 { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3064 { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3065 { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3066 { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3070 #ifdef LIMITED_RATE_FMT_SUPPORT
3071 /* support only the safe format and rate */
3072 #define SUPPORTED_RATES SNDRV_PCM_RATE_48000
3073 #define SUPPORTED_MAXBPS 16
3074 #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
3076 /* support all rates and formats */
3077 #define SUPPORTED_RATES \
3078 (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
3079 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
3080 SNDRV_PCM_RATE_192000)
3081 #define SUPPORTED_MAXBPS 24
3082 #define SUPPORTED_FORMATS \
3083 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
3086 static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
3088 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
3092 static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
3094 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
3098 static const unsigned int channels_2_6_8[] = {
3102 static const unsigned int channels_2_8[] = {
3106 static const struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
3107 .count = ARRAY_SIZE(channels_2_6_8),
3108 .list = channels_2_6_8,
3112 static const struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
3113 .count = ARRAY_SIZE(channels_2_8),
3114 .list = channels_2_8,
3118 static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
3119 struct hda_codec *codec,
3120 struct snd_pcm_substream *substream)
3122 struct hdmi_spec *spec = codec->spec;
3123 const struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
3125 switch (codec->preset->vendor_id) {
3130 hw_constraints_channels = &hw_constraints_2_8_channels;
3133 hw_constraints_channels = &hw_constraints_2_6_8_channels;
3139 if (hw_constraints_channels != NULL) {
3140 snd_pcm_hw_constraint_list(substream->runtime, 0,
3141 SNDRV_PCM_HW_PARAM_CHANNELS,
3142 hw_constraints_channels);
3144 snd_pcm_hw_constraint_step(substream->runtime, 0,
3145 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
3148 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3151 static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
3152 struct hda_codec *codec,
3153 struct snd_pcm_substream *substream)
3155 struct hdmi_spec *spec = codec->spec;
3156 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3159 static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3160 struct hda_codec *codec,
3161 unsigned int stream_tag,
3162 unsigned int format,
3163 struct snd_pcm_substream *substream)
3165 struct hdmi_spec *spec = codec->spec;
3166 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3167 stream_tag, format, substream);
3170 static const struct hda_pcm_stream simple_pcm_playback = {
3175 .open = simple_playback_pcm_open,
3176 .close = simple_playback_pcm_close,
3177 .prepare = simple_playback_pcm_prepare
3181 static const struct hda_codec_ops simple_hdmi_patch_ops = {
3182 .build_controls = simple_playback_build_controls,
3183 .build_pcms = simple_playback_build_pcms,
3184 .init = simple_playback_init,
3185 .free = simple_playback_free,
3186 .unsol_event = simple_hdmi_unsol_event,
3189 static int patch_simple_hdmi(struct hda_codec *codec,
3190 hda_nid_t cvt_nid, hda_nid_t pin_nid)
3192 struct hdmi_spec *spec;
3193 struct hdmi_spec_per_cvt *per_cvt;
3194 struct hdmi_spec_per_pin *per_pin;
3196 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3200 spec->codec = codec;
3202 hdmi_array_init(spec, 1);
3204 spec->multiout.num_dacs = 0; /* no analog */
3205 spec->multiout.max_channels = 2;
3206 spec->multiout.dig_out_nid = cvt_nid;
3209 per_pin = snd_array_new(&spec->pins);
3210 per_cvt = snd_array_new(&spec->cvts);
3211 if (!per_pin || !per_cvt) {
3212 simple_playback_free(codec);
3215 per_cvt->cvt_nid = cvt_nid;
3216 per_pin->pin_nid = pin_nid;
3217 spec->pcm_playback = simple_pcm_playback;
3219 codec->patch_ops = simple_hdmi_patch_ops;
3224 static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
3227 unsigned int chanmask;
3228 int chan = channels ? (channels - 1) : 1;
3247 /* Set the audio infoframe channel allocation and checksum fields. The
3248 * channel count is computed implicitly by the hardware. */
3249 snd_hda_codec_write(codec, 0x1, 0,
3250 Nv_VERB_SET_Channel_Allocation, chanmask);
3252 snd_hda_codec_write(codec, 0x1, 0,
3253 Nv_VERB_SET_Info_Frame_Checksum,
3254 (0x71 - chan - chanmask));
3257 static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
3258 struct hda_codec *codec,
3259 struct snd_pcm_substream *substream)
3261 struct hdmi_spec *spec = codec->spec;
3264 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
3265 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
3266 for (i = 0; i < 4; i++) {
3267 /* set the stream id */
3268 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
3269 AC_VERB_SET_CHANNEL_STREAMID, 0);
3270 /* set the stream format */
3271 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
3272 AC_VERB_SET_STREAM_FORMAT, 0);
3275 /* The audio hardware sends a channel count of 0x7 (8ch) when all the
3276 * streams are disabled. */
3277 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
3279 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3282 static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
3283 struct hda_codec *codec,
3284 unsigned int stream_tag,
3285 unsigned int format,
3286 struct snd_pcm_substream *substream)
3289 unsigned int dataDCC2, channel_id;
3291 struct hdmi_spec *spec = codec->spec;
3292 struct hda_spdif_out *spdif;
3293 struct hdmi_spec_per_cvt *per_cvt;
3295 mutex_lock(&codec->spdif_mutex);
3296 per_cvt = get_cvt(spec, 0);
3297 spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid);
3299 chs = substream->runtime->channels;
3303 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
3304 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
3305 snd_hda_codec_write(codec,
3306 nvhdmi_master_con_nid_7x,
3308 AC_VERB_SET_DIGI_CONVERT_1,
3309 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
3311 /* set the stream id */
3312 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
3313 AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
3315 /* set the stream format */
3316 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
3317 AC_VERB_SET_STREAM_FORMAT, format);
3319 /* turn on again (if needed) */
3320 /* enable and set the channel status audio/data flag */
3321 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
3322 snd_hda_codec_write(codec,
3323 nvhdmi_master_con_nid_7x,
3325 AC_VERB_SET_DIGI_CONVERT_1,
3326 spdif->ctls & 0xff);
3327 snd_hda_codec_write(codec,
3328 nvhdmi_master_con_nid_7x,
3330 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
3333 for (i = 0; i < 4; i++) {
3339 /* turn off SPDIF once;
3340 *otherwise the IEC958 bits won't be updated
3342 if (codec->spdif_status_reset &&
3343 (spdif->ctls & AC_DIG1_ENABLE))
3344 snd_hda_codec_write(codec,
3345 nvhdmi_con_nids_7x[i],
3347 AC_VERB_SET_DIGI_CONVERT_1,
3348 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
3349 /* set the stream id */
3350 snd_hda_codec_write(codec,
3351 nvhdmi_con_nids_7x[i],
3353 AC_VERB_SET_CHANNEL_STREAMID,
3354 (stream_tag << 4) | channel_id);
3355 /* set the stream format */
3356 snd_hda_codec_write(codec,
3357 nvhdmi_con_nids_7x[i],
3359 AC_VERB_SET_STREAM_FORMAT,
3361 /* turn on again (if needed) */
3362 /* enable and set the channel status audio/data flag */
3363 if (codec->spdif_status_reset &&
3364 (spdif->ctls & AC_DIG1_ENABLE)) {
3365 snd_hda_codec_write(codec,
3366 nvhdmi_con_nids_7x[i],
3368 AC_VERB_SET_DIGI_CONVERT_1,
3369 spdif->ctls & 0xff);
3370 snd_hda_codec_write(codec,
3371 nvhdmi_con_nids_7x[i],
3373 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
3377 nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
3379 mutex_unlock(&codec->spdif_mutex);
3383 static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
3387 .nid = nvhdmi_master_con_nid_7x,
3388 .rates = SUPPORTED_RATES,
3389 .maxbps = SUPPORTED_MAXBPS,
3390 .formats = SUPPORTED_FORMATS,
3392 .open = simple_playback_pcm_open,
3393 .close = nvhdmi_8ch_7x_pcm_close,
3394 .prepare = nvhdmi_8ch_7x_pcm_prepare
3398 static int patch_nvhdmi_2ch(struct hda_codec *codec)
3400 struct hdmi_spec *spec;
3401 int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
3402 nvhdmi_master_pin_nid_7x);
3406 codec->patch_ops.init = nvhdmi_7x_init_2ch;
3407 /* override the PCM rates, etc, as the codec doesn't give full list */
3409 spec->pcm_playback.rates = SUPPORTED_RATES;
3410 spec->pcm_playback.maxbps = SUPPORTED_MAXBPS;
3411 spec->pcm_playback.formats = SUPPORTED_FORMATS;
3415 static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
3417 struct hdmi_spec *spec = codec->spec;
3418 int err = simple_playback_build_pcms(codec);
3420 struct hda_pcm *info = get_pcm_rec(spec, 0);
3421 info->own_chmap = true;
3426 static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
3428 struct hdmi_spec *spec = codec->spec;
3429 struct hda_pcm *info;
3430 struct snd_pcm_chmap *chmap;
3433 err = simple_playback_build_controls(codec);
3437 /* add channel maps */
3438 info = get_pcm_rec(spec, 0);
3439 err = snd_pcm_add_chmap_ctls(info->pcm,
3440 SNDRV_PCM_STREAM_PLAYBACK,
3441 snd_pcm_alt_chmaps, 8, 0, &chmap);
3444 switch (codec->preset->vendor_id) {
3449 chmap->channel_mask = (1U << 2) | (1U << 8);
3452 chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8);
3457 static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
3459 struct hdmi_spec *spec;
3460 int err = patch_nvhdmi_2ch(codec);
3464 spec->multiout.max_channels = 8;
3465 spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x;
3466 codec->patch_ops.init = nvhdmi_7x_init_8ch;
3467 codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
3468 codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
3470 /* Initialize the audio infoframe channel mask and checksum to something
3472 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
3478 * NVIDIA codecs ignore ASP mapping for 2ch - confirmed on:
3482 static int nvhdmi_chmap_cea_alloc_validate_get_type(struct hdac_chmap *chmap,
3483 struct hdac_cea_channel_speaker_allocation *cap, int channels)
3485 if (cap->ca_index == 0x00 && channels == 2)
3486 return SNDRV_CTL_TLVT_CHMAP_FIXED;
3488 /* If the speaker allocation matches the channel count, it is OK. */
3489 if (cap->channels != channels)
3492 /* all channels are remappable freely */
3493 return SNDRV_CTL_TLVT_CHMAP_VAR;
3496 static int nvhdmi_chmap_validate(struct hdac_chmap *chmap,
3497 int ca, int chs, unsigned char *map)
3499 if (ca == 0x00 && (map[0] != SNDRV_CHMAP_FL || map[1] != SNDRV_CHMAP_FR))
3505 /* map from pin NID to port; port is 0-based */
3506 /* for Nvidia: assume widget NID starting from 4, with step 1 (4, 5, 6, ...) */
3507 static int nvhdmi_pin2port(void *audio_ptr, int pin_nid)
3512 /* reverse-map from port to pin NID: see above */
3513 static int nvhdmi_port2pin(struct hda_codec *codec, int port)
3518 static const struct drm_audio_component_audio_ops nvhdmi_audio_ops = {
3519 .pin2port = nvhdmi_pin2port,
3520 .pin_eld_notify = generic_acomp_pin_eld_notify,
3521 .master_bind = generic_acomp_master_bind,
3522 .master_unbind = generic_acomp_master_unbind,
3525 static int patch_nvhdmi(struct hda_codec *codec)
3527 struct hdmi_spec *spec;
3530 err = alloc_generic_hdmi(codec);
3533 codec->dp_mst = true;
3536 spec->dyn_pcm_assign = true;
3538 err = hdmi_parse_codec(codec);
3540 generic_spec_free(codec);
3544 generic_hdmi_init_per_pins(codec);
3546 spec->dyn_pin_out = true;
3548 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
3549 nvhdmi_chmap_cea_alloc_validate_get_type;
3550 spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate;
3552 codec->link_down_at_suspend = 1;
3554 generic_acomp_init(codec, &nvhdmi_audio_ops, nvhdmi_port2pin);
3559 static int patch_nvhdmi_legacy(struct hda_codec *codec)
3561 struct hdmi_spec *spec;
3564 err = patch_generic_hdmi(codec);
3569 spec->dyn_pin_out = true;
3571 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
3572 nvhdmi_chmap_cea_alloc_validate_get_type;
3573 spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate;
3575 codec->link_down_at_suspend = 1;
3577 generic_acomp_init(codec, &nvhdmi_audio_ops, nvhdmi_port2pin);
3583 * The HDA codec on NVIDIA Tegra contains two scratch registers that are
3584 * accessed using vendor-defined verbs. These registers can be used for
3585 * interoperability between the HDA and HDMI drivers.
3588 /* Audio Function Group node */
3589 #define NVIDIA_AFG_NID 0x01
3592 * The SCRATCH0 register is used to notify the HDMI codec of changes in audio
3593 * format. On Tegra, bit 31 is used as a trigger that causes an interrupt to
3594 * be raised in the HDMI codec. The remainder of the bits is arbitrary. This
3595 * implementation stores the HDA format (see AC_FMT_*) in bits [15:0] and an
3596 * additional bit (at position 30) to signal the validity of the format.
3598 * | 31 | 30 | 29 16 | 15 0 |
3599 * +---------+-------+--------+--------+
3600 * | TRIGGER | VALID | UNUSED | FORMAT |
3601 * +-----------------------------------|
3603 * Note that for the trigger bit to take effect it needs to change value
3604 * (i.e. it needs to be toggled).
3606 #define NVIDIA_GET_SCRATCH0 0xfa6
3607 #define NVIDIA_SET_SCRATCH0_BYTE0 0xfa7
3608 #define NVIDIA_SET_SCRATCH0_BYTE1 0xfa8
3609 #define NVIDIA_SET_SCRATCH0_BYTE2 0xfa9
3610 #define NVIDIA_SET_SCRATCH0_BYTE3 0xfaa
3611 #define NVIDIA_SCRATCH_TRIGGER (1 << 7)
3612 #define NVIDIA_SCRATCH_VALID (1 << 6)
3614 #define NVIDIA_GET_SCRATCH1 0xfab
3615 #define NVIDIA_SET_SCRATCH1_BYTE0 0xfac
3616 #define NVIDIA_SET_SCRATCH1_BYTE1 0xfad
3617 #define NVIDIA_SET_SCRATCH1_BYTE2 0xfae
3618 #define NVIDIA_SET_SCRATCH1_BYTE3 0xfaf
3621 * The format parameter is the HDA audio format (see AC_FMT_*). If set to 0,
3622 * the format is invalidated so that the HDMI codec can be disabled.
3624 static void tegra_hdmi_set_format(struct hda_codec *codec, unsigned int format)
3628 /* bits [31:30] contain the trigger and valid bits */
3629 value = snd_hda_codec_read(codec, NVIDIA_AFG_NID, 0,
3630 NVIDIA_GET_SCRATCH0, 0);
3631 value = (value >> 24) & 0xff;
3633 /* bits [15:0] are used to store the HDA format */
3634 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3635 NVIDIA_SET_SCRATCH0_BYTE0,
3636 (format >> 0) & 0xff);
3637 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3638 NVIDIA_SET_SCRATCH0_BYTE1,
3639 (format >> 8) & 0xff);
3641 /* bits [16:24] are unused */
3642 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3643 NVIDIA_SET_SCRATCH0_BYTE2, 0);
3646 * Bit 30 signals that the data is valid and hence that HDMI audio can
3650 value &= ~NVIDIA_SCRATCH_VALID;
3652 value |= NVIDIA_SCRATCH_VALID;
3655 * Whenever the trigger bit is toggled, an interrupt is raised in the
3656 * HDMI codec. The HDMI driver will use that as trigger to update its
3659 value ^= NVIDIA_SCRATCH_TRIGGER;
3661 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3662 NVIDIA_SET_SCRATCH0_BYTE3, value);
3665 static int tegra_hdmi_pcm_prepare(struct hda_pcm_stream *hinfo,
3666 struct hda_codec *codec,
3667 unsigned int stream_tag,
3668 unsigned int format,
3669 struct snd_pcm_substream *substream)
3673 err = generic_hdmi_playback_pcm_prepare(hinfo, codec, stream_tag,
3678 /* notify the HDMI codec of the format change */
3679 tegra_hdmi_set_format(codec, format);
3684 static int tegra_hdmi_pcm_cleanup(struct hda_pcm_stream *hinfo,
3685 struct hda_codec *codec,
3686 struct snd_pcm_substream *substream)
3688 /* invalidate the format in the HDMI codec */
3689 tegra_hdmi_set_format(codec, 0);
3691 return generic_hdmi_playback_pcm_cleanup(hinfo, codec, substream);
3694 static struct hda_pcm *hda_find_pcm_by_type(struct hda_codec *codec, int type)
3696 struct hdmi_spec *spec = codec->spec;
3699 for (i = 0; i < spec->num_pins; i++) {
3700 struct hda_pcm *pcm = get_pcm_rec(spec, i);
3702 if (pcm->pcm_type == type)
3709 static int tegra_hdmi_build_pcms(struct hda_codec *codec)
3711 struct hda_pcm_stream *stream;
3712 struct hda_pcm *pcm;
3715 err = generic_hdmi_build_pcms(codec);
3719 pcm = hda_find_pcm_by_type(codec, HDA_PCM_TYPE_HDMI);
3724 * Override ->prepare() and ->cleanup() operations to notify the HDMI
3725 * codec about format changes.
3727 stream = &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
3728 stream->ops.prepare = tegra_hdmi_pcm_prepare;
3729 stream->ops.cleanup = tegra_hdmi_pcm_cleanup;
3734 static int patch_tegra_hdmi(struct hda_codec *codec)
3738 err = patch_generic_hdmi(codec);
3742 codec->patch_ops.build_pcms = tegra_hdmi_build_pcms;
3748 * ATI/AMD-specific implementations
3751 #define is_amdhdmi_rev3_or_later(codec) \
3752 ((codec)->core.vendor_id == 0x1002aa01 && \
3753 ((codec)->core.revision_id & 0xff00) >= 0x0300)
3754 #define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec)
3756 /* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */
3757 #define ATI_VERB_SET_CHANNEL_ALLOCATION 0x771
3758 #define ATI_VERB_SET_DOWNMIX_INFO 0x772
3759 #define ATI_VERB_SET_MULTICHANNEL_01 0x777
3760 #define ATI_VERB_SET_MULTICHANNEL_23 0x778
3761 #define ATI_VERB_SET_MULTICHANNEL_45 0x779
3762 #define ATI_VERB_SET_MULTICHANNEL_67 0x77a
3763 #define ATI_VERB_SET_HBR_CONTROL 0x77c
3764 #define ATI_VERB_SET_MULTICHANNEL_1 0x785
3765 #define ATI_VERB_SET_MULTICHANNEL_3 0x786
3766 #define ATI_VERB_SET_MULTICHANNEL_5 0x787
3767 #define ATI_VERB_SET_MULTICHANNEL_7 0x788
3768 #define ATI_VERB_SET_MULTICHANNEL_MODE 0x789
3769 #define ATI_VERB_GET_CHANNEL_ALLOCATION 0xf71
3770 #define ATI_VERB_GET_DOWNMIX_INFO 0xf72
3771 #define ATI_VERB_GET_MULTICHANNEL_01 0xf77
3772 #define ATI_VERB_GET_MULTICHANNEL_23 0xf78
3773 #define ATI_VERB_GET_MULTICHANNEL_45 0xf79
3774 #define ATI_VERB_GET_MULTICHANNEL_67 0xf7a
3775 #define ATI_VERB_GET_HBR_CONTROL 0xf7c
3776 #define ATI_VERB_GET_MULTICHANNEL_1 0xf85
3777 #define ATI_VERB_GET_MULTICHANNEL_3 0xf86
3778 #define ATI_VERB_GET_MULTICHANNEL_5 0xf87
3779 #define ATI_VERB_GET_MULTICHANNEL_7 0xf88
3780 #define ATI_VERB_GET_MULTICHANNEL_MODE 0xf89
3782 /* AMD specific HDA cvt verbs */
3783 #define ATI_VERB_SET_RAMP_RATE 0x770
3784 #define ATI_VERB_GET_RAMP_RATE 0xf70
3786 #define ATI_OUT_ENABLE 0x1
3788 #define ATI_MULTICHANNEL_MODE_PAIRED 0
3789 #define ATI_MULTICHANNEL_MODE_SINGLE 1
3791 #define ATI_HBR_CAPABLE 0x01
3792 #define ATI_HBR_ENABLE 0x10
3794 static int atihdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
3795 int dev_id, unsigned char *buf, int *eld_size)
3797 WARN_ON(dev_id != 0);
3798 /* call hda_eld.c ATI/AMD-specific function */
3799 return snd_hdmi_get_eld_ati(codec, nid, buf, eld_size,
3800 is_amdhdmi_rev3_or_later(codec));
3803 static void atihdmi_pin_setup_infoframe(struct hda_codec *codec,
3804 hda_nid_t pin_nid, int dev_id, int ca,
3805 int active_channels, int conn_type)
3807 WARN_ON(dev_id != 0);
3808 snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_CHANNEL_ALLOCATION, ca);
3811 static int atihdmi_paired_swap_fc_lfe(int pos)
3814 * ATI/AMD have automatic FC/LFE swap built-in
3815 * when in pairwise mapping mode.
3819 /* see channel_allocations[].speakers[] */
3828 static int atihdmi_paired_chmap_validate(struct hdac_chmap *chmap,
3829 int ca, int chs, unsigned char *map)
3831 struct hdac_cea_channel_speaker_allocation *cap;
3834 /* check that only channel pairs need to be remapped on old pre-rev3 ATI/AMD */
3836 cap = snd_hdac_get_ch_alloc_from_ca(ca);
3837 for (i = 0; i < chs; ++i) {
3838 int mask = snd_hdac_chmap_to_spk_mask(map[i]);
3840 bool companion_ok = false;
3845 for (j = 0 + i % 2; j < 8; j += 2) {
3846 int chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j);
3847 if (cap->speakers[chan_idx] == mask) {
3848 /* channel is in a supported position */
3851 if (i % 2 == 0 && i + 1 < chs) {
3852 /* even channel, check the odd companion */
3853 int comp_chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j + 1);
3854 int comp_mask_req = snd_hdac_chmap_to_spk_mask(map[i+1]);
3855 int comp_mask_act = cap->speakers[comp_chan_idx];
3857 if (comp_mask_req == comp_mask_act)
3858 companion_ok = true;
3870 i++; /* companion channel already checked */
3876 static int atihdmi_pin_set_slot_channel(struct hdac_device *hdac,
3877 hda_nid_t pin_nid, int hdmi_slot, int stream_channel)
3879 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
3881 int ati_channel_setup = 0;
3886 if (!has_amd_full_remap_support(codec)) {
3887 hdmi_slot = atihdmi_paired_swap_fc_lfe(hdmi_slot);
3889 /* In case this is an odd slot but without stream channel, do not
3890 * disable the slot since the corresponding even slot could have a
3891 * channel. In case neither have a channel, the slot pair will be
3892 * disabled when this function is called for the even slot. */
3893 if (hdmi_slot % 2 != 0 && stream_channel == 0xf)
3896 hdmi_slot -= hdmi_slot % 2;
3898 if (stream_channel != 0xf)
3899 stream_channel -= stream_channel % 2;
3902 verb = ATI_VERB_SET_MULTICHANNEL_01 + hdmi_slot/2 + (hdmi_slot % 2) * 0x00e;
3904 /* ati_channel_setup format: [7..4] = stream_channel_id, [1] = mute, [0] = enable */
3906 if (stream_channel != 0xf)
3907 ati_channel_setup = (stream_channel << 4) | ATI_OUT_ENABLE;
3909 return snd_hda_codec_write(codec, pin_nid, 0, verb, ati_channel_setup);
3912 static int atihdmi_pin_get_slot_channel(struct hdac_device *hdac,
3913 hda_nid_t pin_nid, int asp_slot)
3915 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
3916 bool was_odd = false;
3917 int ati_asp_slot = asp_slot;
3919 int ati_channel_setup;
3924 if (!has_amd_full_remap_support(codec)) {
3925 ati_asp_slot = atihdmi_paired_swap_fc_lfe(asp_slot);
3926 if (ati_asp_slot % 2 != 0) {
3932 verb = ATI_VERB_GET_MULTICHANNEL_01 + ati_asp_slot/2 + (ati_asp_slot % 2) * 0x00e;
3934 ati_channel_setup = snd_hda_codec_read(codec, pin_nid, 0, verb, 0);
3936 if (!(ati_channel_setup & ATI_OUT_ENABLE))
3939 return ((ati_channel_setup & 0xf0) >> 4) + !!was_odd;
3942 static int atihdmi_paired_chmap_cea_alloc_validate_get_type(
3943 struct hdac_chmap *chmap,
3944 struct hdac_cea_channel_speaker_allocation *cap,
3950 * Pre-rev3 ATI/AMD codecs operate in a paired channel mode, so
3951 * we need to take that into account (a single channel may take 2
3952 * channel slots if we need to carry a silent channel next to it).
3953 * On Rev3+ AMD codecs this function is not used.
3957 /* We only produce even-numbered channel count TLVs */
3958 if ((channels % 2) != 0)
3961 for (c = 0; c < 7; c += 2) {
3962 if (cap->speakers[c] || cap->speakers[c+1])
3966 if (chanpairs * 2 != channels)
3969 return SNDRV_CTL_TLVT_CHMAP_PAIRED;
3972 static void atihdmi_paired_cea_alloc_to_tlv_chmap(struct hdac_chmap *hchmap,
3973 struct hdac_cea_channel_speaker_allocation *cap,
3974 unsigned int *chmap, int channels)
3976 /* produce paired maps for pre-rev3 ATI/AMD codecs */
3980 for (c = 7; c >= 0; c--) {
3981 int chan = 7 - atihdmi_paired_swap_fc_lfe(7 - c);
3982 int spk = cap->speakers[chan];
3984 /* add N/A channel if the companion channel is occupied */
3985 if (cap->speakers[chan + (chan % 2 ? -1 : 1)])
3986 chmap[count++] = SNDRV_CHMAP_NA;
3991 chmap[count++] = snd_hdac_spk_to_chmap(spk);
3994 WARN_ON(count != channels);
3997 static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
3998 int dev_id, bool hbr)
4000 int hbr_ctl, hbr_ctl_new;
4002 WARN_ON(dev_id != 0);
4004 hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0);
4005 if (hbr_ctl >= 0 && (hbr_ctl & ATI_HBR_CAPABLE)) {
4007 hbr_ctl_new = hbr_ctl | ATI_HBR_ENABLE;
4009 hbr_ctl_new = hbr_ctl & ~ATI_HBR_ENABLE;
4012 "atihdmi_pin_hbr_setup: NID=0x%x, %shbr-ctl=0x%x\n",
4014 hbr_ctl == hbr_ctl_new ? "" : "new-",
4017 if (hbr_ctl != hbr_ctl_new)
4018 snd_hda_codec_write(codec, pin_nid, 0,
4019 ATI_VERB_SET_HBR_CONTROL,
4028 static int atihdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
4029 hda_nid_t pin_nid, int dev_id,
4030 u32 stream_tag, int format)
4032 if (is_amdhdmi_rev3_or_later(codec)) {
4033 int ramp_rate = 180; /* default as per AMD spec */
4034 /* disable ramp-up/down for non-pcm as per AMD spec */
4035 if (format & AC_FMT_TYPE_NON_PCM)
4038 snd_hda_codec_write(codec, cvt_nid, 0, ATI_VERB_SET_RAMP_RATE, ramp_rate);
4041 return hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id,
4042 stream_tag, format);
4046 static int atihdmi_init(struct hda_codec *codec)
4048 struct hdmi_spec *spec = codec->spec;
4051 err = generic_hdmi_init(codec);
4056 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
4057 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
4059 /* make sure downmix information in infoframe is zero */
4060 snd_hda_codec_write(codec, per_pin->pin_nid, 0, ATI_VERB_SET_DOWNMIX_INFO, 0);
4062 /* enable channel-wise remap mode if supported */
4063 if (has_amd_full_remap_support(codec))
4064 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
4065 ATI_VERB_SET_MULTICHANNEL_MODE,
4066 ATI_MULTICHANNEL_MODE_SINGLE);
4072 /* map from pin NID to port; port is 0-based */
4073 /* for AMD: assume widget NID starting from 3, with step 2 (3, 5, 7, ...) */
4074 static int atihdmi_pin2port(void *audio_ptr, int pin_nid)
4076 return pin_nid / 2 - 1;
4079 /* reverse-map from port to pin NID: see above */
4080 static int atihdmi_port2pin(struct hda_codec *codec, int port)
4082 return port * 2 + 3;
4085 static const struct drm_audio_component_audio_ops atihdmi_audio_ops = {
4086 .pin2port = atihdmi_pin2port,
4087 .pin_eld_notify = generic_acomp_pin_eld_notify,
4088 .master_bind = generic_acomp_master_bind,
4089 .master_unbind = generic_acomp_master_unbind,
4092 static int patch_atihdmi(struct hda_codec *codec)
4094 struct hdmi_spec *spec;
4095 struct hdmi_spec_per_cvt *per_cvt;
4098 err = patch_generic_hdmi(codec);
4103 codec->patch_ops.init = atihdmi_init;
4107 spec->ops.pin_get_eld = atihdmi_pin_get_eld;
4108 spec->ops.pin_setup_infoframe = atihdmi_pin_setup_infoframe;
4109 spec->ops.pin_hbr_setup = atihdmi_pin_hbr_setup;
4110 spec->ops.setup_stream = atihdmi_setup_stream;
4112 spec->chmap.ops.pin_get_slot_channel = atihdmi_pin_get_slot_channel;
4113 spec->chmap.ops.pin_set_slot_channel = atihdmi_pin_set_slot_channel;
4115 if (!has_amd_full_remap_support(codec)) {
4116 /* override to ATI/AMD-specific versions with pairwise mapping */
4117 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
4118 atihdmi_paired_chmap_cea_alloc_validate_get_type;
4119 spec->chmap.ops.cea_alloc_to_tlv_chmap =
4120 atihdmi_paired_cea_alloc_to_tlv_chmap;
4121 spec->chmap.ops.chmap_validate = atihdmi_paired_chmap_validate;
4124 /* ATI/AMD converters do not advertise all of their capabilities */
4125 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
4126 per_cvt = get_cvt(spec, cvt_idx);
4127 per_cvt->channels_max = max(per_cvt->channels_max, 8u);
4128 per_cvt->rates |= SUPPORTED_RATES;
4129 per_cvt->formats |= SUPPORTED_FORMATS;
4130 per_cvt->maxbps = max(per_cvt->maxbps, 24u);
4133 spec->chmap.channels_max = max(spec->chmap.channels_max, 8u);
4135 /* AMD GPUs have neither EPSS nor CLKSTOP bits, hence preventing
4136 * the link-down as is. Tell the core to allow it.
4138 codec->link_down_at_suspend = 1;
4140 generic_acomp_init(codec, &atihdmi_audio_ops, atihdmi_port2pin);
4145 /* VIA HDMI Implementation */
4146 #define VIAHDMI_CVT_NID 0x02 /* audio converter1 */
4147 #define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */
4149 static int patch_via_hdmi(struct hda_codec *codec)
4151 return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
4157 static const struct hda_device_id snd_hda_id_hdmi[] = {
4158 HDA_CODEC_ENTRY(0x1002793c, "RS600 HDMI", patch_atihdmi),
4159 HDA_CODEC_ENTRY(0x10027919, "RS600 HDMI", patch_atihdmi),
4160 HDA_CODEC_ENTRY(0x1002791a, "RS690/780 HDMI", patch_atihdmi),
4161 HDA_CODEC_ENTRY(0x1002aa01, "R6xx HDMI", patch_atihdmi),
4162 HDA_CODEC_ENTRY(0x10951390, "SiI1390 HDMI", patch_generic_hdmi),
4163 HDA_CODEC_ENTRY(0x10951392, "SiI1392 HDMI", patch_generic_hdmi),
4164 HDA_CODEC_ENTRY(0x17e80047, "Chrontel HDMI", patch_generic_hdmi),
4165 HDA_CODEC_ENTRY(0x10de0001, "MCP73 HDMI", patch_nvhdmi_2ch),
4166 HDA_CODEC_ENTRY(0x10de0002, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4167 HDA_CODEC_ENTRY(0x10de0003, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4168 HDA_CODEC_ENTRY(0x10de0004, "GPU 04 HDMI", patch_nvhdmi_8ch_7x),
4169 HDA_CODEC_ENTRY(0x10de0005, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4170 HDA_CODEC_ENTRY(0x10de0006, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4171 HDA_CODEC_ENTRY(0x10de0007, "MCP79/7A HDMI", patch_nvhdmi_8ch_7x),
4172 HDA_CODEC_ENTRY(0x10de0008, "GPU 08 HDMI/DP", patch_nvhdmi_legacy),
4173 HDA_CODEC_ENTRY(0x10de0009, "GPU 09 HDMI/DP", patch_nvhdmi_legacy),
4174 HDA_CODEC_ENTRY(0x10de000a, "GPU 0a HDMI/DP", patch_nvhdmi_legacy),
4175 HDA_CODEC_ENTRY(0x10de000b, "GPU 0b HDMI/DP", patch_nvhdmi_legacy),
4176 HDA_CODEC_ENTRY(0x10de000c, "MCP89 HDMI", patch_nvhdmi_legacy),
4177 HDA_CODEC_ENTRY(0x10de000d, "GPU 0d HDMI/DP", patch_nvhdmi_legacy),
4178 HDA_CODEC_ENTRY(0x10de0010, "GPU 10 HDMI/DP", patch_nvhdmi_legacy),
4179 HDA_CODEC_ENTRY(0x10de0011, "GPU 11 HDMI/DP", patch_nvhdmi_legacy),
4180 HDA_CODEC_ENTRY(0x10de0012, "GPU 12 HDMI/DP", patch_nvhdmi_legacy),
4181 HDA_CODEC_ENTRY(0x10de0013, "GPU 13 HDMI/DP", patch_nvhdmi_legacy),
4182 HDA_CODEC_ENTRY(0x10de0014, "GPU 14 HDMI/DP", patch_nvhdmi_legacy),
4183 HDA_CODEC_ENTRY(0x10de0015, "GPU 15 HDMI/DP", patch_nvhdmi_legacy),
4184 HDA_CODEC_ENTRY(0x10de0016, "GPU 16 HDMI/DP", patch_nvhdmi_legacy),
4185 /* 17 is known to be absent */
4186 HDA_CODEC_ENTRY(0x10de0018, "GPU 18 HDMI/DP", patch_nvhdmi_legacy),
4187 HDA_CODEC_ENTRY(0x10de0019, "GPU 19 HDMI/DP", patch_nvhdmi_legacy),
4188 HDA_CODEC_ENTRY(0x10de001a, "GPU 1a HDMI/DP", patch_nvhdmi_legacy),
4189 HDA_CODEC_ENTRY(0x10de001b, "GPU 1b HDMI/DP", patch_nvhdmi_legacy),
4190 HDA_CODEC_ENTRY(0x10de001c, "GPU 1c HDMI/DP", patch_nvhdmi_legacy),
4191 HDA_CODEC_ENTRY(0x10de0020, "Tegra30 HDMI", patch_tegra_hdmi),
4192 HDA_CODEC_ENTRY(0x10de0022, "Tegra114 HDMI", patch_tegra_hdmi),
4193 HDA_CODEC_ENTRY(0x10de0028, "Tegra124 HDMI", patch_tegra_hdmi),
4194 HDA_CODEC_ENTRY(0x10de0029, "Tegra210 HDMI/DP", patch_tegra_hdmi),
4195 HDA_CODEC_ENTRY(0x10de002d, "Tegra186 HDMI/DP0", patch_tegra_hdmi),
4196 HDA_CODEC_ENTRY(0x10de002e, "Tegra186 HDMI/DP1", patch_tegra_hdmi),
4197 HDA_CODEC_ENTRY(0x10de002f, "Tegra194 HDMI/DP2", patch_tegra_hdmi),
4198 HDA_CODEC_ENTRY(0x10de0030, "Tegra194 HDMI/DP3", patch_tegra_hdmi),
4199 HDA_CODEC_ENTRY(0x10de0040, "GPU 40 HDMI/DP", patch_nvhdmi),
4200 HDA_CODEC_ENTRY(0x10de0041, "GPU 41 HDMI/DP", patch_nvhdmi),
4201 HDA_CODEC_ENTRY(0x10de0042, "GPU 42 HDMI/DP", patch_nvhdmi),
4202 HDA_CODEC_ENTRY(0x10de0043, "GPU 43 HDMI/DP", patch_nvhdmi),
4203 HDA_CODEC_ENTRY(0x10de0044, "GPU 44 HDMI/DP", patch_nvhdmi),
4204 HDA_CODEC_ENTRY(0x10de0045, "GPU 45 HDMI/DP", patch_nvhdmi),
4205 HDA_CODEC_ENTRY(0x10de0050, "GPU 50 HDMI/DP", patch_nvhdmi),
4206 HDA_CODEC_ENTRY(0x10de0051, "GPU 51 HDMI/DP", patch_nvhdmi),
4207 HDA_CODEC_ENTRY(0x10de0052, "GPU 52 HDMI/DP", patch_nvhdmi),
4208 HDA_CODEC_ENTRY(0x10de0060, "GPU 60 HDMI/DP", patch_nvhdmi),
4209 HDA_CODEC_ENTRY(0x10de0061, "GPU 61 HDMI/DP", patch_nvhdmi),
4210 HDA_CODEC_ENTRY(0x10de0062, "GPU 62 HDMI/DP", patch_nvhdmi),
4211 HDA_CODEC_ENTRY(0x10de0067, "MCP67 HDMI", patch_nvhdmi_2ch),
4212 HDA_CODEC_ENTRY(0x10de0070, "GPU 70 HDMI/DP", patch_nvhdmi),
4213 HDA_CODEC_ENTRY(0x10de0071, "GPU 71 HDMI/DP", patch_nvhdmi),
4214 HDA_CODEC_ENTRY(0x10de0072, "GPU 72 HDMI/DP", patch_nvhdmi),
4215 HDA_CODEC_ENTRY(0x10de0073, "GPU 73 HDMI/DP", patch_nvhdmi),
4216 HDA_CODEC_ENTRY(0x10de0074, "GPU 74 HDMI/DP", patch_nvhdmi),
4217 HDA_CODEC_ENTRY(0x10de0076, "GPU 76 HDMI/DP", patch_nvhdmi),
4218 HDA_CODEC_ENTRY(0x10de007b, "GPU 7b HDMI/DP", patch_nvhdmi),
4219 HDA_CODEC_ENTRY(0x10de007c, "GPU 7c HDMI/DP", patch_nvhdmi),
4220 HDA_CODEC_ENTRY(0x10de007d, "GPU 7d HDMI/DP", patch_nvhdmi),
4221 HDA_CODEC_ENTRY(0x10de007e, "GPU 7e HDMI/DP", patch_nvhdmi),
4222 HDA_CODEC_ENTRY(0x10de0080, "GPU 80 HDMI/DP", patch_nvhdmi),
4223 HDA_CODEC_ENTRY(0x10de0081, "GPU 81 HDMI/DP", patch_nvhdmi),
4224 HDA_CODEC_ENTRY(0x10de0082, "GPU 82 HDMI/DP", patch_nvhdmi),
4225 HDA_CODEC_ENTRY(0x10de0083, "GPU 83 HDMI/DP", patch_nvhdmi),
4226 HDA_CODEC_ENTRY(0x10de0084, "GPU 84 HDMI/DP", patch_nvhdmi),
4227 HDA_CODEC_ENTRY(0x10de0090, "GPU 90 HDMI/DP", patch_nvhdmi),
4228 HDA_CODEC_ENTRY(0x10de0091, "GPU 91 HDMI/DP", patch_nvhdmi),
4229 HDA_CODEC_ENTRY(0x10de0092, "GPU 92 HDMI/DP", patch_nvhdmi),
4230 HDA_CODEC_ENTRY(0x10de0093, "GPU 93 HDMI/DP", patch_nvhdmi),
4231 HDA_CODEC_ENTRY(0x10de0094, "GPU 94 HDMI/DP", patch_nvhdmi),
4232 HDA_CODEC_ENTRY(0x10de0095, "GPU 95 HDMI/DP", patch_nvhdmi),
4233 HDA_CODEC_ENTRY(0x10de0097, "GPU 97 HDMI/DP", patch_nvhdmi),
4234 HDA_CODEC_ENTRY(0x10de0098, "GPU 98 HDMI/DP", patch_nvhdmi),
4235 HDA_CODEC_ENTRY(0x10de0099, "GPU 99 HDMI/DP", patch_nvhdmi),
4236 HDA_CODEC_ENTRY(0x10de8001, "MCP73 HDMI", patch_nvhdmi_2ch),
4237 HDA_CODEC_ENTRY(0x10de8067, "MCP67/68 HDMI", patch_nvhdmi_2ch),
4238 HDA_CODEC_ENTRY(0x11069f80, "VX900 HDMI/DP", patch_via_hdmi),
4239 HDA_CODEC_ENTRY(0x11069f81, "VX900 HDMI/DP", patch_via_hdmi),
4240 HDA_CODEC_ENTRY(0x11069f84, "VX11 HDMI/DP", patch_generic_hdmi),
4241 HDA_CODEC_ENTRY(0x11069f85, "VX11 HDMI/DP", patch_generic_hdmi),
4242 HDA_CODEC_ENTRY(0x80860054, "IbexPeak HDMI", patch_i915_cpt_hdmi),
4243 HDA_CODEC_ENTRY(0x80862800, "Geminilake HDMI", patch_i915_glk_hdmi),
4244 HDA_CODEC_ENTRY(0x80862801, "Bearlake HDMI", patch_generic_hdmi),
4245 HDA_CODEC_ENTRY(0x80862802, "Cantiga HDMI", patch_generic_hdmi),
4246 HDA_CODEC_ENTRY(0x80862803, "Eaglelake HDMI", patch_generic_hdmi),
4247 HDA_CODEC_ENTRY(0x80862804, "IbexPeak HDMI", patch_i915_cpt_hdmi),
4248 HDA_CODEC_ENTRY(0x80862805, "CougarPoint HDMI", patch_i915_cpt_hdmi),
4249 HDA_CODEC_ENTRY(0x80862806, "PantherPoint HDMI", patch_i915_cpt_hdmi),
4250 HDA_CODEC_ENTRY(0x80862807, "Haswell HDMI", patch_i915_hsw_hdmi),
4251 HDA_CODEC_ENTRY(0x80862808, "Broadwell HDMI", patch_i915_hsw_hdmi),
4252 HDA_CODEC_ENTRY(0x80862809, "Skylake HDMI", patch_i915_hsw_hdmi),
4253 HDA_CODEC_ENTRY(0x8086280a, "Broxton HDMI", patch_i915_hsw_hdmi),
4254 HDA_CODEC_ENTRY(0x8086280b, "Kabylake HDMI", patch_i915_hsw_hdmi),
4255 HDA_CODEC_ENTRY(0x8086280c, "Cannonlake HDMI", patch_i915_glk_hdmi),
4256 HDA_CODEC_ENTRY(0x8086280d, "Geminilake HDMI", patch_i915_glk_hdmi),
4257 HDA_CODEC_ENTRY(0x8086280f, "Icelake HDMI", patch_i915_icl_hdmi),
4258 HDA_CODEC_ENTRY(0x80862812, "Tigerlake HDMI", patch_i915_tgl_hdmi),
4259 HDA_CODEC_ENTRY(0x80862880, "CedarTrail HDMI", patch_generic_hdmi),
4260 HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_i915_byt_hdmi),
4261 HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_i915_byt_hdmi),
4262 HDA_CODEC_ENTRY(0x808629fb, "Crestline HDMI", patch_generic_hdmi),
4263 /* special ID for generic HDMI */
4264 HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC_HDMI, "Generic HDMI", patch_generic_hdmi),
4267 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_hdmi);
4269 MODULE_LICENSE("GPL");
4270 MODULE_DESCRIPTION("HDMI HD-audio codec");
4271 MODULE_ALIAS("snd-hda-codec-intelhdmi");
4272 MODULE_ALIAS("snd-hda-codec-nvhdmi");
4273 MODULE_ALIAS("snd-hda-codec-atihdmi");
4275 static struct hda_codec_driver hdmi_driver = {
4276 .id = snd_hda_id_hdmi,
4279 module_hda_codec_driver(hdmi_driver);