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