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