blob: 8c1d1cf0c0cdd6e9220820844e39f4a1c6dbfd1d [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
Stephen Warren384a48d2011-06-01 11:14:21 -060047struct hdmi_spec_per_cvt {
48 hda_nid_t cvt_nid;
49 int assigned;
50 unsigned int channels_min;
51 unsigned int channels_max;
52 u32 rates;
53 u64 formats;
54 unsigned int maxbps;
55};
56
Takashi Iwai4eea3092013-02-07 18:18:19 +010057/* max. connections to a widget */
58#define HDA_MAX_CONNECTIONS 32
59
Stephen Warren384a48d2011-06-01 11:14:21 -060060struct hdmi_spec_per_pin {
61 hda_nid_t pin_nid;
62 int num_mux_nids;
63 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
Wu Fengguang744626d2011-11-16 16:29:47 +080064
65 struct hda_codec *codec;
Stephen Warren384a48d2011-06-01 11:14:21 -060066 struct hdmi_eld sink_eld;
Wu Fengguang744626d2011-11-16 16:29:47 +080067 struct delayed_work work;
David Henningsson92c69e72013-02-19 16:11:26 +010068 struct snd_kcontrol *eld_ctl;
Wu Fengguangc6e84532011-11-18 16:59:32 -060069 int repoll_count;
Takashi Iwaidc780f72013-09-02 12:33:02 +020070 bool setup; /* the stream has been set up by prepare callback */
71 int channels; /* current number of channels */
Takashi Iwai1a6003b2012-09-06 17:42:08 +020072 bool non_pcm;
Takashi Iwaid45e6882012-07-31 11:36:00 +020073 bool chmap_set; /* channel-map override by ALSA API? */
74 unsigned char chmap[8]; /* ALSA API channel-map */
Takashi Iwaibce0d2a2013-03-13 14:40:31 +010075 char pcm_name[8]; /* filled in build_pcm callbacks */
Stephen Warren384a48d2011-06-01 11:14:21 -060076};
77
Wu Fengguang079d88c2010-03-08 10:44:23 +080078struct hdmi_spec {
79 int num_cvts;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +010080 struct snd_array cvts; /* struct hdmi_spec_per_cvt */
81 hda_nid_t cvt_nids[4]; /* only for haswell fix */
Stephen Warren384a48d2011-06-01 11:14:21 -060082
Wu Fengguang079d88c2010-03-08 10:44:23 +080083 int num_pins;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +010084 struct snd_array pins; /* struct hdmi_spec_per_pin */
85 struct snd_array pcm_rec; /* struct hda_pcm */
Takashi Iwaid45e6882012-07-31 11:36:00 +020086 unsigned int channels_max; /* max over all cvts */
Wu Fengguang079d88c2010-03-08 10:44:23 +080087
David Henningsson4bd038f2013-02-19 16:11:25 +010088 struct hdmi_eld temp_eld;
Wu Fengguang079d88c2010-03-08 10:44:23 +080089 /*
Stephen Warren384a48d2011-06-01 11:14:21 -060090 * Non-generic ATI/NVIDIA specific
Wu Fengguang079d88c2010-03-08 10:44:23 +080091 */
92 struct hda_multi_out multiout;
Takashi Iwaid0b12522012-06-15 14:34:42 +020093 struct hda_pcm_stream pcm_playback;
Wu Fengguang079d88c2010-03-08 10:44:23 +080094};
95
96
97struct hdmi_audio_infoframe {
98 u8 type; /* 0x84 */
99 u8 ver; /* 0x01 */
100 u8 len; /* 0x0a */
101
Wu Fengguang53d7d692010-09-21 14:25:49 +0800102 u8 checksum;
103
Wu Fengguang079d88c2010-03-08 10:44:23 +0800104 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
105 u8 SS01_SF24;
106 u8 CXT04;
107 u8 CA;
108 u8 LFEPBL01_LSV36_DM_INH7;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800109};
110
111struct dp_audio_infoframe {
112 u8 type; /* 0x84 */
113 u8 len; /* 0x1b */
114 u8 ver; /* 0x11 << 2 */
115
116 u8 CC02_CT47; /* match with HDMI infoframe from this on */
117 u8 SS01_SF24;
118 u8 CXT04;
119 u8 CA;
120 u8 LFEPBL01_LSV36_DM_INH7;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800121};
122
Takashi Iwai2b203db2011-02-11 12:17:30 +0100123union audio_infoframe {
124 struct hdmi_audio_infoframe hdmi;
125 struct dp_audio_infoframe dp;
126 u8 bytes[0];
127};
128
Wu Fengguang079d88c2010-03-08 10:44:23 +0800129/*
130 * CEA speaker placement:
131 *
132 * FLH FCH FRH
133 * FLW FL FLC FC FRC FR FRW
134 *
135 * LFE
136 * TC
137 *
138 * RL RLC RC RRC RR
139 *
140 * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
141 * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
142 */
143enum cea_speaker_placement {
144 FL = (1 << 0), /* Front Left */
145 FC = (1 << 1), /* Front Center */
146 FR = (1 << 2), /* Front Right */
147 FLC = (1 << 3), /* Front Left Center */
148 FRC = (1 << 4), /* Front Right Center */
149 RL = (1 << 5), /* Rear Left */
150 RC = (1 << 6), /* Rear Center */
151 RR = (1 << 7), /* Rear Right */
152 RLC = (1 << 8), /* Rear Left Center */
153 RRC = (1 << 9), /* Rear Right Center */
154 LFE = (1 << 10), /* Low Frequency Effect */
155 FLW = (1 << 11), /* Front Left Wide */
156 FRW = (1 << 12), /* Front Right Wide */
157 FLH = (1 << 13), /* Front Left High */
158 FCH = (1 << 14), /* Front Center High */
159 FRH = (1 << 15), /* Front Right High */
160 TC = (1 << 16), /* Top Center */
161};
162
163/*
164 * ELD SA bits in the CEA Speaker Allocation data block
165 */
166static int eld_speaker_allocation_bits[] = {
167 [0] = FL | FR,
168 [1] = LFE,
169 [2] = FC,
170 [3] = RL | RR,
171 [4] = RC,
172 [5] = FLC | FRC,
173 [6] = RLC | RRC,
174 /* the following are not defined in ELD yet */
175 [7] = FLW | FRW,
176 [8] = FLH | FRH,
177 [9] = TC,
178 [10] = FCH,
179};
180
181struct cea_channel_speaker_allocation {
182 int ca_index;
183 int speakers[8];
184
185 /* derived values, just for convenience */
186 int channels;
187 int spk_mask;
188};
189
190/*
191 * ALSA sequence is:
192 *
193 * surround40 surround41 surround50 surround51 surround71
194 * ch0 front left = = = =
195 * ch1 front right = = = =
196 * ch2 rear left = = = =
197 * ch3 rear right = = = =
198 * ch4 LFE center center center
199 * ch5 LFE LFE
200 * ch6 side left
201 * ch7 side right
202 *
203 * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR}
204 */
205static int hdmi_channel_mapping[0x32][8] = {
206 /* stereo */
207 [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
208 /* 2.1 */
209 [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
210 /* Dolby Surround */
211 [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 },
212 /* surround40 */
213 [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 },
214 /* 4ch */
215 [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 },
216 /* surround41 */
Jerry Zhou9396d312010-09-21 14:44:51 +0800217 [0x09] = { 0x00, 0x11, 0x24, 0x35, 0x42, 0xf3, 0xf6, 0xf7 },
Wu Fengguang079d88c2010-03-08 10:44:23 +0800218 /* surround50 */
219 [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 },
220 /* surround51 */
221 [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 },
222 /* 7.1 */
223 [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 },
224};
225
226/*
227 * This is an ordered list!
228 *
229 * The preceding ones have better chances to be selected by
Wu Fengguang53d7d692010-09-21 14:25:49 +0800230 * hdmi_channel_allocation().
Wu Fengguang079d88c2010-03-08 10:44:23 +0800231 */
232static struct cea_channel_speaker_allocation channel_allocations[] = {
233/* channel: 7 6 5 4 3 2 1 0 */
234{ .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
235 /* 2.1 */
236{ .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
237 /* Dolby Surround */
238{ .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
239 /* surround40 */
240{ .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
241 /* surround41 */
242{ .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
243 /* surround50 */
244{ .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
245 /* surround51 */
246{ .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
247 /* 6.1 */
248{ .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
249 /* surround71 */
250{ .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
251
252{ .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
253{ .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
254{ .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
255{ .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
256{ .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
257{ .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
258{ .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
259{ .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
260{ .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
261{ .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
262{ .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
263{ .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
264{ .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
265{ .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
266{ .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
267{ .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
268{ .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
269{ .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
270{ .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
271{ .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
272{ .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
273{ .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
274{ .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
275{ .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } },
276{ .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } },
277{ .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } },
278{ .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } },
279{ .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } },
280{ .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } },
281{ .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } },
282{ .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } },
283{ .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } },
284{ .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } },
285{ .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } },
286{ .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } },
287{ .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } },
288{ .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } },
289{ .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } },
290{ .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } },
291{ .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } },
292{ .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
293};
294
295
296/*
297 * HDMI routines
298 */
299
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100300#define get_pin(spec, idx) \
301 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx))
302#define get_cvt(spec, idx) \
303 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx))
304#define get_pcm_rec(spec, idx) \
305 ((struct hda_pcm *)snd_array_elem(&spec->pcm_rec, idx))
306
Stephen Warren384a48d2011-06-01 11:14:21 -0600307static int pin_nid_to_pin_index(struct hdmi_spec *spec, hda_nid_t pin_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800308{
Stephen Warren384a48d2011-06-01 11:14:21 -0600309 int pin_idx;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800310
Stephen Warren384a48d2011-06-01 11:14:21 -0600311 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100312 if (get_pin(spec, pin_idx)->pin_nid == pin_nid)
Stephen Warren384a48d2011-06-01 11:14:21 -0600313 return pin_idx;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800314
Stephen Warren384a48d2011-06-01 11:14:21 -0600315 snd_printk(KERN_WARNING "HDMI: pin nid %d not registered\n", pin_nid);
316 return -EINVAL;
317}
318
319static int hinfo_to_pin_index(struct hdmi_spec *spec,
320 struct hda_pcm_stream *hinfo)
321{
322 int pin_idx;
323
324 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100325 if (get_pcm_rec(spec, pin_idx)->stream == hinfo)
Stephen Warren384a48d2011-06-01 11:14:21 -0600326 return pin_idx;
327
328 snd_printk(KERN_WARNING "HDMI: hinfo %p not registered\n", hinfo);
329 return -EINVAL;
330}
331
332static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid)
333{
334 int cvt_idx;
335
336 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100337 if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid)
Stephen Warren384a48d2011-06-01 11:14:21 -0600338 return cvt_idx;
339
340 snd_printk(KERN_WARNING "HDMI: cvt nid %d not registered\n", cvt_nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800341 return -EINVAL;
342}
343
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500344static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
345 struct snd_ctl_elem_info *uinfo)
346{
347 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
David Henningsson68e03de2013-02-19 16:11:23 +0100348 struct hdmi_spec *spec = codec->spec;
349 struct hdmi_eld *eld;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500350 int pin_idx;
351
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500352 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
353
354 pin_idx = kcontrol->private_value;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100355 eld = &get_pin(spec, pin_idx)->sink_eld;
David Henningsson68e03de2013-02-19 16:11:23 +0100356
David Henningsson4bd038f2013-02-19 16:11:25 +0100357 mutex_lock(&eld->lock);
David Henningsson68e03de2013-02-19 16:11:23 +0100358 uinfo->count = eld->eld_valid ? eld->eld_size : 0;
David Henningsson4bd038f2013-02-19 16:11:25 +0100359 mutex_unlock(&eld->lock);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500360
361 return 0;
362}
363
364static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
365 struct snd_ctl_elem_value *ucontrol)
366{
367 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
David Henningsson68e03de2013-02-19 16:11:23 +0100368 struct hdmi_spec *spec = codec->spec;
369 struct hdmi_eld *eld;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500370 int pin_idx;
371
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500372 pin_idx = kcontrol->private_value;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100373 eld = &get_pin(spec, pin_idx)->sink_eld;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500374
David Henningsson4bd038f2013-02-19 16:11:25 +0100375 mutex_lock(&eld->lock);
David Henningsson68e03de2013-02-19 16:11:23 +0100376 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data)) {
David Henningsson4bd038f2013-02-19 16:11:25 +0100377 mutex_unlock(&eld->lock);
David Henningsson68e03de2013-02-19 16:11:23 +0100378 snd_BUG();
379 return -EINVAL;
380 }
381
382 memset(ucontrol->value.bytes.data, 0,
383 ARRAY_SIZE(ucontrol->value.bytes.data));
384 if (eld->eld_valid)
385 memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
386 eld->eld_size);
David Henningsson4bd038f2013-02-19 16:11:25 +0100387 mutex_unlock(&eld->lock);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500388
389 return 0;
390}
391
392static struct snd_kcontrol_new eld_bytes_ctl = {
393 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
394 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
395 .name = "ELD",
396 .info = hdmi_eld_ctl_info,
397 .get = hdmi_eld_ctl_get,
398};
399
400static int hdmi_create_eld_ctl(struct hda_codec *codec, int pin_idx,
401 int device)
402{
403 struct snd_kcontrol *kctl;
404 struct hdmi_spec *spec = codec->spec;
405 int err;
406
407 kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
408 if (!kctl)
409 return -ENOMEM;
410 kctl->private_value = pin_idx;
411 kctl->id.device = device;
412
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100413 err = snd_hda_ctl_add(codec, get_pin(spec, pin_idx)->pin_nid, kctl);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500414 if (err < 0)
415 return err;
416
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100417 get_pin(spec, pin_idx)->eld_ctl = kctl;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500418 return 0;
419}
420
Wu Fengguang079d88c2010-03-08 10:44:23 +0800421#ifdef BE_PARANOID
422static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
423 int *packet_index, int *byte_index)
424{
425 int val;
426
427 val = snd_hda_codec_read(codec, pin_nid, 0,
428 AC_VERB_GET_HDMI_DIP_INDEX, 0);
429
430 *packet_index = val >> 5;
431 *byte_index = val & 0x1f;
432}
433#endif
434
435static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
436 int packet_index, int byte_index)
437{
438 int val;
439
440 val = (packet_index << 5) | (byte_index & 0x1f);
441
442 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
443}
444
445static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
446 unsigned char val)
447{
448 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
449}
450
Stephen Warren384a48d2011-06-01 11:14:21 -0600451static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800452{
453 /* Unmute */
454 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
455 snd_hda_codec_write(codec, pin_nid, 0,
456 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
Takashi Iwai6169b672012-12-14 10:22:35 +0100457 /* Enable pin out: some machines with GM965 gets broken output when
458 * the pin is disabled or changed while using with HDMI
459 */
Wu Fengguang079d88c2010-03-08 10:44:23 +0800460 snd_hda_codec_write(codec, pin_nid, 0,
Takashi Iwai6169b672012-12-14 10:22:35 +0100461 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800462}
463
Stephen Warren384a48d2011-06-01 11:14:21 -0600464static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800465{
Stephen Warren384a48d2011-06-01 11:14:21 -0600466 return 1 + snd_hda_codec_read(codec, cvt_nid, 0,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800467 AC_VERB_GET_CVT_CHAN_COUNT, 0);
468}
469
470static void hdmi_set_channel_count(struct hda_codec *codec,
Stephen Warren384a48d2011-06-01 11:14:21 -0600471 hda_nid_t cvt_nid, int chs)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800472{
Stephen Warren384a48d2011-06-01 11:14:21 -0600473 if (chs != hdmi_get_channel_count(codec, cvt_nid))
474 snd_hda_codec_write(codec, cvt_nid, 0,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800475 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
476}
477
478
479/*
480 * Channel mapping routines
481 */
482
483/*
484 * Compute derived values in channel_allocations[].
485 */
486static void init_channel_allocations(void)
487{
488 int i, j;
489 struct cea_channel_speaker_allocation *p;
490
491 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
492 p = channel_allocations + i;
493 p->channels = 0;
494 p->spk_mask = 0;
495 for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
496 if (p->speakers[j]) {
497 p->channels++;
498 p->spk_mask |= p->speakers[j];
499 }
500 }
501}
502
Wang Xingchao72357c72012-09-06 10:02:36 +0800503static int get_channel_allocation_order(int ca)
504{
505 int i;
506
507 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
508 if (channel_allocations[i].ca_index == ca)
509 break;
510 }
511 return i;
512}
513
Wu Fengguang079d88c2010-03-08 10:44:23 +0800514/*
515 * The transformation takes two steps:
516 *
517 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
518 * spk_mask => (channel_allocations[]) => ai->CA
519 *
520 * TODO: it could select the wrong CA from multiple candidates.
521*/
Stephen Warren384a48d2011-06-01 11:14:21 -0600522static int hdmi_channel_allocation(struct hdmi_eld *eld, int channels)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800523{
Wu Fengguang079d88c2010-03-08 10:44:23 +0800524 int i;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800525 int ca = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800526 int spk_mask = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800527 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
528
529 /*
530 * CA defaults to 0 for basic stereo audio
531 */
532 if (channels <= 2)
533 return 0;
534
Wu Fengguang079d88c2010-03-08 10:44:23 +0800535 /*
536 * expand ELD's speaker allocation mask
537 *
538 * ELD tells the speaker mask in a compact(paired) form,
539 * expand ELD's notions to match the ones used by Audio InfoFrame.
540 */
541 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
David Henningsson1613d6b42013-02-19 16:11:24 +0100542 if (eld->info.spk_alloc & (1 << i))
Wu Fengguang079d88c2010-03-08 10:44:23 +0800543 spk_mask |= eld_speaker_allocation_bits[i];
544 }
545
546 /* search for the first working match in the CA table */
547 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
548 if (channels == channel_allocations[i].channels &&
549 (spk_mask & channel_allocations[i].spk_mask) ==
550 channel_allocations[i].spk_mask) {
Wu Fengguang53d7d692010-09-21 14:25:49 +0800551 ca = channel_allocations[i].ca_index;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800552 break;
553 }
554 }
555
Anssi Hannula686edbc2013-09-01 14:36:47 +0300556 if (!ca) {
557 /* if there was no match, select the regular ALSA channel
558 * allocation with the matching number of channels */
559 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
560 if (channels == channel_allocations[i].channels) {
561 ca = channel_allocations[i].ca_index;
562 break;
563 }
564 }
565 }
566
David Henningsson1613d6b42013-02-19 16:11:24 +0100567 snd_print_channel_allocation(eld->info.spk_alloc, buf, sizeof(buf));
Wu Fengguang2abbf432010-03-08 10:45:38 +0800568 snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n",
Wu Fengguang53d7d692010-09-21 14:25:49 +0800569 ca, channels, buf);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800570
Wu Fengguang53d7d692010-09-21 14:25:49 +0800571 return ca;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800572}
573
574static void hdmi_debug_channel_mapping(struct hda_codec *codec,
575 hda_nid_t pin_nid)
576{
577#ifdef CONFIG_SND_DEBUG_VERBOSE
578 int i;
579 int slot;
580
581 for (i = 0; i < 8; i++) {
582 slot = snd_hda_codec_read(codec, pin_nid, 0,
583 AC_VERB_GET_HDMI_CHAN_SLOT, i);
584 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n",
585 slot >> 4, slot & 0xf);
586 }
587#endif
588}
589
590
Takashi Iwaid45e6882012-07-31 11:36:00 +0200591static void hdmi_std_setup_channel_mapping(struct hda_codec *codec,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800592 hda_nid_t pin_nid,
Wang Xingchao433968d2012-09-06 10:02:37 +0800593 bool non_pcm,
Wu Fengguang53d7d692010-09-21 14:25:49 +0800594 int ca)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800595{
596 int i;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800597 int err;
Wang Xingchao72357c72012-09-06 10:02:36 +0800598 int order;
Wang Xingchao433968d2012-09-06 10:02:37 +0800599 int non_pcm_mapping[8];
Wu Fengguang079d88c2010-03-08 10:44:23 +0800600
Wang Xingchao72357c72012-09-06 10:02:36 +0800601 order = get_channel_allocation_order(ca);
Wang Xingchao433968d2012-09-06 10:02:37 +0800602
Wu Fengguang079d88c2010-03-08 10:44:23 +0800603 if (hdmi_channel_mapping[ca][1] == 0) {
Wang Xingchao72357c72012-09-06 10:02:36 +0800604 for (i = 0; i < channel_allocations[order].channels; i++)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800605 hdmi_channel_mapping[ca][i] = i | (i << 4);
606 for (; i < 8; i++)
607 hdmi_channel_mapping[ca][i] = 0xf | (i << 4);
608 }
609
Wang Xingchao433968d2012-09-06 10:02:37 +0800610 if (non_pcm) {
611 for (i = 0; i < channel_allocations[order].channels; i++)
612 non_pcm_mapping[i] = i | (i << 4);
613 for (; i < 8; i++)
614 non_pcm_mapping[i] = 0xf | (i << 4);
615 }
616
Wu Fengguang079d88c2010-03-08 10:44:23 +0800617 for (i = 0; i < 8; i++) {
618 err = snd_hda_codec_write(codec, pin_nid, 0,
619 AC_VERB_SET_HDMI_CHAN_SLOT,
Wang Xingchao433968d2012-09-06 10:02:37 +0800620 non_pcm ? non_pcm_mapping[i] : hdmi_channel_mapping[ca][i]);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800621 if (err) {
Wu Fengguang2abbf432010-03-08 10:45:38 +0800622 snd_printdd(KERN_NOTICE
623 "HDMI: channel mapping failed\n");
Wu Fengguang079d88c2010-03-08 10:44:23 +0800624 break;
625 }
626 }
627
628 hdmi_debug_channel_mapping(codec, pin_nid);
629}
630
Takashi Iwaid45e6882012-07-31 11:36:00 +0200631struct channel_map_table {
632 unsigned char map; /* ALSA API channel map position */
633 unsigned char cea_slot; /* CEA slot value */
634 int spk_mask; /* speaker position bit mask */
635};
636
637static struct channel_map_table map_tables[] = {
638 { SNDRV_CHMAP_FL, 0x00, FL },
639 { SNDRV_CHMAP_FR, 0x01, FR },
640 { SNDRV_CHMAP_RL, 0x04, RL },
641 { SNDRV_CHMAP_RR, 0x05, RR },
642 { SNDRV_CHMAP_LFE, 0x02, LFE },
643 { SNDRV_CHMAP_FC, 0x03, FC },
644 { SNDRV_CHMAP_RLC, 0x06, RLC },
645 { SNDRV_CHMAP_RRC, 0x07, RRC },
646 {} /* terminator */
647};
648
649/* from ALSA API channel position to speaker bit mask */
650static int to_spk_mask(unsigned char c)
651{
652 struct channel_map_table *t = map_tables;
653 for (; t->map; t++) {
654 if (t->map == c)
655 return t->spk_mask;
656 }
657 return 0;
658}
659
660/* from ALSA API channel position to CEA slot */
661static int to_cea_slot(unsigned char c)
662{
663 struct channel_map_table *t = map_tables;
664 for (; t->map; t++) {
665 if (t->map == c)
666 return t->cea_slot;
667 }
668 return 0x0f;
669}
670
671/* from CEA slot to ALSA API channel position */
672static int from_cea_slot(unsigned char c)
673{
674 struct channel_map_table *t = map_tables;
675 for (; t->map; t++) {
676 if (t->cea_slot == c)
677 return t->map;
678 }
679 return 0;
680}
681
682/* from speaker bit mask to ALSA API channel position */
683static int spk_to_chmap(int spk)
684{
685 struct channel_map_table *t = map_tables;
686 for (; t->map; t++) {
687 if (t->spk_mask == spk)
688 return t->map;
689 }
690 return 0;
691}
692
693/* get the CA index corresponding to the given ALSA API channel map */
694static int hdmi_manual_channel_allocation(int chs, unsigned char *map)
695{
696 int i, spks = 0, spk_mask = 0;
697
698 for (i = 0; i < chs; i++) {
699 int mask = to_spk_mask(map[i]);
700 if (mask) {
701 spk_mask |= mask;
702 spks++;
703 }
704 }
705
706 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
707 if ((chs == channel_allocations[i].channels ||
708 spks == channel_allocations[i].channels) &&
709 (spk_mask & channel_allocations[i].spk_mask) ==
710 channel_allocations[i].spk_mask)
711 return channel_allocations[i].ca_index;
712 }
713 return -1;
714}
715
716/* set up the channel slots for the given ALSA API channel map */
717static int hdmi_manual_setup_channel_mapping(struct hda_codec *codec,
718 hda_nid_t pin_nid,
719 int chs, unsigned char *map)
720{
721 int i;
722 for (i = 0; i < 8; i++) {
723 int val, err;
724 if (i < chs)
725 val = to_cea_slot(map[i]);
726 else
727 val = 0xf;
728 val |= (i << 4);
729 err = snd_hda_codec_write(codec, pin_nid, 0,
730 AC_VERB_SET_HDMI_CHAN_SLOT, val);
731 if (err)
732 return -EINVAL;
733 }
734 return 0;
735}
736
737/* store ALSA API channel map from the current default map */
738static void hdmi_setup_fake_chmap(unsigned char *map, int ca)
739{
740 int i;
Anssi Hannula1c645a12013-10-05 02:25:38 +0300741 int ordered_ca = get_channel_allocation_order(ca);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200742 for (i = 0; i < 8; i++) {
Anssi Hannula1c645a12013-10-05 02:25:38 +0300743 if (i < channel_allocations[ordered_ca].channels)
744 map[i] = from_cea_slot(hdmi_channel_mapping[ca][i] & 0x0f);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200745 else
746 map[i] = 0;
747 }
748}
749
750static void hdmi_setup_channel_mapping(struct hda_codec *codec,
751 hda_nid_t pin_nid, bool non_pcm, int ca,
Anssi Hannula20608732013-02-03 17:55:45 +0200752 int channels, unsigned char *map,
753 bool chmap_set)
Takashi Iwaid45e6882012-07-31 11:36:00 +0200754{
Anssi Hannula20608732013-02-03 17:55:45 +0200755 if (!non_pcm && chmap_set) {
Takashi Iwaid45e6882012-07-31 11:36:00 +0200756 hdmi_manual_setup_channel_mapping(codec, pin_nid,
757 channels, map);
758 } else {
759 hdmi_std_setup_channel_mapping(codec, pin_nid, non_pcm, ca);
760 hdmi_setup_fake_chmap(map, ca);
761 }
762}
Wu Fengguang079d88c2010-03-08 10:44:23 +0800763
764/*
765 * Audio InfoFrame routines
766 */
767
768/*
769 * Enable Audio InfoFrame Transmission
770 */
771static void hdmi_start_infoframe_trans(struct hda_codec *codec,
772 hda_nid_t pin_nid)
773{
774 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
775 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
776 AC_DIPXMIT_BEST);
777}
778
779/*
780 * Disable Audio InfoFrame Transmission
781 */
782static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
783 hda_nid_t pin_nid)
784{
785 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
786 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
787 AC_DIPXMIT_DISABLE);
788}
789
790static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
791{
792#ifdef CONFIG_SND_DEBUG_VERBOSE
793 int i;
794 int size;
795
796 size = snd_hdmi_get_eld_size(codec, pin_nid);
797 printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size);
798
799 for (i = 0; i < 8; i++) {
800 size = snd_hda_codec_read(codec, pin_nid, 0,
801 AC_VERB_GET_HDMI_DIP_SIZE, i);
802 printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size);
803 }
804#endif
805}
806
807static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
808{
809#ifdef BE_PARANOID
810 int i, j;
811 int size;
812 int pi, bi;
813 for (i = 0; i < 8; i++) {
814 size = snd_hda_codec_read(codec, pin_nid, 0,
815 AC_VERB_GET_HDMI_DIP_SIZE, i);
816 if (size == 0)
817 continue;
818
819 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
820 for (j = 1; j < 1000; j++) {
821 hdmi_write_dip_byte(codec, pin_nid, 0x0);
822 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
823 if (pi != i)
824 snd_printd(KERN_INFO "dip index %d: %d != %d\n",
825 bi, pi, i);
826 if (bi == 0) /* byte index wrapped around */
827 break;
828 }
829 snd_printd(KERN_INFO
830 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
831 i, size, j);
832 }
833#endif
834}
835
Wu Fengguang53d7d692010-09-21 14:25:49 +0800836static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800837{
Wu Fengguang53d7d692010-09-21 14:25:49 +0800838 u8 *bytes = (u8 *)hdmi_ai;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800839 u8 sum = 0;
840 int i;
841
Wu Fengguang53d7d692010-09-21 14:25:49 +0800842 hdmi_ai->checksum = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800843
Wu Fengguang53d7d692010-09-21 14:25:49 +0800844 for (i = 0; i < sizeof(*hdmi_ai); i++)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800845 sum += bytes[i];
846
Wu Fengguang53d7d692010-09-21 14:25:49 +0800847 hdmi_ai->checksum = -sum;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800848}
849
850static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
851 hda_nid_t pin_nid,
Wu Fengguang53d7d692010-09-21 14:25:49 +0800852 u8 *dip, int size)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800853{
Wu Fengguang079d88c2010-03-08 10:44:23 +0800854 int i;
855
856 hdmi_debug_dip_size(codec, pin_nid);
857 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
858
Wu Fengguang079d88c2010-03-08 10:44:23 +0800859 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
Wu Fengguang53d7d692010-09-21 14:25:49 +0800860 for (i = 0; i < size; i++)
861 hdmi_write_dip_byte(codec, pin_nid, dip[i]);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800862}
863
864static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
Wu Fengguang53d7d692010-09-21 14:25:49 +0800865 u8 *dip, int size)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800866{
Wu Fengguang079d88c2010-03-08 10:44:23 +0800867 u8 val;
868 int i;
869
870 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
871 != AC_DIPXMIT_BEST)
872 return false;
873
874 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
Wu Fengguang53d7d692010-09-21 14:25:49 +0800875 for (i = 0; i < size; i++) {
Wu Fengguang079d88c2010-03-08 10:44:23 +0800876 val = snd_hda_codec_read(codec, pin_nid, 0,
877 AC_VERB_GET_HDMI_DIP_DATA, 0);
Wu Fengguang53d7d692010-09-21 14:25:49 +0800878 if (val != dip[i])
Wu Fengguang079d88c2010-03-08 10:44:23 +0800879 return false;
880 }
881
882 return true;
883}
884
Takashi Iwaidc780f72013-09-02 12:33:02 +0200885static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
886 struct hdmi_spec_per_pin *per_pin,
887 bool non_pcm)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800888{
Stephen Warren384a48d2011-06-01 11:14:21 -0600889 hda_nid_t pin_nid = per_pin->pin_nid;
Takashi Iwaidc780f72013-09-02 12:33:02 +0200890 int channels = per_pin->channels;
Stephen Warren384a48d2011-06-01 11:14:21 -0600891 struct hdmi_eld *eld;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800892 int ca;
Takashi Iwai2b203db2011-02-11 12:17:30 +0100893 union audio_infoframe ai;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800894
Takashi Iwaidc780f72013-09-02 12:33:02 +0200895 if (!channels)
896 return;
897
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100898 eld = &per_pin->sink_eld;
Stephen Warren384a48d2011-06-01 11:14:21 -0600899 if (!eld->monitor_present)
900 return;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800901
Takashi Iwaid45e6882012-07-31 11:36:00 +0200902 if (!non_pcm && per_pin->chmap_set)
903 ca = hdmi_manual_channel_allocation(channels, per_pin->chmap);
904 else
905 ca = hdmi_channel_allocation(eld, channels);
906 if (ca < 0)
907 ca = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800908
Stephen Warren384a48d2011-06-01 11:14:21 -0600909 memset(&ai, 0, sizeof(ai));
David Henningsson1613d6b42013-02-19 16:11:24 +0100910 if (eld->info.conn_type == 0) { /* HDMI */
Stephen Warren384a48d2011-06-01 11:14:21 -0600911 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800912
Stephen Warren384a48d2011-06-01 11:14:21 -0600913 hdmi_ai->type = 0x84;
914 hdmi_ai->ver = 0x01;
915 hdmi_ai->len = 0x0a;
916 hdmi_ai->CC02_CT47 = channels - 1;
917 hdmi_ai->CA = ca;
918 hdmi_checksum_audio_infoframe(hdmi_ai);
David Henningsson1613d6b42013-02-19 16:11:24 +0100919 } else if (eld->info.conn_type == 1) { /* DisplayPort */
Stephen Warren384a48d2011-06-01 11:14:21 -0600920 struct dp_audio_infoframe *dp_ai = &ai.dp;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800921
Stephen Warren384a48d2011-06-01 11:14:21 -0600922 dp_ai->type = 0x84;
923 dp_ai->len = 0x1b;
924 dp_ai->ver = 0x11 << 2;
925 dp_ai->CC02_CT47 = channels - 1;
926 dp_ai->CA = ca;
927 } else {
928 snd_printd("HDMI: unknown connection type at pin %d\n",
929 pin_nid);
930 return;
931 }
Wu Fengguang53d7d692010-09-21 14:25:49 +0800932
Stephen Warren384a48d2011-06-01 11:14:21 -0600933 /*
Anssi Hannula43d3dd12013-10-07 19:24:52 +0300934 * always configure channel mapping, it may have been changed by the
935 * user in the meantime
936 */
937 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
938 channels, per_pin->chmap,
939 per_pin->chmap_set);
940
941 /*
Stephen Warren384a48d2011-06-01 11:14:21 -0600942 * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
943 * sizeof(*dp_ai) to avoid partial match/update problems when
944 * the user switches between HDMI/DP monitors.
945 */
946 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
947 sizeof(ai))) {
948 snd_printdd("hdmi_setup_audio_infoframe: "
949 "pin=%d channels=%d\n",
950 pin_nid,
951 channels);
Stephen Warren384a48d2011-06-01 11:14:21 -0600952 hdmi_stop_infoframe_trans(codec, pin_nid);
953 hdmi_fill_audio_infoframe(codec, pin_nid,
954 ai.bytes, sizeof(ai));
955 hdmi_start_infoframe_trans(codec, pin_nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800956 }
Wang Xingchao433968d2012-09-06 10:02:37 +0800957
Takashi Iwai1a6003b2012-09-06 17:42:08 +0200958 per_pin->non_pcm = non_pcm;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800959}
960
961
962/*
963 * Unsolicited events
964 */
965
Wu Fengguangc6e84532011-11-18 16:59:32 -0600966static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
Takashi Iwai38faddb2010-07-28 14:21:55 +0200967
Wu Fengguang079d88c2010-03-08 10:44:23 +0800968static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
969{
970 struct hdmi_spec *spec = codec->spec;
Takashi Iwai3a938972011-10-28 01:16:55 +0200971 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
972 int pin_nid;
Stephen Warren384a48d2011-06-01 11:14:21 -0600973 int pin_idx;
Takashi Iwai3a938972011-10-28 01:16:55 +0200974 struct hda_jack_tbl *jack;
975
976 jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
977 if (!jack)
978 return;
979 pin_nid = jack->nid;
980 jack->jack_dirty = 1;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800981
Fengguang Wufae3d882012-04-10 17:00:35 +0800982 _snd_printd(SND_PR_VERBOSE,
Stephen Warren384a48d2011-06-01 11:14:21 -0600983 "HDMI hot plug event: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
Fengguang Wufae3d882012-04-10 17:00:35 +0800984 codec->addr, pin_nid,
985 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
Wu Fengguang079d88c2010-03-08 10:44:23 +0800986
Stephen Warren384a48d2011-06-01 11:14:21 -0600987 pin_idx = pin_nid_to_pin_index(spec, pin_nid);
988 if (pin_idx < 0)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800989 return;
990
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100991 hdmi_present_sense(get_pin(spec, pin_idx), 1);
Takashi Iwai01a61e12011-10-28 00:03:22 +0200992 snd_hda_jack_report_sync(codec);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800993}
994
995static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
996{
997 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
998 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
999 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
1000 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
1001
1002 printk(KERN_INFO
Takashi Iwaie9ea8e82012-06-21 11:41:05 +02001003 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
Stephen Warren384a48d2011-06-01 11:14:21 -06001004 codec->addr,
Wu Fengguang079d88c2010-03-08 10:44:23 +08001005 tag,
1006 subtag,
1007 cp_state,
1008 cp_ready);
1009
1010 /* TODO */
1011 if (cp_state)
1012 ;
1013 if (cp_ready)
1014 ;
1015}
1016
1017
1018static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
1019{
Wu Fengguang079d88c2010-03-08 10:44:23 +08001020 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
1021 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
1022
Takashi Iwai3a938972011-10-28 01:16:55 +02001023 if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) {
Wu Fengguang079d88c2010-03-08 10:44:23 +08001024 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag);
1025 return;
1026 }
1027
1028 if (subtag == 0)
1029 hdmi_intrinsic_event(codec, res);
1030 else
1031 hdmi_non_intrinsic_event(codec, res);
1032}
1033
David Henningsson83f26ad2013-04-10 12:26:07 +02001034static void haswell_verify_pin_D0(struct hda_codec *codec, hda_nid_t nid)
1035{
1036 int pwr, lamp, ramp;
1037
1038 pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
1039 pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
1040 if (pwr != AC_PWRST_D0) {
1041 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
1042 AC_PWRST_D0);
1043 msleep(40);
1044 pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
1045 pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
1046 snd_printd("Haswell HDMI audio: Power for pin 0x%x is now D%d\n", nid, pwr);
1047 }
1048
1049 lamp = snd_hda_codec_read(codec, nid, 0,
1050 AC_VERB_GET_AMP_GAIN_MUTE,
1051 AC_AMP_GET_LEFT | AC_AMP_GET_OUTPUT);
1052 ramp = snd_hda_codec_read(codec, nid, 0,
1053 AC_VERB_GET_AMP_GAIN_MUTE,
1054 AC_AMP_GET_RIGHT | AC_AMP_GET_OUTPUT);
1055 if (lamp != ramp) {
1056 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1057 AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT | lamp);
1058
1059 lamp = snd_hda_codec_read(codec, nid, 0,
1060 AC_VERB_GET_AMP_GAIN_MUTE,
1061 AC_AMP_GET_LEFT | AC_AMP_GET_OUTPUT);
1062 ramp = snd_hda_codec_read(codec, nid, 0,
1063 AC_VERB_GET_AMP_GAIN_MUTE,
1064 AC_AMP_GET_RIGHT | AC_AMP_GET_OUTPUT);
1065 snd_printd("Haswell HDMI audio: Mute after set on pin 0x%x: [0x%x 0x%x]\n", nid, lamp, ramp);
1066 }
1067}
1068
Wu Fengguang079d88c2010-03-08 10:44:23 +08001069/*
1070 * Callbacks
1071 */
1072
Takashi Iwai92f10b32010-08-03 14:21:00 +02001073/* HBR should be Non-PCM, 8 channels */
1074#define is_hbr_format(format) \
1075 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
1076
Stephen Warren384a48d2011-06-01 11:14:21 -06001077static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
1078 hda_nid_t pin_nid, u32 stream_tag, int format)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001079{
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001080 int pinctl;
1081 int new_pinctl = 0;
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001082
David Henningsson83f26ad2013-04-10 12:26:07 +02001083 if (codec->vendor_id == 0x80862807)
1084 haswell_verify_pin_D0(codec, pin_nid);
1085
Stephen Warren384a48d2011-06-01 11:14:21 -06001086 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
1087 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001088 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1089
1090 new_pinctl = pinctl & ~AC_PINCTL_EPT;
Takashi Iwai92f10b32010-08-03 14:21:00 +02001091 if (is_hbr_format(format))
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001092 new_pinctl |= AC_PINCTL_EPT_HBR;
1093 else
1094 new_pinctl |= AC_PINCTL_EPT_NATIVE;
1095
1096 snd_printdd("hdmi_setup_stream: "
1097 "NID=0x%x, %spinctl=0x%x\n",
Stephen Warren384a48d2011-06-01 11:14:21 -06001098 pin_nid,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001099 pinctl == new_pinctl ? "" : "new-",
1100 new_pinctl);
1101
1102 if (pinctl != new_pinctl)
Stephen Warren384a48d2011-06-01 11:14:21 -06001103 snd_hda_codec_write(codec, pin_nid, 0,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001104 AC_VERB_SET_PIN_WIDGET_CONTROL,
1105 new_pinctl);
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001106
Stephen Warren384a48d2011-06-01 11:14:21 -06001107 }
Takashi Iwai92f10b32010-08-03 14:21:00 +02001108 if (is_hbr_format(format) && !new_pinctl) {
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001109 snd_printdd("hdmi_setup_stream: HBR is not supported\n");
1110 return -EINVAL;
1111 }
Wu Fengguang079d88c2010-03-08 10:44:23 +08001112
Stephen Warren384a48d2011-06-01 11:14:21 -06001113 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001114 return 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001115}
1116
1117/*
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001118 * HDA PCM callbacks
1119 */
1120static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1121 struct hda_codec *codec,
1122 struct snd_pcm_substream *substream)
1123{
1124 struct hdmi_spec *spec = codec->spec;
Takashi Iwai639cef02011-01-14 10:30:46 +01001125 struct snd_pcm_runtime *runtime = substream->runtime;
Stephen Warren384a48d2011-06-01 11:14:21 -06001126 int pin_idx, cvt_idx, mux_idx = 0;
1127 struct hdmi_spec_per_pin *per_pin;
1128 struct hdmi_eld *eld;
1129 struct hdmi_spec_per_cvt *per_cvt = NULL;
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001130
Stephen Warren384a48d2011-06-01 11:14:21 -06001131 /* Validate hinfo */
1132 pin_idx = hinfo_to_pin_index(spec, hinfo);
1133 if (snd_BUG_ON(pin_idx < 0))
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001134 return -EINVAL;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001135 per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001136 eld = &per_pin->sink_eld;
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001137
Stephen Warren384a48d2011-06-01 11:14:21 -06001138 /* Dynamically assign converter to stream */
1139 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001140 per_cvt = get_cvt(spec, cvt_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001141
1142 /* Must not already be assigned */
1143 if (per_cvt->assigned)
1144 continue;
1145 /* Must be in pin's mux's list of converters */
1146 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
1147 if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid)
1148 break;
1149 /* Not in mux list */
1150 if (mux_idx == per_pin->num_mux_nids)
1151 continue;
1152 break;
1153 }
1154 /* No free converters */
1155 if (cvt_idx == spec->num_cvts)
1156 return -ENODEV;
1157
1158 /* Claim converter */
1159 per_cvt->assigned = 1;
1160 hinfo->nid = per_cvt->cvt_nid;
1161
Takashi Iwai27035ca2013-06-18 16:14:22 +02001162 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
Stephen Warren384a48d2011-06-01 11:14:21 -06001163 AC_VERB_SET_CONNECT_SEL,
1164 mux_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001165 snd_hda_spdif_ctls_assign(codec, pin_idx, per_cvt->cvt_nid);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001166
Stephen Warren2def8172011-06-01 11:14:20 -06001167 /* Initially set the converter's capabilities */
Stephen Warren384a48d2011-06-01 11:14:21 -06001168 hinfo->channels_min = per_cvt->channels_min;
1169 hinfo->channels_max = per_cvt->channels_max;
1170 hinfo->rates = per_cvt->rates;
1171 hinfo->formats = per_cvt->formats;
1172 hinfo->maxbps = per_cvt->maxbps;
Stephen Warren2def8172011-06-01 11:14:20 -06001173
Stephen Warren384a48d2011-06-01 11:14:21 -06001174 /* Restrict capabilities by ELD if this isn't disabled */
Stephen Warrenc3d52102011-06-01 11:14:16 -06001175 if (!static_hdmi_pcm && eld->eld_valid) {
David Henningsson1613d6b42013-02-19 16:11:24 +01001176 snd_hdmi_eld_update_pcm_info(&eld->info, hinfo);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001177 if (hinfo->channels_min > hinfo->channels_max ||
Takashi Iwai2ad779b2013-02-01 14:01:27 +01001178 !hinfo->rates || !hinfo->formats) {
1179 per_cvt->assigned = 0;
1180 hinfo->nid = 0;
1181 snd_hda_spdif_ctls_unassign(codec, pin_idx);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001182 return -ENODEV;
Takashi Iwai2ad779b2013-02-01 14:01:27 +01001183 }
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001184 }
Stephen Warren2def8172011-06-01 11:14:20 -06001185
1186 /* Store the updated parameters */
Takashi Iwai639cef02011-01-14 10:30:46 +01001187 runtime->hw.channels_min = hinfo->channels_min;
1188 runtime->hw.channels_max = hinfo->channels_max;
1189 runtime->hw.formats = hinfo->formats;
1190 runtime->hw.rates = hinfo->rates;
Takashi Iwai4fe2ca12011-01-14 10:33:26 +01001191
1192 snd_pcm_hw_constraint_step(substream->runtime, 0,
1193 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001194 return 0;
1195}
1196
1197/*
Wu Fengguang079d88c2010-03-08 10:44:23 +08001198 * HDA/HDMI auto parsing
1199 */
Stephen Warren384a48d2011-06-01 11:14:21 -06001200static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001201{
1202 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001203 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001204 hda_nid_t pin_nid = per_pin->pin_nid;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001205
1206 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
1207 snd_printk(KERN_WARNING
1208 "HDMI: pin %d wcaps %#x "
1209 "does not support connection list\n",
1210 pin_nid, get_wcaps(codec, pin_nid));
1211 return -EINVAL;
1212 }
1213
Stephen Warren384a48d2011-06-01 11:14:21 -06001214 per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,
1215 per_pin->mux_nids,
1216 HDA_MAX_CONNECTIONS);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001217
1218 return 0;
1219}
1220
Wu Fengguangc6e84532011-11-18 16:59:32 -06001221static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001222{
Wu Fengguang744626d2011-11-16 16:29:47 +08001223 struct hda_codec *codec = per_pin->codec;
David Henningsson4bd038f2013-02-19 16:11:25 +01001224 struct hdmi_spec *spec = codec->spec;
1225 struct hdmi_eld *eld = &spec->temp_eld;
1226 struct hdmi_eld *pin_eld = &per_pin->sink_eld;
Wu Fengguang744626d2011-11-16 16:29:47 +08001227 hda_nid_t pin_nid = per_pin->pin_nid;
Stephen Warren5d44f922011-05-24 17:11:17 -06001228 /*
1229 * Always execute a GetPinSense verb here, even when called from
1230 * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
1231 * response's PD bit is not the real PD value, but indicates that
1232 * the real PD value changed. An older version of the HD-audio
1233 * specification worked this way. Hence, we just ignore the data in
1234 * the unsolicited response to avoid custom WARs.
1235 */
Wu Fengguang079d88c2010-03-08 10:44:23 +08001236 int present = snd_hda_pin_sense(codec, pin_nid);
David Henningsson4bd038f2013-02-19 16:11:25 +01001237 bool update_eld = false;
1238 bool eld_changed = false;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001239
David Henningsson4bd038f2013-02-19 16:11:25 +01001240 pin_eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
1241 if (pin_eld->monitor_present)
1242 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
1243 else
1244 eld->eld_valid = false;
Stephen Warren5d44f922011-05-24 17:11:17 -06001245
Fengguang Wufae3d882012-04-10 17:00:35 +08001246 _snd_printd(SND_PR_VERBOSE,
Stephen Warren384a48d2011-06-01 11:14:21 -06001247 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
Mengdong Lin10250912013-03-28 05:21:28 -04001248 codec->addr, pin_nid, pin_eld->monitor_present, eld->eld_valid);
Stephen Warren5d44f922011-05-24 17:11:17 -06001249
David Henningsson4bd038f2013-02-19 16:11:25 +01001250 if (eld->eld_valid) {
David Henningsson1613d6b42013-02-19 16:11:24 +01001251 if (snd_hdmi_get_eld(codec, pin_nid, eld->eld_buffer,
1252 &eld->eld_size) < 0)
David Henningsson4bd038f2013-02-19 16:11:25 +01001253 eld->eld_valid = false;
David Henningsson1613d6b42013-02-19 16:11:24 +01001254 else {
1255 memset(&eld->info, 0, sizeof(struct parsed_hdmi_eld));
1256 if (snd_hdmi_parse_eld(&eld->info, eld->eld_buffer,
1257 eld->eld_size) < 0)
David Henningsson4bd038f2013-02-19 16:11:25 +01001258 eld->eld_valid = false;
David Henningsson1613d6b42013-02-19 16:11:24 +01001259 }
1260
David Henningsson4bd038f2013-02-19 16:11:25 +01001261 if (eld->eld_valid) {
David Henningsson1613d6b42013-02-19 16:11:24 +01001262 snd_hdmi_show_eld(&eld->info);
David Henningsson4bd038f2013-02-19 16:11:25 +01001263 update_eld = true;
David Henningsson1613d6b42013-02-19 16:11:24 +01001264 }
Wu Fengguangc6e84532011-11-18 16:59:32 -06001265 else if (repoll) {
Wu Fengguang744626d2011-11-16 16:29:47 +08001266 queue_delayed_work(codec->bus->workq,
1267 &per_pin->work,
1268 msecs_to_jiffies(300));
David Henningsson4bd038f2013-02-19 16:11:25 +01001269 return;
Wu Fengguang744626d2011-11-16 16:29:47 +08001270 }
1271 }
David Henningsson4bd038f2013-02-19 16:11:25 +01001272
1273 mutex_lock(&pin_eld->lock);
David Henningsson92c69e72013-02-19 16:11:26 +01001274 if (pin_eld->eld_valid && !eld->eld_valid) {
David Henningsson4bd038f2013-02-19 16:11:25 +01001275 update_eld = true;
David Henningsson92c69e72013-02-19 16:11:26 +01001276 eld_changed = true;
1277 }
David Henningsson4bd038f2013-02-19 16:11:25 +01001278 if (update_eld) {
Takashi Iwaidc780f72013-09-02 12:33:02 +02001279 bool old_eld_valid = pin_eld->eld_valid;
David Henningsson4bd038f2013-02-19 16:11:25 +01001280 pin_eld->eld_valid = eld->eld_valid;
David Henningsson92c69e72013-02-19 16:11:26 +01001281 eld_changed = pin_eld->eld_size != eld->eld_size ||
1282 memcmp(pin_eld->eld_buffer, eld->eld_buffer,
David Henningsson4bd038f2013-02-19 16:11:25 +01001283 eld->eld_size) != 0;
1284 if (eld_changed)
1285 memcpy(pin_eld->eld_buffer, eld->eld_buffer,
1286 eld->eld_size);
1287 pin_eld->eld_size = eld->eld_size;
1288 pin_eld->info = eld->info;
Takashi Iwaidc780f72013-09-02 12:33:02 +02001289
1290 /* Haswell-specific workaround: re-setup when the transcoder is
1291 * changed during the stream playback
1292 */
1293 if (codec->vendor_id == 0x80862807 &&
1294 eld->eld_valid && !old_eld_valid && per_pin->setup) {
1295 snd_hda_codec_write(codec, pin_nid, 0,
1296 AC_VERB_SET_AMP_GAIN_MUTE,
1297 AMP_OUT_UNMUTE);
1298 hdmi_setup_audio_infoframe(codec, per_pin,
1299 per_pin->non_pcm);
1300 }
David Henningsson4bd038f2013-02-19 16:11:25 +01001301 }
1302 mutex_unlock(&pin_eld->lock);
David Henningsson92c69e72013-02-19 16:11:26 +01001303
1304 if (eld_changed)
1305 snd_ctl_notify(codec->bus->card,
1306 SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
1307 &per_pin->eld_ctl->id);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001308}
1309
Wu Fengguang744626d2011-11-16 16:29:47 +08001310static void hdmi_repoll_eld(struct work_struct *work)
1311{
1312 struct hdmi_spec_per_pin *per_pin =
1313 container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
1314
Wu Fengguangc6e84532011-11-18 16:59:32 -06001315 if (per_pin->repoll_count++ > 6)
1316 per_pin->repoll_count = 0;
1317
1318 hdmi_present_sense(per_pin, per_pin->repoll_count);
Wu Fengguang744626d2011-11-16 16:29:47 +08001319}
1320
Takashi Iwaic88d4e82013-02-08 17:10:04 -05001321static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
1322 hda_nid_t nid);
1323
Wu Fengguang079d88c2010-03-08 10:44:23 +08001324static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1325{
1326 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001327 unsigned int caps, config;
1328 int pin_idx;
1329 struct hdmi_spec_per_pin *per_pin;
David Henningsson07acecc2011-05-19 11:46:03 +02001330 int err;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001331
Takashi Iwaiefc2f8de2012-11-21 14:27:37 +01001332 caps = snd_hda_query_pin_caps(codec, pin_nid);
Stephen Warren384a48d2011-06-01 11:14:21 -06001333 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
1334 return 0;
1335
Takashi Iwaiefc2f8de2012-11-21 14:27:37 +01001336 config = snd_hda_codec_get_pincfg(codec, pin_nid);
Stephen Warren384a48d2011-06-01 11:14:21 -06001337 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
1338 return 0;
1339
Takashi Iwaic88d4e82013-02-08 17:10:04 -05001340 if (codec->vendor_id == 0x80862807)
1341 intel_haswell_fixup_connect_list(codec, pin_nid);
1342
Stephen Warren384a48d2011-06-01 11:14:21 -06001343 pin_idx = spec->num_pins;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001344 per_pin = snd_array_new(&spec->pins);
1345 if (!per_pin)
1346 return -ENOMEM;
Stephen Warren384a48d2011-06-01 11:14:21 -06001347
1348 per_pin->pin_nid = pin_nid;
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001349 per_pin->non_pcm = false;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001350
Stephen Warren384a48d2011-06-01 11:14:21 -06001351 err = hdmi_read_pin_conn(codec, pin_idx);
1352 if (err < 0)
1353 return err;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001354
Wu Fengguang079d88c2010-03-08 10:44:23 +08001355 spec->num_pins++;
1356
Stephen Warren384a48d2011-06-01 11:14:21 -06001357 return 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001358}
1359
Stephen Warren384a48d2011-06-01 11:14:21 -06001360static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001361{
1362 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001363 struct hdmi_spec_per_cvt *per_cvt;
1364 unsigned int chans;
1365 int err;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001366
Stephen Warren384a48d2011-06-01 11:14:21 -06001367 chans = get_wcaps(codec, cvt_nid);
1368 chans = get_wcaps_channels(chans);
1369
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001370 per_cvt = snd_array_new(&spec->cvts);
1371 if (!per_cvt)
1372 return -ENOMEM;
Stephen Warren384a48d2011-06-01 11:14:21 -06001373
1374 per_cvt->cvt_nid = cvt_nid;
1375 per_cvt->channels_min = 2;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001376 if (chans <= 16) {
Stephen Warren384a48d2011-06-01 11:14:21 -06001377 per_cvt->channels_max = chans;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001378 if (chans > spec->channels_max)
1379 spec->channels_max = chans;
1380 }
Stephen Warren384a48d2011-06-01 11:14:21 -06001381
1382 err = snd_hda_query_supported_pcm(codec, cvt_nid,
1383 &per_cvt->rates,
1384 &per_cvt->formats,
1385 &per_cvt->maxbps);
1386 if (err < 0)
1387 return err;
1388
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001389 if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids))
1390 spec->cvt_nids[spec->num_cvts] = cvt_nid;
1391 spec->num_cvts++;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001392
1393 return 0;
1394}
1395
1396static int hdmi_parse_codec(struct hda_codec *codec)
1397{
1398 hda_nid_t nid;
1399 int i, nodes;
1400
1401 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
1402 if (!nid || nodes < 0) {
1403 snd_printk(KERN_WARNING "HDMI: failed to get afg sub nodes\n");
1404 return -EINVAL;
1405 }
1406
1407 for (i = 0; i < nodes; i++, nid++) {
1408 unsigned int caps;
1409 unsigned int type;
1410
Takashi Iwaiefc2f8de2012-11-21 14:27:37 +01001411 caps = get_wcaps(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001412 type = get_wcaps_type(caps);
1413
1414 if (!(caps & AC_WCAP_DIGITAL))
1415 continue;
1416
1417 switch (type) {
1418 case AC_WID_AUD_OUT:
Stephen Warren384a48d2011-06-01 11:14:21 -06001419 hdmi_add_cvt(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001420 break;
1421 case AC_WID_PIN:
Wu Fengguang3eaead52010-05-14 16:36:15 +08001422 hdmi_add_pin(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001423 break;
1424 }
1425 }
1426
David Henningssonc9adeef2012-11-07 09:22:33 +01001427#ifdef CONFIG_PM
1428 /* We're seeing some problems with unsolicited hot plug events on
1429 * PantherPoint after S3, if this is not enabled */
1430 if (codec->vendor_id == 0x80862806)
1431 codec->bus->power_keep_link_on = 1;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001432 /*
1433 * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event
1434 * can be lost and presence sense verb will become inaccurate if the
1435 * HDA link is powered off at hot plug or hw initialization time.
1436 */
David Henningssonc9adeef2012-11-07 09:22:33 +01001437 else if (!(snd_hda_param_read(codec, codec->afg, AC_PAR_POWER_STATE) &
Wu Fengguang079d88c2010-03-08 10:44:23 +08001438 AC_PWRST_EPSS))
1439 codec->bus->power_keep_link_on = 1;
1440#endif
1441
1442 return 0;
1443}
1444
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001445/*
1446 */
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001447static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1448{
1449 struct hda_spdif_out *spdif;
1450 bool non_pcm;
1451
1452 mutex_lock(&codec->spdif_mutex);
1453 spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
1454 non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO);
1455 mutex_unlock(&codec->spdif_mutex);
1456 return non_pcm;
1457}
1458
1459
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001460/*
1461 * HDMI callbacks
1462 */
1463
1464static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1465 struct hda_codec *codec,
1466 unsigned int stream_tag,
1467 unsigned int format,
1468 struct snd_pcm_substream *substream)
1469{
Stephen Warren384a48d2011-06-01 11:14:21 -06001470 hda_nid_t cvt_nid = hinfo->nid;
1471 struct hdmi_spec *spec = codec->spec;
1472 int pin_idx = hinfo_to_pin_index(spec, hinfo);
Takashi Iwaidc780f72013-09-02 12:33:02 +02001473 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1474 hda_nid_t pin_nid = per_pin->pin_nid;
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001475 bool non_pcm;
1476
1477 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
Takashi Iwaidc780f72013-09-02 12:33:02 +02001478 per_pin->channels = substream->runtime->channels;
1479 per_pin->setup = true;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001480
Stephen Warren384a48d2011-06-01 11:14:21 -06001481 hdmi_set_channel_count(codec, cvt_nid, substream->runtime->channels);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001482
Takashi Iwaidc780f72013-09-02 12:33:02 +02001483 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
Stephen Warren384a48d2011-06-01 11:14:21 -06001484
1485 return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001486}
1487
Takashi Iwai8dfaa572012-08-06 14:49:36 +02001488static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1489 struct hda_codec *codec,
1490 struct snd_pcm_substream *substream)
1491{
1492 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
1493 return 0;
1494}
1495
Takashi Iwaif2ad24f2012-07-26 18:08:14 +02001496static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1497 struct hda_codec *codec,
1498 struct snd_pcm_substream *substream)
Stephen Warren384a48d2011-06-01 11:14:21 -06001499{
1500 struct hdmi_spec *spec = codec->spec;
1501 int cvt_idx, pin_idx;
1502 struct hdmi_spec_per_cvt *per_cvt;
1503 struct hdmi_spec_per_pin *per_pin;
Stephen Warren384a48d2011-06-01 11:14:21 -06001504
Stephen Warren384a48d2011-06-01 11:14:21 -06001505 if (hinfo->nid) {
1506 cvt_idx = cvt_nid_to_cvt_index(spec, hinfo->nid);
1507 if (snd_BUG_ON(cvt_idx < 0))
1508 return -EINVAL;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001509 per_cvt = get_cvt(spec, cvt_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001510
1511 snd_BUG_ON(!per_cvt->assigned);
1512 per_cvt->assigned = 0;
1513 hinfo->nid = 0;
1514
1515 pin_idx = hinfo_to_pin_index(spec, hinfo);
1516 if (snd_BUG_ON(pin_idx < 0))
1517 return -EINVAL;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001518 per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001519
Stephen Warren384a48d2011-06-01 11:14:21 -06001520 snd_hda_spdif_ctls_unassign(codec, pin_idx);
Takashi Iwaid45e6882012-07-31 11:36:00 +02001521 per_pin->chmap_set = false;
1522 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
Takashi Iwaidc780f72013-09-02 12:33:02 +02001523
1524 per_pin->setup = false;
1525 per_pin->channels = 0;
Stephen Warren384a48d2011-06-01 11:14:21 -06001526 }
Takashi Iwaid45e6882012-07-31 11:36:00 +02001527
Stephen Warren384a48d2011-06-01 11:14:21 -06001528 return 0;
1529}
1530
1531static const struct hda_pcm_ops generic_ops = {
1532 .open = hdmi_pcm_open,
Takashi Iwaif2ad24f2012-07-26 18:08:14 +02001533 .close = hdmi_pcm_close,
Stephen Warren384a48d2011-06-01 11:14:21 -06001534 .prepare = generic_hdmi_playback_pcm_prepare,
Takashi Iwai8dfaa572012-08-06 14:49:36 +02001535 .cleanup = generic_hdmi_playback_pcm_cleanup,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001536};
1537
Takashi Iwaid45e6882012-07-31 11:36:00 +02001538/*
1539 * ALSA API channel-map control callbacks
1540 */
1541static int hdmi_chmap_ctl_info(struct snd_kcontrol *kcontrol,
1542 struct snd_ctl_elem_info *uinfo)
1543{
1544 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
1545 struct hda_codec *codec = info->private_data;
1546 struct hdmi_spec *spec = codec->spec;
1547 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1548 uinfo->count = spec->channels_max;
1549 uinfo->value.integer.min = 0;
1550 uinfo->value.integer.max = SNDRV_CHMAP_LAST;
1551 return 0;
1552}
1553
1554static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1555 unsigned int size, unsigned int __user *tlv)
1556{
1557 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
1558 struct hda_codec *codec = info->private_data;
1559 struct hdmi_spec *spec = codec->spec;
1560 const unsigned int valid_mask =
1561 FL | FR | RL | RR | LFE | FC | RLC | RRC;
1562 unsigned int __user *dst;
1563 int chs, count = 0;
1564
1565 if (size < 8)
1566 return -ENOMEM;
1567 if (put_user(SNDRV_CTL_TLVT_CONTAINER, tlv))
1568 return -EFAULT;
1569 size -= 8;
1570 dst = tlv + 2;
Takashi Iwai498dab32012-09-10 16:08:40 +02001571 for (chs = 2; chs <= spec->channels_max; chs++) {
Takashi Iwaid45e6882012-07-31 11:36:00 +02001572 int i, c;
1573 struct cea_channel_speaker_allocation *cap;
1574 cap = channel_allocations;
1575 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++, cap++) {
1576 int chs_bytes = chs * 4;
1577 if (cap->channels != chs)
1578 continue;
1579 if (cap->spk_mask & ~valid_mask)
1580 continue;
1581 if (size < 8)
1582 return -ENOMEM;
1583 if (put_user(SNDRV_CTL_TLVT_CHMAP_VAR, dst) ||
1584 put_user(chs_bytes, dst + 1))
1585 return -EFAULT;
1586 dst += 2;
1587 size -= 8;
1588 count += 8;
1589 if (size < chs_bytes)
1590 return -ENOMEM;
1591 size -= chs_bytes;
1592 count += chs_bytes;
1593 for (c = 7; c >= 0; c--) {
1594 int spk = cap->speakers[c];
1595 if (!spk)
1596 continue;
1597 if (put_user(spk_to_chmap(spk), dst))
1598 return -EFAULT;
1599 dst++;
1600 }
1601 }
1602 }
1603 if (put_user(count, tlv + 1))
1604 return -EFAULT;
1605 return 0;
1606}
1607
1608static int hdmi_chmap_ctl_get(struct snd_kcontrol *kcontrol,
1609 struct snd_ctl_elem_value *ucontrol)
1610{
1611 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
1612 struct hda_codec *codec = info->private_data;
1613 struct hdmi_spec *spec = codec->spec;
1614 int pin_idx = kcontrol->private_value;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001615 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Takashi Iwaid45e6882012-07-31 11:36:00 +02001616 int i;
1617
1618 for (i = 0; i < ARRAY_SIZE(per_pin->chmap); i++)
1619 ucontrol->value.integer.value[i] = per_pin->chmap[i];
1620 return 0;
1621}
1622
1623static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
1624 struct snd_ctl_elem_value *ucontrol)
1625{
1626 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
1627 struct hda_codec *codec = info->private_data;
1628 struct hdmi_spec *spec = codec->spec;
1629 int pin_idx = kcontrol->private_value;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001630 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Takashi Iwaid45e6882012-07-31 11:36:00 +02001631 unsigned int ctl_idx;
1632 struct snd_pcm_substream *substream;
1633 unsigned char chmap[8];
1634 int i, ca, prepared = 0;
1635
1636 ctl_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1637 substream = snd_pcm_chmap_substream(info, ctl_idx);
1638 if (!substream || !substream->runtime)
Takashi Iwai6f54c362013-01-15 14:44:41 +01001639 return 0; /* just for avoiding error from alsactl restore */
Takashi Iwaid45e6882012-07-31 11:36:00 +02001640 switch (substream->runtime->status->state) {
1641 case SNDRV_PCM_STATE_OPEN:
1642 case SNDRV_PCM_STATE_SETUP:
1643 break;
1644 case SNDRV_PCM_STATE_PREPARED:
1645 prepared = 1;
1646 break;
1647 default:
1648 return -EBUSY;
1649 }
1650 memset(chmap, 0, sizeof(chmap));
1651 for (i = 0; i < ARRAY_SIZE(chmap); i++)
1652 chmap[i] = ucontrol->value.integer.value[i];
1653 if (!memcmp(chmap, per_pin->chmap, sizeof(chmap)))
1654 return 0;
1655 ca = hdmi_manual_channel_allocation(ARRAY_SIZE(chmap), chmap);
1656 if (ca < 0)
1657 return -EINVAL;
1658 per_pin->chmap_set = true;
1659 memcpy(per_pin->chmap, chmap, sizeof(chmap));
1660 if (prepared)
Takashi Iwaidc780f72013-09-02 12:33:02 +02001661 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
Takashi Iwaid45e6882012-07-31 11:36:00 +02001662
1663 return 0;
1664}
1665
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001666static int generic_hdmi_build_pcms(struct hda_codec *codec)
1667{
1668 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001669 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001670
Stephen Warren384a48d2011-06-01 11:14:21 -06001671 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1672 struct hda_pcm *info;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001673 struct hda_pcm_stream *pstr;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001674 struct hdmi_spec_per_pin *per_pin;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001675
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001676 per_pin = get_pin(spec, pin_idx);
1677 sprintf(per_pin->pcm_name, "HDMI %d", pin_idx);
1678 info = snd_array_new(&spec->pcm_rec);
1679 if (!info)
1680 return -ENOMEM;
1681 info->name = per_pin->pcm_name;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001682 info->pcm_type = HDA_PCM_TYPE_HDMI;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001683 info->own_chmap = true;
Stephen Warren384a48d2011-06-01 11:14:21 -06001684
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001685 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
Stephen Warren384a48d2011-06-01 11:14:21 -06001686 pstr->substreams = 1;
1687 pstr->ops = generic_ops;
1688 /* other pstr fields are set in open */
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001689 }
1690
Stephen Warren384a48d2011-06-01 11:14:21 -06001691 codec->num_pcms = spec->num_pins;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001692 codec->pcm_info = spec->pcm_rec.list;
Stephen Warren384a48d2011-06-01 11:14:21 -06001693
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001694 return 0;
1695}
1696
David Henningsson0b6c49b2011-08-23 16:56:03 +02001697static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx)
1698{
Takashi Iwai31ef2252011-12-01 17:41:36 +01001699 char hdmi_str[32] = "HDMI/DP";
David Henningsson0b6c49b2011-08-23 16:56:03 +02001700 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001701 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1702 int pcmdev = get_pcm_rec(spec, pin_idx)->device;
David Henningsson0b6c49b2011-08-23 16:56:03 +02001703
Takashi Iwai31ef2252011-12-01 17:41:36 +01001704 if (pcmdev > 0)
1705 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
David Henningsson30efd8d2013-02-22 10:16:28 +01001706 if (!is_jack_detectable(codec, per_pin->pin_nid))
1707 strncat(hdmi_str, " Phantom",
1708 sizeof(hdmi_str) - strlen(hdmi_str) - 1);
David Henningsson0b6c49b2011-08-23 16:56:03 +02001709
Takashi Iwai31ef2252011-12-01 17:41:36 +01001710 return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str, 0);
David Henningsson0b6c49b2011-08-23 16:56:03 +02001711}
1712
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001713static int generic_hdmi_build_controls(struct hda_codec *codec)
1714{
1715 struct hdmi_spec *spec = codec->spec;
1716 int err;
Stephen Warren384a48d2011-06-01 11:14:21 -06001717 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001718
Stephen Warren384a48d2011-06-01 11:14:21 -06001719 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001720 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
David Henningsson0b6c49b2011-08-23 16:56:03 +02001721
1722 err = generic_hdmi_build_jack(codec, pin_idx);
1723 if (err < 0)
1724 return err;
1725
Takashi Iwaidcda5802012-10-12 17:24:51 +02001726 err = snd_hda_create_dig_out_ctls(codec,
1727 per_pin->pin_nid,
1728 per_pin->mux_nids[0],
1729 HDA_PCM_TYPE_HDMI);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001730 if (err < 0)
1731 return err;
Stephen Warren384a48d2011-06-01 11:14:21 -06001732 snd_hda_spdif_ctls_unassign(codec, pin_idx);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -05001733
1734 /* add control for ELD Bytes */
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001735 err = hdmi_create_eld_ctl(codec, pin_idx,
1736 get_pcm_rec(spec, pin_idx)->device);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -05001737
1738 if (err < 0)
1739 return err;
Takashi Iwai31ef2252011-12-01 17:41:36 +01001740
Takashi Iwai82b1d732011-12-20 15:53:07 +01001741 hdmi_present_sense(per_pin, 0);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001742 }
1743
Takashi Iwaid45e6882012-07-31 11:36:00 +02001744 /* add channel maps */
1745 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1746 struct snd_pcm_chmap *chmap;
1747 struct snd_kcontrol *kctl;
1748 int i;
Takashi Iwaida958132013-08-22 09:55:36 +02001749
1750 if (!codec->pcm_info[pin_idx].pcm)
1751 break;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001752 err = snd_pcm_add_chmap_ctls(codec->pcm_info[pin_idx].pcm,
1753 SNDRV_PCM_STREAM_PLAYBACK,
1754 NULL, 0, pin_idx, &chmap);
1755 if (err < 0)
1756 return err;
1757 /* override handlers */
1758 chmap->private_data = codec;
1759 kctl = chmap->kctl;
1760 for (i = 0; i < kctl->count; i++)
1761 kctl->vd[i].access |= SNDRV_CTL_ELEM_ACCESS_WRITE;
1762 kctl->info = hdmi_chmap_ctl_info;
1763 kctl->get = hdmi_chmap_ctl_get;
1764 kctl->put = hdmi_chmap_ctl_put;
1765 kctl->tlv.c = hdmi_chmap_ctl_tlv;
1766 }
1767
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001768 return 0;
1769}
1770
Takashi Iwai8b8d6542012-06-20 16:32:22 +02001771static int generic_hdmi_init_per_pins(struct hda_codec *codec)
1772{
1773 struct hdmi_spec *spec = codec->spec;
1774 int pin_idx;
1775
1776 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001777 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Takashi Iwai8b8d6542012-06-20 16:32:22 +02001778 struct hdmi_eld *eld = &per_pin->sink_eld;
1779
1780 per_pin->codec = codec;
David Henningsson4bd038f2013-02-19 16:11:25 +01001781 mutex_init(&eld->lock);
Takashi Iwai8b8d6542012-06-20 16:32:22 +02001782 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
1783 snd_hda_eld_proc_new(codec, eld, pin_idx);
1784 }
1785 return 0;
1786}
1787
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001788static int generic_hdmi_init(struct hda_codec *codec)
1789{
1790 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001791 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001792
Stephen Warren384a48d2011-06-01 11:14:21 -06001793 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001794 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001795 hda_nid_t pin_nid = per_pin->pin_nid;
Stephen Warren384a48d2011-06-01 11:14:21 -06001796
1797 hdmi_init_pin(codec, pin_nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001798 snd_hda_jack_detect_enable(codec, pin_nid, pin_nid);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001799 }
1800 return 0;
1801}
1802
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001803static void hdmi_array_init(struct hdmi_spec *spec, int nums)
1804{
1805 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums);
1806 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums);
1807 snd_array_init(&spec->pcm_rec, sizeof(struct hda_pcm), nums);
1808}
1809
1810static void hdmi_array_free(struct hdmi_spec *spec)
1811{
1812 snd_array_free(&spec->pins);
1813 snd_array_free(&spec->cvts);
1814 snd_array_free(&spec->pcm_rec);
1815}
1816
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001817static void generic_hdmi_free(struct hda_codec *codec)
1818{
1819 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001820 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001821
Stephen Warren384a48d2011-06-01 11:14:21 -06001822 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001823 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001824 struct hdmi_eld *eld = &per_pin->sink_eld;
1825
Wu Fengguang744626d2011-11-16 16:29:47 +08001826 cancel_delayed_work(&per_pin->work);
Stephen Warren384a48d2011-06-01 11:14:21 -06001827 snd_hda_eld_proc_free(codec, eld);
1828 }
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001829
Wu Fengguang744626d2011-11-16 16:29:47 +08001830 flush_workqueue(codec->bus->workq);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001831 hdmi_array_free(spec);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001832 kfree(spec);
1833}
1834
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02001835static const struct hda_codec_ops generic_hdmi_patch_ops = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001836 .init = generic_hdmi_init,
1837 .free = generic_hdmi_free,
1838 .build_pcms = generic_hdmi_build_pcms,
1839 .build_controls = generic_hdmi_build_controls,
1840 .unsol_event = hdmi_unsol_event,
1841};
1842
Takashi Iwaic88d4e82013-02-08 17:10:04 -05001843
1844static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
1845 hda_nid_t nid)
Mengdong Lin6ffe1682012-12-18 16:59:15 -05001846{
Takashi Iwaic88d4e82013-02-08 17:10:04 -05001847 struct hdmi_spec *spec = codec->spec;
1848 hda_nid_t conns[4];
1849 int nconns;
Mengdong Lin6ffe1682012-12-18 16:59:15 -05001850
Takashi Iwaic88d4e82013-02-08 17:10:04 -05001851 nconns = snd_hda_get_connections(codec, nid, conns, ARRAY_SIZE(conns));
1852 if (nconns == spec->num_cvts &&
1853 !memcmp(conns, spec->cvt_nids, spec->num_cvts * sizeof(hda_nid_t)))
Mengdong Lin6ffe1682012-12-18 16:59:15 -05001854 return;
1855
Takashi Iwaic88d4e82013-02-08 17:10:04 -05001856 /* override pins connection list */
1857 snd_printdd("hdmi: haswell: override pin connection 0x%x\n", nid);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001858 nconns = max(spec->num_cvts, 4);
Takashi Iwaic88d4e82013-02-08 17:10:04 -05001859 snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids);
Mengdong Lin6ffe1682012-12-18 16:59:15 -05001860}
1861
Mengdong Lin1611a9c2013-02-08 17:09:52 -05001862#define INTEL_VENDOR_NID 0x08
1863#define INTEL_GET_VENDOR_VERB 0xf81
1864#define INTEL_SET_VENDOR_VERB 0x781
1865#define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
1866#define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
1867
1868static void intel_haswell_enable_all_pins(struct hda_codec *codec,
Takashi Iwai17df3f52013-05-08 08:09:34 +02001869 bool update_tree)
Mengdong Lin1611a9c2013-02-08 17:09:52 -05001870{
1871 unsigned int vendor_param;
1872
Mengdong Lin1611a9c2013-02-08 17:09:52 -05001873 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
1874 INTEL_GET_VENDOR_VERB, 0);
1875 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
1876 return;
1877
1878 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
1879 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
1880 INTEL_SET_VENDOR_VERB, vendor_param);
1881 if (vendor_param == -1)
1882 return;
1883
Takashi Iwai17df3f52013-05-08 08:09:34 +02001884 if (update_tree)
1885 snd_hda_codec_update_widgets(codec);
Mengdong Lin1611a9c2013-02-08 17:09:52 -05001886}
1887
Takashi Iwaic88d4e82013-02-08 17:10:04 -05001888static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
1889{
1890 unsigned int vendor_param;
1891
1892 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
1893 INTEL_GET_VENDOR_VERB, 0);
1894 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
1895 return;
1896
1897 /* enable DP1.2 mode */
1898 vendor_param |= INTEL_EN_DP12;
1899 snd_hda_codec_write_cache(codec, INTEL_VENDOR_NID, 0,
1900 INTEL_SET_VENDOR_VERB, vendor_param);
1901}
1902
Takashi Iwai17df3f52013-05-08 08:09:34 +02001903/* Haswell needs to re-issue the vendor-specific verbs before turning to D0.
1904 * Otherwise you may get severe h/w communication errors.
1905 */
1906static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
1907 unsigned int power_state)
1908{
1909 if (power_state == AC_PWRST_D0) {
1910 intel_haswell_enable_all_pins(codec, false);
1911 intel_haswell_fixup_enable_dp12(codec);
1912 }
Takashi Iwaic88d4e82013-02-08 17:10:04 -05001913
Takashi Iwai17df3f52013-05-08 08:09:34 +02001914 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
1915 snd_hda_codec_set_power_to_all(codec, fg, power_state);
1916}
Mengdong Lin6ffe1682012-12-18 16:59:15 -05001917
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001918static int patch_generic_hdmi(struct hda_codec *codec)
1919{
1920 struct hdmi_spec *spec;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001921
1922 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1923 if (spec == NULL)
1924 return -ENOMEM;
1925
1926 codec->spec = spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001927 hdmi_array_init(spec, 4);
Mengdong Lin6ffe1682012-12-18 16:59:15 -05001928
Takashi Iwai17df3f52013-05-08 08:09:34 +02001929 if (codec->vendor_id == 0x80862807) {
1930 intel_haswell_enable_all_pins(codec, true);
Takashi Iwaic88d4e82013-02-08 17:10:04 -05001931 intel_haswell_fixup_enable_dp12(codec);
Takashi Iwai17df3f52013-05-08 08:09:34 +02001932 }
Mengdong Lin6ffe1682012-12-18 16:59:15 -05001933
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001934 if (hdmi_parse_codec(codec) < 0) {
1935 codec->spec = NULL;
1936 kfree(spec);
1937 return -EINVAL;
1938 }
1939 codec->patch_ops = generic_hdmi_patch_ops;
Takashi Iwai17df3f52013-05-08 08:09:34 +02001940 if (codec->vendor_id == 0x80862807)
1941 codec->patch_ops.set_power_state = haswell_set_power_state;
1942
Takashi Iwai8b8d6542012-06-20 16:32:22 +02001943 generic_hdmi_init_per_pins(codec);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001944
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001945 init_channel_allocations();
1946
1947 return 0;
1948}
1949
1950/*
Stephen Warren3aaf8982011-06-01 11:14:19 -06001951 * Shared non-generic implementations
1952 */
1953
1954static int simple_playback_build_pcms(struct hda_codec *codec)
1955{
1956 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001957 struct hda_pcm *info;
Takashi Iwai8ceb3322012-06-21 08:23:27 +02001958 unsigned int chans;
1959 struct hda_pcm_stream *pstr;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001960 struct hdmi_spec_per_cvt *per_cvt;
Stephen Warren3aaf8982011-06-01 11:14:19 -06001961
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001962 per_cvt = get_cvt(spec, 0);
1963 chans = get_wcaps(codec, per_cvt->cvt_nid);
Takashi Iwai8ceb3322012-06-21 08:23:27 +02001964 chans = get_wcaps_channels(chans);
Stephen Warren3aaf8982011-06-01 11:14:19 -06001965
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001966 info = snd_array_new(&spec->pcm_rec);
1967 if (!info)
1968 return -ENOMEM;
1969 info->name = get_pin(spec, 0)->pcm_name;
1970 sprintf(info->name, "HDMI 0");
Takashi Iwai8ceb3322012-06-21 08:23:27 +02001971 info->pcm_type = HDA_PCM_TYPE_HDMI;
1972 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
1973 *pstr = spec->pcm_playback;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001974 pstr->nid = per_cvt->cvt_nid;
Takashi Iwai8ceb3322012-06-21 08:23:27 +02001975 if (pstr->channels_max <= 2 && chans && chans <= 16)
1976 pstr->channels_max = chans;
Stephen Warren3aaf8982011-06-01 11:14:19 -06001977
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001978 codec->num_pcms = 1;
1979 codec->pcm_info = info;
1980
Stephen Warren3aaf8982011-06-01 11:14:19 -06001981 return 0;
1982}
1983
Takashi Iwai4b6ace92012-06-15 11:53:32 +02001984/* unsolicited event for jack sensing */
1985static void simple_hdmi_unsol_event(struct hda_codec *codec,
1986 unsigned int res)
1987{
Takashi Iwai9dd8cf12012-06-21 10:43:15 +02001988 snd_hda_jack_set_dirty_all(codec);
Takashi Iwai4b6ace92012-06-15 11:53:32 +02001989 snd_hda_jack_report_sync(codec);
1990}
1991
1992/* generic_hdmi_build_jack can be used for simple_hdmi, too,
1993 * as long as spec->pins[] is set correctly
1994 */
1995#define simple_hdmi_build_jack generic_hdmi_build_jack
1996
Stephen Warren3aaf8982011-06-01 11:14:19 -06001997static int simple_playback_build_controls(struct hda_codec *codec)
1998{
1999 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002000 struct hdmi_spec_per_cvt *per_cvt;
Stephen Warren3aaf8982011-06-01 11:14:19 -06002001 int err;
Stephen Warren3aaf8982011-06-01 11:14:19 -06002002
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002003 per_cvt = get_cvt(spec, 0);
Anssi Hannula6492e3d2013-12-10 22:46:34 +02002004 err = snd_hda_create_dig_out_ctls(codec, per_cvt->cvt_nid,
2005 per_cvt->cvt_nid,
2006 HDA_PCM_TYPE_HDMI);
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002007 if (err < 0)
2008 return err;
2009 return simple_hdmi_build_jack(codec, 0);
Stephen Warren3aaf8982011-06-01 11:14:19 -06002010}
2011
Takashi Iwai4f0110c2012-06-15 12:45:43 +02002012static int simple_playback_init(struct hda_codec *codec)
2013{
2014 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002015 struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0);
2016 hda_nid_t pin = per_pin->pin_nid;
Takashi Iwai4f0110c2012-06-15 12:45:43 +02002017
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002018 snd_hda_codec_write(codec, pin, 0,
2019 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
2020 /* some codecs require to unmute the pin */
2021 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
2022 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2023 AMP_OUT_UNMUTE);
2024 snd_hda_jack_detect_enable(codec, pin, pin);
Takashi Iwai4f0110c2012-06-15 12:45:43 +02002025 return 0;
2026}
2027
Stephen Warren3aaf8982011-06-01 11:14:19 -06002028static void simple_playback_free(struct hda_codec *codec)
2029{
2030 struct hdmi_spec *spec = codec->spec;
2031
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002032 hdmi_array_free(spec);
Stephen Warren3aaf8982011-06-01 11:14:19 -06002033 kfree(spec);
2034}
2035
2036/*
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002037 * Nvidia specific implementations
2038 */
2039
2040#define Nv_VERB_SET_Channel_Allocation 0xF79
2041#define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
2042#define Nv_VERB_SET_Audio_Protection_On 0xF98
2043#define Nv_VERB_SET_Audio_Protection_Off 0xF99
2044
2045#define nvhdmi_master_con_nid_7x 0x04
2046#define nvhdmi_master_pin_nid_7x 0x05
2047
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02002048static const hda_nid_t nvhdmi_con_nids_7x[4] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002049 /*front, rear, clfe, rear_surr */
2050 0x6, 0x8, 0xa, 0xc,
2051};
2052
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002053static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = {
2054 /* set audio protect on */
2055 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
2056 /* enable digital output on pin widget */
2057 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2058 {} /* terminator */
2059};
2060
2061static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002062 /* set audio protect on */
2063 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
2064 /* enable digital output on pin widget */
2065 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2066 { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2067 { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2068 { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2069 { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2070 {} /* terminator */
2071};
2072
2073#ifdef LIMITED_RATE_FMT_SUPPORT
2074/* support only the safe format and rate */
2075#define SUPPORTED_RATES SNDRV_PCM_RATE_48000
2076#define SUPPORTED_MAXBPS 16
2077#define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
2078#else
2079/* support all rates and formats */
2080#define SUPPORTED_RATES \
2081 (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
2082 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
2083 SNDRV_PCM_RATE_192000)
2084#define SUPPORTED_MAXBPS 24
2085#define SUPPORTED_FORMATS \
2086 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
2087#endif
2088
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002089static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002090{
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002091 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
2092 return 0;
2093}
2094
2095static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
2096{
2097 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002098 return 0;
2099}
2100
Nitin Daga393004b2011-01-10 21:49:31 +05302101static unsigned int channels_2_6_8[] = {
2102 2, 6, 8
2103};
2104
2105static unsigned int channels_2_8[] = {
2106 2, 8
2107};
2108
2109static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
2110 .count = ARRAY_SIZE(channels_2_6_8),
2111 .list = channels_2_6_8,
2112 .mask = 0,
2113};
2114
2115static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
2116 .count = ARRAY_SIZE(channels_2_8),
2117 .list = channels_2_8,
2118 .mask = 0,
2119};
2120
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002121static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
2122 struct hda_codec *codec,
2123 struct snd_pcm_substream *substream)
2124{
2125 struct hdmi_spec *spec = codec->spec;
Nitin Daga393004b2011-01-10 21:49:31 +05302126 struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
2127
2128 switch (codec->preset->id) {
2129 case 0x10de0002:
2130 case 0x10de0003:
2131 case 0x10de0005:
2132 case 0x10de0006:
2133 hw_constraints_channels = &hw_constraints_2_8_channels;
2134 break;
2135 case 0x10de0007:
2136 hw_constraints_channels = &hw_constraints_2_6_8_channels;
2137 break;
2138 default:
2139 break;
2140 }
2141
2142 if (hw_constraints_channels != NULL) {
2143 snd_pcm_hw_constraint_list(substream->runtime, 0,
2144 SNDRV_PCM_HW_PARAM_CHANNELS,
2145 hw_constraints_channels);
Takashi Iwaiad09fc92011-01-14 09:42:27 +01002146 } else {
2147 snd_pcm_hw_constraint_step(substream->runtime, 0,
2148 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Nitin Daga393004b2011-01-10 21:49:31 +05302149 }
2150
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002151 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2152}
2153
2154static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
2155 struct hda_codec *codec,
2156 struct snd_pcm_substream *substream)
2157{
2158 struct hdmi_spec *spec = codec->spec;
2159 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2160}
2161
2162static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2163 struct hda_codec *codec,
2164 unsigned int stream_tag,
2165 unsigned int format,
2166 struct snd_pcm_substream *substream)
2167{
2168 struct hdmi_spec *spec = codec->spec;
2169 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2170 stream_tag, format, substream);
2171}
2172
Takashi Iwaid0b12522012-06-15 14:34:42 +02002173static const struct hda_pcm_stream simple_pcm_playback = {
2174 .substreams = 1,
2175 .channels_min = 2,
2176 .channels_max = 2,
2177 .ops = {
2178 .open = simple_playback_pcm_open,
2179 .close = simple_playback_pcm_close,
2180 .prepare = simple_playback_pcm_prepare
2181 },
2182};
2183
2184static const struct hda_codec_ops simple_hdmi_patch_ops = {
2185 .build_controls = simple_playback_build_controls,
2186 .build_pcms = simple_playback_build_pcms,
2187 .init = simple_playback_init,
2188 .free = simple_playback_free,
Takashi Iwai250e41a2012-06-15 14:40:21 +02002189 .unsol_event = simple_hdmi_unsol_event,
Takashi Iwaid0b12522012-06-15 14:34:42 +02002190};
2191
2192static int patch_simple_hdmi(struct hda_codec *codec,
2193 hda_nid_t cvt_nid, hda_nid_t pin_nid)
2194{
2195 struct hdmi_spec *spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002196 struct hdmi_spec_per_cvt *per_cvt;
2197 struct hdmi_spec_per_pin *per_pin;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002198
2199 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2200 if (!spec)
2201 return -ENOMEM;
2202
2203 codec->spec = spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002204 hdmi_array_init(spec, 1);
Takashi Iwaid0b12522012-06-15 14:34:42 +02002205
2206 spec->multiout.num_dacs = 0; /* no analog */
2207 spec->multiout.max_channels = 2;
2208 spec->multiout.dig_out_nid = cvt_nid;
2209 spec->num_cvts = 1;
2210 spec->num_pins = 1;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002211 per_pin = snd_array_new(&spec->pins);
2212 per_cvt = snd_array_new(&spec->cvts);
2213 if (!per_pin || !per_cvt) {
2214 simple_playback_free(codec);
2215 return -ENOMEM;
2216 }
2217 per_cvt->cvt_nid = cvt_nid;
2218 per_pin->pin_nid = pin_nid;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002219 spec->pcm_playback = simple_pcm_playback;
2220
2221 codec->patch_ops = simple_hdmi_patch_ops;
2222
2223 return 0;
2224}
2225
Aaron Plattner1f348522011-04-06 17:19:04 -07002226static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
2227 int channels)
2228{
2229 unsigned int chanmask;
2230 int chan = channels ? (channels - 1) : 1;
2231
2232 switch (channels) {
2233 default:
2234 case 0:
2235 case 2:
2236 chanmask = 0x00;
2237 break;
2238 case 4:
2239 chanmask = 0x08;
2240 break;
2241 case 6:
2242 chanmask = 0x0b;
2243 break;
2244 case 8:
2245 chanmask = 0x13;
2246 break;
2247 }
2248
2249 /* Set the audio infoframe channel allocation and checksum fields. The
2250 * channel count is computed implicitly by the hardware. */
2251 snd_hda_codec_write(codec, 0x1, 0,
2252 Nv_VERB_SET_Channel_Allocation, chanmask);
2253
2254 snd_hda_codec_write(codec, 0x1, 0,
2255 Nv_VERB_SET_Info_Frame_Checksum,
2256 (0x71 - chan - chanmask));
2257}
2258
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002259static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
2260 struct hda_codec *codec,
2261 struct snd_pcm_substream *substream)
2262{
2263 struct hdmi_spec *spec = codec->spec;
2264 int i;
2265
2266 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
2267 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
2268 for (i = 0; i < 4; i++) {
2269 /* set the stream id */
2270 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
2271 AC_VERB_SET_CHANNEL_STREAMID, 0);
2272 /* set the stream format */
2273 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
2274 AC_VERB_SET_STREAM_FORMAT, 0);
2275 }
2276
Aaron Plattner1f348522011-04-06 17:19:04 -07002277 /* The audio hardware sends a channel count of 0x7 (8ch) when all the
2278 * streams are disabled. */
2279 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
2280
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002281 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2282}
2283
2284static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
2285 struct hda_codec *codec,
2286 unsigned int stream_tag,
2287 unsigned int format,
2288 struct snd_pcm_substream *substream)
2289{
2290 int chs;
Takashi Iwai112daa72011-11-02 21:40:06 +01002291 unsigned int dataDCC2, channel_id;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002292 int i;
Stephen Warren7c935972011-06-01 11:14:17 -06002293 struct hdmi_spec *spec = codec->spec;
Takashi Iwaie3245cd2012-05-10 10:21:29 +02002294 struct hda_spdif_out *spdif;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002295 struct hdmi_spec_per_cvt *per_cvt;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002296
2297 mutex_lock(&codec->spdif_mutex);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002298 per_cvt = get_cvt(spec, 0);
2299 spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002300
2301 chs = substream->runtime->channels;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002302
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002303 dataDCC2 = 0x2;
2304
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002305 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
Stephen Warren7c935972011-06-01 11:14:17 -06002306 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002307 snd_hda_codec_write(codec,
2308 nvhdmi_master_con_nid_7x,
2309 0,
2310 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06002311 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002312
2313 /* set the stream id */
2314 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
2315 AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
2316
2317 /* set the stream format */
2318 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
2319 AC_VERB_SET_STREAM_FORMAT, format);
2320
2321 /* turn on again (if needed) */
2322 /* enable and set the channel status audio/data flag */
Stephen Warren7c935972011-06-01 11:14:17 -06002323 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002324 snd_hda_codec_write(codec,
2325 nvhdmi_master_con_nid_7x,
2326 0,
2327 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06002328 spdif->ctls & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002329 snd_hda_codec_write(codec,
2330 nvhdmi_master_con_nid_7x,
2331 0,
2332 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
2333 }
2334
2335 for (i = 0; i < 4; i++) {
2336 if (chs == 2)
2337 channel_id = 0;
2338 else
2339 channel_id = i * 2;
2340
2341 /* turn off SPDIF once;
2342 *otherwise the IEC958 bits won't be updated
2343 */
2344 if (codec->spdif_status_reset &&
Stephen Warren7c935972011-06-01 11:14:17 -06002345 (spdif->ctls & AC_DIG1_ENABLE))
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002346 snd_hda_codec_write(codec,
2347 nvhdmi_con_nids_7x[i],
2348 0,
2349 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06002350 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002351 /* set the stream id */
2352 snd_hda_codec_write(codec,
2353 nvhdmi_con_nids_7x[i],
2354 0,
2355 AC_VERB_SET_CHANNEL_STREAMID,
2356 (stream_tag << 4) | channel_id);
2357 /* set the stream format */
2358 snd_hda_codec_write(codec,
2359 nvhdmi_con_nids_7x[i],
2360 0,
2361 AC_VERB_SET_STREAM_FORMAT,
2362 format);
2363 /* turn on again (if needed) */
2364 /* enable and set the channel status audio/data flag */
2365 if (codec->spdif_status_reset &&
Stephen Warren7c935972011-06-01 11:14:17 -06002366 (spdif->ctls & AC_DIG1_ENABLE)) {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002367 snd_hda_codec_write(codec,
2368 nvhdmi_con_nids_7x[i],
2369 0,
2370 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06002371 spdif->ctls & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002372 snd_hda_codec_write(codec,
2373 nvhdmi_con_nids_7x[i],
2374 0,
2375 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
2376 }
2377 }
2378
Aaron Plattner1f348522011-04-06 17:19:04 -07002379 nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002380
2381 mutex_unlock(&codec->spdif_mutex);
2382 return 0;
2383}
2384
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02002385static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002386 .substreams = 1,
2387 .channels_min = 2,
2388 .channels_max = 8,
2389 .nid = nvhdmi_master_con_nid_7x,
2390 .rates = SUPPORTED_RATES,
2391 .maxbps = SUPPORTED_MAXBPS,
2392 .formats = SUPPORTED_FORMATS,
2393 .ops = {
2394 .open = simple_playback_pcm_open,
2395 .close = nvhdmi_8ch_7x_pcm_close,
2396 .prepare = nvhdmi_8ch_7x_pcm_prepare
2397 },
2398};
2399
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002400static int patch_nvhdmi_2ch(struct hda_codec *codec)
2401{
2402 struct hdmi_spec *spec;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002403 int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
2404 nvhdmi_master_pin_nid_7x);
2405 if (err < 0)
2406 return err;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002407
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002408 codec->patch_ops.init = nvhdmi_7x_init_2ch;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002409 /* override the PCM rates, etc, as the codec doesn't give full list */
2410 spec = codec->spec;
2411 spec->pcm_playback.rates = SUPPORTED_RATES;
2412 spec->pcm_playback.maxbps = SUPPORTED_MAXBPS;
2413 spec->pcm_playback.formats = SUPPORTED_FORMATS;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002414 return 0;
2415}
2416
Takashi Iwai53775b02012-08-01 12:17:41 +02002417static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
2418{
2419 struct hdmi_spec *spec = codec->spec;
2420 int err = simple_playback_build_pcms(codec);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002421 if (!err) {
2422 struct hda_pcm *info = get_pcm_rec(spec, 0);
2423 info->own_chmap = true;
2424 }
Takashi Iwai53775b02012-08-01 12:17:41 +02002425 return err;
2426}
2427
2428static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
2429{
2430 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002431 struct hda_pcm *info;
Takashi Iwai53775b02012-08-01 12:17:41 +02002432 struct snd_pcm_chmap *chmap;
2433 int err;
2434
2435 err = simple_playback_build_controls(codec);
2436 if (err < 0)
2437 return err;
2438
2439 /* add channel maps */
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002440 info = get_pcm_rec(spec, 0);
2441 err = snd_pcm_add_chmap_ctls(info->pcm,
Takashi Iwai53775b02012-08-01 12:17:41 +02002442 SNDRV_PCM_STREAM_PLAYBACK,
2443 snd_pcm_alt_chmaps, 8, 0, &chmap);
2444 if (err < 0)
2445 return err;
2446 switch (codec->preset->id) {
2447 case 0x10de0002:
2448 case 0x10de0003:
2449 case 0x10de0005:
2450 case 0x10de0006:
2451 chmap->channel_mask = (1U << 2) | (1U << 8);
2452 break;
2453 case 0x10de0007:
2454 chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8);
2455 }
2456 return 0;
2457}
2458
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002459static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
2460{
2461 struct hdmi_spec *spec;
2462 int err = patch_nvhdmi_2ch(codec);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002463 if (err < 0)
2464 return err;
2465 spec = codec->spec;
2466 spec->multiout.max_channels = 8;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002467 spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x;
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002468 codec->patch_ops.init = nvhdmi_7x_init_8ch;
Takashi Iwai53775b02012-08-01 12:17:41 +02002469 codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
2470 codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
Aaron Plattner1f348522011-04-06 17:19:04 -07002471
2472 /* Initialize the audio infoframe channel mask and checksum to something
2473 * valid */
2474 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
2475
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002476 return 0;
2477}
2478
2479/*
2480 * ATI-specific implementations
2481 *
2482 * FIXME: we may omit the whole this and use the generic code once after
2483 * it's confirmed to work.
2484 */
2485
2486#define ATIHDMI_CVT_NID 0x02 /* audio converter */
2487#define ATIHDMI_PIN_NID 0x03 /* HDMI output pin */
2488
2489static int atihdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2490 struct hda_codec *codec,
2491 unsigned int stream_tag,
2492 unsigned int format,
2493 struct snd_pcm_substream *substream)
2494{
2495 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002496 struct hdmi_spec_per_cvt *per_cvt = get_cvt(spec, 0);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002497 int chans = substream->runtime->channels;
2498 int i, err;
2499
2500 err = simple_playback_pcm_prepare(hinfo, codec, stream_tag, format,
2501 substream);
2502 if (err < 0)
2503 return err;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002504 snd_hda_codec_write(codec, per_cvt->cvt_nid, 0,
Stephen Warren384a48d2011-06-01 11:14:21 -06002505 AC_VERB_SET_CVT_CHAN_COUNT, chans - 1);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002506 /* FIXME: XXX */
2507 for (i = 0; i < chans; i++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002508 snd_hda_codec_write(codec, per_cvt->cvt_nid, 0,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002509 AC_VERB_SET_HDMI_CHAN_SLOT,
2510 (i << 4) | i);
2511 }
2512 return 0;
2513}
2514
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002515static int patch_atihdmi(struct hda_codec *codec)
2516{
2517 struct hdmi_spec *spec;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002518 int err = patch_simple_hdmi(codec, ATIHDMI_CVT_NID, ATIHDMI_PIN_NID);
2519 if (err < 0)
2520 return err;
2521 spec = codec->spec;
2522 spec->pcm_playback.ops.prepare = atihdmi_playback_pcm_prepare;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002523 return 0;
2524}
2525
Annie Liu3de5ff82012-06-08 19:18:42 +08002526/* VIA HDMI Implementation */
2527#define VIAHDMI_CVT_NID 0x02 /* audio converter1 */
2528#define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */
2529
Annie Liu3de5ff82012-06-08 19:18:42 +08002530static int patch_via_hdmi(struct hda_codec *codec)
2531{
Takashi Iwai250e41a2012-06-15 14:40:21 +02002532 return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
Annie Liu3de5ff82012-06-08 19:18:42 +08002533}
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002534
2535/*
2536 * patch entries
2537 */
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02002538static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002539{ .id = 0x1002793c, .name = "RS600 HDMI", .patch = patch_atihdmi },
2540{ .id = 0x10027919, .name = "RS600 HDMI", .patch = patch_atihdmi },
2541{ .id = 0x1002791a, .name = "RS690/780 HDMI", .patch = patch_atihdmi },
Anssi Hannula36e9c132010-12-05 02:34:15 +02002542{ .id = 0x1002aa01, .name = "R6xx HDMI", .patch = patch_generic_hdmi },
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002543{ .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_generic_hdmi },
2544{ .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_generic_hdmi },
2545{ .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_generic_hdmi },
2546{ .id = 0x10de0002, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2547{ .id = 0x10de0003, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2548{ .id = 0x10de0005, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2549{ .id = 0x10de0006, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2550{ .id = 0x10de0007, .name = "MCP79/7A HDMI", .patch = patch_nvhdmi_8ch_7x },
Stephen Warren5d44f922011-05-24 17:11:17 -06002551{ .id = 0x10de000a, .name = "GPU 0a HDMI/DP", .patch = patch_generic_hdmi },
2552{ .id = 0x10de000b, .name = "GPU 0b HDMI/DP", .patch = patch_generic_hdmi },
2553{ .id = 0x10de000c, .name = "MCP89 HDMI", .patch = patch_generic_hdmi },
2554{ .id = 0x10de000d, .name = "GPU 0d HDMI/DP", .patch = patch_generic_hdmi },
2555{ .id = 0x10de0010, .name = "GPU 10 HDMI/DP", .patch = patch_generic_hdmi },
2556{ .id = 0x10de0011, .name = "GPU 11 HDMI/DP", .patch = patch_generic_hdmi },
2557{ .id = 0x10de0012, .name = "GPU 12 HDMI/DP", .patch = patch_generic_hdmi },
2558{ .id = 0x10de0013, .name = "GPU 13 HDMI/DP", .patch = patch_generic_hdmi },
2559{ .id = 0x10de0014, .name = "GPU 14 HDMI/DP", .patch = patch_generic_hdmi },
2560{ .id = 0x10de0015, .name = "GPU 15 HDMI/DP", .patch = patch_generic_hdmi },
2561{ .id = 0x10de0016, .name = "GPU 16 HDMI/DP", .patch = patch_generic_hdmi },
Richard Samsonc8900a02011-03-03 12:46:13 +01002562/* 17 is known to be absent */
Stephen Warren5d44f922011-05-24 17:11:17 -06002563{ .id = 0x10de0018, .name = "GPU 18 HDMI/DP", .patch = patch_generic_hdmi },
2564{ .id = 0x10de0019, .name = "GPU 19 HDMI/DP", .patch = patch_generic_hdmi },
2565{ .id = 0x10de001a, .name = "GPU 1a HDMI/DP", .patch = patch_generic_hdmi },
2566{ .id = 0x10de001b, .name = "GPU 1b HDMI/DP", .patch = patch_generic_hdmi },
2567{ .id = 0x10de001c, .name = "GPU 1c HDMI/DP", .patch = patch_generic_hdmi },
2568{ .id = 0x10de0040, .name = "GPU 40 HDMI/DP", .patch = patch_generic_hdmi },
2569{ .id = 0x10de0041, .name = "GPU 41 HDMI/DP", .patch = patch_generic_hdmi },
2570{ .id = 0x10de0042, .name = "GPU 42 HDMI/DP", .patch = patch_generic_hdmi },
2571{ .id = 0x10de0043, .name = "GPU 43 HDMI/DP", .patch = patch_generic_hdmi },
2572{ .id = 0x10de0044, .name = "GPU 44 HDMI/DP", .patch = patch_generic_hdmi },
Aaron Plattner7ae48b52012-07-16 17:10:04 -07002573{ .id = 0x10de0051, .name = "GPU 51 HDMI/DP", .patch = patch_generic_hdmi },
Aaron Plattner782e9ca2013-07-12 11:01:37 -07002574{ .id = 0x10de0060, .name = "GPU 60 HDMI/DP", .patch = patch_generic_hdmi },
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002575{ .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch },
2576{ .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch },
Annie Liu3de5ff82012-06-08 19:18:42 +08002577{ .id = 0x11069f80, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi },
2578{ .id = 0x11069f81, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi },
2579{ .id = 0x11069f84, .name = "VX11 HDMI/DP", .patch = patch_generic_hdmi },
2580{ .id = 0x11069f85, .name = "VX11 HDMI/DP", .patch = patch_generic_hdmi },
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002581{ .id = 0x80860054, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi },
2582{ .id = 0x80862801, .name = "Bearlake HDMI", .patch = patch_generic_hdmi },
2583{ .id = 0x80862802, .name = "Cantiga HDMI", .patch = patch_generic_hdmi },
2584{ .id = 0x80862803, .name = "Eaglelake HDMI", .patch = patch_generic_hdmi },
2585{ .id = 0x80862804, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi },
2586{ .id = 0x80862805, .name = "CougarPoint HDMI", .patch = patch_generic_hdmi },
Wu Fengguang591e6102011-05-20 15:35:43 +08002587{ .id = 0x80862806, .name = "PantherPoint HDMI", .patch = patch_generic_hdmi },
Wang Xingchao1c766842012-06-13 10:23:52 +08002588{ .id = 0x80862807, .name = "Haswell HDMI", .patch = patch_generic_hdmi },
Wu Fengguang6edc59e2012-02-23 15:07:44 +08002589{ .id = 0x80862880, .name = "CedarTrail HDMI", .patch = patch_generic_hdmi },
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002590{ .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi },
2591{} /* terminator */
2592};
2593
2594MODULE_ALIAS("snd-hda-codec-id:1002793c");
2595MODULE_ALIAS("snd-hda-codec-id:10027919");
2596MODULE_ALIAS("snd-hda-codec-id:1002791a");
2597MODULE_ALIAS("snd-hda-codec-id:1002aa01");
2598MODULE_ALIAS("snd-hda-codec-id:10951390");
2599MODULE_ALIAS("snd-hda-codec-id:10951392");
2600MODULE_ALIAS("snd-hda-codec-id:10de0002");
2601MODULE_ALIAS("snd-hda-codec-id:10de0003");
2602MODULE_ALIAS("snd-hda-codec-id:10de0005");
2603MODULE_ALIAS("snd-hda-codec-id:10de0006");
2604MODULE_ALIAS("snd-hda-codec-id:10de0007");
2605MODULE_ALIAS("snd-hda-codec-id:10de000a");
2606MODULE_ALIAS("snd-hda-codec-id:10de000b");
2607MODULE_ALIAS("snd-hda-codec-id:10de000c");
2608MODULE_ALIAS("snd-hda-codec-id:10de000d");
2609MODULE_ALIAS("snd-hda-codec-id:10de0010");
2610MODULE_ALIAS("snd-hda-codec-id:10de0011");
2611MODULE_ALIAS("snd-hda-codec-id:10de0012");
2612MODULE_ALIAS("snd-hda-codec-id:10de0013");
2613MODULE_ALIAS("snd-hda-codec-id:10de0014");
Richard Samsonc8900a02011-03-03 12:46:13 +01002614MODULE_ALIAS("snd-hda-codec-id:10de0015");
2615MODULE_ALIAS("snd-hda-codec-id:10de0016");
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002616MODULE_ALIAS("snd-hda-codec-id:10de0018");
2617MODULE_ALIAS("snd-hda-codec-id:10de0019");
2618MODULE_ALIAS("snd-hda-codec-id:10de001a");
2619MODULE_ALIAS("snd-hda-codec-id:10de001b");
2620MODULE_ALIAS("snd-hda-codec-id:10de001c");
2621MODULE_ALIAS("snd-hda-codec-id:10de0040");
2622MODULE_ALIAS("snd-hda-codec-id:10de0041");
2623MODULE_ALIAS("snd-hda-codec-id:10de0042");
2624MODULE_ALIAS("snd-hda-codec-id:10de0043");
2625MODULE_ALIAS("snd-hda-codec-id:10de0044");
Aaron Plattner7ae48b52012-07-16 17:10:04 -07002626MODULE_ALIAS("snd-hda-codec-id:10de0051");
Aaron Plattner782e9ca2013-07-12 11:01:37 -07002627MODULE_ALIAS("snd-hda-codec-id:10de0060");
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002628MODULE_ALIAS("snd-hda-codec-id:10de0067");
2629MODULE_ALIAS("snd-hda-codec-id:10de8001");
Annie Liu3de5ff82012-06-08 19:18:42 +08002630MODULE_ALIAS("snd-hda-codec-id:11069f80");
2631MODULE_ALIAS("snd-hda-codec-id:11069f81");
2632MODULE_ALIAS("snd-hda-codec-id:11069f84");
2633MODULE_ALIAS("snd-hda-codec-id:11069f85");
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002634MODULE_ALIAS("snd-hda-codec-id:17e80047");
2635MODULE_ALIAS("snd-hda-codec-id:80860054");
2636MODULE_ALIAS("snd-hda-codec-id:80862801");
2637MODULE_ALIAS("snd-hda-codec-id:80862802");
2638MODULE_ALIAS("snd-hda-codec-id:80862803");
2639MODULE_ALIAS("snd-hda-codec-id:80862804");
2640MODULE_ALIAS("snd-hda-codec-id:80862805");
Wu Fengguang591e6102011-05-20 15:35:43 +08002641MODULE_ALIAS("snd-hda-codec-id:80862806");
Wang Xingchao1c766842012-06-13 10:23:52 +08002642MODULE_ALIAS("snd-hda-codec-id:80862807");
Wu Fengguang6edc59e2012-02-23 15:07:44 +08002643MODULE_ALIAS("snd-hda-codec-id:80862880");
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002644MODULE_ALIAS("snd-hda-codec-id:808629fb");
2645
2646MODULE_LICENSE("GPL");
2647MODULE_DESCRIPTION("HDMI HD-audio codec");
2648MODULE_ALIAS("snd-hda-codec-intelhdmi");
2649MODULE_ALIAS("snd-hda-codec-nvhdmi");
2650MODULE_ALIAS("snd-hda-codec-atihdmi");
2651
2652static struct hda_codec_preset_list intel_list = {
2653 .preset = snd_hda_preset_hdmi,
2654 .owner = THIS_MODULE,
2655};
2656
2657static int __init patch_hdmi_init(void)
2658{
2659 return snd_hda_add_codec_preset(&intel_list);
2660}
2661
2662static void __exit patch_hdmi_exit(void)
2663{
2664 snd_hda_delete_codec_preset(&intel_list);
2665}
2666
2667module_init(patch_hdmi_init)
2668module_exit(patch_hdmi_exit)