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