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