blob: 3824699142eee28d3afc4d1e9e9b829324229e6f [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>
Paul Gortmaker65a77212011-07-15 13:13:37 -040034#include <linux/module.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>
Wang Xingchao433968d2012-09-06 10:02:37 +080037#include <sound/asoundef.h>
Takashi Iwaid45e6882012-07-31 11:36:00 +020038#include <sound/tlv.h>
Takashi Iwai84eb01b2010-09-07 12:27:25 +020039#include "hda_codec.h"
40#include "hda_local.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020041#include "hda_jack.h"
Takashi Iwai84eb01b2010-09-07 12:27:25 +020042
Takashi Iwai0ebaa242011-01-11 18:11:04 +010043static bool static_hdmi_pcm;
44module_param(static_hdmi_pcm, bool, 0644);
45MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
46
Takashi Iwai84eb01b2010-09-07 12:27:25 +020047/*
48 * The HDMI/DisplayPort configuration can be highly dynamic. A graphics device
Stephen Warren384a48d2011-06-01 11:14:21 -060049 * could support N independent pipes, each of them can be connected to one or
Takashi Iwai84eb01b2010-09-07 12:27:25 +020050 * more ports (DVI, HDMI or DisplayPort).
51 *
52 * The HDA correspondence of pipes/ports are converter/pin nodes.
53 */
Takashi Iwaia4567cb2011-11-24 14:44:19 +010054#define MAX_HDMI_CVTS 8
55#define MAX_HDMI_PINS 8
Wu Fengguang079d88c2010-03-08 10:44:23 +080056
Stephen Warren384a48d2011-06-01 11:14:21 -060057struct hdmi_spec_per_cvt {
58 hda_nid_t cvt_nid;
59 int assigned;
60 unsigned int channels_min;
61 unsigned int channels_max;
62 u32 rates;
63 u64 formats;
64 unsigned int maxbps;
65};
66
67struct hdmi_spec_per_pin {
68 hda_nid_t pin_nid;
69 int num_mux_nids;
70 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
Wu Fengguang744626d2011-11-16 16:29:47 +080071
72 struct hda_codec *codec;
Stephen Warren384a48d2011-06-01 11:14:21 -060073 struct hdmi_eld sink_eld;
Wu Fengguang744626d2011-11-16 16:29:47 +080074 struct delayed_work work;
Wu Fengguangc6e84532011-11-18 16:59:32 -060075 int repoll_count;
Takashi Iwai1a6003b2012-09-06 17:42:08 +020076 bool non_pcm;
Takashi Iwaid45e6882012-07-31 11:36:00 +020077 bool chmap_set; /* channel-map override by ALSA API? */
78 unsigned char chmap[8]; /* ALSA API channel-map */
Stephen Warren384a48d2011-06-01 11:14:21 -060079};
80
Wu Fengguang079d88c2010-03-08 10:44:23 +080081struct hdmi_spec {
82 int num_cvts;
Stephen Warren384a48d2011-06-01 11:14:21 -060083 struct hdmi_spec_per_cvt cvts[MAX_HDMI_CVTS];
84
Wu Fengguang079d88c2010-03-08 10:44:23 +080085 int num_pins;
Stephen Warren384a48d2011-06-01 11:14:21 -060086 struct hdmi_spec_per_pin pins[MAX_HDMI_PINS];
87 struct hda_pcm pcm_rec[MAX_HDMI_PINS];
Takashi Iwaid45e6882012-07-31 11:36:00 +020088 unsigned int channels_max; /* max over all cvts */
Wu Fengguang079d88c2010-03-08 10:44:23 +080089
90 /*
Stephen Warren384a48d2011-06-01 11:14:21 -060091 * Non-generic ATI/NVIDIA specific
Wu Fengguang079d88c2010-03-08 10:44:23 +080092 */
93 struct hda_multi_out multiout;
Takashi Iwaid0b12522012-06-15 14:34:42 +020094 struct hda_pcm_stream pcm_playback;
Wu Fengguang079d88c2010-03-08 10:44:23 +080095};
96
97
98struct hdmi_audio_infoframe {
99 u8 type; /* 0x84 */
100 u8 ver; /* 0x01 */
101 u8 len; /* 0x0a */
102
Wu Fengguang53d7d692010-09-21 14:25:49 +0800103 u8 checksum;
104
Wu Fengguang079d88c2010-03-08 10:44:23 +0800105 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
106 u8 SS01_SF24;
107 u8 CXT04;
108 u8 CA;
109 u8 LFEPBL01_LSV36_DM_INH7;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800110};
111
112struct dp_audio_infoframe {
113 u8 type; /* 0x84 */
114 u8 len; /* 0x1b */
115 u8 ver; /* 0x11 << 2 */
116
117 u8 CC02_CT47; /* match with HDMI infoframe from this on */
118 u8 SS01_SF24;
119 u8 CXT04;
120 u8 CA;
121 u8 LFEPBL01_LSV36_DM_INH7;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800122};
123
Takashi Iwai2b203db2011-02-11 12:17:30 +0100124union audio_infoframe {
125 struct hdmi_audio_infoframe hdmi;
126 struct dp_audio_infoframe dp;
127 u8 bytes[0];
128};
129
Wu Fengguang079d88c2010-03-08 10:44:23 +0800130/*
131 * CEA speaker placement:
132 *
133 * FLH FCH FRH
134 * FLW FL FLC FC FRC FR FRW
135 *
136 * LFE
137 * TC
138 *
139 * RL RLC RC RRC RR
140 *
141 * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
142 * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
143 */
144enum cea_speaker_placement {
145 FL = (1 << 0), /* Front Left */
146 FC = (1 << 1), /* Front Center */
147 FR = (1 << 2), /* Front Right */
148 FLC = (1 << 3), /* Front Left Center */
149 FRC = (1 << 4), /* Front Right Center */
150 RL = (1 << 5), /* Rear Left */
151 RC = (1 << 6), /* Rear Center */
152 RR = (1 << 7), /* Rear Right */
153 RLC = (1 << 8), /* Rear Left Center */
154 RRC = (1 << 9), /* Rear Right Center */
155 LFE = (1 << 10), /* Low Frequency Effect */
156 FLW = (1 << 11), /* Front Left Wide */
157 FRW = (1 << 12), /* Front Right Wide */
158 FLH = (1 << 13), /* Front Left High */
159 FCH = (1 << 14), /* Front Center High */
160 FRH = (1 << 15), /* Front Right High */
161 TC = (1 << 16), /* Top Center */
162};
163
164/*
165 * ELD SA bits in the CEA Speaker Allocation data block
166 */
167static int eld_speaker_allocation_bits[] = {
168 [0] = FL | FR,
169 [1] = LFE,
170 [2] = FC,
171 [3] = RL | RR,
172 [4] = RC,
173 [5] = FLC | FRC,
174 [6] = RLC | RRC,
175 /* the following are not defined in ELD yet */
176 [7] = FLW | FRW,
177 [8] = FLH | FRH,
178 [9] = TC,
179 [10] = FCH,
180};
181
182struct cea_channel_speaker_allocation {
183 int ca_index;
184 int speakers[8];
185
186 /* derived values, just for convenience */
187 int channels;
188 int spk_mask;
189};
190
191/*
192 * ALSA sequence is:
193 *
194 * surround40 surround41 surround50 surround51 surround71
195 * ch0 front left = = = =
196 * ch1 front right = = = =
197 * ch2 rear left = = = =
198 * ch3 rear right = = = =
199 * ch4 LFE center center center
200 * ch5 LFE LFE
201 * ch6 side left
202 * ch7 side right
203 *
204 * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR}
205 */
206static int hdmi_channel_mapping[0x32][8] = {
207 /* stereo */
208 [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
209 /* 2.1 */
210 [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
211 /* Dolby Surround */
212 [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 },
213 /* surround40 */
214 [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 },
215 /* 4ch */
216 [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 },
217 /* surround41 */
Jerry Zhou9396d312010-09-21 14:44:51 +0800218 [0x09] = { 0x00, 0x11, 0x24, 0x35, 0x42, 0xf3, 0xf6, 0xf7 },
Wu Fengguang079d88c2010-03-08 10:44:23 +0800219 /* surround50 */
220 [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 },
221 /* surround51 */
222 [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 },
223 /* 7.1 */
224 [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 },
225};
226
227/*
228 * This is an ordered list!
229 *
230 * The preceding ones have better chances to be selected by
Wu Fengguang53d7d692010-09-21 14:25:49 +0800231 * hdmi_channel_allocation().
Wu Fengguang079d88c2010-03-08 10:44:23 +0800232 */
233static struct cea_channel_speaker_allocation channel_allocations[] = {
234/* channel: 7 6 5 4 3 2 1 0 */
235{ .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
236 /* 2.1 */
237{ .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
238 /* Dolby Surround */
239{ .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
240 /* surround40 */
241{ .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
242 /* surround41 */
243{ .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
244 /* surround50 */
245{ .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
246 /* surround51 */
247{ .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
248 /* 6.1 */
249{ .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
250 /* surround71 */
251{ .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
252
253{ .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
254{ .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
255{ .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
256{ .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
257{ .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
258{ .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
259{ .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
260{ .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
261{ .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
262{ .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
263{ .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
264{ .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
265{ .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
266{ .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
267{ .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
268{ .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
269{ .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
270{ .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
271{ .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
272{ .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
273{ .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
274{ .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
275{ .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
276{ .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } },
277{ .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } },
278{ .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } },
279{ .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } },
280{ .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } },
281{ .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } },
282{ .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } },
283{ .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } },
284{ .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } },
285{ .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } },
286{ .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } },
287{ .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } },
288{ .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } },
289{ .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } },
290{ .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } },
291{ .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } },
292{ .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } },
293{ .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
294};
295
296
297/*
298 * HDMI routines
299 */
300
Stephen Warren384a48d2011-06-01 11:14:21 -0600301static int pin_nid_to_pin_index(struct hdmi_spec *spec, hda_nid_t pin_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800302{
Stephen Warren384a48d2011-06-01 11:14:21 -0600303 int pin_idx;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800304
Stephen Warren384a48d2011-06-01 11:14:21 -0600305 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
306 if (spec->pins[pin_idx].pin_nid == pin_nid)
307 return pin_idx;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800308
Stephen Warren384a48d2011-06-01 11:14:21 -0600309 snd_printk(KERN_WARNING "HDMI: pin nid %d not registered\n", pin_nid);
310 return -EINVAL;
311}
312
313static int hinfo_to_pin_index(struct hdmi_spec *spec,
314 struct hda_pcm_stream *hinfo)
315{
316 int pin_idx;
317
318 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
319 if (&spec->pcm_rec[pin_idx].stream[0] == hinfo)
320 return pin_idx;
321
322 snd_printk(KERN_WARNING "HDMI: hinfo %p not registered\n", hinfo);
323 return -EINVAL;
324}
325
326static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid)
327{
328 int cvt_idx;
329
330 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
331 if (spec->cvts[cvt_idx].cvt_nid == cvt_nid)
332 return cvt_idx;
333
334 snd_printk(KERN_WARNING "HDMI: cvt nid %d not registered\n", cvt_nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800335 return -EINVAL;
336}
337
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500338static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
339 struct snd_ctl_elem_info *uinfo)
340{
341 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
342 struct hdmi_spec *spec;
343 int pin_idx;
344
345 spec = codec->spec;
346 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
347
348 pin_idx = kcontrol->private_value;
349 uinfo->count = spec->pins[pin_idx].sink_eld.eld_size;
350
351 return 0;
352}
353
354static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
355 struct snd_ctl_elem_value *ucontrol)
356{
357 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
358 struct hdmi_spec *spec;
359 int pin_idx;
360
361 spec = codec->spec;
362 pin_idx = kcontrol->private_value;
363
364 memcpy(ucontrol->value.bytes.data,
365 spec->pins[pin_idx].sink_eld.eld_buffer, ELD_MAX_SIZE);
366
367 return 0;
368}
369
370static struct snd_kcontrol_new eld_bytes_ctl = {
371 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
372 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
373 .name = "ELD",
374 .info = hdmi_eld_ctl_info,
375 .get = hdmi_eld_ctl_get,
376};
377
378static int hdmi_create_eld_ctl(struct hda_codec *codec, int pin_idx,
379 int device)
380{
381 struct snd_kcontrol *kctl;
382 struct hdmi_spec *spec = codec->spec;
383 int err;
384
385 kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
386 if (!kctl)
387 return -ENOMEM;
388 kctl->private_value = pin_idx;
389 kctl->id.device = device;
390
391 err = snd_hda_ctl_add(codec, spec->pins[pin_idx].pin_nid, kctl);
392 if (err < 0)
393 return err;
394
395 return 0;
396}
397
Wu Fengguang079d88c2010-03-08 10:44:23 +0800398#ifdef BE_PARANOID
399static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
400 int *packet_index, int *byte_index)
401{
402 int val;
403
404 val = snd_hda_codec_read(codec, pin_nid, 0,
405 AC_VERB_GET_HDMI_DIP_INDEX, 0);
406
407 *packet_index = val >> 5;
408 *byte_index = val & 0x1f;
409}
410#endif
411
412static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
413 int packet_index, int byte_index)
414{
415 int val;
416
417 val = (packet_index << 5) | (byte_index & 0x1f);
418
419 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
420}
421
422static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
423 unsigned char val)
424{
425 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
426}
427
Stephen Warren384a48d2011-06-01 11:14:21 -0600428static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800429{
430 /* Unmute */
431 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
432 snd_hda_codec_write(codec, pin_nid, 0,
433 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
Stephen Warren384a48d2011-06-01 11:14:21 -0600434 /* Disable pin out until stream is active*/
Wu Fengguang079d88c2010-03-08 10:44:23 +0800435 snd_hda_codec_write(codec, pin_nid, 0,
Stephen Warren384a48d2011-06-01 11:14:21 -0600436 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800437}
438
Stephen Warren384a48d2011-06-01 11:14:21 -0600439static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800440{
Stephen Warren384a48d2011-06-01 11:14:21 -0600441 return 1 + snd_hda_codec_read(codec, cvt_nid, 0,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800442 AC_VERB_GET_CVT_CHAN_COUNT, 0);
443}
444
445static void hdmi_set_channel_count(struct hda_codec *codec,
Stephen Warren384a48d2011-06-01 11:14:21 -0600446 hda_nid_t cvt_nid, int chs)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800447{
Stephen Warren384a48d2011-06-01 11:14:21 -0600448 if (chs != hdmi_get_channel_count(codec, cvt_nid))
449 snd_hda_codec_write(codec, cvt_nid, 0,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800450 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
451}
452
453
454/*
455 * Channel mapping routines
456 */
457
458/*
459 * Compute derived values in channel_allocations[].
460 */
461static void init_channel_allocations(void)
462{
463 int i, j;
464 struct cea_channel_speaker_allocation *p;
465
466 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
467 p = channel_allocations + i;
468 p->channels = 0;
469 p->spk_mask = 0;
470 for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
471 if (p->speakers[j]) {
472 p->channels++;
473 p->spk_mask |= p->speakers[j];
474 }
475 }
476}
477
Wang Xingchao72357c72012-09-06 10:02:36 +0800478static int get_channel_allocation_order(int ca)
479{
480 int i;
481
482 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
483 if (channel_allocations[i].ca_index == ca)
484 break;
485 }
486 return i;
487}
488
Wu Fengguang079d88c2010-03-08 10:44:23 +0800489/*
490 * The transformation takes two steps:
491 *
492 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
493 * spk_mask => (channel_allocations[]) => ai->CA
494 *
495 * TODO: it could select the wrong CA from multiple candidates.
496*/
Stephen Warren384a48d2011-06-01 11:14:21 -0600497static int hdmi_channel_allocation(struct hdmi_eld *eld, int channels)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800498{
Wu Fengguang079d88c2010-03-08 10:44:23 +0800499 int i;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800500 int ca = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800501 int spk_mask = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800502 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
503
504 /*
505 * CA defaults to 0 for basic stereo audio
506 */
507 if (channels <= 2)
508 return 0;
509
Wu Fengguang079d88c2010-03-08 10:44:23 +0800510 /*
511 * expand ELD's speaker allocation mask
512 *
513 * ELD tells the speaker mask in a compact(paired) form,
514 * expand ELD's notions to match the ones used by Audio InfoFrame.
515 */
516 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
517 if (eld->spk_alloc & (1 << i))
518 spk_mask |= eld_speaker_allocation_bits[i];
519 }
520
521 /* search for the first working match in the CA table */
522 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
523 if (channels == channel_allocations[i].channels &&
524 (spk_mask & channel_allocations[i].spk_mask) ==
525 channel_allocations[i].spk_mask) {
Wu Fengguang53d7d692010-09-21 14:25:49 +0800526 ca = channel_allocations[i].ca_index;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800527 break;
528 }
529 }
530
531 snd_print_channel_allocation(eld->spk_alloc, buf, sizeof(buf));
Wu Fengguang2abbf432010-03-08 10:45:38 +0800532 snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n",
Wu Fengguang53d7d692010-09-21 14:25:49 +0800533 ca, channels, buf);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800534
Wu Fengguang53d7d692010-09-21 14:25:49 +0800535 return ca;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800536}
537
538static void hdmi_debug_channel_mapping(struct hda_codec *codec,
539 hda_nid_t pin_nid)
540{
541#ifdef CONFIG_SND_DEBUG_VERBOSE
542 int i;
543 int slot;
544
545 for (i = 0; i < 8; i++) {
546 slot = snd_hda_codec_read(codec, pin_nid, 0,
547 AC_VERB_GET_HDMI_CHAN_SLOT, i);
548 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n",
549 slot >> 4, slot & 0xf);
550 }
551#endif
552}
553
554
Takashi Iwaid45e6882012-07-31 11:36:00 +0200555static void hdmi_std_setup_channel_mapping(struct hda_codec *codec,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800556 hda_nid_t pin_nid,
Wang Xingchao433968d2012-09-06 10:02:37 +0800557 bool non_pcm,
Wu Fengguang53d7d692010-09-21 14:25:49 +0800558 int ca)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800559{
560 int i;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800561 int err;
Wang Xingchao72357c72012-09-06 10:02:36 +0800562 int order;
Wang Xingchao433968d2012-09-06 10:02:37 +0800563 int non_pcm_mapping[8];
Wu Fengguang079d88c2010-03-08 10:44:23 +0800564
Wang Xingchao72357c72012-09-06 10:02:36 +0800565 order = get_channel_allocation_order(ca);
Wang Xingchao433968d2012-09-06 10:02:37 +0800566
Wu Fengguang079d88c2010-03-08 10:44:23 +0800567 if (hdmi_channel_mapping[ca][1] == 0) {
Wang Xingchao72357c72012-09-06 10:02:36 +0800568 for (i = 0; i < channel_allocations[order].channels; i++)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800569 hdmi_channel_mapping[ca][i] = i | (i << 4);
570 for (; i < 8; i++)
571 hdmi_channel_mapping[ca][i] = 0xf | (i << 4);
572 }
573
Wang Xingchao433968d2012-09-06 10:02:37 +0800574 if (non_pcm) {
575 for (i = 0; i < channel_allocations[order].channels; i++)
576 non_pcm_mapping[i] = i | (i << 4);
577 for (; i < 8; i++)
578 non_pcm_mapping[i] = 0xf | (i << 4);
579 }
580
Wu Fengguang079d88c2010-03-08 10:44:23 +0800581 for (i = 0; i < 8; i++) {
582 err = snd_hda_codec_write(codec, pin_nid, 0,
583 AC_VERB_SET_HDMI_CHAN_SLOT,
Wang Xingchao433968d2012-09-06 10:02:37 +0800584 non_pcm ? non_pcm_mapping[i] : hdmi_channel_mapping[ca][i]);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800585 if (err) {
Wu Fengguang2abbf432010-03-08 10:45:38 +0800586 snd_printdd(KERN_NOTICE
587 "HDMI: channel mapping failed\n");
Wu Fengguang079d88c2010-03-08 10:44:23 +0800588 break;
589 }
590 }
591
592 hdmi_debug_channel_mapping(codec, pin_nid);
593}
594
Takashi Iwaid45e6882012-07-31 11:36:00 +0200595struct channel_map_table {
596 unsigned char map; /* ALSA API channel map position */
597 unsigned char cea_slot; /* CEA slot value */
598 int spk_mask; /* speaker position bit mask */
599};
600
601static struct channel_map_table map_tables[] = {
602 { SNDRV_CHMAP_FL, 0x00, FL },
603 { SNDRV_CHMAP_FR, 0x01, FR },
604 { SNDRV_CHMAP_RL, 0x04, RL },
605 { SNDRV_CHMAP_RR, 0x05, RR },
606 { SNDRV_CHMAP_LFE, 0x02, LFE },
607 { SNDRV_CHMAP_FC, 0x03, FC },
608 { SNDRV_CHMAP_RLC, 0x06, RLC },
609 { SNDRV_CHMAP_RRC, 0x07, RRC },
610 {} /* terminator */
611};
612
613/* from ALSA API channel position to speaker bit mask */
614static int to_spk_mask(unsigned char c)
615{
616 struct channel_map_table *t = map_tables;
617 for (; t->map; t++) {
618 if (t->map == c)
619 return t->spk_mask;
620 }
621 return 0;
622}
623
624/* from ALSA API channel position to CEA slot */
625static int to_cea_slot(unsigned char c)
626{
627 struct channel_map_table *t = map_tables;
628 for (; t->map; t++) {
629 if (t->map == c)
630 return t->cea_slot;
631 }
632 return 0x0f;
633}
634
635/* from CEA slot to ALSA API channel position */
636static int from_cea_slot(unsigned char c)
637{
638 struct channel_map_table *t = map_tables;
639 for (; t->map; t++) {
640 if (t->cea_slot == c)
641 return t->map;
642 }
643 return 0;
644}
645
646/* from speaker bit mask to ALSA API channel position */
647static int spk_to_chmap(int spk)
648{
649 struct channel_map_table *t = map_tables;
650 for (; t->map; t++) {
651 if (t->spk_mask == spk)
652 return t->map;
653 }
654 return 0;
655}
656
657/* get the CA index corresponding to the given ALSA API channel map */
658static int hdmi_manual_channel_allocation(int chs, unsigned char *map)
659{
660 int i, spks = 0, spk_mask = 0;
661
662 for (i = 0; i < chs; i++) {
663 int mask = to_spk_mask(map[i]);
664 if (mask) {
665 spk_mask |= mask;
666 spks++;
667 }
668 }
669
670 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
671 if ((chs == channel_allocations[i].channels ||
672 spks == channel_allocations[i].channels) &&
673 (spk_mask & channel_allocations[i].spk_mask) ==
674 channel_allocations[i].spk_mask)
675 return channel_allocations[i].ca_index;
676 }
677 return -1;
678}
679
680/* set up the channel slots for the given ALSA API channel map */
681static int hdmi_manual_setup_channel_mapping(struct hda_codec *codec,
682 hda_nid_t pin_nid,
683 int chs, unsigned char *map)
684{
685 int i;
686 for (i = 0; i < 8; i++) {
687 int val, err;
688 if (i < chs)
689 val = to_cea_slot(map[i]);
690 else
691 val = 0xf;
692 val |= (i << 4);
693 err = snd_hda_codec_write(codec, pin_nid, 0,
694 AC_VERB_SET_HDMI_CHAN_SLOT, val);
695 if (err)
696 return -EINVAL;
697 }
698 return 0;
699}
700
701/* store ALSA API channel map from the current default map */
702static void hdmi_setup_fake_chmap(unsigned char *map, int ca)
703{
704 int i;
705 for (i = 0; i < 8; i++) {
706 if (i < channel_allocations[ca].channels)
707 map[i] = from_cea_slot((hdmi_channel_mapping[ca][i] >> 4) & 0x0f);
708 else
709 map[i] = 0;
710 }
711}
712
713static void hdmi_setup_channel_mapping(struct hda_codec *codec,
714 hda_nid_t pin_nid, bool non_pcm, int ca,
715 int channels, unsigned char *map)
716{
717 if (!non_pcm && map) {
718 hdmi_manual_setup_channel_mapping(codec, pin_nid,
719 channels, map);
720 } else {
721 hdmi_std_setup_channel_mapping(codec, pin_nid, non_pcm, ca);
722 hdmi_setup_fake_chmap(map, ca);
723 }
724}
Wu Fengguang079d88c2010-03-08 10:44:23 +0800725
726/*
727 * Audio InfoFrame routines
728 */
729
730/*
731 * Enable Audio InfoFrame Transmission
732 */
733static void hdmi_start_infoframe_trans(struct hda_codec *codec,
734 hda_nid_t pin_nid)
735{
736 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
737 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
738 AC_DIPXMIT_BEST);
739}
740
741/*
742 * Disable Audio InfoFrame Transmission
743 */
744static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
745 hda_nid_t pin_nid)
746{
747 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
748 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
749 AC_DIPXMIT_DISABLE);
750}
751
752static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
753{
754#ifdef CONFIG_SND_DEBUG_VERBOSE
755 int i;
756 int size;
757
758 size = snd_hdmi_get_eld_size(codec, pin_nid);
759 printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size);
760
761 for (i = 0; i < 8; i++) {
762 size = snd_hda_codec_read(codec, pin_nid, 0,
763 AC_VERB_GET_HDMI_DIP_SIZE, i);
764 printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size);
765 }
766#endif
767}
768
769static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
770{
771#ifdef BE_PARANOID
772 int i, j;
773 int size;
774 int pi, bi;
775 for (i = 0; i < 8; i++) {
776 size = snd_hda_codec_read(codec, pin_nid, 0,
777 AC_VERB_GET_HDMI_DIP_SIZE, i);
778 if (size == 0)
779 continue;
780
781 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
782 for (j = 1; j < 1000; j++) {
783 hdmi_write_dip_byte(codec, pin_nid, 0x0);
784 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
785 if (pi != i)
786 snd_printd(KERN_INFO "dip index %d: %d != %d\n",
787 bi, pi, i);
788 if (bi == 0) /* byte index wrapped around */
789 break;
790 }
791 snd_printd(KERN_INFO
792 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
793 i, size, j);
794 }
795#endif
796}
797
Wu Fengguang53d7d692010-09-21 14:25:49 +0800798static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800799{
Wu Fengguang53d7d692010-09-21 14:25:49 +0800800 u8 *bytes = (u8 *)hdmi_ai;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800801 u8 sum = 0;
802 int i;
803
Wu Fengguang53d7d692010-09-21 14:25:49 +0800804 hdmi_ai->checksum = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800805
Wu Fengguang53d7d692010-09-21 14:25:49 +0800806 for (i = 0; i < sizeof(*hdmi_ai); i++)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800807 sum += bytes[i];
808
Wu Fengguang53d7d692010-09-21 14:25:49 +0800809 hdmi_ai->checksum = -sum;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800810}
811
812static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
813 hda_nid_t pin_nid,
Wu Fengguang53d7d692010-09-21 14:25:49 +0800814 u8 *dip, int size)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800815{
Wu Fengguang079d88c2010-03-08 10:44:23 +0800816 int i;
817
818 hdmi_debug_dip_size(codec, pin_nid);
819 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
820
Wu Fengguang079d88c2010-03-08 10:44:23 +0800821 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
Wu Fengguang53d7d692010-09-21 14:25:49 +0800822 for (i = 0; i < size; i++)
823 hdmi_write_dip_byte(codec, pin_nid, dip[i]);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800824}
825
826static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
Wu Fengguang53d7d692010-09-21 14:25:49 +0800827 u8 *dip, int size)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800828{
Wu Fengguang079d88c2010-03-08 10:44:23 +0800829 u8 val;
830 int i;
831
832 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
833 != AC_DIPXMIT_BEST)
834 return false;
835
836 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
Wu Fengguang53d7d692010-09-21 14:25:49 +0800837 for (i = 0; i < size; i++) {
Wu Fengguang079d88c2010-03-08 10:44:23 +0800838 val = snd_hda_codec_read(codec, pin_nid, 0,
839 AC_VERB_GET_HDMI_DIP_DATA, 0);
Wu Fengguang53d7d692010-09-21 14:25:49 +0800840 if (val != dip[i])
Wu Fengguang079d88c2010-03-08 10:44:23 +0800841 return false;
842 }
843
844 return true;
845}
846
Stephen Warren384a48d2011-06-01 11:14:21 -0600847static void hdmi_setup_audio_infoframe(struct hda_codec *codec, int pin_idx,
Takashi Iwai1a6003b2012-09-06 17:42:08 +0200848 bool non_pcm,
849 struct snd_pcm_substream *substream)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800850{
851 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -0600852 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
853 hda_nid_t pin_nid = per_pin->pin_nid;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800854 int channels = substream->runtime->channels;
Stephen Warren384a48d2011-06-01 11:14:21 -0600855 struct hdmi_eld *eld;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800856 int ca;
Takashi Iwai2b203db2011-02-11 12:17:30 +0100857 union audio_infoframe ai;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800858
Stephen Warren384a48d2011-06-01 11:14:21 -0600859 eld = &spec->pins[pin_idx].sink_eld;
860 if (!eld->monitor_present)
861 return;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800862
Takashi Iwaid45e6882012-07-31 11:36:00 +0200863 if (!non_pcm && per_pin->chmap_set)
864 ca = hdmi_manual_channel_allocation(channels, per_pin->chmap);
865 else
866 ca = hdmi_channel_allocation(eld, channels);
867 if (ca < 0)
868 ca = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800869
Stephen Warren384a48d2011-06-01 11:14:21 -0600870 memset(&ai, 0, sizeof(ai));
871 if (eld->conn_type == 0) { /* HDMI */
872 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800873
Stephen Warren384a48d2011-06-01 11:14:21 -0600874 hdmi_ai->type = 0x84;
875 hdmi_ai->ver = 0x01;
876 hdmi_ai->len = 0x0a;
877 hdmi_ai->CC02_CT47 = channels - 1;
878 hdmi_ai->CA = ca;
879 hdmi_checksum_audio_infoframe(hdmi_ai);
880 } else if (eld->conn_type == 1) { /* DisplayPort */
881 struct dp_audio_infoframe *dp_ai = &ai.dp;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800882
Stephen Warren384a48d2011-06-01 11:14:21 -0600883 dp_ai->type = 0x84;
884 dp_ai->len = 0x1b;
885 dp_ai->ver = 0x11 << 2;
886 dp_ai->CC02_CT47 = channels - 1;
887 dp_ai->CA = ca;
888 } else {
889 snd_printd("HDMI: unknown connection type at pin %d\n",
890 pin_nid);
891 return;
892 }
Wu Fengguang53d7d692010-09-21 14:25:49 +0800893
Stephen Warren384a48d2011-06-01 11:14:21 -0600894 /*
895 * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
896 * sizeof(*dp_ai) to avoid partial match/update problems when
897 * the user switches between HDMI/DP monitors.
898 */
899 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
900 sizeof(ai))) {
901 snd_printdd("hdmi_setup_audio_infoframe: "
902 "pin=%d channels=%d\n",
903 pin_nid,
904 channels);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200905 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
906 channels, per_pin->chmap);
Stephen Warren384a48d2011-06-01 11:14:21 -0600907 hdmi_stop_infoframe_trans(codec, pin_nid);
908 hdmi_fill_audio_infoframe(codec, pin_nid,
909 ai.bytes, sizeof(ai));
910 hdmi_start_infoframe_trans(codec, pin_nid);
Wang Xingchao2d7e8872012-09-06 10:02:38 +0800911 } else {
912 /* For non-pcm audio switch, setup new channel mapping
913 * accordingly */
Takashi Iwai1a6003b2012-09-06 17:42:08 +0200914 if (per_pin->non_pcm != non_pcm)
Takashi Iwaid45e6882012-07-31 11:36:00 +0200915 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
916 channels, per_pin->chmap);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800917 }
Wang Xingchao433968d2012-09-06 10:02:37 +0800918
Takashi Iwai1a6003b2012-09-06 17:42:08 +0200919 per_pin->non_pcm = non_pcm;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800920}
921
922
923/*
924 * Unsolicited events
925 */
926
Wu Fengguangc6e84532011-11-18 16:59:32 -0600927static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
Takashi Iwai38faddb2010-07-28 14:21:55 +0200928
Wu Fengguang079d88c2010-03-08 10:44:23 +0800929static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
930{
931 struct hdmi_spec *spec = codec->spec;
Takashi Iwai3a938972011-10-28 01:16:55 +0200932 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
933 int pin_nid;
Stephen Warren384a48d2011-06-01 11:14:21 -0600934 int pin_idx;
Takashi Iwai3a938972011-10-28 01:16:55 +0200935 struct hda_jack_tbl *jack;
936
937 jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
938 if (!jack)
939 return;
940 pin_nid = jack->nid;
941 jack->jack_dirty = 1;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800942
Fengguang Wufae3d882012-04-10 17:00:35 +0800943 _snd_printd(SND_PR_VERBOSE,
Stephen Warren384a48d2011-06-01 11:14:21 -0600944 "HDMI hot plug event: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
Fengguang Wufae3d882012-04-10 17:00:35 +0800945 codec->addr, pin_nid,
946 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
Wu Fengguang079d88c2010-03-08 10:44:23 +0800947
Stephen Warren384a48d2011-06-01 11:14:21 -0600948 pin_idx = pin_nid_to_pin_index(spec, pin_nid);
949 if (pin_idx < 0)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800950 return;
951
Wu Fengguangc6e84532011-11-18 16:59:32 -0600952 hdmi_present_sense(&spec->pins[pin_idx], 1);
Takashi Iwai01a61e12011-10-28 00:03:22 +0200953 snd_hda_jack_report_sync(codec);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800954}
955
956static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
957{
958 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
959 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
960 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
961 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
962
963 printk(KERN_INFO
Takashi Iwaie9ea8e82012-06-21 11:41:05 +0200964 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
Stephen Warren384a48d2011-06-01 11:14:21 -0600965 codec->addr,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800966 tag,
967 subtag,
968 cp_state,
969 cp_ready);
970
971 /* TODO */
972 if (cp_state)
973 ;
974 if (cp_ready)
975 ;
976}
977
978
979static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
980{
Wu Fengguang079d88c2010-03-08 10:44:23 +0800981 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
982 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
983
Takashi Iwai3a938972011-10-28 01:16:55 +0200984 if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) {
Wu Fengguang079d88c2010-03-08 10:44:23 +0800985 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag);
986 return;
987 }
988
989 if (subtag == 0)
990 hdmi_intrinsic_event(codec, res);
991 else
992 hdmi_non_intrinsic_event(codec, res);
993}
994
995/*
996 * Callbacks
997 */
998
Takashi Iwai92f10b32010-08-03 14:21:00 +0200999/* HBR should be Non-PCM, 8 channels */
1000#define is_hbr_format(format) \
1001 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
1002
Stephen Warren384a48d2011-06-01 11:14:21 -06001003static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
1004 hda_nid_t pin_nid, u32 stream_tag, int format)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001005{
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001006 int pinctl;
1007 int new_pinctl = 0;
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001008
Stephen Warren384a48d2011-06-01 11:14:21 -06001009 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
1010 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001011 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1012
1013 new_pinctl = pinctl & ~AC_PINCTL_EPT;
Takashi Iwai92f10b32010-08-03 14:21:00 +02001014 if (is_hbr_format(format))
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001015 new_pinctl |= AC_PINCTL_EPT_HBR;
1016 else
1017 new_pinctl |= AC_PINCTL_EPT_NATIVE;
1018
1019 snd_printdd("hdmi_setup_stream: "
1020 "NID=0x%x, %spinctl=0x%x\n",
Stephen Warren384a48d2011-06-01 11:14:21 -06001021 pin_nid,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001022 pinctl == new_pinctl ? "" : "new-",
1023 new_pinctl);
1024
1025 if (pinctl != new_pinctl)
Stephen Warren384a48d2011-06-01 11:14:21 -06001026 snd_hda_codec_write(codec, pin_nid, 0,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001027 AC_VERB_SET_PIN_WIDGET_CONTROL,
1028 new_pinctl);
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001029
Stephen Warren384a48d2011-06-01 11:14:21 -06001030 }
Takashi Iwai92f10b32010-08-03 14:21:00 +02001031 if (is_hbr_format(format) && !new_pinctl) {
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001032 snd_printdd("hdmi_setup_stream: HBR is not supported\n");
1033 return -EINVAL;
1034 }
Wu Fengguang079d88c2010-03-08 10:44:23 +08001035
Stephen Warren384a48d2011-06-01 11:14:21 -06001036 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001037 return 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001038}
1039
1040/*
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001041 * HDA PCM callbacks
1042 */
1043static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1044 struct hda_codec *codec,
1045 struct snd_pcm_substream *substream)
1046{
1047 struct hdmi_spec *spec = codec->spec;
Takashi Iwai639cef02011-01-14 10:30:46 +01001048 struct snd_pcm_runtime *runtime = substream->runtime;
Stephen Warren384a48d2011-06-01 11:14:21 -06001049 int pin_idx, cvt_idx, mux_idx = 0;
1050 struct hdmi_spec_per_pin *per_pin;
1051 struct hdmi_eld *eld;
1052 struct hdmi_spec_per_cvt *per_cvt = NULL;
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001053
Stephen Warren384a48d2011-06-01 11:14:21 -06001054 /* Validate hinfo */
1055 pin_idx = hinfo_to_pin_index(spec, hinfo);
1056 if (snd_BUG_ON(pin_idx < 0))
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001057 return -EINVAL;
Stephen Warren384a48d2011-06-01 11:14:21 -06001058 per_pin = &spec->pins[pin_idx];
1059 eld = &per_pin->sink_eld;
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001060
Stephen Warren384a48d2011-06-01 11:14:21 -06001061 /* Dynamically assign converter to stream */
1062 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
1063 per_cvt = &spec->cvts[cvt_idx];
1064
1065 /* Must not already be assigned */
1066 if (per_cvt->assigned)
1067 continue;
1068 /* Must be in pin's mux's list of converters */
1069 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
1070 if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid)
1071 break;
1072 /* Not in mux list */
1073 if (mux_idx == per_pin->num_mux_nids)
1074 continue;
1075 break;
1076 }
1077 /* No free converters */
1078 if (cvt_idx == spec->num_cvts)
1079 return -ENODEV;
1080
1081 /* Claim converter */
1082 per_cvt->assigned = 1;
1083 hinfo->nid = per_cvt->cvt_nid;
1084
1085 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
1086 AC_VERB_SET_CONNECT_SEL,
1087 mux_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001088 snd_hda_spdif_ctls_assign(codec, pin_idx, per_cvt->cvt_nid);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001089
Stephen Warren2def8172011-06-01 11:14:20 -06001090 /* Initially set the converter's capabilities */
Stephen Warren384a48d2011-06-01 11:14:21 -06001091 hinfo->channels_min = per_cvt->channels_min;
1092 hinfo->channels_max = per_cvt->channels_max;
1093 hinfo->rates = per_cvt->rates;
1094 hinfo->formats = per_cvt->formats;
1095 hinfo->maxbps = per_cvt->maxbps;
Stephen Warren2def8172011-06-01 11:14:20 -06001096
Stephen Warren384a48d2011-06-01 11:14:21 -06001097 /* Restrict capabilities by ELD if this isn't disabled */
Stephen Warrenc3d52102011-06-01 11:14:16 -06001098 if (!static_hdmi_pcm && eld->eld_valid) {
Stephen Warren2def8172011-06-01 11:14:20 -06001099 snd_hdmi_eld_update_pcm_info(eld, hinfo);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001100 if (hinfo->channels_min > hinfo->channels_max ||
1101 !hinfo->rates || !hinfo->formats)
1102 return -ENODEV;
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001103 }
Stephen Warren2def8172011-06-01 11:14:20 -06001104
1105 /* Store the updated parameters */
Takashi Iwai639cef02011-01-14 10:30:46 +01001106 runtime->hw.channels_min = hinfo->channels_min;
1107 runtime->hw.channels_max = hinfo->channels_max;
1108 runtime->hw.formats = hinfo->formats;
1109 runtime->hw.rates = hinfo->rates;
Takashi Iwai4fe2ca12011-01-14 10:33:26 +01001110
1111 snd_pcm_hw_constraint_step(substream->runtime, 0,
1112 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001113 return 0;
1114}
1115
1116/*
Wu Fengguang079d88c2010-03-08 10:44:23 +08001117 * HDA/HDMI auto parsing
1118 */
Stephen Warren384a48d2011-06-01 11:14:21 -06001119static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001120{
1121 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001122 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
1123 hda_nid_t pin_nid = per_pin->pin_nid;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001124
1125 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
1126 snd_printk(KERN_WARNING
1127 "HDMI: pin %d wcaps %#x "
1128 "does not support connection list\n",
1129 pin_nid, get_wcaps(codec, pin_nid));
1130 return -EINVAL;
1131 }
1132
Stephen Warren384a48d2011-06-01 11:14:21 -06001133 per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,
1134 per_pin->mux_nids,
1135 HDA_MAX_CONNECTIONS);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001136
1137 return 0;
1138}
1139
Wu Fengguangc6e84532011-11-18 16:59:32 -06001140static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001141{
Wu Fengguang744626d2011-11-16 16:29:47 +08001142 struct hda_codec *codec = per_pin->codec;
1143 struct hdmi_eld *eld = &per_pin->sink_eld;
1144 hda_nid_t pin_nid = per_pin->pin_nid;
Stephen Warren5d44f922011-05-24 17:11:17 -06001145 /*
1146 * Always execute a GetPinSense verb here, even when called from
1147 * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
1148 * response's PD bit is not the real PD value, but indicates that
1149 * the real PD value changed. An older version of the HD-audio
1150 * specification worked this way. Hence, we just ignore the data in
1151 * the unsolicited response to avoid custom WARs.
1152 */
Wu Fengguang079d88c2010-03-08 10:44:23 +08001153 int present = snd_hda_pin_sense(codec, pin_nid);
Wu Fengguangb95d68b2011-11-16 16:29:46 +08001154 bool eld_valid = false;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001155
Wu Fengguangb95d68b2011-11-16 16:29:46 +08001156 memset(eld, 0, offsetof(struct hdmi_eld, eld_buffer));
Wu Fengguang079d88c2010-03-08 10:44:23 +08001157
Stephen Warren5d44f922011-05-24 17:11:17 -06001158 eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
1159 if (eld->monitor_present)
Wu Fengguangb95d68b2011-11-16 16:29:46 +08001160 eld_valid = !!(present & AC_PINSENSE_ELDV);
Stephen Warren5d44f922011-05-24 17:11:17 -06001161
Fengguang Wufae3d882012-04-10 17:00:35 +08001162 _snd_printd(SND_PR_VERBOSE,
Stephen Warren384a48d2011-06-01 11:14:21 -06001163 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
Wu Fengguangb95d68b2011-11-16 16:29:46 +08001164 codec->addr, pin_nid, eld->monitor_present, eld_valid);
Stephen Warren5d44f922011-05-24 17:11:17 -06001165
Wu Fengguang744626d2011-11-16 16:29:47 +08001166 if (eld_valid) {
Stephen Warren5d44f922011-05-24 17:11:17 -06001167 if (!snd_hdmi_get_eld(eld, codec, pin_nid))
1168 snd_hdmi_show_eld(eld);
Wu Fengguangc6e84532011-11-18 16:59:32 -06001169 else if (repoll) {
Wu Fengguang744626d2011-11-16 16:29:47 +08001170 queue_delayed_work(codec->bus->workq,
1171 &per_pin->work,
1172 msecs_to_jiffies(300));
1173 }
1174 }
Wu Fengguang079d88c2010-03-08 10:44:23 +08001175}
1176
Wu Fengguang744626d2011-11-16 16:29:47 +08001177static void hdmi_repoll_eld(struct work_struct *work)
1178{
1179 struct hdmi_spec_per_pin *per_pin =
1180 container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
1181
Wu Fengguangc6e84532011-11-18 16:59:32 -06001182 if (per_pin->repoll_count++ > 6)
1183 per_pin->repoll_count = 0;
1184
1185 hdmi_present_sense(per_pin, per_pin->repoll_count);
Wu Fengguang744626d2011-11-16 16:29:47 +08001186}
1187
Wu Fengguang079d88c2010-03-08 10:44:23 +08001188static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1189{
1190 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001191 unsigned int caps, config;
1192 int pin_idx;
1193 struct hdmi_spec_per_pin *per_pin;
David Henningsson07acecc2011-05-19 11:46:03 +02001194 int err;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001195
Stephen Warren384a48d2011-06-01 11:14:21 -06001196 caps = snd_hda_param_read(codec, pin_nid, AC_PAR_PIN_CAP);
1197 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
1198 return 0;
1199
1200 config = snd_hda_codec_read(codec, pin_nid, 0,
1201 AC_VERB_GET_CONFIG_DEFAULT, 0);
1202 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
1203 return 0;
1204
1205 if (snd_BUG_ON(spec->num_pins >= MAX_HDMI_PINS))
Wu Fengguang3eaead52010-05-14 16:36:15 +08001206 return -E2BIG;
Stephen Warren384a48d2011-06-01 11:14:21 -06001207
1208 pin_idx = spec->num_pins;
1209 per_pin = &spec->pins[pin_idx];
Stephen Warren384a48d2011-06-01 11:14:21 -06001210
1211 per_pin->pin_nid = pin_nid;
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001212 per_pin->non_pcm = false;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001213
Stephen Warren384a48d2011-06-01 11:14:21 -06001214 err = hdmi_read_pin_conn(codec, pin_idx);
1215 if (err < 0)
1216 return err;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001217
Wu Fengguang079d88c2010-03-08 10:44:23 +08001218 spec->num_pins++;
1219
Stephen Warren384a48d2011-06-01 11:14:21 -06001220 return 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001221}
1222
Stephen Warren384a48d2011-06-01 11:14:21 -06001223static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001224{
1225 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001226 int cvt_idx;
1227 struct hdmi_spec_per_cvt *per_cvt;
1228 unsigned int chans;
1229 int err;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001230
David Henningsson116dcde2010-11-23 10:23:40 +01001231 if (snd_BUG_ON(spec->num_cvts >= MAX_HDMI_CVTS))
1232 return -E2BIG;
1233
Stephen Warren384a48d2011-06-01 11:14:21 -06001234 chans = get_wcaps(codec, cvt_nid);
1235 chans = get_wcaps_channels(chans);
1236
1237 cvt_idx = spec->num_cvts;
1238 per_cvt = &spec->cvts[cvt_idx];
1239
1240 per_cvt->cvt_nid = cvt_nid;
1241 per_cvt->channels_min = 2;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001242 if (chans <= 16) {
Stephen Warren384a48d2011-06-01 11:14:21 -06001243 per_cvt->channels_max = chans;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001244 if (chans > spec->channels_max)
1245 spec->channels_max = chans;
1246 }
Stephen Warren384a48d2011-06-01 11:14:21 -06001247
1248 err = snd_hda_query_supported_pcm(codec, cvt_nid,
1249 &per_cvt->rates,
1250 &per_cvt->formats,
1251 &per_cvt->maxbps);
1252 if (err < 0)
1253 return err;
1254
Wu Fengguang079d88c2010-03-08 10:44:23 +08001255 spec->num_cvts++;
1256
1257 return 0;
1258}
1259
1260static int hdmi_parse_codec(struct hda_codec *codec)
1261{
1262 hda_nid_t nid;
1263 int i, nodes;
1264
1265 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
1266 if (!nid || nodes < 0) {
1267 snd_printk(KERN_WARNING "HDMI: failed to get afg sub nodes\n");
1268 return -EINVAL;
1269 }
1270
1271 for (i = 0; i < nodes; i++, nid++) {
1272 unsigned int caps;
1273 unsigned int type;
1274
1275 caps = snd_hda_param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP);
1276 type = get_wcaps_type(caps);
1277
1278 if (!(caps & AC_WCAP_DIGITAL))
1279 continue;
1280
1281 switch (type) {
1282 case AC_WID_AUD_OUT:
Stephen Warren384a48d2011-06-01 11:14:21 -06001283 hdmi_add_cvt(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001284 break;
1285 case AC_WID_PIN:
Wu Fengguang3eaead52010-05-14 16:36:15 +08001286 hdmi_add_pin(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001287 break;
1288 }
1289 }
1290
David Henningssonc9adeef2012-11-07 09:22:33 +01001291#ifdef CONFIG_PM
1292 /* We're seeing some problems with unsolicited hot plug events on
1293 * PantherPoint after S3, if this is not enabled */
1294 if (codec->vendor_id == 0x80862806)
1295 codec->bus->power_keep_link_on = 1;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001296 /*
1297 * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event
1298 * can be lost and presence sense verb will become inaccurate if the
1299 * HDA link is powered off at hot plug or hw initialization time.
1300 */
David Henningssonc9adeef2012-11-07 09:22:33 +01001301 else if (!(snd_hda_param_read(codec, codec->afg, AC_PAR_POWER_STATE) &
Wu Fengguang079d88c2010-03-08 10:44:23 +08001302 AC_PWRST_EPSS))
1303 codec->bus->power_keep_link_on = 1;
1304#endif
1305
1306 return 0;
1307}
1308
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001309/*
1310 */
Takashi Iwaia4567cb2011-11-24 14:44:19 +01001311static char *get_hdmi_pcm_name(int idx)
1312{
1313 static char names[MAX_HDMI_PINS][8];
1314 sprintf(&names[idx][0], "HDMI %d", idx);
1315 return &names[idx][0];
1316}
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001317
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001318static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1319{
1320 struct hda_spdif_out *spdif;
1321 bool non_pcm;
1322
1323 mutex_lock(&codec->spdif_mutex);
1324 spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
1325 non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO);
1326 mutex_unlock(&codec->spdif_mutex);
1327 return non_pcm;
1328}
1329
1330
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001331/*
1332 * HDMI callbacks
1333 */
1334
1335static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1336 struct hda_codec *codec,
1337 unsigned int stream_tag,
1338 unsigned int format,
1339 struct snd_pcm_substream *substream)
1340{
Stephen Warren384a48d2011-06-01 11:14:21 -06001341 hda_nid_t cvt_nid = hinfo->nid;
1342 struct hdmi_spec *spec = codec->spec;
1343 int pin_idx = hinfo_to_pin_index(spec, hinfo);
1344 hda_nid_t pin_nid = spec->pins[pin_idx].pin_nid;
Dylan Reid9e76e6d2012-07-19 17:52:58 -07001345 int pinctl;
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001346 bool non_pcm;
1347
1348 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001349
Stephen Warren384a48d2011-06-01 11:14:21 -06001350 hdmi_set_channel_count(codec, cvt_nid, substream->runtime->channels);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001351
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001352 hdmi_setup_audio_infoframe(codec, pin_idx, non_pcm, substream);
Stephen Warren384a48d2011-06-01 11:14:21 -06001353
Dylan Reid9e76e6d2012-07-19 17:52:58 -07001354 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
1355 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1356 snd_hda_codec_write(codec, pin_nid, 0,
1357 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl | PIN_OUT);
1358
Stephen Warren384a48d2011-06-01 11:14:21 -06001359 return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001360}
1361
Takashi Iwai8dfaa572012-08-06 14:49:36 +02001362static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1363 struct hda_codec *codec,
1364 struct snd_pcm_substream *substream)
1365{
1366 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
1367 return 0;
1368}
1369
Takashi Iwaif2ad24f2012-07-26 18:08:14 +02001370static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1371 struct hda_codec *codec,
1372 struct snd_pcm_substream *substream)
Stephen Warren384a48d2011-06-01 11:14:21 -06001373{
1374 struct hdmi_spec *spec = codec->spec;
1375 int cvt_idx, pin_idx;
1376 struct hdmi_spec_per_cvt *per_cvt;
1377 struct hdmi_spec_per_pin *per_pin;
1378 int pinctl;
1379
Stephen Warren384a48d2011-06-01 11:14:21 -06001380 if (hinfo->nid) {
1381 cvt_idx = cvt_nid_to_cvt_index(spec, hinfo->nid);
1382 if (snd_BUG_ON(cvt_idx < 0))
1383 return -EINVAL;
1384 per_cvt = &spec->cvts[cvt_idx];
1385
1386 snd_BUG_ON(!per_cvt->assigned);
1387 per_cvt->assigned = 0;
1388 hinfo->nid = 0;
1389
1390 pin_idx = hinfo_to_pin_index(spec, hinfo);
1391 if (snd_BUG_ON(pin_idx < 0))
1392 return -EINVAL;
1393 per_pin = &spec->pins[pin_idx];
1394
1395 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
1396 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1397 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
1398 AC_VERB_SET_PIN_WIDGET_CONTROL,
1399 pinctl & ~PIN_OUT);
1400 snd_hda_spdif_ctls_unassign(codec, pin_idx);
Takashi Iwaid45e6882012-07-31 11:36:00 +02001401 per_pin->chmap_set = false;
1402 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
Stephen Warren384a48d2011-06-01 11:14:21 -06001403 }
Takashi Iwaid45e6882012-07-31 11:36:00 +02001404
Stephen Warren384a48d2011-06-01 11:14:21 -06001405 return 0;
1406}
1407
1408static const struct hda_pcm_ops generic_ops = {
1409 .open = hdmi_pcm_open,
Takashi Iwaif2ad24f2012-07-26 18:08:14 +02001410 .close = hdmi_pcm_close,
Stephen Warren384a48d2011-06-01 11:14:21 -06001411 .prepare = generic_hdmi_playback_pcm_prepare,
Takashi Iwai8dfaa572012-08-06 14:49:36 +02001412 .cleanup = generic_hdmi_playback_pcm_cleanup,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001413};
1414
Takashi Iwaid45e6882012-07-31 11:36:00 +02001415/*
1416 * ALSA API channel-map control callbacks
1417 */
1418static int hdmi_chmap_ctl_info(struct snd_kcontrol *kcontrol,
1419 struct snd_ctl_elem_info *uinfo)
1420{
1421 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
1422 struct hda_codec *codec = info->private_data;
1423 struct hdmi_spec *spec = codec->spec;
1424 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1425 uinfo->count = spec->channels_max;
1426 uinfo->value.integer.min = 0;
1427 uinfo->value.integer.max = SNDRV_CHMAP_LAST;
1428 return 0;
1429}
1430
1431static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1432 unsigned int size, unsigned int __user *tlv)
1433{
1434 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
1435 struct hda_codec *codec = info->private_data;
1436 struct hdmi_spec *spec = codec->spec;
1437 const unsigned int valid_mask =
1438 FL | FR | RL | RR | LFE | FC | RLC | RRC;
1439 unsigned int __user *dst;
1440 int chs, count = 0;
1441
1442 if (size < 8)
1443 return -ENOMEM;
1444 if (put_user(SNDRV_CTL_TLVT_CONTAINER, tlv))
1445 return -EFAULT;
1446 size -= 8;
1447 dst = tlv + 2;
Takashi Iwai498dab32012-09-10 16:08:40 +02001448 for (chs = 2; chs <= spec->channels_max; chs++) {
Takashi Iwaid45e6882012-07-31 11:36:00 +02001449 int i, c;
1450 struct cea_channel_speaker_allocation *cap;
1451 cap = channel_allocations;
1452 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++, cap++) {
1453 int chs_bytes = chs * 4;
1454 if (cap->channels != chs)
1455 continue;
1456 if (cap->spk_mask & ~valid_mask)
1457 continue;
1458 if (size < 8)
1459 return -ENOMEM;
1460 if (put_user(SNDRV_CTL_TLVT_CHMAP_VAR, dst) ||
1461 put_user(chs_bytes, dst + 1))
1462 return -EFAULT;
1463 dst += 2;
1464 size -= 8;
1465 count += 8;
1466 if (size < chs_bytes)
1467 return -ENOMEM;
1468 size -= chs_bytes;
1469 count += chs_bytes;
1470 for (c = 7; c >= 0; c--) {
1471 int spk = cap->speakers[c];
1472 if (!spk)
1473 continue;
1474 if (put_user(spk_to_chmap(spk), dst))
1475 return -EFAULT;
1476 dst++;
1477 }
1478 }
1479 }
1480 if (put_user(count, tlv + 1))
1481 return -EFAULT;
1482 return 0;
1483}
1484
1485static int hdmi_chmap_ctl_get(struct snd_kcontrol *kcontrol,
1486 struct snd_ctl_elem_value *ucontrol)
1487{
1488 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
1489 struct hda_codec *codec = info->private_data;
1490 struct hdmi_spec *spec = codec->spec;
1491 int pin_idx = kcontrol->private_value;
1492 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
1493 int i;
1494
1495 for (i = 0; i < ARRAY_SIZE(per_pin->chmap); i++)
1496 ucontrol->value.integer.value[i] = per_pin->chmap[i];
1497 return 0;
1498}
1499
1500static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
1501 struct snd_ctl_elem_value *ucontrol)
1502{
1503 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
1504 struct hda_codec *codec = info->private_data;
1505 struct hdmi_spec *spec = codec->spec;
1506 int pin_idx = kcontrol->private_value;
1507 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
1508 unsigned int ctl_idx;
1509 struct snd_pcm_substream *substream;
1510 unsigned char chmap[8];
1511 int i, ca, prepared = 0;
1512
1513 ctl_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1514 substream = snd_pcm_chmap_substream(info, ctl_idx);
1515 if (!substream || !substream->runtime)
1516 return -EBADFD;
1517 switch (substream->runtime->status->state) {
1518 case SNDRV_PCM_STATE_OPEN:
1519 case SNDRV_PCM_STATE_SETUP:
1520 break;
1521 case SNDRV_PCM_STATE_PREPARED:
1522 prepared = 1;
1523 break;
1524 default:
1525 return -EBUSY;
1526 }
1527 memset(chmap, 0, sizeof(chmap));
1528 for (i = 0; i < ARRAY_SIZE(chmap); i++)
1529 chmap[i] = ucontrol->value.integer.value[i];
1530 if (!memcmp(chmap, per_pin->chmap, sizeof(chmap)))
1531 return 0;
1532 ca = hdmi_manual_channel_allocation(ARRAY_SIZE(chmap), chmap);
1533 if (ca < 0)
1534 return -EINVAL;
1535 per_pin->chmap_set = true;
1536 memcpy(per_pin->chmap, chmap, sizeof(chmap));
1537 if (prepared)
1538 hdmi_setup_audio_infoframe(codec, pin_idx, per_pin->non_pcm,
1539 substream);
1540
1541 return 0;
1542}
1543
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001544static int generic_hdmi_build_pcms(struct hda_codec *codec)
1545{
1546 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001547 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001548
Stephen Warren384a48d2011-06-01 11:14:21 -06001549 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1550 struct hda_pcm *info;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001551 struct hda_pcm_stream *pstr;
1552
Stephen Warren384a48d2011-06-01 11:14:21 -06001553 info = &spec->pcm_rec[pin_idx];
Takashi Iwaia4567cb2011-11-24 14:44:19 +01001554 info->name = get_hdmi_pcm_name(pin_idx);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001555 info->pcm_type = HDA_PCM_TYPE_HDMI;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001556 info->own_chmap = true;
Stephen Warren384a48d2011-06-01 11:14:21 -06001557
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001558 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
Stephen Warren384a48d2011-06-01 11:14:21 -06001559 pstr->substreams = 1;
1560 pstr->ops = generic_ops;
1561 /* other pstr fields are set in open */
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001562 }
1563
Stephen Warren384a48d2011-06-01 11:14:21 -06001564 codec->num_pcms = spec->num_pins;
1565 codec->pcm_info = spec->pcm_rec;
1566
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001567 return 0;
1568}
1569
David Henningsson0b6c49b2011-08-23 16:56:03 +02001570static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx)
1571{
Takashi Iwai31ef2252011-12-01 17:41:36 +01001572 char hdmi_str[32] = "HDMI/DP";
David Henningsson0b6c49b2011-08-23 16:56:03 +02001573 struct hdmi_spec *spec = codec->spec;
1574 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
1575 int pcmdev = spec->pcm_rec[pin_idx].device;
1576
Takashi Iwai31ef2252011-12-01 17:41:36 +01001577 if (pcmdev > 0)
1578 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
David Henningsson0b6c49b2011-08-23 16:56:03 +02001579
Takashi Iwai31ef2252011-12-01 17:41:36 +01001580 return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str, 0);
David Henningsson0b6c49b2011-08-23 16:56:03 +02001581}
1582
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001583static int generic_hdmi_build_controls(struct hda_codec *codec)
1584{
1585 struct hdmi_spec *spec = codec->spec;
1586 int err;
Stephen Warren384a48d2011-06-01 11:14:21 -06001587 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001588
Stephen Warren384a48d2011-06-01 11:14:21 -06001589 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1590 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
David Henningsson0b6c49b2011-08-23 16:56:03 +02001591
1592 err = generic_hdmi_build_jack(codec, pin_idx);
1593 if (err < 0)
1594 return err;
1595
Takashi Iwaidcda5802012-10-12 17:24:51 +02001596 err = snd_hda_create_dig_out_ctls(codec,
1597 per_pin->pin_nid,
1598 per_pin->mux_nids[0],
1599 HDA_PCM_TYPE_HDMI);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001600 if (err < 0)
1601 return err;
Stephen Warren384a48d2011-06-01 11:14:21 -06001602 snd_hda_spdif_ctls_unassign(codec, pin_idx);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -05001603
1604 /* add control for ELD Bytes */
1605 err = hdmi_create_eld_ctl(codec,
1606 pin_idx,
1607 spec->pcm_rec[pin_idx].device);
1608
1609 if (err < 0)
1610 return err;
Takashi Iwai31ef2252011-12-01 17:41:36 +01001611
Takashi Iwai82b1d732011-12-20 15:53:07 +01001612 hdmi_present_sense(per_pin, 0);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001613 }
1614
Takashi Iwaid45e6882012-07-31 11:36:00 +02001615 /* add channel maps */
1616 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1617 struct snd_pcm_chmap *chmap;
1618 struct snd_kcontrol *kctl;
1619 int i;
1620 err = snd_pcm_add_chmap_ctls(codec->pcm_info[pin_idx].pcm,
1621 SNDRV_PCM_STREAM_PLAYBACK,
1622 NULL, 0, pin_idx, &chmap);
1623 if (err < 0)
1624 return err;
1625 /* override handlers */
1626 chmap->private_data = codec;
1627 kctl = chmap->kctl;
1628 for (i = 0; i < kctl->count; i++)
1629 kctl->vd[i].access |= SNDRV_CTL_ELEM_ACCESS_WRITE;
1630 kctl->info = hdmi_chmap_ctl_info;
1631 kctl->get = hdmi_chmap_ctl_get;
1632 kctl->put = hdmi_chmap_ctl_put;
1633 kctl->tlv.c = hdmi_chmap_ctl_tlv;
1634 }
1635
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001636 return 0;
1637}
1638
Takashi Iwai8b8d6542012-06-20 16:32:22 +02001639static int generic_hdmi_init_per_pins(struct hda_codec *codec)
1640{
1641 struct hdmi_spec *spec = codec->spec;
1642 int pin_idx;
1643
1644 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1645 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
1646 struct hdmi_eld *eld = &per_pin->sink_eld;
1647
1648 per_pin->codec = codec;
1649 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
1650 snd_hda_eld_proc_new(codec, eld, pin_idx);
1651 }
1652 return 0;
1653}
1654
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001655static int generic_hdmi_init(struct hda_codec *codec)
1656{
1657 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001658 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001659
Stephen Warren384a48d2011-06-01 11:14:21 -06001660 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1661 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
1662 hda_nid_t pin_nid = per_pin->pin_nid;
Stephen Warren384a48d2011-06-01 11:14:21 -06001663
1664 hdmi_init_pin(codec, pin_nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001665 snd_hda_jack_detect_enable(codec, pin_nid, pin_nid);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001666 }
1667 return 0;
1668}
1669
1670static void generic_hdmi_free(struct hda_codec *codec)
1671{
1672 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001673 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001674
Stephen Warren384a48d2011-06-01 11:14:21 -06001675 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1676 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
1677 struct hdmi_eld *eld = &per_pin->sink_eld;
1678
Wu Fengguang744626d2011-11-16 16:29:47 +08001679 cancel_delayed_work(&per_pin->work);
Stephen Warren384a48d2011-06-01 11:14:21 -06001680 snd_hda_eld_proc_free(codec, eld);
1681 }
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001682
Wu Fengguang744626d2011-11-16 16:29:47 +08001683 flush_workqueue(codec->bus->workq);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001684 kfree(spec);
1685}
1686
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02001687static const struct hda_codec_ops generic_hdmi_patch_ops = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001688 .init = generic_hdmi_init,
1689 .free = generic_hdmi_free,
1690 .build_pcms = generic_hdmi_build_pcms,
1691 .build_controls = generic_hdmi_build_controls,
1692 .unsol_event = hdmi_unsol_event,
1693};
1694
1695static int patch_generic_hdmi(struct hda_codec *codec)
1696{
1697 struct hdmi_spec *spec;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001698
1699 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1700 if (spec == NULL)
1701 return -ENOMEM;
1702
1703 codec->spec = spec;
1704 if (hdmi_parse_codec(codec) < 0) {
1705 codec->spec = NULL;
1706 kfree(spec);
1707 return -EINVAL;
1708 }
1709 codec->patch_ops = generic_hdmi_patch_ops;
Takashi Iwai8b8d6542012-06-20 16:32:22 +02001710 generic_hdmi_init_per_pins(codec);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001711
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001712 init_channel_allocations();
1713
1714 return 0;
1715}
1716
1717/*
Stephen Warren3aaf8982011-06-01 11:14:19 -06001718 * Shared non-generic implementations
1719 */
1720
1721static int simple_playback_build_pcms(struct hda_codec *codec)
1722{
1723 struct hdmi_spec *spec = codec->spec;
1724 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwai8ceb3322012-06-21 08:23:27 +02001725 unsigned int chans;
1726 struct hda_pcm_stream *pstr;
Stephen Warren3aaf8982011-06-01 11:14:19 -06001727
Takashi Iwai8ceb3322012-06-21 08:23:27 +02001728 codec->num_pcms = 1;
Stephen Warren3aaf8982011-06-01 11:14:19 -06001729 codec->pcm_info = info;
1730
Takashi Iwai8ceb3322012-06-21 08:23:27 +02001731 chans = get_wcaps(codec, spec->cvts[0].cvt_nid);
1732 chans = get_wcaps_channels(chans);
Stephen Warren3aaf8982011-06-01 11:14:19 -06001733
Takashi Iwai8ceb3322012-06-21 08:23:27 +02001734 info->name = get_hdmi_pcm_name(0);
1735 info->pcm_type = HDA_PCM_TYPE_HDMI;
1736 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
1737 *pstr = spec->pcm_playback;
1738 pstr->nid = spec->cvts[0].cvt_nid;
1739 if (pstr->channels_max <= 2 && chans && chans <= 16)
1740 pstr->channels_max = chans;
Stephen Warren3aaf8982011-06-01 11:14:19 -06001741
1742 return 0;
1743}
1744
Takashi Iwai4b6ace92012-06-15 11:53:32 +02001745/* unsolicited event for jack sensing */
1746static void simple_hdmi_unsol_event(struct hda_codec *codec,
1747 unsigned int res)
1748{
Takashi Iwai9dd8cf12012-06-21 10:43:15 +02001749 snd_hda_jack_set_dirty_all(codec);
Takashi Iwai4b6ace92012-06-15 11:53:32 +02001750 snd_hda_jack_report_sync(codec);
1751}
1752
1753/* generic_hdmi_build_jack can be used for simple_hdmi, too,
1754 * as long as spec->pins[] is set correctly
1755 */
1756#define simple_hdmi_build_jack generic_hdmi_build_jack
1757
Stephen Warren3aaf8982011-06-01 11:14:19 -06001758static int simple_playback_build_controls(struct hda_codec *codec)
1759{
1760 struct hdmi_spec *spec = codec->spec;
1761 int err;
Stephen Warren3aaf8982011-06-01 11:14:19 -06001762
Takashi Iwai8ceb3322012-06-21 08:23:27 +02001763 err = snd_hda_create_spdif_out_ctls(codec,
1764 spec->cvts[0].cvt_nid,
1765 spec->cvts[0].cvt_nid);
1766 if (err < 0)
1767 return err;
1768 return simple_hdmi_build_jack(codec, 0);
Stephen Warren3aaf8982011-06-01 11:14:19 -06001769}
1770
Takashi Iwai4f0110c2012-06-15 12:45:43 +02001771static int simple_playback_init(struct hda_codec *codec)
1772{
1773 struct hdmi_spec *spec = codec->spec;
Takashi Iwai8ceb3322012-06-21 08:23:27 +02001774 hda_nid_t pin = spec->pins[0].pin_nid;
Takashi Iwai4f0110c2012-06-15 12:45:43 +02001775
Takashi Iwai8ceb3322012-06-21 08:23:27 +02001776 snd_hda_codec_write(codec, pin, 0,
1777 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1778 /* some codecs require to unmute the pin */
1779 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
1780 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1781 AMP_OUT_UNMUTE);
1782 snd_hda_jack_detect_enable(codec, pin, pin);
Takashi Iwai4f0110c2012-06-15 12:45:43 +02001783 return 0;
1784}
1785
Stephen Warren3aaf8982011-06-01 11:14:19 -06001786static void simple_playback_free(struct hda_codec *codec)
1787{
1788 struct hdmi_spec *spec = codec->spec;
1789
1790 kfree(spec);
1791}
1792
1793/*
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001794 * Nvidia specific implementations
1795 */
1796
1797#define Nv_VERB_SET_Channel_Allocation 0xF79
1798#define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
1799#define Nv_VERB_SET_Audio_Protection_On 0xF98
1800#define Nv_VERB_SET_Audio_Protection_Off 0xF99
1801
1802#define nvhdmi_master_con_nid_7x 0x04
1803#define nvhdmi_master_pin_nid_7x 0x05
1804
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02001805static const hda_nid_t nvhdmi_con_nids_7x[4] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001806 /*front, rear, clfe, rear_surr */
1807 0x6, 0x8, 0xa, 0xc,
1808};
1809
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02001810static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = {
1811 /* set audio protect on */
1812 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
1813 /* enable digital output on pin widget */
1814 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1815 {} /* terminator */
1816};
1817
1818static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001819 /* set audio protect on */
1820 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
1821 /* enable digital output on pin widget */
1822 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1823 { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1824 { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1825 { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1826 { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
1827 {} /* terminator */
1828};
1829
1830#ifdef LIMITED_RATE_FMT_SUPPORT
1831/* support only the safe format and rate */
1832#define SUPPORTED_RATES SNDRV_PCM_RATE_48000
1833#define SUPPORTED_MAXBPS 16
1834#define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
1835#else
1836/* support all rates and formats */
1837#define SUPPORTED_RATES \
1838 (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
1839 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
1840 SNDRV_PCM_RATE_192000)
1841#define SUPPORTED_MAXBPS 24
1842#define SUPPORTED_FORMATS \
1843 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
1844#endif
1845
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02001846static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001847{
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02001848 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
1849 return 0;
1850}
1851
1852static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
1853{
1854 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001855 return 0;
1856}
1857
Nitin Daga393004b2011-01-10 21:49:31 +05301858static unsigned int channels_2_6_8[] = {
1859 2, 6, 8
1860};
1861
1862static unsigned int channels_2_8[] = {
1863 2, 8
1864};
1865
1866static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
1867 .count = ARRAY_SIZE(channels_2_6_8),
1868 .list = channels_2_6_8,
1869 .mask = 0,
1870};
1871
1872static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
1873 .count = ARRAY_SIZE(channels_2_8),
1874 .list = channels_2_8,
1875 .mask = 0,
1876};
1877
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001878static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
1879 struct hda_codec *codec,
1880 struct snd_pcm_substream *substream)
1881{
1882 struct hdmi_spec *spec = codec->spec;
Nitin Daga393004b2011-01-10 21:49:31 +05301883 struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
1884
1885 switch (codec->preset->id) {
1886 case 0x10de0002:
1887 case 0x10de0003:
1888 case 0x10de0005:
1889 case 0x10de0006:
1890 hw_constraints_channels = &hw_constraints_2_8_channels;
1891 break;
1892 case 0x10de0007:
1893 hw_constraints_channels = &hw_constraints_2_6_8_channels;
1894 break;
1895 default:
1896 break;
1897 }
1898
1899 if (hw_constraints_channels != NULL) {
1900 snd_pcm_hw_constraint_list(substream->runtime, 0,
1901 SNDRV_PCM_HW_PARAM_CHANNELS,
1902 hw_constraints_channels);
Takashi Iwaiad09fc92011-01-14 09:42:27 +01001903 } else {
1904 snd_pcm_hw_constraint_step(substream->runtime, 0,
1905 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Nitin Daga393004b2011-01-10 21:49:31 +05301906 }
1907
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001908 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1909}
1910
1911static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
1912 struct hda_codec *codec,
1913 struct snd_pcm_substream *substream)
1914{
1915 struct hdmi_spec *spec = codec->spec;
1916 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1917}
1918
1919static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1920 struct hda_codec *codec,
1921 unsigned int stream_tag,
1922 unsigned int format,
1923 struct snd_pcm_substream *substream)
1924{
1925 struct hdmi_spec *spec = codec->spec;
1926 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1927 stream_tag, format, substream);
1928}
1929
Takashi Iwaid0b12522012-06-15 14:34:42 +02001930static const struct hda_pcm_stream simple_pcm_playback = {
1931 .substreams = 1,
1932 .channels_min = 2,
1933 .channels_max = 2,
1934 .ops = {
1935 .open = simple_playback_pcm_open,
1936 .close = simple_playback_pcm_close,
1937 .prepare = simple_playback_pcm_prepare
1938 },
1939};
1940
1941static const struct hda_codec_ops simple_hdmi_patch_ops = {
1942 .build_controls = simple_playback_build_controls,
1943 .build_pcms = simple_playback_build_pcms,
1944 .init = simple_playback_init,
1945 .free = simple_playback_free,
Takashi Iwai250e41a2012-06-15 14:40:21 +02001946 .unsol_event = simple_hdmi_unsol_event,
Takashi Iwaid0b12522012-06-15 14:34:42 +02001947};
1948
1949static int patch_simple_hdmi(struct hda_codec *codec,
1950 hda_nid_t cvt_nid, hda_nid_t pin_nid)
1951{
1952 struct hdmi_spec *spec;
1953
1954 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1955 if (!spec)
1956 return -ENOMEM;
1957
1958 codec->spec = spec;
1959
1960 spec->multiout.num_dacs = 0; /* no analog */
1961 spec->multiout.max_channels = 2;
1962 spec->multiout.dig_out_nid = cvt_nid;
1963 spec->num_cvts = 1;
1964 spec->num_pins = 1;
1965 spec->cvts[0].cvt_nid = cvt_nid;
Takashi Iwai21cd6832012-06-20 09:19:32 +02001966 spec->pins[0].pin_nid = pin_nid;
Takashi Iwaid0b12522012-06-15 14:34:42 +02001967 spec->pcm_playback = simple_pcm_playback;
1968
1969 codec->patch_ops = simple_hdmi_patch_ops;
1970
1971 return 0;
1972}
1973
Aaron Plattner1f348522011-04-06 17:19:04 -07001974static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
1975 int channels)
1976{
1977 unsigned int chanmask;
1978 int chan = channels ? (channels - 1) : 1;
1979
1980 switch (channels) {
1981 default:
1982 case 0:
1983 case 2:
1984 chanmask = 0x00;
1985 break;
1986 case 4:
1987 chanmask = 0x08;
1988 break;
1989 case 6:
1990 chanmask = 0x0b;
1991 break;
1992 case 8:
1993 chanmask = 0x13;
1994 break;
1995 }
1996
1997 /* Set the audio infoframe channel allocation and checksum fields. The
1998 * channel count is computed implicitly by the hardware. */
1999 snd_hda_codec_write(codec, 0x1, 0,
2000 Nv_VERB_SET_Channel_Allocation, chanmask);
2001
2002 snd_hda_codec_write(codec, 0x1, 0,
2003 Nv_VERB_SET_Info_Frame_Checksum,
2004 (0x71 - chan - chanmask));
2005}
2006
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002007static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
2008 struct hda_codec *codec,
2009 struct snd_pcm_substream *substream)
2010{
2011 struct hdmi_spec *spec = codec->spec;
2012 int i;
2013
2014 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
2015 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
2016 for (i = 0; i < 4; i++) {
2017 /* set the stream id */
2018 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
2019 AC_VERB_SET_CHANNEL_STREAMID, 0);
2020 /* set the stream format */
2021 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
2022 AC_VERB_SET_STREAM_FORMAT, 0);
2023 }
2024
Aaron Plattner1f348522011-04-06 17:19:04 -07002025 /* The audio hardware sends a channel count of 0x7 (8ch) when all the
2026 * streams are disabled. */
2027 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
2028
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002029 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2030}
2031
2032static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
2033 struct hda_codec *codec,
2034 unsigned int stream_tag,
2035 unsigned int format,
2036 struct snd_pcm_substream *substream)
2037{
2038 int chs;
Takashi Iwai112daa72011-11-02 21:40:06 +01002039 unsigned int dataDCC2, channel_id;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002040 int i;
Stephen Warren7c9359762011-06-01 11:14:17 -06002041 struct hdmi_spec *spec = codec->spec;
Takashi Iwaie3245cd2012-05-10 10:21:29 +02002042 struct hda_spdif_out *spdif;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002043
2044 mutex_lock(&codec->spdif_mutex);
Takashi Iwaie3245cd2012-05-10 10:21:29 +02002045 spdif = snd_hda_spdif_out_of_nid(codec, spec->cvts[0].cvt_nid);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002046
2047 chs = substream->runtime->channels;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002048
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002049 dataDCC2 = 0x2;
2050
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002051 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
Stephen Warren7c9359762011-06-01 11:14:17 -06002052 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002053 snd_hda_codec_write(codec,
2054 nvhdmi_master_con_nid_7x,
2055 0,
2056 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c9359762011-06-01 11:14:17 -06002057 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002058
2059 /* set the stream id */
2060 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
2061 AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
2062
2063 /* set the stream format */
2064 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
2065 AC_VERB_SET_STREAM_FORMAT, format);
2066
2067 /* turn on again (if needed) */
2068 /* enable and set the channel status audio/data flag */
Stephen Warren7c9359762011-06-01 11:14:17 -06002069 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002070 snd_hda_codec_write(codec,
2071 nvhdmi_master_con_nid_7x,
2072 0,
2073 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c9359762011-06-01 11:14:17 -06002074 spdif->ctls & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002075 snd_hda_codec_write(codec,
2076 nvhdmi_master_con_nid_7x,
2077 0,
2078 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
2079 }
2080
2081 for (i = 0; i < 4; i++) {
2082 if (chs == 2)
2083 channel_id = 0;
2084 else
2085 channel_id = i * 2;
2086
2087 /* turn off SPDIF once;
2088 *otherwise the IEC958 bits won't be updated
2089 */
2090 if (codec->spdif_status_reset &&
Stephen Warren7c9359762011-06-01 11:14:17 -06002091 (spdif->ctls & AC_DIG1_ENABLE))
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002092 snd_hda_codec_write(codec,
2093 nvhdmi_con_nids_7x[i],
2094 0,
2095 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c9359762011-06-01 11:14:17 -06002096 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002097 /* set the stream id */
2098 snd_hda_codec_write(codec,
2099 nvhdmi_con_nids_7x[i],
2100 0,
2101 AC_VERB_SET_CHANNEL_STREAMID,
2102 (stream_tag << 4) | channel_id);
2103 /* set the stream format */
2104 snd_hda_codec_write(codec,
2105 nvhdmi_con_nids_7x[i],
2106 0,
2107 AC_VERB_SET_STREAM_FORMAT,
2108 format);
2109 /* turn on again (if needed) */
2110 /* enable and set the channel status audio/data flag */
2111 if (codec->spdif_status_reset &&
Stephen Warren7c9359762011-06-01 11:14:17 -06002112 (spdif->ctls & AC_DIG1_ENABLE)) {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002113 snd_hda_codec_write(codec,
2114 nvhdmi_con_nids_7x[i],
2115 0,
2116 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c9359762011-06-01 11:14:17 -06002117 spdif->ctls & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002118 snd_hda_codec_write(codec,
2119 nvhdmi_con_nids_7x[i],
2120 0,
2121 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
2122 }
2123 }
2124
Aaron Plattner1f348522011-04-06 17:19:04 -07002125 nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002126
2127 mutex_unlock(&codec->spdif_mutex);
2128 return 0;
2129}
2130
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02002131static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002132 .substreams = 1,
2133 .channels_min = 2,
2134 .channels_max = 8,
2135 .nid = nvhdmi_master_con_nid_7x,
2136 .rates = SUPPORTED_RATES,
2137 .maxbps = SUPPORTED_MAXBPS,
2138 .formats = SUPPORTED_FORMATS,
2139 .ops = {
2140 .open = simple_playback_pcm_open,
2141 .close = nvhdmi_8ch_7x_pcm_close,
2142 .prepare = nvhdmi_8ch_7x_pcm_prepare
2143 },
2144};
2145
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002146static int patch_nvhdmi_2ch(struct hda_codec *codec)
2147{
2148 struct hdmi_spec *spec;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002149 int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
2150 nvhdmi_master_pin_nid_7x);
2151 if (err < 0)
2152 return err;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002153
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002154 codec->patch_ops.init = nvhdmi_7x_init_2ch;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002155 /* override the PCM rates, etc, as the codec doesn't give full list */
2156 spec = codec->spec;
2157 spec->pcm_playback.rates = SUPPORTED_RATES;
2158 spec->pcm_playback.maxbps = SUPPORTED_MAXBPS;
2159 spec->pcm_playback.formats = SUPPORTED_FORMATS;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002160 return 0;
2161}
2162
Takashi Iwai53775b02012-08-01 12:17:41 +02002163static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
2164{
2165 struct hdmi_spec *spec = codec->spec;
2166 int err = simple_playback_build_pcms(codec);
2167 spec->pcm_rec[0].own_chmap = true;
2168 return err;
2169}
2170
2171static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
2172{
2173 struct hdmi_spec *spec = codec->spec;
2174 struct snd_pcm_chmap *chmap;
2175 int err;
2176
2177 err = simple_playback_build_controls(codec);
2178 if (err < 0)
2179 return err;
2180
2181 /* add channel maps */
2182 err = snd_pcm_add_chmap_ctls(spec->pcm_rec[0].pcm,
2183 SNDRV_PCM_STREAM_PLAYBACK,
2184 snd_pcm_alt_chmaps, 8, 0, &chmap);
2185 if (err < 0)
2186 return err;
2187 switch (codec->preset->id) {
2188 case 0x10de0002:
2189 case 0x10de0003:
2190 case 0x10de0005:
2191 case 0x10de0006:
2192 chmap->channel_mask = (1U << 2) | (1U << 8);
2193 break;
2194 case 0x10de0007:
2195 chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8);
2196 }
2197 return 0;
2198}
2199
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002200static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
2201{
2202 struct hdmi_spec *spec;
2203 int err = patch_nvhdmi_2ch(codec);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002204 if (err < 0)
2205 return err;
2206 spec = codec->spec;
2207 spec->multiout.max_channels = 8;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002208 spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x;
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002209 codec->patch_ops.init = nvhdmi_7x_init_8ch;
Takashi Iwai53775b02012-08-01 12:17:41 +02002210 codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
2211 codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
Aaron Plattner1f348522011-04-06 17:19:04 -07002212
2213 /* Initialize the audio infoframe channel mask and checksum to something
2214 * valid */
2215 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
2216
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002217 return 0;
2218}
2219
2220/*
2221 * ATI-specific implementations
2222 *
2223 * FIXME: we may omit the whole this and use the generic code once after
2224 * it's confirmed to work.
2225 */
2226
2227#define ATIHDMI_CVT_NID 0x02 /* audio converter */
2228#define ATIHDMI_PIN_NID 0x03 /* HDMI output pin */
2229
2230static int atihdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2231 struct hda_codec *codec,
2232 unsigned int stream_tag,
2233 unsigned int format,
2234 struct snd_pcm_substream *substream)
2235{
2236 struct hdmi_spec *spec = codec->spec;
2237 int chans = substream->runtime->channels;
2238 int i, err;
2239
2240 err = simple_playback_pcm_prepare(hinfo, codec, stream_tag, format,
2241 substream);
2242 if (err < 0)
2243 return err;
Stephen Warren384a48d2011-06-01 11:14:21 -06002244 snd_hda_codec_write(codec, spec->cvts[0].cvt_nid, 0,
2245 AC_VERB_SET_CVT_CHAN_COUNT, chans - 1);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002246 /* FIXME: XXX */
2247 for (i = 0; i < chans; i++) {
Stephen Warren384a48d2011-06-01 11:14:21 -06002248 snd_hda_codec_write(codec, spec->cvts[0].cvt_nid, 0,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002249 AC_VERB_SET_HDMI_CHAN_SLOT,
2250 (i << 4) | i);
2251 }
2252 return 0;
2253}
2254
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002255static int patch_atihdmi(struct hda_codec *codec)
2256{
2257 struct hdmi_spec *spec;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002258 int err = patch_simple_hdmi(codec, ATIHDMI_CVT_NID, ATIHDMI_PIN_NID);
2259 if (err < 0)
2260 return err;
2261 spec = codec->spec;
2262 spec->pcm_playback.ops.prepare = atihdmi_playback_pcm_prepare;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002263 return 0;
2264}
2265
Annie Liu3de5ff82012-06-08 19:18:42 +08002266/* VIA HDMI Implementation */
2267#define VIAHDMI_CVT_NID 0x02 /* audio converter1 */
2268#define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */
2269
Annie Liu3de5ff82012-06-08 19:18:42 +08002270static int patch_via_hdmi(struct hda_codec *codec)
2271{
Takashi Iwai250e41a2012-06-15 14:40:21 +02002272 return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
Annie Liu3de5ff82012-06-08 19:18:42 +08002273}
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002274
2275/*
2276 * patch entries
2277 */
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02002278static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002279{ .id = 0x1002793c, .name = "RS600 HDMI", .patch = patch_atihdmi },
2280{ .id = 0x10027919, .name = "RS600 HDMI", .patch = patch_atihdmi },
2281{ .id = 0x1002791a, .name = "RS690/780 HDMI", .patch = patch_atihdmi },
Anssi Hannula36e9c132010-12-05 02:34:15 +02002282{ .id = 0x1002aa01, .name = "R6xx HDMI", .patch = patch_generic_hdmi },
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002283{ .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_generic_hdmi },
2284{ .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_generic_hdmi },
2285{ .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_generic_hdmi },
2286{ .id = 0x10de0002, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2287{ .id = 0x10de0003, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2288{ .id = 0x10de0005, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2289{ .id = 0x10de0006, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2290{ .id = 0x10de0007, .name = "MCP79/7A HDMI", .patch = patch_nvhdmi_8ch_7x },
Stephen Warren5d44f922011-05-24 17:11:17 -06002291{ .id = 0x10de000a, .name = "GPU 0a HDMI/DP", .patch = patch_generic_hdmi },
2292{ .id = 0x10de000b, .name = "GPU 0b HDMI/DP", .patch = patch_generic_hdmi },
2293{ .id = 0x10de000c, .name = "MCP89 HDMI", .patch = patch_generic_hdmi },
2294{ .id = 0x10de000d, .name = "GPU 0d HDMI/DP", .patch = patch_generic_hdmi },
2295{ .id = 0x10de0010, .name = "GPU 10 HDMI/DP", .patch = patch_generic_hdmi },
2296{ .id = 0x10de0011, .name = "GPU 11 HDMI/DP", .patch = patch_generic_hdmi },
2297{ .id = 0x10de0012, .name = "GPU 12 HDMI/DP", .patch = patch_generic_hdmi },
2298{ .id = 0x10de0013, .name = "GPU 13 HDMI/DP", .patch = patch_generic_hdmi },
2299{ .id = 0x10de0014, .name = "GPU 14 HDMI/DP", .patch = patch_generic_hdmi },
2300{ .id = 0x10de0015, .name = "GPU 15 HDMI/DP", .patch = patch_generic_hdmi },
2301{ .id = 0x10de0016, .name = "GPU 16 HDMI/DP", .patch = patch_generic_hdmi },
Richard Samsonc8900a02011-03-03 12:46:13 +01002302/* 17 is known to be absent */
Stephen Warren5d44f922011-05-24 17:11:17 -06002303{ .id = 0x10de0018, .name = "GPU 18 HDMI/DP", .patch = patch_generic_hdmi },
2304{ .id = 0x10de0019, .name = "GPU 19 HDMI/DP", .patch = patch_generic_hdmi },
2305{ .id = 0x10de001a, .name = "GPU 1a HDMI/DP", .patch = patch_generic_hdmi },
2306{ .id = 0x10de001b, .name = "GPU 1b HDMI/DP", .patch = patch_generic_hdmi },
2307{ .id = 0x10de001c, .name = "GPU 1c HDMI/DP", .patch = patch_generic_hdmi },
2308{ .id = 0x10de0040, .name = "GPU 40 HDMI/DP", .patch = patch_generic_hdmi },
2309{ .id = 0x10de0041, .name = "GPU 41 HDMI/DP", .patch = patch_generic_hdmi },
2310{ .id = 0x10de0042, .name = "GPU 42 HDMI/DP", .patch = patch_generic_hdmi },
2311{ .id = 0x10de0043, .name = "GPU 43 HDMI/DP", .patch = patch_generic_hdmi },
2312{ .id = 0x10de0044, .name = "GPU 44 HDMI/DP", .patch = patch_generic_hdmi },
Aaron Plattner7ae48b52012-07-16 17:10:04 -07002313{ .id = 0x10de0051, .name = "GPU 51 HDMI/DP", .patch = patch_generic_hdmi },
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002314{ .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch },
2315{ .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch },
Annie Liu3de5ff82012-06-08 19:18:42 +08002316{ .id = 0x11069f80, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi },
2317{ .id = 0x11069f81, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi },
2318{ .id = 0x11069f84, .name = "VX11 HDMI/DP", .patch = patch_generic_hdmi },
2319{ .id = 0x11069f85, .name = "VX11 HDMI/DP", .patch = patch_generic_hdmi },
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002320{ .id = 0x80860054, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi },
2321{ .id = 0x80862801, .name = "Bearlake HDMI", .patch = patch_generic_hdmi },
2322{ .id = 0x80862802, .name = "Cantiga HDMI", .patch = patch_generic_hdmi },
2323{ .id = 0x80862803, .name = "Eaglelake HDMI", .patch = patch_generic_hdmi },
2324{ .id = 0x80862804, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi },
2325{ .id = 0x80862805, .name = "CougarPoint HDMI", .patch = patch_generic_hdmi },
Wu Fengguang591e6102011-05-20 15:35:43 +08002326{ .id = 0x80862806, .name = "PantherPoint HDMI", .patch = patch_generic_hdmi },
Wang Xingchao1c766842012-06-13 10:23:52 +08002327{ .id = 0x80862807, .name = "Haswell HDMI", .patch = patch_generic_hdmi },
Wu Fengguang6edc59e2012-02-23 15:07:44 +08002328{ .id = 0x80862880, .name = "CedarTrail HDMI", .patch = patch_generic_hdmi },
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002329{ .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi },
2330{} /* terminator */
2331};
2332
2333MODULE_ALIAS("snd-hda-codec-id:1002793c");
2334MODULE_ALIAS("snd-hda-codec-id:10027919");
2335MODULE_ALIAS("snd-hda-codec-id:1002791a");
2336MODULE_ALIAS("snd-hda-codec-id:1002aa01");
2337MODULE_ALIAS("snd-hda-codec-id:10951390");
2338MODULE_ALIAS("snd-hda-codec-id:10951392");
2339MODULE_ALIAS("snd-hda-codec-id:10de0002");
2340MODULE_ALIAS("snd-hda-codec-id:10de0003");
2341MODULE_ALIAS("snd-hda-codec-id:10de0005");
2342MODULE_ALIAS("snd-hda-codec-id:10de0006");
2343MODULE_ALIAS("snd-hda-codec-id:10de0007");
2344MODULE_ALIAS("snd-hda-codec-id:10de000a");
2345MODULE_ALIAS("snd-hda-codec-id:10de000b");
2346MODULE_ALIAS("snd-hda-codec-id:10de000c");
2347MODULE_ALIAS("snd-hda-codec-id:10de000d");
2348MODULE_ALIAS("snd-hda-codec-id:10de0010");
2349MODULE_ALIAS("snd-hda-codec-id:10de0011");
2350MODULE_ALIAS("snd-hda-codec-id:10de0012");
2351MODULE_ALIAS("snd-hda-codec-id:10de0013");
2352MODULE_ALIAS("snd-hda-codec-id:10de0014");
Richard Samsonc8900a02011-03-03 12:46:13 +01002353MODULE_ALIAS("snd-hda-codec-id:10de0015");
2354MODULE_ALIAS("snd-hda-codec-id:10de0016");
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002355MODULE_ALIAS("snd-hda-codec-id:10de0018");
2356MODULE_ALIAS("snd-hda-codec-id:10de0019");
2357MODULE_ALIAS("snd-hda-codec-id:10de001a");
2358MODULE_ALIAS("snd-hda-codec-id:10de001b");
2359MODULE_ALIAS("snd-hda-codec-id:10de001c");
2360MODULE_ALIAS("snd-hda-codec-id:10de0040");
2361MODULE_ALIAS("snd-hda-codec-id:10de0041");
2362MODULE_ALIAS("snd-hda-codec-id:10de0042");
2363MODULE_ALIAS("snd-hda-codec-id:10de0043");
2364MODULE_ALIAS("snd-hda-codec-id:10de0044");
Aaron Plattner7ae48b52012-07-16 17:10:04 -07002365MODULE_ALIAS("snd-hda-codec-id:10de0051");
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002366MODULE_ALIAS("snd-hda-codec-id:10de0067");
2367MODULE_ALIAS("snd-hda-codec-id:10de8001");
Annie Liu3de5ff82012-06-08 19:18:42 +08002368MODULE_ALIAS("snd-hda-codec-id:11069f80");
2369MODULE_ALIAS("snd-hda-codec-id:11069f81");
2370MODULE_ALIAS("snd-hda-codec-id:11069f84");
2371MODULE_ALIAS("snd-hda-codec-id:11069f85");
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002372MODULE_ALIAS("snd-hda-codec-id:17e80047");
2373MODULE_ALIAS("snd-hda-codec-id:80860054");
2374MODULE_ALIAS("snd-hda-codec-id:80862801");
2375MODULE_ALIAS("snd-hda-codec-id:80862802");
2376MODULE_ALIAS("snd-hda-codec-id:80862803");
2377MODULE_ALIAS("snd-hda-codec-id:80862804");
2378MODULE_ALIAS("snd-hda-codec-id:80862805");
Wu Fengguang591e6102011-05-20 15:35:43 +08002379MODULE_ALIAS("snd-hda-codec-id:80862806");
Wang Xingchao1c766842012-06-13 10:23:52 +08002380MODULE_ALIAS("snd-hda-codec-id:80862807");
Wu Fengguang6edc59e2012-02-23 15:07:44 +08002381MODULE_ALIAS("snd-hda-codec-id:80862880");
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002382MODULE_ALIAS("snd-hda-codec-id:808629fb");
2383
2384MODULE_LICENSE("GPL");
2385MODULE_DESCRIPTION("HDMI HD-audio codec");
2386MODULE_ALIAS("snd-hda-codec-intelhdmi");
2387MODULE_ALIAS("snd-hda-codec-nvhdmi");
2388MODULE_ALIAS("snd-hda-codec-atihdmi");
2389
2390static struct hda_codec_preset_list intel_list = {
2391 .preset = snd_hda_preset_hdmi,
2392 .owner = THIS_MODULE,
2393};
2394
2395static int __init patch_hdmi_init(void)
2396{
2397 return snd_hda_add_codec_preset(&intel_list);
2398}
2399
2400static void __exit patch_hdmi_exit(void)
2401{
2402 snd_hda_delete_codec_preset(&intel_list);
2403}
2404
2405module_init(patch_hdmi_init)
2406module_exit(patch_hdmi_exit)