blob: 1f57126708e76147115ffe2fe2fe7bc77450022c [file] [log] [blame]
Thomas Gleixner8e8e69d2019-05-29 07:17:59 -07001// SPDX-License-Identifier: GPL-2.0-only
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302/*
3 * hdac_hdmi.c - ASoc HDA-HDMI codec driver for Intel platforms
4 *
5 * Copyright (C) 2014-2015 Intel Corp
6 * Author: Samreen Nilofer <samreen.nilofer@intel.com>
7 * Subhransu S. Prusty <subhransu.s.prusty@intel.com>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 *
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053010 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 */
12#include <linux/init.h>
13#include <linux/delay.h>
14#include <linux/module.h>
15#include <linux/pm_runtime.h>
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +053016#include <linux/hdmi.h>
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +053017#include <drm/drm_edid.h>
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053018#include <sound/pcm_params.h>
Jeeja KP4a3478d2016-02-12 07:46:06 +053019#include <sound/jack.h>
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053020#include <sound/soc.h>
21#include <sound/hdaudio_ext.h>
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +053022#include <sound/hda_i915.h>
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +053023#include <sound/pcm_drm_eld.h>
Subhransu S. Prustybcced702016-04-14 10:07:30 +053024#include <sound/hda_chmap.h>
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053025#include "../../hda/local.h"
Jeeja KP4a3478d2016-02-12 07:46:06 +053026#include "hdac_hdmi.h"
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053027
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +053028#define NAME_SIZE 32
29
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +053030#define AMP_OUT_MUTE 0xb080
31#define AMP_OUT_UNMUTE 0xb000
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053032#define PIN_OUT (AC_PINCTL_OUT_EN)
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +053033
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053034#define HDA_MAX_CONNECTIONS 32
35
Subhransu S. Prusty148569f2016-02-12 07:46:07 +053036#define HDA_MAX_CVTS 3
Jeeja KP754695f2017-02-06 12:09:14 +053037#define HDA_MAX_PORTS 3
Subhransu S. Prusty148569f2016-02-12 07:46:07 +053038
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +053039#define ELD_MAX_SIZE 256
40#define ELD_FIXED_BYTES 20
41
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +053042#define ELD_VER_CEA_861D 2
43#define ELD_VER_PARTIAL 31
44#define ELD_MAX_MNL 16
45
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053046struct hdac_hdmi_cvt_params {
47 unsigned int channels_min;
48 unsigned int channels_max;
49 u32 rates;
50 u64 formats;
51 unsigned int maxbps;
52};
53
54struct hdac_hdmi_cvt {
Subhransu S. Prusty15b91442015-12-09 21:46:10 +053055 struct list_head head;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053056 hda_nid_t nid;
Jeeja KP4a3478d2016-02-12 07:46:06 +053057 const char *name;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053058 struct hdac_hdmi_cvt_params params;
59};
60
Subhransu S. Prustyb7756ed2016-04-14 10:07:28 +053061/* Currently only spk_alloc, more to be added */
62struct hdac_hdmi_parsed_eld {
63 u8 spk_alloc;
64};
65
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +053066struct hdac_hdmi_eld {
67 bool monitor_present;
68 bool eld_valid;
69 int eld_size;
70 char eld_buffer[ELD_MAX_SIZE];
Subhransu S. Prustyb7756ed2016-04-14 10:07:28 +053071 struct hdac_hdmi_parsed_eld info;
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +053072};
73
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053074struct hdac_hdmi_pin {
Subhransu S. Prusty15b91442015-12-09 21:46:10 +053075 struct list_head head;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053076 hda_nid_t nid;
Jeeja KP2acd8302017-02-06 12:09:18 +053077 bool mst_capable;
Jeeja KP754695f2017-02-06 12:09:14 +053078 struct hdac_hdmi_port *ports;
79 int num_ports;
Rakesh Ughreja3787a392018-06-01 22:53:49 -050080 struct hdac_device *hdev;
Jeeja KP754695f2017-02-06 12:09:14 +053081};
82
83struct hdac_hdmi_port {
Jeeja KPe0e5d3e2017-02-07 19:09:48 +053084 struct list_head head;
Jeeja KP754695f2017-02-06 12:09:14 +053085 int id;
86 struct hdac_hdmi_pin *pin;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053087 int num_mux_nids;
88 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +053089 struct hdac_hdmi_eld eld;
Jeeja KP0324e512017-02-07 19:09:55 +053090 const char *jack_pin;
91 struct snd_soc_dapm_context *dapm;
92 const char *output_pin;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053093};
94
Jeeja KP4a3478d2016-02-12 07:46:06 +053095struct hdac_hdmi_pcm {
96 struct list_head head;
97 int pcm_id;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +053098 struct list_head port_list;
Jeeja KP4a3478d2016-02-12 07:46:06 +053099 struct hdac_hdmi_cvt *cvt;
Jeeja KP62490012017-02-07 19:09:49 +0530100 struct snd_soc_jack *jack;
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530101 int stream_tag;
102 int channels;
103 int format;
Jeeja KPab1eea12017-01-24 21:49:05 +0530104 bool chmap_set;
105 unsigned char chmap[8]; /* ALSA API channel-map */
106 struct mutex lock;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530107 int jack_event;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530108};
109
Jeeja KP754695f2017-02-06 12:09:14 +0530110struct hdac_hdmi_dai_port_map {
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530111 int dai_id;
Jeeja KP754695f2017-02-06 12:09:14 +0530112 struct hdac_hdmi_port *port;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +0530113 struct hdac_hdmi_cvt *cvt;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530114};
115
Bard liao019033c2018-11-11 05:18:46 +0800116/*
117 * pin to port mapping table where the value indicate the pin number and
118 * the index indicate the port number with 1 base.
119 */
120static const int icl_pin2port_map[] = {0x4, 0x6, 0x8, 0xa, 0xb};
121
Pradeep Tewani5622bc92017-07-20 11:40:56 +0530122struct hdac_hdmi_drv_data {
123 unsigned int vendor_nid;
Bard liao019033c2018-11-11 05:18:46 +0800124 const int *port_map; /* pin to port mapping table */
125 int port_num;
Pradeep Tewani5622bc92017-07-20 11:40:56 +0530126};
127
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530128struct hdac_hdmi_priv {
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500129 struct hdac_device *hdev;
130 struct snd_soc_component *component;
131 struct snd_card *card;
Jeeja KP754695f2017-02-06 12:09:14 +0530132 struct hdac_hdmi_dai_port_map dai_map[HDA_MAX_CVTS];
Subhransu S. Prusty15b91442015-12-09 21:46:10 +0530133 struct list_head pin_list;
134 struct list_head cvt_list;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530135 struct list_head pcm_list;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +0530136 int num_pin;
137 int num_cvt;
Jeeja KP754695f2017-02-06 12:09:14 +0530138 int num_ports;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530139 struct mutex pin_mutex;
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530140 struct hdac_chmap chmap;
Pradeep Tewani5622bc92017-07-20 11:40:56 +0530141 struct hdac_hdmi_drv_data *drv_data;
Kuninori Morimoto1e02dac2017-12-20 01:48:13 +0000142 struct snd_soc_dai_driver *dai_drv;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530143};
144
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500145#define hdev_to_hdmi_priv(_hdev) dev_get_drvdata(&(_hdev)->dev)
Ughreja, Rakesh Ab09b1c32017-12-01 14:43:17 +0530146
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530147static struct hdac_hdmi_pcm *
148hdac_hdmi_get_pcm_from_cvt(struct hdac_hdmi_priv *hdmi,
149 struct hdac_hdmi_cvt *cvt)
150{
151 struct hdac_hdmi_pcm *pcm = NULL;
Jeeja KP1de777f2017-01-10 17:57:48 +0530152
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530153 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
154 if (pcm->cvt == cvt)
155 break;
156 }
157
158 return pcm;
159}
Jeeja KP1de777f2017-01-10 17:57:48 +0530160
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530161static void hdac_hdmi_jack_report(struct hdac_hdmi_pcm *pcm,
162 struct hdac_hdmi_port *port, bool is_connect)
163{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500164 struct hdac_device *hdev = port->pin->hdev;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530165
Jeeja KP0324e512017-02-07 19:09:55 +0530166 if (is_connect)
167 snd_soc_dapm_enable_pin(port->dapm, port->jack_pin);
168 else
169 snd_soc_dapm_disable_pin(port->dapm, port->jack_pin);
170
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530171 if (is_connect) {
172 /*
173 * Report Jack connect event when a device is connected
174 * for the first time where same PCM is attached to multiple
175 * ports.
176 */
177 if (pcm->jack_event == 0) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500178 dev_dbg(&hdev->dev,
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530179 "jack report for pcm=%d\n",
180 pcm->pcm_id);
Jeeja KP62490012017-02-07 19:09:49 +0530181 snd_soc_jack_report(pcm->jack, SND_JACK_AVOUT,
182 SND_JACK_AVOUT);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530183 }
184 pcm->jack_event++;
185 } else {
186 /*
187 * Report Jack disconnect event when a device is disconnected
188 * is the only last connected device when same PCM is attached
189 * to multiple ports.
190 */
191 if (pcm->jack_event == 1)
Jeeja KP62490012017-02-07 19:09:49 +0530192 snd_soc_jack_report(pcm->jack, 0, SND_JACK_AVOUT);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530193 if (pcm->jack_event > 0)
194 pcm->jack_event--;
195 }
Jeeja KP0324e512017-02-07 19:09:55 +0530196
197 snd_soc_dapm_sync(port->dapm);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530198}
199
Jeeja KPfc181b02017-02-07 19:09:45 +0530200/* MST supported verbs */
201/*
202 * Get the no devices that can be connected to a port on the Pin widget.
203 */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500204static int hdac_hdmi_get_port_len(struct hdac_device *hdev, hda_nid_t nid)
Jeeja KPfc181b02017-02-07 19:09:45 +0530205{
206 unsigned int caps;
207 unsigned int type, param;
208
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500209 caps = get_wcaps(hdev, nid);
Jeeja KPfc181b02017-02-07 19:09:45 +0530210 type = get_wcaps_type(caps);
211
212 if (!(caps & AC_WCAP_DIGITAL) || (type != AC_WID_PIN))
213 return 0;
214
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500215 param = snd_hdac_read_parm_uncached(hdev, nid, AC_PAR_DEVLIST_LEN);
Jeeja KPfc181b02017-02-07 19:09:45 +0530216 if (param == -1)
217 return param;
218
219 return param & AC_DEV_LIST_LEN_MASK;
220}
221
222/*
223 * Get the port entry select on the pin. Return the port entry
224 * id selected on the pin. Return 0 means the first port entry
225 * is selected or MST is not supported.
226 */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500227static int hdac_hdmi_port_select_get(struct hdac_device *hdev,
Jeeja KPfc181b02017-02-07 19:09:45 +0530228 struct hdac_hdmi_port *port)
229{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500230 return snd_hdac_codec_read(hdev, port->pin->nid,
Jeeja KPfc181b02017-02-07 19:09:45 +0530231 0, AC_VERB_GET_DEVICE_SEL, 0);
232}
233
234/*
235 * Sets the selected port entry for the configuring Pin widget verb.
236 * returns error if port set is not equal to port get otherwise success
237 */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500238static int hdac_hdmi_port_select_set(struct hdac_device *hdev,
Jeeja KPfc181b02017-02-07 19:09:45 +0530239 struct hdac_hdmi_port *port)
240{
241 int num_ports;
242
243 if (!port->pin->mst_capable)
244 return 0;
245
246 /* AC_PAR_DEVLIST_LEN is 0 based. */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500247 num_ports = hdac_hdmi_get_port_len(hdev, port->pin->nid);
Jeeja KPfc181b02017-02-07 19:09:45 +0530248 if (num_ports < 0)
249 return -EIO;
250 /*
251 * Device List Length is a 0 based integer value indicating the
252 * number of sink device that a MST Pin Widget can support.
253 */
254 if (num_ports + 1 < port->id)
255 return 0;
256
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500257 snd_hdac_codec_write(hdev, port->pin->nid, 0,
Jeeja KPfc181b02017-02-07 19:09:45 +0530258 AC_VERB_SET_DEVICE_SEL, port->id);
259
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500260 if (port->id != hdac_hdmi_port_select_get(hdev, port))
Jeeja KPfc181b02017-02-07 19:09:45 +0530261 return -EIO;
262
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500263 dev_dbg(&hdev->dev, "Selected the port=%d\n", port->id);
Jeeja KPfc181b02017-02-07 19:09:45 +0530264
265 return 0;
266}
267
Subhransu S. Prusty28890992016-04-14 10:07:34 +0530268static struct hdac_hdmi_pcm *get_hdmi_pcm_from_id(struct hdac_hdmi_priv *hdmi,
269 int pcm_idx)
270{
271 struct hdac_hdmi_pcm *pcm;
272
273 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
274 if (pcm->pcm_id == pcm_idx)
275 return pcm;
276 }
277
278 return NULL;
279}
280
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +0530281static unsigned int sad_format(const u8 *sad)
282{
283 return ((sad[0] >> 0x3) & 0x1f);
284}
285
286static unsigned int sad_sample_bits_lpcm(const u8 *sad)
287{
288 return (sad[2] & 7);
289}
290
291static int hdac_hdmi_eld_limit_formats(struct snd_pcm_runtime *runtime,
292 void *eld)
293{
294 u64 formats = SNDRV_PCM_FMTBIT_S16;
295 int i;
296 const u8 *sad, *eld_buf = eld;
297
298 sad = drm_eld_sad(eld_buf);
299 if (!sad)
300 goto format_constraint;
301
302 for (i = drm_eld_sad_count(eld_buf); i > 0; i--, sad += 3) {
303 if (sad_format(sad) == 1) { /* AUDIO_CODING_TYPE_LPCM */
304
305 /*
306 * the controller support 20 and 24 bits in 32 bit
307 * container so we set S32
308 */
309 if (sad_sample_bits_lpcm(sad) & 0x6)
310 formats |= SNDRV_PCM_FMTBIT_S32;
311 }
312 }
313
314format_constraint:
315 return snd_pcm_hw_constraint_mask64(runtime, SNDRV_PCM_HW_PARAM_FORMAT,
316 formats);
317
318}
319
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530320static void
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500321hdac_hdmi_set_dip_index(struct hdac_device *hdev, hda_nid_t pin_nid,
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530322 int packet_index, int byte_index)
323{
324 int val;
325
326 val = (packet_index << 5) | (byte_index & 0x1f);
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500327 snd_hdac_codec_write(hdev, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530328}
329
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530330struct dp_audio_infoframe {
331 u8 type; /* 0x84 */
332 u8 len; /* 0x1b */
333 u8 ver; /* 0x11 << 2 */
334
335 u8 CC02_CT47; /* match with HDMI infoframe from this on */
336 u8 SS01_SF24;
337 u8 CXT04;
338 u8 CA;
339 u8 LFEPBL01_LSV36_DM_INH7;
340};
341
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500342static int hdac_hdmi_setup_audio_infoframe(struct hdac_device *hdev,
Jeeja KP754695f2017-02-06 12:09:14 +0530343 struct hdac_hdmi_pcm *pcm, struct hdac_hdmi_port *port)
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530344{
345 uint8_t buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AUDIO_INFOFRAME_SIZE];
346 struct hdmi_audio_infoframe frame;
Jeeja KP754695f2017-02-06 12:09:14 +0530347 struct hdac_hdmi_pin *pin = port->pin;
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530348 struct dp_audio_infoframe dp_ai;
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500349 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Jeeja KPab1eea12017-01-24 21:49:05 +0530350 struct hdac_hdmi_cvt *cvt = pcm->cvt;
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530351 u8 *dip;
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530352 int ret;
353 int i;
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530354 const u8 *eld_buf;
355 u8 conn_type;
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530356 int channels, ca;
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530357
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500358 ca = snd_hdac_channel_allocation(hdev, port->eld.info.spk_alloc,
Jeeja KPab1eea12017-01-24 21:49:05 +0530359 pcm->channels, pcm->chmap_set, true, pcm->chmap);
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530360
361 channels = snd_hdac_get_active_channels(ca);
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500362 hdmi->chmap.ops.set_channel_count(hdev, cvt->nid, channels);
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530363
364 snd_hdac_setup_channel_mapping(&hdmi->chmap, pin->nid, false, ca,
Jeeja KPab1eea12017-01-24 21:49:05 +0530365 pcm->channels, pcm->chmap, pcm->chmap_set);
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530366
Jeeja KP754695f2017-02-06 12:09:14 +0530367 eld_buf = port->eld.eld_buffer;
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530368 conn_type = drm_eld_get_conn_type(eld_buf);
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530369
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530370 switch (conn_type) {
371 case DRM_ELD_CONN_TYPE_HDMI:
372 hdmi_audio_infoframe_init(&frame);
373
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530374 frame.channels = channels;
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530375 frame.channel_allocation = ca;
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530376
377 ret = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
378 if (ret < 0)
379 return ret;
380
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530381 break;
382
383 case DRM_ELD_CONN_TYPE_DP:
384 memset(&dp_ai, 0, sizeof(dp_ai));
385 dp_ai.type = 0x84;
386 dp_ai.len = 0x1b;
387 dp_ai.ver = 0x11 << 2;
388 dp_ai.CC02_CT47 = channels - 1;
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530389 dp_ai.CA = ca;
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530390
391 dip = (u8 *)&dp_ai;
392 break;
393
394 default:
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500395 dev_err(&hdev->dev, "Invalid connection type: %d\n", conn_type);
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530396 return -EIO;
397 }
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530398
399 /* stop infoframe transmission */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500400 hdac_hdmi_set_dip_index(hdev, pin->nid, 0x0, 0x0);
401 snd_hdac_codec_write(hdev, pin->nid, 0,
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530402 AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_DISABLE);
403
404
405 /* Fill infoframe. Index auto-incremented */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500406 hdac_hdmi_set_dip_index(hdev, pin->nid, 0x0, 0x0);
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530407 if (conn_type == DRM_ELD_CONN_TYPE_HDMI) {
Subhransu S. Prusty391005e2016-03-10 09:04:07 +0530408 for (i = 0; i < sizeof(buffer); i++)
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500409 snd_hdac_codec_write(hdev, pin->nid, 0,
Subhransu S. Prusty391005e2016-03-10 09:04:07 +0530410 AC_VERB_SET_HDMI_DIP_DATA, buffer[i]);
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530411 } else {
412 for (i = 0; i < sizeof(dp_ai); i++)
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500413 snd_hdac_codec_write(hdev, pin->nid, 0,
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530414 AC_VERB_SET_HDMI_DIP_DATA, dip[i]);
415 }
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530416
417 /* Start infoframe */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500418 hdac_hdmi_set_dip_index(hdev, pin->nid, 0x0, 0x0);
419 snd_hdac_codec_write(hdev, pin->nid, 0,
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530420 AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_BEST);
421
422 return 0;
423}
424
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530425static int hdac_hdmi_set_tdm_slot(struct snd_soc_dai *dai,
426 unsigned int tx_mask, unsigned int rx_mask,
427 int slots, int slot_width)
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530428{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500429 struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
430 struct hdac_device *hdev = hdmi->hdev;
Jeeja KP754695f2017-02-06 12:09:14 +0530431 struct hdac_hdmi_dai_port_map *dai_map;
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530432 struct hdac_hdmi_pcm *pcm;
433
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500434 dev_dbg(&hdev->dev, "%s: strm_tag: %d\n", __func__, tx_mask);
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530435
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530436 dai_map = &hdmi->dai_map[dai->id];
437
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530438 pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530439
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530440 if (pcm)
441 pcm->stream_tag = (tx_mask << 4);
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530442
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530443 return 0;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530444}
445
446static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,
447 struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)
448{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500449 struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
Jeeja KP754695f2017-02-06 12:09:14 +0530450 struct hdac_hdmi_dai_port_map *dai_map;
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530451 struct hdac_hdmi_pcm *pcm;
452 int format;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530453
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530454 dai_map = &hdmi->dai_map[dai->id];
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530455
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530456 format = snd_hdac_calc_stream_format(params_rate(hparams),
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530457 params_channels(hparams), params_format(hparams),
Jeeja KP66d6bbc2017-03-24 23:10:26 +0530458 dai->driver->playback.sig_bits, 0);
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530459
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530460 pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
461 if (!pcm)
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530462 return -EIO;
463
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530464 pcm->format = format;
465 pcm->channels = params_channels(hparams);
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530466
467 return 0;
468}
469
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500470static int hdac_hdmi_query_port_connlist(struct hdac_device *hdev,
Jeeja KP754695f2017-02-06 12:09:14 +0530471 struct hdac_hdmi_pin *pin,
472 struct hdac_hdmi_port *port)
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530473{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500474 if (!(get_wcaps(hdev, pin->nid) & AC_WCAP_CONN_LIST)) {
475 dev_warn(&hdev->dev,
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530476 "HDMI: pin %d wcaps %#x does not support connection list\n",
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500477 pin->nid, get_wcaps(hdev, pin->nid));
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530478 return -EINVAL;
479 }
480
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500481 if (hdac_hdmi_port_select_set(hdev, port) < 0)
Jeeja KP1b46ebd2017-02-07 19:09:47 +0530482 return -EIO;
483
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500484 port->num_mux_nids = snd_hdac_get_connections(hdev, pin->nid,
Jeeja KP754695f2017-02-06 12:09:14 +0530485 port->mux_nids, HDA_MAX_CONNECTIONS);
486 if (port->num_mux_nids == 0)
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500487 dev_warn(&hdev->dev,
Jeeja KP754695f2017-02-06 12:09:14 +0530488 "No connections found for pin:port %d:%d\n",
489 pin->nid, port->id);
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530490
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500491 dev_dbg(&hdev->dev, "num_mux_nids %d for pin:port %d:%d\n",
Jeeja KP754695f2017-02-06 12:09:14 +0530492 port->num_mux_nids, pin->nid, port->id);
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530493
Jeeja KP754695f2017-02-06 12:09:14 +0530494 return port->num_mux_nids;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530495}
496
497/*
Jeeja KP754695f2017-02-06 12:09:14 +0530498 * Query pcm list and return port to which stream is routed.
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530499 *
Jeeja KP754695f2017-02-06 12:09:14 +0530500 * Also query connection list of the pin, to validate the cvt to port map.
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530501 *
Jeeja KP754695f2017-02-06 12:09:14 +0530502 * Same stream rendering to multiple ports simultaneously can be done
503 * possibly, but not supported for now in driver. So return the first port
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530504 * connected.
505 */
Jeeja KP754695f2017-02-06 12:09:14 +0530506static struct hdac_hdmi_port *hdac_hdmi_get_port_from_cvt(
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500507 struct hdac_device *hdev,
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530508 struct hdac_hdmi_priv *hdmi,
509 struct hdac_hdmi_cvt *cvt)
510{
511 struct hdac_hdmi_pcm *pcm;
Jeeja KP754695f2017-02-06 12:09:14 +0530512 struct hdac_hdmi_port *port = NULL;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530513 int ret, i;
514
515 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
516 if (pcm->cvt == cvt) {
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530517 if (list_empty(&pcm->port_list))
518 continue;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530519
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530520 list_for_each_entry(port, &pcm->port_list, head) {
521 mutex_lock(&pcm->lock);
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500522 ret = hdac_hdmi_query_port_connlist(hdev,
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530523 port->pin, port);
524 mutex_unlock(&pcm->lock);
525 if (ret < 0)
526 continue;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530527
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530528 for (i = 0; i < port->num_mux_nids; i++) {
529 if (port->mux_nids[i] == cvt->nid &&
530 port->eld.monitor_present &&
531 port->eld.eld_valid)
532 return port;
533 }
534 }
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530535 }
536 }
537
538 return NULL;
539}
540
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530541/*
542 * This tries to get a valid pin and set the HW constraints based on the
543 * ELD. Even if a valid pin is not found return success so that device open
544 * doesn't fail.
545 */
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530546static int hdac_hdmi_pcm_open(struct snd_pcm_substream *substream,
547 struct snd_soc_dai *dai)
548{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500549 struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
550 struct hdac_device *hdev = hdmi->hdev;
Jeeja KP754695f2017-02-06 12:09:14 +0530551 struct hdac_hdmi_dai_port_map *dai_map;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530552 struct hdac_hdmi_cvt *cvt;
Jeeja KP754695f2017-02-06 12:09:14 +0530553 struct hdac_hdmi_port *port;
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +0530554 int ret;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530555
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530556 dai_map = &hdmi->dai_map[dai->id];
557
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530558 cvt = dai_map->cvt;
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500559 port = hdac_hdmi_get_port_from_cvt(hdev, hdmi, cvt);
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530560
561 /*
562 * To make PA and other userland happy.
563 * userland scans devices so returning error does not help.
564 */
Jeeja KP754695f2017-02-06 12:09:14 +0530565 if (!port)
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530566 return 0;
Jeeja KP754695f2017-02-06 12:09:14 +0530567 if ((!port->eld.monitor_present) ||
568 (!port->eld.eld_valid)) {
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530569
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500570 dev_warn(&hdev->dev,
Jeeja KP754695f2017-02-06 12:09:14 +0530571 "Failed: present?:%d ELD valid?:%d pin:port: %d:%d\n",
572 port->eld.monitor_present, port->eld.eld_valid,
573 port->pin->nid, port->id);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +0530574
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530575 return 0;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530576 }
577
Jeeja KP754695f2017-02-06 12:09:14 +0530578 dai_map->port = port;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530579
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +0530580 ret = hdac_hdmi_eld_limit_formats(substream->runtime,
Jeeja KP754695f2017-02-06 12:09:14 +0530581 port->eld.eld_buffer);
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +0530582 if (ret < 0)
583 return ret;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530584
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +0530585 return snd_pcm_hw_constraint_eld(substream->runtime,
Jeeja KP754695f2017-02-06 12:09:14 +0530586 port->eld.eld_buffer);
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530587}
588
589static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,
590 struct snd_soc_dai *dai)
591{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500592 struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
Jeeja KP754695f2017-02-06 12:09:14 +0530593 struct hdac_hdmi_dai_port_map *dai_map;
Jeeja KPab1eea12017-01-24 21:49:05 +0530594 struct hdac_hdmi_pcm *pcm;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530595
596 dai_map = &hdmi->dai_map[dai->id];
597
Jeeja KPab1eea12017-01-24 21:49:05 +0530598 pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530599
Jeeja KPab1eea12017-01-24 21:49:05 +0530600 if (pcm) {
601 mutex_lock(&pcm->lock);
602 pcm->chmap_set = false;
603 memset(pcm->chmap, 0, sizeof(pcm->chmap));
604 pcm->channels = 0;
605 mutex_unlock(&pcm->lock);
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530606 }
Jeeja KPab1eea12017-01-24 21:49:05 +0530607
Jeeja KP754695f2017-02-06 12:09:14 +0530608 if (dai_map->port)
609 dai_map->port = NULL;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530610}
611
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530612static int
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530613hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct hdac_hdmi_cvt *cvt)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530614{
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530615 unsigned int chans;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530616 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530617 int err;
618
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530619 chans = get_wcaps(hdev, cvt->nid);
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530620 chans = get_wcaps_channels(chans);
621
622 cvt->params.channels_min = 2;
623
624 cvt->params.channels_max = chans;
625 if (chans > hdmi->chmap.channels_max)
626 hdmi->chmap.channels_max = chans;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530627
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530628 err = snd_hdac_query_supported_pcm(hdev, cvt->nid,
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530629 &cvt->params.rates,
630 &cvt->params.formats,
631 &cvt->params.maxbps);
632 if (err < 0)
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530633 dev_err(&hdev->dev,
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530634 "Failed to query pcm params for nid %d: %d\n",
635 cvt->nid, err);
636
637 return err;
638}
639
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530640static int hdac_hdmi_fill_widget_info(struct device *dev,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530641 struct snd_soc_dapm_widget *w, enum snd_soc_dapm_type id,
642 void *priv, const char *wname, const char *stream,
643 struct snd_kcontrol_new *wc, int numkc,
644 int (*event)(struct snd_soc_dapm_widget *,
645 struct snd_kcontrol *, int), unsigned short event_flags)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530646{
647 w->id = id;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530648 w->name = devm_kstrdup(dev, wname, GFP_KERNEL);
649 if (!w->name)
650 return -ENOMEM;
651
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530652 w->sname = stream;
653 w->reg = SND_SOC_NOPM;
654 w->shift = 0;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530655 w->kcontrol_news = wc;
656 w->num_kcontrols = numkc;
657 w->priv = priv;
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530658 w->event = event;
659 w->event_flags = event_flags;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530660
661 return 0;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530662}
663
664static void hdac_hdmi_fill_route(struct snd_soc_dapm_route *route,
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530665 const char *sink, const char *control, const char *src,
666 int (*handler)(struct snd_soc_dapm_widget *src,
667 struct snd_soc_dapm_widget *sink))
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530668{
669 route->sink = sink;
670 route->source = src;
671 route->control = control;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530672 route->connected = handler;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530673}
674
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500675static struct hdac_hdmi_pcm *hdac_hdmi_get_pcm(struct hdac_device *hdev,
Jeeja KP754695f2017-02-06 12:09:14 +0530676 struct hdac_hdmi_port *port)
Jeeja KP4a3478d2016-02-12 07:46:06 +0530677{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500678 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Jeeja KP4a3478d2016-02-12 07:46:06 +0530679 struct hdac_hdmi_pcm *pcm = NULL;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530680 struct hdac_hdmi_port *p;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530681
682 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530683 if (list_empty(&pcm->port_list))
Jeeja KP754695f2017-02-06 12:09:14 +0530684 continue;
685
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530686 list_for_each_entry(p, &pcm->port_list, head) {
687 if (p->id == port->id && port->pin == p->pin)
688 return pcm;
689 }
Jeeja KP4a3478d2016-02-12 07:46:06 +0530690 }
691
692 return NULL;
693}
694
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500695static void hdac_hdmi_set_power_state(struct hdac_device *hdev,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530696 hda_nid_t nid, unsigned int pwr_state)
697{
Abhijeet Kumar753597f2018-02-15 14:05:38 +0530698 int count;
699 unsigned int state;
700
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500701 if (get_wcaps(hdev, nid) & AC_WCAP_POWER) {
702 if (!snd_hdac_check_power_state(hdev, nid, pwr_state)) {
Abhijeet Kumar753597f2018-02-15 14:05:38 +0530703 for (count = 0; count < 10; count++) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500704 snd_hdac_codec_read(hdev, nid, 0,
Abhijeet Kumar753597f2018-02-15 14:05:38 +0530705 AC_VERB_SET_POWER_STATE,
706 pwr_state);
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500707 state = snd_hdac_sync_power_state(hdev,
Abhijeet Kumar753597f2018-02-15 14:05:38 +0530708 nid, pwr_state);
709 if (!(state & AC_PWRST_ERROR))
710 break;
711 }
712 }
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530713 }
714}
715
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500716static void hdac_hdmi_set_amp(struct hdac_device *hdev,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530717 hda_nid_t nid, int val)
718{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500719 if (get_wcaps(hdev, nid) & AC_WCAP_OUT_AMP)
720 snd_hdac_codec_write(hdev, nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530721 AC_VERB_SET_AMP_GAIN_MUTE, val);
722}
723
724
725static int hdac_hdmi_pin_output_widget_event(struct snd_soc_dapm_widget *w,
726 struct snd_kcontrol *kc, int event)
727{
Jeeja KP754695f2017-02-06 12:09:14 +0530728 struct hdac_hdmi_port *port = w->priv;
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500729 struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530730 struct hdac_hdmi_pcm *pcm;
731
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500732 dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n",
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530733 __func__, w->name, event);
734
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500735 pcm = hdac_hdmi_get_pcm(hdev, port);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530736 if (!pcm)
737 return -EIO;
738
Jeeja KP1b46ebd2017-02-07 19:09:47 +0530739 /* set the device if pin is mst_capable */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500740 if (hdac_hdmi_port_select_set(hdev, port) < 0)
Jeeja KP1b46ebd2017-02-07 19:09:47 +0530741 return -EIO;
742
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530743 switch (event) {
744 case SND_SOC_DAPM_PRE_PMU:
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500745 hdac_hdmi_set_power_state(hdev, port->pin->nid, AC_PWRST_D0);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530746
747 /* Enable out path for this pin widget */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500748 snd_hdac_codec_write(hdev, port->pin->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530749 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
750
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500751 hdac_hdmi_set_amp(hdev, port->pin->nid, AMP_OUT_UNMUTE);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530752
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500753 return hdac_hdmi_setup_audio_infoframe(hdev, pcm, port);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530754
755 case SND_SOC_DAPM_POST_PMD:
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500756 hdac_hdmi_set_amp(hdev, port->pin->nid, AMP_OUT_MUTE);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530757
758 /* Disable out path for this pin widget */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500759 snd_hdac_codec_write(hdev, port->pin->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530760 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
761
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500762 hdac_hdmi_set_power_state(hdev, port->pin->nid, AC_PWRST_D3);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530763 break;
764
765 }
766
767 return 0;
768}
769
770static int hdac_hdmi_cvt_output_widget_event(struct snd_soc_dapm_widget *w,
771 struct snd_kcontrol *kc, int event)
772{
773 struct hdac_hdmi_cvt *cvt = w->priv;
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500774 struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev);
775 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530776 struct hdac_hdmi_pcm *pcm;
777
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500778 dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n",
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530779 __func__, w->name, event);
780
781 pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, cvt);
782 if (!pcm)
783 return -EIO;
784
785 switch (event) {
786 case SND_SOC_DAPM_PRE_PMU:
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500787 hdac_hdmi_set_power_state(hdev, cvt->nid, AC_PWRST_D0);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530788
789 /* Enable transmission */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500790 snd_hdac_codec_write(hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530791 AC_VERB_SET_DIGI_CONVERT_1, 1);
792
793 /* Category Code (CC) to zero */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500794 snd_hdac_codec_write(hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530795 AC_VERB_SET_DIGI_CONVERT_2, 0);
796
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500797 snd_hdac_codec_write(hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530798 AC_VERB_SET_CHANNEL_STREAMID, pcm->stream_tag);
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500799 snd_hdac_codec_write(hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530800 AC_VERB_SET_STREAM_FORMAT, pcm->format);
801 break;
802
803 case SND_SOC_DAPM_POST_PMD:
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500804 snd_hdac_codec_write(hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530805 AC_VERB_SET_CHANNEL_STREAMID, 0);
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500806 snd_hdac_codec_write(hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530807 AC_VERB_SET_STREAM_FORMAT, 0);
808
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500809 hdac_hdmi_set_power_state(hdev, cvt->nid, AC_PWRST_D3);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530810 break;
811
812 }
813
814 return 0;
815}
816
817static int hdac_hdmi_pin_mux_widget_event(struct snd_soc_dapm_widget *w,
818 struct snd_kcontrol *kc, int event)
819{
Jeeja KP754695f2017-02-06 12:09:14 +0530820 struct hdac_hdmi_port *port = w->priv;
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500821 struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530822 int mux_idx;
823
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500824 dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n",
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530825 __func__, w->name, event);
826
827 if (!kc)
828 kc = w->kcontrols[0];
829
830 mux_idx = dapm_kcontrol_get_value(kc);
Jeeja KP1b46ebd2017-02-07 19:09:47 +0530831
832 /* set the device if pin is mst_capable */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500833 if (hdac_hdmi_port_select_set(hdev, port) < 0)
Jeeja KP1b46ebd2017-02-07 19:09:47 +0530834 return -EIO;
835
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530836 if (mux_idx > 0) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500837 snd_hdac_codec_write(hdev, port->pin->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530838 AC_VERB_SET_CONNECT_SEL, (mux_idx - 1));
839 }
840
841 return 0;
842}
843
Jeeja KP4a3478d2016-02-12 07:46:06 +0530844/*
845 * Based on user selection, map the PINs with the PCMs.
846 */
Jeeja KP754695f2017-02-06 12:09:14 +0530847static int hdac_hdmi_set_pin_port_mux(struct snd_kcontrol *kcontrol,
Jeeja KP4a3478d2016-02-12 07:46:06 +0530848 struct snd_ctl_elem_value *ucontrol)
849{
850 int ret;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530851 struct hdac_hdmi_port *p, *p_next;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530852 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
853 struct snd_soc_dapm_widget *w = snd_soc_dapm_kcontrol_widget(kcontrol);
854 struct snd_soc_dapm_context *dapm = w->dapm;
Jeeja KP754695f2017-02-06 12:09:14 +0530855 struct hdac_hdmi_port *port = w->priv;
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500856 struct hdac_device *hdev = dev_to_hdac_dev(dapm->dev);
857 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Jeeja KP4a3478d2016-02-12 07:46:06 +0530858 struct hdac_hdmi_pcm *pcm = NULL;
859 const char *cvt_name = e->texts[ucontrol->value.enumerated.item[0]];
860
861 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
862 if (ret < 0)
863 return ret;
864
Jeeja KP754695f2017-02-06 12:09:14 +0530865 if (port == NULL)
866 return -EINVAL;
867
Jeeja KP4a3478d2016-02-12 07:46:06 +0530868 mutex_lock(&hdmi->pin_mutex);
869 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530870 if (list_empty(&pcm->port_list))
871 continue;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530872
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530873 list_for_each_entry_safe(p, p_next, &pcm->port_list, head) {
874 if (p == port && p->id == port->id &&
875 p->pin == port->pin) {
876 hdac_hdmi_jack_report(pcm, port, false);
877 list_del(&p->head);
Jeeja KP4a3478d2016-02-12 07:46:06 +0530878 }
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530879 }
880 }
881
882 /*
883 * Jack status is not reported during device probe as the
884 * PCMs are not registered by then. So report it here.
885 */
886 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
887 if (!strcmp(cvt_name, pcm->cvt->name)) {
888 list_add_tail(&port->head, &pcm->port_list);
889 if (port->eld.monitor_present && port->eld.eld_valid) {
890 hdac_hdmi_jack_report(pcm, port, true);
891 mutex_unlock(&hdmi->pin_mutex);
892 return ret;
893 }
Jeeja KP4a3478d2016-02-12 07:46:06 +0530894 }
895 }
896 mutex_unlock(&hdmi->pin_mutex);
897
898 return ret;
899}
900
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530901/*
902 * Ideally the Mux inputs should be based on the num_muxs enumerated, but
903 * the display driver seem to be programming the connection list for the pin
904 * widget runtime.
905 *
906 * So programming all the possible inputs for the mux, the user has to take
907 * care of selecting the right one and leaving all other inputs selected to
908 * "NONE"
909 */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500910static int hdac_hdmi_create_pin_port_muxs(struct hdac_device *hdev,
Jeeja KP754695f2017-02-06 12:09:14 +0530911 struct hdac_hdmi_port *port,
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530912 struct snd_soc_dapm_widget *widget,
913 const char *widget_name)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530914{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500915 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Jeeja KP754695f2017-02-06 12:09:14 +0530916 struct hdac_hdmi_pin *pin = port->pin;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530917 struct snd_kcontrol_new *kc;
918 struct hdac_hdmi_cvt *cvt;
919 struct soc_enum *se;
920 char kc_name[NAME_SIZE];
921 char mux_items[NAME_SIZE];
922 /* To hold inputs to the Pin mux */
923 char *items[HDA_MAX_CONNECTIONS];
924 int i = 0;
925 int num_items = hdmi->num_cvt + 1;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530926
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500927 kc = devm_kzalloc(&hdev->dev, sizeof(*kc), GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530928 if (!kc)
929 return -ENOMEM;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530930
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500931 se = devm_kzalloc(&hdev->dev, sizeof(*se), GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530932 if (!se)
933 return -ENOMEM;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530934
Subhransu S. Prusty70e97a22017-11-07 16:16:24 +0530935 snprintf(kc_name, NAME_SIZE, "Pin %d port %d Input",
936 pin->nid, port->id);
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500937 kc->name = devm_kstrdup(&hdev->dev, kc_name, GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530938 if (!kc->name)
939 return -ENOMEM;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530940
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530941 kc->private_value = (long)se;
942 kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
943 kc->access = 0;
944 kc->info = snd_soc_info_enum_double;
Jeeja KP754695f2017-02-06 12:09:14 +0530945 kc->put = hdac_hdmi_set_pin_port_mux;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530946 kc->get = snd_soc_dapm_get_enum_double;
947
948 se->reg = SND_SOC_NOPM;
949
950 /* enum texts: ["NONE", "cvt #", "cvt #", ...] */
951 se->items = num_items;
952 se->mask = roundup_pow_of_two(se->items) - 1;
953
954 sprintf(mux_items, "NONE");
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500955 items[i] = devm_kstrdup(&hdev->dev, mux_items, GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530956 if (!items[i])
957 return -ENOMEM;
958
959 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
960 i++;
961 sprintf(mux_items, "cvt %d", cvt->nid);
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500962 items[i] = devm_kstrdup(&hdev->dev, mux_items, GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530963 if (!items[i])
964 return -ENOMEM;
965 }
966
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500967 se->texts = devm_kmemdup(&hdev->dev, items,
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530968 (num_items * sizeof(char *)), GFP_KERNEL);
969 if (!se->texts)
970 return -ENOMEM;
971
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500972 return hdac_hdmi_fill_widget_info(&hdev->dev, widget,
Jeeja KP754695f2017-02-06 12:09:14 +0530973 snd_soc_dapm_mux, port, widget_name, NULL, kc, 1,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530974 hdac_hdmi_pin_mux_widget_event,
975 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_REG);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530976}
977
978/* Add cvt <- input <- mux route map */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500979static void hdac_hdmi_add_pinmux_cvt_route(struct hdac_device *hdev,
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530980 struct snd_soc_dapm_widget *widgets,
981 struct snd_soc_dapm_route *route, int rindex)
982{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500983 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530984 const struct snd_kcontrol_new *kc;
985 struct soc_enum *se;
Jeeja KP754695f2017-02-06 12:09:14 +0530986 int mux_index = hdmi->num_cvt + hdmi->num_ports;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530987 int i, j;
988
Jeeja KP754695f2017-02-06 12:09:14 +0530989 for (i = 0; i < hdmi->num_ports; i++) {
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530990 kc = widgets[mux_index].kcontrol_news;
991 se = (struct soc_enum *)kc->private_value;
992 for (j = 0; j < hdmi->num_cvt; j++) {
993 hdac_hdmi_fill_route(&route[rindex],
994 widgets[mux_index].name,
995 se->texts[j + 1],
996 widgets[j].name, NULL);
997
998 rindex++;
999 }
1000
1001 mux_index++;
1002 }
1003}
1004
1005/*
1006 * Widgets are added in the below sequence
1007 * Converter widgets for num converters enumerated
Jeeja KP754695f2017-02-06 12:09:14 +05301008 * Pin-port widgets for num ports for Pins enumerated
1009 * Pin-port mux widgets to represent connenction list of pin widget
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301010 *
Jeeja KP754695f2017-02-06 12:09:14 +05301011 * For each port, one Mux and One output widget is added
1012 * Total widgets elements = num_cvt + (num_ports * 2);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301013 *
1014 * Routes are added as below:
Jeeja KP754695f2017-02-06 12:09:14 +05301015 * pin-port mux -> pin (based on num_ports)
1016 * cvt -> "Input sel control" -> pin-port_mux
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301017 *
1018 * Total route elements:
Jeeja KP754695f2017-02-06 12:09:14 +05301019 * num_ports + (pin_muxes * num_cvt)
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301020 */
1021static int create_fill_widget_route_map(struct snd_soc_dapm_context *dapm)
1022{
1023 struct snd_soc_dapm_widget *widgets;
1024 struct snd_soc_dapm_route *route;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001025 struct hdac_device *hdev = dev_to_hdac_dev(dapm->dev);
1026 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Kuninori Morimoto1e02dac2017-12-20 01:48:13 +00001027 struct snd_soc_dai_driver *dai_drv = hdmi->dai_drv;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301028 char widget_name[NAME_SIZE];
1029 struct hdac_hdmi_cvt *cvt;
1030 struct hdac_hdmi_pin *pin;
Jeeja KP754695f2017-02-06 12:09:14 +05301031 int ret, i = 0, num_routes = 0, j;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301032
1033 if (list_empty(&hdmi->cvt_list) || list_empty(&hdmi->pin_list))
1034 return -EINVAL;
1035
Jeeja KP754695f2017-02-06 12:09:14 +05301036 widgets = devm_kzalloc(dapm->dev, (sizeof(*widgets) *
1037 ((2 * hdmi->num_ports) + hdmi->num_cvt)),
1038 GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301039
1040 if (!widgets)
1041 return -ENOMEM;
1042
1043 /* DAPM widgets to represent each converter widget */
1044 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
1045 sprintf(widget_name, "Converter %d", cvt->nid);
1046 ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
Jeeja KPc9bfb5d2017-01-24 21:49:03 +05301047 snd_soc_dapm_aif_in, cvt,
1048 widget_name, dai_drv[i].playback.stream_name, NULL, 0,
1049 hdac_hdmi_cvt_output_widget_event,
1050 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301051 if (ret < 0)
1052 return ret;
1053 i++;
1054 }
1055
1056 list_for_each_entry(pin, &hdmi->pin_list, head) {
Jeeja KP754695f2017-02-06 12:09:14 +05301057 for (j = 0; j < pin->num_ports; j++) {
1058 sprintf(widget_name, "hif%d-%d Output",
1059 pin->nid, pin->ports[j].id);
1060 ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
1061 snd_soc_dapm_output, &pin->ports[j],
1062 widget_name, NULL, NULL, 0,
1063 hdac_hdmi_pin_output_widget_event,
1064 SND_SOC_DAPM_PRE_PMU |
1065 SND_SOC_DAPM_POST_PMD);
1066 if (ret < 0)
1067 return ret;
Jeeja KP0324e512017-02-07 19:09:55 +05301068 pin->ports[j].output_pin = widgets[i].name;
Jeeja KP754695f2017-02-06 12:09:14 +05301069 i++;
1070 }
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301071 }
1072
1073 /* DAPM widgets to represent the connection list to pin widget */
1074 list_for_each_entry(pin, &hdmi->pin_list, head) {
Jeeja KP754695f2017-02-06 12:09:14 +05301075 for (j = 0; j < pin->num_ports; j++) {
1076 sprintf(widget_name, "Pin%d-Port%d Mux",
1077 pin->nid, pin->ports[j].id);
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001078 ret = hdac_hdmi_create_pin_port_muxs(hdev,
Jeeja KP754695f2017-02-06 12:09:14 +05301079 &pin->ports[j], &widgets[i],
1080 widget_name);
1081 if (ret < 0)
1082 return ret;
1083 i++;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301084
Jeeja KP754695f2017-02-06 12:09:14 +05301085 /* For cvt to pin_mux mapping */
1086 num_routes += hdmi->num_cvt;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301087
Jeeja KP754695f2017-02-06 12:09:14 +05301088 /* For pin_mux to pin mapping */
1089 num_routes++;
1090 }
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301091 }
1092
1093 route = devm_kzalloc(dapm->dev, (sizeof(*route) * num_routes),
1094 GFP_KERNEL);
1095 if (!route)
1096 return -ENOMEM;
1097
1098 i = 0;
1099 /* Add pin <- NULL <- mux route map */
1100 list_for_each_entry(pin, &hdmi->pin_list, head) {
Jeeja KP754695f2017-02-06 12:09:14 +05301101 for (j = 0; j < pin->num_ports; j++) {
1102 int sink_index = i + hdmi->num_cvt;
1103 int src_index = sink_index + pin->num_ports *
1104 hdmi->num_pin;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301105
Jeeja KP754695f2017-02-06 12:09:14 +05301106 hdac_hdmi_fill_route(&route[i],
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301107 widgets[sink_index].name, NULL,
1108 widgets[src_index].name, NULL);
Jeeja KP754695f2017-02-06 12:09:14 +05301109 i++;
1110 }
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301111 }
1112
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001113 hdac_hdmi_add_pinmux_cvt_route(hdev, widgets, route, i);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301114
1115 snd_soc_dapm_new_controls(dapm, widgets,
Jeeja KP754695f2017-02-06 12:09:14 +05301116 ((2 * hdmi->num_ports) + hdmi->num_cvt));
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301117
1118 snd_soc_dapm_add_routes(dapm, route, num_routes);
1119 snd_soc_dapm_new_widgets(dapm->card);
1120
1121 return 0;
1122
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301123}
1124
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001125static int hdac_hdmi_init_dai_map(struct hdac_device *hdev)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301126{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001127 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Jeeja KP754695f2017-02-06 12:09:14 +05301128 struct hdac_hdmi_dai_port_map *dai_map;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301129 struct hdac_hdmi_cvt *cvt;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301130 int dai_id = 0;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301131
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301132 if (list_empty(&hdmi->cvt_list))
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301133 return -EINVAL;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301134
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301135 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
1136 dai_map = &hdmi->dai_map[dai_id];
1137 dai_map->dai_id = dai_id;
1138 dai_map->cvt = cvt;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301139
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301140 dai_id++;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301141
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301142 if (dai_id == HDA_MAX_CVTS) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001143 dev_warn(&hdev->dev,
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301144 "Max dais supported: %d\n", dai_id);
1145 break;
1146 }
1147 }
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301148
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301149 return 0;
1150}
1151
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001152static int hdac_hdmi_add_cvt(struct hdac_device *hdev, hda_nid_t nid)
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301153{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001154 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301155 struct hdac_hdmi_cvt *cvt;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301156 char name[NAME_SIZE];
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301157
Pierre-Louis Bossartc7ba4e52019-02-08 17:26:53 -06001158 cvt = devm_kzalloc(&hdev->dev, sizeof(*cvt), GFP_KERNEL);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301159 if (!cvt)
1160 return -ENOMEM;
1161
1162 cvt->nid = nid;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301163 sprintf(name, "cvt %d", cvt->nid);
Pierre-Louis Bossartc7ba4e52019-02-08 17:26:53 -06001164 cvt->name = devm_kstrdup(&hdev->dev, name, GFP_KERNEL);
1165 if (!cvt->name)
1166 return -ENOMEM;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301167
1168 list_add_tail(&cvt->head, &hdmi->cvt_list);
1169 hdmi->num_cvt++;
1170
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001171 return hdac_hdmi_query_cvt_params(hdev, cvt);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301172}
1173
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001174static int hdac_hdmi_parse_eld(struct hdac_device *hdev,
Jeeja KP754695f2017-02-06 12:09:14 +05301175 struct hdac_hdmi_port *port)
Subhransu S. Prustyb7756ed2016-04-14 10:07:28 +05301176{
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301177 unsigned int ver, mnl;
1178
Jeeja KP754695f2017-02-06 12:09:14 +05301179 ver = (port->eld.eld_buffer[DRM_ELD_VER] & DRM_ELD_VER_MASK)
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301180 >> DRM_ELD_VER_SHIFT;
1181
1182 if (ver != ELD_VER_CEA_861D && ver != ELD_VER_PARTIAL) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001183 dev_err(&hdev->dev, "HDMI: Unknown ELD version %d\n", ver);
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301184 return -EINVAL;
1185 }
1186
Jeeja KP754695f2017-02-06 12:09:14 +05301187 mnl = (port->eld.eld_buffer[DRM_ELD_CEA_EDID_VER_MNL] &
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301188 DRM_ELD_MNL_MASK) >> DRM_ELD_MNL_SHIFT;
1189
1190 if (mnl > ELD_MAX_MNL) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001191 dev_err(&hdev->dev, "HDMI: MNL Invalid %d\n", mnl);
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301192 return -EINVAL;
1193 }
1194
Jeeja KP754695f2017-02-06 12:09:14 +05301195 port->eld.info.spk_alloc = port->eld.eld_buffer[DRM_ELD_SPEAKER];
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301196
1197 return 0;
Subhransu S. Prustyb7756ed2016-04-14 10:07:28 +05301198}
1199
Jeeja KP754695f2017-02-06 12:09:14 +05301200static void hdac_hdmi_present_sense(struct hdac_hdmi_pin *pin,
1201 struct hdac_hdmi_port *port)
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301202{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001203 struct hdac_device *hdev = pin->hdev;
1204 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Jeeja KP4a3478d2016-02-12 07:46:06 +05301205 struct hdac_hdmi_pcm *pcm;
Jeeja KP754695f2017-02-06 12:09:14 +05301206 int size = 0;
Jeeja KP2acd8302017-02-06 12:09:18 +05301207 int port_id = -1;
Jeeja KP754695f2017-02-06 12:09:14 +05301208
1209 if (!hdmi)
1210 return;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301211
Jeeja KP2acd8302017-02-06 12:09:18 +05301212 /*
1213 * In case of non MST pin, get_eld info API expectes port
1214 * to be -1.
1215 */
Jeeja KP4a3478d2016-02-12 07:46:06 +05301216 mutex_lock(&hdmi->pin_mutex);
Jeeja KP754695f2017-02-06 12:09:14 +05301217 port->eld.monitor_present = false;
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301218
Jeeja KP2acd8302017-02-06 12:09:18 +05301219 if (pin->mst_capable)
1220 port_id = port->id;
1221
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001222 size = snd_hdac_acomp_get_eld(hdev, pin->nid, port_id,
Jeeja KP754695f2017-02-06 12:09:14 +05301223 &port->eld.monitor_present,
1224 port->eld.eld_buffer,
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301225 ELD_MAX_SIZE);
1226
1227 if (size > 0) {
1228 size = min(size, ELD_MAX_SIZE);
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001229 if (hdac_hdmi_parse_eld(hdev, port) < 0)
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301230 size = -EINVAL;
1231 }
1232
1233 if (size > 0) {
Jeeja KP754695f2017-02-06 12:09:14 +05301234 port->eld.eld_valid = true;
1235 port->eld.eld_size = size;
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301236 } else {
Jeeja KP754695f2017-02-06 12:09:14 +05301237 port->eld.eld_valid = false;
1238 port->eld.eld_size = 0;
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301239 }
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301240
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001241 pcm = hdac_hdmi_get_pcm(hdev, port);
Jeeja KP4a3478d2016-02-12 07:46:06 +05301242
Jeeja KP754695f2017-02-06 12:09:14 +05301243 if (!port->eld.monitor_present || !port->eld.eld_valid) {
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301244
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001245 dev_err(&hdev->dev, "%s: disconnect for pin:port %d:%d\n",
Jeeja KP754695f2017-02-06 12:09:14 +05301246 __func__, pin->nid, port->id);
Jeeja KP4a3478d2016-02-12 07:46:06 +05301247
1248 /*
1249 * PCMs are not registered during device probe, so don't
1250 * report jack here. It will be done in usermode mux
1251 * control select.
1252 */
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301253 if (pcm)
1254 hdac_hdmi_jack_report(pcm, port, false);
Jeeja KP4a3478d2016-02-12 07:46:06 +05301255
1256 mutex_unlock(&hdmi->pin_mutex);
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301257 return;
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301258 }
1259
Jeeja KP754695f2017-02-06 12:09:14 +05301260 if (port->eld.monitor_present && port->eld.eld_valid) {
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301261 if (pcm)
1262 hdac_hdmi_jack_report(pcm, port, true);
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301263
1264 print_hex_dump_debug("ELD: ", DUMP_PREFIX_OFFSET, 16, 1,
Jeeja KP754695f2017-02-06 12:09:14 +05301265 port->eld.eld_buffer, port->eld.eld_size, false);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301266
Jeeja KP754695f2017-02-06 12:09:14 +05301267 }
Jeeja KP4a3478d2016-02-12 07:46:06 +05301268 mutex_unlock(&hdmi->pin_mutex);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301269}
1270
Pierre-Louis Bossartc7ba4e52019-02-08 17:26:53 -06001271static int hdac_hdmi_add_ports(struct hdac_device *hdev,
1272 struct hdac_hdmi_pin *pin)
Jeeja KP754695f2017-02-06 12:09:14 +05301273{
1274 struct hdac_hdmi_port *ports;
1275 int max_ports = HDA_MAX_PORTS;
1276 int i;
1277
1278 /*
1279 * FIXME: max_port may vary for each platform, so pass this as
1280 * as driver data or query from i915 interface when this API is
1281 * implemented.
1282 */
1283
Pierre-Louis Bossartc7ba4e52019-02-08 17:26:53 -06001284 ports = devm_kcalloc(&hdev->dev, max_ports, sizeof(*ports), GFP_KERNEL);
Jeeja KP754695f2017-02-06 12:09:14 +05301285 if (!ports)
1286 return -ENOMEM;
1287
1288 for (i = 0; i < max_ports; i++) {
1289 ports[i].id = i;
1290 ports[i].pin = pin;
1291 }
1292 pin->ports = ports;
1293 pin->num_ports = max_ports;
1294 return 0;
1295}
1296
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001297static int hdac_hdmi_add_pin(struct hdac_device *hdev, hda_nid_t nid)
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301298{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001299 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301300 struct hdac_hdmi_pin *pin;
Jeeja KP754695f2017-02-06 12:09:14 +05301301 int ret;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301302
Pierre-Louis Bossartc7ba4e52019-02-08 17:26:53 -06001303 pin = devm_kzalloc(&hdev->dev, sizeof(*pin), GFP_KERNEL);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301304 if (!pin)
1305 return -ENOMEM;
1306
1307 pin->nid = nid;
Jeeja KP2acd8302017-02-06 12:09:18 +05301308 pin->mst_capable = false;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001309 pin->hdev = hdev;
Pierre-Louis Bossartc7ba4e52019-02-08 17:26:53 -06001310 ret = hdac_hdmi_add_ports(hdev, pin);
Jeeja KP754695f2017-02-06 12:09:14 +05301311 if (ret < 0)
1312 return ret;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301313
1314 list_add_tail(&pin->head, &hdmi->pin_list);
1315 hdmi->num_pin++;
Jeeja KP754695f2017-02-06 12:09:14 +05301316 hdmi->num_ports += pin->num_ports;
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301317
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301318 return 0;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301319}
1320
Bard liao019033c2018-11-11 05:18:46 +08001321#define INTEL_VENDOR_NID_0x2 0x02
1322#define INTEL_VENDOR_NID_0x8 0x08
1323#define INTEL_VENDOR_NID_0xb 0x0b
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301324#define INTEL_GET_VENDOR_VERB 0xf81
1325#define INTEL_SET_VENDOR_VERB 0x781
Bard liao019033c2018-11-11 05:18:46 +08001326#define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301327#define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
1328
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301329static void hdac_hdmi_skl_enable_all_pins(struct hdac_device *hdev)
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301330{
1331 unsigned int vendor_param;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301332 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Pradeep Tewani5622bc92017-07-20 11:40:56 +05301333 unsigned int vendor_nid = hdmi->drv_data->vendor_nid;
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301334
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301335 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301336 INTEL_GET_VENDOR_VERB, 0);
1337 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
1338 return;
1339
1340 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301341 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301342 INTEL_SET_VENDOR_VERB, vendor_param);
1343 if (vendor_param == -1)
1344 return;
1345}
1346
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301347static void hdac_hdmi_skl_enable_dp12(struct hdac_device *hdev)
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301348{
1349 unsigned int vendor_param;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301350 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Pradeep Tewani5622bc92017-07-20 11:40:56 +05301351 unsigned int vendor_nid = hdmi->drv_data->vendor_nid;
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301352
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301353 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301354 INTEL_GET_VENDOR_VERB, 0);
1355 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
1356 return;
1357
1358 /* enable DP1.2 mode */
1359 vendor_param |= INTEL_EN_DP12;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301360 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301361 INTEL_SET_VENDOR_VERB, vendor_param);
1362 if (vendor_param == -1)
1363 return;
1364
1365}
1366
Gustavo A. R. Silva61b3b3c2017-07-13 15:38:38 -05001367static const struct snd_soc_dai_ops hdmi_dai_ops = {
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301368 .startup = hdac_hdmi_pcm_open,
1369 .shutdown = hdac_hdmi_pcm_close,
1370 .hw_params = hdac_hdmi_set_hw_params,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +05301371 .set_tdm_slot = hdac_hdmi_set_tdm_slot,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301372};
1373
1374/*
1375 * Each converter can support a stream independently. So a dai is created
1376 * based on the number of converter queried.
1377 */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301378static int hdac_hdmi_create_dais(struct hdac_device *hdev,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301379 struct snd_soc_dai_driver **dais,
1380 struct hdac_hdmi_priv *hdmi, int num_dais)
1381{
1382 struct snd_soc_dai_driver *hdmi_dais;
1383 struct hdac_hdmi_cvt *cvt;
1384 char name[NAME_SIZE], dai_name[NAME_SIZE];
1385 int i = 0;
1386 u32 rates, bps;
1387 unsigned int rate_max = 384000, rate_min = 8000;
1388 u64 formats;
1389 int ret;
1390
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301391 hdmi_dais = devm_kzalloc(&hdev->dev,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301392 (sizeof(*hdmi_dais) * num_dais),
1393 GFP_KERNEL);
1394 if (!hdmi_dais)
1395 return -ENOMEM;
1396
1397 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301398 ret = snd_hdac_query_supported_pcm(hdev, cvt->nid,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301399 &rates, &formats, &bps);
1400 if (ret)
1401 return ret;
1402
Yong Zhi3b857472018-08-07 12:19:16 -05001403 /* Filter out 44.1, 88.2 and 176.4Khz */
1404 rates &= ~(SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |
1405 SNDRV_PCM_RATE_176400);
1406 if (!rates)
1407 return -EINVAL;
1408
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301409 sprintf(dai_name, "intel-hdmi-hifi%d", i+1);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301410 hdmi_dais[i].name = devm_kstrdup(&hdev->dev,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301411 dai_name, GFP_KERNEL);
1412
1413 if (!hdmi_dais[i].name)
1414 return -ENOMEM;
1415
1416 snprintf(name, sizeof(name), "hifi%d", i+1);
1417 hdmi_dais[i].playback.stream_name =
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301418 devm_kstrdup(&hdev->dev, name, GFP_KERNEL);
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301419 if (!hdmi_dais[i].playback.stream_name)
1420 return -ENOMEM;
1421
1422 /*
1423 * Set caps based on capability queried from the converter.
1424 * It will be constrained runtime based on ELD queried.
1425 */
1426 hdmi_dais[i].playback.formats = formats;
1427 hdmi_dais[i].playback.rates = rates;
1428 hdmi_dais[i].playback.rate_max = rate_max;
1429 hdmi_dais[i].playback.rate_min = rate_min;
1430 hdmi_dais[i].playback.channels_min = 2;
1431 hdmi_dais[i].playback.channels_max = 2;
Jeeja KP66d6bbc2017-03-24 23:10:26 +05301432 hdmi_dais[i].playback.sig_bits = bps;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301433 hdmi_dais[i].ops = &hdmi_dai_ops;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301434 i++;
1435 }
1436
1437 *dais = hdmi_dais;
Kuninori Morimoto1e02dac2017-12-20 01:48:13 +00001438 hdmi->dai_drv = hdmi_dais;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301439
1440 return 0;
1441}
1442
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301443/*
1444 * Parse all nodes and store the cvt/pin nids in array
1445 * Add one time initialization for pin and cvt widgets
1446 */
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001447static int hdac_hdmi_parse_and_map_nid(struct hdac_device *hdev,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301448 struct snd_soc_dai_driver **dais, int *num_dais)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301449{
1450 hda_nid_t nid;
Sudip Mukherjee3c83ac22015-12-01 14:29:35 +05301451 int i, num_nodes;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001452 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301453 int ret;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301454
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301455 hdac_hdmi_skl_enable_all_pins(hdev);
1456 hdac_hdmi_skl_enable_dp12(hdev);
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301457
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301458 num_nodes = snd_hdac_get_sub_nodes(hdev, hdev->afg, &nid);
Subhransu S. Prusty541140d2015-12-09 21:46:08 +05301459 if (!nid || num_nodes <= 0) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301460 dev_warn(&hdev->dev, "HDMI: failed to get afg sub nodes\n");
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301461 return -EINVAL;
1462 }
1463
Puneeth Prabhu45a60082017-12-06 16:34:06 +05301464 for (i = 0; i < num_nodes; i++, nid++) {
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301465 unsigned int caps;
1466 unsigned int type;
1467
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301468 caps = get_wcaps(hdev, nid);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301469 type = get_wcaps_type(caps);
1470
1471 if (!(caps & AC_WCAP_DIGITAL))
1472 continue;
1473
1474 switch (type) {
1475
1476 case AC_WID_AUD_OUT:
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001477 ret = hdac_hdmi_add_cvt(hdev, nid);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301478 if (ret < 0)
Pierre-Louis Bossartc7ba4e52019-02-08 17:26:53 -06001479 return ret;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301480 break;
1481
1482 case AC_WID_PIN:
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001483 ret = hdac_hdmi_add_pin(hdev, nid);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301484 if (ret < 0)
Pierre-Louis Bossartc7ba4e52019-02-08 17:26:53 -06001485 return ret;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301486 break;
1487 }
1488 }
1489
Subhransu S. Prusty1c0a7de2017-11-07 16:16:26 +05301490 if (!hdmi->num_pin || !hdmi->num_cvt) {
1491 ret = -EIO;
Pierre-Louis Bossartc7ba4e52019-02-08 17:26:53 -06001492 dev_err(&hdev->dev, "Bad pin/cvt setup in %s\n", __func__);
1493 return ret;
Subhransu S. Prusty1c0a7de2017-11-07 16:16:26 +05301494 }
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301495
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301496 ret = hdac_hdmi_create_dais(hdev, dais, hdmi, hdmi->num_cvt);
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301497 if (ret) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301498 dev_err(&hdev->dev, "Failed to create dais with err: %d\n",
Pierre-Louis Bossartc7ba4e52019-02-08 17:26:53 -06001499 ret);
1500 return ret;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301501 }
1502
1503 *num_dais = hdmi->num_cvt;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001504 ret = hdac_hdmi_init_dai_map(hdev);
Subhransu S. Prusty1c0a7de2017-11-07 16:16:26 +05301505 if (ret < 0)
Pierre-Louis Bossartc7ba4e52019-02-08 17:26:53 -06001506 dev_err(&hdev->dev, "Failed to init DAI map with err: %d\n",
1507 ret);
Subhransu S. Prusty1c0a7de2017-11-07 16:16:26 +05301508 return ret;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301509}
1510
Takashi Iwaia57942b2018-07-11 16:23:16 +02001511static int hdac_hdmi_pin2port(void *aptr, int pin)
1512{
Bard liao019033c2018-11-11 05:18:46 +08001513 struct hdac_device *hdev = aptr;
1514 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
1515 const int *map = hdmi->drv_data->port_map;
1516 int i;
1517
1518 if (!hdmi->drv_data->port_num)
1519 return pin - 4; /* map NID 0x05 -> port #1 */
1520
1521 /*
1522 * looking for the pin number in the mapping table and return
1523 * the index which indicate the port number
1524 */
1525 for (i = 0; i < hdmi->drv_data->port_num; i++) {
1526 if (pin == map[i])
1527 return i + 1;
1528 }
1529
1530 /* return -1 if pin number exceeds our expectation */
1531 dev_err(&hdev->dev, "Can't find the port for pin %d\n", pin);
1532 return -1;
Takashi Iwaia57942b2018-07-11 16:23:16 +02001533}
1534
Pandiyan, Dhinakaranf9318942016-09-21 13:02:48 -07001535static void hdac_hdmi_eld_notify_cb(void *aptr, int port, int pipe)
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301536{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001537 struct hdac_device *hdev = aptr;
1538 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Jeeja KP754695f2017-02-06 12:09:14 +05301539 struct hdac_hdmi_pin *pin = NULL;
1540 struct hdac_hdmi_port *hport = NULL;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001541 struct snd_soc_component *component = hdmi->component;
Jeeja KP2acd8302017-02-06 12:09:18 +05301542 int i;
Bard liao019033c2018-11-11 05:18:46 +08001543 hda_nid_t pin_nid;
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301544
Bard liao019033c2018-11-11 05:18:46 +08001545 if (!hdmi->drv_data->port_num) {
1546 /* for legacy platforms */
1547 pin_nid = port + 0x04;
1548 } else if (port < hdmi->drv_data->port_num) {
1549 /* get pin number from the pin2port mapping table */
1550 pin_nid = hdmi->drv_data->port_map[port - 1];
1551 } else {
1552 dev_err(&hdev->dev, "Can't find the pin for port %d\n", port);
1553 return;
1554 }
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301555
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001556 dev_dbg(&hdev->dev, "%s: for pin:%d port=%d\n", __func__,
Jeeja KP754695f2017-02-06 12:09:14 +05301557 pin_nid, pipe);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301558
1559 /*
1560 * skip notification during system suspend (but not in runtime PM);
1561 * the state will be updated at resume. Also since the ELD and
1562 * connection states are updated in anyway at the end of the resume,
1563 * we can skip it when received during PM process.
1564 */
Kuninori Morimoto45101122018-01-29 04:36:54 +00001565 if (snd_power_get_state(component->card->snd_card) !=
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301566 SNDRV_CTL_POWER_D0)
1567 return;
1568
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001569 if (atomic_read(&hdev->in_pm))
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301570 return;
1571
1572 list_for_each_entry(pin, &hdmi->pin_list, head) {
Jeeja KP754695f2017-02-06 12:09:14 +05301573 if (pin->nid != pin_nid)
1574 continue;
1575
1576 /* In case of non MST pin, pipe is -1 */
1577 if (pipe == -1) {
Jeeja KP2acd8302017-02-06 12:09:18 +05301578 pin->mst_capable = false;
Jeeja KP754695f2017-02-06 12:09:14 +05301579 /* if not MST, default is port[0] */
1580 hport = &pin->ports[0];
Jeeja KP2acd8302017-02-06 12:09:18 +05301581 } else {
1582 for (i = 0; i < pin->num_ports; i++) {
1583 pin->mst_capable = true;
1584 if (pin->ports[i].id == pipe) {
1585 hport = &pin->ports[i];
Jeeja KP04c8f2b2017-03-01 22:41:23 +05301586 break;
Jeeja KP2acd8302017-02-06 12:09:18 +05301587 }
1588 }
Jeeja KP754695f2017-02-06 12:09:14 +05301589 }
Jeeja KP04c8f2b2017-03-01 22:41:23 +05301590
1591 if (hport)
1592 hdac_hdmi_present_sense(pin, hport);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301593 }
Jeeja KP754695f2017-02-06 12:09:14 +05301594
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301595}
1596
Takashi Iwaiae891ab2018-07-11 15:17:22 +02001597static struct drm_audio_component_audio_ops aops = {
Takashi Iwaia57942b2018-07-11 16:23:16 +02001598 .pin2port = hdac_hdmi_pin2port,
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301599 .pin_eld_notify = hdac_hdmi_eld_notify_cb,
1600};
1601
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301602static struct snd_pcm *hdac_hdmi_get_pcm_from_id(struct snd_soc_card *card,
1603 int device)
1604{
1605 struct snd_soc_pcm_runtime *rtd;
1606
Kuninori Morimotobcb1fd12018-09-18 01:29:35 +00001607 for_each_card_rtds(card, rtd) {
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301608 if (rtd->pcm && (rtd->pcm->device == device))
1609 return rtd->pcm;
1610 }
1611
1612 return NULL;
1613}
1614
Jeeja KP0324e512017-02-07 19:09:55 +05301615/* create jack pin kcontrols */
1616static int create_fill_jack_kcontrols(struct snd_soc_card *card,
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001617 struct hdac_device *hdev)
Jeeja KP0324e512017-02-07 19:09:55 +05301618{
1619 struct hdac_hdmi_pin *pin;
1620 struct snd_kcontrol_new *kc;
1621 char kc_name[NAME_SIZE], xname[NAME_SIZE];
1622 char *name;
1623 int i = 0, j;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001624 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
1625 struct snd_soc_component *component = hdmi->component;
Jeeja KP0324e512017-02-07 19:09:55 +05301626
Kuninori Morimoto45101122018-01-29 04:36:54 +00001627 kc = devm_kcalloc(component->dev, hdmi->num_ports,
Jeeja KP0324e512017-02-07 19:09:55 +05301628 sizeof(*kc), GFP_KERNEL);
1629
1630 if (!kc)
1631 return -ENOMEM;
1632
1633 list_for_each_entry(pin, &hdmi->pin_list, head) {
1634 for (j = 0; j < pin->num_ports; j++) {
1635 snprintf(xname, sizeof(xname), "hif%d-%d Jack",
1636 pin->nid, pin->ports[j].id);
Kuninori Morimoto45101122018-01-29 04:36:54 +00001637 name = devm_kstrdup(component->dev, xname, GFP_KERNEL);
Jeeja KP0324e512017-02-07 19:09:55 +05301638 if (!name)
1639 return -ENOMEM;
1640 snprintf(kc_name, sizeof(kc_name), "%s Switch", xname);
Kuninori Morimoto45101122018-01-29 04:36:54 +00001641 kc[i].name = devm_kstrdup(component->dev, kc_name,
Jeeja KP0324e512017-02-07 19:09:55 +05301642 GFP_KERNEL);
1643 if (!kc[i].name)
1644 return -ENOMEM;
1645
1646 kc[i].private_value = (unsigned long)name;
1647 kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1648 kc[i].access = 0;
1649 kc[i].info = snd_soc_dapm_info_pin_switch;
1650 kc[i].put = snd_soc_dapm_put_pin_switch;
1651 kc[i].get = snd_soc_dapm_get_pin_switch;
1652 i++;
1653 }
1654 }
1655
1656 return snd_soc_add_card_controls(card, kc, i);
1657}
1658
Kuninori Morimoto45101122018-01-29 04:36:54 +00001659int hdac_hdmi_jack_port_init(struct snd_soc_component *component,
Jeeja KP0324e512017-02-07 19:09:55 +05301660 struct snd_soc_dapm_context *dapm)
1661{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001662 struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
1663 struct hdac_device *hdev = hdmi->hdev;
Jeeja KP0324e512017-02-07 19:09:55 +05301664 struct hdac_hdmi_pin *pin;
1665 struct snd_soc_dapm_widget *widgets;
1666 struct snd_soc_dapm_route *route;
1667 char w_name[NAME_SIZE];
1668 int i = 0, j, ret;
1669
1670 widgets = devm_kcalloc(dapm->dev, hdmi->num_ports,
1671 sizeof(*widgets), GFP_KERNEL);
1672
1673 if (!widgets)
1674 return -ENOMEM;
1675
1676 route = devm_kcalloc(dapm->dev, hdmi->num_ports,
1677 sizeof(*route), GFP_KERNEL);
1678 if (!route)
1679 return -ENOMEM;
1680
1681 /* create Jack DAPM widget */
1682 list_for_each_entry(pin, &hdmi->pin_list, head) {
1683 for (j = 0; j < pin->num_ports; j++) {
1684 snprintf(w_name, sizeof(w_name), "hif%d-%d Jack",
1685 pin->nid, pin->ports[j].id);
1686
1687 ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
1688 snd_soc_dapm_spk, NULL,
1689 w_name, NULL, NULL, 0, NULL, 0);
1690 if (ret < 0)
1691 return ret;
1692
1693 pin->ports[j].jack_pin = widgets[i].name;
1694 pin->ports[j].dapm = dapm;
1695
1696 /* add to route from Jack widget to output */
1697 hdac_hdmi_fill_route(&route[i], pin->ports[j].jack_pin,
1698 NULL, pin->ports[j].output_pin, NULL);
1699
1700 i++;
1701 }
1702 }
1703
1704 /* Add Route from Jack widget to the output widget */
1705 ret = snd_soc_dapm_new_controls(dapm, widgets, hdmi->num_ports);
1706 if (ret < 0)
1707 return ret;
1708
1709 ret = snd_soc_dapm_add_routes(dapm, route, hdmi->num_ports);
1710 if (ret < 0)
1711 return ret;
1712
1713 ret = snd_soc_dapm_new_widgets(dapm->card);
1714 if (ret < 0)
1715 return ret;
1716
1717 /* Add Jack Pin switch Kcontrol */
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001718 ret = create_fill_jack_kcontrols(dapm->card, hdev);
Jeeja KP0324e512017-02-07 19:09:55 +05301719
1720 if (ret < 0)
1721 return ret;
1722
1723 /* default set the Jack Pin switch to OFF */
1724 list_for_each_entry(pin, &hdmi->pin_list, head) {
1725 for (j = 0; j < pin->num_ports; j++)
1726 snd_soc_dapm_disable_pin(pin->ports[j].dapm,
1727 pin->ports[j].jack_pin);
1728 }
1729
1730 return 0;
1731}
1732EXPORT_SYMBOL_GPL(hdac_hdmi_jack_port_init);
1733
Jeeja KP62490012017-02-07 19:09:49 +05301734int hdac_hdmi_jack_init(struct snd_soc_dai *dai, int device,
1735 struct snd_soc_jack *jack)
Jeeja KP4a3478d2016-02-12 07:46:06 +05301736{
Kuninori Morimoto45101122018-01-29 04:36:54 +00001737 struct snd_soc_component *component = dai->component;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001738 struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
1739 struct hdac_device *hdev = hdmi->hdev;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301740 struct hdac_hdmi_pcm *pcm;
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301741 struct snd_pcm *snd_pcm;
1742 int err;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301743
1744 /*
1745 * this is a new PCM device, create new pcm and
1746 * add to the pcm list
1747 */
Pierre-Louis Bossartc7ba4e52019-02-08 17:26:53 -06001748 pcm = devm_kzalloc(&hdev->dev, sizeof(*pcm), GFP_KERNEL);
Jeeja KP4a3478d2016-02-12 07:46:06 +05301749 if (!pcm)
1750 return -ENOMEM;
1751 pcm->pcm_id = device;
1752 pcm->cvt = hdmi->dai_map[dai->id].cvt;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301753 pcm->jack_event = 0;
Jeeja KP62490012017-02-07 19:09:49 +05301754 pcm->jack = jack;
Jeeja KPab1eea12017-01-24 21:49:05 +05301755 mutex_init(&pcm->lock);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301756 INIT_LIST_HEAD(&pcm->port_list);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301757 snd_pcm = hdac_hdmi_get_pcm_from_id(dai->component->card, device);
1758 if (snd_pcm) {
1759 err = snd_hdac_add_chmap_ctls(snd_pcm, device, &hdmi->chmap);
1760 if (err < 0) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001761 dev_err(&hdev->dev,
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301762 "chmap control add failed with err: %d for pcm: %d\n",
1763 err, device);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301764 return err;
1765 }
1766 }
1767
Jeeja KP4a3478d2016-02-12 07:46:06 +05301768 list_add_tail(&pcm->head, &hdmi->pcm_list);
1769
Jeeja KP62490012017-02-07 19:09:49 +05301770 return 0;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301771}
1772EXPORT_SYMBOL_GPL(hdac_hdmi_jack_init);
1773
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001774static void hdac_hdmi_present_sense_all_pins(struct hdac_device *hdev,
Jeeja KPa9ce96b2017-02-07 19:09:46 +05301775 struct hdac_hdmi_priv *hdmi, bool detect_pin_caps)
1776{
1777 int i;
1778 struct hdac_hdmi_pin *pin;
1779
1780 list_for_each_entry(pin, &hdmi->pin_list, head) {
1781 if (detect_pin_caps) {
1782
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001783 if (hdac_hdmi_get_port_len(hdev, pin->nid) == 0)
Jeeja KPa9ce96b2017-02-07 19:09:46 +05301784 pin->mst_capable = false;
1785 else
1786 pin->mst_capable = true;
1787 }
1788
1789 for (i = 0; i < pin->num_ports; i++) {
1790 if (!pin->mst_capable && i > 0)
1791 continue;
1792
1793 hdac_hdmi_present_sense(pin, &pin->ports[i]);
1794 }
1795 }
1796}
1797
Kuninori Morimoto45101122018-01-29 04:36:54 +00001798static int hdmi_codec_probe(struct snd_soc_component *component)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301799{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001800 struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
1801 struct hdac_device *hdev = hdmi->hdev;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301802 struct snd_soc_dapm_context *dapm =
Kuninori Morimoto45101122018-01-29 04:36:54 +00001803 snd_soc_component_get_dapm(component);
Vinod Koulb2047e92016-05-12 08:58:55 +05301804 struct hdac_ext_link *hlink = NULL;
Jeeja KPa9ce96b2017-02-07 19:09:46 +05301805 int ret;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301806
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001807 hdmi->component = component;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301808
Vinod Koulb2047e92016-05-12 08:58:55 +05301809 /*
1810 * hold the ref while we probe, also no need to drop the ref on
1811 * exit, we call pm_runtime_suspend() so that will do for us
1812 */
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05001813 hlink = snd_hdac_ext_bus_get_link(hdev->bus, dev_name(&hdev->dev));
Vinod Koul500e06b2016-05-31 19:09:55 +05301814 if (!hlink) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001815 dev_err(&hdev->dev, "hdac link not found\n");
Vinod Koul500e06b2016-05-31 19:09:55 +05301816 return -EIO;
1817 }
1818
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05001819 snd_hdac_ext_bus_link_get(hdev->bus, hlink);
Vinod Koulb2047e92016-05-12 08:58:55 +05301820
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301821 ret = create_fill_widget_route_map(dapm);
1822 if (ret < 0)
1823 return ret;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301824
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001825 aops.audio_ptr = hdev;
Takashi Iwaia57942b2018-07-11 16:23:16 +02001826 ret = snd_hdac_acomp_register_notifier(hdev->bus, &aops);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301827 if (ret < 0) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001828 dev_err(&hdev->dev, "notifier register failed: err: %d\n", ret);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301829 return ret;
1830 }
1831
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001832 hdac_hdmi_present_sense_all_pins(hdev, hdmi, true);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301833 /* Imp: Store the card pointer in hda_codec */
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001834 hdmi->card = dapm->card->snd_card;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301835
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05301836 /*
Libin Yang01c83272019-04-13 21:18:12 +08001837 * Setup a device_link between card device and HDMI codec device.
1838 * The card device is the consumer and the HDMI codec device is
1839 * the supplier. With this setting, we can make sure that the audio
1840 * domain in display power will be always turned on before operating
1841 * on the HDMI audio codec registers.
1842 * Let's use the flag DL_FLAG_AUTOREMOVE_CONSUMER. This can make
1843 * sure the device link is freed when the machine driver is removed.
1844 */
1845 device_link_add(component->card->dev, &hdev->dev, DL_FLAG_RPM_ACTIVE |
1846 DL_FLAG_AUTOREMOVE_CONSUMER);
1847 /*
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05301848 * hdac_device core already sets the state to active and calls
1849 * get_noresume. So enable runtime and set the device to suspend.
1850 */
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001851 pm_runtime_enable(&hdev->dev);
1852 pm_runtime_put(&hdev->dev);
1853 pm_runtime_suspend(&hdev->dev);
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05301854
1855 return 0;
1856}
1857
Kuninori Morimoto45101122018-01-29 04:36:54 +00001858static void hdmi_codec_remove(struct snd_soc_component *component)
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05301859{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001860 struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
1861 struct hdac_device *hdev = hdmi->hdev;
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05301862
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001863 pm_runtime_disable(&hdev->dev);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301864}
1865
Takashi Iwai687ae9e2019-01-08 11:37:31 +01001866#ifdef CONFIG_PM_SLEEP
1867static int hdmi_codec_resume(struct device *dev)
Jeeja KP571d5072016-02-22 07:50:33 +05301868{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001869 struct hdac_device *hdev = dev_to_hdac_dev(dev);
1870 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Takashi Iwai687ae9e2019-01-08 11:37:31 +01001871 int ret;
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05301872
Takashi Iwai687ae9e2019-01-08 11:37:31 +01001873 ret = pm_runtime_force_resume(dev);
1874 if (ret < 0)
1875 return ret;
Jeeja KP571d5072016-02-22 07:50:33 +05301876 /*
1877 * As the ELD notify callback request is not entertained while the
1878 * device is in suspend state. Need to manually check detection of
Jeeja KPa9ce96b2017-02-07 19:09:46 +05301879 * all pins here. pin capablity change is not support, so use the
1880 * already set pin caps.
Takashi Iwai687ae9e2019-01-08 11:37:31 +01001881 *
1882 * NOTE: this is safe to call even if the codec doesn't actually resume.
1883 * The pin check involves only with DRM audio component hooks, so it
1884 * works even if the HD-audio side is still dreaming peacefully.
Jeeja KP571d5072016-02-22 07:50:33 +05301885 */
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001886 hdac_hdmi_present_sense_all_pins(hdev, hdmi, false);
Takashi Iwai687ae9e2019-01-08 11:37:31 +01001887 return 0;
Jeeja KP571d5072016-02-22 07:50:33 +05301888}
1889#else
Takashi Iwai687ae9e2019-01-08 11:37:31 +01001890#define hdmi_codec_resume NULL
Jeeja KP571d5072016-02-22 07:50:33 +05301891#endif
1892
Kuninori Morimoto45101122018-01-29 04:36:54 +00001893static const struct snd_soc_component_driver hdmi_hda_codec = {
1894 .probe = hdmi_codec_probe,
1895 .remove = hdmi_codec_remove,
1896 .use_pmdown_time = 1,
1897 .endianness = 1,
1898 .non_legacy_dai_naming = 1,
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301899};
1900
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301901static void hdac_hdmi_get_chmap(struct hdac_device *hdev, int pcm_idx,
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301902 unsigned char *chmap)
1903{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301904 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301905 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301906
Jeeja KPab1eea12017-01-24 21:49:05 +05301907 memcpy(chmap, pcm->chmap, ARRAY_SIZE(pcm->chmap));
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301908}
1909
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301910static void hdac_hdmi_set_chmap(struct hdac_device *hdev, int pcm_idx,
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301911 unsigned char *chmap, int prepared)
1912{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301913 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301914 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301915 struct hdac_hdmi_port *port;
1916
Subhransu S. Prustyeb50fa12017-11-07 16:16:25 +05301917 if (!pcm)
1918 return;
1919
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301920 if (list_empty(&pcm->port_list))
1921 return;
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301922
Jeeja KPab1eea12017-01-24 21:49:05 +05301923 mutex_lock(&pcm->lock);
1924 pcm->chmap_set = true;
1925 memcpy(pcm->chmap, chmap, ARRAY_SIZE(pcm->chmap));
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301926 list_for_each_entry(port, &pcm->port_list, head)
1927 if (prepared)
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001928 hdac_hdmi_setup_audio_infoframe(hdev, pcm, port);
Jeeja KPab1eea12017-01-24 21:49:05 +05301929 mutex_unlock(&pcm->lock);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301930}
1931
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301932static bool is_hdac_hdmi_pcm_attached(struct hdac_device *hdev, int pcm_idx)
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301933{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301934 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301935 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301936
Subhransu S. Prustyeb50fa12017-11-07 16:16:25 +05301937 if (!pcm)
1938 return false;
1939
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301940 if (list_empty(&pcm->port_list))
1941 return false;
1942
1943 return true;
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301944}
1945
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301946static int hdac_hdmi_get_spk_alloc(struct hdac_device *hdev, int pcm_idx)
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301947{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301948 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301949 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301950 struct hdac_hdmi_port *port;
1951
Subhransu S. Prustyeb50fa12017-11-07 16:16:25 +05301952 if (!pcm)
1953 return 0;
1954
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301955 if (list_empty(&pcm->port_list))
1956 return 0;
1957
1958 port = list_first_entry(&pcm->port_list, struct hdac_hdmi_port, head);
1959
Jeeja KP754695f2017-02-06 12:09:14 +05301960 if (!port || !port->eld.eld_valid)
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301961 return 0;
1962
Jeeja KP754695f2017-02-06 12:09:14 +05301963 return port->eld.info.spk_alloc;
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301964}
1965
Bard liao019033c2018-11-11 05:18:46 +08001966static struct hdac_hdmi_drv_data intel_icl_drv_data = {
1967 .vendor_nid = INTEL_VENDOR_NID_0x2,
1968 .port_map = icl_pin2port_map,
1969 .port_num = ARRAY_SIZE(icl_pin2port_map),
1970};
1971
Pradeep Tewani5622bc92017-07-20 11:40:56 +05301972static struct hdac_hdmi_drv_data intel_glk_drv_data = {
Bard liao019033c2018-11-11 05:18:46 +08001973 .vendor_nid = INTEL_VENDOR_NID_0xb,
Pradeep Tewani5622bc92017-07-20 11:40:56 +05301974};
1975
1976static struct hdac_hdmi_drv_data intel_drv_data = {
Bard liao019033c2018-11-11 05:18:46 +08001977 .vendor_nid = INTEL_VENDOR_NID_0x8,
Pradeep Tewani5622bc92017-07-20 11:40:56 +05301978};
1979
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001980static int hdac_hdmi_dev_probe(struct hdac_device *hdev)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301981{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001982 struct hdac_hdmi_priv *hdmi_priv = NULL;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301983 struct snd_soc_dai_driver *hdmi_dais = NULL;
Vinod Koulb2047e92016-05-12 08:58:55 +05301984 struct hdac_ext_link *hlink = NULL;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301985 int num_dais = 0;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301986 int ret = 0;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301987 struct hdac_driver *hdrv = drv_to_hdac_driver(hdev->dev.driver);
1988 const struct hda_device_id *hdac_id = hdac_get_device_id(hdev, hdrv);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301989
Vinod Koulb2047e92016-05-12 08:58:55 +05301990 /* hold the ref while we probe */
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05001991 hlink = snd_hdac_ext_bus_get_link(hdev->bus, dev_name(&hdev->dev));
Vinod Koul500e06b2016-05-31 19:09:55 +05301992 if (!hlink) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001993 dev_err(&hdev->dev, "hdac link not found\n");
Vinod Koul500e06b2016-05-31 19:09:55 +05301994 return -EIO;
1995 }
1996
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05001997 snd_hdac_ext_bus_link_get(hdev->bus, hlink);
Vinod Koulb2047e92016-05-12 08:58:55 +05301998
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301999 hdmi_priv = devm_kzalloc(&hdev->dev, sizeof(*hdmi_priv), GFP_KERNEL);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302000 if (hdmi_priv == NULL)
2001 return -ENOMEM;
2002
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302003 snd_hdac_register_chmap_ops(hdev, &hdmi_priv->chmap);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05302004 hdmi_priv->chmap.ops.get_chmap = hdac_hdmi_get_chmap;
2005 hdmi_priv->chmap.ops.set_chmap = hdac_hdmi_set_chmap;
2006 hdmi_priv->chmap.ops.is_pcm_attached = is_hdac_hdmi_pcm_attached;
2007 hdmi_priv->chmap.ops.get_spk_alloc = hdac_hdmi_get_spk_alloc;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002008 hdmi_priv->hdev = hdev;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302009
Subhransu S. Prustyeb50fa12017-11-07 16:16:25 +05302010 if (!hdac_id)
2011 return -ENODEV;
2012
Pradeep Tewani5622bc92017-07-20 11:40:56 +05302013 if (hdac_id->driver_data)
2014 hdmi_priv->drv_data =
2015 (struct hdac_hdmi_drv_data *)hdac_id->driver_data;
2016 else
2017 hdmi_priv->drv_data = &intel_drv_data;
2018
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002019 dev_set_drvdata(&hdev->dev, hdmi_priv);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302020
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302021 INIT_LIST_HEAD(&hdmi_priv->pin_list);
2022 INIT_LIST_HEAD(&hdmi_priv->cvt_list);
Jeeja KP4a3478d2016-02-12 07:46:06 +05302023 INIT_LIST_HEAD(&hdmi_priv->pcm_list);
2024 mutex_init(&hdmi_priv->pin_mutex);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302025
Ramesh Babuaeaccef2016-02-17 21:34:01 +05302026 /*
2027 * Turned off in the runtime_suspend during the first explicit
2028 * pm_runtime_suspend call.
2029 */
Takashi Iwai4f799e72018-12-09 10:04:25 +01002030 snd_hdac_display_power(hdev->bus, hdev->addr, true);
2031
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002032 ret = hdac_hdmi_parse_and_map_nid(hdev, &hdmi_dais, &num_dais);
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05302033 if (ret < 0) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302034 dev_err(&hdev->dev,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05302035 "Failed in parse and map nid with err: %d\n", ret);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302036 return ret;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05302037 }
Puneeth Prabhu0fb02ba2017-12-06 16:34:05 +05302038 snd_hdac_refresh_widgets(hdev, true);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302039
2040 /* ASoC specific initialization */
Kuninori Morimoto45101122018-01-29 04:36:54 +00002041 ret = devm_snd_soc_register_component(&hdev->dev, &hdmi_hda_codec,
Vinod Koulb2047e92016-05-12 08:58:55 +05302042 hdmi_dais, num_dais);
2043
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05002044 snd_hdac_ext_bus_link_put(hdev->bus, hlink);
Vinod Koulb2047e92016-05-12 08:58:55 +05302045
2046 return ret;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302047}
2048
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002049static int hdac_hdmi_dev_remove(struct hdac_device *hdev)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302050{
Takashi Iwai77a49672018-12-09 10:06:59 +01002051 snd_hdac_display_power(hdev->bus, hdev->addr, false);
2052
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302053 return 0;
2054}
2055
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302056#ifdef CONFIG_PM
2057static int hdac_hdmi_runtime_suspend(struct device *dev)
2058{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002059 struct hdac_device *hdev = dev_to_hdac_dev(dev);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302060 struct hdac_bus *bus = hdev->bus;
Vinod Koulb2047e92016-05-12 08:58:55 +05302061 struct hdac_ext_link *hlink = NULL;
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302062
2063 dev_dbg(dev, "Enter: %s\n", __func__);
2064
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302065 /* controller may not have been initialized for the first time */
2066 if (!bus)
2067 return 0;
2068
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05302069 /*
2070 * Power down afg.
2071 * codec_read is preferred over codec_write to set the power state.
2072 * This way verb is send to set the power state and response
2073 * is received. So setting power state is ensured without using loop
2074 * to read the state.
2075 */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302076 snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05302077 AC_PWRST_D3);
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302078
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05002079 hlink = snd_hdac_ext_bus_get_link(bus, dev_name(dev));
Vinod Koul500e06b2016-05-31 19:09:55 +05302080 if (!hlink) {
2081 dev_err(dev, "hdac link not found\n");
2082 return -EIO;
2083 }
2084
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05002085 snd_hdac_ext_bus_link_put(bus, hlink);
Vinod Koulb2047e92016-05-12 08:58:55 +05302086
Takashi Iwai4f799e72018-12-09 10:04:25 +01002087 snd_hdac_display_power(bus, hdev->addr, false);
Pierre-Louis Bossart4c104732018-11-09 13:39:23 -06002088
Takashi Iwai4f799e72018-12-09 10:04:25 +01002089 return 0;
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302090}
2091
2092static int hdac_hdmi_runtime_resume(struct device *dev)
2093{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002094 struct hdac_device *hdev = dev_to_hdac_dev(dev);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302095 struct hdac_bus *bus = hdev->bus;
Vinod Koulb2047e92016-05-12 08:58:55 +05302096 struct hdac_ext_link *hlink = NULL;
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302097
2098 dev_dbg(dev, "Enter: %s\n", __func__);
2099
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302100 /* controller may not have been initialized for the first time */
2101 if (!bus)
2102 return 0;
2103
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05002104 hlink = snd_hdac_ext_bus_get_link(bus, dev_name(dev));
Vinod Koul500e06b2016-05-31 19:09:55 +05302105 if (!hlink) {
2106 dev_err(dev, "hdac link not found\n");
2107 return -EIO;
2108 }
2109
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05002110 snd_hdac_ext_bus_link_get(bus, hlink);
Vinod Koulb2047e92016-05-12 08:58:55 +05302111
Takashi Iwai4f799e72018-12-09 10:04:25 +01002112 snd_hdac_display_power(bus, hdev->addr, true);
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302113
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002114 hdac_hdmi_skl_enable_all_pins(hdev);
2115 hdac_hdmi_skl_enable_dp12(hdev);
Subhransu S. Prustyab85f5b2016-02-17 21:34:02 +05302116
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302117 /* Power up afg */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302118 snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05302119 AC_PWRST_D0);
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302120
2121 return 0;
2122}
2123#else
2124#define hdac_hdmi_runtime_suspend NULL
2125#define hdac_hdmi_runtime_resume NULL
2126#endif
2127
2128static const struct dev_pm_ops hdac_hdmi_pm = {
2129 SET_RUNTIME_PM_OPS(hdac_hdmi_runtime_suspend, hdac_hdmi_runtime_resume, NULL)
Takashi Iwai687ae9e2019-01-08 11:37:31 +01002130 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, hdmi_codec_resume)
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302131};
2132
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302133static const struct hda_device_id hdmi_list[] = {
2134 HDA_CODEC_EXT_ENTRY(0x80862809, 0x100000, "Skylake HDMI", 0),
Jeeja KPe2304802016-03-11 10:12:55 +05302135 HDA_CODEC_EXT_ENTRY(0x8086280a, 0x100000, "Broxton HDMI", 0),
Shreyas NCcc216882016-07-11 22:02:09 +05302136 HDA_CODEC_EXT_ENTRY(0x8086280b, 0x100000, "Kabylake HDMI", 0),
Guneshwor Singh5fb6e0a2017-12-21 08:45:29 +05302137 HDA_CODEC_EXT_ENTRY(0x8086280c, 0x100000, "Cannonlake HDMI",
2138 &intel_glk_drv_data),
Pradeep Tewani5622bc92017-07-20 11:40:56 +05302139 HDA_CODEC_EXT_ENTRY(0x8086280d, 0x100000, "Geminilake HDMI",
2140 &intel_glk_drv_data),
Bard liao019033c2018-11-11 05:18:46 +08002141 HDA_CODEC_EXT_ENTRY(0x8086280f, 0x100000, "Icelake HDMI",
2142 &intel_icl_drv_data),
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302143 {}
2144};
2145
2146MODULE_DEVICE_TABLE(hdaudio, hdmi_list);
2147
Rakesh Ughrejae1df9312018-06-01 22:53:51 -05002148static struct hdac_driver hdmi_driver = {
2149 .driver = {
2150 .name = "HDMI HDA Codec",
2151 .pm = &hdac_hdmi_pm,
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302152 },
Rakesh Ughrejae1df9312018-06-01 22:53:51 -05002153 .id_table = hdmi_list,
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302154 .probe = hdac_hdmi_dev_probe,
2155 .remove = hdac_hdmi_dev_remove,
2156};
2157
2158static int __init hdmi_init(void)
2159{
2160 return snd_hda_ext_driver_register(&hdmi_driver);
2161}
2162
2163static void __exit hdmi_exit(void)
2164{
2165 snd_hda_ext_driver_unregister(&hdmi_driver);
2166}
2167
2168module_init(hdmi_init);
2169module_exit(hdmi_exit);
2170
2171MODULE_LICENSE("GPL v2");
2172MODULE_DESCRIPTION("HDMI HD codec");
2173MODULE_AUTHOR("Samreen Nilofer<samreen.nilofer@intel.com>");
2174MODULE_AUTHOR("Subhransu S. Prusty<subhransu.s.prusty@intel.com>");