3 * patch_intelhdmi.c - Patch for Intel HDMI codecs
5 * Copyright(c) 2008 Intel Corporation. All rights reserved.
8 * Jiang Zhe <zhe.jiang@intel.com>
9 * Wu Fengguang <wfg@linux.intel.com>
12 * Wu Fengguang <wfg@linux.intel.com>
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option)
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include <linux/init.h>
30 #include <linux/delay.h>
31 #include <linux/slab.h>
32 #include <sound/core.h>
33 #include "hda_codec.h"
34 #include "hda_local.h"
37 * The HDMI/DisplayPort configuration can be highly dynamic. A graphics device
38 * could support two independent pipes, each of them can be connected to one or
39 * more ports (DVI, HDMI or DisplayPort).
41 * The HDA correspondence of pipes/ports are converter/pin nodes.
43 #define INTEL_HDMI_CVTS 2
44 #define INTEL_HDMI_PINS 3
46 static char *intel_hdmi_pcm_names
[INTEL_HDMI_CVTS
] = {
51 struct intel_hdmi_spec
{
54 hda_nid_t cvt
[INTEL_HDMI_CVTS
+1]; /* audio sources */
55 hda_nid_t pin
[INTEL_HDMI_PINS
+1]; /* audio sinks */
58 * source connection for each pin
60 hda_nid_t pin_cvt
[INTEL_HDMI_PINS
+1];
63 * HDMI sink attached to each pin
65 struct hdmi_eld sink_eld
[INTEL_HDMI_PINS
];
68 * export one pcm per pipe
70 struct hda_pcm pcm_rec
[INTEL_HDMI_CVTS
];
73 struct hdmi_audio_infoframe
{
78 u8 checksum
; /* PB0 */
79 u8 CC02_CT47
; /* CC in bits 0:2, CT in 4:7 */
83 u8 LFEPBL01_LSV36_DM_INH7
;
84 u8 reserved
[5]; /* PB6 - PB10 */
88 * CEA speaker placement:
91 * FLW FL FLC FC FRC FR FRW
98 * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
99 * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
101 enum cea_speaker_placement
{
102 FL
= (1 << 0), /* Front Left */
103 FC
= (1 << 1), /* Front Center */
104 FR
= (1 << 2), /* Front Right */
105 FLC
= (1 << 3), /* Front Left Center */
106 FRC
= (1 << 4), /* Front Right Center */
107 RL
= (1 << 5), /* Rear Left */
108 RC
= (1 << 6), /* Rear Center */
109 RR
= (1 << 7), /* Rear Right */
110 RLC
= (1 << 8), /* Rear Left Center */
111 RRC
= (1 << 9), /* Rear Right Center */
112 LFE
= (1 << 10), /* Low Frequency Effect */
113 FLW
= (1 << 11), /* Front Left Wide */
114 FRW
= (1 << 12), /* Front Right Wide */
115 FLH
= (1 << 13), /* Front Left High */
116 FCH
= (1 << 14), /* Front Center High */
117 FRH
= (1 << 15), /* Front Right High */
118 TC
= (1 << 16), /* Top Center */
122 * ELD SA bits in the CEA Speaker Allocation data block
124 static int eld_speaker_allocation_bits
[] = {
132 /* the following are not defined in ELD yet */
139 struct cea_channel_speaker_allocation
{
143 /* derived values, just for convenience */
149 * This is an ordered list!
151 * The preceding ones have better chances to be selected by
152 * hdmi_setup_channel_allocation().
154 static struct cea_channel_speaker_allocation channel_allocations
[] = {
155 /* channel: 8 7 6 5 4 3 2 1 */
156 { .ca_index
= 0x00, .speakers
= { 0, 0, 0, 0, 0, 0, FR
, FL
} },
158 { .ca_index
= 0x01, .speakers
= { 0, 0, 0, 0, 0, LFE
, FR
, FL
} },
160 { .ca_index
= 0x02, .speakers
= { 0, 0, 0, 0, FC
, 0, FR
, FL
} },
161 { .ca_index
= 0x03, .speakers
= { 0, 0, 0, 0, FC
, LFE
, FR
, FL
} },
162 { .ca_index
= 0x04, .speakers
= { 0, 0, 0, RC
, 0, 0, FR
, FL
} },
163 { .ca_index
= 0x05, .speakers
= { 0, 0, 0, RC
, 0, LFE
, FR
, FL
} },
164 { .ca_index
= 0x06, .speakers
= { 0, 0, 0, RC
, FC
, 0, FR
, FL
} },
165 { .ca_index
= 0x07, .speakers
= { 0, 0, 0, RC
, FC
, LFE
, FR
, FL
} },
166 { .ca_index
= 0x08, .speakers
= { 0, 0, RR
, RL
, 0, 0, FR
, FL
} },
167 { .ca_index
= 0x09, .speakers
= { 0, 0, RR
, RL
, 0, LFE
, FR
, FL
} },
168 { .ca_index
= 0x0a, .speakers
= { 0, 0, RR
, RL
, FC
, 0, FR
, FL
} },
170 { .ca_index
= 0x0b, .speakers
= { 0, 0, RR
, RL
, FC
, LFE
, FR
, FL
} },
171 { .ca_index
= 0x0c, .speakers
= { 0, RC
, RR
, RL
, 0, 0, FR
, FL
} },
172 { .ca_index
= 0x0d, .speakers
= { 0, RC
, RR
, RL
, 0, LFE
, FR
, FL
} },
173 { .ca_index
= 0x0e, .speakers
= { 0, RC
, RR
, RL
, FC
, 0, FR
, FL
} },
175 { .ca_index
= 0x0f, .speakers
= { 0, RC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
176 { .ca_index
= 0x10, .speakers
= { RRC
, RLC
, RR
, RL
, 0, 0, FR
, FL
} },
177 { .ca_index
= 0x11, .speakers
= { RRC
, RLC
, RR
, RL
, 0, LFE
, FR
, FL
} },
178 { .ca_index
= 0x12, .speakers
= { RRC
, RLC
, RR
, RL
, FC
, 0, FR
, FL
} },
180 { .ca_index
= 0x13, .speakers
= { RRC
, RLC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
181 { .ca_index
= 0x14, .speakers
= { FRC
, FLC
, 0, 0, 0, 0, FR
, FL
} },
182 { .ca_index
= 0x15, .speakers
= { FRC
, FLC
, 0, 0, 0, LFE
, FR
, FL
} },
183 { .ca_index
= 0x16, .speakers
= { FRC
, FLC
, 0, 0, FC
, 0, FR
, FL
} },
184 { .ca_index
= 0x17, .speakers
= { FRC
, FLC
, 0, 0, FC
, LFE
, FR
, FL
} },
185 { .ca_index
= 0x18, .speakers
= { FRC
, FLC
, 0, RC
, 0, 0, FR
, FL
} },
186 { .ca_index
= 0x19, .speakers
= { FRC
, FLC
, 0, RC
, 0, LFE
, FR
, FL
} },
187 { .ca_index
= 0x1a, .speakers
= { FRC
, FLC
, 0, RC
, FC
, 0, FR
, FL
} },
188 { .ca_index
= 0x1b, .speakers
= { FRC
, FLC
, 0, RC
, FC
, LFE
, FR
, FL
} },
189 { .ca_index
= 0x1c, .speakers
= { FRC
, FLC
, RR
, RL
, 0, 0, FR
, FL
} },
190 { .ca_index
= 0x1d, .speakers
= { FRC
, FLC
, RR
, RL
, 0, LFE
, FR
, FL
} },
191 { .ca_index
= 0x1e, .speakers
= { FRC
, FLC
, RR
, RL
, FC
, 0, FR
, FL
} },
192 { .ca_index
= 0x1f, .speakers
= { FRC
, FLC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
193 { .ca_index
= 0x20, .speakers
= { 0, FCH
, RR
, RL
, FC
, 0, FR
, FL
} },
194 { .ca_index
= 0x21, .speakers
= { 0, FCH
, RR
, RL
, FC
, LFE
, FR
, FL
} },
195 { .ca_index
= 0x22, .speakers
= { TC
, 0, RR
, RL
, FC
, 0, FR
, FL
} },
196 { .ca_index
= 0x23, .speakers
= { TC
, 0, RR
, RL
, FC
, LFE
, FR
, FL
} },
197 { .ca_index
= 0x24, .speakers
= { FRH
, FLH
, RR
, RL
, 0, 0, FR
, FL
} },
198 { .ca_index
= 0x25, .speakers
= { FRH
, FLH
, RR
, RL
, 0, LFE
, FR
, FL
} },
199 { .ca_index
= 0x26, .speakers
= { FRW
, FLW
, RR
, RL
, 0, 0, FR
, FL
} },
200 { .ca_index
= 0x27, .speakers
= { FRW
, FLW
, RR
, RL
, 0, LFE
, FR
, FL
} },
201 { .ca_index
= 0x28, .speakers
= { TC
, RC
, RR
, RL
, FC
, 0, FR
, FL
} },
202 { .ca_index
= 0x29, .speakers
= { TC
, RC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
203 { .ca_index
= 0x2a, .speakers
= { FCH
, RC
, RR
, RL
, FC
, 0, FR
, FL
} },
204 { .ca_index
= 0x2b, .speakers
= { FCH
, RC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
205 { .ca_index
= 0x2c, .speakers
= { TC
, FCH
, RR
, RL
, FC
, 0, FR
, FL
} },
206 { .ca_index
= 0x2d, .speakers
= { TC
, FCH
, RR
, RL
, FC
, LFE
, FR
, FL
} },
207 { .ca_index
= 0x2e, .speakers
= { FRH
, FLH
, RR
, RL
, FC
, 0, FR
, FL
} },
208 { .ca_index
= 0x2f, .speakers
= { FRH
, FLH
, RR
, RL
, FC
, LFE
, FR
, FL
} },
209 { .ca_index
= 0x30, .speakers
= { FRW
, FLW
, RR
, RL
, FC
, 0, FR
, FL
} },
210 { .ca_index
= 0x31, .speakers
= { FRW
, FLW
, RR
, RL
, FC
, LFE
, FR
, FL
} },
215 * HDA/HDMI auto parsing
218 static int hda_node_index(hda_nid_t
*nids
, hda_nid_t nid
)
222 for (i
= 0; nids
[i
]; i
++)
226 snd_printk(KERN_WARNING
"HDMI: nid %d not registered\n", nid
);
230 static int intel_hdmi_read_pin_conn(struct hda_codec
*codec
, hda_nid_t pin_nid
)
232 struct intel_hdmi_spec
*spec
= codec
->spec
;
233 hda_nid_t conn_list
[HDA_MAX_CONNECTIONS
];
237 if (!(get_wcaps(codec
, pin_nid
) & AC_WCAP_CONN_LIST
)) {
238 snd_printk(KERN_WARNING
239 "HDMI: pin %d wcaps %#x "
240 "does not support connection list\n",
241 pin_nid
, get_wcaps(codec
, pin_nid
));
245 conn_len
= snd_hda_get_connections(codec
, pin_nid
, conn_list
,
246 HDA_MAX_CONNECTIONS
);
248 curr
= snd_hda_codec_read(codec
, pin_nid
, 0,
249 AC_VERB_GET_CONNECT_SEL
, 0);
253 index
= hda_node_index(spec
->pin
, pin_nid
);
257 spec
->pin_cvt
[index
] = conn_list
[curr
];
262 static void hdmi_get_show_eld(struct hda_codec
*codec
, hda_nid_t pin_nid
,
263 struct hdmi_eld
*eld
)
265 if (!snd_hdmi_get_eld(eld
, codec
, pin_nid
))
266 snd_hdmi_show_eld(eld
);
269 static void hdmi_present_sense(struct hda_codec
*codec
, hda_nid_t pin_nid
,
270 struct hdmi_eld
*eld
)
272 int present
= snd_hda_pin_sense(codec
, pin_nid
);
274 eld
->monitor_present
= !!(present
& AC_PINSENSE_PRESENCE
);
275 eld
->eld_valid
= !!(present
& AC_PINSENSE_ELDV
);
277 if (present
& AC_PINSENSE_ELDV
)
278 hdmi_get_show_eld(codec
, pin_nid
, eld
);
281 static int intel_hdmi_add_pin(struct hda_codec
*codec
, hda_nid_t pin_nid
)
283 struct intel_hdmi_spec
*spec
= codec
->spec
;
285 if (spec
->num_pins
>= INTEL_HDMI_PINS
) {
286 snd_printk(KERN_WARNING
287 "HDMI: no space for pin %d \n", pin_nid
);
291 hdmi_present_sense(codec
, pin_nid
, &spec
->sink_eld
[spec
->num_pins
]);
293 spec
->pin
[spec
->num_pins
] = pin_nid
;
297 * It is assumed that converter nodes come first in the node list and
298 * hence have been registered and usable now.
300 return intel_hdmi_read_pin_conn(codec
, pin_nid
);
303 static int intel_hdmi_add_cvt(struct hda_codec
*codec
, hda_nid_t nid
)
305 struct intel_hdmi_spec
*spec
= codec
->spec
;
307 if (spec
->num_cvts
>= INTEL_HDMI_CVTS
) {
308 snd_printk(KERN_WARNING
309 "HDMI: no space for converter %d \n", nid
);
313 spec
->cvt
[spec
->num_cvts
] = nid
;
319 static int intel_hdmi_parse_codec(struct hda_codec
*codec
)
324 nodes
= snd_hda_get_sub_nodes(codec
, codec
->afg
, &nid
);
325 if (!nid
|| nodes
< 0) {
326 snd_printk(KERN_WARNING
"HDMI: failed to get afg sub nodes\n");
330 for (i
= 0; i
< nodes
; i
++, nid
++) {
334 caps
= snd_hda_param_read(codec
, nid
, AC_PAR_AUDIO_WIDGET_CAP
);
335 type
= get_wcaps_type(caps
);
337 if (!(caps
& AC_WCAP_DIGITAL
))
342 if (intel_hdmi_add_cvt(codec
, nid
) < 0)
346 caps
= snd_hda_param_read(codec
, nid
, AC_PAR_PIN_CAP
);
347 if (!(caps
& (AC_PINCAP_HDMI
| AC_PINCAP_DP
)))
349 if (intel_hdmi_add_pin(codec
, nid
) < 0)
363 static void hdmi_get_dip_index(struct hda_codec
*codec
, hda_nid_t pin_nid
,
364 int *packet_index
, int *byte_index
)
368 val
= snd_hda_codec_read(codec
, pin_nid
, 0,
369 AC_VERB_GET_HDMI_DIP_INDEX
, 0);
371 *packet_index
= val
>> 5;
372 *byte_index
= val
& 0x1f;
376 static void hdmi_set_dip_index(struct hda_codec
*codec
, hda_nid_t pin_nid
,
377 int packet_index
, int byte_index
)
381 val
= (packet_index
<< 5) | (byte_index
& 0x1f);
383 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_INDEX
, val
);
386 static void hdmi_write_dip_byte(struct hda_codec
*codec
, hda_nid_t pin_nid
,
389 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_DATA
, val
);
392 static void hdmi_enable_output(struct hda_codec
*codec
, hda_nid_t pin_nid
)
395 if (get_wcaps(codec
, pin_nid
) & AC_WCAP_OUT_AMP
)
396 snd_hda_codec_write(codec
, pin_nid
, 0,
397 AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
);
399 snd_hda_codec_write(codec
, pin_nid
, 0,
400 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
);
404 * Enable Audio InfoFrame Transmission
406 static void hdmi_start_infoframe_trans(struct hda_codec
*codec
,
409 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
410 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_XMIT
,
415 * Disable Audio InfoFrame Transmission
417 static void hdmi_stop_infoframe_trans(struct hda_codec
*codec
,
420 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
421 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_XMIT
,
425 static int hdmi_get_channel_count(struct hda_codec
*codec
, hda_nid_t nid
)
427 return 1 + snd_hda_codec_read(codec
, nid
, 0,
428 AC_VERB_GET_CVT_CHAN_COUNT
, 0);
431 static void hdmi_set_channel_count(struct hda_codec
*codec
,
432 hda_nid_t nid
, int chs
)
434 if (chs
!= hdmi_get_channel_count(codec
, nid
))
435 snd_hda_codec_write(codec
, nid
, 0,
436 AC_VERB_SET_CVT_CHAN_COUNT
, chs
- 1);
439 static void hdmi_debug_channel_mapping(struct hda_codec
*codec
, hda_nid_t nid
)
441 #ifdef CONFIG_SND_DEBUG_VERBOSE
445 for (i
= 0; i
< 8; i
++) {
446 slot
= snd_hda_codec_read(codec
, nid
, 0,
447 AC_VERB_GET_HDMI_CHAN_SLOT
, i
);
448 printk(KERN_DEBUG
"HDMI: ASP channel %d => slot %d\n",
449 slot
>> 4, slot
& 0xf);
456 * Audio InfoFrame routines
459 static void hdmi_debug_dip_size(struct hda_codec
*codec
, hda_nid_t pin_nid
)
461 #ifdef CONFIG_SND_DEBUG_VERBOSE
465 size
= snd_hdmi_get_eld_size(codec
, pin_nid
);
466 printk(KERN_DEBUG
"HDMI: ELD buf size is %d\n", size
);
468 for (i
= 0; i
< 8; i
++) {
469 size
= snd_hda_codec_read(codec
, pin_nid
, 0,
470 AC_VERB_GET_HDMI_DIP_SIZE
, i
);
471 printk(KERN_DEBUG
"HDMI: DIP GP[%d] buf size is %d\n", i
, size
);
476 static void hdmi_clear_dip_buffers(struct hda_codec
*codec
, hda_nid_t pin_nid
)
482 for (i
= 0; i
< 8; i
++) {
483 size
= snd_hda_codec_read(codec
, pin_nid
, 0,
484 AC_VERB_GET_HDMI_DIP_SIZE
, i
);
488 hdmi_set_dip_index(codec
, pin_nid
, i
, 0x0);
489 for (j
= 1; j
< 1000; j
++) {
490 hdmi_write_dip_byte(codec
, pin_nid
, 0x0);
491 hdmi_get_dip_index(codec
, pin_nid
, &pi
, &bi
);
493 snd_printd(KERN_INFO
"dip index %d: %d != %d\n",
495 if (bi
== 0) /* byte index wrapped around */
499 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
505 static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe
*ai
)
507 u8
*bytes
= (u8
*)ai
;
513 for (i
= 0; i
< sizeof(*ai
); i
++)
516 ai
->checksum
= - sum
;
519 static void hdmi_fill_audio_infoframe(struct hda_codec
*codec
,
521 struct hdmi_audio_infoframe
*ai
)
523 u8
*bytes
= (u8
*)ai
;
526 hdmi_debug_dip_size(codec
, pin_nid
);
527 hdmi_clear_dip_buffers(codec
, pin_nid
); /* be paranoid */
529 hdmi_checksum_audio_infoframe(ai
);
531 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
532 for (i
= 0; i
< sizeof(*ai
); i
++)
533 hdmi_write_dip_byte(codec
, pin_nid
, bytes
[i
]);
537 * Compute derived values in channel_allocations[].
539 static void init_channel_allocations(void)
542 struct cea_channel_speaker_allocation
*p
;
544 for (i
= 0; i
< ARRAY_SIZE(channel_allocations
); i
++) {
545 p
= channel_allocations
+ i
;
548 for (j
= 0; j
< ARRAY_SIZE(p
->speakers
); j
++)
549 if (p
->speakers
[j
]) {
551 p
->spk_mask
|= p
->speakers
[j
];
557 * The transformation takes two steps:
559 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
560 * spk_mask => (channel_allocations[]) => ai->CA
562 * TODO: it could select the wrong CA from multiple candidates.
564 static int hdmi_setup_channel_allocation(struct hda_codec
*codec
, hda_nid_t nid
,
565 struct hdmi_audio_infoframe
*ai
)
567 struct intel_hdmi_spec
*spec
= codec
->spec
;
568 struct hdmi_eld
*eld
;
571 int channels
= 1 + (ai
->CC02_CT47
& 0x7);
572 char buf
[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE
];
575 * CA defaults to 0 for basic stereo audio
580 i
= hda_node_index(spec
->pin_cvt
, nid
);
583 eld
= &spec
->sink_eld
[i
];
586 * HDMI sink's ELD info cannot always be retrieved for now, e.g.
587 * in console or for audio devices. Assume the highest speakers
588 * configuration, to _not_ prohibit multi-channel audio playback.
591 eld
->spk_alloc
= 0xffff;
594 * expand ELD's speaker allocation mask
596 * ELD tells the speaker mask in a compact(paired) form,
597 * expand ELD's notions to match the ones used by Audio InfoFrame.
599 for (i
= 0; i
< ARRAY_SIZE(eld_speaker_allocation_bits
); i
++) {
600 if (eld
->spk_alloc
& (1 << i
))
601 spk_mask
|= eld_speaker_allocation_bits
[i
];
604 /* search for the first working match in the CA table */
605 for (i
= 0; i
< ARRAY_SIZE(channel_allocations
); i
++) {
606 if (channels
== channel_allocations
[i
].channels
&&
607 (spk_mask
& channel_allocations
[i
].spk_mask
) ==
608 channel_allocations
[i
].spk_mask
) {
609 ai
->CA
= channel_allocations
[i
].ca_index
;
614 snd_print_channel_allocation(eld
->spk_alloc
, buf
, sizeof(buf
));
615 snd_printdd(KERN_INFO
616 "HDMI: select CA 0x%x for %d-channel allocation: %s\n",
617 ai
->CA
, channels
, buf
);
622 static void hdmi_setup_channel_mapping(struct hda_codec
*codec
, hda_nid_t nid
,
623 struct hdmi_audio_infoframe
*ai
)
631 * TODO: adjust channel mapping if necessary
632 * ALSA sequence is front/surr/clfe/side?
635 for (i
= 0; i
< 8; i
++)
636 snd_hda_codec_write(codec
, nid
, 0,
637 AC_VERB_SET_HDMI_CHAN_SLOT
,
640 hdmi_debug_channel_mapping(codec
, nid
);
643 static bool hdmi_infoframe_uptodate(struct hda_codec
*codec
, hda_nid_t pin_nid
,
644 struct hdmi_audio_infoframe
*ai
)
646 u8
*bytes
= (u8
*)ai
;
650 if (snd_hda_codec_read(codec
, pin_nid
, 0, AC_VERB_GET_HDMI_DIP_XMIT
, 0)
654 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
655 for (i
= 0; i
< sizeof(*ai
); i
++) {
656 val
= snd_hda_codec_read(codec
, pin_nid
, 0,
657 AC_VERB_GET_HDMI_DIP_DATA
, 0);
665 static void hdmi_setup_audio_infoframe(struct hda_codec
*codec
, hda_nid_t nid
,
666 struct snd_pcm_substream
*substream
)
668 struct intel_hdmi_spec
*spec
= codec
->spec
;
671 struct hdmi_audio_infoframe ai
= {
675 .CC02_CT47
= substream
->runtime
->channels
- 1,
678 hdmi_setup_channel_allocation(codec
, nid
, &ai
);
679 hdmi_setup_channel_mapping(codec
, nid
, &ai
);
681 for (i
= 0; i
< spec
->num_pins
; i
++) {
682 if (spec
->pin_cvt
[i
] != nid
)
684 if (!spec
->sink_eld
[i
].monitor_present
)
687 pin_nid
= spec
->pin
[i
];
688 if (!hdmi_infoframe_uptodate(codec
, pin_nid
, &ai
)) {
689 hdmi_stop_infoframe_trans(codec
, pin_nid
);
690 hdmi_fill_audio_infoframe(codec
, pin_nid
, &ai
);
691 hdmi_start_infoframe_trans(codec
, pin_nid
);
701 static void hdmi_intrinsic_event(struct hda_codec
*codec
, unsigned int res
)
703 struct intel_hdmi_spec
*spec
= codec
->spec
;
704 int tag
= res
>> AC_UNSOL_RES_TAG_SHIFT
;
705 int pind
= !!(res
& AC_UNSOL_RES_PD
);
706 int eldv
= !!(res
& AC_UNSOL_RES_ELDV
);
710 "HDMI hot plug event: Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
713 index
= hda_node_index(spec
->pin
, tag
);
717 spec
->sink_eld
[index
].monitor_present
= pind
;
718 spec
->sink_eld
[index
].eld_valid
= eldv
;
721 hdmi_get_show_eld(codec
, spec
->pin
[index
], &spec
->sink_eld
[index
]);
722 /* TODO: do real things about ELD */
726 static void hdmi_non_intrinsic_event(struct hda_codec
*codec
, unsigned int res
)
728 int tag
= res
>> AC_UNSOL_RES_TAG_SHIFT
;
729 int subtag
= (res
& AC_UNSOL_RES_SUBTAG
) >> AC_UNSOL_RES_SUBTAG_SHIFT
;
730 int cp_state
= !!(res
& AC_UNSOL_RES_CP_STATE
);
731 int cp_ready
= !!(res
& AC_UNSOL_RES_CP_READY
);
734 "HDMI CP event: PIN=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
748 static void intel_hdmi_unsol_event(struct hda_codec
*codec
, unsigned int res
)
750 struct intel_hdmi_spec
*spec
= codec
->spec
;
751 int tag
= res
>> AC_UNSOL_RES_TAG_SHIFT
;
752 int subtag
= (res
& AC_UNSOL_RES_SUBTAG
) >> AC_UNSOL_RES_SUBTAG_SHIFT
;
754 if (hda_node_index(spec
->pin
, tag
) < 0) {
755 snd_printd(KERN_INFO
"Unexpected HDMI event tag 0x%x\n", tag
);
760 hdmi_intrinsic_event(codec
, res
);
762 hdmi_non_intrinsic_event(codec
, res
);
769 static void hdmi_setup_stream(struct hda_codec
*codec
, hda_nid_t nid
,
770 u32 stream_tag
, int format
)
775 tag
= snd_hda_codec_read(codec
, nid
, 0, AC_VERB_GET_CONV
, 0) >> 4;
776 fmt
= snd_hda_codec_read(codec
, nid
, 0, AC_VERB_GET_STREAM_FORMAT
, 0);
778 snd_printdd("hdmi_setup_stream: "
779 "NID=0x%x, %sstream=0x%x, %sformat=0x%x\n",
781 tag
== stream_tag
? "" : "new-",
783 fmt
== format
? "" : "new-",
786 if (tag
!= stream_tag
)
787 snd_hda_codec_write(codec
, nid
, 0,
788 AC_VERB_SET_CHANNEL_STREAMID
, stream_tag
<< 4);
790 snd_hda_codec_write(codec
, nid
, 0,
791 AC_VERB_SET_STREAM_FORMAT
, format
);
794 static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
795 struct hda_codec
*codec
,
796 unsigned int stream_tag
,
798 struct snd_pcm_substream
*substream
)
800 hdmi_set_channel_count(codec
, hinfo
->nid
,
801 substream
->runtime
->channels
);
803 hdmi_setup_audio_infoframe(codec
, hinfo
->nid
, substream
);
805 hdmi_setup_stream(codec
, hinfo
->nid
, stream_tag
, format
);
809 static int intel_hdmi_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
810 struct hda_codec
*codec
,
811 struct snd_pcm_substream
*substream
)
816 static struct hda_pcm_stream intel_hdmi_pcm_playback
= {
820 .prepare
= intel_hdmi_playback_pcm_prepare
,
821 .cleanup
= intel_hdmi_playback_pcm_cleanup
,
825 static int intel_hdmi_build_pcms(struct hda_codec
*codec
)
827 struct intel_hdmi_spec
*spec
= codec
->spec
;
828 struct hda_pcm
*info
= spec
->pcm_rec
;
831 codec
->num_pcms
= spec
->num_cvts
;
832 codec
->pcm_info
= info
;
834 for (i
= 0; i
< codec
->num_pcms
; i
++, info
++) {
837 chans
= get_wcaps(codec
, spec
->cvt
[i
]);
838 chans
= get_wcaps_channels(chans
);
840 info
->name
= intel_hdmi_pcm_names
[i
];
841 info
->pcm_type
= HDA_PCM_TYPE_HDMI
;
842 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
843 intel_hdmi_pcm_playback
;
844 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->cvt
[i
];
845 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
= chans
;
851 static int intel_hdmi_build_controls(struct hda_codec
*codec
)
853 struct intel_hdmi_spec
*spec
= codec
->spec
;
857 for (i
= 0; i
< codec
->num_pcms
; i
++) {
858 err
= snd_hda_create_spdif_out_ctls(codec
, spec
->cvt
[i
]);
866 static int intel_hdmi_init(struct hda_codec
*codec
)
868 struct intel_hdmi_spec
*spec
= codec
->spec
;
871 for (i
= 0; spec
->pin
[i
]; i
++) {
872 hdmi_enable_output(codec
, spec
->pin
[i
]);
873 snd_hda_codec_write(codec
, spec
->pin
[i
], 0,
874 AC_VERB_SET_UNSOLICITED_ENABLE
,
875 AC_USRSP_EN
| spec
->pin
[i
]);
880 static void intel_hdmi_free(struct hda_codec
*codec
)
882 struct intel_hdmi_spec
*spec
= codec
->spec
;
885 for (i
= 0; i
< spec
->num_pins
; i
++)
886 snd_hda_eld_proc_free(codec
, &spec
->sink_eld
[i
]);
891 static struct hda_codec_ops intel_hdmi_patch_ops
= {
892 .init
= intel_hdmi_init
,
893 .free
= intel_hdmi_free
,
894 .build_pcms
= intel_hdmi_build_pcms
,
895 .build_controls
= intel_hdmi_build_controls
,
896 .unsol_event
= intel_hdmi_unsol_event
,
899 static int patch_intel_hdmi(struct hda_codec
*codec
)
901 struct intel_hdmi_spec
*spec
;
904 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
909 if (intel_hdmi_parse_codec(codec
) < 0) {
914 codec
->patch_ops
= intel_hdmi_patch_ops
;
916 for (i
= 0; i
< spec
->num_pins
; i
++)
917 snd_hda_eld_proc_new(codec
, &spec
->sink_eld
[i
], i
);
919 init_channel_allocations();
924 static struct hda_codec_preset snd_hda_preset_intelhdmi
[] = {
925 { .id
= 0x808629fb, .name
= "G45 DEVCL", .patch
= patch_intel_hdmi
},
926 { .id
= 0x80862801, .name
= "G45 DEVBLC", .patch
= patch_intel_hdmi
},
927 { .id
= 0x80862802, .name
= "G45 DEVCTG", .patch
= patch_intel_hdmi
},
928 { .id
= 0x80862803, .name
= "G45 DEVELK", .patch
= patch_intel_hdmi
},
929 { .id
= 0x80862804, .name
= "G45 DEVIBX", .patch
= patch_intel_hdmi
},
930 { .id
= 0x80860054, .name
= "Q57 DEVIBX", .patch
= patch_intel_hdmi
},
931 { .id
= 0x10951392, .name
= "SiI1392 HDMI", .patch
= patch_intel_hdmi
},
935 MODULE_ALIAS("snd-hda-codec-id:808629fb");
936 MODULE_ALIAS("snd-hda-codec-id:80862801");
937 MODULE_ALIAS("snd-hda-codec-id:80862802");
938 MODULE_ALIAS("snd-hda-codec-id:80862803");
939 MODULE_ALIAS("snd-hda-codec-id:80862804");
940 MODULE_ALIAS("snd-hda-codec-id:80860054");
941 MODULE_ALIAS("snd-hda-codec-id:10951392");
943 MODULE_LICENSE("GPL");
944 MODULE_DESCRIPTION("Intel HDMI HD-audio codec");
946 static struct hda_codec_preset_list intel_list
= {
947 .preset
= snd_hda_preset_intelhdmi
,
948 .owner
= THIS_MODULE
,
951 static int __init
patch_intelhdmi_init(void)
953 return snd_hda_add_codec_preset(&intel_list
);
956 static void __exit
patch_intelhdmi_exit(void)
958 snd_hda_delete_codec_preset(&intel_list
);
961 module_init(patch_intelhdmi_init
)
962 module_exit(patch_intelhdmi_exit
)