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