3 * patch_hdmi.c - routines for HDMI/DisplayPort codecs
5 * Copyright(c) 2008-2010 Intel Corporation. All rights reserved.
6 * Copyright (c) 2006 ATI Technologies Inc.
7 * Copyright (c) 2008 NVIDIA Corp. All rights reserved.
8 * Copyright (c) 2008 Wei Ni <wni@nvidia.com>
9 * Copyright (c) 2013 Anssi Hannula <anssi.hannula@iki.fi>
12 * Wu Fengguang <wfg@linux.intel.com>
15 * Wu Fengguang <wfg@linux.intel.com>
17 * This program is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License as published by the Free
19 * Software Foundation; either version 2 of the License, or (at your option)
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software Foundation,
29 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include <linux/init.h>
33 #include <linux/delay.h>
34 #include <linux/slab.h>
35 #include <linux/module.h>
36 #include <sound/core.h>
37 #include <sound/jack.h>
38 #include <sound/asoundef.h>
39 #include <sound/tlv.h>
40 #include <sound/hdaudio.h>
41 #include <sound/hda_i915.h>
42 #include <sound/hda_chmap.h>
43 #include "hda_codec.h"
44 #include "hda_local.h"
47 static bool static_hdmi_pcm;
48 module_param(static_hdmi_pcm, bool, 0644);
49 MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
51 #define is_haswell(codec) ((codec)->core.vendor_id == 0x80862807)
52 #define is_broadwell(codec) ((codec)->core.vendor_id == 0x80862808)
53 #define is_skylake(codec) ((codec)->core.vendor_id == 0x80862809)
54 #define is_broxton(codec) ((codec)->core.vendor_id == 0x8086280a)
55 #define is_kabylake(codec) ((codec)->core.vendor_id == 0x8086280b)
56 #define is_haswell_plus(codec) (is_haswell(codec) || is_broadwell(codec) \
57 || is_skylake(codec) || is_broxton(codec) \
58 || is_kabylake(codec))
60 #define is_valleyview(codec) ((codec)->core.vendor_id == 0x80862882)
61 #define is_cherryview(codec) ((codec)->core.vendor_id == 0x80862883)
62 #define is_valleyview_plus(codec) (is_valleyview(codec) || is_cherryview(codec))
64 struct hdmi_spec_per_cvt {
67 unsigned int channels_min;
68 unsigned int channels_max;
74 /* max. connections to a widget */
75 #define HDA_MAX_CONNECTIONS 32
77 struct hdmi_spec_per_pin {
79 /* pin idx, different device entries on the same pin use the same idx */
82 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
86 struct hda_codec *codec;
87 struct hdmi_eld sink_eld;
89 struct delayed_work work;
90 struct hdmi_pcm *pcm; /* pointer to spec->pcm_rec[n] dynamically*/
91 int pcm_idx; /* which pcm is attached. -1 means no pcm is attached */
93 bool setup; /* the stream has been set up by prepare callback */
94 int channels; /* current number of channels */
96 bool chmap_set; /* channel-map override by ALSA API? */
97 unsigned char chmap[8]; /* ALSA API channel-map */
98 #ifdef CONFIG_SND_PROC_FS
99 struct snd_info_entry *proc_entry;
103 /* operations used by generic code that can be overridden by patches */
105 int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid,
106 unsigned char *buf, int *eld_size);
108 void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid,
109 int ca, int active_channels, int conn_type);
111 /* enable/disable HBR (HD passthrough) */
112 int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid, bool hbr);
114 int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid,
115 hda_nid_t pin_nid, u32 stream_tag, int format);
121 struct snd_jack *jack;
122 struct snd_kcontrol *eld_ctl;
127 struct snd_array cvts; /* struct hdmi_spec_per_cvt */
128 hda_nid_t cvt_nids[4]; /* only for haswell fix */
131 struct snd_array pins; /* struct hdmi_spec_per_pin */
132 struct hdmi_pcm pcm_rec[16];
133 struct mutex pcm_lock;
134 /* pcm_bitmap means which pcms have been assigned to pins*/
135 unsigned long pcm_bitmap;
136 int pcm_used; /* counter of pcm_rec[] */
137 /* bitmap shows whether the pcm is opened in user space
138 * bit 0 means the first playback PCM (PCM3);
139 * bit 1 means the second playback PCM, and so on.
141 unsigned long pcm_in_use;
143 struct hdmi_eld temp_eld;
149 * Non-generic VIA/NVIDIA specific
151 struct hda_multi_out multiout;
152 struct hda_pcm_stream pcm_playback;
154 /* i915/powerwell (Haswell+/Valleyview+) specific */
155 bool use_acomp_notifier; /* use i915 eld_notify callback for hotplug */
156 struct i915_audio_component_audio_ops i915_audio_ops;
158 struct hdac_chmap chmap;
161 #ifdef CONFIG_SND_HDA_I915
162 static inline bool codec_has_acomp(struct hda_codec *codec)
164 struct hdmi_spec *spec = codec->spec;
165 return spec->use_acomp_notifier;
168 #define codec_has_acomp(codec) false
171 struct hdmi_audio_infoframe {
178 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
182 u8 LFEPBL01_LSV36_DM_INH7;
185 struct dp_audio_infoframe {
188 u8 ver; /* 0x11 << 2 */
190 u8 CC02_CT47; /* match with HDMI infoframe from this on */
194 u8 LFEPBL01_LSV36_DM_INH7;
197 union audio_infoframe {
198 struct hdmi_audio_infoframe hdmi;
199 struct dp_audio_infoframe dp;
207 #define get_pin(spec, idx) \
208 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx))
209 #define get_cvt(spec, idx) \
210 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx))
211 /* obtain hdmi_pcm object assigned to idx */
212 #define get_hdmi_pcm(spec, idx) (&(spec)->pcm_rec[idx])
213 /* obtain hda_pcm object assigned to idx */
214 #define get_pcm_rec(spec, idx) (get_hdmi_pcm(spec, idx)->pcm)
216 static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid)
218 struct hdmi_spec *spec = codec->spec;
221 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
222 if (get_pin(spec, pin_idx)->pin_nid == pin_nid)
225 codec_warn(codec, "HDMI: pin nid %d not registered\n", pin_nid);
229 static int hinfo_to_pcm_index(struct hda_codec *codec,
230 struct hda_pcm_stream *hinfo)
232 struct hdmi_spec *spec = codec->spec;
235 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++)
236 if (get_pcm_rec(spec, pcm_idx)->stream == hinfo)
239 codec_warn(codec, "HDMI: hinfo %p not registered\n", hinfo);
243 static int hinfo_to_pin_index(struct hda_codec *codec,
244 struct hda_pcm_stream *hinfo)
246 struct hdmi_spec *spec = codec->spec;
247 struct hdmi_spec_per_pin *per_pin;
250 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
251 per_pin = get_pin(spec, pin_idx);
253 per_pin->pcm->pcm->stream == hinfo)
257 codec_dbg(codec, "HDMI: hinfo %p not registered\n", hinfo);
261 static struct hdmi_spec_per_pin *pcm_idx_to_pin(struct hdmi_spec *spec,
265 struct hdmi_spec_per_pin *per_pin;
267 for (i = 0; i < spec->num_pins; i++) {
268 per_pin = get_pin(spec, i);
269 if (per_pin->pcm_idx == pcm_idx)
275 static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid)
277 struct hdmi_spec *spec = codec->spec;
280 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
281 if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid)
284 codec_warn(codec, "HDMI: cvt nid %d not registered\n", cvt_nid);
288 static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
289 struct snd_ctl_elem_info *uinfo)
291 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
292 struct hdmi_spec *spec = codec->spec;
293 struct hdmi_spec_per_pin *per_pin;
294 struct hdmi_eld *eld;
297 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
299 pcm_idx = kcontrol->private_value;
300 mutex_lock(&spec->pcm_lock);
301 per_pin = pcm_idx_to_pin(spec, pcm_idx);
303 /* no pin is bound to the pcm */
305 mutex_unlock(&spec->pcm_lock);
308 eld = &per_pin->sink_eld;
309 uinfo->count = eld->eld_valid ? eld->eld_size : 0;
310 mutex_unlock(&spec->pcm_lock);
315 static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
316 struct snd_ctl_elem_value *ucontrol)
318 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
319 struct hdmi_spec *spec = codec->spec;
320 struct hdmi_spec_per_pin *per_pin;
321 struct hdmi_eld *eld;
324 pcm_idx = kcontrol->private_value;
325 mutex_lock(&spec->pcm_lock);
326 per_pin = pcm_idx_to_pin(spec, pcm_idx);
328 /* no pin is bound to the pcm */
329 memset(ucontrol->value.bytes.data, 0,
330 ARRAY_SIZE(ucontrol->value.bytes.data));
331 mutex_unlock(&spec->pcm_lock);
334 eld = &per_pin->sink_eld;
336 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data) ||
337 eld->eld_size > ELD_MAX_SIZE) {
338 mutex_unlock(&spec->pcm_lock);
343 memset(ucontrol->value.bytes.data, 0,
344 ARRAY_SIZE(ucontrol->value.bytes.data));
346 memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
348 mutex_unlock(&spec->pcm_lock);
353 static struct snd_kcontrol_new eld_bytes_ctl = {
354 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
355 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
357 .info = hdmi_eld_ctl_info,
358 .get = hdmi_eld_ctl_get,
361 static int hdmi_create_eld_ctl(struct hda_codec *codec, int pcm_idx,
364 struct snd_kcontrol *kctl;
365 struct hdmi_spec *spec = codec->spec;
368 kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
371 kctl->private_value = pcm_idx;
372 kctl->id.device = device;
374 /* no pin nid is associated with the kctl now
375 * tbd: associate pin nid to eld ctl later
377 err = snd_hda_ctl_add(codec, 0, kctl);
381 get_hdmi_pcm(spec, pcm_idx)->eld_ctl = kctl;
386 static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
387 int *packet_index, int *byte_index)
391 val = snd_hda_codec_read(codec, pin_nid, 0,
392 AC_VERB_GET_HDMI_DIP_INDEX, 0);
394 *packet_index = val >> 5;
395 *byte_index = val & 0x1f;
399 static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
400 int packet_index, int byte_index)
404 val = (packet_index << 5) | (byte_index & 0x1f);
406 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
409 static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
412 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
415 static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
417 struct hdmi_spec *spec = codec->spec;
421 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
422 snd_hda_codec_write(codec, pin_nid, 0,
423 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
425 if (spec->dyn_pin_out)
426 /* Disable pin out until stream is active */
429 /* Enable pin out: some machines with GM965 gets broken output
430 * when the pin is disabled or changed while using with HDMI
434 snd_hda_codec_write(codec, pin_nid, 0,
435 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_out);
442 #ifdef CONFIG_SND_PROC_FS
443 static void print_eld_info(struct snd_info_entry *entry,
444 struct snd_info_buffer *buffer)
446 struct hdmi_spec_per_pin *per_pin = entry->private_data;
448 mutex_lock(&per_pin->lock);
449 snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer);
450 mutex_unlock(&per_pin->lock);
453 static void write_eld_info(struct snd_info_entry *entry,
454 struct snd_info_buffer *buffer)
456 struct hdmi_spec_per_pin *per_pin = entry->private_data;
458 mutex_lock(&per_pin->lock);
459 snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer);
460 mutex_unlock(&per_pin->lock);
463 static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
466 struct hda_codec *codec = per_pin->codec;
467 struct snd_info_entry *entry;
470 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
471 err = snd_card_proc_new(codec->card, name, &entry);
475 snd_info_set_text_ops(entry, per_pin, print_eld_info);
476 entry->c.text.write = write_eld_info;
477 entry->mode |= S_IWUSR;
478 per_pin->proc_entry = entry;
483 static void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
485 if (!per_pin->codec->bus->shutdown) {
486 snd_info_free_entry(per_pin->proc_entry);
487 per_pin->proc_entry = NULL;
491 static inline int eld_proc_new(struct hdmi_spec_per_pin *per_pin,
496 static inline void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
502 * Audio InfoFrame routines
506 * Enable Audio InfoFrame Transmission
508 static void hdmi_start_infoframe_trans(struct hda_codec *codec,
511 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
512 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
517 * Disable Audio InfoFrame Transmission
519 static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
522 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
523 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
527 static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
529 #ifdef CONFIG_SND_DEBUG_VERBOSE
533 size = snd_hdmi_get_eld_size(codec, pin_nid);
534 codec_dbg(codec, "HDMI: ELD buf size is %d\n", size);
536 for (i = 0; i < 8; i++) {
537 size = snd_hda_codec_read(codec, pin_nid, 0,
538 AC_VERB_GET_HDMI_DIP_SIZE, i);
539 codec_dbg(codec, "HDMI: DIP GP[%d] buf size is %d\n", i, size);
544 static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
550 for (i = 0; i < 8; i++) {
551 size = snd_hda_codec_read(codec, pin_nid, 0,
552 AC_VERB_GET_HDMI_DIP_SIZE, i);
556 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
557 for (j = 1; j < 1000; j++) {
558 hdmi_write_dip_byte(codec, pin_nid, 0x0);
559 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
561 codec_dbg(codec, "dip index %d: %d != %d\n",
563 if (bi == 0) /* byte index wrapped around */
567 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
573 static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
575 u8 *bytes = (u8 *)hdmi_ai;
579 hdmi_ai->checksum = 0;
581 for (i = 0; i < sizeof(*hdmi_ai); i++)
584 hdmi_ai->checksum = -sum;
587 static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
593 hdmi_debug_dip_size(codec, pin_nid);
594 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
596 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
597 for (i = 0; i < size; i++)
598 hdmi_write_dip_byte(codec, pin_nid, dip[i]);
601 static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
607 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
611 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
612 for (i = 0; i < size; i++) {
613 val = snd_hda_codec_read(codec, pin_nid, 0,
614 AC_VERB_GET_HDMI_DIP_DATA, 0);
622 static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
624 int ca, int active_channels,
627 union audio_infoframe ai;
629 memset(&ai, 0, sizeof(ai));
630 if (conn_type == 0) { /* HDMI */
631 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
633 hdmi_ai->type = 0x84;
636 hdmi_ai->CC02_CT47 = active_channels - 1;
638 hdmi_checksum_audio_infoframe(hdmi_ai);
639 } else if (conn_type == 1) { /* DisplayPort */
640 struct dp_audio_infoframe *dp_ai = &ai.dp;
644 dp_ai->ver = 0x11 << 2;
645 dp_ai->CC02_CT47 = active_channels - 1;
648 codec_dbg(codec, "HDMI: unknown connection type at pin %d\n",
654 * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
655 * sizeof(*dp_ai) to avoid partial match/update problems when
656 * the user switches between HDMI/DP monitors.
658 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
661 "hdmi_pin_setup_infoframe: pin=%d channels=%d ca=0x%02x\n",
663 active_channels, ca);
664 hdmi_stop_infoframe_trans(codec, pin_nid);
665 hdmi_fill_audio_infoframe(codec, pin_nid,
666 ai.bytes, sizeof(ai));
667 hdmi_start_infoframe_trans(codec, pin_nid);
671 static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
672 struct hdmi_spec_per_pin *per_pin,
675 struct hdmi_spec *spec = codec->spec;
676 struct hdac_chmap *chmap = &spec->chmap;
677 hda_nid_t pin_nid = per_pin->pin_nid;
678 int channels = per_pin->channels;
680 struct hdmi_eld *eld;
686 if (is_haswell_plus(codec))
687 snd_hda_codec_write(codec, pin_nid, 0,
688 AC_VERB_SET_AMP_GAIN_MUTE,
691 eld = &per_pin->sink_eld;
693 ca = snd_hdac_channel_allocation(&codec->core,
694 eld->info.spk_alloc, channels,
695 per_pin->chmap_set, non_pcm, per_pin->chmap);
697 active_channels = snd_hdac_get_active_channels(ca);
699 chmap->ops.set_channel_count(&codec->core, per_pin->cvt_nid,
703 * always configure channel mapping, it may have been changed by the
704 * user in the meantime
706 snd_hdac_setup_channel_mapping(&spec->chmap,
707 pin_nid, non_pcm, ca, channels,
708 per_pin->chmap, per_pin->chmap_set);
710 spec->ops.pin_setup_infoframe(codec, pin_nid, ca, active_channels,
711 eld->info.conn_type);
713 per_pin->non_pcm = non_pcm;
720 static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
722 static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid)
724 struct hdmi_spec *spec = codec->spec;
725 int pin_idx = pin_nid_to_pin_index(codec, nid);
729 if (hdmi_present_sense(get_pin(spec, pin_idx), 1))
730 snd_hda_jack_report_sync(codec);
733 static void jack_callback(struct hda_codec *codec,
734 struct hda_jack_callback *jack)
736 check_presence_and_report(codec, jack->nid);
739 static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
741 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
742 struct hda_jack_tbl *jack;
743 int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
745 jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
748 jack->jack_dirty = 1;
751 "HDMI hot plug event: Codec=%d Pin=%d Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n",
752 codec->addr, jack->nid, dev_entry, !!(res & AC_UNSOL_RES_IA),
753 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
755 check_presence_and_report(codec, jack->nid);
758 static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
760 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
761 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
762 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
763 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
766 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
781 static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
783 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
784 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
786 if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) {
787 codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag);
792 hdmi_intrinsic_event(codec, res);
794 hdmi_non_intrinsic_event(codec, res);
797 static void haswell_verify_D0(struct hda_codec *codec,
798 hda_nid_t cvt_nid, hda_nid_t nid)
802 /* For Haswell, the converter 1/2 may keep in D3 state after bootup,
803 * thus pins could only choose converter 0 for use. Make sure the
804 * converters are in correct power state */
805 if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0))
806 snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
808 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) {
809 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
812 pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
813 pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
814 codec_dbg(codec, "Haswell HDMI audio: Power for pin 0x%x is now D%d\n", nid, pwr);
822 /* HBR should be Non-PCM, 8 channels */
823 #define is_hbr_format(format) \
824 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
826 static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
829 int pinctl, new_pinctl;
831 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
832 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
833 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
836 return hbr ? -EINVAL : 0;
838 new_pinctl = pinctl & ~AC_PINCTL_EPT;
840 new_pinctl |= AC_PINCTL_EPT_HBR;
842 new_pinctl |= AC_PINCTL_EPT_NATIVE;
845 "hdmi_pin_hbr_setup: NID=0x%x, %spinctl=0x%x\n",
847 pinctl == new_pinctl ? "" : "new-",
850 if (pinctl != new_pinctl)
851 snd_hda_codec_write(codec, pin_nid, 0,
852 AC_VERB_SET_PIN_WIDGET_CONTROL,
860 static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
861 hda_nid_t pin_nid, u32 stream_tag, int format)
863 struct hdmi_spec *spec = codec->spec;
866 if (is_haswell_plus(codec))
867 haswell_verify_D0(codec, cvt_nid, pin_nid);
869 err = spec->ops.pin_hbr_setup(codec, pin_nid, is_hbr_format(format));
872 codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n");
876 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
880 /* Try to find an available converter
881 * If pin_idx is less then zero, just try to find an available converter.
882 * Otherwise, try to find an available converter and get the cvt mux index
885 static int hdmi_choose_cvt(struct hda_codec *codec,
886 int pin_idx, int *cvt_id, int *mux_id)
888 struct hdmi_spec *spec = codec->spec;
889 struct hdmi_spec_per_pin *per_pin;
890 struct hdmi_spec_per_cvt *per_cvt = NULL;
891 int cvt_idx, mux_idx = 0;
893 /* pin_idx < 0 means no pin will be bound to the converter */
897 per_pin = get_pin(spec, pin_idx);
899 /* Dynamically assign converter to stream */
900 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
901 per_cvt = get_cvt(spec, cvt_idx);
903 /* Must not already be assigned */
904 if (per_cvt->assigned)
908 /* Must be in pin's mux's list of converters */
909 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
910 if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid)
912 /* Not in mux list */
913 if (mux_idx == per_pin->num_mux_nids)
918 /* No free converters */
919 if (cvt_idx == spec->num_cvts)
923 per_pin->mux_idx = mux_idx;
933 /* Assure the pin select the right convetor */
934 static void intel_verify_pin_cvt_connect(struct hda_codec *codec,
935 struct hdmi_spec_per_pin *per_pin)
937 hda_nid_t pin_nid = per_pin->pin_nid;
940 mux_idx = per_pin->mux_idx;
941 curr = snd_hda_codec_read(codec, pin_nid, 0,
942 AC_VERB_GET_CONNECT_SEL, 0);
944 snd_hda_codec_write_cache(codec, pin_nid, 0,
945 AC_VERB_SET_CONNECT_SEL,
949 /* get the mux index for the converter of the pins
950 * converter's mux index is the same for all pins on Intel platform
952 static int intel_cvt_id_to_mux_idx(struct hdmi_spec *spec,
957 for (i = 0; i < spec->num_cvts; i++)
958 if (spec->cvt_nids[i] == cvt_nid)
963 /* Intel HDMI workaround to fix audio routing issue:
964 * For some Intel display codecs, pins share the same connection list.
965 * So a conveter can be selected by multiple pins and playback on any of these
966 * pins will generate sound on the external display, because audio flows from
967 * the same converter to the display pipeline. Also muting one pin may make
968 * other pins have no sound output.
969 * So this function assures that an assigned converter for a pin is not selected
972 static void intel_not_share_assigned_cvt(struct hda_codec *codec,
973 hda_nid_t pin_nid, int mux_idx)
975 struct hdmi_spec *spec = codec->spec;
978 struct hdmi_spec_per_cvt *per_cvt;
980 /* configure all pins, including "no physical connection" ones */
981 for_each_hda_codec_node(nid, codec) {
982 unsigned int wid_caps = get_wcaps(codec, nid);
983 unsigned int wid_type = get_wcaps_type(wid_caps);
985 if (wid_type != AC_WID_PIN)
991 curr = snd_hda_codec_read(codec, nid, 0,
992 AC_VERB_GET_CONNECT_SEL, 0);
996 /* choose an unassigned converter. The conveters in the
997 * connection list are in the same order as in the codec.
999 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
1000 per_cvt = get_cvt(spec, cvt_idx);
1001 if (!per_cvt->assigned) {
1003 "choose cvt %d for pin nid %d\n",
1005 snd_hda_codec_write_cache(codec, nid, 0,
1006 AC_VERB_SET_CONNECT_SEL,
1014 /* A wrapper of intel_not_share_asigned_cvt() */
1015 static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,
1016 hda_nid_t pin_nid, hda_nid_t cvt_nid)
1019 struct hdmi_spec *spec = codec->spec;
1021 if (!is_haswell_plus(codec) && !is_valleyview_plus(codec))
1024 /* On Intel platform, the mapping of converter nid to
1025 * mux index of the pins are always the same.
1026 * The pin nid may be 0, this means all pins will not
1027 * share the converter.
1029 mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid);
1031 intel_not_share_assigned_cvt(codec, pin_nid, mux_idx);
1034 /* called in hdmi_pcm_open when no pin is assigned to the PCM
1035 * in dyn_pcm_assign mode.
1037 static int hdmi_pcm_open_no_pin(struct hda_pcm_stream *hinfo,
1038 struct hda_codec *codec,
1039 struct snd_pcm_substream *substream)
1041 struct hdmi_spec *spec = codec->spec;
1042 struct snd_pcm_runtime *runtime = substream->runtime;
1043 int cvt_idx, pcm_idx;
1044 struct hdmi_spec_per_cvt *per_cvt = NULL;
1047 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1051 err = hdmi_choose_cvt(codec, -1, &cvt_idx, NULL);
1055 per_cvt = get_cvt(spec, cvt_idx);
1056 per_cvt->assigned = 1;
1057 hinfo->nid = per_cvt->cvt_nid;
1059 intel_not_share_assigned_cvt_nid(codec, 0, per_cvt->cvt_nid);
1061 set_bit(pcm_idx, &spec->pcm_in_use);
1062 /* todo: setup spdif ctls assign */
1064 /* Initially set the converter's capabilities */
1065 hinfo->channels_min = per_cvt->channels_min;
1066 hinfo->channels_max = per_cvt->channels_max;
1067 hinfo->rates = per_cvt->rates;
1068 hinfo->formats = per_cvt->formats;
1069 hinfo->maxbps = per_cvt->maxbps;
1071 /* Store the updated parameters */
1072 runtime->hw.channels_min = hinfo->channels_min;
1073 runtime->hw.channels_max = hinfo->channels_max;
1074 runtime->hw.formats = hinfo->formats;
1075 runtime->hw.rates = hinfo->rates;
1077 snd_pcm_hw_constraint_step(substream->runtime, 0,
1078 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
1085 static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1086 struct hda_codec *codec,
1087 struct snd_pcm_substream *substream)
1089 struct hdmi_spec *spec = codec->spec;
1090 struct snd_pcm_runtime *runtime = substream->runtime;
1091 int pin_idx, cvt_idx, pcm_idx, mux_idx = 0;
1092 struct hdmi_spec_per_pin *per_pin;
1093 struct hdmi_eld *eld;
1094 struct hdmi_spec_per_cvt *per_cvt = NULL;
1097 /* Validate hinfo */
1098 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1102 mutex_lock(&spec->pcm_lock);
1103 pin_idx = hinfo_to_pin_index(codec, hinfo);
1104 if (!spec->dyn_pcm_assign) {
1105 if (snd_BUG_ON(pin_idx < 0)) {
1106 mutex_unlock(&spec->pcm_lock);
1110 /* no pin is assigned to the PCM
1111 * PA need pcm open successfully when probe
1114 err = hdmi_pcm_open_no_pin(hinfo, codec, substream);
1115 mutex_unlock(&spec->pcm_lock);
1120 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, &mux_idx);
1122 mutex_unlock(&spec->pcm_lock);
1126 per_cvt = get_cvt(spec, cvt_idx);
1127 /* Claim converter */
1128 per_cvt->assigned = 1;
1130 set_bit(pcm_idx, &spec->pcm_in_use);
1131 per_pin = get_pin(spec, pin_idx);
1132 per_pin->cvt_nid = per_cvt->cvt_nid;
1133 hinfo->nid = per_cvt->cvt_nid;
1135 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1136 AC_VERB_SET_CONNECT_SEL,
1139 /* configure unused pins to choose other converters */
1140 if (is_haswell_plus(codec) || is_valleyview_plus(codec))
1141 intel_not_share_assigned_cvt(codec, per_pin->pin_nid, mux_idx);
1143 snd_hda_spdif_ctls_assign(codec, pcm_idx, per_cvt->cvt_nid);
1145 /* Initially set the converter's capabilities */
1146 hinfo->channels_min = per_cvt->channels_min;
1147 hinfo->channels_max = per_cvt->channels_max;
1148 hinfo->rates = per_cvt->rates;
1149 hinfo->formats = per_cvt->formats;
1150 hinfo->maxbps = per_cvt->maxbps;
1152 eld = &per_pin->sink_eld;
1153 /* Restrict capabilities by ELD if this isn't disabled */
1154 if (!static_hdmi_pcm && eld->eld_valid) {
1155 snd_hdmi_eld_update_pcm_info(&eld->info, hinfo);
1156 if (hinfo->channels_min > hinfo->channels_max ||
1157 !hinfo->rates || !hinfo->formats) {
1158 per_cvt->assigned = 0;
1160 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
1161 mutex_unlock(&spec->pcm_lock);
1166 mutex_unlock(&spec->pcm_lock);
1167 /* Store the updated parameters */
1168 runtime->hw.channels_min = hinfo->channels_min;
1169 runtime->hw.channels_max = hinfo->channels_max;
1170 runtime->hw.formats = hinfo->formats;
1171 runtime->hw.rates = hinfo->rates;
1173 snd_pcm_hw_constraint_step(substream->runtime, 0,
1174 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
1179 * HDA/HDMI auto parsing
1181 static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
1183 struct hdmi_spec *spec = codec->spec;
1184 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1185 hda_nid_t pin_nid = per_pin->pin_nid;
1187 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
1189 "HDMI: pin %d wcaps %#x does not support connection list\n",
1190 pin_nid, get_wcaps(codec, pin_nid));
1194 per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,
1196 HDA_MAX_CONNECTIONS);
1201 static int hdmi_find_pcm_slot(struct hdmi_spec *spec,
1202 struct hdmi_spec_per_pin *per_pin)
1206 /* try the prefer PCM */
1207 if (!test_bit(per_pin->pin_nid_idx, &spec->pcm_bitmap))
1208 return per_pin->pin_nid_idx;
1210 /* have a second try; check the "reserved area" over num_pins */
1211 for (i = spec->num_pins; i < spec->pcm_used; i++) {
1212 if (!test_bit(i, &spec->pcm_bitmap))
1216 /* the last try; check the empty slots in pins */
1217 for (i = 0; i < spec->num_pins; i++) {
1218 if (!test_bit(i, &spec->pcm_bitmap))
1224 static void hdmi_attach_hda_pcm(struct hdmi_spec *spec,
1225 struct hdmi_spec_per_pin *per_pin)
1229 /* pcm already be attached to the pin */
1232 idx = hdmi_find_pcm_slot(spec, per_pin);
1235 per_pin->pcm_idx = idx;
1236 per_pin->pcm = get_hdmi_pcm(spec, idx);
1237 set_bit(idx, &spec->pcm_bitmap);
1240 static void hdmi_detach_hda_pcm(struct hdmi_spec *spec,
1241 struct hdmi_spec_per_pin *per_pin)
1245 /* pcm already be detached from the pin */
1248 idx = per_pin->pcm_idx;
1249 per_pin->pcm_idx = -1;
1250 per_pin->pcm = NULL;
1251 if (idx >= 0 && idx < spec->pcm_used)
1252 clear_bit(idx, &spec->pcm_bitmap);
1255 static int hdmi_get_pin_cvt_mux(struct hdmi_spec *spec,
1256 struct hdmi_spec_per_pin *per_pin, hda_nid_t cvt_nid)
1260 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
1261 if (per_pin->mux_nids[mux_idx] == cvt_nid)
1266 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid);
1268 static void hdmi_pcm_setup_pin(struct hdmi_spec *spec,
1269 struct hdmi_spec_per_pin *per_pin)
1271 struct hda_codec *codec = per_pin->codec;
1272 struct hda_pcm *pcm;
1273 struct hda_pcm_stream *hinfo;
1274 struct snd_pcm_substream *substream;
1278 if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
1279 pcm = get_pcm_rec(spec, per_pin->pcm_idx);
1282 if (!test_bit(per_pin->pcm_idx, &spec->pcm_in_use))
1285 /* hdmi audio only uses playback and one substream */
1286 hinfo = pcm->stream;
1287 substream = pcm->pcm->streams[0].substream;
1289 per_pin->cvt_nid = hinfo->nid;
1291 mux_idx = hdmi_get_pin_cvt_mux(spec, per_pin, hinfo->nid);
1292 if (mux_idx < per_pin->num_mux_nids)
1293 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1294 AC_VERB_SET_CONNECT_SEL,
1296 snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid);
1298 non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid);
1299 if (substream->runtime)
1300 per_pin->channels = substream->runtime->channels;
1301 per_pin->setup = true;
1302 per_pin->mux_idx = mux_idx;
1304 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
1307 static void hdmi_pcm_reset_pin(struct hdmi_spec *spec,
1308 struct hdmi_spec_per_pin *per_pin)
1310 if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
1311 snd_hda_spdif_ctls_unassign(per_pin->codec, per_pin->pcm_idx);
1313 per_pin->chmap_set = false;
1314 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
1316 per_pin->setup = false;
1317 per_pin->channels = 0;
1320 /* update per_pin ELD from the given new ELD;
1321 * setup info frame and notification accordingly
1323 static void update_eld(struct hda_codec *codec,
1324 struct hdmi_spec_per_pin *per_pin,
1325 struct hdmi_eld *eld)
1327 struct hdmi_eld *pin_eld = &per_pin->sink_eld;
1328 struct hdmi_spec *spec = codec->spec;
1329 bool old_eld_valid = pin_eld->eld_valid;
1333 /* for monitor disconnection, save pcm_idx firstly */
1334 pcm_idx = per_pin->pcm_idx;
1335 if (spec->dyn_pcm_assign) {
1336 if (eld->eld_valid) {
1337 hdmi_attach_hda_pcm(spec, per_pin);
1338 hdmi_pcm_setup_pin(spec, per_pin);
1340 hdmi_pcm_reset_pin(spec, per_pin);
1341 hdmi_detach_hda_pcm(spec, per_pin);
1344 /* if pcm_idx == -1, it means this is in monitor connection event
1345 * we can get the correct pcm_idx now.
1348 pcm_idx = per_pin->pcm_idx;
1351 snd_hdmi_show_eld(codec, &eld->info);
1353 eld_changed = (pin_eld->eld_valid != eld->eld_valid);
1354 if (eld->eld_valid && pin_eld->eld_valid)
1355 if (pin_eld->eld_size != eld->eld_size ||
1356 memcmp(pin_eld->eld_buffer, eld->eld_buffer,
1357 eld->eld_size) != 0)
1360 pin_eld->monitor_present = eld->monitor_present;
1361 pin_eld->eld_valid = eld->eld_valid;
1362 pin_eld->eld_size = eld->eld_size;
1364 memcpy(pin_eld->eld_buffer, eld->eld_buffer, eld->eld_size);
1365 pin_eld->info = eld->info;
1368 * Re-setup pin and infoframe. This is needed e.g. when
1369 * - sink is first plugged-in
1370 * - transcoder can change during stream playback on Haswell
1371 * and this can make HW reset converter selection on a pin.
1373 if (eld->eld_valid && !old_eld_valid && per_pin->setup) {
1374 if (is_haswell_plus(codec) || is_valleyview_plus(codec)) {
1375 intel_verify_pin_cvt_connect(codec, per_pin);
1376 intel_not_share_assigned_cvt(codec, per_pin->pin_nid,
1380 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1383 if (eld_changed && pcm_idx >= 0)
1384 snd_ctl_notify(codec->card,
1385 SNDRV_CTL_EVENT_MASK_VALUE |
1386 SNDRV_CTL_EVENT_MASK_INFO,
1387 &get_hdmi_pcm(spec, pcm_idx)->eld_ctl->id);
1390 /* update ELD and jack state via HD-audio verbs */
1391 static bool hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin,
1394 struct hda_jack_tbl *jack;
1395 struct hda_codec *codec = per_pin->codec;
1396 struct hdmi_spec *spec = codec->spec;
1397 struct hdmi_eld *eld = &spec->temp_eld;
1398 struct hdmi_eld *pin_eld = &per_pin->sink_eld;
1399 hda_nid_t pin_nid = per_pin->pin_nid;
1401 * Always execute a GetPinSense verb here, even when called from
1402 * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
1403 * response's PD bit is not the real PD value, but indicates that
1404 * the real PD value changed. An older version of the HD-audio
1405 * specification worked this way. Hence, we just ignore the data in
1406 * the unsolicited response to avoid custom WARs.
1410 bool do_repoll = false;
1412 present = snd_hda_pin_sense(codec, pin_nid);
1414 mutex_lock(&per_pin->lock);
1415 pin_eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
1416 if (pin_eld->monitor_present)
1417 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
1419 eld->eld_valid = false;
1422 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
1423 codec->addr, pin_nid, pin_eld->monitor_present, eld->eld_valid);
1425 if (eld->eld_valid) {
1426 if (spec->ops.pin_get_eld(codec, pin_nid, eld->eld_buffer,
1427 &eld->eld_size) < 0)
1428 eld->eld_valid = false;
1430 if (snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer,
1432 eld->eld_valid = false;
1434 if (!eld->eld_valid && repoll)
1439 schedule_delayed_work(&per_pin->work, msecs_to_jiffies(300));
1441 update_eld(codec, per_pin, eld);
1443 ret = !repoll || !pin_eld->monitor_present || pin_eld->eld_valid;
1445 jack = snd_hda_jack_tbl_get(codec, pin_nid);
1447 jack->block_report = !ret;
1449 mutex_unlock(&per_pin->lock);
1453 static struct snd_jack *pin_idx_to_jack(struct hda_codec *codec,
1454 struct hdmi_spec_per_pin *per_pin)
1456 struct hdmi_spec *spec = codec->spec;
1457 struct snd_jack *jack = NULL;
1458 struct hda_jack_tbl *jack_tbl;
1460 /* if !dyn_pcm_assign, get jack from hda_jack_tbl
1461 * in !dyn_pcm_assign case, spec->pcm_rec[].jack is not
1462 * NULL even after snd_hda_jack_tbl_clear() is called to
1463 * free snd_jack. This may cause access invalid memory
1464 * when calling snd_jack_report
1466 if (per_pin->pcm_idx >= 0 && spec->dyn_pcm_assign)
1467 jack = spec->pcm_rec[per_pin->pcm_idx].jack;
1468 else if (!spec->dyn_pcm_assign) {
1469 jack_tbl = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
1471 jack = jack_tbl->jack;
1476 /* update ELD and jack state via audio component */
1477 static void sync_eld_via_acomp(struct hda_codec *codec,
1478 struct hdmi_spec_per_pin *per_pin)
1480 struct hdmi_spec *spec = codec->spec;
1481 struct hdmi_eld *eld = &spec->temp_eld;
1482 struct snd_jack *jack = NULL;
1485 mutex_lock(&per_pin->lock);
1486 eld->monitor_present = false;
1487 size = snd_hdac_acomp_get_eld(&codec->bus->core, per_pin->pin_nid,
1488 &eld->monitor_present, eld->eld_buffer,
1491 size = min(size, ELD_MAX_SIZE);
1492 if (snd_hdmi_parse_eld(codec, &eld->info,
1493 eld->eld_buffer, size) < 0)
1498 eld->eld_valid = true;
1499 eld->eld_size = size;
1501 eld->eld_valid = false;
1505 /* pcm_idx >=0 before update_eld() means it is in monitor
1506 * disconnected event. Jack must be fetched before update_eld()
1508 jack = pin_idx_to_jack(codec, per_pin);
1509 update_eld(codec, per_pin, eld);
1511 jack = pin_idx_to_jack(codec, per_pin);
1514 snd_jack_report(jack,
1515 eld->monitor_present ? SND_JACK_AVOUT : 0);
1517 mutex_unlock(&per_pin->lock);
1520 static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1522 struct hda_codec *codec = per_pin->codec;
1523 struct hdmi_spec *spec = codec->spec;
1526 /* no temporary power up/down needed for component notifier */
1527 if (!codec_has_acomp(codec))
1528 snd_hda_power_up_pm(codec);
1530 mutex_lock(&spec->pcm_lock);
1531 if (codec_has_acomp(codec)) {
1532 sync_eld_via_acomp(codec, per_pin);
1533 ret = false; /* don't call snd_hda_jack_report_sync() */
1535 ret = hdmi_present_sense_via_verbs(per_pin, repoll);
1537 mutex_unlock(&spec->pcm_lock);
1539 if (!codec_has_acomp(codec))
1540 snd_hda_power_down_pm(codec);
1545 static void hdmi_repoll_eld(struct work_struct *work)
1547 struct hdmi_spec_per_pin *per_pin =
1548 container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
1550 if (per_pin->repoll_count++ > 6)
1551 per_pin->repoll_count = 0;
1553 if (hdmi_present_sense(per_pin, per_pin->repoll_count))
1554 snd_hda_jack_report_sync(per_pin->codec);
1557 static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
1560 static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1562 struct hdmi_spec *spec = codec->spec;
1563 unsigned int caps, config;
1565 struct hdmi_spec_per_pin *per_pin;
1568 caps = snd_hda_query_pin_caps(codec, pin_nid);
1569 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
1572 config = snd_hda_codec_get_pincfg(codec, pin_nid);
1573 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
1576 if (is_haswell_plus(codec))
1577 intel_haswell_fixup_connect_list(codec, pin_nid);
1579 pin_idx = spec->num_pins;
1580 per_pin = snd_array_new(&spec->pins);
1584 per_pin->pin_nid = pin_nid;
1585 per_pin->non_pcm = false;
1586 if (spec->dyn_pcm_assign)
1587 per_pin->pcm_idx = -1;
1589 per_pin->pcm = get_hdmi_pcm(spec, pin_idx);
1590 per_pin->pcm_idx = pin_idx;
1592 per_pin->pin_nid_idx = pin_idx;
1594 err = hdmi_read_pin_conn(codec, pin_idx);
1603 static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1605 struct hdmi_spec *spec = codec->spec;
1606 struct hdmi_spec_per_cvt *per_cvt;
1610 chans = get_wcaps(codec, cvt_nid);
1611 chans = get_wcaps_channels(chans);
1613 per_cvt = snd_array_new(&spec->cvts);
1617 per_cvt->cvt_nid = cvt_nid;
1618 per_cvt->channels_min = 2;
1620 per_cvt->channels_max = chans;
1621 if (chans > spec->chmap.channels_max)
1622 spec->chmap.channels_max = chans;
1625 err = snd_hda_query_supported_pcm(codec, cvt_nid,
1632 if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids))
1633 spec->cvt_nids[spec->num_cvts] = cvt_nid;
1639 static int hdmi_parse_codec(struct hda_codec *codec)
1644 nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &nid);
1645 if (!nid || nodes < 0) {
1646 codec_warn(codec, "HDMI: failed to get afg sub nodes\n");
1650 for (i = 0; i < nodes; i++, nid++) {
1654 caps = get_wcaps(codec, nid);
1655 type = get_wcaps_type(caps);
1657 if (!(caps & AC_WCAP_DIGITAL))
1661 case AC_WID_AUD_OUT:
1662 hdmi_add_cvt(codec, nid);
1665 hdmi_add_pin(codec, nid);
1675 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1677 struct hda_spdif_out *spdif;
1680 mutex_lock(&codec->spdif_mutex);
1681 spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
1682 non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO);
1683 mutex_unlock(&codec->spdif_mutex);
1691 static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1692 struct hda_codec *codec,
1693 unsigned int stream_tag,
1694 unsigned int format,
1695 struct snd_pcm_substream *substream)
1697 hda_nid_t cvt_nid = hinfo->nid;
1698 struct hdmi_spec *spec = codec->spec;
1700 struct hdmi_spec_per_pin *per_pin;
1702 struct snd_pcm_runtime *runtime = substream->runtime;
1707 mutex_lock(&spec->pcm_lock);
1708 pin_idx = hinfo_to_pin_index(codec, hinfo);
1709 if (spec->dyn_pcm_assign && pin_idx < 0) {
1710 /* when dyn_pcm_assign and pcm is not bound to a pin
1711 * skip pin setup and return 0 to make audio playback
1714 intel_not_share_assigned_cvt_nid(codec, 0, cvt_nid);
1715 snd_hda_codec_setup_stream(codec, cvt_nid,
1716 stream_tag, 0, format);
1717 mutex_unlock(&spec->pcm_lock);
1721 if (snd_BUG_ON(pin_idx < 0)) {
1722 mutex_unlock(&spec->pcm_lock);
1725 per_pin = get_pin(spec, pin_idx);
1726 pin_nid = per_pin->pin_nid;
1727 if (is_haswell_plus(codec) || is_valleyview_plus(codec)) {
1728 /* Verify pin:cvt selections to avoid silent audio after S3.
1729 * After S3, the audio driver restores pin:cvt selections
1730 * but this can happen before gfx is ready and such selection
1731 * is overlooked by HW. Thus multiple pins can share a same
1732 * default convertor and mute control will affect each other,
1733 * which can cause a resumed audio playback become silent
1736 intel_verify_pin_cvt_connect(codec, per_pin);
1737 intel_not_share_assigned_cvt(codec, pin_nid, per_pin->mux_idx);
1740 /* Call sync_audio_rate to set the N/CTS/M manually if necessary */
1741 /* Todo: add DP1.2 MST audio support later */
1742 if (codec_has_acomp(codec))
1743 snd_hdac_sync_audio_rate(&codec->bus->core, pin_nid, runtime->rate);
1745 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
1746 mutex_lock(&per_pin->lock);
1747 per_pin->channels = substream->runtime->channels;
1748 per_pin->setup = true;
1750 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
1751 mutex_unlock(&per_pin->lock);
1752 if (spec->dyn_pin_out) {
1753 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
1754 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1755 snd_hda_codec_write(codec, pin_nid, 0,
1756 AC_VERB_SET_PIN_WIDGET_CONTROL,
1760 err = spec->ops.setup_stream(codec, cvt_nid, pin_nid,
1761 stream_tag, format);
1762 mutex_unlock(&spec->pcm_lock);
1766 static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1767 struct hda_codec *codec,
1768 struct snd_pcm_substream *substream)
1770 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
1774 static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1775 struct hda_codec *codec,
1776 struct snd_pcm_substream *substream)
1778 struct hdmi_spec *spec = codec->spec;
1779 int cvt_idx, pin_idx, pcm_idx;
1780 struct hdmi_spec_per_cvt *per_cvt;
1781 struct hdmi_spec_per_pin *per_pin;
1785 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1786 if (snd_BUG_ON(pcm_idx < 0))
1788 cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid);
1789 if (snd_BUG_ON(cvt_idx < 0))
1791 per_cvt = get_cvt(spec, cvt_idx);
1793 snd_BUG_ON(!per_cvt->assigned);
1794 per_cvt->assigned = 0;
1797 mutex_lock(&spec->pcm_lock);
1798 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
1799 clear_bit(pcm_idx, &spec->pcm_in_use);
1800 pin_idx = hinfo_to_pin_index(codec, hinfo);
1801 if (spec->dyn_pcm_assign && pin_idx < 0) {
1802 mutex_unlock(&spec->pcm_lock);
1806 if (snd_BUG_ON(pin_idx < 0)) {
1807 mutex_unlock(&spec->pcm_lock);
1810 per_pin = get_pin(spec, pin_idx);
1812 if (spec->dyn_pin_out) {
1813 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
1814 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1815 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
1816 AC_VERB_SET_PIN_WIDGET_CONTROL,
1820 mutex_lock(&per_pin->lock);
1821 per_pin->chmap_set = false;
1822 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
1824 per_pin->setup = false;
1825 per_pin->channels = 0;
1826 mutex_unlock(&per_pin->lock);
1827 mutex_unlock(&spec->pcm_lock);
1833 static const struct hda_pcm_ops generic_ops = {
1834 .open = hdmi_pcm_open,
1835 .close = hdmi_pcm_close,
1836 .prepare = generic_hdmi_playback_pcm_prepare,
1837 .cleanup = generic_hdmi_playback_pcm_cleanup,
1840 static void hdmi_get_chmap(struct hdac_device *hdac, int pcm_idx,
1841 unsigned char *chmap)
1843 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
1844 struct hdmi_spec *spec = codec->spec;
1845 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
1847 /* chmap is already set to 0 in caller */
1851 memcpy(chmap, per_pin->chmap, ARRAY_SIZE(per_pin->chmap));
1854 static void hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx,
1855 unsigned char *chmap, int prepared)
1857 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
1858 struct hdmi_spec *spec = codec->spec;
1859 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
1861 mutex_lock(&per_pin->lock);
1862 per_pin->chmap_set = true;
1863 memcpy(per_pin->chmap, chmap, ARRAY_SIZE(per_pin->chmap));
1865 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1866 mutex_unlock(&per_pin->lock);
1869 static bool is_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx)
1871 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
1872 struct hdmi_spec *spec = codec->spec;
1873 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
1875 return per_pin ? true:false;
1878 static int generic_hdmi_build_pcms(struct hda_codec *codec)
1880 struct hdmi_spec *spec = codec->spec;
1883 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1884 struct hda_pcm *info;
1885 struct hda_pcm_stream *pstr;
1887 info = snd_hda_codec_pcm_new(codec, "HDMI %d", pin_idx);
1891 spec->pcm_rec[pin_idx].pcm = info;
1893 info->pcm_type = HDA_PCM_TYPE_HDMI;
1894 info->own_chmap = true;
1896 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
1897 pstr->substreams = 1;
1898 pstr->ops = generic_ops;
1899 /* other pstr fields are set in open */
1905 static void free_hdmi_jack_priv(struct snd_jack *jack)
1907 struct hdmi_pcm *pcm = jack->private_data;
1912 static int add_hdmi_jack_kctl(struct hda_codec *codec,
1913 struct hdmi_spec *spec,
1917 struct snd_jack *jack;
1920 err = snd_jack_new(codec->card, name, SND_JACK_AVOUT, &jack,
1925 spec->pcm_rec[pcm_idx].jack = jack;
1926 jack->private_data = &spec->pcm_rec[pcm_idx];
1927 jack->private_free = free_hdmi_jack_priv;
1931 static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx)
1933 char hdmi_str[32] = "HDMI/DP";
1934 struct hdmi_spec *spec = codec->spec;
1935 struct hdmi_spec_per_pin *per_pin;
1936 struct hda_jack_tbl *jack;
1937 int pcmdev = get_pcm_rec(spec, pcm_idx)->device;
1942 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
1944 if (spec->dyn_pcm_assign)
1945 return add_hdmi_jack_kctl(codec, spec, pcm_idx, hdmi_str);
1947 /* for !dyn_pcm_assign, we still use hda_jack for compatibility */
1948 /* if !dyn_pcm_assign, it must be non-MST mode.
1949 * This means pcms and pins are statically mapped.
1950 * And pcm_idx is pin_idx.
1952 per_pin = get_pin(spec, pcm_idx);
1953 phantom_jack = !is_jack_detectable(codec, per_pin->pin_nid);
1955 strncat(hdmi_str, " Phantom",
1956 sizeof(hdmi_str) - strlen(hdmi_str) - 1);
1957 ret = snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str,
1961 jack = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
1964 /* assign jack->jack to pcm_rec[].jack to
1965 * align with dyn_pcm_assign mode
1967 spec->pcm_rec[pcm_idx].jack = jack->jack;
1971 static int generic_hdmi_build_controls(struct hda_codec *codec)
1973 struct hdmi_spec *spec = codec->spec;
1975 int pin_idx, pcm_idx;
1978 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
1979 err = generic_hdmi_build_jack(codec, pcm_idx);
1983 /* create the spdif for each pcm
1984 * pin will be bound when monitor is connected
1986 if (spec->dyn_pcm_assign)
1987 err = snd_hda_create_dig_out_ctls(codec,
1988 0, spec->cvt_nids[0],
1991 struct hdmi_spec_per_pin *per_pin =
1992 get_pin(spec, pcm_idx);
1993 err = snd_hda_create_dig_out_ctls(codec,
1995 per_pin->mux_nids[0],
2000 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
2002 /* add control for ELD Bytes */
2003 err = hdmi_create_eld_ctl(codec, pcm_idx,
2004 get_pcm_rec(spec, pcm_idx)->device);
2009 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2010 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2012 hdmi_present_sense(per_pin, 0);
2015 /* add channel maps */
2016 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2017 struct hda_pcm *pcm;
2019 pcm = get_pcm_rec(spec, pcm_idx);
2020 if (!pcm || !pcm->pcm)
2022 err = snd_hdac_add_chmap_ctls(pcm->pcm, pcm_idx, &spec->chmap);
2030 static int generic_hdmi_init_per_pins(struct hda_codec *codec)
2032 struct hdmi_spec *spec = codec->spec;
2035 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2036 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2038 per_pin->codec = codec;
2039 mutex_init(&per_pin->lock);
2040 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
2041 eld_proc_new(per_pin, pin_idx);
2046 static int generic_hdmi_init(struct hda_codec *codec)
2048 struct hdmi_spec *spec = codec->spec;
2051 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2052 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2053 hda_nid_t pin_nid = per_pin->pin_nid;
2055 hdmi_init_pin(codec, pin_nid);
2056 if (!codec_has_acomp(codec))
2057 snd_hda_jack_detect_enable_callback(codec, pin_nid,
2058 codec->jackpoll_interval > 0 ?
2059 jack_callback : NULL);
2064 static void hdmi_array_init(struct hdmi_spec *spec, int nums)
2066 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums);
2067 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums);
2070 static void hdmi_array_free(struct hdmi_spec *spec)
2072 snd_array_free(&spec->pins);
2073 snd_array_free(&spec->cvts);
2076 static void generic_spec_free(struct hda_codec *codec)
2078 struct hdmi_spec *spec = codec->spec;
2081 hdmi_array_free(spec);
2085 codec->dp_mst = false;
2088 static void generic_hdmi_free(struct hda_codec *codec)
2090 struct hdmi_spec *spec = codec->spec;
2091 int pin_idx, pcm_idx;
2093 if (codec_has_acomp(codec))
2094 snd_hdac_i915_register_notifier(NULL);
2096 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2097 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2098 cancel_delayed_work_sync(&per_pin->work);
2099 eld_proc_free(per_pin);
2102 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2103 if (spec->pcm_rec[pcm_idx].jack == NULL)
2105 if (spec->dyn_pcm_assign)
2106 snd_device_free(codec->card,
2107 spec->pcm_rec[pcm_idx].jack);
2109 spec->pcm_rec[pcm_idx].jack = NULL;
2112 generic_spec_free(codec);
2116 static int generic_hdmi_resume(struct hda_codec *codec)
2118 struct hdmi_spec *spec = codec->spec;
2121 codec->patch_ops.init(codec);
2122 regcache_sync(codec->core.regmap);
2124 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2125 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2126 hdmi_present_sense(per_pin, 1);
2132 static const struct hda_codec_ops generic_hdmi_patch_ops = {
2133 .init = generic_hdmi_init,
2134 .free = generic_hdmi_free,
2135 .build_pcms = generic_hdmi_build_pcms,
2136 .build_controls = generic_hdmi_build_controls,
2137 .unsol_event = hdmi_unsol_event,
2139 .resume = generic_hdmi_resume,
2143 static const struct hdmi_ops generic_standard_hdmi_ops = {
2144 .pin_get_eld = snd_hdmi_get_eld,
2145 .pin_setup_infoframe = hdmi_pin_setup_infoframe,
2146 .pin_hbr_setup = hdmi_pin_hbr_setup,
2147 .setup_stream = hdmi_setup_stream,
2150 /* allocate codec->spec and assign/initialize generic parser ops */
2151 static int alloc_generic_hdmi(struct hda_codec *codec)
2153 struct hdmi_spec *spec;
2155 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2159 spec->ops = generic_standard_hdmi_ops;
2160 mutex_init(&spec->pcm_lock);
2161 snd_hdac_register_chmap_ops(&codec->core, &spec->chmap);
2163 spec->chmap.ops.get_chmap = hdmi_get_chmap;
2164 spec->chmap.ops.set_chmap = hdmi_set_chmap;
2165 spec->chmap.ops.is_pcm_attached = is_hdmi_pcm_attached;
2168 hdmi_array_init(spec, 4);
2170 codec->patch_ops = generic_hdmi_patch_ops;
2175 /* generic HDMI parser */
2176 static int patch_generic_hdmi(struct hda_codec *codec)
2180 err = alloc_generic_hdmi(codec);
2184 err = hdmi_parse_codec(codec);
2186 generic_spec_free(codec);
2190 generic_hdmi_init_per_pins(codec);
2195 * Intel codec parsers and helpers
2198 static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
2201 struct hdmi_spec *spec = codec->spec;
2205 nconns = snd_hda_get_connections(codec, nid, conns, ARRAY_SIZE(conns));
2206 if (nconns == spec->num_cvts &&
2207 !memcmp(conns, spec->cvt_nids, spec->num_cvts * sizeof(hda_nid_t)))
2210 /* override pins connection list */
2211 codec_dbg(codec, "hdmi: haswell: override pin connection 0x%x\n", nid);
2212 snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids);
2215 #define INTEL_VENDOR_NID 0x08
2216 #define INTEL_GET_VENDOR_VERB 0xf81
2217 #define INTEL_SET_VENDOR_VERB 0x781
2218 #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
2219 #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
2221 static void intel_haswell_enable_all_pins(struct hda_codec *codec,
2224 unsigned int vendor_param;
2226 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
2227 INTEL_GET_VENDOR_VERB, 0);
2228 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
2231 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
2232 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
2233 INTEL_SET_VENDOR_VERB, vendor_param);
2234 if (vendor_param == -1)
2238 snd_hda_codec_update_widgets(codec);
2241 static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
2243 unsigned int vendor_param;
2245 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
2246 INTEL_GET_VENDOR_VERB, 0);
2247 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
2250 /* enable DP1.2 mode */
2251 vendor_param |= INTEL_EN_DP12;
2252 snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB);
2253 snd_hda_codec_write_cache(codec, INTEL_VENDOR_NID, 0,
2254 INTEL_SET_VENDOR_VERB, vendor_param);
2257 /* Haswell needs to re-issue the vendor-specific verbs before turning to D0.
2258 * Otherwise you may get severe h/w communication errors.
2260 static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2261 unsigned int power_state)
2263 if (power_state == AC_PWRST_D0) {
2264 intel_haswell_enable_all_pins(codec, false);
2265 intel_haswell_fixup_enable_dp12(codec);
2268 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
2269 snd_hda_codec_set_power_to_all(codec, fg, power_state);
2272 static void intel_pin_eld_notify(void *audio_ptr, int port)
2274 struct hda_codec *codec = audio_ptr;
2275 int pin_nid = port + 0x04;
2277 /* we assume only from port-B to port-D */
2278 if (port < 1 || port > 3)
2281 /* skip notification during system suspend (but not in runtime PM);
2282 * the state will be updated at resume
2284 if (snd_power_get_state(codec->card) != SNDRV_CTL_POWER_D0)
2286 /* ditto during suspend/resume process itself */
2287 if (atomic_read(&(codec)->core.in_pm))
2290 check_presence_and_report(codec, pin_nid);
2293 /* register i915 component pin_eld_notify callback */
2294 static void register_i915_notifier(struct hda_codec *codec)
2296 struct hdmi_spec *spec = codec->spec;
2298 spec->use_acomp_notifier = true;
2299 spec->i915_audio_ops.audio_ptr = codec;
2300 /* intel_audio_codec_enable() or intel_audio_codec_disable()
2301 * will call pin_eld_notify with using audio_ptr pointer
2302 * We need make sure audio_ptr is really setup
2305 spec->i915_audio_ops.pin_eld_notify = intel_pin_eld_notify;
2306 snd_hdac_i915_register_notifier(&spec->i915_audio_ops);
2309 /* Intel Haswell and onwards; audio component with eld notifier */
2310 static int patch_i915_hsw_hdmi(struct hda_codec *codec)
2312 struct hdmi_spec *spec;
2315 /* HSW+ requires i915 binding */
2316 if (!codec->bus->core.audio_component) {
2317 codec_info(codec, "No i915 binding for Intel HDMI/DP codec\n");
2321 err = alloc_generic_hdmi(codec);
2326 intel_haswell_enable_all_pins(codec, true);
2327 intel_haswell_fixup_enable_dp12(codec);
2329 /* For Haswell/Broadwell, the controller is also in the power well and
2330 * can cover the codec power request, and so need not set this flag.
2332 if (!is_haswell(codec) && !is_broadwell(codec))
2333 codec->core.link_power_control = 1;
2335 codec->patch_ops.set_power_state = haswell_set_power_state;
2336 codec->dp_mst = true;
2337 codec->depop_delay = 0;
2338 codec->auto_runtime_pm = 1;
2340 err = hdmi_parse_codec(codec);
2342 generic_spec_free(codec);
2346 generic_hdmi_init_per_pins(codec);
2347 register_i915_notifier(codec);
2351 /* Intel Baytrail and Braswell; without get_eld notifier */
2352 static int patch_i915_byt_hdmi(struct hda_codec *codec)
2354 struct hdmi_spec *spec;
2357 /* requires i915 binding */
2358 if (!codec->bus->core.audio_component) {
2359 codec_info(codec, "No i915 binding for Intel HDMI/DP codec\n");
2363 err = alloc_generic_hdmi(codec);
2368 /* For Valleyview/Cherryview, only the display codec is in the display
2369 * power well and can use link_power ops to request/release the power.
2371 codec->core.link_power_control = 1;
2373 codec->depop_delay = 0;
2374 codec->auto_runtime_pm = 1;
2376 err = hdmi_parse_codec(codec);
2378 generic_spec_free(codec);
2382 generic_hdmi_init_per_pins(codec);
2387 * Shared non-generic implementations
2390 static int simple_playback_build_pcms(struct hda_codec *codec)
2392 struct hdmi_spec *spec = codec->spec;
2393 struct hda_pcm *info;
2395 struct hda_pcm_stream *pstr;
2396 struct hdmi_spec_per_cvt *per_cvt;
2398 per_cvt = get_cvt(spec, 0);
2399 chans = get_wcaps(codec, per_cvt->cvt_nid);
2400 chans = get_wcaps_channels(chans);
2402 info = snd_hda_codec_pcm_new(codec, "HDMI 0");
2405 spec->pcm_rec[0].pcm = info;
2406 info->pcm_type = HDA_PCM_TYPE_HDMI;
2407 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
2408 *pstr = spec->pcm_playback;
2409 pstr->nid = per_cvt->cvt_nid;
2410 if (pstr->channels_max <= 2 && chans && chans <= 16)
2411 pstr->channels_max = chans;
2416 /* unsolicited event for jack sensing */
2417 static void simple_hdmi_unsol_event(struct hda_codec *codec,
2420 snd_hda_jack_set_dirty_all(codec);
2421 snd_hda_jack_report_sync(codec);
2424 /* generic_hdmi_build_jack can be used for simple_hdmi, too,
2425 * as long as spec->pins[] is set correctly
2427 #define simple_hdmi_build_jack generic_hdmi_build_jack
2429 static int simple_playback_build_controls(struct hda_codec *codec)
2431 struct hdmi_spec *spec = codec->spec;
2432 struct hdmi_spec_per_cvt *per_cvt;
2435 per_cvt = get_cvt(spec, 0);
2436 err = snd_hda_create_dig_out_ctls(codec, per_cvt->cvt_nid,
2441 return simple_hdmi_build_jack(codec, 0);
2444 static int simple_playback_init(struct hda_codec *codec)
2446 struct hdmi_spec *spec = codec->spec;
2447 struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0);
2448 hda_nid_t pin = per_pin->pin_nid;
2450 snd_hda_codec_write(codec, pin, 0,
2451 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
2452 /* some codecs require to unmute the pin */
2453 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
2454 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2456 snd_hda_jack_detect_enable(codec, pin);
2460 static void simple_playback_free(struct hda_codec *codec)
2462 struct hdmi_spec *spec = codec->spec;
2464 hdmi_array_free(spec);
2469 * Nvidia specific implementations
2472 #define Nv_VERB_SET_Channel_Allocation 0xF79
2473 #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
2474 #define Nv_VERB_SET_Audio_Protection_On 0xF98
2475 #define Nv_VERB_SET_Audio_Protection_Off 0xF99
2477 #define nvhdmi_master_con_nid_7x 0x04
2478 #define nvhdmi_master_pin_nid_7x 0x05
2480 static const hda_nid_t nvhdmi_con_nids_7x[4] = {
2481 /*front, rear, clfe, rear_surr */
2485 static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = {
2486 /* set audio protect on */
2487 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
2488 /* enable digital output on pin widget */
2489 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2493 static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = {
2494 /* set audio protect on */
2495 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
2496 /* enable digital output on pin widget */
2497 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2498 { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2499 { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2500 { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2501 { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2505 #ifdef LIMITED_RATE_FMT_SUPPORT
2506 /* support only the safe format and rate */
2507 #define SUPPORTED_RATES SNDRV_PCM_RATE_48000
2508 #define SUPPORTED_MAXBPS 16
2509 #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
2511 /* support all rates and formats */
2512 #define SUPPORTED_RATES \
2513 (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
2514 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
2515 SNDRV_PCM_RATE_192000)
2516 #define SUPPORTED_MAXBPS 24
2517 #define SUPPORTED_FORMATS \
2518 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
2521 static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
2523 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
2527 static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
2529 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
2533 static unsigned int channels_2_6_8[] = {
2537 static unsigned int channels_2_8[] = {
2541 static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
2542 .count = ARRAY_SIZE(channels_2_6_8),
2543 .list = channels_2_6_8,
2547 static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
2548 .count = ARRAY_SIZE(channels_2_8),
2549 .list = channels_2_8,
2553 static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
2554 struct hda_codec *codec,
2555 struct snd_pcm_substream *substream)
2557 struct hdmi_spec *spec = codec->spec;
2558 struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
2560 switch (codec->preset->vendor_id) {
2565 hw_constraints_channels = &hw_constraints_2_8_channels;
2568 hw_constraints_channels = &hw_constraints_2_6_8_channels;
2574 if (hw_constraints_channels != NULL) {
2575 snd_pcm_hw_constraint_list(substream->runtime, 0,
2576 SNDRV_PCM_HW_PARAM_CHANNELS,
2577 hw_constraints_channels);
2579 snd_pcm_hw_constraint_step(substream->runtime, 0,
2580 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
2583 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2586 static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
2587 struct hda_codec *codec,
2588 struct snd_pcm_substream *substream)
2590 struct hdmi_spec *spec = codec->spec;
2591 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2594 static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2595 struct hda_codec *codec,
2596 unsigned int stream_tag,
2597 unsigned int format,
2598 struct snd_pcm_substream *substream)
2600 struct hdmi_spec *spec = codec->spec;
2601 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2602 stream_tag, format, substream);
2605 static const struct hda_pcm_stream simple_pcm_playback = {
2610 .open = simple_playback_pcm_open,
2611 .close = simple_playback_pcm_close,
2612 .prepare = simple_playback_pcm_prepare
2616 static const struct hda_codec_ops simple_hdmi_patch_ops = {
2617 .build_controls = simple_playback_build_controls,
2618 .build_pcms = simple_playback_build_pcms,
2619 .init = simple_playback_init,
2620 .free = simple_playback_free,
2621 .unsol_event = simple_hdmi_unsol_event,
2624 static int patch_simple_hdmi(struct hda_codec *codec,
2625 hda_nid_t cvt_nid, hda_nid_t pin_nid)
2627 struct hdmi_spec *spec;
2628 struct hdmi_spec_per_cvt *per_cvt;
2629 struct hdmi_spec_per_pin *per_pin;
2631 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2636 hdmi_array_init(spec, 1);
2638 spec->multiout.num_dacs = 0; /* no analog */
2639 spec->multiout.max_channels = 2;
2640 spec->multiout.dig_out_nid = cvt_nid;
2643 per_pin = snd_array_new(&spec->pins);
2644 per_cvt = snd_array_new(&spec->cvts);
2645 if (!per_pin || !per_cvt) {
2646 simple_playback_free(codec);
2649 per_cvt->cvt_nid = cvt_nid;
2650 per_pin->pin_nid = pin_nid;
2651 spec->pcm_playback = simple_pcm_playback;
2653 codec->patch_ops = simple_hdmi_patch_ops;
2658 static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
2661 unsigned int chanmask;
2662 int chan = channels ? (channels - 1) : 1;
2681 /* Set the audio infoframe channel allocation and checksum fields. The
2682 * channel count is computed implicitly by the hardware. */
2683 snd_hda_codec_write(codec, 0x1, 0,
2684 Nv_VERB_SET_Channel_Allocation, chanmask);
2686 snd_hda_codec_write(codec, 0x1, 0,
2687 Nv_VERB_SET_Info_Frame_Checksum,
2688 (0x71 - chan - chanmask));
2691 static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
2692 struct hda_codec *codec,
2693 struct snd_pcm_substream *substream)
2695 struct hdmi_spec *spec = codec->spec;
2698 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
2699 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
2700 for (i = 0; i < 4; i++) {
2701 /* set the stream id */
2702 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
2703 AC_VERB_SET_CHANNEL_STREAMID, 0);
2704 /* set the stream format */
2705 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
2706 AC_VERB_SET_STREAM_FORMAT, 0);
2709 /* The audio hardware sends a channel count of 0x7 (8ch) when all the
2710 * streams are disabled. */
2711 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
2713 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2716 static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
2717 struct hda_codec *codec,
2718 unsigned int stream_tag,
2719 unsigned int format,
2720 struct snd_pcm_substream *substream)
2723 unsigned int dataDCC2, channel_id;
2725 struct hdmi_spec *spec = codec->spec;
2726 struct hda_spdif_out *spdif;
2727 struct hdmi_spec_per_cvt *per_cvt;
2729 mutex_lock(&codec->spdif_mutex);
2730 per_cvt = get_cvt(spec, 0);
2731 spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid);
2733 chs = substream->runtime->channels;
2737 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
2738 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
2739 snd_hda_codec_write(codec,
2740 nvhdmi_master_con_nid_7x,
2742 AC_VERB_SET_DIGI_CONVERT_1,
2743 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
2745 /* set the stream id */
2746 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
2747 AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
2749 /* set the stream format */
2750 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
2751 AC_VERB_SET_STREAM_FORMAT, format);
2753 /* turn on again (if needed) */
2754 /* enable and set the channel status audio/data flag */
2755 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
2756 snd_hda_codec_write(codec,
2757 nvhdmi_master_con_nid_7x,
2759 AC_VERB_SET_DIGI_CONVERT_1,
2760 spdif->ctls & 0xff);
2761 snd_hda_codec_write(codec,
2762 nvhdmi_master_con_nid_7x,
2764 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
2767 for (i = 0; i < 4; i++) {
2773 /* turn off SPDIF once;
2774 *otherwise the IEC958 bits won't be updated
2776 if (codec->spdif_status_reset &&
2777 (spdif->ctls & AC_DIG1_ENABLE))
2778 snd_hda_codec_write(codec,
2779 nvhdmi_con_nids_7x[i],
2781 AC_VERB_SET_DIGI_CONVERT_1,
2782 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
2783 /* set the stream id */
2784 snd_hda_codec_write(codec,
2785 nvhdmi_con_nids_7x[i],
2787 AC_VERB_SET_CHANNEL_STREAMID,
2788 (stream_tag << 4) | channel_id);
2789 /* set the stream format */
2790 snd_hda_codec_write(codec,
2791 nvhdmi_con_nids_7x[i],
2793 AC_VERB_SET_STREAM_FORMAT,
2795 /* turn on again (if needed) */
2796 /* enable and set the channel status audio/data flag */
2797 if (codec->spdif_status_reset &&
2798 (spdif->ctls & AC_DIG1_ENABLE)) {
2799 snd_hda_codec_write(codec,
2800 nvhdmi_con_nids_7x[i],
2802 AC_VERB_SET_DIGI_CONVERT_1,
2803 spdif->ctls & 0xff);
2804 snd_hda_codec_write(codec,
2805 nvhdmi_con_nids_7x[i],
2807 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
2811 nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
2813 mutex_unlock(&codec->spdif_mutex);
2817 static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
2821 .nid = nvhdmi_master_con_nid_7x,
2822 .rates = SUPPORTED_RATES,
2823 .maxbps = SUPPORTED_MAXBPS,
2824 .formats = SUPPORTED_FORMATS,
2826 .open = simple_playback_pcm_open,
2827 .close = nvhdmi_8ch_7x_pcm_close,
2828 .prepare = nvhdmi_8ch_7x_pcm_prepare
2832 static int patch_nvhdmi_2ch(struct hda_codec *codec)
2834 struct hdmi_spec *spec;
2835 int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
2836 nvhdmi_master_pin_nid_7x);
2840 codec->patch_ops.init = nvhdmi_7x_init_2ch;
2841 /* override the PCM rates, etc, as the codec doesn't give full list */
2843 spec->pcm_playback.rates = SUPPORTED_RATES;
2844 spec->pcm_playback.maxbps = SUPPORTED_MAXBPS;
2845 spec->pcm_playback.formats = SUPPORTED_FORMATS;
2849 static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
2851 struct hdmi_spec *spec = codec->spec;
2852 int err = simple_playback_build_pcms(codec);
2854 struct hda_pcm *info = get_pcm_rec(spec, 0);
2855 info->own_chmap = true;
2860 static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
2862 struct hdmi_spec *spec = codec->spec;
2863 struct hda_pcm *info;
2864 struct snd_pcm_chmap *chmap;
2867 err = simple_playback_build_controls(codec);
2871 /* add channel maps */
2872 info = get_pcm_rec(spec, 0);
2873 err = snd_pcm_add_chmap_ctls(info->pcm,
2874 SNDRV_PCM_STREAM_PLAYBACK,
2875 snd_pcm_alt_chmaps, 8, 0, &chmap);
2878 switch (codec->preset->vendor_id) {
2883 chmap->channel_mask = (1U << 2) | (1U << 8);
2886 chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8);
2891 static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
2893 struct hdmi_spec *spec;
2894 int err = patch_nvhdmi_2ch(codec);
2898 spec->multiout.max_channels = 8;
2899 spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x;
2900 codec->patch_ops.init = nvhdmi_7x_init_8ch;
2901 codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
2902 codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
2904 /* Initialize the audio infoframe channel mask and checksum to something
2906 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
2912 * NVIDIA codecs ignore ASP mapping for 2ch - confirmed on:
2916 static int nvhdmi_chmap_cea_alloc_validate_get_type(struct hdac_chmap *chmap,
2917 struct hdac_cea_channel_speaker_allocation *cap, int channels)
2919 if (cap->ca_index == 0x00 && channels == 2)
2920 return SNDRV_CTL_TLVT_CHMAP_FIXED;
2922 /* If the speaker allocation matches the channel count, it is OK. */
2923 if (cap->channels != channels)
2926 /* all channels are remappable freely */
2927 return SNDRV_CTL_TLVT_CHMAP_VAR;
2930 static int nvhdmi_chmap_validate(struct hdac_chmap *chmap,
2931 int ca, int chs, unsigned char *map)
2933 if (ca == 0x00 && (map[0] != SNDRV_CHMAP_FL || map[1] != SNDRV_CHMAP_FR))
2939 static int patch_nvhdmi(struct hda_codec *codec)
2941 struct hdmi_spec *spec;
2944 err = patch_generic_hdmi(codec);
2949 spec->dyn_pin_out = true;
2951 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
2952 nvhdmi_chmap_cea_alloc_validate_get_type;
2953 spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate;
2959 * The HDA codec on NVIDIA Tegra contains two scratch registers that are
2960 * accessed using vendor-defined verbs. These registers can be used for
2961 * interoperability between the HDA and HDMI drivers.
2964 /* Audio Function Group node */
2965 #define NVIDIA_AFG_NID 0x01
2968 * The SCRATCH0 register is used to notify the HDMI codec of changes in audio
2969 * format. On Tegra, bit 31 is used as a trigger that causes an interrupt to
2970 * be raised in the HDMI codec. The remainder of the bits is arbitrary. This
2971 * implementation stores the HDA format (see AC_FMT_*) in bits [15:0] and an
2972 * additional bit (at position 30) to signal the validity of the format.
2974 * | 31 | 30 | 29 16 | 15 0 |
2975 * +---------+-------+--------+--------+
2976 * | TRIGGER | VALID | UNUSED | FORMAT |
2977 * +-----------------------------------|
2979 * Note that for the trigger bit to take effect it needs to change value
2980 * (i.e. it needs to be toggled).
2982 #define NVIDIA_GET_SCRATCH0 0xfa6
2983 #define NVIDIA_SET_SCRATCH0_BYTE0 0xfa7
2984 #define NVIDIA_SET_SCRATCH0_BYTE1 0xfa8
2985 #define NVIDIA_SET_SCRATCH0_BYTE2 0xfa9
2986 #define NVIDIA_SET_SCRATCH0_BYTE3 0xfaa
2987 #define NVIDIA_SCRATCH_TRIGGER (1 << 7)
2988 #define NVIDIA_SCRATCH_VALID (1 << 6)
2990 #define NVIDIA_GET_SCRATCH1 0xfab
2991 #define NVIDIA_SET_SCRATCH1_BYTE0 0xfac
2992 #define NVIDIA_SET_SCRATCH1_BYTE1 0xfad
2993 #define NVIDIA_SET_SCRATCH1_BYTE2 0xfae
2994 #define NVIDIA_SET_SCRATCH1_BYTE3 0xfaf
2997 * The format parameter is the HDA audio format (see AC_FMT_*). If set to 0,
2998 * the format is invalidated so that the HDMI codec can be disabled.
3000 static void tegra_hdmi_set_format(struct hda_codec *codec, unsigned int format)
3004 /* bits [31:30] contain the trigger and valid bits */
3005 value = snd_hda_codec_read(codec, NVIDIA_AFG_NID, 0,
3006 NVIDIA_GET_SCRATCH0, 0);
3007 value = (value >> 24) & 0xff;
3009 /* bits [15:0] are used to store the HDA format */
3010 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3011 NVIDIA_SET_SCRATCH0_BYTE0,
3012 (format >> 0) & 0xff);
3013 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3014 NVIDIA_SET_SCRATCH0_BYTE1,
3015 (format >> 8) & 0xff);
3017 /* bits [16:24] are unused */
3018 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3019 NVIDIA_SET_SCRATCH0_BYTE2, 0);
3022 * Bit 30 signals that the data is valid and hence that HDMI audio can
3026 value &= ~NVIDIA_SCRATCH_VALID;
3028 value |= NVIDIA_SCRATCH_VALID;
3031 * Whenever the trigger bit is toggled, an interrupt is raised in the
3032 * HDMI codec. The HDMI driver will use that as trigger to update its
3035 value ^= NVIDIA_SCRATCH_TRIGGER;
3037 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3038 NVIDIA_SET_SCRATCH0_BYTE3, value);
3041 static int tegra_hdmi_pcm_prepare(struct hda_pcm_stream *hinfo,
3042 struct hda_codec *codec,
3043 unsigned int stream_tag,
3044 unsigned int format,
3045 struct snd_pcm_substream *substream)
3049 err = generic_hdmi_playback_pcm_prepare(hinfo, codec, stream_tag,
3054 /* notify the HDMI codec of the format change */
3055 tegra_hdmi_set_format(codec, format);
3060 static int tegra_hdmi_pcm_cleanup(struct hda_pcm_stream *hinfo,
3061 struct hda_codec *codec,
3062 struct snd_pcm_substream *substream)
3064 /* invalidate the format in the HDMI codec */
3065 tegra_hdmi_set_format(codec, 0);
3067 return generic_hdmi_playback_pcm_cleanup(hinfo, codec, substream);
3070 static struct hda_pcm *hda_find_pcm_by_type(struct hda_codec *codec, int type)
3072 struct hdmi_spec *spec = codec->spec;
3075 for (i = 0; i < spec->num_pins; i++) {
3076 struct hda_pcm *pcm = get_pcm_rec(spec, i);
3078 if (pcm->pcm_type == type)
3085 static int tegra_hdmi_build_pcms(struct hda_codec *codec)
3087 struct hda_pcm_stream *stream;
3088 struct hda_pcm *pcm;
3091 err = generic_hdmi_build_pcms(codec);
3095 pcm = hda_find_pcm_by_type(codec, HDA_PCM_TYPE_HDMI);
3100 * Override ->prepare() and ->cleanup() operations to notify the HDMI
3101 * codec about format changes.
3103 stream = &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
3104 stream->ops.prepare = tegra_hdmi_pcm_prepare;
3105 stream->ops.cleanup = tegra_hdmi_pcm_cleanup;
3110 static int patch_tegra_hdmi(struct hda_codec *codec)
3114 err = patch_generic_hdmi(codec);
3118 codec->patch_ops.build_pcms = tegra_hdmi_build_pcms;
3124 * ATI/AMD-specific implementations
3127 #define is_amdhdmi_rev3_or_later(codec) \
3128 ((codec)->core.vendor_id == 0x1002aa01 && \
3129 ((codec)->core.revision_id & 0xff00) >= 0x0300)
3130 #define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec)
3132 /* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */
3133 #define ATI_VERB_SET_CHANNEL_ALLOCATION 0x771
3134 #define ATI_VERB_SET_DOWNMIX_INFO 0x772
3135 #define ATI_VERB_SET_MULTICHANNEL_01 0x777
3136 #define ATI_VERB_SET_MULTICHANNEL_23 0x778
3137 #define ATI_VERB_SET_MULTICHANNEL_45 0x779
3138 #define ATI_VERB_SET_MULTICHANNEL_67 0x77a
3139 #define ATI_VERB_SET_HBR_CONTROL 0x77c
3140 #define ATI_VERB_SET_MULTICHANNEL_1 0x785
3141 #define ATI_VERB_SET_MULTICHANNEL_3 0x786
3142 #define ATI_VERB_SET_MULTICHANNEL_5 0x787
3143 #define ATI_VERB_SET_MULTICHANNEL_7 0x788
3144 #define ATI_VERB_SET_MULTICHANNEL_MODE 0x789
3145 #define ATI_VERB_GET_CHANNEL_ALLOCATION 0xf71
3146 #define ATI_VERB_GET_DOWNMIX_INFO 0xf72
3147 #define ATI_VERB_GET_MULTICHANNEL_01 0xf77
3148 #define ATI_VERB_GET_MULTICHANNEL_23 0xf78
3149 #define ATI_VERB_GET_MULTICHANNEL_45 0xf79
3150 #define ATI_VERB_GET_MULTICHANNEL_67 0xf7a
3151 #define ATI_VERB_GET_HBR_CONTROL 0xf7c
3152 #define ATI_VERB_GET_MULTICHANNEL_1 0xf85
3153 #define ATI_VERB_GET_MULTICHANNEL_3 0xf86
3154 #define ATI_VERB_GET_MULTICHANNEL_5 0xf87
3155 #define ATI_VERB_GET_MULTICHANNEL_7 0xf88
3156 #define ATI_VERB_GET_MULTICHANNEL_MODE 0xf89
3158 /* AMD specific HDA cvt verbs */
3159 #define ATI_VERB_SET_RAMP_RATE 0x770
3160 #define ATI_VERB_GET_RAMP_RATE 0xf70
3162 #define ATI_OUT_ENABLE 0x1
3164 #define ATI_MULTICHANNEL_MODE_PAIRED 0
3165 #define ATI_MULTICHANNEL_MODE_SINGLE 1
3167 #define ATI_HBR_CAPABLE 0x01
3168 #define ATI_HBR_ENABLE 0x10
3170 static int atihdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
3171 unsigned char *buf, int *eld_size)
3173 /* call hda_eld.c ATI/AMD-specific function */
3174 return snd_hdmi_get_eld_ati(codec, nid, buf, eld_size,
3175 is_amdhdmi_rev3_or_later(codec));
3178 static void atihdmi_pin_setup_infoframe(struct hda_codec *codec, hda_nid_t pin_nid, int ca,
3179 int active_channels, int conn_type)
3181 snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_CHANNEL_ALLOCATION, ca);
3184 static int atihdmi_paired_swap_fc_lfe(int pos)
3187 * ATI/AMD have automatic FC/LFE swap built-in
3188 * when in pairwise mapping mode.
3192 /* see channel_allocations[].speakers[] */
3201 static int atihdmi_paired_chmap_validate(struct hdac_chmap *chmap,
3202 int ca, int chs, unsigned char *map)
3204 struct hdac_cea_channel_speaker_allocation *cap;
3207 /* check that only channel pairs need to be remapped on old pre-rev3 ATI/AMD */
3209 cap = snd_hdac_get_ch_alloc_from_ca(ca);
3210 for (i = 0; i < chs; ++i) {
3211 int mask = snd_hdac_chmap_to_spk_mask(map[i]);
3213 bool companion_ok = false;
3218 for (j = 0 + i % 2; j < 8; j += 2) {
3219 int chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j);
3220 if (cap->speakers[chan_idx] == mask) {
3221 /* channel is in a supported position */
3224 if (i % 2 == 0 && i + 1 < chs) {
3225 /* even channel, check the odd companion */
3226 int comp_chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j + 1);
3227 int comp_mask_req = snd_hdac_chmap_to_spk_mask(map[i+1]);
3228 int comp_mask_act = cap->speakers[comp_chan_idx];
3230 if (comp_mask_req == comp_mask_act)
3231 companion_ok = true;
3243 i++; /* companion channel already checked */
3249 static int atihdmi_pin_set_slot_channel(struct hdac_device *hdac,
3250 hda_nid_t pin_nid, int hdmi_slot, int stream_channel)
3252 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
3254 int ati_channel_setup = 0;
3259 if (!has_amd_full_remap_support(codec)) {
3260 hdmi_slot = atihdmi_paired_swap_fc_lfe(hdmi_slot);
3262 /* In case this is an odd slot but without stream channel, do not
3263 * disable the slot since the corresponding even slot could have a
3264 * channel. In case neither have a channel, the slot pair will be
3265 * disabled when this function is called for the even slot. */
3266 if (hdmi_slot % 2 != 0 && stream_channel == 0xf)
3269 hdmi_slot -= hdmi_slot % 2;
3271 if (stream_channel != 0xf)
3272 stream_channel -= stream_channel % 2;
3275 verb = ATI_VERB_SET_MULTICHANNEL_01 + hdmi_slot/2 + (hdmi_slot % 2) * 0x00e;
3277 /* ati_channel_setup format: [7..4] = stream_channel_id, [1] = mute, [0] = enable */
3279 if (stream_channel != 0xf)
3280 ati_channel_setup = (stream_channel << 4) | ATI_OUT_ENABLE;
3282 return snd_hda_codec_write(codec, pin_nid, 0, verb, ati_channel_setup);
3285 static int atihdmi_pin_get_slot_channel(struct hdac_device *hdac,
3286 hda_nid_t pin_nid, int asp_slot)
3288 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
3289 bool was_odd = false;
3290 int ati_asp_slot = asp_slot;
3292 int ati_channel_setup;
3297 if (!has_amd_full_remap_support(codec)) {
3298 ati_asp_slot = atihdmi_paired_swap_fc_lfe(asp_slot);
3299 if (ati_asp_slot % 2 != 0) {
3305 verb = ATI_VERB_GET_MULTICHANNEL_01 + ati_asp_slot/2 + (ati_asp_slot % 2) * 0x00e;
3307 ati_channel_setup = snd_hda_codec_read(codec, pin_nid, 0, verb, 0);
3309 if (!(ati_channel_setup & ATI_OUT_ENABLE))
3312 return ((ati_channel_setup & 0xf0) >> 4) + !!was_odd;
3315 static int atihdmi_paired_chmap_cea_alloc_validate_get_type(
3316 struct hdac_chmap *chmap,
3317 struct hdac_cea_channel_speaker_allocation *cap,
3323 * Pre-rev3 ATI/AMD codecs operate in a paired channel mode, so
3324 * we need to take that into account (a single channel may take 2
3325 * channel slots if we need to carry a silent channel next to it).
3326 * On Rev3+ AMD codecs this function is not used.
3330 /* We only produce even-numbered channel count TLVs */
3331 if ((channels % 2) != 0)
3334 for (c = 0; c < 7; c += 2) {
3335 if (cap->speakers[c] || cap->speakers[c+1])
3339 if (chanpairs * 2 != channels)
3342 return SNDRV_CTL_TLVT_CHMAP_PAIRED;
3345 static void atihdmi_paired_cea_alloc_to_tlv_chmap(struct hdac_chmap *hchmap,
3346 struct hdac_cea_channel_speaker_allocation *cap,
3347 unsigned int *chmap, int channels)
3349 /* produce paired maps for pre-rev3 ATI/AMD codecs */
3353 for (c = 7; c >= 0; c--) {
3354 int chan = 7 - atihdmi_paired_swap_fc_lfe(7 - c);
3355 int spk = cap->speakers[chan];
3357 /* add N/A channel if the companion channel is occupied */
3358 if (cap->speakers[chan + (chan % 2 ? -1 : 1)])
3359 chmap[count++] = SNDRV_CHMAP_NA;
3364 chmap[count++] = snd_hdac_spk_to_chmap(spk);
3367 WARN_ON(count != channels);
3370 static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
3373 int hbr_ctl, hbr_ctl_new;
3375 hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0);
3376 if (hbr_ctl >= 0 && (hbr_ctl & ATI_HBR_CAPABLE)) {
3378 hbr_ctl_new = hbr_ctl | ATI_HBR_ENABLE;
3380 hbr_ctl_new = hbr_ctl & ~ATI_HBR_ENABLE;
3383 "atihdmi_pin_hbr_setup: NID=0x%x, %shbr-ctl=0x%x\n",
3385 hbr_ctl == hbr_ctl_new ? "" : "new-",
3388 if (hbr_ctl != hbr_ctl_new)
3389 snd_hda_codec_write(codec, pin_nid, 0,
3390 ATI_VERB_SET_HBR_CONTROL,
3399 static int atihdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
3400 hda_nid_t pin_nid, u32 stream_tag, int format)
3403 if (is_amdhdmi_rev3_or_later(codec)) {
3404 int ramp_rate = 180; /* default as per AMD spec */
3405 /* disable ramp-up/down for non-pcm as per AMD spec */
3406 if (format & AC_FMT_TYPE_NON_PCM)
3409 snd_hda_codec_write(codec, cvt_nid, 0, ATI_VERB_SET_RAMP_RATE, ramp_rate);
3412 return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
3416 static int atihdmi_init(struct hda_codec *codec)
3418 struct hdmi_spec *spec = codec->spec;
3421 err = generic_hdmi_init(codec);
3426 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
3427 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
3429 /* make sure downmix information in infoframe is zero */
3430 snd_hda_codec_write(codec, per_pin->pin_nid, 0, ATI_VERB_SET_DOWNMIX_INFO, 0);
3432 /* enable channel-wise remap mode if supported */
3433 if (has_amd_full_remap_support(codec))
3434 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
3435 ATI_VERB_SET_MULTICHANNEL_MODE,
3436 ATI_MULTICHANNEL_MODE_SINGLE);
3442 static int patch_atihdmi(struct hda_codec *codec)
3444 struct hdmi_spec *spec;
3445 struct hdmi_spec_per_cvt *per_cvt;
3448 err = patch_generic_hdmi(codec);
3453 codec->patch_ops.init = atihdmi_init;
3457 spec->ops.pin_get_eld = atihdmi_pin_get_eld;
3458 spec->ops.pin_setup_infoframe = atihdmi_pin_setup_infoframe;
3459 spec->ops.pin_hbr_setup = atihdmi_pin_hbr_setup;
3460 spec->ops.setup_stream = atihdmi_setup_stream;
3462 if (!has_amd_full_remap_support(codec)) {
3463 /* override to ATI/AMD-specific versions with pairwise mapping */
3464 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
3465 atihdmi_paired_chmap_cea_alloc_validate_get_type;
3466 spec->chmap.ops.cea_alloc_to_tlv_chmap =
3467 atihdmi_paired_cea_alloc_to_tlv_chmap;
3468 spec->chmap.ops.chmap_validate = atihdmi_paired_chmap_validate;
3469 spec->chmap.ops.pin_get_slot_channel =
3470 atihdmi_pin_get_slot_channel;
3471 spec->chmap.ops.pin_set_slot_channel =
3472 atihdmi_pin_set_slot_channel;
3475 /* ATI/AMD converters do not advertise all of their capabilities */
3476 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
3477 per_cvt = get_cvt(spec, cvt_idx);
3478 per_cvt->channels_max = max(per_cvt->channels_max, 8u);
3479 per_cvt->rates |= SUPPORTED_RATES;
3480 per_cvt->formats |= SUPPORTED_FORMATS;
3481 per_cvt->maxbps = max(per_cvt->maxbps, 24u);
3484 spec->chmap.channels_max = max(spec->chmap.channels_max, 8u);
3489 /* VIA HDMI Implementation */
3490 #define VIAHDMI_CVT_NID 0x02 /* audio converter1 */
3491 #define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */
3493 static int patch_via_hdmi(struct hda_codec *codec)
3495 return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
3501 static const struct hda_device_id snd_hda_id_hdmi[] = {
3502 HDA_CODEC_ENTRY(0x1002793c, "RS600 HDMI", patch_atihdmi),
3503 HDA_CODEC_ENTRY(0x10027919, "RS600 HDMI", patch_atihdmi),
3504 HDA_CODEC_ENTRY(0x1002791a, "RS690/780 HDMI", patch_atihdmi),
3505 HDA_CODEC_ENTRY(0x1002aa01, "R6xx HDMI", patch_atihdmi),
3506 HDA_CODEC_ENTRY(0x10951390, "SiI1390 HDMI", patch_generic_hdmi),
3507 HDA_CODEC_ENTRY(0x10951392, "SiI1392 HDMI", patch_generic_hdmi),
3508 HDA_CODEC_ENTRY(0x17e80047, "Chrontel HDMI", patch_generic_hdmi),
3509 HDA_CODEC_ENTRY(0x10de0002, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3510 HDA_CODEC_ENTRY(0x10de0003, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3511 HDA_CODEC_ENTRY(0x10de0005, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3512 HDA_CODEC_ENTRY(0x10de0006, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3513 HDA_CODEC_ENTRY(0x10de0007, "MCP79/7A HDMI", patch_nvhdmi_8ch_7x),
3514 HDA_CODEC_ENTRY(0x10de000a, "GPU 0a HDMI/DP", patch_nvhdmi),
3515 HDA_CODEC_ENTRY(0x10de000b, "GPU 0b HDMI/DP", patch_nvhdmi),
3516 HDA_CODEC_ENTRY(0x10de000c, "MCP89 HDMI", patch_nvhdmi),
3517 HDA_CODEC_ENTRY(0x10de000d, "GPU 0d HDMI/DP", patch_nvhdmi),
3518 HDA_CODEC_ENTRY(0x10de0010, "GPU 10 HDMI/DP", patch_nvhdmi),
3519 HDA_CODEC_ENTRY(0x10de0011, "GPU 11 HDMI/DP", patch_nvhdmi),
3520 HDA_CODEC_ENTRY(0x10de0012, "GPU 12 HDMI/DP", patch_nvhdmi),
3521 HDA_CODEC_ENTRY(0x10de0013, "GPU 13 HDMI/DP", patch_nvhdmi),
3522 HDA_CODEC_ENTRY(0x10de0014, "GPU 14 HDMI/DP", patch_nvhdmi),
3523 HDA_CODEC_ENTRY(0x10de0015, "GPU 15 HDMI/DP", patch_nvhdmi),
3524 HDA_CODEC_ENTRY(0x10de0016, "GPU 16 HDMI/DP", patch_nvhdmi),
3525 /* 17 is known to be absent */
3526 HDA_CODEC_ENTRY(0x10de0018, "GPU 18 HDMI/DP", patch_nvhdmi),
3527 HDA_CODEC_ENTRY(0x10de0019, "GPU 19 HDMI/DP", patch_nvhdmi),
3528 HDA_CODEC_ENTRY(0x10de001a, "GPU 1a HDMI/DP", patch_nvhdmi),
3529 HDA_CODEC_ENTRY(0x10de001b, "GPU 1b HDMI/DP", patch_nvhdmi),
3530 HDA_CODEC_ENTRY(0x10de001c, "GPU 1c HDMI/DP", patch_nvhdmi),
3531 HDA_CODEC_ENTRY(0x10de0020, "Tegra30 HDMI", patch_tegra_hdmi),
3532 HDA_CODEC_ENTRY(0x10de0022, "Tegra114 HDMI", patch_tegra_hdmi),
3533 HDA_CODEC_ENTRY(0x10de0028, "Tegra124 HDMI", patch_tegra_hdmi),
3534 HDA_CODEC_ENTRY(0x10de0029, "Tegra210 HDMI/DP", patch_tegra_hdmi),
3535 HDA_CODEC_ENTRY(0x10de0040, "GPU 40 HDMI/DP", patch_nvhdmi),
3536 HDA_CODEC_ENTRY(0x10de0041, "GPU 41 HDMI/DP", patch_nvhdmi),
3537 HDA_CODEC_ENTRY(0x10de0042, "GPU 42 HDMI/DP", patch_nvhdmi),
3538 HDA_CODEC_ENTRY(0x10de0043, "GPU 43 HDMI/DP", patch_nvhdmi),
3539 HDA_CODEC_ENTRY(0x10de0044, "GPU 44 HDMI/DP", patch_nvhdmi),
3540 HDA_CODEC_ENTRY(0x10de0051, "GPU 51 HDMI/DP", patch_nvhdmi),
3541 HDA_CODEC_ENTRY(0x10de0060, "GPU 60 HDMI/DP", patch_nvhdmi),
3542 HDA_CODEC_ENTRY(0x10de0067, "MCP67 HDMI", patch_nvhdmi_2ch),
3543 HDA_CODEC_ENTRY(0x10de0070, "GPU 70 HDMI/DP", patch_nvhdmi),
3544 HDA_CODEC_ENTRY(0x10de0071, "GPU 71 HDMI/DP", patch_nvhdmi),
3545 HDA_CODEC_ENTRY(0x10de0072, "GPU 72 HDMI/DP", patch_nvhdmi),
3546 HDA_CODEC_ENTRY(0x10de007d, "GPU 7d HDMI/DP", patch_nvhdmi),
3547 HDA_CODEC_ENTRY(0x10de0082, "GPU 82 HDMI/DP", patch_nvhdmi),
3548 HDA_CODEC_ENTRY(0x10de0083, "GPU 83 HDMI/DP", patch_nvhdmi),
3549 HDA_CODEC_ENTRY(0x10de8001, "MCP73 HDMI", patch_nvhdmi_2ch),
3550 HDA_CODEC_ENTRY(0x11069f80, "VX900 HDMI/DP", patch_via_hdmi),
3551 HDA_CODEC_ENTRY(0x11069f81, "VX900 HDMI/DP", patch_via_hdmi),
3552 HDA_CODEC_ENTRY(0x11069f84, "VX11 HDMI/DP", patch_generic_hdmi),
3553 HDA_CODEC_ENTRY(0x11069f85, "VX11 HDMI/DP", patch_generic_hdmi),
3554 HDA_CODEC_ENTRY(0x80860054, "IbexPeak HDMI", patch_generic_hdmi),
3555 HDA_CODEC_ENTRY(0x80862801, "Bearlake HDMI", patch_generic_hdmi),
3556 HDA_CODEC_ENTRY(0x80862802, "Cantiga HDMI", patch_generic_hdmi),
3557 HDA_CODEC_ENTRY(0x80862803, "Eaglelake HDMI", patch_generic_hdmi),
3558 HDA_CODEC_ENTRY(0x80862804, "IbexPeak HDMI", patch_generic_hdmi),
3559 HDA_CODEC_ENTRY(0x80862805, "CougarPoint HDMI", patch_generic_hdmi),
3560 HDA_CODEC_ENTRY(0x80862806, "PantherPoint HDMI", patch_generic_hdmi),
3561 HDA_CODEC_ENTRY(0x80862807, "Haswell HDMI", patch_i915_hsw_hdmi),
3562 HDA_CODEC_ENTRY(0x80862808, "Broadwell HDMI", patch_i915_hsw_hdmi),
3563 HDA_CODEC_ENTRY(0x80862809, "Skylake HDMI", patch_i915_hsw_hdmi),
3564 HDA_CODEC_ENTRY(0x8086280a, "Broxton HDMI", patch_i915_hsw_hdmi),
3565 HDA_CODEC_ENTRY(0x8086280b, "Kabylake HDMI", patch_i915_hsw_hdmi),
3566 HDA_CODEC_ENTRY(0x80862880, "CedarTrail HDMI", patch_generic_hdmi),
3567 HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_i915_byt_hdmi),
3568 HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_i915_byt_hdmi),
3569 HDA_CODEC_ENTRY(0x808629fb, "Crestline HDMI", patch_generic_hdmi),
3570 /* special ID for generic HDMI */
3571 HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC_HDMI, "Generic HDMI", patch_generic_hdmi),
3574 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_hdmi);
3576 MODULE_LICENSE("GPL");
3577 MODULE_DESCRIPTION("HDMI HD-audio codec");
3578 MODULE_ALIAS("snd-hda-codec-intelhdmi");
3579 MODULE_ALIAS("snd-hda-codec-nvhdmi");
3580 MODULE_ALIAS("snd-hda-codec-atihdmi");
3582 static struct hda_codec_driver hdmi_driver = {
3583 .id = snd_hda_id_hdmi,
3586 module_hda_codec_driver(hdmi_driver);