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/module.h>
35 #include <sound/core.h>
36 #include <sound/jack.h>
37 #include <sound/asoundef.h>
38 #include <sound/tlv.h>
39 #include "hda_codec.h"
40 #include "hda_local.h"
43 static bool static_hdmi_pcm
;
44 module_param(static_hdmi_pcm
, bool, 0644);
45 MODULE_PARM_DESC(static_hdmi_pcm
, "Don't restrict PCM parameters per ELD info");
48 * The HDMI/DisplayPort configuration can be highly dynamic. A graphics device
49 * could support N independent pipes, each of them can be connected to one or
50 * more ports (DVI, HDMI or DisplayPort).
52 * The HDA correspondence of pipes/ports are converter/pin nodes.
54 #define MAX_HDMI_CVTS 8
55 #define MAX_HDMI_PINS 8
57 struct hdmi_spec_per_cvt
{
60 unsigned int channels_min
;
61 unsigned int channels_max
;
67 /* max. connections to a widget */
68 #define HDA_MAX_CONNECTIONS 32
70 struct hdmi_spec_per_pin
{
73 hda_nid_t mux_nids
[HDA_MAX_CONNECTIONS
];
75 struct hda_codec
*codec
;
76 struct hdmi_eld sink_eld
;
77 struct delayed_work work
;
80 bool chmap_set
; /* channel-map override by ALSA API? */
81 unsigned char chmap
[8]; /* ALSA API channel-map */
86 struct hdmi_spec_per_cvt cvts
[MAX_HDMI_CVTS
];
89 struct hdmi_spec_per_pin pins
[MAX_HDMI_PINS
];
90 struct hda_pcm pcm_rec
[MAX_HDMI_PINS
];
91 unsigned int channels_max
; /* max over all cvts */
94 * Non-generic ATI/NVIDIA specific
96 struct hda_multi_out multiout
;
97 struct hda_pcm_stream pcm_playback
;
101 struct hdmi_audio_infoframe
{
108 u8 CC02_CT47
; /* CC in bits 0:2, CT in 4:7 */
112 u8 LFEPBL01_LSV36_DM_INH7
;
115 struct dp_audio_infoframe
{
118 u8 ver
; /* 0x11 << 2 */
120 u8 CC02_CT47
; /* match with HDMI infoframe from this on */
124 u8 LFEPBL01_LSV36_DM_INH7
;
127 union audio_infoframe
{
128 struct hdmi_audio_infoframe hdmi
;
129 struct dp_audio_infoframe dp
;
134 * CEA speaker placement:
137 * FLW FL FLC FC FRC FR FRW
144 * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
145 * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
147 enum cea_speaker_placement
{
148 FL
= (1 << 0), /* Front Left */
149 FC
= (1 << 1), /* Front Center */
150 FR
= (1 << 2), /* Front Right */
151 FLC
= (1 << 3), /* Front Left Center */
152 FRC
= (1 << 4), /* Front Right Center */
153 RL
= (1 << 5), /* Rear Left */
154 RC
= (1 << 6), /* Rear Center */
155 RR
= (1 << 7), /* Rear Right */
156 RLC
= (1 << 8), /* Rear Left Center */
157 RRC
= (1 << 9), /* Rear Right Center */
158 LFE
= (1 << 10), /* Low Frequency Effect */
159 FLW
= (1 << 11), /* Front Left Wide */
160 FRW
= (1 << 12), /* Front Right Wide */
161 FLH
= (1 << 13), /* Front Left High */
162 FCH
= (1 << 14), /* Front Center High */
163 FRH
= (1 << 15), /* Front Right High */
164 TC
= (1 << 16), /* Top Center */
168 * ELD SA bits in the CEA Speaker Allocation data block
170 static int eld_speaker_allocation_bits
[] = {
178 /* the following are not defined in ELD yet */
185 struct cea_channel_speaker_allocation
{
189 /* derived values, just for convenience */
197 * surround40 surround41 surround50 surround51 surround71
198 * ch0 front left = = = =
199 * ch1 front right = = = =
200 * ch2 rear left = = = =
201 * ch3 rear right = = = =
202 * ch4 LFE center center center
207 * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR}
209 static int hdmi_channel_mapping
[0x32][8] = {
211 [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
213 [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
215 [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 },
217 [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 },
219 [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 },
221 [0x09] = { 0x00, 0x11, 0x24, 0x35, 0x42, 0xf3, 0xf6, 0xf7 },
223 [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 },
225 [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 },
227 [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 },
231 * This is an ordered list!
233 * The preceding ones have better chances to be selected by
234 * hdmi_channel_allocation().
236 static struct cea_channel_speaker_allocation channel_allocations
[] = {
237 /* channel: 7 6 5 4 3 2 1 0 */
238 { .ca_index
= 0x00, .speakers
= { 0, 0, 0, 0, 0, 0, FR
, FL
} },
240 { .ca_index
= 0x01, .speakers
= { 0, 0, 0, 0, 0, LFE
, FR
, FL
} },
242 { .ca_index
= 0x02, .speakers
= { 0, 0, 0, 0, FC
, 0, FR
, FL
} },
244 { .ca_index
= 0x08, .speakers
= { 0, 0, RR
, RL
, 0, 0, FR
, FL
} },
246 { .ca_index
= 0x09, .speakers
= { 0, 0, RR
, RL
, 0, LFE
, FR
, FL
} },
248 { .ca_index
= 0x0a, .speakers
= { 0, 0, RR
, RL
, FC
, 0, FR
, FL
} },
250 { .ca_index
= 0x0b, .speakers
= { 0, 0, RR
, RL
, FC
, LFE
, FR
, FL
} },
252 { .ca_index
= 0x0f, .speakers
= { 0, RC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
254 { .ca_index
= 0x13, .speakers
= { RRC
, RLC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
256 { .ca_index
= 0x03, .speakers
= { 0, 0, 0, 0, FC
, LFE
, FR
, FL
} },
257 { .ca_index
= 0x04, .speakers
= { 0, 0, 0, RC
, 0, 0, FR
, FL
} },
258 { .ca_index
= 0x05, .speakers
= { 0, 0, 0, RC
, 0, LFE
, FR
, FL
} },
259 { .ca_index
= 0x06, .speakers
= { 0, 0, 0, RC
, FC
, 0, FR
, FL
} },
260 { .ca_index
= 0x07, .speakers
= { 0, 0, 0, RC
, FC
, LFE
, FR
, FL
} },
261 { .ca_index
= 0x0c, .speakers
= { 0, RC
, RR
, RL
, 0, 0, FR
, FL
} },
262 { .ca_index
= 0x0d, .speakers
= { 0, RC
, RR
, RL
, 0, LFE
, FR
, FL
} },
263 { .ca_index
= 0x0e, .speakers
= { 0, RC
, RR
, RL
, FC
, 0, FR
, FL
} },
264 { .ca_index
= 0x10, .speakers
= { RRC
, RLC
, RR
, RL
, 0, 0, FR
, FL
} },
265 { .ca_index
= 0x11, .speakers
= { RRC
, RLC
, RR
, RL
, 0, LFE
, FR
, FL
} },
266 { .ca_index
= 0x12, .speakers
= { RRC
, RLC
, RR
, RL
, FC
, 0, FR
, FL
} },
267 { .ca_index
= 0x14, .speakers
= { FRC
, FLC
, 0, 0, 0, 0, FR
, FL
} },
268 { .ca_index
= 0x15, .speakers
= { FRC
, FLC
, 0, 0, 0, LFE
, FR
, FL
} },
269 { .ca_index
= 0x16, .speakers
= { FRC
, FLC
, 0, 0, FC
, 0, FR
, FL
} },
270 { .ca_index
= 0x17, .speakers
= { FRC
, FLC
, 0, 0, FC
, LFE
, FR
, FL
} },
271 { .ca_index
= 0x18, .speakers
= { FRC
, FLC
, 0, RC
, 0, 0, FR
, FL
} },
272 { .ca_index
= 0x19, .speakers
= { FRC
, FLC
, 0, RC
, 0, LFE
, FR
, FL
} },
273 { .ca_index
= 0x1a, .speakers
= { FRC
, FLC
, 0, RC
, FC
, 0, FR
, FL
} },
274 { .ca_index
= 0x1b, .speakers
= { FRC
, FLC
, 0, RC
, FC
, LFE
, FR
, FL
} },
275 { .ca_index
= 0x1c, .speakers
= { FRC
, FLC
, RR
, RL
, 0, 0, FR
, FL
} },
276 { .ca_index
= 0x1d, .speakers
= { FRC
, FLC
, RR
, RL
, 0, LFE
, FR
, FL
} },
277 { .ca_index
= 0x1e, .speakers
= { FRC
, FLC
, RR
, RL
, FC
, 0, FR
, FL
} },
278 { .ca_index
= 0x1f, .speakers
= { FRC
, FLC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
279 { .ca_index
= 0x20, .speakers
= { 0, FCH
, RR
, RL
, FC
, 0, FR
, FL
} },
280 { .ca_index
= 0x21, .speakers
= { 0, FCH
, RR
, RL
, FC
, LFE
, FR
, FL
} },
281 { .ca_index
= 0x22, .speakers
= { TC
, 0, RR
, RL
, FC
, 0, FR
, FL
} },
282 { .ca_index
= 0x23, .speakers
= { TC
, 0, RR
, RL
, FC
, LFE
, FR
, FL
} },
283 { .ca_index
= 0x24, .speakers
= { FRH
, FLH
, RR
, RL
, 0, 0, FR
, FL
} },
284 { .ca_index
= 0x25, .speakers
= { FRH
, FLH
, RR
, RL
, 0, LFE
, FR
, FL
} },
285 { .ca_index
= 0x26, .speakers
= { FRW
, FLW
, RR
, RL
, 0, 0, FR
, FL
} },
286 { .ca_index
= 0x27, .speakers
= { FRW
, FLW
, RR
, RL
, 0, LFE
, FR
, FL
} },
287 { .ca_index
= 0x28, .speakers
= { TC
, RC
, RR
, RL
, FC
, 0, FR
, FL
} },
288 { .ca_index
= 0x29, .speakers
= { TC
, RC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
289 { .ca_index
= 0x2a, .speakers
= { FCH
, RC
, RR
, RL
, FC
, 0, FR
, FL
} },
290 { .ca_index
= 0x2b, .speakers
= { FCH
, RC
, RR
, RL
, FC
, LFE
, FR
, FL
} },
291 { .ca_index
= 0x2c, .speakers
= { TC
, FCH
, RR
, RL
, FC
, 0, FR
, FL
} },
292 { .ca_index
= 0x2d, .speakers
= { TC
, FCH
, RR
, RL
, FC
, LFE
, FR
, FL
} },
293 { .ca_index
= 0x2e, .speakers
= { FRH
, FLH
, RR
, RL
, FC
, 0, FR
, FL
} },
294 { .ca_index
= 0x2f, .speakers
= { FRH
, FLH
, RR
, RL
, FC
, LFE
, FR
, FL
} },
295 { .ca_index
= 0x30, .speakers
= { FRW
, FLW
, RR
, RL
, FC
, 0, FR
, FL
} },
296 { .ca_index
= 0x31, .speakers
= { FRW
, FLW
, RR
, RL
, FC
, LFE
, FR
, FL
} },
304 static int pin_nid_to_pin_index(struct hdmi_spec
*spec
, hda_nid_t pin_nid
)
308 for (pin_idx
= 0; pin_idx
< spec
->num_pins
; pin_idx
++)
309 if (spec
->pins
[pin_idx
].pin_nid
== pin_nid
)
312 snd_printk(KERN_WARNING
"HDMI: pin nid %d not registered\n", pin_nid
);
316 static int hinfo_to_pin_index(struct hdmi_spec
*spec
,
317 struct hda_pcm_stream
*hinfo
)
321 for (pin_idx
= 0; pin_idx
< spec
->num_pins
; pin_idx
++)
322 if (&spec
->pcm_rec
[pin_idx
].stream
[0] == hinfo
)
325 snd_printk(KERN_WARNING
"HDMI: hinfo %p not registered\n", hinfo
);
329 static int cvt_nid_to_cvt_index(struct hdmi_spec
*spec
, hda_nid_t cvt_nid
)
333 for (cvt_idx
= 0; cvt_idx
< spec
->num_cvts
; cvt_idx
++)
334 if (spec
->cvts
[cvt_idx
].cvt_nid
== cvt_nid
)
337 snd_printk(KERN_WARNING
"HDMI: cvt nid %d not registered\n", cvt_nid
);
341 static int hdmi_eld_ctl_info(struct snd_kcontrol
*kcontrol
,
342 struct snd_ctl_elem_info
*uinfo
)
344 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
345 struct hdmi_spec
*spec
;
349 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BYTES
;
351 pin_idx
= kcontrol
->private_value
;
352 uinfo
->count
= spec
->pins
[pin_idx
].sink_eld
.eld_size
;
357 static int hdmi_eld_ctl_get(struct snd_kcontrol
*kcontrol
,
358 struct snd_ctl_elem_value
*ucontrol
)
360 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
361 struct hdmi_spec
*spec
;
365 pin_idx
= kcontrol
->private_value
;
367 memcpy(ucontrol
->value
.bytes
.data
,
368 spec
->pins
[pin_idx
].sink_eld
.eld_buffer
, ELD_MAX_SIZE
);
373 static struct snd_kcontrol_new eld_bytes_ctl
= {
374 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
375 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
377 .info
= hdmi_eld_ctl_info
,
378 .get
= hdmi_eld_ctl_get
,
381 static int hdmi_create_eld_ctl(struct hda_codec
*codec
, int pin_idx
,
384 struct snd_kcontrol
*kctl
;
385 struct hdmi_spec
*spec
= codec
->spec
;
388 kctl
= snd_ctl_new1(&eld_bytes_ctl
, codec
);
391 kctl
->private_value
= pin_idx
;
392 kctl
->id
.device
= device
;
394 err
= snd_hda_ctl_add(codec
, spec
->pins
[pin_idx
].pin_nid
, kctl
);
402 static void hdmi_get_dip_index(struct hda_codec
*codec
, hda_nid_t pin_nid
,
403 int *packet_index
, int *byte_index
)
407 val
= snd_hda_codec_read(codec
, pin_nid
, 0,
408 AC_VERB_GET_HDMI_DIP_INDEX
, 0);
410 *packet_index
= val
>> 5;
411 *byte_index
= val
& 0x1f;
415 static void hdmi_set_dip_index(struct hda_codec
*codec
, hda_nid_t pin_nid
,
416 int packet_index
, int byte_index
)
420 val
= (packet_index
<< 5) | (byte_index
& 0x1f);
422 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_INDEX
, val
);
425 static void hdmi_write_dip_byte(struct hda_codec
*codec
, hda_nid_t pin_nid
,
428 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_DATA
, val
);
431 static void hdmi_init_pin(struct hda_codec
*codec
, hda_nid_t pin_nid
)
434 if (get_wcaps(codec
, pin_nid
) & AC_WCAP_OUT_AMP
)
435 snd_hda_codec_write(codec
, pin_nid
, 0,
436 AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
);
437 /* Enable pin out: some machines with GM965 gets broken output when
438 * the pin is disabled or changed while using with HDMI
440 snd_hda_codec_write(codec
, pin_nid
, 0,
441 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
);
444 static int hdmi_get_channel_count(struct hda_codec
*codec
, hda_nid_t cvt_nid
)
446 return 1 + snd_hda_codec_read(codec
, cvt_nid
, 0,
447 AC_VERB_GET_CVT_CHAN_COUNT
, 0);
450 static void hdmi_set_channel_count(struct hda_codec
*codec
,
451 hda_nid_t cvt_nid
, int chs
)
453 if (chs
!= hdmi_get_channel_count(codec
, cvt_nid
))
454 snd_hda_codec_write(codec
, cvt_nid
, 0,
455 AC_VERB_SET_CVT_CHAN_COUNT
, chs
- 1);
460 * Channel mapping routines
464 * Compute derived values in channel_allocations[].
466 static void init_channel_allocations(void)
469 struct cea_channel_speaker_allocation
*p
;
471 for (i
= 0; i
< ARRAY_SIZE(channel_allocations
); i
++) {
472 p
= channel_allocations
+ i
;
475 for (j
= 0; j
< ARRAY_SIZE(p
->speakers
); j
++)
476 if (p
->speakers
[j
]) {
478 p
->spk_mask
|= p
->speakers
[j
];
483 static int get_channel_allocation_order(int ca
)
487 for (i
= 0; i
< ARRAY_SIZE(channel_allocations
); i
++) {
488 if (channel_allocations
[i
].ca_index
== ca
)
495 * The transformation takes two steps:
497 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
498 * spk_mask => (channel_allocations[]) => ai->CA
500 * TODO: it could select the wrong CA from multiple candidates.
502 static int hdmi_channel_allocation(struct hdmi_eld
*eld
, int channels
)
507 char buf
[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE
];
510 * CA defaults to 0 for basic stereo audio
516 * expand ELD's speaker allocation mask
518 * ELD tells the speaker mask in a compact(paired) form,
519 * expand ELD's notions to match the ones used by Audio InfoFrame.
521 for (i
= 0; i
< ARRAY_SIZE(eld_speaker_allocation_bits
); i
++) {
522 if (eld
->spk_alloc
& (1 << i
))
523 spk_mask
|= eld_speaker_allocation_bits
[i
];
526 /* search for the first working match in the CA table */
527 for (i
= 0; i
< ARRAY_SIZE(channel_allocations
); i
++) {
528 if (channels
== channel_allocations
[i
].channels
&&
529 (spk_mask
& channel_allocations
[i
].spk_mask
) ==
530 channel_allocations
[i
].spk_mask
) {
531 ca
= channel_allocations
[i
].ca_index
;
536 snd_print_channel_allocation(eld
->spk_alloc
, buf
, sizeof(buf
));
537 snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n",
543 static void hdmi_debug_channel_mapping(struct hda_codec
*codec
,
546 #ifdef CONFIG_SND_DEBUG_VERBOSE
550 for (i
= 0; i
< 8; i
++) {
551 slot
= snd_hda_codec_read(codec
, pin_nid
, 0,
552 AC_VERB_GET_HDMI_CHAN_SLOT
, i
);
553 printk(KERN_DEBUG
"HDMI: ASP channel %d => slot %d\n",
554 slot
>> 4, slot
& 0xf);
560 static void hdmi_std_setup_channel_mapping(struct hda_codec
*codec
,
568 int non_pcm_mapping
[8];
570 order
= get_channel_allocation_order(ca
);
572 if (hdmi_channel_mapping
[ca
][1] == 0) {
573 for (i
= 0; i
< channel_allocations
[order
].channels
; i
++)
574 hdmi_channel_mapping
[ca
][i
] = i
| (i
<< 4);
576 hdmi_channel_mapping
[ca
][i
] = 0xf | (i
<< 4);
580 for (i
= 0; i
< channel_allocations
[order
].channels
; i
++)
581 non_pcm_mapping
[i
] = i
| (i
<< 4);
583 non_pcm_mapping
[i
] = 0xf | (i
<< 4);
586 for (i
= 0; i
< 8; i
++) {
587 err
= snd_hda_codec_write(codec
, pin_nid
, 0,
588 AC_VERB_SET_HDMI_CHAN_SLOT
,
589 non_pcm
? non_pcm_mapping
[i
] : hdmi_channel_mapping
[ca
][i
]);
591 snd_printdd(KERN_NOTICE
592 "HDMI: channel mapping failed\n");
597 hdmi_debug_channel_mapping(codec
, pin_nid
);
600 struct channel_map_table
{
601 unsigned char map
; /* ALSA API channel map position */
602 unsigned char cea_slot
; /* CEA slot value */
603 int spk_mask
; /* speaker position bit mask */
606 static struct channel_map_table map_tables
[] = {
607 { SNDRV_CHMAP_FL
, 0x00, FL
},
608 { SNDRV_CHMAP_FR
, 0x01, FR
},
609 { SNDRV_CHMAP_RL
, 0x04, RL
},
610 { SNDRV_CHMAP_RR
, 0x05, RR
},
611 { SNDRV_CHMAP_LFE
, 0x02, LFE
},
612 { SNDRV_CHMAP_FC
, 0x03, FC
},
613 { SNDRV_CHMAP_RLC
, 0x06, RLC
},
614 { SNDRV_CHMAP_RRC
, 0x07, RRC
},
618 /* from ALSA API channel position to speaker bit mask */
619 static int to_spk_mask(unsigned char c
)
621 struct channel_map_table
*t
= map_tables
;
622 for (; t
->map
; t
++) {
629 /* from ALSA API channel position to CEA slot */
630 static int to_cea_slot(unsigned char c
)
632 struct channel_map_table
*t
= map_tables
;
633 for (; t
->map
; t
++) {
640 /* from CEA slot to ALSA API channel position */
641 static int from_cea_slot(unsigned char c
)
643 struct channel_map_table
*t
= map_tables
;
644 for (; t
->map
; t
++) {
645 if (t
->cea_slot
== c
)
651 /* from speaker bit mask to ALSA API channel position */
652 static int spk_to_chmap(int spk
)
654 struct channel_map_table
*t
= map_tables
;
655 for (; t
->map
; t
++) {
656 if (t
->spk_mask
== spk
)
662 /* get the CA index corresponding to the given ALSA API channel map */
663 static int hdmi_manual_channel_allocation(int chs
, unsigned char *map
)
665 int i
, spks
= 0, spk_mask
= 0;
667 for (i
= 0; i
< chs
; i
++) {
668 int mask
= to_spk_mask(map
[i
]);
675 for (i
= 0; i
< ARRAY_SIZE(channel_allocations
); i
++) {
676 if ((chs
== channel_allocations
[i
].channels
||
677 spks
== channel_allocations
[i
].channels
) &&
678 (spk_mask
& channel_allocations
[i
].spk_mask
) ==
679 channel_allocations
[i
].spk_mask
)
680 return channel_allocations
[i
].ca_index
;
685 /* set up the channel slots for the given ALSA API channel map */
686 static int hdmi_manual_setup_channel_mapping(struct hda_codec
*codec
,
688 int chs
, unsigned char *map
)
691 for (i
= 0; i
< 8; i
++) {
694 val
= to_cea_slot(map
[i
]);
698 err
= snd_hda_codec_write(codec
, pin_nid
, 0,
699 AC_VERB_SET_HDMI_CHAN_SLOT
, val
);
706 /* store ALSA API channel map from the current default map */
707 static void hdmi_setup_fake_chmap(unsigned char *map
, int ca
)
710 for (i
= 0; i
< 8; i
++) {
711 if (i
< channel_allocations
[ca
].channels
)
712 map
[i
] = from_cea_slot((hdmi_channel_mapping
[ca
][i
] >> 4) & 0x0f);
718 static void hdmi_setup_channel_mapping(struct hda_codec
*codec
,
719 hda_nid_t pin_nid
, bool non_pcm
, int ca
,
720 int channels
, unsigned char *map
,
723 if (!non_pcm
&& chmap_set
) {
724 hdmi_manual_setup_channel_mapping(codec
, pin_nid
,
727 hdmi_std_setup_channel_mapping(codec
, pin_nid
, non_pcm
, ca
);
728 hdmi_setup_fake_chmap(map
, ca
);
733 * Audio InfoFrame routines
737 * Enable Audio InfoFrame Transmission
739 static void hdmi_start_infoframe_trans(struct hda_codec
*codec
,
742 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
743 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_XMIT
,
748 * Disable Audio InfoFrame Transmission
750 static void hdmi_stop_infoframe_trans(struct hda_codec
*codec
,
753 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
754 snd_hda_codec_write(codec
, pin_nid
, 0, AC_VERB_SET_HDMI_DIP_XMIT
,
758 static void hdmi_debug_dip_size(struct hda_codec
*codec
, hda_nid_t pin_nid
)
760 #ifdef CONFIG_SND_DEBUG_VERBOSE
764 size
= snd_hdmi_get_eld_size(codec
, pin_nid
);
765 printk(KERN_DEBUG
"HDMI: ELD buf size is %d\n", size
);
767 for (i
= 0; i
< 8; i
++) {
768 size
= snd_hda_codec_read(codec
, pin_nid
, 0,
769 AC_VERB_GET_HDMI_DIP_SIZE
, i
);
770 printk(KERN_DEBUG
"HDMI: DIP GP[%d] buf size is %d\n", i
, size
);
775 static void hdmi_clear_dip_buffers(struct hda_codec
*codec
, hda_nid_t pin_nid
)
781 for (i
= 0; i
< 8; i
++) {
782 size
= snd_hda_codec_read(codec
, pin_nid
, 0,
783 AC_VERB_GET_HDMI_DIP_SIZE
, i
);
787 hdmi_set_dip_index(codec
, pin_nid
, i
, 0x0);
788 for (j
= 1; j
< 1000; j
++) {
789 hdmi_write_dip_byte(codec
, pin_nid
, 0x0);
790 hdmi_get_dip_index(codec
, pin_nid
, &pi
, &bi
);
792 snd_printd(KERN_INFO
"dip index %d: %d != %d\n",
794 if (bi
== 0) /* byte index wrapped around */
798 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
804 static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe
*hdmi_ai
)
806 u8
*bytes
= (u8
*)hdmi_ai
;
810 hdmi_ai
->checksum
= 0;
812 for (i
= 0; i
< sizeof(*hdmi_ai
); i
++)
815 hdmi_ai
->checksum
= -sum
;
818 static void hdmi_fill_audio_infoframe(struct hda_codec
*codec
,
824 hdmi_debug_dip_size(codec
, pin_nid
);
825 hdmi_clear_dip_buffers(codec
, pin_nid
); /* be paranoid */
827 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
828 for (i
= 0; i
< size
; i
++)
829 hdmi_write_dip_byte(codec
, pin_nid
, dip
[i
]);
832 static bool hdmi_infoframe_uptodate(struct hda_codec
*codec
, hda_nid_t pin_nid
,
838 if (snd_hda_codec_read(codec
, pin_nid
, 0, AC_VERB_GET_HDMI_DIP_XMIT
, 0)
842 hdmi_set_dip_index(codec
, pin_nid
, 0x0, 0x0);
843 for (i
= 0; i
< size
; i
++) {
844 val
= snd_hda_codec_read(codec
, pin_nid
, 0,
845 AC_VERB_GET_HDMI_DIP_DATA
, 0);
853 static void hdmi_setup_audio_infoframe(struct hda_codec
*codec
, int pin_idx
,
855 struct snd_pcm_substream
*substream
)
857 struct hdmi_spec
*spec
= codec
->spec
;
858 struct hdmi_spec_per_pin
*per_pin
= &spec
->pins
[pin_idx
];
859 hda_nid_t pin_nid
= per_pin
->pin_nid
;
860 int channels
= substream
->runtime
->channels
;
861 struct hdmi_eld
*eld
;
863 union audio_infoframe ai
;
865 eld
= &spec
->pins
[pin_idx
].sink_eld
;
866 if (!eld
->monitor_present
)
869 if (!non_pcm
&& per_pin
->chmap_set
)
870 ca
= hdmi_manual_channel_allocation(channels
, per_pin
->chmap
);
872 ca
= hdmi_channel_allocation(eld
, channels
);
876 memset(&ai
, 0, sizeof(ai
));
877 if (eld
->conn_type
== 0) { /* HDMI */
878 struct hdmi_audio_infoframe
*hdmi_ai
= &ai
.hdmi
;
880 hdmi_ai
->type
= 0x84;
883 hdmi_ai
->CC02_CT47
= channels
- 1;
885 hdmi_checksum_audio_infoframe(hdmi_ai
);
886 } else if (eld
->conn_type
== 1) { /* DisplayPort */
887 struct dp_audio_infoframe
*dp_ai
= &ai
.dp
;
891 dp_ai
->ver
= 0x11 << 2;
892 dp_ai
->CC02_CT47
= channels
- 1;
895 snd_printd("HDMI: unknown connection type at pin %d\n",
901 * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
902 * sizeof(*dp_ai) to avoid partial match/update problems when
903 * the user switches between HDMI/DP monitors.
905 if (!hdmi_infoframe_uptodate(codec
, pin_nid
, ai
.bytes
,
907 snd_printdd("hdmi_setup_audio_infoframe: "
908 "pin=%d channels=%d\n",
911 hdmi_setup_channel_mapping(codec
, pin_nid
, non_pcm
, ca
,
912 channels
, per_pin
->chmap
,
914 hdmi_stop_infoframe_trans(codec
, pin_nid
);
915 hdmi_fill_audio_infoframe(codec
, pin_nid
,
916 ai
.bytes
, sizeof(ai
));
917 hdmi_start_infoframe_trans(codec
, pin_nid
);
919 /* For non-pcm audio switch, setup new channel mapping
921 if (per_pin
->non_pcm
!= non_pcm
)
922 hdmi_setup_channel_mapping(codec
, pin_nid
, non_pcm
, ca
,
923 channels
, per_pin
->chmap
,
927 per_pin
->non_pcm
= non_pcm
;
935 static void hdmi_present_sense(struct hdmi_spec_per_pin
*per_pin
, int repoll
);
937 static void hdmi_intrinsic_event(struct hda_codec
*codec
, unsigned int res
)
939 struct hdmi_spec
*spec
= codec
->spec
;
940 int tag
= res
>> AC_UNSOL_RES_TAG_SHIFT
;
943 struct hda_jack_tbl
*jack
;
945 jack
= snd_hda_jack_tbl_get_from_tag(codec
, tag
);
949 jack
->jack_dirty
= 1;
951 _snd_printd(SND_PR_VERBOSE
,
952 "HDMI hot plug event: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
953 codec
->addr
, pin_nid
,
954 !!(res
& AC_UNSOL_RES_PD
), !!(res
& AC_UNSOL_RES_ELDV
));
956 pin_idx
= pin_nid_to_pin_index(spec
, pin_nid
);
960 hdmi_present_sense(&spec
->pins
[pin_idx
], 1);
961 snd_hda_jack_report_sync(codec
);
964 static void hdmi_non_intrinsic_event(struct hda_codec
*codec
, unsigned int res
)
966 int tag
= res
>> AC_UNSOL_RES_TAG_SHIFT
;
967 int subtag
= (res
& AC_UNSOL_RES_SUBTAG
) >> AC_UNSOL_RES_SUBTAG_SHIFT
;
968 int cp_state
= !!(res
& AC_UNSOL_RES_CP_STATE
);
969 int cp_ready
= !!(res
& AC_UNSOL_RES_CP_READY
);
972 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
987 static void hdmi_unsol_event(struct hda_codec
*codec
, unsigned int res
)
989 int tag
= res
>> AC_UNSOL_RES_TAG_SHIFT
;
990 int subtag
= (res
& AC_UNSOL_RES_SUBTAG
) >> AC_UNSOL_RES_SUBTAG_SHIFT
;
992 if (!snd_hda_jack_tbl_get_from_tag(codec
, tag
)) {
993 snd_printd(KERN_INFO
"Unexpected HDMI event tag 0x%x\n", tag
);
998 hdmi_intrinsic_event(codec
, res
);
1000 hdmi_non_intrinsic_event(codec
, res
);
1007 /* HBR should be Non-PCM, 8 channels */
1008 #define is_hbr_format(format) \
1009 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
1011 static int hdmi_setup_stream(struct hda_codec
*codec
, hda_nid_t cvt_nid
,
1012 hda_nid_t pin_nid
, u32 stream_tag
, int format
)
1017 if (snd_hda_query_pin_caps(codec
, pin_nid
) & AC_PINCAP_HBR
) {
1018 pinctl
= snd_hda_codec_read(codec
, pin_nid
, 0,
1019 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
1021 new_pinctl
= pinctl
& ~AC_PINCTL_EPT
;
1022 if (is_hbr_format(format
))
1023 new_pinctl
|= AC_PINCTL_EPT_HBR
;
1025 new_pinctl
|= AC_PINCTL_EPT_NATIVE
;
1027 snd_printdd("hdmi_setup_stream: "
1028 "NID=0x%x, %spinctl=0x%x\n",
1030 pinctl
== new_pinctl
? "" : "new-",
1033 if (pinctl
!= new_pinctl
)
1034 snd_hda_codec_write(codec
, pin_nid
, 0,
1035 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1039 if (is_hbr_format(format
) && !new_pinctl
) {
1040 snd_printdd("hdmi_setup_stream: HBR is not supported\n");
1044 snd_hda_codec_setup_stream(codec
, cvt_nid
, stream_tag
, 0, format
);
1051 static int hdmi_pcm_open(struct hda_pcm_stream
*hinfo
,
1052 struct hda_codec
*codec
,
1053 struct snd_pcm_substream
*substream
)
1055 struct hdmi_spec
*spec
= codec
->spec
;
1056 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1057 int pin_idx
, cvt_idx
, mux_idx
= 0;
1058 struct hdmi_spec_per_pin
*per_pin
;
1059 struct hdmi_eld
*eld
;
1060 struct hdmi_spec_per_cvt
*per_cvt
= NULL
;
1062 /* Validate hinfo */
1063 pin_idx
= hinfo_to_pin_index(spec
, hinfo
);
1064 if (snd_BUG_ON(pin_idx
< 0))
1066 per_pin
= &spec
->pins
[pin_idx
];
1067 eld
= &per_pin
->sink_eld
;
1069 /* Dynamically assign converter to stream */
1070 for (cvt_idx
= 0; cvt_idx
< spec
->num_cvts
; cvt_idx
++) {
1071 per_cvt
= &spec
->cvts
[cvt_idx
];
1073 /* Must not already be assigned */
1074 if (per_cvt
->assigned
)
1076 /* Must be in pin's mux's list of converters */
1077 for (mux_idx
= 0; mux_idx
< per_pin
->num_mux_nids
; mux_idx
++)
1078 if (per_pin
->mux_nids
[mux_idx
] == per_cvt
->cvt_nid
)
1080 /* Not in mux list */
1081 if (mux_idx
== per_pin
->num_mux_nids
)
1085 /* No free converters */
1086 if (cvt_idx
== spec
->num_cvts
)
1089 /* Claim converter */
1090 per_cvt
->assigned
= 1;
1091 hinfo
->nid
= per_cvt
->cvt_nid
;
1093 snd_hda_codec_write(codec
, per_pin
->pin_nid
, 0,
1094 AC_VERB_SET_CONNECT_SEL
,
1096 snd_hda_spdif_ctls_assign(codec
, pin_idx
, per_cvt
->cvt_nid
);
1098 /* Initially set the converter's capabilities */
1099 hinfo
->channels_min
= per_cvt
->channels_min
;
1100 hinfo
->channels_max
= per_cvt
->channels_max
;
1101 hinfo
->rates
= per_cvt
->rates
;
1102 hinfo
->formats
= per_cvt
->formats
;
1103 hinfo
->maxbps
= per_cvt
->maxbps
;
1105 /* Restrict capabilities by ELD if this isn't disabled */
1106 if (!static_hdmi_pcm
&& eld
->eld_valid
) {
1107 snd_hdmi_eld_update_pcm_info(eld
, hinfo
);
1108 if (hinfo
->channels_min
> hinfo
->channels_max
||
1109 !hinfo
->rates
|| !hinfo
->formats
) {
1110 per_cvt
->assigned
= 0;
1112 snd_hda_spdif_ctls_unassign(codec
, pin_idx
);
1117 /* Store the updated parameters */
1118 runtime
->hw
.channels_min
= hinfo
->channels_min
;
1119 runtime
->hw
.channels_max
= hinfo
->channels_max
;
1120 runtime
->hw
.formats
= hinfo
->formats
;
1121 runtime
->hw
.rates
= hinfo
->rates
;
1123 snd_pcm_hw_constraint_step(substream
->runtime
, 0,
1124 SNDRV_PCM_HW_PARAM_CHANNELS
, 2);
1129 * HDA/HDMI auto parsing
1131 static int hdmi_read_pin_conn(struct hda_codec
*codec
, int pin_idx
)
1133 struct hdmi_spec
*spec
= codec
->spec
;
1134 struct hdmi_spec_per_pin
*per_pin
= &spec
->pins
[pin_idx
];
1135 hda_nid_t pin_nid
= per_pin
->pin_nid
;
1137 if (!(get_wcaps(codec
, pin_nid
) & AC_WCAP_CONN_LIST
)) {
1138 snd_printk(KERN_WARNING
1139 "HDMI: pin %d wcaps %#x "
1140 "does not support connection list\n",
1141 pin_nid
, get_wcaps(codec
, pin_nid
));
1145 per_pin
->num_mux_nids
= snd_hda_get_connections(codec
, pin_nid
,
1147 HDA_MAX_CONNECTIONS
);
1152 static void hdmi_present_sense(struct hdmi_spec_per_pin
*per_pin
, int repoll
)
1154 struct hda_codec
*codec
= per_pin
->codec
;
1155 struct hdmi_eld
*eld
= &per_pin
->sink_eld
;
1156 hda_nid_t pin_nid
= per_pin
->pin_nid
;
1158 * Always execute a GetPinSense verb here, even when called from
1159 * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
1160 * response's PD bit is not the real PD value, but indicates that
1161 * the real PD value changed. An older version of the HD-audio
1162 * specification worked this way. Hence, we just ignore the data in
1163 * the unsolicited response to avoid custom WARs.
1165 int present
= snd_hda_pin_sense(codec
, pin_nid
);
1166 bool eld_valid
= false;
1168 memset(eld
, 0, offsetof(struct hdmi_eld
, eld_buffer
));
1170 eld
->monitor_present
= !!(present
& AC_PINSENSE_PRESENCE
);
1171 if (eld
->monitor_present
)
1172 eld_valid
= !!(present
& AC_PINSENSE_ELDV
);
1174 _snd_printd(SND_PR_VERBOSE
,
1175 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
1176 codec
->addr
, pin_nid
, eld
->monitor_present
, eld_valid
);
1179 if (!snd_hdmi_get_eld(eld
, codec
, pin_nid
))
1180 snd_hdmi_show_eld(eld
);
1182 queue_delayed_work(codec
->bus
->workq
,
1184 msecs_to_jiffies(300));
1189 static void hdmi_repoll_eld(struct work_struct
*work
)
1191 struct hdmi_spec_per_pin
*per_pin
=
1192 container_of(to_delayed_work(work
), struct hdmi_spec_per_pin
, work
);
1194 if (per_pin
->repoll_count
++ > 6)
1195 per_pin
->repoll_count
= 0;
1197 hdmi_present_sense(per_pin
, per_pin
->repoll_count
);
1200 static int hdmi_add_pin(struct hda_codec
*codec
, hda_nid_t pin_nid
)
1202 struct hdmi_spec
*spec
= codec
->spec
;
1203 unsigned int caps
, config
;
1205 struct hdmi_spec_per_pin
*per_pin
;
1208 caps
= snd_hda_query_pin_caps(codec
, pin_nid
);
1209 if (!(caps
& (AC_PINCAP_HDMI
| AC_PINCAP_DP
)))
1212 config
= snd_hda_codec_get_pincfg(codec
, pin_nid
);
1213 if (get_defcfg_connect(config
) == AC_JACK_PORT_NONE
)
1216 if (snd_BUG_ON(spec
->num_pins
>= MAX_HDMI_PINS
))
1219 pin_idx
= spec
->num_pins
;
1220 per_pin
= &spec
->pins
[pin_idx
];
1222 per_pin
->pin_nid
= pin_nid
;
1223 per_pin
->non_pcm
= false;
1225 err
= hdmi_read_pin_conn(codec
, pin_idx
);
1234 static int hdmi_add_cvt(struct hda_codec
*codec
, hda_nid_t cvt_nid
)
1236 struct hdmi_spec
*spec
= codec
->spec
;
1238 struct hdmi_spec_per_cvt
*per_cvt
;
1242 if (snd_BUG_ON(spec
->num_cvts
>= MAX_HDMI_CVTS
))
1245 chans
= get_wcaps(codec
, cvt_nid
);
1246 chans
= get_wcaps_channels(chans
);
1248 cvt_idx
= spec
->num_cvts
;
1249 per_cvt
= &spec
->cvts
[cvt_idx
];
1251 per_cvt
->cvt_nid
= cvt_nid
;
1252 per_cvt
->channels_min
= 2;
1254 per_cvt
->channels_max
= chans
;
1255 if (chans
> spec
->channels_max
)
1256 spec
->channels_max
= chans
;
1259 err
= snd_hda_query_supported_pcm(codec
, cvt_nid
,
1271 static int hdmi_parse_codec(struct hda_codec
*codec
)
1276 nodes
= snd_hda_get_sub_nodes(codec
, codec
->afg
, &nid
);
1277 if (!nid
|| nodes
< 0) {
1278 snd_printk(KERN_WARNING
"HDMI: failed to get afg sub nodes\n");
1282 for (i
= 0; i
< nodes
; i
++, nid
++) {
1286 caps
= get_wcaps(codec
, nid
);
1287 type
= get_wcaps_type(caps
);
1289 if (!(caps
& AC_WCAP_DIGITAL
))
1293 case AC_WID_AUD_OUT
:
1294 hdmi_add_cvt(codec
, nid
);
1297 hdmi_add_pin(codec
, nid
);
1303 /* We're seeing some problems with unsolicited hot plug events on
1304 * PantherPoint after S3, if this is not enabled */
1305 if (codec
->vendor_id
== 0x80862806)
1306 codec
->bus
->power_keep_link_on
= 1;
1308 * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event
1309 * can be lost and presence sense verb will become inaccurate if the
1310 * HDA link is powered off at hot plug or hw initialization time.
1312 else if (!(snd_hda_param_read(codec
, codec
->afg
, AC_PAR_POWER_STATE
) &
1314 codec
->bus
->power_keep_link_on
= 1;
1322 static char *get_hdmi_pcm_name(int idx
)
1324 static char names
[MAX_HDMI_PINS
][8];
1325 sprintf(&names
[idx
][0], "HDMI %d", idx
);
1326 return &names
[idx
][0];
1329 static bool check_non_pcm_per_cvt(struct hda_codec
*codec
, hda_nid_t cvt_nid
)
1331 struct hda_spdif_out
*spdif
;
1334 mutex_lock(&codec
->spdif_mutex
);
1335 spdif
= snd_hda_spdif_out_of_nid(codec
, cvt_nid
);
1336 non_pcm
= !!(spdif
->status
& IEC958_AES0_NONAUDIO
);
1337 mutex_unlock(&codec
->spdif_mutex
);
1346 static int generic_hdmi_playback_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
)
1352 hda_nid_t cvt_nid
= hinfo
->nid
;
1353 struct hdmi_spec
*spec
= codec
->spec
;
1354 int pin_idx
= hinfo_to_pin_index(spec
, hinfo
);
1355 hda_nid_t pin_nid
= spec
->pins
[pin_idx
].pin_nid
;
1358 non_pcm
= check_non_pcm_per_cvt(codec
, cvt_nid
);
1360 hdmi_set_channel_count(codec
, cvt_nid
, substream
->runtime
->channels
);
1362 hdmi_setup_audio_infoframe(codec
, pin_idx
, non_pcm
, substream
);
1364 return hdmi_setup_stream(codec
, cvt_nid
, pin_nid
, stream_tag
, format
);
1367 static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1368 struct hda_codec
*codec
,
1369 struct snd_pcm_substream
*substream
)
1371 snd_hda_codec_cleanup_stream(codec
, hinfo
->nid
);
1375 static int hdmi_pcm_close(struct hda_pcm_stream
*hinfo
,
1376 struct hda_codec
*codec
,
1377 struct snd_pcm_substream
*substream
)
1379 struct hdmi_spec
*spec
= codec
->spec
;
1380 int cvt_idx
, pin_idx
;
1381 struct hdmi_spec_per_cvt
*per_cvt
;
1382 struct hdmi_spec_per_pin
*per_pin
;
1385 cvt_idx
= cvt_nid_to_cvt_index(spec
, hinfo
->nid
);
1386 if (snd_BUG_ON(cvt_idx
< 0))
1388 per_cvt
= &spec
->cvts
[cvt_idx
];
1390 snd_BUG_ON(!per_cvt
->assigned
);
1391 per_cvt
->assigned
= 0;
1394 pin_idx
= hinfo_to_pin_index(spec
, hinfo
);
1395 if (snd_BUG_ON(pin_idx
< 0))
1397 per_pin
= &spec
->pins
[pin_idx
];
1399 snd_hda_spdif_ctls_unassign(codec
, pin_idx
);
1400 per_pin
->chmap_set
= false;
1401 memset(per_pin
->chmap
, 0, sizeof(per_pin
->chmap
));
1407 static const struct hda_pcm_ops generic_ops
= {
1408 .open
= hdmi_pcm_open
,
1409 .close
= hdmi_pcm_close
,
1410 .prepare
= generic_hdmi_playback_pcm_prepare
,
1411 .cleanup
= generic_hdmi_playback_pcm_cleanup
,
1415 * ALSA API channel-map control callbacks
1417 static int hdmi_chmap_ctl_info(struct snd_kcontrol
*kcontrol
,
1418 struct snd_ctl_elem_info
*uinfo
)
1420 struct snd_pcm_chmap
*info
= snd_kcontrol_chip(kcontrol
);
1421 struct hda_codec
*codec
= info
->private_data
;
1422 struct hdmi_spec
*spec
= codec
->spec
;
1423 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1424 uinfo
->count
= spec
->channels_max
;
1425 uinfo
->value
.integer
.min
= 0;
1426 uinfo
->value
.integer
.max
= SNDRV_CHMAP_LAST
;
1430 static int hdmi_chmap_ctl_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
1431 unsigned int size
, unsigned int __user
*tlv
)
1433 struct snd_pcm_chmap
*info
= snd_kcontrol_chip(kcontrol
);
1434 struct hda_codec
*codec
= info
->private_data
;
1435 struct hdmi_spec
*spec
= codec
->spec
;
1436 const unsigned int valid_mask
=
1437 FL
| FR
| RL
| RR
| LFE
| FC
| RLC
| RRC
;
1438 unsigned int __user
*dst
;
1443 if (put_user(SNDRV_CTL_TLVT_CONTAINER
, tlv
))
1447 for (chs
= 2; chs
<= spec
->channels_max
; chs
++) {
1449 struct cea_channel_speaker_allocation
*cap
;
1450 cap
= channel_allocations
;
1451 for (i
= 0; i
< ARRAY_SIZE(channel_allocations
); i
++, cap
++) {
1452 int chs_bytes
= chs
* 4;
1453 if (cap
->channels
!= chs
)
1455 if (cap
->spk_mask
& ~valid_mask
)
1459 if (put_user(SNDRV_CTL_TLVT_CHMAP_VAR
, dst
) ||
1460 put_user(chs_bytes
, dst
+ 1))
1465 if (size
< chs_bytes
)
1469 for (c
= 7; c
>= 0; c
--) {
1470 int spk
= cap
->speakers
[c
];
1473 if (put_user(spk_to_chmap(spk
), dst
))
1479 if (put_user(count
, tlv
+ 1))
1484 static int hdmi_chmap_ctl_get(struct snd_kcontrol
*kcontrol
,
1485 struct snd_ctl_elem_value
*ucontrol
)
1487 struct snd_pcm_chmap
*info
= snd_kcontrol_chip(kcontrol
);
1488 struct hda_codec
*codec
= info
->private_data
;
1489 struct hdmi_spec
*spec
= codec
->spec
;
1490 int pin_idx
= kcontrol
->private_value
;
1491 struct hdmi_spec_per_pin
*per_pin
= &spec
->pins
[pin_idx
];
1494 for (i
= 0; i
< ARRAY_SIZE(per_pin
->chmap
); i
++)
1495 ucontrol
->value
.integer
.value
[i
] = per_pin
->chmap
[i
];
1499 static int hdmi_chmap_ctl_put(struct snd_kcontrol
*kcontrol
,
1500 struct snd_ctl_elem_value
*ucontrol
)
1502 struct snd_pcm_chmap
*info
= snd_kcontrol_chip(kcontrol
);
1503 struct hda_codec
*codec
= info
->private_data
;
1504 struct hdmi_spec
*spec
= codec
->spec
;
1505 int pin_idx
= kcontrol
->private_value
;
1506 struct hdmi_spec_per_pin
*per_pin
= &spec
->pins
[pin_idx
];
1507 unsigned int ctl_idx
;
1508 struct snd_pcm_substream
*substream
;
1509 unsigned char chmap
[8];
1510 int i
, ca
, prepared
= 0;
1512 ctl_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1513 substream
= snd_pcm_chmap_substream(info
, ctl_idx
);
1514 if (!substream
|| !substream
->runtime
)
1515 return 0; /* just for avoiding error from alsactl restore */
1516 switch (substream
->runtime
->status
->state
) {
1517 case SNDRV_PCM_STATE_OPEN
:
1518 case SNDRV_PCM_STATE_SETUP
:
1520 case SNDRV_PCM_STATE_PREPARED
:
1526 memset(chmap
, 0, sizeof(chmap
));
1527 for (i
= 0; i
< ARRAY_SIZE(chmap
); i
++)
1528 chmap
[i
] = ucontrol
->value
.integer
.value
[i
];
1529 if (!memcmp(chmap
, per_pin
->chmap
, sizeof(chmap
)))
1531 ca
= hdmi_manual_channel_allocation(ARRAY_SIZE(chmap
), chmap
);
1534 per_pin
->chmap_set
= true;
1535 memcpy(per_pin
->chmap
, chmap
, sizeof(chmap
));
1537 hdmi_setup_audio_infoframe(codec
, pin_idx
, per_pin
->non_pcm
,
1543 static int generic_hdmi_build_pcms(struct hda_codec
*codec
)
1545 struct hdmi_spec
*spec
= codec
->spec
;
1548 for (pin_idx
= 0; pin_idx
< spec
->num_pins
; pin_idx
++) {
1549 struct hda_pcm
*info
;
1550 struct hda_pcm_stream
*pstr
;
1552 info
= &spec
->pcm_rec
[pin_idx
];
1553 info
->name
= get_hdmi_pcm_name(pin_idx
);
1554 info
->pcm_type
= HDA_PCM_TYPE_HDMI
;
1555 info
->own_chmap
= true;
1557 pstr
= &info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
];
1558 pstr
->substreams
= 1;
1559 pstr
->ops
= generic_ops
;
1560 /* other pstr fields are set in open */
1563 codec
->num_pcms
= spec
->num_pins
;
1564 codec
->pcm_info
= spec
->pcm_rec
;
1569 static int generic_hdmi_build_jack(struct hda_codec
*codec
, int pin_idx
)
1571 char hdmi_str
[32] = "HDMI/DP";
1572 struct hdmi_spec
*spec
= codec
->spec
;
1573 struct hdmi_spec_per_pin
*per_pin
= &spec
->pins
[pin_idx
];
1574 int pcmdev
= spec
->pcm_rec
[pin_idx
].device
;
1577 sprintf(hdmi_str
+ strlen(hdmi_str
), ",pcm=%d", pcmdev
);
1579 return snd_hda_jack_add_kctl(codec
, per_pin
->pin_nid
, hdmi_str
, 0);
1582 static int generic_hdmi_build_controls(struct hda_codec
*codec
)
1584 struct hdmi_spec
*spec
= codec
->spec
;
1588 for (pin_idx
= 0; pin_idx
< spec
->num_pins
; pin_idx
++) {
1589 struct hdmi_spec_per_pin
*per_pin
= &spec
->pins
[pin_idx
];
1591 err
= generic_hdmi_build_jack(codec
, pin_idx
);
1595 err
= snd_hda_create_dig_out_ctls(codec
,
1597 per_pin
->mux_nids
[0],
1601 snd_hda_spdif_ctls_unassign(codec
, pin_idx
);
1603 /* add control for ELD Bytes */
1604 err
= hdmi_create_eld_ctl(codec
,
1606 spec
->pcm_rec
[pin_idx
].device
);
1611 hdmi_present_sense(per_pin
, 0);
1614 /* add channel maps */
1615 for (pin_idx
= 0; pin_idx
< spec
->num_pins
; pin_idx
++) {
1616 struct snd_pcm_chmap
*chmap
;
1617 struct snd_kcontrol
*kctl
;
1619 err
= snd_pcm_add_chmap_ctls(codec
->pcm_info
[pin_idx
].pcm
,
1620 SNDRV_PCM_STREAM_PLAYBACK
,
1621 NULL
, 0, pin_idx
, &chmap
);
1624 /* override handlers */
1625 chmap
->private_data
= codec
;
1627 for (i
= 0; i
< kctl
->count
; i
++)
1628 kctl
->vd
[i
].access
|= SNDRV_CTL_ELEM_ACCESS_WRITE
;
1629 kctl
->info
= hdmi_chmap_ctl_info
;
1630 kctl
->get
= hdmi_chmap_ctl_get
;
1631 kctl
->put
= hdmi_chmap_ctl_put
;
1632 kctl
->tlv
.c
= hdmi_chmap_ctl_tlv
;
1638 static int generic_hdmi_init_per_pins(struct hda_codec
*codec
)
1640 struct hdmi_spec
*spec
= codec
->spec
;
1643 for (pin_idx
= 0; pin_idx
< spec
->num_pins
; pin_idx
++) {
1644 struct hdmi_spec_per_pin
*per_pin
= &spec
->pins
[pin_idx
];
1645 struct hdmi_eld
*eld
= &per_pin
->sink_eld
;
1647 per_pin
->codec
= codec
;
1648 INIT_DELAYED_WORK(&per_pin
->work
, hdmi_repoll_eld
);
1649 snd_hda_eld_proc_new(codec
, eld
, pin_idx
);
1654 static int generic_hdmi_init(struct hda_codec
*codec
)
1656 struct hdmi_spec
*spec
= codec
->spec
;
1659 for (pin_idx
= 0; pin_idx
< spec
->num_pins
; pin_idx
++) {
1660 struct hdmi_spec_per_pin
*per_pin
= &spec
->pins
[pin_idx
];
1661 hda_nid_t pin_nid
= per_pin
->pin_nid
;
1663 hdmi_init_pin(codec
, pin_nid
);
1664 snd_hda_jack_detect_enable(codec
, pin_nid
, pin_nid
);
1669 static void generic_hdmi_free(struct hda_codec
*codec
)
1671 struct hdmi_spec
*spec
= codec
->spec
;
1674 for (pin_idx
= 0; pin_idx
< spec
->num_pins
; pin_idx
++) {
1675 struct hdmi_spec_per_pin
*per_pin
= &spec
->pins
[pin_idx
];
1676 struct hdmi_eld
*eld
= &per_pin
->sink_eld
;
1678 cancel_delayed_work(&per_pin
->work
);
1679 snd_hda_eld_proc_free(codec
, eld
);
1682 flush_workqueue(codec
->bus
->workq
);
1686 static const struct hda_codec_ops generic_hdmi_patch_ops
= {
1687 .init
= generic_hdmi_init
,
1688 .free
= generic_hdmi_free
,
1689 .build_pcms
= generic_hdmi_build_pcms
,
1690 .build_controls
= generic_hdmi_build_controls
,
1691 .unsol_event
= hdmi_unsol_event
,
1694 static void intel_haswell_fixup_connect_list(struct hda_codec
*codec
)
1696 unsigned int vendor_param
;
1697 hda_nid_t list
[3] = {0x2, 0x3, 0x4};
1699 vendor_param
= snd_hda_codec_read(codec
, 0x08, 0, 0xf81, 0);
1700 if (vendor_param
== -1 || vendor_param
& 0x02)
1703 /* enable DP1.2 mode */
1704 vendor_param
|= 0x02;
1705 snd_hda_codec_read(codec
, 0x08, 0, 0x781, vendor_param
);
1707 vendor_param
= snd_hda_codec_read(codec
, 0x08, 0, 0xf81, 0);
1708 if (vendor_param
== -1 || !(vendor_param
& 0x02))
1711 /* override 3 pins connection list */
1712 snd_hda_override_conn_list(codec
, 0x05, 3, list
);
1713 snd_hda_override_conn_list(codec
, 0x06, 3, list
);
1714 snd_hda_override_conn_list(codec
, 0x07, 3, list
);
1717 #define INTEL_VENDOR_NID 0x08
1718 #define INTEL_GET_VENDOR_VERB 0xf81
1719 #define INTEL_SET_VENDOR_VERB 0x781
1720 #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
1721 #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
1723 static void intel_haswell_enable_all_pins(struct hda_codec
*codec
,
1724 const struct hda_fixup
*fix
, int action
)
1726 unsigned int vendor_param
;
1728 if (action
!= HDA_FIXUP_ACT_PRE_PROBE
)
1730 vendor_param
= snd_hda_codec_read(codec
, INTEL_VENDOR_NID
, 0,
1731 INTEL_GET_VENDOR_VERB
, 0);
1732 if (vendor_param
== -1 || vendor_param
& INTEL_EN_ALL_PIN_CVTS
)
1735 vendor_param
|= INTEL_EN_ALL_PIN_CVTS
;
1736 vendor_param
= snd_hda_codec_read(codec
, INTEL_VENDOR_NID
, 0,
1737 INTEL_SET_VENDOR_VERB
, vendor_param
);
1738 if (vendor_param
== -1)
1741 snd_hda_codec_update_widgets(codec
);
1746 /* available models for fixup */
1751 static const struct hda_model_fixup hdmi_models
[] = {
1752 {.id
= INTEL_HASWELL
, .name
= "Haswell"},
1756 static const struct snd_pci_quirk hdmi_fixup_tbl
[] = {
1757 SND_PCI_QUIRK(0x8086, 0x2010, "Haswell", INTEL_HASWELL
),
1761 static const struct hda_fixup hdmi_fixups
[] = {
1763 .type
= HDA_FIXUP_FUNC
,
1764 .v
.func
= intel_haswell_enable_all_pins
,
1769 static int patch_generic_hdmi(struct hda_codec
*codec
)
1771 struct hdmi_spec
*spec
;
1773 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1779 snd_hda_pick_fixup(codec
, hdmi_models
, hdmi_fixup_tbl
, hdmi_fixups
);
1780 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
1782 if (codec
->vendor_id
== 0x80862807)
1783 intel_haswell_fixup_connect_list(codec
);
1785 if (hdmi_parse_codec(codec
) < 0) {
1790 codec
->patch_ops
= generic_hdmi_patch_ops
;
1791 generic_hdmi_init_per_pins(codec
);
1793 init_channel_allocations();
1799 * Shared non-generic implementations
1802 static int simple_playback_build_pcms(struct hda_codec
*codec
)
1804 struct hdmi_spec
*spec
= codec
->spec
;
1805 struct hda_pcm
*info
= spec
->pcm_rec
;
1807 struct hda_pcm_stream
*pstr
;
1809 codec
->num_pcms
= 1;
1810 codec
->pcm_info
= info
;
1812 chans
= get_wcaps(codec
, spec
->cvts
[0].cvt_nid
);
1813 chans
= get_wcaps_channels(chans
);
1815 info
->name
= get_hdmi_pcm_name(0);
1816 info
->pcm_type
= HDA_PCM_TYPE_HDMI
;
1817 pstr
= &info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
];
1818 *pstr
= spec
->pcm_playback
;
1819 pstr
->nid
= spec
->cvts
[0].cvt_nid
;
1820 if (pstr
->channels_max
<= 2 && chans
&& chans
<= 16)
1821 pstr
->channels_max
= chans
;
1826 /* unsolicited event for jack sensing */
1827 static void simple_hdmi_unsol_event(struct hda_codec
*codec
,
1830 snd_hda_jack_set_dirty_all(codec
);
1831 snd_hda_jack_report_sync(codec
);
1834 /* generic_hdmi_build_jack can be used for simple_hdmi, too,
1835 * as long as spec->pins[] is set correctly
1837 #define simple_hdmi_build_jack generic_hdmi_build_jack
1839 static int simple_playback_build_controls(struct hda_codec
*codec
)
1841 struct hdmi_spec
*spec
= codec
->spec
;
1844 err
= snd_hda_create_spdif_out_ctls(codec
,
1845 spec
->cvts
[0].cvt_nid
,
1846 spec
->cvts
[0].cvt_nid
);
1849 return simple_hdmi_build_jack(codec
, 0);
1852 static int simple_playback_init(struct hda_codec
*codec
)
1854 struct hdmi_spec
*spec
= codec
->spec
;
1855 hda_nid_t pin
= spec
->pins
[0].pin_nid
;
1857 snd_hda_codec_write(codec
, pin
, 0,
1858 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
);
1859 /* some codecs require to unmute the pin */
1860 if (get_wcaps(codec
, pin
) & AC_WCAP_OUT_AMP
)
1861 snd_hda_codec_write(codec
, pin
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
1863 snd_hda_jack_detect_enable(codec
, pin
, pin
);
1867 static void simple_playback_free(struct hda_codec
*codec
)
1869 struct hdmi_spec
*spec
= codec
->spec
;
1875 * Nvidia specific implementations
1878 #define Nv_VERB_SET_Channel_Allocation 0xF79
1879 #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
1880 #define Nv_VERB_SET_Audio_Protection_On 0xF98
1881 #define Nv_VERB_SET_Audio_Protection_Off 0xF99
1883 #define nvhdmi_master_con_nid_7x 0x04
1884 #define nvhdmi_master_pin_nid_7x 0x05
1886 static const hda_nid_t nvhdmi_con_nids_7x
[4] = {
1887 /*front, rear, clfe, rear_surr */
1891 static const struct hda_verb nvhdmi_basic_init_7x_2ch
[] = {
1892 /* set audio protect on */
1893 { 0x1, Nv_VERB_SET_Audio_Protection_On
, 0x1},
1894 /* enable digital output on pin widget */
1895 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
| 0x5 },
1899 static const struct hda_verb nvhdmi_basic_init_7x_8ch
[] = {
1900 /* set audio protect on */
1901 { 0x1, Nv_VERB_SET_Audio_Protection_On
, 0x1},
1902 /* enable digital output on pin widget */
1903 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
| 0x5 },
1904 { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
| 0x5 },
1905 { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
| 0x5 },
1906 { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
| 0x5 },
1907 { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
| 0x5 },
1911 #ifdef LIMITED_RATE_FMT_SUPPORT
1912 /* support only the safe format and rate */
1913 #define SUPPORTED_RATES SNDRV_PCM_RATE_48000
1914 #define SUPPORTED_MAXBPS 16
1915 #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
1917 /* support all rates and formats */
1918 #define SUPPORTED_RATES \
1919 (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
1920 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
1921 SNDRV_PCM_RATE_192000)
1922 #define SUPPORTED_MAXBPS 24
1923 #define SUPPORTED_FORMATS \
1924 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
1927 static int nvhdmi_7x_init_2ch(struct hda_codec
*codec
)
1929 snd_hda_sequence_write(codec
, nvhdmi_basic_init_7x_2ch
);
1933 static int nvhdmi_7x_init_8ch(struct hda_codec
*codec
)
1935 snd_hda_sequence_write(codec
, nvhdmi_basic_init_7x_8ch
);
1939 static unsigned int channels_2_6_8
[] = {
1943 static unsigned int channels_2_8
[] = {
1947 static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels
= {
1948 .count
= ARRAY_SIZE(channels_2_6_8
),
1949 .list
= channels_2_6_8
,
1953 static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels
= {
1954 .count
= ARRAY_SIZE(channels_2_8
),
1955 .list
= channels_2_8
,
1959 static int simple_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
1960 struct hda_codec
*codec
,
1961 struct snd_pcm_substream
*substream
)
1963 struct hdmi_spec
*spec
= codec
->spec
;
1964 struct snd_pcm_hw_constraint_list
*hw_constraints_channels
= NULL
;
1966 switch (codec
->preset
->id
) {
1971 hw_constraints_channels
= &hw_constraints_2_8_channels
;
1974 hw_constraints_channels
= &hw_constraints_2_6_8_channels
;
1980 if (hw_constraints_channels
!= NULL
) {
1981 snd_pcm_hw_constraint_list(substream
->runtime
, 0,
1982 SNDRV_PCM_HW_PARAM_CHANNELS
,
1983 hw_constraints_channels
);
1985 snd_pcm_hw_constraint_step(substream
->runtime
, 0,
1986 SNDRV_PCM_HW_PARAM_CHANNELS
, 2);
1989 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
1992 static int simple_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
1993 struct hda_codec
*codec
,
1994 struct snd_pcm_substream
*substream
)
1996 struct hdmi_spec
*spec
= codec
->spec
;
1997 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
2000 static int simple_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2001 struct hda_codec
*codec
,
2002 unsigned int stream_tag
,
2003 unsigned int format
,
2004 struct snd_pcm_substream
*substream
)
2006 struct hdmi_spec
*spec
= codec
->spec
;
2007 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
2008 stream_tag
, format
, substream
);
2011 static const struct hda_pcm_stream simple_pcm_playback
= {
2016 .open
= simple_playback_pcm_open
,
2017 .close
= simple_playback_pcm_close
,
2018 .prepare
= simple_playback_pcm_prepare
2022 static const struct hda_codec_ops simple_hdmi_patch_ops
= {
2023 .build_controls
= simple_playback_build_controls
,
2024 .build_pcms
= simple_playback_build_pcms
,
2025 .init
= simple_playback_init
,
2026 .free
= simple_playback_free
,
2027 .unsol_event
= simple_hdmi_unsol_event
,
2030 static int patch_simple_hdmi(struct hda_codec
*codec
,
2031 hda_nid_t cvt_nid
, hda_nid_t pin_nid
)
2033 struct hdmi_spec
*spec
;
2035 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2041 spec
->multiout
.num_dacs
= 0; /* no analog */
2042 spec
->multiout
.max_channels
= 2;
2043 spec
->multiout
.dig_out_nid
= cvt_nid
;
2046 spec
->cvts
[0].cvt_nid
= cvt_nid
;
2047 spec
->pins
[0].pin_nid
= pin_nid
;
2048 spec
->pcm_playback
= simple_pcm_playback
;
2050 codec
->patch_ops
= simple_hdmi_patch_ops
;
2055 static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec
*codec
,
2058 unsigned int chanmask
;
2059 int chan
= channels
? (channels
- 1) : 1;
2078 /* Set the audio infoframe channel allocation and checksum fields. The
2079 * channel count is computed implicitly by the hardware. */
2080 snd_hda_codec_write(codec
, 0x1, 0,
2081 Nv_VERB_SET_Channel_Allocation
, chanmask
);
2083 snd_hda_codec_write(codec
, 0x1, 0,
2084 Nv_VERB_SET_Info_Frame_Checksum
,
2085 (0x71 - chan
- chanmask
));
2088 static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream
*hinfo
,
2089 struct hda_codec
*codec
,
2090 struct snd_pcm_substream
*substream
)
2092 struct hdmi_spec
*spec
= codec
->spec
;
2095 snd_hda_codec_write(codec
, nvhdmi_master_con_nid_7x
,
2096 0, AC_VERB_SET_CHANNEL_STREAMID
, 0);
2097 for (i
= 0; i
< 4; i
++) {
2098 /* set the stream id */
2099 snd_hda_codec_write(codec
, nvhdmi_con_nids_7x
[i
], 0,
2100 AC_VERB_SET_CHANNEL_STREAMID
, 0);
2101 /* set the stream format */
2102 snd_hda_codec_write(codec
, nvhdmi_con_nids_7x
[i
], 0,
2103 AC_VERB_SET_STREAM_FORMAT
, 0);
2106 /* The audio hardware sends a channel count of 0x7 (8ch) when all the
2107 * streams are disabled. */
2108 nvhdmi_8ch_7x_set_info_frame_parameters(codec
, 8);
2110 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
2113 static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2114 struct hda_codec
*codec
,
2115 unsigned int stream_tag
,
2116 unsigned int format
,
2117 struct snd_pcm_substream
*substream
)
2120 unsigned int dataDCC2
, channel_id
;
2122 struct hdmi_spec
*spec
= codec
->spec
;
2123 struct hda_spdif_out
*spdif
;
2125 mutex_lock(&codec
->spdif_mutex
);
2126 spdif
= snd_hda_spdif_out_of_nid(codec
, spec
->cvts
[0].cvt_nid
);
2128 chs
= substream
->runtime
->channels
;
2132 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
2133 if (codec
->spdif_status_reset
&& (spdif
->ctls
& AC_DIG1_ENABLE
))
2134 snd_hda_codec_write(codec
,
2135 nvhdmi_master_con_nid_7x
,
2137 AC_VERB_SET_DIGI_CONVERT_1
,
2138 spdif
->ctls
& ~AC_DIG1_ENABLE
& 0xff);
2140 /* set the stream id */
2141 snd_hda_codec_write(codec
, nvhdmi_master_con_nid_7x
, 0,
2142 AC_VERB_SET_CHANNEL_STREAMID
, (stream_tag
<< 4) | 0x0);
2144 /* set the stream format */
2145 snd_hda_codec_write(codec
, nvhdmi_master_con_nid_7x
, 0,
2146 AC_VERB_SET_STREAM_FORMAT
, format
);
2148 /* turn on again (if needed) */
2149 /* enable and set the channel status audio/data flag */
2150 if (codec
->spdif_status_reset
&& (spdif
->ctls
& AC_DIG1_ENABLE
)) {
2151 snd_hda_codec_write(codec
,
2152 nvhdmi_master_con_nid_7x
,
2154 AC_VERB_SET_DIGI_CONVERT_1
,
2155 spdif
->ctls
& 0xff);
2156 snd_hda_codec_write(codec
,
2157 nvhdmi_master_con_nid_7x
,
2159 AC_VERB_SET_DIGI_CONVERT_2
, dataDCC2
);
2162 for (i
= 0; i
< 4; i
++) {
2168 /* turn off SPDIF once;
2169 *otherwise the IEC958 bits won't be updated
2171 if (codec
->spdif_status_reset
&&
2172 (spdif
->ctls
& AC_DIG1_ENABLE
))
2173 snd_hda_codec_write(codec
,
2174 nvhdmi_con_nids_7x
[i
],
2176 AC_VERB_SET_DIGI_CONVERT_1
,
2177 spdif
->ctls
& ~AC_DIG1_ENABLE
& 0xff);
2178 /* set the stream id */
2179 snd_hda_codec_write(codec
,
2180 nvhdmi_con_nids_7x
[i
],
2182 AC_VERB_SET_CHANNEL_STREAMID
,
2183 (stream_tag
<< 4) | channel_id
);
2184 /* set the stream format */
2185 snd_hda_codec_write(codec
,
2186 nvhdmi_con_nids_7x
[i
],
2188 AC_VERB_SET_STREAM_FORMAT
,
2190 /* turn on again (if needed) */
2191 /* enable and set the channel status audio/data flag */
2192 if (codec
->spdif_status_reset
&&
2193 (spdif
->ctls
& AC_DIG1_ENABLE
)) {
2194 snd_hda_codec_write(codec
,
2195 nvhdmi_con_nids_7x
[i
],
2197 AC_VERB_SET_DIGI_CONVERT_1
,
2198 spdif
->ctls
& 0xff);
2199 snd_hda_codec_write(codec
,
2200 nvhdmi_con_nids_7x
[i
],
2202 AC_VERB_SET_DIGI_CONVERT_2
, dataDCC2
);
2206 nvhdmi_8ch_7x_set_info_frame_parameters(codec
, chs
);
2208 mutex_unlock(&codec
->spdif_mutex
);
2212 static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x
= {
2216 .nid
= nvhdmi_master_con_nid_7x
,
2217 .rates
= SUPPORTED_RATES
,
2218 .maxbps
= SUPPORTED_MAXBPS
,
2219 .formats
= SUPPORTED_FORMATS
,
2221 .open
= simple_playback_pcm_open
,
2222 .close
= nvhdmi_8ch_7x_pcm_close
,
2223 .prepare
= nvhdmi_8ch_7x_pcm_prepare
2227 static int patch_nvhdmi_2ch(struct hda_codec
*codec
)
2229 struct hdmi_spec
*spec
;
2230 int err
= patch_simple_hdmi(codec
, nvhdmi_master_con_nid_7x
,
2231 nvhdmi_master_pin_nid_7x
);
2235 codec
->patch_ops
.init
= nvhdmi_7x_init_2ch
;
2236 /* override the PCM rates, etc, as the codec doesn't give full list */
2238 spec
->pcm_playback
.rates
= SUPPORTED_RATES
;
2239 spec
->pcm_playback
.maxbps
= SUPPORTED_MAXBPS
;
2240 spec
->pcm_playback
.formats
= SUPPORTED_FORMATS
;
2244 static int nvhdmi_7x_8ch_build_pcms(struct hda_codec
*codec
)
2246 struct hdmi_spec
*spec
= codec
->spec
;
2247 int err
= simple_playback_build_pcms(codec
);
2248 spec
->pcm_rec
[0].own_chmap
= true;
2252 static int nvhdmi_7x_8ch_build_controls(struct hda_codec
*codec
)
2254 struct hdmi_spec
*spec
= codec
->spec
;
2255 struct snd_pcm_chmap
*chmap
;
2258 err
= simple_playback_build_controls(codec
);
2262 /* add channel maps */
2263 err
= snd_pcm_add_chmap_ctls(spec
->pcm_rec
[0].pcm
,
2264 SNDRV_PCM_STREAM_PLAYBACK
,
2265 snd_pcm_alt_chmaps
, 8, 0, &chmap
);
2268 switch (codec
->preset
->id
) {
2273 chmap
->channel_mask
= (1U << 2) | (1U << 8);
2276 chmap
->channel_mask
= (1U << 2) | (1U << 6) | (1U << 8);
2281 static int patch_nvhdmi_8ch_7x(struct hda_codec
*codec
)
2283 struct hdmi_spec
*spec
;
2284 int err
= patch_nvhdmi_2ch(codec
);
2288 spec
->multiout
.max_channels
= 8;
2289 spec
->pcm_playback
= nvhdmi_pcm_playback_8ch_7x
;
2290 codec
->patch_ops
.init
= nvhdmi_7x_init_8ch
;
2291 codec
->patch_ops
.build_pcms
= nvhdmi_7x_8ch_build_pcms
;
2292 codec
->patch_ops
.build_controls
= nvhdmi_7x_8ch_build_controls
;
2294 /* Initialize the audio infoframe channel mask and checksum to something
2296 nvhdmi_8ch_7x_set_info_frame_parameters(codec
, 8);
2302 * ATI-specific implementations
2304 * FIXME: we may omit the whole this and use the generic code once after
2305 * it's confirmed to work.
2308 #define ATIHDMI_CVT_NID 0x02 /* audio converter */
2309 #define ATIHDMI_PIN_NID 0x03 /* HDMI output pin */
2311 static int atihdmi_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2312 struct hda_codec
*codec
,
2313 unsigned int stream_tag
,
2314 unsigned int format
,
2315 struct snd_pcm_substream
*substream
)
2317 struct hdmi_spec
*spec
= codec
->spec
;
2318 int chans
= substream
->runtime
->channels
;
2321 err
= simple_playback_pcm_prepare(hinfo
, codec
, stream_tag
, format
,
2325 snd_hda_codec_write(codec
, spec
->cvts
[0].cvt_nid
, 0,
2326 AC_VERB_SET_CVT_CHAN_COUNT
, chans
- 1);
2328 for (i
= 0; i
< chans
; i
++) {
2329 snd_hda_codec_write(codec
, spec
->cvts
[0].cvt_nid
, 0,
2330 AC_VERB_SET_HDMI_CHAN_SLOT
,
2336 static int patch_atihdmi(struct hda_codec
*codec
)
2338 struct hdmi_spec
*spec
;
2339 int err
= patch_simple_hdmi(codec
, ATIHDMI_CVT_NID
, ATIHDMI_PIN_NID
);
2343 spec
->pcm_playback
.ops
.prepare
= atihdmi_playback_pcm_prepare
;
2347 /* VIA HDMI Implementation */
2348 #define VIAHDMI_CVT_NID 0x02 /* audio converter1 */
2349 #define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */
2351 static int patch_via_hdmi(struct hda_codec
*codec
)
2353 return patch_simple_hdmi(codec
, VIAHDMI_CVT_NID
, VIAHDMI_PIN_NID
);
2359 static const struct hda_codec_preset snd_hda_preset_hdmi
[] = {
2360 { .id
= 0x1002793c, .name
= "RS600 HDMI", .patch
= patch_atihdmi
},
2361 { .id
= 0x10027919, .name
= "RS600 HDMI", .patch
= patch_atihdmi
},
2362 { .id
= 0x1002791a, .name
= "RS690/780 HDMI", .patch
= patch_atihdmi
},
2363 { .id
= 0x1002aa01, .name
= "R6xx HDMI", .patch
= patch_generic_hdmi
},
2364 { .id
= 0x10951390, .name
= "SiI1390 HDMI", .patch
= patch_generic_hdmi
},
2365 { .id
= 0x10951392, .name
= "SiI1392 HDMI", .patch
= patch_generic_hdmi
},
2366 { .id
= 0x17e80047, .name
= "Chrontel HDMI", .patch
= patch_generic_hdmi
},
2367 { .id
= 0x10de0002, .name
= "MCP77/78 HDMI", .patch
= patch_nvhdmi_8ch_7x
},
2368 { .id
= 0x10de0003, .name
= "MCP77/78 HDMI", .patch
= patch_nvhdmi_8ch_7x
},
2369 { .id
= 0x10de0005, .name
= "MCP77/78 HDMI", .patch
= patch_nvhdmi_8ch_7x
},
2370 { .id
= 0x10de0006, .name
= "MCP77/78 HDMI", .patch
= patch_nvhdmi_8ch_7x
},
2371 { .id
= 0x10de0007, .name
= "MCP79/7A HDMI", .patch
= patch_nvhdmi_8ch_7x
},
2372 { .id
= 0x10de000a, .name
= "GPU 0a HDMI/DP", .patch
= patch_generic_hdmi
},
2373 { .id
= 0x10de000b, .name
= "GPU 0b HDMI/DP", .patch
= patch_generic_hdmi
},
2374 { .id
= 0x10de000c, .name
= "MCP89 HDMI", .patch
= patch_generic_hdmi
},
2375 { .id
= 0x10de000d, .name
= "GPU 0d HDMI/DP", .patch
= patch_generic_hdmi
},
2376 { .id
= 0x10de0010, .name
= "GPU 10 HDMI/DP", .patch
= patch_generic_hdmi
},
2377 { .id
= 0x10de0011, .name
= "GPU 11 HDMI/DP", .patch
= patch_generic_hdmi
},
2378 { .id
= 0x10de0012, .name
= "GPU 12 HDMI/DP", .patch
= patch_generic_hdmi
},
2379 { .id
= 0x10de0013, .name
= "GPU 13 HDMI/DP", .patch
= patch_generic_hdmi
},
2380 { .id
= 0x10de0014, .name
= "GPU 14 HDMI/DP", .patch
= patch_generic_hdmi
},
2381 { .id
= 0x10de0015, .name
= "GPU 15 HDMI/DP", .patch
= patch_generic_hdmi
},
2382 { .id
= 0x10de0016, .name
= "GPU 16 HDMI/DP", .patch
= patch_generic_hdmi
},
2383 /* 17 is known to be absent */
2384 { .id
= 0x10de0018, .name
= "GPU 18 HDMI/DP", .patch
= patch_generic_hdmi
},
2385 { .id
= 0x10de0019, .name
= "GPU 19 HDMI/DP", .patch
= patch_generic_hdmi
},
2386 { .id
= 0x10de001a, .name
= "GPU 1a HDMI/DP", .patch
= patch_generic_hdmi
},
2387 { .id
= 0x10de001b, .name
= "GPU 1b HDMI/DP", .patch
= patch_generic_hdmi
},
2388 { .id
= 0x10de001c, .name
= "GPU 1c HDMI/DP", .patch
= patch_generic_hdmi
},
2389 { .id
= 0x10de0040, .name
= "GPU 40 HDMI/DP", .patch
= patch_generic_hdmi
},
2390 { .id
= 0x10de0041, .name
= "GPU 41 HDMI/DP", .patch
= patch_generic_hdmi
},
2391 { .id
= 0x10de0042, .name
= "GPU 42 HDMI/DP", .patch
= patch_generic_hdmi
},
2392 { .id
= 0x10de0043, .name
= "GPU 43 HDMI/DP", .patch
= patch_generic_hdmi
},
2393 { .id
= 0x10de0044, .name
= "GPU 44 HDMI/DP", .patch
= patch_generic_hdmi
},
2394 { .id
= 0x10de0051, .name
= "GPU 51 HDMI/DP", .patch
= patch_generic_hdmi
},
2395 { .id
= 0x10de0067, .name
= "MCP67 HDMI", .patch
= patch_nvhdmi_2ch
},
2396 { .id
= 0x10de8001, .name
= "MCP73 HDMI", .patch
= patch_nvhdmi_2ch
},
2397 { .id
= 0x11069f80, .name
= "VX900 HDMI/DP", .patch
= patch_via_hdmi
},
2398 { .id
= 0x11069f81, .name
= "VX900 HDMI/DP", .patch
= patch_via_hdmi
},
2399 { .id
= 0x11069f84, .name
= "VX11 HDMI/DP", .patch
= patch_generic_hdmi
},
2400 { .id
= 0x11069f85, .name
= "VX11 HDMI/DP", .patch
= patch_generic_hdmi
},
2401 { .id
= 0x80860054, .name
= "IbexPeak HDMI", .patch
= patch_generic_hdmi
},
2402 { .id
= 0x80862801, .name
= "Bearlake HDMI", .patch
= patch_generic_hdmi
},
2403 { .id
= 0x80862802, .name
= "Cantiga HDMI", .patch
= patch_generic_hdmi
},
2404 { .id
= 0x80862803, .name
= "Eaglelake HDMI", .patch
= patch_generic_hdmi
},
2405 { .id
= 0x80862804, .name
= "IbexPeak HDMI", .patch
= patch_generic_hdmi
},
2406 { .id
= 0x80862805, .name
= "CougarPoint HDMI", .patch
= patch_generic_hdmi
},
2407 { .id
= 0x80862806, .name
= "PantherPoint HDMI", .patch
= patch_generic_hdmi
},
2408 { .id
= 0x80862807, .name
= "Haswell HDMI", .patch
= patch_generic_hdmi
},
2409 { .id
= 0x80862880, .name
= "CedarTrail HDMI", .patch
= patch_generic_hdmi
},
2410 { .id
= 0x808629fb, .name
= "Crestline HDMI", .patch
= patch_generic_hdmi
},
2414 MODULE_ALIAS("snd-hda-codec-id:1002793c");
2415 MODULE_ALIAS("snd-hda-codec-id:10027919");
2416 MODULE_ALIAS("snd-hda-codec-id:1002791a");
2417 MODULE_ALIAS("snd-hda-codec-id:1002aa01");
2418 MODULE_ALIAS("snd-hda-codec-id:10951390");
2419 MODULE_ALIAS("snd-hda-codec-id:10951392");
2420 MODULE_ALIAS("snd-hda-codec-id:10de0002");
2421 MODULE_ALIAS("snd-hda-codec-id:10de0003");
2422 MODULE_ALIAS("snd-hda-codec-id:10de0005");
2423 MODULE_ALIAS("snd-hda-codec-id:10de0006");
2424 MODULE_ALIAS("snd-hda-codec-id:10de0007");
2425 MODULE_ALIAS("snd-hda-codec-id:10de000a");
2426 MODULE_ALIAS("snd-hda-codec-id:10de000b");
2427 MODULE_ALIAS("snd-hda-codec-id:10de000c");
2428 MODULE_ALIAS("snd-hda-codec-id:10de000d");
2429 MODULE_ALIAS("snd-hda-codec-id:10de0010");
2430 MODULE_ALIAS("snd-hda-codec-id:10de0011");
2431 MODULE_ALIAS("snd-hda-codec-id:10de0012");
2432 MODULE_ALIAS("snd-hda-codec-id:10de0013");
2433 MODULE_ALIAS("snd-hda-codec-id:10de0014");
2434 MODULE_ALIAS("snd-hda-codec-id:10de0015");
2435 MODULE_ALIAS("snd-hda-codec-id:10de0016");
2436 MODULE_ALIAS("snd-hda-codec-id:10de0018");
2437 MODULE_ALIAS("snd-hda-codec-id:10de0019");
2438 MODULE_ALIAS("snd-hda-codec-id:10de001a");
2439 MODULE_ALIAS("snd-hda-codec-id:10de001b");
2440 MODULE_ALIAS("snd-hda-codec-id:10de001c");
2441 MODULE_ALIAS("snd-hda-codec-id:10de0040");
2442 MODULE_ALIAS("snd-hda-codec-id:10de0041");
2443 MODULE_ALIAS("snd-hda-codec-id:10de0042");
2444 MODULE_ALIAS("snd-hda-codec-id:10de0043");
2445 MODULE_ALIAS("snd-hda-codec-id:10de0044");
2446 MODULE_ALIAS("snd-hda-codec-id:10de0051");
2447 MODULE_ALIAS("snd-hda-codec-id:10de0067");
2448 MODULE_ALIAS("snd-hda-codec-id:10de8001");
2449 MODULE_ALIAS("snd-hda-codec-id:11069f80");
2450 MODULE_ALIAS("snd-hda-codec-id:11069f81");
2451 MODULE_ALIAS("snd-hda-codec-id:11069f84");
2452 MODULE_ALIAS("snd-hda-codec-id:11069f85");
2453 MODULE_ALIAS("snd-hda-codec-id:17e80047");
2454 MODULE_ALIAS("snd-hda-codec-id:80860054");
2455 MODULE_ALIAS("snd-hda-codec-id:80862801");
2456 MODULE_ALIAS("snd-hda-codec-id:80862802");
2457 MODULE_ALIAS("snd-hda-codec-id:80862803");
2458 MODULE_ALIAS("snd-hda-codec-id:80862804");
2459 MODULE_ALIAS("snd-hda-codec-id:80862805");
2460 MODULE_ALIAS("snd-hda-codec-id:80862806");
2461 MODULE_ALIAS("snd-hda-codec-id:80862807");
2462 MODULE_ALIAS("snd-hda-codec-id:80862880");
2463 MODULE_ALIAS("snd-hda-codec-id:808629fb");
2465 MODULE_LICENSE("GPL");
2466 MODULE_DESCRIPTION("HDMI HD-audio codec");
2467 MODULE_ALIAS("snd-hda-codec-intelhdmi");
2468 MODULE_ALIAS("snd-hda-codec-nvhdmi");
2469 MODULE_ALIAS("snd-hda-codec-atihdmi");
2471 static struct hda_codec_preset_list intel_list
= {
2472 .preset
= snd_hda_preset_hdmi
,
2473 .owner
= THIS_MODULE
,
2476 static int __init
patch_hdmi_init(void)
2478 return snd_hda_add_codec_preset(&intel_list
);
2481 static void __exit
patch_hdmi_exit(void)
2483 snd_hda_delete_codec_preset(&intel_list
);
2486 module_init(patch_hdmi_init
)
2487 module_exit(patch_hdmi_exit
)