3 * patch_hdmi.c - routines for HDMI/DisplayPort codecs
5 * Copyright(c) 2008-2010 Intel Corporation. All rights reserved.
8 * Wu Fengguang <wfg@linux.intel.com>
11 * Wu Fengguang <wfg@linux.intel.com>
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software Foundation,
25 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 hda_nid_t cvt[MAX_HDMI_CVTS+1]; /* audio sources */
33 hda_nid_t pin[MAX_HDMI_PINS+1]; /* audio sinks */
36 * source connection for each pin
38 hda_nid_t pin_cvt[MAX_HDMI_PINS+1];
41 * HDMI sink attached to each pin
43 struct hdmi_eld sink_eld[MAX_HDMI_PINS];
46 * export one pcm per pipe
48 struct hda_pcm pcm_rec[MAX_HDMI_CVTS];
53 struct hda_multi_out multiout;
54 unsigned int codec_type;
57 /* PD bit indicates only the update, not the current state */
58 unsigned int old_pin_detect:1;
62 struct hdmi_audio_infoframe {
67 u8 checksum; /* PB0 */
68 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
72 u8 LFEPBL01_LSV36_DM_INH7;
73 u8 reserved[5]; /* PB6 - PB10 */
77 * CEA speaker placement:
80 * FLW FL FLC FC FRC FR FRW
87 * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
88 * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
90 enum cea_speaker_placement {
91 FL = (1 << 0), /* Front Left */
92 FC = (1 << 1), /* Front Center */
93 FR = (1 << 2), /* Front Right */
94 FLC = (1 << 3), /* Front Left Center */
95 FRC = (1 << 4), /* Front Right Center */
96 RL = (1 << 5), /* Rear Left */
97 RC = (1 << 6), /* Rear Center */
98 RR = (1 << 7), /* Rear Right */
99 RLC = (1 << 8), /* Rear Left Center */
100 RRC = (1 << 9), /* Rear Right Center */
101 LFE = (1 << 10), /* Low Frequency Effect */
102 FLW = (1 << 11), /* Front Left Wide */
103 FRW = (1 << 12), /* Front Right Wide */
104 FLH = (1 << 13), /* Front Left High */
105 FCH = (1 << 14), /* Front Center High */
106 FRH = (1 << 15), /* Front Right High */
107 TC = (1 << 16), /* Top Center */
111 * ELD SA bits in the CEA Speaker Allocation data block
113 static int eld_speaker_allocation_bits[] = {
121 /* the following are not defined in ELD yet */
128 struct cea_channel_speaker_allocation {
132 /* derived values, just for convenience */
140 * surround40 surround41 surround50 surround51 surround71
141 * ch0 front left = = = =
142 * ch1 front right = = = =
143 * ch2 rear left = = = =
144 * ch3 rear right = = = =
145 * ch4 LFE center center center
150 * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR}
152 static int hdmi_channel_mapping[0x32][8] = {
154 [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
156 [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
158 [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 },
160 [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 },
162 [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 },
164 [0x09] = { 0x00, 0x11, 0x24, 0x34, 0x43, 0xf2, 0xf6, 0xf7 },
166 [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 },
168 [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 },
170 [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 },
174 * This is an ordered list!
176 * The preceding ones have better chances to be selected by
177 * hdmi_setup_channel_allocation().
179 static struct cea_channel_speaker_allocation channel_allocations[] = {
180 /* channel: 7 6 5 4 3 2 1 0 */
181 { .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
183 { .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
185 { .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
187 { .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
189 { .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
191 { .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
193 { .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
195 { .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
197 { .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
199 { .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
200 { .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
201 { .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
202 { .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
203 { .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
204 { .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
205 { .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
206 { .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
207 { .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
208 { .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
209 { .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
210 { .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
211 { .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
212 { .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
213 { .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
214 { .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
215 { .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
216 { .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
217 { .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
218 { .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
219 { .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
220 { .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
221 { .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
222 { .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } },
223 { .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } },
224 { .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } },
225 { .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } },
226 { .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } },
227 { .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } },
228 { .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } },
229 { .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } },
230 { .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } },
231 { .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } },
232 { .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } },
233 { .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } },
234 { .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } },
235 { .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } },
236 { .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } },
237 { .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } },
238 { .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } },
239 { .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
247 static int hda_node_index(hda_nid_t *nids, hda_nid_t nid)
251 for (i = 0; nids[i]; i++)
255 snd_printk(KERN_WARNING "HDMI: nid %d not registered\n", nid);
259 static void hdmi_get_show_eld(struct hda_codec *codec, hda_nid_t pin_nid,
260 struct hdmi_eld *eld)
262 if (!snd_hdmi_get_eld(eld, codec, pin_nid))
263 snd_hdmi_show_eld(eld);
267 static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
268 int *packet_index, int *byte_index)
272 val = snd_hda_codec_read(codec, pin_nid, 0,
273 AC_VERB_GET_HDMI_DIP_INDEX, 0);
275 *packet_index = val >> 5;
276 *byte_index = val & 0x1f;
280 static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
281 int packet_index, int byte_index)
285 val = (packet_index << 5) | (byte_index & 0x1f);
287 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
290 static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
293 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
296 static void hdmi_enable_output(struct hda_codec *codec, hda_nid_t pin_nid)
299 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
300 snd_hda_codec_write(codec, pin_nid, 0,
301 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
303 snd_hda_codec_write(codec, pin_nid, 0,
304 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
307 static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t nid)
309 return 1 + snd_hda_codec_read(codec, nid, 0,
310 AC_VERB_GET_CVT_CHAN_COUNT, 0);
313 static void hdmi_set_channel_count(struct hda_codec *codec,
314 hda_nid_t nid, int chs)
316 if (chs != hdmi_get_channel_count(codec, nid))
317 snd_hda_codec_write(codec, nid, 0,
318 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
323 * Channel mapping routines
327 * Compute derived values in channel_allocations[].
329 static void init_channel_allocations(void)
332 struct cea_channel_speaker_allocation *p;
334 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
335 p = channel_allocations + i;
338 for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
339 if (p->speakers[j]) {
341 p->spk_mask |= p->speakers[j];
347 * The transformation takes two steps:
349 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
350 * spk_mask => (channel_allocations[]) => ai->CA
352 * TODO: it could select the wrong CA from multiple candidates.
354 static int hdmi_setup_channel_allocation(struct hda_codec *codec, hda_nid_t nid,
355 struct hdmi_audio_infoframe *ai)
357 struct hdmi_spec *spec = codec->spec;
358 struct hdmi_eld *eld;
361 int channels = 1 + (ai->CC02_CT47 & 0x7);
362 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
365 * CA defaults to 0 for basic stereo audio
370 i = hda_node_index(spec->pin_cvt, nid);
373 eld = &spec->sink_eld[i];
376 * HDMI sink's ELD info cannot always be retrieved for now, e.g.
377 * in console or for audio devices. Assume the highest speakers
378 * configuration, to _not_ prohibit multi-channel audio playback.
381 eld->spk_alloc = 0xffff;
384 * expand ELD's speaker allocation mask
386 * ELD tells the speaker mask in a compact(paired) form,
387 * expand ELD's notions to match the ones used by Audio InfoFrame.
389 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
390 if (eld->spk_alloc & (1 << i))
391 spk_mask |= eld_speaker_allocation_bits[i];
394 /* search for the first working match in the CA table */
395 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
396 if (channels == channel_allocations[i].channels &&
397 (spk_mask & channel_allocations[i].spk_mask) ==
398 channel_allocations[i].spk_mask) {
399 ai->CA = channel_allocations[i].ca_index;
404 snd_print_channel_allocation(eld->spk_alloc, buf, sizeof(buf));
405 snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n",
406 ai->CA, channels, buf);
411 static void hdmi_debug_channel_mapping(struct hda_codec *codec,
414 #ifdef CONFIG_SND_DEBUG_VERBOSE
418 for (i = 0; i < 8; i++) {
419 slot = snd_hda_codec_read(codec, pin_nid, 0,
420 AC_VERB_GET_HDMI_CHAN_SLOT, i);
421 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n",
422 slot >> 4, slot & 0xf);
428 static void hdmi_setup_channel_mapping(struct hda_codec *codec,
430 struct hdmi_audio_infoframe *ai)
436 if (hdmi_channel_mapping[ca][1] == 0) {
437 for (i = 0; i < channel_allocations[ca].channels; i++)
438 hdmi_channel_mapping[ca][i] = i | (i << 4);
440 hdmi_channel_mapping[ca][i] = 0xf | (i << 4);
443 for (i = 0; i < 8; i++) {
444 err = snd_hda_codec_write(codec, pin_nid, 0,
445 AC_VERB_SET_HDMI_CHAN_SLOT,
446 hdmi_channel_mapping[ca][i]);
448 snd_printdd(KERN_NOTICE
449 "HDMI: channel mapping failed\n");
454 hdmi_debug_channel_mapping(codec, pin_nid);
459 * Audio InfoFrame routines
463 * Enable Audio InfoFrame Transmission
465 static void hdmi_start_infoframe_trans(struct hda_codec *codec,
468 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
469 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
474 * Disable Audio InfoFrame Transmission
476 static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
479 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
480 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
484 static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
486 #ifdef CONFIG_SND_DEBUG_VERBOSE
490 size = snd_hdmi_get_eld_size(codec, pin_nid);
491 printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size);
493 for (i = 0; i < 8; i++) {
494 size = snd_hda_codec_read(codec, pin_nid, 0,
495 AC_VERB_GET_HDMI_DIP_SIZE, i);
496 printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size);
501 static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
507 for (i = 0; i < 8; i++) {
508 size = snd_hda_codec_read(codec, pin_nid, 0,
509 AC_VERB_GET_HDMI_DIP_SIZE, i);
513 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
514 for (j = 1; j < 1000; j++) {
515 hdmi_write_dip_byte(codec, pin_nid, 0x0);
516 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
518 snd_printd(KERN_INFO "dip index %d: %d != %d\n",
520 if (bi == 0) /* byte index wrapped around */
524 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
530 static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *ai)
532 u8 *bytes = (u8 *)ai;
538 for (i = 0; i < sizeof(*ai); i++)
544 static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
546 struct hdmi_audio_infoframe *ai)
548 u8 *bytes = (u8 *)ai;
551 hdmi_debug_dip_size(codec, pin_nid);
552 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
554 hdmi_checksum_audio_infoframe(ai);
556 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
557 for (i = 0; i < sizeof(*ai); i++)
558 hdmi_write_dip_byte(codec, pin_nid, bytes[i]);
561 static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
562 struct hdmi_audio_infoframe *ai)
564 u8 *bytes = (u8 *)ai;
568 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
572 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
573 for (i = 0; i < sizeof(*ai); i++) {
574 val = snd_hda_codec_read(codec, pin_nid, 0,
575 AC_VERB_GET_HDMI_DIP_DATA, 0);
583 static void hdmi_setup_audio_infoframe(struct hda_codec *codec, hda_nid_t nid,
584 struct snd_pcm_substream *substream)
586 struct hdmi_spec *spec = codec->spec;
589 struct hdmi_audio_infoframe ai = {
593 .CC02_CT47 = substream->runtime->channels - 1,
596 hdmi_setup_channel_allocation(codec, nid, &ai);
598 for (i = 0; i < spec->num_pins; i++) {
599 if (spec->pin_cvt[i] != nid)
601 if (!spec->sink_eld[i].monitor_present)
604 pin_nid = spec->pin[i];
605 if (!hdmi_infoframe_uptodate(codec, pin_nid, &ai)) {
606 snd_printdd("hdmi_setup_audio_infoframe: "
607 "cvt=%d pin=%d channels=%d\n",
609 substream->runtime->channels);
610 hdmi_setup_channel_mapping(codec, pin_nid, &ai);
611 hdmi_stop_infoframe_trans(codec, pin_nid);
612 hdmi_fill_audio_infoframe(codec, pin_nid, &ai);
613 hdmi_start_infoframe_trans(codec, pin_nid);
623 static void hdmi_present_sense(struct hda_codec *codec, hda_nid_t pin_nid,
624 struct hdmi_eld *eld);
626 static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
628 struct hdmi_spec *spec = codec->spec;
629 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
630 int pind = !!(res & AC_UNSOL_RES_PD);
631 int eldv = !!(res & AC_UNSOL_RES_ELDV);
635 "HDMI hot plug event: Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
638 index = hda_node_index(spec->pin, tag);
642 if (spec->old_pin_detect) {
644 hdmi_present_sense(codec, tag, &spec->sink_eld[index]);
645 pind = spec->sink_eld[index].monitor_present;
648 spec->sink_eld[index].monitor_present = pind;
649 spec->sink_eld[index].eld_valid = eldv;
652 hdmi_get_show_eld(codec, spec->pin[index],
653 &spec->sink_eld[index]);
654 /* TODO: do real things about ELD */
658 static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
660 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
661 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
662 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
663 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
666 "HDMI CP event: PIN=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
680 static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
682 struct hdmi_spec *spec = codec->spec;
683 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
684 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
686 if (hda_node_index(spec->pin, tag) < 0) {
687 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag);
692 hdmi_intrinsic_event(codec, res);
694 hdmi_non_intrinsic_event(codec, res);
701 static void hdmi_setup_stream(struct hda_codec *codec, hda_nid_t nid,
702 u32 stream_tag, int format)
707 tag = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0) >> 4;
708 fmt = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_STREAM_FORMAT, 0);
710 snd_printdd("hdmi_setup_stream: "
711 "NID=0x%x, %sstream=0x%x, %sformat=0x%x\n",
713 tag == stream_tag ? "" : "new-",
715 fmt == format ? "" : "new-",
718 if (tag != stream_tag)
719 snd_hda_codec_write(codec, nid, 0,
720 AC_VERB_SET_CHANNEL_STREAMID,
723 snd_hda_codec_write(codec, nid, 0,
724 AC_VERB_SET_STREAM_FORMAT, format);
728 * HDA/HDMI auto parsing
731 static int hdmi_read_pin_conn(struct hda_codec *codec, hda_nid_t pin_nid)
733 struct hdmi_spec *spec = codec->spec;
734 hda_nid_t conn_list[HDA_MAX_CONNECTIONS];
738 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
739 snd_printk(KERN_WARNING
740 "HDMI: pin %d wcaps %#x "
741 "does not support connection list\n",
742 pin_nid, get_wcaps(codec, pin_nid));
746 conn_len = snd_hda_get_connections(codec, pin_nid, conn_list,
747 HDA_MAX_CONNECTIONS);
749 curr = snd_hda_codec_read(codec, pin_nid, 0,
750 AC_VERB_GET_CONNECT_SEL, 0);
754 index = hda_node_index(spec->pin, pin_nid);
758 spec->pin_cvt[index] = conn_list[curr];
763 static void hdmi_present_sense(struct hda_codec *codec, hda_nid_t pin_nid,
764 struct hdmi_eld *eld)
766 int present = snd_hda_pin_sense(codec, pin_nid);
768 eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
769 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
771 if (present & AC_PINSENSE_ELDV)
772 hdmi_get_show_eld(codec, pin_nid, eld);
775 static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
777 struct hdmi_spec *spec = codec->spec;
779 if (spec->num_pins >= MAX_HDMI_PINS) {
780 snd_printk(KERN_WARNING
781 "HDMI: no space for pin %d\n", pin_nid);
785 hdmi_present_sense(codec, pin_nid, &spec->sink_eld[spec->num_pins]);
787 spec->pin[spec->num_pins] = pin_nid;
791 * It is assumed that converter nodes come first in the node list and
792 * hence have been registered and usable now.
794 return hdmi_read_pin_conn(codec, pin_nid);
797 static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t nid)
799 struct hdmi_spec *spec = codec->spec;
801 if (spec->num_cvts >= MAX_HDMI_CVTS) {
802 snd_printk(KERN_WARNING
803 "HDMI: no space for converter %d\n", nid);
807 spec->cvt[spec->num_cvts] = nid;
813 static int hdmi_parse_codec(struct hda_codec *codec)
818 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
819 if (!nid || nodes < 0) {
820 snd_printk(KERN_WARNING "HDMI: failed to get afg sub nodes\n");
824 for (i = 0; i < nodes; i++, nid++) {
828 caps = snd_hda_param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP);
829 type = get_wcaps_type(caps);
831 if (!(caps & AC_WCAP_DIGITAL))
836 hdmi_add_cvt(codec, nid);
839 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
840 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
842 hdmi_add_pin(codec, nid);
848 * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event
849 * can be lost and presence sense verb will become inaccurate if the
850 * HDA link is powered off at hot plug or hw initialization time.
852 #ifdef CONFIG_SND_HDA_POWER_SAVE
853 if (!(snd_hda_param_read(codec, codec->afg, AC_PAR_POWER_STATE) &
855 codec->bus->power_keep_link_on = 1;