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 <linux/pm_runtime.h>
37 #include <sound/core.h>
38 #include <sound/jack.h>
39 #include <sound/asoundef.h>
40 #include <sound/tlv.h>
41 #include <sound/hdaudio.h>
42 #include <sound/hda_i915.h>
43 #include <sound/hda_chmap.h>
44 #include "hda_codec.h"
45 #include "hda_local.h"
48 static bool static_hdmi_pcm;
49 module_param(static_hdmi_pcm, bool, 0644);
50 MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
52 #define is_haswell(codec) ((codec)->core.vendor_id == 0x80862807)
53 #define is_broadwell(codec) ((codec)->core.vendor_id == 0x80862808)
54 #define is_skylake(codec) ((codec)->core.vendor_id == 0x80862809)
55 #define is_broxton(codec) ((codec)->core.vendor_id == 0x8086280a)
56 #define is_kabylake(codec) ((codec)->core.vendor_id == 0x8086280b)
57 #define is_geminilake(codec) (((codec)->core.vendor_id == 0x8086280d) || \
58 ((codec)->core.vendor_id == 0x80862800))
59 #define is_cannonlake(codec) ((codec)->core.vendor_id == 0x8086280c)
60 #define is_haswell_plus(codec) (is_haswell(codec) || is_broadwell(codec) \
61 || is_skylake(codec) || is_broxton(codec) \
62 || is_kabylake(codec)) || is_geminilake(codec) \
63 || is_cannonlake(codec)
64 #define is_valleyview(codec) ((codec)->core.vendor_id == 0x80862882)
65 #define is_cherryview(codec) ((codec)->core.vendor_id == 0x80862883)
66 #define is_valleyview_plus(codec) (is_valleyview(codec) || is_cherryview(codec))
68 struct hdmi_spec_per_cvt {
71 unsigned int channels_min;
72 unsigned int channels_max;
78 /* max. connections to a widget */
79 #define HDA_MAX_CONNECTIONS 32
81 struct hdmi_spec_per_pin {
84 /* pin idx, different device entries on the same pin use the same idx */
87 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
91 struct hda_codec *codec;
92 struct hdmi_eld sink_eld;
94 struct delayed_work work;
95 struct hdmi_pcm *pcm; /* pointer to spec->pcm_rec[n] dynamically*/
96 int pcm_idx; /* which pcm is attached. -1 means no pcm is attached */
98 bool setup; /* the stream has been set up by prepare callback */
99 int channels; /* current number of channels */
101 bool chmap_set; /* channel-map override by ALSA API? */
102 unsigned char chmap[8]; /* ALSA API channel-map */
103 #ifdef CONFIG_SND_PROC_FS
104 struct snd_info_entry *proc_entry;
108 /* operations used by generic code that can be overridden by patches */
110 int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid,
111 unsigned char *buf, int *eld_size);
113 void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid,
114 int ca, int active_channels, int conn_type);
116 /* enable/disable HBR (HD passthrough) */
117 int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid, bool hbr);
119 int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid,
120 hda_nid_t pin_nid, u32 stream_tag, int format);
122 void (*pin_cvt_fixup)(struct hda_codec *codec,
123 struct hdmi_spec_per_pin *per_pin,
129 struct snd_jack *jack;
130 struct snd_kcontrol *eld_ctl;
135 struct snd_array cvts; /* struct hdmi_spec_per_cvt */
136 hda_nid_t cvt_nids[4]; /* only for haswell fix */
139 * num_pins is the number of virtual pins
140 * for example, there are 3 pins, and each pin
141 * has 4 device entries, then the num_pins is 12
145 * num_nids is the number of real pins
146 * In the above example, num_nids is 3
150 * dev_num is the number of device entries
152 * In the above example, dev_num is 4
155 struct snd_array pins; /* struct hdmi_spec_per_pin */
156 struct hdmi_pcm pcm_rec[16];
157 struct mutex pcm_lock;
158 /* pcm_bitmap means which pcms have been assigned to pins*/
159 unsigned long pcm_bitmap;
160 int pcm_used; /* counter of pcm_rec[] */
161 /* bitmap shows whether the pcm is opened in user space
162 * bit 0 means the first playback PCM (PCM3);
163 * bit 1 means the second playback PCM, and so on.
165 unsigned long pcm_in_use;
167 struct hdmi_eld temp_eld;
173 * Non-generic VIA/NVIDIA specific
175 struct hda_multi_out multiout;
176 struct hda_pcm_stream pcm_playback;
178 /* i915/powerwell (Haswell+/Valleyview+) specific */
179 bool use_acomp_notifier; /* use i915 eld_notify callback for hotplug */
180 struct drm_audio_component_audio_ops drm_audio_ops;
182 struct hdac_chmap chmap;
183 hda_nid_t vendor_nid;
186 #ifdef CONFIG_SND_HDA_COMPONENT
187 static inline bool codec_has_acomp(struct hda_codec *codec)
189 struct hdmi_spec *spec = codec->spec;
190 return spec->use_acomp_notifier;
193 #define codec_has_acomp(codec) false
196 struct hdmi_audio_infoframe {
203 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
207 u8 LFEPBL01_LSV36_DM_INH7;
210 struct dp_audio_infoframe {
213 u8 ver; /* 0x11 << 2 */
215 u8 CC02_CT47; /* match with HDMI infoframe from this on */
219 u8 LFEPBL01_LSV36_DM_INH7;
222 union audio_infoframe {
223 struct hdmi_audio_infoframe hdmi;
224 struct dp_audio_infoframe dp;
232 #define get_pin(spec, idx) \
233 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx))
234 #define get_cvt(spec, idx) \
235 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx))
236 /* obtain hdmi_pcm object assigned to idx */
237 #define get_hdmi_pcm(spec, idx) (&(spec)->pcm_rec[idx])
238 /* obtain hda_pcm object assigned to idx */
239 #define get_pcm_rec(spec, idx) (get_hdmi_pcm(spec, idx)->pcm)
241 static int pin_id_to_pin_index(struct hda_codec *codec,
242 hda_nid_t pin_nid, int dev_id)
244 struct hdmi_spec *spec = codec->spec;
246 struct hdmi_spec_per_pin *per_pin;
249 * (dev_id == -1) means it is NON-MST pin
250 * return the first virtual pin on this port
255 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
256 per_pin = get_pin(spec, pin_idx);
257 if ((per_pin->pin_nid == pin_nid) &&
258 (per_pin->dev_id == dev_id))
262 codec_warn(codec, "HDMI: pin nid %d not registered\n", pin_nid);
266 static int hinfo_to_pcm_index(struct hda_codec *codec,
267 struct hda_pcm_stream *hinfo)
269 struct hdmi_spec *spec = codec->spec;
272 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++)
273 if (get_pcm_rec(spec, pcm_idx)->stream == hinfo)
276 codec_warn(codec, "HDMI: hinfo %p not registered\n", hinfo);
280 static int hinfo_to_pin_index(struct hda_codec *codec,
281 struct hda_pcm_stream *hinfo)
283 struct hdmi_spec *spec = codec->spec;
284 struct hdmi_spec_per_pin *per_pin;
287 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
288 per_pin = get_pin(spec, pin_idx);
290 per_pin->pcm->pcm->stream == hinfo)
294 codec_dbg(codec, "HDMI: hinfo %p not registered\n", hinfo);
298 static struct hdmi_spec_per_pin *pcm_idx_to_pin(struct hdmi_spec *spec,
302 struct hdmi_spec_per_pin *per_pin;
304 for (i = 0; i < spec->num_pins; i++) {
305 per_pin = get_pin(spec, i);
306 if (per_pin->pcm_idx == pcm_idx)
312 static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid)
314 struct hdmi_spec *spec = codec->spec;
317 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
318 if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid)
321 codec_warn(codec, "HDMI: cvt nid %d not registered\n", cvt_nid);
325 static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
326 struct snd_ctl_elem_info *uinfo)
328 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
329 struct hdmi_spec *spec = codec->spec;
330 struct hdmi_spec_per_pin *per_pin;
331 struct hdmi_eld *eld;
334 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
336 pcm_idx = kcontrol->private_value;
337 mutex_lock(&spec->pcm_lock);
338 per_pin = pcm_idx_to_pin(spec, pcm_idx);
340 /* no pin is bound to the pcm */
344 eld = &per_pin->sink_eld;
345 uinfo->count = eld->eld_valid ? eld->eld_size : 0;
348 mutex_unlock(&spec->pcm_lock);
352 static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
353 struct snd_ctl_elem_value *ucontrol)
355 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
356 struct hdmi_spec *spec = codec->spec;
357 struct hdmi_spec_per_pin *per_pin;
358 struct hdmi_eld *eld;
362 pcm_idx = kcontrol->private_value;
363 mutex_lock(&spec->pcm_lock);
364 per_pin = pcm_idx_to_pin(spec, pcm_idx);
366 /* no pin is bound to the pcm */
367 memset(ucontrol->value.bytes.data, 0,
368 ARRAY_SIZE(ucontrol->value.bytes.data));
372 eld = &per_pin->sink_eld;
373 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data) ||
374 eld->eld_size > ELD_MAX_SIZE) {
380 memset(ucontrol->value.bytes.data, 0,
381 ARRAY_SIZE(ucontrol->value.bytes.data));
383 memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
387 mutex_unlock(&spec->pcm_lock);
391 static const struct snd_kcontrol_new eld_bytes_ctl = {
392 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
393 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
395 .info = hdmi_eld_ctl_info,
396 .get = hdmi_eld_ctl_get,
399 static int hdmi_create_eld_ctl(struct hda_codec *codec, int pcm_idx,
402 struct snd_kcontrol *kctl;
403 struct hdmi_spec *spec = codec->spec;
406 kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
409 kctl->private_value = pcm_idx;
410 kctl->id.device = device;
412 /* no pin nid is associated with the kctl now
413 * tbd: associate pin nid to eld ctl later
415 err = snd_hda_ctl_add(codec, 0, kctl);
419 get_hdmi_pcm(spec, pcm_idx)->eld_ctl = kctl;
424 static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
425 int *packet_index, int *byte_index)
429 val = snd_hda_codec_read(codec, pin_nid, 0,
430 AC_VERB_GET_HDMI_DIP_INDEX, 0);
432 *packet_index = val >> 5;
433 *byte_index = val & 0x1f;
437 static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
438 int packet_index, int byte_index)
442 val = (packet_index << 5) | (byte_index & 0x1f);
444 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
447 static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
450 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
453 static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
455 struct hdmi_spec *spec = codec->spec;
459 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
460 snd_hda_codec_write(codec, pin_nid, 0,
461 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
463 if (spec->dyn_pin_out)
464 /* Disable pin out until stream is active */
467 /* Enable pin out: some machines with GM965 gets broken output
468 * when the pin is disabled or changed while using with HDMI
472 snd_hda_codec_write(codec, pin_nid, 0,
473 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_out);
480 #ifdef CONFIG_SND_PROC_FS
481 static void print_eld_info(struct snd_info_entry *entry,
482 struct snd_info_buffer *buffer)
484 struct hdmi_spec_per_pin *per_pin = entry->private_data;
486 mutex_lock(&per_pin->lock);
487 snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer);
488 mutex_unlock(&per_pin->lock);
491 static void write_eld_info(struct snd_info_entry *entry,
492 struct snd_info_buffer *buffer)
494 struct hdmi_spec_per_pin *per_pin = entry->private_data;
496 mutex_lock(&per_pin->lock);
497 snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer);
498 mutex_unlock(&per_pin->lock);
501 static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
504 struct hda_codec *codec = per_pin->codec;
505 struct snd_info_entry *entry;
508 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
509 err = snd_card_proc_new(codec->card, name, &entry);
513 snd_info_set_text_ops(entry, per_pin, print_eld_info);
514 entry->c.text.write = write_eld_info;
516 per_pin->proc_entry = entry;
521 static void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
523 if (!per_pin->codec->bus->shutdown) {
524 snd_info_free_entry(per_pin->proc_entry);
525 per_pin->proc_entry = NULL;
529 static inline int eld_proc_new(struct hdmi_spec_per_pin *per_pin,
534 static inline void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
540 * Audio InfoFrame routines
544 * Enable Audio InfoFrame Transmission
546 static void hdmi_start_infoframe_trans(struct hda_codec *codec,
549 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
550 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
555 * Disable Audio InfoFrame Transmission
557 static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
560 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
561 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
565 static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
567 #ifdef CONFIG_SND_DEBUG_VERBOSE
571 size = snd_hdmi_get_eld_size(codec, pin_nid);
572 codec_dbg(codec, "HDMI: ELD buf size is %d\n", size);
574 for (i = 0; i < 8; i++) {
575 size = snd_hda_codec_read(codec, pin_nid, 0,
576 AC_VERB_GET_HDMI_DIP_SIZE, i);
577 codec_dbg(codec, "HDMI: DIP GP[%d] buf size is %d\n", i, size);
582 static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
588 for (i = 0; i < 8; i++) {
589 size = snd_hda_codec_read(codec, pin_nid, 0,
590 AC_VERB_GET_HDMI_DIP_SIZE, i);
594 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
595 for (j = 1; j < 1000; j++) {
596 hdmi_write_dip_byte(codec, pin_nid, 0x0);
597 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
599 codec_dbg(codec, "dip index %d: %d != %d\n",
601 if (bi == 0) /* byte index wrapped around */
605 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
611 static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
613 u8 *bytes = (u8 *)hdmi_ai;
617 hdmi_ai->checksum = 0;
619 for (i = 0; i < sizeof(*hdmi_ai); i++)
622 hdmi_ai->checksum = -sum;
625 static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
631 hdmi_debug_dip_size(codec, pin_nid);
632 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
634 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
635 for (i = 0; i < size; i++)
636 hdmi_write_dip_byte(codec, pin_nid, dip[i]);
639 static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
645 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
649 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
650 for (i = 0; i < size; i++) {
651 val = snd_hda_codec_read(codec, pin_nid, 0,
652 AC_VERB_GET_HDMI_DIP_DATA, 0);
660 static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
662 int ca, int active_channels,
665 union audio_infoframe ai;
667 memset(&ai, 0, sizeof(ai));
668 if (conn_type == 0) { /* HDMI */
669 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
671 hdmi_ai->type = 0x84;
674 hdmi_ai->CC02_CT47 = active_channels - 1;
676 hdmi_checksum_audio_infoframe(hdmi_ai);
677 } else if (conn_type == 1) { /* DisplayPort */
678 struct dp_audio_infoframe *dp_ai = &ai.dp;
682 dp_ai->ver = 0x11 << 2;
683 dp_ai->CC02_CT47 = active_channels - 1;
686 codec_dbg(codec, "HDMI: unknown connection type at pin %d\n",
692 * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
693 * sizeof(*dp_ai) to avoid partial match/update problems when
694 * the user switches between HDMI/DP monitors.
696 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
699 "hdmi_pin_setup_infoframe: pin=%d channels=%d ca=0x%02x\n",
701 active_channels, ca);
702 hdmi_stop_infoframe_trans(codec, pin_nid);
703 hdmi_fill_audio_infoframe(codec, pin_nid,
704 ai.bytes, sizeof(ai));
705 hdmi_start_infoframe_trans(codec, pin_nid);
709 static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
710 struct hdmi_spec_per_pin *per_pin,
713 struct hdmi_spec *spec = codec->spec;
714 struct hdac_chmap *chmap = &spec->chmap;
715 hda_nid_t pin_nid = per_pin->pin_nid;
716 int channels = per_pin->channels;
718 struct hdmi_eld *eld;
724 /* some HW (e.g. HSW+) needs reprogramming the amp at each time */
725 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
726 snd_hda_codec_write(codec, pin_nid, 0,
727 AC_VERB_SET_AMP_GAIN_MUTE,
730 eld = &per_pin->sink_eld;
732 ca = snd_hdac_channel_allocation(&codec->core,
733 eld->info.spk_alloc, channels,
734 per_pin->chmap_set, non_pcm, per_pin->chmap);
736 active_channels = snd_hdac_get_active_channels(ca);
738 chmap->ops.set_channel_count(&codec->core, per_pin->cvt_nid,
742 * always configure channel mapping, it may have been changed by the
743 * user in the meantime
745 snd_hdac_setup_channel_mapping(&spec->chmap,
746 pin_nid, non_pcm, ca, channels,
747 per_pin->chmap, per_pin->chmap_set);
749 spec->ops.pin_setup_infoframe(codec, pin_nid, ca, active_channels,
750 eld->info.conn_type);
752 per_pin->non_pcm = non_pcm;
759 static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
761 static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid,
764 struct hdmi_spec *spec = codec->spec;
765 int pin_idx = pin_id_to_pin_index(codec, nid, dev_id);
769 mutex_lock(&spec->pcm_lock);
770 if (hdmi_present_sense(get_pin(spec, pin_idx), 1))
771 snd_hda_jack_report_sync(codec);
772 mutex_unlock(&spec->pcm_lock);
775 static void jack_callback(struct hda_codec *codec,
776 struct hda_jack_callback *jack)
778 /* hda_jack don't support DP MST */
779 check_presence_and_report(codec, jack->nid, 0);
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;
786 int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
789 * assume DP MST uses dyn_pcm_assign and acomp and
791 * if DP MST supports unsol event, below code need
794 jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
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, dev_entry, !!(res & AC_UNSOL_RES_IA),
802 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
804 /* hda_jack don't support DP MST */
805 check_presence_and_report(codec, jack->nid, 0);
808 static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
810 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
811 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
812 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
813 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
816 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
831 static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
833 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
834 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
836 if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) {
837 codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag);
842 hdmi_intrinsic_event(codec, res);
844 hdmi_non_intrinsic_event(codec, res);
847 static void haswell_verify_D0(struct hda_codec *codec,
848 hda_nid_t cvt_nid, hda_nid_t nid)
852 /* For Haswell, the converter 1/2 may keep in D3 state after bootup,
853 * thus pins could only choose converter 0 for use. Make sure the
854 * converters are in correct power state */
855 if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0))
856 snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
858 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) {
859 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
862 pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
863 pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
864 codec_dbg(codec, "Haswell HDMI audio: Power for pin 0x%x is now D%d\n", nid, pwr);
872 /* HBR should be Non-PCM, 8 channels */
873 #define is_hbr_format(format) \
874 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
876 static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
879 int pinctl, new_pinctl;
881 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
882 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
883 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
886 return hbr ? -EINVAL : 0;
888 new_pinctl = pinctl & ~AC_PINCTL_EPT;
890 new_pinctl |= AC_PINCTL_EPT_HBR;
892 new_pinctl |= AC_PINCTL_EPT_NATIVE;
895 "hdmi_pin_hbr_setup: NID=0x%x, %spinctl=0x%x\n",
897 pinctl == new_pinctl ? "" : "new-",
900 if (pinctl != new_pinctl)
901 snd_hda_codec_write(codec, pin_nid, 0,
902 AC_VERB_SET_PIN_WIDGET_CONTROL,
910 static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
911 hda_nid_t pin_nid, u32 stream_tag, int format)
913 struct hdmi_spec *spec = codec->spec;
917 err = spec->ops.pin_hbr_setup(codec, pin_nid, is_hbr_format(format));
920 codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n");
924 if (is_haswell_plus(codec)) {
927 * on recent platforms IEC Coding Type is required for HBR
928 * support, read current Digital Converter settings and set
929 * ICT bitfield if needed.
931 param = snd_hda_codec_read(codec, cvt_nid, 0,
932 AC_VERB_GET_DIGI_CONVERT_1, 0);
934 param = (param >> 16) & ~(AC_DIG3_ICT);
936 /* on recent platforms ICT mode is required for HBR support */
937 if (is_hbr_format(format))
940 snd_hda_codec_write(codec, cvt_nid, 0,
941 AC_VERB_SET_DIGI_CONVERT_3, param);
944 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
948 /* Try to find an available converter
949 * If pin_idx is less then zero, just try to find an available converter.
950 * Otherwise, try to find an available converter and get the cvt mux index
953 static int hdmi_choose_cvt(struct hda_codec *codec,
954 int pin_idx, int *cvt_id)
956 struct hdmi_spec *spec = codec->spec;
957 struct hdmi_spec_per_pin *per_pin;
958 struct hdmi_spec_per_cvt *per_cvt = NULL;
959 int cvt_idx, mux_idx = 0;
961 /* pin_idx < 0 means no pin will be bound to the converter */
965 per_pin = get_pin(spec, pin_idx);
967 /* Dynamically assign converter to stream */
968 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
969 per_cvt = get_cvt(spec, cvt_idx);
971 /* Must not already be assigned */
972 if (per_cvt->assigned)
976 /* Must be in pin's mux's list of converters */
977 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
978 if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid)
980 /* Not in mux list */
981 if (mux_idx == per_pin->num_mux_nids)
986 /* No free converters */
987 if (cvt_idx == spec->num_cvts)
991 per_pin->mux_idx = mux_idx;
999 /* Assure the pin select the right convetor */
1000 static void intel_verify_pin_cvt_connect(struct hda_codec *codec,
1001 struct hdmi_spec_per_pin *per_pin)
1003 hda_nid_t pin_nid = per_pin->pin_nid;
1006 mux_idx = per_pin->mux_idx;
1007 curr = snd_hda_codec_read(codec, pin_nid, 0,
1008 AC_VERB_GET_CONNECT_SEL, 0);
1009 if (curr != mux_idx)
1010 snd_hda_codec_write_cache(codec, pin_nid, 0,
1011 AC_VERB_SET_CONNECT_SEL,
1015 /* get the mux index for the converter of the pins
1016 * converter's mux index is the same for all pins on Intel platform
1018 static int intel_cvt_id_to_mux_idx(struct hdmi_spec *spec,
1023 for (i = 0; i < spec->num_cvts; i++)
1024 if (spec->cvt_nids[i] == cvt_nid)
1029 /* Intel HDMI workaround to fix audio routing issue:
1030 * For some Intel display codecs, pins share the same connection list.
1031 * So a conveter can be selected by multiple pins and playback on any of these
1032 * pins will generate sound on the external display, because audio flows from
1033 * the same converter to the display pipeline. Also muting one pin may make
1034 * other pins have no sound output.
1035 * So this function assures that an assigned converter for a pin is not selected
1036 * by any other pins.
1038 static void intel_not_share_assigned_cvt(struct hda_codec *codec,
1040 int dev_id, int mux_idx)
1042 struct hdmi_spec *spec = codec->spec;
1045 struct hdmi_spec_per_cvt *per_cvt;
1046 struct hdmi_spec_per_pin *per_pin;
1049 /* configure the pins connections */
1050 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1054 per_pin = get_pin(spec, pin_idx);
1056 * pin not connected to monitor
1057 * no need to operate on it
1062 if ((per_pin->pin_nid == pin_nid) &&
1063 (per_pin->dev_id == dev_id))
1067 * if per_pin->dev_id >= dev_num,
1068 * snd_hda_get_dev_select() will fail,
1069 * and the following operation is unpredictable.
1070 * So skip this situation.
1072 dev_num = snd_hda_get_num_devices(codec, per_pin->pin_nid) + 1;
1073 if (per_pin->dev_id >= dev_num)
1076 nid = per_pin->pin_nid;
1079 * Calling this function should not impact
1080 * on the device entry selection
1081 * So let's save the dev id for each pin,
1082 * and restore it when return
1084 dev_id_saved = snd_hda_get_dev_select(codec, nid);
1085 snd_hda_set_dev_select(codec, nid, per_pin->dev_id);
1086 curr = snd_hda_codec_read(codec, nid, 0,
1087 AC_VERB_GET_CONNECT_SEL, 0);
1088 if (curr != mux_idx) {
1089 snd_hda_set_dev_select(codec, nid, dev_id_saved);
1094 /* choose an unassigned converter. The conveters in the
1095 * connection list are in the same order as in the codec.
1097 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
1098 per_cvt = get_cvt(spec, cvt_idx);
1099 if (!per_cvt->assigned) {
1101 "choose cvt %d for pin nid %d\n",
1103 snd_hda_codec_write_cache(codec, nid, 0,
1104 AC_VERB_SET_CONNECT_SEL,
1109 snd_hda_set_dev_select(codec, nid, dev_id_saved);
1113 /* A wrapper of intel_not_share_asigned_cvt() */
1114 static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,
1115 hda_nid_t pin_nid, int dev_id, hda_nid_t cvt_nid)
1118 struct hdmi_spec *spec = codec->spec;
1120 /* On Intel platform, the mapping of converter nid to
1121 * mux index of the pins are always the same.
1122 * The pin nid may be 0, this means all pins will not
1123 * share the converter.
1125 mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid);
1127 intel_not_share_assigned_cvt(codec, pin_nid, dev_id, mux_idx);
1130 /* skeleton caller of pin_cvt_fixup ops */
1131 static void pin_cvt_fixup(struct hda_codec *codec,
1132 struct hdmi_spec_per_pin *per_pin,
1135 struct hdmi_spec *spec = codec->spec;
1137 if (spec->ops.pin_cvt_fixup)
1138 spec->ops.pin_cvt_fixup(codec, per_pin, cvt_nid);
1141 /* called in hdmi_pcm_open when no pin is assigned to the PCM
1142 * in dyn_pcm_assign mode.
1144 static int hdmi_pcm_open_no_pin(struct hda_pcm_stream *hinfo,
1145 struct hda_codec *codec,
1146 struct snd_pcm_substream *substream)
1148 struct hdmi_spec *spec = codec->spec;
1149 struct snd_pcm_runtime *runtime = substream->runtime;
1150 int cvt_idx, pcm_idx;
1151 struct hdmi_spec_per_cvt *per_cvt = NULL;
1154 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1158 err = hdmi_choose_cvt(codec, -1, &cvt_idx);
1162 per_cvt = get_cvt(spec, cvt_idx);
1163 per_cvt->assigned = 1;
1164 hinfo->nid = per_cvt->cvt_nid;
1166 pin_cvt_fixup(codec, NULL, per_cvt->cvt_nid);
1168 set_bit(pcm_idx, &spec->pcm_in_use);
1169 /* todo: setup spdif ctls assign */
1171 /* Initially set the converter's capabilities */
1172 hinfo->channels_min = per_cvt->channels_min;
1173 hinfo->channels_max = per_cvt->channels_max;
1174 hinfo->rates = per_cvt->rates;
1175 hinfo->formats = per_cvt->formats;
1176 hinfo->maxbps = per_cvt->maxbps;
1178 /* Store the updated parameters */
1179 runtime->hw.channels_min = hinfo->channels_min;
1180 runtime->hw.channels_max = hinfo->channels_max;
1181 runtime->hw.formats = hinfo->formats;
1182 runtime->hw.rates = hinfo->rates;
1184 snd_pcm_hw_constraint_step(substream->runtime, 0,
1185 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
1192 static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1193 struct hda_codec *codec,
1194 struct snd_pcm_substream *substream)
1196 struct hdmi_spec *spec = codec->spec;
1197 struct snd_pcm_runtime *runtime = substream->runtime;
1198 int pin_idx, cvt_idx, pcm_idx;
1199 struct hdmi_spec_per_pin *per_pin;
1200 struct hdmi_eld *eld;
1201 struct hdmi_spec_per_cvt *per_cvt = NULL;
1204 /* Validate hinfo */
1205 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1209 mutex_lock(&spec->pcm_lock);
1210 pin_idx = hinfo_to_pin_index(codec, hinfo);
1211 if (!spec->dyn_pcm_assign) {
1212 if (snd_BUG_ON(pin_idx < 0)) {
1217 /* no pin is assigned to the PCM
1218 * PA need pcm open successfully when probe
1221 err = hdmi_pcm_open_no_pin(hinfo, codec, substream);
1226 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx);
1230 per_cvt = get_cvt(spec, cvt_idx);
1231 /* Claim converter */
1232 per_cvt->assigned = 1;
1234 set_bit(pcm_idx, &spec->pcm_in_use);
1235 per_pin = get_pin(spec, pin_idx);
1236 per_pin->cvt_nid = per_cvt->cvt_nid;
1237 hinfo->nid = per_cvt->cvt_nid;
1239 snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id);
1240 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1241 AC_VERB_SET_CONNECT_SEL,
1244 /* configure unused pins to choose other converters */
1245 pin_cvt_fixup(codec, per_pin, 0);
1247 snd_hda_spdif_ctls_assign(codec, pcm_idx, per_cvt->cvt_nid);
1249 /* Initially set the converter's capabilities */
1250 hinfo->channels_min = per_cvt->channels_min;
1251 hinfo->channels_max = per_cvt->channels_max;
1252 hinfo->rates = per_cvt->rates;
1253 hinfo->formats = per_cvt->formats;
1254 hinfo->maxbps = per_cvt->maxbps;
1256 eld = &per_pin->sink_eld;
1257 /* Restrict capabilities by ELD if this isn't disabled */
1258 if (!static_hdmi_pcm && eld->eld_valid) {
1259 snd_hdmi_eld_update_pcm_info(&eld->info, hinfo);
1260 if (hinfo->channels_min > hinfo->channels_max ||
1261 !hinfo->rates || !hinfo->formats) {
1262 per_cvt->assigned = 0;
1264 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
1270 /* Store the updated parameters */
1271 runtime->hw.channels_min = hinfo->channels_min;
1272 runtime->hw.channels_max = hinfo->channels_max;
1273 runtime->hw.formats = hinfo->formats;
1274 runtime->hw.rates = hinfo->rates;
1276 snd_pcm_hw_constraint_step(substream->runtime, 0,
1277 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
1279 mutex_unlock(&spec->pcm_lock);
1284 * HDA/HDMI auto parsing
1286 static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
1288 struct hdmi_spec *spec = codec->spec;
1289 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1290 hda_nid_t pin_nid = per_pin->pin_nid;
1292 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
1294 "HDMI: pin %d wcaps %#x does not support connection list\n",
1295 pin_nid, get_wcaps(codec, pin_nid));
1299 /* all the device entries on the same pin have the same conn list */
1300 per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,
1302 HDA_MAX_CONNECTIONS);
1307 static int hdmi_find_pcm_slot(struct hdmi_spec *spec,
1308 struct hdmi_spec_per_pin *per_pin)
1312 /* try the prefer PCM */
1313 if (!test_bit(per_pin->pin_nid_idx, &spec->pcm_bitmap))
1314 return per_pin->pin_nid_idx;
1316 /* have a second try; check the "reserved area" over num_pins */
1317 for (i = spec->num_nids; i < spec->pcm_used; i++) {
1318 if (!test_bit(i, &spec->pcm_bitmap))
1322 /* the last try; check the empty slots in pins */
1323 for (i = 0; i < spec->num_nids; i++) {
1324 if (!test_bit(i, &spec->pcm_bitmap))
1330 static void hdmi_attach_hda_pcm(struct hdmi_spec *spec,
1331 struct hdmi_spec_per_pin *per_pin)
1335 /* pcm already be attached to the pin */
1338 idx = hdmi_find_pcm_slot(spec, per_pin);
1341 per_pin->pcm_idx = idx;
1342 per_pin->pcm = get_hdmi_pcm(spec, idx);
1343 set_bit(idx, &spec->pcm_bitmap);
1346 static void hdmi_detach_hda_pcm(struct hdmi_spec *spec,
1347 struct hdmi_spec_per_pin *per_pin)
1351 /* pcm already be detached from the pin */
1354 idx = per_pin->pcm_idx;
1355 per_pin->pcm_idx = -1;
1356 per_pin->pcm = NULL;
1357 if (idx >= 0 && idx < spec->pcm_used)
1358 clear_bit(idx, &spec->pcm_bitmap);
1361 static int hdmi_get_pin_cvt_mux(struct hdmi_spec *spec,
1362 struct hdmi_spec_per_pin *per_pin, hda_nid_t cvt_nid)
1366 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
1367 if (per_pin->mux_nids[mux_idx] == cvt_nid)
1372 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid);
1374 static void hdmi_pcm_setup_pin(struct hdmi_spec *spec,
1375 struct hdmi_spec_per_pin *per_pin)
1377 struct hda_codec *codec = per_pin->codec;
1378 struct hda_pcm *pcm;
1379 struct hda_pcm_stream *hinfo;
1380 struct snd_pcm_substream *substream;
1384 if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
1385 pcm = get_pcm_rec(spec, per_pin->pcm_idx);
1390 if (!test_bit(per_pin->pcm_idx, &spec->pcm_in_use))
1393 /* hdmi audio only uses playback and one substream */
1394 hinfo = pcm->stream;
1395 substream = pcm->pcm->streams[0].substream;
1397 per_pin->cvt_nid = hinfo->nid;
1399 mux_idx = hdmi_get_pin_cvt_mux(spec, per_pin, hinfo->nid);
1400 if (mux_idx < per_pin->num_mux_nids) {
1401 snd_hda_set_dev_select(codec, per_pin->pin_nid,
1403 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1404 AC_VERB_SET_CONNECT_SEL,
1407 snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid);
1409 non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid);
1410 if (substream->runtime)
1411 per_pin->channels = substream->runtime->channels;
1412 per_pin->setup = true;
1413 per_pin->mux_idx = mux_idx;
1415 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
1418 static void hdmi_pcm_reset_pin(struct hdmi_spec *spec,
1419 struct hdmi_spec_per_pin *per_pin)
1421 if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
1422 snd_hda_spdif_ctls_unassign(per_pin->codec, per_pin->pcm_idx);
1424 per_pin->chmap_set = false;
1425 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
1427 per_pin->setup = false;
1428 per_pin->channels = 0;
1431 /* update per_pin ELD from the given new ELD;
1432 * setup info frame and notification accordingly
1434 static void update_eld(struct hda_codec *codec,
1435 struct hdmi_spec_per_pin *per_pin,
1436 struct hdmi_eld *eld)
1438 struct hdmi_eld *pin_eld = &per_pin->sink_eld;
1439 struct hdmi_spec *spec = codec->spec;
1440 bool old_eld_valid = pin_eld->eld_valid;
1444 /* for monitor disconnection, save pcm_idx firstly */
1445 pcm_idx = per_pin->pcm_idx;
1446 if (spec->dyn_pcm_assign) {
1447 if (eld->eld_valid) {
1448 hdmi_attach_hda_pcm(spec, per_pin);
1449 hdmi_pcm_setup_pin(spec, per_pin);
1451 hdmi_pcm_reset_pin(spec, per_pin);
1452 hdmi_detach_hda_pcm(spec, per_pin);
1455 /* if pcm_idx == -1, it means this is in monitor connection event
1456 * we can get the correct pcm_idx now.
1459 pcm_idx = per_pin->pcm_idx;
1462 snd_hdmi_show_eld(codec, &eld->info);
1464 eld_changed = (pin_eld->eld_valid != eld->eld_valid);
1465 if (eld->eld_valid && pin_eld->eld_valid)
1466 if (pin_eld->eld_size != eld->eld_size ||
1467 memcmp(pin_eld->eld_buffer, eld->eld_buffer,
1468 eld->eld_size) != 0)
1471 pin_eld->monitor_present = eld->monitor_present;
1472 pin_eld->eld_valid = eld->eld_valid;
1473 pin_eld->eld_size = eld->eld_size;
1475 memcpy(pin_eld->eld_buffer, eld->eld_buffer, eld->eld_size);
1476 pin_eld->info = eld->info;
1479 * Re-setup pin and infoframe. This is needed e.g. when
1480 * - sink is first plugged-in
1481 * - transcoder can change during stream playback on Haswell
1482 * and this can make HW reset converter selection on a pin.
1484 if (eld->eld_valid && !old_eld_valid && per_pin->setup) {
1485 pin_cvt_fixup(codec, per_pin, 0);
1486 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1489 if (eld_changed && pcm_idx >= 0)
1490 snd_ctl_notify(codec->card,
1491 SNDRV_CTL_EVENT_MASK_VALUE |
1492 SNDRV_CTL_EVENT_MASK_INFO,
1493 &get_hdmi_pcm(spec, pcm_idx)->eld_ctl->id);
1496 /* update ELD and jack state via HD-audio verbs */
1497 static bool hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin,
1500 struct hda_jack_tbl *jack;
1501 struct hda_codec *codec = per_pin->codec;
1502 struct hdmi_spec *spec = codec->spec;
1503 struct hdmi_eld *eld = &spec->temp_eld;
1504 hda_nid_t pin_nid = per_pin->pin_nid;
1506 * Always execute a GetPinSense verb here, even when called from
1507 * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
1508 * response's PD bit is not the real PD value, but indicates that
1509 * the real PD value changed. An older version of the HD-audio
1510 * specification worked this way. Hence, we just ignore the data in
1511 * the unsolicited response to avoid custom WARs.
1515 bool do_repoll = false;
1517 present = snd_hda_pin_sense(codec, pin_nid);
1519 mutex_lock(&per_pin->lock);
1520 eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
1521 if (eld->monitor_present)
1522 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
1524 eld->eld_valid = false;
1527 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
1528 codec->addr, pin_nid, eld->monitor_present, eld->eld_valid);
1530 if (eld->eld_valid) {
1531 if (spec->ops.pin_get_eld(codec, pin_nid, eld->eld_buffer,
1532 &eld->eld_size) < 0)
1533 eld->eld_valid = false;
1535 if (snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer,
1537 eld->eld_valid = false;
1539 if (!eld->eld_valid && repoll)
1544 schedule_delayed_work(&per_pin->work, msecs_to_jiffies(300));
1546 update_eld(codec, per_pin, eld);
1548 ret = !repoll || !eld->monitor_present || eld->eld_valid;
1550 jack = snd_hda_jack_tbl_get(codec, pin_nid);
1552 jack->block_report = !ret;
1554 mutex_unlock(&per_pin->lock);
1558 static struct snd_jack *pin_idx_to_jack(struct hda_codec *codec,
1559 struct hdmi_spec_per_pin *per_pin)
1561 struct hdmi_spec *spec = codec->spec;
1562 struct snd_jack *jack = NULL;
1563 struct hda_jack_tbl *jack_tbl;
1565 /* if !dyn_pcm_assign, get jack from hda_jack_tbl
1566 * in !dyn_pcm_assign case, spec->pcm_rec[].jack is not
1567 * NULL even after snd_hda_jack_tbl_clear() is called to
1568 * free snd_jack. This may cause access invalid memory
1569 * when calling snd_jack_report
1571 if (per_pin->pcm_idx >= 0 && spec->dyn_pcm_assign)
1572 jack = spec->pcm_rec[per_pin->pcm_idx].jack;
1573 else if (!spec->dyn_pcm_assign) {
1575 * jack tbl doesn't support DP MST
1576 * DP MST will use dyn_pcm_assign,
1577 * so DP MST will never come here
1579 jack_tbl = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
1581 jack = jack_tbl->jack;
1586 /* update ELD and jack state via audio component */
1587 static void sync_eld_via_acomp(struct hda_codec *codec,
1588 struct hdmi_spec_per_pin *per_pin)
1590 struct hdmi_spec *spec = codec->spec;
1591 struct hdmi_eld *eld = &spec->temp_eld;
1592 struct snd_jack *jack = NULL;
1595 mutex_lock(&per_pin->lock);
1596 eld->monitor_present = false;
1597 size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid,
1598 per_pin->dev_id, &eld->monitor_present,
1599 eld->eld_buffer, ELD_MAX_SIZE);
1601 size = min(size, ELD_MAX_SIZE);
1602 if (snd_hdmi_parse_eld(codec, &eld->info,
1603 eld->eld_buffer, size) < 0)
1608 eld->eld_valid = true;
1609 eld->eld_size = size;
1611 eld->eld_valid = false;
1615 /* pcm_idx >=0 before update_eld() means it is in monitor
1616 * disconnected event. Jack must be fetched before update_eld()
1618 jack = pin_idx_to_jack(codec, per_pin);
1619 update_eld(codec, per_pin, eld);
1621 jack = pin_idx_to_jack(codec, per_pin);
1624 snd_jack_report(jack,
1625 eld->monitor_present ? SND_JACK_AVOUT : 0);
1627 mutex_unlock(&per_pin->lock);
1630 static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1632 struct hda_codec *codec = per_pin->codec;
1635 /* no temporary power up/down needed for component notifier */
1636 if (!codec_has_acomp(codec)) {
1637 ret = snd_hda_power_up_pm(codec);
1638 if (ret < 0 && pm_runtime_suspended(hda_codec_dev(codec))) {
1639 snd_hda_power_down_pm(codec);
1644 if (codec_has_acomp(codec)) {
1645 sync_eld_via_acomp(codec, per_pin);
1646 ret = false; /* don't call snd_hda_jack_report_sync() */
1648 ret = hdmi_present_sense_via_verbs(per_pin, repoll);
1651 if (!codec_has_acomp(codec))
1652 snd_hda_power_down_pm(codec);
1657 static void hdmi_repoll_eld(struct work_struct *work)
1659 struct hdmi_spec_per_pin *per_pin =
1660 container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
1661 struct hda_codec *codec = per_pin->codec;
1662 struct hdmi_spec *spec = codec->spec;
1663 struct hda_jack_tbl *jack;
1665 jack = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
1667 jack->jack_dirty = 1;
1669 if (per_pin->repoll_count++ > 6)
1670 per_pin->repoll_count = 0;
1672 mutex_lock(&spec->pcm_lock);
1673 if (hdmi_present_sense(per_pin, per_pin->repoll_count))
1674 snd_hda_jack_report_sync(per_pin->codec);
1675 mutex_unlock(&spec->pcm_lock);
1678 static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
1681 static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1683 struct hdmi_spec *spec = codec->spec;
1684 unsigned int caps, config;
1686 struct hdmi_spec_per_pin *per_pin;
1690 caps = snd_hda_query_pin_caps(codec, pin_nid);
1691 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
1695 * For DP MST audio, Configuration Default is the same for
1696 * all device entries on the same pin
1698 config = snd_hda_codec_get_pincfg(codec, pin_nid);
1699 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
1703 * To simplify the implementation, malloc all
1704 * the virtual pins in the initialization statically
1706 if (is_haswell_plus(codec)) {
1708 * On Intel platforms, device entries number is
1709 * changed dynamically. If there is a DP MST
1710 * hub connected, the device entries number is 3.
1711 * Otherwise, it is 1.
1712 * Here we manually set dev_num to 3, so that
1713 * we can initialize all the device entries when
1714 * bootup statically.
1718 } else if (spec->dyn_pcm_assign && codec->dp_mst) {
1719 dev_num = snd_hda_get_num_devices(codec, pin_nid) + 1;
1721 * spec->dev_num is the maxinum number of device entries
1722 * among all the pins
1724 spec->dev_num = (spec->dev_num > dev_num) ?
1725 spec->dev_num : dev_num;
1728 * If the platform doesn't support DP MST,
1729 * manually set dev_num to 1. This means
1730 * the pin has only one device entry.
1736 for (i = 0; i < dev_num; i++) {
1737 pin_idx = spec->num_pins;
1738 per_pin = snd_array_new(&spec->pins);
1743 if (spec->dyn_pcm_assign) {
1744 per_pin->pcm = NULL;
1745 per_pin->pcm_idx = -1;
1747 per_pin->pcm = get_hdmi_pcm(spec, pin_idx);
1748 per_pin->pcm_idx = pin_idx;
1750 per_pin->pin_nid = pin_nid;
1751 per_pin->pin_nid_idx = spec->num_nids;
1752 per_pin->dev_id = i;
1753 per_pin->non_pcm = false;
1754 snd_hda_set_dev_select(codec, pin_nid, i);
1755 if (is_haswell_plus(codec))
1756 intel_haswell_fixup_connect_list(codec, pin_nid);
1757 err = hdmi_read_pin_conn(codec, pin_idx);
1767 static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1769 struct hdmi_spec *spec = codec->spec;
1770 struct hdmi_spec_per_cvt *per_cvt;
1774 chans = get_wcaps(codec, cvt_nid);
1775 chans = get_wcaps_channels(chans);
1777 per_cvt = snd_array_new(&spec->cvts);
1781 per_cvt->cvt_nid = cvt_nid;
1782 per_cvt->channels_min = 2;
1784 per_cvt->channels_max = chans;
1785 if (chans > spec->chmap.channels_max)
1786 spec->chmap.channels_max = chans;
1789 err = snd_hda_query_supported_pcm(codec, cvt_nid,
1796 if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids))
1797 spec->cvt_nids[spec->num_cvts] = cvt_nid;
1803 static int hdmi_parse_codec(struct hda_codec *codec)
1808 nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &nid);
1809 if (!nid || nodes < 0) {
1810 codec_warn(codec, "HDMI: failed to get afg sub nodes\n");
1814 for (i = 0; i < nodes; i++, nid++) {
1818 caps = get_wcaps(codec, nid);
1819 type = get_wcaps_type(caps);
1821 if (!(caps & AC_WCAP_DIGITAL))
1825 case AC_WID_AUD_OUT:
1826 hdmi_add_cvt(codec, nid);
1829 hdmi_add_pin(codec, nid);
1839 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1841 struct hda_spdif_out *spdif;
1844 mutex_lock(&codec->spdif_mutex);
1845 spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
1846 /* Add sanity check to pass klockwork check.
1847 * This should never happen.
1849 if (WARN_ON(spdif == NULL))
1851 non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO);
1852 mutex_unlock(&codec->spdif_mutex);
1860 static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1861 struct hda_codec *codec,
1862 unsigned int stream_tag,
1863 unsigned int format,
1864 struct snd_pcm_substream *substream)
1866 hda_nid_t cvt_nid = hinfo->nid;
1867 struct hdmi_spec *spec = codec->spec;
1869 struct hdmi_spec_per_pin *per_pin;
1871 struct snd_pcm_runtime *runtime = substream->runtime;
1876 mutex_lock(&spec->pcm_lock);
1877 pin_idx = hinfo_to_pin_index(codec, hinfo);
1878 if (spec->dyn_pcm_assign && pin_idx < 0) {
1879 /* when dyn_pcm_assign and pcm is not bound to a pin
1880 * skip pin setup and return 0 to make audio playback
1883 pin_cvt_fixup(codec, NULL, cvt_nid);
1884 snd_hda_codec_setup_stream(codec, cvt_nid,
1885 stream_tag, 0, format);
1889 if (snd_BUG_ON(pin_idx < 0)) {
1893 per_pin = get_pin(spec, pin_idx);
1894 pin_nid = per_pin->pin_nid;
1896 /* Verify pin:cvt selections to avoid silent audio after S3.
1897 * After S3, the audio driver restores pin:cvt selections
1898 * but this can happen before gfx is ready and such selection
1899 * is overlooked by HW. Thus multiple pins can share a same
1900 * default convertor and mute control will affect each other,
1901 * which can cause a resumed audio playback become silent
1904 pin_cvt_fixup(codec, per_pin, 0);
1906 /* Call sync_audio_rate to set the N/CTS/M manually if necessary */
1907 /* Todo: add DP1.2 MST audio support later */
1908 if (codec_has_acomp(codec))
1909 snd_hdac_sync_audio_rate(&codec->core, pin_nid, per_pin->dev_id,
1912 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
1913 mutex_lock(&per_pin->lock);
1914 per_pin->channels = substream->runtime->channels;
1915 per_pin->setup = true;
1917 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
1918 mutex_unlock(&per_pin->lock);
1919 if (spec->dyn_pin_out) {
1920 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
1921 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1922 snd_hda_codec_write(codec, pin_nid, 0,
1923 AC_VERB_SET_PIN_WIDGET_CONTROL,
1927 /* snd_hda_set_dev_select() has been called before */
1928 err = spec->ops.setup_stream(codec, cvt_nid, pin_nid,
1929 stream_tag, format);
1931 mutex_unlock(&spec->pcm_lock);
1935 static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1936 struct hda_codec *codec,
1937 struct snd_pcm_substream *substream)
1939 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
1943 static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1944 struct hda_codec *codec,
1945 struct snd_pcm_substream *substream)
1947 struct hdmi_spec *spec = codec->spec;
1948 int cvt_idx, pin_idx, pcm_idx;
1949 struct hdmi_spec_per_cvt *per_cvt;
1950 struct hdmi_spec_per_pin *per_pin;
1955 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1956 if (snd_BUG_ON(pcm_idx < 0))
1958 cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid);
1959 if (snd_BUG_ON(cvt_idx < 0))
1961 per_cvt = get_cvt(spec, cvt_idx);
1963 snd_BUG_ON(!per_cvt->assigned);
1964 per_cvt->assigned = 0;
1967 mutex_lock(&spec->pcm_lock);
1968 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
1969 clear_bit(pcm_idx, &spec->pcm_in_use);
1970 pin_idx = hinfo_to_pin_index(codec, hinfo);
1971 if (spec->dyn_pcm_assign && pin_idx < 0)
1974 if (snd_BUG_ON(pin_idx < 0)) {
1978 per_pin = get_pin(spec, pin_idx);
1980 if (spec->dyn_pin_out) {
1981 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
1982 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1983 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
1984 AC_VERB_SET_PIN_WIDGET_CONTROL,
1988 mutex_lock(&per_pin->lock);
1989 per_pin->chmap_set = false;
1990 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
1992 per_pin->setup = false;
1993 per_pin->channels = 0;
1994 mutex_unlock(&per_pin->lock);
1996 mutex_unlock(&spec->pcm_lock);
2002 static const struct hda_pcm_ops generic_ops = {
2003 .open = hdmi_pcm_open,
2004 .close = hdmi_pcm_close,
2005 .prepare = generic_hdmi_playback_pcm_prepare,
2006 .cleanup = generic_hdmi_playback_pcm_cleanup,
2009 static int hdmi_get_spk_alloc(struct hdac_device *hdac, int pcm_idx)
2011 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
2012 struct hdmi_spec *spec = codec->spec;
2013 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2018 return per_pin->sink_eld.info.spk_alloc;
2021 static void hdmi_get_chmap(struct hdac_device *hdac, int pcm_idx,
2022 unsigned char *chmap)
2024 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
2025 struct hdmi_spec *spec = codec->spec;
2026 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2028 /* chmap is already set to 0 in caller */
2032 memcpy(chmap, per_pin->chmap, ARRAY_SIZE(per_pin->chmap));
2035 static void hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx,
2036 unsigned char *chmap, int prepared)
2038 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
2039 struct hdmi_spec *spec = codec->spec;
2040 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2044 mutex_lock(&per_pin->lock);
2045 per_pin->chmap_set = true;
2046 memcpy(per_pin->chmap, chmap, ARRAY_SIZE(per_pin->chmap));
2048 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
2049 mutex_unlock(&per_pin->lock);
2052 static bool is_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx)
2054 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
2055 struct hdmi_spec *spec = codec->spec;
2056 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
2058 return per_pin ? true:false;
2061 static int generic_hdmi_build_pcms(struct hda_codec *codec)
2063 struct hdmi_spec *spec = codec->spec;
2067 * for non-mst mode, pcm number is the same as before
2068 * for DP MST mode, pcm number is (nid number + dev_num - 1)
2069 * dev_num is the device entry number in a pin
2072 for (idx = 0; idx < spec->num_nids + spec->dev_num - 1; idx++) {
2073 struct hda_pcm *info;
2074 struct hda_pcm_stream *pstr;
2076 info = snd_hda_codec_pcm_new(codec, "HDMI %d", idx);
2080 spec->pcm_rec[idx].pcm = info;
2082 info->pcm_type = HDA_PCM_TYPE_HDMI;
2083 info->own_chmap = true;
2085 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
2086 pstr->substreams = 1;
2087 pstr->ops = generic_ops;
2088 /* pcm number is less than 16 */
2089 if (spec->pcm_used >= 16)
2091 /* other pstr fields are set in open */
2097 static void free_hdmi_jack_priv(struct snd_jack *jack)
2099 struct hdmi_pcm *pcm = jack->private_data;
2104 static int add_hdmi_jack_kctl(struct hda_codec *codec,
2105 struct hdmi_spec *spec,
2109 struct snd_jack *jack;
2112 err = snd_jack_new(codec->card, name, SND_JACK_AVOUT, &jack,
2117 spec->pcm_rec[pcm_idx].jack = jack;
2118 jack->private_data = &spec->pcm_rec[pcm_idx];
2119 jack->private_free = free_hdmi_jack_priv;
2123 static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx)
2125 char hdmi_str[32] = "HDMI/DP";
2126 struct hdmi_spec *spec = codec->spec;
2127 struct hdmi_spec_per_pin *per_pin;
2128 struct hda_jack_tbl *jack;
2129 int pcmdev = get_pcm_rec(spec, pcm_idx)->device;
2134 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
2136 if (spec->dyn_pcm_assign)
2137 return add_hdmi_jack_kctl(codec, spec, pcm_idx, hdmi_str);
2139 /* for !dyn_pcm_assign, we still use hda_jack for compatibility */
2140 /* if !dyn_pcm_assign, it must be non-MST mode.
2141 * This means pcms and pins are statically mapped.
2142 * And pcm_idx is pin_idx.
2144 per_pin = get_pin(spec, pcm_idx);
2145 phantom_jack = !is_jack_detectable(codec, per_pin->pin_nid);
2147 strncat(hdmi_str, " Phantom",
2148 sizeof(hdmi_str) - strlen(hdmi_str) - 1);
2149 ret = snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str,
2153 jack = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
2156 /* assign jack->jack to pcm_rec[].jack to
2157 * align with dyn_pcm_assign mode
2159 spec->pcm_rec[pcm_idx].jack = jack->jack;
2163 static int generic_hdmi_build_controls(struct hda_codec *codec)
2165 struct hdmi_spec *spec = codec->spec;
2167 int pin_idx, pcm_idx;
2169 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2170 if (!get_pcm_rec(spec, pcm_idx)->pcm) {
2171 /* no PCM: mark this for skipping permanently */
2172 set_bit(pcm_idx, &spec->pcm_bitmap);
2176 err = generic_hdmi_build_jack(codec, pcm_idx);
2180 /* create the spdif for each pcm
2181 * pin will be bound when monitor is connected
2183 if (spec->dyn_pcm_assign)
2184 err = snd_hda_create_dig_out_ctls(codec,
2185 0, spec->cvt_nids[0],
2188 struct hdmi_spec_per_pin *per_pin =
2189 get_pin(spec, pcm_idx);
2190 err = snd_hda_create_dig_out_ctls(codec,
2192 per_pin->mux_nids[0],
2197 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
2199 dev = get_pcm_rec(spec, pcm_idx)->device;
2200 if (dev != SNDRV_PCM_INVALID_DEVICE) {
2201 /* add control for ELD Bytes */
2202 err = hdmi_create_eld_ctl(codec, pcm_idx, dev);
2208 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2209 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2211 hdmi_present_sense(per_pin, 0);
2214 /* add channel maps */
2215 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2216 struct hda_pcm *pcm;
2218 pcm = get_pcm_rec(spec, pcm_idx);
2219 if (!pcm || !pcm->pcm)
2221 err = snd_hdac_add_chmap_ctls(pcm->pcm, pcm_idx, &spec->chmap);
2229 static int generic_hdmi_init_per_pins(struct hda_codec *codec)
2231 struct hdmi_spec *spec = codec->spec;
2234 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2235 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2237 per_pin->codec = codec;
2238 mutex_init(&per_pin->lock);
2239 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
2240 eld_proc_new(per_pin, pin_idx);
2245 static int generic_hdmi_init(struct hda_codec *codec)
2247 struct hdmi_spec *spec = codec->spec;
2250 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2251 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2252 hda_nid_t pin_nid = per_pin->pin_nid;
2253 int dev_id = per_pin->dev_id;
2255 snd_hda_set_dev_select(codec, pin_nid, dev_id);
2256 hdmi_init_pin(codec, pin_nid);
2257 if (!codec_has_acomp(codec))
2258 snd_hda_jack_detect_enable_callback(codec, pin_nid,
2259 codec->jackpoll_interval > 0 ?
2260 jack_callback : NULL);
2265 static void hdmi_array_init(struct hdmi_spec *spec, int nums)
2267 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums);
2268 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums);
2271 static void hdmi_array_free(struct hdmi_spec *spec)
2273 snd_array_free(&spec->pins);
2274 snd_array_free(&spec->cvts);
2277 static void generic_spec_free(struct hda_codec *codec)
2279 struct hdmi_spec *spec = codec->spec;
2282 hdmi_array_free(spec);
2286 codec->dp_mst = false;
2289 static void generic_hdmi_free(struct hda_codec *codec)
2291 struct hdmi_spec *spec = codec->spec;
2292 int pin_idx, pcm_idx;
2294 if (codec_has_acomp(codec))
2295 snd_hdac_acomp_register_notifier(&codec->bus->core, NULL);
2297 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2298 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2299 cancel_delayed_work_sync(&per_pin->work);
2300 eld_proc_free(per_pin);
2303 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2304 if (spec->pcm_rec[pcm_idx].jack == NULL)
2306 if (spec->dyn_pcm_assign)
2307 snd_device_free(codec->card,
2308 spec->pcm_rec[pcm_idx].jack);
2310 spec->pcm_rec[pcm_idx].jack = NULL;
2313 generic_spec_free(codec);
2317 static int generic_hdmi_resume(struct hda_codec *codec)
2319 struct hdmi_spec *spec = codec->spec;
2322 codec->patch_ops.init(codec);
2323 regcache_sync(codec->core.regmap);
2325 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2326 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2327 hdmi_present_sense(per_pin, 1);
2333 static const struct hda_codec_ops generic_hdmi_patch_ops = {
2334 .init = generic_hdmi_init,
2335 .free = generic_hdmi_free,
2336 .build_pcms = generic_hdmi_build_pcms,
2337 .build_controls = generic_hdmi_build_controls,
2338 .unsol_event = hdmi_unsol_event,
2340 .resume = generic_hdmi_resume,
2344 static const struct hdmi_ops generic_standard_hdmi_ops = {
2345 .pin_get_eld = snd_hdmi_get_eld,
2346 .pin_setup_infoframe = hdmi_pin_setup_infoframe,
2347 .pin_hbr_setup = hdmi_pin_hbr_setup,
2348 .setup_stream = hdmi_setup_stream,
2351 /* allocate codec->spec and assign/initialize generic parser ops */
2352 static int alloc_generic_hdmi(struct hda_codec *codec)
2354 struct hdmi_spec *spec;
2356 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2360 spec->ops = generic_standard_hdmi_ops;
2361 spec->dev_num = 1; /* initialize to 1 */
2362 mutex_init(&spec->pcm_lock);
2363 snd_hdac_register_chmap_ops(&codec->core, &spec->chmap);
2365 spec->chmap.ops.get_chmap = hdmi_get_chmap;
2366 spec->chmap.ops.set_chmap = hdmi_set_chmap;
2367 spec->chmap.ops.is_pcm_attached = is_hdmi_pcm_attached;
2368 spec->chmap.ops.get_spk_alloc = hdmi_get_spk_alloc,
2371 hdmi_array_init(spec, 4);
2373 codec->patch_ops = generic_hdmi_patch_ops;
2378 /* generic HDMI parser */
2379 static int patch_generic_hdmi(struct hda_codec *codec)
2383 err = alloc_generic_hdmi(codec);
2387 err = hdmi_parse_codec(codec);
2389 generic_spec_free(codec);
2393 generic_hdmi_init_per_pins(codec);
2398 * Intel codec parsers and helpers
2401 static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
2404 struct hdmi_spec *spec = codec->spec;
2408 nconns = snd_hda_get_connections(codec, nid, conns, ARRAY_SIZE(conns));
2409 if (nconns == spec->num_cvts &&
2410 !memcmp(conns, spec->cvt_nids, spec->num_cvts * sizeof(hda_nid_t)))
2413 /* override pins connection list */
2414 codec_dbg(codec, "hdmi: haswell: override pin connection 0x%x\n", nid);
2415 snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids);
2418 #define INTEL_VENDOR_NID 0x08
2419 #define INTEL_GLK_VENDOR_NID 0x0B
2420 #define INTEL_GET_VENDOR_VERB 0xf81
2421 #define INTEL_SET_VENDOR_VERB 0x781
2422 #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
2423 #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
2425 static void intel_haswell_enable_all_pins(struct hda_codec *codec,
2428 unsigned int vendor_param;
2429 struct hdmi_spec *spec = codec->spec;
2431 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2432 INTEL_GET_VENDOR_VERB, 0);
2433 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
2436 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
2437 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2438 INTEL_SET_VENDOR_VERB, vendor_param);
2439 if (vendor_param == -1)
2443 snd_hda_codec_update_widgets(codec);
2446 static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
2448 unsigned int vendor_param;
2449 struct hdmi_spec *spec = codec->spec;
2451 vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
2452 INTEL_GET_VENDOR_VERB, 0);
2453 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
2456 /* enable DP1.2 mode */
2457 vendor_param |= INTEL_EN_DP12;
2458 snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB);
2459 snd_hda_codec_write_cache(codec, spec->vendor_nid, 0,
2460 INTEL_SET_VENDOR_VERB, vendor_param);
2463 /* Haswell needs to re-issue the vendor-specific verbs before turning to D0.
2464 * Otherwise you may get severe h/w communication errors.
2466 static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2467 unsigned int power_state)
2469 if (power_state == AC_PWRST_D0) {
2470 intel_haswell_enable_all_pins(codec, false);
2471 intel_haswell_fixup_enable_dp12(codec);
2474 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
2475 snd_hda_codec_set_power_to_all(codec, fg, power_state);
2478 /* There is a fixed mapping between audio pin node and display port.
2479 * on SNB, IVY, HSW, BSW, SKL, BXT, KBL:
2480 * Pin Widget 5 - PORT B (port = 1 in i915 driver)
2481 * Pin Widget 6 - PORT C (port = 2 in i915 driver)
2482 * Pin Widget 7 - PORT D (port = 3 in i915 driver)
2485 * Pin Widget 4 - PORT B (port = 1 in i915 driver)
2486 * Pin Widget 5 - PORT C (port = 2 in i915 driver)
2487 * Pin Widget 6 - PORT D (port = 3 in i915 driver)
2489 static int intel_base_nid(struct hda_codec *codec)
2491 switch (codec->core.vendor_id) {
2492 case 0x80860054: /* ILK */
2493 case 0x80862804: /* ILK */
2494 case 0x80862882: /* VLV */
2501 static int intel_pin2port(void *audio_ptr, int pin_nid)
2503 int base_nid = intel_base_nid(audio_ptr);
2505 if (WARN_ON(pin_nid < base_nid || pin_nid >= base_nid + 3))
2507 return pin_nid - base_nid + 1; /* intel port is 1-based */
2510 static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe)
2512 struct hda_codec *codec = audio_ptr;
2516 /* we assume only from port-B to port-D */
2517 if (port < 1 || port > 3)
2520 pin_nid = port + intel_base_nid(codec) - 1; /* intel port is 1-based */
2522 /* skip notification during system suspend (but not in runtime PM);
2523 * the state will be updated at resume
2525 if (snd_power_get_state(codec->card) != SNDRV_CTL_POWER_D0)
2527 /* ditto during suspend/resume process itself */
2528 if (snd_hdac_is_in_pm(&codec->core))
2531 snd_hdac_i915_set_bclk(&codec->bus->core);
2532 check_presence_and_report(codec, pin_nid, dev_id);
2535 /* register i915 component pin_eld_notify callback */
2536 static void register_i915_notifier(struct hda_codec *codec)
2538 struct hdmi_spec *spec = codec->spec;
2540 spec->use_acomp_notifier = true;
2541 spec->drm_audio_ops.audio_ptr = codec;
2542 /* intel_audio_codec_enable() or intel_audio_codec_disable()
2543 * will call pin_eld_notify with using audio_ptr pointer
2544 * We need make sure audio_ptr is really setup
2547 spec->drm_audio_ops.pin2port = intel_pin2port;
2548 spec->drm_audio_ops.pin_eld_notify = intel_pin_eld_notify;
2549 snd_hdac_acomp_register_notifier(&codec->bus->core,
2550 &spec->drm_audio_ops);
2553 /* setup_stream ops override for HSW+ */
2554 static int i915_hsw_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
2555 hda_nid_t pin_nid, u32 stream_tag, int format)
2557 haswell_verify_D0(codec, cvt_nid, pin_nid);
2558 return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
2561 /* pin_cvt_fixup ops override for HSW+ and VLV+ */
2562 static void i915_pin_cvt_fixup(struct hda_codec *codec,
2563 struct hdmi_spec_per_pin *per_pin,
2567 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2569 intel_verify_pin_cvt_connect(codec, per_pin);
2570 intel_not_share_assigned_cvt(codec, per_pin->pin_nid,
2571 per_pin->dev_id, per_pin->mux_idx);
2573 intel_not_share_assigned_cvt_nid(codec, 0, 0, cvt_nid);
2577 /* precondition and allocation for Intel codecs */
2578 static int alloc_intel_hdmi(struct hda_codec *codec)
2580 /* requires i915 binding */
2581 if (!codec->bus->core.audio_component) {
2582 codec_info(codec, "No i915 binding for Intel HDMI/DP codec\n");
2583 /* set probe_id here to prevent generic fallback binding */
2584 codec->probe_id = HDA_CODEC_ID_SKIP_PROBE;
2588 return alloc_generic_hdmi(codec);
2591 /* parse and post-process for Intel codecs */
2592 static int parse_intel_hdmi(struct hda_codec *codec)
2596 err = hdmi_parse_codec(codec);
2598 generic_spec_free(codec);
2602 generic_hdmi_init_per_pins(codec);
2603 register_i915_notifier(codec);
2607 /* Intel Haswell and onwards; audio component with eld notifier */
2608 static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid)
2610 struct hdmi_spec *spec;
2613 err = alloc_intel_hdmi(codec);
2617 codec->dp_mst = true;
2618 spec->dyn_pcm_assign = true;
2619 spec->vendor_nid = vendor_nid;
2621 intel_haswell_enable_all_pins(codec, true);
2622 intel_haswell_fixup_enable_dp12(codec);
2624 /* For Haswell/Broadwell, the controller is also in the power well and
2625 * can cover the codec power request, and so need not set this flag.
2627 if (!is_haswell(codec) && !is_broadwell(codec))
2628 codec->core.link_power_control = 1;
2630 codec->patch_ops.set_power_state = haswell_set_power_state;
2631 codec->depop_delay = 0;
2632 codec->auto_runtime_pm = 1;
2634 spec->ops.setup_stream = i915_hsw_setup_stream;
2635 spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup;
2637 return parse_intel_hdmi(codec);
2640 static int patch_i915_hsw_hdmi(struct hda_codec *codec)
2642 return intel_hsw_common_init(codec, INTEL_VENDOR_NID);
2645 static int patch_i915_glk_hdmi(struct hda_codec *codec)
2647 return intel_hsw_common_init(codec, INTEL_GLK_VENDOR_NID);
2650 /* Intel Baytrail and Braswell; with eld notifier */
2651 static int patch_i915_byt_hdmi(struct hda_codec *codec)
2653 struct hdmi_spec *spec;
2656 err = alloc_intel_hdmi(codec);
2661 /* For Valleyview/Cherryview, only the display codec is in the display
2662 * power well and can use link_power ops to request/release the power.
2664 codec->core.link_power_control = 1;
2666 codec->depop_delay = 0;
2667 codec->auto_runtime_pm = 1;
2669 spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup;
2671 return parse_intel_hdmi(codec);
2674 /* Intel IronLake, SandyBridge and IvyBridge; with eld notifier */
2675 static int patch_i915_cpt_hdmi(struct hda_codec *codec)
2679 err = alloc_intel_hdmi(codec);
2682 return parse_intel_hdmi(codec);
2686 * Shared non-generic implementations
2689 static int simple_playback_build_pcms(struct hda_codec *codec)
2691 struct hdmi_spec *spec = codec->spec;
2692 struct hda_pcm *info;
2694 struct hda_pcm_stream *pstr;
2695 struct hdmi_spec_per_cvt *per_cvt;
2697 per_cvt = get_cvt(spec, 0);
2698 chans = get_wcaps(codec, per_cvt->cvt_nid);
2699 chans = get_wcaps_channels(chans);
2701 info = snd_hda_codec_pcm_new(codec, "HDMI 0");
2704 spec->pcm_rec[0].pcm = info;
2705 info->pcm_type = HDA_PCM_TYPE_HDMI;
2706 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
2707 *pstr = spec->pcm_playback;
2708 pstr->nid = per_cvt->cvt_nid;
2709 if (pstr->channels_max <= 2 && chans && chans <= 16)
2710 pstr->channels_max = chans;
2715 /* unsolicited event for jack sensing */
2716 static void simple_hdmi_unsol_event(struct hda_codec *codec,
2719 snd_hda_jack_set_dirty_all(codec);
2720 snd_hda_jack_report_sync(codec);
2723 /* generic_hdmi_build_jack can be used for simple_hdmi, too,
2724 * as long as spec->pins[] is set correctly
2726 #define simple_hdmi_build_jack generic_hdmi_build_jack
2728 static int simple_playback_build_controls(struct hda_codec *codec)
2730 struct hdmi_spec *spec = codec->spec;
2731 struct hdmi_spec_per_cvt *per_cvt;
2734 per_cvt = get_cvt(spec, 0);
2735 err = snd_hda_create_dig_out_ctls(codec, per_cvt->cvt_nid,
2740 return simple_hdmi_build_jack(codec, 0);
2743 static int simple_playback_init(struct hda_codec *codec)
2745 struct hdmi_spec *spec = codec->spec;
2746 struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0);
2747 hda_nid_t pin = per_pin->pin_nid;
2749 snd_hda_codec_write(codec, pin, 0,
2750 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
2751 /* some codecs require to unmute the pin */
2752 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
2753 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2755 snd_hda_jack_detect_enable(codec, pin);
2759 static void simple_playback_free(struct hda_codec *codec)
2761 struct hdmi_spec *spec = codec->spec;
2763 hdmi_array_free(spec);
2768 * Nvidia specific implementations
2771 #define Nv_VERB_SET_Channel_Allocation 0xF79
2772 #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
2773 #define Nv_VERB_SET_Audio_Protection_On 0xF98
2774 #define Nv_VERB_SET_Audio_Protection_Off 0xF99
2776 #define nvhdmi_master_con_nid_7x 0x04
2777 #define nvhdmi_master_pin_nid_7x 0x05
2779 static const hda_nid_t nvhdmi_con_nids_7x[4] = {
2780 /*front, rear, clfe, rear_surr */
2784 static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = {
2785 /* set audio protect on */
2786 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
2787 /* enable digital output on pin widget */
2788 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2792 static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = {
2793 /* set audio protect on */
2794 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
2795 /* enable digital output on pin widget */
2796 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2797 { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2798 { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2799 { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2800 { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2804 #ifdef LIMITED_RATE_FMT_SUPPORT
2805 /* support only the safe format and rate */
2806 #define SUPPORTED_RATES SNDRV_PCM_RATE_48000
2807 #define SUPPORTED_MAXBPS 16
2808 #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
2810 /* support all rates and formats */
2811 #define SUPPORTED_RATES \
2812 (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
2813 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
2814 SNDRV_PCM_RATE_192000)
2815 #define SUPPORTED_MAXBPS 24
2816 #define SUPPORTED_FORMATS \
2817 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
2820 static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
2822 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
2826 static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
2828 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
2832 static const unsigned int channels_2_6_8[] = {
2836 static const unsigned int channels_2_8[] = {
2840 static const struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
2841 .count = ARRAY_SIZE(channels_2_6_8),
2842 .list = channels_2_6_8,
2846 static const struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
2847 .count = ARRAY_SIZE(channels_2_8),
2848 .list = channels_2_8,
2852 static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
2853 struct hda_codec *codec,
2854 struct snd_pcm_substream *substream)
2856 struct hdmi_spec *spec = codec->spec;
2857 const struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
2859 switch (codec->preset->vendor_id) {
2864 hw_constraints_channels = &hw_constraints_2_8_channels;
2867 hw_constraints_channels = &hw_constraints_2_6_8_channels;
2873 if (hw_constraints_channels != NULL) {
2874 snd_pcm_hw_constraint_list(substream->runtime, 0,
2875 SNDRV_PCM_HW_PARAM_CHANNELS,
2876 hw_constraints_channels);
2878 snd_pcm_hw_constraint_step(substream->runtime, 0,
2879 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
2882 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2885 static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
2886 struct hda_codec *codec,
2887 struct snd_pcm_substream *substream)
2889 struct hdmi_spec *spec = codec->spec;
2890 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2893 static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2894 struct hda_codec *codec,
2895 unsigned int stream_tag,
2896 unsigned int format,
2897 struct snd_pcm_substream *substream)
2899 struct hdmi_spec *spec = codec->spec;
2900 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2901 stream_tag, format, substream);
2904 static const struct hda_pcm_stream simple_pcm_playback = {
2909 .open = simple_playback_pcm_open,
2910 .close = simple_playback_pcm_close,
2911 .prepare = simple_playback_pcm_prepare
2915 static const struct hda_codec_ops simple_hdmi_patch_ops = {
2916 .build_controls = simple_playback_build_controls,
2917 .build_pcms = simple_playback_build_pcms,
2918 .init = simple_playback_init,
2919 .free = simple_playback_free,
2920 .unsol_event = simple_hdmi_unsol_event,
2923 static int patch_simple_hdmi(struct hda_codec *codec,
2924 hda_nid_t cvt_nid, hda_nid_t pin_nid)
2926 struct hdmi_spec *spec;
2927 struct hdmi_spec_per_cvt *per_cvt;
2928 struct hdmi_spec_per_pin *per_pin;
2930 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2935 hdmi_array_init(spec, 1);
2937 spec->multiout.num_dacs = 0; /* no analog */
2938 spec->multiout.max_channels = 2;
2939 spec->multiout.dig_out_nid = cvt_nid;
2942 per_pin = snd_array_new(&spec->pins);
2943 per_cvt = snd_array_new(&spec->cvts);
2944 if (!per_pin || !per_cvt) {
2945 simple_playback_free(codec);
2948 per_cvt->cvt_nid = cvt_nid;
2949 per_pin->pin_nid = pin_nid;
2950 spec->pcm_playback = simple_pcm_playback;
2952 codec->patch_ops = simple_hdmi_patch_ops;
2957 static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
2960 unsigned int chanmask;
2961 int chan = channels ? (channels - 1) : 1;
2980 /* Set the audio infoframe channel allocation and checksum fields. The
2981 * channel count is computed implicitly by the hardware. */
2982 snd_hda_codec_write(codec, 0x1, 0,
2983 Nv_VERB_SET_Channel_Allocation, chanmask);
2985 snd_hda_codec_write(codec, 0x1, 0,
2986 Nv_VERB_SET_Info_Frame_Checksum,
2987 (0x71 - chan - chanmask));
2990 static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
2991 struct hda_codec *codec,
2992 struct snd_pcm_substream *substream)
2994 struct hdmi_spec *spec = codec->spec;
2997 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
2998 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
2999 for (i = 0; i < 4; i++) {
3000 /* set the stream id */
3001 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
3002 AC_VERB_SET_CHANNEL_STREAMID, 0);
3003 /* set the stream format */
3004 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
3005 AC_VERB_SET_STREAM_FORMAT, 0);
3008 /* The audio hardware sends a channel count of 0x7 (8ch) when all the
3009 * streams are disabled. */
3010 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
3012 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3015 static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
3016 struct hda_codec *codec,
3017 unsigned int stream_tag,
3018 unsigned int format,
3019 struct snd_pcm_substream *substream)
3022 unsigned int dataDCC2, channel_id;
3024 struct hdmi_spec *spec = codec->spec;
3025 struct hda_spdif_out *spdif;
3026 struct hdmi_spec_per_cvt *per_cvt;
3028 mutex_lock(&codec->spdif_mutex);
3029 per_cvt = get_cvt(spec, 0);
3030 spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid);
3032 chs = substream->runtime->channels;
3036 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
3037 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
3038 snd_hda_codec_write(codec,
3039 nvhdmi_master_con_nid_7x,
3041 AC_VERB_SET_DIGI_CONVERT_1,
3042 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
3044 /* set the stream id */
3045 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
3046 AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
3048 /* set the stream format */
3049 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
3050 AC_VERB_SET_STREAM_FORMAT, format);
3052 /* turn on again (if needed) */
3053 /* enable and set the channel status audio/data flag */
3054 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
3055 snd_hda_codec_write(codec,
3056 nvhdmi_master_con_nid_7x,
3058 AC_VERB_SET_DIGI_CONVERT_1,
3059 spdif->ctls & 0xff);
3060 snd_hda_codec_write(codec,
3061 nvhdmi_master_con_nid_7x,
3063 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
3066 for (i = 0; i < 4; i++) {
3072 /* turn off SPDIF once;
3073 *otherwise the IEC958 bits won't be updated
3075 if (codec->spdif_status_reset &&
3076 (spdif->ctls & AC_DIG1_ENABLE))
3077 snd_hda_codec_write(codec,
3078 nvhdmi_con_nids_7x[i],
3080 AC_VERB_SET_DIGI_CONVERT_1,
3081 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
3082 /* set the stream id */
3083 snd_hda_codec_write(codec,
3084 nvhdmi_con_nids_7x[i],
3086 AC_VERB_SET_CHANNEL_STREAMID,
3087 (stream_tag << 4) | channel_id);
3088 /* set the stream format */
3089 snd_hda_codec_write(codec,
3090 nvhdmi_con_nids_7x[i],
3092 AC_VERB_SET_STREAM_FORMAT,
3094 /* turn on again (if needed) */
3095 /* enable and set the channel status audio/data flag */
3096 if (codec->spdif_status_reset &&
3097 (spdif->ctls & AC_DIG1_ENABLE)) {
3098 snd_hda_codec_write(codec,
3099 nvhdmi_con_nids_7x[i],
3101 AC_VERB_SET_DIGI_CONVERT_1,
3102 spdif->ctls & 0xff);
3103 snd_hda_codec_write(codec,
3104 nvhdmi_con_nids_7x[i],
3106 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
3110 nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
3112 mutex_unlock(&codec->spdif_mutex);
3116 static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
3120 .nid = nvhdmi_master_con_nid_7x,
3121 .rates = SUPPORTED_RATES,
3122 .maxbps = SUPPORTED_MAXBPS,
3123 .formats = SUPPORTED_FORMATS,
3125 .open = simple_playback_pcm_open,
3126 .close = nvhdmi_8ch_7x_pcm_close,
3127 .prepare = nvhdmi_8ch_7x_pcm_prepare
3131 static int patch_nvhdmi_2ch(struct hda_codec *codec)
3133 struct hdmi_spec *spec;
3134 int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
3135 nvhdmi_master_pin_nid_7x);
3139 codec->patch_ops.init = nvhdmi_7x_init_2ch;
3140 /* override the PCM rates, etc, as the codec doesn't give full list */
3142 spec->pcm_playback.rates = SUPPORTED_RATES;
3143 spec->pcm_playback.maxbps = SUPPORTED_MAXBPS;
3144 spec->pcm_playback.formats = SUPPORTED_FORMATS;
3148 static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
3150 struct hdmi_spec *spec = codec->spec;
3151 int err = simple_playback_build_pcms(codec);
3153 struct hda_pcm *info = get_pcm_rec(spec, 0);
3154 info->own_chmap = true;
3159 static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
3161 struct hdmi_spec *spec = codec->spec;
3162 struct hda_pcm *info;
3163 struct snd_pcm_chmap *chmap;
3166 err = simple_playback_build_controls(codec);
3170 /* add channel maps */
3171 info = get_pcm_rec(spec, 0);
3172 err = snd_pcm_add_chmap_ctls(info->pcm,
3173 SNDRV_PCM_STREAM_PLAYBACK,
3174 snd_pcm_alt_chmaps, 8, 0, &chmap);
3177 switch (codec->preset->vendor_id) {
3182 chmap->channel_mask = (1U << 2) | (1U << 8);
3185 chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8);
3190 static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
3192 struct hdmi_spec *spec;
3193 int err = patch_nvhdmi_2ch(codec);
3197 spec->multiout.max_channels = 8;
3198 spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x;
3199 codec->patch_ops.init = nvhdmi_7x_init_8ch;
3200 codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
3201 codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
3203 /* Initialize the audio infoframe channel mask and checksum to something
3205 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
3211 * NVIDIA codecs ignore ASP mapping for 2ch - confirmed on:
3215 static int nvhdmi_chmap_cea_alloc_validate_get_type(struct hdac_chmap *chmap,
3216 struct hdac_cea_channel_speaker_allocation *cap, int channels)
3218 if (cap->ca_index == 0x00 && channels == 2)
3219 return SNDRV_CTL_TLVT_CHMAP_FIXED;
3221 /* If the speaker allocation matches the channel count, it is OK. */
3222 if (cap->channels != channels)
3225 /* all channels are remappable freely */
3226 return SNDRV_CTL_TLVT_CHMAP_VAR;
3229 static int nvhdmi_chmap_validate(struct hdac_chmap *chmap,
3230 int ca, int chs, unsigned char *map)
3232 if (ca == 0x00 && (map[0] != SNDRV_CHMAP_FL || map[1] != SNDRV_CHMAP_FR))
3238 static int patch_nvhdmi(struct hda_codec *codec)
3240 struct hdmi_spec *spec;
3243 err = patch_generic_hdmi(codec);
3248 spec->dyn_pin_out = true;
3250 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
3251 nvhdmi_chmap_cea_alloc_validate_get_type;
3252 spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate;
3258 * The HDA codec on NVIDIA Tegra contains two scratch registers that are
3259 * accessed using vendor-defined verbs. These registers can be used for
3260 * interoperability between the HDA and HDMI drivers.
3263 /* Audio Function Group node */
3264 #define NVIDIA_AFG_NID 0x01
3267 * The SCRATCH0 register is used to notify the HDMI codec of changes in audio
3268 * format. On Tegra, bit 31 is used as a trigger that causes an interrupt to
3269 * be raised in the HDMI codec. The remainder of the bits is arbitrary. This
3270 * implementation stores the HDA format (see AC_FMT_*) in bits [15:0] and an
3271 * additional bit (at position 30) to signal the validity of the format.
3273 * | 31 | 30 | 29 16 | 15 0 |
3274 * +---------+-------+--------+--------+
3275 * | TRIGGER | VALID | UNUSED | FORMAT |
3276 * +-----------------------------------|
3278 * Note that for the trigger bit to take effect it needs to change value
3279 * (i.e. it needs to be toggled).
3281 #define NVIDIA_GET_SCRATCH0 0xfa6
3282 #define NVIDIA_SET_SCRATCH0_BYTE0 0xfa7
3283 #define NVIDIA_SET_SCRATCH0_BYTE1 0xfa8
3284 #define NVIDIA_SET_SCRATCH0_BYTE2 0xfa9
3285 #define NVIDIA_SET_SCRATCH0_BYTE3 0xfaa
3286 #define NVIDIA_SCRATCH_TRIGGER (1 << 7)
3287 #define NVIDIA_SCRATCH_VALID (1 << 6)
3289 #define NVIDIA_GET_SCRATCH1 0xfab
3290 #define NVIDIA_SET_SCRATCH1_BYTE0 0xfac
3291 #define NVIDIA_SET_SCRATCH1_BYTE1 0xfad
3292 #define NVIDIA_SET_SCRATCH1_BYTE2 0xfae
3293 #define NVIDIA_SET_SCRATCH1_BYTE3 0xfaf
3296 * The format parameter is the HDA audio format (see AC_FMT_*). If set to 0,
3297 * the format is invalidated so that the HDMI codec can be disabled.
3299 static void tegra_hdmi_set_format(struct hda_codec *codec, unsigned int format)
3303 /* bits [31:30] contain the trigger and valid bits */
3304 value = snd_hda_codec_read(codec, NVIDIA_AFG_NID, 0,
3305 NVIDIA_GET_SCRATCH0, 0);
3306 value = (value >> 24) & 0xff;
3308 /* bits [15:0] are used to store the HDA format */
3309 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3310 NVIDIA_SET_SCRATCH0_BYTE0,
3311 (format >> 0) & 0xff);
3312 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3313 NVIDIA_SET_SCRATCH0_BYTE1,
3314 (format >> 8) & 0xff);
3316 /* bits [16:24] are unused */
3317 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3318 NVIDIA_SET_SCRATCH0_BYTE2, 0);
3321 * Bit 30 signals that the data is valid and hence that HDMI audio can
3325 value &= ~NVIDIA_SCRATCH_VALID;
3327 value |= NVIDIA_SCRATCH_VALID;
3330 * Whenever the trigger bit is toggled, an interrupt is raised in the
3331 * HDMI codec. The HDMI driver will use that as trigger to update its
3334 value ^= NVIDIA_SCRATCH_TRIGGER;
3336 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3337 NVIDIA_SET_SCRATCH0_BYTE3, value);
3340 static int tegra_hdmi_pcm_prepare(struct hda_pcm_stream *hinfo,
3341 struct hda_codec *codec,
3342 unsigned int stream_tag,
3343 unsigned int format,
3344 struct snd_pcm_substream *substream)
3348 err = generic_hdmi_playback_pcm_prepare(hinfo, codec, stream_tag,
3353 /* notify the HDMI codec of the format change */
3354 tegra_hdmi_set_format(codec, format);
3359 static int tegra_hdmi_pcm_cleanup(struct hda_pcm_stream *hinfo,
3360 struct hda_codec *codec,
3361 struct snd_pcm_substream *substream)
3363 /* invalidate the format in the HDMI codec */
3364 tegra_hdmi_set_format(codec, 0);
3366 return generic_hdmi_playback_pcm_cleanup(hinfo, codec, substream);
3369 static struct hda_pcm *hda_find_pcm_by_type(struct hda_codec *codec, int type)
3371 struct hdmi_spec *spec = codec->spec;
3374 for (i = 0; i < spec->num_pins; i++) {
3375 struct hda_pcm *pcm = get_pcm_rec(spec, i);
3377 if (pcm->pcm_type == type)
3384 static int tegra_hdmi_build_pcms(struct hda_codec *codec)
3386 struct hda_pcm_stream *stream;
3387 struct hda_pcm *pcm;
3390 err = generic_hdmi_build_pcms(codec);
3394 pcm = hda_find_pcm_by_type(codec, HDA_PCM_TYPE_HDMI);
3399 * Override ->prepare() and ->cleanup() operations to notify the HDMI
3400 * codec about format changes.
3402 stream = &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
3403 stream->ops.prepare = tegra_hdmi_pcm_prepare;
3404 stream->ops.cleanup = tegra_hdmi_pcm_cleanup;
3409 static int patch_tegra_hdmi(struct hda_codec *codec)
3413 err = patch_generic_hdmi(codec);
3417 codec->patch_ops.build_pcms = tegra_hdmi_build_pcms;
3423 * ATI/AMD-specific implementations
3426 #define is_amdhdmi_rev3_or_later(codec) \
3427 ((codec)->core.vendor_id == 0x1002aa01 && \
3428 ((codec)->core.revision_id & 0xff00) >= 0x0300)
3429 #define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec)
3431 /* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */
3432 #define ATI_VERB_SET_CHANNEL_ALLOCATION 0x771
3433 #define ATI_VERB_SET_DOWNMIX_INFO 0x772
3434 #define ATI_VERB_SET_MULTICHANNEL_01 0x777
3435 #define ATI_VERB_SET_MULTICHANNEL_23 0x778
3436 #define ATI_VERB_SET_MULTICHANNEL_45 0x779
3437 #define ATI_VERB_SET_MULTICHANNEL_67 0x77a
3438 #define ATI_VERB_SET_HBR_CONTROL 0x77c
3439 #define ATI_VERB_SET_MULTICHANNEL_1 0x785
3440 #define ATI_VERB_SET_MULTICHANNEL_3 0x786
3441 #define ATI_VERB_SET_MULTICHANNEL_5 0x787
3442 #define ATI_VERB_SET_MULTICHANNEL_7 0x788
3443 #define ATI_VERB_SET_MULTICHANNEL_MODE 0x789
3444 #define ATI_VERB_GET_CHANNEL_ALLOCATION 0xf71
3445 #define ATI_VERB_GET_DOWNMIX_INFO 0xf72
3446 #define ATI_VERB_GET_MULTICHANNEL_01 0xf77
3447 #define ATI_VERB_GET_MULTICHANNEL_23 0xf78
3448 #define ATI_VERB_GET_MULTICHANNEL_45 0xf79
3449 #define ATI_VERB_GET_MULTICHANNEL_67 0xf7a
3450 #define ATI_VERB_GET_HBR_CONTROL 0xf7c
3451 #define ATI_VERB_GET_MULTICHANNEL_1 0xf85
3452 #define ATI_VERB_GET_MULTICHANNEL_3 0xf86
3453 #define ATI_VERB_GET_MULTICHANNEL_5 0xf87
3454 #define ATI_VERB_GET_MULTICHANNEL_7 0xf88
3455 #define ATI_VERB_GET_MULTICHANNEL_MODE 0xf89
3457 /* AMD specific HDA cvt verbs */
3458 #define ATI_VERB_SET_RAMP_RATE 0x770
3459 #define ATI_VERB_GET_RAMP_RATE 0xf70
3461 #define ATI_OUT_ENABLE 0x1
3463 #define ATI_MULTICHANNEL_MODE_PAIRED 0
3464 #define ATI_MULTICHANNEL_MODE_SINGLE 1
3466 #define ATI_HBR_CAPABLE 0x01
3467 #define ATI_HBR_ENABLE 0x10
3469 static int atihdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
3470 unsigned char *buf, int *eld_size)
3472 /* call hda_eld.c ATI/AMD-specific function */
3473 return snd_hdmi_get_eld_ati(codec, nid, buf, eld_size,
3474 is_amdhdmi_rev3_or_later(codec));
3477 static void atihdmi_pin_setup_infoframe(struct hda_codec *codec, hda_nid_t pin_nid, int ca,
3478 int active_channels, int conn_type)
3480 snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_CHANNEL_ALLOCATION, ca);
3483 static int atihdmi_paired_swap_fc_lfe(int pos)
3486 * ATI/AMD have automatic FC/LFE swap built-in
3487 * when in pairwise mapping mode.
3491 /* see channel_allocations[].speakers[] */
3500 static int atihdmi_paired_chmap_validate(struct hdac_chmap *chmap,
3501 int ca, int chs, unsigned char *map)
3503 struct hdac_cea_channel_speaker_allocation *cap;
3506 /* check that only channel pairs need to be remapped on old pre-rev3 ATI/AMD */
3508 cap = snd_hdac_get_ch_alloc_from_ca(ca);
3509 for (i = 0; i < chs; ++i) {
3510 int mask = snd_hdac_chmap_to_spk_mask(map[i]);
3512 bool companion_ok = false;
3517 for (j = 0 + i % 2; j < 8; j += 2) {
3518 int chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j);
3519 if (cap->speakers[chan_idx] == mask) {
3520 /* channel is in a supported position */
3523 if (i % 2 == 0 && i + 1 < chs) {
3524 /* even channel, check the odd companion */
3525 int comp_chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j + 1);
3526 int comp_mask_req = snd_hdac_chmap_to_spk_mask(map[i+1]);
3527 int comp_mask_act = cap->speakers[comp_chan_idx];
3529 if (comp_mask_req == comp_mask_act)
3530 companion_ok = true;
3542 i++; /* companion channel already checked */
3548 static int atihdmi_pin_set_slot_channel(struct hdac_device *hdac,
3549 hda_nid_t pin_nid, int hdmi_slot, int stream_channel)
3551 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
3553 int ati_channel_setup = 0;
3558 if (!has_amd_full_remap_support(codec)) {
3559 hdmi_slot = atihdmi_paired_swap_fc_lfe(hdmi_slot);
3561 /* In case this is an odd slot but without stream channel, do not
3562 * disable the slot since the corresponding even slot could have a
3563 * channel. In case neither have a channel, the slot pair will be
3564 * disabled when this function is called for the even slot. */
3565 if (hdmi_slot % 2 != 0 && stream_channel == 0xf)
3568 hdmi_slot -= hdmi_slot % 2;
3570 if (stream_channel != 0xf)
3571 stream_channel -= stream_channel % 2;
3574 verb = ATI_VERB_SET_MULTICHANNEL_01 + hdmi_slot/2 + (hdmi_slot % 2) * 0x00e;
3576 /* ati_channel_setup format: [7..4] = stream_channel_id, [1] = mute, [0] = enable */
3578 if (stream_channel != 0xf)
3579 ati_channel_setup = (stream_channel << 4) | ATI_OUT_ENABLE;
3581 return snd_hda_codec_write(codec, pin_nid, 0, verb, ati_channel_setup);
3584 static int atihdmi_pin_get_slot_channel(struct hdac_device *hdac,
3585 hda_nid_t pin_nid, int asp_slot)
3587 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
3588 bool was_odd = false;
3589 int ati_asp_slot = asp_slot;
3591 int ati_channel_setup;
3596 if (!has_amd_full_remap_support(codec)) {
3597 ati_asp_slot = atihdmi_paired_swap_fc_lfe(asp_slot);
3598 if (ati_asp_slot % 2 != 0) {
3604 verb = ATI_VERB_GET_MULTICHANNEL_01 + ati_asp_slot/2 + (ati_asp_slot % 2) * 0x00e;
3606 ati_channel_setup = snd_hda_codec_read(codec, pin_nid, 0, verb, 0);
3608 if (!(ati_channel_setup & ATI_OUT_ENABLE))
3611 return ((ati_channel_setup & 0xf0) >> 4) + !!was_odd;
3614 static int atihdmi_paired_chmap_cea_alloc_validate_get_type(
3615 struct hdac_chmap *chmap,
3616 struct hdac_cea_channel_speaker_allocation *cap,
3622 * Pre-rev3 ATI/AMD codecs operate in a paired channel mode, so
3623 * we need to take that into account (a single channel may take 2
3624 * channel slots if we need to carry a silent channel next to it).
3625 * On Rev3+ AMD codecs this function is not used.
3629 /* We only produce even-numbered channel count TLVs */
3630 if ((channels % 2) != 0)
3633 for (c = 0; c < 7; c += 2) {
3634 if (cap->speakers[c] || cap->speakers[c+1])
3638 if (chanpairs * 2 != channels)
3641 return SNDRV_CTL_TLVT_CHMAP_PAIRED;
3644 static void atihdmi_paired_cea_alloc_to_tlv_chmap(struct hdac_chmap *hchmap,
3645 struct hdac_cea_channel_speaker_allocation *cap,
3646 unsigned int *chmap, int channels)
3648 /* produce paired maps for pre-rev3 ATI/AMD codecs */
3652 for (c = 7; c >= 0; c--) {
3653 int chan = 7 - atihdmi_paired_swap_fc_lfe(7 - c);
3654 int spk = cap->speakers[chan];
3656 /* add N/A channel if the companion channel is occupied */
3657 if (cap->speakers[chan + (chan % 2 ? -1 : 1)])
3658 chmap[count++] = SNDRV_CHMAP_NA;
3663 chmap[count++] = snd_hdac_spk_to_chmap(spk);
3666 WARN_ON(count != channels);
3669 static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
3672 int hbr_ctl, hbr_ctl_new;
3674 hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0);
3675 if (hbr_ctl >= 0 && (hbr_ctl & ATI_HBR_CAPABLE)) {
3677 hbr_ctl_new = hbr_ctl | ATI_HBR_ENABLE;
3679 hbr_ctl_new = hbr_ctl & ~ATI_HBR_ENABLE;
3682 "atihdmi_pin_hbr_setup: NID=0x%x, %shbr-ctl=0x%x\n",
3684 hbr_ctl == hbr_ctl_new ? "" : "new-",
3687 if (hbr_ctl != hbr_ctl_new)
3688 snd_hda_codec_write(codec, pin_nid, 0,
3689 ATI_VERB_SET_HBR_CONTROL,
3698 static int atihdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
3699 hda_nid_t pin_nid, u32 stream_tag, int format)
3702 if (is_amdhdmi_rev3_or_later(codec)) {
3703 int ramp_rate = 180; /* default as per AMD spec */
3704 /* disable ramp-up/down for non-pcm as per AMD spec */
3705 if (format & AC_FMT_TYPE_NON_PCM)
3708 snd_hda_codec_write(codec, cvt_nid, 0, ATI_VERB_SET_RAMP_RATE, ramp_rate);
3711 return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
3715 static int atihdmi_init(struct hda_codec *codec)
3717 struct hdmi_spec *spec = codec->spec;
3720 err = generic_hdmi_init(codec);
3725 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
3726 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
3728 /* make sure downmix information in infoframe is zero */
3729 snd_hda_codec_write(codec, per_pin->pin_nid, 0, ATI_VERB_SET_DOWNMIX_INFO, 0);
3731 /* enable channel-wise remap mode if supported */
3732 if (has_amd_full_remap_support(codec))
3733 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
3734 ATI_VERB_SET_MULTICHANNEL_MODE,
3735 ATI_MULTICHANNEL_MODE_SINGLE);
3741 static int patch_atihdmi(struct hda_codec *codec)
3743 struct hdmi_spec *spec;
3744 struct hdmi_spec_per_cvt *per_cvt;
3747 err = patch_generic_hdmi(codec);
3752 codec->patch_ops.init = atihdmi_init;
3756 spec->ops.pin_get_eld = atihdmi_pin_get_eld;
3757 spec->ops.pin_setup_infoframe = atihdmi_pin_setup_infoframe;
3758 spec->ops.pin_hbr_setup = atihdmi_pin_hbr_setup;
3759 spec->ops.setup_stream = atihdmi_setup_stream;
3761 spec->chmap.ops.pin_get_slot_channel = atihdmi_pin_get_slot_channel;
3762 spec->chmap.ops.pin_set_slot_channel = atihdmi_pin_set_slot_channel;
3764 if (!has_amd_full_remap_support(codec)) {
3765 /* override to ATI/AMD-specific versions with pairwise mapping */
3766 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
3767 atihdmi_paired_chmap_cea_alloc_validate_get_type;
3768 spec->chmap.ops.cea_alloc_to_tlv_chmap =
3769 atihdmi_paired_cea_alloc_to_tlv_chmap;
3770 spec->chmap.ops.chmap_validate = atihdmi_paired_chmap_validate;
3773 /* ATI/AMD converters do not advertise all of their capabilities */
3774 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
3775 per_cvt = get_cvt(spec, cvt_idx);
3776 per_cvt->channels_max = max(per_cvt->channels_max, 8u);
3777 per_cvt->rates |= SUPPORTED_RATES;
3778 per_cvt->formats |= SUPPORTED_FORMATS;
3779 per_cvt->maxbps = max(per_cvt->maxbps, 24u);
3782 spec->chmap.channels_max = max(spec->chmap.channels_max, 8u);
3784 /* AMD GPUs have neither EPSS nor CLKSTOP bits, hence preventing
3785 * the link-down as is. Tell the core to allow it.
3787 codec->link_down_at_suspend = 1;
3792 /* VIA HDMI Implementation */
3793 #define VIAHDMI_CVT_NID 0x02 /* audio converter1 */
3794 #define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */
3796 static int patch_via_hdmi(struct hda_codec *codec)
3798 return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
3804 static const struct hda_device_id snd_hda_id_hdmi[] = {
3805 HDA_CODEC_ENTRY(0x1002793c, "RS600 HDMI", patch_atihdmi),
3806 HDA_CODEC_ENTRY(0x10027919, "RS600 HDMI", patch_atihdmi),
3807 HDA_CODEC_ENTRY(0x1002791a, "RS690/780 HDMI", patch_atihdmi),
3808 HDA_CODEC_ENTRY(0x1002aa01, "R6xx HDMI", patch_atihdmi),
3809 HDA_CODEC_ENTRY(0x10951390, "SiI1390 HDMI", patch_generic_hdmi),
3810 HDA_CODEC_ENTRY(0x10951392, "SiI1392 HDMI", patch_generic_hdmi),
3811 HDA_CODEC_ENTRY(0x17e80047, "Chrontel HDMI", patch_generic_hdmi),
3812 HDA_CODEC_ENTRY(0x10de0001, "MCP73 HDMI", patch_nvhdmi_2ch),
3813 HDA_CODEC_ENTRY(0x10de0002, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3814 HDA_CODEC_ENTRY(0x10de0003, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3815 HDA_CODEC_ENTRY(0x10de0004, "GPU 04 HDMI", patch_nvhdmi_8ch_7x),
3816 HDA_CODEC_ENTRY(0x10de0005, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3817 HDA_CODEC_ENTRY(0x10de0006, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3818 HDA_CODEC_ENTRY(0x10de0007, "MCP79/7A HDMI", patch_nvhdmi_8ch_7x),
3819 HDA_CODEC_ENTRY(0x10de0008, "GPU 08 HDMI/DP", patch_nvhdmi),
3820 HDA_CODEC_ENTRY(0x10de0009, "GPU 09 HDMI/DP", patch_nvhdmi),
3821 HDA_CODEC_ENTRY(0x10de000a, "GPU 0a HDMI/DP", patch_nvhdmi),
3822 HDA_CODEC_ENTRY(0x10de000b, "GPU 0b HDMI/DP", patch_nvhdmi),
3823 HDA_CODEC_ENTRY(0x10de000c, "MCP89 HDMI", patch_nvhdmi),
3824 HDA_CODEC_ENTRY(0x10de000d, "GPU 0d HDMI/DP", patch_nvhdmi),
3825 HDA_CODEC_ENTRY(0x10de0010, "GPU 10 HDMI/DP", patch_nvhdmi),
3826 HDA_CODEC_ENTRY(0x10de0011, "GPU 11 HDMI/DP", patch_nvhdmi),
3827 HDA_CODEC_ENTRY(0x10de0012, "GPU 12 HDMI/DP", patch_nvhdmi),
3828 HDA_CODEC_ENTRY(0x10de0013, "GPU 13 HDMI/DP", patch_nvhdmi),
3829 HDA_CODEC_ENTRY(0x10de0014, "GPU 14 HDMI/DP", patch_nvhdmi),
3830 HDA_CODEC_ENTRY(0x10de0015, "GPU 15 HDMI/DP", patch_nvhdmi),
3831 HDA_CODEC_ENTRY(0x10de0016, "GPU 16 HDMI/DP", patch_nvhdmi),
3832 /* 17 is known to be absent */
3833 HDA_CODEC_ENTRY(0x10de0018, "GPU 18 HDMI/DP", patch_nvhdmi),
3834 HDA_CODEC_ENTRY(0x10de0019, "GPU 19 HDMI/DP", patch_nvhdmi),
3835 HDA_CODEC_ENTRY(0x10de001a, "GPU 1a HDMI/DP", patch_nvhdmi),
3836 HDA_CODEC_ENTRY(0x10de001b, "GPU 1b HDMI/DP", patch_nvhdmi),
3837 HDA_CODEC_ENTRY(0x10de001c, "GPU 1c HDMI/DP", patch_nvhdmi),
3838 HDA_CODEC_ENTRY(0x10de0020, "Tegra30 HDMI", patch_tegra_hdmi),
3839 HDA_CODEC_ENTRY(0x10de0022, "Tegra114 HDMI", patch_tegra_hdmi),
3840 HDA_CODEC_ENTRY(0x10de0028, "Tegra124 HDMI", patch_tegra_hdmi),
3841 HDA_CODEC_ENTRY(0x10de0029, "Tegra210 HDMI/DP", patch_tegra_hdmi),
3842 HDA_CODEC_ENTRY(0x10de0040, "GPU 40 HDMI/DP", patch_nvhdmi),
3843 HDA_CODEC_ENTRY(0x10de0041, "GPU 41 HDMI/DP", patch_nvhdmi),
3844 HDA_CODEC_ENTRY(0x10de0042, "GPU 42 HDMI/DP", patch_nvhdmi),
3845 HDA_CODEC_ENTRY(0x10de0043, "GPU 43 HDMI/DP", patch_nvhdmi),
3846 HDA_CODEC_ENTRY(0x10de0044, "GPU 44 HDMI/DP", patch_nvhdmi),
3847 HDA_CODEC_ENTRY(0x10de0045, "GPU 45 HDMI/DP", patch_nvhdmi),
3848 HDA_CODEC_ENTRY(0x10de0050, "GPU 50 HDMI/DP", patch_nvhdmi),
3849 HDA_CODEC_ENTRY(0x10de0051, "GPU 51 HDMI/DP", patch_nvhdmi),
3850 HDA_CODEC_ENTRY(0x10de0052, "GPU 52 HDMI/DP", patch_nvhdmi),
3851 HDA_CODEC_ENTRY(0x10de0060, "GPU 60 HDMI/DP", patch_nvhdmi),
3852 HDA_CODEC_ENTRY(0x10de0061, "GPU 61 HDMI/DP", patch_nvhdmi),
3853 HDA_CODEC_ENTRY(0x10de0062, "GPU 62 HDMI/DP", patch_nvhdmi),
3854 HDA_CODEC_ENTRY(0x10de0067, "MCP67 HDMI", patch_nvhdmi_2ch),
3855 HDA_CODEC_ENTRY(0x10de0070, "GPU 70 HDMI/DP", patch_nvhdmi),
3856 HDA_CODEC_ENTRY(0x10de0071, "GPU 71 HDMI/DP", patch_nvhdmi),
3857 HDA_CODEC_ENTRY(0x10de0072, "GPU 72 HDMI/DP", patch_nvhdmi),
3858 HDA_CODEC_ENTRY(0x10de0073, "GPU 73 HDMI/DP", patch_nvhdmi),
3859 HDA_CODEC_ENTRY(0x10de0074, "GPU 74 HDMI/DP", patch_nvhdmi),
3860 HDA_CODEC_ENTRY(0x10de0076, "GPU 76 HDMI/DP", patch_nvhdmi),
3861 HDA_CODEC_ENTRY(0x10de007b, "GPU 7b HDMI/DP", patch_nvhdmi),
3862 HDA_CODEC_ENTRY(0x10de007c, "GPU 7c HDMI/DP", patch_nvhdmi),
3863 HDA_CODEC_ENTRY(0x10de007d, "GPU 7d HDMI/DP", patch_nvhdmi),
3864 HDA_CODEC_ENTRY(0x10de007e, "GPU 7e HDMI/DP", patch_nvhdmi),
3865 HDA_CODEC_ENTRY(0x10de0080, "GPU 80 HDMI/DP", patch_nvhdmi),
3866 HDA_CODEC_ENTRY(0x10de0081, "GPU 81 HDMI/DP", patch_nvhdmi),
3867 HDA_CODEC_ENTRY(0x10de0082, "GPU 82 HDMI/DP", patch_nvhdmi),
3868 HDA_CODEC_ENTRY(0x10de0083, "GPU 83 HDMI/DP", patch_nvhdmi),
3869 HDA_CODEC_ENTRY(0x10de0084, "GPU 84 HDMI/DP", patch_nvhdmi),
3870 HDA_CODEC_ENTRY(0x10de0090, "GPU 90 HDMI/DP", patch_nvhdmi),
3871 HDA_CODEC_ENTRY(0x10de0091, "GPU 91 HDMI/DP", patch_nvhdmi),
3872 HDA_CODEC_ENTRY(0x10de0092, "GPU 92 HDMI/DP", patch_nvhdmi),
3873 HDA_CODEC_ENTRY(0x10de0093, "GPU 93 HDMI/DP", patch_nvhdmi),
3874 HDA_CODEC_ENTRY(0x10de0094, "GPU 94 HDMI/DP", patch_nvhdmi),
3875 HDA_CODEC_ENTRY(0x10de0095, "GPU 95 HDMI/DP", patch_nvhdmi),
3876 HDA_CODEC_ENTRY(0x10de0097, "GPU 97 HDMI/DP", patch_nvhdmi),
3877 HDA_CODEC_ENTRY(0x10de0098, "GPU 98 HDMI/DP", patch_nvhdmi),
3878 HDA_CODEC_ENTRY(0x10de0099, "GPU 99 HDMI/DP", patch_nvhdmi),
3879 HDA_CODEC_ENTRY(0x10de8001, "MCP73 HDMI", patch_nvhdmi_2ch),
3880 HDA_CODEC_ENTRY(0x10de8067, "MCP67/68 HDMI", patch_nvhdmi_2ch),
3881 HDA_CODEC_ENTRY(0x11069f80, "VX900 HDMI/DP", patch_via_hdmi),
3882 HDA_CODEC_ENTRY(0x11069f81, "VX900 HDMI/DP", patch_via_hdmi),
3883 HDA_CODEC_ENTRY(0x11069f84, "VX11 HDMI/DP", patch_generic_hdmi),
3884 HDA_CODEC_ENTRY(0x11069f85, "VX11 HDMI/DP", patch_generic_hdmi),
3885 HDA_CODEC_ENTRY(0x80860054, "IbexPeak HDMI", patch_i915_cpt_hdmi),
3886 HDA_CODEC_ENTRY(0x80862801, "Bearlake HDMI", patch_generic_hdmi),
3887 HDA_CODEC_ENTRY(0x80862802, "Cantiga HDMI", patch_generic_hdmi),
3888 HDA_CODEC_ENTRY(0x80862803, "Eaglelake HDMI", patch_generic_hdmi),
3889 HDA_CODEC_ENTRY(0x80862804, "IbexPeak HDMI", patch_i915_cpt_hdmi),
3890 HDA_CODEC_ENTRY(0x80862805, "CougarPoint HDMI", patch_i915_cpt_hdmi),
3891 HDA_CODEC_ENTRY(0x80862806, "PantherPoint HDMI", patch_i915_cpt_hdmi),
3892 HDA_CODEC_ENTRY(0x80862807, "Haswell HDMI", patch_i915_hsw_hdmi),
3893 HDA_CODEC_ENTRY(0x80862808, "Broadwell HDMI", patch_i915_hsw_hdmi),
3894 HDA_CODEC_ENTRY(0x80862809, "Skylake HDMI", patch_i915_hsw_hdmi),
3895 HDA_CODEC_ENTRY(0x8086280a, "Broxton HDMI", patch_i915_hsw_hdmi),
3896 HDA_CODEC_ENTRY(0x8086280b, "Kabylake HDMI", patch_i915_hsw_hdmi),
3897 HDA_CODEC_ENTRY(0x8086280c, "Cannonlake HDMI", patch_i915_glk_hdmi),
3898 HDA_CODEC_ENTRY(0x8086280d, "Geminilake HDMI", patch_i915_glk_hdmi),
3899 HDA_CODEC_ENTRY(0x80862800, "Geminilake HDMI", patch_i915_glk_hdmi),
3900 HDA_CODEC_ENTRY(0x80862880, "CedarTrail HDMI", patch_generic_hdmi),
3901 HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_i915_byt_hdmi),
3902 HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_i915_byt_hdmi),
3903 HDA_CODEC_ENTRY(0x808629fb, "Crestline HDMI", patch_generic_hdmi),
3904 /* special ID for generic HDMI */
3905 HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC_HDMI, "Generic HDMI", patch_generic_hdmi),
3908 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_hdmi);
3910 MODULE_LICENSE("GPL");
3911 MODULE_DESCRIPTION("HDMI HD-audio codec");
3912 MODULE_ALIAS("snd-hda-codec-intelhdmi");
3913 MODULE_ALIAS("snd-hda-codec-nvhdmi");
3914 MODULE_ALIAS("snd-hda-codec-atihdmi");
3916 static struct hda_codec_driver hdmi_driver = {
3917 .id = snd_hda_id_hdmi,
3920 module_hda_codec_driver(hdmi_driver);