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