propogate_mnt: Handle the first propogated copy being a slave
[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 * Copyright (c) 2013 Anssi Hannula <anssi.hannula@iki.fi>
10 *
11 * Authors:
12 * Wu Fengguang <wfg@linux.intel.com>
13 *
14 * Maintained by:
15 * Wu Fengguang <wfg@linux.intel.com>
16 *
17 * This program is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License as published by the Free
19 * Software Foundation; either version 2 of the License, or (at your option)
20 * any later version.
21 *
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 * for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software Foundation,
29 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 */
31
32 #include <linux/init.h>
33 #include <linux/delay.h>
34 #include <linux/slab.h>
35 #include <linux/module.h>
36 #include <sound/core.h>
37 #include <sound/jack.h>
38 #include <sound/asoundef.h>
39 #include <sound/tlv.h>
40 #include <sound/hdaudio.h>
41 #include <sound/hda_i915.h>
42 #include <sound/hda_chmap.h>
43 #include "hda_codec.h"
44 #include "hda_local.h"
45 #include "hda_jack.h"
46
47 static bool static_hdmi_pcm;
48 module_param(static_hdmi_pcm, bool, 0644);
49 MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
50
51 #define is_haswell(codec) ((codec)->core.vendor_id == 0x80862807)
52 #define is_broadwell(codec) ((codec)->core.vendor_id == 0x80862808)
53 #define is_skylake(codec) ((codec)->core.vendor_id == 0x80862809)
54 #define is_broxton(codec) ((codec)->core.vendor_id == 0x8086280a)
55 #define is_kabylake(codec) ((codec)->core.vendor_id == 0x8086280b)
56 #define is_haswell_plus(codec) (is_haswell(codec) || is_broadwell(codec) \
57 || is_skylake(codec) || is_broxton(codec) \
58 || is_kabylake(codec))
59
60 #define is_valleyview(codec) ((codec)->core.vendor_id == 0x80862882)
61 #define is_cherryview(codec) ((codec)->core.vendor_id == 0x80862883)
62 #define is_valleyview_plus(codec) (is_valleyview(codec) || is_cherryview(codec))
63
64 struct hdmi_spec_per_cvt {
65 hda_nid_t cvt_nid;
66 int assigned;
67 unsigned int channels_min;
68 unsigned int channels_max;
69 u32 rates;
70 u64 formats;
71 unsigned int maxbps;
72 };
73
74 /* max. connections to a widget */
75 #define HDA_MAX_CONNECTIONS 32
76
77 struct hdmi_spec_per_pin {
78 hda_nid_t pin_nid;
79 /* pin idx, different device entries on the same pin use the same idx */
80 int pin_nid_idx;
81 int num_mux_nids;
82 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
83 int mux_idx;
84 hda_nid_t cvt_nid;
85
86 struct hda_codec *codec;
87 struct hdmi_eld sink_eld;
88 struct mutex lock;
89 struct delayed_work work;
90 struct hdmi_pcm *pcm; /* pointer to spec->pcm_rec[n] dynamically*/
91 int pcm_idx; /* which pcm is attached. -1 means no pcm is attached */
92 int repoll_count;
93 bool setup; /* the stream has been set up by prepare callback */
94 int channels; /* current number of channels */
95 bool non_pcm;
96 bool chmap_set; /* channel-map override by ALSA API? */
97 unsigned char chmap[8]; /* ALSA API channel-map */
98 #ifdef CONFIG_SND_PROC_FS
99 struct snd_info_entry *proc_entry;
100 #endif
101 };
102
103 /* operations used by generic code that can be overridden by patches */
104 struct hdmi_ops {
105 int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid,
106 unsigned char *buf, int *eld_size);
107
108 void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid,
109 int ca, int active_channels, int conn_type);
110
111 /* enable/disable HBR (HD passthrough) */
112 int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid, bool hbr);
113
114 int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid,
115 hda_nid_t pin_nid, u32 stream_tag, int format);
116
117 };
118
119 struct hdmi_pcm {
120 struct hda_pcm *pcm;
121 struct snd_jack *jack;
122 struct snd_kcontrol *eld_ctl;
123 };
124
125 struct hdmi_spec {
126 int num_cvts;
127 struct snd_array cvts; /* struct hdmi_spec_per_cvt */
128 hda_nid_t cvt_nids[4]; /* only for haswell fix */
129
130 int num_pins;
131 struct snd_array pins; /* struct hdmi_spec_per_pin */
132 struct hdmi_pcm pcm_rec[16];
133 struct mutex pcm_lock;
134 /* pcm_bitmap means which pcms have been assigned to pins*/
135 unsigned long pcm_bitmap;
136 int pcm_used; /* counter of pcm_rec[] */
137 /* bitmap shows whether the pcm is opened in user space
138 * bit 0 means the first playback PCM (PCM3);
139 * bit 1 means the second playback PCM, and so on.
140 */
141 unsigned long pcm_in_use;
142
143 struct hdmi_eld temp_eld;
144 struct hdmi_ops ops;
145
146 bool dyn_pin_out;
147 bool dyn_pcm_assign;
148 /*
149 * Non-generic VIA/NVIDIA specific
150 */
151 struct hda_multi_out multiout;
152 struct hda_pcm_stream pcm_playback;
153
154 /* i915/powerwell (Haswell+/Valleyview+) specific */
155 bool use_acomp_notifier; /* use i915 eld_notify callback for hotplug */
156 struct i915_audio_component_audio_ops i915_audio_ops;
157 bool i915_bound; /* was i915 bound in this driver? */
158
159 struct hdac_chmap chmap;
160 };
161
162 #ifdef CONFIG_SND_HDA_I915
163 static inline bool codec_has_acomp(struct hda_codec *codec)
164 {
165 struct hdmi_spec *spec = codec->spec;
166 return spec->use_acomp_notifier;
167 }
168 #else
169 #define codec_has_acomp(codec) false
170 #endif
171
172 struct hdmi_audio_infoframe {
173 u8 type; /* 0x84 */
174 u8 ver; /* 0x01 */
175 u8 len; /* 0x0a */
176
177 u8 checksum;
178
179 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
180 u8 SS01_SF24;
181 u8 CXT04;
182 u8 CA;
183 u8 LFEPBL01_LSV36_DM_INH7;
184 };
185
186 struct dp_audio_infoframe {
187 u8 type; /* 0x84 */
188 u8 len; /* 0x1b */
189 u8 ver; /* 0x11 << 2 */
190
191 u8 CC02_CT47; /* match with HDMI infoframe from this on */
192 u8 SS01_SF24;
193 u8 CXT04;
194 u8 CA;
195 u8 LFEPBL01_LSV36_DM_INH7;
196 };
197
198 union audio_infoframe {
199 struct hdmi_audio_infoframe hdmi;
200 struct dp_audio_infoframe dp;
201 u8 bytes[0];
202 };
203
204 /*
205 * HDMI routines
206 */
207
208 #define get_pin(spec, idx) \
209 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx))
210 #define get_cvt(spec, idx) \
211 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx))
212 /* obtain hdmi_pcm object assigned to idx */
213 #define get_hdmi_pcm(spec, idx) (&(spec)->pcm_rec[idx])
214 /* obtain hda_pcm object assigned to idx */
215 #define get_pcm_rec(spec, idx) (get_hdmi_pcm(spec, idx)->pcm)
216
217 static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid)
218 {
219 struct hdmi_spec *spec = codec->spec;
220 int pin_idx;
221
222 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
223 if (get_pin(spec, pin_idx)->pin_nid == pin_nid)
224 return pin_idx;
225
226 codec_warn(codec, "HDMI: pin nid %d not registered\n", pin_nid);
227 return -EINVAL;
228 }
229
230 static int hinfo_to_pcm_index(struct hda_codec *codec,
231 struct hda_pcm_stream *hinfo)
232 {
233 struct hdmi_spec *spec = codec->spec;
234 int pcm_idx;
235
236 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++)
237 if (get_pcm_rec(spec, pcm_idx)->stream == hinfo)
238 return pcm_idx;
239
240 codec_warn(codec, "HDMI: hinfo %p not registered\n", hinfo);
241 return -EINVAL;
242 }
243
244 static int hinfo_to_pin_index(struct hda_codec *codec,
245 struct hda_pcm_stream *hinfo)
246 {
247 struct hdmi_spec *spec = codec->spec;
248 struct hdmi_spec_per_pin *per_pin;
249 int pin_idx;
250
251 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
252 per_pin = get_pin(spec, pin_idx);
253 if (per_pin->pcm &&
254 per_pin->pcm->pcm->stream == hinfo)
255 return pin_idx;
256 }
257
258 codec_dbg(codec, "HDMI: hinfo %p not registered\n", hinfo);
259 return -EINVAL;
260 }
261
262 static struct hdmi_spec_per_pin *pcm_idx_to_pin(struct hdmi_spec *spec,
263 int pcm_idx)
264 {
265 int i;
266 struct hdmi_spec_per_pin *per_pin;
267
268 for (i = 0; i < spec->num_pins; i++) {
269 per_pin = get_pin(spec, i);
270 if (per_pin->pcm_idx == pcm_idx)
271 return per_pin;
272 }
273 return NULL;
274 }
275
276 static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid)
277 {
278 struct hdmi_spec *spec = codec->spec;
279 int cvt_idx;
280
281 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
282 if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid)
283 return cvt_idx;
284
285 codec_warn(codec, "HDMI: cvt nid %d not registered\n", cvt_nid);
286 return -EINVAL;
287 }
288
289 static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
290 struct snd_ctl_elem_info *uinfo)
291 {
292 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
293 struct hdmi_spec *spec = codec->spec;
294 struct hdmi_spec_per_pin *per_pin;
295 struct hdmi_eld *eld;
296 int pcm_idx;
297
298 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
299
300 pcm_idx = kcontrol->private_value;
301 mutex_lock(&spec->pcm_lock);
302 per_pin = pcm_idx_to_pin(spec, pcm_idx);
303 if (!per_pin) {
304 /* no pin is bound to the pcm */
305 uinfo->count = 0;
306 mutex_unlock(&spec->pcm_lock);
307 return 0;
308 }
309 eld = &per_pin->sink_eld;
310 uinfo->count = eld->eld_valid ? eld->eld_size : 0;
311 mutex_unlock(&spec->pcm_lock);
312
313 return 0;
314 }
315
316 static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
317 struct snd_ctl_elem_value *ucontrol)
318 {
319 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
320 struct hdmi_spec *spec = codec->spec;
321 struct hdmi_spec_per_pin *per_pin;
322 struct hdmi_eld *eld;
323 int pcm_idx;
324
325 pcm_idx = kcontrol->private_value;
326 mutex_lock(&spec->pcm_lock);
327 per_pin = pcm_idx_to_pin(spec, pcm_idx);
328 if (!per_pin) {
329 /* no pin is bound to the pcm */
330 memset(ucontrol->value.bytes.data, 0,
331 ARRAY_SIZE(ucontrol->value.bytes.data));
332 mutex_unlock(&spec->pcm_lock);
333 return 0;
334 }
335 eld = &per_pin->sink_eld;
336
337 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data) ||
338 eld->eld_size > ELD_MAX_SIZE) {
339 mutex_unlock(&spec->pcm_lock);
340 snd_BUG();
341 return -EINVAL;
342 }
343
344 memset(ucontrol->value.bytes.data, 0,
345 ARRAY_SIZE(ucontrol->value.bytes.data));
346 if (eld->eld_valid)
347 memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
348 eld->eld_size);
349 mutex_unlock(&spec->pcm_lock);
350
351 return 0;
352 }
353
354 static struct snd_kcontrol_new eld_bytes_ctl = {
355 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
356 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
357 .name = "ELD",
358 .info = hdmi_eld_ctl_info,
359 .get = hdmi_eld_ctl_get,
360 };
361
362 static int hdmi_create_eld_ctl(struct hda_codec *codec, int pcm_idx,
363 int device)
364 {
365 struct snd_kcontrol *kctl;
366 struct hdmi_spec *spec = codec->spec;
367 int err;
368
369 kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
370 if (!kctl)
371 return -ENOMEM;
372 kctl->private_value = pcm_idx;
373 kctl->id.device = device;
374
375 /* no pin nid is associated with the kctl now
376 * tbd: associate pin nid to eld ctl later
377 */
378 err = snd_hda_ctl_add(codec, 0, kctl);
379 if (err < 0)
380 return err;
381
382 get_hdmi_pcm(spec, pcm_idx)->eld_ctl = kctl;
383 return 0;
384 }
385
386 #ifdef BE_PARANOID
387 static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
388 int *packet_index, int *byte_index)
389 {
390 int val;
391
392 val = snd_hda_codec_read(codec, pin_nid, 0,
393 AC_VERB_GET_HDMI_DIP_INDEX, 0);
394
395 *packet_index = val >> 5;
396 *byte_index = val & 0x1f;
397 }
398 #endif
399
400 static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
401 int packet_index, int byte_index)
402 {
403 int val;
404
405 val = (packet_index << 5) | (byte_index & 0x1f);
406
407 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
408 }
409
410 static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
411 unsigned char val)
412 {
413 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
414 }
415
416 static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
417 {
418 struct hdmi_spec *spec = codec->spec;
419 int pin_out;
420
421 /* Unmute */
422 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
423 snd_hda_codec_write(codec, pin_nid, 0,
424 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
425
426 if (spec->dyn_pin_out)
427 /* Disable pin out until stream is active */
428 pin_out = 0;
429 else
430 /* Enable pin out: some machines with GM965 gets broken output
431 * when the pin is disabled or changed while using with HDMI
432 */
433 pin_out = PIN_OUT;
434
435 snd_hda_codec_write(codec, pin_nid, 0,
436 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_out);
437 }
438
439 /*
440 * ELD proc files
441 */
442
443 #ifdef CONFIG_SND_PROC_FS
444 static void print_eld_info(struct snd_info_entry *entry,
445 struct snd_info_buffer *buffer)
446 {
447 struct hdmi_spec_per_pin *per_pin = entry->private_data;
448
449 mutex_lock(&per_pin->lock);
450 snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer);
451 mutex_unlock(&per_pin->lock);
452 }
453
454 static void write_eld_info(struct snd_info_entry *entry,
455 struct snd_info_buffer *buffer)
456 {
457 struct hdmi_spec_per_pin *per_pin = entry->private_data;
458
459 mutex_lock(&per_pin->lock);
460 snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer);
461 mutex_unlock(&per_pin->lock);
462 }
463
464 static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
465 {
466 char name[32];
467 struct hda_codec *codec = per_pin->codec;
468 struct snd_info_entry *entry;
469 int err;
470
471 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
472 err = snd_card_proc_new(codec->card, name, &entry);
473 if (err < 0)
474 return err;
475
476 snd_info_set_text_ops(entry, per_pin, print_eld_info);
477 entry->c.text.write = write_eld_info;
478 entry->mode |= S_IWUSR;
479 per_pin->proc_entry = entry;
480
481 return 0;
482 }
483
484 static void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
485 {
486 if (!per_pin->codec->bus->shutdown) {
487 snd_info_free_entry(per_pin->proc_entry);
488 per_pin->proc_entry = NULL;
489 }
490 }
491 #else
492 static inline int eld_proc_new(struct hdmi_spec_per_pin *per_pin,
493 int index)
494 {
495 return 0;
496 }
497 static inline void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
498 {
499 }
500 #endif
501
502 /*
503 * Audio InfoFrame routines
504 */
505
506 /*
507 * Enable Audio InfoFrame Transmission
508 */
509 static void hdmi_start_infoframe_trans(struct hda_codec *codec,
510 hda_nid_t pin_nid)
511 {
512 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
513 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
514 AC_DIPXMIT_BEST);
515 }
516
517 /*
518 * Disable Audio InfoFrame Transmission
519 */
520 static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
521 hda_nid_t pin_nid)
522 {
523 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
524 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
525 AC_DIPXMIT_DISABLE);
526 }
527
528 static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
529 {
530 #ifdef CONFIG_SND_DEBUG_VERBOSE
531 int i;
532 int size;
533
534 size = snd_hdmi_get_eld_size(codec, pin_nid);
535 codec_dbg(codec, "HDMI: ELD buf size is %d\n", size);
536
537 for (i = 0; i < 8; i++) {
538 size = snd_hda_codec_read(codec, pin_nid, 0,
539 AC_VERB_GET_HDMI_DIP_SIZE, i);
540 codec_dbg(codec, "HDMI: DIP GP[%d] buf size is %d\n", i, size);
541 }
542 #endif
543 }
544
545 static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
546 {
547 #ifdef BE_PARANOID
548 int i, j;
549 int size;
550 int pi, bi;
551 for (i = 0; i < 8; i++) {
552 size = snd_hda_codec_read(codec, pin_nid, 0,
553 AC_VERB_GET_HDMI_DIP_SIZE, i);
554 if (size == 0)
555 continue;
556
557 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
558 for (j = 1; j < 1000; j++) {
559 hdmi_write_dip_byte(codec, pin_nid, 0x0);
560 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
561 if (pi != i)
562 codec_dbg(codec, "dip index %d: %d != %d\n",
563 bi, pi, i);
564 if (bi == 0) /* byte index wrapped around */
565 break;
566 }
567 codec_dbg(codec,
568 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
569 i, size, j);
570 }
571 #endif
572 }
573
574 static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
575 {
576 u8 *bytes = (u8 *)hdmi_ai;
577 u8 sum = 0;
578 int i;
579
580 hdmi_ai->checksum = 0;
581
582 for (i = 0; i < sizeof(*hdmi_ai); i++)
583 sum += bytes[i];
584
585 hdmi_ai->checksum = -sum;
586 }
587
588 static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
589 hda_nid_t pin_nid,
590 u8 *dip, int size)
591 {
592 int i;
593
594 hdmi_debug_dip_size(codec, pin_nid);
595 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
596
597 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
598 for (i = 0; i < size; i++)
599 hdmi_write_dip_byte(codec, pin_nid, dip[i]);
600 }
601
602 static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
603 u8 *dip, int size)
604 {
605 u8 val;
606 int i;
607
608 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
609 != AC_DIPXMIT_BEST)
610 return false;
611
612 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
613 for (i = 0; i < size; i++) {
614 val = snd_hda_codec_read(codec, pin_nid, 0,
615 AC_VERB_GET_HDMI_DIP_DATA, 0);
616 if (val != dip[i])
617 return false;
618 }
619
620 return true;
621 }
622
623 static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
624 hda_nid_t pin_nid,
625 int ca, int active_channels,
626 int conn_type)
627 {
628 union audio_infoframe ai;
629
630 memset(&ai, 0, sizeof(ai));
631 if (conn_type == 0) { /* HDMI */
632 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
633
634 hdmi_ai->type = 0x84;
635 hdmi_ai->ver = 0x01;
636 hdmi_ai->len = 0x0a;
637 hdmi_ai->CC02_CT47 = active_channels - 1;
638 hdmi_ai->CA = ca;
639 hdmi_checksum_audio_infoframe(hdmi_ai);
640 } else if (conn_type == 1) { /* DisplayPort */
641 struct dp_audio_infoframe *dp_ai = &ai.dp;
642
643 dp_ai->type = 0x84;
644 dp_ai->len = 0x1b;
645 dp_ai->ver = 0x11 << 2;
646 dp_ai->CC02_CT47 = active_channels - 1;
647 dp_ai->CA = ca;
648 } else {
649 codec_dbg(codec, "HDMI: unknown connection type at pin %d\n",
650 pin_nid);
651 return;
652 }
653
654 /*
655 * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
656 * sizeof(*dp_ai) to avoid partial match/update problems when
657 * the user switches between HDMI/DP monitors.
658 */
659 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
660 sizeof(ai))) {
661 codec_dbg(codec,
662 "hdmi_pin_setup_infoframe: pin=%d channels=%d ca=0x%02x\n",
663 pin_nid,
664 active_channels, ca);
665 hdmi_stop_infoframe_trans(codec, pin_nid);
666 hdmi_fill_audio_infoframe(codec, pin_nid,
667 ai.bytes, sizeof(ai));
668 hdmi_start_infoframe_trans(codec, pin_nid);
669 }
670 }
671
672 static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
673 struct hdmi_spec_per_pin *per_pin,
674 bool non_pcm)
675 {
676 struct hdmi_spec *spec = codec->spec;
677 struct hdac_chmap *chmap = &spec->chmap;
678 hda_nid_t pin_nid = per_pin->pin_nid;
679 int channels = per_pin->channels;
680 int active_channels;
681 struct hdmi_eld *eld;
682 int ca;
683
684 if (!channels)
685 return;
686
687 if (is_haswell_plus(codec))
688 snd_hda_codec_write(codec, pin_nid, 0,
689 AC_VERB_SET_AMP_GAIN_MUTE,
690 AMP_OUT_UNMUTE);
691
692 eld = &per_pin->sink_eld;
693
694 ca = snd_hdac_channel_allocation(&codec->core,
695 eld->info.spk_alloc, channels,
696 per_pin->chmap_set, non_pcm, per_pin->chmap);
697
698 active_channels = snd_hdac_get_active_channels(ca);
699
700 chmap->ops.set_channel_count(&codec->core, per_pin->cvt_nid,
701 active_channels);
702
703 /*
704 * always configure channel mapping, it may have been changed by the
705 * user in the meantime
706 */
707 snd_hdac_setup_channel_mapping(&spec->chmap,
708 pin_nid, non_pcm, ca, channels,
709 per_pin->chmap, per_pin->chmap_set);
710
711 spec->ops.pin_setup_infoframe(codec, pin_nid, ca, active_channels,
712 eld->info.conn_type);
713
714 per_pin->non_pcm = non_pcm;
715 }
716
717 /*
718 * Unsolicited events
719 */
720
721 static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
722
723 static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid)
724 {
725 struct hdmi_spec *spec = codec->spec;
726 int pin_idx = pin_nid_to_pin_index(codec, nid);
727
728 if (pin_idx < 0)
729 return;
730 if (hdmi_present_sense(get_pin(spec, pin_idx), 1))
731 snd_hda_jack_report_sync(codec);
732 }
733
734 static void jack_callback(struct hda_codec *codec,
735 struct hda_jack_callback *jack)
736 {
737 check_presence_and_report(codec, jack->nid);
738 }
739
740 static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
741 {
742 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
743 struct hda_jack_tbl *jack;
744 int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
745
746 jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
747 if (!jack)
748 return;
749 jack->jack_dirty = 1;
750
751 codec_dbg(codec,
752 "HDMI hot plug event: Codec=%d Pin=%d Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n",
753 codec->addr, jack->nid, dev_entry, !!(res & AC_UNSOL_RES_IA),
754 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
755
756 check_presence_and_report(codec, jack->nid);
757 }
758
759 static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
760 {
761 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
762 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
763 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
764 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
765
766 codec_info(codec,
767 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
768 codec->addr,
769 tag,
770 subtag,
771 cp_state,
772 cp_ready);
773
774 /* TODO */
775 if (cp_state)
776 ;
777 if (cp_ready)
778 ;
779 }
780
781
782 static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
783 {
784 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
785 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
786
787 if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) {
788 codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag);
789 return;
790 }
791
792 if (subtag == 0)
793 hdmi_intrinsic_event(codec, res);
794 else
795 hdmi_non_intrinsic_event(codec, res);
796 }
797
798 static void haswell_verify_D0(struct hda_codec *codec,
799 hda_nid_t cvt_nid, hda_nid_t nid)
800 {
801 int pwr;
802
803 /* For Haswell, the converter 1/2 may keep in D3 state after bootup,
804 * thus pins could only choose converter 0 for use. Make sure the
805 * converters are in correct power state */
806 if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0))
807 snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
808
809 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) {
810 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
811 AC_PWRST_D0);
812 msleep(40);
813 pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
814 pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
815 codec_dbg(codec, "Haswell HDMI audio: Power for pin 0x%x is now D%d\n", nid, pwr);
816 }
817 }
818
819 /*
820 * Callbacks
821 */
822
823 /* HBR should be Non-PCM, 8 channels */
824 #define is_hbr_format(format) \
825 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
826
827 static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
828 bool hbr)
829 {
830 int pinctl, new_pinctl;
831
832 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
833 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
834 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
835
836 if (pinctl < 0)
837 return hbr ? -EINVAL : 0;
838
839 new_pinctl = pinctl & ~AC_PINCTL_EPT;
840 if (hbr)
841 new_pinctl |= AC_PINCTL_EPT_HBR;
842 else
843 new_pinctl |= AC_PINCTL_EPT_NATIVE;
844
845 codec_dbg(codec,
846 "hdmi_pin_hbr_setup: NID=0x%x, %spinctl=0x%x\n",
847 pin_nid,
848 pinctl == new_pinctl ? "" : "new-",
849 new_pinctl);
850
851 if (pinctl != new_pinctl)
852 snd_hda_codec_write(codec, pin_nid, 0,
853 AC_VERB_SET_PIN_WIDGET_CONTROL,
854 new_pinctl);
855 } else if (hbr)
856 return -EINVAL;
857
858 return 0;
859 }
860
861 static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
862 hda_nid_t pin_nid, u32 stream_tag, int format)
863 {
864 struct hdmi_spec *spec = codec->spec;
865 int err;
866
867 if (is_haswell_plus(codec))
868 haswell_verify_D0(codec, cvt_nid, pin_nid);
869
870 err = spec->ops.pin_hbr_setup(codec, pin_nid, is_hbr_format(format));
871
872 if (err) {
873 codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n");
874 return err;
875 }
876
877 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
878 return 0;
879 }
880
881 /* Try to find an available converter
882 * If pin_idx is less then zero, just try to find an available converter.
883 * Otherwise, try to find an available converter and get the cvt mux index
884 * of the pin.
885 */
886 static int hdmi_choose_cvt(struct hda_codec *codec,
887 int pin_idx, int *cvt_id, int *mux_id)
888 {
889 struct hdmi_spec *spec = codec->spec;
890 struct hdmi_spec_per_pin *per_pin;
891 struct hdmi_spec_per_cvt *per_cvt = NULL;
892 int cvt_idx, mux_idx = 0;
893
894 /* pin_idx < 0 means no pin will be bound to the converter */
895 if (pin_idx < 0)
896 per_pin = NULL;
897 else
898 per_pin = get_pin(spec, pin_idx);
899
900 /* Dynamically assign converter to stream */
901 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
902 per_cvt = get_cvt(spec, cvt_idx);
903
904 /* Must not already be assigned */
905 if (per_cvt->assigned)
906 continue;
907 if (per_pin == NULL)
908 break;
909 /* Must be in pin's mux's list of converters */
910 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
911 if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid)
912 break;
913 /* Not in mux list */
914 if (mux_idx == per_pin->num_mux_nids)
915 continue;
916 break;
917 }
918
919 /* No free converters */
920 if (cvt_idx == spec->num_cvts)
921 return -EBUSY;
922
923 if (per_pin != NULL)
924 per_pin->mux_idx = mux_idx;
925
926 if (cvt_id)
927 *cvt_id = cvt_idx;
928 if (mux_id)
929 *mux_id = mux_idx;
930
931 return 0;
932 }
933
934 /* Assure the pin select the right convetor */
935 static void intel_verify_pin_cvt_connect(struct hda_codec *codec,
936 struct hdmi_spec_per_pin *per_pin)
937 {
938 hda_nid_t pin_nid = per_pin->pin_nid;
939 int mux_idx, curr;
940
941 mux_idx = per_pin->mux_idx;
942 curr = snd_hda_codec_read(codec, pin_nid, 0,
943 AC_VERB_GET_CONNECT_SEL, 0);
944 if (curr != mux_idx)
945 snd_hda_codec_write_cache(codec, pin_nid, 0,
946 AC_VERB_SET_CONNECT_SEL,
947 mux_idx);
948 }
949
950 /* get the mux index for the converter of the pins
951 * converter's mux index is the same for all pins on Intel platform
952 */
953 static int intel_cvt_id_to_mux_idx(struct hdmi_spec *spec,
954 hda_nid_t cvt_nid)
955 {
956 int i;
957
958 for (i = 0; i < spec->num_cvts; i++)
959 if (spec->cvt_nids[i] == cvt_nid)
960 return i;
961 return -EINVAL;
962 }
963
964 /* Intel HDMI workaround to fix audio routing issue:
965 * For some Intel display codecs, pins share the same connection list.
966 * So a conveter can be selected by multiple pins and playback on any of these
967 * pins will generate sound on the external display, because audio flows from
968 * the same converter to the display pipeline. Also muting one pin may make
969 * other pins have no sound output.
970 * So this function assures that an assigned converter for a pin is not selected
971 * by any other pins.
972 */
973 static void intel_not_share_assigned_cvt(struct hda_codec *codec,
974 hda_nid_t pin_nid, int mux_idx)
975 {
976 struct hdmi_spec *spec = codec->spec;
977 hda_nid_t nid;
978 int cvt_idx, curr;
979 struct hdmi_spec_per_cvt *per_cvt;
980
981 /* configure all pins, including "no physical connection" ones */
982 for_each_hda_codec_node(nid, codec) {
983 unsigned int wid_caps = get_wcaps(codec, nid);
984 unsigned int wid_type = get_wcaps_type(wid_caps);
985
986 if (wid_type != AC_WID_PIN)
987 continue;
988
989 if (nid == pin_nid)
990 continue;
991
992 curr = snd_hda_codec_read(codec, nid, 0,
993 AC_VERB_GET_CONNECT_SEL, 0);
994 if (curr != mux_idx)
995 continue;
996
997 /* choose an unassigned converter. The conveters in the
998 * connection list are in the same order as in the codec.
999 */
1000 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
1001 per_cvt = get_cvt(spec, cvt_idx);
1002 if (!per_cvt->assigned) {
1003 codec_dbg(codec,
1004 "choose cvt %d for pin nid %d\n",
1005 cvt_idx, nid);
1006 snd_hda_codec_write_cache(codec, nid, 0,
1007 AC_VERB_SET_CONNECT_SEL,
1008 cvt_idx);
1009 break;
1010 }
1011 }
1012 }
1013 }
1014
1015 /* A wrapper of intel_not_share_asigned_cvt() */
1016 static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,
1017 hda_nid_t pin_nid, hda_nid_t cvt_nid)
1018 {
1019 int mux_idx;
1020 struct hdmi_spec *spec = codec->spec;
1021
1022 if (!is_haswell_plus(codec) && !is_valleyview_plus(codec))
1023 return;
1024
1025 /* On Intel platform, the mapping of converter nid to
1026 * mux index of the pins are always the same.
1027 * The pin nid may be 0, this means all pins will not
1028 * share the converter.
1029 */
1030 mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid);
1031 if (mux_idx >= 0)
1032 intel_not_share_assigned_cvt(codec, pin_nid, mux_idx);
1033 }
1034
1035 /* called in hdmi_pcm_open when no pin is assigned to the PCM
1036 * in dyn_pcm_assign mode.
1037 */
1038 static int hdmi_pcm_open_no_pin(struct hda_pcm_stream *hinfo,
1039 struct hda_codec *codec,
1040 struct snd_pcm_substream *substream)
1041 {
1042 struct hdmi_spec *spec = codec->spec;
1043 struct snd_pcm_runtime *runtime = substream->runtime;
1044 int cvt_idx, pcm_idx;
1045 struct hdmi_spec_per_cvt *per_cvt = NULL;
1046 int err;
1047
1048 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1049 if (pcm_idx < 0)
1050 return -EINVAL;
1051
1052 err = hdmi_choose_cvt(codec, -1, &cvt_idx, NULL);
1053 if (err)
1054 return err;
1055
1056 per_cvt = get_cvt(spec, cvt_idx);
1057 per_cvt->assigned = 1;
1058 hinfo->nid = per_cvt->cvt_nid;
1059
1060 intel_not_share_assigned_cvt_nid(codec, 0, per_cvt->cvt_nid);
1061
1062 set_bit(pcm_idx, &spec->pcm_in_use);
1063 /* todo: setup spdif ctls assign */
1064
1065 /* Initially set the converter's capabilities */
1066 hinfo->channels_min = per_cvt->channels_min;
1067 hinfo->channels_max = per_cvt->channels_max;
1068 hinfo->rates = per_cvt->rates;
1069 hinfo->formats = per_cvt->formats;
1070 hinfo->maxbps = per_cvt->maxbps;
1071
1072 /* Store the updated parameters */
1073 runtime->hw.channels_min = hinfo->channels_min;
1074 runtime->hw.channels_max = hinfo->channels_max;
1075 runtime->hw.formats = hinfo->formats;
1076 runtime->hw.rates = hinfo->rates;
1077
1078 snd_pcm_hw_constraint_step(substream->runtime, 0,
1079 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
1080 return 0;
1081 }
1082
1083 /*
1084 * HDA PCM callbacks
1085 */
1086 static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1087 struct hda_codec *codec,
1088 struct snd_pcm_substream *substream)
1089 {
1090 struct hdmi_spec *spec = codec->spec;
1091 struct snd_pcm_runtime *runtime = substream->runtime;
1092 int pin_idx, cvt_idx, pcm_idx, mux_idx = 0;
1093 struct hdmi_spec_per_pin *per_pin;
1094 struct hdmi_eld *eld;
1095 struct hdmi_spec_per_cvt *per_cvt = NULL;
1096 int err;
1097
1098 /* Validate hinfo */
1099 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1100 if (pcm_idx < 0)
1101 return -EINVAL;
1102
1103 mutex_lock(&spec->pcm_lock);
1104 pin_idx = hinfo_to_pin_index(codec, hinfo);
1105 if (!spec->dyn_pcm_assign) {
1106 if (snd_BUG_ON(pin_idx < 0)) {
1107 mutex_unlock(&spec->pcm_lock);
1108 return -EINVAL;
1109 }
1110 } else {
1111 /* no pin is assigned to the PCM
1112 * PA need pcm open successfully when probe
1113 */
1114 if (pin_idx < 0) {
1115 err = hdmi_pcm_open_no_pin(hinfo, codec, substream);
1116 mutex_unlock(&spec->pcm_lock);
1117 return err;
1118 }
1119 }
1120
1121 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, &mux_idx);
1122 if (err < 0) {
1123 mutex_unlock(&spec->pcm_lock);
1124 return err;
1125 }
1126
1127 per_cvt = get_cvt(spec, cvt_idx);
1128 /* Claim converter */
1129 per_cvt->assigned = 1;
1130
1131 set_bit(pcm_idx, &spec->pcm_in_use);
1132 per_pin = get_pin(spec, pin_idx);
1133 per_pin->cvt_nid = per_cvt->cvt_nid;
1134 hinfo->nid = per_cvt->cvt_nid;
1135
1136 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1137 AC_VERB_SET_CONNECT_SEL,
1138 mux_idx);
1139
1140 /* configure unused pins to choose other converters */
1141 if (is_haswell_plus(codec) || is_valleyview_plus(codec))
1142 intel_not_share_assigned_cvt(codec, per_pin->pin_nid, mux_idx);
1143
1144 snd_hda_spdif_ctls_assign(codec, pcm_idx, per_cvt->cvt_nid);
1145
1146 /* Initially set the converter's capabilities */
1147 hinfo->channels_min = per_cvt->channels_min;
1148 hinfo->channels_max = per_cvt->channels_max;
1149 hinfo->rates = per_cvt->rates;
1150 hinfo->formats = per_cvt->formats;
1151 hinfo->maxbps = per_cvt->maxbps;
1152
1153 eld = &per_pin->sink_eld;
1154 /* Restrict capabilities by ELD if this isn't disabled */
1155 if (!static_hdmi_pcm && eld->eld_valid) {
1156 snd_hdmi_eld_update_pcm_info(&eld->info, hinfo);
1157 if (hinfo->channels_min > hinfo->channels_max ||
1158 !hinfo->rates || !hinfo->formats) {
1159 per_cvt->assigned = 0;
1160 hinfo->nid = 0;
1161 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
1162 mutex_unlock(&spec->pcm_lock);
1163 return -ENODEV;
1164 }
1165 }
1166
1167 mutex_unlock(&spec->pcm_lock);
1168 /* Store the updated parameters */
1169 runtime->hw.channels_min = hinfo->channels_min;
1170 runtime->hw.channels_max = hinfo->channels_max;
1171 runtime->hw.formats = hinfo->formats;
1172 runtime->hw.rates = hinfo->rates;
1173
1174 snd_pcm_hw_constraint_step(substream->runtime, 0,
1175 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
1176 return 0;
1177 }
1178
1179 /*
1180 * HDA/HDMI auto parsing
1181 */
1182 static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
1183 {
1184 struct hdmi_spec *spec = codec->spec;
1185 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1186 hda_nid_t pin_nid = per_pin->pin_nid;
1187
1188 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
1189 codec_warn(codec,
1190 "HDMI: pin %d wcaps %#x does not support connection list\n",
1191 pin_nid, get_wcaps(codec, pin_nid));
1192 return -EINVAL;
1193 }
1194
1195 per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,
1196 per_pin->mux_nids,
1197 HDA_MAX_CONNECTIONS);
1198
1199 return 0;
1200 }
1201
1202 static int hdmi_find_pcm_slot(struct hdmi_spec *spec,
1203 struct hdmi_spec_per_pin *per_pin)
1204 {
1205 int i;
1206
1207 /* try the prefer PCM */
1208 if (!test_bit(per_pin->pin_nid_idx, &spec->pcm_bitmap))
1209 return per_pin->pin_nid_idx;
1210
1211 /* have a second try; check the "reserved area" over num_pins */
1212 for (i = spec->num_pins; i < spec->pcm_used; i++) {
1213 if (!test_bit(i, &spec->pcm_bitmap))
1214 return i;
1215 }
1216
1217 /* the last try; check the empty slots in pins */
1218 for (i = 0; i < spec->num_pins; i++) {
1219 if (!test_bit(i, &spec->pcm_bitmap))
1220 return i;
1221 }
1222 return -EBUSY;
1223 }
1224
1225 static void hdmi_attach_hda_pcm(struct hdmi_spec *spec,
1226 struct hdmi_spec_per_pin *per_pin)
1227 {
1228 int idx;
1229
1230 /* pcm already be attached to the pin */
1231 if (per_pin->pcm)
1232 return;
1233 idx = hdmi_find_pcm_slot(spec, per_pin);
1234 if (idx == -EBUSY)
1235 return;
1236 per_pin->pcm_idx = idx;
1237 per_pin->pcm = get_hdmi_pcm(spec, idx);
1238 set_bit(idx, &spec->pcm_bitmap);
1239 }
1240
1241 static void hdmi_detach_hda_pcm(struct hdmi_spec *spec,
1242 struct hdmi_spec_per_pin *per_pin)
1243 {
1244 int idx;
1245
1246 /* pcm already be detached from the pin */
1247 if (!per_pin->pcm)
1248 return;
1249 idx = per_pin->pcm_idx;
1250 per_pin->pcm_idx = -1;
1251 per_pin->pcm = NULL;
1252 if (idx >= 0 && idx < spec->pcm_used)
1253 clear_bit(idx, &spec->pcm_bitmap);
1254 }
1255
1256 static int hdmi_get_pin_cvt_mux(struct hdmi_spec *spec,
1257 struct hdmi_spec_per_pin *per_pin, hda_nid_t cvt_nid)
1258 {
1259 int mux_idx;
1260
1261 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
1262 if (per_pin->mux_nids[mux_idx] == cvt_nid)
1263 break;
1264 return mux_idx;
1265 }
1266
1267 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid);
1268
1269 static void hdmi_pcm_setup_pin(struct hdmi_spec *spec,
1270 struct hdmi_spec_per_pin *per_pin)
1271 {
1272 struct hda_codec *codec = per_pin->codec;
1273 struct hda_pcm *pcm;
1274 struct hda_pcm_stream *hinfo;
1275 struct snd_pcm_substream *substream;
1276 int mux_idx;
1277 bool non_pcm;
1278
1279 if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
1280 pcm = get_pcm_rec(spec, per_pin->pcm_idx);
1281 else
1282 return;
1283 if (!test_bit(per_pin->pcm_idx, &spec->pcm_in_use))
1284 return;
1285
1286 /* hdmi audio only uses playback and one substream */
1287 hinfo = pcm->stream;
1288 substream = pcm->pcm->streams[0].substream;
1289
1290 per_pin->cvt_nid = hinfo->nid;
1291
1292 mux_idx = hdmi_get_pin_cvt_mux(spec, per_pin, hinfo->nid);
1293 if (mux_idx < per_pin->num_mux_nids)
1294 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1295 AC_VERB_SET_CONNECT_SEL,
1296 mux_idx);
1297 snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid);
1298
1299 non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid);
1300 if (substream->runtime)
1301 per_pin->channels = substream->runtime->channels;
1302 per_pin->setup = true;
1303 per_pin->mux_idx = mux_idx;
1304
1305 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
1306 }
1307
1308 static void hdmi_pcm_reset_pin(struct hdmi_spec *spec,
1309 struct hdmi_spec_per_pin *per_pin)
1310 {
1311 if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
1312 snd_hda_spdif_ctls_unassign(per_pin->codec, per_pin->pcm_idx);
1313
1314 per_pin->chmap_set = false;
1315 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
1316
1317 per_pin->setup = false;
1318 per_pin->channels = 0;
1319 }
1320
1321 /* update per_pin ELD from the given new ELD;
1322 * setup info frame and notification accordingly
1323 */
1324 static void update_eld(struct hda_codec *codec,
1325 struct hdmi_spec_per_pin *per_pin,
1326 struct hdmi_eld *eld)
1327 {
1328 struct hdmi_eld *pin_eld = &per_pin->sink_eld;
1329 struct hdmi_spec *spec = codec->spec;
1330 bool old_eld_valid = pin_eld->eld_valid;
1331 bool eld_changed;
1332 int pcm_idx = -1;
1333
1334 /* for monitor disconnection, save pcm_idx firstly */
1335 pcm_idx = per_pin->pcm_idx;
1336 if (spec->dyn_pcm_assign) {
1337 if (eld->eld_valid) {
1338 hdmi_attach_hda_pcm(spec, per_pin);
1339 hdmi_pcm_setup_pin(spec, per_pin);
1340 } else {
1341 hdmi_pcm_reset_pin(spec, per_pin);
1342 hdmi_detach_hda_pcm(spec, per_pin);
1343 }
1344 }
1345 /* if pcm_idx == -1, it means this is in monitor connection event
1346 * we can get the correct pcm_idx now.
1347 */
1348 if (pcm_idx == -1)
1349 pcm_idx = per_pin->pcm_idx;
1350
1351 if (eld->eld_valid)
1352 snd_hdmi_show_eld(codec, &eld->info);
1353
1354 eld_changed = (pin_eld->eld_valid != eld->eld_valid);
1355 if (eld->eld_valid && pin_eld->eld_valid)
1356 if (pin_eld->eld_size != eld->eld_size ||
1357 memcmp(pin_eld->eld_buffer, eld->eld_buffer,
1358 eld->eld_size) != 0)
1359 eld_changed = true;
1360
1361 pin_eld->monitor_present = eld->monitor_present;
1362 pin_eld->eld_valid = eld->eld_valid;
1363 pin_eld->eld_size = eld->eld_size;
1364 if (eld->eld_valid)
1365 memcpy(pin_eld->eld_buffer, eld->eld_buffer, eld->eld_size);
1366 pin_eld->info = eld->info;
1367
1368 /*
1369 * Re-setup pin and infoframe. This is needed e.g. when
1370 * - sink is first plugged-in
1371 * - transcoder can change during stream playback on Haswell
1372 * and this can make HW reset converter selection on a pin.
1373 */
1374 if (eld->eld_valid && !old_eld_valid && per_pin->setup) {
1375 if (is_haswell_plus(codec) || is_valleyview_plus(codec)) {
1376 intel_verify_pin_cvt_connect(codec, per_pin);
1377 intel_not_share_assigned_cvt(codec, per_pin->pin_nid,
1378 per_pin->mux_idx);
1379 }
1380
1381 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1382 }
1383
1384 if (eld_changed && pcm_idx >= 0)
1385 snd_ctl_notify(codec->card,
1386 SNDRV_CTL_EVENT_MASK_VALUE |
1387 SNDRV_CTL_EVENT_MASK_INFO,
1388 &get_hdmi_pcm(spec, pcm_idx)->eld_ctl->id);
1389 }
1390
1391 /* update ELD and jack state via HD-audio verbs */
1392 static bool hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin,
1393 int repoll)
1394 {
1395 struct hda_jack_tbl *jack;
1396 struct hda_codec *codec = per_pin->codec;
1397 struct hdmi_spec *spec = codec->spec;
1398 struct hdmi_eld *eld = &spec->temp_eld;
1399 hda_nid_t pin_nid = per_pin->pin_nid;
1400 /*
1401 * Always execute a GetPinSense verb here, even when called from
1402 * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
1403 * response's PD bit is not the real PD value, but indicates that
1404 * the real PD value changed. An older version of the HD-audio
1405 * specification worked this way. Hence, we just ignore the data in
1406 * the unsolicited response to avoid custom WARs.
1407 */
1408 int present;
1409 bool ret;
1410 bool do_repoll = false;
1411
1412 present = snd_hda_pin_sense(codec, pin_nid);
1413
1414 mutex_lock(&per_pin->lock);
1415 eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
1416 if (eld->monitor_present)
1417 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
1418 else
1419 eld->eld_valid = false;
1420
1421 codec_dbg(codec,
1422 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
1423 codec->addr, pin_nid, eld->monitor_present, eld->eld_valid);
1424
1425 if (eld->eld_valid) {
1426 if (spec->ops.pin_get_eld(codec, pin_nid, eld->eld_buffer,
1427 &eld->eld_size) < 0)
1428 eld->eld_valid = false;
1429 else {
1430 if (snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer,
1431 eld->eld_size) < 0)
1432 eld->eld_valid = false;
1433 }
1434 if (!eld->eld_valid && repoll)
1435 do_repoll = true;
1436 }
1437
1438 if (do_repoll)
1439 schedule_delayed_work(&per_pin->work, msecs_to_jiffies(300));
1440 else
1441 update_eld(codec, per_pin, eld);
1442
1443 ret = !repoll || !eld->monitor_present || eld->eld_valid;
1444
1445 jack = snd_hda_jack_tbl_get(codec, pin_nid);
1446 if (jack)
1447 jack->block_report = !ret;
1448
1449 mutex_unlock(&per_pin->lock);
1450 return ret;
1451 }
1452
1453 static struct snd_jack *pin_idx_to_jack(struct hda_codec *codec,
1454 struct hdmi_spec_per_pin *per_pin)
1455 {
1456 struct hdmi_spec *spec = codec->spec;
1457 struct snd_jack *jack = NULL;
1458 struct hda_jack_tbl *jack_tbl;
1459
1460 /* if !dyn_pcm_assign, get jack from hda_jack_tbl
1461 * in !dyn_pcm_assign case, spec->pcm_rec[].jack is not
1462 * NULL even after snd_hda_jack_tbl_clear() is called to
1463 * free snd_jack. This may cause access invalid memory
1464 * when calling snd_jack_report
1465 */
1466 if (per_pin->pcm_idx >= 0 && spec->dyn_pcm_assign)
1467 jack = spec->pcm_rec[per_pin->pcm_idx].jack;
1468 else if (!spec->dyn_pcm_assign) {
1469 jack_tbl = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
1470 if (jack_tbl)
1471 jack = jack_tbl->jack;
1472 }
1473 return jack;
1474 }
1475
1476 /* update ELD and jack state via audio component */
1477 static void sync_eld_via_acomp(struct hda_codec *codec,
1478 struct hdmi_spec_per_pin *per_pin)
1479 {
1480 struct hdmi_spec *spec = codec->spec;
1481 struct hdmi_eld *eld = &spec->temp_eld;
1482 struct snd_jack *jack = NULL;
1483 int size;
1484
1485 mutex_lock(&per_pin->lock);
1486 eld->monitor_present = false;
1487 size = snd_hdac_acomp_get_eld(&codec->bus->core, per_pin->pin_nid,
1488 &eld->monitor_present, eld->eld_buffer,
1489 ELD_MAX_SIZE);
1490 if (size > 0) {
1491 size = min(size, ELD_MAX_SIZE);
1492 if (snd_hdmi_parse_eld(codec, &eld->info,
1493 eld->eld_buffer, size) < 0)
1494 size = -EINVAL;
1495 }
1496
1497 if (size > 0) {
1498 eld->eld_valid = true;
1499 eld->eld_size = size;
1500 } else {
1501 eld->eld_valid = false;
1502 eld->eld_size = 0;
1503 }
1504
1505 /* pcm_idx >=0 before update_eld() means it is in monitor
1506 * disconnected event. Jack must be fetched before update_eld()
1507 */
1508 jack = pin_idx_to_jack(codec, per_pin);
1509 update_eld(codec, per_pin, eld);
1510 if (jack == NULL)
1511 jack = pin_idx_to_jack(codec, per_pin);
1512 if (jack == NULL)
1513 goto unlock;
1514 snd_jack_report(jack,
1515 eld->monitor_present ? SND_JACK_AVOUT : 0);
1516 unlock:
1517 mutex_unlock(&per_pin->lock);
1518 }
1519
1520 static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1521 {
1522 struct hda_codec *codec = per_pin->codec;
1523 struct hdmi_spec *spec = codec->spec;
1524 int ret;
1525
1526 /* no temporary power up/down needed for component notifier */
1527 if (!codec_has_acomp(codec))
1528 snd_hda_power_up_pm(codec);
1529
1530 mutex_lock(&spec->pcm_lock);
1531 if (codec_has_acomp(codec)) {
1532 sync_eld_via_acomp(codec, per_pin);
1533 ret = false; /* don't call snd_hda_jack_report_sync() */
1534 } else {
1535 ret = hdmi_present_sense_via_verbs(per_pin, repoll);
1536 }
1537 mutex_unlock(&spec->pcm_lock);
1538
1539 if (!codec_has_acomp(codec))
1540 snd_hda_power_down_pm(codec);
1541
1542 return ret;
1543 }
1544
1545 static void hdmi_repoll_eld(struct work_struct *work)
1546 {
1547 struct hdmi_spec_per_pin *per_pin =
1548 container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
1549
1550 if (per_pin->repoll_count++ > 6)
1551 per_pin->repoll_count = 0;
1552
1553 if (hdmi_present_sense(per_pin, per_pin->repoll_count))
1554 snd_hda_jack_report_sync(per_pin->codec);
1555 }
1556
1557 static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
1558 hda_nid_t nid);
1559
1560 static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1561 {
1562 struct hdmi_spec *spec = codec->spec;
1563 unsigned int caps, config;
1564 int pin_idx;
1565 struct hdmi_spec_per_pin *per_pin;
1566 int err;
1567
1568 caps = snd_hda_query_pin_caps(codec, pin_nid);
1569 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
1570 return 0;
1571
1572 config = snd_hda_codec_get_pincfg(codec, pin_nid);
1573 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
1574 return 0;
1575
1576 if (is_haswell_plus(codec))
1577 intel_haswell_fixup_connect_list(codec, pin_nid);
1578
1579 pin_idx = spec->num_pins;
1580 per_pin = snd_array_new(&spec->pins);
1581 if (!per_pin)
1582 return -ENOMEM;
1583
1584 per_pin->pin_nid = pin_nid;
1585 per_pin->non_pcm = false;
1586 if (spec->dyn_pcm_assign)
1587 per_pin->pcm_idx = -1;
1588 else {
1589 per_pin->pcm = get_hdmi_pcm(spec, pin_idx);
1590 per_pin->pcm_idx = pin_idx;
1591 }
1592 per_pin->pin_nid_idx = pin_idx;
1593
1594 err = hdmi_read_pin_conn(codec, pin_idx);
1595 if (err < 0)
1596 return err;
1597
1598 spec->num_pins++;
1599
1600 return 0;
1601 }
1602
1603 static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1604 {
1605 struct hdmi_spec *spec = codec->spec;
1606 struct hdmi_spec_per_cvt *per_cvt;
1607 unsigned int chans;
1608 int err;
1609
1610 chans = get_wcaps(codec, cvt_nid);
1611 chans = get_wcaps_channels(chans);
1612
1613 per_cvt = snd_array_new(&spec->cvts);
1614 if (!per_cvt)
1615 return -ENOMEM;
1616
1617 per_cvt->cvt_nid = cvt_nid;
1618 per_cvt->channels_min = 2;
1619 if (chans <= 16) {
1620 per_cvt->channels_max = chans;
1621 if (chans > spec->chmap.channels_max)
1622 spec->chmap.channels_max = chans;
1623 }
1624
1625 err = snd_hda_query_supported_pcm(codec, cvt_nid,
1626 &per_cvt->rates,
1627 &per_cvt->formats,
1628 &per_cvt->maxbps);
1629 if (err < 0)
1630 return err;
1631
1632 if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids))
1633 spec->cvt_nids[spec->num_cvts] = cvt_nid;
1634 spec->num_cvts++;
1635
1636 return 0;
1637 }
1638
1639 static int hdmi_parse_codec(struct hda_codec *codec)
1640 {
1641 hda_nid_t nid;
1642 int i, nodes;
1643
1644 nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &nid);
1645 if (!nid || nodes < 0) {
1646 codec_warn(codec, "HDMI: failed to get afg sub nodes\n");
1647 return -EINVAL;
1648 }
1649
1650 for (i = 0; i < nodes; i++, nid++) {
1651 unsigned int caps;
1652 unsigned int type;
1653
1654 caps = get_wcaps(codec, nid);
1655 type = get_wcaps_type(caps);
1656
1657 if (!(caps & AC_WCAP_DIGITAL))
1658 continue;
1659
1660 switch (type) {
1661 case AC_WID_AUD_OUT:
1662 hdmi_add_cvt(codec, nid);
1663 break;
1664 case AC_WID_PIN:
1665 hdmi_add_pin(codec, nid);
1666 break;
1667 }
1668 }
1669
1670 return 0;
1671 }
1672
1673 /*
1674 */
1675 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1676 {
1677 struct hda_spdif_out *spdif;
1678 bool non_pcm;
1679
1680 mutex_lock(&codec->spdif_mutex);
1681 spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
1682 non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO);
1683 mutex_unlock(&codec->spdif_mutex);
1684 return non_pcm;
1685 }
1686
1687 /*
1688 * HDMI callbacks
1689 */
1690
1691 static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1692 struct hda_codec *codec,
1693 unsigned int stream_tag,
1694 unsigned int format,
1695 struct snd_pcm_substream *substream)
1696 {
1697 hda_nid_t cvt_nid = hinfo->nid;
1698 struct hdmi_spec *spec = codec->spec;
1699 int pin_idx;
1700 struct hdmi_spec_per_pin *per_pin;
1701 hda_nid_t pin_nid;
1702 struct snd_pcm_runtime *runtime = substream->runtime;
1703 bool non_pcm;
1704 int pinctl;
1705 int err;
1706
1707 mutex_lock(&spec->pcm_lock);
1708 pin_idx = hinfo_to_pin_index(codec, hinfo);
1709 if (spec->dyn_pcm_assign && pin_idx < 0) {
1710 /* when dyn_pcm_assign and pcm is not bound to a pin
1711 * skip pin setup and return 0 to make audio playback
1712 * be ongoing
1713 */
1714 intel_not_share_assigned_cvt_nid(codec, 0, cvt_nid);
1715 snd_hda_codec_setup_stream(codec, cvt_nid,
1716 stream_tag, 0, format);
1717 mutex_unlock(&spec->pcm_lock);
1718 return 0;
1719 }
1720
1721 if (snd_BUG_ON(pin_idx < 0)) {
1722 mutex_unlock(&spec->pcm_lock);
1723 return -EINVAL;
1724 }
1725 per_pin = get_pin(spec, pin_idx);
1726 pin_nid = per_pin->pin_nid;
1727 if (is_haswell_plus(codec) || is_valleyview_plus(codec)) {
1728 /* Verify pin:cvt selections to avoid silent audio after S3.
1729 * After S3, the audio driver restores pin:cvt selections
1730 * but this can happen before gfx is ready and such selection
1731 * is overlooked by HW. Thus multiple pins can share a same
1732 * default convertor and mute control will affect each other,
1733 * which can cause a resumed audio playback become silent
1734 * after S3.
1735 */
1736 intel_verify_pin_cvt_connect(codec, per_pin);
1737 intel_not_share_assigned_cvt(codec, pin_nid, per_pin->mux_idx);
1738 }
1739
1740 /* Call sync_audio_rate to set the N/CTS/M manually if necessary */
1741 /* Todo: add DP1.2 MST audio support later */
1742 if (codec_has_acomp(codec))
1743 snd_hdac_sync_audio_rate(&codec->bus->core, pin_nid, runtime->rate);
1744
1745 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
1746 mutex_lock(&per_pin->lock);
1747 per_pin->channels = substream->runtime->channels;
1748 per_pin->setup = true;
1749
1750 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
1751 mutex_unlock(&per_pin->lock);
1752 if (spec->dyn_pin_out) {
1753 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
1754 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1755 snd_hda_codec_write(codec, pin_nid, 0,
1756 AC_VERB_SET_PIN_WIDGET_CONTROL,
1757 pinctl | PIN_OUT);
1758 }
1759
1760 err = spec->ops.setup_stream(codec, cvt_nid, pin_nid,
1761 stream_tag, format);
1762 mutex_unlock(&spec->pcm_lock);
1763 return err;
1764 }
1765
1766 static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1767 struct hda_codec *codec,
1768 struct snd_pcm_substream *substream)
1769 {
1770 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
1771 return 0;
1772 }
1773
1774 static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1775 struct hda_codec *codec,
1776 struct snd_pcm_substream *substream)
1777 {
1778 struct hdmi_spec *spec = codec->spec;
1779 int cvt_idx, pin_idx, pcm_idx;
1780 struct hdmi_spec_per_cvt *per_cvt;
1781 struct hdmi_spec_per_pin *per_pin;
1782 int pinctl;
1783
1784 if (hinfo->nid) {
1785 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1786 if (snd_BUG_ON(pcm_idx < 0))
1787 return -EINVAL;
1788 cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid);
1789 if (snd_BUG_ON(cvt_idx < 0))
1790 return -EINVAL;
1791 per_cvt = get_cvt(spec, cvt_idx);
1792
1793 snd_BUG_ON(!per_cvt->assigned);
1794 per_cvt->assigned = 0;
1795 hinfo->nid = 0;
1796
1797 mutex_lock(&spec->pcm_lock);
1798 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
1799 clear_bit(pcm_idx, &spec->pcm_in_use);
1800 pin_idx = hinfo_to_pin_index(codec, hinfo);
1801 if (spec->dyn_pcm_assign && pin_idx < 0) {
1802 mutex_unlock(&spec->pcm_lock);
1803 return 0;
1804 }
1805
1806 if (snd_BUG_ON(pin_idx < 0)) {
1807 mutex_unlock(&spec->pcm_lock);
1808 return -EINVAL;
1809 }
1810 per_pin = get_pin(spec, pin_idx);
1811
1812 if (spec->dyn_pin_out) {
1813 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
1814 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1815 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
1816 AC_VERB_SET_PIN_WIDGET_CONTROL,
1817 pinctl & ~PIN_OUT);
1818 }
1819
1820 mutex_lock(&per_pin->lock);
1821 per_pin->chmap_set = false;
1822 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
1823
1824 per_pin->setup = false;
1825 per_pin->channels = 0;
1826 mutex_unlock(&per_pin->lock);
1827 mutex_unlock(&spec->pcm_lock);
1828 }
1829
1830 return 0;
1831 }
1832
1833 static const struct hda_pcm_ops generic_ops = {
1834 .open = hdmi_pcm_open,
1835 .close = hdmi_pcm_close,
1836 .prepare = generic_hdmi_playback_pcm_prepare,
1837 .cleanup = generic_hdmi_playback_pcm_cleanup,
1838 };
1839
1840 static void hdmi_get_chmap(struct hdac_device *hdac, int pcm_idx,
1841 unsigned char *chmap)
1842 {
1843 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
1844 struct hdmi_spec *spec = codec->spec;
1845 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
1846
1847 /* chmap is already set to 0 in caller */
1848 if (!per_pin)
1849 return;
1850
1851 memcpy(chmap, per_pin->chmap, ARRAY_SIZE(per_pin->chmap));
1852 }
1853
1854 static void hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx,
1855 unsigned char *chmap, int prepared)
1856 {
1857 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
1858 struct hdmi_spec *spec = codec->spec;
1859 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
1860
1861 if (!per_pin)
1862 return;
1863 mutex_lock(&per_pin->lock);
1864 per_pin->chmap_set = true;
1865 memcpy(per_pin->chmap, chmap, ARRAY_SIZE(per_pin->chmap));
1866 if (prepared)
1867 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1868 mutex_unlock(&per_pin->lock);
1869 }
1870
1871 static bool is_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx)
1872 {
1873 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
1874 struct hdmi_spec *spec = codec->spec;
1875 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
1876
1877 return per_pin ? true:false;
1878 }
1879
1880 static int generic_hdmi_build_pcms(struct hda_codec *codec)
1881 {
1882 struct hdmi_spec *spec = codec->spec;
1883 int pin_idx;
1884
1885 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1886 struct hda_pcm *info;
1887 struct hda_pcm_stream *pstr;
1888
1889 info = snd_hda_codec_pcm_new(codec, "HDMI %d", pin_idx);
1890 if (!info)
1891 return -ENOMEM;
1892
1893 spec->pcm_rec[pin_idx].pcm = info;
1894 spec->pcm_used++;
1895 info->pcm_type = HDA_PCM_TYPE_HDMI;
1896 info->own_chmap = true;
1897
1898 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
1899 pstr->substreams = 1;
1900 pstr->ops = generic_ops;
1901 /* other pstr fields are set in open */
1902 }
1903
1904 return 0;
1905 }
1906
1907 static void free_hdmi_jack_priv(struct snd_jack *jack)
1908 {
1909 struct hdmi_pcm *pcm = jack->private_data;
1910
1911 pcm->jack = NULL;
1912 }
1913
1914 static int add_hdmi_jack_kctl(struct hda_codec *codec,
1915 struct hdmi_spec *spec,
1916 int pcm_idx,
1917 const char *name)
1918 {
1919 struct snd_jack *jack;
1920 int err;
1921
1922 err = snd_jack_new(codec->card, name, SND_JACK_AVOUT, &jack,
1923 true, false);
1924 if (err < 0)
1925 return err;
1926
1927 spec->pcm_rec[pcm_idx].jack = jack;
1928 jack->private_data = &spec->pcm_rec[pcm_idx];
1929 jack->private_free = free_hdmi_jack_priv;
1930 return 0;
1931 }
1932
1933 static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx)
1934 {
1935 char hdmi_str[32] = "HDMI/DP";
1936 struct hdmi_spec *spec = codec->spec;
1937 struct hdmi_spec_per_pin *per_pin;
1938 struct hda_jack_tbl *jack;
1939 int pcmdev = get_pcm_rec(spec, pcm_idx)->device;
1940 bool phantom_jack;
1941 int ret;
1942
1943 if (pcmdev > 0)
1944 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
1945
1946 if (spec->dyn_pcm_assign)
1947 return add_hdmi_jack_kctl(codec, spec, pcm_idx, hdmi_str);
1948
1949 /* for !dyn_pcm_assign, we still use hda_jack for compatibility */
1950 /* if !dyn_pcm_assign, it must be non-MST mode.
1951 * This means pcms and pins are statically mapped.
1952 * And pcm_idx is pin_idx.
1953 */
1954 per_pin = get_pin(spec, pcm_idx);
1955 phantom_jack = !is_jack_detectable(codec, per_pin->pin_nid);
1956 if (phantom_jack)
1957 strncat(hdmi_str, " Phantom",
1958 sizeof(hdmi_str) - strlen(hdmi_str) - 1);
1959 ret = snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str,
1960 phantom_jack);
1961 if (ret < 0)
1962 return ret;
1963 jack = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
1964 if (jack == NULL)
1965 return 0;
1966 /* assign jack->jack to pcm_rec[].jack to
1967 * align with dyn_pcm_assign mode
1968 */
1969 spec->pcm_rec[pcm_idx].jack = jack->jack;
1970 return 0;
1971 }
1972
1973 static int generic_hdmi_build_controls(struct hda_codec *codec)
1974 {
1975 struct hdmi_spec *spec = codec->spec;
1976 int err;
1977 int pin_idx, pcm_idx;
1978
1979
1980 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
1981 err = generic_hdmi_build_jack(codec, pcm_idx);
1982 if (err < 0)
1983 return err;
1984
1985 /* create the spdif for each pcm
1986 * pin will be bound when monitor is connected
1987 */
1988 if (spec->dyn_pcm_assign)
1989 err = snd_hda_create_dig_out_ctls(codec,
1990 0, spec->cvt_nids[0],
1991 HDA_PCM_TYPE_HDMI);
1992 else {
1993 struct hdmi_spec_per_pin *per_pin =
1994 get_pin(spec, pcm_idx);
1995 err = snd_hda_create_dig_out_ctls(codec,
1996 per_pin->pin_nid,
1997 per_pin->mux_nids[0],
1998 HDA_PCM_TYPE_HDMI);
1999 }
2000 if (err < 0)
2001 return err;
2002 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
2003
2004 /* add control for ELD Bytes */
2005 err = hdmi_create_eld_ctl(codec, pcm_idx,
2006 get_pcm_rec(spec, pcm_idx)->device);
2007 if (err < 0)
2008 return err;
2009 }
2010
2011 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2012 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2013
2014 hdmi_present_sense(per_pin, 0);
2015 }
2016
2017 /* add channel maps */
2018 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2019 struct hda_pcm *pcm;
2020
2021 pcm = get_pcm_rec(spec, pcm_idx);
2022 if (!pcm || !pcm->pcm)
2023 break;
2024 err = snd_hdac_add_chmap_ctls(pcm->pcm, pcm_idx, &spec->chmap);
2025 if (err < 0)
2026 return err;
2027 }
2028
2029 return 0;
2030 }
2031
2032 static int generic_hdmi_init_per_pins(struct hda_codec *codec)
2033 {
2034 struct hdmi_spec *spec = codec->spec;
2035 int pin_idx;
2036
2037 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2038 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2039
2040 per_pin->codec = codec;
2041 mutex_init(&per_pin->lock);
2042 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
2043 eld_proc_new(per_pin, pin_idx);
2044 }
2045 return 0;
2046 }
2047
2048 static int generic_hdmi_init(struct hda_codec *codec)
2049 {
2050 struct hdmi_spec *spec = codec->spec;
2051 int pin_idx;
2052
2053 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2054 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2055 hda_nid_t pin_nid = per_pin->pin_nid;
2056
2057 hdmi_init_pin(codec, pin_nid);
2058 if (!codec_has_acomp(codec))
2059 snd_hda_jack_detect_enable_callback(codec, pin_nid,
2060 codec->jackpoll_interval > 0 ?
2061 jack_callback : NULL);
2062 }
2063 return 0;
2064 }
2065
2066 static void hdmi_array_init(struct hdmi_spec *spec, int nums)
2067 {
2068 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums);
2069 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums);
2070 }
2071
2072 static void hdmi_array_free(struct hdmi_spec *spec)
2073 {
2074 snd_array_free(&spec->pins);
2075 snd_array_free(&spec->cvts);
2076 }
2077
2078 static void generic_hdmi_free(struct hda_codec *codec)
2079 {
2080 struct hdmi_spec *spec = codec->spec;
2081 int pin_idx, pcm_idx;
2082
2083 if (codec_has_acomp(codec))
2084 snd_hdac_i915_register_notifier(NULL);
2085
2086 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2087 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2088 cancel_delayed_work_sync(&per_pin->work);
2089 eld_proc_free(per_pin);
2090 }
2091
2092 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2093 if (spec->pcm_rec[pcm_idx].jack == NULL)
2094 continue;
2095 if (spec->dyn_pcm_assign)
2096 snd_device_free(codec->card,
2097 spec->pcm_rec[pcm_idx].jack);
2098 else
2099 spec->pcm_rec[pcm_idx].jack = NULL;
2100 }
2101
2102 if (spec->i915_bound)
2103 snd_hdac_i915_exit(&codec->bus->core);
2104 hdmi_array_free(spec);
2105 kfree(spec);
2106 }
2107
2108 #ifdef CONFIG_PM
2109 static int generic_hdmi_resume(struct hda_codec *codec)
2110 {
2111 struct hdmi_spec *spec = codec->spec;
2112 int pin_idx;
2113
2114 codec->patch_ops.init(codec);
2115 regcache_sync(codec->core.regmap);
2116
2117 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2118 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2119 hdmi_present_sense(per_pin, 1);
2120 }
2121 return 0;
2122 }
2123 #endif
2124
2125 static const struct hda_codec_ops generic_hdmi_patch_ops = {
2126 .init = generic_hdmi_init,
2127 .free = generic_hdmi_free,
2128 .build_pcms = generic_hdmi_build_pcms,
2129 .build_controls = generic_hdmi_build_controls,
2130 .unsol_event = hdmi_unsol_event,
2131 #ifdef CONFIG_PM
2132 .resume = generic_hdmi_resume,
2133 #endif
2134 };
2135
2136 static const struct hdmi_ops generic_standard_hdmi_ops = {
2137 .pin_get_eld = snd_hdmi_get_eld,
2138 .pin_setup_infoframe = hdmi_pin_setup_infoframe,
2139 .pin_hbr_setup = hdmi_pin_hbr_setup,
2140 .setup_stream = hdmi_setup_stream,
2141 };
2142
2143 static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
2144 hda_nid_t nid)
2145 {
2146 struct hdmi_spec *spec = codec->spec;
2147 hda_nid_t conns[4];
2148 int nconns;
2149
2150 nconns = snd_hda_get_connections(codec, nid, conns, ARRAY_SIZE(conns));
2151 if (nconns == spec->num_cvts &&
2152 !memcmp(conns, spec->cvt_nids, spec->num_cvts * sizeof(hda_nid_t)))
2153 return;
2154
2155 /* override pins connection list */
2156 codec_dbg(codec, "hdmi: haswell: override pin connection 0x%x\n", nid);
2157 snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids);
2158 }
2159
2160 #define INTEL_VENDOR_NID 0x08
2161 #define INTEL_GET_VENDOR_VERB 0xf81
2162 #define INTEL_SET_VENDOR_VERB 0x781
2163 #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
2164 #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
2165
2166 static void intel_haswell_enable_all_pins(struct hda_codec *codec,
2167 bool update_tree)
2168 {
2169 unsigned int vendor_param;
2170
2171 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
2172 INTEL_GET_VENDOR_VERB, 0);
2173 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
2174 return;
2175
2176 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
2177 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
2178 INTEL_SET_VENDOR_VERB, vendor_param);
2179 if (vendor_param == -1)
2180 return;
2181
2182 if (update_tree)
2183 snd_hda_codec_update_widgets(codec);
2184 }
2185
2186 static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
2187 {
2188 unsigned int vendor_param;
2189
2190 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
2191 INTEL_GET_VENDOR_VERB, 0);
2192 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
2193 return;
2194
2195 /* enable DP1.2 mode */
2196 vendor_param |= INTEL_EN_DP12;
2197 snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB);
2198 snd_hda_codec_write_cache(codec, INTEL_VENDOR_NID, 0,
2199 INTEL_SET_VENDOR_VERB, vendor_param);
2200 }
2201
2202 /* Haswell needs to re-issue the vendor-specific verbs before turning to D0.
2203 * Otherwise you may get severe h/w communication errors.
2204 */
2205 static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2206 unsigned int power_state)
2207 {
2208 if (power_state == AC_PWRST_D0) {
2209 intel_haswell_enable_all_pins(codec, false);
2210 intel_haswell_fixup_enable_dp12(codec);
2211 }
2212
2213 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
2214 snd_hda_codec_set_power_to_all(codec, fg, power_state);
2215 }
2216
2217 static void intel_pin_eld_notify(void *audio_ptr, int port)
2218 {
2219 struct hda_codec *codec = audio_ptr;
2220 int pin_nid = port + 0x04;
2221
2222 /* we assume only from port-B to port-D */
2223 if (port < 1 || port > 3)
2224 return;
2225
2226 /* skip notification during system suspend (but not in runtime PM);
2227 * the state will be updated at resume
2228 */
2229 if (snd_power_get_state(codec->card) != SNDRV_CTL_POWER_D0)
2230 return;
2231 /* ditto during suspend/resume process itself */
2232 if (atomic_read(&(codec)->core.in_pm))
2233 return;
2234
2235 check_presence_and_report(codec, pin_nid);
2236 }
2237
2238 static int patch_generic_hdmi(struct hda_codec *codec)
2239 {
2240 struct hdmi_spec *spec;
2241
2242 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2243 if (spec == NULL)
2244 return -ENOMEM;
2245
2246 spec->ops = generic_standard_hdmi_ops;
2247 mutex_init(&spec->pcm_lock);
2248 snd_hdac_register_chmap_ops(&codec->core, &spec->chmap);
2249
2250 spec->chmap.ops.get_chmap = hdmi_get_chmap;
2251 spec->chmap.ops.set_chmap = hdmi_set_chmap;
2252 spec->chmap.ops.is_pcm_attached = is_hdmi_pcm_attached;
2253
2254 codec->spec = spec;
2255 hdmi_array_init(spec, 4);
2256
2257 #ifdef CONFIG_SND_HDA_I915
2258 /* Try to bind with i915 for Intel HSW+ codecs (if not done yet) */
2259 if ((codec->core.vendor_id >> 16) == 0x8086 &&
2260 is_haswell_plus(codec)) {
2261 #if 0
2262 /* on-demand binding leads to an unbalanced refcount when
2263 * both i915 and hda drivers are probed concurrently;
2264 * disabled temporarily for now
2265 */
2266 if (!codec->bus->core.audio_component)
2267 if (!snd_hdac_i915_init(&codec->bus->core))
2268 spec->i915_bound = true;
2269 #endif
2270 /* use i915 audio component notifier for hotplug */
2271 if (codec->bus->core.audio_component)
2272 spec->use_acomp_notifier = true;
2273 }
2274 #endif
2275
2276 if (is_haswell_plus(codec)) {
2277 intel_haswell_enable_all_pins(codec, true);
2278 intel_haswell_fixup_enable_dp12(codec);
2279 }
2280
2281 /* For Valleyview/Cherryview, only the display codec is in the display
2282 * power well and can use link_power ops to request/release the power.
2283 * For Haswell/Broadwell, the controller is also in the power well and
2284 * can cover the codec power request, and so need not set this flag.
2285 * For previous platforms, there is no such power well feature.
2286 */
2287 if (is_valleyview_plus(codec) || is_skylake(codec) ||
2288 is_broxton(codec))
2289 codec->core.link_power_control = 1;
2290
2291 if (hdmi_parse_codec(codec) < 0) {
2292 if (spec->i915_bound)
2293 snd_hdac_i915_exit(&codec->bus->core);
2294 codec->spec = NULL;
2295 kfree(spec);
2296 return -EINVAL;
2297 }
2298 codec->patch_ops = generic_hdmi_patch_ops;
2299 if (is_haswell_plus(codec)) {
2300 codec->patch_ops.set_power_state = haswell_set_power_state;
2301 codec->dp_mst = true;
2302 }
2303
2304 /* Enable runtime pm for HDMI audio codec of HSW/BDW/SKL/BYT/BSW */
2305 if (is_haswell_plus(codec) || is_valleyview_plus(codec))
2306 codec->auto_runtime_pm = 1;
2307
2308 generic_hdmi_init_per_pins(codec);
2309
2310
2311 if (codec_has_acomp(codec)) {
2312 codec->depop_delay = 0;
2313 spec->i915_audio_ops.audio_ptr = codec;
2314 /* intel_audio_codec_enable() or intel_audio_codec_disable()
2315 * will call pin_eld_notify with using audio_ptr pointer
2316 * We need make sure audio_ptr is really setup
2317 */
2318 wmb();
2319 spec->i915_audio_ops.pin_eld_notify = intel_pin_eld_notify;
2320 snd_hdac_i915_register_notifier(&spec->i915_audio_ops);
2321 }
2322
2323 WARN_ON(spec->dyn_pcm_assign && !codec_has_acomp(codec));
2324 return 0;
2325 }
2326
2327 /*
2328 * Shared non-generic implementations
2329 */
2330
2331 static int simple_playback_build_pcms(struct hda_codec *codec)
2332 {
2333 struct hdmi_spec *spec = codec->spec;
2334 struct hda_pcm *info;
2335 unsigned int chans;
2336 struct hda_pcm_stream *pstr;
2337 struct hdmi_spec_per_cvt *per_cvt;
2338
2339 per_cvt = get_cvt(spec, 0);
2340 chans = get_wcaps(codec, per_cvt->cvt_nid);
2341 chans = get_wcaps_channels(chans);
2342
2343 info = snd_hda_codec_pcm_new(codec, "HDMI 0");
2344 if (!info)
2345 return -ENOMEM;
2346 spec->pcm_rec[0].pcm = info;
2347 info->pcm_type = HDA_PCM_TYPE_HDMI;
2348 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
2349 *pstr = spec->pcm_playback;
2350 pstr->nid = per_cvt->cvt_nid;
2351 if (pstr->channels_max <= 2 && chans && chans <= 16)
2352 pstr->channels_max = chans;
2353
2354 return 0;
2355 }
2356
2357 /* unsolicited event for jack sensing */
2358 static void simple_hdmi_unsol_event(struct hda_codec *codec,
2359 unsigned int res)
2360 {
2361 snd_hda_jack_set_dirty_all(codec);
2362 snd_hda_jack_report_sync(codec);
2363 }
2364
2365 /* generic_hdmi_build_jack can be used for simple_hdmi, too,
2366 * as long as spec->pins[] is set correctly
2367 */
2368 #define simple_hdmi_build_jack generic_hdmi_build_jack
2369
2370 static int simple_playback_build_controls(struct hda_codec *codec)
2371 {
2372 struct hdmi_spec *spec = codec->spec;
2373 struct hdmi_spec_per_cvt *per_cvt;
2374 int err;
2375
2376 per_cvt = get_cvt(spec, 0);
2377 err = snd_hda_create_dig_out_ctls(codec, per_cvt->cvt_nid,
2378 per_cvt->cvt_nid,
2379 HDA_PCM_TYPE_HDMI);
2380 if (err < 0)
2381 return err;
2382 return simple_hdmi_build_jack(codec, 0);
2383 }
2384
2385 static int simple_playback_init(struct hda_codec *codec)
2386 {
2387 struct hdmi_spec *spec = codec->spec;
2388 struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0);
2389 hda_nid_t pin = per_pin->pin_nid;
2390
2391 snd_hda_codec_write(codec, pin, 0,
2392 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
2393 /* some codecs require to unmute the pin */
2394 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
2395 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2396 AMP_OUT_UNMUTE);
2397 snd_hda_jack_detect_enable(codec, pin);
2398 return 0;
2399 }
2400
2401 static void simple_playback_free(struct hda_codec *codec)
2402 {
2403 struct hdmi_spec *spec = codec->spec;
2404
2405 hdmi_array_free(spec);
2406 kfree(spec);
2407 }
2408
2409 /*
2410 * Nvidia specific implementations
2411 */
2412
2413 #define Nv_VERB_SET_Channel_Allocation 0xF79
2414 #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
2415 #define Nv_VERB_SET_Audio_Protection_On 0xF98
2416 #define Nv_VERB_SET_Audio_Protection_Off 0xF99
2417
2418 #define nvhdmi_master_con_nid_7x 0x04
2419 #define nvhdmi_master_pin_nid_7x 0x05
2420
2421 static const hda_nid_t nvhdmi_con_nids_7x[4] = {
2422 /*front, rear, clfe, rear_surr */
2423 0x6, 0x8, 0xa, 0xc,
2424 };
2425
2426 static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = {
2427 /* set audio protect on */
2428 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
2429 /* enable digital output on pin widget */
2430 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2431 {} /* terminator */
2432 };
2433
2434 static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = {
2435 /* set audio protect on */
2436 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
2437 /* enable digital output on pin widget */
2438 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2439 { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2440 { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2441 { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2442 { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2443 {} /* terminator */
2444 };
2445
2446 #ifdef LIMITED_RATE_FMT_SUPPORT
2447 /* support only the safe format and rate */
2448 #define SUPPORTED_RATES SNDRV_PCM_RATE_48000
2449 #define SUPPORTED_MAXBPS 16
2450 #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
2451 #else
2452 /* support all rates and formats */
2453 #define SUPPORTED_RATES \
2454 (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
2455 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
2456 SNDRV_PCM_RATE_192000)
2457 #define SUPPORTED_MAXBPS 24
2458 #define SUPPORTED_FORMATS \
2459 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
2460 #endif
2461
2462 static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
2463 {
2464 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
2465 return 0;
2466 }
2467
2468 static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
2469 {
2470 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
2471 return 0;
2472 }
2473
2474 static unsigned int channels_2_6_8[] = {
2475 2, 6, 8
2476 };
2477
2478 static unsigned int channels_2_8[] = {
2479 2, 8
2480 };
2481
2482 static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
2483 .count = ARRAY_SIZE(channels_2_6_8),
2484 .list = channels_2_6_8,
2485 .mask = 0,
2486 };
2487
2488 static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
2489 .count = ARRAY_SIZE(channels_2_8),
2490 .list = channels_2_8,
2491 .mask = 0,
2492 };
2493
2494 static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
2495 struct hda_codec *codec,
2496 struct snd_pcm_substream *substream)
2497 {
2498 struct hdmi_spec *spec = codec->spec;
2499 struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
2500
2501 switch (codec->preset->vendor_id) {
2502 case 0x10de0002:
2503 case 0x10de0003:
2504 case 0x10de0005:
2505 case 0x10de0006:
2506 hw_constraints_channels = &hw_constraints_2_8_channels;
2507 break;
2508 case 0x10de0007:
2509 hw_constraints_channels = &hw_constraints_2_6_8_channels;
2510 break;
2511 default:
2512 break;
2513 }
2514
2515 if (hw_constraints_channels != NULL) {
2516 snd_pcm_hw_constraint_list(substream->runtime, 0,
2517 SNDRV_PCM_HW_PARAM_CHANNELS,
2518 hw_constraints_channels);
2519 } else {
2520 snd_pcm_hw_constraint_step(substream->runtime, 0,
2521 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
2522 }
2523
2524 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2525 }
2526
2527 static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
2528 struct hda_codec *codec,
2529 struct snd_pcm_substream *substream)
2530 {
2531 struct hdmi_spec *spec = codec->spec;
2532 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2533 }
2534
2535 static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2536 struct hda_codec *codec,
2537 unsigned int stream_tag,
2538 unsigned int format,
2539 struct snd_pcm_substream *substream)
2540 {
2541 struct hdmi_spec *spec = codec->spec;
2542 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2543 stream_tag, format, substream);
2544 }
2545
2546 static const struct hda_pcm_stream simple_pcm_playback = {
2547 .substreams = 1,
2548 .channels_min = 2,
2549 .channels_max = 2,
2550 .ops = {
2551 .open = simple_playback_pcm_open,
2552 .close = simple_playback_pcm_close,
2553 .prepare = simple_playback_pcm_prepare
2554 },
2555 };
2556
2557 static const struct hda_codec_ops simple_hdmi_patch_ops = {
2558 .build_controls = simple_playback_build_controls,
2559 .build_pcms = simple_playback_build_pcms,
2560 .init = simple_playback_init,
2561 .free = simple_playback_free,
2562 .unsol_event = simple_hdmi_unsol_event,
2563 };
2564
2565 static int patch_simple_hdmi(struct hda_codec *codec,
2566 hda_nid_t cvt_nid, hda_nid_t pin_nid)
2567 {
2568 struct hdmi_spec *spec;
2569 struct hdmi_spec_per_cvt *per_cvt;
2570 struct hdmi_spec_per_pin *per_pin;
2571
2572 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2573 if (!spec)
2574 return -ENOMEM;
2575
2576 codec->spec = spec;
2577 hdmi_array_init(spec, 1);
2578
2579 spec->multiout.num_dacs = 0; /* no analog */
2580 spec->multiout.max_channels = 2;
2581 spec->multiout.dig_out_nid = cvt_nid;
2582 spec->num_cvts = 1;
2583 spec->num_pins = 1;
2584 per_pin = snd_array_new(&spec->pins);
2585 per_cvt = snd_array_new(&spec->cvts);
2586 if (!per_pin || !per_cvt) {
2587 simple_playback_free(codec);
2588 return -ENOMEM;
2589 }
2590 per_cvt->cvt_nid = cvt_nid;
2591 per_pin->pin_nid = pin_nid;
2592 spec->pcm_playback = simple_pcm_playback;
2593
2594 codec->patch_ops = simple_hdmi_patch_ops;
2595
2596 return 0;
2597 }
2598
2599 static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
2600 int channels)
2601 {
2602 unsigned int chanmask;
2603 int chan = channels ? (channels - 1) : 1;
2604
2605 switch (channels) {
2606 default:
2607 case 0:
2608 case 2:
2609 chanmask = 0x00;
2610 break;
2611 case 4:
2612 chanmask = 0x08;
2613 break;
2614 case 6:
2615 chanmask = 0x0b;
2616 break;
2617 case 8:
2618 chanmask = 0x13;
2619 break;
2620 }
2621
2622 /* Set the audio infoframe channel allocation and checksum fields. The
2623 * channel count is computed implicitly by the hardware. */
2624 snd_hda_codec_write(codec, 0x1, 0,
2625 Nv_VERB_SET_Channel_Allocation, chanmask);
2626
2627 snd_hda_codec_write(codec, 0x1, 0,
2628 Nv_VERB_SET_Info_Frame_Checksum,
2629 (0x71 - chan - chanmask));
2630 }
2631
2632 static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
2633 struct hda_codec *codec,
2634 struct snd_pcm_substream *substream)
2635 {
2636 struct hdmi_spec *spec = codec->spec;
2637 int i;
2638
2639 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
2640 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
2641 for (i = 0; i < 4; i++) {
2642 /* set the stream id */
2643 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
2644 AC_VERB_SET_CHANNEL_STREAMID, 0);
2645 /* set the stream format */
2646 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
2647 AC_VERB_SET_STREAM_FORMAT, 0);
2648 }
2649
2650 /* The audio hardware sends a channel count of 0x7 (8ch) when all the
2651 * streams are disabled. */
2652 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
2653
2654 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2655 }
2656
2657 static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
2658 struct hda_codec *codec,
2659 unsigned int stream_tag,
2660 unsigned int format,
2661 struct snd_pcm_substream *substream)
2662 {
2663 int chs;
2664 unsigned int dataDCC2, channel_id;
2665 int i;
2666 struct hdmi_spec *spec = codec->spec;
2667 struct hda_spdif_out *spdif;
2668 struct hdmi_spec_per_cvt *per_cvt;
2669
2670 mutex_lock(&codec->spdif_mutex);
2671 per_cvt = get_cvt(spec, 0);
2672 spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid);
2673
2674 chs = substream->runtime->channels;
2675
2676 dataDCC2 = 0x2;
2677
2678 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
2679 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
2680 snd_hda_codec_write(codec,
2681 nvhdmi_master_con_nid_7x,
2682 0,
2683 AC_VERB_SET_DIGI_CONVERT_1,
2684 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
2685
2686 /* set the stream id */
2687 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
2688 AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
2689
2690 /* set the stream format */
2691 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
2692 AC_VERB_SET_STREAM_FORMAT, format);
2693
2694 /* turn on again (if needed) */
2695 /* enable and set the channel status audio/data flag */
2696 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
2697 snd_hda_codec_write(codec,
2698 nvhdmi_master_con_nid_7x,
2699 0,
2700 AC_VERB_SET_DIGI_CONVERT_1,
2701 spdif->ctls & 0xff);
2702 snd_hda_codec_write(codec,
2703 nvhdmi_master_con_nid_7x,
2704 0,
2705 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
2706 }
2707
2708 for (i = 0; i < 4; i++) {
2709 if (chs == 2)
2710 channel_id = 0;
2711 else
2712 channel_id = i * 2;
2713
2714 /* turn off SPDIF once;
2715 *otherwise the IEC958 bits won't be updated
2716 */
2717 if (codec->spdif_status_reset &&
2718 (spdif->ctls & AC_DIG1_ENABLE))
2719 snd_hda_codec_write(codec,
2720 nvhdmi_con_nids_7x[i],
2721 0,
2722 AC_VERB_SET_DIGI_CONVERT_1,
2723 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
2724 /* set the stream id */
2725 snd_hda_codec_write(codec,
2726 nvhdmi_con_nids_7x[i],
2727 0,
2728 AC_VERB_SET_CHANNEL_STREAMID,
2729 (stream_tag << 4) | channel_id);
2730 /* set the stream format */
2731 snd_hda_codec_write(codec,
2732 nvhdmi_con_nids_7x[i],
2733 0,
2734 AC_VERB_SET_STREAM_FORMAT,
2735 format);
2736 /* turn on again (if needed) */
2737 /* enable and set the channel status audio/data flag */
2738 if (codec->spdif_status_reset &&
2739 (spdif->ctls & AC_DIG1_ENABLE)) {
2740 snd_hda_codec_write(codec,
2741 nvhdmi_con_nids_7x[i],
2742 0,
2743 AC_VERB_SET_DIGI_CONVERT_1,
2744 spdif->ctls & 0xff);
2745 snd_hda_codec_write(codec,
2746 nvhdmi_con_nids_7x[i],
2747 0,
2748 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
2749 }
2750 }
2751
2752 nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
2753
2754 mutex_unlock(&codec->spdif_mutex);
2755 return 0;
2756 }
2757
2758 static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
2759 .substreams = 1,
2760 .channels_min = 2,
2761 .channels_max = 8,
2762 .nid = nvhdmi_master_con_nid_7x,
2763 .rates = SUPPORTED_RATES,
2764 .maxbps = SUPPORTED_MAXBPS,
2765 .formats = SUPPORTED_FORMATS,
2766 .ops = {
2767 .open = simple_playback_pcm_open,
2768 .close = nvhdmi_8ch_7x_pcm_close,
2769 .prepare = nvhdmi_8ch_7x_pcm_prepare
2770 },
2771 };
2772
2773 static int patch_nvhdmi_2ch(struct hda_codec *codec)
2774 {
2775 struct hdmi_spec *spec;
2776 int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
2777 nvhdmi_master_pin_nid_7x);
2778 if (err < 0)
2779 return err;
2780
2781 codec->patch_ops.init = nvhdmi_7x_init_2ch;
2782 /* override the PCM rates, etc, as the codec doesn't give full list */
2783 spec = codec->spec;
2784 spec->pcm_playback.rates = SUPPORTED_RATES;
2785 spec->pcm_playback.maxbps = SUPPORTED_MAXBPS;
2786 spec->pcm_playback.formats = SUPPORTED_FORMATS;
2787 return 0;
2788 }
2789
2790 static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
2791 {
2792 struct hdmi_spec *spec = codec->spec;
2793 int err = simple_playback_build_pcms(codec);
2794 if (!err) {
2795 struct hda_pcm *info = get_pcm_rec(spec, 0);
2796 info->own_chmap = true;
2797 }
2798 return err;
2799 }
2800
2801 static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
2802 {
2803 struct hdmi_spec *spec = codec->spec;
2804 struct hda_pcm *info;
2805 struct snd_pcm_chmap *chmap;
2806 int err;
2807
2808 err = simple_playback_build_controls(codec);
2809 if (err < 0)
2810 return err;
2811
2812 /* add channel maps */
2813 info = get_pcm_rec(spec, 0);
2814 err = snd_pcm_add_chmap_ctls(info->pcm,
2815 SNDRV_PCM_STREAM_PLAYBACK,
2816 snd_pcm_alt_chmaps, 8, 0, &chmap);
2817 if (err < 0)
2818 return err;
2819 switch (codec->preset->vendor_id) {
2820 case 0x10de0002:
2821 case 0x10de0003:
2822 case 0x10de0005:
2823 case 0x10de0006:
2824 chmap->channel_mask = (1U << 2) | (1U << 8);
2825 break;
2826 case 0x10de0007:
2827 chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8);
2828 }
2829 return 0;
2830 }
2831
2832 static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
2833 {
2834 struct hdmi_spec *spec;
2835 int err = patch_nvhdmi_2ch(codec);
2836 if (err < 0)
2837 return err;
2838 spec = codec->spec;
2839 spec->multiout.max_channels = 8;
2840 spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x;
2841 codec->patch_ops.init = nvhdmi_7x_init_8ch;
2842 codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
2843 codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
2844
2845 /* Initialize the audio infoframe channel mask and checksum to something
2846 * valid */
2847 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
2848
2849 return 0;
2850 }
2851
2852 /*
2853 * NVIDIA codecs ignore ASP mapping for 2ch - confirmed on:
2854 * - 0x10de0015
2855 * - 0x10de0040
2856 */
2857 static int nvhdmi_chmap_cea_alloc_validate_get_type(struct hdac_chmap *chmap,
2858 struct hdac_cea_channel_speaker_allocation *cap, int channels)
2859 {
2860 if (cap->ca_index == 0x00 && channels == 2)
2861 return SNDRV_CTL_TLVT_CHMAP_FIXED;
2862
2863 /* If the speaker allocation matches the channel count, it is OK. */
2864 if (cap->channels != channels)
2865 return -1;
2866
2867 /* all channels are remappable freely */
2868 return SNDRV_CTL_TLVT_CHMAP_VAR;
2869 }
2870
2871 static int nvhdmi_chmap_validate(struct hdac_chmap *chmap,
2872 int ca, int chs, unsigned char *map)
2873 {
2874 if (ca == 0x00 && (map[0] != SNDRV_CHMAP_FL || map[1] != SNDRV_CHMAP_FR))
2875 return -EINVAL;
2876
2877 return 0;
2878 }
2879
2880 static int patch_nvhdmi(struct hda_codec *codec)
2881 {
2882 struct hdmi_spec *spec;
2883 int err;
2884
2885 err = patch_generic_hdmi(codec);
2886 if (err)
2887 return err;
2888
2889 spec = codec->spec;
2890 spec->dyn_pin_out = true;
2891
2892 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
2893 nvhdmi_chmap_cea_alloc_validate_get_type;
2894 spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate;
2895
2896 return 0;
2897 }
2898
2899 /*
2900 * The HDA codec on NVIDIA Tegra contains two scratch registers that are
2901 * accessed using vendor-defined verbs. These registers can be used for
2902 * interoperability between the HDA and HDMI drivers.
2903 */
2904
2905 /* Audio Function Group node */
2906 #define NVIDIA_AFG_NID 0x01
2907
2908 /*
2909 * The SCRATCH0 register is used to notify the HDMI codec of changes in audio
2910 * format. On Tegra, bit 31 is used as a trigger that causes an interrupt to
2911 * be raised in the HDMI codec. The remainder of the bits is arbitrary. This
2912 * implementation stores the HDA format (see AC_FMT_*) in bits [15:0] and an
2913 * additional bit (at position 30) to signal the validity of the format.
2914 *
2915 * | 31 | 30 | 29 16 | 15 0 |
2916 * +---------+-------+--------+--------+
2917 * | TRIGGER | VALID | UNUSED | FORMAT |
2918 * +-----------------------------------|
2919 *
2920 * Note that for the trigger bit to take effect it needs to change value
2921 * (i.e. it needs to be toggled).
2922 */
2923 #define NVIDIA_GET_SCRATCH0 0xfa6
2924 #define NVIDIA_SET_SCRATCH0_BYTE0 0xfa7
2925 #define NVIDIA_SET_SCRATCH0_BYTE1 0xfa8
2926 #define NVIDIA_SET_SCRATCH0_BYTE2 0xfa9
2927 #define NVIDIA_SET_SCRATCH0_BYTE3 0xfaa
2928 #define NVIDIA_SCRATCH_TRIGGER (1 << 7)
2929 #define NVIDIA_SCRATCH_VALID (1 << 6)
2930
2931 #define NVIDIA_GET_SCRATCH1 0xfab
2932 #define NVIDIA_SET_SCRATCH1_BYTE0 0xfac
2933 #define NVIDIA_SET_SCRATCH1_BYTE1 0xfad
2934 #define NVIDIA_SET_SCRATCH1_BYTE2 0xfae
2935 #define NVIDIA_SET_SCRATCH1_BYTE3 0xfaf
2936
2937 /*
2938 * The format parameter is the HDA audio format (see AC_FMT_*). If set to 0,
2939 * the format is invalidated so that the HDMI codec can be disabled.
2940 */
2941 static void tegra_hdmi_set_format(struct hda_codec *codec, unsigned int format)
2942 {
2943 unsigned int value;
2944
2945 /* bits [31:30] contain the trigger and valid bits */
2946 value = snd_hda_codec_read(codec, NVIDIA_AFG_NID, 0,
2947 NVIDIA_GET_SCRATCH0, 0);
2948 value = (value >> 24) & 0xff;
2949
2950 /* bits [15:0] are used to store the HDA format */
2951 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
2952 NVIDIA_SET_SCRATCH0_BYTE0,
2953 (format >> 0) & 0xff);
2954 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
2955 NVIDIA_SET_SCRATCH0_BYTE1,
2956 (format >> 8) & 0xff);
2957
2958 /* bits [16:24] are unused */
2959 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
2960 NVIDIA_SET_SCRATCH0_BYTE2, 0);
2961
2962 /*
2963 * Bit 30 signals that the data is valid and hence that HDMI audio can
2964 * be enabled.
2965 */
2966 if (format == 0)
2967 value &= ~NVIDIA_SCRATCH_VALID;
2968 else
2969 value |= NVIDIA_SCRATCH_VALID;
2970
2971 /*
2972 * Whenever the trigger bit is toggled, an interrupt is raised in the
2973 * HDMI codec. The HDMI driver will use that as trigger to update its
2974 * configuration.
2975 */
2976 value ^= NVIDIA_SCRATCH_TRIGGER;
2977
2978 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
2979 NVIDIA_SET_SCRATCH0_BYTE3, value);
2980 }
2981
2982 static int tegra_hdmi_pcm_prepare(struct hda_pcm_stream *hinfo,
2983 struct hda_codec *codec,
2984 unsigned int stream_tag,
2985 unsigned int format,
2986 struct snd_pcm_substream *substream)
2987 {
2988 int err;
2989
2990 err = generic_hdmi_playback_pcm_prepare(hinfo, codec, stream_tag,
2991 format, substream);
2992 if (err < 0)
2993 return err;
2994
2995 /* notify the HDMI codec of the format change */
2996 tegra_hdmi_set_format(codec, format);
2997
2998 return 0;
2999 }
3000
3001 static int tegra_hdmi_pcm_cleanup(struct hda_pcm_stream *hinfo,
3002 struct hda_codec *codec,
3003 struct snd_pcm_substream *substream)
3004 {
3005 /* invalidate the format in the HDMI codec */
3006 tegra_hdmi_set_format(codec, 0);
3007
3008 return generic_hdmi_playback_pcm_cleanup(hinfo, codec, substream);
3009 }
3010
3011 static struct hda_pcm *hda_find_pcm_by_type(struct hda_codec *codec, int type)
3012 {
3013 struct hdmi_spec *spec = codec->spec;
3014 unsigned int i;
3015
3016 for (i = 0; i < spec->num_pins; i++) {
3017 struct hda_pcm *pcm = get_pcm_rec(spec, i);
3018
3019 if (pcm->pcm_type == type)
3020 return pcm;
3021 }
3022
3023 return NULL;
3024 }
3025
3026 static int tegra_hdmi_build_pcms(struct hda_codec *codec)
3027 {
3028 struct hda_pcm_stream *stream;
3029 struct hda_pcm *pcm;
3030 int err;
3031
3032 err = generic_hdmi_build_pcms(codec);
3033 if (err < 0)
3034 return err;
3035
3036 pcm = hda_find_pcm_by_type(codec, HDA_PCM_TYPE_HDMI);
3037 if (!pcm)
3038 return -ENODEV;
3039
3040 /*
3041 * Override ->prepare() and ->cleanup() operations to notify the HDMI
3042 * codec about format changes.
3043 */
3044 stream = &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
3045 stream->ops.prepare = tegra_hdmi_pcm_prepare;
3046 stream->ops.cleanup = tegra_hdmi_pcm_cleanup;
3047
3048 return 0;
3049 }
3050
3051 static int patch_tegra_hdmi(struct hda_codec *codec)
3052 {
3053 int err;
3054
3055 err = patch_generic_hdmi(codec);
3056 if (err)
3057 return err;
3058
3059 codec->patch_ops.build_pcms = tegra_hdmi_build_pcms;
3060
3061 return 0;
3062 }
3063
3064 /*
3065 * ATI/AMD-specific implementations
3066 */
3067
3068 #define is_amdhdmi_rev3_or_later(codec) \
3069 ((codec)->core.vendor_id == 0x1002aa01 && \
3070 ((codec)->core.revision_id & 0xff00) >= 0x0300)
3071 #define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec)
3072
3073 /* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */
3074 #define ATI_VERB_SET_CHANNEL_ALLOCATION 0x771
3075 #define ATI_VERB_SET_DOWNMIX_INFO 0x772
3076 #define ATI_VERB_SET_MULTICHANNEL_01 0x777
3077 #define ATI_VERB_SET_MULTICHANNEL_23 0x778
3078 #define ATI_VERB_SET_MULTICHANNEL_45 0x779
3079 #define ATI_VERB_SET_MULTICHANNEL_67 0x77a
3080 #define ATI_VERB_SET_HBR_CONTROL 0x77c
3081 #define ATI_VERB_SET_MULTICHANNEL_1 0x785
3082 #define ATI_VERB_SET_MULTICHANNEL_3 0x786
3083 #define ATI_VERB_SET_MULTICHANNEL_5 0x787
3084 #define ATI_VERB_SET_MULTICHANNEL_7 0x788
3085 #define ATI_VERB_SET_MULTICHANNEL_MODE 0x789
3086 #define ATI_VERB_GET_CHANNEL_ALLOCATION 0xf71
3087 #define ATI_VERB_GET_DOWNMIX_INFO 0xf72
3088 #define ATI_VERB_GET_MULTICHANNEL_01 0xf77
3089 #define ATI_VERB_GET_MULTICHANNEL_23 0xf78
3090 #define ATI_VERB_GET_MULTICHANNEL_45 0xf79
3091 #define ATI_VERB_GET_MULTICHANNEL_67 0xf7a
3092 #define ATI_VERB_GET_HBR_CONTROL 0xf7c
3093 #define ATI_VERB_GET_MULTICHANNEL_1 0xf85
3094 #define ATI_VERB_GET_MULTICHANNEL_3 0xf86
3095 #define ATI_VERB_GET_MULTICHANNEL_5 0xf87
3096 #define ATI_VERB_GET_MULTICHANNEL_7 0xf88
3097 #define ATI_VERB_GET_MULTICHANNEL_MODE 0xf89
3098
3099 /* AMD specific HDA cvt verbs */
3100 #define ATI_VERB_SET_RAMP_RATE 0x770
3101 #define ATI_VERB_GET_RAMP_RATE 0xf70
3102
3103 #define ATI_OUT_ENABLE 0x1
3104
3105 #define ATI_MULTICHANNEL_MODE_PAIRED 0
3106 #define ATI_MULTICHANNEL_MODE_SINGLE 1
3107
3108 #define ATI_HBR_CAPABLE 0x01
3109 #define ATI_HBR_ENABLE 0x10
3110
3111 static int atihdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
3112 unsigned char *buf, int *eld_size)
3113 {
3114 /* call hda_eld.c ATI/AMD-specific function */
3115 return snd_hdmi_get_eld_ati(codec, nid, buf, eld_size,
3116 is_amdhdmi_rev3_or_later(codec));
3117 }
3118
3119 static void atihdmi_pin_setup_infoframe(struct hda_codec *codec, hda_nid_t pin_nid, int ca,
3120 int active_channels, int conn_type)
3121 {
3122 snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_CHANNEL_ALLOCATION, ca);
3123 }
3124
3125 static int atihdmi_paired_swap_fc_lfe(int pos)
3126 {
3127 /*
3128 * ATI/AMD have automatic FC/LFE swap built-in
3129 * when in pairwise mapping mode.
3130 */
3131
3132 switch (pos) {
3133 /* see channel_allocations[].speakers[] */
3134 case 2: return 3;
3135 case 3: return 2;
3136 default: break;
3137 }
3138
3139 return pos;
3140 }
3141
3142 static int atihdmi_paired_chmap_validate(struct hdac_chmap *chmap,
3143 int ca, int chs, unsigned char *map)
3144 {
3145 struct hdac_cea_channel_speaker_allocation *cap;
3146 int i, j;
3147
3148 /* check that only channel pairs need to be remapped on old pre-rev3 ATI/AMD */
3149
3150 cap = snd_hdac_get_ch_alloc_from_ca(ca);
3151 for (i = 0; i < chs; ++i) {
3152 int mask = snd_hdac_chmap_to_spk_mask(map[i]);
3153 bool ok = false;
3154 bool companion_ok = false;
3155
3156 if (!mask)
3157 continue;
3158
3159 for (j = 0 + i % 2; j < 8; j += 2) {
3160 int chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j);
3161 if (cap->speakers[chan_idx] == mask) {
3162 /* channel is in a supported position */
3163 ok = true;
3164
3165 if (i % 2 == 0 && i + 1 < chs) {
3166 /* even channel, check the odd companion */
3167 int comp_chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j + 1);
3168 int comp_mask_req = snd_hdac_chmap_to_spk_mask(map[i+1]);
3169 int comp_mask_act = cap->speakers[comp_chan_idx];
3170
3171 if (comp_mask_req == comp_mask_act)
3172 companion_ok = true;
3173 else
3174 return -EINVAL;
3175 }
3176 break;
3177 }
3178 }
3179
3180 if (!ok)
3181 return -EINVAL;
3182
3183 if (companion_ok)
3184 i++; /* companion channel already checked */
3185 }
3186
3187 return 0;
3188 }
3189
3190 static int atihdmi_pin_set_slot_channel(struct hdac_device *hdac,
3191 hda_nid_t pin_nid, int hdmi_slot, int stream_channel)
3192 {
3193 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
3194 int verb;
3195 int ati_channel_setup = 0;
3196
3197 if (hdmi_slot > 7)
3198 return -EINVAL;
3199
3200 if (!has_amd_full_remap_support(codec)) {
3201 hdmi_slot = atihdmi_paired_swap_fc_lfe(hdmi_slot);
3202
3203 /* In case this is an odd slot but without stream channel, do not
3204 * disable the slot since the corresponding even slot could have a
3205 * channel. In case neither have a channel, the slot pair will be
3206 * disabled when this function is called for the even slot. */
3207 if (hdmi_slot % 2 != 0 && stream_channel == 0xf)
3208 return 0;
3209
3210 hdmi_slot -= hdmi_slot % 2;
3211
3212 if (stream_channel != 0xf)
3213 stream_channel -= stream_channel % 2;
3214 }
3215
3216 verb = ATI_VERB_SET_MULTICHANNEL_01 + hdmi_slot/2 + (hdmi_slot % 2) * 0x00e;
3217
3218 /* ati_channel_setup format: [7..4] = stream_channel_id, [1] = mute, [0] = enable */
3219
3220 if (stream_channel != 0xf)
3221 ati_channel_setup = (stream_channel << 4) | ATI_OUT_ENABLE;
3222
3223 return snd_hda_codec_write(codec, pin_nid, 0, verb, ati_channel_setup);
3224 }
3225
3226 static int atihdmi_pin_get_slot_channel(struct hdac_device *hdac,
3227 hda_nid_t pin_nid, int asp_slot)
3228 {
3229 struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
3230 bool was_odd = false;
3231 int ati_asp_slot = asp_slot;
3232 int verb;
3233 int ati_channel_setup;
3234
3235 if (asp_slot > 7)
3236 return -EINVAL;
3237
3238 if (!has_amd_full_remap_support(codec)) {
3239 ati_asp_slot = atihdmi_paired_swap_fc_lfe(asp_slot);
3240 if (ati_asp_slot % 2 != 0) {
3241 ati_asp_slot -= 1;
3242 was_odd = true;
3243 }
3244 }
3245
3246 verb = ATI_VERB_GET_MULTICHANNEL_01 + ati_asp_slot/2 + (ati_asp_slot % 2) * 0x00e;
3247
3248 ati_channel_setup = snd_hda_codec_read(codec, pin_nid, 0, verb, 0);
3249
3250 if (!(ati_channel_setup & ATI_OUT_ENABLE))
3251 return 0xf;
3252
3253 return ((ati_channel_setup & 0xf0) >> 4) + !!was_odd;
3254 }
3255
3256 static int atihdmi_paired_chmap_cea_alloc_validate_get_type(
3257 struct hdac_chmap *chmap,
3258 struct hdac_cea_channel_speaker_allocation *cap,
3259 int channels)
3260 {
3261 int c;
3262
3263 /*
3264 * Pre-rev3 ATI/AMD codecs operate in a paired channel mode, so
3265 * we need to take that into account (a single channel may take 2
3266 * channel slots if we need to carry a silent channel next to it).
3267 * On Rev3+ AMD codecs this function is not used.
3268 */
3269 int chanpairs = 0;
3270
3271 /* We only produce even-numbered channel count TLVs */
3272 if ((channels % 2) != 0)
3273 return -1;
3274
3275 for (c = 0; c < 7; c += 2) {
3276 if (cap->speakers[c] || cap->speakers[c+1])
3277 chanpairs++;
3278 }
3279
3280 if (chanpairs * 2 != channels)
3281 return -1;
3282
3283 return SNDRV_CTL_TLVT_CHMAP_PAIRED;
3284 }
3285
3286 static void atihdmi_paired_cea_alloc_to_tlv_chmap(struct hdac_chmap *hchmap,
3287 struct hdac_cea_channel_speaker_allocation *cap,
3288 unsigned int *chmap, int channels)
3289 {
3290 /* produce paired maps for pre-rev3 ATI/AMD codecs */
3291 int count = 0;
3292 int c;
3293
3294 for (c = 7; c >= 0; c--) {
3295 int chan = 7 - atihdmi_paired_swap_fc_lfe(7 - c);
3296 int spk = cap->speakers[chan];
3297 if (!spk) {
3298 /* add N/A channel if the companion channel is occupied */
3299 if (cap->speakers[chan + (chan % 2 ? -1 : 1)])
3300 chmap[count++] = SNDRV_CHMAP_NA;
3301
3302 continue;
3303 }
3304
3305 chmap[count++] = snd_hdac_spk_to_chmap(spk);
3306 }
3307
3308 WARN_ON(count != channels);
3309 }
3310
3311 static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
3312 bool hbr)
3313 {
3314 int hbr_ctl, hbr_ctl_new;
3315
3316 hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0);
3317 if (hbr_ctl >= 0 && (hbr_ctl & ATI_HBR_CAPABLE)) {
3318 if (hbr)
3319 hbr_ctl_new = hbr_ctl | ATI_HBR_ENABLE;
3320 else
3321 hbr_ctl_new = hbr_ctl & ~ATI_HBR_ENABLE;
3322
3323 codec_dbg(codec,
3324 "atihdmi_pin_hbr_setup: NID=0x%x, %shbr-ctl=0x%x\n",
3325 pin_nid,
3326 hbr_ctl == hbr_ctl_new ? "" : "new-",
3327 hbr_ctl_new);
3328
3329 if (hbr_ctl != hbr_ctl_new)
3330 snd_hda_codec_write(codec, pin_nid, 0,
3331 ATI_VERB_SET_HBR_CONTROL,
3332 hbr_ctl_new);
3333
3334 } else if (hbr)
3335 return -EINVAL;
3336
3337 return 0;
3338 }
3339
3340 static int atihdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
3341 hda_nid_t pin_nid, u32 stream_tag, int format)
3342 {
3343
3344 if (is_amdhdmi_rev3_or_later(codec)) {
3345 int ramp_rate = 180; /* default as per AMD spec */
3346 /* disable ramp-up/down for non-pcm as per AMD spec */
3347 if (format & AC_FMT_TYPE_NON_PCM)
3348 ramp_rate = 0;
3349
3350 snd_hda_codec_write(codec, cvt_nid, 0, ATI_VERB_SET_RAMP_RATE, ramp_rate);
3351 }
3352
3353 return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
3354 }
3355
3356
3357 static int atihdmi_init(struct hda_codec *codec)
3358 {
3359 struct hdmi_spec *spec = codec->spec;
3360 int pin_idx, err;
3361
3362 err = generic_hdmi_init(codec);
3363
3364 if (err)
3365 return err;
3366
3367 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
3368 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
3369
3370 /* make sure downmix information in infoframe is zero */
3371 snd_hda_codec_write(codec, per_pin->pin_nid, 0, ATI_VERB_SET_DOWNMIX_INFO, 0);
3372
3373 /* enable channel-wise remap mode if supported */
3374 if (has_amd_full_remap_support(codec))
3375 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
3376 ATI_VERB_SET_MULTICHANNEL_MODE,
3377 ATI_MULTICHANNEL_MODE_SINGLE);
3378 }
3379
3380 return 0;
3381 }
3382
3383 static int patch_atihdmi(struct hda_codec *codec)
3384 {
3385 struct hdmi_spec *spec;
3386 struct hdmi_spec_per_cvt *per_cvt;
3387 int err, cvt_idx;
3388
3389 err = patch_generic_hdmi(codec);
3390
3391 if (err)
3392 return err;
3393
3394 codec->patch_ops.init = atihdmi_init;
3395
3396 spec = codec->spec;
3397
3398 spec->ops.pin_get_eld = atihdmi_pin_get_eld;
3399 spec->ops.pin_setup_infoframe = atihdmi_pin_setup_infoframe;
3400 spec->ops.pin_hbr_setup = atihdmi_pin_hbr_setup;
3401 spec->ops.setup_stream = atihdmi_setup_stream;
3402
3403 if (!has_amd_full_remap_support(codec)) {
3404 /* override to ATI/AMD-specific versions with pairwise mapping */
3405 spec->chmap.ops.chmap_cea_alloc_validate_get_type =
3406 atihdmi_paired_chmap_cea_alloc_validate_get_type;
3407 spec->chmap.ops.cea_alloc_to_tlv_chmap =
3408 atihdmi_paired_cea_alloc_to_tlv_chmap;
3409 spec->chmap.ops.chmap_validate = atihdmi_paired_chmap_validate;
3410 spec->chmap.ops.pin_get_slot_channel =
3411 atihdmi_pin_get_slot_channel;
3412 spec->chmap.ops.pin_set_slot_channel =
3413 atihdmi_pin_set_slot_channel;
3414 }
3415
3416 /* ATI/AMD converters do not advertise all of their capabilities */
3417 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
3418 per_cvt = get_cvt(spec, cvt_idx);
3419 per_cvt->channels_max = max(per_cvt->channels_max, 8u);
3420 per_cvt->rates |= SUPPORTED_RATES;
3421 per_cvt->formats |= SUPPORTED_FORMATS;
3422 per_cvt->maxbps = max(per_cvt->maxbps, 24u);
3423 }
3424
3425 spec->chmap.channels_max = max(spec->chmap.channels_max, 8u);
3426
3427 return 0;
3428 }
3429
3430 /* VIA HDMI Implementation */
3431 #define VIAHDMI_CVT_NID 0x02 /* audio converter1 */
3432 #define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */
3433
3434 static int patch_via_hdmi(struct hda_codec *codec)
3435 {
3436 return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
3437 }
3438
3439 /*
3440 * patch entries
3441 */
3442 static const struct hda_device_id snd_hda_id_hdmi[] = {
3443 HDA_CODEC_ENTRY(0x1002793c, "RS600 HDMI", patch_atihdmi),
3444 HDA_CODEC_ENTRY(0x10027919, "RS600 HDMI", patch_atihdmi),
3445 HDA_CODEC_ENTRY(0x1002791a, "RS690/780 HDMI", patch_atihdmi),
3446 HDA_CODEC_ENTRY(0x1002aa01, "R6xx HDMI", patch_atihdmi),
3447 HDA_CODEC_ENTRY(0x10951390, "SiI1390 HDMI", patch_generic_hdmi),
3448 HDA_CODEC_ENTRY(0x10951392, "SiI1392 HDMI", patch_generic_hdmi),
3449 HDA_CODEC_ENTRY(0x17e80047, "Chrontel HDMI", patch_generic_hdmi),
3450 HDA_CODEC_ENTRY(0x10de0002, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3451 HDA_CODEC_ENTRY(0x10de0003, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3452 HDA_CODEC_ENTRY(0x10de0005, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3453 HDA_CODEC_ENTRY(0x10de0006, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3454 HDA_CODEC_ENTRY(0x10de0007, "MCP79/7A HDMI", patch_nvhdmi_8ch_7x),
3455 HDA_CODEC_ENTRY(0x10de000a, "GPU 0a HDMI/DP", patch_nvhdmi),
3456 HDA_CODEC_ENTRY(0x10de000b, "GPU 0b HDMI/DP", patch_nvhdmi),
3457 HDA_CODEC_ENTRY(0x10de000c, "MCP89 HDMI", patch_nvhdmi),
3458 HDA_CODEC_ENTRY(0x10de000d, "GPU 0d HDMI/DP", patch_nvhdmi),
3459 HDA_CODEC_ENTRY(0x10de0010, "GPU 10 HDMI/DP", patch_nvhdmi),
3460 HDA_CODEC_ENTRY(0x10de0011, "GPU 11 HDMI/DP", patch_nvhdmi),
3461 HDA_CODEC_ENTRY(0x10de0012, "GPU 12 HDMI/DP", patch_nvhdmi),
3462 HDA_CODEC_ENTRY(0x10de0013, "GPU 13 HDMI/DP", patch_nvhdmi),
3463 HDA_CODEC_ENTRY(0x10de0014, "GPU 14 HDMI/DP", patch_nvhdmi),
3464 HDA_CODEC_ENTRY(0x10de0015, "GPU 15 HDMI/DP", patch_nvhdmi),
3465 HDA_CODEC_ENTRY(0x10de0016, "GPU 16 HDMI/DP", patch_nvhdmi),
3466 /* 17 is known to be absent */
3467 HDA_CODEC_ENTRY(0x10de0018, "GPU 18 HDMI/DP", patch_nvhdmi),
3468 HDA_CODEC_ENTRY(0x10de0019, "GPU 19 HDMI/DP", patch_nvhdmi),
3469 HDA_CODEC_ENTRY(0x10de001a, "GPU 1a HDMI/DP", patch_nvhdmi),
3470 HDA_CODEC_ENTRY(0x10de001b, "GPU 1b HDMI/DP", patch_nvhdmi),
3471 HDA_CODEC_ENTRY(0x10de001c, "GPU 1c HDMI/DP", patch_nvhdmi),
3472 HDA_CODEC_ENTRY(0x10de0020, "Tegra30 HDMI", patch_tegra_hdmi),
3473 HDA_CODEC_ENTRY(0x10de0022, "Tegra114 HDMI", patch_tegra_hdmi),
3474 HDA_CODEC_ENTRY(0x10de0028, "Tegra124 HDMI", patch_tegra_hdmi),
3475 HDA_CODEC_ENTRY(0x10de0029, "Tegra210 HDMI/DP", patch_tegra_hdmi),
3476 HDA_CODEC_ENTRY(0x10de0040, "GPU 40 HDMI/DP", patch_nvhdmi),
3477 HDA_CODEC_ENTRY(0x10de0041, "GPU 41 HDMI/DP", patch_nvhdmi),
3478 HDA_CODEC_ENTRY(0x10de0042, "GPU 42 HDMI/DP", patch_nvhdmi),
3479 HDA_CODEC_ENTRY(0x10de0043, "GPU 43 HDMI/DP", patch_nvhdmi),
3480 HDA_CODEC_ENTRY(0x10de0044, "GPU 44 HDMI/DP", patch_nvhdmi),
3481 HDA_CODEC_ENTRY(0x10de0051, "GPU 51 HDMI/DP", patch_nvhdmi),
3482 HDA_CODEC_ENTRY(0x10de0060, "GPU 60 HDMI/DP", patch_nvhdmi),
3483 HDA_CODEC_ENTRY(0x10de0067, "MCP67 HDMI", patch_nvhdmi_2ch),
3484 HDA_CODEC_ENTRY(0x10de0070, "GPU 70 HDMI/DP", patch_nvhdmi),
3485 HDA_CODEC_ENTRY(0x10de0071, "GPU 71 HDMI/DP", patch_nvhdmi),
3486 HDA_CODEC_ENTRY(0x10de0072, "GPU 72 HDMI/DP", patch_nvhdmi),
3487 HDA_CODEC_ENTRY(0x10de007d, "GPU 7d HDMI/DP", patch_nvhdmi),
3488 HDA_CODEC_ENTRY(0x10de0082, "GPU 82 HDMI/DP", patch_nvhdmi),
3489 HDA_CODEC_ENTRY(0x10de0083, "GPU 83 HDMI/DP", patch_nvhdmi),
3490 HDA_CODEC_ENTRY(0x10de8001, "MCP73 HDMI", patch_nvhdmi_2ch),
3491 HDA_CODEC_ENTRY(0x11069f80, "VX900 HDMI/DP", patch_via_hdmi),
3492 HDA_CODEC_ENTRY(0x11069f81, "VX900 HDMI/DP", patch_via_hdmi),
3493 HDA_CODEC_ENTRY(0x11069f84, "VX11 HDMI/DP", patch_generic_hdmi),
3494 HDA_CODEC_ENTRY(0x11069f85, "VX11 HDMI/DP", patch_generic_hdmi),
3495 HDA_CODEC_ENTRY(0x80860054, "IbexPeak HDMI", patch_generic_hdmi),
3496 HDA_CODEC_ENTRY(0x80862801, "Bearlake HDMI", patch_generic_hdmi),
3497 HDA_CODEC_ENTRY(0x80862802, "Cantiga HDMI", patch_generic_hdmi),
3498 HDA_CODEC_ENTRY(0x80862803, "Eaglelake HDMI", patch_generic_hdmi),
3499 HDA_CODEC_ENTRY(0x80862804, "IbexPeak HDMI", patch_generic_hdmi),
3500 HDA_CODEC_ENTRY(0x80862805, "CougarPoint HDMI", patch_generic_hdmi),
3501 HDA_CODEC_ENTRY(0x80862806, "PantherPoint HDMI", patch_generic_hdmi),
3502 HDA_CODEC_ENTRY(0x80862807, "Haswell HDMI", patch_generic_hdmi),
3503 HDA_CODEC_ENTRY(0x80862808, "Broadwell HDMI", patch_generic_hdmi),
3504 HDA_CODEC_ENTRY(0x80862809, "Skylake HDMI", patch_generic_hdmi),
3505 HDA_CODEC_ENTRY(0x8086280a, "Broxton HDMI", patch_generic_hdmi),
3506 HDA_CODEC_ENTRY(0x8086280b, "Kabylake HDMI", patch_generic_hdmi),
3507 HDA_CODEC_ENTRY(0x80862880, "CedarTrail HDMI", patch_generic_hdmi),
3508 HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_generic_hdmi),
3509 HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_generic_hdmi),
3510 HDA_CODEC_ENTRY(0x808629fb, "Crestline HDMI", patch_generic_hdmi),
3511 /* special ID for generic HDMI */
3512 HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC_HDMI, "Generic HDMI", patch_generic_hdmi),
3513 {} /* terminator */
3514 };
3515 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_hdmi);
3516
3517 MODULE_LICENSE("GPL");
3518 MODULE_DESCRIPTION("HDMI HD-audio codec");
3519 MODULE_ALIAS("snd-hda-codec-intelhdmi");
3520 MODULE_ALIAS("snd-hda-codec-nvhdmi");
3521 MODULE_ALIAS("snd-hda-codec-atihdmi");
3522
3523 static struct hda_codec_driver hdmi_driver = {
3524 .id = snd_hda_id_hdmi,
3525 };
3526
3527 module_hda_codec_driver(hdmi_driver);
This page took 0.129351 seconds and 5 git commands to generate.