blob: acc00fe01b71fe13c589a3ae4cbdd92669b462e3 [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
Mengdong Linfb87fa32013-09-04 16:36:57 -040047#define is_haswell(codec) ((codec)->vendor_id == 0x80862807)
48
Stephen Warren384a48d2011-06-01 11:14:21 -060049struct hdmi_spec_per_cvt {
50 hda_nid_t cvt_nid;
51 int assigned;
52 unsigned int channels_min;
53 unsigned int channels_max;
54 u32 rates;
55 u64 formats;
56 unsigned int maxbps;
57};
58
Takashi Iwai4eea3092013-02-07 18:18:19 +010059/* max. connections to a widget */
60#define HDA_MAX_CONNECTIONS 32
61
Stephen Warren384a48d2011-06-01 11:14:21 -060062struct hdmi_spec_per_pin {
63 hda_nid_t pin_nid;
64 int num_mux_nids;
65 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
Anssi Hannula1df5a062013-10-05 02:25:40 +030066 hda_nid_t cvt_nid;
Wu Fengguang744626d2011-11-16 16:29:47 +080067
68 struct hda_codec *codec;
Stephen Warren384a48d2011-06-01 11:14:21 -060069 struct hdmi_eld sink_eld;
Takashi Iwaia4e9a382013-10-17 18:21:12 +020070 struct mutex lock;
Wu Fengguang744626d2011-11-16 16:29:47 +080071 struct delayed_work work;
David Henningsson92c69e72013-02-19 16:11:26 +010072 struct snd_kcontrol *eld_ctl;
Wu Fengguangc6e84532011-11-18 16:59:32 -060073 int repoll_count;
Takashi Iwaib0540872013-09-02 12:33:02 +020074 bool setup; /* the stream has been set up by prepare callback */
75 int channels; /* current number of channels */
Takashi Iwai1a6003b2012-09-06 17:42:08 +020076 bool non_pcm;
Takashi Iwaid45e6882012-07-31 11:36:00 +020077 bool chmap_set; /* channel-map override by ALSA API? */
78 unsigned char chmap[8]; /* ALSA API channel-map */
Takashi Iwaibce0d2a2013-03-13 14:40:31 +010079 char pcm_name[8]; /* filled in build_pcm callbacks */
Takashi Iwaia4e9a382013-10-17 18:21:12 +020080#ifdef CONFIG_PROC_FS
81 struct snd_info_entry *proc_entry;
82#endif
Stephen Warren384a48d2011-06-01 11:14:21 -060083};
84
Anssi Hannula307229d2013-10-24 21:10:34 +030085struct cea_channel_speaker_allocation;
86
87/* operations used by generic code that can be overridden by patches */
88struct hdmi_ops {
89 int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid,
90 unsigned char *buf, int *eld_size);
91
92 /* get and set channel assigned to each HDMI ASP (audio sample packet) slot */
93 int (*pin_get_slot_channel)(struct hda_codec *codec, hda_nid_t pin_nid,
94 int asp_slot);
95 int (*pin_set_slot_channel)(struct hda_codec *codec, hda_nid_t pin_nid,
96 int asp_slot, int channel);
97
98 void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid,
99 int ca, int active_channels, int conn_type);
100
101 /* enable/disable HBR (HD passthrough) */
102 int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid, bool hbr);
103
104 int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid,
105 hda_nid_t pin_nid, u32 stream_tag, int format);
106
107 /* Helpers for producing the channel map TLVs. These can be overridden
108 * for devices that have non-standard mapping requirements. */
109 int (*chmap_cea_alloc_validate_get_type)(struct cea_channel_speaker_allocation *cap,
110 int channels);
111 void (*cea_alloc_to_tlv_chmap)(struct cea_channel_speaker_allocation *cap,
112 unsigned int *chmap, int channels);
113
114 /* check that the user-given chmap is supported */
115 int (*chmap_validate)(int ca, int channels, unsigned char *chmap);
116};
117
Wu Fengguang079d88c2010-03-08 10:44:23 +0800118struct hdmi_spec {
119 int num_cvts;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100120 struct snd_array cvts; /* struct hdmi_spec_per_cvt */
121 hda_nid_t cvt_nids[4]; /* only for haswell fix */
Stephen Warren384a48d2011-06-01 11:14:21 -0600122
Wu Fengguang079d88c2010-03-08 10:44:23 +0800123 int num_pins;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100124 struct snd_array pins; /* struct hdmi_spec_per_pin */
125 struct snd_array pcm_rec; /* struct hda_pcm */
Takashi Iwaid45e6882012-07-31 11:36:00 +0200126 unsigned int channels_max; /* max over all cvts */
Wu Fengguang079d88c2010-03-08 10:44:23 +0800127
David Henningsson4bd038f2013-02-19 16:11:25 +0100128 struct hdmi_eld temp_eld;
Anssi Hannula307229d2013-10-24 21:10:34 +0300129 struct hdmi_ops ops;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800130 /*
Stephen Warren384a48d2011-06-01 11:14:21 -0600131 * Non-generic ATI/NVIDIA specific
Wu Fengguang079d88c2010-03-08 10:44:23 +0800132 */
133 struct hda_multi_out multiout;
Takashi Iwaid0b12522012-06-15 14:34:42 +0200134 struct hda_pcm_stream pcm_playback;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800135};
136
137
138struct hdmi_audio_infoframe {
139 u8 type; /* 0x84 */
140 u8 ver; /* 0x01 */
141 u8 len; /* 0x0a */
142
Wu Fengguang53d7d692010-09-21 14:25:49 +0800143 u8 checksum;
144
Wu Fengguang079d88c2010-03-08 10:44:23 +0800145 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
146 u8 SS01_SF24;
147 u8 CXT04;
148 u8 CA;
149 u8 LFEPBL01_LSV36_DM_INH7;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800150};
151
152struct dp_audio_infoframe {
153 u8 type; /* 0x84 */
154 u8 len; /* 0x1b */
155 u8 ver; /* 0x11 << 2 */
156
157 u8 CC02_CT47; /* match with HDMI infoframe from this on */
158 u8 SS01_SF24;
159 u8 CXT04;
160 u8 CA;
161 u8 LFEPBL01_LSV36_DM_INH7;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800162};
163
Takashi Iwai2b203dbb2011-02-11 12:17:30 +0100164union audio_infoframe {
165 struct hdmi_audio_infoframe hdmi;
166 struct dp_audio_infoframe dp;
167 u8 bytes[0];
168};
169
Wu Fengguang079d88c2010-03-08 10:44:23 +0800170/*
171 * CEA speaker placement:
172 *
173 * FLH FCH FRH
174 * FLW FL FLC FC FRC FR FRW
175 *
176 * LFE
177 * TC
178 *
179 * RL RLC RC RRC RR
180 *
181 * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
182 * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
183 */
184enum cea_speaker_placement {
185 FL = (1 << 0), /* Front Left */
186 FC = (1 << 1), /* Front Center */
187 FR = (1 << 2), /* Front Right */
188 FLC = (1 << 3), /* Front Left Center */
189 FRC = (1 << 4), /* Front Right Center */
190 RL = (1 << 5), /* Rear Left */
191 RC = (1 << 6), /* Rear Center */
192 RR = (1 << 7), /* Rear Right */
193 RLC = (1 << 8), /* Rear Left Center */
194 RRC = (1 << 9), /* Rear Right Center */
195 LFE = (1 << 10), /* Low Frequency Effect */
196 FLW = (1 << 11), /* Front Left Wide */
197 FRW = (1 << 12), /* Front Right Wide */
198 FLH = (1 << 13), /* Front Left High */
199 FCH = (1 << 14), /* Front Center High */
200 FRH = (1 << 15), /* Front Right High */
201 TC = (1 << 16), /* Top Center */
202};
203
204/*
205 * ELD SA bits in the CEA Speaker Allocation data block
206 */
207static int eld_speaker_allocation_bits[] = {
208 [0] = FL | FR,
209 [1] = LFE,
210 [2] = FC,
211 [3] = RL | RR,
212 [4] = RC,
213 [5] = FLC | FRC,
214 [6] = RLC | RRC,
215 /* the following are not defined in ELD yet */
216 [7] = FLW | FRW,
217 [8] = FLH | FRH,
218 [9] = TC,
219 [10] = FCH,
220};
221
222struct cea_channel_speaker_allocation {
223 int ca_index;
224 int speakers[8];
225
226 /* derived values, just for convenience */
227 int channels;
228 int spk_mask;
229};
230
231/*
232 * ALSA sequence is:
233 *
234 * surround40 surround41 surround50 surround51 surround71
235 * ch0 front left = = = =
236 * ch1 front right = = = =
237 * ch2 rear left = = = =
238 * ch3 rear right = = = =
239 * ch4 LFE center center center
240 * ch5 LFE LFE
241 * ch6 side left
242 * ch7 side right
243 *
244 * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR}
245 */
246static int hdmi_channel_mapping[0x32][8] = {
247 /* stereo */
248 [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
249 /* 2.1 */
250 [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
251 /* Dolby Surround */
252 [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 },
253 /* surround40 */
254 [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 },
255 /* 4ch */
256 [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 },
257 /* surround41 */
Jerry Zhou9396d312010-09-21 14:44:51 +0800258 [0x09] = { 0x00, 0x11, 0x24, 0x35, 0x42, 0xf3, 0xf6, 0xf7 },
Wu Fengguang079d88c2010-03-08 10:44:23 +0800259 /* surround50 */
260 [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 },
261 /* surround51 */
262 [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 },
263 /* 7.1 */
264 [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 },
265};
266
267/*
268 * This is an ordered list!
269 *
270 * The preceding ones have better chances to be selected by
Wu Fengguang53d7d692010-09-21 14:25:49 +0800271 * hdmi_channel_allocation().
Wu Fengguang079d88c2010-03-08 10:44:23 +0800272 */
273static struct cea_channel_speaker_allocation channel_allocations[] = {
274/* channel: 7 6 5 4 3 2 1 0 */
275{ .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
276 /* 2.1 */
277{ .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
278 /* Dolby Surround */
279{ .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
280 /* surround40 */
281{ .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
282 /* surround41 */
283{ .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
284 /* surround50 */
285{ .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
286 /* surround51 */
287{ .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
288 /* 6.1 */
289{ .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
290 /* surround71 */
291{ .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
292
293{ .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
294{ .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
295{ .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
296{ .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
297{ .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
298{ .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
299{ .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
300{ .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
301{ .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
302{ .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
303{ .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
304{ .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
305{ .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
306{ .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
307{ .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
308{ .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
309{ .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
310{ .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
311{ .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
312{ .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
313{ .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
314{ .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
315{ .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
316{ .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } },
317{ .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } },
318{ .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } },
319{ .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } },
320{ .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } },
321{ .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } },
322{ .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } },
323{ .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } },
324{ .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } },
325{ .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } },
326{ .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } },
327{ .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } },
328{ .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } },
329{ .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } },
330{ .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } },
331{ .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } },
332{ .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } },
333{ .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
334};
335
336
337/*
338 * HDMI routines
339 */
340
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100341#define get_pin(spec, idx) \
342 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx))
343#define get_cvt(spec, idx) \
344 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx))
345#define get_pcm_rec(spec, idx) \
346 ((struct hda_pcm *)snd_array_elem(&spec->pcm_rec, idx))
347
Stephen Warren384a48d2011-06-01 11:14:21 -0600348static int pin_nid_to_pin_index(struct hdmi_spec *spec, hda_nid_t pin_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800349{
Stephen Warren384a48d2011-06-01 11:14:21 -0600350 int pin_idx;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800351
Stephen Warren384a48d2011-06-01 11:14:21 -0600352 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100353 if (get_pin(spec, pin_idx)->pin_nid == pin_nid)
Stephen Warren384a48d2011-06-01 11:14:21 -0600354 return pin_idx;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800355
Stephen Warren384a48d2011-06-01 11:14:21 -0600356 snd_printk(KERN_WARNING "HDMI: pin nid %d not registered\n", pin_nid);
357 return -EINVAL;
358}
359
360static int hinfo_to_pin_index(struct hdmi_spec *spec,
361 struct hda_pcm_stream *hinfo)
362{
363 int pin_idx;
364
365 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100366 if (get_pcm_rec(spec, pin_idx)->stream == hinfo)
Stephen Warren384a48d2011-06-01 11:14:21 -0600367 return pin_idx;
368
369 snd_printk(KERN_WARNING "HDMI: hinfo %p not registered\n", hinfo);
370 return -EINVAL;
371}
372
373static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid)
374{
375 int cvt_idx;
376
377 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100378 if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid)
Stephen Warren384a48d2011-06-01 11:14:21 -0600379 return cvt_idx;
380
381 snd_printk(KERN_WARNING "HDMI: cvt nid %d not registered\n", cvt_nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800382 return -EINVAL;
383}
384
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500385static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
386 struct snd_ctl_elem_info *uinfo)
387{
388 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
David Henningsson68e03de2013-02-19 16:11:23 +0100389 struct hdmi_spec *spec = codec->spec;
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200390 struct hdmi_spec_per_pin *per_pin;
David Henningsson68e03de2013-02-19 16:11:23 +0100391 struct hdmi_eld *eld;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500392 int pin_idx;
393
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500394 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
395
396 pin_idx = kcontrol->private_value;
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200397 per_pin = get_pin(spec, pin_idx);
398 eld = &per_pin->sink_eld;
David Henningsson68e03de2013-02-19 16:11:23 +0100399
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200400 mutex_lock(&per_pin->lock);
David Henningsson68e03de2013-02-19 16:11:23 +0100401 uinfo->count = eld->eld_valid ? eld->eld_size : 0;
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200402 mutex_unlock(&per_pin->lock);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500403
404 return 0;
405}
406
407static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
408 struct snd_ctl_elem_value *ucontrol)
409{
410 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
David Henningsson68e03de2013-02-19 16:11:23 +0100411 struct hdmi_spec *spec = codec->spec;
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200412 struct hdmi_spec_per_pin *per_pin;
David Henningsson68e03de2013-02-19 16:11:23 +0100413 struct hdmi_eld *eld;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500414 int pin_idx;
415
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500416 pin_idx = kcontrol->private_value;
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200417 per_pin = get_pin(spec, pin_idx);
418 eld = &per_pin->sink_eld;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500419
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200420 mutex_lock(&per_pin->lock);
David Henningsson68e03de2013-02-19 16:11:23 +0100421 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data)) {
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200422 mutex_unlock(&per_pin->lock);
David Henningsson68e03de2013-02-19 16:11:23 +0100423 snd_BUG();
424 return -EINVAL;
425 }
426
427 memset(ucontrol->value.bytes.data, 0,
428 ARRAY_SIZE(ucontrol->value.bytes.data));
429 if (eld->eld_valid)
430 memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
431 eld->eld_size);
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200432 mutex_unlock(&per_pin->lock);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500433
434 return 0;
435}
436
437static struct snd_kcontrol_new eld_bytes_ctl = {
438 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
439 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
440 .name = "ELD",
441 .info = hdmi_eld_ctl_info,
442 .get = hdmi_eld_ctl_get,
443};
444
445static int hdmi_create_eld_ctl(struct hda_codec *codec, int pin_idx,
446 int device)
447{
448 struct snd_kcontrol *kctl;
449 struct hdmi_spec *spec = codec->spec;
450 int err;
451
452 kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
453 if (!kctl)
454 return -ENOMEM;
455 kctl->private_value = pin_idx;
456 kctl->id.device = device;
457
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100458 err = snd_hda_ctl_add(codec, get_pin(spec, pin_idx)->pin_nid, kctl);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500459 if (err < 0)
460 return err;
461
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100462 get_pin(spec, pin_idx)->eld_ctl = kctl;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500463 return 0;
464}
465
Wu Fengguang079d88c2010-03-08 10:44:23 +0800466#ifdef BE_PARANOID
467static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
468 int *packet_index, int *byte_index)
469{
470 int val;
471
472 val = snd_hda_codec_read(codec, pin_nid, 0,
473 AC_VERB_GET_HDMI_DIP_INDEX, 0);
474
475 *packet_index = val >> 5;
476 *byte_index = val & 0x1f;
477}
478#endif
479
480static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
481 int packet_index, int byte_index)
482{
483 int val;
484
485 val = (packet_index << 5) | (byte_index & 0x1f);
486
487 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
488}
489
490static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
491 unsigned char val)
492{
493 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
494}
495
Stephen Warren384a48d2011-06-01 11:14:21 -0600496static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800497{
498 /* Unmute */
499 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
500 snd_hda_codec_write(codec, pin_nid, 0,
501 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
Takashi Iwai6169b672012-12-14 10:22:35 +0100502 /* Enable pin out: some machines with GM965 gets broken output when
503 * the pin is disabled or changed while using with HDMI
504 */
Wu Fengguang079d88c2010-03-08 10:44:23 +0800505 snd_hda_codec_write(codec, pin_nid, 0,
Takashi Iwai6169b672012-12-14 10:22:35 +0100506 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800507}
508
Stephen Warren384a48d2011-06-01 11:14:21 -0600509static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800510{
Stephen Warren384a48d2011-06-01 11:14:21 -0600511 return 1 + snd_hda_codec_read(codec, cvt_nid, 0,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800512 AC_VERB_GET_CVT_CHAN_COUNT, 0);
513}
514
515static void hdmi_set_channel_count(struct hda_codec *codec,
Stephen Warren384a48d2011-06-01 11:14:21 -0600516 hda_nid_t cvt_nid, int chs)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800517{
Stephen Warren384a48d2011-06-01 11:14:21 -0600518 if (chs != hdmi_get_channel_count(codec, cvt_nid))
519 snd_hda_codec_write(codec, cvt_nid, 0,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800520 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
521}
522
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200523/*
524 * ELD proc files
525 */
526
527#ifdef CONFIG_PROC_FS
528static void print_eld_info(struct snd_info_entry *entry,
529 struct snd_info_buffer *buffer)
530{
531 struct hdmi_spec_per_pin *per_pin = entry->private_data;
532
533 mutex_lock(&per_pin->lock);
534 snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer);
535 mutex_unlock(&per_pin->lock);
536}
537
538static void write_eld_info(struct snd_info_entry *entry,
539 struct snd_info_buffer *buffer)
540{
541 struct hdmi_spec_per_pin *per_pin = entry->private_data;
542
543 mutex_lock(&per_pin->lock);
544 snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer);
545 mutex_unlock(&per_pin->lock);
546}
547
548static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
549{
550 char name[32];
551 struct hda_codec *codec = per_pin->codec;
552 struct snd_info_entry *entry;
553 int err;
554
555 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
556 err = snd_card_proc_new(codec->bus->card, name, &entry);
557 if (err < 0)
558 return err;
559
560 snd_info_set_text_ops(entry, per_pin, print_eld_info);
561 entry->c.text.write = write_eld_info;
562 entry->mode |= S_IWUSR;
563 per_pin->proc_entry = entry;
564
565 return 0;
566}
567
568static void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
569{
570 if (!per_pin->codec->bus->shutdown && per_pin->proc_entry) {
571 snd_device_free(per_pin->codec->bus->card, per_pin->proc_entry);
572 per_pin->proc_entry = NULL;
573 }
574}
575#else
Takashi Iwaib55447a2013-10-21 16:31:45 +0200576static inline int eld_proc_new(struct hdmi_spec_per_pin *per_pin,
577 int index)
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200578{
579 return 0;
580}
Takashi Iwaib55447a2013-10-21 16:31:45 +0200581static inline void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200582{
583}
584#endif
Wu Fengguang079d88c2010-03-08 10:44:23 +0800585
586/*
587 * Channel mapping routines
588 */
589
590/*
591 * Compute derived values in channel_allocations[].
592 */
593static void init_channel_allocations(void)
594{
595 int i, j;
596 struct cea_channel_speaker_allocation *p;
597
598 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
599 p = channel_allocations + i;
600 p->channels = 0;
601 p->spk_mask = 0;
602 for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
603 if (p->speakers[j]) {
604 p->channels++;
605 p->spk_mask |= p->speakers[j];
606 }
607 }
608}
609
Wang Xingchao72357c72012-09-06 10:02:36 +0800610static int get_channel_allocation_order(int ca)
611{
612 int i;
613
614 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
615 if (channel_allocations[i].ca_index == ca)
616 break;
617 }
618 return i;
619}
620
Wu Fengguang079d88c2010-03-08 10:44:23 +0800621/*
622 * The transformation takes two steps:
623 *
624 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
625 * spk_mask => (channel_allocations[]) => ai->CA
626 *
627 * TODO: it could select the wrong CA from multiple candidates.
628*/
Stephen Warren384a48d2011-06-01 11:14:21 -0600629static int hdmi_channel_allocation(struct hdmi_eld *eld, int channels)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800630{
Wu Fengguang079d88c2010-03-08 10:44:23 +0800631 int i;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800632 int ca = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800633 int spk_mask = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800634 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
635
636 /*
637 * CA defaults to 0 for basic stereo audio
638 */
639 if (channels <= 2)
640 return 0;
641
Wu Fengguang079d88c2010-03-08 10:44:23 +0800642 /*
643 * expand ELD's speaker allocation mask
644 *
645 * ELD tells the speaker mask in a compact(paired) form,
646 * expand ELD's notions to match the ones used by Audio InfoFrame.
647 */
648 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
David Henningsson1613d6b2013-02-19 16:11:24 +0100649 if (eld->info.spk_alloc & (1 << i))
Wu Fengguang079d88c2010-03-08 10:44:23 +0800650 spk_mask |= eld_speaker_allocation_bits[i];
651 }
652
653 /* search for the first working match in the CA table */
654 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
655 if (channels == channel_allocations[i].channels &&
656 (spk_mask & channel_allocations[i].spk_mask) ==
657 channel_allocations[i].spk_mask) {
Wu Fengguang53d7d692010-09-21 14:25:49 +0800658 ca = channel_allocations[i].ca_index;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800659 break;
660 }
661 }
662
Anssi Hannula18e39182013-09-01 14:36:47 +0300663 if (!ca) {
664 /* if there was no match, select the regular ALSA channel
665 * allocation with the matching number of channels */
666 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
667 if (channels == channel_allocations[i].channels) {
668 ca = channel_allocations[i].ca_index;
669 break;
670 }
671 }
672 }
673
David Henningsson1613d6b2013-02-19 16:11:24 +0100674 snd_print_channel_allocation(eld->info.spk_alloc, buf, sizeof(buf));
Wu Fengguang2abbf432010-03-08 10:45:38 +0800675 snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n",
Wu Fengguang53d7d692010-09-21 14:25:49 +0800676 ca, channels, buf);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800677
Wu Fengguang53d7d692010-09-21 14:25:49 +0800678 return ca;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800679}
680
681static void hdmi_debug_channel_mapping(struct hda_codec *codec,
682 hda_nid_t pin_nid)
683{
684#ifdef CONFIG_SND_DEBUG_VERBOSE
Anssi Hannula307229d2013-10-24 21:10:34 +0300685 struct hdmi_spec *spec = codec->spec;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800686 int i;
Anssi Hannula307229d2013-10-24 21:10:34 +0300687 int channel;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800688
689 for (i = 0; i < 8; i++) {
Anssi Hannula307229d2013-10-24 21:10:34 +0300690 channel = spec->ops.pin_get_slot_channel(codec, pin_nid, i);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800691 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n",
Anssi Hannula307229d2013-10-24 21:10:34 +0300692 channel, i);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800693 }
694#endif
695}
696
Takashi Iwaid45e6882012-07-31 11:36:00 +0200697static void hdmi_std_setup_channel_mapping(struct hda_codec *codec,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800698 hda_nid_t pin_nid,
Wang Xingchao433968d2012-09-06 10:02:37 +0800699 bool non_pcm,
Wu Fengguang53d7d692010-09-21 14:25:49 +0800700 int ca)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800701{
Anssi Hannula307229d2013-10-24 21:10:34 +0300702 struct hdmi_spec *spec = codec->spec;
Anssi Hannula90f28002013-10-05 02:25:39 +0300703 struct cea_channel_speaker_allocation *ch_alloc;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800704 int i;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800705 int err;
Wang Xingchao72357c72012-09-06 10:02:36 +0800706 int order;
Wang Xingchao433968d2012-09-06 10:02:37 +0800707 int non_pcm_mapping[8];
Wu Fengguang079d88c2010-03-08 10:44:23 +0800708
Wang Xingchao72357c72012-09-06 10:02:36 +0800709 order = get_channel_allocation_order(ca);
Anssi Hannula90f28002013-10-05 02:25:39 +0300710 ch_alloc = &channel_allocations[order];
Wang Xingchao433968d2012-09-06 10:02:37 +0800711
Wu Fengguang079d88c2010-03-08 10:44:23 +0800712 if (hdmi_channel_mapping[ca][1] == 0) {
Anssi Hannula90f28002013-10-05 02:25:39 +0300713 int hdmi_slot = 0;
714 /* fill actual channel mappings in ALSA channel (i) order */
715 for (i = 0; i < ch_alloc->channels; i++) {
716 while (!ch_alloc->speakers[7 - hdmi_slot] && !WARN_ON(hdmi_slot >= 8))
717 hdmi_slot++; /* skip zero slots */
718
719 hdmi_channel_mapping[ca][i] = (i << 4) | hdmi_slot++;
720 }
721 /* fill the rest of the slots with ALSA channel 0xf */
722 for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++)
723 if (!ch_alloc->speakers[7 - hdmi_slot])
724 hdmi_channel_mapping[ca][i++] = (0xf << 4) | hdmi_slot;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800725 }
726
Wang Xingchao433968d2012-09-06 10:02:37 +0800727 if (non_pcm) {
Anssi Hannula90f28002013-10-05 02:25:39 +0300728 for (i = 0; i < ch_alloc->channels; i++)
Anssi Hannula11f7c522013-10-05 02:25:41 +0300729 non_pcm_mapping[i] = (i << 4) | i;
Wang Xingchao433968d2012-09-06 10:02:37 +0800730 for (; i < 8; i++)
Anssi Hannula11f7c522013-10-05 02:25:41 +0300731 non_pcm_mapping[i] = (0xf << 4) | i;
Wang Xingchao433968d2012-09-06 10:02:37 +0800732 }
733
Wu Fengguang079d88c2010-03-08 10:44:23 +0800734 for (i = 0; i < 8; i++) {
Anssi Hannula307229d2013-10-24 21:10:34 +0300735 int slotsetup = non_pcm ? non_pcm_mapping[i] : hdmi_channel_mapping[ca][i];
736 int hdmi_slot = slotsetup & 0x0f;
737 int channel = (slotsetup & 0xf0) >> 4;
738 err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot, channel);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800739 if (err) {
Wu Fengguang2abbf432010-03-08 10:45:38 +0800740 snd_printdd(KERN_NOTICE
741 "HDMI: channel mapping failed\n");
Wu Fengguang079d88c2010-03-08 10:44:23 +0800742 break;
743 }
744 }
Wu Fengguang079d88c2010-03-08 10:44:23 +0800745}
746
Takashi Iwaid45e6882012-07-31 11:36:00 +0200747struct channel_map_table {
748 unsigned char map; /* ALSA API channel map position */
Takashi Iwaid45e6882012-07-31 11:36:00 +0200749 int spk_mask; /* speaker position bit mask */
750};
751
752static struct channel_map_table map_tables[] = {
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300753 { SNDRV_CHMAP_FL, FL },
754 { SNDRV_CHMAP_FR, FR },
755 { SNDRV_CHMAP_RL, RL },
756 { SNDRV_CHMAP_RR, RR },
757 { SNDRV_CHMAP_LFE, LFE },
758 { SNDRV_CHMAP_FC, FC },
759 { SNDRV_CHMAP_RLC, RLC },
760 { SNDRV_CHMAP_RRC, RRC },
761 { SNDRV_CHMAP_RC, RC },
762 { SNDRV_CHMAP_FLC, FLC },
763 { SNDRV_CHMAP_FRC, FRC },
764 { SNDRV_CHMAP_FLH, FLH },
765 { SNDRV_CHMAP_FRH, FRH },
766 { SNDRV_CHMAP_FLW, FLW },
767 { SNDRV_CHMAP_FRW, FRW },
768 { SNDRV_CHMAP_TC, TC },
769 { SNDRV_CHMAP_FCH, FCH },
Takashi Iwaid45e6882012-07-31 11:36:00 +0200770 {} /* terminator */
771};
772
773/* from ALSA API channel position to speaker bit mask */
774static int to_spk_mask(unsigned char c)
775{
776 struct channel_map_table *t = map_tables;
777 for (; t->map; t++) {
778 if (t->map == c)
779 return t->spk_mask;
780 }
781 return 0;
782}
783
784/* from ALSA API channel position to CEA slot */
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300785static int to_cea_slot(int ordered_ca, unsigned char pos)
Takashi Iwaid45e6882012-07-31 11:36:00 +0200786{
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300787 int mask = to_spk_mask(pos);
788 int i;
Takashi Iwaid45e6882012-07-31 11:36:00 +0200789
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300790 if (mask) {
791 for (i = 0; i < 8; i++) {
792 if (channel_allocations[ordered_ca].speakers[7 - i] == mask)
793 return i;
794 }
Takashi Iwaid45e6882012-07-31 11:36:00 +0200795 }
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300796
797 return -1;
Takashi Iwaid45e6882012-07-31 11:36:00 +0200798}
799
800/* from speaker bit mask to ALSA API channel position */
801static int spk_to_chmap(int spk)
802{
803 struct channel_map_table *t = map_tables;
804 for (; t->map; t++) {
805 if (t->spk_mask == spk)
806 return t->map;
807 }
808 return 0;
809}
810
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300811/* from CEA slot to ALSA API channel position */
812static int from_cea_slot(int ordered_ca, unsigned char slot)
813{
814 int mask = channel_allocations[ordered_ca].speakers[7 - slot];
815
816 return spk_to_chmap(mask);
817}
818
Takashi Iwaid45e6882012-07-31 11:36:00 +0200819/* get the CA index corresponding to the given ALSA API channel map */
820static int hdmi_manual_channel_allocation(int chs, unsigned char *map)
821{
822 int i, spks = 0, spk_mask = 0;
823
824 for (i = 0; i < chs; i++) {
825 int mask = to_spk_mask(map[i]);
826 if (mask) {
827 spk_mask |= mask;
828 spks++;
829 }
830 }
831
832 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
833 if ((chs == channel_allocations[i].channels ||
834 spks == channel_allocations[i].channels) &&
835 (spk_mask & channel_allocations[i].spk_mask) ==
836 channel_allocations[i].spk_mask)
837 return channel_allocations[i].ca_index;
838 }
839 return -1;
840}
841
842/* set up the channel slots for the given ALSA API channel map */
843static int hdmi_manual_setup_channel_mapping(struct hda_codec *codec,
844 hda_nid_t pin_nid,
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300845 int chs, unsigned char *map,
846 int ca)
Takashi Iwaid45e6882012-07-31 11:36:00 +0200847{
Anssi Hannula307229d2013-10-24 21:10:34 +0300848 struct hdmi_spec *spec = codec->spec;
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300849 int ordered_ca = get_channel_allocation_order(ca);
Anssi Hannula11f7c522013-10-05 02:25:41 +0300850 int alsa_pos, hdmi_slot;
851 int assignments[8] = {[0 ... 7] = 0xf};
852
853 for (alsa_pos = 0; alsa_pos < chs; alsa_pos++) {
854
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300855 hdmi_slot = to_cea_slot(ordered_ca, map[alsa_pos]);
Anssi Hannula11f7c522013-10-05 02:25:41 +0300856
857 if (hdmi_slot < 0)
858 continue; /* unassigned channel */
859
860 assignments[hdmi_slot] = alsa_pos;
861 }
862
863 for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++) {
Anssi Hannula307229d2013-10-24 21:10:34 +0300864 int err;
Anssi Hannula11f7c522013-10-05 02:25:41 +0300865
Anssi Hannula307229d2013-10-24 21:10:34 +0300866 err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot,
867 assignments[hdmi_slot]);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200868 if (err)
869 return -EINVAL;
870 }
871 return 0;
872}
873
874/* store ALSA API channel map from the current default map */
875static void hdmi_setup_fake_chmap(unsigned char *map, int ca)
876{
877 int i;
Anssi Hannula56cac412013-10-05 02:25:38 +0300878 int ordered_ca = get_channel_allocation_order(ca);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200879 for (i = 0; i < 8; i++) {
Anssi Hannula56cac412013-10-05 02:25:38 +0300880 if (i < channel_allocations[ordered_ca].channels)
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300881 map[i] = from_cea_slot(ordered_ca, hdmi_channel_mapping[ca][i] & 0x0f);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200882 else
883 map[i] = 0;
884 }
885}
886
887static void hdmi_setup_channel_mapping(struct hda_codec *codec,
888 hda_nid_t pin_nid, bool non_pcm, int ca,
Anssi Hannula20608732013-02-03 17:55:45 +0200889 int channels, unsigned char *map,
890 bool chmap_set)
Takashi Iwaid45e6882012-07-31 11:36:00 +0200891{
Anssi Hannula20608732013-02-03 17:55:45 +0200892 if (!non_pcm && chmap_set) {
Takashi Iwaid45e6882012-07-31 11:36:00 +0200893 hdmi_manual_setup_channel_mapping(codec, pin_nid,
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300894 channels, map, ca);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200895 } else {
896 hdmi_std_setup_channel_mapping(codec, pin_nid, non_pcm, ca);
897 hdmi_setup_fake_chmap(map, ca);
898 }
Anssi Hannula980b2492013-10-05 02:25:44 +0300899
900 hdmi_debug_channel_mapping(codec, pin_nid);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200901}
Wu Fengguang079d88c2010-03-08 10:44:23 +0800902
Anssi Hannula307229d2013-10-24 21:10:34 +0300903static int hdmi_pin_set_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
904 int asp_slot, int channel)
905{
906 return snd_hda_codec_write(codec, pin_nid, 0,
907 AC_VERB_SET_HDMI_CHAN_SLOT,
908 (channel << 4) | asp_slot);
909}
910
911static int hdmi_pin_get_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
912 int asp_slot)
913{
914 return (snd_hda_codec_read(codec, pin_nid, 0,
915 AC_VERB_GET_HDMI_CHAN_SLOT,
916 asp_slot) & 0xf0) >> 4;
917}
918
Wu Fengguang079d88c2010-03-08 10:44:23 +0800919/*
920 * Audio InfoFrame routines
921 */
922
923/*
924 * Enable Audio InfoFrame Transmission
925 */
926static void hdmi_start_infoframe_trans(struct hda_codec *codec,
927 hda_nid_t pin_nid)
928{
929 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
930 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
931 AC_DIPXMIT_BEST);
932}
933
934/*
935 * Disable Audio InfoFrame Transmission
936 */
937static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
938 hda_nid_t pin_nid)
939{
940 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
941 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
942 AC_DIPXMIT_DISABLE);
943}
944
945static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
946{
947#ifdef CONFIG_SND_DEBUG_VERBOSE
948 int i;
949 int size;
950
951 size = snd_hdmi_get_eld_size(codec, pin_nid);
952 printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size);
953
954 for (i = 0; i < 8; i++) {
955 size = snd_hda_codec_read(codec, pin_nid, 0,
956 AC_VERB_GET_HDMI_DIP_SIZE, i);
957 printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size);
958 }
959#endif
960}
961
962static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
963{
964#ifdef BE_PARANOID
965 int i, j;
966 int size;
967 int pi, bi;
968 for (i = 0; i < 8; i++) {
969 size = snd_hda_codec_read(codec, pin_nid, 0,
970 AC_VERB_GET_HDMI_DIP_SIZE, i);
971 if (size == 0)
972 continue;
973
974 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
975 for (j = 1; j < 1000; j++) {
976 hdmi_write_dip_byte(codec, pin_nid, 0x0);
977 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
978 if (pi != i)
979 snd_printd(KERN_INFO "dip index %d: %d != %d\n",
980 bi, pi, i);
981 if (bi == 0) /* byte index wrapped around */
982 break;
983 }
984 snd_printd(KERN_INFO
985 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
986 i, size, j);
987 }
988#endif
989}
990
Wu Fengguang53d7d692010-09-21 14:25:49 +0800991static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800992{
Wu Fengguang53d7d692010-09-21 14:25:49 +0800993 u8 *bytes = (u8 *)hdmi_ai;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800994 u8 sum = 0;
995 int i;
996
Wu Fengguang53d7d692010-09-21 14:25:49 +0800997 hdmi_ai->checksum = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800998
Wu Fengguang53d7d692010-09-21 14:25:49 +0800999 for (i = 0; i < sizeof(*hdmi_ai); i++)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001000 sum += bytes[i];
1001
Wu Fengguang53d7d692010-09-21 14:25:49 +08001002 hdmi_ai->checksum = -sum;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001003}
1004
1005static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
1006 hda_nid_t pin_nid,
Wu Fengguang53d7d692010-09-21 14:25:49 +08001007 u8 *dip, int size)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001008{
Wu Fengguang079d88c2010-03-08 10:44:23 +08001009 int i;
1010
1011 hdmi_debug_dip_size(codec, pin_nid);
1012 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
1013
Wu Fengguang079d88c2010-03-08 10:44:23 +08001014 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
Wu Fengguang53d7d692010-09-21 14:25:49 +08001015 for (i = 0; i < size; i++)
1016 hdmi_write_dip_byte(codec, pin_nid, dip[i]);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001017}
1018
1019static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
Wu Fengguang53d7d692010-09-21 14:25:49 +08001020 u8 *dip, int size)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001021{
Wu Fengguang079d88c2010-03-08 10:44:23 +08001022 u8 val;
1023 int i;
1024
1025 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
1026 != AC_DIPXMIT_BEST)
1027 return false;
1028
1029 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
Wu Fengguang53d7d692010-09-21 14:25:49 +08001030 for (i = 0; i < size; i++) {
Wu Fengguang079d88c2010-03-08 10:44:23 +08001031 val = snd_hda_codec_read(codec, pin_nid, 0,
1032 AC_VERB_GET_HDMI_DIP_DATA, 0);
Wu Fengguang53d7d692010-09-21 14:25:49 +08001033 if (val != dip[i])
Wu Fengguang079d88c2010-03-08 10:44:23 +08001034 return false;
1035 }
1036
1037 return true;
1038}
1039
Anssi Hannula307229d2013-10-24 21:10:34 +03001040static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
1041 hda_nid_t pin_nid,
1042 int ca, int active_channels,
1043 int conn_type)
1044{
1045 union audio_infoframe ai;
1046
1047 if (conn_type == 0) { /* HDMI */
1048 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
1049
1050 hdmi_ai->type = 0x84;
1051 hdmi_ai->ver = 0x01;
1052 hdmi_ai->len = 0x0a;
1053 hdmi_ai->CC02_CT47 = active_channels - 1;
1054 hdmi_ai->CA = ca;
1055 hdmi_checksum_audio_infoframe(hdmi_ai);
1056 } else if (conn_type == 1) { /* DisplayPort */
1057 struct dp_audio_infoframe *dp_ai = &ai.dp;
1058
1059 dp_ai->type = 0x84;
1060 dp_ai->len = 0x1b;
1061 dp_ai->ver = 0x11 << 2;
1062 dp_ai->CC02_CT47 = active_channels - 1;
1063 dp_ai->CA = ca;
1064 } else {
1065 snd_printd("HDMI: unknown connection type at pin %d\n",
1066 pin_nid);
1067 return;
1068 }
1069
1070 /*
1071 * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
1072 * sizeof(*dp_ai) to avoid partial match/update problems when
1073 * the user switches between HDMI/DP monitors.
1074 */
1075 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
1076 sizeof(ai))) {
1077 snd_printdd("hdmi_pin_setup_infoframe: "
1078 "pin=%d channels=%d ca=0x%02x\n",
1079 pin_nid,
1080 active_channels, ca);
1081 hdmi_stop_infoframe_trans(codec, pin_nid);
1082 hdmi_fill_audio_infoframe(codec, pin_nid,
1083 ai.bytes, sizeof(ai));
1084 hdmi_start_infoframe_trans(codec, pin_nid);
1085 }
1086}
1087
Takashi Iwaib0540872013-09-02 12:33:02 +02001088static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
1089 struct hdmi_spec_per_pin *per_pin,
1090 bool non_pcm)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001091{
Anssi Hannula307229d2013-10-24 21:10:34 +03001092 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001093 hda_nid_t pin_nid = per_pin->pin_nid;
Takashi Iwaib0540872013-09-02 12:33:02 +02001094 int channels = per_pin->channels;
Anssi Hannula1df5a062013-10-05 02:25:40 +03001095 int active_channels;
Stephen Warren384a48d2011-06-01 11:14:21 -06001096 struct hdmi_eld *eld;
Anssi Hannula1df5a062013-10-05 02:25:40 +03001097 int ca, ordered_ca;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001098
Takashi Iwaib0540872013-09-02 12:33:02 +02001099 if (!channels)
1100 return;
1101
Mengdong Lin58f7d282013-09-04 16:37:12 -04001102 if (is_haswell(codec))
1103 snd_hda_codec_write(codec, pin_nid, 0,
1104 AC_VERB_SET_AMP_GAIN_MUTE,
1105 AMP_OUT_UNMUTE);
1106
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001107 eld = &per_pin->sink_eld;
Stephen Warren384a48d2011-06-01 11:14:21 -06001108 if (!eld->monitor_present)
1109 return;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001110
Takashi Iwaid45e6882012-07-31 11:36:00 +02001111 if (!non_pcm && per_pin->chmap_set)
1112 ca = hdmi_manual_channel_allocation(channels, per_pin->chmap);
1113 else
1114 ca = hdmi_channel_allocation(eld, channels);
1115 if (ca < 0)
1116 ca = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001117
Anssi Hannula1df5a062013-10-05 02:25:40 +03001118 ordered_ca = get_channel_allocation_order(ca);
1119 active_channels = channel_allocations[ordered_ca].channels;
1120
1121 hdmi_set_channel_count(codec, per_pin->cvt_nid, active_channels);
1122
Stephen Warren384a48d2011-06-01 11:14:21 -06001123 /*
Anssi Hannula39edac72013-10-07 19:24:52 +03001124 * always configure channel mapping, it may have been changed by the
1125 * user in the meantime
1126 */
1127 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
1128 channels, per_pin->chmap,
1129 per_pin->chmap_set);
1130
Anssi Hannula307229d2013-10-24 21:10:34 +03001131 spec->ops.pin_setup_infoframe(codec, pin_nid, ca, active_channels,
1132 eld->info.conn_type);
Wang Xingchao433968d2012-09-06 10:02:37 +08001133
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001134 per_pin->non_pcm = non_pcm;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001135}
1136
Wu Fengguang079d88c2010-03-08 10:44:23 +08001137/*
1138 * Unsolicited events
1139 */
1140
Wu Fengguangc6e84532011-11-18 16:59:32 -06001141static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
Takashi Iwai38faddb2010-07-28 14:21:55 +02001142
Wu Fengguang079d88c2010-03-08 10:44:23 +08001143static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
1144{
1145 struct hdmi_spec *spec = codec->spec;
Takashi Iwai3a938972011-10-28 01:16:55 +02001146 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
1147 int pin_nid;
Stephen Warren384a48d2011-06-01 11:14:21 -06001148 int pin_idx;
Takashi Iwai3a938972011-10-28 01:16:55 +02001149 struct hda_jack_tbl *jack;
Mengdong Lin2e59e5a2013-08-26 21:35:49 -04001150 int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
Takashi Iwai3a938972011-10-28 01:16:55 +02001151
1152 jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
1153 if (!jack)
1154 return;
1155 pin_nid = jack->nid;
1156 jack->jack_dirty = 1;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001157
Fengguang Wufae3d882012-04-10 17:00:35 +08001158 _snd_printd(SND_PR_VERBOSE,
Mengdong Lin2e59e5a2013-08-26 21:35:49 -04001159 "HDMI hot plug event: Codec=%d Pin=%d Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n",
1160 codec->addr, pin_nid, dev_entry, !!(res & AC_UNSOL_RES_IA),
Fengguang Wufae3d882012-04-10 17:00:35 +08001161 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
Wu Fengguang079d88c2010-03-08 10:44:23 +08001162
Stephen Warren384a48d2011-06-01 11:14:21 -06001163 pin_idx = pin_nid_to_pin_index(spec, pin_nid);
1164 if (pin_idx < 0)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001165 return;
1166
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001167 hdmi_present_sense(get_pin(spec, pin_idx), 1);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001168 snd_hda_jack_report_sync(codec);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001169}
1170
1171static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
1172{
1173 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
1174 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
1175 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
1176 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
1177
1178 printk(KERN_INFO
Takashi Iwaie9ea8e82012-06-21 11:41:05 +02001179 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
Stephen Warren384a48d2011-06-01 11:14:21 -06001180 codec->addr,
Wu Fengguang079d88c2010-03-08 10:44:23 +08001181 tag,
1182 subtag,
1183 cp_state,
1184 cp_ready);
1185
1186 /* TODO */
1187 if (cp_state)
1188 ;
1189 if (cp_ready)
1190 ;
1191}
1192
1193
1194static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
1195{
Wu Fengguang079d88c2010-03-08 10:44:23 +08001196 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
1197 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
1198
Takashi Iwai3a938972011-10-28 01:16:55 +02001199 if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) {
Wu Fengguang079d88c2010-03-08 10:44:23 +08001200 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag);
1201 return;
1202 }
1203
1204 if (subtag == 0)
1205 hdmi_intrinsic_event(codec, res);
1206 else
1207 hdmi_non_intrinsic_event(codec, res);
1208}
1209
Mengdong Lin58f7d282013-09-04 16:37:12 -04001210static void haswell_verify_D0(struct hda_codec *codec,
Wang Xingchao53b434f2013-06-18 10:41:53 +08001211 hda_nid_t cvt_nid, hda_nid_t nid)
David Henningsson83f26ad2013-04-10 12:26:07 +02001212{
Mengdong Lin58f7d282013-09-04 16:37:12 -04001213 int pwr;
David Henningsson83f26ad2013-04-10 12:26:07 +02001214
Wang Xingchao53b434f2013-06-18 10:41:53 +08001215 /* For Haswell, the converter 1/2 may keep in D3 state after bootup,
1216 * thus pins could only choose converter 0 for use. Make sure the
1217 * converters are in correct power state */
Takashi Iwaifd678ca2013-06-18 16:28:36 +02001218 if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0))
Wang Xingchao53b434f2013-06-18 10:41:53 +08001219 snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1220
Takashi Iwaifd678ca2013-06-18 16:28:36 +02001221 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) {
David Henningsson83f26ad2013-04-10 12:26:07 +02001222 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
1223 AC_PWRST_D0);
1224 msleep(40);
1225 pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
1226 pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
1227 snd_printd("Haswell HDMI audio: Power for pin 0x%x is now D%d\n", nid, pwr);
1228 }
David Henningsson83f26ad2013-04-10 12:26:07 +02001229}
1230
Wu Fengguang079d88c2010-03-08 10:44:23 +08001231/*
1232 * Callbacks
1233 */
1234
Takashi Iwai92f10b32010-08-03 14:21:00 +02001235/* HBR should be Non-PCM, 8 channels */
1236#define is_hbr_format(format) \
1237 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
1238
Anssi Hannula307229d2013-10-24 21:10:34 +03001239static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
1240 bool hbr)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001241{
Anssi Hannula307229d2013-10-24 21:10:34 +03001242 int pinctl, new_pinctl;
David Henningsson83f26ad2013-04-10 12:26:07 +02001243
Stephen Warren384a48d2011-06-01 11:14:21 -06001244 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
1245 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001246 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1247
1248 new_pinctl = pinctl & ~AC_PINCTL_EPT;
Anssi Hannula307229d2013-10-24 21:10:34 +03001249 if (hbr)
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001250 new_pinctl |= AC_PINCTL_EPT_HBR;
1251 else
1252 new_pinctl |= AC_PINCTL_EPT_NATIVE;
1253
Anssi Hannula307229d2013-10-24 21:10:34 +03001254 snd_printdd("hdmi_pin_hbr_setup: "
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001255 "NID=0x%x, %spinctl=0x%x\n",
Stephen Warren384a48d2011-06-01 11:14:21 -06001256 pin_nid,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001257 pinctl == new_pinctl ? "" : "new-",
1258 new_pinctl);
1259
1260 if (pinctl != new_pinctl)
Stephen Warren384a48d2011-06-01 11:14:21 -06001261 snd_hda_codec_write(codec, pin_nid, 0,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001262 AC_VERB_SET_PIN_WIDGET_CONTROL,
1263 new_pinctl);
Anssi Hannula307229d2013-10-24 21:10:34 +03001264 } else if (hbr)
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001265 return -EINVAL;
Anssi Hannula307229d2013-10-24 21:10:34 +03001266
1267 return 0;
1268}
1269
1270static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
1271 hda_nid_t pin_nid, u32 stream_tag, int format)
1272{
1273 struct hdmi_spec *spec = codec->spec;
1274 int err;
1275
1276 if (is_haswell(codec))
1277 haswell_verify_D0(codec, cvt_nid, pin_nid);
1278
1279 err = spec->ops.pin_hbr_setup(codec, pin_nid, is_hbr_format(format));
1280
1281 if (err) {
1282 snd_printdd("hdmi_setup_stream: HBR is not supported\n");
1283 return err;
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001284 }
Wu Fengguang079d88c2010-03-08 10:44:23 +08001285
Stephen Warren384a48d2011-06-01 11:14:21 -06001286 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001287 return 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001288}
1289
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001290static int hdmi_choose_cvt(struct hda_codec *codec,
1291 int pin_idx, int *cvt_id, int *mux_id)
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001292{
1293 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001294 struct hdmi_spec_per_pin *per_pin;
Stephen Warren384a48d2011-06-01 11:14:21 -06001295 struct hdmi_spec_per_cvt *per_cvt = NULL;
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001296 int cvt_idx, mux_idx = 0;
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001297
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001298 per_pin = get_pin(spec, pin_idx);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001299
Stephen Warren384a48d2011-06-01 11:14:21 -06001300 /* Dynamically assign converter to stream */
1301 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001302 per_cvt = get_cvt(spec, cvt_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001303
1304 /* Must not already be assigned */
1305 if (per_cvt->assigned)
1306 continue;
1307 /* Must be in pin's mux's list of converters */
1308 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
1309 if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid)
1310 break;
1311 /* Not in mux list */
1312 if (mux_idx == per_pin->num_mux_nids)
1313 continue;
1314 break;
1315 }
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001316
Stephen Warren384a48d2011-06-01 11:14:21 -06001317 /* No free converters */
1318 if (cvt_idx == spec->num_cvts)
1319 return -ENODEV;
1320
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001321 if (cvt_id)
1322 *cvt_id = cvt_idx;
1323 if (mux_id)
1324 *mux_id = mux_idx;
1325
1326 return 0;
1327}
1328
1329static void haswell_config_cvts(struct hda_codec *codec,
Mengdong Linf82d7d12013-09-21 20:34:45 -04001330 hda_nid_t pin_nid, int mux_idx)
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001331{
1332 struct hdmi_spec *spec = codec->spec;
Mengdong Linf82d7d12013-09-21 20:34:45 -04001333 hda_nid_t nid, end_nid;
1334 int cvt_idx, curr;
1335 struct hdmi_spec_per_cvt *per_cvt;
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001336
Mengdong Linf82d7d12013-09-21 20:34:45 -04001337 /* configure all pins, including "no physical connection" ones */
1338 end_nid = codec->start_nid + codec->num_nodes;
1339 for (nid = codec->start_nid; nid < end_nid; nid++) {
1340 unsigned int wid_caps = get_wcaps(codec, nid);
1341 unsigned int wid_type = get_wcaps_type(wid_caps);
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001342
Mengdong Linf82d7d12013-09-21 20:34:45 -04001343 if (wid_type != AC_WID_PIN)
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001344 continue;
1345
Mengdong Linf82d7d12013-09-21 20:34:45 -04001346 if (nid == pin_nid)
1347 continue;
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001348
Mengdong Linf82d7d12013-09-21 20:34:45 -04001349 curr = snd_hda_codec_read(codec, nid, 0,
1350 AC_VERB_GET_CONNECT_SEL, 0);
1351 if (curr != mux_idx)
1352 continue;
1353
1354 /* choose an unassigned converter. The conveters in the
1355 * connection list are in the same order as in the codec.
1356 */
1357 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
1358 per_cvt = get_cvt(spec, cvt_idx);
1359 if (!per_cvt->assigned) {
1360 snd_printdd("choose cvt %d for pin nid %d\n",
1361 cvt_idx, nid);
1362 snd_hda_codec_write_cache(codec, nid, 0,
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001363 AC_VERB_SET_CONNECT_SEL,
Mengdong Linf82d7d12013-09-21 20:34:45 -04001364 cvt_idx);
1365 break;
1366 }
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001367 }
1368 }
1369}
1370
1371/*
1372 * HDA PCM callbacks
1373 */
1374static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1375 struct hda_codec *codec,
1376 struct snd_pcm_substream *substream)
1377{
1378 struct hdmi_spec *spec = codec->spec;
1379 struct snd_pcm_runtime *runtime = substream->runtime;
1380 int pin_idx, cvt_idx, mux_idx = 0;
1381 struct hdmi_spec_per_pin *per_pin;
1382 struct hdmi_eld *eld;
1383 struct hdmi_spec_per_cvt *per_cvt = NULL;
1384 int err;
1385
1386 /* Validate hinfo */
1387 pin_idx = hinfo_to_pin_index(spec, hinfo);
1388 if (snd_BUG_ON(pin_idx < 0))
1389 return -EINVAL;
1390 per_pin = get_pin(spec, pin_idx);
1391 eld = &per_pin->sink_eld;
1392
1393 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, &mux_idx);
1394 if (err < 0)
1395 return err;
1396
1397 per_cvt = get_cvt(spec, cvt_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001398 /* Claim converter */
1399 per_cvt->assigned = 1;
Anssi Hannula1df5a062013-10-05 02:25:40 +03001400 per_pin->cvt_nid = per_cvt->cvt_nid;
Stephen Warren384a48d2011-06-01 11:14:21 -06001401 hinfo->nid = per_cvt->cvt_nid;
1402
Takashi Iwaibddee962013-06-18 16:14:22 +02001403 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
Stephen Warren384a48d2011-06-01 11:14:21 -06001404 AC_VERB_SET_CONNECT_SEL,
1405 mux_idx);
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001406
1407 /* configure unused pins to choose other converters */
Mengdong Linfb87fa32013-09-04 16:36:57 -04001408 if (is_haswell(codec))
Mengdong Linf82d7d12013-09-21 20:34:45 -04001409 haswell_config_cvts(codec, per_pin->pin_nid, mux_idx);
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001410
Stephen Warren384a48d2011-06-01 11:14:21 -06001411 snd_hda_spdif_ctls_assign(codec, pin_idx, per_cvt->cvt_nid);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001412
Stephen Warren2def8172011-06-01 11:14:20 -06001413 /* Initially set the converter's capabilities */
Stephen Warren384a48d2011-06-01 11:14:21 -06001414 hinfo->channels_min = per_cvt->channels_min;
1415 hinfo->channels_max = per_cvt->channels_max;
1416 hinfo->rates = per_cvt->rates;
1417 hinfo->formats = per_cvt->formats;
1418 hinfo->maxbps = per_cvt->maxbps;
Stephen Warren2def8172011-06-01 11:14:20 -06001419
Stephen Warren384a48d2011-06-01 11:14:21 -06001420 /* Restrict capabilities by ELD if this isn't disabled */
Stephen Warrenc3d52102011-06-01 11:14:16 -06001421 if (!static_hdmi_pcm && eld->eld_valid) {
David Henningsson1613d6b2013-02-19 16:11:24 +01001422 snd_hdmi_eld_update_pcm_info(&eld->info, hinfo);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001423 if (hinfo->channels_min > hinfo->channels_max ||
Takashi Iwai2ad779b2013-02-01 14:01:27 +01001424 !hinfo->rates || !hinfo->formats) {
1425 per_cvt->assigned = 0;
1426 hinfo->nid = 0;
1427 snd_hda_spdif_ctls_unassign(codec, pin_idx);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001428 return -ENODEV;
Takashi Iwai2ad779b2013-02-01 14:01:27 +01001429 }
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001430 }
Stephen Warren2def8172011-06-01 11:14:20 -06001431
1432 /* Store the updated parameters */
Takashi Iwai639cef02011-01-14 10:30:46 +01001433 runtime->hw.channels_min = hinfo->channels_min;
1434 runtime->hw.channels_max = hinfo->channels_max;
1435 runtime->hw.formats = hinfo->formats;
1436 runtime->hw.rates = hinfo->rates;
Takashi Iwai4fe2ca12011-01-14 10:33:26 +01001437
1438 snd_pcm_hw_constraint_step(substream->runtime, 0,
1439 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001440 return 0;
1441}
1442
1443/*
Wu Fengguang079d88c2010-03-08 10:44:23 +08001444 * HDA/HDMI auto parsing
1445 */
Stephen Warren384a48d2011-06-01 11:14:21 -06001446static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001447{
1448 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001449 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001450 hda_nid_t pin_nid = per_pin->pin_nid;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001451
1452 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
1453 snd_printk(KERN_WARNING
1454 "HDMI: pin %d wcaps %#x "
1455 "does not support connection list\n",
1456 pin_nid, get_wcaps(codec, pin_nid));
1457 return -EINVAL;
1458 }
1459
Stephen Warren384a48d2011-06-01 11:14:21 -06001460 per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,
1461 per_pin->mux_nids,
1462 HDA_MAX_CONNECTIONS);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001463
1464 return 0;
1465}
1466
Wu Fengguangc6e84532011-11-18 16:59:32 -06001467static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001468{
Wu Fengguang744626d2011-11-16 16:29:47 +08001469 struct hda_codec *codec = per_pin->codec;
David Henningsson4bd038f2013-02-19 16:11:25 +01001470 struct hdmi_spec *spec = codec->spec;
1471 struct hdmi_eld *eld = &spec->temp_eld;
1472 struct hdmi_eld *pin_eld = &per_pin->sink_eld;
Wu Fengguang744626d2011-11-16 16:29:47 +08001473 hda_nid_t pin_nid = per_pin->pin_nid;
Stephen Warren5d44f922011-05-24 17:11:17 -06001474 /*
1475 * Always execute a GetPinSense verb here, even when called from
1476 * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
1477 * response's PD bit is not the real PD value, but indicates that
1478 * the real PD value changed. An older version of the HD-audio
1479 * specification worked this way. Hence, we just ignore the data in
1480 * the unsolicited response to avoid custom WARs.
1481 */
Wu Fengguang079d88c2010-03-08 10:44:23 +08001482 int present = snd_hda_pin_sense(codec, pin_nid);
David Henningsson4bd038f2013-02-19 16:11:25 +01001483 bool update_eld = false;
1484 bool eld_changed = false;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001485
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001486 mutex_lock(&per_pin->lock);
David Henningsson4bd038f2013-02-19 16:11:25 +01001487 pin_eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
1488 if (pin_eld->monitor_present)
1489 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
1490 else
1491 eld->eld_valid = false;
Stephen Warren5d44f922011-05-24 17:11:17 -06001492
Fengguang Wufae3d882012-04-10 17:00:35 +08001493 _snd_printd(SND_PR_VERBOSE,
Stephen Warren384a48d2011-06-01 11:14:21 -06001494 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
Mengdong Lin10250912013-03-28 05:21:28 -04001495 codec->addr, pin_nid, pin_eld->monitor_present, eld->eld_valid);
Stephen Warren5d44f922011-05-24 17:11:17 -06001496
David Henningsson4bd038f2013-02-19 16:11:25 +01001497 if (eld->eld_valid) {
Anssi Hannula307229d2013-10-24 21:10:34 +03001498 if (spec->ops.pin_get_eld(codec, pin_nid, eld->eld_buffer,
David Henningsson1613d6b2013-02-19 16:11:24 +01001499 &eld->eld_size) < 0)
David Henningsson4bd038f2013-02-19 16:11:25 +01001500 eld->eld_valid = false;
David Henningsson1613d6b2013-02-19 16:11:24 +01001501 else {
1502 memset(&eld->info, 0, sizeof(struct parsed_hdmi_eld));
1503 if (snd_hdmi_parse_eld(&eld->info, eld->eld_buffer,
1504 eld->eld_size) < 0)
David Henningsson4bd038f2013-02-19 16:11:25 +01001505 eld->eld_valid = false;
David Henningsson1613d6b2013-02-19 16:11:24 +01001506 }
1507
David Henningsson4bd038f2013-02-19 16:11:25 +01001508 if (eld->eld_valid) {
David Henningsson1613d6b2013-02-19 16:11:24 +01001509 snd_hdmi_show_eld(&eld->info);
David Henningsson4bd038f2013-02-19 16:11:25 +01001510 update_eld = true;
David Henningsson1613d6b2013-02-19 16:11:24 +01001511 }
Wu Fengguangc6e84532011-11-18 16:59:32 -06001512 else if (repoll) {
Wu Fengguang744626d2011-11-16 16:29:47 +08001513 queue_delayed_work(codec->bus->workq,
1514 &per_pin->work,
1515 msecs_to_jiffies(300));
Takashi Iwaicbbaa602013-10-17 18:03:24 +02001516 goto unlock;
Wu Fengguang744626d2011-11-16 16:29:47 +08001517 }
1518 }
David Henningsson4bd038f2013-02-19 16:11:25 +01001519
David Henningsson92c69e72013-02-19 16:11:26 +01001520 if (pin_eld->eld_valid && !eld->eld_valid) {
David Henningsson4bd038f2013-02-19 16:11:25 +01001521 update_eld = true;
David Henningsson92c69e72013-02-19 16:11:26 +01001522 eld_changed = true;
1523 }
David Henningsson4bd038f2013-02-19 16:11:25 +01001524 if (update_eld) {
Takashi Iwaib0540872013-09-02 12:33:02 +02001525 bool old_eld_valid = pin_eld->eld_valid;
David Henningsson4bd038f2013-02-19 16:11:25 +01001526 pin_eld->eld_valid = eld->eld_valid;
David Henningsson92c69e72013-02-19 16:11:26 +01001527 eld_changed = pin_eld->eld_size != eld->eld_size ||
1528 memcmp(pin_eld->eld_buffer, eld->eld_buffer,
David Henningsson4bd038f2013-02-19 16:11:25 +01001529 eld->eld_size) != 0;
1530 if (eld_changed)
1531 memcpy(pin_eld->eld_buffer, eld->eld_buffer,
1532 eld->eld_size);
1533 pin_eld->eld_size = eld->eld_size;
1534 pin_eld->info = eld->info;
Takashi Iwaib0540872013-09-02 12:33:02 +02001535
1536 /* Haswell-specific workaround: re-setup when the transcoder is
1537 * changed during the stream playback
1538 */
Mengdong Linfb87fa32013-09-04 16:36:57 -04001539 if (is_haswell(codec) &&
Mengdong Lin58f7d282013-09-04 16:37:12 -04001540 eld->eld_valid && !old_eld_valid && per_pin->setup)
Takashi Iwaib0540872013-09-02 12:33:02 +02001541 hdmi_setup_audio_infoframe(codec, per_pin,
1542 per_pin->non_pcm);
David Henningsson4bd038f2013-02-19 16:11:25 +01001543 }
David Henningsson92c69e72013-02-19 16:11:26 +01001544
1545 if (eld_changed)
1546 snd_ctl_notify(codec->bus->card,
1547 SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
1548 &per_pin->eld_ctl->id);
Takashi Iwaicbbaa602013-10-17 18:03:24 +02001549 unlock:
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001550 mutex_unlock(&per_pin->lock);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001551}
1552
Wu Fengguang744626d2011-11-16 16:29:47 +08001553static void hdmi_repoll_eld(struct work_struct *work)
1554{
1555 struct hdmi_spec_per_pin *per_pin =
1556 container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
1557
Wu Fengguangc6e84532011-11-18 16:59:32 -06001558 if (per_pin->repoll_count++ > 6)
1559 per_pin->repoll_count = 0;
1560
1561 hdmi_present_sense(per_pin, per_pin->repoll_count);
Wu Fengguang744626d2011-11-16 16:29:47 +08001562}
1563
Takashi Iwaic88d4e82013-02-08 17:10:04 -05001564static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
1565 hda_nid_t nid);
1566
Wu Fengguang079d88c2010-03-08 10:44:23 +08001567static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1568{
1569 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001570 unsigned int caps, config;
1571 int pin_idx;
1572 struct hdmi_spec_per_pin *per_pin;
David Henningsson07acecc2011-05-19 11:46:03 +02001573 int err;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001574
Takashi Iwaiefc2f8de2012-11-21 14:27:37 +01001575 caps = snd_hda_query_pin_caps(codec, pin_nid);
Stephen Warren384a48d2011-06-01 11:14:21 -06001576 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
1577 return 0;
1578
Takashi Iwaiefc2f8de2012-11-21 14:27:37 +01001579 config = snd_hda_codec_get_pincfg(codec, pin_nid);
Stephen Warren384a48d2011-06-01 11:14:21 -06001580 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
1581 return 0;
1582
Mengdong Linfb87fa32013-09-04 16:36:57 -04001583 if (is_haswell(codec))
Takashi Iwaic88d4e82013-02-08 17:10:04 -05001584 intel_haswell_fixup_connect_list(codec, pin_nid);
1585
Stephen Warren384a48d2011-06-01 11:14:21 -06001586 pin_idx = spec->num_pins;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001587 per_pin = snd_array_new(&spec->pins);
1588 if (!per_pin)
1589 return -ENOMEM;
Stephen Warren384a48d2011-06-01 11:14:21 -06001590
1591 per_pin->pin_nid = pin_nid;
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001592 per_pin->non_pcm = false;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001593
Stephen Warren384a48d2011-06-01 11:14:21 -06001594 err = hdmi_read_pin_conn(codec, pin_idx);
1595 if (err < 0)
1596 return err;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001597
Wu Fengguang079d88c2010-03-08 10:44:23 +08001598 spec->num_pins++;
1599
Stephen Warren384a48d2011-06-01 11:14:21 -06001600 return 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001601}
1602
Stephen Warren384a48d2011-06-01 11:14:21 -06001603static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001604{
1605 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001606 struct hdmi_spec_per_cvt *per_cvt;
1607 unsigned int chans;
1608 int err;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001609
Stephen Warren384a48d2011-06-01 11:14:21 -06001610 chans = get_wcaps(codec, cvt_nid);
1611 chans = get_wcaps_channels(chans);
1612
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001613 per_cvt = snd_array_new(&spec->cvts);
1614 if (!per_cvt)
1615 return -ENOMEM;
Stephen Warren384a48d2011-06-01 11:14:21 -06001616
1617 per_cvt->cvt_nid = cvt_nid;
1618 per_cvt->channels_min = 2;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001619 if (chans <= 16) {
Stephen Warren384a48d2011-06-01 11:14:21 -06001620 per_cvt->channels_max = chans;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001621 if (chans > spec->channels_max)
1622 spec->channels_max = chans;
1623 }
Stephen Warren384a48d2011-06-01 11:14:21 -06001624
1625 err = snd_hda_query_supported_pcm(codec, cvt_nid,
1626 &per_cvt->rates,
1627 &per_cvt->formats,
1628 &per_cvt->maxbps);
1629 if (err < 0)
1630 return err;
1631
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001632 if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids))
1633 spec->cvt_nids[spec->num_cvts] = cvt_nid;
1634 spec->num_cvts++;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001635
1636 return 0;
1637}
1638
1639static int hdmi_parse_codec(struct hda_codec *codec)
1640{
1641 hda_nid_t nid;
1642 int i, nodes;
1643
1644 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
1645 if (!nid || nodes < 0) {
1646 snd_printk(KERN_WARNING "HDMI: failed to get afg sub nodes\n");
1647 return -EINVAL;
1648 }
1649
1650 for (i = 0; i < nodes; i++, nid++) {
1651 unsigned int caps;
1652 unsigned int type;
1653
Takashi Iwaiefc2f8de2012-11-21 14:27:37 +01001654 caps = get_wcaps(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001655 type = get_wcaps_type(caps);
1656
1657 if (!(caps & AC_WCAP_DIGITAL))
1658 continue;
1659
1660 switch (type) {
1661 case AC_WID_AUD_OUT:
Stephen Warren384a48d2011-06-01 11:14:21 -06001662 hdmi_add_cvt(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001663 break;
1664 case AC_WID_PIN:
Wu Fengguang3eaead52010-05-14 16:36:15 +08001665 hdmi_add_pin(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001666 break;
1667 }
1668 }
1669
David Henningssonc9adeef2012-11-07 09:22:33 +01001670#ifdef CONFIG_PM
1671 /* We're seeing some problems with unsolicited hot plug events on
1672 * PantherPoint after S3, if this is not enabled */
1673 if (codec->vendor_id == 0x80862806)
1674 codec->bus->power_keep_link_on = 1;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001675 /*
1676 * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event
1677 * can be lost and presence sense verb will become inaccurate if the
1678 * HDA link is powered off at hot plug or hw initialization time.
1679 */
David Henningssonc9adeef2012-11-07 09:22:33 +01001680 else if (!(snd_hda_param_read(codec, codec->afg, AC_PAR_POWER_STATE) &
Wu Fengguang079d88c2010-03-08 10:44:23 +08001681 AC_PWRST_EPSS))
1682 codec->bus->power_keep_link_on = 1;
1683#endif
1684
1685 return 0;
1686}
1687
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001688/*
1689 */
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001690static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1691{
1692 struct hda_spdif_out *spdif;
1693 bool non_pcm;
1694
1695 mutex_lock(&codec->spdif_mutex);
1696 spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
1697 non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO);
1698 mutex_unlock(&codec->spdif_mutex);
1699 return non_pcm;
1700}
1701
1702
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001703/*
1704 * HDMI callbacks
1705 */
1706
1707static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1708 struct hda_codec *codec,
1709 unsigned int stream_tag,
1710 unsigned int format,
1711 struct snd_pcm_substream *substream)
1712{
Stephen Warren384a48d2011-06-01 11:14:21 -06001713 hda_nid_t cvt_nid = hinfo->nid;
1714 struct hdmi_spec *spec = codec->spec;
1715 int pin_idx = hinfo_to_pin_index(spec, hinfo);
Takashi Iwaib0540872013-09-02 12:33:02 +02001716 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1717 hda_nid_t pin_nid = per_pin->pin_nid;
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001718 bool non_pcm;
1719
1720 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001721 mutex_lock(&per_pin->lock);
Takashi Iwaib0540872013-09-02 12:33:02 +02001722 per_pin->channels = substream->runtime->channels;
1723 per_pin->setup = true;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001724
Takashi Iwaib0540872013-09-02 12:33:02 +02001725 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001726 mutex_unlock(&per_pin->lock);
Stephen Warren384a48d2011-06-01 11:14:21 -06001727
Anssi Hannula307229d2013-10-24 21:10:34 +03001728 return spec->ops.setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001729}
1730
Takashi Iwai8dfaa572012-08-06 14:49:36 +02001731static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1732 struct hda_codec *codec,
1733 struct snd_pcm_substream *substream)
1734{
1735 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
1736 return 0;
1737}
1738
Takashi Iwaif2ad24f2012-07-26 18:08:14 +02001739static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1740 struct hda_codec *codec,
1741 struct snd_pcm_substream *substream)
Stephen Warren384a48d2011-06-01 11:14:21 -06001742{
1743 struct hdmi_spec *spec = codec->spec;
1744 int cvt_idx, pin_idx;
1745 struct hdmi_spec_per_cvt *per_cvt;
1746 struct hdmi_spec_per_pin *per_pin;
Stephen Warren384a48d2011-06-01 11:14:21 -06001747
Stephen Warren384a48d2011-06-01 11:14:21 -06001748 if (hinfo->nid) {
1749 cvt_idx = cvt_nid_to_cvt_index(spec, hinfo->nid);
1750 if (snd_BUG_ON(cvt_idx < 0))
1751 return -EINVAL;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001752 per_cvt = get_cvt(spec, cvt_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001753
1754 snd_BUG_ON(!per_cvt->assigned);
1755 per_cvt->assigned = 0;
1756 hinfo->nid = 0;
1757
1758 pin_idx = hinfo_to_pin_index(spec, hinfo);
1759 if (snd_BUG_ON(pin_idx < 0))
1760 return -EINVAL;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001761 per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001762
Stephen Warren384a48d2011-06-01 11:14:21 -06001763 snd_hda_spdif_ctls_unassign(codec, pin_idx);
Takashi Iwaicbbaa602013-10-17 18:03:24 +02001764
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001765 mutex_lock(&per_pin->lock);
Takashi Iwaid45e6882012-07-31 11:36:00 +02001766 per_pin->chmap_set = false;
1767 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
Takashi Iwaib0540872013-09-02 12:33:02 +02001768
1769 per_pin->setup = false;
1770 per_pin->channels = 0;
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001771 mutex_unlock(&per_pin->lock);
Stephen Warren384a48d2011-06-01 11:14:21 -06001772 }
Takashi Iwaid45e6882012-07-31 11:36:00 +02001773
Stephen Warren384a48d2011-06-01 11:14:21 -06001774 return 0;
1775}
1776
1777static const struct hda_pcm_ops generic_ops = {
1778 .open = hdmi_pcm_open,
Takashi Iwaif2ad24f2012-07-26 18:08:14 +02001779 .close = hdmi_pcm_close,
Stephen Warren384a48d2011-06-01 11:14:21 -06001780 .prepare = generic_hdmi_playback_pcm_prepare,
Takashi Iwai8dfaa572012-08-06 14:49:36 +02001781 .cleanup = generic_hdmi_playback_pcm_cleanup,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001782};
1783
Takashi Iwaid45e6882012-07-31 11:36:00 +02001784/*
1785 * ALSA API channel-map control callbacks
1786 */
1787static int hdmi_chmap_ctl_info(struct snd_kcontrol *kcontrol,
1788 struct snd_ctl_elem_info *uinfo)
1789{
1790 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
1791 struct hda_codec *codec = info->private_data;
1792 struct hdmi_spec *spec = codec->spec;
1793 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1794 uinfo->count = spec->channels_max;
1795 uinfo->value.integer.min = 0;
1796 uinfo->value.integer.max = SNDRV_CHMAP_LAST;
1797 return 0;
1798}
1799
Anssi Hannula307229d2013-10-24 21:10:34 +03001800static int hdmi_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap,
1801 int channels)
1802{
1803 /* If the speaker allocation matches the channel count, it is OK.*/
1804 if (cap->channels != channels)
1805 return -1;
1806
1807 /* all channels are remappable freely */
1808 return SNDRV_CTL_TLVT_CHMAP_VAR;
1809}
1810
1811static void hdmi_cea_alloc_to_tlv_chmap(struct cea_channel_speaker_allocation *cap,
1812 unsigned int *chmap, int channels)
1813{
1814 int count = 0;
1815 int c;
1816
1817 for (c = 7; c >= 0; c--) {
1818 int spk = cap->speakers[c];
1819 if (!spk)
1820 continue;
1821
1822 chmap[count++] = spk_to_chmap(spk);
1823 }
1824
1825 WARN_ON(count != channels);
1826}
1827
Takashi Iwaid45e6882012-07-31 11:36:00 +02001828static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1829 unsigned int size, unsigned int __user *tlv)
1830{
1831 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
1832 struct hda_codec *codec = info->private_data;
1833 struct hdmi_spec *spec = codec->spec;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001834 unsigned int __user *dst;
1835 int chs, count = 0;
1836
1837 if (size < 8)
1838 return -ENOMEM;
1839 if (put_user(SNDRV_CTL_TLVT_CONTAINER, tlv))
1840 return -EFAULT;
1841 size -= 8;
1842 dst = tlv + 2;
Takashi Iwai498dab32012-09-10 16:08:40 +02001843 for (chs = 2; chs <= spec->channels_max; chs++) {
Anssi Hannula307229d2013-10-24 21:10:34 +03001844 int i;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001845 struct cea_channel_speaker_allocation *cap;
1846 cap = channel_allocations;
1847 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++, cap++) {
1848 int chs_bytes = chs * 4;
Anssi Hannula307229d2013-10-24 21:10:34 +03001849 int type = spec->ops.chmap_cea_alloc_validate_get_type(cap, chs);
1850 unsigned int tlv_chmap[8];
1851
1852 if (type < 0)
Takashi Iwaid45e6882012-07-31 11:36:00 +02001853 continue;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001854 if (size < 8)
1855 return -ENOMEM;
Anssi Hannula307229d2013-10-24 21:10:34 +03001856 if (put_user(type, dst) ||
Takashi Iwaid45e6882012-07-31 11:36:00 +02001857 put_user(chs_bytes, dst + 1))
1858 return -EFAULT;
1859 dst += 2;
1860 size -= 8;
1861 count += 8;
1862 if (size < chs_bytes)
1863 return -ENOMEM;
1864 size -= chs_bytes;
1865 count += chs_bytes;
Anssi Hannula307229d2013-10-24 21:10:34 +03001866 spec->ops.cea_alloc_to_tlv_chmap(cap, tlv_chmap, chs);
1867 if (copy_to_user(dst, tlv_chmap, chs_bytes))
1868 return -EFAULT;
1869 dst += chs;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001870 }
1871 }
1872 if (put_user(count, tlv + 1))
1873 return -EFAULT;
1874 return 0;
1875}
1876
1877static int hdmi_chmap_ctl_get(struct snd_kcontrol *kcontrol,
1878 struct snd_ctl_elem_value *ucontrol)
1879{
1880 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
1881 struct hda_codec *codec = info->private_data;
1882 struct hdmi_spec *spec = codec->spec;
1883 int pin_idx = kcontrol->private_value;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001884 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Takashi Iwaid45e6882012-07-31 11:36:00 +02001885 int i;
1886
1887 for (i = 0; i < ARRAY_SIZE(per_pin->chmap); i++)
1888 ucontrol->value.integer.value[i] = per_pin->chmap[i];
1889 return 0;
1890}
1891
1892static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
1893 struct snd_ctl_elem_value *ucontrol)
1894{
1895 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
1896 struct hda_codec *codec = info->private_data;
1897 struct hdmi_spec *spec = codec->spec;
1898 int pin_idx = kcontrol->private_value;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001899 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Takashi Iwaid45e6882012-07-31 11:36:00 +02001900 unsigned int ctl_idx;
1901 struct snd_pcm_substream *substream;
1902 unsigned char chmap[8];
Anssi Hannula307229d2013-10-24 21:10:34 +03001903 int i, err, ca, prepared = 0;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001904
1905 ctl_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1906 substream = snd_pcm_chmap_substream(info, ctl_idx);
1907 if (!substream || !substream->runtime)
Takashi Iwai6f54c362013-01-15 14:44:41 +01001908 return 0; /* just for avoiding error from alsactl restore */
Takashi Iwaid45e6882012-07-31 11:36:00 +02001909 switch (substream->runtime->status->state) {
1910 case SNDRV_PCM_STATE_OPEN:
1911 case SNDRV_PCM_STATE_SETUP:
1912 break;
1913 case SNDRV_PCM_STATE_PREPARED:
1914 prepared = 1;
1915 break;
1916 default:
1917 return -EBUSY;
1918 }
1919 memset(chmap, 0, sizeof(chmap));
1920 for (i = 0; i < ARRAY_SIZE(chmap); i++)
1921 chmap[i] = ucontrol->value.integer.value[i];
1922 if (!memcmp(chmap, per_pin->chmap, sizeof(chmap)))
1923 return 0;
1924 ca = hdmi_manual_channel_allocation(ARRAY_SIZE(chmap), chmap);
1925 if (ca < 0)
1926 return -EINVAL;
Anssi Hannula307229d2013-10-24 21:10:34 +03001927 if (spec->ops.chmap_validate) {
1928 err = spec->ops.chmap_validate(ca, ARRAY_SIZE(chmap), chmap);
1929 if (err)
1930 return err;
1931 }
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001932 mutex_lock(&per_pin->lock);
Takashi Iwaid45e6882012-07-31 11:36:00 +02001933 per_pin->chmap_set = true;
1934 memcpy(per_pin->chmap, chmap, sizeof(chmap));
1935 if (prepared)
Takashi Iwaib0540872013-09-02 12:33:02 +02001936 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001937 mutex_unlock(&per_pin->lock);
Takashi Iwaid45e6882012-07-31 11:36:00 +02001938
1939 return 0;
1940}
1941
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001942static int generic_hdmi_build_pcms(struct hda_codec *codec)
1943{
1944 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001945 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001946
Stephen Warren384a48d2011-06-01 11:14:21 -06001947 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1948 struct hda_pcm *info;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001949 struct hda_pcm_stream *pstr;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001950 struct hdmi_spec_per_pin *per_pin;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001951
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001952 per_pin = get_pin(spec, pin_idx);
1953 sprintf(per_pin->pcm_name, "HDMI %d", pin_idx);
1954 info = snd_array_new(&spec->pcm_rec);
1955 if (!info)
1956 return -ENOMEM;
1957 info->name = per_pin->pcm_name;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001958 info->pcm_type = HDA_PCM_TYPE_HDMI;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001959 info->own_chmap = true;
Stephen Warren384a48d2011-06-01 11:14:21 -06001960
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001961 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
Stephen Warren384a48d2011-06-01 11:14:21 -06001962 pstr->substreams = 1;
1963 pstr->ops = generic_ops;
1964 /* other pstr fields are set in open */
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001965 }
1966
Stephen Warren384a48d2011-06-01 11:14:21 -06001967 codec->num_pcms = spec->num_pins;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001968 codec->pcm_info = spec->pcm_rec.list;
Stephen Warren384a48d2011-06-01 11:14:21 -06001969
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001970 return 0;
1971}
1972
David Henningsson0b6c49b2011-08-23 16:56:03 +02001973static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx)
1974{
Takashi Iwai31ef2252011-12-01 17:41:36 +01001975 char hdmi_str[32] = "HDMI/DP";
David Henningsson0b6c49b2011-08-23 16:56:03 +02001976 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001977 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1978 int pcmdev = get_pcm_rec(spec, pin_idx)->device;
David Henningsson0b6c49b2011-08-23 16:56:03 +02001979
Takashi Iwai31ef2252011-12-01 17:41:36 +01001980 if (pcmdev > 0)
1981 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
David Henningsson30efd8d2013-02-22 10:16:28 +01001982 if (!is_jack_detectable(codec, per_pin->pin_nid))
1983 strncat(hdmi_str, " Phantom",
1984 sizeof(hdmi_str) - strlen(hdmi_str) - 1);
David Henningsson0b6c49b2011-08-23 16:56:03 +02001985
Takashi Iwai31ef2252011-12-01 17:41:36 +01001986 return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str, 0);
David Henningsson0b6c49b2011-08-23 16:56:03 +02001987}
1988
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001989static int generic_hdmi_build_controls(struct hda_codec *codec)
1990{
1991 struct hdmi_spec *spec = codec->spec;
1992 int err;
Stephen Warren384a48d2011-06-01 11:14:21 -06001993 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001994
Stephen Warren384a48d2011-06-01 11:14:21 -06001995 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001996 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
David Henningsson0b6c49b2011-08-23 16:56:03 +02001997
1998 err = generic_hdmi_build_jack(codec, pin_idx);
1999 if (err < 0)
2000 return err;
2001
Takashi Iwaidcda5802012-10-12 17:24:51 +02002002 err = snd_hda_create_dig_out_ctls(codec,
2003 per_pin->pin_nid,
2004 per_pin->mux_nids[0],
2005 HDA_PCM_TYPE_HDMI);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002006 if (err < 0)
2007 return err;
Stephen Warren384a48d2011-06-01 11:14:21 -06002008 snd_hda_spdif_ctls_unassign(codec, pin_idx);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -05002009
2010 /* add control for ELD Bytes */
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002011 err = hdmi_create_eld_ctl(codec, pin_idx,
2012 get_pcm_rec(spec, pin_idx)->device);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -05002013
2014 if (err < 0)
2015 return err;
Takashi Iwai31ef2252011-12-01 17:41:36 +01002016
Takashi Iwai82b1d732011-12-20 15:53:07 +01002017 hdmi_present_sense(per_pin, 0);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002018 }
2019
Takashi Iwaid45e6882012-07-31 11:36:00 +02002020 /* add channel maps */
2021 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2022 struct snd_pcm_chmap *chmap;
2023 struct snd_kcontrol *kctl;
2024 int i;
Takashi Iwai2ca320e2013-08-22 09:55:36 +02002025
2026 if (!codec->pcm_info[pin_idx].pcm)
2027 break;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002028 err = snd_pcm_add_chmap_ctls(codec->pcm_info[pin_idx].pcm,
2029 SNDRV_PCM_STREAM_PLAYBACK,
2030 NULL, 0, pin_idx, &chmap);
2031 if (err < 0)
2032 return err;
2033 /* override handlers */
2034 chmap->private_data = codec;
2035 kctl = chmap->kctl;
2036 for (i = 0; i < kctl->count; i++)
2037 kctl->vd[i].access |= SNDRV_CTL_ELEM_ACCESS_WRITE;
2038 kctl->info = hdmi_chmap_ctl_info;
2039 kctl->get = hdmi_chmap_ctl_get;
2040 kctl->put = hdmi_chmap_ctl_put;
2041 kctl->tlv.c = hdmi_chmap_ctl_tlv;
2042 }
2043
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002044 return 0;
2045}
2046
Takashi Iwai8b8d6542012-06-20 16:32:22 +02002047static int generic_hdmi_init_per_pins(struct hda_codec *codec)
2048{
2049 struct hdmi_spec *spec = codec->spec;
2050 int pin_idx;
2051
2052 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002053 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Takashi Iwai8b8d6542012-06-20 16:32:22 +02002054
2055 per_pin->codec = codec;
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002056 mutex_init(&per_pin->lock);
Takashi Iwai8b8d6542012-06-20 16:32:22 +02002057 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002058 eld_proc_new(per_pin, pin_idx);
Takashi Iwai8b8d6542012-06-20 16:32:22 +02002059 }
2060 return 0;
2061}
2062
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002063static int generic_hdmi_init(struct hda_codec *codec)
2064{
2065 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06002066 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002067
Stephen Warren384a48d2011-06-01 11:14:21 -06002068 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002069 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06002070 hda_nid_t pin_nid = per_pin->pin_nid;
Stephen Warren384a48d2011-06-01 11:14:21 -06002071
2072 hdmi_init_pin(codec, pin_nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02002073 snd_hda_jack_detect_enable(codec, pin_nid, pin_nid);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002074 }
2075 return 0;
2076}
2077
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002078static void hdmi_array_init(struct hdmi_spec *spec, int nums)
2079{
2080 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums);
2081 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums);
2082 snd_array_init(&spec->pcm_rec, sizeof(struct hda_pcm), nums);
2083}
2084
2085static void hdmi_array_free(struct hdmi_spec *spec)
2086{
2087 snd_array_free(&spec->pins);
2088 snd_array_free(&spec->cvts);
2089 snd_array_free(&spec->pcm_rec);
2090}
2091
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002092static void generic_hdmi_free(struct hda_codec *codec)
2093{
2094 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06002095 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002096
Stephen Warren384a48d2011-06-01 11:14:21 -06002097 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002098 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06002099
Wu Fengguang744626d2011-11-16 16:29:47 +08002100 cancel_delayed_work(&per_pin->work);
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002101 eld_proc_free(per_pin);
Stephen Warren384a48d2011-06-01 11:14:21 -06002102 }
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002103
Wu Fengguang744626d2011-11-16 16:29:47 +08002104 flush_workqueue(codec->bus->workq);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002105 hdmi_array_free(spec);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002106 kfree(spec);
2107}
2108
Wang Xingchao28cb72e2013-06-24 07:45:23 -04002109#ifdef CONFIG_PM
2110static int generic_hdmi_resume(struct hda_codec *codec)
2111{
2112 struct hdmi_spec *spec = codec->spec;
2113 int pin_idx;
2114
2115 generic_hdmi_init(codec);
2116 snd_hda_codec_resume_amp(codec);
2117 snd_hda_codec_resume_cache(codec);
2118
2119 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2120 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2121 hdmi_present_sense(per_pin, 1);
2122 }
2123 return 0;
2124}
2125#endif
2126
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02002127static const struct hda_codec_ops generic_hdmi_patch_ops = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002128 .init = generic_hdmi_init,
2129 .free = generic_hdmi_free,
2130 .build_pcms = generic_hdmi_build_pcms,
2131 .build_controls = generic_hdmi_build_controls,
2132 .unsol_event = hdmi_unsol_event,
Wang Xingchao28cb72e2013-06-24 07:45:23 -04002133#ifdef CONFIG_PM
2134 .resume = generic_hdmi_resume,
2135#endif
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002136};
2137
Anssi Hannula307229d2013-10-24 21:10:34 +03002138static const struct hdmi_ops generic_standard_hdmi_ops = {
2139 .pin_get_eld = snd_hdmi_get_eld,
2140 .pin_get_slot_channel = hdmi_pin_get_slot_channel,
2141 .pin_set_slot_channel = hdmi_pin_set_slot_channel,
2142 .pin_setup_infoframe = hdmi_pin_setup_infoframe,
2143 .pin_hbr_setup = hdmi_pin_hbr_setup,
2144 .setup_stream = hdmi_setup_stream,
2145 .chmap_cea_alloc_validate_get_type = hdmi_chmap_cea_alloc_validate_get_type,
2146 .cea_alloc_to_tlv_chmap = hdmi_cea_alloc_to_tlv_chmap,
2147};
2148
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002149
2150static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
2151 hda_nid_t nid)
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002152{
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002153 struct hdmi_spec *spec = codec->spec;
2154 hda_nid_t conns[4];
2155 int nconns;
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002156
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002157 nconns = snd_hda_get_connections(codec, nid, conns, ARRAY_SIZE(conns));
2158 if (nconns == spec->num_cvts &&
2159 !memcmp(conns, spec->cvt_nids, spec->num_cvts * sizeof(hda_nid_t)))
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002160 return;
2161
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002162 /* override pins connection list */
2163 snd_printdd("hdmi: haswell: override pin connection 0x%x\n", nid);
2164 snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids);
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002165}
2166
Mengdong Lin1611a9c2013-02-08 17:09:52 -05002167#define INTEL_VENDOR_NID 0x08
2168#define INTEL_GET_VENDOR_VERB 0xf81
2169#define INTEL_SET_VENDOR_VERB 0x781
2170#define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
2171#define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
2172
2173static void intel_haswell_enable_all_pins(struct hda_codec *codec,
Takashi Iwai17df3f52013-05-08 08:09:34 +02002174 bool update_tree)
Mengdong Lin1611a9c2013-02-08 17:09:52 -05002175{
2176 unsigned int vendor_param;
2177
Mengdong Lin1611a9c2013-02-08 17:09:52 -05002178 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
2179 INTEL_GET_VENDOR_VERB, 0);
2180 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
2181 return;
2182
2183 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
2184 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
2185 INTEL_SET_VENDOR_VERB, vendor_param);
2186 if (vendor_param == -1)
2187 return;
2188
Takashi Iwai17df3f52013-05-08 08:09:34 +02002189 if (update_tree)
2190 snd_hda_codec_update_widgets(codec);
Mengdong Lin1611a9c2013-02-08 17:09:52 -05002191}
2192
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002193static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
2194{
2195 unsigned int vendor_param;
2196
2197 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
2198 INTEL_GET_VENDOR_VERB, 0);
2199 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
2200 return;
2201
2202 /* enable DP1.2 mode */
2203 vendor_param |= INTEL_EN_DP12;
2204 snd_hda_codec_write_cache(codec, INTEL_VENDOR_NID, 0,
2205 INTEL_SET_VENDOR_VERB, vendor_param);
2206}
2207
Takashi Iwai17df3f52013-05-08 08:09:34 +02002208/* Haswell needs to re-issue the vendor-specific verbs before turning to D0.
2209 * Otherwise you may get severe h/w communication errors.
2210 */
2211static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2212 unsigned int power_state)
2213{
2214 if (power_state == AC_PWRST_D0) {
2215 intel_haswell_enable_all_pins(codec, false);
2216 intel_haswell_fixup_enable_dp12(codec);
2217 }
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002218
Takashi Iwai17df3f52013-05-08 08:09:34 +02002219 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
2220 snd_hda_codec_set_power_to_all(codec, fg, power_state);
2221}
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002222
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002223static int patch_generic_hdmi(struct hda_codec *codec)
2224{
2225 struct hdmi_spec *spec;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002226
2227 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2228 if (spec == NULL)
2229 return -ENOMEM;
2230
Anssi Hannula307229d2013-10-24 21:10:34 +03002231 spec->ops = generic_standard_hdmi_ops;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002232 codec->spec = spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002233 hdmi_array_init(spec, 4);
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002234
Mengdong Linfb87fa32013-09-04 16:36:57 -04002235 if (is_haswell(codec)) {
Takashi Iwai17df3f52013-05-08 08:09:34 +02002236 intel_haswell_enable_all_pins(codec, true);
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002237 intel_haswell_fixup_enable_dp12(codec);
Takashi Iwai17df3f52013-05-08 08:09:34 +02002238 }
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002239
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002240 if (hdmi_parse_codec(codec) < 0) {
2241 codec->spec = NULL;
2242 kfree(spec);
2243 return -EINVAL;
2244 }
2245 codec->patch_ops = generic_hdmi_patch_ops;
Mengdong Linfb87fa32013-09-04 16:36:57 -04002246 if (is_haswell(codec)) {
Takashi Iwai17df3f52013-05-08 08:09:34 +02002247 codec->patch_ops.set_power_state = haswell_set_power_state;
Mengdong Lin5dc989b2013-08-26 21:35:41 -04002248 codec->dp_mst = true;
2249 }
Takashi Iwai17df3f52013-05-08 08:09:34 +02002250
Takashi Iwai8b8d6542012-06-20 16:32:22 +02002251 generic_hdmi_init_per_pins(codec);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002252
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002253 init_channel_allocations();
2254
2255 return 0;
2256}
2257
2258/*
Stephen Warren3aaf8982011-06-01 11:14:19 -06002259 * Shared non-generic implementations
2260 */
2261
2262static int simple_playback_build_pcms(struct hda_codec *codec)
2263{
2264 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002265 struct hda_pcm *info;
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002266 unsigned int chans;
2267 struct hda_pcm_stream *pstr;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002268 struct hdmi_spec_per_cvt *per_cvt;
Stephen Warren3aaf8982011-06-01 11:14:19 -06002269
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002270 per_cvt = get_cvt(spec, 0);
2271 chans = get_wcaps(codec, per_cvt->cvt_nid);
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002272 chans = get_wcaps_channels(chans);
Stephen Warren3aaf8982011-06-01 11:14:19 -06002273
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002274 info = snd_array_new(&spec->pcm_rec);
2275 if (!info)
2276 return -ENOMEM;
2277 info->name = get_pin(spec, 0)->pcm_name;
2278 sprintf(info->name, "HDMI 0");
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002279 info->pcm_type = HDA_PCM_TYPE_HDMI;
2280 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
2281 *pstr = spec->pcm_playback;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002282 pstr->nid = per_cvt->cvt_nid;
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002283 if (pstr->channels_max <= 2 && chans && chans <= 16)
2284 pstr->channels_max = chans;
Stephen Warren3aaf8982011-06-01 11:14:19 -06002285
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002286 codec->num_pcms = 1;
2287 codec->pcm_info = info;
2288
Stephen Warren3aaf8982011-06-01 11:14:19 -06002289 return 0;
2290}
2291
Takashi Iwai4b6ace92012-06-15 11:53:32 +02002292/* unsolicited event for jack sensing */
2293static void simple_hdmi_unsol_event(struct hda_codec *codec,
2294 unsigned int res)
2295{
Takashi Iwai9dd8cf12012-06-21 10:43:15 +02002296 snd_hda_jack_set_dirty_all(codec);
Takashi Iwai4b6ace92012-06-15 11:53:32 +02002297 snd_hda_jack_report_sync(codec);
2298}
2299
2300/* generic_hdmi_build_jack can be used for simple_hdmi, too,
2301 * as long as spec->pins[] is set correctly
2302 */
2303#define simple_hdmi_build_jack generic_hdmi_build_jack
2304
Stephen Warren3aaf8982011-06-01 11:14:19 -06002305static int simple_playback_build_controls(struct hda_codec *codec)
2306{
2307 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002308 struct hdmi_spec_per_cvt *per_cvt;
Stephen Warren3aaf8982011-06-01 11:14:19 -06002309 int err;
Stephen Warren3aaf8982011-06-01 11:14:19 -06002310
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002311 per_cvt = get_cvt(spec, 0);
2312 err = snd_hda_create_spdif_out_ctls(codec, per_cvt->cvt_nid,
2313 per_cvt->cvt_nid);
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002314 if (err < 0)
2315 return err;
2316 return simple_hdmi_build_jack(codec, 0);
Stephen Warren3aaf8982011-06-01 11:14:19 -06002317}
2318
Takashi Iwai4f0110c2012-06-15 12:45:43 +02002319static int simple_playback_init(struct hda_codec *codec)
2320{
2321 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002322 struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0);
2323 hda_nid_t pin = per_pin->pin_nid;
Takashi Iwai4f0110c2012-06-15 12:45:43 +02002324
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002325 snd_hda_codec_write(codec, pin, 0,
2326 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
2327 /* some codecs require to unmute the pin */
2328 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
2329 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2330 AMP_OUT_UNMUTE);
2331 snd_hda_jack_detect_enable(codec, pin, pin);
Takashi Iwai4f0110c2012-06-15 12:45:43 +02002332 return 0;
2333}
2334
Stephen Warren3aaf8982011-06-01 11:14:19 -06002335static void simple_playback_free(struct hda_codec *codec)
2336{
2337 struct hdmi_spec *spec = codec->spec;
2338
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002339 hdmi_array_free(spec);
Stephen Warren3aaf8982011-06-01 11:14:19 -06002340 kfree(spec);
2341}
2342
2343/*
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002344 * Nvidia specific implementations
2345 */
2346
2347#define Nv_VERB_SET_Channel_Allocation 0xF79
2348#define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
2349#define Nv_VERB_SET_Audio_Protection_On 0xF98
2350#define Nv_VERB_SET_Audio_Protection_Off 0xF99
2351
2352#define nvhdmi_master_con_nid_7x 0x04
2353#define nvhdmi_master_pin_nid_7x 0x05
2354
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02002355static const hda_nid_t nvhdmi_con_nids_7x[4] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002356 /*front, rear, clfe, rear_surr */
2357 0x6, 0x8, 0xa, 0xc,
2358};
2359
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002360static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = {
2361 /* set audio protect on */
2362 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
2363 /* enable digital output on pin widget */
2364 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2365 {} /* terminator */
2366};
2367
2368static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002369 /* set audio protect on */
2370 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
2371 /* enable digital output on pin widget */
2372 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2373 { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2374 { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2375 { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2376 { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2377 {} /* terminator */
2378};
2379
2380#ifdef LIMITED_RATE_FMT_SUPPORT
2381/* support only the safe format and rate */
2382#define SUPPORTED_RATES SNDRV_PCM_RATE_48000
2383#define SUPPORTED_MAXBPS 16
2384#define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
2385#else
2386/* support all rates and formats */
2387#define SUPPORTED_RATES \
2388 (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
2389 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
2390 SNDRV_PCM_RATE_192000)
2391#define SUPPORTED_MAXBPS 24
2392#define SUPPORTED_FORMATS \
2393 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
2394#endif
2395
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002396static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002397{
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002398 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
2399 return 0;
2400}
2401
2402static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
2403{
2404 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002405 return 0;
2406}
2407
Nitin Daga393004b2011-01-10 21:49:31 +05302408static unsigned int channels_2_6_8[] = {
2409 2, 6, 8
2410};
2411
2412static unsigned int channels_2_8[] = {
2413 2, 8
2414};
2415
2416static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
2417 .count = ARRAY_SIZE(channels_2_6_8),
2418 .list = channels_2_6_8,
2419 .mask = 0,
2420};
2421
2422static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
2423 .count = ARRAY_SIZE(channels_2_8),
2424 .list = channels_2_8,
2425 .mask = 0,
2426};
2427
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002428static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
2429 struct hda_codec *codec,
2430 struct snd_pcm_substream *substream)
2431{
2432 struct hdmi_spec *spec = codec->spec;
Nitin Daga393004b2011-01-10 21:49:31 +05302433 struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
2434
2435 switch (codec->preset->id) {
2436 case 0x10de0002:
2437 case 0x10de0003:
2438 case 0x10de0005:
2439 case 0x10de0006:
2440 hw_constraints_channels = &hw_constraints_2_8_channels;
2441 break;
2442 case 0x10de0007:
2443 hw_constraints_channels = &hw_constraints_2_6_8_channels;
2444 break;
2445 default:
2446 break;
2447 }
2448
2449 if (hw_constraints_channels != NULL) {
2450 snd_pcm_hw_constraint_list(substream->runtime, 0,
2451 SNDRV_PCM_HW_PARAM_CHANNELS,
2452 hw_constraints_channels);
Takashi Iwaiad09fc92011-01-14 09:42:27 +01002453 } else {
2454 snd_pcm_hw_constraint_step(substream->runtime, 0,
2455 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Nitin Daga393004b2011-01-10 21:49:31 +05302456 }
2457
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002458 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2459}
2460
2461static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
2462 struct hda_codec *codec,
2463 struct snd_pcm_substream *substream)
2464{
2465 struct hdmi_spec *spec = codec->spec;
2466 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2467}
2468
2469static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2470 struct hda_codec *codec,
2471 unsigned int stream_tag,
2472 unsigned int format,
2473 struct snd_pcm_substream *substream)
2474{
2475 struct hdmi_spec *spec = codec->spec;
2476 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2477 stream_tag, format, substream);
2478}
2479
Takashi Iwaid0b12522012-06-15 14:34:42 +02002480static const struct hda_pcm_stream simple_pcm_playback = {
2481 .substreams = 1,
2482 .channels_min = 2,
2483 .channels_max = 2,
2484 .ops = {
2485 .open = simple_playback_pcm_open,
2486 .close = simple_playback_pcm_close,
2487 .prepare = simple_playback_pcm_prepare
2488 },
2489};
2490
2491static const struct hda_codec_ops simple_hdmi_patch_ops = {
2492 .build_controls = simple_playback_build_controls,
2493 .build_pcms = simple_playback_build_pcms,
2494 .init = simple_playback_init,
2495 .free = simple_playback_free,
Takashi Iwai250e41a2012-06-15 14:40:21 +02002496 .unsol_event = simple_hdmi_unsol_event,
Takashi Iwaid0b12522012-06-15 14:34:42 +02002497};
2498
2499static int patch_simple_hdmi(struct hda_codec *codec,
2500 hda_nid_t cvt_nid, hda_nid_t pin_nid)
2501{
2502 struct hdmi_spec *spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002503 struct hdmi_spec_per_cvt *per_cvt;
2504 struct hdmi_spec_per_pin *per_pin;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002505
2506 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2507 if (!spec)
2508 return -ENOMEM;
2509
2510 codec->spec = spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002511 hdmi_array_init(spec, 1);
Takashi Iwaid0b12522012-06-15 14:34:42 +02002512
2513 spec->multiout.num_dacs = 0; /* no analog */
2514 spec->multiout.max_channels = 2;
2515 spec->multiout.dig_out_nid = cvt_nid;
2516 spec->num_cvts = 1;
2517 spec->num_pins = 1;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002518 per_pin = snd_array_new(&spec->pins);
2519 per_cvt = snd_array_new(&spec->cvts);
2520 if (!per_pin || !per_cvt) {
2521 simple_playback_free(codec);
2522 return -ENOMEM;
2523 }
2524 per_cvt->cvt_nid = cvt_nid;
2525 per_pin->pin_nid = pin_nid;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002526 spec->pcm_playback = simple_pcm_playback;
2527
2528 codec->patch_ops = simple_hdmi_patch_ops;
2529
2530 return 0;
2531}
2532
Aaron Plattner1f348522011-04-06 17:19:04 -07002533static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
2534 int channels)
2535{
2536 unsigned int chanmask;
2537 int chan = channels ? (channels - 1) : 1;
2538
2539 switch (channels) {
2540 default:
2541 case 0:
2542 case 2:
2543 chanmask = 0x00;
2544 break;
2545 case 4:
2546 chanmask = 0x08;
2547 break;
2548 case 6:
2549 chanmask = 0x0b;
2550 break;
2551 case 8:
2552 chanmask = 0x13;
2553 break;
2554 }
2555
2556 /* Set the audio infoframe channel allocation and checksum fields. The
2557 * channel count is computed implicitly by the hardware. */
2558 snd_hda_codec_write(codec, 0x1, 0,
2559 Nv_VERB_SET_Channel_Allocation, chanmask);
2560
2561 snd_hda_codec_write(codec, 0x1, 0,
2562 Nv_VERB_SET_Info_Frame_Checksum,
2563 (0x71 - chan - chanmask));
2564}
2565
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002566static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
2567 struct hda_codec *codec,
2568 struct snd_pcm_substream *substream)
2569{
2570 struct hdmi_spec *spec = codec->spec;
2571 int i;
2572
2573 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
2574 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
2575 for (i = 0; i < 4; i++) {
2576 /* set the stream id */
2577 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
2578 AC_VERB_SET_CHANNEL_STREAMID, 0);
2579 /* set the stream format */
2580 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
2581 AC_VERB_SET_STREAM_FORMAT, 0);
2582 }
2583
Aaron Plattner1f348522011-04-06 17:19:04 -07002584 /* The audio hardware sends a channel count of 0x7 (8ch) when all the
2585 * streams are disabled. */
2586 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
2587
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002588 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2589}
2590
2591static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
2592 struct hda_codec *codec,
2593 unsigned int stream_tag,
2594 unsigned int format,
2595 struct snd_pcm_substream *substream)
2596{
2597 int chs;
Takashi Iwai112daa72011-11-02 21:40:06 +01002598 unsigned int dataDCC2, channel_id;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002599 int i;
Stephen Warren7c935972011-06-01 11:14:17 -06002600 struct hdmi_spec *spec = codec->spec;
Takashi Iwaie3245cd2012-05-10 10:21:29 +02002601 struct hda_spdif_out *spdif;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002602 struct hdmi_spec_per_cvt *per_cvt;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002603
2604 mutex_lock(&codec->spdif_mutex);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002605 per_cvt = get_cvt(spec, 0);
2606 spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002607
2608 chs = substream->runtime->channels;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002609
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002610 dataDCC2 = 0x2;
2611
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002612 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
Stephen Warren7c935972011-06-01 11:14:17 -06002613 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002614 snd_hda_codec_write(codec,
2615 nvhdmi_master_con_nid_7x,
2616 0,
2617 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06002618 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002619
2620 /* set the stream id */
2621 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
2622 AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
2623
2624 /* set the stream format */
2625 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
2626 AC_VERB_SET_STREAM_FORMAT, format);
2627
2628 /* turn on again (if needed) */
2629 /* enable and set the channel status audio/data flag */
Stephen Warren7c935972011-06-01 11:14:17 -06002630 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002631 snd_hda_codec_write(codec,
2632 nvhdmi_master_con_nid_7x,
2633 0,
2634 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06002635 spdif->ctls & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002636 snd_hda_codec_write(codec,
2637 nvhdmi_master_con_nid_7x,
2638 0,
2639 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
2640 }
2641
2642 for (i = 0; i < 4; i++) {
2643 if (chs == 2)
2644 channel_id = 0;
2645 else
2646 channel_id = i * 2;
2647
2648 /* turn off SPDIF once;
2649 *otherwise the IEC958 bits won't be updated
2650 */
2651 if (codec->spdif_status_reset &&
Stephen Warren7c935972011-06-01 11:14:17 -06002652 (spdif->ctls & AC_DIG1_ENABLE))
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002653 snd_hda_codec_write(codec,
2654 nvhdmi_con_nids_7x[i],
2655 0,
2656 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06002657 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002658 /* set the stream id */
2659 snd_hda_codec_write(codec,
2660 nvhdmi_con_nids_7x[i],
2661 0,
2662 AC_VERB_SET_CHANNEL_STREAMID,
2663 (stream_tag << 4) | channel_id);
2664 /* set the stream format */
2665 snd_hda_codec_write(codec,
2666 nvhdmi_con_nids_7x[i],
2667 0,
2668 AC_VERB_SET_STREAM_FORMAT,
2669 format);
2670 /* turn on again (if needed) */
2671 /* enable and set the channel status audio/data flag */
2672 if (codec->spdif_status_reset &&
Stephen Warren7c935972011-06-01 11:14:17 -06002673 (spdif->ctls & AC_DIG1_ENABLE)) {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002674 snd_hda_codec_write(codec,
2675 nvhdmi_con_nids_7x[i],
2676 0,
2677 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06002678 spdif->ctls & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002679 snd_hda_codec_write(codec,
2680 nvhdmi_con_nids_7x[i],
2681 0,
2682 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
2683 }
2684 }
2685
Aaron Plattner1f348522011-04-06 17:19:04 -07002686 nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002687
2688 mutex_unlock(&codec->spdif_mutex);
2689 return 0;
2690}
2691
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02002692static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002693 .substreams = 1,
2694 .channels_min = 2,
2695 .channels_max = 8,
2696 .nid = nvhdmi_master_con_nid_7x,
2697 .rates = SUPPORTED_RATES,
2698 .maxbps = SUPPORTED_MAXBPS,
2699 .formats = SUPPORTED_FORMATS,
2700 .ops = {
2701 .open = simple_playback_pcm_open,
2702 .close = nvhdmi_8ch_7x_pcm_close,
2703 .prepare = nvhdmi_8ch_7x_pcm_prepare
2704 },
2705};
2706
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002707static int patch_nvhdmi_2ch(struct hda_codec *codec)
2708{
2709 struct hdmi_spec *spec;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002710 int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
2711 nvhdmi_master_pin_nid_7x);
2712 if (err < 0)
2713 return err;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002714
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002715 codec->patch_ops.init = nvhdmi_7x_init_2ch;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002716 /* override the PCM rates, etc, as the codec doesn't give full list */
2717 spec = codec->spec;
2718 spec->pcm_playback.rates = SUPPORTED_RATES;
2719 spec->pcm_playback.maxbps = SUPPORTED_MAXBPS;
2720 spec->pcm_playback.formats = SUPPORTED_FORMATS;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002721 return 0;
2722}
2723
Takashi Iwai53775b02012-08-01 12:17:41 +02002724static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
2725{
2726 struct hdmi_spec *spec = codec->spec;
2727 int err = simple_playback_build_pcms(codec);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002728 if (!err) {
2729 struct hda_pcm *info = get_pcm_rec(spec, 0);
2730 info->own_chmap = true;
2731 }
Takashi Iwai53775b02012-08-01 12:17:41 +02002732 return err;
2733}
2734
2735static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
2736{
2737 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002738 struct hda_pcm *info;
Takashi Iwai53775b02012-08-01 12:17:41 +02002739 struct snd_pcm_chmap *chmap;
2740 int err;
2741
2742 err = simple_playback_build_controls(codec);
2743 if (err < 0)
2744 return err;
2745
2746 /* add channel maps */
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002747 info = get_pcm_rec(spec, 0);
2748 err = snd_pcm_add_chmap_ctls(info->pcm,
Takashi Iwai53775b02012-08-01 12:17:41 +02002749 SNDRV_PCM_STREAM_PLAYBACK,
2750 snd_pcm_alt_chmaps, 8, 0, &chmap);
2751 if (err < 0)
2752 return err;
2753 switch (codec->preset->id) {
2754 case 0x10de0002:
2755 case 0x10de0003:
2756 case 0x10de0005:
2757 case 0x10de0006:
2758 chmap->channel_mask = (1U << 2) | (1U << 8);
2759 break;
2760 case 0x10de0007:
2761 chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8);
2762 }
2763 return 0;
2764}
2765
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002766static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
2767{
2768 struct hdmi_spec *spec;
2769 int err = patch_nvhdmi_2ch(codec);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002770 if (err < 0)
2771 return err;
2772 spec = codec->spec;
2773 spec->multiout.max_channels = 8;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002774 spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x;
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002775 codec->patch_ops.init = nvhdmi_7x_init_8ch;
Takashi Iwai53775b02012-08-01 12:17:41 +02002776 codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
2777 codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
Aaron Plattner1f348522011-04-06 17:19:04 -07002778
2779 /* Initialize the audio infoframe channel mask and checksum to something
2780 * valid */
2781 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
2782
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002783 return 0;
2784}
2785
2786/*
2787 * ATI-specific implementations
2788 *
2789 * FIXME: we may omit the whole this and use the generic code once after
2790 * it's confirmed to work.
2791 */
2792
2793#define ATIHDMI_CVT_NID 0x02 /* audio converter */
2794#define ATIHDMI_PIN_NID 0x03 /* HDMI output pin */
2795
2796static int atihdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2797 struct hda_codec *codec,
2798 unsigned int stream_tag,
2799 unsigned int format,
2800 struct snd_pcm_substream *substream)
2801{
2802 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002803 struct hdmi_spec_per_cvt *per_cvt = get_cvt(spec, 0);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002804 int chans = substream->runtime->channels;
2805 int i, err;
2806
2807 err = simple_playback_pcm_prepare(hinfo, codec, stream_tag, format,
2808 substream);
2809 if (err < 0)
2810 return err;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002811 snd_hda_codec_write(codec, per_cvt->cvt_nid, 0,
Stephen Warren384a48d2011-06-01 11:14:21 -06002812 AC_VERB_SET_CVT_CHAN_COUNT, chans - 1);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002813 /* FIXME: XXX */
2814 for (i = 0; i < chans; i++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002815 snd_hda_codec_write(codec, per_cvt->cvt_nid, 0,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002816 AC_VERB_SET_HDMI_CHAN_SLOT,
2817 (i << 4) | i);
2818 }
2819 return 0;
2820}
2821
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002822static int patch_atihdmi(struct hda_codec *codec)
2823{
2824 struct hdmi_spec *spec;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002825 int err = patch_simple_hdmi(codec, ATIHDMI_CVT_NID, ATIHDMI_PIN_NID);
2826 if (err < 0)
2827 return err;
2828 spec = codec->spec;
2829 spec->pcm_playback.ops.prepare = atihdmi_playback_pcm_prepare;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002830 return 0;
2831}
2832
Annie Liu3de5ff82012-06-08 19:18:42 +08002833/* VIA HDMI Implementation */
2834#define VIAHDMI_CVT_NID 0x02 /* audio converter1 */
2835#define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */
2836
Annie Liu3de5ff82012-06-08 19:18:42 +08002837static int patch_via_hdmi(struct hda_codec *codec)
2838{
Takashi Iwai250e41a2012-06-15 14:40:21 +02002839 return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
Annie Liu3de5ff82012-06-08 19:18:42 +08002840}
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002841
2842/*
2843 * patch entries
2844 */
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02002845static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002846{ .id = 0x1002793c, .name = "RS600 HDMI", .patch = patch_atihdmi },
2847{ .id = 0x10027919, .name = "RS600 HDMI", .patch = patch_atihdmi },
2848{ .id = 0x1002791a, .name = "RS690/780 HDMI", .patch = patch_atihdmi },
Anssi Hannula36e9c132010-12-05 02:34:15 +02002849{ .id = 0x1002aa01, .name = "R6xx HDMI", .patch = patch_generic_hdmi },
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002850{ .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_generic_hdmi },
2851{ .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_generic_hdmi },
2852{ .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_generic_hdmi },
2853{ .id = 0x10de0002, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2854{ .id = 0x10de0003, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2855{ .id = 0x10de0005, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2856{ .id = 0x10de0006, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2857{ .id = 0x10de0007, .name = "MCP79/7A HDMI", .patch = patch_nvhdmi_8ch_7x },
Stephen Warren5d44f922011-05-24 17:11:17 -06002858{ .id = 0x10de000a, .name = "GPU 0a HDMI/DP", .patch = patch_generic_hdmi },
2859{ .id = 0x10de000b, .name = "GPU 0b HDMI/DP", .patch = patch_generic_hdmi },
2860{ .id = 0x10de000c, .name = "MCP89 HDMI", .patch = patch_generic_hdmi },
2861{ .id = 0x10de000d, .name = "GPU 0d HDMI/DP", .patch = patch_generic_hdmi },
2862{ .id = 0x10de0010, .name = "GPU 10 HDMI/DP", .patch = patch_generic_hdmi },
2863{ .id = 0x10de0011, .name = "GPU 11 HDMI/DP", .patch = patch_generic_hdmi },
2864{ .id = 0x10de0012, .name = "GPU 12 HDMI/DP", .patch = patch_generic_hdmi },
2865{ .id = 0x10de0013, .name = "GPU 13 HDMI/DP", .patch = patch_generic_hdmi },
2866{ .id = 0x10de0014, .name = "GPU 14 HDMI/DP", .patch = patch_generic_hdmi },
2867{ .id = 0x10de0015, .name = "GPU 15 HDMI/DP", .patch = patch_generic_hdmi },
2868{ .id = 0x10de0016, .name = "GPU 16 HDMI/DP", .patch = patch_generic_hdmi },
Richard Samsonc8900a02011-03-03 12:46:13 +01002869/* 17 is known to be absent */
Stephen Warren5d44f922011-05-24 17:11:17 -06002870{ .id = 0x10de0018, .name = "GPU 18 HDMI/DP", .patch = patch_generic_hdmi },
2871{ .id = 0x10de0019, .name = "GPU 19 HDMI/DP", .patch = patch_generic_hdmi },
2872{ .id = 0x10de001a, .name = "GPU 1a HDMI/DP", .patch = patch_generic_hdmi },
2873{ .id = 0x10de001b, .name = "GPU 1b HDMI/DP", .patch = patch_generic_hdmi },
2874{ .id = 0x10de001c, .name = "GPU 1c HDMI/DP", .patch = patch_generic_hdmi },
2875{ .id = 0x10de0040, .name = "GPU 40 HDMI/DP", .patch = patch_generic_hdmi },
2876{ .id = 0x10de0041, .name = "GPU 41 HDMI/DP", .patch = patch_generic_hdmi },
2877{ .id = 0x10de0042, .name = "GPU 42 HDMI/DP", .patch = patch_generic_hdmi },
2878{ .id = 0x10de0043, .name = "GPU 43 HDMI/DP", .patch = patch_generic_hdmi },
2879{ .id = 0x10de0044, .name = "GPU 44 HDMI/DP", .patch = patch_generic_hdmi },
Aaron Plattner7ae48b52012-07-16 17:10:04 -07002880{ .id = 0x10de0051, .name = "GPU 51 HDMI/DP", .patch = patch_generic_hdmi },
Aaron Plattnerd52392b2013-07-12 11:01:37 -07002881{ .id = 0x10de0060, .name = "GPU 60 HDMI/DP", .patch = patch_generic_hdmi },
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002882{ .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch },
2883{ .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch },
Annie Liu3de5ff82012-06-08 19:18:42 +08002884{ .id = 0x11069f80, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi },
2885{ .id = 0x11069f81, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi },
2886{ .id = 0x11069f84, .name = "VX11 HDMI/DP", .patch = patch_generic_hdmi },
2887{ .id = 0x11069f85, .name = "VX11 HDMI/DP", .patch = patch_generic_hdmi },
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002888{ .id = 0x80860054, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi },
2889{ .id = 0x80862801, .name = "Bearlake HDMI", .patch = patch_generic_hdmi },
2890{ .id = 0x80862802, .name = "Cantiga HDMI", .patch = patch_generic_hdmi },
2891{ .id = 0x80862803, .name = "Eaglelake HDMI", .patch = patch_generic_hdmi },
2892{ .id = 0x80862804, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi },
2893{ .id = 0x80862805, .name = "CougarPoint HDMI", .patch = patch_generic_hdmi },
Wu Fengguang591e6102011-05-20 15:35:43 +08002894{ .id = 0x80862806, .name = "PantherPoint HDMI", .patch = patch_generic_hdmi },
Wang Xingchao1c766842012-06-13 10:23:52 +08002895{ .id = 0x80862807, .name = "Haswell HDMI", .patch = patch_generic_hdmi },
Wu Fengguang6edc59e2012-02-23 15:07:44 +08002896{ .id = 0x80862880, .name = "CedarTrail HDMI", .patch = patch_generic_hdmi },
Mengdong Lincc1a95d2013-10-20 23:03:31 -04002897{ .id = 0x80862882, .name = "Valleyview2 HDMI", .patch = patch_generic_hdmi },
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002898{ .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi },
2899{} /* terminator */
2900};
2901
2902MODULE_ALIAS("snd-hda-codec-id:1002793c");
2903MODULE_ALIAS("snd-hda-codec-id:10027919");
2904MODULE_ALIAS("snd-hda-codec-id:1002791a");
2905MODULE_ALIAS("snd-hda-codec-id:1002aa01");
2906MODULE_ALIAS("snd-hda-codec-id:10951390");
2907MODULE_ALIAS("snd-hda-codec-id:10951392");
2908MODULE_ALIAS("snd-hda-codec-id:10de0002");
2909MODULE_ALIAS("snd-hda-codec-id:10de0003");
2910MODULE_ALIAS("snd-hda-codec-id:10de0005");
2911MODULE_ALIAS("snd-hda-codec-id:10de0006");
2912MODULE_ALIAS("snd-hda-codec-id:10de0007");
2913MODULE_ALIAS("snd-hda-codec-id:10de000a");
2914MODULE_ALIAS("snd-hda-codec-id:10de000b");
2915MODULE_ALIAS("snd-hda-codec-id:10de000c");
2916MODULE_ALIAS("snd-hda-codec-id:10de000d");
2917MODULE_ALIAS("snd-hda-codec-id:10de0010");
2918MODULE_ALIAS("snd-hda-codec-id:10de0011");
2919MODULE_ALIAS("snd-hda-codec-id:10de0012");
2920MODULE_ALIAS("snd-hda-codec-id:10de0013");
2921MODULE_ALIAS("snd-hda-codec-id:10de0014");
Richard Samsonc8900a02011-03-03 12:46:13 +01002922MODULE_ALIAS("snd-hda-codec-id:10de0015");
2923MODULE_ALIAS("snd-hda-codec-id:10de0016");
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002924MODULE_ALIAS("snd-hda-codec-id:10de0018");
2925MODULE_ALIAS("snd-hda-codec-id:10de0019");
2926MODULE_ALIAS("snd-hda-codec-id:10de001a");
2927MODULE_ALIAS("snd-hda-codec-id:10de001b");
2928MODULE_ALIAS("snd-hda-codec-id:10de001c");
2929MODULE_ALIAS("snd-hda-codec-id:10de0040");
2930MODULE_ALIAS("snd-hda-codec-id:10de0041");
2931MODULE_ALIAS("snd-hda-codec-id:10de0042");
2932MODULE_ALIAS("snd-hda-codec-id:10de0043");
2933MODULE_ALIAS("snd-hda-codec-id:10de0044");
Aaron Plattner7ae48b52012-07-16 17:10:04 -07002934MODULE_ALIAS("snd-hda-codec-id:10de0051");
Aaron Plattnerd52392b2013-07-12 11:01:37 -07002935MODULE_ALIAS("snd-hda-codec-id:10de0060");
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002936MODULE_ALIAS("snd-hda-codec-id:10de0067");
2937MODULE_ALIAS("snd-hda-codec-id:10de8001");
Annie Liu3de5ff82012-06-08 19:18:42 +08002938MODULE_ALIAS("snd-hda-codec-id:11069f80");
2939MODULE_ALIAS("snd-hda-codec-id:11069f81");
2940MODULE_ALIAS("snd-hda-codec-id:11069f84");
2941MODULE_ALIAS("snd-hda-codec-id:11069f85");
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002942MODULE_ALIAS("snd-hda-codec-id:17e80047");
2943MODULE_ALIAS("snd-hda-codec-id:80860054");
2944MODULE_ALIAS("snd-hda-codec-id:80862801");
2945MODULE_ALIAS("snd-hda-codec-id:80862802");
2946MODULE_ALIAS("snd-hda-codec-id:80862803");
2947MODULE_ALIAS("snd-hda-codec-id:80862804");
2948MODULE_ALIAS("snd-hda-codec-id:80862805");
Wu Fengguang591e6102011-05-20 15:35:43 +08002949MODULE_ALIAS("snd-hda-codec-id:80862806");
Wang Xingchao1c766842012-06-13 10:23:52 +08002950MODULE_ALIAS("snd-hda-codec-id:80862807");
Wu Fengguang6edc59e2012-02-23 15:07:44 +08002951MODULE_ALIAS("snd-hda-codec-id:80862880");
Mengdong Lincc1a95d2013-10-20 23:03:31 -04002952MODULE_ALIAS("snd-hda-codec-id:80862882");
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002953MODULE_ALIAS("snd-hda-codec-id:808629fb");
2954
2955MODULE_LICENSE("GPL");
2956MODULE_DESCRIPTION("HDMI HD-audio codec");
2957MODULE_ALIAS("snd-hda-codec-intelhdmi");
2958MODULE_ALIAS("snd-hda-codec-nvhdmi");
2959MODULE_ALIAS("snd-hda-codec-atihdmi");
2960
2961static struct hda_codec_preset_list intel_list = {
2962 .preset = snd_hda_preset_hdmi,
2963 .owner = THIS_MODULE,
2964};
2965
2966static int __init patch_hdmi_init(void)
2967{
2968 return snd_hda_add_codec_preset(&intel_list);
2969}
2970
2971static void __exit patch_hdmi_exit(void)
2972{
2973 snd_hda_delete_codec_preset(&intel_list);
2974}
2975
2976module_init(patch_hdmi_init)
2977module_exit(patch_hdmi_exit)