xref: /openbmc/linux/sound/soc/codecs/hdac_hdmi.c (revision fc181b04f2d44805624d4bc5a0615bc084199a81)
118382eadSSubhransu S. Prusty /*
218382eadSSubhransu S. Prusty  *  hdac_hdmi.c - ASoc HDA-HDMI codec driver for Intel platforms
318382eadSSubhransu S. Prusty  *
418382eadSSubhransu S. Prusty  *  Copyright (C) 2014-2015 Intel Corp
518382eadSSubhransu S. Prusty  *  Author: Samreen Nilofer <samreen.nilofer@intel.com>
618382eadSSubhransu S. Prusty  *	    Subhransu S. Prusty <subhransu.s.prusty@intel.com>
718382eadSSubhransu S. Prusty  *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
818382eadSSubhransu S. Prusty  *
918382eadSSubhransu S. Prusty  *  This program is free software; you can redistribute it and/or modify
1018382eadSSubhransu S. Prusty  *  it under the terms of the GNU General Public License as published by
1118382eadSSubhransu S. Prusty  *  the Free Software Foundation; version 2 of the License.
1218382eadSSubhransu S. Prusty  *
1318382eadSSubhransu S. Prusty  *  This program is distributed in the hope that it will be useful, but
1418382eadSSubhransu S. Prusty  *  WITHOUT ANY WARRANTY; without even the implied warranty of
1518382eadSSubhransu S. Prusty  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1618382eadSSubhransu S. Prusty  *  General Public License for more details.
1718382eadSSubhransu S. Prusty  *
1818382eadSSubhransu S. Prusty  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1918382eadSSubhransu S. Prusty  */
2018382eadSSubhransu S. Prusty #include <linux/init.h>
2118382eadSSubhransu S. Prusty #include <linux/delay.h>
2218382eadSSubhransu S. Prusty #include <linux/module.h>
2318382eadSSubhransu S. Prusty #include <linux/pm_runtime.h>
24a657f1d0SSubhransu S. Prusty #include <linux/hdmi.h>
252428bca3SSubhransu S. Prusty #include <drm/drm_edid.h>
2618382eadSSubhransu S. Prusty #include <sound/pcm_params.h>
274a3478deSJeeja KP #include <sound/jack.h>
2818382eadSSubhransu S. Prusty #include <sound/soc.h>
2918382eadSSubhransu S. Prusty #include <sound/hdaudio_ext.h>
3007f083abSSubhransu S. Prusty #include <sound/hda_i915.h>
312428bca3SSubhransu S. Prusty #include <sound/pcm_drm_eld.h>
32bcced704SSubhransu S. Prusty #include <sound/hda_chmap.h>
3318382eadSSubhransu S. Prusty #include "../../hda/local.h"
344a3478deSJeeja KP #include "hdac_hdmi.h"
3518382eadSSubhransu S. Prusty 
3617a42c45SSubhransu S. Prusty #define NAME_SIZE	32
3717a42c45SSubhransu S. Prusty 
38b0362adbSSubhransu S. Prusty #define AMP_OUT_MUTE		0xb080
39b0362adbSSubhransu S. Prusty #define AMP_OUT_UNMUTE		0xb000
4018382eadSSubhransu S. Prusty #define PIN_OUT			(AC_PINCTL_OUT_EN)
41b0362adbSSubhransu S. Prusty 
4218382eadSSubhransu S. Prusty #define HDA_MAX_CONNECTIONS     32
4318382eadSSubhransu S. Prusty 
44148569fdSSubhransu S. Prusty #define HDA_MAX_CVTS		3
45754695f9SJeeja KP #define HDA_MAX_PORTS		3
46148569fdSSubhransu S. Prusty 
47b8a54545SSubhransu S. Prusty #define ELD_MAX_SIZE    256
48b8a54545SSubhransu S. Prusty #define ELD_FIXED_BYTES	20
49b8a54545SSubhransu S. Prusty 
50f6fa11a3SSandeep Tayal #define ELD_VER_CEA_861D 2
51f6fa11a3SSandeep Tayal #define ELD_VER_PARTIAL 31
52f6fa11a3SSandeep Tayal #define ELD_MAX_MNL     16
53f6fa11a3SSandeep Tayal 
5418382eadSSubhransu S. Prusty struct hdac_hdmi_cvt_params {
5518382eadSSubhransu S. Prusty 	unsigned int channels_min;
5618382eadSSubhransu S. Prusty 	unsigned int channels_max;
5718382eadSSubhransu S. Prusty 	u32 rates;
5818382eadSSubhransu S. Prusty 	u64 formats;
5918382eadSSubhransu S. Prusty 	unsigned int maxbps;
6018382eadSSubhransu S. Prusty };
6118382eadSSubhransu S. Prusty 
6218382eadSSubhransu S. Prusty struct hdac_hdmi_cvt {
6315b91447SSubhransu S. Prusty 	struct list_head head;
6418382eadSSubhransu S. Prusty 	hda_nid_t nid;
654a3478deSJeeja KP 	const char *name;
6618382eadSSubhransu S. Prusty 	struct hdac_hdmi_cvt_params params;
6718382eadSSubhransu S. Prusty };
6818382eadSSubhransu S. Prusty 
69b7756edeSSubhransu S. Prusty /* Currently only spk_alloc, more to be added */
70b7756edeSSubhransu S. Prusty struct hdac_hdmi_parsed_eld {
71b7756edeSSubhransu S. Prusty 	u8 spk_alloc;
72b7756edeSSubhransu S. Prusty };
73b7756edeSSubhransu S. Prusty 
74b8a54545SSubhransu S. Prusty struct hdac_hdmi_eld {
75b8a54545SSubhransu S. Prusty 	bool	monitor_present;
76b8a54545SSubhransu S. Prusty 	bool	eld_valid;
77b8a54545SSubhransu S. Prusty 	int	eld_size;
78b8a54545SSubhransu S. Prusty 	char    eld_buffer[ELD_MAX_SIZE];
79b7756edeSSubhransu S. Prusty 	struct	hdac_hdmi_parsed_eld info;
80b8a54545SSubhransu S. Prusty };
81b8a54545SSubhransu S. Prusty 
8218382eadSSubhransu S. Prusty struct hdac_hdmi_pin {
8315b91447SSubhransu S. Prusty 	struct list_head head;
8418382eadSSubhransu S. Prusty 	hda_nid_t nid;
852acd8309SJeeja KP 	bool mst_capable;
86754695f9SJeeja KP 	struct hdac_hdmi_port *ports;
87754695f9SJeeja KP 	int num_ports;
88754695f9SJeeja KP 	struct hdac_ext_device *edev;
89754695f9SJeeja KP };
90754695f9SJeeja KP 
91754695f9SJeeja KP struct hdac_hdmi_port {
92754695f9SJeeja KP 	int id;
93754695f9SJeeja KP 	struct hdac_hdmi_pin *pin;
9418382eadSSubhransu S. Prusty 	int num_mux_nids;
9518382eadSSubhransu S. Prusty 	hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
96b8a54545SSubhransu S. Prusty 	struct hdac_hdmi_eld eld;
9718382eadSSubhransu S. Prusty };
9818382eadSSubhransu S. Prusty 
994a3478deSJeeja KP struct hdac_hdmi_pcm {
1004a3478deSJeeja KP 	struct list_head head;
1014a3478deSJeeja KP 	int pcm_id;
102754695f9SJeeja KP 	struct hdac_hdmi_port *port;
1034a3478deSJeeja KP 	struct hdac_hdmi_cvt *cvt;
1044a3478deSJeeja KP 	struct snd_jack *jack;
105c9bfb5d7SJeeja KP 	int stream_tag;
106c9bfb5d7SJeeja KP 	int channels;
107c9bfb5d7SJeeja KP 	int format;
108ab1eea19SJeeja KP 	bool chmap_set;
109ab1eea19SJeeja KP 	unsigned char chmap[8]; /* ALSA API channel-map */
110ab1eea19SJeeja KP 	struct mutex lock;
1114a3478deSJeeja KP };
1124a3478deSJeeja KP 
113754695f9SJeeja KP struct hdac_hdmi_dai_port_map {
11418382eadSSubhransu S. Prusty 	int dai_id;
115754695f9SJeeja KP 	struct hdac_hdmi_port *port;
11615b91447SSubhransu S. Prusty 	struct hdac_hdmi_cvt *cvt;
11718382eadSSubhransu S. Prusty };
11818382eadSSubhransu S. Prusty 
11918382eadSSubhransu S. Prusty struct hdac_hdmi_priv {
120754695f9SJeeja KP 	struct hdac_hdmi_dai_port_map dai_map[HDA_MAX_CVTS];
12115b91447SSubhransu S. Prusty 	struct list_head pin_list;
12215b91447SSubhransu S. Prusty 	struct list_head cvt_list;
1234a3478deSJeeja KP 	struct list_head pcm_list;
12415b91447SSubhransu S. Prusty 	int num_pin;
12515b91447SSubhransu S. Prusty 	int num_cvt;
126754695f9SJeeja KP 	int num_ports;
1274a3478deSJeeja KP 	struct mutex pin_mutex;
128bcced704SSubhransu S. Prusty 	struct hdac_chmap chmap;
12918382eadSSubhransu S. Prusty };
13018382eadSSubhransu S. Prusty 
131c9bfb5d7SJeeja KP static struct hdac_hdmi_pcm *
132c9bfb5d7SJeeja KP hdac_hdmi_get_pcm_from_cvt(struct hdac_hdmi_priv *hdmi,
133c9bfb5d7SJeeja KP 			   struct hdac_hdmi_cvt *cvt)
134c9bfb5d7SJeeja KP {
135c9bfb5d7SJeeja KP 	struct hdac_hdmi_pcm *pcm = NULL;
1361de777feSJeeja KP 
137c9bfb5d7SJeeja KP 	list_for_each_entry(pcm, &hdmi->pcm_list, head) {
138c9bfb5d7SJeeja KP 		if (pcm->cvt == cvt)
139c9bfb5d7SJeeja KP 			break;
140c9bfb5d7SJeeja KP 	}
141c9bfb5d7SJeeja KP 
142c9bfb5d7SJeeja KP 	return pcm;
143c9bfb5d7SJeeja KP }
1441de777feSJeeja KP 
145*fc181b04SJeeja KP /* MST supported verbs */
146*fc181b04SJeeja KP /*
147*fc181b04SJeeja KP  * Get the no devices that can be connected to a port on the Pin widget.
148*fc181b04SJeeja KP  */
149*fc181b04SJeeja KP static int hdac_hdmi_get_port_len(struct hdac_ext_device *hdac, hda_nid_t nid)
150*fc181b04SJeeja KP {
151*fc181b04SJeeja KP 	unsigned int caps;
152*fc181b04SJeeja KP 	unsigned int type, param;
153*fc181b04SJeeja KP 
154*fc181b04SJeeja KP 	caps = get_wcaps(&hdac->hdac, nid);
155*fc181b04SJeeja KP 	type = get_wcaps_type(caps);
156*fc181b04SJeeja KP 
157*fc181b04SJeeja KP 	if (!(caps & AC_WCAP_DIGITAL) || (type != AC_WID_PIN))
158*fc181b04SJeeja KP 		return 0;
159*fc181b04SJeeja KP 
160*fc181b04SJeeja KP 	param = snd_hdac_read_parm_uncached(&hdac->hdac, nid,
161*fc181b04SJeeja KP 					AC_PAR_DEVLIST_LEN);
162*fc181b04SJeeja KP 	if (param == -1)
163*fc181b04SJeeja KP 		return param;
164*fc181b04SJeeja KP 
165*fc181b04SJeeja KP 	return param & AC_DEV_LIST_LEN_MASK;
166*fc181b04SJeeja KP }
167*fc181b04SJeeja KP 
168*fc181b04SJeeja KP /*
169*fc181b04SJeeja KP  * Get the port entry select on the pin. Return the port entry
170*fc181b04SJeeja KP  * id selected on the pin. Return 0 means the first port entry
171*fc181b04SJeeja KP  * is selected or MST is not supported.
172*fc181b04SJeeja KP  */
173*fc181b04SJeeja KP static int hdac_hdmi_port_select_get(struct hdac_ext_device *hdac,
174*fc181b04SJeeja KP 					struct hdac_hdmi_port *port)
175*fc181b04SJeeja KP {
176*fc181b04SJeeja KP 	return snd_hdac_codec_read(&hdac->hdac, port->pin->nid,
177*fc181b04SJeeja KP 				0, AC_VERB_GET_DEVICE_SEL, 0);
178*fc181b04SJeeja KP }
179*fc181b04SJeeja KP 
180*fc181b04SJeeja KP /*
181*fc181b04SJeeja KP  * Sets the selected port entry for the configuring Pin widget verb.
182*fc181b04SJeeja KP  * returns error if port set is not equal to port get otherwise success
183*fc181b04SJeeja KP  */
184*fc181b04SJeeja KP static int hdac_hdmi_port_select_set(struct hdac_ext_device *hdac,
185*fc181b04SJeeja KP 					struct hdac_hdmi_port *port)
186*fc181b04SJeeja KP {
187*fc181b04SJeeja KP 	int num_ports;
188*fc181b04SJeeja KP 
189*fc181b04SJeeja KP 	if (!port->pin->mst_capable)
190*fc181b04SJeeja KP 		return 0;
191*fc181b04SJeeja KP 
192*fc181b04SJeeja KP 	/* AC_PAR_DEVLIST_LEN is 0 based. */
193*fc181b04SJeeja KP 	num_ports = hdac_hdmi_get_port_len(hdac, port->pin->nid);
194*fc181b04SJeeja KP 
195*fc181b04SJeeja KP 	if (num_ports < 0)
196*fc181b04SJeeja KP 		return -EIO;
197*fc181b04SJeeja KP 	/*
198*fc181b04SJeeja KP 	 * Device List Length is a 0 based integer value indicating the
199*fc181b04SJeeja KP 	 * number of sink device that a MST Pin Widget can support.
200*fc181b04SJeeja KP 	 */
201*fc181b04SJeeja KP 	if (num_ports + 1  < port->id)
202*fc181b04SJeeja KP 		return 0;
203*fc181b04SJeeja KP 
204*fc181b04SJeeja KP 	snd_hdac_codec_write(&hdac->hdac, port->pin->nid, 0,
205*fc181b04SJeeja KP 			AC_VERB_SET_DEVICE_SEL, port->id);
206*fc181b04SJeeja KP 
207*fc181b04SJeeja KP 	if (port->id != hdac_hdmi_port_select_get(hdac, port))
208*fc181b04SJeeja KP 		return -EIO;
209*fc181b04SJeeja KP 
210*fc181b04SJeeja KP 	dev_dbg(&hdac->hdac.dev, "Selected the port=%d\n", port->id);
211*fc181b04SJeeja KP 
212*fc181b04SJeeja KP 	return 0;
213*fc181b04SJeeja KP }
214*fc181b04SJeeja KP 
2152889099eSSubhransu S. Prusty static struct hdac_hdmi_pcm *get_hdmi_pcm_from_id(struct hdac_hdmi_priv *hdmi,
2162889099eSSubhransu S. Prusty 						int pcm_idx)
2172889099eSSubhransu S. Prusty {
2182889099eSSubhransu S. Prusty 	struct hdac_hdmi_pcm *pcm;
2192889099eSSubhransu S. Prusty 
2202889099eSSubhransu S. Prusty 	list_for_each_entry(pcm, &hdmi->pcm_list, head) {
2212889099eSSubhransu S. Prusty 		if (pcm->pcm_id == pcm_idx)
2222889099eSSubhransu S. Prusty 			return pcm;
2232889099eSSubhransu S. Prusty 	}
2242889099eSSubhransu S. Prusty 
2252889099eSSubhransu S. Prusty 	return NULL;
2262889099eSSubhransu S. Prusty }
2272889099eSSubhransu S. Prusty 
228e342ac08SSubhransu S. Prusty static inline struct hdac_ext_device *to_hda_ext_device(struct device *dev)
229e342ac08SSubhransu S. Prusty {
23051b2c425SGeliang Tang 	struct hdac_device *hdac = dev_to_hdac_dev(dev);
231e342ac08SSubhransu S. Prusty 
23251b2c425SGeliang Tang 	return to_ehdac_device(hdac);
233e342ac08SSubhransu S. Prusty }
234e342ac08SSubhransu S. Prusty 
2352428bca3SSubhransu S. Prusty static unsigned int sad_format(const u8 *sad)
2362428bca3SSubhransu S. Prusty {
2372428bca3SSubhransu S. Prusty 	return ((sad[0] >> 0x3) & 0x1f);
2382428bca3SSubhransu S. Prusty }
2392428bca3SSubhransu S. Prusty 
2402428bca3SSubhransu S. Prusty static unsigned int sad_sample_bits_lpcm(const u8 *sad)
2412428bca3SSubhransu S. Prusty {
2422428bca3SSubhransu S. Prusty 	return (sad[2] & 7);
2432428bca3SSubhransu S. Prusty }
2442428bca3SSubhransu S. Prusty 
2452428bca3SSubhransu S. Prusty static int hdac_hdmi_eld_limit_formats(struct snd_pcm_runtime *runtime,
2462428bca3SSubhransu S. Prusty 						void *eld)
2472428bca3SSubhransu S. Prusty {
2482428bca3SSubhransu S. Prusty 	u64 formats = SNDRV_PCM_FMTBIT_S16;
2492428bca3SSubhransu S. Prusty 	int i;
2502428bca3SSubhransu S. Prusty 	const u8 *sad, *eld_buf = eld;
2512428bca3SSubhransu S. Prusty 
2522428bca3SSubhransu S. Prusty 	sad = drm_eld_sad(eld_buf);
2532428bca3SSubhransu S. Prusty 	if (!sad)
2542428bca3SSubhransu S. Prusty 		goto format_constraint;
2552428bca3SSubhransu S. Prusty 
2562428bca3SSubhransu S. Prusty 	for (i = drm_eld_sad_count(eld_buf); i > 0; i--, sad += 3) {
2572428bca3SSubhransu S. Prusty 		if (sad_format(sad) == 1) { /* AUDIO_CODING_TYPE_LPCM */
2582428bca3SSubhransu S. Prusty 
2592428bca3SSubhransu S. Prusty 			/*
2602428bca3SSubhransu S. Prusty 			 * the controller support 20 and 24 bits in 32 bit
2612428bca3SSubhransu S. Prusty 			 * container so we set S32
2622428bca3SSubhransu S. Prusty 			 */
2632428bca3SSubhransu S. Prusty 			if (sad_sample_bits_lpcm(sad) & 0x6)
2642428bca3SSubhransu S. Prusty 				formats |= SNDRV_PCM_FMTBIT_S32;
2652428bca3SSubhransu S. Prusty 		}
2662428bca3SSubhransu S. Prusty 	}
2672428bca3SSubhransu S. Prusty 
2682428bca3SSubhransu S. Prusty format_constraint:
2692428bca3SSubhransu S. Prusty 	return snd_pcm_hw_constraint_mask64(runtime, SNDRV_PCM_HW_PARAM_FORMAT,
2702428bca3SSubhransu S. Prusty 				formats);
2712428bca3SSubhransu S. Prusty 
2722428bca3SSubhransu S. Prusty }
2732428bca3SSubhransu S. Prusty 
274a657f1d0SSubhransu S. Prusty static void
275a657f1d0SSubhransu S. Prusty hdac_hdmi_set_dip_index(struct hdac_ext_device *hdac, hda_nid_t pin_nid,
276a657f1d0SSubhransu S. Prusty 				int packet_index, int byte_index)
277a657f1d0SSubhransu S. Prusty {
278a657f1d0SSubhransu S. Prusty 	int val;
279a657f1d0SSubhransu S. Prusty 
280a657f1d0SSubhransu S. Prusty 	val = (packet_index << 5) | (byte_index & 0x1f);
281a657f1d0SSubhransu S. Prusty 
282a657f1d0SSubhransu S. Prusty 	snd_hdac_codec_write(&hdac->hdac, pin_nid, 0,
283a657f1d0SSubhransu S. Prusty 				AC_VERB_SET_HDMI_DIP_INDEX, val);
284a657f1d0SSubhransu S. Prusty }
285a657f1d0SSubhransu S. Prusty 
286478f544eSSubhransu S. Prusty struct dp_audio_infoframe {
287478f544eSSubhransu S. Prusty 	u8 type; /* 0x84 */
288478f544eSSubhransu S. Prusty 	u8 len;  /* 0x1b */
289478f544eSSubhransu S. Prusty 	u8 ver;  /* 0x11 << 2 */
290478f544eSSubhransu S. Prusty 
291478f544eSSubhransu S. Prusty 	u8 CC02_CT47;	/* match with HDMI infoframe from this on */
292478f544eSSubhransu S. Prusty 	u8 SS01_SF24;
293478f544eSSubhransu S. Prusty 	u8 CXT04;
294478f544eSSubhransu S. Prusty 	u8 CA;
295478f544eSSubhransu S. Prusty 	u8 LFEPBL01_LSV36_DM_INH7;
296478f544eSSubhransu S. Prusty };
297478f544eSSubhransu S. Prusty 
298a657f1d0SSubhransu S. Prusty static int hdac_hdmi_setup_audio_infoframe(struct hdac_ext_device *hdac,
299754695f9SJeeja KP 		   struct hdac_hdmi_pcm *pcm, struct hdac_hdmi_port *port)
300a657f1d0SSubhransu S. Prusty {
301a657f1d0SSubhransu S. Prusty 	uint8_t buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AUDIO_INFOFRAME_SIZE];
302a657f1d0SSubhransu S. Prusty 	struct hdmi_audio_infoframe frame;
303754695f9SJeeja KP 	struct hdac_hdmi_pin *pin = port->pin;
304478f544eSSubhransu S. Prusty 	struct dp_audio_infoframe dp_ai;
305478f544eSSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = hdac->private_data;
306ab1eea19SJeeja KP 	struct hdac_hdmi_cvt *cvt = pcm->cvt;
307478f544eSSubhransu S. Prusty 	u8 *dip;
308a657f1d0SSubhransu S. Prusty 	int ret;
309a657f1d0SSubhransu S. Prusty 	int i;
310478f544eSSubhransu S. Prusty 	const u8 *eld_buf;
311478f544eSSubhransu S. Prusty 	u8 conn_type;
312bcced704SSubhransu S. Prusty 	int channels, ca;
313a657f1d0SSubhransu S. Prusty 
314754695f9SJeeja KP 	ca = snd_hdac_channel_allocation(&hdac->hdac, port->eld.info.spk_alloc,
315ab1eea19SJeeja KP 			pcm->channels, pcm->chmap_set, true, pcm->chmap);
316bcced704SSubhransu S. Prusty 
317bcced704SSubhransu S. Prusty 	channels = snd_hdac_get_active_channels(ca);
318ab1eea19SJeeja KP 	hdmi->chmap.ops.set_channel_count(&hdac->hdac, cvt->nid, channels);
319bcced704SSubhransu S. Prusty 
320bcced704SSubhransu S. Prusty 	snd_hdac_setup_channel_mapping(&hdmi->chmap, pin->nid, false, ca,
321ab1eea19SJeeja KP 				pcm->channels, pcm->chmap, pcm->chmap_set);
322bcced704SSubhransu S. Prusty 
323754695f9SJeeja KP 	eld_buf = port->eld.eld_buffer;
324478f544eSSubhransu S. Prusty 	conn_type = drm_eld_get_conn_type(eld_buf);
325a657f1d0SSubhransu S. Prusty 
326478f544eSSubhransu S. Prusty 	switch (conn_type) {
327478f544eSSubhransu S. Prusty 	case DRM_ELD_CONN_TYPE_HDMI:
328478f544eSSubhransu S. Prusty 		hdmi_audio_infoframe_init(&frame);
329478f544eSSubhransu S. Prusty 
330478f544eSSubhransu S. Prusty 		frame.channels = channels;
331bcced704SSubhransu S. Prusty 		frame.channel_allocation = ca;
332a657f1d0SSubhransu S. Prusty 
333a657f1d0SSubhransu S. Prusty 		ret = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
334a657f1d0SSubhransu S. Prusty 		if (ret < 0)
335a657f1d0SSubhransu S. Prusty 			return ret;
336a657f1d0SSubhransu S. Prusty 
337478f544eSSubhransu S. Prusty 		break;
338478f544eSSubhransu S. Prusty 
339478f544eSSubhransu S. Prusty 	case DRM_ELD_CONN_TYPE_DP:
340478f544eSSubhransu S. Prusty 		memset(&dp_ai, 0, sizeof(dp_ai));
341478f544eSSubhransu S. Prusty 		dp_ai.type	= 0x84;
342478f544eSSubhransu S. Prusty 		dp_ai.len	= 0x1b;
343478f544eSSubhransu S. Prusty 		dp_ai.ver	= 0x11 << 2;
344478f544eSSubhransu S. Prusty 		dp_ai.CC02_CT47	= channels - 1;
345bcced704SSubhransu S. Prusty 		dp_ai.CA	= ca;
346478f544eSSubhransu S. Prusty 
347478f544eSSubhransu S. Prusty 		dip = (u8 *)&dp_ai;
348478f544eSSubhransu S. Prusty 		break;
349478f544eSSubhransu S. Prusty 
350478f544eSSubhransu S. Prusty 	default:
351478f544eSSubhransu S. Prusty 		dev_err(&hdac->hdac.dev, "Invalid connection type: %d\n",
352478f544eSSubhransu S. Prusty 						conn_type);
353478f544eSSubhransu S. Prusty 		return -EIO;
354478f544eSSubhransu S. Prusty 	}
355478f544eSSubhransu S. Prusty 
356a657f1d0SSubhransu S. Prusty 	/* stop infoframe transmission */
357ab1eea19SJeeja KP 	hdac_hdmi_set_dip_index(hdac, pin->nid, 0x0, 0x0);
358ab1eea19SJeeja KP 	snd_hdac_codec_write(&hdac->hdac, pin->nid, 0,
359a657f1d0SSubhransu S. Prusty 			AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_DISABLE);
360a657f1d0SSubhransu S. Prusty 
361a657f1d0SSubhransu S. Prusty 
362a657f1d0SSubhransu S. Prusty 	/*  Fill infoframe. Index auto-incremented */
363ab1eea19SJeeja KP 	hdac_hdmi_set_dip_index(hdac, pin->nid, 0x0, 0x0);
364478f544eSSubhransu S. Prusty 	if (conn_type == DRM_ELD_CONN_TYPE_HDMI) {
365391005e8SSubhransu S. Prusty 		for (i = 0; i < sizeof(buffer); i++)
366ab1eea19SJeeja KP 			snd_hdac_codec_write(&hdac->hdac, pin->nid, 0,
367391005e8SSubhransu S. Prusty 				AC_VERB_SET_HDMI_DIP_DATA, buffer[i]);
368478f544eSSubhransu S. Prusty 	} else {
369478f544eSSubhransu S. Prusty 		for (i = 0; i < sizeof(dp_ai); i++)
370ab1eea19SJeeja KP 			snd_hdac_codec_write(&hdac->hdac, pin->nid, 0,
371478f544eSSubhransu S. Prusty 				AC_VERB_SET_HDMI_DIP_DATA, dip[i]);
372478f544eSSubhransu S. Prusty 	}
373a657f1d0SSubhransu S. Prusty 
374a657f1d0SSubhransu S. Prusty 	/* Start infoframe */
375ab1eea19SJeeja KP 	hdac_hdmi_set_dip_index(hdac, pin->nid, 0x0, 0x0);
376ab1eea19SJeeja KP 	snd_hdac_codec_write(&hdac->hdac, pin->nid, 0,
377a657f1d0SSubhransu S. Prusty 			AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_BEST);
378a657f1d0SSubhransu S. Prusty 
379a657f1d0SSubhransu S. Prusty 	return 0;
380a657f1d0SSubhransu S. Prusty }
381a657f1d0SSubhransu S. Prusty 
382c9bfb5d7SJeeja KP static int hdac_hdmi_set_tdm_slot(struct snd_soc_dai *dai,
383c9bfb5d7SJeeja KP 		unsigned int tx_mask, unsigned int rx_mask,
384c9bfb5d7SJeeja KP 		int slots, int slot_width)
385b0362adbSSubhransu S. Prusty {
386c9bfb5d7SJeeja KP 	struct hdac_ext_device *edev = snd_soc_dai_get_drvdata(dai);
387c9bfb5d7SJeeja KP 	struct hdac_hdmi_priv *hdmi = edev->private_data;
388754695f9SJeeja KP 	struct hdac_hdmi_dai_port_map *dai_map;
389c9bfb5d7SJeeja KP 	struct hdac_hdmi_pcm *pcm;
390c9bfb5d7SJeeja KP 
391c9bfb5d7SJeeja KP 	dev_dbg(&edev->hdac.dev, "%s: strm_tag: %d\n", __func__, tx_mask);
392b0362adbSSubhransu S. Prusty 
393b0362adbSSubhransu S. Prusty 	dai_map = &hdmi->dai_map[dai->id];
394b0362adbSSubhransu S. Prusty 
395c9bfb5d7SJeeja KP 	pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
396b0362adbSSubhransu S. Prusty 
397c9bfb5d7SJeeja KP 	if (pcm)
398c9bfb5d7SJeeja KP 		pcm->stream_tag = (tx_mask << 4);
399bcced704SSubhransu S. Prusty 
400c9bfb5d7SJeeja KP 	return 0;
401b0362adbSSubhransu S. Prusty }
402b0362adbSSubhransu S. Prusty 
403b0362adbSSubhransu S. Prusty static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,
404b0362adbSSubhransu S. Prusty 	struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)
405b0362adbSSubhransu S. Prusty {
406b0362adbSSubhransu S. Prusty 	struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai);
40754dfa1eaSSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = hdac->private_data;
408754695f9SJeeja KP 	struct hdac_hdmi_dai_port_map *dai_map;
409754695f9SJeeja KP 	struct hdac_hdmi_port *port;
410c9bfb5d7SJeeja KP 	struct hdac_hdmi_pcm *pcm;
411c9bfb5d7SJeeja KP 	int format;
412b0362adbSSubhransu S. Prusty 
41354dfa1eaSSubhransu S. Prusty 	dai_map = &hdmi->dai_map[dai->id];
414754695f9SJeeja KP 	port = dai_map->port;
41554dfa1eaSSubhransu S. Prusty 
416754695f9SJeeja KP 	if (!port)
41754dfa1eaSSubhransu S. Prusty 		return -ENODEV;
41854dfa1eaSSubhransu S. Prusty 
419754695f9SJeeja KP 	if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
420754695f9SJeeja KP 		dev_err(&hdac->hdac.dev,
421754695f9SJeeja KP 			"device is not configured for this pin:port%d:%d\n",
422754695f9SJeeja KP 					port->pin->nid, port->id);
423b0362adbSSubhransu S. Prusty 		return -ENODEV;
424b0362adbSSubhransu S. Prusty 	}
425b0362adbSSubhransu S. Prusty 
426c9bfb5d7SJeeja KP 	format = snd_hdac_calc_stream_format(params_rate(hparams),
427b0362adbSSubhransu S. Prusty 			params_channels(hparams), params_format(hparams),
428b0362adbSSubhransu S. Prusty 			24, 0);
429b0362adbSSubhransu S. Prusty 
430c9bfb5d7SJeeja KP 	pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
431c9bfb5d7SJeeja KP 	if (!pcm)
432148569fdSSubhransu S. Prusty 		return -EIO;
433148569fdSSubhransu S. Prusty 
434c9bfb5d7SJeeja KP 	pcm->format = format;
435c9bfb5d7SJeeja KP 	pcm->channels = params_channels(hparams);
436148569fdSSubhransu S. Prusty 
437148569fdSSubhransu S. Prusty 	return 0;
438148569fdSSubhransu S. Prusty }
439148569fdSSubhransu S. Prusty 
440754695f9SJeeja KP static int hdac_hdmi_query_port_connlist(struct hdac_ext_device *hdac,
441754695f9SJeeja KP 					struct hdac_hdmi_pin *pin,
442754695f9SJeeja KP 					struct hdac_hdmi_port *port)
443148569fdSSubhransu S. Prusty {
444148569fdSSubhransu S. Prusty 	if (!(get_wcaps(&hdac->hdac, pin->nid) & AC_WCAP_CONN_LIST)) {
445148569fdSSubhransu S. Prusty 		dev_warn(&hdac->hdac.dev,
446148569fdSSubhransu S. Prusty 			"HDMI: pin %d wcaps %#x does not support connection list\n",
447148569fdSSubhransu S. Prusty 			pin->nid, get_wcaps(&hdac->hdac, pin->nid));
448148569fdSSubhransu S. Prusty 		return -EINVAL;
449148569fdSSubhransu S. Prusty 	}
450148569fdSSubhransu S. Prusty 
451754695f9SJeeja KP 	port->num_mux_nids = snd_hdac_get_connections(&hdac->hdac, pin->nid,
452754695f9SJeeja KP 			port->mux_nids, HDA_MAX_CONNECTIONS);
453754695f9SJeeja KP 	if (port->num_mux_nids == 0)
454754695f9SJeeja KP 		dev_warn(&hdac->hdac.dev,
455754695f9SJeeja KP 			"No connections found for pin:port %d:%d\n",
456754695f9SJeeja KP 						pin->nid, port->id);
457148569fdSSubhransu S. Prusty 
458754695f9SJeeja KP 	dev_dbg(&hdac->hdac.dev, "num_mux_nids %d for pin:port %d:%d\n",
459754695f9SJeeja KP 			port->num_mux_nids, pin->nid, port->id);
460148569fdSSubhransu S. Prusty 
461754695f9SJeeja KP 	return port->num_mux_nids;
462148569fdSSubhransu S. Prusty }
463148569fdSSubhransu S. Prusty 
464148569fdSSubhransu S. Prusty /*
465754695f9SJeeja KP  * Query pcm list and return port to which stream is routed.
466148569fdSSubhransu S. Prusty  *
467754695f9SJeeja KP  * Also query connection list of the pin, to validate the cvt to port map.
468148569fdSSubhransu S. Prusty  *
469754695f9SJeeja KP  * Same stream rendering to multiple ports simultaneously can be done
470754695f9SJeeja KP  * possibly, but not supported for now in driver. So return the first port
471148569fdSSubhransu S. Prusty  * connected.
472148569fdSSubhransu S. Prusty  */
473754695f9SJeeja KP static struct hdac_hdmi_port *hdac_hdmi_get_port_from_cvt(
474148569fdSSubhransu S. Prusty 			struct hdac_ext_device *edev,
475148569fdSSubhransu S. Prusty 			struct hdac_hdmi_priv *hdmi,
476148569fdSSubhransu S. Prusty 			struct hdac_hdmi_cvt *cvt)
477148569fdSSubhransu S. Prusty {
478148569fdSSubhransu S. Prusty 	struct hdac_hdmi_pcm *pcm;
479754695f9SJeeja KP 	struct hdac_hdmi_port *port = NULL;
480148569fdSSubhransu S. Prusty 	int ret, i;
481148569fdSSubhransu S. Prusty 
482148569fdSSubhransu S. Prusty 	list_for_each_entry(pcm, &hdmi->pcm_list, head) {
483148569fdSSubhransu S. Prusty 		if (pcm->cvt == cvt) {
484754695f9SJeeja KP 			port = pcm->port;
485148569fdSSubhransu S. Prusty 			break;
486148569fdSSubhransu S. Prusty 		}
487148569fdSSubhransu S. Prusty 	}
488148569fdSSubhransu S. Prusty 
489754695f9SJeeja KP 	if (port) {
490754695f9SJeeja KP 		ret = hdac_hdmi_query_port_connlist(edev, port->pin, port);
491148569fdSSubhransu S. Prusty 		if (ret < 0)
492148569fdSSubhransu S. Prusty 			return NULL;
493148569fdSSubhransu S. Prusty 
494754695f9SJeeja KP 		for (i = 0; i < port->num_mux_nids; i++) {
495754695f9SJeeja KP 			if (port->mux_nids[i] == cvt->nid)
496754695f9SJeeja KP 				return port;
497148569fdSSubhransu S. Prusty 		}
498148569fdSSubhransu S. Prusty 	}
499148569fdSSubhransu S. Prusty 
500148569fdSSubhransu S. Prusty 	return NULL;
501148569fdSSubhransu S. Prusty }
502148569fdSSubhransu S. Prusty 
50354dfa1eaSSubhransu S. Prusty /*
50454dfa1eaSSubhransu S. Prusty  * This tries to get a valid pin and set the HW constraints based on the
50554dfa1eaSSubhransu S. Prusty  * ELD. Even if a valid pin is not found return success so that device open
50654dfa1eaSSubhransu S. Prusty  * doesn't fail.
50754dfa1eaSSubhransu S. Prusty  */
508b0362adbSSubhransu S. Prusty static int hdac_hdmi_pcm_open(struct snd_pcm_substream *substream,
509b0362adbSSubhransu S. Prusty 			struct snd_soc_dai *dai)
510b0362adbSSubhransu S. Prusty {
511b0362adbSSubhransu S. Prusty 	struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai);
512b0362adbSSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = hdac->private_data;
513754695f9SJeeja KP 	struct hdac_hdmi_dai_port_map *dai_map;
514148569fdSSubhransu S. Prusty 	struct hdac_hdmi_cvt *cvt;
515754695f9SJeeja KP 	struct hdac_hdmi_port *port;
5162428bca3SSubhransu S. Prusty 	int ret;
517b0362adbSSubhransu S. Prusty 
518b0362adbSSubhransu S. Prusty 	dai_map = &hdmi->dai_map[dai->id];
519b0362adbSSubhransu S. Prusty 
520148569fdSSubhransu S. Prusty 	cvt = dai_map->cvt;
521754695f9SJeeja KP 	port = hdac_hdmi_get_port_from_cvt(hdac, hdmi, cvt);
52254dfa1eaSSubhransu S. Prusty 
52354dfa1eaSSubhransu S. Prusty 	/*
52454dfa1eaSSubhransu S. Prusty 	 * To make PA and other userland happy.
52554dfa1eaSSubhransu S. Prusty 	 * userland scans devices so returning error does not help.
52654dfa1eaSSubhransu S. Prusty 	 */
527754695f9SJeeja KP 	if (!port)
52854dfa1eaSSubhransu S. Prusty 		return 0;
529148569fdSSubhransu S. Prusty 
530754695f9SJeeja KP 	if ((!port->eld.monitor_present) ||
531754695f9SJeeja KP 			(!port->eld.eld_valid)) {
532b0362adbSSubhransu S. Prusty 
53354dfa1eaSSubhransu S. Prusty 		dev_warn(&hdac->hdac.dev,
534754695f9SJeeja KP 			"Failed: present?:%d ELD valid?:%d pin:port: %d:%d\n",
535754695f9SJeeja KP 			port->eld.monitor_present, port->eld.eld_valid,
536754695f9SJeeja KP 			port->pin->nid, port->id);
537b8a54545SSubhransu S. Prusty 
53854dfa1eaSSubhransu S. Prusty 		return 0;
539b0362adbSSubhransu S. Prusty 	}
540b0362adbSSubhransu S. Prusty 
541754695f9SJeeja KP 	dai_map->port = port;
542b0362adbSSubhransu S. Prusty 
5432428bca3SSubhransu S. Prusty 	ret = hdac_hdmi_eld_limit_formats(substream->runtime,
544754695f9SJeeja KP 				port->eld.eld_buffer);
5452428bca3SSubhransu S. Prusty 	if (ret < 0)
5462428bca3SSubhransu S. Prusty 		return ret;
547b0362adbSSubhransu S. Prusty 
5482428bca3SSubhransu S. Prusty 	return snd_pcm_hw_constraint_eld(substream->runtime,
549754695f9SJeeja KP 				port->eld.eld_buffer);
550b0362adbSSubhransu S. Prusty }
551b0362adbSSubhransu S. Prusty 
552b0362adbSSubhransu S. Prusty static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,
553b0362adbSSubhransu S. Prusty 		struct snd_soc_dai *dai)
554b0362adbSSubhransu S. Prusty {
555b0362adbSSubhransu S. Prusty 	struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai);
556b0362adbSSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = hdac->private_data;
557754695f9SJeeja KP 	struct hdac_hdmi_dai_port_map *dai_map;
558ab1eea19SJeeja KP 	struct hdac_hdmi_pcm *pcm;
559b0362adbSSubhransu S. Prusty 
560b0362adbSSubhransu S. Prusty 	dai_map = &hdmi->dai_map[dai->id];
561b0362adbSSubhransu S. Prusty 
562ab1eea19SJeeja KP 	pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
563bcced704SSubhransu S. Prusty 
564ab1eea19SJeeja KP 	if (pcm) {
565ab1eea19SJeeja KP 		mutex_lock(&pcm->lock);
566ab1eea19SJeeja KP 		pcm->chmap_set = false;
567ab1eea19SJeeja KP 		memset(pcm->chmap, 0, sizeof(pcm->chmap));
568ab1eea19SJeeja KP 		pcm->channels = 0;
569ab1eea19SJeeja KP 		mutex_unlock(&pcm->lock);
570b0362adbSSubhransu S. Prusty 	}
571ab1eea19SJeeja KP 
572754695f9SJeeja KP 	if (dai_map->port)
573754695f9SJeeja KP 		dai_map->port = NULL;
57454dfa1eaSSubhransu S. Prusty }
575b0362adbSSubhransu S. Prusty 
57618382eadSSubhransu S. Prusty static int
57718382eadSSubhransu S. Prusty hdac_hdmi_query_cvt_params(struct hdac_device *hdac, struct hdac_hdmi_cvt *cvt)
57818382eadSSubhransu S. Prusty {
579bcced704SSubhransu S. Prusty 	unsigned int chans;
580bcced704SSubhransu S. Prusty 	struct hdac_ext_device *edev = to_ehdac_device(hdac);
581bcced704SSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = edev->private_data;
58218382eadSSubhransu S. Prusty 	int err;
58318382eadSSubhransu S. Prusty 
584bcced704SSubhransu S. Prusty 	chans = get_wcaps(hdac, cvt->nid);
585bcced704SSubhransu S. Prusty 	chans = get_wcaps_channels(chans);
586bcced704SSubhransu S. Prusty 
587bcced704SSubhransu S. Prusty 	cvt->params.channels_min = 2;
588bcced704SSubhransu S. Prusty 
589bcced704SSubhransu S. Prusty 	cvt->params.channels_max = chans;
590bcced704SSubhransu S. Prusty 	if (chans > hdmi->chmap.channels_max)
591bcced704SSubhransu S. Prusty 		hdmi->chmap.channels_max = chans;
59218382eadSSubhransu S. Prusty 
59318382eadSSubhransu S. Prusty 	err = snd_hdac_query_supported_pcm(hdac, cvt->nid,
59418382eadSSubhransu S. Prusty 			&cvt->params.rates,
59518382eadSSubhransu S. Prusty 			&cvt->params.formats,
59618382eadSSubhransu S. Prusty 			&cvt->params.maxbps);
59718382eadSSubhransu S. Prusty 	if (err < 0)
59818382eadSSubhransu S. Prusty 		dev_err(&hdac->dev,
59918382eadSSubhransu S. Prusty 			"Failed to query pcm params for nid %d: %d\n",
60018382eadSSubhransu S. Prusty 			cvt->nid, err);
60118382eadSSubhransu S. Prusty 
60218382eadSSubhransu S. Prusty 	return err;
60318382eadSSubhransu S. Prusty }
60418382eadSSubhransu S. Prusty 
60579f4e922SSubhransu S. Prusty static int hdac_hdmi_fill_widget_info(struct device *dev,
606c9bfb5d7SJeeja KP 		struct snd_soc_dapm_widget *w, enum snd_soc_dapm_type id,
607c9bfb5d7SJeeja KP 		void *priv, const char *wname, const char *stream,
608c9bfb5d7SJeeja KP 		struct snd_kcontrol_new *wc, int numkc,
609c9bfb5d7SJeeja KP 		int (*event)(struct snd_soc_dapm_widget *,
610c9bfb5d7SJeeja KP 		struct snd_kcontrol *, int), unsigned short event_flags)
61118382eadSSubhransu S. Prusty {
61218382eadSSubhransu S. Prusty 	w->id = id;
61379f4e922SSubhransu S. Prusty 	w->name = devm_kstrdup(dev, wname, GFP_KERNEL);
61479f4e922SSubhransu S. Prusty 	if (!w->name)
61579f4e922SSubhransu S. Prusty 		return -ENOMEM;
61679f4e922SSubhransu S. Prusty 
61718382eadSSubhransu S. Prusty 	w->sname = stream;
61818382eadSSubhransu S. Prusty 	w->reg = SND_SOC_NOPM;
61918382eadSSubhransu S. Prusty 	w->shift = 0;
62079f4e922SSubhransu S. Prusty 	w->kcontrol_news = wc;
62179f4e922SSubhransu S. Prusty 	w->num_kcontrols = numkc;
62279f4e922SSubhransu S. Prusty 	w->priv = priv;
623c9bfb5d7SJeeja KP 	w->event = event;
624c9bfb5d7SJeeja KP 	w->event_flags = event_flags;
62579f4e922SSubhransu S. Prusty 
62679f4e922SSubhransu S. Prusty 	return 0;
62718382eadSSubhransu S. Prusty }
62818382eadSSubhransu S. Prusty 
62918382eadSSubhransu S. Prusty static void hdac_hdmi_fill_route(struct snd_soc_dapm_route *route,
63079f4e922SSubhransu S. Prusty 		const char *sink, const char *control, const char *src,
63179f4e922SSubhransu S. Prusty 		int (*handler)(struct snd_soc_dapm_widget *src,
63279f4e922SSubhransu S. Prusty 			struct snd_soc_dapm_widget *sink))
63318382eadSSubhransu S. Prusty {
63418382eadSSubhransu S. Prusty 	route->sink = sink;
63518382eadSSubhransu S. Prusty 	route->source = src;
63618382eadSSubhransu S. Prusty 	route->control = control;
63779f4e922SSubhransu S. Prusty 	route->connected = handler;
63818382eadSSubhransu S. Prusty }
63918382eadSSubhransu S. Prusty 
6404a3478deSJeeja KP static struct hdac_hdmi_pcm *hdac_hdmi_get_pcm(struct hdac_ext_device *edev,
641754695f9SJeeja KP 					struct hdac_hdmi_port *port)
6424a3478deSJeeja KP {
6434a3478deSJeeja KP 	struct hdac_hdmi_priv *hdmi = edev->private_data;
6444a3478deSJeeja KP 	struct hdac_hdmi_pcm *pcm = NULL;
6454a3478deSJeeja KP 
6464a3478deSJeeja KP 	list_for_each_entry(pcm, &hdmi->pcm_list, head) {
647754695f9SJeeja KP 		if (!pcm->port)
648754695f9SJeeja KP 			continue;
649754695f9SJeeja KP 
650754695f9SJeeja KP 		if (pcm->port == port)
6514a3478deSJeeja KP 			return pcm;
6524a3478deSJeeja KP 	}
6534a3478deSJeeja KP 
6544a3478deSJeeja KP 	return NULL;
6554a3478deSJeeja KP }
6564a3478deSJeeja KP 
657c9bfb5d7SJeeja KP static void hdac_hdmi_set_power_state(struct hdac_ext_device *edev,
658c9bfb5d7SJeeja KP 			     hda_nid_t nid, unsigned int pwr_state)
659c9bfb5d7SJeeja KP {
660c9bfb5d7SJeeja KP 	if (get_wcaps(&edev->hdac, nid) & AC_WCAP_POWER) {
661c9bfb5d7SJeeja KP 		if (!snd_hdac_check_power_state(&edev->hdac, nid, pwr_state))
662c9bfb5d7SJeeja KP 			snd_hdac_codec_write(&edev->hdac, nid, 0,
663c9bfb5d7SJeeja KP 				AC_VERB_SET_POWER_STATE, pwr_state);
664c9bfb5d7SJeeja KP 	}
665c9bfb5d7SJeeja KP }
666c9bfb5d7SJeeja KP 
667c9bfb5d7SJeeja KP static void hdac_hdmi_set_amp(struct hdac_ext_device *edev,
668c9bfb5d7SJeeja KP 				   hda_nid_t nid, int val)
669c9bfb5d7SJeeja KP {
670c9bfb5d7SJeeja KP 	if (get_wcaps(&edev->hdac, nid) & AC_WCAP_OUT_AMP)
671c9bfb5d7SJeeja KP 		snd_hdac_codec_write(&edev->hdac, nid, 0,
672c9bfb5d7SJeeja KP 					AC_VERB_SET_AMP_GAIN_MUTE, val);
673c9bfb5d7SJeeja KP }
674c9bfb5d7SJeeja KP 
675c9bfb5d7SJeeja KP 
676c9bfb5d7SJeeja KP static int hdac_hdmi_pin_output_widget_event(struct snd_soc_dapm_widget *w,
677c9bfb5d7SJeeja KP 					struct snd_kcontrol *kc, int event)
678c9bfb5d7SJeeja KP {
679754695f9SJeeja KP 	struct hdac_hdmi_port *port = w->priv;
680c9bfb5d7SJeeja KP 	struct hdac_ext_device *edev = to_hda_ext_device(w->dapm->dev);
681c9bfb5d7SJeeja KP 	struct hdac_hdmi_pcm *pcm;
682c9bfb5d7SJeeja KP 
683c9bfb5d7SJeeja KP 	dev_dbg(&edev->hdac.dev, "%s: widget: %s event: %x\n",
684c9bfb5d7SJeeja KP 			__func__, w->name, event);
685c9bfb5d7SJeeja KP 
686754695f9SJeeja KP 	pcm = hdac_hdmi_get_pcm(edev, port);
687c9bfb5d7SJeeja KP 	if (!pcm)
688c9bfb5d7SJeeja KP 		return -EIO;
689c9bfb5d7SJeeja KP 
690c9bfb5d7SJeeja KP 	switch (event) {
691c9bfb5d7SJeeja KP 	case SND_SOC_DAPM_PRE_PMU:
692754695f9SJeeja KP 		hdac_hdmi_set_power_state(edev, port->pin->nid, AC_PWRST_D0);
693c9bfb5d7SJeeja KP 
694c9bfb5d7SJeeja KP 		/* Enable out path for this pin widget */
695754695f9SJeeja KP 		snd_hdac_codec_write(&edev->hdac, port->pin->nid, 0,
696c9bfb5d7SJeeja KP 				AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
697c9bfb5d7SJeeja KP 
698754695f9SJeeja KP 		hdac_hdmi_set_amp(edev, port->pin->nid, AMP_OUT_UNMUTE);
699c9bfb5d7SJeeja KP 
700754695f9SJeeja KP 		return hdac_hdmi_setup_audio_infoframe(edev, pcm, port);
701c9bfb5d7SJeeja KP 
702c9bfb5d7SJeeja KP 	case SND_SOC_DAPM_POST_PMD:
703754695f9SJeeja KP 		hdac_hdmi_set_amp(edev, port->pin->nid, AMP_OUT_MUTE);
704c9bfb5d7SJeeja KP 
705c9bfb5d7SJeeja KP 		/* Disable out path for this pin widget */
706754695f9SJeeja KP 		snd_hdac_codec_write(&edev->hdac, port->pin->nid, 0,
707c9bfb5d7SJeeja KP 				AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
708c9bfb5d7SJeeja KP 
709754695f9SJeeja KP 		hdac_hdmi_set_power_state(edev, port->pin->nid, AC_PWRST_D3);
710c9bfb5d7SJeeja KP 		break;
711c9bfb5d7SJeeja KP 
712c9bfb5d7SJeeja KP 	}
713c9bfb5d7SJeeja KP 
714c9bfb5d7SJeeja KP 	return 0;
715c9bfb5d7SJeeja KP }
716c9bfb5d7SJeeja KP 
717c9bfb5d7SJeeja KP static int hdac_hdmi_cvt_output_widget_event(struct snd_soc_dapm_widget *w,
718c9bfb5d7SJeeja KP 					struct snd_kcontrol *kc, int event)
719c9bfb5d7SJeeja KP {
720c9bfb5d7SJeeja KP 	struct hdac_hdmi_cvt *cvt = w->priv;
721c9bfb5d7SJeeja KP 	struct hdac_ext_device *edev = to_hda_ext_device(w->dapm->dev);
722c9bfb5d7SJeeja KP 	struct hdac_hdmi_priv *hdmi = edev->private_data;
723c9bfb5d7SJeeja KP 	struct hdac_hdmi_pcm *pcm;
724c9bfb5d7SJeeja KP 
725c9bfb5d7SJeeja KP 	dev_dbg(&edev->hdac.dev, "%s: widget: %s event: %x\n",
726c9bfb5d7SJeeja KP 			__func__, w->name, event);
727c9bfb5d7SJeeja KP 
728c9bfb5d7SJeeja KP 	pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, cvt);
729c9bfb5d7SJeeja KP 	if (!pcm)
730c9bfb5d7SJeeja KP 		return -EIO;
731c9bfb5d7SJeeja KP 
732c9bfb5d7SJeeja KP 	switch (event) {
733c9bfb5d7SJeeja KP 	case SND_SOC_DAPM_PRE_PMU:
734c9bfb5d7SJeeja KP 		hdac_hdmi_set_power_state(edev, cvt->nid, AC_PWRST_D0);
735c9bfb5d7SJeeja KP 
736c9bfb5d7SJeeja KP 		/* Enable transmission */
737c9bfb5d7SJeeja KP 		snd_hdac_codec_write(&edev->hdac, cvt->nid, 0,
738c9bfb5d7SJeeja KP 			AC_VERB_SET_DIGI_CONVERT_1, 1);
739c9bfb5d7SJeeja KP 
740c9bfb5d7SJeeja KP 		/* Category Code (CC) to zero */
741c9bfb5d7SJeeja KP 		snd_hdac_codec_write(&edev->hdac, cvt->nid, 0,
742c9bfb5d7SJeeja KP 			AC_VERB_SET_DIGI_CONVERT_2, 0);
743c9bfb5d7SJeeja KP 
744c9bfb5d7SJeeja KP 		snd_hdac_codec_write(&edev->hdac, cvt->nid, 0,
745c9bfb5d7SJeeja KP 				AC_VERB_SET_CHANNEL_STREAMID, pcm->stream_tag);
746c9bfb5d7SJeeja KP 		snd_hdac_codec_write(&edev->hdac, cvt->nid, 0,
747c9bfb5d7SJeeja KP 				AC_VERB_SET_STREAM_FORMAT, pcm->format);
748c9bfb5d7SJeeja KP 		break;
749c9bfb5d7SJeeja KP 
750c9bfb5d7SJeeja KP 	case SND_SOC_DAPM_POST_PMD:
751c9bfb5d7SJeeja KP 		snd_hdac_codec_write(&edev->hdac, cvt->nid, 0,
752c9bfb5d7SJeeja KP 				AC_VERB_SET_CHANNEL_STREAMID, 0);
753c9bfb5d7SJeeja KP 		snd_hdac_codec_write(&edev->hdac, cvt->nid, 0,
754c9bfb5d7SJeeja KP 				AC_VERB_SET_STREAM_FORMAT, 0);
755c9bfb5d7SJeeja KP 
756c9bfb5d7SJeeja KP 		hdac_hdmi_set_power_state(edev, cvt->nid, AC_PWRST_D3);
757c9bfb5d7SJeeja KP 		break;
758c9bfb5d7SJeeja KP 
759c9bfb5d7SJeeja KP 	}
760c9bfb5d7SJeeja KP 
761c9bfb5d7SJeeja KP 	return 0;
762c9bfb5d7SJeeja KP }
763c9bfb5d7SJeeja KP 
764c9bfb5d7SJeeja KP static int hdac_hdmi_pin_mux_widget_event(struct snd_soc_dapm_widget *w,
765c9bfb5d7SJeeja KP 					struct snd_kcontrol *kc, int event)
766c9bfb5d7SJeeja KP {
767754695f9SJeeja KP 	struct hdac_hdmi_port *port = w->priv;
768c9bfb5d7SJeeja KP 	struct hdac_ext_device *edev = to_hda_ext_device(w->dapm->dev);
769c9bfb5d7SJeeja KP 	int mux_idx;
770c9bfb5d7SJeeja KP 
771c9bfb5d7SJeeja KP 	dev_dbg(&edev->hdac.dev, "%s: widget: %s event: %x\n",
772c9bfb5d7SJeeja KP 			__func__, w->name, event);
773c9bfb5d7SJeeja KP 
774c9bfb5d7SJeeja KP 	if (!kc)
775c9bfb5d7SJeeja KP 		kc  = w->kcontrols[0];
776c9bfb5d7SJeeja KP 
777c9bfb5d7SJeeja KP 	mux_idx = dapm_kcontrol_get_value(kc);
778c9bfb5d7SJeeja KP 	if (mux_idx > 0) {
779754695f9SJeeja KP 		snd_hdac_codec_write(&edev->hdac, port->pin->nid, 0,
780c9bfb5d7SJeeja KP 			AC_VERB_SET_CONNECT_SEL, (mux_idx - 1));
781c9bfb5d7SJeeja KP 	}
782c9bfb5d7SJeeja KP 
783c9bfb5d7SJeeja KP 	return 0;
784c9bfb5d7SJeeja KP }
785c9bfb5d7SJeeja KP 
7864a3478deSJeeja KP /*
7874a3478deSJeeja KP  * Based on user selection, map the PINs with the PCMs.
7884a3478deSJeeja KP  */
789754695f9SJeeja KP static int hdac_hdmi_set_pin_port_mux(struct snd_kcontrol *kcontrol,
7904a3478deSJeeja KP 		struct snd_ctl_elem_value *ucontrol)
7914a3478deSJeeja KP {
7924a3478deSJeeja KP 	int ret;
7934a3478deSJeeja KP 	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
7944a3478deSJeeja KP 	struct snd_soc_dapm_widget *w = snd_soc_dapm_kcontrol_widget(kcontrol);
7954a3478deSJeeja KP 	struct snd_soc_dapm_context *dapm = w->dapm;
796754695f9SJeeja KP 	struct hdac_hdmi_port *port = w->priv;
7974a3478deSJeeja KP 	struct hdac_ext_device *edev = to_hda_ext_device(dapm->dev);
7984a3478deSJeeja KP 	struct hdac_hdmi_priv *hdmi = edev->private_data;
7994a3478deSJeeja KP 	struct hdac_hdmi_pcm *pcm = NULL;
8004a3478deSJeeja KP 	const char *cvt_name =  e->texts[ucontrol->value.enumerated.item[0]];
8014a3478deSJeeja KP 
8024a3478deSJeeja KP 	ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
8034a3478deSJeeja KP 	if (ret < 0)
8044a3478deSJeeja KP 		return ret;
8054a3478deSJeeja KP 
806754695f9SJeeja KP 	if (port == NULL)
807754695f9SJeeja KP 		return -EINVAL;
808754695f9SJeeja KP 
8094a3478deSJeeja KP 	mutex_lock(&hdmi->pin_mutex);
8104a3478deSJeeja KP 	list_for_each_entry(pcm, &hdmi->pcm_list, head) {
811754695f9SJeeja KP 		if (!pcm->port && pcm->port == port &&
812754695f9SJeeja KP 			pcm->port->id == port->id)
813754695f9SJeeja KP 			pcm->port = NULL;
8144a3478deSJeeja KP 
8154a3478deSJeeja KP 		/*
8164a3478deSJeeja KP 		 * Jack status is not reported during device probe as the
8174a3478deSJeeja KP 		 * PCMs are not registered by then. So report it here.
8184a3478deSJeeja KP 		 */
819754695f9SJeeja KP 		if (!strcmp(cvt_name, pcm->cvt->name) && !pcm->port) {
820754695f9SJeeja KP 			pcm->port = port;
821754695f9SJeeja KP 			if (port->eld.monitor_present && port->eld.eld_valid) {
8224a3478deSJeeja KP 				dev_dbg(&edev->hdac.dev,
8234a3478deSJeeja KP 					"jack report for pcm=%d\n",
8244a3478deSJeeja KP 					pcm->pcm_id);
8254a3478deSJeeja KP 
8264a3478deSJeeja KP 				snd_jack_report(pcm->jack, SND_JACK_AVOUT);
8274a3478deSJeeja KP 			}
8284a3478deSJeeja KP 			mutex_unlock(&hdmi->pin_mutex);
8294a3478deSJeeja KP 			return ret;
8304a3478deSJeeja KP 		}
8314a3478deSJeeja KP 	}
8324a3478deSJeeja KP 	mutex_unlock(&hdmi->pin_mutex);
8334a3478deSJeeja KP 
8344a3478deSJeeja KP 	return ret;
8354a3478deSJeeja KP }
8364a3478deSJeeja KP 
83779f4e922SSubhransu S. Prusty /*
83879f4e922SSubhransu S. Prusty  * Ideally the Mux inputs should be based on the num_muxs enumerated, but
83979f4e922SSubhransu S. Prusty  * the display driver seem to be programming the connection list for the pin
84079f4e922SSubhransu S. Prusty  * widget runtime.
84179f4e922SSubhransu S. Prusty  *
84279f4e922SSubhransu S. Prusty  * So programming all the possible inputs for the mux, the user has to take
84379f4e922SSubhransu S. Prusty  * care of selecting the right one and leaving all other inputs selected to
84479f4e922SSubhransu S. Prusty  * "NONE"
84579f4e922SSubhransu S. Prusty  */
846754695f9SJeeja KP static int hdac_hdmi_create_pin_port_muxs(struct hdac_ext_device *edev,
847754695f9SJeeja KP 				struct hdac_hdmi_port *port,
84879f4e922SSubhransu S. Prusty 				struct snd_soc_dapm_widget *widget,
84979f4e922SSubhransu S. Prusty 				const char *widget_name)
85018382eadSSubhransu S. Prusty {
85179f4e922SSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = edev->private_data;
852754695f9SJeeja KP 	struct hdac_hdmi_pin *pin = port->pin;
85379f4e922SSubhransu S. Prusty 	struct snd_kcontrol_new *kc;
85479f4e922SSubhransu S. Prusty 	struct hdac_hdmi_cvt *cvt;
85579f4e922SSubhransu S. Prusty 	struct soc_enum *se;
85679f4e922SSubhransu S. Prusty 	char kc_name[NAME_SIZE];
85779f4e922SSubhransu S. Prusty 	char mux_items[NAME_SIZE];
85879f4e922SSubhransu S. Prusty 	/* To hold inputs to the Pin mux */
85979f4e922SSubhransu S. Prusty 	char *items[HDA_MAX_CONNECTIONS];
86079f4e922SSubhransu S. Prusty 	int i = 0;
86179f4e922SSubhransu S. Prusty 	int num_items = hdmi->num_cvt + 1;
86218382eadSSubhransu S. Prusty 
86379f4e922SSubhransu S. Prusty 	kc = devm_kzalloc(&edev->hdac.dev, sizeof(*kc), GFP_KERNEL);
86479f4e922SSubhransu S. Prusty 	if (!kc)
86579f4e922SSubhransu S. Prusty 		return -ENOMEM;
86618382eadSSubhransu S. Prusty 
86779f4e922SSubhransu S. Prusty 	se = devm_kzalloc(&edev->hdac.dev, sizeof(*se), GFP_KERNEL);
86879f4e922SSubhransu S. Prusty 	if (!se)
86979f4e922SSubhransu S. Prusty 		return -ENOMEM;
87018382eadSSubhransu S. Prusty 
871754695f9SJeeja KP 	sprintf(kc_name, "Pin %d port %d Input", pin->nid, port->id);
87279f4e922SSubhransu S. Prusty 	kc->name = devm_kstrdup(&edev->hdac.dev, kc_name, GFP_KERNEL);
87379f4e922SSubhransu S. Prusty 	if (!kc->name)
87479f4e922SSubhransu S. Prusty 		return -ENOMEM;
87518382eadSSubhransu S. Prusty 
87679f4e922SSubhransu S. Prusty 	kc->private_value = (long)se;
87779f4e922SSubhransu S. Prusty 	kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
87879f4e922SSubhransu S. Prusty 	kc->access = 0;
87979f4e922SSubhransu S. Prusty 	kc->info = snd_soc_info_enum_double;
880754695f9SJeeja KP 	kc->put = hdac_hdmi_set_pin_port_mux;
88179f4e922SSubhransu S. Prusty 	kc->get = snd_soc_dapm_get_enum_double;
88279f4e922SSubhransu S. Prusty 
88379f4e922SSubhransu S. Prusty 	se->reg = SND_SOC_NOPM;
88479f4e922SSubhransu S. Prusty 
88579f4e922SSubhransu S. Prusty 	/* enum texts: ["NONE", "cvt #", "cvt #", ...] */
88679f4e922SSubhransu S. Prusty 	se->items = num_items;
88779f4e922SSubhransu S. Prusty 	se->mask = roundup_pow_of_two(se->items) - 1;
88879f4e922SSubhransu S. Prusty 
88979f4e922SSubhransu S. Prusty 	sprintf(mux_items, "NONE");
89079f4e922SSubhransu S. Prusty 	items[i] = devm_kstrdup(&edev->hdac.dev, mux_items, GFP_KERNEL);
89179f4e922SSubhransu S. Prusty 	if (!items[i])
89279f4e922SSubhransu S. Prusty 		return -ENOMEM;
89379f4e922SSubhransu S. Prusty 
89479f4e922SSubhransu S. Prusty 	list_for_each_entry(cvt, &hdmi->cvt_list, head) {
89579f4e922SSubhransu S. Prusty 		i++;
89679f4e922SSubhransu S. Prusty 		sprintf(mux_items, "cvt %d", cvt->nid);
89779f4e922SSubhransu S. Prusty 		items[i] = devm_kstrdup(&edev->hdac.dev, mux_items, GFP_KERNEL);
89879f4e922SSubhransu S. Prusty 		if (!items[i])
89979f4e922SSubhransu S. Prusty 			return -ENOMEM;
90079f4e922SSubhransu S. Prusty 	}
90179f4e922SSubhransu S. Prusty 
90279f4e922SSubhransu S. Prusty 	se->texts = devm_kmemdup(&edev->hdac.dev, items,
90379f4e922SSubhransu S. Prusty 			(num_items  * sizeof(char *)), GFP_KERNEL);
90479f4e922SSubhransu S. Prusty 	if (!se->texts)
90579f4e922SSubhransu S. Prusty 		return -ENOMEM;
90679f4e922SSubhransu S. Prusty 
90779f4e922SSubhransu S. Prusty 	return hdac_hdmi_fill_widget_info(&edev->hdac.dev, widget,
908754695f9SJeeja KP 			snd_soc_dapm_mux, port, widget_name, NULL, kc, 1,
909c9bfb5d7SJeeja KP 			hdac_hdmi_pin_mux_widget_event,
910c9bfb5d7SJeeja KP 			SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_REG);
91179f4e922SSubhransu S. Prusty }
91279f4e922SSubhransu S. Prusty 
91379f4e922SSubhransu S. Prusty /* Add cvt <- input <- mux route map */
91479f4e922SSubhransu S. Prusty static void hdac_hdmi_add_pinmux_cvt_route(struct hdac_ext_device *edev,
91579f4e922SSubhransu S. Prusty 			struct snd_soc_dapm_widget *widgets,
91679f4e922SSubhransu S. Prusty 			struct snd_soc_dapm_route *route, int rindex)
91779f4e922SSubhransu S. Prusty {
91879f4e922SSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = edev->private_data;
91979f4e922SSubhransu S. Prusty 	const struct snd_kcontrol_new *kc;
92079f4e922SSubhransu S. Prusty 	struct soc_enum *se;
921754695f9SJeeja KP 	int mux_index = hdmi->num_cvt + hdmi->num_ports;
92279f4e922SSubhransu S. Prusty 	int i, j;
92379f4e922SSubhransu S. Prusty 
924754695f9SJeeja KP 	for (i = 0; i < hdmi->num_ports; i++) {
92579f4e922SSubhransu S. Prusty 		kc = widgets[mux_index].kcontrol_news;
92679f4e922SSubhransu S. Prusty 		se = (struct soc_enum *)kc->private_value;
92779f4e922SSubhransu S. Prusty 		for (j = 0; j < hdmi->num_cvt; j++) {
92879f4e922SSubhransu S. Prusty 			hdac_hdmi_fill_route(&route[rindex],
92979f4e922SSubhransu S. Prusty 					widgets[mux_index].name,
93079f4e922SSubhransu S. Prusty 					se->texts[j + 1],
93179f4e922SSubhransu S. Prusty 					widgets[j].name, NULL);
93279f4e922SSubhransu S. Prusty 
93379f4e922SSubhransu S. Prusty 			rindex++;
93479f4e922SSubhransu S. Prusty 		}
93579f4e922SSubhransu S. Prusty 
93679f4e922SSubhransu S. Prusty 		mux_index++;
93779f4e922SSubhransu S. Prusty 	}
93879f4e922SSubhransu S. Prusty }
93979f4e922SSubhransu S. Prusty 
94079f4e922SSubhransu S. Prusty /*
94179f4e922SSubhransu S. Prusty  * Widgets are added in the below sequence
94279f4e922SSubhransu S. Prusty  *	Converter widgets for num converters enumerated
943754695f9SJeeja KP  *	Pin-port widgets for num ports for Pins enumerated
944754695f9SJeeja KP  *	Pin-port mux widgets to represent connenction list of pin widget
94579f4e922SSubhransu S. Prusty  *
946754695f9SJeeja KP  * For each port, one Mux and One output widget is added
947754695f9SJeeja KP  * Total widgets elements = num_cvt + (num_ports * 2);
94879f4e922SSubhransu S. Prusty  *
94979f4e922SSubhransu S. Prusty  * Routes are added as below:
950754695f9SJeeja KP  *	pin-port mux -> pin (based on num_ports)
951754695f9SJeeja KP  *	cvt -> "Input sel control" -> pin-port_mux
95279f4e922SSubhransu S. Prusty  *
95379f4e922SSubhransu S. Prusty  * Total route elements:
954754695f9SJeeja KP  *	num_ports + (pin_muxes * num_cvt)
95579f4e922SSubhransu S. Prusty  */
95679f4e922SSubhransu S. Prusty static int create_fill_widget_route_map(struct snd_soc_dapm_context *dapm)
95779f4e922SSubhransu S. Prusty {
95879f4e922SSubhransu S. Prusty 	struct snd_soc_dapm_widget *widgets;
95979f4e922SSubhransu S. Prusty 	struct snd_soc_dapm_route *route;
96079f4e922SSubhransu S. Prusty 	struct hdac_ext_device *edev = to_hda_ext_device(dapm->dev);
96179f4e922SSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = edev->private_data;
96279f4e922SSubhransu S. Prusty 	struct snd_soc_dai_driver *dai_drv = dapm->component->dai_drv;
96379f4e922SSubhransu S. Prusty 	char widget_name[NAME_SIZE];
96479f4e922SSubhransu S. Prusty 	struct hdac_hdmi_cvt *cvt;
96579f4e922SSubhransu S. Prusty 	struct hdac_hdmi_pin *pin;
966754695f9SJeeja KP 	int ret, i = 0, num_routes = 0, j;
96779f4e922SSubhransu S. Prusty 
96879f4e922SSubhransu S. Prusty 	if (list_empty(&hdmi->cvt_list) || list_empty(&hdmi->pin_list))
96979f4e922SSubhransu S. Prusty 		return -EINVAL;
97079f4e922SSubhransu S. Prusty 
971754695f9SJeeja KP 	widgets = devm_kzalloc(dapm->dev, (sizeof(*widgets) *
972754695f9SJeeja KP 				((2 * hdmi->num_ports) + hdmi->num_cvt)),
97379f4e922SSubhransu S. Prusty 				GFP_KERNEL);
97479f4e922SSubhransu S. Prusty 
97579f4e922SSubhransu S. Prusty 	if (!widgets)
97679f4e922SSubhransu S. Prusty 		return -ENOMEM;
97779f4e922SSubhransu S. Prusty 
97879f4e922SSubhransu S. Prusty 	/* DAPM widgets to represent each converter widget */
97979f4e922SSubhransu S. Prusty 	list_for_each_entry(cvt, &hdmi->cvt_list, head) {
98079f4e922SSubhransu S. Prusty 		sprintf(widget_name, "Converter %d", cvt->nid);
98179f4e922SSubhransu S. Prusty 		ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
982c9bfb5d7SJeeja KP 			snd_soc_dapm_aif_in, cvt,
983c9bfb5d7SJeeja KP 			widget_name, dai_drv[i].playback.stream_name, NULL, 0,
984c9bfb5d7SJeeja KP 			hdac_hdmi_cvt_output_widget_event,
985c9bfb5d7SJeeja KP 			SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD);
98679f4e922SSubhransu S. Prusty 		if (ret < 0)
98779f4e922SSubhransu S. Prusty 			return ret;
98879f4e922SSubhransu S. Prusty 		i++;
98979f4e922SSubhransu S. Prusty 	}
99079f4e922SSubhransu S. Prusty 
99179f4e922SSubhransu S. Prusty 	list_for_each_entry(pin, &hdmi->pin_list, head) {
992754695f9SJeeja KP 		for (j = 0; j < pin->num_ports; j++) {
993754695f9SJeeja KP 			sprintf(widget_name, "hif%d-%d Output",
994754695f9SJeeja KP 				pin->nid, pin->ports[j].id);
99579f4e922SSubhransu S. Prusty 			ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
996754695f9SJeeja KP 					snd_soc_dapm_output, &pin->ports[j],
997c9bfb5d7SJeeja KP 					widget_name, NULL, NULL, 0,
998c9bfb5d7SJeeja KP 					hdac_hdmi_pin_output_widget_event,
999754695f9SJeeja KP 					SND_SOC_DAPM_PRE_PMU |
1000754695f9SJeeja KP 					SND_SOC_DAPM_POST_PMD);
100179f4e922SSubhransu S. Prusty 			if (ret < 0)
100279f4e922SSubhransu S. Prusty 				return ret;
100379f4e922SSubhransu S. Prusty 			i++;
100479f4e922SSubhransu S. Prusty 		}
1005754695f9SJeeja KP 	}
100679f4e922SSubhransu S. Prusty 
100779f4e922SSubhransu S. Prusty 	/* DAPM widgets to represent the connection list to pin widget */
100879f4e922SSubhransu S. Prusty 	list_for_each_entry(pin, &hdmi->pin_list, head) {
1009754695f9SJeeja KP 		for (j = 0; j < pin->num_ports; j++) {
1010754695f9SJeeja KP 			sprintf(widget_name, "Pin%d-Port%d Mux",
1011754695f9SJeeja KP 				pin->nid, pin->ports[j].id);
1012754695f9SJeeja KP 			ret = hdac_hdmi_create_pin_port_muxs(edev,
1013754695f9SJeeja KP 						&pin->ports[j], &widgets[i],
101479f4e922SSubhransu S. Prusty 						widget_name);
101579f4e922SSubhransu S. Prusty 			if (ret < 0)
101679f4e922SSubhransu S. Prusty 				return ret;
101779f4e922SSubhransu S. Prusty 			i++;
101879f4e922SSubhransu S. Prusty 
101979f4e922SSubhransu S. Prusty 			/* For cvt to pin_mux mapping */
102079f4e922SSubhransu S. Prusty 			num_routes += hdmi->num_cvt;
102179f4e922SSubhransu S. Prusty 
102279f4e922SSubhransu S. Prusty 			/* For pin_mux to pin mapping */
102379f4e922SSubhransu S. Prusty 			num_routes++;
102479f4e922SSubhransu S. Prusty 		}
1025754695f9SJeeja KP 	}
102679f4e922SSubhransu S. Prusty 
102779f4e922SSubhransu S. Prusty 	route = devm_kzalloc(dapm->dev, (sizeof(*route) * num_routes),
102879f4e922SSubhransu S. Prusty 							GFP_KERNEL);
102979f4e922SSubhransu S. Prusty 	if (!route)
103079f4e922SSubhransu S. Prusty 		return -ENOMEM;
103179f4e922SSubhransu S. Prusty 
103279f4e922SSubhransu S. Prusty 	i = 0;
103379f4e922SSubhransu S. Prusty 	/* Add pin <- NULL <- mux route map */
103479f4e922SSubhransu S. Prusty 	list_for_each_entry(pin, &hdmi->pin_list, head) {
1035754695f9SJeeja KP 		for (j = 0; j < pin->num_ports; j++) {
103679f4e922SSubhransu S. Prusty 			int sink_index = i + hdmi->num_cvt;
1037754695f9SJeeja KP 			int src_index = sink_index + pin->num_ports *
1038754695f9SJeeja KP 						hdmi->num_pin;
103979f4e922SSubhransu S. Prusty 
104079f4e922SSubhransu S. Prusty 			hdac_hdmi_fill_route(&route[i],
104179f4e922SSubhransu S. Prusty 				widgets[sink_index].name, NULL,
104279f4e922SSubhransu S. Prusty 				widgets[src_index].name, NULL);
104379f4e922SSubhransu S. Prusty 			i++;
1044754695f9SJeeja KP 		}
104579f4e922SSubhransu S. Prusty 	}
104679f4e922SSubhransu S. Prusty 
104779f4e922SSubhransu S. Prusty 	hdac_hdmi_add_pinmux_cvt_route(edev, widgets, route, i);
104879f4e922SSubhransu S. Prusty 
104979f4e922SSubhransu S. Prusty 	snd_soc_dapm_new_controls(dapm, widgets,
1050754695f9SJeeja KP 		((2 * hdmi->num_ports) + hdmi->num_cvt));
105179f4e922SSubhransu S. Prusty 
105279f4e922SSubhransu S. Prusty 	snd_soc_dapm_add_routes(dapm, route, num_routes);
105379f4e922SSubhransu S. Prusty 	snd_soc_dapm_new_widgets(dapm->card);
105479f4e922SSubhransu S. Prusty 
105579f4e922SSubhransu S. Prusty 	return 0;
105679f4e922SSubhransu S. Prusty 
105718382eadSSubhransu S. Prusty }
105818382eadSSubhransu S. Prusty 
105915b91447SSubhransu S. Prusty static int hdac_hdmi_init_dai_map(struct hdac_ext_device *edev)
106018382eadSSubhransu S. Prusty {
106115b91447SSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = edev->private_data;
1062754695f9SJeeja KP 	struct hdac_hdmi_dai_port_map *dai_map;
106315b91447SSubhransu S. Prusty 	struct hdac_hdmi_cvt *cvt;
1064148569fdSSubhransu S. Prusty 	int dai_id = 0;
106518382eadSSubhransu S. Prusty 
1066148569fdSSubhransu S. Prusty 	if (list_empty(&hdmi->cvt_list))
106715b91447SSubhransu S. Prusty 		return -EINVAL;
106818382eadSSubhransu S. Prusty 
1069148569fdSSubhransu S. Prusty 	list_for_each_entry(cvt, &hdmi->cvt_list, head) {
1070148569fdSSubhransu S. Prusty 		dai_map = &hdmi->dai_map[dai_id];
1071148569fdSSubhransu S. Prusty 		dai_map->dai_id = dai_id;
107215b91447SSubhransu S. Prusty 		dai_map->cvt = cvt;
107318382eadSSubhransu S. Prusty 
1074148569fdSSubhransu S. Prusty 		dai_id++;
1075148569fdSSubhransu S. Prusty 
1076148569fdSSubhransu S. Prusty 		if (dai_id == HDA_MAX_CVTS) {
1077148569fdSSubhransu S. Prusty 			dev_warn(&edev->hdac.dev,
1078148569fdSSubhransu S. Prusty 				"Max dais supported: %d\n", dai_id);
1079148569fdSSubhransu S. Prusty 			break;
1080148569fdSSubhransu S. Prusty 		}
1081148569fdSSubhransu S. Prusty 	}
108218382eadSSubhransu S. Prusty 
108315b91447SSubhransu S. Prusty 	return 0;
108415b91447SSubhransu S. Prusty }
108515b91447SSubhransu S. Prusty 
108615b91447SSubhransu S. Prusty static int hdac_hdmi_add_cvt(struct hdac_ext_device *edev, hda_nid_t nid)
108715b91447SSubhransu S. Prusty {
108815b91447SSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = edev->private_data;
108915b91447SSubhransu S. Prusty 	struct hdac_hdmi_cvt *cvt;
10904a3478deSJeeja KP 	char name[NAME_SIZE];
109115b91447SSubhransu S. Prusty 
109215b91447SSubhransu S. Prusty 	cvt = kzalloc(sizeof(*cvt), GFP_KERNEL);
109315b91447SSubhransu S. Prusty 	if (!cvt)
109415b91447SSubhransu S. Prusty 		return -ENOMEM;
109515b91447SSubhransu S. Prusty 
109615b91447SSubhransu S. Prusty 	cvt->nid = nid;
10974a3478deSJeeja KP 	sprintf(name, "cvt %d", cvt->nid);
10984a3478deSJeeja KP 	cvt->name = kstrdup(name, GFP_KERNEL);
109915b91447SSubhransu S. Prusty 
110015b91447SSubhransu S. Prusty 	list_add_tail(&cvt->head, &hdmi->cvt_list);
110115b91447SSubhransu S. Prusty 	hdmi->num_cvt++;
110215b91447SSubhransu S. Prusty 
110315b91447SSubhransu S. Prusty 	return hdac_hdmi_query_cvt_params(&edev->hdac, cvt);
110415b91447SSubhransu S. Prusty }
110515b91447SSubhransu S. Prusty 
1106f6fa11a3SSandeep Tayal static int hdac_hdmi_parse_eld(struct hdac_ext_device *edev,
1107754695f9SJeeja KP 			struct hdac_hdmi_port *port)
1108b7756edeSSubhransu S. Prusty {
1109f6fa11a3SSandeep Tayal 	unsigned int ver, mnl;
1110f6fa11a3SSandeep Tayal 
1111754695f9SJeeja KP 	ver = (port->eld.eld_buffer[DRM_ELD_VER] & DRM_ELD_VER_MASK)
1112f6fa11a3SSandeep Tayal 						>> DRM_ELD_VER_SHIFT;
1113f6fa11a3SSandeep Tayal 
1114f6fa11a3SSandeep Tayal 	if (ver != ELD_VER_CEA_861D && ver != ELD_VER_PARTIAL) {
1115f6fa11a3SSandeep Tayal 		dev_err(&edev->hdac.dev, "HDMI: Unknown ELD version %d\n", ver);
1116f6fa11a3SSandeep Tayal 		return -EINVAL;
1117b7756edeSSubhransu S. Prusty 	}
1118b7756edeSSubhransu S. Prusty 
1119754695f9SJeeja KP 	mnl = (port->eld.eld_buffer[DRM_ELD_CEA_EDID_VER_MNL] &
1120f6fa11a3SSandeep Tayal 		DRM_ELD_MNL_MASK) >> DRM_ELD_MNL_SHIFT;
1121f6fa11a3SSandeep Tayal 
1122f6fa11a3SSandeep Tayal 	if (mnl > ELD_MAX_MNL) {
1123f6fa11a3SSandeep Tayal 		dev_err(&edev->hdac.dev, "HDMI: MNL Invalid %d\n", mnl);
1124f6fa11a3SSandeep Tayal 		return -EINVAL;
1125f6fa11a3SSandeep Tayal 	}
1126f6fa11a3SSandeep Tayal 
1127754695f9SJeeja KP 	port->eld.info.spk_alloc = port->eld.eld_buffer[DRM_ELD_SPEAKER];
1128f6fa11a3SSandeep Tayal 
1129f6fa11a3SSandeep Tayal 	return 0;
1130f6fa11a3SSandeep Tayal }
1131f6fa11a3SSandeep Tayal 
1132754695f9SJeeja KP static void hdac_hdmi_present_sense(struct hdac_hdmi_pin *pin,
1133754695f9SJeeja KP 				    struct hdac_hdmi_port *port)
1134b8a54545SSubhransu S. Prusty {
1135b8a54545SSubhransu S. Prusty 	struct hdac_ext_device *edev = pin->edev;
11364a3478deSJeeja KP 	struct hdac_hdmi_priv *hdmi = edev->private_data;
11374a3478deSJeeja KP 	struct hdac_hdmi_pcm *pcm;
1138754695f9SJeeja KP 	int size = 0;
11392acd8309SJeeja KP 	int port_id = -1;
1140754695f9SJeeja KP 
1141754695f9SJeeja KP 	if (!hdmi)
1142754695f9SJeeja KP 		return;
11434a3478deSJeeja KP 
11442acd8309SJeeja KP 	/*
11452acd8309SJeeja KP 	 * In case of non MST pin, get_eld info API expectes port
11462acd8309SJeeja KP 	 * to be -1.
11472acd8309SJeeja KP 	 */
11484a3478deSJeeja KP 	mutex_lock(&hdmi->pin_mutex);
1149754695f9SJeeja KP 	port->eld.monitor_present = false;
1150f6fa11a3SSandeep Tayal 
11512acd8309SJeeja KP 	if (pin->mst_capable)
11522acd8309SJeeja KP 		port_id = port->id;
11532acd8309SJeeja KP 
11542acd8309SJeeja KP 	size = snd_hdac_acomp_get_eld(&edev->hdac, pin->nid, port_id,
1155754695f9SJeeja KP 				&port->eld.monitor_present,
1156754695f9SJeeja KP 				port->eld.eld_buffer,
1157f6fa11a3SSandeep Tayal 				ELD_MAX_SIZE);
1158f6fa11a3SSandeep Tayal 
1159f6fa11a3SSandeep Tayal 	if (size > 0) {
1160f6fa11a3SSandeep Tayal 		size = min(size, ELD_MAX_SIZE);
1161754695f9SJeeja KP 		if (hdac_hdmi_parse_eld(edev, port) < 0)
1162f6fa11a3SSandeep Tayal 			size = -EINVAL;
1163f6fa11a3SSandeep Tayal 	}
1164f6fa11a3SSandeep Tayal 
1165f6fa11a3SSandeep Tayal 	if (size > 0) {
1166754695f9SJeeja KP 		port->eld.eld_valid = true;
1167754695f9SJeeja KP 		port->eld.eld_size = size;
1168f6fa11a3SSandeep Tayal 	} else {
1169754695f9SJeeja KP 		port->eld.eld_valid = false;
1170754695f9SJeeja KP 		port->eld.eld_size = 0;
1171f6fa11a3SSandeep Tayal 	}
1172b8a54545SSubhransu S. Prusty 
1173754695f9SJeeja KP 	pcm = hdac_hdmi_get_pcm(edev, port);
11744a3478deSJeeja KP 
1175754695f9SJeeja KP 	if (!port->eld.monitor_present || !port->eld.eld_valid) {
1176b8a54545SSubhransu S. Prusty 
1177754695f9SJeeja KP 		dev_dbg(&edev->hdac.dev, "%s: disconnect for pin:port %d:%d\n",
1178754695f9SJeeja KP 						__func__, pin->nid, port->id);
11794a3478deSJeeja KP 
11804a3478deSJeeja KP 		/*
11814a3478deSJeeja KP 		 * PCMs are not registered during device probe, so don't
11824a3478deSJeeja KP 		 * report jack here. It will be done in usermode mux
11834a3478deSJeeja KP 		 * control select.
11844a3478deSJeeja KP 		 */
11854a3478deSJeeja KP 		if (pcm) {
11864a3478deSJeeja KP 			dev_dbg(&edev->hdac.dev,
11874a3478deSJeeja KP 				"jack report for pcm=%d\n", pcm->pcm_id);
11884a3478deSJeeja KP 
11894a3478deSJeeja KP 			snd_jack_report(pcm->jack, 0);
11904a3478deSJeeja KP 		}
11914a3478deSJeeja KP 
11924a3478deSJeeja KP 		mutex_unlock(&hdmi->pin_mutex);
1193f6fa11a3SSandeep Tayal 		return;
1194b8a54545SSubhransu S. Prusty 	}
1195b8a54545SSubhransu S. Prusty 
1196754695f9SJeeja KP 	if (port->eld.monitor_present && port->eld.eld_valid) {
11974a3478deSJeeja KP 		if (pcm) {
11984a3478deSJeeja KP 			dev_dbg(&edev->hdac.dev,
11994a3478deSJeeja KP 				"jack report for pcm=%d\n",
12004a3478deSJeeja KP 				pcm->pcm_id);
12014a3478deSJeeja KP 
12024a3478deSJeeja KP 			snd_jack_report(pcm->jack, SND_JACK_AVOUT);
12034a3478deSJeeja KP 		}
12044a3478deSJeeja KP 
1205f6fa11a3SSandeep Tayal 		print_hex_dump_debug("ELD: ", DUMP_PREFIX_OFFSET, 16, 1,
1206754695f9SJeeja KP 			  port->eld.eld_buffer, port->eld.eld_size, false);
1207754695f9SJeeja KP 
1208754695f9SJeeja KP 	}
1209754695f9SJeeja KP 	mutex_unlock(&hdmi->pin_mutex);
12104a3478deSJeeja KP }
12114a3478deSJeeja KP 
1212754695f9SJeeja KP static int hdac_hdmi_add_ports(struct hdac_hdmi_priv *hdmi,
1213754695f9SJeeja KP 				struct hdac_hdmi_pin *pin)
1214754695f9SJeeja KP {
1215754695f9SJeeja KP 	struct hdac_hdmi_port *ports;
1216754695f9SJeeja KP 	int max_ports = HDA_MAX_PORTS;
1217754695f9SJeeja KP 	int i;
1218754695f9SJeeja KP 
1219754695f9SJeeja KP 	/*
1220754695f9SJeeja KP 	 * FIXME: max_port may vary for each platform, so pass this as
1221754695f9SJeeja KP 	 * as driver data or query from i915 interface when this API is
1222754695f9SJeeja KP 	 * implemented.
1223754695f9SJeeja KP 	 */
1224754695f9SJeeja KP 
1225754695f9SJeeja KP 	ports = kcalloc(max_ports, sizeof(*ports), GFP_KERNEL);
1226754695f9SJeeja KP 	if (!ports)
1227754695f9SJeeja KP 		return -ENOMEM;
1228754695f9SJeeja KP 
1229754695f9SJeeja KP 	for (i = 0; i < max_ports; i++) {
1230754695f9SJeeja KP 		ports[i].id = i;
1231754695f9SJeeja KP 		ports[i].pin = pin;
1232754695f9SJeeja KP 	}
1233754695f9SJeeja KP 	pin->ports = ports;
1234754695f9SJeeja KP 	pin->num_ports = max_ports;
1235754695f9SJeeja KP 	return 0;
1236b8a54545SSubhransu S. Prusty }
1237b8a54545SSubhransu S. Prusty 
123815b91447SSubhransu S. Prusty static int hdac_hdmi_add_pin(struct hdac_ext_device *edev, hda_nid_t nid)
123915b91447SSubhransu S. Prusty {
124015b91447SSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = edev->private_data;
124115b91447SSubhransu S. Prusty 	struct hdac_hdmi_pin *pin;
1242754695f9SJeeja KP 	int ret;
124315b91447SSubhransu S. Prusty 
124415b91447SSubhransu S. Prusty 	pin = kzalloc(sizeof(*pin), GFP_KERNEL);
124515b91447SSubhransu S. Prusty 	if (!pin)
124615b91447SSubhransu S. Prusty 		return -ENOMEM;
124715b91447SSubhransu S. Prusty 
124815b91447SSubhransu S. Prusty 	pin->nid = nid;
12492acd8309SJeeja KP 	pin->mst_capable = false;
1250754695f9SJeeja KP 	pin->edev = edev;
1251754695f9SJeeja KP 	ret = hdac_hdmi_add_ports(hdmi, pin);
1252754695f9SJeeja KP 	if (ret < 0)
1253754695f9SJeeja KP 		return ret;
125415b91447SSubhransu S. Prusty 
125515b91447SSubhransu S. Prusty 	list_add_tail(&pin->head, &hdmi->pin_list);
125615b91447SSubhransu S. Prusty 	hdmi->num_pin++;
1257754695f9SJeeja KP 	hdmi->num_ports += pin->num_ports;
1258b8a54545SSubhransu S. Prusty 
125915b91447SSubhransu S. Prusty 	return 0;
126018382eadSSubhransu S. Prusty }
126118382eadSSubhransu S. Prusty 
1262211caab7SSubhransu S. Prusty #define INTEL_VENDOR_NID 0x08
1263211caab7SSubhransu S. Prusty #define INTEL_GET_VENDOR_VERB 0xf81
1264211caab7SSubhransu S. Prusty #define INTEL_SET_VENDOR_VERB 0x781
1265211caab7SSubhransu S. Prusty #define INTEL_EN_DP12			0x02 /* enable DP 1.2 features */
1266211caab7SSubhransu S. Prusty #define INTEL_EN_ALL_PIN_CVTS	0x01 /* enable 2nd & 3rd pins and convertors */
1267211caab7SSubhransu S. Prusty 
1268211caab7SSubhransu S. Prusty static void hdac_hdmi_skl_enable_all_pins(struct hdac_device *hdac)
1269211caab7SSubhransu S. Prusty {
1270211caab7SSubhransu S. Prusty 	unsigned int vendor_param;
1271211caab7SSubhransu S. Prusty 
1272211caab7SSubhransu S. Prusty 	vendor_param = snd_hdac_codec_read(hdac, INTEL_VENDOR_NID, 0,
1273211caab7SSubhransu S. Prusty 				INTEL_GET_VENDOR_VERB, 0);
1274211caab7SSubhransu S. Prusty 	if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
1275211caab7SSubhransu S. Prusty 		return;
1276211caab7SSubhransu S. Prusty 
1277211caab7SSubhransu S. Prusty 	vendor_param |= INTEL_EN_ALL_PIN_CVTS;
1278211caab7SSubhransu S. Prusty 	vendor_param = snd_hdac_codec_read(hdac, INTEL_VENDOR_NID, 0,
1279211caab7SSubhransu S. Prusty 				INTEL_SET_VENDOR_VERB, vendor_param);
1280211caab7SSubhransu S. Prusty 	if (vendor_param == -1)
1281211caab7SSubhransu S. Prusty 		return;
1282211caab7SSubhransu S. Prusty }
1283211caab7SSubhransu S. Prusty 
1284211caab7SSubhransu S. Prusty static void hdac_hdmi_skl_enable_dp12(struct hdac_device *hdac)
1285211caab7SSubhransu S. Prusty {
1286211caab7SSubhransu S. Prusty 	unsigned int vendor_param;
1287211caab7SSubhransu S. Prusty 
1288211caab7SSubhransu S. Prusty 	vendor_param = snd_hdac_codec_read(hdac, INTEL_VENDOR_NID, 0,
1289211caab7SSubhransu S. Prusty 				INTEL_GET_VENDOR_VERB, 0);
1290211caab7SSubhransu S. Prusty 	if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
1291211caab7SSubhransu S. Prusty 		return;
1292211caab7SSubhransu S. Prusty 
1293211caab7SSubhransu S. Prusty 	/* enable DP1.2 mode */
1294211caab7SSubhransu S. Prusty 	vendor_param |= INTEL_EN_DP12;
1295211caab7SSubhransu S. Prusty 	vendor_param = snd_hdac_codec_read(hdac, INTEL_VENDOR_NID, 0,
1296211caab7SSubhransu S. Prusty 				INTEL_SET_VENDOR_VERB, vendor_param);
1297211caab7SSubhransu S. Prusty 	if (vendor_param == -1)
1298211caab7SSubhransu S. Prusty 		return;
1299211caab7SSubhransu S. Prusty 
1300211caab7SSubhransu S. Prusty }
1301211caab7SSubhransu S. Prusty 
130217a42c45SSubhransu S. Prusty static struct snd_soc_dai_ops hdmi_dai_ops = {
130317a42c45SSubhransu S. Prusty 	.startup = hdac_hdmi_pcm_open,
130417a42c45SSubhransu S. Prusty 	.shutdown = hdac_hdmi_pcm_close,
130517a42c45SSubhransu S. Prusty 	.hw_params = hdac_hdmi_set_hw_params,
1306c9bfb5d7SJeeja KP 	.set_tdm_slot = hdac_hdmi_set_tdm_slot,
130717a42c45SSubhransu S. Prusty };
130817a42c45SSubhransu S. Prusty 
130917a42c45SSubhransu S. Prusty /*
131017a42c45SSubhransu S. Prusty  * Each converter can support a stream independently. So a dai is created
131117a42c45SSubhransu S. Prusty  * based on the number of converter queried.
131217a42c45SSubhransu S. Prusty  */
131317a42c45SSubhransu S. Prusty static int hdac_hdmi_create_dais(struct hdac_device *hdac,
131417a42c45SSubhransu S. Prusty 		struct snd_soc_dai_driver **dais,
131517a42c45SSubhransu S. Prusty 		struct hdac_hdmi_priv *hdmi, int num_dais)
131617a42c45SSubhransu S. Prusty {
131717a42c45SSubhransu S. Prusty 	struct snd_soc_dai_driver *hdmi_dais;
131817a42c45SSubhransu S. Prusty 	struct hdac_hdmi_cvt *cvt;
131917a42c45SSubhransu S. Prusty 	char name[NAME_SIZE], dai_name[NAME_SIZE];
132017a42c45SSubhransu S. Prusty 	int i = 0;
132117a42c45SSubhransu S. Prusty 	u32 rates, bps;
132217a42c45SSubhransu S. Prusty 	unsigned int rate_max = 384000, rate_min = 8000;
132317a42c45SSubhransu S. Prusty 	u64 formats;
132417a42c45SSubhransu S. Prusty 	int ret;
132517a42c45SSubhransu S. Prusty 
132617a42c45SSubhransu S. Prusty 	hdmi_dais = devm_kzalloc(&hdac->dev,
132717a42c45SSubhransu S. Prusty 			(sizeof(*hdmi_dais) * num_dais),
132817a42c45SSubhransu S. Prusty 			GFP_KERNEL);
132917a42c45SSubhransu S. Prusty 	if (!hdmi_dais)
133017a42c45SSubhransu S. Prusty 		return -ENOMEM;
133117a42c45SSubhransu S. Prusty 
133217a42c45SSubhransu S. Prusty 	list_for_each_entry(cvt, &hdmi->cvt_list, head) {
133317a42c45SSubhransu S. Prusty 		ret = snd_hdac_query_supported_pcm(hdac, cvt->nid,
133417a42c45SSubhransu S. Prusty 					&rates,	&formats, &bps);
133517a42c45SSubhransu S. Prusty 		if (ret)
133617a42c45SSubhransu S. Prusty 			return ret;
133717a42c45SSubhransu S. Prusty 
133817a42c45SSubhransu S. Prusty 		sprintf(dai_name, "intel-hdmi-hifi%d", i+1);
133917a42c45SSubhransu S. Prusty 		hdmi_dais[i].name = devm_kstrdup(&hdac->dev,
134017a42c45SSubhransu S. Prusty 					dai_name, GFP_KERNEL);
134117a42c45SSubhransu S. Prusty 
134217a42c45SSubhransu S. Prusty 		if (!hdmi_dais[i].name)
134317a42c45SSubhransu S. Prusty 			return -ENOMEM;
134417a42c45SSubhransu S. Prusty 
134517a42c45SSubhransu S. Prusty 		snprintf(name, sizeof(name), "hifi%d", i+1);
134617a42c45SSubhransu S. Prusty 		hdmi_dais[i].playback.stream_name =
134717a42c45SSubhransu S. Prusty 				devm_kstrdup(&hdac->dev, name, GFP_KERNEL);
134817a42c45SSubhransu S. Prusty 		if (!hdmi_dais[i].playback.stream_name)
134917a42c45SSubhransu S. Prusty 			return -ENOMEM;
135017a42c45SSubhransu S. Prusty 
135117a42c45SSubhransu S. Prusty 		/*
135217a42c45SSubhransu S. Prusty 		 * Set caps based on capability queried from the converter.
135317a42c45SSubhransu S. Prusty 		 * It will be constrained runtime based on ELD queried.
135417a42c45SSubhransu S. Prusty 		 */
135517a42c45SSubhransu S. Prusty 		hdmi_dais[i].playback.formats = formats;
135617a42c45SSubhransu S. Prusty 		hdmi_dais[i].playback.rates = rates;
135717a42c45SSubhransu S. Prusty 		hdmi_dais[i].playback.rate_max = rate_max;
135817a42c45SSubhransu S. Prusty 		hdmi_dais[i].playback.rate_min = rate_min;
135917a42c45SSubhransu S. Prusty 		hdmi_dais[i].playback.channels_min = 2;
136017a42c45SSubhransu S. Prusty 		hdmi_dais[i].playback.channels_max = 2;
136117a42c45SSubhransu S. Prusty 		hdmi_dais[i].ops = &hdmi_dai_ops;
136217a42c45SSubhransu S. Prusty 
136317a42c45SSubhransu S. Prusty 		i++;
136417a42c45SSubhransu S. Prusty 	}
136517a42c45SSubhransu S. Prusty 
136617a42c45SSubhransu S. Prusty 	*dais = hdmi_dais;
136717a42c45SSubhransu S. Prusty 
136817a42c45SSubhransu S. Prusty 	return 0;
136917a42c45SSubhransu S. Prusty }
137017a42c45SSubhransu S. Prusty 
137118382eadSSubhransu S. Prusty /*
137218382eadSSubhransu S. Prusty  * Parse all nodes and store the cvt/pin nids in array
137318382eadSSubhransu S. Prusty  * Add one time initialization for pin and cvt widgets
137418382eadSSubhransu S. Prusty  */
137517a42c45SSubhransu S. Prusty static int hdac_hdmi_parse_and_map_nid(struct hdac_ext_device *edev,
137617a42c45SSubhransu S. Prusty 		struct snd_soc_dai_driver **dais, int *num_dais)
137718382eadSSubhransu S. Prusty {
137818382eadSSubhransu S. Prusty 	hda_nid_t nid;
13793c83ac23SSudip Mukherjee 	int i, num_nodes;
138018382eadSSubhransu S. Prusty 	struct hdac_device *hdac = &edev->hdac;
138118382eadSSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = edev->private_data;
138215b91447SSubhransu S. Prusty 	int ret;
138318382eadSSubhransu S. Prusty 
1384211caab7SSubhransu S. Prusty 	hdac_hdmi_skl_enable_all_pins(hdac);
1385211caab7SSubhransu S. Prusty 	hdac_hdmi_skl_enable_dp12(hdac);
1386211caab7SSubhransu S. Prusty 
13873c83ac23SSudip Mukherjee 	num_nodes = snd_hdac_get_sub_nodes(hdac, hdac->afg, &nid);
1388541140d4SSubhransu S. Prusty 	if (!nid || num_nodes <= 0) {
138918382eadSSubhransu S. Prusty 		dev_warn(&hdac->dev, "HDMI: failed to get afg sub nodes\n");
139018382eadSSubhransu S. Prusty 		return -EINVAL;
139118382eadSSubhransu S. Prusty 	}
139218382eadSSubhransu S. Prusty 
13933c83ac23SSudip Mukherjee 	hdac->num_nodes = num_nodes;
139418382eadSSubhransu S. Prusty 	hdac->start_nid = nid;
139518382eadSSubhransu S. Prusty 
139618382eadSSubhransu S. Prusty 	for (i = 0; i < hdac->num_nodes; i++, nid++) {
139718382eadSSubhransu S. Prusty 		unsigned int caps;
139818382eadSSubhransu S. Prusty 		unsigned int type;
139918382eadSSubhransu S. Prusty 
140018382eadSSubhransu S. Prusty 		caps = get_wcaps(hdac, nid);
140118382eadSSubhransu S. Prusty 		type = get_wcaps_type(caps);
140218382eadSSubhransu S. Prusty 
140318382eadSSubhransu S. Prusty 		if (!(caps & AC_WCAP_DIGITAL))
140418382eadSSubhransu S. Prusty 			continue;
140518382eadSSubhransu S. Prusty 
140618382eadSSubhransu S. Prusty 		switch (type) {
140718382eadSSubhransu S. Prusty 
140818382eadSSubhransu S. Prusty 		case AC_WID_AUD_OUT:
140915b91447SSubhransu S. Prusty 			ret = hdac_hdmi_add_cvt(edev, nid);
141015b91447SSubhransu S. Prusty 			if (ret < 0)
141115b91447SSubhransu S. Prusty 				return ret;
141218382eadSSubhransu S. Prusty 			break;
141318382eadSSubhransu S. Prusty 
141418382eadSSubhransu S. Prusty 		case AC_WID_PIN:
141515b91447SSubhransu S. Prusty 			ret = hdac_hdmi_add_pin(edev, nid);
141615b91447SSubhransu S. Prusty 			if (ret < 0)
141715b91447SSubhransu S. Prusty 				return ret;
141818382eadSSubhransu S. Prusty 			break;
141918382eadSSubhransu S. Prusty 		}
142018382eadSSubhransu S. Prusty 	}
142118382eadSSubhransu S. Prusty 
142218382eadSSubhransu S. Prusty 	hdac->end_nid = nid;
142318382eadSSubhransu S. Prusty 
142415b91447SSubhransu S. Prusty 	if (!hdmi->num_pin || !hdmi->num_cvt)
142518382eadSSubhransu S. Prusty 		return -EIO;
142618382eadSSubhransu S. Prusty 
142717a42c45SSubhransu S. Prusty 	ret = hdac_hdmi_create_dais(hdac, dais, hdmi, hdmi->num_cvt);
142817a42c45SSubhransu S. Prusty 	if (ret) {
142917a42c45SSubhransu S. Prusty 		dev_err(&hdac->dev, "Failed to create dais with err: %d\n",
143017a42c45SSubhransu S. Prusty 							ret);
143117a42c45SSubhransu S. Prusty 		return ret;
143217a42c45SSubhransu S. Prusty 	}
143317a42c45SSubhransu S. Prusty 
143417a42c45SSubhransu S. Prusty 	*num_dais = hdmi->num_cvt;
143517a42c45SSubhransu S. Prusty 
143615b91447SSubhransu S. Prusty 	return hdac_hdmi_init_dai_map(edev);
143718382eadSSubhransu S. Prusty }
143818382eadSSubhransu S. Prusty 
1439f9318941SPandiyan, Dhinakaran static void hdac_hdmi_eld_notify_cb(void *aptr, int port, int pipe)
1440b8a54545SSubhransu S. Prusty {
1441b8a54545SSubhransu S. Prusty 	struct hdac_ext_device *edev = aptr;
1442b8a54545SSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = edev->private_data;
1443754695f9SJeeja KP 	struct hdac_hdmi_pin *pin = NULL;
1444754695f9SJeeja KP 	struct hdac_hdmi_port *hport = NULL;
1445b8a54545SSubhransu S. Prusty 	struct snd_soc_codec *codec = edev->scodec;
14462acd8309SJeeja KP 	int i;
1447b8a54545SSubhransu S. Prusty 
1448b8a54545SSubhransu S. Prusty 	/* Don't know how this mapping is derived */
1449b8a54545SSubhransu S. Prusty 	hda_nid_t pin_nid = port + 0x04;
1450b8a54545SSubhransu S. Prusty 
1451754695f9SJeeja KP 	dev_dbg(&edev->hdac.dev, "%s: for pin:%d port=%d\n", __func__,
1452754695f9SJeeja KP 							pin_nid, pipe);
1453b8a54545SSubhransu S. Prusty 
1454b8a54545SSubhransu S. Prusty 	/*
1455b8a54545SSubhransu S. Prusty 	 * skip notification during system suspend (but not in runtime PM);
1456b8a54545SSubhransu S. Prusty 	 * the state will be updated at resume. Also since the ELD and
1457b8a54545SSubhransu S. Prusty 	 * connection states are updated in anyway at the end of the resume,
1458b8a54545SSubhransu S. Prusty 	 * we can skip it when received during PM process.
1459b8a54545SSubhransu S. Prusty 	 */
1460b8a54545SSubhransu S. Prusty 	if (snd_power_get_state(codec->component.card->snd_card) !=
1461b8a54545SSubhransu S. Prusty 			SNDRV_CTL_POWER_D0)
1462b8a54545SSubhransu S. Prusty 		return;
1463b8a54545SSubhransu S. Prusty 
1464b8a54545SSubhransu S. Prusty 	if (atomic_read(&edev->hdac.in_pm))
1465b8a54545SSubhransu S. Prusty 		return;
1466b8a54545SSubhransu S. Prusty 
1467b8a54545SSubhransu S. Prusty 	list_for_each_entry(pin, &hdmi->pin_list, head) {
1468754695f9SJeeja KP 		if (pin->nid != pin_nid)
1469754695f9SJeeja KP 			continue;
1470754695f9SJeeja KP 
1471754695f9SJeeja KP 		/* In case of non MST pin, pipe is -1 */
1472754695f9SJeeja KP 		if (pipe == -1) {
14732acd8309SJeeja KP 			pin->mst_capable = false;
1474754695f9SJeeja KP 			/* if not MST, default is port[0] */
1475754695f9SJeeja KP 			hport = &pin->ports[0];
14762acd8309SJeeja KP 			goto out;
14772acd8309SJeeja KP 		} else {
14782acd8309SJeeja KP 			for (i = 0; i < pin->num_ports; i++) {
14792acd8309SJeeja KP 				pin->mst_capable = true;
14802acd8309SJeeja KP 				if (pin->ports[i].id == pipe) {
14812acd8309SJeeja KP 					hport = &pin->ports[i];
14822acd8309SJeeja KP 					goto out;
14832acd8309SJeeja KP 				}
14842acd8309SJeeja KP 			}
1485b8a54545SSubhransu S. Prusty 		}
1486b8a54545SSubhransu S. Prusty 	}
1487b8a54545SSubhransu S. Prusty 
14882acd8309SJeeja KP out:
14892acd8309SJeeja KP 	if (pin && hport)
1490754695f9SJeeja KP 		hdac_hdmi_present_sense(pin, hport);
1491754695f9SJeeja KP }
1492754695f9SJeeja KP 
1493b8a54545SSubhransu S. Prusty static struct i915_audio_component_audio_ops aops = {
1494b8a54545SSubhransu S. Prusty 	.pin_eld_notify	= hdac_hdmi_eld_notify_cb,
1495b8a54545SSubhransu S. Prusty };
1496b8a54545SSubhransu S. Prusty 
14972889099eSSubhransu S. Prusty static struct snd_pcm *hdac_hdmi_get_pcm_from_id(struct snd_soc_card *card,
14982889099eSSubhransu S. Prusty 						int device)
14992889099eSSubhransu S. Prusty {
15002889099eSSubhransu S. Prusty 	struct snd_soc_pcm_runtime *rtd;
15012889099eSSubhransu S. Prusty 
15022889099eSSubhransu S. Prusty 	list_for_each_entry(rtd, &card->rtd_list, list) {
15032889099eSSubhransu S. Prusty 		if (rtd->pcm && (rtd->pcm->device == device))
15042889099eSSubhransu S. Prusty 			return rtd->pcm;
15052889099eSSubhransu S. Prusty 	}
15062889099eSSubhransu S. Prusty 
15072889099eSSubhransu S. Prusty 	return NULL;
15082889099eSSubhransu S. Prusty }
15092889099eSSubhransu S. Prusty 
15104a3478deSJeeja KP int hdac_hdmi_jack_init(struct snd_soc_dai *dai, int device)
15114a3478deSJeeja KP {
15124a3478deSJeeja KP 	char jack_name[NAME_SIZE];
15134a3478deSJeeja KP 	struct snd_soc_codec *codec = dai->codec;
15144a3478deSJeeja KP 	struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec);
15154a3478deSJeeja KP 	struct snd_soc_dapm_context *dapm =
15164a3478deSJeeja KP 		snd_soc_component_get_dapm(&codec->component);
15174a3478deSJeeja KP 	struct hdac_hdmi_priv *hdmi = edev->private_data;
15184a3478deSJeeja KP 	struct hdac_hdmi_pcm *pcm;
15192889099eSSubhransu S. Prusty 	struct snd_pcm *snd_pcm;
15202889099eSSubhransu S. Prusty 	int err;
15214a3478deSJeeja KP 
15224a3478deSJeeja KP 	/*
15234a3478deSJeeja KP 	 * this is a new PCM device, create new pcm and
15244a3478deSJeeja KP 	 * add to the pcm list
15254a3478deSJeeja KP 	 */
15264a3478deSJeeja KP 	pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
15274a3478deSJeeja KP 	if (!pcm)
15284a3478deSJeeja KP 		return -ENOMEM;
15294a3478deSJeeja KP 	pcm->pcm_id = device;
15304a3478deSJeeja KP 	pcm->cvt = hdmi->dai_map[dai->id].cvt;
1531ab1eea19SJeeja KP 	mutex_init(&pcm->lock);
15324a3478deSJeeja KP 
15332889099eSSubhransu S. Prusty 	snd_pcm = hdac_hdmi_get_pcm_from_id(dai->component->card, device);
15342889099eSSubhransu S. Prusty 	if (snd_pcm) {
15352889099eSSubhransu S. Prusty 		err = snd_hdac_add_chmap_ctls(snd_pcm, device, &hdmi->chmap);
15362889099eSSubhransu S. Prusty 		if (err < 0) {
15372889099eSSubhransu S. Prusty 			dev_err(&edev->hdac.dev,
15382889099eSSubhransu S. Prusty 				"chmap control add failed with err: %d for pcm: %d\n",
15392889099eSSubhransu S. Prusty 				err, device);
15402889099eSSubhransu S. Prusty 			kfree(pcm);
15412889099eSSubhransu S. Prusty 			return err;
15422889099eSSubhransu S. Prusty 		}
15432889099eSSubhransu S. Prusty 	}
15442889099eSSubhransu S. Prusty 
15454a3478deSJeeja KP 	list_add_tail(&pcm->head, &hdmi->pcm_list);
15464a3478deSJeeja KP 
15474a3478deSJeeja KP 	sprintf(jack_name, "HDMI/DP, pcm=%d Jack", device);
15484a3478deSJeeja KP 
15494a3478deSJeeja KP 	return snd_jack_new(dapm->card->snd_card, jack_name,
15504a3478deSJeeja KP 		SND_JACK_AVOUT,	&pcm->jack, true, false);
15514a3478deSJeeja KP }
15524a3478deSJeeja KP EXPORT_SYMBOL_GPL(hdac_hdmi_jack_init);
15534a3478deSJeeja KP 
155418382eadSSubhransu S. Prusty static int hdmi_codec_probe(struct snd_soc_codec *codec)
155518382eadSSubhransu S. Prusty {
155618382eadSSubhransu S. Prusty 	struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec);
155718382eadSSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = edev->private_data;
155818382eadSSubhransu S. Prusty 	struct snd_soc_dapm_context *dapm =
155918382eadSSubhransu S. Prusty 		snd_soc_component_get_dapm(&codec->component);
1560b8a54545SSubhransu S. Prusty 	struct hdac_hdmi_pin *pin;
1561b2047e99SVinod Koul 	struct hdac_ext_link *hlink = NULL;
1562754695f9SJeeja KP 	int ret, i;
156318382eadSSubhransu S. Prusty 
156418382eadSSubhransu S. Prusty 	edev->scodec = codec;
156518382eadSSubhransu S. Prusty 
1566b2047e99SVinod Koul 	/*
1567b2047e99SVinod Koul 	 * hold the ref while we probe, also no need to drop the ref on
1568b2047e99SVinod Koul 	 * exit, we call pm_runtime_suspend() so that will do for us
1569b2047e99SVinod Koul 	 */
1570b2047e99SVinod Koul 	hlink = snd_hdac_ext_bus_get_link(edev->ebus, dev_name(&edev->hdac.dev));
1571500e06b9SVinod Koul 	if (!hlink) {
1572500e06b9SVinod Koul 		dev_err(&edev->hdac.dev, "hdac link not found\n");
1573500e06b9SVinod Koul 		return -EIO;
1574500e06b9SVinod Koul 	}
1575500e06b9SVinod Koul 
1576b2047e99SVinod Koul 	snd_hdac_ext_bus_link_get(edev->ebus, hlink);
1577b2047e99SVinod Koul 
157879f4e922SSubhransu S. Prusty 	ret = create_fill_widget_route_map(dapm);
157979f4e922SSubhransu S. Prusty 	if (ret < 0)
158079f4e922SSubhransu S. Prusty 		return ret;
158118382eadSSubhransu S. Prusty 
1582b8a54545SSubhransu S. Prusty 	aops.audio_ptr = edev;
1583b8a54545SSubhransu S. Prusty 	ret = snd_hdac_i915_register_notifier(&aops);
1584b8a54545SSubhransu S. Prusty 	if (ret < 0) {
1585b8a54545SSubhransu S. Prusty 		dev_err(&edev->hdac.dev, "notifier register failed: err: %d\n",
1586b8a54545SSubhransu S. Prusty 				ret);
1587b8a54545SSubhransu S. Prusty 		return ret;
1588b8a54545SSubhransu S. Prusty 	}
1589b8a54545SSubhransu S. Prusty 
1590b8a54545SSubhransu S. Prusty 	list_for_each_entry(pin, &hdmi->pin_list, head)
1591754695f9SJeeja KP 		for (i = 0; i < pin->num_ports; i++)
1592754695f9SJeeja KP 			hdac_hdmi_present_sense(pin, &pin->ports[i]);
1593b8a54545SSubhransu S. Prusty 
159418382eadSSubhransu S. Prusty 	/* Imp: Store the card pointer in hda_codec */
159518382eadSSubhransu S. Prusty 	edev->card = dapm->card->snd_card;
159618382eadSSubhransu S. Prusty 
1597e342ac08SSubhransu S. Prusty 	/*
1598e342ac08SSubhransu S. Prusty 	 * hdac_device core already sets the state to active and calls
1599e342ac08SSubhransu S. Prusty 	 * get_noresume. So enable runtime and set the device to suspend.
1600e342ac08SSubhransu S. Prusty 	 */
1601e342ac08SSubhransu S. Prusty 	pm_runtime_enable(&edev->hdac.dev);
1602e342ac08SSubhransu S. Prusty 	pm_runtime_put(&edev->hdac.dev);
1603e342ac08SSubhransu S. Prusty 	pm_runtime_suspend(&edev->hdac.dev);
1604e342ac08SSubhransu S. Prusty 
1605e342ac08SSubhransu S. Prusty 	return 0;
1606e342ac08SSubhransu S. Prusty }
1607e342ac08SSubhransu S. Prusty 
1608e342ac08SSubhransu S. Prusty static int hdmi_codec_remove(struct snd_soc_codec *codec)
1609e342ac08SSubhransu S. Prusty {
1610e342ac08SSubhransu S. Prusty 	struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec);
1611e342ac08SSubhransu S. Prusty 
1612e342ac08SSubhransu S. Prusty 	pm_runtime_disable(&edev->hdac.dev);
161318382eadSSubhransu S. Prusty 	return 0;
161418382eadSSubhransu S. Prusty }
161518382eadSSubhransu S. Prusty 
1616571d5078SJeeja KP #ifdef CONFIG_PM
16171b377ccdSSubhransu S. Prusty static int hdmi_codec_prepare(struct device *dev)
16181b377ccdSSubhransu S. Prusty {
16191b377ccdSSubhransu S. Prusty 	struct hdac_ext_device *edev = to_hda_ext_device(dev);
16201b377ccdSSubhransu S. Prusty 	struct hdac_device *hdac = &edev->hdac;
16211b377ccdSSubhransu S. Prusty 
16221b377ccdSSubhransu S. Prusty 	pm_runtime_get_sync(&edev->hdac.dev);
16231b377ccdSSubhransu S. Prusty 
16241b377ccdSSubhransu S. Prusty 	/*
16251b377ccdSSubhransu S. Prusty 	 * Power down afg.
16261b377ccdSSubhransu S. Prusty 	 * codec_read is preferred over codec_write to set the power state.
16271b377ccdSSubhransu S. Prusty 	 * This way verb is send to set the power state and response
16281b377ccdSSubhransu S. Prusty 	 * is received. So setting power state is ensured without using loop
16291b377ccdSSubhransu S. Prusty 	 * to read the state.
16301b377ccdSSubhransu S. Prusty 	 */
16311b377ccdSSubhransu S. Prusty 	snd_hdac_codec_read(hdac, hdac->afg, 0,	AC_VERB_SET_POWER_STATE,
16321b377ccdSSubhransu S. Prusty 							AC_PWRST_D3);
16331b377ccdSSubhransu S. Prusty 
16341b377ccdSSubhransu S. Prusty 	return 0;
16351b377ccdSSubhransu S. Prusty }
16361b377ccdSSubhransu S. Prusty 
16370fee1798SSubhransu S. Prusty static void hdmi_codec_complete(struct device *dev)
1638571d5078SJeeja KP {
16390fee1798SSubhransu S. Prusty 	struct hdac_ext_device *edev = to_hda_ext_device(dev);
1640571d5078SJeeja KP 	struct hdac_hdmi_priv *hdmi = edev->private_data;
1641571d5078SJeeja KP 	struct hdac_hdmi_pin *pin;
1642571d5078SJeeja KP 	struct hdac_device *hdac = &edev->hdac;
1643754695f9SJeeja KP 	int i;
16441b377ccdSSubhransu S. Prusty 
16451b377ccdSSubhransu S. Prusty 	/* Power up afg */
16461b377ccdSSubhransu S. Prusty 	snd_hdac_codec_read(hdac, hdac->afg, 0,	AC_VERB_SET_POWER_STATE,
16471b377ccdSSubhransu S. Prusty 							AC_PWRST_D0);
1648571d5078SJeeja KP 
1649571d5078SJeeja KP 	hdac_hdmi_skl_enable_all_pins(&edev->hdac);
1650571d5078SJeeja KP 	hdac_hdmi_skl_enable_dp12(&edev->hdac);
1651571d5078SJeeja KP 
1652571d5078SJeeja KP 	/*
1653571d5078SJeeja KP 	 * As the ELD notify callback request is not entertained while the
1654571d5078SJeeja KP 	 * device is in suspend state. Need to manually check detection of
1655571d5078SJeeja KP 	 * all pins here.
1656571d5078SJeeja KP 	 */
1657571d5078SJeeja KP 	list_for_each_entry(pin, &hdmi->pin_list, head)
1658754695f9SJeeja KP 		for (i = 0; i < pin->num_ports; i++)
1659754695f9SJeeja KP 			hdac_hdmi_present_sense(pin, &pin->ports[i]);
1660571d5078SJeeja KP 
16611b377ccdSSubhransu S. Prusty 	pm_runtime_put_sync(&edev->hdac.dev);
1662571d5078SJeeja KP }
1663571d5078SJeeja KP #else
16641b377ccdSSubhransu S. Prusty #define hdmi_codec_prepare NULL
16650fee1798SSubhransu S. Prusty #define hdmi_codec_complete NULL
1666571d5078SJeeja KP #endif
1667571d5078SJeeja KP 
166818382eadSSubhransu S. Prusty static struct snd_soc_codec_driver hdmi_hda_codec = {
166918382eadSSubhransu S. Prusty 	.probe		= hdmi_codec_probe,
1670e342ac08SSubhransu S. Prusty 	.remove		= hdmi_codec_remove,
167118382eadSSubhransu S. Prusty 	.idle_bias_off	= true,
167218382eadSSubhransu S. Prusty };
167318382eadSSubhransu S. Prusty 
16742889099eSSubhransu S. Prusty static void hdac_hdmi_get_chmap(struct hdac_device *hdac, int pcm_idx,
16752889099eSSubhransu S. Prusty 					unsigned char *chmap)
16762889099eSSubhransu S. Prusty {
16772889099eSSubhransu S. Prusty 	struct hdac_ext_device *edev = to_ehdac_device(hdac);
16782889099eSSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = edev->private_data;
16792889099eSSubhransu S. Prusty 	struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
16802889099eSSubhransu S. Prusty 
1681ab1eea19SJeeja KP 	memcpy(chmap, pcm->chmap, ARRAY_SIZE(pcm->chmap));
16822889099eSSubhransu S. Prusty }
16832889099eSSubhransu S. Prusty 
16842889099eSSubhransu S. Prusty static void hdac_hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx,
16852889099eSSubhransu S. Prusty 				unsigned char *chmap, int prepared)
16862889099eSSubhransu S. Prusty {
16872889099eSSubhransu S. Prusty 	struct hdac_ext_device *edev = to_ehdac_device(hdac);
16882889099eSSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = edev->private_data;
16892889099eSSubhransu S. Prusty 	struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
1690754695f9SJeeja KP 	struct hdac_hdmi_port *port = pcm->port;
16912889099eSSubhransu S. Prusty 
1692ab1eea19SJeeja KP 	mutex_lock(&pcm->lock);
1693ab1eea19SJeeja KP 	pcm->chmap_set = true;
1694ab1eea19SJeeja KP 	memcpy(pcm->chmap, chmap, ARRAY_SIZE(pcm->chmap));
16952889099eSSubhransu S. Prusty 	if (prepared)
1696754695f9SJeeja KP 		hdac_hdmi_setup_audio_infoframe(edev, pcm, port);
1697ab1eea19SJeeja KP 	mutex_unlock(&pcm->lock);
16982889099eSSubhransu S. Prusty }
16992889099eSSubhransu S. Prusty 
17002889099eSSubhransu S. Prusty static bool is_hdac_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx)
17012889099eSSubhransu S. Prusty {
17022889099eSSubhransu S. Prusty 	struct hdac_ext_device *edev = to_ehdac_device(hdac);
17032889099eSSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = edev->private_data;
17042889099eSSubhransu S. Prusty 	struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
1705754695f9SJeeja KP 	struct hdac_hdmi_port *port = pcm->port;
17062889099eSSubhransu S. Prusty 
1707754695f9SJeeja KP 	return port ? true:false;
17082889099eSSubhransu S. Prusty }
17092889099eSSubhransu S. Prusty 
17102889099eSSubhransu S. Prusty static int hdac_hdmi_get_spk_alloc(struct hdac_device *hdac, int pcm_idx)
17112889099eSSubhransu S. Prusty {
17122889099eSSubhransu S. Prusty 	struct hdac_ext_device *edev = to_ehdac_device(hdac);
17132889099eSSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = edev->private_data;
17142889099eSSubhransu S. Prusty 	struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
1715754695f9SJeeja KP 	struct hdac_hdmi_port *port = pcm->port;
17162889099eSSubhransu S. Prusty 
1717754695f9SJeeja KP 	if (!port || !port->eld.eld_valid)
17182889099eSSubhransu S. Prusty 		return 0;
17192889099eSSubhransu S. Prusty 
1720754695f9SJeeja KP 	return port->eld.info.spk_alloc;
17212889099eSSubhransu S. Prusty }
17222889099eSSubhransu S. Prusty 
172318382eadSSubhransu S. Prusty static int hdac_hdmi_dev_probe(struct hdac_ext_device *edev)
172418382eadSSubhransu S. Prusty {
172518382eadSSubhransu S. Prusty 	struct hdac_device *codec = &edev->hdac;
172618382eadSSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi_priv;
172717a42c45SSubhransu S. Prusty 	struct snd_soc_dai_driver *hdmi_dais = NULL;
1728b2047e99SVinod Koul 	struct hdac_ext_link *hlink = NULL;
172917a42c45SSubhransu S. Prusty 	int num_dais = 0;
173018382eadSSubhransu S. Prusty 	int ret = 0;
173118382eadSSubhransu S. Prusty 
1732b2047e99SVinod Koul 	/* hold the ref while we probe */
1733b2047e99SVinod Koul 	hlink = snd_hdac_ext_bus_get_link(edev->ebus, dev_name(&edev->hdac.dev));
1734500e06b9SVinod Koul 	if (!hlink) {
1735500e06b9SVinod Koul 		dev_err(&edev->hdac.dev, "hdac link not found\n");
1736500e06b9SVinod Koul 		return -EIO;
1737500e06b9SVinod Koul 	}
1738500e06b9SVinod Koul 
1739b2047e99SVinod Koul 	snd_hdac_ext_bus_link_get(edev->ebus, hlink);
1740b2047e99SVinod Koul 
174118382eadSSubhransu S. Prusty 	hdmi_priv = devm_kzalloc(&codec->dev, sizeof(*hdmi_priv), GFP_KERNEL);
174218382eadSSubhransu S. Prusty 	if (hdmi_priv == NULL)
174318382eadSSubhransu S. Prusty 		return -ENOMEM;
174418382eadSSubhransu S. Prusty 
174518382eadSSubhransu S. Prusty 	edev->private_data = hdmi_priv;
1746bcced704SSubhransu S. Prusty 	snd_hdac_register_chmap_ops(codec, &hdmi_priv->chmap);
17472889099eSSubhransu S. Prusty 	hdmi_priv->chmap.ops.get_chmap = hdac_hdmi_get_chmap;
17482889099eSSubhransu S. Prusty 	hdmi_priv->chmap.ops.set_chmap = hdac_hdmi_set_chmap;
17492889099eSSubhransu S. Prusty 	hdmi_priv->chmap.ops.is_pcm_attached = is_hdac_hdmi_pcm_attached;
17502889099eSSubhransu S. Prusty 	hdmi_priv->chmap.ops.get_spk_alloc = hdac_hdmi_get_spk_alloc;
175118382eadSSubhransu S. Prusty 
175218382eadSSubhransu S. Prusty 	dev_set_drvdata(&codec->dev, edev);
175318382eadSSubhransu S. Prusty 
175415b91447SSubhransu S. Prusty 	INIT_LIST_HEAD(&hdmi_priv->pin_list);
175515b91447SSubhransu S. Prusty 	INIT_LIST_HEAD(&hdmi_priv->cvt_list);
17564a3478deSJeeja KP 	INIT_LIST_HEAD(&hdmi_priv->pcm_list);
17574a3478deSJeeja KP 	mutex_init(&hdmi_priv->pin_mutex);
175815b91447SSubhransu S. Prusty 
1759aeaccef0SRamesh Babu 	/*
1760aeaccef0SRamesh Babu 	 * Turned off in the runtime_suspend during the first explicit
1761aeaccef0SRamesh Babu 	 * pm_runtime_suspend call.
1762aeaccef0SRamesh Babu 	 */
1763aeaccef0SRamesh Babu 	ret = snd_hdac_display_power(edev->hdac.bus, true);
1764aeaccef0SRamesh Babu 	if (ret < 0) {
1765aeaccef0SRamesh Babu 		dev_err(&edev->hdac.dev,
1766aeaccef0SRamesh Babu 			"Cannot turn on display power on i915 err: %d\n",
1767aeaccef0SRamesh Babu 			ret);
1768aeaccef0SRamesh Babu 		return ret;
1769aeaccef0SRamesh Babu 	}
1770aeaccef0SRamesh Babu 
177117a42c45SSubhransu S. Prusty 	ret = hdac_hdmi_parse_and_map_nid(edev, &hdmi_dais, &num_dais);
177217a42c45SSubhransu S. Prusty 	if (ret < 0) {
177317a42c45SSubhransu S. Prusty 		dev_err(&codec->dev,
177417a42c45SSubhransu S. Prusty 			"Failed in parse and map nid with err: %d\n", ret);
177518382eadSSubhransu S. Prusty 		return ret;
177617a42c45SSubhransu S. Prusty 	}
177718382eadSSubhransu S. Prusty 
177818382eadSSubhransu S. Prusty 	/* ASoC specific initialization */
1779b2047e99SVinod Koul 	ret = snd_soc_register_codec(&codec->dev, &hdmi_hda_codec,
178017a42c45SSubhransu S. Prusty 					hdmi_dais, num_dais);
1781b2047e99SVinod Koul 
1782b2047e99SVinod Koul 	snd_hdac_ext_bus_link_put(edev->ebus, hlink);
1783b2047e99SVinod Koul 
1784b2047e99SVinod Koul 	return ret;
178518382eadSSubhransu S. Prusty }
178618382eadSSubhransu S. Prusty 
178718382eadSSubhransu S. Prusty static int hdac_hdmi_dev_remove(struct hdac_ext_device *edev)
178818382eadSSubhransu S. Prusty {
178915b91447SSubhransu S. Prusty 	struct hdac_hdmi_priv *hdmi = edev->private_data;
179015b91447SSubhransu S. Prusty 	struct hdac_hdmi_pin *pin, *pin_next;
179115b91447SSubhransu S. Prusty 	struct hdac_hdmi_cvt *cvt, *cvt_next;
17924a3478deSJeeja KP 	struct hdac_hdmi_pcm *pcm, *pcm_next;
1793754695f9SJeeja KP 	int i;
179415b91447SSubhransu S. Prusty 
179518382eadSSubhransu S. Prusty 	snd_soc_unregister_codec(&edev->hdac.dev);
179618382eadSSubhransu S. Prusty 
17974a3478deSJeeja KP 	list_for_each_entry_safe(pcm, pcm_next, &hdmi->pcm_list, head) {
17984a3478deSJeeja KP 		pcm->cvt = NULL;
1799754695f9SJeeja KP 		pcm->port = NULL;
18004a3478deSJeeja KP 		list_del(&pcm->head);
18014a3478deSJeeja KP 		kfree(pcm);
18024a3478deSJeeja KP 	}
18034a3478deSJeeja KP 
180415b91447SSubhransu S. Prusty 	list_for_each_entry_safe(cvt, cvt_next, &hdmi->cvt_list, head) {
180515b91447SSubhransu S. Prusty 		list_del(&cvt->head);
18064a3478deSJeeja KP 		kfree(cvt->name);
180715b91447SSubhransu S. Prusty 		kfree(cvt);
180815b91447SSubhransu S. Prusty 	}
180915b91447SSubhransu S. Prusty 
181015b91447SSubhransu S. Prusty 	list_for_each_entry_safe(pin, pin_next, &hdmi->pin_list, head) {
1811754695f9SJeeja KP 		for (i = 0; i < pin->num_ports; i++)
1812754695f9SJeeja KP 			pin->ports[i].pin = NULL;
1813754695f9SJeeja KP 		kfree(pin->ports);
181415b91447SSubhransu S. Prusty 		list_del(&pin->head);
181515b91447SSubhransu S. Prusty 		kfree(pin);
181615b91447SSubhransu S. Prusty 	}
181715b91447SSubhransu S. Prusty 
181818382eadSSubhransu S. Prusty 	return 0;
181918382eadSSubhransu S. Prusty }
182018382eadSSubhransu S. Prusty 
1821e342ac08SSubhransu S. Prusty #ifdef CONFIG_PM
1822e342ac08SSubhransu S. Prusty static int hdac_hdmi_runtime_suspend(struct device *dev)
1823e342ac08SSubhransu S. Prusty {
1824e342ac08SSubhransu S. Prusty 	struct hdac_ext_device *edev = to_hda_ext_device(dev);
1825e342ac08SSubhransu S. Prusty 	struct hdac_device *hdac = &edev->hdac;
182607f083abSSubhransu S. Prusty 	struct hdac_bus *bus = hdac->bus;
1827b2047e99SVinod Koul 	struct hdac_ext_bus *ebus = hbus_to_ebus(bus);
1828b2047e99SVinod Koul 	struct hdac_ext_link *hlink = NULL;
182907f083abSSubhransu S. Prusty 	int err;
1830e342ac08SSubhransu S. Prusty 
1831e342ac08SSubhransu S. Prusty 	dev_dbg(dev, "Enter: %s\n", __func__);
1832e342ac08SSubhransu S. Prusty 
183307f083abSSubhransu S. Prusty 	/* controller may not have been initialized for the first time */
183407f083abSSubhransu S. Prusty 	if (!bus)
183507f083abSSubhransu S. Prusty 		return 0;
183607f083abSSubhransu S. Prusty 
18371b377ccdSSubhransu S. Prusty 	/*
18381b377ccdSSubhransu S. Prusty 	 * Power down afg.
18391b377ccdSSubhransu S. Prusty 	 * codec_read is preferred over codec_write to set the power state.
18401b377ccdSSubhransu S. Prusty 	 * This way verb is send to set the power state and response
18411b377ccdSSubhransu S. Prusty 	 * is received. So setting power state is ensured without using loop
18421b377ccdSSubhransu S. Prusty 	 * to read the state.
18431b377ccdSSubhransu S. Prusty 	 */
18441b377ccdSSubhransu S. Prusty 	snd_hdac_codec_read(hdac, hdac->afg, 0,	AC_VERB_SET_POWER_STATE,
18451b377ccdSSubhransu S. Prusty 							AC_PWRST_D3);
184607f083abSSubhransu S. Prusty 	err = snd_hdac_display_power(bus, false);
184707f083abSSubhransu S. Prusty 	if (err < 0) {
184807f083abSSubhransu S. Prusty 		dev_err(bus->dev, "Cannot turn on display power on i915\n");
184907f083abSSubhransu S. Prusty 		return err;
185007f083abSSubhransu S. Prusty 	}
185107f083abSSubhransu S. Prusty 
1852b2047e99SVinod Koul 	hlink = snd_hdac_ext_bus_get_link(ebus, dev_name(dev));
1853500e06b9SVinod Koul 	if (!hlink) {
1854500e06b9SVinod Koul 		dev_err(dev, "hdac link not found\n");
1855500e06b9SVinod Koul 		return -EIO;
1856500e06b9SVinod Koul 	}
1857500e06b9SVinod Koul 
1858b2047e99SVinod Koul 	snd_hdac_ext_bus_link_put(ebus, hlink);
1859b2047e99SVinod Koul 
1860e342ac08SSubhransu S. Prusty 	return 0;
1861e342ac08SSubhransu S. Prusty }
1862e342ac08SSubhransu S. Prusty 
1863e342ac08SSubhransu S. Prusty static int hdac_hdmi_runtime_resume(struct device *dev)
1864e342ac08SSubhransu S. Prusty {
1865e342ac08SSubhransu S. Prusty 	struct hdac_ext_device *edev = to_hda_ext_device(dev);
1866e342ac08SSubhransu S. Prusty 	struct hdac_device *hdac = &edev->hdac;
186707f083abSSubhransu S. Prusty 	struct hdac_bus *bus = hdac->bus;
1868b2047e99SVinod Koul 	struct hdac_ext_bus *ebus = hbus_to_ebus(bus);
1869b2047e99SVinod Koul 	struct hdac_ext_link *hlink = NULL;
187007f083abSSubhransu S. Prusty 	int err;
1871e342ac08SSubhransu S. Prusty 
1872e342ac08SSubhransu S. Prusty 	dev_dbg(dev, "Enter: %s\n", __func__);
1873e342ac08SSubhransu S. Prusty 
187407f083abSSubhransu S. Prusty 	/* controller may not have been initialized for the first time */
187507f083abSSubhransu S. Prusty 	if (!bus)
187607f083abSSubhransu S. Prusty 		return 0;
187707f083abSSubhransu S. Prusty 
1878b2047e99SVinod Koul 	hlink = snd_hdac_ext_bus_get_link(ebus, dev_name(dev));
1879500e06b9SVinod Koul 	if (!hlink) {
1880500e06b9SVinod Koul 		dev_err(dev, "hdac link not found\n");
1881500e06b9SVinod Koul 		return -EIO;
1882500e06b9SVinod Koul 	}
1883500e06b9SVinod Koul 
1884b2047e99SVinod Koul 	snd_hdac_ext_bus_link_get(ebus, hlink);
1885b2047e99SVinod Koul 
188607f083abSSubhransu S. Prusty 	err = snd_hdac_display_power(bus, true);
188707f083abSSubhransu S. Prusty 	if (err < 0) {
188807f083abSSubhransu S. Prusty 		dev_err(bus->dev, "Cannot turn on display power on i915\n");
188907f083abSSubhransu S. Prusty 		return err;
189007f083abSSubhransu S. Prusty 	}
189107f083abSSubhransu S. Prusty 
1892ab85f5b3SSubhransu S. Prusty 	hdac_hdmi_skl_enable_all_pins(&edev->hdac);
1893ab85f5b3SSubhransu S. Prusty 	hdac_hdmi_skl_enable_dp12(&edev->hdac);
1894ab85f5b3SSubhransu S. Prusty 
1895e342ac08SSubhransu S. Prusty 	/* Power up afg */
18961b377ccdSSubhransu S. Prusty 	snd_hdac_codec_read(hdac, hdac->afg, 0,	AC_VERB_SET_POWER_STATE,
18971b377ccdSSubhransu S. Prusty 							AC_PWRST_D0);
1898e342ac08SSubhransu S. Prusty 
1899e342ac08SSubhransu S. Prusty 	return 0;
1900e342ac08SSubhransu S. Prusty }
1901e342ac08SSubhransu S. Prusty #else
1902e342ac08SSubhransu S. Prusty #define hdac_hdmi_runtime_suspend NULL
1903e342ac08SSubhransu S. Prusty #define hdac_hdmi_runtime_resume NULL
1904e342ac08SSubhransu S. Prusty #endif
1905e342ac08SSubhransu S. Prusty 
1906e342ac08SSubhransu S. Prusty static const struct dev_pm_ops hdac_hdmi_pm = {
1907e342ac08SSubhransu S. Prusty 	SET_RUNTIME_PM_OPS(hdac_hdmi_runtime_suspend, hdac_hdmi_runtime_resume, NULL)
19081b377ccdSSubhransu S. Prusty 	.prepare = hdmi_codec_prepare,
19090fee1798SSubhransu S. Prusty 	.complete = hdmi_codec_complete,
1910e342ac08SSubhransu S. Prusty };
1911e342ac08SSubhransu S. Prusty 
191218382eadSSubhransu S. Prusty static const struct hda_device_id hdmi_list[] = {
191318382eadSSubhransu S. Prusty 	HDA_CODEC_EXT_ENTRY(0x80862809, 0x100000, "Skylake HDMI", 0),
1914e2304803SJeeja KP 	HDA_CODEC_EXT_ENTRY(0x8086280a, 0x100000, "Broxton HDMI", 0),
1915cc216887SShreyas NC 	HDA_CODEC_EXT_ENTRY(0x8086280b, 0x100000, "Kabylake HDMI", 0),
191618382eadSSubhransu S. Prusty 	{}
191718382eadSSubhransu S. Prusty };
191818382eadSSubhransu S. Prusty 
191918382eadSSubhransu S. Prusty MODULE_DEVICE_TABLE(hdaudio, hdmi_list);
192018382eadSSubhransu S. Prusty 
192118382eadSSubhransu S. Prusty static struct hdac_ext_driver hdmi_driver = {
192218382eadSSubhransu S. Prusty 	. hdac = {
192318382eadSSubhransu S. Prusty 		.driver = {
192418382eadSSubhransu S. Prusty 			.name   = "HDMI HDA Codec",
1925e342ac08SSubhransu S. Prusty 			.pm = &hdac_hdmi_pm,
192618382eadSSubhransu S. Prusty 		},
192718382eadSSubhransu S. Prusty 		.id_table       = hdmi_list,
192818382eadSSubhransu S. Prusty 	},
192918382eadSSubhransu S. Prusty 	.probe          = hdac_hdmi_dev_probe,
193018382eadSSubhransu S. Prusty 	.remove         = hdac_hdmi_dev_remove,
193118382eadSSubhransu S. Prusty };
193218382eadSSubhransu S. Prusty 
193318382eadSSubhransu S. Prusty static int __init hdmi_init(void)
193418382eadSSubhransu S. Prusty {
193518382eadSSubhransu S. Prusty 	return snd_hda_ext_driver_register(&hdmi_driver);
193618382eadSSubhransu S. Prusty }
193718382eadSSubhransu S. Prusty 
193818382eadSSubhransu S. Prusty static void __exit hdmi_exit(void)
193918382eadSSubhransu S. Prusty {
194018382eadSSubhransu S. Prusty 	snd_hda_ext_driver_unregister(&hdmi_driver);
194118382eadSSubhransu S. Prusty }
194218382eadSSubhransu S. Prusty 
194318382eadSSubhransu S. Prusty module_init(hdmi_init);
194418382eadSSubhransu S. Prusty module_exit(hdmi_exit);
194518382eadSSubhransu S. Prusty 
194618382eadSSubhransu S. Prusty MODULE_LICENSE("GPL v2");
194718382eadSSubhransu S. Prusty MODULE_DESCRIPTION("HDMI HD codec");
194818382eadSSubhransu S. Prusty MODULE_AUTHOR("Samreen Nilofer<samreen.nilofer@intel.com>");
194918382eadSSubhransu S. Prusty MODULE_AUTHOR("Subhransu S. Prusty<subhransu.s.prusty@intel.com>");
1950