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>
11 * Wu Fengguang <wfg@linux.intel.com>
14 * Wu Fengguang <wfg@linux.intel.com>
16 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the Free
18 * Software Foundation; either version 2 of the License, or (at your option)
21 * This program is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software Foundation,
28 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include <linux/init.h>
32 #include <linux/delay.h>
33 #include <linux/slab.h>
34 #include <linux/moduleparam.h>
35 #include <sound/core.h>
36 #include <sound/jack.h>
37 #include "hda_codec.h"
38 #include "hda_local.h"
40 static bool static_hdmi_pcm
;
41 module_param(static_hdmi_pcm
, bool, 0644);
42 MODULE_PARM_DESC(static_hdmi_pcm
, "Don't restrict PCM parameters per ELD info");
45 * The HDMI/DisplayPort configuration can be highly dynamic. A graphics device
46 * could support two independent pipes, each of them can be connected to one or
47 * more ports (DVI, HDMI or DisplayPort).
49 * The HDA correspondence of pipes/ports are converter/pin nodes.
51 #define MAX_HDMI_CVTS 4
52 #define MAX_HDMI_PINS 4
57 hda_nid_t cvt
[MAX_HDMI_CVTS
+1]; /* audio sources */
58 hda_nid_t pin
[MAX_HDMI_PINS
+1]; /* audio sinks */
61 * source connection for each pin
63 hda_nid_t pin_cvt
[MAX_HDMI_PINS
+1];
66 * HDMI sink attached to each pin
68 struct hdmi_eld sink_eld
[MAX_HDMI_PINS
];
71 * export one pcm per pipe
73 struct hda_pcm pcm_rec
[MAX_HDMI_CVTS
];
74 struct hda_pcm_stream codec_pcm_pars
[MAX_HDMI_CVTS
];
79 struct hda_multi_out multiout
;
80 const struct hda_pcm_stream
*pcm_playback
;
84 struct hdmi_audio_infoframe
{
91 u8 CC02_CT47
; /* CC in bits 0:2, CT in 4:7 */
95 u8 LFEPBL01_LSV36_DM_INH7
;
98 struct dp_audio_infoframe
{
101 u8 ver
; /* 0x11 << 2 */
103 u8 CC02_CT47
; /* match with HDMI infoframe from this on */
107 u8 LFEPBL01_LSV36_DM_INH7
;
110 union audio_infoframe
{
111 struct hdmi_audio_infoframe hdmi
;
112 struct dp_audio_infoframe dp
;
117 * CEA speaker placement:
120 * FLW FL FLC FC FRC FR FRW
127 * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
128 * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
130 enum cea_speaker_placement
{
131 FL
= (1 << 0), /* Front Left */
132 FC
= (1 << 1), /* Front Center */
133 FR
= (1 << 2), /* Front Right */
134 FLC
= (1 << 3), /* Front Left Center */
135 FRC
= (1 << 4), /* Front Right Center */
136 RL
= (1 << 5), /* Rear Left */
137 RC
= (1 << 6), /* Rear Center */
138 RR
= (1 << 7), /* Rear Right */
139 RLC
= (1 << 8), /* Rear Left Center */
140 RRC
= (1 << 9), /* Rear Right Center */
141 LFE
= (1 << 10), /* Low Frequency Effect */
142 FLW
= (1 << 11), /* Front Left Wide */
143 FRW
= (1 << 12), /* Front Right Wide */
144 FLH
= (1 << 13), /* Front Left High */
145 FCH
= (1 << 14), /* Front Center High */
146 FRH
= (1 << 15), /* Front Right High */
147 TC
= (1 << 16), /* Top Center */
151 * ELD SA bits in the CEA Speaker Allocation data block
153 static int eld_speaker_allocation_bits
[] = {
161 /* the following are not defined in ELD yet */
168 struct cea_channel_speaker_allocation
{
172 /* derived values, just for convenience */
180 * surround40 surround41 surround50 surround51 surround71
181 * ch0 front left = = = =
182 * ch1 front right = = = =
183 * ch2 rear left = = = =
184 * ch3 rear right = = = =
185 * ch4 LFE center center center
190 * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR}
192 static int hdmi_channel_mapping
[0x32][8] = {
194 [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
196 [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
198 [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 },
200 [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 },
202 [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 },
204 [0x09] = { 0x00, 0x11, 0x24, 0x35, 0x42, 0xf3, 0xf6, 0xf7 },
206 [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 },
208 [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 },
210 [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 },
214 * This is an ordered list!
216 * The preceding ones have better chances to be selected by
217 * hdmi_channel_allocation().
219 static struct cea_channel_speaker_allocation channel_allocations
[] = {
220 /* channel: 7 6 5 4 3 2 1 0 */
221 { .ca_index
= 0x00, .speakers
= { 0, 0, 0, 0, 0, 0, FR
, FL
} },
223 { .ca_index
= 0x01, .speakers
= { 0, 0, 0, 0, 0, LFE
, FR
, FL
} },
225 { .ca_index
= 0x02, .speakers
= { 0, 0, 0, 0, FC
, 0, FR
, FL
} },
227 { .ca_index
= 0x08, .speakers
= { 0, 0, RR
, RL
, 0, 0, FR
, FL
} },
229 { .ca_index
= 0x09, .speakers
= { 0, 0, RR
, RL
, 0, LFE
, FR
, FL
} },
231 { .ca_index
= 0x0a, .speakers
= { 0, 0, RR
, RL
, FC
, 0, FR
, FL
} },
233 { .ca_index
= 0x0b, .speakers
= { 0, 0, RR
, RL
, FC
, LFE
, FR
, FL
} },
235 { .ca_index
= 0x0f, .speakers
= { 0, RC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
237 { .ca_index
= 0x13, .speakers
= { RRC
, RLC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
239 { .ca_index
= 0x03, .speakers
= { 0, 0, 0, 0, FC
, LFE
, FR
, FL
} },
240 { .ca_index
= 0x04, .speakers
= { 0, 0, 0, RC
, 0, 0, FR
, FL
} },
241 { .ca_index
= 0x05, .speakers
= { 0, 0, 0, RC
, 0, LFE
, FR
, FL
} },
242 { .ca_index
= 0x06, .speakers
= { 0, 0, 0, RC
, FC
, 0, FR
, FL
} },
243 { .ca_index
= 0x07, .speakers
= { 0, 0, 0, RC
, FC
, LFE
, FR
, FL
} },
244 { .ca_index
= 0x0c, .speakers
= { 0, RC
, RR
, RL
, 0, 0, FR
, FL
} },
245 { .ca_index
= 0x0d, .speakers
= { 0, RC
, RR
, RL
, 0, LFE
, FR
, FL
} },
246 { .ca_index
= 0x0e, .speakers
= { 0, RC
, RR
, RL
, FC
, 0, FR
, FL
} },
247 { .ca_index
= 0x10, .speakers
= { RRC
, RLC
, RR
, RL
, 0, 0, FR
, FL
} },
248 { .ca_index
= 0x11, .speakers
= { RRC
, RLC
, RR
, RL
, 0, LFE
, FR
, FL
} },
249 { .ca_index
= 0x12, .speakers
= { RRC
, RLC
, RR
, RL
, FC
, 0, FR
, FL
} },
250 { .ca_index
= 0x14, .speakers
= { FRC
, FLC
, 0, 0, 0, 0, FR
, FL
} },
251 { .ca_index
= 0x15, .speakers
= { FRC
, FLC
, 0, 0, 0, LFE
, FR
, FL
} },
252 { .ca_index
= 0x16, .speakers
= { FRC
, FLC
, 0, 0, FC
, 0, FR
, FL
} },
253 { .ca_index
= 0x17, .speakers
= { FRC
, FLC
, 0, 0, FC
, LFE
, FR
, FL
} },
254 { .ca_index
= 0x18, .speakers
= { FRC
, FLC
, 0, RC
, 0, 0, FR
, FL
} },
255 { .ca_index
= 0x19, .speakers
= { FRC
, FLC
, 0, RC
, 0, LFE
, FR
, FL
} },
256 { .ca_index
= 0x1a, .speakers
= { FRC
, FLC
, 0, RC
, FC
, 0, FR
, FL
} },
257 { .ca_index
= 0x1b, .speakers
= { FRC
, FLC
, 0, RC
, FC
, LFE
, FR
, FL
} },
258 { .ca_index
= 0x1c, .speakers
= { FRC
, FLC
, RR
, RL
, 0, 0, FR
, FL
} },
259 { .ca_index
= 0x1d, .speakers
= { FRC
, FLC
, RR
, RL
, 0, LFE
, FR
, FL
} },
260 { .ca_index
= 0x1e, .speakers
= { FRC
, FLC
, RR
, RL
, FC
, 0, FR
, FL
} },
261 { .ca_index
= 0x1f, .speakers
= { FRC
, FLC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
262 { .ca_index
= 0x20, .speakers
= { 0, FCH
, RR
, RL
, FC
, 0, FR
, FL
} },
263 { .ca_index
= 0x21, .speakers
= { 0, FCH
, RR
, RL
, FC
, LFE
, FR
, FL
} },
264 { .ca_index
= 0x22, .speakers
= { TC
, 0, RR
, RL
, FC
, 0, FR
, FL
} },
265 { .ca_index
= 0x23, .speakers
= { TC
, 0, RR
, RL
, FC
, LFE
, FR
, FL
} },
266 { .ca_index
= 0x24, .speakers
= { FRH
, FLH
, RR
, RL
, 0, 0, FR
, FL
} },
267 { .ca_index
= 0x25, .speakers
= { FRH
, FLH
, RR
, RL
, 0, LFE
, FR
, FL
} },
268 { .ca_index
= 0x26, .speakers
= { FRW
, FLW
, RR
, RL
, 0, 0, FR
, FL
} },
269 { .ca_index
= 0x27, .speakers
= { FRW
, FLW
, RR
, RL
, 0, LFE
, FR
, FL
} },
270 { .ca_index
= 0x28, .speakers
= { TC
, RC
, RR
, RL
, FC
, 0, FR
, FL
} },
271 { .ca_index
= 0x29, .speakers
= { TC
, RC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
272 { .ca_index
= 0x2a, .speakers
= { FCH
, RC
, RR
, RL
, FC
, 0, FR
, FL
} },
273 { .ca_index
= 0x2b, .speakers
= { FCH
, RC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
274 { .ca_index
= 0x2c, .speakers
= { TC
, FCH
, RR
, RL
, FC
, 0, FR
, FL
} },
275 { .ca_index
= 0x2d, .speakers
= { TC
, FCH
, RR
, RL
, FC
, LFE
, FR
, FL
} },
276 { .ca_index
= 0x2e, .speakers
= { FRH
, FLH
, RR
, RL
, FC
, 0, FR
, FL
} },
277 { .ca_index
= 0x2f, .speakers
= { FRH
, FLH
, RR
, RL
, FC
, LFE
, FR
, FL
} },
278 { .ca_index
= 0x30, .speakers
= { FRW
, FLW
, RR
, RL
, FC
, 0, FR
, FL
} },
279 { .ca_index
= 0x31, .speakers
= { FRW
, FLW
, RR
, RL
, FC
, LFE
, FR
, FL
} },
287 static int hda_node_index(hda_nid_t
*nids
, hda_nid_t nid
)
291 for (i
= 0; nids
[i
]; i
++)
295 snd_printk(KERN_WARNING
"HDMI: nid %d not registered\n", nid
);
300 static void hdmi_get_dip_index(struct hda_codec
*codec
, hda_nid_t pin_nid
,
301 int *packet_index
, int *byte_index
)
305 val
= snd_hda_codec_read(codec
, pin_nid
, 0,
306 AC_VERB_GET_HDMI_DIP_INDEX
, 0);
308 *packet_index
= val
>> 5;
309 *byte_index
= val
& 0x1f;
313 static void hdmi_set_dip_index(struct hda_codec
*codec
, hda_nid_t pin_nid
,
314 int packet_index
, int byte_index
)
318 val
= (packet_index
<< 5) | (byte_index
& 0x1f);
320 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_INDEX
, val
);
323 static void hdmi_write_dip_byte(struct hda_codec
*codec
, hda_nid_t pin_nid
,
326 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_DATA
, val
);
329 static void hdmi_enable_output(struct hda_codec
*codec
, hda_nid_t pin_nid
)
332 if (get_wcaps(codec
, pin_nid
) & AC_WCAP_OUT_AMP
)
333 snd_hda_codec_write(codec
, pin_nid
, 0,
334 AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
);
336 snd_hda_codec_write(codec
, pin_nid
, 0,
337 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
);
340 static int hdmi_get_channel_count(struct hda_codec
*codec
, hda_nid_t nid
)
342 return 1 + snd_hda_codec_read(codec
, nid
, 0,
343 AC_VERB_GET_CVT_CHAN_COUNT
, 0);
346 static void hdmi_set_channel_count(struct hda_codec
*codec
,
347 hda_nid_t nid
, int chs
)
349 if (chs
!= hdmi_get_channel_count(codec
, nid
))
350 snd_hda_codec_write(codec
, nid
, 0,
351 AC_VERB_SET_CVT_CHAN_COUNT
, chs
- 1);
356 * Channel mapping routines
360 * Compute derived values in channel_allocations[].
362 static void init_channel_allocations(void)
365 struct cea_channel_speaker_allocation
*p
;
367 for (i
= 0; i
< ARRAY_SIZE(channel_allocations
); i
++) {
368 p
= channel_allocations
+ i
;
371 for (j
= 0; j
< ARRAY_SIZE(p
->speakers
); j
++)
372 if (p
->speakers
[j
]) {
374 p
->spk_mask
|= p
->speakers
[j
];
380 * The transformation takes two steps:
382 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
383 * spk_mask => (channel_allocations[]) => ai->CA
385 * TODO: it could select the wrong CA from multiple candidates.
387 static int hdmi_channel_allocation(struct hda_codec
*codec
, hda_nid_t nid
,
390 struct hdmi_spec
*spec
= codec
->spec
;
391 struct hdmi_eld
*eld
;
395 char buf
[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE
];
398 * CA defaults to 0 for basic stereo audio
403 i
= hda_node_index(spec
->pin_cvt
, nid
);
406 eld
= &spec
->sink_eld
[i
];
409 * HDMI sink's ELD info cannot always be retrieved for now, e.g.
410 * in console or for audio devices. Assume the highest speakers
411 * configuration, to _not_ prohibit multi-channel audio playback.
414 eld
->spk_alloc
= 0xffff;
417 * expand ELD's speaker allocation mask
419 * ELD tells the speaker mask in a compact(paired) form,
420 * expand ELD's notions to match the ones used by Audio InfoFrame.
422 for (i
= 0; i
< ARRAY_SIZE(eld_speaker_allocation_bits
); i
++) {
423 if (eld
->spk_alloc
& (1 << i
))
424 spk_mask
|= eld_speaker_allocation_bits
[i
];
427 /* search for the first working match in the CA table */
428 for (i
= 0; i
< ARRAY_SIZE(channel_allocations
); i
++) {
429 if (channels
== channel_allocations
[i
].channels
&&
430 (spk_mask
& channel_allocations
[i
].spk_mask
) ==
431 channel_allocations
[i
].spk_mask
) {
432 ca
= channel_allocations
[i
].ca_index
;
437 snd_print_channel_allocation(eld
->spk_alloc
, buf
, sizeof(buf
));
438 snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n",
444 static void hdmi_debug_channel_mapping(struct hda_codec
*codec
,
447 #ifdef CONFIG_SND_DEBUG_VERBOSE
451 for (i
= 0; i
< 8; i
++) {
452 slot
= snd_hda_codec_read(codec
, pin_nid
, 0,
453 AC_VERB_GET_HDMI_CHAN_SLOT
, i
);
454 printk(KERN_DEBUG
"HDMI: ASP channel %d => slot %d\n",
455 slot
>> 4, slot
& 0xf);
461 static void hdmi_setup_channel_mapping(struct hda_codec
*codec
,
468 if (hdmi_channel_mapping
[ca
][1] == 0) {
469 for (i
= 0; i
< channel_allocations
[ca
].channels
; i
++)
470 hdmi_channel_mapping
[ca
][i
] = i
| (i
<< 4);
472 hdmi_channel_mapping
[ca
][i
] = 0xf | (i
<< 4);
475 for (i
= 0; i
< 8; i
++) {
476 err
= snd_hda_codec_write(codec
, pin_nid
, 0,
477 AC_VERB_SET_HDMI_CHAN_SLOT
,
478 hdmi_channel_mapping
[ca
][i
]);
480 snd_printdd(KERN_NOTICE
481 "HDMI: channel mapping failed\n");
486 hdmi_debug_channel_mapping(codec
, pin_nid
);
491 * Audio InfoFrame routines
495 * Enable Audio InfoFrame Transmission
497 static void hdmi_start_infoframe_trans(struct hda_codec
*codec
,
500 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
501 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_XMIT
,
506 * Disable Audio InfoFrame Transmission
508 static void hdmi_stop_infoframe_trans(struct hda_codec
*codec
,
511 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
512 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_XMIT
,
516 static void hdmi_debug_dip_size(struct hda_codec
*codec
, hda_nid_t pin_nid
)
518 #ifdef CONFIG_SND_DEBUG_VERBOSE
522 size
= snd_hdmi_get_eld_size(codec
, pin_nid
);
523 printk(KERN_DEBUG
"HDMI: ELD buf size is %d\n", size
);
525 for (i
= 0; i
< 8; i
++) {
526 size
= snd_hda_codec_read(codec
, pin_nid
, 0,
527 AC_VERB_GET_HDMI_DIP_SIZE
, i
);
528 printk(KERN_DEBUG
"HDMI: DIP GP[%d] buf size is %d\n", i
, size
);
533 static void hdmi_clear_dip_buffers(struct hda_codec
*codec
, hda_nid_t pin_nid
)
539 for (i
= 0; i
< 8; i
++) {
540 size
= snd_hda_codec_read(codec
, pin_nid
, 0,
541 AC_VERB_GET_HDMI_DIP_SIZE
, i
);
545 hdmi_set_dip_index(codec
, pin_nid
, i
, 0x0);
546 for (j
= 1; j
< 1000; j
++) {
547 hdmi_write_dip_byte(codec
, pin_nid
, 0x0);
548 hdmi_get_dip_index(codec
, pin_nid
, &pi
, &bi
);
550 snd_printd(KERN_INFO
"dip index %d: %d != %d\n",
552 if (bi
== 0) /* byte index wrapped around */
556 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
562 static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe
*hdmi_ai
)
564 u8
*bytes
= (u8
*)hdmi_ai
;
568 hdmi_ai
->checksum
= 0;
570 for (i
= 0; i
< sizeof(*hdmi_ai
); i
++)
573 hdmi_ai
->checksum
= -sum
;
576 static void hdmi_fill_audio_infoframe(struct hda_codec
*codec
,
582 hdmi_debug_dip_size(codec
, pin_nid
);
583 hdmi_clear_dip_buffers(codec
, pin_nid
); /* be paranoid */
585 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
586 for (i
= 0; i
< size
; i
++)
587 hdmi_write_dip_byte(codec
, pin_nid
, dip
[i
]);
590 static bool hdmi_infoframe_uptodate(struct hda_codec
*codec
, hda_nid_t pin_nid
,
596 if (snd_hda_codec_read(codec
, pin_nid
, 0, AC_VERB_GET_HDMI_DIP_XMIT
, 0)
600 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
601 for (i
= 0; i
< size
; i
++) {
602 val
= snd_hda_codec_read(codec
, pin_nid
, 0,
603 AC_VERB_GET_HDMI_DIP_DATA
, 0);
611 static void hdmi_setup_audio_infoframe(struct hda_codec
*codec
, hda_nid_t nid
,
612 struct snd_pcm_substream
*substream
)
614 struct hdmi_spec
*spec
= codec
->spec
;
616 int channels
= substream
->runtime
->channels
;
619 union audio_infoframe ai
;
621 ca
= hdmi_channel_allocation(codec
, nid
, channels
);
623 for (i
= 0; i
< spec
->num_pins
; i
++) {
624 if (spec
->pin_cvt
[i
] != nid
)
626 if (!spec
->sink_eld
[i
].monitor_present
)
629 pin_nid
= spec
->pin
[i
];
631 memset(&ai
, 0, sizeof(ai
));
632 if (spec
->sink_eld
[i
].conn_type
== 0) { /* HDMI */
633 struct hdmi_audio_infoframe
*hdmi_ai
= &ai
.hdmi
;
635 hdmi_ai
->type
= 0x84;
638 hdmi_ai
->CC02_CT47
= channels
- 1;
640 hdmi_checksum_audio_infoframe(hdmi_ai
);
641 } else if (spec
->sink_eld
[i
].conn_type
== 1) { /* DisplayPort */
642 struct dp_audio_infoframe
*dp_ai
= &ai
.dp
;
646 dp_ai
->ver
= 0x11 << 2;
647 dp_ai
->CC02_CT47
= channels
- 1;
650 snd_printd("HDMI: unknown connection type at pin %d\n",
656 * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
657 * sizeof(*dp_ai) to avoid partial match/update problems when
658 * the user switches between HDMI/DP monitors.
660 if (!hdmi_infoframe_uptodate(codec
, pin_nid
, ai
.bytes
,
662 snd_printdd("hdmi_setup_audio_infoframe: "
663 "cvt=%d pin=%d channels=%d\n",
666 hdmi_setup_channel_mapping(codec
, pin_nid
, ca
);
667 hdmi_stop_infoframe_trans(codec
, pin_nid
);
668 hdmi_fill_audio_infoframe(codec
, pin_nid
,
669 ai
.bytes
, sizeof(ai
));
670 hdmi_start_infoframe_trans(codec
, pin_nid
);
680 static void hdmi_present_sense(struct hda_codec
*codec
, hda_nid_t pin_nid
,
681 struct hdmi_eld
*eld
);
683 static void hdmi_intrinsic_event(struct hda_codec
*codec
, unsigned int res
)
685 struct hdmi_spec
*spec
= codec
->spec
;
686 int pin_nid
= res
>> AC_UNSOL_RES_TAG_SHIFT
;
687 int pd
= !!(res
& AC_UNSOL_RES_PD
);
688 int eldv
= !!(res
& AC_UNSOL_RES_ELDV
);
692 "HDMI hot plug event: Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
695 index
= hda_node_index(spec
->pin
, pin_nid
);
699 hdmi_present_sense(codec
, pin_nid
, &spec
->sink_eld
[index
]);
702 static void hdmi_non_intrinsic_event(struct hda_codec
*codec
, unsigned int res
)
704 int tag
= res
>> AC_UNSOL_RES_TAG_SHIFT
;
705 int subtag
= (res
& AC_UNSOL_RES_SUBTAG
) >> AC_UNSOL_RES_SUBTAG_SHIFT
;
706 int cp_state
= !!(res
& AC_UNSOL_RES_CP_STATE
);
707 int cp_ready
= !!(res
& AC_UNSOL_RES_CP_READY
);
710 "HDMI CP event: PIN=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
724 static void hdmi_unsol_event(struct hda_codec
*codec
, unsigned int res
)
726 struct hdmi_spec
*spec
= codec
->spec
;
727 int tag
= res
>> AC_UNSOL_RES_TAG_SHIFT
;
728 int subtag
= (res
& AC_UNSOL_RES_SUBTAG
) >> AC_UNSOL_RES_SUBTAG_SHIFT
;
730 if (hda_node_index(spec
->pin
, tag
) < 0) {
731 snd_printd(KERN_INFO
"Unexpected HDMI event tag 0x%x\n", tag
);
736 hdmi_intrinsic_event(codec
, res
);
738 hdmi_non_intrinsic_event(codec
, res
);
745 /* HBR should be Non-PCM, 8 channels */
746 #define is_hbr_format(format) \
747 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
749 static int hdmi_setup_stream(struct hda_codec
*codec
, hda_nid_t nid
,
750 u32 stream_tag
, int format
)
752 struct hdmi_spec
*spec
= codec
->spec
;
757 for (i
= 0; i
< spec
->num_pins
; i
++) {
758 if (spec
->pin_cvt
[i
] != nid
)
760 if (!(snd_hda_query_pin_caps(codec
, spec
->pin
[i
]) & AC_PINCAP_HBR
))
763 pinctl
= snd_hda_codec_read(codec
, spec
->pin
[i
], 0,
764 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
766 new_pinctl
= pinctl
& ~AC_PINCTL_EPT
;
767 if (is_hbr_format(format
))
768 new_pinctl
|= AC_PINCTL_EPT_HBR
;
770 new_pinctl
|= AC_PINCTL_EPT_NATIVE
;
772 snd_printdd("hdmi_setup_stream: "
773 "NID=0x%x, %spinctl=0x%x\n",
775 pinctl
== new_pinctl
? "" : "new-",
778 if (pinctl
!= new_pinctl
)
779 snd_hda_codec_write(codec
, spec
->pin
[i
], 0,
780 AC_VERB_SET_PIN_WIDGET_CONTROL
,
784 if (is_hbr_format(format
) && !new_pinctl
) {
785 snd_printdd("hdmi_setup_stream: HBR is not supported\n");
789 snd_hda_codec_setup_stream(codec
, nid
, stream_tag
, 0, format
);
796 static int hdmi_pcm_open(struct hda_pcm_stream
*hinfo
,
797 struct hda_codec
*codec
,
798 struct snd_pcm_substream
*substream
)
800 struct hdmi_spec
*spec
= codec
->spec
;
801 struct hdmi_eld
*eld
;
802 struct hda_pcm_stream
*codec_pars
;
803 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
806 for (idx
= 0; idx
< spec
->num_cvts
; idx
++)
807 if (hinfo
->nid
== spec
->cvt
[idx
])
809 if (snd_BUG_ON(idx
>= spec
->num_cvts
) ||
810 snd_BUG_ON(idx
>= spec
->num_pins
))
813 /* save the PCM info the codec provides */
814 codec_pars
= &spec
->codec_pcm_pars
[idx
];
815 if (!codec_pars
->rates
)
816 *codec_pars
= *hinfo
;
818 eld
= &spec
->sink_eld
[idx
];
819 if (!static_hdmi_pcm
&& eld
->eld_valid
&& eld
->sad_count
> 0) {
820 hdmi_eld_update_pcm_info(eld
, hinfo
, codec_pars
);
821 if (hinfo
->channels_min
> hinfo
->channels_max
||
822 !hinfo
->rates
|| !hinfo
->formats
)
825 /* fallback to the codec default */
826 hinfo
->channels_max
= codec_pars
->channels_max
;
827 hinfo
->rates
= codec_pars
->rates
;
828 hinfo
->formats
= codec_pars
->formats
;
829 hinfo
->maxbps
= codec_pars
->maxbps
;
831 /* store the updated parameters */
832 runtime
->hw
.channels_min
= hinfo
->channels_min
;
833 runtime
->hw
.channels_max
= hinfo
->channels_max
;
834 runtime
->hw
.formats
= hinfo
->formats
;
835 runtime
->hw
.rates
= hinfo
->rates
;
837 snd_pcm_hw_constraint_step(substream
->runtime
, 0,
838 SNDRV_PCM_HW_PARAM_CHANNELS
, 2);
843 * HDA/HDMI auto parsing
845 static int hdmi_read_pin_conn(struct hda_codec
*codec
, hda_nid_t pin_nid
)
847 struct hdmi_spec
*spec
= codec
->spec
;
848 hda_nid_t conn_list
[HDA_MAX_CONNECTIONS
];
852 if (!(get_wcaps(codec
, pin_nid
) & AC_WCAP_CONN_LIST
)) {
853 snd_printk(KERN_WARNING
854 "HDMI: pin %d wcaps %#x "
855 "does not support connection list\n",
856 pin_nid
, get_wcaps(codec
, pin_nid
));
860 conn_len
= snd_hda_get_connections(codec
, pin_nid
, conn_list
,
861 HDA_MAX_CONNECTIONS
);
863 curr
= snd_hda_codec_read(codec
, pin_nid
, 0,
864 AC_VERB_GET_CONNECT_SEL
, 0);
868 index
= hda_node_index(spec
->pin
, pin_nid
);
872 spec
->pin_cvt
[index
] = conn_list
[curr
];
877 static void hdmi_present_sense(struct hda_codec
*codec
, hda_nid_t pin_nid
,
878 struct hdmi_eld
*eld
)
881 * Always execute a GetPinSense verb here, even when called from
882 * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
883 * response's PD bit is not the real PD value, but indicates that
884 * the real PD value changed. An older version of the HD-audio
885 * specification worked this way. Hence, we just ignore the data in
886 * the unsolicited response to avoid custom WARs.
888 int present
= snd_hda_pin_sense(codec
, pin_nid
);
890 memset(eld
, 0, sizeof(*eld
));
892 eld
->monitor_present
= !!(present
& AC_PINSENSE_PRESENCE
);
893 if (eld
->monitor_present
)
894 eld
->eld_valid
= !!(present
& AC_PINSENSE_ELDV
);
899 "HDMI status: Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
900 pin_nid
, eld
->monitor_present
, eld
->eld_valid
);
903 if (!snd_hdmi_get_eld(eld
, codec
, pin_nid
))
904 snd_hdmi_show_eld(eld
);
906 snd_hda_input_jack_report(codec
, pin_nid
);
909 static int hdmi_add_pin(struct hda_codec
*codec
, hda_nid_t pin_nid
)
911 struct hdmi_spec
*spec
= codec
->spec
;
914 if (spec
->num_pins
>= MAX_HDMI_PINS
) {
915 snd_printk(KERN_WARNING
916 "HDMI: no space for pin %d\n", pin_nid
);
920 err
= snd_hda_input_jack_add(codec
, pin_nid
,
921 SND_JACK_VIDEOOUT
, NULL
);
925 hdmi_present_sense(codec
, pin_nid
, &spec
->sink_eld
[spec
->num_pins
]);
927 spec
->pin
[spec
->num_pins
] = pin_nid
;
930 return hdmi_read_pin_conn(codec
, pin_nid
);
933 static int hdmi_add_cvt(struct hda_codec
*codec
, hda_nid_t nid
)
935 int i
, found_pin
= 0;
936 struct hdmi_spec
*spec
= codec
->spec
;
938 for (i
= 0; i
< spec
->num_pins
; i
++)
939 if (nid
== spec
->pin_cvt
[i
]) {
945 snd_printdd("HDMI: Skipping node %d (no connection)\n", nid
);
949 if (snd_BUG_ON(spec
->num_cvts
>= MAX_HDMI_CVTS
))
952 spec
->cvt
[spec
->num_cvts
] = nid
;
958 static int hdmi_parse_codec(struct hda_codec
*codec
)
962 int num_tmp_cvts
= 0;
963 hda_nid_t tmp_cvt
[MAX_HDMI_CVTS
];
965 nodes
= snd_hda_get_sub_nodes(codec
, codec
->afg
, &nid
);
966 if (!nid
|| nodes
< 0) {
967 snd_printk(KERN_WARNING
"HDMI: failed to get afg sub nodes\n");
971 for (i
= 0; i
< nodes
; i
++, nid
++) {
976 caps
= snd_hda_param_read(codec
, nid
, AC_PAR_AUDIO_WIDGET_CAP
);
977 type
= get_wcaps_type(caps
);
979 if (!(caps
& AC_WCAP_DIGITAL
))
984 if (num_tmp_cvts
>= MAX_HDMI_CVTS
) {
985 snd_printk(KERN_WARNING
986 "HDMI: no space for converter %d\n", nid
);
989 tmp_cvt
[num_tmp_cvts
] = nid
;
993 caps
= snd_hda_param_read(codec
, nid
, AC_PAR_PIN_CAP
);
994 if (!(caps
& (AC_PINCAP_HDMI
| AC_PINCAP_DP
)))
997 config
= snd_hda_codec_read(codec
, nid
, 0,
998 AC_VERB_GET_CONFIG_DEFAULT
, 0);
999 if (get_defcfg_connect(config
) == AC_JACK_PORT_NONE
)
1002 hdmi_add_pin(codec
, nid
);
1007 for (i
= 0; i
< num_tmp_cvts
; i
++)
1008 hdmi_add_cvt(codec
, tmp_cvt
[i
]);
1011 * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event
1012 * can be lost and presence sense verb will become inaccurate if the
1013 * HDA link is powered off at hot plug or hw initialization time.
1015 #ifdef CONFIG_SND_HDA_POWER_SAVE
1016 if (!(snd_hda_param_read(codec
, codec
->afg
, AC_PAR_POWER_STATE
) &
1018 codec
->bus
->power_keep_link_on
= 1;
1026 static char *generic_hdmi_pcm_names
[MAX_HDMI_CVTS
] = {
1037 static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1038 struct hda_codec
*codec
,
1039 unsigned int stream_tag
,
1040 unsigned int format
,
1041 struct snd_pcm_substream
*substream
)
1043 hdmi_set_channel_count(codec
, hinfo
->nid
,
1044 substream
->runtime
->channels
);
1046 hdmi_setup_audio_infoframe(codec
, hinfo
->nid
, substream
);
1048 return hdmi_setup_stream(codec
, hinfo
->nid
, stream_tag
, format
);
1051 static const struct hda_pcm_stream generic_hdmi_pcm_playback
= {
1055 .open
= hdmi_pcm_open
,
1056 .prepare
= generic_hdmi_playback_pcm_prepare
,
1060 static int generic_hdmi_build_pcms(struct hda_codec
*codec
)
1062 struct hdmi_spec
*spec
= codec
->spec
;
1063 struct hda_pcm
*info
= spec
->pcm_rec
;
1066 codec
->num_pcms
= spec
->num_cvts
;
1067 codec
->pcm_info
= info
;
1069 for (i
= 0; i
< codec
->num_pcms
; i
++, info
++) {
1071 struct hda_pcm_stream
*pstr
;
1073 chans
= get_wcaps(codec
, spec
->cvt
[i
]);
1074 chans
= get_wcaps_channels(chans
);
1076 info
->name
= generic_hdmi_pcm_names
[i
];
1077 info
->pcm_type
= HDA_PCM_TYPE_HDMI
;
1078 pstr
= &info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
];
1079 if (spec
->pcm_playback
)
1080 *pstr
= *spec
->pcm_playback
;
1082 *pstr
= generic_hdmi_pcm_playback
;
1083 pstr
->nid
= spec
->cvt
[i
];
1084 if (pstr
->channels_max
<= 2 && chans
&& chans
<= 16)
1085 pstr
->channels_max
= chans
;
1091 static int generic_hdmi_build_controls(struct hda_codec
*codec
)
1093 struct hdmi_spec
*spec
= codec
->spec
;
1097 for (i
= 0; i
< codec
->num_pcms
; i
++) {
1098 err
= snd_hda_create_spdif_out_ctls(codec
, spec
->cvt
[i
]);
1106 static int generic_hdmi_init(struct hda_codec
*codec
)
1108 struct hdmi_spec
*spec
= codec
->spec
;
1111 for (i
= 0; spec
->pin
[i
]; i
++) {
1112 hdmi_enable_output(codec
, spec
->pin
[i
]);
1113 snd_hda_codec_write(codec
, spec
->pin
[i
], 0,
1114 AC_VERB_SET_UNSOLICITED_ENABLE
,
1115 AC_USRSP_EN
| spec
->pin
[i
]);
1120 static void generic_hdmi_free(struct hda_codec
*codec
)
1122 struct hdmi_spec
*spec
= codec
->spec
;
1125 for (i
= 0; i
< spec
->num_pins
; i
++)
1126 snd_hda_eld_proc_free(codec
, &spec
->sink_eld
[i
]);
1127 snd_hda_input_jack_free(codec
);
1132 static const struct hda_codec_ops generic_hdmi_patch_ops
= {
1133 .init
= generic_hdmi_init
,
1134 .free
= generic_hdmi_free
,
1135 .build_pcms
= generic_hdmi_build_pcms
,
1136 .build_controls
= generic_hdmi_build_controls
,
1137 .unsol_event
= hdmi_unsol_event
,
1140 static int patch_generic_hdmi(struct hda_codec
*codec
)
1142 struct hdmi_spec
*spec
;
1145 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1150 if (hdmi_parse_codec(codec
) < 0) {
1155 codec
->patch_ops
= generic_hdmi_patch_ops
;
1157 for (i
= 0; i
< spec
->num_pins
; i
++)
1158 snd_hda_eld_proc_new(codec
, &spec
->sink_eld
[i
], i
);
1160 init_channel_allocations();
1166 * Nvidia specific implementations
1169 #define Nv_VERB_SET_Channel_Allocation 0xF79
1170 #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
1171 #define Nv_VERB_SET_Audio_Protection_On 0xF98
1172 #define Nv_VERB_SET_Audio_Protection_Off 0xF99
1174 #define nvhdmi_master_con_nid_7x 0x04
1175 #define nvhdmi_master_pin_nid_7x 0x05
1177 static const hda_nid_t nvhdmi_con_nids_7x
[4] = {
1178 /*front, rear, clfe, rear_surr */
1182 static const struct hda_verb nvhdmi_basic_init_7x
[] = {
1183 /* set audio protect on */
1184 { 0x1, Nv_VERB_SET_Audio_Protection_On
, 0x1},
1185 /* enable digital output on pin widget */
1186 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
| 0x5 },
1187 { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
| 0x5 },
1188 { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
| 0x5 },
1189 { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
| 0x5 },
1190 { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
| 0x5 },
1194 #ifdef LIMITED_RATE_FMT_SUPPORT
1195 /* support only the safe format and rate */
1196 #define SUPPORTED_RATES SNDRV_PCM_RATE_48000
1197 #define SUPPORTED_MAXBPS 16
1198 #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
1200 /* support all rates and formats */
1201 #define SUPPORTED_RATES \
1202 (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
1203 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
1204 SNDRV_PCM_RATE_192000)
1205 #define SUPPORTED_MAXBPS 24
1206 #define SUPPORTED_FORMATS \
1207 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
1210 static int nvhdmi_7x_init(struct hda_codec
*codec
)
1212 snd_hda_sequence_write(codec
, nvhdmi_basic_init_7x
);
1216 static unsigned int channels_2_6_8
[] = {
1220 static unsigned int channels_2_8
[] = {
1224 static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels
= {
1225 .count
= ARRAY_SIZE(channels_2_6_8
),
1226 .list
= channels_2_6_8
,
1230 static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels
= {
1231 .count
= ARRAY_SIZE(channels_2_8
),
1232 .list
= channels_2_8
,
1236 static int simple_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
1237 struct hda_codec
*codec
,
1238 struct snd_pcm_substream
*substream
)
1240 struct hdmi_spec
*spec
= codec
->spec
;
1241 struct snd_pcm_hw_constraint_list
*hw_constraints_channels
= NULL
;
1243 switch (codec
->preset
->id
) {
1248 hw_constraints_channels
= &hw_constraints_2_8_channels
;
1251 hw_constraints_channels
= &hw_constraints_2_6_8_channels
;
1257 if (hw_constraints_channels
!= NULL
) {
1258 snd_pcm_hw_constraint_list(substream
->runtime
, 0,
1259 SNDRV_PCM_HW_PARAM_CHANNELS
,
1260 hw_constraints_channels
);
1262 snd_pcm_hw_constraint_step(substream
->runtime
, 0,
1263 SNDRV_PCM_HW_PARAM_CHANNELS
, 2);
1266 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
1269 static int simple_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
1270 struct hda_codec
*codec
,
1271 struct snd_pcm_substream
*substream
)
1273 struct hdmi_spec
*spec
= codec
->spec
;
1274 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
1277 static int simple_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1278 struct hda_codec
*codec
,
1279 unsigned int stream_tag
,
1280 unsigned int format
,
1281 struct snd_pcm_substream
*substream
)
1283 struct hdmi_spec
*spec
= codec
->spec
;
1284 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
1285 stream_tag
, format
, substream
);
1288 static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec
*codec
,
1291 unsigned int chanmask
;
1292 int chan
= channels
? (channels
- 1) : 1;
1311 /* Set the audio infoframe channel allocation and checksum fields. The
1312 * channel count is computed implicitly by the hardware. */
1313 snd_hda_codec_write(codec
, 0x1, 0,
1314 Nv_VERB_SET_Channel_Allocation
, chanmask
);
1316 snd_hda_codec_write(codec
, 0x1, 0,
1317 Nv_VERB_SET_Info_Frame_Checksum
,
1318 (0x71 - chan
- chanmask
));
1321 static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream
*hinfo
,
1322 struct hda_codec
*codec
,
1323 struct snd_pcm_substream
*substream
)
1325 struct hdmi_spec
*spec
= codec
->spec
;
1328 snd_hda_codec_write(codec
, nvhdmi_master_con_nid_7x
,
1329 0, AC_VERB_SET_CHANNEL_STREAMID
, 0);
1330 for (i
= 0; i
< 4; i
++) {
1331 /* set the stream id */
1332 snd_hda_codec_write(codec
, nvhdmi_con_nids_7x
[i
], 0,
1333 AC_VERB_SET_CHANNEL_STREAMID
, 0);
1334 /* set the stream format */
1335 snd_hda_codec_write(codec
, nvhdmi_con_nids_7x
[i
], 0,
1336 AC_VERB_SET_STREAM_FORMAT
, 0);
1339 /* The audio hardware sends a channel count of 0x7 (8ch) when all the
1340 * streams are disabled. */
1341 nvhdmi_8ch_7x_set_info_frame_parameters(codec
, 8);
1343 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
1346 static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1347 struct hda_codec
*codec
,
1348 unsigned int stream_tag
,
1349 unsigned int format
,
1350 struct snd_pcm_substream
*substream
)
1353 unsigned int dataDCC1
, dataDCC2
, channel_id
;
1356 mutex_lock(&codec
->spdif_mutex
);
1358 chs
= substream
->runtime
->channels
;
1360 dataDCC1
= AC_DIG1_ENABLE
| AC_DIG1_COPYRIGHT
;
1363 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
1364 if (codec
->spdif_status_reset
&& (codec
->spdif_ctls
& AC_DIG1_ENABLE
))
1365 snd_hda_codec_write(codec
,
1366 nvhdmi_master_con_nid_7x
,
1368 AC_VERB_SET_DIGI_CONVERT_1
,
1369 codec
->spdif_ctls
& ~AC_DIG1_ENABLE
& 0xff);
1371 /* set the stream id */
1372 snd_hda_codec_write(codec
, nvhdmi_master_con_nid_7x
, 0,
1373 AC_VERB_SET_CHANNEL_STREAMID
, (stream_tag
<< 4) | 0x0);
1375 /* set the stream format */
1376 snd_hda_codec_write(codec
, nvhdmi_master_con_nid_7x
, 0,
1377 AC_VERB_SET_STREAM_FORMAT
, format
);
1379 /* turn on again (if needed) */
1380 /* enable and set the channel status audio/data flag */
1381 if (codec
->spdif_status_reset
&& (codec
->spdif_ctls
& AC_DIG1_ENABLE
)) {
1382 snd_hda_codec_write(codec
,
1383 nvhdmi_master_con_nid_7x
,
1385 AC_VERB_SET_DIGI_CONVERT_1
,
1386 codec
->spdif_ctls
& 0xff);
1387 snd_hda_codec_write(codec
,
1388 nvhdmi_master_con_nid_7x
,
1390 AC_VERB_SET_DIGI_CONVERT_2
, dataDCC2
);
1393 for (i
= 0; i
< 4; i
++) {
1399 /* turn off SPDIF once;
1400 *otherwise the IEC958 bits won't be updated
1402 if (codec
->spdif_status_reset
&&
1403 (codec
->spdif_ctls
& AC_DIG1_ENABLE
))
1404 snd_hda_codec_write(codec
,
1405 nvhdmi_con_nids_7x
[i
],
1407 AC_VERB_SET_DIGI_CONVERT_1
,
1408 codec
->spdif_ctls
& ~AC_DIG1_ENABLE
& 0xff);
1409 /* set the stream id */
1410 snd_hda_codec_write(codec
,
1411 nvhdmi_con_nids_7x
[i
],
1413 AC_VERB_SET_CHANNEL_STREAMID
,
1414 (stream_tag
<< 4) | channel_id
);
1415 /* set the stream format */
1416 snd_hda_codec_write(codec
,
1417 nvhdmi_con_nids_7x
[i
],
1419 AC_VERB_SET_STREAM_FORMAT
,
1421 /* turn on again (if needed) */
1422 /* enable and set the channel status audio/data flag */
1423 if (codec
->spdif_status_reset
&&
1424 (codec
->spdif_ctls
& AC_DIG1_ENABLE
)) {
1425 snd_hda_codec_write(codec
,
1426 nvhdmi_con_nids_7x
[i
],
1428 AC_VERB_SET_DIGI_CONVERT_1
,
1429 codec
->spdif_ctls
& 0xff);
1430 snd_hda_codec_write(codec
,
1431 nvhdmi_con_nids_7x
[i
],
1433 AC_VERB_SET_DIGI_CONVERT_2
, dataDCC2
);
1437 nvhdmi_8ch_7x_set_info_frame_parameters(codec
, chs
);
1439 mutex_unlock(&codec
->spdif_mutex
);
1443 static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x
= {
1447 .nid
= nvhdmi_master_con_nid_7x
,
1448 .rates
= SUPPORTED_RATES
,
1449 .maxbps
= SUPPORTED_MAXBPS
,
1450 .formats
= SUPPORTED_FORMATS
,
1452 .open
= simple_playback_pcm_open
,
1453 .close
= nvhdmi_8ch_7x_pcm_close
,
1454 .prepare
= nvhdmi_8ch_7x_pcm_prepare
1458 static const struct hda_pcm_stream nvhdmi_pcm_playback_2ch
= {
1462 .nid
= nvhdmi_master_con_nid_7x
,
1463 .rates
= SUPPORTED_RATES
,
1464 .maxbps
= SUPPORTED_MAXBPS
,
1465 .formats
= SUPPORTED_FORMATS
,
1467 .open
= simple_playback_pcm_open
,
1468 .close
= simple_playback_pcm_close
,
1469 .prepare
= simple_playback_pcm_prepare
1473 static const struct hda_codec_ops nvhdmi_patch_ops_8ch_7x
= {
1474 .build_controls
= generic_hdmi_build_controls
,
1475 .build_pcms
= generic_hdmi_build_pcms
,
1476 .init
= nvhdmi_7x_init
,
1477 .free
= generic_hdmi_free
,
1480 static const struct hda_codec_ops nvhdmi_patch_ops_2ch
= {
1481 .build_controls
= generic_hdmi_build_controls
,
1482 .build_pcms
= generic_hdmi_build_pcms
,
1483 .init
= nvhdmi_7x_init
,
1484 .free
= generic_hdmi_free
,
1487 static int patch_nvhdmi_2ch(struct hda_codec
*codec
)
1489 struct hdmi_spec
*spec
;
1491 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1497 spec
->multiout
.num_dacs
= 0; /* no analog */
1498 spec
->multiout
.max_channels
= 2;
1499 spec
->multiout
.dig_out_nid
= nvhdmi_master_con_nid_7x
;
1501 spec
->cvt
[0] = nvhdmi_master_con_nid_7x
;
1502 spec
->pcm_playback
= &nvhdmi_pcm_playback_2ch
;
1504 codec
->patch_ops
= nvhdmi_patch_ops_2ch
;
1509 static int patch_nvhdmi_8ch_7x(struct hda_codec
*codec
)
1511 struct hdmi_spec
*spec
;
1512 int err
= patch_nvhdmi_2ch(codec
);
1517 spec
->multiout
.max_channels
= 8;
1518 spec
->pcm_playback
= &nvhdmi_pcm_playback_8ch_7x
;
1519 codec
->patch_ops
= nvhdmi_patch_ops_8ch_7x
;
1521 /* Initialize the audio infoframe channel mask and checksum to something
1523 nvhdmi_8ch_7x_set_info_frame_parameters(codec
, 8);
1529 * ATI-specific implementations
1531 * FIXME: we may omit the whole this and use the generic code once after
1532 * it's confirmed to work.
1535 #define ATIHDMI_CVT_NID 0x02 /* audio converter */
1536 #define ATIHDMI_PIN_NID 0x03 /* HDMI output pin */
1538 static int atihdmi_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1539 struct hda_codec
*codec
,
1540 unsigned int stream_tag
,
1541 unsigned int format
,
1542 struct snd_pcm_substream
*substream
)
1544 struct hdmi_spec
*spec
= codec
->spec
;
1545 int chans
= substream
->runtime
->channels
;
1548 err
= simple_playback_pcm_prepare(hinfo
, codec
, stream_tag
, format
,
1552 snd_hda_codec_write(codec
, spec
->cvt
[0], 0, AC_VERB_SET_CVT_CHAN_COUNT
,
1555 for (i
= 0; i
< chans
; i
++) {
1556 snd_hda_codec_write(codec
, spec
->cvt
[0], 0,
1557 AC_VERB_SET_HDMI_CHAN_SLOT
,
1563 static const struct hda_pcm_stream atihdmi_pcm_digital_playback
= {
1567 .nid
= ATIHDMI_CVT_NID
,
1569 .open
= simple_playback_pcm_open
,
1570 .close
= simple_playback_pcm_close
,
1571 .prepare
= atihdmi_playback_pcm_prepare
1575 static const struct hda_verb atihdmi_basic_init
[] = {
1576 /* enable digital output on pin widget */
1577 { 0x03, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
1581 static int atihdmi_init(struct hda_codec
*codec
)
1583 struct hdmi_spec
*spec
= codec
->spec
;
1585 snd_hda_sequence_write(codec
, atihdmi_basic_init
);
1586 /* SI codec requires to unmute the pin */
1587 if (get_wcaps(codec
, spec
->pin
[0]) & AC_WCAP_OUT_AMP
)
1588 snd_hda_codec_write(codec
, spec
->pin
[0], 0,
1589 AC_VERB_SET_AMP_GAIN_MUTE
,
1594 static const struct hda_codec_ops atihdmi_patch_ops
= {
1595 .build_controls
= generic_hdmi_build_controls
,
1596 .build_pcms
= generic_hdmi_build_pcms
,
1597 .init
= atihdmi_init
,
1598 .free
= generic_hdmi_free
,
1602 static int patch_atihdmi(struct hda_codec
*codec
)
1604 struct hdmi_spec
*spec
;
1606 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1612 spec
->multiout
.num_dacs
= 0; /* no analog */
1613 spec
->multiout
.max_channels
= 2;
1614 spec
->multiout
.dig_out_nid
= ATIHDMI_CVT_NID
;
1616 spec
->cvt
[0] = ATIHDMI_CVT_NID
;
1617 spec
->pin
[0] = ATIHDMI_PIN_NID
;
1618 spec
->pcm_playback
= &atihdmi_pcm_digital_playback
;
1620 codec
->patch_ops
= atihdmi_patch_ops
;
1629 static const struct hda_codec_preset snd_hda_preset_hdmi
[] = {
1630 { .id
= 0x1002793c, .name
= "RS600 HDMI", .patch
= patch_atihdmi
},
1631 { .id
= 0x10027919, .name
= "RS600 HDMI", .patch
= patch_atihdmi
},
1632 { .id
= 0x1002791a, .name
= "RS690/780 HDMI", .patch
= patch_atihdmi
},
1633 { .id
= 0x1002aa01, .name
= "R6xx HDMI", .patch
= patch_generic_hdmi
},
1634 { .id
= 0x10951390, .name
= "SiI1390 HDMI", .patch
= patch_generic_hdmi
},
1635 { .id
= 0x10951392, .name
= "SiI1392 HDMI", .patch
= patch_generic_hdmi
},
1636 { .id
= 0x17e80047, .name
= "Chrontel HDMI", .patch
= patch_generic_hdmi
},
1637 { .id
= 0x10de0002, .name
= "MCP77/78 HDMI", .patch
= patch_nvhdmi_8ch_7x
},
1638 { .id
= 0x10de0003, .name
= "MCP77/78 HDMI", .patch
= patch_nvhdmi_8ch_7x
},
1639 { .id
= 0x10de0005, .name
= "MCP77/78 HDMI", .patch
= patch_nvhdmi_8ch_7x
},
1640 { .id
= 0x10de0006, .name
= "MCP77/78 HDMI", .patch
= patch_nvhdmi_8ch_7x
},
1641 { .id
= 0x10de0007, .name
= "MCP79/7A HDMI", .patch
= patch_nvhdmi_8ch_7x
},
1642 { .id
= 0x10de000a, .name
= "GPU 0a HDMI/DP", .patch
= patch_generic_hdmi
},
1643 { .id
= 0x10de000b, .name
= "GPU 0b HDMI/DP", .patch
= patch_generic_hdmi
},
1644 { .id
= 0x10de000c, .name
= "MCP89 HDMI", .patch
= patch_generic_hdmi
},
1645 { .id
= 0x10de000d, .name
= "GPU 0d HDMI/DP", .patch
= patch_generic_hdmi
},
1646 { .id
= 0x10de0010, .name
= "GPU 10 HDMI/DP", .patch
= patch_generic_hdmi
},
1647 { .id
= 0x10de0011, .name
= "GPU 11 HDMI/DP", .patch
= patch_generic_hdmi
},
1648 { .id
= 0x10de0012, .name
= "GPU 12 HDMI/DP", .patch
= patch_generic_hdmi
},
1649 { .id
= 0x10de0013, .name
= "GPU 13 HDMI/DP", .patch
= patch_generic_hdmi
},
1650 { .id
= 0x10de0014, .name
= "GPU 14 HDMI/DP", .patch
= patch_generic_hdmi
},
1651 { .id
= 0x10de0015, .name
= "GPU 15 HDMI/DP", .patch
= patch_generic_hdmi
},
1652 { .id
= 0x10de0016, .name
= "GPU 16 HDMI/DP", .patch
= patch_generic_hdmi
},
1653 /* 17 is known to be absent */
1654 { .id
= 0x10de0018, .name
= "GPU 18 HDMI/DP", .patch
= patch_generic_hdmi
},
1655 { .id
= 0x10de0019, .name
= "GPU 19 HDMI/DP", .patch
= patch_generic_hdmi
},
1656 { .id
= 0x10de001a, .name
= "GPU 1a HDMI/DP", .patch
= patch_generic_hdmi
},
1657 { .id
= 0x10de001b, .name
= "GPU 1b HDMI/DP", .patch
= patch_generic_hdmi
},
1658 { .id
= 0x10de001c, .name
= "GPU 1c HDMI/DP", .patch
= patch_generic_hdmi
},
1659 { .id
= 0x10de0040, .name
= "GPU 40 HDMI/DP", .patch
= patch_generic_hdmi
},
1660 { .id
= 0x10de0041, .name
= "GPU 41 HDMI/DP", .patch
= patch_generic_hdmi
},
1661 { .id
= 0x10de0042, .name
= "GPU 42 HDMI/DP", .patch
= patch_generic_hdmi
},
1662 { .id
= 0x10de0043, .name
= "GPU 43 HDMI/DP", .patch
= patch_generic_hdmi
},
1663 { .id
= 0x10de0044, .name
= "GPU 44 HDMI/DP", .patch
= patch_generic_hdmi
},
1664 { .id
= 0x10de0067, .name
= "MCP67 HDMI", .patch
= patch_nvhdmi_2ch
},
1665 { .id
= 0x10de8001, .name
= "MCP73 HDMI", .patch
= patch_nvhdmi_2ch
},
1666 { .id
= 0x80860054, .name
= "IbexPeak HDMI", .patch
= patch_generic_hdmi
},
1667 { .id
= 0x80862801, .name
= "Bearlake HDMI", .patch
= patch_generic_hdmi
},
1668 { .id
= 0x80862802, .name
= "Cantiga HDMI", .patch
= patch_generic_hdmi
},
1669 { .id
= 0x80862803, .name
= "Eaglelake HDMI", .patch
= patch_generic_hdmi
},
1670 { .id
= 0x80862804, .name
= "IbexPeak HDMI", .patch
= patch_generic_hdmi
},
1671 { .id
= 0x80862805, .name
= "CougarPoint HDMI", .patch
= patch_generic_hdmi
},
1672 { .id
= 0x80862806, .name
= "PantherPoint HDMI", .patch
= patch_generic_hdmi
},
1673 { .id
= 0x808629fb, .name
= "Crestline HDMI", .patch
= patch_generic_hdmi
},
1677 MODULE_ALIAS("snd-hda-codec-id:1002793c");
1678 MODULE_ALIAS("snd-hda-codec-id:10027919");
1679 MODULE_ALIAS("snd-hda-codec-id:1002791a");
1680 MODULE_ALIAS("snd-hda-codec-id:1002aa01");
1681 MODULE_ALIAS("snd-hda-codec-id:10951390");
1682 MODULE_ALIAS("snd-hda-codec-id:10951392");
1683 MODULE_ALIAS("snd-hda-codec-id:10de0002");
1684 MODULE_ALIAS("snd-hda-codec-id:10de0003");
1685 MODULE_ALIAS("snd-hda-codec-id:10de0005");
1686 MODULE_ALIAS("snd-hda-codec-id:10de0006");
1687 MODULE_ALIAS("snd-hda-codec-id:10de0007");
1688 MODULE_ALIAS("snd-hda-codec-id:10de000a");
1689 MODULE_ALIAS("snd-hda-codec-id:10de000b");
1690 MODULE_ALIAS("snd-hda-codec-id:10de000c");
1691 MODULE_ALIAS("snd-hda-codec-id:10de000d");
1692 MODULE_ALIAS("snd-hda-codec-id:10de0010");
1693 MODULE_ALIAS("snd-hda-codec-id:10de0011");
1694 MODULE_ALIAS("snd-hda-codec-id:10de0012");
1695 MODULE_ALIAS("snd-hda-codec-id:10de0013");
1696 MODULE_ALIAS("snd-hda-codec-id:10de0014");
1697 MODULE_ALIAS("snd-hda-codec-id:10de0015");
1698 MODULE_ALIAS("snd-hda-codec-id:10de0016");
1699 MODULE_ALIAS("snd-hda-codec-id:10de0018");
1700 MODULE_ALIAS("snd-hda-codec-id:10de0019");
1701 MODULE_ALIAS("snd-hda-codec-id:10de001a");
1702 MODULE_ALIAS("snd-hda-codec-id:10de001b");
1703 MODULE_ALIAS("snd-hda-codec-id:10de001c");
1704 MODULE_ALIAS("snd-hda-codec-id:10de0040");
1705 MODULE_ALIAS("snd-hda-codec-id:10de0041");
1706 MODULE_ALIAS("snd-hda-codec-id:10de0042");
1707 MODULE_ALIAS("snd-hda-codec-id:10de0043");
1708 MODULE_ALIAS("snd-hda-codec-id:10de0044");
1709 MODULE_ALIAS("snd-hda-codec-id:10de0067");
1710 MODULE_ALIAS("snd-hda-codec-id:10de8001");
1711 MODULE_ALIAS("snd-hda-codec-id:17e80047");
1712 MODULE_ALIAS("snd-hda-codec-id:80860054");
1713 MODULE_ALIAS("snd-hda-codec-id:80862801");
1714 MODULE_ALIAS("snd-hda-codec-id:80862802");
1715 MODULE_ALIAS("snd-hda-codec-id:80862803");
1716 MODULE_ALIAS("snd-hda-codec-id:80862804");
1717 MODULE_ALIAS("snd-hda-codec-id:80862805");
1718 MODULE_ALIAS("snd-hda-codec-id:80862806");
1719 MODULE_ALIAS("snd-hda-codec-id:808629fb");
1721 MODULE_LICENSE("GPL");
1722 MODULE_DESCRIPTION("HDMI HD-audio codec");
1723 MODULE_ALIAS("snd-hda-codec-intelhdmi");
1724 MODULE_ALIAS("snd-hda-codec-nvhdmi");
1725 MODULE_ALIAS("snd-hda-codec-atihdmi");
1727 static struct hda_codec_preset_list intel_list
= {
1728 .preset
= snd_hda_preset_hdmi
,
1729 .owner
= THIS_MODULE
,
1732 static int __init
patch_hdmi_init(void)
1734 return snd_hda_add_codec_preset(&intel_list
);
1737 static void __exit
patch_hdmi_exit(void)
1739 snd_hda_delete_codec_preset(&intel_list
);
1742 module_init(patch_hdmi_init
)
1743 module_exit(patch_hdmi_exit
)