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
;
58 struct hdmi_audio_infoframe
{
63 u8 checksum
; /* PB0 */
64 u8 CC02_CT47
; /* CC in bits 0:2, CT in 4:7 */
68 u8 LFEPBL01_LSV36_DM_INH7
;
69 u8 reserved
[5]; /* PB6 - PB10 */
73 * CEA speaker placement:
76 * FLW FL FLC FC FRC FR FRW
83 * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
84 * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
86 enum cea_speaker_placement
{
87 FL
= (1 << 0), /* Front Left */
88 FC
= (1 << 1), /* Front Center */
89 FR
= (1 << 2), /* Front Right */
90 FLC
= (1 << 3), /* Front Left Center */
91 FRC
= (1 << 4), /* Front Right Center */
92 RL
= (1 << 5), /* Rear Left */
93 RC
= (1 << 6), /* Rear Center */
94 RR
= (1 << 7), /* Rear Right */
95 RLC
= (1 << 8), /* Rear Left Center */
96 RRC
= (1 << 9), /* Rear Right Center */
97 LFE
= (1 << 10), /* Low Frequency Effect */
98 FLW
= (1 << 11), /* Front Left Wide */
99 FRW
= (1 << 12), /* Front Right Wide */
100 FLH
= (1 << 13), /* Front Left High */
101 FCH
= (1 << 14), /* Front Center High */
102 FRH
= (1 << 15), /* Front Right High */
103 TC
= (1 << 16), /* Top Center */
107 * ELD SA bits in the CEA Speaker Allocation data block
109 static int eld_speaker_allocation_bits
[] = {
117 /* the following are not defined in ELD yet */
124 struct cea_channel_speaker_allocation
{
128 /* derived values, just for convenience */
136 * surround40 surround41 surround50 surround51 surround71
137 * ch0 front left = = = =
138 * ch1 front right = = = =
139 * ch2 rear left = = = =
140 * ch3 rear right = = = =
141 * ch4 LFE center center center
146 * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR}
148 static int hdmi_channel_mapping
[0x32][8] = {
150 [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
152 [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
154 [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 },
156 [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 },
158 [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 },
160 [0x09] = { 0x00, 0x11, 0x24, 0x34, 0x43, 0xf2, 0xf6, 0xf7 },
162 [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 },
164 [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 },
166 [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 },
170 * This is an ordered list!
172 * The preceding ones have better chances to be selected by
173 * hdmi_setup_channel_allocation().
175 static struct cea_channel_speaker_allocation channel_allocations
[] = {
176 /* channel: 7 6 5 4 3 2 1 0 */
177 { .ca_index
= 0x00, .speakers
= { 0, 0, 0, 0, 0, 0, FR
, FL
} },
179 { .ca_index
= 0x01, .speakers
= { 0, 0, 0, 0, 0, LFE
, FR
, FL
} },
181 { .ca_index
= 0x02, .speakers
= { 0, 0, 0, 0, FC
, 0, FR
, FL
} },
183 { .ca_index
= 0x08, .speakers
= { 0, 0, RR
, RL
, 0, 0, FR
, FL
} },
185 { .ca_index
= 0x09, .speakers
= { 0, 0, RR
, RL
, 0, LFE
, FR
, FL
} },
187 { .ca_index
= 0x0a, .speakers
= { 0, 0, RR
, RL
, FC
, 0, FR
, FL
} },
189 { .ca_index
= 0x0b, .speakers
= { 0, 0, RR
, RL
, FC
, LFE
, FR
, FL
} },
191 { .ca_index
= 0x0f, .speakers
= { 0, RC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
193 { .ca_index
= 0x13, .speakers
= { RRC
, RLC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
195 { .ca_index
= 0x03, .speakers
= { 0, 0, 0, 0, FC
, LFE
, FR
, FL
} },
196 { .ca_index
= 0x04, .speakers
= { 0, 0, 0, RC
, 0, 0, FR
, FL
} },
197 { .ca_index
= 0x05, .speakers
= { 0, 0, 0, RC
, 0, LFE
, FR
, FL
} },
198 { .ca_index
= 0x06, .speakers
= { 0, 0, 0, RC
, FC
, 0, FR
, FL
} },
199 { .ca_index
= 0x07, .speakers
= { 0, 0, 0, RC
, FC
, LFE
, FR
, FL
} },
200 { .ca_index
= 0x0c, .speakers
= { 0, RC
, RR
, RL
, 0, 0, FR
, FL
} },
201 { .ca_index
= 0x0d, .speakers
= { 0, RC
, RR
, RL
, 0, LFE
, FR
, FL
} },
202 { .ca_index
= 0x0e, .speakers
= { 0, RC
, RR
, RL
, FC
, 0, FR
, FL
} },
203 { .ca_index
= 0x10, .speakers
= { RRC
, RLC
, RR
, RL
, 0, 0, FR
, FL
} },
204 { .ca_index
= 0x11, .speakers
= { RRC
, RLC
, RR
, RL
, 0, LFE
, FR
, FL
} },
205 { .ca_index
= 0x12, .speakers
= { RRC
, RLC
, RR
, RL
, FC
, 0, FR
, FL
} },
206 { .ca_index
= 0x14, .speakers
= { FRC
, FLC
, 0, 0, 0, 0, FR
, FL
} },
207 { .ca_index
= 0x15, .speakers
= { FRC
, FLC
, 0, 0, 0, LFE
, FR
, FL
} },
208 { .ca_index
= 0x16, .speakers
= { FRC
, FLC
, 0, 0, FC
, 0, FR
, FL
} },
209 { .ca_index
= 0x17, .speakers
= { FRC
, FLC
, 0, 0, FC
, LFE
, FR
, FL
} },
210 { .ca_index
= 0x18, .speakers
= { FRC
, FLC
, 0, RC
, 0, 0, FR
, FL
} },
211 { .ca_index
= 0x19, .speakers
= { FRC
, FLC
, 0, RC
, 0, LFE
, FR
, FL
} },
212 { .ca_index
= 0x1a, .speakers
= { FRC
, FLC
, 0, RC
, FC
, 0, FR
, FL
} },
213 { .ca_index
= 0x1b, .speakers
= { FRC
, FLC
, 0, RC
, FC
, LFE
, FR
, FL
} },
214 { .ca_index
= 0x1c, .speakers
= { FRC
, FLC
, RR
, RL
, 0, 0, FR
, FL
} },
215 { .ca_index
= 0x1d, .speakers
= { FRC
, FLC
, RR
, RL
, 0, LFE
, FR
, FL
} },
216 { .ca_index
= 0x1e, .speakers
= { FRC
, FLC
, RR
, RL
, FC
, 0, FR
, FL
} },
217 { .ca_index
= 0x1f, .speakers
= { FRC
, FLC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
218 { .ca_index
= 0x20, .speakers
= { 0, FCH
, RR
, RL
, FC
, 0, FR
, FL
} },
219 { .ca_index
= 0x21, .speakers
= { 0, FCH
, RR
, RL
, FC
, LFE
, FR
, FL
} },
220 { .ca_index
= 0x22, .speakers
= { TC
, 0, RR
, RL
, FC
, 0, FR
, FL
} },
221 { .ca_index
= 0x23, .speakers
= { TC
, 0, RR
, RL
, FC
, LFE
, FR
, FL
} },
222 { .ca_index
= 0x24, .speakers
= { FRH
, FLH
, RR
, RL
, 0, 0, FR
, FL
} },
223 { .ca_index
= 0x25, .speakers
= { FRH
, FLH
, RR
, RL
, 0, LFE
, FR
, FL
} },
224 { .ca_index
= 0x26, .speakers
= { FRW
, FLW
, RR
, RL
, 0, 0, FR
, FL
} },
225 { .ca_index
= 0x27, .speakers
= { FRW
, FLW
, RR
, RL
, 0, LFE
, FR
, FL
} },
226 { .ca_index
= 0x28, .speakers
= { TC
, RC
, RR
, RL
, FC
, 0, FR
, FL
} },
227 { .ca_index
= 0x29, .speakers
= { TC
, RC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
228 { .ca_index
= 0x2a, .speakers
= { FCH
, RC
, RR
, RL
, FC
, 0, FR
, FL
} },
229 { .ca_index
= 0x2b, .speakers
= { FCH
, RC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
230 { .ca_index
= 0x2c, .speakers
= { TC
, FCH
, RR
, RL
, FC
, 0, FR
, FL
} },
231 { .ca_index
= 0x2d, .speakers
= { TC
, FCH
, RR
, RL
, FC
, LFE
, FR
, FL
} },
232 { .ca_index
= 0x2e, .speakers
= { FRH
, FLH
, RR
, RL
, FC
, 0, FR
, FL
} },
233 { .ca_index
= 0x2f, .speakers
= { FRH
, FLH
, RR
, RL
, FC
, LFE
, FR
, FL
} },
234 { .ca_index
= 0x30, .speakers
= { FRW
, FLW
, RR
, RL
, FC
, 0, FR
, FL
} },
235 { .ca_index
= 0x31, .speakers
= { FRW
, FLW
, RR
, RL
, FC
, LFE
, FR
, FL
} },
243 static int hda_node_index(hda_nid_t
*nids
, hda_nid_t nid
)
247 for (i
= 0; nids
[i
]; i
++)
251 snd_printk(KERN_WARNING
"HDMI: nid %d not registered\n", nid
);
255 static void hdmi_get_show_eld(struct hda_codec
*codec
, hda_nid_t pin_nid
,
256 struct hdmi_eld
*eld
)
258 if (!snd_hdmi_get_eld(eld
, codec
, pin_nid
))
259 snd_hdmi_show_eld(eld
);
263 static void hdmi_get_dip_index(struct hda_codec
*codec
, hda_nid_t pin_nid
,
264 int *packet_index
, int *byte_index
)
268 val
= snd_hda_codec_read(codec
, pin_nid
, 0,
269 AC_VERB_GET_HDMI_DIP_INDEX
, 0);
271 *packet_index
= val
>> 5;
272 *byte_index
= val
& 0x1f;
276 static void hdmi_set_dip_index(struct hda_codec
*codec
, hda_nid_t pin_nid
,
277 int packet_index
, int byte_index
)
281 val
= (packet_index
<< 5) | (byte_index
& 0x1f);
283 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_INDEX
, val
);
286 static void hdmi_write_dip_byte(struct hda_codec
*codec
, hda_nid_t pin_nid
,
289 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_DATA
, val
);
292 static void hdmi_enable_output(struct hda_codec
*codec
, hda_nid_t pin_nid
)
295 if (get_wcaps(codec
, pin_nid
) & AC_WCAP_OUT_AMP
)
296 snd_hda_codec_write(codec
, pin_nid
, 0,
297 AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
);
299 snd_hda_codec_write(codec
, pin_nid
, 0,
300 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
);
303 static int hdmi_get_channel_count(struct hda_codec
*codec
, hda_nid_t nid
)
305 return 1 + snd_hda_codec_read(codec
, nid
, 0,
306 AC_VERB_GET_CVT_CHAN_COUNT
, 0);
309 static void hdmi_set_channel_count(struct hda_codec
*codec
,
310 hda_nid_t nid
, int chs
)
312 if (chs
!= hdmi_get_channel_count(codec
, nid
))
313 snd_hda_codec_write(codec
, nid
, 0,
314 AC_VERB_SET_CVT_CHAN_COUNT
, chs
- 1);
319 * Channel mapping routines
323 * Compute derived values in channel_allocations[].
325 static void init_channel_allocations(void)
328 struct cea_channel_speaker_allocation
*p
;
330 for (i
= 0; i
< ARRAY_SIZE(channel_allocations
); i
++) {
331 p
= channel_allocations
+ i
;
334 for (j
= 0; j
< ARRAY_SIZE(p
->speakers
); j
++)
335 if (p
->speakers
[j
]) {
337 p
->spk_mask
|= p
->speakers
[j
];
343 * The transformation takes two steps:
345 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
346 * spk_mask => (channel_allocations[]) => ai->CA
348 * TODO: it could select the wrong CA from multiple candidates.
350 static int hdmi_setup_channel_allocation(struct hda_codec
*codec
, hda_nid_t nid
,
351 struct hdmi_audio_infoframe
*ai
)
353 struct hdmi_spec
*spec
= codec
->spec
;
354 struct hdmi_eld
*eld
;
357 int channels
= 1 + (ai
->CC02_CT47
& 0x7);
358 char buf
[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE
];
361 * CA defaults to 0 for basic stereo audio
366 i
= hda_node_index(spec
->pin_cvt
, nid
);
369 eld
= &spec
->sink_eld
[i
];
372 * HDMI sink's ELD info cannot always be retrieved for now, e.g.
373 * in console or for audio devices. Assume the highest speakers
374 * configuration, to _not_ prohibit multi-channel audio playback.
377 eld
->spk_alloc
= 0xffff;
380 * expand ELD's speaker allocation mask
382 * ELD tells the speaker mask in a compact(paired) form,
383 * expand ELD's notions to match the ones used by Audio InfoFrame.
385 for (i
= 0; i
< ARRAY_SIZE(eld_speaker_allocation_bits
); i
++) {
386 if (eld
->spk_alloc
& (1 << i
))
387 spk_mask
|= eld_speaker_allocation_bits
[i
];
390 /* search for the first working match in the CA table */
391 for (i
= 0; i
< ARRAY_SIZE(channel_allocations
); i
++) {
392 if (channels
== channel_allocations
[i
].channels
&&
393 (spk_mask
& channel_allocations
[i
].spk_mask
) ==
394 channel_allocations
[i
].spk_mask
) {
395 ai
->CA
= channel_allocations
[i
].ca_index
;
400 snd_print_channel_allocation(eld
->spk_alloc
, buf
, sizeof(buf
));
401 snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n",
402 ai
->CA
, channels
, buf
);
407 static void hdmi_debug_channel_mapping(struct hda_codec
*codec
,
410 #ifdef CONFIG_SND_DEBUG_VERBOSE
414 for (i
= 0; i
< 8; i
++) {
415 slot
= snd_hda_codec_read(codec
, pin_nid
, 0,
416 AC_VERB_GET_HDMI_CHAN_SLOT
, i
);
417 printk(KERN_DEBUG
"HDMI: ASP channel %d => slot %d\n",
418 slot
>> 4, slot
& 0xf);
424 static void hdmi_setup_channel_mapping(struct hda_codec
*codec
,
426 struct hdmi_audio_infoframe
*ai
)
432 if (hdmi_channel_mapping
[ca
][1] == 0) {
433 for (i
= 0; i
< channel_allocations
[ca
].channels
; i
++)
434 hdmi_channel_mapping
[ca
][i
] = i
| (i
<< 4);
436 hdmi_channel_mapping
[ca
][i
] = 0xf | (i
<< 4);
439 for (i
= 0; i
< 8; i
++) {
440 err
= snd_hda_codec_write(codec
, pin_nid
, 0,
441 AC_VERB_SET_HDMI_CHAN_SLOT
,
442 hdmi_channel_mapping
[ca
][i
]);
444 snd_printdd(KERN_NOTICE
445 "HDMI: channel mapping failed\n");
450 hdmi_debug_channel_mapping(codec
, pin_nid
);
455 * Audio InfoFrame routines
459 * Enable Audio InfoFrame Transmission
461 static void hdmi_start_infoframe_trans(struct hda_codec
*codec
,
464 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
465 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_XMIT
,
470 * Disable Audio InfoFrame Transmission
472 static void hdmi_stop_infoframe_trans(struct hda_codec
*codec
,
475 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
476 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_XMIT
,
480 static void hdmi_debug_dip_size(struct hda_codec
*codec
, hda_nid_t pin_nid
)
482 #ifdef CONFIG_SND_DEBUG_VERBOSE
486 size
= snd_hdmi_get_eld_size(codec
, pin_nid
);
487 printk(KERN_DEBUG
"HDMI: ELD buf size is %d\n", size
);
489 for (i
= 0; i
< 8; i
++) {
490 size
= snd_hda_codec_read(codec
, pin_nid
, 0,
491 AC_VERB_GET_HDMI_DIP_SIZE
, i
);
492 printk(KERN_DEBUG
"HDMI: DIP GP[%d] buf size is %d\n", i
, size
);
497 static void hdmi_clear_dip_buffers(struct hda_codec
*codec
, hda_nid_t pin_nid
)
503 for (i
= 0; i
< 8; i
++) {
504 size
= snd_hda_codec_read(codec
, pin_nid
, 0,
505 AC_VERB_GET_HDMI_DIP_SIZE
, i
);
509 hdmi_set_dip_index(codec
, pin_nid
, i
, 0x0);
510 for (j
= 1; j
< 1000; j
++) {
511 hdmi_write_dip_byte(codec
, pin_nid
, 0x0);
512 hdmi_get_dip_index(codec
, pin_nid
, &pi
, &bi
);
514 snd_printd(KERN_INFO
"dip index %d: %d != %d\n",
516 if (bi
== 0) /* byte index wrapped around */
520 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
526 static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe
*ai
)
528 u8
*bytes
= (u8
*)ai
;
534 for (i
= 0; i
< sizeof(*ai
); i
++)
540 static void hdmi_fill_audio_infoframe(struct hda_codec
*codec
,
542 struct hdmi_audio_infoframe
*ai
)
544 u8
*bytes
= (u8
*)ai
;
547 hdmi_debug_dip_size(codec
, pin_nid
);
548 hdmi_clear_dip_buffers(codec
, pin_nid
); /* be paranoid */
550 hdmi_checksum_audio_infoframe(ai
);
552 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
553 for (i
= 0; i
< sizeof(*ai
); i
++)
554 hdmi_write_dip_byte(codec
, pin_nid
, bytes
[i
]);
557 static bool hdmi_infoframe_uptodate(struct hda_codec
*codec
, hda_nid_t pin_nid
,
558 struct hdmi_audio_infoframe
*ai
)
560 u8
*bytes
= (u8
*)ai
;
564 if (snd_hda_codec_read(codec
, pin_nid
, 0, AC_VERB_GET_HDMI_DIP_XMIT
, 0)
568 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
569 for (i
= 0; i
< sizeof(*ai
); i
++) {
570 val
= snd_hda_codec_read(codec
, pin_nid
, 0,
571 AC_VERB_GET_HDMI_DIP_DATA
, 0);
579 static void hdmi_setup_audio_infoframe(struct hda_codec
*codec
, hda_nid_t nid
,
580 struct snd_pcm_substream
*substream
)
582 struct hdmi_spec
*spec
= codec
->spec
;
585 struct hdmi_audio_infoframe ai
= {
589 .CC02_CT47
= substream
->runtime
->channels
- 1,
592 hdmi_setup_channel_allocation(codec
, nid
, &ai
);
594 for (i
= 0; i
< spec
->num_pins
; i
++) {
595 if (spec
->pin_cvt
[i
] != nid
)
597 if (!spec
->sink_eld
[i
].monitor_present
)
600 pin_nid
= spec
->pin
[i
];
601 if (!hdmi_infoframe_uptodate(codec
, pin_nid
, &ai
)) {
602 snd_printdd("hdmi_setup_audio_infoframe: "
603 "cvt=%d pin=%d channels=%d\n",
605 substream
->runtime
->channels
);
606 hdmi_setup_channel_mapping(codec
, pin_nid
, &ai
);
607 hdmi_stop_infoframe_trans(codec
, pin_nid
);
608 hdmi_fill_audio_infoframe(codec
, pin_nid
, &ai
);
609 hdmi_start_infoframe_trans(codec
, pin_nid
);
619 static void hdmi_intrinsic_event(struct hda_codec
*codec
, unsigned int res
)
621 struct hdmi_spec
*spec
= codec
->spec
;
622 int tag
= res
>> AC_UNSOL_RES_TAG_SHIFT
;
623 int pind
= !!(res
& AC_UNSOL_RES_PD
);
624 int eldv
= !!(res
& AC_UNSOL_RES_ELDV
);
628 "HDMI hot plug event: Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
631 index
= hda_node_index(spec
->pin
, tag
);
635 spec
->sink_eld
[index
].monitor_present
= pind
;
636 spec
->sink_eld
[index
].eld_valid
= eldv
;
639 hdmi_get_show_eld(codec
, spec
->pin
[index
],
640 &spec
->sink_eld
[index
]);
641 /* TODO: do real things about ELD */
645 static void hdmi_non_intrinsic_event(struct hda_codec
*codec
, unsigned int res
)
647 int tag
= res
>> AC_UNSOL_RES_TAG_SHIFT
;
648 int subtag
= (res
& AC_UNSOL_RES_SUBTAG
) >> AC_UNSOL_RES_SUBTAG_SHIFT
;
649 int cp_state
= !!(res
& AC_UNSOL_RES_CP_STATE
);
650 int cp_ready
= !!(res
& AC_UNSOL_RES_CP_READY
);
653 "HDMI CP event: PIN=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
667 static void hdmi_unsol_event(struct hda_codec
*codec
, unsigned int res
)
669 struct hdmi_spec
*spec
= codec
->spec
;
670 int tag
= res
>> AC_UNSOL_RES_TAG_SHIFT
;
671 int subtag
= (res
& AC_UNSOL_RES_SUBTAG
) >> AC_UNSOL_RES_SUBTAG_SHIFT
;
673 if (hda_node_index(spec
->pin
, tag
) < 0) {
674 snd_printd(KERN_INFO
"Unexpected HDMI event tag 0x%x\n", tag
);
679 hdmi_intrinsic_event(codec
, res
);
681 hdmi_non_intrinsic_event(codec
, res
);
688 static void hdmi_setup_stream(struct hda_codec
*codec
, hda_nid_t nid
,
689 u32 stream_tag
, int format
)
694 tag
= snd_hda_codec_read(codec
, nid
, 0, AC_VERB_GET_CONV
, 0) >> 4;
695 fmt
= snd_hda_codec_read(codec
, nid
, 0, AC_VERB_GET_STREAM_FORMAT
, 0);
697 snd_printdd("hdmi_setup_stream: "
698 "NID=0x%x, %sstream=0x%x, %sformat=0x%x\n",
700 tag
== stream_tag
? "" : "new-",
702 fmt
== format
? "" : "new-",
705 if (tag
!= stream_tag
)
706 snd_hda_codec_write(codec
, nid
, 0,
707 AC_VERB_SET_CHANNEL_STREAMID
,
710 snd_hda_codec_write(codec
, nid
, 0,
711 AC_VERB_SET_STREAM_FORMAT
, format
);
715 * HDA/HDMI auto parsing
718 static int hdmi_read_pin_conn(struct hda_codec
*codec
, hda_nid_t pin_nid
)
720 struct hdmi_spec
*spec
= codec
->spec
;
721 hda_nid_t conn_list
[HDA_MAX_CONNECTIONS
];
725 if (!(get_wcaps(codec
, pin_nid
) & AC_WCAP_CONN_LIST
)) {
726 snd_printk(KERN_WARNING
727 "HDMI: pin %d wcaps %#x "
728 "does not support connection list\n",
729 pin_nid
, get_wcaps(codec
, pin_nid
));
733 conn_len
= snd_hda_get_connections(codec
, pin_nid
, conn_list
,
734 HDA_MAX_CONNECTIONS
);
736 curr
= snd_hda_codec_read(codec
, pin_nid
, 0,
737 AC_VERB_GET_CONNECT_SEL
, 0);
741 index
= hda_node_index(spec
->pin
, pin_nid
);
745 spec
->pin_cvt
[index
] = conn_list
[curr
];
750 static void hdmi_present_sense(struct hda_codec
*codec
, hda_nid_t pin_nid
,
751 struct hdmi_eld
*eld
)
753 int present
= snd_hda_pin_sense(codec
, pin_nid
);
755 eld
->monitor_present
= !!(present
& AC_PINSENSE_PRESENCE
);
756 eld
->eld_valid
= !!(present
& AC_PINSENSE_ELDV
);
758 if (present
& AC_PINSENSE_ELDV
)
759 hdmi_get_show_eld(codec
, pin_nid
, eld
);
762 static int hdmi_add_pin(struct hda_codec
*codec
, hda_nid_t pin_nid
)
764 struct hdmi_spec
*spec
= codec
->spec
;
766 if (spec
->num_pins
>= MAX_HDMI_PINS
) {
767 snd_printk(KERN_WARNING
768 "HDMI: no space for pin %d\n", pin_nid
);
772 hdmi_present_sense(codec
, pin_nid
, &spec
->sink_eld
[spec
->num_pins
]);
774 spec
->pin
[spec
->num_pins
] = pin_nid
;
778 * It is assumed that converter nodes come first in the node list and
779 * hence have been registered and usable now.
781 return hdmi_read_pin_conn(codec
, pin_nid
);
784 static int hdmi_add_cvt(struct hda_codec
*codec
, hda_nid_t nid
)
786 struct hdmi_spec
*spec
= codec
->spec
;
788 if (spec
->num_cvts
>= MAX_HDMI_CVTS
) {
789 snd_printk(KERN_WARNING
790 "HDMI: no space for converter %d\n", nid
);
794 spec
->cvt
[spec
->num_cvts
] = nid
;
800 static int hdmi_parse_codec(struct hda_codec
*codec
)
805 nodes
= snd_hda_get_sub_nodes(codec
, codec
->afg
, &nid
);
806 if (!nid
|| nodes
< 0) {
807 snd_printk(KERN_WARNING
"HDMI: failed to get afg sub nodes\n");
811 for (i
= 0; i
< nodes
; i
++, nid
++) {
815 caps
= snd_hda_param_read(codec
, nid
, AC_PAR_AUDIO_WIDGET_CAP
);
816 type
= get_wcaps_type(caps
);
818 if (!(caps
& AC_WCAP_DIGITAL
))
823 if (hdmi_add_cvt(codec
, nid
) < 0)
827 caps
= snd_hda_param_read(codec
, nid
, AC_PAR_PIN_CAP
);
828 if (!(caps
& (AC_PINCAP_HDMI
| AC_PINCAP_DP
)))
830 if (hdmi_add_pin(codec
, nid
) < 0)
837 * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event
838 * can be lost and presence sense verb will become inaccurate if the
839 * HDA link is powered off at hot plug or hw initialization time.
841 #ifdef CONFIG_SND_HDA_POWER_SAVE
842 if (!(snd_hda_param_read(codec
, codec
->afg
, AC_PAR_POWER_STATE
) &
844 codec
->bus
->power_keep_link_on
= 1;