blob: aa7bd3f581296d3ce03cb753109ca1b568424ba3 [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>
Anssi Hannula5a6135842013-10-24 21:10:35 +03009 * Copyright (c) 2013 Anssi Hannula <anssi.hannula@iki.fi>
Wu Fengguang079d88c2010-03-08 10:44:23 +080010 *
11 * Authors:
12 * Wu Fengguang <wfg@linux.intel.com>
13 *
14 * Maintained by:
15 * Wu Fengguang <wfg@linux.intel.com>
16 *
17 * This program is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License as published by the Free
19 * Software Foundation; either version 2 of the License, or (at your option)
20 * any later version.
21 *
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 * for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software Foundation,
29 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 */
31
Takashi Iwai84eb01b2010-09-07 12:27:25 +020032#include <linux/init.h>
33#include <linux/delay.h>
34#include <linux/slab.h>
Paul Gortmaker65a77212011-07-15 13:13:37 -040035#include <linux/module.h>
Takashi Iwai84eb01b2010-09-07 12:27:25 +020036#include <sound/core.h>
David Henningsson07acecc2011-05-19 11:46:03 +020037#include <sound/jack.h>
Wang Xingchao433968d2012-09-06 10:02:37 +080038#include <sound/asoundef.h>
Takashi Iwaid45e6882012-07-31 11:36:00 +020039#include <sound/tlv.h>
David Henningsson25adc132015-08-19 10:48:58 +020040#include <sound/hdaudio.h>
41#include <sound/hda_i915.h>
Takashi Iwai84eb01b2010-09-07 12:27:25 +020042#include "hda_codec.h"
43#include "hda_local.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020044#include "hda_jack.h"
Takashi Iwai84eb01b2010-09-07 12:27:25 +020045
Takashi Iwai0ebaa242011-01-11 18:11:04 +010046static bool static_hdmi_pcm;
47module_param(static_hdmi_pcm, bool, 0644);
48MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
49
Takashi Iwai7639a062015-03-03 10:07:24 +010050#define is_haswell(codec) ((codec)->core.vendor_id == 0x80862807)
51#define is_broadwell(codec) ((codec)->core.vendor_id == 0x80862808)
52#define is_skylake(codec) ((codec)->core.vendor_id == 0x80862809)
Lu, Hane2656412015-11-11 16:54:27 +080053#define is_broxton(codec) ((codec)->core.vendor_id == 0x8086280a)
Libin Yang91815d82016-01-14 14:09:00 +080054#define is_kabylake(codec) ((codec)->core.vendor_id == 0x8086280b)
Libin Yang432ac1a2014-12-16 13:17:34 +080055#define is_haswell_plus(codec) (is_haswell(codec) || is_broadwell(codec) \
Libin Yang91815d82016-01-14 14:09:00 +080056 || is_skylake(codec) || is_broxton(codec) \
57 || is_kabylake(codec))
Mengdong Lin75dcbe42014-01-08 15:55:32 -050058
Takashi Iwai7639a062015-03-03 10:07:24 +010059#define is_valleyview(codec) ((codec)->core.vendor_id == 0x80862882)
60#define is_cherryview(codec) ((codec)->core.vendor_id == 0x80862883)
Libin Yangca2e7222014-08-19 16:20:12 +080061#define is_valleyview_plus(codec) (is_valleyview(codec) || is_cherryview(codec))
Mengdong Linfb87fa32013-09-04 16:36:57 -040062
Stephen Warren384a48d2011-06-01 11:14:21 -060063struct hdmi_spec_per_cvt {
64 hda_nid_t cvt_nid;
65 int assigned;
66 unsigned int channels_min;
67 unsigned int channels_max;
68 u32 rates;
69 u64 formats;
70 unsigned int maxbps;
71};
72
Takashi Iwai4eea3092013-02-07 18:18:19 +010073/* max. connections to a widget */
74#define HDA_MAX_CONNECTIONS 32
75
Stephen Warren384a48d2011-06-01 11:14:21 -060076struct hdmi_spec_per_pin {
77 hda_nid_t pin_nid;
78 int num_mux_nids;
79 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
Mengdong Lin2df67422014-03-20 13:01:06 +080080 int mux_idx;
Anssi Hannula1df5a062013-10-05 02:25:40 +030081 hda_nid_t cvt_nid;
Wu Fengguang744626d2011-11-16 16:29:47 +080082
83 struct hda_codec *codec;
Stephen Warren384a48d2011-06-01 11:14:21 -060084 struct hdmi_eld sink_eld;
Takashi Iwaia4e9a382013-10-17 18:21:12 +020085 struct mutex lock;
Wu Fengguang744626d2011-11-16 16:29:47 +080086 struct delayed_work work;
David Henningsson92c69e72013-02-19 16:11:26 +010087 struct snd_kcontrol *eld_ctl;
Takashi Iwai788d4412015-11-12 15:36:13 +010088 struct snd_jack *acomp_jack; /* jack via audio component */
Libin Yang6590faa2015-12-16 13:42:41 +080089 struct hda_pcm *pcm; /* pointer to spec->pcm_rec[n] dynamically*/
Wu Fengguangc6e84532011-11-18 16:59:32 -060090 int repoll_count;
Takashi Iwaib0540872013-09-02 12:33:02 +020091 bool setup; /* the stream has been set up by prepare callback */
92 int channels; /* current number of channels */
Takashi Iwai1a6003b2012-09-06 17:42:08 +020093 bool non_pcm;
Takashi Iwaid45e6882012-07-31 11:36:00 +020094 bool chmap_set; /* channel-map override by ALSA API? */
95 unsigned char chmap[8]; /* ALSA API channel-map */
Jie Yangcd6a6502015-05-27 19:45:45 +080096#ifdef CONFIG_SND_PROC_FS
Takashi Iwaia4e9a382013-10-17 18:21:12 +020097 struct snd_info_entry *proc_entry;
98#endif
Stephen Warren384a48d2011-06-01 11:14:21 -060099};
100
Anssi Hannula307229d2013-10-24 21:10:34 +0300101struct cea_channel_speaker_allocation;
102
103/* operations used by generic code that can be overridden by patches */
104struct hdmi_ops {
105 int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid,
106 unsigned char *buf, int *eld_size);
107
108 /* get and set channel assigned to each HDMI ASP (audio sample packet) slot */
109 int (*pin_get_slot_channel)(struct hda_codec *codec, hda_nid_t pin_nid,
110 int asp_slot);
111 int (*pin_set_slot_channel)(struct hda_codec *codec, hda_nid_t pin_nid,
112 int asp_slot, int channel);
113
114 void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid,
115 int ca, int active_channels, int conn_type);
116
117 /* enable/disable HBR (HD passthrough) */
118 int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid, bool hbr);
119
120 int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid,
121 hda_nid_t pin_nid, u32 stream_tag, int format);
122
123 /* Helpers for producing the channel map TLVs. These can be overridden
124 * for devices that have non-standard mapping requirements. */
125 int (*chmap_cea_alloc_validate_get_type)(struct cea_channel_speaker_allocation *cap,
126 int channels);
127 void (*cea_alloc_to_tlv_chmap)(struct cea_channel_speaker_allocation *cap,
128 unsigned int *chmap, int channels);
129
130 /* check that the user-given chmap is supported */
131 int (*chmap_validate)(int ca, int channels, unsigned char *chmap);
132};
133
Wu Fengguang079d88c2010-03-08 10:44:23 +0800134struct hdmi_spec {
135 int num_cvts;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100136 struct snd_array cvts; /* struct hdmi_spec_per_cvt */
137 hda_nid_t cvt_nids[4]; /* only for haswell fix */
Stephen Warren384a48d2011-06-01 11:14:21 -0600138
Wu Fengguang079d88c2010-03-08 10:44:23 +0800139 int num_pins;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100140 struct snd_array pins; /* struct hdmi_spec_per_pin */
Takashi Iwaibbbc7e82015-02-27 17:43:19 +0100141 struct hda_pcm *pcm_rec[16];
Takashi Iwaid45e6882012-07-31 11:36:00 +0200142 unsigned int channels_max; /* max over all cvts */
Wu Fengguang079d88c2010-03-08 10:44:23 +0800143
David Henningsson4bd038f2013-02-19 16:11:25 +0100144 struct hdmi_eld temp_eld;
Anssi Hannula307229d2013-10-24 21:10:34 +0300145 struct hdmi_ops ops;
Stephen Warren75fae112014-01-30 11:52:16 -0700146
147 bool dyn_pin_out;
Libin Yang6590faa2015-12-16 13:42:41 +0800148 bool dyn_pcm_assign;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800149 /*
Anssi Hannula5a6135842013-10-24 21:10:35 +0300150 * Non-generic VIA/NVIDIA specific
Wu Fengguang079d88c2010-03-08 10:44:23 +0800151 */
152 struct hda_multi_out multiout;
Takashi Iwaid0b12522012-06-15 14:34:42 +0200153 struct hda_pcm_stream pcm_playback;
David Henningsson25adc132015-08-19 10:48:58 +0200154
155 /* i915/powerwell (Haswell+/Valleyview+) specific */
156 struct i915_audio_component_audio_ops i915_audio_ops;
Takashi Iwai55913112015-12-10 13:03:29 +0100157 bool i915_bound; /* was i915 bound in this driver? */
Wu Fengguang079d88c2010-03-08 10:44:23 +0800158};
159
Takashi Iwaif4e30402015-12-10 13:01:28 +0100160#ifdef CONFIG_SND_HDA_I915
Takashi Iwai66032492015-12-01 16:49:35 +0100161#define codec_has_acomp(codec) \
162 ((codec)->bus->core.audio_component != NULL)
Takashi Iwaif4e30402015-12-10 13:01:28 +0100163#else
164#define codec_has_acomp(codec) false
165#endif
Wu Fengguang079d88c2010-03-08 10:44:23 +0800166
167struct hdmi_audio_infoframe {
168 u8 type; /* 0x84 */
169 u8 ver; /* 0x01 */
170 u8 len; /* 0x0a */
171
Wu Fengguang53d7d692010-09-21 14:25:49 +0800172 u8 checksum;
173
Wu Fengguang079d88c2010-03-08 10:44:23 +0800174 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
175 u8 SS01_SF24;
176 u8 CXT04;
177 u8 CA;
178 u8 LFEPBL01_LSV36_DM_INH7;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800179};
180
181struct dp_audio_infoframe {
182 u8 type; /* 0x84 */
183 u8 len; /* 0x1b */
184 u8 ver; /* 0x11 << 2 */
185
186 u8 CC02_CT47; /* match with HDMI infoframe from this on */
187 u8 SS01_SF24;
188 u8 CXT04;
189 u8 CA;
190 u8 LFEPBL01_LSV36_DM_INH7;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800191};
192
Takashi Iwai2b203dbb2011-02-11 12:17:30 +0100193union audio_infoframe {
194 struct hdmi_audio_infoframe hdmi;
195 struct dp_audio_infoframe dp;
196 u8 bytes[0];
197};
198
Wu Fengguang079d88c2010-03-08 10:44:23 +0800199/*
200 * CEA speaker placement:
201 *
202 * FLH FCH FRH
203 * FLW FL FLC FC FRC FR FRW
204 *
205 * LFE
206 * TC
207 *
208 * RL RLC RC RRC RR
209 *
210 * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
211 * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
212 */
213enum cea_speaker_placement {
214 FL = (1 << 0), /* Front Left */
215 FC = (1 << 1), /* Front Center */
216 FR = (1 << 2), /* Front Right */
217 FLC = (1 << 3), /* Front Left Center */
218 FRC = (1 << 4), /* Front Right Center */
219 RL = (1 << 5), /* Rear Left */
220 RC = (1 << 6), /* Rear Center */
221 RR = (1 << 7), /* Rear Right */
222 RLC = (1 << 8), /* Rear Left Center */
223 RRC = (1 << 9), /* Rear Right Center */
224 LFE = (1 << 10), /* Low Frequency Effect */
225 FLW = (1 << 11), /* Front Left Wide */
226 FRW = (1 << 12), /* Front Right Wide */
227 FLH = (1 << 13), /* Front Left High */
228 FCH = (1 << 14), /* Front Center High */
229 FRH = (1 << 15), /* Front Right High */
230 TC = (1 << 16), /* Top Center */
231};
232
233/*
234 * ELD SA bits in the CEA Speaker Allocation data block
235 */
236static int eld_speaker_allocation_bits[] = {
237 [0] = FL | FR,
238 [1] = LFE,
239 [2] = FC,
240 [3] = RL | RR,
241 [4] = RC,
242 [5] = FLC | FRC,
243 [6] = RLC | RRC,
244 /* the following are not defined in ELD yet */
245 [7] = FLW | FRW,
246 [8] = FLH | FRH,
247 [9] = TC,
248 [10] = FCH,
249};
250
251struct cea_channel_speaker_allocation {
252 int ca_index;
253 int speakers[8];
254
255 /* derived values, just for convenience */
256 int channels;
257 int spk_mask;
258};
259
260/*
261 * ALSA sequence is:
262 *
263 * surround40 surround41 surround50 surround51 surround71
264 * ch0 front left = = = =
265 * ch1 front right = = = =
266 * ch2 rear left = = = =
267 * ch3 rear right = = = =
268 * ch4 LFE center center center
269 * ch5 LFE LFE
270 * ch6 side left
271 * ch7 side right
272 *
273 * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR}
274 */
275static int hdmi_channel_mapping[0x32][8] = {
276 /* stereo */
277 [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
278 /* 2.1 */
279 [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
280 /* Dolby Surround */
281 [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 },
282 /* surround40 */
283 [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 },
284 /* 4ch */
285 [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 },
286 /* surround41 */
Jerry Zhou9396d312010-09-21 14:44:51 +0800287 [0x09] = { 0x00, 0x11, 0x24, 0x35, 0x42, 0xf3, 0xf6, 0xf7 },
Wu Fengguang079d88c2010-03-08 10:44:23 +0800288 /* surround50 */
289 [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 },
290 /* surround51 */
291 [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 },
292 /* 7.1 */
293 [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 },
294};
295
296/*
297 * This is an ordered list!
298 *
299 * The preceding ones have better chances to be selected by
Wu Fengguang53d7d692010-09-21 14:25:49 +0800300 * hdmi_channel_allocation().
Wu Fengguang079d88c2010-03-08 10:44:23 +0800301 */
302static struct cea_channel_speaker_allocation channel_allocations[] = {
303/* channel: 7 6 5 4 3 2 1 0 */
304{ .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
305 /* 2.1 */
306{ .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
307 /* Dolby Surround */
308{ .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
309 /* surround40 */
310{ .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
311 /* surround41 */
312{ .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
313 /* surround50 */
314{ .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
315 /* surround51 */
316{ .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
317 /* 6.1 */
318{ .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
319 /* surround71 */
320{ .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
321
322{ .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
323{ .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
324{ .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
325{ .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
326{ .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
327{ .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
328{ .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
329{ .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
330{ .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
331{ .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
332{ .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
333{ .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
334{ .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
335{ .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
336{ .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
337{ .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
338{ .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
339{ .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
340{ .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
341{ .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
342{ .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
343{ .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
344{ .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
345{ .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } },
346{ .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } },
347{ .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } },
348{ .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } },
349{ .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } },
350{ .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } },
351{ .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } },
352{ .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } },
353{ .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } },
354{ .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } },
355{ .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } },
356{ .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } },
357{ .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } },
358{ .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } },
359{ .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } },
360{ .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } },
361{ .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } },
362{ .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
363};
364
365
366/*
367 * HDMI routines
368 */
369
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100370#define get_pin(spec, idx) \
371 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx))
372#define get_cvt(spec, idx) \
373 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx))
Takashi Iwaibbbc7e82015-02-27 17:43:19 +0100374#define get_pcm_rec(spec, idx) ((spec)->pcm_rec[idx])
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100375
Takashi Iwai4e76a882014-02-25 12:21:03 +0100376static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800377{
Takashi Iwai4e76a882014-02-25 12:21:03 +0100378 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -0600379 int pin_idx;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800380
Stephen Warren384a48d2011-06-01 11:14:21 -0600381 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100382 if (get_pin(spec, pin_idx)->pin_nid == pin_nid)
Stephen Warren384a48d2011-06-01 11:14:21 -0600383 return pin_idx;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800384
Takashi Iwai4e76a882014-02-25 12:21:03 +0100385 codec_warn(codec, "HDMI: pin nid %d not registered\n", pin_nid);
Stephen Warren384a48d2011-06-01 11:14:21 -0600386 return -EINVAL;
387}
388
Takashi Iwai4e76a882014-02-25 12:21:03 +0100389static int hinfo_to_pin_index(struct hda_codec *codec,
Stephen Warren384a48d2011-06-01 11:14:21 -0600390 struct hda_pcm_stream *hinfo)
391{
Takashi Iwai4e76a882014-02-25 12:21:03 +0100392 struct hdmi_spec *spec = codec->spec;
Libin Yang6590faa2015-12-16 13:42:41 +0800393 struct hdmi_spec_per_pin *per_pin;
Stephen Warren384a48d2011-06-01 11:14:21 -0600394 int pin_idx;
395
Libin Yang6590faa2015-12-16 13:42:41 +0800396 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
397 per_pin = get_pin(spec, pin_idx);
398 if (per_pin->pcm && per_pin->pcm->stream == hinfo)
Stephen Warren384a48d2011-06-01 11:14:21 -0600399 return pin_idx;
Libin Yang6590faa2015-12-16 13:42:41 +0800400 }
Stephen Warren384a48d2011-06-01 11:14:21 -0600401
Libin Yang6590faa2015-12-16 13:42:41 +0800402 codec_dbg(codec, "HDMI: hinfo %p not registered\n", hinfo);
Stephen Warren384a48d2011-06-01 11:14:21 -0600403 return -EINVAL;
404}
405
Takashi Iwai4e76a882014-02-25 12:21:03 +0100406static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid)
Stephen Warren384a48d2011-06-01 11:14:21 -0600407{
Takashi Iwai4e76a882014-02-25 12:21:03 +0100408 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -0600409 int cvt_idx;
410
411 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100412 if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid)
Stephen Warren384a48d2011-06-01 11:14:21 -0600413 return cvt_idx;
414
Takashi Iwai4e76a882014-02-25 12:21:03 +0100415 codec_warn(codec, "HDMI: cvt nid %d not registered\n", cvt_nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800416 return -EINVAL;
417}
418
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500419static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
420 struct snd_ctl_elem_info *uinfo)
421{
422 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
David Henningsson68e03de2013-02-19 16:11:23 +0100423 struct hdmi_spec *spec = codec->spec;
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200424 struct hdmi_spec_per_pin *per_pin;
David Henningsson68e03de2013-02-19 16:11:23 +0100425 struct hdmi_eld *eld;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500426 int pin_idx;
427
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500428 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
429
430 pin_idx = kcontrol->private_value;
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200431 per_pin = get_pin(spec, pin_idx);
432 eld = &per_pin->sink_eld;
David Henningsson68e03de2013-02-19 16:11:23 +0100433
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200434 mutex_lock(&per_pin->lock);
David Henningsson68e03de2013-02-19 16:11:23 +0100435 uinfo->count = eld->eld_valid ? eld->eld_size : 0;
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200436 mutex_unlock(&per_pin->lock);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500437
438 return 0;
439}
440
441static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
442 struct snd_ctl_elem_value *ucontrol)
443{
444 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
David Henningsson68e03de2013-02-19 16:11:23 +0100445 struct hdmi_spec *spec = codec->spec;
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200446 struct hdmi_spec_per_pin *per_pin;
David Henningsson68e03de2013-02-19 16:11:23 +0100447 struct hdmi_eld *eld;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500448 int pin_idx;
449
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500450 pin_idx = kcontrol->private_value;
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200451 per_pin = get_pin(spec, pin_idx);
452 eld = &per_pin->sink_eld;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500453
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200454 mutex_lock(&per_pin->lock);
David Henningsson68e03de2013-02-19 16:11:23 +0100455 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data)) {
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200456 mutex_unlock(&per_pin->lock);
David Henningsson68e03de2013-02-19 16:11:23 +0100457 snd_BUG();
458 return -EINVAL;
459 }
460
461 memset(ucontrol->value.bytes.data, 0,
462 ARRAY_SIZE(ucontrol->value.bytes.data));
463 if (eld->eld_valid)
464 memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
465 eld->eld_size);
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200466 mutex_unlock(&per_pin->lock);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500467
468 return 0;
469}
470
471static struct snd_kcontrol_new eld_bytes_ctl = {
472 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
473 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
474 .name = "ELD",
475 .info = hdmi_eld_ctl_info,
476 .get = hdmi_eld_ctl_get,
477};
478
479static int hdmi_create_eld_ctl(struct hda_codec *codec, int pin_idx,
480 int device)
481{
482 struct snd_kcontrol *kctl;
483 struct hdmi_spec *spec = codec->spec;
484 int err;
485
486 kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
487 if (!kctl)
488 return -ENOMEM;
489 kctl->private_value = pin_idx;
490 kctl->id.device = device;
491
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100492 err = snd_hda_ctl_add(codec, get_pin(spec, pin_idx)->pin_nid, kctl);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500493 if (err < 0)
494 return err;
495
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100496 get_pin(spec, pin_idx)->eld_ctl = kctl;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500497 return 0;
498}
499
Wu Fengguang079d88c2010-03-08 10:44:23 +0800500#ifdef BE_PARANOID
501static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
502 int *packet_index, int *byte_index)
503{
504 int val;
505
506 val = snd_hda_codec_read(codec, pin_nid, 0,
507 AC_VERB_GET_HDMI_DIP_INDEX, 0);
508
509 *packet_index = val >> 5;
510 *byte_index = val & 0x1f;
511}
512#endif
513
514static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
515 int packet_index, int byte_index)
516{
517 int val;
518
519 val = (packet_index << 5) | (byte_index & 0x1f);
520
521 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
522}
523
524static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
525 unsigned char val)
526{
527 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
528}
529
Stephen Warren384a48d2011-06-01 11:14:21 -0600530static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800531{
Stephen Warren75fae112014-01-30 11:52:16 -0700532 struct hdmi_spec *spec = codec->spec;
533 int pin_out;
534
Wu Fengguang079d88c2010-03-08 10:44:23 +0800535 /* Unmute */
536 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
537 snd_hda_codec_write(codec, pin_nid, 0,
538 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
Stephen Warren75fae112014-01-30 11:52:16 -0700539
540 if (spec->dyn_pin_out)
541 /* Disable pin out until stream is active */
542 pin_out = 0;
543 else
544 /* Enable pin out: some machines with GM965 gets broken output
545 * when the pin is disabled or changed while using with HDMI
546 */
547 pin_out = PIN_OUT;
548
Wu Fengguang079d88c2010-03-08 10:44:23 +0800549 snd_hda_codec_write(codec, pin_nid, 0,
Stephen Warren75fae112014-01-30 11:52:16 -0700550 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_out);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800551}
552
Stephen Warren384a48d2011-06-01 11:14:21 -0600553static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800554{
Stephen Warren384a48d2011-06-01 11:14:21 -0600555 return 1 + snd_hda_codec_read(codec, cvt_nid, 0,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800556 AC_VERB_GET_CVT_CHAN_COUNT, 0);
557}
558
559static void hdmi_set_channel_count(struct hda_codec *codec,
Stephen Warren384a48d2011-06-01 11:14:21 -0600560 hda_nid_t cvt_nid, int chs)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800561{
Stephen Warren384a48d2011-06-01 11:14:21 -0600562 if (chs != hdmi_get_channel_count(codec, cvt_nid))
563 snd_hda_codec_write(codec, cvt_nid, 0,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800564 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
565}
566
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200567/*
568 * ELD proc files
569 */
570
Jie Yangcd6a6502015-05-27 19:45:45 +0800571#ifdef CONFIG_SND_PROC_FS
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200572static void print_eld_info(struct snd_info_entry *entry,
573 struct snd_info_buffer *buffer)
574{
575 struct hdmi_spec_per_pin *per_pin = entry->private_data;
576
577 mutex_lock(&per_pin->lock);
578 snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer);
579 mutex_unlock(&per_pin->lock);
580}
581
582static void write_eld_info(struct snd_info_entry *entry,
583 struct snd_info_buffer *buffer)
584{
585 struct hdmi_spec_per_pin *per_pin = entry->private_data;
586
587 mutex_lock(&per_pin->lock);
588 snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer);
589 mutex_unlock(&per_pin->lock);
590}
591
592static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
593{
594 char name[32];
595 struct hda_codec *codec = per_pin->codec;
596 struct snd_info_entry *entry;
597 int err;
598
599 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
Takashi Iwai6efdd852015-02-27 16:09:22 +0100600 err = snd_card_proc_new(codec->card, name, &entry);
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200601 if (err < 0)
602 return err;
603
604 snd_info_set_text_ops(entry, per_pin, print_eld_info);
605 entry->c.text.write = write_eld_info;
606 entry->mode |= S_IWUSR;
607 per_pin->proc_entry = entry;
608
609 return 0;
610}
611
612static void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
613{
Markus Elfring1947a112015-06-28 11:15:28 +0200614 if (!per_pin->codec->bus->shutdown) {
Takashi Iwaic560a672015-04-22 18:26:38 +0200615 snd_info_free_entry(per_pin->proc_entry);
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200616 per_pin->proc_entry = NULL;
617 }
618}
619#else
Takashi Iwaib55447a2013-10-21 16:31:45 +0200620static inline int eld_proc_new(struct hdmi_spec_per_pin *per_pin,
621 int index)
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200622{
623 return 0;
624}
Takashi Iwaib55447a2013-10-21 16:31:45 +0200625static inline void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200626{
627}
628#endif
Wu Fengguang079d88c2010-03-08 10:44:23 +0800629
630/*
631 * Channel mapping routines
632 */
633
634/*
635 * Compute derived values in channel_allocations[].
636 */
637static void init_channel_allocations(void)
638{
639 int i, j;
640 struct cea_channel_speaker_allocation *p;
641
642 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
643 p = channel_allocations + i;
644 p->channels = 0;
645 p->spk_mask = 0;
646 for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
647 if (p->speakers[j]) {
648 p->channels++;
649 p->spk_mask |= p->speakers[j];
650 }
651 }
652}
653
Wang Xingchao72357c72012-09-06 10:02:36 +0800654static int get_channel_allocation_order(int ca)
655{
656 int i;
657
658 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
659 if (channel_allocations[i].ca_index == ca)
660 break;
661 }
662 return i;
663}
664
Wu Fengguang079d88c2010-03-08 10:44:23 +0800665/*
666 * The transformation takes two steps:
667 *
668 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
669 * spk_mask => (channel_allocations[]) => ai->CA
670 *
671 * TODO: it could select the wrong CA from multiple candidates.
672*/
Takashi Iwai79514d42014-06-06 18:04:34 +0200673static int hdmi_channel_allocation(struct hda_codec *codec,
674 struct hdmi_eld *eld, int channels)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800675{
Wu Fengguang079d88c2010-03-08 10:44:23 +0800676 int i;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800677 int ca = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800678 int spk_mask = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800679 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
680
681 /*
682 * CA defaults to 0 for basic stereo audio
683 */
684 if (channels <= 2)
685 return 0;
686
Wu Fengguang079d88c2010-03-08 10:44:23 +0800687 /*
688 * expand ELD's speaker allocation mask
689 *
690 * ELD tells the speaker mask in a compact(paired) form,
691 * expand ELD's notions to match the ones used by Audio InfoFrame.
692 */
693 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
David Henningsson1613d6b2013-02-19 16:11:24 +0100694 if (eld->info.spk_alloc & (1 << i))
Wu Fengguang079d88c2010-03-08 10:44:23 +0800695 spk_mask |= eld_speaker_allocation_bits[i];
696 }
697
698 /* search for the first working match in the CA table */
699 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
700 if (channels == channel_allocations[i].channels &&
701 (spk_mask & channel_allocations[i].spk_mask) ==
702 channel_allocations[i].spk_mask) {
Wu Fengguang53d7d692010-09-21 14:25:49 +0800703 ca = channel_allocations[i].ca_index;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800704 break;
705 }
706 }
707
Anssi Hannula18e39182013-09-01 14:36:47 +0300708 if (!ca) {
709 /* if there was no match, select the regular ALSA channel
710 * allocation with the matching number of channels */
711 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
712 if (channels == channel_allocations[i].channels) {
713 ca = channel_allocations[i].ca_index;
714 break;
715 }
716 }
717 }
718
David Henningsson1613d6b2013-02-19 16:11:24 +0100719 snd_print_channel_allocation(eld->info.spk_alloc, buf, sizeof(buf));
Takashi Iwai79514d42014-06-06 18:04:34 +0200720 codec_dbg(codec, "HDMI: select CA 0x%x for %d-channel allocation: %s\n",
Wu Fengguang53d7d692010-09-21 14:25:49 +0800721 ca, channels, buf);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800722
Wu Fengguang53d7d692010-09-21 14:25:49 +0800723 return ca;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800724}
725
726static void hdmi_debug_channel_mapping(struct hda_codec *codec,
727 hda_nid_t pin_nid)
728{
729#ifdef CONFIG_SND_DEBUG_VERBOSE
Anssi Hannula307229d2013-10-24 21:10:34 +0300730 struct hdmi_spec *spec = codec->spec;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800731 int i;
Anssi Hannula307229d2013-10-24 21:10:34 +0300732 int channel;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800733
734 for (i = 0; i < 8; i++) {
Anssi Hannula307229d2013-10-24 21:10:34 +0300735 channel = spec->ops.pin_get_slot_channel(codec, pin_nid, i);
Takashi Iwai4e76a882014-02-25 12:21:03 +0100736 codec_dbg(codec, "HDMI: ASP channel %d => slot %d\n",
Anssi Hannula307229d2013-10-24 21:10:34 +0300737 channel, i);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800738 }
739#endif
740}
741
Takashi Iwaid45e6882012-07-31 11:36:00 +0200742static void hdmi_std_setup_channel_mapping(struct hda_codec *codec,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800743 hda_nid_t pin_nid,
Wang Xingchao433968d2012-09-06 10:02:37 +0800744 bool non_pcm,
Wu Fengguang53d7d692010-09-21 14:25:49 +0800745 int ca)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800746{
Anssi Hannula307229d2013-10-24 21:10:34 +0300747 struct hdmi_spec *spec = codec->spec;
Anssi Hannula90f28002013-10-05 02:25:39 +0300748 struct cea_channel_speaker_allocation *ch_alloc;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800749 int i;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800750 int err;
Wang Xingchao72357c72012-09-06 10:02:36 +0800751 int order;
Wang Xingchao433968d2012-09-06 10:02:37 +0800752 int non_pcm_mapping[8];
Wu Fengguang079d88c2010-03-08 10:44:23 +0800753
Wang Xingchao72357c72012-09-06 10:02:36 +0800754 order = get_channel_allocation_order(ca);
Anssi Hannula90f28002013-10-05 02:25:39 +0300755 ch_alloc = &channel_allocations[order];
Wang Xingchao433968d2012-09-06 10:02:37 +0800756
Wu Fengguang079d88c2010-03-08 10:44:23 +0800757 if (hdmi_channel_mapping[ca][1] == 0) {
Anssi Hannula90f28002013-10-05 02:25:39 +0300758 int hdmi_slot = 0;
759 /* fill actual channel mappings in ALSA channel (i) order */
760 for (i = 0; i < ch_alloc->channels; i++) {
761 while (!ch_alloc->speakers[7 - hdmi_slot] && !WARN_ON(hdmi_slot >= 8))
762 hdmi_slot++; /* skip zero slots */
763
764 hdmi_channel_mapping[ca][i] = (i << 4) | hdmi_slot++;
765 }
766 /* fill the rest of the slots with ALSA channel 0xf */
767 for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++)
768 if (!ch_alloc->speakers[7 - hdmi_slot])
769 hdmi_channel_mapping[ca][i++] = (0xf << 4) | hdmi_slot;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800770 }
771
Wang Xingchao433968d2012-09-06 10:02:37 +0800772 if (non_pcm) {
Anssi Hannula90f28002013-10-05 02:25:39 +0300773 for (i = 0; i < ch_alloc->channels; i++)
Anssi Hannula11f7c522013-10-05 02:25:41 +0300774 non_pcm_mapping[i] = (i << 4) | i;
Wang Xingchao433968d2012-09-06 10:02:37 +0800775 for (; i < 8; i++)
Anssi Hannula11f7c522013-10-05 02:25:41 +0300776 non_pcm_mapping[i] = (0xf << 4) | i;
Wang Xingchao433968d2012-09-06 10:02:37 +0800777 }
778
Wu Fengguang079d88c2010-03-08 10:44:23 +0800779 for (i = 0; i < 8; i++) {
Anssi Hannula307229d2013-10-24 21:10:34 +0300780 int slotsetup = non_pcm ? non_pcm_mapping[i] : hdmi_channel_mapping[ca][i];
781 int hdmi_slot = slotsetup & 0x0f;
782 int channel = (slotsetup & 0xf0) >> 4;
783 err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot, channel);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800784 if (err) {
Takashi Iwai4e76a882014-02-25 12:21:03 +0100785 codec_dbg(codec, "HDMI: channel mapping failed\n");
Wu Fengguang079d88c2010-03-08 10:44:23 +0800786 break;
787 }
788 }
Wu Fengguang079d88c2010-03-08 10:44:23 +0800789}
790
Takashi Iwaid45e6882012-07-31 11:36:00 +0200791struct channel_map_table {
792 unsigned char map; /* ALSA API channel map position */
Takashi Iwaid45e6882012-07-31 11:36:00 +0200793 int spk_mask; /* speaker position bit mask */
794};
795
796static struct channel_map_table map_tables[] = {
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300797 { SNDRV_CHMAP_FL, FL },
798 { SNDRV_CHMAP_FR, FR },
799 { SNDRV_CHMAP_RL, RL },
800 { SNDRV_CHMAP_RR, RR },
801 { SNDRV_CHMAP_LFE, LFE },
802 { SNDRV_CHMAP_FC, FC },
803 { SNDRV_CHMAP_RLC, RLC },
804 { SNDRV_CHMAP_RRC, RRC },
805 { SNDRV_CHMAP_RC, RC },
806 { SNDRV_CHMAP_FLC, FLC },
807 { SNDRV_CHMAP_FRC, FRC },
Anssi Hannula94908a32013-11-10 21:24:04 +0200808 { SNDRV_CHMAP_TFL, FLH },
809 { SNDRV_CHMAP_TFR, FRH },
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300810 { SNDRV_CHMAP_FLW, FLW },
811 { SNDRV_CHMAP_FRW, FRW },
812 { SNDRV_CHMAP_TC, TC },
Anssi Hannula94908a32013-11-10 21:24:04 +0200813 { SNDRV_CHMAP_TFC, FCH },
Takashi Iwaid45e6882012-07-31 11:36:00 +0200814 {} /* terminator */
815};
816
817/* from ALSA API channel position to speaker bit mask */
818static int to_spk_mask(unsigned char c)
819{
820 struct channel_map_table *t = map_tables;
821 for (; t->map; t++) {
822 if (t->map == c)
823 return t->spk_mask;
824 }
825 return 0;
826}
827
828/* from ALSA API channel position to CEA slot */
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300829static int to_cea_slot(int ordered_ca, unsigned char pos)
Takashi Iwaid45e6882012-07-31 11:36:00 +0200830{
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300831 int mask = to_spk_mask(pos);
832 int i;
Takashi Iwaid45e6882012-07-31 11:36:00 +0200833
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300834 if (mask) {
835 for (i = 0; i < 8; i++) {
836 if (channel_allocations[ordered_ca].speakers[7 - i] == mask)
837 return i;
838 }
Takashi Iwaid45e6882012-07-31 11:36:00 +0200839 }
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300840
841 return -1;
Takashi Iwaid45e6882012-07-31 11:36:00 +0200842}
843
844/* from speaker bit mask to ALSA API channel position */
845static int spk_to_chmap(int spk)
846{
847 struct channel_map_table *t = map_tables;
848 for (; t->map; t++) {
849 if (t->spk_mask == spk)
850 return t->map;
851 }
852 return 0;
853}
854
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300855/* from CEA slot to ALSA API channel position */
856static int from_cea_slot(int ordered_ca, unsigned char slot)
857{
858 int mask = channel_allocations[ordered_ca].speakers[7 - slot];
859
860 return spk_to_chmap(mask);
861}
862
Takashi Iwaid45e6882012-07-31 11:36:00 +0200863/* get the CA index corresponding to the given ALSA API channel map */
864static int hdmi_manual_channel_allocation(int chs, unsigned char *map)
865{
866 int i, spks = 0, spk_mask = 0;
867
868 for (i = 0; i < chs; i++) {
869 int mask = to_spk_mask(map[i]);
870 if (mask) {
871 spk_mask |= mask;
872 spks++;
873 }
874 }
875
876 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
877 if ((chs == channel_allocations[i].channels ||
878 spks == channel_allocations[i].channels) &&
879 (spk_mask & channel_allocations[i].spk_mask) ==
880 channel_allocations[i].spk_mask)
881 return channel_allocations[i].ca_index;
882 }
883 return -1;
884}
885
886/* set up the channel slots for the given ALSA API channel map */
887static int hdmi_manual_setup_channel_mapping(struct hda_codec *codec,
888 hda_nid_t pin_nid,
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300889 int chs, unsigned char *map,
890 int ca)
Takashi Iwaid45e6882012-07-31 11:36:00 +0200891{
Anssi Hannula307229d2013-10-24 21:10:34 +0300892 struct hdmi_spec *spec = codec->spec;
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300893 int ordered_ca = get_channel_allocation_order(ca);
Anssi Hannula11f7c522013-10-05 02:25:41 +0300894 int alsa_pos, hdmi_slot;
895 int assignments[8] = {[0 ... 7] = 0xf};
896
897 for (alsa_pos = 0; alsa_pos < chs; alsa_pos++) {
898
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300899 hdmi_slot = to_cea_slot(ordered_ca, map[alsa_pos]);
Anssi Hannula11f7c522013-10-05 02:25:41 +0300900
901 if (hdmi_slot < 0)
902 continue; /* unassigned channel */
903
904 assignments[hdmi_slot] = alsa_pos;
905 }
906
907 for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++) {
Anssi Hannula307229d2013-10-24 21:10:34 +0300908 int err;
Anssi Hannula11f7c522013-10-05 02:25:41 +0300909
Anssi Hannula307229d2013-10-24 21:10:34 +0300910 err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot,
911 assignments[hdmi_slot]);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200912 if (err)
913 return -EINVAL;
914 }
915 return 0;
916}
917
918/* store ALSA API channel map from the current default map */
919static void hdmi_setup_fake_chmap(unsigned char *map, int ca)
920{
921 int i;
Anssi Hannula56cac412013-10-05 02:25:38 +0300922 int ordered_ca = get_channel_allocation_order(ca);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200923 for (i = 0; i < 8; i++) {
Anssi Hannula56cac412013-10-05 02:25:38 +0300924 if (i < channel_allocations[ordered_ca].channels)
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300925 map[i] = from_cea_slot(ordered_ca, hdmi_channel_mapping[ca][i] & 0x0f);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200926 else
927 map[i] = 0;
928 }
929}
930
931static void hdmi_setup_channel_mapping(struct hda_codec *codec,
932 hda_nid_t pin_nid, bool non_pcm, int ca,
Anssi Hannula20608732013-02-03 17:55:45 +0200933 int channels, unsigned char *map,
934 bool chmap_set)
Takashi Iwaid45e6882012-07-31 11:36:00 +0200935{
Anssi Hannula20608732013-02-03 17:55:45 +0200936 if (!non_pcm && chmap_set) {
Takashi Iwaid45e6882012-07-31 11:36:00 +0200937 hdmi_manual_setup_channel_mapping(codec, pin_nid,
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300938 channels, map, ca);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200939 } else {
940 hdmi_std_setup_channel_mapping(codec, pin_nid, non_pcm, ca);
941 hdmi_setup_fake_chmap(map, ca);
942 }
Anssi Hannula980b2492013-10-05 02:25:44 +0300943
944 hdmi_debug_channel_mapping(codec, pin_nid);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200945}
Wu Fengguang079d88c2010-03-08 10:44:23 +0800946
Anssi Hannula307229d2013-10-24 21:10:34 +0300947static int hdmi_pin_set_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
948 int asp_slot, int channel)
949{
950 return snd_hda_codec_write(codec, pin_nid, 0,
951 AC_VERB_SET_HDMI_CHAN_SLOT,
952 (channel << 4) | asp_slot);
953}
954
955static int hdmi_pin_get_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
956 int asp_slot)
957{
958 return (snd_hda_codec_read(codec, pin_nid, 0,
959 AC_VERB_GET_HDMI_CHAN_SLOT,
960 asp_slot) & 0xf0) >> 4;
961}
962
Wu Fengguang079d88c2010-03-08 10:44:23 +0800963/*
964 * Audio InfoFrame routines
965 */
966
967/*
968 * Enable Audio InfoFrame Transmission
969 */
970static void hdmi_start_infoframe_trans(struct hda_codec *codec,
971 hda_nid_t pin_nid)
972{
973 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
974 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
975 AC_DIPXMIT_BEST);
976}
977
978/*
979 * Disable Audio InfoFrame Transmission
980 */
981static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
982 hda_nid_t pin_nid)
983{
984 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
985 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
986 AC_DIPXMIT_DISABLE);
987}
988
989static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
990{
991#ifdef CONFIG_SND_DEBUG_VERBOSE
992 int i;
993 int size;
994
995 size = snd_hdmi_get_eld_size(codec, pin_nid);
Takashi Iwai4e76a882014-02-25 12:21:03 +0100996 codec_dbg(codec, "HDMI: ELD buf size is %d\n", size);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800997
998 for (i = 0; i < 8; i++) {
999 size = snd_hda_codec_read(codec, pin_nid, 0,
1000 AC_VERB_GET_HDMI_DIP_SIZE, i);
Takashi Iwai4e76a882014-02-25 12:21:03 +01001001 codec_dbg(codec, "HDMI: DIP GP[%d] buf size is %d\n", i, size);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001002 }
1003#endif
1004}
1005
1006static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
1007{
1008#ifdef BE_PARANOID
1009 int i, j;
1010 int size;
1011 int pi, bi;
1012 for (i = 0; i < 8; i++) {
1013 size = snd_hda_codec_read(codec, pin_nid, 0,
1014 AC_VERB_GET_HDMI_DIP_SIZE, i);
1015 if (size == 0)
1016 continue;
1017
1018 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
1019 for (j = 1; j < 1000; j++) {
1020 hdmi_write_dip_byte(codec, pin_nid, 0x0);
1021 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
1022 if (pi != i)
Takashi Iwai4e76a882014-02-25 12:21:03 +01001023 codec_dbg(codec, "dip index %d: %d != %d\n",
Wu Fengguang079d88c2010-03-08 10:44:23 +08001024 bi, pi, i);
1025 if (bi == 0) /* byte index wrapped around */
1026 break;
1027 }
Takashi Iwai4e76a882014-02-25 12:21:03 +01001028 codec_dbg(codec,
Wu Fengguang079d88c2010-03-08 10:44:23 +08001029 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
1030 i, size, j);
1031 }
1032#endif
1033}
1034
Wu Fengguang53d7d692010-09-21 14:25:49 +08001035static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001036{
Wu Fengguang53d7d692010-09-21 14:25:49 +08001037 u8 *bytes = (u8 *)hdmi_ai;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001038 u8 sum = 0;
1039 int i;
1040
Wu Fengguang53d7d692010-09-21 14:25:49 +08001041 hdmi_ai->checksum = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001042
Wu Fengguang53d7d692010-09-21 14:25:49 +08001043 for (i = 0; i < sizeof(*hdmi_ai); i++)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001044 sum += bytes[i];
1045
Wu Fengguang53d7d692010-09-21 14:25:49 +08001046 hdmi_ai->checksum = -sum;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001047}
1048
1049static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
1050 hda_nid_t pin_nid,
Wu Fengguang53d7d692010-09-21 14:25:49 +08001051 u8 *dip, int size)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001052{
Wu Fengguang079d88c2010-03-08 10:44:23 +08001053 int i;
1054
1055 hdmi_debug_dip_size(codec, pin_nid);
1056 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
1057
Wu Fengguang079d88c2010-03-08 10:44:23 +08001058 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
Wu Fengguang53d7d692010-09-21 14:25:49 +08001059 for (i = 0; i < size; i++)
1060 hdmi_write_dip_byte(codec, pin_nid, dip[i]);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001061}
1062
1063static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
Wu Fengguang53d7d692010-09-21 14:25:49 +08001064 u8 *dip, int size)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001065{
Wu Fengguang079d88c2010-03-08 10:44:23 +08001066 u8 val;
1067 int i;
1068
1069 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
1070 != AC_DIPXMIT_BEST)
1071 return false;
1072
1073 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
Wu Fengguang53d7d692010-09-21 14:25:49 +08001074 for (i = 0; i < size; i++) {
Wu Fengguang079d88c2010-03-08 10:44:23 +08001075 val = snd_hda_codec_read(codec, pin_nid, 0,
1076 AC_VERB_GET_HDMI_DIP_DATA, 0);
Wu Fengguang53d7d692010-09-21 14:25:49 +08001077 if (val != dip[i])
Wu Fengguang079d88c2010-03-08 10:44:23 +08001078 return false;
1079 }
1080
1081 return true;
1082}
1083
Anssi Hannula307229d2013-10-24 21:10:34 +03001084static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
1085 hda_nid_t pin_nid,
1086 int ca, int active_channels,
1087 int conn_type)
1088{
1089 union audio_infoframe ai;
1090
Mengdong Lincaaf5ef2014-03-11 17:12:52 -04001091 memset(&ai, 0, sizeof(ai));
Anssi Hannula307229d2013-10-24 21:10:34 +03001092 if (conn_type == 0) { /* HDMI */
1093 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
1094
1095 hdmi_ai->type = 0x84;
1096 hdmi_ai->ver = 0x01;
1097 hdmi_ai->len = 0x0a;
1098 hdmi_ai->CC02_CT47 = active_channels - 1;
1099 hdmi_ai->CA = ca;
1100 hdmi_checksum_audio_infoframe(hdmi_ai);
1101 } else if (conn_type == 1) { /* DisplayPort */
1102 struct dp_audio_infoframe *dp_ai = &ai.dp;
1103
1104 dp_ai->type = 0x84;
1105 dp_ai->len = 0x1b;
1106 dp_ai->ver = 0x11 << 2;
1107 dp_ai->CC02_CT47 = active_channels - 1;
1108 dp_ai->CA = ca;
1109 } else {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001110 codec_dbg(codec, "HDMI: unknown connection type at pin %d\n",
Anssi Hannula307229d2013-10-24 21:10:34 +03001111 pin_nid);
1112 return;
1113 }
1114
1115 /*
1116 * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
1117 * sizeof(*dp_ai) to avoid partial match/update problems when
1118 * the user switches between HDMI/DP monitors.
1119 */
1120 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
1121 sizeof(ai))) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001122 codec_dbg(codec,
1123 "hdmi_pin_setup_infoframe: pin=%d channels=%d ca=0x%02x\n",
Anssi Hannula307229d2013-10-24 21:10:34 +03001124 pin_nid,
1125 active_channels, ca);
1126 hdmi_stop_infoframe_trans(codec, pin_nid);
1127 hdmi_fill_audio_infoframe(codec, pin_nid,
1128 ai.bytes, sizeof(ai));
1129 hdmi_start_infoframe_trans(codec, pin_nid);
1130 }
1131}
1132
Takashi Iwaib0540872013-09-02 12:33:02 +02001133static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
1134 struct hdmi_spec_per_pin *per_pin,
1135 bool non_pcm)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001136{
Anssi Hannula307229d2013-10-24 21:10:34 +03001137 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001138 hda_nid_t pin_nid = per_pin->pin_nid;
Takashi Iwaib0540872013-09-02 12:33:02 +02001139 int channels = per_pin->channels;
Anssi Hannula1df5a062013-10-05 02:25:40 +03001140 int active_channels;
Stephen Warren384a48d2011-06-01 11:14:21 -06001141 struct hdmi_eld *eld;
Anssi Hannula1df5a062013-10-05 02:25:40 +03001142 int ca, ordered_ca;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001143
Takashi Iwaib0540872013-09-02 12:33:02 +02001144 if (!channels)
1145 return;
1146
Mengdong Lin75dcbe42014-01-08 15:55:32 -05001147 if (is_haswell_plus(codec))
Mengdong Lin58f7d282013-09-04 16:37:12 -04001148 snd_hda_codec_write(codec, pin_nid, 0,
1149 AC_VERB_SET_AMP_GAIN_MUTE,
1150 AMP_OUT_UNMUTE);
1151
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001152 eld = &per_pin->sink_eld;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001153
Takashi Iwaid45e6882012-07-31 11:36:00 +02001154 if (!non_pcm && per_pin->chmap_set)
1155 ca = hdmi_manual_channel_allocation(channels, per_pin->chmap);
1156 else
Takashi Iwai79514d42014-06-06 18:04:34 +02001157 ca = hdmi_channel_allocation(codec, eld, channels);
Takashi Iwaid45e6882012-07-31 11:36:00 +02001158 if (ca < 0)
1159 ca = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001160
Anssi Hannula1df5a062013-10-05 02:25:40 +03001161 ordered_ca = get_channel_allocation_order(ca);
1162 active_channels = channel_allocations[ordered_ca].channels;
1163
1164 hdmi_set_channel_count(codec, per_pin->cvt_nid, active_channels);
1165
Stephen Warren384a48d2011-06-01 11:14:21 -06001166 /*
Anssi Hannula39edac72013-10-07 19:24:52 +03001167 * always configure channel mapping, it may have been changed by the
1168 * user in the meantime
1169 */
1170 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
1171 channels, per_pin->chmap,
1172 per_pin->chmap_set);
1173
Anssi Hannula307229d2013-10-24 21:10:34 +03001174 spec->ops.pin_setup_infoframe(codec, pin_nid, ca, active_channels,
1175 eld->info.conn_type);
Wang Xingchao433968d2012-09-06 10:02:37 +08001176
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001177 per_pin->non_pcm = non_pcm;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001178}
1179
Wu Fengguang079d88c2010-03-08 10:44:23 +08001180/*
1181 * Unsolicited events
1182 */
1183
Takashi Iwaiefe47102013-11-07 13:38:23 +01001184static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
Takashi Iwai38faddb2010-07-28 14:21:55 +02001185
Takashi Iwai1a4f69d2014-09-11 15:22:46 +02001186static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001187{
1188 struct hdmi_spec *spec = codec->spec;
Takashi Iwai1a4f69d2014-09-11 15:22:46 +02001189 int pin_idx = pin_nid_to_pin_index(codec, nid);
1190
David Henningsson20ce9022013-12-04 10:19:41 +08001191 if (pin_idx < 0)
1192 return;
David Henningsson20ce9022013-12-04 10:19:41 +08001193 if (hdmi_present_sense(get_pin(spec, pin_idx), 1))
1194 snd_hda_jack_report_sync(codec);
1195}
1196
Takashi Iwai1a4f69d2014-09-11 15:22:46 +02001197static void jack_callback(struct hda_codec *codec,
1198 struct hda_jack_callback *jack)
1199{
1200 check_presence_and_report(codec, jack->tbl->nid);
1201}
1202
David Henningsson20ce9022013-12-04 10:19:41 +08001203static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
1204{
Takashi Iwai3a938972011-10-28 01:16:55 +02001205 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
Takashi Iwai3a938972011-10-28 01:16:55 +02001206 struct hda_jack_tbl *jack;
Mengdong Lin2e59e5a2013-08-26 21:35:49 -04001207 int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
Takashi Iwai3a938972011-10-28 01:16:55 +02001208
1209 jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
1210 if (!jack)
1211 return;
Takashi Iwai3a938972011-10-28 01:16:55 +02001212 jack->jack_dirty = 1;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001213
Takashi Iwai4e76a882014-02-25 12:21:03 +01001214 codec_dbg(codec,
Mengdong Lin2e59e5a2013-08-26 21:35:49 -04001215 "HDMI hot plug event: Codec=%d Pin=%d Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n",
David Henningsson20ce9022013-12-04 10:19:41 +08001216 codec->addr, jack->nid, dev_entry, !!(res & AC_UNSOL_RES_IA),
Fengguang Wufae3d882012-04-10 17:00:35 +08001217 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
Wu Fengguang079d88c2010-03-08 10:44:23 +08001218
Takashi Iwai1a4f69d2014-09-11 15:22:46 +02001219 check_presence_and_report(codec, jack->nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001220}
1221
1222static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
1223{
1224 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
1225 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
1226 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
1227 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
1228
Takashi Iwai4e76a882014-02-25 12:21:03 +01001229 codec_info(codec,
Takashi Iwaie9ea8e82012-06-21 11:41:05 +02001230 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
Stephen Warren384a48d2011-06-01 11:14:21 -06001231 codec->addr,
Wu Fengguang079d88c2010-03-08 10:44:23 +08001232 tag,
1233 subtag,
1234 cp_state,
1235 cp_ready);
1236
1237 /* TODO */
1238 if (cp_state)
1239 ;
1240 if (cp_ready)
1241 ;
1242}
1243
1244
1245static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
1246{
Wu Fengguang079d88c2010-03-08 10:44:23 +08001247 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
1248 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
1249
Takashi Iwai3a938972011-10-28 01:16:55 +02001250 if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001251 codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001252 return;
1253 }
1254
1255 if (subtag == 0)
1256 hdmi_intrinsic_event(codec, res);
1257 else
1258 hdmi_non_intrinsic_event(codec, res);
1259}
1260
Mengdong Lin58f7d282013-09-04 16:37:12 -04001261static void haswell_verify_D0(struct hda_codec *codec,
Wang Xingchao53b434f2013-06-18 10:41:53 +08001262 hda_nid_t cvt_nid, hda_nid_t nid)
David Henningsson83f26ad2013-04-10 12:26:07 +02001263{
Mengdong Lin58f7d282013-09-04 16:37:12 -04001264 int pwr;
David Henningsson83f26ad2013-04-10 12:26:07 +02001265
Wang Xingchao53b434f2013-06-18 10:41:53 +08001266 /* For Haswell, the converter 1/2 may keep in D3 state after bootup,
1267 * thus pins could only choose converter 0 for use. Make sure the
1268 * converters are in correct power state */
Takashi Iwaifd678ca2013-06-18 16:28:36 +02001269 if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0))
Wang Xingchao53b434f2013-06-18 10:41:53 +08001270 snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1271
Takashi Iwaifd678ca2013-06-18 16:28:36 +02001272 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) {
David Henningsson83f26ad2013-04-10 12:26:07 +02001273 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
1274 AC_PWRST_D0);
1275 msleep(40);
1276 pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
1277 pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
Takashi Iwai4e76a882014-02-25 12:21:03 +01001278 codec_dbg(codec, "Haswell HDMI audio: Power for pin 0x%x is now D%d\n", nid, pwr);
David Henningsson83f26ad2013-04-10 12:26:07 +02001279 }
David Henningsson83f26ad2013-04-10 12:26:07 +02001280}
1281
Wu Fengguang079d88c2010-03-08 10:44:23 +08001282/*
1283 * Callbacks
1284 */
1285
Takashi Iwai92f10b32010-08-03 14:21:00 +02001286/* HBR should be Non-PCM, 8 channels */
1287#define is_hbr_format(format) \
1288 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
1289
Anssi Hannula307229d2013-10-24 21:10:34 +03001290static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
1291 bool hbr)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001292{
Anssi Hannula307229d2013-10-24 21:10:34 +03001293 int pinctl, new_pinctl;
David Henningsson83f26ad2013-04-10 12:26:07 +02001294
Stephen Warren384a48d2011-06-01 11:14:21 -06001295 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
1296 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001297 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1298
Anssi Hannula13122e62013-11-10 20:56:10 +02001299 if (pinctl < 0)
1300 return hbr ? -EINVAL : 0;
1301
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001302 new_pinctl = pinctl & ~AC_PINCTL_EPT;
Anssi Hannula307229d2013-10-24 21:10:34 +03001303 if (hbr)
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001304 new_pinctl |= AC_PINCTL_EPT_HBR;
1305 else
1306 new_pinctl |= AC_PINCTL_EPT_NATIVE;
1307
Takashi Iwai4e76a882014-02-25 12:21:03 +01001308 codec_dbg(codec,
1309 "hdmi_pin_hbr_setup: NID=0x%x, %spinctl=0x%x\n",
Stephen Warren384a48d2011-06-01 11:14:21 -06001310 pin_nid,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001311 pinctl == new_pinctl ? "" : "new-",
1312 new_pinctl);
1313
1314 if (pinctl != new_pinctl)
Stephen Warren384a48d2011-06-01 11:14:21 -06001315 snd_hda_codec_write(codec, pin_nid, 0,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001316 AC_VERB_SET_PIN_WIDGET_CONTROL,
1317 new_pinctl);
Anssi Hannula307229d2013-10-24 21:10:34 +03001318 } else if (hbr)
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001319 return -EINVAL;
Anssi Hannula307229d2013-10-24 21:10:34 +03001320
1321 return 0;
1322}
1323
1324static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
1325 hda_nid_t pin_nid, u32 stream_tag, int format)
1326{
1327 struct hdmi_spec *spec = codec->spec;
1328 int err;
1329
Mengdong Lin75dcbe42014-01-08 15:55:32 -05001330 if (is_haswell_plus(codec))
Anssi Hannula307229d2013-10-24 21:10:34 +03001331 haswell_verify_D0(codec, cvt_nid, pin_nid);
1332
1333 err = spec->ops.pin_hbr_setup(codec, pin_nid, is_hbr_format(format));
1334
1335 if (err) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001336 codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n");
Anssi Hannula307229d2013-10-24 21:10:34 +03001337 return err;
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001338 }
Wu Fengguang079d88c2010-03-08 10:44:23 +08001339
Stephen Warren384a48d2011-06-01 11:14:21 -06001340 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001341 return 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001342}
1343
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001344static int hdmi_choose_cvt(struct hda_codec *codec,
1345 int pin_idx, int *cvt_id, int *mux_id)
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001346{
1347 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001348 struct hdmi_spec_per_pin *per_pin;
Stephen Warren384a48d2011-06-01 11:14:21 -06001349 struct hdmi_spec_per_cvt *per_cvt = NULL;
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001350 int cvt_idx, mux_idx = 0;
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001351
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001352 per_pin = get_pin(spec, pin_idx);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001353
Stephen Warren384a48d2011-06-01 11:14:21 -06001354 /* Dynamically assign converter to stream */
1355 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001356 per_cvt = get_cvt(spec, cvt_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001357
1358 /* Must not already be assigned */
1359 if (per_cvt->assigned)
1360 continue;
1361 /* Must be in pin's mux's list of converters */
1362 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
1363 if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid)
1364 break;
1365 /* Not in mux list */
1366 if (mux_idx == per_pin->num_mux_nids)
1367 continue;
1368 break;
1369 }
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001370
Stephen Warren384a48d2011-06-01 11:14:21 -06001371 /* No free converters */
1372 if (cvt_idx == spec->num_cvts)
1373 return -ENODEV;
1374
Mengdong Lin2df67422014-03-20 13:01:06 +08001375 per_pin->mux_idx = mux_idx;
1376
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001377 if (cvt_id)
1378 *cvt_id = cvt_idx;
1379 if (mux_id)
1380 *mux_id = mux_idx;
1381
1382 return 0;
1383}
1384
Mengdong Lin2df67422014-03-20 13:01:06 +08001385/* Assure the pin select the right convetor */
1386static void intel_verify_pin_cvt_connect(struct hda_codec *codec,
1387 struct hdmi_spec_per_pin *per_pin)
1388{
1389 hda_nid_t pin_nid = per_pin->pin_nid;
1390 int mux_idx, curr;
1391
1392 mux_idx = per_pin->mux_idx;
1393 curr = snd_hda_codec_read(codec, pin_nid, 0,
1394 AC_VERB_GET_CONNECT_SEL, 0);
1395 if (curr != mux_idx)
1396 snd_hda_codec_write_cache(codec, pin_nid, 0,
1397 AC_VERB_SET_CONNECT_SEL,
1398 mux_idx);
1399}
1400
Mengdong Lin300016b2013-11-04 01:13:13 -05001401/* Intel HDMI workaround to fix audio routing issue:
1402 * For some Intel display codecs, pins share the same connection list.
1403 * So a conveter can be selected by multiple pins and playback on any of these
1404 * pins will generate sound on the external display, because audio flows from
1405 * the same converter to the display pipeline. Also muting one pin may make
1406 * other pins have no sound output.
1407 * So this function assures that an assigned converter for a pin is not selected
1408 * by any other pins.
1409 */
1410static void intel_not_share_assigned_cvt(struct hda_codec *codec,
Mengdong Linf82d7d12013-09-21 20:34:45 -04001411 hda_nid_t pin_nid, int mux_idx)
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001412{
1413 struct hdmi_spec *spec = codec->spec;
Takashi Iwai7639a062015-03-03 10:07:24 +01001414 hda_nid_t nid;
Mengdong Linf82d7d12013-09-21 20:34:45 -04001415 int cvt_idx, curr;
1416 struct hdmi_spec_per_cvt *per_cvt;
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001417
Mengdong Linf82d7d12013-09-21 20:34:45 -04001418 /* configure all pins, including "no physical connection" ones */
Takashi Iwai7639a062015-03-03 10:07:24 +01001419 for_each_hda_codec_node(nid, codec) {
Mengdong Linf82d7d12013-09-21 20:34:45 -04001420 unsigned int wid_caps = get_wcaps(codec, nid);
1421 unsigned int wid_type = get_wcaps_type(wid_caps);
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001422
Mengdong Linf82d7d12013-09-21 20:34:45 -04001423 if (wid_type != AC_WID_PIN)
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001424 continue;
1425
Mengdong Linf82d7d12013-09-21 20:34:45 -04001426 if (nid == pin_nid)
1427 continue;
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001428
Mengdong Linf82d7d12013-09-21 20:34:45 -04001429 curr = snd_hda_codec_read(codec, nid, 0,
1430 AC_VERB_GET_CONNECT_SEL, 0);
1431 if (curr != mux_idx)
1432 continue;
1433
1434 /* choose an unassigned converter. The conveters in the
1435 * connection list are in the same order as in the codec.
1436 */
1437 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
1438 per_cvt = get_cvt(spec, cvt_idx);
1439 if (!per_cvt->assigned) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001440 codec_dbg(codec,
1441 "choose cvt %d for pin nid %d\n",
Mengdong Linf82d7d12013-09-21 20:34:45 -04001442 cvt_idx, nid);
1443 snd_hda_codec_write_cache(codec, nid, 0,
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001444 AC_VERB_SET_CONNECT_SEL,
Mengdong Linf82d7d12013-09-21 20:34:45 -04001445 cvt_idx);
1446 break;
1447 }
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001448 }
1449 }
1450}
1451
1452/*
1453 * HDA PCM callbacks
1454 */
1455static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1456 struct hda_codec *codec,
1457 struct snd_pcm_substream *substream)
1458{
1459 struct hdmi_spec *spec = codec->spec;
1460 struct snd_pcm_runtime *runtime = substream->runtime;
1461 int pin_idx, cvt_idx, mux_idx = 0;
1462 struct hdmi_spec_per_pin *per_pin;
1463 struct hdmi_eld *eld;
1464 struct hdmi_spec_per_cvt *per_cvt = NULL;
1465 int err;
1466
1467 /* Validate hinfo */
Takashi Iwai4e76a882014-02-25 12:21:03 +01001468 pin_idx = hinfo_to_pin_index(codec, hinfo);
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001469 if (snd_BUG_ON(pin_idx < 0))
1470 return -EINVAL;
1471 per_pin = get_pin(spec, pin_idx);
1472 eld = &per_pin->sink_eld;
1473
1474 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, &mux_idx);
1475 if (err < 0)
1476 return err;
1477
1478 per_cvt = get_cvt(spec, cvt_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001479 /* Claim converter */
1480 per_cvt->assigned = 1;
Anssi Hannula1df5a062013-10-05 02:25:40 +03001481 per_pin->cvt_nid = per_cvt->cvt_nid;
Stephen Warren384a48d2011-06-01 11:14:21 -06001482 hinfo->nid = per_cvt->cvt_nid;
1483
Takashi Iwaibddee962013-06-18 16:14:22 +02001484 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
Stephen Warren384a48d2011-06-01 11:14:21 -06001485 AC_VERB_SET_CONNECT_SEL,
1486 mux_idx);
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001487
1488 /* configure unused pins to choose other converters */
Libin Yangca2e7222014-08-19 16:20:12 +08001489 if (is_haswell_plus(codec) || is_valleyview_plus(codec))
Mengdong Lin300016b2013-11-04 01:13:13 -05001490 intel_not_share_assigned_cvt(codec, per_pin->pin_nid, mux_idx);
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001491
Stephen Warren384a48d2011-06-01 11:14:21 -06001492 snd_hda_spdif_ctls_assign(codec, pin_idx, per_cvt->cvt_nid);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001493
Stephen Warren2def8172011-06-01 11:14:20 -06001494 /* Initially set the converter's capabilities */
Stephen Warren384a48d2011-06-01 11:14:21 -06001495 hinfo->channels_min = per_cvt->channels_min;
1496 hinfo->channels_max = per_cvt->channels_max;
1497 hinfo->rates = per_cvt->rates;
1498 hinfo->formats = per_cvt->formats;
1499 hinfo->maxbps = per_cvt->maxbps;
Stephen Warren2def8172011-06-01 11:14:20 -06001500
Stephen Warren384a48d2011-06-01 11:14:21 -06001501 /* Restrict capabilities by ELD if this isn't disabled */
Stephen Warrenc3d52102011-06-01 11:14:16 -06001502 if (!static_hdmi_pcm && eld->eld_valid) {
David Henningsson1613d6b2013-02-19 16:11:24 +01001503 snd_hdmi_eld_update_pcm_info(&eld->info, hinfo);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001504 if (hinfo->channels_min > hinfo->channels_max ||
Takashi Iwai2ad779b2013-02-01 14:01:27 +01001505 !hinfo->rates || !hinfo->formats) {
1506 per_cvt->assigned = 0;
1507 hinfo->nid = 0;
1508 snd_hda_spdif_ctls_unassign(codec, pin_idx);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001509 return -ENODEV;
Takashi Iwai2ad779b2013-02-01 14:01:27 +01001510 }
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001511 }
Stephen Warren2def8172011-06-01 11:14:20 -06001512
1513 /* Store the updated parameters */
Takashi Iwai639cef02011-01-14 10:30:46 +01001514 runtime->hw.channels_min = hinfo->channels_min;
1515 runtime->hw.channels_max = hinfo->channels_max;
1516 runtime->hw.formats = hinfo->formats;
1517 runtime->hw.rates = hinfo->rates;
Takashi Iwai4fe2ca12011-01-14 10:33:26 +01001518
1519 snd_pcm_hw_constraint_step(substream->runtime, 0,
1520 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001521 return 0;
1522}
1523
1524/*
Wu Fengguang079d88c2010-03-08 10:44:23 +08001525 * HDA/HDMI auto parsing
1526 */
Stephen Warren384a48d2011-06-01 11:14:21 -06001527static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001528{
1529 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001530 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001531 hda_nid_t pin_nid = per_pin->pin_nid;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001532
1533 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001534 codec_warn(codec,
1535 "HDMI: pin %d wcaps %#x does not support connection list\n",
Wu Fengguang079d88c2010-03-08 10:44:23 +08001536 pin_nid, get_wcaps(codec, pin_nid));
1537 return -EINVAL;
1538 }
1539
Stephen Warren384a48d2011-06-01 11:14:21 -06001540 per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,
1541 per_pin->mux_nids,
1542 HDA_MAX_CONNECTIONS);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001543
1544 return 0;
1545}
1546
Takashi Iwaie90247f2015-11-13 09:12:12 +01001547/* update per_pin ELD from the given new ELD;
1548 * setup info frame and notification accordingly
1549 */
1550static void update_eld(struct hda_codec *codec,
1551 struct hdmi_spec_per_pin *per_pin,
1552 struct hdmi_eld *eld)
1553{
1554 struct hdmi_eld *pin_eld = &per_pin->sink_eld;
1555 bool old_eld_valid = pin_eld->eld_valid;
1556 bool eld_changed;
1557
1558 if (eld->eld_valid)
1559 snd_hdmi_show_eld(codec, &eld->info);
1560
1561 eld_changed = (pin_eld->eld_valid != eld->eld_valid);
1562 if (eld->eld_valid && pin_eld->eld_valid)
1563 if (pin_eld->eld_size != eld->eld_size ||
1564 memcmp(pin_eld->eld_buffer, eld->eld_buffer,
1565 eld->eld_size) != 0)
1566 eld_changed = true;
1567
1568 pin_eld->eld_valid = eld->eld_valid;
1569 pin_eld->eld_size = eld->eld_size;
1570 if (eld->eld_valid)
1571 memcpy(pin_eld->eld_buffer, eld->eld_buffer, eld->eld_size);
1572 pin_eld->info = eld->info;
1573
1574 /*
1575 * Re-setup pin and infoframe. This is needed e.g. when
1576 * - sink is first plugged-in
1577 * - transcoder can change during stream playback on Haswell
1578 * and this can make HW reset converter selection on a pin.
1579 */
1580 if (eld->eld_valid && !old_eld_valid && per_pin->setup) {
1581 if (is_haswell_plus(codec) || is_valleyview_plus(codec)) {
1582 intel_verify_pin_cvt_connect(codec, per_pin);
1583 intel_not_share_assigned_cvt(codec, per_pin->pin_nid,
1584 per_pin->mux_idx);
1585 }
1586
1587 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1588 }
1589
1590 if (eld_changed)
1591 snd_ctl_notify(codec->card,
1592 SNDRV_CTL_EVENT_MASK_VALUE |
1593 SNDRV_CTL_EVENT_MASK_INFO,
1594 &per_pin->eld_ctl->id);
1595}
1596
Takashi Iwai788d4412015-11-12 15:36:13 +01001597/* update ELD and jack state via HD-audio verbs */
1598static bool hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin,
1599 int repoll)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001600{
David Henningsson464837a2013-11-07 13:38:25 +01001601 struct hda_jack_tbl *jack;
Wu Fengguang744626d2011-11-16 16:29:47 +08001602 struct hda_codec *codec = per_pin->codec;
David Henningsson4bd038f2013-02-19 16:11:25 +01001603 struct hdmi_spec *spec = codec->spec;
1604 struct hdmi_eld *eld = &spec->temp_eld;
1605 struct hdmi_eld *pin_eld = &per_pin->sink_eld;
Wu Fengguang744626d2011-11-16 16:29:47 +08001606 hda_nid_t pin_nid = per_pin->pin_nid;
Stephen Warren5d44f922011-05-24 17:11:17 -06001607 /*
1608 * Always execute a GetPinSense verb here, even when called from
1609 * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
1610 * response's PD bit is not the real PD value, but indicates that
1611 * the real PD value changed. An older version of the HD-audio
1612 * specification worked this way. Hence, we just ignore the data in
1613 * the unsolicited response to avoid custom WARs.
1614 */
David Henningssonda4a7a32013-12-18 10:46:04 +01001615 int present;
Takashi Iwaiefe47102013-11-07 13:38:23 +01001616 bool ret;
Takashi Iwai9a5e5232015-12-10 14:35:09 +01001617 bool do_repoll = false;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001618
Takashi Iwai664c7152015-04-08 11:43:14 +02001619 snd_hda_power_up_pm(codec);
David Henningssonda4a7a32013-12-18 10:46:04 +01001620 present = snd_hda_pin_sense(codec, pin_nid);
1621
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001622 mutex_lock(&per_pin->lock);
David Henningsson4bd038f2013-02-19 16:11:25 +01001623 pin_eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
1624 if (pin_eld->monitor_present)
1625 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
1626 else
1627 eld->eld_valid = false;
Stephen Warren5d44f922011-05-24 17:11:17 -06001628
Takashi Iwai4e76a882014-02-25 12:21:03 +01001629 codec_dbg(codec,
Stephen Warren384a48d2011-06-01 11:14:21 -06001630 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
Mengdong Lin10250912013-03-28 05:21:28 -04001631 codec->addr, pin_nid, pin_eld->monitor_present, eld->eld_valid);
Stephen Warren5d44f922011-05-24 17:11:17 -06001632
David Henningsson4bd038f2013-02-19 16:11:25 +01001633 if (eld->eld_valid) {
Anssi Hannula307229d2013-10-24 21:10:34 +03001634 if (spec->ops.pin_get_eld(codec, pin_nid, eld->eld_buffer,
David Henningsson1613d6b2013-02-19 16:11:24 +01001635 &eld->eld_size) < 0)
David Henningsson4bd038f2013-02-19 16:11:25 +01001636 eld->eld_valid = false;
David Henningsson1613d6b2013-02-19 16:11:24 +01001637 else {
Takashi Iwai79514d42014-06-06 18:04:34 +02001638 if (snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer,
David Henningsson1613d6b2013-02-19 16:11:24 +01001639 eld->eld_size) < 0)
David Henningsson4bd038f2013-02-19 16:11:25 +01001640 eld->eld_valid = false;
David Henningsson1613d6b2013-02-19 16:11:24 +01001641 }
Takashi Iwai9a5e5232015-12-10 14:35:09 +01001642 if (!eld->eld_valid && repoll)
1643 do_repoll = true;
Wu Fengguang744626d2011-11-16 16:29:47 +08001644 }
David Henningsson4bd038f2013-02-19 16:11:25 +01001645
Takashi Iwai9a5e5232015-12-10 14:35:09 +01001646 if (do_repoll)
Takashi Iwaie90247f2015-11-13 09:12:12 +01001647 schedule_delayed_work(&per_pin->work, msecs_to_jiffies(300));
1648 else
1649 update_eld(codec, per_pin, eld);
Anssi Hannula6acce402014-10-19 19:25:19 +03001650
Takashi Iwaiaff747eb2013-11-07 16:39:37 +01001651 ret = !repoll || !pin_eld->monitor_present || pin_eld->eld_valid;
David Henningsson464837a2013-11-07 13:38:25 +01001652
1653 jack = snd_hda_jack_tbl_get(codec, pin_nid);
1654 if (jack)
1655 jack->block_report = !ret;
1656
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001657 mutex_unlock(&per_pin->lock);
Takashi Iwai664c7152015-04-08 11:43:14 +02001658 snd_hda_power_down_pm(codec);
Takashi Iwaiefe47102013-11-07 13:38:23 +01001659 return ret;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001660}
1661
Takashi Iwai788d4412015-11-12 15:36:13 +01001662/* update ELD and jack state via audio component */
1663static void sync_eld_via_acomp(struct hda_codec *codec,
1664 struct hdmi_spec_per_pin *per_pin)
1665{
Takashi Iwai788d4412015-11-12 15:36:13 +01001666 struct hdmi_spec *spec = codec->spec;
1667 struct hdmi_eld *eld = &spec->temp_eld;
1668 int size;
1669
Takashi Iwaie2dc7d72015-12-01 12:39:38 +01001670 mutex_lock(&per_pin->lock);
1671 size = snd_hdac_acomp_get_eld(&codec->bus->core, per_pin->pin_nid,
1672 &eld->monitor_present, eld->eld_buffer,
1673 ELD_MAX_SIZE);
1674 if (size < 0)
1675 goto unlock;
1676 if (size > 0) {
1677 size = min(size, ELD_MAX_SIZE);
1678 if (snd_hdmi_parse_eld(codec, &eld->info,
1679 eld->eld_buffer, size) < 0)
1680 size = -EINVAL;
Takashi Iwai788d4412015-11-12 15:36:13 +01001681 }
Takashi Iwaie2dc7d72015-12-01 12:39:38 +01001682
1683 if (size > 0) {
1684 eld->eld_valid = true;
1685 eld->eld_size = size;
1686 } else {
1687 eld->eld_valid = false;
1688 eld->eld_size = 0;
1689 }
1690
1691 update_eld(codec, per_pin, eld);
1692 snd_jack_report(per_pin->acomp_jack,
1693 eld->monitor_present ? SND_JACK_AVOUT : 0);
1694 unlock:
1695 mutex_unlock(&per_pin->lock);
Takashi Iwai788d4412015-11-12 15:36:13 +01001696}
1697
1698static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1699{
1700 struct hda_codec *codec = per_pin->codec;
1701
1702 if (codec_has_acomp(codec)) {
1703 sync_eld_via_acomp(codec, per_pin);
1704 return false; /* don't call snd_hda_jack_report_sync() */
1705 } else {
1706 return hdmi_present_sense_via_verbs(per_pin, repoll);
1707 }
1708}
1709
Wu Fengguang744626d2011-11-16 16:29:47 +08001710static void hdmi_repoll_eld(struct work_struct *work)
1711{
1712 struct hdmi_spec_per_pin *per_pin =
1713 container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
1714
Wu Fengguangc6e84532011-11-18 16:59:32 -06001715 if (per_pin->repoll_count++ > 6)
1716 per_pin->repoll_count = 0;
1717
Takashi Iwaiefe47102013-11-07 13:38:23 +01001718 if (hdmi_present_sense(per_pin, per_pin->repoll_count))
1719 snd_hda_jack_report_sync(per_pin->codec);
Wu Fengguang744626d2011-11-16 16:29:47 +08001720}
1721
Takashi Iwaic88d4e82013-02-08 17:10:04 -05001722static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
1723 hda_nid_t nid);
1724
Wu Fengguang079d88c2010-03-08 10:44:23 +08001725static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1726{
1727 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001728 unsigned int caps, config;
1729 int pin_idx;
1730 struct hdmi_spec_per_pin *per_pin;
David Henningsson07acecc2011-05-19 11:46:03 +02001731 int err;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001732
Takashi Iwaiefc2f8de2012-11-21 14:27:37 +01001733 caps = snd_hda_query_pin_caps(codec, pin_nid);
Stephen Warren384a48d2011-06-01 11:14:21 -06001734 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
1735 return 0;
1736
Takashi Iwaiefc2f8de2012-11-21 14:27:37 +01001737 config = snd_hda_codec_get_pincfg(codec, pin_nid);
Stephen Warren384a48d2011-06-01 11:14:21 -06001738 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
1739 return 0;
1740
Mengdong Lin75dcbe42014-01-08 15:55:32 -05001741 if (is_haswell_plus(codec))
Takashi Iwaic88d4e82013-02-08 17:10:04 -05001742 intel_haswell_fixup_connect_list(codec, pin_nid);
1743
Stephen Warren384a48d2011-06-01 11:14:21 -06001744 pin_idx = spec->num_pins;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001745 per_pin = snd_array_new(&spec->pins);
1746 if (!per_pin)
1747 return -ENOMEM;
Stephen Warren384a48d2011-06-01 11:14:21 -06001748
1749 per_pin->pin_nid = pin_nid;
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001750 per_pin->non_pcm = false;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001751
Stephen Warren384a48d2011-06-01 11:14:21 -06001752 err = hdmi_read_pin_conn(codec, pin_idx);
1753 if (err < 0)
1754 return err;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001755
Wu Fengguang079d88c2010-03-08 10:44:23 +08001756 spec->num_pins++;
1757
Stephen Warren384a48d2011-06-01 11:14:21 -06001758 return 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001759}
1760
Stephen Warren384a48d2011-06-01 11:14:21 -06001761static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001762{
1763 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001764 struct hdmi_spec_per_cvt *per_cvt;
1765 unsigned int chans;
1766 int err;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001767
Stephen Warren384a48d2011-06-01 11:14:21 -06001768 chans = get_wcaps(codec, cvt_nid);
1769 chans = get_wcaps_channels(chans);
1770
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001771 per_cvt = snd_array_new(&spec->cvts);
1772 if (!per_cvt)
1773 return -ENOMEM;
Stephen Warren384a48d2011-06-01 11:14:21 -06001774
1775 per_cvt->cvt_nid = cvt_nid;
1776 per_cvt->channels_min = 2;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001777 if (chans <= 16) {
Stephen Warren384a48d2011-06-01 11:14:21 -06001778 per_cvt->channels_max = chans;
Takashi Iwaid45e6882012-07-31 11:36:00 +02001779 if (chans > spec->channels_max)
1780 spec->channels_max = chans;
1781 }
Stephen Warren384a48d2011-06-01 11:14:21 -06001782
1783 err = snd_hda_query_supported_pcm(codec, cvt_nid,
1784 &per_cvt->rates,
1785 &per_cvt->formats,
1786 &per_cvt->maxbps);
1787 if (err < 0)
1788 return err;
1789
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001790 if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids))
1791 spec->cvt_nids[spec->num_cvts] = cvt_nid;
1792 spec->num_cvts++;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001793
1794 return 0;
1795}
1796
1797static int hdmi_parse_codec(struct hda_codec *codec)
1798{
1799 hda_nid_t nid;
1800 int i, nodes;
1801
Takashi Iwai7639a062015-03-03 10:07:24 +01001802 nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001803 if (!nid || nodes < 0) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001804 codec_warn(codec, "HDMI: failed to get afg sub nodes\n");
Wu Fengguang079d88c2010-03-08 10:44:23 +08001805 return -EINVAL;
1806 }
1807
1808 for (i = 0; i < nodes; i++, nid++) {
1809 unsigned int caps;
1810 unsigned int type;
1811
Takashi Iwaiefc2f8de2012-11-21 14:27:37 +01001812 caps = get_wcaps(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001813 type = get_wcaps_type(caps);
1814
1815 if (!(caps & AC_WCAP_DIGITAL))
1816 continue;
1817
1818 switch (type) {
1819 case AC_WID_AUD_OUT:
Stephen Warren384a48d2011-06-01 11:14:21 -06001820 hdmi_add_cvt(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001821 break;
1822 case AC_WID_PIN:
Wu Fengguang3eaead52010-05-14 16:36:15 +08001823 hdmi_add_pin(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001824 break;
1825 }
1826 }
1827
Wu Fengguang079d88c2010-03-08 10:44:23 +08001828 return 0;
1829}
1830
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001831/*
1832 */
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001833static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1834{
1835 struct hda_spdif_out *spdif;
1836 bool non_pcm;
1837
1838 mutex_lock(&codec->spdif_mutex);
1839 spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
1840 non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO);
1841 mutex_unlock(&codec->spdif_mutex);
1842 return non_pcm;
1843}
1844
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001845/*
1846 * HDMI callbacks
1847 */
1848
1849static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1850 struct hda_codec *codec,
1851 unsigned int stream_tag,
1852 unsigned int format,
1853 struct snd_pcm_substream *substream)
1854{
Stephen Warren384a48d2011-06-01 11:14:21 -06001855 hda_nid_t cvt_nid = hinfo->nid;
1856 struct hdmi_spec *spec = codec->spec;
Takashi Iwai4e76a882014-02-25 12:21:03 +01001857 int pin_idx = hinfo_to_pin_index(codec, hinfo);
Takashi Iwaib0540872013-09-02 12:33:02 +02001858 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1859 hda_nid_t pin_nid = per_pin->pin_nid;
Libin Yangddd621f2015-09-02 14:11:40 +08001860 struct snd_pcm_runtime *runtime = substream->runtime;
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001861 bool non_pcm;
Stephen Warren75fae112014-01-30 11:52:16 -07001862 int pinctl;
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001863
Libin Yangca2e7222014-08-19 16:20:12 +08001864 if (is_haswell_plus(codec) || is_valleyview_plus(codec)) {
Mengdong Lin2df67422014-03-20 13:01:06 +08001865 /* Verify pin:cvt selections to avoid silent audio after S3.
1866 * After S3, the audio driver restores pin:cvt selections
1867 * but this can happen before gfx is ready and such selection
1868 * is overlooked by HW. Thus multiple pins can share a same
1869 * default convertor and mute control will affect each other,
1870 * which can cause a resumed audio playback become silent
1871 * after S3.
1872 */
1873 intel_verify_pin_cvt_connect(codec, per_pin);
1874 intel_not_share_assigned_cvt(codec, pin_nid, per_pin->mux_idx);
1875 }
1876
Libin Yangddd621f2015-09-02 14:11:40 +08001877 /* Call sync_audio_rate to set the N/CTS/M manually if necessary */
1878 /* Todo: add DP1.2 MST audio support later */
Takashi Iwaie2dc7d72015-12-01 12:39:38 +01001879 snd_hdac_sync_audio_rate(&codec->bus->core, pin_nid, runtime->rate);
Libin Yangddd621f2015-09-02 14:11:40 +08001880
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001881 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001882 mutex_lock(&per_pin->lock);
Takashi Iwaib0540872013-09-02 12:33:02 +02001883 per_pin->channels = substream->runtime->channels;
1884 per_pin->setup = true;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001885
Takashi Iwaib0540872013-09-02 12:33:02 +02001886 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001887 mutex_unlock(&per_pin->lock);
Stephen Warren384a48d2011-06-01 11:14:21 -06001888
Stephen Warren75fae112014-01-30 11:52:16 -07001889 if (spec->dyn_pin_out) {
1890 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
1891 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1892 snd_hda_codec_write(codec, pin_nid, 0,
1893 AC_VERB_SET_PIN_WIDGET_CONTROL,
1894 pinctl | PIN_OUT);
1895 }
1896
Anssi Hannula307229d2013-10-24 21:10:34 +03001897 return spec->ops.setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001898}
1899
Takashi Iwai8dfaa572012-08-06 14:49:36 +02001900static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1901 struct hda_codec *codec,
1902 struct snd_pcm_substream *substream)
1903{
1904 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
1905 return 0;
1906}
1907
Takashi Iwaif2ad24f2012-07-26 18:08:14 +02001908static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1909 struct hda_codec *codec,
1910 struct snd_pcm_substream *substream)
Stephen Warren384a48d2011-06-01 11:14:21 -06001911{
1912 struct hdmi_spec *spec = codec->spec;
1913 int cvt_idx, pin_idx;
1914 struct hdmi_spec_per_cvt *per_cvt;
1915 struct hdmi_spec_per_pin *per_pin;
Stephen Warren75fae112014-01-30 11:52:16 -07001916 int pinctl;
Stephen Warren384a48d2011-06-01 11:14:21 -06001917
Stephen Warren384a48d2011-06-01 11:14:21 -06001918 if (hinfo->nid) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001919 cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid);
Stephen Warren384a48d2011-06-01 11:14:21 -06001920 if (snd_BUG_ON(cvt_idx < 0))
1921 return -EINVAL;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001922 per_cvt = get_cvt(spec, cvt_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001923
1924 snd_BUG_ON(!per_cvt->assigned);
1925 per_cvt->assigned = 0;
1926 hinfo->nid = 0;
1927
Takashi Iwai4e76a882014-02-25 12:21:03 +01001928 pin_idx = hinfo_to_pin_index(codec, hinfo);
Stephen Warren384a48d2011-06-01 11:14:21 -06001929 if (snd_BUG_ON(pin_idx < 0))
1930 return -EINVAL;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001931 per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001932
Stephen Warren75fae112014-01-30 11:52:16 -07001933 if (spec->dyn_pin_out) {
1934 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
1935 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1936 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
1937 AC_VERB_SET_PIN_WIDGET_CONTROL,
1938 pinctl & ~PIN_OUT);
1939 }
1940
Stephen Warren384a48d2011-06-01 11:14:21 -06001941 snd_hda_spdif_ctls_unassign(codec, pin_idx);
Takashi Iwaicbbaa602013-10-17 18:03:24 +02001942
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001943 mutex_lock(&per_pin->lock);
Takashi Iwaid45e6882012-07-31 11:36:00 +02001944 per_pin->chmap_set = false;
1945 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
Takashi Iwaib0540872013-09-02 12:33:02 +02001946
1947 per_pin->setup = false;
1948 per_pin->channels = 0;
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001949 mutex_unlock(&per_pin->lock);
Stephen Warren384a48d2011-06-01 11:14:21 -06001950 }
Takashi Iwaid45e6882012-07-31 11:36:00 +02001951
Stephen Warren384a48d2011-06-01 11:14:21 -06001952 return 0;
1953}
1954
1955static const struct hda_pcm_ops generic_ops = {
1956 .open = hdmi_pcm_open,
Takashi Iwaif2ad24f2012-07-26 18:08:14 +02001957 .close = hdmi_pcm_close,
Stephen Warren384a48d2011-06-01 11:14:21 -06001958 .prepare = generic_hdmi_playback_pcm_prepare,
Takashi Iwai8dfaa572012-08-06 14:49:36 +02001959 .cleanup = generic_hdmi_playback_pcm_cleanup,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02001960};
1961
Takashi Iwaid45e6882012-07-31 11:36:00 +02001962/*
1963 * ALSA API channel-map control callbacks
1964 */
1965static int hdmi_chmap_ctl_info(struct snd_kcontrol *kcontrol,
1966 struct snd_ctl_elem_info *uinfo)
1967{
1968 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
1969 struct hda_codec *codec = info->private_data;
1970 struct hdmi_spec *spec = codec->spec;
1971 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1972 uinfo->count = spec->channels_max;
1973 uinfo->value.integer.min = 0;
1974 uinfo->value.integer.max = SNDRV_CHMAP_LAST;
1975 return 0;
1976}
1977
Anssi Hannula307229d2013-10-24 21:10:34 +03001978static int hdmi_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap,
1979 int channels)
1980{
1981 /* If the speaker allocation matches the channel count, it is OK.*/
1982 if (cap->channels != channels)
1983 return -1;
1984
1985 /* all channels are remappable freely */
1986 return SNDRV_CTL_TLVT_CHMAP_VAR;
1987}
1988
1989static void hdmi_cea_alloc_to_tlv_chmap(struct cea_channel_speaker_allocation *cap,
1990 unsigned int *chmap, int channels)
1991{
1992 int count = 0;
1993 int c;
1994
1995 for (c = 7; c >= 0; c--) {
1996 int spk = cap->speakers[c];
1997 if (!spk)
1998 continue;
1999
2000 chmap[count++] = spk_to_chmap(spk);
2001 }
2002
2003 WARN_ON(count != channels);
2004}
2005
Takashi Iwaid45e6882012-07-31 11:36:00 +02002006static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
2007 unsigned int size, unsigned int __user *tlv)
2008{
2009 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
2010 struct hda_codec *codec = info->private_data;
2011 struct hdmi_spec *spec = codec->spec;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002012 unsigned int __user *dst;
2013 int chs, count = 0;
2014
2015 if (size < 8)
2016 return -ENOMEM;
2017 if (put_user(SNDRV_CTL_TLVT_CONTAINER, tlv))
2018 return -EFAULT;
2019 size -= 8;
2020 dst = tlv + 2;
Takashi Iwai498dab32012-09-10 16:08:40 +02002021 for (chs = 2; chs <= spec->channels_max; chs++) {
Anssi Hannula307229d2013-10-24 21:10:34 +03002022 int i;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002023 struct cea_channel_speaker_allocation *cap;
2024 cap = channel_allocations;
2025 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++, cap++) {
2026 int chs_bytes = chs * 4;
Anssi Hannula307229d2013-10-24 21:10:34 +03002027 int type = spec->ops.chmap_cea_alloc_validate_get_type(cap, chs);
2028 unsigned int tlv_chmap[8];
2029
2030 if (type < 0)
Takashi Iwaid45e6882012-07-31 11:36:00 +02002031 continue;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002032 if (size < 8)
2033 return -ENOMEM;
Anssi Hannula307229d2013-10-24 21:10:34 +03002034 if (put_user(type, dst) ||
Takashi Iwaid45e6882012-07-31 11:36:00 +02002035 put_user(chs_bytes, dst + 1))
2036 return -EFAULT;
2037 dst += 2;
2038 size -= 8;
2039 count += 8;
2040 if (size < chs_bytes)
2041 return -ENOMEM;
2042 size -= chs_bytes;
2043 count += chs_bytes;
Anssi Hannula307229d2013-10-24 21:10:34 +03002044 spec->ops.cea_alloc_to_tlv_chmap(cap, tlv_chmap, chs);
2045 if (copy_to_user(dst, tlv_chmap, chs_bytes))
2046 return -EFAULT;
2047 dst += chs;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002048 }
2049 }
2050 if (put_user(count, tlv + 1))
2051 return -EFAULT;
2052 return 0;
2053}
2054
2055static int hdmi_chmap_ctl_get(struct snd_kcontrol *kcontrol,
2056 struct snd_ctl_elem_value *ucontrol)
2057{
2058 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
2059 struct hda_codec *codec = info->private_data;
2060 struct hdmi_spec *spec = codec->spec;
2061 int pin_idx = kcontrol->private_value;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002062 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Takashi Iwaid45e6882012-07-31 11:36:00 +02002063 int i;
2064
2065 for (i = 0; i < ARRAY_SIZE(per_pin->chmap); i++)
2066 ucontrol->value.integer.value[i] = per_pin->chmap[i];
2067 return 0;
2068}
2069
2070static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
2071 struct snd_ctl_elem_value *ucontrol)
2072{
2073 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
2074 struct hda_codec *codec = info->private_data;
2075 struct hdmi_spec *spec = codec->spec;
2076 int pin_idx = kcontrol->private_value;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002077 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Takashi Iwaid45e6882012-07-31 11:36:00 +02002078 unsigned int ctl_idx;
2079 struct snd_pcm_substream *substream;
2080 unsigned char chmap[8];
Anssi Hannula307229d2013-10-24 21:10:34 +03002081 int i, err, ca, prepared = 0;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002082
2083 ctl_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2084 substream = snd_pcm_chmap_substream(info, ctl_idx);
2085 if (!substream || !substream->runtime)
Takashi Iwai6f54c362013-01-15 14:44:41 +01002086 return 0; /* just for avoiding error from alsactl restore */
Takashi Iwaid45e6882012-07-31 11:36:00 +02002087 switch (substream->runtime->status->state) {
2088 case SNDRV_PCM_STATE_OPEN:
2089 case SNDRV_PCM_STATE_SETUP:
2090 break;
2091 case SNDRV_PCM_STATE_PREPARED:
2092 prepared = 1;
2093 break;
2094 default:
2095 return -EBUSY;
2096 }
2097 memset(chmap, 0, sizeof(chmap));
2098 for (i = 0; i < ARRAY_SIZE(chmap); i++)
2099 chmap[i] = ucontrol->value.integer.value[i];
2100 if (!memcmp(chmap, per_pin->chmap, sizeof(chmap)))
2101 return 0;
2102 ca = hdmi_manual_channel_allocation(ARRAY_SIZE(chmap), chmap);
2103 if (ca < 0)
2104 return -EINVAL;
Anssi Hannula307229d2013-10-24 21:10:34 +03002105 if (spec->ops.chmap_validate) {
2106 err = spec->ops.chmap_validate(ca, ARRAY_SIZE(chmap), chmap);
2107 if (err)
2108 return err;
2109 }
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002110 mutex_lock(&per_pin->lock);
Takashi Iwaid45e6882012-07-31 11:36:00 +02002111 per_pin->chmap_set = true;
2112 memcpy(per_pin->chmap, chmap, sizeof(chmap));
2113 if (prepared)
Takashi Iwaib0540872013-09-02 12:33:02 +02002114 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002115 mutex_unlock(&per_pin->lock);
Takashi Iwaid45e6882012-07-31 11:36:00 +02002116
2117 return 0;
2118}
2119
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002120static int generic_hdmi_build_pcms(struct hda_codec *codec)
2121{
2122 struct hdmi_spec *spec = codec->spec;
Libin Yang6590faa2015-12-16 13:42:41 +08002123 struct hdmi_spec_per_pin *per_pin;
Stephen Warren384a48d2011-06-01 11:14:21 -06002124 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002125
Stephen Warren384a48d2011-06-01 11:14:21 -06002126 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2127 struct hda_pcm *info;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002128 struct hda_pcm_stream *pstr;
2129
Takashi Iwaibbbc7e82015-02-27 17:43:19 +01002130 info = snd_hda_codec_pcm_new(codec, "HDMI %d", pin_idx);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002131 if (!info)
2132 return -ENOMEM;
Libin Yang6590faa2015-12-16 13:42:41 +08002133 if (!spec->dyn_pcm_assign) {
2134 per_pin = get_pin(spec, pin_idx);
2135 per_pin->pcm = info;
2136 }
Takashi Iwaibbbc7e82015-02-27 17:43:19 +01002137 spec->pcm_rec[pin_idx] = info;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002138 info->pcm_type = HDA_PCM_TYPE_HDMI;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002139 info->own_chmap = true;
Stephen Warren384a48d2011-06-01 11:14:21 -06002140
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002141 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
Stephen Warren384a48d2011-06-01 11:14:21 -06002142 pstr->substreams = 1;
2143 pstr->ops = generic_ops;
2144 /* other pstr fields are set in open */
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002145 }
2146
2147 return 0;
2148}
2149
Takashi Iwai788d4412015-11-12 15:36:13 +01002150static void free_acomp_jack_priv(struct snd_jack *jack)
2151{
2152 struct hdmi_spec_per_pin *per_pin = jack->private_data;
2153
2154 per_pin->acomp_jack = NULL;
2155}
2156
2157static int add_acomp_jack_kctl(struct hda_codec *codec,
2158 struct hdmi_spec_per_pin *per_pin,
2159 const char *name)
2160{
2161 struct snd_jack *jack;
2162 int err;
2163
2164 err = snd_jack_new(codec->card, name, SND_JACK_AVOUT, &jack,
2165 true, false);
2166 if (err < 0)
2167 return err;
2168 per_pin->acomp_jack = jack;
2169 jack->private_data = per_pin;
2170 jack->private_free = free_acomp_jack_priv;
2171 return 0;
2172}
2173
David Henningsson0b6c49b2011-08-23 16:56:03 +02002174static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx)
2175{
Takashi Iwai31ef2252011-12-01 17:41:36 +01002176 char hdmi_str[32] = "HDMI/DP";
David Henningsson0b6c49b2011-08-23 16:56:03 +02002177 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002178 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2179 int pcmdev = get_pcm_rec(spec, pin_idx)->device;
Takashi Iwai909cadc2015-11-12 11:52:13 +01002180 bool phantom_jack;
David Henningsson0b6c49b2011-08-23 16:56:03 +02002181
Takashi Iwai31ef2252011-12-01 17:41:36 +01002182 if (pcmdev > 0)
2183 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
Takashi Iwai788d4412015-11-12 15:36:13 +01002184 if (codec_has_acomp(codec))
2185 return add_acomp_jack_kctl(codec, per_pin, hdmi_str);
Takashi Iwai909cadc2015-11-12 11:52:13 +01002186 phantom_jack = !is_jack_detectable(codec, per_pin->pin_nid);
2187 if (phantom_jack)
David Henningsson30efd8d2013-02-22 10:16:28 +01002188 strncat(hdmi_str, " Phantom",
2189 sizeof(hdmi_str) - strlen(hdmi_str) - 1);
David Henningsson0b6c49b2011-08-23 16:56:03 +02002190
Takashi Iwai909cadc2015-11-12 11:52:13 +01002191 return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str,
2192 phantom_jack);
David Henningsson0b6c49b2011-08-23 16:56:03 +02002193}
2194
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002195static int generic_hdmi_build_controls(struct hda_codec *codec)
2196{
2197 struct hdmi_spec *spec = codec->spec;
2198 int err;
Stephen Warren384a48d2011-06-01 11:14:21 -06002199 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002200
Stephen Warren384a48d2011-06-01 11:14:21 -06002201 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002202 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
David Henningsson0b6c49b2011-08-23 16:56:03 +02002203
2204 err = generic_hdmi_build_jack(codec, pin_idx);
2205 if (err < 0)
2206 return err;
2207
Takashi Iwaidcda5802012-10-12 17:24:51 +02002208 err = snd_hda_create_dig_out_ctls(codec,
2209 per_pin->pin_nid,
2210 per_pin->mux_nids[0],
2211 HDA_PCM_TYPE_HDMI);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002212 if (err < 0)
2213 return err;
Stephen Warren384a48d2011-06-01 11:14:21 -06002214 snd_hda_spdif_ctls_unassign(codec, pin_idx);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -05002215
2216 /* add control for ELD Bytes */
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002217 err = hdmi_create_eld_ctl(codec, pin_idx,
2218 get_pcm_rec(spec, pin_idx)->device);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -05002219
2220 if (err < 0)
2221 return err;
Takashi Iwai31ef2252011-12-01 17:41:36 +01002222
Takashi Iwai82b1d732011-12-20 15:53:07 +01002223 hdmi_present_sense(per_pin, 0);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002224 }
2225
Takashi Iwaid45e6882012-07-31 11:36:00 +02002226 /* add channel maps */
2227 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibbbc7e82015-02-27 17:43:19 +01002228 struct hda_pcm *pcm;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002229 struct snd_pcm_chmap *chmap;
2230 struct snd_kcontrol *kctl;
2231 int i;
Takashi Iwai2ca320e2013-08-22 09:55:36 +02002232
Takashi Iwaibbbc7e82015-02-27 17:43:19 +01002233 pcm = spec->pcm_rec[pin_idx];
2234 if (!pcm || !pcm->pcm)
Takashi Iwai2ca320e2013-08-22 09:55:36 +02002235 break;
Takashi Iwaibbbc7e82015-02-27 17:43:19 +01002236 err = snd_pcm_add_chmap_ctls(pcm->pcm,
Takashi Iwaid45e6882012-07-31 11:36:00 +02002237 SNDRV_PCM_STREAM_PLAYBACK,
2238 NULL, 0, pin_idx, &chmap);
2239 if (err < 0)
2240 return err;
2241 /* override handlers */
2242 chmap->private_data = codec;
2243 kctl = chmap->kctl;
2244 for (i = 0; i < kctl->count; i++)
2245 kctl->vd[i].access |= SNDRV_CTL_ELEM_ACCESS_WRITE;
2246 kctl->info = hdmi_chmap_ctl_info;
2247 kctl->get = hdmi_chmap_ctl_get;
2248 kctl->put = hdmi_chmap_ctl_put;
2249 kctl->tlv.c = hdmi_chmap_ctl_tlv;
2250 }
2251
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002252 return 0;
2253}
2254
Takashi Iwai8b8d6542012-06-20 16:32:22 +02002255static int generic_hdmi_init_per_pins(struct hda_codec *codec)
2256{
2257 struct hdmi_spec *spec = codec->spec;
2258 int pin_idx;
2259
2260 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002261 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Takashi Iwai8b8d6542012-06-20 16:32:22 +02002262
2263 per_pin->codec = codec;
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002264 mutex_init(&per_pin->lock);
Takashi Iwai8b8d6542012-06-20 16:32:22 +02002265 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002266 eld_proc_new(per_pin, pin_idx);
Takashi Iwai8b8d6542012-06-20 16:32:22 +02002267 }
2268 return 0;
2269}
2270
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002271static int generic_hdmi_init(struct hda_codec *codec)
2272{
2273 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06002274 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002275
Stephen Warren384a48d2011-06-01 11:14:21 -06002276 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002277 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06002278 hda_nid_t pin_nid = per_pin->pin_nid;
Stephen Warren384a48d2011-06-01 11:14:21 -06002279
2280 hdmi_init_pin(codec, pin_nid);
Takashi Iwai788d4412015-11-12 15:36:13 +01002281 if (!codec_has_acomp(codec))
2282 snd_hda_jack_detect_enable_callback(codec, pin_nid,
2283 codec->jackpoll_interval > 0 ?
2284 jack_callback : NULL);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002285 }
2286 return 0;
2287}
2288
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002289static void hdmi_array_init(struct hdmi_spec *spec, int nums)
2290{
2291 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums);
2292 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002293}
2294
2295static void hdmi_array_free(struct hdmi_spec *spec)
2296{
2297 snd_array_free(&spec->pins);
2298 snd_array_free(&spec->cvts);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002299}
2300
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002301static void generic_hdmi_free(struct hda_codec *codec)
2302{
2303 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06002304 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002305
Takashi Iwai66032492015-12-01 16:49:35 +01002306 if (codec_has_acomp(codec))
David Henningsson25adc132015-08-19 10:48:58 +02002307 snd_hdac_i915_register_notifier(NULL);
2308
Stephen Warren384a48d2011-06-01 11:14:21 -06002309 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002310 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06002311
Takashi Iwai2f35c632015-02-27 22:43:26 +01002312 cancel_delayed_work_sync(&per_pin->work);
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002313 eld_proc_free(per_pin);
Takashi Iwai788d4412015-11-12 15:36:13 +01002314 if (per_pin->acomp_jack)
2315 snd_device_free(codec->card, per_pin->acomp_jack);
Stephen Warren384a48d2011-06-01 11:14:21 -06002316 }
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002317
Takashi Iwai55913112015-12-10 13:03:29 +01002318 if (spec->i915_bound)
2319 snd_hdac_i915_exit(&codec->bus->core);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002320 hdmi_array_free(spec);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002321 kfree(spec);
2322}
2323
Wang Xingchao28cb72e2013-06-24 07:45:23 -04002324#ifdef CONFIG_PM
2325static int generic_hdmi_resume(struct hda_codec *codec)
2326{
2327 struct hdmi_spec *spec = codec->spec;
2328 int pin_idx;
2329
Pierre Ossmana2833682014-06-18 21:48:09 +02002330 codec->patch_ops.init(codec);
Takashi Iwaieeecd9d2015-02-25 15:18:50 +01002331 regcache_sync(codec->core.regmap);
Wang Xingchao28cb72e2013-06-24 07:45:23 -04002332
2333 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2334 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2335 hdmi_present_sense(per_pin, 1);
2336 }
2337 return 0;
2338}
2339#endif
2340
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02002341static const struct hda_codec_ops generic_hdmi_patch_ops = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002342 .init = generic_hdmi_init,
2343 .free = generic_hdmi_free,
2344 .build_pcms = generic_hdmi_build_pcms,
2345 .build_controls = generic_hdmi_build_controls,
2346 .unsol_event = hdmi_unsol_event,
Wang Xingchao28cb72e2013-06-24 07:45:23 -04002347#ifdef CONFIG_PM
2348 .resume = generic_hdmi_resume,
2349#endif
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002350};
2351
Anssi Hannula307229d2013-10-24 21:10:34 +03002352static const struct hdmi_ops generic_standard_hdmi_ops = {
2353 .pin_get_eld = snd_hdmi_get_eld,
2354 .pin_get_slot_channel = hdmi_pin_get_slot_channel,
2355 .pin_set_slot_channel = hdmi_pin_set_slot_channel,
2356 .pin_setup_infoframe = hdmi_pin_setup_infoframe,
2357 .pin_hbr_setup = hdmi_pin_hbr_setup,
2358 .setup_stream = hdmi_setup_stream,
2359 .chmap_cea_alloc_validate_get_type = hdmi_chmap_cea_alloc_validate_get_type,
2360 .cea_alloc_to_tlv_chmap = hdmi_cea_alloc_to_tlv_chmap,
2361};
2362
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002363
2364static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
2365 hda_nid_t nid)
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002366{
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002367 struct hdmi_spec *spec = codec->spec;
2368 hda_nid_t conns[4];
2369 int nconns;
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002370
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002371 nconns = snd_hda_get_connections(codec, nid, conns, ARRAY_SIZE(conns));
2372 if (nconns == spec->num_cvts &&
2373 !memcmp(conns, spec->cvt_nids, spec->num_cvts * sizeof(hda_nid_t)))
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002374 return;
2375
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002376 /* override pins connection list */
Takashi Iwai4e76a882014-02-25 12:21:03 +01002377 codec_dbg(codec, "hdmi: haswell: override pin connection 0x%x\n", nid);
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002378 snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids);
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002379}
2380
Mengdong Lin1611a9c2013-02-08 17:09:52 -05002381#define INTEL_VENDOR_NID 0x08
2382#define INTEL_GET_VENDOR_VERB 0xf81
2383#define INTEL_SET_VENDOR_VERB 0x781
2384#define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
2385#define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
2386
2387static void intel_haswell_enable_all_pins(struct hda_codec *codec,
Takashi Iwai17df3f52013-05-08 08:09:34 +02002388 bool update_tree)
Mengdong Lin1611a9c2013-02-08 17:09:52 -05002389{
2390 unsigned int vendor_param;
2391
Mengdong Lin1611a9c2013-02-08 17:09:52 -05002392 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
2393 INTEL_GET_VENDOR_VERB, 0);
2394 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
2395 return;
2396
2397 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
2398 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
2399 INTEL_SET_VENDOR_VERB, vendor_param);
2400 if (vendor_param == -1)
2401 return;
2402
Takashi Iwai17df3f52013-05-08 08:09:34 +02002403 if (update_tree)
2404 snd_hda_codec_update_widgets(codec);
Mengdong Lin1611a9c2013-02-08 17:09:52 -05002405}
2406
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002407static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
2408{
2409 unsigned int vendor_param;
2410
2411 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
2412 INTEL_GET_VENDOR_VERB, 0);
2413 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
2414 return;
2415
2416 /* enable DP1.2 mode */
2417 vendor_param |= INTEL_EN_DP12;
Takashi Iwaia551d912015-02-26 12:34:49 +01002418 snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB);
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002419 snd_hda_codec_write_cache(codec, INTEL_VENDOR_NID, 0,
2420 INTEL_SET_VENDOR_VERB, vendor_param);
2421}
2422
Takashi Iwai17df3f52013-05-08 08:09:34 +02002423/* Haswell needs to re-issue the vendor-specific verbs before turning to D0.
2424 * Otherwise you may get severe h/w communication errors.
2425 */
2426static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2427 unsigned int power_state)
2428{
2429 if (power_state == AC_PWRST_D0) {
2430 intel_haswell_enable_all_pins(codec, false);
2431 intel_haswell_fixup_enable_dp12(codec);
2432 }
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002433
Takashi Iwai17df3f52013-05-08 08:09:34 +02002434 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
2435 snd_hda_codec_set_power_to_all(codec, fg, power_state);
2436}
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002437
David Henningssonf0675d42015-09-03 11:51:34 +02002438static void intel_pin_eld_notify(void *audio_ptr, int port)
David Henningsson25adc132015-08-19 10:48:58 +02002439{
2440 struct hda_codec *codec = audio_ptr;
2441 int pin_nid = port + 0x04;
2442
Takashi Iwai8ae743e2015-11-27 14:23:00 +01002443 /* skip notification during system suspend (but not in runtime PM);
2444 * the state will be updated at resume
2445 */
2446 if (snd_power_get_state(codec->card) != SNDRV_CTL_POWER_D0)
2447 return;
Takashi Iwaieb399d32015-11-27 14:53:35 +01002448 /* ditto during suspend/resume process itself */
2449 if (atomic_read(&(codec)->core.in_pm))
2450 return;
Takashi Iwai8ae743e2015-11-27 14:23:00 +01002451
David Henningsson25adc132015-08-19 10:48:58 +02002452 check_presence_and_report(codec, pin_nid);
2453}
2454
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002455static int patch_generic_hdmi(struct hda_codec *codec)
2456{
2457 struct hdmi_spec *spec;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002458
2459 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2460 if (spec == NULL)
2461 return -ENOMEM;
2462
Anssi Hannula307229d2013-10-24 21:10:34 +03002463 spec->ops = generic_standard_hdmi_ops;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002464 codec->spec = spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002465 hdmi_array_init(spec, 4);
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002466
Takashi Iwai55913112015-12-10 13:03:29 +01002467 /* Try to bind with i915 for any Intel codecs (if not done yet) */
2468 if (!codec_has_acomp(codec) &&
2469 (codec->core.vendor_id >> 16) == 0x8086)
2470 if (!snd_hdac_i915_init(&codec->bus->core))
2471 spec->i915_bound = true;
2472
Mengdong Lin75dcbe42014-01-08 15:55:32 -05002473 if (is_haswell_plus(codec)) {
Takashi Iwai17df3f52013-05-08 08:09:34 +02002474 intel_haswell_enable_all_pins(codec, true);
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002475 intel_haswell_fixup_enable_dp12(codec);
Takashi Iwai17df3f52013-05-08 08:09:34 +02002476 }
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002477
Mengdong Lin2bd1f73f2015-04-29 17:43:43 +08002478 /* For Valleyview/Cherryview, only the display codec is in the display
2479 * power well and can use link_power ops to request/release the power.
2480 * For Haswell/Broadwell, the controller is also in the power well and
2481 * can cover the codec power request, and so need not set this flag.
2482 * For previous platforms, there is no such power well feature.
2483 */
Lu, Hanff9d8852015-11-19 23:25:13 +08002484 if (is_valleyview_plus(codec) || is_skylake(codec) ||
2485 is_broxton(codec))
Mengdong Lin2bd1f73f2015-04-29 17:43:43 +08002486 codec->core.link_power_control = 1;
2487
Takashi Iwai66032492015-12-01 16:49:35 +01002488 if (codec_has_acomp(codec)) {
Mengdong Lin5b8620b2013-12-05 18:35:48 -05002489 codec->depop_delay = 0;
David Henningsson25adc132015-08-19 10:48:58 +02002490 spec->i915_audio_ops.audio_ptr = codec;
2491 spec->i915_audio_ops.pin_eld_notify = intel_pin_eld_notify;
2492 snd_hdac_i915_register_notifier(&spec->i915_audio_ops);
2493 }
Mengdong Lin5b8620b2013-12-05 18:35:48 -05002494
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002495 if (hdmi_parse_codec(codec) < 0) {
Takashi Iwai55913112015-12-10 13:03:29 +01002496 if (spec->i915_bound)
2497 snd_hdac_i915_exit(&codec->bus->core);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002498 codec->spec = NULL;
2499 kfree(spec);
2500 return -EINVAL;
2501 }
2502 codec->patch_ops = generic_hdmi_patch_ops;
Mengdong Lin75dcbe42014-01-08 15:55:32 -05002503 if (is_haswell_plus(codec)) {
Takashi Iwai17df3f52013-05-08 08:09:34 +02002504 codec->patch_ops.set_power_state = haswell_set_power_state;
Mengdong Lin5dc989b2013-08-26 21:35:41 -04002505 codec->dp_mst = true;
2506 }
Takashi Iwai17df3f52013-05-08 08:09:34 +02002507
Lu, Han2377c3c2015-06-09 16:50:38 +08002508 /* Enable runtime pm for HDMI audio codec of HSW/BDW/SKL/BYT/BSW */
2509 if (is_haswell_plus(codec) || is_valleyview_plus(codec))
2510 codec->auto_runtime_pm = 1;
2511
Takashi Iwai8b8d6542012-06-20 16:32:22 +02002512 generic_hdmi_init_per_pins(codec);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002513
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002514 init_channel_allocations();
2515
2516 return 0;
2517}
2518
2519/*
Stephen Warren3aaf8982011-06-01 11:14:19 -06002520 * Shared non-generic implementations
2521 */
2522
2523static int simple_playback_build_pcms(struct hda_codec *codec)
2524{
2525 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002526 struct hda_pcm *info;
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002527 unsigned int chans;
2528 struct hda_pcm_stream *pstr;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002529 struct hdmi_spec_per_cvt *per_cvt;
Stephen Warren3aaf8982011-06-01 11:14:19 -06002530
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002531 per_cvt = get_cvt(spec, 0);
2532 chans = get_wcaps(codec, per_cvt->cvt_nid);
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002533 chans = get_wcaps_channels(chans);
Stephen Warren3aaf8982011-06-01 11:14:19 -06002534
Takashi Iwaibbbc7e82015-02-27 17:43:19 +01002535 info = snd_hda_codec_pcm_new(codec, "HDMI 0");
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002536 if (!info)
2537 return -ENOMEM;
Takashi Iwaibbbc7e82015-02-27 17:43:19 +01002538 spec->pcm_rec[0] = info;
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002539 info->pcm_type = HDA_PCM_TYPE_HDMI;
2540 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
2541 *pstr = spec->pcm_playback;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002542 pstr->nid = per_cvt->cvt_nid;
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002543 if (pstr->channels_max <= 2 && chans && chans <= 16)
2544 pstr->channels_max = chans;
Stephen Warren3aaf8982011-06-01 11:14:19 -06002545
2546 return 0;
2547}
2548
Takashi Iwai4b6ace92012-06-15 11:53:32 +02002549/* unsolicited event for jack sensing */
2550static void simple_hdmi_unsol_event(struct hda_codec *codec,
2551 unsigned int res)
2552{
Takashi Iwai9dd8cf12012-06-21 10:43:15 +02002553 snd_hda_jack_set_dirty_all(codec);
Takashi Iwai4b6ace92012-06-15 11:53:32 +02002554 snd_hda_jack_report_sync(codec);
2555}
2556
2557/* generic_hdmi_build_jack can be used for simple_hdmi, too,
2558 * as long as spec->pins[] is set correctly
2559 */
2560#define simple_hdmi_build_jack generic_hdmi_build_jack
2561
Stephen Warren3aaf8982011-06-01 11:14:19 -06002562static int simple_playback_build_controls(struct hda_codec *codec)
2563{
2564 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002565 struct hdmi_spec_per_cvt *per_cvt;
Stephen Warren3aaf8982011-06-01 11:14:19 -06002566 int err;
Stephen Warren3aaf8982011-06-01 11:14:19 -06002567
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002568 per_cvt = get_cvt(spec, 0);
Anssi Hannulac9a63382013-12-10 22:46:34 +02002569 err = snd_hda_create_dig_out_ctls(codec, per_cvt->cvt_nid,
2570 per_cvt->cvt_nid,
2571 HDA_PCM_TYPE_HDMI);
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002572 if (err < 0)
2573 return err;
2574 return simple_hdmi_build_jack(codec, 0);
Stephen Warren3aaf8982011-06-01 11:14:19 -06002575}
2576
Takashi Iwai4f0110c2012-06-15 12:45:43 +02002577static int simple_playback_init(struct hda_codec *codec)
2578{
2579 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002580 struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0);
2581 hda_nid_t pin = per_pin->pin_nid;
Takashi Iwai4f0110c2012-06-15 12:45:43 +02002582
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002583 snd_hda_codec_write(codec, pin, 0,
2584 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
2585 /* some codecs require to unmute the pin */
2586 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
2587 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2588 AMP_OUT_UNMUTE);
Takashi Iwai62f949b2014-09-11 14:06:53 +02002589 snd_hda_jack_detect_enable(codec, pin);
Takashi Iwai4f0110c2012-06-15 12:45:43 +02002590 return 0;
2591}
2592
Stephen Warren3aaf8982011-06-01 11:14:19 -06002593static void simple_playback_free(struct hda_codec *codec)
2594{
2595 struct hdmi_spec *spec = codec->spec;
2596
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002597 hdmi_array_free(spec);
Stephen Warren3aaf8982011-06-01 11:14:19 -06002598 kfree(spec);
2599}
2600
2601/*
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002602 * Nvidia specific implementations
2603 */
2604
2605#define Nv_VERB_SET_Channel_Allocation 0xF79
2606#define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
2607#define Nv_VERB_SET_Audio_Protection_On 0xF98
2608#define Nv_VERB_SET_Audio_Protection_Off 0xF99
2609
2610#define nvhdmi_master_con_nid_7x 0x04
2611#define nvhdmi_master_pin_nid_7x 0x05
2612
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02002613static const hda_nid_t nvhdmi_con_nids_7x[4] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002614 /*front, rear, clfe, rear_surr */
2615 0x6, 0x8, 0xa, 0xc,
2616};
2617
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002618static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = {
2619 /* set audio protect on */
2620 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
2621 /* enable digital output on pin widget */
2622 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2623 {} /* terminator */
2624};
2625
2626static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002627 /* set audio protect on */
2628 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
2629 /* enable digital output on pin widget */
2630 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2631 { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2632 { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2633 { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2634 { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
2635 {} /* terminator */
2636};
2637
2638#ifdef LIMITED_RATE_FMT_SUPPORT
2639/* support only the safe format and rate */
2640#define SUPPORTED_RATES SNDRV_PCM_RATE_48000
2641#define SUPPORTED_MAXBPS 16
2642#define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
2643#else
2644/* support all rates and formats */
2645#define SUPPORTED_RATES \
2646 (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
2647 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
2648 SNDRV_PCM_RATE_192000)
2649#define SUPPORTED_MAXBPS 24
2650#define SUPPORTED_FORMATS \
2651 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
2652#endif
2653
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002654static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002655{
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002656 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
2657 return 0;
2658}
2659
2660static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
2661{
2662 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002663 return 0;
2664}
2665
Nitin Daga393004b2011-01-10 21:49:31 +05302666static unsigned int channels_2_6_8[] = {
2667 2, 6, 8
2668};
2669
2670static unsigned int channels_2_8[] = {
2671 2, 8
2672};
2673
2674static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
2675 .count = ARRAY_SIZE(channels_2_6_8),
2676 .list = channels_2_6_8,
2677 .mask = 0,
2678};
2679
2680static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
2681 .count = ARRAY_SIZE(channels_2_8),
2682 .list = channels_2_8,
2683 .mask = 0,
2684};
2685
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002686static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
2687 struct hda_codec *codec,
2688 struct snd_pcm_substream *substream)
2689{
2690 struct hdmi_spec *spec = codec->spec;
Nitin Daga393004b2011-01-10 21:49:31 +05302691 struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
2692
Takashi Iwaib9a94a92015-10-01 16:20:04 +02002693 switch (codec->preset->vendor_id) {
Nitin Daga393004b2011-01-10 21:49:31 +05302694 case 0x10de0002:
2695 case 0x10de0003:
2696 case 0x10de0005:
2697 case 0x10de0006:
2698 hw_constraints_channels = &hw_constraints_2_8_channels;
2699 break;
2700 case 0x10de0007:
2701 hw_constraints_channels = &hw_constraints_2_6_8_channels;
2702 break;
2703 default:
2704 break;
2705 }
2706
2707 if (hw_constraints_channels != NULL) {
2708 snd_pcm_hw_constraint_list(substream->runtime, 0,
2709 SNDRV_PCM_HW_PARAM_CHANNELS,
2710 hw_constraints_channels);
Takashi Iwaiad09fc92011-01-14 09:42:27 +01002711 } else {
2712 snd_pcm_hw_constraint_step(substream->runtime, 0,
2713 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Nitin Daga393004b2011-01-10 21:49:31 +05302714 }
2715
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002716 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2717}
2718
2719static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
2720 struct hda_codec *codec,
2721 struct snd_pcm_substream *substream)
2722{
2723 struct hdmi_spec *spec = codec->spec;
2724 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2725}
2726
2727static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2728 struct hda_codec *codec,
2729 unsigned int stream_tag,
2730 unsigned int format,
2731 struct snd_pcm_substream *substream)
2732{
2733 struct hdmi_spec *spec = codec->spec;
2734 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2735 stream_tag, format, substream);
2736}
2737
Takashi Iwaid0b12522012-06-15 14:34:42 +02002738static const struct hda_pcm_stream simple_pcm_playback = {
2739 .substreams = 1,
2740 .channels_min = 2,
2741 .channels_max = 2,
2742 .ops = {
2743 .open = simple_playback_pcm_open,
2744 .close = simple_playback_pcm_close,
2745 .prepare = simple_playback_pcm_prepare
2746 },
2747};
2748
2749static const struct hda_codec_ops simple_hdmi_patch_ops = {
2750 .build_controls = simple_playback_build_controls,
2751 .build_pcms = simple_playback_build_pcms,
2752 .init = simple_playback_init,
2753 .free = simple_playback_free,
Takashi Iwai250e41a2012-06-15 14:40:21 +02002754 .unsol_event = simple_hdmi_unsol_event,
Takashi Iwaid0b12522012-06-15 14:34:42 +02002755};
2756
2757static int patch_simple_hdmi(struct hda_codec *codec,
2758 hda_nid_t cvt_nid, hda_nid_t pin_nid)
2759{
2760 struct hdmi_spec *spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002761 struct hdmi_spec_per_cvt *per_cvt;
2762 struct hdmi_spec_per_pin *per_pin;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002763
2764 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2765 if (!spec)
2766 return -ENOMEM;
2767
2768 codec->spec = spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002769 hdmi_array_init(spec, 1);
Takashi Iwaid0b12522012-06-15 14:34:42 +02002770
2771 spec->multiout.num_dacs = 0; /* no analog */
2772 spec->multiout.max_channels = 2;
2773 spec->multiout.dig_out_nid = cvt_nid;
2774 spec->num_cvts = 1;
2775 spec->num_pins = 1;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002776 per_pin = snd_array_new(&spec->pins);
2777 per_cvt = snd_array_new(&spec->cvts);
2778 if (!per_pin || !per_cvt) {
2779 simple_playback_free(codec);
2780 return -ENOMEM;
2781 }
2782 per_cvt->cvt_nid = cvt_nid;
2783 per_pin->pin_nid = pin_nid;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002784 spec->pcm_playback = simple_pcm_playback;
2785
2786 codec->patch_ops = simple_hdmi_patch_ops;
2787
2788 return 0;
2789}
2790
Aaron Plattner1f348522011-04-06 17:19:04 -07002791static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
2792 int channels)
2793{
2794 unsigned int chanmask;
2795 int chan = channels ? (channels - 1) : 1;
2796
2797 switch (channels) {
2798 default:
2799 case 0:
2800 case 2:
2801 chanmask = 0x00;
2802 break;
2803 case 4:
2804 chanmask = 0x08;
2805 break;
2806 case 6:
2807 chanmask = 0x0b;
2808 break;
2809 case 8:
2810 chanmask = 0x13;
2811 break;
2812 }
2813
2814 /* Set the audio infoframe channel allocation and checksum fields. The
2815 * channel count is computed implicitly by the hardware. */
2816 snd_hda_codec_write(codec, 0x1, 0,
2817 Nv_VERB_SET_Channel_Allocation, chanmask);
2818
2819 snd_hda_codec_write(codec, 0x1, 0,
2820 Nv_VERB_SET_Info_Frame_Checksum,
2821 (0x71 - chan - chanmask));
2822}
2823
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002824static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
2825 struct hda_codec *codec,
2826 struct snd_pcm_substream *substream)
2827{
2828 struct hdmi_spec *spec = codec->spec;
2829 int i;
2830
2831 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
2832 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
2833 for (i = 0; i < 4; i++) {
2834 /* set the stream id */
2835 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
2836 AC_VERB_SET_CHANNEL_STREAMID, 0);
2837 /* set the stream format */
2838 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
2839 AC_VERB_SET_STREAM_FORMAT, 0);
2840 }
2841
Aaron Plattner1f348522011-04-06 17:19:04 -07002842 /* The audio hardware sends a channel count of 0x7 (8ch) when all the
2843 * streams are disabled. */
2844 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
2845
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002846 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2847}
2848
2849static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
2850 struct hda_codec *codec,
2851 unsigned int stream_tag,
2852 unsigned int format,
2853 struct snd_pcm_substream *substream)
2854{
2855 int chs;
Takashi Iwai112daa72011-11-02 21:40:06 +01002856 unsigned int dataDCC2, channel_id;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002857 int i;
Stephen Warren7c935972011-06-01 11:14:17 -06002858 struct hdmi_spec *spec = codec->spec;
Takashi Iwaie3245cd2012-05-10 10:21:29 +02002859 struct hda_spdif_out *spdif;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002860 struct hdmi_spec_per_cvt *per_cvt;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002861
2862 mutex_lock(&codec->spdif_mutex);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002863 per_cvt = get_cvt(spec, 0);
2864 spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002865
2866 chs = substream->runtime->channels;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002867
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002868 dataDCC2 = 0x2;
2869
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002870 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
Stephen Warren7c935972011-06-01 11:14:17 -06002871 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002872 snd_hda_codec_write(codec,
2873 nvhdmi_master_con_nid_7x,
2874 0,
2875 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06002876 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002877
2878 /* set the stream id */
2879 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
2880 AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
2881
2882 /* set the stream format */
2883 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
2884 AC_VERB_SET_STREAM_FORMAT, format);
2885
2886 /* turn on again (if needed) */
2887 /* enable and set the channel status audio/data flag */
Stephen Warren7c935972011-06-01 11:14:17 -06002888 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002889 snd_hda_codec_write(codec,
2890 nvhdmi_master_con_nid_7x,
2891 0,
2892 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06002893 spdif->ctls & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002894 snd_hda_codec_write(codec,
2895 nvhdmi_master_con_nid_7x,
2896 0,
2897 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
2898 }
2899
2900 for (i = 0; i < 4; i++) {
2901 if (chs == 2)
2902 channel_id = 0;
2903 else
2904 channel_id = i * 2;
2905
2906 /* turn off SPDIF once;
2907 *otherwise the IEC958 bits won't be updated
2908 */
2909 if (codec->spdif_status_reset &&
Stephen Warren7c935972011-06-01 11:14:17 -06002910 (spdif->ctls & AC_DIG1_ENABLE))
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002911 snd_hda_codec_write(codec,
2912 nvhdmi_con_nids_7x[i],
2913 0,
2914 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06002915 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002916 /* set the stream id */
2917 snd_hda_codec_write(codec,
2918 nvhdmi_con_nids_7x[i],
2919 0,
2920 AC_VERB_SET_CHANNEL_STREAMID,
2921 (stream_tag << 4) | channel_id);
2922 /* set the stream format */
2923 snd_hda_codec_write(codec,
2924 nvhdmi_con_nids_7x[i],
2925 0,
2926 AC_VERB_SET_STREAM_FORMAT,
2927 format);
2928 /* turn on again (if needed) */
2929 /* enable and set the channel status audio/data flag */
2930 if (codec->spdif_status_reset &&
Stephen Warren7c935972011-06-01 11:14:17 -06002931 (spdif->ctls & AC_DIG1_ENABLE)) {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002932 snd_hda_codec_write(codec,
2933 nvhdmi_con_nids_7x[i],
2934 0,
2935 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06002936 spdif->ctls & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002937 snd_hda_codec_write(codec,
2938 nvhdmi_con_nids_7x[i],
2939 0,
2940 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
2941 }
2942 }
2943
Aaron Plattner1f348522011-04-06 17:19:04 -07002944 nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002945
2946 mutex_unlock(&codec->spdif_mutex);
2947 return 0;
2948}
2949
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02002950static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002951 .substreams = 1,
2952 .channels_min = 2,
2953 .channels_max = 8,
2954 .nid = nvhdmi_master_con_nid_7x,
2955 .rates = SUPPORTED_RATES,
2956 .maxbps = SUPPORTED_MAXBPS,
2957 .formats = SUPPORTED_FORMATS,
2958 .ops = {
2959 .open = simple_playback_pcm_open,
2960 .close = nvhdmi_8ch_7x_pcm_close,
2961 .prepare = nvhdmi_8ch_7x_pcm_prepare
2962 },
2963};
2964
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002965static int patch_nvhdmi_2ch(struct hda_codec *codec)
2966{
2967 struct hdmi_spec *spec;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002968 int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
2969 nvhdmi_master_pin_nid_7x);
2970 if (err < 0)
2971 return err;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002972
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02002973 codec->patch_ops.init = nvhdmi_7x_init_2ch;
Takashi Iwaid0b12522012-06-15 14:34:42 +02002974 /* override the PCM rates, etc, as the codec doesn't give full list */
2975 spec = codec->spec;
2976 spec->pcm_playback.rates = SUPPORTED_RATES;
2977 spec->pcm_playback.maxbps = SUPPORTED_MAXBPS;
2978 spec->pcm_playback.formats = SUPPORTED_FORMATS;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002979 return 0;
2980}
2981
Takashi Iwai53775b02012-08-01 12:17:41 +02002982static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
2983{
2984 struct hdmi_spec *spec = codec->spec;
2985 int err = simple_playback_build_pcms(codec);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002986 if (!err) {
2987 struct hda_pcm *info = get_pcm_rec(spec, 0);
2988 info->own_chmap = true;
2989 }
Takashi Iwai53775b02012-08-01 12:17:41 +02002990 return err;
2991}
2992
2993static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
2994{
2995 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002996 struct hda_pcm *info;
Takashi Iwai53775b02012-08-01 12:17:41 +02002997 struct snd_pcm_chmap *chmap;
2998 int err;
2999
3000 err = simple_playback_build_controls(codec);
3001 if (err < 0)
3002 return err;
3003
3004 /* add channel maps */
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01003005 info = get_pcm_rec(spec, 0);
3006 err = snd_pcm_add_chmap_ctls(info->pcm,
Takashi Iwai53775b02012-08-01 12:17:41 +02003007 SNDRV_PCM_STREAM_PLAYBACK,
3008 snd_pcm_alt_chmaps, 8, 0, &chmap);
3009 if (err < 0)
3010 return err;
Takashi Iwaib9a94a92015-10-01 16:20:04 +02003011 switch (codec->preset->vendor_id) {
Takashi Iwai53775b02012-08-01 12:17:41 +02003012 case 0x10de0002:
3013 case 0x10de0003:
3014 case 0x10de0005:
3015 case 0x10de0006:
3016 chmap->channel_mask = (1U << 2) | (1U << 8);
3017 break;
3018 case 0x10de0007:
3019 chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8);
3020 }
3021 return 0;
3022}
3023
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003024static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
3025{
3026 struct hdmi_spec *spec;
3027 int err = patch_nvhdmi_2ch(codec);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003028 if (err < 0)
3029 return err;
3030 spec = codec->spec;
3031 spec->multiout.max_channels = 8;
Takashi Iwaid0b12522012-06-15 14:34:42 +02003032 spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x;
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02003033 codec->patch_ops.init = nvhdmi_7x_init_8ch;
Takashi Iwai53775b02012-08-01 12:17:41 +02003034 codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
3035 codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
Aaron Plattner1f348522011-04-06 17:19:04 -07003036
3037 /* Initialize the audio infoframe channel mask and checksum to something
3038 * valid */
3039 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
3040
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003041 return 0;
3042}
3043
3044/*
Anssi Hannula611885b2013-11-03 17:15:00 +02003045 * NVIDIA codecs ignore ASP mapping for 2ch - confirmed on:
3046 * - 0x10de0015
3047 * - 0x10de0040
3048 */
3049static int nvhdmi_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap,
3050 int channels)
3051{
3052 if (cap->ca_index == 0x00 && channels == 2)
3053 return SNDRV_CTL_TLVT_CHMAP_FIXED;
3054
3055 return hdmi_chmap_cea_alloc_validate_get_type(cap, channels);
3056}
3057
3058static int nvhdmi_chmap_validate(int ca, int chs, unsigned char *map)
3059{
3060 if (ca == 0x00 && (map[0] != SNDRV_CHMAP_FL || map[1] != SNDRV_CHMAP_FR))
3061 return -EINVAL;
3062
3063 return 0;
3064}
3065
3066static int patch_nvhdmi(struct hda_codec *codec)
3067{
3068 struct hdmi_spec *spec;
3069 int err;
3070
3071 err = patch_generic_hdmi(codec);
3072 if (err)
3073 return err;
3074
3075 spec = codec->spec;
Stephen Warren75fae112014-01-30 11:52:16 -07003076 spec->dyn_pin_out = true;
Anssi Hannula611885b2013-11-03 17:15:00 +02003077
3078 spec->ops.chmap_cea_alloc_validate_get_type =
3079 nvhdmi_chmap_cea_alloc_validate_get_type;
3080 spec->ops.chmap_validate = nvhdmi_chmap_validate;
3081
3082 return 0;
3083}
3084
3085/*
Thierry Reding26e9a962015-05-05 14:56:20 +02003086 * The HDA codec on NVIDIA Tegra contains two scratch registers that are
3087 * accessed using vendor-defined verbs. These registers can be used for
3088 * interoperability between the HDA and HDMI drivers.
3089 */
3090
3091/* Audio Function Group node */
3092#define NVIDIA_AFG_NID 0x01
3093
3094/*
3095 * The SCRATCH0 register is used to notify the HDMI codec of changes in audio
3096 * format. On Tegra, bit 31 is used as a trigger that causes an interrupt to
3097 * be raised in the HDMI codec. The remainder of the bits is arbitrary. This
3098 * implementation stores the HDA format (see AC_FMT_*) in bits [15:0] and an
3099 * additional bit (at position 30) to signal the validity of the format.
3100 *
3101 * | 31 | 30 | 29 16 | 15 0 |
3102 * +---------+-------+--------+--------+
3103 * | TRIGGER | VALID | UNUSED | FORMAT |
3104 * +-----------------------------------|
3105 *
3106 * Note that for the trigger bit to take effect it needs to change value
3107 * (i.e. it needs to be toggled).
3108 */
3109#define NVIDIA_GET_SCRATCH0 0xfa6
3110#define NVIDIA_SET_SCRATCH0_BYTE0 0xfa7
3111#define NVIDIA_SET_SCRATCH0_BYTE1 0xfa8
3112#define NVIDIA_SET_SCRATCH0_BYTE2 0xfa9
3113#define NVIDIA_SET_SCRATCH0_BYTE3 0xfaa
3114#define NVIDIA_SCRATCH_TRIGGER (1 << 7)
3115#define NVIDIA_SCRATCH_VALID (1 << 6)
3116
3117#define NVIDIA_GET_SCRATCH1 0xfab
3118#define NVIDIA_SET_SCRATCH1_BYTE0 0xfac
3119#define NVIDIA_SET_SCRATCH1_BYTE1 0xfad
3120#define NVIDIA_SET_SCRATCH1_BYTE2 0xfae
3121#define NVIDIA_SET_SCRATCH1_BYTE3 0xfaf
3122
3123/*
3124 * The format parameter is the HDA audio format (see AC_FMT_*). If set to 0,
3125 * the format is invalidated so that the HDMI codec can be disabled.
3126 */
3127static void tegra_hdmi_set_format(struct hda_codec *codec, unsigned int format)
3128{
3129 unsigned int value;
3130
3131 /* bits [31:30] contain the trigger and valid bits */
3132 value = snd_hda_codec_read(codec, NVIDIA_AFG_NID, 0,
3133 NVIDIA_GET_SCRATCH0, 0);
3134 value = (value >> 24) & 0xff;
3135
3136 /* bits [15:0] are used to store the HDA format */
3137 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3138 NVIDIA_SET_SCRATCH0_BYTE0,
3139 (format >> 0) & 0xff);
3140 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3141 NVIDIA_SET_SCRATCH0_BYTE1,
3142 (format >> 8) & 0xff);
3143
3144 /* bits [16:24] are unused */
3145 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3146 NVIDIA_SET_SCRATCH0_BYTE2, 0);
3147
3148 /*
3149 * Bit 30 signals that the data is valid and hence that HDMI audio can
3150 * be enabled.
3151 */
3152 if (format == 0)
3153 value &= ~NVIDIA_SCRATCH_VALID;
3154 else
3155 value |= NVIDIA_SCRATCH_VALID;
3156
3157 /*
3158 * Whenever the trigger bit is toggled, an interrupt is raised in the
3159 * HDMI codec. The HDMI driver will use that as trigger to update its
3160 * configuration.
3161 */
3162 value ^= NVIDIA_SCRATCH_TRIGGER;
3163
3164 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3165 NVIDIA_SET_SCRATCH0_BYTE3, value);
3166}
3167
3168static int tegra_hdmi_pcm_prepare(struct hda_pcm_stream *hinfo,
3169 struct hda_codec *codec,
3170 unsigned int stream_tag,
3171 unsigned int format,
3172 struct snd_pcm_substream *substream)
3173{
3174 int err;
3175
3176 err = generic_hdmi_playback_pcm_prepare(hinfo, codec, stream_tag,
3177 format, substream);
3178 if (err < 0)
3179 return err;
3180
3181 /* notify the HDMI codec of the format change */
3182 tegra_hdmi_set_format(codec, format);
3183
3184 return 0;
3185}
3186
3187static int tegra_hdmi_pcm_cleanup(struct hda_pcm_stream *hinfo,
3188 struct hda_codec *codec,
3189 struct snd_pcm_substream *substream)
3190{
3191 /* invalidate the format in the HDMI codec */
3192 tegra_hdmi_set_format(codec, 0);
3193
3194 return generic_hdmi_playback_pcm_cleanup(hinfo, codec, substream);
3195}
3196
3197static struct hda_pcm *hda_find_pcm_by_type(struct hda_codec *codec, int type)
3198{
3199 struct hdmi_spec *spec = codec->spec;
3200 unsigned int i;
3201
3202 for (i = 0; i < spec->num_pins; i++) {
3203 struct hda_pcm *pcm = get_pcm_rec(spec, i);
3204
3205 if (pcm->pcm_type == type)
3206 return pcm;
3207 }
3208
3209 return NULL;
3210}
3211
3212static int tegra_hdmi_build_pcms(struct hda_codec *codec)
3213{
3214 struct hda_pcm_stream *stream;
3215 struct hda_pcm *pcm;
3216 int err;
3217
3218 err = generic_hdmi_build_pcms(codec);
3219 if (err < 0)
3220 return err;
3221
3222 pcm = hda_find_pcm_by_type(codec, HDA_PCM_TYPE_HDMI);
3223 if (!pcm)
3224 return -ENODEV;
3225
3226 /*
3227 * Override ->prepare() and ->cleanup() operations to notify the HDMI
3228 * codec about format changes.
3229 */
3230 stream = &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
3231 stream->ops.prepare = tegra_hdmi_pcm_prepare;
3232 stream->ops.cleanup = tegra_hdmi_pcm_cleanup;
3233
3234 return 0;
3235}
3236
3237static int patch_tegra_hdmi(struct hda_codec *codec)
3238{
3239 int err;
3240
3241 err = patch_generic_hdmi(codec);
3242 if (err)
3243 return err;
3244
3245 codec->patch_ops.build_pcms = tegra_hdmi_build_pcms;
3246
3247 return 0;
3248}
3249
3250/*
Anssi Hannula5a6135842013-10-24 21:10:35 +03003251 * ATI/AMD-specific implementations
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003252 */
3253
Anssi Hannula5a6135842013-10-24 21:10:35 +03003254#define is_amdhdmi_rev3_or_later(codec) \
Takashi Iwai7639a062015-03-03 10:07:24 +01003255 ((codec)->core.vendor_id == 0x1002aa01 && \
3256 ((codec)->core.revision_id & 0xff00) >= 0x0300)
Anssi Hannula5a6135842013-10-24 21:10:35 +03003257#define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec)
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003258
Anssi Hannula5a6135842013-10-24 21:10:35 +03003259/* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */
3260#define ATI_VERB_SET_CHANNEL_ALLOCATION 0x771
3261#define ATI_VERB_SET_DOWNMIX_INFO 0x772
3262#define ATI_VERB_SET_MULTICHANNEL_01 0x777
3263#define ATI_VERB_SET_MULTICHANNEL_23 0x778
3264#define ATI_VERB_SET_MULTICHANNEL_45 0x779
3265#define ATI_VERB_SET_MULTICHANNEL_67 0x77a
Anssi Hannula461cf6b2013-10-24 21:10:37 +03003266#define ATI_VERB_SET_HBR_CONTROL 0x77c
Anssi Hannula5a6135842013-10-24 21:10:35 +03003267#define ATI_VERB_SET_MULTICHANNEL_1 0x785
3268#define ATI_VERB_SET_MULTICHANNEL_3 0x786
3269#define ATI_VERB_SET_MULTICHANNEL_5 0x787
3270#define ATI_VERB_SET_MULTICHANNEL_7 0x788
3271#define ATI_VERB_SET_MULTICHANNEL_MODE 0x789
3272#define ATI_VERB_GET_CHANNEL_ALLOCATION 0xf71
3273#define ATI_VERB_GET_DOWNMIX_INFO 0xf72
3274#define ATI_VERB_GET_MULTICHANNEL_01 0xf77
3275#define ATI_VERB_GET_MULTICHANNEL_23 0xf78
3276#define ATI_VERB_GET_MULTICHANNEL_45 0xf79
3277#define ATI_VERB_GET_MULTICHANNEL_67 0xf7a
Anssi Hannula461cf6b2013-10-24 21:10:37 +03003278#define ATI_VERB_GET_HBR_CONTROL 0xf7c
Anssi Hannula5a6135842013-10-24 21:10:35 +03003279#define ATI_VERB_GET_MULTICHANNEL_1 0xf85
3280#define ATI_VERB_GET_MULTICHANNEL_3 0xf86
3281#define ATI_VERB_GET_MULTICHANNEL_5 0xf87
3282#define ATI_VERB_GET_MULTICHANNEL_7 0xf88
3283#define ATI_VERB_GET_MULTICHANNEL_MODE 0xf89
3284
Anssi Hannula84d69e72013-10-24 21:10:38 +03003285/* AMD specific HDA cvt verbs */
3286#define ATI_VERB_SET_RAMP_RATE 0x770
3287#define ATI_VERB_GET_RAMP_RATE 0xf70
3288
Anssi Hannula5a6135842013-10-24 21:10:35 +03003289#define ATI_OUT_ENABLE 0x1
3290
3291#define ATI_MULTICHANNEL_MODE_PAIRED 0
3292#define ATI_MULTICHANNEL_MODE_SINGLE 1
3293
Anssi Hannula461cf6b2013-10-24 21:10:37 +03003294#define ATI_HBR_CAPABLE 0x01
3295#define ATI_HBR_ENABLE 0x10
3296
Anssi Hannula89250f82013-10-24 21:10:36 +03003297static int atihdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
3298 unsigned char *buf, int *eld_size)
3299{
3300 /* call hda_eld.c ATI/AMD-specific function */
3301 return snd_hdmi_get_eld_ati(codec, nid, buf, eld_size,
3302 is_amdhdmi_rev3_or_later(codec));
3303}
3304
Anssi Hannula5a6135842013-10-24 21:10:35 +03003305static void atihdmi_pin_setup_infoframe(struct hda_codec *codec, hda_nid_t pin_nid, int ca,
3306 int active_channels, int conn_type)
3307{
3308 snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_CHANNEL_ALLOCATION, ca);
3309}
3310
3311static int atihdmi_paired_swap_fc_lfe(int pos)
3312{
3313 /*
3314 * ATI/AMD have automatic FC/LFE swap built-in
3315 * when in pairwise mapping mode.
3316 */
3317
3318 switch (pos) {
3319 /* see channel_allocations[].speakers[] */
3320 case 2: return 3;
3321 case 3: return 2;
3322 default: break;
3323 }
3324
3325 return pos;
3326}
3327
3328static int atihdmi_paired_chmap_validate(int ca, int chs, unsigned char *map)
3329{
3330 struct cea_channel_speaker_allocation *cap;
3331 int i, j;
3332
3333 /* check that only channel pairs need to be remapped on old pre-rev3 ATI/AMD */
3334
3335 cap = &channel_allocations[get_channel_allocation_order(ca)];
3336 for (i = 0; i < chs; ++i) {
3337 int mask = to_spk_mask(map[i]);
3338 bool ok = false;
3339 bool companion_ok = false;
3340
3341 if (!mask)
3342 continue;
3343
3344 for (j = 0 + i % 2; j < 8; j += 2) {
3345 int chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j);
3346 if (cap->speakers[chan_idx] == mask) {
3347 /* channel is in a supported position */
3348 ok = true;
3349
3350 if (i % 2 == 0 && i + 1 < chs) {
3351 /* even channel, check the odd companion */
3352 int comp_chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j + 1);
3353 int comp_mask_req = to_spk_mask(map[i+1]);
3354 int comp_mask_act = cap->speakers[comp_chan_idx];
3355
3356 if (comp_mask_req == comp_mask_act)
3357 companion_ok = true;
3358 else
3359 return -EINVAL;
3360 }
3361 break;
3362 }
3363 }
3364
3365 if (!ok)
3366 return -EINVAL;
3367
3368 if (companion_ok)
3369 i++; /* companion channel already checked */
3370 }
3371
3372 return 0;
3373}
3374
3375static int atihdmi_pin_set_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
3376 int hdmi_slot, int stream_channel)
3377{
3378 int verb;
3379 int ati_channel_setup = 0;
3380
3381 if (hdmi_slot > 7)
3382 return -EINVAL;
3383
3384 if (!has_amd_full_remap_support(codec)) {
3385 hdmi_slot = atihdmi_paired_swap_fc_lfe(hdmi_slot);
3386
3387 /* In case this is an odd slot but without stream channel, do not
3388 * disable the slot since the corresponding even slot could have a
3389 * channel. In case neither have a channel, the slot pair will be
3390 * disabled when this function is called for the even slot. */
3391 if (hdmi_slot % 2 != 0 && stream_channel == 0xf)
3392 return 0;
3393
3394 hdmi_slot -= hdmi_slot % 2;
3395
3396 if (stream_channel != 0xf)
3397 stream_channel -= stream_channel % 2;
3398 }
3399
3400 verb = ATI_VERB_SET_MULTICHANNEL_01 + hdmi_slot/2 + (hdmi_slot % 2) * 0x00e;
3401
3402 /* ati_channel_setup format: [7..4] = stream_channel_id, [1] = mute, [0] = enable */
3403
3404 if (stream_channel != 0xf)
3405 ati_channel_setup = (stream_channel << 4) | ATI_OUT_ENABLE;
3406
3407 return snd_hda_codec_write(codec, pin_nid, 0, verb, ati_channel_setup);
3408}
3409
3410static int atihdmi_pin_get_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
3411 int asp_slot)
3412{
3413 bool was_odd = false;
3414 int ati_asp_slot = asp_slot;
3415 int verb;
3416 int ati_channel_setup;
3417
3418 if (asp_slot > 7)
3419 return -EINVAL;
3420
3421 if (!has_amd_full_remap_support(codec)) {
3422 ati_asp_slot = atihdmi_paired_swap_fc_lfe(asp_slot);
3423 if (ati_asp_slot % 2 != 0) {
3424 ati_asp_slot -= 1;
3425 was_odd = true;
3426 }
3427 }
3428
3429 verb = ATI_VERB_GET_MULTICHANNEL_01 + ati_asp_slot/2 + (ati_asp_slot % 2) * 0x00e;
3430
3431 ati_channel_setup = snd_hda_codec_read(codec, pin_nid, 0, verb, 0);
3432
3433 if (!(ati_channel_setup & ATI_OUT_ENABLE))
3434 return 0xf;
3435
3436 return ((ati_channel_setup & 0xf0) >> 4) + !!was_odd;
3437}
3438
3439static int atihdmi_paired_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap,
3440 int channels)
3441{
3442 int c;
3443
3444 /*
3445 * Pre-rev3 ATI/AMD codecs operate in a paired channel mode, so
3446 * we need to take that into account (a single channel may take 2
3447 * channel slots if we need to carry a silent channel next to it).
3448 * On Rev3+ AMD codecs this function is not used.
3449 */
3450 int chanpairs = 0;
3451
3452 /* We only produce even-numbered channel count TLVs */
3453 if ((channels % 2) != 0)
3454 return -1;
3455
3456 for (c = 0; c < 7; c += 2) {
3457 if (cap->speakers[c] || cap->speakers[c+1])
3458 chanpairs++;
3459 }
3460
3461 if (chanpairs * 2 != channels)
3462 return -1;
3463
3464 return SNDRV_CTL_TLVT_CHMAP_PAIRED;
3465}
3466
3467static void atihdmi_paired_cea_alloc_to_tlv_chmap(struct cea_channel_speaker_allocation *cap,
3468 unsigned int *chmap, int channels)
3469{
3470 /* produce paired maps for pre-rev3 ATI/AMD codecs */
3471 int count = 0;
3472 int c;
3473
3474 for (c = 7; c >= 0; c--) {
3475 int chan = 7 - atihdmi_paired_swap_fc_lfe(7 - c);
3476 int spk = cap->speakers[chan];
3477 if (!spk) {
3478 /* add N/A channel if the companion channel is occupied */
3479 if (cap->speakers[chan + (chan % 2 ? -1 : 1)])
3480 chmap[count++] = SNDRV_CHMAP_NA;
3481
3482 continue;
3483 }
3484
3485 chmap[count++] = spk_to_chmap(spk);
3486 }
3487
3488 WARN_ON(count != channels);
3489}
3490
Anssi Hannula461cf6b2013-10-24 21:10:37 +03003491static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
3492 bool hbr)
3493{
3494 int hbr_ctl, hbr_ctl_new;
3495
3496 hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0);
Anssi Hannula13122e62013-11-10 20:56:10 +02003497 if (hbr_ctl >= 0 && (hbr_ctl & ATI_HBR_CAPABLE)) {
Anssi Hannula461cf6b2013-10-24 21:10:37 +03003498 if (hbr)
3499 hbr_ctl_new = hbr_ctl | ATI_HBR_ENABLE;
3500 else
3501 hbr_ctl_new = hbr_ctl & ~ATI_HBR_ENABLE;
3502
Takashi Iwai4e76a882014-02-25 12:21:03 +01003503 codec_dbg(codec,
3504 "atihdmi_pin_hbr_setup: NID=0x%x, %shbr-ctl=0x%x\n",
Anssi Hannula461cf6b2013-10-24 21:10:37 +03003505 pin_nid,
3506 hbr_ctl == hbr_ctl_new ? "" : "new-",
3507 hbr_ctl_new);
3508
3509 if (hbr_ctl != hbr_ctl_new)
3510 snd_hda_codec_write(codec, pin_nid, 0,
3511 ATI_VERB_SET_HBR_CONTROL,
3512 hbr_ctl_new);
3513
3514 } else if (hbr)
3515 return -EINVAL;
3516
3517 return 0;
3518}
3519
Anssi Hannula84d69e72013-10-24 21:10:38 +03003520static int atihdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
3521 hda_nid_t pin_nid, u32 stream_tag, int format)
3522{
3523
3524 if (is_amdhdmi_rev3_or_later(codec)) {
3525 int ramp_rate = 180; /* default as per AMD spec */
3526 /* disable ramp-up/down for non-pcm as per AMD spec */
3527 if (format & AC_FMT_TYPE_NON_PCM)
3528 ramp_rate = 0;
3529
3530 snd_hda_codec_write(codec, cvt_nid, 0, ATI_VERB_SET_RAMP_RATE, ramp_rate);
3531 }
3532
3533 return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
3534}
3535
3536
Anssi Hannula5a6135842013-10-24 21:10:35 +03003537static int atihdmi_init(struct hda_codec *codec)
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003538{
3539 struct hdmi_spec *spec = codec->spec;
Anssi Hannula5a6135842013-10-24 21:10:35 +03003540 int pin_idx, err;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003541
Anssi Hannula5a6135842013-10-24 21:10:35 +03003542 err = generic_hdmi_init(codec);
3543
3544 if (err)
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003545 return err;
Anssi Hannula5a6135842013-10-24 21:10:35 +03003546
3547 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
3548 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
3549
3550 /* make sure downmix information in infoframe is zero */
3551 snd_hda_codec_write(codec, per_pin->pin_nid, 0, ATI_VERB_SET_DOWNMIX_INFO, 0);
3552
3553 /* enable channel-wise remap mode if supported */
3554 if (has_amd_full_remap_support(codec))
3555 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
3556 ATI_VERB_SET_MULTICHANNEL_MODE,
3557 ATI_MULTICHANNEL_MODE_SINGLE);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003558 }
Anssi Hannula5a6135842013-10-24 21:10:35 +03003559
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003560 return 0;
3561}
3562
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003563static int patch_atihdmi(struct hda_codec *codec)
3564{
3565 struct hdmi_spec *spec;
Anssi Hannula5a6135842013-10-24 21:10:35 +03003566 struct hdmi_spec_per_cvt *per_cvt;
3567 int err, cvt_idx;
3568
3569 err = patch_generic_hdmi(codec);
3570
3571 if (err)
Takashi Iwaid0b12522012-06-15 14:34:42 +02003572 return err;
Anssi Hannula5a6135842013-10-24 21:10:35 +03003573
3574 codec->patch_ops.init = atihdmi_init;
3575
Takashi Iwaid0b12522012-06-15 14:34:42 +02003576 spec = codec->spec;
Anssi Hannula5a6135842013-10-24 21:10:35 +03003577
Anssi Hannula89250f82013-10-24 21:10:36 +03003578 spec->ops.pin_get_eld = atihdmi_pin_get_eld;
Anssi Hannula5a6135842013-10-24 21:10:35 +03003579 spec->ops.pin_get_slot_channel = atihdmi_pin_get_slot_channel;
3580 spec->ops.pin_set_slot_channel = atihdmi_pin_set_slot_channel;
3581 spec->ops.pin_setup_infoframe = atihdmi_pin_setup_infoframe;
Anssi Hannula461cf6b2013-10-24 21:10:37 +03003582 spec->ops.pin_hbr_setup = atihdmi_pin_hbr_setup;
Anssi Hannula84d69e72013-10-24 21:10:38 +03003583 spec->ops.setup_stream = atihdmi_setup_stream;
Anssi Hannula5a6135842013-10-24 21:10:35 +03003584
3585 if (!has_amd_full_remap_support(codec)) {
3586 /* override to ATI/AMD-specific versions with pairwise mapping */
3587 spec->ops.chmap_cea_alloc_validate_get_type =
3588 atihdmi_paired_chmap_cea_alloc_validate_get_type;
3589 spec->ops.cea_alloc_to_tlv_chmap = atihdmi_paired_cea_alloc_to_tlv_chmap;
3590 spec->ops.chmap_validate = atihdmi_paired_chmap_validate;
3591 }
3592
3593 /* ATI/AMD converters do not advertise all of their capabilities */
3594 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
3595 per_cvt = get_cvt(spec, cvt_idx);
3596 per_cvt->channels_max = max(per_cvt->channels_max, 8u);
3597 per_cvt->rates |= SUPPORTED_RATES;
3598 per_cvt->formats |= SUPPORTED_FORMATS;
3599 per_cvt->maxbps = max(per_cvt->maxbps, 24u);
3600 }
3601
3602 spec->channels_max = max(spec->channels_max, 8u);
3603
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003604 return 0;
3605}
3606
Annie Liu3de5ff82012-06-08 19:18:42 +08003607/* VIA HDMI Implementation */
3608#define VIAHDMI_CVT_NID 0x02 /* audio converter1 */
3609#define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */
3610
Annie Liu3de5ff82012-06-08 19:18:42 +08003611static int patch_via_hdmi(struct hda_codec *codec)
3612{
Takashi Iwai250e41a2012-06-15 14:40:21 +02003613 return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
Annie Liu3de5ff82012-06-08 19:18:42 +08003614}
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003615
3616/*
3617 * patch entries
3618 */
Takashi Iwaib9a94a92015-10-01 16:20:04 +02003619static const struct hda_device_id snd_hda_id_hdmi[] = {
3620HDA_CODEC_ENTRY(0x1002793c, "RS600 HDMI", patch_atihdmi),
3621HDA_CODEC_ENTRY(0x10027919, "RS600 HDMI", patch_atihdmi),
3622HDA_CODEC_ENTRY(0x1002791a, "RS690/780 HDMI", patch_atihdmi),
3623HDA_CODEC_ENTRY(0x1002aa01, "R6xx HDMI", patch_atihdmi),
3624HDA_CODEC_ENTRY(0x10951390, "SiI1390 HDMI", patch_generic_hdmi),
3625HDA_CODEC_ENTRY(0x10951392, "SiI1392 HDMI", patch_generic_hdmi),
3626HDA_CODEC_ENTRY(0x17e80047, "Chrontel HDMI", patch_generic_hdmi),
3627HDA_CODEC_ENTRY(0x10de0002, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3628HDA_CODEC_ENTRY(0x10de0003, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3629HDA_CODEC_ENTRY(0x10de0005, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3630HDA_CODEC_ENTRY(0x10de0006, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
3631HDA_CODEC_ENTRY(0x10de0007, "MCP79/7A HDMI", patch_nvhdmi_8ch_7x),
3632HDA_CODEC_ENTRY(0x10de000a, "GPU 0a HDMI/DP", patch_nvhdmi),
3633HDA_CODEC_ENTRY(0x10de000b, "GPU 0b HDMI/DP", patch_nvhdmi),
3634HDA_CODEC_ENTRY(0x10de000c, "MCP89 HDMI", patch_nvhdmi),
3635HDA_CODEC_ENTRY(0x10de000d, "GPU 0d HDMI/DP", patch_nvhdmi),
3636HDA_CODEC_ENTRY(0x10de0010, "GPU 10 HDMI/DP", patch_nvhdmi),
3637HDA_CODEC_ENTRY(0x10de0011, "GPU 11 HDMI/DP", patch_nvhdmi),
3638HDA_CODEC_ENTRY(0x10de0012, "GPU 12 HDMI/DP", patch_nvhdmi),
3639HDA_CODEC_ENTRY(0x10de0013, "GPU 13 HDMI/DP", patch_nvhdmi),
3640HDA_CODEC_ENTRY(0x10de0014, "GPU 14 HDMI/DP", patch_nvhdmi),
3641HDA_CODEC_ENTRY(0x10de0015, "GPU 15 HDMI/DP", patch_nvhdmi),
3642HDA_CODEC_ENTRY(0x10de0016, "GPU 16 HDMI/DP", patch_nvhdmi),
Richard Samsonc8900a02011-03-03 12:46:13 +01003643/* 17 is known to be absent */
Takashi Iwaib9a94a92015-10-01 16:20:04 +02003644HDA_CODEC_ENTRY(0x10de0018, "GPU 18 HDMI/DP", patch_nvhdmi),
3645HDA_CODEC_ENTRY(0x10de0019, "GPU 19 HDMI/DP", patch_nvhdmi),
3646HDA_CODEC_ENTRY(0x10de001a, "GPU 1a HDMI/DP", patch_nvhdmi),
3647HDA_CODEC_ENTRY(0x10de001b, "GPU 1b HDMI/DP", patch_nvhdmi),
3648HDA_CODEC_ENTRY(0x10de001c, "GPU 1c HDMI/DP", patch_nvhdmi),
3649HDA_CODEC_ENTRY(0x10de0020, "Tegra30 HDMI", patch_tegra_hdmi),
3650HDA_CODEC_ENTRY(0x10de0022, "Tegra114 HDMI", patch_tegra_hdmi),
3651HDA_CODEC_ENTRY(0x10de0028, "Tegra124 HDMI", patch_tegra_hdmi),
3652HDA_CODEC_ENTRY(0x10de0029, "Tegra210 HDMI/DP", patch_tegra_hdmi),
3653HDA_CODEC_ENTRY(0x10de0040, "GPU 40 HDMI/DP", patch_nvhdmi),
3654HDA_CODEC_ENTRY(0x10de0041, "GPU 41 HDMI/DP", patch_nvhdmi),
3655HDA_CODEC_ENTRY(0x10de0042, "GPU 42 HDMI/DP", patch_nvhdmi),
3656HDA_CODEC_ENTRY(0x10de0043, "GPU 43 HDMI/DP", patch_nvhdmi),
3657HDA_CODEC_ENTRY(0x10de0044, "GPU 44 HDMI/DP", patch_nvhdmi),
3658HDA_CODEC_ENTRY(0x10de0051, "GPU 51 HDMI/DP", patch_nvhdmi),
3659HDA_CODEC_ENTRY(0x10de0060, "GPU 60 HDMI/DP", patch_nvhdmi),
3660HDA_CODEC_ENTRY(0x10de0067, "MCP67 HDMI", patch_nvhdmi_2ch),
3661HDA_CODEC_ENTRY(0x10de0070, "GPU 70 HDMI/DP", patch_nvhdmi),
3662HDA_CODEC_ENTRY(0x10de0071, "GPU 71 HDMI/DP", patch_nvhdmi),
3663HDA_CODEC_ENTRY(0x10de0072, "GPU 72 HDMI/DP", patch_nvhdmi),
3664HDA_CODEC_ENTRY(0x10de007d, "GPU 7d HDMI/DP", patch_nvhdmi),
3665HDA_CODEC_ENTRY(0x10de8001, "MCP73 HDMI", patch_nvhdmi_2ch),
3666HDA_CODEC_ENTRY(0x11069f80, "VX900 HDMI/DP", patch_via_hdmi),
3667HDA_CODEC_ENTRY(0x11069f81, "VX900 HDMI/DP", patch_via_hdmi),
3668HDA_CODEC_ENTRY(0x11069f84, "VX11 HDMI/DP", patch_generic_hdmi),
3669HDA_CODEC_ENTRY(0x11069f85, "VX11 HDMI/DP", patch_generic_hdmi),
3670HDA_CODEC_ENTRY(0x80860054, "IbexPeak HDMI", patch_generic_hdmi),
3671HDA_CODEC_ENTRY(0x80862801, "Bearlake HDMI", patch_generic_hdmi),
3672HDA_CODEC_ENTRY(0x80862802, "Cantiga HDMI", patch_generic_hdmi),
3673HDA_CODEC_ENTRY(0x80862803, "Eaglelake HDMI", patch_generic_hdmi),
3674HDA_CODEC_ENTRY(0x80862804, "IbexPeak HDMI", patch_generic_hdmi),
3675HDA_CODEC_ENTRY(0x80862805, "CougarPoint HDMI", patch_generic_hdmi),
3676HDA_CODEC_ENTRY(0x80862806, "PantherPoint HDMI", patch_generic_hdmi),
3677HDA_CODEC_ENTRY(0x80862807, "Haswell HDMI", patch_generic_hdmi),
3678HDA_CODEC_ENTRY(0x80862808, "Broadwell HDMI", patch_generic_hdmi),
3679HDA_CODEC_ENTRY(0x80862809, "Skylake HDMI", patch_generic_hdmi),
3680HDA_CODEC_ENTRY(0x8086280a, "Broxton HDMI", patch_generic_hdmi),
Libin Yang91815d82016-01-14 14:09:00 +08003681HDA_CODEC_ENTRY(0x8086280b, "Kabylake HDMI", patch_generic_hdmi),
Takashi Iwaib9a94a92015-10-01 16:20:04 +02003682HDA_CODEC_ENTRY(0x80862880, "CedarTrail HDMI", patch_generic_hdmi),
3683HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_generic_hdmi),
3684HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_generic_hdmi),
3685HDA_CODEC_ENTRY(0x808629fb, "Crestline HDMI", patch_generic_hdmi),
Takashi Iwaid8a766a2015-02-17 15:25:37 +01003686/* special ID for generic HDMI */
Takashi Iwaib9a94a92015-10-01 16:20:04 +02003687HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC_HDMI, "Generic HDMI", patch_generic_hdmi),
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003688{} /* terminator */
3689};
Takashi Iwaib9a94a92015-10-01 16:20:04 +02003690MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_hdmi);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003691
3692MODULE_LICENSE("GPL");
3693MODULE_DESCRIPTION("HDMI HD-audio codec");
3694MODULE_ALIAS("snd-hda-codec-intelhdmi");
3695MODULE_ALIAS("snd-hda-codec-nvhdmi");
3696MODULE_ALIAS("snd-hda-codec-atihdmi");
3697
Takashi Iwaid8a766a2015-02-17 15:25:37 +01003698static struct hda_codec_driver hdmi_driver = {
Takashi Iwaib9a94a92015-10-01 16:20:04 +02003699 .id = snd_hda_id_hdmi,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003700};
3701
Takashi Iwaid8a766a2015-02-17 15:25:37 +01003702module_hda_codec_driver(hdmi_driver);