899c4fbbfd83fe08ca79b50d98829164f397778c
[deliverable/linux.git] / sound / pci / hda / patch_hdmi.c
1 /*
2 *
3 * patch_hdmi.c - routines for HDMI/DisplayPort codecs
4 *
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>
9 *
10 * Authors:
11 * Wu Fengguang <wfg@linux.intel.com>
12 *
13 * Maintained by:
14 * Wu Fengguang <wfg@linux.intel.com>
15 *
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)
19 * any later version.
20 *
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
24 * for more details.
25 *
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.
29 */
30
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"
41 #include "hda_jack.h"
42
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");
46
47 /*
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).
51 *
52 * The HDA correspondence of pipes/ports are converter/pin nodes.
53 */
54 #define MAX_HDMI_CVTS 8
55 #define MAX_HDMI_PINS 8
56
57 struct hdmi_spec_per_cvt {
58 hda_nid_t cvt_nid;
59 int assigned;
60 unsigned int channels_min;
61 unsigned int channels_max;
62 u32 rates;
63 u64 formats;
64 unsigned int maxbps;
65 };
66
67 /* max. connections to a widget */
68 #define HDA_MAX_CONNECTIONS 32
69
70 struct hdmi_spec_per_pin {
71 hda_nid_t pin_nid;
72 int num_mux_nids;
73 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
74
75 struct hda_codec *codec;
76 struct hdmi_eld sink_eld;
77 struct delayed_work work;
78 int repoll_count;
79 bool non_pcm;
80 bool chmap_set; /* channel-map override by ALSA API? */
81 unsigned char chmap[8]; /* ALSA API channel-map */
82 };
83
84 struct hdmi_spec {
85 int num_cvts;
86 struct hdmi_spec_per_cvt cvts[MAX_HDMI_CVTS];
87
88 int num_pins;
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 */
92
93 /*
94 * Non-generic ATI/NVIDIA specific
95 */
96 struct hda_multi_out multiout;
97 struct hda_pcm_stream pcm_playback;
98 };
99
100
101 struct hdmi_audio_infoframe {
102 u8 type; /* 0x84 */
103 u8 ver; /* 0x01 */
104 u8 len; /* 0x0a */
105
106 u8 checksum;
107
108 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
109 u8 SS01_SF24;
110 u8 CXT04;
111 u8 CA;
112 u8 LFEPBL01_LSV36_DM_INH7;
113 };
114
115 struct dp_audio_infoframe {
116 u8 type; /* 0x84 */
117 u8 len; /* 0x1b */
118 u8 ver; /* 0x11 << 2 */
119
120 u8 CC02_CT47; /* match with HDMI infoframe from this on */
121 u8 SS01_SF24;
122 u8 CXT04;
123 u8 CA;
124 u8 LFEPBL01_LSV36_DM_INH7;
125 };
126
127 union audio_infoframe {
128 struct hdmi_audio_infoframe hdmi;
129 struct dp_audio_infoframe dp;
130 u8 bytes[0];
131 };
132
133 /*
134 * CEA speaker placement:
135 *
136 * FLH FCH FRH
137 * FLW FL FLC FC FRC FR FRW
138 *
139 * LFE
140 * TC
141 *
142 * RL RLC RC RRC RR
143 *
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.
146 */
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 */
165 };
166
167 /*
168 * ELD SA bits in the CEA Speaker Allocation data block
169 */
170 static int eld_speaker_allocation_bits[] = {
171 [0] = FL | FR,
172 [1] = LFE,
173 [2] = FC,
174 [3] = RL | RR,
175 [4] = RC,
176 [5] = FLC | FRC,
177 [6] = RLC | RRC,
178 /* the following are not defined in ELD yet */
179 [7] = FLW | FRW,
180 [8] = FLH | FRH,
181 [9] = TC,
182 [10] = FCH,
183 };
184
185 struct cea_channel_speaker_allocation {
186 int ca_index;
187 int speakers[8];
188
189 /* derived values, just for convenience */
190 int channels;
191 int spk_mask;
192 };
193
194 /*
195 * ALSA sequence is:
196 *
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
203 * ch5 LFE LFE
204 * ch6 side left
205 * ch7 side right
206 *
207 * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR}
208 */
209 static int hdmi_channel_mapping[0x32][8] = {
210 /* stereo */
211 [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
212 /* 2.1 */
213 [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
214 /* Dolby Surround */
215 [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 },
216 /* surround40 */
217 [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 },
218 /* 4ch */
219 [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 },
220 /* surround41 */
221 [0x09] = { 0x00, 0x11, 0x24, 0x35, 0x42, 0xf3, 0xf6, 0xf7 },
222 /* surround50 */
223 [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 },
224 /* surround51 */
225 [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 },
226 /* 7.1 */
227 [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 },
228 };
229
230 /*
231 * This is an ordered list!
232 *
233 * The preceding ones have better chances to be selected by
234 * hdmi_channel_allocation().
235 */
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 } },
239 /* 2.1 */
240 { .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
241 /* Dolby Surround */
242 { .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
243 /* surround40 */
244 { .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
245 /* surround41 */
246 { .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
247 /* surround50 */
248 { .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
249 /* surround51 */
250 { .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
251 /* 6.1 */
252 { .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
253 /* surround71 */
254 { .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
255
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 } },
297 };
298
299
300 /*
301 * HDMI routines
302 */
303
304 static int pin_nid_to_pin_index(struct hdmi_spec *spec, hda_nid_t pin_nid)
305 {
306 int pin_idx;
307
308 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
309 if (spec->pins[pin_idx].pin_nid == pin_nid)
310 return pin_idx;
311
312 snd_printk(KERN_WARNING "HDMI: pin nid %d not registered\n", pin_nid);
313 return -EINVAL;
314 }
315
316 static int hinfo_to_pin_index(struct hdmi_spec *spec,
317 struct hda_pcm_stream *hinfo)
318 {
319 int pin_idx;
320
321 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
322 if (&spec->pcm_rec[pin_idx].stream[0] == hinfo)
323 return pin_idx;
324
325 snd_printk(KERN_WARNING "HDMI: hinfo %p not registered\n", hinfo);
326 return -EINVAL;
327 }
328
329 static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid)
330 {
331 int cvt_idx;
332
333 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
334 if (spec->cvts[cvt_idx].cvt_nid == cvt_nid)
335 return cvt_idx;
336
337 snd_printk(KERN_WARNING "HDMI: cvt nid %d not registered\n", cvt_nid);
338 return -EINVAL;
339 }
340
341 static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
342 struct snd_ctl_elem_info *uinfo)
343 {
344 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
345 struct hdmi_spec *spec;
346 int pin_idx;
347
348 spec = codec->spec;
349 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
350
351 pin_idx = kcontrol->private_value;
352 uinfo->count = spec->pins[pin_idx].sink_eld.eld_size;
353
354 return 0;
355 }
356
357 static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
358 struct snd_ctl_elem_value *ucontrol)
359 {
360 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
361 struct hdmi_spec *spec;
362 int pin_idx;
363
364 spec = codec->spec;
365 pin_idx = kcontrol->private_value;
366
367 memcpy(ucontrol->value.bytes.data,
368 spec->pins[pin_idx].sink_eld.eld_buffer, ELD_MAX_SIZE);
369
370 return 0;
371 }
372
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,
376 .name = "ELD",
377 .info = hdmi_eld_ctl_info,
378 .get = hdmi_eld_ctl_get,
379 };
380
381 static int hdmi_create_eld_ctl(struct hda_codec *codec, int pin_idx,
382 int device)
383 {
384 struct snd_kcontrol *kctl;
385 struct hdmi_spec *spec = codec->spec;
386 int err;
387
388 kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
389 if (!kctl)
390 return -ENOMEM;
391 kctl->private_value = pin_idx;
392 kctl->id.device = device;
393
394 err = snd_hda_ctl_add(codec, spec->pins[pin_idx].pin_nid, kctl);
395 if (err < 0)
396 return err;
397
398 return 0;
399 }
400
401 #ifdef BE_PARANOID
402 static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
403 int *packet_index, int *byte_index)
404 {
405 int val;
406
407 val = snd_hda_codec_read(codec, pin_nid, 0,
408 AC_VERB_GET_HDMI_DIP_INDEX, 0);
409
410 *packet_index = val >> 5;
411 *byte_index = val & 0x1f;
412 }
413 #endif
414
415 static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
416 int packet_index, int byte_index)
417 {
418 int val;
419
420 val = (packet_index << 5) | (byte_index & 0x1f);
421
422 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
423 }
424
425 static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
426 unsigned char val)
427 {
428 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
429 }
430
431 static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
432 {
433 /* Unmute */
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
439 */
440 snd_hda_codec_write(codec, pin_nid, 0,
441 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
442 }
443
444 static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid)
445 {
446 return 1 + snd_hda_codec_read(codec, cvt_nid, 0,
447 AC_VERB_GET_CVT_CHAN_COUNT, 0);
448 }
449
450 static void hdmi_set_channel_count(struct hda_codec *codec,
451 hda_nid_t cvt_nid, int chs)
452 {
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);
456 }
457
458
459 /*
460 * Channel mapping routines
461 */
462
463 /*
464 * Compute derived values in channel_allocations[].
465 */
466 static void init_channel_allocations(void)
467 {
468 int i, j;
469 struct cea_channel_speaker_allocation *p;
470
471 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
472 p = channel_allocations + i;
473 p->channels = 0;
474 p->spk_mask = 0;
475 for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
476 if (p->speakers[j]) {
477 p->channels++;
478 p->spk_mask |= p->speakers[j];
479 }
480 }
481 }
482
483 static int get_channel_allocation_order(int ca)
484 {
485 int i;
486
487 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
488 if (channel_allocations[i].ca_index == ca)
489 break;
490 }
491 return i;
492 }
493
494 /*
495 * The transformation takes two steps:
496 *
497 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
498 * spk_mask => (channel_allocations[]) => ai->CA
499 *
500 * TODO: it could select the wrong CA from multiple candidates.
501 */
502 static int hdmi_channel_allocation(struct hdmi_eld *eld, int channels)
503 {
504 int i;
505 int ca = 0;
506 int spk_mask = 0;
507 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
508
509 /*
510 * CA defaults to 0 for basic stereo audio
511 */
512 if (channels <= 2)
513 return 0;
514
515 /*
516 * expand ELD's speaker allocation mask
517 *
518 * ELD tells the speaker mask in a compact(paired) form,
519 * expand ELD's notions to match the ones used by Audio InfoFrame.
520 */
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];
524 }
525
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;
532 break;
533 }
534 }
535
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",
538 ca, channels, buf);
539
540 return ca;
541 }
542
543 static void hdmi_debug_channel_mapping(struct hda_codec *codec,
544 hda_nid_t pin_nid)
545 {
546 #ifdef CONFIG_SND_DEBUG_VERBOSE
547 int i;
548 int slot;
549
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);
555 }
556 #endif
557 }
558
559
560 static void hdmi_std_setup_channel_mapping(struct hda_codec *codec,
561 hda_nid_t pin_nid,
562 bool non_pcm,
563 int ca)
564 {
565 int i;
566 int err;
567 int order;
568 int non_pcm_mapping[8];
569
570 order = get_channel_allocation_order(ca);
571
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);
575 for (; i < 8; i++)
576 hdmi_channel_mapping[ca][i] = 0xf | (i << 4);
577 }
578
579 if (non_pcm) {
580 for (i = 0; i < channel_allocations[order].channels; i++)
581 non_pcm_mapping[i] = i | (i << 4);
582 for (; i < 8; i++)
583 non_pcm_mapping[i] = 0xf | (i << 4);
584 }
585
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]);
590 if (err) {
591 snd_printdd(KERN_NOTICE
592 "HDMI: channel mapping failed\n");
593 break;
594 }
595 }
596
597 hdmi_debug_channel_mapping(codec, pin_nid);
598 }
599
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 */
604 };
605
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 },
615 {} /* terminator */
616 };
617
618 /* from ALSA API channel position to speaker bit mask */
619 static int to_spk_mask(unsigned char c)
620 {
621 struct channel_map_table *t = map_tables;
622 for (; t->map; t++) {
623 if (t->map == c)
624 return t->spk_mask;
625 }
626 return 0;
627 }
628
629 /* from ALSA API channel position to CEA slot */
630 static int to_cea_slot(unsigned char c)
631 {
632 struct channel_map_table *t = map_tables;
633 for (; t->map; t++) {
634 if (t->map == c)
635 return t->cea_slot;
636 }
637 return 0x0f;
638 }
639
640 /* from CEA slot to ALSA API channel position */
641 static int from_cea_slot(unsigned char c)
642 {
643 struct channel_map_table *t = map_tables;
644 for (; t->map; t++) {
645 if (t->cea_slot == c)
646 return t->map;
647 }
648 return 0;
649 }
650
651 /* from speaker bit mask to ALSA API channel position */
652 static int spk_to_chmap(int spk)
653 {
654 struct channel_map_table *t = map_tables;
655 for (; t->map; t++) {
656 if (t->spk_mask == spk)
657 return t->map;
658 }
659 return 0;
660 }
661
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)
664 {
665 int i, spks = 0, spk_mask = 0;
666
667 for (i = 0; i < chs; i++) {
668 int mask = to_spk_mask(map[i]);
669 if (mask) {
670 spk_mask |= mask;
671 spks++;
672 }
673 }
674
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;
681 }
682 return -1;
683 }
684
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,
687 hda_nid_t pin_nid,
688 int chs, unsigned char *map)
689 {
690 int i;
691 for (i = 0; i < 8; i++) {
692 int val, err;
693 if (i < chs)
694 val = to_cea_slot(map[i]);
695 else
696 val = 0xf;
697 val |= (i << 4);
698 err = snd_hda_codec_write(codec, pin_nid, 0,
699 AC_VERB_SET_HDMI_CHAN_SLOT, val);
700 if (err)
701 return -EINVAL;
702 }
703 return 0;
704 }
705
706 /* store ALSA API channel map from the current default map */
707 static void hdmi_setup_fake_chmap(unsigned char *map, int ca)
708 {
709 int i;
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);
713 else
714 map[i] = 0;
715 }
716 }
717
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,
721 bool chmap_set)
722 {
723 if (!non_pcm && chmap_set) {
724 hdmi_manual_setup_channel_mapping(codec, pin_nid,
725 channels, map);
726 } else {
727 hdmi_std_setup_channel_mapping(codec, pin_nid, non_pcm, ca);
728 hdmi_setup_fake_chmap(map, ca);
729 }
730 }
731
732 /*
733 * Audio InfoFrame routines
734 */
735
736 /*
737 * Enable Audio InfoFrame Transmission
738 */
739 static void hdmi_start_infoframe_trans(struct hda_codec *codec,
740 hda_nid_t pin_nid)
741 {
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,
744 AC_DIPXMIT_BEST);
745 }
746
747 /*
748 * Disable Audio InfoFrame Transmission
749 */
750 static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
751 hda_nid_t pin_nid)
752 {
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,
755 AC_DIPXMIT_DISABLE);
756 }
757
758 static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
759 {
760 #ifdef CONFIG_SND_DEBUG_VERBOSE
761 int i;
762 int size;
763
764 size = snd_hdmi_get_eld_size(codec, pin_nid);
765 printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size);
766
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);
771 }
772 #endif
773 }
774
775 static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
776 {
777 #ifdef BE_PARANOID
778 int i, j;
779 int size;
780 int pi, bi;
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);
784 if (size == 0)
785 continue;
786
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);
791 if (pi != i)
792 snd_printd(KERN_INFO "dip index %d: %d != %d\n",
793 bi, pi, i);
794 if (bi == 0) /* byte index wrapped around */
795 break;
796 }
797 snd_printd(KERN_INFO
798 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
799 i, size, j);
800 }
801 #endif
802 }
803
804 static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
805 {
806 u8 *bytes = (u8 *)hdmi_ai;
807 u8 sum = 0;
808 int i;
809
810 hdmi_ai->checksum = 0;
811
812 for (i = 0; i < sizeof(*hdmi_ai); i++)
813 sum += bytes[i];
814
815 hdmi_ai->checksum = -sum;
816 }
817
818 static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
819 hda_nid_t pin_nid,
820 u8 *dip, int size)
821 {
822 int i;
823
824 hdmi_debug_dip_size(codec, pin_nid);
825 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
826
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]);
830 }
831
832 static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
833 u8 *dip, int size)
834 {
835 u8 val;
836 int i;
837
838 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
839 != AC_DIPXMIT_BEST)
840 return false;
841
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);
846 if (val != dip[i])
847 return false;
848 }
849
850 return true;
851 }
852
853 static void hdmi_setup_audio_infoframe(struct hda_codec *codec, int pin_idx,
854 bool non_pcm,
855 struct snd_pcm_substream *substream)
856 {
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;
862 int ca;
863 union audio_infoframe ai;
864
865 eld = &spec->pins[pin_idx].sink_eld;
866 if (!eld->monitor_present)
867 return;
868
869 if (!non_pcm && per_pin->chmap_set)
870 ca = hdmi_manual_channel_allocation(channels, per_pin->chmap);
871 else
872 ca = hdmi_channel_allocation(eld, channels);
873 if (ca < 0)
874 ca = 0;
875
876 memset(&ai, 0, sizeof(ai));
877 if (eld->conn_type == 0) { /* HDMI */
878 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
879
880 hdmi_ai->type = 0x84;
881 hdmi_ai->ver = 0x01;
882 hdmi_ai->len = 0x0a;
883 hdmi_ai->CC02_CT47 = channels - 1;
884 hdmi_ai->CA = ca;
885 hdmi_checksum_audio_infoframe(hdmi_ai);
886 } else if (eld->conn_type == 1) { /* DisplayPort */
887 struct dp_audio_infoframe *dp_ai = &ai.dp;
888
889 dp_ai->type = 0x84;
890 dp_ai->len = 0x1b;
891 dp_ai->ver = 0x11 << 2;
892 dp_ai->CC02_CT47 = channels - 1;
893 dp_ai->CA = ca;
894 } else {
895 snd_printd("HDMI: unknown connection type at pin %d\n",
896 pin_nid);
897 return;
898 }
899
900 /*
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.
904 */
905 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
906 sizeof(ai))) {
907 snd_printdd("hdmi_setup_audio_infoframe: "
908 "pin=%d channels=%d\n",
909 pin_nid,
910 channels);
911 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
912 channels, per_pin->chmap,
913 per_pin->chmap_set);
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);
918 } else {
919 /* For non-pcm audio switch, setup new channel mapping
920 * accordingly */
921 if (per_pin->non_pcm != non_pcm)
922 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
923 channels, per_pin->chmap,
924 per_pin->chmap_set);
925 }
926
927 per_pin->non_pcm = non_pcm;
928 }
929
930
931 /*
932 * Unsolicited events
933 */
934
935 static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
936
937 static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
938 {
939 struct hdmi_spec *spec = codec->spec;
940 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
941 int pin_nid;
942 int pin_idx;
943 struct hda_jack_tbl *jack;
944
945 jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
946 if (!jack)
947 return;
948 pin_nid = jack->nid;
949 jack->jack_dirty = 1;
950
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));
955
956 pin_idx = pin_nid_to_pin_index(spec, pin_nid);
957 if (pin_idx < 0)
958 return;
959
960 hdmi_present_sense(&spec->pins[pin_idx], 1);
961 snd_hda_jack_report_sync(codec);
962 }
963
964 static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
965 {
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);
970
971 printk(KERN_INFO
972 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
973 codec->addr,
974 tag,
975 subtag,
976 cp_state,
977 cp_ready);
978
979 /* TODO */
980 if (cp_state)
981 ;
982 if (cp_ready)
983 ;
984 }
985
986
987 static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
988 {
989 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
990 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
991
992 if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) {
993 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag);
994 return;
995 }
996
997 if (subtag == 0)
998 hdmi_intrinsic_event(codec, res);
999 else
1000 hdmi_non_intrinsic_event(codec, res);
1001 }
1002
1003 /*
1004 * Callbacks
1005 */
1006
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)
1010
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)
1013 {
1014 int pinctl;
1015 int new_pinctl = 0;
1016
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);
1020
1021 new_pinctl = pinctl & ~AC_PINCTL_EPT;
1022 if (is_hbr_format(format))
1023 new_pinctl |= AC_PINCTL_EPT_HBR;
1024 else
1025 new_pinctl |= AC_PINCTL_EPT_NATIVE;
1026
1027 snd_printdd("hdmi_setup_stream: "
1028 "NID=0x%x, %spinctl=0x%x\n",
1029 pin_nid,
1030 pinctl == new_pinctl ? "" : "new-",
1031 new_pinctl);
1032
1033 if (pinctl != new_pinctl)
1034 snd_hda_codec_write(codec, pin_nid, 0,
1035 AC_VERB_SET_PIN_WIDGET_CONTROL,
1036 new_pinctl);
1037
1038 }
1039 if (is_hbr_format(format) && !new_pinctl) {
1040 snd_printdd("hdmi_setup_stream: HBR is not supported\n");
1041 return -EINVAL;
1042 }
1043
1044 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
1045 return 0;
1046 }
1047
1048 /*
1049 * HDA PCM callbacks
1050 */
1051 static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1052 struct hda_codec *codec,
1053 struct snd_pcm_substream *substream)
1054 {
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;
1061
1062 /* Validate hinfo */
1063 pin_idx = hinfo_to_pin_index(spec, hinfo);
1064 if (snd_BUG_ON(pin_idx < 0))
1065 return -EINVAL;
1066 per_pin = &spec->pins[pin_idx];
1067 eld = &per_pin->sink_eld;
1068
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];
1072
1073 /* Must not already be assigned */
1074 if (per_cvt->assigned)
1075 continue;
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)
1079 break;
1080 /* Not in mux list */
1081 if (mux_idx == per_pin->num_mux_nids)
1082 continue;
1083 break;
1084 }
1085 /* No free converters */
1086 if (cvt_idx == spec->num_cvts)
1087 return -ENODEV;
1088
1089 /* Claim converter */
1090 per_cvt->assigned = 1;
1091 hinfo->nid = per_cvt->cvt_nid;
1092
1093 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
1094 AC_VERB_SET_CONNECT_SEL,
1095 mux_idx);
1096 snd_hda_spdif_ctls_assign(codec, pin_idx, per_cvt->cvt_nid);
1097
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;
1104
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;
1111 hinfo->nid = 0;
1112 snd_hda_spdif_ctls_unassign(codec, pin_idx);
1113 return -ENODEV;
1114 }
1115 }
1116
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;
1122
1123 snd_pcm_hw_constraint_step(substream->runtime, 0,
1124 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
1125 return 0;
1126 }
1127
1128 /*
1129 * HDA/HDMI auto parsing
1130 */
1131 static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
1132 {
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;
1136
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));
1142 return -EINVAL;
1143 }
1144
1145 per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,
1146 per_pin->mux_nids,
1147 HDA_MAX_CONNECTIONS);
1148
1149 return 0;
1150 }
1151
1152 static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1153 {
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;
1157 /*
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.
1164 */
1165 int present = snd_hda_pin_sense(codec, pin_nid);
1166 bool eld_valid = false;
1167
1168 memset(eld, 0, offsetof(struct hdmi_eld, eld_buffer));
1169
1170 eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
1171 if (eld->monitor_present)
1172 eld_valid = !!(present & AC_PINSENSE_ELDV);
1173
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);
1177
1178 if (eld_valid) {
1179 if (!snd_hdmi_get_eld(eld, codec, pin_nid))
1180 snd_hdmi_show_eld(eld);
1181 else if (repoll) {
1182 queue_delayed_work(codec->bus->workq,
1183 &per_pin->work,
1184 msecs_to_jiffies(300));
1185 }
1186 }
1187 }
1188
1189 static void hdmi_repoll_eld(struct work_struct *work)
1190 {
1191 struct hdmi_spec_per_pin *per_pin =
1192 container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
1193
1194 if (per_pin->repoll_count++ > 6)
1195 per_pin->repoll_count = 0;
1196
1197 hdmi_present_sense(per_pin, per_pin->repoll_count);
1198 }
1199
1200 static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1201 {
1202 struct hdmi_spec *spec = codec->spec;
1203 unsigned int caps, config;
1204 int pin_idx;
1205 struct hdmi_spec_per_pin *per_pin;
1206 int err;
1207
1208 caps = snd_hda_query_pin_caps(codec, pin_nid);
1209 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
1210 return 0;
1211
1212 config = snd_hda_codec_get_pincfg(codec, pin_nid);
1213 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
1214 return 0;
1215
1216 if (snd_BUG_ON(spec->num_pins >= MAX_HDMI_PINS))
1217 return -E2BIG;
1218
1219 pin_idx = spec->num_pins;
1220 per_pin = &spec->pins[pin_idx];
1221
1222 per_pin->pin_nid = pin_nid;
1223 per_pin->non_pcm = false;
1224
1225 err = hdmi_read_pin_conn(codec, pin_idx);
1226 if (err < 0)
1227 return err;
1228
1229 spec->num_pins++;
1230
1231 return 0;
1232 }
1233
1234 static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1235 {
1236 struct hdmi_spec *spec = codec->spec;
1237 int cvt_idx;
1238 struct hdmi_spec_per_cvt *per_cvt;
1239 unsigned int chans;
1240 int err;
1241
1242 if (snd_BUG_ON(spec->num_cvts >= MAX_HDMI_CVTS))
1243 return -E2BIG;
1244
1245 chans = get_wcaps(codec, cvt_nid);
1246 chans = get_wcaps_channels(chans);
1247
1248 cvt_idx = spec->num_cvts;
1249 per_cvt = &spec->cvts[cvt_idx];
1250
1251 per_cvt->cvt_nid = cvt_nid;
1252 per_cvt->channels_min = 2;
1253 if (chans <= 16) {
1254 per_cvt->channels_max = chans;
1255 if (chans > spec->channels_max)
1256 spec->channels_max = chans;
1257 }
1258
1259 err = snd_hda_query_supported_pcm(codec, cvt_nid,
1260 &per_cvt->rates,
1261 &per_cvt->formats,
1262 &per_cvt->maxbps);
1263 if (err < 0)
1264 return err;
1265
1266 spec->num_cvts++;
1267
1268 return 0;
1269 }
1270
1271 static int hdmi_parse_codec(struct hda_codec *codec)
1272 {
1273 hda_nid_t nid;
1274 int i, nodes;
1275
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");
1279 return -EINVAL;
1280 }
1281
1282 for (i = 0; i < nodes; i++, nid++) {
1283 unsigned int caps;
1284 unsigned int type;
1285
1286 caps = get_wcaps(codec, nid);
1287 type = get_wcaps_type(caps);
1288
1289 if (!(caps & AC_WCAP_DIGITAL))
1290 continue;
1291
1292 switch (type) {
1293 case AC_WID_AUD_OUT:
1294 hdmi_add_cvt(codec, nid);
1295 break;
1296 case AC_WID_PIN:
1297 hdmi_add_pin(codec, nid);
1298 break;
1299 }
1300 }
1301
1302 #ifdef CONFIG_PM
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;
1307 /*
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.
1311 */
1312 else if (!(snd_hda_param_read(codec, codec->afg, AC_PAR_POWER_STATE) &
1313 AC_PWRST_EPSS))
1314 codec->bus->power_keep_link_on = 1;
1315 #endif
1316
1317 return 0;
1318 }
1319
1320 /*
1321 */
1322 static char *get_hdmi_pcm_name(int idx)
1323 {
1324 static char names[MAX_HDMI_PINS][8];
1325 sprintf(&names[idx][0], "HDMI %d", idx);
1326 return &names[idx][0];
1327 }
1328
1329 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1330 {
1331 struct hda_spdif_out *spdif;
1332 bool non_pcm;
1333
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);
1338 return non_pcm;
1339 }
1340
1341
1342 /*
1343 * HDMI callbacks
1344 */
1345
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)
1351 {
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;
1356 bool non_pcm;
1357
1358 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
1359
1360 hdmi_set_channel_count(codec, cvt_nid, substream->runtime->channels);
1361
1362 hdmi_setup_audio_infoframe(codec, pin_idx, non_pcm, substream);
1363
1364 return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
1365 }
1366
1367 static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1368 struct hda_codec *codec,
1369 struct snd_pcm_substream *substream)
1370 {
1371 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
1372 return 0;
1373 }
1374
1375 static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1376 struct hda_codec *codec,
1377 struct snd_pcm_substream *substream)
1378 {
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;
1383
1384 if (hinfo->nid) {
1385 cvt_idx = cvt_nid_to_cvt_index(spec, hinfo->nid);
1386 if (snd_BUG_ON(cvt_idx < 0))
1387 return -EINVAL;
1388 per_cvt = &spec->cvts[cvt_idx];
1389
1390 snd_BUG_ON(!per_cvt->assigned);
1391 per_cvt->assigned = 0;
1392 hinfo->nid = 0;
1393
1394 pin_idx = hinfo_to_pin_index(spec, hinfo);
1395 if (snd_BUG_ON(pin_idx < 0))
1396 return -EINVAL;
1397 per_pin = &spec->pins[pin_idx];
1398
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));
1402 }
1403
1404 return 0;
1405 }
1406
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,
1412 };
1413
1414 /*
1415 * ALSA API channel-map control callbacks
1416 */
1417 static int hdmi_chmap_ctl_info(struct snd_kcontrol *kcontrol,
1418 struct snd_ctl_elem_info *uinfo)
1419 {
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;
1427 return 0;
1428 }
1429
1430 static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1431 unsigned int size, unsigned int __user *tlv)
1432 {
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;
1439 int chs, count = 0;
1440
1441 if (size < 8)
1442 return -ENOMEM;
1443 if (put_user(SNDRV_CTL_TLVT_CONTAINER, tlv))
1444 return -EFAULT;
1445 size -= 8;
1446 dst = tlv + 2;
1447 for (chs = 2; chs <= spec->channels_max; chs++) {
1448 int i, c;
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)
1454 continue;
1455 if (cap->spk_mask & ~valid_mask)
1456 continue;
1457 if (size < 8)
1458 return -ENOMEM;
1459 if (put_user(SNDRV_CTL_TLVT_CHMAP_VAR, dst) ||
1460 put_user(chs_bytes, dst + 1))
1461 return -EFAULT;
1462 dst += 2;
1463 size -= 8;
1464 count += 8;
1465 if (size < chs_bytes)
1466 return -ENOMEM;
1467 size -= chs_bytes;
1468 count += chs_bytes;
1469 for (c = 7; c >= 0; c--) {
1470 int spk = cap->speakers[c];
1471 if (!spk)
1472 continue;
1473 if (put_user(spk_to_chmap(spk), dst))
1474 return -EFAULT;
1475 dst++;
1476 }
1477 }
1478 }
1479 if (put_user(count, tlv + 1))
1480 return -EFAULT;
1481 return 0;
1482 }
1483
1484 static int hdmi_chmap_ctl_get(struct snd_kcontrol *kcontrol,
1485 struct snd_ctl_elem_value *ucontrol)
1486 {
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];
1492 int i;
1493
1494 for (i = 0; i < ARRAY_SIZE(per_pin->chmap); i++)
1495 ucontrol->value.integer.value[i] = per_pin->chmap[i];
1496 return 0;
1497 }
1498
1499 static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
1500 struct snd_ctl_elem_value *ucontrol)
1501 {
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;
1511
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:
1519 break;
1520 case SNDRV_PCM_STATE_PREPARED:
1521 prepared = 1;
1522 break;
1523 default:
1524 return -EBUSY;
1525 }
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)))
1530 return 0;
1531 ca = hdmi_manual_channel_allocation(ARRAY_SIZE(chmap), chmap);
1532 if (ca < 0)
1533 return -EINVAL;
1534 per_pin->chmap_set = true;
1535 memcpy(per_pin->chmap, chmap, sizeof(chmap));
1536 if (prepared)
1537 hdmi_setup_audio_infoframe(codec, pin_idx, per_pin->non_pcm,
1538 substream);
1539
1540 return 0;
1541 }
1542
1543 static int generic_hdmi_build_pcms(struct hda_codec *codec)
1544 {
1545 struct hdmi_spec *spec = codec->spec;
1546 int pin_idx;
1547
1548 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1549 struct hda_pcm *info;
1550 struct hda_pcm_stream *pstr;
1551
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;
1556
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 */
1561 }
1562
1563 codec->num_pcms = spec->num_pins;
1564 codec->pcm_info = spec->pcm_rec;
1565
1566 return 0;
1567 }
1568
1569 static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx)
1570 {
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;
1575
1576 if (pcmdev > 0)
1577 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
1578
1579 return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str, 0);
1580 }
1581
1582 static int generic_hdmi_build_controls(struct hda_codec *codec)
1583 {
1584 struct hdmi_spec *spec = codec->spec;
1585 int err;
1586 int pin_idx;
1587
1588 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1589 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
1590
1591 err = generic_hdmi_build_jack(codec, pin_idx);
1592 if (err < 0)
1593 return err;
1594
1595 err = snd_hda_create_dig_out_ctls(codec,
1596 per_pin->pin_nid,
1597 per_pin->mux_nids[0],
1598 HDA_PCM_TYPE_HDMI);
1599 if (err < 0)
1600 return err;
1601 snd_hda_spdif_ctls_unassign(codec, pin_idx);
1602
1603 /* add control for ELD Bytes */
1604 err = hdmi_create_eld_ctl(codec,
1605 pin_idx,
1606 spec->pcm_rec[pin_idx].device);
1607
1608 if (err < 0)
1609 return err;
1610
1611 hdmi_present_sense(per_pin, 0);
1612 }
1613
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;
1618 int i;
1619 err = snd_pcm_add_chmap_ctls(codec->pcm_info[pin_idx].pcm,
1620 SNDRV_PCM_STREAM_PLAYBACK,
1621 NULL, 0, pin_idx, &chmap);
1622 if (err < 0)
1623 return err;
1624 /* override handlers */
1625 chmap->private_data = codec;
1626 kctl = chmap->kctl;
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;
1633 }
1634
1635 return 0;
1636 }
1637
1638 static int generic_hdmi_init_per_pins(struct hda_codec *codec)
1639 {
1640 struct hdmi_spec *spec = codec->spec;
1641 int pin_idx;
1642
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;
1646
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);
1650 }
1651 return 0;
1652 }
1653
1654 static int generic_hdmi_init(struct hda_codec *codec)
1655 {
1656 struct hdmi_spec *spec = codec->spec;
1657 int pin_idx;
1658
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;
1662
1663 hdmi_init_pin(codec, pin_nid);
1664 snd_hda_jack_detect_enable(codec, pin_nid, pin_nid);
1665 }
1666 return 0;
1667 }
1668
1669 static void generic_hdmi_free(struct hda_codec *codec)
1670 {
1671 struct hdmi_spec *spec = codec->spec;
1672 int pin_idx;
1673
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;
1677
1678 cancel_delayed_work(&per_pin->work);
1679 snd_hda_eld_proc_free(codec, eld);
1680 }
1681
1682 flush_workqueue(codec->bus->workq);
1683 kfree(spec);
1684 }
1685
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,
1692 };
1693
1694 static void intel_haswell_fixup_connect_list(struct hda_codec *codec)
1695 {
1696 unsigned int vendor_param;
1697 hda_nid_t list[3] = {0x2, 0x3, 0x4};
1698
1699 vendor_param = snd_hda_codec_read(codec, 0x08, 0, 0xf81, 0);
1700 if (vendor_param == -1 || vendor_param & 0x02)
1701 return;
1702
1703 /* enable DP1.2 mode */
1704 vendor_param |= 0x02;
1705 snd_hda_codec_read(codec, 0x08, 0, 0x781, vendor_param);
1706
1707 vendor_param = snd_hda_codec_read(codec, 0x08, 0, 0xf81, 0);
1708 if (vendor_param == -1 || !(vendor_param & 0x02))
1709 return;
1710
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);
1715 }
1716
1717
1718 static int patch_generic_hdmi(struct hda_codec *codec)
1719 {
1720 struct hdmi_spec *spec;
1721
1722 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1723 if (spec == NULL)
1724 return -ENOMEM;
1725
1726 codec->spec = spec;
1727
1728 if (codec->vendor_id == 0x80862807)
1729 intel_haswell_fixup_connect_list(codec);
1730
1731 if (hdmi_parse_codec(codec) < 0) {
1732 codec->spec = NULL;
1733 kfree(spec);
1734 return -EINVAL;
1735 }
1736 codec->patch_ops = generic_hdmi_patch_ops;
1737 generic_hdmi_init_per_pins(codec);
1738
1739 init_channel_allocations();
1740
1741 return 0;
1742 }
1743
1744 /*
1745 * Shared non-generic implementations
1746 */
1747
1748 static int simple_playback_build_pcms(struct hda_codec *codec)
1749 {
1750 struct hdmi_spec *spec = codec->spec;
1751 struct hda_pcm *info = spec->pcm_rec;
1752 unsigned int chans;
1753 struct hda_pcm_stream *pstr;
1754
1755 codec->num_pcms = 1;
1756 codec->pcm_info = info;
1757
1758 chans = get_wcaps(codec, spec->cvts[0].cvt_nid);
1759 chans = get_wcaps_channels(chans);
1760
1761 info->name = get_hdmi_pcm_name(0);
1762 info->pcm_type = HDA_PCM_TYPE_HDMI;
1763 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
1764 *pstr = spec->pcm_playback;
1765 pstr->nid = spec->cvts[0].cvt_nid;
1766 if (pstr->channels_max <= 2 && chans && chans <= 16)
1767 pstr->channels_max = chans;
1768
1769 return 0;
1770 }
1771
1772 /* unsolicited event for jack sensing */
1773 static void simple_hdmi_unsol_event(struct hda_codec *codec,
1774 unsigned int res)
1775 {
1776 snd_hda_jack_set_dirty_all(codec);
1777 snd_hda_jack_report_sync(codec);
1778 }
1779
1780 /* generic_hdmi_build_jack can be used for simple_hdmi, too,
1781 * as long as spec->pins[] is set correctly
1782 */
1783 #define simple_hdmi_build_jack generic_hdmi_build_jack
1784
1785 static int simple_playback_build_controls(struct hda_codec *codec)
1786 {
1787 struct hdmi_spec *spec = codec->spec;
1788 int err;
1789
1790 err = snd_hda_create_spdif_out_ctls(codec,
1791 spec->cvts[0].cvt_nid,
1792 spec->cvts[0].cvt_nid);
1793 if (err < 0)
1794 return err;
1795 return simple_hdmi_build_jack(codec, 0);
1796 }
1797
1798 static int simple_playback_init(struct hda_codec *codec)
1799 {
1800 struct hdmi_spec *spec = codec->spec;
1801 hda_nid_t pin = spec->pins[0].pin_nid;
1802
1803 snd_hda_codec_write(codec, pin, 0,
1804 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1805 /* some codecs require to unmute the pin */
1806 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
1807 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1808 AMP_OUT_UNMUTE);
1809 snd_hda_jack_detect_enable(codec, pin, pin);
1810 return 0;
1811 }
1812
1813 static void simple_playback_free(struct hda_codec *codec)
1814 {
1815 struct hdmi_spec *spec = codec->spec;
1816
1817 kfree(spec);
1818 }
1819
1820 /*
1821 * Nvidia specific implementations
1822 */
1823
1824 #define Nv_VERB_SET_Channel_Allocation 0xF79
1825 #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
1826 #define Nv_VERB_SET_Audio_Protection_On 0xF98
1827 #define Nv_VERB_SET_Audio_Protection_Off 0xF99
1828
1829 #define nvhdmi_master_con_nid_7x 0x04
1830 #define nvhdmi_master_pin_nid_7x 0x05
1831
1832 static const hda_nid_t nvhdmi_con_nids_7x[4] = {
1833 /*front, rear, clfe, rear_surr */
1834 0x6, 0x8, 0xa, 0xc,
1835 };
1836
1837 static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = {
1838 /* set audio protect on */
1839 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
1840 /* enable digital output on pin widget */
1841 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1842 {} /* terminator */
1843 };
1844
1845 static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = {
1846 /* set audio protect on */
1847 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
1848 /* enable digital output on pin widget */
1849 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1850 { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1851 { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1852 { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1853 { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1854 {} /* terminator */
1855 };
1856
1857 #ifdef LIMITED_RATE_FMT_SUPPORT
1858 /* support only the safe format and rate */
1859 #define SUPPORTED_RATES SNDRV_PCM_RATE_48000
1860 #define SUPPORTED_MAXBPS 16
1861 #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
1862 #else
1863 /* support all rates and formats */
1864 #define SUPPORTED_RATES \
1865 (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
1866 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
1867 SNDRV_PCM_RATE_192000)
1868 #define SUPPORTED_MAXBPS 24
1869 #define SUPPORTED_FORMATS \
1870 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
1871 #endif
1872
1873 static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
1874 {
1875 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
1876 return 0;
1877 }
1878
1879 static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
1880 {
1881 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
1882 return 0;
1883 }
1884
1885 static unsigned int channels_2_6_8[] = {
1886 2, 6, 8
1887 };
1888
1889 static unsigned int channels_2_8[] = {
1890 2, 8
1891 };
1892
1893 static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
1894 .count = ARRAY_SIZE(channels_2_6_8),
1895 .list = channels_2_6_8,
1896 .mask = 0,
1897 };
1898
1899 static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
1900 .count = ARRAY_SIZE(channels_2_8),
1901 .list = channels_2_8,
1902 .mask = 0,
1903 };
1904
1905 static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
1906 struct hda_codec *codec,
1907 struct snd_pcm_substream *substream)
1908 {
1909 struct hdmi_spec *spec = codec->spec;
1910 struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
1911
1912 switch (codec->preset->id) {
1913 case 0x10de0002:
1914 case 0x10de0003:
1915 case 0x10de0005:
1916 case 0x10de0006:
1917 hw_constraints_channels = &hw_constraints_2_8_channels;
1918 break;
1919 case 0x10de0007:
1920 hw_constraints_channels = &hw_constraints_2_6_8_channels;
1921 break;
1922 default:
1923 break;
1924 }
1925
1926 if (hw_constraints_channels != NULL) {
1927 snd_pcm_hw_constraint_list(substream->runtime, 0,
1928 SNDRV_PCM_HW_PARAM_CHANNELS,
1929 hw_constraints_channels);
1930 } else {
1931 snd_pcm_hw_constraint_step(substream->runtime, 0,
1932 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
1933 }
1934
1935 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1936 }
1937
1938 static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
1939 struct hda_codec *codec,
1940 struct snd_pcm_substream *substream)
1941 {
1942 struct hdmi_spec *spec = codec->spec;
1943 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1944 }
1945
1946 static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1947 struct hda_codec *codec,
1948 unsigned int stream_tag,
1949 unsigned int format,
1950 struct snd_pcm_substream *substream)
1951 {
1952 struct hdmi_spec *spec = codec->spec;
1953 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1954 stream_tag, format, substream);
1955 }
1956
1957 static const struct hda_pcm_stream simple_pcm_playback = {
1958 .substreams = 1,
1959 .channels_min = 2,
1960 .channels_max = 2,
1961 .ops = {
1962 .open = simple_playback_pcm_open,
1963 .close = simple_playback_pcm_close,
1964 .prepare = simple_playback_pcm_prepare
1965 },
1966 };
1967
1968 static const struct hda_codec_ops simple_hdmi_patch_ops = {
1969 .build_controls = simple_playback_build_controls,
1970 .build_pcms = simple_playback_build_pcms,
1971 .init = simple_playback_init,
1972 .free = simple_playback_free,
1973 .unsol_event = simple_hdmi_unsol_event,
1974 };
1975
1976 static int patch_simple_hdmi(struct hda_codec *codec,
1977 hda_nid_t cvt_nid, hda_nid_t pin_nid)
1978 {
1979 struct hdmi_spec *spec;
1980
1981 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1982 if (!spec)
1983 return -ENOMEM;
1984
1985 codec->spec = spec;
1986
1987 spec->multiout.num_dacs = 0; /* no analog */
1988 spec->multiout.max_channels = 2;
1989 spec->multiout.dig_out_nid = cvt_nid;
1990 spec->num_cvts = 1;
1991 spec->num_pins = 1;
1992 spec->cvts[0].cvt_nid = cvt_nid;
1993 spec->pins[0].pin_nid = pin_nid;
1994 spec->pcm_playback = simple_pcm_playback;
1995
1996 codec->patch_ops = simple_hdmi_patch_ops;
1997
1998 return 0;
1999 }
2000
2001 static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
2002 int channels)
2003 {
2004 unsigned int chanmask;
2005 int chan = channels ? (channels - 1) : 1;
2006
2007 switch (channels) {
2008 default:
2009 case 0:
2010 case 2:
2011 chanmask = 0x00;
2012 break;
2013 case 4:
2014 chanmask = 0x08;
2015 break;
2016 case 6:
2017 chanmask = 0x0b;
2018 break;
2019 case 8:
2020 chanmask = 0x13;
2021 break;
2022 }
2023
2024 /* Set the audio infoframe channel allocation and checksum fields. The
2025 * channel count is computed implicitly by the hardware. */
2026 snd_hda_codec_write(codec, 0x1, 0,
2027 Nv_VERB_SET_Channel_Allocation, chanmask);
2028
2029 snd_hda_codec_write(codec, 0x1, 0,
2030 Nv_VERB_SET_Info_Frame_Checksum,
2031 (0x71 - chan - chanmask));
2032 }
2033
2034 static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
2035 struct hda_codec *codec,
2036 struct snd_pcm_substream *substream)
2037 {
2038 struct hdmi_spec *spec = codec->spec;
2039 int i;
2040
2041 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
2042 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
2043 for (i = 0; i < 4; i++) {
2044 /* set the stream id */
2045 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
2046 AC_VERB_SET_CHANNEL_STREAMID, 0);
2047 /* set the stream format */
2048 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
2049 AC_VERB_SET_STREAM_FORMAT, 0);
2050 }
2051
2052 /* The audio hardware sends a channel count of 0x7 (8ch) when all the
2053 * streams are disabled. */
2054 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
2055
2056 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2057 }
2058
2059 static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
2060 struct hda_codec *codec,
2061 unsigned int stream_tag,
2062 unsigned int format,
2063 struct snd_pcm_substream *substream)
2064 {
2065 int chs;
2066 unsigned int dataDCC2, channel_id;
2067 int i;
2068 struct hdmi_spec *spec = codec->spec;
2069 struct hda_spdif_out *spdif;
2070
2071 mutex_lock(&codec->spdif_mutex);
2072 spdif = snd_hda_spdif_out_of_nid(codec, spec->cvts[0].cvt_nid);
2073
2074 chs = substream->runtime->channels;
2075
2076 dataDCC2 = 0x2;
2077
2078 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
2079 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
2080 snd_hda_codec_write(codec,
2081 nvhdmi_master_con_nid_7x,
2082 0,
2083 AC_VERB_SET_DIGI_CONVERT_1,
2084 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
2085
2086 /* set the stream id */
2087 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
2088 AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
2089
2090 /* set the stream format */
2091 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
2092 AC_VERB_SET_STREAM_FORMAT, format);
2093
2094 /* turn on again (if needed) */
2095 /* enable and set the channel status audio/data flag */
2096 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
2097 snd_hda_codec_write(codec,
2098 nvhdmi_master_con_nid_7x,
2099 0,
2100 AC_VERB_SET_DIGI_CONVERT_1,
2101 spdif->ctls & 0xff);
2102 snd_hda_codec_write(codec,
2103 nvhdmi_master_con_nid_7x,
2104 0,
2105 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
2106 }
2107
2108 for (i = 0; i < 4; i++) {
2109 if (chs == 2)
2110 channel_id = 0;
2111 else
2112 channel_id = i * 2;
2113
2114 /* turn off SPDIF once;
2115 *otherwise the IEC958 bits won't be updated
2116 */
2117 if (codec->spdif_status_reset &&
2118 (spdif->ctls & AC_DIG1_ENABLE))
2119 snd_hda_codec_write(codec,
2120 nvhdmi_con_nids_7x[i],
2121 0,
2122 AC_VERB_SET_DIGI_CONVERT_1,
2123 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
2124 /* set the stream id */
2125 snd_hda_codec_write(codec,
2126 nvhdmi_con_nids_7x[i],
2127 0,
2128 AC_VERB_SET_CHANNEL_STREAMID,
2129 (stream_tag << 4) | channel_id);
2130 /* set the stream format */
2131 snd_hda_codec_write(codec,
2132 nvhdmi_con_nids_7x[i],
2133 0,
2134 AC_VERB_SET_STREAM_FORMAT,
2135 format);
2136 /* turn on again (if needed) */
2137 /* enable and set the channel status audio/data flag */
2138 if (codec->spdif_status_reset &&
2139 (spdif->ctls & AC_DIG1_ENABLE)) {
2140 snd_hda_codec_write(codec,
2141 nvhdmi_con_nids_7x[i],
2142 0,
2143 AC_VERB_SET_DIGI_CONVERT_1,
2144 spdif->ctls & 0xff);
2145 snd_hda_codec_write(codec,
2146 nvhdmi_con_nids_7x[i],
2147 0,
2148 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
2149 }
2150 }
2151
2152 nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
2153
2154 mutex_unlock(&codec->spdif_mutex);
2155 return 0;
2156 }
2157
2158 static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
2159 .substreams = 1,
2160 .channels_min = 2,
2161 .channels_max = 8,
2162 .nid = nvhdmi_master_con_nid_7x,
2163 .rates = SUPPORTED_RATES,
2164 .maxbps = SUPPORTED_MAXBPS,
2165 .formats = SUPPORTED_FORMATS,
2166 .ops = {
2167 .open = simple_playback_pcm_open,
2168 .close = nvhdmi_8ch_7x_pcm_close,
2169 .prepare = nvhdmi_8ch_7x_pcm_prepare
2170 },
2171 };
2172
2173 static int patch_nvhdmi_2ch(struct hda_codec *codec)
2174 {
2175 struct hdmi_spec *spec;
2176 int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
2177 nvhdmi_master_pin_nid_7x);
2178 if (err < 0)
2179 return err;
2180
2181 codec->patch_ops.init = nvhdmi_7x_init_2ch;
2182 /* override the PCM rates, etc, as the codec doesn't give full list */
2183 spec = codec->spec;
2184 spec->pcm_playback.rates = SUPPORTED_RATES;
2185 spec->pcm_playback.maxbps = SUPPORTED_MAXBPS;
2186 spec->pcm_playback.formats = SUPPORTED_FORMATS;
2187 return 0;
2188 }
2189
2190 static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
2191 {
2192 struct hdmi_spec *spec = codec->spec;
2193 int err = simple_playback_build_pcms(codec);
2194 spec->pcm_rec[0].own_chmap = true;
2195 return err;
2196 }
2197
2198 static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
2199 {
2200 struct hdmi_spec *spec = codec->spec;
2201 struct snd_pcm_chmap *chmap;
2202 int err;
2203
2204 err = simple_playback_build_controls(codec);
2205 if (err < 0)
2206 return err;
2207
2208 /* add channel maps */
2209 err = snd_pcm_add_chmap_ctls(spec->pcm_rec[0].pcm,
2210 SNDRV_PCM_STREAM_PLAYBACK,
2211 snd_pcm_alt_chmaps, 8, 0, &chmap);
2212 if (err < 0)
2213 return err;
2214 switch (codec->preset->id) {
2215 case 0x10de0002:
2216 case 0x10de0003:
2217 case 0x10de0005:
2218 case 0x10de0006:
2219 chmap->channel_mask = (1U << 2) | (1U << 8);
2220 break;
2221 case 0x10de0007:
2222 chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8);
2223 }
2224 return 0;
2225 }
2226
2227 static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
2228 {
2229 struct hdmi_spec *spec;
2230 int err = patch_nvhdmi_2ch(codec);
2231 if (err < 0)
2232 return err;
2233 spec = codec->spec;
2234 spec->multiout.max_channels = 8;
2235 spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x;
2236 codec->patch_ops.init = nvhdmi_7x_init_8ch;
2237 codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
2238 codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
2239
2240 /* Initialize the audio infoframe channel mask and checksum to something
2241 * valid */
2242 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
2243
2244 return 0;
2245 }
2246
2247 /*
2248 * ATI-specific implementations
2249 *
2250 * FIXME: we may omit the whole this and use the generic code once after
2251 * it's confirmed to work.
2252 */
2253
2254 #define ATIHDMI_CVT_NID 0x02 /* audio converter */
2255 #define ATIHDMI_PIN_NID 0x03 /* HDMI output pin */
2256
2257 static int atihdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2258 struct hda_codec *codec,
2259 unsigned int stream_tag,
2260 unsigned int format,
2261 struct snd_pcm_substream *substream)
2262 {
2263 struct hdmi_spec *spec = codec->spec;
2264 int chans = substream->runtime->channels;
2265 int i, err;
2266
2267 err = simple_playback_pcm_prepare(hinfo, codec, stream_tag, format,
2268 substream);
2269 if (err < 0)
2270 return err;
2271 snd_hda_codec_write(codec, spec->cvts[0].cvt_nid, 0,
2272 AC_VERB_SET_CVT_CHAN_COUNT, chans - 1);
2273 /* FIXME: XXX */
2274 for (i = 0; i < chans; i++) {
2275 snd_hda_codec_write(codec, spec->cvts[0].cvt_nid, 0,
2276 AC_VERB_SET_HDMI_CHAN_SLOT,
2277 (i << 4) | i);
2278 }
2279 return 0;
2280 }
2281
2282 static int patch_atihdmi(struct hda_codec *codec)
2283 {
2284 struct hdmi_spec *spec;
2285 int err = patch_simple_hdmi(codec, ATIHDMI_CVT_NID, ATIHDMI_PIN_NID);
2286 if (err < 0)
2287 return err;
2288 spec = codec->spec;
2289 spec->pcm_playback.ops.prepare = atihdmi_playback_pcm_prepare;
2290 return 0;
2291 }
2292
2293 /* VIA HDMI Implementation */
2294 #define VIAHDMI_CVT_NID 0x02 /* audio converter1 */
2295 #define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */
2296
2297 static int patch_via_hdmi(struct hda_codec *codec)
2298 {
2299 return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
2300 }
2301
2302 /*
2303 * patch entries
2304 */
2305 static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
2306 { .id = 0x1002793c, .name = "RS600 HDMI", .patch = patch_atihdmi },
2307 { .id = 0x10027919, .name = "RS600 HDMI", .patch = patch_atihdmi },
2308 { .id = 0x1002791a, .name = "RS690/780 HDMI", .patch = patch_atihdmi },
2309 { .id = 0x1002aa01, .name = "R6xx HDMI", .patch = patch_generic_hdmi },
2310 { .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_generic_hdmi },
2311 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_generic_hdmi },
2312 { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_generic_hdmi },
2313 { .id = 0x10de0002, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2314 { .id = 0x10de0003, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2315 { .id = 0x10de0005, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2316 { .id = 0x10de0006, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2317 { .id = 0x10de0007, .name = "MCP79/7A HDMI", .patch = patch_nvhdmi_8ch_7x },
2318 { .id = 0x10de000a, .name = "GPU 0a HDMI/DP", .patch = patch_generic_hdmi },
2319 { .id = 0x10de000b, .name = "GPU 0b HDMI/DP", .patch = patch_generic_hdmi },
2320 { .id = 0x10de000c, .name = "MCP89 HDMI", .patch = patch_generic_hdmi },
2321 { .id = 0x10de000d, .name = "GPU 0d HDMI/DP", .patch = patch_generic_hdmi },
2322 { .id = 0x10de0010, .name = "GPU 10 HDMI/DP", .patch = patch_generic_hdmi },
2323 { .id = 0x10de0011, .name = "GPU 11 HDMI/DP", .patch = patch_generic_hdmi },
2324 { .id = 0x10de0012, .name = "GPU 12 HDMI/DP", .patch = patch_generic_hdmi },
2325 { .id = 0x10de0013, .name = "GPU 13 HDMI/DP", .patch = patch_generic_hdmi },
2326 { .id = 0x10de0014, .name = "GPU 14 HDMI/DP", .patch = patch_generic_hdmi },
2327 { .id = 0x10de0015, .name = "GPU 15 HDMI/DP", .patch = patch_generic_hdmi },
2328 { .id = 0x10de0016, .name = "GPU 16 HDMI/DP", .patch = patch_generic_hdmi },
2329 /* 17 is known to be absent */
2330 { .id = 0x10de0018, .name = "GPU 18 HDMI/DP", .patch = patch_generic_hdmi },
2331 { .id = 0x10de0019, .name = "GPU 19 HDMI/DP", .patch = patch_generic_hdmi },
2332 { .id = 0x10de001a, .name = "GPU 1a HDMI/DP", .patch = patch_generic_hdmi },
2333 { .id = 0x10de001b, .name = "GPU 1b HDMI/DP", .patch = patch_generic_hdmi },
2334 { .id = 0x10de001c, .name = "GPU 1c HDMI/DP", .patch = patch_generic_hdmi },
2335 { .id = 0x10de0040, .name = "GPU 40 HDMI/DP", .patch = patch_generic_hdmi },
2336 { .id = 0x10de0041, .name = "GPU 41 HDMI/DP", .patch = patch_generic_hdmi },
2337 { .id = 0x10de0042, .name = "GPU 42 HDMI/DP", .patch = patch_generic_hdmi },
2338 { .id = 0x10de0043, .name = "GPU 43 HDMI/DP", .patch = patch_generic_hdmi },
2339 { .id = 0x10de0044, .name = "GPU 44 HDMI/DP", .patch = patch_generic_hdmi },
2340 { .id = 0x10de0051, .name = "GPU 51 HDMI/DP", .patch = patch_generic_hdmi },
2341 { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch },
2342 { .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch },
2343 { .id = 0x11069f80, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi },
2344 { .id = 0x11069f81, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi },
2345 { .id = 0x11069f84, .name = "VX11 HDMI/DP", .patch = patch_generic_hdmi },
2346 { .id = 0x11069f85, .name = "VX11 HDMI/DP", .patch = patch_generic_hdmi },
2347 { .id = 0x80860054, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi },
2348 { .id = 0x80862801, .name = "Bearlake HDMI", .patch = patch_generic_hdmi },
2349 { .id = 0x80862802, .name = "Cantiga HDMI", .patch = patch_generic_hdmi },
2350 { .id = 0x80862803, .name = "Eaglelake HDMI", .patch = patch_generic_hdmi },
2351 { .id = 0x80862804, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi },
2352 { .id = 0x80862805, .name = "CougarPoint HDMI", .patch = patch_generic_hdmi },
2353 { .id = 0x80862806, .name = "PantherPoint HDMI", .patch = patch_generic_hdmi },
2354 { .id = 0x80862807, .name = "Haswell HDMI", .patch = patch_generic_hdmi },
2355 { .id = 0x80862880, .name = "CedarTrail HDMI", .patch = patch_generic_hdmi },
2356 { .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi },
2357 {} /* terminator */
2358 };
2359
2360 MODULE_ALIAS("snd-hda-codec-id:1002793c");
2361 MODULE_ALIAS("snd-hda-codec-id:10027919");
2362 MODULE_ALIAS("snd-hda-codec-id:1002791a");
2363 MODULE_ALIAS("snd-hda-codec-id:1002aa01");
2364 MODULE_ALIAS("snd-hda-codec-id:10951390");
2365 MODULE_ALIAS("snd-hda-codec-id:10951392");
2366 MODULE_ALIAS("snd-hda-codec-id:10de0002");
2367 MODULE_ALIAS("snd-hda-codec-id:10de0003");
2368 MODULE_ALIAS("snd-hda-codec-id:10de0005");
2369 MODULE_ALIAS("snd-hda-codec-id:10de0006");
2370 MODULE_ALIAS("snd-hda-codec-id:10de0007");
2371 MODULE_ALIAS("snd-hda-codec-id:10de000a");
2372 MODULE_ALIAS("snd-hda-codec-id:10de000b");
2373 MODULE_ALIAS("snd-hda-codec-id:10de000c");
2374 MODULE_ALIAS("snd-hda-codec-id:10de000d");
2375 MODULE_ALIAS("snd-hda-codec-id:10de0010");
2376 MODULE_ALIAS("snd-hda-codec-id:10de0011");
2377 MODULE_ALIAS("snd-hda-codec-id:10de0012");
2378 MODULE_ALIAS("snd-hda-codec-id:10de0013");
2379 MODULE_ALIAS("snd-hda-codec-id:10de0014");
2380 MODULE_ALIAS("snd-hda-codec-id:10de0015");
2381 MODULE_ALIAS("snd-hda-codec-id:10de0016");
2382 MODULE_ALIAS("snd-hda-codec-id:10de0018");
2383 MODULE_ALIAS("snd-hda-codec-id:10de0019");
2384 MODULE_ALIAS("snd-hda-codec-id:10de001a");
2385 MODULE_ALIAS("snd-hda-codec-id:10de001b");
2386 MODULE_ALIAS("snd-hda-codec-id:10de001c");
2387 MODULE_ALIAS("snd-hda-codec-id:10de0040");
2388 MODULE_ALIAS("snd-hda-codec-id:10de0041");
2389 MODULE_ALIAS("snd-hda-codec-id:10de0042");
2390 MODULE_ALIAS("snd-hda-codec-id:10de0043");
2391 MODULE_ALIAS("snd-hda-codec-id:10de0044");
2392 MODULE_ALIAS("snd-hda-codec-id:10de0051");
2393 MODULE_ALIAS("snd-hda-codec-id:10de0067");
2394 MODULE_ALIAS("snd-hda-codec-id:10de8001");
2395 MODULE_ALIAS("snd-hda-codec-id:11069f80");
2396 MODULE_ALIAS("snd-hda-codec-id:11069f81");
2397 MODULE_ALIAS("snd-hda-codec-id:11069f84");
2398 MODULE_ALIAS("snd-hda-codec-id:11069f85");
2399 MODULE_ALIAS("snd-hda-codec-id:17e80047");
2400 MODULE_ALIAS("snd-hda-codec-id:80860054");
2401 MODULE_ALIAS("snd-hda-codec-id:80862801");
2402 MODULE_ALIAS("snd-hda-codec-id:80862802");
2403 MODULE_ALIAS("snd-hda-codec-id:80862803");
2404 MODULE_ALIAS("snd-hda-codec-id:80862804");
2405 MODULE_ALIAS("snd-hda-codec-id:80862805");
2406 MODULE_ALIAS("snd-hda-codec-id:80862806");
2407 MODULE_ALIAS("snd-hda-codec-id:80862807");
2408 MODULE_ALIAS("snd-hda-codec-id:80862880");
2409 MODULE_ALIAS("snd-hda-codec-id:808629fb");
2410
2411 MODULE_LICENSE("GPL");
2412 MODULE_DESCRIPTION("HDMI HD-audio codec");
2413 MODULE_ALIAS("snd-hda-codec-intelhdmi");
2414 MODULE_ALIAS("snd-hda-codec-nvhdmi");
2415 MODULE_ALIAS("snd-hda-codec-atihdmi");
2416
2417 static struct hda_codec_preset_list intel_list = {
2418 .preset = snd_hda_preset_hdmi,
2419 .owner = THIS_MODULE,
2420 };
2421
2422 static int __init patch_hdmi_init(void)
2423 {
2424 return snd_hda_add_codec_preset(&intel_list);
2425 }
2426
2427 static void __exit patch_hdmi_exit(void)
2428 {
2429 snd_hda_delete_codec_preset(&intel_list);
2430 }
2431
2432 module_init(patch_hdmi_init)
2433 module_exit(patch_hdmi_exit)
This page took 0.107884 seconds and 5 git commands to generate.