Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) |
| 2 | // |
| 3 | // This file is provided under a dual BSD/GPLv2 license. When using or |
| 4 | // redistributing this file, you may do so under either license. |
| 5 | // |
| 6 | // Copyright(c) 2018 Intel Corporation. All rights reserved. |
| 7 | // |
| 8 | // Authors: Keyon Jie <yang.jie@linux.intel.com> |
| 9 | // |
| 10 | |
| 11 | #include <sound/pcm_params.h> |
| 12 | #include <sound/hdaudio_ext.h> |
| 13 | #include "../sof-priv.h" |
Ranjani Sridharan | ee1e79b | 2019-12-04 15:15:51 -0600 | [diff] [blame] | 14 | #include "../sof-audio.h" |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 15 | #include "hda.h" |
| 16 | |
| 17 | #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) |
| 18 | |
| 19 | struct hda_pipe_params { |
| 20 | u8 host_dma_id; |
| 21 | u8 link_dma_id; |
| 22 | u32 ch; |
| 23 | u32 s_freq; |
| 24 | u32 s_fmt; |
| 25 | u8 linktype; |
| 26 | snd_pcm_format_t format; |
| 27 | int link_index; |
| 28 | int stream; |
| 29 | unsigned int host_bps; |
| 30 | unsigned int link_bps; |
| 31 | }; |
| 32 | |
| 33 | /* |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 34 | * This function checks if the host dma channel corresponding |
| 35 | * to the link DMA stream_tag argument is assigned to one |
| 36 | * of the FEs connected to the BE DAI. |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 37 | */ |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 38 | static bool hda_check_fes(struct snd_soc_pcm_runtime *rtd, |
| 39 | int dir, int stream_tag) |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 40 | { |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 41 | struct snd_pcm_substream *fe_substream; |
| 42 | struct hdac_stream *fe_hstream; |
| 43 | struct snd_soc_dpcm *dpcm; |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 44 | |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 45 | for_each_dpcm_fe(rtd, dir, dpcm) { |
| 46 | fe_substream = snd_soc_dpcm_get_substream(dpcm->fe, dir); |
| 47 | fe_hstream = fe_substream->runtime->private_data; |
| 48 | if (fe_hstream->stream_tag == stream_tag) |
| 49 | return true; |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 50 | } |
| 51 | |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 52 | return false; |
| 53 | } |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 54 | |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 55 | static struct hdac_ext_stream * |
| 56 | hda_link_stream_assign(struct hdac_bus *bus, |
| 57 | struct snd_pcm_substream *substream) |
| 58 | { |
| 59 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 60 | struct sof_intel_hda_stream *hda_stream; |
| 61 | struct hdac_ext_stream *res = NULL; |
| 62 | struct hdac_stream *stream = NULL; |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 63 | |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 64 | int stream_dir = substream->stream; |
| 65 | |
| 66 | if (!bus->ppcap) { |
| 67 | dev_err(bus->dev, "stream type not supported\n"); |
| 68 | return NULL; |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 69 | } |
| 70 | |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 71 | list_for_each_entry(stream, &bus->stream_list, list) { |
| 72 | struct hdac_ext_stream *hstream = |
| 73 | stream_to_hdac_ext_stream(stream); |
| 74 | if (stream->direction != substream->stream) |
| 75 | continue; |
| 76 | |
| 77 | hda_stream = hstream_to_sof_hda_stream(hstream); |
| 78 | |
Ranjani Sridharan | 6b2239e | 2019-06-12 12:23:37 -0500 | [diff] [blame] | 79 | /* check if link is available */ |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 80 | if (!hstream->link_locked) { |
| 81 | if (stream->opened) { |
| 82 | /* |
| 83 | * check if the stream tag matches the stream |
| 84 | * tag of one of the connected FEs |
| 85 | */ |
| 86 | if (hda_check_fes(rtd, stream_dir, |
| 87 | stream->stream_tag)) { |
| 88 | res = hstream; |
| 89 | break; |
| 90 | } |
| 91 | } else { |
| 92 | res = hstream; |
Ranjani Sridharan | 6b2239e | 2019-06-12 12:23:37 -0500 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * This must be a hostless stream. |
| 96 | * So reserve the host DMA channel. |
| 97 | */ |
| 98 | hda_stream->host_reserved = 1; |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 99 | break; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | if (res) { |
| 105 | /* |
| 106 | * Decouple host and link DMA. The decoupled flag |
| 107 | * is updated in snd_hdac_ext_stream_decouple(). |
| 108 | */ |
| 109 | if (!res->decoupled) |
| 110 | snd_hdac_ext_stream_decouple(bus, res, true); |
| 111 | spin_lock_irq(&bus->reg_lock); |
| 112 | res->link_locked = 1; |
| 113 | res->link_substream = substream; |
| 114 | spin_unlock_irq(&bus->reg_lock); |
| 115 | } |
| 116 | |
| 117 | return res; |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | static int hda_link_dma_params(struct hdac_ext_stream *stream, |
| 121 | struct hda_pipe_params *params) |
| 122 | { |
| 123 | struct hdac_stream *hstream = &stream->hstream; |
| 124 | unsigned char stream_tag = hstream->stream_tag; |
| 125 | struct hdac_bus *bus = hstream->bus; |
| 126 | struct hdac_ext_link *link; |
| 127 | unsigned int format_val; |
| 128 | |
| 129 | snd_hdac_ext_stream_decouple(bus, stream, true); |
| 130 | snd_hdac_ext_link_stream_reset(stream); |
| 131 | |
| 132 | format_val = snd_hdac_calc_stream_format(params->s_freq, params->ch, |
| 133 | params->format, |
| 134 | params->link_bps, 0); |
| 135 | |
| 136 | dev_dbg(bus->dev, "format_val=%d, rate=%d, ch=%d, format=%d\n", |
| 137 | format_val, params->s_freq, params->ch, params->format); |
| 138 | |
| 139 | snd_hdac_ext_link_stream_setup(stream, format_val); |
| 140 | |
| 141 | if (stream->hstream.direction == SNDRV_PCM_STREAM_PLAYBACK) { |
| 142 | list_for_each_entry(link, &bus->hlink_list, list) { |
| 143 | if (link->index == params->link_index) |
| 144 | snd_hdac_ext_link_set_stream_id(link, |
| 145 | stream_tag); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | stream->link_prepared = 1; |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 154 | /* Send DAI_CONFIG IPC to the DAI that matches the dai_name and direction */ |
| 155 | static int hda_link_config_ipc(struct sof_intel_hda_stream *hda_stream, |
| 156 | const char *dai_name, int channel, int dir) |
| 157 | { |
| 158 | struct sof_ipc_dai_config *config; |
| 159 | struct snd_sof_dai *sof_dai; |
| 160 | struct sof_ipc_reply reply; |
| 161 | int ret = 0; |
| 162 | |
| 163 | list_for_each_entry(sof_dai, &hda_stream->sdev->dai_list, list) { |
| 164 | if (!sof_dai->cpu_dai_name) |
| 165 | continue; |
| 166 | |
| 167 | if (!strcmp(dai_name, sof_dai->cpu_dai_name) && |
| 168 | dir == sof_dai->comp_dai.direction) { |
| 169 | config = sof_dai->dai_config; |
| 170 | |
| 171 | if (!config) { |
| 172 | dev_err(hda_stream->sdev->dev, |
| 173 | "error: no config for DAI %s\n", |
| 174 | sof_dai->name); |
| 175 | return -EINVAL; |
| 176 | } |
| 177 | |
| 178 | /* update config with stream tag */ |
| 179 | config->hda.link_dma_ch = channel; |
| 180 | |
| 181 | /* send IPC */ |
| 182 | ret = sof_ipc_tx_message(hda_stream->sdev->ipc, |
| 183 | config->hdr.cmd, |
| 184 | config, |
| 185 | config->hdr.size, |
| 186 | &reply, sizeof(reply)); |
| 187 | |
| 188 | if (ret < 0) |
| 189 | dev_err(hda_stream->sdev->dev, |
| 190 | "error: failed to set dai config for %s\n", |
| 191 | sof_dai->name); |
| 192 | return ret; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | return -EINVAL; |
| 197 | } |
| 198 | |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 199 | static int hda_link_hw_params(struct snd_pcm_substream *substream, |
| 200 | struct snd_pcm_hw_params *params, |
| 201 | struct snd_soc_dai *dai) |
| 202 | { |
| 203 | struct hdac_stream *hstream = substream->runtime->private_data; |
| 204 | struct hdac_bus *bus = hstream->bus; |
| 205 | struct hdac_ext_stream *link_dev; |
| 206 | struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream); |
Kuninori Morimoto | be3e8de | 2020-03-23 14:20:37 +0900 | [diff] [blame] | 207 | struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
Ranjani Sridharan | ed3baac | 2019-04-30 18:09:31 -0500 | [diff] [blame] | 208 | struct sof_intel_hda_stream *hda_stream; |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 209 | struct hda_pipe_params p_params = {0}; |
| 210 | struct hdac_ext_link *link; |
| 211 | int stream_tag; |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 212 | int ret; |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 213 | |
Rander Wang | 934bf82 | 2019-07-22 09:13:59 -0500 | [diff] [blame] | 214 | /* get stored dma data if resuming from system suspend */ |
| 215 | link_dev = snd_soc_dai_get_dma_data(dai, substream); |
| 216 | if (!link_dev) { |
| 217 | link_dev = hda_link_stream_assign(bus, substream); |
| 218 | if (!link_dev) |
| 219 | return -EBUSY; |
Pierre-Louis Bossart | 921162c | 2019-12-17 18:05:17 -0600 | [diff] [blame] | 220 | |
| 221 | snd_soc_dai_set_dma_data(dai, substream, (void *)link_dev); |
Rander Wang | 934bf82 | 2019-07-22 09:13:59 -0500 | [diff] [blame] | 222 | } |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 223 | |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 224 | stream_tag = hdac_stream(link_dev)->stream_tag; |
| 225 | |
| 226 | hda_stream = hstream_to_sof_hda_stream(link_dev); |
| 227 | |
| 228 | /* update the DSP with the new tag */ |
| 229 | ret = hda_link_config_ipc(hda_stream, dai->name, stream_tag - 1, |
| 230 | substream->stream); |
| 231 | if (ret < 0) |
| 232 | return ret; |
| 233 | |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 234 | link = snd_hdac_ext_bus_get_link(bus, codec_dai->component->name); |
| 235 | if (!link) |
| 236 | return -EINVAL; |
| 237 | |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 238 | /* set the stream tag in the codec dai dma params */ |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 239 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 240 | snd_soc_dai_set_tdm_slot(codec_dai, stream_tag, 0, 0, 0); |
| 241 | else |
| 242 | snd_soc_dai_set_tdm_slot(codec_dai, 0, stream_tag, 0, 0); |
| 243 | |
| 244 | p_params.s_fmt = snd_pcm_format_width(params_format(params)); |
| 245 | p_params.ch = params_channels(params); |
| 246 | p_params.s_freq = params_rate(params); |
| 247 | p_params.stream = substream->stream; |
| 248 | p_params.link_dma_id = stream_tag - 1; |
| 249 | p_params.link_index = link->index; |
| 250 | p_params.format = params_format(params); |
| 251 | |
| 252 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 253 | p_params.link_bps = codec_dai->driver->playback.sig_bits; |
| 254 | else |
| 255 | p_params.link_bps = codec_dai->driver->capture.sig_bits; |
| 256 | |
| 257 | return hda_link_dma_params(link_dev, &p_params); |
| 258 | } |
| 259 | |
| 260 | static int hda_link_pcm_prepare(struct snd_pcm_substream *substream, |
| 261 | struct snd_soc_dai *dai) |
| 262 | { |
Ranjani Sridharan | ed3baac | 2019-04-30 18:09:31 -0500 | [diff] [blame] | 263 | struct hdac_ext_stream *link_dev = |
| 264 | snd_soc_dai_get_dma_data(dai, substream); |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 265 | struct snd_sof_dev *sdev = |
Ranjani Sridharan | ed3baac | 2019-04-30 18:09:31 -0500 | [diff] [blame] | 266 | snd_soc_component_get_drvdata(dai->component); |
| 267 | struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream); |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 268 | int stream = substream->stream; |
| 269 | |
Kai Vehmanen | a3ebccb | 2019-07-22 09:13:58 -0500 | [diff] [blame] | 270 | if (link_dev->link_prepared) |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 271 | return 0; |
| 272 | |
Ranjani Sridharan | ed3baac | 2019-04-30 18:09:31 -0500 | [diff] [blame] | 273 | dev_dbg(sdev->dev, "hda: prepare stream dir %d\n", substream->stream); |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 274 | |
| 275 | return hda_link_hw_params(substream, &rtd->dpcm[stream].hw_params, |
| 276 | dai); |
| 277 | } |
| 278 | |
| 279 | static int hda_link_pcm_trigger(struct snd_pcm_substream *substream, |
| 280 | int cmd, struct snd_soc_dai *dai) |
| 281 | { |
| 282 | struct hdac_ext_stream *link_dev = |
| 283 | snd_soc_dai_get_dma_data(dai, substream); |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 284 | struct sof_intel_hda_stream *hda_stream; |
| 285 | struct snd_soc_pcm_runtime *rtd; |
| 286 | struct hdac_ext_link *link; |
| 287 | struct hdac_stream *hstream; |
| 288 | struct hdac_bus *bus; |
| 289 | int stream_tag; |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 290 | int ret; |
| 291 | |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 292 | hstream = substream->runtime->private_data; |
| 293 | bus = hstream->bus; |
| 294 | rtd = snd_pcm_substream_chip(substream); |
| 295 | |
Kuninori Morimoto | be3e8de | 2020-03-23 14:20:37 +0900 | [diff] [blame] | 296 | link = snd_hdac_ext_bus_get_link(bus, asoc_rtd_to_codec(rtd, 0)->component->name); |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 297 | if (!link) |
| 298 | return -EINVAL; |
| 299 | |
| 300 | hda_stream = hstream_to_sof_hda_stream(link_dev); |
| 301 | |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 302 | dev_dbg(dai->dev, "In %s cmd=%d\n", __func__, cmd); |
| 303 | switch (cmd) { |
| 304 | case SNDRV_PCM_TRIGGER_RESUME: |
| 305 | /* set up hw_params */ |
| 306 | ret = hda_link_pcm_prepare(substream, dai); |
| 307 | if (ret < 0) { |
| 308 | dev_err(dai->dev, |
| 309 | "error: setting up hw_params during resume\n"); |
| 310 | return ret; |
| 311 | } |
| 312 | |
| 313 | /* fallthrough */ |
| 314 | case SNDRV_PCM_TRIGGER_START: |
| 315 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 316 | snd_hdac_ext_link_stream_start(link_dev); |
| 317 | break; |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 318 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Kai Vehmanen | a3ebccb | 2019-07-22 09:13:58 -0500 | [diff] [blame] | 319 | case SNDRV_PCM_TRIGGER_STOP: |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 320 | /* |
Rander Wang | 934bf82 | 2019-07-22 09:13:59 -0500 | [diff] [blame] | 321 | * clear link DMA channel. It will be assigned when |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 322 | * hw_params is set up again after resume. |
| 323 | */ |
| 324 | ret = hda_link_config_ipc(hda_stream, dai->name, |
| 325 | DMA_CHAN_INVALID, substream->stream); |
| 326 | if (ret < 0) |
| 327 | return ret; |
Rander Wang | 810dbea | 2019-07-22 09:14:00 -0500 | [diff] [blame] | 328 | |
| 329 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 330 | stream_tag = hdac_stream(link_dev)->stream_tag; |
| 331 | snd_hdac_ext_link_clear_stream_id(link, stream_tag); |
| 332 | } |
| 333 | |
Kai Vehmanen | a3ebccb | 2019-07-22 09:13:58 -0500 | [diff] [blame] | 334 | link_dev->link_prepared = 0; |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 335 | |
| 336 | /* fallthrough */ |
| 337 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 338 | snd_hdac_ext_link_stream_clear(link_dev); |
| 339 | break; |
| 340 | default: |
| 341 | return -EINVAL; |
| 342 | } |
| 343 | return 0; |
| 344 | } |
| 345 | |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 346 | static int hda_link_hw_free(struct snd_pcm_substream *substream, |
| 347 | struct snd_soc_dai *dai) |
| 348 | { |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 349 | unsigned int stream_tag; |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 350 | struct sof_intel_hda_stream *hda_stream; |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 351 | struct hdac_bus *bus; |
| 352 | struct hdac_ext_link *link; |
| 353 | struct hdac_stream *hstream; |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 354 | struct snd_soc_pcm_runtime *rtd; |
| 355 | struct hdac_ext_stream *link_dev; |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 356 | int ret; |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 357 | |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 358 | hstream = substream->runtime->private_data; |
| 359 | bus = hstream->bus; |
| 360 | rtd = snd_pcm_substream_chip(substream); |
| 361 | link_dev = snd_soc_dai_get_dma_data(dai, substream); |
Pierre-Louis Bossart | 921162c | 2019-12-17 18:05:17 -0600 | [diff] [blame] | 362 | |
| 363 | if (!link_dev) { |
| 364 | dev_dbg(dai->dev, |
| 365 | "%s: link_dev is not assigned\n", __func__); |
| 366 | return -EINVAL; |
| 367 | } |
| 368 | |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 369 | hda_stream = hstream_to_sof_hda_stream(link_dev); |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 370 | |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 371 | /* free the link DMA channel in the FW */ |
| 372 | ret = hda_link_config_ipc(hda_stream, dai->name, DMA_CHAN_INVALID, |
| 373 | substream->stream); |
| 374 | if (ret < 0) |
| 375 | return ret; |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 376 | |
Kuninori Morimoto | be3e8de | 2020-03-23 14:20:37 +0900 | [diff] [blame] | 377 | link = snd_hdac_ext_bus_get_link(bus, asoc_rtd_to_codec(rtd, 0)->component->name); |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 378 | if (!link) |
| 379 | return -EINVAL; |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 380 | |
Rander Wang | 810dbea | 2019-07-22 09:14:00 -0500 | [diff] [blame] | 381 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 382 | stream_tag = hdac_stream(link_dev)->stream_tag; |
| 383 | snd_hdac_ext_link_clear_stream_id(link, stream_tag); |
| 384 | } |
| 385 | |
Rander Wang | 934bf82 | 2019-07-22 09:13:59 -0500 | [diff] [blame] | 386 | snd_soc_dai_set_dma_data(dai, substream, NULL); |
Ranjani Sridharan | bdf4ad3f | 2019-06-12 12:23:36 -0500 | [diff] [blame] | 387 | snd_hdac_ext_stream_release(link_dev, HDAC_EXT_STREAM_TYPE_LINK); |
| 388 | link_dev->link_prepared = 0; |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 389 | |
Ranjani Sridharan | 6b2239e | 2019-06-12 12:23:37 -0500 | [diff] [blame] | 390 | /* free the host DMA channel reserved by hostless streams */ |
| 391 | hda_stream->host_reserved = 0; |
| 392 | |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | static const struct snd_soc_dai_ops hda_link_dai_ops = { |
| 397 | .hw_params = hda_link_hw_params, |
| 398 | .hw_free = hda_link_hw_free, |
| 399 | .trigger = hda_link_pcm_trigger, |
| 400 | .prepare = hda_link_pcm_prepare, |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 401 | }; |
Cezary Rojewski | 7036810 | 2020-02-18 15:39:24 +0100 | [diff] [blame] | 402 | |
| 403 | #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_PROBES) |
| 404 | #include "../compress.h" |
| 405 | |
| 406 | static struct snd_soc_cdai_ops sof_probe_compr_ops = { |
| 407 | .startup = sof_probe_compr_open, |
| 408 | .shutdown = sof_probe_compr_free, |
| 409 | .set_params = sof_probe_compr_set_params, |
| 410 | .trigger = sof_probe_compr_trigger, |
| 411 | .pointer = sof_probe_compr_pointer, |
| 412 | }; |
| 413 | |
| 414 | #endif |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 415 | #endif |
| 416 | |
| 417 | /* |
| 418 | * common dai driver for skl+ platforms. |
| 419 | * some products who use this DAI array only physically have a subset of |
| 420 | * the DAIs, but no harm is done here by adding the whole set. |
| 421 | */ |
| 422 | struct snd_soc_dai_driver skl_dai[] = { |
| 423 | { |
| 424 | .name = "SSP0 Pin", |
Bard Liao | e81d47e | 2020-03-12 15:06:17 -0500 | [diff] [blame] | 425 | .playback = { |
| 426 | .channels_min = 1, |
| 427 | .channels_max = 8, |
| 428 | }, |
| 429 | .capture = { |
| 430 | .channels_min = 1, |
| 431 | .channels_max = 8, |
| 432 | }, |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 433 | }, |
| 434 | { |
| 435 | .name = "SSP1 Pin", |
Bard Liao | e81d47e | 2020-03-12 15:06:17 -0500 | [diff] [blame] | 436 | .playback = { |
| 437 | .channels_min = 1, |
| 438 | .channels_max = 8, |
| 439 | }, |
| 440 | .capture = { |
| 441 | .channels_min = 1, |
| 442 | .channels_max = 8, |
| 443 | }, |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 444 | }, |
| 445 | { |
| 446 | .name = "SSP2 Pin", |
Bard Liao | e81d47e | 2020-03-12 15:06:17 -0500 | [diff] [blame] | 447 | .playback = { |
| 448 | .channels_min = 1, |
| 449 | .channels_max = 8, |
| 450 | }, |
| 451 | .capture = { |
| 452 | .channels_min = 1, |
| 453 | .channels_max = 8, |
| 454 | }, |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 455 | }, |
| 456 | { |
| 457 | .name = "SSP3 Pin", |
Bard Liao | e81d47e | 2020-03-12 15:06:17 -0500 | [diff] [blame] | 458 | .playback = { |
| 459 | .channels_min = 1, |
| 460 | .channels_max = 8, |
| 461 | }, |
| 462 | .capture = { |
| 463 | .channels_min = 1, |
| 464 | .channels_max = 8, |
| 465 | }, |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 466 | }, |
| 467 | { |
| 468 | .name = "SSP4 Pin", |
Bard Liao | e81d47e | 2020-03-12 15:06:17 -0500 | [diff] [blame] | 469 | .playback = { |
| 470 | .channels_min = 1, |
| 471 | .channels_max = 8, |
| 472 | }, |
| 473 | .capture = { |
| 474 | .channels_min = 1, |
| 475 | .channels_max = 8, |
| 476 | }, |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 477 | }, |
| 478 | { |
| 479 | .name = "SSP5 Pin", |
Bard Liao | e81d47e | 2020-03-12 15:06:17 -0500 | [diff] [blame] | 480 | .playback = { |
| 481 | .channels_min = 1, |
| 482 | .channels_max = 8, |
| 483 | }, |
| 484 | .capture = { |
| 485 | .channels_min = 1, |
| 486 | .channels_max = 8, |
| 487 | }, |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 488 | }, |
| 489 | { |
| 490 | .name = "DMIC01 Pin", |
Bard Liao | e81d47e | 2020-03-12 15:06:17 -0500 | [diff] [blame] | 491 | .capture = { |
| 492 | .channels_min = 1, |
| 493 | .channels_max = 4, |
| 494 | }, |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 495 | }, |
| 496 | { |
| 497 | .name = "DMIC16k Pin", |
Bard Liao | e81d47e | 2020-03-12 15:06:17 -0500 | [diff] [blame] | 498 | .capture = { |
| 499 | .channels_min = 1, |
| 500 | .channels_max = 4, |
| 501 | }, |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 502 | }, |
| 503 | #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) |
| 504 | { |
| 505 | .name = "iDisp1 Pin", |
| 506 | .ops = &hda_link_dai_ops, |
Bard Liao | e81d47e | 2020-03-12 15:06:17 -0500 | [diff] [blame] | 507 | .playback = { |
| 508 | .channels_min = 1, |
| 509 | .channels_max = 8, |
| 510 | }, |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 511 | }, |
| 512 | { |
| 513 | .name = "iDisp2 Pin", |
| 514 | .ops = &hda_link_dai_ops, |
Bard Liao | e81d47e | 2020-03-12 15:06:17 -0500 | [diff] [blame] | 515 | .playback = { |
| 516 | .channels_min = 1, |
| 517 | .channels_max = 8, |
| 518 | }, |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 519 | }, |
| 520 | { |
| 521 | .name = "iDisp3 Pin", |
| 522 | .ops = &hda_link_dai_ops, |
Bard Liao | e81d47e | 2020-03-12 15:06:17 -0500 | [diff] [blame] | 523 | .playback = { |
| 524 | .channels_min = 1, |
| 525 | .channels_max = 8, |
| 526 | }, |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 527 | }, |
| 528 | { |
Sathyanarayana Nujella | e68d669 | 2019-12-20 11:10:36 -0600 | [diff] [blame] | 529 | .name = "iDisp4 Pin", |
| 530 | .ops = &hda_link_dai_ops, |
Bard Liao | e81d47e | 2020-03-12 15:06:17 -0500 | [diff] [blame] | 531 | .playback = { |
| 532 | .channels_min = 1, |
| 533 | .channels_max = 8, |
| 534 | }, |
Sathyanarayana Nujella | e68d669 | 2019-12-20 11:10:36 -0600 | [diff] [blame] | 535 | }, |
| 536 | { |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 537 | .name = "Analog CPU DAI", |
| 538 | .ops = &hda_link_dai_ops, |
Bard Liao | e81d47e | 2020-03-12 15:06:17 -0500 | [diff] [blame] | 539 | .playback = { |
| 540 | .channels_min = 1, |
| 541 | .channels_max = 16, |
| 542 | }, |
| 543 | .capture = { |
| 544 | .channels_min = 1, |
| 545 | .channels_max = 16, |
| 546 | }, |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 547 | }, |
| 548 | { |
| 549 | .name = "Digital CPU DAI", |
| 550 | .ops = &hda_link_dai_ops, |
Bard Liao | e81d47e | 2020-03-12 15:06:17 -0500 | [diff] [blame] | 551 | .playback = { |
| 552 | .channels_min = 1, |
| 553 | .channels_max = 16, |
| 554 | }, |
| 555 | .capture = { |
| 556 | .channels_min = 1, |
| 557 | .channels_max = 16, |
| 558 | }, |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 559 | }, |
| 560 | { |
| 561 | .name = "Alt Analog CPU DAI", |
| 562 | .ops = &hda_link_dai_ops, |
Bard Liao | e81d47e | 2020-03-12 15:06:17 -0500 | [diff] [blame] | 563 | .playback = { |
| 564 | .channels_min = 1, |
| 565 | .channels_max = 16, |
| 566 | }, |
| 567 | .capture = { |
| 568 | .channels_min = 1, |
| 569 | .channels_max = 16, |
| 570 | }, |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 571 | }, |
Cezary Rojewski | 7036810 | 2020-02-18 15:39:24 +0100 | [diff] [blame] | 572 | #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_PROBES) |
| 573 | { |
| 574 | .name = "Probe Extraction CPU DAI", |
| 575 | .compress_new = snd_soc_new_compress, |
| 576 | .cops = &sof_probe_compr_ops, |
| 577 | .capture = { |
| 578 | .stream_name = "Probe Extraction", |
| 579 | .channels_min = 1, |
| 580 | .channels_max = 8, |
| 581 | .rates = SNDRV_PCM_RATE_48000, |
| 582 | .rate_min = 48000, |
| 583 | .rate_max = 48000, |
| 584 | }, |
| 585 | }, |
| 586 | #endif |
Keyon Jie | fdd961e | 2019-04-12 11:08:57 -0500 | [diff] [blame] | 587 | #endif |
| 588 | }; |