blob: 15c3638fe345d8b80b02ea819c69319c7b78f54f [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;
88 struct hdac_ext_device *edev;
89};
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 {
Jeeja KP754695f2017-02-06 12:09:14 +0530129 struct hdac_hdmi_dai_port_map dai_map[HDA_MAX_CVTS];
Subhransu S. Prusty15b91442015-12-09 21:46:10 +0530130 struct list_head pin_list;
131 struct list_head cvt_list;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530132 struct list_head pcm_list;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +0530133 int num_pin;
134 int num_cvt;
Jeeja KP754695f2017-02-06 12:09:14 +0530135 int num_ports;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530136 struct mutex pin_mutex;
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530137 struct hdac_chmap chmap;
Pradeep Tewani5622bc92017-07-20 11:40:56 +0530138 struct hdac_hdmi_drv_data *drv_data;
Kuninori Morimoto1e02dac2017-12-20 01:48:13 +0000139 struct snd_soc_dai_driver *dai_drv;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530140};
141
Ughreja, Rakesh Ab09b1c32017-12-01 14:43:17 +0530142#define hdev_to_hdmi_priv(_hdev) ((to_ehdac_device(_hdev))->private_data)
143
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530144static struct hdac_hdmi_pcm *
145hdac_hdmi_get_pcm_from_cvt(struct hdac_hdmi_priv *hdmi,
146 struct hdac_hdmi_cvt *cvt)
147{
148 struct hdac_hdmi_pcm *pcm = NULL;
Jeeja KP1de777f2017-01-10 17:57:48 +0530149
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530150 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
151 if (pcm->cvt == cvt)
152 break;
153 }
154
155 return pcm;
156}
Jeeja KP1de777f2017-01-10 17:57:48 +0530157
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530158static void hdac_hdmi_jack_report(struct hdac_hdmi_pcm *pcm,
159 struct hdac_hdmi_port *port, bool is_connect)
160{
161 struct hdac_ext_device *edev = port->pin->edev;
162
Jeeja KP0324e512017-02-07 19:09:55 +0530163 if (is_connect)
164 snd_soc_dapm_enable_pin(port->dapm, port->jack_pin);
165 else
166 snd_soc_dapm_disable_pin(port->dapm, port->jack_pin);
167
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530168 if (is_connect) {
169 /*
170 * Report Jack connect event when a device is connected
171 * for the first time where same PCM is attached to multiple
172 * ports.
173 */
174 if (pcm->jack_event == 0) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530175 dev_dbg(&edev->hdev.dev,
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530176 "jack report for pcm=%d\n",
177 pcm->pcm_id);
Jeeja KP62490012017-02-07 19:09:49 +0530178 snd_soc_jack_report(pcm->jack, SND_JACK_AVOUT,
179 SND_JACK_AVOUT);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530180 }
181 pcm->jack_event++;
182 } else {
183 /*
184 * Report Jack disconnect event when a device is disconnected
185 * is the only last connected device when same PCM is attached
186 * to multiple ports.
187 */
188 if (pcm->jack_event == 1)
Jeeja KP62490012017-02-07 19:09:49 +0530189 snd_soc_jack_report(pcm->jack, 0, SND_JACK_AVOUT);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530190 if (pcm->jack_event > 0)
191 pcm->jack_event--;
192 }
Jeeja KP0324e512017-02-07 19:09:55 +0530193
194 snd_soc_dapm_sync(port->dapm);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530195}
196
Jeeja KPfc181b02017-02-07 19:09:45 +0530197/* MST supported verbs */
198/*
199 * Get the no devices that can be connected to a port on the Pin widget.
200 */
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530201static int hdac_hdmi_get_port_len(struct hdac_ext_device *edev, hda_nid_t nid)
Jeeja KPfc181b02017-02-07 19:09:45 +0530202{
203 unsigned int caps;
204 unsigned int type, param;
205
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530206 caps = get_wcaps(&edev->hdev, nid);
Jeeja KPfc181b02017-02-07 19:09:45 +0530207 type = get_wcaps_type(caps);
208
209 if (!(caps & AC_WCAP_DIGITAL) || (type != AC_WID_PIN))
210 return 0;
211
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530212 param = snd_hdac_read_parm_uncached(&edev->hdev, nid,
Jeeja KPfc181b02017-02-07 19:09:45 +0530213 AC_PAR_DEVLIST_LEN);
214 if (param == -1)
215 return param;
216
217 return param & AC_DEV_LIST_LEN_MASK;
218}
219
220/*
221 * Get the port entry select on the pin. Return the port entry
222 * id selected on the pin. Return 0 means the first port entry
223 * is selected or MST is not supported.
224 */
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530225static int hdac_hdmi_port_select_get(struct hdac_ext_device *edev,
Jeeja KPfc181b02017-02-07 19:09:45 +0530226 struct hdac_hdmi_port *port)
227{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530228 return snd_hdac_codec_read(&edev->hdev, port->pin->nid,
Jeeja KPfc181b02017-02-07 19:09:45 +0530229 0, AC_VERB_GET_DEVICE_SEL, 0);
230}
231
232/*
233 * Sets the selected port entry for the configuring Pin widget verb.
234 * returns error if port set is not equal to port get otherwise success
235 */
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530236static int hdac_hdmi_port_select_set(struct hdac_ext_device *edev,
Jeeja KPfc181b02017-02-07 19:09:45 +0530237 struct hdac_hdmi_port *port)
238{
239 int num_ports;
240
241 if (!port->pin->mst_capable)
242 return 0;
243
244 /* AC_PAR_DEVLIST_LEN is 0 based. */
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530245 num_ports = hdac_hdmi_get_port_len(edev, port->pin->nid);
Jeeja KPfc181b02017-02-07 19:09:45 +0530246
247 if (num_ports < 0)
248 return -EIO;
249 /*
250 * Device List Length is a 0 based integer value indicating the
251 * number of sink device that a MST Pin Widget can support.
252 */
253 if (num_ports + 1 < port->id)
254 return 0;
255
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530256 snd_hdac_codec_write(&edev->hdev, port->pin->nid, 0,
Jeeja KPfc181b02017-02-07 19:09:45 +0530257 AC_VERB_SET_DEVICE_SEL, port->id);
258
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530259 if (port->id != hdac_hdmi_port_select_get(edev, port))
Jeeja KPfc181b02017-02-07 19:09:45 +0530260 return -EIO;
261
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530262 dev_dbg(&edev->hdev.dev, "Selected the port=%d\n", port->id);
Jeeja KPfc181b02017-02-07 19:09:45 +0530263
264 return 0;
265}
266
Subhransu S. Prusty28890992016-04-14 10:07:34 +0530267static struct hdac_hdmi_pcm *get_hdmi_pcm_from_id(struct hdac_hdmi_priv *hdmi,
268 int pcm_idx)
269{
270 struct hdac_hdmi_pcm *pcm;
271
272 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
273 if (pcm->pcm_id == pcm_idx)
274 return pcm;
275 }
276
277 return NULL;
278}
279
Subhransu S. Prustye342ac02015-11-10 18:42:07 +0530280static inline struct hdac_ext_device *to_hda_ext_device(struct device *dev)
281{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530282 struct hdac_device *hdev = dev_to_hdac_dev(dev);
Subhransu S. Prustye342ac02015-11-10 18:42:07 +0530283
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530284 return to_ehdac_device(hdev);
Subhransu S. Prustye342ac02015-11-10 18:42:07 +0530285}
286
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +0530287static unsigned int sad_format(const u8 *sad)
288{
289 return ((sad[0] >> 0x3) & 0x1f);
290}
291
292static unsigned int sad_sample_bits_lpcm(const u8 *sad)
293{
294 return (sad[2] & 7);
295}
296
297static int hdac_hdmi_eld_limit_formats(struct snd_pcm_runtime *runtime,
298 void *eld)
299{
300 u64 formats = SNDRV_PCM_FMTBIT_S16;
301 int i;
302 const u8 *sad, *eld_buf = eld;
303
304 sad = drm_eld_sad(eld_buf);
305 if (!sad)
306 goto format_constraint;
307
308 for (i = drm_eld_sad_count(eld_buf); i > 0; i--, sad += 3) {
309 if (sad_format(sad) == 1) { /* AUDIO_CODING_TYPE_LPCM */
310
311 /*
312 * the controller support 20 and 24 bits in 32 bit
313 * container so we set S32
314 */
315 if (sad_sample_bits_lpcm(sad) & 0x6)
316 formats |= SNDRV_PCM_FMTBIT_S32;
317 }
318 }
319
320format_constraint:
321 return snd_pcm_hw_constraint_mask64(runtime, SNDRV_PCM_HW_PARAM_FORMAT,
322 formats);
323
324}
325
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530326static void
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530327hdac_hdmi_set_dip_index(struct hdac_ext_device *edev, hda_nid_t pin_nid,
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530328 int packet_index, int byte_index)
329{
330 int val;
331
332 val = (packet_index << 5) | (byte_index & 0x1f);
333
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530334 snd_hdac_codec_write(&edev->hdev, pin_nid, 0,
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530335 AC_VERB_SET_HDMI_DIP_INDEX, val);
336}
337
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530338struct dp_audio_infoframe {
339 u8 type; /* 0x84 */
340 u8 len; /* 0x1b */
341 u8 ver; /* 0x11 << 2 */
342
343 u8 CC02_CT47; /* match with HDMI infoframe from this on */
344 u8 SS01_SF24;
345 u8 CXT04;
346 u8 CA;
347 u8 LFEPBL01_LSV36_DM_INH7;
348};
349
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530350static int hdac_hdmi_setup_audio_infoframe(struct hdac_ext_device *edev,
Jeeja KP754695f2017-02-06 12:09:14 +0530351 struct hdac_hdmi_pcm *pcm, struct hdac_hdmi_port *port)
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530352{
353 uint8_t buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AUDIO_INFOFRAME_SIZE];
354 struct hdmi_audio_infoframe frame;
Jeeja KP754695f2017-02-06 12:09:14 +0530355 struct hdac_hdmi_pin *pin = port->pin;
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530356 struct dp_audio_infoframe dp_ai;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530357 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Jeeja KPab1eea12017-01-24 21:49:05 +0530358 struct hdac_hdmi_cvt *cvt = pcm->cvt;
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530359 u8 *dip;
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530360 int ret;
361 int i;
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530362 const u8 *eld_buf;
363 u8 conn_type;
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530364 int channels, ca;
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530365
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530366 ca = snd_hdac_channel_allocation(&edev->hdev, port->eld.info.spk_alloc,
Jeeja KPab1eea12017-01-24 21:49:05 +0530367 pcm->channels, pcm->chmap_set, true, pcm->chmap);
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530368
369 channels = snd_hdac_get_active_channels(ca);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530370 hdmi->chmap.ops.set_channel_count(&edev->hdev, cvt->nid, channels);
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530371
372 snd_hdac_setup_channel_mapping(&hdmi->chmap, pin->nid, false, ca,
Jeeja KPab1eea12017-01-24 21:49:05 +0530373 pcm->channels, pcm->chmap, pcm->chmap_set);
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530374
Jeeja KP754695f2017-02-06 12:09:14 +0530375 eld_buf = port->eld.eld_buffer;
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530376 conn_type = drm_eld_get_conn_type(eld_buf);
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530377
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530378 switch (conn_type) {
379 case DRM_ELD_CONN_TYPE_HDMI:
380 hdmi_audio_infoframe_init(&frame);
381
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530382 frame.channels = channels;
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530383 frame.channel_allocation = ca;
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530384
385 ret = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
386 if (ret < 0)
387 return ret;
388
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530389 break;
390
391 case DRM_ELD_CONN_TYPE_DP:
392 memset(&dp_ai, 0, sizeof(dp_ai));
393 dp_ai.type = 0x84;
394 dp_ai.len = 0x1b;
395 dp_ai.ver = 0x11 << 2;
396 dp_ai.CC02_CT47 = channels - 1;
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530397 dp_ai.CA = ca;
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530398
399 dip = (u8 *)&dp_ai;
400 break;
401
402 default:
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530403 dev_err(&edev->hdev.dev, "Invalid connection type: %d\n",
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530404 conn_type);
405 return -EIO;
406 }
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530407
408 /* stop infoframe transmission */
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530409 hdac_hdmi_set_dip_index(edev, pin->nid, 0x0, 0x0);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530410 snd_hdac_codec_write(&edev->hdev, pin->nid, 0,
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530411 AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_DISABLE);
412
413
414 /* Fill infoframe. Index auto-incremented */
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530415 hdac_hdmi_set_dip_index(edev, pin->nid, 0x0, 0x0);
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530416 if (conn_type == DRM_ELD_CONN_TYPE_HDMI) {
Subhransu S. Prusty391005e2016-03-10 09:04:07 +0530417 for (i = 0; i < sizeof(buffer); i++)
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530418 snd_hdac_codec_write(&edev->hdev, pin->nid, 0,
Subhransu S. Prusty391005e2016-03-10 09:04:07 +0530419 AC_VERB_SET_HDMI_DIP_DATA, buffer[i]);
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530420 } else {
421 for (i = 0; i < sizeof(dp_ai); i++)
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530422 snd_hdac_codec_write(&edev->hdev, pin->nid, 0,
Subhransu S. Prusty478f544e2016-02-12 07:46:09 +0530423 AC_VERB_SET_HDMI_DIP_DATA, dip[i]);
424 }
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530425
426 /* Start infoframe */
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530427 hdac_hdmi_set_dip_index(edev, pin->nid, 0x0, 0x0);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530428 snd_hdac_codec_write(&edev->hdev, pin->nid, 0,
Subhransu S. Prustya657f1d2015-11-10 18:42:09 +0530429 AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_BEST);
430
431 return 0;
432}
433
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530434static int hdac_hdmi_set_tdm_slot(struct snd_soc_dai *dai,
435 unsigned int tx_mask, unsigned int rx_mask,
436 int slots, int slot_width)
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530437{
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530438 struct hdac_ext_device *edev = snd_soc_dai_get_drvdata(dai);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530439 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Jeeja KP754695f2017-02-06 12:09:14 +0530440 struct hdac_hdmi_dai_port_map *dai_map;
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530441 struct hdac_hdmi_pcm *pcm;
442
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530443 dev_dbg(&edev->hdev.dev, "%s: strm_tag: %d\n", __func__, tx_mask);
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530444
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530445 dai_map = &hdmi->dai_map[dai->id];
446
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530447 pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530448
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530449 if (pcm)
450 pcm->stream_tag = (tx_mask << 4);
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530451
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530452 return 0;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530453}
454
455static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,
456 struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)
457{
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530458 struct hdac_ext_device *edev = snd_soc_dai_get_drvdata(dai);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530459 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Jeeja KP754695f2017-02-06 12:09:14 +0530460 struct hdac_hdmi_dai_port_map *dai_map;
461 struct hdac_hdmi_port *port;
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530462 struct hdac_hdmi_pcm *pcm;
463 int format;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530464
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530465 dai_map = &hdmi->dai_map[dai->id];
Jeeja KP754695f2017-02-06 12:09:14 +0530466 port = dai_map->port;
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530467
Jeeja KP754695f2017-02-06 12:09:14 +0530468 if (!port)
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530469 return -ENODEV;
470
Jeeja KP754695f2017-02-06 12:09:14 +0530471 if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530472 dev_err(&edev->hdev.dev,
Jeeja KP754695f2017-02-06 12:09:14 +0530473 "device is not configured for this pin:port%d:%d\n",
474 port->pin->nid, port->id);
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530475 return -ENODEV;
476 }
477
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530478 format = snd_hdac_calc_stream_format(params_rate(hparams),
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530479 params_channels(hparams), params_format(hparams),
Jeeja KP66d6bbc2017-03-24 23:10:26 +0530480 dai->driver->playback.sig_bits, 0);
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530481
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530482 pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
483 if (!pcm)
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530484 return -EIO;
485
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530486 pcm->format = format;
487 pcm->channels = params_channels(hparams);
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530488
489 return 0;
490}
491
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530492static int hdac_hdmi_query_port_connlist(struct hdac_ext_device *edev,
Jeeja KP754695f2017-02-06 12:09:14 +0530493 struct hdac_hdmi_pin *pin,
494 struct hdac_hdmi_port *port)
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530495{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530496 if (!(get_wcaps(&edev->hdev, pin->nid) & AC_WCAP_CONN_LIST)) {
497 dev_warn(&edev->hdev.dev,
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530498 "HDMI: pin %d wcaps %#x does not support connection list\n",
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530499 pin->nid, get_wcaps(&edev->hdev, pin->nid));
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530500 return -EINVAL;
501 }
502
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530503 if (hdac_hdmi_port_select_set(edev, port) < 0)
Jeeja KP1b46ebd2017-02-07 19:09:47 +0530504 return -EIO;
505
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530506 port->num_mux_nids = snd_hdac_get_connections(&edev->hdev, pin->nid,
Jeeja KP754695f2017-02-06 12:09:14 +0530507 port->mux_nids, HDA_MAX_CONNECTIONS);
508 if (port->num_mux_nids == 0)
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530509 dev_warn(&edev->hdev.dev,
Jeeja KP754695f2017-02-06 12:09:14 +0530510 "No connections found for pin:port %d:%d\n",
511 pin->nid, port->id);
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530512
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530513 dev_dbg(&edev->hdev.dev, "num_mux_nids %d for pin:port %d:%d\n",
Jeeja KP754695f2017-02-06 12:09:14 +0530514 port->num_mux_nids, pin->nid, port->id);
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530515
Jeeja KP754695f2017-02-06 12:09:14 +0530516 return port->num_mux_nids;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530517}
518
519/*
Jeeja KP754695f2017-02-06 12:09:14 +0530520 * Query pcm list and return port to which stream is routed.
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530521 *
Jeeja KP754695f2017-02-06 12:09:14 +0530522 * Also query connection list of the pin, to validate the cvt to port map.
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530523 *
Jeeja KP754695f2017-02-06 12:09:14 +0530524 * Same stream rendering to multiple ports simultaneously can be done
525 * possibly, but not supported for now in driver. So return the first port
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530526 * connected.
527 */
Jeeja KP754695f2017-02-06 12:09:14 +0530528static struct hdac_hdmi_port *hdac_hdmi_get_port_from_cvt(
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530529 struct hdac_ext_device *edev,
530 struct hdac_hdmi_priv *hdmi,
531 struct hdac_hdmi_cvt *cvt)
532{
533 struct hdac_hdmi_pcm *pcm;
Jeeja KP754695f2017-02-06 12:09:14 +0530534 struct hdac_hdmi_port *port = NULL;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530535 int ret, i;
536
537 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
538 if (pcm->cvt == cvt) {
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530539 if (list_empty(&pcm->port_list))
540 continue;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530541
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530542 list_for_each_entry(port, &pcm->port_list, head) {
543 mutex_lock(&pcm->lock);
544 ret = hdac_hdmi_query_port_connlist(edev,
545 port->pin, port);
546 mutex_unlock(&pcm->lock);
547 if (ret < 0)
548 continue;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530549
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530550 for (i = 0; i < port->num_mux_nids; i++) {
551 if (port->mux_nids[i] == cvt->nid &&
552 port->eld.monitor_present &&
553 port->eld.eld_valid)
554 return port;
555 }
556 }
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530557 }
558 }
559
560 return NULL;
561}
562
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530563/*
564 * This tries to get a valid pin and set the HW constraints based on the
565 * ELD. Even if a valid pin is not found return success so that device open
566 * doesn't fail.
567 */
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530568static int hdac_hdmi_pcm_open(struct snd_pcm_substream *substream,
569 struct snd_soc_dai *dai)
570{
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530571 struct hdac_ext_device *edev = snd_soc_dai_get_drvdata(dai);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530572 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Jeeja KP754695f2017-02-06 12:09:14 +0530573 struct hdac_hdmi_dai_port_map *dai_map;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530574 struct hdac_hdmi_cvt *cvt;
Jeeja KP754695f2017-02-06 12:09:14 +0530575 struct hdac_hdmi_port *port;
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +0530576 int ret;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530577
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530578 dai_map = &hdmi->dai_map[dai->id];
579
Subhransu S. Prusty148569f2016-02-12 07:46:07 +0530580 cvt = dai_map->cvt;
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530581 port = hdac_hdmi_get_port_from_cvt(edev, hdmi, cvt);
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530582
583 /*
584 * To make PA and other userland happy.
585 * userland scans devices so returning error does not help.
586 */
Jeeja KP754695f2017-02-06 12:09:14 +0530587 if (!port)
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530588 return 0;
Jeeja KP754695f2017-02-06 12:09:14 +0530589 if ((!port->eld.monitor_present) ||
590 (!port->eld.eld_valid)) {
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530591
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530592 dev_warn(&edev->hdev.dev,
Jeeja KP754695f2017-02-06 12:09:14 +0530593 "Failed: present?:%d ELD valid?:%d pin:port: %d:%d\n",
594 port->eld.monitor_present, port->eld.eld_valid,
595 port->pin->nid, port->id);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +0530596
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530597 return 0;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530598 }
599
Jeeja KP754695f2017-02-06 12:09:14 +0530600 dai_map->port = port;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530601
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +0530602 ret = hdac_hdmi_eld_limit_formats(substream->runtime,
Jeeja KP754695f2017-02-06 12:09:14 +0530603 port->eld.eld_buffer);
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +0530604 if (ret < 0)
605 return ret;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530606
Subhransu S. Prusty2428bca2016-02-12 07:46:02 +0530607 return snd_pcm_hw_constraint_eld(substream->runtime,
Jeeja KP754695f2017-02-06 12:09:14 +0530608 port->eld.eld_buffer);
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530609}
610
611static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,
612 struct snd_soc_dai *dai)
613{
Ughreja, Rakesh A72bc39c2017-12-01 14:43:18 +0530614 struct hdac_ext_device *edev = snd_soc_dai_get_drvdata(dai);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530615 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Jeeja KP754695f2017-02-06 12:09:14 +0530616 struct hdac_hdmi_dai_port_map *dai_map;
Jeeja KPab1eea12017-01-24 21:49:05 +0530617 struct hdac_hdmi_pcm *pcm;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530618
619 dai_map = &hdmi->dai_map[dai->id];
620
Jeeja KPab1eea12017-01-24 21:49:05 +0530621 pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530622
Jeeja KPab1eea12017-01-24 21:49:05 +0530623 if (pcm) {
624 mutex_lock(&pcm->lock);
625 pcm->chmap_set = false;
626 memset(pcm->chmap, 0, sizeof(pcm->chmap));
627 pcm->channels = 0;
628 mutex_unlock(&pcm->lock);
Subhransu S. Prusty54dfa1e2016-02-17 21:34:00 +0530629 }
Jeeja KPab1eea12017-01-24 21:49:05 +0530630
Jeeja KP754695f2017-02-06 12:09:14 +0530631 if (dai_map->port)
632 dai_map->port = NULL;
Subhransu S. Prustyb0362ad2015-11-10 18:42:08 +0530633}
634
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530635static int
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530636hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct hdac_hdmi_cvt *cvt)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530637{
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530638 unsigned int chans;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530639 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530640 int err;
641
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530642 chans = get_wcaps(hdev, cvt->nid);
Subhransu S. Prustybcced702016-04-14 10:07:30 +0530643 chans = get_wcaps_channels(chans);
644
645 cvt->params.channels_min = 2;
646
647 cvt->params.channels_max = chans;
648 if (chans > hdmi->chmap.channels_max)
649 hdmi->chmap.channels_max = chans;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530650
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530651 err = snd_hdac_query_supported_pcm(hdev, cvt->nid,
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530652 &cvt->params.rates,
653 &cvt->params.formats,
654 &cvt->params.maxbps);
655 if (err < 0)
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530656 dev_err(&hdev->dev,
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530657 "Failed to query pcm params for nid %d: %d\n",
658 cvt->nid, err);
659
660 return err;
661}
662
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530663static int hdac_hdmi_fill_widget_info(struct device *dev,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530664 struct snd_soc_dapm_widget *w, enum snd_soc_dapm_type id,
665 void *priv, const char *wname, const char *stream,
666 struct snd_kcontrol_new *wc, int numkc,
667 int (*event)(struct snd_soc_dapm_widget *,
668 struct snd_kcontrol *, int), unsigned short event_flags)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530669{
670 w->id = id;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530671 w->name = devm_kstrdup(dev, wname, GFP_KERNEL);
672 if (!w->name)
673 return -ENOMEM;
674
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530675 w->sname = stream;
676 w->reg = SND_SOC_NOPM;
677 w->shift = 0;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530678 w->kcontrol_news = wc;
679 w->num_kcontrols = numkc;
680 w->priv = priv;
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530681 w->event = event;
682 w->event_flags = event_flags;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530683
684 return 0;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530685}
686
687static void hdac_hdmi_fill_route(struct snd_soc_dapm_route *route,
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530688 const char *sink, const char *control, const char *src,
689 int (*handler)(struct snd_soc_dapm_widget *src,
690 struct snd_soc_dapm_widget *sink))
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530691{
692 route->sink = sink;
693 route->source = src;
694 route->control = control;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530695 route->connected = handler;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530696}
697
Jeeja KP4a3478d2016-02-12 07:46:06 +0530698static struct hdac_hdmi_pcm *hdac_hdmi_get_pcm(struct hdac_ext_device *edev,
Jeeja KP754695f2017-02-06 12:09:14 +0530699 struct hdac_hdmi_port *port)
Jeeja KP4a3478d2016-02-12 07:46:06 +0530700{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530701 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Jeeja KP4a3478d2016-02-12 07:46:06 +0530702 struct hdac_hdmi_pcm *pcm = NULL;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530703 struct hdac_hdmi_port *p;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530704
705 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530706 if (list_empty(&pcm->port_list))
Jeeja KP754695f2017-02-06 12:09:14 +0530707 continue;
708
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530709 list_for_each_entry(p, &pcm->port_list, head) {
710 if (p->id == port->id && port->pin == p->pin)
711 return pcm;
712 }
Jeeja KP4a3478d2016-02-12 07:46:06 +0530713 }
714
715 return NULL;
716}
717
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530718static void hdac_hdmi_set_power_state(struct hdac_ext_device *edev,
719 hda_nid_t nid, unsigned int pwr_state)
720{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530721 if (get_wcaps(&edev->hdev, nid) & AC_WCAP_POWER) {
722 if (!snd_hdac_check_power_state(&edev->hdev, nid, pwr_state))
723 snd_hdac_codec_write(&edev->hdev, nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530724 AC_VERB_SET_POWER_STATE, pwr_state);
725 }
726}
727
728static void hdac_hdmi_set_amp(struct hdac_ext_device *edev,
729 hda_nid_t nid, int val)
730{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530731 if (get_wcaps(&edev->hdev, nid) & AC_WCAP_OUT_AMP)
732 snd_hdac_codec_write(&edev->hdev, nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530733 AC_VERB_SET_AMP_GAIN_MUTE, val);
734}
735
736
737static int hdac_hdmi_pin_output_widget_event(struct snd_soc_dapm_widget *w,
738 struct snd_kcontrol *kc, int event)
739{
Jeeja KP754695f2017-02-06 12:09:14 +0530740 struct hdac_hdmi_port *port = w->priv;
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530741 struct hdac_ext_device *edev = to_hda_ext_device(w->dapm->dev);
742 struct hdac_hdmi_pcm *pcm;
743
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530744 dev_dbg(&edev->hdev.dev, "%s: widget: %s event: %x\n",
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530745 __func__, w->name, event);
746
Jeeja KP754695f2017-02-06 12:09:14 +0530747 pcm = hdac_hdmi_get_pcm(edev, port);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530748 if (!pcm)
749 return -EIO;
750
Jeeja KP1b46ebd2017-02-07 19:09:47 +0530751 /* set the device if pin is mst_capable */
752 if (hdac_hdmi_port_select_set(edev, port) < 0)
753 return -EIO;
754
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530755 switch (event) {
756 case SND_SOC_DAPM_PRE_PMU:
Jeeja KP754695f2017-02-06 12:09:14 +0530757 hdac_hdmi_set_power_state(edev, port->pin->nid, AC_PWRST_D0);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530758
759 /* Enable out path for this pin widget */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530760 snd_hdac_codec_write(&edev->hdev, port->pin->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530761 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
762
Jeeja KP754695f2017-02-06 12:09:14 +0530763 hdac_hdmi_set_amp(edev, port->pin->nid, AMP_OUT_UNMUTE);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530764
Jeeja KP754695f2017-02-06 12:09:14 +0530765 return hdac_hdmi_setup_audio_infoframe(edev, pcm, port);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530766
767 case SND_SOC_DAPM_POST_PMD:
Jeeja KP754695f2017-02-06 12:09:14 +0530768 hdac_hdmi_set_amp(edev, port->pin->nid, AMP_OUT_MUTE);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530769
770 /* Disable out path for this pin widget */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530771 snd_hdac_codec_write(&edev->hdev, port->pin->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530772 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
773
Jeeja KP754695f2017-02-06 12:09:14 +0530774 hdac_hdmi_set_power_state(edev, port->pin->nid, AC_PWRST_D3);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530775 break;
776
777 }
778
779 return 0;
780}
781
782static int hdac_hdmi_cvt_output_widget_event(struct snd_soc_dapm_widget *w,
783 struct snd_kcontrol *kc, int event)
784{
785 struct hdac_hdmi_cvt *cvt = w->priv;
786 struct hdac_ext_device *edev = to_hda_ext_device(w->dapm->dev);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530787 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530788 struct hdac_hdmi_pcm *pcm;
789
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530790 dev_dbg(&edev->hdev.dev, "%s: widget: %s event: %x\n",
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530791 __func__, w->name, event);
792
793 pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, cvt);
794 if (!pcm)
795 return -EIO;
796
797 switch (event) {
798 case SND_SOC_DAPM_PRE_PMU:
799 hdac_hdmi_set_power_state(edev, cvt->nid, AC_PWRST_D0);
800
801 /* Enable transmission */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530802 snd_hdac_codec_write(&edev->hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530803 AC_VERB_SET_DIGI_CONVERT_1, 1);
804
805 /* Category Code (CC) to zero */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530806 snd_hdac_codec_write(&edev->hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530807 AC_VERB_SET_DIGI_CONVERT_2, 0);
808
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530809 snd_hdac_codec_write(&edev->hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530810 AC_VERB_SET_CHANNEL_STREAMID, pcm->stream_tag);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530811 snd_hdac_codec_write(&edev->hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530812 AC_VERB_SET_STREAM_FORMAT, pcm->format);
813 break;
814
815 case SND_SOC_DAPM_POST_PMD:
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530816 snd_hdac_codec_write(&edev->hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530817 AC_VERB_SET_CHANNEL_STREAMID, 0);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530818 snd_hdac_codec_write(&edev->hdev, cvt->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530819 AC_VERB_SET_STREAM_FORMAT, 0);
820
821 hdac_hdmi_set_power_state(edev, cvt->nid, AC_PWRST_D3);
822 break;
823
824 }
825
826 return 0;
827}
828
829static int hdac_hdmi_pin_mux_widget_event(struct snd_soc_dapm_widget *w,
830 struct snd_kcontrol *kc, int event)
831{
Jeeja KP754695f2017-02-06 12:09:14 +0530832 struct hdac_hdmi_port *port = w->priv;
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530833 struct hdac_ext_device *edev = to_hda_ext_device(w->dapm->dev);
834 int mux_idx;
835
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530836 dev_dbg(&edev->hdev.dev, "%s: widget: %s event: %x\n",
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530837 __func__, w->name, event);
838
839 if (!kc)
840 kc = w->kcontrols[0];
841
842 mux_idx = dapm_kcontrol_get_value(kc);
Jeeja KP1b46ebd2017-02-07 19:09:47 +0530843
844 /* set the device if pin is mst_capable */
845 if (hdac_hdmi_port_select_set(edev, port) < 0)
846 return -EIO;
847
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530848 if (mux_idx > 0) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530849 snd_hdac_codec_write(&edev->hdev, port->pin->nid, 0,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530850 AC_VERB_SET_CONNECT_SEL, (mux_idx - 1));
851 }
852
853 return 0;
854}
855
Jeeja KP4a3478d2016-02-12 07:46:06 +0530856/*
857 * Based on user selection, map the PINs with the PCMs.
858 */
Jeeja KP754695f2017-02-06 12:09:14 +0530859static int hdac_hdmi_set_pin_port_mux(struct snd_kcontrol *kcontrol,
Jeeja KP4a3478d2016-02-12 07:46:06 +0530860 struct snd_ctl_elem_value *ucontrol)
861{
862 int ret;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530863 struct hdac_hdmi_port *p, *p_next;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530864 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
865 struct snd_soc_dapm_widget *w = snd_soc_dapm_kcontrol_widget(kcontrol);
866 struct snd_soc_dapm_context *dapm = w->dapm;
Jeeja KP754695f2017-02-06 12:09:14 +0530867 struct hdac_hdmi_port *port = w->priv;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530868 struct hdac_ext_device *edev = to_hda_ext_device(dapm->dev);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530869 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Jeeja KP4a3478d2016-02-12 07:46:06 +0530870 struct hdac_hdmi_pcm *pcm = NULL;
871 const char *cvt_name = e->texts[ucontrol->value.enumerated.item[0]];
872
873 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
874 if (ret < 0)
875 return ret;
876
Jeeja KP754695f2017-02-06 12:09:14 +0530877 if (port == NULL)
878 return -EINVAL;
879
Jeeja KP4a3478d2016-02-12 07:46:06 +0530880 mutex_lock(&hdmi->pin_mutex);
881 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530882 if (list_empty(&pcm->port_list))
883 continue;
Jeeja KP4a3478d2016-02-12 07:46:06 +0530884
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530885 list_for_each_entry_safe(p, p_next, &pcm->port_list, head) {
886 if (p == port && p->id == port->id &&
887 p->pin == port->pin) {
888 hdac_hdmi_jack_report(pcm, port, false);
889 list_del(&p->head);
Jeeja KP4a3478d2016-02-12 07:46:06 +0530890 }
Jeeja KPe0e5d3e2017-02-07 19:09:48 +0530891 }
892 }
893
894 /*
895 * Jack status is not reported during device probe as the
896 * PCMs are not registered by then. So report it here.
897 */
898 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
899 if (!strcmp(cvt_name, pcm->cvt->name)) {
900 list_add_tail(&port->head, &pcm->port_list);
901 if (port->eld.monitor_present && port->eld.eld_valid) {
902 hdac_hdmi_jack_report(pcm, port, true);
903 mutex_unlock(&hdmi->pin_mutex);
904 return ret;
905 }
Jeeja KP4a3478d2016-02-12 07:46:06 +0530906 }
907 }
908 mutex_unlock(&hdmi->pin_mutex);
909
910 return ret;
911}
912
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530913/*
914 * Ideally the Mux inputs should be based on the num_muxs enumerated, but
915 * the display driver seem to be programming the connection list for the pin
916 * widget runtime.
917 *
918 * So programming all the possible inputs for the mux, the user has to take
919 * care of selecting the right one and leaving all other inputs selected to
920 * "NONE"
921 */
Jeeja KP754695f2017-02-06 12:09:14 +0530922static int hdac_hdmi_create_pin_port_muxs(struct hdac_ext_device *edev,
923 struct hdac_hdmi_port *port,
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530924 struct snd_soc_dapm_widget *widget,
925 const char *widget_name)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530926{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530927 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Jeeja KP754695f2017-02-06 12:09:14 +0530928 struct hdac_hdmi_pin *pin = port->pin;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530929 struct snd_kcontrol_new *kc;
930 struct hdac_hdmi_cvt *cvt;
931 struct soc_enum *se;
932 char kc_name[NAME_SIZE];
933 char mux_items[NAME_SIZE];
934 /* To hold inputs to the Pin mux */
935 char *items[HDA_MAX_CONNECTIONS];
936 int i = 0;
937 int num_items = hdmi->num_cvt + 1;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530938
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530939 kc = devm_kzalloc(&edev->hdev.dev, sizeof(*kc), GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530940 if (!kc)
941 return -ENOMEM;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530942
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530943 se = devm_kzalloc(&edev->hdev.dev, sizeof(*se), GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530944 if (!se)
945 return -ENOMEM;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530946
Subhransu S. Prusty70e97a22017-11-07 16:16:24 +0530947 snprintf(kc_name, NAME_SIZE, "Pin %d port %d Input",
948 pin->nid, port->id);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530949 kc->name = devm_kstrdup(&edev->hdev.dev, kc_name, GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530950 if (!kc->name)
951 return -ENOMEM;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +0530952
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530953 kc->private_value = (long)se;
954 kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
955 kc->access = 0;
956 kc->info = snd_soc_info_enum_double;
Jeeja KP754695f2017-02-06 12:09:14 +0530957 kc->put = hdac_hdmi_set_pin_port_mux;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530958 kc->get = snd_soc_dapm_get_enum_double;
959
960 se->reg = SND_SOC_NOPM;
961
962 /* enum texts: ["NONE", "cvt #", "cvt #", ...] */
963 se->items = num_items;
964 se->mask = roundup_pow_of_two(se->items) - 1;
965
966 sprintf(mux_items, "NONE");
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530967 items[i] = devm_kstrdup(&edev->hdev.dev, mux_items, GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530968 if (!items[i])
969 return -ENOMEM;
970
971 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
972 i++;
973 sprintf(mux_items, "cvt %d", cvt->nid);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530974 items[i] = devm_kstrdup(&edev->hdev.dev, mux_items, GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530975 if (!items[i])
976 return -ENOMEM;
977 }
978
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530979 se->texts = devm_kmemdup(&edev->hdev.dev, items,
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530980 (num_items * sizeof(char *)), GFP_KERNEL);
981 if (!se->texts)
982 return -ENOMEM;
983
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530984 return hdac_hdmi_fill_widget_info(&edev->hdev.dev, widget,
Jeeja KP754695f2017-02-06 12:09:14 +0530985 snd_soc_dapm_mux, port, widget_name, NULL, kc, 1,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +0530986 hdac_hdmi_pin_mux_widget_event,
987 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_REG);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530988}
989
990/* Add cvt <- input <- mux route map */
991static void hdac_hdmi_add_pinmux_cvt_route(struct hdac_ext_device *edev,
992 struct snd_soc_dapm_widget *widgets,
993 struct snd_soc_dapm_route *route, int rindex)
994{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +0530995 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530996 const struct snd_kcontrol_new *kc;
997 struct soc_enum *se;
Jeeja KP754695f2017-02-06 12:09:14 +0530998 int mux_index = hdmi->num_cvt + hdmi->num_ports;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +0530999 int i, j;
1000
Jeeja KP754695f2017-02-06 12:09:14 +05301001 for (i = 0; i < hdmi->num_ports; i++) {
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301002 kc = widgets[mux_index].kcontrol_news;
1003 se = (struct soc_enum *)kc->private_value;
1004 for (j = 0; j < hdmi->num_cvt; j++) {
1005 hdac_hdmi_fill_route(&route[rindex],
1006 widgets[mux_index].name,
1007 se->texts[j + 1],
1008 widgets[j].name, NULL);
1009
1010 rindex++;
1011 }
1012
1013 mux_index++;
1014 }
1015}
1016
1017/*
1018 * Widgets are added in the below sequence
1019 * Converter widgets for num converters enumerated
Jeeja KP754695f2017-02-06 12:09:14 +05301020 * Pin-port widgets for num ports for Pins enumerated
1021 * Pin-port mux widgets to represent connenction list of pin widget
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301022 *
Jeeja KP754695f2017-02-06 12:09:14 +05301023 * For each port, one Mux and One output widget is added
1024 * Total widgets elements = num_cvt + (num_ports * 2);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301025 *
1026 * Routes are added as below:
Jeeja KP754695f2017-02-06 12:09:14 +05301027 * pin-port mux -> pin (based on num_ports)
1028 * cvt -> "Input sel control" -> pin-port_mux
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301029 *
1030 * Total route elements:
Jeeja KP754695f2017-02-06 12:09:14 +05301031 * num_ports + (pin_muxes * num_cvt)
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301032 */
1033static int create_fill_widget_route_map(struct snd_soc_dapm_context *dapm)
1034{
1035 struct snd_soc_dapm_widget *widgets;
1036 struct snd_soc_dapm_route *route;
1037 struct hdac_ext_device *edev = to_hda_ext_device(dapm->dev);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301038 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Kuninori Morimoto1e02dac2017-12-20 01:48:13 +00001039 struct snd_soc_dai_driver *dai_drv = hdmi->dai_drv;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301040 char widget_name[NAME_SIZE];
1041 struct hdac_hdmi_cvt *cvt;
1042 struct hdac_hdmi_pin *pin;
Jeeja KP754695f2017-02-06 12:09:14 +05301043 int ret, i = 0, num_routes = 0, j;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301044
1045 if (list_empty(&hdmi->cvt_list) || list_empty(&hdmi->pin_list))
1046 return -EINVAL;
1047
Jeeja KP754695f2017-02-06 12:09:14 +05301048 widgets = devm_kzalloc(dapm->dev, (sizeof(*widgets) *
1049 ((2 * hdmi->num_ports) + hdmi->num_cvt)),
1050 GFP_KERNEL);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301051
1052 if (!widgets)
1053 return -ENOMEM;
1054
1055 /* DAPM widgets to represent each converter widget */
1056 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
1057 sprintf(widget_name, "Converter %d", cvt->nid);
1058 ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
Jeeja KPc9bfb5d2017-01-24 21:49:03 +05301059 snd_soc_dapm_aif_in, cvt,
1060 widget_name, dai_drv[i].playback.stream_name, NULL, 0,
1061 hdac_hdmi_cvt_output_widget_event,
1062 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD);
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301063 if (ret < 0)
1064 return ret;
1065 i++;
1066 }
1067
1068 list_for_each_entry(pin, &hdmi->pin_list, head) {
Jeeja KP754695f2017-02-06 12:09:14 +05301069 for (j = 0; j < pin->num_ports; j++) {
1070 sprintf(widget_name, "hif%d-%d Output",
1071 pin->nid, pin->ports[j].id);
1072 ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
1073 snd_soc_dapm_output, &pin->ports[j],
1074 widget_name, NULL, NULL, 0,
1075 hdac_hdmi_pin_output_widget_event,
1076 SND_SOC_DAPM_PRE_PMU |
1077 SND_SOC_DAPM_POST_PMD);
1078 if (ret < 0)
1079 return ret;
Jeeja KP0324e512017-02-07 19:09:55 +05301080 pin->ports[j].output_pin = widgets[i].name;
Jeeja KP754695f2017-02-06 12:09:14 +05301081 i++;
1082 }
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301083 }
1084
1085 /* DAPM widgets to represent the connection list to pin widget */
1086 list_for_each_entry(pin, &hdmi->pin_list, head) {
Jeeja KP754695f2017-02-06 12:09:14 +05301087 for (j = 0; j < pin->num_ports; j++) {
1088 sprintf(widget_name, "Pin%d-Port%d Mux",
1089 pin->nid, pin->ports[j].id);
1090 ret = hdac_hdmi_create_pin_port_muxs(edev,
1091 &pin->ports[j], &widgets[i],
1092 widget_name);
1093 if (ret < 0)
1094 return ret;
1095 i++;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301096
Jeeja KP754695f2017-02-06 12:09:14 +05301097 /* For cvt to pin_mux mapping */
1098 num_routes += hdmi->num_cvt;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301099
Jeeja KP754695f2017-02-06 12:09:14 +05301100 /* For pin_mux to pin mapping */
1101 num_routes++;
1102 }
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301103 }
1104
1105 route = devm_kzalloc(dapm->dev, (sizeof(*route) * num_routes),
1106 GFP_KERNEL);
1107 if (!route)
1108 return -ENOMEM;
1109
1110 i = 0;
1111 /* Add pin <- NULL <- mux route map */
1112 list_for_each_entry(pin, &hdmi->pin_list, head) {
Jeeja KP754695f2017-02-06 12:09:14 +05301113 for (j = 0; j < pin->num_ports; j++) {
1114 int sink_index = i + hdmi->num_cvt;
1115 int src_index = sink_index + pin->num_ports *
1116 hdmi->num_pin;
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301117
Jeeja KP754695f2017-02-06 12:09:14 +05301118 hdac_hdmi_fill_route(&route[i],
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301119 widgets[sink_index].name, NULL,
1120 widgets[src_index].name, NULL);
Jeeja KP754695f2017-02-06 12:09:14 +05301121 i++;
1122 }
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301123 }
1124
1125 hdac_hdmi_add_pinmux_cvt_route(edev, widgets, route, i);
1126
1127 snd_soc_dapm_new_controls(dapm, widgets,
Jeeja KP754695f2017-02-06 12:09:14 +05301128 ((2 * hdmi->num_ports) + hdmi->num_cvt));
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301129
1130 snd_soc_dapm_add_routes(dapm, route, num_routes);
1131 snd_soc_dapm_new_widgets(dapm->card);
1132
1133 return 0;
1134
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301135}
1136
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301137static int hdac_hdmi_init_dai_map(struct hdac_ext_device *edev)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301138{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301139 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Jeeja KP754695f2017-02-06 12:09:14 +05301140 struct hdac_hdmi_dai_port_map *dai_map;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301141 struct hdac_hdmi_cvt *cvt;
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301142 int dai_id = 0;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301143
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301144 if (list_empty(&hdmi->cvt_list))
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301145 return -EINVAL;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301146
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301147 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
1148 dai_map = &hdmi->dai_map[dai_id];
1149 dai_map->dai_id = dai_id;
1150 dai_map->cvt = cvt;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301151
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301152 dai_id++;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301153
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301154 if (dai_id == HDA_MAX_CVTS) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301155 dev_warn(&edev->hdev.dev,
Subhransu S. Prusty148569f2016-02-12 07:46:07 +05301156 "Max dais supported: %d\n", dai_id);
1157 break;
1158 }
1159 }
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301160
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301161 return 0;
1162}
1163
1164static int hdac_hdmi_add_cvt(struct hdac_ext_device *edev, hda_nid_t nid)
1165{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301166 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301167 struct hdac_hdmi_cvt *cvt;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301168 char name[NAME_SIZE];
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301169
1170 cvt = kzalloc(sizeof(*cvt), GFP_KERNEL);
1171 if (!cvt)
1172 return -ENOMEM;
1173
1174 cvt->nid = nid;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301175 sprintf(name, "cvt %d", cvt->nid);
1176 cvt->name = kstrdup(name, GFP_KERNEL);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301177
1178 list_add_tail(&cvt->head, &hdmi->cvt_list);
1179 hdmi->num_cvt++;
1180
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301181 return hdac_hdmi_query_cvt_params(&edev->hdev, cvt);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301182}
1183
Jeeja KP754695f2017-02-06 12:09:14 +05301184static int hdac_hdmi_parse_eld(struct hdac_ext_device *edev,
1185 struct hdac_hdmi_port *port)
Subhransu S. Prustyb7756ed2016-04-14 10:07:28 +05301186{
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301187 unsigned int ver, mnl;
1188
Jeeja KP754695f2017-02-06 12:09:14 +05301189 ver = (port->eld.eld_buffer[DRM_ELD_VER] & DRM_ELD_VER_MASK)
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301190 >> DRM_ELD_VER_SHIFT;
1191
1192 if (ver != ELD_VER_CEA_861D && ver != ELD_VER_PARTIAL) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301193 dev_err(&edev->hdev.dev, "HDMI: Unknown ELD version %d\n", ver);
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301194 return -EINVAL;
1195 }
1196
Jeeja KP754695f2017-02-06 12:09:14 +05301197 mnl = (port->eld.eld_buffer[DRM_ELD_CEA_EDID_VER_MNL] &
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301198 DRM_ELD_MNL_MASK) >> DRM_ELD_MNL_SHIFT;
1199
1200 if (mnl > ELD_MAX_MNL) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301201 dev_err(&edev->hdev.dev, "HDMI: MNL Invalid %d\n", mnl);
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301202 return -EINVAL;
1203 }
1204
Jeeja KP754695f2017-02-06 12:09:14 +05301205 port->eld.info.spk_alloc = port->eld.eld_buffer[DRM_ELD_SPEAKER];
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301206
1207 return 0;
Subhransu S. Prustyb7756ed2016-04-14 10:07:28 +05301208}
1209
Jeeja KP754695f2017-02-06 12:09:14 +05301210static void hdac_hdmi_present_sense(struct hdac_hdmi_pin *pin,
1211 struct hdac_hdmi_port *port)
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301212{
1213 struct hdac_ext_device *edev = pin->edev;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301214 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Jeeja KP4a3478d2016-02-12 07:46:06 +05301215 struct hdac_hdmi_pcm *pcm;
Jeeja KP754695f2017-02-06 12:09:14 +05301216 int size = 0;
Jeeja KP2acd8302017-02-06 12:09:18 +05301217 int port_id = -1;
Jeeja KP754695f2017-02-06 12:09:14 +05301218
1219 if (!hdmi)
1220 return;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301221
Jeeja KP2acd8302017-02-06 12:09:18 +05301222 /*
1223 * In case of non MST pin, get_eld info API expectes port
1224 * to be -1.
1225 */
Jeeja KP4a3478d2016-02-12 07:46:06 +05301226 mutex_lock(&hdmi->pin_mutex);
Jeeja KP754695f2017-02-06 12:09:14 +05301227 port->eld.monitor_present = false;
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301228
Jeeja KP2acd8302017-02-06 12:09:18 +05301229 if (pin->mst_capable)
1230 port_id = port->id;
1231
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301232 size = snd_hdac_acomp_get_eld(&edev->hdev, pin->nid, port_id,
Jeeja KP754695f2017-02-06 12:09:14 +05301233 &port->eld.monitor_present,
1234 port->eld.eld_buffer,
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301235 ELD_MAX_SIZE);
1236
1237 if (size > 0) {
1238 size = min(size, ELD_MAX_SIZE);
Jeeja KP754695f2017-02-06 12:09:14 +05301239 if (hdac_hdmi_parse_eld(edev, port) < 0)
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301240 size = -EINVAL;
1241 }
1242
1243 if (size > 0) {
Jeeja KP754695f2017-02-06 12:09:14 +05301244 port->eld.eld_valid = true;
1245 port->eld.eld_size = size;
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301246 } else {
Jeeja KP754695f2017-02-06 12:09:14 +05301247 port->eld.eld_valid = false;
1248 port->eld.eld_size = 0;
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301249 }
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301250
Jeeja KP754695f2017-02-06 12:09:14 +05301251 pcm = hdac_hdmi_get_pcm(edev, port);
Jeeja KP4a3478d2016-02-12 07:46:06 +05301252
Jeeja KP754695f2017-02-06 12:09:14 +05301253 if (!port->eld.monitor_present || !port->eld.eld_valid) {
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301254
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301255 dev_err(&edev->hdev.dev, "%s: disconnect for pin:port %d:%d\n",
Jeeja KP754695f2017-02-06 12:09:14 +05301256 __func__, pin->nid, port->id);
Jeeja KP4a3478d2016-02-12 07:46:06 +05301257
1258 /*
1259 * PCMs are not registered during device probe, so don't
1260 * report jack here. It will be done in usermode mux
1261 * control select.
1262 */
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301263 if (pcm)
1264 hdac_hdmi_jack_report(pcm, port, false);
Jeeja KP4a3478d2016-02-12 07:46:06 +05301265
1266 mutex_unlock(&hdmi->pin_mutex);
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301267 return;
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301268 }
1269
Jeeja KP754695f2017-02-06 12:09:14 +05301270 if (port->eld.monitor_present && port->eld.eld_valid) {
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301271 if (pcm)
1272 hdac_hdmi_jack_report(pcm, port, true);
Sandeep Tayalf6fa11a2017-01-18 21:34:41 +05301273
1274 print_hex_dump_debug("ELD: ", DUMP_PREFIX_OFFSET, 16, 1,
Jeeja KP754695f2017-02-06 12:09:14 +05301275 port->eld.eld_buffer, port->eld.eld_size, false);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301276
Jeeja KP754695f2017-02-06 12:09:14 +05301277 }
Jeeja KP4a3478d2016-02-12 07:46:06 +05301278 mutex_unlock(&hdmi->pin_mutex);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301279}
1280
Jeeja KP754695f2017-02-06 12:09:14 +05301281static int hdac_hdmi_add_ports(struct hdac_hdmi_priv *hdmi,
1282 struct hdac_hdmi_pin *pin)
1283{
1284 struct hdac_hdmi_port *ports;
1285 int max_ports = HDA_MAX_PORTS;
1286 int i;
1287
1288 /*
1289 * FIXME: max_port may vary for each platform, so pass this as
1290 * as driver data or query from i915 interface when this API is
1291 * implemented.
1292 */
1293
1294 ports = kcalloc(max_ports, sizeof(*ports), GFP_KERNEL);
1295 if (!ports)
1296 return -ENOMEM;
1297
1298 for (i = 0; i < max_ports; i++) {
1299 ports[i].id = i;
1300 ports[i].pin = pin;
1301 }
1302 pin->ports = ports;
1303 pin->num_ports = max_ports;
1304 return 0;
1305}
1306
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301307static int hdac_hdmi_add_pin(struct hdac_ext_device *edev, hda_nid_t nid)
1308{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301309 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301310 struct hdac_hdmi_pin *pin;
Jeeja KP754695f2017-02-06 12:09:14 +05301311 int ret;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301312
1313 pin = kzalloc(sizeof(*pin), GFP_KERNEL);
1314 if (!pin)
1315 return -ENOMEM;
1316
1317 pin->nid = nid;
Jeeja KP2acd8302017-02-06 12:09:18 +05301318 pin->mst_capable = false;
Jeeja KP754695f2017-02-06 12:09:14 +05301319 pin->edev = edev;
1320 ret = hdac_hdmi_add_ports(hdmi, pin);
1321 if (ret < 0)
1322 return ret;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301323
1324 list_add_tail(&pin->head, &hdmi->pin_list);
1325 hdmi->num_pin++;
Jeeja KP754695f2017-02-06 12:09:14 +05301326 hdmi->num_ports += pin->num_ports;
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301327
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301328 return 0;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301329}
1330
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301331#define INTEL_VENDOR_NID 0x08
Pradeep Tewani5622bc92017-07-20 11:40:56 +05301332#define INTEL_GLK_VENDOR_NID 0x0b
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301333#define INTEL_GET_VENDOR_VERB 0xf81
1334#define INTEL_SET_VENDOR_VERB 0x781
1335#define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
1336#define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
1337
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301338static void hdac_hdmi_skl_enable_all_pins(struct hdac_device *hdev)
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301339{
1340 unsigned int vendor_param;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301341 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Pradeep Tewani5622bc92017-07-20 11:40:56 +05301342 unsigned int vendor_nid = hdmi->drv_data->vendor_nid;
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301343
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301344 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301345 INTEL_GET_VENDOR_VERB, 0);
1346 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
1347 return;
1348
1349 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301350 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301351 INTEL_SET_VENDOR_VERB, vendor_param);
1352 if (vendor_param == -1)
1353 return;
1354}
1355
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301356static void hdac_hdmi_skl_enable_dp12(struct hdac_device *hdev)
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301357{
1358 unsigned int vendor_param;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301359 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Pradeep Tewani5622bc92017-07-20 11:40:56 +05301360 unsigned int vendor_nid = hdmi->drv_data->vendor_nid;
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301361
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301362 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301363 INTEL_GET_VENDOR_VERB, 0);
1364 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
1365 return;
1366
1367 /* enable DP1.2 mode */
1368 vendor_param |= INTEL_EN_DP12;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301369 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
Subhransu S. Prusty211caab2016-02-12 07:46:03 +05301370 INTEL_SET_VENDOR_VERB, vendor_param);
1371 if (vendor_param == -1)
1372 return;
1373
1374}
1375
Gustavo A. R. Silva61b3b3c2017-07-13 15:38:38 -05001376static const struct snd_soc_dai_ops hdmi_dai_ops = {
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301377 .startup = hdac_hdmi_pcm_open,
1378 .shutdown = hdac_hdmi_pcm_close,
1379 .hw_params = hdac_hdmi_set_hw_params,
Jeeja KPc9bfb5d2017-01-24 21:49:03 +05301380 .set_tdm_slot = hdac_hdmi_set_tdm_slot,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301381};
1382
1383/*
1384 * Each converter can support a stream independently. So a dai is created
1385 * based on the number of converter queried.
1386 */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301387static int hdac_hdmi_create_dais(struct hdac_device *hdev,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301388 struct snd_soc_dai_driver **dais,
1389 struct hdac_hdmi_priv *hdmi, int num_dais)
1390{
1391 struct snd_soc_dai_driver *hdmi_dais;
1392 struct hdac_hdmi_cvt *cvt;
1393 char name[NAME_SIZE], dai_name[NAME_SIZE];
1394 int i = 0;
1395 u32 rates, bps;
1396 unsigned int rate_max = 384000, rate_min = 8000;
1397 u64 formats;
1398 int ret;
1399
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301400 hdmi_dais = devm_kzalloc(&hdev->dev,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301401 (sizeof(*hdmi_dais) * num_dais),
1402 GFP_KERNEL);
1403 if (!hdmi_dais)
1404 return -ENOMEM;
1405
1406 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301407 ret = snd_hdac_query_supported_pcm(hdev, cvt->nid,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301408 &rates, &formats, &bps);
1409 if (ret)
1410 return ret;
1411
1412 sprintf(dai_name, "intel-hdmi-hifi%d", i+1);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301413 hdmi_dais[i].name = devm_kstrdup(&hdev->dev,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301414 dai_name, GFP_KERNEL);
1415
1416 if (!hdmi_dais[i].name)
1417 return -ENOMEM;
1418
1419 snprintf(name, sizeof(name), "hifi%d", i+1);
1420 hdmi_dais[i].playback.stream_name =
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301421 devm_kstrdup(&hdev->dev, name, GFP_KERNEL);
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301422 if (!hdmi_dais[i].playback.stream_name)
1423 return -ENOMEM;
1424
1425 /*
1426 * Set caps based on capability queried from the converter.
1427 * It will be constrained runtime based on ELD queried.
1428 */
1429 hdmi_dais[i].playback.formats = formats;
1430 hdmi_dais[i].playback.rates = rates;
1431 hdmi_dais[i].playback.rate_max = rate_max;
1432 hdmi_dais[i].playback.rate_min = rate_min;
1433 hdmi_dais[i].playback.channels_min = 2;
1434 hdmi_dais[i].playback.channels_max = 2;
Jeeja KP66d6bbc2017-03-24 23:10:26 +05301435 hdmi_dais[i].playback.sig_bits = bps;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301436 hdmi_dais[i].ops = &hdmi_dai_ops;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301437 i++;
1438 }
1439
1440 *dais = hdmi_dais;
Kuninori Morimoto1e02dac2017-12-20 01:48:13 +00001441 hdmi->dai_drv = hdmi_dais;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301442
1443 return 0;
1444}
1445
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301446/*
1447 * Parse all nodes and store the cvt/pin nids in array
1448 * Add one time initialization for pin and cvt widgets
1449 */
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301450static int hdac_hdmi_parse_and_map_nid(struct hdac_ext_device *edev,
1451 struct snd_soc_dai_driver **dais, int *num_dais)
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301452{
1453 hda_nid_t nid;
Sudip Mukherjee3c83ac22015-12-01 14:29:35 +05301454 int i, num_nodes;
Subhransu S. Prusty1c0a7de2017-11-07 16:16:26 +05301455 struct hdac_hdmi_cvt *temp_cvt, *cvt_next;
1456 struct hdac_hdmi_pin *temp_pin, *pin_next;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301457 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
1458 struct hdac_device *hdev = &edev->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:
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301483 ret = hdac_hdmi_add_cvt(edev, nid);
1484 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:
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05301489 ret = hdac_hdmi_add_pin(edev, nid);
1490 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;
Subhransu S. Prusty1c0a7de2017-11-07 16:16:26 +05301509 ret = hdac_hdmi_init_dai_map(edev);
1510 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
Pandiyan, Dhinakaranf9318942016-09-21 13:02:48 -07001533static void hdac_hdmi_eld_notify_cb(void *aptr, int port, int pipe)
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301534{
1535 struct hdac_ext_device *edev = aptr;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301536 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Jeeja KP754695f2017-02-06 12:09:14 +05301537 struct hdac_hdmi_pin *pin = NULL;
1538 struct hdac_hdmi_port *hport = NULL;
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301539 struct snd_soc_codec *codec = edev->scodec;
Jeeja KP2acd8302017-02-06 12:09:18 +05301540 int i;
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301541
1542 /* Don't know how this mapping is derived */
1543 hda_nid_t pin_nid = port + 0x04;
1544
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301545 dev_dbg(&edev->hdev.dev, "%s: for pin:%d port=%d\n", __func__,
Jeeja KP754695f2017-02-06 12:09:14 +05301546 pin_nid, pipe);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301547
1548 /*
1549 * skip notification during system suspend (but not in runtime PM);
1550 * the state will be updated at resume. Also since the ELD and
1551 * connection states are updated in anyway at the end of the resume,
1552 * we can skip it when received during PM process.
1553 */
1554 if (snd_power_get_state(codec->component.card->snd_card) !=
1555 SNDRV_CTL_POWER_D0)
1556 return;
1557
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301558 if (atomic_read(&edev->hdev.in_pm))
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301559 return;
1560
1561 list_for_each_entry(pin, &hdmi->pin_list, head) {
Jeeja KP754695f2017-02-06 12:09:14 +05301562 if (pin->nid != pin_nid)
1563 continue;
1564
1565 /* In case of non MST pin, pipe is -1 */
1566 if (pipe == -1) {
Jeeja KP2acd8302017-02-06 12:09:18 +05301567 pin->mst_capable = false;
Jeeja KP754695f2017-02-06 12:09:14 +05301568 /* if not MST, default is port[0] */
1569 hport = &pin->ports[0];
Jeeja KP2acd8302017-02-06 12:09:18 +05301570 } else {
1571 for (i = 0; i < pin->num_ports; i++) {
1572 pin->mst_capable = true;
1573 if (pin->ports[i].id == pipe) {
1574 hport = &pin->ports[i];
Jeeja KP04c8f2b2017-03-01 22:41:23 +05301575 break;
Jeeja KP2acd8302017-02-06 12:09:18 +05301576 }
1577 }
Jeeja KP754695f2017-02-06 12:09:14 +05301578 }
Jeeja KP04c8f2b2017-03-01 22:41:23 +05301579
1580 if (hport)
1581 hdac_hdmi_present_sense(pin, hport);
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301582 }
Jeeja KP754695f2017-02-06 12:09:14 +05301583
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301584}
1585
1586static struct i915_audio_component_audio_ops aops = {
1587 .pin_eld_notify = hdac_hdmi_eld_notify_cb,
1588};
1589
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301590static struct snd_pcm *hdac_hdmi_get_pcm_from_id(struct snd_soc_card *card,
1591 int device)
1592{
1593 struct snd_soc_pcm_runtime *rtd;
1594
1595 list_for_each_entry(rtd, &card->rtd_list, list) {
1596 if (rtd->pcm && (rtd->pcm->device == device))
1597 return rtd->pcm;
1598 }
1599
1600 return NULL;
1601}
1602
Jeeja KP0324e512017-02-07 19:09:55 +05301603/* create jack pin kcontrols */
1604static int create_fill_jack_kcontrols(struct snd_soc_card *card,
1605 struct hdac_ext_device *edev)
1606{
1607 struct hdac_hdmi_pin *pin;
1608 struct snd_kcontrol_new *kc;
1609 char kc_name[NAME_SIZE], xname[NAME_SIZE];
1610 char *name;
1611 int i = 0, j;
1612 struct snd_soc_codec *codec = edev->scodec;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301613 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Jeeja KP0324e512017-02-07 19:09:55 +05301614
1615 kc = devm_kcalloc(codec->dev, hdmi->num_ports,
1616 sizeof(*kc), GFP_KERNEL);
1617
1618 if (!kc)
1619 return -ENOMEM;
1620
1621 list_for_each_entry(pin, &hdmi->pin_list, head) {
1622 for (j = 0; j < pin->num_ports; j++) {
1623 snprintf(xname, sizeof(xname), "hif%d-%d Jack",
1624 pin->nid, pin->ports[j].id);
1625 name = devm_kstrdup(codec->dev, xname, GFP_KERNEL);
1626 if (!name)
1627 return -ENOMEM;
1628 snprintf(kc_name, sizeof(kc_name), "%s Switch", xname);
1629 kc[i].name = devm_kstrdup(codec->dev, kc_name,
1630 GFP_KERNEL);
1631 if (!kc[i].name)
1632 return -ENOMEM;
1633
1634 kc[i].private_value = (unsigned long)name;
1635 kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1636 kc[i].access = 0;
1637 kc[i].info = snd_soc_dapm_info_pin_switch;
1638 kc[i].put = snd_soc_dapm_put_pin_switch;
1639 kc[i].get = snd_soc_dapm_get_pin_switch;
1640 i++;
1641 }
1642 }
1643
1644 return snd_soc_add_card_controls(card, kc, i);
1645}
1646
1647int hdac_hdmi_jack_port_init(struct snd_soc_codec *codec,
1648 struct snd_soc_dapm_context *dapm)
1649{
1650 struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301651 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Jeeja KP0324e512017-02-07 19:09:55 +05301652 struct hdac_hdmi_pin *pin;
1653 struct snd_soc_dapm_widget *widgets;
1654 struct snd_soc_dapm_route *route;
1655 char w_name[NAME_SIZE];
1656 int i = 0, j, ret;
1657
1658 widgets = devm_kcalloc(dapm->dev, hdmi->num_ports,
1659 sizeof(*widgets), GFP_KERNEL);
1660
1661 if (!widgets)
1662 return -ENOMEM;
1663
1664 route = devm_kcalloc(dapm->dev, hdmi->num_ports,
1665 sizeof(*route), GFP_KERNEL);
1666 if (!route)
1667 return -ENOMEM;
1668
1669 /* create Jack DAPM widget */
1670 list_for_each_entry(pin, &hdmi->pin_list, head) {
1671 for (j = 0; j < pin->num_ports; j++) {
1672 snprintf(w_name, sizeof(w_name), "hif%d-%d Jack",
1673 pin->nid, pin->ports[j].id);
1674
1675 ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
1676 snd_soc_dapm_spk, NULL,
1677 w_name, NULL, NULL, 0, NULL, 0);
1678 if (ret < 0)
1679 return ret;
1680
1681 pin->ports[j].jack_pin = widgets[i].name;
1682 pin->ports[j].dapm = dapm;
1683
1684 /* add to route from Jack widget to output */
1685 hdac_hdmi_fill_route(&route[i], pin->ports[j].jack_pin,
1686 NULL, pin->ports[j].output_pin, NULL);
1687
1688 i++;
1689 }
1690 }
1691
1692 /* Add Route from Jack widget to the output widget */
1693 ret = snd_soc_dapm_new_controls(dapm, widgets, hdmi->num_ports);
1694 if (ret < 0)
1695 return ret;
1696
1697 ret = snd_soc_dapm_add_routes(dapm, route, hdmi->num_ports);
1698 if (ret < 0)
1699 return ret;
1700
1701 ret = snd_soc_dapm_new_widgets(dapm->card);
1702 if (ret < 0)
1703 return ret;
1704
1705 /* Add Jack Pin switch Kcontrol */
1706 ret = create_fill_jack_kcontrols(dapm->card, edev);
1707
1708 if (ret < 0)
1709 return ret;
1710
1711 /* default set the Jack Pin switch to OFF */
1712 list_for_each_entry(pin, &hdmi->pin_list, head) {
1713 for (j = 0; j < pin->num_ports; j++)
1714 snd_soc_dapm_disable_pin(pin->ports[j].dapm,
1715 pin->ports[j].jack_pin);
1716 }
1717
1718 return 0;
1719}
1720EXPORT_SYMBOL_GPL(hdac_hdmi_jack_port_init);
1721
Jeeja KP62490012017-02-07 19:09:49 +05301722int hdac_hdmi_jack_init(struct snd_soc_dai *dai, int device,
1723 struct snd_soc_jack *jack)
Jeeja KP4a3478d2016-02-12 07:46:06 +05301724{
Jeeja KP4a3478d2016-02-12 07:46:06 +05301725 struct snd_soc_codec *codec = dai->codec;
1726 struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301727 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Jeeja KP4a3478d2016-02-12 07:46:06 +05301728 struct hdac_hdmi_pcm *pcm;
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301729 struct snd_pcm *snd_pcm;
1730 int err;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301731
1732 /*
1733 * this is a new PCM device, create new pcm and
1734 * add to the pcm list
1735 */
1736 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
1737 if (!pcm)
1738 return -ENOMEM;
1739 pcm->pcm_id = device;
1740 pcm->cvt = hdmi->dai_map[dai->id].cvt;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301741 pcm->jack_event = 0;
Jeeja KP62490012017-02-07 19:09:49 +05301742 pcm->jack = jack;
Jeeja KPab1eea12017-01-24 21:49:05 +05301743 mutex_init(&pcm->lock);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301744 INIT_LIST_HEAD(&pcm->port_list);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301745 snd_pcm = hdac_hdmi_get_pcm_from_id(dai->component->card, device);
1746 if (snd_pcm) {
1747 err = snd_hdac_add_chmap_ctls(snd_pcm, device, &hdmi->chmap);
1748 if (err < 0) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301749 dev_err(&edev->hdev.dev,
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301750 "chmap control add failed with err: %d for pcm: %d\n",
1751 err, device);
1752 kfree(pcm);
1753 return err;
1754 }
1755 }
1756
Jeeja KP4a3478d2016-02-12 07:46:06 +05301757 list_add_tail(&pcm->head, &hdmi->pcm_list);
1758
Jeeja KP62490012017-02-07 19:09:49 +05301759 return 0;
Jeeja KP4a3478d2016-02-12 07:46:06 +05301760}
1761EXPORT_SYMBOL_GPL(hdac_hdmi_jack_init);
1762
Jeeja KPa9ce96b2017-02-07 19:09:46 +05301763static void hdac_hdmi_present_sense_all_pins(struct hdac_ext_device *edev,
1764 struct hdac_hdmi_priv *hdmi, bool detect_pin_caps)
1765{
1766 int i;
1767 struct hdac_hdmi_pin *pin;
1768
1769 list_for_each_entry(pin, &hdmi->pin_list, head) {
1770 if (detect_pin_caps) {
1771
1772 if (hdac_hdmi_get_port_len(edev, pin->nid) == 0)
1773 pin->mst_capable = false;
1774 else
1775 pin->mst_capable = true;
1776 }
1777
1778 for (i = 0; i < pin->num_ports; i++) {
1779 if (!pin->mst_capable && i > 0)
1780 continue;
1781
1782 hdac_hdmi_present_sense(pin, &pin->ports[i]);
1783 }
1784 }
1785}
1786
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301787static int hdmi_codec_probe(struct snd_soc_codec *codec)
1788{
1789 struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301790 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301791 struct snd_soc_dapm_context *dapm =
1792 snd_soc_component_get_dapm(&codec->component);
Vinod Koulb2047e92016-05-12 08:58:55 +05301793 struct hdac_ext_link *hlink = NULL;
Jeeja KPa9ce96b2017-02-07 19:09:46 +05301794 int ret;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301795
1796 edev->scodec = codec;
1797
Vinod Koulb2047e92016-05-12 08:58:55 +05301798 /*
1799 * hold the ref while we probe, also no need to drop the ref on
1800 * exit, we call pm_runtime_suspend() so that will do for us
1801 */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301802 hlink = snd_hdac_ext_bus_get_link(edev->ebus, dev_name(&edev->hdev.dev));
Vinod Koul500e06b2016-05-31 19:09:55 +05301803 if (!hlink) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301804 dev_err(&edev->hdev.dev, "hdac link not found\n");
Vinod Koul500e06b2016-05-31 19:09:55 +05301805 return -EIO;
1806 }
1807
Vinod Koulb2047e92016-05-12 08:58:55 +05301808 snd_hdac_ext_bus_link_get(edev->ebus, hlink);
1809
Subhransu S. Prusty79f4e922016-02-12 07:46:05 +05301810 ret = create_fill_widget_route_map(dapm);
1811 if (ret < 0)
1812 return ret;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301813
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301814 aops.audio_ptr = edev;
1815 ret = snd_hdac_i915_register_notifier(&aops);
1816 if (ret < 0) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301817 dev_err(&edev->hdev.dev, "notifier register failed: err: %d\n",
Subhransu S. Prustyb8a54542016-02-12 07:46:01 +05301818 ret);
1819 return ret;
1820 }
1821
Jeeja KPa9ce96b2017-02-07 19:09:46 +05301822 hdac_hdmi_present_sense_all_pins(edev, hdmi, true);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301823 /* Imp: Store the card pointer in hda_codec */
1824 edev->card = dapm->card->snd_card;
1825
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05301826 /*
1827 * hdac_device core already sets the state to active and calls
1828 * get_noresume. So enable runtime and set the device to suspend.
1829 */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301830 pm_runtime_enable(&edev->hdev.dev);
1831 pm_runtime_put(&edev->hdev.dev);
1832 pm_runtime_suspend(&edev->hdev.dev);
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05301833
1834 return 0;
1835}
1836
1837static int hdmi_codec_remove(struct snd_soc_codec *codec)
1838{
1839 struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec);
1840
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301841 pm_runtime_disable(&edev->hdev.dev);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301842 return 0;
1843}
1844
Jeeja KP571d5072016-02-22 07:50:33 +05301845#ifdef CONFIG_PM
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05301846static int hdmi_codec_prepare(struct device *dev)
1847{
1848 struct hdac_ext_device *edev = to_hda_ext_device(dev);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301849 struct hdac_device *hdev = &edev->hdev;
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05301850
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301851 pm_runtime_get_sync(&edev->hdev.dev);
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05301852
1853 /*
1854 * Power down afg.
1855 * codec_read is preferred over codec_write to set the power state.
1856 * This way verb is send to set the power state and response
1857 * is received. So setting power state is ensured without using loop
1858 * to read the state.
1859 */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301860 snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05301861 AC_PWRST_D3);
1862
1863 return 0;
1864}
1865
Subhransu S. Prusty0fee1792016-04-01 13:36:25 +05301866static void hdmi_codec_complete(struct device *dev)
Jeeja KP571d5072016-02-22 07:50:33 +05301867{
Subhransu S. Prusty0fee1792016-04-01 13:36:25 +05301868 struct hdac_ext_device *edev = to_hda_ext_device(dev);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301869 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
1870 struct hdac_device *hdev = &edev->hdev;
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05301871
1872 /* Power up afg */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301873 snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05301874 AC_PWRST_D0);
Jeeja KP571d5072016-02-22 07:50:33 +05301875
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301876 hdac_hdmi_skl_enable_all_pins(&edev->hdev);
1877 hdac_hdmi_skl_enable_dp12(&edev->hdev);
Jeeja KP571d5072016-02-22 07:50:33 +05301878
Jeeja KP571d5072016-02-22 07:50:33 +05301879 /*
1880 * As the ELD notify callback request is not entertained while the
1881 * device is in suspend state. Need to manually check detection of
Jeeja KPa9ce96b2017-02-07 19:09:46 +05301882 * all pins here. pin capablity change is not support, so use the
1883 * already set pin caps.
Jeeja KP571d5072016-02-22 07:50:33 +05301884 */
Jeeja KPa9ce96b2017-02-07 19:09:46 +05301885 hdac_hdmi_present_sense_all_pins(edev, hdmi, false);
Jeeja KP571d5072016-02-22 07:50:33 +05301886
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301887 pm_runtime_put_sync(&edev->hdev.dev);
Jeeja KP571d5072016-02-22 07:50:33 +05301888}
1889#else
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05301890#define hdmi_codec_prepare NULL
Subhransu S. Prusty0fee1792016-04-01 13:36:25 +05301891#define hdmi_codec_complete NULL
Jeeja KP571d5072016-02-22 07:50:33 +05301892#endif
1893
Bhumika Goyala180ba42017-08-03 21:30:19 +05301894static const struct snd_soc_codec_driver hdmi_hda_codec = {
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301895 .probe = hdmi_codec_probe,
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05301896 .remove = hdmi_codec_remove,
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301897 .idle_bias_off = true,
1898};
1899
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301900static void hdac_hdmi_get_chmap(struct hdac_device *hdev, int pcm_idx,
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301901 unsigned char *chmap)
1902{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301903 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301904 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301905
Jeeja KPab1eea12017-01-24 21:49:05 +05301906 memcpy(chmap, pcm->chmap, ARRAY_SIZE(pcm->chmap));
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301907}
1908
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301909static void hdac_hdmi_set_chmap(struct hdac_device *hdev, int pcm_idx,
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301910 unsigned char *chmap, int prepared)
1911{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301912 struct hdac_ext_device *edev = to_ehdac_device(hdev);
1913 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301914 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301915 struct hdac_hdmi_port *port;
1916
Subhransu S. Prustyeb50fa12017-11-07 16:16:25 +05301917 if (!pcm)
1918 return;
1919
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301920 if (list_empty(&pcm->port_list))
1921 return;
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301922
Jeeja KPab1eea12017-01-24 21:49:05 +05301923 mutex_lock(&pcm->lock);
1924 pcm->chmap_set = true;
1925 memcpy(pcm->chmap, chmap, ARRAY_SIZE(pcm->chmap));
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301926 list_for_each_entry(port, &pcm->port_list, head)
1927 if (prepared)
1928 hdac_hdmi_setup_audio_infoframe(edev, pcm, port);
Jeeja KPab1eea12017-01-24 21:49:05 +05301929 mutex_unlock(&pcm->lock);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301930}
1931
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301932static bool is_hdac_hdmi_pcm_attached(struct hdac_device *hdev, int pcm_idx)
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301933{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301934 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301935 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301936
Subhransu S. Prustyeb50fa12017-11-07 16:16:25 +05301937 if (!pcm)
1938 return false;
1939
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301940 if (list_empty(&pcm->port_list))
1941 return false;
1942
1943 return true;
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301944}
1945
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301946static int hdac_hdmi_get_spk_alloc(struct hdac_device *hdev, int pcm_idx)
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301947{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301948 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301949 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301950 struct hdac_hdmi_port *port;
1951
Subhransu S. Prustyeb50fa12017-11-07 16:16:25 +05301952 if (!pcm)
1953 return 0;
1954
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05301955 if (list_empty(&pcm->port_list))
1956 return 0;
1957
1958 port = list_first_entry(&pcm->port_list, struct hdac_hdmi_port, head);
1959
1960 if (!port)
1961 return 0;
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301962
Jeeja KP754695f2017-02-06 12:09:14 +05301963 if (!port || !port->eld.eld_valid)
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301964 return 0;
1965
Jeeja KP754695f2017-02-06 12:09:14 +05301966 return port->eld.info.spk_alloc;
Subhransu S. Prusty28890992016-04-14 10:07:34 +05301967}
1968
Pradeep Tewani5622bc92017-07-20 11:40:56 +05301969static struct hdac_hdmi_drv_data intel_glk_drv_data = {
1970 .vendor_nid = INTEL_GLK_VENDOR_NID,
1971};
1972
1973static struct hdac_hdmi_drv_data intel_drv_data = {
1974 .vendor_nid = INTEL_VENDOR_NID,
1975};
1976
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301977static int hdac_hdmi_dev_probe(struct hdac_ext_device *edev)
1978{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301979 struct hdac_device *hdev = &edev->hdev;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301980 struct hdac_hdmi_priv *hdmi_priv;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301981 struct snd_soc_dai_driver *hdmi_dais = NULL;
Vinod Koulb2047e92016-05-12 08:58:55 +05301982 struct hdac_ext_link *hlink = NULL;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05301983 int num_dais = 0;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301984 int ret = 0;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301985 struct hdac_driver *hdrv = drv_to_hdac_driver(hdev->dev.driver);
1986 const struct hda_device_id *hdac_id = hdac_get_device_id(hdev, hdrv);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301987
Vinod Koulb2047e92016-05-12 08:58:55 +05301988 /* hold the ref while we probe */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301989 hlink = snd_hdac_ext_bus_get_link(edev->ebus, dev_name(&edev->hdev.dev));
Vinod Koul500e06b2016-05-31 19:09:55 +05301990 if (!hlink) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301991 dev_err(&edev->hdev.dev, "hdac link not found\n");
Vinod Koul500e06b2016-05-31 19:09:55 +05301992 return -EIO;
1993 }
1994
Vinod Koulb2047e92016-05-12 08:58:55 +05301995 snd_hdac_ext_bus_link_get(edev->ebus, hlink);
1996
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05301997 hdmi_priv = devm_kzalloc(&hdev->dev, sizeof(*hdmi_priv), GFP_KERNEL);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05301998 if (hdmi_priv == NULL)
1999 return -ENOMEM;
2000
2001 edev->private_data = hdmi_priv;
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302002 snd_hdac_register_chmap_ops(hdev, &hdmi_priv->chmap);
Subhransu S. Prusty28890992016-04-14 10:07:34 +05302003 hdmi_priv->chmap.ops.get_chmap = hdac_hdmi_get_chmap;
2004 hdmi_priv->chmap.ops.set_chmap = hdac_hdmi_set_chmap;
2005 hdmi_priv->chmap.ops.is_pcm_attached = is_hdac_hdmi_pcm_attached;
2006 hdmi_priv->chmap.ops.get_spk_alloc = hdac_hdmi_get_spk_alloc;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302007
Subhransu S. Prustyeb50fa12017-11-07 16:16:25 +05302008 if (!hdac_id)
2009 return -ENODEV;
2010
Pradeep Tewani5622bc92017-07-20 11:40:56 +05302011 if (hdac_id->driver_data)
2012 hdmi_priv->drv_data =
2013 (struct hdac_hdmi_drv_data *)hdac_id->driver_data;
2014 else
2015 hdmi_priv->drv_data = &intel_drv_data;
2016
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302017 dev_set_drvdata(&hdev->dev, edev);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302018
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302019 INIT_LIST_HEAD(&hdmi_priv->pin_list);
2020 INIT_LIST_HEAD(&hdmi_priv->cvt_list);
Jeeja KP4a3478d2016-02-12 07:46:06 +05302021 INIT_LIST_HEAD(&hdmi_priv->pcm_list);
2022 mutex_init(&hdmi_priv->pin_mutex);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302023
Ramesh Babuaeaccef2016-02-17 21:34:01 +05302024 /*
2025 * Turned off in the runtime_suspend during the first explicit
2026 * pm_runtime_suspend call.
2027 */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302028 ret = snd_hdac_display_power(edev->hdev.bus, true);
Ramesh Babuaeaccef2016-02-17 21:34:01 +05302029 if (ret < 0) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302030 dev_err(&edev->hdev.dev,
Ramesh Babuaeaccef2016-02-17 21:34:01 +05302031 "Cannot turn on display power on i915 err: %d\n",
2032 ret);
2033 return ret;
2034 }
2035
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05302036 ret = hdac_hdmi_parse_and_map_nid(edev, &hdmi_dais, &num_dais);
2037 if (ret < 0) {
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302038 dev_err(&hdev->dev,
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05302039 "Failed in parse and map nid with err: %d\n", ret);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302040 return ret;
Subhransu S. Prusty17a42c42016-02-12 07:46:04 +05302041 }
Puneeth Prabhu0fb02ba2017-12-06 16:34:05 +05302042 snd_hdac_refresh_widgets(hdev, true);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302043
2044 /* ASoC specific initialization */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302045 ret = snd_soc_register_codec(&hdev->dev, &hdmi_hda_codec,
Vinod Koulb2047e92016-05-12 08:58:55 +05302046 hdmi_dais, num_dais);
2047
2048 snd_hdac_ext_bus_link_put(edev->ebus, hlink);
2049
2050 return ret;
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302051}
2052
2053static int hdac_hdmi_dev_remove(struct hdac_ext_device *edev)
2054{
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302055 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(&edev->hdev);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302056 struct hdac_hdmi_pin *pin, *pin_next;
2057 struct hdac_hdmi_cvt *cvt, *cvt_next;
Jeeja KP4a3478d2016-02-12 07:46:06 +05302058 struct hdac_hdmi_pcm *pcm, *pcm_next;
Jeeja KP2fe42dd2017-03-01 22:41:24 +05302059 struct hdac_hdmi_port *port, *port_next;
Jeeja KP754695f2017-02-06 12:09:14 +05302060 int i;
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302061
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302062 snd_soc_unregister_codec(&edev->hdev.dev);
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302063
Jeeja KP4a3478d2016-02-12 07:46:06 +05302064 list_for_each_entry_safe(pcm, pcm_next, &hdmi->pcm_list, head) {
2065 pcm->cvt = NULL;
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05302066 if (list_empty(&pcm->port_list))
2067 continue;
2068
Jeeja KP2fe42dd2017-03-01 22:41:24 +05302069 list_for_each_entry_safe(port, port_next,
2070 &pcm->port_list, head)
2071 list_del(&port->head);
Jeeja KPe0e5d3e2017-02-07 19:09:48 +05302072
Jeeja KP4a3478d2016-02-12 07:46:06 +05302073 list_del(&pcm->head);
2074 kfree(pcm);
2075 }
2076
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302077 list_for_each_entry_safe(cvt, cvt_next, &hdmi->cvt_list, head) {
2078 list_del(&cvt->head);
Jeeja KP4a3478d2016-02-12 07:46:06 +05302079 kfree(cvt->name);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302080 kfree(cvt);
2081 }
2082
2083 list_for_each_entry_safe(pin, pin_next, &hdmi->pin_list, head) {
Jeeja KP754695f2017-02-06 12:09:14 +05302084 for (i = 0; i < pin->num_ports; i++)
2085 pin->ports[i].pin = NULL;
2086 kfree(pin->ports);
Subhransu S. Prusty15b91442015-12-09 21:46:10 +05302087 list_del(&pin->head);
2088 kfree(pin);
2089 }
2090
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302091 return 0;
2092}
2093
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302094#ifdef CONFIG_PM
2095static int hdac_hdmi_runtime_suspend(struct device *dev)
2096{
2097 struct hdac_ext_device *edev = to_hda_ext_device(dev);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302098 struct hdac_device *hdev = &edev->hdev;
2099 struct hdac_bus *bus = hdev->bus;
Vinod Koulb2047e92016-05-12 08:58:55 +05302100 struct hdac_ext_bus *ebus = hbus_to_ebus(bus);
2101 struct hdac_ext_link *hlink = NULL;
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302102 int err;
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302103
2104 dev_dbg(dev, "Enter: %s\n", __func__);
2105
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302106 /* controller may not have been initialized for the first time */
2107 if (!bus)
2108 return 0;
2109
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05302110 /*
2111 * Power down afg.
2112 * codec_read is preferred over codec_write to set the power state.
2113 * This way verb is send to set the power state and response
2114 * is received. So setting power state is ensured without using loop
2115 * to read the state.
2116 */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302117 snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05302118 AC_PWRST_D3);
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302119 err = snd_hdac_display_power(bus, false);
2120 if (err < 0) {
2121 dev_err(bus->dev, "Cannot turn on display power on i915\n");
2122 return err;
2123 }
2124
Vinod Koulb2047e92016-05-12 08:58:55 +05302125 hlink = snd_hdac_ext_bus_get_link(ebus, dev_name(dev));
Vinod Koul500e06b2016-05-31 19:09:55 +05302126 if (!hlink) {
2127 dev_err(dev, "hdac link not found\n");
2128 return -EIO;
2129 }
2130
Vinod Koulb2047e92016-05-12 08:58:55 +05302131 snd_hdac_ext_bus_link_put(ebus, hlink);
2132
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302133 return 0;
2134}
2135
2136static int hdac_hdmi_runtime_resume(struct device *dev)
2137{
2138 struct hdac_ext_device *edev = to_hda_ext_device(dev);
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302139 struct hdac_device *hdev = &edev->hdev;
2140 struct hdac_bus *bus = hdev->bus;
Vinod Koulb2047e92016-05-12 08:58:55 +05302141 struct hdac_ext_bus *ebus = hbus_to_ebus(bus);
2142 struct hdac_ext_link *hlink = NULL;
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302143 int err;
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302144
2145 dev_dbg(dev, "Enter: %s\n", __func__);
2146
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302147 /* controller may not have been initialized for the first time */
2148 if (!bus)
2149 return 0;
2150
Vinod Koulb2047e92016-05-12 08:58:55 +05302151 hlink = snd_hdac_ext_bus_get_link(ebus, dev_name(dev));
Vinod Koul500e06b2016-05-31 19:09:55 +05302152 if (!hlink) {
2153 dev_err(dev, "hdac link not found\n");
2154 return -EIO;
2155 }
2156
Vinod Koulb2047e92016-05-12 08:58:55 +05302157 snd_hdac_ext_bus_link_get(ebus, hlink);
2158
Subhransu S. Prusty07f083a2015-11-10 18:42:10 +05302159 err = snd_hdac_display_power(bus, true);
2160 if (err < 0) {
2161 dev_err(bus->dev, "Cannot turn on display power on i915\n");
2162 return err;
2163 }
2164
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302165 hdac_hdmi_skl_enable_all_pins(&edev->hdev);
2166 hdac_hdmi_skl_enable_dp12(&edev->hdev);
Subhransu S. Prustyab85f5b2016-02-17 21:34:02 +05302167
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302168 /* Power up afg */
Ughreja, Rakesh Af0c5ebe2017-12-01 14:43:19 +05302169 snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05302170 AC_PWRST_D0);
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302171
2172 return 0;
2173}
2174#else
2175#define hdac_hdmi_runtime_suspend NULL
2176#define hdac_hdmi_runtime_resume NULL
2177#endif
2178
2179static const struct dev_pm_ops hdac_hdmi_pm = {
2180 SET_RUNTIME_PM_OPS(hdac_hdmi_runtime_suspend, hdac_hdmi_runtime_resume, NULL)
Subhransu S. Prusty1b377cc2016-04-01 13:36:26 +05302181 .prepare = hdmi_codec_prepare,
Subhransu S. Prusty0fee1792016-04-01 13:36:25 +05302182 .complete = hdmi_codec_complete,
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302183};
2184
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302185static const struct hda_device_id hdmi_list[] = {
2186 HDA_CODEC_EXT_ENTRY(0x80862809, 0x100000, "Skylake HDMI", 0),
Jeeja KPe2304802016-03-11 10:12:55 +05302187 HDA_CODEC_EXT_ENTRY(0x8086280a, 0x100000, "Broxton HDMI", 0),
Shreyas NCcc216882016-07-11 22:02:09 +05302188 HDA_CODEC_EXT_ENTRY(0x8086280b, 0x100000, "Kabylake HDMI", 0),
Pradeep Tewani5622bc92017-07-20 11:40:56 +05302189 HDA_CODEC_EXT_ENTRY(0x8086280d, 0x100000, "Geminilake HDMI",
2190 &intel_glk_drv_data),
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302191 {}
2192};
2193
2194MODULE_DEVICE_TABLE(hdaudio, hdmi_list);
2195
2196static struct hdac_ext_driver hdmi_driver = {
2197 . hdac = {
2198 .driver = {
2199 .name = "HDMI HDA Codec",
Subhransu S. Prustye342ac02015-11-10 18:42:07 +05302200 .pm = &hdac_hdmi_pm,
Subhransu S. Prusty18382ea2015-11-10 18:42:06 +05302201 },
2202 .id_table = hdmi_list,
2203 },
2204 .probe = hdac_hdmi_dev_probe,
2205 .remove = hdac_hdmi_dev_remove,
2206};
2207
2208static int __init hdmi_init(void)
2209{
2210 return snd_hda_ext_driver_register(&hdmi_driver);
2211}
2212
2213static void __exit hdmi_exit(void)
2214{
2215 snd_hda_ext_driver_unregister(&hdmi_driver);
2216}
2217
2218module_init(hdmi_init);
2219module_exit(hdmi_exit);
2220
2221MODULE_LICENSE("GPL v2");
2222MODULE_DESCRIPTION("HDMI HD codec");
2223MODULE_AUTHOR("Samreen Nilofer<samreen.nilofer@intel.com>");
2224MODULE_AUTHOR("Subhransu S. Prusty<subhransu.s.prusty@intel.com>");