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