blob: 3f1f6ac8e6432fe5fc49d8ec533e6722e57f8e74 [file] [log] [blame]
Wu Fengguang079d88c2010-03-08 10:44:23 +08001/*
2 *
3 * patch_hdmi.c - routines for HDMI/DisplayPort codecs
4 *
5 * Copyright(c) 2008-2010 Intel Corporation. All rights reserved.
Takashi Iwai84eb01b2010-09-07 12:27:25 +02006 * Copyright (c) 2006 ATI Technologies Inc.
7 * Copyright (c) 2008 NVIDIA Corp. All rights reserved.
8 * Copyright (c) 2008 Wei Ni <wni@nvidia.com>
Wu Fengguang079d88c2010-03-08 10:44:23 +08009 *
10 * Authors:
11 * Wu Fengguang <wfg@linux.intel.com>
12 *
13 * Maintained by:
14 * Wu Fengguang <wfg@linux.intel.com>
15 *
16 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the Free
18 * Software Foundation; either version 2 of the License, or (at your option)
19 * any later version.
20 *
21 * This program is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software Foundation,
28 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 */
30
Takashi Iwai84eb01b2010-09-07 12:27:25 +020031#include <linux/init.h>
32#include <linux/delay.h>
33#include <linux/slab.h>
Takashi Iwai0ebaa242011-01-11 18:11:04 +010034#include <linux/moduleparam.h>
Takashi Iwai84eb01b2010-09-07 12:27:25 +020035#include <sound/core.h>
David Henningsson07acecc2011-05-19 11:46:03 +020036#include <sound/jack.h>
Takashi Iwai84eb01b2010-09-07 12:27:25 +020037#include "hda_codec.h"
38#include "hda_local.h"
39
Takashi Iwai0ebaa242011-01-11 18:11:04 +010040static bool static_hdmi_pcm;
41module_param(static_hdmi_pcm, bool, 0644);
42MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
43
Takashi Iwai84eb01b2010-09-07 12:27:25 +020044/*
45 * The HDMI/DisplayPort configuration can be highly dynamic. A graphics device
Stephen Warren384a48d2011-06-01 11:14:21 -060046 * could support N independent pipes, each of them can be connected to one or
Takashi Iwai84eb01b2010-09-07 12:27:25 +020047 * more ports (DVI, HDMI or DisplayPort).
48 *
49 * The HDA correspondence of pipes/ports are converter/pin nodes.
50 */
Stephen Warren73926652011-05-25 12:42:13 -060051#define MAX_HDMI_CVTS 4
52#define MAX_HDMI_PINS 4
Wu Fengguang079d88c2010-03-08 10:44:23 +080053
Stephen Warren384a48d2011-06-01 11:14:21 -060054struct hdmi_spec_per_cvt {
55 hda_nid_t cvt_nid;
56 int assigned;
57 unsigned int channels_min;
58 unsigned int channels_max;
59 u32 rates;
60 u64 formats;
61 unsigned int maxbps;
62};
63
64struct hdmi_spec_per_pin {
65 hda_nid_t pin_nid;
66 int num_mux_nids;
67 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
68 struct hdmi_eld sink_eld;
69};
70
Wu Fengguang079d88c2010-03-08 10:44:23 +080071struct hdmi_spec {
72 int num_cvts;
Stephen Warren384a48d2011-06-01 11:14:21 -060073 struct hdmi_spec_per_cvt cvts[MAX_HDMI_CVTS];
74
Wu Fengguang079d88c2010-03-08 10:44:23 +080075 int num_pins;
Stephen Warren384a48d2011-06-01 11:14:21 -060076 struct hdmi_spec_per_pin pins[MAX_HDMI_PINS];
77 struct hda_pcm pcm_rec[MAX_HDMI_PINS];
Wu Fengguang079d88c2010-03-08 10:44:23 +080078
79 /*
Stephen Warren384a48d2011-06-01 11:14:21 -060080 * Non-generic ATI/NVIDIA specific
Wu Fengguang079d88c2010-03-08 10:44:23 +080081 */
82 struct hda_multi_out multiout;
Takashi Iwaifb79e1e2011-05-02 12:17:41 +020083 const struct hda_pcm_stream *pcm_playback;
Wu Fengguang079d88c2010-03-08 10:44:23 +080084};
85
86
87struct hdmi_audio_infoframe {
88 u8 type; /* 0x84 */
89 u8 ver; /* 0x01 */
90 u8 len; /* 0x0a */
91
Wu Fengguang53d7d692010-09-21 14:25:49 +080092 u8 checksum;
93
Wu Fengguang079d88c2010-03-08 10:44:23 +080094 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
95 u8 SS01_SF24;
96 u8 CXT04;
97 u8 CA;
98 u8 LFEPBL01_LSV36_DM_INH7;
Wu Fengguang53d7d692010-09-21 14:25:49 +080099};
100
101struct dp_audio_infoframe {
102 u8 type; /* 0x84 */
103 u8 len; /* 0x1b */
104 u8 ver; /* 0x11 << 2 */
105
106 u8 CC02_CT47; /* match with HDMI infoframe from this on */
107 u8 SS01_SF24;
108 u8 CXT04;
109 u8 CA;
110 u8 LFEPBL01_LSV36_DM_INH7;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800111};
112
Takashi Iwai2b203dbb2011-02-11 12:17:30 +0100113union audio_infoframe {
114 struct hdmi_audio_infoframe hdmi;
115 struct dp_audio_infoframe dp;
116 u8 bytes[0];
117};
118
Wu Fengguang079d88c2010-03-08 10:44:23 +0800119/*
120 * CEA speaker placement:
121 *
122 * FLH FCH FRH
123 * FLW FL FLC FC FRC FR FRW
124 *
125 * LFE
126 * TC
127 *
128 * RL RLC RC RRC RR
129 *
130 * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
131 * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
132 */
133enum cea_speaker_placement {
134 FL = (1 << 0), /* Front Left */
135 FC = (1 << 1), /* Front Center */
136 FR = (1 << 2), /* Front Right */
137 FLC = (1 << 3), /* Front Left Center */
138 FRC = (1 << 4), /* Front Right Center */
139 RL = (1 << 5), /* Rear Left */
140 RC = (1 << 6), /* Rear Center */
141 RR = (1 << 7), /* Rear Right */
142 RLC = (1 << 8), /* Rear Left Center */
143 RRC = (1 << 9), /* Rear Right Center */
144 LFE = (1 << 10), /* Low Frequency Effect */
145 FLW = (1 << 11), /* Front Left Wide */
146 FRW = (1 << 12), /* Front Right Wide */
147 FLH = (1 << 13), /* Front Left High */
148 FCH = (1 << 14), /* Front Center High */
149 FRH = (1 << 15), /* Front Right High */
150 TC = (1 << 16), /* Top Center */
151};
152
153/*
154 * ELD SA bits in the CEA Speaker Allocation data block
155 */
156static int eld_speaker_allocation_bits[] = {
157 [0] = FL | FR,
158 [1] = LFE,
159 [2] = FC,
160 [3] = RL | RR,
161 [4] = RC,
162 [5] = FLC | FRC,
163 [6] = RLC | RRC,
164 /* the following are not defined in ELD yet */
165 [7] = FLW | FRW,
166 [8] = FLH | FRH,
167 [9] = TC,
168 [10] = FCH,
169};
170
171struct cea_channel_speaker_allocation {
172 int ca_index;
173 int speakers[8];
174
175 /* derived values, just for convenience */
176 int channels;
177 int spk_mask;
178};
179
180/*
181 * ALSA sequence is:
182 *
183 * surround40 surround41 surround50 surround51 surround71
184 * ch0 front left = = = =
185 * ch1 front right = = = =
186 * ch2 rear left = = = =
187 * ch3 rear right = = = =
188 * ch4 LFE center center center
189 * ch5 LFE LFE
190 * ch6 side left
191 * ch7 side right
192 *
193 * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR}
194 */
195static int hdmi_channel_mapping[0x32][8] = {
196 /* stereo */
197 [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
198 /* 2.1 */
199 [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
200 /* Dolby Surround */
201 [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 },
202 /* surround40 */
203 [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 },
204 /* 4ch */
205 [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 },
206 /* surround41 */
Jerry Zhou9396d312010-09-21 14:44:51 +0800207 [0x09] = { 0x00, 0x11, 0x24, 0x35, 0x42, 0xf3, 0xf6, 0xf7 },
Wu Fengguang079d88c2010-03-08 10:44:23 +0800208 /* surround50 */
209 [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 },
210 /* surround51 */
211 [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 },
212 /* 7.1 */
213 [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 },
214};
215
216/*
217 * This is an ordered list!
218 *
219 * The preceding ones have better chances to be selected by
Wu Fengguang53d7d692010-09-21 14:25:49 +0800220 * hdmi_channel_allocation().
Wu Fengguang079d88c2010-03-08 10:44:23 +0800221 */
222static struct cea_channel_speaker_allocation channel_allocations[] = {
223/* channel: 7 6 5 4 3 2 1 0 */
224{ .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
225 /* 2.1 */
226{ .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
227 /* Dolby Surround */
228{ .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
229 /* surround40 */
230{ .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
231 /* surround41 */
232{ .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
233 /* surround50 */
234{ .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
235 /* surround51 */
236{ .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
237 /* 6.1 */
238{ .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
239 /* surround71 */
240{ .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
241
242{ .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
243{ .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
244{ .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
245{ .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
246{ .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
247{ .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
248{ .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
249{ .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
250{ .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
251{ .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
252{ .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
253{ .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
254{ .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
255{ .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
256{ .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
257{ .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
258{ .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
259{ .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
260{ .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
261{ .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
262{ .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
263{ .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
264{ .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
265{ .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } },
266{ .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } },
267{ .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } },
268{ .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } },
269{ .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } },
270{ .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } },
271{ .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } },
272{ .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } },
273{ .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } },
274{ .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } },
275{ .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } },
276{ .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } },
277{ .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } },
278{ .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } },
279{ .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } },
280{ .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } },
281{ .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } },
282{ .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
283};
284
285
286/*
287 * HDMI routines
288 */
289
Stephen Warren384a48d2011-06-01 11:14:21 -0600290static int pin_nid_to_pin_index(struct hdmi_spec *spec, hda_nid_t pin_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800291{
Stephen Warren384a48d2011-06-01 11:14:21 -0600292 int pin_idx;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800293
Stephen Warren384a48d2011-06-01 11:14:21 -0600294 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
295 if (spec->pins[pin_idx].pin_nid == pin_nid)
296 return pin_idx;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800297
Stephen Warren384a48d2011-06-01 11:14:21 -0600298 snd_printk(KERN_WARNING "HDMI: pin nid %d not registered\n", pin_nid);
299 return -EINVAL;
300}
301
302static int hinfo_to_pin_index(struct hdmi_spec *spec,
303 struct hda_pcm_stream *hinfo)
304{
305 int pin_idx;
306
307 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
308 if (&spec->pcm_rec[pin_idx].stream[0] == hinfo)
309 return pin_idx;
310
311 snd_printk(KERN_WARNING "HDMI: hinfo %p not registered\n", hinfo);
312 return -EINVAL;
313}
314
315static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid)
316{
317 int cvt_idx;
318
319 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
320 if (spec->cvts[cvt_idx].cvt_nid == cvt_nid)
321 return cvt_idx;
322
323 snd_printk(KERN_WARNING "HDMI: cvt nid %d not registered\n", cvt_nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800324 return -EINVAL;
325}
326
Wu Fengguang079d88c2010-03-08 10:44:23 +0800327#ifdef BE_PARANOID
328static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
329 int *packet_index, int *byte_index)
330{
331 int val;
332
333 val = snd_hda_codec_read(codec, pin_nid, 0,
334 AC_VERB_GET_HDMI_DIP_INDEX, 0);
335
336 *packet_index = val >> 5;
337 *byte_index = val & 0x1f;
338}
339#endif
340
341static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
342 int packet_index, int byte_index)
343{
344 int val;
345
346 val = (packet_index << 5) | (byte_index & 0x1f);
347
348 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
349}
350
351static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
352 unsigned char val)
353{
354 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
355}
356
Stephen Warren384a48d2011-06-01 11:14:21 -0600357static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800358{
359 /* Unmute */
360 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
361 snd_hda_codec_write(codec, pin_nid, 0,
362 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
Stephen Warren384a48d2011-06-01 11:14:21 -0600363 /* Disable pin out until stream is active*/
Wu Fengguang079d88c2010-03-08 10:44:23 +0800364 snd_hda_codec_write(codec, pin_nid, 0,
Stephen Warren384a48d2011-06-01 11:14:21 -0600365 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800366}
367
Stephen Warren384a48d2011-06-01 11:14:21 -0600368static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800369{
Stephen Warren384a48d2011-06-01 11:14:21 -0600370 return 1 + snd_hda_codec_read(codec, cvt_nid, 0,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800371 AC_VERB_GET_CVT_CHAN_COUNT, 0);
372}
373
374static void hdmi_set_channel_count(struct hda_codec *codec,
Stephen Warren384a48d2011-06-01 11:14:21 -0600375 hda_nid_t cvt_nid, int chs)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800376{
Stephen Warren384a48d2011-06-01 11:14:21 -0600377 if (chs != hdmi_get_channel_count(codec, cvt_nid))
378 snd_hda_codec_write(codec, cvt_nid, 0,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800379 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
380}
381
382
383/*
384 * Channel mapping routines
385 */
386
387/*
388 * Compute derived values in channel_allocations[].
389 */
390static void init_channel_allocations(void)
391{
392 int i, j;
393 struct cea_channel_speaker_allocation *p;
394
395 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
396 p = channel_allocations + i;
397 p->channels = 0;
398 p->spk_mask = 0;
399 for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
400 if (p->speakers[j]) {
401 p->channels++;
402 p->spk_mask |= p->speakers[j];
403 }
404 }
405}
406
407/*
408 * The transformation takes two steps:
409 *
410 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
411 * spk_mask => (channel_allocations[]) => ai->CA
412 *
413 * TODO: it could select the wrong CA from multiple candidates.
414*/
Stephen Warren384a48d2011-06-01 11:14:21 -0600415static int hdmi_channel_allocation(struct hdmi_eld *eld, int channels)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800416{
Wu Fengguang079d88c2010-03-08 10:44:23 +0800417 int i;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800418 int ca = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800419 int spk_mask = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800420 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
421
422 /*
423 * CA defaults to 0 for basic stereo audio
424 */
425 if (channels <= 2)
426 return 0;
427
Wu Fengguang079d88c2010-03-08 10:44:23 +0800428 /*
429 * expand ELD's speaker allocation mask
430 *
431 * ELD tells the speaker mask in a compact(paired) form,
432 * expand ELD's notions to match the ones used by Audio InfoFrame.
433 */
434 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
435 if (eld->spk_alloc & (1 << i))
436 spk_mask |= eld_speaker_allocation_bits[i];
437 }
438
439 /* search for the first working match in the CA table */
440 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
441 if (channels == channel_allocations[i].channels &&
442 (spk_mask & channel_allocations[i].spk_mask) ==
443 channel_allocations[i].spk_mask) {
Wu Fengguang53d7d692010-09-21 14:25:49 +0800444 ca = channel_allocations[i].ca_index;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800445 break;
446 }
447 }
448
449 snd_print_channel_allocation(eld->spk_alloc, buf, sizeof(buf));
Wu Fengguang2abbf432010-03-08 10:45:38 +0800450 snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n",
Wu Fengguang53d7d692010-09-21 14:25:49 +0800451 ca, channels, buf);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800452
Wu Fengguang53d7d692010-09-21 14:25:49 +0800453 return ca;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800454}
455
456static void hdmi_debug_channel_mapping(struct hda_codec *codec,
457 hda_nid_t pin_nid)
458{
459#ifdef CONFIG_SND_DEBUG_VERBOSE
460 int i;
461 int slot;
462
463 for (i = 0; i < 8; i++) {
464 slot = snd_hda_codec_read(codec, pin_nid, 0,
465 AC_VERB_GET_HDMI_CHAN_SLOT, i);
466 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n",
467 slot >> 4, slot & 0xf);
468 }
469#endif
470}
471
472
473static void hdmi_setup_channel_mapping(struct hda_codec *codec,
474 hda_nid_t pin_nid,
Wu Fengguang53d7d692010-09-21 14:25:49 +0800475 int ca)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800476{
477 int i;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800478 int err;
479
480 if (hdmi_channel_mapping[ca][1] == 0) {
481 for (i = 0; i < channel_allocations[ca].channels; i++)
482 hdmi_channel_mapping[ca][i] = i | (i << 4);
483 for (; i < 8; i++)
484 hdmi_channel_mapping[ca][i] = 0xf | (i << 4);
485 }
486
487 for (i = 0; i < 8; i++) {
488 err = snd_hda_codec_write(codec, pin_nid, 0,
489 AC_VERB_SET_HDMI_CHAN_SLOT,
490 hdmi_channel_mapping[ca][i]);
491 if (err) {
Wu Fengguang2abbf432010-03-08 10:45:38 +0800492 snd_printdd(KERN_NOTICE
493 "HDMI: channel mapping failed\n");
Wu Fengguang079d88c2010-03-08 10:44:23 +0800494 break;
495 }
496 }
497
498 hdmi_debug_channel_mapping(codec, pin_nid);
499}
500
501
502/*
503 * Audio InfoFrame routines
504 */
505
506/*
507 * Enable Audio InfoFrame Transmission
508 */
509static 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 */
520static 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
528static 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 printk(KERN_DEBUG "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 printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size);
541 }
542#endif
543}
544
545static 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 snd_printd(KERN_INFO "dip index %d: %d != %d\n",
563 bi, pi, i);
564 if (bi == 0) /* byte index wrapped around */
565 break;
566 }
567 snd_printd(KERN_INFO
568 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
569 i, size, j);
570 }
571#endif
572}
573
Wu Fengguang53d7d692010-09-21 14:25:49 +0800574static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800575{
Wu Fengguang53d7d692010-09-21 14:25:49 +0800576 u8 *bytes = (u8 *)hdmi_ai;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800577 u8 sum = 0;
578 int i;
579
Wu Fengguang53d7d692010-09-21 14:25:49 +0800580 hdmi_ai->checksum = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800581
Wu Fengguang53d7d692010-09-21 14:25:49 +0800582 for (i = 0; i < sizeof(*hdmi_ai); i++)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800583 sum += bytes[i];
584
Wu Fengguang53d7d692010-09-21 14:25:49 +0800585 hdmi_ai->checksum = -sum;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800586}
587
588static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
589 hda_nid_t pin_nid,
Wu Fengguang53d7d692010-09-21 14:25:49 +0800590 u8 *dip, int size)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800591{
Wu Fengguang079d88c2010-03-08 10:44:23 +0800592 int i;
593
594 hdmi_debug_dip_size(codec, pin_nid);
595 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
596
Wu Fengguang079d88c2010-03-08 10:44:23 +0800597 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
Wu Fengguang53d7d692010-09-21 14:25:49 +0800598 for (i = 0; i < size; i++)
599 hdmi_write_dip_byte(codec, pin_nid, dip[i]);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800600}
601
602static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
Wu Fengguang53d7d692010-09-21 14:25:49 +0800603 u8 *dip, int size)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800604{
Wu Fengguang079d88c2010-03-08 10:44:23 +0800605 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);
Wu Fengguang53d7d692010-09-21 14:25:49 +0800613 for (i = 0; i < size; i++) {
Wu Fengguang079d88c2010-03-08 10:44:23 +0800614 val = snd_hda_codec_read(codec, pin_nid, 0,
615 AC_VERB_GET_HDMI_DIP_DATA, 0);
Wu Fengguang53d7d692010-09-21 14:25:49 +0800616 if (val != dip[i])
Wu Fengguang079d88c2010-03-08 10:44:23 +0800617 return false;
618 }
619
620 return true;
621}
622
Stephen Warren384a48d2011-06-01 11:14:21 -0600623static void hdmi_setup_audio_infoframe(struct hda_codec *codec, int pin_idx,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800624 struct snd_pcm_substream *substream)
625{
626 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -0600627 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
628 hda_nid_t pin_nid = per_pin->pin_nid;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800629 int channels = substream->runtime->channels;
Stephen Warren384a48d2011-06-01 11:14:21 -0600630 struct hdmi_eld *eld;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800631 int ca;
Takashi Iwai2b203dbb2011-02-11 12:17:30 +0100632 union audio_infoframe ai;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800633
Stephen Warren384a48d2011-06-01 11:14:21 -0600634 eld = &spec->pins[pin_idx].sink_eld;
635 if (!eld->monitor_present)
636 return;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800637
Stephen Warren384a48d2011-06-01 11:14:21 -0600638 ca = hdmi_channel_allocation(eld, channels);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800639
Stephen Warren384a48d2011-06-01 11:14:21 -0600640 memset(&ai, 0, sizeof(ai));
641 if (eld->conn_type == 0) { /* HDMI */
642 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800643
Stephen Warren384a48d2011-06-01 11:14:21 -0600644 hdmi_ai->type = 0x84;
645 hdmi_ai->ver = 0x01;
646 hdmi_ai->len = 0x0a;
647 hdmi_ai->CC02_CT47 = channels - 1;
648 hdmi_ai->CA = ca;
649 hdmi_checksum_audio_infoframe(hdmi_ai);
650 } else if (eld->conn_type == 1) { /* DisplayPort */
651 struct dp_audio_infoframe *dp_ai = &ai.dp;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800652
Stephen Warren384a48d2011-06-01 11:14:21 -0600653 dp_ai->type = 0x84;
654 dp_ai->len = 0x1b;
655 dp_ai->ver = 0x11 << 2;
656 dp_ai->CC02_CT47 = channels - 1;
657 dp_ai->CA = ca;
658 } else {
659 snd_printd("HDMI: unknown connection type at pin %d\n",
660 pin_nid);
661 return;
662 }
Wu Fengguang53d7d692010-09-21 14:25:49 +0800663
Stephen Warren384a48d2011-06-01 11:14:21 -0600664 /*
665 * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
666 * sizeof(*dp_ai) to avoid partial match/update problems when
667 * the user switches between HDMI/DP monitors.
668 */
669 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
670 sizeof(ai))) {
671 snd_printdd("hdmi_setup_audio_infoframe: "
672 "pin=%d channels=%d\n",
673 pin_nid,
674 channels);
675 hdmi_setup_channel_mapping(codec, pin_nid, ca);
676 hdmi_stop_infoframe_trans(codec, pin_nid);
677 hdmi_fill_audio_infoframe(codec, pin_nid,
678 ai.bytes, sizeof(ai));
679 hdmi_start_infoframe_trans(codec, pin_nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800680 }
681}
682
683
684/*
685 * Unsolicited events
686 */
687
Takashi Iwai38faddb2010-07-28 14:21:55 +0200688static void hdmi_present_sense(struct hda_codec *codec, hda_nid_t pin_nid,
689 struct hdmi_eld *eld);
690
Wu Fengguang079d88c2010-03-08 10:44:23 +0800691static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
692{
693 struct hdmi_spec *spec = codec->spec;
Stephen Warren5d44f922011-05-24 17:11:17 -0600694 int pin_nid = res >> AC_UNSOL_RES_TAG_SHIFT;
695 int pd = !!(res & AC_UNSOL_RES_PD);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800696 int eldv = !!(res & AC_UNSOL_RES_ELDV);
Stephen Warren384a48d2011-06-01 11:14:21 -0600697 int pin_idx;
698 struct hdmi_eld *eld;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800699
700 printk(KERN_INFO
Stephen Warren384a48d2011-06-01 11:14:21 -0600701 "HDMI hot plug event: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
702 codec->addr, pin_nid, pd, eldv);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800703
Stephen Warren384a48d2011-06-01 11:14:21 -0600704 pin_idx = pin_nid_to_pin_index(spec, pin_nid);
705 if (pin_idx < 0)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800706 return;
Stephen Warren384a48d2011-06-01 11:14:21 -0600707 eld = &spec->pins[pin_idx].sink_eld;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800708
Stephen Warren384a48d2011-06-01 11:14:21 -0600709 hdmi_present_sense(codec, pin_nid, eld);
710
711 /*
712 * HDMI sink's ELD info cannot always be retrieved for now, e.g.
713 * in console or for audio devices. Assume the highest speakers
714 * configuration, to _not_ prohibit multi-channel audio playback.
715 */
716 if (!eld->spk_alloc)
717 eld->spk_alloc = 0xffff;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800718}
719
720static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
721{
722 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
723 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
724 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
725 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
726
727 printk(KERN_INFO
Stephen Warren384a48d2011-06-01 11:14:21 -0600728 "HDMI CP event: CODEC=%d PIN=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
729 codec->addr,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800730 tag,
731 subtag,
732 cp_state,
733 cp_ready);
734
735 /* TODO */
736 if (cp_state)
737 ;
738 if (cp_ready)
739 ;
740}
741
742
743static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
744{
745 struct hdmi_spec *spec = codec->spec;
746 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
747 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
748
Stephen Warren384a48d2011-06-01 11:14:21 -0600749 if (pin_nid_to_pin_index(spec, tag) < 0) {
Wu Fengguang079d88c2010-03-08 10:44:23 +0800750 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag);
751 return;
752 }
753
754 if (subtag == 0)
755 hdmi_intrinsic_event(codec, res);
756 else
757 hdmi_non_intrinsic_event(codec, res);
758}
759
760/*
761 * Callbacks
762 */
763
Takashi Iwai92f10b32010-08-03 14:21:00 +0200764/* HBR should be Non-PCM, 8 channels */
765#define is_hbr_format(format) \
766 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
767
Stephen Warren384a48d2011-06-01 11:14:21 -0600768static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
769 hda_nid_t pin_nid, u32 stream_tag, int format)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800770{
Anssi Hannulaea87d1c2010-08-03 13:28:58 +0300771 int pinctl;
772 int new_pinctl = 0;
Anssi Hannulaea87d1c2010-08-03 13:28:58 +0300773
Stephen Warren384a48d2011-06-01 11:14:21 -0600774 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
775 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +0300776 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
777
778 new_pinctl = pinctl & ~AC_PINCTL_EPT;
Takashi Iwai92f10b32010-08-03 14:21:00 +0200779 if (is_hbr_format(format))
Anssi Hannulaea87d1c2010-08-03 13:28:58 +0300780 new_pinctl |= AC_PINCTL_EPT_HBR;
781 else
782 new_pinctl |= AC_PINCTL_EPT_NATIVE;
783
784 snd_printdd("hdmi_setup_stream: "
785 "NID=0x%x, %spinctl=0x%x\n",
Stephen Warren384a48d2011-06-01 11:14:21 -0600786 pin_nid,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +0300787 pinctl == new_pinctl ? "" : "new-",
788 new_pinctl);
789
790 if (pinctl != new_pinctl)
Stephen Warren384a48d2011-06-01 11:14:21 -0600791 snd_hda_codec_write(codec, pin_nid, 0,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +0300792 AC_VERB_SET_PIN_WIDGET_CONTROL,
793 new_pinctl);
Anssi Hannulaea87d1c2010-08-03 13:28:58 +0300794
Stephen Warren384a48d2011-06-01 11:14:21 -0600795 }
Takashi Iwai92f10b32010-08-03 14:21:00 +0200796 if (is_hbr_format(format) && !new_pinctl) {
Anssi Hannulaea87d1c2010-08-03 13:28:58 +0300797 snd_printdd("hdmi_setup_stream: HBR is not supported\n");
798 return -EINVAL;
799 }
Wu Fengguang079d88c2010-03-08 10:44:23 +0800800
Stephen Warren384a48d2011-06-01 11:14:21 -0600801 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
Anssi Hannulaea87d1c2010-08-03 13:28:58 +0300802 return 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800803}
804
805/*
Takashi Iwaibbbe3392010-08-13 08:45:23 +0200806 * HDA PCM callbacks
807 */
808static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
809 struct hda_codec *codec,
810 struct snd_pcm_substream *substream)
811{
812 struct hdmi_spec *spec = codec->spec;
Takashi Iwai639cef02011-01-14 10:30:46 +0100813 struct snd_pcm_runtime *runtime = substream->runtime;
Stephen Warren384a48d2011-06-01 11:14:21 -0600814 int pin_idx, cvt_idx, mux_idx = 0;
815 struct hdmi_spec_per_pin *per_pin;
816 struct hdmi_eld *eld;
817 struct hdmi_spec_per_cvt *per_cvt = NULL;
818 int pinctl;
Takashi Iwaibbbe3392010-08-13 08:45:23 +0200819
Stephen Warren384a48d2011-06-01 11:14:21 -0600820 /* Validate hinfo */
821 pin_idx = hinfo_to_pin_index(spec, hinfo);
822 if (snd_BUG_ON(pin_idx < 0))
Takashi Iwaibbbe3392010-08-13 08:45:23 +0200823 return -EINVAL;
Stephen Warren384a48d2011-06-01 11:14:21 -0600824 per_pin = &spec->pins[pin_idx];
825 eld = &per_pin->sink_eld;
Takashi Iwaibbbe3392010-08-13 08:45:23 +0200826
Stephen Warren384a48d2011-06-01 11:14:21 -0600827 /* Dynamically assign converter to stream */
828 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
829 per_cvt = &spec->cvts[cvt_idx];
830
831 /* Must not already be assigned */
832 if (per_cvt->assigned)
833 continue;
834 /* Must be in pin's mux's list of converters */
835 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
836 if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid)
837 break;
838 /* Not in mux list */
839 if (mux_idx == per_pin->num_mux_nids)
840 continue;
841 break;
842 }
843 /* No free converters */
844 if (cvt_idx == spec->num_cvts)
845 return -ENODEV;
846
847 /* Claim converter */
848 per_cvt->assigned = 1;
849 hinfo->nid = per_cvt->cvt_nid;
850
851 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
852 AC_VERB_SET_CONNECT_SEL,
853 mux_idx);
854 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
855 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
856 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
857 AC_VERB_SET_PIN_WIDGET_CONTROL,
858 pinctl | PIN_OUT);
859 snd_hda_spdif_ctls_assign(codec, pin_idx, per_cvt->cvt_nid);
Takashi Iwaibbbe3392010-08-13 08:45:23 +0200860
Stephen Warren2def8172011-06-01 11:14:20 -0600861 /* Initially set the converter's capabilities */
Stephen Warren384a48d2011-06-01 11:14:21 -0600862 hinfo->channels_min = per_cvt->channels_min;
863 hinfo->channels_max = per_cvt->channels_max;
864 hinfo->rates = per_cvt->rates;
865 hinfo->formats = per_cvt->formats;
866 hinfo->maxbps = per_cvt->maxbps;
Stephen Warren2def8172011-06-01 11:14:20 -0600867
Stephen Warren384a48d2011-06-01 11:14:21 -0600868 /* Restrict capabilities by ELD if this isn't disabled */
Stephen Warrenc3d52102011-06-01 11:14:16 -0600869 if (!static_hdmi_pcm && eld->eld_valid) {
Stephen Warren2def8172011-06-01 11:14:20 -0600870 snd_hdmi_eld_update_pcm_info(eld, hinfo);
Takashi Iwaibbbe3392010-08-13 08:45:23 +0200871 if (hinfo->channels_min > hinfo->channels_max ||
872 !hinfo->rates || !hinfo->formats)
873 return -ENODEV;
Takashi Iwaibbbe3392010-08-13 08:45:23 +0200874 }
Stephen Warren2def8172011-06-01 11:14:20 -0600875
876 /* Store the updated parameters */
Takashi Iwai639cef02011-01-14 10:30:46 +0100877 runtime->hw.channels_min = hinfo->channels_min;
878 runtime->hw.channels_max = hinfo->channels_max;
879 runtime->hw.formats = hinfo->formats;
880 runtime->hw.rates = hinfo->rates;
Takashi Iwai4fe2ca12011-01-14 10:33:26 +0100881
882 snd_pcm_hw_constraint_step(substream->runtime, 0,
883 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Takashi Iwaibbbe3392010-08-13 08:45:23 +0200884 return 0;
885}
886
887/*
Wu Fengguang079d88c2010-03-08 10:44:23 +0800888 * HDA/HDMI auto parsing
889 */
Stephen Warren384a48d2011-06-01 11:14:21 -0600890static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800891{
892 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -0600893 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
894 hda_nid_t pin_nid = per_pin->pin_nid;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800895
896 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
897 snd_printk(KERN_WARNING
898 "HDMI: pin %d wcaps %#x "
899 "does not support connection list\n",
900 pin_nid, get_wcaps(codec, pin_nid));
901 return -EINVAL;
902 }
903
Stephen Warren384a48d2011-06-01 11:14:21 -0600904 per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,
905 per_pin->mux_nids,
906 HDA_MAX_CONNECTIONS);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800907
908 return 0;
909}
910
911static void hdmi_present_sense(struct hda_codec *codec, hda_nid_t pin_nid,
912 struct hdmi_eld *eld)
913{
Stephen Warren5d44f922011-05-24 17:11:17 -0600914 /*
915 * Always execute a GetPinSense verb here, even when called from
916 * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
917 * response's PD bit is not the real PD value, but indicates that
918 * the real PD value changed. An older version of the HD-audio
919 * specification worked this way. Hence, we just ignore the data in
920 * the unsolicited response to avoid custom WARs.
921 */
Wu Fengguang079d88c2010-03-08 10:44:23 +0800922 int present = snd_hda_pin_sense(codec, pin_nid);
923
Stephen Warren5d44f922011-05-24 17:11:17 -0600924 memset(eld, 0, sizeof(*eld));
Wu Fengguang079d88c2010-03-08 10:44:23 +0800925
Stephen Warren5d44f922011-05-24 17:11:17 -0600926 eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
927 if (eld->monitor_present)
928 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
929 else
930 eld->eld_valid = 0;
931
932 printk(KERN_INFO
Stephen Warren384a48d2011-06-01 11:14:21 -0600933 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
934 codec->addr, pin_nid, eld->monitor_present, eld->eld_valid);
Stephen Warren5d44f922011-05-24 17:11:17 -0600935
936 if (eld->eld_valid)
937 if (!snd_hdmi_get_eld(eld, codec, pin_nid))
938 snd_hdmi_show_eld(eld);
939
940 snd_hda_input_jack_report(codec, pin_nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800941}
942
943static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
944{
945 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -0600946 unsigned int caps, config;
947 int pin_idx;
948 struct hdmi_spec_per_pin *per_pin;
949 struct hdmi_eld *eld;
David Henningsson07acecc2011-05-19 11:46:03 +0200950 int err;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800951
Stephen Warren384a48d2011-06-01 11:14:21 -0600952 caps = snd_hda_param_read(codec, pin_nid, AC_PAR_PIN_CAP);
953 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
954 return 0;
955
956 config = snd_hda_codec_read(codec, pin_nid, 0,
957 AC_VERB_GET_CONFIG_DEFAULT, 0);
958 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
959 return 0;
960
961 if (snd_BUG_ON(spec->num_pins >= MAX_HDMI_PINS))
Wu Fengguang3eaead52010-05-14 16:36:15 +0800962 return -E2BIG;
Stephen Warren384a48d2011-06-01 11:14:21 -0600963
964 pin_idx = spec->num_pins;
965 per_pin = &spec->pins[pin_idx];
966 eld = &per_pin->sink_eld;
967
968 per_pin->pin_nid = pin_nid;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800969
Stephen Warren384a48d2011-06-01 11:14:21 -0600970 err = hdmi_read_pin_conn(codec, pin_idx);
971 if (err < 0)
972 return err;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800973
Wu Fengguang079d88c2010-03-08 10:44:23 +0800974 spec->num_pins++;
975
Stephen Warren384a48d2011-06-01 11:14:21 -0600976 return 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800977}
978
Stephen Warren384a48d2011-06-01 11:14:21 -0600979static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800980{
981 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -0600982 int cvt_idx;
983 struct hdmi_spec_per_cvt *per_cvt;
984 unsigned int chans;
985 int err;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800986
David Henningsson116dcde2010-11-23 10:23:40 +0100987 if (snd_BUG_ON(spec->num_cvts >= MAX_HDMI_CVTS))
988 return -E2BIG;
989
Stephen Warren384a48d2011-06-01 11:14:21 -0600990 chans = get_wcaps(codec, cvt_nid);
991 chans = get_wcaps_channels(chans);
992
993 cvt_idx = spec->num_cvts;
994 per_cvt = &spec->cvts[cvt_idx];
995
996 per_cvt->cvt_nid = cvt_nid;
997 per_cvt->channels_min = 2;
998 if (chans <= 16)
999 per_cvt->channels_max = chans;
1000
1001 err = snd_hda_query_supported_pcm(codec, cvt_nid,
1002 &per_cvt->rates,
1003 &per_cvt->formats,
1004 &per_cvt->maxbps);
1005 if (err < 0)
1006 return err;
1007
Wu Fengguang079d88c2010-03-08 10:44:23 +08001008 spec->num_cvts++;
1009
1010 return 0;
1011}
1012
1013static int hdmi_parse_codec(struct hda_codec *codec)
1014{
1015 hda_nid_t nid;
1016 int i, nodes;
1017
1018 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
1019 if (!nid || nodes < 0) {
1020 snd_printk(KERN_WARNING "HDMI: failed to get afg sub nodes\n");
1021 return -EINVAL;
1022 }
1023
1024 for (i = 0; i < nodes; i++, nid++) {
1025 unsigned int caps;
1026 unsigned int type;
1027
1028 caps = snd_hda_param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP);
1029 type = get_wcaps_type(caps);
1030
1031 if (!(caps & AC_WCAP_DIGITAL))
1032 continue;
1033
1034 switch (type) {
1035 case AC_WID_AUD_OUT:
Stephen Warren384a48d2011-06-01 11:14:21 -06001036 hdmi_add_cvt(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001037 break;
1038 case AC_WID_PIN:
Wu Fengguang3eaead52010-05-14 16:36:15 +08001039 hdmi_add_pin(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001040 break;
1041 }
1042 }
1043
1044 /*
1045 * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event
1046 * can be lost and presence sense verb will become inaccurate if the
1047 * HDA link is powered off at hot plug or hw initialization time.
1048 */
1049#ifdef CONFIG_SND_HDA_POWER_SAVE
1050 if (!(snd_hda_param_read(codec, codec->afg, AC_PAR_POWER_STATE) &
1051 AC_PWRST_EPSS))
1052 codec->bus->power_keep_link_on = 1;
1053#endif
1054
1055 return 0;
1056}
1057
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001058/*
1059 */
Stephen Warren384a48d2011-06-01 11:14:21 -06001060static char *generic_hdmi_pcm_names[MAX_HDMI_PINS] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001061 "HDMI 0",
1062 "HDMI 1",
1063 "HDMI 2",
Stephen Warren73926652011-05-25 12:42:13 -06001064 "HDMI 3",
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001065};
1066
1067/*
1068 * HDMI callbacks
1069 */
1070
1071static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1072 struct hda_codec *codec,
1073 unsigned int stream_tag,
1074 unsigned int format,
1075 struct snd_pcm_substream *substream)
1076{
Stephen Warren384a48d2011-06-01 11:14:21 -06001077 hda_nid_t cvt_nid = hinfo->nid;
1078 struct hdmi_spec *spec = codec->spec;
1079 int pin_idx = hinfo_to_pin_index(spec, hinfo);
1080 hda_nid_t pin_nid = spec->pins[pin_idx].pin_nid;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001081
Stephen Warren384a48d2011-06-01 11:14:21 -06001082 hdmi_set_channel_count(codec, cvt_nid, substream->runtime->channels);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001083
Stephen Warren384a48d2011-06-01 11:14:21 -06001084 hdmi_setup_audio_infoframe(codec, pin_idx, substream);
1085
1086 return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001087}
1088
Stephen Warren384a48d2011-06-01 11:14:21 -06001089static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1090 struct hda_codec *codec,
1091 struct snd_pcm_substream *substream)
1092{
1093 struct hdmi_spec *spec = codec->spec;
1094 int cvt_idx, pin_idx;
1095 struct hdmi_spec_per_cvt *per_cvt;
1096 struct hdmi_spec_per_pin *per_pin;
1097 int pinctl;
1098
1099 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
1100
1101 if (hinfo->nid) {
1102 cvt_idx = cvt_nid_to_cvt_index(spec, hinfo->nid);
1103 if (snd_BUG_ON(cvt_idx < 0))
1104 return -EINVAL;
1105 per_cvt = &spec->cvts[cvt_idx];
1106
1107 snd_BUG_ON(!per_cvt->assigned);
1108 per_cvt->assigned = 0;
1109 hinfo->nid = 0;
1110
1111 pin_idx = hinfo_to_pin_index(spec, hinfo);
1112 if (snd_BUG_ON(pin_idx < 0))
1113 return -EINVAL;
1114 per_pin = &spec->pins[pin_idx];
1115
1116 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
1117 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1118 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
1119 AC_VERB_SET_PIN_WIDGET_CONTROL,
1120 pinctl & ~PIN_OUT);
1121 snd_hda_spdif_ctls_unassign(codec, pin_idx);
1122 }
1123
1124 return 0;
1125}
1126
1127static const struct hda_pcm_ops generic_ops = {
1128 .open = hdmi_pcm_open,
1129 .prepare = generic_hdmi_playback_pcm_prepare,
1130 .cleanup = generic_hdmi_playback_pcm_cleanup,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001131};
1132
1133static int generic_hdmi_build_pcms(struct hda_codec *codec)
1134{
1135 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001136 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001137
Stephen Warren384a48d2011-06-01 11:14:21 -06001138 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1139 struct hda_pcm *info;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001140 struct hda_pcm_stream *pstr;
1141
Stephen Warren384a48d2011-06-01 11:14:21 -06001142 info = &spec->pcm_rec[pin_idx];
1143 info->name = generic_hdmi_pcm_names[pin_idx];
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001144 info->pcm_type = HDA_PCM_TYPE_HDMI;
Stephen Warren384a48d2011-06-01 11:14:21 -06001145
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001146 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
Stephen Warren384a48d2011-06-01 11:14:21 -06001147 pstr->substreams = 1;
1148 pstr->ops = generic_ops;
1149 /* other pstr fields are set in open */
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001150 }
1151
Stephen Warren384a48d2011-06-01 11:14:21 -06001152 codec->num_pcms = spec->num_pins;
1153 codec->pcm_info = spec->pcm_rec;
1154
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001155 return 0;
1156}
1157
David Henningsson0b6c49b2011-08-23 16:56:03 +02001158static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx)
1159{
1160 int err;
1161 char hdmi_str[32];
1162 struct hdmi_spec *spec = codec->spec;
1163 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
1164 int pcmdev = spec->pcm_rec[pin_idx].device;
1165
1166 snprintf(hdmi_str, sizeof(hdmi_str), "HDMI/DP,pcm=%d", pcmdev);
1167
1168 err = snd_hda_input_jack_add(codec, per_pin->pin_nid,
1169 SND_JACK_VIDEOOUT, pcmdev > 0 ? hdmi_str : NULL);
1170 if (err < 0)
1171 return err;
1172
1173 hdmi_present_sense(codec, per_pin->pin_nid, &per_pin->sink_eld);
1174 return 0;
1175}
1176
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001177static int generic_hdmi_build_controls(struct hda_codec *codec)
1178{
1179 struct hdmi_spec *spec = codec->spec;
1180 int err;
Stephen Warren384a48d2011-06-01 11:14:21 -06001181 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001182
Stephen Warren384a48d2011-06-01 11:14:21 -06001183 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1184 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
David Henningsson0b6c49b2011-08-23 16:56:03 +02001185
1186 err = generic_hdmi_build_jack(codec, pin_idx);
1187 if (err < 0)
1188 return err;
1189
Stephen Warren384a48d2011-06-01 11:14:21 -06001190 err = snd_hda_create_spdif_out_ctls(codec,
1191 per_pin->pin_nid,
1192 per_pin->mux_nids[0]);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001193 if (err < 0)
1194 return err;
Stephen Warren384a48d2011-06-01 11:14:21 -06001195 snd_hda_spdif_ctls_unassign(codec, pin_idx);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001196 }
1197
1198 return 0;
1199}
1200
1201static int generic_hdmi_init(struct hda_codec *codec)
1202{
1203 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001204 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001205
Stephen Warren384a48d2011-06-01 11:14:21 -06001206 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1207 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
1208 hda_nid_t pin_nid = per_pin->pin_nid;
1209 struct hdmi_eld *eld = &per_pin->sink_eld;
1210
1211 hdmi_init_pin(codec, pin_nid);
1212 snd_hda_codec_write(codec, pin_nid, 0,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001213 AC_VERB_SET_UNSOLICITED_ENABLE,
Stephen Warren384a48d2011-06-01 11:14:21 -06001214 AC_USRSP_EN | pin_nid);
1215
1216 snd_hda_eld_proc_new(codec, eld, pin_idx);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001217 }
1218 return 0;
1219}
1220
1221static void generic_hdmi_free(struct hda_codec *codec)
1222{
1223 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001224 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001225
Stephen Warren384a48d2011-06-01 11:14:21 -06001226 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1227 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
1228 struct hdmi_eld *eld = &per_pin->sink_eld;
1229
1230 snd_hda_eld_proc_free(codec, eld);
1231 }
David Henningsson07acecc2011-05-19 11:46:03 +02001232 snd_hda_input_jack_free(codec);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001233
1234 kfree(spec);
1235}
1236
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02001237static const struct hda_codec_ops generic_hdmi_patch_ops = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001238 .init = generic_hdmi_init,
1239 .free = generic_hdmi_free,
1240 .build_pcms = generic_hdmi_build_pcms,
1241 .build_controls = generic_hdmi_build_controls,
1242 .unsol_event = hdmi_unsol_event,
1243};
1244
1245static int patch_generic_hdmi(struct hda_codec *codec)
1246{
1247 struct hdmi_spec *spec;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001248
1249 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1250 if (spec == NULL)
1251 return -ENOMEM;
1252
1253 codec->spec = spec;
1254 if (hdmi_parse_codec(codec) < 0) {
1255 codec->spec = NULL;
1256 kfree(spec);
1257 return -EINVAL;
1258 }
1259 codec->patch_ops = generic_hdmi_patch_ops;
1260
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001261 init_channel_allocations();
1262
1263 return 0;
1264}
1265
1266/*
Stephen Warren3aaf8982011-06-01 11:14:19 -06001267 * Shared non-generic implementations
1268 */
1269
1270static int simple_playback_build_pcms(struct hda_codec *codec)
1271{
1272 struct hdmi_spec *spec = codec->spec;
1273 struct hda_pcm *info = spec->pcm_rec;
1274 int i;
1275
1276 codec->num_pcms = spec->num_cvts;
1277 codec->pcm_info = info;
1278
1279 for (i = 0; i < codec->num_pcms; i++, info++) {
1280 unsigned int chans;
1281 struct hda_pcm_stream *pstr;
1282
Stephen Warren384a48d2011-06-01 11:14:21 -06001283 chans = get_wcaps(codec, spec->cvts[i].cvt_nid);
Stephen Warren3aaf8982011-06-01 11:14:19 -06001284 chans = get_wcaps_channels(chans);
1285
1286 info->name = generic_hdmi_pcm_names[i];
1287 info->pcm_type = HDA_PCM_TYPE_HDMI;
1288 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
1289 snd_BUG_ON(!spec->pcm_playback);
1290 *pstr = *spec->pcm_playback;
Stephen Warren384a48d2011-06-01 11:14:21 -06001291 pstr->nid = spec->cvts[i].cvt_nid;
Stephen Warren3aaf8982011-06-01 11:14:19 -06001292 if (pstr->channels_max <= 2 && chans && chans <= 16)
1293 pstr->channels_max = chans;
1294 }
1295
1296 return 0;
1297}
1298
1299static int simple_playback_build_controls(struct hda_codec *codec)
1300{
1301 struct hdmi_spec *spec = codec->spec;
1302 int err;
1303 int i;
1304
1305 for (i = 0; i < codec->num_pcms; i++) {
1306 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren384a48d2011-06-01 11:14:21 -06001307 spec->cvts[i].cvt_nid,
1308 spec->cvts[i].cvt_nid);
Stephen Warren3aaf8982011-06-01 11:14:19 -06001309 if (err < 0)
1310 return err;
1311 }
1312
1313 return 0;
1314}
1315
1316static void simple_playback_free(struct hda_codec *codec)
1317{
1318 struct hdmi_spec *spec = codec->spec;
1319
1320 kfree(spec);
1321}
1322
1323/*
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001324 * Nvidia specific implementations
1325 */
1326
1327#define Nv_VERB_SET_Channel_Allocation 0xF79
1328#define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
1329#define Nv_VERB_SET_Audio_Protection_On 0xF98
1330#define Nv_VERB_SET_Audio_Protection_Off 0xF99
1331
1332#define nvhdmi_master_con_nid_7x 0x04
1333#define nvhdmi_master_pin_nid_7x 0x05
1334
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02001335static const hda_nid_t nvhdmi_con_nids_7x[4] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001336 /*front, rear, clfe, rear_surr */
1337 0x6, 0x8, 0xa, 0xc,
1338};
1339
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02001340static const struct hda_verb nvhdmi_basic_init_7x[] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001341 /* set audio protect on */
1342 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
1343 /* enable digital output on pin widget */
1344 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1345 { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1346 { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1347 { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1348 { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1349 {} /* terminator */
1350};
1351
1352#ifdef LIMITED_RATE_FMT_SUPPORT
1353/* support only the safe format and rate */
1354#define SUPPORTED_RATES SNDRV_PCM_RATE_48000
1355#define SUPPORTED_MAXBPS 16
1356#define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
1357#else
1358/* support all rates and formats */
1359#define SUPPORTED_RATES \
1360 (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
1361 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
1362 SNDRV_PCM_RATE_192000)
1363#define SUPPORTED_MAXBPS 24
1364#define SUPPORTED_FORMATS \
1365 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
1366#endif
1367
1368static int nvhdmi_7x_init(struct hda_codec *codec)
1369{
1370 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x);
1371 return 0;
1372}
1373
Nitin Daga393004b2011-01-10 21:49:31 +05301374static unsigned int channels_2_6_8[] = {
1375 2, 6, 8
1376};
1377
1378static unsigned int channels_2_8[] = {
1379 2, 8
1380};
1381
1382static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
1383 .count = ARRAY_SIZE(channels_2_6_8),
1384 .list = channels_2_6_8,
1385 .mask = 0,
1386};
1387
1388static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
1389 .count = ARRAY_SIZE(channels_2_8),
1390 .list = channels_2_8,
1391 .mask = 0,
1392};
1393
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001394static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
1395 struct hda_codec *codec,
1396 struct snd_pcm_substream *substream)
1397{
1398 struct hdmi_spec *spec = codec->spec;
Nitin Daga393004b2011-01-10 21:49:31 +05301399 struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
1400
1401 switch (codec->preset->id) {
1402 case 0x10de0002:
1403 case 0x10de0003:
1404 case 0x10de0005:
1405 case 0x10de0006:
1406 hw_constraints_channels = &hw_constraints_2_8_channels;
1407 break;
1408 case 0x10de0007:
1409 hw_constraints_channels = &hw_constraints_2_6_8_channels;
1410 break;
1411 default:
1412 break;
1413 }
1414
1415 if (hw_constraints_channels != NULL) {
1416 snd_pcm_hw_constraint_list(substream->runtime, 0,
1417 SNDRV_PCM_HW_PARAM_CHANNELS,
1418 hw_constraints_channels);
Takashi Iwaiad09fc92011-01-14 09:42:27 +01001419 } else {
1420 snd_pcm_hw_constraint_step(substream->runtime, 0,
1421 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Nitin Daga393004b2011-01-10 21:49:31 +05301422 }
1423
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001424 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1425}
1426
1427static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
1428 struct hda_codec *codec,
1429 struct snd_pcm_substream *substream)
1430{
1431 struct hdmi_spec *spec = codec->spec;
1432 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1433}
1434
1435static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1436 struct hda_codec *codec,
1437 unsigned int stream_tag,
1438 unsigned int format,
1439 struct snd_pcm_substream *substream)
1440{
1441 struct hdmi_spec *spec = codec->spec;
1442 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1443 stream_tag, format, substream);
1444}
1445
Aaron Plattner1f348522011-04-06 17:19:04 -07001446static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
1447 int channels)
1448{
1449 unsigned int chanmask;
1450 int chan = channels ? (channels - 1) : 1;
1451
1452 switch (channels) {
1453 default:
1454 case 0:
1455 case 2:
1456 chanmask = 0x00;
1457 break;
1458 case 4:
1459 chanmask = 0x08;
1460 break;
1461 case 6:
1462 chanmask = 0x0b;
1463 break;
1464 case 8:
1465 chanmask = 0x13;
1466 break;
1467 }
1468
1469 /* Set the audio infoframe channel allocation and checksum fields. The
1470 * channel count is computed implicitly by the hardware. */
1471 snd_hda_codec_write(codec, 0x1, 0,
1472 Nv_VERB_SET_Channel_Allocation, chanmask);
1473
1474 snd_hda_codec_write(codec, 0x1, 0,
1475 Nv_VERB_SET_Info_Frame_Checksum,
1476 (0x71 - chan - chanmask));
1477}
1478
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001479static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
1480 struct hda_codec *codec,
1481 struct snd_pcm_substream *substream)
1482{
1483 struct hdmi_spec *spec = codec->spec;
1484 int i;
1485
1486 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
1487 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
1488 for (i = 0; i < 4; i++) {
1489 /* set the stream id */
1490 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
1491 AC_VERB_SET_CHANNEL_STREAMID, 0);
1492 /* set the stream format */
1493 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
1494 AC_VERB_SET_STREAM_FORMAT, 0);
1495 }
1496
Aaron Plattner1f348522011-04-06 17:19:04 -07001497 /* The audio hardware sends a channel count of 0x7 (8ch) when all the
1498 * streams are disabled. */
1499 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
1500
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001501 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1502}
1503
1504static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
1505 struct hda_codec *codec,
1506 unsigned int stream_tag,
1507 unsigned int format,
1508 struct snd_pcm_substream *substream)
1509{
1510 int chs;
Aaron Plattner1f348522011-04-06 17:19:04 -07001511 unsigned int dataDCC1, dataDCC2, channel_id;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001512 int i;
Stephen Warren7c935972011-06-01 11:14:17 -06001513 struct hdmi_spec *spec = codec->spec;
1514 struct hda_spdif_out *spdif =
Stephen Warren384a48d2011-06-01 11:14:21 -06001515 snd_hda_spdif_out_of_nid(codec, spec->cvts[0].cvt_nid);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001516
1517 mutex_lock(&codec->spdif_mutex);
1518
1519 chs = substream->runtime->channels;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001520
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001521 dataDCC1 = AC_DIG1_ENABLE | AC_DIG1_COPYRIGHT;
1522 dataDCC2 = 0x2;
1523
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001524 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
Stephen Warren7c935972011-06-01 11:14:17 -06001525 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001526 snd_hda_codec_write(codec,
1527 nvhdmi_master_con_nid_7x,
1528 0,
1529 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001530 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001531
1532 /* set the stream id */
1533 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
1534 AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
1535
1536 /* set the stream format */
1537 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
1538 AC_VERB_SET_STREAM_FORMAT, format);
1539
1540 /* turn on again (if needed) */
1541 /* enable and set the channel status audio/data flag */
Stephen Warren7c935972011-06-01 11:14:17 -06001542 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001543 snd_hda_codec_write(codec,
1544 nvhdmi_master_con_nid_7x,
1545 0,
1546 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001547 spdif->ctls & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001548 snd_hda_codec_write(codec,
1549 nvhdmi_master_con_nid_7x,
1550 0,
1551 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
1552 }
1553
1554 for (i = 0; i < 4; i++) {
1555 if (chs == 2)
1556 channel_id = 0;
1557 else
1558 channel_id = i * 2;
1559
1560 /* turn off SPDIF once;
1561 *otherwise the IEC958 bits won't be updated
1562 */
1563 if (codec->spdif_status_reset &&
Stephen Warren7c935972011-06-01 11:14:17 -06001564 (spdif->ctls & AC_DIG1_ENABLE))
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001565 snd_hda_codec_write(codec,
1566 nvhdmi_con_nids_7x[i],
1567 0,
1568 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001569 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001570 /* set the stream id */
1571 snd_hda_codec_write(codec,
1572 nvhdmi_con_nids_7x[i],
1573 0,
1574 AC_VERB_SET_CHANNEL_STREAMID,
1575 (stream_tag << 4) | channel_id);
1576 /* set the stream format */
1577 snd_hda_codec_write(codec,
1578 nvhdmi_con_nids_7x[i],
1579 0,
1580 AC_VERB_SET_STREAM_FORMAT,
1581 format);
1582 /* turn on again (if needed) */
1583 /* enable and set the channel status audio/data flag */
1584 if (codec->spdif_status_reset &&
Stephen Warren7c935972011-06-01 11:14:17 -06001585 (spdif->ctls & AC_DIG1_ENABLE)) {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001586 snd_hda_codec_write(codec,
1587 nvhdmi_con_nids_7x[i],
1588 0,
1589 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001590 spdif->ctls & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001591 snd_hda_codec_write(codec,
1592 nvhdmi_con_nids_7x[i],
1593 0,
1594 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
1595 }
1596 }
1597
Aaron Plattner1f348522011-04-06 17:19:04 -07001598 nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001599
1600 mutex_unlock(&codec->spdif_mutex);
1601 return 0;
1602}
1603
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02001604static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001605 .substreams = 1,
1606 .channels_min = 2,
1607 .channels_max = 8,
1608 .nid = nvhdmi_master_con_nid_7x,
1609 .rates = SUPPORTED_RATES,
1610 .maxbps = SUPPORTED_MAXBPS,
1611 .formats = SUPPORTED_FORMATS,
1612 .ops = {
1613 .open = simple_playback_pcm_open,
1614 .close = nvhdmi_8ch_7x_pcm_close,
1615 .prepare = nvhdmi_8ch_7x_pcm_prepare
1616 },
1617};
1618
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02001619static const struct hda_pcm_stream nvhdmi_pcm_playback_2ch = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001620 .substreams = 1,
1621 .channels_min = 2,
1622 .channels_max = 2,
1623 .nid = nvhdmi_master_con_nid_7x,
1624 .rates = SUPPORTED_RATES,
1625 .maxbps = SUPPORTED_MAXBPS,
1626 .formats = SUPPORTED_FORMATS,
1627 .ops = {
1628 .open = simple_playback_pcm_open,
1629 .close = simple_playback_pcm_close,
1630 .prepare = simple_playback_pcm_prepare
1631 },
1632};
1633
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02001634static const struct hda_codec_ops nvhdmi_patch_ops_8ch_7x = {
Stephen Warren3aaf8982011-06-01 11:14:19 -06001635 .build_controls = simple_playback_build_controls,
1636 .build_pcms = simple_playback_build_pcms,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001637 .init = nvhdmi_7x_init,
Stephen Warren3aaf8982011-06-01 11:14:19 -06001638 .free = simple_playback_free,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001639};
1640
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02001641static const struct hda_codec_ops nvhdmi_patch_ops_2ch = {
Stephen Warren3aaf8982011-06-01 11:14:19 -06001642 .build_controls = simple_playback_build_controls,
1643 .build_pcms = simple_playback_build_pcms,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001644 .init = nvhdmi_7x_init,
Stephen Warren3aaf8982011-06-01 11:14:19 -06001645 .free = simple_playback_free,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001646};
1647
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001648static int patch_nvhdmi_2ch(struct hda_codec *codec)
1649{
1650 struct hdmi_spec *spec;
1651
1652 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1653 if (spec == NULL)
1654 return -ENOMEM;
1655
1656 codec->spec = spec;
1657
1658 spec->multiout.num_dacs = 0; /* no analog */
1659 spec->multiout.max_channels = 2;
1660 spec->multiout.dig_out_nid = nvhdmi_master_con_nid_7x;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001661 spec->num_cvts = 1;
Stephen Warren384a48d2011-06-01 11:14:21 -06001662 spec->cvts[0].cvt_nid = nvhdmi_master_con_nid_7x;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001663 spec->pcm_playback = &nvhdmi_pcm_playback_2ch;
1664
1665 codec->patch_ops = nvhdmi_patch_ops_2ch;
1666
1667 return 0;
1668}
1669
1670static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
1671{
1672 struct hdmi_spec *spec;
1673 int err = patch_nvhdmi_2ch(codec);
1674
1675 if (err < 0)
1676 return err;
1677 spec = codec->spec;
1678 spec->multiout.max_channels = 8;
1679 spec->pcm_playback = &nvhdmi_pcm_playback_8ch_7x;
1680 codec->patch_ops = nvhdmi_patch_ops_8ch_7x;
Aaron Plattner1f348522011-04-06 17:19:04 -07001681
1682 /* Initialize the audio infoframe channel mask and checksum to something
1683 * valid */
1684 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
1685
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001686 return 0;
1687}
1688
1689/*
1690 * ATI-specific implementations
1691 *
1692 * FIXME: we may omit the whole this and use the generic code once after
1693 * it's confirmed to work.
1694 */
1695
1696#define ATIHDMI_CVT_NID 0x02 /* audio converter */
1697#define ATIHDMI_PIN_NID 0x03 /* HDMI output pin */
1698
1699static int atihdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1700 struct hda_codec *codec,
1701 unsigned int stream_tag,
1702 unsigned int format,
1703 struct snd_pcm_substream *substream)
1704{
1705 struct hdmi_spec *spec = codec->spec;
1706 int chans = substream->runtime->channels;
1707 int i, err;
1708
1709 err = simple_playback_pcm_prepare(hinfo, codec, stream_tag, format,
1710 substream);
1711 if (err < 0)
1712 return err;
Stephen Warren384a48d2011-06-01 11:14:21 -06001713 snd_hda_codec_write(codec, spec->cvts[0].cvt_nid, 0,
1714 AC_VERB_SET_CVT_CHAN_COUNT, chans - 1);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001715 /* FIXME: XXX */
1716 for (i = 0; i < chans; i++) {
Stephen Warren384a48d2011-06-01 11:14:21 -06001717 snd_hda_codec_write(codec, spec->cvts[0].cvt_nid, 0,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001718 AC_VERB_SET_HDMI_CHAN_SLOT,
1719 (i << 4) | i);
1720 }
1721 return 0;
1722}
1723
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02001724static const struct hda_pcm_stream atihdmi_pcm_digital_playback = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001725 .substreams = 1,
1726 .channels_min = 2,
1727 .channels_max = 2,
1728 .nid = ATIHDMI_CVT_NID,
1729 .ops = {
1730 .open = simple_playback_pcm_open,
1731 .close = simple_playback_pcm_close,
1732 .prepare = atihdmi_playback_pcm_prepare
1733 },
1734};
1735
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02001736static const struct hda_verb atihdmi_basic_init[] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001737 /* enable digital output on pin widget */
1738 { 0x03, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1739 {} /* terminator */
1740};
1741
1742static int atihdmi_init(struct hda_codec *codec)
1743{
1744 struct hdmi_spec *spec = codec->spec;
1745
1746 snd_hda_sequence_write(codec, atihdmi_basic_init);
1747 /* SI codec requires to unmute the pin */
Stephen Warren384a48d2011-06-01 11:14:21 -06001748 if (get_wcaps(codec, spec->pins[0].pin_nid) & AC_WCAP_OUT_AMP)
1749 snd_hda_codec_write(codec, spec->pins[0].pin_nid, 0,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001750 AC_VERB_SET_AMP_GAIN_MUTE,
1751 AMP_OUT_UNMUTE);
1752 return 0;
1753}
1754
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02001755static const struct hda_codec_ops atihdmi_patch_ops = {
Stephen Warren3aaf8982011-06-01 11:14:19 -06001756 .build_controls = simple_playback_build_controls,
1757 .build_pcms = simple_playback_build_pcms,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001758 .init = atihdmi_init,
Stephen Warren3aaf8982011-06-01 11:14:19 -06001759 .free = simple_playback_free,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001760};
1761
1762
1763static int patch_atihdmi(struct hda_codec *codec)
1764{
1765 struct hdmi_spec *spec;
1766
1767 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1768 if (spec == NULL)
1769 return -ENOMEM;
1770
1771 codec->spec = spec;
1772
1773 spec->multiout.num_dacs = 0; /* no analog */
1774 spec->multiout.max_channels = 2;
1775 spec->multiout.dig_out_nid = ATIHDMI_CVT_NID;
1776 spec->num_cvts = 1;
Stephen Warren384a48d2011-06-01 11:14:21 -06001777 spec->cvts[0].cvt_nid = ATIHDMI_CVT_NID;
1778 spec->pins[0].pin_nid = ATIHDMI_PIN_NID;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001779 spec->pcm_playback = &atihdmi_pcm_digital_playback;
1780
1781 codec->patch_ops = atihdmi_patch_ops;
1782
1783 return 0;
1784}
1785
1786
1787/*
1788 * patch entries
1789 */
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02001790static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001791{ .id = 0x1002793c, .name = "RS600 HDMI", .patch = patch_atihdmi },
1792{ .id = 0x10027919, .name = "RS600 HDMI", .patch = patch_atihdmi },
1793{ .id = 0x1002791a, .name = "RS690/780 HDMI", .patch = patch_atihdmi },
Anssi Hannula36e9c132010-12-05 02:34:15 +02001794{ .id = 0x1002aa01, .name = "R6xx HDMI", .patch = patch_generic_hdmi },
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001795{ .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_generic_hdmi },
1796{ .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_generic_hdmi },
1797{ .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_generic_hdmi },
1798{ .id = 0x10de0002, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
1799{ .id = 0x10de0003, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
1800{ .id = 0x10de0005, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
1801{ .id = 0x10de0006, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
1802{ .id = 0x10de0007, .name = "MCP79/7A HDMI", .patch = patch_nvhdmi_8ch_7x },
Stephen Warren5d44f922011-05-24 17:11:17 -06001803{ .id = 0x10de000a, .name = "GPU 0a HDMI/DP", .patch = patch_generic_hdmi },
1804{ .id = 0x10de000b, .name = "GPU 0b HDMI/DP", .patch = patch_generic_hdmi },
1805{ .id = 0x10de000c, .name = "MCP89 HDMI", .patch = patch_generic_hdmi },
1806{ .id = 0x10de000d, .name = "GPU 0d HDMI/DP", .patch = patch_generic_hdmi },
1807{ .id = 0x10de0010, .name = "GPU 10 HDMI/DP", .patch = patch_generic_hdmi },
1808{ .id = 0x10de0011, .name = "GPU 11 HDMI/DP", .patch = patch_generic_hdmi },
1809{ .id = 0x10de0012, .name = "GPU 12 HDMI/DP", .patch = patch_generic_hdmi },
1810{ .id = 0x10de0013, .name = "GPU 13 HDMI/DP", .patch = patch_generic_hdmi },
1811{ .id = 0x10de0014, .name = "GPU 14 HDMI/DP", .patch = patch_generic_hdmi },
1812{ .id = 0x10de0015, .name = "GPU 15 HDMI/DP", .patch = patch_generic_hdmi },
1813{ .id = 0x10de0016, .name = "GPU 16 HDMI/DP", .patch = patch_generic_hdmi },
Richard Samsonc8900a02011-03-03 12:46:13 +01001814/* 17 is known to be absent */
Stephen Warren5d44f922011-05-24 17:11:17 -06001815{ .id = 0x10de0018, .name = "GPU 18 HDMI/DP", .patch = patch_generic_hdmi },
1816{ .id = 0x10de0019, .name = "GPU 19 HDMI/DP", .patch = patch_generic_hdmi },
1817{ .id = 0x10de001a, .name = "GPU 1a HDMI/DP", .patch = patch_generic_hdmi },
1818{ .id = 0x10de001b, .name = "GPU 1b HDMI/DP", .patch = patch_generic_hdmi },
1819{ .id = 0x10de001c, .name = "GPU 1c HDMI/DP", .patch = patch_generic_hdmi },
1820{ .id = 0x10de0040, .name = "GPU 40 HDMI/DP", .patch = patch_generic_hdmi },
1821{ .id = 0x10de0041, .name = "GPU 41 HDMI/DP", .patch = patch_generic_hdmi },
1822{ .id = 0x10de0042, .name = "GPU 42 HDMI/DP", .patch = patch_generic_hdmi },
1823{ .id = 0x10de0043, .name = "GPU 43 HDMI/DP", .patch = patch_generic_hdmi },
1824{ .id = 0x10de0044, .name = "GPU 44 HDMI/DP", .patch = patch_generic_hdmi },
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001825{ .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch },
1826{ .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch },
1827{ .id = 0x80860054, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi },
1828{ .id = 0x80862801, .name = "Bearlake HDMI", .patch = patch_generic_hdmi },
1829{ .id = 0x80862802, .name = "Cantiga HDMI", .patch = patch_generic_hdmi },
1830{ .id = 0x80862803, .name = "Eaglelake HDMI", .patch = patch_generic_hdmi },
1831{ .id = 0x80862804, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi },
1832{ .id = 0x80862805, .name = "CougarPoint HDMI", .patch = patch_generic_hdmi },
Wu Fengguang591e610d2011-05-20 15:35:43 +08001833{ .id = 0x80862806, .name = "PantherPoint HDMI", .patch = patch_generic_hdmi },
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001834{ .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi },
1835{} /* terminator */
1836};
1837
1838MODULE_ALIAS("snd-hda-codec-id:1002793c");
1839MODULE_ALIAS("snd-hda-codec-id:10027919");
1840MODULE_ALIAS("snd-hda-codec-id:1002791a");
1841MODULE_ALIAS("snd-hda-codec-id:1002aa01");
1842MODULE_ALIAS("snd-hda-codec-id:10951390");
1843MODULE_ALIAS("snd-hda-codec-id:10951392");
1844MODULE_ALIAS("snd-hda-codec-id:10de0002");
1845MODULE_ALIAS("snd-hda-codec-id:10de0003");
1846MODULE_ALIAS("snd-hda-codec-id:10de0005");
1847MODULE_ALIAS("snd-hda-codec-id:10de0006");
1848MODULE_ALIAS("snd-hda-codec-id:10de0007");
1849MODULE_ALIAS("snd-hda-codec-id:10de000a");
1850MODULE_ALIAS("snd-hda-codec-id:10de000b");
1851MODULE_ALIAS("snd-hda-codec-id:10de000c");
1852MODULE_ALIAS("snd-hda-codec-id:10de000d");
1853MODULE_ALIAS("snd-hda-codec-id:10de0010");
1854MODULE_ALIAS("snd-hda-codec-id:10de0011");
1855MODULE_ALIAS("snd-hda-codec-id:10de0012");
1856MODULE_ALIAS("snd-hda-codec-id:10de0013");
1857MODULE_ALIAS("snd-hda-codec-id:10de0014");
Richard Samsonc8900a02011-03-03 12:46:13 +01001858MODULE_ALIAS("snd-hda-codec-id:10de0015");
1859MODULE_ALIAS("snd-hda-codec-id:10de0016");
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001860MODULE_ALIAS("snd-hda-codec-id:10de0018");
1861MODULE_ALIAS("snd-hda-codec-id:10de0019");
1862MODULE_ALIAS("snd-hda-codec-id:10de001a");
1863MODULE_ALIAS("snd-hda-codec-id:10de001b");
1864MODULE_ALIAS("snd-hda-codec-id:10de001c");
1865MODULE_ALIAS("snd-hda-codec-id:10de0040");
1866MODULE_ALIAS("snd-hda-codec-id:10de0041");
1867MODULE_ALIAS("snd-hda-codec-id:10de0042");
1868MODULE_ALIAS("snd-hda-codec-id:10de0043");
1869MODULE_ALIAS("snd-hda-codec-id:10de0044");
1870MODULE_ALIAS("snd-hda-codec-id:10de0067");
1871MODULE_ALIAS("snd-hda-codec-id:10de8001");
1872MODULE_ALIAS("snd-hda-codec-id:17e80047");
1873MODULE_ALIAS("snd-hda-codec-id:80860054");
1874MODULE_ALIAS("snd-hda-codec-id:80862801");
1875MODULE_ALIAS("snd-hda-codec-id:80862802");
1876MODULE_ALIAS("snd-hda-codec-id:80862803");
1877MODULE_ALIAS("snd-hda-codec-id:80862804");
1878MODULE_ALIAS("snd-hda-codec-id:80862805");
Wu Fengguang591e610d2011-05-20 15:35:43 +08001879MODULE_ALIAS("snd-hda-codec-id:80862806");
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001880MODULE_ALIAS("snd-hda-codec-id:808629fb");
1881
1882MODULE_LICENSE("GPL");
1883MODULE_DESCRIPTION("HDMI HD-audio codec");
1884MODULE_ALIAS("snd-hda-codec-intelhdmi");
1885MODULE_ALIAS("snd-hda-codec-nvhdmi");
1886MODULE_ALIAS("snd-hda-codec-atihdmi");
1887
1888static struct hda_codec_preset_list intel_list = {
1889 .preset = snd_hda_preset_hdmi,
1890 .owner = THIS_MODULE,
1891};
1892
1893static int __init patch_hdmi_init(void)
1894{
1895 return snd_hda_add_codec_preset(&intel_list);
1896}
1897
1898static void __exit patch_hdmi_exit(void)
1899{
1900 snd_hda_delete_codec_preset(&intel_list);
1901}
1902
1903module_init(patch_hdmi_init)
1904module_exit(patch_hdmi_exit)