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