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