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 struct hdmi_spec_per_cvt {
44 unsigned int channels_min;
45 unsigned int channels_max;
51 /* max. connections to a widget */
52 #define HDA_MAX_CONNECTIONS 32
54 struct hdmi_spec_per_pin {
57 /* pin idx, different device entries on the same pin use the same idx */
60 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
64 struct hda_codec *codec;
65 struct hdmi_eld sink_eld;
67 struct delayed_work work;
68 struct hdmi_pcm *pcm; /* pointer to spec->pcm_rec[n] dynamically*/
69 int pcm_idx; /* which pcm is attached. -1 means no pcm is attached */
71 bool setup; /* the stream has been set up by prepare callback */
72 int channels; /* current number of channels */
74 bool chmap_set; /* channel-map override by ALSA API? */
75 unsigned char chmap[8]; /* ALSA API channel-map */
76 #ifdef CONFIG_SND_PROC_FS
77 struct snd_info_entry *proc_entry;
81 /* operations used by generic code that can be overridden by patches */
83 int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid,
84 int dev_id, unsigned char *buf, int *eld_size);
86 void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid,
88 int ca, int active_channels, int conn_type);
90 /* enable/disable HBR (HD passthrough) */
91 int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid,
92 int dev_id, bool hbr);
94 int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid,
95 hda_nid_t pin_nid, int dev_id, u32 stream_tag,
98 void (*pin_cvt_fixup)(struct hda_codec *codec,
99 struct hdmi_spec_per_pin *per_pin,
105 struct snd_jack *jack;
106 struct snd_kcontrol *eld_ctl;
110 struct hda_codec *codec;
112 struct snd_array cvts; /* struct hdmi_spec_per_cvt */
113 hda_nid_t cvt_nids[4]; /* only for haswell fix */
116 * num_pins is the number of virtual pins
117 * for example, there are 3 pins, and each pin
118 * has 4 device entries, then the num_pins is 12
122 * num_nids is the number of real pins
123 * In the above example, num_nids is 3
127 * dev_num is the number of device entries
129 * In the above example, dev_num is 4
132 struct snd_array pins; /* struct hdmi_spec_per_pin */
133 struct hdmi_pcm pcm_rec[16];
134 struct mutex pcm_lock;
135 struct mutex bind_lock; /* for audio component binding */
136 /* pcm_bitmap means which pcms have been assigned to pins*/
137 unsigned long pcm_bitmap;
138 int pcm_used; /* counter of pcm_rec[] */
139 /* bitmap shows whether the pcm is opened in user space
140 * bit 0 means the first playback PCM (PCM3);
141 * bit 1 means the second playback PCM, and so on.
143 unsigned long pcm_in_use;
145 struct hdmi_eld temp_eld;
150 bool intel_hsw_fixup; /* apply Intel platform-specific fixups */
152 * Non-generic VIA/NVIDIA specific
154 struct hda_multi_out multiout;
155 struct hda_pcm_stream pcm_playback;
157 bool use_jack_detect; /* jack detection enabled */
158 bool use_acomp_notifier; /* use eld_notify callback for hotplug */
159 bool acomp_registered; /* audio component registered in this driver */
160 struct drm_audio_component_audio_ops drm_audio_ops;
161 int (*port2pin)(struct hda_codec *, int); /* reverse port/pin mapping */
163 struct hdac_chmap chmap;
164 hda_nid_t vendor_nid;
169 #ifdef CONFIG_SND_HDA_COMPONENT
170 static inline bool codec_has_acomp(struct hda_codec *codec)
172 struct hdmi_spec *spec = codec->spec;
173 return spec->use_acomp_notifier;
176 #define codec_has_acomp(codec) false
179 struct hdmi_audio_infoframe {
186 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
190 u8 LFEPBL01_LSV36_DM_INH7;
193 struct dp_audio_infoframe {
196 u8 ver; /* 0x11 << 2 */
198 u8 CC02_CT47; /* match with HDMI infoframe from this on */
202 u8 LFEPBL01_LSV36_DM_INH7;
205 union audio_infoframe {
206 struct hdmi_audio_infoframe hdmi;
207 struct dp_audio_infoframe dp;
215 #define get_pin(spec, idx) \
216 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx))
217 #define get_cvt(spec, idx) \
218 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx))
219 /* obtain hdmi_pcm object assigned to idx */
220 #define get_hdmi_pcm(spec, idx) (&(spec)->pcm_rec[idx])
221 /* obtain hda_pcm object assigned to idx */
222 #define get_pcm_rec(spec, idx) (get_hdmi_pcm(spec, idx)->pcm)
224 static int pin_id_to_pin_index(struct hda_codec *codec,
225 hda_nid_t pin_nid, int dev_id)
227 struct hdmi_spec *spec = codec->spec;
229 struct hdmi_spec_per_pin *per_pin;
232 * (dev_id == -1) means it is NON-MST pin
233 * return the first virtual pin on this port
238 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
239 per_pin = get_pin(spec, pin_idx);
240 if ((per_pin->pin_nid == pin_nid) &&
241 (per_pin->dev_id == dev_id))
245 codec_warn(codec, "HDMI: pin nid %d not registered\n", pin_nid);
249 static int hinfo_to_pcm_index(struct hda_codec *codec,
250 struct hda_pcm_stream *hinfo)
252 struct hdmi_spec *spec = codec->spec;
255 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++)
256 if (get_pcm_rec(spec, pcm_idx)->stream == hinfo)
259 codec_warn(codec, "HDMI: hinfo %p not registered\n", hinfo);
263 static int hinfo_to_pin_index(struct hda_codec *codec,
264 struct hda_pcm_stream *hinfo)
266 struct hdmi_spec *spec = codec->spec;
267 struct hdmi_spec_per_pin *per_pin;
270 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
271 per_pin = get_pin(spec, pin_idx);
273 per_pin->pcm->pcm->stream == hinfo)
277 codec_dbg(codec, "HDMI: hinfo %p not registered\n", hinfo);
281 static struct hdmi_spec_per_pin *pcm_idx_to_pin(struct hdmi_spec *spec,
285 struct hdmi_spec_per_pin *per_pin;
287 for (i = 0; i < spec->num_pins; i++) {
288 per_pin = get_pin(spec, i);
289 if (per_pin->pcm_idx == pcm_idx)
295 static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid)
297 struct hdmi_spec *spec = codec->spec;
300 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
301 if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid)
304 codec_warn(codec, "HDMI: cvt nid %d not registered\n", cvt_nid);
308 static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
309 struct snd_ctl_elem_info *uinfo)
311 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
312 struct hdmi_spec *spec = codec->spec;
313 struct hdmi_spec_per_pin *per_pin;
314 struct hdmi_eld *eld;
317 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
319 pcm_idx = kcontrol->private_value;
320 mutex_lock(&spec->pcm_lock);
321 per_pin = pcm_idx_to_pin(spec, pcm_idx);
323 /* no pin is bound to the pcm */
327 eld = &per_pin->sink_eld;
328 uinfo->count = eld->eld_valid ? eld->eld_size : 0;
331 mutex_unlock(&spec->pcm_lock);
335 static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
336 struct snd_ctl_elem_value *ucontrol)
338 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
339 struct hdmi_spec *spec = codec->spec;
340 struct hdmi_spec_per_pin *per_pin;
341 struct hdmi_eld *eld;
345 pcm_idx = kcontrol->private_value;
346 mutex_lock(&spec->pcm_lock);
347 per_pin = pcm_idx_to_pin(spec, pcm_idx);
349 /* no pin is bound to the pcm */
350 memset(ucontrol->value.bytes.data, 0,
351 ARRAY_SIZE(ucontrol->value.bytes.data));
355 eld = &per_pin->sink_eld;
356 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data) ||
357 eld->eld_size > ELD_MAX_SIZE) {
363 memset(ucontrol->value.bytes.data, 0,
364 ARRAY_SIZE(ucontrol->value.bytes.data));
366 memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
370 mutex_unlock(&spec->pcm_lock);
374 static const struct snd_kcontrol_new eld_bytes_ctl = {
375 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE |
376 SNDRV_CTL_ELEM_ACCESS_SKIP_CHECK,
377 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
379 .info = hdmi_eld_ctl_info,
380 .get = hdmi_eld_ctl_get,
383 static int hdmi_create_eld_ctl(struct hda_codec *codec, int pcm_idx,
386 struct snd_kcontrol *kctl;
387 struct hdmi_spec *spec = codec->spec;
390 kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
393 kctl->private_value = pcm_idx;
394 kctl->id.device = device;
396 /* no pin nid is associated with the kctl now
397 * tbd: associate pin nid to eld ctl later
399 err = snd_hda_ctl_add(codec, 0, kctl);
403 get_hdmi_pcm(spec, pcm_idx)->eld_ctl = kctl;
408 static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
409 int *packet_index, int *byte_index)
413 val = snd_hda_codec_read(codec, pin_nid, 0,
414 AC_VERB_GET_HDMI_DIP_INDEX, 0);
416 *packet_index = val >> 5;
417 *byte_index = val & 0x1f;
421 static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
422 int packet_index, int byte_index)
426 val = (packet_index << 5) | (byte_index & 0x1f);
428 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
431 static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
434 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
437 static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
439 struct hdmi_spec *spec = codec->spec;
443 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
444 snd_hda_codec_write(codec, pin_nid, 0,
445 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
447 if (spec->dyn_pin_out)
448 /* Disable pin out until stream is active */
451 /* Enable pin out: some machines with GM965 gets broken output
452 * when the pin is disabled or changed while using with HDMI
456 snd_hda_codec_write(codec, pin_nid, 0,
457 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_out);
464 #ifdef CONFIG_SND_PROC_FS
465 static void print_eld_info(struct snd_info_entry *entry,
466 struct snd_info_buffer *buffer)
468 struct hdmi_spec_per_pin *per_pin = entry->private_data;
470 mutex_lock(&per_pin->lock);
471 snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer);
472 mutex_unlock(&per_pin->lock);
475 static void write_eld_info(struct snd_info_entry *entry,
476 struct snd_info_buffer *buffer)
478 struct hdmi_spec_per_pin *per_pin = entry->private_data;
480 mutex_lock(&per_pin->lock);
481 snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer);
482 mutex_unlock(&per_pin->lock);
485 static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
488 struct hda_codec *codec = per_pin->codec;
489 struct snd_info_entry *entry;
492 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
493 err = snd_card_proc_new(codec->card, name, &entry);
497 snd_info_set_text_ops(entry, per_pin, print_eld_info);
498 entry->c.text.write = write_eld_info;
500 per_pin->proc_entry = entry;
505 static void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
507 if (!per_pin->codec->bus->shutdown) {
508 snd_info_free_entry(per_pin->proc_entry);
509 per_pin->proc_entry = NULL;
513 static inline int eld_proc_new(struct hdmi_spec_per_pin *per_pin,
518 static inline void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
524 * Audio InfoFrame routines
528 * Enable Audio InfoFrame Transmission
530 static void hdmi_start_infoframe_trans(struct hda_codec *codec,
533 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
534 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
539 * Disable Audio InfoFrame Transmission
541 static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
544 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
545 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
549 static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
551 #ifdef CONFIG_SND_DEBUG_VERBOSE
555 size = snd_hdmi_get_eld_size(codec, pin_nid);
556 codec_dbg(codec, "HDMI: ELD buf size is %d\n", size);
558 for (i = 0; i < 8; i++) {
559 size = snd_hda_codec_read(codec, pin_nid, 0,
560 AC_VERB_GET_HDMI_DIP_SIZE, i);
561 codec_dbg(codec, "HDMI: DIP GP[%d] buf size is %d\n", i, size);
566 static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
572 for (i = 0; i < 8; i++) {
573 size = snd_hda_codec_read(codec, pin_nid, 0,
574 AC_VERB_GET_HDMI_DIP_SIZE, i);
578 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
579 for (j = 1; j < 1000; j++) {
580 hdmi_write_dip_byte(codec, pin_nid, 0x0);
581 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
583 codec_dbg(codec, "dip index %d: %d != %d\n",
585 if (bi == 0) /* byte index wrapped around */
589 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
595 static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
597 u8 *bytes = (u8 *)hdmi_ai;
601 hdmi_ai->checksum = 0;
603 for (i = 0; i < sizeof(*hdmi_ai); i++)
606 hdmi_ai->checksum = -sum;
609 static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
615 hdmi_debug_dip_size(codec, pin_nid);
616 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
618 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
619 for (i = 0; i < size; i++)
620 hdmi_write_dip_byte(codec, pin_nid, dip[i]);
623 static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
629 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
633 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
634 for (i = 0; i < size; i++) {
635 val = snd_hda_codec_read(codec, pin_nid, 0,
636 AC_VERB_GET_HDMI_DIP_DATA, 0);
644 static int hdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
645 int dev_id, unsigned char *buf, int *eld_size)
647 snd_hda_set_dev_select(codec, nid, dev_id);
649 return snd_hdmi_get_eld(codec, nid, buf, eld_size);
652 static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
653 hda_nid_t pin_nid, int dev_id,
654 int ca, int active_channels,
657 union audio_infoframe ai;
659 memset(&ai, 0, sizeof(ai));
660 if (conn_type == 0) { /* HDMI */
661 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
663 hdmi_ai->type = 0x84;
666 hdmi_ai->CC02_CT47 = active_channels - 1;
668 hdmi_checksum_audio_infoframe(hdmi_ai);
669 } else if (conn_type == 1) { /* DisplayPort */
670 struct dp_audio_infoframe *dp_ai = &ai.dp;
674 dp_ai->ver = 0x11 << 2;
675 dp_ai->CC02_CT47 = active_channels - 1;
678 codec_dbg(codec, "HDMI: unknown connection type at pin %d\n",
683 snd_hda_set_dev_select(codec, pin_nid, dev_id);
686 * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
687 * sizeof(*dp_ai) to avoid partial match/update problems when
688 * the user switches between HDMI/DP monitors.
690 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
693 "hdmi_pin_setup_infoframe: pin=%d channels=%d ca=0x%02x\n",
695 active_channels, ca);
696 hdmi_stop_infoframe_trans(codec, pin_nid);
697 hdmi_fill_audio_infoframe(codec, pin_nid,
698 ai.bytes, sizeof(ai));
699 hdmi_start_infoframe_trans(codec, pin_nid);
703 static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
704 struct hdmi_spec_per_pin *per_pin,
707 struct hdmi_spec *spec = codec->spec;
708 struct hdac_chmap *chmap = &spec->chmap;
709 hda_nid_t pin_nid = per_pin->pin_nid;
710 int dev_id = per_pin->dev_id;
711 int channels = per_pin->channels;
713 struct hdmi_eld *eld;
719 snd_hda_set_dev_select(codec, pin_nid, dev_id);
721 /* some HW (e.g. HSW+) needs reprogramming the amp at each time */
722 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
723 snd_hda_codec_write(codec, pin_nid, 0,
724 AC_VERB_SET_AMP_GAIN_MUTE,
727 eld = &per_pin->sink_eld;
729 ca = snd_hdac_channel_allocation(&codec->core,
730 eld->info.spk_alloc, channels,
731 per_pin->chmap_set, non_pcm, per_pin->chmap);
733 active_channels = snd_hdac_get_active_channels(ca);
735 chmap->ops.set_channel_count(&codec->core, per_pin->cvt_nid,
739 * always configure channel mapping, it may have been changed by the
740 * user in the meantime
742 snd_hdac_setup_channel_mapping(&spec->chmap,
743 pin_nid, non_pcm, ca, channels,
744 per_pin->chmap, per_pin->chmap_set);
746 spec->ops.pin_setup_infoframe(codec, pin_nid, dev_id,
747 ca, active_channels, eld->info.conn_type);
749 per_pin->non_pcm = non_pcm;
756 static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
758 static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid,
761 struct hdmi_spec *spec = codec->spec;
762 int pin_idx = pin_id_to_pin_index(codec, nid, dev_id);
766 mutex_lock(&spec->pcm_lock);
767 if (hdmi_present_sense(get_pin(spec, pin_idx), 1))
768 snd_hda_jack_report_sync(codec);
769 mutex_unlock(&spec->pcm_lock);
772 static void jack_callback(struct hda_codec *codec,
773 struct hda_jack_callback *jack)
775 /* stop polling when notification is enabled */
776 if (codec_has_acomp(codec))
779 check_presence_and_report(codec, jack->nid, jack->dev_id);
782 static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
784 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
785 struct hda_jack_tbl *jack;
789 (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
791 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, dev_entry);
793 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, 0);
797 jack->jack_dirty = 1;
800 "HDMI hot plug event: Codec=%d Pin=%d Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n",
801 codec->addr, jack->nid, jack->dev_id, !!(res & AC_UNSOL_RES_IA),
802 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
804 check_presence_and_report(codec, jack->nid, jack->dev_id);
807 static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
809 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
810 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
811 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
812 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
815 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
832 static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
834 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
835 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
836 struct hda_jack_tbl *jack;
838 if (codec_has_acomp(codec))
843 (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
845 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, dev_entry);
847 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, 0);
851 codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag);
856 hdmi_intrinsic_event(codec, res);
858 hdmi_non_intrinsic_event(codec, res);
861 static void haswell_verify_D0(struct hda_codec *codec,
862 hda_nid_t cvt_nid, hda_nid_t nid)
866 /* For Haswell, the converter 1/2 may keep in D3 state after bootup,
867 * thus pins could only choose converter 0 for use. Make sure the
868 * converters are in correct power state */
869 if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0))
870 snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
872 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) {
873 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
876 pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
877 pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
878 codec_dbg(codec, "Haswell HDMI audio: Power for pin 0x%x is now D%d\n", nid, pwr);
886 /* HBR should be Non-PCM, 8 channels */
887 #define is_hbr_format(format) \
888 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
890 static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
891 int dev_id, bool hbr)
893 int pinctl, new_pinctl;
895 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
896 snd_hda_set_dev_select(codec, pin_nid, dev_id);
897 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
898 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
901 return hbr ? -EINVAL : 0;
903 new_pinctl = pinctl & ~AC_PINCTL_EPT;
905 new_pinctl |= AC_PINCTL_EPT_HBR;
907 new_pinctl |= AC_PINCTL_EPT_NATIVE;
910 "hdmi_pin_hbr_setup: NID=0x%x, %spinctl=0x%x\n",
912 pinctl == new_pinctl ? "" : "new-",
915 if (pinctl != new_pinctl)
916 snd_hda_codec_write(codec, pin_nid, 0,
917 AC_VERB_SET_PIN_WIDGET_CONTROL,
925 static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
926 hda_nid_t pin_nid, int dev_id,
927 u32 stream_tag, int format)
929 struct hdmi_spec *spec = codec->spec;
933 err = spec->ops.pin_hbr_setup(codec, pin_nid, dev_id,
934 is_hbr_format(format));
937 codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n");
941 if (spec->intel_hsw_fixup) {
944 * on recent platforms IEC Coding Type is required for HBR
945 * support, read current Digital Converter settings and set
946 * ICT bitfield if needed.
948 param = snd_hda_codec_read(codec, cvt_nid, 0,
949 AC_VERB_GET_DIGI_CONVERT_1, 0);
951 param = (param >> 16) & ~(AC_DIG3_ICT);
953 /* on recent platforms ICT mode is required for HBR support */
954 if (is_hbr_format(format))
957 snd_hda_codec_write(codec, cvt_nid, 0,
958 AC_VERB_SET_DIGI_CONVERT_3, param);
961 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
965 /* Try to find an available converter
966 * If pin_idx is less then zero, just try to find an available converter.
967 * Otherwise, try to find an available converter and get the cvt mux index
970 static int hdmi_choose_cvt(struct hda_codec *codec,
971 int pin_idx, int *cvt_id)
973 struct hdmi_spec *spec = codec->spec;
974 struct hdmi_spec_per_pin *per_pin;
975 struct hdmi_spec_per_cvt *per_cvt = NULL;
976 int cvt_idx, mux_idx = 0;
978 /* pin_idx < 0 means no pin will be bound to the converter */
982 per_pin = get_pin(spec, pin_idx);
984 /* Dynamically assign converter to stream */
985 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
986 per_cvt = get_cvt(spec, cvt_idx);
988 /* Must not already be assigned */
989 if (per_cvt->assigned)
993 /* Must be in pin's mux's list of converters */
994 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
995 if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid)
997 /* Not in mux list */
998 if (mux_idx == per_pin->num_mux_nids)
1003 /* No free converters */
1004 if (cvt_idx == spec->num_cvts)
1007 if (per_pin != NULL)
1008 per_pin->mux_idx = mux_idx;
1016 /* Assure the pin select the right convetor */
1017 static void intel_verify_pin_cvt_connect(struct hda_codec *codec,
1018 struct hdmi_spec_per_pin *per_pin)
1020 hda_nid_t pin_nid = per_pin->pin_nid;
1023 mux_idx = per_pin->mux_idx;
1024 curr = snd_hda_codec_read(codec, pin_nid, 0,
1025 AC_VERB_GET_CONNECT_SEL, 0);
1026 if (curr != mux_idx)
1027 snd_hda_codec_write_cache(codec, pin_nid, 0,
1028 AC_VERB_SET_CONNECT_SEL,
1032 /* get the mux index for the converter of the pins
1033 * converter's mux index is the same for all pins on Intel platform
1035 static int intel_cvt_id_to_mux_idx(struct hdmi_spec *spec,
1040 for (i = 0; i < spec->num_cvts; i++)
1041 if (spec->cvt_nids[i] == cvt_nid)
1046 /* Intel HDMI workaround to fix audio routing issue:
1047 * For some Intel display codecs, pins share the same connection list.
1048 * So a conveter can be selected by multiple pins and playback on any of these
1049 * pins will generate sound on the external display, because audio flows from
1050 * the same converter to the display pipeline. Also muting one pin may make
1051 * other pins have no sound output.
1052 * So this function assures that an assigned converter for a pin is not selected
1053 * by any other pins.
1055 static void intel_not_share_assigned_cvt(struct hda_codec *codec,
1057 int dev_id, int mux_idx)
1059 struct hdmi_spec *spec = codec->spec;
1062 struct hdmi_spec_per_cvt *per_cvt;
1063 struct hdmi_spec_per_pin *per_pin;
1066 /* configure the pins connections */
1067 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1071 per_pin = get_pin(spec, pin_idx);
1073 * pin not connected to monitor
1074 * no need to operate on it
1079 if ((per_pin->pin_nid == pin_nid) &&
1080 (per_pin->dev_id == dev_id))
1084 * if per_pin->dev_id >= dev_num,
1085 * snd_hda_get_dev_select() will fail,
1086 * and the following operation is unpredictable.
1087 * So skip this situation.
1089 dev_num = snd_hda_get_num_devices(codec, per_pin->pin_nid) + 1;
1090 if (per_pin->dev_id >= dev_num)
1093 nid = per_pin->pin_nid;
1096 * Calling this function should not impact
1097 * on the device entry selection
1098 * So let's save the dev id for each pin,
1099 * and restore it when return
1101 dev_id_saved = snd_hda_get_dev_select(codec, nid);
1102 snd_hda_set_dev_select(codec, nid, per_pin->dev_id);
1103 curr = snd_hda_codec_read(codec, nid, 0,
1104 AC_VERB_GET_CONNECT_SEL, 0);
1105 if (curr != mux_idx) {
1106 snd_hda_set_dev_select(codec, nid, dev_id_saved);
1111 /* choose an unassigned converter. The conveters in the
1112 * connection list are in the same order as in the codec.
1114 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
1115 per_cvt = get_cvt(spec, cvt_idx);
1116 if (!per_cvt->assigned) {
1118 "choose cvt %d for pin nid %d\n",
1120 snd_hda_codec_write_cache(codec, nid, 0,
1121 AC_VERB_SET_CONNECT_SEL,
1126 snd_hda_set_dev_select(codec, nid, dev_id_saved);
1130 /* A wrapper of intel_not_share_asigned_cvt() */
1131 static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,
1132 hda_nid_t pin_nid, int dev_id, hda_nid_t cvt_nid)
1135 struct hdmi_spec *spec = codec->spec;
1137 /* On Intel platform, the mapping of converter nid to
1138 * mux index of the pins are always the same.
1139 * The pin nid may be 0, this means all pins will not
1140 * share the converter.
1142 mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid);
1144 intel_not_share_assigned_cvt(codec, pin_nid, dev_id, mux_idx);
1147 /* skeleton caller of pin_cvt_fixup ops */
1148 static void pin_cvt_fixup(struct hda_codec *codec,
1149 struct hdmi_spec_per_pin *per_pin,
1152 struct hdmi_spec *spec = codec->spec;
1154 if (spec->ops.pin_cvt_fixup)
1155 spec->ops.pin_cvt_fixup(codec, per_pin, cvt_nid);
1158 /* called in hdmi_pcm_open when no pin is assigned to the PCM
1159 * in dyn_pcm_assign mode.
1161 static int hdmi_pcm_open_no_pin(struct hda_pcm_stream *hinfo,
1162 struct hda_codec *codec,
1163 struct snd_pcm_substream *substream)
1165 struct hdmi_spec *spec = codec->spec;
1166 struct snd_pcm_runtime *runtime = substream->runtime;
1167 int cvt_idx, pcm_idx;
1168 struct hdmi_spec_per_cvt *per_cvt = NULL;
1171 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1175 err = hdmi_choose_cvt(codec, -1, &cvt_idx);
1179 per_cvt = get_cvt(spec, cvt_idx);
1180 per_cvt->assigned = 1;
1181 hinfo->nid = per_cvt->cvt_nid;
1183 pin_cvt_fixup(codec, NULL, per_cvt->cvt_nid);
1185 set_bit(pcm_idx, &spec->pcm_in_use);
1186 /* todo: setup spdif ctls assign */
1188 /* Initially set the converter's capabilities */
1189 hinfo->channels_min = per_cvt->channels_min;
1190 hinfo->channels_max = per_cvt->channels_max;
1191 hinfo->rates = per_cvt->rates;
1192 hinfo->formats = per_cvt->formats;
1193 hinfo->maxbps = per_cvt->maxbps;
1195 /* Store the updated parameters */
1196 runtime->hw.channels_min = hinfo->channels_min;
1197 runtime->hw.channels_max = hinfo->channels_max;
1198 runtime->hw.formats = hinfo->formats;
1199 runtime->hw.rates = hinfo->rates;
1201 snd_pcm_hw_constraint_step(substream->runtime, 0,
1202 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
1209 static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1210 struct hda_codec *codec,
1211 struct snd_pcm_substream *substream)
1213 struct hdmi_spec *spec = codec->spec;
1214 struct snd_pcm_runtime *runtime = substream->runtime;
1215 int pin_idx, cvt_idx, pcm_idx;
1216 struct hdmi_spec_per_pin *per_pin;
1217 struct hdmi_eld *eld;
1218 struct hdmi_spec_per_cvt *per_cvt = NULL;
1221 /* Validate hinfo */
1222 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1226 mutex_lock(&spec->pcm_lock);
1227 pin_idx = hinfo_to_pin_index(codec, hinfo);
1228 if (!spec->dyn_pcm_assign) {
1229 if (snd_BUG_ON(pin_idx < 0)) {
1234 /* no pin is assigned to the PCM
1235 * PA need pcm open successfully when probe
1238 err = hdmi_pcm_open_no_pin(hinfo, codec, substream);
1243 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx);
1247 per_cvt = get_cvt(spec, cvt_idx);
1248 /* Claim converter */
1249 per_cvt->assigned = 1;
1251 set_bit(pcm_idx, &spec->pcm_in_use);
1252 per_pin = get_pin(spec, pin_idx);
1253 per_pin->cvt_nid = per_cvt->cvt_nid;
1254 hinfo->nid = per_cvt->cvt_nid;
1256 /* flip stripe flag for the assigned stream if supported */
1257 if (get_wcaps(codec, per_cvt->cvt_nid) & AC_WCAP_STRIPE)
1258 azx_stream(get_azx_dev(substream))->stripe = 1;
1260 snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id);
1261 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1262 AC_VERB_SET_CONNECT_SEL,
1265 /* configure unused pins to choose other converters */
1266 pin_cvt_fixup(codec, per_pin, 0);
1268 snd_hda_spdif_ctls_assign(codec, pcm_idx, per_cvt->cvt_nid);
1270 /* Initially set the converter's capabilities */
1271 hinfo->channels_min = per_cvt->channels_min;
1272 hinfo->channels_max = per_cvt->channels_max;
1273 hinfo->rates = per_cvt->rates;
1274 hinfo->formats = per_cvt->formats;
1275 hinfo->maxbps = per_cvt->maxbps;
1277 eld = &per_pin->sink_eld;
1278 /* Restrict capabilities by ELD if this isn't disabled */
1279 if (!static_hdmi_pcm && eld->eld_valid) {
1280 snd_hdmi_eld_update_pcm_info(&eld->info, hinfo);
1281 if (hinfo->channels_min > hinfo->channels_max ||
1282 !hinfo->rates || !hinfo->formats) {
1283 per_cvt->assigned = 0;
1285 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
1291 /* Store the updated parameters */
1292 runtime->hw.channels_min = hinfo->channels_min;
1293 runtime->hw.channels_max = hinfo->channels_max;
1294 runtime->hw.formats = hinfo->formats;
1295 runtime->hw.rates = hinfo->rates;
1297 snd_pcm_hw_constraint_step(substream->runtime, 0,
1298 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
1300 mutex_unlock(&spec->pcm_lock);
1305 * HDA/HDMI auto parsing
1307 static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
1309 struct hdmi_spec *spec = codec->spec;
1310 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1311 hda_nid_t pin_nid = per_pin->pin_nid;
1312 int dev_id = per_pin->dev_id;
1315 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
1317 "HDMI: pin %d wcaps %#x does not support connection list\n",
1318 pin_nid, get_wcaps(codec, pin_nid));
1322 snd_hda_set_dev_select(codec, pin_nid, dev_id);
1324 if (spec->intel_hsw_fixup) {
1325 conns = spec->num_cvts;
1326 memcpy(per_pin->mux_nids, spec->cvt_nids,
1327 sizeof(hda_nid_t) * conns);
1329 conns = snd_hda_get_raw_connections(codec, pin_nid,
1331 HDA_MAX_CONNECTIONS);
1334 /* all the device entries on the same pin have the same conn list */
1335 per_pin->num_mux_nids = conns;
1340 static int hdmi_find_pcm_slot(struct hdmi_spec *spec,
1341 struct hdmi_spec_per_pin *per_pin)
1346 * generic_hdmi_build_pcms() may allocate extra PCMs on some
1347 * platforms (with maximum of 'num_nids + dev_num - 1')
1349 * The per_pin of pin_nid_idx=n and dev_id=m prefers to get pcm-n
1350 * if m==0. This guarantees that dynamic pcm assignments are compatible
1351 * with the legacy static per_pin-pcm assignment that existed in the
1352 * days before DP-MST.
1354 * Intel DP-MST prefers this legacy behavior for compatibility, too.
1356 * per_pin of m!=0 prefers to get pcm=(num_nids + (m - 1)).
1359 if (per_pin->dev_id == 0 || spec->intel_hsw_fixup) {
1360 if (!test_bit(per_pin->pin_nid_idx, &spec->pcm_bitmap))
1361 return per_pin->pin_nid_idx;
1363 i = spec->num_nids + (per_pin->dev_id - 1);
1364 if (i < spec->pcm_used && !(test_bit(i, &spec->pcm_bitmap)))
1368 /* have a second try; check the area over num_nids */
1369 for (i = spec->num_nids; i < spec->pcm_used; i++) {
1370 if (!test_bit(i, &spec->pcm_bitmap))
1374 /* the last try; check the empty slots in pins */
1375 for (i = 0; i < spec->num_nids; i++) {
1376 if (!test_bit(i, &spec->pcm_bitmap))
1382 static void hdmi_attach_hda_pcm(struct hdmi_spec *spec,
1383 struct hdmi_spec_per_pin *per_pin)
1387 /* pcm already be attached to the pin */
1390 idx = hdmi_find_pcm_slot(spec, per_pin);
1393 per_pin->pcm_idx = idx;
1394 per_pin->pcm = get_hdmi_pcm(spec, idx);
1395 set_bit(idx, &spec->pcm_bitmap);
1398 static void hdmi_detach_hda_pcm(struct hdmi_spec *spec,
1399 struct hdmi_spec_per_pin *per_pin)
1403 /* pcm already be detached from the pin */
1406 idx = per_pin->pcm_idx;
1407 per_pin->pcm_idx = -1;
1408 per_pin->pcm = NULL;
1409 if (idx >= 0 && idx < spec->pcm_used)
1410 clear_bit(idx, &spec->pcm_bitmap);
1413 static int hdmi_get_pin_cvt_mux(struct hdmi_spec *spec,
1414 struct hdmi_spec_per_pin *per_pin, hda_nid_t cvt_nid)
1418 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
1419 if (per_pin->mux_nids[mux_idx] == cvt_nid)
1424 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid);
1426 static void hdmi_pcm_setup_pin(struct hdmi_spec *spec,
1427 struct hdmi_spec_per_pin *per_pin)
1429 struct hda_codec *codec = per_pin->codec;
1430 struct hda_pcm *pcm;
1431 struct hda_pcm_stream *hinfo;
1432 struct snd_pcm_substream *substream;
1436 if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
1437 pcm = get_pcm_rec(spec, per_pin->pcm_idx);
1442 if (!test_bit(per_pin->pcm_idx, &spec->pcm_in_use))
1445 /* hdmi audio only uses playback and one substream */
1446 hinfo = pcm->stream;
1447 substream = pcm->pcm->streams[0].substream;
1449 per_pin->cvt_nid = hinfo->nid;
1451 mux_idx = hdmi_get_pin_cvt_mux(spec, per_pin, hinfo->nid);
1452 if (mux_idx < per_pin->num_mux_nids) {
1453 snd_hda_set_dev_select(codec, per_pin->pin_nid,
1455 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1456 AC_VERB_SET_CONNECT_SEL,
1459 snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid);
1461 non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid);
1462 if (substream->runtime)
1463 per_pin->channels = substream->runtime->channels;
1464 per_pin->setup = true;
1465 per_pin->mux_idx = mux_idx;
1467 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
1470 static void hdmi_pcm_reset_pin(struct hdmi_spec *spec,
1471 struct hdmi_spec_per_pin *per_pin)
1473 if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
1474 snd_hda_spdif_ctls_unassign(per_pin->codec, per_pin->pcm_idx);
1476 per_pin->chmap_set = false;
1477 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
1479 per_pin->setup = false;
1480 per_pin->channels = 0;
1483 /* update per_pin ELD from the given new ELD;
1484 * setup info frame and notification accordingly
1486 static bool update_eld(struct hda_codec *codec,
1487 struct hdmi_spec_per_pin *per_pin,
1488 struct hdmi_eld *eld)
1490 struct hdmi_eld *pin_eld = &per_pin->sink_eld;
1491 struct hdmi_spec *spec = codec->spec;
1492 bool old_eld_valid = pin_eld->eld_valid;
1496 /* for monitor disconnection, save pcm_idx firstly */
1497 pcm_idx = per_pin->pcm_idx;
1498 if (spec->dyn_pcm_assign) {
1499 if (eld->eld_valid) {
1500 hdmi_attach_hda_pcm(spec, per_pin);
1501 hdmi_pcm_setup_pin(spec, per_pin);
1503 hdmi_pcm_reset_pin(spec, per_pin);
1504 hdmi_detach_hda_pcm(spec, per_pin);
1507 /* if pcm_idx == -1, it means this is in monitor connection event
1508 * we can get the correct pcm_idx now.
1511 pcm_idx = per_pin->pcm_idx;
1514 snd_hdmi_show_eld(codec, &eld->info);
1516 eld_changed = (pin_eld->eld_valid != eld->eld_valid);
1517 eld_changed |= (pin_eld->monitor_present != eld->monitor_present);
1518 if (!eld_changed && eld->eld_valid && pin_eld->eld_valid)
1519 if (pin_eld->eld_size != eld->eld_size ||
1520 memcmp(pin_eld->eld_buffer, eld->eld_buffer,
1521 eld->eld_size) != 0)
1525 pin_eld->monitor_present = eld->monitor_present;
1526 pin_eld->eld_valid = eld->eld_valid;
1527 pin_eld->eld_size = eld->eld_size;
1529 memcpy(pin_eld->eld_buffer, eld->eld_buffer,
1531 pin_eld->info = eld->info;
1535 * Re-setup pin and infoframe. This is needed e.g. when
1536 * - sink is first plugged-in
1537 * - transcoder can change during stream playback on Haswell
1538 * and this can make HW reset converter selection on a pin.
1540 if (eld->eld_valid && !old_eld_valid && per_pin->setup) {
1541 pin_cvt_fixup(codec, per_pin, 0);
1542 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1545 if (eld_changed && pcm_idx >= 0)
1546 snd_ctl_notify(codec->card,
1547 SNDRV_CTL_EVENT_MASK_VALUE |
1548 SNDRV_CTL_EVENT_MASK_INFO,
1549 &get_hdmi_pcm(spec, pcm_idx)->eld_ctl->id);
1553 /* update ELD and jack state via HD-audio verbs */
1554 static bool hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin,
1557 struct hda_jack_tbl *jack;
1558 struct hda_codec *codec = per_pin->codec;
1559 struct hdmi_spec *spec = codec->spec;
1560 struct hdmi_eld *eld = &spec->temp_eld;
1561 hda_nid_t pin_nid = per_pin->pin_nid;
1562 int dev_id = per_pin->dev_id;
1564 * Always execute a GetPinSense verb here, even when called from
1565 * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
1566 * response's PD bit is not the real PD value, but indicates that
1567 * the real PD value changed. An older version of the HD-audio
1568 * specification worked this way. Hence, we just ignore the data in
1569 * the unsolicited response to avoid custom WARs.
1573 bool do_repoll = false;
1575 present = snd_hda_jack_pin_sense(codec, pin_nid, dev_id);
1577 mutex_lock(&per_pin->lock);
1578 eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
1579 if (eld->monitor_present)
1580 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
1582 eld->eld_valid = false;
1585 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
1586 codec->addr, pin_nid, eld->monitor_present, eld->eld_valid);
1588 if (eld->eld_valid) {
1589 if (spec->ops.pin_get_eld(codec, pin_nid, dev_id,
1590 eld->eld_buffer, &eld->eld_size) < 0)
1591 eld->eld_valid = false;
1593 if (snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer,
1595 eld->eld_valid = false;
1597 if (!eld->eld_valid && repoll)
1602 schedule_delayed_work(&per_pin->work, msecs_to_jiffies(300));
1604 update_eld(codec, per_pin, eld);
1606 ret = !repoll || !eld->monitor_present || eld->eld_valid;
1608 jack = snd_hda_jack_tbl_get_mst(codec, pin_nid, per_pin->dev_id);
1610 jack->block_report = !ret;
1611 jack->pin_sense = (eld->monitor_present && eld->eld_valid) ?
1612 AC_PINSENSE_PRESENCE : 0;
1614 mutex_unlock(&per_pin->lock);
1618 static struct snd_jack *pin_idx_to_jack(struct hda_codec *codec,
1619 struct hdmi_spec_per_pin *per_pin)
1621 struct hdmi_spec *spec = codec->spec;
1622 struct snd_jack *jack = NULL;
1623 struct hda_jack_tbl *jack_tbl;
1625 /* if !dyn_pcm_assign, get jack from hda_jack_tbl
1626 * in !dyn_pcm_assign case, spec->pcm_rec[].jack is not
1627 * NULL even after snd_hda_jack_tbl_clear() is called to
1628 * free snd_jack. This may cause access invalid memory
1629 * when calling snd_jack_report
1631 if (per_pin->pcm_idx >= 0 && spec->dyn_pcm_assign)
1632 jack = spec->pcm_rec[per_pin->pcm_idx].jack;
1633 else if (!spec->dyn_pcm_assign) {
1635 * jack tbl doesn't support DP MST
1636 * DP MST will use dyn_pcm_assign,
1637 * so DP MST will never come here
1639 jack_tbl = snd_hda_jack_tbl_get_mst(codec, per_pin->pin_nid,
1642 jack = jack_tbl->jack;
1647 /* update ELD and jack state via audio component */
1648 static void sync_eld_via_acomp(struct hda_codec *codec,
1649 struct hdmi_spec_per_pin *per_pin)
1651 struct hdmi_spec *spec = codec->spec;
1652 struct hdmi_eld *eld = &spec->temp_eld;
1653 struct snd_jack *jack = NULL;
1657 mutex_lock(&per_pin->lock);
1658 eld->monitor_present = false;
1659 size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid,
1660 per_pin->dev_id, &eld->monitor_present,
1661 eld->eld_buffer, ELD_MAX_SIZE);
1663 size = min(size, ELD_MAX_SIZE);
1664 if (snd_hdmi_parse_eld(codec, &eld->info,
1665 eld->eld_buffer, size) < 0)
1670 eld->eld_valid = true;
1671 eld->eld_size = size;
1673 eld->eld_valid = false;
1677 /* pcm_idx >=0 before update_eld() means it is in monitor
1678 * disconnected event. Jack must be fetched before update_eld()
1680 jack = pin_idx_to_jack(codec, per_pin);
1681 changed = update_eld(codec, per_pin, eld);
1683 jack = pin_idx_to_jack(codec, per_pin);
1684 if (changed && jack)
1685 snd_jack_report(jack,
1686 (eld->monitor_present && eld->eld_valid) ?
1687 SND_JACK_AVOUT : 0);
1688 mutex_unlock(&per_pin->lock);
1691 static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1693 struct hda_codec *codec = per_pin->codec;
1696 /* no temporary power up/down needed for component notifier */
1697 if (!codec_has_acomp(codec)) {
1698 ret = snd_hda_power_up_pm(codec);
1699 if (ret < 0 && pm_runtime_suspended(hda_codec_dev(codec))) {
1700 snd_hda_power_down_pm(codec);
1703 ret = hdmi_present_sense_via_verbs(per_pin, repoll);
1704 snd_hda_power_down_pm(codec);
1706 sync_eld_via_acomp(codec, per_pin);
1707 ret = false; /* don't call snd_hda_jack_report_sync() */
1713 static void hdmi_repoll_eld(struct work_struct *work)
1715 struct hdmi_spec_per_pin *per_pin =
1716 container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
1717 struct hda_codec *codec = per_pin->codec;
1718 struct hdmi_spec *spec = codec->spec;
1719 struct hda_jack_tbl *jack;
1721 jack = snd_hda_jack_tbl_get_mst(codec, per_pin->pin_nid,
1724 jack->jack_dirty = 1;
1726 if (per_pin->repoll_count++ > 6)
1727 per_pin->repoll_count = 0;
1729 mutex_lock(&spec->pcm_lock);
1730 if (hdmi_present_sense(per_pin, per_pin->repoll_count))
1731 snd_hda_jack_report_sync(per_pin->codec);
1732 mutex_unlock(&spec->pcm_lock);
1735 static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1737 struct hdmi_spec *spec = codec->spec;
1738 unsigned int caps, config;
1740 struct hdmi_spec_per_pin *per_pin;
1744 caps = snd_hda_query_pin_caps(codec, pin_nid);
1745 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
1749 * For DP MST audio, Configuration Default is the same for
1750 * all device entries on the same pin
1752 config = snd_hda_codec_get_pincfg(codec, pin_nid);
1753 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
1757 * To simplify the implementation, malloc all
1758 * the virtual pins in the initialization statically
1760 if (spec->intel_hsw_fixup) {
1762 * On Intel platforms, device entries number is
1763 * changed dynamically. If there is a DP MST
1764 * hub connected, the device entries number is 3.
1765 * Otherwise, it is 1.
1766 * Here we manually set dev_num to 3, so that
1767 * we can initialize all the device entries when
1768 * bootup statically.
1772 } else if (spec->dyn_pcm_assign && codec->dp_mst) {
1773 dev_num = snd_hda_get_num_devices(codec, pin_nid) + 1;
1775 * spec->dev_num is the maxinum number of device entries
1776 * among all the pins
1778 spec->dev_num = (spec->dev_num > dev_num) ?
1779 spec->dev_num : dev_num;
1782 * If the platform doesn't support DP MST,
1783 * manually set dev_num to 1. This means
1784 * the pin has only one device entry.
1790 for (i = 0; i < dev_num; i++) {
1791 pin_idx = spec->num_pins;
1792 per_pin = snd_array_new(&spec->pins);
1797 if (spec->dyn_pcm_assign) {
1798 per_pin->pcm = NULL;
1799 per_pin->pcm_idx = -1;
1801 per_pin->pcm = get_hdmi_pcm(spec, pin_idx);
1802 per_pin->pcm_idx = pin_idx;
1804 per_pin->pin_nid = pin_nid;
1805 per_pin->pin_nid_idx = spec->num_nids;
1806 per_pin->dev_id = i;
1807 per_pin->non_pcm = false;
1808 snd_hda_set_dev_select(codec, pin_nid, i);
1809 err = hdmi_read_pin_conn(codec, pin_idx);
1819 static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1821 struct hdmi_spec *spec = codec->spec;
1822 struct hdmi_spec_per_cvt *per_cvt;
1826 chans = get_wcaps(codec, cvt_nid);
1827 chans = get_wcaps_channels(chans);
1829 per_cvt = snd_array_new(&spec->cvts);
1833 per_cvt->cvt_nid = cvt_nid;
1834 per_cvt->channels_min = 2;
1836 per_cvt->channels_max = chans;
1837 if (chans > spec->chmap.channels_max)
1838 spec->chmap.channels_max = chans;
1841 err = snd_hda_query_supported_pcm(codec, cvt_nid,
1848 if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids))
1849 spec->cvt_nids[spec->num_cvts] = cvt_nid;
1855 static int hdmi_parse_codec(struct hda_codec *codec)
1860 nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &nid);
1861 if (!nid || nodes < 0) {
1862 codec_warn(codec, "HDMI: failed to get afg sub nodes\n");
1866 for (i = 0; i < nodes; i++, nid++) {
1870 caps = get_wcaps(codec, nid);
1871 type = get_wcaps_type(caps);
1873 if (!(caps & AC_WCAP_DIGITAL))
1877 case AC_WID_AUD_OUT:
1878 hdmi_add_cvt(codec, nid);
1881 hdmi_add_pin(codec, nid);
1891 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1893 struct hda_spdif_out *spdif;
1896 mutex_lock(&codec->spdif_mutex);
1897 spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
1898 /* Add sanity check to pass klockwork check.
1899 * This should never happen.
1901 if (WARN_ON(spdif == NULL))
1903 non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO);
1904 mutex_unlock(&codec->spdif_mutex);
1912 static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1913 struct hda_codec *codec,
1914 unsigned int stream_tag,
1915 unsigned int format,
1916 struct snd_pcm_substream *substream)
1918 hda_nid_t cvt_nid = hinfo->nid;
1919 struct hdmi_spec *spec = codec->spec;
1921 struct hdmi_spec_per_pin *per_pin;
1922 struct snd_pcm_runtime *runtime = substream->runtime;
1927 mutex_lock(&spec->pcm_lock);
1928 pin_idx = hinfo_to_pin_index(codec, hinfo);
1929 if (spec->dyn_pcm_assign && pin_idx < 0) {
1930 /* when dyn_pcm_assign and pcm is not bound to a pin
1931 * skip pin setup and return 0 to make audio playback
1934 pin_cvt_fixup(codec, NULL, cvt_nid);
1935 snd_hda_codec_setup_stream(codec, cvt_nid,
1936 stream_tag, 0, format);
1940 if (snd_BUG_ON(pin_idx < 0)) {
1944 per_pin = get_pin(spec, pin_idx);
1946 /* Verify pin:cvt selections to avoid silent audio after S3.
1947 * After S3, the audio driver restores pin:cvt selections
1948 * but this can happen before gfx is ready and such selection
1949 * is overlooked by HW. Thus multiple pins can share a same
1950 * default convertor and mute control will affect each other,
1951 * which can cause a resumed audio playback become silent
1954 pin_cvt_fixup(codec, per_pin, 0);
1956 /* Call sync_audio_rate to set the N/CTS/M manually if necessary */
1957 /* Todo: add DP1.2 MST audio support later */
1958 if (codec_has_acomp(codec))
1959 snd_hdac_sync_audio_rate(&codec->core, per_pin->pin_nid,
1960 per_pin->dev_id, runtime->rate);
1962 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
1963 mutex_lock(&per_pin->lock);
1964 per_pin->channels = substream->runtime->channels;
1965 per_pin->setup = true;
1967 if (get_wcaps(codec, cvt_nid) & AC_WCAP_STRIPE) {
1968 stripe = snd_hdac_get_stream_stripe_ctl(&codec->bus->core,
1970 snd_hda_codec_write(codec, cvt_nid, 0,
1971 AC_VERB_SET_STRIPE_CONTROL,
1975 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
1976 mutex_unlock(&per_pin->lock);
1977 if (spec->dyn_pin_out) {
1978 snd_hda_set_dev_select(codec, per_pin->pin_nid,
1980 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
1981 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1982 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
1983 AC_VERB_SET_PIN_WIDGET_CONTROL,
1987 /* snd_hda_set_dev_select() has been called before */
1988 err = spec->ops.setup_stream(codec, cvt_nid, per_pin->pin_nid,
1989 per_pin->dev_id, stream_tag, format);
1991 mutex_unlock(&spec->pcm_lock);
1995 static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1996 struct hda_codec *codec,
1997 struct snd_pcm_substream *substream)
1999 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
2003 static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
2004 struct hda_codec *codec,
2005 struct snd_pcm_substream *substream)
2007 struct hdmi_spec *spec = codec->spec;
2008 int cvt_idx, pin_idx, pcm_idx;
2009 struct hdmi_spec_per_cvt *per_cvt;
2010 struct hdmi_spec_per_pin *per_pin;
2015 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
2016 if (snd_BUG_ON(pcm_idx < 0))
2018 cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid);
2019 if (snd_BUG_ON(cvt_idx < 0))
2021 per_cvt = get_cvt(spec, cvt_idx);
2023 snd_BUG_ON(!per_cvt->assigned);
2024 per_cvt->assigned = 0;
2027 azx_stream(get_azx_dev(substream))->stripe = 0;
2029 mutex_lock(&spec->pcm_lock);
2030 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
2031 clear_bit(pcm_idx, &spec->pcm_in_use);
2032 pin_idx = hinfo_to_pin_index(codec, hinfo);
2033 if (spec->dyn_pcm_assign && pin_idx < 0)
2036 if (snd_BUG_ON(pin_idx < 0)) {
2040 per_pin = get_pin(spec, pin_idx);
2042 if (spec->dyn_pin_out) {
2043 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2045 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
2046 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2047 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
2048 AC_VERB_SET_PIN_WIDGET_CONTROL,
2052 mutex_lock(&per_pin->lock);
2053 per_pin->chmap_set = false;
2054 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
2056 per_pin->setup = false;
2057 per_pin->channels = 0;
2058 mutex_unlock(&per_pin->lock);
2060 mutex_unlock(&spec->pcm_lock);
2066 static const struct hda_pcm_ops generic_ops = {
2067 .open = hdmi_pcm_open,
2068 .close = hdmi_pcm_close,
2069 .prepare = generic_hdmi_playback_pcm_prepare,
2070 .cleanup = generic_hdmi_playback_pcm_cleanup,
2073 static int hdmi_get_spk_alloc(struct hdac_device *hdac, int pcm_idx)
2075 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
2076 struct hdmi_spec *spec = codec->spec;
2077 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2082 return per_pin->sink_eld.info.spk_alloc;
2085 static void hdmi_get_chmap(struct hdac_device *hdac, int pcm_idx,
2086 unsigned char *chmap)
2088 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
2089 struct hdmi_spec *spec = codec->spec;
2090 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2092 /* chmap is already set to 0 in caller */
2096 memcpy(chmap, per_pin->chmap, ARRAY_SIZE(per_pin->chmap));
2099 static void hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx,
2100 unsigned char *chmap, int prepared)
2102 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
2103 struct hdmi_spec *spec = codec->spec;
2104 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2108 mutex_lock(&per_pin->lock);
2109 per_pin->chmap_set = true;
2110 memcpy(per_pin->chmap, chmap, ARRAY_SIZE(per_pin->chmap));
2112 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
2113 mutex_unlock(&per_pin->lock);
2116 static bool is_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx)
2118 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
2119 struct hdmi_spec *spec = codec->spec;
2120 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2122 return per_pin ? true:false;
2125 static int generic_hdmi_build_pcms(struct hda_codec *codec)
2127 struct hdmi_spec *spec = codec->spec;
2131 * for non-mst mode, pcm number is the same as before
2132 * for DP MST mode without extra PCM, pcm number is same
2133 * for DP MST mode with extra PCMs, pcm number is
2134 * (nid number + dev_num - 1)
2135 * dev_num is the device entry number in a pin
2138 if (codec->mst_no_extra_pcms)
2139 pcm_num = spec->num_nids;
2141 pcm_num = spec->num_nids + spec->dev_num - 1;
2143 codec_dbg(codec, "hdmi: pcm_num set to %d\n", pcm_num);
2145 for (idx = 0; idx < pcm_num; idx++) {
2146 struct hda_pcm *info;
2147 struct hda_pcm_stream *pstr;
2149 info = snd_hda_codec_pcm_new(codec, "HDMI %d", idx);
2153 spec->pcm_rec[idx].pcm = info;
2155 info->pcm_type = HDA_PCM_TYPE_HDMI;
2156 info->own_chmap = true;
2158 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
2159 pstr->substreams = 1;
2160 pstr->ops = generic_ops;
2161 /* pcm number is less than 16 */
2162 if (spec->pcm_used >= 16)
2164 /* other pstr fields are set in open */
2170 static void free_hdmi_jack_priv(struct snd_jack *jack)
2172 struct hdmi_pcm *pcm = jack->private_data;
2177 static int add_hdmi_jack_kctl(struct hda_codec *codec,
2178 struct hdmi_spec *spec,
2182 struct snd_jack *jack;
2185 err = snd_jack_new(codec->card, name, SND_JACK_AVOUT, &jack,
2190 spec->pcm_rec[pcm_idx].jack = jack;
2191 jack->private_data = &spec->pcm_rec[pcm_idx];
2192 jack->private_free = free_hdmi_jack_priv;
2196 static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx)
2198 char hdmi_str[32] = "HDMI/DP";
2199 struct hdmi_spec *spec = codec->spec;
2200 struct hdmi_spec_per_pin *per_pin;
2201 struct hda_jack_tbl *jack;
2202 int pcmdev = get_pcm_rec(spec, pcm_idx)->device;
2207 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
2209 if (spec->dyn_pcm_assign)
2210 return add_hdmi_jack_kctl(codec, spec, pcm_idx, hdmi_str);
2212 /* for !dyn_pcm_assign, we still use hda_jack for compatibility */
2213 /* if !dyn_pcm_assign, it must be non-MST mode.
2214 * This means pcms and pins are statically mapped.
2215 * And pcm_idx is pin_idx.
2217 per_pin = get_pin(spec, pcm_idx);
2218 phantom_jack = !is_jack_detectable(codec, per_pin->pin_nid);
2220 strncat(hdmi_str, " Phantom",
2221 sizeof(hdmi_str) - strlen(hdmi_str) - 1);
2222 ret = snd_hda_jack_add_kctl_mst(codec, per_pin->pin_nid,
2223 per_pin->dev_id, hdmi_str, phantom_jack,
2227 jack = snd_hda_jack_tbl_get_mst(codec, per_pin->pin_nid,
2231 /* assign jack->jack to pcm_rec[].jack to
2232 * align with dyn_pcm_assign mode
2234 spec->pcm_rec[pcm_idx].jack = jack->jack;
2238 static int generic_hdmi_build_controls(struct hda_codec *codec)
2240 struct hdmi_spec *spec = codec->spec;
2242 int pin_idx, pcm_idx;
2244 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2245 if (!get_pcm_rec(spec, pcm_idx)->pcm) {
2246 /* no PCM: mark this for skipping permanently */
2247 set_bit(pcm_idx, &spec->pcm_bitmap);
2251 err = generic_hdmi_build_jack(codec, pcm_idx);
2255 /* create the spdif for each pcm
2256 * pin will be bound when monitor is connected
2258 if (spec->dyn_pcm_assign)
2259 err = snd_hda_create_dig_out_ctls(codec,
2260 0, spec->cvt_nids[0],
2263 struct hdmi_spec_per_pin *per_pin =
2264 get_pin(spec, pcm_idx);
2265 err = snd_hda_create_dig_out_ctls(codec,
2267 per_pin->mux_nids[0],
2272 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
2274 dev = get_pcm_rec(spec, pcm_idx)->device;
2275 if (dev != SNDRV_PCM_INVALID_DEVICE) {
2276 /* add control for ELD Bytes */
2277 err = hdmi_create_eld_ctl(codec, pcm_idx, dev);
2283 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2284 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2286 hdmi_present_sense(per_pin, 0);
2289 /* add channel maps */
2290 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2291 struct hda_pcm *pcm;
2293 pcm = get_pcm_rec(spec, pcm_idx);
2294 if (!pcm || !pcm->pcm)
2296 err = snd_hdac_add_chmap_ctls(pcm->pcm, pcm_idx, &spec->chmap);
2304 static int generic_hdmi_init_per_pins(struct hda_codec *codec)
2306 struct hdmi_spec *spec = codec->spec;
2309 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2310 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2312 per_pin->codec = codec;
2313 mutex_init(&per_pin->lock);
2314 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
2315 eld_proc_new(per_pin, pin_idx);
2320 static int generic_hdmi_init(struct hda_codec *codec)
2322 struct hdmi_spec *spec = codec->spec;
2325 mutex_lock(&spec->bind_lock);
2326 spec->use_jack_detect = !codec->jackpoll_interval;
2327 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2328 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2329 hda_nid_t pin_nid = per_pin->pin_nid;
2330 int dev_id = per_pin->dev_id;
2332 snd_hda_set_dev_select(codec, pin_nid, dev_id);
2333 hdmi_init_pin(codec, pin_nid);
2334 if (codec_has_acomp(codec))
2336 if (spec->use_jack_detect)
2337 snd_hda_jack_detect_enable(codec, pin_nid, dev_id);
2339 snd_hda_jack_detect_enable_callback_mst(codec, pin_nid,
2343 mutex_unlock(&spec->bind_lock);
2347 static void hdmi_array_init(struct hdmi_spec *spec, int nums)
2349 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums);
2350 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums);
2353 static void hdmi_array_free(struct hdmi_spec *spec)
2355 snd_array_free(&spec->pins);
2356 snd_array_free(&spec->cvts);
2359 static void generic_spec_free(struct hda_codec *codec)
2361 struct hdmi_spec *spec = codec->spec;
2364 hdmi_array_free(spec);
2368 codec->dp_mst = false;
2371 static void generic_hdmi_free(struct hda_codec *codec)
2373 struct hdmi_spec *spec = codec->spec;
2374 int pin_idx, pcm_idx;
2376 if (spec->acomp_registered) {
2377 snd_hdac_acomp_exit(&codec->bus->core);
2378 } else if (codec_has_acomp(codec)) {
2379 snd_hdac_acomp_register_notifier(&codec->bus->core, NULL);
2381 codec->relaxed_resume = 0;
2383 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2384 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2385 cancel_delayed_work_sync(&per_pin->work);
2386 eld_proc_free(per_pin);
2389 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2390 if (spec->pcm_rec[pcm_idx].jack == NULL)
2392 if (spec->dyn_pcm_assign)
2393 snd_device_free(codec->card,
2394 spec->pcm_rec[pcm_idx].jack);
2396 spec->pcm_rec[pcm_idx].jack = NULL;
2399 generic_spec_free(codec);
2403 static int generic_hdmi_resume(struct hda_codec *codec)
2405 struct hdmi_spec *spec = codec->spec;
2408 codec->patch_ops.init(codec);
2409 snd_hda_regmap_sync(codec);
2411 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2412 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2413 hdmi_present_sense(per_pin, 1);
2419 static const struct hda_codec_ops generic_hdmi_patch_ops = {
2420 .init = generic_hdmi_init,
2421 .free = generic_hdmi_free,
2422 .build_pcms = generic_hdmi_build_pcms,
2423 .build_controls = generic_hdmi_build_controls,
2424 .unsol_event = hdmi_unsol_event,
2426 .resume = generic_hdmi_resume,
2430 static const struct hdmi_ops generic_standard_hdmi_ops = {
2431 .pin_get_eld = hdmi_pin_get_eld,
2432 .pin_setup_infoframe = hdmi_pin_setup_infoframe,
2433 .pin_hbr_setup = hdmi_pin_hbr_setup,
2434 .setup_stream = hdmi_setup_stream,
2437 /* allocate codec->spec and assign/initialize generic parser ops */
2438 static int alloc_generic_hdmi(struct hda_codec *codec)
2440 struct hdmi_spec *spec;
2442 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2446 spec->codec = codec;
2447 spec->ops = generic_standard_hdmi_ops;
2448 spec->dev_num = 1; /* initialize to 1 */
2449 mutex_init(&spec->pcm_lock);
2450 mutex_init(&spec->bind_lock);
2451 snd_hdac_register_chmap_ops(&codec->core, &spec->chmap);
2453 spec->chmap.ops.get_chmap = hdmi_get_chmap;
2454 spec->chmap.ops.set_chmap = hdmi_set_chmap;
2455 spec->chmap.ops.is_pcm_attached = is_hdmi_pcm_attached;
2456 spec->chmap.ops.get_spk_alloc = hdmi_get_spk_alloc,
2459 hdmi_array_init(spec, 4);
2461 codec->patch_ops = generic_hdmi_patch_ops;
2466 /* generic HDMI parser */
2467 static int patch_generic_hdmi(struct hda_codec *codec)
2471 err = alloc_generic_hdmi(codec);
2475 err = hdmi_parse_codec(codec);
2477 generic_spec_free(codec);
2481 generic_hdmi_init_per_pins(codec);
2486 * generic audio component binding
2489 /* turn on / off the unsol event jack detection dynamically */
2490 static void reprogram_jack_detect(struct hda_codec *codec, hda_nid_t nid,
2491 int dev_id, bool use_acomp)
2493 struct hda_jack_tbl *tbl;
2495 tbl = snd_hda_jack_tbl_get_mst(codec, nid, dev_id);
2497 /* clear unsol even if component notifier is used, or re-enable
2498 * if notifier is cleared
2500 unsigned int val = use_acomp ? 0 : (AC_USRSP_EN | tbl->tag);
2501 snd_hda_codec_write_cache(codec, nid, 0,
2502 AC_VERB_SET_UNSOLICITED_ENABLE, val);
2504 /* if no jack entry was defined beforehand, create a new one
2505 * at need (i.e. only when notifier is cleared)
2508 snd_hda_jack_detect_enable(codec, nid, dev_id);
2512 /* set up / clear component notifier dynamically */
2513 static void generic_acomp_notifier_set(struct drm_audio_component *acomp,
2516 struct hdmi_spec *spec;
2519 spec = container_of(acomp->audio_ops, struct hdmi_spec, drm_audio_ops);
2520 mutex_lock(&spec->bind_lock);
2521 spec->use_acomp_notifier = use_acomp;
2522 spec->codec->relaxed_resume = use_acomp;
2523 /* reprogram each jack detection logic depending on the notifier */
2524 if (spec->use_jack_detect) {
2525 for (i = 0; i < spec->num_pins; i++)
2526 reprogram_jack_detect(spec->codec,
2527 get_pin(spec, i)->pin_nid,
2528 get_pin(spec, i)->dev_id,
2531 mutex_unlock(&spec->bind_lock);
2534 /* enable / disable the notifier via master bind / unbind */
2535 static int generic_acomp_master_bind(struct device *dev,
2536 struct drm_audio_component *acomp)
2538 generic_acomp_notifier_set(acomp, true);
2542 static void generic_acomp_master_unbind(struct device *dev,
2543 struct drm_audio_component *acomp)
2545 generic_acomp_notifier_set(acomp, false);
2548 /* check whether both HD-audio and DRM PCI devices belong to the same bus */
2549 static int match_bound_vga(struct device *dev, int subtype, void *data)
2551 struct hdac_bus *bus = data;
2552 struct pci_dev *pci, *master;
2554 if (!dev_is_pci(dev) || !dev_is_pci(bus->dev))
2556 master = to_pci_dev(bus->dev);
2557 pci = to_pci_dev(dev);
2558 return master->bus == pci->bus;
2561 /* audio component notifier for AMD/Nvidia HDMI codecs */
2562 static void generic_acomp_pin_eld_notify(void *audio_ptr, int port, int dev_id)
2564 struct hda_codec *codec = audio_ptr;
2565 struct hdmi_spec *spec = codec->spec;
2566 hda_nid_t pin_nid = spec->port2pin(codec, port);
2570 if (get_wcaps_type(get_wcaps(codec, pin_nid)) != AC_WID_PIN)
2572 /* skip notification during system suspend (but not in runtime PM);
2573 * the state will be updated at resume
2575 if (snd_power_get_state(codec->card) != SNDRV_CTL_POWER_D0)
2577 /* ditto during suspend/resume process itself */
2578 if (snd_hdac_is_in_pm(&codec->core))
2581 check_presence_and_report(codec, pin_nid, dev_id);
2584 /* set up the private drm_audio_ops from the template */
2585 static void setup_drm_audio_ops(struct hda_codec *codec,
2586 const struct drm_audio_component_audio_ops *ops)
2588 struct hdmi_spec *spec = codec->spec;
2590 spec->drm_audio_ops.audio_ptr = codec;
2591 /* intel_audio_codec_enable() or intel_audio_codec_disable()
2592 * will call pin_eld_notify with using audio_ptr pointer
2593 * We need make sure audio_ptr is really setup
2596 spec->drm_audio_ops.pin2port = ops->pin2port;
2597 spec->drm_audio_ops.pin_eld_notify = ops->pin_eld_notify;
2598 spec->drm_audio_ops.master_bind = ops->master_bind;
2599 spec->drm_audio_ops.master_unbind = ops->master_unbind;
2602 /* initialize the generic HDMI audio component */
2603 static void generic_acomp_init(struct hda_codec *codec,
2604 const struct drm_audio_component_audio_ops *ops,
2605 int (*port2pin)(struct hda_codec *, int))
2607 struct hdmi_spec *spec = codec->spec;
2609 spec->port2pin = port2pin;
2610 setup_drm_audio_ops(codec, ops);
2611 if (!snd_hdac_acomp_init(&codec->bus->core, &spec->drm_audio_ops,
2612 match_bound_vga, 0)) {
2613 spec->acomp_registered = true;
2614 codec->bus->keep_power = 0;
2619 * Intel codec parsers and helpers
2622 #define INTEL_GET_VENDOR_VERB 0xf81
2623 #define INTEL_SET_VENDOR_VERB 0x781
2624 #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
2625 #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
2627 static void intel_haswell_enable_all_pins(struct hda_codec *codec,
2630 unsigned int vendor_param;
2631 struct hdmi_spec *spec = codec->spec;
2633 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2634 INTEL_GET_VENDOR_VERB, 0);
2635 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
2638 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
2639 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2640 INTEL_SET_VENDOR_VERB, vendor_param);
2641 if (vendor_param == -1)
2645 snd_hda_codec_update_widgets(codec);
2648 static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
2650 unsigned int vendor_param;
2651 struct hdmi_spec *spec = codec->spec;
2653 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2654 INTEL_GET_VENDOR_VERB, 0);
2655 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
2658 /* enable DP1.2 mode */
2659 vendor_param |= INTEL_EN_DP12;
2660 snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB);
2661 snd_hda_codec_write_cache(codec, spec->vendor_nid, 0,
2662 INTEL_SET_VENDOR_VERB, vendor_param);
2665 /* Haswell needs to re-issue the vendor-specific verbs before turning to D0.
2666 * Otherwise you may get severe h/w communication errors.
2668 static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2669 unsigned int power_state)
2671 if (power_state == AC_PWRST_D0) {
2672 intel_haswell_enable_all_pins(codec, false);
2673 intel_haswell_fixup_enable_dp12(codec);
2676 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
2677 snd_hda_codec_set_power_to_all(codec, fg, power_state);
2680 /* There is a fixed mapping between audio pin node and display port.
2681 * on SNB, IVY, HSW, BSW, SKL, BXT, KBL:
2682 * Pin Widget 5 - PORT B (port = 1 in i915 driver)
2683 * Pin Widget 6 - PORT C (port = 2 in i915 driver)
2684 * Pin Widget 7 - PORT D (port = 3 in i915 driver)
2687 * Pin Widget 4 - PORT B (port = 1 in i915 driver)
2688 * Pin Widget 5 - PORT C (port = 2 in i915 driver)
2689 * Pin Widget 6 - PORT D (port = 3 in i915 driver)
2691 static int intel_base_nid(struct hda_codec *codec)
2693 switch (codec->core.vendor_id) {
2694 case 0x80860054: /* ILK */
2695 case 0x80862804: /* ILK */
2696 case 0x80862882: /* VLV */
2703 static int intel_pin2port(void *audio_ptr, int pin_nid)
2705 struct hda_codec *codec = audio_ptr;
2706 struct hdmi_spec *spec = codec->spec;
2709 if (!spec->port_num) {
2710 base_nid = intel_base_nid(codec);
2711 if (WARN_ON(pin_nid < base_nid || pin_nid >= base_nid + 3))
2713 return pin_nid - base_nid + 1;
2717 * looking for the pin number in the mapping table and return
2718 * the index which indicate the port number
2720 for (i = 0; i < spec->port_num; i++) {
2721 if (pin_nid == spec->port_map[i])
2725 codec_info(codec, "Can't find the HDMI/DP port for pin %d\n", pin_nid);
2729 static int intel_port2pin(struct hda_codec *codec, int port)
2731 struct hdmi_spec *spec = codec->spec;
2733 if (!spec->port_num) {
2734 /* we assume only from port-B to port-D */
2735 if (port < 1 || port > 3)
2737 return port + intel_base_nid(codec) - 1;
2740 if (port < 0 || port >= spec->port_num)
2742 return spec->port_map[port];
2745 static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe)
2747 struct hda_codec *codec = audio_ptr;
2751 pin_nid = intel_port2pin(codec, port);
2754 /* skip notification during system suspend (but not in runtime PM);
2755 * the state will be updated at resume
2757 if (snd_power_get_state(codec->card) != SNDRV_CTL_POWER_D0)
2759 /* ditto during suspend/resume process itself */
2760 if (snd_hdac_is_in_pm(&codec->core))
2763 snd_hdac_i915_set_bclk(&codec->bus->core);
2764 check_presence_and_report(codec, pin_nid, dev_id);
2767 static const struct drm_audio_component_audio_ops intel_audio_ops = {
2768 .pin2port = intel_pin2port,
2769 .pin_eld_notify = intel_pin_eld_notify,
2772 /* register i915 component pin_eld_notify callback */
2773 static void register_i915_notifier(struct hda_codec *codec)
2775 struct hdmi_spec *spec = codec->spec;
2777 spec->use_acomp_notifier = true;
2778 spec->port2pin = intel_port2pin;
2779 setup_drm_audio_ops(codec, &intel_audio_ops);
2780 snd_hdac_acomp_register_notifier(&codec->bus->core,
2781 &spec->drm_audio_ops);
2782 /* no need for forcible resume for jack check thanks to notifier */
2783 codec->relaxed_resume = 1;
2786 /* setup_stream ops override for HSW+ */
2787 static int i915_hsw_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
2788 hda_nid_t pin_nid, int dev_id, u32 stream_tag,
2791 haswell_verify_D0(codec, cvt_nid, pin_nid);
2792 return hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id,
2793 stream_tag, format);
2796 /* pin_cvt_fixup ops override for HSW+ and VLV+ */
2797 static void i915_pin_cvt_fixup(struct hda_codec *codec,
2798 struct hdmi_spec_per_pin *per_pin,
2802 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2804 intel_verify_pin_cvt_connect(codec, per_pin);
2805 intel_not_share_assigned_cvt(codec, per_pin->pin_nid,
2806 per_pin->dev_id, per_pin->mux_idx);
2808 intel_not_share_assigned_cvt_nid(codec, 0, 0, cvt_nid);
2812 /* precondition and allocation for Intel codecs */
2813 static int alloc_intel_hdmi(struct hda_codec *codec)
2817 /* requires i915 binding */
2818 if (!codec->bus->core.audio_component) {
2819 codec_info(codec, "No i915 binding for Intel HDMI/DP codec\n");
2820 /* set probe_id here to prevent generic fallback binding */
2821 codec->probe_id = HDA_CODEC_ID_SKIP_PROBE;
2825 err = alloc_generic_hdmi(codec);
2828 /* no need to handle unsol events */
2829 codec->patch_ops.unsol_event = NULL;
2833 /* parse and post-process for Intel codecs */
2834 static int parse_intel_hdmi(struct hda_codec *codec)
2836 int err, retries = 3;
2839 err = hdmi_parse_codec(codec);
2840 } while (err < 0 && retries--);
2843 generic_spec_free(codec);
2847 generic_hdmi_init_per_pins(codec);
2848 register_i915_notifier(codec);
2852 /* Intel Haswell and onwards; audio component with eld notifier */
2853 static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid,
2854 const int *port_map, int port_num)
2856 struct hdmi_spec *spec;
2859 err = alloc_intel_hdmi(codec);
2863 codec->dp_mst = true;
2864 spec->dyn_pcm_assign = true;
2865 spec->vendor_nid = vendor_nid;
2866 spec->port_map = port_map;
2867 spec->port_num = port_num;
2868 spec->intel_hsw_fixup = true;
2870 intel_haswell_enable_all_pins(codec, true);
2871 intel_haswell_fixup_enable_dp12(codec);
2873 codec->display_power_control = 1;
2875 codec->patch_ops.set_power_state = haswell_set_power_state;
2876 codec->depop_delay = 0;
2877 codec->auto_runtime_pm = 1;
2879 spec->ops.setup_stream = i915_hsw_setup_stream;
2880 spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup;
2882 return parse_intel_hdmi(codec);
2885 static int patch_i915_hsw_hdmi(struct hda_codec *codec)
2887 return intel_hsw_common_init(codec, 0x08, NULL, 0);
2890 static int patch_i915_glk_hdmi(struct hda_codec *codec)
2892 return intel_hsw_common_init(codec, 0x0b, NULL, 0);
2895 static int patch_i915_icl_hdmi(struct hda_codec *codec)
2898 * pin to port mapping table where the value indicate the pin number and
2899 * the index indicate the port number.
2901 static const int map[] = {0x0, 0x4, 0x6, 0x8, 0xa, 0xb};
2903 return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map));
2906 static int patch_i915_tgl_hdmi(struct hda_codec *codec)
2909 * pin to port mapping table where the value indicate the pin number and
2910 * the index indicate the port number.
2912 static const int map[] = {0x4, 0x6, 0x8, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
2914 return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map));
2917 /* Intel Baytrail and Braswell; with eld notifier */
2918 static int patch_i915_byt_hdmi(struct hda_codec *codec)
2920 struct hdmi_spec *spec;
2923 err = alloc_intel_hdmi(codec);
2928 /* For Valleyview/Cherryview, only the display codec is in the display
2929 * power well and can use link_power ops to request/release the power.
2931 codec->display_power_control = 1;
2933 codec->depop_delay = 0;
2934 codec->auto_runtime_pm = 1;
2936 spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup;
2938 return parse_intel_hdmi(codec);
2941 /* Intel IronLake, SandyBridge and IvyBridge; with eld notifier */
2942 static int patch_i915_cpt_hdmi(struct hda_codec *codec)
2946 err = alloc_intel_hdmi(codec);
2949 return parse_intel_hdmi(codec);
2953 * Shared non-generic implementations
2956 static int simple_playback_build_pcms(struct hda_codec *codec)
2958 struct hdmi_spec *spec = codec->spec;
2959 struct hda_pcm *info;
2961 struct hda_pcm_stream *pstr;
2962 struct hdmi_spec_per_cvt *per_cvt;
2964 per_cvt = get_cvt(spec, 0);
2965 chans = get_wcaps(codec, per_cvt->cvt_nid);
2966 chans = get_wcaps_channels(chans);
2968 info = snd_hda_codec_pcm_new(codec, "HDMI 0");
2971 spec->pcm_rec[0].pcm = info;
2972 info->pcm_type = HDA_PCM_TYPE_HDMI;
2973 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
2974 *pstr = spec->pcm_playback;
2975 pstr->nid = per_cvt->cvt_nid;
2976 if (pstr->channels_max <= 2 && chans && chans <= 16)
2977 pstr->channels_max = chans;
2982 /* unsolicited event for jack sensing */
2983 static void simple_hdmi_unsol_event(struct hda_codec *codec,
2986 snd_hda_jack_set_dirty_all(codec);
2987 snd_hda_jack_report_sync(codec);
2990 /* generic_hdmi_build_jack can be used for simple_hdmi, too,
2991 * as long as spec->pins[] is set correctly
2993 #define simple_hdmi_build_jack generic_hdmi_build_jack
2995 static int simple_playback_build_controls(struct hda_codec *codec)
2997 struct hdmi_spec *spec = codec->spec;
2998 struct hdmi_spec_per_cvt *per_cvt;
3001 per_cvt = get_cvt(spec, 0);
3002 err = snd_hda_create_dig_out_ctls(codec, per_cvt->cvt_nid,
3007 return simple_hdmi_build_jack(codec, 0);
3010 static int simple_playback_init(struct hda_codec *codec)
3012 struct hdmi_spec *spec = codec->spec;
3013 struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0);
3014 hda_nid_t pin = per_pin->pin_nid;
3016 snd_hda_codec_write(codec, pin, 0,
3017 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3018 /* some codecs require to unmute the pin */
3019 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
3020 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3022 snd_hda_jack_detect_enable(codec, pin, per_pin->dev_id);
3026 static void simple_playback_free(struct hda_codec *codec)
3028 struct hdmi_spec *spec = codec->spec;
3030 hdmi_array_free(spec);
3035 * Nvidia specific implementations
3038 #define Nv_VERB_SET_Channel_Allocation 0xF79
3039 #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
3040 #define Nv_VERB_SET_Audio_Protection_On 0xF98
3041 #define Nv_VERB_SET_Audio_Protection_Off 0xF99
3043 #define nvhdmi_master_con_nid_7x 0x04
3044 #define nvhdmi_master_pin_nid_7x 0x05
3046 static const hda_nid_t nvhdmi_con_nids_7x[4] = {
3047 /*front, rear, clfe, rear_surr */
3051 static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = {
3052 /* set audio protect on */
3053 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
3054 /* enable digital output on pin widget */
3055 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3059 static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = {
3060 /* set audio protect on */
3061 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
3062 /* enable digital output on pin widget */
3063 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3064 { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3065 { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3066 { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3067 { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3071 #ifdef LIMITED_RATE_FMT_SUPPORT
3072 /* support only the safe format and rate */
3073 #define SUPPORTED_RATES SNDRV_PCM_RATE_48000
3074 #define SUPPORTED_MAXBPS 16
3075 #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
3077 /* support all rates and formats */
3078 #define SUPPORTED_RATES \
3079 (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
3080 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
3081 SNDRV_PCM_RATE_192000)
3082 #define SUPPORTED_MAXBPS 24
3083 #define SUPPORTED_FORMATS \
3084 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
3087 static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
3089 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
3093 static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
3095 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
3099 static const unsigned int channels_2_6_8[] = {
3103 static const unsigned int channels_2_8[] = {
3107 static const struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
3108 .count = ARRAY_SIZE(channels_2_6_8),
3109 .list = channels_2_6_8,
3113 static const struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
3114 .count = ARRAY_SIZE(channels_2_8),
3115 .list = channels_2_8,
3119 static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
3120 struct hda_codec *codec,
3121 struct snd_pcm_substream *substream)
3123 struct hdmi_spec *spec = codec->spec;
3124 const struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
3126 switch (codec->preset->vendor_id) {
3131 hw_constraints_channels = &hw_constraints_2_8_channels;
3134 hw_constraints_channels = &hw_constraints_2_6_8_channels;
3140 if (hw_constraints_channels != NULL) {
3141 snd_pcm_hw_constraint_list(substream->runtime, 0,
3142 SNDRV_PCM_HW_PARAM_CHANNELS,
3143 hw_constraints_channels);
3145 snd_pcm_hw_constraint_step(substream->runtime, 0,
3146 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
3149 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3152 static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
3153 struct hda_codec *codec,
3154 struct snd_pcm_substream *substream)
3156 struct hdmi_spec *spec = codec->spec;
3157 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3160 static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3161 struct hda_codec *codec,
3162 unsigned int stream_tag,
3163 unsigned int format,
3164 struct snd_pcm_substream *substream)
3166 struct hdmi_spec *spec = codec->spec;
3167 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3168 stream_tag, format, substream);
3171 static const struct hda_pcm_stream simple_pcm_playback = {
3176 .open = simple_playback_pcm_open,
3177 .close = simple_playback_pcm_close,
3178 .prepare = simple_playback_pcm_prepare
3182 static const struct hda_codec_ops simple_hdmi_patch_ops = {
3183 .build_controls = simple_playback_build_controls,
3184 .build_pcms = simple_playback_build_pcms,
3185 .init = simple_playback_init,
3186 .free = simple_playback_free,
3187 .unsol_event = simple_hdmi_unsol_event,
3190 static int patch_simple_hdmi(struct hda_codec *codec,
3191 hda_nid_t cvt_nid, hda_nid_t pin_nid)
3193 struct hdmi_spec *spec;
3194 struct hdmi_spec_per_cvt *per_cvt;
3195 struct hdmi_spec_per_pin *per_pin;
3197 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3201 spec->codec = codec;
3203 hdmi_array_init(spec, 1);
3205 spec->multiout.num_dacs = 0; /* no analog */
3206 spec->multiout.max_channels = 2;
3207 spec->multiout.dig_out_nid = cvt_nid;
3210 per_pin = snd_array_new(&spec->pins);
3211 per_cvt = snd_array_new(&spec->cvts);
3212 if (!per_pin || !per_cvt) {
3213 simple_playback_free(codec);
3216 per_cvt->cvt_nid = cvt_nid;
3217 per_pin->pin_nid = pin_nid;
3218 spec->pcm_playback = simple_pcm_playback;
3220 codec->patch_ops = simple_hdmi_patch_ops;
3225 static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
3228 unsigned int chanmask;
3229 int chan = channels ? (channels - 1) : 1;
3248 /* Set the audio infoframe channel allocation and checksum fields. The
3249 * channel count is computed implicitly by the hardware. */
3250 snd_hda_codec_write(codec, 0x1, 0,
3251 Nv_VERB_SET_Channel_Allocation, chanmask);
3253 snd_hda_codec_write(codec, 0x1, 0,
3254 Nv_VERB_SET_Info_Frame_Checksum,
3255 (0x71 - chan - chanmask));
3258 static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
3259 struct hda_codec *codec,
3260 struct snd_pcm_substream *substream)
3262 struct hdmi_spec *spec = codec->spec;
3265 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
3266 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
3267 for (i = 0; i < 4; i++) {
3268 /* set the stream id */
3269 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
3270 AC_VERB_SET_CHANNEL_STREAMID, 0);
3271 /* set the stream format */
3272 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
3273 AC_VERB_SET_STREAM_FORMAT, 0);
3276 /* The audio hardware sends a channel count of 0x7 (8ch) when all the
3277 * streams are disabled. */
3278 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
3280 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3283 static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
3284 struct hda_codec *codec,
3285 unsigned int stream_tag,
3286 unsigned int format,
3287 struct snd_pcm_substream *substream)
3290 unsigned int dataDCC2, channel_id;
3292 struct hdmi_spec *spec = codec->spec;
3293 struct hda_spdif_out *spdif;
3294 struct hdmi_spec_per_cvt *per_cvt;
3296 mutex_lock(&codec->spdif_mutex);
3297 per_cvt = get_cvt(spec, 0);
3298 spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid);
3300 chs = substream->runtime->channels;
3304 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
3305 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
3306 snd_hda_codec_write(codec,
3307 nvhdmi_master_con_nid_7x,
3309 AC_VERB_SET_DIGI_CONVERT_1,
3310 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
3312 /* set the stream id */
3313 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
3314 AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
3316 /* set the stream format */
3317 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
3318 AC_VERB_SET_STREAM_FORMAT, format);
3320 /* turn on again (if needed) */
3321 /* enable and set the channel status audio/data flag */
3322 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
3323 snd_hda_codec_write(codec,
3324 nvhdmi_master_con_nid_7x,
3326 AC_VERB_SET_DIGI_CONVERT_1,
3327 spdif->ctls & 0xff);
3328 snd_hda_codec_write(codec,
3329 nvhdmi_master_con_nid_7x,
3331 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
3334 for (i = 0; i < 4; i++) {
3340 /* turn off SPDIF once;
3341 *otherwise the IEC958 bits won't be updated
3343 if (codec->spdif_status_reset &&
3344 (spdif->ctls & AC_DIG1_ENABLE))
3345 snd_hda_codec_write(codec,
3346 nvhdmi_con_nids_7x[i],
3348 AC_VERB_SET_DIGI_CONVERT_1,
3349 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
3350 /* set the stream id */
3351 snd_hda_codec_write(codec,
3352 nvhdmi_con_nids_7x[i],
3354 AC_VERB_SET_CHANNEL_STREAMID,
3355 (stream_tag << 4) | channel_id);
3356 /* set the stream format */
3357 snd_hda_codec_write(codec,
3358 nvhdmi_con_nids_7x[i],
3360 AC_VERB_SET_STREAM_FORMAT,
3362 /* turn on again (if needed) */
3363 /* enable and set the channel status audio/data flag */
3364 if (codec->spdif_status_reset &&
3365 (spdif->ctls & AC_DIG1_ENABLE)) {
3366 snd_hda_codec_write(codec,
3367 nvhdmi_con_nids_7x[i],
3369 AC_VERB_SET_DIGI_CONVERT_1,
3370 spdif->ctls & 0xff);
3371 snd_hda_codec_write(codec,
3372 nvhdmi_con_nids_7x[i],
3374 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
3378 nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
3380 mutex_unlock(&codec->spdif_mutex);
3384 static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
3388 .nid = nvhdmi_master_con_nid_7x,
3389 .rates = SUPPORTED_RATES,
3390 .maxbps = SUPPORTED_MAXBPS,
3391 .formats = SUPPORTED_FORMATS,
3393 .open = simple_playback_pcm_open,
3394 .close = nvhdmi_8ch_7x_pcm_close,
3395 .prepare = nvhdmi_8ch_7x_pcm_prepare
3399 static int patch_nvhdmi_2ch(struct hda_codec *codec)
3401 struct hdmi_spec *spec;
3402 int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
3403 nvhdmi_master_pin_nid_7x);
3407 codec->patch_ops.init = nvhdmi_7x_init_2ch;
3408 /* override the PCM rates, etc, as the codec doesn't give full list */
3410 spec->pcm_playback.rates = SUPPORTED_RATES;
3411 spec->pcm_playback.maxbps = SUPPORTED_MAXBPS;
3412 spec->pcm_playback.formats = SUPPORTED_FORMATS;
3416 static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
3418 struct hdmi_spec *spec = codec->spec;
3419 int err = simple_playback_build_pcms(codec);
3421 struct hda_pcm *info = get_pcm_rec(spec, 0);
3422 info->own_chmap = true;
3427 static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
3429 struct hdmi_spec *spec = codec->spec;
3430 struct hda_pcm *info;
3431 struct snd_pcm_chmap *chmap;
3434 err = simple_playback_build_controls(codec);
3438 /* add channel maps */
3439 info = get_pcm_rec(spec, 0);
3440 err = snd_pcm_add_chmap_ctls(info->pcm,
3441 SNDRV_PCM_STREAM_PLAYBACK,
3442 snd_pcm_alt_chmaps, 8, 0, &chmap);
3445 switch (codec->preset->vendor_id) {
3450 chmap->channel_mask = (1U << 2) | (1U << 8);
3453 chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8);
3458 static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
3460 struct hdmi_spec *spec;
3461 int err = patch_nvhdmi_2ch(codec);
3465 spec->multiout.max_channels = 8;
3466 spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x;
3467 codec->patch_ops.init = nvhdmi_7x_init_8ch;
3468 codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
3469 codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
3471 /* Initialize the audio infoframe channel mask and checksum to something
3473 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
3479 * NVIDIA codecs ignore ASP mapping for 2ch - confirmed on:
3483 static int nvhdmi_chmap_cea_alloc_validate_get_type(struct hdac_chmap *chmap,
3484 struct hdac_cea_channel_speaker_allocation *cap, int channels)
3486 if (cap->ca_index == 0x00 && channels == 2)
3487 return SNDRV_CTL_TLVT_CHMAP_FIXED;
3489 /* If the speaker allocation matches the channel count, it is OK. */
3490 if (cap->channels != channels)
3493 /* all channels are remappable freely */
3494 return SNDRV_CTL_TLVT_CHMAP_VAR;
3497 static int nvhdmi_chmap_validate(struct hdac_chmap *chmap,
3498 int ca, int chs, unsigned char *map)
3500 if (ca == 0x00 && (map[0] != SNDRV_CHMAP_FL || map[1] != SNDRV_CHMAP_FR))
3506 /* map from pin NID to port; port is 0-based */
3507 /* for Nvidia: assume widget NID starting from 4, with step 1 (4, 5, 6, ...) */
3508 static int nvhdmi_pin2port(void *audio_ptr, int pin_nid)
3513 /* reverse-map from port to pin NID: see above */
3514 static int nvhdmi_port2pin(struct hda_codec *codec, int port)
3519 static const struct drm_audio_component_audio_ops nvhdmi_audio_ops = {
3520 .pin2port = nvhdmi_pin2port,
3521 .pin_eld_notify = generic_acomp_pin_eld_notify,
3522 .master_bind = generic_acomp_master_bind,
3523 .master_unbind = generic_acomp_master_unbind,
3526 static int patch_nvhdmi(struct hda_codec *codec)
3528 struct hdmi_spec *spec;
3531 err = alloc_generic_hdmi(codec);
3534 codec->dp_mst = true;
3537 spec->dyn_pcm_assign = true;
3539 err = hdmi_parse_codec(codec);
3541 generic_spec_free(codec);
3545 generic_hdmi_init_per_pins(codec);
3547 spec->dyn_pin_out = true;
3549 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
3550 nvhdmi_chmap_cea_alloc_validate_get_type;
3551 spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate;
3553 codec->link_down_at_suspend = 1;
3555 generic_acomp_init(codec, &nvhdmi_audio_ops, nvhdmi_port2pin);
3560 static int patch_nvhdmi_legacy(struct hda_codec *codec)
3562 struct hdmi_spec *spec;
3565 err = patch_generic_hdmi(codec);
3570 spec->dyn_pin_out = true;
3572 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
3573 nvhdmi_chmap_cea_alloc_validate_get_type;
3574 spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate;
3576 codec->link_down_at_suspend = 1;
3582 * The HDA codec on NVIDIA Tegra contains two scratch registers that are
3583 * accessed using vendor-defined verbs. These registers can be used for
3584 * interoperability between the HDA and HDMI drivers.
3587 /* Audio Function Group node */
3588 #define NVIDIA_AFG_NID 0x01
3591 * The SCRATCH0 register is used to notify the HDMI codec of changes in audio
3592 * format. On Tegra, bit 31 is used as a trigger that causes an interrupt to
3593 * be raised in the HDMI codec. The remainder of the bits is arbitrary. This
3594 * implementation stores the HDA format (see AC_FMT_*) in bits [15:0] and an
3595 * additional bit (at position 30) to signal the validity of the format.
3597 * | 31 | 30 | 29 16 | 15 0 |
3598 * +---------+-------+--------+--------+
3599 * | TRIGGER | VALID | UNUSED | FORMAT |
3600 * +-----------------------------------|
3602 * Note that for the trigger bit to take effect it needs to change value
3603 * (i.e. it needs to be toggled).
3605 #define NVIDIA_GET_SCRATCH0 0xfa6
3606 #define NVIDIA_SET_SCRATCH0_BYTE0 0xfa7
3607 #define NVIDIA_SET_SCRATCH0_BYTE1 0xfa8
3608 #define NVIDIA_SET_SCRATCH0_BYTE2 0xfa9
3609 #define NVIDIA_SET_SCRATCH0_BYTE3 0xfaa
3610 #define NVIDIA_SCRATCH_TRIGGER (1 << 7)
3611 #define NVIDIA_SCRATCH_VALID (1 << 6)
3613 #define NVIDIA_GET_SCRATCH1 0xfab
3614 #define NVIDIA_SET_SCRATCH1_BYTE0 0xfac
3615 #define NVIDIA_SET_SCRATCH1_BYTE1 0xfad
3616 #define NVIDIA_SET_SCRATCH1_BYTE2 0xfae
3617 #define NVIDIA_SET_SCRATCH1_BYTE3 0xfaf
3620 * The format parameter is the HDA audio format (see AC_FMT_*). If set to 0,
3621 * the format is invalidated so that the HDMI codec can be disabled.
3623 static void tegra_hdmi_set_format(struct hda_codec *codec, unsigned int format)
3627 /* bits [31:30] contain the trigger and valid bits */
3628 value = snd_hda_codec_read(codec, NVIDIA_AFG_NID, 0,
3629 NVIDIA_GET_SCRATCH0, 0);
3630 value = (value >> 24) & 0xff;
3632 /* bits [15:0] are used to store the HDA format */
3633 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3634 NVIDIA_SET_SCRATCH0_BYTE0,
3635 (format >> 0) & 0xff);
3636 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3637 NVIDIA_SET_SCRATCH0_BYTE1,
3638 (format >> 8) & 0xff);
3640 /* bits [16:24] are unused */
3641 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3642 NVIDIA_SET_SCRATCH0_BYTE2, 0);
3645 * Bit 30 signals that the data is valid and hence that HDMI audio can
3649 value &= ~NVIDIA_SCRATCH_VALID;
3651 value |= NVIDIA_SCRATCH_VALID;
3654 * Whenever the trigger bit is toggled, an interrupt is raised in the
3655 * HDMI codec. The HDMI driver will use that as trigger to update its
3658 value ^= NVIDIA_SCRATCH_TRIGGER;
3660 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3661 NVIDIA_SET_SCRATCH0_BYTE3, value);
3664 static int tegra_hdmi_pcm_prepare(struct hda_pcm_stream *hinfo,
3665 struct hda_codec *codec,
3666 unsigned int stream_tag,
3667 unsigned int format,
3668 struct snd_pcm_substream *substream)
3672 err = generic_hdmi_playback_pcm_prepare(hinfo, codec, stream_tag,
3677 /* notify the HDMI codec of the format change */
3678 tegra_hdmi_set_format(codec, format);
3683 static int tegra_hdmi_pcm_cleanup(struct hda_pcm_stream *hinfo,
3684 struct hda_codec *codec,
3685 struct snd_pcm_substream *substream)
3687 /* invalidate the format in the HDMI codec */
3688 tegra_hdmi_set_format(codec, 0);
3690 return generic_hdmi_playback_pcm_cleanup(hinfo, codec, substream);
3693 static struct hda_pcm *hda_find_pcm_by_type(struct hda_codec *codec, int type)
3695 struct hdmi_spec *spec = codec->spec;
3698 for (i = 0; i < spec->num_pins; i++) {
3699 struct hda_pcm *pcm = get_pcm_rec(spec, i);
3701 if (pcm->pcm_type == type)
3708 static int tegra_hdmi_build_pcms(struct hda_codec *codec)
3710 struct hda_pcm_stream *stream;
3711 struct hda_pcm *pcm;
3714 err = generic_hdmi_build_pcms(codec);
3718 pcm = hda_find_pcm_by_type(codec, HDA_PCM_TYPE_HDMI);
3723 * Override ->prepare() and ->cleanup() operations to notify the HDMI
3724 * codec about format changes.
3726 stream = &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
3727 stream->ops.prepare = tegra_hdmi_pcm_prepare;
3728 stream->ops.cleanup = tegra_hdmi_pcm_cleanup;
3733 static int patch_tegra_hdmi(struct hda_codec *codec)
3737 err = patch_generic_hdmi(codec);
3741 codec->patch_ops.build_pcms = tegra_hdmi_build_pcms;
3747 * ATI/AMD-specific implementations
3750 #define is_amdhdmi_rev3_or_later(codec) \
3751 ((codec)->core.vendor_id == 0x1002aa01 && \
3752 ((codec)->core.revision_id & 0xff00) >= 0x0300)
3753 #define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec)
3755 /* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */
3756 #define ATI_VERB_SET_CHANNEL_ALLOCATION 0x771
3757 #define ATI_VERB_SET_DOWNMIX_INFO 0x772
3758 #define ATI_VERB_SET_MULTICHANNEL_01 0x777
3759 #define ATI_VERB_SET_MULTICHANNEL_23 0x778
3760 #define ATI_VERB_SET_MULTICHANNEL_45 0x779
3761 #define ATI_VERB_SET_MULTICHANNEL_67 0x77a
3762 #define ATI_VERB_SET_HBR_CONTROL 0x77c
3763 #define ATI_VERB_SET_MULTICHANNEL_1 0x785
3764 #define ATI_VERB_SET_MULTICHANNEL_3 0x786
3765 #define ATI_VERB_SET_MULTICHANNEL_5 0x787
3766 #define ATI_VERB_SET_MULTICHANNEL_7 0x788
3767 #define ATI_VERB_SET_MULTICHANNEL_MODE 0x789
3768 #define ATI_VERB_GET_CHANNEL_ALLOCATION 0xf71
3769 #define ATI_VERB_GET_DOWNMIX_INFO 0xf72
3770 #define ATI_VERB_GET_MULTICHANNEL_01 0xf77
3771 #define ATI_VERB_GET_MULTICHANNEL_23 0xf78
3772 #define ATI_VERB_GET_MULTICHANNEL_45 0xf79
3773 #define ATI_VERB_GET_MULTICHANNEL_67 0xf7a
3774 #define ATI_VERB_GET_HBR_CONTROL 0xf7c
3775 #define ATI_VERB_GET_MULTICHANNEL_1 0xf85
3776 #define ATI_VERB_GET_MULTICHANNEL_3 0xf86
3777 #define ATI_VERB_GET_MULTICHANNEL_5 0xf87
3778 #define ATI_VERB_GET_MULTICHANNEL_7 0xf88
3779 #define ATI_VERB_GET_MULTICHANNEL_MODE 0xf89
3781 /* AMD specific HDA cvt verbs */
3782 #define ATI_VERB_SET_RAMP_RATE 0x770
3783 #define ATI_VERB_GET_RAMP_RATE 0xf70
3785 #define ATI_OUT_ENABLE 0x1
3787 #define ATI_MULTICHANNEL_MODE_PAIRED 0
3788 #define ATI_MULTICHANNEL_MODE_SINGLE 1
3790 #define ATI_HBR_CAPABLE 0x01
3791 #define ATI_HBR_ENABLE 0x10
3793 static int atihdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
3794 int dev_id, unsigned char *buf, int *eld_size)
3796 WARN_ON(dev_id != 0);
3797 /* call hda_eld.c ATI/AMD-specific function */
3798 return snd_hdmi_get_eld_ati(codec, nid, buf, eld_size,
3799 is_amdhdmi_rev3_or_later(codec));
3802 static void atihdmi_pin_setup_infoframe(struct hda_codec *codec,
3803 hda_nid_t pin_nid, int dev_id, int ca,
3804 int active_channels, int conn_type)
3806 WARN_ON(dev_id != 0);
3807 snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_CHANNEL_ALLOCATION, ca);
3810 static int atihdmi_paired_swap_fc_lfe(int pos)
3813 * ATI/AMD have automatic FC/LFE swap built-in
3814 * when in pairwise mapping mode.
3818 /* see channel_allocations[].speakers[] */
3827 static int atihdmi_paired_chmap_validate(struct hdac_chmap *chmap,
3828 int ca, int chs, unsigned char *map)
3830 struct hdac_cea_channel_speaker_allocation *cap;
3833 /* check that only channel pairs need to be remapped on old pre-rev3 ATI/AMD */
3835 cap = snd_hdac_get_ch_alloc_from_ca(ca);
3836 for (i = 0; i < chs; ++i) {
3837 int mask = snd_hdac_chmap_to_spk_mask(map[i]);
3839 bool companion_ok = false;
3844 for (j = 0 + i % 2; j < 8; j += 2) {
3845 int chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j);
3846 if (cap->speakers[chan_idx] == mask) {
3847 /* channel is in a supported position */
3850 if (i % 2 == 0 && i + 1 < chs) {
3851 /* even channel, check the odd companion */
3852 int comp_chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j + 1);
3853 int comp_mask_req = snd_hdac_chmap_to_spk_mask(map[i+1]);
3854 int comp_mask_act = cap->speakers[comp_chan_idx];
3856 if (comp_mask_req == comp_mask_act)
3857 companion_ok = true;
3869 i++; /* companion channel already checked */
3875 static int atihdmi_pin_set_slot_channel(struct hdac_device *hdac,
3876 hda_nid_t pin_nid, int hdmi_slot, int stream_channel)
3878 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
3880 int ati_channel_setup = 0;
3885 if (!has_amd_full_remap_support(codec)) {
3886 hdmi_slot = atihdmi_paired_swap_fc_lfe(hdmi_slot);
3888 /* In case this is an odd slot but without stream channel, do not
3889 * disable the slot since the corresponding even slot could have a
3890 * channel. In case neither have a channel, the slot pair will be
3891 * disabled when this function is called for the even slot. */
3892 if (hdmi_slot % 2 != 0 && stream_channel == 0xf)
3895 hdmi_slot -= hdmi_slot % 2;
3897 if (stream_channel != 0xf)
3898 stream_channel -= stream_channel % 2;
3901 verb = ATI_VERB_SET_MULTICHANNEL_01 + hdmi_slot/2 + (hdmi_slot % 2) * 0x00e;
3903 /* ati_channel_setup format: [7..4] = stream_channel_id, [1] = mute, [0] = enable */
3905 if (stream_channel != 0xf)
3906 ati_channel_setup = (stream_channel << 4) | ATI_OUT_ENABLE;
3908 return snd_hda_codec_write(codec, pin_nid, 0, verb, ati_channel_setup);
3911 static int atihdmi_pin_get_slot_channel(struct hdac_device *hdac,
3912 hda_nid_t pin_nid, int asp_slot)
3914 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
3915 bool was_odd = false;
3916 int ati_asp_slot = asp_slot;
3918 int ati_channel_setup;
3923 if (!has_amd_full_remap_support(codec)) {
3924 ati_asp_slot = atihdmi_paired_swap_fc_lfe(asp_slot);
3925 if (ati_asp_slot % 2 != 0) {
3931 verb = ATI_VERB_GET_MULTICHANNEL_01 + ati_asp_slot/2 + (ati_asp_slot % 2) * 0x00e;
3933 ati_channel_setup = snd_hda_codec_read(codec, pin_nid, 0, verb, 0);
3935 if (!(ati_channel_setup & ATI_OUT_ENABLE))
3938 return ((ati_channel_setup & 0xf0) >> 4) + !!was_odd;
3941 static int atihdmi_paired_chmap_cea_alloc_validate_get_type(
3942 struct hdac_chmap *chmap,
3943 struct hdac_cea_channel_speaker_allocation *cap,
3949 * Pre-rev3 ATI/AMD codecs operate in a paired channel mode, so
3950 * we need to take that into account (a single channel may take 2
3951 * channel slots if we need to carry a silent channel next to it).
3952 * On Rev3+ AMD codecs this function is not used.
3956 /* We only produce even-numbered channel count TLVs */
3957 if ((channels % 2) != 0)
3960 for (c = 0; c < 7; c += 2) {
3961 if (cap->speakers[c] || cap->speakers[c+1])
3965 if (chanpairs * 2 != channels)
3968 return SNDRV_CTL_TLVT_CHMAP_PAIRED;
3971 static void atihdmi_paired_cea_alloc_to_tlv_chmap(struct hdac_chmap *hchmap,
3972 struct hdac_cea_channel_speaker_allocation *cap,
3973 unsigned int *chmap, int channels)
3975 /* produce paired maps for pre-rev3 ATI/AMD codecs */
3979 for (c = 7; c >= 0; c--) {
3980 int chan = 7 - atihdmi_paired_swap_fc_lfe(7 - c);
3981 int spk = cap->speakers[chan];
3983 /* add N/A channel if the companion channel is occupied */
3984 if (cap->speakers[chan + (chan % 2 ? -1 : 1)])
3985 chmap[count++] = SNDRV_CHMAP_NA;
3990 chmap[count++] = snd_hdac_spk_to_chmap(spk);
3993 WARN_ON(count != channels);
3996 static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
3997 int dev_id, bool hbr)
3999 int hbr_ctl, hbr_ctl_new;
4001 WARN_ON(dev_id != 0);
4003 hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0);
4004 if (hbr_ctl >= 0 && (hbr_ctl & ATI_HBR_CAPABLE)) {
4006 hbr_ctl_new = hbr_ctl | ATI_HBR_ENABLE;
4008 hbr_ctl_new = hbr_ctl & ~ATI_HBR_ENABLE;
4011 "atihdmi_pin_hbr_setup: NID=0x%x, %shbr-ctl=0x%x\n",
4013 hbr_ctl == hbr_ctl_new ? "" : "new-",
4016 if (hbr_ctl != hbr_ctl_new)
4017 snd_hda_codec_write(codec, pin_nid, 0,
4018 ATI_VERB_SET_HBR_CONTROL,
4027 static int atihdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
4028 hda_nid_t pin_nid, int dev_id,
4029 u32 stream_tag, int format)
4031 if (is_amdhdmi_rev3_or_later(codec)) {
4032 int ramp_rate = 180; /* default as per AMD spec */
4033 /* disable ramp-up/down for non-pcm as per AMD spec */
4034 if (format & AC_FMT_TYPE_NON_PCM)
4037 snd_hda_codec_write(codec, cvt_nid, 0, ATI_VERB_SET_RAMP_RATE, ramp_rate);
4040 return hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id,
4041 stream_tag, format);
4045 static int atihdmi_init(struct hda_codec *codec)
4047 struct hdmi_spec *spec = codec->spec;
4050 err = generic_hdmi_init(codec);
4055 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
4056 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
4058 /* make sure downmix information in infoframe is zero */
4059 snd_hda_codec_write(codec, per_pin->pin_nid, 0, ATI_VERB_SET_DOWNMIX_INFO, 0);
4061 /* enable channel-wise remap mode if supported */
4062 if (has_amd_full_remap_support(codec))
4063 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
4064 ATI_VERB_SET_MULTICHANNEL_MODE,
4065 ATI_MULTICHANNEL_MODE_SINGLE);
4067 codec->auto_runtime_pm = 1;
4072 /* map from pin NID to port; port is 0-based */
4073 /* for AMD: assume widget NID starting from 3, with step 2 (3, 5, 7, ...) */
4074 static int atihdmi_pin2port(void *audio_ptr, int pin_nid)
4076 return pin_nid / 2 - 1;
4079 /* reverse-map from port to pin NID: see above */
4080 static int atihdmi_port2pin(struct hda_codec *codec, int port)
4082 return port * 2 + 3;
4085 static const struct drm_audio_component_audio_ops atihdmi_audio_ops = {
4086 .pin2port = atihdmi_pin2port,
4087 .pin_eld_notify = generic_acomp_pin_eld_notify,
4088 .master_bind = generic_acomp_master_bind,
4089 .master_unbind = generic_acomp_master_unbind,
4092 static int patch_atihdmi(struct hda_codec *codec)
4094 struct hdmi_spec *spec;
4095 struct hdmi_spec_per_cvt *per_cvt;
4098 err = patch_generic_hdmi(codec);
4103 codec->patch_ops.init = atihdmi_init;
4107 spec->ops.pin_get_eld = atihdmi_pin_get_eld;
4108 spec->ops.pin_setup_infoframe = atihdmi_pin_setup_infoframe;
4109 spec->ops.pin_hbr_setup = atihdmi_pin_hbr_setup;
4110 spec->ops.setup_stream = atihdmi_setup_stream;
4112 spec->chmap.ops.pin_get_slot_channel = atihdmi_pin_get_slot_channel;
4113 spec->chmap.ops.pin_set_slot_channel = atihdmi_pin_set_slot_channel;
4115 if (!has_amd_full_remap_support(codec)) {
4116 /* override to ATI/AMD-specific versions with pairwise mapping */
4117 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
4118 atihdmi_paired_chmap_cea_alloc_validate_get_type;
4119 spec->chmap.ops.cea_alloc_to_tlv_chmap =
4120 atihdmi_paired_cea_alloc_to_tlv_chmap;
4121 spec->chmap.ops.chmap_validate = atihdmi_paired_chmap_validate;
4124 /* ATI/AMD converters do not advertise all of their capabilities */
4125 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
4126 per_cvt = get_cvt(spec, cvt_idx);
4127 per_cvt->channels_max = max(per_cvt->channels_max, 8u);
4128 per_cvt->rates |= SUPPORTED_RATES;
4129 per_cvt->formats |= SUPPORTED_FORMATS;
4130 per_cvt->maxbps = max(per_cvt->maxbps, 24u);
4133 spec->chmap.channels_max = max(spec->chmap.channels_max, 8u);
4135 /* AMD GPUs have neither EPSS nor CLKSTOP bits, hence preventing
4136 * the link-down as is. Tell the core to allow it.
4138 codec->link_down_at_suspend = 1;
4140 generic_acomp_init(codec, &atihdmi_audio_ops, atihdmi_port2pin);
4145 /* VIA HDMI Implementation */
4146 #define VIAHDMI_CVT_NID 0x02 /* audio converter1 */
4147 #define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */
4149 static int patch_via_hdmi(struct hda_codec *codec)
4151 return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
4157 static const struct hda_device_id snd_hda_id_hdmi[] = {
4158 HDA_CODEC_ENTRY(0x1002793c, "RS600 HDMI", patch_atihdmi),
4159 HDA_CODEC_ENTRY(0x10027919, "RS600 HDMI", patch_atihdmi),
4160 HDA_CODEC_ENTRY(0x1002791a, "RS690/780 HDMI", patch_atihdmi),
4161 HDA_CODEC_ENTRY(0x1002aa01, "R6xx HDMI", patch_atihdmi),
4162 HDA_CODEC_ENTRY(0x10951390, "SiI1390 HDMI", patch_generic_hdmi),
4163 HDA_CODEC_ENTRY(0x10951392, "SiI1392 HDMI", patch_generic_hdmi),
4164 HDA_CODEC_ENTRY(0x17e80047, "Chrontel HDMI", patch_generic_hdmi),
4165 HDA_CODEC_ENTRY(0x10de0001, "MCP73 HDMI", patch_nvhdmi_2ch),
4166 HDA_CODEC_ENTRY(0x10de0002, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4167 HDA_CODEC_ENTRY(0x10de0003, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4168 HDA_CODEC_ENTRY(0x10de0004, "GPU 04 HDMI", patch_nvhdmi_8ch_7x),
4169 HDA_CODEC_ENTRY(0x10de0005, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4170 HDA_CODEC_ENTRY(0x10de0006, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4171 HDA_CODEC_ENTRY(0x10de0007, "MCP79/7A HDMI", patch_nvhdmi_8ch_7x),
4172 HDA_CODEC_ENTRY(0x10de0008, "GPU 08 HDMI/DP", patch_nvhdmi_legacy),
4173 HDA_CODEC_ENTRY(0x10de0009, "GPU 09 HDMI/DP", patch_nvhdmi_legacy),
4174 HDA_CODEC_ENTRY(0x10de000a, "GPU 0a HDMI/DP", patch_nvhdmi_legacy),
4175 HDA_CODEC_ENTRY(0x10de000b, "GPU 0b HDMI/DP", patch_nvhdmi_legacy),
4176 HDA_CODEC_ENTRY(0x10de000c, "MCP89 HDMI", patch_nvhdmi_legacy),
4177 HDA_CODEC_ENTRY(0x10de000d, "GPU 0d HDMI/DP", patch_nvhdmi_legacy),
4178 HDA_CODEC_ENTRY(0x10de0010, "GPU 10 HDMI/DP", patch_nvhdmi_legacy),
4179 HDA_CODEC_ENTRY(0x10de0011, "GPU 11 HDMI/DP", patch_nvhdmi_legacy),
4180 HDA_CODEC_ENTRY(0x10de0012, "GPU 12 HDMI/DP", patch_nvhdmi_legacy),
4181 HDA_CODEC_ENTRY(0x10de0013, "GPU 13 HDMI/DP", patch_nvhdmi_legacy),
4182 HDA_CODEC_ENTRY(0x10de0014, "GPU 14 HDMI/DP", patch_nvhdmi_legacy),
4183 HDA_CODEC_ENTRY(0x10de0015, "GPU 15 HDMI/DP", patch_nvhdmi_legacy),
4184 HDA_CODEC_ENTRY(0x10de0016, "GPU 16 HDMI/DP", patch_nvhdmi_legacy),
4185 /* 17 is known to be absent */
4186 HDA_CODEC_ENTRY(0x10de0018, "GPU 18 HDMI/DP", patch_nvhdmi_legacy),
4187 HDA_CODEC_ENTRY(0x10de0019, "GPU 19 HDMI/DP", patch_nvhdmi_legacy),
4188 HDA_CODEC_ENTRY(0x10de001a, "GPU 1a HDMI/DP", patch_nvhdmi_legacy),
4189 HDA_CODEC_ENTRY(0x10de001b, "GPU 1b HDMI/DP", patch_nvhdmi_legacy),
4190 HDA_CODEC_ENTRY(0x10de001c, "GPU 1c HDMI/DP", patch_nvhdmi_legacy),
4191 HDA_CODEC_ENTRY(0x10de0020, "Tegra30 HDMI", patch_tegra_hdmi),
4192 HDA_CODEC_ENTRY(0x10de0022, "Tegra114 HDMI", patch_tegra_hdmi),
4193 HDA_CODEC_ENTRY(0x10de0028, "Tegra124 HDMI", patch_tegra_hdmi),
4194 HDA_CODEC_ENTRY(0x10de0029, "Tegra210 HDMI/DP", patch_tegra_hdmi),
4195 HDA_CODEC_ENTRY(0x10de002d, "Tegra186 HDMI/DP0", patch_tegra_hdmi),
4196 HDA_CODEC_ENTRY(0x10de002e, "Tegra186 HDMI/DP1", patch_tegra_hdmi),
4197 HDA_CODEC_ENTRY(0x10de002f, "Tegra194 HDMI/DP2", patch_tegra_hdmi),
4198 HDA_CODEC_ENTRY(0x10de0030, "Tegra194 HDMI/DP3", patch_tegra_hdmi),
4199 HDA_CODEC_ENTRY(0x10de0040, "GPU 40 HDMI/DP", patch_nvhdmi),
4200 HDA_CODEC_ENTRY(0x10de0041, "GPU 41 HDMI/DP", patch_nvhdmi),
4201 HDA_CODEC_ENTRY(0x10de0042, "GPU 42 HDMI/DP", patch_nvhdmi),
4202 HDA_CODEC_ENTRY(0x10de0043, "GPU 43 HDMI/DP", patch_nvhdmi),
4203 HDA_CODEC_ENTRY(0x10de0044, "GPU 44 HDMI/DP", patch_nvhdmi),
4204 HDA_CODEC_ENTRY(0x10de0045, "GPU 45 HDMI/DP", patch_nvhdmi),
4205 HDA_CODEC_ENTRY(0x10de0050, "GPU 50 HDMI/DP", patch_nvhdmi),
4206 HDA_CODEC_ENTRY(0x10de0051, "GPU 51 HDMI/DP", patch_nvhdmi),
4207 HDA_CODEC_ENTRY(0x10de0052, "GPU 52 HDMI/DP", patch_nvhdmi),
4208 HDA_CODEC_ENTRY(0x10de0060, "GPU 60 HDMI/DP", patch_nvhdmi),
4209 HDA_CODEC_ENTRY(0x10de0061, "GPU 61 HDMI/DP", patch_nvhdmi),
4210 HDA_CODEC_ENTRY(0x10de0062, "GPU 62 HDMI/DP", patch_nvhdmi),
4211 HDA_CODEC_ENTRY(0x10de0067, "MCP67 HDMI", patch_nvhdmi_2ch),
4212 HDA_CODEC_ENTRY(0x10de0070, "GPU 70 HDMI/DP", patch_nvhdmi),
4213 HDA_CODEC_ENTRY(0x10de0071, "GPU 71 HDMI/DP", patch_nvhdmi),
4214 HDA_CODEC_ENTRY(0x10de0072, "GPU 72 HDMI/DP", patch_nvhdmi),
4215 HDA_CODEC_ENTRY(0x10de0073, "GPU 73 HDMI/DP", patch_nvhdmi),
4216 HDA_CODEC_ENTRY(0x10de0074, "GPU 74 HDMI/DP", patch_nvhdmi),
4217 HDA_CODEC_ENTRY(0x10de0076, "GPU 76 HDMI/DP", patch_nvhdmi),
4218 HDA_CODEC_ENTRY(0x10de007b, "GPU 7b HDMI/DP", patch_nvhdmi),
4219 HDA_CODEC_ENTRY(0x10de007c, "GPU 7c HDMI/DP", patch_nvhdmi),
4220 HDA_CODEC_ENTRY(0x10de007d, "GPU 7d HDMI/DP", patch_nvhdmi),
4221 HDA_CODEC_ENTRY(0x10de007e, "GPU 7e HDMI/DP", patch_nvhdmi),
4222 HDA_CODEC_ENTRY(0x10de0080, "GPU 80 HDMI/DP", patch_nvhdmi),
4223 HDA_CODEC_ENTRY(0x10de0081, "GPU 81 HDMI/DP", patch_nvhdmi),
4224 HDA_CODEC_ENTRY(0x10de0082, "GPU 82 HDMI/DP", patch_nvhdmi),
4225 HDA_CODEC_ENTRY(0x10de0083, "GPU 83 HDMI/DP", patch_nvhdmi),
4226 HDA_CODEC_ENTRY(0x10de0084, "GPU 84 HDMI/DP", patch_nvhdmi),
4227 HDA_CODEC_ENTRY(0x10de0090, "GPU 90 HDMI/DP", patch_nvhdmi),
4228 HDA_CODEC_ENTRY(0x10de0091, "GPU 91 HDMI/DP", patch_nvhdmi),
4229 HDA_CODEC_ENTRY(0x10de0092, "GPU 92 HDMI/DP", patch_nvhdmi),
4230 HDA_CODEC_ENTRY(0x10de0093, "GPU 93 HDMI/DP", patch_nvhdmi),
4231 HDA_CODEC_ENTRY(0x10de0094, "GPU 94 HDMI/DP", patch_nvhdmi),
4232 HDA_CODEC_ENTRY(0x10de0095, "GPU 95 HDMI/DP", patch_nvhdmi),
4233 HDA_CODEC_ENTRY(0x10de0097, "GPU 97 HDMI/DP", patch_nvhdmi),
4234 HDA_CODEC_ENTRY(0x10de0098, "GPU 98 HDMI/DP", patch_nvhdmi),
4235 HDA_CODEC_ENTRY(0x10de0099, "GPU 99 HDMI/DP", patch_nvhdmi),
4236 HDA_CODEC_ENTRY(0x10de8001, "MCP73 HDMI", patch_nvhdmi_2ch),
4237 HDA_CODEC_ENTRY(0x10de8067, "MCP67/68 HDMI", patch_nvhdmi_2ch),
4238 HDA_CODEC_ENTRY(0x11069f80, "VX900 HDMI/DP", patch_via_hdmi),
4239 HDA_CODEC_ENTRY(0x11069f81, "VX900 HDMI/DP", patch_via_hdmi),
4240 HDA_CODEC_ENTRY(0x11069f84, "VX11 HDMI/DP", patch_generic_hdmi),
4241 HDA_CODEC_ENTRY(0x11069f85, "VX11 HDMI/DP", patch_generic_hdmi),
4242 HDA_CODEC_ENTRY(0x80860054, "IbexPeak HDMI", patch_i915_cpt_hdmi),
4243 HDA_CODEC_ENTRY(0x80862800, "Geminilake HDMI", patch_i915_glk_hdmi),
4244 HDA_CODEC_ENTRY(0x80862801, "Bearlake HDMI", patch_generic_hdmi),
4245 HDA_CODEC_ENTRY(0x80862802, "Cantiga HDMI", patch_generic_hdmi),
4246 HDA_CODEC_ENTRY(0x80862803, "Eaglelake HDMI", patch_generic_hdmi),
4247 HDA_CODEC_ENTRY(0x80862804, "IbexPeak HDMI", patch_i915_cpt_hdmi),
4248 HDA_CODEC_ENTRY(0x80862805, "CougarPoint HDMI", patch_i915_cpt_hdmi),
4249 HDA_CODEC_ENTRY(0x80862806, "PantherPoint HDMI", patch_i915_cpt_hdmi),
4250 HDA_CODEC_ENTRY(0x80862807, "Haswell HDMI", patch_i915_hsw_hdmi),
4251 HDA_CODEC_ENTRY(0x80862808, "Broadwell HDMI", patch_i915_hsw_hdmi),
4252 HDA_CODEC_ENTRY(0x80862809, "Skylake HDMI", patch_i915_hsw_hdmi),
4253 HDA_CODEC_ENTRY(0x8086280a, "Broxton HDMI", patch_i915_hsw_hdmi),
4254 HDA_CODEC_ENTRY(0x8086280b, "Kabylake HDMI", patch_i915_hsw_hdmi),
4255 HDA_CODEC_ENTRY(0x8086280c, "Cannonlake HDMI", patch_i915_glk_hdmi),
4256 HDA_CODEC_ENTRY(0x8086280d, "Geminilake HDMI", patch_i915_glk_hdmi),
4257 HDA_CODEC_ENTRY(0x8086280f, "Icelake HDMI", patch_i915_icl_hdmi),
4258 HDA_CODEC_ENTRY(0x80862812, "Tigerlake HDMI", patch_i915_tgl_hdmi),
4259 HDA_CODEC_ENTRY(0x80862880, "CedarTrail HDMI", patch_generic_hdmi),
4260 HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_i915_byt_hdmi),
4261 HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_i915_byt_hdmi),
4262 HDA_CODEC_ENTRY(0x808629fb, "Crestline HDMI", patch_generic_hdmi),
4263 /* special ID for generic HDMI */
4264 HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC_HDMI, "Generic HDMI", patch_generic_hdmi),
4267 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_hdmi);
4269 MODULE_LICENSE("GPL");
4270 MODULE_DESCRIPTION("HDMI HD-audio codec");
4271 MODULE_ALIAS("snd-hda-codec-intelhdmi");
4272 MODULE_ALIAS("snd-hda-codec-nvhdmi");
4273 MODULE_ALIAS("snd-hda-codec-atihdmi");
4275 static struct hda_codec_driver hdmi_driver = {
4276 .id = snd_hda_id_hdmi,
4279 module_hda_codec_driver(hdmi_driver);