Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1 | /* |
| 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. Prusty | a657f1d | 2015-11-10 18:42:09 +0530 | [diff] [blame] | 24 | #include <linux/hdmi.h> |
Subhransu S. Prusty | 2428bca | 2016-02-12 07:46:02 +0530 | [diff] [blame] | 25 | #include <drm/drm_edid.h> |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 26 | #include <sound/pcm_params.h> |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 27 | #include <sound/jack.h> |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 28 | #include <sound/soc.h> |
| 29 | #include <sound/hdaudio_ext.h> |
Subhransu S. Prusty | 07f083a | 2015-11-10 18:42:10 +0530 | [diff] [blame] | 30 | #include <sound/hda_i915.h> |
Subhransu S. Prusty | 2428bca | 2016-02-12 07:46:02 +0530 | [diff] [blame] | 31 | #include <sound/pcm_drm_eld.h> |
Subhransu S. Prusty | bcced70 | 2016-04-14 10:07:30 +0530 | [diff] [blame] | 32 | #include <sound/hda_chmap.h> |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 33 | #include "../../hda/local.h" |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 34 | #include "hdac_hdmi.h" |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 35 | |
Subhransu S. Prusty | 17a42c4 | 2016-02-12 07:46:04 +0530 | [diff] [blame] | 36 | #define NAME_SIZE 32 |
| 37 | |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 38 | #define AMP_OUT_MUTE 0xb080 |
| 39 | #define AMP_OUT_UNMUTE 0xb000 |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 40 | #define PIN_OUT (AC_PINCTL_OUT_EN) |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 41 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 42 | #define HDA_MAX_CONNECTIONS 32 |
| 43 | |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 44 | #define HDA_MAX_CVTS 3 |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 45 | #define HDA_MAX_PORTS 3 |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 46 | |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 47 | #define ELD_MAX_SIZE 256 |
| 48 | #define ELD_FIXED_BYTES 20 |
| 49 | |
Sandeep Tayal | f6fa11a | 2017-01-18 21:34:41 +0530 | [diff] [blame] | 50 | #define ELD_VER_CEA_861D 2 |
| 51 | #define ELD_VER_PARTIAL 31 |
| 52 | #define ELD_MAX_MNL 16 |
| 53 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 54 | struct 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 | |
| 62 | struct hdac_hdmi_cvt { |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 63 | struct list_head head; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 64 | hda_nid_t nid; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 65 | const char *name; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 66 | struct hdac_hdmi_cvt_params params; |
| 67 | }; |
| 68 | |
Subhransu S. Prusty | b7756ed | 2016-04-14 10:07:28 +0530 | [diff] [blame] | 69 | /* Currently only spk_alloc, more to be added */ |
| 70 | struct hdac_hdmi_parsed_eld { |
| 71 | u8 spk_alloc; |
| 72 | }; |
| 73 | |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 74 | struct hdac_hdmi_eld { |
| 75 | bool monitor_present; |
| 76 | bool eld_valid; |
| 77 | int eld_size; |
| 78 | char eld_buffer[ELD_MAX_SIZE]; |
Subhransu S. Prusty | b7756ed | 2016-04-14 10:07:28 +0530 | [diff] [blame] | 79 | struct hdac_hdmi_parsed_eld info; |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 80 | }; |
| 81 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 82 | struct hdac_hdmi_pin { |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 83 | struct list_head head; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 84 | hda_nid_t nid; |
Jeeja KP | 2acd830 | 2017-02-06 12:09:18 +0530 | [diff] [blame] | 85 | bool mst_capable; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 86 | struct hdac_hdmi_port *ports; |
| 87 | int num_ports; |
| 88 | struct hdac_ext_device *edev; |
| 89 | }; |
| 90 | |
| 91 | struct hdac_hdmi_port { |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 92 | struct list_head head; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 93 | int id; |
| 94 | struct hdac_hdmi_pin *pin; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 95 | int num_mux_nids; |
| 96 | hda_nid_t mux_nids[HDA_MAX_CONNECTIONS]; |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 97 | struct hdac_hdmi_eld eld; |
Jeeja KP | 0324e51 | 2017-02-07 19:09:55 +0530 | [diff] [blame] | 98 | const char *jack_pin; |
| 99 | struct snd_soc_dapm_context *dapm; |
| 100 | const char *output_pin; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 101 | }; |
| 102 | |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 103 | struct hdac_hdmi_pcm { |
| 104 | struct list_head head; |
| 105 | int pcm_id; |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 106 | struct list_head port_list; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 107 | struct hdac_hdmi_cvt *cvt; |
Jeeja KP | 6249001 | 2017-02-07 19:09:49 +0530 | [diff] [blame] | 108 | struct snd_soc_jack *jack; |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 109 | int stream_tag; |
| 110 | int channels; |
| 111 | int format; |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 112 | bool chmap_set; |
| 113 | unsigned char chmap[8]; /* ALSA API channel-map */ |
| 114 | struct mutex lock; |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 115 | int jack_event; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 116 | }; |
| 117 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 118 | struct hdac_hdmi_dai_port_map { |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 119 | int dai_id; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 120 | struct hdac_hdmi_port *port; |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 121 | struct hdac_hdmi_cvt *cvt; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | struct hdac_hdmi_priv { |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 125 | struct hdac_hdmi_dai_port_map dai_map[HDA_MAX_CVTS]; |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 126 | struct list_head pin_list; |
| 127 | struct list_head cvt_list; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 128 | struct list_head pcm_list; |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 129 | int num_pin; |
| 130 | int num_cvt; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 131 | int num_ports; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 132 | struct mutex pin_mutex; |
Subhransu S. Prusty | bcced70 | 2016-04-14 10:07:30 +0530 | [diff] [blame] | 133 | struct hdac_chmap chmap; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 134 | }; |
| 135 | |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 136 | static struct hdac_hdmi_pcm * |
| 137 | hdac_hdmi_get_pcm_from_cvt(struct hdac_hdmi_priv *hdmi, |
| 138 | struct hdac_hdmi_cvt *cvt) |
| 139 | { |
| 140 | struct hdac_hdmi_pcm *pcm = NULL; |
Jeeja KP | 1de777f | 2017-01-10 17:57:48 +0530 | [diff] [blame] | 141 | |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 142 | list_for_each_entry(pcm, &hdmi->pcm_list, head) { |
| 143 | if (pcm->cvt == cvt) |
| 144 | break; |
| 145 | } |
| 146 | |
| 147 | return pcm; |
| 148 | } |
Jeeja KP | 1de777f | 2017-01-10 17:57:48 +0530 | [diff] [blame] | 149 | |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 150 | static void hdac_hdmi_jack_report(struct hdac_hdmi_pcm *pcm, |
| 151 | struct hdac_hdmi_port *port, bool is_connect) |
| 152 | { |
| 153 | struct hdac_ext_device *edev = port->pin->edev; |
| 154 | |
Jeeja KP | 0324e51 | 2017-02-07 19:09:55 +0530 | [diff] [blame] | 155 | if (is_connect) |
| 156 | snd_soc_dapm_enable_pin(port->dapm, port->jack_pin); |
| 157 | else |
| 158 | snd_soc_dapm_disable_pin(port->dapm, port->jack_pin); |
| 159 | |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 160 | if (is_connect) { |
| 161 | /* |
| 162 | * Report Jack connect event when a device is connected |
| 163 | * for the first time where same PCM is attached to multiple |
| 164 | * ports. |
| 165 | */ |
| 166 | if (pcm->jack_event == 0) { |
| 167 | dev_dbg(&edev->hdac.dev, |
| 168 | "jack report for pcm=%d\n", |
| 169 | pcm->pcm_id); |
Jeeja KP | 6249001 | 2017-02-07 19:09:49 +0530 | [diff] [blame] | 170 | snd_soc_jack_report(pcm->jack, SND_JACK_AVOUT, |
| 171 | SND_JACK_AVOUT); |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 172 | } |
| 173 | pcm->jack_event++; |
| 174 | } else { |
| 175 | /* |
| 176 | * Report Jack disconnect event when a device is disconnected |
| 177 | * is the only last connected device when same PCM is attached |
| 178 | * to multiple ports. |
| 179 | */ |
| 180 | if (pcm->jack_event == 1) |
Jeeja KP | 6249001 | 2017-02-07 19:09:49 +0530 | [diff] [blame] | 181 | snd_soc_jack_report(pcm->jack, 0, SND_JACK_AVOUT); |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 182 | if (pcm->jack_event > 0) |
| 183 | pcm->jack_event--; |
| 184 | } |
Jeeja KP | 0324e51 | 2017-02-07 19:09:55 +0530 | [diff] [blame] | 185 | |
| 186 | snd_soc_dapm_sync(port->dapm); |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 187 | } |
| 188 | |
Jeeja KP | fc181b0 | 2017-02-07 19:09:45 +0530 | [diff] [blame] | 189 | /* MST supported verbs */ |
| 190 | /* |
| 191 | * Get the no devices that can be connected to a port on the Pin widget. |
| 192 | */ |
| 193 | static int hdac_hdmi_get_port_len(struct hdac_ext_device *hdac, hda_nid_t nid) |
| 194 | { |
| 195 | unsigned int caps; |
| 196 | unsigned int type, param; |
| 197 | |
| 198 | caps = get_wcaps(&hdac->hdac, nid); |
| 199 | type = get_wcaps_type(caps); |
| 200 | |
| 201 | if (!(caps & AC_WCAP_DIGITAL) || (type != AC_WID_PIN)) |
| 202 | return 0; |
| 203 | |
| 204 | param = snd_hdac_read_parm_uncached(&hdac->hdac, nid, |
| 205 | AC_PAR_DEVLIST_LEN); |
| 206 | if (param == -1) |
| 207 | return param; |
| 208 | |
| 209 | return param & AC_DEV_LIST_LEN_MASK; |
| 210 | } |
| 211 | |
| 212 | /* |
| 213 | * Get the port entry select on the pin. Return the port entry |
| 214 | * id selected on the pin. Return 0 means the first port entry |
| 215 | * is selected or MST is not supported. |
| 216 | */ |
| 217 | static int hdac_hdmi_port_select_get(struct hdac_ext_device *hdac, |
| 218 | struct hdac_hdmi_port *port) |
| 219 | { |
| 220 | return snd_hdac_codec_read(&hdac->hdac, port->pin->nid, |
| 221 | 0, AC_VERB_GET_DEVICE_SEL, 0); |
| 222 | } |
| 223 | |
| 224 | /* |
| 225 | * Sets the selected port entry for the configuring Pin widget verb. |
| 226 | * returns error if port set is not equal to port get otherwise success |
| 227 | */ |
| 228 | static int hdac_hdmi_port_select_set(struct hdac_ext_device *hdac, |
| 229 | struct hdac_hdmi_port *port) |
| 230 | { |
| 231 | int num_ports; |
| 232 | |
| 233 | if (!port->pin->mst_capable) |
| 234 | return 0; |
| 235 | |
| 236 | /* AC_PAR_DEVLIST_LEN is 0 based. */ |
| 237 | num_ports = hdac_hdmi_get_port_len(hdac, port->pin->nid); |
| 238 | |
| 239 | if (num_ports < 0) |
| 240 | return -EIO; |
| 241 | /* |
| 242 | * Device List Length is a 0 based integer value indicating the |
| 243 | * number of sink device that a MST Pin Widget can support. |
| 244 | */ |
| 245 | if (num_ports + 1 < port->id) |
| 246 | return 0; |
| 247 | |
| 248 | snd_hdac_codec_write(&hdac->hdac, port->pin->nid, 0, |
| 249 | AC_VERB_SET_DEVICE_SEL, port->id); |
| 250 | |
| 251 | if (port->id != hdac_hdmi_port_select_get(hdac, port)) |
| 252 | return -EIO; |
| 253 | |
| 254 | dev_dbg(&hdac->hdac.dev, "Selected the port=%d\n", port->id); |
| 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | |
Subhransu S. Prusty | 2889099 | 2016-04-14 10:07:34 +0530 | [diff] [blame] | 259 | static struct hdac_hdmi_pcm *get_hdmi_pcm_from_id(struct hdac_hdmi_priv *hdmi, |
| 260 | int pcm_idx) |
| 261 | { |
| 262 | struct hdac_hdmi_pcm *pcm; |
| 263 | |
| 264 | list_for_each_entry(pcm, &hdmi->pcm_list, head) { |
| 265 | if (pcm->pcm_id == pcm_idx) |
| 266 | return pcm; |
| 267 | } |
| 268 | |
| 269 | return NULL; |
| 270 | } |
| 271 | |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 272 | static inline struct hdac_ext_device *to_hda_ext_device(struct device *dev) |
| 273 | { |
Geliang Tang | 51b2c42 | 2015-12-28 22:47:13 +0800 | [diff] [blame] | 274 | struct hdac_device *hdac = dev_to_hdac_dev(dev); |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 275 | |
Geliang Tang | 51b2c42 | 2015-12-28 22:47:13 +0800 | [diff] [blame] | 276 | return to_ehdac_device(hdac); |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 277 | } |
| 278 | |
Subhransu S. Prusty | 2428bca | 2016-02-12 07:46:02 +0530 | [diff] [blame] | 279 | static unsigned int sad_format(const u8 *sad) |
| 280 | { |
| 281 | return ((sad[0] >> 0x3) & 0x1f); |
| 282 | } |
| 283 | |
| 284 | static unsigned int sad_sample_bits_lpcm(const u8 *sad) |
| 285 | { |
| 286 | return (sad[2] & 7); |
| 287 | } |
| 288 | |
| 289 | static int hdac_hdmi_eld_limit_formats(struct snd_pcm_runtime *runtime, |
| 290 | void *eld) |
| 291 | { |
| 292 | u64 formats = SNDRV_PCM_FMTBIT_S16; |
| 293 | int i; |
| 294 | const u8 *sad, *eld_buf = eld; |
| 295 | |
| 296 | sad = drm_eld_sad(eld_buf); |
| 297 | if (!sad) |
| 298 | goto format_constraint; |
| 299 | |
| 300 | for (i = drm_eld_sad_count(eld_buf); i > 0; i--, sad += 3) { |
| 301 | if (sad_format(sad) == 1) { /* AUDIO_CODING_TYPE_LPCM */ |
| 302 | |
| 303 | /* |
| 304 | * the controller support 20 and 24 bits in 32 bit |
| 305 | * container so we set S32 |
| 306 | */ |
| 307 | if (sad_sample_bits_lpcm(sad) & 0x6) |
| 308 | formats |= SNDRV_PCM_FMTBIT_S32; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | format_constraint: |
| 313 | return snd_pcm_hw_constraint_mask64(runtime, SNDRV_PCM_HW_PARAM_FORMAT, |
| 314 | formats); |
| 315 | |
| 316 | } |
| 317 | |
Subhransu S. Prusty | a657f1d | 2015-11-10 18:42:09 +0530 | [diff] [blame] | 318 | static void |
| 319 | hdac_hdmi_set_dip_index(struct hdac_ext_device *hdac, hda_nid_t pin_nid, |
| 320 | int packet_index, int byte_index) |
| 321 | { |
| 322 | int val; |
| 323 | |
| 324 | val = (packet_index << 5) | (byte_index & 0x1f); |
| 325 | |
| 326 | snd_hdac_codec_write(&hdac->hdac, pin_nid, 0, |
| 327 | AC_VERB_SET_HDMI_DIP_INDEX, val); |
| 328 | } |
| 329 | |
Subhransu S. Prusty | 478f544e | 2016-02-12 07:46:09 +0530 | [diff] [blame] | 330 | struct dp_audio_infoframe { |
| 331 | u8 type; /* 0x84 */ |
| 332 | u8 len; /* 0x1b */ |
| 333 | u8 ver; /* 0x11 << 2 */ |
| 334 | |
| 335 | u8 CC02_CT47; /* match with HDMI infoframe from this on */ |
| 336 | u8 SS01_SF24; |
| 337 | u8 CXT04; |
| 338 | u8 CA; |
| 339 | u8 LFEPBL01_LSV36_DM_INH7; |
| 340 | }; |
| 341 | |
Subhransu S. Prusty | a657f1d | 2015-11-10 18:42:09 +0530 | [diff] [blame] | 342 | static int hdac_hdmi_setup_audio_infoframe(struct hdac_ext_device *hdac, |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 343 | struct hdac_hdmi_pcm *pcm, struct hdac_hdmi_port *port) |
Subhransu S. Prusty | a657f1d | 2015-11-10 18:42:09 +0530 | [diff] [blame] | 344 | { |
| 345 | uint8_t buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AUDIO_INFOFRAME_SIZE]; |
| 346 | struct hdmi_audio_infoframe frame; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 347 | struct hdac_hdmi_pin *pin = port->pin; |
Subhransu S. Prusty | 478f544e | 2016-02-12 07:46:09 +0530 | [diff] [blame] | 348 | struct dp_audio_infoframe dp_ai; |
| 349 | struct hdac_hdmi_priv *hdmi = hdac->private_data; |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 350 | struct hdac_hdmi_cvt *cvt = pcm->cvt; |
Subhransu S. Prusty | 478f544e | 2016-02-12 07:46:09 +0530 | [diff] [blame] | 351 | u8 *dip; |
Subhransu S. Prusty | a657f1d | 2015-11-10 18:42:09 +0530 | [diff] [blame] | 352 | int ret; |
| 353 | int i; |
Subhransu S. Prusty | 478f544e | 2016-02-12 07:46:09 +0530 | [diff] [blame] | 354 | const u8 *eld_buf; |
| 355 | u8 conn_type; |
Subhransu S. Prusty | bcced70 | 2016-04-14 10:07:30 +0530 | [diff] [blame] | 356 | int channels, ca; |
Subhransu S. Prusty | a657f1d | 2015-11-10 18:42:09 +0530 | [diff] [blame] | 357 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 358 | ca = snd_hdac_channel_allocation(&hdac->hdac, port->eld.info.spk_alloc, |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 359 | pcm->channels, pcm->chmap_set, true, pcm->chmap); |
Subhransu S. Prusty | bcced70 | 2016-04-14 10:07:30 +0530 | [diff] [blame] | 360 | |
| 361 | channels = snd_hdac_get_active_channels(ca); |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 362 | hdmi->chmap.ops.set_channel_count(&hdac->hdac, cvt->nid, channels); |
Subhransu S. Prusty | bcced70 | 2016-04-14 10:07:30 +0530 | [diff] [blame] | 363 | |
| 364 | snd_hdac_setup_channel_mapping(&hdmi->chmap, pin->nid, false, ca, |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 365 | pcm->channels, pcm->chmap, pcm->chmap_set); |
Subhransu S. Prusty | bcced70 | 2016-04-14 10:07:30 +0530 | [diff] [blame] | 366 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 367 | eld_buf = port->eld.eld_buffer; |
Subhransu S. Prusty | 478f544e | 2016-02-12 07:46:09 +0530 | [diff] [blame] | 368 | conn_type = drm_eld_get_conn_type(eld_buf); |
Subhransu S. Prusty | a657f1d | 2015-11-10 18:42:09 +0530 | [diff] [blame] | 369 | |
Subhransu S. Prusty | 478f544e | 2016-02-12 07:46:09 +0530 | [diff] [blame] | 370 | switch (conn_type) { |
| 371 | case DRM_ELD_CONN_TYPE_HDMI: |
| 372 | hdmi_audio_infoframe_init(&frame); |
| 373 | |
Subhransu S. Prusty | 478f544e | 2016-02-12 07:46:09 +0530 | [diff] [blame] | 374 | frame.channels = channels; |
Subhransu S. Prusty | bcced70 | 2016-04-14 10:07:30 +0530 | [diff] [blame] | 375 | frame.channel_allocation = ca; |
Subhransu S. Prusty | 478f544e | 2016-02-12 07:46:09 +0530 | [diff] [blame] | 376 | |
| 377 | ret = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer)); |
| 378 | if (ret < 0) |
| 379 | return ret; |
| 380 | |
Subhransu S. Prusty | 478f544e | 2016-02-12 07:46:09 +0530 | [diff] [blame] | 381 | break; |
| 382 | |
| 383 | case DRM_ELD_CONN_TYPE_DP: |
| 384 | memset(&dp_ai, 0, sizeof(dp_ai)); |
| 385 | dp_ai.type = 0x84; |
| 386 | dp_ai.len = 0x1b; |
| 387 | dp_ai.ver = 0x11 << 2; |
| 388 | dp_ai.CC02_CT47 = channels - 1; |
Subhransu S. Prusty | bcced70 | 2016-04-14 10:07:30 +0530 | [diff] [blame] | 389 | dp_ai.CA = ca; |
Subhransu S. Prusty | 478f544e | 2016-02-12 07:46:09 +0530 | [diff] [blame] | 390 | |
| 391 | dip = (u8 *)&dp_ai; |
| 392 | break; |
| 393 | |
| 394 | default: |
| 395 | dev_err(&hdac->hdac.dev, "Invalid connection type: %d\n", |
| 396 | conn_type); |
| 397 | return -EIO; |
| 398 | } |
Subhransu S. Prusty | a657f1d | 2015-11-10 18:42:09 +0530 | [diff] [blame] | 399 | |
| 400 | /* stop infoframe transmission */ |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 401 | hdac_hdmi_set_dip_index(hdac, pin->nid, 0x0, 0x0); |
| 402 | snd_hdac_codec_write(&hdac->hdac, pin->nid, 0, |
Subhransu S. Prusty | a657f1d | 2015-11-10 18:42:09 +0530 | [diff] [blame] | 403 | AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_DISABLE); |
| 404 | |
| 405 | |
| 406 | /* Fill infoframe. Index auto-incremented */ |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 407 | hdac_hdmi_set_dip_index(hdac, pin->nid, 0x0, 0x0); |
Subhransu S. Prusty | 478f544e | 2016-02-12 07:46:09 +0530 | [diff] [blame] | 408 | if (conn_type == DRM_ELD_CONN_TYPE_HDMI) { |
Subhransu S. Prusty | 391005e | 2016-03-10 09:04:07 +0530 | [diff] [blame] | 409 | for (i = 0; i < sizeof(buffer); i++) |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 410 | snd_hdac_codec_write(&hdac->hdac, pin->nid, 0, |
Subhransu S. Prusty | 391005e | 2016-03-10 09:04:07 +0530 | [diff] [blame] | 411 | AC_VERB_SET_HDMI_DIP_DATA, buffer[i]); |
Subhransu S. Prusty | 478f544e | 2016-02-12 07:46:09 +0530 | [diff] [blame] | 412 | } else { |
| 413 | for (i = 0; i < sizeof(dp_ai); i++) |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 414 | snd_hdac_codec_write(&hdac->hdac, pin->nid, 0, |
Subhransu S. Prusty | 478f544e | 2016-02-12 07:46:09 +0530 | [diff] [blame] | 415 | AC_VERB_SET_HDMI_DIP_DATA, dip[i]); |
| 416 | } |
Subhransu S. Prusty | a657f1d | 2015-11-10 18:42:09 +0530 | [diff] [blame] | 417 | |
| 418 | /* Start infoframe */ |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 419 | hdac_hdmi_set_dip_index(hdac, pin->nid, 0x0, 0x0); |
| 420 | snd_hdac_codec_write(&hdac->hdac, pin->nid, 0, |
Subhransu S. Prusty | a657f1d | 2015-11-10 18:42:09 +0530 | [diff] [blame] | 421 | AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_BEST); |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 426 | static int hdac_hdmi_set_tdm_slot(struct snd_soc_dai *dai, |
| 427 | unsigned int tx_mask, unsigned int rx_mask, |
| 428 | int slots, int slot_width) |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 429 | { |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 430 | struct hdac_ext_device *edev = snd_soc_dai_get_drvdata(dai); |
| 431 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 432 | struct hdac_hdmi_dai_port_map *dai_map; |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 433 | struct hdac_hdmi_pcm *pcm; |
| 434 | |
| 435 | dev_dbg(&edev->hdac.dev, "%s: strm_tag: %d\n", __func__, tx_mask); |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 436 | |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 437 | dai_map = &hdmi->dai_map[dai->id]; |
| 438 | |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 439 | pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt); |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 440 | |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 441 | if (pcm) |
| 442 | pcm->stream_tag = (tx_mask << 4); |
Subhransu S. Prusty | bcced70 | 2016-04-14 10:07:30 +0530 | [diff] [blame] | 443 | |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 444 | return 0; |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream, |
| 448 | struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai) |
| 449 | { |
| 450 | struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai); |
Subhransu S. Prusty | 54dfa1e | 2016-02-17 21:34:00 +0530 | [diff] [blame] | 451 | struct hdac_hdmi_priv *hdmi = hdac->private_data; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 452 | struct hdac_hdmi_dai_port_map *dai_map; |
| 453 | struct hdac_hdmi_port *port; |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 454 | struct hdac_hdmi_pcm *pcm; |
| 455 | int format; |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 456 | |
Subhransu S. Prusty | 54dfa1e | 2016-02-17 21:34:00 +0530 | [diff] [blame] | 457 | dai_map = &hdmi->dai_map[dai->id]; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 458 | port = dai_map->port; |
Subhransu S. Prusty | 54dfa1e | 2016-02-17 21:34:00 +0530 | [diff] [blame] | 459 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 460 | if (!port) |
Subhransu S. Prusty | 54dfa1e | 2016-02-17 21:34:00 +0530 | [diff] [blame] | 461 | return -ENODEV; |
| 462 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 463 | if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) { |
| 464 | dev_err(&hdac->hdac.dev, |
| 465 | "device is not configured for this pin:port%d:%d\n", |
| 466 | port->pin->nid, port->id); |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 467 | return -ENODEV; |
| 468 | } |
| 469 | |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 470 | format = snd_hdac_calc_stream_format(params_rate(hparams), |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 471 | params_channels(hparams), params_format(hparams), |
Jeeja KP | 66d6bbc | 2017-03-24 23:10:26 +0530 | [diff] [blame] | 472 | dai->driver->playback.sig_bits, 0); |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 473 | |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 474 | pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt); |
| 475 | if (!pcm) |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 476 | return -EIO; |
| 477 | |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 478 | pcm->format = format; |
| 479 | pcm->channels = params_channels(hparams); |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 480 | |
| 481 | return 0; |
| 482 | } |
| 483 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 484 | static int hdac_hdmi_query_port_connlist(struct hdac_ext_device *hdac, |
| 485 | struct hdac_hdmi_pin *pin, |
| 486 | struct hdac_hdmi_port *port) |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 487 | { |
| 488 | if (!(get_wcaps(&hdac->hdac, pin->nid) & AC_WCAP_CONN_LIST)) { |
| 489 | dev_warn(&hdac->hdac.dev, |
| 490 | "HDMI: pin %d wcaps %#x does not support connection list\n", |
| 491 | pin->nid, get_wcaps(&hdac->hdac, pin->nid)); |
| 492 | return -EINVAL; |
| 493 | } |
| 494 | |
Jeeja KP | 1b46ebd | 2017-02-07 19:09:47 +0530 | [diff] [blame] | 495 | if (hdac_hdmi_port_select_set(hdac, port) < 0) |
| 496 | return -EIO; |
| 497 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 498 | port->num_mux_nids = snd_hdac_get_connections(&hdac->hdac, pin->nid, |
| 499 | port->mux_nids, HDA_MAX_CONNECTIONS); |
| 500 | if (port->num_mux_nids == 0) |
| 501 | dev_warn(&hdac->hdac.dev, |
| 502 | "No connections found for pin:port %d:%d\n", |
| 503 | pin->nid, port->id); |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 504 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 505 | dev_dbg(&hdac->hdac.dev, "num_mux_nids %d for pin:port %d:%d\n", |
| 506 | port->num_mux_nids, pin->nid, port->id); |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 507 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 508 | return port->num_mux_nids; |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | /* |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 512 | * Query pcm list and return port to which stream is routed. |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 513 | * |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 514 | * Also query connection list of the pin, to validate the cvt to port map. |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 515 | * |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 516 | * Same stream rendering to multiple ports simultaneously can be done |
| 517 | * possibly, but not supported for now in driver. So return the first port |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 518 | * connected. |
| 519 | */ |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 520 | static struct hdac_hdmi_port *hdac_hdmi_get_port_from_cvt( |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 521 | struct hdac_ext_device *edev, |
| 522 | struct hdac_hdmi_priv *hdmi, |
| 523 | struct hdac_hdmi_cvt *cvt) |
| 524 | { |
| 525 | struct hdac_hdmi_pcm *pcm; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 526 | struct hdac_hdmi_port *port = NULL; |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 527 | int ret, i; |
| 528 | |
| 529 | list_for_each_entry(pcm, &hdmi->pcm_list, head) { |
| 530 | if (pcm->cvt == cvt) { |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 531 | if (list_empty(&pcm->port_list)) |
| 532 | continue; |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 533 | |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 534 | list_for_each_entry(port, &pcm->port_list, head) { |
| 535 | mutex_lock(&pcm->lock); |
| 536 | ret = hdac_hdmi_query_port_connlist(edev, |
| 537 | port->pin, port); |
| 538 | mutex_unlock(&pcm->lock); |
| 539 | if (ret < 0) |
| 540 | continue; |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 541 | |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 542 | for (i = 0; i < port->num_mux_nids; i++) { |
| 543 | if (port->mux_nids[i] == cvt->nid && |
| 544 | port->eld.monitor_present && |
| 545 | port->eld.eld_valid) |
| 546 | return port; |
| 547 | } |
| 548 | } |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | |
| 552 | return NULL; |
| 553 | } |
| 554 | |
Subhransu S. Prusty | 54dfa1e | 2016-02-17 21:34:00 +0530 | [diff] [blame] | 555 | /* |
| 556 | * This tries to get a valid pin and set the HW constraints based on the |
| 557 | * ELD. Even if a valid pin is not found return success so that device open |
| 558 | * doesn't fail. |
| 559 | */ |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 560 | static int hdac_hdmi_pcm_open(struct snd_pcm_substream *substream, |
| 561 | struct snd_soc_dai *dai) |
| 562 | { |
| 563 | struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai); |
| 564 | struct hdac_hdmi_priv *hdmi = hdac->private_data; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 565 | struct hdac_hdmi_dai_port_map *dai_map; |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 566 | struct hdac_hdmi_cvt *cvt; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 567 | struct hdac_hdmi_port *port; |
Subhransu S. Prusty | 2428bca | 2016-02-12 07:46:02 +0530 | [diff] [blame] | 568 | int ret; |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 569 | |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 570 | dai_map = &hdmi->dai_map[dai->id]; |
| 571 | |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 572 | cvt = dai_map->cvt; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 573 | port = hdac_hdmi_get_port_from_cvt(hdac, hdmi, cvt); |
Subhransu S. Prusty | 54dfa1e | 2016-02-17 21:34:00 +0530 | [diff] [blame] | 574 | |
| 575 | /* |
| 576 | * To make PA and other userland happy. |
| 577 | * userland scans devices so returning error does not help. |
| 578 | */ |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 579 | if (!port) |
Subhransu S. Prusty | 54dfa1e | 2016-02-17 21:34:00 +0530 | [diff] [blame] | 580 | return 0; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 581 | if ((!port->eld.monitor_present) || |
| 582 | (!port->eld.eld_valid)) { |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 583 | |
Subhransu S. Prusty | 54dfa1e | 2016-02-17 21:34:00 +0530 | [diff] [blame] | 584 | dev_warn(&hdac->hdac.dev, |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 585 | "Failed: present?:%d ELD valid?:%d pin:port: %d:%d\n", |
| 586 | port->eld.monitor_present, port->eld.eld_valid, |
| 587 | port->pin->nid, port->id); |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 588 | |
Subhransu S. Prusty | 54dfa1e | 2016-02-17 21:34:00 +0530 | [diff] [blame] | 589 | return 0; |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 590 | } |
| 591 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 592 | dai_map->port = port; |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 593 | |
Subhransu S. Prusty | 2428bca | 2016-02-12 07:46:02 +0530 | [diff] [blame] | 594 | ret = hdac_hdmi_eld_limit_formats(substream->runtime, |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 595 | port->eld.eld_buffer); |
Subhransu S. Prusty | 2428bca | 2016-02-12 07:46:02 +0530 | [diff] [blame] | 596 | if (ret < 0) |
| 597 | return ret; |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 598 | |
Subhransu S. Prusty | 2428bca | 2016-02-12 07:46:02 +0530 | [diff] [blame] | 599 | return snd_pcm_hw_constraint_eld(substream->runtime, |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 600 | port->eld.eld_buffer); |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream, |
| 604 | struct snd_soc_dai *dai) |
| 605 | { |
| 606 | struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai); |
| 607 | struct hdac_hdmi_priv *hdmi = hdac->private_data; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 608 | struct hdac_hdmi_dai_port_map *dai_map; |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 609 | struct hdac_hdmi_pcm *pcm; |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 610 | |
| 611 | dai_map = &hdmi->dai_map[dai->id]; |
| 612 | |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 613 | pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt); |
Subhransu S. Prusty | bcced70 | 2016-04-14 10:07:30 +0530 | [diff] [blame] | 614 | |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 615 | if (pcm) { |
| 616 | mutex_lock(&pcm->lock); |
| 617 | pcm->chmap_set = false; |
| 618 | memset(pcm->chmap, 0, sizeof(pcm->chmap)); |
| 619 | pcm->channels = 0; |
| 620 | mutex_unlock(&pcm->lock); |
Subhransu S. Prusty | 54dfa1e | 2016-02-17 21:34:00 +0530 | [diff] [blame] | 621 | } |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 622 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 623 | if (dai_map->port) |
| 624 | dai_map->port = NULL; |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 625 | } |
| 626 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 627 | static int |
| 628 | hdac_hdmi_query_cvt_params(struct hdac_device *hdac, struct hdac_hdmi_cvt *cvt) |
| 629 | { |
Subhransu S. Prusty | bcced70 | 2016-04-14 10:07:30 +0530 | [diff] [blame] | 630 | unsigned int chans; |
| 631 | struct hdac_ext_device *edev = to_ehdac_device(hdac); |
| 632 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 633 | int err; |
| 634 | |
Subhransu S. Prusty | bcced70 | 2016-04-14 10:07:30 +0530 | [diff] [blame] | 635 | chans = get_wcaps(hdac, cvt->nid); |
| 636 | chans = get_wcaps_channels(chans); |
| 637 | |
| 638 | cvt->params.channels_min = 2; |
| 639 | |
| 640 | cvt->params.channels_max = chans; |
| 641 | if (chans > hdmi->chmap.channels_max) |
| 642 | hdmi->chmap.channels_max = chans; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 643 | |
| 644 | err = snd_hdac_query_supported_pcm(hdac, cvt->nid, |
| 645 | &cvt->params.rates, |
| 646 | &cvt->params.formats, |
| 647 | &cvt->params.maxbps); |
| 648 | if (err < 0) |
| 649 | dev_err(&hdac->dev, |
| 650 | "Failed to query pcm params for nid %d: %d\n", |
| 651 | cvt->nid, err); |
| 652 | |
| 653 | return err; |
| 654 | } |
| 655 | |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 656 | static int hdac_hdmi_fill_widget_info(struct device *dev, |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 657 | struct snd_soc_dapm_widget *w, enum snd_soc_dapm_type id, |
| 658 | void *priv, const char *wname, const char *stream, |
| 659 | struct snd_kcontrol_new *wc, int numkc, |
| 660 | int (*event)(struct snd_soc_dapm_widget *, |
| 661 | struct snd_kcontrol *, int), unsigned short event_flags) |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 662 | { |
| 663 | w->id = id; |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 664 | w->name = devm_kstrdup(dev, wname, GFP_KERNEL); |
| 665 | if (!w->name) |
| 666 | return -ENOMEM; |
| 667 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 668 | w->sname = stream; |
| 669 | w->reg = SND_SOC_NOPM; |
| 670 | w->shift = 0; |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 671 | w->kcontrol_news = wc; |
| 672 | w->num_kcontrols = numkc; |
| 673 | w->priv = priv; |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 674 | w->event = event; |
| 675 | w->event_flags = event_flags; |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 676 | |
| 677 | return 0; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | static void hdac_hdmi_fill_route(struct snd_soc_dapm_route *route, |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 681 | const char *sink, const char *control, const char *src, |
| 682 | int (*handler)(struct snd_soc_dapm_widget *src, |
| 683 | struct snd_soc_dapm_widget *sink)) |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 684 | { |
| 685 | route->sink = sink; |
| 686 | route->source = src; |
| 687 | route->control = control; |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 688 | route->connected = handler; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 689 | } |
| 690 | |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 691 | static struct hdac_hdmi_pcm *hdac_hdmi_get_pcm(struct hdac_ext_device *edev, |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 692 | struct hdac_hdmi_port *port) |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 693 | { |
| 694 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 695 | struct hdac_hdmi_pcm *pcm = NULL; |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 696 | struct hdac_hdmi_port *p; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 697 | |
| 698 | list_for_each_entry(pcm, &hdmi->pcm_list, head) { |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 699 | if (list_empty(&pcm->port_list)) |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 700 | continue; |
| 701 | |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 702 | list_for_each_entry(p, &pcm->port_list, head) { |
| 703 | if (p->id == port->id && port->pin == p->pin) |
| 704 | return pcm; |
| 705 | } |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | return NULL; |
| 709 | } |
| 710 | |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 711 | static void hdac_hdmi_set_power_state(struct hdac_ext_device *edev, |
| 712 | hda_nid_t nid, unsigned int pwr_state) |
| 713 | { |
| 714 | if (get_wcaps(&edev->hdac, nid) & AC_WCAP_POWER) { |
| 715 | if (!snd_hdac_check_power_state(&edev->hdac, nid, pwr_state)) |
| 716 | snd_hdac_codec_write(&edev->hdac, nid, 0, |
| 717 | AC_VERB_SET_POWER_STATE, pwr_state); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | static void hdac_hdmi_set_amp(struct hdac_ext_device *edev, |
| 722 | hda_nid_t nid, int val) |
| 723 | { |
| 724 | if (get_wcaps(&edev->hdac, nid) & AC_WCAP_OUT_AMP) |
| 725 | snd_hdac_codec_write(&edev->hdac, nid, 0, |
| 726 | AC_VERB_SET_AMP_GAIN_MUTE, val); |
| 727 | } |
| 728 | |
| 729 | |
| 730 | static int hdac_hdmi_pin_output_widget_event(struct snd_soc_dapm_widget *w, |
| 731 | struct snd_kcontrol *kc, int event) |
| 732 | { |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 733 | struct hdac_hdmi_port *port = w->priv; |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 734 | struct hdac_ext_device *edev = to_hda_ext_device(w->dapm->dev); |
| 735 | struct hdac_hdmi_pcm *pcm; |
| 736 | |
| 737 | dev_dbg(&edev->hdac.dev, "%s: widget: %s event: %x\n", |
| 738 | __func__, w->name, event); |
| 739 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 740 | pcm = hdac_hdmi_get_pcm(edev, port); |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 741 | if (!pcm) |
| 742 | return -EIO; |
| 743 | |
Jeeja KP | 1b46ebd | 2017-02-07 19:09:47 +0530 | [diff] [blame] | 744 | /* set the device if pin is mst_capable */ |
| 745 | if (hdac_hdmi_port_select_set(edev, port) < 0) |
| 746 | return -EIO; |
| 747 | |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 748 | switch (event) { |
| 749 | case SND_SOC_DAPM_PRE_PMU: |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 750 | hdac_hdmi_set_power_state(edev, port->pin->nid, AC_PWRST_D0); |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 751 | |
| 752 | /* Enable out path for this pin widget */ |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 753 | snd_hdac_codec_write(&edev->hdac, port->pin->nid, 0, |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 754 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); |
| 755 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 756 | hdac_hdmi_set_amp(edev, port->pin->nid, AMP_OUT_UNMUTE); |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 757 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 758 | return hdac_hdmi_setup_audio_infoframe(edev, pcm, port); |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 759 | |
| 760 | case SND_SOC_DAPM_POST_PMD: |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 761 | hdac_hdmi_set_amp(edev, port->pin->nid, AMP_OUT_MUTE); |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 762 | |
| 763 | /* Disable out path for this pin widget */ |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 764 | snd_hdac_codec_write(&edev->hdac, port->pin->nid, 0, |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 765 | AC_VERB_SET_PIN_WIDGET_CONTROL, 0); |
| 766 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 767 | hdac_hdmi_set_power_state(edev, port->pin->nid, AC_PWRST_D3); |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 768 | break; |
| 769 | |
| 770 | } |
| 771 | |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | static int hdac_hdmi_cvt_output_widget_event(struct snd_soc_dapm_widget *w, |
| 776 | struct snd_kcontrol *kc, int event) |
| 777 | { |
| 778 | struct hdac_hdmi_cvt *cvt = w->priv; |
| 779 | struct hdac_ext_device *edev = to_hda_ext_device(w->dapm->dev); |
| 780 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 781 | struct hdac_hdmi_pcm *pcm; |
| 782 | |
| 783 | dev_dbg(&edev->hdac.dev, "%s: widget: %s event: %x\n", |
| 784 | __func__, w->name, event); |
| 785 | |
| 786 | pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, cvt); |
| 787 | if (!pcm) |
| 788 | return -EIO; |
| 789 | |
| 790 | switch (event) { |
| 791 | case SND_SOC_DAPM_PRE_PMU: |
| 792 | hdac_hdmi_set_power_state(edev, cvt->nid, AC_PWRST_D0); |
| 793 | |
| 794 | /* Enable transmission */ |
| 795 | snd_hdac_codec_write(&edev->hdac, cvt->nid, 0, |
| 796 | AC_VERB_SET_DIGI_CONVERT_1, 1); |
| 797 | |
| 798 | /* Category Code (CC) to zero */ |
| 799 | snd_hdac_codec_write(&edev->hdac, cvt->nid, 0, |
| 800 | AC_VERB_SET_DIGI_CONVERT_2, 0); |
| 801 | |
| 802 | snd_hdac_codec_write(&edev->hdac, cvt->nid, 0, |
| 803 | AC_VERB_SET_CHANNEL_STREAMID, pcm->stream_tag); |
| 804 | snd_hdac_codec_write(&edev->hdac, cvt->nid, 0, |
| 805 | AC_VERB_SET_STREAM_FORMAT, pcm->format); |
| 806 | break; |
| 807 | |
| 808 | case SND_SOC_DAPM_POST_PMD: |
| 809 | snd_hdac_codec_write(&edev->hdac, cvt->nid, 0, |
| 810 | AC_VERB_SET_CHANNEL_STREAMID, 0); |
| 811 | snd_hdac_codec_write(&edev->hdac, cvt->nid, 0, |
| 812 | AC_VERB_SET_STREAM_FORMAT, 0); |
| 813 | |
| 814 | hdac_hdmi_set_power_state(edev, cvt->nid, AC_PWRST_D3); |
| 815 | break; |
| 816 | |
| 817 | } |
| 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | static int hdac_hdmi_pin_mux_widget_event(struct snd_soc_dapm_widget *w, |
| 823 | struct snd_kcontrol *kc, int event) |
| 824 | { |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 825 | struct hdac_hdmi_port *port = w->priv; |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 826 | struct hdac_ext_device *edev = to_hda_ext_device(w->dapm->dev); |
| 827 | int mux_idx; |
| 828 | |
| 829 | dev_dbg(&edev->hdac.dev, "%s: widget: %s event: %x\n", |
| 830 | __func__, w->name, event); |
| 831 | |
| 832 | if (!kc) |
| 833 | kc = w->kcontrols[0]; |
| 834 | |
| 835 | mux_idx = dapm_kcontrol_get_value(kc); |
Jeeja KP | 1b46ebd | 2017-02-07 19:09:47 +0530 | [diff] [blame] | 836 | |
| 837 | /* set the device if pin is mst_capable */ |
| 838 | if (hdac_hdmi_port_select_set(edev, port) < 0) |
| 839 | return -EIO; |
| 840 | |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 841 | if (mux_idx > 0) { |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 842 | snd_hdac_codec_write(&edev->hdac, port->pin->nid, 0, |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 843 | AC_VERB_SET_CONNECT_SEL, (mux_idx - 1)); |
| 844 | } |
| 845 | |
| 846 | return 0; |
| 847 | } |
| 848 | |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 849 | /* |
| 850 | * Based on user selection, map the PINs with the PCMs. |
| 851 | */ |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 852 | static int hdac_hdmi_set_pin_port_mux(struct snd_kcontrol *kcontrol, |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 853 | struct snd_ctl_elem_value *ucontrol) |
| 854 | { |
| 855 | int ret; |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 856 | struct hdac_hdmi_port *p, *p_next; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 857 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 858 | struct snd_soc_dapm_widget *w = snd_soc_dapm_kcontrol_widget(kcontrol); |
| 859 | struct snd_soc_dapm_context *dapm = w->dapm; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 860 | struct hdac_hdmi_port *port = w->priv; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 861 | struct hdac_ext_device *edev = to_hda_ext_device(dapm->dev); |
| 862 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 863 | struct hdac_hdmi_pcm *pcm = NULL; |
| 864 | const char *cvt_name = e->texts[ucontrol->value.enumerated.item[0]]; |
| 865 | |
| 866 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 867 | if (ret < 0) |
| 868 | return ret; |
| 869 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 870 | if (port == NULL) |
| 871 | return -EINVAL; |
| 872 | |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 873 | mutex_lock(&hdmi->pin_mutex); |
| 874 | list_for_each_entry(pcm, &hdmi->pcm_list, head) { |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 875 | if (list_empty(&pcm->port_list)) |
| 876 | continue; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 877 | |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 878 | list_for_each_entry_safe(p, p_next, &pcm->port_list, head) { |
| 879 | if (p == port && p->id == port->id && |
| 880 | p->pin == port->pin) { |
| 881 | hdac_hdmi_jack_report(pcm, port, false); |
| 882 | list_del(&p->head); |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 883 | } |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | |
| 887 | /* |
| 888 | * Jack status is not reported during device probe as the |
| 889 | * PCMs are not registered by then. So report it here. |
| 890 | */ |
| 891 | list_for_each_entry(pcm, &hdmi->pcm_list, head) { |
| 892 | if (!strcmp(cvt_name, pcm->cvt->name)) { |
| 893 | list_add_tail(&port->head, &pcm->port_list); |
| 894 | if (port->eld.monitor_present && port->eld.eld_valid) { |
| 895 | hdac_hdmi_jack_report(pcm, port, true); |
| 896 | mutex_unlock(&hdmi->pin_mutex); |
| 897 | return ret; |
| 898 | } |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 899 | } |
| 900 | } |
| 901 | mutex_unlock(&hdmi->pin_mutex); |
| 902 | |
| 903 | return ret; |
| 904 | } |
| 905 | |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 906 | /* |
| 907 | * Ideally the Mux inputs should be based on the num_muxs enumerated, but |
| 908 | * the display driver seem to be programming the connection list for the pin |
| 909 | * widget runtime. |
| 910 | * |
| 911 | * So programming all the possible inputs for the mux, the user has to take |
| 912 | * care of selecting the right one and leaving all other inputs selected to |
| 913 | * "NONE" |
| 914 | */ |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 915 | static int hdac_hdmi_create_pin_port_muxs(struct hdac_ext_device *edev, |
| 916 | struct hdac_hdmi_port *port, |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 917 | struct snd_soc_dapm_widget *widget, |
| 918 | const char *widget_name) |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 919 | { |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 920 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 921 | struct hdac_hdmi_pin *pin = port->pin; |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 922 | struct snd_kcontrol_new *kc; |
| 923 | struct hdac_hdmi_cvt *cvt; |
| 924 | struct soc_enum *se; |
| 925 | char kc_name[NAME_SIZE]; |
| 926 | char mux_items[NAME_SIZE]; |
| 927 | /* To hold inputs to the Pin mux */ |
| 928 | char *items[HDA_MAX_CONNECTIONS]; |
| 929 | int i = 0; |
| 930 | int num_items = hdmi->num_cvt + 1; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 931 | |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 932 | kc = devm_kzalloc(&edev->hdac.dev, sizeof(*kc), GFP_KERNEL); |
| 933 | if (!kc) |
| 934 | return -ENOMEM; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 935 | |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 936 | se = devm_kzalloc(&edev->hdac.dev, sizeof(*se), GFP_KERNEL); |
| 937 | if (!se) |
| 938 | return -ENOMEM; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 939 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 940 | sprintf(kc_name, "Pin %d port %d Input", pin->nid, port->id); |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 941 | kc->name = devm_kstrdup(&edev->hdac.dev, kc_name, GFP_KERNEL); |
| 942 | if (!kc->name) |
| 943 | return -ENOMEM; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 944 | |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 945 | kc->private_value = (long)se; |
| 946 | kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 947 | kc->access = 0; |
| 948 | kc->info = snd_soc_info_enum_double; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 949 | kc->put = hdac_hdmi_set_pin_port_mux; |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 950 | kc->get = snd_soc_dapm_get_enum_double; |
| 951 | |
| 952 | se->reg = SND_SOC_NOPM; |
| 953 | |
| 954 | /* enum texts: ["NONE", "cvt #", "cvt #", ...] */ |
| 955 | se->items = num_items; |
| 956 | se->mask = roundup_pow_of_two(se->items) - 1; |
| 957 | |
| 958 | sprintf(mux_items, "NONE"); |
| 959 | items[i] = devm_kstrdup(&edev->hdac.dev, mux_items, GFP_KERNEL); |
| 960 | if (!items[i]) |
| 961 | return -ENOMEM; |
| 962 | |
| 963 | list_for_each_entry(cvt, &hdmi->cvt_list, head) { |
| 964 | i++; |
| 965 | sprintf(mux_items, "cvt %d", cvt->nid); |
| 966 | items[i] = devm_kstrdup(&edev->hdac.dev, mux_items, GFP_KERNEL); |
| 967 | if (!items[i]) |
| 968 | return -ENOMEM; |
| 969 | } |
| 970 | |
| 971 | se->texts = devm_kmemdup(&edev->hdac.dev, items, |
| 972 | (num_items * sizeof(char *)), GFP_KERNEL); |
| 973 | if (!se->texts) |
| 974 | return -ENOMEM; |
| 975 | |
| 976 | return hdac_hdmi_fill_widget_info(&edev->hdac.dev, widget, |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 977 | snd_soc_dapm_mux, port, widget_name, NULL, kc, 1, |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 978 | hdac_hdmi_pin_mux_widget_event, |
| 979 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_REG); |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | /* Add cvt <- input <- mux route map */ |
| 983 | static void hdac_hdmi_add_pinmux_cvt_route(struct hdac_ext_device *edev, |
| 984 | struct snd_soc_dapm_widget *widgets, |
| 985 | struct snd_soc_dapm_route *route, int rindex) |
| 986 | { |
| 987 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 988 | const struct snd_kcontrol_new *kc; |
| 989 | struct soc_enum *se; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 990 | int mux_index = hdmi->num_cvt + hdmi->num_ports; |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 991 | int i, j; |
| 992 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 993 | for (i = 0; i < hdmi->num_ports; i++) { |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 994 | kc = widgets[mux_index].kcontrol_news; |
| 995 | se = (struct soc_enum *)kc->private_value; |
| 996 | for (j = 0; j < hdmi->num_cvt; j++) { |
| 997 | hdac_hdmi_fill_route(&route[rindex], |
| 998 | widgets[mux_index].name, |
| 999 | se->texts[j + 1], |
| 1000 | widgets[j].name, NULL); |
| 1001 | |
| 1002 | rindex++; |
| 1003 | } |
| 1004 | |
| 1005 | mux_index++; |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | /* |
| 1010 | * Widgets are added in the below sequence |
| 1011 | * Converter widgets for num converters enumerated |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1012 | * Pin-port widgets for num ports for Pins enumerated |
| 1013 | * Pin-port mux widgets to represent connenction list of pin widget |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1014 | * |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1015 | * For each port, one Mux and One output widget is added |
| 1016 | * Total widgets elements = num_cvt + (num_ports * 2); |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1017 | * |
| 1018 | * Routes are added as below: |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1019 | * pin-port mux -> pin (based on num_ports) |
| 1020 | * cvt -> "Input sel control" -> pin-port_mux |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1021 | * |
| 1022 | * Total route elements: |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1023 | * num_ports + (pin_muxes * num_cvt) |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1024 | */ |
| 1025 | static int create_fill_widget_route_map(struct snd_soc_dapm_context *dapm) |
| 1026 | { |
| 1027 | struct snd_soc_dapm_widget *widgets; |
| 1028 | struct snd_soc_dapm_route *route; |
| 1029 | struct hdac_ext_device *edev = to_hda_ext_device(dapm->dev); |
| 1030 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 1031 | struct snd_soc_dai_driver *dai_drv = dapm->component->dai_drv; |
| 1032 | char widget_name[NAME_SIZE]; |
| 1033 | struct hdac_hdmi_cvt *cvt; |
| 1034 | struct hdac_hdmi_pin *pin; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1035 | int ret, i = 0, num_routes = 0, j; |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1036 | |
| 1037 | if (list_empty(&hdmi->cvt_list) || list_empty(&hdmi->pin_list)) |
| 1038 | return -EINVAL; |
| 1039 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1040 | widgets = devm_kzalloc(dapm->dev, (sizeof(*widgets) * |
| 1041 | ((2 * hdmi->num_ports) + hdmi->num_cvt)), |
| 1042 | GFP_KERNEL); |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1043 | |
| 1044 | if (!widgets) |
| 1045 | return -ENOMEM; |
| 1046 | |
| 1047 | /* DAPM widgets to represent each converter widget */ |
| 1048 | list_for_each_entry(cvt, &hdmi->cvt_list, head) { |
| 1049 | sprintf(widget_name, "Converter %d", cvt->nid); |
| 1050 | ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i], |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 1051 | snd_soc_dapm_aif_in, cvt, |
| 1052 | widget_name, dai_drv[i].playback.stream_name, NULL, 0, |
| 1053 | hdac_hdmi_cvt_output_widget_event, |
| 1054 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD); |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1055 | if (ret < 0) |
| 1056 | return ret; |
| 1057 | i++; |
| 1058 | } |
| 1059 | |
| 1060 | list_for_each_entry(pin, &hdmi->pin_list, head) { |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1061 | for (j = 0; j < pin->num_ports; j++) { |
| 1062 | sprintf(widget_name, "hif%d-%d Output", |
| 1063 | pin->nid, pin->ports[j].id); |
| 1064 | ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i], |
| 1065 | snd_soc_dapm_output, &pin->ports[j], |
| 1066 | widget_name, NULL, NULL, 0, |
| 1067 | hdac_hdmi_pin_output_widget_event, |
| 1068 | SND_SOC_DAPM_PRE_PMU | |
| 1069 | SND_SOC_DAPM_POST_PMD); |
| 1070 | if (ret < 0) |
| 1071 | return ret; |
Jeeja KP | 0324e51 | 2017-02-07 19:09:55 +0530 | [diff] [blame] | 1072 | pin->ports[j].output_pin = widgets[i].name; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1073 | i++; |
| 1074 | } |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | /* DAPM widgets to represent the connection list to pin widget */ |
| 1078 | list_for_each_entry(pin, &hdmi->pin_list, head) { |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1079 | for (j = 0; j < pin->num_ports; j++) { |
| 1080 | sprintf(widget_name, "Pin%d-Port%d Mux", |
| 1081 | pin->nid, pin->ports[j].id); |
| 1082 | ret = hdac_hdmi_create_pin_port_muxs(edev, |
| 1083 | &pin->ports[j], &widgets[i], |
| 1084 | widget_name); |
| 1085 | if (ret < 0) |
| 1086 | return ret; |
| 1087 | i++; |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1088 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1089 | /* For cvt to pin_mux mapping */ |
| 1090 | num_routes += hdmi->num_cvt; |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1091 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1092 | /* For pin_mux to pin mapping */ |
| 1093 | num_routes++; |
| 1094 | } |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | route = devm_kzalloc(dapm->dev, (sizeof(*route) * num_routes), |
| 1098 | GFP_KERNEL); |
| 1099 | if (!route) |
| 1100 | return -ENOMEM; |
| 1101 | |
| 1102 | i = 0; |
| 1103 | /* Add pin <- NULL <- mux route map */ |
| 1104 | list_for_each_entry(pin, &hdmi->pin_list, head) { |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1105 | for (j = 0; j < pin->num_ports; j++) { |
| 1106 | int sink_index = i + hdmi->num_cvt; |
| 1107 | int src_index = sink_index + pin->num_ports * |
| 1108 | hdmi->num_pin; |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1109 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1110 | hdac_hdmi_fill_route(&route[i], |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1111 | widgets[sink_index].name, NULL, |
| 1112 | widgets[src_index].name, NULL); |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1113 | i++; |
| 1114 | } |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | hdac_hdmi_add_pinmux_cvt_route(edev, widgets, route, i); |
| 1118 | |
| 1119 | snd_soc_dapm_new_controls(dapm, widgets, |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1120 | ((2 * hdmi->num_ports) + hdmi->num_cvt)); |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1121 | |
| 1122 | snd_soc_dapm_add_routes(dapm, route, num_routes); |
| 1123 | snd_soc_dapm_new_widgets(dapm->card); |
| 1124 | |
| 1125 | return 0; |
| 1126 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1127 | } |
| 1128 | |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1129 | static int hdac_hdmi_init_dai_map(struct hdac_ext_device *edev) |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1130 | { |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1131 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1132 | struct hdac_hdmi_dai_port_map *dai_map; |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1133 | struct hdac_hdmi_cvt *cvt; |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 1134 | int dai_id = 0; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1135 | |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 1136 | if (list_empty(&hdmi->cvt_list)) |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1137 | return -EINVAL; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1138 | |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 1139 | list_for_each_entry(cvt, &hdmi->cvt_list, head) { |
| 1140 | dai_map = &hdmi->dai_map[dai_id]; |
| 1141 | dai_map->dai_id = dai_id; |
| 1142 | dai_map->cvt = cvt; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1143 | |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 1144 | dai_id++; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1145 | |
Subhransu S. Prusty | 148569f | 2016-02-12 07:46:07 +0530 | [diff] [blame] | 1146 | if (dai_id == HDA_MAX_CVTS) { |
| 1147 | dev_warn(&edev->hdac.dev, |
| 1148 | "Max dais supported: %d\n", dai_id); |
| 1149 | break; |
| 1150 | } |
| 1151 | } |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1152 | |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1153 | return 0; |
| 1154 | } |
| 1155 | |
| 1156 | static int hdac_hdmi_add_cvt(struct hdac_ext_device *edev, hda_nid_t nid) |
| 1157 | { |
| 1158 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 1159 | struct hdac_hdmi_cvt *cvt; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1160 | char name[NAME_SIZE]; |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1161 | |
| 1162 | cvt = kzalloc(sizeof(*cvt), GFP_KERNEL); |
| 1163 | if (!cvt) |
| 1164 | return -ENOMEM; |
| 1165 | |
| 1166 | cvt->nid = nid; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1167 | sprintf(name, "cvt %d", cvt->nid); |
| 1168 | cvt->name = kstrdup(name, GFP_KERNEL); |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1169 | |
| 1170 | list_add_tail(&cvt->head, &hdmi->cvt_list); |
| 1171 | hdmi->num_cvt++; |
| 1172 | |
| 1173 | return hdac_hdmi_query_cvt_params(&edev->hdac, cvt); |
| 1174 | } |
| 1175 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1176 | static int hdac_hdmi_parse_eld(struct hdac_ext_device *edev, |
| 1177 | struct hdac_hdmi_port *port) |
Subhransu S. Prusty | b7756ed | 2016-04-14 10:07:28 +0530 | [diff] [blame] | 1178 | { |
Sandeep Tayal | f6fa11a | 2017-01-18 21:34:41 +0530 | [diff] [blame] | 1179 | unsigned int ver, mnl; |
| 1180 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1181 | ver = (port->eld.eld_buffer[DRM_ELD_VER] & DRM_ELD_VER_MASK) |
Sandeep Tayal | f6fa11a | 2017-01-18 21:34:41 +0530 | [diff] [blame] | 1182 | >> DRM_ELD_VER_SHIFT; |
| 1183 | |
| 1184 | if (ver != ELD_VER_CEA_861D && ver != ELD_VER_PARTIAL) { |
| 1185 | dev_err(&edev->hdac.dev, "HDMI: Unknown ELD version %d\n", ver); |
| 1186 | return -EINVAL; |
| 1187 | } |
| 1188 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1189 | mnl = (port->eld.eld_buffer[DRM_ELD_CEA_EDID_VER_MNL] & |
Sandeep Tayal | f6fa11a | 2017-01-18 21:34:41 +0530 | [diff] [blame] | 1190 | DRM_ELD_MNL_MASK) >> DRM_ELD_MNL_SHIFT; |
| 1191 | |
| 1192 | if (mnl > ELD_MAX_MNL) { |
| 1193 | dev_err(&edev->hdac.dev, "HDMI: MNL Invalid %d\n", mnl); |
| 1194 | return -EINVAL; |
| 1195 | } |
| 1196 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1197 | port->eld.info.spk_alloc = port->eld.eld_buffer[DRM_ELD_SPEAKER]; |
Sandeep Tayal | f6fa11a | 2017-01-18 21:34:41 +0530 | [diff] [blame] | 1198 | |
| 1199 | return 0; |
Subhransu S. Prusty | b7756ed | 2016-04-14 10:07:28 +0530 | [diff] [blame] | 1200 | } |
| 1201 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1202 | static void hdac_hdmi_present_sense(struct hdac_hdmi_pin *pin, |
| 1203 | struct hdac_hdmi_port *port) |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 1204 | { |
| 1205 | struct hdac_ext_device *edev = pin->edev; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1206 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 1207 | struct hdac_hdmi_pcm *pcm; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1208 | int size = 0; |
Jeeja KP | 2acd830 | 2017-02-06 12:09:18 +0530 | [diff] [blame] | 1209 | int port_id = -1; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1210 | |
| 1211 | if (!hdmi) |
| 1212 | return; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1213 | |
Jeeja KP | 2acd830 | 2017-02-06 12:09:18 +0530 | [diff] [blame] | 1214 | /* |
| 1215 | * In case of non MST pin, get_eld info API expectes port |
| 1216 | * to be -1. |
| 1217 | */ |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1218 | mutex_lock(&hdmi->pin_mutex); |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1219 | port->eld.monitor_present = false; |
Sandeep Tayal | f6fa11a | 2017-01-18 21:34:41 +0530 | [diff] [blame] | 1220 | |
Jeeja KP | 2acd830 | 2017-02-06 12:09:18 +0530 | [diff] [blame] | 1221 | if (pin->mst_capable) |
| 1222 | port_id = port->id; |
| 1223 | |
| 1224 | size = snd_hdac_acomp_get_eld(&edev->hdac, pin->nid, port_id, |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1225 | &port->eld.monitor_present, |
| 1226 | port->eld.eld_buffer, |
Sandeep Tayal | f6fa11a | 2017-01-18 21:34:41 +0530 | [diff] [blame] | 1227 | ELD_MAX_SIZE); |
| 1228 | |
| 1229 | if (size > 0) { |
| 1230 | size = min(size, ELD_MAX_SIZE); |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1231 | if (hdac_hdmi_parse_eld(edev, port) < 0) |
Sandeep Tayal | f6fa11a | 2017-01-18 21:34:41 +0530 | [diff] [blame] | 1232 | size = -EINVAL; |
| 1233 | } |
| 1234 | |
| 1235 | if (size > 0) { |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1236 | port->eld.eld_valid = true; |
| 1237 | port->eld.eld_size = size; |
Sandeep Tayal | f6fa11a | 2017-01-18 21:34:41 +0530 | [diff] [blame] | 1238 | } else { |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1239 | port->eld.eld_valid = false; |
| 1240 | port->eld.eld_size = 0; |
Sandeep Tayal | f6fa11a | 2017-01-18 21:34:41 +0530 | [diff] [blame] | 1241 | } |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 1242 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1243 | pcm = hdac_hdmi_get_pcm(edev, port); |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1244 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1245 | if (!port->eld.monitor_present || !port->eld.eld_valid) { |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 1246 | |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 1247 | dev_err(&edev->hdac.dev, "%s: disconnect for pin:port %d:%d\n", |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1248 | __func__, pin->nid, port->id); |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1249 | |
| 1250 | /* |
| 1251 | * PCMs are not registered during device probe, so don't |
| 1252 | * report jack here. It will be done in usermode mux |
| 1253 | * control select. |
| 1254 | */ |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 1255 | if (pcm) |
| 1256 | hdac_hdmi_jack_report(pcm, port, false); |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1257 | |
| 1258 | mutex_unlock(&hdmi->pin_mutex); |
Sandeep Tayal | f6fa11a | 2017-01-18 21:34:41 +0530 | [diff] [blame] | 1259 | return; |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 1260 | } |
| 1261 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1262 | if (port->eld.monitor_present && port->eld.eld_valid) { |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 1263 | if (pcm) |
| 1264 | hdac_hdmi_jack_report(pcm, port, true); |
Sandeep Tayal | f6fa11a | 2017-01-18 21:34:41 +0530 | [diff] [blame] | 1265 | |
| 1266 | print_hex_dump_debug("ELD: ", DUMP_PREFIX_OFFSET, 16, 1, |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1267 | port->eld.eld_buffer, port->eld.eld_size, false); |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 1268 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1269 | } |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1270 | mutex_unlock(&hdmi->pin_mutex); |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 1271 | } |
| 1272 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1273 | static int hdac_hdmi_add_ports(struct hdac_hdmi_priv *hdmi, |
| 1274 | struct hdac_hdmi_pin *pin) |
| 1275 | { |
| 1276 | struct hdac_hdmi_port *ports; |
| 1277 | int max_ports = HDA_MAX_PORTS; |
| 1278 | int i; |
| 1279 | |
| 1280 | /* |
| 1281 | * FIXME: max_port may vary for each platform, so pass this as |
| 1282 | * as driver data or query from i915 interface when this API is |
| 1283 | * implemented. |
| 1284 | */ |
| 1285 | |
| 1286 | ports = kcalloc(max_ports, sizeof(*ports), GFP_KERNEL); |
| 1287 | if (!ports) |
| 1288 | return -ENOMEM; |
| 1289 | |
| 1290 | for (i = 0; i < max_ports; i++) { |
| 1291 | ports[i].id = i; |
| 1292 | ports[i].pin = pin; |
| 1293 | } |
| 1294 | pin->ports = ports; |
| 1295 | pin->num_ports = max_ports; |
| 1296 | return 0; |
| 1297 | } |
| 1298 | |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1299 | static int hdac_hdmi_add_pin(struct hdac_ext_device *edev, hda_nid_t nid) |
| 1300 | { |
| 1301 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 1302 | struct hdac_hdmi_pin *pin; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1303 | int ret; |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1304 | |
| 1305 | pin = kzalloc(sizeof(*pin), GFP_KERNEL); |
| 1306 | if (!pin) |
| 1307 | return -ENOMEM; |
| 1308 | |
| 1309 | pin->nid = nid; |
Jeeja KP | 2acd830 | 2017-02-06 12:09:18 +0530 | [diff] [blame] | 1310 | pin->mst_capable = false; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1311 | pin->edev = edev; |
| 1312 | ret = hdac_hdmi_add_ports(hdmi, pin); |
| 1313 | if (ret < 0) |
| 1314 | return ret; |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1315 | |
| 1316 | list_add_tail(&pin->head, &hdmi->pin_list); |
| 1317 | hdmi->num_pin++; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1318 | hdmi->num_ports += pin->num_ports; |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 1319 | |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1320 | return 0; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1321 | } |
| 1322 | |
Subhransu S. Prusty | 211caab | 2016-02-12 07:46:03 +0530 | [diff] [blame] | 1323 | #define INTEL_VENDOR_NID 0x08 |
| 1324 | #define INTEL_GET_VENDOR_VERB 0xf81 |
| 1325 | #define INTEL_SET_VENDOR_VERB 0x781 |
| 1326 | #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */ |
| 1327 | #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */ |
| 1328 | |
| 1329 | static void hdac_hdmi_skl_enable_all_pins(struct hdac_device *hdac) |
| 1330 | { |
| 1331 | unsigned int vendor_param; |
| 1332 | |
| 1333 | vendor_param = snd_hdac_codec_read(hdac, INTEL_VENDOR_NID, 0, |
| 1334 | INTEL_GET_VENDOR_VERB, 0); |
| 1335 | if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS) |
| 1336 | return; |
| 1337 | |
| 1338 | vendor_param |= INTEL_EN_ALL_PIN_CVTS; |
| 1339 | vendor_param = snd_hdac_codec_read(hdac, INTEL_VENDOR_NID, 0, |
| 1340 | INTEL_SET_VENDOR_VERB, vendor_param); |
| 1341 | if (vendor_param == -1) |
| 1342 | return; |
| 1343 | } |
| 1344 | |
| 1345 | static void hdac_hdmi_skl_enable_dp12(struct hdac_device *hdac) |
| 1346 | { |
| 1347 | unsigned int vendor_param; |
| 1348 | |
| 1349 | vendor_param = snd_hdac_codec_read(hdac, INTEL_VENDOR_NID, 0, |
| 1350 | INTEL_GET_VENDOR_VERB, 0); |
| 1351 | if (vendor_param == -1 || vendor_param & INTEL_EN_DP12) |
| 1352 | return; |
| 1353 | |
| 1354 | /* enable DP1.2 mode */ |
| 1355 | vendor_param |= INTEL_EN_DP12; |
| 1356 | vendor_param = snd_hdac_codec_read(hdac, INTEL_VENDOR_NID, 0, |
| 1357 | INTEL_SET_VENDOR_VERB, vendor_param); |
| 1358 | if (vendor_param == -1) |
| 1359 | return; |
| 1360 | |
| 1361 | } |
| 1362 | |
Subhransu S. Prusty | 17a42c4 | 2016-02-12 07:46:04 +0530 | [diff] [blame] | 1363 | static struct snd_soc_dai_ops hdmi_dai_ops = { |
| 1364 | .startup = hdac_hdmi_pcm_open, |
| 1365 | .shutdown = hdac_hdmi_pcm_close, |
| 1366 | .hw_params = hdac_hdmi_set_hw_params, |
Jeeja KP | c9bfb5d | 2017-01-24 21:49:03 +0530 | [diff] [blame] | 1367 | .set_tdm_slot = hdac_hdmi_set_tdm_slot, |
Subhransu S. Prusty | 17a42c4 | 2016-02-12 07:46:04 +0530 | [diff] [blame] | 1368 | }; |
| 1369 | |
| 1370 | /* |
| 1371 | * Each converter can support a stream independently. So a dai is created |
| 1372 | * based on the number of converter queried. |
| 1373 | */ |
| 1374 | static int hdac_hdmi_create_dais(struct hdac_device *hdac, |
| 1375 | struct snd_soc_dai_driver **dais, |
| 1376 | struct hdac_hdmi_priv *hdmi, int num_dais) |
| 1377 | { |
| 1378 | struct snd_soc_dai_driver *hdmi_dais; |
| 1379 | struct hdac_hdmi_cvt *cvt; |
| 1380 | char name[NAME_SIZE], dai_name[NAME_SIZE]; |
| 1381 | int i = 0; |
| 1382 | u32 rates, bps; |
| 1383 | unsigned int rate_max = 384000, rate_min = 8000; |
| 1384 | u64 formats; |
| 1385 | int ret; |
| 1386 | |
| 1387 | hdmi_dais = devm_kzalloc(&hdac->dev, |
| 1388 | (sizeof(*hdmi_dais) * num_dais), |
| 1389 | GFP_KERNEL); |
| 1390 | if (!hdmi_dais) |
| 1391 | return -ENOMEM; |
| 1392 | |
| 1393 | list_for_each_entry(cvt, &hdmi->cvt_list, head) { |
| 1394 | ret = snd_hdac_query_supported_pcm(hdac, cvt->nid, |
| 1395 | &rates, &formats, &bps); |
| 1396 | if (ret) |
| 1397 | return ret; |
| 1398 | |
| 1399 | sprintf(dai_name, "intel-hdmi-hifi%d", i+1); |
| 1400 | hdmi_dais[i].name = devm_kstrdup(&hdac->dev, |
| 1401 | dai_name, GFP_KERNEL); |
| 1402 | |
| 1403 | if (!hdmi_dais[i].name) |
| 1404 | return -ENOMEM; |
| 1405 | |
| 1406 | snprintf(name, sizeof(name), "hifi%d", i+1); |
| 1407 | hdmi_dais[i].playback.stream_name = |
| 1408 | devm_kstrdup(&hdac->dev, name, GFP_KERNEL); |
| 1409 | if (!hdmi_dais[i].playback.stream_name) |
| 1410 | return -ENOMEM; |
| 1411 | |
| 1412 | /* |
| 1413 | * Set caps based on capability queried from the converter. |
| 1414 | * It will be constrained runtime based on ELD queried. |
| 1415 | */ |
| 1416 | hdmi_dais[i].playback.formats = formats; |
| 1417 | hdmi_dais[i].playback.rates = rates; |
| 1418 | hdmi_dais[i].playback.rate_max = rate_max; |
| 1419 | hdmi_dais[i].playback.rate_min = rate_min; |
| 1420 | hdmi_dais[i].playback.channels_min = 2; |
| 1421 | hdmi_dais[i].playback.channels_max = 2; |
Jeeja KP | 66d6bbc | 2017-03-24 23:10:26 +0530 | [diff] [blame] | 1422 | hdmi_dais[i].playback.sig_bits = bps; |
Subhransu S. Prusty | 17a42c4 | 2016-02-12 07:46:04 +0530 | [diff] [blame] | 1423 | hdmi_dais[i].ops = &hdmi_dai_ops; |
Subhransu S. Prusty | 17a42c4 | 2016-02-12 07:46:04 +0530 | [diff] [blame] | 1424 | i++; |
| 1425 | } |
| 1426 | |
| 1427 | *dais = hdmi_dais; |
| 1428 | |
| 1429 | return 0; |
| 1430 | } |
| 1431 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1432 | /* |
| 1433 | * Parse all nodes and store the cvt/pin nids in array |
| 1434 | * Add one time initialization for pin and cvt widgets |
| 1435 | */ |
Subhransu S. Prusty | 17a42c4 | 2016-02-12 07:46:04 +0530 | [diff] [blame] | 1436 | static int hdac_hdmi_parse_and_map_nid(struct hdac_ext_device *edev, |
| 1437 | struct snd_soc_dai_driver **dais, int *num_dais) |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1438 | { |
| 1439 | hda_nid_t nid; |
Sudip Mukherjee | 3c83ac2 | 2015-12-01 14:29:35 +0530 | [diff] [blame] | 1440 | int i, num_nodes; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1441 | struct hdac_device *hdac = &edev->hdac; |
| 1442 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1443 | int ret; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1444 | |
Subhransu S. Prusty | 211caab | 2016-02-12 07:46:03 +0530 | [diff] [blame] | 1445 | hdac_hdmi_skl_enable_all_pins(hdac); |
| 1446 | hdac_hdmi_skl_enable_dp12(hdac); |
| 1447 | |
Sudip Mukherjee | 3c83ac2 | 2015-12-01 14:29:35 +0530 | [diff] [blame] | 1448 | num_nodes = snd_hdac_get_sub_nodes(hdac, hdac->afg, &nid); |
Subhransu S. Prusty | 541140d | 2015-12-09 21:46:08 +0530 | [diff] [blame] | 1449 | if (!nid || num_nodes <= 0) { |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1450 | dev_warn(&hdac->dev, "HDMI: failed to get afg sub nodes\n"); |
| 1451 | return -EINVAL; |
| 1452 | } |
| 1453 | |
Sudip Mukherjee | 3c83ac2 | 2015-12-01 14:29:35 +0530 | [diff] [blame] | 1454 | hdac->num_nodes = num_nodes; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1455 | hdac->start_nid = nid; |
| 1456 | |
| 1457 | for (i = 0; i < hdac->num_nodes; i++, nid++) { |
| 1458 | unsigned int caps; |
| 1459 | unsigned int type; |
| 1460 | |
| 1461 | caps = get_wcaps(hdac, nid); |
| 1462 | type = get_wcaps_type(caps); |
| 1463 | |
| 1464 | if (!(caps & AC_WCAP_DIGITAL)) |
| 1465 | continue; |
| 1466 | |
| 1467 | switch (type) { |
| 1468 | |
| 1469 | case AC_WID_AUD_OUT: |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1470 | ret = hdac_hdmi_add_cvt(edev, nid); |
| 1471 | if (ret < 0) |
| 1472 | return ret; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1473 | break; |
| 1474 | |
| 1475 | case AC_WID_PIN: |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1476 | ret = hdac_hdmi_add_pin(edev, nid); |
| 1477 | if (ret < 0) |
| 1478 | return ret; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1479 | break; |
| 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | hdac->end_nid = nid; |
| 1484 | |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1485 | if (!hdmi->num_pin || !hdmi->num_cvt) |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1486 | return -EIO; |
| 1487 | |
Subhransu S. Prusty | 17a42c4 | 2016-02-12 07:46:04 +0530 | [diff] [blame] | 1488 | ret = hdac_hdmi_create_dais(hdac, dais, hdmi, hdmi->num_cvt); |
| 1489 | if (ret) { |
| 1490 | dev_err(&hdac->dev, "Failed to create dais with err: %d\n", |
| 1491 | ret); |
| 1492 | return ret; |
| 1493 | } |
| 1494 | |
| 1495 | *num_dais = hdmi->num_cvt; |
| 1496 | |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1497 | return hdac_hdmi_init_dai_map(edev); |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1498 | } |
| 1499 | |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 1500 | static void hdac_hdmi_eld_notify_cb(void *aptr, int port, int pipe) |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 1501 | { |
| 1502 | struct hdac_ext_device *edev = aptr; |
| 1503 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1504 | struct hdac_hdmi_pin *pin = NULL; |
| 1505 | struct hdac_hdmi_port *hport = NULL; |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 1506 | struct snd_soc_codec *codec = edev->scodec; |
Jeeja KP | 2acd830 | 2017-02-06 12:09:18 +0530 | [diff] [blame] | 1507 | int i; |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 1508 | |
| 1509 | /* Don't know how this mapping is derived */ |
| 1510 | hda_nid_t pin_nid = port + 0x04; |
| 1511 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1512 | dev_dbg(&edev->hdac.dev, "%s: for pin:%d port=%d\n", __func__, |
| 1513 | pin_nid, pipe); |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 1514 | |
| 1515 | /* |
| 1516 | * skip notification during system suspend (but not in runtime PM); |
| 1517 | * the state will be updated at resume. Also since the ELD and |
| 1518 | * connection states are updated in anyway at the end of the resume, |
| 1519 | * we can skip it when received during PM process. |
| 1520 | */ |
| 1521 | if (snd_power_get_state(codec->component.card->snd_card) != |
| 1522 | SNDRV_CTL_POWER_D0) |
| 1523 | return; |
| 1524 | |
| 1525 | if (atomic_read(&edev->hdac.in_pm)) |
| 1526 | return; |
| 1527 | |
| 1528 | list_for_each_entry(pin, &hdmi->pin_list, head) { |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1529 | if (pin->nid != pin_nid) |
| 1530 | continue; |
| 1531 | |
| 1532 | /* In case of non MST pin, pipe is -1 */ |
| 1533 | if (pipe == -1) { |
Jeeja KP | 2acd830 | 2017-02-06 12:09:18 +0530 | [diff] [blame] | 1534 | pin->mst_capable = false; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1535 | /* if not MST, default is port[0] */ |
| 1536 | hport = &pin->ports[0]; |
Jeeja KP | 2acd830 | 2017-02-06 12:09:18 +0530 | [diff] [blame] | 1537 | } else { |
| 1538 | for (i = 0; i < pin->num_ports; i++) { |
| 1539 | pin->mst_capable = true; |
| 1540 | if (pin->ports[i].id == pipe) { |
| 1541 | hport = &pin->ports[i]; |
Jeeja KP | 04c8f2b | 2017-03-01 22:41:23 +0530 | [diff] [blame] | 1542 | break; |
Jeeja KP | 2acd830 | 2017-02-06 12:09:18 +0530 | [diff] [blame] | 1543 | } |
| 1544 | } |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1545 | } |
Jeeja KP | 04c8f2b | 2017-03-01 22:41:23 +0530 | [diff] [blame] | 1546 | |
| 1547 | if (hport) |
| 1548 | hdac_hdmi_present_sense(pin, hport); |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 1549 | } |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1550 | |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | static struct i915_audio_component_audio_ops aops = { |
| 1554 | .pin_eld_notify = hdac_hdmi_eld_notify_cb, |
| 1555 | }; |
| 1556 | |
Subhransu S. Prusty | 2889099 | 2016-04-14 10:07:34 +0530 | [diff] [blame] | 1557 | static struct snd_pcm *hdac_hdmi_get_pcm_from_id(struct snd_soc_card *card, |
| 1558 | int device) |
| 1559 | { |
| 1560 | struct snd_soc_pcm_runtime *rtd; |
| 1561 | |
| 1562 | list_for_each_entry(rtd, &card->rtd_list, list) { |
| 1563 | if (rtd->pcm && (rtd->pcm->device == device)) |
| 1564 | return rtd->pcm; |
| 1565 | } |
| 1566 | |
| 1567 | return NULL; |
| 1568 | } |
| 1569 | |
Jeeja KP | 0324e51 | 2017-02-07 19:09:55 +0530 | [diff] [blame] | 1570 | /* create jack pin kcontrols */ |
| 1571 | static int create_fill_jack_kcontrols(struct snd_soc_card *card, |
| 1572 | struct hdac_ext_device *edev) |
| 1573 | { |
| 1574 | struct hdac_hdmi_pin *pin; |
| 1575 | struct snd_kcontrol_new *kc; |
| 1576 | char kc_name[NAME_SIZE], xname[NAME_SIZE]; |
| 1577 | char *name; |
| 1578 | int i = 0, j; |
| 1579 | struct snd_soc_codec *codec = edev->scodec; |
| 1580 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 1581 | |
| 1582 | kc = devm_kcalloc(codec->dev, hdmi->num_ports, |
| 1583 | sizeof(*kc), GFP_KERNEL); |
| 1584 | |
| 1585 | if (!kc) |
| 1586 | return -ENOMEM; |
| 1587 | |
| 1588 | list_for_each_entry(pin, &hdmi->pin_list, head) { |
| 1589 | for (j = 0; j < pin->num_ports; j++) { |
| 1590 | snprintf(xname, sizeof(xname), "hif%d-%d Jack", |
| 1591 | pin->nid, pin->ports[j].id); |
| 1592 | name = devm_kstrdup(codec->dev, xname, GFP_KERNEL); |
| 1593 | if (!name) |
| 1594 | return -ENOMEM; |
| 1595 | snprintf(kc_name, sizeof(kc_name), "%s Switch", xname); |
| 1596 | kc[i].name = devm_kstrdup(codec->dev, kc_name, |
| 1597 | GFP_KERNEL); |
| 1598 | if (!kc[i].name) |
| 1599 | return -ENOMEM; |
| 1600 | |
| 1601 | kc[i].private_value = (unsigned long)name; |
| 1602 | kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 1603 | kc[i].access = 0; |
| 1604 | kc[i].info = snd_soc_dapm_info_pin_switch; |
| 1605 | kc[i].put = snd_soc_dapm_put_pin_switch; |
| 1606 | kc[i].get = snd_soc_dapm_get_pin_switch; |
| 1607 | i++; |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | return snd_soc_add_card_controls(card, kc, i); |
| 1612 | } |
| 1613 | |
| 1614 | int hdac_hdmi_jack_port_init(struct snd_soc_codec *codec, |
| 1615 | struct snd_soc_dapm_context *dapm) |
| 1616 | { |
| 1617 | struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec); |
| 1618 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 1619 | struct hdac_hdmi_pin *pin; |
| 1620 | struct snd_soc_dapm_widget *widgets; |
| 1621 | struct snd_soc_dapm_route *route; |
| 1622 | char w_name[NAME_SIZE]; |
| 1623 | int i = 0, j, ret; |
| 1624 | |
| 1625 | widgets = devm_kcalloc(dapm->dev, hdmi->num_ports, |
| 1626 | sizeof(*widgets), GFP_KERNEL); |
| 1627 | |
| 1628 | if (!widgets) |
| 1629 | return -ENOMEM; |
| 1630 | |
| 1631 | route = devm_kcalloc(dapm->dev, hdmi->num_ports, |
| 1632 | sizeof(*route), GFP_KERNEL); |
| 1633 | if (!route) |
| 1634 | return -ENOMEM; |
| 1635 | |
| 1636 | /* create Jack DAPM widget */ |
| 1637 | list_for_each_entry(pin, &hdmi->pin_list, head) { |
| 1638 | for (j = 0; j < pin->num_ports; j++) { |
| 1639 | snprintf(w_name, sizeof(w_name), "hif%d-%d Jack", |
| 1640 | pin->nid, pin->ports[j].id); |
| 1641 | |
| 1642 | ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i], |
| 1643 | snd_soc_dapm_spk, NULL, |
| 1644 | w_name, NULL, NULL, 0, NULL, 0); |
| 1645 | if (ret < 0) |
| 1646 | return ret; |
| 1647 | |
| 1648 | pin->ports[j].jack_pin = widgets[i].name; |
| 1649 | pin->ports[j].dapm = dapm; |
| 1650 | |
| 1651 | /* add to route from Jack widget to output */ |
| 1652 | hdac_hdmi_fill_route(&route[i], pin->ports[j].jack_pin, |
| 1653 | NULL, pin->ports[j].output_pin, NULL); |
| 1654 | |
| 1655 | i++; |
| 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | /* Add Route from Jack widget to the output widget */ |
| 1660 | ret = snd_soc_dapm_new_controls(dapm, widgets, hdmi->num_ports); |
| 1661 | if (ret < 0) |
| 1662 | return ret; |
| 1663 | |
| 1664 | ret = snd_soc_dapm_add_routes(dapm, route, hdmi->num_ports); |
| 1665 | if (ret < 0) |
| 1666 | return ret; |
| 1667 | |
| 1668 | ret = snd_soc_dapm_new_widgets(dapm->card); |
| 1669 | if (ret < 0) |
| 1670 | return ret; |
| 1671 | |
| 1672 | /* Add Jack Pin switch Kcontrol */ |
| 1673 | ret = create_fill_jack_kcontrols(dapm->card, edev); |
| 1674 | |
| 1675 | if (ret < 0) |
| 1676 | return ret; |
| 1677 | |
| 1678 | /* default set the Jack Pin switch to OFF */ |
| 1679 | list_for_each_entry(pin, &hdmi->pin_list, head) { |
| 1680 | for (j = 0; j < pin->num_ports; j++) |
| 1681 | snd_soc_dapm_disable_pin(pin->ports[j].dapm, |
| 1682 | pin->ports[j].jack_pin); |
| 1683 | } |
| 1684 | |
| 1685 | return 0; |
| 1686 | } |
| 1687 | EXPORT_SYMBOL_GPL(hdac_hdmi_jack_port_init); |
| 1688 | |
Jeeja KP | 6249001 | 2017-02-07 19:09:49 +0530 | [diff] [blame] | 1689 | int hdac_hdmi_jack_init(struct snd_soc_dai *dai, int device, |
| 1690 | struct snd_soc_jack *jack) |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1691 | { |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1692 | struct snd_soc_codec *codec = dai->codec; |
| 1693 | struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec); |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1694 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 1695 | struct hdac_hdmi_pcm *pcm; |
Subhransu S. Prusty | 2889099 | 2016-04-14 10:07:34 +0530 | [diff] [blame] | 1696 | struct snd_pcm *snd_pcm; |
| 1697 | int err; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1698 | |
| 1699 | /* |
| 1700 | * this is a new PCM device, create new pcm and |
| 1701 | * add to the pcm list |
| 1702 | */ |
| 1703 | pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); |
| 1704 | if (!pcm) |
| 1705 | return -ENOMEM; |
| 1706 | pcm->pcm_id = device; |
| 1707 | pcm->cvt = hdmi->dai_map[dai->id].cvt; |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 1708 | pcm->jack_event = 0; |
Jeeja KP | 6249001 | 2017-02-07 19:09:49 +0530 | [diff] [blame] | 1709 | pcm->jack = jack; |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 1710 | mutex_init(&pcm->lock); |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 1711 | INIT_LIST_HEAD(&pcm->port_list); |
Subhransu S. Prusty | 2889099 | 2016-04-14 10:07:34 +0530 | [diff] [blame] | 1712 | snd_pcm = hdac_hdmi_get_pcm_from_id(dai->component->card, device); |
| 1713 | if (snd_pcm) { |
| 1714 | err = snd_hdac_add_chmap_ctls(snd_pcm, device, &hdmi->chmap); |
| 1715 | if (err < 0) { |
| 1716 | dev_err(&edev->hdac.dev, |
| 1717 | "chmap control add failed with err: %d for pcm: %d\n", |
| 1718 | err, device); |
| 1719 | kfree(pcm); |
| 1720 | return err; |
| 1721 | } |
| 1722 | } |
| 1723 | |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1724 | list_add_tail(&pcm->head, &hdmi->pcm_list); |
| 1725 | |
Jeeja KP | 6249001 | 2017-02-07 19:09:49 +0530 | [diff] [blame] | 1726 | return 0; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1727 | } |
| 1728 | EXPORT_SYMBOL_GPL(hdac_hdmi_jack_init); |
| 1729 | |
Jeeja KP | a9ce96b | 2017-02-07 19:09:46 +0530 | [diff] [blame] | 1730 | static void hdac_hdmi_present_sense_all_pins(struct hdac_ext_device *edev, |
| 1731 | struct hdac_hdmi_priv *hdmi, bool detect_pin_caps) |
| 1732 | { |
| 1733 | int i; |
| 1734 | struct hdac_hdmi_pin *pin; |
| 1735 | |
| 1736 | list_for_each_entry(pin, &hdmi->pin_list, head) { |
| 1737 | if (detect_pin_caps) { |
| 1738 | |
| 1739 | if (hdac_hdmi_get_port_len(edev, pin->nid) == 0) |
| 1740 | pin->mst_capable = false; |
| 1741 | else |
| 1742 | pin->mst_capable = true; |
| 1743 | } |
| 1744 | |
| 1745 | for (i = 0; i < pin->num_ports; i++) { |
| 1746 | if (!pin->mst_capable && i > 0) |
| 1747 | continue; |
| 1748 | |
| 1749 | hdac_hdmi_present_sense(pin, &pin->ports[i]); |
| 1750 | } |
| 1751 | } |
| 1752 | } |
| 1753 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1754 | static int hdmi_codec_probe(struct snd_soc_codec *codec) |
| 1755 | { |
| 1756 | struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec); |
| 1757 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 1758 | struct snd_soc_dapm_context *dapm = |
| 1759 | snd_soc_component_get_dapm(&codec->component); |
Vinod Koul | b2047e9 | 2016-05-12 08:58:55 +0530 | [diff] [blame] | 1760 | struct hdac_ext_link *hlink = NULL; |
Jeeja KP | a9ce96b | 2017-02-07 19:09:46 +0530 | [diff] [blame] | 1761 | int ret; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1762 | |
| 1763 | edev->scodec = codec; |
| 1764 | |
Vinod Koul | b2047e9 | 2016-05-12 08:58:55 +0530 | [diff] [blame] | 1765 | /* |
| 1766 | * hold the ref while we probe, also no need to drop the ref on |
| 1767 | * exit, we call pm_runtime_suspend() so that will do for us |
| 1768 | */ |
| 1769 | hlink = snd_hdac_ext_bus_get_link(edev->ebus, dev_name(&edev->hdac.dev)); |
Vinod Koul | 500e06b | 2016-05-31 19:09:55 +0530 | [diff] [blame] | 1770 | if (!hlink) { |
| 1771 | dev_err(&edev->hdac.dev, "hdac link not found\n"); |
| 1772 | return -EIO; |
| 1773 | } |
| 1774 | |
Vinod Koul | b2047e9 | 2016-05-12 08:58:55 +0530 | [diff] [blame] | 1775 | snd_hdac_ext_bus_link_get(edev->ebus, hlink); |
| 1776 | |
Subhransu S. Prusty | 79f4e92 | 2016-02-12 07:46:05 +0530 | [diff] [blame] | 1777 | ret = create_fill_widget_route_map(dapm); |
| 1778 | if (ret < 0) |
| 1779 | return ret; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1780 | |
Subhransu S. Prusty | b8a5454 | 2016-02-12 07:46:01 +0530 | [diff] [blame] | 1781 | aops.audio_ptr = edev; |
| 1782 | ret = snd_hdac_i915_register_notifier(&aops); |
| 1783 | if (ret < 0) { |
| 1784 | dev_err(&edev->hdac.dev, "notifier register failed: err: %d\n", |
| 1785 | ret); |
| 1786 | return ret; |
| 1787 | } |
| 1788 | |
Jeeja KP | a9ce96b | 2017-02-07 19:09:46 +0530 | [diff] [blame] | 1789 | hdac_hdmi_present_sense_all_pins(edev, hdmi, true); |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1790 | /* Imp: Store the card pointer in hda_codec */ |
| 1791 | edev->card = dapm->card->snd_card; |
| 1792 | |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 1793 | /* |
| 1794 | * hdac_device core already sets the state to active and calls |
| 1795 | * get_noresume. So enable runtime and set the device to suspend. |
| 1796 | */ |
| 1797 | pm_runtime_enable(&edev->hdac.dev); |
| 1798 | pm_runtime_put(&edev->hdac.dev); |
| 1799 | pm_runtime_suspend(&edev->hdac.dev); |
| 1800 | |
| 1801 | return 0; |
| 1802 | } |
| 1803 | |
| 1804 | static int hdmi_codec_remove(struct snd_soc_codec *codec) |
| 1805 | { |
| 1806 | struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec); |
| 1807 | |
| 1808 | pm_runtime_disable(&edev->hdac.dev); |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1809 | return 0; |
| 1810 | } |
| 1811 | |
Jeeja KP | 571d507 | 2016-02-22 07:50:33 +0530 | [diff] [blame] | 1812 | #ifdef CONFIG_PM |
Subhransu S. Prusty | 1b377cc | 2016-04-01 13:36:26 +0530 | [diff] [blame] | 1813 | static int hdmi_codec_prepare(struct device *dev) |
| 1814 | { |
| 1815 | struct hdac_ext_device *edev = to_hda_ext_device(dev); |
| 1816 | struct hdac_device *hdac = &edev->hdac; |
| 1817 | |
| 1818 | pm_runtime_get_sync(&edev->hdac.dev); |
| 1819 | |
| 1820 | /* |
| 1821 | * Power down afg. |
| 1822 | * codec_read is preferred over codec_write to set the power state. |
| 1823 | * This way verb is send to set the power state and response |
| 1824 | * is received. So setting power state is ensured without using loop |
| 1825 | * to read the state. |
| 1826 | */ |
| 1827 | snd_hdac_codec_read(hdac, hdac->afg, 0, AC_VERB_SET_POWER_STATE, |
| 1828 | AC_PWRST_D3); |
| 1829 | |
| 1830 | return 0; |
| 1831 | } |
| 1832 | |
Subhransu S. Prusty | 0fee179 | 2016-04-01 13:36:25 +0530 | [diff] [blame] | 1833 | static void hdmi_codec_complete(struct device *dev) |
Jeeja KP | 571d507 | 2016-02-22 07:50:33 +0530 | [diff] [blame] | 1834 | { |
Subhransu S. Prusty | 0fee179 | 2016-04-01 13:36:25 +0530 | [diff] [blame] | 1835 | struct hdac_ext_device *edev = to_hda_ext_device(dev); |
Jeeja KP | 571d507 | 2016-02-22 07:50:33 +0530 | [diff] [blame] | 1836 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
Jeeja KP | 571d507 | 2016-02-22 07:50:33 +0530 | [diff] [blame] | 1837 | struct hdac_device *hdac = &edev->hdac; |
Subhransu S. Prusty | 1b377cc | 2016-04-01 13:36:26 +0530 | [diff] [blame] | 1838 | |
| 1839 | /* Power up afg */ |
| 1840 | snd_hdac_codec_read(hdac, hdac->afg, 0, AC_VERB_SET_POWER_STATE, |
| 1841 | AC_PWRST_D0); |
Jeeja KP | 571d507 | 2016-02-22 07:50:33 +0530 | [diff] [blame] | 1842 | |
| 1843 | hdac_hdmi_skl_enable_all_pins(&edev->hdac); |
| 1844 | hdac_hdmi_skl_enable_dp12(&edev->hdac); |
| 1845 | |
Jeeja KP | 571d507 | 2016-02-22 07:50:33 +0530 | [diff] [blame] | 1846 | /* |
| 1847 | * As the ELD notify callback request is not entertained while the |
| 1848 | * device is in suspend state. Need to manually check detection of |
Jeeja KP | a9ce96b | 2017-02-07 19:09:46 +0530 | [diff] [blame] | 1849 | * all pins here. pin capablity change is not support, so use the |
| 1850 | * already set pin caps. |
Jeeja KP | 571d507 | 2016-02-22 07:50:33 +0530 | [diff] [blame] | 1851 | */ |
Jeeja KP | a9ce96b | 2017-02-07 19:09:46 +0530 | [diff] [blame] | 1852 | hdac_hdmi_present_sense_all_pins(edev, hdmi, false); |
Jeeja KP | 571d507 | 2016-02-22 07:50:33 +0530 | [diff] [blame] | 1853 | |
Subhransu S. Prusty | 1b377cc | 2016-04-01 13:36:26 +0530 | [diff] [blame] | 1854 | pm_runtime_put_sync(&edev->hdac.dev); |
Jeeja KP | 571d507 | 2016-02-22 07:50:33 +0530 | [diff] [blame] | 1855 | } |
| 1856 | #else |
Subhransu S. Prusty | 1b377cc | 2016-04-01 13:36:26 +0530 | [diff] [blame] | 1857 | #define hdmi_codec_prepare NULL |
Subhransu S. Prusty | 0fee179 | 2016-04-01 13:36:25 +0530 | [diff] [blame] | 1858 | #define hdmi_codec_complete NULL |
Jeeja KP | 571d507 | 2016-02-22 07:50:33 +0530 | [diff] [blame] | 1859 | #endif |
| 1860 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1861 | static struct snd_soc_codec_driver hdmi_hda_codec = { |
| 1862 | .probe = hdmi_codec_probe, |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 1863 | .remove = hdmi_codec_remove, |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1864 | .idle_bias_off = true, |
| 1865 | }; |
| 1866 | |
Subhransu S. Prusty | 2889099 | 2016-04-14 10:07:34 +0530 | [diff] [blame] | 1867 | static void hdac_hdmi_get_chmap(struct hdac_device *hdac, int pcm_idx, |
| 1868 | unsigned char *chmap) |
| 1869 | { |
| 1870 | struct hdac_ext_device *edev = to_ehdac_device(hdac); |
| 1871 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 1872 | struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx); |
Subhransu S. Prusty | 2889099 | 2016-04-14 10:07:34 +0530 | [diff] [blame] | 1873 | |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 1874 | memcpy(chmap, pcm->chmap, ARRAY_SIZE(pcm->chmap)); |
Subhransu S. Prusty | 2889099 | 2016-04-14 10:07:34 +0530 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | static void hdac_hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx, |
| 1878 | unsigned char *chmap, int prepared) |
| 1879 | { |
| 1880 | struct hdac_ext_device *edev = to_ehdac_device(hdac); |
| 1881 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 1882 | struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx); |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 1883 | struct hdac_hdmi_port *port; |
| 1884 | |
| 1885 | if (list_empty(&pcm->port_list)) |
| 1886 | return; |
Subhransu S. Prusty | 2889099 | 2016-04-14 10:07:34 +0530 | [diff] [blame] | 1887 | |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 1888 | mutex_lock(&pcm->lock); |
| 1889 | pcm->chmap_set = true; |
| 1890 | memcpy(pcm->chmap, chmap, ARRAY_SIZE(pcm->chmap)); |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 1891 | list_for_each_entry(port, &pcm->port_list, head) |
| 1892 | if (prepared) |
| 1893 | hdac_hdmi_setup_audio_infoframe(edev, pcm, port); |
Jeeja KP | ab1eea1 | 2017-01-24 21:49:05 +0530 | [diff] [blame] | 1894 | mutex_unlock(&pcm->lock); |
Subhransu S. Prusty | 2889099 | 2016-04-14 10:07:34 +0530 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | static bool is_hdac_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx) |
| 1898 | { |
| 1899 | struct hdac_ext_device *edev = to_ehdac_device(hdac); |
| 1900 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 1901 | struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx); |
Subhransu S. Prusty | 2889099 | 2016-04-14 10:07:34 +0530 | [diff] [blame] | 1902 | |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 1903 | if (list_empty(&pcm->port_list)) |
| 1904 | return false; |
| 1905 | |
| 1906 | return true; |
Subhransu S. Prusty | 2889099 | 2016-04-14 10:07:34 +0530 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | static int hdac_hdmi_get_spk_alloc(struct hdac_device *hdac, int pcm_idx) |
| 1910 | { |
| 1911 | struct hdac_ext_device *edev = to_ehdac_device(hdac); |
| 1912 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 1913 | struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx); |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 1914 | struct hdac_hdmi_port *port; |
| 1915 | |
| 1916 | if (list_empty(&pcm->port_list)) |
| 1917 | return 0; |
| 1918 | |
| 1919 | port = list_first_entry(&pcm->port_list, struct hdac_hdmi_port, head); |
| 1920 | |
| 1921 | if (!port) |
| 1922 | return 0; |
Subhransu S. Prusty | 2889099 | 2016-04-14 10:07:34 +0530 | [diff] [blame] | 1923 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1924 | if (!port || !port->eld.eld_valid) |
Subhransu S. Prusty | 2889099 | 2016-04-14 10:07:34 +0530 | [diff] [blame] | 1925 | return 0; |
| 1926 | |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 1927 | return port->eld.info.spk_alloc; |
Subhransu S. Prusty | 2889099 | 2016-04-14 10:07:34 +0530 | [diff] [blame] | 1928 | } |
| 1929 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1930 | static int hdac_hdmi_dev_probe(struct hdac_ext_device *edev) |
| 1931 | { |
| 1932 | struct hdac_device *codec = &edev->hdac; |
| 1933 | struct hdac_hdmi_priv *hdmi_priv; |
Subhransu S. Prusty | 17a42c4 | 2016-02-12 07:46:04 +0530 | [diff] [blame] | 1934 | struct snd_soc_dai_driver *hdmi_dais = NULL; |
Vinod Koul | b2047e9 | 2016-05-12 08:58:55 +0530 | [diff] [blame] | 1935 | struct hdac_ext_link *hlink = NULL; |
Subhransu S. Prusty | 17a42c4 | 2016-02-12 07:46:04 +0530 | [diff] [blame] | 1936 | int num_dais = 0; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1937 | int ret = 0; |
| 1938 | |
Vinod Koul | b2047e9 | 2016-05-12 08:58:55 +0530 | [diff] [blame] | 1939 | /* hold the ref while we probe */ |
| 1940 | hlink = snd_hdac_ext_bus_get_link(edev->ebus, dev_name(&edev->hdac.dev)); |
Vinod Koul | 500e06b | 2016-05-31 19:09:55 +0530 | [diff] [blame] | 1941 | if (!hlink) { |
| 1942 | dev_err(&edev->hdac.dev, "hdac link not found\n"); |
| 1943 | return -EIO; |
| 1944 | } |
| 1945 | |
Vinod Koul | b2047e9 | 2016-05-12 08:58:55 +0530 | [diff] [blame] | 1946 | snd_hdac_ext_bus_link_get(edev->ebus, hlink); |
| 1947 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1948 | hdmi_priv = devm_kzalloc(&codec->dev, sizeof(*hdmi_priv), GFP_KERNEL); |
| 1949 | if (hdmi_priv == NULL) |
| 1950 | return -ENOMEM; |
| 1951 | |
| 1952 | edev->private_data = hdmi_priv; |
Subhransu S. Prusty | bcced70 | 2016-04-14 10:07:30 +0530 | [diff] [blame] | 1953 | snd_hdac_register_chmap_ops(codec, &hdmi_priv->chmap); |
Subhransu S. Prusty | 2889099 | 2016-04-14 10:07:34 +0530 | [diff] [blame] | 1954 | hdmi_priv->chmap.ops.get_chmap = hdac_hdmi_get_chmap; |
| 1955 | hdmi_priv->chmap.ops.set_chmap = hdac_hdmi_set_chmap; |
| 1956 | hdmi_priv->chmap.ops.is_pcm_attached = is_hdac_hdmi_pcm_attached; |
| 1957 | hdmi_priv->chmap.ops.get_spk_alloc = hdac_hdmi_get_spk_alloc; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1958 | |
| 1959 | dev_set_drvdata(&codec->dev, edev); |
| 1960 | |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1961 | INIT_LIST_HEAD(&hdmi_priv->pin_list); |
| 1962 | INIT_LIST_HEAD(&hdmi_priv->cvt_list); |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1963 | INIT_LIST_HEAD(&hdmi_priv->pcm_list); |
| 1964 | mutex_init(&hdmi_priv->pin_mutex); |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1965 | |
Ramesh Babu | aeaccef | 2016-02-17 21:34:01 +0530 | [diff] [blame] | 1966 | /* |
| 1967 | * Turned off in the runtime_suspend during the first explicit |
| 1968 | * pm_runtime_suspend call. |
| 1969 | */ |
| 1970 | ret = snd_hdac_display_power(edev->hdac.bus, true); |
| 1971 | if (ret < 0) { |
| 1972 | dev_err(&edev->hdac.dev, |
| 1973 | "Cannot turn on display power on i915 err: %d\n", |
| 1974 | ret); |
| 1975 | return ret; |
| 1976 | } |
| 1977 | |
Subhransu S. Prusty | 17a42c4 | 2016-02-12 07:46:04 +0530 | [diff] [blame] | 1978 | ret = hdac_hdmi_parse_and_map_nid(edev, &hdmi_dais, &num_dais); |
| 1979 | if (ret < 0) { |
| 1980 | dev_err(&codec->dev, |
| 1981 | "Failed in parse and map nid with err: %d\n", ret); |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1982 | return ret; |
Subhransu S. Prusty | 17a42c4 | 2016-02-12 07:46:04 +0530 | [diff] [blame] | 1983 | } |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1984 | |
| 1985 | /* ASoC specific initialization */ |
Vinod Koul | b2047e9 | 2016-05-12 08:58:55 +0530 | [diff] [blame] | 1986 | ret = snd_soc_register_codec(&codec->dev, &hdmi_hda_codec, |
| 1987 | hdmi_dais, num_dais); |
| 1988 | |
| 1989 | snd_hdac_ext_bus_link_put(edev->ebus, hlink); |
| 1990 | |
| 1991 | return ret; |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | static int hdac_hdmi_dev_remove(struct hdac_ext_device *edev) |
| 1995 | { |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 1996 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 1997 | struct hdac_hdmi_pin *pin, *pin_next; |
| 1998 | struct hdac_hdmi_cvt *cvt, *cvt_next; |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 1999 | struct hdac_hdmi_pcm *pcm, *pcm_next; |
Jeeja KP | 2fe42dd | 2017-03-01 22:41:24 +0530 | [diff] [blame] | 2000 | struct hdac_hdmi_port *port, *port_next; |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 2001 | int i; |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 2002 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 2003 | snd_soc_unregister_codec(&edev->hdac.dev); |
| 2004 | |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 2005 | list_for_each_entry_safe(pcm, pcm_next, &hdmi->pcm_list, head) { |
| 2006 | pcm->cvt = NULL; |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 2007 | if (list_empty(&pcm->port_list)) |
| 2008 | continue; |
| 2009 | |
Jeeja KP | 2fe42dd | 2017-03-01 22:41:24 +0530 | [diff] [blame] | 2010 | list_for_each_entry_safe(port, port_next, |
| 2011 | &pcm->port_list, head) |
| 2012 | list_del(&port->head); |
Jeeja KP | e0e5d3e | 2017-02-07 19:09:48 +0530 | [diff] [blame] | 2013 | |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 2014 | list_del(&pcm->head); |
| 2015 | kfree(pcm); |
| 2016 | } |
| 2017 | |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 2018 | list_for_each_entry_safe(cvt, cvt_next, &hdmi->cvt_list, head) { |
| 2019 | list_del(&cvt->head); |
Jeeja KP | 4a3478d | 2016-02-12 07:46:06 +0530 | [diff] [blame] | 2020 | kfree(cvt->name); |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 2021 | kfree(cvt); |
| 2022 | } |
| 2023 | |
| 2024 | list_for_each_entry_safe(pin, pin_next, &hdmi->pin_list, head) { |
Jeeja KP | 754695f | 2017-02-06 12:09:14 +0530 | [diff] [blame] | 2025 | for (i = 0; i < pin->num_ports; i++) |
| 2026 | pin->ports[i].pin = NULL; |
| 2027 | kfree(pin->ports); |
Subhransu S. Prusty | 15b9144 | 2015-12-09 21:46:10 +0530 | [diff] [blame] | 2028 | list_del(&pin->head); |
| 2029 | kfree(pin); |
| 2030 | } |
| 2031 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 2032 | return 0; |
| 2033 | } |
| 2034 | |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 2035 | #ifdef CONFIG_PM |
| 2036 | static int hdac_hdmi_runtime_suspend(struct device *dev) |
| 2037 | { |
| 2038 | struct hdac_ext_device *edev = to_hda_ext_device(dev); |
| 2039 | struct hdac_device *hdac = &edev->hdac; |
Subhransu S. Prusty | 07f083a | 2015-11-10 18:42:10 +0530 | [diff] [blame] | 2040 | struct hdac_bus *bus = hdac->bus; |
Vinod Koul | b2047e9 | 2016-05-12 08:58:55 +0530 | [diff] [blame] | 2041 | struct hdac_ext_bus *ebus = hbus_to_ebus(bus); |
| 2042 | struct hdac_ext_link *hlink = NULL; |
Subhransu S. Prusty | 07f083a | 2015-11-10 18:42:10 +0530 | [diff] [blame] | 2043 | int err; |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 2044 | |
| 2045 | dev_dbg(dev, "Enter: %s\n", __func__); |
| 2046 | |
Subhransu S. Prusty | 07f083a | 2015-11-10 18:42:10 +0530 | [diff] [blame] | 2047 | /* controller may not have been initialized for the first time */ |
| 2048 | if (!bus) |
| 2049 | return 0; |
| 2050 | |
Subhransu S. Prusty | 1b377cc | 2016-04-01 13:36:26 +0530 | [diff] [blame] | 2051 | /* |
| 2052 | * Power down afg. |
| 2053 | * codec_read is preferred over codec_write to set the power state. |
| 2054 | * This way verb is send to set the power state and response |
| 2055 | * is received. So setting power state is ensured without using loop |
| 2056 | * to read the state. |
| 2057 | */ |
| 2058 | snd_hdac_codec_read(hdac, hdac->afg, 0, AC_VERB_SET_POWER_STATE, |
| 2059 | AC_PWRST_D3); |
Subhransu S. Prusty | 07f083a | 2015-11-10 18:42:10 +0530 | [diff] [blame] | 2060 | err = snd_hdac_display_power(bus, false); |
| 2061 | if (err < 0) { |
| 2062 | dev_err(bus->dev, "Cannot turn on display power on i915\n"); |
| 2063 | return err; |
| 2064 | } |
| 2065 | |
Vinod Koul | b2047e9 | 2016-05-12 08:58:55 +0530 | [diff] [blame] | 2066 | hlink = snd_hdac_ext_bus_get_link(ebus, dev_name(dev)); |
Vinod Koul | 500e06b | 2016-05-31 19:09:55 +0530 | [diff] [blame] | 2067 | if (!hlink) { |
| 2068 | dev_err(dev, "hdac link not found\n"); |
| 2069 | return -EIO; |
| 2070 | } |
| 2071 | |
Vinod Koul | b2047e9 | 2016-05-12 08:58:55 +0530 | [diff] [blame] | 2072 | snd_hdac_ext_bus_link_put(ebus, hlink); |
| 2073 | |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 2074 | return 0; |
| 2075 | } |
| 2076 | |
| 2077 | static int hdac_hdmi_runtime_resume(struct device *dev) |
| 2078 | { |
| 2079 | struct hdac_ext_device *edev = to_hda_ext_device(dev); |
| 2080 | struct hdac_device *hdac = &edev->hdac; |
Subhransu S. Prusty | 07f083a | 2015-11-10 18:42:10 +0530 | [diff] [blame] | 2081 | struct hdac_bus *bus = hdac->bus; |
Vinod Koul | b2047e9 | 2016-05-12 08:58:55 +0530 | [diff] [blame] | 2082 | struct hdac_ext_bus *ebus = hbus_to_ebus(bus); |
| 2083 | struct hdac_ext_link *hlink = NULL; |
Subhransu S. Prusty | 07f083a | 2015-11-10 18:42:10 +0530 | [diff] [blame] | 2084 | int err; |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 2085 | |
| 2086 | dev_dbg(dev, "Enter: %s\n", __func__); |
| 2087 | |
Subhransu S. Prusty | 07f083a | 2015-11-10 18:42:10 +0530 | [diff] [blame] | 2088 | /* controller may not have been initialized for the first time */ |
| 2089 | if (!bus) |
| 2090 | return 0; |
| 2091 | |
Vinod Koul | b2047e9 | 2016-05-12 08:58:55 +0530 | [diff] [blame] | 2092 | hlink = snd_hdac_ext_bus_get_link(ebus, dev_name(dev)); |
Vinod Koul | 500e06b | 2016-05-31 19:09:55 +0530 | [diff] [blame] | 2093 | if (!hlink) { |
| 2094 | dev_err(dev, "hdac link not found\n"); |
| 2095 | return -EIO; |
| 2096 | } |
| 2097 | |
Vinod Koul | b2047e9 | 2016-05-12 08:58:55 +0530 | [diff] [blame] | 2098 | snd_hdac_ext_bus_link_get(ebus, hlink); |
| 2099 | |
Subhransu S. Prusty | 07f083a | 2015-11-10 18:42:10 +0530 | [diff] [blame] | 2100 | err = snd_hdac_display_power(bus, true); |
| 2101 | if (err < 0) { |
| 2102 | dev_err(bus->dev, "Cannot turn on display power on i915\n"); |
| 2103 | return err; |
| 2104 | } |
| 2105 | |
Subhransu S. Prusty | ab85f5b | 2016-02-17 21:34:02 +0530 | [diff] [blame] | 2106 | hdac_hdmi_skl_enable_all_pins(&edev->hdac); |
| 2107 | hdac_hdmi_skl_enable_dp12(&edev->hdac); |
| 2108 | |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 2109 | /* Power up afg */ |
Subhransu S. Prusty | 1b377cc | 2016-04-01 13:36:26 +0530 | [diff] [blame] | 2110 | snd_hdac_codec_read(hdac, hdac->afg, 0, AC_VERB_SET_POWER_STATE, |
| 2111 | AC_PWRST_D0); |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 2112 | |
| 2113 | return 0; |
| 2114 | } |
| 2115 | #else |
| 2116 | #define hdac_hdmi_runtime_suspend NULL |
| 2117 | #define hdac_hdmi_runtime_resume NULL |
| 2118 | #endif |
| 2119 | |
| 2120 | static const struct dev_pm_ops hdac_hdmi_pm = { |
| 2121 | SET_RUNTIME_PM_OPS(hdac_hdmi_runtime_suspend, hdac_hdmi_runtime_resume, NULL) |
Subhransu S. Prusty | 1b377cc | 2016-04-01 13:36:26 +0530 | [diff] [blame] | 2122 | .prepare = hdmi_codec_prepare, |
Subhransu S. Prusty | 0fee179 | 2016-04-01 13:36:25 +0530 | [diff] [blame] | 2123 | .complete = hdmi_codec_complete, |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 2124 | }; |
| 2125 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 2126 | static const struct hda_device_id hdmi_list[] = { |
| 2127 | HDA_CODEC_EXT_ENTRY(0x80862809, 0x100000, "Skylake HDMI", 0), |
Jeeja KP | e230480 | 2016-03-11 10:12:55 +0530 | [diff] [blame] | 2128 | HDA_CODEC_EXT_ENTRY(0x8086280a, 0x100000, "Broxton HDMI", 0), |
Shreyas NC | cc21688 | 2016-07-11 22:02:09 +0530 | [diff] [blame] | 2129 | HDA_CODEC_EXT_ENTRY(0x8086280b, 0x100000, "Kabylake HDMI", 0), |
Vinod Koul | e3efb2a | 2017-02-09 16:44:04 +0530 | [diff] [blame] | 2130 | HDA_CODEC_EXT_ENTRY(0x8086280d, 0x100000, "Geminilake HDMI", 0), |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 2131 | {} |
| 2132 | }; |
| 2133 | |
| 2134 | MODULE_DEVICE_TABLE(hdaudio, hdmi_list); |
| 2135 | |
| 2136 | static struct hdac_ext_driver hdmi_driver = { |
| 2137 | . hdac = { |
| 2138 | .driver = { |
| 2139 | .name = "HDMI HDA Codec", |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 2140 | .pm = &hdac_hdmi_pm, |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 2141 | }, |
| 2142 | .id_table = hdmi_list, |
| 2143 | }, |
| 2144 | .probe = hdac_hdmi_dev_probe, |
| 2145 | .remove = hdac_hdmi_dev_remove, |
| 2146 | }; |
| 2147 | |
| 2148 | static int __init hdmi_init(void) |
| 2149 | { |
| 2150 | return snd_hda_ext_driver_register(&hdmi_driver); |
| 2151 | } |
| 2152 | |
| 2153 | static void __exit hdmi_exit(void) |
| 2154 | { |
| 2155 | snd_hda_ext_driver_unregister(&hdmi_driver); |
| 2156 | } |
| 2157 | |
| 2158 | module_init(hdmi_init); |
| 2159 | module_exit(hdmi_exit); |
| 2160 | |
| 2161 | MODULE_LICENSE("GPL v2"); |
| 2162 | MODULE_DESCRIPTION("HDMI HD codec"); |
| 2163 | MODULE_AUTHOR("Samreen Nilofer<samreen.nilofer@intel.com>"); |
| 2164 | MODULE_AUTHOR("Subhransu S. Prusty<subhransu.s.prusty@intel.com>"); |