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"
35 #include "hda_controller.h"
37 static bool static_hdmi_pcm;
38 module_param(static_hdmi_pcm, bool, 0644);
39 MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
41 static bool enable_acomp = true;
42 module_param(enable_acomp, bool, 0444);
43 MODULE_PARM_DESC(enable_acomp, "Enable audio component binding (default=yes)");
45 static bool enable_silent_stream =
46 IS_ENABLED(CONFIG_SND_HDA_INTEL_HDMI_SILENT_STREAM);
47 module_param(enable_silent_stream, bool, 0644);
48 MODULE_PARM_DESC(enable_silent_stream, "Enable Silent Stream for HDMI devices");
50 struct hdmi_spec_per_cvt {
53 unsigned int channels_min;
54 unsigned int channels_max;
60 /* max. connections to a widget */
61 #define HDA_MAX_CONNECTIONS 32
63 struct hdmi_spec_per_pin {
66 /* pin idx, different device entries on the same pin use the same idx */
69 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
73 struct hda_codec *codec;
74 struct hdmi_eld sink_eld;
76 struct delayed_work work;
77 struct hdmi_pcm *pcm; /* pointer to spec->pcm_rec[n] dynamically*/
78 int pcm_idx; /* which pcm is attached. -1 means no pcm is attached */
80 bool setup; /* the stream has been set up by prepare callback */
82 int channels; /* current number of channels */
84 bool chmap_set; /* channel-map override by ALSA API? */
85 unsigned char chmap[8]; /* ALSA API channel-map */
86 #ifdef CONFIG_SND_PROC_FS
87 struct snd_info_entry *proc_entry;
91 /* operations used by generic code that can be overridden by patches */
93 int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid,
94 int dev_id, unsigned char *buf, int *eld_size);
96 void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid,
98 int ca, int active_channels, int conn_type);
100 /* enable/disable HBR (HD passthrough) */
101 int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid,
102 int dev_id, bool hbr);
104 int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid,
105 hda_nid_t pin_nid, int dev_id, u32 stream_tag,
108 void (*pin_cvt_fixup)(struct hda_codec *codec,
109 struct hdmi_spec_per_pin *per_pin,
115 struct snd_jack *jack;
116 struct snd_kcontrol *eld_ctl;
120 struct hda_codec *codec;
122 struct snd_array cvts; /* struct hdmi_spec_per_cvt */
123 hda_nid_t cvt_nids[4]; /* only for haswell fix */
126 * num_pins is the number of virtual pins
127 * for example, there are 3 pins, and each pin
128 * has 4 device entries, then the num_pins is 12
132 * num_nids is the number of real pins
133 * In the above example, num_nids is 3
137 * dev_num is the number of device entries
139 * In the above example, dev_num is 4
142 struct snd_array pins; /* struct hdmi_spec_per_pin */
143 struct hdmi_pcm pcm_rec[16];
144 struct mutex pcm_lock;
145 struct mutex bind_lock; /* for audio component binding */
146 /* pcm_bitmap means which pcms have been assigned to pins*/
147 unsigned long pcm_bitmap;
148 int pcm_used; /* counter of pcm_rec[] */
149 /* bitmap shows whether the pcm is opened in user space
150 * bit 0 means the first playback PCM (PCM3);
151 * bit 1 means the second playback PCM, and so on.
153 unsigned long pcm_in_use;
155 struct hdmi_eld temp_eld;
160 bool dyn_pcm_no_legacy;
161 bool intel_hsw_fixup; /* apply Intel platform-specific fixups */
163 * Non-generic VIA/NVIDIA specific
165 struct hda_multi_out multiout;
166 struct hda_pcm_stream pcm_playback;
168 bool use_acomp_notifier; /* use eld_notify callback for hotplug */
169 bool acomp_registered; /* audio component registered in this driver */
170 bool force_connect; /* force connectivity */
171 struct drm_audio_component_audio_ops drm_audio_ops;
172 int (*port2pin)(struct hda_codec *, int); /* reverse port/pin mapping */
174 struct hdac_chmap chmap;
175 hda_nid_t vendor_nid;
178 bool send_silent_stream; /* Flag to enable silent stream feature */
181 #ifdef CONFIG_SND_HDA_COMPONENT
182 static inline bool codec_has_acomp(struct hda_codec *codec)
184 struct hdmi_spec *spec = codec->spec;
185 return spec->use_acomp_notifier;
188 #define codec_has_acomp(codec) false
191 struct hdmi_audio_infoframe {
198 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
202 u8 LFEPBL01_LSV36_DM_INH7;
205 struct dp_audio_infoframe {
208 u8 ver; /* 0x11 << 2 */
210 u8 CC02_CT47; /* match with HDMI infoframe from this on */
214 u8 LFEPBL01_LSV36_DM_INH7;
217 union audio_infoframe {
218 struct hdmi_audio_infoframe hdmi;
219 struct dp_audio_infoframe dp;
227 #define get_pin(spec, idx) \
228 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx))
229 #define get_cvt(spec, idx) \
230 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx))
231 /* obtain hdmi_pcm object assigned to idx */
232 #define get_hdmi_pcm(spec, idx) (&(spec)->pcm_rec[idx])
233 /* obtain hda_pcm object assigned to idx */
234 #define get_pcm_rec(spec, idx) (get_hdmi_pcm(spec, idx)->pcm)
236 static int pin_id_to_pin_index(struct hda_codec *codec,
237 hda_nid_t pin_nid, int dev_id)
239 struct hdmi_spec *spec = codec->spec;
241 struct hdmi_spec_per_pin *per_pin;
244 * (dev_id == -1) means it is NON-MST pin
245 * return the first virtual pin on this port
250 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
251 per_pin = get_pin(spec, pin_idx);
252 if ((per_pin->pin_nid == pin_nid) &&
253 (per_pin->dev_id == dev_id))
257 codec_warn(codec, "HDMI: pin NID 0x%x not registered\n", pin_nid);
261 static int hinfo_to_pcm_index(struct hda_codec *codec,
262 struct hda_pcm_stream *hinfo)
264 struct hdmi_spec *spec = codec->spec;
267 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++)
268 if (get_pcm_rec(spec, pcm_idx)->stream == hinfo)
271 codec_warn(codec, "HDMI: hinfo %p not tied to a PCM\n", hinfo);
275 static int hinfo_to_pin_index(struct hda_codec *codec,
276 struct hda_pcm_stream *hinfo)
278 struct hdmi_spec *spec = codec->spec;
279 struct hdmi_spec_per_pin *per_pin;
282 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
283 per_pin = get_pin(spec, pin_idx);
285 per_pin->pcm->pcm->stream == hinfo)
289 codec_dbg(codec, "HDMI: hinfo %p (pcm %d) not registered\n", hinfo,
290 hinfo_to_pcm_index(codec, hinfo));
294 static struct hdmi_spec_per_pin *pcm_idx_to_pin(struct hdmi_spec *spec,
298 struct hdmi_spec_per_pin *per_pin;
300 for (i = 0; i < spec->num_pins; i++) {
301 per_pin = get_pin(spec, i);
302 if (per_pin->pcm_idx == pcm_idx)
308 static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid)
310 struct hdmi_spec *spec = codec->spec;
313 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
314 if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid)
317 codec_warn(codec, "HDMI: cvt NID 0x%x not registered\n", cvt_nid);
321 static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
322 struct snd_ctl_elem_info *uinfo)
324 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
325 struct hdmi_spec *spec = codec->spec;
326 struct hdmi_spec_per_pin *per_pin;
327 struct hdmi_eld *eld;
330 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
332 pcm_idx = kcontrol->private_value;
333 mutex_lock(&spec->pcm_lock);
334 per_pin = pcm_idx_to_pin(spec, pcm_idx);
336 /* no pin is bound to the pcm */
340 eld = &per_pin->sink_eld;
341 uinfo->count = eld->eld_valid ? eld->eld_size : 0;
344 mutex_unlock(&spec->pcm_lock);
348 static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
349 struct snd_ctl_elem_value *ucontrol)
351 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
352 struct hdmi_spec *spec = codec->spec;
353 struct hdmi_spec_per_pin *per_pin;
354 struct hdmi_eld *eld;
358 pcm_idx = kcontrol->private_value;
359 mutex_lock(&spec->pcm_lock);
360 per_pin = pcm_idx_to_pin(spec, pcm_idx);
362 /* no pin is bound to the pcm */
363 memset(ucontrol->value.bytes.data, 0,
364 ARRAY_SIZE(ucontrol->value.bytes.data));
368 eld = &per_pin->sink_eld;
369 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data) ||
370 eld->eld_size > ELD_MAX_SIZE) {
376 memset(ucontrol->value.bytes.data, 0,
377 ARRAY_SIZE(ucontrol->value.bytes.data));
379 memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
383 mutex_unlock(&spec->pcm_lock);
387 static const struct snd_kcontrol_new eld_bytes_ctl = {
388 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE |
389 SNDRV_CTL_ELEM_ACCESS_SKIP_CHECK,
390 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
392 .info = hdmi_eld_ctl_info,
393 .get = hdmi_eld_ctl_get,
396 static int hdmi_create_eld_ctl(struct hda_codec *codec, int pcm_idx,
399 struct snd_kcontrol *kctl;
400 struct hdmi_spec *spec = codec->spec;
403 kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
406 kctl->private_value = pcm_idx;
407 kctl->id.device = device;
409 /* no pin nid is associated with the kctl now
410 * tbd: associate pin nid to eld ctl later
412 err = snd_hda_ctl_add(codec, 0, kctl);
416 get_hdmi_pcm(spec, pcm_idx)->eld_ctl = kctl;
421 static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
422 int *packet_index, int *byte_index)
426 val = snd_hda_codec_read(codec, pin_nid, 0,
427 AC_VERB_GET_HDMI_DIP_INDEX, 0);
429 *packet_index = val >> 5;
430 *byte_index = val & 0x1f;
434 static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
435 int packet_index, int byte_index)
439 val = (packet_index << 5) | (byte_index & 0x1f);
441 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
444 static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
447 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
450 static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
452 struct hdmi_spec *spec = codec->spec;
456 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
457 snd_hda_codec_write(codec, pin_nid, 0,
458 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
460 if (spec->dyn_pin_out)
461 /* Disable pin out until stream is active */
464 /* Enable pin out: some machines with GM965 gets broken output
465 * when the pin is disabled or changed while using with HDMI
469 snd_hda_codec_write(codec, pin_nid, 0,
470 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_out);
477 #ifdef CONFIG_SND_PROC_FS
478 static void print_eld_info(struct snd_info_entry *entry,
479 struct snd_info_buffer *buffer)
481 struct hdmi_spec_per_pin *per_pin = entry->private_data;
483 mutex_lock(&per_pin->lock);
484 snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer);
485 mutex_unlock(&per_pin->lock);
488 static void write_eld_info(struct snd_info_entry *entry,
489 struct snd_info_buffer *buffer)
491 struct hdmi_spec_per_pin *per_pin = entry->private_data;
493 mutex_lock(&per_pin->lock);
494 snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer);
495 mutex_unlock(&per_pin->lock);
498 static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
501 struct hda_codec *codec = per_pin->codec;
502 struct snd_info_entry *entry;
505 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
506 err = snd_card_proc_new(codec->card, name, &entry);
510 snd_info_set_text_ops(entry, per_pin, print_eld_info);
511 entry->c.text.write = write_eld_info;
513 per_pin->proc_entry = entry;
518 static void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
520 if (!per_pin->codec->bus->shutdown) {
521 snd_info_free_entry(per_pin->proc_entry);
522 per_pin->proc_entry = NULL;
526 static inline int eld_proc_new(struct hdmi_spec_per_pin *per_pin,
531 static inline void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
537 * Audio InfoFrame routines
541 * Enable Audio InfoFrame Transmission
543 static void hdmi_start_infoframe_trans(struct hda_codec *codec,
546 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
547 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
552 * Disable Audio InfoFrame Transmission
554 static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
557 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
558 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
562 static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
564 #ifdef CONFIG_SND_DEBUG_VERBOSE
568 size = snd_hdmi_get_eld_size(codec, pin_nid);
569 codec_dbg(codec, "HDMI: ELD buf size is %d\n", size);
571 for (i = 0; i < 8; i++) {
572 size = snd_hda_codec_read(codec, pin_nid, 0,
573 AC_VERB_GET_HDMI_DIP_SIZE, i);
574 codec_dbg(codec, "HDMI: DIP GP[%d] buf size is %d\n", i, size);
579 static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
585 for (i = 0; i < 8; i++) {
586 size = snd_hda_codec_read(codec, pin_nid, 0,
587 AC_VERB_GET_HDMI_DIP_SIZE, i);
591 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
592 for (j = 1; j < 1000; j++) {
593 hdmi_write_dip_byte(codec, pin_nid, 0x0);
594 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
596 codec_dbg(codec, "dip index %d: %d != %d\n",
598 if (bi == 0) /* byte index wrapped around */
602 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
608 static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
610 u8 *bytes = (u8 *)hdmi_ai;
614 hdmi_ai->checksum = 0;
616 for (i = 0; i < sizeof(*hdmi_ai); i++)
619 hdmi_ai->checksum = -sum;
622 static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
628 hdmi_debug_dip_size(codec, pin_nid);
629 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
631 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
632 for (i = 0; i < size; i++)
633 hdmi_write_dip_byte(codec, pin_nid, dip[i]);
636 static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
642 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
643 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
647 for (i = 0; i < size; i++) {
648 val = snd_hda_codec_read(codec, pin_nid, 0,
649 AC_VERB_GET_HDMI_DIP_DATA, 0);
657 static int hdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
658 int dev_id, unsigned char *buf, int *eld_size)
660 snd_hda_set_dev_select(codec, nid, dev_id);
662 return snd_hdmi_get_eld(codec, nid, buf, eld_size);
665 static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
666 hda_nid_t pin_nid, int dev_id,
667 int ca, int active_channels,
670 union audio_infoframe ai;
672 memset(&ai, 0, sizeof(ai));
673 if (conn_type == 0) { /* HDMI */
674 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
676 hdmi_ai->type = 0x84;
679 hdmi_ai->CC02_CT47 = active_channels - 1;
681 hdmi_checksum_audio_infoframe(hdmi_ai);
682 } else if (conn_type == 1) { /* DisplayPort */
683 struct dp_audio_infoframe *dp_ai = &ai.dp;
687 dp_ai->ver = 0x11 << 2;
688 dp_ai->CC02_CT47 = active_channels - 1;
691 codec_dbg(codec, "HDMI: unknown connection type at pin NID 0x%x\n", pin_nid);
695 snd_hda_set_dev_select(codec, pin_nid, dev_id);
698 * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
699 * sizeof(*dp_ai) to avoid partial match/update problems when
700 * the user switches between HDMI/DP monitors.
702 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
704 codec_dbg(codec, "%s: pin NID=0x%x channels=%d ca=0x%02x\n",
705 __func__, pin_nid, active_channels, ca);
706 hdmi_stop_infoframe_trans(codec, pin_nid);
707 hdmi_fill_audio_infoframe(codec, pin_nid,
708 ai.bytes, sizeof(ai));
709 hdmi_start_infoframe_trans(codec, pin_nid);
713 static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
714 struct hdmi_spec_per_pin *per_pin,
717 struct hdmi_spec *spec = codec->spec;
718 struct hdac_chmap *chmap = &spec->chmap;
719 hda_nid_t pin_nid = per_pin->pin_nid;
720 int dev_id = per_pin->dev_id;
721 int channels = per_pin->channels;
723 struct hdmi_eld *eld;
729 snd_hda_set_dev_select(codec, pin_nid, dev_id);
731 /* some HW (e.g. HSW+) needs reprogramming the amp at each time */
732 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
733 snd_hda_codec_write(codec, pin_nid, 0,
734 AC_VERB_SET_AMP_GAIN_MUTE,
737 eld = &per_pin->sink_eld;
739 ca = snd_hdac_channel_allocation(&codec->core,
740 eld->info.spk_alloc, channels,
741 per_pin->chmap_set, non_pcm, per_pin->chmap);
743 active_channels = snd_hdac_get_active_channels(ca);
745 chmap->ops.set_channel_count(&codec->core, per_pin->cvt_nid,
749 * always configure channel mapping, it may have been changed by the
750 * user in the meantime
752 snd_hdac_setup_channel_mapping(&spec->chmap,
753 pin_nid, non_pcm, ca, channels,
754 per_pin->chmap, per_pin->chmap_set);
756 spec->ops.pin_setup_infoframe(codec, pin_nid, dev_id,
757 ca, active_channels, eld->info.conn_type);
759 per_pin->non_pcm = non_pcm;
766 static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
768 static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid,
771 struct hdmi_spec *spec = codec->spec;
772 int pin_idx = pin_id_to_pin_index(codec, nid, dev_id);
776 mutex_lock(&spec->pcm_lock);
777 hdmi_present_sense(get_pin(spec, pin_idx), 1);
778 mutex_unlock(&spec->pcm_lock);
781 static void jack_callback(struct hda_codec *codec,
782 struct hda_jack_callback *jack)
784 /* stop polling when notification is enabled */
785 if (codec_has_acomp(codec))
788 check_presence_and_report(codec, jack->nid, jack->dev_id);
791 static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res,
792 struct hda_jack_tbl *jack)
794 jack->jack_dirty = 1;
797 "HDMI hot plug event: Codec=%d NID=0x%x Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n",
798 codec->addr, jack->nid, jack->dev_id, !!(res & AC_UNSOL_RES_IA),
799 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
801 check_presence_and_report(codec, jack->nid, jack->dev_id);
804 static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
806 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
807 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
808 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
809 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
812 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
829 static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
831 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
832 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
833 struct hda_jack_tbl *jack;
835 if (codec_has_acomp(codec))
840 (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
842 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, dev_entry);
844 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, 0);
848 codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag);
853 hdmi_intrinsic_event(codec, res, jack);
855 hdmi_non_intrinsic_event(codec, res);
858 static void haswell_verify_D0(struct hda_codec *codec,
859 hda_nid_t cvt_nid, hda_nid_t nid)
863 /* For Haswell, the converter 1/2 may keep in D3 state after bootup,
864 * thus pins could only choose converter 0 for use. Make sure the
865 * converters are in correct power state */
866 if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0))
867 snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
869 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) {
870 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
873 pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
874 pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
875 codec_dbg(codec, "Haswell HDMI audio: Power for NID 0x%x is now D%d\n", nid, pwr);
883 /* HBR should be Non-PCM, 8 channels */
884 #define is_hbr_format(format) \
885 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
887 static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
888 int dev_id, bool hbr)
890 int pinctl, new_pinctl;
892 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
893 snd_hda_set_dev_select(codec, pin_nid, dev_id);
894 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
895 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
898 return hbr ? -EINVAL : 0;
900 new_pinctl = pinctl & ~AC_PINCTL_EPT;
902 new_pinctl |= AC_PINCTL_EPT_HBR;
904 new_pinctl |= AC_PINCTL_EPT_NATIVE;
907 "hdmi_pin_hbr_setup: NID=0x%x, %spinctl=0x%x\n",
909 pinctl == new_pinctl ? "" : "new-",
912 if (pinctl != new_pinctl)
913 snd_hda_codec_write(codec, pin_nid, 0,
914 AC_VERB_SET_PIN_WIDGET_CONTROL,
922 static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
923 hda_nid_t pin_nid, int dev_id,
924 u32 stream_tag, int format)
926 struct hdmi_spec *spec = codec->spec;
930 err = spec->ops.pin_hbr_setup(codec, pin_nid, dev_id,
931 is_hbr_format(format));
934 codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n");
938 if (spec->intel_hsw_fixup) {
941 * on recent platforms IEC Coding Type is required for HBR
942 * support, read current Digital Converter settings and set
943 * ICT bitfield if needed.
945 param = snd_hda_codec_read(codec, cvt_nid, 0,
946 AC_VERB_GET_DIGI_CONVERT_1, 0);
948 param = (param >> 16) & ~(AC_DIG3_ICT);
950 /* on recent platforms ICT mode is required for HBR support */
951 if (is_hbr_format(format))
954 snd_hda_codec_write(codec, cvt_nid, 0,
955 AC_VERB_SET_DIGI_CONVERT_3, param);
958 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
962 /* Try to find an available converter
963 * If pin_idx is less then zero, just try to find an available converter.
964 * Otherwise, try to find an available converter and get the cvt mux index
967 static int hdmi_choose_cvt(struct hda_codec *codec,
968 int pin_idx, int *cvt_id)
970 struct hdmi_spec *spec = codec->spec;
971 struct hdmi_spec_per_pin *per_pin;
972 struct hdmi_spec_per_cvt *per_cvt = NULL;
973 int cvt_idx, mux_idx = 0;
975 /* pin_idx < 0 means no pin will be bound to the converter */
979 per_pin = get_pin(spec, pin_idx);
981 if (per_pin && per_pin->silent_stream) {
982 cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid);
988 /* Dynamically assign converter to stream */
989 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
990 per_cvt = get_cvt(spec, cvt_idx);
992 /* Must not already be assigned */
993 if (per_cvt->assigned)
997 /* Must be in pin's mux's list of converters */
998 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
999 if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid)
1001 /* Not in mux list */
1002 if (mux_idx == per_pin->num_mux_nids)
1007 /* No free converters */
1008 if (cvt_idx == spec->num_cvts)
1011 if (per_pin != NULL)
1012 per_pin->mux_idx = mux_idx;
1020 /* Assure the pin select the right convetor */
1021 static void intel_verify_pin_cvt_connect(struct hda_codec *codec,
1022 struct hdmi_spec_per_pin *per_pin)
1024 hda_nid_t pin_nid = per_pin->pin_nid;
1027 mux_idx = per_pin->mux_idx;
1028 curr = snd_hda_codec_read(codec, pin_nid, 0,
1029 AC_VERB_GET_CONNECT_SEL, 0);
1030 if (curr != mux_idx)
1031 snd_hda_codec_write_cache(codec, pin_nid, 0,
1032 AC_VERB_SET_CONNECT_SEL,
1036 /* get the mux index for the converter of the pins
1037 * converter's mux index is the same for all pins on Intel platform
1039 static int intel_cvt_id_to_mux_idx(struct hdmi_spec *spec,
1044 for (i = 0; i < spec->num_cvts; i++)
1045 if (spec->cvt_nids[i] == cvt_nid)
1050 /* Intel HDMI workaround to fix audio routing issue:
1051 * For some Intel display codecs, pins share the same connection list.
1052 * So a conveter can be selected by multiple pins and playback on any of these
1053 * pins will generate sound on the external display, because audio flows from
1054 * the same converter to the display pipeline. Also muting one pin may make
1055 * other pins have no sound output.
1056 * So this function assures that an assigned converter for a pin is not selected
1057 * by any other pins.
1059 static void intel_not_share_assigned_cvt(struct hda_codec *codec,
1061 int dev_id, int mux_idx)
1063 struct hdmi_spec *spec = codec->spec;
1066 struct hdmi_spec_per_cvt *per_cvt;
1067 struct hdmi_spec_per_pin *per_pin;
1070 /* configure the pins connections */
1071 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1075 per_pin = get_pin(spec, pin_idx);
1077 * pin not connected to monitor
1078 * no need to operate on it
1083 if ((per_pin->pin_nid == pin_nid) &&
1084 (per_pin->dev_id == dev_id))
1088 * if per_pin->dev_id >= dev_num,
1089 * snd_hda_get_dev_select() will fail,
1090 * and the following operation is unpredictable.
1091 * So skip this situation.
1093 dev_num = snd_hda_get_num_devices(codec, per_pin->pin_nid) + 1;
1094 if (per_pin->dev_id >= dev_num)
1097 nid = per_pin->pin_nid;
1100 * Calling this function should not impact
1101 * on the device entry selection
1102 * So let's save the dev id for each pin,
1103 * and restore it when return
1105 dev_id_saved = snd_hda_get_dev_select(codec, nid);
1106 snd_hda_set_dev_select(codec, nid, per_pin->dev_id);
1107 curr = snd_hda_codec_read(codec, nid, 0,
1108 AC_VERB_GET_CONNECT_SEL, 0);
1109 if (curr != mux_idx) {
1110 snd_hda_set_dev_select(codec, nid, dev_id_saved);
1115 /* choose an unassigned converter. The conveters in the
1116 * connection list are in the same order as in the codec.
1118 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
1119 per_cvt = get_cvt(spec, cvt_idx);
1120 if (!per_cvt->assigned) {
1122 "choose cvt %d for pin NID 0x%x\n",
1124 snd_hda_codec_write_cache(codec, nid, 0,
1125 AC_VERB_SET_CONNECT_SEL,
1130 snd_hda_set_dev_select(codec, nid, dev_id_saved);
1134 /* A wrapper of intel_not_share_asigned_cvt() */
1135 static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,
1136 hda_nid_t pin_nid, int dev_id, hda_nid_t cvt_nid)
1139 struct hdmi_spec *spec = codec->spec;
1141 /* On Intel platform, the mapping of converter nid to
1142 * mux index of the pins are always the same.
1143 * The pin nid may be 0, this means all pins will not
1144 * share the converter.
1146 mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid);
1148 intel_not_share_assigned_cvt(codec, pin_nid, dev_id, mux_idx);
1151 /* skeleton caller of pin_cvt_fixup ops */
1152 static void pin_cvt_fixup(struct hda_codec *codec,
1153 struct hdmi_spec_per_pin *per_pin,
1156 struct hdmi_spec *spec = codec->spec;
1158 if (spec->ops.pin_cvt_fixup)
1159 spec->ops.pin_cvt_fixup(codec, per_pin, cvt_nid);
1162 /* called in hdmi_pcm_open when no pin is assigned to the PCM
1163 * in dyn_pcm_assign mode.
1165 static int hdmi_pcm_open_no_pin(struct hda_pcm_stream *hinfo,
1166 struct hda_codec *codec,
1167 struct snd_pcm_substream *substream)
1169 struct hdmi_spec *spec = codec->spec;
1170 struct snd_pcm_runtime *runtime = substream->runtime;
1171 int cvt_idx, pcm_idx;
1172 struct hdmi_spec_per_cvt *per_cvt = NULL;
1175 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1179 err = hdmi_choose_cvt(codec, -1, &cvt_idx);
1183 per_cvt = get_cvt(spec, cvt_idx);
1184 per_cvt->assigned = 1;
1185 hinfo->nid = per_cvt->cvt_nid;
1187 pin_cvt_fixup(codec, NULL, per_cvt->cvt_nid);
1189 set_bit(pcm_idx, &spec->pcm_in_use);
1190 /* todo: setup spdif ctls assign */
1192 /* Initially set the converter's capabilities */
1193 hinfo->channels_min = per_cvt->channels_min;
1194 hinfo->channels_max = per_cvt->channels_max;
1195 hinfo->rates = per_cvt->rates;
1196 hinfo->formats = per_cvt->formats;
1197 hinfo->maxbps = per_cvt->maxbps;
1199 /* Store the updated parameters */
1200 runtime->hw.channels_min = hinfo->channels_min;
1201 runtime->hw.channels_max = hinfo->channels_max;
1202 runtime->hw.formats = hinfo->formats;
1203 runtime->hw.rates = hinfo->rates;
1205 snd_pcm_hw_constraint_step(substream->runtime, 0,
1206 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
1213 static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1214 struct hda_codec *codec,
1215 struct snd_pcm_substream *substream)
1217 struct hdmi_spec *spec = codec->spec;
1218 struct snd_pcm_runtime *runtime = substream->runtime;
1219 int pin_idx, cvt_idx, pcm_idx;
1220 struct hdmi_spec_per_pin *per_pin;
1221 struct hdmi_eld *eld;
1222 struct hdmi_spec_per_cvt *per_cvt = NULL;
1225 /* Validate hinfo */
1226 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1230 mutex_lock(&spec->pcm_lock);
1231 pin_idx = hinfo_to_pin_index(codec, hinfo);
1232 if (!spec->dyn_pcm_assign) {
1233 if (snd_BUG_ON(pin_idx < 0)) {
1238 /* no pin is assigned to the PCM
1239 * PA need pcm open successfully when probe
1242 err = hdmi_pcm_open_no_pin(hinfo, codec, substream);
1247 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx);
1251 per_cvt = get_cvt(spec, cvt_idx);
1252 /* Claim converter */
1253 per_cvt->assigned = 1;
1255 set_bit(pcm_idx, &spec->pcm_in_use);
1256 per_pin = get_pin(spec, pin_idx);
1257 per_pin->cvt_nid = per_cvt->cvt_nid;
1258 hinfo->nid = per_cvt->cvt_nid;
1260 /* flip stripe flag for the assigned stream if supported */
1261 if (get_wcaps(codec, per_cvt->cvt_nid) & AC_WCAP_STRIPE)
1262 azx_stream(get_azx_dev(substream))->stripe = 1;
1264 snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id);
1265 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1266 AC_VERB_SET_CONNECT_SEL,
1269 /* configure unused pins to choose other converters */
1270 pin_cvt_fixup(codec, per_pin, 0);
1272 snd_hda_spdif_ctls_assign(codec, pcm_idx, per_cvt->cvt_nid);
1274 /* Initially set the converter's capabilities */
1275 hinfo->channels_min = per_cvt->channels_min;
1276 hinfo->channels_max = per_cvt->channels_max;
1277 hinfo->rates = per_cvt->rates;
1278 hinfo->formats = per_cvt->formats;
1279 hinfo->maxbps = per_cvt->maxbps;
1281 eld = &per_pin->sink_eld;
1282 /* Restrict capabilities by ELD if this isn't disabled */
1283 if (!static_hdmi_pcm && eld->eld_valid) {
1284 snd_hdmi_eld_update_pcm_info(&eld->info, hinfo);
1285 if (hinfo->channels_min > hinfo->channels_max ||
1286 !hinfo->rates || !hinfo->formats) {
1287 per_cvt->assigned = 0;
1289 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
1295 /* Store the updated parameters */
1296 runtime->hw.channels_min = hinfo->channels_min;
1297 runtime->hw.channels_max = hinfo->channels_max;
1298 runtime->hw.formats = hinfo->formats;
1299 runtime->hw.rates = hinfo->rates;
1301 snd_pcm_hw_constraint_step(substream->runtime, 0,
1302 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
1304 mutex_unlock(&spec->pcm_lock);
1309 * HDA/HDMI auto parsing
1311 static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
1313 struct hdmi_spec *spec = codec->spec;
1314 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1315 hda_nid_t pin_nid = per_pin->pin_nid;
1316 int dev_id = per_pin->dev_id;
1319 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
1321 "HDMI: pin NID 0x%x wcaps %#x does not support connection list\n",
1322 pin_nid, get_wcaps(codec, pin_nid));
1326 snd_hda_set_dev_select(codec, pin_nid, dev_id);
1328 if (spec->intel_hsw_fixup) {
1329 conns = spec->num_cvts;
1330 memcpy(per_pin->mux_nids, spec->cvt_nids,
1331 sizeof(hda_nid_t) * conns);
1333 conns = snd_hda_get_raw_connections(codec, pin_nid,
1335 HDA_MAX_CONNECTIONS);
1338 /* all the device entries on the same pin have the same conn list */
1339 per_pin->num_mux_nids = conns;
1344 static int hdmi_find_pcm_slot(struct hdmi_spec *spec,
1345 struct hdmi_spec_per_pin *per_pin)
1349 /* on the new machines, try to assign the pcm slot dynamically,
1350 * not use the preferred fixed map (legacy way) anymore.
1352 if (spec->dyn_pcm_no_legacy)
1356 * generic_hdmi_build_pcms() may allocate extra PCMs on some
1357 * platforms (with maximum of 'num_nids + dev_num - 1')
1359 * The per_pin of pin_nid_idx=n and dev_id=m prefers to get pcm-n
1360 * if m==0. This guarantees that dynamic pcm assignments are compatible
1361 * with the legacy static per_pin-pcm assignment that existed in the
1362 * days before DP-MST.
1364 * Intel DP-MST prefers this legacy behavior for compatibility, too.
1366 * per_pin of m!=0 prefers to get pcm=(num_nids + (m - 1)).
1369 if (per_pin->dev_id == 0 || spec->intel_hsw_fixup) {
1370 if (!test_bit(per_pin->pin_nid_idx, &spec->pcm_bitmap))
1371 return per_pin->pin_nid_idx;
1373 i = spec->num_nids + (per_pin->dev_id - 1);
1374 if (i < spec->pcm_used && !(test_bit(i, &spec->pcm_bitmap)))
1378 /* have a second try; check the area over num_nids */
1379 for (i = spec->num_nids; i < spec->pcm_used; i++) {
1380 if (!test_bit(i, &spec->pcm_bitmap))
1385 /* the last try; check the empty slots in pins */
1386 for (i = 0; i < spec->num_nids; i++) {
1387 if (!test_bit(i, &spec->pcm_bitmap))
1393 static void hdmi_attach_hda_pcm(struct hdmi_spec *spec,
1394 struct hdmi_spec_per_pin *per_pin)
1398 /* pcm already be attached to the pin */
1401 idx = hdmi_find_pcm_slot(spec, per_pin);
1404 per_pin->pcm_idx = idx;
1405 per_pin->pcm = get_hdmi_pcm(spec, idx);
1406 set_bit(idx, &spec->pcm_bitmap);
1409 static void hdmi_detach_hda_pcm(struct hdmi_spec *spec,
1410 struct hdmi_spec_per_pin *per_pin)
1414 /* pcm already be detached from the pin */
1417 idx = per_pin->pcm_idx;
1418 per_pin->pcm_idx = -1;
1419 per_pin->pcm = NULL;
1420 if (idx >= 0 && idx < spec->pcm_used)
1421 clear_bit(idx, &spec->pcm_bitmap);
1424 static int hdmi_get_pin_cvt_mux(struct hdmi_spec *spec,
1425 struct hdmi_spec_per_pin *per_pin, hda_nid_t cvt_nid)
1429 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
1430 if (per_pin->mux_nids[mux_idx] == cvt_nid)
1435 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid);
1437 static void hdmi_pcm_setup_pin(struct hdmi_spec *spec,
1438 struct hdmi_spec_per_pin *per_pin)
1440 struct hda_codec *codec = per_pin->codec;
1441 struct hda_pcm *pcm;
1442 struct hda_pcm_stream *hinfo;
1443 struct snd_pcm_substream *substream;
1447 if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
1448 pcm = get_pcm_rec(spec, per_pin->pcm_idx);
1453 if (!test_bit(per_pin->pcm_idx, &spec->pcm_in_use))
1456 /* hdmi audio only uses playback and one substream */
1457 hinfo = pcm->stream;
1458 substream = pcm->pcm->streams[0].substream;
1460 per_pin->cvt_nid = hinfo->nid;
1462 mux_idx = hdmi_get_pin_cvt_mux(spec, per_pin, hinfo->nid);
1463 if (mux_idx < per_pin->num_mux_nids) {
1464 snd_hda_set_dev_select(codec, per_pin->pin_nid,
1466 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1467 AC_VERB_SET_CONNECT_SEL,
1470 snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid);
1472 non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid);
1473 if (substream->runtime)
1474 per_pin->channels = substream->runtime->channels;
1475 per_pin->setup = true;
1476 per_pin->mux_idx = mux_idx;
1478 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
1481 static void hdmi_pcm_reset_pin(struct hdmi_spec *spec,
1482 struct hdmi_spec_per_pin *per_pin)
1484 if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
1485 snd_hda_spdif_ctls_unassign(per_pin->codec, per_pin->pcm_idx);
1487 per_pin->chmap_set = false;
1488 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
1490 per_pin->setup = false;
1491 per_pin->channels = 0;
1494 static struct snd_jack *pin_idx_to_pcm_jack(struct hda_codec *codec,
1495 struct hdmi_spec_per_pin *per_pin)
1497 struct hdmi_spec *spec = codec->spec;
1499 if (per_pin->pcm_idx >= 0)
1500 return spec->pcm_rec[per_pin->pcm_idx].jack;
1505 /* update per_pin ELD from the given new ELD;
1506 * setup info frame and notification accordingly
1507 * also notify ELD kctl and report jack status changes
1509 static void update_eld(struct hda_codec *codec,
1510 struct hdmi_spec_per_pin *per_pin,
1511 struct hdmi_eld *eld,
1514 struct hdmi_eld *pin_eld = &per_pin->sink_eld;
1515 struct hdmi_spec *spec = codec->spec;
1516 struct snd_jack *pcm_jack;
1517 bool old_eld_valid = pin_eld->eld_valid;
1521 if (eld->eld_valid) {
1522 if (eld->eld_size <= 0 ||
1523 snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer,
1524 eld->eld_size) < 0) {
1525 eld->eld_valid = false;
1527 schedule_delayed_work(&per_pin->work,
1528 msecs_to_jiffies(300));
1534 if (!eld->eld_valid || eld->eld_size <= 0) {
1535 eld->eld_valid = false;
1539 /* for monitor disconnection, save pcm_idx firstly */
1540 pcm_idx = per_pin->pcm_idx;
1543 * pcm_idx >=0 before update_eld() means it is in monitor
1544 * disconnected event. Jack must be fetched before update_eld().
1546 pcm_jack = pin_idx_to_pcm_jack(codec, per_pin);
1548 if (spec->dyn_pcm_assign) {
1549 if (eld->eld_valid) {
1550 hdmi_attach_hda_pcm(spec, per_pin);
1551 hdmi_pcm_setup_pin(spec, per_pin);
1553 hdmi_pcm_reset_pin(spec, per_pin);
1554 hdmi_detach_hda_pcm(spec, per_pin);
1557 /* if pcm_idx == -1, it means this is in monitor connection event
1558 * we can get the correct pcm_idx now.
1561 pcm_idx = per_pin->pcm_idx;
1563 pcm_jack = pin_idx_to_pcm_jack(codec, per_pin);
1566 snd_hdmi_show_eld(codec, &eld->info);
1568 eld_changed = (pin_eld->eld_valid != eld->eld_valid);
1569 eld_changed |= (pin_eld->monitor_present != eld->monitor_present);
1570 if (!eld_changed && eld->eld_valid && pin_eld->eld_valid)
1571 if (pin_eld->eld_size != eld->eld_size ||
1572 memcmp(pin_eld->eld_buffer, eld->eld_buffer,
1573 eld->eld_size) != 0)
1577 pin_eld->monitor_present = eld->monitor_present;
1578 pin_eld->eld_valid = eld->eld_valid;
1579 pin_eld->eld_size = eld->eld_size;
1581 memcpy(pin_eld->eld_buffer, eld->eld_buffer,
1583 pin_eld->info = eld->info;
1587 * Re-setup pin and infoframe. This is needed e.g. when
1588 * - sink is first plugged-in
1589 * - transcoder can change during stream playback on Haswell
1590 * and this can make HW reset converter selection on a pin.
1592 if (eld->eld_valid && !old_eld_valid && per_pin->setup) {
1593 pin_cvt_fixup(codec, per_pin, 0);
1594 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1597 if (eld_changed && pcm_idx >= 0)
1598 snd_ctl_notify(codec->card,
1599 SNDRV_CTL_EVENT_MASK_VALUE |
1600 SNDRV_CTL_EVENT_MASK_INFO,
1601 &get_hdmi_pcm(spec, pcm_idx)->eld_ctl->id);
1603 if (eld_changed && pcm_jack)
1604 snd_jack_report(pcm_jack,
1605 (eld->monitor_present && eld->eld_valid) ?
1606 SND_JACK_AVOUT : 0);
1609 /* update ELD and jack state via HD-audio verbs */
1610 static void hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin,
1613 struct hda_codec *codec = per_pin->codec;
1614 struct hdmi_spec *spec = codec->spec;
1615 struct hdmi_eld *eld = &spec->temp_eld;
1616 hda_nid_t pin_nid = per_pin->pin_nid;
1617 int dev_id = per_pin->dev_id;
1619 * Always execute a GetPinSense verb here, even when called from
1620 * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
1621 * response's PD bit is not the real PD value, but indicates that
1622 * the real PD value changed. An older version of the HD-audio
1623 * specification worked this way. Hence, we just ignore the data in
1624 * the unsolicited response to avoid custom WARs.
1629 ret = snd_hda_power_up_pm(codec);
1630 if (ret < 0 && pm_runtime_suspended(hda_codec_dev(codec)))
1633 present = snd_hda_jack_pin_sense(codec, pin_nid, dev_id);
1635 mutex_lock(&per_pin->lock);
1636 eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
1637 if (eld->monitor_present)
1638 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
1640 eld->eld_valid = false;
1643 "HDMI status: Codec=%d NID=0x%x Presence_Detect=%d ELD_Valid=%d\n",
1644 codec->addr, pin_nid, eld->monitor_present, eld->eld_valid);
1646 if (eld->eld_valid) {
1647 if (spec->ops.pin_get_eld(codec, pin_nid, dev_id,
1648 eld->eld_buffer, &eld->eld_size) < 0)
1649 eld->eld_valid = false;
1652 update_eld(codec, per_pin, eld, repoll);
1653 mutex_unlock(&per_pin->lock);
1655 snd_hda_power_down_pm(codec);
1658 #define I915_SILENT_RATE 48000
1659 #define I915_SILENT_CHANNELS 2
1660 #define I915_SILENT_FORMAT SNDRV_PCM_FORMAT_S16_LE
1661 #define I915_SILENT_FORMAT_BITS 16
1662 #define I915_SILENT_FMT_MASK 0xf
1664 static void silent_stream_enable(struct hda_codec *codec,
1665 struct hdmi_spec_per_pin *per_pin)
1667 struct hdmi_spec *spec = codec->spec;
1668 struct hdmi_spec_per_cvt *per_cvt;
1669 int cvt_idx, pin_idx, err;
1670 unsigned int format;
1672 mutex_lock(&per_pin->lock);
1674 if (per_pin->setup) {
1675 codec_dbg(codec, "hdmi: PCM already open, no silent stream\n");
1679 pin_idx = pin_id_to_pin_index(codec, per_pin->pin_nid, per_pin->dev_id);
1680 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx);
1682 codec_err(codec, "hdmi: no free converter to enable silent mode\n");
1686 per_cvt = get_cvt(spec, cvt_idx);
1687 per_cvt->assigned = 1;
1688 per_pin->cvt_nid = per_cvt->cvt_nid;
1689 per_pin->silent_stream = true;
1691 codec_dbg(codec, "hdmi: enabling silent stream pin-NID=0x%x cvt-NID=0x%x\n",
1692 per_pin->pin_nid, per_cvt->cvt_nid);
1694 snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id);
1695 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1696 AC_VERB_SET_CONNECT_SEL,
1699 /* configure unused pins to choose other converters */
1700 pin_cvt_fixup(codec, per_pin, 0);
1702 snd_hdac_sync_audio_rate(&codec->core, per_pin->pin_nid,
1703 per_pin->dev_id, I915_SILENT_RATE);
1705 /* trigger silent stream generation in hw */
1706 format = snd_hdac_calc_stream_format(I915_SILENT_RATE, I915_SILENT_CHANNELS,
1707 I915_SILENT_FORMAT, I915_SILENT_FORMAT_BITS, 0);
1708 snd_hda_codec_setup_stream(codec, per_pin->cvt_nid,
1709 I915_SILENT_FMT_MASK, I915_SILENT_FMT_MASK, format);
1710 usleep_range(100, 200);
1711 snd_hda_codec_setup_stream(codec, per_pin->cvt_nid, I915_SILENT_FMT_MASK, 0, format);
1713 per_pin->channels = I915_SILENT_CHANNELS;
1714 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1717 mutex_unlock(&per_pin->lock);
1720 static void silent_stream_disable(struct hda_codec *codec,
1721 struct hdmi_spec_per_pin *per_pin)
1723 struct hdmi_spec *spec = codec->spec;
1724 struct hdmi_spec_per_cvt *per_cvt;
1727 mutex_lock(&per_pin->lock);
1728 if (!per_pin->silent_stream)
1731 codec_dbg(codec, "HDMI: disable silent stream on pin-NID=0x%x cvt-NID=0x%x\n",
1732 per_pin->pin_nid, per_pin->cvt_nid);
1734 cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid);
1735 if (cvt_idx >= 0 && cvt_idx < spec->num_cvts) {
1736 per_cvt = get_cvt(spec, cvt_idx);
1737 per_cvt->assigned = 0;
1740 per_pin->cvt_nid = 0;
1741 per_pin->silent_stream = false;
1744 mutex_unlock(&per_pin->lock);
1747 /* update ELD and jack state via audio component */
1748 static void sync_eld_via_acomp(struct hda_codec *codec,
1749 struct hdmi_spec_per_pin *per_pin)
1751 struct hdmi_spec *spec = codec->spec;
1752 struct hdmi_eld *eld = &spec->temp_eld;
1753 bool monitor_prev, monitor_next;
1755 mutex_lock(&per_pin->lock);
1756 eld->monitor_present = false;
1757 monitor_prev = per_pin->sink_eld.monitor_present;
1758 eld->eld_size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid,
1759 per_pin->dev_id, &eld->monitor_present,
1760 eld->eld_buffer, ELD_MAX_SIZE);
1761 eld->eld_valid = (eld->eld_size > 0);
1762 update_eld(codec, per_pin, eld, 0);
1763 monitor_next = per_pin->sink_eld.monitor_present;
1764 mutex_unlock(&per_pin->lock);
1767 * Power-up will call hdmi_present_sense, so the PM calls
1768 * have to be done without mutex held.
1771 if (spec->send_silent_stream) {
1774 if (!monitor_prev && monitor_next) {
1775 pm_ret = snd_hda_power_up_pm(codec);
1778 "Monitor plugged-in, Failed to power up codec ret=[%d]\n",
1780 silent_stream_enable(codec, per_pin);
1781 } else if (monitor_prev && !monitor_next) {
1782 silent_stream_disable(codec, per_pin);
1783 pm_ret = snd_hda_power_down_pm(codec);
1786 "Monitor plugged-out, Failed to power down codec ret=[%d]\n",
1792 static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1794 struct hda_codec *codec = per_pin->codec;
1796 if (!codec_has_acomp(codec))
1797 hdmi_present_sense_via_verbs(per_pin, repoll);
1799 sync_eld_via_acomp(codec, per_pin);
1802 static void hdmi_repoll_eld(struct work_struct *work)
1804 struct hdmi_spec_per_pin *per_pin =
1805 container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
1806 struct hda_codec *codec = per_pin->codec;
1807 struct hdmi_spec *spec = codec->spec;
1808 struct hda_jack_tbl *jack;
1810 jack = snd_hda_jack_tbl_get_mst(codec, per_pin->pin_nid,
1813 jack->jack_dirty = 1;
1815 if (per_pin->repoll_count++ > 6)
1816 per_pin->repoll_count = 0;
1818 mutex_lock(&spec->pcm_lock);
1819 hdmi_present_sense(per_pin, per_pin->repoll_count);
1820 mutex_unlock(&spec->pcm_lock);
1823 static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1825 struct hdmi_spec *spec = codec->spec;
1826 unsigned int caps, config;
1828 struct hdmi_spec_per_pin *per_pin;
1832 caps = snd_hda_query_pin_caps(codec, pin_nid);
1833 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
1837 * For DP MST audio, Configuration Default is the same for
1838 * all device entries on the same pin
1840 config = snd_hda_codec_get_pincfg(codec, pin_nid);
1841 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE &&
1842 !spec->force_connect)
1846 * To simplify the implementation, malloc all
1847 * the virtual pins in the initialization statically
1849 if (spec->intel_hsw_fixup) {
1851 * On Intel platforms, device entries count returned
1852 * by AC_PAR_DEVLIST_LEN is dynamic, and depends on
1853 * the type of receiver that is connected. Allocate pin
1854 * structures based on worst case.
1856 dev_num = spec->dev_num;
1857 } else if (spec->dyn_pcm_assign && codec->dp_mst) {
1858 dev_num = snd_hda_get_num_devices(codec, pin_nid) + 1;
1860 * spec->dev_num is the maxinum number of device entries
1861 * among all the pins
1863 spec->dev_num = (spec->dev_num > dev_num) ?
1864 spec->dev_num : dev_num;
1867 * If the platform doesn't support DP MST,
1868 * manually set dev_num to 1. This means
1869 * the pin has only one device entry.
1875 for (i = 0; i < dev_num; i++) {
1876 pin_idx = spec->num_pins;
1877 per_pin = snd_array_new(&spec->pins);
1882 if (spec->dyn_pcm_assign) {
1883 per_pin->pcm = NULL;
1884 per_pin->pcm_idx = -1;
1886 per_pin->pcm = get_hdmi_pcm(spec, pin_idx);
1887 per_pin->pcm_idx = pin_idx;
1889 per_pin->pin_nid = pin_nid;
1890 per_pin->pin_nid_idx = spec->num_nids;
1891 per_pin->dev_id = i;
1892 per_pin->non_pcm = false;
1893 snd_hda_set_dev_select(codec, pin_nid, i);
1894 err = hdmi_read_pin_conn(codec, pin_idx);
1904 static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1906 struct hdmi_spec *spec = codec->spec;
1907 struct hdmi_spec_per_cvt *per_cvt;
1911 chans = get_wcaps(codec, cvt_nid);
1912 chans = get_wcaps_channels(chans);
1914 per_cvt = snd_array_new(&spec->cvts);
1918 per_cvt->cvt_nid = cvt_nid;
1919 per_cvt->channels_min = 2;
1921 per_cvt->channels_max = chans;
1922 if (chans > spec->chmap.channels_max)
1923 spec->chmap.channels_max = chans;
1926 err = snd_hda_query_supported_pcm(codec, cvt_nid,
1933 if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids))
1934 spec->cvt_nids[spec->num_cvts] = cvt_nid;
1940 static const struct snd_pci_quirk force_connect_list[] = {
1941 SND_PCI_QUIRK(0x103c, 0x870f, "HP", 1),
1942 SND_PCI_QUIRK(0x103c, 0x871a, "HP", 1),
1946 static int hdmi_parse_codec(struct hda_codec *codec)
1948 struct hdmi_spec *spec = codec->spec;
1949 hda_nid_t start_nid;
1952 const struct snd_pci_quirk *q;
1954 nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &start_nid);
1955 if (!start_nid || nodes < 0) {
1956 codec_warn(codec, "HDMI: failed to get afg sub nodes\n");
1960 q = snd_pci_quirk_lookup(codec->bus->pci, force_connect_list);
1963 spec->force_connect = true;
1966 * hdmi_add_pin() assumes total amount of converters to
1967 * be known, so first discover all converters
1969 for (i = 0; i < nodes; i++) {
1970 hda_nid_t nid = start_nid + i;
1972 caps = get_wcaps(codec, nid);
1974 if (!(caps & AC_WCAP_DIGITAL))
1977 if (get_wcaps_type(caps) == AC_WID_AUD_OUT)
1978 hdmi_add_cvt(codec, nid);
1981 /* discover audio pins */
1982 for (i = 0; i < nodes; i++) {
1983 hda_nid_t nid = start_nid + i;
1985 caps = get_wcaps(codec, nid);
1987 if (!(caps & AC_WCAP_DIGITAL))
1990 if (get_wcaps_type(caps) == AC_WID_PIN)
1991 hdmi_add_pin(codec, nid);
1999 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
2001 struct hda_spdif_out *spdif;
2004 mutex_lock(&codec->spdif_mutex);
2005 spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
2006 /* Add sanity check to pass klockwork check.
2007 * This should never happen.
2009 if (WARN_ON(spdif == NULL)) {
2010 mutex_unlock(&codec->spdif_mutex);
2013 non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO);
2014 mutex_unlock(&codec->spdif_mutex);
2022 static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2023 struct hda_codec *codec,
2024 unsigned int stream_tag,
2025 unsigned int format,
2026 struct snd_pcm_substream *substream)
2028 hda_nid_t cvt_nid = hinfo->nid;
2029 struct hdmi_spec *spec = codec->spec;
2031 struct hdmi_spec_per_pin *per_pin;
2032 struct snd_pcm_runtime *runtime = substream->runtime;
2037 mutex_lock(&spec->pcm_lock);
2038 pin_idx = hinfo_to_pin_index(codec, hinfo);
2039 if (spec->dyn_pcm_assign && pin_idx < 0) {
2040 /* when dyn_pcm_assign and pcm is not bound to a pin
2041 * skip pin setup and return 0 to make audio playback
2044 pin_cvt_fixup(codec, NULL, cvt_nid);
2045 snd_hda_codec_setup_stream(codec, cvt_nid,
2046 stream_tag, 0, format);
2050 if (snd_BUG_ON(pin_idx < 0)) {
2054 per_pin = get_pin(spec, pin_idx);
2056 /* Verify pin:cvt selections to avoid silent audio after S3.
2057 * After S3, the audio driver restores pin:cvt selections
2058 * but this can happen before gfx is ready and such selection
2059 * is overlooked by HW. Thus multiple pins can share a same
2060 * default convertor and mute control will affect each other,
2061 * which can cause a resumed audio playback become silent
2064 pin_cvt_fixup(codec, per_pin, 0);
2066 /* Call sync_audio_rate to set the N/CTS/M manually if necessary */
2067 /* Todo: add DP1.2 MST audio support later */
2068 if (codec_has_acomp(codec))
2069 snd_hdac_sync_audio_rate(&codec->core, per_pin->pin_nid,
2070 per_pin->dev_id, runtime->rate);
2072 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
2073 mutex_lock(&per_pin->lock);
2074 per_pin->channels = substream->runtime->channels;
2075 per_pin->setup = true;
2077 if (get_wcaps(codec, cvt_nid) & AC_WCAP_STRIPE) {
2078 stripe = snd_hdac_get_stream_stripe_ctl(&codec->bus->core,
2080 snd_hda_codec_write(codec, cvt_nid, 0,
2081 AC_VERB_SET_STRIPE_CONTROL,
2085 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
2086 mutex_unlock(&per_pin->lock);
2087 if (spec->dyn_pin_out) {
2088 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2090 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
2091 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2092 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
2093 AC_VERB_SET_PIN_WIDGET_CONTROL,
2097 /* snd_hda_set_dev_select() has been called before */
2098 err = spec->ops.setup_stream(codec, cvt_nid, per_pin->pin_nid,
2099 per_pin->dev_id, stream_tag, format);
2101 mutex_unlock(&spec->pcm_lock);
2105 static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2106 struct hda_codec *codec,
2107 struct snd_pcm_substream *substream)
2109 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
2113 static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
2114 struct hda_codec *codec,
2115 struct snd_pcm_substream *substream)
2117 struct hdmi_spec *spec = codec->spec;
2118 int cvt_idx, pin_idx, pcm_idx;
2119 struct hdmi_spec_per_cvt *per_cvt;
2120 struct hdmi_spec_per_pin *per_pin;
2124 mutex_lock(&spec->pcm_lock);
2126 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
2127 if (snd_BUG_ON(pcm_idx < 0)) {
2131 cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid);
2132 if (snd_BUG_ON(cvt_idx < 0)) {
2136 per_cvt = get_cvt(spec, cvt_idx);
2137 per_cvt->assigned = 0;
2140 azx_stream(get_azx_dev(substream))->stripe = 0;
2142 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
2143 clear_bit(pcm_idx, &spec->pcm_in_use);
2144 pin_idx = hinfo_to_pin_index(codec, hinfo);
2145 if (spec->dyn_pcm_assign && pin_idx < 0)
2148 if (snd_BUG_ON(pin_idx < 0)) {
2152 per_pin = get_pin(spec, pin_idx);
2154 if (spec->dyn_pin_out) {
2155 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2157 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
2158 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2159 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
2160 AC_VERB_SET_PIN_WIDGET_CONTROL,
2164 mutex_lock(&per_pin->lock);
2165 per_pin->chmap_set = false;
2166 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
2168 per_pin->setup = false;
2169 per_pin->channels = 0;
2170 mutex_unlock(&per_pin->lock);
2174 mutex_unlock(&spec->pcm_lock);
2179 static const struct hda_pcm_ops generic_ops = {
2180 .open = hdmi_pcm_open,
2181 .close = hdmi_pcm_close,
2182 .prepare = generic_hdmi_playback_pcm_prepare,
2183 .cleanup = generic_hdmi_playback_pcm_cleanup,
2186 static int hdmi_get_spk_alloc(struct hdac_device *hdac, int pcm_idx)
2188 struct hda_codec *codec = hdac_to_hda_codec(hdac);
2189 struct hdmi_spec *spec = codec->spec;
2190 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2195 return per_pin->sink_eld.info.spk_alloc;
2198 static void hdmi_get_chmap(struct hdac_device *hdac, int pcm_idx,
2199 unsigned char *chmap)
2201 struct hda_codec *codec = hdac_to_hda_codec(hdac);
2202 struct hdmi_spec *spec = codec->spec;
2203 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2205 /* chmap is already set to 0 in caller */
2209 memcpy(chmap, per_pin->chmap, ARRAY_SIZE(per_pin->chmap));
2212 static void hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx,
2213 unsigned char *chmap, int prepared)
2215 struct hda_codec *codec = hdac_to_hda_codec(hdac);
2216 struct hdmi_spec *spec = codec->spec;
2217 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2221 mutex_lock(&per_pin->lock);
2222 per_pin->chmap_set = true;
2223 memcpy(per_pin->chmap, chmap, ARRAY_SIZE(per_pin->chmap));
2225 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
2226 mutex_unlock(&per_pin->lock);
2229 static bool is_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx)
2231 struct hda_codec *codec = hdac_to_hda_codec(hdac);
2232 struct hdmi_spec *spec = codec->spec;
2233 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2235 return per_pin ? true:false;
2238 static int generic_hdmi_build_pcms(struct hda_codec *codec)
2240 struct hdmi_spec *spec = codec->spec;
2244 * for non-mst mode, pcm number is the same as before
2245 * for DP MST mode without extra PCM, pcm number is same
2246 * for DP MST mode with extra PCMs, pcm number is
2247 * (nid number + dev_num - 1)
2248 * dev_num is the device entry number in a pin
2251 if (codec->mst_no_extra_pcms)
2252 pcm_num = spec->num_nids;
2254 pcm_num = spec->num_nids + spec->dev_num - 1;
2256 codec_dbg(codec, "hdmi: pcm_num set to %d\n", pcm_num);
2258 for (idx = 0; idx < pcm_num; idx++) {
2259 struct hda_pcm *info;
2260 struct hda_pcm_stream *pstr;
2262 info = snd_hda_codec_pcm_new(codec, "HDMI %d", idx);
2266 spec->pcm_rec[idx].pcm = info;
2268 info->pcm_type = HDA_PCM_TYPE_HDMI;
2269 info->own_chmap = true;
2271 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
2272 pstr->substreams = 1;
2273 pstr->ops = generic_ops;
2274 /* pcm number is less than 16 */
2275 if (spec->pcm_used >= 16)
2277 /* other pstr fields are set in open */
2283 static void free_hdmi_jack_priv(struct snd_jack *jack)
2285 struct hdmi_pcm *pcm = jack->private_data;
2290 static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx)
2292 char hdmi_str[32] = "HDMI/DP";
2293 struct hdmi_spec *spec = codec->spec;
2294 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pcm_idx);
2295 struct snd_jack *jack;
2296 int pcmdev = get_pcm_rec(spec, pcm_idx)->device;
2300 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
2301 if (!spec->dyn_pcm_assign &&
2302 !is_jack_detectable(codec, per_pin->pin_nid))
2303 strncat(hdmi_str, " Phantom",
2304 sizeof(hdmi_str) - strlen(hdmi_str) - 1);
2306 err = snd_jack_new(codec->card, hdmi_str, SND_JACK_AVOUT, &jack,
2311 spec->pcm_rec[pcm_idx].jack = jack;
2312 jack->private_data = &spec->pcm_rec[pcm_idx];
2313 jack->private_free = free_hdmi_jack_priv;
2317 static int generic_hdmi_build_controls(struct hda_codec *codec)
2319 struct hdmi_spec *spec = codec->spec;
2321 int pin_idx, pcm_idx;
2323 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2324 if (!get_pcm_rec(spec, pcm_idx)->pcm) {
2325 /* no PCM: mark this for skipping permanently */
2326 set_bit(pcm_idx, &spec->pcm_bitmap);
2330 err = generic_hdmi_build_jack(codec, pcm_idx);
2334 /* create the spdif for each pcm
2335 * pin will be bound when monitor is connected
2337 if (spec->dyn_pcm_assign)
2338 err = snd_hda_create_dig_out_ctls(codec,
2339 0, spec->cvt_nids[0],
2342 struct hdmi_spec_per_pin *per_pin =
2343 get_pin(spec, pcm_idx);
2344 err = snd_hda_create_dig_out_ctls(codec,
2346 per_pin->mux_nids[0],
2351 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
2353 dev = get_pcm_rec(spec, pcm_idx)->device;
2354 if (dev != SNDRV_PCM_INVALID_DEVICE) {
2355 /* add control for ELD Bytes */
2356 err = hdmi_create_eld_ctl(codec, pcm_idx, dev);
2362 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2363 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2364 struct hdmi_eld *pin_eld = &per_pin->sink_eld;
2366 pin_eld->eld_valid = false;
2367 hdmi_present_sense(per_pin, 0);
2370 /* add channel maps */
2371 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2372 struct hda_pcm *pcm;
2374 pcm = get_pcm_rec(spec, pcm_idx);
2375 if (!pcm || !pcm->pcm)
2377 err = snd_hdac_add_chmap_ctls(pcm->pcm, pcm_idx, &spec->chmap);
2385 static int generic_hdmi_init_per_pins(struct hda_codec *codec)
2387 struct hdmi_spec *spec = codec->spec;
2390 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2391 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2393 per_pin->codec = codec;
2394 mutex_init(&per_pin->lock);
2395 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
2396 eld_proc_new(per_pin, pin_idx);
2401 static int generic_hdmi_init(struct hda_codec *codec)
2403 struct hdmi_spec *spec = codec->spec;
2406 mutex_lock(&spec->bind_lock);
2407 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2408 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2409 hda_nid_t pin_nid = per_pin->pin_nid;
2410 int dev_id = per_pin->dev_id;
2412 snd_hda_set_dev_select(codec, pin_nid, dev_id);
2413 hdmi_init_pin(codec, pin_nid);
2414 if (codec_has_acomp(codec))
2416 snd_hda_jack_detect_enable_callback_mst(codec, pin_nid, dev_id,
2419 mutex_unlock(&spec->bind_lock);
2423 static void hdmi_array_init(struct hdmi_spec *spec, int nums)
2425 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums);
2426 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums);
2429 static void hdmi_array_free(struct hdmi_spec *spec)
2431 snd_array_free(&spec->pins);
2432 snd_array_free(&spec->cvts);
2435 static void generic_spec_free(struct hda_codec *codec)
2437 struct hdmi_spec *spec = codec->spec;
2440 hdmi_array_free(spec);
2444 codec->dp_mst = false;
2447 static void generic_hdmi_free(struct hda_codec *codec)
2449 struct hdmi_spec *spec = codec->spec;
2450 int pin_idx, pcm_idx;
2452 if (spec->acomp_registered) {
2453 snd_hdac_acomp_exit(&codec->bus->core);
2454 } else if (codec_has_acomp(codec)) {
2455 snd_hdac_acomp_register_notifier(&codec->bus->core, NULL);
2457 codec->relaxed_resume = 0;
2459 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2460 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2461 cancel_delayed_work_sync(&per_pin->work);
2462 eld_proc_free(per_pin);
2465 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2466 if (spec->pcm_rec[pcm_idx].jack == NULL)
2468 if (spec->dyn_pcm_assign)
2469 snd_device_free(codec->card,
2470 spec->pcm_rec[pcm_idx].jack);
2472 spec->pcm_rec[pcm_idx].jack = NULL;
2475 generic_spec_free(codec);
2479 static int generic_hdmi_suspend(struct hda_codec *codec)
2481 struct hdmi_spec *spec = codec->spec;
2484 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2485 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2486 cancel_delayed_work_sync(&per_pin->work);
2491 static int generic_hdmi_resume(struct hda_codec *codec)
2493 struct hdmi_spec *spec = codec->spec;
2496 codec->patch_ops.init(codec);
2497 snd_hda_regmap_sync(codec);
2499 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2500 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2501 hdmi_present_sense(per_pin, 1);
2507 static const struct hda_codec_ops generic_hdmi_patch_ops = {
2508 .init = generic_hdmi_init,
2509 .free = generic_hdmi_free,
2510 .build_pcms = generic_hdmi_build_pcms,
2511 .build_controls = generic_hdmi_build_controls,
2512 .unsol_event = hdmi_unsol_event,
2514 .suspend = generic_hdmi_suspend,
2515 .resume = generic_hdmi_resume,
2519 static const struct hdmi_ops generic_standard_hdmi_ops = {
2520 .pin_get_eld = hdmi_pin_get_eld,
2521 .pin_setup_infoframe = hdmi_pin_setup_infoframe,
2522 .pin_hbr_setup = hdmi_pin_hbr_setup,
2523 .setup_stream = hdmi_setup_stream,
2526 /* allocate codec->spec and assign/initialize generic parser ops */
2527 static int alloc_generic_hdmi(struct hda_codec *codec)
2529 struct hdmi_spec *spec;
2531 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2535 spec->codec = codec;
2536 spec->ops = generic_standard_hdmi_ops;
2537 spec->dev_num = 1; /* initialize to 1 */
2538 mutex_init(&spec->pcm_lock);
2539 mutex_init(&spec->bind_lock);
2540 snd_hdac_register_chmap_ops(&codec->core, &spec->chmap);
2542 spec->chmap.ops.get_chmap = hdmi_get_chmap;
2543 spec->chmap.ops.set_chmap = hdmi_set_chmap;
2544 spec->chmap.ops.is_pcm_attached = is_hdmi_pcm_attached;
2545 spec->chmap.ops.get_spk_alloc = hdmi_get_spk_alloc;
2548 hdmi_array_init(spec, 4);
2550 codec->patch_ops = generic_hdmi_patch_ops;
2555 /* generic HDMI parser */
2556 static int patch_generic_hdmi(struct hda_codec *codec)
2560 err = alloc_generic_hdmi(codec);
2564 err = hdmi_parse_codec(codec);
2566 generic_spec_free(codec);
2570 generic_hdmi_init_per_pins(codec);
2575 * generic audio component binding
2578 /* turn on / off the unsol event jack detection dynamically */
2579 static void reprogram_jack_detect(struct hda_codec *codec, hda_nid_t nid,
2580 int dev_id, bool use_acomp)
2582 struct hda_jack_tbl *tbl;
2584 tbl = snd_hda_jack_tbl_get_mst(codec, nid, dev_id);
2586 /* clear unsol even if component notifier is used, or re-enable
2587 * if notifier is cleared
2589 unsigned int val = use_acomp ? 0 : (AC_USRSP_EN | tbl->tag);
2590 snd_hda_codec_write_cache(codec, nid, 0,
2591 AC_VERB_SET_UNSOLICITED_ENABLE, val);
2595 /* set up / clear component notifier dynamically */
2596 static void generic_acomp_notifier_set(struct drm_audio_component *acomp,
2599 struct hdmi_spec *spec;
2602 spec = container_of(acomp->audio_ops, struct hdmi_spec, drm_audio_ops);
2603 mutex_lock(&spec->bind_lock);
2604 spec->use_acomp_notifier = use_acomp;
2605 spec->codec->relaxed_resume = use_acomp;
2606 spec->codec->bus->keep_power = 0;
2607 /* reprogram each jack detection logic depending on the notifier */
2608 for (i = 0; i < spec->num_pins; i++)
2609 reprogram_jack_detect(spec->codec,
2610 get_pin(spec, i)->pin_nid,
2611 get_pin(spec, i)->dev_id,
2613 mutex_unlock(&spec->bind_lock);
2616 /* enable / disable the notifier via master bind / unbind */
2617 static int generic_acomp_master_bind(struct device *dev,
2618 struct drm_audio_component *acomp)
2620 generic_acomp_notifier_set(acomp, true);
2624 static void generic_acomp_master_unbind(struct device *dev,
2625 struct drm_audio_component *acomp)
2627 generic_acomp_notifier_set(acomp, false);
2630 /* check whether both HD-audio and DRM PCI devices belong to the same bus */
2631 static int match_bound_vga(struct device *dev, int subtype, void *data)
2633 struct hdac_bus *bus = data;
2634 struct pci_dev *pci, *master;
2636 if (!dev_is_pci(dev) || !dev_is_pci(bus->dev))
2638 master = to_pci_dev(bus->dev);
2639 pci = to_pci_dev(dev);
2640 return master->bus == pci->bus;
2643 /* audio component notifier for AMD/Nvidia HDMI codecs */
2644 static void generic_acomp_pin_eld_notify(void *audio_ptr, int port, int dev_id)
2646 struct hda_codec *codec = audio_ptr;
2647 struct hdmi_spec *spec = codec->spec;
2648 hda_nid_t pin_nid = spec->port2pin(codec, port);
2652 if (get_wcaps_type(get_wcaps(codec, pin_nid)) != AC_WID_PIN)
2654 /* skip notification during system suspend (but not in runtime PM);
2655 * the state will be updated at resume
2657 if (codec->core.dev.power.power_state.event == PM_EVENT_SUSPEND)
2659 /* ditto during suspend/resume process itself */
2660 if (snd_hdac_is_in_pm(&codec->core))
2663 check_presence_and_report(codec, pin_nid, dev_id);
2666 /* set up the private drm_audio_ops from the template */
2667 static void setup_drm_audio_ops(struct hda_codec *codec,
2668 const struct drm_audio_component_audio_ops *ops)
2670 struct hdmi_spec *spec = codec->spec;
2672 spec->drm_audio_ops.audio_ptr = codec;
2673 /* intel_audio_codec_enable() or intel_audio_codec_disable()
2674 * will call pin_eld_notify with using audio_ptr pointer
2675 * We need make sure audio_ptr is really setup
2678 spec->drm_audio_ops.pin2port = ops->pin2port;
2679 spec->drm_audio_ops.pin_eld_notify = ops->pin_eld_notify;
2680 spec->drm_audio_ops.master_bind = ops->master_bind;
2681 spec->drm_audio_ops.master_unbind = ops->master_unbind;
2684 /* initialize the generic HDMI audio component */
2685 static void generic_acomp_init(struct hda_codec *codec,
2686 const struct drm_audio_component_audio_ops *ops,
2687 int (*port2pin)(struct hda_codec *, int))
2689 struct hdmi_spec *spec = codec->spec;
2691 if (!enable_acomp) {
2692 codec_info(codec, "audio component disabled by module option\n");
2696 spec->port2pin = port2pin;
2697 setup_drm_audio_ops(codec, ops);
2698 if (!snd_hdac_acomp_init(&codec->bus->core, &spec->drm_audio_ops,
2699 match_bound_vga, 0)) {
2700 spec->acomp_registered = true;
2705 * Intel codec parsers and helpers
2708 #define INTEL_GET_VENDOR_VERB 0xf81
2709 #define INTEL_SET_VENDOR_VERB 0x781
2710 #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
2711 #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
2713 static void intel_haswell_enable_all_pins(struct hda_codec *codec,
2716 unsigned int vendor_param;
2717 struct hdmi_spec *spec = codec->spec;
2719 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2720 INTEL_GET_VENDOR_VERB, 0);
2721 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
2724 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
2725 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2726 INTEL_SET_VENDOR_VERB, vendor_param);
2727 if (vendor_param == -1)
2731 snd_hda_codec_update_widgets(codec);
2734 static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
2736 unsigned int vendor_param;
2737 struct hdmi_spec *spec = codec->spec;
2739 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2740 INTEL_GET_VENDOR_VERB, 0);
2741 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
2744 /* enable DP1.2 mode */
2745 vendor_param |= INTEL_EN_DP12;
2746 snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB);
2747 snd_hda_codec_write_cache(codec, spec->vendor_nid, 0,
2748 INTEL_SET_VENDOR_VERB, vendor_param);
2751 /* Haswell needs to re-issue the vendor-specific verbs before turning to D0.
2752 * Otherwise you may get severe h/w communication errors.
2754 static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2755 unsigned int power_state)
2757 if (power_state == AC_PWRST_D0) {
2758 intel_haswell_enable_all_pins(codec, false);
2759 intel_haswell_fixup_enable_dp12(codec);
2762 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
2763 snd_hda_codec_set_power_to_all(codec, fg, power_state);
2766 /* There is a fixed mapping between audio pin node and display port.
2767 * on SNB, IVY, HSW, BSW, SKL, BXT, KBL:
2768 * Pin Widget 5 - PORT B (port = 1 in i915 driver)
2769 * Pin Widget 6 - PORT C (port = 2 in i915 driver)
2770 * Pin Widget 7 - PORT D (port = 3 in i915 driver)
2773 * Pin Widget 4 - PORT B (port = 1 in i915 driver)
2774 * Pin Widget 5 - PORT C (port = 2 in i915 driver)
2775 * Pin Widget 6 - PORT D (port = 3 in i915 driver)
2777 static int intel_base_nid(struct hda_codec *codec)
2779 switch (codec->core.vendor_id) {
2780 case 0x80860054: /* ILK */
2781 case 0x80862804: /* ILK */
2782 case 0x80862882: /* VLV */
2789 static int intel_pin2port(void *audio_ptr, int pin_nid)
2791 struct hda_codec *codec = audio_ptr;
2792 struct hdmi_spec *spec = codec->spec;
2795 if (!spec->port_num) {
2796 base_nid = intel_base_nid(codec);
2797 if (WARN_ON(pin_nid < base_nid || pin_nid >= base_nid + 3))
2799 return pin_nid - base_nid + 1;
2803 * looking for the pin number in the mapping table and return
2804 * the index which indicate the port number
2806 for (i = 0; i < spec->port_num; i++) {
2807 if (pin_nid == spec->port_map[i])
2811 codec_info(codec, "Can't find the HDMI/DP port for pin NID 0x%x\n", pin_nid);
2815 static int intel_port2pin(struct hda_codec *codec, int port)
2817 struct hdmi_spec *spec = codec->spec;
2819 if (!spec->port_num) {
2820 /* we assume only from port-B to port-D */
2821 if (port < 1 || port > 3)
2823 return port + intel_base_nid(codec) - 1;
2826 if (port < 0 || port >= spec->port_num)
2828 return spec->port_map[port];
2831 static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe)
2833 struct hda_codec *codec = audio_ptr;
2837 pin_nid = intel_port2pin(codec, port);
2840 /* skip notification during system suspend (but not in runtime PM);
2841 * the state will be updated at resume
2843 if (codec->core.dev.power.power_state.event == PM_EVENT_SUSPEND)
2845 /* ditto during suspend/resume process itself */
2846 if (snd_hdac_is_in_pm(&codec->core))
2849 snd_hdac_i915_set_bclk(&codec->bus->core);
2850 check_presence_and_report(codec, pin_nid, dev_id);
2853 static const struct drm_audio_component_audio_ops intel_audio_ops = {
2854 .pin2port = intel_pin2port,
2855 .pin_eld_notify = intel_pin_eld_notify,
2858 /* register i915 component pin_eld_notify callback */
2859 static void register_i915_notifier(struct hda_codec *codec)
2861 struct hdmi_spec *spec = codec->spec;
2863 spec->use_acomp_notifier = true;
2864 spec->port2pin = intel_port2pin;
2865 setup_drm_audio_ops(codec, &intel_audio_ops);
2866 snd_hdac_acomp_register_notifier(&codec->bus->core,
2867 &spec->drm_audio_ops);
2868 /* no need for forcible resume for jack check thanks to notifier */
2869 codec->relaxed_resume = 1;
2872 /* setup_stream ops override for HSW+ */
2873 static int i915_hsw_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
2874 hda_nid_t pin_nid, int dev_id, u32 stream_tag,
2877 haswell_verify_D0(codec, cvt_nid, pin_nid);
2878 return hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id,
2879 stream_tag, format);
2882 /* pin_cvt_fixup ops override for HSW+ and VLV+ */
2883 static void i915_pin_cvt_fixup(struct hda_codec *codec,
2884 struct hdmi_spec_per_pin *per_pin,
2888 haswell_verify_D0(codec, per_pin->cvt_nid, per_pin->pin_nid);
2889 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2891 intel_verify_pin_cvt_connect(codec, per_pin);
2892 intel_not_share_assigned_cvt(codec, per_pin->pin_nid,
2893 per_pin->dev_id, per_pin->mux_idx);
2895 intel_not_share_assigned_cvt_nid(codec, 0, 0, cvt_nid);
2899 /* precondition and allocation for Intel codecs */
2900 static int alloc_intel_hdmi(struct hda_codec *codec)
2904 /* requires i915 binding */
2905 if (!codec->bus->core.audio_component) {
2906 codec_info(codec, "No i915 binding for Intel HDMI/DP codec\n");
2907 /* set probe_id here to prevent generic fallback binding */
2908 codec->probe_id = HDA_CODEC_ID_SKIP_PROBE;
2912 err = alloc_generic_hdmi(codec);
2915 /* no need to handle unsol events */
2916 codec->patch_ops.unsol_event = NULL;
2920 /* parse and post-process for Intel codecs */
2921 static int parse_intel_hdmi(struct hda_codec *codec)
2923 int err, retries = 3;
2926 err = hdmi_parse_codec(codec);
2927 } while (err < 0 && retries--);
2930 generic_spec_free(codec);
2934 generic_hdmi_init_per_pins(codec);
2935 register_i915_notifier(codec);
2939 /* Intel Haswell and onwards; audio component with eld notifier */
2940 static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid,
2941 const int *port_map, int port_num, int dev_num)
2943 struct hdmi_spec *spec;
2946 err = alloc_intel_hdmi(codec);
2950 codec->dp_mst = true;
2951 spec->dyn_pcm_assign = true;
2952 spec->vendor_nid = vendor_nid;
2953 spec->port_map = port_map;
2954 spec->port_num = port_num;
2955 spec->intel_hsw_fixup = true;
2956 spec->dev_num = dev_num;
2958 intel_haswell_enable_all_pins(codec, true);
2959 intel_haswell_fixup_enable_dp12(codec);
2961 codec->display_power_control = 1;
2963 codec->patch_ops.set_power_state = haswell_set_power_state;
2964 codec->depop_delay = 0;
2965 codec->auto_runtime_pm = 1;
2967 spec->ops.setup_stream = i915_hsw_setup_stream;
2968 spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup;
2971 * Enable silent stream feature, if it is enabled via
2972 * module param or Kconfig option
2974 if (enable_silent_stream)
2975 spec->send_silent_stream = true;
2977 return parse_intel_hdmi(codec);
2980 static int patch_i915_hsw_hdmi(struct hda_codec *codec)
2982 return intel_hsw_common_init(codec, 0x08, NULL, 0, 3);
2985 static int patch_i915_glk_hdmi(struct hda_codec *codec)
2987 return intel_hsw_common_init(codec, 0x0b, NULL, 0, 3);
2990 static int patch_i915_icl_hdmi(struct hda_codec *codec)
2993 * pin to port mapping table where the value indicate the pin number and
2994 * the index indicate the port number.
2996 static const int map[] = {0x0, 0x4, 0x6, 0x8, 0xa, 0xb};
2998 return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map), 3);
3001 static int patch_i915_tgl_hdmi(struct hda_codec *codec)
3004 * pin to port mapping table where the value indicate the pin number and
3005 * the index indicate the port number.
3007 static const int map[] = {0x4, 0x6, 0x8, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
3010 ret = intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map), 4);
3012 struct hdmi_spec *spec = codec->spec;
3014 spec->dyn_pcm_no_legacy = true;
3020 /* Intel Baytrail and Braswell; with eld notifier */
3021 static int patch_i915_byt_hdmi(struct hda_codec *codec)
3023 struct hdmi_spec *spec;
3026 err = alloc_intel_hdmi(codec);
3031 /* For Valleyview/Cherryview, only the display codec is in the display
3032 * power well and can use link_power ops to request/release the power.
3034 codec->display_power_control = 1;
3036 codec->depop_delay = 0;
3037 codec->auto_runtime_pm = 1;
3039 spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup;
3041 return parse_intel_hdmi(codec);
3044 /* Intel IronLake, SandyBridge and IvyBridge; with eld notifier */
3045 static int patch_i915_cpt_hdmi(struct hda_codec *codec)
3049 err = alloc_intel_hdmi(codec);
3052 return parse_intel_hdmi(codec);
3056 * Shared non-generic implementations
3059 static int simple_playback_build_pcms(struct hda_codec *codec)
3061 struct hdmi_spec *spec = codec->spec;
3062 struct hda_pcm *info;
3064 struct hda_pcm_stream *pstr;
3065 struct hdmi_spec_per_cvt *per_cvt;
3067 per_cvt = get_cvt(spec, 0);
3068 chans = get_wcaps(codec, per_cvt->cvt_nid);
3069 chans = get_wcaps_channels(chans);
3071 info = snd_hda_codec_pcm_new(codec, "HDMI 0");
3074 spec->pcm_rec[0].pcm = info;
3075 info->pcm_type = HDA_PCM_TYPE_HDMI;
3076 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
3077 *pstr = spec->pcm_playback;
3078 pstr->nid = per_cvt->cvt_nid;
3079 if (pstr->channels_max <= 2 && chans && chans <= 16)
3080 pstr->channels_max = chans;
3085 /* unsolicited event for jack sensing */
3086 static void simple_hdmi_unsol_event(struct hda_codec *codec,
3089 snd_hda_jack_set_dirty_all(codec);
3090 snd_hda_jack_report_sync(codec);
3093 /* generic_hdmi_build_jack can be used for simple_hdmi, too,
3094 * as long as spec->pins[] is set correctly
3096 #define simple_hdmi_build_jack generic_hdmi_build_jack
3098 static int simple_playback_build_controls(struct hda_codec *codec)
3100 struct hdmi_spec *spec = codec->spec;
3101 struct hdmi_spec_per_cvt *per_cvt;
3104 per_cvt = get_cvt(spec, 0);
3105 err = snd_hda_create_dig_out_ctls(codec, per_cvt->cvt_nid,
3110 return simple_hdmi_build_jack(codec, 0);
3113 static int simple_playback_init(struct hda_codec *codec)
3115 struct hdmi_spec *spec = codec->spec;
3116 struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0);
3117 hda_nid_t pin = per_pin->pin_nid;
3119 snd_hda_codec_write(codec, pin, 0,
3120 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3121 /* some codecs require to unmute the pin */
3122 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
3123 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3125 snd_hda_jack_detect_enable(codec, pin, per_pin->dev_id);
3129 static void simple_playback_free(struct hda_codec *codec)
3131 struct hdmi_spec *spec = codec->spec;
3133 hdmi_array_free(spec);
3138 * Nvidia specific implementations
3141 #define Nv_VERB_SET_Channel_Allocation 0xF79
3142 #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
3143 #define Nv_VERB_SET_Audio_Protection_On 0xF98
3144 #define Nv_VERB_SET_Audio_Protection_Off 0xF99
3146 #define nvhdmi_master_con_nid_7x 0x04
3147 #define nvhdmi_master_pin_nid_7x 0x05
3149 static const hda_nid_t nvhdmi_con_nids_7x[4] = {
3150 /*front, rear, clfe, rear_surr */
3154 static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = {
3155 /* set audio protect on */
3156 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
3157 /* enable digital output on pin widget */
3158 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3162 static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = {
3163 /* set audio protect on */
3164 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
3165 /* enable digital output on pin widget */
3166 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3167 { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3168 { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3169 { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3170 { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3174 #ifdef LIMITED_RATE_FMT_SUPPORT
3175 /* support only the safe format and rate */
3176 #define SUPPORTED_RATES SNDRV_PCM_RATE_48000
3177 #define SUPPORTED_MAXBPS 16
3178 #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
3180 /* support all rates and formats */
3181 #define SUPPORTED_RATES \
3182 (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
3183 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
3184 SNDRV_PCM_RATE_192000)
3185 #define SUPPORTED_MAXBPS 24
3186 #define SUPPORTED_FORMATS \
3187 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
3190 static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
3192 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
3196 static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
3198 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
3202 static const unsigned int channels_2_6_8[] = {
3206 static const unsigned int channels_2_8[] = {
3210 static const struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
3211 .count = ARRAY_SIZE(channels_2_6_8),
3212 .list = channels_2_6_8,
3216 static const struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
3217 .count = ARRAY_SIZE(channels_2_8),
3218 .list = channels_2_8,
3222 static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
3223 struct hda_codec *codec,
3224 struct snd_pcm_substream *substream)
3226 struct hdmi_spec *spec = codec->spec;
3227 const struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
3229 switch (codec->preset->vendor_id) {
3234 hw_constraints_channels = &hw_constraints_2_8_channels;
3237 hw_constraints_channels = &hw_constraints_2_6_8_channels;
3243 if (hw_constraints_channels != NULL) {
3244 snd_pcm_hw_constraint_list(substream->runtime, 0,
3245 SNDRV_PCM_HW_PARAM_CHANNELS,
3246 hw_constraints_channels);
3248 snd_pcm_hw_constraint_step(substream->runtime, 0,
3249 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
3252 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3255 static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
3256 struct hda_codec *codec,
3257 struct snd_pcm_substream *substream)
3259 struct hdmi_spec *spec = codec->spec;
3260 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3263 static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3264 struct hda_codec *codec,
3265 unsigned int stream_tag,
3266 unsigned int format,
3267 struct snd_pcm_substream *substream)
3269 struct hdmi_spec *spec = codec->spec;
3270 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3271 stream_tag, format, substream);
3274 static const struct hda_pcm_stream simple_pcm_playback = {
3279 .open = simple_playback_pcm_open,
3280 .close = simple_playback_pcm_close,
3281 .prepare = simple_playback_pcm_prepare
3285 static const struct hda_codec_ops simple_hdmi_patch_ops = {
3286 .build_controls = simple_playback_build_controls,
3287 .build_pcms = simple_playback_build_pcms,
3288 .init = simple_playback_init,
3289 .free = simple_playback_free,
3290 .unsol_event = simple_hdmi_unsol_event,
3293 static int patch_simple_hdmi(struct hda_codec *codec,
3294 hda_nid_t cvt_nid, hda_nid_t pin_nid)
3296 struct hdmi_spec *spec;
3297 struct hdmi_spec_per_cvt *per_cvt;
3298 struct hdmi_spec_per_pin *per_pin;
3300 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3304 spec->codec = codec;
3306 hdmi_array_init(spec, 1);
3308 spec->multiout.num_dacs = 0; /* no analog */
3309 spec->multiout.max_channels = 2;
3310 spec->multiout.dig_out_nid = cvt_nid;
3313 per_pin = snd_array_new(&spec->pins);
3314 per_cvt = snd_array_new(&spec->cvts);
3315 if (!per_pin || !per_cvt) {
3316 simple_playback_free(codec);
3319 per_cvt->cvt_nid = cvt_nid;
3320 per_pin->pin_nid = pin_nid;
3321 spec->pcm_playback = simple_pcm_playback;
3323 codec->patch_ops = simple_hdmi_patch_ops;
3328 static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
3331 unsigned int chanmask;
3332 int chan = channels ? (channels - 1) : 1;
3351 /* Set the audio infoframe channel allocation and checksum fields. The
3352 * channel count is computed implicitly by the hardware. */
3353 snd_hda_codec_write(codec, 0x1, 0,
3354 Nv_VERB_SET_Channel_Allocation, chanmask);
3356 snd_hda_codec_write(codec, 0x1, 0,
3357 Nv_VERB_SET_Info_Frame_Checksum,
3358 (0x71 - chan - chanmask));
3361 static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
3362 struct hda_codec *codec,
3363 struct snd_pcm_substream *substream)
3365 struct hdmi_spec *spec = codec->spec;
3368 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
3369 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
3370 for (i = 0; i < 4; i++) {
3371 /* set the stream id */
3372 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
3373 AC_VERB_SET_CHANNEL_STREAMID, 0);
3374 /* set the stream format */
3375 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
3376 AC_VERB_SET_STREAM_FORMAT, 0);
3379 /* The audio hardware sends a channel count of 0x7 (8ch) when all the
3380 * streams are disabled. */
3381 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
3383 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3386 static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
3387 struct hda_codec *codec,
3388 unsigned int stream_tag,
3389 unsigned int format,
3390 struct snd_pcm_substream *substream)
3393 unsigned int dataDCC2, channel_id;
3395 struct hdmi_spec *spec = codec->spec;
3396 struct hda_spdif_out *spdif;
3397 struct hdmi_spec_per_cvt *per_cvt;
3399 mutex_lock(&codec->spdif_mutex);
3400 per_cvt = get_cvt(spec, 0);
3401 spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid);
3403 chs = substream->runtime->channels;
3407 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
3408 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
3409 snd_hda_codec_write(codec,
3410 nvhdmi_master_con_nid_7x,
3412 AC_VERB_SET_DIGI_CONVERT_1,
3413 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
3415 /* set the stream id */
3416 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
3417 AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
3419 /* set the stream format */
3420 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
3421 AC_VERB_SET_STREAM_FORMAT, format);
3423 /* turn on again (if needed) */
3424 /* enable and set the channel status audio/data flag */
3425 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
3426 snd_hda_codec_write(codec,
3427 nvhdmi_master_con_nid_7x,
3429 AC_VERB_SET_DIGI_CONVERT_1,
3430 spdif->ctls & 0xff);
3431 snd_hda_codec_write(codec,
3432 nvhdmi_master_con_nid_7x,
3434 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
3437 for (i = 0; i < 4; i++) {
3443 /* turn off SPDIF once;
3444 *otherwise the IEC958 bits won't be updated
3446 if (codec->spdif_status_reset &&
3447 (spdif->ctls & AC_DIG1_ENABLE))
3448 snd_hda_codec_write(codec,
3449 nvhdmi_con_nids_7x[i],
3451 AC_VERB_SET_DIGI_CONVERT_1,
3452 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
3453 /* set the stream id */
3454 snd_hda_codec_write(codec,
3455 nvhdmi_con_nids_7x[i],
3457 AC_VERB_SET_CHANNEL_STREAMID,
3458 (stream_tag << 4) | channel_id);
3459 /* set the stream format */
3460 snd_hda_codec_write(codec,
3461 nvhdmi_con_nids_7x[i],
3463 AC_VERB_SET_STREAM_FORMAT,
3465 /* turn on again (if needed) */
3466 /* enable and set the channel status audio/data flag */
3467 if (codec->spdif_status_reset &&
3468 (spdif->ctls & AC_DIG1_ENABLE)) {
3469 snd_hda_codec_write(codec,
3470 nvhdmi_con_nids_7x[i],
3472 AC_VERB_SET_DIGI_CONVERT_1,
3473 spdif->ctls & 0xff);
3474 snd_hda_codec_write(codec,
3475 nvhdmi_con_nids_7x[i],
3477 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
3481 nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
3483 mutex_unlock(&codec->spdif_mutex);
3487 static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
3491 .nid = nvhdmi_master_con_nid_7x,
3492 .rates = SUPPORTED_RATES,
3493 .maxbps = SUPPORTED_MAXBPS,
3494 .formats = SUPPORTED_FORMATS,
3496 .open = simple_playback_pcm_open,
3497 .close = nvhdmi_8ch_7x_pcm_close,
3498 .prepare = nvhdmi_8ch_7x_pcm_prepare
3502 static int patch_nvhdmi_2ch(struct hda_codec *codec)
3504 struct hdmi_spec *spec;
3505 int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
3506 nvhdmi_master_pin_nid_7x);
3510 codec->patch_ops.init = nvhdmi_7x_init_2ch;
3511 /* override the PCM rates, etc, as the codec doesn't give full list */
3513 spec->pcm_playback.rates = SUPPORTED_RATES;
3514 spec->pcm_playback.maxbps = SUPPORTED_MAXBPS;
3515 spec->pcm_playback.formats = SUPPORTED_FORMATS;
3519 static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
3521 struct hdmi_spec *spec = codec->spec;
3522 int err = simple_playback_build_pcms(codec);
3524 struct hda_pcm *info = get_pcm_rec(spec, 0);
3525 info->own_chmap = true;
3530 static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
3532 struct hdmi_spec *spec = codec->spec;
3533 struct hda_pcm *info;
3534 struct snd_pcm_chmap *chmap;
3537 err = simple_playback_build_controls(codec);
3541 /* add channel maps */
3542 info = get_pcm_rec(spec, 0);
3543 err = snd_pcm_add_chmap_ctls(info->pcm,
3544 SNDRV_PCM_STREAM_PLAYBACK,
3545 snd_pcm_alt_chmaps, 8, 0, &chmap);
3548 switch (codec->preset->vendor_id) {
3553 chmap->channel_mask = (1U << 2) | (1U << 8);
3556 chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8);
3561 static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
3563 struct hdmi_spec *spec;
3564 int err = patch_nvhdmi_2ch(codec);
3568 spec->multiout.max_channels = 8;
3569 spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x;
3570 codec->patch_ops.init = nvhdmi_7x_init_8ch;
3571 codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
3572 codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
3574 /* Initialize the audio infoframe channel mask and checksum to something
3576 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
3582 * NVIDIA codecs ignore ASP mapping for 2ch - confirmed on:
3586 static int nvhdmi_chmap_cea_alloc_validate_get_type(struct hdac_chmap *chmap,
3587 struct hdac_cea_channel_speaker_allocation *cap, int channels)
3589 if (cap->ca_index == 0x00 && channels == 2)
3590 return SNDRV_CTL_TLVT_CHMAP_FIXED;
3592 /* If the speaker allocation matches the channel count, it is OK. */
3593 if (cap->channels != channels)
3596 /* all channels are remappable freely */
3597 return SNDRV_CTL_TLVT_CHMAP_VAR;
3600 static int nvhdmi_chmap_validate(struct hdac_chmap *chmap,
3601 int ca, int chs, unsigned char *map)
3603 if (ca == 0x00 && (map[0] != SNDRV_CHMAP_FL || map[1] != SNDRV_CHMAP_FR))
3609 /* map from pin NID to port; port is 0-based */
3610 /* for Nvidia: assume widget NID starting from 4, with step 1 (4, 5, 6, ...) */
3611 static int nvhdmi_pin2port(void *audio_ptr, int pin_nid)
3616 /* reverse-map from port to pin NID: see above */
3617 static int nvhdmi_port2pin(struct hda_codec *codec, int port)
3622 static const struct drm_audio_component_audio_ops nvhdmi_audio_ops = {
3623 .pin2port = nvhdmi_pin2port,
3624 .pin_eld_notify = generic_acomp_pin_eld_notify,
3625 .master_bind = generic_acomp_master_bind,
3626 .master_unbind = generic_acomp_master_unbind,
3629 static int patch_nvhdmi(struct hda_codec *codec)
3631 struct hdmi_spec *spec;
3634 err = alloc_generic_hdmi(codec);
3637 codec->dp_mst = true;
3640 spec->dyn_pcm_assign = true;
3642 err = hdmi_parse_codec(codec);
3644 generic_spec_free(codec);
3648 generic_hdmi_init_per_pins(codec);
3650 spec->dyn_pin_out = true;
3652 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
3653 nvhdmi_chmap_cea_alloc_validate_get_type;
3654 spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate;
3656 codec->link_down_at_suspend = 1;
3658 generic_acomp_init(codec, &nvhdmi_audio_ops, nvhdmi_port2pin);
3663 static int patch_nvhdmi_legacy(struct hda_codec *codec)
3665 struct hdmi_spec *spec;
3668 err = patch_generic_hdmi(codec);
3673 spec->dyn_pin_out = true;
3675 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
3676 nvhdmi_chmap_cea_alloc_validate_get_type;
3677 spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate;
3679 codec->link_down_at_suspend = 1;
3685 * The HDA codec on NVIDIA Tegra contains two scratch registers that are
3686 * accessed using vendor-defined verbs. These registers can be used for
3687 * interoperability between the HDA and HDMI drivers.
3690 /* Audio Function Group node */
3691 #define NVIDIA_AFG_NID 0x01
3694 * The SCRATCH0 register is used to notify the HDMI codec of changes in audio
3695 * format. On Tegra, bit 31 is used as a trigger that causes an interrupt to
3696 * be raised in the HDMI codec. The remainder of the bits is arbitrary. This
3697 * implementation stores the HDA format (see AC_FMT_*) in bits [15:0] and an
3698 * additional bit (at position 30) to signal the validity of the format.
3700 * | 31 | 30 | 29 16 | 15 0 |
3701 * +---------+-------+--------+--------+
3702 * | TRIGGER | VALID | UNUSED | FORMAT |
3703 * +-----------------------------------|
3705 * Note that for the trigger bit to take effect it needs to change value
3706 * (i.e. it needs to be toggled).
3708 #define NVIDIA_GET_SCRATCH0 0xfa6
3709 #define NVIDIA_SET_SCRATCH0_BYTE0 0xfa7
3710 #define NVIDIA_SET_SCRATCH0_BYTE1 0xfa8
3711 #define NVIDIA_SET_SCRATCH0_BYTE2 0xfa9
3712 #define NVIDIA_SET_SCRATCH0_BYTE3 0xfaa
3713 #define NVIDIA_SCRATCH_TRIGGER (1 << 7)
3714 #define NVIDIA_SCRATCH_VALID (1 << 6)
3716 #define NVIDIA_GET_SCRATCH1 0xfab
3717 #define NVIDIA_SET_SCRATCH1_BYTE0 0xfac
3718 #define NVIDIA_SET_SCRATCH1_BYTE1 0xfad
3719 #define NVIDIA_SET_SCRATCH1_BYTE2 0xfae
3720 #define NVIDIA_SET_SCRATCH1_BYTE3 0xfaf
3723 * The format parameter is the HDA audio format (see AC_FMT_*). If set to 0,
3724 * the format is invalidated so that the HDMI codec can be disabled.
3726 static void tegra_hdmi_set_format(struct hda_codec *codec, unsigned int format)
3730 /* bits [31:30] contain the trigger and valid bits */
3731 value = snd_hda_codec_read(codec, NVIDIA_AFG_NID, 0,
3732 NVIDIA_GET_SCRATCH0, 0);
3733 value = (value >> 24) & 0xff;
3735 /* bits [15:0] are used to store the HDA format */
3736 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3737 NVIDIA_SET_SCRATCH0_BYTE0,
3738 (format >> 0) & 0xff);
3739 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3740 NVIDIA_SET_SCRATCH0_BYTE1,
3741 (format >> 8) & 0xff);
3743 /* bits [16:24] are unused */
3744 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3745 NVIDIA_SET_SCRATCH0_BYTE2, 0);
3748 * Bit 30 signals that the data is valid and hence that HDMI audio can
3752 value &= ~NVIDIA_SCRATCH_VALID;
3754 value |= NVIDIA_SCRATCH_VALID;
3757 * Whenever the trigger bit is toggled, an interrupt is raised in the
3758 * HDMI codec. The HDMI driver will use that as trigger to update its
3761 value ^= NVIDIA_SCRATCH_TRIGGER;
3763 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3764 NVIDIA_SET_SCRATCH0_BYTE3, value);
3767 static int tegra_hdmi_pcm_prepare(struct hda_pcm_stream *hinfo,
3768 struct hda_codec *codec,
3769 unsigned int stream_tag,
3770 unsigned int format,
3771 struct snd_pcm_substream *substream)
3775 err = generic_hdmi_playback_pcm_prepare(hinfo, codec, stream_tag,
3780 /* notify the HDMI codec of the format change */
3781 tegra_hdmi_set_format(codec, format);
3786 static int tegra_hdmi_pcm_cleanup(struct hda_pcm_stream *hinfo,
3787 struct hda_codec *codec,
3788 struct snd_pcm_substream *substream)
3790 /* invalidate the format in the HDMI codec */
3791 tegra_hdmi_set_format(codec, 0);
3793 return generic_hdmi_playback_pcm_cleanup(hinfo, codec, substream);
3796 static struct hda_pcm *hda_find_pcm_by_type(struct hda_codec *codec, int type)
3798 struct hdmi_spec *spec = codec->spec;
3801 for (i = 0; i < spec->num_pins; i++) {
3802 struct hda_pcm *pcm = get_pcm_rec(spec, i);
3804 if (pcm->pcm_type == type)
3811 static int tegra_hdmi_build_pcms(struct hda_codec *codec)
3813 struct hda_pcm_stream *stream;
3814 struct hda_pcm *pcm;
3817 err = generic_hdmi_build_pcms(codec);
3821 pcm = hda_find_pcm_by_type(codec, HDA_PCM_TYPE_HDMI);
3826 * Override ->prepare() and ->cleanup() operations to notify the HDMI
3827 * codec about format changes.
3829 stream = &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
3830 stream->ops.prepare = tegra_hdmi_pcm_prepare;
3831 stream->ops.cleanup = tegra_hdmi_pcm_cleanup;
3836 static int patch_tegra_hdmi(struct hda_codec *codec)
3838 struct hdmi_spec *spec;
3841 err = patch_generic_hdmi(codec);
3845 codec->patch_ops.build_pcms = tegra_hdmi_build_pcms;
3847 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
3848 nvhdmi_chmap_cea_alloc_validate_get_type;
3849 spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate;
3855 * ATI/AMD-specific implementations
3858 #define is_amdhdmi_rev3_or_later(codec) \
3859 ((codec)->core.vendor_id == 0x1002aa01 && \
3860 ((codec)->core.revision_id & 0xff00) >= 0x0300)
3861 #define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec)
3863 /* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */
3864 #define ATI_VERB_SET_CHANNEL_ALLOCATION 0x771
3865 #define ATI_VERB_SET_DOWNMIX_INFO 0x772
3866 #define ATI_VERB_SET_MULTICHANNEL_01 0x777
3867 #define ATI_VERB_SET_MULTICHANNEL_23 0x778
3868 #define ATI_VERB_SET_MULTICHANNEL_45 0x779
3869 #define ATI_VERB_SET_MULTICHANNEL_67 0x77a
3870 #define ATI_VERB_SET_HBR_CONTROL 0x77c
3871 #define ATI_VERB_SET_MULTICHANNEL_1 0x785
3872 #define ATI_VERB_SET_MULTICHANNEL_3 0x786
3873 #define ATI_VERB_SET_MULTICHANNEL_5 0x787
3874 #define ATI_VERB_SET_MULTICHANNEL_7 0x788
3875 #define ATI_VERB_SET_MULTICHANNEL_MODE 0x789
3876 #define ATI_VERB_GET_CHANNEL_ALLOCATION 0xf71
3877 #define ATI_VERB_GET_DOWNMIX_INFO 0xf72
3878 #define ATI_VERB_GET_MULTICHANNEL_01 0xf77
3879 #define ATI_VERB_GET_MULTICHANNEL_23 0xf78
3880 #define ATI_VERB_GET_MULTICHANNEL_45 0xf79
3881 #define ATI_VERB_GET_MULTICHANNEL_67 0xf7a
3882 #define ATI_VERB_GET_HBR_CONTROL 0xf7c
3883 #define ATI_VERB_GET_MULTICHANNEL_1 0xf85
3884 #define ATI_VERB_GET_MULTICHANNEL_3 0xf86
3885 #define ATI_VERB_GET_MULTICHANNEL_5 0xf87
3886 #define ATI_VERB_GET_MULTICHANNEL_7 0xf88
3887 #define ATI_VERB_GET_MULTICHANNEL_MODE 0xf89
3889 /* AMD specific HDA cvt verbs */
3890 #define ATI_VERB_SET_RAMP_RATE 0x770
3891 #define ATI_VERB_GET_RAMP_RATE 0xf70
3893 #define ATI_OUT_ENABLE 0x1
3895 #define ATI_MULTICHANNEL_MODE_PAIRED 0
3896 #define ATI_MULTICHANNEL_MODE_SINGLE 1
3898 #define ATI_HBR_CAPABLE 0x01
3899 #define ATI_HBR_ENABLE 0x10
3901 static int atihdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
3902 int dev_id, unsigned char *buf, int *eld_size)
3904 WARN_ON(dev_id != 0);
3905 /* call hda_eld.c ATI/AMD-specific function */
3906 return snd_hdmi_get_eld_ati(codec, nid, buf, eld_size,
3907 is_amdhdmi_rev3_or_later(codec));
3910 static void atihdmi_pin_setup_infoframe(struct hda_codec *codec,
3911 hda_nid_t pin_nid, int dev_id, int ca,
3912 int active_channels, int conn_type)
3914 WARN_ON(dev_id != 0);
3915 snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_CHANNEL_ALLOCATION, ca);
3918 static int atihdmi_paired_swap_fc_lfe(int pos)
3921 * ATI/AMD have automatic FC/LFE swap built-in
3922 * when in pairwise mapping mode.
3926 /* see channel_allocations[].speakers[] */
3935 static int atihdmi_paired_chmap_validate(struct hdac_chmap *chmap,
3936 int ca, int chs, unsigned char *map)
3938 struct hdac_cea_channel_speaker_allocation *cap;
3941 /* check that only channel pairs need to be remapped on old pre-rev3 ATI/AMD */
3943 cap = snd_hdac_get_ch_alloc_from_ca(ca);
3944 for (i = 0; i < chs; ++i) {
3945 int mask = snd_hdac_chmap_to_spk_mask(map[i]);
3947 bool companion_ok = false;
3952 for (j = 0 + i % 2; j < 8; j += 2) {
3953 int chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j);
3954 if (cap->speakers[chan_idx] == mask) {
3955 /* channel is in a supported position */
3958 if (i % 2 == 0 && i + 1 < chs) {
3959 /* even channel, check the odd companion */
3960 int comp_chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j + 1);
3961 int comp_mask_req = snd_hdac_chmap_to_spk_mask(map[i+1]);
3962 int comp_mask_act = cap->speakers[comp_chan_idx];
3964 if (comp_mask_req == comp_mask_act)
3965 companion_ok = true;
3977 i++; /* companion channel already checked */
3983 static int atihdmi_pin_set_slot_channel(struct hdac_device *hdac,
3984 hda_nid_t pin_nid, int hdmi_slot, int stream_channel)
3986 struct hda_codec *codec = hdac_to_hda_codec(hdac);
3988 int ati_channel_setup = 0;
3993 if (!has_amd_full_remap_support(codec)) {
3994 hdmi_slot = atihdmi_paired_swap_fc_lfe(hdmi_slot);
3996 /* In case this is an odd slot but without stream channel, do not
3997 * disable the slot since the corresponding even slot could have a
3998 * channel. In case neither have a channel, the slot pair will be
3999 * disabled when this function is called for the even slot. */
4000 if (hdmi_slot % 2 != 0 && stream_channel == 0xf)
4003 hdmi_slot -= hdmi_slot % 2;
4005 if (stream_channel != 0xf)
4006 stream_channel -= stream_channel % 2;
4009 verb = ATI_VERB_SET_MULTICHANNEL_01 + hdmi_slot/2 + (hdmi_slot % 2) * 0x00e;
4011 /* ati_channel_setup format: [7..4] = stream_channel_id, [1] = mute, [0] = enable */
4013 if (stream_channel != 0xf)
4014 ati_channel_setup = (stream_channel << 4) | ATI_OUT_ENABLE;
4016 return snd_hda_codec_write(codec, pin_nid, 0, verb, ati_channel_setup);
4019 static int atihdmi_pin_get_slot_channel(struct hdac_device *hdac,
4020 hda_nid_t pin_nid, int asp_slot)
4022 struct hda_codec *codec = hdac_to_hda_codec(hdac);
4023 bool was_odd = false;
4024 int ati_asp_slot = asp_slot;
4026 int ati_channel_setup;
4031 if (!has_amd_full_remap_support(codec)) {
4032 ati_asp_slot = atihdmi_paired_swap_fc_lfe(asp_slot);
4033 if (ati_asp_slot % 2 != 0) {
4039 verb = ATI_VERB_GET_MULTICHANNEL_01 + ati_asp_slot/2 + (ati_asp_slot % 2) * 0x00e;
4041 ati_channel_setup = snd_hda_codec_read(codec, pin_nid, 0, verb, 0);
4043 if (!(ati_channel_setup & ATI_OUT_ENABLE))
4046 return ((ati_channel_setup & 0xf0) >> 4) + !!was_odd;
4049 static int atihdmi_paired_chmap_cea_alloc_validate_get_type(
4050 struct hdac_chmap *chmap,
4051 struct hdac_cea_channel_speaker_allocation *cap,
4057 * Pre-rev3 ATI/AMD codecs operate in a paired channel mode, so
4058 * we need to take that into account (a single channel may take 2
4059 * channel slots if we need to carry a silent channel next to it).
4060 * On Rev3+ AMD codecs this function is not used.
4064 /* We only produce even-numbered channel count TLVs */
4065 if ((channels % 2) != 0)
4068 for (c = 0; c < 7; c += 2) {
4069 if (cap->speakers[c] || cap->speakers[c+1])
4073 if (chanpairs * 2 != channels)
4076 return SNDRV_CTL_TLVT_CHMAP_PAIRED;
4079 static void atihdmi_paired_cea_alloc_to_tlv_chmap(struct hdac_chmap *hchmap,
4080 struct hdac_cea_channel_speaker_allocation *cap,
4081 unsigned int *chmap, int channels)
4083 /* produce paired maps for pre-rev3 ATI/AMD codecs */
4087 for (c = 7; c >= 0; c--) {
4088 int chan = 7 - atihdmi_paired_swap_fc_lfe(7 - c);
4089 int spk = cap->speakers[chan];
4091 /* add N/A channel if the companion channel is occupied */
4092 if (cap->speakers[chan + (chan % 2 ? -1 : 1)])
4093 chmap[count++] = SNDRV_CHMAP_NA;
4098 chmap[count++] = snd_hdac_spk_to_chmap(spk);
4101 WARN_ON(count != channels);
4104 static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
4105 int dev_id, bool hbr)
4107 int hbr_ctl, hbr_ctl_new;
4109 WARN_ON(dev_id != 0);
4111 hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0);
4112 if (hbr_ctl >= 0 && (hbr_ctl & ATI_HBR_CAPABLE)) {
4114 hbr_ctl_new = hbr_ctl | ATI_HBR_ENABLE;
4116 hbr_ctl_new = hbr_ctl & ~ATI_HBR_ENABLE;
4119 "atihdmi_pin_hbr_setup: NID=0x%x, %shbr-ctl=0x%x\n",
4121 hbr_ctl == hbr_ctl_new ? "" : "new-",
4124 if (hbr_ctl != hbr_ctl_new)
4125 snd_hda_codec_write(codec, pin_nid, 0,
4126 ATI_VERB_SET_HBR_CONTROL,
4135 static int atihdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
4136 hda_nid_t pin_nid, int dev_id,
4137 u32 stream_tag, int format)
4139 if (is_amdhdmi_rev3_or_later(codec)) {
4140 int ramp_rate = 180; /* default as per AMD spec */
4141 /* disable ramp-up/down for non-pcm as per AMD spec */
4142 if (format & AC_FMT_TYPE_NON_PCM)
4145 snd_hda_codec_write(codec, cvt_nid, 0, ATI_VERB_SET_RAMP_RATE, ramp_rate);
4148 return hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id,
4149 stream_tag, format);
4153 static int atihdmi_init(struct hda_codec *codec)
4155 struct hdmi_spec *spec = codec->spec;
4158 err = generic_hdmi_init(codec);
4163 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
4164 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
4166 /* make sure downmix information in infoframe is zero */
4167 snd_hda_codec_write(codec, per_pin->pin_nid, 0, ATI_VERB_SET_DOWNMIX_INFO, 0);
4169 /* enable channel-wise remap mode if supported */
4170 if (has_amd_full_remap_support(codec))
4171 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
4172 ATI_VERB_SET_MULTICHANNEL_MODE,
4173 ATI_MULTICHANNEL_MODE_SINGLE);
4175 codec->auto_runtime_pm = 1;
4180 /* map from pin NID to port; port is 0-based */
4181 /* for AMD: assume widget NID starting from 3, with step 2 (3, 5, 7, ...) */
4182 static int atihdmi_pin2port(void *audio_ptr, int pin_nid)
4184 return pin_nid / 2 - 1;
4187 /* reverse-map from port to pin NID: see above */
4188 static int atihdmi_port2pin(struct hda_codec *codec, int port)
4190 return port * 2 + 3;
4193 static const struct drm_audio_component_audio_ops atihdmi_audio_ops = {
4194 .pin2port = atihdmi_pin2port,
4195 .pin_eld_notify = generic_acomp_pin_eld_notify,
4196 .master_bind = generic_acomp_master_bind,
4197 .master_unbind = generic_acomp_master_unbind,
4200 static int patch_atihdmi(struct hda_codec *codec)
4202 struct hdmi_spec *spec;
4203 struct hdmi_spec_per_cvt *per_cvt;
4206 err = patch_generic_hdmi(codec);
4211 codec->patch_ops.init = atihdmi_init;
4215 spec->ops.pin_get_eld = atihdmi_pin_get_eld;
4216 spec->ops.pin_setup_infoframe = atihdmi_pin_setup_infoframe;
4217 spec->ops.pin_hbr_setup = atihdmi_pin_hbr_setup;
4218 spec->ops.setup_stream = atihdmi_setup_stream;
4220 spec->chmap.ops.pin_get_slot_channel = atihdmi_pin_get_slot_channel;
4221 spec->chmap.ops.pin_set_slot_channel = atihdmi_pin_set_slot_channel;
4223 if (!has_amd_full_remap_support(codec)) {
4224 /* override to ATI/AMD-specific versions with pairwise mapping */
4225 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
4226 atihdmi_paired_chmap_cea_alloc_validate_get_type;
4227 spec->chmap.ops.cea_alloc_to_tlv_chmap =
4228 atihdmi_paired_cea_alloc_to_tlv_chmap;
4229 spec->chmap.ops.chmap_validate = atihdmi_paired_chmap_validate;
4232 /* ATI/AMD converters do not advertise all of their capabilities */
4233 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
4234 per_cvt = get_cvt(spec, cvt_idx);
4235 per_cvt->channels_max = max(per_cvt->channels_max, 8u);
4236 per_cvt->rates |= SUPPORTED_RATES;
4237 per_cvt->formats |= SUPPORTED_FORMATS;
4238 per_cvt->maxbps = max(per_cvt->maxbps, 24u);
4241 spec->chmap.channels_max = max(spec->chmap.channels_max, 8u);
4243 /* AMD GPUs have neither EPSS nor CLKSTOP bits, hence preventing
4244 * the link-down as is. Tell the core to allow it.
4246 codec->link_down_at_suspend = 1;
4248 generic_acomp_init(codec, &atihdmi_audio_ops, atihdmi_port2pin);
4253 /* VIA HDMI Implementation */
4254 #define VIAHDMI_CVT_NID 0x02 /* audio converter1 */
4255 #define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */
4257 static int patch_via_hdmi(struct hda_codec *codec)
4259 return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
4265 static const struct hda_device_id snd_hda_id_hdmi[] = {
4266 HDA_CODEC_ENTRY(0x1002793c, "RS600 HDMI", patch_atihdmi),
4267 HDA_CODEC_ENTRY(0x10027919, "RS600 HDMI", patch_atihdmi),
4268 HDA_CODEC_ENTRY(0x1002791a, "RS690/780 HDMI", patch_atihdmi),
4269 HDA_CODEC_ENTRY(0x1002aa01, "R6xx HDMI", patch_atihdmi),
4270 HDA_CODEC_ENTRY(0x10951390, "SiI1390 HDMI", patch_generic_hdmi),
4271 HDA_CODEC_ENTRY(0x10951392, "SiI1392 HDMI", patch_generic_hdmi),
4272 HDA_CODEC_ENTRY(0x17e80047, "Chrontel HDMI", patch_generic_hdmi),
4273 HDA_CODEC_ENTRY(0x10de0001, "MCP73 HDMI", patch_nvhdmi_2ch),
4274 HDA_CODEC_ENTRY(0x10de0002, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4275 HDA_CODEC_ENTRY(0x10de0003, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4276 HDA_CODEC_ENTRY(0x10de0004, "GPU 04 HDMI", patch_nvhdmi_8ch_7x),
4277 HDA_CODEC_ENTRY(0x10de0005, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4278 HDA_CODEC_ENTRY(0x10de0006, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4279 HDA_CODEC_ENTRY(0x10de0007, "MCP79/7A HDMI", patch_nvhdmi_8ch_7x),
4280 HDA_CODEC_ENTRY(0x10de0008, "GPU 08 HDMI/DP", patch_nvhdmi_legacy),
4281 HDA_CODEC_ENTRY(0x10de0009, "GPU 09 HDMI/DP", patch_nvhdmi_legacy),
4282 HDA_CODEC_ENTRY(0x10de000a, "GPU 0a HDMI/DP", patch_nvhdmi_legacy),
4283 HDA_CODEC_ENTRY(0x10de000b, "GPU 0b HDMI/DP", patch_nvhdmi_legacy),
4284 HDA_CODEC_ENTRY(0x10de000c, "MCP89 HDMI", patch_nvhdmi_legacy),
4285 HDA_CODEC_ENTRY(0x10de000d, "GPU 0d HDMI/DP", patch_nvhdmi_legacy),
4286 HDA_CODEC_ENTRY(0x10de0010, "GPU 10 HDMI/DP", patch_nvhdmi_legacy),
4287 HDA_CODEC_ENTRY(0x10de0011, "GPU 11 HDMI/DP", patch_nvhdmi_legacy),
4288 HDA_CODEC_ENTRY(0x10de0012, "GPU 12 HDMI/DP", patch_nvhdmi_legacy),
4289 HDA_CODEC_ENTRY(0x10de0013, "GPU 13 HDMI/DP", patch_nvhdmi_legacy),
4290 HDA_CODEC_ENTRY(0x10de0014, "GPU 14 HDMI/DP", patch_nvhdmi_legacy),
4291 HDA_CODEC_ENTRY(0x10de0015, "GPU 15 HDMI/DP", patch_nvhdmi_legacy),
4292 HDA_CODEC_ENTRY(0x10de0016, "GPU 16 HDMI/DP", patch_nvhdmi_legacy),
4293 /* 17 is known to be absent */
4294 HDA_CODEC_ENTRY(0x10de0018, "GPU 18 HDMI/DP", patch_nvhdmi_legacy),
4295 HDA_CODEC_ENTRY(0x10de0019, "GPU 19 HDMI/DP", patch_nvhdmi_legacy),
4296 HDA_CODEC_ENTRY(0x10de001a, "GPU 1a HDMI/DP", patch_nvhdmi_legacy),
4297 HDA_CODEC_ENTRY(0x10de001b, "GPU 1b HDMI/DP", patch_nvhdmi_legacy),
4298 HDA_CODEC_ENTRY(0x10de001c, "GPU 1c HDMI/DP", patch_nvhdmi_legacy),
4299 HDA_CODEC_ENTRY(0x10de0020, "Tegra30 HDMI", patch_tegra_hdmi),
4300 HDA_CODEC_ENTRY(0x10de0022, "Tegra114 HDMI", patch_tegra_hdmi),
4301 HDA_CODEC_ENTRY(0x10de0028, "Tegra124 HDMI", patch_tegra_hdmi),
4302 HDA_CODEC_ENTRY(0x10de0029, "Tegra210 HDMI/DP", patch_tegra_hdmi),
4303 HDA_CODEC_ENTRY(0x10de002d, "Tegra186 HDMI/DP0", patch_tegra_hdmi),
4304 HDA_CODEC_ENTRY(0x10de002e, "Tegra186 HDMI/DP1", patch_tegra_hdmi),
4305 HDA_CODEC_ENTRY(0x10de002f, "Tegra194 HDMI/DP2", patch_tegra_hdmi),
4306 HDA_CODEC_ENTRY(0x10de0030, "Tegra194 HDMI/DP3", patch_tegra_hdmi),
4307 HDA_CODEC_ENTRY(0x10de0040, "GPU 40 HDMI/DP", patch_nvhdmi),
4308 HDA_CODEC_ENTRY(0x10de0041, "GPU 41 HDMI/DP", patch_nvhdmi),
4309 HDA_CODEC_ENTRY(0x10de0042, "GPU 42 HDMI/DP", patch_nvhdmi),
4310 HDA_CODEC_ENTRY(0x10de0043, "GPU 43 HDMI/DP", patch_nvhdmi),
4311 HDA_CODEC_ENTRY(0x10de0044, "GPU 44 HDMI/DP", patch_nvhdmi),
4312 HDA_CODEC_ENTRY(0x10de0045, "GPU 45 HDMI/DP", patch_nvhdmi),
4313 HDA_CODEC_ENTRY(0x10de0050, "GPU 50 HDMI/DP", patch_nvhdmi),
4314 HDA_CODEC_ENTRY(0x10de0051, "GPU 51 HDMI/DP", patch_nvhdmi),
4315 HDA_CODEC_ENTRY(0x10de0052, "GPU 52 HDMI/DP", patch_nvhdmi),
4316 HDA_CODEC_ENTRY(0x10de0060, "GPU 60 HDMI/DP", patch_nvhdmi),
4317 HDA_CODEC_ENTRY(0x10de0061, "GPU 61 HDMI/DP", patch_nvhdmi),
4318 HDA_CODEC_ENTRY(0x10de0062, "GPU 62 HDMI/DP", patch_nvhdmi),
4319 HDA_CODEC_ENTRY(0x10de0067, "MCP67 HDMI", patch_nvhdmi_2ch),
4320 HDA_CODEC_ENTRY(0x10de0070, "GPU 70 HDMI/DP", patch_nvhdmi),
4321 HDA_CODEC_ENTRY(0x10de0071, "GPU 71 HDMI/DP", patch_nvhdmi),
4322 HDA_CODEC_ENTRY(0x10de0072, "GPU 72 HDMI/DP", patch_nvhdmi),
4323 HDA_CODEC_ENTRY(0x10de0073, "GPU 73 HDMI/DP", patch_nvhdmi),
4324 HDA_CODEC_ENTRY(0x10de0074, "GPU 74 HDMI/DP", patch_nvhdmi),
4325 HDA_CODEC_ENTRY(0x10de0076, "GPU 76 HDMI/DP", patch_nvhdmi),
4326 HDA_CODEC_ENTRY(0x10de007b, "GPU 7b HDMI/DP", patch_nvhdmi),
4327 HDA_CODEC_ENTRY(0x10de007c, "GPU 7c HDMI/DP", patch_nvhdmi),
4328 HDA_CODEC_ENTRY(0x10de007d, "GPU 7d HDMI/DP", patch_nvhdmi),
4329 HDA_CODEC_ENTRY(0x10de007e, "GPU 7e HDMI/DP", patch_nvhdmi),
4330 HDA_CODEC_ENTRY(0x10de0080, "GPU 80 HDMI/DP", patch_nvhdmi),
4331 HDA_CODEC_ENTRY(0x10de0081, "GPU 81 HDMI/DP", patch_nvhdmi),
4332 HDA_CODEC_ENTRY(0x10de0082, "GPU 82 HDMI/DP", patch_nvhdmi),
4333 HDA_CODEC_ENTRY(0x10de0083, "GPU 83 HDMI/DP", patch_nvhdmi),
4334 HDA_CODEC_ENTRY(0x10de0084, "GPU 84 HDMI/DP", patch_nvhdmi),
4335 HDA_CODEC_ENTRY(0x10de0090, "GPU 90 HDMI/DP", patch_nvhdmi),
4336 HDA_CODEC_ENTRY(0x10de0091, "GPU 91 HDMI/DP", patch_nvhdmi),
4337 HDA_CODEC_ENTRY(0x10de0092, "GPU 92 HDMI/DP", patch_nvhdmi),
4338 HDA_CODEC_ENTRY(0x10de0093, "GPU 93 HDMI/DP", patch_nvhdmi),
4339 HDA_CODEC_ENTRY(0x10de0094, "GPU 94 HDMI/DP", patch_nvhdmi),
4340 HDA_CODEC_ENTRY(0x10de0095, "GPU 95 HDMI/DP", patch_nvhdmi),
4341 HDA_CODEC_ENTRY(0x10de0097, "GPU 97 HDMI/DP", patch_nvhdmi),
4342 HDA_CODEC_ENTRY(0x10de0098, "GPU 98 HDMI/DP", patch_nvhdmi),
4343 HDA_CODEC_ENTRY(0x10de0099, "GPU 99 HDMI/DP", patch_nvhdmi),
4344 HDA_CODEC_ENTRY(0x10de009a, "GPU 9a HDMI/DP", patch_nvhdmi),
4345 HDA_CODEC_ENTRY(0x10de009d, "GPU 9d HDMI/DP", patch_nvhdmi),
4346 HDA_CODEC_ENTRY(0x10de009e, "GPU 9e HDMI/DP", patch_nvhdmi),
4347 HDA_CODEC_ENTRY(0x10de009f, "GPU 9f HDMI/DP", patch_nvhdmi),
4348 HDA_CODEC_ENTRY(0x10de00a0, "GPU a0 HDMI/DP", patch_nvhdmi),
4349 HDA_CODEC_ENTRY(0x10de8001, "MCP73 HDMI", patch_nvhdmi_2ch),
4350 HDA_CODEC_ENTRY(0x10de8067, "MCP67/68 HDMI", patch_nvhdmi_2ch),
4351 HDA_CODEC_ENTRY(0x11069f80, "VX900 HDMI/DP", patch_via_hdmi),
4352 HDA_CODEC_ENTRY(0x11069f81, "VX900 HDMI/DP", patch_via_hdmi),
4353 HDA_CODEC_ENTRY(0x11069f84, "VX11 HDMI/DP", patch_generic_hdmi),
4354 HDA_CODEC_ENTRY(0x11069f85, "VX11 HDMI/DP", patch_generic_hdmi),
4355 HDA_CODEC_ENTRY(0x80860054, "IbexPeak HDMI", patch_i915_cpt_hdmi),
4356 HDA_CODEC_ENTRY(0x80862800, "Geminilake HDMI", patch_i915_glk_hdmi),
4357 HDA_CODEC_ENTRY(0x80862801, "Bearlake HDMI", patch_generic_hdmi),
4358 HDA_CODEC_ENTRY(0x80862802, "Cantiga HDMI", patch_generic_hdmi),
4359 HDA_CODEC_ENTRY(0x80862803, "Eaglelake HDMI", patch_generic_hdmi),
4360 HDA_CODEC_ENTRY(0x80862804, "IbexPeak HDMI", patch_i915_cpt_hdmi),
4361 HDA_CODEC_ENTRY(0x80862805, "CougarPoint HDMI", patch_i915_cpt_hdmi),
4362 HDA_CODEC_ENTRY(0x80862806, "PantherPoint HDMI", patch_i915_cpt_hdmi),
4363 HDA_CODEC_ENTRY(0x80862807, "Haswell HDMI", patch_i915_hsw_hdmi),
4364 HDA_CODEC_ENTRY(0x80862808, "Broadwell HDMI", patch_i915_hsw_hdmi),
4365 HDA_CODEC_ENTRY(0x80862809, "Skylake HDMI", patch_i915_hsw_hdmi),
4366 HDA_CODEC_ENTRY(0x8086280a, "Broxton HDMI", patch_i915_hsw_hdmi),
4367 HDA_CODEC_ENTRY(0x8086280b, "Kabylake HDMI", patch_i915_hsw_hdmi),
4368 HDA_CODEC_ENTRY(0x8086280c, "Cannonlake HDMI", patch_i915_glk_hdmi),
4369 HDA_CODEC_ENTRY(0x8086280d, "Geminilake HDMI", patch_i915_glk_hdmi),
4370 HDA_CODEC_ENTRY(0x8086280f, "Icelake HDMI", patch_i915_icl_hdmi),
4371 HDA_CODEC_ENTRY(0x80862812, "Tigerlake HDMI", patch_i915_tgl_hdmi),
4372 HDA_CODEC_ENTRY(0x80862814, "DG1 HDMI", patch_i915_tgl_hdmi),
4373 HDA_CODEC_ENTRY(0x80862815, "Alderlake HDMI", patch_i915_tgl_hdmi),
4374 HDA_CODEC_ENTRY(0x8086281c, "Alderlake-P HDMI", patch_i915_tgl_hdmi),
4375 HDA_CODEC_ENTRY(0x80862816, "Rocketlake HDMI", patch_i915_tgl_hdmi),
4376 HDA_CODEC_ENTRY(0x8086281a, "Jasperlake HDMI", patch_i915_icl_hdmi),
4377 HDA_CODEC_ENTRY(0x8086281b, "Elkhartlake HDMI", patch_i915_icl_hdmi),
4378 HDA_CODEC_ENTRY(0x80862880, "CedarTrail HDMI", patch_generic_hdmi),
4379 HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_i915_byt_hdmi),
4380 HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_i915_byt_hdmi),
4381 HDA_CODEC_ENTRY(0x808629fb, "Crestline HDMI", patch_generic_hdmi),
4382 /* special ID for generic HDMI */
4383 HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC_HDMI, "Generic HDMI", patch_generic_hdmi),
4386 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_hdmi);
4388 MODULE_LICENSE("GPL");
4389 MODULE_DESCRIPTION("HDMI HD-audio codec");
4390 MODULE_ALIAS("snd-hda-codec-intelhdmi");
4391 MODULE_ALIAS("snd-hda-codec-nvhdmi");
4392 MODULE_ALIAS("snd-hda-codec-atihdmi");
4394 static struct hda_codec_driver hdmi_driver = {
4395 .id = snd_hda_id_hdmi,
4398 module_hda_codec_driver(hdmi_driver);