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