blob: 541986f414cb2c7b6d0e01832a3b337431e6abd7 [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;
Libin Yanga76056f2015-12-16 16:48:15 +080078 /* pin idx, different device entries on the same pin use the same idx */
79 int pin_nid_idx;
Stephen Warren384a48d2011-06-01 11:14:21 -060080 int num_mux_nids;
81 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
Mengdong Lin2df67422014-03-20 13:01:06 +080082 int mux_idx;
Anssi Hannula1df5a062013-10-05 02:25:40 +030083 hda_nid_t cvt_nid;
Wu Fengguang744626d2011-11-16 16:29:47 +080084
85 struct hda_codec *codec;
Stephen Warren384a48d2011-06-01 11:14:21 -060086 struct hdmi_eld sink_eld;
Takashi Iwaia4e9a382013-10-17 18:21:12 +020087 struct mutex lock;
Wu Fengguang744626d2011-11-16 16:29:47 +080088 struct delayed_work work;
David Henningsson92c69e72013-02-19 16:11:26 +010089 struct snd_kcontrol *eld_ctl;
Libin Yang2bea2412016-01-12 11:13:26 +080090 struct hdmi_pcm *pcm; /* pointer to spec->pcm_rec[n] dynamically*/
Libin Yanga76056f2015-12-16 16:48:15 +080091 int pcm_idx; /* which pcm is attached. -1 means no pcm is attached */
Wu Fengguangc6e84532011-11-18 16:59:32 -060092 int repoll_count;
Takashi Iwaib0540872013-09-02 12:33:02 +020093 bool setup; /* the stream has been set up by prepare callback */
94 int channels; /* current number of channels */
Takashi Iwai1a6003b2012-09-06 17:42:08 +020095 bool non_pcm;
Takashi Iwaid45e6882012-07-31 11:36:00 +020096 bool chmap_set; /* channel-map override by ALSA API? */
97 unsigned char chmap[8]; /* ALSA API channel-map */
Jie Yangcd6a6502015-05-27 19:45:45 +080098#ifdef CONFIG_SND_PROC_FS
Takashi Iwaia4e9a382013-10-17 18:21:12 +020099 struct snd_info_entry *proc_entry;
100#endif
Stephen Warren384a48d2011-06-01 11:14:21 -0600101};
102
Anssi Hannula307229d2013-10-24 21:10:34 +0300103struct cea_channel_speaker_allocation;
104
105/* operations used by generic code that can be overridden by patches */
106struct hdmi_ops {
107 int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid,
108 unsigned char *buf, int *eld_size);
109
110 /* get and set channel assigned to each HDMI ASP (audio sample packet) slot */
111 int (*pin_get_slot_channel)(struct hda_codec *codec, hda_nid_t pin_nid,
112 int asp_slot);
113 int (*pin_set_slot_channel)(struct hda_codec *codec, hda_nid_t pin_nid,
114 int asp_slot, int channel);
115
116 void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid,
117 int ca, int active_channels, int conn_type);
118
119 /* enable/disable HBR (HD passthrough) */
120 int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid, bool hbr);
121
122 int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid,
123 hda_nid_t pin_nid, u32 stream_tag, int format);
124
125 /* Helpers for producing the channel map TLVs. These can be overridden
126 * for devices that have non-standard mapping requirements. */
127 int (*chmap_cea_alloc_validate_get_type)(struct cea_channel_speaker_allocation *cap,
128 int channels);
129 void (*cea_alloc_to_tlv_chmap)(struct cea_channel_speaker_allocation *cap,
130 unsigned int *chmap, int channels);
131
132 /* check that the user-given chmap is supported */
133 int (*chmap_validate)(int ca, int channels, unsigned char *chmap);
134};
135
Libin Yang2bea2412016-01-12 11:13:26 +0800136struct hdmi_pcm {
137 struct hda_pcm *pcm;
138 struct snd_jack *jack;
139};
140
Wu Fengguang079d88c2010-03-08 10:44:23 +0800141struct hdmi_spec {
142 int num_cvts;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100143 struct snd_array cvts; /* struct hdmi_spec_per_cvt */
144 hda_nid_t cvt_nids[4]; /* only for haswell fix */
Stephen Warren384a48d2011-06-01 11:14:21 -0600145
Wu Fengguang079d88c2010-03-08 10:44:23 +0800146 int num_pins;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100147 struct snd_array pins; /* struct hdmi_spec_per_pin */
Libin Yang2bea2412016-01-12 11:13:26 +0800148 struct hdmi_pcm pcm_rec[16];
Libin Yang42b29872015-12-16 13:42:42 +0800149 struct mutex pcm_lock;
Libin Yanga76056f2015-12-16 16:48:15 +0800150 /* pcm_bitmap means which pcms have been assigned to pins*/
151 unsigned long pcm_bitmap;
Libin Yang2bf3c852015-12-16 13:42:43 +0800152 int pcm_used; /* counter of pcm_rec[] */
Libin Yangac983792015-12-16 16:48:16 +0800153 /* bitmap shows whether the pcm is opened in user space
154 * bit 0 means the first playback PCM (PCM3);
155 * bit 1 means the second playback PCM, and so on.
156 */
157 unsigned long pcm_in_use;
Takashi Iwaid45e6882012-07-31 11:36:00 +0200158 unsigned int channels_max; /* max over all cvts */
Wu Fengguang079d88c2010-03-08 10:44:23 +0800159
David Henningsson4bd038f2013-02-19 16:11:25 +0100160 struct hdmi_eld temp_eld;
Anssi Hannula307229d2013-10-24 21:10:34 +0300161 struct hdmi_ops ops;
Stephen Warren75fae112014-01-30 11:52:16 -0700162
163 bool dyn_pin_out;
Libin Yang6590faa2015-12-16 13:42:41 +0800164 bool dyn_pcm_assign;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800165 /*
Anssi Hannula5a6135842013-10-24 21:10:35 +0300166 * Non-generic VIA/NVIDIA specific
Wu Fengguang079d88c2010-03-08 10:44:23 +0800167 */
168 struct hda_multi_out multiout;
Takashi Iwaid0b12522012-06-15 14:34:42 +0200169 struct hda_pcm_stream pcm_playback;
David Henningsson25adc132015-08-19 10:48:58 +0200170
171 /* i915/powerwell (Haswell+/Valleyview+) specific */
172 struct i915_audio_component_audio_ops i915_audio_ops;
Takashi Iwai55913112015-12-10 13:03:29 +0100173 bool i915_bound; /* was i915 bound in this driver? */
Wu Fengguang079d88c2010-03-08 10:44:23 +0800174};
175
Takashi Iwaif4e30402015-12-10 13:01:28 +0100176#ifdef CONFIG_SND_HDA_I915
Takashi Iwai66032492015-12-01 16:49:35 +0100177#define codec_has_acomp(codec) \
178 ((codec)->bus->core.audio_component != NULL)
Takashi Iwaif4e30402015-12-10 13:01:28 +0100179#else
180#define codec_has_acomp(codec) false
181#endif
Wu Fengguang079d88c2010-03-08 10:44:23 +0800182
183struct hdmi_audio_infoframe {
184 u8 type; /* 0x84 */
185 u8 ver; /* 0x01 */
186 u8 len; /* 0x0a */
187
Wu Fengguang53d7d692010-09-21 14:25:49 +0800188 u8 checksum;
189
Wu Fengguang079d88c2010-03-08 10:44:23 +0800190 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
191 u8 SS01_SF24;
192 u8 CXT04;
193 u8 CA;
194 u8 LFEPBL01_LSV36_DM_INH7;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800195};
196
197struct dp_audio_infoframe {
198 u8 type; /* 0x84 */
199 u8 len; /* 0x1b */
200 u8 ver; /* 0x11 << 2 */
201
202 u8 CC02_CT47; /* match with HDMI infoframe from this on */
203 u8 SS01_SF24;
204 u8 CXT04;
205 u8 CA;
206 u8 LFEPBL01_LSV36_DM_INH7;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800207};
208
Takashi Iwai2b203dbb2011-02-11 12:17:30 +0100209union audio_infoframe {
210 struct hdmi_audio_infoframe hdmi;
211 struct dp_audio_infoframe dp;
212 u8 bytes[0];
213};
214
Wu Fengguang079d88c2010-03-08 10:44:23 +0800215/*
216 * CEA speaker placement:
217 *
218 * FLH FCH FRH
219 * FLW FL FLC FC FRC FR FRW
220 *
221 * LFE
222 * TC
223 *
224 * RL RLC RC RRC RR
225 *
226 * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
227 * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
228 */
229enum cea_speaker_placement {
230 FL = (1 << 0), /* Front Left */
231 FC = (1 << 1), /* Front Center */
232 FR = (1 << 2), /* Front Right */
233 FLC = (1 << 3), /* Front Left Center */
234 FRC = (1 << 4), /* Front Right Center */
235 RL = (1 << 5), /* Rear Left */
236 RC = (1 << 6), /* Rear Center */
237 RR = (1 << 7), /* Rear Right */
238 RLC = (1 << 8), /* Rear Left Center */
239 RRC = (1 << 9), /* Rear Right Center */
240 LFE = (1 << 10), /* Low Frequency Effect */
241 FLW = (1 << 11), /* Front Left Wide */
242 FRW = (1 << 12), /* Front Right Wide */
243 FLH = (1 << 13), /* Front Left High */
244 FCH = (1 << 14), /* Front Center High */
245 FRH = (1 << 15), /* Front Right High */
246 TC = (1 << 16), /* Top Center */
247};
248
249/*
250 * ELD SA bits in the CEA Speaker Allocation data block
251 */
252static int eld_speaker_allocation_bits[] = {
253 [0] = FL | FR,
254 [1] = LFE,
255 [2] = FC,
256 [3] = RL | RR,
257 [4] = RC,
258 [5] = FLC | FRC,
259 [6] = RLC | RRC,
260 /* the following are not defined in ELD yet */
261 [7] = FLW | FRW,
262 [8] = FLH | FRH,
263 [9] = TC,
264 [10] = FCH,
265};
266
267struct cea_channel_speaker_allocation {
268 int ca_index;
269 int speakers[8];
270
271 /* derived values, just for convenience */
272 int channels;
273 int spk_mask;
274};
275
276/*
277 * ALSA sequence is:
278 *
279 * surround40 surround41 surround50 surround51 surround71
280 * ch0 front left = = = =
281 * ch1 front right = = = =
282 * ch2 rear left = = = =
283 * ch3 rear right = = = =
284 * ch4 LFE center center center
285 * ch5 LFE LFE
286 * ch6 side left
287 * ch7 side right
288 *
289 * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR}
290 */
291static int hdmi_channel_mapping[0x32][8] = {
292 /* stereo */
293 [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
294 /* 2.1 */
295 [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
296 /* Dolby Surround */
297 [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 },
298 /* surround40 */
299 [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 },
300 /* 4ch */
301 [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 },
302 /* surround41 */
Jerry Zhou9396d312010-09-21 14:44:51 +0800303 [0x09] = { 0x00, 0x11, 0x24, 0x35, 0x42, 0xf3, 0xf6, 0xf7 },
Wu Fengguang079d88c2010-03-08 10:44:23 +0800304 /* surround50 */
305 [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 },
306 /* surround51 */
307 [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 },
308 /* 7.1 */
309 [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 },
310};
311
312/*
313 * This is an ordered list!
314 *
315 * The preceding ones have better chances to be selected by
Wu Fengguang53d7d692010-09-21 14:25:49 +0800316 * hdmi_channel_allocation().
Wu Fengguang079d88c2010-03-08 10:44:23 +0800317 */
318static struct cea_channel_speaker_allocation channel_allocations[] = {
319/* channel: 7 6 5 4 3 2 1 0 */
320{ .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
321 /* 2.1 */
322{ .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
323 /* Dolby Surround */
324{ .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
325 /* surround40 */
326{ .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
327 /* surround41 */
328{ .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
329 /* surround50 */
330{ .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
331 /* surround51 */
332{ .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
333 /* 6.1 */
334{ .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
335 /* surround71 */
336{ .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
337
338{ .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
339{ .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
340{ .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
341{ .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
342{ .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
343{ .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
344{ .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
345{ .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
346{ .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
347{ .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
348{ .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
349{ .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
350{ .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
351{ .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
352{ .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
353{ .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
354{ .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
355{ .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
356{ .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
357{ .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
358{ .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
359{ .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
360{ .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
361{ .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } },
362{ .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } },
363{ .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } },
364{ .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } },
365{ .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } },
366{ .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } },
367{ .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } },
368{ .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } },
369{ .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } },
370{ .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } },
371{ .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } },
372{ .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } },
373{ .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } },
374{ .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } },
375{ .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } },
376{ .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } },
377{ .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } },
378{ .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
379};
380
381
382/*
383 * HDMI routines
384 */
385
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100386#define get_pin(spec, idx) \
387 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx))
388#define get_cvt(spec, idx) \
389 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx))
Libin Yang2bea2412016-01-12 11:13:26 +0800390/* obtain hdmi_pcm object assigned to idx */
391#define get_hdmi_pcm(spec, idx) (&(spec)->pcm_rec[idx])
392/* obtain hda_pcm object assigned to idx */
393#define get_pcm_rec(spec, idx) (get_hdmi_pcm(spec, idx)->pcm)
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100394
Takashi Iwai4e76a882014-02-25 12:21:03 +0100395static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800396{
Takashi Iwai4e76a882014-02-25 12:21:03 +0100397 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -0600398 int pin_idx;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800399
Stephen Warren384a48d2011-06-01 11:14:21 -0600400 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100401 if (get_pin(spec, pin_idx)->pin_nid == pin_nid)
Stephen Warren384a48d2011-06-01 11:14:21 -0600402 return pin_idx;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800403
Takashi Iwai4e76a882014-02-25 12:21:03 +0100404 codec_warn(codec, "HDMI: pin nid %d not registered\n", pin_nid);
Stephen Warren384a48d2011-06-01 11:14:21 -0600405 return -EINVAL;
406}
407
Libin Yang2bf3c852015-12-16 13:42:43 +0800408static int hinfo_to_pcm_index(struct hda_codec *codec,
409 struct hda_pcm_stream *hinfo)
410{
411 struct hdmi_spec *spec = codec->spec;
412 int pcm_idx;
413
414 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++)
415 if (get_pcm_rec(spec, pcm_idx)->stream == hinfo)
416 return pcm_idx;
417
418 codec_warn(codec, "HDMI: hinfo %p not registered\n", hinfo);
419 return -EINVAL;
420}
421
Takashi Iwai4e76a882014-02-25 12:21:03 +0100422static int hinfo_to_pin_index(struct hda_codec *codec,
Stephen Warren384a48d2011-06-01 11:14:21 -0600423 struct hda_pcm_stream *hinfo)
424{
Takashi Iwai4e76a882014-02-25 12:21:03 +0100425 struct hdmi_spec *spec = codec->spec;
Libin Yang6590faa2015-12-16 13:42:41 +0800426 struct hdmi_spec_per_pin *per_pin;
Stephen Warren384a48d2011-06-01 11:14:21 -0600427 int pin_idx;
428
Libin Yang6590faa2015-12-16 13:42:41 +0800429 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
430 per_pin = get_pin(spec, pin_idx);
Libin Yang2bea2412016-01-12 11:13:26 +0800431 if (per_pin->pcm &&
432 per_pin->pcm->pcm->stream == hinfo)
Stephen Warren384a48d2011-06-01 11:14:21 -0600433 return pin_idx;
Libin Yang6590faa2015-12-16 13:42:41 +0800434 }
Stephen Warren384a48d2011-06-01 11:14:21 -0600435
Libin Yang6590faa2015-12-16 13:42:41 +0800436 codec_dbg(codec, "HDMI: hinfo %p not registered\n", hinfo);
Stephen Warren384a48d2011-06-01 11:14:21 -0600437 return -EINVAL;
438}
439
Libin Yang022f3442016-02-03 10:48:34 +0800440static struct hdmi_spec_per_pin *pcm_idx_to_pin(struct hdmi_spec *spec,
441 int pcm_idx)
442{
443 int i;
444 struct hdmi_spec_per_pin *per_pin;
445
446 for (i = 0; i < spec->num_pins; i++) {
447 per_pin = get_pin(spec, i);
448 if (per_pin->pcm_idx == pcm_idx)
449 return per_pin;
450 }
451 return NULL;
452}
453
Takashi Iwai4e76a882014-02-25 12:21:03 +0100454static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid)
Stephen Warren384a48d2011-06-01 11:14:21 -0600455{
Takashi Iwai4e76a882014-02-25 12:21:03 +0100456 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -0600457 int cvt_idx;
458
459 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100460 if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid)
Stephen Warren384a48d2011-06-01 11:14:21 -0600461 return cvt_idx;
462
Takashi Iwai4e76a882014-02-25 12:21:03 +0100463 codec_warn(codec, "HDMI: cvt nid %d not registered\n", cvt_nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800464 return -EINVAL;
465}
466
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500467static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
468 struct snd_ctl_elem_info *uinfo)
469{
470 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
David Henningsson68e03de2013-02-19 16:11:23 +0100471 struct hdmi_spec *spec = codec->spec;
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200472 struct hdmi_spec_per_pin *per_pin;
David Henningsson68e03de2013-02-19 16:11:23 +0100473 struct hdmi_eld *eld;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500474 int pin_idx;
475
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500476 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
477
478 pin_idx = kcontrol->private_value;
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200479 per_pin = get_pin(spec, pin_idx);
480 eld = &per_pin->sink_eld;
David Henningsson68e03de2013-02-19 16:11:23 +0100481
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200482 mutex_lock(&per_pin->lock);
David Henningsson68e03de2013-02-19 16:11:23 +0100483 uinfo->count = eld->eld_valid ? eld->eld_size : 0;
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200484 mutex_unlock(&per_pin->lock);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500485
486 return 0;
487}
488
489static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
490 struct snd_ctl_elem_value *ucontrol)
491{
492 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
David Henningsson68e03de2013-02-19 16:11:23 +0100493 struct hdmi_spec *spec = codec->spec;
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200494 struct hdmi_spec_per_pin *per_pin;
David Henningsson68e03de2013-02-19 16:11:23 +0100495 struct hdmi_eld *eld;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500496 int pin_idx;
497
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500498 pin_idx = kcontrol->private_value;
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200499 per_pin = get_pin(spec, pin_idx);
500 eld = &per_pin->sink_eld;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500501
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200502 mutex_lock(&per_pin->lock);
David Henningsson360a8242016-02-05 09:05:41 +0100503 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data) ||
504 eld->eld_size > ELD_MAX_SIZE) {
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200505 mutex_unlock(&per_pin->lock);
David Henningsson68e03de2013-02-19 16:11:23 +0100506 snd_BUG();
507 return -EINVAL;
508 }
509
510 memset(ucontrol->value.bytes.data, 0,
511 ARRAY_SIZE(ucontrol->value.bytes.data));
512 if (eld->eld_valid)
513 memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
514 eld->eld_size);
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200515 mutex_unlock(&per_pin->lock);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500516
517 return 0;
518}
519
520static struct snd_kcontrol_new eld_bytes_ctl = {
521 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
522 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
523 .name = "ELD",
524 .info = hdmi_eld_ctl_info,
525 .get = hdmi_eld_ctl_get,
526};
527
528static int hdmi_create_eld_ctl(struct hda_codec *codec, int pin_idx,
529 int device)
530{
531 struct snd_kcontrol *kctl;
532 struct hdmi_spec *spec = codec->spec;
533 int err;
534
535 kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
536 if (!kctl)
537 return -ENOMEM;
538 kctl->private_value = pin_idx;
539 kctl->id.device = device;
540
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100541 err = snd_hda_ctl_add(codec, get_pin(spec, pin_idx)->pin_nid, kctl);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500542 if (err < 0)
543 return err;
544
Takashi Iwaibce0d2a2013-03-13 14:40:31 +0100545 get_pin(spec, pin_idx)->eld_ctl = kctl;
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -0500546 return 0;
547}
548
Wu Fengguang079d88c2010-03-08 10:44:23 +0800549#ifdef BE_PARANOID
550static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
551 int *packet_index, int *byte_index)
552{
553 int val;
554
555 val = snd_hda_codec_read(codec, pin_nid, 0,
556 AC_VERB_GET_HDMI_DIP_INDEX, 0);
557
558 *packet_index = val >> 5;
559 *byte_index = val & 0x1f;
560}
561#endif
562
563static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
564 int packet_index, int byte_index)
565{
566 int val;
567
568 val = (packet_index << 5) | (byte_index & 0x1f);
569
570 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
571}
572
573static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
574 unsigned char val)
575{
576 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
577}
578
Stephen Warren384a48d2011-06-01 11:14:21 -0600579static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800580{
Stephen Warren75fae112014-01-30 11:52:16 -0700581 struct hdmi_spec *spec = codec->spec;
582 int pin_out;
583
Wu Fengguang079d88c2010-03-08 10:44:23 +0800584 /* Unmute */
585 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
586 snd_hda_codec_write(codec, pin_nid, 0,
587 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
Stephen Warren75fae112014-01-30 11:52:16 -0700588
589 if (spec->dyn_pin_out)
590 /* Disable pin out until stream is active */
591 pin_out = 0;
592 else
593 /* Enable pin out: some machines with GM965 gets broken output
594 * when the pin is disabled or changed while using with HDMI
595 */
596 pin_out = PIN_OUT;
597
Wu Fengguang079d88c2010-03-08 10:44:23 +0800598 snd_hda_codec_write(codec, pin_nid, 0,
Stephen Warren75fae112014-01-30 11:52:16 -0700599 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_out);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800600}
601
Stephen Warren384a48d2011-06-01 11:14:21 -0600602static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800603{
Stephen Warren384a48d2011-06-01 11:14:21 -0600604 return 1 + snd_hda_codec_read(codec, cvt_nid, 0,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800605 AC_VERB_GET_CVT_CHAN_COUNT, 0);
606}
607
608static void hdmi_set_channel_count(struct hda_codec *codec,
Stephen Warren384a48d2011-06-01 11:14:21 -0600609 hda_nid_t cvt_nid, int chs)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800610{
Stephen Warren384a48d2011-06-01 11:14:21 -0600611 if (chs != hdmi_get_channel_count(codec, cvt_nid))
612 snd_hda_codec_write(codec, cvt_nid, 0,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800613 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
614}
615
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200616/*
617 * ELD proc files
618 */
619
Jie Yangcd6a6502015-05-27 19:45:45 +0800620#ifdef CONFIG_SND_PROC_FS
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200621static void print_eld_info(struct snd_info_entry *entry,
622 struct snd_info_buffer *buffer)
623{
624 struct hdmi_spec_per_pin *per_pin = entry->private_data;
625
626 mutex_lock(&per_pin->lock);
627 snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer);
628 mutex_unlock(&per_pin->lock);
629}
630
631static void write_eld_info(struct snd_info_entry *entry,
632 struct snd_info_buffer *buffer)
633{
634 struct hdmi_spec_per_pin *per_pin = entry->private_data;
635
636 mutex_lock(&per_pin->lock);
637 snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer);
638 mutex_unlock(&per_pin->lock);
639}
640
641static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
642{
643 char name[32];
644 struct hda_codec *codec = per_pin->codec;
645 struct snd_info_entry *entry;
646 int err;
647
648 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
Takashi Iwai6efdd852015-02-27 16:09:22 +0100649 err = snd_card_proc_new(codec->card, name, &entry);
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200650 if (err < 0)
651 return err;
652
653 snd_info_set_text_ops(entry, per_pin, print_eld_info);
654 entry->c.text.write = write_eld_info;
655 entry->mode |= S_IWUSR;
656 per_pin->proc_entry = entry;
657
658 return 0;
659}
660
661static void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
662{
Markus Elfring1947a112015-06-28 11:15:28 +0200663 if (!per_pin->codec->bus->shutdown) {
Takashi Iwaic560a672015-04-22 18:26:38 +0200664 snd_info_free_entry(per_pin->proc_entry);
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200665 per_pin->proc_entry = NULL;
666 }
667}
668#else
Takashi Iwaib55447a2013-10-21 16:31:45 +0200669static inline int eld_proc_new(struct hdmi_spec_per_pin *per_pin,
670 int index)
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200671{
672 return 0;
673}
Takashi Iwaib55447a2013-10-21 16:31:45 +0200674static inline void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
Takashi Iwaia4e9a382013-10-17 18:21:12 +0200675{
676}
677#endif
Wu Fengguang079d88c2010-03-08 10:44:23 +0800678
679/*
680 * Channel mapping routines
681 */
682
683/*
684 * Compute derived values in channel_allocations[].
685 */
686static void init_channel_allocations(void)
687{
688 int i, j;
689 struct cea_channel_speaker_allocation *p;
690
691 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
692 p = channel_allocations + i;
693 p->channels = 0;
694 p->spk_mask = 0;
695 for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
696 if (p->speakers[j]) {
697 p->channels++;
698 p->spk_mask |= p->speakers[j];
699 }
700 }
701}
702
Wang Xingchao72357c72012-09-06 10:02:36 +0800703static int get_channel_allocation_order(int ca)
704{
705 int i;
706
707 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
708 if (channel_allocations[i].ca_index == ca)
709 break;
710 }
711 return i;
712}
713
Wu Fengguang079d88c2010-03-08 10:44:23 +0800714/*
715 * The transformation takes two steps:
716 *
717 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
718 * spk_mask => (channel_allocations[]) => ai->CA
719 *
720 * TODO: it could select the wrong CA from multiple candidates.
721*/
Takashi Iwai79514d42014-06-06 18:04:34 +0200722static int hdmi_channel_allocation(struct hda_codec *codec,
723 struct hdmi_eld *eld, int channels)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800724{
Wu Fengguang079d88c2010-03-08 10:44:23 +0800725 int i;
Wu Fengguang53d7d692010-09-21 14:25:49 +0800726 int ca = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800727 int spk_mask = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800728 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
729
730 /*
731 * CA defaults to 0 for basic stereo audio
732 */
733 if (channels <= 2)
734 return 0;
735
Wu Fengguang079d88c2010-03-08 10:44:23 +0800736 /*
737 * expand ELD's speaker allocation mask
738 *
739 * ELD tells the speaker mask in a compact(paired) form,
740 * expand ELD's notions to match the ones used by Audio InfoFrame.
741 */
742 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
David Henningsson1613d6b2013-02-19 16:11:24 +0100743 if (eld->info.spk_alloc & (1 << i))
Wu Fengguang079d88c2010-03-08 10:44:23 +0800744 spk_mask |= eld_speaker_allocation_bits[i];
745 }
746
747 /* search for the first working match in the CA table */
748 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
749 if (channels == channel_allocations[i].channels &&
750 (spk_mask & channel_allocations[i].spk_mask) ==
751 channel_allocations[i].spk_mask) {
Wu Fengguang53d7d692010-09-21 14:25:49 +0800752 ca = channel_allocations[i].ca_index;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800753 break;
754 }
755 }
756
Anssi Hannula18e39182013-09-01 14:36:47 +0300757 if (!ca) {
758 /* if there was no match, select the regular ALSA channel
759 * allocation with the matching number of channels */
760 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
761 if (channels == channel_allocations[i].channels) {
762 ca = channel_allocations[i].ca_index;
763 break;
764 }
765 }
766 }
767
David Henningsson1613d6b2013-02-19 16:11:24 +0100768 snd_print_channel_allocation(eld->info.spk_alloc, buf, sizeof(buf));
Takashi Iwai79514d42014-06-06 18:04:34 +0200769 codec_dbg(codec, "HDMI: select CA 0x%x for %d-channel allocation: %s\n",
Wu Fengguang53d7d692010-09-21 14:25:49 +0800770 ca, channels, buf);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800771
Wu Fengguang53d7d692010-09-21 14:25:49 +0800772 return ca;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800773}
774
775static void hdmi_debug_channel_mapping(struct hda_codec *codec,
776 hda_nid_t pin_nid)
777{
778#ifdef CONFIG_SND_DEBUG_VERBOSE
Anssi Hannula307229d2013-10-24 21:10:34 +0300779 struct hdmi_spec *spec = codec->spec;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800780 int i;
Anssi Hannula307229d2013-10-24 21:10:34 +0300781 int channel;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800782
783 for (i = 0; i < 8; i++) {
Anssi Hannula307229d2013-10-24 21:10:34 +0300784 channel = spec->ops.pin_get_slot_channel(codec, pin_nid, i);
Takashi Iwai4e76a882014-02-25 12:21:03 +0100785 codec_dbg(codec, "HDMI: ASP channel %d => slot %d\n",
Anssi Hannula307229d2013-10-24 21:10:34 +0300786 channel, i);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800787 }
788#endif
789}
790
Takashi Iwaid45e6882012-07-31 11:36:00 +0200791static void hdmi_std_setup_channel_mapping(struct hda_codec *codec,
Wu Fengguang079d88c2010-03-08 10:44:23 +0800792 hda_nid_t pin_nid,
Wang Xingchao433968d2012-09-06 10:02:37 +0800793 bool non_pcm,
Wu Fengguang53d7d692010-09-21 14:25:49 +0800794 int ca)
Wu Fengguang079d88c2010-03-08 10:44:23 +0800795{
Anssi Hannula307229d2013-10-24 21:10:34 +0300796 struct hdmi_spec *spec = codec->spec;
Anssi Hannula90f28002013-10-05 02:25:39 +0300797 struct cea_channel_speaker_allocation *ch_alloc;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800798 int i;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800799 int err;
Wang Xingchao72357c72012-09-06 10:02:36 +0800800 int order;
Wang Xingchao433968d2012-09-06 10:02:37 +0800801 int non_pcm_mapping[8];
Wu Fengguang079d88c2010-03-08 10:44:23 +0800802
Wang Xingchao72357c72012-09-06 10:02:36 +0800803 order = get_channel_allocation_order(ca);
Anssi Hannula90f28002013-10-05 02:25:39 +0300804 ch_alloc = &channel_allocations[order];
Wang Xingchao433968d2012-09-06 10:02:37 +0800805
Wu Fengguang079d88c2010-03-08 10:44:23 +0800806 if (hdmi_channel_mapping[ca][1] == 0) {
Anssi Hannula90f28002013-10-05 02:25:39 +0300807 int hdmi_slot = 0;
808 /* fill actual channel mappings in ALSA channel (i) order */
809 for (i = 0; i < ch_alloc->channels; i++) {
810 while (!ch_alloc->speakers[7 - hdmi_slot] && !WARN_ON(hdmi_slot >= 8))
811 hdmi_slot++; /* skip zero slots */
812
813 hdmi_channel_mapping[ca][i] = (i << 4) | hdmi_slot++;
814 }
815 /* fill the rest of the slots with ALSA channel 0xf */
816 for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++)
817 if (!ch_alloc->speakers[7 - hdmi_slot])
818 hdmi_channel_mapping[ca][i++] = (0xf << 4) | hdmi_slot;
Wu Fengguang079d88c2010-03-08 10:44:23 +0800819 }
820
Wang Xingchao433968d2012-09-06 10:02:37 +0800821 if (non_pcm) {
Anssi Hannula90f28002013-10-05 02:25:39 +0300822 for (i = 0; i < ch_alloc->channels; i++)
Anssi Hannula11f7c522013-10-05 02:25:41 +0300823 non_pcm_mapping[i] = (i << 4) | i;
Wang Xingchao433968d2012-09-06 10:02:37 +0800824 for (; i < 8; i++)
Anssi Hannula11f7c522013-10-05 02:25:41 +0300825 non_pcm_mapping[i] = (0xf << 4) | i;
Wang Xingchao433968d2012-09-06 10:02:37 +0800826 }
827
Wu Fengguang079d88c2010-03-08 10:44:23 +0800828 for (i = 0; i < 8; i++) {
Anssi Hannula307229d2013-10-24 21:10:34 +0300829 int slotsetup = non_pcm ? non_pcm_mapping[i] : hdmi_channel_mapping[ca][i];
830 int hdmi_slot = slotsetup & 0x0f;
831 int channel = (slotsetup & 0xf0) >> 4;
832 err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot, channel);
Wu Fengguang079d88c2010-03-08 10:44:23 +0800833 if (err) {
Takashi Iwai4e76a882014-02-25 12:21:03 +0100834 codec_dbg(codec, "HDMI: channel mapping failed\n");
Wu Fengguang079d88c2010-03-08 10:44:23 +0800835 break;
836 }
837 }
Wu Fengguang079d88c2010-03-08 10:44:23 +0800838}
839
Takashi Iwaid45e6882012-07-31 11:36:00 +0200840struct channel_map_table {
841 unsigned char map; /* ALSA API channel map position */
Takashi Iwaid45e6882012-07-31 11:36:00 +0200842 int spk_mask; /* speaker position bit mask */
843};
844
845static struct channel_map_table map_tables[] = {
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300846 { SNDRV_CHMAP_FL, FL },
847 { SNDRV_CHMAP_FR, FR },
848 { SNDRV_CHMAP_RL, RL },
849 { SNDRV_CHMAP_RR, RR },
850 { SNDRV_CHMAP_LFE, LFE },
851 { SNDRV_CHMAP_FC, FC },
852 { SNDRV_CHMAP_RLC, RLC },
853 { SNDRV_CHMAP_RRC, RRC },
854 { SNDRV_CHMAP_RC, RC },
855 { SNDRV_CHMAP_FLC, FLC },
856 { SNDRV_CHMAP_FRC, FRC },
Anssi Hannula94908a32013-11-10 21:24:04 +0200857 { SNDRV_CHMAP_TFL, FLH },
858 { SNDRV_CHMAP_TFR, FRH },
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300859 { SNDRV_CHMAP_FLW, FLW },
860 { SNDRV_CHMAP_FRW, FRW },
861 { SNDRV_CHMAP_TC, TC },
Anssi Hannula94908a32013-11-10 21:24:04 +0200862 { SNDRV_CHMAP_TFC, FCH },
Takashi Iwaid45e6882012-07-31 11:36:00 +0200863 {} /* terminator */
864};
865
866/* from ALSA API channel position to speaker bit mask */
867static int to_spk_mask(unsigned char c)
868{
869 struct channel_map_table *t = map_tables;
870 for (; t->map; t++) {
871 if (t->map == c)
872 return t->spk_mask;
873 }
874 return 0;
875}
876
877/* from ALSA API channel position to CEA slot */
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300878static int to_cea_slot(int ordered_ca, unsigned char pos)
Takashi Iwaid45e6882012-07-31 11:36:00 +0200879{
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300880 int mask = to_spk_mask(pos);
881 int i;
Takashi Iwaid45e6882012-07-31 11:36:00 +0200882
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300883 if (mask) {
884 for (i = 0; i < 8; i++) {
885 if (channel_allocations[ordered_ca].speakers[7 - i] == mask)
886 return i;
887 }
Takashi Iwaid45e6882012-07-31 11:36:00 +0200888 }
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300889
890 return -1;
Takashi Iwaid45e6882012-07-31 11:36:00 +0200891}
892
893/* from speaker bit mask to ALSA API channel position */
894static int spk_to_chmap(int spk)
895{
896 struct channel_map_table *t = map_tables;
897 for (; t->map; t++) {
898 if (t->spk_mask == spk)
899 return t->map;
900 }
901 return 0;
902}
903
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300904/* from CEA slot to ALSA API channel position */
905static int from_cea_slot(int ordered_ca, unsigned char slot)
906{
907 int mask = channel_allocations[ordered_ca].speakers[7 - slot];
908
909 return spk_to_chmap(mask);
910}
911
Takashi Iwaid45e6882012-07-31 11:36:00 +0200912/* get the CA index corresponding to the given ALSA API channel map */
913static int hdmi_manual_channel_allocation(int chs, unsigned char *map)
914{
915 int i, spks = 0, spk_mask = 0;
916
917 for (i = 0; i < chs; i++) {
918 int mask = to_spk_mask(map[i]);
919 if (mask) {
920 spk_mask |= mask;
921 spks++;
922 }
923 }
924
925 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
926 if ((chs == channel_allocations[i].channels ||
927 spks == channel_allocations[i].channels) &&
928 (spk_mask & channel_allocations[i].spk_mask) ==
929 channel_allocations[i].spk_mask)
930 return channel_allocations[i].ca_index;
931 }
932 return -1;
933}
934
935/* set up the channel slots for the given ALSA API channel map */
936static int hdmi_manual_setup_channel_mapping(struct hda_codec *codec,
937 hda_nid_t pin_nid,
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300938 int chs, unsigned char *map,
939 int ca)
Takashi Iwaid45e6882012-07-31 11:36:00 +0200940{
Anssi Hannula307229d2013-10-24 21:10:34 +0300941 struct hdmi_spec *spec = codec->spec;
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300942 int ordered_ca = get_channel_allocation_order(ca);
Anssi Hannula11f7c522013-10-05 02:25:41 +0300943 int alsa_pos, hdmi_slot;
944 int assignments[8] = {[0 ... 7] = 0xf};
945
946 for (alsa_pos = 0; alsa_pos < chs; alsa_pos++) {
947
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300948 hdmi_slot = to_cea_slot(ordered_ca, map[alsa_pos]);
Anssi Hannula11f7c522013-10-05 02:25:41 +0300949
950 if (hdmi_slot < 0)
951 continue; /* unassigned channel */
952
953 assignments[hdmi_slot] = alsa_pos;
954 }
955
956 for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++) {
Anssi Hannula307229d2013-10-24 21:10:34 +0300957 int err;
Anssi Hannula11f7c522013-10-05 02:25:41 +0300958
Anssi Hannula307229d2013-10-24 21:10:34 +0300959 err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot,
960 assignments[hdmi_slot]);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200961 if (err)
962 return -EINVAL;
963 }
964 return 0;
965}
966
967/* store ALSA API channel map from the current default map */
968static void hdmi_setup_fake_chmap(unsigned char *map, int ca)
969{
970 int i;
Anssi Hannula56cac412013-10-05 02:25:38 +0300971 int ordered_ca = get_channel_allocation_order(ca);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200972 for (i = 0; i < 8; i++) {
Anssi Hannula56cac412013-10-05 02:25:38 +0300973 if (i < channel_allocations[ordered_ca].channels)
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300974 map[i] = from_cea_slot(ordered_ca, hdmi_channel_mapping[ca][i] & 0x0f);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200975 else
976 map[i] = 0;
977 }
978}
979
980static void hdmi_setup_channel_mapping(struct hda_codec *codec,
981 hda_nid_t pin_nid, bool non_pcm, int ca,
Anssi Hannula20608732013-02-03 17:55:45 +0200982 int channels, unsigned char *map,
983 bool chmap_set)
Takashi Iwaid45e6882012-07-31 11:36:00 +0200984{
Anssi Hannula20608732013-02-03 17:55:45 +0200985 if (!non_pcm && chmap_set) {
Takashi Iwaid45e6882012-07-31 11:36:00 +0200986 hdmi_manual_setup_channel_mapping(codec, pin_nid,
Anssi Hannulaa5b7d512013-10-05 02:25:42 +0300987 channels, map, ca);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200988 } else {
989 hdmi_std_setup_channel_mapping(codec, pin_nid, non_pcm, ca);
990 hdmi_setup_fake_chmap(map, ca);
991 }
Anssi Hannula980b2492013-10-05 02:25:44 +0300992
993 hdmi_debug_channel_mapping(codec, pin_nid);
Takashi Iwaid45e6882012-07-31 11:36:00 +0200994}
Wu Fengguang079d88c2010-03-08 10:44:23 +0800995
Anssi Hannula307229d2013-10-24 21:10:34 +0300996static int hdmi_pin_set_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
997 int asp_slot, int channel)
998{
999 return snd_hda_codec_write(codec, pin_nid, 0,
1000 AC_VERB_SET_HDMI_CHAN_SLOT,
1001 (channel << 4) | asp_slot);
1002}
1003
1004static int hdmi_pin_get_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
1005 int asp_slot)
1006{
1007 return (snd_hda_codec_read(codec, pin_nid, 0,
1008 AC_VERB_GET_HDMI_CHAN_SLOT,
1009 asp_slot) & 0xf0) >> 4;
1010}
1011
Wu Fengguang079d88c2010-03-08 10:44:23 +08001012/*
1013 * Audio InfoFrame routines
1014 */
1015
1016/*
1017 * Enable Audio InfoFrame Transmission
1018 */
1019static void hdmi_start_infoframe_trans(struct hda_codec *codec,
1020 hda_nid_t pin_nid)
1021{
1022 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
1023 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
1024 AC_DIPXMIT_BEST);
1025}
1026
1027/*
1028 * Disable Audio InfoFrame Transmission
1029 */
1030static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
1031 hda_nid_t pin_nid)
1032{
1033 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
1034 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
1035 AC_DIPXMIT_DISABLE);
1036}
1037
1038static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
1039{
1040#ifdef CONFIG_SND_DEBUG_VERBOSE
1041 int i;
1042 int size;
1043
1044 size = snd_hdmi_get_eld_size(codec, pin_nid);
Takashi Iwai4e76a882014-02-25 12:21:03 +01001045 codec_dbg(codec, "HDMI: ELD buf size is %d\n", size);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001046
1047 for (i = 0; i < 8; i++) {
1048 size = snd_hda_codec_read(codec, pin_nid, 0,
1049 AC_VERB_GET_HDMI_DIP_SIZE, i);
Takashi Iwai4e76a882014-02-25 12:21:03 +01001050 codec_dbg(codec, "HDMI: DIP GP[%d] buf size is %d\n", i, size);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001051 }
1052#endif
1053}
1054
1055static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
1056{
1057#ifdef BE_PARANOID
1058 int i, j;
1059 int size;
1060 int pi, bi;
1061 for (i = 0; i < 8; i++) {
1062 size = snd_hda_codec_read(codec, pin_nid, 0,
1063 AC_VERB_GET_HDMI_DIP_SIZE, i);
1064 if (size == 0)
1065 continue;
1066
1067 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
1068 for (j = 1; j < 1000; j++) {
1069 hdmi_write_dip_byte(codec, pin_nid, 0x0);
1070 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
1071 if (pi != i)
Takashi Iwai4e76a882014-02-25 12:21:03 +01001072 codec_dbg(codec, "dip index %d: %d != %d\n",
Wu Fengguang079d88c2010-03-08 10:44:23 +08001073 bi, pi, i);
1074 if (bi == 0) /* byte index wrapped around */
1075 break;
1076 }
Takashi Iwai4e76a882014-02-25 12:21:03 +01001077 codec_dbg(codec,
Wu Fengguang079d88c2010-03-08 10:44:23 +08001078 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
1079 i, size, j);
1080 }
1081#endif
1082}
1083
Wu Fengguang53d7d692010-09-21 14:25:49 +08001084static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001085{
Wu Fengguang53d7d692010-09-21 14:25:49 +08001086 u8 *bytes = (u8 *)hdmi_ai;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001087 u8 sum = 0;
1088 int i;
1089
Wu Fengguang53d7d692010-09-21 14:25:49 +08001090 hdmi_ai->checksum = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001091
Wu Fengguang53d7d692010-09-21 14:25:49 +08001092 for (i = 0; i < sizeof(*hdmi_ai); i++)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001093 sum += bytes[i];
1094
Wu Fengguang53d7d692010-09-21 14:25:49 +08001095 hdmi_ai->checksum = -sum;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001096}
1097
1098static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
1099 hda_nid_t pin_nid,
Wu Fengguang53d7d692010-09-21 14:25:49 +08001100 u8 *dip, int size)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001101{
Wu Fengguang079d88c2010-03-08 10:44:23 +08001102 int i;
1103
1104 hdmi_debug_dip_size(codec, pin_nid);
1105 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
1106
Wu Fengguang079d88c2010-03-08 10:44:23 +08001107 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
Wu Fengguang53d7d692010-09-21 14:25:49 +08001108 for (i = 0; i < size; i++)
1109 hdmi_write_dip_byte(codec, pin_nid, dip[i]);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001110}
1111
1112static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
Wu Fengguang53d7d692010-09-21 14:25:49 +08001113 u8 *dip, int size)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001114{
Wu Fengguang079d88c2010-03-08 10:44:23 +08001115 u8 val;
1116 int i;
1117
1118 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
1119 != AC_DIPXMIT_BEST)
1120 return false;
1121
1122 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
Wu Fengguang53d7d692010-09-21 14:25:49 +08001123 for (i = 0; i < size; i++) {
Wu Fengguang079d88c2010-03-08 10:44:23 +08001124 val = snd_hda_codec_read(codec, pin_nid, 0,
1125 AC_VERB_GET_HDMI_DIP_DATA, 0);
Wu Fengguang53d7d692010-09-21 14:25:49 +08001126 if (val != dip[i])
Wu Fengguang079d88c2010-03-08 10:44:23 +08001127 return false;
1128 }
1129
1130 return true;
1131}
1132
Anssi Hannula307229d2013-10-24 21:10:34 +03001133static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
1134 hda_nid_t pin_nid,
1135 int ca, int active_channels,
1136 int conn_type)
1137{
1138 union audio_infoframe ai;
1139
Mengdong Lincaaf5ef2014-03-11 17:12:52 -04001140 memset(&ai, 0, sizeof(ai));
Anssi Hannula307229d2013-10-24 21:10:34 +03001141 if (conn_type == 0) { /* HDMI */
1142 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
1143
1144 hdmi_ai->type = 0x84;
1145 hdmi_ai->ver = 0x01;
1146 hdmi_ai->len = 0x0a;
1147 hdmi_ai->CC02_CT47 = active_channels - 1;
1148 hdmi_ai->CA = ca;
1149 hdmi_checksum_audio_infoframe(hdmi_ai);
1150 } else if (conn_type == 1) { /* DisplayPort */
1151 struct dp_audio_infoframe *dp_ai = &ai.dp;
1152
1153 dp_ai->type = 0x84;
1154 dp_ai->len = 0x1b;
1155 dp_ai->ver = 0x11 << 2;
1156 dp_ai->CC02_CT47 = active_channels - 1;
1157 dp_ai->CA = ca;
1158 } else {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001159 codec_dbg(codec, "HDMI: unknown connection type at pin %d\n",
Anssi Hannula307229d2013-10-24 21:10:34 +03001160 pin_nid);
1161 return;
1162 }
1163
1164 /*
1165 * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
1166 * sizeof(*dp_ai) to avoid partial match/update problems when
1167 * the user switches between HDMI/DP monitors.
1168 */
1169 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
1170 sizeof(ai))) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001171 codec_dbg(codec,
1172 "hdmi_pin_setup_infoframe: pin=%d channels=%d ca=0x%02x\n",
Anssi Hannula307229d2013-10-24 21:10:34 +03001173 pin_nid,
1174 active_channels, ca);
1175 hdmi_stop_infoframe_trans(codec, pin_nid);
1176 hdmi_fill_audio_infoframe(codec, pin_nid,
1177 ai.bytes, sizeof(ai));
1178 hdmi_start_infoframe_trans(codec, pin_nid);
1179 }
1180}
1181
Takashi Iwaib0540872013-09-02 12:33:02 +02001182static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
1183 struct hdmi_spec_per_pin *per_pin,
1184 bool non_pcm)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001185{
Anssi Hannula307229d2013-10-24 21:10:34 +03001186 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001187 hda_nid_t pin_nid = per_pin->pin_nid;
Takashi Iwaib0540872013-09-02 12:33:02 +02001188 int channels = per_pin->channels;
Anssi Hannula1df5a062013-10-05 02:25:40 +03001189 int active_channels;
Stephen Warren384a48d2011-06-01 11:14:21 -06001190 struct hdmi_eld *eld;
Anssi Hannula1df5a062013-10-05 02:25:40 +03001191 int ca, ordered_ca;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001192
Takashi Iwaib0540872013-09-02 12:33:02 +02001193 if (!channels)
1194 return;
1195
Mengdong Lin75dcbe42014-01-08 15:55:32 -05001196 if (is_haswell_plus(codec))
Mengdong Lin58f7d282013-09-04 16:37:12 -04001197 snd_hda_codec_write(codec, pin_nid, 0,
1198 AC_VERB_SET_AMP_GAIN_MUTE,
1199 AMP_OUT_UNMUTE);
1200
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001201 eld = &per_pin->sink_eld;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001202
Takashi Iwaid45e6882012-07-31 11:36:00 +02001203 if (!non_pcm && per_pin->chmap_set)
1204 ca = hdmi_manual_channel_allocation(channels, per_pin->chmap);
1205 else
Takashi Iwai79514d42014-06-06 18:04:34 +02001206 ca = hdmi_channel_allocation(codec, eld, channels);
Takashi Iwaid45e6882012-07-31 11:36:00 +02001207 if (ca < 0)
1208 ca = 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001209
Anssi Hannula1df5a062013-10-05 02:25:40 +03001210 ordered_ca = get_channel_allocation_order(ca);
1211 active_channels = channel_allocations[ordered_ca].channels;
1212
1213 hdmi_set_channel_count(codec, per_pin->cvt_nid, active_channels);
1214
Stephen Warren384a48d2011-06-01 11:14:21 -06001215 /*
Anssi Hannula39edac72013-10-07 19:24:52 +03001216 * always configure channel mapping, it may have been changed by the
1217 * user in the meantime
1218 */
1219 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
1220 channels, per_pin->chmap,
1221 per_pin->chmap_set);
1222
Anssi Hannula307229d2013-10-24 21:10:34 +03001223 spec->ops.pin_setup_infoframe(codec, pin_nid, ca, active_channels,
1224 eld->info.conn_type);
Wang Xingchao433968d2012-09-06 10:02:37 +08001225
Takashi Iwai1a6003b2012-09-06 17:42:08 +02001226 per_pin->non_pcm = non_pcm;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001227}
1228
Wu Fengguang079d88c2010-03-08 10:44:23 +08001229/*
1230 * Unsolicited events
1231 */
1232
Takashi Iwaiefe47102013-11-07 13:38:23 +01001233static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
Takashi Iwai38faddb2010-07-28 14:21:55 +02001234
Takashi Iwai1a4f69d2014-09-11 15:22:46 +02001235static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001236{
1237 struct hdmi_spec *spec = codec->spec;
Takashi Iwai1a4f69d2014-09-11 15:22:46 +02001238 int pin_idx = pin_nid_to_pin_index(codec, nid);
1239
David Henningsson20ce9022013-12-04 10:19:41 +08001240 if (pin_idx < 0)
1241 return;
David Henningsson20ce9022013-12-04 10:19:41 +08001242 if (hdmi_present_sense(get_pin(spec, pin_idx), 1))
1243 snd_hda_jack_report_sync(codec);
1244}
1245
Takashi Iwai1a4f69d2014-09-11 15:22:46 +02001246static void jack_callback(struct hda_codec *codec,
1247 struct hda_jack_callback *jack)
1248{
Takashi Iwai2ebab402016-02-09 10:23:52 +01001249 check_presence_and_report(codec, jack->nid);
Takashi Iwai1a4f69d2014-09-11 15:22:46 +02001250}
1251
David Henningsson20ce9022013-12-04 10:19:41 +08001252static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
1253{
Takashi Iwai3a938972011-10-28 01:16:55 +02001254 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
Takashi Iwai3a938972011-10-28 01:16:55 +02001255 struct hda_jack_tbl *jack;
Mengdong Lin2e59e5a2013-08-26 21:35:49 -04001256 int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
Takashi Iwai3a938972011-10-28 01:16:55 +02001257
1258 jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
1259 if (!jack)
1260 return;
Takashi Iwai3a938972011-10-28 01:16:55 +02001261 jack->jack_dirty = 1;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001262
Takashi Iwai4e76a882014-02-25 12:21:03 +01001263 codec_dbg(codec,
Mengdong Lin2e59e5a2013-08-26 21:35:49 -04001264 "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 +08001265 codec->addr, jack->nid, dev_entry, !!(res & AC_UNSOL_RES_IA),
Fengguang Wufae3d882012-04-10 17:00:35 +08001266 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
Wu Fengguang079d88c2010-03-08 10:44:23 +08001267
Takashi Iwai1a4f69d2014-09-11 15:22:46 +02001268 check_presence_and_report(codec, jack->nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001269}
1270
1271static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
1272{
1273 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
1274 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
1275 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
1276 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
1277
Takashi Iwai4e76a882014-02-25 12:21:03 +01001278 codec_info(codec,
Takashi Iwaie9ea8e82012-06-21 11:41:05 +02001279 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
Stephen Warren384a48d2011-06-01 11:14:21 -06001280 codec->addr,
Wu Fengguang079d88c2010-03-08 10:44:23 +08001281 tag,
1282 subtag,
1283 cp_state,
1284 cp_ready);
1285
1286 /* TODO */
1287 if (cp_state)
1288 ;
1289 if (cp_ready)
1290 ;
1291}
1292
1293
1294static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
1295{
Wu Fengguang079d88c2010-03-08 10:44:23 +08001296 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
1297 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
1298
Takashi Iwai3a938972011-10-28 01:16:55 +02001299 if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001300 codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001301 return;
1302 }
1303
1304 if (subtag == 0)
1305 hdmi_intrinsic_event(codec, res);
1306 else
1307 hdmi_non_intrinsic_event(codec, res);
1308}
1309
Mengdong Lin58f7d282013-09-04 16:37:12 -04001310static void haswell_verify_D0(struct hda_codec *codec,
Wang Xingchao53b434f2013-06-18 10:41:53 +08001311 hda_nid_t cvt_nid, hda_nid_t nid)
David Henningsson83f26ad2013-04-10 12:26:07 +02001312{
Mengdong Lin58f7d282013-09-04 16:37:12 -04001313 int pwr;
David Henningsson83f26ad2013-04-10 12:26:07 +02001314
Wang Xingchao53b434f2013-06-18 10:41:53 +08001315 /* For Haswell, the converter 1/2 may keep in D3 state after bootup,
1316 * thus pins could only choose converter 0 for use. Make sure the
1317 * converters are in correct power state */
Takashi Iwaifd678ca2013-06-18 16:28:36 +02001318 if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0))
Wang Xingchao53b434f2013-06-18 10:41:53 +08001319 snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1320
Takashi Iwaifd678ca2013-06-18 16:28:36 +02001321 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) {
David Henningsson83f26ad2013-04-10 12:26:07 +02001322 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
1323 AC_PWRST_D0);
1324 msleep(40);
1325 pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
1326 pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
Takashi Iwai4e76a882014-02-25 12:21:03 +01001327 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 +02001328 }
David Henningsson83f26ad2013-04-10 12:26:07 +02001329}
1330
Wu Fengguang079d88c2010-03-08 10:44:23 +08001331/*
1332 * Callbacks
1333 */
1334
Takashi Iwai92f10b32010-08-03 14:21:00 +02001335/* HBR should be Non-PCM, 8 channels */
1336#define is_hbr_format(format) \
1337 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
1338
Anssi Hannula307229d2013-10-24 21:10:34 +03001339static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
1340 bool hbr)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001341{
Anssi Hannula307229d2013-10-24 21:10:34 +03001342 int pinctl, new_pinctl;
David Henningsson83f26ad2013-04-10 12:26:07 +02001343
Stephen Warren384a48d2011-06-01 11:14:21 -06001344 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
1345 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001346 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1347
Anssi Hannula13122e62013-11-10 20:56:10 +02001348 if (pinctl < 0)
1349 return hbr ? -EINVAL : 0;
1350
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001351 new_pinctl = pinctl & ~AC_PINCTL_EPT;
Anssi Hannula307229d2013-10-24 21:10:34 +03001352 if (hbr)
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001353 new_pinctl |= AC_PINCTL_EPT_HBR;
1354 else
1355 new_pinctl |= AC_PINCTL_EPT_NATIVE;
1356
Takashi Iwai4e76a882014-02-25 12:21:03 +01001357 codec_dbg(codec,
1358 "hdmi_pin_hbr_setup: NID=0x%x, %spinctl=0x%x\n",
Stephen Warren384a48d2011-06-01 11:14:21 -06001359 pin_nid,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001360 pinctl == new_pinctl ? "" : "new-",
1361 new_pinctl);
1362
1363 if (pinctl != new_pinctl)
Stephen Warren384a48d2011-06-01 11:14:21 -06001364 snd_hda_codec_write(codec, pin_nid, 0,
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001365 AC_VERB_SET_PIN_WIDGET_CONTROL,
1366 new_pinctl);
Anssi Hannula307229d2013-10-24 21:10:34 +03001367 } else if (hbr)
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001368 return -EINVAL;
Anssi Hannula307229d2013-10-24 21:10:34 +03001369
1370 return 0;
1371}
1372
1373static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
1374 hda_nid_t pin_nid, u32 stream_tag, int format)
1375{
1376 struct hdmi_spec *spec = codec->spec;
1377 int err;
1378
Mengdong Lin75dcbe42014-01-08 15:55:32 -05001379 if (is_haswell_plus(codec))
Anssi Hannula307229d2013-10-24 21:10:34 +03001380 haswell_verify_D0(codec, cvt_nid, pin_nid);
1381
1382 err = spec->ops.pin_hbr_setup(codec, pin_nid, is_hbr_format(format));
1383
1384 if (err) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001385 codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n");
Anssi Hannula307229d2013-10-24 21:10:34 +03001386 return err;
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001387 }
Wu Fengguang079d88c2010-03-08 10:44:23 +08001388
Stephen Warren384a48d2011-06-01 11:14:21 -06001389 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
Anssi Hannulaea87d1c2010-08-03 13:28:58 +03001390 return 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001391}
1392
Libin Yang42b29872015-12-16 13:42:42 +08001393/* Try to find an available converter
1394 * If pin_idx is less then zero, just try to find an available converter.
1395 * Otherwise, try to find an available converter and get the cvt mux index
1396 * of the pin.
1397 */
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001398static int hdmi_choose_cvt(struct hda_codec *codec,
1399 int pin_idx, int *cvt_id, int *mux_id)
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001400{
1401 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06001402 struct hdmi_spec_per_pin *per_pin;
Stephen Warren384a48d2011-06-01 11:14:21 -06001403 struct hdmi_spec_per_cvt *per_cvt = NULL;
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001404 int cvt_idx, mux_idx = 0;
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001405
Libin Yang42b29872015-12-16 13:42:42 +08001406 /* pin_idx < 0 means no pin will be bound to the converter */
1407 if (pin_idx < 0)
1408 per_pin = NULL;
1409 else
1410 per_pin = get_pin(spec, pin_idx);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001411
Stephen Warren384a48d2011-06-01 11:14:21 -06001412 /* Dynamically assign converter to stream */
1413 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001414 per_cvt = get_cvt(spec, cvt_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001415
1416 /* Must not already be assigned */
1417 if (per_cvt->assigned)
1418 continue;
Libin Yang42b29872015-12-16 13:42:42 +08001419 if (per_pin == NULL)
1420 break;
Stephen Warren384a48d2011-06-01 11:14:21 -06001421 /* Must be in pin's mux's list of converters */
1422 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
1423 if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid)
1424 break;
1425 /* Not in mux list */
1426 if (mux_idx == per_pin->num_mux_nids)
1427 continue;
1428 break;
1429 }
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001430
Stephen Warren384a48d2011-06-01 11:14:21 -06001431 /* No free converters */
1432 if (cvt_idx == spec->num_cvts)
Libin Yang42b29872015-12-16 13:42:42 +08001433 return -EBUSY;
Stephen Warren384a48d2011-06-01 11:14:21 -06001434
Libin Yang42b29872015-12-16 13:42:42 +08001435 if (per_pin != NULL)
1436 per_pin->mux_idx = mux_idx;
Mengdong Lin2df67422014-03-20 13:01:06 +08001437
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001438 if (cvt_id)
1439 *cvt_id = cvt_idx;
1440 if (mux_id)
1441 *mux_id = mux_idx;
1442
1443 return 0;
1444}
1445
Mengdong Lin2df67422014-03-20 13:01:06 +08001446/* Assure the pin select the right convetor */
1447static void intel_verify_pin_cvt_connect(struct hda_codec *codec,
1448 struct hdmi_spec_per_pin *per_pin)
1449{
1450 hda_nid_t pin_nid = per_pin->pin_nid;
1451 int mux_idx, curr;
1452
1453 mux_idx = per_pin->mux_idx;
1454 curr = snd_hda_codec_read(codec, pin_nid, 0,
1455 AC_VERB_GET_CONNECT_SEL, 0);
1456 if (curr != mux_idx)
1457 snd_hda_codec_write_cache(codec, pin_nid, 0,
1458 AC_VERB_SET_CONNECT_SEL,
1459 mux_idx);
1460}
1461
Libin Yang42b29872015-12-16 13:42:42 +08001462/* get the mux index for the converter of the pins
1463 * converter's mux index is the same for all pins on Intel platform
1464 */
1465static int intel_cvt_id_to_mux_idx(struct hdmi_spec *spec,
1466 hda_nid_t cvt_nid)
1467{
1468 int i;
1469
1470 for (i = 0; i < spec->num_cvts; i++)
1471 if (spec->cvt_nids[i] == cvt_nid)
1472 return i;
1473 return -EINVAL;
1474}
1475
Mengdong Lin300016b2013-11-04 01:13:13 -05001476/* Intel HDMI workaround to fix audio routing issue:
1477 * For some Intel display codecs, pins share the same connection list.
1478 * So a conveter can be selected by multiple pins and playback on any of these
1479 * pins will generate sound on the external display, because audio flows from
1480 * the same converter to the display pipeline. Also muting one pin may make
1481 * other pins have no sound output.
1482 * So this function assures that an assigned converter for a pin is not selected
1483 * by any other pins.
1484 */
1485static void intel_not_share_assigned_cvt(struct hda_codec *codec,
Mengdong Linf82d7d12013-09-21 20:34:45 -04001486 hda_nid_t pin_nid, int mux_idx)
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001487{
1488 struct hdmi_spec *spec = codec->spec;
Takashi Iwai7639a062015-03-03 10:07:24 +01001489 hda_nid_t nid;
Mengdong Linf82d7d12013-09-21 20:34:45 -04001490 int cvt_idx, curr;
1491 struct hdmi_spec_per_cvt *per_cvt;
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001492
Mengdong Linf82d7d12013-09-21 20:34:45 -04001493 /* configure all pins, including "no physical connection" ones */
Takashi Iwai7639a062015-03-03 10:07:24 +01001494 for_each_hda_codec_node(nid, codec) {
Mengdong Linf82d7d12013-09-21 20:34:45 -04001495 unsigned int wid_caps = get_wcaps(codec, nid);
1496 unsigned int wid_type = get_wcaps_type(wid_caps);
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001497
Mengdong Linf82d7d12013-09-21 20:34:45 -04001498 if (wid_type != AC_WID_PIN)
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001499 continue;
1500
Mengdong Linf82d7d12013-09-21 20:34:45 -04001501 if (nid == pin_nid)
1502 continue;
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001503
Mengdong Linf82d7d12013-09-21 20:34:45 -04001504 curr = snd_hda_codec_read(codec, nid, 0,
1505 AC_VERB_GET_CONNECT_SEL, 0);
1506 if (curr != mux_idx)
1507 continue;
1508
1509 /* choose an unassigned converter. The conveters in the
1510 * connection list are in the same order as in the codec.
1511 */
1512 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
1513 per_cvt = get_cvt(spec, cvt_idx);
1514 if (!per_cvt->assigned) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001515 codec_dbg(codec,
1516 "choose cvt %d for pin nid %d\n",
Mengdong Linf82d7d12013-09-21 20:34:45 -04001517 cvt_idx, nid);
1518 snd_hda_codec_write_cache(codec, nid, 0,
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001519 AC_VERB_SET_CONNECT_SEL,
Mengdong Linf82d7d12013-09-21 20:34:45 -04001520 cvt_idx);
1521 break;
1522 }
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001523 }
1524 }
1525}
1526
Libin Yang42b29872015-12-16 13:42:42 +08001527/* A wrapper of intel_not_share_asigned_cvt() */
1528static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,
1529 hda_nid_t pin_nid, hda_nid_t cvt_nid)
1530{
1531 int mux_idx;
1532 struct hdmi_spec *spec = codec->spec;
1533
1534 if (!is_haswell_plus(codec) && !is_valleyview_plus(codec))
1535 return;
1536
1537 /* On Intel platform, the mapping of converter nid to
1538 * mux index of the pins are always the same.
1539 * The pin nid may be 0, this means all pins will not
1540 * share the converter.
1541 */
1542 mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid);
1543 if (mux_idx >= 0)
1544 intel_not_share_assigned_cvt(codec, pin_nid, mux_idx);
1545}
1546
1547/* called in hdmi_pcm_open when no pin is assigned to the PCM
1548 * in dyn_pcm_assign mode.
1549 */
1550static int hdmi_pcm_open_no_pin(struct hda_pcm_stream *hinfo,
1551 struct hda_codec *codec,
1552 struct snd_pcm_substream *substream)
1553{
1554 struct hdmi_spec *spec = codec->spec;
1555 struct snd_pcm_runtime *runtime = substream->runtime;
Libin Yangac983792015-12-16 16:48:16 +08001556 int cvt_idx, pcm_idx;
Libin Yang42b29872015-12-16 13:42:42 +08001557 struct hdmi_spec_per_cvt *per_cvt = NULL;
1558 int err;
1559
Libin Yangac983792015-12-16 16:48:16 +08001560 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1561 if (pcm_idx < 0)
1562 return -EINVAL;
1563
Libin Yang42b29872015-12-16 13:42:42 +08001564 err = hdmi_choose_cvt(codec, -1, &cvt_idx, NULL);
1565 if (err)
1566 return err;
1567
1568 per_cvt = get_cvt(spec, cvt_idx);
1569 per_cvt->assigned = 1;
1570 hinfo->nid = per_cvt->cvt_nid;
1571
1572 intel_not_share_assigned_cvt_nid(codec, 0, per_cvt->cvt_nid);
1573
Libin Yangac983792015-12-16 16:48:16 +08001574 set_bit(pcm_idx, &spec->pcm_in_use);
Libin Yang42b29872015-12-16 13:42:42 +08001575 /* todo: setup spdif ctls assign */
1576
1577 /* Initially set the converter's capabilities */
1578 hinfo->channels_min = per_cvt->channels_min;
1579 hinfo->channels_max = per_cvt->channels_max;
1580 hinfo->rates = per_cvt->rates;
1581 hinfo->formats = per_cvt->formats;
1582 hinfo->maxbps = per_cvt->maxbps;
1583
1584 /* Store the updated parameters */
1585 runtime->hw.channels_min = hinfo->channels_min;
1586 runtime->hw.channels_max = hinfo->channels_max;
1587 runtime->hw.formats = hinfo->formats;
1588 runtime->hw.rates = hinfo->rates;
1589
1590 snd_pcm_hw_constraint_step(substream->runtime, 0,
1591 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
1592 return 0;
1593}
1594
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001595/*
1596 * HDA PCM callbacks
1597 */
1598static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1599 struct hda_codec *codec,
1600 struct snd_pcm_substream *substream)
1601{
1602 struct hdmi_spec *spec = codec->spec;
1603 struct snd_pcm_runtime *runtime = substream->runtime;
Libin Yang2bf3c852015-12-16 13:42:43 +08001604 int pin_idx, cvt_idx, pcm_idx, mux_idx = 0;
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001605 struct hdmi_spec_per_pin *per_pin;
1606 struct hdmi_eld *eld;
1607 struct hdmi_spec_per_cvt *per_cvt = NULL;
1608 int err;
1609
1610 /* Validate hinfo */
Libin Yang2bf3c852015-12-16 13:42:43 +08001611 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
1612 if (pcm_idx < 0)
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001613 return -EINVAL;
Libin Yang2bf3c852015-12-16 13:42:43 +08001614
Libin Yang42b29872015-12-16 13:42:42 +08001615 mutex_lock(&spec->pcm_lock);
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001616 pin_idx = hinfo_to_pin_index(codec, hinfo);
Libin Yang42b29872015-12-16 13:42:42 +08001617 if (!spec->dyn_pcm_assign) {
1618 if (snd_BUG_ON(pin_idx < 0)) {
1619 mutex_unlock(&spec->pcm_lock);
1620 return -EINVAL;
1621 }
1622 } else {
1623 /* no pin is assigned to the PCM
1624 * PA need pcm open successfully when probe
1625 */
1626 if (pin_idx < 0) {
1627 err = hdmi_pcm_open_no_pin(hinfo, codec, substream);
1628 mutex_unlock(&spec->pcm_lock);
1629 return err;
1630 }
1631 }
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001632
1633 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, &mux_idx);
Libin Yang42b29872015-12-16 13:42:42 +08001634 if (err < 0) {
1635 mutex_unlock(&spec->pcm_lock);
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001636 return err;
Libin Yang42b29872015-12-16 13:42:42 +08001637 }
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001638
1639 per_cvt = get_cvt(spec, cvt_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001640 /* Claim converter */
1641 per_cvt->assigned = 1;
Libin Yang42b29872015-12-16 13:42:42 +08001642
Libin Yangac983792015-12-16 16:48:16 +08001643 set_bit(pcm_idx, &spec->pcm_in_use);
Libin Yang42b29872015-12-16 13:42:42 +08001644 per_pin = get_pin(spec, pin_idx);
Anssi Hannula1df5a062013-10-05 02:25:40 +03001645 per_pin->cvt_nid = per_cvt->cvt_nid;
Stephen Warren384a48d2011-06-01 11:14:21 -06001646 hinfo->nid = per_cvt->cvt_nid;
1647
Takashi Iwaibddee962013-06-18 16:14:22 +02001648 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
Stephen Warren384a48d2011-06-01 11:14:21 -06001649 AC_VERB_SET_CONNECT_SEL,
1650 mux_idx);
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001651
1652 /* configure unused pins to choose other converters */
Libin Yangca2e7222014-08-19 16:20:12 +08001653 if (is_haswell_plus(codec) || is_valleyview_plus(codec))
Mengdong Lin300016b2013-11-04 01:13:13 -05001654 intel_not_share_assigned_cvt(codec, per_pin->pin_nid, mux_idx);
Wang Xingchao7ef166b2013-06-18 21:42:14 +08001655
Libin Yang2bf3c852015-12-16 13:42:43 +08001656 snd_hda_spdif_ctls_assign(codec, pcm_idx, per_cvt->cvt_nid);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001657
Stephen Warren2def8172011-06-01 11:14:20 -06001658 /* Initially set the converter's capabilities */
Stephen Warren384a48d2011-06-01 11:14:21 -06001659 hinfo->channels_min = per_cvt->channels_min;
1660 hinfo->channels_max = per_cvt->channels_max;
1661 hinfo->rates = per_cvt->rates;
1662 hinfo->formats = per_cvt->formats;
1663 hinfo->maxbps = per_cvt->maxbps;
Stephen Warren2def8172011-06-01 11:14:20 -06001664
Libin Yang42b29872015-12-16 13:42:42 +08001665 eld = &per_pin->sink_eld;
Stephen Warren384a48d2011-06-01 11:14:21 -06001666 /* Restrict capabilities by ELD if this isn't disabled */
Stephen Warrenc3d52102011-06-01 11:14:16 -06001667 if (!static_hdmi_pcm && eld->eld_valid) {
David Henningsson1613d6b2013-02-19 16:11:24 +01001668 snd_hdmi_eld_update_pcm_info(&eld->info, hinfo);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001669 if (hinfo->channels_min > hinfo->channels_max ||
Takashi Iwai2ad779b2013-02-01 14:01:27 +01001670 !hinfo->rates || !hinfo->formats) {
1671 per_cvt->assigned = 0;
1672 hinfo->nid = 0;
Libin Yang2bf3c852015-12-16 13:42:43 +08001673 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
Libin Yang42b29872015-12-16 13:42:42 +08001674 mutex_unlock(&spec->pcm_lock);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001675 return -ENODEV;
Takashi Iwai2ad779b2013-02-01 14:01:27 +01001676 }
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001677 }
Stephen Warren2def8172011-06-01 11:14:20 -06001678
Libin Yang42b29872015-12-16 13:42:42 +08001679 mutex_unlock(&spec->pcm_lock);
Stephen Warren2def8172011-06-01 11:14:20 -06001680 /* Store the updated parameters */
Takashi Iwai639cef02011-01-14 10:30:46 +01001681 runtime->hw.channels_min = hinfo->channels_min;
1682 runtime->hw.channels_max = hinfo->channels_max;
1683 runtime->hw.formats = hinfo->formats;
1684 runtime->hw.rates = hinfo->rates;
Takashi Iwai4fe2ca12011-01-14 10:33:26 +01001685
1686 snd_pcm_hw_constraint_step(substream->runtime, 0,
1687 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Takashi Iwaibbbe3392010-08-13 08:45:23 +02001688 return 0;
1689}
1690
1691/*
Wu Fengguang079d88c2010-03-08 10:44:23 +08001692 * HDA/HDMI auto parsing
1693 */
Stephen Warren384a48d2011-06-01 11:14:21 -06001694static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001695{
1696 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01001697 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06001698 hda_nid_t pin_nid = per_pin->pin_nid;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001699
1700 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01001701 codec_warn(codec,
1702 "HDMI: pin %d wcaps %#x does not support connection list\n",
Wu Fengguang079d88c2010-03-08 10:44:23 +08001703 pin_nid, get_wcaps(codec, pin_nid));
1704 return -EINVAL;
1705 }
1706
Stephen Warren384a48d2011-06-01 11:14:21 -06001707 per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,
1708 per_pin->mux_nids,
1709 HDA_MAX_CONNECTIONS);
Wu Fengguang079d88c2010-03-08 10:44:23 +08001710
1711 return 0;
1712}
1713
Libin Yanga76056f2015-12-16 16:48:15 +08001714static int hdmi_find_pcm_slot(struct hdmi_spec *spec,
1715 struct hdmi_spec_per_pin *per_pin)
1716{
1717 int i;
1718
1719 /* try the prefer PCM */
1720 if (!test_bit(per_pin->pin_nid_idx, &spec->pcm_bitmap))
1721 return per_pin->pin_nid_idx;
1722
1723 /* have a second try; check the "reserved area" over num_pins */
1724 for (i = spec->num_pins; i < spec->pcm_used; i++) {
1725 if (!test_bit(i, &spec->pcm_bitmap))
1726 return i;
1727 }
1728
1729 /* the last try; check the empty slots in pins */
1730 for (i = 0; i < spec->num_pins; i++) {
1731 if (!test_bit(i, &spec->pcm_bitmap))
1732 return i;
1733 }
1734 return -EBUSY;
1735}
1736
1737static void hdmi_attach_hda_pcm(struct hdmi_spec *spec,
1738 struct hdmi_spec_per_pin *per_pin)
1739{
1740 int idx;
1741
1742 /* pcm already be attached to the pin */
1743 if (per_pin->pcm)
1744 return;
1745 idx = hdmi_find_pcm_slot(spec, per_pin);
1746 if (idx == -ENODEV)
1747 return;
1748 per_pin->pcm_idx = idx;
Libin Yang2bea2412016-01-12 11:13:26 +08001749 per_pin->pcm = get_hdmi_pcm(spec, idx);
Libin Yanga76056f2015-12-16 16:48:15 +08001750 set_bit(idx, &spec->pcm_bitmap);
1751}
1752
1753static void hdmi_detach_hda_pcm(struct hdmi_spec *spec,
1754 struct hdmi_spec_per_pin *per_pin)
1755{
1756 int idx;
1757
1758 /* pcm already be detached from the pin */
1759 if (!per_pin->pcm)
1760 return;
1761 idx = per_pin->pcm_idx;
1762 per_pin->pcm_idx = -1;
1763 per_pin->pcm = NULL;
1764 if (idx >= 0 && idx < spec->pcm_used)
1765 clear_bit(idx, &spec->pcm_bitmap);
1766}
1767
Libin Yangac983792015-12-16 16:48:16 +08001768static int hdmi_get_pin_cvt_mux(struct hdmi_spec *spec,
1769 struct hdmi_spec_per_pin *per_pin, hda_nid_t cvt_nid)
1770{
1771 int mux_idx;
1772
1773 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
1774 if (per_pin->mux_nids[mux_idx] == cvt_nid)
1775 break;
1776 return mux_idx;
1777}
1778
1779static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid);
1780
1781static void hdmi_pcm_setup_pin(struct hdmi_spec *spec,
1782 struct hdmi_spec_per_pin *per_pin)
1783{
1784 struct hda_codec *codec = per_pin->codec;
1785 struct hda_pcm *pcm;
1786 struct hda_pcm_stream *hinfo;
1787 struct snd_pcm_substream *substream;
1788 int mux_idx;
1789 bool non_pcm;
1790
1791 if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
Libin Yang2bea2412016-01-12 11:13:26 +08001792 pcm = get_pcm_rec(spec, per_pin->pcm_idx);
Libin Yangac983792015-12-16 16:48:16 +08001793 else
1794 return;
1795 if (!test_bit(per_pin->pcm_idx, &spec->pcm_in_use))
1796 return;
1797
1798 /* hdmi audio only uses playback and one substream */
1799 hinfo = pcm->stream;
1800 substream = pcm->pcm->streams[0].substream;
1801
1802 per_pin->cvt_nid = hinfo->nid;
1803
1804 mux_idx = hdmi_get_pin_cvt_mux(spec, per_pin, hinfo->nid);
1805 if (mux_idx < per_pin->num_mux_nids)
1806 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1807 AC_VERB_SET_CONNECT_SEL,
1808 mux_idx);
1809 snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid);
1810
1811 non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid);
1812 if (substream->runtime)
1813 per_pin->channels = substream->runtime->channels;
1814 per_pin->setup = true;
1815 per_pin->mux_idx = mux_idx;
1816
1817 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
1818}
1819
1820static void hdmi_pcm_reset_pin(struct hdmi_spec *spec,
1821 struct hdmi_spec_per_pin *per_pin)
1822{
1823 if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
1824 snd_hda_spdif_ctls_unassign(per_pin->codec, per_pin->pcm_idx);
1825
1826 per_pin->chmap_set = false;
1827 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
1828
1829 per_pin->setup = false;
1830 per_pin->channels = 0;
1831}
1832
Takashi Iwaie90247f2015-11-13 09:12:12 +01001833/* update per_pin ELD from the given new ELD;
1834 * setup info frame and notification accordingly
1835 */
1836static void update_eld(struct hda_codec *codec,
1837 struct hdmi_spec_per_pin *per_pin,
1838 struct hdmi_eld *eld)
1839{
1840 struct hdmi_eld *pin_eld = &per_pin->sink_eld;
Libin Yanga76056f2015-12-16 16:48:15 +08001841 struct hdmi_spec *spec = codec->spec;
Takashi Iwaie90247f2015-11-13 09:12:12 +01001842 bool old_eld_valid = pin_eld->eld_valid;
1843 bool eld_changed;
1844
Libin Yanga76056f2015-12-16 16:48:15 +08001845 if (spec->dyn_pcm_assign) {
Libin Yangac983792015-12-16 16:48:16 +08001846 if (eld->eld_valid) {
Libin Yanga76056f2015-12-16 16:48:15 +08001847 hdmi_attach_hda_pcm(spec, per_pin);
Libin Yangac983792015-12-16 16:48:16 +08001848 hdmi_pcm_setup_pin(spec, per_pin);
1849 } else {
1850 hdmi_pcm_reset_pin(spec, per_pin);
Libin Yanga76056f2015-12-16 16:48:15 +08001851 hdmi_detach_hda_pcm(spec, per_pin);
Libin Yangac983792015-12-16 16:48:16 +08001852 }
Libin Yanga76056f2015-12-16 16:48:15 +08001853 }
1854
Takashi Iwaie90247f2015-11-13 09:12:12 +01001855 if (eld->eld_valid)
1856 snd_hdmi_show_eld(codec, &eld->info);
1857
1858 eld_changed = (pin_eld->eld_valid != eld->eld_valid);
1859 if (eld->eld_valid && pin_eld->eld_valid)
1860 if (pin_eld->eld_size != eld->eld_size ||
1861 memcmp(pin_eld->eld_buffer, eld->eld_buffer,
1862 eld->eld_size) != 0)
1863 eld_changed = true;
1864
1865 pin_eld->eld_valid = eld->eld_valid;
1866 pin_eld->eld_size = eld->eld_size;
1867 if (eld->eld_valid)
1868 memcpy(pin_eld->eld_buffer, eld->eld_buffer, eld->eld_size);
1869 pin_eld->info = eld->info;
1870
1871 /*
1872 * Re-setup pin and infoframe. This is needed e.g. when
1873 * - sink is first plugged-in
1874 * - transcoder can change during stream playback on Haswell
1875 * and this can make HW reset converter selection on a pin.
1876 */
1877 if (eld->eld_valid && !old_eld_valid && per_pin->setup) {
1878 if (is_haswell_plus(codec) || is_valleyview_plus(codec)) {
1879 intel_verify_pin_cvt_connect(codec, per_pin);
1880 intel_not_share_assigned_cvt(codec, per_pin->pin_nid,
1881 per_pin->mux_idx);
1882 }
1883
1884 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1885 }
1886
1887 if (eld_changed)
1888 snd_ctl_notify(codec->card,
1889 SNDRV_CTL_EVENT_MASK_VALUE |
1890 SNDRV_CTL_EVENT_MASK_INFO,
1891 &per_pin->eld_ctl->id);
1892}
1893
Takashi Iwai788d4412015-11-12 15:36:13 +01001894/* update ELD and jack state via HD-audio verbs */
1895static bool hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin,
1896 int repoll)
Wu Fengguang079d88c2010-03-08 10:44:23 +08001897{
David Henningsson464837a2013-11-07 13:38:25 +01001898 struct hda_jack_tbl *jack;
Wu Fengguang744626d2011-11-16 16:29:47 +08001899 struct hda_codec *codec = per_pin->codec;
David Henningsson4bd038f2013-02-19 16:11:25 +01001900 struct hdmi_spec *spec = codec->spec;
1901 struct hdmi_eld *eld = &spec->temp_eld;
1902 struct hdmi_eld *pin_eld = &per_pin->sink_eld;
Wu Fengguang744626d2011-11-16 16:29:47 +08001903 hda_nid_t pin_nid = per_pin->pin_nid;
Stephen Warren5d44f922011-05-24 17:11:17 -06001904 /*
1905 * Always execute a GetPinSense verb here, even when called from
1906 * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
1907 * response's PD bit is not the real PD value, but indicates that
1908 * the real PD value changed. An older version of the HD-audio
1909 * specification worked this way. Hence, we just ignore the data in
1910 * the unsolicited response to avoid custom WARs.
1911 */
David Henningssonda4a7a32013-12-18 10:46:04 +01001912 int present;
Takashi Iwaiefe47102013-11-07 13:38:23 +01001913 bool ret;
Takashi Iwai9a5e5232015-12-10 14:35:09 +01001914 bool do_repoll = false;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001915
Takashi Iwai664c7152015-04-08 11:43:14 +02001916 snd_hda_power_up_pm(codec);
David Henningssonda4a7a32013-12-18 10:46:04 +01001917 present = snd_hda_pin_sense(codec, pin_nid);
1918
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001919 mutex_lock(&per_pin->lock);
David Henningsson4bd038f2013-02-19 16:11:25 +01001920 pin_eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
1921 if (pin_eld->monitor_present)
1922 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
1923 else
1924 eld->eld_valid = false;
Stephen Warren5d44f922011-05-24 17:11:17 -06001925
Takashi Iwai4e76a882014-02-25 12:21:03 +01001926 codec_dbg(codec,
Stephen Warren384a48d2011-06-01 11:14:21 -06001927 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
Mengdong Lin10250912013-03-28 05:21:28 -04001928 codec->addr, pin_nid, pin_eld->monitor_present, eld->eld_valid);
Stephen Warren5d44f922011-05-24 17:11:17 -06001929
David Henningsson4bd038f2013-02-19 16:11:25 +01001930 if (eld->eld_valid) {
Anssi Hannula307229d2013-10-24 21:10:34 +03001931 if (spec->ops.pin_get_eld(codec, pin_nid, eld->eld_buffer,
David Henningsson1613d6b2013-02-19 16:11:24 +01001932 &eld->eld_size) < 0)
David Henningsson4bd038f2013-02-19 16:11:25 +01001933 eld->eld_valid = false;
David Henningsson1613d6b2013-02-19 16:11:24 +01001934 else {
Takashi Iwai79514d42014-06-06 18:04:34 +02001935 if (snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer,
David Henningsson1613d6b2013-02-19 16:11:24 +01001936 eld->eld_size) < 0)
David Henningsson4bd038f2013-02-19 16:11:25 +01001937 eld->eld_valid = false;
David Henningsson1613d6b2013-02-19 16:11:24 +01001938 }
Takashi Iwai9a5e5232015-12-10 14:35:09 +01001939 if (!eld->eld_valid && repoll)
1940 do_repoll = true;
Wu Fengguang744626d2011-11-16 16:29:47 +08001941 }
David Henningsson4bd038f2013-02-19 16:11:25 +01001942
Takashi Iwai9a5e5232015-12-10 14:35:09 +01001943 if (do_repoll)
Takashi Iwaie90247f2015-11-13 09:12:12 +01001944 schedule_delayed_work(&per_pin->work, msecs_to_jiffies(300));
1945 else
1946 update_eld(codec, per_pin, eld);
Anssi Hannula6acce402014-10-19 19:25:19 +03001947
Takashi Iwaiaff747eb2013-11-07 16:39:37 +01001948 ret = !repoll || !pin_eld->monitor_present || pin_eld->eld_valid;
David Henningsson464837a2013-11-07 13:38:25 +01001949
1950 jack = snd_hda_jack_tbl_get(codec, pin_nid);
1951 if (jack)
1952 jack->block_report = !ret;
1953
Takashi Iwaia4e9a382013-10-17 18:21:12 +02001954 mutex_unlock(&per_pin->lock);
Takashi Iwai664c7152015-04-08 11:43:14 +02001955 snd_hda_power_down_pm(codec);
Takashi Iwaiefe47102013-11-07 13:38:23 +01001956 return ret;
Wu Fengguang079d88c2010-03-08 10:44:23 +08001957}
1958
Libin Yang31842702016-02-19 15:42:06 +08001959static struct snd_jack *pin_idx_to_jack(struct hda_codec *codec,
1960 struct hdmi_spec_per_pin *per_pin)
1961{
1962 struct hdmi_spec *spec = codec->spec;
1963 struct snd_jack *jack = NULL;
1964 struct hda_jack_tbl *jack_tbl;
1965
1966 /* if !dyn_pcm_assign, get jack from hda_jack_tbl
1967 * in !dyn_pcm_assign case, spec->pcm_rec[].jack is not
1968 * NULL even after snd_hda_jack_tbl_clear() is called to
1969 * free snd_jack. This may cause access invalid memory
1970 * when calling snd_jack_report
1971 */
1972 if (per_pin->pcm_idx >= 0 && spec->dyn_pcm_assign)
1973 jack = spec->pcm_rec[per_pin->pcm_idx].jack;
1974 else if (!spec->dyn_pcm_assign) {
1975 jack_tbl = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
1976 if (jack_tbl)
1977 jack = jack_tbl->jack;
1978 }
1979 return jack;
1980}
1981
Takashi Iwai788d4412015-11-12 15:36:13 +01001982/* update ELD and jack state via audio component */
1983static void sync_eld_via_acomp(struct hda_codec *codec,
1984 struct hdmi_spec_per_pin *per_pin)
1985{
Takashi Iwai788d4412015-11-12 15:36:13 +01001986 struct hdmi_spec *spec = codec->spec;
1987 struct hdmi_eld *eld = &spec->temp_eld;
Libin Yang25e4abb2016-01-12 11:13:27 +08001988 struct snd_jack *jack = NULL;
Takashi Iwai788d4412015-11-12 15:36:13 +01001989 int size;
1990
Takashi Iwaie2dc7d72015-12-01 12:39:38 +01001991 mutex_lock(&per_pin->lock);
1992 size = snd_hdac_acomp_get_eld(&codec->bus->core, per_pin->pin_nid,
1993 &eld->monitor_present, eld->eld_buffer,
1994 ELD_MAX_SIZE);
1995 if (size < 0)
1996 goto unlock;
1997 if (size > 0) {
1998 size = min(size, ELD_MAX_SIZE);
1999 if (snd_hdmi_parse_eld(codec, &eld->info,
2000 eld->eld_buffer, size) < 0)
2001 size = -EINVAL;
Takashi Iwai788d4412015-11-12 15:36:13 +01002002 }
Takashi Iwaie2dc7d72015-12-01 12:39:38 +01002003
2004 if (size > 0) {
2005 eld->eld_valid = true;
2006 eld->eld_size = size;
2007 } else {
2008 eld->eld_valid = false;
2009 eld->eld_size = 0;
2010 }
2011
Libin Yang25e4abb2016-01-12 11:13:27 +08002012 /* pcm_idx >=0 before update_eld() means it is in monitor
2013 * disconnected event. Jack must be fetched before update_eld()
2014 */
Libin Yang31842702016-02-19 15:42:06 +08002015 jack = pin_idx_to_jack(codec, per_pin);
Takashi Iwaie2dc7d72015-12-01 12:39:38 +01002016 update_eld(codec, per_pin, eld);
Libin Yang31842702016-02-19 15:42:06 +08002017 if (jack == NULL)
2018 jack = pin_idx_to_jack(codec, per_pin);
Libin Yang25e4abb2016-01-12 11:13:27 +08002019 if (jack == NULL)
2020 goto unlock;
2021 snd_jack_report(jack,
Takashi Iwaie2dc7d72015-12-01 12:39:38 +01002022 eld->monitor_present ? SND_JACK_AVOUT : 0);
2023 unlock:
2024 mutex_unlock(&per_pin->lock);
Takashi Iwai788d4412015-11-12 15:36:13 +01002025}
2026
2027static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
2028{
2029 struct hda_codec *codec = per_pin->codec;
Libin Yanga76056f2015-12-16 16:48:15 +08002030 struct hdmi_spec *spec = codec->spec;
2031 int ret;
Takashi Iwai788d4412015-11-12 15:36:13 +01002032
Libin Yanga76056f2015-12-16 16:48:15 +08002033 mutex_lock(&spec->pcm_lock);
Takashi Iwai788d4412015-11-12 15:36:13 +01002034 if (codec_has_acomp(codec)) {
2035 sync_eld_via_acomp(codec, per_pin);
Libin Yanga76056f2015-12-16 16:48:15 +08002036 ret = false; /* don't call snd_hda_jack_report_sync() */
Takashi Iwai788d4412015-11-12 15:36:13 +01002037 } else {
Libin Yanga76056f2015-12-16 16:48:15 +08002038 ret = hdmi_present_sense_via_verbs(per_pin, repoll);
Takashi Iwai788d4412015-11-12 15:36:13 +01002039 }
Libin Yanga76056f2015-12-16 16:48:15 +08002040 mutex_unlock(&spec->pcm_lock);
2041
2042 return ret;
Takashi Iwai788d4412015-11-12 15:36:13 +01002043}
2044
Wu Fengguang744626d2011-11-16 16:29:47 +08002045static void hdmi_repoll_eld(struct work_struct *work)
2046{
2047 struct hdmi_spec_per_pin *per_pin =
2048 container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
2049
Wu Fengguangc6e84532011-11-18 16:59:32 -06002050 if (per_pin->repoll_count++ > 6)
2051 per_pin->repoll_count = 0;
2052
Takashi Iwaiefe47102013-11-07 13:38:23 +01002053 if (hdmi_present_sense(per_pin, per_pin->repoll_count))
2054 snd_hda_jack_report_sync(per_pin->codec);
Wu Fengguang744626d2011-11-16 16:29:47 +08002055}
2056
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002057static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
2058 hda_nid_t nid);
2059
Wu Fengguang079d88c2010-03-08 10:44:23 +08002060static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
2061{
2062 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06002063 unsigned int caps, config;
2064 int pin_idx;
2065 struct hdmi_spec_per_pin *per_pin;
David Henningsson07acecc2011-05-19 11:46:03 +02002066 int err;
Wu Fengguang079d88c2010-03-08 10:44:23 +08002067
Takashi Iwaiefc2f8de2012-11-21 14:27:37 +01002068 caps = snd_hda_query_pin_caps(codec, pin_nid);
Stephen Warren384a48d2011-06-01 11:14:21 -06002069 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
2070 return 0;
2071
Takashi Iwaiefc2f8de2012-11-21 14:27:37 +01002072 config = snd_hda_codec_get_pincfg(codec, pin_nid);
Stephen Warren384a48d2011-06-01 11:14:21 -06002073 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
2074 return 0;
2075
Mengdong Lin75dcbe42014-01-08 15:55:32 -05002076 if (is_haswell_plus(codec))
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002077 intel_haswell_fixup_connect_list(codec, pin_nid);
2078
Stephen Warren384a48d2011-06-01 11:14:21 -06002079 pin_idx = spec->num_pins;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002080 per_pin = snd_array_new(&spec->pins);
2081 if (!per_pin)
2082 return -ENOMEM;
Stephen Warren384a48d2011-06-01 11:14:21 -06002083
2084 per_pin->pin_nid = pin_nid;
Takashi Iwai1a6003b2012-09-06 17:42:08 +02002085 per_pin->non_pcm = false;
Libin Yanga76056f2015-12-16 16:48:15 +08002086 if (spec->dyn_pcm_assign)
2087 per_pin->pcm_idx = -1;
Libin Yang2bea2412016-01-12 11:13:26 +08002088 else {
2089 per_pin->pcm = get_hdmi_pcm(spec, pin_idx);
Libin Yanga76056f2015-12-16 16:48:15 +08002090 per_pin->pcm_idx = pin_idx;
Libin Yang2bea2412016-01-12 11:13:26 +08002091 }
Libin Yanga76056f2015-12-16 16:48:15 +08002092 per_pin->pin_nid_idx = pin_idx;
Wu Fengguang079d88c2010-03-08 10:44:23 +08002093
Stephen Warren384a48d2011-06-01 11:14:21 -06002094 err = hdmi_read_pin_conn(codec, pin_idx);
2095 if (err < 0)
2096 return err;
Wu Fengguang079d88c2010-03-08 10:44:23 +08002097
Wu Fengguang079d88c2010-03-08 10:44:23 +08002098 spec->num_pins++;
2099
Stephen Warren384a48d2011-06-01 11:14:21 -06002100 return 0;
Wu Fengguang079d88c2010-03-08 10:44:23 +08002101}
2102
Stephen Warren384a48d2011-06-01 11:14:21 -06002103static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
Wu Fengguang079d88c2010-03-08 10:44:23 +08002104{
2105 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06002106 struct hdmi_spec_per_cvt *per_cvt;
2107 unsigned int chans;
2108 int err;
Wu Fengguang079d88c2010-03-08 10:44:23 +08002109
Stephen Warren384a48d2011-06-01 11:14:21 -06002110 chans = get_wcaps(codec, cvt_nid);
2111 chans = get_wcaps_channels(chans);
2112
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002113 per_cvt = snd_array_new(&spec->cvts);
2114 if (!per_cvt)
2115 return -ENOMEM;
Stephen Warren384a48d2011-06-01 11:14:21 -06002116
2117 per_cvt->cvt_nid = cvt_nid;
2118 per_cvt->channels_min = 2;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002119 if (chans <= 16) {
Stephen Warren384a48d2011-06-01 11:14:21 -06002120 per_cvt->channels_max = chans;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002121 if (chans > spec->channels_max)
2122 spec->channels_max = chans;
2123 }
Stephen Warren384a48d2011-06-01 11:14:21 -06002124
2125 err = snd_hda_query_supported_pcm(codec, cvt_nid,
2126 &per_cvt->rates,
2127 &per_cvt->formats,
2128 &per_cvt->maxbps);
2129 if (err < 0)
2130 return err;
2131
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002132 if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids))
2133 spec->cvt_nids[spec->num_cvts] = cvt_nid;
2134 spec->num_cvts++;
Wu Fengguang079d88c2010-03-08 10:44:23 +08002135
2136 return 0;
2137}
2138
2139static int hdmi_parse_codec(struct hda_codec *codec)
2140{
2141 hda_nid_t nid;
2142 int i, nodes;
2143
Takashi Iwai7639a062015-03-03 10:07:24 +01002144 nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08002145 if (!nid || nodes < 0) {
Takashi Iwai4e76a882014-02-25 12:21:03 +01002146 codec_warn(codec, "HDMI: failed to get afg sub nodes\n");
Wu Fengguang079d88c2010-03-08 10:44:23 +08002147 return -EINVAL;
2148 }
2149
2150 for (i = 0; i < nodes; i++, nid++) {
2151 unsigned int caps;
2152 unsigned int type;
2153
Takashi Iwaiefc2f8de2012-11-21 14:27:37 +01002154 caps = get_wcaps(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08002155 type = get_wcaps_type(caps);
2156
2157 if (!(caps & AC_WCAP_DIGITAL))
2158 continue;
2159
2160 switch (type) {
2161 case AC_WID_AUD_OUT:
Stephen Warren384a48d2011-06-01 11:14:21 -06002162 hdmi_add_cvt(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08002163 break;
2164 case AC_WID_PIN:
Wu Fengguang3eaead52010-05-14 16:36:15 +08002165 hdmi_add_pin(codec, nid);
Wu Fengguang079d88c2010-03-08 10:44:23 +08002166 break;
2167 }
2168 }
2169
Wu Fengguang079d88c2010-03-08 10:44:23 +08002170 return 0;
2171}
2172
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002173/*
2174 */
Takashi Iwai1a6003b2012-09-06 17:42:08 +02002175static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
2176{
2177 struct hda_spdif_out *spdif;
2178 bool non_pcm;
2179
2180 mutex_lock(&codec->spdif_mutex);
2181 spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
2182 non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO);
2183 mutex_unlock(&codec->spdif_mutex);
2184 return non_pcm;
2185}
2186
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002187/*
2188 * HDMI callbacks
2189 */
2190
2191static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2192 struct hda_codec *codec,
2193 unsigned int stream_tag,
2194 unsigned int format,
2195 struct snd_pcm_substream *substream)
2196{
Stephen Warren384a48d2011-06-01 11:14:21 -06002197 hda_nid_t cvt_nid = hinfo->nid;
2198 struct hdmi_spec *spec = codec->spec;
Libin Yang42b29872015-12-16 13:42:42 +08002199 int pin_idx;
2200 struct hdmi_spec_per_pin *per_pin;
2201 hda_nid_t pin_nid;
Libin Yangddd621f2015-09-02 14:11:40 +08002202 struct snd_pcm_runtime *runtime = substream->runtime;
Takashi Iwai1a6003b2012-09-06 17:42:08 +02002203 bool non_pcm;
Stephen Warren75fae112014-01-30 11:52:16 -07002204 int pinctl;
Libin Yang42b29872015-12-16 13:42:42 +08002205 int err;
Takashi Iwai1a6003b2012-09-06 17:42:08 +02002206
Libin Yang42b29872015-12-16 13:42:42 +08002207 mutex_lock(&spec->pcm_lock);
2208 pin_idx = hinfo_to_pin_index(codec, hinfo);
2209 if (spec->dyn_pcm_assign && pin_idx < 0) {
2210 /* when dyn_pcm_assign and pcm is not bound to a pin
2211 * skip pin setup and return 0 to make audio playback
2212 * be ongoing
2213 */
2214 intel_not_share_assigned_cvt_nid(codec, 0, cvt_nid);
2215 snd_hda_codec_setup_stream(codec, cvt_nid,
2216 stream_tag, 0, format);
2217 mutex_unlock(&spec->pcm_lock);
2218 return 0;
2219 }
2220
2221 if (snd_BUG_ON(pin_idx < 0)) {
2222 mutex_unlock(&spec->pcm_lock);
2223 return -EINVAL;
2224 }
2225 per_pin = get_pin(spec, pin_idx);
2226 pin_nid = per_pin->pin_nid;
Libin Yangca2e7222014-08-19 16:20:12 +08002227 if (is_haswell_plus(codec) || is_valleyview_plus(codec)) {
Mengdong Lin2df67422014-03-20 13:01:06 +08002228 /* Verify pin:cvt selections to avoid silent audio after S3.
2229 * After S3, the audio driver restores pin:cvt selections
2230 * but this can happen before gfx is ready and such selection
2231 * is overlooked by HW. Thus multiple pins can share a same
2232 * default convertor and mute control will affect each other,
2233 * which can cause a resumed audio playback become silent
2234 * after S3.
2235 */
2236 intel_verify_pin_cvt_connect(codec, per_pin);
2237 intel_not_share_assigned_cvt(codec, pin_nid, per_pin->mux_idx);
2238 }
2239
Libin Yangddd621f2015-09-02 14:11:40 +08002240 /* Call sync_audio_rate to set the N/CTS/M manually if necessary */
2241 /* Todo: add DP1.2 MST audio support later */
Takashi Iwaie2dc7d72015-12-01 12:39:38 +01002242 snd_hdac_sync_audio_rate(&codec->bus->core, pin_nid, runtime->rate);
Libin Yangddd621f2015-09-02 14:11:40 +08002243
Takashi Iwai1a6003b2012-09-06 17:42:08 +02002244 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002245 mutex_lock(&per_pin->lock);
Takashi Iwaib0540872013-09-02 12:33:02 +02002246 per_pin->channels = substream->runtime->channels;
2247 per_pin->setup = true;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002248
Takashi Iwaib0540872013-09-02 12:33:02 +02002249 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002250 mutex_unlock(&per_pin->lock);
Stephen Warren75fae112014-01-30 11:52:16 -07002251 if (spec->dyn_pin_out) {
2252 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
2253 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2254 snd_hda_codec_write(codec, pin_nid, 0,
2255 AC_VERB_SET_PIN_WIDGET_CONTROL,
2256 pinctl | PIN_OUT);
2257 }
2258
Libin Yang42b29872015-12-16 13:42:42 +08002259 err = spec->ops.setup_stream(codec, cvt_nid, pin_nid,
2260 stream_tag, format);
2261 mutex_unlock(&spec->pcm_lock);
2262 return err;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002263}
2264
Takashi Iwai8dfaa572012-08-06 14:49:36 +02002265static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2266 struct hda_codec *codec,
2267 struct snd_pcm_substream *substream)
2268{
2269 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
2270 return 0;
2271}
2272
Takashi Iwaif2ad24f2012-07-26 18:08:14 +02002273static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
2274 struct hda_codec *codec,
2275 struct snd_pcm_substream *substream)
Stephen Warren384a48d2011-06-01 11:14:21 -06002276{
2277 struct hdmi_spec *spec = codec->spec;
Libin Yang2bf3c852015-12-16 13:42:43 +08002278 int cvt_idx, pin_idx, pcm_idx;
Stephen Warren384a48d2011-06-01 11:14:21 -06002279 struct hdmi_spec_per_cvt *per_cvt;
2280 struct hdmi_spec_per_pin *per_pin;
Stephen Warren75fae112014-01-30 11:52:16 -07002281 int pinctl;
Stephen Warren384a48d2011-06-01 11:14:21 -06002282
Stephen Warren384a48d2011-06-01 11:14:21 -06002283 if (hinfo->nid) {
Libin Yang2bf3c852015-12-16 13:42:43 +08002284 pcm_idx = hinfo_to_pcm_index(codec, hinfo);
2285 if (snd_BUG_ON(pcm_idx < 0))
2286 return -EINVAL;
Takashi Iwai4e76a882014-02-25 12:21:03 +01002287 cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid);
Stephen Warren384a48d2011-06-01 11:14:21 -06002288 if (snd_BUG_ON(cvt_idx < 0))
2289 return -EINVAL;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002290 per_cvt = get_cvt(spec, cvt_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06002291
2292 snd_BUG_ON(!per_cvt->assigned);
2293 per_cvt->assigned = 0;
2294 hinfo->nid = 0;
2295
Libin Yang42b29872015-12-16 13:42:42 +08002296 mutex_lock(&spec->pcm_lock);
Libin Yangb09887f82016-01-29 13:53:27 +08002297 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
Libin Yangac983792015-12-16 16:48:16 +08002298 clear_bit(pcm_idx, &spec->pcm_in_use);
Takashi Iwai4e76a882014-02-25 12:21:03 +01002299 pin_idx = hinfo_to_pin_index(codec, hinfo);
Libin Yang42b29872015-12-16 13:42:42 +08002300 if (spec->dyn_pcm_assign && pin_idx < 0) {
2301 mutex_unlock(&spec->pcm_lock);
2302 return 0;
2303 }
2304
2305 if (snd_BUG_ON(pin_idx < 0)) {
2306 mutex_unlock(&spec->pcm_lock);
Stephen Warren384a48d2011-06-01 11:14:21 -06002307 return -EINVAL;
Libin Yang42b29872015-12-16 13:42:42 +08002308 }
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002309 per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06002310
Stephen Warren75fae112014-01-30 11:52:16 -07002311 if (spec->dyn_pin_out) {
2312 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
2313 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2314 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
2315 AC_VERB_SET_PIN_WIDGET_CONTROL,
2316 pinctl & ~PIN_OUT);
2317 }
2318
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002319 mutex_lock(&per_pin->lock);
Takashi Iwaid45e6882012-07-31 11:36:00 +02002320 per_pin->chmap_set = false;
2321 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
Takashi Iwaib0540872013-09-02 12:33:02 +02002322
2323 per_pin->setup = false;
2324 per_pin->channels = 0;
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002325 mutex_unlock(&per_pin->lock);
Libin Yang42b29872015-12-16 13:42:42 +08002326 mutex_unlock(&spec->pcm_lock);
Stephen Warren384a48d2011-06-01 11:14:21 -06002327 }
Takashi Iwaid45e6882012-07-31 11:36:00 +02002328
Stephen Warren384a48d2011-06-01 11:14:21 -06002329 return 0;
2330}
2331
2332static const struct hda_pcm_ops generic_ops = {
2333 .open = hdmi_pcm_open,
Takashi Iwaif2ad24f2012-07-26 18:08:14 +02002334 .close = hdmi_pcm_close,
Stephen Warren384a48d2011-06-01 11:14:21 -06002335 .prepare = generic_hdmi_playback_pcm_prepare,
Takashi Iwai8dfaa572012-08-06 14:49:36 +02002336 .cleanup = generic_hdmi_playback_pcm_cleanup,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002337};
2338
Takashi Iwaid45e6882012-07-31 11:36:00 +02002339/*
2340 * ALSA API channel-map control callbacks
2341 */
2342static int hdmi_chmap_ctl_info(struct snd_kcontrol *kcontrol,
2343 struct snd_ctl_elem_info *uinfo)
2344{
2345 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
2346 struct hda_codec *codec = info->private_data;
2347 struct hdmi_spec *spec = codec->spec;
2348 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2349 uinfo->count = spec->channels_max;
2350 uinfo->value.integer.min = 0;
2351 uinfo->value.integer.max = SNDRV_CHMAP_LAST;
2352 return 0;
2353}
2354
Anssi Hannula307229d2013-10-24 21:10:34 +03002355static int hdmi_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap,
2356 int channels)
2357{
2358 /* If the speaker allocation matches the channel count, it is OK.*/
2359 if (cap->channels != channels)
2360 return -1;
2361
2362 /* all channels are remappable freely */
2363 return SNDRV_CTL_TLVT_CHMAP_VAR;
2364}
2365
2366static void hdmi_cea_alloc_to_tlv_chmap(struct cea_channel_speaker_allocation *cap,
2367 unsigned int *chmap, int channels)
2368{
2369 int count = 0;
2370 int c;
2371
2372 for (c = 7; c >= 0; c--) {
2373 int spk = cap->speakers[c];
2374 if (!spk)
2375 continue;
2376
2377 chmap[count++] = spk_to_chmap(spk);
2378 }
2379
2380 WARN_ON(count != channels);
2381}
2382
Takashi Iwaid45e6882012-07-31 11:36:00 +02002383static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
2384 unsigned int size, unsigned int __user *tlv)
2385{
2386 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
2387 struct hda_codec *codec = info->private_data;
2388 struct hdmi_spec *spec = codec->spec;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002389 unsigned int __user *dst;
2390 int chs, count = 0;
2391
2392 if (size < 8)
2393 return -ENOMEM;
2394 if (put_user(SNDRV_CTL_TLVT_CONTAINER, tlv))
2395 return -EFAULT;
2396 size -= 8;
2397 dst = tlv + 2;
Takashi Iwai498dab32012-09-10 16:08:40 +02002398 for (chs = 2; chs <= spec->channels_max; chs++) {
Anssi Hannula307229d2013-10-24 21:10:34 +03002399 int i;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002400 struct cea_channel_speaker_allocation *cap;
2401 cap = channel_allocations;
2402 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++, cap++) {
2403 int chs_bytes = chs * 4;
Anssi Hannula307229d2013-10-24 21:10:34 +03002404 int type = spec->ops.chmap_cea_alloc_validate_get_type(cap, chs);
2405 unsigned int tlv_chmap[8];
2406
2407 if (type < 0)
Takashi Iwaid45e6882012-07-31 11:36:00 +02002408 continue;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002409 if (size < 8)
2410 return -ENOMEM;
Anssi Hannula307229d2013-10-24 21:10:34 +03002411 if (put_user(type, dst) ||
Takashi Iwaid45e6882012-07-31 11:36:00 +02002412 put_user(chs_bytes, dst + 1))
2413 return -EFAULT;
2414 dst += 2;
2415 size -= 8;
2416 count += 8;
2417 if (size < chs_bytes)
2418 return -ENOMEM;
2419 size -= chs_bytes;
2420 count += chs_bytes;
Anssi Hannula307229d2013-10-24 21:10:34 +03002421 spec->ops.cea_alloc_to_tlv_chmap(cap, tlv_chmap, chs);
2422 if (copy_to_user(dst, tlv_chmap, chs_bytes))
2423 return -EFAULT;
2424 dst += chs;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002425 }
2426 }
2427 if (put_user(count, tlv + 1))
2428 return -EFAULT;
2429 return 0;
2430}
2431
2432static int hdmi_chmap_ctl_get(struct snd_kcontrol *kcontrol,
2433 struct snd_ctl_elem_value *ucontrol)
2434{
2435 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
2436 struct hda_codec *codec = info->private_data;
2437 struct hdmi_spec *spec = codec->spec;
Libin Yang022f3442016-02-03 10:48:34 +08002438 int pcm_idx = kcontrol->private_value;
2439 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
Takashi Iwaid45e6882012-07-31 11:36:00 +02002440 int i;
2441
Libin Yang022f3442016-02-03 10:48:34 +08002442 if (!per_pin) {
2443 for (i = 0; i < spec->channels_max; i++)
2444 ucontrol->value.integer.value[i] = 0;
2445 return 0;
2446 }
2447
Takashi Iwaid45e6882012-07-31 11:36:00 +02002448 for (i = 0; i < ARRAY_SIZE(per_pin->chmap); i++)
2449 ucontrol->value.integer.value[i] = per_pin->chmap[i];
2450 return 0;
2451}
2452
2453static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
2454 struct snd_ctl_elem_value *ucontrol)
2455{
2456 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
2457 struct hda_codec *codec = info->private_data;
2458 struct hdmi_spec *spec = codec->spec;
Libin Yang022f3442016-02-03 10:48:34 +08002459 int pcm_idx = kcontrol->private_value;
2460 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
Takashi Iwaid45e6882012-07-31 11:36:00 +02002461 unsigned int ctl_idx;
2462 struct snd_pcm_substream *substream;
2463 unsigned char chmap[8];
Anssi Hannula307229d2013-10-24 21:10:34 +03002464 int i, err, ca, prepared = 0;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002465
Libin Yang022f3442016-02-03 10:48:34 +08002466 /* No monitor is connected in dyn_pcm_assign.
2467 * It's invalid to setup the chmap
2468 */
2469 if (!per_pin)
2470 return 0;
2471
Takashi Iwaid45e6882012-07-31 11:36:00 +02002472 ctl_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2473 substream = snd_pcm_chmap_substream(info, ctl_idx);
2474 if (!substream || !substream->runtime)
Takashi Iwai6f54c362013-01-15 14:44:41 +01002475 return 0; /* just for avoiding error from alsactl restore */
Takashi Iwaid45e6882012-07-31 11:36:00 +02002476 switch (substream->runtime->status->state) {
2477 case SNDRV_PCM_STATE_OPEN:
2478 case SNDRV_PCM_STATE_SETUP:
2479 break;
2480 case SNDRV_PCM_STATE_PREPARED:
2481 prepared = 1;
2482 break;
2483 default:
2484 return -EBUSY;
2485 }
2486 memset(chmap, 0, sizeof(chmap));
2487 for (i = 0; i < ARRAY_SIZE(chmap); i++)
2488 chmap[i] = ucontrol->value.integer.value[i];
2489 if (!memcmp(chmap, per_pin->chmap, sizeof(chmap)))
2490 return 0;
2491 ca = hdmi_manual_channel_allocation(ARRAY_SIZE(chmap), chmap);
2492 if (ca < 0)
2493 return -EINVAL;
Anssi Hannula307229d2013-10-24 21:10:34 +03002494 if (spec->ops.chmap_validate) {
2495 err = spec->ops.chmap_validate(ca, ARRAY_SIZE(chmap), chmap);
2496 if (err)
2497 return err;
2498 }
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002499 mutex_lock(&per_pin->lock);
Takashi Iwaid45e6882012-07-31 11:36:00 +02002500 per_pin->chmap_set = true;
2501 memcpy(per_pin->chmap, chmap, sizeof(chmap));
2502 if (prepared)
Takashi Iwaib0540872013-09-02 12:33:02 +02002503 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002504 mutex_unlock(&per_pin->lock);
Takashi Iwaid45e6882012-07-31 11:36:00 +02002505
2506 return 0;
2507}
2508
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002509static int generic_hdmi_build_pcms(struct hda_codec *codec)
2510{
2511 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06002512 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002513
Stephen Warren384a48d2011-06-01 11:14:21 -06002514 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2515 struct hda_pcm *info;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002516 struct hda_pcm_stream *pstr;
2517
Takashi Iwaibbbc7e82015-02-27 17:43:19 +01002518 info = snd_hda_codec_pcm_new(codec, "HDMI %d", pin_idx);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002519 if (!info)
2520 return -ENOMEM;
Libin Yang2bea2412016-01-12 11:13:26 +08002521
2522 spec->pcm_rec[pin_idx].pcm = info;
Libin Yang2bf3c852015-12-16 13:42:43 +08002523 spec->pcm_used++;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002524 info->pcm_type = HDA_PCM_TYPE_HDMI;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002525 info->own_chmap = true;
Stephen Warren384a48d2011-06-01 11:14:21 -06002526
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002527 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
Stephen Warren384a48d2011-06-01 11:14:21 -06002528 pstr->substreams = 1;
2529 pstr->ops = generic_ops;
2530 /* other pstr fields are set in open */
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002531 }
2532
2533 return 0;
2534}
2535
Libin Yang25e4abb2016-01-12 11:13:27 +08002536static void free_hdmi_jack_priv(struct snd_jack *jack)
Takashi Iwai788d4412015-11-12 15:36:13 +01002537{
Libin Yang25e4abb2016-01-12 11:13:27 +08002538 struct hdmi_pcm *pcm = jack->private_data;
Takashi Iwai788d4412015-11-12 15:36:13 +01002539
Libin Yang25e4abb2016-01-12 11:13:27 +08002540 pcm->jack = NULL;
Takashi Iwai788d4412015-11-12 15:36:13 +01002541}
2542
Libin Yang25e4abb2016-01-12 11:13:27 +08002543static int add_hdmi_jack_kctl(struct hda_codec *codec,
2544 struct hdmi_spec *spec,
2545 int pcm_idx,
Takashi Iwai788d4412015-11-12 15:36:13 +01002546 const char *name)
2547{
2548 struct snd_jack *jack;
2549 int err;
2550
2551 err = snd_jack_new(codec->card, name, SND_JACK_AVOUT, &jack,
2552 true, false);
2553 if (err < 0)
2554 return err;
Libin Yang25e4abb2016-01-12 11:13:27 +08002555
2556 spec->pcm_rec[pcm_idx].jack = jack;
2557 jack->private_data = &spec->pcm_rec[pcm_idx];
2558 jack->private_free = free_hdmi_jack_priv;
Takashi Iwai788d4412015-11-12 15:36:13 +01002559 return 0;
2560}
2561
Libin Yang25e4abb2016-01-12 11:13:27 +08002562static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx)
David Henningsson0b6c49b2011-08-23 16:56:03 +02002563{
Takashi Iwai31ef2252011-12-01 17:41:36 +01002564 char hdmi_str[32] = "HDMI/DP";
David Henningsson0b6c49b2011-08-23 16:56:03 +02002565 struct hdmi_spec *spec = codec->spec;
Libin Yang25e4abb2016-01-12 11:13:27 +08002566 struct hdmi_spec_per_pin *per_pin;
2567 struct hda_jack_tbl *jack;
2568 int pcmdev = get_pcm_rec(spec, pcm_idx)->device;
Takashi Iwai909cadc2015-11-12 11:52:13 +01002569 bool phantom_jack;
Libin Yang25e4abb2016-01-12 11:13:27 +08002570 int ret;
David Henningsson0b6c49b2011-08-23 16:56:03 +02002571
Takashi Iwai31ef2252011-12-01 17:41:36 +01002572 if (pcmdev > 0)
2573 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
Libin Yang25e4abb2016-01-12 11:13:27 +08002574
2575 if (spec->dyn_pcm_assign)
2576 return add_hdmi_jack_kctl(codec, spec, pcm_idx, hdmi_str);
2577
2578 /* for !dyn_pcm_assign, we still use hda_jack for compatibility */
2579 /* if !dyn_pcm_assign, it must be non-MST mode.
2580 * This means pcms and pins are statically mapped.
2581 * And pcm_idx is pin_idx.
2582 */
2583 per_pin = get_pin(spec, pcm_idx);
Takashi Iwai909cadc2015-11-12 11:52:13 +01002584 phantom_jack = !is_jack_detectable(codec, per_pin->pin_nid);
2585 if (phantom_jack)
David Henningsson30efd8d2013-02-22 10:16:28 +01002586 strncat(hdmi_str, " Phantom",
2587 sizeof(hdmi_str) - strlen(hdmi_str) - 1);
Libin Yang25e4abb2016-01-12 11:13:27 +08002588 ret = snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str,
2589 phantom_jack);
2590 if (ret < 0)
2591 return ret;
2592 jack = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
2593 if (jack == NULL)
2594 return 0;
2595 /* assign jack->jack to pcm_rec[].jack to
2596 * align with dyn_pcm_assign mode
2597 */
2598 spec->pcm_rec[pcm_idx].jack = jack->jack;
2599 return 0;
David Henningsson0b6c49b2011-08-23 16:56:03 +02002600}
2601
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002602static int generic_hdmi_build_controls(struct hda_codec *codec)
2603{
2604 struct hdmi_spec *spec = codec->spec;
2605 int err;
Libin Yang25e4abb2016-01-12 11:13:27 +08002606 int pin_idx, pcm_idx;
2607
2608
2609 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2610 err = generic_hdmi_build_jack(codec, pcm_idx);
2611 if (err < 0)
2612 return err;
Libin Yangb09887f82016-01-29 13:53:27 +08002613
2614 /* create the spdif for each pcm
2615 * pin will be bound when monitor is connected
2616 */
2617 if (spec->dyn_pcm_assign)
2618 err = snd_hda_create_dig_out_ctls(codec,
2619 0, spec->cvt_nids[0],
2620 HDA_PCM_TYPE_HDMI);
2621 else {
2622 struct hdmi_spec_per_pin *per_pin =
2623 get_pin(spec, pcm_idx);
2624 err = snd_hda_create_dig_out_ctls(codec,
2625 per_pin->pin_nid,
2626 per_pin->mux_nids[0],
2627 HDA_PCM_TYPE_HDMI);
2628 }
2629 if (err < 0)
2630 return err;
2631 snd_hda_spdif_ctls_unassign(codec, pcm_idx);
Libin Yang25e4abb2016-01-12 11:13:27 +08002632 }
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002633
Stephen Warren384a48d2011-06-01 11:14:21 -06002634 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002635 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
David Henningsson0b6c49b2011-08-23 16:56:03 +02002636
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -05002637 /* add control for ELD Bytes */
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002638 err = hdmi_create_eld_ctl(codec, pin_idx,
Libin Yang2bea2412016-01-12 11:13:26 +08002639 get_pcm_rec(spec, pin_idx)->device);
Pierre-Louis Bossart14bc52b2011-09-30 16:35:41 -05002640
2641 if (err < 0)
2642 return err;
Takashi Iwai31ef2252011-12-01 17:41:36 +01002643
Takashi Iwai82b1d732011-12-20 15:53:07 +01002644 hdmi_present_sense(per_pin, 0);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002645 }
2646
Takashi Iwaid45e6882012-07-31 11:36:00 +02002647 /* add channel maps */
Libin Yang022f3442016-02-03 10:48:34 +08002648 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
Takashi Iwaibbbc7e82015-02-27 17:43:19 +01002649 struct hda_pcm *pcm;
Takashi Iwaid45e6882012-07-31 11:36:00 +02002650 struct snd_pcm_chmap *chmap;
2651 struct snd_kcontrol *kctl;
2652 int i;
Takashi Iwai2ca320e2013-08-22 09:55:36 +02002653
Libin Yang022f3442016-02-03 10:48:34 +08002654 pcm = get_pcm_rec(spec, pcm_idx);
Takashi Iwaibbbc7e82015-02-27 17:43:19 +01002655 if (!pcm || !pcm->pcm)
Takashi Iwai2ca320e2013-08-22 09:55:36 +02002656 break;
Takashi Iwaibbbc7e82015-02-27 17:43:19 +01002657 err = snd_pcm_add_chmap_ctls(pcm->pcm,
Takashi Iwaid45e6882012-07-31 11:36:00 +02002658 SNDRV_PCM_STREAM_PLAYBACK,
Libin Yang022f3442016-02-03 10:48:34 +08002659 NULL, 0, pcm_idx, &chmap);
Takashi Iwaid45e6882012-07-31 11:36:00 +02002660 if (err < 0)
2661 return err;
2662 /* override handlers */
2663 chmap->private_data = codec;
2664 kctl = chmap->kctl;
2665 for (i = 0; i < kctl->count; i++)
2666 kctl->vd[i].access |= SNDRV_CTL_ELEM_ACCESS_WRITE;
2667 kctl->info = hdmi_chmap_ctl_info;
2668 kctl->get = hdmi_chmap_ctl_get;
2669 kctl->put = hdmi_chmap_ctl_put;
2670 kctl->tlv.c = hdmi_chmap_ctl_tlv;
2671 }
2672
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002673 return 0;
2674}
2675
Takashi Iwai8b8d6542012-06-20 16:32:22 +02002676static int generic_hdmi_init_per_pins(struct hda_codec *codec)
2677{
2678 struct hdmi_spec *spec = codec->spec;
2679 int pin_idx;
2680
2681 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002682 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Takashi Iwai8b8d6542012-06-20 16:32:22 +02002683
2684 per_pin->codec = codec;
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002685 mutex_init(&per_pin->lock);
Takashi Iwai8b8d6542012-06-20 16:32:22 +02002686 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002687 eld_proc_new(per_pin, pin_idx);
Takashi Iwai8b8d6542012-06-20 16:32:22 +02002688 }
2689 return 0;
2690}
2691
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002692static int generic_hdmi_init(struct hda_codec *codec)
2693{
2694 struct hdmi_spec *spec = codec->spec;
Stephen Warren384a48d2011-06-01 11:14:21 -06002695 int pin_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002696
Stephen Warren384a48d2011-06-01 11:14:21 -06002697 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002698 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Stephen Warren384a48d2011-06-01 11:14:21 -06002699 hda_nid_t pin_nid = per_pin->pin_nid;
Stephen Warren384a48d2011-06-01 11:14:21 -06002700
2701 hdmi_init_pin(codec, pin_nid);
Takashi Iwai788d4412015-11-12 15:36:13 +01002702 if (!codec_has_acomp(codec))
2703 snd_hda_jack_detect_enable_callback(codec, pin_nid,
2704 codec->jackpoll_interval > 0 ?
2705 jack_callback : NULL);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002706 }
2707 return 0;
2708}
2709
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002710static void hdmi_array_init(struct hdmi_spec *spec, int nums)
2711{
2712 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums);
2713 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002714}
2715
2716static void hdmi_array_free(struct hdmi_spec *spec)
2717{
2718 snd_array_free(&spec->pins);
2719 snd_array_free(&spec->cvts);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002720}
2721
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002722static void generic_hdmi_free(struct hda_codec *codec)
2723{
2724 struct hdmi_spec *spec = codec->spec;
Libin Yang25e4abb2016-01-12 11:13:27 +08002725 int pin_idx, pcm_idx;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002726
Takashi Iwai66032492015-12-01 16:49:35 +01002727 if (codec_has_acomp(codec))
David Henningsson25adc132015-08-19 10:48:58 +02002728 snd_hdac_i915_register_notifier(NULL);
2729
Stephen Warren384a48d2011-06-01 11:14:21 -06002730 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002731 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
Takashi Iwai2f35c632015-02-27 22:43:26 +01002732 cancel_delayed_work_sync(&per_pin->work);
Takashi Iwaia4e9a382013-10-17 18:21:12 +02002733 eld_proc_free(per_pin);
Libin Yang25e4abb2016-01-12 11:13:27 +08002734 }
2735
2736 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
2737 if (spec->pcm_rec[pcm_idx].jack == NULL)
2738 continue;
2739 if (spec->dyn_pcm_assign)
2740 snd_device_free(codec->card,
2741 spec->pcm_rec[pcm_idx].jack);
2742 else
2743 spec->pcm_rec[pcm_idx].jack = NULL;
Stephen Warren384a48d2011-06-01 11:14:21 -06002744 }
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002745
Takashi Iwai55913112015-12-10 13:03:29 +01002746 if (spec->i915_bound)
2747 snd_hdac_i915_exit(&codec->bus->core);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002748 hdmi_array_free(spec);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002749 kfree(spec);
2750}
2751
Wang Xingchao28cb72e2013-06-24 07:45:23 -04002752#ifdef CONFIG_PM
2753static int generic_hdmi_resume(struct hda_codec *codec)
2754{
2755 struct hdmi_spec *spec = codec->spec;
2756 int pin_idx;
2757
Pierre Ossmana2833682014-06-18 21:48:09 +02002758 codec->patch_ops.init(codec);
Takashi Iwaieeecd9d2015-02-25 15:18:50 +01002759 regcache_sync(codec->core.regmap);
Wang Xingchao28cb72e2013-06-24 07:45:23 -04002760
2761 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2762 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2763 hdmi_present_sense(per_pin, 1);
2764 }
2765 return 0;
2766}
2767#endif
2768
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02002769static const struct hda_codec_ops generic_hdmi_patch_ops = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002770 .init = generic_hdmi_init,
2771 .free = generic_hdmi_free,
2772 .build_pcms = generic_hdmi_build_pcms,
2773 .build_controls = generic_hdmi_build_controls,
2774 .unsol_event = hdmi_unsol_event,
Wang Xingchao28cb72e2013-06-24 07:45:23 -04002775#ifdef CONFIG_PM
2776 .resume = generic_hdmi_resume,
2777#endif
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002778};
2779
Anssi Hannula307229d2013-10-24 21:10:34 +03002780static const struct hdmi_ops generic_standard_hdmi_ops = {
2781 .pin_get_eld = snd_hdmi_get_eld,
2782 .pin_get_slot_channel = hdmi_pin_get_slot_channel,
2783 .pin_set_slot_channel = hdmi_pin_set_slot_channel,
2784 .pin_setup_infoframe = hdmi_pin_setup_infoframe,
2785 .pin_hbr_setup = hdmi_pin_hbr_setup,
2786 .setup_stream = hdmi_setup_stream,
2787 .chmap_cea_alloc_validate_get_type = hdmi_chmap_cea_alloc_validate_get_type,
2788 .cea_alloc_to_tlv_chmap = hdmi_cea_alloc_to_tlv_chmap,
2789};
2790
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002791
2792static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
2793 hda_nid_t nid)
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002794{
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002795 struct hdmi_spec *spec = codec->spec;
2796 hda_nid_t conns[4];
2797 int nconns;
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002798
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002799 nconns = snd_hda_get_connections(codec, nid, conns, ARRAY_SIZE(conns));
2800 if (nconns == spec->num_cvts &&
2801 !memcmp(conns, spec->cvt_nids, spec->num_cvts * sizeof(hda_nid_t)))
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002802 return;
2803
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002804 /* override pins connection list */
Takashi Iwai4e76a882014-02-25 12:21:03 +01002805 codec_dbg(codec, "hdmi: haswell: override pin connection 0x%x\n", nid);
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002806 snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids);
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002807}
2808
Mengdong Lin1611a9c2013-02-08 17:09:52 -05002809#define INTEL_VENDOR_NID 0x08
2810#define INTEL_GET_VENDOR_VERB 0xf81
2811#define INTEL_SET_VENDOR_VERB 0x781
2812#define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
2813#define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
2814
2815static void intel_haswell_enable_all_pins(struct hda_codec *codec,
Takashi Iwai17df3f52013-05-08 08:09:34 +02002816 bool update_tree)
Mengdong Lin1611a9c2013-02-08 17:09:52 -05002817{
2818 unsigned int vendor_param;
2819
Mengdong Lin1611a9c2013-02-08 17:09:52 -05002820 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
2821 INTEL_GET_VENDOR_VERB, 0);
2822 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
2823 return;
2824
2825 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
2826 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
2827 INTEL_SET_VENDOR_VERB, vendor_param);
2828 if (vendor_param == -1)
2829 return;
2830
Takashi Iwai17df3f52013-05-08 08:09:34 +02002831 if (update_tree)
2832 snd_hda_codec_update_widgets(codec);
Mengdong Lin1611a9c2013-02-08 17:09:52 -05002833}
2834
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002835static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
2836{
2837 unsigned int vendor_param;
2838
2839 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
2840 INTEL_GET_VENDOR_VERB, 0);
2841 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
2842 return;
2843
2844 /* enable DP1.2 mode */
2845 vendor_param |= INTEL_EN_DP12;
Takashi Iwaia551d912015-02-26 12:34:49 +01002846 snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB);
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002847 snd_hda_codec_write_cache(codec, INTEL_VENDOR_NID, 0,
2848 INTEL_SET_VENDOR_VERB, vendor_param);
2849}
2850
Takashi Iwai17df3f52013-05-08 08:09:34 +02002851/* Haswell needs to re-issue the vendor-specific verbs before turning to D0.
2852 * Otherwise you may get severe h/w communication errors.
2853 */
2854static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2855 unsigned int power_state)
2856{
2857 if (power_state == AC_PWRST_D0) {
2858 intel_haswell_enable_all_pins(codec, false);
2859 intel_haswell_fixup_enable_dp12(codec);
2860 }
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002861
Takashi Iwai17df3f52013-05-08 08:09:34 +02002862 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
2863 snd_hda_codec_set_power_to_all(codec, fg, power_state);
2864}
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002865
David Henningssonf0675d42015-09-03 11:51:34 +02002866static void intel_pin_eld_notify(void *audio_ptr, int port)
David Henningsson25adc132015-08-19 10:48:58 +02002867{
2868 struct hda_codec *codec = audio_ptr;
2869 int pin_nid = port + 0x04;
2870
Takashi Iwai8ae743e2015-11-27 14:23:00 +01002871 /* skip notification during system suspend (but not in runtime PM);
2872 * the state will be updated at resume
2873 */
2874 if (snd_power_get_state(codec->card) != SNDRV_CTL_POWER_D0)
2875 return;
Takashi Iwaieb399d32015-11-27 14:53:35 +01002876 /* ditto during suspend/resume process itself */
2877 if (atomic_read(&(codec)->core.in_pm))
2878 return;
Takashi Iwai8ae743e2015-11-27 14:23:00 +01002879
David Henningsson25adc132015-08-19 10:48:58 +02002880 check_presence_and_report(codec, pin_nid);
2881}
2882
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002883static int patch_generic_hdmi(struct hda_codec *codec)
2884{
2885 struct hdmi_spec *spec;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002886
2887 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2888 if (spec == NULL)
2889 return -ENOMEM;
2890
Anssi Hannula307229d2013-10-24 21:10:34 +03002891 spec->ops = generic_standard_hdmi_ops;
Libin Yang42b29872015-12-16 13:42:42 +08002892 mutex_init(&spec->pcm_lock);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002893 codec->spec = spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002894 hdmi_array_init(spec, 4);
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002895
Takashi Iwai55913112015-12-10 13:03:29 +01002896 /* Try to bind with i915 for any Intel codecs (if not done yet) */
2897 if (!codec_has_acomp(codec) &&
2898 (codec->core.vendor_id >> 16) == 0x8086)
2899 if (!snd_hdac_i915_init(&codec->bus->core))
2900 spec->i915_bound = true;
2901
Mengdong Lin75dcbe42014-01-08 15:55:32 -05002902 if (is_haswell_plus(codec)) {
Takashi Iwai17df3f52013-05-08 08:09:34 +02002903 intel_haswell_enable_all_pins(codec, true);
Takashi Iwaic88d4e82013-02-08 17:10:04 -05002904 intel_haswell_fixup_enable_dp12(codec);
Takashi Iwai17df3f52013-05-08 08:09:34 +02002905 }
Mengdong Lin6ffe1682012-12-18 16:59:15 -05002906
Mengdong Lin2bd1f73f2015-04-29 17:43:43 +08002907 /* For Valleyview/Cherryview, only the display codec is in the display
2908 * power well and can use link_power ops to request/release the power.
2909 * For Haswell/Broadwell, the controller is also in the power well and
2910 * can cover the codec power request, and so need not set this flag.
2911 * For previous platforms, there is no such power well feature.
2912 */
Lu, Hanff9d8852015-11-19 23:25:13 +08002913 if (is_valleyview_plus(codec) || is_skylake(codec) ||
2914 is_broxton(codec))
Mengdong Lin2bd1f73f2015-04-29 17:43:43 +08002915 codec->core.link_power_control = 1;
2916
Takashi Iwai66032492015-12-01 16:49:35 +01002917 if (codec_has_acomp(codec)) {
Mengdong Lin5b8620b2013-12-05 18:35:48 -05002918 codec->depop_delay = 0;
David Henningsson25adc132015-08-19 10:48:58 +02002919 spec->i915_audio_ops.audio_ptr = codec;
2920 spec->i915_audio_ops.pin_eld_notify = intel_pin_eld_notify;
2921 snd_hdac_i915_register_notifier(&spec->i915_audio_ops);
2922 }
Mengdong Lin5b8620b2013-12-05 18:35:48 -05002923
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002924 if (hdmi_parse_codec(codec) < 0) {
Takashi Iwai55913112015-12-10 13:03:29 +01002925 if (spec->i915_bound)
2926 snd_hdac_i915_exit(&codec->bus->core);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002927 codec->spec = NULL;
2928 kfree(spec);
2929 return -EINVAL;
2930 }
2931 codec->patch_ops = generic_hdmi_patch_ops;
Mengdong Lin75dcbe42014-01-08 15:55:32 -05002932 if (is_haswell_plus(codec)) {
Takashi Iwai17df3f52013-05-08 08:09:34 +02002933 codec->patch_ops.set_power_state = haswell_set_power_state;
Mengdong Lin5dc989b2013-08-26 21:35:41 -04002934 codec->dp_mst = true;
2935 }
Takashi Iwai17df3f52013-05-08 08:09:34 +02002936
Lu, Han2377c3c2015-06-09 16:50:38 +08002937 /* Enable runtime pm for HDMI audio codec of HSW/BDW/SKL/BYT/BSW */
2938 if (is_haswell_plus(codec) || is_valleyview_plus(codec))
2939 codec->auto_runtime_pm = 1;
2940
Takashi Iwai8b8d6542012-06-20 16:32:22 +02002941 generic_hdmi_init_per_pins(codec);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002942
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002943 init_channel_allocations();
2944
Libin Yang25e4abb2016-01-12 11:13:27 +08002945 WARN_ON(spec->dyn_pcm_assign && !codec_has_acomp(codec));
Takashi Iwai84eb01b2010-09-07 12:27:25 +02002946 return 0;
2947}
2948
2949/*
Stephen Warren3aaf8982011-06-01 11:14:19 -06002950 * Shared non-generic implementations
2951 */
2952
2953static int simple_playback_build_pcms(struct hda_codec *codec)
2954{
2955 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002956 struct hda_pcm *info;
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002957 unsigned int chans;
2958 struct hda_pcm_stream *pstr;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002959 struct hdmi_spec_per_cvt *per_cvt;
Stephen Warren3aaf8982011-06-01 11:14:19 -06002960
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002961 per_cvt = get_cvt(spec, 0);
2962 chans = get_wcaps(codec, per_cvt->cvt_nid);
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002963 chans = get_wcaps_channels(chans);
Stephen Warren3aaf8982011-06-01 11:14:19 -06002964
Takashi Iwaibbbc7e82015-02-27 17:43:19 +01002965 info = snd_hda_codec_pcm_new(codec, "HDMI 0");
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002966 if (!info)
2967 return -ENOMEM;
Libin Yang2bea2412016-01-12 11:13:26 +08002968 spec->pcm_rec[0].pcm = info;
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002969 info->pcm_type = HDA_PCM_TYPE_HDMI;
2970 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
2971 *pstr = spec->pcm_playback;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002972 pstr->nid = per_cvt->cvt_nid;
Takashi Iwai8ceb3322012-06-21 08:23:27 +02002973 if (pstr->channels_max <= 2 && chans && chans <= 16)
2974 pstr->channels_max = chans;
Stephen Warren3aaf8982011-06-01 11:14:19 -06002975
2976 return 0;
2977}
2978
Takashi Iwai4b6ace92012-06-15 11:53:32 +02002979/* unsolicited event for jack sensing */
2980static void simple_hdmi_unsol_event(struct hda_codec *codec,
2981 unsigned int res)
2982{
Takashi Iwai9dd8cf12012-06-21 10:43:15 +02002983 snd_hda_jack_set_dirty_all(codec);
Takashi Iwai4b6ace92012-06-15 11:53:32 +02002984 snd_hda_jack_report_sync(codec);
2985}
2986
2987/* generic_hdmi_build_jack can be used for simple_hdmi, too,
2988 * as long as spec->pins[] is set correctly
2989 */
2990#define simple_hdmi_build_jack generic_hdmi_build_jack
2991
Stephen Warren3aaf8982011-06-01 11:14:19 -06002992static int simple_playback_build_controls(struct hda_codec *codec)
2993{
2994 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002995 struct hdmi_spec_per_cvt *per_cvt;
Stephen Warren3aaf8982011-06-01 11:14:19 -06002996 int err;
Stephen Warren3aaf8982011-06-01 11:14:19 -06002997
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01002998 per_cvt = get_cvt(spec, 0);
Anssi Hannulac9a63382013-12-10 22:46:34 +02002999 err = snd_hda_create_dig_out_ctls(codec, per_cvt->cvt_nid,
3000 per_cvt->cvt_nid,
3001 HDA_PCM_TYPE_HDMI);
Takashi Iwai8ceb3322012-06-21 08:23:27 +02003002 if (err < 0)
3003 return err;
3004 return simple_hdmi_build_jack(codec, 0);
Stephen Warren3aaf8982011-06-01 11:14:19 -06003005}
3006
Takashi Iwai4f0110c2012-06-15 12:45:43 +02003007static int simple_playback_init(struct hda_codec *codec)
3008{
3009 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01003010 struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0);
3011 hda_nid_t pin = per_pin->pin_nid;
Takashi Iwai4f0110c2012-06-15 12:45:43 +02003012
Takashi Iwai8ceb3322012-06-21 08:23:27 +02003013 snd_hda_codec_write(codec, pin, 0,
3014 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3015 /* some codecs require to unmute the pin */
3016 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
3017 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3018 AMP_OUT_UNMUTE);
Takashi Iwai62f949b2014-09-11 14:06:53 +02003019 snd_hda_jack_detect_enable(codec, pin);
Takashi Iwai4f0110c2012-06-15 12:45:43 +02003020 return 0;
3021}
3022
Stephen Warren3aaf8982011-06-01 11:14:19 -06003023static void simple_playback_free(struct hda_codec *codec)
3024{
3025 struct hdmi_spec *spec = codec->spec;
3026
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01003027 hdmi_array_free(spec);
Stephen Warren3aaf8982011-06-01 11:14:19 -06003028 kfree(spec);
3029}
3030
3031/*
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003032 * Nvidia specific implementations
3033 */
3034
3035#define Nv_VERB_SET_Channel_Allocation 0xF79
3036#define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
3037#define Nv_VERB_SET_Audio_Protection_On 0xF98
3038#define Nv_VERB_SET_Audio_Protection_Off 0xF99
3039
3040#define nvhdmi_master_con_nid_7x 0x04
3041#define nvhdmi_master_pin_nid_7x 0x05
3042
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02003043static const hda_nid_t nvhdmi_con_nids_7x[4] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003044 /*front, rear, clfe, rear_surr */
3045 0x6, 0x8, 0xa, 0xc,
3046};
3047
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02003048static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = {
3049 /* set audio protect on */
3050 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
3051 /* enable digital output on pin widget */
3052 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3053 {} /* terminator */
3054};
3055
3056static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003057 /* set audio protect on */
3058 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
3059 /* enable digital output on pin widget */
3060 { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3061 { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3062 { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3063 { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3064 { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
3065 {} /* terminator */
3066};
3067
3068#ifdef LIMITED_RATE_FMT_SUPPORT
3069/* support only the safe format and rate */
3070#define SUPPORTED_RATES SNDRV_PCM_RATE_48000
3071#define SUPPORTED_MAXBPS 16
3072#define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
3073#else
3074/* support all rates and formats */
3075#define SUPPORTED_RATES \
3076 (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
3077 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
3078 SNDRV_PCM_RATE_192000)
3079#define SUPPORTED_MAXBPS 24
3080#define SUPPORTED_FORMATS \
3081 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
3082#endif
3083
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02003084static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003085{
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02003086 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
3087 return 0;
3088}
3089
3090static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
3091{
3092 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003093 return 0;
3094}
3095
Nitin Daga393004b2011-01-10 21:49:31 +05303096static unsigned int channels_2_6_8[] = {
3097 2, 6, 8
3098};
3099
3100static unsigned int channels_2_8[] = {
3101 2, 8
3102};
3103
3104static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
3105 .count = ARRAY_SIZE(channels_2_6_8),
3106 .list = channels_2_6_8,
3107 .mask = 0,
3108};
3109
3110static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
3111 .count = ARRAY_SIZE(channels_2_8),
3112 .list = channels_2_8,
3113 .mask = 0,
3114};
3115
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003116static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
3117 struct hda_codec *codec,
3118 struct snd_pcm_substream *substream)
3119{
3120 struct hdmi_spec *spec = codec->spec;
Nitin Daga393004b2011-01-10 21:49:31 +05303121 struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
3122
Takashi Iwaib9a94a92015-10-01 16:20:04 +02003123 switch (codec->preset->vendor_id) {
Nitin Daga393004b2011-01-10 21:49:31 +05303124 case 0x10de0002:
3125 case 0x10de0003:
3126 case 0x10de0005:
3127 case 0x10de0006:
3128 hw_constraints_channels = &hw_constraints_2_8_channels;
3129 break;
3130 case 0x10de0007:
3131 hw_constraints_channels = &hw_constraints_2_6_8_channels;
3132 break;
3133 default:
3134 break;
3135 }
3136
3137 if (hw_constraints_channels != NULL) {
3138 snd_pcm_hw_constraint_list(substream->runtime, 0,
3139 SNDRV_PCM_HW_PARAM_CHANNELS,
3140 hw_constraints_channels);
Takashi Iwaiad09fc92011-01-14 09:42:27 +01003141 } else {
3142 snd_pcm_hw_constraint_step(substream->runtime, 0,
3143 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
Nitin Daga393004b2011-01-10 21:49:31 +05303144 }
3145
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003146 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3147}
3148
3149static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
3150 struct hda_codec *codec,
3151 struct snd_pcm_substream *substream)
3152{
3153 struct hdmi_spec *spec = codec->spec;
3154 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3155}
3156
3157static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3158 struct hda_codec *codec,
3159 unsigned int stream_tag,
3160 unsigned int format,
3161 struct snd_pcm_substream *substream)
3162{
3163 struct hdmi_spec *spec = codec->spec;
3164 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3165 stream_tag, format, substream);
3166}
3167
Takashi Iwaid0b12522012-06-15 14:34:42 +02003168static const struct hda_pcm_stream simple_pcm_playback = {
3169 .substreams = 1,
3170 .channels_min = 2,
3171 .channels_max = 2,
3172 .ops = {
3173 .open = simple_playback_pcm_open,
3174 .close = simple_playback_pcm_close,
3175 .prepare = simple_playback_pcm_prepare
3176 },
3177};
3178
3179static const struct hda_codec_ops simple_hdmi_patch_ops = {
3180 .build_controls = simple_playback_build_controls,
3181 .build_pcms = simple_playback_build_pcms,
3182 .init = simple_playback_init,
3183 .free = simple_playback_free,
Takashi Iwai250e41a2012-06-15 14:40:21 +02003184 .unsol_event = simple_hdmi_unsol_event,
Takashi Iwaid0b12522012-06-15 14:34:42 +02003185};
3186
3187static int patch_simple_hdmi(struct hda_codec *codec,
3188 hda_nid_t cvt_nid, hda_nid_t pin_nid)
3189{
3190 struct hdmi_spec *spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01003191 struct hdmi_spec_per_cvt *per_cvt;
3192 struct hdmi_spec_per_pin *per_pin;
Takashi Iwaid0b12522012-06-15 14:34:42 +02003193
3194 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3195 if (!spec)
3196 return -ENOMEM;
3197
3198 codec->spec = spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01003199 hdmi_array_init(spec, 1);
Takashi Iwaid0b12522012-06-15 14:34:42 +02003200
3201 spec->multiout.num_dacs = 0; /* no analog */
3202 spec->multiout.max_channels = 2;
3203 spec->multiout.dig_out_nid = cvt_nid;
3204 spec->num_cvts = 1;
3205 spec->num_pins = 1;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01003206 per_pin = snd_array_new(&spec->pins);
3207 per_cvt = snd_array_new(&spec->cvts);
3208 if (!per_pin || !per_cvt) {
3209 simple_playback_free(codec);
3210 return -ENOMEM;
3211 }
3212 per_cvt->cvt_nid = cvt_nid;
3213 per_pin->pin_nid = pin_nid;
Takashi Iwaid0b12522012-06-15 14:34:42 +02003214 spec->pcm_playback = simple_pcm_playback;
3215
3216 codec->patch_ops = simple_hdmi_patch_ops;
3217
3218 return 0;
3219}
3220
Aaron Plattner1f348522011-04-06 17:19:04 -07003221static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
3222 int channels)
3223{
3224 unsigned int chanmask;
3225 int chan = channels ? (channels - 1) : 1;
3226
3227 switch (channels) {
3228 default:
3229 case 0:
3230 case 2:
3231 chanmask = 0x00;
3232 break;
3233 case 4:
3234 chanmask = 0x08;
3235 break;
3236 case 6:
3237 chanmask = 0x0b;
3238 break;
3239 case 8:
3240 chanmask = 0x13;
3241 break;
3242 }
3243
3244 /* Set the audio infoframe channel allocation and checksum fields. The
3245 * channel count is computed implicitly by the hardware. */
3246 snd_hda_codec_write(codec, 0x1, 0,
3247 Nv_VERB_SET_Channel_Allocation, chanmask);
3248
3249 snd_hda_codec_write(codec, 0x1, 0,
3250 Nv_VERB_SET_Info_Frame_Checksum,
3251 (0x71 - chan - chanmask));
3252}
3253
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003254static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
3255 struct hda_codec *codec,
3256 struct snd_pcm_substream *substream)
3257{
3258 struct hdmi_spec *spec = codec->spec;
3259 int i;
3260
3261 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
3262 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
3263 for (i = 0; i < 4; i++) {
3264 /* set the stream id */
3265 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
3266 AC_VERB_SET_CHANNEL_STREAMID, 0);
3267 /* set the stream format */
3268 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
3269 AC_VERB_SET_STREAM_FORMAT, 0);
3270 }
3271
Aaron Plattner1f348522011-04-06 17:19:04 -07003272 /* The audio hardware sends a channel count of 0x7 (8ch) when all the
3273 * streams are disabled. */
3274 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
3275
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003276 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3277}
3278
3279static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
3280 struct hda_codec *codec,
3281 unsigned int stream_tag,
3282 unsigned int format,
3283 struct snd_pcm_substream *substream)
3284{
3285 int chs;
Takashi Iwai112daa72011-11-02 21:40:06 +01003286 unsigned int dataDCC2, channel_id;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003287 int i;
Stephen Warren7c935972011-06-01 11:14:17 -06003288 struct hdmi_spec *spec = codec->spec;
Takashi Iwaie3245cd2012-05-10 10:21:29 +02003289 struct hda_spdif_out *spdif;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01003290 struct hdmi_spec_per_cvt *per_cvt;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003291
3292 mutex_lock(&codec->spdif_mutex);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01003293 per_cvt = get_cvt(spec, 0);
3294 spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003295
3296 chs = substream->runtime->channels;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003297
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003298 dataDCC2 = 0x2;
3299
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003300 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
Stephen Warren7c935972011-06-01 11:14:17 -06003301 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003302 snd_hda_codec_write(codec,
3303 nvhdmi_master_con_nid_7x,
3304 0,
3305 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06003306 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003307
3308 /* set the stream id */
3309 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
3310 AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
3311
3312 /* set the stream format */
3313 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
3314 AC_VERB_SET_STREAM_FORMAT, format);
3315
3316 /* turn on again (if needed) */
3317 /* enable and set the channel status audio/data flag */
Stephen Warren7c935972011-06-01 11:14:17 -06003318 if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003319 snd_hda_codec_write(codec,
3320 nvhdmi_master_con_nid_7x,
3321 0,
3322 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06003323 spdif->ctls & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003324 snd_hda_codec_write(codec,
3325 nvhdmi_master_con_nid_7x,
3326 0,
3327 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
3328 }
3329
3330 for (i = 0; i < 4; i++) {
3331 if (chs == 2)
3332 channel_id = 0;
3333 else
3334 channel_id = i * 2;
3335
3336 /* turn off SPDIF once;
3337 *otherwise the IEC958 bits won't be updated
3338 */
3339 if (codec->spdif_status_reset &&
Stephen Warren7c935972011-06-01 11:14:17 -06003340 (spdif->ctls & AC_DIG1_ENABLE))
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003341 snd_hda_codec_write(codec,
3342 nvhdmi_con_nids_7x[i],
3343 0,
3344 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06003345 spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003346 /* set the stream id */
3347 snd_hda_codec_write(codec,
3348 nvhdmi_con_nids_7x[i],
3349 0,
3350 AC_VERB_SET_CHANNEL_STREAMID,
3351 (stream_tag << 4) | channel_id);
3352 /* set the stream format */
3353 snd_hda_codec_write(codec,
3354 nvhdmi_con_nids_7x[i],
3355 0,
3356 AC_VERB_SET_STREAM_FORMAT,
3357 format);
3358 /* turn on again (if needed) */
3359 /* enable and set the channel status audio/data flag */
3360 if (codec->spdif_status_reset &&
Stephen Warren7c935972011-06-01 11:14:17 -06003361 (spdif->ctls & AC_DIG1_ENABLE)) {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003362 snd_hda_codec_write(codec,
3363 nvhdmi_con_nids_7x[i],
3364 0,
3365 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06003366 spdif->ctls & 0xff);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003367 snd_hda_codec_write(codec,
3368 nvhdmi_con_nids_7x[i],
3369 0,
3370 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
3371 }
3372 }
3373
Aaron Plattner1f348522011-04-06 17:19:04 -07003374 nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003375
3376 mutex_unlock(&codec->spdif_mutex);
3377 return 0;
3378}
3379
Takashi Iwaifb79e1e2011-05-02 12:17:41 +02003380static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003381 .substreams = 1,
3382 .channels_min = 2,
3383 .channels_max = 8,
3384 .nid = nvhdmi_master_con_nid_7x,
3385 .rates = SUPPORTED_RATES,
3386 .maxbps = SUPPORTED_MAXBPS,
3387 .formats = SUPPORTED_FORMATS,
3388 .ops = {
3389 .open = simple_playback_pcm_open,
3390 .close = nvhdmi_8ch_7x_pcm_close,
3391 .prepare = nvhdmi_8ch_7x_pcm_prepare
3392 },
3393};
3394
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003395static int patch_nvhdmi_2ch(struct hda_codec *codec)
3396{
3397 struct hdmi_spec *spec;
Takashi Iwaid0b12522012-06-15 14:34:42 +02003398 int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
3399 nvhdmi_master_pin_nid_7x);
3400 if (err < 0)
3401 return err;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003402
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02003403 codec->patch_ops.init = nvhdmi_7x_init_2ch;
Takashi Iwaid0b12522012-06-15 14:34:42 +02003404 /* override the PCM rates, etc, as the codec doesn't give full list */
3405 spec = codec->spec;
3406 spec->pcm_playback.rates = SUPPORTED_RATES;
3407 spec->pcm_playback.maxbps = SUPPORTED_MAXBPS;
3408 spec->pcm_playback.formats = SUPPORTED_FORMATS;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003409 return 0;
3410}
3411
Takashi Iwai53775b02012-08-01 12:17:41 +02003412static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
3413{
3414 struct hdmi_spec *spec = codec->spec;
3415 int err = simple_playback_build_pcms(codec);
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01003416 if (!err) {
3417 struct hda_pcm *info = get_pcm_rec(spec, 0);
3418 info->own_chmap = true;
3419 }
Takashi Iwai53775b02012-08-01 12:17:41 +02003420 return err;
3421}
3422
3423static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
3424{
3425 struct hdmi_spec *spec = codec->spec;
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01003426 struct hda_pcm *info;
Takashi Iwai53775b02012-08-01 12:17:41 +02003427 struct snd_pcm_chmap *chmap;
3428 int err;
3429
3430 err = simple_playback_build_controls(codec);
3431 if (err < 0)
3432 return err;
3433
3434 /* add channel maps */
Takashi Iwaibce0d2a2013-03-13 14:40:31 +01003435 info = get_pcm_rec(spec, 0);
3436 err = snd_pcm_add_chmap_ctls(info->pcm,
Takashi Iwai53775b02012-08-01 12:17:41 +02003437 SNDRV_PCM_STREAM_PLAYBACK,
3438 snd_pcm_alt_chmaps, 8, 0, &chmap);
3439 if (err < 0)
3440 return err;
Takashi Iwaib9a94a92015-10-01 16:20:04 +02003441 switch (codec->preset->vendor_id) {
Takashi Iwai53775b02012-08-01 12:17:41 +02003442 case 0x10de0002:
3443 case 0x10de0003:
3444 case 0x10de0005:
3445 case 0x10de0006:
3446 chmap->channel_mask = (1U << 2) | (1U << 8);
3447 break;
3448 case 0x10de0007:
3449 chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8);
3450 }
3451 return 0;
3452}
3453
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003454static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
3455{
3456 struct hdmi_spec *spec;
3457 int err = patch_nvhdmi_2ch(codec);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003458 if (err < 0)
3459 return err;
3460 spec = codec->spec;
3461 spec->multiout.max_channels = 8;
Takashi Iwaid0b12522012-06-15 14:34:42 +02003462 spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x;
Takashi Iwaiceaa86b2012-06-15 14:38:31 +02003463 codec->patch_ops.init = nvhdmi_7x_init_8ch;
Takashi Iwai53775b02012-08-01 12:17:41 +02003464 codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
3465 codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
Aaron Plattner1f348522011-04-06 17:19:04 -07003466
3467 /* Initialize the audio infoframe channel mask and checksum to something
3468 * valid */
3469 nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
3470
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003471 return 0;
3472}
3473
3474/*
Anssi Hannula611885b2013-11-03 17:15:00 +02003475 * NVIDIA codecs ignore ASP mapping for 2ch - confirmed on:
3476 * - 0x10de0015
3477 * - 0x10de0040
3478 */
3479static int nvhdmi_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap,
3480 int channels)
3481{
3482 if (cap->ca_index == 0x00 && channels == 2)
3483 return SNDRV_CTL_TLVT_CHMAP_FIXED;
3484
3485 return hdmi_chmap_cea_alloc_validate_get_type(cap, channels);
3486}
3487
3488static int nvhdmi_chmap_validate(int ca, int chs, unsigned char *map)
3489{
3490 if (ca == 0x00 && (map[0] != SNDRV_CHMAP_FL || map[1] != SNDRV_CHMAP_FR))
3491 return -EINVAL;
3492
3493 return 0;
3494}
3495
3496static int patch_nvhdmi(struct hda_codec *codec)
3497{
3498 struct hdmi_spec *spec;
3499 int err;
3500
3501 err = patch_generic_hdmi(codec);
3502 if (err)
3503 return err;
3504
3505 spec = codec->spec;
Stephen Warren75fae112014-01-30 11:52:16 -07003506 spec->dyn_pin_out = true;
Anssi Hannula611885b2013-11-03 17:15:00 +02003507
3508 spec->ops.chmap_cea_alloc_validate_get_type =
3509 nvhdmi_chmap_cea_alloc_validate_get_type;
3510 spec->ops.chmap_validate = nvhdmi_chmap_validate;
3511
3512 return 0;
3513}
3514
3515/*
Thierry Reding26e9a962015-05-05 14:56:20 +02003516 * The HDA codec on NVIDIA Tegra contains two scratch registers that are
3517 * accessed using vendor-defined verbs. These registers can be used for
3518 * interoperability between the HDA and HDMI drivers.
3519 */
3520
3521/* Audio Function Group node */
3522#define NVIDIA_AFG_NID 0x01
3523
3524/*
3525 * The SCRATCH0 register is used to notify the HDMI codec of changes in audio
3526 * format. On Tegra, bit 31 is used as a trigger that causes an interrupt to
3527 * be raised in the HDMI codec. The remainder of the bits is arbitrary. This
3528 * implementation stores the HDA format (see AC_FMT_*) in bits [15:0] and an
3529 * additional bit (at position 30) to signal the validity of the format.
3530 *
3531 * | 31 | 30 | 29 16 | 15 0 |
3532 * +---------+-------+--------+--------+
3533 * | TRIGGER | VALID | UNUSED | FORMAT |
3534 * +-----------------------------------|
3535 *
3536 * Note that for the trigger bit to take effect it needs to change value
3537 * (i.e. it needs to be toggled).
3538 */
3539#define NVIDIA_GET_SCRATCH0 0xfa6
3540#define NVIDIA_SET_SCRATCH0_BYTE0 0xfa7
3541#define NVIDIA_SET_SCRATCH0_BYTE1 0xfa8
3542#define NVIDIA_SET_SCRATCH0_BYTE2 0xfa9
3543#define NVIDIA_SET_SCRATCH0_BYTE3 0xfaa
3544#define NVIDIA_SCRATCH_TRIGGER (1 << 7)
3545#define NVIDIA_SCRATCH_VALID (1 << 6)
3546
3547#define NVIDIA_GET_SCRATCH1 0xfab
3548#define NVIDIA_SET_SCRATCH1_BYTE0 0xfac
3549#define NVIDIA_SET_SCRATCH1_BYTE1 0xfad
3550#define NVIDIA_SET_SCRATCH1_BYTE2 0xfae
3551#define NVIDIA_SET_SCRATCH1_BYTE3 0xfaf
3552
3553/*
3554 * The format parameter is the HDA audio format (see AC_FMT_*). If set to 0,
3555 * the format is invalidated so that the HDMI codec can be disabled.
3556 */
3557static void tegra_hdmi_set_format(struct hda_codec *codec, unsigned int format)
3558{
3559 unsigned int value;
3560
3561 /* bits [31:30] contain the trigger and valid bits */
3562 value = snd_hda_codec_read(codec, NVIDIA_AFG_NID, 0,
3563 NVIDIA_GET_SCRATCH0, 0);
3564 value = (value >> 24) & 0xff;
3565
3566 /* bits [15:0] are used to store the HDA format */
3567 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3568 NVIDIA_SET_SCRATCH0_BYTE0,
3569 (format >> 0) & 0xff);
3570 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3571 NVIDIA_SET_SCRATCH0_BYTE1,
3572 (format >> 8) & 0xff);
3573
3574 /* bits [16:24] are unused */
3575 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3576 NVIDIA_SET_SCRATCH0_BYTE2, 0);
3577
3578 /*
3579 * Bit 30 signals that the data is valid and hence that HDMI audio can
3580 * be enabled.
3581 */
3582 if (format == 0)
3583 value &= ~NVIDIA_SCRATCH_VALID;
3584 else
3585 value |= NVIDIA_SCRATCH_VALID;
3586
3587 /*
3588 * Whenever the trigger bit is toggled, an interrupt is raised in the
3589 * HDMI codec. The HDMI driver will use that as trigger to update its
3590 * configuration.
3591 */
3592 value ^= NVIDIA_SCRATCH_TRIGGER;
3593
3594 snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
3595 NVIDIA_SET_SCRATCH0_BYTE3, value);
3596}
3597
3598static int tegra_hdmi_pcm_prepare(struct hda_pcm_stream *hinfo,
3599 struct hda_codec *codec,
3600 unsigned int stream_tag,
3601 unsigned int format,
3602 struct snd_pcm_substream *substream)
3603{
3604 int err;
3605
3606 err = generic_hdmi_playback_pcm_prepare(hinfo, codec, stream_tag,
3607 format, substream);
3608 if (err < 0)
3609 return err;
3610
3611 /* notify the HDMI codec of the format change */
3612 tegra_hdmi_set_format(codec, format);
3613
3614 return 0;
3615}
3616
3617static int tegra_hdmi_pcm_cleanup(struct hda_pcm_stream *hinfo,
3618 struct hda_codec *codec,
3619 struct snd_pcm_substream *substream)
3620{
3621 /* invalidate the format in the HDMI codec */
3622 tegra_hdmi_set_format(codec, 0);
3623
3624 return generic_hdmi_playback_pcm_cleanup(hinfo, codec, substream);
3625}
3626
3627static struct hda_pcm *hda_find_pcm_by_type(struct hda_codec *codec, int type)
3628{
3629 struct hdmi_spec *spec = codec->spec;
3630 unsigned int i;
3631
3632 for (i = 0; i < spec->num_pins; i++) {
3633 struct hda_pcm *pcm = get_pcm_rec(spec, i);
3634
3635 if (pcm->pcm_type == type)
3636 return pcm;
3637 }
3638
3639 return NULL;
3640}
3641
3642static int tegra_hdmi_build_pcms(struct hda_codec *codec)
3643{
3644 struct hda_pcm_stream *stream;
3645 struct hda_pcm *pcm;
3646 int err;
3647
3648 err = generic_hdmi_build_pcms(codec);
3649 if (err < 0)
3650 return err;
3651
3652 pcm = hda_find_pcm_by_type(codec, HDA_PCM_TYPE_HDMI);
3653 if (!pcm)
3654 return -ENODEV;
3655
3656 /*
3657 * Override ->prepare() and ->cleanup() operations to notify the HDMI
3658 * codec about format changes.
3659 */
3660 stream = &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
3661 stream->ops.prepare = tegra_hdmi_pcm_prepare;
3662 stream->ops.cleanup = tegra_hdmi_pcm_cleanup;
3663
3664 return 0;
3665}
3666
3667static int patch_tegra_hdmi(struct hda_codec *codec)
3668{
3669 int err;
3670
3671 err = patch_generic_hdmi(codec);
3672 if (err)
3673 return err;
3674
3675 codec->patch_ops.build_pcms = tegra_hdmi_build_pcms;
3676
3677 return 0;
3678}
3679
3680/*
Anssi Hannula5a6135842013-10-24 21:10:35 +03003681 * ATI/AMD-specific implementations
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003682 */
3683
Anssi Hannula5a6135842013-10-24 21:10:35 +03003684#define is_amdhdmi_rev3_or_later(codec) \
Takashi Iwai7639a062015-03-03 10:07:24 +01003685 ((codec)->core.vendor_id == 0x1002aa01 && \
3686 ((codec)->core.revision_id & 0xff00) >= 0x0300)
Anssi Hannula5a6135842013-10-24 21:10:35 +03003687#define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec)
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003688
Anssi Hannula5a6135842013-10-24 21:10:35 +03003689/* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */
3690#define ATI_VERB_SET_CHANNEL_ALLOCATION 0x771
3691#define ATI_VERB_SET_DOWNMIX_INFO 0x772
3692#define ATI_VERB_SET_MULTICHANNEL_01 0x777
3693#define ATI_VERB_SET_MULTICHANNEL_23 0x778
3694#define ATI_VERB_SET_MULTICHANNEL_45 0x779
3695#define ATI_VERB_SET_MULTICHANNEL_67 0x77a
Anssi Hannula461cf6b2013-10-24 21:10:37 +03003696#define ATI_VERB_SET_HBR_CONTROL 0x77c
Anssi Hannula5a6135842013-10-24 21:10:35 +03003697#define ATI_VERB_SET_MULTICHANNEL_1 0x785
3698#define ATI_VERB_SET_MULTICHANNEL_3 0x786
3699#define ATI_VERB_SET_MULTICHANNEL_5 0x787
3700#define ATI_VERB_SET_MULTICHANNEL_7 0x788
3701#define ATI_VERB_SET_MULTICHANNEL_MODE 0x789
3702#define ATI_VERB_GET_CHANNEL_ALLOCATION 0xf71
3703#define ATI_VERB_GET_DOWNMIX_INFO 0xf72
3704#define ATI_VERB_GET_MULTICHANNEL_01 0xf77
3705#define ATI_VERB_GET_MULTICHANNEL_23 0xf78
3706#define ATI_VERB_GET_MULTICHANNEL_45 0xf79
3707#define ATI_VERB_GET_MULTICHANNEL_67 0xf7a
Anssi Hannula461cf6b2013-10-24 21:10:37 +03003708#define ATI_VERB_GET_HBR_CONTROL 0xf7c
Anssi Hannula5a6135842013-10-24 21:10:35 +03003709#define ATI_VERB_GET_MULTICHANNEL_1 0xf85
3710#define ATI_VERB_GET_MULTICHANNEL_3 0xf86
3711#define ATI_VERB_GET_MULTICHANNEL_5 0xf87
3712#define ATI_VERB_GET_MULTICHANNEL_7 0xf88
3713#define ATI_VERB_GET_MULTICHANNEL_MODE 0xf89
3714
Anssi Hannula84d69e72013-10-24 21:10:38 +03003715/* AMD specific HDA cvt verbs */
3716#define ATI_VERB_SET_RAMP_RATE 0x770
3717#define ATI_VERB_GET_RAMP_RATE 0xf70
3718
Anssi Hannula5a6135842013-10-24 21:10:35 +03003719#define ATI_OUT_ENABLE 0x1
3720
3721#define ATI_MULTICHANNEL_MODE_PAIRED 0
3722#define ATI_MULTICHANNEL_MODE_SINGLE 1
3723
Anssi Hannula461cf6b2013-10-24 21:10:37 +03003724#define ATI_HBR_CAPABLE 0x01
3725#define ATI_HBR_ENABLE 0x10
3726
Anssi Hannula89250f82013-10-24 21:10:36 +03003727static int atihdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
3728 unsigned char *buf, int *eld_size)
3729{
3730 /* call hda_eld.c ATI/AMD-specific function */
3731 return snd_hdmi_get_eld_ati(codec, nid, buf, eld_size,
3732 is_amdhdmi_rev3_or_later(codec));
3733}
3734
Anssi Hannula5a6135842013-10-24 21:10:35 +03003735static void atihdmi_pin_setup_infoframe(struct hda_codec *codec, hda_nid_t pin_nid, int ca,
3736 int active_channels, int conn_type)
3737{
3738 snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_CHANNEL_ALLOCATION, ca);
3739}
3740
3741static int atihdmi_paired_swap_fc_lfe(int pos)
3742{
3743 /*
3744 * ATI/AMD have automatic FC/LFE swap built-in
3745 * when in pairwise mapping mode.
3746 */
3747
3748 switch (pos) {
3749 /* see channel_allocations[].speakers[] */
3750 case 2: return 3;
3751 case 3: return 2;
3752 default: break;
3753 }
3754
3755 return pos;
3756}
3757
3758static int atihdmi_paired_chmap_validate(int ca, int chs, unsigned char *map)
3759{
3760 struct cea_channel_speaker_allocation *cap;
3761 int i, j;
3762
3763 /* check that only channel pairs need to be remapped on old pre-rev3 ATI/AMD */
3764
3765 cap = &channel_allocations[get_channel_allocation_order(ca)];
3766 for (i = 0; i < chs; ++i) {
3767 int mask = to_spk_mask(map[i]);
3768 bool ok = false;
3769 bool companion_ok = false;
3770
3771 if (!mask)
3772 continue;
3773
3774 for (j = 0 + i % 2; j < 8; j += 2) {
3775 int chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j);
3776 if (cap->speakers[chan_idx] == mask) {
3777 /* channel is in a supported position */
3778 ok = true;
3779
3780 if (i % 2 == 0 && i + 1 < chs) {
3781 /* even channel, check the odd companion */
3782 int comp_chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j + 1);
3783 int comp_mask_req = to_spk_mask(map[i+1]);
3784 int comp_mask_act = cap->speakers[comp_chan_idx];
3785
3786 if (comp_mask_req == comp_mask_act)
3787 companion_ok = true;
3788 else
3789 return -EINVAL;
3790 }
3791 break;
3792 }
3793 }
3794
3795 if (!ok)
3796 return -EINVAL;
3797
3798 if (companion_ok)
3799 i++; /* companion channel already checked */
3800 }
3801
3802 return 0;
3803}
3804
3805static int atihdmi_pin_set_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
3806 int hdmi_slot, int stream_channel)
3807{
3808 int verb;
3809 int ati_channel_setup = 0;
3810
3811 if (hdmi_slot > 7)
3812 return -EINVAL;
3813
3814 if (!has_amd_full_remap_support(codec)) {
3815 hdmi_slot = atihdmi_paired_swap_fc_lfe(hdmi_slot);
3816
3817 /* In case this is an odd slot but without stream channel, do not
3818 * disable the slot since the corresponding even slot could have a
3819 * channel. In case neither have a channel, the slot pair will be
3820 * disabled when this function is called for the even slot. */
3821 if (hdmi_slot % 2 != 0 && stream_channel == 0xf)
3822 return 0;
3823
3824 hdmi_slot -= hdmi_slot % 2;
3825
3826 if (stream_channel != 0xf)
3827 stream_channel -= stream_channel % 2;
3828 }
3829
3830 verb = ATI_VERB_SET_MULTICHANNEL_01 + hdmi_slot/2 + (hdmi_slot % 2) * 0x00e;
3831
3832 /* ati_channel_setup format: [7..4] = stream_channel_id, [1] = mute, [0] = enable */
3833
3834 if (stream_channel != 0xf)
3835 ati_channel_setup = (stream_channel << 4) | ATI_OUT_ENABLE;
3836
3837 return snd_hda_codec_write(codec, pin_nid, 0, verb, ati_channel_setup);
3838}
3839
3840static int atihdmi_pin_get_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
3841 int asp_slot)
3842{
3843 bool was_odd = false;
3844 int ati_asp_slot = asp_slot;
3845 int verb;
3846 int ati_channel_setup;
3847
3848 if (asp_slot > 7)
3849 return -EINVAL;
3850
3851 if (!has_amd_full_remap_support(codec)) {
3852 ati_asp_slot = atihdmi_paired_swap_fc_lfe(asp_slot);
3853 if (ati_asp_slot % 2 != 0) {
3854 ati_asp_slot -= 1;
3855 was_odd = true;
3856 }
3857 }
3858
3859 verb = ATI_VERB_GET_MULTICHANNEL_01 + ati_asp_slot/2 + (ati_asp_slot % 2) * 0x00e;
3860
3861 ati_channel_setup = snd_hda_codec_read(codec, pin_nid, 0, verb, 0);
3862
3863 if (!(ati_channel_setup & ATI_OUT_ENABLE))
3864 return 0xf;
3865
3866 return ((ati_channel_setup & 0xf0) >> 4) + !!was_odd;
3867}
3868
3869static int atihdmi_paired_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap,
3870 int channels)
3871{
3872 int c;
3873
3874 /*
3875 * Pre-rev3 ATI/AMD codecs operate in a paired channel mode, so
3876 * we need to take that into account (a single channel may take 2
3877 * channel slots if we need to carry a silent channel next to it).
3878 * On Rev3+ AMD codecs this function is not used.
3879 */
3880 int chanpairs = 0;
3881
3882 /* We only produce even-numbered channel count TLVs */
3883 if ((channels % 2) != 0)
3884 return -1;
3885
3886 for (c = 0; c < 7; c += 2) {
3887 if (cap->speakers[c] || cap->speakers[c+1])
3888 chanpairs++;
3889 }
3890
3891 if (chanpairs * 2 != channels)
3892 return -1;
3893
3894 return SNDRV_CTL_TLVT_CHMAP_PAIRED;
3895}
3896
3897static void atihdmi_paired_cea_alloc_to_tlv_chmap(struct cea_channel_speaker_allocation *cap,
3898 unsigned int *chmap, int channels)
3899{
3900 /* produce paired maps for pre-rev3 ATI/AMD codecs */
3901 int count = 0;
3902 int c;
3903
3904 for (c = 7; c >= 0; c--) {
3905 int chan = 7 - atihdmi_paired_swap_fc_lfe(7 - c);
3906 int spk = cap->speakers[chan];
3907 if (!spk) {
3908 /* add N/A channel if the companion channel is occupied */
3909 if (cap->speakers[chan + (chan % 2 ? -1 : 1)])
3910 chmap[count++] = SNDRV_CHMAP_NA;
3911
3912 continue;
3913 }
3914
3915 chmap[count++] = spk_to_chmap(spk);
3916 }
3917
3918 WARN_ON(count != channels);
3919}
3920
Anssi Hannula461cf6b2013-10-24 21:10:37 +03003921static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
3922 bool hbr)
3923{
3924 int hbr_ctl, hbr_ctl_new;
3925
3926 hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0);
Anssi Hannula13122e62013-11-10 20:56:10 +02003927 if (hbr_ctl >= 0 && (hbr_ctl & ATI_HBR_CAPABLE)) {
Anssi Hannula461cf6b2013-10-24 21:10:37 +03003928 if (hbr)
3929 hbr_ctl_new = hbr_ctl | ATI_HBR_ENABLE;
3930 else
3931 hbr_ctl_new = hbr_ctl & ~ATI_HBR_ENABLE;
3932
Takashi Iwai4e76a882014-02-25 12:21:03 +01003933 codec_dbg(codec,
3934 "atihdmi_pin_hbr_setup: NID=0x%x, %shbr-ctl=0x%x\n",
Anssi Hannula461cf6b2013-10-24 21:10:37 +03003935 pin_nid,
3936 hbr_ctl == hbr_ctl_new ? "" : "new-",
3937 hbr_ctl_new);
3938
3939 if (hbr_ctl != hbr_ctl_new)
3940 snd_hda_codec_write(codec, pin_nid, 0,
3941 ATI_VERB_SET_HBR_CONTROL,
3942 hbr_ctl_new);
3943
3944 } else if (hbr)
3945 return -EINVAL;
3946
3947 return 0;
3948}
3949
Anssi Hannula84d69e72013-10-24 21:10:38 +03003950static int atihdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
3951 hda_nid_t pin_nid, u32 stream_tag, int format)
3952{
3953
3954 if (is_amdhdmi_rev3_or_later(codec)) {
3955 int ramp_rate = 180; /* default as per AMD spec */
3956 /* disable ramp-up/down for non-pcm as per AMD spec */
3957 if (format & AC_FMT_TYPE_NON_PCM)
3958 ramp_rate = 0;
3959
3960 snd_hda_codec_write(codec, cvt_nid, 0, ATI_VERB_SET_RAMP_RATE, ramp_rate);
3961 }
3962
3963 return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
3964}
3965
3966
Anssi Hannula5a6135842013-10-24 21:10:35 +03003967static int atihdmi_init(struct hda_codec *codec)
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003968{
3969 struct hdmi_spec *spec = codec->spec;
Anssi Hannula5a6135842013-10-24 21:10:35 +03003970 int pin_idx, err;
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003971
Anssi Hannula5a6135842013-10-24 21:10:35 +03003972 err = generic_hdmi_init(codec);
3973
3974 if (err)
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003975 return err;
Anssi Hannula5a6135842013-10-24 21:10:35 +03003976
3977 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
3978 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
3979
3980 /* make sure downmix information in infoframe is zero */
3981 snd_hda_codec_write(codec, per_pin->pin_nid, 0, ATI_VERB_SET_DOWNMIX_INFO, 0);
3982
3983 /* enable channel-wise remap mode if supported */
3984 if (has_amd_full_remap_support(codec))
3985 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
3986 ATI_VERB_SET_MULTICHANNEL_MODE,
3987 ATI_MULTICHANNEL_MODE_SINGLE);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003988 }
Anssi Hannula5a6135842013-10-24 21:10:35 +03003989
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003990 return 0;
3991}
3992
Takashi Iwai84eb01b2010-09-07 12:27:25 +02003993static int patch_atihdmi(struct hda_codec *codec)
3994{
3995 struct hdmi_spec *spec;
Anssi Hannula5a6135842013-10-24 21:10:35 +03003996 struct hdmi_spec_per_cvt *per_cvt;
3997 int err, cvt_idx;
3998
3999 err = patch_generic_hdmi(codec);
4000
4001 if (err)
Takashi Iwaid0b12522012-06-15 14:34:42 +02004002 return err;
Anssi Hannula5a6135842013-10-24 21:10:35 +03004003
4004 codec->patch_ops.init = atihdmi_init;
4005
Takashi Iwaid0b12522012-06-15 14:34:42 +02004006 spec = codec->spec;
Anssi Hannula5a6135842013-10-24 21:10:35 +03004007
Anssi Hannula89250f82013-10-24 21:10:36 +03004008 spec->ops.pin_get_eld = atihdmi_pin_get_eld;
Anssi Hannula5a6135842013-10-24 21:10:35 +03004009 spec->ops.pin_get_slot_channel = atihdmi_pin_get_slot_channel;
4010 spec->ops.pin_set_slot_channel = atihdmi_pin_set_slot_channel;
4011 spec->ops.pin_setup_infoframe = atihdmi_pin_setup_infoframe;
Anssi Hannula461cf6b2013-10-24 21:10:37 +03004012 spec->ops.pin_hbr_setup = atihdmi_pin_hbr_setup;
Anssi Hannula84d69e72013-10-24 21:10:38 +03004013 spec->ops.setup_stream = atihdmi_setup_stream;
Anssi Hannula5a6135842013-10-24 21:10:35 +03004014
4015 if (!has_amd_full_remap_support(codec)) {
4016 /* override to ATI/AMD-specific versions with pairwise mapping */
4017 spec->ops.chmap_cea_alloc_validate_get_type =
4018 atihdmi_paired_chmap_cea_alloc_validate_get_type;
4019 spec->ops.cea_alloc_to_tlv_chmap = atihdmi_paired_cea_alloc_to_tlv_chmap;
4020 spec->ops.chmap_validate = atihdmi_paired_chmap_validate;
4021 }
4022
4023 /* ATI/AMD converters do not advertise all of their capabilities */
4024 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
4025 per_cvt = get_cvt(spec, cvt_idx);
4026 per_cvt->channels_max = max(per_cvt->channels_max, 8u);
4027 per_cvt->rates |= SUPPORTED_RATES;
4028 per_cvt->formats |= SUPPORTED_FORMATS;
4029 per_cvt->maxbps = max(per_cvt->maxbps, 24u);
4030 }
4031
4032 spec->channels_max = max(spec->channels_max, 8u);
4033
Takashi Iwai84eb01b2010-09-07 12:27:25 +02004034 return 0;
4035}
4036
Annie Liu3de5ff82012-06-08 19:18:42 +08004037/* VIA HDMI Implementation */
4038#define VIAHDMI_CVT_NID 0x02 /* audio converter1 */
4039#define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */
4040
Annie Liu3de5ff82012-06-08 19:18:42 +08004041static int patch_via_hdmi(struct hda_codec *codec)
4042{
Takashi Iwai250e41a2012-06-15 14:40:21 +02004043 return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
Annie Liu3de5ff82012-06-08 19:18:42 +08004044}
Takashi Iwai84eb01b2010-09-07 12:27:25 +02004045
4046/*
4047 * patch entries
4048 */
Takashi Iwaib9a94a92015-10-01 16:20:04 +02004049static const struct hda_device_id snd_hda_id_hdmi[] = {
4050HDA_CODEC_ENTRY(0x1002793c, "RS600 HDMI", patch_atihdmi),
4051HDA_CODEC_ENTRY(0x10027919, "RS600 HDMI", patch_atihdmi),
4052HDA_CODEC_ENTRY(0x1002791a, "RS690/780 HDMI", patch_atihdmi),
4053HDA_CODEC_ENTRY(0x1002aa01, "R6xx HDMI", patch_atihdmi),
4054HDA_CODEC_ENTRY(0x10951390, "SiI1390 HDMI", patch_generic_hdmi),
4055HDA_CODEC_ENTRY(0x10951392, "SiI1392 HDMI", patch_generic_hdmi),
4056HDA_CODEC_ENTRY(0x17e80047, "Chrontel HDMI", patch_generic_hdmi),
4057HDA_CODEC_ENTRY(0x10de0002, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4058HDA_CODEC_ENTRY(0x10de0003, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4059HDA_CODEC_ENTRY(0x10de0005, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4060HDA_CODEC_ENTRY(0x10de0006, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
4061HDA_CODEC_ENTRY(0x10de0007, "MCP79/7A HDMI", patch_nvhdmi_8ch_7x),
4062HDA_CODEC_ENTRY(0x10de000a, "GPU 0a HDMI/DP", patch_nvhdmi),
4063HDA_CODEC_ENTRY(0x10de000b, "GPU 0b HDMI/DP", patch_nvhdmi),
4064HDA_CODEC_ENTRY(0x10de000c, "MCP89 HDMI", patch_nvhdmi),
4065HDA_CODEC_ENTRY(0x10de000d, "GPU 0d HDMI/DP", patch_nvhdmi),
4066HDA_CODEC_ENTRY(0x10de0010, "GPU 10 HDMI/DP", patch_nvhdmi),
4067HDA_CODEC_ENTRY(0x10de0011, "GPU 11 HDMI/DP", patch_nvhdmi),
4068HDA_CODEC_ENTRY(0x10de0012, "GPU 12 HDMI/DP", patch_nvhdmi),
4069HDA_CODEC_ENTRY(0x10de0013, "GPU 13 HDMI/DP", patch_nvhdmi),
4070HDA_CODEC_ENTRY(0x10de0014, "GPU 14 HDMI/DP", patch_nvhdmi),
4071HDA_CODEC_ENTRY(0x10de0015, "GPU 15 HDMI/DP", patch_nvhdmi),
4072HDA_CODEC_ENTRY(0x10de0016, "GPU 16 HDMI/DP", patch_nvhdmi),
Richard Samsonc8900a02011-03-03 12:46:13 +01004073/* 17 is known to be absent */
Takashi Iwaib9a94a92015-10-01 16:20:04 +02004074HDA_CODEC_ENTRY(0x10de0018, "GPU 18 HDMI/DP", patch_nvhdmi),
4075HDA_CODEC_ENTRY(0x10de0019, "GPU 19 HDMI/DP", patch_nvhdmi),
4076HDA_CODEC_ENTRY(0x10de001a, "GPU 1a HDMI/DP", patch_nvhdmi),
4077HDA_CODEC_ENTRY(0x10de001b, "GPU 1b HDMI/DP", patch_nvhdmi),
4078HDA_CODEC_ENTRY(0x10de001c, "GPU 1c HDMI/DP", patch_nvhdmi),
4079HDA_CODEC_ENTRY(0x10de0020, "Tegra30 HDMI", patch_tegra_hdmi),
4080HDA_CODEC_ENTRY(0x10de0022, "Tegra114 HDMI", patch_tegra_hdmi),
4081HDA_CODEC_ENTRY(0x10de0028, "Tegra124 HDMI", patch_tegra_hdmi),
4082HDA_CODEC_ENTRY(0x10de0029, "Tegra210 HDMI/DP", patch_tegra_hdmi),
4083HDA_CODEC_ENTRY(0x10de0040, "GPU 40 HDMI/DP", patch_nvhdmi),
4084HDA_CODEC_ENTRY(0x10de0041, "GPU 41 HDMI/DP", patch_nvhdmi),
4085HDA_CODEC_ENTRY(0x10de0042, "GPU 42 HDMI/DP", patch_nvhdmi),
4086HDA_CODEC_ENTRY(0x10de0043, "GPU 43 HDMI/DP", patch_nvhdmi),
4087HDA_CODEC_ENTRY(0x10de0044, "GPU 44 HDMI/DP", patch_nvhdmi),
4088HDA_CODEC_ENTRY(0x10de0051, "GPU 51 HDMI/DP", patch_nvhdmi),
4089HDA_CODEC_ENTRY(0x10de0060, "GPU 60 HDMI/DP", patch_nvhdmi),
4090HDA_CODEC_ENTRY(0x10de0067, "MCP67 HDMI", patch_nvhdmi_2ch),
4091HDA_CODEC_ENTRY(0x10de0070, "GPU 70 HDMI/DP", patch_nvhdmi),
4092HDA_CODEC_ENTRY(0x10de0071, "GPU 71 HDMI/DP", patch_nvhdmi),
4093HDA_CODEC_ENTRY(0x10de0072, "GPU 72 HDMI/DP", patch_nvhdmi),
4094HDA_CODEC_ENTRY(0x10de007d, "GPU 7d HDMI/DP", patch_nvhdmi),
Aaron Plattner3ec622f2016-01-28 14:07:38 -08004095HDA_CODEC_ENTRY(0x10de0083, "GPU 83 HDMI/DP", patch_nvhdmi),
Takashi Iwaib9a94a92015-10-01 16:20:04 +02004096HDA_CODEC_ENTRY(0x10de8001, "MCP73 HDMI", patch_nvhdmi_2ch),
4097HDA_CODEC_ENTRY(0x11069f80, "VX900 HDMI/DP", patch_via_hdmi),
4098HDA_CODEC_ENTRY(0x11069f81, "VX900 HDMI/DP", patch_via_hdmi),
4099HDA_CODEC_ENTRY(0x11069f84, "VX11 HDMI/DP", patch_generic_hdmi),
4100HDA_CODEC_ENTRY(0x11069f85, "VX11 HDMI/DP", patch_generic_hdmi),
4101HDA_CODEC_ENTRY(0x80860054, "IbexPeak HDMI", patch_generic_hdmi),
4102HDA_CODEC_ENTRY(0x80862801, "Bearlake HDMI", patch_generic_hdmi),
4103HDA_CODEC_ENTRY(0x80862802, "Cantiga HDMI", patch_generic_hdmi),
4104HDA_CODEC_ENTRY(0x80862803, "Eaglelake HDMI", patch_generic_hdmi),
4105HDA_CODEC_ENTRY(0x80862804, "IbexPeak HDMI", patch_generic_hdmi),
4106HDA_CODEC_ENTRY(0x80862805, "CougarPoint HDMI", patch_generic_hdmi),
4107HDA_CODEC_ENTRY(0x80862806, "PantherPoint HDMI", patch_generic_hdmi),
4108HDA_CODEC_ENTRY(0x80862807, "Haswell HDMI", patch_generic_hdmi),
4109HDA_CODEC_ENTRY(0x80862808, "Broadwell HDMI", patch_generic_hdmi),
4110HDA_CODEC_ENTRY(0x80862809, "Skylake HDMI", patch_generic_hdmi),
4111HDA_CODEC_ENTRY(0x8086280a, "Broxton HDMI", patch_generic_hdmi),
Libin Yang91815d82016-01-14 14:09:00 +08004112HDA_CODEC_ENTRY(0x8086280b, "Kabylake HDMI", patch_generic_hdmi),
Takashi Iwaib9a94a92015-10-01 16:20:04 +02004113HDA_CODEC_ENTRY(0x80862880, "CedarTrail HDMI", patch_generic_hdmi),
4114HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_generic_hdmi),
4115HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_generic_hdmi),
4116HDA_CODEC_ENTRY(0x808629fb, "Crestline HDMI", patch_generic_hdmi),
Takashi Iwaid8a766a2015-02-17 15:25:37 +01004117/* special ID for generic HDMI */
Takashi Iwaib9a94a92015-10-01 16:20:04 +02004118HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC_HDMI, "Generic HDMI", patch_generic_hdmi),
Takashi Iwai84eb01b2010-09-07 12:27:25 +02004119{} /* terminator */
4120};
Takashi Iwaib9a94a92015-10-01 16:20:04 +02004121MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_hdmi);
Takashi Iwai84eb01b2010-09-07 12:27:25 +02004122
4123MODULE_LICENSE("GPL");
4124MODULE_DESCRIPTION("HDMI HD-audio codec");
4125MODULE_ALIAS("snd-hda-codec-intelhdmi");
4126MODULE_ALIAS("snd-hda-codec-nvhdmi");
4127MODULE_ALIAS("snd-hda-codec-atihdmi");
4128
Takashi Iwaid8a766a2015-02-17 15:25:37 +01004129static struct hda_codec_driver hdmi_driver = {
Takashi Iwaib9a94a92015-10-01 16:20:04 +02004130 .id = snd_hda_id_hdmi,
Takashi Iwai84eb01b2010-09-07 12:27:25 +02004131};
4132
Takashi Iwaid8a766a2015-02-17 15:25:37 +01004133module_hda_codec_driver(hdmi_driver);