b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | /* |
| 3 | * skl-pcm.c -ASoC HDA Platform driver file implementing PCM functionality |
| 4 | * |
| 5 | * Copyright (C) 2014-2015 Intel Corp |
| 6 | * Author: Jeeja KP <jeeja.kp@intel.com> |
| 7 | * |
| 8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 9 | * |
| 10 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11 | */ |
| 12 | |
| 13 | #include <linux/pci.h> |
| 14 | #include <linux/pm_runtime.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <sound/pcm_params.h> |
| 17 | #include <sound/soc.h> |
| 18 | #include "skl.h" |
| 19 | #include "skl-topology.h" |
| 20 | #include "skl-sst-dsp.h" |
| 21 | #include "skl-sst-ipc.h" |
| 22 | |
| 23 | #define HDA_MONO 1 |
| 24 | #define HDA_STEREO 2 |
| 25 | #define HDA_QUAD 4 |
| 26 | #define HDA_MAX 8 |
| 27 | |
| 28 | static const struct snd_pcm_hardware azx_pcm_hw = { |
| 29 | .info = (SNDRV_PCM_INFO_MMAP | |
| 30 | SNDRV_PCM_INFO_INTERLEAVED | |
| 31 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 32 | SNDRV_PCM_INFO_MMAP_VALID | |
| 33 | SNDRV_PCM_INFO_PAUSE | |
| 34 | SNDRV_PCM_INFO_RESUME | |
| 35 | SNDRV_PCM_INFO_SYNC_START | |
| 36 | SNDRV_PCM_INFO_HAS_WALL_CLOCK | /* legacy */ |
| 37 | SNDRV_PCM_INFO_HAS_LINK_ATIME | |
| 38 | SNDRV_PCM_INFO_NO_PERIOD_WAKEUP), |
| 39 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 40 | SNDRV_PCM_FMTBIT_S32_LE | |
| 41 | SNDRV_PCM_FMTBIT_S24_LE, |
| 42 | .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000 | |
| 43 | SNDRV_PCM_RATE_8000, |
| 44 | .rate_min = 8000, |
| 45 | .rate_max = 48000, |
| 46 | .channels_min = 1, |
| 47 | .channels_max = 8, |
| 48 | .buffer_bytes_max = AZX_MAX_BUF_SIZE, |
| 49 | .period_bytes_min = 128, |
| 50 | .period_bytes_max = AZX_MAX_BUF_SIZE / 2, |
| 51 | .periods_min = 2, |
| 52 | .periods_max = AZX_MAX_FRAG, |
| 53 | .fifo_size = 0, |
| 54 | }; |
| 55 | |
| 56 | static inline |
| 57 | struct hdac_ext_stream *get_hdac_ext_stream(struct snd_pcm_substream *substream) |
| 58 | { |
| 59 | return substream->runtime->private_data; |
| 60 | } |
| 61 | |
| 62 | static struct hdac_bus *get_bus_ctx(struct snd_pcm_substream *substream) |
| 63 | { |
| 64 | struct hdac_ext_stream *stream = get_hdac_ext_stream(substream); |
| 65 | struct hdac_stream *hstream = hdac_stream(stream); |
| 66 | struct hdac_bus *bus = hstream->bus; |
| 67 | return bus; |
| 68 | } |
| 69 | |
| 70 | static int skl_substream_alloc_pages(struct hdac_bus *bus, |
| 71 | struct snd_pcm_substream *substream, |
| 72 | size_t size) |
| 73 | { |
| 74 | struct hdac_ext_stream *stream = get_hdac_ext_stream(substream); |
| 75 | |
| 76 | hdac_stream(stream)->bufsize = 0; |
| 77 | hdac_stream(stream)->period_bytes = 0; |
| 78 | hdac_stream(stream)->format_val = 0; |
| 79 | |
| 80 | return snd_pcm_lib_malloc_pages(substream, size); |
| 81 | } |
| 82 | |
| 83 | static int skl_substream_free_pages(struct hdac_bus *bus, |
| 84 | struct snd_pcm_substream *substream) |
| 85 | { |
| 86 | return snd_pcm_lib_free_pages(substream); |
| 87 | } |
| 88 | |
| 89 | static void skl_set_pcm_constrains(struct hdac_bus *bus, |
| 90 | struct snd_pcm_runtime *runtime) |
| 91 | { |
| 92 | snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); |
| 93 | |
| 94 | /* avoid wrap-around with wall-clock */ |
| 95 | snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_TIME, |
| 96 | 20, 178000000); |
| 97 | } |
| 98 | |
| 99 | static enum hdac_ext_stream_type skl_get_host_stream_type(struct hdac_bus *bus) |
| 100 | { |
| 101 | if (bus->ppcap) |
| 102 | return HDAC_EXT_STREAM_TYPE_HOST; |
| 103 | else |
| 104 | return HDAC_EXT_STREAM_TYPE_COUPLED; |
| 105 | } |
| 106 | |
| 107 | /* |
| 108 | * check if the stream opened is marked as ignore_suspend by machine, if so |
| 109 | * then enable suspend_active refcount |
| 110 | * |
| 111 | * The count supend_active does not need lock as it is used in open/close |
| 112 | * and suspend context |
| 113 | */ |
| 114 | static void skl_set_suspend_active(struct snd_pcm_substream *substream, |
| 115 | struct snd_soc_dai *dai, bool enable) |
| 116 | { |
| 117 | struct hdac_bus *bus = dev_get_drvdata(dai->dev); |
| 118 | struct snd_soc_dapm_widget *w; |
| 119 | struct skl_dev *skl = bus_to_skl(bus); |
| 120 | |
| 121 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 122 | w = dai->playback_widget; |
| 123 | else |
| 124 | w = dai->capture_widget; |
| 125 | |
| 126 | if (w->ignore_suspend && enable) |
| 127 | skl->supend_active++; |
| 128 | else if (w->ignore_suspend && !enable) |
| 129 | skl->supend_active--; |
| 130 | } |
| 131 | |
| 132 | int skl_pcm_host_dma_prepare(struct device *dev, struct skl_pipe_params *params) |
| 133 | { |
| 134 | struct hdac_bus *bus = dev_get_drvdata(dev); |
| 135 | struct skl_dev *skl = bus_to_skl(bus); |
| 136 | unsigned int format_val; |
| 137 | struct hdac_stream *hstream; |
| 138 | struct hdac_ext_stream *stream; |
| 139 | int err; |
| 140 | |
| 141 | hstream = snd_hdac_get_stream(bus, params->stream, |
| 142 | params->host_dma_id + 1); |
| 143 | if (!hstream) |
| 144 | return -EINVAL; |
| 145 | |
| 146 | stream = stream_to_hdac_ext_stream(hstream); |
| 147 | snd_hdac_ext_stream_decouple(bus, stream, true); |
| 148 | |
| 149 | format_val = snd_hdac_calc_stream_format(params->s_freq, |
| 150 | params->ch, params->format, params->host_bps, 0); |
| 151 | |
| 152 | dev_dbg(dev, "format_val=%d, rate=%d, ch=%d, format=%d\n", |
| 153 | format_val, params->s_freq, params->ch, params->format); |
| 154 | |
| 155 | snd_hdac_stream_reset(hdac_stream(stream)); |
| 156 | err = snd_hdac_stream_set_params(hdac_stream(stream), format_val); |
| 157 | if (err < 0) |
| 158 | return err; |
| 159 | |
| 160 | /* |
| 161 | * The recommended SDxFMT programming sequence for BXT |
| 162 | * platforms is to couple the stream before writing the format |
| 163 | */ |
| 164 | if (IS_BXT(skl->pci)) { |
| 165 | snd_hdac_ext_stream_decouple(bus, stream, false); |
| 166 | err = snd_hdac_stream_setup(hdac_stream(stream)); |
| 167 | snd_hdac_ext_stream_decouple(bus, stream, true); |
| 168 | } else { |
| 169 | err = snd_hdac_stream_setup(hdac_stream(stream)); |
| 170 | } |
| 171 | |
| 172 | if (err < 0) |
| 173 | return err; |
| 174 | |
| 175 | hdac_stream(stream)->prepared = 1; |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | int skl_pcm_link_dma_prepare(struct device *dev, struct skl_pipe_params *params) |
| 181 | { |
| 182 | struct hdac_bus *bus = dev_get_drvdata(dev); |
| 183 | unsigned int format_val; |
| 184 | struct hdac_stream *hstream; |
| 185 | struct hdac_ext_stream *stream; |
| 186 | struct hdac_ext_link *link; |
| 187 | unsigned char stream_tag; |
| 188 | |
| 189 | hstream = snd_hdac_get_stream(bus, params->stream, |
| 190 | params->link_dma_id + 1); |
| 191 | if (!hstream) |
| 192 | return -EINVAL; |
| 193 | |
| 194 | stream = stream_to_hdac_ext_stream(hstream); |
| 195 | snd_hdac_ext_stream_decouple(bus, stream, true); |
| 196 | format_val = snd_hdac_calc_stream_format(params->s_freq, params->ch, |
| 197 | params->format, params->link_bps, 0); |
| 198 | |
| 199 | dev_dbg(dev, "format_val=%d, rate=%d, ch=%d, format=%d\n", |
| 200 | format_val, params->s_freq, params->ch, params->format); |
| 201 | |
| 202 | snd_hdac_ext_link_stream_reset(stream); |
| 203 | |
| 204 | snd_hdac_ext_link_stream_setup(stream, format_val); |
| 205 | |
| 206 | stream_tag = hstream->stream_tag; |
| 207 | if (stream->hstream.direction == SNDRV_PCM_STREAM_PLAYBACK) { |
| 208 | list_for_each_entry(link, &bus->hlink_list, list) { |
| 209 | if (link->index == params->link_index) |
| 210 | snd_hdac_ext_link_set_stream_id(link, |
| 211 | stream_tag); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | stream->link_prepared = 1; |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | static int skl_pcm_open(struct snd_pcm_substream *substream, |
| 221 | struct snd_soc_dai *dai) |
| 222 | { |
| 223 | struct hdac_bus *bus = dev_get_drvdata(dai->dev); |
| 224 | struct hdac_ext_stream *stream; |
| 225 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 226 | struct skl_dma_params *dma_params; |
| 227 | struct skl_dev *skl = get_skl_ctx(dai->dev); |
| 228 | struct skl_module_cfg *mconfig; |
| 229 | |
| 230 | dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name); |
| 231 | |
| 232 | stream = snd_hdac_ext_stream_assign(bus, substream, |
| 233 | skl_get_host_stream_type(bus)); |
| 234 | if (stream == NULL) |
| 235 | return -EBUSY; |
| 236 | |
| 237 | skl_set_pcm_constrains(bus, runtime); |
| 238 | |
| 239 | /* |
| 240 | * disable WALLCLOCK timestamps for capture streams |
| 241 | * until we figure out how to handle digital inputs |
| 242 | */ |
| 243 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { |
| 244 | runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK; /* legacy */ |
| 245 | runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_LINK_ATIME; |
| 246 | } |
| 247 | |
| 248 | runtime->private_data = stream; |
| 249 | |
| 250 | dma_params = kzalloc(sizeof(*dma_params), GFP_KERNEL); |
| 251 | if (!dma_params) |
| 252 | return -ENOMEM; |
| 253 | |
| 254 | dma_params->stream_tag = hdac_stream(stream)->stream_tag; |
| 255 | snd_soc_dai_set_dma_data(dai, substream, dma_params); |
| 256 | |
| 257 | dev_dbg(dai->dev, "stream tag set in dma params=%d\n", |
| 258 | dma_params->stream_tag); |
| 259 | skl_set_suspend_active(substream, dai, true); |
| 260 | snd_pcm_set_sync(substream); |
| 261 | |
| 262 | mconfig = skl_tplg_fe_get_cpr_module(dai, substream->stream); |
| 263 | if (!mconfig) { |
| 264 | kfree(dma_params); |
| 265 | return -EINVAL; |
| 266 | } |
| 267 | |
| 268 | skl_tplg_d0i3_get(skl, mconfig->d0i3_caps); |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | static int skl_pcm_prepare(struct snd_pcm_substream *substream, |
| 274 | struct snd_soc_dai *dai) |
| 275 | { |
| 276 | struct skl_dev *skl = get_skl_ctx(dai->dev); |
| 277 | struct skl_module_cfg *mconfig; |
| 278 | int ret; |
| 279 | |
| 280 | dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name); |
| 281 | |
| 282 | mconfig = skl_tplg_fe_get_cpr_module(dai, substream->stream); |
| 283 | |
| 284 | /* |
| 285 | * In case of XRUN recovery or in the case when the application |
| 286 | * calls prepare another time, reset the FW pipe to clean state |
| 287 | */ |
| 288 | if (mconfig && |
| 289 | (substream->runtime->status->state == SNDRV_PCM_STATE_XRUN || |
| 290 | mconfig->pipe->state == SKL_PIPE_CREATED || |
| 291 | mconfig->pipe->state == SKL_PIPE_PAUSED)) { |
| 292 | |
| 293 | ret = skl_reset_pipe(skl, mconfig->pipe); |
| 294 | |
| 295 | if (ret < 0) |
| 296 | return ret; |
| 297 | |
| 298 | ret = skl_pcm_host_dma_prepare(dai->dev, |
| 299 | mconfig->pipe->p_params); |
| 300 | if (ret < 0) |
| 301 | return ret; |
| 302 | } |
| 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | static int skl_pcm_hw_params(struct snd_pcm_substream *substream, |
| 308 | struct snd_pcm_hw_params *params, |
| 309 | struct snd_soc_dai *dai) |
| 310 | { |
| 311 | struct hdac_bus *bus = dev_get_drvdata(dai->dev); |
| 312 | struct hdac_ext_stream *stream = get_hdac_ext_stream(substream); |
| 313 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 314 | struct skl_pipe_params p_params = {0}; |
| 315 | struct skl_module_cfg *m_cfg; |
| 316 | int ret, dma_id; |
| 317 | |
| 318 | dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name); |
| 319 | ret = skl_substream_alloc_pages(bus, substream, |
| 320 | params_buffer_bytes(params)); |
| 321 | if (ret < 0) |
| 322 | return ret; |
| 323 | |
| 324 | dev_dbg(dai->dev, "format_val, rate=%d, ch=%d, format=%d\n", |
| 325 | runtime->rate, runtime->channels, runtime->format); |
| 326 | |
| 327 | dma_id = hdac_stream(stream)->stream_tag - 1; |
| 328 | dev_dbg(dai->dev, "dma_id=%d\n", dma_id); |
| 329 | |
| 330 | p_params.s_fmt = snd_pcm_format_width(params_format(params)); |
| 331 | p_params.ch = params_channels(params); |
| 332 | p_params.s_freq = params_rate(params); |
| 333 | p_params.host_dma_id = dma_id; |
| 334 | p_params.stream = substream->stream; |
| 335 | p_params.format = params_format(params); |
| 336 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 337 | p_params.host_bps = dai->driver->playback.sig_bits; |
| 338 | else |
| 339 | p_params.host_bps = dai->driver->capture.sig_bits; |
| 340 | |
| 341 | |
| 342 | m_cfg = skl_tplg_fe_get_cpr_module(dai, p_params.stream); |
| 343 | if (m_cfg) |
| 344 | skl_tplg_update_pipe_params(dai->dev, m_cfg, &p_params); |
| 345 | |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | static void skl_pcm_close(struct snd_pcm_substream *substream, |
| 350 | struct snd_soc_dai *dai) |
| 351 | { |
| 352 | struct hdac_ext_stream *stream = get_hdac_ext_stream(substream); |
| 353 | struct hdac_bus *bus = dev_get_drvdata(dai->dev); |
| 354 | struct skl_dma_params *dma_params = NULL; |
| 355 | struct skl_dev *skl = bus_to_skl(bus); |
| 356 | struct skl_module_cfg *mconfig; |
| 357 | |
| 358 | dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name); |
| 359 | |
| 360 | snd_hdac_ext_stream_release(stream, skl_get_host_stream_type(bus)); |
| 361 | |
| 362 | dma_params = snd_soc_dai_get_dma_data(dai, substream); |
| 363 | /* |
| 364 | * now we should set this to NULL as we are freeing by the |
| 365 | * dma_params |
| 366 | */ |
| 367 | snd_soc_dai_set_dma_data(dai, substream, NULL); |
| 368 | skl_set_suspend_active(substream, dai, false); |
| 369 | |
| 370 | /* |
| 371 | * check if close is for "Reference Pin" and set back the |
| 372 | * CGCTL.MISCBDCGE if disabled by driver |
| 373 | */ |
| 374 | if (!strncmp(dai->name, "Reference Pin", 13) && |
| 375 | skl->miscbdcg_disabled) { |
| 376 | skl->enable_miscbdcge(dai->dev, true); |
| 377 | skl->miscbdcg_disabled = false; |
| 378 | } |
| 379 | |
| 380 | mconfig = skl_tplg_fe_get_cpr_module(dai, substream->stream); |
| 381 | if (mconfig) |
| 382 | skl_tplg_d0i3_put(skl, mconfig->d0i3_caps); |
| 383 | |
| 384 | kfree(dma_params); |
| 385 | } |
| 386 | |
| 387 | static int skl_pcm_hw_free(struct snd_pcm_substream *substream, |
| 388 | struct snd_soc_dai *dai) |
| 389 | { |
| 390 | struct hdac_bus *bus = dev_get_drvdata(dai->dev); |
| 391 | struct hdac_ext_stream *stream = get_hdac_ext_stream(substream); |
| 392 | struct skl_dev *skl = get_skl_ctx(dai->dev); |
| 393 | struct skl_module_cfg *mconfig; |
| 394 | int ret; |
| 395 | |
| 396 | dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name); |
| 397 | |
| 398 | mconfig = skl_tplg_fe_get_cpr_module(dai, substream->stream); |
| 399 | |
| 400 | if (mconfig) { |
| 401 | ret = skl_reset_pipe(skl, mconfig->pipe); |
| 402 | if (ret < 0) |
| 403 | dev_err(dai->dev, "%s:Reset failed ret =%d", |
| 404 | __func__, ret); |
| 405 | } |
| 406 | |
| 407 | snd_hdac_stream_cleanup(hdac_stream(stream)); |
| 408 | hdac_stream(stream)->prepared = 0; |
| 409 | |
| 410 | return skl_substream_free_pages(bus, substream); |
| 411 | } |
| 412 | |
| 413 | static int skl_be_hw_params(struct snd_pcm_substream *substream, |
| 414 | struct snd_pcm_hw_params *params, |
| 415 | struct snd_soc_dai *dai) |
| 416 | { |
| 417 | struct skl_pipe_params p_params = {0}; |
| 418 | |
| 419 | p_params.s_fmt = snd_pcm_format_width(params_format(params)); |
| 420 | p_params.ch = params_channels(params); |
| 421 | p_params.s_freq = params_rate(params); |
| 422 | p_params.stream = substream->stream; |
| 423 | |
| 424 | return skl_tplg_be_update_params(dai, &p_params); |
| 425 | } |
| 426 | |
| 427 | static int skl_decoupled_trigger(struct snd_pcm_substream *substream, |
| 428 | int cmd) |
| 429 | { |
| 430 | struct hdac_bus *bus = get_bus_ctx(substream); |
| 431 | struct hdac_ext_stream *stream; |
| 432 | int start; |
| 433 | unsigned long cookie; |
| 434 | struct hdac_stream *hstr; |
| 435 | |
| 436 | stream = get_hdac_ext_stream(substream); |
| 437 | hstr = hdac_stream(stream); |
| 438 | |
| 439 | if (!hstr->prepared) |
| 440 | return -EPIPE; |
| 441 | |
| 442 | switch (cmd) { |
| 443 | case SNDRV_PCM_TRIGGER_START: |
| 444 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 445 | case SNDRV_PCM_TRIGGER_RESUME: |
| 446 | start = 1; |
| 447 | break; |
| 448 | |
| 449 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 450 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 451 | case SNDRV_PCM_TRIGGER_STOP: |
| 452 | start = 0; |
| 453 | break; |
| 454 | |
| 455 | default: |
| 456 | return -EINVAL; |
| 457 | } |
| 458 | |
| 459 | spin_lock_irqsave(&bus->reg_lock, cookie); |
| 460 | |
| 461 | if (start) { |
| 462 | snd_hdac_stream_start(hdac_stream(stream), true); |
| 463 | snd_hdac_stream_timecounter_init(hstr, 0); |
| 464 | } else { |
| 465 | snd_hdac_stream_stop(hdac_stream(stream)); |
| 466 | } |
| 467 | |
| 468 | spin_unlock_irqrestore(&bus->reg_lock, cookie); |
| 469 | |
| 470 | return 0; |
| 471 | } |
| 472 | |
| 473 | static int skl_pcm_trigger(struct snd_pcm_substream *substream, int cmd, |
| 474 | struct snd_soc_dai *dai) |
| 475 | { |
| 476 | struct skl_dev *skl = get_skl_ctx(dai->dev); |
| 477 | struct skl_module_cfg *mconfig; |
| 478 | struct hdac_bus *bus = get_bus_ctx(substream); |
| 479 | struct hdac_ext_stream *stream = get_hdac_ext_stream(substream); |
| 480 | struct snd_soc_dapm_widget *w; |
| 481 | int ret; |
| 482 | |
| 483 | mconfig = skl_tplg_fe_get_cpr_module(dai, substream->stream); |
| 484 | if (!mconfig) |
| 485 | return -EIO; |
| 486 | |
| 487 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 488 | w = dai->playback_widget; |
| 489 | else |
| 490 | w = dai->capture_widget; |
| 491 | |
| 492 | switch (cmd) { |
| 493 | case SNDRV_PCM_TRIGGER_RESUME: |
| 494 | if (!w->ignore_suspend) { |
| 495 | /* |
| 496 | * enable DMA Resume enable bit for the stream, set the |
| 497 | * dpib & lpib position to resume before starting the |
| 498 | * DMA |
| 499 | */ |
| 500 | snd_hdac_ext_stream_drsm_enable(bus, true, |
| 501 | hdac_stream(stream)->index); |
| 502 | snd_hdac_ext_stream_set_dpibr(bus, stream, |
| 503 | stream->lpib); |
| 504 | snd_hdac_ext_stream_set_lpib(stream, stream->lpib); |
| 505 | } |
| 506 | /* fall through */ |
| 507 | |
| 508 | case SNDRV_PCM_TRIGGER_START: |
| 509 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 510 | /* |
| 511 | * Start HOST DMA and Start FE Pipe.This is to make sure that |
| 512 | * there are no underrun/overrun in the case when the FE |
| 513 | * pipeline is started but there is a delay in starting the |
| 514 | * DMA channel on the host. |
| 515 | */ |
| 516 | ret = skl_decoupled_trigger(substream, cmd); |
| 517 | if (ret < 0) |
| 518 | return ret; |
| 519 | return skl_run_pipe(skl, mconfig->pipe); |
| 520 | break; |
| 521 | |
| 522 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 523 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 524 | case SNDRV_PCM_TRIGGER_STOP: |
| 525 | /* |
| 526 | * Stop FE Pipe first and stop DMA. This is to make sure that |
| 527 | * there are no underrun/overrun in the case if there is a delay |
| 528 | * between the two operations. |
| 529 | */ |
| 530 | ret = skl_stop_pipe(skl, mconfig->pipe); |
| 531 | if (ret < 0) |
| 532 | return ret; |
| 533 | |
| 534 | ret = skl_decoupled_trigger(substream, cmd); |
| 535 | if ((cmd == SNDRV_PCM_TRIGGER_SUSPEND) && !w->ignore_suspend) { |
| 536 | /* save the dpib and lpib positions */ |
| 537 | stream->dpib = readl(bus->remap_addr + |
| 538 | AZX_REG_VS_SDXDPIB_XBASE + |
| 539 | (AZX_REG_VS_SDXDPIB_XINTERVAL * |
| 540 | hdac_stream(stream)->index)); |
| 541 | |
| 542 | stream->lpib = snd_hdac_stream_get_pos_lpib( |
| 543 | hdac_stream(stream)); |
| 544 | snd_hdac_ext_stream_decouple(bus, stream, false); |
| 545 | } |
| 546 | break; |
| 547 | |
| 548 | default: |
| 549 | return -EINVAL; |
| 550 | } |
| 551 | |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | |
| 556 | static int skl_link_hw_params(struct snd_pcm_substream *substream, |
| 557 | struct snd_pcm_hw_params *params, |
| 558 | struct snd_soc_dai *dai) |
| 559 | { |
| 560 | struct hdac_bus *bus = dev_get_drvdata(dai->dev); |
| 561 | struct hdac_ext_stream *link_dev; |
| 562 | struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream); |
| 563 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 564 | struct skl_pipe_params p_params = {0}; |
| 565 | struct hdac_ext_link *link; |
| 566 | int stream_tag; |
| 567 | |
| 568 | link_dev = snd_hdac_ext_stream_assign(bus, substream, |
| 569 | HDAC_EXT_STREAM_TYPE_LINK); |
| 570 | if (!link_dev) |
| 571 | return -EBUSY; |
| 572 | |
| 573 | snd_soc_dai_set_dma_data(dai, substream, (void *)link_dev); |
| 574 | |
| 575 | link = snd_hdac_ext_bus_get_link(bus, codec_dai->component->name); |
| 576 | if (!link) |
| 577 | return -EINVAL; |
| 578 | |
| 579 | stream_tag = hdac_stream(link_dev)->stream_tag; |
| 580 | |
| 581 | /* set the stream tag in the codec dai dma params */ |
| 582 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 583 | snd_soc_dai_set_tdm_slot(codec_dai, stream_tag, 0, 0, 0); |
| 584 | else |
| 585 | snd_soc_dai_set_tdm_slot(codec_dai, 0, stream_tag, 0, 0); |
| 586 | |
| 587 | p_params.s_fmt = snd_pcm_format_width(params_format(params)); |
| 588 | p_params.ch = params_channels(params); |
| 589 | p_params.s_freq = params_rate(params); |
| 590 | p_params.stream = substream->stream; |
| 591 | p_params.link_dma_id = stream_tag - 1; |
| 592 | p_params.link_index = link->index; |
| 593 | p_params.format = params_format(params); |
| 594 | |
| 595 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 596 | p_params.link_bps = codec_dai->driver->playback.sig_bits; |
| 597 | else |
| 598 | p_params.link_bps = codec_dai->driver->capture.sig_bits; |
| 599 | |
| 600 | return skl_tplg_be_update_params(dai, &p_params); |
| 601 | } |
| 602 | |
| 603 | static int skl_link_pcm_prepare(struct snd_pcm_substream *substream, |
| 604 | struct snd_soc_dai *dai) |
| 605 | { |
| 606 | struct skl_dev *skl = get_skl_ctx(dai->dev); |
| 607 | struct skl_module_cfg *mconfig = NULL; |
| 608 | |
| 609 | /* In case of XRUN recovery, reset the FW pipe to clean state */ |
| 610 | mconfig = skl_tplg_be_get_cpr_module(dai, substream->stream); |
| 611 | if (mconfig && !mconfig->pipe->passthru && |
| 612 | (substream->runtime->status->state == SNDRV_PCM_STATE_XRUN)) |
| 613 | skl_reset_pipe(skl, mconfig->pipe); |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | static int skl_link_pcm_trigger(struct snd_pcm_substream *substream, |
| 619 | int cmd, struct snd_soc_dai *dai) |
| 620 | { |
| 621 | struct hdac_ext_stream *link_dev = |
| 622 | snd_soc_dai_get_dma_data(dai, substream); |
| 623 | struct hdac_bus *bus = get_bus_ctx(substream); |
| 624 | struct hdac_ext_stream *stream = get_hdac_ext_stream(substream); |
| 625 | |
| 626 | dev_dbg(dai->dev, "In %s cmd=%d\n", __func__, cmd); |
| 627 | switch (cmd) { |
| 628 | case SNDRV_PCM_TRIGGER_RESUME: |
| 629 | case SNDRV_PCM_TRIGGER_START: |
| 630 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 631 | snd_hdac_ext_link_stream_start(link_dev); |
| 632 | break; |
| 633 | |
| 634 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 635 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 636 | case SNDRV_PCM_TRIGGER_STOP: |
| 637 | snd_hdac_ext_link_stream_clear(link_dev); |
| 638 | if (cmd == SNDRV_PCM_TRIGGER_SUSPEND) |
| 639 | snd_hdac_ext_stream_decouple(bus, stream, false); |
| 640 | break; |
| 641 | |
| 642 | default: |
| 643 | return -EINVAL; |
| 644 | } |
| 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | static int skl_link_hw_free(struct snd_pcm_substream *substream, |
| 649 | struct snd_soc_dai *dai) |
| 650 | { |
| 651 | struct hdac_bus *bus = dev_get_drvdata(dai->dev); |
| 652 | struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream); |
| 653 | struct hdac_ext_stream *link_dev = |
| 654 | snd_soc_dai_get_dma_data(dai, substream); |
| 655 | struct hdac_ext_link *link; |
| 656 | unsigned char stream_tag; |
| 657 | |
| 658 | dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name); |
| 659 | |
| 660 | link_dev->link_prepared = 0; |
| 661 | |
| 662 | link = snd_hdac_ext_bus_get_link(bus, rtd->codec_dai->component->name); |
| 663 | if (!link) |
| 664 | return -EINVAL; |
| 665 | |
| 666 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 667 | stream_tag = hdac_stream(link_dev)->stream_tag; |
| 668 | snd_hdac_ext_link_clear_stream_id(link, stream_tag); |
| 669 | } |
| 670 | |
| 671 | snd_hdac_ext_stream_release(link_dev, HDAC_EXT_STREAM_TYPE_LINK); |
| 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | static const struct snd_soc_dai_ops skl_pcm_dai_ops = { |
| 676 | .startup = skl_pcm_open, |
| 677 | .shutdown = skl_pcm_close, |
| 678 | .prepare = skl_pcm_prepare, |
| 679 | .hw_params = skl_pcm_hw_params, |
| 680 | .hw_free = skl_pcm_hw_free, |
| 681 | .trigger = skl_pcm_trigger, |
| 682 | }; |
| 683 | |
| 684 | static const struct snd_soc_dai_ops skl_dmic_dai_ops = { |
| 685 | .hw_params = skl_be_hw_params, |
| 686 | }; |
| 687 | |
| 688 | static const struct snd_soc_dai_ops skl_be_ssp_dai_ops = { |
| 689 | .hw_params = skl_be_hw_params, |
| 690 | }; |
| 691 | |
| 692 | static const struct snd_soc_dai_ops skl_link_dai_ops = { |
| 693 | .prepare = skl_link_pcm_prepare, |
| 694 | .hw_params = skl_link_hw_params, |
| 695 | .hw_free = skl_link_hw_free, |
| 696 | .trigger = skl_link_pcm_trigger, |
| 697 | }; |
| 698 | |
| 699 | static struct snd_soc_dai_driver skl_fe_dai[] = { |
| 700 | { |
| 701 | .name = "System Pin", |
| 702 | .ops = &skl_pcm_dai_ops, |
| 703 | .playback = { |
| 704 | .stream_name = "System Playback", |
| 705 | .channels_min = HDA_MONO, |
| 706 | .channels_max = HDA_STEREO, |
| 707 | .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_8000, |
| 708 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 709 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE, |
| 710 | .sig_bits = 32, |
| 711 | }, |
| 712 | .capture = { |
| 713 | .stream_name = "System Capture", |
| 714 | .channels_min = HDA_MONO, |
| 715 | .channels_max = HDA_STEREO, |
| 716 | .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000, |
| 717 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE, |
| 718 | .sig_bits = 32, |
| 719 | }, |
| 720 | }, |
| 721 | { |
| 722 | .name = "System Pin2", |
| 723 | .ops = &skl_pcm_dai_ops, |
| 724 | .playback = { |
| 725 | .stream_name = "Headset Playback", |
| 726 | .channels_min = HDA_MONO, |
| 727 | .channels_max = HDA_STEREO, |
| 728 | .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000 | |
| 729 | SNDRV_PCM_RATE_8000, |
| 730 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 731 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE, |
| 732 | }, |
| 733 | }, |
| 734 | { |
| 735 | .name = "Echoref Pin", |
| 736 | .ops = &skl_pcm_dai_ops, |
| 737 | .capture = { |
| 738 | .stream_name = "Echoreference Capture", |
| 739 | .channels_min = HDA_STEREO, |
| 740 | .channels_max = HDA_STEREO, |
| 741 | .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000 | |
| 742 | SNDRV_PCM_RATE_8000, |
| 743 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 744 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE, |
| 745 | }, |
| 746 | }, |
| 747 | { |
| 748 | .name = "Reference Pin", |
| 749 | .ops = &skl_pcm_dai_ops, |
| 750 | .capture = { |
| 751 | .stream_name = "Reference Capture", |
| 752 | .channels_min = HDA_MONO, |
| 753 | .channels_max = HDA_QUAD, |
| 754 | .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000, |
| 755 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE, |
| 756 | .sig_bits = 32, |
| 757 | }, |
| 758 | }, |
| 759 | { |
| 760 | .name = "Deepbuffer Pin", |
| 761 | .ops = &skl_pcm_dai_ops, |
| 762 | .playback = { |
| 763 | .stream_name = "Deepbuffer Playback", |
| 764 | .channels_min = HDA_STEREO, |
| 765 | .channels_max = HDA_STEREO, |
| 766 | .rates = SNDRV_PCM_RATE_48000, |
| 767 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE, |
| 768 | .sig_bits = 32, |
| 769 | }, |
| 770 | }, |
| 771 | { |
| 772 | .name = "LowLatency Pin", |
| 773 | .ops = &skl_pcm_dai_ops, |
| 774 | .playback = { |
| 775 | .stream_name = "Low Latency Playback", |
| 776 | .channels_min = HDA_STEREO, |
| 777 | .channels_max = HDA_STEREO, |
| 778 | .rates = SNDRV_PCM_RATE_48000, |
| 779 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE, |
| 780 | .sig_bits = 32, |
| 781 | }, |
| 782 | }, |
| 783 | { |
| 784 | .name = "DMIC Pin", |
| 785 | .ops = &skl_pcm_dai_ops, |
| 786 | .capture = { |
| 787 | .stream_name = "DMIC Capture", |
| 788 | .channels_min = HDA_MONO, |
| 789 | .channels_max = HDA_QUAD, |
| 790 | .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000, |
| 791 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE, |
| 792 | .sig_bits = 32, |
| 793 | }, |
| 794 | }, |
| 795 | { |
| 796 | .name = "HDMI1 Pin", |
| 797 | .ops = &skl_pcm_dai_ops, |
| 798 | .playback = { |
| 799 | .stream_name = "HDMI1 Playback", |
| 800 | .channels_min = HDA_STEREO, |
| 801 | .channels_max = 8, |
| 802 | .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | |
| 803 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | |
| 804 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 | |
| 805 | SNDRV_PCM_RATE_192000, |
| 806 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
| 807 | SNDRV_PCM_FMTBIT_S32_LE, |
| 808 | .sig_bits = 32, |
| 809 | }, |
| 810 | }, |
| 811 | { |
| 812 | .name = "HDMI2 Pin", |
| 813 | .ops = &skl_pcm_dai_ops, |
| 814 | .playback = { |
| 815 | .stream_name = "HDMI2 Playback", |
| 816 | .channels_min = HDA_STEREO, |
| 817 | .channels_max = 8, |
| 818 | .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | |
| 819 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | |
| 820 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 | |
| 821 | SNDRV_PCM_RATE_192000, |
| 822 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
| 823 | SNDRV_PCM_FMTBIT_S32_LE, |
| 824 | .sig_bits = 32, |
| 825 | }, |
| 826 | }, |
| 827 | { |
| 828 | .name = "HDMI3 Pin", |
| 829 | .ops = &skl_pcm_dai_ops, |
| 830 | .playback = { |
| 831 | .stream_name = "HDMI3 Playback", |
| 832 | .channels_min = HDA_STEREO, |
| 833 | .channels_max = 8, |
| 834 | .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | |
| 835 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | |
| 836 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 | |
| 837 | SNDRV_PCM_RATE_192000, |
| 838 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
| 839 | SNDRV_PCM_FMTBIT_S32_LE, |
| 840 | .sig_bits = 32, |
| 841 | }, |
| 842 | }, |
| 843 | }; |
| 844 | |
| 845 | /* BE CPU Dais */ |
| 846 | static struct snd_soc_dai_driver skl_platform_dai[] = { |
| 847 | { |
| 848 | .name = "SSP0 Pin", |
| 849 | .ops = &skl_be_ssp_dai_ops, |
| 850 | .playback = { |
| 851 | .stream_name = "ssp0 Tx", |
| 852 | .channels_min = HDA_STEREO, |
| 853 | .channels_max = HDA_STEREO, |
| 854 | .rates = SNDRV_PCM_RATE_48000, |
| 855 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 856 | }, |
| 857 | .capture = { |
| 858 | .stream_name = "ssp0 Rx", |
| 859 | .channels_min = HDA_STEREO, |
| 860 | .channels_max = HDA_STEREO, |
| 861 | .rates = SNDRV_PCM_RATE_48000, |
| 862 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 863 | }, |
| 864 | }, |
| 865 | { |
| 866 | .name = "SSP1 Pin", |
| 867 | .ops = &skl_be_ssp_dai_ops, |
| 868 | .playback = { |
| 869 | .stream_name = "ssp1 Tx", |
| 870 | .channels_min = HDA_STEREO, |
| 871 | .channels_max = HDA_STEREO, |
| 872 | .rates = SNDRV_PCM_RATE_48000, |
| 873 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 874 | }, |
| 875 | .capture = { |
| 876 | .stream_name = "ssp1 Rx", |
| 877 | .channels_min = HDA_STEREO, |
| 878 | .channels_max = HDA_STEREO, |
| 879 | .rates = SNDRV_PCM_RATE_48000, |
| 880 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 881 | }, |
| 882 | }, |
| 883 | { |
| 884 | .name = "SSP2 Pin", |
| 885 | .ops = &skl_be_ssp_dai_ops, |
| 886 | .playback = { |
| 887 | .stream_name = "ssp2 Tx", |
| 888 | .channels_min = HDA_STEREO, |
| 889 | .channels_max = HDA_STEREO, |
| 890 | .rates = SNDRV_PCM_RATE_48000, |
| 891 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 892 | }, |
| 893 | .capture = { |
| 894 | .stream_name = "ssp2 Rx", |
| 895 | .channels_min = HDA_STEREO, |
| 896 | .channels_max = HDA_STEREO, |
| 897 | .rates = SNDRV_PCM_RATE_48000, |
| 898 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 899 | }, |
| 900 | }, |
| 901 | { |
| 902 | .name = "SSP3 Pin", |
| 903 | .ops = &skl_be_ssp_dai_ops, |
| 904 | .playback = { |
| 905 | .stream_name = "ssp3 Tx", |
| 906 | .channels_min = HDA_STEREO, |
| 907 | .channels_max = HDA_STEREO, |
| 908 | .rates = SNDRV_PCM_RATE_48000, |
| 909 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 910 | }, |
| 911 | .capture = { |
| 912 | .stream_name = "ssp3 Rx", |
| 913 | .channels_min = HDA_STEREO, |
| 914 | .channels_max = HDA_STEREO, |
| 915 | .rates = SNDRV_PCM_RATE_48000, |
| 916 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 917 | }, |
| 918 | }, |
| 919 | { |
| 920 | .name = "SSP4 Pin", |
| 921 | .ops = &skl_be_ssp_dai_ops, |
| 922 | .playback = { |
| 923 | .stream_name = "ssp4 Tx", |
| 924 | .channels_min = HDA_STEREO, |
| 925 | .channels_max = HDA_STEREO, |
| 926 | .rates = SNDRV_PCM_RATE_48000, |
| 927 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 928 | }, |
| 929 | .capture = { |
| 930 | .stream_name = "ssp4 Rx", |
| 931 | .channels_min = HDA_STEREO, |
| 932 | .channels_max = HDA_STEREO, |
| 933 | .rates = SNDRV_PCM_RATE_48000, |
| 934 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 935 | }, |
| 936 | }, |
| 937 | { |
| 938 | .name = "SSP5 Pin", |
| 939 | .ops = &skl_be_ssp_dai_ops, |
| 940 | .playback = { |
| 941 | .stream_name = "ssp5 Tx", |
| 942 | .channels_min = HDA_STEREO, |
| 943 | .channels_max = HDA_STEREO, |
| 944 | .rates = SNDRV_PCM_RATE_48000, |
| 945 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 946 | }, |
| 947 | .capture = { |
| 948 | .stream_name = "ssp5 Rx", |
| 949 | .channels_min = HDA_STEREO, |
| 950 | .channels_max = HDA_STEREO, |
| 951 | .rates = SNDRV_PCM_RATE_48000, |
| 952 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 953 | }, |
| 954 | }, |
| 955 | { |
| 956 | .name = "iDisp1 Pin", |
| 957 | .ops = &skl_link_dai_ops, |
| 958 | .playback = { |
| 959 | .stream_name = "iDisp1 Tx", |
| 960 | .channels_min = HDA_STEREO, |
| 961 | .channels_max = 8, |
| 962 | .rates = SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_48000, |
| 963 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE | |
| 964 | SNDRV_PCM_FMTBIT_S24_LE, |
| 965 | }, |
| 966 | }, |
| 967 | { |
| 968 | .name = "iDisp2 Pin", |
| 969 | .ops = &skl_link_dai_ops, |
| 970 | .playback = { |
| 971 | .stream_name = "iDisp2 Tx", |
| 972 | .channels_min = HDA_STEREO, |
| 973 | .channels_max = 8, |
| 974 | .rates = SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000| |
| 975 | SNDRV_PCM_RATE_48000, |
| 976 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE | |
| 977 | SNDRV_PCM_FMTBIT_S24_LE, |
| 978 | }, |
| 979 | }, |
| 980 | { |
| 981 | .name = "iDisp3 Pin", |
| 982 | .ops = &skl_link_dai_ops, |
| 983 | .playback = { |
| 984 | .stream_name = "iDisp3 Tx", |
| 985 | .channels_min = HDA_STEREO, |
| 986 | .channels_max = 8, |
| 987 | .rates = SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000| |
| 988 | SNDRV_PCM_RATE_48000, |
| 989 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE | |
| 990 | SNDRV_PCM_FMTBIT_S24_LE, |
| 991 | }, |
| 992 | }, |
| 993 | { |
| 994 | .name = "DMIC01 Pin", |
| 995 | .ops = &skl_dmic_dai_ops, |
| 996 | .capture = { |
| 997 | .stream_name = "DMIC01 Rx", |
| 998 | .channels_min = HDA_MONO, |
| 999 | .channels_max = HDA_QUAD, |
| 1000 | .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000, |
| 1001 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE, |
| 1002 | }, |
| 1003 | }, |
| 1004 | { |
| 1005 | .name = "DMIC16k Pin", |
| 1006 | .ops = &skl_dmic_dai_ops, |
| 1007 | .capture = { |
| 1008 | .stream_name = "DMIC16k Rx", |
| 1009 | .channels_min = HDA_MONO, |
| 1010 | .channels_max = HDA_QUAD, |
| 1011 | .rates = SNDRV_PCM_RATE_16000, |
| 1012 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 1013 | }, |
| 1014 | }, |
| 1015 | { |
| 1016 | .name = "Analog CPU DAI", |
| 1017 | .ops = &skl_link_dai_ops, |
| 1018 | .playback = { |
| 1019 | .stream_name = "Analog CPU Playback", |
| 1020 | .channels_min = HDA_MONO, |
| 1021 | .channels_max = HDA_MAX, |
| 1022 | .rates = SNDRV_PCM_RATE_8000_192000, |
| 1023 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
| 1024 | SNDRV_PCM_FMTBIT_S32_LE, |
| 1025 | }, |
| 1026 | .capture = { |
| 1027 | .stream_name = "Analog CPU Capture", |
| 1028 | .channels_min = HDA_MONO, |
| 1029 | .channels_max = HDA_MAX, |
| 1030 | .rates = SNDRV_PCM_RATE_8000_192000, |
| 1031 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
| 1032 | SNDRV_PCM_FMTBIT_S32_LE, |
| 1033 | }, |
| 1034 | }, |
| 1035 | { |
| 1036 | .name = "Alt Analog CPU DAI", |
| 1037 | .ops = &skl_link_dai_ops, |
| 1038 | .playback = { |
| 1039 | .stream_name = "Alt Analog CPU Playback", |
| 1040 | .channels_min = HDA_MONO, |
| 1041 | .channels_max = HDA_MAX, |
| 1042 | .rates = SNDRV_PCM_RATE_8000_192000, |
| 1043 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
| 1044 | SNDRV_PCM_FMTBIT_S32_LE, |
| 1045 | }, |
| 1046 | .capture = { |
| 1047 | .stream_name = "Alt Analog CPU Capture", |
| 1048 | .channels_min = HDA_MONO, |
| 1049 | .channels_max = HDA_MAX, |
| 1050 | .rates = SNDRV_PCM_RATE_8000_192000, |
| 1051 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
| 1052 | SNDRV_PCM_FMTBIT_S32_LE, |
| 1053 | }, |
| 1054 | }, |
| 1055 | { |
| 1056 | .name = "Digital CPU DAI", |
| 1057 | .ops = &skl_link_dai_ops, |
| 1058 | .playback = { |
| 1059 | .stream_name = "Digital CPU Playback", |
| 1060 | .channels_min = HDA_MONO, |
| 1061 | .channels_max = HDA_MAX, |
| 1062 | .rates = SNDRV_PCM_RATE_8000_192000, |
| 1063 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
| 1064 | SNDRV_PCM_FMTBIT_S32_LE, |
| 1065 | }, |
| 1066 | .capture = { |
| 1067 | .stream_name = "Digital CPU Capture", |
| 1068 | .channels_min = HDA_MONO, |
| 1069 | .channels_max = HDA_MAX, |
| 1070 | .rates = SNDRV_PCM_RATE_8000_192000, |
| 1071 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
| 1072 | SNDRV_PCM_FMTBIT_S32_LE, |
| 1073 | }, |
| 1074 | }, |
| 1075 | }; |
| 1076 | |
| 1077 | int skl_dai_load(struct snd_soc_component *cmp, int index, |
| 1078 | struct snd_soc_dai_driver *dai_drv, |
| 1079 | struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai) |
| 1080 | { |
| 1081 | dai_drv->ops = &skl_pcm_dai_ops; |
| 1082 | |
| 1083 | return 0; |
| 1084 | } |
| 1085 | |
| 1086 | static int skl_platform_open(struct snd_pcm_substream *substream) |
| 1087 | { |
| 1088 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 1089 | struct snd_soc_dai_link *dai_link = rtd->dai_link; |
| 1090 | |
| 1091 | dev_dbg(rtd->cpu_dai->dev, "In %s:%s\n", __func__, |
| 1092 | dai_link->cpus->dai_name); |
| 1093 | |
| 1094 | snd_soc_set_runtime_hwparams(substream, &azx_pcm_hw); |
| 1095 | |
| 1096 | return 0; |
| 1097 | } |
| 1098 | |
| 1099 | static int skl_coupled_trigger(struct snd_pcm_substream *substream, |
| 1100 | int cmd) |
| 1101 | { |
| 1102 | struct hdac_bus *bus = get_bus_ctx(substream); |
| 1103 | struct hdac_ext_stream *stream; |
| 1104 | struct snd_pcm_substream *s; |
| 1105 | bool start; |
| 1106 | int sbits = 0; |
| 1107 | unsigned long cookie; |
| 1108 | struct hdac_stream *hstr; |
| 1109 | |
| 1110 | stream = get_hdac_ext_stream(substream); |
| 1111 | hstr = hdac_stream(stream); |
| 1112 | |
| 1113 | dev_dbg(bus->dev, "In %s cmd=%d\n", __func__, cmd); |
| 1114 | |
| 1115 | if (!hstr->prepared) |
| 1116 | return -EPIPE; |
| 1117 | |
| 1118 | switch (cmd) { |
| 1119 | case SNDRV_PCM_TRIGGER_START: |
| 1120 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 1121 | case SNDRV_PCM_TRIGGER_RESUME: |
| 1122 | start = true; |
| 1123 | break; |
| 1124 | |
| 1125 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 1126 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 1127 | case SNDRV_PCM_TRIGGER_STOP: |
| 1128 | start = false; |
| 1129 | break; |
| 1130 | |
| 1131 | default: |
| 1132 | return -EINVAL; |
| 1133 | } |
| 1134 | |
| 1135 | snd_pcm_group_for_each_entry(s, substream) { |
| 1136 | if (s->pcm->card != substream->pcm->card) |
| 1137 | continue; |
| 1138 | stream = get_hdac_ext_stream(s); |
| 1139 | sbits |= 1 << hdac_stream(stream)->index; |
| 1140 | snd_pcm_trigger_done(s, substream); |
| 1141 | } |
| 1142 | |
| 1143 | spin_lock_irqsave(&bus->reg_lock, cookie); |
| 1144 | |
| 1145 | /* first, set SYNC bits of corresponding streams */ |
| 1146 | snd_hdac_stream_sync_trigger(hstr, true, sbits, AZX_REG_SSYNC); |
| 1147 | |
| 1148 | snd_pcm_group_for_each_entry(s, substream) { |
| 1149 | if (s->pcm->card != substream->pcm->card) |
| 1150 | continue; |
| 1151 | stream = get_hdac_ext_stream(s); |
| 1152 | if (start) |
| 1153 | snd_hdac_stream_start(hdac_stream(stream), true); |
| 1154 | else |
| 1155 | snd_hdac_stream_stop(hdac_stream(stream)); |
| 1156 | } |
| 1157 | spin_unlock_irqrestore(&bus->reg_lock, cookie); |
| 1158 | |
| 1159 | snd_hdac_stream_sync(hstr, start, sbits); |
| 1160 | |
| 1161 | spin_lock_irqsave(&bus->reg_lock, cookie); |
| 1162 | |
| 1163 | /* reset SYNC bits */ |
| 1164 | snd_hdac_stream_sync_trigger(hstr, false, sbits, AZX_REG_SSYNC); |
| 1165 | if (start) |
| 1166 | snd_hdac_stream_timecounter_init(hstr, sbits); |
| 1167 | spin_unlock_irqrestore(&bus->reg_lock, cookie); |
| 1168 | |
| 1169 | return 0; |
| 1170 | } |
| 1171 | |
| 1172 | static int skl_platform_pcm_trigger(struct snd_pcm_substream *substream, |
| 1173 | int cmd) |
| 1174 | { |
| 1175 | struct hdac_bus *bus = get_bus_ctx(substream); |
| 1176 | |
| 1177 | if (!bus->ppcap) |
| 1178 | return skl_coupled_trigger(substream, cmd); |
| 1179 | |
| 1180 | return 0; |
| 1181 | } |
| 1182 | |
| 1183 | static snd_pcm_uframes_t skl_platform_pcm_pointer |
| 1184 | (struct snd_pcm_substream *substream) |
| 1185 | { |
| 1186 | struct hdac_ext_stream *hstream = get_hdac_ext_stream(substream); |
| 1187 | struct hdac_bus *bus = get_bus_ctx(substream); |
| 1188 | unsigned int pos; |
| 1189 | |
| 1190 | /* |
| 1191 | * Use DPIB for Playback stream as the periodic DMA Position-in- |
| 1192 | * Buffer Writes may be scheduled at the same time or later than |
| 1193 | * the MSI and does not guarantee to reflect the Position of the |
| 1194 | * last buffer that was transferred. Whereas DPIB register in |
| 1195 | * HAD space reflects the actual data that is transferred. |
| 1196 | * Use the position buffer for capture, as DPIB write gets |
| 1197 | * completed earlier than the actual data written to the DDR. |
| 1198 | * |
| 1199 | * For capture stream following workaround is required to fix the |
| 1200 | * incorrect position reporting. |
| 1201 | * |
| 1202 | * 1. Wait for 20us before reading the DMA position in buffer once |
| 1203 | * the interrupt is generated for stream completion as update happens |
| 1204 | * on the HDA frame boundary i.e. 20.833uSec. |
| 1205 | * 2. Read DPIB register to flush the DMA position value. This dummy |
| 1206 | * read is required to flush DMA position value. |
| 1207 | * 3. Read the DMA Position-in-Buffer. This value now will be equal to |
| 1208 | * or greater than period boundary. |
| 1209 | */ |
| 1210 | |
| 1211 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 1212 | pos = readl(bus->remap_addr + AZX_REG_VS_SDXDPIB_XBASE + |
| 1213 | (AZX_REG_VS_SDXDPIB_XINTERVAL * |
| 1214 | hdac_stream(hstream)->index)); |
| 1215 | } else { |
| 1216 | udelay(20); |
| 1217 | readl(bus->remap_addr + |
| 1218 | AZX_REG_VS_SDXDPIB_XBASE + |
| 1219 | (AZX_REG_VS_SDXDPIB_XINTERVAL * |
| 1220 | hdac_stream(hstream)->index)); |
| 1221 | pos = snd_hdac_stream_get_pos_posbuf(hdac_stream(hstream)); |
| 1222 | } |
| 1223 | |
| 1224 | if (pos >= hdac_stream(hstream)->bufsize) |
| 1225 | pos = 0; |
| 1226 | |
| 1227 | return bytes_to_frames(substream->runtime, pos); |
| 1228 | } |
| 1229 | |
| 1230 | static u64 skl_adjust_codec_delay(struct snd_pcm_substream *substream, |
| 1231 | u64 nsec) |
| 1232 | { |
| 1233 | struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream); |
| 1234 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 1235 | u64 codec_frames, codec_nsecs; |
| 1236 | |
| 1237 | if (!codec_dai->driver->ops->delay) |
| 1238 | return nsec; |
| 1239 | |
| 1240 | codec_frames = codec_dai->driver->ops->delay(substream, codec_dai); |
| 1241 | codec_nsecs = div_u64(codec_frames * 1000000000LL, |
| 1242 | substream->runtime->rate); |
| 1243 | |
| 1244 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 1245 | return nsec + codec_nsecs; |
| 1246 | |
| 1247 | return (nsec > codec_nsecs) ? nsec - codec_nsecs : 0; |
| 1248 | } |
| 1249 | |
| 1250 | static int skl_get_time_info(struct snd_pcm_substream *substream, |
| 1251 | struct timespec64 *system_ts, struct timespec64 *audio_ts, |
| 1252 | struct snd_pcm_audio_tstamp_config *audio_tstamp_config, |
| 1253 | struct snd_pcm_audio_tstamp_report *audio_tstamp_report) |
| 1254 | { |
| 1255 | struct hdac_ext_stream *sstream = get_hdac_ext_stream(substream); |
| 1256 | struct hdac_stream *hstr = hdac_stream(sstream); |
| 1257 | u64 nsec; |
| 1258 | |
| 1259 | if ((substream->runtime->hw.info & SNDRV_PCM_INFO_HAS_LINK_ATIME) && |
| 1260 | (audio_tstamp_config->type_requested == SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK)) { |
| 1261 | |
| 1262 | snd_pcm_gettime(substream->runtime, system_ts); |
| 1263 | |
| 1264 | nsec = timecounter_read(&hstr->tc); |
| 1265 | nsec = div_u64(nsec, 3); /* can be optimized */ |
| 1266 | if (audio_tstamp_config->report_delay) |
| 1267 | nsec = skl_adjust_codec_delay(substream, nsec); |
| 1268 | |
| 1269 | *audio_ts = ns_to_timespec64(nsec); |
| 1270 | |
| 1271 | audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK; |
| 1272 | audio_tstamp_report->accuracy_report = 1; /* rest of struct is valid */ |
| 1273 | audio_tstamp_report->accuracy = 42; /* 24MHzWallClk == 42ns resolution */ |
| 1274 | |
| 1275 | } else { |
| 1276 | audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT; |
| 1277 | } |
| 1278 | |
| 1279 | return 0; |
| 1280 | } |
| 1281 | |
| 1282 | static const struct snd_pcm_ops skl_platform_ops = { |
| 1283 | .open = skl_platform_open, |
| 1284 | .ioctl = snd_pcm_lib_ioctl, |
| 1285 | .trigger = skl_platform_pcm_trigger, |
| 1286 | .pointer = skl_platform_pcm_pointer, |
| 1287 | .get_time_info = skl_get_time_info, |
| 1288 | .mmap = snd_pcm_lib_default_mmap, |
| 1289 | .page = snd_pcm_sgbuf_ops_page, |
| 1290 | }; |
| 1291 | |
| 1292 | static void skl_pcm_free(struct snd_pcm *pcm) |
| 1293 | { |
| 1294 | snd_pcm_lib_preallocate_free_for_all(pcm); |
| 1295 | } |
| 1296 | |
| 1297 | #define MAX_PREALLOC_SIZE (32 * 1024 * 1024) |
| 1298 | |
| 1299 | static int skl_pcm_new(struct snd_soc_pcm_runtime *rtd) |
| 1300 | { |
| 1301 | struct snd_soc_dai *dai = rtd->cpu_dai; |
| 1302 | struct hdac_bus *bus = dev_get_drvdata(dai->dev); |
| 1303 | struct snd_pcm *pcm = rtd->pcm; |
| 1304 | unsigned int size; |
| 1305 | struct skl_dev *skl = bus_to_skl(bus); |
| 1306 | |
| 1307 | if (dai->driver->playback.channels_min || |
| 1308 | dai->driver->capture.channels_min) { |
| 1309 | /* buffer pre-allocation */ |
| 1310 | size = CONFIG_SND_HDA_PREALLOC_SIZE * 1024; |
| 1311 | if (size > MAX_PREALLOC_SIZE) |
| 1312 | size = MAX_PREALLOC_SIZE; |
| 1313 | snd_pcm_lib_preallocate_pages_for_all(pcm, |
| 1314 | SNDRV_DMA_TYPE_DEV_SG, |
| 1315 | snd_dma_pci_data(skl->pci), |
| 1316 | size, MAX_PREALLOC_SIZE); |
| 1317 | } |
| 1318 | |
| 1319 | return 0; |
| 1320 | } |
| 1321 | |
| 1322 | static int skl_get_module_info(struct skl_dev *skl, |
| 1323 | struct skl_module_cfg *mconfig) |
| 1324 | { |
| 1325 | struct skl_module_inst_id *pin_id; |
| 1326 | guid_t *uuid_mod, *uuid_tplg; |
| 1327 | struct skl_module *skl_module; |
| 1328 | struct uuid_module *module; |
| 1329 | int i, ret = -EIO; |
| 1330 | |
| 1331 | uuid_mod = (guid_t *)mconfig->guid; |
| 1332 | |
| 1333 | if (list_empty(&skl->uuid_list)) { |
| 1334 | dev_err(skl->dev, "Module list is empty\n"); |
| 1335 | return -EIO; |
| 1336 | } |
| 1337 | |
| 1338 | for (i = 0; i < skl->nr_modules; i++) { |
| 1339 | skl_module = skl->modules[i]; |
| 1340 | uuid_tplg = &skl_module->uuid; |
| 1341 | if (guid_equal(uuid_mod, uuid_tplg)) { |
| 1342 | mconfig->module = skl_module; |
| 1343 | ret = 0; |
| 1344 | break; |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | if (skl->nr_modules && ret) |
| 1349 | return ret; |
| 1350 | |
| 1351 | ret = -EIO; |
| 1352 | list_for_each_entry(module, &skl->uuid_list, list) { |
| 1353 | if (guid_equal(uuid_mod, &module->uuid)) { |
| 1354 | mconfig->id.module_id = module->id; |
| 1355 | mconfig->module->loadable = module->is_loadable; |
| 1356 | ret = 0; |
| 1357 | } |
| 1358 | |
| 1359 | for (i = 0; i < MAX_IN_QUEUE; i++) { |
| 1360 | pin_id = &mconfig->m_in_pin[i].id; |
| 1361 | if (guid_equal(&pin_id->mod_uuid, &module->uuid)) |
| 1362 | pin_id->module_id = module->id; |
| 1363 | } |
| 1364 | |
| 1365 | for (i = 0; i < MAX_OUT_QUEUE; i++) { |
| 1366 | pin_id = &mconfig->m_out_pin[i].id; |
| 1367 | if (guid_equal(&pin_id->mod_uuid, &module->uuid)) |
| 1368 | pin_id->module_id = module->id; |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | return ret; |
| 1373 | } |
| 1374 | |
| 1375 | static int skl_populate_modules(struct skl_dev *skl) |
| 1376 | { |
| 1377 | struct skl_pipeline *p; |
| 1378 | struct skl_pipe_module *m; |
| 1379 | struct snd_soc_dapm_widget *w; |
| 1380 | struct skl_module_cfg *mconfig; |
| 1381 | int ret = 0; |
| 1382 | |
| 1383 | list_for_each_entry(p, &skl->ppl_list, node) { |
| 1384 | list_for_each_entry(m, &p->pipe->w_list, node) { |
| 1385 | w = m->w; |
| 1386 | mconfig = w->priv; |
| 1387 | |
| 1388 | ret = skl_get_module_info(skl, mconfig); |
| 1389 | if (ret < 0) { |
| 1390 | dev_err(skl->dev, |
| 1391 | "query module info failed\n"); |
| 1392 | return ret; |
| 1393 | } |
| 1394 | |
| 1395 | skl_tplg_add_moduleid_in_bind_params(skl, w); |
| 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | return ret; |
| 1400 | } |
| 1401 | |
| 1402 | static int skl_platform_soc_probe(struct snd_soc_component *component) |
| 1403 | { |
| 1404 | struct hdac_bus *bus = dev_get_drvdata(component->dev); |
| 1405 | struct skl_dev *skl = bus_to_skl(bus); |
| 1406 | const struct skl_dsp_ops *ops; |
| 1407 | int ret; |
| 1408 | |
| 1409 | pm_runtime_get_sync(component->dev); |
| 1410 | if (bus->ppcap) { |
| 1411 | skl->component = component; |
| 1412 | |
| 1413 | /* init debugfs */ |
| 1414 | skl->debugfs = skl_debugfs_init(skl); |
| 1415 | |
| 1416 | ret = skl_tplg_init(component, bus); |
| 1417 | if (ret < 0) { |
| 1418 | dev_err(component->dev, "Failed to init topology!\n"); |
| 1419 | return ret; |
| 1420 | } |
| 1421 | |
| 1422 | /* load the firmwares, since all is set */ |
| 1423 | ops = skl_get_dsp_ops(skl->pci->device); |
| 1424 | if (!ops) |
| 1425 | return -EIO; |
| 1426 | |
| 1427 | /* |
| 1428 | * Disable dynamic clock and power gating during firmware |
| 1429 | * and library download |
| 1430 | */ |
| 1431 | skl->enable_miscbdcge(component->dev, false); |
| 1432 | skl->clock_power_gating(component->dev, false); |
| 1433 | |
| 1434 | ret = ops->init_fw(component->dev, skl); |
| 1435 | skl->enable_miscbdcge(component->dev, true); |
| 1436 | skl->clock_power_gating(component->dev, true); |
| 1437 | if (ret < 0) { |
| 1438 | dev_err(component->dev, "Failed to boot first fw: %d\n", ret); |
| 1439 | return ret; |
| 1440 | } |
| 1441 | skl_populate_modules(skl); |
| 1442 | skl->update_d0i3c = skl_update_d0i3c; |
| 1443 | |
| 1444 | if (skl->cfg.astate_cfg != NULL) { |
| 1445 | skl_dsp_set_astate_cfg(skl, |
| 1446 | skl->cfg.astate_cfg->count, |
| 1447 | skl->cfg.astate_cfg); |
| 1448 | } |
| 1449 | } |
| 1450 | pm_runtime_mark_last_busy(component->dev); |
| 1451 | pm_runtime_put_autosuspend(component->dev); |
| 1452 | |
| 1453 | return 0; |
| 1454 | } |
| 1455 | |
| 1456 | static void skl_pcm_remove(struct snd_soc_component *component) |
| 1457 | { |
| 1458 | struct hdac_bus *bus = dev_get_drvdata(component->dev); |
| 1459 | struct skl_dev *skl = bus_to_skl(bus); |
| 1460 | |
| 1461 | skl_tplg_exit(component, bus); |
| 1462 | |
| 1463 | skl_debugfs_exit(skl); |
| 1464 | } |
| 1465 | |
| 1466 | static const struct snd_soc_component_driver skl_component = { |
| 1467 | .name = "pcm", |
| 1468 | .probe = skl_platform_soc_probe, |
| 1469 | .remove = skl_pcm_remove, |
| 1470 | .ops = &skl_platform_ops, |
| 1471 | .pcm_new = skl_pcm_new, |
| 1472 | .pcm_free = skl_pcm_free, |
| 1473 | .module_get_upon_open = 1, /* increment refcount when a pcm is opened */ |
| 1474 | }; |
| 1475 | |
| 1476 | int skl_platform_register(struct device *dev) |
| 1477 | { |
| 1478 | int ret; |
| 1479 | struct snd_soc_dai_driver *dais; |
| 1480 | int num_dais = ARRAY_SIZE(skl_platform_dai); |
| 1481 | struct hdac_bus *bus = dev_get_drvdata(dev); |
| 1482 | struct skl_dev *skl = bus_to_skl(bus); |
| 1483 | |
| 1484 | skl->dais = kmemdup(skl_platform_dai, sizeof(skl_platform_dai), |
| 1485 | GFP_KERNEL); |
| 1486 | if (!skl->dais) { |
| 1487 | ret = -ENOMEM; |
| 1488 | goto err; |
| 1489 | } |
| 1490 | |
| 1491 | if (!skl->use_tplg_pcm) { |
| 1492 | dais = krealloc(skl->dais, sizeof(skl_fe_dai) + |
| 1493 | sizeof(skl_platform_dai), GFP_KERNEL); |
| 1494 | if (!dais) { |
| 1495 | kfree(skl->dais); |
| 1496 | ret = -ENOMEM; |
| 1497 | goto err; |
| 1498 | } |
| 1499 | |
| 1500 | skl->dais = dais; |
| 1501 | memcpy(&skl->dais[ARRAY_SIZE(skl_platform_dai)], skl_fe_dai, |
| 1502 | sizeof(skl_fe_dai)); |
| 1503 | num_dais += ARRAY_SIZE(skl_fe_dai); |
| 1504 | } |
| 1505 | |
| 1506 | ret = devm_snd_soc_register_component(dev, &skl_component, |
| 1507 | skl->dais, num_dais); |
| 1508 | if (ret) { |
| 1509 | kfree(skl->dais); |
| 1510 | dev_err(dev, "soc component registration failed %d\n", ret); |
| 1511 | } |
| 1512 | err: |
| 1513 | return ret; |
| 1514 | } |
| 1515 | |
| 1516 | int skl_platform_unregister(struct device *dev) |
| 1517 | { |
| 1518 | struct hdac_bus *bus = dev_get_drvdata(dev); |
| 1519 | struct skl_dev *skl = bus_to_skl(bus); |
| 1520 | struct skl_module_deferred_bind *modules, *tmp; |
| 1521 | |
| 1522 | if (!list_empty(&skl->bind_list)) { |
| 1523 | list_for_each_entry_safe(modules, tmp, &skl->bind_list, node) { |
| 1524 | list_del(&modules->node); |
| 1525 | kfree(modules); |
| 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | kfree(skl->dais); |
| 1530 | |
| 1531 | return 0; |
| 1532 | } |