blob: 4748a9d5de3bd4d127922830cca4e01a826968a5 [file] [log] [blame]
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301/*
2 * hdac_hdmi.c - ASoc HDA-HDMI codec driver for Intel platforms
3 *
4 * Copyright (C) 2014-2015 Intel Corp
5 * Author: Samreen Nilofer <samreen.nilofer@intel.com>
6 * Subhransu S. Prusty <subhransu.s.prusty@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 */
20#include <linux/init.h>
21#include <linux/delay.h>
22#include <linux/module.h>
23#include <linux/pm_runtime.h>
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +053024#include <linux/hdmi.h>
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +053025#include <drm/drm_edid.h>
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053026#include <sound/pcm_params.h>
Jeeja KP4a3478d2016-02-12 07:46:06 +053027#include <sound/jack.h>
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053028#include <sound/soc.h>
29#include <sound/hdaudio_ext.h>
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +053030#include <sound/hda_i915.h>
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +053031#include <sound/pcm_drm_eld.h>
Subhransu S. Prustybcced702016-04-14 10:07:30 +053032#include <sound/hda_chmap.h>
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053033#include "../../hda/local.h"
Jeeja KP4a3478d2016-02-12 07:46:06 +053034#include "hdac_hdmi.h"
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053035
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +053036#define NAME_SIZE 32
37
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +053038#define AMP_OUT_MUTE 0xb080
39#define AMP_OUT_UNMUTE 0xb000
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053040#define PIN_OUT (AC_PINCTL_OUT_EN)
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +053041
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053042#define HDA_MAX_CONNECTIONS 32
43
Subhransu S. Prusty148569f2016-02-12 07:46:07 +053044#define HDA_MAX_CVTS 3
Jeeja KP754695f2017-02-06 12:09:14 +053045#define HDA_MAX_PORTS 3
Subhransu S. Prusty148569f2016-02-12 07:46:07 +053046
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +053047#define ELD_MAX_SIZE 256
48#define ELD_FIXED_BYTES 20
49
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +053050#define ELD_VER_CEA_861D 2
51#define ELD_VER_PARTIAL 31
52#define ELD_MAX_MNL 16
53
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053054struct hdac_hdmi_cvt_params {
55 unsigned int channels_min;
56 unsigned int channels_max;
57 u32 rates;
58 u64 formats;
59 unsigned int maxbps;
60};
61
62struct hdac_hdmi_cvt {
Subhransu S. Prusty15b91442015-12-09 21:46:10 +053063 struct list_head head;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053064 hda_nid_t nid;
Jeeja KP4a3478d2016-02-12 07:46:06 +053065 const char *name;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053066 struct hdac_hdmi_cvt_params params;
67};
68
Subhransu S. Prustyb7756ed2016-04-14 10:07:28 +053069/* Currently only spk_alloc, more to be added */
70struct hdac_hdmi_parsed_eld {
71 u8 spk_alloc;
72};
73
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +053074struct hdac_hdmi_eld {
75 bool monitor_present;
76 bool eld_valid;
77 int eld_size;
78 char eld_buffer[ELD_MAX_SIZE];
Subhransu S. Prustyb7756ed2016-04-14 10:07:28 +053079 struct hdac_hdmi_parsed_eld info;
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +053080};
81
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053082struct hdac_hdmi_pin {
Subhransu S. Prusty15b91442015-12-09 21:46:10 +053083 struct list_head head;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053084 hda_nid_t nid;
Jeeja KP2acd8302017-02-06 12:09:18 +053085 bool mst_capable;
Jeeja KP754695f2017-02-06 12:09:14 +053086 struct hdac_hdmi_port *ports;
87 int num_ports;
Rakesh Ughreja3787a392018-06-01 22:53:49 -050088 struct hdac_device *hdev;
Jeeja KP754695f2017-02-06 12:09:14 +053089};
90
91struct hdac_hdmi_port {
Jeeja KPe0e5d3e2017-02-07 19:09:48 +053092 struct list_head head;
Jeeja KP754695f2017-02-06 12:09:14 +053093 int id;
94 struct hdac_hdmi_pin *pin;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +053095 int num_mux_nids;
96 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +053097 struct hdac_hdmi_eld eld;
Jeeja KP0324e512017-02-07 19:09:55 +053098 const char *jack_pin;
99 struct snd_soc_dapm_context *dapm;
100 const char *output_pin;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530101};
102
Jeeja KP4a3478d2016-02-12 07:46:06 +0530103struct hdac_hdmi_pcm {
104 struct list_head head;
105 int pcm_id;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530106 struct list_head port_list;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530107 struct hdac_hdmi_cvt *cvt;
Jeeja KP62490012017-02-07 19:09:49 +0530108 struct snd_soc_jack *jack;
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530109 int stream_tag;
110 int channels;
111 int format;
Jeeja KPab1eea12017-01-24 21:49:05 +0530112 bool chmap_set;
113 unsigned char chmap[8]; /* ALSA API channel-map */
114 struct mutex lock;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530115 int jack_event;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530116};
117
Jeeja KP754695f2017-02-06 12:09:14 +0530118struct hdac_hdmi_dai_port_map {
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530119 int dai_id;
Jeeja KP754695f2017-02-06 12:09:14 +0530120 struct hdac_hdmi_port *port;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +0530121 struct hdac_hdmi_cvt *cvt;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530122};
123
Pradeep Tewani5622bc92017-07-20 11:40:56 +0530124struct hdac_hdmi_drv_data {
125 unsigned int vendor_nid;
126};
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);
450 struct hdac_device *hdev = hdmi->hdev;
Jeeja KP754695f2017-02-06 12:09:14 +0530451 struct hdac_hdmi_dai_port_map *dai_map;
452 struct hdac_hdmi_port *port;
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530453 struct hdac_hdmi_pcm *pcm;
454 int format;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530455
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530456 dai_map = &hdmi->dai_map[dai->id];
Jeeja KP754695f2017-02-06 12:09:14 +0530457 port = dai_map->port;
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530458
Jeeja KP754695f2017-02-06 12:09:14 +0530459 if (!port)
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530460 return -ENODEV;
461
Jeeja KP754695f2017-02-06 12:09:14 +0530462 if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500463 dev_err(&hdev->dev,
Jeeja KP754695f2017-02-06 12:09:14 +0530464 "device is not configured for this pin:port%d:%d\n",
465 port->pin->nid, port->id);
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530466 return -ENODEV;
467 }
468
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530469 format = snd_hdac_calc_stream_format(params_rate(hparams),
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530470 params_channels(hparams), params_format(hparams),
Jeeja KP66d6bbc2017-03-24 23:10:26 +0530471 dai->driver->playback.sig_bits, 0);
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530472
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530473 pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
474 if (!pcm)
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530475 return -EIO;
476
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530477 pcm->format = format;
478 pcm->channels = params_channels(hparams);
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530479
480 return 0;
481}
482
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500483static int hdac_hdmi_query_port_connlist(struct hdac_device *hdev,
Jeeja KP754695f2017-02-06 12:09:14 +0530484 struct hdac_hdmi_pin *pin,
485 struct hdac_hdmi_port *port)
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530486{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500487 if (!(get_wcaps(hdev, pin->nid) & AC_WCAP_CONN_LIST)) {
488 dev_warn(&hdev->dev,
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530489 "HDMI: pin %d wcaps %#x does not support connection list\n",
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500490 pin->nid, get_wcaps(hdev, pin->nid));
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530491 return -EINVAL;
492 }
493
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500494 if (hdac_hdmi_port_select_set(hdev, port) < 0)
Jeeja KP1b46ebd2017-02-07 19:09:47 +0530495 return -EIO;
496
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500497 port->num_mux_nids = snd_hdac_get_connections(hdev, pin->nid,
Jeeja KP754695f2017-02-06 12:09:14 +0530498 port->mux_nids, HDA_MAX_CONNECTIONS);
499 if (port->num_mux_nids == 0)
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500500 dev_warn(&hdev->dev,
Jeeja KP754695f2017-02-06 12:09:14 +0530501 "No connections found for pin:port %d:%d\n",
502 pin->nid, port->id);
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530503
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500504 dev_dbg(&hdev->dev, "num_mux_nids %d for pin:port %d:%d\n",
Jeeja KP754695f2017-02-06 12:09:14 +0530505 port->num_mux_nids, pin->nid, port->id);
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530506
Jeeja KP754695f2017-02-06 12:09:14 +0530507 return port->num_mux_nids;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530508}
509
510/*
Jeeja KP754695f2017-02-06 12:09:14 +0530511 * Query pcm list and return port to which stream is routed.
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530512 *
Jeeja KP754695f2017-02-06 12:09:14 +0530513 * Also query connection list of the pin, to validate the cvt to port map.
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530514 *
Jeeja KP754695f2017-02-06 12:09:14 +0530515 * Same stream rendering to multiple ports simultaneously can be done
516 * possibly, but not supported for now in driver. So return the first port
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530517 * connected.
518 */
Jeeja KP754695f2017-02-06 12:09:14 +0530519static struct hdac_hdmi_port *hdac_hdmi_get_port_from_cvt(
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500520 struct hdac_device *hdev,
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530521 struct hdac_hdmi_priv *hdmi,
522 struct hdac_hdmi_cvt *cvt)
523{
524 struct hdac_hdmi_pcm *pcm;
Jeeja KP754695f2017-02-06 12:09:14 +0530525 struct hdac_hdmi_port *port = NULL;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530526 int ret, i;
527
528 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
529 if (pcm->cvt == cvt) {
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530530 if (list_empty(&pcm->port_list))
531 continue;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530532
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530533 list_for_each_entry(port, &pcm->port_list, head) {
534 mutex_lock(&pcm->lock);
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500535 ret = hdac_hdmi_query_port_connlist(hdev,
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530536 port->pin, port);
537 mutex_unlock(&pcm->lock);
538 if (ret < 0)
539 continue;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530540
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530541 for (i = 0; i < port->num_mux_nids; i++) {
542 if (port->mux_nids[i] == cvt->nid &&
543 port->eld.monitor_present &&
544 port->eld.eld_valid)
545 return port;
546 }
547 }
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530548 }
549 }
550
551 return NULL;
552}
553
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530554/*
555 * This tries to get a valid pin and set the HW constraints based on the
556 * ELD. Even if a valid pin is not found return success so that device open
557 * doesn't fail.
558 */
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530559static int hdac_hdmi_pcm_open(struct snd_pcm_substream *substream,
560 struct snd_soc_dai *dai)
561{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500562 struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
563 struct hdac_device *hdev = hdmi->hdev;
Jeeja KP754695f2017-02-06 12:09:14 +0530564 struct hdac_hdmi_dai_port_map *dai_map;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530565 struct hdac_hdmi_cvt *cvt;
Jeeja KP754695f2017-02-06 12:09:14 +0530566 struct hdac_hdmi_port *port;
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +0530567 int ret;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530568
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530569 dai_map = &hdmi->dai_map[dai->id];
570
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530571 cvt = dai_map->cvt;
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500572 port = hdac_hdmi_get_port_from_cvt(hdev, hdmi, cvt);
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530573
574 /*
575 * To make PA and other userland happy.
576 * userland scans devices so returning error does not help.
577 */
Jeeja KP754695f2017-02-06 12:09:14 +0530578 if (!port)
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530579 return 0;
Jeeja KP754695f2017-02-06 12:09:14 +0530580 if ((!port->eld.monitor_present) ||
581 (!port->eld.eld_valid)) {
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530582
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500583 dev_warn(&hdev->dev,
Jeeja KP754695f2017-02-06 12:09:14 +0530584 "Failed: present?:%d ELD valid?:%d pin:port: %d:%d\n",
585 port->eld.monitor_present, port->eld.eld_valid,
586 port->pin->nid, port->id);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +0530587
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530588 return 0;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530589 }
590
Jeeja KP754695f2017-02-06 12:09:14 +0530591 dai_map->port = port;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530592
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +0530593 ret = hdac_hdmi_eld_limit_formats(substream->runtime,
Jeeja KP754695f2017-02-06 12:09:14 +0530594 port->eld.eld_buffer);
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +0530595 if (ret < 0)
596 return ret;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530597
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +0530598 return snd_pcm_hw_constraint_eld(substream->runtime,
Jeeja KP754695f2017-02-06 12:09:14 +0530599 port->eld.eld_buffer);
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530600}
601
602static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,
603 struct snd_soc_dai *dai)
604{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500605 struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
Jeeja KP754695f2017-02-06 12:09:14 +0530606 struct hdac_hdmi_dai_port_map *dai_map;
Jeeja KPab1eea12017-01-24 21:49:05 +0530607 struct hdac_hdmi_pcm *pcm;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530608
609 dai_map = &hdmi->dai_map[dai->id];
610
Jeeja KPab1eea12017-01-24 21:49:05 +0530611 pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530612
Jeeja KPab1eea12017-01-24 21:49:05 +0530613 if (pcm) {
614 mutex_lock(&pcm->lock);
615 pcm->chmap_set = false;
616 memset(pcm->chmap, 0, sizeof(pcm->chmap));
617 pcm->channels = 0;
618 mutex_unlock(&pcm->lock);
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530619 }
Jeeja KPab1eea12017-01-24 21:49:05 +0530620
Jeeja KP754695f2017-02-06 12:09:14 +0530621 if (dai_map->port)
622 dai_map->port = NULL;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530623}
624
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530625static int
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530626hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct hdac_hdmi_cvt *cvt)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530627{
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530628 unsigned int chans;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530629 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530630 int err;
631
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530632 chans = get_wcaps(hdev, cvt->nid);
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530633 chans = get_wcaps_channels(chans);
634
635 cvt->params.channels_min = 2;
636
637 cvt->params.channels_max = chans;
638 if (chans > hdmi->chmap.channels_max)
639 hdmi->chmap.channels_max = chans;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530640
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530641 err = snd_hdac_query_supported_pcm(hdev, cvt->nid,
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530642 &cvt->params.rates,
643 &cvt->params.formats,
644 &cvt->params.maxbps);
645 if (err < 0)
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530646 dev_err(&hdev->dev,
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530647 "Failed to query pcm params for nid %d: %d\n",
648 cvt->nid, err);
649
650 return err;
651}
652
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530653static int hdac_hdmi_fill_widget_info(struct device *dev,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530654 struct snd_soc_dapm_widget *w, enum snd_soc_dapm_type id,
655 void *priv, const char *wname, const char *stream,
656 struct snd_kcontrol_new *wc, int numkc,
657 int (*event)(struct snd_soc_dapm_widget *,
658 struct snd_kcontrol *, int), unsigned short event_flags)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530659{
660 w->id = id;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530661 w->name = devm_kstrdup(dev, wname, GFP_KERNEL);
662 if (!w->name)
663 return -ENOMEM;
664
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530665 w->sname = stream;
666 w->reg = SND_SOC_NOPM;
667 w->shift = 0;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530668 w->kcontrol_news = wc;
669 w->num_kcontrols = numkc;
670 w->priv = priv;
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530671 w->event = event;
672 w->event_flags = event_flags;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530673
674 return 0;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530675}
676
677static void hdac_hdmi_fill_route(struct snd_soc_dapm_route *route,
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530678 const char *sink, const char *control, const char *src,
679 int (*handler)(struct snd_soc_dapm_widget *src,
680 struct snd_soc_dapm_widget *sink))
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530681{
682 route->sink = sink;
683 route->source = src;
684 route->control = control;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530685 route->connected = handler;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530686}
687
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500688static struct hdac_hdmi_pcm *hdac_hdmi_get_pcm(struct hdac_device *hdev,
Jeeja KP754695f2017-02-06 12:09:14 +0530689 struct hdac_hdmi_port *port)
Jeeja KP4a3478d2016-02-12 07:46:06 +0530690{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500691 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Jeeja KP4a3478d2016-02-12 07:46:06 +0530692 struct hdac_hdmi_pcm *pcm = NULL;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530693 struct hdac_hdmi_port *p;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530694
695 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530696 if (list_empty(&pcm->port_list))
Jeeja KP754695f2017-02-06 12:09:14 +0530697 continue;
698
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530699 list_for_each_entry(p, &pcm->port_list, head) {
700 if (p->id == port->id && port->pin == p->pin)
701 return pcm;
702 }
Jeeja KP4a3478d2016-02-12 07:46:06 +0530703 }
704
705 return NULL;
706}
707
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500708static void hdac_hdmi_set_power_state(struct hdac_device *hdev,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530709 hda_nid_t nid, unsigned int pwr_state)
710{
Abhijeet Kumar753597f2018-02-15 14:05:38 +0530711 int count;
712 unsigned int state;
713
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500714 if (get_wcaps(hdev, nid) & AC_WCAP_POWER) {
715 if (!snd_hdac_check_power_state(hdev, nid, pwr_state)) {
Abhijeet Kumar753597f2018-02-15 14:05:38 +0530716 for (count = 0; count < 10; count++) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500717 snd_hdac_codec_read(hdev, nid, 0,
Abhijeet Kumar753597f2018-02-15 14:05:38 +0530718 AC_VERB_SET_POWER_STATE,
719 pwr_state);
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500720 state = snd_hdac_sync_power_state(hdev,
Abhijeet Kumar753597f2018-02-15 14:05:38 +0530721 nid, pwr_state);
722 if (!(state & AC_PWRST_ERROR))
723 break;
724 }
725 }
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530726 }
727}
728
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500729static void hdac_hdmi_set_amp(struct hdac_device *hdev,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530730 hda_nid_t nid, int val)
731{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500732 if (get_wcaps(hdev, nid) & AC_WCAP_OUT_AMP)
733 snd_hdac_codec_write(hdev, nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530734 AC_VERB_SET_AMP_GAIN_MUTE, val);
735}
736
737
738static int hdac_hdmi_pin_output_widget_event(struct snd_soc_dapm_widget *w,
739 struct snd_kcontrol *kc, int event)
740{
Jeeja KP754695f2017-02-06 12:09:14 +0530741 struct hdac_hdmi_port *port = w->priv;
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500742 struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530743 struct hdac_hdmi_pcm *pcm;
744
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500745 dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n",
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530746 __func__, w->name, event);
747
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500748 pcm = hdac_hdmi_get_pcm(hdev, port);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530749 if (!pcm)
750 return -EIO;
751
Jeeja KP1b46ebd2017-02-07 19:09:47 +0530752 /* set the device if pin is mst_capable */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500753 if (hdac_hdmi_port_select_set(hdev, port) < 0)
Jeeja KP1b46ebd2017-02-07 19:09:47 +0530754 return -EIO;
755
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530756 switch (event) {
757 case SND_SOC_DAPM_PRE_PMU:
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500758 hdac_hdmi_set_power_state(hdev, port->pin->nid, AC_PWRST_D0);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530759
760 /* Enable out path for this pin widget */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500761 snd_hdac_codec_write(hdev, port->pin->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530762 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
763
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500764 hdac_hdmi_set_amp(hdev, port->pin->nid, AMP_OUT_UNMUTE);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530765
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500766 return hdac_hdmi_setup_audio_infoframe(hdev, pcm, port);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530767
768 case SND_SOC_DAPM_POST_PMD:
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500769 hdac_hdmi_set_amp(hdev, port->pin->nid, AMP_OUT_MUTE);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530770
771 /* Disable out path for this pin widget */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500772 snd_hdac_codec_write(hdev, port->pin->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530773 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
774
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500775 hdac_hdmi_set_power_state(hdev, port->pin->nid, AC_PWRST_D3);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530776 break;
777
778 }
779
780 return 0;
781}
782
783static int hdac_hdmi_cvt_output_widget_event(struct snd_soc_dapm_widget *w,
784 struct snd_kcontrol *kc, int event)
785{
786 struct hdac_hdmi_cvt *cvt = w->priv;
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500787 struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev);
788 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530789 struct hdac_hdmi_pcm *pcm;
790
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500791 dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n",
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530792 __func__, w->name, event);
793
794 pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, cvt);
795 if (!pcm)
796 return -EIO;
797
798 switch (event) {
799 case SND_SOC_DAPM_PRE_PMU:
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500800 hdac_hdmi_set_power_state(hdev, cvt->nid, AC_PWRST_D0);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530801
802 /* Enable transmission */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500803 snd_hdac_codec_write(hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530804 AC_VERB_SET_DIGI_CONVERT_1, 1);
805
806 /* Category Code (CC) to zero */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500807 snd_hdac_codec_write(hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530808 AC_VERB_SET_DIGI_CONVERT_2, 0);
809
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500810 snd_hdac_codec_write(hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530811 AC_VERB_SET_CHANNEL_STREAMID, pcm->stream_tag);
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500812 snd_hdac_codec_write(hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530813 AC_VERB_SET_STREAM_FORMAT, pcm->format);
814 break;
815
816 case SND_SOC_DAPM_POST_PMD:
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500817 snd_hdac_codec_write(hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530818 AC_VERB_SET_CHANNEL_STREAMID, 0);
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500819 snd_hdac_codec_write(hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530820 AC_VERB_SET_STREAM_FORMAT, 0);
821
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500822 hdac_hdmi_set_power_state(hdev, cvt->nid, AC_PWRST_D3);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530823 break;
824
825 }
826
827 return 0;
828}
829
830static int hdac_hdmi_pin_mux_widget_event(struct snd_soc_dapm_widget *w,
831 struct snd_kcontrol *kc, int event)
832{
Jeeja KP754695f2017-02-06 12:09:14 +0530833 struct hdac_hdmi_port *port = w->priv;
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500834 struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530835 int mux_idx;
836
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500837 dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n",
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530838 __func__, w->name, event);
839
840 if (!kc)
841 kc = w->kcontrols[0];
842
843 mux_idx = dapm_kcontrol_get_value(kc);
Jeeja KP1b46ebd2017-02-07 19:09:47 +0530844
845 /* set the device if pin is mst_capable */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500846 if (hdac_hdmi_port_select_set(hdev, port) < 0)
Jeeja KP1b46ebd2017-02-07 19:09:47 +0530847 return -EIO;
848
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530849 if (mux_idx > 0) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500850 snd_hdac_codec_write(hdev, port->pin->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530851 AC_VERB_SET_CONNECT_SEL, (mux_idx - 1));
852 }
853
854 return 0;
855}
856
Jeeja KP4a3478d2016-02-12 07:46:06 +0530857/*
858 * Based on user selection, map the PINs with the PCMs.
859 */
Jeeja KP754695f2017-02-06 12:09:14 +0530860static int hdac_hdmi_set_pin_port_mux(struct snd_kcontrol *kcontrol,
Jeeja KP4a3478d2016-02-12 07:46:06 +0530861 struct snd_ctl_elem_value *ucontrol)
862{
863 int ret;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530864 struct hdac_hdmi_port *p, *p_next;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530865 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
866 struct snd_soc_dapm_widget *w = snd_soc_dapm_kcontrol_widget(kcontrol);
867 struct snd_soc_dapm_context *dapm = w->dapm;
Jeeja KP754695f2017-02-06 12:09:14 +0530868 struct hdac_hdmi_port *port = w->priv;
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500869 struct hdac_device *hdev = dev_to_hdac_dev(dapm->dev);
870 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Jeeja KP4a3478d2016-02-12 07:46:06 +0530871 struct hdac_hdmi_pcm *pcm = NULL;
872 const char *cvt_name = e->texts[ucontrol->value.enumerated.item[0]];
873
874 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
875 if (ret < 0)
876 return ret;
877
Jeeja KP754695f2017-02-06 12:09:14 +0530878 if (port == NULL)
879 return -EINVAL;
880
Jeeja KP4a3478d2016-02-12 07:46:06 +0530881 mutex_lock(&hdmi->pin_mutex);
882 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530883 if (list_empty(&pcm->port_list))
884 continue;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530885
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530886 list_for_each_entry_safe(p, p_next, &pcm->port_list, head) {
887 if (p == port && p->id == port->id &&
888 p->pin == port->pin) {
889 hdac_hdmi_jack_report(pcm, port, false);
890 list_del(&p->head);
Jeeja KP4a3478d2016-02-12 07:46:06 +0530891 }
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530892 }
893 }
894
895 /*
896 * Jack status is not reported during device probe as the
897 * PCMs are not registered by then. So report it here.
898 */
899 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
900 if (!strcmp(cvt_name, pcm->cvt->name)) {
901 list_add_tail(&port->head, &pcm->port_list);
902 if (port->eld.monitor_present && port->eld.eld_valid) {
903 hdac_hdmi_jack_report(pcm, port, true);
904 mutex_unlock(&hdmi->pin_mutex);
905 return ret;
906 }
Jeeja KP4a3478d2016-02-12 07:46:06 +0530907 }
908 }
909 mutex_unlock(&hdmi->pin_mutex);
910
911 return ret;
912}
913
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530914/*
915 * Ideally the Mux inputs should be based on the num_muxs enumerated, but
916 * the display driver seem to be programming the connection list for the pin
917 * widget runtime.
918 *
919 * So programming all the possible inputs for the mux, the user has to take
920 * care of selecting the right one and leaving all other inputs selected to
921 * "NONE"
922 */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500923static int hdac_hdmi_create_pin_port_muxs(struct hdac_device *hdev,
Jeeja KP754695f2017-02-06 12:09:14 +0530924 struct hdac_hdmi_port *port,
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530925 struct snd_soc_dapm_widget *widget,
926 const char *widget_name)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530927{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500928 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Jeeja KP754695f2017-02-06 12:09:14 +0530929 struct hdac_hdmi_pin *pin = port->pin;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530930 struct snd_kcontrol_new *kc;
931 struct hdac_hdmi_cvt *cvt;
932 struct soc_enum *se;
933 char kc_name[NAME_SIZE];
934 char mux_items[NAME_SIZE];
935 /* To hold inputs to the Pin mux */
936 char *items[HDA_MAX_CONNECTIONS];
937 int i = 0;
938 int num_items = hdmi->num_cvt + 1;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530939
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500940 kc = devm_kzalloc(&hdev->dev, sizeof(*kc), GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530941 if (!kc)
942 return -ENOMEM;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530943
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500944 se = devm_kzalloc(&hdev->dev, sizeof(*se), GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530945 if (!se)
946 return -ENOMEM;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530947
Subhransu S. Prusty70e97a22017-11-07 16:16:24 +0530948 snprintf(kc_name, NAME_SIZE, "Pin %d port %d Input",
949 pin->nid, port->id);
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500950 kc->name = devm_kstrdup(&hdev->dev, kc_name, GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530951 if (!kc->name)
952 return -ENOMEM;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530953
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530954 kc->private_value = (long)se;
955 kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
956 kc->access = 0;
957 kc->info = snd_soc_info_enum_double;
Jeeja KP754695f2017-02-06 12:09:14 +0530958 kc->put = hdac_hdmi_set_pin_port_mux;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530959 kc->get = snd_soc_dapm_get_enum_double;
960
961 se->reg = SND_SOC_NOPM;
962
963 /* enum texts: ["NONE", "cvt #", "cvt #", ...] */
964 se->items = num_items;
965 se->mask = roundup_pow_of_two(se->items) - 1;
966
967 sprintf(mux_items, "NONE");
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500968 items[i] = devm_kstrdup(&hdev->dev, mux_items, GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530969 if (!items[i])
970 return -ENOMEM;
971
972 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
973 i++;
974 sprintf(mux_items, "cvt %d", cvt->nid);
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500975 items[i] = devm_kstrdup(&hdev->dev, mux_items, GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530976 if (!items[i])
977 return -ENOMEM;
978 }
979
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500980 se->texts = devm_kmemdup(&hdev->dev, items,
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530981 (num_items * sizeof(char *)), GFP_KERNEL);
982 if (!se->texts)
983 return -ENOMEM;
984
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500985 return hdac_hdmi_fill_widget_info(&hdev->dev, widget,
Jeeja KP754695f2017-02-06 12:09:14 +0530986 snd_soc_dapm_mux, port, widget_name, NULL, kc, 1,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530987 hdac_hdmi_pin_mux_widget_event,
988 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_REG);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530989}
990
991/* Add cvt <- input <- mux route map */
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500992static void hdac_hdmi_add_pinmux_cvt_route(struct hdac_device *hdev,
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530993 struct snd_soc_dapm_widget *widgets,
994 struct snd_soc_dapm_route *route, int rindex)
995{
Rakesh Ughreja3787a392018-06-01 22:53:49 -0500996 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530997 const struct snd_kcontrol_new *kc;
998 struct soc_enum *se;
Jeeja KP754695f2017-02-06 12:09:14 +0530999 int mux_index = hdmi->num_cvt + hdmi->num_ports;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301000 int i, j;
1001
Jeeja KP754695f2017-02-06 12:09:14 +05301002 for (i = 0; i < hdmi->num_ports; i++) {
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301003 kc = widgets[mux_index].kcontrol_news;
1004 se = (struct soc_enum *)kc->private_value;
1005 for (j = 0; j < hdmi->num_cvt; j++) {
1006 hdac_hdmi_fill_route(&route[rindex],
1007 widgets[mux_index].name,
1008 se->texts[j + 1],
1009 widgets[j].name, NULL);
1010
1011 rindex++;
1012 }
1013
1014 mux_index++;
1015 }
1016}
1017
1018/*
1019 * Widgets are added in the below sequence
1020 * Converter widgets for num converters enumerated
Jeeja KP754695f2017-02-06 12:09:14 +05301021 * Pin-port widgets for num ports for Pins enumerated
1022 * Pin-port mux widgets to represent connenction list of pin widget
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301023 *
Jeeja KP754695f2017-02-06 12:09:14 +05301024 * For each port, one Mux and One output widget is added
1025 * Total widgets elements = num_cvt + (num_ports * 2);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301026 *
1027 * Routes are added as below:
Jeeja KP754695f2017-02-06 12:09:14 +05301028 * pin-port mux -> pin (based on num_ports)
1029 * cvt -> "Input sel control" -> pin-port_mux
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301030 *
1031 * Total route elements:
Jeeja KP754695f2017-02-06 12:09:14 +05301032 * num_ports + (pin_muxes * num_cvt)
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301033 */
1034static int create_fill_widget_route_map(struct snd_soc_dapm_context *dapm)
1035{
1036 struct snd_soc_dapm_widget *widgets;
1037 struct snd_soc_dapm_route *route;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001038 struct hdac_device *hdev = dev_to_hdac_dev(dapm->dev);
1039 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Kuninori Morimoto1e02dac2017-12-20 01:48:13 +00001040 struct snd_soc_dai_driver *dai_drv = hdmi->dai_drv;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301041 char widget_name[NAME_SIZE];
1042 struct hdac_hdmi_cvt *cvt;
1043 struct hdac_hdmi_pin *pin;
Jeeja KP754695f2017-02-06 12:09:14 +05301044 int ret, i = 0, num_routes = 0, j;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301045
1046 if (list_empty(&hdmi->cvt_list) || list_empty(&hdmi->pin_list))
1047 return -EINVAL;
1048
Jeeja KP754695f2017-02-06 12:09:14 +05301049 widgets = devm_kzalloc(dapm->dev, (sizeof(*widgets) *
1050 ((2 * hdmi->num_ports) + hdmi->num_cvt)),
1051 GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301052
1053 if (!widgets)
1054 return -ENOMEM;
1055
1056 /* DAPM widgets to represent each converter widget */
1057 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
1058 sprintf(widget_name, "Converter %d", cvt->nid);
1059 ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
Jeeja KPc9bfb5d2017-01-24 21:49:03 +05301060 snd_soc_dapm_aif_in, cvt,
1061 widget_name, dai_drv[i].playback.stream_name, NULL, 0,
1062 hdac_hdmi_cvt_output_widget_event,
1063 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301064 if (ret < 0)
1065 return ret;
1066 i++;
1067 }
1068
1069 list_for_each_entry(pin, &hdmi->pin_list, head) {
Jeeja KP754695f2017-02-06 12:09:14 +05301070 for (j = 0; j < pin->num_ports; j++) {
1071 sprintf(widget_name, "hif%d-%d Output",
1072 pin->nid, pin->ports[j].id);
1073 ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
1074 snd_soc_dapm_output, &pin->ports[j],
1075 widget_name, NULL, NULL, 0,
1076 hdac_hdmi_pin_output_widget_event,
1077 SND_SOC_DAPM_PRE_PMU |
1078 SND_SOC_DAPM_POST_PMD);
1079 if (ret < 0)
1080 return ret;
Jeeja KP0324e512017-02-07 19:09:55 +05301081 pin->ports[j].output_pin = widgets[i].name;
Jeeja KP754695f2017-02-06 12:09:14 +05301082 i++;
1083 }
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301084 }
1085
1086 /* DAPM widgets to represent the connection list to pin widget */
1087 list_for_each_entry(pin, &hdmi->pin_list, head) {
Jeeja KP754695f2017-02-06 12:09:14 +05301088 for (j = 0; j < pin->num_ports; j++) {
1089 sprintf(widget_name, "Pin%d-Port%d Mux",
1090 pin->nid, pin->ports[j].id);
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001091 ret = hdac_hdmi_create_pin_port_muxs(hdev,
Jeeja KP754695f2017-02-06 12:09:14 +05301092 &pin->ports[j], &widgets[i],
1093 widget_name);
1094 if (ret < 0)
1095 return ret;
1096 i++;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301097
Jeeja KP754695f2017-02-06 12:09:14 +05301098 /* For cvt to pin_mux mapping */
1099 num_routes += hdmi->num_cvt;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301100
Jeeja KP754695f2017-02-06 12:09:14 +05301101 /* For pin_mux to pin mapping */
1102 num_routes++;
1103 }
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301104 }
1105
1106 route = devm_kzalloc(dapm->dev, (sizeof(*route) * num_routes),
1107 GFP_KERNEL);
1108 if (!route)
1109 return -ENOMEM;
1110
1111 i = 0;
1112 /* Add pin <- NULL <- mux route map */
1113 list_for_each_entry(pin, &hdmi->pin_list, head) {
Jeeja KP754695f2017-02-06 12:09:14 +05301114 for (j = 0; j < pin->num_ports; j++) {
1115 int sink_index = i + hdmi->num_cvt;
1116 int src_index = sink_index + pin->num_ports *
1117 hdmi->num_pin;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301118
Jeeja KP754695f2017-02-06 12:09:14 +05301119 hdac_hdmi_fill_route(&route[i],
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301120 widgets[sink_index].name, NULL,
1121 widgets[src_index].name, NULL);
Jeeja KP754695f2017-02-06 12:09:14 +05301122 i++;
1123 }
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301124 }
1125
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001126 hdac_hdmi_add_pinmux_cvt_route(hdev, widgets, route, i);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301127
1128 snd_soc_dapm_new_controls(dapm, widgets,
Jeeja KP754695f2017-02-06 12:09:14 +05301129 ((2 * hdmi->num_ports) + hdmi->num_cvt));
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301130
1131 snd_soc_dapm_add_routes(dapm, route, num_routes);
1132 snd_soc_dapm_new_widgets(dapm->card);
1133
1134 return 0;
1135
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301136}
1137
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001138static int hdac_hdmi_init_dai_map(struct hdac_device *hdev)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301139{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001140 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Jeeja KP754695f2017-02-06 12:09:14 +05301141 struct hdac_hdmi_dai_port_map *dai_map;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301142 struct hdac_hdmi_cvt *cvt;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301143 int dai_id = 0;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301144
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301145 if (list_empty(&hdmi->cvt_list))
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301146 return -EINVAL;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301147
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301148 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
1149 dai_map = &hdmi->dai_map[dai_id];
1150 dai_map->dai_id = dai_id;
1151 dai_map->cvt = cvt;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301152
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301153 dai_id++;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301154
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301155 if (dai_id == HDA_MAX_CVTS) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001156 dev_warn(&hdev->dev,
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301157 "Max dais supported: %d\n", dai_id);
1158 break;
1159 }
1160 }
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301161
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301162 return 0;
1163}
1164
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001165static int hdac_hdmi_add_cvt(struct hdac_device *hdev, hda_nid_t nid)
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301166{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001167 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301168 struct hdac_hdmi_cvt *cvt;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301169 char name[NAME_SIZE];
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301170
1171 cvt = kzalloc(sizeof(*cvt), GFP_KERNEL);
1172 if (!cvt)
1173 return -ENOMEM;
1174
1175 cvt->nid = nid;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301176 sprintf(name, "cvt %d", cvt->nid);
1177 cvt->name = kstrdup(name, GFP_KERNEL);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301178
1179 list_add_tail(&cvt->head, &hdmi->cvt_list);
1180 hdmi->num_cvt++;
1181
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001182 return hdac_hdmi_query_cvt_params(hdev, cvt);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301183}
1184
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001185static int hdac_hdmi_parse_eld(struct hdac_device *hdev,
Jeeja KP754695f2017-02-06 12:09:14 +05301186 struct hdac_hdmi_port *port)
Subhransu S. Prustyb7756ed2016-04-14 10:07:28 +05301187{
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301188 unsigned int ver, mnl;
1189
Jeeja KP754695f2017-02-06 12:09:14 +05301190 ver = (port->eld.eld_buffer[DRM_ELD_VER] & DRM_ELD_VER_MASK)
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301191 >> DRM_ELD_VER_SHIFT;
1192
1193 if (ver != ELD_VER_CEA_861D && ver != ELD_VER_PARTIAL) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001194 dev_err(&hdev->dev, "HDMI: Unknown ELD version %d\n", ver);
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301195 return -EINVAL;
1196 }
1197
Jeeja KP754695f2017-02-06 12:09:14 +05301198 mnl = (port->eld.eld_buffer[DRM_ELD_CEA_EDID_VER_MNL] &
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301199 DRM_ELD_MNL_MASK) >> DRM_ELD_MNL_SHIFT;
1200
1201 if (mnl > ELD_MAX_MNL) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001202 dev_err(&hdev->dev, "HDMI: MNL Invalid %d\n", mnl);
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301203 return -EINVAL;
1204 }
1205
Jeeja KP754695f2017-02-06 12:09:14 +05301206 port->eld.info.spk_alloc = port->eld.eld_buffer[DRM_ELD_SPEAKER];
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301207
1208 return 0;
Subhransu S. Prustyb7756ed2016-04-14 10:07:28 +05301209}
1210
Jeeja KP754695f2017-02-06 12:09:14 +05301211static void hdac_hdmi_present_sense(struct hdac_hdmi_pin *pin,
1212 struct hdac_hdmi_port *port)
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301213{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001214 struct hdac_device *hdev = pin->hdev;
1215 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Jeeja KP4a3478d2016-02-12 07:46:06 +05301216 struct hdac_hdmi_pcm *pcm;
Jeeja KP754695f2017-02-06 12:09:14 +05301217 int size = 0;
Jeeja KP2acd8302017-02-06 12:09:18 +05301218 int port_id = -1;
Jeeja KP754695f2017-02-06 12:09:14 +05301219
1220 if (!hdmi)
1221 return;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301222
Jeeja KP2acd8302017-02-06 12:09:18 +05301223 /*
1224 * In case of non MST pin, get_eld info API expectes port
1225 * to be -1.
1226 */
Jeeja KP4a3478d2016-02-12 07:46:06 +05301227 mutex_lock(&hdmi->pin_mutex);
Jeeja KP754695f2017-02-06 12:09:14 +05301228 port->eld.monitor_present = false;
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301229
Jeeja KP2acd8302017-02-06 12:09:18 +05301230 if (pin->mst_capable)
1231 port_id = port->id;
1232
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001233 size = snd_hdac_acomp_get_eld(hdev, pin->nid, port_id,
Jeeja KP754695f2017-02-06 12:09:14 +05301234 &port->eld.monitor_present,
1235 port->eld.eld_buffer,
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301236 ELD_MAX_SIZE);
1237
1238 if (size > 0) {
1239 size = min(size, ELD_MAX_SIZE);
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001240 if (hdac_hdmi_parse_eld(hdev, port) < 0)
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301241 size = -EINVAL;
1242 }
1243
1244 if (size > 0) {
Jeeja KP754695f2017-02-06 12:09:14 +05301245 port->eld.eld_valid = true;
1246 port->eld.eld_size = size;
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301247 } else {
Jeeja KP754695f2017-02-06 12:09:14 +05301248 port->eld.eld_valid = false;
1249 port->eld.eld_size = 0;
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301250 }
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301251
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001252 pcm = hdac_hdmi_get_pcm(hdev, port);
Jeeja KP4a3478d2016-02-12 07:46:06 +05301253
Jeeja KP754695f2017-02-06 12:09:14 +05301254 if (!port->eld.monitor_present || !port->eld.eld_valid) {
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301255
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001256 dev_err(&hdev->dev, "%s: disconnect for pin:port %d:%d\n",
Jeeja KP754695f2017-02-06 12:09:14 +05301257 __func__, pin->nid, port->id);
Jeeja KP4a3478d2016-02-12 07:46:06 +05301258
1259 /*
1260 * PCMs are not registered during device probe, so don't
1261 * report jack here. It will be done in usermode mux
1262 * control select.
1263 */
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301264 if (pcm)
1265 hdac_hdmi_jack_report(pcm, port, false);
Jeeja KP4a3478d2016-02-12 07:46:06 +05301266
1267 mutex_unlock(&hdmi->pin_mutex);
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301268 return;
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301269 }
1270
Jeeja KP754695f2017-02-06 12:09:14 +05301271 if (port->eld.monitor_present && port->eld.eld_valid) {
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301272 if (pcm)
1273 hdac_hdmi_jack_report(pcm, port, true);
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301274
1275 print_hex_dump_debug("ELD: ", DUMP_PREFIX_OFFSET, 16, 1,
Jeeja KP754695f2017-02-06 12:09:14 +05301276 port->eld.eld_buffer, port->eld.eld_size, false);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301277
Jeeja KP754695f2017-02-06 12:09:14 +05301278 }
Jeeja KP4a3478d2016-02-12 07:46:06 +05301279 mutex_unlock(&hdmi->pin_mutex);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301280}
1281
Jeeja KP754695f2017-02-06 12:09:14 +05301282static int hdac_hdmi_add_ports(struct hdac_hdmi_priv *hdmi,
1283 struct hdac_hdmi_pin *pin)
1284{
1285 struct hdac_hdmi_port *ports;
1286 int max_ports = HDA_MAX_PORTS;
1287 int i;
1288
1289 /*
1290 * FIXME: max_port may vary for each platform, so pass this as
1291 * as driver data or query from i915 interface when this API is
1292 * implemented.
1293 */
1294
1295 ports = kcalloc(max_ports, sizeof(*ports), GFP_KERNEL);
1296 if (!ports)
1297 return -ENOMEM;
1298
1299 for (i = 0; i < max_ports; i++) {
1300 ports[i].id = i;
1301 ports[i].pin = pin;
1302 }
1303 pin->ports = ports;
1304 pin->num_ports = max_ports;
1305 return 0;
1306}
1307
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001308static int hdac_hdmi_add_pin(struct hdac_device *hdev, hda_nid_t nid)
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301309{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001310 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301311 struct hdac_hdmi_pin *pin;
Jeeja KP754695f2017-02-06 12:09:14 +05301312 int ret;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301313
1314 pin = kzalloc(sizeof(*pin), GFP_KERNEL);
1315 if (!pin)
1316 return -ENOMEM;
1317
1318 pin->nid = nid;
Jeeja KP2acd8302017-02-06 12:09:18 +05301319 pin->mst_capable = false;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001320 pin->hdev = hdev;
Jeeja KP754695f2017-02-06 12:09:14 +05301321 ret = hdac_hdmi_add_ports(hdmi, pin);
1322 if (ret < 0)
1323 return ret;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301324
1325 list_add_tail(&pin->head, &hdmi->pin_list);
1326 hdmi->num_pin++;
Jeeja KP754695f2017-02-06 12:09:14 +05301327 hdmi->num_ports += pin->num_ports;
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301328
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301329 return 0;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301330}
1331
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301332#define INTEL_VENDOR_NID 0x08
Pradeep Tewani5622bc92017-07-20 11:40:56 +05301333#define INTEL_GLK_VENDOR_NID 0x0b
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301334#define INTEL_GET_VENDOR_VERB 0xf81
1335#define INTEL_SET_VENDOR_VERB 0x781
1336#define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
1337#define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
1338
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301339static void hdac_hdmi_skl_enable_all_pins(struct hdac_device *hdev)
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301340{
1341 unsigned int vendor_param;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301342 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Pradeep Tewani5622bc92017-07-20 11:40:56 +05301343 unsigned int vendor_nid = hdmi->drv_data->vendor_nid;
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301344
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301345 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301346 INTEL_GET_VENDOR_VERB, 0);
1347 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
1348 return;
1349
1350 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301351 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301352 INTEL_SET_VENDOR_VERB, vendor_param);
1353 if (vendor_param == -1)
1354 return;
1355}
1356
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301357static void hdac_hdmi_skl_enable_dp12(struct hdac_device *hdev)
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301358{
1359 unsigned int vendor_param;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301360 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Pradeep Tewani5622bc92017-07-20 11:40:56 +05301361 unsigned int vendor_nid = hdmi->drv_data->vendor_nid;
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301362
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301363 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301364 INTEL_GET_VENDOR_VERB, 0);
1365 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
1366 return;
1367
1368 /* enable DP1.2 mode */
1369 vendor_param |= INTEL_EN_DP12;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301370 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301371 INTEL_SET_VENDOR_VERB, vendor_param);
1372 if (vendor_param == -1)
1373 return;
1374
1375}
1376
Gustavo A. R. Silva61b3b3c2017-07-13 15:38:38 -05001377static const struct snd_soc_dai_ops hdmi_dai_ops = {
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301378 .startup = hdac_hdmi_pcm_open,
1379 .shutdown = hdac_hdmi_pcm_close,
1380 .hw_params = hdac_hdmi_set_hw_params,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +05301381 .set_tdm_slot = hdac_hdmi_set_tdm_slot,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301382};
1383
1384/*
1385 * Each converter can support a stream independently. So a dai is created
1386 * based on the number of converter queried.
1387 */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301388static int hdac_hdmi_create_dais(struct hdac_device *hdev,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301389 struct snd_soc_dai_driver **dais,
1390 struct hdac_hdmi_priv *hdmi, int num_dais)
1391{
1392 struct snd_soc_dai_driver *hdmi_dais;
1393 struct hdac_hdmi_cvt *cvt;
1394 char name[NAME_SIZE], dai_name[NAME_SIZE];
1395 int i = 0;
1396 u32 rates, bps;
1397 unsigned int rate_max = 384000, rate_min = 8000;
1398 u64 formats;
1399 int ret;
1400
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301401 hdmi_dais = devm_kzalloc(&hdev->dev,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301402 (sizeof(*hdmi_dais) * num_dais),
1403 GFP_KERNEL);
1404 if (!hdmi_dais)
1405 return -ENOMEM;
1406
1407 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301408 ret = snd_hdac_query_supported_pcm(hdev, cvt->nid,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301409 &rates, &formats, &bps);
1410 if (ret)
1411 return ret;
1412
1413 sprintf(dai_name, "intel-hdmi-hifi%d", i+1);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301414 hdmi_dais[i].name = devm_kstrdup(&hdev->dev,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301415 dai_name, GFP_KERNEL);
1416
1417 if (!hdmi_dais[i].name)
1418 return -ENOMEM;
1419
1420 snprintf(name, sizeof(name), "hifi%d", i+1);
1421 hdmi_dais[i].playback.stream_name =
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301422 devm_kstrdup(&hdev->dev, name, GFP_KERNEL);
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301423 if (!hdmi_dais[i].playback.stream_name)
1424 return -ENOMEM;
1425
1426 /*
1427 * Set caps based on capability queried from the converter.
1428 * It will be constrained runtime based on ELD queried.
1429 */
1430 hdmi_dais[i].playback.formats = formats;
1431 hdmi_dais[i].playback.rates = rates;
1432 hdmi_dais[i].playback.rate_max = rate_max;
1433 hdmi_dais[i].playback.rate_min = rate_min;
1434 hdmi_dais[i].playback.channels_min = 2;
1435 hdmi_dais[i].playback.channels_max = 2;
Jeeja KP66d6bbc2017-03-24 23:10:26 +05301436 hdmi_dais[i].playback.sig_bits = bps;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301437 hdmi_dais[i].ops = &hdmi_dai_ops;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301438 i++;
1439 }
1440
1441 *dais = hdmi_dais;
Kuninori Morimoto1e02dac2017-12-20 01:48:13 +00001442 hdmi->dai_drv = hdmi_dais;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301443
1444 return 0;
1445}
1446
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301447/*
1448 * Parse all nodes and store the cvt/pin nids in array
1449 * Add one time initialization for pin and cvt widgets
1450 */
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001451static int hdac_hdmi_parse_and_map_nid(struct hdac_device *hdev,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301452 struct snd_soc_dai_driver **dais, int *num_dais)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301453{
1454 hda_nid_t nid;
Sudip Mukherjee3c83ac22015-12-01 14:29:35 +05301455 int i, num_nodes;
Subhransu S. Prusty1c0a7de2017-11-07 16:16:26 +05301456 struct hdac_hdmi_cvt *temp_cvt, *cvt_next;
1457 struct hdac_hdmi_pin *temp_pin, *pin_next;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001458 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301459 int ret;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301460
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301461 hdac_hdmi_skl_enable_all_pins(hdev);
1462 hdac_hdmi_skl_enable_dp12(hdev);
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301463
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301464 num_nodes = snd_hdac_get_sub_nodes(hdev, hdev->afg, &nid);
Subhransu S. Prusty541140d2015-12-09 21:46:08 +05301465 if (!nid || num_nodes <= 0) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301466 dev_warn(&hdev->dev, "HDMI: failed to get afg sub nodes\n");
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301467 return -EINVAL;
1468 }
1469
Puneeth Prabhu45a60082017-12-06 16:34:06 +05301470 for (i = 0; i < num_nodes; i++, nid++) {
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301471 unsigned int caps;
1472 unsigned int type;
1473
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301474 caps = get_wcaps(hdev, nid);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301475 type = get_wcaps_type(caps);
1476
1477 if (!(caps & AC_WCAP_DIGITAL))
1478 continue;
1479
1480 switch (type) {
1481
1482 case AC_WID_AUD_OUT:
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001483 ret = hdac_hdmi_add_cvt(hdev, nid);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301484 if (ret < 0)
Subhransu S. Prusty1c0a7de2017-11-07 16:16:26 +05301485 goto free_widgets;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301486 break;
1487
1488 case AC_WID_PIN:
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001489 ret = hdac_hdmi_add_pin(hdev, nid);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301490 if (ret < 0)
Subhransu S. Prusty1c0a7de2017-11-07 16:16:26 +05301491 goto free_widgets;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301492 break;
1493 }
1494 }
1495
Subhransu S. Prusty1c0a7de2017-11-07 16:16:26 +05301496 if (!hdmi->num_pin || !hdmi->num_cvt) {
1497 ret = -EIO;
1498 goto free_widgets;
1499 }
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301500
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301501 ret = hdac_hdmi_create_dais(hdev, dais, hdmi, hdmi->num_cvt);
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301502 if (ret) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301503 dev_err(&hdev->dev, "Failed to create dais with err: %d\n",
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301504 ret);
Subhransu S. Prusty1c0a7de2017-11-07 16:16:26 +05301505 goto free_widgets;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301506 }
1507
1508 *num_dais = hdmi->num_cvt;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001509 ret = hdac_hdmi_init_dai_map(hdev);
Subhransu S. Prusty1c0a7de2017-11-07 16:16:26 +05301510 if (ret < 0)
1511 goto free_widgets;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301512
Subhransu S. Prusty1c0a7de2017-11-07 16:16:26 +05301513 return ret;
1514
1515free_widgets:
1516 list_for_each_entry_safe(temp_cvt, cvt_next, &hdmi->cvt_list, head) {
1517 list_del(&temp_cvt->head);
1518 kfree(temp_cvt->name);
1519 kfree(temp_cvt);
1520 }
1521
1522 list_for_each_entry_safe(temp_pin, pin_next, &hdmi->pin_list, head) {
1523 for (i = 0; i < temp_pin->num_ports; i++)
1524 temp_pin->ports[i].pin = NULL;
1525 kfree(temp_pin->ports);
1526 list_del(&temp_pin->head);
1527 kfree(temp_pin);
1528 }
1529
1530 return ret;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301531}
1532
Takashi Iwaia57942b2018-07-11 16:23:16 +02001533static int hdac_hdmi_pin2port(void *aptr, int pin)
1534{
1535 return pin - 4; /* map NID 0x05 -> port #1 */
1536}
1537
Pandiyan, Dhinakaranf9318942016-09-21 13:02:48 -07001538static void hdac_hdmi_eld_notify_cb(void *aptr, int port, int pipe)
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301539{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001540 struct hdac_device *hdev = aptr;
1541 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Jeeja KP754695f2017-02-06 12:09:14 +05301542 struct hdac_hdmi_pin *pin = NULL;
1543 struct hdac_hdmi_port *hport = NULL;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001544 struct snd_soc_component *component = hdmi->component;
Jeeja KP2acd8302017-02-06 12:09:18 +05301545 int i;
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301546
1547 /* Don't know how this mapping is derived */
1548 hda_nid_t pin_nid = port + 0x04;
1549
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001550 dev_dbg(&hdev->dev, "%s: for pin:%d port=%d\n", __func__,
Jeeja KP754695f2017-02-06 12:09:14 +05301551 pin_nid, pipe);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301552
1553 /*
1554 * skip notification during system suspend (but not in runtime PM);
1555 * the state will be updated at resume. Also since the ELD and
1556 * connection states are updated in anyway at the end of the resume,
1557 * we can skip it when received during PM process.
1558 */
Kuninori Morimoto45101122018-01-29 04:36:54 +00001559 if (snd_power_get_state(component->card->snd_card) !=
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301560 SNDRV_CTL_POWER_D0)
1561 return;
1562
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001563 if (atomic_read(&hdev->in_pm))
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301564 return;
1565
1566 list_for_each_entry(pin, &hdmi->pin_list, head) {
Jeeja KP754695f2017-02-06 12:09:14 +05301567 if (pin->nid != pin_nid)
1568 continue;
1569
1570 /* In case of non MST pin, pipe is -1 */
1571 if (pipe == -1) {
Jeeja KP2acd8302017-02-06 12:09:18 +05301572 pin->mst_capable = false;
Jeeja KP754695f2017-02-06 12:09:14 +05301573 /* if not MST, default is port[0] */
1574 hport = &pin->ports[0];
Jeeja KP2acd8302017-02-06 12:09:18 +05301575 } else {
1576 for (i = 0; i < pin->num_ports; i++) {
1577 pin->mst_capable = true;
1578 if (pin->ports[i].id == pipe) {
1579 hport = &pin->ports[i];
Jeeja KP04c8f2b2017-03-01 22:41:23 +05301580 break;
Jeeja KP2acd8302017-02-06 12:09:18 +05301581 }
1582 }
Jeeja KP754695f2017-02-06 12:09:14 +05301583 }
Jeeja KP04c8f2b2017-03-01 22:41:23 +05301584
1585 if (hport)
1586 hdac_hdmi_present_sense(pin, hport);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301587 }
Jeeja KP754695f2017-02-06 12:09:14 +05301588
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301589}
1590
Takashi Iwaiae891ab2018-07-11 15:17:22 +02001591static struct drm_audio_component_audio_ops aops = {
Takashi Iwaia57942b2018-07-11 16:23:16 +02001592 .pin2port = hdac_hdmi_pin2port,
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301593 .pin_eld_notify = hdac_hdmi_eld_notify_cb,
1594};
1595
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301596static struct snd_pcm *hdac_hdmi_get_pcm_from_id(struct snd_soc_card *card,
1597 int device)
1598{
1599 struct snd_soc_pcm_runtime *rtd;
1600
1601 list_for_each_entry(rtd, &card->rtd_list, list) {
1602 if (rtd->pcm && (rtd->pcm->device == device))
1603 return rtd->pcm;
1604 }
1605
1606 return NULL;
1607}
1608
Jeeja KP0324e512017-02-07 19:09:55 +05301609/* create jack pin kcontrols */
1610static int create_fill_jack_kcontrols(struct snd_soc_card *card,
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001611 struct hdac_device *hdev)
Jeeja KP0324e512017-02-07 19:09:55 +05301612{
1613 struct hdac_hdmi_pin *pin;
1614 struct snd_kcontrol_new *kc;
1615 char kc_name[NAME_SIZE], xname[NAME_SIZE];
1616 char *name;
1617 int i = 0, j;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001618 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
1619 struct snd_soc_component *component = hdmi->component;
Jeeja KP0324e512017-02-07 19:09:55 +05301620
Kuninori Morimoto45101122018-01-29 04:36:54 +00001621 kc = devm_kcalloc(component->dev, hdmi->num_ports,
Jeeja KP0324e512017-02-07 19:09:55 +05301622 sizeof(*kc), GFP_KERNEL);
1623
1624 if (!kc)
1625 return -ENOMEM;
1626
1627 list_for_each_entry(pin, &hdmi->pin_list, head) {
1628 for (j = 0; j < pin->num_ports; j++) {
1629 snprintf(xname, sizeof(xname), "hif%d-%d Jack",
1630 pin->nid, pin->ports[j].id);
Kuninori Morimoto45101122018-01-29 04:36:54 +00001631 name = devm_kstrdup(component->dev, xname, GFP_KERNEL);
Jeeja KP0324e512017-02-07 19:09:55 +05301632 if (!name)
1633 return -ENOMEM;
1634 snprintf(kc_name, sizeof(kc_name), "%s Switch", xname);
Kuninori Morimoto45101122018-01-29 04:36:54 +00001635 kc[i].name = devm_kstrdup(component->dev, kc_name,
Jeeja KP0324e512017-02-07 19:09:55 +05301636 GFP_KERNEL);
1637 if (!kc[i].name)
1638 return -ENOMEM;
1639
1640 kc[i].private_value = (unsigned long)name;
1641 kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1642 kc[i].access = 0;
1643 kc[i].info = snd_soc_dapm_info_pin_switch;
1644 kc[i].put = snd_soc_dapm_put_pin_switch;
1645 kc[i].get = snd_soc_dapm_get_pin_switch;
1646 i++;
1647 }
1648 }
1649
1650 return snd_soc_add_card_controls(card, kc, i);
1651}
1652
Kuninori Morimoto45101122018-01-29 04:36:54 +00001653int hdac_hdmi_jack_port_init(struct snd_soc_component *component,
Jeeja KP0324e512017-02-07 19:09:55 +05301654 struct snd_soc_dapm_context *dapm)
1655{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001656 struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
1657 struct hdac_device *hdev = hdmi->hdev;
Jeeja KP0324e512017-02-07 19:09:55 +05301658 struct hdac_hdmi_pin *pin;
1659 struct snd_soc_dapm_widget *widgets;
1660 struct snd_soc_dapm_route *route;
1661 char w_name[NAME_SIZE];
1662 int i = 0, j, ret;
1663
1664 widgets = devm_kcalloc(dapm->dev, hdmi->num_ports,
1665 sizeof(*widgets), GFP_KERNEL);
1666
1667 if (!widgets)
1668 return -ENOMEM;
1669
1670 route = devm_kcalloc(dapm->dev, hdmi->num_ports,
1671 sizeof(*route), GFP_KERNEL);
1672 if (!route)
1673 return -ENOMEM;
1674
1675 /* create Jack DAPM widget */
1676 list_for_each_entry(pin, &hdmi->pin_list, head) {
1677 for (j = 0; j < pin->num_ports; j++) {
1678 snprintf(w_name, sizeof(w_name), "hif%d-%d Jack",
1679 pin->nid, pin->ports[j].id);
1680
1681 ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
1682 snd_soc_dapm_spk, NULL,
1683 w_name, NULL, NULL, 0, NULL, 0);
1684 if (ret < 0)
1685 return ret;
1686
1687 pin->ports[j].jack_pin = widgets[i].name;
1688 pin->ports[j].dapm = dapm;
1689
1690 /* add to route from Jack widget to output */
1691 hdac_hdmi_fill_route(&route[i], pin->ports[j].jack_pin,
1692 NULL, pin->ports[j].output_pin, NULL);
1693
1694 i++;
1695 }
1696 }
1697
1698 /* Add Route from Jack widget to the output widget */
1699 ret = snd_soc_dapm_new_controls(dapm, widgets, hdmi->num_ports);
1700 if (ret < 0)
1701 return ret;
1702
1703 ret = snd_soc_dapm_add_routes(dapm, route, hdmi->num_ports);
1704 if (ret < 0)
1705 return ret;
1706
1707 ret = snd_soc_dapm_new_widgets(dapm->card);
1708 if (ret < 0)
1709 return ret;
1710
1711 /* Add Jack Pin switch Kcontrol */
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001712 ret = create_fill_jack_kcontrols(dapm->card, hdev);
Jeeja KP0324e512017-02-07 19:09:55 +05301713
1714 if (ret < 0)
1715 return ret;
1716
1717 /* default set the Jack Pin switch to OFF */
1718 list_for_each_entry(pin, &hdmi->pin_list, head) {
1719 for (j = 0; j < pin->num_ports; j++)
1720 snd_soc_dapm_disable_pin(pin->ports[j].dapm,
1721 pin->ports[j].jack_pin);
1722 }
1723
1724 return 0;
1725}
1726EXPORT_SYMBOL_GPL(hdac_hdmi_jack_port_init);
1727
Jeeja KP62490012017-02-07 19:09:49 +05301728int hdac_hdmi_jack_init(struct snd_soc_dai *dai, int device,
1729 struct snd_soc_jack *jack)
Jeeja KP4a3478d2016-02-12 07:46:06 +05301730{
Kuninori Morimoto45101122018-01-29 04:36:54 +00001731 struct snd_soc_component *component = dai->component;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001732 struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
1733 struct hdac_device *hdev = hdmi->hdev;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301734 struct hdac_hdmi_pcm *pcm;
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301735 struct snd_pcm *snd_pcm;
1736 int err;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301737
1738 /*
1739 * this is a new PCM device, create new pcm and
1740 * add to the pcm list
1741 */
1742 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
1743 if (!pcm)
1744 return -ENOMEM;
1745 pcm->pcm_id = device;
1746 pcm->cvt = hdmi->dai_map[dai->id].cvt;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301747 pcm->jack_event = 0;
Jeeja KP62490012017-02-07 19:09:49 +05301748 pcm->jack = jack;
Jeeja KPab1eea12017-01-24 21:49:05 +05301749 mutex_init(&pcm->lock);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301750 INIT_LIST_HEAD(&pcm->port_list);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301751 snd_pcm = hdac_hdmi_get_pcm_from_id(dai->component->card, device);
1752 if (snd_pcm) {
1753 err = snd_hdac_add_chmap_ctls(snd_pcm, device, &hdmi->chmap);
1754 if (err < 0) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001755 dev_err(&hdev->dev,
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301756 "chmap control add failed with err: %d for pcm: %d\n",
1757 err, device);
1758 kfree(pcm);
1759 return err;
1760 }
1761 }
1762
Jeeja KP4a3478d2016-02-12 07:46:06 +05301763 list_add_tail(&pcm->head, &hdmi->pcm_list);
1764
Jeeja KP62490012017-02-07 19:09:49 +05301765 return 0;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301766}
1767EXPORT_SYMBOL_GPL(hdac_hdmi_jack_init);
1768
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001769static void hdac_hdmi_present_sense_all_pins(struct hdac_device *hdev,
Jeeja KPa9ce96b2017-02-07 19:09:46 +05301770 struct hdac_hdmi_priv *hdmi, bool detect_pin_caps)
1771{
1772 int i;
1773 struct hdac_hdmi_pin *pin;
1774
1775 list_for_each_entry(pin, &hdmi->pin_list, head) {
1776 if (detect_pin_caps) {
1777
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001778 if (hdac_hdmi_get_port_len(hdev, pin->nid) == 0)
Jeeja KPa9ce96b2017-02-07 19:09:46 +05301779 pin->mst_capable = false;
1780 else
1781 pin->mst_capable = true;
1782 }
1783
1784 for (i = 0; i < pin->num_ports; i++) {
1785 if (!pin->mst_capable && i > 0)
1786 continue;
1787
1788 hdac_hdmi_present_sense(pin, &pin->ports[i]);
1789 }
1790 }
1791}
1792
Kuninori Morimoto45101122018-01-29 04:36:54 +00001793static int hdmi_codec_probe(struct snd_soc_component *component)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301794{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001795 struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
1796 struct hdac_device *hdev = hdmi->hdev;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301797 struct snd_soc_dapm_context *dapm =
Kuninori Morimoto45101122018-01-29 04:36:54 +00001798 snd_soc_component_get_dapm(component);
Vinod Koulb2047e92016-05-12 08:58:55 +05301799 struct hdac_ext_link *hlink = NULL;
Jeeja KPa9ce96b2017-02-07 19:09:46 +05301800 int ret;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301801
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001802 hdmi->component = component;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301803
Vinod Koulb2047e92016-05-12 08:58:55 +05301804 /*
1805 * hold the ref while we probe, also no need to drop the ref on
1806 * exit, we call pm_runtime_suspend() so that will do for us
1807 */
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05001808 hlink = snd_hdac_ext_bus_get_link(hdev->bus, dev_name(&hdev->dev));
Vinod Koul500e06b2016-05-31 19:09:55 +05301809 if (!hlink) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001810 dev_err(&hdev->dev, "hdac link not found\n");
Vinod Koul500e06b2016-05-31 19:09:55 +05301811 return -EIO;
1812 }
1813
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05001814 snd_hdac_ext_bus_link_get(hdev->bus, hlink);
Vinod Koulb2047e92016-05-12 08:58:55 +05301815
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301816 ret = create_fill_widget_route_map(dapm);
1817 if (ret < 0)
1818 return ret;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301819
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001820 aops.audio_ptr = hdev;
Takashi Iwaia57942b2018-07-11 16:23:16 +02001821 ret = snd_hdac_acomp_register_notifier(hdev->bus, &aops);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301822 if (ret < 0) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001823 dev_err(&hdev->dev, "notifier register failed: err: %d\n", ret);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301824 return ret;
1825 }
1826
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001827 hdac_hdmi_present_sense_all_pins(hdev, hdmi, true);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301828 /* Imp: Store the card pointer in hda_codec */
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001829 hdmi->card = dapm->card->snd_card;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301830
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05301831 /*
1832 * hdac_device core already sets the state to active and calls
1833 * get_noresume. So enable runtime and set the device to suspend.
1834 */
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001835 pm_runtime_enable(&hdev->dev);
1836 pm_runtime_put(&hdev->dev);
1837 pm_runtime_suspend(&hdev->dev);
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05301838
1839 return 0;
1840}
1841
Kuninori Morimoto45101122018-01-29 04:36:54 +00001842static void hdmi_codec_remove(struct snd_soc_component *component)
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05301843{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001844 struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
1845 struct hdac_device *hdev = hdmi->hdev;
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05301846
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001847 pm_runtime_disable(&hdev->dev);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301848}
1849
Jeeja KP571d5072016-02-22 07:50:33 +05301850#ifdef CONFIG_PM
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05301851static int hdmi_codec_prepare(struct device *dev)
1852{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001853 struct hdac_device *hdev = dev_to_hdac_dev(dev);
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05301854
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001855 pm_runtime_get_sync(&hdev->dev);
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05301856
1857 /*
1858 * Power down afg.
1859 * codec_read is preferred over codec_write to set the power state.
1860 * This way verb is send to set the power state and response
1861 * is received. So setting power state is ensured without using loop
1862 * to read the state.
1863 */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301864 snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05301865 AC_PWRST_D3);
1866
1867 return 0;
1868}
1869
Subhransu S. Prusty0fee1792016-04-01 13:36:25 +05301870static void hdmi_codec_complete(struct device *dev)
Jeeja KP571d5072016-02-22 07:50:33 +05301871{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001872 struct hdac_device *hdev = dev_to_hdac_dev(dev);
1873 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05301874
1875 /* Power up afg */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301876 snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05301877 AC_PWRST_D0);
Jeeja KP571d5072016-02-22 07:50:33 +05301878
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001879 hdac_hdmi_skl_enable_all_pins(hdev);
1880 hdac_hdmi_skl_enable_dp12(hdev);
Jeeja KP571d5072016-02-22 07:50:33 +05301881
Jeeja KP571d5072016-02-22 07:50:33 +05301882 /*
1883 * As the ELD notify callback request is not entertained while the
1884 * device is in suspend state. Need to manually check detection of
Jeeja KPa9ce96b2017-02-07 19:09:46 +05301885 * all pins here. pin capablity change is not support, so use the
1886 * already set pin caps.
Jeeja KP571d5072016-02-22 07:50:33 +05301887 */
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001888 hdac_hdmi_present_sense_all_pins(hdev, hdmi, false);
Jeeja KP571d5072016-02-22 07:50:33 +05301889
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001890 pm_runtime_put_sync(&hdev->dev);
Jeeja KP571d5072016-02-22 07:50:33 +05301891}
1892#else
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05301893#define hdmi_codec_prepare NULL
Subhransu S. Prusty0fee1792016-04-01 13:36:25 +05301894#define hdmi_codec_complete NULL
Jeeja KP571d5072016-02-22 07:50:33 +05301895#endif
1896
Kuninori Morimoto45101122018-01-29 04:36:54 +00001897static const struct snd_soc_component_driver hdmi_hda_codec = {
1898 .probe = hdmi_codec_probe,
1899 .remove = hdmi_codec_remove,
1900 .use_pmdown_time = 1,
1901 .endianness = 1,
1902 .non_legacy_dai_naming = 1,
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301903};
1904
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301905static void hdac_hdmi_get_chmap(struct hdac_device *hdev, int pcm_idx,
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301906 unsigned char *chmap)
1907{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301908 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301909 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301910
Jeeja KPab1eea12017-01-24 21:49:05 +05301911 memcpy(chmap, pcm->chmap, ARRAY_SIZE(pcm->chmap));
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301912}
1913
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301914static void hdac_hdmi_set_chmap(struct hdac_device *hdev, int pcm_idx,
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301915 unsigned char *chmap, int prepared)
1916{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301917 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301918 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301919 struct hdac_hdmi_port *port;
1920
Subhransu S. Prustyeb50fa12017-11-07 16:16:25 +05301921 if (!pcm)
1922 return;
1923
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301924 if (list_empty(&pcm->port_list))
1925 return;
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301926
Jeeja KPab1eea12017-01-24 21:49:05 +05301927 mutex_lock(&pcm->lock);
1928 pcm->chmap_set = true;
1929 memcpy(pcm->chmap, chmap, ARRAY_SIZE(pcm->chmap));
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301930 list_for_each_entry(port, &pcm->port_list, head)
1931 if (prepared)
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001932 hdac_hdmi_setup_audio_infoframe(hdev, pcm, port);
Jeeja KPab1eea12017-01-24 21:49:05 +05301933 mutex_unlock(&pcm->lock);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301934}
1935
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301936static bool is_hdac_hdmi_pcm_attached(struct hdac_device *hdev, int pcm_idx)
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301937{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301938 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301939 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301940
Subhransu S. Prustyeb50fa12017-11-07 16:16:25 +05301941 if (!pcm)
1942 return false;
1943
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301944 if (list_empty(&pcm->port_list))
1945 return false;
1946
1947 return true;
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301948}
1949
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301950static int hdac_hdmi_get_spk_alloc(struct hdac_device *hdev, int pcm_idx)
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301951{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301952 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301953 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301954 struct hdac_hdmi_port *port;
1955
Subhransu S. Prustyeb50fa12017-11-07 16:16:25 +05301956 if (!pcm)
1957 return 0;
1958
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301959 if (list_empty(&pcm->port_list))
1960 return 0;
1961
1962 port = list_first_entry(&pcm->port_list, struct hdac_hdmi_port, head);
1963
1964 if (!port)
1965 return 0;
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301966
Jeeja KP754695f2017-02-06 12:09:14 +05301967 if (!port || !port->eld.eld_valid)
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301968 return 0;
1969
Jeeja KP754695f2017-02-06 12:09:14 +05301970 return port->eld.info.spk_alloc;
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301971}
1972
Pradeep Tewani5622bc92017-07-20 11:40:56 +05301973static struct hdac_hdmi_drv_data intel_glk_drv_data = {
1974 .vendor_nid = INTEL_GLK_VENDOR_NID,
1975};
1976
1977static struct hdac_hdmi_drv_data intel_drv_data = {
1978 .vendor_nid = INTEL_VENDOR_NID,
1979};
1980
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001981static int hdac_hdmi_dev_probe(struct hdac_device *hdev)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301982{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001983 struct hdac_hdmi_priv *hdmi_priv = NULL;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301984 struct snd_soc_dai_driver *hdmi_dais = NULL;
Vinod Koulb2047e92016-05-12 08:58:55 +05301985 struct hdac_ext_link *hlink = NULL;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301986 int num_dais = 0;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301987 int ret = 0;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301988 struct hdac_driver *hdrv = drv_to_hdac_driver(hdev->dev.driver);
1989 const struct hda_device_id *hdac_id = hdac_get_device_id(hdev, hdrv);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301990
Vinod Koulb2047e92016-05-12 08:58:55 +05301991 /* hold the ref while we probe */
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05001992 hlink = snd_hdac_ext_bus_get_link(hdev->bus, dev_name(&hdev->dev));
Vinod Koul500e06b2016-05-31 19:09:55 +05301993 if (!hlink) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05001994 dev_err(&hdev->dev, "hdac link not found\n");
Vinod Koul500e06b2016-05-31 19:09:55 +05301995 return -EIO;
1996 }
1997
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05001998 snd_hdac_ext_bus_link_get(hdev->bus, hlink);
Vinod Koulb2047e92016-05-12 08:58:55 +05301999
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302000 hdmi_priv = devm_kzalloc(&hdev->dev, sizeof(*hdmi_priv), GFP_KERNEL);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302001 if (hdmi_priv == NULL)
2002 return -ENOMEM;
2003
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302004 snd_hdac_register_chmap_ops(hdev, &hdmi_priv->chmap);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05302005 hdmi_priv->chmap.ops.get_chmap = hdac_hdmi_get_chmap;
2006 hdmi_priv->chmap.ops.set_chmap = hdac_hdmi_set_chmap;
2007 hdmi_priv->chmap.ops.is_pcm_attached = is_hdac_hdmi_pcm_attached;
2008 hdmi_priv->chmap.ops.get_spk_alloc = hdac_hdmi_get_spk_alloc;
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002009 hdmi_priv->hdev = hdev;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302010
Subhransu S. Prustyeb50fa12017-11-07 16:16:25 +05302011 if (!hdac_id)
2012 return -ENODEV;
2013
Pradeep Tewani5622bc92017-07-20 11:40:56 +05302014 if (hdac_id->driver_data)
2015 hdmi_priv->drv_data =
2016 (struct hdac_hdmi_drv_data *)hdac_id->driver_data;
2017 else
2018 hdmi_priv->drv_data = &intel_drv_data;
2019
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002020 dev_set_drvdata(&hdev->dev, hdmi_priv);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302021
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302022 INIT_LIST_HEAD(&hdmi_priv->pin_list);
2023 INIT_LIST_HEAD(&hdmi_priv->cvt_list);
Jeeja KP4a3478d2016-02-12 07:46:06 +05302024 INIT_LIST_HEAD(&hdmi_priv->pcm_list);
2025 mutex_init(&hdmi_priv->pin_mutex);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302026
Ramesh Babuaeaccef2016-02-17 21:34:01 +05302027 /*
2028 * Turned off in the runtime_suspend during the first explicit
2029 * pm_runtime_suspend call.
2030 */
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002031 ret = snd_hdac_display_power(hdev->bus, true);
Ramesh Babuaeaccef2016-02-17 21:34:01 +05302032 if (ret < 0) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002033 dev_err(&hdev->dev,
Ramesh Babuaeaccef2016-02-17 21:34:01 +05302034 "Cannot turn on display power on i915 err: %d\n",
2035 ret);
2036 return ret;
2037 }
2038
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002039 ret = hdac_hdmi_parse_and_map_nid(hdev, &hdmi_dais, &num_dais);
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05302040 if (ret < 0) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302041 dev_err(&hdev->dev,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05302042 "Failed in parse and map nid with err: %d\n", ret);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302043 return ret;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05302044 }
Puneeth Prabhu0fb02ba2017-12-06 16:34:05 +05302045 snd_hdac_refresh_widgets(hdev, true);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302046
2047 /* ASoC specific initialization */
Kuninori Morimoto45101122018-01-29 04:36:54 +00002048 ret = devm_snd_soc_register_component(&hdev->dev, &hdmi_hda_codec,
Vinod Koulb2047e92016-05-12 08:58:55 +05302049 hdmi_dais, num_dais);
2050
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05002051 snd_hdac_ext_bus_link_put(hdev->bus, hlink);
Vinod Koulb2047e92016-05-12 08:58:55 +05302052
2053 return ret;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302054}
2055
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002056static int hdac_hdmi_dev_remove(struct hdac_device *hdev)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302057{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002058 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302059 struct hdac_hdmi_pin *pin, *pin_next;
2060 struct hdac_hdmi_cvt *cvt, *cvt_next;
Jeeja KP4a3478d2016-02-12 07:46:06 +05302061 struct hdac_hdmi_pcm *pcm, *pcm_next;
Jeeja KP2fe42dd2017-03-01 22:41:24 +05302062 struct hdac_hdmi_port *port, *port_next;
Jeeja KP754695f2017-02-06 12:09:14 +05302063 int i;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302064
Jeeja KP4a3478d2016-02-12 07:46:06 +05302065 list_for_each_entry_safe(pcm, pcm_next, &hdmi->pcm_list, head) {
2066 pcm->cvt = NULL;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05302067 if (list_empty(&pcm->port_list))
2068 continue;
2069
Jeeja KP2fe42dd2017-03-01 22:41:24 +05302070 list_for_each_entry_safe(port, port_next,
2071 &pcm->port_list, head)
2072 list_del(&port->head);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05302073
Jeeja KP4a3478d2016-02-12 07:46:06 +05302074 list_del(&pcm->head);
2075 kfree(pcm);
2076 }
2077
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302078 list_for_each_entry_safe(cvt, cvt_next, &hdmi->cvt_list, head) {
2079 list_del(&cvt->head);
Jeeja KP4a3478d2016-02-12 07:46:06 +05302080 kfree(cvt->name);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302081 kfree(cvt);
2082 }
2083
2084 list_for_each_entry_safe(pin, pin_next, &hdmi->pin_list, head) {
Jeeja KP754695f2017-02-06 12:09:14 +05302085 for (i = 0; i < pin->num_ports; i++)
2086 pin->ports[i].pin = NULL;
2087 kfree(pin->ports);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302088 list_del(&pin->head);
2089 kfree(pin);
2090 }
2091
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302092 return 0;
2093}
2094
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302095#ifdef CONFIG_PM
2096static int hdac_hdmi_runtime_suspend(struct device *dev)
2097{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002098 struct hdac_device *hdev = dev_to_hdac_dev(dev);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302099 struct hdac_bus *bus = hdev->bus;
Vinod Koulb2047e92016-05-12 08:58:55 +05302100 struct hdac_ext_link *hlink = NULL;
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302101 int err;
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302102
2103 dev_dbg(dev, "Enter: %s\n", __func__);
2104
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302105 /* controller may not have been initialized for the first time */
2106 if (!bus)
2107 return 0;
2108
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05302109 /*
2110 * Power down afg.
2111 * codec_read is preferred over codec_write to set the power state.
2112 * This way verb is send to set the power state and response
2113 * is received. So setting power state is ensured without using loop
2114 * to read the state.
2115 */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302116 snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05302117 AC_PWRST_D3);
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302118 err = snd_hdac_display_power(bus, false);
2119 if (err < 0) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002120 dev_err(dev, "Cannot turn on display power on i915\n");
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302121 return err;
2122 }
2123
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05002124 hlink = snd_hdac_ext_bus_get_link(bus, dev_name(dev));
Vinod Koul500e06b2016-05-31 19:09:55 +05302125 if (!hlink) {
2126 dev_err(dev, "hdac link not found\n");
2127 return -EIO;
2128 }
2129
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05002130 snd_hdac_ext_bus_link_put(bus, hlink);
Vinod Koulb2047e92016-05-12 08:58:55 +05302131
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302132 return 0;
2133}
2134
2135static int hdac_hdmi_runtime_resume(struct device *dev)
2136{
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002137 struct hdac_device *hdev = dev_to_hdac_dev(dev);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302138 struct hdac_bus *bus = hdev->bus;
Vinod Koulb2047e92016-05-12 08:58:55 +05302139 struct hdac_ext_link *hlink = NULL;
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302140 int err;
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302141
2142 dev_dbg(dev, "Enter: %s\n", __func__);
2143
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302144 /* controller may not have been initialized for the first time */
2145 if (!bus)
2146 return 0;
2147
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05002148 hlink = snd_hdac_ext_bus_get_link(bus, dev_name(dev));
Vinod Koul500e06b2016-05-31 19:09:55 +05302149 if (!hlink) {
2150 dev_err(dev, "hdac link not found\n");
2151 return -EIO;
2152 }
2153
Rakesh Ughreja76f56fa2018-06-01 22:53:50 -05002154 snd_hdac_ext_bus_link_get(bus, hlink);
Vinod Koulb2047e92016-05-12 08:58:55 +05302155
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302156 err = snd_hdac_display_power(bus, true);
2157 if (err < 0) {
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002158 dev_err(dev, "Cannot turn on display power on i915\n");
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302159 return err;
2160 }
2161
Rakesh Ughreja3787a392018-06-01 22:53:49 -05002162 hdac_hdmi_skl_enable_all_pins(hdev);
2163 hdac_hdmi_skl_enable_dp12(hdev);
Subhransu S. Prustyab85f5b2016-02-17 21:34:02 +05302164
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302165 /* Power up afg */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302166 snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05302167 AC_PWRST_D0);
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302168
2169 return 0;
2170}
2171#else
2172#define hdac_hdmi_runtime_suspend NULL
2173#define hdac_hdmi_runtime_resume NULL
2174#endif
2175
2176static const struct dev_pm_ops hdac_hdmi_pm = {
2177 SET_RUNTIME_PM_OPS(hdac_hdmi_runtime_suspend, hdac_hdmi_runtime_resume, NULL)
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05302178 .prepare = hdmi_codec_prepare,
Subhransu S. Prusty0fee1792016-04-01 13:36:25 +05302179 .complete = hdmi_codec_complete,
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302180};
2181
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302182static const struct hda_device_id hdmi_list[] = {
2183 HDA_CODEC_EXT_ENTRY(0x80862809, 0x100000, "Skylake HDMI", 0),
Jeeja KPe2304802016-03-11 10:12:55 +05302184 HDA_CODEC_EXT_ENTRY(0x8086280a, 0x100000, "Broxton HDMI", 0),
Shreyas NCcc216882016-07-11 22:02:09 +05302185 HDA_CODEC_EXT_ENTRY(0x8086280b, 0x100000, "Kabylake HDMI", 0),
Guneshwor Singh5fb6e0a2017-12-21 08:45:29 +05302186 HDA_CODEC_EXT_ENTRY(0x8086280c, 0x100000, "Cannonlake HDMI",
2187 &intel_glk_drv_data),
Pradeep Tewani5622bc92017-07-20 11:40:56 +05302188 HDA_CODEC_EXT_ENTRY(0x8086280d, 0x100000, "Geminilake HDMI",
2189 &intel_glk_drv_data),
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302190 {}
2191};
2192
2193MODULE_DEVICE_TABLE(hdaudio, hdmi_list);
2194
Rakesh Ughrejae1df9312018-06-01 22:53:51 -05002195static struct hdac_driver hdmi_driver = {
2196 .driver = {
2197 .name = "HDMI HDA Codec",
2198 .pm = &hdac_hdmi_pm,
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302199 },
Rakesh Ughrejae1df9312018-06-01 22:53:51 -05002200 .id_table = hdmi_list,
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302201 .probe = hdac_hdmi_dev_probe,
2202 .remove = hdac_hdmi_dev_remove,
2203};
2204
2205static int __init hdmi_init(void)
2206{
2207 return snd_hda_ext_driver_register(&hdmi_driver);
2208}
2209
2210static void __exit hdmi_exit(void)
2211{
2212 snd_hda_ext_driver_unregister(&hdmi_driver);
2213}
2214
2215module_init(hdmi_init);
2216module_exit(hdmi_exit);
2217
2218MODULE_LICENSE("GPL v2");
2219MODULE_DESCRIPTION("HDMI HD codec");
2220MODULE_AUTHOR("Samreen Nilofer<samreen.nilofer@intel.com>");
2221MODULE_AUTHOR("Subhransu S. Prusty<subhransu.s.prusty@intel.com>");